
theorem Th4:
  for X being non empty RLSStruct, f being Function of the carrier
of X,ExtREAL st (for x being VECTOR of X holds f.x <> -infty) holds f is convex
iff for x1, x2 being VECTOR of X,
   p being Real st 0<p & p<1 holds f.(p*x1+(1-p)
  *x2) <= (p)*f.x1+(1-p)*f.x2
proof
  let X be non empty RLSStruct, f be Function of the carrier of X,ExtREAL;
  assume
A1: for x being VECTOR of X holds f.x <> -infty;
  thus f is convex implies for x1, x2 being VECTOR of X,
   p being Real st 0<p &
  p<1 holds f.(p*x1+(1-p)*x2) <= (p)*f.x1+(1-p)*f.x2
  proof
    assume f is convex;
    then
A2: epigraph f is convex;
    let x1, x2 be VECTOR of X, p be Real;
    assume that
A3: 0<p and
A4: p<1;
    set p2 = (1-p);
    set p1 = (p);
A5: 1-p > 0 by A4,XREAL_1:50;
    per cases by A1,XXREAL_0:14;
    suppose
A6:   f.x1 in REAL & f.x2 in REAL;
      then reconsider w2=f.x2 as Element of REAL;
      reconsider w1=f.x1 as Element of REAL by A6;
      reconsider u1=[x1,w1] as VECTOR of Prod_of_RLS(X,RLS_Real);
      reconsider u2=[x2,w2] as VECTOR of Prod_of_RLS(X,RLS_Real);
A7:   [x2,w2] in epigraph f;
A8:   p*u1 = [p*x1,p*w1] by Lm1;
A9:   (1-p)*u2 = [(1-p)*x2,(1-p)*w2] by Lm1;
      [x1,w1] in epigraph f;
      then p*u1 + (1-p)*u2 in epigraph f by A2,A3,A4,A7,CONVEX1:def 2;
      then [p*x1+(1-p)*x2,p*w1+(1-p)*w2] in epigraph f by A8,A9,Lm2;
      then consider x0 being Element of X, y0 being Element of REAL such that
A10:  [p*x1+(1-p)*x2,p*w1+(1-p)*w2] = [x0,y0] and
A11:  f.x0 <= (y0);
A12:  y0 = p*w1+(1-p)*w2 by A10,XTUPLE_0:1;
      x0 = p*x1+(1-p)*x2 by A10,XTUPLE_0:1;
      hence thesis by A11,A12,Lm12;
    end;
    suppose
A13:  f.x1 = +infty & f.x2 in REAL;
A14:  p2*f.x2 in REAL
      by A13,XREAL_0:def 1;
      p1*f.x1 = +infty by A3,A13,XXREAL_3:def 5;
      then p1*f.x1+p2*f.x2 = +infty by A14,XXREAL_3:def 2;
      hence thesis by XXREAL_0:4;
    end;
    suppose
A15:  f.x1 in REAL & f.x2 = +infty;
A16:  p1*f.x1 in REAL
      by A15,XREAL_0:def 1;
      p2*f.x2 = +infty by A5,A15,XXREAL_3:def 5;
      then p1*f.x1+p2*f.x2 = +infty by A16,XXREAL_3:def 2;
      hence thesis by XXREAL_0:4;
    end;
    suppose
A17:  f.x1 = +infty & f.x2 = +infty;
      then p2*f.x2 = +infty by A5,XXREAL_3:def 5;
      then p1*f.x1+p2*f.x2 = +infty by A3,A17,XXREAL_3:def 2;
      hence thesis by XXREAL_0:4;
    end;
  end;
  assume
A18: for x1, x2 being VECTOR of X, p being Real
  st 0<p & p<1 holds f.(p*
  x1+(1-p)*x2) <= (p)*f.x1+(1-p)*f.x2;
  for u1,u2 being VECTOR of Prod_of_RLS(X,RLS_Real),
      p being Real st 0 <
p & p < 1 & u1 in epigraph f & u2 in epigraph f holds p*u1+(1-p)*u2 in epigraph
  f
  proof
    let u1,u2 be VECTOR of Prod_of_RLS(X,RLS_Real), p being Real;
    assume that
A19: 0 < p and
A20: p < 1 and
A21: u1 in epigraph f and
A22: u2 in epigraph f;
    reconsider pp=p as Real;
    thus p*u1 + (1-p)*u2 in epigraph f
    proof
      consider x2 being Element of X, y2 being Element of REAL such that
A23:  u2=[x2,y2] and
A24:  f.x2 <= (y2) by A22;
A25:  (1-p)*u2 = [(1-p)*x2,(1-p)*y2] by A23,Lm1;
      f.x2 <> +infty by A24,XXREAL_0:9;
      then reconsider w2 = f.x2 as Element of REAL by A1,XXREAL_0:14;
      consider x1 being Element of X, y1 being Element of REAL such that
A26:  u1=[x1,y1] and
A27:  f.x1 <= (y1) by A21;
      f.x1 <> +infty by A27,XXREAL_0:9;
      then reconsider w1 = f.x1 as Element of REAL by A1,XXREAL_0:14;
      1-p>0 by A20,XREAL_1:50;
      then (1-p)*w2<=(1-p)*y2 by A24,XREAL_1:64;
      then
A28:  p*w1+(1-p)*w2<=p*w1+(1-p)*y2 by XREAL_1:6;
      p*w1<=p*y1 by A19,A27,XREAL_1:64;
      then p*w1+(1-p)*y2<=p*y1+(1-p)*y2 by XREAL_1:6;
      then
A29:  p*w1+(1-p)*w2<=p*y1+(1-p)*y2 by A28,XXREAL_0:2;
A30:    p*w1+(1-p)*w2 in REAL by XREAL_0:def 1;
A31:  (p*w1+(1-p)*w2) = (p)*f.x1+(1-p)*f.x2 by Lm12;
      then f.(pp*x1+(1-pp)*x2) <> +infty by A18,A19,A20,XXREAL_0:9,A30;
      then reconsider w = f.(p*x1+(1-p)*x2) as Element of REAL
by A1,XXREAL_0:14;
A32:   p*y1+(1-p)*y2 in REAL by XREAL_0:def 1;
      w<=pp*w1+(1-pp)*w2 by A18,A19,A20,A31;
      then f.(pp*x1+(1-pp)*x2) <= (p*y1+(1-p)*y2) by A29,XXREAL_0:2;
      then
A33:  [p*x1+(1-p)*x2,p*y1+(1-p)*y2] in {[x,y] where x is Element of X, y
      is Element of REAL: f.x <= (y)} by A32;
      p*u1 = [p*x1,p*y1] by A26,Lm1;
      then p*u1 + (1-p)*u2 = [p*x1+(1-p)*x2,p*y1+(1-p)*y2] by A25,Lm2;
      hence thesis by A33;
    end;
  end;
  then epigraph f is convex by CONVEX1:def 2;
  hence thesis;
end;
