galois.jacobi_symbol(a: int, n: int) int

Computes the Jacobi symbol (an).

Parameters:
a: int

An integer.

n: int

An odd integer n3.

Returns:

The Jacobi symbol (an) with value in {0,1,1}.

Notes

The Jacobi symbol extends the Legendre symbol for odd n3. Unlike the Legendre symbol, (an)=1 does not imply a is a quadratic residue modulo n. However, all aQn have (an)=1.

References

Examples

The quadratic residues modulo 9 are Q9={1,4,7} and these all satisfy (a9)=1. The quadratic non-residues modulo 9 are Q9={2,3,5,6,8}, but notice {2,5,8} also satisfy (a9)=1. The set of integers {3,6} not coprime to 9 satisfies (a9)=0.

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