reserve Z for set;

theorem Th11:
  for n be Element of NAT, A be non empty closed_interval Subset of REAL, f
  being Function of A,REAL n, T being DivSequence of A, S be
  middle_volume_Sequence of f,T st f is bounded & f is integrable & delta(T) is
  convergent & lim delta(T)=0 holds middle_sum(f,S) is convergent & lim (
  middle_sum(f,S))=integral(f)
proof
  let n be Element of NAT, A be non empty closed_interval Subset of REAL,
  f being
Function of A,REAL n, T being DivSequence of A, S be middle_volume_Sequence of
  f,T;
  assume that
A1: f is bounded & f is integrable and
A2: delta(T) is convergent & lim delta(T)=0;
  set seq=middle_sum(f,S);
  set xs=integral(f);
  (REAL n) = the carrier of (REAL-NS n) by REAL_NS1:def 4;
  then reconsider xseq=seq as sequence of REAL n;
A3: for i be Nat st i in Seg n ex rseqi be Real_Sequence st
     for k be Nat holds rseqi.k = (xseq.k).i &
    rseqi is convergent & xs.i = lim rseqi
  proof
    let i be Nat;
    reconsider pjinf= (proj(i,n)*f) as Function of A,REAL;
    defpred P[Element of NAT,set] means $2= proj(i,n)*(S.$1);
A4: for x being Element of NAT ex y being Element of (REAL)* st P[x, y]
    proof
      let x being Element of NAT;
      proj(i,n)*(S.x) is Element of REAL* by FINSEQ_1:def 11;
      hence thesis;
    end;
    consider F being sequence of  (REAL)* such that
A5: for x being Element of NAT holds P[x, F.x] from FUNCT_2:sch 3(A4);
A6: for x being Element of NAT holds proj(i,n)*(S.x) is FinSequence of REAL
    & dom(proj(i,n)*(S.x)) =Seg len(S.x) & rng(proj(i,n)*(S.x)) c= REAL
    proof
      let x being Element of NAT;
      dom (proj(i,n))=REAL n by FUNCT_2:def 1;
      then rng (S.x) c= dom(proj(i,n));
      then dom(proj(i,n)*(S.x)) = dom (S.x) by RELAT_1:27
        .= Seg len(S.x) by FINSEQ_1:def 3;
      hence thesis;
    end;
    for k be Element of NAT holds F.k is middle_volume of pjinf,T.k
    proof
      let k be Element of NAT;
      reconsider Tk=T.k as FinSequence;
      reconsider Fk=F.k as FinSequence of REAL;
A7:   F.k= proj(i,n)*(S.k) by A5;
      then
A8:   dom (Fk) =Seg len(S.k) by A6
        .=Seg len(Tk) by Def5;
      then
A9:   dom (Fk) = dom (Tk) by FINSEQ_1:def 3;
A10:  now
        let j be Nat;
        dom (proj(i,n))=REAL n by FUNCT_2:def 1;
        then
A11:    rng (f) c= dom(proj(i,n));
        assume
A12:    j in dom (Tk);
        then consider r be Element of (REAL n) such that
A13:    r in rng (f|divset((T.k),j)) and
A14:    (S.k).j=vol divset((T.k),j)*r by Def5;
        reconsider v=proj(i,n).r as Element of REAL;
        take v;
        consider t be object such that
A15:    t in dom (f|divset((T.k),j)) and
A16:    r=(f|divset((T.k),j)).t by A13,FUNCT_1:def 3;
        t in dom(f) /\ divset((T.k),j) by A15,RELAT_1:61;
        then t in dom(f) by XBOOLE_0:def 4;
        then
A17:    t in dom (proj(i,n)*f) by A11,RELAT_1:27;
A18:    dom (f|divset((T.k),j)) =dom (f) /\ divset((T.k),j) by RELAT_1:61
          .=dom (pjinf) /\ divset((T.k),j) by A11,RELAT_1:27
          .=dom (pjinf|divset((T.k),j)) by RELAT_1:61;
        proj(i,n).r = proj(i,n).(f.t) by A15,A16,FUNCT_1:47
          .= (proj(i,n)*f).t by A17,FUNCT_1:12
          .= (pjinf|divset((T.k),j)).t by A15,A18,FUNCT_1:47;
        hence v in rng (pjinf|divset((T.k),j)) by A15,A18,FUNCT_1:3;
        thus (Fk).j = proj(i,n).((S.k).j) by A7,A9,A12,FUNCT_1:12
          .= (vol divset((T.k),j)*r).i by A14,PDIFF_1:def 1
          .= vol divset((T.k),j) * (r.i) by RVSUM_1:44
          .= v*vol divset((T.k),j) by PDIFF_1:def 1;
      end;
      len (Fk) = len(Tk) by A8,FINSEQ_1:def 3;
      hence thesis by A10,Def1;
    end;
    then reconsider pjis = F as middle_volume_Sequence of pjinf,T by Def3;
    reconsider rseqi = middle_sum(pjinf,pjis) as Real_Sequence;
    assume
A19: i in Seg n;
A20: for k be Nat holds rseqi.k = (xseq.k).i
    proof
      let k be Nat;
      reconsider k as Element of NAT by ORDINAL1:def 12;
A21:  ex Fi be FinSequence of REAL st Fi=proj(i,n)*(S.k) &
       (middle_sum(f,S.k)).i = Sum(Fi) by A19,Def6;
      rseqi.k = middle_sum(pjinf,pjis.k) by Def4
        .= (middle_sum(f,S.k)).i by A5,A21
        .= (xseq.k).i by Def8;
     hence thesis;
    end;
    take rseqi;
A22: (proj(i,n)*f) is bounded & pjinf is integrable by A1,A19;
    then lim (middle_sum(pjinf,pjis))=integral(pjinf) by A2,Th9;
    hence thesis by A2,A19,A22,A20,Def14,Th9;
  end;
  reconsider x=xs as Point of REAL-NS n by REAL_NS1:def 4;
  xs = x;
  hence thesis by A3,REAL_NS1:11;
end;
