reserve a,b,c,d,e,x,r for Real,
  A for non empty closed_interval Subset of REAL,
  f,g for PartFunc of REAL,REAL;

theorem Th28:
  for x0 be Real, F be PartFunc of REAL,REAL st a <= b & f
is_integrable_on [' a,b '] & f|[' a,b '] is bounded & [' a,b '] c= dom f & ].a,
b.[ c= dom F & (for x be Real st x in ].a,b.[ holds F.x = integral(f,a,x
  )) & x0 in ].a,b.[ & f is_continuous_in x0 holds F is_differentiable_in x0 &
  diff(F,x0)=f.x0
proof
  deffunc F2(object) = 0;
  let x0 be Real, F be PartFunc of REAL,REAL;
  assume that
A1: a <= b and
A2: f is_integrable_on [' a,b '] and
A3: f|[' a,b '] is bounded and
A4: [' a,b '] c= dom f and
A5: ].a,b.[ c= dom F and
A6: for x be Real st x in ].a,b.[ holds F.x = integral(f,a,x) and
A7: x0 in ].a,b.[ and
A8: f is_continuous_in x0;
  defpred C1[object] means (x0+In($1,REAL)) in ].a,b.[;
  deffunc F0(Real)=In((f.x0)*$1,REAL);
  consider L be Function of REAL,REAL such that
A9: for h be Element of REAL holds L.h=F0(h) from FUNCT_2:sch 4;
A10: for h be Real holds L.h=(f.x0)*h
   proof let h be Real;
     reconsider h as Element of REAL by XREAL_0:def 1;
     L.h=F0(h) by A9;
    hence thesis;
   end;
  reconsider L as PartFunc of REAL,REAL;
  deffunc F1(object) = F.(x0+In($1,REAL))-F.x0-L.In($1,REAL);
  reconsider L as LinearFunc by A10,FDIFF_1:def 3;
  consider R be Function such that
A11: dom R=REAL & for x be object st x in REAL holds (C1[x] implies R.x =
  F1(x)) & (not C1[x] implies R.x = F2(x)) from PARTFUN1:sch 1;
  rng R c= REAL
  proof
    let y be object;
    assume y in rng R;
    then consider x be object such that
A12: x in dom R and
A13: y=R.x by FUNCT_1:def 3;
A14: not C1[x] implies R.x = F2(x) by A11,A12;
    C1[x] implies R.x = F1(x) by A11,A12;
    hence thesis by A13,A14,XREAL_0:def 1;
  end;
  then reconsider R as PartFunc of REAL,REAL by A11,RELSET_1:4;
A15: R is total by A11,PARTFUN1:def 2;
A16: [' a,b '] = [.a,b.] by A1,INTEGRA5:def 3;
A17: for h be 0-convergent non-zero Real_Sequence holds (h")(#)(R/*h) is
  convergent & lim ((h")(#)(R/*h)) = 0
  proof
    let h be 0-convergent non-zero Real_Sequence;
A18: for e be Real st 0<e ex n be Nat st
    for m be Nat st n <= m holds |.((h")(#)(R/*h)).m - 0 .| < e
    proof
       reconsider fx0 = f.x0 as Element of REAL by XREAL_0:def 1;
      set g = REAL --> fx0;
      let e0 be Real;
      set e=e0/2;
A19:  h is convergent & lim(h) = 0;
      assume
A20:  0 < e0;
      then 0 < e by XREAL_1:215;
      then consider p be Real such that
A21:  0 < p and
A22:  for t be Real st t in dom f & |.t - x0.| < p holds |.
      f.t - f.x0.| < e by A8,FCONT_1:3;
A23:  0 < p/2 by A21,XREAL_1:215;
A24:  p/2 < p by A21,XREAL_1:216;
      consider N be Neighbourhood of x0 such that
A25:  N c= ].a,b.[ by A7,RCOMP_1:18;
      consider q be Real such that
A26:  0<q and
A27:  N = ].x0-q,x0+q.[ by RCOMP_1:def 6;
A28:  q/2 < q by A26,XREAL_1:216;
      set r=min(p/2,q/2);
      0 < q/2 by A26,XREAL_1:215;
      then 0 < r by A23,XXREAL_0:15;
      then consider n be Nat such that
A29:  for m be Nat st n <= m holds |.h.m - 0 .|<r by A19,SEQ_2:def 7;
      take n;
      let m be Nat;
      r <= q/2 by XXREAL_0:17;
      then
A30:  ].x0-r,x0+r.[ c= ].x0-q,x0+q.[ by A28,Th2,XXREAL_0:2;
      assume n <= m;
      then
A31:  |.h.m - 0 .| < r by A29;
      then |.(x0 + h.m)-x0.| < r;
      then x0 + h.m in ].x0-r,x0+r.[ by RCOMP_1:1;
      then
A32:  x0 + h.m in ].x0-q,x0+q.[ by A30;
      then
A33:  x0+h.m in ].a,b.[ by A25,A27;
      then x0+In(h.m,REAL) in ].a,b.[;
      then R.(h.m)=F.(x0+In(h.m,REAL))-F.x0-L.In(h.m,REAL) by A11;
      then R.(h.m)=F.(x0+h.m)-F.x0-L.In(h.m,REAL);
      then R.(h.m) = F.(x0+h.m)-F.x0-L.(h.m);
      then
A34:  R.(h.m) = F.(x0+h.m)-F.x0-(f.x0)*h.m by A10;
      F.(x0+h.m) = integral(f,a,x0+h.m) by A6,A25,A27,A32;
      then
A35:  R.(h.m) =integral(f,a,x0+h.m ) -integral(f,a,x0) -(f.x0)*h.m by A6,A7,A34
;
A36:  dom g = REAL by FUNCT_2:def 1;
      then [' a,b '] /\ [' a,b '] c= dom f /\ dom g by A4,XBOOLE_1:27;
      then
A37:  [' a,b '] c= dom (f-g) by VALUED_1:12;
A38:  ].a,b.[ c= [.a,b.] by XXREAL_1:25;
      then
A39:  integral(f,a,x0+h.m) = integral(f,a,x0) +integral(f,x0,x0+h.m) by A1,A2
,A3,A4,A7,A16,A33,Th20;
A40:  r <= p/2 by XXREAL_0:17;
A41:  for x be Real st x in [' min(x0,x0+h.m),max(x0,x0+h.m) ']
      holds |.(f-g).x.| <= e
      proof
        let x be Real;
        reconsider x1 = x as Real;
A42:    min(x0,x0+h.m) <= x0 & x0 <= max(x0,x0+h.m) by XXREAL_0:17,25;
        assume x in [' min(x0,x0+h.m),max(x0,x0+h.m) '];
        then
A43:    x in [. min(x0,x0+h.m),max(x0,x0+h.m) .] by A42,INTEGRA5:def 3
,XXREAL_0:2;
        |.x-x0.| <=|.h.m.|
        proof
          per cases;
          suppose
            x0<= x0+h.m;
            then x0 = min(x0,x0+h.m) & x0+h.m = max(x0,x0+h.m) by
XXREAL_0:def 9,def 10;
            then x in {z where z is Real:
          x0<=z & z<=x0+h.m } by A43,
RCOMP_1:def 1;
            then
A44:        ex z be Real st x=z & x0<=z & z<=x0+h.m;
            then 0 <= x-x0 by XREAL_1:48;
            then
A45:        |.x-x0.| = x-x0 by ABSVALUE:def 1;
A46:        x-x0 <= x0+h.m - x0 by A44,XREAL_1:9;
            then 0 <= h.m by A44,XREAL_1:48;
            hence thesis by A46,A45,ABSVALUE:def 1;
          end;
          suppose
A47:        not x0<=x0 +h.m;
            then x0 = max(x0,x0+h.m) & x0+h.m = min(x0,x0+h.m) by
XXREAL_0:def 9,def 10;
            then x in {z where z is Real:
      x0+h.m<=z & z<=x0 } by A43,
RCOMP_1:def 1;
            then
A48:        ex z be Real st x=z & x0+h.m<=z & z<=x0;
            then
A49:        x0 +h.m -x0 <= x-x0 by XREAL_1:9;
            per cases;
            suppose
A50:          x-x0 <> 0;
              x0 + h.m - x0 < x0-x0 by A47,XREAL_1:14;
              then
A51:          |.h.m.| = -(h.m) by ABSVALUE:def 1;
              x-x0 < 0 by A48,A50,XREAL_1:47;
              then |.x-x0.| = -(x-x0) by ABSVALUE:def 1;
              hence thesis by A49,A51,XREAL_1:24;
            end;
            suppose
              x-x0 = 0;
              then |.x-x0.| = 0 by ABSVALUE:def 1;
              hence thesis by COMPLEX1:46;
            end;
          end;
        end;
        then
A52:    |.x-x0.| < r by A31,XXREAL_0:2;
        then x in ].x0-r,x0+r.[ by RCOMP_1:1;
        then x in ].x0-q,x0+q.[ by A30;
        then x in ].a,b.[ by A25,A27;
        then
A53:    x in [.a,b.] by A38;
A54:     x1 in REAL by XREAL_0:def 1;
        |.x-x0.| < p/2 by A40,A52,XXREAL_0:2;
        then |.x-x0.| < p by A24,XXREAL_0:2;
        then |.f.x- f.x0.|<=e by A4,A16,A22,A53;
        then |.f.x1- g.x1.|<=e by FUNCOP_1:7,A54;
        hence thesis by A16,A37,A53,VALUED_1:13;
      end;
A55:  for x be Real st x in [' a,b '] holds g.x = f.x0 by FUNCOP_1:7;
      then
A56:  g|[' a,b '] is bounded by A1,A36,Th26;
      then
A57:  (f-g)|(['a,b '] /\ ['a,b ']) is bounded by A3,RFUNCT_1:84;
A58:   m in NAT by ORDINAL1:def 12;
      rng h c= dom R by A11;
      then R.(h.m)/(h.m) =(R/*h).m /(h.m) by FUNCT_2:108,A58;
      then R.(h.m)/(h.m) =((R/*h).m) *((h").m) by VALUED_1:10;
      then
A59:  R.(h.m)/(h.m) = ((h")(#)(R/*h)).m by SEQ_1:8;
      h.m <> 0 by SEQ_1:4,A58;
      then
A60:  0 < |.h.m.| by COMPLEX1:47;
A61:  g is_integrable_on [' a,b '] by A1,A36,A55,Th26;
      then f-g is_integrable_on [' a,b '] by A2,A3,A4,A36,A56,Th11;
      then
A62:  |.integral(f-g,x0,x0+h.m).| <= e*|.x0+h.m-x0.| by A1,A7,A16,A38,A33,A57
,A37,A41,Lm8;
      integral(g,x0,x0+h.m)=(f.x0)*((x0+h.m)-x0) by A1,A7,A16,A38,A33,A36,A55
,Th27;
      then R.(h.m) =integral(f-g,x0,x0+h.m) by A1,A2,A3,A4,A7,A16,A38,A33,A35
,A36,A61,A56,A39,Th24;
      then |.R.(h.m)/(h.m).| = |.R.(h.m).|/|.h.m.| & |.R.(h.m).|/|.h.m.|
      <= e*|. h.m.|/|.h.m.| by A62,A60,COMPLEX1:67,XREAL_1:72;
      then
A63:  |.R.(h.m)/(h.m).| <= e by A60,XCMPLX_1:89;
      e < e0 by A20,XREAL_1:216;
      hence thesis by A63,A59,XXREAL_0:2;
    end;
    hence (h")(#)(R/*h) is convergent by SEQ_2:def 6;
    hence thesis by A18,SEQ_2:def 7;
  end;
  consider N be Neighbourhood of x0 such that
A64: N c= ].a,b.[ by A7,RCOMP_1:18;
  reconsider R as RestFunc by A15,A17,FDIFF_1:def 2;
A65: for x be Real st x in N holds F.x-F.x0 = L.(x-x0) + R.(x-x0)
  proof
    let x be Real;
    assume x in N;
    then
A66:x0 + (x-x0) in N;
    reconsider x as Real;
A67:  x0+(x-x0) in N by A66;
     C1[x-x0] by A67,A64;
     then R.(x-x0) = F1(x-x0) by A11;
    hence thesis;
  end;
A68: N c= dom F by A5,A64;
  hence
A69: F is_differentiable_in x0 by A65,FDIFF_1:def 4;
  L.1=(f.x0)*1 by A10;
  hence thesis by A68,A65,A69,FDIFF_1:def 5;
end;
