fact
stringlengths
6
3.84k
type
stringclasses
11 values
library
stringclasses
32 values
imports
listlengths
1
14
filename
stringlengths
20
95
symbolic_name
stringlengths
1
90
docstring
stringlengths
7
20k
Int.sq_ne_two_mod_four (z : ℤ) : z * z % 4 ≠ 2 := by suffices ¬z * z % (4 : ℕ) = 2 % (4 : ℕ) by exact this rw [← ZMod.intCast_eq_intCast_iff'] simpa using sq_ne_two_fin_zmod_four _ noncomputable section
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
Int.sq_ne_two_mod_four
null
PythagoreanTriple (x y z : ℤ) : Prop := x * x + y * y = z * z
def
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
PythagoreanTriple
Three integers `x`, `y`, and `z` form a Pythagorean triple if `x * x + y * y = z * z`.
pythagoreanTriple_comm {x y z : ℤ} : PythagoreanTriple x y z ↔ PythagoreanTriple y x z := by delta PythagoreanTriple rw [add_comm]
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
pythagoreanTriple_comm
Pythagorean triples are interchangeable, i.e `x * x + y * y = y * y + x * x = z * z`. This comes from additive commutativity.
PythagoreanTriple.zero : PythagoreanTriple 0 0 0 := by simp only [PythagoreanTriple, zero_mul, zero_add]
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
PythagoreanTriple.zero
The zeroth Pythagorean triple is all zeros.
eq (h : PythagoreanTriple x y z) : x * x + y * y = z * z := h @[symm]
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
eq
null
symm (h : PythagoreanTriple x y z) : PythagoreanTriple y x z := by rwa [pythagoreanTriple_comm]
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
symm
null
mul (h : PythagoreanTriple x y z) (k : ℤ) : PythagoreanTriple (k * x) (k * y) (k * z) := calc k * x * (k * x) + k * y * (k * y) = k ^ 2 * (x * x + y * y) := by ring _ = k ^ 2 * (z * z) := by rw [h.eq] _ = k * z * (k * z) := by ring
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
mul
A triple is still a triple if you multiply `x`, `y` and `z` by a constant `k`.
mul_iff (k : ℤ) (hk : k ≠ 0) : PythagoreanTriple (k * x) (k * y) (k * z) ↔ PythagoreanTriple x y z := by refine ⟨?_, fun h => h.mul k⟩ simp only [PythagoreanTriple] intro h rw [← mul_left_inj' (mul_ne_zero hk hk)] convert h using 1 <;> ring
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
mul_iff
`(k*x, k*y, k*z)` is a Pythagorean triple if and only if `(x, y, z)` is also a triple.
@[nolint unusedArguments] IsClassified (_ : PythagoreanTriple x y z) := ∃ k m n : ℤ, (x = k * (m ^ 2 - n ^ 2) ∧ y = k * (2 * m * n) ∨ x = k * (2 * m * n) ∧ y = k * (m ^ 2 - n ^ 2)) ∧ Int.gcd m n = 1
def
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
IsClassified
A Pythagorean triple `x, y, z` is “classified” if there exist integers `k, m, n` such that either * `x = k * (m ^ 2 - n ^ 2)` and `y = k * (2 * m * n)`, or * `x = k * (2 * m * n)` and `y = k * (m ^ 2 - n ^ 2)`.
@[nolint unusedArguments] IsPrimitiveClassified (_ : PythagoreanTriple x y z) := ∃ m n : ℤ, (x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∨ x = 2 * m * n ∧ y = m ^ 2 - n ^ 2) ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) variable (h : PythagoreanTriple x y z) include h
def
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
IsPrimitiveClassified
A primitive Pythagorean triple `x, y, z` is a Pythagorean triple with `x` and `y` coprime. Such a triple is “primitively classified” if there exist coprime integers `m, n` such that either * `x = m ^ 2 - n ^ 2` and `y = 2 * m * n`, or * `x = 2 * m * n` and `y = m ^ 2 - n ^ 2`.
mul_isClassified (k : ℤ) (hc : h.IsClassified) : (h.mul k).IsClassified := by obtain ⟨l, m, n, ⟨⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, co⟩⟩ := hc <;> use k * l, m, n <;> grind
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
mul_isClassified
null
even_odd_of_coprime (hc : Int.gcd x y = 1) : x % 2 = 0 ∧ y % 2 = 1 ∨ x % 2 = 1 ∧ y % 2 = 0 := by rcases Int.emod_two_eq_zero_or_one x with hx | hx <;> rcases Int.emod_two_eq_zero_or_one y with hy | hy · exfalso apply Nat.not_coprime_of_dvd_of_dvd (by decide : 1 < 2) _ _ hc · apply Int.natCast_dvd.1 ...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
even_odd_of_coprime
null
gcd_dvd : (Int.gcd x y : ℤ) ∣ z := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 have hz : z = 0 := by sim...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
gcd_dvd
null
normalize : PythagoreanTriple (x / Int.gcd x y) (y / Int.gcd x y) (z / Int.gcd x y) := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
normalize
null
isClassified_of_isPrimitiveClassified (hp : h.IsPrimitiveClassified) : h.IsClassified := by obtain ⟨m, n, H⟩ := hp use 1, m, n cutsat
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
isClassified_of_isPrimitiveClassified
null
isClassified_of_normalize_isPrimitiveClassified (hc : h.normalize.IsPrimitiveClassified) : h.IsClassified := by convert h.normalize.mul_isClassified (Int.gcd x y) (isClassified_of_isPrimitiveClassified h.normalize hc) <;> rw [Int.mul_ediv_cancel'] · exact Int.gcd_dvd_left .. · exact Int.gcd_dvd_ri...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
isClassified_of_normalize_isPrimitiveClassified
null
ne_zero_of_coprime (hc : Int.gcd x y = 1) : z ≠ 0 := by suffices 0 < z * z by rintro rfl norm_num at this rw [← h.eq, ← sq, ← sq] have hc' : Int.gcd x y ≠ 0 := by rw [hc] exact one_ne_zero rcases Int.ne_zero_of_gcd hc' with hxz | hyz · apply lt_add_of_pos_of_le (sq_pos_of_ne_zero hxz) (sq_nonn...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
ne_zero_of_coprime
null
isPrimitiveClassified_of_coprime_of_zero_left (hc : Int.gcd x y = 1) (hx : x = 0) : h.IsPrimitiveClassified := by subst x change Nat.gcd 0 (Int.natAbs y) = 1 at hc rw [Nat.gcd_zero_left (Int.natAbs y)] at hc rcases Int.natAbs_eq y with hy | hy · use 1, 0 rw [hy, hc, Int.gcd_zero_right] decide · ...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
isPrimitiveClassified_of_coprime_of_zero_left
null
coprime_of_coprime (hc : Int.gcd x y = 1) : Int.gcd y z = 1 := by by_contra H obtain ⟨p, hp, hpy, hpz⟩ := Nat.Prime.not_coprime_iff_dvd.mp H apply hp.not_dvd_one rw [← hc] apply Nat.dvd_gcd (Int.Prime.dvd_natAbs_of_coe_dvd_sq hp _ _) hpy rw [sq, eq_sub_of_add_eq h] rw [← Int.natCast_dvd] at hpy hpz exac...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_of_coprime
null
circleEquivGen (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) : K ≃ { p : K × K // p.1 ^ 2 + p.2 ^ 2 = 1 ∧ p.2 ≠ -1 } where toFun x := ⟨⟨2 * x / (1 + x ^ 2), (1 - x ^ 2) / (1 + x ^ 2)⟩, by field_simp [hk x]; ring, by simp only [Ne, div_eq_iff (hk x), neg_mul, one_mul, neg_add, sub_eq_add_neg, add_left_inj] s...
def
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
circleEquivGen
A parameterization of the unit circle that is useful for classifying Pythagorean triples. (To be applied in the case where `K = ℚ`.)
circleEquivGen_apply (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) (x : K) : (circleEquivGen hk x : K × K) = ⟨2 * x / (1 + x ^ 2), (1 - x ^ 2) / (1 + x ^ 2)⟩ := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
circleEquivGen_apply
null
circleEquivGen_symm_apply (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) (v : { p : K × K // p.1 ^ 2 + p.2 ^ 2 = 1 ∧ p.2 ≠ -1 }) : (circleEquivGen hk).symm v = (v : K × K).1 / ((v : K × K).2 + 1) := rfl
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
circleEquivGen_symm_apply
null
private coprime_sq_sub_sq_add_of_even_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 0) (hn : n % 2 = 1) : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1 := by by_contra H obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp H rw [← Int.natCast_dvd] at hp1 hp2 have h2m : (p : ℤ) ∣ 2 * m ^ 2 := by ...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_sq_sub_sq_add_of_even_odd
null
private coprime_sq_sub_sq_add_of_odd_even {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1 := by rw [Int.gcd, ← Int.natAbs_neg (m ^ 2 - n ^ 2)] rw [(by ring : -(m ^ 2 - n ^ 2) = n ^ 2 - m ^ 2), add_comm] apply coprime_sq_sub_sq_add_of_even_odd _ h...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_sq_sub_sq_add_of_odd_even
null
private coprime_sq_sub_mul_of_even_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 0) (hn : n % 2 = 1) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by by_contra H obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp H rw [← Int.natCast_dvd] at hp1 hp2 have hnp : ¬(p : ℤ) ∣ Int.gcd m n := by rw...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_sq_sub_mul_of_even_odd
null
private coprime_sq_sub_mul_of_odd_even {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by rw [Int.gcd, ← Int.natAbs_neg (m ^ 2 - n ^ 2)] rw [(by ring : 2 * m * n = 2 * n * m), (by ring : -(m ^ 2 - n ^ 2) = n ^ 2 - m ^ 2)] apply coprime_sq_sub_mul_...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_sq_sub_mul_of_odd_even
null
private coprime_sq_sub_mul {m n : ℤ} (h : Int.gcd m n = 1) (hmn : m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by rcases hmn with h1 | h2 · exact coprime_sq_sub_mul_of_even_odd h h1.left h1.right · exact coprime_sq_sub_mul_of_odd_even h h2.left h2.right
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_sq_sub_mul
null
private coprime_sq_sub_sq_sum_of_odd_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 1) : 2 ∣ m ^ 2 + n ^ 2 ∧ 2 ∣ m ^ 2 - n ^ 2 ∧ (m ^ 2 - n ^ 2) / 2 % 2 = 0 ∧ Int.gcd ((m ^ 2 - n ^ 2) / 2) ((m ^ 2 + n ^ 2) / 2) = 1 := by obtain ⟨m0, hm2⟩ := exists_eq_mul_left_of_dvd (Int.dvd_...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_sq_sub_sq_sum_of_odd_odd
null
isPrimitiveClassified_aux (hc : x.gcd y = 1) (hzpos : 0 < z) {m n : ℤ} (hm2n2 : 0 < m ^ 2 + n ^ 2) (hv2 : (x : ℚ) / z = 2 * m * n / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2)) (hw2 : (y : ℚ) / z = ((m : ℚ) ^ 2 - (n : ℚ) ^ 2) / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2)) (H : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1) (co : Int.gcd m n...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
isPrimitiveClassified_aux
null
isPrimitiveClassified_of_coprime_of_odd_of_pos (hc : Int.gcd x y = 1) (hyo : y % 2 = 1) (hzpos : 0 < z) : h.IsPrimitiveClassified := by by_cases h0 : x = 0 · exact h.isPrimitiveClassified_of_coprime_of_zero_left hc h0 let v := (x : ℚ) / z let w := (y : ℚ) / z have hq : v ^ 2 + w ^ 2 = 1 := by simp [fi...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
isPrimitiveClassified_of_coprime_of_odd_of_pos
null
isPrimitiveClassified_of_coprime_of_pos (hc : Int.gcd x y = 1) (hzpos : 0 < z) : h.IsPrimitiveClassified := by rcases h.even_odd_of_coprime hc with h1 | h2 · exact h.isPrimitiveClassified_of_coprime_of_odd_of_pos hc h1.right hzpos rw [Int.gcd_comm] at hc obtain ⟨m, n, H⟩ := h.symm.isPrimitiveClassified_of_c...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
isPrimitiveClassified_of_coprime_of_pos
null
isPrimitiveClassified_of_coprime (hc : Int.gcd x y = 1) : h.IsPrimitiveClassified := by by_cases hz : 0 < z · exact h.isPrimitiveClassified_of_coprime_of_pos hc hz have h' : PythagoreanTriple x y (-z) := by simpa [PythagoreanTriple, neg_mul_neg] using h.eq apply h'.isPrimitiveClassified_of_coprime_of_pos hc a...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
isPrimitiveClassified_of_coprime
null
classified : h.IsClassified := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 use 0, 1, 0 simp [hx, hy] app...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
classified
null
coprime_classification : PythagoreanTriple x y z ∧ Int.gcd x y = 1 ↔ ∃ m n, (x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∨ x = 2 * m * n ∧ y = m ^ 2 - n ^ 2) ∧ (z = m ^ 2 + n ^ 2 ∨ z = -(m ^ 2 + n ^ 2)) ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) := by constructor...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_classification
null
coprime_classification' {x y z : ℤ} (h : PythagoreanTriple x y z) (h_coprime : Int.gcd x y = 1) (h_parity : x % 2 = 1) (h_pos : 0 < z) : ∃ m n, x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∧ z = m ^ 2 + n ^ 2 ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) ∧ 0 ≤ m :=...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
coprime_classification'
By assuming `x` is odd and `z` is positive we get a slightly more precise classification of the Pythagorean triple `x ^ 2 + y ^ 2 = z ^ 2`.
classification : PythagoreanTriple x y z ↔ ∃ k m n, (x = k * (m ^ 2 - n ^ 2) ∧ y = k * (2 * m * n) ∨ x = k * (2 * m * n) ∧ y = k * (m ^ 2 - n ^ 2)) ∧ (z = k * (m ^ 2 + n ^ 2) ∨ z = -k * (m ^ 2 + n ^ 2)) := by constructor · intro h obtain ⟨k, m, n, H⟩ := h.classified u...
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
classification
**Formula for Pythagorean Triples**
noncomputable beattySeq (r : ℝ) : ℤ → ℤ := fun k ↦ ⌊k * r⌋
def
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
beattySeq
In the Beatty sequence for real number `r`, the `k`th term is `⌊k * r⌋`.
noncomputable beattySeq' (r : ℝ) : ℤ → ℤ := fun k ↦ ⌈k * r⌉ - 1
def
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
beattySeq'
In this variant of the Beatty sequence for `r`, the `k`th term is `⌈k * r⌉ - 1`.
private no_collision (hrs : r.HolderConjugate s) : Disjoint {beattySeq r k | k} {beattySeq' s k | k} := by rw [Set.disjoint_left] intro j ⟨k, h₁⟩ ⟨m, h₂⟩ rw [beattySeq, Int.floor_eq_iff, ← div_le_iff₀ hrs.pos, ← lt_div_iff₀ hrs.pos] at h₁ rw [beattySeq', sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int...
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
no_collision
Let `r > 1` and `1/r + 1/s = 1`. Then `B_r` and `B'_s` are disjoint (i.e. no collision exists).
private no_anticollision (hrs : r.HolderConjugate s) : ¬∃ j k m : ℤ, k < j / r ∧ (j + 1) / r ≤ k + 1 ∧ m ≤ j / s ∧ (j + 1) / s < m + 1 := by intro ⟨j, k, m, h₁₁, h₁₂, h₂₁, h₂₂⟩ have h₃ := add_lt_add_of_lt_of_le h₁₁ h₂₁ have h₄ := add_lt_add_of_le_of_lt h₁₂ h₂₂ simp_rw [div_eq_inv_mul, ← right_distrib, hrs.i...
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
no_anticollision
Let `r > 1` and `1/r + 1/s = 1`. Suppose there is an integer `j` where `B_r` and `B'_s` both jump over `j` (i.e. an anti-collision). Then this leads to a contradiction.
private hit_or_miss (h : r > 0) : j ∈ {beattySeq r k | k} ∨ ∃ k : ℤ, k < j / r ∧ (j + 1) / r ≤ k + 1 := by cases lt_or_ge ((⌈(j + 1) / r⌉ - 1) * r) j · refine Or.inr ⟨⌈(j + 1) / r⌉ - 1, ?_⟩ rw [Int.cast_sub, Int.cast_one, lt_div_iff₀ h, sub_add_cancel] exact ⟨‹_›, Int.le_ceil _⟩ · refine Or.inl ⟨⌈(j +...
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
hit_or_miss
Let `0 < r ∈ ℝ` and `j ∈ ℤ`. Then either `j ∈ B_r` or `B_r` jumps over `j`.
private hit_or_miss' (h : r > 0) : j ∈ {beattySeq' r k | k} ∨ ∃ k : ℤ, k ≤ j / r ∧ (j + 1) / r < k + 1 := by cases le_or_gt (⌊(j + 1) / r⌋ * r) j · exact Or.inr ⟨⌊(j + 1) / r⌋, (le_div_iff₀ h).2 ‹_›, Int.lt_floor_add_one _⟩ · refine Or.inl ⟨⌊(j + 1) / r⌋, ?_⟩ rw [beattySeq', sub_eq_iff_eq_add, Int.ceil_eq...
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
hit_or_miss'
Let `0 < r ∈ ℝ` and `j ∈ ℤ`. Then either `j ∈ B'_r` or `B'_r` jumps over `j`.
compl_beattySeq {r s : ℝ} (hrs : r.HolderConjugate s) : {beattySeq r k | k}ᶜ = {beattySeq' s k | k} := by ext j by_cases h₁ : j ∈ {beattySeq r k | k} <;> by_cases h₂ : j ∈ {beattySeq' s k | k} · exact (Set.not_disjoint_iff.2 ⟨j, h₁, h₂⟩ (Beatty.no_collision hrs)).elim · simp only [Set.mem_compl_iff, h₁, h₂,...
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
compl_beattySeq
Generalization of Rayleigh's theorem on Beatty sequences. Let `r` be a real number greater than 1, and `1/r + 1/s = 1`. Then the complement of `B_r` is `B'_s`.
compl_beattySeq' {r s : ℝ} (hrs : r.HolderConjugate s) : {beattySeq' r k | k}ᶜ = {beattySeq s k | k} := by rw [← compl_beattySeq hrs.symm, compl_compl] open scoped symmDiff
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
compl_beattySeq'
null
beattySeq_symmDiff_beattySeq'_pos {r s : ℝ} (hrs : r.HolderConjugate s) : {beattySeq r k | k > 0} ∆ {beattySeq' s k | k > 0} = {n | 0 < n} := by apply Set.eq_of_subset_of_subset · rintro j (⟨⟨k, hk, hjk⟩, -⟩ | ⟨⟨k, hk, hjk⟩, -⟩) · rw [Set.mem_setOf_eq, ← hjk, beattySeq, Int.floor_pos] exact one_le_mul...
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
beattySeq_symmDiff_beattySeq'_pos
Generalization of Rayleigh's theorem on Beatty sequences. Let `r` be a real number greater than 1, and `1/r + 1/s = 1`. Then `B⁺_r` and `B⁺'_s` partition the positive integers.
beattySeq'_symmDiff_beattySeq_pos {r s : ℝ} (hrs : r.HolderConjugate s) : {beattySeq' r k | k > 0} ∆ {beattySeq s k | k > 0} = {n | 0 < n} := by rw [symmDiff_comm, beattySeq_symmDiff_beattySeq'_pos hrs.symm]
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
beattySeq'_symmDiff_beattySeq_pos
null
Irrational.beattySeq'_pos_eq {r : ℝ} (hr : Irrational r) : {beattySeq' r k | k > 0} = {beattySeq r k | k > 0} := by dsimp only [beattySeq, beattySeq'] congr! 4; rename_i k; rw [and_congr_right_iff]; intro hk; congr! rw [sub_eq_iff_eq_add, Int.ceil_eq_iff, Int.cast_add, Int.cast_one, add_sub_cancel_right] re...
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
Irrational.beattySeq'_pos_eq
Let `r` be an irrational number. Then `B⁺_r` and `B⁺'_r` are equal.
Irrational.beattySeq_symmDiff_beattySeq_pos {r s : ℝ} (hrs : r.HolderConjugate s) (hr : Irrational r) : {beattySeq r k | k > 0} ∆ {beattySeq s k | k > 0} = {n | 0 < n} := by rw [← hr.beattySeq'_pos_eq, beattySeq'_symmDiff_beattySeq_pos hrs]
theorem
NumberTheory
[ "Mathlib.Data.Real.ConjExponents", "Mathlib.Data.Real.Irrational" ]
Mathlib/NumberTheory/Rayleigh.lean
Irrational.beattySeq_symmDiff_beattySeq_pos
**Rayleigh's theorem** on Beatty sequences. Let `r` be an irrational number greater than 1, and `1/r + 1/s = 1`. Then `B⁺_r` and `B⁺_s` partition the positive integers.
BoundingSieve where /-- The set of natural numbers that is to be sifted. The fundamental lemma yields an upper bound on the size of this set after the multiples of small primes have been removed. -/ support : Finset ℕ /-- The finite set of prime numbers whose multiples are to be sifted from `support`. We work w...
structure
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
BoundingSieve
We set up a sieve problem as follows. Take a finite set of natural numbers `A`, whose elements are weighted by a sequence `a n`. Also take a finite set of primes `P`, represented by a squarefree natural number. These are the primes that we will sift from our set `A`. Suppose we can approximate `∑ n ∈ {k ∈ A | d ∣ k}, a...
SelbergSieve extends BoundingSieve where /-- The `level` of the sieve controls how many terms we include in the inclusion-exclusion type sum. A higher level will yield a tighter bound for the main term, but will also increase the size of the error term. -/ level : ℝ one_le_level : 1 ≤ level attribute [arith_m...
structure
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
SelbergSieve
The Selberg upper bound sieve in particular introduces a parameter called the `level` which gives the user control over the size of the error term.
@[positivity BoundingSieve.weights _ _] evalBoundingSieveWeights : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@BoundingSieve.weights $s $n) => assertInstancesCommute pure (.nonnegative q(BoundingSieve.weights_nonneg $s $n)) | _, _, _ => throwError "not BoundingSieve.w...
def
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
evalBoundingSieveWeights
Extension for the `positivity` tactic: `BoundingSieve.weights`.
one_le_y {s : SelbergSieve} : 1 ≤ s.level := s.one_le_level variable {s : BoundingSieve} /-! Lemmas about $P$. -/
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
one_le_y
null
prodPrimes_ne_zero : s.prodPrimes ≠ 0 := Squarefree.ne_zero s.prodPrimes_squarefree
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
prodPrimes_ne_zero
null
squarefree_of_dvd_prodPrimes {d : ℕ} (hd : d ∣ s.prodPrimes) : Squarefree d := Squarefree.squarefree_of_dvd hd s.prodPrimes_squarefree
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
squarefree_of_dvd_prodPrimes
null
squarefree_of_mem_divisors_prodPrimes {d : ℕ} (hd : d ∈ divisors s.prodPrimes) : Squarefree d := by simp only [Nat.mem_divisors] at hd exact Squarefree.squarefree_of_dvd hd.left s.prodPrimes_squarefree /-! Lemmas about $\nu$. -/
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
squarefree_of_mem_divisors_prodPrimes
null
prod_primeFactors_nu {d : ℕ} (hd : d ∣ s.prodPrimes) : ∏ p ∈ d.primeFactors, s.nu p = s.nu d := by rw [← s.nu_mult.map_prod_of_subset_primeFactors _ _ subset_rfl, Nat.prod_primeFactors_of_squarefree <| Squarefree.squarefree_of_dvd hd s.prodPrimes_squarefree]
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
prod_primeFactors_nu
null
nu_pos_of_dvd_prodPrimes {d : ℕ} (hd : d ∣ s.prodPrimes) : 0 < s.nu d := by calc 0 < ∏ p ∈ d.primeFactors, s.nu p := by apply prod_pos intro p hpd have hp_prime : p.Prime := prime_of_mem_primeFactors hpd have hp_dvd : p ∣ s.prodPrimes := (dvd_of_mem_primeFactors hpd).trans hd exact s...
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
nu_pos_of_dvd_prodPrimes
null
nu_ne_zero {d : ℕ} (hd : d ∣ s.prodPrimes) : s.nu d ≠ 0 := by apply _root_.ne_of_gt exact nu_pos_of_dvd_prodPrimes hd
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
nu_ne_zero
null
nu_lt_one_of_dvd_prodPrimes {d : ℕ} (hdP : d ∣ s.prodPrimes) (hd_ne_one : d ≠ 1) : s.nu d < 1 := by have hd_sq : Squarefree d := Squarefree.squarefree_of_dvd hdP s.prodPrimes_squarefree have := hd_sq.ne_zero calc s.nu d = ∏ p ∈ d.primeFactors, s.nu p := (prod_primeFactors_nu hdP).symm _ < ∏ p ∈ d.prim...
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
nu_lt_one_of_dvd_prodPrimes
null
@[simp] multSum (d : ℕ) : ℝ := ∑ n ∈ s.support, if d ∣ n then s.weights n else 0
def
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
multSum
The weight of all the elements that are a multiple of `d`.
@[simp] rem (d : ℕ) : ℝ := s.multSum d - s.nu d * s.totalMass
def
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
rem
The remainder term in the approximation A_d = ν (d) X + R_d. This is the degree to which `nu` fails to approximate the proportion of the weight that is a multiple of `d`.
siftedSum : ℝ := ∑ d ∈ s.support, if Coprime s.prodPrimes d then s.weights d else 0
def
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
siftedSum
The weight of all the elements that are not a multiple of any of our finite set of primes.
mainSum (muPlus : ℕ → ℝ) : ℝ := ∑ d ∈ divisors s.prodPrimes, muPlus d * s.nu d
def
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
mainSum
`X * mainSum μ⁺` is the main term in the upper bound on `sifted_sum`.
errSum (muPlus : ℕ → ℝ) : ℝ := ∑ d ∈ divisors s.prodPrimes, |muPlus d| * |s.rem d|
def
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
errSum
`errSum μ⁺` is the error term in the upper bound on `sifted_sum`.
multSum_eq_main_err (d : ℕ) : s.multSum d = s.nu d * s.totalMass + s.rem d := by dsimp [rem] ring
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
multSum_eq_main_err
null
siftedSum_eq_sum_support_mul_ite : s.siftedSum = ∑ d ∈ s.support, s.weights d * if Nat.gcd s.prodPrimes d = 1 then 1 else 0 := by dsimp only [siftedSum] simp_rw [mul_ite, mul_one, mul_zero] @[deprecated (since := "2025-07-27")] alias siftedsum_eq_sum_support_mul_ite := siftedSum_eq_sum_support_mul_ite omit s in
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
siftedSum_eq_sum_support_mul_ite
null
IsUpperMoebius (muPlus : ℕ → ℝ) : Prop := ∀ n : ℕ, (if n = 1 then 1 else 0) ≤ ∑ d ∈ n.divisors, muPlus d
def
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
IsUpperMoebius
A sequence of coefficients $\mu^{+}$ is upper Moebius if $\mu * \zeta ≤ \mu^{+} * \zeta$. These coefficients then yield an upper bound on the sifted sum.
siftedSum_le_sum_of_upperMoebius (muPlus : ℕ → ℝ) (h : IsUpperMoebius muPlus) : s.siftedSum ≤ ∑ d ∈ divisors s.prodPrimes, muPlus d * s.multSum d := by have hμ : ∀ n, (if n = 1 then 1 else 0) ≤ ∑ d ∈ n.divisors, muPlus d := h calc siftedSum ≤ ∑ n ∈ s.support, s.weights n * ∑ d ∈ (Nat.gcd s.prodPrimes n).div...
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
siftedSum_le_sum_of_upperMoebius
null
siftedSum_le_mainSum_errSum_of_upperMoebius (muPlus : ℕ → ℝ) (h : IsUpperMoebius muPlus) : s.siftedSum ≤ s.totalMass * s.mainSum muPlus + s.errSum muPlus := calc s.siftedSum ≤ ∑ d ∈ divisors s.prodPrimes, muPlus d * multSum d := siftedSum_le_sum_of_upperMoebius _ h _ = s.totalMass * mainSum muPlus + ∑ d ∈ d...
theorem
NumberTheory
[ "Mathlib.Data.Real.Basic", "Mathlib.NumberTheory.ArithmeticFunction" ]
Mathlib/NumberTheory/SelbergSieve.lean
siftedSum_le_mainSum_errSum_of_upperMoebius
null
private image_T_subset_S [DecidableEq α] [DecidableEq β] (v) (hv : v ∈ T) : A *ᵥ v ∈ S := by rw [mem_Icc] at hv ⊢ have mulVec_def : A.mulVec v = fun i ↦ Finset.sum univ fun j : β ↦ A i j * v j := rfl rw [mulVec_def] refine ⟨fun i ↦ ?_, fun i ↦ ?_⟩ all_goals simp only [mul_neg] gcongr ∑ _ : α, ?_...
lemma
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
image_T_subset_S
null
private card_T_eq [DecidableEq β] : #T = (B + 1) ^ n := by rw [Pi.card_Icc 0 B'] simp only [Pi.zero_apply, card_Icc, sub_zero, toNat_natCast_add_one, prod_const, card_univ]
lemma
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
card_T_eq
null
private N_le_P_add_one (i : α) : N i ≤ P i + 1 := by calc N i _ ≤ 0 := by apply Finset.sum_nonpos intro j _ simp only [mul_neg, Left.neg_nonpos_iff] positivity _ ≤ P i + 1 := by apply le_trans (Finset.sum_nonneg _) (Int.le_add_one (le_refl P i)) intro j _ positivity
lemma
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
N_le_P_add_one
null
private card_S_eq [DecidableEq α] : #(Finset.Icc N P) = ∏ i : α, (P i - N i + 1) := by rw [Pi.card_Icc N P, Nat.cast_prod] congr ext i rw [Int.card_Icc_of_le (N i) (P i) (N_le_P_add_one A i)] exact add_sub_right_comm (P i) 1 (N i)
lemma
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
card_S_eq
null
one_le_norm_A_of_ne_zero (hA : A ≠ 0) : 1 ≤ ‖A‖ := by by_contra! h apply hA ext i j simp only [zero_apply] rw [norm_lt_iff Real.zero_lt_one] at h specialize h i j rw [Int.norm_eq_abs] at h norm_cast at h exact Int.abs_lt_one_iff.1 h open Real Nat
lemma
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
one_le_norm_A_of_ne_zero
The sup norm of a non-zero integer matrix is at least one
private card_S_lt_card_T [DecidableEq α] [DecidableEq β] (hn : Fintype.card α < Fintype.card β) (hm : 0 < Fintype.card α) : #S < #T := by zify -- This is necessary to use card_S_eq rw [card_T_eq A, card_S_eq] rify -- This is necessary because ‖A‖ is a real number calc ∏ x : α, (∑ x_1 : β, ↑B * ↑(A x x...
lemma
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
card_S_lt_card_T
null
exists_ne_zero_int_vec_norm_le (hn : Fintype.card α < Fintype.card β) (hm : 0 < Fintype.card α) : ∃ t : β → ℤ, t ≠ 0 ∧ A *ᵥ t = 0 ∧ ‖t‖ ≤ (n * max 1 ‖A‖) ^ ((m : ℝ) / (n - m)) := by classical rcases Finset.exists_ne_map_eq_of_card_lt_of_maps_to (card_S_lt_card_T A hn hm) (image_T_subset_S A) with ⟨x...
theorem
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
exists_ne_zero_int_vec_norm_le
null
exists_ne_zero_int_vec_norm_le' (hn : Fintype.card α < Fintype.card β) (hm : 0 < Fintype.card α) (hA : A ≠ 0) : ∃ t : β → ℤ, t ≠ 0 ∧ A *ᵥ t = 0 ∧ ‖t‖ ≤ (n * ‖A‖) ^ ((m : ℝ) / (n - m)) := by have := exists_ne_zero_int_vec_norm_le A hn hm rwa [max_eq_right] at this exact Int.Matrix.one_le_norm_A_of_ne_z...
theorem
NumberTheory
[ "Mathlib.Analysis.Matrix", "Mathlib.Data.Pi.Interval", "Mathlib.Tactic.Rify" ]
Mathlib/NumberTheory/SiegelsLemma.lean
exists_ne_zero_int_vec_norm_le'
null
primesBelow (n : ℕ) : Finset ℕ := {p ∈ Finset.range n | p.Prime} @[simp]
def
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
primesBelow
`primesBelow n` is the set of primes less than `n` as a `Finset`.
primesBelow_zero : primesBelow 0 = ∅ := by rw [primesBelow, Finset.range_zero, Finset.filter_empty]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
primesBelow_zero
null
mem_primesBelow {k n : ℕ} : n ∈ primesBelow k ↔ n < k ∧ n.Prime := by simp [primesBelow]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mem_primesBelow
null
prime_of_mem_primesBelow {p n : ℕ} (h : p ∈ n.primesBelow) : p.Prime := (Finset.mem_filter.mp h).2
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
prime_of_mem_primesBelow
null
lt_of_mem_primesBelow {p n : ℕ} (h : p ∈ n.primesBelow) : p < n := Finset.mem_range.mp <| Finset.mem_of_mem_filter p h
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
lt_of_mem_primesBelow
null
primesBelow_succ (n : ℕ) : primesBelow (n + 1) = if n.Prime then insert n (primesBelow n) else primesBelow n := by rw [primesBelow, primesBelow, Finset.range_add_one, Finset.filter_insert]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
primesBelow_succ
null
notMem_primesBelow (n : ℕ) : n ∉ primesBelow n := fun hn ↦ (lt_of_mem_primesBelow hn).false @[deprecated (since := "2025-05-23")] alias not_mem_primesBelow := notMem_primesBelow /-!
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
notMem_primesBelow
null
factoredNumbers (s : Finset ℕ) : Set ℕ := {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s}
def
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
factoredNumbers
`factoredNumbers s`, for a finite set `s` of natural numbers, is the set of positive natural numbers all of whose prime factors are in `s`.
mem_factoredNumbers {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s := Iff.rfl
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mem_factoredNumbers
null
mem_factoredNumbers_of_dvd {s : Finset ℕ} {m k : ℕ} (h : m ∈ factoredNumbers s) (h' : k ∣ m) : k ∈ factoredNumbers s := by obtain ⟨h₁, h₂⟩ := h have hk := ne_zero_of_dvd_ne_zero h₁ h' refine ⟨hk, fun p hp ↦ h₂ p ?_⟩ rw [mem_primeFactorsList <| by assumption] at hp ⊢ exact ⟨hp.1, hp.2.trans h'⟩
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mem_factoredNumbers_of_dvd
Membership in `Nat.factoredNumbers n` is decidable. -/ instance (s : Finset ℕ) : DecidablePred (· ∈ factoredNumbers s) := inferInstanceAs <| DecidablePred fun x ↦ x ∈ {m | m ≠ 0 ∧ ∀ p ∈ primeFactorsList m, p ∈ s} /-- A number that divides an `s`-factored number is itself `s`-factored.
mem_factoredNumbers_iff_forall_le {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ m ≠ 0 ∧ ∀ p ≤ m, p.Prime → p ∣ m → p ∈ s := by simp_rw [mem_factoredNumbers, mem_primeFactorsList'] exact ⟨fun ⟨H₀, H₁⟩ ↦ ⟨H₀, fun p _ hp₂ hp₃ ↦ H₁ p ⟨hp₂, hp₃, H₀⟩⟩, fun ⟨H₀, H₁⟩ ↦ ⟨H₀, fun p ⟨hp₁, hp₂, hp₃⟩ ↦ H₁ p (le...
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mem_factoredNumbers_iff_forall_le
`m` is `s`-factored if and only if `m` is nonzero and all prime divisors `≤ m` of `m` are in `s`.
mem_factoredNumbers' {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ ∀ p, p.Prime → p ∣ m → p ∈ s := by obtain ⟨p, hp₁, hp₂⟩ := exists_infinite_primes (1 + Finset.sup s id) rw [mem_factoredNumbers_iff_forall_le] refine ⟨fun ⟨H₀, H₁⟩ ↦ fun p hp₁ hp₂ ↦ H₁ p (le_of_dvd (Nat.pos_of_ne_zero H₀) hp₂) hp₁ hp₂, ...
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mem_factoredNumbers'
`m` is `s`-factored if and only if all prime divisors of `m` are in `s`.
ne_zero_of_mem_factoredNumbers {s : Finset ℕ} {m : ℕ} (h : m ∈ factoredNumbers s) : m ≠ 0 := h.1
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
ne_zero_of_mem_factoredNumbers
null
primeFactors_subset_of_mem_factoredNumbers {s : Finset ℕ} {m : ℕ} (hm : m ∈ factoredNumbers s) : m.primeFactors ⊆ s := by rw [mem_factoredNumbers] at hm exact fun n hn ↦ hm.2 n (mem_primeFactors_iff_mem_primeFactorsList.mp hn)
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
primeFactors_subset_of_mem_factoredNumbers
The `Finset` of prime factors of an `s`-factored number is contained in `s`.
mem_factoredNumbers_of_primeFactors_subset {s : Finset ℕ} {m : ℕ} (hm : m ≠ 0) (hp : m.primeFactors ⊆ s) : m ∈ factoredNumbers s := by rw [mem_factoredNumbers] exact ⟨hm, fun p hp' ↦ hp <| mem_primeFactors_iff_mem_primeFactorsList.mpr hp'⟩
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mem_factoredNumbers_of_primeFactors_subset
If `m ≠ 0` and the `Finset` of prime factors of `m` is contained in `s`, then `m` is `s`-factored.
mem_factoredNumbers_iff_primeFactors_subset {s : Finset ℕ} {m : ℕ} : m ∈ factoredNumbers s ↔ m ≠ 0 ∧ m.primeFactors ⊆ s := ⟨fun h ↦ ⟨ne_zero_of_mem_factoredNumbers h, primeFactors_subset_of_mem_factoredNumbers h⟩, fun ⟨h₁, h₂⟩ ↦ mem_factoredNumbers_of_primeFactors_subset h₁ h₂⟩ @[simp]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mem_factoredNumbers_iff_primeFactors_subset
`m` is `s`-factored if and only if `m ≠ 0` and its `Finset` of prime factors is contained in `s`.
factoredNumbers_empty : factoredNumbers ∅ = {1} := by ext m simp only [mem_factoredNumbers, Finset.notMem_empty, ← List.eq_nil_iff_forall_not_mem, primeFactorsList_eq_nil, and_or_left, not_and_self_iff, ne_and_eq_iff_right zero_ne_one, false_or, Set.mem_singleton_iff]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
factoredNumbers_empty
null
mul_mem_factoredNumbers {s : Finset ℕ} {m n : ℕ} (hm : m ∈ factoredNumbers s) (hn : n ∈ factoredNumbers s) : m * n ∈ factoredNumbers s := by have hm' := primeFactors_subset_of_mem_factoredNumbers hm have hn' := primeFactors_subset_of_mem_factoredNumbers hn exact mem_factoredNumbers_of_primeFactors_subset ...
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
mul_mem_factoredNumbers
The product of two `s`-factored numbers is again `s`-factored.
prod_mem_factoredNumbers (s : Finset ℕ) (n : ℕ) : (n.primeFactorsList.filter (· ∈ s)).prod ∈ factoredNumbers s := by have h₀ : (n.primeFactorsList.filter (· ∈ s)).prod ≠ 0 := List.prod_ne_zero fun h ↦ (pos_of_mem_primeFactorsList (List.mem_of_mem_filter h)).false refine ⟨h₀, fun p hp ↦ ?_⟩ obtain ⟨H₁, H₂⟩...
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
prod_mem_factoredNumbers
The product of the prime factors of `n` that are in `s` is an `s`-factored number.
factoredNumbers_insert (s : Finset ℕ) {N : ℕ} (hN : ¬ N.Prime) : factoredNumbers (insert N s) = factoredNumbers s := by ext m refine ⟨fun hm ↦ ⟨hm.1, fun p hp ↦ ?_⟩, fun hm ↦ ⟨hm.1, fun p hp ↦ Finset.mem_insert_of_mem <| hm.2 p hp⟩⟩ exact Finset.mem_of_mem_insert_of_ne (hm.2 p hp) fun h ↦ hN <| ...
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
factoredNumbers_insert
The sets of `s`-factored and of `s ∪ {N}`-factored numbers are the same when `N` is not prime. See `Nat.equivProdNatFactoredNumbers` for when `N` is prime.
factoredNumbers_compl {N : ℕ} {s : Finset ℕ} (h : primesBelow N ≤ s) : (factoredNumbers s)ᶜ \ {0} ⊆ {n | N ≤ n} := by intro n hn simp only [Set.mem_compl_iff, mem_factoredNumbers, Set.mem_diff, ne_eq, not_and, not_forall, exists_prop, Set.mem_singleton_iff] at hn simp only [Set.mem_setOf_eq] obtain ⟨p, ...
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
factoredNumbers_compl
The non-zero non-`s`-factored numbers are `≥ N` when `s` contains all primes less than `N`.
pow_mul_mem_factoredNumbers {s : Finset ℕ} {p n : ℕ} (hp : p.Prime) (e : ℕ) (hn : n ∈ factoredNumbers s) : p ^ e * n ∈ factoredNumbers (insert p s) := by have hp' := pow_ne_zero e hp.ne_zero refine ⟨mul_ne_zero hp' hn.1, fun q hq ↦ ?_⟩ rcases (mem_primeFactorsList_mul hp' hn.1).mp hq with H | H · rw [me...
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
pow_mul_mem_factoredNumbers
If `p` is a prime and `n` is `s`-factored, then every product `p^e * n` is `s ∪ {p}`-factored.
Prime.factoredNumbers_coprime {s : Finset ℕ} {p n : ℕ} (hp : p.Prime) (hs : p ∉ s) (hn : n ∈ factoredNumbers s) : Nat.Coprime p n := by rw [hp.coprime_iff_not_dvd, ← mem_primeFactorsList_iff_dvd hn.1 hp] exact fun H ↦ hs <| hn.2 p H
lemma
NumberTheory
[ "Mathlib.Data.Nat.Factorization.Defs", "Mathlib.Data.Nat.Squarefree" ]
Mathlib/NumberTheory/SmoothNumbers.lean
Prime.factoredNumbers_coprime
If `p ∉ s` is a prime and `n` is `s`-factored, then `p` and `n` are coprime.