reserve D,D1,D2 for non empty set,
        d,d1,d2 for XFinSequence of D,
        n,k,i,j for Nat;

theorem Th21:
  for r be Real, f be real-valued FinSequence st rng f c= {0,r}
    holds Sum f = r * card (f"{r})
proof
  let r be Real;
  defpred P[Nat] means for f be real-valued FinSequence st
    len f = $1 & rng f c= {0,r} holds Sum f = r* card (f"{r});
A1:P[0]
  proof
    let f be real-valued FinSequence such that
A2:     len f = 0 and
        rng f c= {0,r};
A3: f={} by A2;
    then f"{r}={};
    hence thesis by A3,RVSUM_1:72;
  end;
A4:for n st P[n] holds P[n+1]
  proof
    let n such that
A5:   P[n];
    set n1=n+1;
    let f be real-valued FinSequence such that
A6:     len f = n1
      and
A7:     rng f c= {0,r};
    rng f c= REAL;
    then reconsider F=f as FinSequence of REAL by FINSEQ_1:def 4;
    set fn=F|n,FF=<*f.n1*>;
A8:   f = fn^FF by A6,FINSEQ_3:55;
    then
A9:   Sum f = Sum fn + (F.n1) by RVSUM_1:74;
    rng fn c= rng f by RELAT_1:70;
    then
A10:  rng fn c= {0,r} by A7;
A11:  len fn = n by NAT_1:11,A6,FINSEQ_1:59;
    then
A12:  Sum fn = r*card (fn"{r}) by A10,A5;
A13:  dom FF = Seg 1 by FINSEQ_1:38;
    rng FF = {F.n1} by FINSEQ_1:38;
    then
A14:  FF = Seg 1 --> F.n1 by A13,FUNCOP_1:9;
A15:  card (f"{r}) = card (fn"{r}) + card (FF"{r}) by FINSEQ_3:57,A8;
    1 <= n1 by NAT_1:11;
    then n1 in dom F by A6,FINSEQ_3:25;
    then
A16:  F.n1 in rng F by FUNCT_1:def 3;
    per cases;
      suppose
A17:      F.n1 <> r;
        then not F.n1 in {r} by TARSKI:def 1;
        then
A18:      FF"{r}={} by A14,FUNCOP_1:16;
        F.n1 = 0 by A17,A16,A7,TARSKI:def 2;
        hence thesis by A11,A10,A5,A9,A15,A18;
      end;
      suppose
A19:    F.n1 = r;
        then FF"{r}=Seg 1 by A14,FUNCOP_1:15;
        then card (FF"{r}) = 1 by FINSEQ_1:57;
        hence thesis by A12,A9,A15,A19;
      end;
  end;
A20: for n holds P[n] from NAT_1:sch 2(A1,A4);
  let f be real-valued FinSequence;
  P[len f] by A20;
  hence thesis;
end;
