
theorem Th17:
  for X be non empty set, S be SigmaField of X, M be sigma_Measure
of S, f be PartFunc of X,ExtREAL, A be Element of S, E be SetSequence of S
 st f is A-measurable & A = dom f & E is disjoint_valued & A = Union E
  & (integral+(M,max+ f) < +infty or integral+(M,max- f) < +infty)
holds
 ex I be ExtREAL_sequence st (for n be Nat holds I.n = Integral(M,f|(E.n)))
  & I is summable & Integral(M,f) = Sum I
proof
    let X be non empty set, S be SigmaField of X, M be sigma_Measure of S,
    f be PartFunc of X,ExtREAL, A be Element of S, E be SetSequence of S;
    assume that
A1:  f is A-measurable and
A2:  A = dom f and
A3:  E is disjoint_valued and
A4:  A = Union E and
A5:  integral+(M,max+ f) < +infty or integral+(M,max- f) < +infty;

A6: max+ f is nonnegative & max-f is nonnegative by MESFUN11:5;
A7: max+ f is A-measurable & max- f is A-measurable by A1,A2,MESFUNC2:25,26;
A8: A = dom(max+ f) & A = dom(max- f) by A2,MESFUNC2:def 2,def 3;

    consider I1 be nonnegative ExtREAL_sequence such that
A9:  for n be Nat holds I1.n = Integral(M,(max+ f)|(E.n)) and
A10: I1 is summable & Integral(M,max+f) = Sum I1 by A7,A8,A3,A4,Lm1,MESFUN11:5;

    consider I2 be nonnegative ExtREAL_sequence such that
A11: for n be Nat holds I2.n = Integral(M,(max- f)|(E.n)) and
A12: I2 is summable & Integral(M,max-f) = Sum I2 by A7,A8,A3,A4,Lm1,MESFUN11:5;

A13: for n be Nat holds E.n is Element of S & E.n c= dom f
    proof
     let n be Nat;
     dom E = NAT by FUNCT_2:def 1; then
A14:  E.n in rng E by FUNCT_1:3,ORDINAL1:def 12;
     hence E.n is Element of S;
     E.n c= union rng E by A14,ZFMISC_1:74;
     hence E.n c= dom f by A2,A4,CARD_3:def 4;
    end;

A15: for n be Nat holds I1.n = integral+(M,max+f|(E.n))
    proof
     let n be Nat;
     reconsider En = E.n as Element of S by A13;
A16:  max+f is En-measurable by A7,A2,A13,MESFUNC1:30;
A17:  dom((max+f)|(E.n)) = En by A2,A8,A13,RELAT_1:62; then
     dom(max+f) /\ En = En by RELAT_1:61; then
A18:  (max+f)|(E.n) is En-measurable by A16,MESFUNC5:42;
     I1.n = Integral(M,(max+f)|(E.n)) by A9;
     hence thesis by A17,A18,A6,MESFUNC5:15,88;
    end;

A19: for n be Nat holds I2.n = integral+(M,max-f|(E.n))
    proof
     let n be Nat;
     reconsider En = E.n as Element of S by A13;
A20:  max-f is En-measurable by A7,A2,A13,MESFUNC1:30;
A21:  dom((max-f)|(E.n)) = En by A2,A8,A13,RELAT_1:62; then
     dom(max-f) /\ En = En by RELAT_1:61; then
A22:  (max-f)|(E.n) is En-measurable by A20,MESFUNC5:42;
     I2.n = Integral(M,(max-f)|(E.n)) by A11;
     hence thesis by A21,A22,A6,MESFUNC5:15,88;
    end;

    per cases by A5;
    suppose integral+(M,max+f) < +infty; then
A23: Integral(M,max+f) < +infty by A7,A8,MESFUNC5:88,MESFUN11:5; then
A24:  lim Partial_Sums I1 < +infty by A10,MESFUNC9:def 3;

     for n be set st n in dom I1 holds I1.n < +infty
     proof
      let n be set;
      assume A25: n in dom I1; then
      E.n is Element of S & E.n c= dom(max+f) by A2,A8,A13; then
      Integral(M,(max+f)|(E.n)) <= Integral(M,(max+f)|A)
        by A8,A7,MESFUNC5:93,MESFUN11:5; then
      Integral(M,(max+f)|(E.n)) < +infty by A8,A23,XXREAL_0:2;
      hence I1.n < +infty by A9,A25;
     end; then
     reconsider I1 as without+infty ExtREAL_sequence by MESFUNC5:11;
     take I = I1-I2;
     thus for n be Nat holds I.n = Integral(M,f|(E.n))
     proof
      let n be Nat;
