reserve x,X for set;
reserve x0,r1,r2,g,g1,g2,p,s for Real;
reserve r for Real;
reserve n,m for Nat;
reserve a,b,d for Real_Sequence;
reserve f for PartFunc of REAL,REAL;

theorem Th14:
  X c= dom f & f|X is monotone & (ex p st f.:X =
  right_closed_halfline(p)) implies f|X is continuous
proof
  assume that
A1: X c= dom f and
A2: f|X is monotone;
  given p such that
A3: f.:X = right_closed_halfline(p);
  set L = right_open_halfline(p);
  set l = right_closed_halfline(p);
  for x0 be Real st x0 in dom(f|X) holds f|X is_continuous_in x0
  proof
    let x0 be Real;
A4: (f|X).:X = f.:X by RELAT_1:129;
A5: L c= l by XXREAL_1:22;
    assume x0 in dom(f|X);
    then
 x0 in X;
    then x0 in dom f /\ X by A1,XBOOLE_0:def 4;
    then
A6: x0 in dom (f|X) by RELAT_1:61;
    then (f|X).x0 in (f|X).:X by FUNCT_1:def 6;
    then (f|X).x0 in {p} \/ L by A3,A4,XXREAL_1:427;
    then
A7: (f|X).x0 in {p} or (f|X).x0 in L by XBOOLE_0:def 3;
    now
      let N1 be Neighbourhood of (f|X).x0;
      now
        per cases by A2,RFUNCT_2:def 5;
        suppose
          f|X is non-decreasing;
          then
A8:       f|X|X is non-decreasing;
          now
            per cases by A7,TARSKI:def 1;
            suppose
              (f|X).x0 in L;
              then consider N2 being Neighbourhood of (f|X).x0 such that
A9:          N2 c= L by RCOMP_1:18;
              consider N3 being Neighbourhood of (f|X).x0 such that
A10:          N3 c= N1 and
A11:          N3 c= N2 by RCOMP_1:17;
              consider r be Real such that
