Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit b4a5b01

Browse files
committed
feat(data/finset/basic): add card_insert_eq_ite (#10209)
Adds the lemma `card_insert_eq_ite` combining the functionality of `card_insert_of_not_mem` and `card_insert_of_mem`, analogous to how `card_erase_eq_ite`.
1 parent 2fd6a77 commit b4a5b01

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/data/finset/basic.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,16 @@ theorem card_insert_le [decidable_eq α] (a : α) (s : finset α) : card (insert
22932293
by by_cases a ∈ s; [{rw [insert_eq_of_mem h], apply nat.le_add_right},
22942294
rw [card_insert_of_not_mem h]]
22952295

2296+
/-- If `a ∈ s` is known, see also `finset.card_insert_of_mem` and
2297+
`finset.card_insert_of_not_mem`. -/
2298+
theorem card_insert_eq_ite [decidable_eq α] {a : α} {s : finset α} :
2299+
card (insert a s) = if a ∈ s then card s else card s + 1 :=
2300+
begin
2301+
by_cases h : a ∈ s,
2302+
{ rw [card_insert_of_mem h, if_pos h] },
2303+
{ rw [card_insert_of_not_mem h, if_neg h] },
2304+
end
2305+
22962306
@[simp] theorem card_singleton (a : α) : card ({a} : finset α) = 1 := card_singleton _
22972307

22982308
lemma card_singleton_inter [decidable_eq α] {x : α} {s : finset α} : ({x} ∩ s).card ≤ 1 :=

0 commit comments

Comments
 (0)