- galois.legendre_symbol(a: int, p: int) int
Computes the Legendre symbol
.See also
Notes¶
The Legendre symbol is useful for determining if
is a quadratic residue modulo , namely . A quadratic residue modulo satisfies for some .References¶
Algorithm 2.149 from https://cacr.uwaterloo.ca/hac/about/chap2.pdf
Examples¶
The quadratic residues modulo 7 are
. The quadratic non-residues modulo 7 are .In [1]: [pow(x, 2, 7) for x in range(7)] Out[1]: [0, 1, 4, 2, 2, 4, 1] In [2]: for a in range(7): ...: print(f"({a} / 7) = {galois.legendre_symbol(a, 7)}") ...: (0 / 7) = 0 (1 / 7) = 1 (2 / 7) = 1 (3 / 7) = -1 (4 / 7) = 1 (5 / 7) = -1 (6 / 7) = -1