l3lab/ntp-mathlib huggingface dataset:
@[simp]
theorem count_erase_of_ne {a b : α} (ab : a ≠ b) (s : Multiset α) :
    count a (erase s b) = count a s :=
  Quotient.inductionOn s <| fun l => by
    convert List.count_erase_of_ne ab l <;> 

Proof state:
case h.e'_3
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a b : α
ab : a ≠ b
s : Multiset α
l : List α
⊢ count a ⟦l⟧ = List.count a l

Next tactic:
rw [← coe_count]
@[simp]
theorem count_erase_of_ne {a b : α} (ab : a ≠ b) (s : Multiset α) :
    count a (erase s b) = count a s :=
  Quotient.inductionOn s <| fun l => by
    convert List.count_erase_of_ne ab l <;> rw [← coe_count] <;> 

Proof state:
case h.e'_2
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a b : α
ab : a ≠ b
s : Multiset α
l : List α
⊢ count a (erase ⟦l⟧ b) = count a ↑(List.erase l b)

Next tactic:
simp
@[simp]
theorem count_erase_of_ne {a b : α} (ab : a ≠ b) (s : Multiset α) :
    count a (erase s b) = count a s :=
  Quotient.inductionOn s <| fun l => by
    convert List.count_erase_of_ne ab l <;> rw [← coe_count] <;> 

Proof state:
case h.e'_3
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a b : α
ab : a ≠ b
s : Multiset α
l : List α
⊢ count a ⟦l⟧ = count a ↑l

Next tactic:
simp
@[simp]
theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
s t : Multiset α
⊢ count a (s - t) = count a s - count a t

Next tactic:
revert s
@[simp]
theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by
  revert s; 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s : Multiset α
a : α
t : Multiset α
⊢ ∀ (s : Multiset α), count a (s - t) = count a s - count a t

Next tactic:
refine' Multiset.induction_on t (by simp) fun b t IH s => _
@[simp]
theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by
  revert s; refine' Multiset.induction_on t (by 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s : Multiset α
a : α
t : Multiset α
⊢ ∀ (s : Multiset α), count a (s - 0) = count a s - count a 0

Next tactic:
simp
@[simp]
theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by
  revert s; refine' Multiset.induction_on t (by simp) fun b t IH s => _
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
t✝ : Multiset α
b : α
t : Multiset α
IH : ∀ (s : Multiset α), count a (s - t) = count a s - count a t
s : Multiset α
⊢ count a (s - b ::ₘ t) = count a s - count a (b ::ₘ t)

Next tactic:
rw [sub_cons, IH]
@[simp]
theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by
  revert s; refine' Multiset.induction_on t (by simp) fun b t IH s => _
  rw [sub_cons, IH]
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
t✝ : Multiset α
b : α
t : Multiset α
IH : ∀ (s : Multiset α), count a (s - t) = count a s - count a t
s : Multiset α
⊢ count a (erase s b) - count a t = count a s - count a (b ::ₘ t)

Next tactic:
rcases Decidable.eq_or_ne a b with rfl | ab
@[simp]
theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by
  revert s; refine' Multiset.induction_on t (by simp) fun b t IH s => _
  rw [sub_cons, IH]
  rcases Decidable.eq_or_ne a b with rfl | ab
  · 

Proof state:
case inl
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
t✝ t : Multiset α
IH : ∀ (s : Multiset α), count a (s - t) = count a s - count a t
s : Multiset α
⊢ count a (erase s a) - count a t = count a s - count a (a ::ₘ t)

Next tactic:
rw [count_erase_self, count_cons_self, Nat.sub_sub, add_comm]
@[simp]
theorem count_sub (a : α) (s t : Multiset α) : count a (s - t) = count a s - count a t := by
  revert s; refine' Multiset.induction_on t (by simp) fun b t IH s => _
  rw [sub_cons, IH]
  rcases Decidable.eq_or_ne a b with rfl | ab
  · rw [count_erase_self, count_cons_self, Nat.sub_sub, add_comm]
  · 

