Skip to content

Commit

Permalink
feat(data/finset/basic): add card_insert_eq_ite (#10209)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
BoltonBailey committed Nov 8, 2021
1 parent 2fd6a77 commit b4a5b01
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/data/finset/basic.lean
Expand Up @@ -2293,6 +2293,16 @@ theorem card_insert_le [decidable_eq α] (a : α) (s : finset α) : card (insert
by by_cases a ∈ s; [{rw [insert_eq_of_mem h], apply nat.le_add_right},
rw [card_insert_of_not_mem h]]

/-- If `a ∈ s` is known, see also `finset.card_insert_of_mem` and
`finset.card_insert_of_not_mem`. -/
theorem card_insert_eq_ite [decidable_eq α] {a : α} {s : finset α} :
card (insert a s) = if a ∈ s then card s else card s + 1 :=
begin
by_cases h : a ∈ s,
{ rw [card_insert_of_mem h, if_pos h] },
{ rw [card_insert_of_not_mem h, if_neg h] },
end

@[simp] theorem card_singleton (a : α) : card ({a} : finset α) = 1 := card_singleton _

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

0 comments on commit b4a5b01

Please sign in to comment.