reserve n for Nat;

theorem Th7:
  for n be Nat, x be Element of REAL n st (for i be
  Nat st i in Seg n holds 0 <= x.i) holds 0 <= Sum x & for i be
  Nat st i in Seg n holds x.i <= Sum x
proof
  defpred P[Nat] means for x be Element of REAL $1 st (for i be
  Nat st i in Seg $1 holds 0 <= x.i) holds 0 <= Sum x & (for i be
  Nat st i in Seg $1 holds x.i <= Sum x);
A1: now
    let k be Nat such that
A2: P[k];
    now
      let x be Element of REAL (k+1);
      assume
A3:   for i be Nat st i in Seg (k+1) holds 0 <= x.i;
      thus 0 <= Sum x & for i be Nat st i in Seg (k+1) holds x.i <=
      Sum x
      proof
        set xk= x|k;
A4:     0 <= x.(k+1) by A3,FINSEQ_1:4;
A5:     k+1 = len x by CARD_1:def 7;
        then len(x|k) = k by FINSEQ_1:59,NAT_1:11;
        then
A6:     xk is Element of k-tuples_on REAL by FINSEQ_2:92;
        1 <= k+1 by NAT_1:11;
        then k+1 in Seg len x by A5,FINSEQ_1:1;
        then
A7:     k+1 in dom x by FINSEQ_1:def 3;
        reconsider xk as Element of REAL k by A6,EUCLID:def 1;
A8:     xk = x|Seg k by FINSEQ_1:def 16;
        x = x| (k+1) by A5,FINSEQ_1:58
          .= x|Seg(k+1) by FINSEQ_1:def 16
          .= xk^<* x.(k+1) *> by A7,A8,FINSEQ_5:10;
        then
A9:     Sum x=Sum xk + x.(k+1) by RVSUM_1:74;
A10:    now
          let i be Nat;
          assume
A11:      i in Seg k;
          k <= k+1 by NAT_1:11;
          then Seg k c= Seg(k+1) by FINSEQ_1:5;
          then 0 <= x.i by A3,A11;
          then 0 <= (x|Seg k).i by A11,FUNCT_1:49;
          hence 0 <= xk.i by FINSEQ_1:def 16;
        end;
A12:    k+1 in Seg (k+1) by FINSEQ_1:4;
A13:    now
          let i be Nat;
          assume
A14:      i in Seg (k+1);
          then
A15:      1 <= i by FINSEQ_1:1;
A16:      i <=k+1 by A14,FINSEQ_1:1;
          per cases by A16,XXREAL_0:1;
          suppose
            i < k+1;
            then i <=k by NAT_1:13;
            then
A17:        i in Seg k by A15,FINSEQ_1:1;
            then xk.i <= Sum xk by A2,A10;
            then
A18:        x.i <= Sum xk by A8,A17,FUNCT_1:49;
            Sum xk <= Sum xk + x.(k+1) by A3,A12,XREAL_1:31;
            hence x.i <=Sum x by A9,A18,XXREAL_0:2;
          end;
          suppose
            i=k+1;
            hence x.i <= Sum x by A2,A10,A9,XREAL_1:31;
          end;
        end;
        0 <=Sum xk by A2,A10;
        hence thesis by A4,A9,A13;
      end;
    end;
    hence P[k+1];
  end;
A19: P[0] by RVSUM_1:72;
  thus for k be Nat holds P[k] from NAT_1:sch 2(A19,A1);
end;
