(* Consumer Indifference Threshold *)
FullSimplify[Solve[pI +(((x-λI))^2)t==pE+((((1-λE)-x))^2)t,{x}]]

FullSimplify[(-(((-1+λE))^2)+((λI)^2))/(-1+λE+λI)]

(* Duopoly profts and solutions to first-order conditions *) profitI=(pI-c)((-pE+pI+t (-(((-1+λE))^2)+((λI)^2)))/(2 t (-1+λE+λI)));
profitE=(pE-c-τ)(1-((-pE+pI+t (-(((-1+λE))^2)+((λI)^2)))/(2 t (-1+λE+λI))));
FullSimplify[Solve[D[profitI,pI]==0,pI]]
FullSimplify[Solve[D[profitE,pE]==0,pE]]

(* Second-order conditions *)
D[profitI,{pI,2}]
D[profitE,{pE,2}]

(* Bertrand equilibrium *)
FullSimplify[Solve[pI==(1/2) (c+(1/2) (c+pI-t (1+λE-λI) (-1+λE+λI)+τ)+t ((((-1+λE))^2)-((λI)^2))),pI]]
FullSimplify[Solve[pE==(1/2) (c+(1/2) (c+pE+t ((((-1+λE))^2)-((λI)^2)))-t (1+λE-λI) (-1+λE+λI)+τ),pE]]

(* Difference between equilibrium prices pE - pI (for X) *)FullSimplify[(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)-(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)]

(* Individual profits in Bertrand equilibrium *)profitI=FullSimplify[((1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)-c)(1/(2 t (-1+λE+λI)))(-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)+(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)+t (-(((-1+λE))^2)+((λI)^2)))]
profitE=FullSimplify[((1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)-c-τ)(1-(1/(2 t (-1+λE+λI)))(-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)+(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)+t (-(((-1+λE))^2)+((λI)^2))))]
FullSimplify[D[profitI,τ]]
FullSimplify[D[profitE,τ]]

(* Total profits in Bertrand equilibrium *)
FullSimplify[profitI+profitE]
FullSimplify[profitI+profitE/.τ->0]
(* Separate transport cost term in total profits in Bertrand equilibrium *)FullSimplify[%%-%]
FullSimplify[%%+%-%%%]
FullSimplify[D[profitI+profitE,τ]]
FullSimplify[D[profitI+profitE,λE]]

(* Existence of Bertrand equilibrium with all consumers buying *)U0=s-(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)-((λI)^2)t;U1=s-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)-((λE)^2)t;
Ux0=s-(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)-((((1/(2 t (-1+λE+λI)))(-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)+(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)+t (-(((-1+λE))^2)+((λI)^2)))-λI))^2)t;
Ux1=s-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)-(((1-λE-(1/(2 t (-1+λE+λI)))(-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)+(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)+t (-(((-1+λE))^2)+((λI)^2)))))^2)t;
Solve[U0==0,s]
Solve[U1==0,s]
Simplify[Solve[Ux0==0,s]]
Simplify[Solve[Ux1==0,s]]

FullSimplify[(3 -4 λE+ ((λE)^2)-2 λI+2  ((λI)^2))/(1-λE-λI)]
FullSimplify[(3 -2 λE+2  ((λE)^2)-4  λI+((λI)^2))/(1-λE-λI)]

FullSimplify[(3 c+3 t-4 t λE+t ((λE)^2)-2 t λI+2 t ((λI)^2)+τ)- (3 c+3 t-2 t λE+2 t ((λE)^2)-4 t λI+t ((λI)^2)+2 τ)]

(* Middle range of consumers buys if the following condition is strictly positive *)FullSimplify[2λI-(1/(2 t (-1+λE+λI)))(-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)+(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)+t (-(((-1+λE))^2)+((λI)^2)))]
FullSimplify[2λE-1+(1/(2 t (-1+λE+λI)))(-(1/3) (3 c-t (3+λE-λI) (-1+λE+λI)+2 τ)+(1/3) (3 c+t (-3+λE-λI) (-1+λE+λI)+τ)+t (-(((-1+λE))^2)+((λI)^2)))]