reserve n for Nat,
        p,p1,p2 for Point of TOP-REAL n,
        x for Real;
reserve n,m for non zero Nat;
reserve i,j for Nat;
reserve f for PartFunc of REAL-NS m,REAL-NS n;
reserve g for PartFunc of REAL m,REAL n;
reserve h for PartFunc of REAL m,REAL;
reserve x for Point of REAL-NS m;
reserve y for Element of REAL m;
reserve X for set;

theorem Th47:
for m be non zero Nat, f be PartFunc of REAL m,REAL 1,
  X be Subset of REAL m,
  x be Element of REAL m
 st X is open & x in X &
   (for i be Nat st 1 <=i & i <= m holds
      f is_partial_differentiable_on X,i &
      f`partial|(X,i) is_continuous_on X) holds
  f is_differentiable_in x &
  for h be Element of REAL m
   ex w be FinSequence of REAL 1 st
    dom w = Seg m &
    (for i be Nat st i in Seg m holds
          w.i = (proj(i,m).h)*(partdiff(f,x,i)) )
   & diff(f,x).h = Sum w
proof
   let m be non zero Nat,
       f be PartFunc of REAL m,REAL 1,
       X be Subset of REAL m,
       x be Element of REAL m;
   assume
A1: X is open & x in X & for i be Nat st 1 <=i & i <= m holds
      f is_partial_differentiable_on X,i &
      f`partial|(X,i) is_continuous_on X;
   consider L be Lipschitzian LinearOperator of m,1 such that
A2:for h be Element of REAL m ex w be FinSequence of REAL 1 st dom w = Seg m &
      (for i be Nat st i in Seg m holds
          w.i = (proj(i,m).h)*(partdiff(f,x,i)) ) &
      L.h = Sum w by Lm8;
   consider d0 be Real such that
A3:d0 >0 and
A4:{y where y is Element of REAL m: |. y-x .| < d0} c= X by A1,Th31;
   set N = {y where y is Element of REAL m: |. y-x .| < d0};
    1 <= m by NAT_1:14;
   then f is_partial_differentiable_on X,m by A1;
   then X c= dom f;
then
A5:
   N c= dom f by A4;
   deffunc RF(Element of REAL m) = f/.(x+$1) - f/.x - L.$1;
   consider R be Function of REAL m,REAL 1 such that
A6:for h be Element of REAL m holds R.h = RF(h) from FUNCT_2:sch 4;
   consider f0 be PartFunc of REAL m,REAL such that
A7: f=<>*f0 by Th29;
A8: now let r0 be Real;
    assume A9: r0 > 0;
    set r1=r0/2;
    set r=r1/m;
    defpred DSQ[Nat, Real] means
     ex k be Nat st $1=k & 0 < $2 &
      for q be Element of REAL m st q in X & |. q-x .| < $2 holds
       |. partdiff(f,q,k)- partdiff(f,x,k) .| < r;
A10:for k0 be Nat st k0 in Seg m holds
    ex d be Element of REAL st DSQ[k0,d]
    proof
     let k0 be Nat;
     assume A11: k0 in Seg m;
     reconsider k = k0 as Nat;
A12:1 <= k & k <= m by A11,FINSEQ_1:1;
     then f`partial|(X,k) is_continuous_on X by A1;
     then consider d be Real such that
A13:  0 < d & for q be Element of REAL m st q in X & |. q- x .| < d holds
       |. (f`partial|(X,k))/.q - (f`partial|(X,k))/.x .| < r
          by A9,A1,Th38;
      reconsider d as Element of REAL by XREAL_0:def 1;
     take d;
      for q be Element of REAL m st q in X & |. q- x .| < d holds
       |. partdiff(f,q,k) - partdiff(f,x,k) .| < r
     proof
      let q be Element of REAL m;
      assume A14:q in X & |. q- x .| < d;
then A15:  |. (f`partial|(X,k))/.q - (f`partial|(X,k))/.x .| < r by A13;
A16:  f is_partial_differentiable_on X,k by A1,A12;
      then (f`partial|(X,k))/.q = partdiff(f,q,k) by A14,Def5;
      hence |. partdiff(f,q,k)- partdiff(f,x,k) .|<r by A15,A16,A1,Def5;
     end;
     hence ex k be Nat st k0=k & 0 < d &
      for q be Element of REAL m st q in X & |. q-x .| < d holds
       |. partdiff(f,q,k) - partdiff(f,x,k) .| < r by A13;
    end;
    consider Dseq be FinSequence of REAL such that
