- galois.jacobi_symbol(a: int, n: int) int
Computes the Jacobi symbol
.See also
Notes¶
The Jacobi symbol extends the Legendre symbol for odd
. Unlike the Legendre symbol, does not imply is a quadratic residue modulo . However, all have .References¶
Algorithm 2.149 from https://cacr.uwaterloo.ca/hac/about/chap2.pdf
Examples¶
The quadratic residues modulo 9 are
and these all satisfy . The quadratic non-residues modulo 9 are , but notice also satisfy . The set of integers not coprime to 9 satisfies .In [1]: [pow(x, 2, 9) for x in range(9)] Out[1]: [0, 1, 4, 0, 7, 7, 0, 4, 1] In [2]: for a in range(9): ...: print(f"({a} / 9) = {galois.jacobi_symbol(a, 9)}") ...: (0 / 9) = 0 (1 / 9) = 1 (2 / 9) = 1 (3 / 9) = 0 (4 / 9) = 1 (5 / 9) = 1 (6 / 9) = 0 (7 / 9) = 1 (8 / 9) = 1