reserve i, j, m, n for Nat,
  z, B0 for set,
  f, x0 for real-valued FinSequence;

theorem Th41:
  for f being FinSequence of REAL n, g being FinSequence of the
  carrier of RealVectSpace(Seg n) st f=g holds Sum f=Sum g
proof
  let f be FinSequence of REAL n, g be FinSequence of the carrier of
  RealVectSpace(Seg n);
  assume
A1: f=g;
  set V=RealVectSpace(Seg n);
A2: REAL(n) = the carrier of V by FINSEQ_2:93;
  now
    per cases;
    case
A3:   len f>0;
      set g2 = accum f;
A4:   len f=len g2 by Def10;
A5:   f.1=g2.1 by Def10;
A6:   Sum f=g2.(len f) by Def11,A3;
      deffunc F(set)=IFIN($1,len f+1,IFEQ($1,0, 0.V, g2/.$1),0.V);
A7:   for x being set st x in NAT holds F(x) in the carrier of V
      proof
        let x be set;
        assume x in NAT;
        then reconsider nx=x as Element of NAT;
        per cases;
        suppose
          nx in (len f+1);
          then
A8:       F(x)=IFEQ(x,0, 0.V, g2/.nx) by MATRIX_7:def 1;
          per cases;
          suppose x=0;
            then F(x)=0.V by A8,FUNCOP_1:def 8;
            hence F(x) in the carrier of V;
          end;
          suppose x<>0;
            then F(x)=g2/.nx by A8,FUNCOP_1:def 8;
            hence F(x) in the carrier of V by A2;
          end;
        end;
        suppose not nx in (len f +1);
          then F(x)=0.V by MATRIX_7:def 1;
          hence F(x) in the carrier of V;
        end;
      end;
      consider f3 being sequence of the carrier of V such that
A9:  for x being set st x in NAT holds f3.x = F(x) from FUNCT_2:sch
      11(A7);
A10:  for j being Nat for v being Element of V st j < len g &
      v = g . (j + 1) holds f3 . (j + 1) = (f3 . j) + v
      proof
        let j be Nat;
A11:      j in NAT by ORDINAL1:def 12;
        let v be Element of V;
        assume that
A12:    j < len g and
A13:    v = g . (j + 1);
A14:    j+1<=len f by A1,A12,NAT_1:13;
        per cases;
        suppose
A15:      j=0;
          then j+1<len f+1 by A3,XREAL_1:6;
          then
A16:      (j+1) in Segm(len f+1) by NAT_1:44;
A17:      0 in Segm(len f +1) by NAT_1:44;
A18:      f3.j=IFIN(j,len f+1,IFEQ(j,0, 0.V, g2/.j),0.V) by A9,A11
            .= IFEQ(j,0, 0.V, g2/.j) by A15,A17,MATRIX_7:def 1
            .= 0.V by A15,FUNCOP_1:def 8;
          thus f3.(j+1)=IFIN(j+1,len f+1,IFEQ(j+1,0, 0.V, g2/.(j+1)),0.V) by A9
            .=IFEQ(j+1,0, 0.V, g2/.(j+1)) by A16,MATRIX_7:def 1
            .=g2/.1 by A15,FUNCOP_1:def 8
            .=g.(j+1) by A1,A4,A5,A14,A15,FINSEQ_4:15
            .= (f3.j)+v by A13,A18,RLVECT_1:4;
        end;
        suppose
A19:      j<>0;
          len f<len f+1 by XREAL_1:29;
          then j< len f+1 by A1,A12,XXREAL_0:2;
          then
A20:      j in Segm(len f +1) by NAT_1:44;
A21:      f3.j=IFIN(j,len f+1,IFEQ(j,0, 0.V, g2/.j),0.V) by A9,A11
            .= IFEQ(j,0, 0.V, g2/.j) by A20,MATRIX_7:def 1
            .= g2/.j by A19,FUNCOP_1:def 8;
A22:      0+1<=j+1 by NAT_1:13;
A23:      0+1<=j by A19,NAT_1:13;
          j+1<len f+1 by A1,A12,XREAL_1:6;
          then
A24:      (j+1) in Segm(len f+1) by NAT_1:44;
          thus f3.(j+1)=IFIN(j+1,len f+1,IFEQ(j+1,0, 0.V, g2/.(j+1)),0.V) by A9
            .=IFEQ(j+1,0, 0.V, g2/.(j+1)) by A24,MATRIX_7:def 1
            .=g2/.(j+1) by FUNCOP_1:def 8
            .=g2.(j+1) by A4,A14,A22,FINSEQ_4:15
            .=(g2/.j)+(f/.(j+1)) by A1,Def10,A12,A23
            .=(f3.j)+v by A1,A13,A14,A22,A21,FINSEQ_4:15;
        end;
      end;
      len f <len f+1 by XREAL_1:29;
      then
A25:  len f in Segm(len f+1) by NAT_1:44;
A26:  0+1<=len f by A3,NAT_1:13;
A27:  0 in Segm(len f +1) by NAT_1:44;
A28:  f3.0=IFIN(0,len f+1,IFEQ(0,0, 0.V, g2/.0),0.V) by A9
        .=IFEQ(0,0, 0.V, g2/.0) by A27,MATRIX_7:def 1
        .=0.V by FUNCOP_1:def 8;
      f3.(len g)=F(len f) by A1,A9
        .=IFEQ(len f,0,0.V,g2/.(len f)) by A25,MATRIX_7:def 1
        .=g2/.(len f) by A3,FUNCOP_1:def 8
        .=Sum f by A4,A6,A26,FINSEQ_4:15;
      hence
      ex f2 being sequence of the carrier of V st Sum f = f2 . (len g
) & f2 . 0 = 0. V & for j being Nat for v being Element of V st j <
      len g & v = g . (j + 1) holds f2 . (j + 1) = (f2 . j) + v by A28,A10;
    end;
    case
A29:  len f<=0;
      set f3 = NAT --> 0.V;
A30:  for j being Nat for v being Element of V st j < len g &
      v = g . (j + 1) holds f3 . (j + 1) = (f3 . j) + v by A1,A29;
A31:  f3.(len g)= 0*n by FUNCOP_1:7;
A32:  f3.0=0.V by FUNCOP_1:7;
      Sum f = 0*n by A29,Def11;
      hence
      ex f2 being sequence of the carrier of V st Sum f = f2 . (len g
) & f2 . 0 = 0. V & for j being Nat for v being Element of V st j <
      len g & v = g . (j + 1) holds f2 . (j + 1) = (f2 . j) + v by A31,A32,A30;
    end;
  end;
  hence Sum f=Sum g by RLVECT_1:def 12;
end;
