Theorem: card_orderOf_eq_totient_aux₁
File: Mathlib/GroupTheory/SpecificGroups/Cyclic.lean

tactic: intro d hd hpos
state_before: α : Type u
a : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
⊢ ∀ {d : ℕ},
    d ∣ Fintype.card α →
      0 < card (filter (fun a => orderOf a = d) univ) → card (filter (fun a => orderOf a = d) univ) = φ d

tactic: induction' d using Nat.strongRec' with d IH
state_before: α : Type u
a : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d : ℕ
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
⊢ card (filter (fun a => orderOf a = d) univ) = φ d

tactic: rcases Decidable.eq_or_ne d 0 with (rfl | hd0)
state_before: case H
α : Type u
a : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
⊢ card (filter (fun a => orderOf a = d) univ) = φ d

tactic: rcases card_pos.1 hpos with ⟨a, ha'⟩
state_before: case H.inr
α : Type u
a : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
⊢ card (filter (fun a => orderOf a = d) univ) = φ d

tactic: have ha : orderOf a = d := (mem_filter.1 ha').2
state_before: case H.inr.intro
α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
⊢ card (filter (fun a => orderOf a = d) univ) = φ d

tactic: have h1 :
  (∑ m in d.properDivisors, (univ.filter fun a : α => orderOf a = m).card) =
    ∑ m in d.properDivisors, φ m := by
  refine' Finset.sum_congr rfl fun m hm => _
  simp only [mem_filter, mem_range, mem_properDivisors] at hm
  refine' IH m hm.2 (hm.1.trans hd) (Finset.card_pos.2 ⟨a ^ (d / m), _⟩)
  simp only [mem_filter, mem_univ, orderOf_pow a, ha, true_and_iff,
    Nat.gcd_eq_right (div_dvd_of_dvd hm.1), Nat.div_div_self hm.1 hd0]
state_before: case H.inr.intro
α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
⊢ card (filter (fun a => orderOf a = d) univ) = φ d

tactic: have h2 :
  (∑ m in d.divisors, (univ.filter fun a : α => orderOf a = m).card) =
    ∑ m in d.divisors, φ m := by
  rw [← filter_dvd_eq_divisors hd0, sum_card_orderOf_eq_card_pow_eq_one hd0,
    filter_dvd_eq_divisors hd0, sum_totient, ← ha, card_pow_eq_one_eq_orderOf_aux hn a]
state_before: case H.inr.intro
α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
h1 : ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m
⊢ card (filter (fun a => orderOf a = d) univ) = φ d

tactic: simpa [← cons_self_properDivisors hd0, ← h1] using h2
state_before: case H.inr.intro
α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
h1 : ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m
h2 : ∑ m in divisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in divisors d, φ m
⊢ card (filter (fun a => orderOf a = d) univ) = φ d

tactic: cases Fintype.card_ne_zero (eq_zero_of_zero_dvd hd)
state_before: case H.inl
α : Type u
a : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d : ℕ
hd✝ : d ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d) univ)
IH :
  ∀ (m : ℕ),
    m < 0 →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : 0 ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = 0) univ)
⊢ card (filter (fun a => orderOf a = 0) univ) = φ 0

tactic: refine' Finset.sum_congr rfl fun m hm => _
state_before: α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
⊢ ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m

tactic: simp only [mem_filter, mem_range, mem_properDivisors] at hm
state_before: α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
m : ℕ
hm : m ∈ properDivisors d
⊢ card (filter (fun a => orderOf a = m) univ) = φ m

tactic: refine' IH m hm.2 (hm.1.trans hd) (Finset.card_pos.2 ⟨a ^ (d / m), _⟩)
state_before: α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
m : ℕ
hm : m ∣ d ∧ m < d
⊢ card (filter (fun a => orderOf a = m) univ) = φ m

tactic: simp only [mem_filter, mem_univ, orderOf_pow a, ha, true_and_iff,
  Nat.gcd_eq_right (div_dvd_of_dvd hm.1), Nat.div_div_self hm.1 hd0]
state_before: α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
m : ℕ
hm : m ∣ d ∧ m < d
⊢ a ^ (d / m) ∈ filter (fun a => orderOf a = m) univ

tactic: rw [← filter_dvd_eq_divisors hd0, sum_card_orderOf_eq_card_pow_eq_one hd0,
  filter_dvd_eq_divisors hd0, sum_totient, ← ha, card_pow_eq_one_eq_orderOf_aux hn a]
state_before: α : Type u
a✝ : α
inst✝² : Group α
inst✝¹ : DecidableEq α
inst✝ : Fintype α
hn : ∀ (n : ℕ), 0 < n → card (filter (fun a => a ^ n = 1) univ) ≤ n
d✝ : ℕ
hd✝ : d✝ ∣ Fintype.card α
hpos✝ : 0 < card (filter (fun a => orderOf a = d✝) univ)
d : ℕ
IH :
  ∀ (m : ℕ),
    m < d →
      m ∣ Fintype.card α →
        0 < card (filter (fun a => orderOf a = m) univ) → card (filter (fun a => orderOf a = m) univ) = φ m
hd : d ∣ Fintype.card α
hpos : 0 < card (filter (fun a => orderOf a = d) univ)
hd0 : d ≠ 0
a : α
ha' : a ∈ filter (fun a => orderOf a = d) univ
ha : orderOf a = d
h1 : ∑ m in properDivisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in properDivisors d, φ m
⊢ ∑ m in divisors d, card (filter (fun a => orderOf a = m) univ) = ∑ m in divisors d, φ m