Documentation

Mathlib.Data.Nat.Totient

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
    Instances For

      Euler's totient function. This counts the number of naturals strictly less than n which are coprime with n.

      Equations
        Instances For

          A characterisation of Nat.totient that avoids Finset.

          theorem Nat.totient_lt (n : β„•) (hn : 1 < n) :
          theorem Nat.Ico_filter_coprime_le {a : β„•} (k n : β„•) (a_ne_zero : a β‰  0) :
          {x ∈ Finset.Ico k (k + n) | a.Coprime x}.card ≀ a.totient * (n / a + 1)
          @[simp]

          Note this takes an explicit Fintype ((ZMod n)Λ£) argument to avoid trouble with instance diamonds.

          theorem Nat.totient_div_of_dvd {n d : β„•} (hnd : 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' (n : β„•) :
          βˆ‘ m ∈ Finset.range n.succ with m ∣ n, m.totient = n
          theorem Nat.totient_prime_pow_succ {p : β„•} (hp : 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 {p : β„•} (hp : Prime p) {n : β„•} (hn : 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)

          Euler's totient function is only odd at 1 or 2.

          theorem Nat.dvd_two_of_totient_le_one {a : β„•} (han : 0 < a) (ha : a.totient ≀ 1) :
          a ∣ 2

          Nat.totient m and Nat.totient n are coprime iff one of them is 1.

          Euler's product formula for the totient function #

          We prove several different statements of this formula.

          theorem Nat.totient_eq_prod_factorization {n : β„•} (hn : 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 (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 (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 (n : β„•) :
          ↑n.totient = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)

          Euler's product formula for the totient function.

          theorem Nat.eq_or_eq_of_totient_eq_totient {a b : β„•} (h : a ∣ b) (h' : a.totient = b.totient) :
          a = b ∨ 2 * a = b
          theorem Even.eq_of_totient_eq_totient {a b : β„•} (h : a ∣ b) (ha : Even a) (h' : a.totient = b.totient) :
          a = b
          theorem Nat.prime_pow_pow_totient_ediv_prod {p k : β„•} (hp : Prime p) (hk : 0 < k) :
          (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 {n : β„•} (hn : 0 < n) :
          ∏ p ∈ n.primeFactors, p ^ (n.totient / (p - 1)) ∣ n ^ n.totient