. . . mod $p$, of course, for $p$ prime and equal to 1 mod 4.

For any prime $p$ which is 1 mod 4, $-1$ has a square root in $\mathbb{Z}/p\mathbb{Z}$. But it quickly gets frustrating to find the precise value of $\sqrt{-1}$ in $\mathbb{Z}/p\mathbb{Z}$ by hand. My question is: is there a snappy way to do this?

To make this precise, let me ask a question I'm sure the answer to which is no:

Is there an elementary function $f$ such that, for each prime $p$ which is 1 mod 4, we have $[f(p)]^2=-1$ (mod $p$), where $[\cdot]$ is the "nearest integer" function?

(I'm using the precise meaning of "elementary function" here: https://en.wikipedia.org/wiki/Elementary_function. Note that elementary functions in general take values in $\mathbb{C}$; so tweak the "nearest integer" function appropriately: for $c$ complex, $[c]$ is the least integer $z\in\mathbb{Z}$ (not $\mathbb{Z}+\mathbb{Z}i$) such that $\vert c-z\vert$ is minimal.)


Solution 1:

If $p=4k+1$ then $f(p)=(2k)!$ has this property.

Proof: By Wilson's theorem, $(p-1)! \equiv -1$, so $(4k)! \equiv -1$.

Furthermore, $$(4k)!=(1)(2)\ldots (2k)(2k+1)(2k+2)\ldots (4k-1)(4k)$$ $$ =(1)(2)\ldots(2k)(p-2k)(p-(2k-1))\ldots(p-1)$$ $$ \equiv (1)(2)\ldots(2k)(-2k)(-(2k-1))\ldots(-1)$$ $$ \equiv (2k)!^2(-1)^{2k} \equiv (2k)!^2$$

Thus $(2k)!^2 \equiv (4k)! \equiv -1$.

In all of these calculations, $\equiv$ refers to mod p.

Edit: I remember reading in Davenport's "The Higher Arithmetic," which gives four different methods of finding such square roots of $-1$, mentions that this is actually a remarkably difficult problem. I'm going to give it a look now, but I believe that if such an elementary function exists, then it has not been discovered.

Edit 2: I stand corrected. Davenport gives four different methods of finding representations of $p$ as the sum of two squares, not finding square roots of $-1$ mod $p$. I still, however, do not think that an elementary function exists. My incredibly non-rigorous logic is that (since the square roots are unique up to a sign), if an elementary function existed which gave that value of $\sqrt{-1}$ mod $p$, then that would mean that the function given by $f(p)=\left({(\frac{p-1}{2})! \mod p}\right)$ is an elementary function, which doesn't feel right.