reserve a, b, p, q for Real;

theorem Th4:
  1 < p & 1/p + 1/q = 1 & 0 < a & 0 < b implies a * b <= a #R p / p
  + b #R q / q & (a * b = a #R p / p + b #R q / q iff a #R p= b #R q)
proof
  assume that
A1: 1 < p and
A2: 1/p + 1/q = 1 and
A3: 0 < a and
A4: 0 < b;
A5: 0 < b #R q by A4,PREPOWER:81;
  reconsider pp=1/p as Real;
  1-pp <> 0 by A1,XREAL_1:189;
  then
A6: (q")" <> 0 by A2;
  then ((1*q+1*p)/(p*q))*(p*q) =1*(p*q) by A1,A2,XCMPLX_1:116;
  then
A7: q+p=p*q by A1,A6,XCMPLX_1:6,87;
  then
A8: (q-1)*p =q;
A9: 0 < b #R (q-1) by A4,PREPOWER:81;
A10: now
    assume
A11: a #R p= b #R q;
    then
A12: a #R p = (b #R (q-1) ) #R p by A4,A8,PREPOWER:91;
    a=a #R 1 by A3,PREPOWER:72
      .=a #R (p *(1/p) ) by A1,XCMPLX_1:106
      .= (a #R p ) #R (1/p) by A3,PREPOWER:91
      .= (b #R (q-1) ) #R (p *(1/p)) by A4,A12,PREPOWER:81,91
      .=(b #R (q-1) ) #R 1 by A1,XCMPLX_1:106
      .= b #R (q-1) by A4,PREPOWER:72,81;
    then a*1 = b #R (q-1);
    then a *( b #R ( (1-q)+ (q-1)) ) = b #R (q-1) by A4,PREPOWER:71;
    then a *(( b #R (1-q))*( b #R (q-1))) =1*( b #R (q-1)) by A4,PREPOWER:75;
    then
A13: a *( b #R (1-q))*( b #R (q-1)) =1*( b #R (q-1));
    thus a #R p / p + b #R q / q =b #R q *(1/ p) + b #R q / q by A11,
XCMPLX_1:99
      .=b #R q *(1/ p) + b #R q *(1/q) by XCMPLX_1:99
      .=b #R q * (1/p + 1/q)
      .=b #R q *(a*(b #R (1-q))) by A2,A9,A13,XCMPLX_1:5
      .=a* ( (b #R (1-q)) *(b #R q))
      .=a*(b #R ((1-q) + q)) by A4,PREPOWER:75
      .=a* b by A4,PREPOWER:72;
  end;
A14: 0 < b #R (1-q) by A4,PREPOWER:81;
  then
A15: 0*(b #R (1-q)) < a * (b #R (1-q)) by A3,XREAL_1:68;
  ex h be PartFunc of REAL,REAL st dom(h)= right_open_halfline(0) & for x
be Real st x > 0 holds h.x=x #R p / p & h is_differentiable_in x & diff(h,x)=x
  #R (p-1)
  proof
    set h=(1/p)(#)( #R p);
    take h;
    dom( #R p) =right_open_halfline(0) by TAYLOR_1:def 4;
    hence
A16: dom(h)= right_open_halfline(0) by VALUED_1:def 5;
    now
      let x be Real such that
A17:  x > 0;
      x in {g where g is Real: 0<g} by A17;
      then
A18:  x in right_open_halfline(0) by XXREAL_1:230;
      hence h.x = (1/p) * ( #R p).x by A16,VALUED_1:def 5
        .=(1/p) *(x #R p) by A18,TAYLOR_1:def 4
        .=(x #R p) /p by XCMPLX_1:99;
A19:  ( #R p) is_differentiable_in x by A17,TAYLOR_1:21;
      hence h is_differentiable_in x by FDIFF_1:15;
      thus diff(h,x) = (1/p)*diff(( #R p),x) by A19,FDIFF_1:15
        .= (1/p)*(p*(x #R (p-1))) by A17,TAYLOR_1:21
        .= (1/p)*p*(x #R (p-1))
        .= 1*x #R (p-1) by A1,XCMPLX_1:106
        .=x #R (p-1);
    end;
    hence thesis;
  end;
  then consider h be PartFunc of REAL,REAL such that
A20: dom(h)= right_open_halfline(0) and
A21: for x be Real st x > 0 holds h.x=x #R p / p & h
  is_differentiable_in x & diff(h,x)=x #R (p-1);
  ex g be PartFunc of REAL,REAL st dom(g)=REAL &
   for x be Element of REAL holds g.x=
  1 / q - x & g is_differentiable_in x & diff(g,x)=-1
  proof
    deffunc U(Real) = In(1/q - $1,REAL);
    defpred X[set] means $1 in REAL;
    consider g being PartFunc of REAL,REAL such that
A22: for d be Element of REAL holds d in dom g iff X[d] and
A23: for d be Element of REAL st d in dom g holds g/.d = U(d) from
    PARTFUN2:sch 2;
    take g;
    for x be object st x in REAL holds x in dom g by A22;
    then
A24: dom(g) c= REAL & REAL c=dom(g) by RELAT_1:def 18;
    then
A25: dom(g)=[#]REAL by XBOOLE_0:def 10;
A26: for d be Element of REAL holds g.d = 1 / q-d
    proof
      let d be Element of REAL;
      g/.d = U(d) by A23,A25;
      hence thesis by A25,PARTFUN1:def 6;
    end;
A27: for d be Real st d in REAL holds g.d = (-1)*d + 1 / q
    proof
      let d be Real such that
A28:    d in REAL;
      thus g.d=1 / q-d by A26,A28
        .= (-1)*d + 1 / q;
    end;
    then
A29: g is_differentiable_on dom(g) by A25,FDIFF_1:23;
    for x be Element of REAL holds g is_differentiable_in x & diff(g,x)=-1
    proof
      let d be Element of REAL;
      thus g is_differentiable_in d by A25,A29,FDIFF_1:9;
      thus diff(g,d)=(g`|dom(g)).d by A25,A29,FDIFF_1:def 7
        .= -1 by A25,A27,FDIFF_1:23;
    end;
    hence thesis by A24,A26,XBOOLE_0:def 10;
  end;
  then consider g be PartFunc of REAL,REAL such that
A30: dom(g)=REAL and
A31: for x be Element of REAL holds g.x=1 / q - x and
A32: for x be Element of REAL holds g is_differentiable_in x & diff(g,x)=-1;
  set f=h+g;
A33: dom f= right_open_halfline(0) /\ REAL by A30,A20,VALUED_1:def 1
    .= right_open_halfline(0) by XBOOLE_1:28;
A34: for x be Real st x in right_open_halfline(0) holds f.x=x #R p / p + 1 /
  q - x & f is_differentiable_in x & diff(f,x)=x #R (p-1) -1
  proof
    let x be Real such that
A35: x in right_open_halfline(0);
    reconsider xx=x as Element of REAL by XREAL_0:def 1;
    x in {y where y is Real: 0< y} by A35,XXREAL_1:230;
    then
A36: ex y be Real st x=y & 0 < y;
    then
A37: diff(h,x)=x #R (p-1) by A21;
    thus f.x=h.x + g.x by A33,A35,VALUED_1:def 1
      .=x #R p / p + g.xx by A21,A36
      .=x #R p / p +(1 / q - x) by A31
      .=x #R p / p +1 / q - x;
A38: g is_differentiable_in xx by A32;
A39: h is_differentiable_in x by A21,A36;
    hence f is_differentiable_in x by A38,FDIFF_1:13;
A40: diff(g,xx)=-1 by A32;
    thus diff(f,x)=diff(h,x)+diff(g,x) by A38,A39,FDIFF_1:13
      .=x #R (p-1) - 1 by A40,A37;
  end;
A41: for x be Real st 0 < x & x <> 1 holds x < x #R p / p + 1 / q
  proof
    1 in {y where y is Real: 0< y};
    then 1 in right_open_halfline(0) by XXREAL_1:230;
    then
A42: f.1= 1 #R p / p + 1 / q - 1 by A34
      .=1/p + 1/q -1 by PREPOWER:73
      .=0 by A2;
    for x be Real st x in right_open_halfline(0) holds f
    is_differentiable_in x by A34;
    then
A43: f is_differentiable_on right_open_halfline(0) by A33,FDIFF_1:9;
    let x be Real such that
A44: 0 < x and
A45: x <> 1;
    x in {y where y is Real: 0< y} by A44;
    then
A46: x in right_open_halfline(0) by XXREAL_1:230;
    now
      per cases by A45,XXREAL_0:1;
      case
        x<1;
        then
A47:    1-1 < 1-x by XREAL_1:15;
        set t=1-x;
A48:    1-1 < p-1 by A1,XREAL_1:14;
        now
          let z be object;
          assume z in [.x,x+t.];
          then z in {r where r is Real: x<=r & r<=x+t }
                  by RCOMP_1:def 1;
          then ex r be Real st r=z & x<=r & r<=x+t;
          then z in {y where y is Real: 0< y} by A44;
          hence z in right_open_halfline(0) by XXREAL_1:230;
        end;
        then
A49:    [.x,x+t.] c= right_open_halfline(0);
        f|right_open_halfline(0) is continuous by A43,FDIFF_1:25;
        then
A50:    f|[.x,x+t.] is continuous by A49,FCONT_1:16;
        ].x,x+t.[ c= [.x,x+t.] by XXREAL_1:25;
        then f is_differentiable_on ].x,x+t.[ by A43,A49,FDIFF_1:26,XBOOLE_1:1;
        then consider s be Real such that
A51:    0<s and
A52:    s<1 and
A53:    f.(x+t) = f.x + t*diff(f,x+s*t) by A33,A47,A49,A50,ROLLE:4;
        s*t < 1*t by A47,A52,XREAL_1:68;
        then x+s*t < x+t by XREAL_1:8;
        then (x+s*t) to_power (p-1) < (x+s*t) to_power 0 by A44,A47,A51,A48,
POWER:40;
        then (x+s*t) #R (p-1) < (x+s*t) to_power 0 by A44,A47,A51,POWER:def 2;
        then (x+s*t) #R (p-1) < (x+s*t) #R 0 by A44,A47,A51,POWER:def 2;
        then (x+s*t) #R (p-1) < 1 by A44,A47,A51,PREPOWER:71;
        then
A54:    (x+s*t) #R (p-1) -1 < 1-1 by XREAL_1:14;
        x+s*t in {y where y is Real: 0< y} by A44,A47,A51;
        then x+s*t in right_open_halfline(0) by XXREAL_1:230;
        then diff(f,x+s*t) =(x+s*t) #R (p-1)-1 by A34;
        then t*diff(f,x+s*t) < t*0 by A47,A54,XREAL_1:68;
        then f.x + t*diff(f,x+s*t) < f.x +0 by XREAL_1:8;
        then 0 < x #R p / p + 1 / q-x by A34,A46,A42,A53;
        then 0+x < x #R p / p + 1 / q-x+x by XREAL_1:8;
        hence thesis;
      end;
      case
        x > 1;
        then
A55:    1-1 < x-1 by XREAL_1:14;
        set t=x-1;
        now
          let z be object;
          assume z in [.1,1+t.];
          then z in {r where r is Real: 1<=r & r<=1+t }
              by RCOMP_1:def 1;
          then ex r be Real st r=z & 1<=r & r<=1+t;
          then z in {y where y is Real: 0< y};
          hence z in right_open_halfline(0) by XXREAL_1:230;
        end;
        then
A56:    [.1,1+t.] c= right_open_halfline(0);
A57:    1-1 < p-1 by A1,XREAL_1:14;
        f|right_open_halfline(0) is continuous by A43,FDIFF_1:25;
        then
A58:    f|[.1,1+t.] is continuous by A56,FCONT_1:16;
        ].1,1+t.[ c= [.1,1+t.] by XXREAL_1:25;
        then f is_differentiable_on ].1,1+t.[ by A43,A56,FDIFF_1:26,XBOOLE_1:1;
        then consider s be Real such that
A59:    0<s and
        s<1 and
A60:    f.(1+t) = f.1 + t*diff(f,1+s*t) by A33,A55,A56,A58,ROLLE:4;
        0*t < s*t by A55,A59,XREAL_1:68;
        then 1+ 0 < 1+ s*t by XREAL_1:8;
        then 1 < (1+s*t) #R (p-1) by A57,PREPOWER:86;
        then
A61:    1-1 < (1+s*t) #R (p-1) -1 by XREAL_1:14;
        1+s*t in {y where y is Real: 0< y} by A55,A59;
        then 1+s*t in right_open_halfline(0) by XXREAL_1:230;
        then diff(f,1+s*t) =(1+s*t) #R (p-1)-1 by A34;
        then t*0 < t*diff(f,1+s*t) by A55,A61,XREAL_1:68;
        then 0 < x #R p / p + 1 / q-x by A34,A46,A42,A60;
        then 0+x < x #R p / p + 1 / q-x+x by XREAL_1:8;
        hence thesis;
      end;
    end;
    hence thesis;
  end;
A62: (1-q)*p + q=0 by A7;
A63: now
    assume a * b = a #R p / p + b #R q / q;
    then a*b = a #R p /p+ (1 / q)*(b #R q) by XCMPLX_1:99;
    then a*b = a #R p * (1/p)+ (1 / q)*(b #R q) by XCMPLX_1:99;
    then a*b = a #R p * (b #R 0/p)+ (1 / q)*(b #R q) by A4,PREPOWER:71;
    then a*b = a #R p * ((b #R ((1-q)*p) )*(b #R q)/p)+ (1 / q)*(b #R q) by A4
,A62,PREPOWER:75;
    then a*b = a #R p * ((b #R ((1-q)*p) )/ p*(b #R q))+ (1 / q)*(b #R q) by
XCMPLX_1:74;
    then a*b = (a #R p * ((b #R ((1-q)*p) )/ p )*(b #R q))+ (1 / q)*(b #R q);
    then a*b = (a #R p * (b #R ((1-q)*p) )/ p )*(b #R q)+ (1 / q)*(b #R q) by
XCMPLX_1:74;
    then a*b = (a #R p * (b #R ((1-q)*p) )/ p + 1 / q)*(b #R q);
    then
a*b = ((a #R p * (b #R (1-q)) #R p )/ p + 1 / q)*(b #R q) by A4,PREPOWER:91;
    then
    a*b = ((a * (b #R (1-q))) #R p / p + 1 / q)*(b #R q) by A3,A14,PREPOWER:78;
    then a*(b #R ((1-q) + q)) = ((a * (b #R (1-q))) #R p / p + 1 / q)*(b #R q
    ) by A4,PREPOWER:72;
    then a*( (b #R (1-q)) *(b #R q)) = ((a * (b #R (1-q))) #R p / p + 1 / q)*
    (b #R q) by A4,PREPOWER:75;
    then a * (b #R (1-q)) *(b #R q) = ((a * (b #R (1-q))) #R p / p + 1 / q)*(
    b #R q);
    then
A64: a * (b #R (1-q)) = (a * (b #R (1-q))) #R p / p + 1 / q by A5,XCMPLX_1:5;
    a *(( b #R (1-q))*( b #R (q-1))) = a *( b #R (1-q))*( b #R (q-1))
      .= 1*( b #R (q-1)) by A41,A15,A64;
    then a *( b #R ( (1-q)+ (q-1)) ) = b #R (q-1) by A4,PREPOWER:75;
    then a*1 = b #R (q-1) by A4,PREPOWER:71;
    hence a #R p = b #R q by A4,A8,PREPOWER:91;
  end;
  a * (b #R (1-q)) <= (a * (b #R (1-q))) #R p / p + 1 / q
  proof
    now
      per cases;
      case
        a * (b #R (1-q)) =1;
        hence a * (b #R (1-q)) =(a * (b #R (1-q))) #R p / p + 1 / q by A2,
PREPOWER:73;
      end;
      case
        a * (b #R (1-q)) <>1;
        hence thesis by A41,A15;
      end;
    end;
    hence thesis;
  end;
  then a * (b #R (1-q)) *(b #R q) <= ((a * (b #R (1-q))) #R p / p + 1 / q)*(b
  #R q) by A5,XREAL_1:64;
  then a*( (b #R (1-q)) *(b #R q)) <= ((a * (b #R (1-q))) #R p / p + 1 / q)*(
  b #R q);
  then a*(b #R ((1-q) + q)) <= ((a * (b #R (1-q))) #R p / p + 1 / q)*(b #R q)
  by A4,PREPOWER:75;
  then a*b <= ((a * (b #R (1-q))) #R p / p + 1 / q)*(b #R q) by A4,PREPOWER:72;
  then a*b <= ((a #R p * (b #R (1-q)) #R p )/ p + 1 / q)*(b #R q) by A3,A14,
PREPOWER:78;
  then a*b <= (a #R p * (b #R ((1-q)*p) )/ p + 1 / q)*(b #R q) by A4,
PREPOWER:91;
  then a*b <= (a #R p * (b #R ((1-q)*p) )/ p )*(b #R q)+ (1 / q)*(b #R q);
  then a*b <= (a #R p * ((b #R ((1-q)*p) )/ p )*(b #R q))+ (1 / q)*(b #R q)
  by XCMPLX_1:74;
  then a*b <= a #R p * ((b #R ((1-q)*p) )/ p*(b #R q))+ (1 / q)*(b #R q);
  then a*b <= a #R p * ((b #R ((1-q)*p) )*(b #R q)/p)+ (1 / q)*(b #R q) by
XCMPLX_1:74;
  then a*b <= a #R p * (b #R ((1-q)*p + q)/p)+ (1 / q)*(b #R q) by A4,
PREPOWER:75;
  then a*b <= a #R p * (1/p)+ (1 / q)*(b #R q) by A4,A7,PREPOWER:71;
  then a*b <= a #R p /p+ (1 / q)*(b #R q) by XCMPLX_1:99;
  hence thesis by A63,A10,XCMPLX_1:99;
end;
