Primes represented by quadratic forms

Choose a positive integer n . Which primes p can be written as p=x^2+ny^2 with integers x,y ? For n=1 the answer is familiar: apart from 2 , the primes are exactly those leaving remainder 1 on division by 4 . For n=5 , something slightly different happens. We have 41=6^2+5(1)^2 , but 23 cannot be written as x^2+5y^2 . Yet both primes have a square root of -5 : 6^2+5=41 and 8^2+5=3\cdot23 . The same simple test succeeds for both primes, while the original equation succeeds for only one. What has the test actually told us about 23 ?

There is a good answer, and it is the main point of this discussion. When -n has a square root modulo a prime p , the prime can always be represented by a quadratic expression closely related to x^2+ny^2 . It may not be the expression we started with. For n=5 there are only two possibilities; for n=11 there are three, and for n=14 there are four. We can find these other expressions by a short calculation. Once we see where the prime has gone, the different answers for n=1,5,11,14,21 become much easier to understand. We will still be asking about x^2+ny^2 throughout; the other expressions enter only to explain why a prime that passes the first test may fail to have the representation we want.

Congruence test

Suppose p=x^2+ny^2 , where p is an odd prime not dividing n . The number y cannot be divisible by p : otherwise the equation would force p to divide x as well, and the right side would be divisible by p^2 . We can therefore divide by y^2 modulo p . The original equation gives (xy^{-1})^2\equiv-n\pmod p , where y^{-1} means the inverse of y modulo p . Thus the polynomial X^2+n must have a root modulo p . This is a necessary condition, and it is often easy to check even for a large prime.

\displaystyle X^2+n\equiv0\pmod p.

For n=1 , this condition is also sufficient. A root of X^2+1 modulo an odd prime exists exactly when p\equiv1\pmod4 , and Fermat’s two-square theorem says that every such prime is x^2+y^2 . For n=2 the represented odd primes are exactly p\equiv1,3\pmod8 . For n=3 they are exactly p\equiv1\pmod3 , together with the prime 3 . Some small examples are 13=2^2+3^2 , 11=3^2+2(1)^2 , and 19=4^2+3(1)^2 . In these three cases the first square-root test tells the whole story. The question is why it stops doing so as n changes.

The first test has three possible outcomes, which are useful to keep separate. For n=5 , the prime 13 fails immediately: the nonzero squares modulo 13 are 1,3,4,9,10,12 , and -5\equiv8\pmod{13} is not among them. The prime 23 passes the test but is not x^2+5y^2 . The prime 41 passes and does have the desired representation. Thus failure of the modular equation rules out the integer equation, but success only begins the search. What makes the successful modular tests so useful is that we can always attach a concrete two-variable expression to them.

Representation by some form

Assume now that p is odd, that p does not divide n , and that we have found an integer r with r^2+n\equiv0\pmod p . Because p divides r^2+n , the number c=(r^2+n)/p is an integer. Consider the following quadratic form in two new variables:

\displaystyle Q(X,Y)=pX^2+2rXY+\frac{r^2+n}{p}Y^2.

There are two immediate facts about this expression. First, Q(1,0)=p , so it represents the prime we started with. Second, the number (2r)^2-4p((r^2+n)/p) is always -4n . For a general expression aX^2+bXY+cY^2 , the number b^2-4ac is called its discriminant. Thus our new form and the original X^2+nY^2 have the same discriminant, -4n . The expression is also positive away from (0,0) , as we can see by completing the square:

\displaystyle Q(X,Y)=\frac{(pX+rY)^2+nY^2}{p}.

So a root of X^2+n modulo p really does produce a positive quadratic form of the correct discriminant that represents p . No theorem about number fields is needed for this construction. It is just the observation that a congruence makes one coefficient an integer. The only remaining question is whether this form can be changed into X^2+nY^2 by an invertible integer change of variables. If it can, then the prime has the representation we wanted. If it cannot, the new form tells us what kind of representation the prime has instead.

We need a way to compare such expressions without trying arbitrary substitutions. Write a form briefly as [a,b,c] , meaning aX^2+bXY+cY^2 . There are two simple moves. Replacing X by X+kY changes its coefficients to [a,b+2ak,ak^2+bk+c] . Replacing (X,Y) by (-Y,X) changes the coefficients to [c,-b,a] . Both substitutions are reversible using integers, and neither changes the numbers represented by the form. We first choose k to make the middle coefficient satisfy |b|\le a . If the last coefficient is then smaller than a , we exchange the first and last coefficients and repeat. Each such exchange makes the first coefficient smaller, so the process must stop.

