
theorem Th4:
  for m be non zero Nat,
      s be FinSequence of REAL m,
      j be Nat
    st 1 <= j <= m
  holds
    ex t be FinSequence of REAL
    st len t = len s
      & ( for i be Nat st 1 <= i <= len s
          holds
          ex si be Element of REAL m
          st si = s.i & t.i = si.j )
      & (Sum s).j = Sum t
proof
  let m be non zero Nat;

  defpred P[Nat] means
  for s be FinSequence of REAL m,
      j be Nat
    st len s = $1 & 1 <= j <= m
  holds
    ex t be FinSequence of REAL
    st len t = len s
      & ( for i be Nat st 1 <= i <= len s
          holds
          ex si be Element of REAL m
          st si = s.i & t.i = si.j )
      & (Sum s).j = Sum t;

  A1: P[0]
  proof
    let s be FinSequence of REAL m,
        j be Nat;
    assume
    A2: len s = 0 & 1 <= j <= m;
    reconsider t = <*>REAL as FinSequence of REAL;
    take t;
    thus len t = len s by A2;
    thus
    for i be Nat st 1 <= i <= len s
    holds
      ex si be Element of REAL m
      st si = s.i & t.i = si.j by A2;

    (Sum s).j
      = (0* m).j by EUCLID_7:def 11,A2
    .= 0;
    hence thesis by RVSUM_1:72;
  end;

  A3: for n be Nat st P[n] holds P[n+1]
  proof
    let n be Nat;
    assume
    A4: P[n];

    let s be FinSequence of REAL m,
        j be Nat;
    reconsider sn = s|n as FinSequence of REAL m;
    assume
    A5: len s = n+1 & 1 <= j <= m; then

    A6: len sn = n by FINSEQ_1:59,NAT_1:11;
    A7: s = sn ^ <*s.(n+1)*> by A5,FINSEQ_3:55;

    n+1 in Seg (n+1) by FINSEQ_1:4;
    then n+1 in dom s by A5,FINSEQ_1:def 3;
    then s.(n+1) in rng s by FUNCT_1:3;
    then reconsider sn1 = s.(n+1) as Element of REAL m;

    A8: Sum s = Sum sn + sn1 by Th3,A7;

    len(Sum sn) = m by CARD_1:def 7;
    then dom(Sum sn) = Seg m by FINSEQ_1:def 3;
    then j in dom (Sum sn) by A5;
    then
    A9: (Sum sn).j in rng (Sum sn) by FUNCT_1:3;

    len sn1 = m by CARD_1:def 7;
    then dom sn1 = Seg m by FINSEQ_1:def 3;
    then j in dom sn1 by A5;
    then sn1.j in rng sn1 by FUNCT_1:3;
    then reconsider x = (Sum sn).j, y = sn1.j as Element of REAL by A9;

    A10: (Sum s).j = x+y by A8,RVSUM_1:11;
    consider tn be FinSequence of REAL such that
    A11: len tn = len sn
        & ( for i be Nat st 1 <= i & i <=len sn
            holds
              ex sni be Element of REAL m
              st sni = sn.i & tn.i = sni.j )
        & (Sum sn).j = Sum tn by A4,A5,A6;

    reconsider t = tn ^ <*y*> as FinSequence of REAL;
    take t;
    thus len t
      = len tn + len <*y*> by FINSEQ_1:22
    .= n + len <*y*> by A5,A11,FINSEQ_1:59,NAT_1:11
    .= len s by A5,FINSEQ_1:40;

    thus
    for i be Nat st 1 <= i <= len s
    holds
      ex si be Element of REAL m
      st si = s.i & t.i = si.j
    proof
      let i be Nat;
      assume
      A12: 1 <= i <= len s;

      per cases;
      suppose
        i <> len s;
        then i < n+1 by A5,A12,XXREAL_0:1;
        then
        A13: i <= n by NAT_1:13;
        then consider sni be Element of REAL m such that
        A14: sni = sn.i & tn.i = sni.j by A6,A11,A12;
        take sni;
        i in Seg n by A12,A13;
        hence sni = s.i by A14,FUNCT_1:49;

        i in Seg len tn by A6,A11,A12,A13;
        then i in dom tn by FINSEQ_1:def 3;
        hence t.i = sni.j by A14,FINSEQ_1:def 7;
      end;
      suppose
        A15: i = len s;
        take sn1;
        thus sn1 = s.i by A5,A15;
        thus t.i = sn1.j by A5,A6,A11,A15,FINSEQ_1:42;
      end;
    end;
    thus (Sum s).j = Sum t by RVSUM_1:74,A11,A10;
  end;

  for n be Nat holds P[n] from NAT_1:sch 2(A1,A3);
  hence thesis;
end;
