The areas / V12. Number theory
Mathlib.NumberTheory.LegendreSymbol.JacobiSymbol
46 declarations. Mathlib docs · Source
The Jacobi Symbol
We define the Jacobi symbol and prove its main properties.
Main definitions
We define the Jacobi symbol, jacobiSym a b, for integers a and natural numbers b
as the product over the prime factors p of b of the Legendre symbols legendreSym p a.
This agrees with the mathematical definition when b is odd.
The prime factors are obtained via Nat.factors. Since Nat.factors 0 = [],
this implies in particular that jacobiSym a 0 = 1 for all a.
Main statements
We prove the main properties of the Jacobi symbol, including the following.
-
Multiplicativity in both arguments (
jacobiSym.mul_left,jacobiSym.mul_right) -
The value of the symbol is
1or-1when the arguments are coprime (jacobiSym.eq_one_or_neg_one) -
The symbol vanishes if and only if
b ≠ 0and the arguments are not coprime (jacobiSym.eq_zero_iff_not_coprime) -
If the symbol has the value
-1, thena : ZMod bis not a square (ZMod.nonsquare_of_jacobiSym_eq_neg_one); the converse holds whenb = pis a prime (ZMod.nonsquare_iff_jacobiSym_eq_neg_one); in particular, in this caseais a square modpwhen the symbol has the value1(ZMod.isSquare_of_jacobiSym_eq_one). -
Quadratic reciprocity (
jacobiSym.quadratic_reciprocity,jacobiSym.quadratic_reciprocity_one_mod_four,jacobiSym.quadratic_reciprocity_three_mod_four) -
The supplementary laws for
a = -1,a = 2,a = -2(jacobiSym.at_neg_one,jacobiSym.at_two,jacobiSym.at_neg_two) -
The symbol depends on
aonly via its residue class modb(jacobiSym.mod_left) and onbonly via its residue class mod4*a(jacobiSym.mod_right) -
A
csimprule forjacobiSymandlegendreSymthat evaluatesJ(a | b)efficiently by reducing to the case0 ≤ a < banda,bodd, and then swapsa,band recurses using quadratic reciprocity.
Notation
We define the notation J(a | b) for jacobiSym a b, localized to NumberTheorySymbols.
Tags
Jacobi symbol, quadratic reciprocity
Definition of the Jacobi symbol
We define the Jacobi symbol $\Bigl(\frac{a}{b}\Bigr)$ for integers a and natural numbers b
as the product of the Legendre symbols $\Bigl(\frac{a}{p}\Bigr)$, where p runs through the
prime divisors (with multiplicity) of b, as provided by b.factors. This agrees with the
Jacobi symbol when b is odd and gives less meaningful values when it is not (e.g., the symbol
is 1 when b = 0). This is called jacobiSym a b.
We define localized notation (scope NumberTheorySymbols) J(a | b) for the Jacobi
symbol jacobiSym a b.
Properties of the Jacobi symbol
Values at -1, 2 and -2
Quadratic Reciprocity
Fast computation of the Jacobi symbol
We follow the implementation as in Mathlib/Tactic/NormNum/LegendreSymbol.lean.
def jacobiSym E3 #
ℤ → ℕ → ℤ
The Jacobi symbol of a and b
def NumberTheorySymbols.«termJ(_|_)» E1 #
Lean.ParserDescr
The Jacobi symbol of a and b
theorem jacobiSym.zero_right E0 #
∀ (a : ℤ), jacobiSym a 0 = 1
The symbol J(a | 0) has the value 1.
theorem jacobiSym.one_right E0 #
∀ (a : ℤ), jacobiSym a 1 = 1
The symbol J(a | 1) has the value 1.
theorem jacobiSym.legendreSym.to_jacobiSym E1 #
∀ (p : ℕ) [fp : Fact (Nat.Prime p)] (a : ℤ), legendreSym p a = jacobiSym a p
The Legendre symbol legendreSym p a with an integer a and a prime number p
is the same as the Jacobi symbol J(a | p).
theorem jacobiSym.mul_right' E1 #
∀ (a : ℤ) {b₁ b₂ : ℕ}, b₁ ≠ 0 → b₂ ≠ 0 → jacobiSym a (b₁ * b₂) = jacobiSym a b₁ * jacobiSym a b₂
The Jacobi symbol is multiplicative in its second argument.
theorem jacobiSym.mul_right E3 #
∀ (a : ℤ) (b₁ b₂ : ℕ) [NeZero b₁] [NeZero b₂], jacobiSym a (b₁ * b₂) = jacobiSym a b₁ * jacobiSym a b₂
The Jacobi symbol is multiplicative in its second argument.
theorem jacobiSym.trichotomy E1 #
∀ (a : ℤ) (b : ℕ), jacobiSym a b = 0 ∨ jacobiSym a b = 1 ∨ jacobiSym a b = -1
The Jacobi symbol takes only the values 0, 1 and -1.
theorem jacobiSym.one_left E0 #
∀ (b : ℕ), jacobiSym 1 b = 1
The symbol J(1 | b) has the value 1.
theorem jacobiSym.mul_left E3 #
∀ (a₁ a₂ : ℤ) (b : ℕ), jacobiSym (a₁ * a₂) b = jacobiSym a₁ b * jacobiSym a₂ b
The Jacobi symbol is multiplicative in its first argument.
theorem jacobiSym.ne_zero E1 #
∀ {a : ℤ} {b : ℕ}, a.gcd ↑b = 1 → jacobiSym a b ≠ 0
The symbol J(a | b) is nonzero when a and b are coprime.
theorem jacobiSym.zero_left E1 #
∀ {b : ℕ}, 1 < b → jacobiSym 0 b = 0
The symbol J(0 | b) vanishes when b > 1.
theorem jacobiSym.pow_left E1 #
∀ (a : ℤ) (e b : ℕ), jacobiSym (a ^ e) b = jacobiSym a b ^ e
We have that J(a^e | b) = J(a | b)^e.
theorem jacobiSym.pow_right E1 #
∀ (a : ℤ) (b e : ℕ), jacobiSym a (b ^ e) = jacobiSym a b ^ e
We have that J(a | b^e) = J(a | b)^e.
theorem jacobiSym.sq_one E1 #
∀ {a : ℤ} {b : ℕ}, a.gcd ↑b = 1 → jacobiSym a b ^ 2 = 1
The square of J(a | b) is 1 when a and b are coprime.
theorem jacobiSym.sq_one' E1 #
∀ {a : ℤ} {b : ℕ}, a.gcd ↑b = 1 → jacobiSym (a ^ 2) b = 1
The symbol J(a^2 | b) is 1 when a and b are coprime.
theorem jacobiSym.mod_left E3 #
∀ (a : ℤ) (b : ℕ), jacobiSym a b = jacobiSym (a % ↑b) b
The symbol J(a | b) depends only on a mod b.
theorem jacobiSym.mod_left' E1 #
∀ {a₁ a₂ : ℤ} {b : ℕ}, a₁ % ↑b = a₂ % ↑b → jacobiSym a₁ b = jacobiSym a₂ b
The symbol J(a | b) depends only on a mod b.
theorem jacobiSym.prime_dvd_of_eq_neg_one E1 #
∀ {p : ℕ} [Fact (Nat.Prime p)] {a : ℤ}, jacobiSym a p = -1 → ∀ {x y : ℤ}, ↑p ∣ x ^ 2 - a * y ^ 2 → ↑p ∣ x ∧ ↑p ∣ y
If p is prime, J(a | p) = -1 and p divides x^2 - a*y^2, then p must divide
x and y.
theorem jacobiSym.list_prod_left E1 #
∀ {l : List ℤ} {n : ℕ}, jacobiSym l.prod n = (List.map (fun a ↦ jacobiSym a n) l).prod
We can pull out a product over a list in the first argument of the Jacobi symbol.
theorem jacobiSym.list_prod_right E1 #
∀ {a : ℤ} {l : List ℕ}, (∀ n ∈ l, n ≠ 0) → jacobiSym a l.prod = (List.map (fun n ↦ jacobiSym a n) l).prod
We can pull out a product over a list in the second argument of the Jacobi symbol.
theorem ZMod.nonsquare_of_jacobiSym_eq_neg_one E3 #
∀ {a : ℤ} {b : ℕ}, jacobiSym a b = -1 → ¬IsSquare ↑a
If J(a | b) is -1, then a is not a square modulo b.
theorem ZMod.nonsquare_iff_jacobiSym_eq_neg_one E3 #
∀ {a : ℤ} {p : ℕ} [inst : Fact (Nat.Prime p)], jacobiSym a p = -1 ↔ ¬IsSquare ↑a
If p is prime, then J(a | p) is -1 iff a is not a square modulo p.
theorem ZMod.isSquare_of_jacobiSym_eq_one E3 #
∀ {a : ℤ} {p : ℕ} [inst : Fact (Nat.Prime p)], jacobiSym a p = 1 → IsSquare ↑a
If p is prime and J(a | p) = 1, then a is a square mod p.
theorem jacobiSym.value_at E1 #
∀ (a : ℤ) {R : Type u_1} [inst : Semiring R] (χ : R →* ℤ),
(∀ (p : ℕ) (pp : Nat.Prime p), p ≠ 2 → legendreSym p a = χ ↑p) → ∀ {b : ℕ}, Odd b → jacobiSym a b = χ ↑b
If χ is a multiplicative function such that J(a | p) = χ p for all odd primes p,
then J(a | b) equals χ b for all odd natural numbers b.
theorem jacobiSym.at_neg_one E3 #
∀ {b : ℕ}, Odd b → jacobiSym (-1) b = ZMod.χ₄ ↑b
If b is odd, then J(-1 | b) is given by χ₄ b.
theorem jacobiSym.neg E1 #
∀ (a : ℤ) {b : ℕ}, Odd b → jacobiSym (-a) b = ZMod.χ₄ ↑b * jacobiSym a b
If b is odd, then J(-a | b) = χ₄ b * J(a | b).
theorem jacobiSym.at_two E3 #
∀ {b : ℕ}, Odd b → jacobiSym 2 b = ZMod.χ₈ ↑b
If b is odd, then J(2 | b) is given by χ₈ b.
theorem jacobiSym.at_neg_two E3 #
∀ {b : ℕ}, Odd b → jacobiSym (-2) b = ZMod.χ₈' ↑b
If b is odd, then J(-2 | b) is given by χ₈' b.
theorem jacobiSym.div_four_left E1 #
∀ {a : ℤ} {b : ℕ}, a % 4 = 0 → b % 2 = 1 → jacobiSym (a / 4) b = jacobiSym a b
theorem jacobiSym.at_four E1 #
∀ {b : ℕ}, Odd b → jacobiSym 4 b = 1
If b is odd, then J(4 | b) = 1.
theorem jacobiSym.even_odd E1 #
∀ {a : ℤ} {b : ℕ},
a % 2 = 0 → b % 2 = 1 → (if b % 8 = 3 ∨ b % 8 = 5 then -jacobiSym (a / 2) b else jacobiSym (a / 2) b) = jacobiSym a b
def qrSign E1 #
ℕ → ℕ → ℤ
The bi-multiplicative map giving the sign in the Law of Quadratic Reciprocity
theorem qrSign.neg_one_pow E1 #
∀ {m n : ℕ}, Odd m → Odd n → qrSign m n = (-1) ^ (m / 2 * (n / 2))
We can express qrSign m n as a power of -1 when m and n are odd.
theorem qrSign.sq_eq_one E1 #
∀ {m n : ℕ}, Odd m → Odd n → qrSign m n ^ 2 = 1
When m and n are odd, then the square of qrSign m n is 1.
theorem qrSign.mul_left E1 #
∀ (m₁ m₂ n : ℕ), qrSign (m₁ * m₂) n = qrSign m₁ n * qrSign m₂ n
qrSign is multiplicative in the first argument.
theorem qrSign.mul_right E1 #
∀ (m n₁ n₂ : ℕ) [NeZero n₁] [NeZero n₂], qrSign m (n₁ * n₂) = qrSign m n₁ * qrSign m n₂
qrSign is multiplicative in the second argument.
theorem qrSign.symm E1 #
∀ {m n : ℕ}, Odd m → Odd n → qrSign m n = qrSign n m
qrSign is symmetric when both arguments are odd.
theorem jacobiSym.quadratic_reciprocity' E1 #
∀ {a b : ℕ}, Odd a → Odd b → jacobiSym (↑a) b = qrSign b a * jacobiSym (↑b) a
The Law of Quadratic Reciprocity for the Jacobi symbol, version with qrSign
theorem jacobiSym.quadratic_reciprocity E3 #
∀ {a b : ℕ}, Odd a → Odd b → jacobiSym (↑a) b = (-1) ^ (a / 2 * (b / 2)) * jacobiSym (↑b) a
The Law of Quadratic Reciprocity for the Jacobi symbol
theorem jacobiSym.quadratic_reciprocity_one_mod_four E3 #
∀ {a b : ℕ}, a % 4 = 1 → Odd b → jacobiSym (↑a) b = jacobiSym (↑b) a
The Law of Quadratic Reciprocity for the Jacobi symbol: if a and b are natural numbers
with a % 4 = 1 and b odd, then J(a | b) = J(b | a).
theorem jacobiSym.quadratic_reciprocity_one_mod_four' E1 #
∀ {a b : ℕ}, Odd a → b % 4 = 1 → jacobiSym (↑a) b = jacobiSym (↑b) a
The Law of Quadratic Reciprocity for the Jacobi symbol: if a and b are natural numbers
with a odd and b % 4 = 1, then J(a | b) = J(b | a).
theorem jacobiSym.quadratic_reciprocity_three_mod_four E3 #
∀ {a b : ℕ}, a % 4 = 3 → b % 4 = 3 → jacobiSym (↑a) b = -jacobiSym (↑b) a
The Law of Quadratic Reciprocity for the Jacobi symbol: if a and b are natural numbers
both congruent to 3 mod 4, then J(a | b) = -J(b | a).
theorem jacobiSym.quadratic_reciprocity_if E1 #
∀ {a b : ℕ},
a % 2 = 1 → b % 2 = 1 → (if a % 4 = 3 ∧ b % 4 = 3 then -jacobiSym (↑b) a else jacobiSym (↑b) a) = jacobiSym (↑a) b
theorem jacobiSym.mod_right' E1 #
∀ (a : ℕ) {b : ℕ}, Odd b → jacobiSym (↑a) b = jacobiSym (↑a) (b % (4 * a))
The Jacobi symbol J(a | b) depends only on b mod 4*a (version for a : ℕ).
theorem jacobiSym.mod_right E3 #
∀ (a : ℤ) {b : ℕ}, Odd b → jacobiSym a b = jacobiSym a (b % (4 * a.natAbs))
The Jacobi symbol J(a | b) depends only on b mod 4*a.