The square root of Wilson's theorem when $p\equiv 1 \mod 4$

My question relates, at least superficially, to these old ones:

The value $\pm 1$ for the square root of Wilson's theorem, ((p-1)/2)! mod p

Primes P such that ((P-1)/2)!=1 mod P

When $p\equiv 1 \mod 4$, if $x=((p-1)/2)!$, then $x^2 = -1 \mod p$.

For what primes does $x \in \{1,\ldots,(p-1)/2\}$ (the elements of the set regarded as residues $\mod p$)?

One gets "yes" for $5,13,29,41,53,61,73,89,97,\ldots$ and "no" for $17,37,101,\ldots$. Despite the slow start for "no", the counts substantially even out, say, when looking at primes up to 100000. Can one prove that the ratio approaches $1/2$?

• The first eight terms of your $5,13,29\dots$ match oeis.org/A185086 (but your 9th term is 97, instaed of 109). – Gerry Myerson Feb 24 '18 at 6:45

In the case $p \equiv 1$ mod $4$, the connection is to the real quadratic field ${\mathbb Q}(\sqrt{p})$, whereas the case $p \equiv 3$ mod $4$ is connected to the imaginary quadratic field ${\mathbb Q}(\sqrt{-p})$.

Chowla ("On the class number of real quadratic fields", 1961 PNAS) proves that $$\left( \frac{p-1}{2} \right)! \equiv (-1)^{\frac{h+1}{2}} \cdot \frac{t}{2} \text{ mod } p,$$ where $h$ is the class number of ${\mathbb Q}(\sqrt{p})$ and the fundamental unit is $\frac{1}{2}(t + u \sqrt{p}) > 1$ with $t,u \in {\mathbb Z}$.

In fact, 0 < t < 2p. EDIT: that's false. I think I was remembering a converse, that if you find such an element $\frac{1}{2}(t + u \sqrt{p})$ of norm $-1$, and $0 < t < 2p$, then it's a fundamental unit. (This is right, I hope, but not so relevant). See Upper bound on answer for Pell equation for more on bounding $t$.

So it seems like the answer depends on (1) the class number mod 4 and (2) whether $\frac{t}{2} \in \{ 1,2,\ldots,\frac{p-1}{2} \}$ mod $p$. The statistics seem (to me) at least as difficult as the $p \equiv 3$ mod $4$ case.

• Do you have a reference on hand that $t<2p$? – Dror Speiser Feb 25 '18 at 19:05
• According to the table at mathworld.wolfram.com/FundamentalUnit.html, the fundamental unit when $p=73$ is $1068+125\sqrt{73}$, apparently in violation of $0<t<2p$. – Gerry Myerson Feb 25 '18 at 21:50
• Chowla's paper (p. 878 of the reference cited) does not claim $0<t<2p$. – Gerry Myerson Feb 25 '18 at 23:23
• Ahh - I messed up on that one. I've made a correction, and sadly it makes the answer a bit weaker when we don't have such a nice bound on $t$. It was too good to be true. – Marty Feb 26 '18 at 2:45
• There is a discussion of the case $p \equiv 3 \bmod 4$ at mathoverflow.net/questions/16141/… – KConrad Feb 26 '18 at 8:31