Ramanujan's Notebooks, Part IV, Ch. 24: ch24PrimeCount
DefinitionRamanujanNotebooks_ch24_ch24PrimeCountnumber-theoryramanujan-notebooks
Number of primes p ≤ n, for a natural number n: the cardinality of
{p ∈ {0, 1, …, n} | p prime} (the prime counting function π at an integer; Part IV,
Chapter 24, p. 111). Total, computable, no junk value.
Reference: ch24PrimeCount 1 = 0, ch24PrimeCount 2 = 1, ch24PrimeCount 10 = 4,
ch24PrimeCount 1000 = 168.
Definition code
import Mathlib
namespace RamanujanNotebooks
/-- Number of primes `p ≤ n`, for a natural number `n`: the cardinality of
`{p ∈ {0, 1, …, n} | p prime}` (the prime counting function `π` at an integer; Part IV,
Chapter 24, p. 111). Total, computable, no junk value.
Reference: `ch24PrimeCount 1 = 0`, `ch24PrimeCount 2 = 1`, `ch24PrimeCount 10 = 4`,
`ch24PrimeCount 1000 = 168`. -/
def ch24PrimeCount (n : ℕ) : ℕ :=
(Finset.filter Nat.Prime (Finset.range (n + 1))).card
end RamanujanNotebooks
Source
Bruce C. Berndt, Ramanujan's Notebooks, Part IV (Springer, 1994), Chapter 24.