2

Background/Motivation

I am advising a number theory project for a group of students. They are going to implement an algorithm to express any prime $p$ congruent to $1$ mod $4$ as a sum of two squares.

One thing they will need to do is to find a square root of $-1$ mod $p$.

My first thought is that since half of the numbers $1,2,3, ...$ are non quadratic residues mod $p$, they can just check $a^{\frac{p-1}{2}}$ mod $p$ for $a = 2, 3, 4, ...$ until they get $-1$. Computing these powers is relatively quick if they express $\frac{p-1}{2}$ in binary and use repeated squaring to find the values $a^{2^n}$ mod $p$.

This leads to the question of "worst case scenarios": what if there is a long string of quadratic residues at the beginning of the sequence?

Question

What is known about the longest string of consecutive quadratic residues mod $p$? Can we say anything about the ratio of this number to $p$ as $p \to \infty$?

  • 1
    Polya Vinogradov is relatively elementary and gives $\sqrt{p} \log p$. The improvements (search for least quadratic non-residue) are much harder. – reuns Feb 25 '22 at 14:46
  • @reuns Thanks! I was missing this keyword. If you post your comment as an answer, I would be glad to accept it. – Steven Gubkin Feb 25 '22 at 14:51
  • see also Stan Wagon, Editor's corner: The Euclidean algorithm strikes again, American Mathematical Monthly, 97 (1990) 125-129. list at http://stanwagon.com/wagon/misc/papers.html The method I like is to use the square root of -1 mod p to construct a binary quadratic form $<p, 2b, c> $ or $px^2 + 2bxy + c y^2 $ of discriminant $-4$ Then Gauss reduce this to $<1,0,1>$ keeping track of the change of basis matrix; at the end, invert this, the left column represents $p$ as $t^2 + u^2$ – Will Jagy Feb 25 '22 at 17:51
  • 1
    @WillJagy Yes, I did another student project on this method. We thought about the same thing from a topographic perspective. Here is the code: https://replit.com/@StevenGubkin/Fermats-Christmas-Theorem#main.py – Steven Gubkin Feb 25 '22 at 18:13
  • Note this question about graphics: https://math.stackexchange.com/questions/1078450/maps-of-primitive-vectors-and-conways-river-has-anyone-built-this-in-sage I made a few programs to give the numbers for parts of the topograph, allowing me to draw the diagrams. Still a solid hour just to draw the river for a "reduced" indefinite form with relatively small automorphism (generator) matrix. – Will Jagy Feb 25 '22 at 19:22

0 Answers0