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

theorem Th9:
   for f,h be natural-valued FinSequence st
     for i holds card Coim(h,i) = f.i
   holds Sum h = 1 * f.1 + 2 * f.2 + ((id dom f)(#)f,3) +...
proof
  defpred P[Nat] means
  for f,h be natural-valued FinSequence st len f = $1 &
    for i holds card Coim(h,i) = f.i
  holds Sum h = ((id dom f) (#)f,1) +...;
  A1:P[0]
  proof
    let f,h be natural-valued FinSequence such that
      A2:len f = 0
    and
      A3:for i holds card Coim(h,i) = f.i;
    set L=(len h) |->0;
    now let i such that A4:1 <= i & i <= len h;
      A5:i in dom h by A4,FINSEQ_3:25;
      f={} by A2;
      then f.(h.i)=0;
      then card Coim(h,h.i) =0 by A3;
      then Coim(h,h.i)={};
      then h"{h.i} = {} by RELAT_1:def 17;
      then not h.i in rng h by FUNCT_1:72;
      hence h.i = L.i by A5,FUNCT_1:def 3;
    end;
    then A6: h = (len h) |->0 by CARD_1:def 7;
    A7: f={} by A2;
    then reconsider E= (id dom f) (#)f as complex-valued FinSequence;
    ((id dom f) (#)f,1) +... = E.1 + (E,1+1) +... by FLEXARY1:20
                            .= Sum E by FLEXARY1:22
                            .=0 by A7,RVSUM_1:72;
    hence thesis by A6,RVSUM_1:81;
  end;
  A8:P[i] implies P[i+1]
  proof
    assume A9:P[i];
    set i1=i+1;
    let f,h be natural-valued FinSequence such that
      A10:len f = i1
    and
      A11:for i holds card Coim(h,i) = f.i;
    A12:id dom f = idseq i1 by FINSEQ_1:def 3,A10;
    set fi=f|i;
    A13: f = fi^ <*f.i1*> by A10,FINSEQ_3:55;
    A14:i < i1 by NAT_1:13;
    then A15:len fi = i by A10,FINSEQ_1:59;
    then A16: id dom fi = idseq i by FINSEQ_1:def 3;
    A17: idseq i1 = (idseq i)^ <*i1*> by FINSEQ_2:51;
    len fi = len (idseq i) by CARD_1:def 7,A15;
    then A18: (id dom f) (#) f = ((idseq i) (#)fi)^(<*i1*>(#)<*f.i1*>)
      by Th8,A12,A13,A17;
    A19: Seg 1 /\Seg 1 = Seg 1;
    dom <*i1*> = Seg 1 & dom <*f.i1*> = Seg 1 by FINSEQ_1:38;
    then dom (<*i1*>(#)<*f.i1*>) = Seg 1 by VALUED_1:def 4,A19;
    then A20: len (<*i1*>(#)<*f.i1*>) = 1 by FINSEQ_1:def 3;
    <*i1*>.1=i1 & <*f.i1*>.1 = f.i1;
    then (<*i1*>(#)<*f.i1*>).1 = i1 * (f.i1) by VALUED_1:5;
    then A21: <*i1*>(#)<*f.i1*> = <*i1 * (f.i1)*> by A20,FINSEQ_1:40;
    A22:((id dom f) (#) f,1)+... = Sum ((idseq i1)(#)f) by A12,FLEXARY1:21;
    per cases;
    suppose A23: f.i1 =0;
      then A24: ((id dom f) (#) f,1)+... = (Sum ((idseq i) (#)fi)) + 0
        by A21,A12,A18,A22,RVSUM_1:74;
      for j holds card Coim(h,j) = fi.j
      proof
        let j;
        per cases;
        suppose j in dom fi;
          then fi.j=f.j & f.j = card Coim(h,j) by A11,FUNCT_1:47;
          hence thesis;
        end;
        suppose A25: j = i1;
          then not j in dom fi by A14,A15,FINSEQ_3:25;
          then fi.j=0 & f.j = card Coim(h,j) by A11,FUNCT_1:def 2;
          hence thesis by A23,A25;
        end;
        suppose A26: j <> i1 & not j in dom fi;
          then A27:fi.j = 0 by FUNCT_1:def 2;
          j < 1 or j >i by A26,A15,FINSEQ_3:25;
          then j < 1 or j >= i1 by NAT_1:13;
          then j < 1 or j > i1 by A26,XXREAL_0:1;
          then not j in dom f by A10,FINSEQ_3:25;
          then f.j=0 by FUNCT_1:def 2;
          hence thesis by A11,A27;
        end;
      end;
      then Sum h = ((idseq i)(#)fi,1)+... by A9,A16,A15
                .= Sum ((idseq i) (#)fi) by FLEXARY1:21;
      hence thesis by A24;
    end;
    suppose f.i1 <>0;
      then card Coim(h,i1)<>0 by A11;
      then Coim(h,i1) <>{};
      then consider xx be object such that
      A28:xx in Coim(h,i1) by XBOOLE_0:def 1;
      A29:xx in Coim(h,i1) & Coim(h,i1) = h"{i1} by A28,RELAT_1:def 17;
      then reconsider D=dom h as non empty set by FUNCT_1:def 7;
      A30: rng h c= REAL;
      then reconsider H=h as Function of D,REAL by FUNCT_2:2;
      reconsider h1=H as FinSequence of REAL by A30,FINSEQ_1:def 4;
      set X = h"{i1},Y=D\X;
      dom (H| (Y\/X)) is finite;
      then A31: FinS(H,Y \/ X), FinS(H,Y) ^ FinS(H,X) are_fiberwise_equipotent
      by RFUNCT_3:76,XBOOLE_1:79;
      A32: D = X \/ Y by RELAT_1:132,XBOOLE_1:45;
      H|D = H;
      then H,FinS(H,X \/ Y) are_fiberwise_equipotent by A32,RFUNCT_3:def 13;
      then A33: Sum h1 = Sum (FinS(H,Y) ^ FinS(H,X))
        by A31,CLASSES1:76,RFINSEQ:9
            .= Sum FinS(H,Y) + Sum FinS(H,X) by RVSUM_1:75;
      A34:dom (H|X) = X & dom (H|Y) = Y by RELAT_1:132,RELAT_1:62;
      rng (H|X) c= {i1}
      proof
        let y be object;
        assume y in rng (H|X);
        then consider x be object such that
        A35:x in X & (H|X).x=y by A34,FUNCT_1:def 3;
        (H|X).x=H.x by A35,FUNCT_1:49;
        hence thesis by A35,FUNCT_1:def 7;
      end;
      then FinS(H,X) = (card X) |->i1 by A29,A34,ZFMISC_1:33,RFUNCT_3:75;
      then A36: FinS(H,X) = (f.i1) |->i1 by A29,A11;
      A37: H|Y, FinS(H,Y) are_fiberwise_equipotent by A34,RFUNCT_3:def 13;
      then rng (H|Y) = rng FinS(H,Y) by CLASSES1:75;
      then rng FinS(H,Y) c= NAT by VALUED_0:def 6;
      then reconsider F=FinS(H,Y) as natural-valued FinSequence
        by VALUED_0:def 6;
      for j holds card Coim(F,j) = fi.j
      proof
        let j;
        set hY=h|Y;
        A38: card Coim(F,j) = card Coim(hY,j) by A37,CLASSES1:def 10;
        A39: hY"{j} = Coim(hY,j) & h"{j} = Coim(h,j) by RELAT_1:def 17;
        A40: hY"{j} = Y /\ h"{j} by FUNCT_1:70
                   .= (h"{j}/\D) \h"{i1} by XBOOLE_1:49
                   .= h"{j} \h"{i1} by RELAT_1:132,XBOOLE_1:28
                   .= h"({j}\{i1}) by FUNCT_1:69;
        A41: card Coim(h,j) = f.j by A11;
        per cases;
        suppose A42:j in dom fi;
          then j<>i1 by A15,FINSEQ_3:25,A14;
          then card Coim(F,j) = card Coim(h,j) by ZFMISC_1:14,A38,A39,A40;
          hence thesis by A41,A42,FUNCT_1:47;
        end;
        suppose A43:j = i1;
          then A44:not j in dom fi by A14,A15,FINSEQ_3:25;
          card Coim(F,j) = card (h"{}) by A43,A38,A39,A40;
          hence thesis by A44,FUNCT_1:def 2;
        end;
        suppose A45:not j in dom fi & j<>i1;
          then A46:fi.j = 0 by FUNCT_1:def 2;
          j < 1 or j >i by A45,A15,FINSEQ_3:25;
          then j < 1 or j >= i1 by NAT_1:13;
          then j < 1 or j > i1 by A45,XXREAL_0:1;
          then A47:not j in dom f by A10,FINSEQ_3:25;
          card Coim(F,j) = card Coim(h,j) by A45,ZFMISC_1:14,A38,A39,A40;
          hence thesis by A46,A47,FUNCT_1:def 2,A41;
        end;
      end;
      then A48: Sum F = ((idseq i)(#)fi,1)+... by A9,A15,A16
      .= Sum ((idseq i) (#)fi) by FLEXARY1:21;
      ((id dom f) (#) f,1)+... = (Sum ((idseq i) (#)fi)) + (i1 * (f.i1))
        by A21,A12,A18,A22,RVSUM_1:74;
      hence thesis by A33,A48,A36,RVSUM_1:80;
    end;
  end;
  A49:P[i] from NAT_1:sch 2(A1,A8);
  let f,h be natural-valued FinSequence such that A50:
  for i holds card Coim(h,i) = f.i;
  set I=(idseq len f) (#)f;
  A51:id dom f = idseq len f by FINSEQ_1:def 3;
  then A52: I.1 = 1*f.1 by Lm2;
  A53: I.2 = 2*f.2 by Lm2,A51;
  Sum h = (I,1) +... by A49,A51,A50
       .= I.1 + (I,1+1)+... by FLEXARY1:20
       .= I.1 +(I.2 +(I,2+1)+...) by FLEXARY1:20;
  hence thesis by A52,A53,A51;
end;
