reserve n for Nat,
  i for Integer,
  p, x, x0, y for Real,
  q for Rational,
  f for PartFunc of REAL,REAL;

theorem
  for n be Nat, f be PartFunc of REAL,REAL, x0,r be Real st
].x0-r,x0+r.[ c= dom f & 0 < r & f is_differentiable_on n+1, ].x0-r,x0+r.[
for  x be Real st x in ].x0-r, x0+r.[
 ex s be Real st 0 < s & s < 1 & f.x=
Partial_Sums(Taylor(f, ].x0-r,x0+r.[,x0,x)).n + (diff(f,].x0-r,x0+r.[).(n+1)).(
  x0+s*(x-x0)) * (x-x0) |^ (n+1) / ((n+1)!)
proof
  let n be Nat;
  let f be PartFunc of REAL,REAL;
  let x0,r be Real such that
A1: ].x0-r,x0+r.[ c= dom f and
A2: 0 < r and
A3: f is_differentiable_on n+1, ].x0-r,x0+r.[;
  let x be Real such that
A4: x in ].x0-r, x0+r.[;
  now
    per cases by XXREAL_0:1;
    case
A5:   x < x0;
      |.x0-x0.|=0 by ABSVALUE:2;
      then x0 in ].x0-r, x0+r.[ by A2,RCOMP_1:1;
      then
A6:   [.x,x0.] c= ].x0-r,x0+r.[ by A4,XXREAL_2:def 12;
      diff(f,].x0-r,x0+r.[).n is_differentiable_on ].x0-r,x0+r.[ by A3;
      then (diff(f,].x0-r,x0+r.[).n)|].x0-r,x0+r.[ is continuous by FDIFF_1:25;
      then
A7:   (diff(f,].x0-r,x0+r.[).n)|[.x,x0.] is continuous by A6,FCONT_1:16;
A8:   f is_differentiable_on n, ].x0-r,x0+r.[ by A3,Th23,NAT_1:11;
      set t= x0-x;
A9:   t > 0 by A5,XREAL_1:50;
A10:  ].x,x0.[ c= [.x,x0.] by XXREAL_1:25;
      then f is_differentiable_on n+1, ].x,x0.[ by A3,A6,Th31,XBOOLE_1:1;
      then consider c be Real such that
A11:  c in ].x,x0.[ and
A12:  f.x=Partial_Sums(Taylor(f, ].x0-r,x0+r.[,x0,x)).n + (diff(f,].x
      ,x0.[).(n+1)).c * (x-x0) |^ (n+1) /((n+1)!) by A1,A5,A6,A8,A7,Th29;
      take s=(x0-c)/t;
A13:  x0+s*(x-x0) =x0-((x0-c)/t)*t .=x0-(x0-c) by A9,XCMPLX_1:87
        .=c;
      c in {p where p is Real : x0-t<p & p<x0} by A11,RCOMP_1:def 2;
      then
A14:  ex g be Real st g=c & x0-t<g & g<x0;
      then 0<x0-c by XREAL_1:50;
      then 0/t < (x0-c)/t by A9,XREAL_1:74;
      hence 0<s;
      x0-t+t < c+t by A14,XREAL_1:8;
      then x0-c < t by XREAL_1:19;
      then (x0-c)/t<t/t by A9,XREAL_1:74;
      hence s<1 by A9,XCMPLX_1:60;
      diff(f,].x,x0.[).(n+1).c = (diff(f,].x0-r,x0+r.[).(n+1) |].x,x0.[).
      c by A3,A6,A10,Th30,XBOOLE_1:1
        .= (diff(f,].x0-r,x0+r.[).(n+1)).c by A11,FUNCT_1:49;
      hence
      f.x=Partial_Sums(Taylor(f, ].x0-r,x0+r.[,x0,x)).n + (diff(f,].x0-r,
      x0+r.[).(n+1)).(x0+s*(x-x0)) * (x-x0) |^ (n+1) /((n+1)!) by A12,A13;
    end;
    case
A15:  x = x0;
      set s=1/2;
      take s;
      thus 0 < s & s < 1;
      set c = x0+s*(x-x0);
      thus Partial_Sums(Taylor(f, ].x0-r,x0+r.[,x0,x)).n + (diff(f,].x0-r,x0+r
.[).(n+1)).(x0+s*(x-x0)) * (x-x0) |^ (n+1) /((n+1)!) =f.x + (diff(f,].x0-r,x0+r
      .[).(n+1)).c * (x-x) |^ (n+1) /((n+1)!) by A4,A15,Th32
        .=f.x + (diff(f,].x0-r,x0+r.[).(n+1)).c * (0|^n*0) /((n+1)!) by
NEWTON:6
        .=f.x;
    end;
    case
A16:  x > x0;
      set t= x-x0;
A17:  f is_differentiable_on n, ].x0-r,x0+r.[ by A3,Th23,NAT_1:11;
      |.x0-x0.|=0 by ABSVALUE:2;
      then x0 in ].x0-r, x0+r.[ by A2,RCOMP_1:1;
      then
A18:  [.x0,x.] c= ].x0-r,x0+r.[ by A4,XXREAL_2:def 12;
      diff(f,].x0-r,x0+r.[).n is_differentiable_on ].x0-r,x0+r.[ by A3;
      then (diff(f,].x0-r,x0+r.[).n)|].x0-r,x0+r.[ is continuous by FDIFF_1:25;
      then
A19:  (diff(f,].x0-r,x0+r.[).n)|[.x0,x.] is continuous by A18,FCONT_1:16;
A20:  ].x0,x.[ c= [.x0,x.] by XXREAL_1:25;
      then f is_differentiable_on n+1, ].x0,x.[ by A3,A18,Th31,XBOOLE_1:1;
      then consider c be Real such that
A21:  c in ].x0,x.[ and
A22:  f.x=Partial_Sums(Taylor(f, ].x0-r,x0+r.[,x0,x)).n + (diff(f,].
      x0,x.[).(n+1)).c * (x-x0) |^ (n+1) /((n+1)!) by A1,A16,A18,A17,A19,Th27;
      take s=(c-x0)/t;
A23:  t > 0 by A16,XREAL_1:50;
      then
A24:  x0+s*(x-x0) = x0+(c-x0) by XCMPLX_1:87
        .=c;
      c in {p where p is Real : x0<p & p<x0+t} by A21,RCOMP_1:def 2;
      then
A25:  ex g be Real st g=c & x0<g & g<x0+t;
      then 0<c-x0 by XREAL_1:50;
      then 0/t < (c-x0)/t by A23,XREAL_1:74;
      hence 0<s;
      c-x0<t by A25,XREAL_1:19;
      then (c-x0)/t<t/t by A23,XREAL_1:74;
      hence s<1 by A23,XCMPLX_1:60;
      diff(f,].x0,x.[).(n+1).c = (diff(f,].x0-r,x0+r.[).(n+1) |].x0,x.[).
      c by A3,A18,A20,Th30,XBOOLE_1:1
        .= (diff(f,].x0-r,x0+r.[).(n+1)).c by A21,FUNCT_1:49;
      hence
      f.x=Partial_Sums(Taylor(f, ].x0-r,x0+r.[,x0,x)).n + (diff(f,].x0-r,
      x0+r.[).(n+1)).(x0+s*(x-x0)) * (x-x0) |^ (n+1) /((n+1)!) by A22,A24;
    end;
  end;
  hence thesis;
end;
