reserve A for non empty closed_interval Subset of REAL;

theorem Lm22:
for a,b,c,d be Real, f be Function of REAL,REAL st
b > 0 & c > 0 & d > 0 & ['a-c,a+c'] c= A &
( for x be Real holds f.x = min(d, max(0, b - |. b*(x-a)/c .|)) )
holds
centroid (f,A) = a
proof
 let a,b,c,d be Real, f be Function of REAL,REAL;
 assume that
 A1: b > 0 & c > 0 and
 A2: d > 0 and
 A3:  ['a-c,a+c'] c= A  and
 A4: for x be Real holds f.x = min(d, max(0, b - |. b*(x-a)/c .|));
 a < a+c & a-c < a by XREAL_1:44, XREAL_1:29,A1; then
 a-c < a+c by XXREAL_0:2;
 then
 lower_bound ['a-c,a+c'] = a-c & upper_bound ['a-c,a+c'] = a+c
 by FUZZY_6:7; then
 B1: lower_bound ['a-c,a+c'] <> upper_bound ['a-c,a+c'] by A1;
 B2: f is_integrable_on A & f | A is bounded by A1,A4,Lm22a;
 B3: (for x be Real st x in (A \ ['a-c,a+c']) holds f.x = 0)
   by Lm22B3,A1,A2,A4;
 f.(lower_bound ['a-c,a+c']) = 0 & f.(upper_bound ['a-c,a+c']) = 0
    by A1,A2,A4,Lm22b; then
 C1: centroid (f,A) = centroid (f,['a-c,a+c'])
    by A3,B1,B2,B3,FUZZY_7:24;
 per cases;
  suppose d < b;
   hence a = centroid (f,A) by Lm221,A1,A2,A4,C1;
  end;
  suppose K2: d >= b;
   for x be Real holds f.x = max(0,b-|. b*(x-a)/c .|)
   proof
    let x be Real;
    |. b*(x-a)/c .| >= 0 by COMPLEX1:46; then
    - |. b*(x-a)/c .|+b <= 0+b by XREAL_1:6; then
    max(0,b - |. b*(x-a)/c .|) <= b by XXREAL_0:28,A1; then
    min(d, max(0, b - |. b*(x-a)/c .|)) = max(0,b - |. b*(x-a)/c .|)
    by XXREAL_0:def 9,XXREAL_0:2,K2;
    hence thesis by A4;
   end;
   hence thesis by FUZZY_7:34,A1,A3;
  end;
end;
