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 Th15:
  X c= dom f & f|X is monotone & (ex p,g st f.:X = ].p,g.[)
  implies f|X is continuous
proof
  assume that
A1: X c= dom f and
A2: f|X is monotone;
  given p,g such that
A3: f.:X = ].p,g.[;
  set L = ].p,g.[;
  now
    per cases by A2,RFUNCT_2:def 5;
    suppose
      f|X is non-decreasing;
      then
A4:   f|X|X is non-decreasing;
      for x0 be Real st x0 in dom(f|X) holds f|X is_continuous_in x0
      proof
        let x0 be Real;
A5:     (f|X).:X = f.:X by RELAT_1:129;
        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
A7:     (f|X).x0 in L by A3,RELAT_1:129;
        now
          let N1 be Neighbourhood of (f|X).x0;
          consider N2 being Neighbourhood of (f|X).x0 such that
A8:       N2 c= L by A7,RCOMP_1:18;
          consider N3 being Neighbourhood of (f|X).x0 such that
A9:      N3 c= N1 and
A10:      N3 c= N2 by RCOMP_1:17;
          consider r be Real such that
A11:      r>0 and
A12:      N3 = ].(f|X).x0 - r,(f|X).x0 + r.[ by RCOMP_1:def 6;
          reconsider r as Real;
A13:      (f|X).x0 + r/2 < (f|X).x0 + r/2 + r/2 by A11,XREAL_1:29,215;
          set M2 = (f|X).x0 + r/2;
A14:      (f|X).x0 < (f|X).x0 + r/2 by A11,XREAL_1:29,215;
A15:      (f|X).x0 < (f|X).x0 + r by A11,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 A14,XXREAL_0:2;
          then
A16:      M2 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A13;
          then M2 in N2 by A10,A12;
          then consider r2 being Element of REAL such that
A17:      r2 in dom (f|X) & r2 in X and
A18:      M2 = (f|X).r2 by A3,A5,A8,PARTFUN2:59;
A19:      M2 > (f|X).x0 by A11,XREAL_1:29,215;
A20:      now
            assume
A21:        r2 < x0;
            x0 in X /\ dom(f|X) & r2 in X /\ dom (f|X) by A6,A17,XBOOLE_0:def 4
;
            hence contradiction by A4,A18,A19,A21,RFUNCT_2:22;
          end;
          set M1 = (f|X).x0 - r/2;
A22:      (f|X).x0 - r < (f|X).x0 - r + r/2 by A11,XREAL_1:29,215;
          (f|X).x0 - r/2 < (f|X).x0 by A14,XREAL_1:19;
          then (f|X).x0 - r/2 < (f|X).x0 + r by A15,XXREAL_0:2;
          then
A23:      M1 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A22;
          then M1 in N2 by A10,A12;
          then consider r1 being Element of REAL such that
A24:      r1 in dom (f|X) & r1 in X and
A25:      M1 = (f|X).r1 by A3,A5,A8,PARTFUN2:59;
A26:      (f|X).x0 < (f|X).x0 + r/2 by A11,XREAL_1:29,215;
          then
A27:      M1 < (f|X).x0 by XREAL_1:19;
A28:      now
            assume
A29:        x0 < r1;
            x0 in X /\ dom( f|X) & r1 in X /\ dom(f|X) by A6,A24,XBOOLE_0:def 4
;
            hence contradiction by A4,A25,A27,A29,RFUNCT_2:22;
          end;
          x0 <> r2 by A11,A18,XREAL_1:29,215;
          then x0 < r2 by A20,XXREAL_0:1;
          then
A30:      r2 - x0 > 0 by XREAL_1:50;
          set R = min(x0 - r1,r2 - x0);
A31:      R <= r2 - x0 by XXREAL_0:17;
          r1 <> x0 by A25,A26,XREAL_1:19;
          then r1 < x0 by A28,XXREAL_0:1;
          then x0 - r1 > 0 by XREAL_1:50;
          then R > 0 by A30,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
A32:      x in dom (f|X) and
A33:      x in N;
A34:      x in X /\ dom (f|X) by A32,XBOOLE_1:28;
A35:      ex s st s = x & x0 - R < s & s < x0 + R by A33;
          then x0 < R + x by XREAL_1:19;
          then
A36:      x0 - x < R + x - x by XREAL_1:9;
          R <= x0 - r1 by XXREAL_0:17;
          then x0 - x < x0 - r1 by A36,XXREAL_0:2;
          then -(x0 - x) > -(x0 - r1) by XREAL_1:24;
          then
A37:      x - x0 + x0 > r1 - x0 + x0 by XREAL_1:6;
          r1 in X /\ dom (f|X) by A24,XBOOLE_0:def 4;
          then
A38:      (f|X).r1 <= (f|X).x by A4,A37,A34,RFUNCT_2:22;
          x - x0 < R by A35,XREAL_1:19;
          then x - x0 < r2 - x0 by A31,XXREAL_0:2;
          then
A39:      x - x0 + x0 < r2 - x0 + x0 by XREAL_1:6;
          r2 in X /\ dom (f|X) by A17,XBOOLE_0:def 4;
          then (f|X).x <= (f|X).r2 by A4,A39,A34,RFUNCT_2:22;
          then
A40:      (f|X).x in [.M1,M2.] by A25,A18,A38;
          [.M1,M2.] c= ].(f|X).x0 - r,(f|X).x0 + r.[ by A23,A16,XXREAL_2:def 12
;
          then (f|X).x in N3 by A12,A40;
          hence (f|X).x in N1 by A9;
        end;
        hence thesis by FCONT_1:4;
      end;
      hence thesis by FCONT_1:def 2;
    end;
    suppose
      f|X is non-increasing;
      then
A41:  f|X|X is non-increasing;
      for x0 be Real st x0 in dom(f|X) holds f|X is_continuous_in x0
      proof
        let x0 be Real;
A42:    (f|X).:X = f.:X by RELAT_1:129;
        assume x0 in dom(f|X);
        then
    x0 in X;
        then x0 in dom f /\ X by A1,XBOOLE_0:def 4;
        then
A43:    x0 in dom(f|X) by RELAT_1:61;
        then (f|X).x0 in (f|X).:X by FUNCT_1:def 6;
        then
A44:    (f|X).x0 in L by A3,RELAT_1:129;
        now
          let N1 be Neighbourhood of (f|X).x0;
          consider N2 being Neighbourhood of (f|X).x0 such that
A45:      N2 c= L by A44,RCOMP_1:18;
          consider N3 being Neighbourhood of (f|X).x0 such that
A46:      N3 c= N1 and
A47:      N3 c= N2 by RCOMP_1:17;
          consider r be Real such that
A48:      r > 0 and
A49:      N3 = ].(f|X).x0 - r,(f|X).x0 + r.[ by RCOMP_1:def 6;
          reconsider r as Real;
A50:      (f|X).x0 + r/2 < (f|X).x0 + r/2 + r/2 by A48,XREAL_1:29,215;
          set M2 = (f|X).x0 + r/2;
A51:      (f|X).x0 < (f|X).x0 + r/2 by A48,XREAL_1:29,215;
A52:      (f|X).x0 < (f|X).x0 + r by A48,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 A51,XXREAL_0:2;
          then
A53:      M2 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A50;
          then M2 in N2 by A47,A49;
          then consider r2 being Element of REAL such that
A54:      r2 in dom (f|X) & r2 in X and
A55:      M2 = (f|X).r2 by A3,A42,A45,PARTFUN2:59;
A56:      M2 > (f|X).x0 by A48,XREAL_1:29,215;
A57:      now
            assume
A58:        r2 > x0;
            x0 in X /\ dom (f|X) & r2 in X /\ dom (f|X) by A43,A54,
XBOOLE_0:def 4;
            hence contradiction by A41,A55,A56,A58,RFUNCT_2:23;
          end;
          set M1 = (f|X).x0 - r/2;
A59:      (f|X).x0 - r < (f|X).x0 - r + r/2 by A48,XREAL_1:29,215;
          (f|X).x0 - r/2 < (f|X).x0 by A51,XREAL_1:19;
          then (f|X).x0 - r/2 < (f|X).x0 + r by A52,XXREAL_0:2;
          then
A60:      M1 in ].(f|X).x0 - r,(f|X).x0 + r.[ by A59;
          then M1 in N2 by A47,A49;
          then consider r1 being Element of REAL such that
A61:      r1 in dom (f|X) & r1 in X and
A62:      M1 = (f|X).r1 by A3,A42,A45,PARTFUN2:59;
A63:      (f|X).x0 < (f|X).x0 + r/2 by A48,XREAL_1:29,215;
          then
A64:      M1 < (f|X).x0 by XREAL_1:19;
A65:      now
            assume
A66:        x0 > r1;
            x0 in X /\ dom (f|X) & r1 in X /\ dom(f|X) by A43,A61,
XBOOLE_0:def 4;
            hence contradiction by A41,A62,A64,A66,RFUNCT_2:23;
          end;
          x0 <> r2 by A48,A55,XREAL_1:29,215;
          then x0 > r2 by A57,XXREAL_0:1;
          then
A67:      x0 - r2 > 0 by XREAL_1:50;
          set R = min(r1 - x0,x0 - r2);
A68:      R <= r1 - x0 by XXREAL_0:17;
          r1 <> x0 by A62,A63,XREAL_1:19;
          then r1 > x0 by A65,XXREAL_0:1;
          then r1 - x0 > 0 by XREAL_1:50;
          then R > 0 by A67,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
A69:      x in dom (f|X) and
A70:      x in N;
A71:      x in X /\ dom(f|X) by A69,XBOOLE_1:28;
A72:      ex s st s = x & x0 - R < s & s < x0 + R by A70;
          then x0 < R + x by XREAL_1:19;
          then
A73:      x0 - x < R + x - x by XREAL_1:9;
          x - x0 < R by A72,XREAL_1:19;
          then x - x0 < r1-x0 by A68,XXREAL_0:2;
          then
A74:      x - x0 + x0 < r1 - x0 + x0 by XREAL_1:6;
          r1 in X /\ dom(f|X) by A61,XBOOLE_0:def 4;
          then
A75:      (f|X).r1 <= (f|X).x by A41,A74,A71,RFUNCT_2:23;
          R <= x0 - r2 by XXREAL_0:17;
          then x0 - x < x0 - r2 by A73,XXREAL_0:2;
          then -(x0 - x) > -(x0 - r2) by XREAL_1:24;
          then
A76:      x - x0 + x0 > r2 - x0 + x0 by XREAL_1:6;
          r2 in X /\ dom(f|X) by A54,XBOOLE_0:def 4;
          then (f|X).x <= (f|X).r2 by A41,A76,A71,RFUNCT_2:23;
          then
A77:      (f|X).x in [.M1,M2.] by A62,A55,A75;
          [.M1,M2.] c= ].(f|X).x0 - r,(f|X).x0 + r.[ by A60,A53,XXREAL_2:def 12
;
          then (f|X).x in N3 by A49,A77;
          hence (f|X).x in N1 by A46;
        end;
        hence thesis by FCONT_1:4;
      end;
      hence thesis by FCONT_1:def 2;
    end;
  end;
  hence thesis;
end;