\displaystyle |b|\le a\le c,\qquad 4n=4ac-b^2\ge3a^2.

A form satisfying these inequalities is called reduced. The second inequality shows that its first coefficient cannot exceed \sqrt{4n/3} . For any fixed n , we therefore have only a short list to examine. For example, when n=5 , the first coefficient is at most 2 . Substituting a=1 and a=2 into b^2-4ac=-20 gives exactly the two reduced forms [1,0,5] and [2,2,3] , with the standard choice of sign on the boundary. This is the first place where we see why a prime can pass the square-root test without being x^2+5y^2 : there is a second possible destination.

It is useful to check why this procedure really answers our original question. If p=x^2+ny^2 , then x,y have no common factor, since the square of such a factor would divide the prime. We can find integers u,v such that xv-yu=1 . Making the substitution (X,Y)=(xU+uV,yU+vV) in X^2+nY^2 gives a form whose leading coefficient is p . Its discriminant is still -4n , so its middle coefficient is 2r for some root r^2\equiv-n\pmod p . Conversely, every move in our reduction procedure can be reversed using integers. If the constructed form reduces to [1,0,n] , reversing the substitutions turns its value Q(1,0)=p into an actual representation p=x^2+ny^2 . This explains the difference between the first test and the full reduction: the first constructs a form, while the second decides whether it is the particular form we wanted.

There are usually two square roots, r and -r , modulo the odd prime p . They lead to forms with opposite middle coefficients, after an elementary change of variables. Such forms represent the same integers, because replacing Y by -Y changes the sign of the middle term. So the answer to our original question does not depend on which root we chose. Later, when we list forms such as [3,2,4] and [3,-2,4] , we will see both signs; for deciding whether a prime has a representation, they give the same set of prime values.

Let us follow the calculation for p=41 . We have 6^2\equiv-5\pmod{41} , so the construction gives [41,12,1] . Exchanging the two variables gives [1,-12,41] . We then replace X by X+6Y , obtaining [1,0,5] . This is the form we wanted. Reading the substitutions backward gives the familiar equality 41=6^2+5(1)^2 . Nothing mysterious happened: the modular root gave a quadratic form, and two elementary changes of variables revealed that it was the original form in different coordinates.

\displaystyle [41,12,1]\ \longrightarrow\ [1,-12,41]\ \longrightarrow\ [1,0,5].

Now try p=23 . This time 8^2\equiv-5\pmod{23} , so we obtain [23,16,3] . Exchange the variables to get [3,-16,23] , replace X by X+3Y to get [3,2,2] , and exchange once more. A final replacement X\mapsto X+Y gives [2,2,3] . This is not the form X^2+5Y^2 . But it does represent 23 , and we can see the representation explicitly:

\displaystyle 23=2(2)^2+2(2)(-3)+3(-3)^2.

The difference between 41 and 23 is now concrete. Both primes satisfy the congruence X^2+5\equiv0\pmod p , but one reduces to [1,0,5] and the other to [2,2,3] . Notice also that an odd number of the form X^2+5Y^2 is 1\pmod4 , whereas an odd number of the form 2X^2+2XY+3Y^2 is 3\pmod4 . In the second case Y must be odd, and X(X+Y) is even. Thus the two forms are separated by a simple remainder test. In fact, for primes other than 2,5 , the first form represents precisely the primes 1,9\pmod{20} , and the second represents precisely the primes 3,7\pmod{20} . Together, the two forms account for every prime for which -5 has a square root.

For n=6 , the reduced list is again short: [1,0,6] and [2,0,3] . We have 31=5^2+6(1)^2 , so 31 belongs to the first form. But 11 also passes the first test, because 4^2\equiv-6\pmod{11} . Its constructed form is [11,8,2] , which reduces by [11,8,2]\to[2,-8,11]\to[2,0,3] . Indeed, 11=2(2)^2+3(1)^2 . Here again the square-root test gives two possibilities, and ordinary congruences separate them: for primes not dividing 6 , the form X^2+6Y^2 represents exactly p\equiv1,7\pmod{24} , while 2X^2+3Y^2 represents exactly p\equiv5,11\pmod{24} .

The two cases also show how to add a second polynomial test instead of carrying out a reduction for every new prime. For n=5 , a prime different from 2,5 is x^2+5y^2 precisely when both X^2+5 and X^2+1 have roots modulo p . The first test says that the prime is represented by one of the two forms; the second distinguishes the form [1,0,5] from [2,2,3] . For p=41 , we have 6^2\equiv-5 and 9^2\equiv-1\pmod{41} . For p=23 , the first congruence has a root but the second does not, because 23\equiv3\pmod4 . Likewise, for n=6 , the two useful tests are X^2+6 and X^2-2 . The prime 31 passes both, since 5^2\equiv-6 and 8^2\equiv2\pmod{31} , whereas 11 passes the first but not the second. In these examples, a second square-root test gives exactly the information missing from the first.

