I am trying to show that when inserting $$S = Q \frac{hd + pb}{bh + pb}$$ into the expression $$\frac{h(bS - dQ)^2}{2b(b-d)Q} + \frac{pb(Q-S)^2}{2(b-d)Q}$$ it can be simplified to the fraction $$\frac{hp(b-d)Q}{2(h+p)b}.$$
However, when I first insert $S$ into the expression and start expanding and get a very long a complex expression with lots of quadratic terms. Are there any tricks so to speak that can make this simplification easier? Is there something I am missing?
Rewrite the first equation \begin{eqnarray*} S=Q\frac{pb+\color{red}{bh-bh}+hd}{b(h+p)}=Q\frac{\color{blue}{pb+bh}-bh+hd}{b(h+p)}=Q \left(\color{blue}{1}+\frac{h(d-b)}{b(h+p)} \right) \\ bS= Q \left(d+ \frac{p(b-d)}{h+p} \right) \end{eqnarray*} Now sub into the expression \begin{eqnarray*} \frac{h(bS-dQ)^2}{2b(b-d)Q}+\frac{pb(Q-S)^2}{2(b-d)Q} &=&Q \frac{hp^2(b-d)^2}{2b(b-d)(h+p)^2} +\frac{Qpbh^2(b-d)^2}{2(b-d)b^2(h+p)^2} \\ &=& \frac{Qhp}{2b(h+p)^2} \left(p(b-d)+h(b-d) \right) \\ &=& \frac{Qhp(b-d)}{2b(h+p)} \end{eqnarray*}