File: Mathlib/Data/Nat/Totient.lean

full_name: Nat.totient
code: /-- Euler's totient function. This counts the number of naturals strictly less than `n` which are
coprime with `n`. -/
def totient (n : ℕ) : ℕ 
goal: ℕ

full_name: Nat._aux_Mathlib_Data_Nat_Totient___macroRules_Nat_termφ_1
code: @[inherit_doc]
scoped notation "φ" => Nat.totient
goal: Lean.Macro

full_name: Nat._aux_Mathlib_Data_Nat_Totient___unexpand_Nat_totient_1
code: @[inherit_doc]
scoped notation "φ" => Nat.totient
goal: Lean.PrettyPrinter.Unexpander

full_name: Nat.totient_zero
code: @[simp]
theorem totient_zero : φ 0 = 0 
goal: Nat.totient 0 = 0

full_name: Nat.totient_one
code: @[simp]
theorem totient_one : φ 1 = 1 
goal: Nat.totient 1 = 1

full_name: Nat.totient_eq_card_coprime
code: theorem totient_eq_card_coprime (n : ℕ) : φ n = ((range n).filter n.Coprime).card 
goal: n.totient = (Finset.filter n.Coprime (Finset.range n)).card

full_name: Nat.totient_eq_card_lt_and_coprime
code: /-- A characterisation of `Nat.totient` that avoids `Finset`. -/
theorem totient_eq_card_lt_and_coprime (n : ℕ) : φ n = Nat.card { m | m < n ∧ n.Coprime m } 
goal: n.totient = Nat.card ↑{m | m < n ∧ n.Coprime m}

full_name: Nat.totient_le
code: theorem totient_le (n : ℕ) : φ n ≤ n 
goal: n.totient ≤ n

full_name: Nat.totient_lt
code: theorem totient_lt (n : ℕ) (hn : 1 < n) : φ n < n 
goal: n.totient < n

full_name: Nat.totient_eq_zero
code: @[simp]
theorem totient_eq_zero : ∀ {n : ℕ}, φ n = 0 ↔ n = 0
  
goal: n.totient = 0 ↔ n = 0

full_name: Nat.totient_pos
code: @[simp] theorem totient_pos {n : ℕ} : 0 < φ n ↔ 0 < n 
goal: 0 < n.totient ↔ 0 < n

full_name: Nat.filter_coprime_Ico_eq_totient
code: theorem filter_coprime_Ico_eq_totient (a n : ℕ) :
    ((Ico n (n + a)).filter (Coprime a)).card = totient a 
goal: (Finset.filter a.Coprime (Finset.Ico n (n + a))).card = a.totient

full_name: Nat.Ico_filter_coprime_le
code: theorem Ico_filter_coprime_le {a : ℕ} (k n : ℕ) (a_pos : 0 < a) :
    ((Ico k (k + n)).filter (Coprime a)).card ≤ totient a * (n / a + 1) 
goal: (Finset.filter a.Coprime (Finset.Ico k (k + n))).card ≤ a.totient * (n / a + 1)

full_name: ZMod.card_units_eq_totient
code: /-- Note this takes an explicit `Fintype ((ZMod n)ˣ)` argument to avoid trouble with instance
diamonds. -/
@[simp]
theorem _root_.ZMod.card_units_eq_totient (n : ℕ) [NeZero n] [Fintype (ZMod n)ˣ] :
    Fintype.card (ZMod n)ˣ = φ n 
goal: Fintype.card (ZMod n)ˣ = n.totient

full_name: Nat.totient_even
code: theorem totient_even {n : ℕ} (hn : 2 < n) : Even n.totient 
goal: Even n.totient

full_name: Nat.totient_mul
code: theorem totient_mul {m n : ℕ} (h : m.Coprime n) : φ (m * n) = φ m * φ n 
goal: (m * n).totient = m.totient * n.totient

full_name: Nat.totient_div_of_dvd
code: /-- For `d ∣ n`, the totient of `n/d` equals the number of values `k < n` such that `gcd n k = d` -/
theorem totient_div_of_dvd {n d : ℕ} (hnd : d ∣ n) :
    φ (n / d) = (filter (fun k : ℕ => n.gcd k = d) (range n)).card 
goal: (n / d).totient = (Finset.filter (fun k => n.gcd k = d) (Finset.range n)).card

full_name: Nat.sum_totient
code: theorem sum_totient (n : ℕ) : n.divisors.sum φ = n 
goal: n.divisors.sum Nat.totient = n

full_name: Nat.sum_totient'
code: theorem sum_totient' (n : ℕ) : (∑ m ∈ (range n.succ).filter (· ∣ n), φ m) = n 
goal: ∑ m ∈ Finset.filter (fun x => x ∣ n) (Finset.range n.succ), m.totient = n

full_name: Nat.totient_prime_pow_succ
code: /-- When `p` is prime, then the totient of `p ^ (n + 1)` is `p ^ n * (p - 1)` -/
theorem totient_prime_pow_succ {p : ℕ} (hp : p.Prime) (n : ℕ) : φ (p ^ (n + 1)) = p ^ n * (p - 1) 
goal: (p ^ (n + 1)).totient = p ^ n * (p - 1)

