reserve x,y for object,
        i,j,k,m,n for Nat;

theorem Th10:
   for g be natural-valued FinSequence
    for sort be DoubleReorganization of dom g
      ex h be (2*len sort)-element FinSequence of NAT st
      for j holds h.(2*j) = 0 &
      h.(2*j-1) = g. sort_(j,1) + (g*.sort.j,2)+...
    proof
      let g be natural-valued FinSequence;
      let sort be DoubleReorganization of dom g;
      defpred P[object,object] means
      ($1 = 2*j-1 implies
         $2 = g. sort_(j,1) + (g*.sort.j,2)+...) &
      ($1 = 2*j implies $2 = 0);
      set S=Seg (2* len sort);
      A1: for k st k in S ex x st P[k,x]
      proof
        let k;
        assume k in Seg (2*len sort);
        per cases;
        suppose A2:k is even;
          set j=the Nat;
          take x = 0;
          thus thesis by A2;
        end;
        suppose k is odd;
          then consider j such that
          A4: k=2*j+1 by ABIAN:9;
          set j1=j+1;
          take x= g. sort_(j1,1) + (g*.sort.j1,2)+...;
          let i;
          thus thesis by A4;
        end;
      end;
      consider f be FinSequence such that
      A5:dom f = S & for i st i in S holds P[i,f.i] from FINSEQ_1:sch 1(A1);
      A6:rng f c= NAT
      proof
        let y;
        assume y in rng f;
        then consider x such that
        A7:x in dom f & f.x=y by FUNCT_1:def 3;
        reconsider x as Nat by A7;
        per cases;
        suppose x is even;
          then ex i st x=2*i by ABIAN:def 2;
          then f.x=0 by A5,A7;
          hence thesis by A7;
        end;
        suppose x is odd;
          then consider i such that
          A8: x = 2*i+1 by ABIAN:9;
          2*(i+1) - 1 = x by A8;
          then f.x= g. sort_(i+1,1) + (g*.sort.(i+1),2)+... by A7,A5;
          hence thesis by A7,ORDINAL1:def 12;
        end;
      end;
      A9: len f = (2*len sort) by A5,FINSEQ_1:def 3;
      then reconsider f as (2*len sort)-element FinSequence of NAT
        by A6,FINSEQ_1:def 4,CARD_1:def 7;
      take f;
      let i;
      thus f.(2*i) = 0
      proof
        2*i in dom f or not 2*i in dom f;
        hence thesis by A5,FUNCT_1:def 2;
      end;
      thus f.(2*i-1) = g. sort_(i,1) + (g*.sort.i,2)+...
      proof
        per cases by FINSEQ_3:25;
        suppose 2*i-1 in dom f;
          hence thesis by A5;
        end;
        suppose A10:2*i-1 > len f;
          then A11:not 2*i-1 in dom f by FINSEQ_3:25;
          2*i-1 +1 > len f by A10,NAT_1:13;
          then i > len sort by A9,XREAL_1:64;
          then A12: not i in dom sort by FINSEQ_3:25;
          then sort.i = {} by FUNCT_1:def 2;
          then not sort_(i,1) in dom g by FINSEQ_3:25;
          then A13: g. sort_(i,1)={} by FUNCT_1:def 2;
          dom (g*.sort)= dom sort by FOMODEL2:def 6;
          then g*.sort.i = {} by A12,FUNCT_1:def 2;
          then g. sort_(i,1) + (g*.sort.i,2)+... = 0 by FLEXARY1:15,A13;
          hence thesis by A11,FUNCT_1:def 2;
        end;
        suppose A14: 2*i-1 < 1;
          then A15: not 2*i-1 in dom f by FINSEQ_3:25;
          2*i-1+1 < 1+1 by A14,XREAL_1:6;
          then 2*i < 2*1;
          then A16:not i in dom sort by XREAL_1:64,FINSEQ_3:25;
          then sort.i = 0 by FUNCT_1:def 2;
          then not sort_(i,1) in dom g by FUNCT_1:def 2,FINSEQ_3:25;
          then A17:g. sort_(i,1)=0 by FUNCT_1:def 2;
          dom (g*.sort)= dom sort by FOMODEL2:def 6;
          then g*.sort.i = {} by A16,FUNCT_1:def 2;
          then g.sort_(i,1) + (g*.sort.i,2)+... = 0 by FLEXARY1:15,A17;
          hence thesis by A15,FUNCT_1:def 2;
        end;
      end;
    end;
