The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V12. Number theory

Mathlib.NumberTheory.PrimeCounting

59 declarations. Mathlib docs · Source

The Prime Counting Function

In this file we define the prime counting function: the function on natural numbers that returns the number of primes less than or equal to its input.

Main Results

The main definitions for this file are

  • Nat.primeCounting: The prime counting function π
  • Nat.primeCounting': π(n - 1)
  • Nat.primesBelow: The finset of primes less than n (this was previously in Mathlib.NumberTheory.SmoothNumbers)
  • Nat.primesLE: The finset of primes less than or equal to n

We then prove that these are monotone in Nat.monotone_primeCounting and Nat.monotone_primeCounting'. The last main theorem Nat.primeCounting'_add_le is an upper bound on π' which arises by observing that all numbers greater than k and not coprime to k are not prime, and so only at most φ(k)/k fraction of the numbers from k to n are prime.

Notation

With open scoped Nat.Prime, we use the standard notation π to represent the prime counting function (and π' to represent the reindexed version).

def Nat.primeCounting' E3 #

ℕ → ℕ

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 π'.

def Nat.primeCounting E3 #

ℕ → ℕ

The prime counting function: Returns the number of primes less than or equal to the input.

With open scoped Nat.Prime, this has notation π.

def Nat.Prime.termπ E1 #

Lean.ParserDescr

The prime counting function: Returns the number of primes less than or equal to the input.

With open scoped Nat.Prime, this has notation π.

def Nat.Prime.termπ' E1 #

Lean.ParserDescr

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 π'.

theorem Nat.primeCounting_eq_primeCounting'_succ E1 #

∀ (n : ℕ), n.primeCounting = (n + 1).primeCounting'

theorem Nat.primeCounting_sub_one E0 #

∀ (n : ℕ), (n - 1).primeCounting = n.primeCounting'

theorem Nat.monotone_primeCounting' E3 #

Monotone Nat.primeCounting'

theorem Nat.monotone_primeCounting E3 #

Monotone Nat.primeCounting

theorem Nat.primeCounting'_nth_eq E0 #

∀ (n : ℕ), (Nat.nth Nat.Prime n).primeCounting' = n

theorem Nat.add_two_le_nth_prime E1 #

∀ (n : ℕ), n + 2 ≤ Nat.nth Nat.Prime n

The nth prime is greater or equal to n + 2.

theorem Nat.surjective_primeCounting' E1 #

Function.Surjective Nat.primeCounting'

theorem Nat.surjective_primeCounting E1 #

Function.Surjective Nat.primeCounting

theorem Nat.tendsto_primeCounting' E1 #

Filter.Tendsto Nat.primeCounting' Filter.atTop Filter.atTop

theorem Nat.tendsto_primeCounting E1 #

Filter.Tendsto Nat.primeCounting Filter.atTop Filter.atTop

theorem Nat.prime_nth_prime E0 #

∀ (n : ℕ), Nat.Prime (Nat.nth Nat.Prime n)

theorem Nat.primeCounting'_eq_zero_iff E0 #

∀ {n : ℕ}, n.primeCounting' = 0 ↔ n ≤ 2

theorem Nat.primeCounting_eq_zero_iff E0 #

∀ {n : ℕ}, n.primeCounting = 0 ↔ n ≤ 1

theorem Nat.primeCounting_zero E0 #

Nat.primeCounting 0 = 0

theorem Nat.primeCounting_one E0 #

Nat.primeCounting 1 = 0

def Nat.primesBelow E3 #

ℕ → Finset ℕ

primesBelow n is the set of primes less than n as a Finset.

def Nat.primesLE E3 #

ℕ → Finset ℕ

primesLE n is the set of primes less than or equal to n as a Finset.

theorem Nat.primesBelow_eq_filter_range E1 #

∀ (n : ℕ), n.primesBelow = Finset.filter Nat.Prime (Finset.range n)

theorem Nat.primesLE_eq_filter_range E1 #

∀ (n : ℕ), n.primesLE = Finset.filter Nat.Prime (Finset.range (n + 1))

theorem Nat.primesBelow_zero E0 #

Nat.primesBelow 0 = ∅

theorem Nat.primesBelow_one E0 #

Nat.primesBelow 1 = ∅

theorem Nat.primesBelow_two E0 #

Nat.primesBelow 2 = ∅

theorem Nat.primesLE_zero E0 #

Nat.primesLE 0 = ∅

theorem Nat.primesLE_one E0 #

Nat.primesLE 1 = ∅

theorem Nat.primesBelow_eq_primesLE_sub_one E1 #

∀ (n : ℕ), n.primesBelow = (n - 1).primesLE

theorem Nat.mem_primesBelow E0 #

∀ {k n : ℕ}, n ∈ k.primesBelow ↔ n < k ∧ Nat.Prime n

theorem Nat.mem_primesLE E0 #

∀ {p n : ℕ}, p ∈ n.primesLE ↔ p ≤ n ∧ Nat.Prime p

theorem Nat.prime_of_mem_primesBelow E1 #

∀ {p n : ℕ}, p ∈ n.primesBelow → Nat.Prime p

theorem Nat.prime_of_mem_primesLE E1 #

∀ {p n : ℕ}, p ∈ n.primesLE → Nat.Prime p

theorem Nat.lt_of_mem_primesBelow E1 #

∀ {p n : ℕ}, p ∈ n.primesBelow → p < n

theorem Nat.le_of_mem_primesLE E1 #

∀ {p n : ℕ}, p ∈ n.primesLE → p ≤ n

theorem Nat.one_lt_of_mem_primesBelow E1 #

∀ {p n : ℕ}, p ∈ n.primesBelow → 1 < p

theorem Nat.one_lt_of_mem_primesLE E1 #

∀ {p n : ℕ}, p ∈ n.primesLE → 1 < p

theorem Nat.two_le_of_mem_primesBelow E1 #

∀ {p n : ℕ}, p ∈ n.primesBelow → 2 ≤ p

theorem Nat.two_le_of_mem_primesLE E1 #

∀ {p n : ℕ}, p ∈ n.primesLE → 2 ≤ p

theorem Nat.primesBelow_eq_filter_Ico_zero E1 #

∀ (n : ℕ), n.primesBelow = Finset.filter Nat.Prime (Finset.Ico 0 n)

theorem Nat.primesLE_eq_filter_Icc_zero E1 #

∀ (n : ℕ), n.primesLE = Finset.filter Nat.Prime (Finset.Icc 0 n)

theorem Nat.primesBelow_eq_filter_Ioo_zero E1 #

∀ (n : ℕ), n.primesBelow = Finset.filter Nat.Prime (Finset.Ioo 0 n)

theorem Nat.primesLE_eq_filter_Ioc_zero E1 #

∀ (n : ℕ), n.primesLE = Finset.filter Nat.Prime (Finset.Ioc 0 n)

theorem Nat.primesBelow_eq_filter_Ico_one E1 #

∀ (n : ℕ), n.primesBelow = Finset.filter Nat.Prime (Finset.Ico 1 n)

theorem Nat.primesLE_eq_filter_Icc_one E1 #

∀ (n : ℕ), n.primesLE = Finset.filter Nat.Prime (Finset.Icc 1 n)

theorem Nat.primesBelow_eq_filter_Ioo_one E1 #

∀ (n : ℕ), n.primesBelow = Finset.filter Nat.Prime (Finset.Ioo 1 n)

theorem Nat.primesLE_eq_filter_Ioc_one E1 #

∀ (n : ℕ), n.primesLE = Finset.filter Nat.Prime (Finset.Ioc 1 n)

theorem Nat.primesBelow_eq_filter_Ico_two E1 #

∀ (n : ℕ), n.primesBelow = Finset.filter Nat.Prime (Finset.Ico 2 n)

theorem Nat.primesLE_eq_filter_Icc_two E1 #

∀ (n : ℕ), n.primesLE = Finset.filter Nat.Prime (Finset.Icc 2 n)

theorem Nat.primesBelow_mono E1 #

Monotone Nat.primesBelow

theorem Nat.primesLE_mono E1 #

Monotone Nat.primesLE

theorem Nat.primesBelow_succ E1 #

∀ (n : ℕ), (n + 1).primesBelow = if Nat.Prime n then insert n n.primesBelow else n.primesBelow

theorem Nat.primesLE_succ E1 #

∀ (n : ℕ), (n + 1).primesLE = if Nat.Prime (n + 1) then insert (n + 1) n.primesLE else n.primesLE

theorem Nat.notMem_primesBelow E1 #

∀ (n : ℕ), n ∉ n.primesBelow

theorem Nat.notMem_primesLE E1 #

∀ (n : ℕ), n + 1 ∉ n.primesLE

theorem Nat.primesBelow_card_eq_primeCounting' E1 #

∀ (n : ℕ), n.primesBelow.card = n.primeCounting'

The cardinality of the finset primesBelow n equals the counting function primeCounting' at n.

theorem Nat.primesLE_card_eq_primeCounting E0 #

∀ (n : ℕ), n.primesLE.card = n.primeCounting

The cardinality of the finset primesLE n equals the counting function primeCounting at n.

theorem Nat.primeCounting'_add_le E3 #

∀ {a k : ℕ}, a ≠ 0 → a < k → ∀ (n : ℕ), (k + n).primeCounting' ≤ k.primeCounting' + a.totient * (n / a + 1)

A linear upper bound on the size of the primeCounting' function

theorem Nat.primeCounting_add_le E1 #

∀ {a k : ℕ}, a ≠ 0 → a ≤ k → ∀ (n : ℕ), (k + n).primeCounting ≤ k.primeCounting + a.totient * (n / a + 1)