full_name: Nat.totient_prime_pow
code: /-- When `p` is prime, then the totient of `p ^ n` is `p ^ (n - 1) * (p - 1)` -/
theorem totient_prime_pow {p : ℕ} (hp : p.Prime) {n : ℕ} (hn : 0 < n) :
    φ (p ^ n) = p ^ (n - 1) * (p - 1) 
goal: (p ^ n).totient = p ^ (n - 1) * (p - 1)

full_name: Nat.totient_prime
code: theorem totient_prime {p : ℕ} (hp : p.Prime) : φ p = p - 1 
goal: p.totient = p - 1

full_name: Nat.totient_eq_iff_prime
code: theorem totient_eq_iff_prime {p : ℕ} (hp : 0 < p) : p.totient = p - 1 ↔ p.Prime 
goal: p.totient = p - 1 ↔ Nat.Prime p

full_name: Nat.card_units_zmod_lt_sub_one
code: theorem card_units_zmod_lt_sub_one {p : ℕ} (hp : 1 < p) [Fintype (ZMod p)ˣ] :
    Fintype.card (ZMod p)ˣ ≤ p - 1 
goal: Fintype.card (ZMod p)ˣ ≤ p - 1

full_name: Nat.prime_iff_card_units
code: theorem prime_iff_card_units (p : ℕ) [Fintype (ZMod p)ˣ] :
    p.Prime ↔ Fintype.card (ZMod p)ˣ = p - 1 
goal: Nat.Prime p ↔ Fintype.card (ZMod p)ˣ = p - 1

full_name: Nat.totient_two
code: @[simp]
theorem totient_two : φ 2 = 1 
goal: Nat.totient 2 = 1

full_name: Nat.totient_eq_one_iff
code: theorem totient_eq_one_iff : ∀ {n : ℕ}, n.totient = 1 ↔ n = 1 ∨ n = 2
  
goal: n.totient = 1 ↔ n = 1 ∨ n = 2

full_name: Nat.dvd_two_of_totient_le_one
code: theorem dvd_two_of_totient_le_one {a : ℕ} (han : 0 < a) (ha : a.totient ≤ 1) : a ∣ 2 
goal: a ∣ 2

full_name: Nat.totient_eq_prod_factorization
code: /-- Euler's product formula for the totient function. -/
theorem totient_eq_prod_factorization {n : ℕ} (hn : n ≠ 0) :
    φ n = n.factorization.prod fun p k => p ^ (k - 1) * (p - 1) 
goal: n.totient = n.factorization.prod fun p k => p ^ (k - 1) * (p - 1)

full_name: Nat.totient_mul_prod_primeFactors
code: /-- Euler's product formula for the totient function. -/
theorem totient_mul_prod_primeFactors (n : ℕ) :
    (φ n * ∏ p ∈ n.primeFactors, p) = n * ∏ p ∈ n.primeFactors, (p - 1) 
goal: n.totient * ∏ p ∈ n.primeFactors, p = n * ∏ p ∈ n.primeFactors, (p - 1)

full_name: Nat.totient_eq_div_primeFactors_mul
code: /-- Euler's product formula for the totient function. -/
theorem totient_eq_div_primeFactors_mul (n : ℕ) :
    φ n = (n / ∏ p ∈ n.primeFactors, p) * ∏ p ∈ n.primeFactors, (p - 1) 
goal: n.totient = (n / ∏ p ∈ n.primeFactors, p) * ∏ p ∈ n.primeFactors, (p - 1)

full_name: Nat.totient_eq_mul_prod_factors
code: /-- Euler's product formula for the totient function. -/
theorem totient_eq_mul_prod_factors (n : ℕ) :
    (φ n : ℚ) = n * ∏ p ∈ n.primeFactors, (1 - (p : ℚ)⁻¹) 
goal: ↑n.totient = ↑n * ∏ p ∈ n.primeFactors, (1 - (↑p)⁻¹)

full_name: Nat.totient_gcd_mul_totient_mul
code: theorem totient_gcd_mul_totient_mul (a b : ℕ) : φ (a.gcd b) * φ (a * b) = φ a * φ b * a.gcd b 
goal: (a.gcd b).totient * (a * b).totient = a.totient * b.totient * a.gcd b

full_name: Nat.totient_super_multiplicative
code: theorem totient_super_multiplicative (a b : ℕ) : φ a * φ b ≤ φ (a * b) 
goal: a.totient * b.totient ≤ (a * b).totient

full_name: Nat.totient_dvd_of_dvd
code: theorem totient_dvd_of_dvd {a b : ℕ} (h : a ∣ b) : φ a ∣ φ b 
goal: a.totient ∣ b.totient

full_name: Nat.totient_mul_of_prime_of_dvd
code: theorem totient_mul_of_prime_of_dvd {p n : ℕ} (hp : p.Prime) (h : p ∣ n) :
    (p * n).totient = p * n.totient 
goal: (p * n).totient = p * n.totient

full_name: Nat.totient_mul_of_prime_of_not_dvd
code: theorem totient_mul_of_prime_of_not_dvd {p n : ℕ} (hp : p.Prime) (h : ¬p ∣ n) :
    (p * n).totient = (p - 1) * n.totient 
goal: (p * n).totient = (p - 1) * n.totient