Theorem: DivisorChain.element_of_chain_eq_pow_second_of_chain
File: Mathlib/RingTheory/ChainOfDivisors.lean

tactic: let i := Multiset.card (normalizedFactors r)
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
⊢ ∃ i, r = c 1 ^ ↑i

tactic: have hi : normalizedFactors r = Multiset.replicate i (c 1) := by
  apply Multiset.eq_replicate_of_mem
  intro b hb
  refine'
    eq_second_of_chain_of_prime_dvd hn h₁ (@fun r' => h₂) (prime_of_normalized_factor b hb) hr
      (dvd_of_mem_normalizedFactors hb)
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
⊢ ∃ i, r = c 1 ^ ↑i

tactic: have H : r = c 1 ^ i := by
  have := UniqueFactorizationMonoid.normalizedFactors_prod (ne_zero_of_dvd_ne_zero hq hr)
  rw [associated_iff_eq, hi, Multiset.prod_replicate] at this
  rw [this]
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
⊢ ∃ i, r = c 1 ^ ↑i

tactic: refine' ⟨⟨i, _⟩, H⟩
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
⊢ ∃ i, r = c 1 ^ ↑i

tactic: suffices H' : ∀ r ∈ Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ), r ≤ q
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
⊢ i < n + 1

tactic: simp only [Finset.mem_image]
state_before: case H'
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
⊢ ∀ (r_1 : Associates M), r_1 ∈ Finset.image (fun m => c 1 ^ ↑m) Finset.univ → r_1 ≤ q

tactic: rintro r ⟨a, _, rfl⟩
state_before: case H'
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
⊢ ∀ (r_1 : Associates M), (∃ a, a ∈ Finset.univ ∧ c 1 ^ ↑a = r_1) → r_1 ≤ q

tactic: refine' dvd_trans _ hr
state_before: case H'.intro.intro
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
a : Fin (↑Multiset.card (normalizedFactors r) + 1)
left✝ : a ∈ Finset.univ
⊢ c 1 ^ ↑a ≤ q

tactic: use c 1 ^ (i - (a : ℕ))
state_before: case H'.intro.intro
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
a : Fin (↑Multiset.card (normalizedFactors r) + 1)
left✝ : a ∈ Finset.univ
⊢ c 1 ^ ↑a ∣ r

tactic: rw [pow_mul_pow_sub (c 1)]
state_before: case H'.intro.intro
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
a : Fin (↑Multiset.card (normalizedFactors r) + 1)
left✝ : a ∈ Finset.univ
⊢ r = c 1 ^ ↑a * c 1 ^ (i - ↑a)

tactic: apply Multiset.eq_replicate_of_mem
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
⊢ normalizedFactors r = Multiset.replicate i (c 1)

tactic: intro b hb
state_before: case a
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
⊢ ∀ (b : Associates M), b ∈ normalizedFactors r → b = c 1

tactic: refine'
  eq_second_of_chain_of_prime_dvd hn h₁ (@fun r' => h₂) (prime_of_normalized_factor b hb) hr
    (dvd_of_mem_normalizedFactors hb)
state_before: case a
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
b : Associates M
hb : b ∈ normalizedFactors r
⊢ b = c 1

tactic: have := UniqueFactorizationMonoid.normalizedFactors_prod (ne_zero_of_dvd_ne_zero hq hr)
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
⊢ r = c 1 ^ i

tactic: rw [associated_iff_eq, hi, Multiset.prod_replicate] at this
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
this : Associated (Multiset.prod (normalizedFactors r)) r
⊢ r = c 1 ^ i

tactic: rw [this]
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
this : c 1 ^ i = r
⊢ r = c 1 ^ i

tactic: conv_rhs => rw [← Finset.card_fin (i + 1)]
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
⊢ Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1

tactic: cases n
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
⊢ Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = Finset.card Finset.univ

tactic: rw [Finset.card_image_iff]
state_before: case succ
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
n✝ : ℕ
hn : Nat.succ n✝ ≠ 0
c : Fin (Nat.succ n✝ + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
⊢ Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = Finset.card Finset.univ

tactic: refine' Set.injOn_of_injective (fun m m' h => Fin.ext _) _
state_before: case succ
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
n✝ : ℕ
hn : Nat.succ n✝ ≠ 0
c : Fin (Nat.succ n✝ + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
⊢ Set.InjOn (fun m => c 1 ^ ↑m) ↑Finset.univ

tactic: refine'
  pow_injective_of_not_unit (element_of_chain_not_isUnit_of_index_ne_zero (by simp) h₁) _ h
state_before: case succ
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
n✝ : ℕ
hn : Nat.succ n✝ ≠ 0
c : Fin (Nat.succ n✝ + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
m m' : Fin (i + 1)
h : c 1 ^ ↑m = c 1 ^ ↑m'
⊢ ↑m = ↑m'

tactic: exact Irreducible.ne_zero (second_of_chain_is_irreducible hn h₁ (@h₂) hq)
state_before: case succ
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
n✝ : ℕ
hn : Nat.succ n✝ ≠ 0
c : Fin (Nat.succ n✝ + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
m m' : Fin (i + 1)
h : c 1 ^ ↑m = c 1 ^ ↑m'
⊢ c 1 ≠ 0

tactic: contradiction
state_before: case zero
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hn : Nat.zero ≠ 0
c : Fin (Nat.zero + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
⊢ Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = Finset.card Finset.univ

tactic: simp
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
n✝ : ℕ
hn : Nat.succ n✝ ≠ 0
c : Fin (Nat.succ n✝ + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
m m' : Fin (i + 1)
h : c 1 ^ ↑m = c 1 ^ ↑m'
⊢ 1 ≠ 0

tactic: simp only [← Nat.succ_le_iff, Nat.succ_eq_add_one, ← this]
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
H' : ∀ (r_1 : Associates M), r_1 ∈ Finset.image (fun m => c 1 ^ ↑m) Finset.univ → r_1 ≤ q
⊢ i < n + 1

tactic: apply card_subset_divisors_le_length_of_chain (@h₂) H'
state_before: M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
H' : ∀ (r_1 : Associates M), r_1 ∈ Finset.image (fun m => c 1 ^ ↑m) Finset.univ → r_1 ≤ q
⊢ Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) ≤ n + 1

tactic: exact H
state_before: case H'.intro.intro
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
a : Fin (↑Multiset.card (normalizedFactors r) + 1)
left✝ : a ∈ Finset.univ
⊢ r = c 1 ^ i

tactic: exact Nat.succ_le_succ_iff.mp a.2
state_before: case H'.intro.intro
M : Type u_1
inst✝¹ : CancelCommMonoidWithZero M
inst✝ : UniqueFactorizationMonoid M
q r : Associates M
n : ℕ
hn : n ≠ 0
c : Fin (n + 1) → Associates M
h₁ : StrictMono c
h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i
hr : r ∣ q
hq : q ≠ 0
i : (fun x => ℕ) (normalizedFactors r) := ↑Multiset.card (normalizedFactors r)
hi : normalizedFactors r = Multiset.replicate i (c 1)
H : r = c 1 ^ i
this : Finset.card (Finset.image (fun m => c 1 ^ ↑m) Finset.univ) = i + 1
a : Fin (↑Multiset.card (normalizedFactors r) + 1)
left✝ : a ∈ Finset.univ
⊢ ↑a ≤ i