Theorem: List.perm_iff_count
File: .lake/packages/batteries/Batteries/Data/List/Perm.lean

tactic: refine ⟨Perm.count_eq, fun H => ?_⟩
state_before: α : Type u_1
inst✝ : DecidableEq α
l₁ l₂ : List α
⊢ l₁ ~ l₂ ↔ ∀ (a : α), count a l₁ = count a l₂
state_after: α : Type u_1
inst✝ : DecidableEq α
l₁ l₂ : List α
H : ∀ (a : α), count a l₁ = count a l₂
⊢ l₁ ~ l₂

tactic: induction l₁ generalizing l₂ with
| nil =>
  match l₂ with
  | nil => rfl
  | cons b l₂ =>
    specialize H b
    simp at H
| cons a l₁ IH =>
  have : a ∈ l₂ := count_pos_iff_mem.mp (by rw [← H]; simp)
  refine ((IH fun b => ?_).cons a).trans (perm_cons_erase this).symm
  specialize H b
  rw [(perm_cons_erase this).count_eq] at H
  by_cases h : b = a <;> simpa [h] using H
state_before: α : Type u_1
inst✝ : DecidableEq α
l₁ l₂ : List α
H : ∀ (a : α), count a l₁ = count a l₂
⊢ l₁ ~ l₂
state_after: no goals

tactic: match l₂ with
| nil => rfl
| cons b l₂ =>
  specialize H b
  simp at H
state_before: case nil
α : Type u_1
inst✝ : DecidableEq α
l₂ : List α
H : ∀ (a : α), count a [] = count a l₂
⊢ [] ~ l₂
state_after: no goals

tactic: rfl
state_before: α : Type u_1
inst✝ : DecidableEq α
l₂ : List α
H : ∀ (a : α), count a [] = count a []
⊢ [] ~ []
state_after: no goals

tactic: specialize H b
state_before: α : Type u_1
inst✝ : DecidableEq α
l₂✝ : List α
b : α
l₂ : List α
H : ∀ (a : α), count a [] = count a (b :: l₂)
⊢ [] ~ b :: l₂
state_after: α : Type u_1
inst✝ : DecidableEq α
l₂✝ : List α
b : α
l₂ : List α
H : count b [] = count b (b :: l₂)
⊢ [] ~ b :: l₂

tactic: simp at H
state_before: α : Type u_1
inst✝ : DecidableEq α
l₂✝ : List α
b : α
l₂ : List α
H : count b [] = count b (b :: l₂)
⊢ [] ~ b :: l₂
state_after: no goals

tactic: have : a ∈ l₂ := count_pos_iff_mem.mp (by rw [← H]; simp)
state_before: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
⊢ a :: l₁ ~ l₂
state_after: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
this : a ∈ l₂
⊢ a :: l₁ ~ l₂

tactic: refine ((IH fun b => ?_).cons a).trans (perm_cons_erase this).symm
state_before: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
this : a ∈ l₂
⊢ a :: l₁ ~ l₂
state_after: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
this : a ∈ l₂
b : α
⊢ count b l₁ = count b (l₂.erase a)

tactic: specialize H b
state_before: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
this : a ∈ l₂
b : α
⊢ count b l₁ = count b (l₂.erase a)
state_after: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
this : a ∈ l₂
b : α
H : count b (a :: l₁) = count b l₂
⊢ count b l₁ = count b (l₂.erase a)

tactic: rw [(perm_cons_erase this).count_eq] at H
state_before: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
this : a ∈ l₂
b : α
H : count b (a :: l₁) = count b l₂
⊢ count b l₁ = count b (l₂.erase a)
state_after: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
this : a ∈ l₂
b : α
H : count b (a :: l₁) = count b (a :: l₂.erase a)
⊢ count b l₁ = count b (l₂.erase a)

tactic: by_cases h : b = a <;> simpa [h] using H
state_before: case cons
α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
this : a ∈ l₂
b : α
H : count b (a :: l₁) = count b (a :: l₂.erase a)
⊢ count b l₁ = count b (l₂.erase a)
state_after: no goals

tactic: rw [← H]
state_before: α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
⊢ 0 < count a l₂
state_after: α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
⊢ 0 < count a (a :: l₁)

tactic: simp
state_before: α : Type u_1
inst✝ : DecidableEq α
a : α
l₁ : List α
IH : ∀ {l₂ : List α}, (∀ (a : α), count a l₁ = count a l₂) → l₁ ~ l₂
l₂ : List α
H : ∀ (a_1 : α), count a_1 (a :: l₁) = count a_1 l₂
⊢ 0 < count a (a :: l₁)
state_after: no goals