-- Mathlib/RingTheory/UniqueFactorizationDomain/Multiplicity.lean
theorem count_normalizedFactors_eq' [DecidableEq R] {p x : R} (hp : p = 0 ∨ Irreducible p)
    (hnorm : normalize p = p) {n : ℕ} (hle : p ^ n ∣ x) (hlt : ¬p ^ (n + 1) ∣ x) :
    (normalizedFactors x).count p = n

Proof state:
case inl
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
n : ℕ
hnorm : normalize 0 = 0
hle : 0 ^ n ∣ x
hlt : ¬0 ^ (n + 1) ∣ x
⊢ count 0 (normalizedFactors x) = n

Tactic:
cases n

Result:
case inl.zero
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
hnorm : normalize 0 = 0
hle : 0 ^ 0 ∣ x
hlt : ¬0 ^ (0 + 1) ∣ x
⊢ count 0 (normalizedFactors x) = 0

case inl.succ
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
hnorm : normalize 0 = 0
n✝ : ℕ
hle : 0 ^ (n✝ + 1) ∣ x
hlt : ¬0 ^ (n✝ + 1 + 1) ∣ x
⊢ count 0 (normalizedFactors x) = n✝ + 1

Proof state:
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
p x : R
hp : p = 0 ∨ Irreducible p
hnorm : normalize p = p
n : ℕ
hle : p ^ n ∣ x
hlt : ¬p ^ (n + 1) ∣ x
⊢ count p (normalizedFactors x) = n

Tactic:
rcases hp with (rfl | hp)

Result:
case inl
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
n : ℕ
hnorm : normalize 0 = 0
hle : 0 ^ n ∣ x
hlt : ¬0 ^ (n + 1) ∣ x
⊢ count 0 (normalizedFactors x) = n

case inr
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
p x : R
hnorm : normalize p = p
n : ℕ
hle : p ^ n ∣ x
hlt : ¬p ^ (n + 1) ∣ x
hp : Irreducible p
⊢ count p (normalizedFactors x) = n

Proof state:
case inr
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
p x : R
hnorm : normalize p = p
n : ℕ
hle : p ^ n ∣ x
hlt : ¬p ^ (n + 1) ∣ x
hp : Irreducible p
⊢ count p (normalizedFactors x) = n

Tactic:
exact count_normalizedFactors_eq hp hnorm hle hlt

Result:
no goals

Proof state:
case inl.succ
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
hnorm : normalize 0 = 0
n✝ : ℕ
hle : 0 ∣ x
hlt : ¬0 ∣ x
⊢ count 0 (normalizedFactors x) = n✝ + 1

Tactic:
exact absurd hle hlt

Result:
no goals

Proof state:
case inl.zero
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
hnorm : normalize 0 = 0
hle : 0 ^ 0 ∣ x
hlt : ¬0 ^ (0 + 1) ∣ x
⊢ count 0 (normalizedFactors x) = 0

Tactic:
exact count_eq_zero.2 (zero_not_mem_normalizedFactors _)

Result:
no goals

Proof state:
case inl.succ
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
hnorm : normalize 0 = 0
n✝ : ℕ
hle : 0 ^ (n✝ + 1) ∣ x
hlt : ¬0 ^ (n✝ + 1 + 1) ∣ x
⊢ count 0 (normalizedFactors x) = n✝ + 1

Tactic:
rw [zero_pow (Nat.succ_ne_zero _)] at hle hlt

Result:
case inl.succ
R : Type u_2
inst✝³ : CancelCommMonoidWithZero R
inst✝² : UniqueFactorizationMonoid R
inst✝¹ : NormalizationMonoid R
inst✝ : DecidableEq R
x : R
hnorm : normalize 0 = 0
n✝ : ℕ
hle : 0 ∣ x
hlt : ¬0 ∣ x
⊢ count 0 (normalizedFactors x) = n✝ + 1