
theorem Th65:
for f be PartFunc of REAL,REAL, b be Real st left_closed_halfline b c= dom f
 & f is_-infty_ext_Riemann_integrable_on b
 & abs f is_-infty_ext_Riemann_integrable_on b
holds max+f is_-infty_ext_Riemann_integrable_on b
proof
    let f be PartFunc of REAL,REAL, b be Real;
    assume that
A1:  left_closed_halfline b c= dom f and
A2:  f is_-infty_ext_Riemann_integrable_on b and
A3: abs f is_-infty_ext_Riemann_integrable_on b;

A4: b in REAL by XREAL_0:def 1;

A5: left_closed_halfline b = ].-infty,b.] by LIMFUNC1:def 1;

    set G = infty_ext_left_integral(f,b);
    set AG = infty_ext_left_integral(abs f,b);

    consider I be PartFunc of REAL,REAL such that
A6:  dom I = left_closed_halfline b and
A7:  for x be Real st x in dom I holds I.x = integral(f,x,b) and
A8:  I is convergent_in-infty and
A9:  G = lim_in-infty I by A2,INTEGR10:def 8;
    consider AI be PartFunc of REAL,REAL such that
A10:  dom AI = left_closed_halfline b and
A11:  for x be Real st x in dom AI holds AI.x = integral(abs f,x,b) and
A12:  AI is convergent_in-infty and
A13: AG = lim_in-infty AI by A3,INTEGR10:def 8;

A14:for d be Real st d <= b holds
     max+f is_integrable_on ['d,b'] & (max+f)|['d,b'] is bounded
    proof
     let d be Real;
     assume
A15:  d <= b; then
A16: f is_integrable_on ['d,b'] & f|['d,b'] is bounded
       by A2,INTEGR10:def 6;
A17: (f||['d,b'])|['d,b'] is bounded by A15,A2,INTEGR10:def 6;

A18:  d in REAL by XREAL_0:def 1;
     ['d,b'] = [.d,b.] by A15,INTEGRA5:def 3; then
     ['d,b'] c= ].-infty,b.] by A18,XXREAL_0:12,XXREAL_1:39; then
A19: ['d,b'] c= dom f by A1,A5; then
A20: dom(f||['d,b']) = ['d,b'] by RELAT_1:62;
A21: max+(f||['d,b']) = max+(f|['d,b']) by A19,Th59
      .= (max+f)||['d,b'] by MESFUNC6:66;
A22: f||['d,b'] is Function of ['d,b'],REAL by A20,FUNCT_2:67;
     f||['d,b'] is integrable by A15,A2,INTEGR10:def 6,INTEGRA5:def 1;
     hence max+f is_integrable_on ['d,b']
       by A21,A17,A22,INTEGRA4:20,INTEGRA5:def 1;
     f|['d,b'] is bounded_above by A16,SEQ_2:def 8; then
     (max+f)|['d,b'] is bounded_above & (max+f)|['d,b'] is bounded_below
       by INTEGRA4:14,15;
     hence (max+f)|['d,b'] is bounded by SEQ_2:def 8;
    end;

    ex Intf be PartFunc of REAL,REAL st
     dom Intf = left_closed_halfline b &
     (for x be Real st x in dom Intf holds Intf.x = integral(max+f,x,b)) &
     Intf is convergent_in-infty
    proof
     reconsider A = ].-infty,b.] as non empty Subset of REAL
       by A4,XXREAL_0:12,XXREAL_1:32;
     deffunc F(Element of A) = In(integral(max+f,$1,b),REAL);
     consider Intf be Function of A, REAL such that
A23:  for x being Element of A holds Intf.x = F(x) from FUNCT_2:sch 4;
A24: dom Intf = A by FUNCT_2:def 1; then
     reconsider Intf as PartFunc of REAL, REAL by RELSET_1:5;
     take Intf;
A25: for x be Real st x in dom Intf holds Intf.x = integral(max+f,x,b)
     proof
      let x be Real;
      assume x in dom Intf; then
      x is Element of A by FUNCT_2:def 1; then
      Intf.x = In(integral(max+f,x,b),REAL) by A23;
      hence Intf.x = integral(max+f,x,b);
     end;

A26: for r be Real ex g be Real st g<r & g in dom Intf
       by A5,A6,A8,A24,LIMFUNC1:45;

     for g1 be Real st 0 < g1
      ex r be Real st for r1 be Real st r1 < r & r1 in dom Intf
        holds |. Intf.r1- (G+AG)/2.| < g1
     proof
      let g1 be Real;
      assume
A27:    0 < g1; then
      consider R1 be Real such that
A28:   for r1 be Real st r1<R1 & r1 in dom I holds |.I.r1-G.|<g1
        by A8,A9,LIMFUNC1:78;
      consider R2 be Real such that
A29:   for r1 be Real st r1<R2 & r1 in dom AI holds |.AI.r1-AG.|<g1
        by A12,A13,A27,LIMFUNC1:78;

      set RR1 = min(b,R1);
      set RR2 = min(b,R2);
      take R = min(RR1,RR2);
      hereby let r1 be Real;
       assume
A30:    r1 < R & r1 in dom Intf;

A31:    r1 in REAL by XREAL_0:def 1;

       b >= RR1 & R1 >= RR1 & R2 >= RR2 & RR1 >= R & RR2 >= R
         by XXREAL_0:17; then
       b >= R & R1 >= R & R2 >= R by XXREAL_0:2; then
A32:   b > r1 & R1 > r1 & R2 > r1 by A30,XXREAL_0:2;
       [.r1,b.] c= ].-infty,b.] by A31,XXREAL_0:12,XXREAL_1:39; then
A33:   [.r1,b.] c= dom f by A1,A5;
       f is_integrable_on ['r1,b'] & f|['r1,b'] is bounded
         by A32,A2,INTEGR10:def 6; then
       2*integral(max+f,r1,b) = integral(f,r1,b) + integral(abs f,r1,b)
         by A32,A33,Th62; then
       2*Intf.r1 = integral(f,r1,b) + integral(abs f,r1,b) by A25,A30; then
       2*Intf.r1 = I.r1 + integral(abs f,r1,b) by A5,A30,A24,A6,A7; then
       2*Intf.r1 = I.r1 + AI.r1 by A5,A30,A24,A10,A11; then
       Intf.r1 - (G+AG)/2 = ( (I.r1 - G) + (AI.r1 - AG) ) /2; then
A34:    |. Intf.r1 - (G+AG)/2 .|
         = |.(I.r1-G) + (AI.r1-AG).|/|.2.| by COMPLEX1:67
        .= |.(I.r1-G) + (AI.r1-AG).| / 2 by ABSVALUE:def 1;

A35:   |.(I.r1-G) + (AI.r1-AG).|
        <= |. I.r1-G .| + |. AI.r1-AG .| by COMPLEX1:56;

       |. I.r1 - G .| < g1 & |. AI.r1-AG .| < g1
         by A5,A6,A10,A24,A28,A29,A32,A30; then
       |. I.r1-G .| + |. AI.r1-AG .| < g1 + g1 by XREAL_1:8; then
       |.(I.r1-G) + (AI.r1-AG).| < 2*g1 by A35,XXREAL_0:2; then
       |. Intf.r1 - (G+AG)/2 .| < 2*g1/2 by A34,XREAL_1:74;
       hence |. Intf.r1- (G+AG)/2.| < g1;
      end;
     end;
     hence thesis by A5,A25,A26,LIMFUNC1:45,FUNCT_2:def 1;
    end;
    hence max+f is_-infty_ext_Riemann_integrable_on b by A14,INTEGR10:def 6;
end;
