The areas / V34. The tactics of Mathlib
Mathlib.Tactic.NormNum.LegendreSymbol
29 declarations. Mathlib docs · Source
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) andJ(a | 1) = 1to deal with corner cases. -
Use
J(a | b) = J(a % b | b)to reduce to the case thatais a natural number. We define a version of the Jacobi symbol restricted to natural numbers for use in the following steps; seeNormNum.jacobiSymNat. (But we'll continue to writeJ(a | b)in this description.) -
Remove powers of two from
b. This is done viaJ(2a | 2b) = 0andJ(2a+1 | 2b) = J(2a+1 | b)(another artifact of the definition). -
Now
0 ≤ a < bandbis odd. Ifb = 1, then the value is1. Ifa = 0(andb > 1), then the value is0. Otherwise, we remove powers of two fromaviaJ(4a | b) = J(a | b)andJ(2a | b) = ±J(a | b), where the sign is determined by the residue class ofbmod 8, to reduce toaodd. -
Once
ais odd, we use Quadratic Reciprocity (QR) in the formJ(a | b) = ±J(b % a | a), where the sign is determined by the residue classes ofaandbmod 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.
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.
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
def Mathlib.Meta.NormNum.jacobiSymNat E1 #
ℕ → ℕ → ℤ
The Jacobi symbol restricted to natural numbers in both arguments.
theorem Mathlib.Meta.NormNum.jacobiSymNat.zero_right E1 #
∀ (a : ℕ), Mathlib.Meta.NormNum.jacobiSymNat a 0 = 1
Base cases: b = 0, b = 1, a = 0, a = 1.
theorem Mathlib.Meta.NormNum.jacobiSymNat.one_right E1 #
∀ (a : ℕ), Mathlib.Meta.NormNum.jacobiSymNat a 1 = 1
theorem Mathlib.Meta.NormNum.jacobiSymNat.zero_left E1 #
∀ (b : ℕ), (b / 2).beq 0 = false → Mathlib.Meta.NormNum.jacobiSymNat 0 b = 0
theorem Mathlib.Meta.NormNum.jacobiSymNat.one_left E1 #
∀ (b : ℕ), Mathlib.Meta.NormNum.jacobiSymNat 1 b = 1
theorem Mathlib.Meta.NormNum.LegendreSym.to_jacobiSym E1 #
∀ (p : ℕ) (pp : Fact (Nat.Prime p)) (a r : ℤ),
Mathlib.Meta.NormNum.IsInt (jacobiSym a p) r → Mathlib.Meta.NormNum.IsInt (legendreSym p a) r
Turn a Legendre symbol into a Jacobi symbol.
theorem Mathlib.Meta.NormNum.JacobiSym.mod_left E1 #
∀ (a : ℤ) (b ab' : ℕ) (ab r b' : ℤ),
↑b = b' → a % b' = ab → ↑ab' = ab → Mathlib.Meta.NormNum.jacobiSymNat ab' b = r → jacobiSym a b = r
The value depends only on the residue class of a mod b.
theorem Mathlib.Meta.NormNum.jacobiSymNat.mod_left E1 #
∀ (a b ab : ℕ) (r : ℤ),
a % b = ab → Mathlib.Meta.NormNum.jacobiSymNat ab b = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
theorem Mathlib.Meta.NormNum.jacobiSymNat.even_even E1 #
∀ (a b : ℕ), (b / 2).beq 0 = false → a % 2 = 0 → b % 2 = 0 → Mathlib.Meta.NormNum.jacobiSymNat a b = 0
The symbol vanishes when both entries are even (and b / 2 ≠ 0).
theorem Mathlib.Meta.NormNum.jacobiSymNat.odd_even E1 #
∀ (a b c : ℕ) (r : ℤ),
a % 2 = 1 →
b % 2 = 0 → b / 2 = c → Mathlib.Meta.NormNum.jacobiSymNat a c = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
When a is odd and b is even, we can replace b by b / 2.
theorem Mathlib.Meta.NormNum.jacobiSymNat.double_even E1 #
∀ (a b c : ℕ) (r : ℤ),
a % 4 = 0 →
b % 2 = 1 → a / 4 = c → Mathlib.Meta.NormNum.jacobiSymNat c b = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
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₁ E1 #
∀ (a b c : ℕ) (r : ℤ),
a % 2 = 0 →
b % 8 = 1 → a / 2 = c → Mathlib.Meta.NormNum.jacobiSymNat c b = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
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₇ E1 #
∀ (a b c : ℕ) (r : ℤ),
a % 2 = 0 →
b % 8 = 7 → a / 2 = c → Mathlib.Meta.NormNum.jacobiSymNat c b = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
theorem Mathlib.Meta.NormNum.jacobiSymNat.even_odd₃ E1 #
∀ (a b c : ℕ) (r : ℤ),
a % 2 = 0 →
b % 8 = 3 → a / 2 = c → Mathlib.Meta.NormNum.jacobiSymNat c b = r → Mathlib.Meta.NormNum.jacobiSymNat a b = -r
theorem Mathlib.Meta.NormNum.jacobiSymNat.even_odd₅ E1 #
∀ (a b c : ℕ) (r : ℤ),
a % 2 = 0 →
b % 8 = 5 → a / 2 = c → Mathlib.Meta.NormNum.jacobiSymNat c b = r → Mathlib.Meta.NormNum.jacobiSymNat a b = -r
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁ E1 #
∀ (a b : ℕ) (r : ℤ),
a % 4 = 1 → b % 2 = 1 → Mathlib.Meta.NormNum.jacobiSymNat b a = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
Use quadratic reciprocity to reduce to smaller b.
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁_mod E1 #
∀ (a b ab : ℕ) (r : ℤ),
a % 4 = 1 →
b % 2 = 1 → b % a = ab → Mathlib.Meta.NormNum.jacobiSymNat ab a = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁' E1 #
∀ (a b : ℕ) (r : ℤ),
a % 2 = 1 → b % 4 = 1 → Mathlib.Meta.NormNum.jacobiSymNat b a = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₁'_mod E1 #
∀ (a b ab : ℕ) (r : ℤ),
a % 2 = 1 →
b % 4 = 1 → b % a = ab → Mathlib.Meta.NormNum.jacobiSymNat ab a = r → Mathlib.Meta.NormNum.jacobiSymNat a b = r
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₃ E1 #
∀ (a b : ℕ) (r : ℤ),
a % 4 = 3 → b % 4 = 3 → Mathlib.Meta.NormNum.jacobiSymNat b a = r → Mathlib.Meta.NormNum.jacobiSymNat a b = -r
theorem Mathlib.Meta.NormNum.jacobiSymNat.qr₃_mod E1 #
∀ (a b ab : ℕ) (r : ℤ),
a % 4 = 3 →
b % 4 = 3 → b % a = ab → Mathlib.Meta.NormNum.jacobiSymNat ab a = r → Mathlib.Meta.NormNum.jacobiSymNat a b = -r
theorem Mathlib.Meta.NormNum.isInt_jacobiSym E1 #
∀ {a na : ℤ} {b nb : ℕ} {r : ℤ},
Mathlib.Meta.NormNum.IsInt a na →
Mathlib.Meta.NormNum.IsNat b nb → jacobiSym na nb = r → Mathlib.Meta.NormNum.IsInt (jacobiSym a b) r
theorem Mathlib.Meta.NormNum.isInt_jacobiSymNat E1 #
∀ {a na b nb : ℕ} {r : ℤ},
Mathlib.Meta.NormNum.IsNat a na →
Mathlib.Meta.NormNum.IsNat b nb →
Mathlib.Meta.NormNum.jacobiSymNat na nb = r → Mathlib.Meta.NormNum.IsInt (Mathlib.Meta.NormNum.jacobiSymNat a b) r
opaque Mathlib.Meta.NormNum.proveJacobiSymOdd E1 #
(ea eb : Q(ℕ)) → (er : Q(ℤ)) × Q(Mathlib.Meta.NormNum.jacobiSymNat «$ea» «$eb» = «$er»)
This evaluates r := jacobiSymNat a b recursively using quadratic reciprocity
and produces a proof term for the equality, assuming that a < b and b is odd.
def Mathlib.Meta.NormNum.proveJacobiSymNat E1 #
(ea eb : Q(ℕ)) → (er : Q(ℤ)) × Q(Mathlib.Meta.NormNum.jacobiSymNat «$ea» «$eb» = «$er»)
This evaluates r := jacobiSymNat a b and produces a proof term for the equality
by removing powers of 2 from b and then calling proveJacobiSymOdd.
def Mathlib.Meta.NormNum.proveJacobiSym E1 #
(ea : Q(ℤ)) → (eb : Q(ℕ)) → (er : Q(ℤ)) × Q(jacobiSym «$ea» «$eb» = «$er»)
This evaluates r := jacobiSym a b and produces a proof term for the equality.
This is done by reducing to r := jacobiSymNat (a % b) b.
def Tactic.NormNum.evalJacobiSym E1 #
Mathlib.Meta.NormNum.NormNumExt
This is the norm_num plug-in that evaluates Jacobi symbols.
def Tactic.NormNum.evalJacobiSymNat E1 #
Mathlib.Meta.NormNum.NormNumExt
This is the norm_num plug-in that evaluates Jacobi symbols on natural numbers.
def Tactic.NormNum.evalLegendreSym E1 #
Mathlib.Meta.NormNum.NormNumExt
This is the norm_num plug-in that evaluates Legendre symbols.