A12:          r>0 and
A13:          N3 = ].(f|X).x0 - r,(f|X).x0 + r.[ by RCOMP_1:def 6;
              reconsider r as Real;
A14:          (f|X).x0 + r/2 < (f|X).x0 + r/2 + r/2 by A12,XREAL_1:29,215;
              set M2 = (f|X).x0 + r/2;
A15:          (f|X).x0 < (f|X).x0 + r/2 by A12,XREAL_1:29,215;
A16:          (f|X).x0 < (f|X).x0 + r by A12,XREAL_1:29;
              then (f|X).x0 - r < (f|X).x0 + r - r by XREAL_1:9;
              then (f|X).x0 - r < (f|X).x0 + r/2 by A15,XXREAL_0:2;
              then
A17:          M2 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A14;
              then M2 in N2 by A11,A13;
              then M2 in L by A9;
              then consider r2 being Element of REAL such that
A18:          r2 in dom (f|X) & r2 in X and
A19:          M2 = (f|X).r2 by A3,A4,A5,PARTFUN2:59;
A20:          M2 > (f|X).x0 by A12,XREAL_1:29,215;
A21:          now
                assume
A22:            r2 < x0;
                x0 in X /\ dom(f|X) & r2 in X /\ dom (f|X)
                 by A6,A18,XBOOLE_0:def 4;
                hence contradiction by A8,A19,A20,A22,RFUNCT_2:22;
              end;
              set M1 = (f|X).x0 - r/2;
A23:          (f|X).x0 - r < (f|X).x0 - r + r/2 by A12,XREAL_1:29,215;
              (f|X).x0 - r/2 < (f|X).x0 by A15,XREAL_1:19;
              then (f|X).x0 - r/2 < (f|X).x0 + r by A16,XXREAL_0:2;
              then
A24:          M1 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A23;
              then M1 in N2 by A11,A13;
              then M1 in L by A9;
              then consider r1 being Element of REAL such that
A25:          r1 in dom (f|X) & r1 in X and
A26:          M1 = (f|X).r1 by A3,A4,A5,PARTFUN2:59;
A27:          (f|X).x0 < (f|X).x0 + r/2 by A12,XREAL_1:29,215;
              then
A28:          M1 < (f|X).x0 by XREAL_1:19;
A29:          now
                assume
A30:            x0 < r1;
                x0 in X /\ dom( f|X) & r1 in X /\ dom(f|X)
                 by A6,A25,XBOOLE_0:def 4;
                hence contradiction by A8,A26,A28,A30,RFUNCT_2:22;
              end;
              x0 <> r2 by A12,A19,XREAL_1:29,215;
              then x0 < r2 by A21,XXREAL_0:1;
              then
A31:          r2 - x0 > 0 by XREAL_1:50;
              set R = min(x0 - r1,r2 - x0);
A32:          R <= r2 - x0 by XXREAL_0:17;
              r1 <> x0 by A26,A27,XREAL_1:19;
              then r1 < x0 by A29,XXREAL_0:1;
              then x0 - r1 > 0 by XREAL_1:50;
              then R > 0 by A31,XXREAL_0:15;
              then reconsider N = ].x0 - R,x0+ R.[ as Neighbourhood of x0 by
RCOMP_1:def 6;
              take N;
              let x be Real;
              assume that
A33:          x in dom (f|X) and
A34:          x in N;
A35:          x in X /\ dom (f|X) by A33,XBOOLE_1:28;
A36:          ex s st s = x & x0 - R < s & s < x0 + R by A34;
              then x0 < R + x by XREAL_1:19;
              then
A37:          x0 - x < R + x - x by XREAL_1:9;
              R <= x0 - r1 by XXREAL_0:17;
              then x0 - x < x0 - r1 by A37,XXREAL_0:2;
              then -(x0 - x) > -(x0 - r1) by XREAL_1:24;
              then
A38:          x - x0 + x0 > r1 - x0 + x0 by XREAL_1:6;
              r1 in X /\ dom (f|X) by A25,XBOOLE_0:def 4;
              then
A39:          (f|X).r1 <= (f|X).x by A8,A38,A35,RFUNCT_2:22;
              x - x0 < R by A36,XREAL_1:19;
              then x - x0 < r2 - x0 by A32,XXREAL_0:2;
              then
A40:          x - x0 + x0 < r2 - x0 + x0 by XREAL_1:6;
              r2 in X /\ dom (f|X) by A18,XBOOLE_0:def 4;
              then (f|X).x <= (f|X).r2 by A8,A40,A35,RFUNCT_2:22;
              then
A41:          (f|X).x in [.M1,M2.] by A26,A19,A39;
              [.M1,M2.] c= ].(f|X).x0 - r,(f|X).x0 + r.[ by A24,A17,
XXREAL_2:def 12;
              then (f|X).x in N3 by A13,A41;
              hence (f|X).x in N1 by A10;
            end;
            suppose
A42:          (f|X).x0 = p;
              then consider r be Real such that
A43:          r > 0 and
A44:          N1 = ].p - r,p + r.[ by RCOMP_1:def 6;
              reconsider r as Real;
              set R = r/2;
A45:          p - R < p by A43,XREAL_1:44,215;
A46:          p < p + R by A43,XREAL_1:29,215;
              then p + R in {s : p < s};
              then p + R in L by XXREAL_1:230;
              then consider r1 being Element of REAL such that
A47:          r1 in dom (f|X) & r1 in X and
A48:          p + R = (f|X).r1 by A3,A4,A5,PARTFUN2:59;
A49:          now
                assume
A50:            x0 > r1;
                x0 in X /\ dom (f|X) &
                 r1 in X /\ dom (f|X) by A6,A47,XBOOLE_0:def 4;
                hence contradiction by A8,A42,A46,A48,A50,RFUNCT_2:22;
              end;
              r1 <> x0 by A42,A43,A48,XREAL_1:29,215;
              then r1 > x0 by A49,XXREAL_0:1;
              then reconsider N = ].x0 - (r1 - x0),x0 + (r1 - x0).[ as
              Neighbourhood of x0 by RCOMP_1:def 6,XREAL_1:50;
              take N;
              let x be Real such that
A51:          x in dom(f|X) and
A52:          x in N;
A53:          ex s st s = x & x0 - (r1-x0) < s & s < x0 + (r1-x0) by A52;
              (f|X).x in l by A3,A4,A51,FUNCT_1:def 6;
              then (f|X).x in {s: p <= s} by XXREAL_1:232;
              then ex s st s = (f|X).x & p <= s;
              then
A54:          p - R <= (f|X).x by A45,XXREAL_0:2;
A55:          r1 in X /\ dom (f|X) by A47,XBOOLE_0:def 4;
              x in X /\ dom (f|X) by A51,XBOOLE_0:def 4;
              then p + R >= (f|X).x by A8,A48,A55,A53,RFUNCT_2:22;
              then
A56:          (f|X).x in [.p - R, p + R.] by A54;
A57:          R < r by A43,XREAL_1:216;
              then
A58:          p - r < p - R by XREAL_1:15;
              p < p + r by A43,XREAL_1:29;
              then p - R < p + r by A45,XXREAL_0:2;
              then
A59:          p - R in ].p - r, p + r.[ by A58;
A60:          p + R < p + r by A57,XREAL_1:6;
              p - r < p by A43,XREAL_1:44;
              then p - r < p + R by A46,XXREAL_0:2;
              then p + R in ].p - r, p + r.[ by A60;
              then [.p - R, p + R.] c= N1 by A44,A59,XXREAL_2:def 12;
              hence (f|X).x in N1 by A56;
            end;
          end;
          hence ex N being Neighbourhood of x0 st for r1 be Real st r1
          in dom(f|X) & r1 in N holds (f|X).r1 in N1;
        end;
        suppose
          f|X is non-increasing;
          then
A61:      f|X|X is non-increasing;
          now
            per cases by A7,TARSKI:def 1;
            suppose
              (f|X).x0 in L;
              then consider N2 being Neighbourhood of (f|X).x0 such that
A62:          N2 c= L by RCOMP_1:18;
              consider N3 being Neighbourhood of (f|X).x0 such that
A63:          N3 c= N1 and
A64:          N3 c= N2 by RCOMP_1:17;
              consider r be Real such that
A65:          r > 0 and
A66:          N3 = ].(f|X).x0 - r,(f|X).x0 + r.[ by RCOMP_1:def 6;
              reconsider r as Real;
A67:          (f|X).x0 + r/2 < (f|X).x0 + r/2 + r/2 by A65,XREAL_1:29,215;
              set M2 = (f|X).x0 + r/2;
A68:          (f|X).x0 < (f|X).x0 + r/2 by A65,XREAL_1:29,215;
A69:          (f|X).x0 < (f|X).x0 + r by A65,XREAL_1:29;
              then (f|X).x0 - r < (f|X).x0 + r - r by XREAL_1:9;
              then (f|X).x0 - r < (f|X).x0 + r/2 by A68,XXREAL_0:2;
              then
A70:          M2 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A67;
              then M2 in N2 by A64,A66;
              then M2 in L by A62;
              then consider r2 being Element of REAL such that
A71:          r2 in dom (f|X) & r2 in X and
A72:          M2 = (f|X).r2 by A3,A4,A5,PARTFUN2:59;
A73:          M2 > (f|X).x0 by A65,XREAL_1:29,215;
A74:          now
                assume
A75:            r2 > x0;
                x0 in X /\ dom (f|X) & r2 in X /\ dom (f|X)
                 by A6,A71,XBOOLE_0:def 4;
                hence contradiction by A61,A72,A73,A75,RFUNCT_2:23;
              end;
              set M1 = (f|X).x0 - r/2;
A76:          (f|X).x0 - r < (f|X).x0 - r + r/2 by A65,XREAL_1:29,215;
              (f|X).x0 - r/2 < (f|X).x0 by A68,XREAL_1:19;
              then (f|X).x0 - r/2 < (f|X).x0 + r by A69,XXREAL_0:2;
              then
A77:          M1 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A76;
              then M1 in N2 by A64,A66;
              then M1 in L by A62;
              then consider r1 being Element of REAL such that
A78:          r1 in dom (f|X) & r1 in X and
A79:          M1 = (f|X).r1 by A3,A4,A5,PARTFUN2:59;
A80:          (f|X).x0 < (f|X).x0 + r/2 by A65,XREAL_1:29,215;
              then
A81:          M1 < (f|X).x0 by XREAL_1:19;
A82:          now
                assume
A83:            x0 > r1;
                x0 in X /\ dom (f|X) & r1 in X /\ dom(f|X)
                 by A6,A78,XBOOLE_0:def 4;
                hence contradiction by A61,A79,A81,A83,RFUNCT_2:23;
              end;
              x0 <> r2 by A65,A72,XREAL_1:29,215;
              then x0 > r2 by A74,XXREAL_0:1;
              then
A84:          x0 - r2 > 0 by XREAL_1:50;
              set R = min(r1 - x0,x0 - r2);
A85:          R <= r1 - x0 by XXREAL_0:17;
              r1 <> x0 by A79,A80,XREAL_1:19;
              then r1 > x0 by A82,XXREAL_0:1;
              then r1 - x0 > 0 by XREAL_1:50;
              then R > 0 by A84,XXREAL_0:15;
              then reconsider N =].x0 - R,x0 + R.[ as Neighbourhood of x0 by
RCOMP_1:def 6;
              take N;
              let x be Real;
              assume that
A86:          x in dom (f|X) and
A87:          x in N;
A88:          x in X /\ dom(f|X) by A86,XBOOLE_1:28;
A89:          ex s st s = x & x0 - R < s & s < x0 + R by A87;
              then x0 < R + x by XREAL_1:19;
              then
A90:          x0 - x < R + x - x by XREAL_1:9;
              x - x0 < R by A89,XREAL_1:19;
              then x - x0 < r1-x0 by A85,XXREAL_0:2;
              then
A91:          x - x0 + x0 < r1 - x0 + x0 by XREAL_1:6;
              r1 in X /\ dom(f|X) by A78,XBOOLE_0:def 4;
              then
A92:          (f|X).r1 <= (f|X).x by A61,A91,A88,RFUNCT_2:23;
              R <= x0 - r2 by XXREAL_0:17;
              then x0 - x < x0 - r2 by A90,XXREAL_0:2;
              then -(x0 - x) > -(x0 - r2) by XREAL_1:24;
              then
A93:          x - x0 + x0 > r2 - x0 + x0 by XREAL_1:6;
              r2 in X /\ dom(f|X) by A71,XBOOLE_0:def 4;
              then (f|X).x <= (f|X).r2 by A61,A93,A88,RFUNCT_2:23;
              then
A94:          (f|X).x in [.M1,M2.] by A79,A72,A92;
              [.M1,M2.] c= ].(f|X).x0 - r,(f|X).x0 + r.[ by A77,A70,
XXREAL_2:def 12;
              then (f|X).x in N3 by A66,A94;
              hence (f|X).x in N1 by A63;
            end;
            suppose
A95:          (f|X).x0 = p;
              then consider r be Real such that
A96:          r > 0 and
A97:          N1 = ].p - r,p + r.[ by RCOMP_1:def 6;
              reconsider r as Real;
              set R = r/2;
A98:         p - R < p by A96,XREAL_1:44,215;
A99:         p < p + R by A96,XREAL_1:29,215;
              then p + R in {s : p < s};
              then p + R in L by XXREAL_1:230;
              then consider r1 being Element of REAL such that
A100:         r1 in dom (f|X) & r1 in X and
A101:         p + R = (f|X).r1 by A3,A4,A5,PARTFUN2:59;
A102:         now
                assume
A103:           x0 < r1;
                x0 in X /\ dom (f|X) & r1 in X /\ dom (f|X)
                 by A6,A100,XBOOLE_0:def 4;
                hence contradiction by A61,A95,A99,A101,A103,RFUNCT_2:23;
              end;
              r1 <> x0 by A95,A96,A101,XREAL_1:29,215;
              then r1 < x0 by A102,XXREAL_0:1;
              then reconsider N = ].x0 - (x0 - r1),x0 + (x0 - r1).[ as
              Neighbourhood of x0 by RCOMP_1:def 6,XREAL_1:50;
              take N;
              let x be Real such that
A104:         x in dom(f|X) and
A105:         x in N;
A106:         ex s st s = x & x0 - (x0-r1) < s & s < x0 + (x0-r1) by A105;
              (f|X).x in l by A3,A4,A104,FUNCT_1:def 6;
              then (f|X).x in {s: p <= s} by XXREAL_1:232;
              then ex s st s = (f|X).x & p <= s;
              then
A107:         p - R <= (f|X).x by A98,XXREAL_0:2;
A108:         r1 in X /\ dom (f|X) by A100,XBOOLE_0:def 4;
              x in X /\ dom (f|X) by A104,XBOOLE_0:def 4;
              then p + R >= (f|X).x by A61,A101,A108,A106,RFUNCT_2:23;
              then
A109:         (f|X).x in [.p - R, p + R.] by A107;
A110:         R < r by A96,XREAL_1:216;
              then
A111:         p - r < p - R by XREAL_1:15;
              p < p + r by A96,XREAL_1:29;
              then p - R < p + r by A98,XXREAL_0:2;
              then
A112:         p - R in ].p - r, p + r.[ by A111;
A113:         p + R < p + r by A110,XREAL_1:6;
              p - r < p by A96,XREAL_1:44;
              then p - r < p + R by A99,XXREAL_0:2;
              then p + R in ].p - r, p + r.[ by A113;
              then [.p - R, p + R.] c= N1 by A97,A112,XXREAL_2:def 12;
              hence (f|X).x in N1 by A109;
            end;
          end;
          hence ex N being Neighbourhood of x0 st for r1 be Real st r1
          in dom(f|X) & r1 in N holds (f|X).r1 in N1;
        end;
      end;
      hence ex N being Neighbourhood of x0 st for r1 be Real st r1 in
      dom(f|X) & r1 in N holds (f|X).r1 in N1;
    end;
    hence thesis by FCONT_1:4;
  end;
  hence thesis by FCONT_1:def 2;
end;
