reserve m,n,s for non zero Element of NAT;

theorem Th5:
  for x be FinSequence of Z_2,
      v be Element of Z_2,
      j be Nat
  st len x = m & j in Seg m & for i be Nat st i in Seg m holds
  (i = j implies x.i = v) & (i <> j implies x.i = 0.Z_2)
  holds Sum(x) = v
proof
  defpred P[Nat] means
  for m be non zero Element of NAT,
      x be FinSequence of Z_2,
      v be Element of Z_2,
      j be Nat
  st $1 = m & len x = m & j in Seg m & for i be Nat st i in Seg m holds
  (i = j implies x.i = v) & (i <> j implies x.i = 0.Z_2)
  holds Sum(x) = v;
A1: P[0];
A2: for k be Nat st P[k] holds P[k+1]
  proof
    let k be Nat;
    assume
A3: P[k];
    for m be non zero Element of NAT, x be FinSequence of Z_2,
    v be Element of Z_2, j be Nat
    st k + 1 = m & len x = m & j in Seg m & for i be Nat st i in Seg m holds
    (i = j implies x.i = v) & (i <> j implies x.i = 0.Z_2)
    holds Sum(x) = v
    proof
      let m be non zero Element of NAT, x be FinSequence of Z_2,
      v be Element of Z_2, j be Nat;
      assume
A4:   k + 1 = m & len x = m & j in Seg m & for i be Nat st i in Seg m holds
      (i = j implies x.i = v) & (i <> j implies x.i = 0.Z_2);
      reconsider xk = x|k as FinSequence of Z_2;
A5:   k <= k + 1 by NAT_1:11;
A6:   len xk = k by A4,NAT_1:11,FINSEQ_1:59;
A7:   len x = len xk + 1 by A4,NAT_1:11,FINSEQ_1:59;
A8:   xk = x | dom xk by A6,FINSEQ_1:def 3;
A9:   len ((len xk)|->0.Z_2) = len xk by CARD_1:def 7;
      per cases;
      suppose
A10:    j = m;
        then
A11:    x.(len x) = v by A4;
        for i be Nat st i in dom xk holds xk.i = ((len xk)|->0.Z_2).i
        proof
          let i be Nat;
          assume
A12:     i in dom xk;
          then
A13:     i in Seg k by A6,FINSEQ_1:def 3;
          then
A14:     i in Seg m by A4,A5,FINSEQ_1:5,TARSKI:def 3;
          1 <= i & i <= k by FINSEQ_1:1,A13;
          then i <> j by A4,A10,NAT_1:13;
          then x.i = 0.Z_2 by A4,A14;
          then xk.i = 0.Z_2 by A12,A8,FUNCT_1:49;
          hence thesis by BSPACE:5;
        end; then
A15:    xk = (len xk)|->0.Z_2 by A9,FINSEQ_2:9;
        thus Sum(x) = Sum(xk) + v by RLVECT_1:38,A7,A8,A11
        .= v + 0.Z_2 by A15,Th4
        .= v by BSPACE:5;
      end;
      suppose
A16:    j <> m;
A17:   1 <= j & j <= m by A4,FINSEQ_1:1;
        then j < m by A16,XXREAL_0:1;
        then j <= k by A4,NAT_1:13;
        then
A18:   j in Seg k by A17;
A19:   k <> 0 by A4,A16,XXREAL_0:1,A17;
        for i be Nat st i in Seg k holds (i = j implies xk.i = v) &
        (i <> j implies xk.i = 0.Z_2)
        proof
          let i be Nat;
          assume
A20:     i in Seg k;
A21:     Seg k c= Seg m by A4,NAT_1:11,FINSEQ_1:5;
          xk.i = x.i by A20,FUNCT_1:49;
          hence (i = j implies xk.i = v) &
          (i <> j implies xk.i = 0.Z_2) by A4,A20,A21;
        end;
        then
A22:   Sum(xk) = v by A6,A3,A18,A19;
A23:   m in Seg m by FINSEQ_1:3;
A24:    x.(len x) = 0.Z_2 by A4,A23,A16;
        thus Sum(x) = v + 0.Z_2 by RLVECT_1:38,A7,A8,A24,A22
        .= v by BSPACE:5;
      end;
    end;
    hence thesis;
  end;
  for k be Nat holds P[k] from NAT_1:sch 2(A1,A2);
  hence thesis;
end;
