Skip to content

Commit

Permalink
feat(NumberTheory/PrimeCounting): surjective and tendsto (#17006)
Browse files Browse the repository at this point in the history
Co-authored-by: Moritz Firsching <[email protected]>
  • Loading branch information
mo271 and mo271 committed Sep 24, 2024
1 parent f4a9481 commit d6fde79
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Mathlib/Data/Nat/Nth.lean
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ theorem count_nth_of_lt_card_finite {n : ℕ} (hp : (setOf p).Finite) (hlt : n <
theorem count_nth_of_infinite (hp : (setOf p).Infinite) (n : ℕ) : count p (nth p n) = n :=
count_nth fun hf => absurd hf hp

theorem surjective_count_of_infinite_setOf (h : {n | p n}.Infinite) :
Function.Surjective (Nat.count p) :=
fun n => ⟨nth p n, count_nth_of_infinite h n⟩

theorem count_nth_succ {n : ℕ} (hn : ∀ hf : (setOf p).Finite, n < hf.toFinset.card) :
count p (nth p n + 1) = n + 1 := by rw [count_succ, count_nth hn, if_pos (nth_mem _ hn)]

Expand Down
40 changes: 31 additions & 9 deletions Mathlib/NumberTheory/PrimeCounting.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Copyright (c) 2021 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Ralf Stephan
-/
import Mathlib.Data.Nat.Totient
import Mathlib.Data.Nat.Nth
import Mathlib.Data.Nat.Totient
import Mathlib.NumberTheory.SmoothNumbers

/-!
Expand Down Expand Up @@ -56,6 +56,10 @@ def primeCounting (n : ℕ) : ℕ :=

open scoped Nat.Prime

@[simp]
theorem primeCounting_sub_one (n : ℕ) : π (n - 1) = π' n := by
cases n <;> rfl

theorem monotone_primeCounting' : Monotone primeCounting' :=
count_monotone Prime

Expand All @@ -66,13 +70,38 @@ theorem monotone_primeCounting : Monotone primeCounting :=
theorem primeCounting'_nth_eq (n : ℕ) : π' (nth Prime n) = n :=
count_nth_of_infinite infinite_setOf_prime _

@[simp]
theorem zeroth_prime_eq_two : nth Prime 0 = 2 := nth_count prime_two

/-- The `n`th prime is greater or equal to `n + 2`. -/
theorem add_two_le_nth_prime (n : ℕ) : n + 2 ≤ nth Prime n :=
zeroth_prime_eq_two ▸ (nth_strictMono infinite_setOf_prime).add_le_nat n 0

theorem surjective_primeCounting' : Function.Surjective π' :=
Nat.surjective_count_of_infinite_setOf infinite_setOf_prime

theorem 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 tendsto_primeCounting' : Tendsto π' atTop atTop := by
apply tendsto_atTop_atTop_of_monotone' monotone_primeCounting'
simp [Set.range_iff_surjective.mpr surjective_primeCounting']

theorem tensto_primeCounting : Tendsto π atTop atTop :=
(tendsto_add_atTop_iff_nat 1).mpr tendsto_primeCounting'

@[simp]
theorem prime_nth_prime (n : ℕ) : Prime (nth Prime n) :=
nth_mem_of_infinite infinite_setOf_prime _

/-- The cardinality of the finset `primesBelow n` equals the counting function
`primeCounting'` at `n`. -/
lemma primesBelow_card_eq_primeCounting' (n : ℕ) : n.primesBelow.card = primeCounting' n := by
theorem primesBelow_card_eq_primeCounting' (n : ℕ) : n.primesBelow.card = primeCounting' n := by
simp only [primesBelow, primeCounting']
exact (count_eq_card_filter_range Prime n).symm

Expand All @@ -98,11 +127,4 @@ theorem primeCounting'_add_le {a k : ℕ} (h0 : 0 < a) (h1 : a < k) (n : ℕ) :
rw [add_le_add_iff_left]
exact Ico_filter_coprime_le k n h0

@[simp]
theorem zeroth_prime_eq_two : nth Prime 0 = 2 := nth_count prime_two

/-- The `n`th prime is greater or equal to `n + 2`. -/
lemma add_two_le_nth_prime (n : ℕ) : n + 2 ≤ nth Prime n :=
zeroth_prime_eq_two ▸ (nth_strictMono infinite_setOf_prime).add_le_nat n 0

end Nat

0 comments on commit d6fde79

Please sign in to comment.