1

Due to Fermat, we know that every prime $p \equiv 1 (\mathop{mod} 4)$ is the sum of two squares. There are several published algorithms to find the two squares. I was curious about the inner workings of these algorithms and tinkered around a bit.

First, I'd find a root of $-1$. This I did by taking random numbers $a$ and raising them to the $(p-1)\over 4$th power. Sometimes, the square $b = a^2$ of this number happens to be $-1$. Now we have:

$$ a^2+1^2 \equiv 0 $$

However, $a$ is usually of the order of $p$, so that ${(a^2+1^2)\over p} \gg 1$. Generally also ${(a^2+1^2)\over p} \neq 1$.

The Euclidean Algorithm yields numbers $k$, so that $|ak| \lt |a|$. In particular, there's a number $k \approx\sqrt{p}$ so that $ak \approx \sqrt{p}$. This makes a pretty compelling candidate for $a$ and $b$ so that $a^2+b^2 = p$. We can multiply the equivalence above to have

$$ (ak)^2+k^2 \equiv 0 $$

Now, both $ak$ and $k$ are $\approx \sqrt{p}$. So their squares are $\approx{p}$, and their sum will not be too different. While experimenting with this, I found that the euclidean algorithm always appears to run symmetrically on this problem: factors $k$ later appear as remainders $ak$, with one sign flipped. In particular, there'll be a point where one step yields $b \equiv ak$, and the next gives $-a \equiv bk$. These $a$ and $b$ apparently always are the sought numbers so that $a^2+b^2\mathbf{=}p$.

Is it always possible to find $a$ and $b$ this way? Are there any counterexamples? I'm looking forward to Your comments and ideas.

0 Answers0