reserve y for object, X for set;
reserve x,x0,x1,x2,g,g1,g2,r,r1,s,p,p1 for Real;
reserve n,m,k for Element of NAT;
reserve Y for Subset of REAL;
reserve Z for open Subset of REAL;
reserve s1,s3 for Real_Sequence;
reserve f,f1,f2 for PartFunc of REAL,REAL;
reserve h for non-zero 0-convergent Real_Sequence;
reserve c for constant Real_Sequence;
reserve R,R1,R2 for RestFunc;
reserve L,L1,L2 for LinearFunc;

theorem
  Z c= dom f & (for x st x in Z holds f.x = r*x + p) implies f
  is_differentiable_on Z & for x st x in Z holds (f`|Z).x = r
proof
  reconsider cf = REAL --> In(0,REAL) as Function of REAL, REAL;
  set R = cf;
  defpred P[set] means $1 in REAL;
  now
    let h;
A2: now
      let n be Nat;
A3:   rng h c= dom R;
A5:   n in NAT by ORDINAL1:def 12;
      thus ((h")(#)(R/*h)).n = (h".n)*((R/*h).n) by SEQ_1:8
        .=(h".n)*(R.(h.n)) by A5,A3,FUNCT_2:108
        .=(h".n)*0
        .=0;
    end;
    then
A6: (h")(#)(R/*h) is constant by VALUED_0:def 18;
    hence (h")(#)(R/*h) is convergent;
    ((h")(#)(R/*h)).0 = 0 by A2;
    hence lim ((h")(#)(R/*h)) = 0 by A6,SEQ_4:25;
  end;
  then reconsider R as RestFunc by Def2;
  assume that
A7: Z c= dom f and
A8: for x st x in Z holds f.x = r*x + p;
  deffunc G(Real) = In(r*$1,REAL);
  consider L being PartFunc of REAL,REAL such that
A9: (for x being Element of REAL holds x in dom L iff P[x]) &
     for x being Element of REAL st x in dom L holds L.x=G(x)
      from SEQ_1:sch 3;
  for r holds r in dom L iff r in REAL
   by A9;
  then dom L = REAL by Th1;
  then
A10: L is total by PARTFUN1:def 2;
A11: for x holds L.x=r*x
   proof let x;
     reconsider x as Element of REAL by XREAL_0:def 1;
     L.x=G(x) by A9;
    hence thesis;
   end;
  then reconsider L as LinearFunc by A10,Def3;
A12: now
    let x0;
    assume
A13: x0 in Z;
    then consider N being Neighbourhood of x0 such that
A14: N c= Z by RCOMP_1:18;
A15: for x st x in N holds f.x-f.x0=L.(x-x0)+R.(x-x0)
    proof
      let x;
     reconsider xx = x, xx0 = x0 as Element of REAL by XREAL_0:def 1;
      assume x in N;
      hence f.x-f.x0=r*x+p-f.x0 by A8,A14
        .=r*x+p - (r*x0+p) by A8,A13
        .=r*(x-x0)+0
        .=L.(xx-xx0)+0 by A11
        .=L.(x-x0)+R.(x-x0);
    end;
    N c= dom f by A7,A14;
    hence f is_differentiable_in x0 by A15;
  end;
  hence
A16: f is_differentiable_on Z by A7,Th9;
  let x0;
  assume
A17: x0 in Z;
  then consider N being Neighbourhood of x0 such that
A18: N c= Z by RCOMP_1:18;
A19: for x st x in N holds f.x-f.x0=L.(x-x0)+R.(x-x0)
  proof
    let x;
     reconsider xx = x, xx0 = x0 as Element of REAL by XREAL_0:def 1;
    assume x in N;
    hence f.x - f.x0 = r*x+p - f.x0 by A8,A18
      .=r*x+p-(r*x0+p) by A8,A17
      .=r*(x-x0)+0
      .=L.(xx-xx0) + 0 by A11
      .=L.(x-x0) + R.(x-x0);
  end;
A20: N c= dom f by A7,A18;
A21: f is_differentiable_in x0 by A12,A17;
  thus (f`|Z).x0 = diff(f,x0) by A16,A17,Def7
    .=L.1 by A21,A20,A19,Def5
    .=r*1 by A11
    .=r;
end;
