# Documentation

Mathlib.Tactic.NormNum.LegendreSymbol

# A norm_num extension for Jacobi and Legendre symbols #

We extend the norm_num tactic so that it can be used to provably compute the value of the Jacobi symbol J(a | b) or the Legendre symbol legendreSym p a when the arguments are numerals.

## Implementation notes #

We use the Law of Quadratic Reciprocity for the Jacobi symbol to compute the value of J(a | b) efficiently, roughly comparable in effort with the euclidean algorithm for the computation of the gcd of a and b. More precisely, the computation is done in the following steps.

• Use J(a | 0) = 1 (an artifact of the definition) and J(a | 1) = 1 to deal with corner cases.

• Use J(a | b) = J(a % b | b) to reduce to the case that a is a natural number. We define a version of the Jacobi symbol restricted to natural numbers for use in the following steps; see NormNum.jacobiSymNat. (But we'll continue to write J(a | b) in this description.)

• Remove powers of two from b. This is done via J(2a | 2b) = 0 and J(2a+1 | 2b) = J(2a+1 | b) (another artifact of the definition).

• Now 0 ≤ a < b and b is odd. If b = 1, then the value is 1. If a = 0 (and b > 1), then the value is 0. Otherwise, we remove powers of two from a via J(4a | b) = J(a | b) and J(2a | b) = ±J(a | b), where the sign is determined by the residue class of b mod 8, to reduce to a odd.

• Once a is odd, we use Quadratic Reciprocity (QR) in the form J(a | b) = ±J(b % a | a), where the sign is determined by the residue classes of a and b mod 4. We are then back in the previous case.

We provide customized versions of these results for the various reduction steps, where we encode the residue classes mod 2, mod 4, or mod 8 by using hypotheses like a % n = b. In this way, the only divisions we have to compute and prove are the ones occurring in the use of QR above.

The Jacobi symbol restricted to natural numbers in both arguments.

Instances For

### API Lemmas #

We repeat part of the API for jacobiSym with NormNum.jacobiSymNat and without implicit arguments, in a form that is suitable for constructing proofs in norm_num.

Base cases: b = 0, b = 1, a = 0, a = 1.

theorem Mathlib.Meta.NormNum.LegendreSym.to_jacobiSym (p : ) (pp : Fact ()) (a : ) (r : ) (hr : ) :

Turn a Legendre symbol into a Jacobi symbol.

theorem Mathlib.Meta.NormNum.JacobiSym.mod_left (a : ) (b : ) (ab' : ) (ab : ) (r : ) (b' : ) (hb' : b = b') (hab : a % b' = ab) (h : ab' = ab) (hr : ) :
= r

The value depends only on the residue class of a mod b.

theorem Mathlib.Meta.NormNum.jacobiSymNat.mod_left (a : ) (b : ) (ab : ) (r : ) (hab : a % b = ab) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.even_even (a : ) (b : ) (hb₀ : Nat.beq (b / 2) 0 = false) (ha : a % 2 = 0) (hb₁ : b % 2 = 0) :

The symbol vanishes when both entries are even (and b / 2 ≠ 0).

theorem Mathlib.Meta.NormNum.jacobiSymNat.odd_even (a : ) (b : ) (c : ) (r : ) (ha : a % 2 = 1) (hb : b % 2 = 0) (hc : b / 2 = c) (hr : ) :

When a is odd and b is even, we can replace b by b / 2.

theorem Mathlib.Meta.NormNum.jacobiSymNat.double_even (a : ) (b : ) (c : ) (r : ) (ha : a % 4 = 0) (hb : b % 2 = 1) (hc : a / 4 = c) (hr : ) :

If a is divisible by 4 and b is odd, then we can remove the factor 4 from a.

theorem Mathlib.Meta.NormNum.jacobiSymNat.even_odd₁ (a : ) (b : ) (c : ) (r : ) (ha : a % 2 = 0) (hb : b % 8 = 1) (hc : a / 2 = c) (hr : ) :

If a is even and b is odd, then we can remove a factor 2 from a, but we may have to change the sign, depending on b % 8. We give one version for each of the four odd residue classes mod 8.

theorem Mathlib.Meta.NormNum.jacobiSymNat.even_odd₇ (a : ) (b : ) (c : ) (r : ) (ha : a % 2 = 0) (hb : b % 8 = 7) (hc : a / 2 = c) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.even_odd₃ (a : ) (b : ) (c : ) (r : ) (ha : a % 2 = 0) (hb : b % 8 = 3) (hc : a / 2 = c) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.even_odd₅ (a : ) (b : ) (c : ) (r : ) (ha : a % 2 = 0) (hb : b % 8 = 5) (hc : a / 2 = c) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁ (a : ) (b : ) (r : ) (ha : a % 4 = 1) (hb : b % 2 = 1) (hr : ) :

Use quadratic reciproity to reduce to smaller b.

theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁_mod (a : ) (b : ) (ab : ) (r : ) (ha : a % 4 = 1) (hb : b % 2 = 1) (hab : b % a = ab) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁' (a : ) (b : ) (r : ) (ha : a % 2 = 1) (hb : b % 4 = 1) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁'_mod (a : ) (b : ) (ab : ) (r : ) (ha : a % 2 = 1) (hb : b % 4 = 1) (hab : b % a = ab) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₃ (a : ) (b : ) (r : ) (ha : a % 4 = 3) (hb : b % 4 = 3) (hr : ) :
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₃_mod (a : ) (b : ) (ab : ) (r : ) (ha : a % 4 = 3) (hb : b % 4 = 3) (hab : b % a = ab) (hr : ) :
theorem Mathlib.Meta.NormNum.isInt_jacobiSym {a : } {na : } {b : } {nb : } {r : } :
jacobiSym na nb = r
theorem Mathlib.Meta.NormNum.isInt_jacobiSymNat {a : } {na : } {b : } {nb : } {r : } :

### Certified evaluation of the Jacobi symbol #

The following functions recursively evaluate a Jacobi symbol and construct the corresponding proof term.

### The norm_num plug-in #

This is the norm_num plug-in that evaluates Jacobi symbols.

Instances For

This is the norm_num plug-in that evaluates Jacobi symbols on natural numbers.

Instances For

This is the norm_num plug-in that evaluates Legendre symbols.

Instances For