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