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
xn_one : xn a1 1 = a := by simp
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_one
null
yn_one : yn a1 1 = 1 := by simp
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_one
null
xz (n : ℕ) : ℤ := xn a1 n
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xz
The Pell `x` sequence, considered as an integer sequence.
yz (n : ℕ) : ℤ := yn a1 n
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yz
The Pell `y` sequence, considered as an integer sequence.
az (a : ℕ) : ℤ := a
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
az
The element `a` such that `d = a ^ 2 - 1`, considered as an integer.
asq_pos : 0 < a * a := le_trans (le_of_lt a1) (by have := @Nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa [mul_one] at this)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
asq_pos
null
dz_val : ↑(d a1) = az a * az a - 1 := have : 1 ≤ a * a := asq_pos a1 by rw [Pell.d, Int.ofNat_sub this]; rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
dz_val
null
xz_succ (n : ℕ) : (xz a1 (n + 1)) = xz a1 n * az a + d a1 * yz a1 n := rfl @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xz_succ
null
yz_succ (n : ℕ) : yz a1 (n + 1) = xz a1 n + yz a1 n * az a := rfl
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yz_succ
null
pellZd (n : ℕ) : ℤ√(d a1) := ⟨xn a1 n, yn a1 n⟩ @[simp]
def
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pellZd
The Pell sequence can also be viewed as an element of `ℤ√d`
re_pellZd (n : ℕ) : (pellZd a1 n).re = xn a1 n := rfl @[deprecated (since := "2025-08-31")] alias pellZd_re := re_pellZd @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
re_pellZd
null
im_pellZd (n : ℕ) : (pellZd a1 n).im = yn a1 n := rfl @[deprecated (since := "2025-08-31")] alias pellZd_im := im_pellZd
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
im_pellZd
null
isPell_nat {x y : ℕ} : IsPell (⟨x, y⟩ : ℤ√(d a1)) ↔ x * x - d a1 * y * y = 1 := ⟨fun h => (Nat.cast_inj (R := ℤ)).1 (by rw [Int.ofNat_sub (Int.le_of_ofNat_le_ofNat <| Int.le.intro_sub _ h)]; exact h), fun h => show ((x * x : ℕ) - (d a1 * y * y : ℕ) : ℤ) = 1 by rw [← Int.ofNat_sub <| le_of_lt <...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
isPell_nat
null
pellZd_succ (n : ℕ) : pellZd a1 (n + 1) = pellZd a1 n * ⟨a, 1⟩ := by ext <;> simp
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pellZd_succ
null
isPell_one : IsPell (⟨a, 1⟩ : ℤ√(d a1)) := show az a * az a - d a1 * 1 * 1 = 1 by simp [dz_val]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
isPell_one
null
isPell_pellZd : ∀ n : ℕ, IsPell (pellZd a1 n) | 0 => rfl | n + 1 => by let o := isPell_one a1 simpa using Pell.isPell_mul (isPell_pellZd n) o @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
isPell_pellZd
null
pell_eqz (n : ℕ) : xz a1 n * xz a1 n - d a1 * yz a1 n * yz a1 n = 1 := isPell_pellZd a1 n @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pell_eqz
null
pell_eq (n : ℕ) : xn a1 n * xn a1 n - d a1 * yn a1 n * yn a1 n = 1 := let pn := pell_eqz a1 n have h : (↑(xn a1 n * xn a1 n) : ℤ) - ↑(d a1 * yn a1 n * yn a1 n) = 1 := by repeat' rw [Int.natCast_mul]; exact pn have hl : d a1 * yn a1 n * yn a1 n ≤ xn a1 n * xn a1 n := Nat.cast_le.1 <| Int.le.intro _ <| add_...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pell_eq
null
dnsq : Zsqrtd.Nonsquare (d a1) := ⟨fun n h => have : n * n + 1 = a * a := by rw [← h]; exact Nat.succ_pred_eq_of_pos (asq_pos a1) have na : n < a := Nat.mul_self_lt_mul_self_iff.1 (by rw [← this]; exact Nat.lt_succ_self _) have : (n + 1) * (n + 1) ≤ n * n + 1 := by rw [this]; exact Nat.mul_self_le_mul_sel...
instance
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
dnsq
null
xn_ge_a_pow : ∀ n : ℕ, a ^ n ≤ xn a1 n | 0 => le_refl 1 | n + 1 => by simp only [_root_.pow_succ, xn_succ] exact le_trans (Nat.mul_le_mul_right _ (xn_ge_a_pow n)) (Nat.le_add_right _ _)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_ge_a_pow
null
n_lt_xn (n) : n < xn a1 n := lt_of_lt_of_le (Nat.lt_pow_self a1) (xn_ge_a_pow a1 n)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
n_lt_xn
null
x_pos (n) : 0 < xn a1 n := lt_of_le_of_lt (Nat.zero_le n) (n_lt_xn a1 n)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
x_pos
null
eq_pell_lem : ∀ (n) (b : ℤ√(d a1)), 1 ≤ b → IsPell b → b ≤ pellZd a1 n → ∃ n, b = pellZd a1 n | 0, _ => fun h1 _ hl => ⟨0, @Zsqrtd.le_antisymm _ (dnsq a1) _ _ hl h1⟩ | n + 1, b => fun h1 hp h => have a1p : (0 : ℤ√(d a1)) ≤ ⟨a, 1⟩ := trivial have am1p : (0 : ℤ√(d a1)) ≤ ⟨a, -1⟩ := show (_ : Nat) ≤ _ by s...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_pell_lem
null
eq_pellZd (b : ℤ√(d a1)) (b1 : 1 ≤ b) (hp : IsPell b) : ∃ n, b = pellZd a1 n := let ⟨n, h⟩ := @Zsqrtd.le_arch (d a1) b eq_pell_lem a1 n b b1 hp <| h.trans <| by rw [Zsqrtd.natCast_val] exact Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| le_of_lt <| n_lt_xn _ _) (Int.ofNat_zero_le...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_pellZd
null
eq_pell {x y : ℕ} (hp : x * x - d a1 * y * y = 1) : ∃ n, x = xn a1 n ∧ y = yn a1 n := have : (1 : ℤ√(d a1)) ≤ ⟨x, y⟩ := match x, hp with | 0, (hp : 0 - _ = 1) => by rw [zero_tsub] at hp; contradiction | x + 1, _hp => Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| Nat.succ_pos x) (Int.ofNat_zero_le ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_pell
Every solution to **Pell's equation** is recursively obtained from the initial solution `(1,0)` using the recursion `pell`.
pellZd_add (m) : ∀ n, pellZd a1 (m + n) = pellZd a1 m * pellZd a1 n | 0 => (mul_one _).symm | n + 1 => by rw [← add_assoc, pellZd_succ, pellZd_succ, pellZd_add _ n, ← mul_assoc]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pellZd_add
null
xn_add (m n) : xn a1 (m + n) = xn a1 m * xn a1 n + d a1 * yn a1 m * yn a1 n := by injection pellZd_add a1 m n with h _ zify rw [h] simp [pellZd]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_add
null
yn_add (m n) : yn a1 (m + n) = xn a1 m * yn a1 n + yn a1 m * xn a1 n := by injection pellZd_add a1 m n with _ h zify rw [h] simp [pellZd]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_add
null
pellZd_sub {m n} (h : n ≤ m) : pellZd a1 (m - n) = pellZd a1 m * star (pellZd a1 n) := by let t := pellZd_add a1 n (m - n) rw [add_tsub_cancel_of_le h] at t rw [t, mul_comm (pellZd _ n) _, mul_assoc, isPell_norm.1 (isPell_pellZd _ _), mul_one]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pellZd_sub
null
xz_sub {m n} (h : n ≤ m) : xz a1 (m - n) = xz a1 m * xz a1 n - d a1 * yz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg] exact congr_arg Zsqrtd.re (pellZd_sub a1 h)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xz_sub
null
yz_sub {m n} (h : n ≤ m) : yz a1 (m - n) = xz a1 n * yz a1 m - xz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg, mul_comm, add_comm] exact congr_arg Zsqrtd.im (pellZd_sub a1 h)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yz_sub
null
xy_coprime (n) : (xn a1 n).Coprime (yn a1 n) := Nat.coprime_of_dvd' fun k _ kx ky => by let p := pell_eq a1 n rw [← p] exact Nat.dvd_sub (kx.mul_left _) (ky.mul_left _)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xy_coprime
null
strictMono_y : StrictMono (yn a1) | _, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : yn a1 m ≤ yn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_y hl) fun e => by rw [e] simp only [yn_succ, gt_iff_lt]; refine lt_of_le_of_lt ?_ ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
strictMono_y
null
strictMono_x : StrictMono (xn a1) | _, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : xn a1 m ≤ xn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_x hl) fun e => by rw [e] simp only [xn_succ, gt_iff_lt] refine lt_of_lt_of_le ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
strictMono_x
null
yn_ge_n : ∀ n, n ≤ yn a1 n | 0 => Nat.zero_le _ | n + 1 => show n < yn a1 (n + 1) from lt_of_le_of_lt (yn_ge_n n) (strictMono_y a1 <| Nat.lt_succ_self n)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_ge_n
null
y_mul_dvd (n) : ∀ k, yn a1 n ∣ yn a1 (n * k) | 0 => dvd_zero _ | k + 1 => by rw [Nat.mul_succ, yn_add]; exact dvd_add (dvd_mul_left _ _) ((y_mul_dvd _ k).mul_right _)
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
y_mul_dvd
null
y_dvd_iff (m n) : yn a1 m ∣ yn a1 n ↔ m ∣ n := ⟨fun h => Nat.dvd_of_mod_eq_zero <| (Nat.eq_zero_or_pos _).resolve_right fun hp => by have co : Nat.Coprime (yn a1 m) (xn a1 (m * (n / m))) := Nat.Coprime.symm <| (xy_coprime a1 _).coprime_dvd_right (y_mul_dvd a1 m (n / m)) have m0 : 0...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
y_dvd_iff
null
xy_modEq_yn (n) : ∀ k, xn a1 (n * k) ≡ xn a1 n ^ k [MOD yn a1 n ^ 2] ∧ yn a1 (n * k) ≡ k * xn a1 n ^ (k - 1) * yn a1 n [MOD yn a1 n ^ 3] | 0 => by simp [Nat.ModEq.refl] | k + 1 => by let ⟨hx, hy⟩ := xy_modEq_yn n k have L : xn a1 (n * k) * xn a1 n + d a1 * yn a1 (n * k) * yn a1 n ≡ xn a1...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xy_modEq_yn
null
ysq_dvd_yy (n) : yn a1 n * yn a1 n ∣ yn a1 (n * yn a1 n) := modEq_zero_iff_dvd.1 <| ((xy_modEq_yn a1 n (yn a1 n)).right.of_dvd <| by simp [_root_.pow_succ]).trans (modEq_zero_iff_dvd.2 <| by simp [mul_dvd_mul_left, mul_assoc])
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
ysq_dvd_yy
null
dvd_of_ysq_dvd {n t} (h : yn a1 n * yn a1 n ∣ yn a1 t) : yn a1 n ∣ t := have nt : n ∣ t := (y_dvd_iff a1 n t).1 <| dvd_of_mul_left_dvd h n.eq_zero_or_pos.elim (fun n0 => by rwa [n0] at nt ⊢) fun n0l : 0 < n => by let ⟨k, ke⟩ := nt have : yn a1 n ∣ k * xn a1 n ^ (k - 1) := Nat.dvd_of_mul_dvd_mul_right ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
dvd_of_ysq_dvd
null
pellZd_succ_succ (n) : pellZd a1 (n + 2) + pellZd a1 n = (2 * a : ℕ) * pellZd a1 (n + 1) := by have : (1 : ℤ√(d a1)) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a) := by rw [Zsqrtd.natCast_val] change (⟨_, _⟩ : ℤ√(d a1)) = ⟨_, _⟩ rw [dz_val] dsimp [az] ext <;> dsimp <;> ring_nf simpa [mul_add, mul_com...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
pellZd_succ_succ
null
xy_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) ∧ yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := by have := pellZd_succ_succ a1 n; unfold pellZd at this rw [Zsqrtd.nsmul_val (2 * a : ℕ)] at this injection this with h₁ h₂ grind
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xy_succ_succ
null
xn_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) := (xy_succ_succ a1 n).1
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_succ_succ
null
yn_succ_succ (n) : yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := (xy_succ_succ a1 n).2
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_succ_succ
null
xz_succ_succ (n) : xz a1 (n + 2) = (2 * a : ℕ) * xz a1 (n + 1) - xz a1 n := eq_sub_of_add_eq <| by delta xz; rw [← Int.natCast_add, ← Int.natCast_mul, xn_succ_succ]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xz_succ_succ
null
yz_succ_succ (n) : yz a1 (n + 2) = (2 * a : ℕ) * yz a1 (n + 1) - yz a1 n := eq_sub_of_add_eq <| by delta yz; rw [← Int.natCast_add, ← Int.natCast_mul, yn_succ_succ]
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yz_succ_succ
null
yn_modEq_a_sub_one : ∀ n, yn a1 n ≡ n [MOD a - 1] | 0 => by simp [Nat.ModEq.refl] | 1 => by simp [Nat.ModEq.refl] | n + 2 => (yn_modEq_a_sub_one n).add_right_cancel <| by rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))] exact ((modEq_sub a1.le).mul_left 2).mul (yn_modEq_a_sub_one (n + 1))
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_modEq_a_sub_one
null
yn_modEq_two : ∀ n, yn a1 n ≡ n [MOD 2] | 0 => by rfl | 1 => by simp [Nat.ModEq.refl] | n + 2 => (yn_modEq_two n).add_right_cancel <| by rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))] exact (dvd_mul_right 2 _).modEq_zero_nat.trans (dvd_mul_right 2 _).zero_modEq_nat
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
yn_modEq_two
null
x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) : (a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) = y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
x_sub_y_dvd_pow_lem
null
x_sub_y_dvd_pow (y : ℕ) : ∀ n, (2 * a * y - y * y - 1 : ℤ) ∣ yz a1 n * (a - y) + ↑(y ^ n) - xz a1 n | 0 => by simp [xz, yz] | 1 => by simp [xz, yz] | n + 2 => by have : (2 * a * y - y * y - 1 : ℤ) ∣ ↑(y ^ (n + 2)) - ↑(2 * a) * ↑(y ^ (n + 1)) + ↑(y ^ n) := ⟨-↑(y ^ n), by simp [_root_.pow_succ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
x_sub_y_dvd_pow
null
xn_modEq_x2n_add_lem (n j) : xn a1 n ∣ d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j := by have h1 : d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j = (d a1 * yn a1 n * yn a1 n + 1) * xn a1 j := by simp [add_mul, mul_assoc] have h2 : d a1 * yn a1 n * yn a1 n + 1 = xn a1 n * xn a1 n := by zify at * ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_modEq_x2n_add_lem
null
xn_modEq_x2n_add (n j) : xn a1 (2 * n + j) + xn a1 j ≡ 0 [MOD xn a1 n] := by rw [two_mul, add_assoc, xn_add, add_assoc, ← zero_add 0] refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modEq_zero_nat.add ?_ rw [yn_add, left_distrib, add_assoc, ← zero_add 0] exact ((dvd_mul_right _ _).mul_left _).modEq_zero_na...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_modEq_x2n_add
null
xn_modEq_x2n_sub_lem {n j} (h : j ≤ n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := by have h1 : xz a1 n ∣ d a1 * yz a1 n * yz a1 (n - j) + xz a1 j := by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub] exact dvd_sub (by delta xz; delta yz rw [mul_comm (xn _ _ ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_modEq_x2n_sub_lem
null
xn_modEq_x2n_sub {n j} (h : j ≤ 2 * n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := (le_total j n).elim (xn_modEq_x2n_sub_lem a1) fun jn => by have : 2 * n - j + j ≤ n + j := by rw [tsub_add_cancel_of_le h, two_mul]; exact Nat.add_le_add_left jn _ let t := xn_modEq_x2n_sub_lem a1 (Nat.le_of_add_le...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_modEq_x2n_sub
null
xn_modEq_x4n_add (n j) : xn a1 (4 * n + j) ≡ xn a1 j [MOD xn a1 n] := ModEq.add_right_cancel' (xn a1 (2 * n + j)) <| by refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_add _ _ _).symm) rw [show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n, add_assoc] apply xn_modEq_x2n_add
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_modEq_x4n_add
null
xn_modEq_x4n_sub {n j} (h : j ≤ 2 * n) : xn a1 (4 * n - j) ≡ xn a1 j [MOD xn a1 n] := have h' : j ≤ 2 * n := le_trans h (by rw [Nat.succ_mul]) ModEq.add_right_cancel' (xn a1 (2 * n - j)) <| by refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_sub _ h).symm) rw [show 4 * n = 2 * n + 2 * n...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xn_modEq_x4n_sub
null
eq_of_xn_modEq_lem1 {i n} : ∀ {j}, i < j → j < n → xn a1 i % xn a1 n < xn a1 j % xn a1 n | 0, ij, _ => absurd ij (Nat.not_lt_zero _) | j + 1, ij, jn => by suffices xn a1 j % xn a1 n < xn a1 (j + 1) % xn a1 n from (lt_or_eq_of_le (Nat.le_of_succ_le_succ ij)).elim (fun h => lt_trans (eq_of_xn_modEq_...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_of_xn_modEq_lem1
null
eq_of_xn_modEq_lem2 {n} (h : 2 * xn a1 n = xn a1 (n + 1)) : a = 2 ∧ n = 0 := by rw [xn_succ, mul_comm] at h have : n = 0 := n.eq_zero_or_pos.resolve_right fun np => _root_.ne_of_lt (lt_of_le_of_lt (Nat.mul_le_mul_left _ a1) (Nat.lt_add_of_pos_right <| mul_pos (d_pos a1) (strictMono_y a1 ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_of_xn_modEq_lem2
null
eq_of_xn_modEq_lem3 {i n} (npos : 0 < n) : ∀ {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → xn a1 i % xn a1 n < xn a1 j % xn a1 n | 0, ij, _, _, _ => absurd ij (Nat.not_lt_zero _) | j + 1, ij, j2n, jnn, ntriv => have lem2 : ∀ k > n, k ≤ 2 * n → (↑(xn a1 k % xn a1 n) : ℤ) = ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_of_xn_modEq_lem3
null
eq_of_xn_modEq_le {i j n} (ij : i ≤ j) (j2n : j ≤ 2 * n) (h : xn a1 i ≡ xn a1 j [MOD xn a1 n]) (ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j := if npos : n = 0 then by simp_all else (lt_or_eq_of_le ij).resolve_left fun ij' => if jn : j = n then by refine _root_.ne_of_gt ?_ h r...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_of_xn_modEq_le
null
eq_of_xn_modEq {i j n} (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n) (h : xn a1 i ≡ xn a1 j [MOD xn a1 n]) (ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j := (le_total i j).elim (fun ij => eq_of_xn_modEq_le a1 ij j2n h fun ⟨a2, n1, i0, j2⟩ => (ntriv a2 n1).left i0 j2) fun ij => (eq_of_xn...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_of_xn_modEq
null
eq_of_xn_modEq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n) (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j = i ∨ j + i = 4 * n := have i2n : i ≤ 2 * n := by apply le_trans hin; rw [two_mul]; apply Nat.le_add_left (le_or_gt j (2 * n)).imp (fun j2n : j ≤ 2 * n => eq_of_xn_modEq a1 j2n i2n h fun _ ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_of_xn_modEq'
null
modEq_of_xn_modEq {i j n} (ipos : 0 < i) (hin : i ≤ n) (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] := let j' := j % (4 * n) have n4 : 0 < 4 * n := mul_pos (by decide) (ipos.trans_le hin) have jl : j' < 4 * n := Nat.mod_lt _ n4 have jj : j ≡ j' [MOD 4 * n] := by delt...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
modEq_of_xn_modEq
null
xy_modEq_of_modEq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) : ∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c] | 0 => by simp [Nat.ModEq.refl] | 1 => by simpa [Nat.ModEq.refl] | n + 2 => ⟨(xy_modEq_of_modEq a1 b1 h n).left.add_right_cancel <| by rw [xn_succ_succ a1, xn_succ_s...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
xy_modEq_of_modEq
null
matiyasevic {a k x y} : (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔ 1 < a ∧ k ≤ y ∧ (x = 1 ∧ y = 0 ∨ ∃ u v s t b : ℕ, x * x - (a * a - 1) * y * y = 1 ∧ u * u - (a * a - 1) * v * v = 1 ∧ s * s - (b * b - 1) * t * t = 1 ∧ 1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧ 0 < v ∧ ...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
matiyasevic
null
eq_pow_of_pell_lem {a y k : ℕ} (hy0 : y ≠ 0) (hk0 : k ≠ 0) (hyk : y ^ k < a) : (↑(y ^ k) : ℤ) < 2 * a * y - y * y - 1 := have hya : y < a := (Nat.le_self_pow hk0 _).trans_lt hyk calc (↑(y ^ k) : ℤ) < a := Nat.cast_lt.2 hyk _ ≤ (a : ℤ) ^ 2 - (a - 1 : ℤ) ^ 2 - 1 := by rw [sub_sq, mul_one, one_pow, s...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_pow_of_pell_lem
null
eq_pow_of_pell {m n k} : n ^ k = m ↔ k = 0 ∧ m = 1 ∨0 < k ∧ (n = 0 ∧ m = 0 ∨ 0 < n ∧ ∃ (w a t z : ℕ) (a1 : 1 < a), xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧ 2 * a * n = t + (n * n + 1) ∧ m < t ∧ n ≤ w ∧ k ≤ w ∧ a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1) := by constructor · rintro...
theorem
NumberTheory
[ "Mathlib.Data.Nat.ModEq", "Mathlib.Data.Nat.Prime.Basic", "Mathlib.NumberTheory.Zsqrtd.Basic" ]
Mathlib/NumberTheory/PellMatiyasevic.lean
eq_pow_of_pell
null
pow_totient_mod_eq_one {x n : ℕ} (hn : 1 < n) (h : x.Coprime n) : (x ^ φ n) % n = 1 := by exact mod_eq_of_modEq (ModEq.pow_totient h) hn
lemma
NumberTheory
[ "Mathlib.FieldTheory.Finite.Basic" ]
Mathlib/NumberTheory/PowModTotient.lean
pow_totient_mod_eq_one
null
pow_add_totient_mod_eq {x k n : ℕ} (hn : 1 < n) (h : x.Coprime n) : (x ^ (k + φ n)) % n = (x ^ k) % n := by rw [pow_add, mul_mod, pow_totient_mod_eq_one hn h] simp only [mul_one, dvd_refl, mod_mod_of_dvd]
lemma
NumberTheory
[ "Mathlib.FieldTheory.Finite.Basic" ]
Mathlib/NumberTheory/PowModTotient.lean
pow_add_totient_mod_eq
null
pow_add_mul_totient_mod_eq {x k l n : ℕ} (hn : 1 < n) (h : x.Coprime n) : (x ^ (k + l * φ n)) % n = (x ^ k) % n := by induction l with | zero => simp | succ l ih => rw [add_mul, one_mul, ← add_assoc, pow_add_totient_mod_eq hn h, ih]
lemma
NumberTheory
[ "Mathlib.FieldTheory.Finite.Basic" ]
Mathlib/NumberTheory/PowModTotient.lean
pow_add_mul_totient_mod_eq
null
pow_totient_mod {x k n : ℕ} (hn : 1 < n) (h : x.Coprime n) : x ^ k % n = x ^ (k % φ n) % n := by rw [← div_add_mod' k (φ n), add_comm, pow_add_mul_totient_mod_eq hn h, add_mul_mod_self_right, mod_mod k (φ n)]
lemma
NumberTheory
[ "Mathlib.FieldTheory.Finite.Basic" ]
Mathlib/NumberTheory/PowModTotient.lean
pow_totient_mod
null
primeCounting' : ℕ → ℕ := Nat.count Prime
def
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting'
A variant of the traditional prime counting function which gives the number of primes *strictly* less than the input. More convenient for avoiding off-by-one errors. With `open scoped Nat.Prime`, this has notation `π'`.
primeCounting (n : ℕ) : ℕ := primeCounting' (n + 1) @[inherit_doc] scoped[Nat.Prime] notation "π" => Nat.primeCounting @[inherit_doc] scoped[Nat.Prime] notation "π'" => Nat.primeCounting' open scoped Nat.Prime @[simp]
def
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting
The prime counting function: Returns the number of primes less than or equal to the input. With `open scoped Nat.Prime`, this has notation `π`.
primeCounting_sub_one (n : ℕ) : π (n - 1) = π' n := by cases n <;> rfl
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting_sub_one
null
monotone_primeCounting' : Monotone primeCounting' := count_monotone Prime
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
monotone_primeCounting'
null
monotone_primeCounting : Monotone primeCounting := monotone_primeCounting'.comp (monotone_id.add_const _) @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
monotone_primeCounting
null
primeCounting'_nth_eq (n : ℕ) : π' (nth Prime n) = n := count_nth_of_infinite infinite_setOf_prime _
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting'_nth_eq
null
add_two_le_nth_prime (n : ℕ) : n + 2 ≤ nth Prime n := nth_prime_zero_eq_two ▸ (nth_strictMono infinite_setOf_prime).add_le_nat n 0
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
add_two_le_nth_prime
The `n`th prime is greater or equal to `n + 2`.
surjective_primeCounting' : Function.Surjective π' := Nat.surjective_count_of_infinite_setOf infinite_setOf_prime
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
surjective_primeCounting'
null
surjective_primeCounting : Function.Surjective π := by suffices Function.Surjective (π ∘ fun n => n - 1) from this.of_comp convert surjective_primeCounting' ext exact primeCounting_sub_one _ open Filter
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
surjective_primeCounting
null
tendsto_primeCounting' : Tendsto π' atTop atTop := by apply tendsto_atTop_atTop_of_monotone' monotone_primeCounting' simp [Set.range_eq_univ.mpr surjective_primeCounting']
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
tendsto_primeCounting'
null
tendsto_primeCounting : Tendsto π atTop atTop := (tendsto_add_atTop_iff_nat 1).mpr tendsto_primeCounting' @[deprecated (since := "2025-07-08")] alias tensto_primeCounting := tendsto_primeCounting @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
tendsto_primeCounting
null
prime_nth_prime (n : ℕ) : Prime (nth Prime n) := nth_mem_of_infinite infinite_setOf_prime _ @[simp]
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
prime_nth_prime
null
primeCounting'_eq_zero_iff {n : ℕ} : n.primeCounting' = 0 ↔ n ≤ 2 := by rw [primeCounting', Nat.count_eq_zero ⟨_, Nat.prime_two⟩, Nat.nth_prime_zero_eq_two] @[simp]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting'_eq_zero_iff
null
primeCounting_eq_zero_iff {n : ℕ} : n.primeCounting = 0 ↔ n ≤ 1 := by simp [primeCounting] @[simp]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting_eq_zero_iff
null
primeCounting_zero : primeCounting 0 = 0 := primeCounting_eq_zero_iff.mpr zero_le_one @[simp]
lemma
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting_zero
null
primeCounting_one : primeCounting 1 = 0 := primeCounting_eq_zero_iff.mpr le_rfl
lemma
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting_one
null
primesBelow_card_eq_primeCounting' (n : ℕ) : #n.primesBelow = primeCounting' n := by simp only [primesBelow, primeCounting'] exact (count_eq_card_filter_range Prime n).symm
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primesBelow_card_eq_primeCounting'
The cardinality of the finset `primesBelow n` equals the counting function `primeCounting'` at `n`.
primeCounting'_add_le {a k : ℕ} (h0 : a ≠ 0) (h1 : a < k) (n : ℕ) : π' (k + n) ≤ π' k + Nat.totient a * (n / a + 1) := calc π' (k + n) ≤ #{p ∈ range k | p.Prime} + #{p ∈ Ico k (k + n) | p.Prime} := by rw [primeCounting', count_eq_card_filter_range, range_eq_Ico, ← Ico_union_Ico_eq_Ico (zero_le k...
theorem
NumberTheory
[ "Mathlib.Data.Nat.Prime.Nth", "Mathlib.Data.Nat.Totient", "Mathlib.NumberTheory.SmoothNumbers", "Mathlib.Order.Filter.AtTopBot.Basic" ]
Mathlib/NumberTheory/PrimeCounting.lean
primeCounting'_add_le
A linear upper bound on the size of the `primeCounting'` function
exists_prime_gt_modEq_one {k : ℕ} (n : ℕ) (hk0 : k ≠ 0) : ∃ p : ℕ, Nat.Prime p ∧ n < p ∧ p ≡ 1 [MOD k] := by rcases (one_le_iff_ne_zero.2 hk0).eq_or_lt with (rfl | hk1) · rcases exists_infinite_primes (n + 1) with ⟨p, hnp, hp⟩ exact ⟨p, hp, hnp, modEq_one⟩ let b := k * (n !) have hgt : 1 < (eval (↑b) (c...
theorem
NumberTheory
[ "Mathlib.RingTheory.Polynomial.Cyclotomic.Eval" ]
Mathlib/NumberTheory/PrimesCongruentOne.lean
exists_prime_gt_modEq_one
For any positive `k : ℕ` there exists an arbitrarily large prime `p` such that `p ≡ 1 [MOD k]`.
frequently_atTop_modEq_one {k : ℕ} (hk0 : k ≠ 0) : ∃ᶠ p in atTop, Nat.Prime p ∧ p ≡ 1 [MOD k] := by refine frequently_atTop.2 fun n => ?_ obtain ⟨p, hp⟩ := exists_prime_gt_modEq_one n hk0 exact ⟨p, ⟨hp.2.1.le, hp.1, hp.2.2⟩⟩
theorem
NumberTheory
[ "Mathlib.RingTheory.Polynomial.Cyclotomic.Eval" ]
Mathlib/NumberTheory/PrimesCongruentOne.lean
frequently_atTop_modEq_one
null
infinite_setOf_prime_modEq_one {k : ℕ} (hk0 : k ≠ 0) : Set.Infinite {p : ℕ | Nat.Prime p ∧ p ≡ 1 [MOD k]} := frequently_atTop_iff_infinite.1 (frequently_atTop_modEq_one hk0)
theorem
NumberTheory
[ "Mathlib.RingTheory.Polynomial.Cyclotomic.Eval" ]
Mathlib/NumberTheory/PrimesCongruentOne.lean
infinite_setOf_prime_modEq_one
For any positive `k : ℕ` there are infinitely many primes `p` such that `p ≡ 1 [MOD k]`.
primorial (n : ℕ) : ℕ := ∏ p ∈ range (n + 1) with p.Prime, p local notation x "#" => primorial x
def
NumberTheory
[ "Mathlib.Algebra.BigOperators.Associated", "Mathlib.Algebra.Order.BigOperators.Ring.Finset", "Mathlib.Algebra.Order.Ring.Abs", "Mathlib.Data.Nat.Choose.Sum", "Mathlib.Data.Nat.Choose.Dvd", "Mathlib.Data.Nat.Prime.Basic" ]
Mathlib/NumberTheory/Primorial.lean
primorial
The primorial `n#` of `n` is the product of the primes less than or equal to `n`.
primorial_pos (n : ℕ) : 0 < n# := prod_pos fun _p hp ↦ (mem_filter.1 hp).2.pos
theorem
NumberTheory
[ "Mathlib.Algebra.BigOperators.Associated", "Mathlib.Algebra.Order.BigOperators.Ring.Finset", "Mathlib.Algebra.Order.Ring.Abs", "Mathlib.Data.Nat.Choose.Sum", "Mathlib.Data.Nat.Choose.Dvd", "Mathlib.Data.Nat.Prime.Basic" ]
Mathlib/NumberTheory/Primorial.lean
primorial_pos
null
primorial_succ {n : ℕ} (hn1 : n ≠ 1) (hn : Odd n) : (n + 1)# = n# := by refine prod_congr ?_ fun _ _ ↦ rfl rw [range_add_one, filter_insert, if_neg fun h ↦ not_even_iff_odd.2 hn _] exact fun h ↦ h.even_sub_one <| mt succ.inj hn1
theorem
NumberTheory
[ "Mathlib.Algebra.BigOperators.Associated", "Mathlib.Algebra.Order.BigOperators.Ring.Finset", "Mathlib.Algebra.Order.Ring.Abs", "Mathlib.Data.Nat.Choose.Sum", "Mathlib.Data.Nat.Choose.Dvd", "Mathlib.Data.Nat.Prime.Basic" ]
Mathlib/NumberTheory/Primorial.lean
primorial_succ
null
primorial_add (m n : ℕ) : (m + n)# = m# * ∏ p ∈ Ico (m + 1) (m + n + 1) with p.Prime, p := by rw [primorial, primorial, ← Ico_zero_eq_range, ← prod_union, ← filter_union, Ico_union_Ico_eq_Ico] exacts [Nat.zero_le _, add_le_add_right (Nat.le_add_right _ _) _, disjoint_filter_filter <| Ico_disjoint_Ico_consec...
theorem
NumberTheory
[ "Mathlib.Algebra.BigOperators.Associated", "Mathlib.Algebra.Order.BigOperators.Ring.Finset", "Mathlib.Algebra.Order.Ring.Abs", "Mathlib.Data.Nat.Choose.Sum", "Mathlib.Data.Nat.Choose.Dvd", "Mathlib.Data.Nat.Prime.Basic" ]
Mathlib/NumberTheory/Primorial.lean
primorial_add
null
primorial_add_dvd {m n : ℕ} (h : n ≤ m) : (m + n)# ∣ m# * choose (m + n) m := calc (m + n)# = m# * ∏ p ∈ Ico (m + 1) (m + n + 1) with p.Prime, p := primorial_add _ _ _ ∣ m# * choose (m + n) m := mul_dvd_mul_left _ <| prod_primes_dvd _ (fun _ hk ↦ (mem_filter.1 hk).2.prime) fun p hp ↦ by ...
theorem
NumberTheory
[ "Mathlib.Algebra.BigOperators.Associated", "Mathlib.Algebra.Order.BigOperators.Ring.Finset", "Mathlib.Algebra.Order.Ring.Abs", "Mathlib.Data.Nat.Choose.Sum", "Mathlib.Data.Nat.Choose.Dvd", "Mathlib.Data.Nat.Prime.Basic" ]
Mathlib/NumberTheory/Primorial.lean
primorial_add_dvd
null
primorial_add_le {m n : ℕ} (h : n ≤ m) : (m + n)# ≤ m# * choose (m + n) m := le_of_dvd (mul_pos (primorial_pos _) (choose_pos <| Nat.le_add_right _ _)) (primorial_add_dvd h)
theorem
NumberTheory
[ "Mathlib.Algebra.BigOperators.Associated", "Mathlib.Algebra.Order.BigOperators.Ring.Finset", "Mathlib.Algebra.Order.Ring.Abs", "Mathlib.Data.Nat.Choose.Sum", "Mathlib.Data.Nat.Choose.Dvd", "Mathlib.Data.Nat.Prime.Basic" ]
Mathlib/NumberTheory/Primorial.lean
primorial_add_le
null
primorial_le_4_pow (n : ℕ) : n# ≤ 4 ^ n := by induction n using Nat.strong_induction_on with | h n ihn => rcases n with - | n; · rfl rcases n.even_or_odd with (⟨m, rfl⟩ | ho) · rcases m.eq_zero_or_pos with (rfl | hm) · decide calc (m + m + 1)# = (m + 1 + m)# := by rw [add_right_comm] _ ≤ (m ...
theorem
NumberTheory
[ "Mathlib.Algebra.BigOperators.Associated", "Mathlib.Algebra.Order.BigOperators.Ring.Finset", "Mathlib.Algebra.Order.Ring.Abs", "Mathlib.Data.Nat.Choose.Sum", "Mathlib.Data.Nat.Choose.Dvd", "Mathlib.Data.Nat.Prime.Basic" ]
Mathlib/NumberTheory/Primorial.lean
primorial_le_4_pow
null
sq_ne_two_fin_zmod_four (z : ZMod 4) : z * z ≠ 2 := by change Fin 4 at z fin_cases z <;> decide
theorem
NumberTheory
[ "Mathlib.Data.Int.NatPrime", "Mathlib.Data.ZMod.Basic", "Mathlib.RingTheory.Int.Basic", "Mathlib.Tactic.FieldSimp" ]
Mathlib/NumberTheory/PythagoreanTriples.lean
sq_ne_two_fin_zmod_four
null