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
  ].p,g.[ c= dom f & f|].p,g.[ is continuous & (f|].p,g.[ is increasing
  or f|].p,g.[ is decreasing) implies rng (f|].p,g.[) is open
proof
  assume that
A1: ].p,g.[ c= dom f and
A2: f|].p,g.[ is continuous and
A3: f|].p,g.[ is increasing or f|].p,g.[ is decreasing;
  now
    let r1 be Element of REAL;
    set f1 = f|].p,g.[;
    assume r1 in rng f1;
    then consider x0 being Element of REAL such that
A4: x0 in dom f1 and
A5: f1.x0 = r1 by PARTFUN1:3;
A6: r1 = f.x0 by A4,A5,FUNCT_1:47;
A7: x0 in dom f /\ ].p,g.[ by A4,RELAT_1:61;
    then x0 in ].p,g.[ by XBOOLE_0:def 4;
    then consider N be Neighbourhood of x0 such that
A8: N c= ].p,g.[ by RCOMP_1:18;
    consider r be Real such that
A9: 0 < r and
A10: N = ].x0 - r, x0 + r.[ by RCOMP_1:def 6;
    reconsider r as Element of REAL by XREAL_0:def 1;
    0 < r/2 by A9,XREAL_1:215;
    then
A11: x0 - r/2 < x0 - 0 by XREAL_1:15;
A12: r/2 < r by A9,XREAL_1:216;
    then
A13: x0 - r < x0 - r/2 by XREAL_1:15;
A14: N c= dom f by A1,A8;
    set fp = f.(x0 + r/2);
    set fm = f.(x0 - r/2);
A15: x0 + r/2 < x0 + r by A12,XREAL_1:8;
A16: x0 < x0 + r/2 by A9,XREAL_1:29,215;
    then
A17: x0 - r/2 < x0 + r/2 by A11,XXREAL_0:2;
    x0 < x0 + r by A9,XREAL_1:29;
    then x0 - r/2 < x0 + r by A11,XXREAL_0:2;
    then
A18: x0 - r/2 in ].x0 - r, x0 + r.[ by A13;
    then
A19: x0 - r/2 in ].p,g.[ /\ dom f by A8,A10,A14,XBOOLE_0:def 4;
    x0 - r < x0 by A9,XREAL_1:44;
    then x0 - r < x0 + r/2 by A16,XXREAL_0:2;
    then
A20: x0 + r/2 in ].x0 - r, x0 + r.[ by A15;
    then
A21: x0 + r/2 in ].p,g.[ /\ dom f by A8,A10,A14,XBOOLE_0:def 4;
A22: [.x0 - r/2, x0 + r/2.] c= ].x0 - r, x0 + r.[ by A18,A20,XXREAL_2:def 12;
A23: [.x0 - r/2, x0 + r/2.] c= ].p,g.[ by A8,A10,A18,A20,XXREAL_2:def 12;
    then
A24: f|[.x0 - r/2, x0 + r/2.] is continuous by A2,FCONT_1:16;
    now
      per cases by A3;
      suppose
A25:    f|].p,g.[ is increasing;
        set R = min(f.x0 - fm,fp - f.x0);
        f.x0 < fp by A7,A16,A21,A25,RFUNCT_2:20;
        then
A26:    0 < fp - f.x0 by XREAL_1:50;
        fm < f.x0 by A7,A11,A19,A25,RFUNCT_2:20;
        then 0 < f.x0 - fm by XREAL_1:50;
        then 0 < R by A26,XXREAL_0:15;
        then reconsider N1 = ].r1 - R, r1 + R.[ as Neighbourhood of r1 by
RCOMP_1:def 6;
        take N1;
        fm < fp by A17,A21,A19,A25,RFUNCT_2:20;
        then [.fp,fm.] = {} by XXREAL_1:29;
        then
A27:    [.fm,fp.] \/ [.fp,fm.] = [.fm,fp.];
        thus N1 c= rng f1
        proof
          let x be object;
A28:      ].fm,fp.[ c= [.fm,fp.] by XXREAL_1:25;
          assume x in N1;
          then consider r2 such that
A29:      r2 = x and
A30:      f.x0 - R < r2 and
A31:      r2 < f.x0 + R by A6;
          R <= fp - f.x0 by XXREAL_0:17;
          then f.x0 + R <= f.x0 + (fp - f.x0) by XREAL_1:7;
          then
A32:      r2 < fp by A31,XXREAL_0:2;
          R <= f.x0 - fm by XXREAL_0:17;
          then f.x0 - (f.x0 - fm) <= f.x0 - R by XREAL_1:13;
          then fm < r2 by A30,XXREAL_0:2;
          then r2 in ].fm,fp.[ by A32;
          then consider s such that
A33:      s in [.x0 - r/2, x0 + r/2.] and
A34:      x = f.s by A1,A23,A24,A17,A27,A29,A28,FCONT_2:15,XBOOLE_1:1;
          s in N by A10,A22,A33;
          then s in dom f /\ ].p,g.[ by A8,A14,XBOOLE_0:def 4;
          then
A35:      s in dom f1 by RELAT_1:61;
          then x = f1.s by A34,FUNCT_1:47;
          hence thesis by A35,FUNCT_1:def 3;
        end;
      end;
      suppose
A36:    f|].p,g.[ is decreasing;
        set R = min(fm - f.x0,f.x0 - fp);
        fp < f.x0 by A7,A16,A21,A36,RFUNCT_2:21;
        then
A37:    0 < f.x0 - fp by XREAL_1:50;
        f.x0 < fm by A7,A11,A19,A36,RFUNCT_2:21;
        then 0 < fm - f.x0 by XREAL_1:50;
        then 0 < R by A37,XXREAL_0:15;
        then reconsider N1 = ].r1 - R, r1 + R.[ as Neighbourhood of r1 by
RCOMP_1:def 6;
        take N1;
        fp < fm by A17,A21,A19,A36,RFUNCT_2:21;
        then [.fm,fp.] = {} by XXREAL_1:29;
        then
A38:    [.fm,fp.] \/ [.fp,fm.] = [.fp,fm.];
        thus N1 c= rng f1
        proof
          let x be object;
A39:      ].fp,fm.[ c= [.fp,fm.] by XXREAL_1:25;
          assume x in N1;
          then consider r2 such that
A40:      r2 = x and
A41:      f.x0 - R < r2 and
A42:      r2 < f.x0 + R by A6;
          R <= fm - f.x0 by XXREAL_0:17;
          then f.x0 + R <= f.x0 + (fm - f.x0) by XREAL_1:7;
          then
A43:      r2 < fm by A42,XXREAL_0:2;
          R <= f.x0 - fp by XXREAL_0:17;
          then f.x0 - (f.x0 - fp) <= f.x0 - R by XREAL_1:13;
          then fp < r2 by A41,XXREAL_0:2;
          then r2 in ].fp,fm.[ by A43;
          then consider s such that
A44:      s in [.x0 - r/2, x0 + r/2.] and
A45:      x = f.s by A1,A23,A24,A17,A38,A40,A39,FCONT_2:15,XBOOLE_1:1;
          s in N by A10,A22,A44;
          then s in dom f /\ ].p,g.[ by A8,A14,XBOOLE_0:def 4;
          then
A46:      s in dom f1 by RELAT_1:61;
          then x = f1.s by A45,FUNCT_1:47;
          hence thesis by A46,FUNCT_1:def 3;
        end;
      end;
    end;
    hence ex N be Neighbourhood of r1 st N c= rng f1;
  end;
  hence thesis by RCOMP_1:20;
end;
