Doubt on a method used in an article ( extreme value problem of trig function) This might be a straightforward problem but I couldn't figure it out on my own.

start

$$
\begin{aligned} \mathcal{W}_{\mathbf{p}, \theta} &=\frac{1}{2}\left[\cos \alpha+\cos (\theta-\alpha)+2 \cos \frac{\theta}{2}+4 \sin \frac{\theta}{2}\right] \\ &=(2 \mathbf{p}-1)\left(\cos \frac{\theta}{2}\right)^{2}+2 \sqrt{\mathbf{p}(1-\mathbf{p})} \cos \frac{\theta}{2} \sqrt{1-\left(\cos \frac{\theta}{2}\right)^{2}}+\cos \frac{\theta}{2}+2 \sqrt{1-\left(\cos \frac{\theta}{2}\right)^{2}} \end{aligned}
$$
where $\mathbf{p}=\frac{1+\cos \alpha}{2}$.
Furthermore, in order to obtain the maximal value of $\mathcal{W}$ expression only about the maximal guessing probability $\mathbf{p}$ (i.e., the angle of $\alpha$ ), we use the method of the extreme-value problem of function and let $x=\cos \frac{\theta}{2} .$ Applying to the equation above, we get
$$
\mathcal{W}_{\mathbf{p}}^{\max }=\max _{\{r\}}\left\{r+(2 \mathbf{p}-1) r^{2}+2 \sqrt{1-r^{2}}+2 \sqrt{\mathbf{p}(1-\mathbf{p})} r \sqrt{1-r^{2}}\right\}
$$
where $r$ is one of the real roots of $4 x^{4}+4[(2 \mathbf{p}-1)+4 \sqrt{\mathbf{p}(1-\mathbf{p})}] x^{3}+x^{2}-4[(2 \mathbf{p}-1)+2 \sqrt{\mathbf{p}(1-\mathbf{p})}] x+(2 \mathbf{p}-1)^{2}=$ $0 .$

end

How do they get the polynomial equation? What method is this? I needed to find the extrema of a multivariable trigonometric function. Can I apply the same method there? Kindly help in any way possible.
This was written in the supplementary of this article.
 A: Thanks for the article and its appendix. Having browsed it, I understand now that they proceed in two steps to obtain the maximal value of $W$:

*

*For a fixed $p$, they (partially) differentiate $W$ with respect to $r$, and set the derivative to zero for having their maximum.

After grouping the different square roots, say in the RHS, squaring the resulting equation gives indeed the following fourth degree equation for $r$:
$$(1-r^2)(1+2rU+V)^2=r^2(V+1) \tag{1}$$
where $U:=2p-1$ and $V:=2\sqrt{p(1-p)}.$


*Then they proceed with the maximization with respect to the other variable... like reaching the summit of a mountain by following an ascending crest.

Remark: It looks to me that the authors push some dust under the carpet, because saying $r$ is one of the real roots of (1) isn't enough: how do they proceed for finding which one to select (moreover with the fact that there are spurious roots in (1) due to the squaring process) ? How can one be sure that there isn't a "bifurcation" between these roots for certain values of $p$ ?