It would be natural to guess that the problem gets harder simply because the number of forms increases. That guess is not quite right. Take n=21 . Its discriminant is -84 , and reduction gives four forms:

\displaystyle [1,0,21],\qquad [2,2,11],\qquad [3,0,7],\qquad [5,4,5].

We can find a prime represented by each one. The prime 37=4^2+21(1)^2 belongs to the first form. The prime 11 belongs to the second, simply by taking X=0,Y=1 . The prime 19=3(2)^2+7(1)^2 belongs to the third, and 17=5(2)^2+4(2)(-1)+5(-1)^2 belongs to the fourth. All four primes satisfy the first modular condition: roots of X^2+21 modulo 11,17,19,37 are respectively 1,8,6,4 . So the first test again sends us to one of several forms, and the reduction procedure tells us which one.

For instance, the roots just listed give the forms [11,2,2] , [17,16,5] , [19,12,3] , and [37,8,1] . Reducing them yields, in the same order, [2,2,11] , [5,4,5] , [3,0,7] , and [1,0,21] . There are four possible forms, but a theorem says that the primes represented by the first one are still described by remainders alone:

\displaystyle p=x^2+21y^2\quad\Longleftrightarrow\quad p\equiv1,25,37\pmod{84}.

For example, 37=4^2+21 , 109=5^2+21(2)^2 , and 421=20^2+21 give the three remainders 37,25,1 modulo 84 . Here the different forms can still be separated by their remainders, even though there are four of them. The number of forms by itself is therefore not what decides whether a simple congruence test will work. To see a real change, we need an example where two primes pass exactly the same remainder test but end up in different forms.

The list of four forms for n=21 can also be checked without assuming it in advance. The inequality 3a^2\le84 gives a\le5 . For each a=1,2,3,4,5 , the equation b^2-4ac=-84 and the restriction |b|\le a leave only a few values of b . The choices a=1,2,3,5 give exactly the four forms above. The possibility a=4 gives no primitive reduced form. This calculation is typical: we do not need to guess the other forms from a table. We can write them all down by solving a short list of elementary equations, and then ask which one a particular prime belongs to.

Consider n=11 . The reduced forms of discriminant -44 are [1,0,11] and [3,2,4],[3,-2,4] . The two forms with opposite middle coefficients represent the same integers, since replacing Y by -Y changes one into the other. But they are not the same form under changes of variables of determinant one. For our question about the primes represented, it is enough to view them as the second possibility. We have 47=6^2+11(1)^2 , whereas 179 is not x^2+11y^2 . Checking the latter directly is easy: |y| is at most 4 , and the possibilities for 179-11y^2 are 179,168,135,80,3 , none of which is a square.

Even so, 47\equiv179\equiv3\pmod{44} , and both primes satisfy X^2+11\equiv0\pmod p . For 47 we can choose r=6 , obtaining [47,12,1] , which reduces to [1,0,11] . For 179 we can choose r=40 ; the construction gives [179,80,9] . Its reduction is worth following because it answers the question of where the prime went:

\displaystyle [179,80,9]\longrightarrow[9,-80,179]\longrightarrow[9,-8,3]\longrightarrow[3,8,9]\longrightarrow[3,2,4].

Thus 179 is represented by the other form. Indeed,

\displaystyle 179=3(5)^2+2(5)(4)+4(4)^2.

The two primes have the same remainder modulo 44 , and both pass the same first square-root test. Nevertheless, one reduces to the form X^2+11Y^2 and the other to 3X^2+2XY+4Y^2 . This is the point at which remainders modulo 44 stop giving enough information. A different, still quite concrete, test is possible. Consider the fixed cubic polynomial H(T)=T^3-T^2-T-1 . For every prime other than 2,11 , a theorem says that p=x^2+11y^2 exactly when H(T) has three distinct roots modulo p . Modulo 47 , those roots are 5,17,26 . Modulo 179 , the cubic has no root. The factorization of a fixed polynomial has distinguished two primes that the first congruence test could not separate.

