Willans' formula for the n-th prime #
The n-th prime is 1 + Σ_{i=1}^{2^n} ⌊(n / Σ_{j=1}^{i} ⌊cos² (π ((j - 1)! + 1) / j)⌋)^{1/n}⌋
(Willans, 1964). By Wilson's theorem (Mathlib's Nat.prime_iff_fac_equiv_neg_one) the inner floor
is 1 exactly when j = 1 or j is prime, so the inner sum is π(i) + 1; the outer floor is 1
when π(i) < n and 0 otherwise (bounding y^n < 2^n instead of n^{1/n}), and Bertrand's
postulate gives p_n ≤ 2^n, so the outer sum counts 1 ≤ i < p_n.
Main results #
Willans.floor_cos_sq_eq: floor(cos^2(pi((j-1)!+1)/j)) is 1 iff j = 1 or j is prime (Wilson)Willans.nth_prime_eq: Willans' formula for the n-th prime
References #
- C. P. Willans, On formulae for the nth prime number, Math. Gazette 48 (1964), 413–415.