Theorem: List.dedup_eq_cons
File: Mathlib/Data/List/Dedup.lean

tactic: refine ⟨fun h => ?_, fun h => ?_⟩
state_before: α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
⊢ l.dedup = a :: l' ↔ a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
state_after: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
⊢ a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'

case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
⊢ l.dedup = a :: l'

tactic: refine ⟨mem_dedup.1 (h.symm ▸ mem_cons_self _ _), fun ha => ?_, by rw [h, tail_cons]⟩
state_before: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
⊢ a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
state_after: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
⊢ False

tactic: have := count_pos_iff_mem.2 ha
state_before: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
⊢ False
state_after: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
this : 0 < count a l'
⊢ False

tactic: have : count a l.dedup ≤ 1 := nodup_iff_count_le_one.1 (nodup_dedup l) a
state_before: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
this : 0 < count a l'
⊢ False
state_after: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
this✝ : 0 < count a l'
this : count a l.dedup ≤ 1
⊢ False

tactic: rw [h, count_cons_self] at this
state_before: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
this✝ : 0 < count a l'
this : count a l.dedup ≤ 1
⊢ False
state_after: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
this✝ : 0 < count a l'
this : count a l' + 1 ≤ 1
⊢ False

tactic: omega
state_before: case refine_1
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
ha : a ∈ l'
this✝ : 0 < count a l'
this : count a l' + 1 ≤ 1
⊢ False
state_after: no goals

tactic: rw [h, tail_cons]
state_before: α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : l.dedup = a :: l'
⊢ l.dedup.tail = l'
state_after: no goals

tactic: have := @List.cons_head!_tail α ⟨a⟩ _ (ne_nil_of_mem (mem_dedup.2 h.1))
state_before: case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
⊢ l.dedup = a :: l'
state_after: case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
this : l.dedup.head! :: l.dedup.tail = l.dedup
⊢ l.dedup = a :: l'

tactic: have hal : a ∈ l.dedup := mem_dedup.2 h.1
state_before: case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
this : l.dedup.head! :: l.dedup.tail = l.dedup
⊢ l.dedup = a :: l'
state_after: case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
this : l.dedup.head! :: l.dedup.tail = l.dedup
hal : a ∈ l.dedup
⊢ l.dedup = a :: l'

tactic: rw [← this, mem_cons, or_iff_not_imp_right] at hal
state_before: case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
this : l.dedup.head! :: l.dedup.tail = l.dedup
hal : a ∈ l.dedup
⊢ l.dedup = a :: l'
state_after: case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
this : l.dedup.head! :: l.dedup.tail = l.dedup
hal : a ∉ l.dedup.tail → a = l.dedup.head!
⊢ l.dedup = a :: l'

tactic: exact this ▸ h.2.2.symm ▸ cons_eq_cons.2 ⟨(hal (h.2.2.symm ▸ h.2.1)).symm, rfl⟩
state_before: case refine_2
α : Type u
inst✝ : DecidableEq α
l : List α
a : α
l' : List α
h : a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l'
this : l.dedup.head! :: l.dedup.tail = l.dedup
hal : a ∉ l.dedup.tail → a = l.dedup.head!
⊢ l.dedup = a :: l'
state_after: no goals