reserve a,b,p,r,r1,r2,s,s1,s2,x0,x for Real;
reserve f,g for PartFunc of REAL,REAL;
reserve X,Y for set;

theorem
  for X being set, f being PartFunc of REAL,REAL holds f is_convex_on X
  iff X c= dom f &
  for a,b,c being Real st a in X & b in X & c in X & a<b & b<c
  holds f.b <=((c-b)/(c-a))*f.a + ((b-a)/(c-a))*f.c
proof
  let X be set, f be PartFunc of REAL,REAL;
A1: (X c= dom f &
  for a,b,c being Real st a in X & b in X & c in X & a<b &
b<c holds f.b <=((c-b)/(c-a))*f.a + ((b-a)/(c-a))*f.c) implies f is_convex_on X
  proof
    assume that
A2: X c= dom f and
A3: for a,b,c being Real st a in X & b in X & c in X & a<b & b<c
    holds f.b <=((c-b)/(c-a))*f.a + ((b-a)/(c-a))*f.c;
    for p being Real st 0<=p & p<=1 holds
     for r,s being Real st r in X &
    s in X & p*r + (1-p)*s in X holds f.(p*r + (1-p)*s) <= p*f.r + (1-p)*f.s
    proof
      let p be Real;
      assume
A4:   0<=p & p<=1;
      for r,s being Real
      st r in X & s in X & p*r + (1-p)*s in X holds f.
      (p*r + (1-p)*s) <= p*f.r + (1-p)*f.s
      proof
        let r,s be Real;
        assume
A5:     r in X & s in X & p*r + (1-p)*s in X;
        f.(p*r + (1-p)*s) <= p*f.r + (1-p)*f.s
        proof
          per cases by A4,XXREAL_0:1;
          suppose
            p=0;
            hence thesis;
          end;
          suppose
            p=1;
            hence thesis;
          end;
          suppose
A6:         0<p & p<1;
            then
A7:         0 < 1-p by XREAL_1:50;
            per cases by XXREAL_0:1;
            suppose
              r=s;
              hence thesis;
            end;
            suppose
A8:           r>s;
              set t = p*r + (1-p)*s;
A9:           r-s > 0 by A8,XREAL_1:50;
A10:          r - t = (1-p)*(r-s);
              then r - t > 0 by A7,A9,XREAL_1:129;
              then
A11:          t < r by XREAL_1:47;
A12:          t - s =p*(r-s);
              then
A13:          (t-s)/(r-s)=p by A9,XCMPLX_1:89;
              t - s > 0 by A6,A9,A12,XREAL_1:129;
              then
A14:          s < t by XREAL_1:47;
              (r-t)/(r-s)=(1-p) by A9,A10,XCMPLX_1:89;
              hence thesis by A3,A5,A14,A11,A13;
            end;
            suppose
A15:          r<s;
              set t = p*r + (1-p)*s;
A16:          s-r > 0 by A15,XREAL_1:50;
A17:          s - t = p*(s-r);
              then s - t > 0 by A6,A16,XREAL_1:129;
              then
A18:          t < s by XREAL_1:47;
A19:          t - r = (1-p)*(s-r);
              then
A20:          (t-r)/(s-r)=1-p by A16,XCMPLX_1:89;
              t - r > 0 by A7,A16,A19,XREAL_1:129;
              then
A21:          r < t by XREAL_1:47;
              (s-t)/(s-r)=p by A16,A17,XCMPLX_1:89;
              hence thesis by A3,A5,A21,A18,A20;
            end;
          end;
        end;
        hence thesis;
      end;
      hence thesis;
    end;
    hence thesis by A2,RFUNCT_3:def 12;
  end;
  f is_convex_on X implies X c= dom f &
  for a,b,c being Real st a in X & b
  in X & c in X & a<b & b<c holds f.b <=((c-b)/(c-a))*f.a + ((b-a)/(c-a))*f.c
  proof
    assume
A22: f is_convex_on X;
    for a,b,c being Real
     st a in X & b in X & c in X & a < b & b < c holds
    f.b <=((c-b)/(c-a))*f.a + ((b-a)/(c-a))*f.c
    proof
      let a,b,c be Real;
      assume that
A23:  a in X & b in X & c in X and
A24:  a < b & b < c;
      set p = (c-b)/(c-a);
A25:  c-b < c-a & 0 < c-b by A24,XREAL_1:10,50;
      then
A26:  (c-b)/(c-a) < 1 by XREAL_1:189;
A27:  p+(b-a)/(c-a) = ((c-b)+(b-a))/(c-a) by XCMPLX_1:62
        .= 1 by A25,XCMPLX_1:60;
      then p*a + (1-p)*c = (a*(c-b))/(c-a)+c*((b-a)/(c-a)) by XCMPLX_1:74
        .= (a*(c-b))/(c-a)+(c*(b-a))/(c-a) by XCMPLX_1:74
        .= ((c*a-b*a)+(b-a)*c)/(c-a) by XCMPLX_1:62
        .= b*(c-a)/(c-a);
      then p*a + (1-p)*c = b by A25,XCMPLX_1:89;
      hence thesis by A22,A23,A25,A26,A27,RFUNCT_3:def 12;
    end;
    hence thesis by A22,RFUNCT_3:def 12;
  end;
  hence thesis by A1;
end;
