Proving that if $p^2 = a^2 + 2b^2$ then also $p$ can be written in form $a^2 +2b^2$

Here's an elementary proof.

From $p^2=a^2+2b^2$, we have $2b^2=(p-a)(p+a)$. Since $b\not=0$, we have $\gcd(a,b)=1$ and consequently $\gcd(p-a,p+a)=2$. Let's write $m=(p-a)/2$ and $n=(p+a)/2$, so that $\gcd(m,n)=1$ and $mn=2\beta^2$ where $\beta=b/2$. (It's easy to see that $b$ must be even.)

Without loss of generality (since $a$ can be either positive or negative), we can assume that $m$ is even. But since $\gcd(m,n)=1$, we must now have $m=2r^2$ and $n=s^2$, with $\gcd(2r,s)=1$ -- i.e., each prime factor of $\beta$ belongs entirely to either $m$ or $n$. So we now have

$$m={p-a\over2}=2r^2$$ and $$n={p+a\over2}=s^2$$

from which it follows that

$$p=s^2+2r^2$$


Let's assume that $p$ is odd and use a bit of algebraic number theory.

Consider the field $\mathbb{Q}(\sqrt{-2})$, which has the ring of integers $\mathbb{Z}[-2]$. This is a Dedekind domain, so ideals factor uniquely, and so a PID.

By the question we have $(p^2)=(p)^2=(a^2+2b^2)$ and we want $(p)=(c^2+2d^2)$, as then have $p=u(c^2+2d^2)$ for some unit $u$ (the only units in $\mathbb{Z}[-2]$ are $\pm 1$, and by sign, $u=1$).

It's proven (c.f. Ireland and Rosen, page 190) that $(p)$ splits up into a product of one or two prime ideals in one of three ways. This depends on two conditions on $p$.

(Let $P,P'$ be distinct prime ideals throughout).

  • For finitely many $p$ (condition: $p\mid -8$, $-8$ being the discriminant of the field), $(p)=P^2$. But this only concerns $p=2$ so we move on to cases where $p \not \mid -8$.

  • If $x^2=-2 \text{ mod }p$ is soluble in $\mathbb{Z}$, then $(p)=PP'$. $\mathbb{Z}[-2]$ is a a PID so $(p)=(x)(y)=(xy)$ for $x \ne y$, and have $p=uxy=\pm xy$. Necessarily $x=\bar{y}=c+d\sqrt{-2}$ and hence the result.

  • If not soluble, then $(p)=P$, in which case your result would not hold. But if $(p)$ is prime, $p$ is prime in $\mathbb{Z}[\sqrt{-2}]$, then $p^2=(a+\sqrt{-2}b)(a-\sqrt{-2}b)$ implies that $(a+\sqrt{-2}b),(a-\sqrt{-2}b)$ are prime. But then $a=p,b=0$ by unique factorisation.