
theorem Th5:
for X be non empty set, S be SigmaField of X,
 f be non empty PartFunc of X,ExtREAL, M be sigma_Measure of S
  st f is_simple_func_in S
 ex E be non empty Finite_Sep_Sequence of S, a be FinSequence of ExtREAL,
  r be FinSequence of REAL st
  E,a are_Re-presentation_of f &
  for n be Nat holds
    a.n = r.n & f|(E.n) = (chi(r.n,E.n,X))|(E.n) & (E.n = {} implies r.n = 0)
proof
    let X be non empty set, S be SigmaField of X,
    f be non empty PartFunc of X,ExtREAL,
    M be sigma_Measure of S;
    assume A1: f is_simple_func_in S; then
    consider E be Finite_Sep_Sequence of S,
      b be FinSequence of ExtREAL such that
A2:  E,b are_Re-presentation_of f by MESFUNC3:12;
A3: dom f = union rng E & dom E = dom b
  & for n be Nat st n in dom E for x be object st x in E.n holds f.x = b.n
      by A2,MESFUNC3:def 1;
    reconsider E as non empty Finite_Sep_Sequence of S by A3,ZFMISC_1:2;
A4: for n be Nat st E.n <> {} holds b.n in REAL
    proof
     let n be Nat;
     assume A5: E.n <> {}; then
     consider x be object such that
A6:   x in E.n by XBOOLE_0:def 1;
A7:  n in dom E by A5,FUNCT_1:def 2; then
     E.n in rng E by FUNCT_1:3; then
     x in dom f by A3,A6,TARSKI:def 4; then
A8:  f.x in rng f by FUNCT_1:3;
     rng f is Subset of REAL by A1,MESFUNC2:def 4,32; then
     f.x in REAL by A8;
     hence b.n in REAL by A2,A6,A7,MESFUNC3:def 1;
    end;
    defpred P1[Nat,object] means
     (E.$1 <> {} implies $2 = b.$1) & (E.$1 = {} implies $2 = 0);
A9: for n be Nat st n in Seg len E ex a be Element of ExtREAL st P1[n,a]
    proof
     let n be Nat;
     assume n in Seg len E;
     per cases;
     suppose A10: E.n <> {};
      take a = b.n;
      thus P1[n,a] by A10;
     end;
     suppose A11: E.n = {};
      take a = 0.;
      thus P1[n,a] by A11;
     end;
    end;

    consider a be FinSequence of ExtREAL such that
A12: dom a = Seg len E & for n be Nat st n in Seg len E holds P1[n,a.n]
      from FINSEQ_1:sch 5(A9);

    defpred P2[Nat,object] means $2 = a.$1;

A13:for n be Nat st n in Seg len E ex r be Element of REAL st P2[n,r]
    proof
     let n be Nat;
     assume A14: n in Seg len E;
     per cases;
     suppose A15: E.n <> {}; then
      a.n = b.n by A12,A14; then
      reconsider r = a.n as Element of REAL by A4,A15;
      take r;
      thus P2[n,r];
     end;
     suppose E.n = {}; then
      a.n = 0 by A12,A14; then
      reconsider r = a.n as Element of REAL by XREAL_0:def 1;
      take r;
      thus P2[n,r];
     end;
    end;

    consider r be FinSequence of REAL such that
A16: dom r = Seg len E & for n be Nat st n in Seg len E holds P2[n,r.n]
      from FINSEQ_1:sch 5(A13);

    take E,a,r;

A17:dom a = dom E by A12,FINSEQ_1:def 3;

A18:for n be Nat st n in dom E for x be object st x in E.n holds f.x = a.n
    proof
     let n be Nat;
     assume A19: n in dom E; then
A20: n in Seg len E by FINSEQ_1:def 3;
     let x be object;
     assume A21: x in E.n; then
     f.x = b.n by A2,A19,MESFUNC3:def 1;
     hence f.x = a.n by A12,A20,A21;
    end;
    hence E,a are_Re-presentation_of f by A3,A17,MESFUNC3:def 1;

    thus for n be Nat holds a.n = r.n & f|(E.n) = (chi(r.n,E.n,X))|(E.n) &
     (E.n = {} implies r.n = 0)
    proof
     let n be Nat;
     per cases;
     suppose A22: E.n <> {}; then
A23:  n in dom E by FUNCT_1:def 2; then
      n in Seg len E by FINSEQ_1:def 3;
      hence A24:  a.n = r.n by A16;

      E.n c= dom f by A3,A23,FUNCT_1:3,ZFMISC_1:74; then
A27:  dom (f|(E.n)) = E.n by RELAT_1:62;

      dom(chi(r.n,E.n,X)) = X by FUNCT_2:def 1; then
A28:  dom((chi(r.n,E.n,X))|(E.n)) = dom(f|(E.n)) by A27,RELAT_1:62;

      for x be Element of X st x in dom (f|(E.n)) holds
       (f|(E.n)).x = ( (chi(r.n,E.n,X))|(E.n) ).x
      proof
       let x be Element of X;
       assume A29: x in dom(f|(E.n)); then
       ( (chi(r.n,E.n,X))|(E.n) ).x = chi(r.n,E.n,X).x by A27,FUNCT_1:49
        .= a.n by A24,A27,A29,Def1
        .= f.x by A18,A23,A27,A29;
       hence (f|(E.n)).x = ( (chi(r.n,E.n,X))|(E.n) ).x by A29,FUNCT_1:47;
      end;
      hence thesis by A22,A28,PARTFUN1:5;
     end;
     suppose z1: E.n = {};
      now per cases;
       suppose n in dom E; then
A30:    n in Seg len E by FINSEQ_1:def 3;
        hence a.n = 0 by A12,z1;
        hence r.n = 0 by A30,A16;
       end;
       suppose A31: not n in dom E;
        hence a.n = 0 by A17,FUNCT_1:def 2;
        not n in Seg len E by A31,FINSEQ_1:def 3;
        hence r.n = 0 by A16,FUNCT_1:def 2;
       end;
      end;
      hence thesis by z1;
     end;
    end;
end;
