reserve X for set;
reserve X,X1,X2 for non empty set;
reserve S for SigmaField of X;
reserve S1 for SigmaField of X1;
reserve S2 for SigmaField of X2;
reserve M for sigma_Measure of S;
reserve M1 for sigma_Measure of S1;
reserve M2 for sigma_Measure of S2;

theorem Th23:
for A being Element of S, f being PartFunc of X,ExtREAL st
  M.A = 0 & A c= dom f & f|A` is_integrable_on M holds
  ex g be PartFunc of X,ExtREAL st dom g = dom f &
    f|A` = g|A` & g is_integrable_on M & Integral(M,f|A`) = Integral(M,g)
proof
    let A be Element of S, f be PartFunc of X,ExtREAL;
    assume that
A2:  M.A = 0 and
A1:  A c= dom f and
A3:  f|A` is_integrable_on M;
    consider B be Element of S such that
A4:  B = dom(f|A`) & f|A` is B-measurable by A3,MESFUNC5:def 17;
A5: f|A` = f|(dom f \ A) by Th15; then
A6: B = dom f /\ (dom f \ A) by A4,RELAT_1:61
     .= (dom f /\ dom f) \ A by XBOOLE_1:49
     .= dom f \ A; then
A7: dom f =  A \/ B by A1,XBOOLE_1:45;
A8: (ex E be Element of S st E = dom(f|B) & f|B is E-measurable)
  & integral+(M,max+(f|B)) < +infty & integral+(M,max-(f|B)) < +infty
      by A3,A5,A6,MESFUNC5:def 17;
    defpred C[object] means $1 in A;
    deffunc F(object) = +infty;
    deffunc G(object) = f.$1;
    consider g be Function such that
A9:  dom g = dom f &
     for x be object st x in dom f holds
      (C[x] implies g.x = F(x)) & (not C[x] implies g.x = G(x))
        from PARTFUN1:sch 1;
    now let y be object;
     assume y in rng g; then
     consider x be object such that
A10:  x in dom g & y = g.x by FUNCT_1:def 3;
     per cases;
     suppose x in A; then
      g.x = +infty by A9,A10;
      hence y in ExtREAL by A10,XXREAL_0:def 1;
     end;
     suppose not x in A; then
      g.x = f.x by A9,A10; then
      g.x in rng f by A9,A10,FUNCT_1:3;
      hence y in ExtREAL by A10;
     end;
    end; then
    rng g c= ExtREAL; then
    reconsider g as PartFunc of X,ExtREAL by A9,RELSET_1:4;
    take g;
    thus dom g = dom f by A9;
    dom(f|A`) = dom f /\ A` by RELAT_1:61; then
A11:dom(f|A`) = dom(g|A`) by A9,RELAT_1:61;
    now let x be Element of X;
     assume x in dom(f|A`); then
A12: x in dom f & x in A` by RELAT_1:57; then
     x in X \ A by SUBSET_1:def 4; then
A13: not x in A by XBOOLE_0:def 5;
     (f|A`).x = f.x by A12,FUNCT_1:49; then
     (f|A`).x = g.x by A9,A12,A13;
     hence (f|A`).x = (g|A`).x by A12,FUNCT_1:49;
    end;
    hence
A14: f|A` = g|A` by A11,PARTFUN1:5;
A15:A` = X \ A by SUBSET_1:def 4; then
    f|B = (g|A`)|B by A6,A14,XBOOLE_1:33,RELAT_1:74; then
    f|B = g|B by A6,A15,XBOOLE_1:33,RELAT_1:74; then
A16:(max+g)|B = max+(f|B) & (max-g)|B = max-(f|B) by MESFUNC5:28;
A17:for r be Real holds (A \/ B) /\ less_dom(g,r) in S
    proof
     let r be Real;
     now let x be object;
      assume x in (A \/ B) /\ less_dom(g,r); then
A18:  x in dom f & x in less_dom(g,r) by A7,XBOOLE_0:def 4; then
A19:  x in dom g & g.x < r by MESFUNC1:def 11;
A20:  now assume x in A; then
       g.x = +infty by A9,A18;
       hence contradiction by A19,XXREAL_0:3;
      end; then
A21:  x in B by A7,A18,XBOOLE_0:def 3;
      g.x = f.x by A9,A18,A20; then
      (f|B).x < r by A19,A21,FUNCT_1:49; then
      x in less_dom(f|B,r) by A4,A5,A6,A21,MESFUNC1:def 11;
      hence x in B /\ less_dom(f|B,r) by A21,XBOOLE_0:def 4;
     end; then
A22: (A \/ B) /\ less_dom(g,r) c= B /\ less_dom(f|B,r);
     now let x be object;
      assume x in B /\ less_dom(f|B,r); then
A23:  x in B & x in less_dom(f|B,r) by XBOOLE_0:def 4; then
A24:  x in dom(f|B) & (f|B).x < r by MESFUNC1:def 11;
A25:  x in dom f & not x in A by A23,A6,XBOOLE_0:def 5; then
      g.x = f.x by A9; then
      g.x < r by A24,FUNCT_1:47; then
      x in less_dom(g,r) by A9,A25,MESFUNC1:def 11;
      hence x in (A \/ B) /\ less_dom(g,r) by A7,A25,XBOOLE_0:def 4;
     end; then
     B /\ less_dom(f|B,r) c= (A \/ B) /\ less_dom(g,r); then
     (A \/ B) /\ less_dom(g,r) = B /\ less_dom(f|B,r) by A22;
     hence (A \/ B) /\ less_dom(g,r) in S by A4,A5,A6;
    end; then
A26:max+g is (A\/B)-measurable & max-g is (A\/B)-measurable
      by A7,A9,MESFUNC1:def 16,MESFUNC2:25,26;
A27:(max+g)|B is nonnegative & (max-g)|B is nonnegative
     by MESFUNC5:15,MESFUN11:5;
A28:dom(max+g) = A \/ B & dom(max-g) = A \/ B by A7,A9,MESFUNC2:def 2,def 3;
A29:B = (A \/ B) /\ B by XBOOLE_1:7,28; then
A30:dom((max+g)|B) = B & dom((max-g)|B) = B by A28,RELAT_1:61;
A31:max+g is B-measurable & max-g is B-measurable
      by A26,XBOOLE_1:7,MESFUNC1:30;
    Integral(M,(max+g)|B) = Integral(M,max+g)
  & Integral(M,(max-g)|B) = Integral(M,max-g)
      by A2,A6,A7,A26,A28,MESFUNC5:95; then
    integral+(M,(max+g)|B) = Integral(M,max+g)
  & integral+(M,(max-g)|B) = Integral(M,max-g)
      by A27,A28,A29,A30,A31,MESFUNC5:42,88; then
    integral+(M,max+g) < +infty & integral+(M,max-g) < +infty
      by A8,A16,A26,A28,MESFUNC5:88,MESFUN11:5;
    hence g is_integrable_on M by A7,A9,A17,MESFUNC5:def 17,MESFUNC1:def 16;
    f is_a.e.integrable_on M by A1,A2,A3; then
    reconsider E = dom f as Element of S by Th16;
    Integral(M,f|A`) = Integral(M,g|(dom g \ A)) by A14,Th15;
    hence Integral(M,f|A`) = Integral(M,g)
      by A2,A7,A9,A17,MESFUNC5:95,MESFUNC1:def 16;
end;
