reserve x for object;
reserve x0,r,r1,r2,g,g1,g2,p,y0 for Real;
reserve n,m,k,l for Element of NAT;
reserve a,b,d for Real_Sequence;
reserve h,h1,h2 for non-zero 0-convergent Real_Sequence;
reserve c,c1 for constant Real_Sequence;
reserve A for open Subset of REAL;
reserve f,f1,f2 for PartFunc of REAL,REAL;
reserve L for LinearFunc;
reserve R for RestFunc;

theorem
  for f be one-to-one PartFunc of REAL,REAL st ].p,g.[ c= dom f & f
is_differentiable_on ].p,g.[ & ((for x0 st x0 in ].p,g.[ holds 0 < diff(f,x0))
or for x0 st x0 in ].p,g.[ holds diff(f,x0) < 0) holds f|].p,g.[ is one-to-one
& (f|].p,g.[)" is_differentiable_on dom ((f|].p,g.[)") & for x0 st x0 in dom ((
  f|].p,g.[)") holds diff((f|].p,g.[)",x0) = 1/diff(f,((f|].p,g.[)").x0)
proof
  let f be one-to-one PartFunc of REAL,REAL;
  set l = ].p,g.[;
  assume that
 l c= dom f and
A1: f is_differentiable_on l and
A2: (for x0 st x0 in l holds 0 < diff(f,x0)) or for x0 st x0 in l holds
  diff(f,x0) < 0;
A3: rng (f|l) is open by A1,A2,Th41;
  set f1 = f|l;
  thus f1 is one-to-one;
A4: dom (f1") = rng f1 by FUNCT_1:33;
A5: rng (f1") = dom f1 by FUNCT_1:33;
A6: for y0 being Element of REAL st y0 in dom (f1")
holds f1" is_differentiable_in y0 &
  diff(f1",y0) = 1/diff(f,(f1").y0)
  proof
    let y0 be Element of REAL;
    assume
A7: y0 in dom (f1");
    then consider x0 being Element of REAL such that
A8: x0 in dom f1 and
A9: y0 = f1.x0 by A4,PARTFUN1:3;
A10: for h,c st rng c = {y0} & rng (h + c) c= dom (f1") holds h"(#)((f1")
/*(h+c) - (f1")/*c) is convergent & lim (h"(#)((f1")/*(h+c) - (f1")/*c)) = 1/
    diff(f,(f1").y0)
    proof
A11:  f|l is increasing or f|l is decreasing
      proof
        per cases by A2;
        suppose
          for x0 st x0 in l holds 0 < diff(f,x0);
          hence thesis by A1,ROLLE:9;
        end;
        suppose
          for x0 st x0 in l holds diff(f,x0) < 0;
          hence thesis by A1,ROLLE:10;
        end;
      end;
      l c= dom f by A1;
      then f1"|(f.:l) is continuous by A11,FCONT_3:17;
      then
A12:  f1"|rng f1 is continuous by RELAT_1:115;
      y0 in dom(f1"|rng f1) by A4,A7,RELAT_1:69;
      then (f1")|rng f1 is_continuous_in y0 by A12,FCONT_1:def 2;
      then
A13:  f1" is_continuous_in y0 by A4,RELAT_1:68;
      reconsider fy =(f1").y0 as Element of REAL by XREAL_0:def 1;
      set a = seq_const (f1").y0;
      let h,c such that
A14:  rng c = {y0} and
A15:  rng (h + c) c= dom (f1");
A16:  lim (h + c) = y0 by A14,Th4;
      reconsider a as constant Real_Sequence;
      defpred P[Element of NAT,Real] means for r1,r2 be Real st
r1=(h + c).$1 & r2 = a.$1 holds r1 = f.(r2 + $2) & r2 + $2 in dom f & r2 + $2
      in dom (f|l);
A17:  for n ex r be Element of REAL st P[n,r]
      proof
        let n;
        (h + c).n in rng (h + c) by VALUED_0:28;
        then consider g being Element of REAL such that
A18:    g in dom f1 and
A19:    (h + c).n = f1.g by A4,A15,PARTFUN1:3;
        take r = g - x0;
        let r1,r2 be Real;
        assume that
A20:    r1 = (h + c).n and
A21:    r2 = a.n;
A22:    a.n = (f1").(f1.x0) by A9,SEQ_1:57
          .= x0 by A8,FUNCT_1:34;
        hence r1 = f.(r2 + r) by A18,A19,A20,A21,FUNCT_1:47;
        g in dom f /\ l by A18,RELAT_1:61;
        hence thesis by A18,A22,A21,XBOOLE_0:def 4;
      end;
      consider b such that
A23:  for n holds P[n,b.n] from FUNCT_2:sch 3(A17);
A24:  now
        let n;
A25:    (h + c).n = (h + c).n;
        then
A26:    a.n + b.n in dom f1 by A23;
        thus (((f1")/*(h+c)) - a).n = ((f1")/*(h+c)).n - a.n by RFUNCT_2:1
          .= (f1").((h + c).n) - a.n by A15,FUNCT_2:108
          .= (f1").(f.(a.n + b.n)) - a.n by A23
          .= (f1").(f1.(a.n + b.n)) - a.n by A23,A25,FUNCT_1:47
          .= a.n + b.n - a.n by A26,FUNCT_1:34
          .= b.n;
      end;
A27:  (f1")/*(h+c) is convergent by A15,A16,A13,FCONT_1:def 1;
      then ((f1")/*(h+c)) - a is convergent;
      then
A28:  b is convergent by A24,FUNCT_2:63;
A29:  lim a = a.0 by SEQ_4:26
        .= (f1").y0 by SEQ_1:57;
      (f1").y0 = lim ((f1")/*(h+c)) by A15,A16,A13,FCONT_1:def 1;
      then lim (((f1")/*(h+c)) - a) = (f1").y0 - (f1").y0 by A27,A29,SEQ_2:12
        .= 0;
      then
A30:  lim b = 0 by A24,FUNCT_2:63;
A31:  rng (b + a) c= dom f
      proof
        let x be object;
        assume x in rng (b + a);
        then consider n such that
A32:    x = (b + a).n by FUNCT_2:113;
A33:    (h+c).n = (h+c).n;
        x = a.n + b.n by A32,SEQ_1:7;
        hence thesis by A23,A33;
      end;
      (f1").y0 in dom f1 by A5,A7,FUNCT_1:def 3;
      then (f1").y0 in dom f /\ l by RELAT_1:61;
      then
A34:  (f1").y0 in l by XBOOLE_0:def 4;
      then
A35:  f is_differentiable_in (f1").y0 by A1,FDIFF_1:9;
A36:  now
        let n;
        c.n in rng c by VALUED_0:28;
        hence c.n = f1.x0 by A9,A14,TARSKI:def 1;
      end;
A37:  0 <> diff(f,(f1").y0) by A2,A34;
      now
        given n being Nat such that
A38:    b.n = 0;
A39:     n in NAT by ORDINAL1:def 12;
        a.n = (f1").(f1.x0) by A9,SEQ_1:57
          .= x0 by A8,FUNCT_1:34;
        then
A40:    f.(a.n + b.n) = f1.x0 by A8,A38,FUNCT_1:47;
        (h + c).n = h.n + c.n by SEQ_1:7
          .= h.n + f1.x0 by A36,A39;
        then h.n + f1.x0 = f1.x0 by A23,A40,A39;
        hence contradiction by SEQ_1:5;
      end;
      then
      b is non-zero by SEQ_1:5;
      then reconsider b as 0-convergent non-zero Real_Sequence by A28,A30,
FDIFF_1:def 1;
A41:  b" is non-zero by SEQ_1:33;
A42:  rng a = {(f1").y0}
      proof
        thus rng a c= {(f1").y0}
        proof
          let x be object;
          assume x in rng a;
          then ex n st x = a.n by FUNCT_2:113;
          then x = (f1").y0 by SEQ_1:57;
          hence thesis by TARSKI:def 1;
        end;
        let x be object;
        assume x in {(f1").y0};
        then x = (f1").y0 by TARSKI:def 1;
        then a.0 = x by SEQ_1:57;
        hence thesis by VALUED_0:28;
      end;
A43:  rng a c= dom f
      proof
        let x be object;
        assume x in rng a;
        then x = (f1").y0 by A42,TARSKI:def 1;
        then x = x0 by A8,A9,FUNCT_1:34;
        then x in dom f /\ l by A8,RELAT_1:61;
        hence thesis by XBOOLE_0:def 4;
      end;
      now
        let n;
A44:    (f1").y0 in rng (f1") by A7,FUNCT_1:def 3;
        c.n in rng c by VALUED_0:28;
        then
A45:    c.n = y0 by A14,TARSKI:def 1;
        thus (f/*a).n = f.(a.n) by A43,FUNCT_2:108
          .= f.((f1").y0) by SEQ_1:57
          .= f1.((f1").y0) by A5,A44,FUNCT_1:47
          .= c.n by A4,A7,A45,FUNCT_1:35;
      end;
      then
A46:  f/*a = c;
      now
        let n;
        (h + c).n = f.(a.n + b.n) by A23;
        then h.n + c.n = f.(a.n + b.n) by SEQ_1:7;
        hence h.n = f.(b.n + a.n) - (f/*a).n by A46
          .= f.((b + a).n) - (f/*a).n by SEQ_1:7
          .= (f/*(b+a)).n - (f/*a).n by A31,FUNCT_2:108
          .= (f/*(b+a) - f/*a).n by RFUNCT_2:1;
      end;
      then
A47:  h = f/*(b+a) - f/*a;
      then f/*(b+a) - f/*a is non-zero;
      then
A48:  b"(#)(f/*(b+a) - f/*a) is non-zero by A41,SEQ_1:35;
A49:  rng c c= dom (f1")
      by A7,A14,TARSKI:def 1;
      now
        let n;
A50:    (h + c).n = (h + c).n;
        then
A51:    a.n + b.n in dom f1 by A23;
        c.n in rng c by VALUED_0:28;
        then
A52:    c.n = y0 by A14,TARSKI:def 1;
        thus (h"(#)((f1")/*(h+c) - (f1")/*c)).n = (h").n * ((f1")/*(h+c) - (f1
        ")/*c).n by SEQ_1:8
          .= (h").n * (((f1")/*(h+c)).n - ((f1")/*c).n) by RFUNCT_2:1
          .= (h").n * ((f1").((h + c).n) - ((f1")/*c).n) by A15,FUNCT_2:108
          .= (h").n * ((f1").(f.(a.n + b.n)) - ((f1")/*c).n) by A23
          .= (h").n * ((f1").(f1.(a.n + b.n)) - ((f1")/*c).n) by A23,A50,
FUNCT_1:47
          .= (h").n * (a.n + b.n - ((f1")/*c).n) by A51,FUNCT_1:34
          .= (h").n * (a.n + b.n - (f1").(c.n)) by A49,FUNCT_2:108
          .= (h").n * (a.n + b.n - a.n) by A52,SEQ_1:57
          .= (h" (#) (b"")).n by SEQ_1:8
          .= ((b" (#) (f/*(b+a) - f/*a))").n by A47,SEQ_1:36;
      end;
      then
A53:  h
"(#)((f1")/*(h+c) - (f1")/*c) = (b"(#) (f/*(b+a) - f/*a))";
      diff(f,(f1").y0) = diff(f,(f1"). y0);
      then
A54:  b"(#)(f/*(b+a) - f/*a) is convergent by A42,A31,A35,Th12;
A55:  lim (b"(#)(f/*(b+a) - f/*a)) = diff(f,(f1").y0) by A42,A31,A35,Th12;
      hence h"(#) ((f1")/*(h+c) - (f1")/*c) is convergent by A53,A48,A54,A37,
SEQ_2:21;
      thus lim (h"(#)((f1")/*(h+c) - (f1")/*c)) = diff(f,(f1").y0)" by A53,A48
,A54,A55,A37,SEQ_2:22
        .= 1/diff(f,(f1").y0) by XCMPLX_1:215;
    end;
    ex N being Neighbourhood of y0 st N c= dom (f1") by A3,A4,A7,RCOMP_1:18;
    hence thesis by A10,Th12;
  end;
  then for y0 being Real holds y0 in dom (f1") implies f1"
  is_differentiable_in y0;
  hence f1" is_differentiable_on dom (f1") by A3,A4,FDIFF_1:9;
  let x0;
  assume x0 in dom (f1");
  hence thesis by A6;
end;
