Skip to content

Commit bb2fd92

Browse files
committed
feat(Data/Multiset/Antidiagonal): two structural lemmas
1 parent 859caf7 commit bb2fd92

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Mathlib/Data/Multiset/Antidiagonal.lean

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ theorem antidiagonal_cons (a : α) (s) :
7474
map_coe, antidiagonal_coe', coe_add]
7575
rw [← zip_map, ← zip_map, zip_append, (_ : _ ++ _ = _)] <;> simp
7676

77+
theorem antidiagonal_add (s t : Multiset α) :
78+
(s + t).antidiagonal =
79+
s.antidiagonal.bind fun p ↦ t.antidiagonal.map fun q ↦ (p.1 + q.1, p.2 + q.2) := by
80+
induction s using Multiset.induction_on with
81+
| empty => simp
82+
| cons a s ih =>
83+
simp_rw [cons_add, antidiagonal_cons, ih, add_bind, bind_map, map_bind, map_map]
84+
congr! <;> simp
85+
86+
@[simp]
87+
theorem map_swap_antidiagonal (s : Multiset α) :
88+
s.antidiagonal.map Prod.swap = s.antidiagonal := by
89+
induction s using Multiset.induction_on with
90+
| empty => rfl
91+
| cons a s ih =>
92+
simp only [antidiagonal_cons, map_add, map_map, ← Prod.map_comp_swap,
93+
← Multiset.map_map _ Prod.swap, ih, add_comm]
94+
7795
theorem antidiagonal_eq_map_powerset [DecidableEq α] (s : Multiset α) :
7896
s.antidiagonal = s.powerset.map fun t ↦ (s - t, t) := by
7997
induction s using Multiset.induction_on with

Mathlib/Data/Multiset/Bind.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ theorem mem_bind {b s} {f : α → Multiset β} : b ∈ bind s f ↔ ∃ a ∈ s
153153
@[simp]
154154
theorem card_bind : card (s.bind f) = (s.map (card ∘ f)).sum := by simp [bind]
155155

156+
@[congr]
156157
theorem bind_congr {f g : α → Multiset β} {m : Multiset α} :
157158
(∀ a ∈ m, f a = g a) → bind m f = bind m g := by simp +contextual [bind]
158159

0 commit comments

Comments
 (0)