Proof state:
case inr
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
t✝ : Multiset α
b : α
t : Multiset α
IH : ∀ (s : Multiset α), count a (s - t) = count a s - count a t
s : Multiset α
ab : a ≠ b
⊢ count a (erase s b) - count a t = count a s - count a (b ::ₘ t)

Next tactic:
rw [count_erase_of_ne ab, count_cons_of_ne ab]
@[simp]
theorem count_union (a : α) (s t : Multiset α) : count a (s ∪ t) = max (count a s) (count a t) := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
s t : Multiset α
⊢ count a (s ∪ t) = max (count a s) (count a t)

Next tactic:
simp [(· ∪ ·), union, tsub_add_eq_max]
@[simp]
theorem count_inter (a : α) (s t : Multiset α) : count a (s ∩ t) = min (count a s) (count a t) := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
s t : Multiset α
⊢ count a (s ∩ t) = min (count a s) (count a t)

Next tactic:
apply @Nat.add_left_cancel (count a (s - t))
@[simp]
theorem count_inter (a : α) (s t : Multiset α) : count a (s ∩ t) = min (count a s) (count a t) := by
  apply @Nat.add_left_cancel (count a (s - t))
  

Proof state:
case a
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
s t : Multiset α
⊢ count a (s - t) + count a (s ∩ t) = count a (s - t) + min (count a s) (count a t)

Next tactic:
rw [← count_add, sub_add_inter, count_sub, tsub_add_min]
theorem le_count_iff_replicate_le {a : α} {s : Multiset α} {n : ℕ} :
    n ≤ count a s ↔ replicate n a ≤ s :=
  Quot.inductionOn s fun _l => by
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
s : Multiset α
n : ℕ
_l : List α
⊢ n ≤ count a (Quot.mk Setoid.r _l) ↔ replicate n a ≤ Quot.mk Setoid.r _l

Next tactic:
simp only [quot_mk_to_coe'', mem_coe, coe_count]
theorem le_count_iff_replicate_le {a : α} {s : Multiset α} {n : ℕ} :
    n ≤ count a s ↔ replicate n a ≤ s :=
  Quot.inductionOn s fun _l => by
    simp only [quot_mk_to_coe'', mem_coe, coe_count]
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
a : α
s : Multiset α
n : ℕ
_l : List α
⊢ n ≤ List.count a _l ↔ replicate n a ≤ ↑_l

Next tactic:
exact le_count_iff_replicate_sublist.trans replicate_le_coe.symm
@[simp]
theorem count_filter_of_pos {p} [DecidablePred p] {a} {s : Multiset α} (h : p a) :
    count a (filter p s) = count a s :=
  Quot.inductionOn s fun _l => by
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
p : α → Prop
inst✝ : DecidablePred p
a : α
s : Multiset α
h : p a
_l : List α
⊢ count a (filter p (Quot.mk Setoid.r _l)) = count a (Quot.mk Setoid.r _l)

Next tactic:
simp only [quot_mk_to_coe'', coe_filter, mem_coe, coe_count, decide_eq_true_eq]
@[simp]
theorem count_filter_of_pos {p} [DecidablePred p] {a} {s : Multiset α} (h : p a) :
    count a (filter p s) = count a s :=
  Quot.inductionOn s fun _l => by
    simp only [quot_mk_to_coe'', coe_filter, mem_coe, coe_count, decide_eq_true_eq]
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
p : α → Prop
inst✝ : DecidablePred p
a : α
s : Multiset α
h : p a
_l : List α
⊢ List.count a (List.filter (fun b => decide (p b)) _l) = List.count a _l

Next tactic:
apply count_filter
@[simp]
theorem count_filter_of_pos {p} [DecidablePred p] {a} {s : Multiset α} (h : p a) :
    count a (filter p s) = count a s :=
  Quot.inductionOn s fun _l => by
    simp only [quot_mk_to_coe'', coe_filter, mem_coe, coe_count, decide_eq_true_eq]
    apply count_filter
    

Proof state:
case h
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
p : α → Prop
inst✝ : DecidablePred p
a : α
s : Multiset α
h : p a
_l : List α
⊢ decide (p a) = true

Next tactic:
simpa using h
theorem count_filter {p} [DecidablePred p] {a} {s : Multiset α} :
    count a (filter p s) = if p a then count a s else 0 := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
