expected profit given price and discontinuous demand function I would like to calculate expected profit given the price level, $P$. Assume that $A \sim U(0,1) $ and $B \sim U(0,1)$ and independent. Demand, $x$,  is as follows $x=0$ if $P > A$, and $x = B - \frac{BP}{A}$ if $0 \leq P \leq A$. Then my aim is to find $E(Px)$. Is the following attempt correct? What do you think?
$$E(Px) = E(Px|P>A)Pr(P>A) + E(Px|0 \leq P \leq A)Pr(0 \leq P \leq A) = E(Px|0 \leq P \leq A)(1-P)$$
$$=\frac{ \int_{0}^{1} \int_{P}^{1}Pxf_Af_B dAdB }{Pr(P \leq A \leq 1)}(1-P) = \frac{ \int_{0}^{1} \int_{P}^{1}P(B-BP/A) dAdB }{1-P}(1-P)= \frac{P-P^2 + P^2 log(P)}{2} $$ 
In the last raw above I am a bit confused and not sure. 
 A: Recall that for an event $E$, the conditional expectation of a random variable $X$ given $E$ is $$\mathbb E[X\mid E] = \frac{\mathbb E[X\mathsf 1_E]}{\mathbb P(E)},$$ where $\mathsf 1_\cdot$ denotes the indicator function. So using the tower property, we compute
\begin{align}
\mathbb E[pX] &= \mathbb E\left[\mathbb E\left[pB\left(1-\frac pA\right)\mid A>p\right]\right]\\
&= \frac{p\cdot\mathbb E\left[\mathbb E\left[B\left(1-\frac pA\right)\mathsf 1_{\{A>p\}}\right]\right]}{\mathbb P(A>p)}\\
&=\frac p{1-p}\mathbb E\left[\int_0^1\int_A^1 y\left(1-\frac px\right)\ \mathsf dx\ \mathsf dy\right]\\
&=\frac p{1-p}\mathbb E\left[\int_0^1 y(1-A +p\log A)\ \mathsf dy\right]\\
&= \mathbb E\left[\frac{p(1-a+p\log A)}{2(1-p)}\right]\\
&= \frac{p\left(\frac12-p\right)}{2(1-p)}.
\end{align}
This is maximized when
$$
\frac{\mathsf d}{\mathsf dp}\left[\frac{p\left(\frac12-p\right)}{2(1-p)}\right] = \frac{2 p^2-4 p+1}{4 (1-p)^2} = 0 \iff p = \frac{1}{2} \left(2-\sqrt{2}\right),
$$
for a value of $\frac{3}{4}-\frac{1}{\sqrt{2}}$.
(Note the the map $\frac{p \left(\frac{1}{2}-p\right)}{2 (1-p)}$ is twice-differentiable, with second derivative strictly negative for $p>0$, and so in fact the critical point is a maximum.)
