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 f being PartFunc of REAL,REAL st f is total holds (for n being
  Element of NAT, P,E,F being Element of n-tuples_on REAL st Sum P=1 & (for i
being Element of NAT st i in dom P holds P.i >=0 & F.i=f.(E.i)) holds f.Sum(mlt
  (P,E))<=Sum(mlt(P,F))) implies f is_convex_on REAL
proof
  let f be PartFunc of REAL,REAL;
  assume f is total;
  then
A1: REAL c= dom f by PARTFUN1:def 2;
  (for n being Element of NAT, P,E,F being Element of n-tuples_on REAL st
Sum P=1 & (for i being Element of NAT st i in dom P holds P.i >=0 & F.i=f.(E.i)
  ) holds f.Sum(mlt(P,E))<=Sum(mlt(P,F))) implies f is_convex_on REAL
  proof
    assume
A2: for n being Element of NAT, P,E,F being Element of n-tuples_on
REAL st Sum P=1 & (for i being Element of NAT st i in dom P holds P.i >=0 & F.i
    =f.(E.i)) holds f.Sum(mlt(P,E))<=Sum(mlt(P,F));
    for p being Real st 0<=p & p<=1
   for r,s being Real st r in REAL
& s in REAL & p*r + (1-p)*s in REAL holds f.(p*r + (1-p)*s) <= p*f.r + (1-p)*f.
    s
    proof
      let p be Real such that
A3:  0<=p and
A4:  p<=1;
      let r,s be Real such that
   r in REAL and
   s in REAL and
    p*r + (1-p)*s in REAL;
      reconsider rr=r,ss=s,pp=p, mp=1-p as Element of REAL by XREAL_0:def 1;
      f.rr in REAL & f.ss in REAL by XREAL_0:def 1;
      then reconsider P=<*pp,mp*>, E=<*rr,ss*>, F=<*f.rr,f.ss*>
           as Element of 2-tuples_on REAL
                   by FINSEQ_2:101;
A5:  for i being Element of NAT st i in dom P holds P.i >=0 & F.i=f.(E.i )
      proof
A6:    dom P = Seg len P by FINSEQ_1:def 3
          .= Seg 2 by CARD_1:def 7;
        let i be Element of NAT such that
A7:    i in dom P;
        now
          per cases by A7,A6,FINSEQ_1:2,TARSKI:def 2;
          suppose
A8:        i=1;
            thus thesis by A3,A8;
          end;
          suppose
A9:        i=2;
            thus thesis by A4,A9,XREAL_1:48;
          end;
        end;
        hence thesis;
      end;
      Sum P=p+(1-p) by RVSUM_1:77
        .= 1;
      then
A10:  f.Sum(mlt(P,E))<=Sum(mlt(P,F)) by A2,A5;
      len P = 2 by FINSEQ_1:44
        .= len E by FINSEQ_1:44;
      then len (multreal.:(P,E)) = len P by FINSEQ_2:72;
      then
A12:  len mlt(P,E) = 2 by FINSEQ_1:44;
A13:  mlt(P,E).1 = P.1*E.1 & mlt(P,E).2 = P.2*E.2 by RVSUM_1:60;
      mlt(P,E)=<*p*r,(1-p)*s*> by A12,A13,FINSEQ_1:44;
      then
A14:  Sum(mlt(P,E))=p*r+(1-p)*s by RVSUM_1:77;
A15:  mlt(P,F).1 = P.1*F.1 & mlt(P,F).2 = P.2*F.2 by RVSUM_1:60;
      len P = 2 by FINSEQ_1:44
        .= len F by FINSEQ_1:44;
      then len (multreal.:(P,F)) = len P by FINSEQ_2:72;
      then
A16:  len mlt(P,F) = 2 by FINSEQ_1:44;
      mlt(P,F)=<*p*f.r,(1-p)*f.s*> by A16,A15,FINSEQ_1:44;
      hence thesis by A10,A14,RVSUM_1:77;
    end;
    hence thesis by A1,RFUNCT_3:def 12;
  end;
  hence thesis;
end;
