reserve i,j,k,n,m for Nat,
  x,y,z,y1,y2 for object, X,Y,D for set,
  p,q for XFinSequence;
reserve k1,k2 for Nat;
reserve D for non empty set,
  F,G for XFinSequence of D,
  b for BinOp of D,
  d,d1,d2 for Element of D;
reserve F for XFinSequence,
        rF,rF1,rF2 for real-valued XFinSequence,
        r for Real,
        cF,cF1,cF2 for complex-valued XFinSequence,
        c,c1,c2 for Complex;

theorem :: CATALAN2:45
  rng cF c= {0,c} implies Sum cF = c * card (cF"{c})
proof
  defpred P[Nat] means for cF,c st len cF=$1 &
  rng cF c= {0,c} holds Sum cF = c* card (cF"{c});
assume
A1: rng cF c= {0,c};
A2: for k st P[k] holds P[k+1]
  proof
    let k such that
A3: P[k];
    let F be complex-valued XFinSequence,
     c be Complex such that
A4: len F=k+1 and
A5: rng F c= {0,c};
    per cases;
    suppose
A6:   c <>0;
      ( not k in k)& Segm k \/ {k}= Segm(k+1) by AFINSQ_1:2;
      then
A7:   dom F\{k}=k by A4,ZFMISC_1:117;
      k <k+1 by NAT_1:13;
      then k in dom F by A4,AFINSQ_1:86;
      then
A8:   F.k in rng F by FUNCT_1:def 3;
      per cases by A5,A8,TARSKI:def 2;
      suppose
A9:     F.k=0;
A10:    F|(k+1)=F by A4;
A11:    k <k+1 by NAT_1:13; then
A12:    Sum (F|k) + (0 qua Real)= Sum F by A9,A10,Th64,A4,AFINSQ_1:86;
A13:    len (F|k)=k by A4,A11,AFINSQ_1:54;
        rng (F|k) c= rng F & (F|k)"{c}=F"{c} by A6,A7,A9,Th66;
        hence thesis by A3,A5,A13,A12,XBOOLE_1:1;
      end;
      suppose
A14:    F.k=c;
        set Fk=(F|k)"{c};
        not k in k;
        then not k in dom (F|k);
        then
A15:    not k in Fk by FUNCT_1:def 7;
A16:    k <k+1 by NAT_1:13;
        then
A17:    k in dom F by A4,AFINSQ_1:86;
        rng (F| k) c= rng F & len (F|k)= k by A4,A16,AFINSQ_1:54;
        then
A18:    Sum (F|k)=c* card ((F|k)"{c}) by A3,A5,XBOOLE_1:1;
        F|(k+1)=F by A4;
        then
A19:    Sum (F|k)+ c = Sum F by A14,A17,Th64;
        {k}\/Fk=F"{c} by A7,A14,A17,Th65;
        then (card Fk)+1=card (F"{c}) by A15,CARD_2:41;
        hence thesis by A18,A19;
      end;
    end;
    suppose
A20:  c = 0;
      for x being object st x in dom F holds F.x = 0
      proof
        let x be object;
        assume x in dom F;
        then F.x in rng F by FUNCT_1:def 3;
        hence thesis by A5,A20,TARSKI:def 2;
      end;
      then F = dom F --> 0 by FUNCOP_1:11;
      then Sum F = len F*0 by Th61;
hence thesis by A20;
    end;
  end;
A21: P[0]
  proof
    let F be complex-valued XFinSequence,
c be Complex such that
A22: len F=0 and
    rng F c= {0,c};
    F"{c} c= 0 & F={} by A22,RELAT_1:132;
then card (F"{c})=0 & Sum F =0;
    hence thesis;
  end;
 for k holds P[k] from NAT_1:sch 2(A21,A2);
then P[len cF];
  hence thesis by A1;
end;
