History, conventions, and elementary facts
Fermat, Euler,Prime modulus
Modulo 2, every integer is a quadratic residue. Modulo an oddPrime power modulus
All odd squares are ≡ 1 (mod 8) and thus also ≡ 1 (mod 4). If ''a'' is an odd number and ''m'' = 8, 16, or some higher power of 2, then ''a'' is a residue modulo ''m'' if and only if ''a'' ≡ 1 (mod 8).For example, mod (32) the odd squares are :12 ≡ 152 ≡ 1 :32 ≡ 132 ≡ 9 :52 ≡ 112 ≡ 25 :72 ≡ 92 ≡ 49 ≡ 17 and the even ones are :02 ≡ 82 ≡ 162 ≡ 0 :22 ≡ 62≡ 102 ≡ 142≡ 4 :42 ≡ 122 ≡ 16.So a nonzero number is a residue mod 8, 16, etc., if and only if it is of the form 4''k''(8''n'' + 1). A number ''a'' relatively prime to an odd prime ''p'' is a residue modulo any power of ''p'' if and only if it is a residue modulo ''p''.Gauss, DA, art. 101 If the modulus is ''p''''n'', :then ''p''''k''''a'' ::is a residue modulo ''p''''n'' if ''k'' ≥ ''n'' ::is a nonresidue modulo ''p''''n'' if ''k'' < ''n'' is odd ::is a residue modulo ''p''''n'' if ''k'' < ''n'' is even and ''a'' is a residue ::is a nonresidue modulo ''p''''n'' if ''k'' < ''n'' is even and ''a'' is a nonresidue. Notice that the rules are different for powers of two and powers of odd primes. Modulo an odd prime power ''n'' = ''p''''k'', the products of residues and nonresidues relatively prime to ''p'' obey the same rules as they do mod ''p''; ''p'' is a nonresidue, and in general all the residues and nonresidues obey the same rules, except that the products will be zero if the power of ''p'' in the product ≥ ''n''. Modulo 8, the product of the nonresidues 3 and 5 is the nonresidue 7, and likewise for permutations of 3, 5 and 7. In fact, the multiplicative group of the non-residues and 1 form the Klein four-group.
Composite modulus not a prime power
The basic fact in this case is :if ''a'' is a residue modulo ''n'', then ''a'' is a residue modulo ''p''''k'' for ''every'' prime power dividing ''n''. :if ''a'' is a nonresidue modulo ''n'', then ''a'' is a nonresidue modulo ''p''''k'' for ''at least one'' prime power dividing ''n''. Modulo a composite number, the product of two residues is a residue. The product of a residue and a nonresidue may be a residue, a nonresidue, or zero.For example, from the table for modulus 6 1, 2, 3, 4, 5 (residues in bold). The product of the residue 3 and the nonresidue 5 is the residue 3, whereas the product of the residue 4 and the nonresidue 2 is the nonresidue 2.Also, the product of two nonresidues may be either a residue, a nonresidue, or zero.
For example, from the table for modulus 15 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 (residues in bold). The product of the nonresidues 2 and 8 is the residue 1, whereas the product of the nonresidues 2 and 7 is the nonresidue 14.This phenomenon can best be described using the vocabulary of abstract algebra. The congruence classes relatively prime to the modulus are a group under multiplication, called the group of units of the ring Z/''n''Z, and the squares are a subgroup of it. Different nonresidues may belong to different cosets, and there is no simple rule that predicts which one their product will be in. Modulo a prime, there is only the subgroup of squares and a single coset. The fact that, e.g., modulo 15 the product of the nonresidues 3 and 5, or of the nonresidue 5 and the residue 9, or the two residues 9 and 10 are all zero comes from working in the full ring Z/''n''Z, which has zero divisors for composite ''n''. For this reason some authors add to the definition that a quadratic residue ''a'' must not only be a square but must also be relatively prime to the modulus ''n''. (''a'' is coprime to ''n'' if and only if ''a''2 is coprime to ''n''.) Although it makes things tidier, this article does not insist that residues must be coprime to the modulus.
Notations
Gauss used and to denote residuosity and non-residuosity, respectively; :for example, and , or and . Although this notation is compact and convenient for some purposes, a more useful notation is the Legendre symbol, also called the quadratic character, which is defined for all integers and positive oddDistribution of quadratic residues
Although quadratic residues appear to occur in a rather random pattern modulo ''n'', and this has been exploited in such applications as acoustics andFor example, if ''p'' ≡ 1 (mod 8), (mod 12), (mod 5) and (mod 28), then by the law of quadratic reciprocity 2, 3, 5, and 7 will all be residues modulo ''p'', and thus all numbers 1–10 will be. The CRT says that this is the same as ''p'' ≡ 1 (mod 840), and Dirichlet's theorem says there are an infinite number of primes of this form. 2521 is the smallest, and indeed 12 ≡ 1, 10462 ≡ 2, 1232 ≡ 3, 22 ≡ 4, 6432 ≡ 5, 872 ≡ 6, 6682 ≡ 7, 4292 ≡ 8, 32 ≡ 9, and 5292 ≡ 10 (mod 2521).
Dirichlet's formulas
The first of these regularities stems from Peter Gustav Lejeune Dirichlet's work (in the 1830s) on the analytic formula for the class number of binary quadratic forms. Let ''q'' be a prime number, ''s'' a complex variable, and define aFor example, modulo 11, :1, 2, 3, 4, 5, 6, 7, 8, 9, 10 (residues in bold) :1 + 4 + 9 + 5 + 3 = 22, 2 + 6 + 7 + 8 + 10 = 33, and the difference is −11.In fact the difference will always be an odd multiple of ''q'' if ''q'' > 3. In contrast, for prime ''q'' ≡ 1 (mod 4), the sum of the quadratic residues minus the sum of the nonresidues in the range 1, 2, ..., ''q'' − 1 is zero, implying that both sums equal . Dirichlet also proved that for prime ''q'' ≡ 3 (mod 4), : This implies that there are more quadratic residues than nonresidues among the numbers 1, 2, ..., (''q'' − 1)/2.
For example, modulo 11 there are four residues less than 6 (namely 1, 3, 4, and 5), but only one nonresidue (2).An intriguing fact about these two theorems is that all known proofs rely on analysis; no-one has ever published a simple or direct proof of either statement.
Law of quadratic reciprocity
If ''p'' and ''q'' are odd primes, then: ((''p'' is a quadratic residue mod ''q'') if and only if (''q'' is a quadratic residue mod ''p'')) if and only if (at least one of ''p'' and ''q'' is congruent to 1 mod 4). That is: : where is the Legendre symbol. Thus, for numbers ''a'' and odd primes ''p'' that don't divide ''a'':Pairs of residues and nonresidues
Modulo a prime ''p'', the number of pairs ''n'', ''n'' + 1 where ''n'' R ''p'' and ''n'' + 1 R ''p'', or ''n'' N ''p'' and ''n'' + 1 R ''p'', etc., are almost equal. More precisely, let ''p'' be an odd prime. For ''i'', ''j'' = 0, 1 define the sets : and let : That is, :α00 is the number of residues that are followed by a residue, :α01 is the number of residues that are followed by a nonresidue, :α10 is the number of nonresidues that are followed by a residue, and :α11 is the number of nonresidues that are followed by a nonresidue. Then if ''p'' ≡ 1 (mod 4) : and if ''p'' ≡ 3 (mod 4) :For example: (residues in bold) Modulo 17 :1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ::''A''00 = , ::''A''01 = , ::''A''10 = , ::''A''11 = . Modulo 19 :1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ::''A''00 = , ::''A''01 = , ::''A''10 = , ::''A''11 = .Gauss (1828) introduced this sort of counting when he proved that if ''p'' ≡ 1 (mod 4) then ''x''4 ≡ 2 (mod ''p'') can be solved if and only if ''p'' = ''a''2 + 64 ''b''2.
The Pólya–Vinogradov inequality
The values of for consecutive values of ''a'' mimic a random variable like a coin flip. Specifically, Pólya and Vinogradov proved (independently) in 1918 that for any nonprincipal Dirichlet character χ(''n'') modulo ''q'' and any integers ''M'' and ''N'', : in big O notation. Setting : this shows that the number of quadratic residues modulo ''q'' in any interval of length ''N'' is : It is easy to prove that : In fact, : Montgomery and Vaughan improved this in 1977, showing that, if theLeast quadratic non-residue
The least quadratic residue mod ''p'' is clearly 1. The question of the magnitude of the least quadratic non-residue ''n''(''p'') is more subtle, but it is always prime, with 7 appearing for the first time at 71. The Pólya–Vinogradov inequality above gives O( log ''p''). The best unconditional estimate is ''n''(''p'') ≪ ''p''θ for any θ>1/4, obtained by estimates of Burgess on character sums. Assuming the Generalised Riemann hypothesis, Ankeny obtained ''n''(''p'') ≪ (log ''p'')2.Quadratic excess
Let ''p'' be an odd prime. The quadratic excess ''E''(''p'') is the number of quadratic residues on the range (0,''p''/2) minus the number in the range (''p''/2,''p'') . For ''p'' congruent to 1 mod 4, the excess is zero, since −1 is a quadratic residue and the residues are symmetric under ''r'' ↔ ''p''−''r''. For ''p'' congruent to 3 mod 4, the excess ''E'' is always positive.Complexity of finding square roots
That is, given a number ''a'' and a modulus ''n'', how hard is it # to tell whether an ''x'' solving ''x''2 ≡ ''a'' (mod ''n'') exists # assuming one does exist, to calculate it? An important difference between prime and composite moduli shows up here. Modulo a prime ''p'', a quadratic residue ''a'' has 1 + (''a'', ''p'') roots (i.e. zero if ''a'' N ''p'', one if ''a'' ≡ 0 (mod ''p''), or two if ''a'' R ''p'' and gcd(''a,p'') = 1.) In general if a composite modulus ''n'' is written as a product of powers of distinct primes, and there are ''n''1 roots modulo the first one, ''n''2 mod the second, ..., there will be ''n''1''n''2... roots modulo ''n''. The theoretical way solutions modulo the prime powers are combined to make solutions modulo ''n'' is called theFor example: :Solve x2 ≡ 6 (mod 15). ::x2 ≡ 6 (mod 3) has one solution, 0; x2 ≡ 6 (mod 5) has two, 1 and 4. :: and there are two solutions modulo 15, namely 6 and 9. :Solve x2 ≡ 4 (mod 15). ::x2 ≡ 4 (mod 3) has two solutions, 1 and 2; x2 ≡ 4 (mod 5) has two, 2 and 3. :: and there are four solutions modulo 15, namely 2, 7, 8, and 13. :Solve x2 ≡ 7 (mod 15). ::x2 ≡ 7 (mod 3) has two solutions, 1 and 2; x2 ≡ 7 (mod 5) has no solutions. :: and there are no solutions modulo 15.
Prime or prime power modulus
First off, if the modulus ''n'' is prime the Legendre symbol can be quickly computed using a variation of Euclid's algorithm or theComposite modulus
If the modulus ''n'' has been factored into prime powers the solution was discussed above. If ''n'' is not congruent to 2 modulo 4 and the Kronecker symbol then there is no solution; if ''n'' is congruent to 2 modulo 4 and , then there is also no solution. If ''n'' is not congruent to 2 modulo 4 and , or ''n'' is congruent to 2 modulo 4 and , there may or may not be one. If the complete factorization of ''n'' is not known, and and ''n'' is not congruent to 2 modulo 4, or ''n'' is congruent to 2 modulo 4 and , the problem is known to be equivalent to integer factorization of ''n'' (i.e. an efficient solution to either problem could be used to solve the other efficiently).The above discussion indicates how knowing the factors of ''n'' allows us to find the roots efficiently. Say there were an efficient algorithm for finding square roots modulo a composite number. The article congruence of squares discusses how finding two numbers x and y where and suffices to factorize ''n'' efficiently. Generate a random number, square it modulo ''n'', and have the efficient square root algorithm find a root. Repeat until it returns a number not equal to the one we originally squared (or its negative modulo ''n''), then follow the algorithm described in congruence of squares. The efficiency of the factoring algorithm depends on the exact characteristics of the root-finder (e.g. does it return all roots? just the smallest one? a random one?), but it will be efficient.Determining whether ''a'' is a quadratic residue or nonresidue modulo ''n'' (denoted or ) can be done efficiently for prime ''n'' by computing the Legendre symbol. However, for composite ''n'', this forms the quadratic residuosity problem, which is not known to be as hard as factorization, but is assumed to be quite hard. On the other hand, if we want to know if there is a solution for ''x'' less than some given limit ''c'', this problem is NP-complete; however, this is a fixed-parameter tractable problem, where ''c'' is the parameter. In general, to determine if ''a'' is a quadratic residue modulo composite ''n'', one can use the following theorem: Let , and . Then is solvable if and only if: * The Legendre symbol for all odd prime divisors ''p'' of ''n''. * if ''n'' is divisible by 4 but not 8; or if ''n'' is divisible by 8. Note: This theorem essentially requires that the factorization of ''n'' is known. Also notice that if , then the congruence can be reduced to , but then this takes the problem away from quadratic residues (unless ''m'' is a square).
The number of quadratic residues
The list of the number of quadratic residues modulo ''n'', for ''n'' = 1, 2, 3 ..., looks like: :1, 2, 2, 2, 3, 4, 4, 3, 4, 6, 6, 4, 7, 8, 6, ... A formula to count the number of squares modulo ''n'' is given by Stangl.Applications of quadratic residues
Acoustics
Sound diffusers have been based on number-theoretic concepts such as primitive roots and quadratic residues.Graph theory
Paley graphs are dense undirected graphs, one for each prime ''p'' ≡ 1 (mod 4), that form an infinite family of conference graphs, which yield an infinite family of symmetric conference matrices. Paley digraphs are directed analogs of Paley graphs, one for each ''p'' ≡ 3 (mod 4), that yield antisymmetric conference matrices. The construction of these graphs uses quadratic residues.Cryptography
The fact that finding a square root of a number modulo a large composite ''n'' is equivalent to factoring (which is widely believed to be a hard problem) has been used for constructing cryptographic schemes such as the Rabin cryptosystem and the oblivious transfer. The quadratic residuosity problem is the basis for the Goldwasser-Micali cryptosystem. The discrete logarithm is a similar problem that is also used in cryptography.Primality testing
Integer factorization
In § VI of the ''Disquisitiones Arithmeticae''Gauss, DA, arts 329–334 Gauss discusses two factoring algorithms that use quadratic residues and the law of quadratic reciprocity. Several modern factorization algorithms (including Dixon's algorithm, the continued fraction method, the quadratic sieve, and the number field sieve) generate small quadratic residues (modulo the number being factorized) in an attempt to find a congruence of squares which will yield a factorization. The number field sieve is the fastest general-purpose factorization algorithm known.Table of quadratic residues
The following table lists the quadratic residues mod 1 to 75 (a means it is not coprime to ''n''). (For the quadratic residues coprime to ''n'', see , and for nonzero quadratic residues, see .)See also
*Notes
References
The '' Disquisitiones Arithmeticae'' has been translated from Gauss's Ciceronian Latin into English and German. The German edition includes all of his papers on number theory: all the proofs of quadratic reciprocity, the determination of the sign of the Gauss sum, the investigations into biquadratic reciprocity, and unpublished notes. * * * * * * A7.1: AN1, pg.249. * * * *External links
* * {{DEFAULTSORT:Quadratic Residue Modular arithmetic NP-complete problems