reserve i,j,k,n,n1,n2,m for Nat;
reserve a,r,x,y for Real;
reserve A for non empty closed_interval Subset of REAL;
reserve C for non empty set;
reserve X for set;

theorem
  for f being Function of A,REAL st f|A is bounded & f is integrable
holds ex a st lower_bound rng f <= a & a <= upper_bound rng f & integral(f)=a*
  vol(A)
proof
  let f be Function of A,REAL;
  consider g being Function of A,REAL such that
A1: rng g = {lower_bound rng f} and
A2: g|A is bounded by Th5;
  consider h being Function of A,REAL such that
A3: rng h = {upper_bound rng f} and
A4: h|A is bounded by Th5;
A5: integral(g)=(lower_bound rng f)*vol(A) by A1,Th4;
  assume
A6: f|A is bounded;
A7: for x st x in dom f holds lower_bound rng f <= f.x & f.x <= upper_bound
  rng f
  proof
    let x;
    assume x in dom f;
    then
A8: f.x in rng f by FUNCT_1:def 3;
A9: rng f is bounded_below by A6,INTEGRA1:11;
    rng f is bounded_above by A6,INTEGRA1:13;
    hence thesis by A9,A8,SEQ_4:def 1,def 2;
  end;
A10: for x st x in A holds f.x <= h.x
  proof
    let x;
    assume
A11: x in A;
    dom h = A by FUNCT_2:def 1;
    then
A12: h.x in rng h by A11,FUNCT_1:def 3;
    dom f = A by FUNCT_2:def 1;
    then f.x <= upper_bound rng f by A7,A11;
    hence thesis by A3,A12,TARSKI:def 1;
  end;
A13: for x st x in A holds g.x <= f.x
  proof
    let x;
    assume
A14: x in A;
    dom g = A by FUNCT_2:def 1;
    then
A15: g.x in rng g by A14,FUNCT_1:def 3;
    dom f = A by FUNCT_2:def 1;
    then lower_bound rng f <= f.x by A7,A14;
    hence thesis by A1,A15,TARSKI:def 1;
  end;
  assume
A16: f is integrable;
A17: integral(h)=(upper_bound rng f)*vol(A) by A3,Th4;
A18: h is integrable by A3,Th4;
A19: g is integrable by A1,Th4;
  now
    per cases;
    suppose
A20:  vol(A)<>0;
      reconsider a=integral(f)/vol(A) as Real;
A21:  integral(f)=a*vol(A) by A20,XCMPLX_1:87;
A22:  vol(A) >= 0 by INTEGRA1:9;
      then
A23:  integral(f)/vol(A) <= (upper_bound rng f) by A6,A16,A4,A18,A17,A10,A20,
INTEGRA2:34,XREAL_1:79;
      (lower_bound rng f) <= integral(f)/vol(A) by A6,A16,A2,A19,A5,A13,A20,A22
,INTEGRA2:34,XREAL_1:77;
      hence thesis by A23,A21;
    end;
    suppose
A24:  vol(A)=0;
A25:  lower_bound rng f <= upper_bound rng f
      proof
        dom f = A by FUNCT_2:def 1;
        then consider x being Element of REAL such that
A26:    x in dom f by SUBSET_1:4;
A27:    f.x <= upper_bound rng f by A7,A26;
        lower_bound rng f <= f.x by A7,A26;
        hence thesis by A27,XXREAL_0:2;
      end;
      integral(f)=(lower_bound rng f)*vol(A) by A24,Th6;
      hence thesis by A25;
    end;
  end;
  hence thesis;
end;
