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 => s.gcd * x) t ∧ t.gcd = 1
state_after: case pos
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ x ∈ s, x = 0
⊢ ∃ t, s = map (fun x => s.gcd * x) t ∧ t.gcd = 1

case neg
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ¬∀ x ∈ s, x = 0
⊢ ∃ t, s = map (fun x => s.gcd * x) t ∧ t.gcd = 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 ∈ s, x = 0
⊢ ∃ t, s = map (fun x => s.gcd * x) t ∧ t.gcd = 1
state_after: case h
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ x ∈ s, x = 0
⊢ s = map (fun x => s.gcd * x) (replicate (card s) 1) ∧ (replicate (card s) 1).gcd = 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 h
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ x ∈ s, x = 0
⊢ s = map (fun x => s.gcd * x) (replicate (card s) 1) ∧ (replicate (card s) 1).gcd = 1
state_after: case h
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ∀ x ∈ s, x = 0
⊢ (card s = card s ∧ ∀ b ∈ s, b = 0) ∧ normalize 1 = 1

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

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 ∈ s, x = 0
⊢ ∃ t, s = map (fun x => s.gcd * x) t ∧ t.gcd = 1
state_after: case neg
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ¬∀ x ∈ s, x = 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = s.gcd * f h
⊢ ∃ t, s = map (fun x => s.gcd * x) t ∧ t.gcd = 1

tactic: push_neg at h
state_before: case neg
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
h : ¬∀ x ∈ s, x = 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = s.gcd * f h
⊢ ∃ t, s = map (fun x => s.gcd * x) t ∧ t.gcd = 1
state_after: case neg
α : Type u_1
inst✝¹ : CancelCommMonoidWithZero α
inst✝ : NormalizedGCDMonoid α
s : Multiset α
hs : s ≠ 0
f : {a : α} → a ∈ s → α
hf : ∀ {a : α} (h : a ∈ s), a = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
⊢ ∃ t, s = map (fun x => s.gcd * x) t ∧ t.gcd = 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 = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
⊢ s = map (fun x => s.gcd * x) (pmap f s ⋯)
state_after: 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 = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
⊢ s = pmap (fun a h => s.gcd * f h) 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 = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
⊢ s = pmap (fun a h => s.gcd * f h) s ⋯
state_after: 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 = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
⊢ pmap (fun a x => id a) s ⋯ = pmap (fun a h => s.gcd * f h) 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 = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
⊢ pmap (fun a x => id a) s ⋯ = pmap (fun a h => s.gcd * f h) s ⋯
state_after: 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 = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
x : α
hx : x ∈ s
⊢ id x = s.gcd * f hx

tactic: rw [id, ← 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 = s.gcd * f h
h : ∃ x ∈ s, x ≠ 0
x : α
hx : x ∈ s
⊢ id x = s.gcd * f hx
state_after: no goals