Theorem: Multiset.extract_gcd
File: Mathlib/Algebra/GCDMonoid/Multiset.lean

tactic: by_cases h : ∀ x ∈ s, x = (0 : α)
state_before: α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
⊢ ∃ t, s = map ((fun x x_1 => x * x_1) (gcd s)) t ∧ gcd t = 1

tactic: use replicate (card s) 1
state_before: case pos
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ (x : α), x ∈ s → x = 0
⊢ ∃ t, s = map ((fun x x_1 => x * x_1) (gcd s)) t ∧ gcd t = 1

tactic: simp only
state_before: case pos
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ (x : α), x ∈ s → x = 0
⊢ s = map ((fun x x_1 => x * x_1) (gcd s)) (replicate (↑card s) 1) ∧ gcd (replicate (↑card s) 1) = 1

tactic: rw [map_replicate, eq_replicate, mul_one, s.gcd_eq_zero_iff.2 h, ← nsmul_singleton,
← gcd_dedup, dedup_nsmul (card_pos.2 hs).ne', dedup_singleton, gcd_singleton]
state_before: case pos
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ (x : α), x ∈ s → x = 0
⊢ s = map (fun x => gcd s * x) (replicate (↑card s) 1) ∧ gcd (replicate (↑card s) 1) = 1

tactic: exact ⟨⟨rfl, h⟩, normalize_one⟩
state_before: case pos
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ (x : α), x ∈ s → x = 0
⊢ (↑card s = ↑card s ∧ ∀ (b : α), b ∈ s → b = 0) ∧ ↑normalize 1 = 1

tactic: choose f hf using @gcd_dvd _ _ _ s
state_before: case neg
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ¬∀ (x : α), x ∈ s → x = 0
⊢ ∃ t, s = map ((fun x x_1 => x * x_1) (gcd s)) t ∧ gcd t = 1

tactic: push_neg  at h
state_before: case neg
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ¬∀ (x : α), x ∈ s → x = 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = gcd s * f h
⊢ ∃ t, s = map ((fun x x_1 => x * x_1) (gcd s)) t ∧ gcd t = 1

tactic: rw [map_pmap]
state_before: case neg.refine'_2
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = gcd s * f h
h : ∃ x, x ∈ s ∧ x ≠ 0
⊢ s = map ((fun x x_1 => x * x_1) (gcd s)) (pmap f s (_ : ∀ (x : α), x ∈ s → x ∈ s))

tactic: conv_lhs => rw [← s.map_id, ← s.pmap_eq_map _ _ fun _ ↦ id]
state_before: case neg.refine'_2
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = gcd s * f h
h : ∃ x, x ∈ s ∧ x ≠ 0
⊢ s = pmap (fun a h => (fun x x_1 => x * x_1) (gcd s) (f h)) s (_ : ∀ (x : α), x ∈ s → x ∈ s)

tactic: congr with (x hx)
state_before: case neg.refine'_2
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = gcd s * f h
h : ∃ x, x ∈ s ∧ x ≠ 0
⊢ pmap (fun a x => id a) s (_ : ∀ (x : α), x ∈ s → x ∈ s) =
    pmap (fun a h => (fun x x_1 => x * x_1) (gcd s) (f h)) s (_ : ∀ (x : α), x ∈ s → x ∈ s)

tactic: simp only
state_before: case neg.refine'_2.e_f.h.h
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = gcd s * f h
h : ∃ x, x ∈ s ∧ x ≠ 0
x : α
hx : x ∈ s
⊢ id x = (fun x x_1 => x * x_1) (gcd s) (f hx)

tactic: rw [id]
state_before: case neg.refine'_2.e_f.h.h
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = gcd s * f h
h : ∃ x, x ∈ s ∧ x ≠ 0
x : α
hx : x ∈ s
⊢ id x = gcd s * f hx

tactic: rw [← hf hx]
state_before: case neg.refine'_2.e_f.h.h
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = gcd s * f h
h : ∃ x, x ∈ s ∧ x ≠ 0
x : α
hx : x ∈ s
⊢ x = gcd s * f hx