Skip to content

Commit c7d8aad

Browse files
haitian-yukim4lvin
andcommitted
feat: Multiset lemmas (#15645)
Co-authored-by: Malvin Gattinger <malvin@w4eg.de>
1 parent 8e9838b commit c7d8aad

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Mathlib/Data/Multiset/Basic.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,24 @@ theorem map_count_True_eq_filter_card (s : Multiset α) (p : α → Prop) [Decid
23462346
simp only [count_eq_card_filter_eq, filter_map, card_map, Function.id_comp,
23472347
eq_true_eq_id, Function.comp_apply]
23482348

2349+
@[simp] theorem sub_singleton [DecidableEq α] (a : α) (s : Multiset α) : s - {a} = s.erase a := by
2350+
ext
2351+
simp only [count_sub, count_singleton]
2352+
split <;> simp_all
2353+
2354+
theorem mem_sub [DecidableEq α] {a : α} {s t : Multiset α} :
2355+
a ∈ s - t ↔ t.count a < s.count a := by
2356+
rw [← count_pos, count_sub, Nat.sub_pos_iff_lt]
2357+
2358+
theorem inter_add_sub_of_add_eq_add [DecidableEq α] {M N P Q : Multiset α} (h : M + N = P + Q) :
2359+
(N ∩ Q) + (P - M) = N := by
2360+
ext x
2361+
rw [Multiset.count_add, Multiset.count_inter, Multiset.count_sub]
2362+
have h0 : M.count x + N.count x = P.count x + Q.count x := by
2363+
rw [Multiset.ext] at h
2364+
simp_all only [Multiset.mem_add, Multiset.count_add]
2365+
omega
2366+
23492367
/-! ### Lift a relation to `Multiset`s -/
23502368

23512369

0 commit comments

Comments
 (0)