Function of #cas

jacobiSymbol

The Jacobi symbol (a/n) of an integer and an odd natural number, with a theorem about Mathlib’s jacobiSym.

#cas (jacobiSymbol a n)
gives the Jacobi symbol (a / n) of the integer a and the odd natural number n, one of −1, 0 and 1, and proves jacobiSym a n = j.

jacobiSymbol computes the Jacobi symbol, and what it’s good for is ruling out squares modulo an odd integer. For a prime n it is the Legendre symbol. For every odd n the value −1 proves that a is not a square modulo n, but for a composite n the value 1 proves nothing of the kind, as Possible Issues shows.

Details and Options

  • a is an integer and n an odd natural number, literals or closed integer expressions.
  • The theorem is jacobiSym a n = j for Mathlib’s jacobiSym, by CAS.NumberTheory.Jacobi.jacobiSym_eq_of_loop. The kernel runs a loop that takes out factors 2 with the value of (2/n) and otherwise swaps the arguments by quadratic reciprocity.
  • (a/1)=1, and j=0 exactly when gcd(a,n)>1.
  • For every odd n, j=−1 shows that a is not a square modulo n, by ZMod.nonsquare_of_jacobiSym_eq_neg_one.
  • In a proof, cas proves jacobiSym a n = j for odd n by the same run of the loop.
  • The call is evaluated when it is the whole input of #cas.
  • There are no options.

Examples (7)#

Basic Examples (1)

The symbol (1001/9907), with the theorem that the kernel checked:

In[1]:=
#cas (jacobiSymbol 1001 9907)
Out[1]=

Jacobi symbol

-1
Domain
ℤ × ℕ
Input (an integer and an odd natural number)
(1001 / 9907)

Checked by Lean’s kernel: Jacobi symbol

jacobiSym 1001 9907 = -1
The certificate: 1 checked step
  1. Jacobi symbol

    jacobiSym 1001 9907 = -1

    Checked by Lean’s kernel

Scope (2)

The integer may be negative. For an odd prime p, (−1/p)=−1 exactly when p≡3(mod4):

In[2]:=
#cas (jacobiSymbol (-1) 7)
Out[2]=

Jacobi symbol

-1
Domain
ℤ × ℕ
Input (an integer and an odd natural number)
(-1 / 7)

Checked by Lean’s kernel: Jacobi symbol

jacobiSym (-1) 7 = -1
The certificate: 1 checked step
  1. Jacobi symbol

    jacobiSym (-1) 7 = -1

    Checked by Lean’s kernel


The symbol is 0 exactly when gcd(a,n)>1, here gcd(6,9)=3:

In[3]:=
#cas (jacobiSymbol 6 9)
Out[3]=

Jacobi symbol

0
Domain
ℤ × ℕ
Input (an integer and an odd natural number)
(6 / 9)

Checked by Lean’s kernel: Jacobi symbol

jacobiSym 6 9 = 0
The certificate: 1 checked step
  1. Jacobi symbol

    jacobiSym 6 9 = 0

    Checked by Lean’s kernel

Applications (1)

ZMod.nonsquare_of_jacobiSym_eq_neg_one turns the value −1 into a statement about squares, and cas proves the value. Only the three standard axioms are used:

In[4]:=
theorem not_square_mod_9907 : ¬IsSquare ((1001 : ℤ) : ZMod 9907) :=
  ZMod.nonsquare_of_jacobiSym_eq_neg_one (by cas)

#print axioms not_square_mod_9907
Out[4]=

not_square_mod_9907 depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (1)

For an odd prime p, Euler’s criterion a(p−1)/2≡(a/p)(modp) relates the symbol to powerMod. For a=2 and p=7, 23=8≡1, and indeed 32=9≡2, so 2 is a square modulo 7:

In[5]:=
#cas (jacobiSymbol 2 7)
Out[5]=

Jacobi symbol

1
Domain
ℤ × ℕ
Input (an integer and an odd natural number)
(2 / 7)

Checked by Lean’s kernel: Jacobi symbol

jacobiSym 2 7 = 1
The certificate: 1 checked step
  1. Jacobi symbol

    jacobiSym 2 7 = 1

    Checked by Lean’s kernel

Possible Issues (2)

For a composite n the value 1 does not make a a square modulo n. (2/15)=(2/3)(2/5)=(−1)(−1)=1, while the squares modulo 15 are 0, 1, 4, 6, 9 and 10:

In[6]:=
#cas (jacobiSymbol 2 15)
Out[6]=

Jacobi symbol

1
Domain
ℤ × ℕ
Input (an integer and an odd natural number)
(2 / 15)

Checked by Lean’s kernel: Jacobi symbol

jacobiSym 2 15 = 1
The certificate: 1 checked step
  1. Jacobi symbol

    jacobiSym 2 15 = 1

    Checked by Lean’s kernel


The Jacobi symbol is defined for odd n. Mathlib’s jacobiSym takes every natural number and agrees with the symbol when n is odd, and the call takes only odd n:

In[7]:=
#cas (jacobiSymbol 2 4)
Out[7]=

Error

jacobiSymbol: expected an odd natural number

See Also

powerMod · primeQ · modularInverse