Mathlib.Data.Nat.Totient
45 declarations and 1 deprecated aliases. Mathlib docs · Source
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 product formula for the totient function
We prove several different statements of this formula.
def Nat.totient E3 #
ℕ → ℕ
Euler's totient function. This counts the number of naturals strictly less than n which are
coprime with n.
def Nat.termφ E1 #
Lean.ParserDescr
Euler's totient function. This counts the number of naturals strictly less than n which are
coprime with n.
theorem Nat.totient_zero E0 #
Nat.totient 0 = 0
theorem Nat.totient_one E0 #
Nat.totient 1 = 1
theorem Nat.totient_eq_card_coprime E1 #
∀ (n : ℕ), n.totient = {a ∈ Finset.range n | n.Coprime a}.card
theorem Nat.totient_eq_card_lt_and_coprime E1 #
∀ (n : ℕ), n.totient = Nat.card ↑{m | m < n ∧ n.Coprime m}
A characterisation of Nat.totient that avoids Finset.
theorem Nat.totient_le E1 #
∀ (n : ℕ), n.totient ≤ n
theorem Nat.totient_lt E1 #
∀ (n : ℕ), 1 < n → n.totient < n
theorem Nat.totient_eq_zero E0 #
∀ {n : ℕ}, n.totient = 0 ↔ n = 0
theorem Nat.totient_pos E0 #
∀ {n : ℕ}, 0 < n.totient ↔ 0 < n
instance Nat.neZero_totient E0 #
∀ {n : ℕ} [NeZero n], NeZero n.totient
theorem Nat.filter_coprime_Ico_eq_totient E1 #
∀ (a n : ℕ), {x ∈ Finset.Ico n (n + a) | a.Coprime x}.card = a.totient
theorem Nat.Ico_filter_coprime_le E1 #
∀ {a : ℕ} (k n : ℕ), a ≠ 0 → {x ∈ Finset.Ico k (k + n) | a.Coprime x}.card ≤ a.totient * (n / a + 1)
theorem ZMod.card_units_eq_totient E0 #
∀ (n : ℕ) [NeZero n] [inst : Fintype (ZMod n)ˣ], Fintype.card (ZMod n)ˣ = n.totient
Note this takes an explicit Fintype ((ZMod n)ˣ) argument to avoid trouble with instance
diamonds.
theorem Nat.totient_even E1 #
∀ {n : ℕ}, 2 < n → Even n.totient
theorem Nat.totient_mul E1 #
∀ {m n : ℕ}, m.Coprime n → (m * n).totient = m.totient * n.totient
theorem Nat.totient_div_of_dvd E1 #
∀ {n d : ℕ}, d ∣ n → (n / d).totient = {k ∈ Finset.range n | n.gcd k = d}.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 E1 #
∀ (n : ℕ), n.divisors.sum Nat.totient = n
theorem Nat.sum_totient' E1 #
∀ (n : ℕ), ∑ m ∈ Finset.range n.succ with m ∣ n, m.totient = n
theorem Nat.totient_prime_pow_succ E1 #
∀ {p : ℕ}, Nat.Prime p → ∀ (n : ℕ), (p ^ (n + 1)).totient = p ^ n * (p - 1)
When p is prime, then the totient of p ^ (n + 1) is p ^ n * (p - 1)
theorem Nat.totient_prime_pow E1 #
∀ {p : ℕ}, Nat.Prime p → ∀ {n : ℕ}, 0 < n → (p ^ n).totient = p ^ (n - 1) * (p - 1)
When p is prime, then the totient of p ^ n is p ^ (n - 1) * (p - 1)
theorem Nat.totient_prime E1 #
∀ {p : ℕ}, Nat.Prime p → p.totient = p - 1
theorem Nat.totient_eq_iff_prime E1 #
∀ {p : ℕ}, 0 < p → (p.totient = p - 1 ↔ Nat.Prime p)
theorem Nat.card_units_zmod_lt_sub_one E1 #
∀ {p : ℕ}, 1 < p → ∀ [inst : Fintype (ZMod p)ˣ], Fintype.card (ZMod p)ˣ ≤ p - 1
theorem Nat.prime_iff_card_units E1 #
∀ (p : ℕ) [inst : Fintype (ZMod p)ˣ], Nat.Prime p ↔ Fintype.card (ZMod p)ˣ = p - 1
theorem Nat.totient_two E0 #
Nat.totient 2 = 1
theorem Nat.odd_totient_iff E0 #
∀ {n : ℕ}, Odd n.totient ↔ n = 1 ∨ n = 2
Euler's totient function is only odd at 1 or 2.
theorem Nat.totient_eq_one_iff E0 #
∀ {n : ℕ}, n.totient = 1 ↔ n = 1 ∨ n = 2
theorem Nat.dvd_two_of_totient_le_one E1 #
∀ {a : ℕ}, 0 < a → a.totient ≤ 1 → a ∣ 2
theorem Nat.odd_totient_iff_eq_one E1 #
∀ {n : ℕ}, Odd n.totient ↔ n.totient = 1
theorem Nat.totient_coprime_totient_iff E0 #
∀ (m n : ℕ), m.totient.Coprime n.totient ↔ (m = 1 ∨ m = 2) ∨ n = 1 ∨ n = 2
Nat.totient m and Nat.totient n are coprime iff one of them is 1.
theorem Nat.totient_eq_prod_factorization E1 #
∀ {n : ℕ}, n ≠ 0 → n.totient = n.factorization.prod fun p k ↦ p ^ (k - 1) * (p - 1)
Euler's product formula for the totient function.
theorem Nat.totient_mul_prod_primeFactors E1 #
∀ (n : ℕ), n.totient * ∏ p ∈ n.primeFactors, p = n * ∏ p ∈ n.primeFactors, (p - 1)
Euler's product formula for the totient function.
theorem Nat.totient_eq_div_primeFactors_mul E1 #
∀ (n : ℕ), n.totient = (n / ∏ p ∈ n.primeFactors, p) * ∏ p ∈ n.primeFactors, (p - 1)
Euler's product formula for the totient function.
theorem Nat.totient_eq_mul_prod_factors E1 #
∀ (n : ℕ), ↑n.totient = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)
Euler's product formula for the totient function.
theorem Nat.totient_gcd_mul_totient_mul E1 #
∀ (a b : ℕ), (a.gcd b).totient * (a * b).totient = a.totient * b.totient * a.gcd b
theorem Nat.totient_super_multiplicative E1 #
∀ (a b : ℕ), a.totient * b.totient ≤ (a * b).totient
theorem Nat.totient_dvd_of_dvd E1 #
∀ {a b : ℕ}, a ∣ b → a.totient ∣ b.totient
theorem Nat.totient_mul_of_dvd E1 #
∀ {p n : ℕ}, p ∣ n → (p * n).totient = p * n.totient
theorem Nat.totient_mul_of_prime_of_not_dvd E1 #
∀ {p n : ℕ}, Nat.Prime p → ¬p ∣ n → (p * n).totient = (p - 1) * n.totient
theorem Nat.totient_two_mul_of_even E1 #
∀ {n : ℕ}, Even n → (2 * n).totient = 2 * n.totient
theorem Nat.totient_two_mul_of_odd E1 #
∀ {n : ℕ}, Odd n → (2 * n).totient = n.totient
theorem Nat.prime_pow_pow_totient_ediv_prod E1 #
∀ {p : ℕ} (k : ℕ),
Nat.Prime p →
(p ^ k) ^ (p ^ k).totient / ∏ q ∈ (p ^ k).primeFactors, q ^ ((p ^ k).totient / (q - 1)) =
p ^ (p ^ (k - 1) * ((p - 1) * k - 1))
theorem Nat.prod_primeFactors_pow_totient_ediv_dvd E1 #
∀ (n : ℕ), ∏ p ∈ n.primeFactors, p ^ (n.totient / (p - 1)) ∣ n ^ n.totient
def Mathlib.Meta.Positivity.evalNatTotient E1 #
Mathlib.Meta.Positivity.PositivityExt
Extension for Nat.totient.
Deprecated aliases
| Name | New name | Since |
|---|---|---|
Nat.totient_mul_of_prime_of_dvd | Nat.totient_mul_of_dvd | 2026-11-04 |