reserve i,j,n,n1,n2,m,k,u for Nat,
        r,r1,r2 for Real,
        x,y for Integer,
        a,b for non trivial Nat;

theorem Th1:
  for F be FinSequence of NAT st
    for k st 1 < k <= len F holds (F.k) mod n = 0
  holds Sum F mod n = (F.1) mod n
proof
  defpred P[Nat] means for F be FinSequence of NAT st
    len F = $1 & for k st 1 < k <= len F holds (F.k) mod n = 0
      holds Sum F mod n = (F.1) mod n;
A1:P[0]
  proof
    let F be FinSequence of NAT such that A2: len F = 0;
    F = {} by A2;
    hence thesis;
  end;
  A3:P[k] implies P[k+1]
  proof
    assume
A4:   P[k];set k1=k+1;
    let F be FinSequence of NAT such that
A5:   len F = k+1 and
A6:   for i be Nat st 1<i<=len F holds (F.i) mod n = 0;
    per cases;
    suppose k=0;
      then F = <*F.1*> by A5,FINSEQ_1:40;
      hence thesis;
    end;
    suppose
A7:     k >0;
      F is non empty by A5;
      then len F in dom F by FINSEQ_5:6;
      then (F|k) ^ <*F.k1*> = F| k1 by A5,FINSEQ_5:10
        .=F by A5;
      then
A8:   Sum F = Sum (F|k) + F.k1 by RVSUM_1:74;
A9:   k <= k1 by NAT_1:11;
A10:  len (F|k) = k by A5,NAT_1:11,FINSEQ_1:59;
      for i be Nat st 1 < i <= len (F|k) holds ((F|k).i) mod n = 0
      proof
        let i be Nat such that
A11:    1< i <= len (F|k);
        (F|k).i = F.i & i <= len F by A10,A11,A5,A9,FINSEQ_3:112,XXREAL_0:2;
        hence thesis by A11,A6;
      end;
      then
A12:  Sum (F|k) mod n = ((F|k).1) mod n by A4,A10;
A13:  F.1 mod n = Sum (F|k) mod n by A7,NAT_1:14,A12,FINSEQ_3:112;
      per cases;
      suppose n=0;
        then Sum F mod n = 0 = (F.1) mod n by INT_1:def 10;
        hence thesis;
      end;
      suppose
A14:    n >0;
A15:    Sum(F|k) is Nat & Sum(F) is Nat by TARSKI:1;
        0+1< k1 by A7,XREAL_1:8;
        then 0= (Sum F - Sum (F|k))mod n by A5,A6,A8;
        hence thesis by A13, A15,A14,INT_4:22;
      end;
    end;
  end;
  P[k] from NAT_1:sch 2(A1,A3);
  hence thesis;
end;
