Euler's totient function #
This file defines Euler's totient function
Nat.totient n
which counts the number of naturals less than n
that are coprime with n
.
We prove the divisor sum formula, namely that n
equals φ
summed over the divisors of n
. See
sum_totient
. We also prove two lemmas to help compute totients, namely totient_mul
and
totient_prime_pow
.
Euler's totient function. This counts the number of naturals strictly less than n
which are
coprime with n
.
Equations
- n.totient = (Finset.filter n.Coprime (Finset.range n)).card
Instances For
Euler's totient function. This counts the number of naturals strictly less than n
which are
coprime with n
.
Equations
- Nat.termφ = Lean.ParserDescr.node `Nat.termφ 1024 (Lean.ParserDescr.symbol "φ")
Instances For
theorem
Nat.totient_eq_card_coprime
(n : ℕ)
:
n.totient = (Finset.filter n.Coprime (Finset.range n)).card
A characterisation of Nat.totient
that avoids Finset
.
theorem
Nat.filter_coprime_Ico_eq_totient
(a : ℕ)
(n : ℕ)
:
(Finset.filter a.Coprime (Finset.Ico n (n + a))).card = a.totient
theorem
Nat.Ico_filter_coprime_le
{a : ℕ}
(k : ℕ)
(n : ℕ)
(a_pos : 0 < a)
:
(Finset.filter a.Coprime (Finset.Ico k (k + n))).card ≤ a.totient * (n / a + 1)
theorem
Nat.totient_div_of_dvd
{n : ℕ}
{d : ℕ}
(hnd : d ∣ n)
:
(n / d).totient = (Finset.filter (fun (k : ℕ) => n.gcd k = d) (Finset.range n)).card
For d ∣ n
, the totient of n/d
equals the number of values k < n
such that gcd n k = d
theorem
Nat.sum_totient'
(n : ℕ)
:
∑ m ∈ Finset.filter (fun (x : ℕ) => x ∣ n) (Finset.range n.succ), m.totient = n
Euler's product formula for the totient function #
We prove several different statements of this formula.