p : α → Prop
inst✝ : DecidablePred p
a : α
s : Multiset α
⊢ count a (filter p s) = if p a then count a s else 0

Next tactic:
split_ifs with h
theorem count_filter {p} [DecidablePred p] {a} {s : Multiset α} :
    count a (filter p s) = if p a then count a s else 0 := by
  split_ifs with h
  · 

Proof state:
case pos
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
p : α → Prop
inst✝ : DecidablePred p
a : α
s : Multiset α
h : p a
⊢ count a (filter p s) = count a s

Next tactic:
exact count_filter_of_pos h
theorem count_filter {p} [DecidablePred p] {a} {s : Multiset α} :
    count a (filter p s) = if p a then count a s else 0 := by
  split_ifs with h
  · exact count_filter_of_pos h
  · 

Proof state:
case neg
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
p : α → Prop
inst✝ : DecidablePred p
a : α
s : Multiset α
h : ¬p a
⊢ count a (filter p s) = 0

Next tactic:
exact count_filter_of_neg h
theorem ext {s t : Multiset α} : s = t ↔ ∀ a, count a s = count a t :=
  Quotient.inductionOn₂ s t fun _l₁ _l₂ => Quotient.eq.trans <| by
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s t : Multiset α
_l₁ _l₂ : List α
⊢ _l₁ ≈ _l₂ ↔ ∀ (a : α), count a ⟦_l₁⟧ = count a ⟦_l₂⟧

Next tactic:
simp only [quot_mk_to_coe, coe_filter, mem_coe, coe_count, decide_eq_true_eq]
theorem ext {s t : Multiset α} : s = t ↔ ∀ a, count a s = count a t :=
  Quotient.inductionOn₂ s t fun _l₁ _l₂ => Quotient.eq.trans <| by
    simp only [quot_mk_to_coe, coe_filter, mem_coe, coe_count, decide_eq_true_eq]
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s t : Multiset α
_l₁ _l₂ : List α
⊢ _l₁ ≈ _l₂ ↔ ∀ (a : α), List.count a _l₁ = List.count a _l₂

Next tactic:
apply perm_iff_count
@[simp]
theorem coe_inter (s t : List α) : (s ∩ t : Multiset α) = (s.bagInter t : List α) := by 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
s t : List α
⊢ ↑s ∩ ↑t = ↑(List.bagInter s t)

Next tactic:
ext
@[simp]
theorem coe_inter (s t : List α) : (s ∩ t : Multiset α) = (s.bagInter t : List α) := by ext; 

Proof state:
case a
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
s t : List α
a✝ : α
⊢ count a✝ (↑s ∩ ↑t) = count a✝ ↑(List.bagInter s t)

Next tactic:
simp
theorem le_iff_count {s t : Multiset α} : s ≤ t ↔ ∀ a, count a s ≤ count a t :=
  ⟨fun h a => count_le_of_le a h, fun al => by
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s t : Multiset α
al : ∀ (a : α), count a s ≤ count a t
⊢ s ≤ t

