reserve A for non empty closed_interval Subset of REAL;

theorem
for a,b,p,q,c,d,e being Real, f be Function of REAL,REAL st a <> p &
f | A = AffineMap (a,b) | [.lower_bound A,(q-b)/(a-p).]
     +* AffineMap (p,q) | [.(q-b)/(a-p),upper_bound A.]  & (q-b)/(a-p) in A
holds
centroid(f,A) =
(   1/3*a*(((q-b)/(a-p))^3 - (lower_bound A)^3)
  + 1/2*b*(((q-b)/(a-p))^2 - (lower_bound A)^2)
  + 1/3*p*((upper_bound A)^3 - ((q-b)/(a-p))^3)
  + 1/2*q*((upper_bound A)^2 - ((q-b)/(a-p))^2) ) /
( 1/2*a*(((q-b)/(a-p))^2 -(lower_bound A)^2) + b*((q-b)/(a-p) - lower_bound A)
+ 1/2*p*((upper_bound A)^2 -((q-b)/(a-p))^2) + q*(upper_bound A -(q-b)/(a-p)) )
proof
 let a,b,p,q,c,d,e being Real, f be Function of REAL,REAL;
 assume that
 A1: a <> p and
 A2: f | A = AffineMap (a,b) | [.lower_bound A,(q-b)/(a-p).]
     +* AffineMap (p,q) | [.(q-b)/(a-p),upper_bound A.] and
 A3: (q-b)/(a-p) in A;
 set F = ( AffineMap (a,b) |].-infty,(q-b)/(a-p).[ )
 +* ( AffineMap (p,q) |[.(q-b)/(a-p),+infty.[ );
 reconsider F as Function of REAL,REAL by Th19;
 A4: F | A = f | A by A2,Th17C,A3;
 B1: integral(f,A) = integral(F | A) by A4,INTEGRA5:def 2
 .= integral(F,A) by INTEGRA5:def 2
 .= integral(AffineMap (a,b),['lower_bound A,(q-b)/(a-p)'])
  + integral(AffineMap (p,q),['(q-b)/(a-p),upper_bound A']) by Th17,A1,A3;
 set c = lower_bound A;
 set d = (q-b)/(a-p);
 set e = upper_bound A;
 (q-b)/(a-p) in [.lower_bound A,upper_bound A.] by INTEGRA1:4,A3;
 then
 CD: c <= d & d <= e by XXREAL_1:1;
 centroid (f,A)
=(  integral((id REAL) (#) (AffineMap (a,b)),['lower_bound A,(q-b)/(a-p)'])
+  integral((id REAL) (#) (AffineMap (p,q)),['(q-b)/(a-p),upper_bound A']) ) /
(  integral(AffineMap (a,b),['lower_bound A,(q-b)/(a-p)'])
+  integral(AffineMap (p,q),['(q-b)/(a-p),upper_bound A']) )
   by B1,Th23A,A1,A2,A3
.=(  integral((id REAL) (#) (AffineMap (a,b)),c,d)
+  integral((id REAL) (#) (AffineMap (p,q)),['(q-b)/(a-p),upper_bound A']) ) /
  (integral(AffineMap (a,b),['lower_bound A,(q-b)/(a-p)'])
+ integral(AffineMap (p,q),['(q-b)/(a-p),upper_bound A']) )
   by INTEGRA5:def 4,CD
.= (integral((id REAL) (#) (AffineMap (a,b)),c,d)
+ integral((id REAL) (#) (AffineMap (p,q)),d,e) ) /
(integral(AffineMap (a,b),['lower_bound A,(q-b)/(a-p)'])
+ integral(AffineMap (p,q),['(q-b)/(a-p),upper_bound A']) )
   by INTEGRA5:def 4,CD
.=(integral((id REAL) (#) (AffineMap (a,b)),c,d)
+ integral((id REAL) (#) (AffineMap (p,q)),d,e) ) /
(integral(AffineMap (a,b),c,d)
+ integral(AffineMap (p,q),['(q-b)/(a-p),upper_bound A']) )
   by INTEGRA5:def 4,CD
.=(integral((id REAL) (#) (AffineMap (a,b)),c,d)
+ integral((id REAL) (#) (AffineMap (p,q)),d,e) ) /
(integral(AffineMap (a,b),c,d)+ integral(AffineMap (p,q),d,e) )
   by INTEGRA5:def 4,CD
.=(  (1/3*a*(d*d*d - c*c*c) + 1/2*b*(d*d - c*c))
+  integral((id REAL) (#) (AffineMap (p,q)),d,e) ) /
(integral(AffineMap (a,b),c,d)+ integral(AffineMap (p,q),d,e) )
   by Th23B,CD
.=((1/3*a*(d*d*d - c*c*c) + 1/2*b*(d*d - c*c))
+ (1/3*p*(e*e*e - d*d*d) + 1/2*q*(e*e - d*d)) ) /
(integral(AffineMap (a,b),c,d)+ integral(AffineMap (p,q),d,e) )
   by Th23B,CD
.=((1/3*a*(d*d*d - c*c*c) + 1/2*b*(d*d - c*c))
+ (1/3*p*(e*e*e - d*d*d) + 1/2*q*(e*e - d*d)) ) /
(1/2*a*(d*d - c*c) + b*(d - c) + integral(AffineMap (p,q),d,e) )
   by Th23D,CD
.=((1/3*a*(d*d*d - c*c*c) + 1/2*b*(d*d - c*c))
+ (1/3*p*(e ^2*e - d*d*d) + 1/2*q*(e*e - d*d)) ) /
(1/2*a*(d*d - c ^2) + b*(d - c) + (1/2*p*(e*e - d*d) + q*(e - d)) )
   by Th23D,CD
.=((1/3*a*(d^2*d - c^2*c) + 1/2*b*(d ^2 - c ^2))
+ (1/3*p*(e ^3 - d^2*d) + 1/2*q*(e ^2 - d ^2)) ) /
(1/2*a*(d ^2 - c ^2) + b*(d - c) + (1/2*p*(e ^2 - d ^2) + q*(e - d)) )
   by POLYEQ_3:def 3
.=((1/3*a*(d^2*d - c^2*c) + 1/2*b*(d ^2 - c ^2))
+ (1/3*p*(e ^3 - d^3) + 1/2*q*(e ^2 - d ^2)) ) /
  (1/2*a*(d ^2 - c ^2) + b*(d - c) + (1/2*p*(e ^2 - d ^2) + q*(e - d)) )
   by POLYEQ_3:def 3
.= ((1/3*a*(d^3 - c^2*c) + 1/2*b*(d ^2 - c ^2))
  + (1/3*p*(e ^3 - d^3) + 1/2*q*(e ^2 - d ^2)) ) /
  (1/2*a*(d ^2 - c ^2) + b*(d - c) + (1/2*p*(e ^2 - d ^2) + q*(e - d)) )
   by POLYEQ_3:def 3
.= ((1/3*a*(d^3 - c^3) + 1/2*b*(d ^2 - c ^2))
  + (1/3*p*(e^3 - d^3) + 1/2*q*(e ^2 - d ^2)) ) /
  (1/2*a*(d ^2 - c ^2) + b*(d - c) + (1/2*p*(e ^2 - d ^2) + q*(e - d)) )
   by POLYEQ_3:def 3;
 hence thesis;
end;
