Theorem: Nat.factorization_gcd
File: Mathlib/Data/Nat/Factorization/Basic.lean

tactic: let dfac := a.factorization ⊓ b.factorization
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
⊢ factorization (gcd a b) = factorization a ⊓ factorization b

tactic: let d := dfac.prod Nat.pow
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
⊢ factorization (gcd a b) = factorization a ⊓ factorization b

tactic: have dfac_prime : ∀ p : ℕ, p ∈ dfac.support → Prime p := by
  intro p hp
  have : p ∈ a.factors ∧ p ∈ b.factors := by simpa using hp
  exact prime_of_mem_factors this.1
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
⊢ factorization (gcd a b) = factorization a ⊓ factorization b

tactic: have h1 : d.factorization = dfac := prod_pow_factorization_eq_self dfac_prime
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
⊢ factorization (gcd a b) = factorization a ⊓ factorization b

tactic: have hd_pos : d ≠ 0 := (factorizationEquiv.invFun ⟨dfac, dfac_prime⟩).2.ne'
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
⊢ factorization (gcd a b) = factorization a ⊓ factorization b

tactic: suffices d = gcd a b by rwa [← this]
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
⊢ factorization (gcd a b) = factorization a ⊓ factorization b

tactic: apply gcd_greatest
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
⊢ d = gcd a b

tactic: intro p hp
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
⊢ ∀ (p : ℕ), p ∈ dfac.support → Prime p

tactic: have : p ∈ a.factors ∧ p ∈ b.factors := by simpa using hp
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
p : ℕ
hp : p ∈ dfac.support
⊢ Prime p

tactic: exact prime_of_mem_factors this.1
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
p : ℕ
hp : p ∈ dfac.support
this : p ∈ factors a ∧ p ∈ factors b
⊢ Prime p

tactic: simpa using hp
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
p : ℕ
hp : p ∈ dfac.support
⊢ p ∈ factors a ∧ p ∈ factors b

tactic: rwa [← this]
state_before: a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
this : d = gcd a b
⊢ factorization (gcd a b) = factorization a ⊓ factorization b

tactic: rw [← factorization_le_iff_dvd hd_pos ha_pos, h1]
state_before: case hda
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
⊢ d ∣ a

tactic: exact inf_le_left
state_before: case hda
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
⊢ dfac ≤ factorization a

tactic: rw [← factorization_le_iff_dvd hd_pos hb_pos, h1]
state_before: case hdb
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
⊢ d ∣ b

tactic: exact inf_le_right
state_before: case hdb
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
⊢ dfac ≤ factorization b

tactic: intro e hea heb
state_before: case hd
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
⊢ ∀ (e : ℕ), e ∣ a → e ∣ b → e ∣ d

tactic: rcases Decidable.eq_or_ne e 0 with (rfl | he_pos)
state_before: case hd
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
e : ℕ
hea : e ∣ a
heb : e ∣ b
⊢ e ∣ d

tactic: have hea' := (factorization_le_iff_dvd he_pos ha_pos).mpr hea
state_before: case hd.inr
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
e : ℕ
hea : e ∣ a
heb : e ∣ b
he_pos : e ≠ 0
⊢ e ∣ d

tactic: have heb' := (factorization_le_iff_dvd he_pos hb_pos).mpr heb
state_before: case hd.inr
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
e : ℕ
hea : e ∣ a
heb : e ∣ b
he_pos : e ≠ 0
hea' : factorization e ≤ factorization a
⊢ e ∣ d

tactic: simp [← factorization_le_iff_dvd he_pos hd_pos, h1, hea', heb']
state_before: case hd.inr
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
e : ℕ
hea : e ∣ a
heb : e ∣ b
he_pos : e ≠ 0
hea' : factorization e ≤ factorization a
heb' : factorization e ≤ factorization b
⊢ e ∣ d

tactic: simp only [zero_dvd_iff] at hea
state_before: case hd.inl
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
hea : 0 ∣ a
heb : 0 ∣ b
⊢ 0 ∣ d

tactic: contradiction
state_before: case hd.inl
a b : ℕ
ha_pos : a ≠ 0
hb_pos : b ≠ 0
dfac : ℕ →₀ ℕ := factorization a ⊓ factorization b
d : ℕ := Finsupp.prod dfac Nat.pow
dfac_prime : ∀ (p : ℕ), p ∈ dfac.support → Prime p
h1 : factorization d = dfac
hd_pos : d ≠ 0
heb : 0 ∣ b
hea : a = 0
⊢ 0 ∣ d