-- Mathlib/RingTheory/RootsOfUnity/Lemmas.lean
/-- If `μ` is a primitive `n`th root of unity in `R` and `k < n`, then `n` is divisible
by `(μ-1)^k` in `ℤ[μ] ⊆ R`. -/
lemma self_sub_one_pow_dvd_order {k n : ℕ} (hn : k < n) {μ : R} (hμ : IsPrimitiveRoot μ n) :
    ∃ z ∈ adjoin ℤ {μ}, n = z * (μ - 1) ^ k

Proof state:
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
k n : ℕ
μ : R
m : ℕ
hn : k < m + k + 1
hμ : IsPrimitiveRoot μ (m + k + 1)
hdvd : ∀ (k : ℕ), ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1)
⊢ ∃ z ∈ adjoin ℤ {μ}, ↑(m + k + 1) = z * (μ - 1) ^ k

Tactic:
let Z k := Classical.choose <| hdvd k

Result:
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
k n : ℕ
μ : R
m : ℕ
hn : k < m + k + 1
hμ : IsPrimitiveRoot μ (m + k + 1)
hdvd : ∀ (k : ℕ), ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1)
Z : ℕ → R := fun k => Classical.choose ⋯
⊢ ∃ z ∈ adjoin ℤ {μ}, ↑(m + k + 1) = z * (μ - 1) ^ k

Proof state:
case intro.refine_2.e_a
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
k n : ℕ
μ : R
m : ℕ
hn : k < m + k + 1
hμ : IsPrimitiveRoot μ (m + k + 1)
hdvd : ∀ (k : ℕ), ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1)
Z : ℕ → R := fun k => Classical.choose ⋯
Zdef : ∀ (k : ℕ), Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1)
this : (-1) ^ (m + k) * ∏ k ∈ range (m + k), (μ ^ (k + 1) - 1) = ↑m + ↑k + 1
⊢ ∏ k ∈ range (m + k), (μ ^ (k + 1) - 1) =
    (∏ j ∈ range k, Z (j + 1)) * ((∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1)) * (μ - 1) ^ #(range k))

Tactic:
rw [← prod_range_mul_prod_Ico _ (Nat.le_add_left k m), mul_comm _ (_ ^ #_), ← mul_assoc,
  prod_mul_pow_card]

Result:
case intro.refine_2.e_a
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
k n : ℕ
μ : R
m : ℕ
hn : k < m + k + 1
hμ : IsPrimitiveRoot μ (m + k + 1)
hdvd : ∀ (k : ℕ), ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1)
Z : ℕ → R := fun k => Classical.choose ⋯
Zdef : ∀ (k : ℕ), Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1)
this : (-1) ^ (m + k) * ∏ k ∈ range (m + k), (μ ^ (k + 1) - 1) = ↑m + ↑k + 1
⊢ (∏ k ∈ range k, (μ ^ (k + 1) - 1)) * ∏ k ∈ Ico k (m + k), (μ ^ (k + 1) - 1) =
    (∏ a ∈ range k, Z (a + 1) * (μ - 1)) * ∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1)

Proof state:
case intro.refine_1.hx.hx
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
k n : ℕ
μ : R
m : ℕ
hn : k < m + k + 1
hμ : IsPrimitiveRoot μ (m + k + 1)
hdvd : ∀ (k : ℕ), ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1)
Z : ℕ → R := fun k => Classical.choose ⋯
Zdef : ∀ (k : ℕ), Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1)
⊢ (-1) ^ (m + k) ∈ adjoin ℤ {μ}

Tactic:
exact Subalgebra.pow_mem _ (Subalgebra.neg_mem _ <| Subalgebra.one_mem _) _

Result:
no goals

Proof state:
case intro.refine_2
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
k n : ℕ
μ : R
m : ℕ
hn : k < m + k + 1
hμ : IsPrimitiveRoot μ (m + k + 1)
hdvd : ∀ (k : ℕ), ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1)
Z : ℕ → R := fun k => Classical.choose ⋯
Zdef : ∀ (k : ℕ), Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1)
⊢ ↑(m + k + 1) = (((-1) ^ (m + k) * ∏ j ∈ range k, Z (j + 1)) * ∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1)) * (μ - 1) ^ k

Tactic:
push_cast

Result:
case intro.refine_2
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
k n : ℕ
μ : R
m : ℕ
hn : k < m + k + 1
hμ : IsPrimitiveRoot μ (m + k + 1)
hdvd : ∀ (k : ℕ), ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1)
Z : ℕ → R := fun k => Classical.choose ⋯
Zdef : ∀ (k : ℕ), Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1)
⊢ ↑m + ↑k + 1 = (((-1) ^ (m + k) * ∏ j ∈ range k, Z (j + 1)) * ∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1)) * (μ - 1) ^ k