A26:  n is Element of NAT by ORDINAL1:def 12;
      Integral(M,f|(E.n))
       = integral+(M,max+(f|(E.n))) - integral+(M,max-(f|(E.n)))
         by MESFUNC5:def 16
      .= integral+(M,max+f|(E.n)) - integral+(M,max-(f|(E.n)))
         by MESFUNC5:28
      .= integral+(M,max+f|(E.n)) - integral+(M,max-f|(E.n))
         by MESFUNC5:28
      .= I1.n - integral+(M,max-f|(E.n)) by A15
      .= I1.n - I2.n by A19;
      hence thesis by A26,DBLSEQ_3:7;
     end;

     Partial_Sums I1 is nonnegative & Partial_Sums I1 is non-decreasing
       by MESFUNC9:16; then
A27:  Partial_Sums I1 is convergent_to_+infty or
     Partial_Sums I1 is convergent_to_finite_number by DBLSEQ_3:62; then
     consider LI1 be Real such that
A28:  lim Partial_Sums I1 = LI1 and
      (for p be Real st 0<p ex n be Nat st for m be Nat st n<=m holds
       |. (Partial_Sums I1).m - lim Partial_Sums I1 .| < p) by A24,MESFUNC9:7;

A29: Partial_Sums I2 is nonnegative & Partial_Sums I2 is non-decreasing
       by MESFUNC9:16; then
A30:  Partial_Sums I2 is convergent_to_+infty or
     Partial_Sums I2 is convergent_to_finite_number by DBLSEQ_3:62;
A31:  Partial_Sums I = Partial_Sums I1 - Partial_Sums I2 by Th3;
     Partial_Sums I is convergent by A30,A31,A24,A27
,MESFUNC5:def 12,DBLSEQ_3:25;
     hence I is summable by MESFUNC9:def 2;

A32:  Integral(M,f) = integral+(M,max+f)-integral+(M,max-f) by MESFUNC5:def 16
      .= Integral(M,max+f)-integral+(M,max-f) by A7,A8,MESFUNC5:88,MESFUN11:5
      .= Integral(M,max+f)-Integral(M,max-f) by A7,A8,MESFUNC5:88,MESFUN11:5
      .= lim Partial_Sums I1 - Integral(M,max-f) by A10,MESFUNC9:def 3
      .= lim Partial_Sums I1 - lim Partial_Sums I2 by A12,MESFUNC9:def 3;

     thus Integral(M,f) = Sum I
     proof
      per cases by A29,DBLSEQ_3:62;
      suppose A33: Partial_Sums I2 is convergent_to_+infty; then
       lim Partial_Sums I2 = +infty by MESFUNC5:def 12; then
A34:    Integral(M,f) = -infty by A28,A32,XXREAL_3:13;

       lim (Partial_Sums I1 - Partial_Sums I2) = -infty
         by A33,A24,A27,MESFUNC5:def 12,DBLSEQ_3:25; then
       lim Partial_Sums I = -infty by Th3;
       hence Integral(M,f) = Sum I by A34,MESFUNC9:def 3;
      end;
      suppose A35: Partial_Sums I2 is convergent_to_finite_number;
       lim (Partial_Sums I)
        = lim (Partial_Sums I1 - Partial_Sums I2) by Th3
       .= lim Partial_Sums I1 - lim Partial_Sums I2
         by A35,A24,A27,MESFUNC5:def 12,DBLSEQ_3:25;
       hence Integral(M,f) = Sum I by A32,MESFUNC9:def 3;
      end;
     end;
    end;
    suppose integral+(M,max-f) < +infty; then
