I have a 4-D scalar field over the $A$, $B$, $C$, and $D$ axes:
$$X = \cos(A-B) + \cos(A-D) + \cos(C-B) - \cos(C-D)$$
and I want to find the global maxima and minima. I did
$$\nabla X = [-\sin(A-B) - \sin(A-D)]\hat a + [\sin(A-B) + \sin(C-B)]\hat b + [-\sin(C-B) + \sin(C-D)]\hat c + [\sin(A-D) -\sin(C-D)]\hat d$$
Where $\hat a$, $\hat b$, $\hat c$, and $\hat d$ are the unit vectors in each direction. I then set each term in square brackets to zero in order to find out what the critical points are (second-derivative tests can come later):
$$\sin(A-B) + \sin(A-D) = 0$$ $$\sin(A-B) + \sin(C-B) = 0$$ $$\sin(C-D) - \sin(C-B) = 0$$ $$\sin(A-D) - \sin(C-D) = 0$$
An obvious solution is each variable being an integer multiple of π:
$$A = nπ$$ $$B = mπ$$ $$C = pπ$$ $$D = qπ$$
Where $n$, $m$, $p$, and $q$ can each independently be any integer (positive, negative or 0).
However, I found out through numerical simulations that $X$ can reach a maximum value of $2\sqrt{2}$. It is clear that the above integer-π solutions can't possibly make $X$ take on this value. My question is: how do I find out what the other solutions are to those four equations, analytically?
\begin{align*} \cos (A-B)+\cos(A-D) &= 2\cos \frac{B-D}{2} \cos \frac{2A-B-D}{2} \\ \cos (C-B)-\cos(C-D) &= 2\sin \frac{B-D}{2} \sin \frac{2C-B-D}{2} \\ X &= R\sin \left( \frac{B-D}{2}+\theta \right) \\ R^2 &= 4\cos^2 \frac{2A-B-D}{2}+4\sin^2 \frac{2C-B-D}{2} \\ &= 2[2+\cos (2A-B-D)-\cos (2C-B-D)] \\ \end{align*}
For maximal $R^2$, \begin{align*} 2A-B-D &= 2n\pi \\ 2C-B-D &= (2m+1)\pi \\ X &= 2\left[(-1)^n\cos \frac{B-D}{2}+(-1)^m\sin \frac{B-D}{2} \right] \\ &= 2\sqrt{2} \sin \left[ (-1)^{m}\frac{\pi}{4}+(-1)^{n} \frac{B-D}{2} \right] \end{align*}
For maximal $X$, \begin{align*} (-1)^{m}\frac{\pi}{4}+(-1)^{n} \frac{B-D}{2} &= \frac{(4k+1)\pi}{2} \\ (-1)^{m}\frac{\pi}{2}+(-1)^{n} (B-D) &= (4k+1)\pi \\ \end{align*}
For minimal $X$, \begin{align*} (-1)^{m}\frac{\pi}{4}+(-1)^{n} \frac{B-D}{2} &= \frac{(4k+3)\pi}{2} \\ (-1)^{m}\frac{\pi}{2}+(-1)^{n} (B-D) &= (4k+3)\pi \\ \end{align*}