Euler's totient function #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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
theorem
nat.totient_eq_card_coprime
(n : ℕ) :
n.totient = (finset.filter n.coprime (finset.range n)).card
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 (λ (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 : ℕ) :
(finset.filter (λ (_x : ℕ), _x ∣ n) (finset.range n.succ)).sum (λ (m : ℕ), m.totient) = n
Euler's product formula for the totient function #
We prove several different statements of this formula.