There are other small primes in the second family for n=11 . For example, 5=3(1)^2+2(1)(-1)+4(-1)^2 and 3=3(1)^2+2(1)(0)+4(0)^2 . In contrast, 53=3^2+11(2)^2 and 163=8^2+11(3)^2 belong to the original form. The cubic test is not tied to the particular pair 47,179 : it works for every prime away from the two exceptional primes, using the same polynomial each time. Our reduction calculation also gives an effective method for finding an actual representation once we know a root of X^2+11 . The polynomial test is different in purpose. It lets us decide which type of form a prime belongs to, without searching through all possible integer pairs x,y .

The case n=14 shows the same phenomenon with four reduced forms of discriminant -56 :

\displaystyle [1,0,14],\qquad [2,0,7],\qquad [3,2,5],\qquad [3,-2,5].

The prime 281=15^2+14(2)^2 is represented by the first form. The prime 113 is not: the only possible values of 113-14y^2 are 113,99,57 , and none is a square. But 113\equiv281\equiv1\pmod{56} , and -14 is a square modulo both primes. For 113 , take r=41 . The resulting form reduces as follows:

\displaystyle [113,82,15]\longrightarrow[15,-82,113]\longrightarrow[15,8,2]\longrightarrow[2,-8,15]\longrightarrow[2,0,7].

Once again, the prime has not disappeared. It belongs to a different form, since 113=2(5)^2+7(3)^2 . For 281 we can choose r=133 , obtaining [281,266,63] . This reduces to [1,0,14] , as expected. Other primes can land in the remaining two forms: 13=3(2)^2+2(2)(-1)+5(1)^2 and 19=3(1)^2+2(1)(-2)+5(2)^2 . So among primes for which the first square-root test succeeds, we can meet the original form, the form 2X^2+7Y^2 , or one of the two forms 3X^2\pm2XY+5Y^2 . Their existence explains why the first modular test need not identify our chosen representation.

For n=14 a quartic polynomial supplies a more precise test. Set P(T)=T^4+2T^2-7 . For primes other than 2,7 , a theorem says that p=x^2+14y^2 exactly when this quartic splits into four distinct linear factors modulo p . The difference between 113 and 281 can be checked directly. Modulo 281 , the four roots are 4,-4,87,-87 . Modulo 113 , the polynomial factors only as

\displaystyle P(T)\equiv(T^2+12)(T^2-10)\pmod{113},

and neither of these quadratic factors has a root. Modulo 13 , the quartic remains irreducible. So the way this one polynomial breaks apart shows three possible behaviors of split primes: four linear factors when the prime is x^2+14y^2 , two irreducible quadratic factors in the example 113 , and an irreducible quartic in the example 13 . We began by asking whether the prime has an integer representation. We ended by looking at the number and sizes of factors of a polynomial modulo that prime. These are two ways of organizing the same arithmetic information.

It matters that the quartic split completely. Asking only for one root would give a weaker test, just as the first quadratic congruence gave a weaker test. For example, modulo 31 , the quartic T^4+2T^2-7 has the roots 13,-13 but not four roots. The prime 31 is not x^2+14y^2 . In fact, X^2+14 has no root modulo 31 either. Thus a higher-degree polynomial can have a few roots without supplying the complete information we need. The exact theorem uses four distinct roots, not merely the existence of a root. This is why the way a polynomial factors, rather than just whether it has one solution, becomes the natural test in these examples.

The small cases now fit into a single picture. The test X^2+n\equiv0\pmod p tells us whether a prime is represented by some positive quadratic form of discriminant -4n . The formula [p,2r,(r^2+n)/p] constructs that form, and elementary changes of variables reduce it to one of finitely many possibilities. If there is only one possibility, as for n=1,2,3 , the first test settles the question. If there are several forms, we must find which one represents the prime. Sometimes their remainders distinguish them completely, as for n=5,6,21 . Sometimes primes with the same remainder fall into different forms, as for n=11,14 . Then a fixed cubic or quartic polynomial can give information that the first congruence did not give.

There is a general theorem behind the last two examples. Starting from the integers of the form x+y\sqrt{-n} , one can construct a number field in which the way a prime splits records whether p=x^2+ny^2 . In the usual cases this is described by the Hilbert class field of the quadratic field \mathbb Q(\sqrt{-n}) ; when the integers x+y\sqrt{-n} form a smaller ring than the full ring of integers, as for n=11 , the appropriate object is called a ring class field. We do not need their construction to appreciate what they accomplish. They give a reason why one fixed polynomial, chosen once for n , can recognize the primes represented by x^2+ny^2 through its factorization modulo p . The calculation with [p,2r,(r^2+n)/p] is the elementary beginning of this story. It shows exactly what the first square-root test knows, and why more information is sometimes needed to return from a solution modulo p to an equation in ordinary integers.

Leave a Reply