Next tactic:
rw [← (ext.2 fun a => by simp [max_eq_right (al a)] : s ∪ t = t)]
theorem le_iff_count {s t : Multiset α} : s ≤ t ↔ ∀ a, count a s ≤ count a t :=
  ⟨fun h a => count_le_of_le a h, fun al => by
    rw [← (ext.2 fun a => by 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s t : Multiset α
al : ∀ (a : α), count a s ≤ count a t
a : α
⊢ count a (s ∪ t) = count a t

Next tactic:
simp [max_eq_right (al a)]
theorem le_iff_count {s t : Multiset α} : s ≤ t ↔ ∀ a, count a s ≤ count a t :=
  ⟨fun h a => count_le_of_le a h, fun al => by
    rw [← (ext.2 fun a => by simp [max_eq_right (al a)] : s ∪ t = t)]; 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s t : Multiset α
al : ∀ (a : α), count a s ≤ count a t
⊢ s ≤ s ∪ t

Next tactic:
apply le_union_left
instance : DistribLattice (Multiset α) :=
  { le_sup_inf := fun s t u =>
      le_of_eq <|
        Eq.symm <|
          ext.2 fun a => by
            

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s t u : Multiset α
a : α
⊢ count a (s ⊔ t ⊓ u) = count a ((s ⊔ t) ⊓ (s ⊔ u))

Next tactic:
simp only [max_min_distrib_left, Multiset.count_inter, Multiset.sup_eq_union,
              Multiset.count_union, Multiset.inf_eq_inter]
theorem count_map {α β : Type*} (f : α → β) (s : Multiset α) [DecidableEq β] (b : β) :
    count b (map f s) = card (s.filter fun a => b = f a) := by
  

Proof state:
α✝ : Type u_1
β✝ : Type v
γ : Type u_2
inst✝¹ : DecidableEq α✝
s✝ : Multiset α✝
α : Type u_3
β : Type u_4
f : α → β
s : Multiset α
inst✝ : DecidableEq β
b : β
⊢ count b (map f s) = card (filter (fun a => b = f a) s)

Next tactic:
simp [Bool.beq_eq_decide_eq, eq_comm, count, countP_map]
/-- `Multiset.map f` preserves `count` if `f` is injective on the set of elements contained in
the multiset -/
theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α)
    (hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Set.InjOn f {x | x ∈ s}
x : α
H : x ∈ s
⊢ count (f x) (map f s) = count x s

Next tactic:
suffices (filter (fun a : α => f x = f a) s).count x = card (filter (fun a : α => f x = f a) s) by
    rw [count, countP_map, ← this]
    exact count_filter_of_pos $ rfl
/-- `Multiset.map f` preserves `count` if `f` is injective on the set of elements contained in
the multiset -/
theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α)
    (hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x := by
  suffices (filter (fun a : α => f x = f a) s).count x = card (filter (fun a : α => f x = f a) s) by
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Set.InjOn f {x | x ∈ s}
x : α
H : x ∈ s
this : count x (filter (fun a => f x = f a) s) = card (filter (fun a => f x = f a) s)
⊢ count (f x) (map f s) = count x s

Next tactic:
rw [count, countP_map, ← this]
/-- `Multiset.map f` preserves `count` if `f` is injective on the set of elements contained in
the multiset -/
theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α)
    (hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x := by
  suffices (filter (fun a : α => f x = f a) s).count x = card (filter (fun a : α => f x = f a) s) by
    rw [count, countP_map, ← this]
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Set.InjOn f {x | x ∈ s}
x : α
H : x ∈ s
this : count x (filter (fun a => f x = f a) s) = card (filter (fun a => f x = f a) s)
⊢ count x (filter (fun a => f x = f a) s) = count x s

Next tactic:
exact count_filter_of_pos $ rfl
/-- `Multiset.map f` preserves `count` if `f` is injective on the set of elements contained in
the multiset -/
theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α)
    (hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x := by
  suffices (filter (fun a : α => f x = f a) s).count x = card (filter (fun a : α => f x = f a) s) by
    rw [count, countP_map, ← this]
    exact count_filter_of_pos $ rfl
  · 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Set.InjOn f {x | x ∈ s}
x : α
H : x ∈ s
⊢ count x (filter (fun a => f x = f a) s) = card (filter (fun a => f x = f a) s)

Next tactic:
rw [eq_replicate_card.2 fun b hb => (hf H (mem_filter.1 hb).left _).symm]
/-- `Multiset.map f` preserves `count` if `f` is injective on the set of elements contained in
the multiset -/
theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α)
    (hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x := by
  suffices (filter (fun a : α => f x = f a) s).count x = card (filter (fun a : α => f x = f a) s) by
    rw [count, countP_map, ← this]
    exact count_filter_of_pos $ rfl
  · rw [eq_replicate_card.2 fun b hb => (hf H (mem_filter.1 hb).left _).symm]
    · 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Set.InjOn f {x | x ∈ s}
x : α
H : x ∈ s
⊢ count x (replicate (card (filter (fun a => f x = f a) s)) x) =
    card (replicate (card (filter (fun a => f x = f a) s)) x)

Next tactic:
simp only [count_replicate, eq_self_iff_true, if_true, card_replicate]
/-- `Multiset.map f` preserves `count` if `f` is injective on the set of elements contained in
the multiset -/
theorem count_map_eq_count [DecidableEq β] (f : α → β) (s : Multiset α)
    (hf : Set.InjOn f { x : α | x ∈ s }) (x) (H : x ∈ s) : (s.map f).count (f x) = s.count x := by
  suffices (filter (fun a : α => f x = f a) s).count x = card (filter (fun a : α => f x = f a) s) by
    rw [count, countP_map, ← this]
    exact count_filter_of_pos $ rfl
  · rw [eq_replicate_card.2 fun b hb => (hf H (mem_filter.1 hb).left _).symm]
    · simp only [count_replicate, eq_self_iff_true, if_true, card_replicate]
    · 

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Set.InjOn f {x | x ∈ s}
x : α
H : x ∈ s
⊢ ∀ b ∈ filter (fun a => f x = f a) s, f x = f b

Next tactic:
simp only [mem_filter, beq_iff_eq, and_imp, @eq_comm _ (f x), imp_self, implies_true]
/-- `Multiset.map f` preserves `count` if `f` is injective -/
theorem count_map_eq_count' [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Function.Injective f)
    (x : α) : (s.map f).count (f x) = s.count x := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Injective f
x : α
⊢ count (f x) (map f s) = count x s

Next tactic:
by_cases H : x ∈ s
/-- `Multiset.map f` preserves `count` if `f` is injective -/
theorem count_map_eq_count' [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Function.Injective f)
    (x : α) : (s.map f).count (f x) = s.count x := by
  by_cases H : x ∈ s
  · 

Proof state:
case pos
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Injective f
x : α
H : x ∈ s
⊢ count (f x) (map f s) = count x s

Next tactic:
exact count_map_eq_count f _ (Set.injOn_of_injective hf _) _ H
/-- `Multiset.map f` preserves `count` if `f` is injective -/
theorem count_map_eq_count' [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Function.Injective f)
    (x : α) : (s.map f).count (f x) = s.count x := by
  by_cases H : x ∈ s
  · exact count_map_eq_count f _ (Set.injOn_of_injective hf _) _ H
  · 

Proof state:
case neg
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Injective f
x : α
H : x ∉ s
⊢ count (f x) (map f s) = count x s

Next tactic:
rw [count_eq_zero_of_not_mem H, count_eq_zero, mem_map]
/-- `Multiset.map f` preserves `count` if `f` is injective -/
theorem count_map_eq_count' [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Function.Injective f)
    (x : α) : (s.map f).count (f x) = s.count x := by
  by_cases H : x ∈ s
  · exact count_map_eq_count f _ (Set.injOn_of_injective hf _) _ H
  · rw [count_eq_zero_of_not_mem H, count_eq_zero, mem_map]
    

Proof state:
case neg
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Injective f
x : α
H : x ∉ s
⊢ ¬∃ a ∈ s, f a = f x

Next tactic:
rintro ⟨k, hks, hkx⟩
/-- `Multiset.map f` preserves `count` if `f` is injective -/
theorem count_map_eq_count' [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Function.Injective f)
    (x : α) : (s.map f).count (f x) = s.count x := by
  by_cases H : x ∈ s
  · exact count_map_eq_count f _ (Set.injOn_of_injective hf _) _ H
  · rw [count_eq_zero_of_not_mem H, count_eq_zero, mem_map]
    rintro ⟨k, hks, hkx⟩
    

Proof state:
case neg.intro.intro
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Injective f
x : α
H : x ∉ s
k : α
hks : k ∈ s
hkx : f k = f x
⊢ False

Next tactic:
rw [hf hkx] at hks
/-- `Multiset.map f` preserves `count` if `f` is injective -/
theorem count_map_eq_count' [DecidableEq β] (f : α → β) (s : Multiset α) (hf : Function.Injective f)
    (x : α) : (s.map f).count (f x) = s.count x := by
  by_cases H : x ∈ s
  · exact count_map_eq_count f _ (Set.injOn_of_injective hf _) _ H
  · rw [count_eq_zero_of_not_mem H, count_eq_zero, mem_map]
    rintro ⟨k, hks, hkx⟩
    rw [hf hkx] at hks
    

Proof state:
case neg.intro.intro
α : Type u_1
β : Type v
γ : Type u_2
inst✝¹ : DecidableEq α
s✝ : Multiset α
inst✝ : DecidableEq β
f : α → β
s : Multiset α
hf : Injective f
x : α
H : x ∉ s
k : α
hks : x ∈ s
hkx : f k = f x
⊢ False

Next tactic:
contradiction
theorem filter_eq' (s : Multiset α) (b : α) : s.filter (· = b) = replicate (count b s) b :=
  Quotient.inductionOn s <| fun l => by
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s : Multiset α
b : α
l : List α
⊢ filter (fun x => x = b) ⟦l⟧ = replicate (count b ⟦l⟧) b

Next tactic:
simp only [quot_mk_to_coe, coe_filter, mem_coe, coe_count]
theorem filter_eq' (s : Multiset α) (b : α) : s.filter (· = b) = replicate (count b s) b :=
  Quotient.inductionOn s <| fun l => by
    simp only [quot_mk_to_coe, coe_filter, mem_coe, coe_count]
    

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s : Multiset α
b : α
l : List α
⊢ ↑(List.filter (fun b_1 => decide (b_1 = b)) l) = replicate (List.count b l) b

Next tactic:
rw [List.filter_eq l b, coe_replicate]
theorem filter_eq (s : Multiset α) (b : α) : s.filter (Eq b) = replicate (count b s) b := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ s : Multiset α
b : α
⊢ filter (Eq b) s = replicate (count b s) b

Next tactic:
simp_rw [← filter_eq', eq_comm]
@[simp]
theorem replicate_inter (n : ℕ) (x : α) (s : Multiset α) :
    replicate n x ∩ s = replicate (min n (s.count x)) x := by
  

Proof state:
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
n : ℕ
x : α
s : Multiset α
⊢ replicate n x ∩ s = replicate (min n (count x s)) x

Next tactic:
ext y
@[simp]
theorem replicate_inter (n : ℕ) (x : α) (s : Multiset α) :
    replicate n x ∩ s = replicate (min n (s.count x)) x := by
  ext y
  

Proof state:
case a
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
n : ℕ
x : α
s : Multiset α
y : α
⊢ count y (replicate n x ∩ s) = count y (replicate (min n (count x s)) x)

Next tactic:
rw [count_inter, count_replicate, count_replicate]
@[simp]
theorem replicate_inter (n : ℕ) (x : α) (s : Multiset α) :
    replicate n x ∩ s = replicate (min n (s.count x)) x := by
  ext y
  rw [count_inter, count_replicate, count_replicate]
  

Proof state:
case a
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
n : ℕ
x : α
s : Multiset α
y : α
⊢ min (if y = x then n else 0) (count y s) = if y = x then min n (count x s) else 0

Next tactic:
by_cases h : y = x
@[simp]
theorem replicate_inter (n : ℕ) (x : α) (s : Multiset α) :
    replicate n x ∩ s = replicate (min n (s.count x)) x := by
  ext y
  rw [count_inter, count_replicate, count_replicate]
  by_cases h : y = x
  · 

Proof state:
case pos
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
n : ℕ
x : α
s : Multiset α
y : α
h : y = x
⊢ min (if y = x then n else 0) (count y s) = if y = x then min n (count x s) else 0

Next tactic:
simp only [h, if_true]
@[simp]
theorem replicate_inter (n : ℕ) (x : α) (s : Multiset α) :
    replicate n x ∩ s = replicate (min n (s.count x)) x := by
  ext y
  rw [count_inter, count_replicate, count_replicate]
  by_cases h : y = x
  · simp only [h, if_true]
  · 

Proof state:
case neg
α : Type u_1
β : Type v
γ : Type u_2
inst✝ : DecidableEq α
s✝ : Multiset α
n : ℕ
x : α
s : Multiset α
y : α
h : ¬y = x
⊢ min (if y = x then n else 0) (count y s) = if y = x then min n (count x s) else 0

Next tactic:
simp only [h, if_false, zero_min]