reserve x,y for object,
        D,D1,D2 for non empty set,
        i,j,k,m,n for Nat,
        f,g for FinSequence of D*,
        f1 for FinSequence of D1*,
        f2 for FinSequence of D2*;
reserve f for complex-valued Function,
        g,h for complex-valued FinSequence;

theorem
  for f be complex-valued FinSequence,
      o be DoubleReorganization of dom f holds
    Sum f = Sum Sum (f*.o)
proof
  defpred P[Nat] means
  for f be complex-valued FinSequence,
      o be DoubleReorganization of dom f st len f=$1 holds
    Sum f = Sum Sum (f*.o);
  A1:P[0]
  proof
    let f be complex-valued FinSequence,
        o be DoubleReorganization of dom f such that A2: len f=0;
    set fo=f*.o, S=Sum fo;
    A3:dom S= Seg len S by FINSEQ_1:def 3;
    x in dom S implies S.x=0
    proof
      reconsider xx=x as set by TARSKI:1;
      assume x in dom S;
      A4: S.xx = Sum (fo.x) by Def8;
      dom (fo.x) ={}
      proof
        assume dom (fo.x) <>{};
        then consider y be object such that
        A5: y in dom (fo.x) by XBOOLE_0:def 1;
        len (fo.x) = len (o.x) by CARD_1:def 7;
        then A6: dom (fo.x) = dom (o.x) by FINSEQ_3:29;
        f={} by A2;
        hence thesis by A6,A5;
      end;
      then fo.x=<*>REAL;
      hence thesis by RVSUM_1:72,A4;
    end;
    then A7: S= (len S) |-> 0 by A3;
    f=<*>REAL by A2;
    hence thesis by RVSUM_1:72,A7,RVSUM_1:81;
  end;
  A8: P[i] implies P[i+1]
  proof
   assume A9:P[i];
   set i1=i+1;
   let f be complex-valued FinSequence,
       o be DoubleReorganization of dom f such that A10:len f=i1;
   set fo=f*.o;
   A11: 1 <= i1 by NAT_1:11;
   then A12:i1 in dom f by A10,FINSEQ_3:25;
   Values o = dom f by Def7;
   then consider x,y be object such that
   A13:x in dom o & y in dom (o.x) & o.x.y=i1 by A11,A10,FINSEQ_3:25,Th1;
   reconsider x,y as Nat by A13;
   set ox=o.x,rox=rng ox;
   A14:ox in rng o by A13,FUNCT_1:def 3;
   then A15: rox c= dom f by RELAT_1:def 19;
   set C=canFS (rox\{i1});
   A16:i1 in rox by A13,FUNCT_1:def 3;
   A17:rng C=rox\{i1} by FUNCT_2:def 3;
   A18: (rox\{i1}) \/ {i1} = rox by ZFMISC_1:116,A16;
   A19:rng <*i1*>= {i1} by FINSEQ_1:38;
   then A20: rng (C^<*i1*>) = rox by A18,A17,FINSEQ_1:31;
   C^<*i1*> is one-to-one by XBOOLE_1:79,FINSEQ_3:91,A17,A19;
   then consider P be Permutation of dom ox such that
   A21: C^<*i1*> = ox*P by A20,RFINSEQ:26,RFINSEQ:4;
   A22:rng C c= rox by A17;
   A23:rng C c= dom f\{i1} by A17,A14,RELAT_1:def 19,XBOOLE_1:33;
   A24: rng C \/ (dom f \{i1}) = dom f \{i1} by
     A17,A15,XBOOLE_1:33,XBOOLE_1:12;
   A25:rng C c= dom f by A15,A17;
   A26:rng C \/ (dom f \rox) = rng C \/ (dom f \(rng C\/{i1}))
       by A17,ZFMISC_1:116,A16
     .= rng C \/ ((dom f \(rng C)) /\ (dom f \{i1}) ) by XBOOLE_1:53
     .= (rng C \/ (dom f \(rng C))) /\ ( rng C \/ (dom f \{i1})) by XBOOLE_1:24
     .= dom f /\ (dom f \{i1}) by A25,XBOOLE_1:45,A24
     .= dom f\{i1} by XBOOLE_1:28;
   dom f=Seg i1 by A10,FINSEQ_1:def 3;
   then A27: dom f\{i1} = Seg i by FINSEQ_1:10;
   set fi=f|i;
   A28: len fi = i by NAT_1:11,A10,FINSEQ_1:59;
   rng C /\ dom f c= rox by A22;
   then reconsider oC=o+*(x,C) as DoubleReorganization of dom fi
     by A27,A13,Th37,A26;
   set FO=fi*.oC;
   A29:dom oC=dom o by FUNCT_7:30;
   then A30:len oC=len o by FINSEQ_3:29;
   A31: len FO = len oC by CARD_1:def 7;
   set FOx=FO|x;
   consider H be FinSequence such that
   A32: FO = FOx^H by FINSEQ_1:80;
   A33: 1<= x & x <= len o by A13,FINSEQ_3:25;
   then A34:len FOx = x by FINSEQ_1:59,A30,A31;
   then A35:dom FOx = Seg x by FINSEQ_1:def 3;
   A36: x in Seg x by A33;
   reconsider x1=x-1 as Nat by A33;
   len FOx = x1+1 by A33,FINSEQ_1:59,A30,A31;
   then A37: FOx = (FOx|x1) ^ <*FOx.x*> by FINSEQ_3:55;
   A38:x1 <=x1+1 by NAT_1:11;
   then A39:FOx|x1=FO|x1 by FINSEQ_1:82;
   reconsider H as  complex-functions-valued FinSequence-yielding FinSequence
     by A32,Th43,Th44;
   reconsider FF=<*FO.x*>,FOx1=FO|x1 as
      complex-functions-valued FinSequence-yielding FinSequence;
   Sum (FOx1^FF) = Sum FOx1^ Sum FF by Th46;
   then A40:Sum Sum (FOx1^FF) = Sum Sum FOx1 + Sum Sum FF by RVSUM_2:32;
   FO = FOx1^FF^H by A39,A37,A35,A36,FUNCT_1:47,A32;
   then A41:Sum FO = Sum (FOx1^FF) ^ Sum H by Th46;
   A42: Sum FF = <*Sum (FO.x)*> by Th45;
   A43: len fo = len o by CARD_1:def 7;
   set fox=fo|x;
   consider h be FinSequence such that
   A44: fo = fox^h by FINSEQ_1:80;
   A45:len fox = x by A33,FINSEQ_1:59,A43;
   then A46:dom fox = Seg x by FINSEQ_1:def 3;
   len fox = x1+1 by A33,FINSEQ_1:59,A43;
   then A47: fox = (fox|x1) ^ <*fox.x*> by FINSEQ_3:55;
   A48:fox|x1=fo|x1 by A38,FINSEQ_1:82;
   reconsider h as  complex-functions-valued FinSequence-yielding FinSequence
     by A44,Th43,Th44;
   reconsider ff=<*fo.x*>,fox1=fo|x1 as
     complex-functions-valued FinSequence-yielding FinSequence;
    Sum (fox1^ff) = Sum fox1^ Sum ff by Th46;
   then A49:Sum Sum (fox1^ff) = Sum Sum fox1 + Sum  Sum ff by RVSUM_2:32;
   fo = fox1^ff^h by A44,A47,A48,A46,A36,FUNCT_1:47;
   then A50:Sum fo = Sum (fox1^ff) ^ Sum h by Th46;
   A51: Sum ff= <*Sum (fo.x)*> by Th45;
   A52:len fox1 = x1 & len FOx1 = x1 by A38,A45,A34,A48,A39,FINSEQ_1:59;
   for i st 1<= i & i <= x1 holds fox1.i = FOx1.i
   proof
     let j;
     assume A53: 1<= j & j <= x1;
     then A54:j < x by A38,NAT_1:13;
     then A55: j <= len o by A33,XXREAL_0:2;
     then A56: j in dom o by A53,FINSEQ_3:25;
     A57: fo.j = f*(o.j) & FO.j = fi*(oC.j)
       by A55,A53,FINSEQ_3:25,A29,FOMODEL2:def 6;
     j in Seg x1 by A53;
     then A58:fox1.j = fo.j & FOx1.j = FO.j by FUNCT_1:49;
     o.j in rng o & rng o c= (dom f)* by A56,FUNCT_1:def 3;
     then A59: o.j is FinSequence of dom f by FINSEQ_1:def 11;
     not i1 in rng (o.j)
     proof
       assume i1 in rng (o.j);
       then consider w be object such that
       A60: w in dom (o.j) & o.j.w = i1 by FUNCT_1:def 3;
       o_(j,w) = o_(x,y) by A60,A13;
       hence thesis by A60,A56,A13,Def6,A54;
     end;
     then A61: rng (o.j) c= Seg i by A27,A59,FINSEQ_1:def 4,ZFMISC_1:34;
     (f|Seg i)*(o.j) = (f*id Seg i)*(o.j) by RELAT_1:65
                    .= f*((id Seg i)*(o.j)) by RELAT_1:36
                    .= f*(o.j) by A61,RELAT_1:53;
     hence thesis by A57,A54,FUNCT_7:32,A58;
   end;
   then A62: fox1 = FOx1 by A52;
   A63:len FO = len FOx + len H by A32,FINSEQ_1:22;
   then A64:len FOx + len H = len fox + len h
     by A44,FINSEQ_1:22,A43,A31,A30;
   for i st 1<= i & i <= len H holds H.i = h.i
   proof
     let j;
     set jx=j+x;
     assume A65: 1<= j & j <= len H;
     then j in dom H & j in dom h by A64,A34,A45,FINSEQ_3:25;
     then A66:H.j = FO.jx & h.j = fo.jx by A34,A45,A32,A44,FINSEQ_1:def 7;
     j<>0 by A65;
     then A67: jx<>x;
     j <= jx by NAT_1:11;
     then jx >= 1 by A65,XXREAL_0:2;
     then A68: jx in dom o by A65,A63,A34,A31,A29,XREAL_1:6,FINSEQ_3:25;
     then A69: fo.jx = f*(o.jx) & FO.jx = fi*(oC.jx) by A29,FOMODEL2:def 6;
     o.jx in rng o & rng o c= (dom f)* by A68,FUNCT_1:def 3;
     then A70: o.jx is FinSequence of dom f by FINSEQ_1:def 11;
     not i1 in rng (o.jx)
     proof
       assume i1 in rng (o.jx);
       then consider w be object such that
       A71: w in dom (o.jx) & o.jx.w = i1 by FUNCT_1:def 3;
       o_(jx,w) = o_(x,y) by A71,A13;
       then jx=x & y = w by A71,A68,A13,Def6;
       then j=0;
       hence thesis by A65;
     end;
     then A72: rng (o.jx) c= Seg i by A27,A70,FINSEQ_1:def 4,ZFMISC_1:34;
     (f|Seg i)*(o.jx) = (f*id Seg i)*(o.jx) by RELAT_1:65
       .= f*((id Seg i)*(o.jx)) by RELAT_1:36
       .= f*(o.jx) by A72,RELAT_1:53;
     hence thesis by A69,A67,FUNCT_7:32,A66;
   end;
   then A73: H = h by A64,A34,A45;
   A74: fo.x= f*ox & FO.x = fi*(oC.x) by A13,A29,FOMODEL2:def 6;
   A75: dom (f*ox) = dom ox by A15,RELAT_1:27;
   rng (f*ox) c= COMPLEX;
   then reconsider g=f*ox as FinSequence of COMPLEX by FINSEQ_1:def 4;
   reconsider PP=P as Permutation of dom g by A75;
   A76:dom ox = Seg len ox by FINSEQ_1:def 3;
   rng P = dom ox by FUNCT_2:def 3;
   then
   A77:dom (ox*P) = dom P & rng (ox*P) = rng ox & dom (g*P) = dom P &
     rng (g*P) = rng g by A75,RELAT_1:27,28;
   then g*PP is FinSequence by A76,FUNCT_2:52,FINSEQ_1:def 2;
   then reconsider G=g*PP as FinSequence of COMPLEX by FINSEQ_1:def 4,A77;
   A78: Sum g = addcomplex $$ g by RVSUM_1:def 11
     .=addcomplex "**" G by FINSOP_1:7
     .=Sum G by RVSUM_1:def 11;
   reconsider F=f as Function of dom f,rng f by FUNCT_2:1;
   reconsider I1=i1 as Element of dom f by A11,A10,FINSEQ_3:25;
   reconsider C1=C as FinSequence of dom f by A25,FINSEQ_1:def 4;
   A79:dom f is non empty & rng f is non empty by A12, RELAT_1:42;
   G = f*(ox*P) by RELAT_1:36;
   then A80: G = (F*C1) ^ <*f.i1*> by A21,A79,A12,FINSEQOP:8;
   fi*C = (f*id Seg i)*C by RELAT_1:65
     .= f*((id Seg i)*C) by RELAT_1:36
     .=f*C by A23,A27,RELAT_1:53;
   then FO.x = f*C by A74, A13,FUNCT_7:31;
   then A81: Sum (fo.x) = Sum (FO.x) + f.i1 by A80,RVSUM_2:31,A78,A74;
   A82:Sum fi = Sum Sum FO by A9,A28
     .= Sum Sum FOx1 + Sum  Sum FF + Sum Sum H by A41,A40,RVSUM_2:32
     .= Sum Sum fox1 + Sum (FO.x) + Sum Sum h by A62,A73,A42,RVSUM_2:30;
   A83: Sum Sum fo = Sum Sum fox1 + Sum Sum ff + Sum Sum h by
   A49,A50,RVSUM_2:32
     .= Sum Sum fox1 + Sum (fo.x) + Sum Sum h by A51,RVSUM_2:30
     .= Sum Sum fox1 + Sum (FO.x) + Sum Sum h+f.i1 by A81;
   f= fi ^ <*f.i1*> by FINSEQ_3:55,A10;
   hence thesis by RVSUM_2:31,A83,A82;
 end;
 A84:P[i] from NAT_1:sch 2(A1,A8);
 let f be complex-valued FinSequence,o be DoubleReorganization of dom f;
 P[len f] by A84;
 hence thesis;
end;
