Theorem: isPrimePow_iff_unique_prime_dvd
File: Mathlib/Data/Nat/Factorization/PrimePow.lean

tactic: rw [isPrimePow_nat_iff]
state_before: R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p : R
k n : ℕ
⊢ IsPrimePow n ↔ ∃! p, Nat.Prime p ∧ p ∣ n

tactic: constructor
state_before: R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p : R
k n : ℕ
⊢ (∃ p k, Nat.Prime p ∧ 0 < k ∧ p ^ k = n) ↔ ∃! p, Nat.Prime p ∧ p ∣ n

tactic: rintro ⟨p, ⟨hp, hn⟩, hq⟩
state_before: case mpr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p : R
k n : ℕ
⊢ (∃! p, Nat.Prime p ∧ p ∣ n) → ∃ p k, Nat.Prime p ∧ 0 < k ∧ p ^ k = n

tactic: rcases eq_or_ne n 0 with (rfl | hn₀)
state_before: case mpr.intro.intro.intro
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hq : ∀ (y : ℕ), (fun p => Nat.Prime p ∧ p ∣ n) y → y = p
hp : Nat.Prime p
hn : p ∣ n
⊢ ∃ p k, Nat.Prime p ∧ 0 < k ∧ p ^ k = n

tactic: refine' ⟨p, n.factorization p, hp, hp.factorization_pos_of_dvd hn₀ hn, _⟩
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hq : ∀ (y : ℕ), (fun p => Nat.Prime p ∧ p ∣ n) y → y = p
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
⊢ ∃ p k, Nat.Prime p ∧ 0 < k ∧ p ^ k = n

tactic: simp only [and_imp] at hq
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hq : ∀ (y : ℕ), (fun p => Nat.Prime p ∧ p ∣ n) y → y = p
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
⊢ p ^ ↑(Nat.factorization n) p = n

tactic: apply Nat.dvd_antisymm (Nat.ord_proj_dvd _ _)
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
hq : ∀ (y : ℕ), Nat.Prime y → y ∣ n → y = p
⊢ p ^ ↑(Nat.factorization n) p = n

tactic: apply Nat.dvd_of_factors_subperm hn₀
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
hq : ∀ (y : ℕ), Nat.Prime y → y ∣ n → y = p
⊢ n ∣ p ^ ↑(Nat.factorization n) p

tactic: rw [hp.factors_pow, List.subperm_ext_iff]
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
hq : ∀ (y : ℕ), Nat.Prime y → y ∣ n → y = p
⊢ Nat.factors n <+~ Nat.factors (p ^ ↑(Nat.factorization n) p)

tactic: intro q hq'
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
hq : ∀ (y : ℕ), Nat.Prime y → y ∣ n → y = p
⊢ ∀ (x : ℕ),
    x ∈ Nat.factors n → List.count x (Nat.factors n) ≤ List.count x (List.replicate (↑(Nat.factorization n) p) p)

tactic: rw [Nat.mem_factors hn₀] at hq'
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
hq : ∀ (y : ℕ), Nat.Prime y → y ∣ n → y = p
q : ℕ
hq' : q ∈ Nat.factors n
⊢ List.count q (Nat.factors n) ≤ List.count q (List.replicate (↑(Nat.factorization n) p) p)

tactic: cases hq _ hq'.1 hq'.2
state_before: case mpr.intro.intro.intro.inr
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
hq : ∀ (y : ℕ), Nat.Prime y → y ∣ n → y = p
q : ℕ
hq' : Nat.Prime q ∧ q ∣ n
⊢ List.count q (Nat.factors n) ≤ List.count q (List.replicate (↑(Nat.factorization n) p) p)

tactic: simp
state_before: case mpr.intro.intro.intro.inr.refl
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p✝ : R
k n p : ℕ
hp : Nat.Prime p
hn : p ∣ n
hn₀ : n ≠ 0
hq : ∀ (y : ℕ), Nat.Prime y → y ∣ n → y = p
hq' : Nat.Prime p ∧ p ∣ n
⊢ List.count p (Nat.factors n) ≤ List.count p (List.replicate (↑(Nat.factorization n) p) p)

tactic: rintro ⟨p, k, hp, hk, rfl⟩
state_before: case mp
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n✝ p : R
k n : ℕ
⊢ (∃ p k, Nat.Prime p ∧ 0 < k ∧ p ^ k = n) → ∃! p, Nat.Prime p ∧ p ∣ n

tactic: refine' ⟨p, ⟨hp, dvd_pow_self _ hk.ne'⟩, _⟩
state_before: case mp.intro.intro.intro.intro
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n p✝ : R
k✝ p k : ℕ
hp : Nat.Prime p
hk : 0 < k
⊢ ∃! p_1, Nat.Prime p_1 ∧ p_1 ∣ p ^ k

tactic: rintro q ⟨hq, hq'⟩
state_before: case mp.intro.intro.intro.intro
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n p✝ : R
k✝ p k : ℕ
hp : Nat.Prime p
hk : 0 < k
⊢ ∀ (y : ℕ), (fun p_1 => Nat.Prime p_1 ∧ p_1 ∣ p ^ k) y → y = p

tactic: exact (Nat.prime_dvd_prime_iff_eq hq hp).1 (hq.dvd_of_dvd_pow hq')
state_before: case mp.intro.intro.intro.intro.intro
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n p✝ : R
k✝ p k : ℕ
hp : Nat.Prime p
hk : 0 < k
q : ℕ
hq : Nat.Prime q
hq' : q ∣ p ^ k
⊢ q = p

tactic: cases (hq 2 ⟨Nat.prime_two, dvd_zero 2⟩).trans (hq 3 ⟨Nat.prime_three, dvd_zero 3⟩).symm
state_before: case mpr.intro.intro.intro.inl
R : Type ?u.8343
inst✝ : CommMonoidWithZero R
n p✝ : R
k p : ℕ
hp : Nat.Prime p
hq : ∀ (y : ℕ), (fun p => Nat.Prime p ∧ p ∣ 0) y → y = p
hn : p ∣ 0
⊢ ∃ p k, Nat.Prime p ∧ 0 < k ∧ p ^ k = 0