A17: dom Dseq = Seg m &
     for i be Nat st i in Seg m holds DSQ[i,Dseq.i] from FINSEQ_1:sch 5(A10);
A18:rng Dseq is finite by A17,FINSET_1:8;
     m in Seg m by FINSEQ_1:3;
    then reconsider rDseq = rng Dseq as non empty ext-real-membered set
      by A17,FUNCT_1:3;
    reconsider rDseq as left_end right_end non empty ext-real-membered set
      by A18;
A19:min rDseq in rng Dseq by XXREAL_2:def 7;
    reconsider d1 = min rDseq as Real;
    set d = min(d0,d1);
    consider i1 be object such that
A20: i1 in dom Dseq & d1 = Dseq.i1 by A19,FUNCT_1:def 3;
    reconsider i1 as Nat by A20;
A21:ex k be Nat st i1=k & 0 < Dseq.i1 &
     for q be Element of REAL m st q in X & |. q-x .| < Dseq.i1 holds
       |. partdiff(f,q,k) - partdiff(f,x,k) .| < r by A17,A20;
A22:now let q be Element of REAL m;
     assume A23: |. q-x .| < d;
     d <= d0 by XXREAL_0:17;
     then |. q-x .| < d0 by A23,XXREAL_0:2;
     then q in {y where y is Element of REAL m: |. y-x .| < d0};
     hence q in X by A4;
    end;
A24:now let q be Element of REAL m, i be Nat;
     assume A25: |. q-x .| < d & i in Seg m;
     reconsider i0=i as Nat;
     consider k be Nat such that
A26: i0 = k & 0 < Dseq.i0 &
      for q be Element of REAL m st q in X & |. q-x .| < Dseq.i0 holds
       |. partdiff(f,q,k) - partdiff(f,x,k) .| < r by A17,A25;
      Dseq.i0 in rng Dseq by A17,A25,FUNCT_1:3;
 then A27:d1 <= Dseq.i0 by XXREAL_2:def 7;
      d <= d1 by XXREAL_0:17;
     then d <= Dseq.i0 by A27,XXREAL_0:2;
     then |. q-x .| < Dseq.i0 by A25,XXREAL_0:2;
     hence |. partdiff(f,q,i) - partdiff(f,x,i) .| < r by A22,A25,A26;
    end;
    take d;
    thus 0 < d by A3,A20,A21,XXREAL_0:21;
    thus for y be Element of REAL m,z be Element of REAL 1 st
       y <> 0*m & |.y.| < d & z=R.y holds |.y.|"* |. z .| < r0
    proof
     let y be Element of REAL m, z be Element of REAL 1;
     assume A28: y <> 0*m & |. y .|< d & z = R.y;
     consider h be FinSequence of REAL m, g be FinSequence of REAL 1 such that
A29:  len h = m+1 & len g = m
     & (for i be Nat st i in dom h holds h/.i = (y| (m+1-'i))^(0*(i-'1)))
     & (for i be Nat st i in dom g holds g/.i = f/.(x+h/.i) - f/.(x+h/.(i+1)))
     & (for i be Nat, hi be Element of REAL m st i in dom h & h/.i= hi
           holds |. hi .| <=|. y .|)
     & f/.(x+y) - f/.x = Sum g by Th28;
A30: R/.y = Sum g - L.y by A6,A29;
     consider w be FinSequence of REAL 1 such that
A31: dom w = Seg m & (for i be Nat st i in Seg m holds
           w.i = (proj(i,m).y)*(partdiff(f,x,i)) ) &
      L.y = Sum w by A2;
       idseq m is Permutation of Seg m by FINSEQ_2:55;
      then A32: dom idseq m = Seg m & rng idseq m = Seg m &
      idseq m is one-to-one by FUNCT_2:def 1,def 3;
      then A33: dom Rev idseq m = Seg m &
      rng Rev idseq m = Seg m by FINSEQ_5:57;
      then