A36: Integral(M,max-f) < +infty by A7,A8,MESFUNC5:88,MESFUN11:5; then
A37:  lim Partial_Sums I2 < +infty by A12,MESFUNC9:def 3;

     for n be set st n in dom I2 holds I2.n < +infty
     proof
      let n be set;
      assume A38: n in dom I2; then
      E.n is Element of S & E.n c= dom(max-f) by A2,A8,A13; then
      Integral(M,(max-f)|(E.n)) <= Integral(M,(max-f)|A)
        by A8,A7,MESFUNC5:93,MESFUN11:5; then
      Integral(M,(max-f)|(E.n)) < +infty by A8,A36,XXREAL_0:2;
      hence I2.n < +infty by A11,A38;
     end; then
     reconsider I2 as without+infty ExtREAL_sequence by MESFUNC5:11;

     take I = I1-I2;
     thus for n be Nat holds I.n = Integral(M,f|(E.n))
     proof
      let n be Nat;
A39:  n is Element of NAT by ORDINAL1:def 12;
      Integral(M,f|(E.n))
       = integral+(M,max+(f|(E.n))) - integral+(M,max-(f|(E.n)))
         by MESFUNC5:def 16
      .= integral+(M,max+f|(E.n)) - integral+(M,max-(f|(E.n)))
         by MESFUNC5:28
      .= integral+(M,max+f|(E.n)) - integral+(M,max-f|(E.n))
         by MESFUNC5:28
      .= I1.n - integral+(M,max-f|(E.n)) by A15
      .= I1.n - I2.n by A19;
      hence thesis by A39,DBLSEQ_3:7;
     end;

     Partial_Sums I2 is nonnegative & Partial_Sums I2 is non-decreasing
       by MESFUNC9:16; then
A40:  Partial_Sums I2 is convergent_to_+infty or
     Partial_Sums I2 is convergent_to_finite_number by DBLSEQ_3:62; then
     consider LI2 be Real such that
A41:  lim Partial_Sums I2 = LI2 and
      (for p be Real st 0<p ex n be Nat st for m be Nat st n<=m holds
       |. (Partial_Sums I2).m - lim Partial_Sums I2 .| < p) by A37,MESFUNC9:7;

A42: Partial_Sums I1 is nonnegative & Partial_Sums I1 is non-decreasing
       by MESFUNC9:16; then
A43:  Partial_Sums I1 is convergent_to_+infty or
     Partial_Sums I1 is convergent_to_finite_number by DBLSEQ_3:62;
     Partial_Sums I = Partial_Sums I1 - Partial_Sums I2 by Th3; then
     Partial_Sums I is convergent by A43,A40,A37,MESFUNC5:def 12,DBLSEQ_3:25;
     hence I is summable by MESFUNC9:def 2;

A44:  Integral(M,f) = integral+(M,max+f)-integral+(M,max-f) by MESFUNC5:def 16
      .= Integral(M,max+f)-integral+(M,max-f) by A7,A8,MESFUNC5:88,MESFUN11:5
      .= Integral(M,max+f)-Integral(M,max-f) by A7,A8,MESFUNC5:88,MESFUN11:5
      .= lim Partial_Sums I1 - Integral(M,max-f) by A10,MESFUNC9:def 3
      .= lim Partial_Sums I1 - lim Partial_Sums I2 by A12,MESFUNC9:def 3;

     thus Integral(M,f) = Sum I
     proof
      per cases by A42,DBLSEQ_3:62;
      suppose A45: Partial_Sums I1 is convergent_to_+infty; then
       lim Partial_Sums I1 = +infty by MESFUNC5:def 12; then
A46:    Integral(M,f) = +infty by A41,A44,XXREAL_3:13;

       lim (Partial_Sums I1 - Partial_Sums I2) = +infty
         by A45,A40,A37,MESFUNC5:def 12,DBLSEQ_3:25; then
       lim Partial_Sums I = +infty by Th3;
       hence Integral(M,f) = Sum I by A46,MESFUNC9:def 3;
      end;
      suppose A47: Partial_Sums I1 is convergent_to_finite_number;
       lim (Partial_Sums I)
        = lim (Partial_Sums I1 - Partial_Sums I2) by Th3
       .= lim Partial_Sums I1 - lim Partial_Sums I2
         by A47,A40,A37,MESFUNC5:def 12,DBLSEQ_3:25;
       hence Integral(M,f) = Sum I by A44,MESFUNC9:def 3;
      end;
     end;
    end;
end;