reconsider Ri=Rev idseq m as Function of Seg m,Seg m by FUNCT_2:1;
       Ri is one-to-one onto by A33,FUNCT_2:def 3;
      then reconsider Ri=Rev idseq m as Permutation of dom w by A31;
    reconsider mm=m as Element of NAT by ORDINAL1:def 12;
      A34: len (idseq m) = mm by A32,FINSEQ_1:def 3
      .= len w by A31,FINSEQ_1:def 3;
      A35: dom (w (*) Ri) = dom Ri by A33,RELAT_1:27
      .= dom Rev w by A33,A31,FINSEQ_5:57;
       now
        let k be Nat;
        assume A36: k in dom Rev w;
        then A37: k in dom Rev idseq m by A33,A31,FINSEQ_5:57;
        then A38: 1 <= k & k <= m by A33,FINSEQ_1:1;
        then reconsider mk=m-k as Nat by NAT_1:21;
    reconsider mm=m as Element of NAT by ORDINAL1:def 12;
        A39: len idseq m = mm by A32,FINSEQ_1:def 3;
         0 <= mk;
        then A40: 0+1 <= m - k + 1 by XREAL_1:6;
         k-1 >= 1-1 by A38,XREAL_1:9;
        then m-(k-1) <= m by XREAL_1:43;
        then A41: mk+1 in Seg m by A40;
        thus (Rev w).k = w.(len (idseq m) - k + 1) by A34,A36,FINSEQ_5:def 3
        .= w.((idseq m).(len (idseq m) - k + 1)) by A41,A39,FINSEQ_2:49
        .= w.((Rev idseq m).k) by A37,FINSEQ_5:def 3
        .= (w (*) Ri).k by A36,A35,FUNCT_1:12;
      end;
then A42: Sum Rev w = Sum w by A35,EUCLID_7:21,FINSEQ_1:13;
     deffunc GW(Nat) = g/.$1 - (Rev w)/.$1;
     consider gw be FinSequence of REAL 1 such that
A43:len gw =m &
      for j being Nat st j in dom gw holds gw.j = GW(j) from FINSEQ_2:sch 1;
A44:now let j be Nat;
      assume A45:j in dom gw;
      hence gw/.j = gw.j by PARTFUN1:def 6
                 .= g/.j - (Rev w)/.j by A45,A43;
     end;
    reconsider mm=m as Element of NAT by ORDINAL1:def 12;
A46: len w = mm by A31,FINSEQ_1:def 3;
     then len Rev w = m by FINSEQ_5:def 3;
then A47:R/.y = Sum gw by A29,A30,A31,A43,A44,A42,Th27;
A48: for j be Nat st j in dom gw
      ex gwj be Element of REAL 1 st gw.j=gwj & |. gwj .| <= |. y .|*r
     proof
      let j be Nat;
      assume A49: j in dom gw;
then A50:  j in Seg m by A43,FINSEQ_1:def 3;
then j in dom g by A29,FINSEQ_1:def 3;
then A51:  g/.j = f/.(x+h/.j) - f/.(x+h/.(j+1)) by A29;
A52: 1 <= j & j <=m by A50,FINSEQ_1:1;
      then m+1 <= m+j & j+1 <= m+1 by XREAL_1:6;
      then m+1-j <= m & 1 <= m+1-j by XREAL_1:19,20;
then A53: m+1-'j <= m & 1 <= m+1-'j by A52,NAT_D:37;
then A54:  f is_partial_differentiable_on X,(m+1-'j) by A1;
then A55:  X c=dom f & for x be Element of REAL m st x in X holds
       f is_partial_differentiable_in x,(m+1-'j) by A53,Th34,A1;
A56: m+1-'j in Seg m by A53;
then A57:  w/.(m+1-'j) = w.(m+1-'j) by A31,PARTFUN1:def 6
          .= (proj((m+1-'j),m).y)*(partdiff(f,x,(m+1-'j))) by A31,A56;
A58:  now let j be Nat;
       assume 1 <= j & j <= m + 1;
       then j in Seg(m+1);
then A59:   j in dom h by A29,FINSEQ_1:def 3;
A60:  (x+h/.j)-x = h/.j by RVSUM_1:42;
       reconsider hj = h/.j as Element of REAL m;
       |. hj .| <= |. y .| by A29,A59;
       hence |. (x+h/.j)-x .| < d by A60,A28,XXREAL_0:2;
      end;
       rng f0 c= dom (proj(1,1) qua Function") by PDIFF_1:2;
then A61:dom f = dom f0 by A7,RELAT_1:27;
       m <= m+1 by NAT_1:11;
      then Seg m c= Seg(m+1) by FINSEQ_1:5;
      then 1 <= j & j <= m + 1 by A50,FINSEQ_1:1;
then A62:  |. (x+h/.j)-x .| < d by A58;
      then A63: x+h/.j in X by A22;
then A64:  f/.(x+h/.j) = (<>*f0).(x+h/.j) by A55,A7,PARTFUN1:def 6
          .= (proj(1,1) qua Function").(f0.(x+h/.j)) by A63,A55,A61,FUNCT_1:13
          .= <* f0.(x+h/.j) *> by PDIFF_1:1
          .= <* f0/.(x+h/.j) *> by A63,A55,A61,PARTFUN1:def 6;
A65:  1 <= j & j <= m by A50,FINSEQ_1:1;
A66:  1 <= j+1 by NAT_1:11;
A67:   j+1 <= m+1 by A65,XREAL_1:6;
then A68:  |. (x+h/.(j+1))-x .| < d by A66,A58;
      then A69: x+h/.(j+1) in X by A22;
then A70: f/.(x+h/.(j+1)) = (<>*f0).(x+h/.(j+1)) by A55,A7,PARTFUN1:def 6
       .= (proj(1,1) qua Function").(f0.(x+h/.(j+1))) by A69,A55,A61,FUNCT_1:13
       .= <* f0.(x+h/.(j+1)) *> by PDIFF_1:1
       .= <* f0/.(x+h/.(j+1)) *> by A69,A55,A61,PARTFUN1:def 6;
       f is_partial_differentiable_in x,(m+1-'j) by A54,A53,Th34,A1;
then A71:  partdiff(f,x,(m+1-'j)) = <*partdiff(f0,x,(m+1-'j))*> by A7,
PDIFF_1:19;
then A72:  (proj((m+1-'j),m).y)*(partdiff(f,x,(m+1-'j)))
        = <* (proj((m+1-'j),m).y)*(partdiff(f0,x,(m+1-'j))) *>
           by RVSUM_1:47;
A73:  f/.(x+h/.j) - f/.(x+h/.(j+1))
        = <* f0/.(x+h/.j) - f0/.(x+h/.(j+1)) *> by A64,A70,RVSUM_1:29;
A74: X c= dom f0 & for x be Element of REAL m st x in X holds
        f0 is_partial_differentiable_in x,(m+1-'j)
      proof
       thus X c=dom f0 by A54,A61;
       let x be Element of REAL m;
       assume x in X;
       then f is_partial_differentiable_in x,(m+1-'j) by A54,A53,Th34,A1;
       hence f0 is_partial_differentiable_in x,(m+1-'j) by A7,PDIFF_1:18;
      end;
A75:  x + h/.j = reproj(m+1-'j,(x+h/.(j+1))).(proj(m+1-'j,m).(x+y))
        by Th46,A29,A65;
       m+1-'(j+1) = m+1-(j+1) by A67,XREAL_1:233;
      then m+1-'(j+1) = m-j;
then A76:   m+1-'(j+1) = m-'j by A65,XREAL_1:233;
A77:  (j+1)-'1 = (j+1)-1 by NAT_1:11,XREAL_1:233;
      consider q be Element of REAL m such that
A78:   |. q - x .| < d & f0 is_partial_differentiable_in q,(m+1-'j) &
       f0/.(x+h/.j) - f0 /.(x+h/.(j+1))
        = ( (proj(m+1-'j,m).(x+y)) - proj(m+1-'j,m).(x+h/.(j+1)) )*
             (partdiff(f0,q,m+1-'j))
          by A62,A68,A75,A53,A74,A22,A1,Th45;
A79:  |. partdiff(f,q,(m+1-'j)) - partdiff(f,x,(m+1-'j)) .| < r by A78,A56,A24;
       f is_partial_differentiable_in q,(m+1-'j) by A78,A7,PDIFF_1:18;
then A80:  partdiff(f,q,(m+1-'j)) = <*partdiff(f0,q,(m+1-'j))*> by A7,
PDIFF_1:19;
      set mij=m+1-'j;
      set mj=m-'j;
      reconsider hj1=h/.(j+1) as Element of REAL m;
A81:   len x = m & len y = m & len hj1 = m by CARD_1:def 7;
      then mij in dom x & mij in dom y & mij in dom hj1 by A56,FINSEQ_1:def 3;
      then mij in dom x /\ dom y & mij in dom x /\ dom hj1 by XBOOLE_0:def 4;
      then
A82:   mij in dom (x+y) & mij in dom (x+hj1) by VALUED_1:def 1;
       j+1 in Seg(m+1) by A66,A67;
      then j+1 in dom h by A29,FINSEQ_1:def 3;
then A83:    h/.(j+1) = (y| mj)^(0*j) by A29,A76,A77;
A84:   len (y|mj) = mj by A81,FINSEQ_1:59,NAT_D:35;
   mij = mj+1 by A65,NAT_D:38;
      then mij > len (y|mj) by A84,NAT_1:13;
      then A85:   hj1.mij = (0*j).(mij-mj) by A53,A81,A83,A84,FINSEQ_1:24
      .= 0;
A86:  (proj(m+1-'j,m).(x+y)) - proj(m+1-'j,m).(x+h/.(j+1))
       = (x+y).mij - proj(m+1-'j,m).(x+h/.(j+1)) by PDIFF_1:def 1
      .= (x+y).mij - (x+h/.(j+1)).mij by PDIFF_1:def 1
      .= x . mij + y.mij - (x+h/.(j+1)).mij by A82,VALUED_1:def 1
      .= x . mij + y.mij - (x . mij + 0) by A85,A82,VALUED_1:def 1
      .= proj(m+1-'j,m).y by PDIFF_1:def 1;
      reconsider gwj=gw/.j as Element of REAL 1;
      take gwj;
      thus gw.j=gwj by A49,PARTFUN1:def 6;
A87:  m+1-'j = m+1-j by A65,NAT_1:12,XREAL_1:233;
       j in Seg len (Rev w) by A50,A46,FINSEQ_5:def 3;
then A88:  j in dom Rev w by FINSEQ_1:def 3;
then (Rev w)/.j = (Rev w).j by PARTFUN1:def 6
        .= w.(m-j+1) by A46,A88,FINSEQ_5:def 3
        .= w/.(m+1-'j) by A87,A56,A31,PARTFUN1:def 6;
      then gw/.j = g/.j - w/.(m+1-'j) by A49,A44
           .= <* (proj(m+1-'j,m).y)*(partdiff(f0,q,m+1-'j))
                 - (proj(m+1-'j,m).y)*(partdiff(f0,x,m+1-'j)) *>
                 by A78,A86,A57,A51,A72,A73,RVSUM_1:29
           .= <* (proj(m+1-'j,m).y)*((partdiff(f0,q,m+1-'j))
                      - (partdiff(f0,x,m+1-'j))) *>
           .= (proj(m+1-'j,m).y)* <* partdiff(f0,q,m+1-'j)
                  - partdiff(f0,x,m+1-'j) *> by RVSUM_1:47
           .= (proj(m+1-'j,m).y)*(partdiff(f,q,m+1-'j) - partdiff(f,x,m+1-'j))
               by A71,A80,RVSUM_1:29;
then A89:  |. gwj .| = |.(proj(m+1-'j,m).y).| *
          |. partdiff(f,q,m+1-'j) - partdiff(f,x,m+1-'j) .| by EUCLID:11;
       0 <= |.(proj(m+1-'j,m).y).| by COMPLEX1:46;
then A90: |. gwj .| <= |.(proj(m+1-'j,m).y).|*r by A89,A79,XREAL_1:64;
       |.y.(m+1-'j).| <= |.y.| by A56,REAL_NS1:8;
      then |.(proj(m+1-'j,m).y).| <= |. y .| by PDIFF_1:def 1;
      then |.(proj(m+1-'j,m).y).|*r <= |. y .|*r by A9,XREAL_1:64;
      hence |. gwj .| <= |. y .|*r by A90,XXREAL_0:2;
     end;
     defpred YSQ[set,set] means
        ex v be Element of REAL 1 st v = gw.$1 & $2 = |. v .|;
A91: now let k be Nat;
      assume k in Seg m;
      then k in dom gw by A43,FINSEQ_1:def 3;
      then reconsider v= gw.k as Element of REAL 1 by PARTFUN1:4;
       |.v .| in REAL by XREAL_0:def 1;
      hence ex x being Element of REAL st YSQ[k,x];
     end;
     consider yseq be FinSequence of REAL such that
A92:  dom yseq = Seg m &
      for i be Nat st i in Seg m holds YSQ[i,yseq.i] from FINSEQ_1:sch 5(A91);
A93:len gw = len yseq by A43,A92,FINSEQ_1:def 3;
A94: now let i be Nat;
      assume i in dom gw;
      then i in Seg m by A43,FINSEQ_1:def 3;
      hence ex v be Element of REAL 1 st v=gw.i & yseq.i = |. v .| by A92;
     end;
     reconsider yseq as Element of REAL m by A93,A43,FINSEQ_2:92;
A95: |. Sum gw .| <= Sum yseq by A94,A93,PDIFF_6:17;
      reconsider yr = |. y .|*r as Element of REAL by XREAL_0:def 1;
      for j be Nat st j in Seg m holds yseq.j <= (m |-> yr).j
     proof
      let j be Nat;
      assume A96: j in Seg m;
then A97: j in dom gw by A43,FINSEQ_1:def 3; then
A98: ex v be Element of REAL 1 st v = gw.j & yseq.j = |. v .| by A94;
       ex gwj be Element of REAL 1 st gw.j = gwj & |. gwj .| <= |. y .|*r
        by A48,A97;
      hence yseq.j <= (m |-> yr).j by A98,A96,FINSEQ_2:57;
     end;
     then Sum yseq <= Sum(m |-> yr) by RVSUM_1:82;
     then Sum yseq <= m*(|. y .|*r) by RVSUM_1:80;
then |. z .| <= m*(|. y .|*r) by A47,A28,A95,XXREAL_0:2;
     then |. z .|*|.y.|" <= (m*|. y .|*r)*|.y.|" by XREAL_1:64;
     then |. z .|*|.y.|" <= m*((r*|. y .|)*|.y.|");
     then |.y.|"* |. z .| <= m*r by A28,EUCLID:8,XCMPLX_1:203;
then A99: |.y.|"* |. z .| <= r1 by XCMPLX_1:87;
      r1 < r0 by A9,XREAL_1:216;
     hence (|.y.|"* |. z .|) < r0 by A99,XXREAL_0:2;
    end;
   end;
    for y being Element of REAL m st |. y-x .| < d0 holds
       f/.y - f/.x = L.(y-x) + R.(y-x)
   proof
    let y be Element of REAL m;
    assume |. y-x .| < d0;
    R.(y-x) = f/.(x+(y-x)) - f/.x - L.(y-x) by A6;
    hence L.(y-x) + R.(y-x)
         = f/.(x+(y-x)) - f/.x - (L.(y-x) - L.(y-x)) by RVSUM_1:41
        .= f/.(x+(y-x)) - f/.x - 0*1 by RVSUM_1:37
        .= f/.(x+(y-x)) - f/.x by RVSUM_1:32
        .= f/.(x+y-x) - f/.x by RVSUM_1:40
        .= f/.(y+(x-x)) - f/.x by RVSUM_1:40
        .= f/.(y+ 0*m) - f/.x by RVSUM_1:37
        .= f/.y - f/.x by RVSUM_1:16;
   end;
   then f is_differentiable_in x & diff(f,x) = L by A3,A5,A8,PDIFF_6:24;
   hence thesis by A2;
end;
