Skip to content

Commit 589431f

Browse files
committed
feat(Data/Finset/Card): add card_{pair,triple}_eq_iff (leanprover-community#39840)
Two simple lemmas which characterise when explicit finsets have maximal size.
1 parent c34d29f commit 589431f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

Mathlib/Data/Finset/Card.lean

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ variable {α β R : Type*}
3939

4040
namespace Finset
4141

42-
variable {s t : Finset α} {a b : α}
42+
variable {s t : Finset α} {a b c : α}
4343

4444
/-- `s.card` is the number of elements of `s`, aka its cardinality.
4545
@@ -135,8 +135,17 @@ theorem card_insert_eq_ite : #(insert a s) = if a ∈ s then #s else #s + 1 := b
135135
@[simp]
136136
theorem card_pair_eq_one_or_two : #{a, b} = 1 ∨ #{a, b} = 2 := by grind
137137

138-
theorem card_pair (h : a ≠ b) : #{a, b} = 2 := by
139-
simp [h]
138+
/-- A two-element finset `{a, b}` has cardinality `2` iff `a ≠ b`. The reverse direction is
139+
`Finset.card_pair`. -/
140+
theorem card_pair_eq_two_iff : #{a, b} = 2 ↔ a ≠ b := by
141+
aesop (add simp card_insert_eq_ite)
142+
143+
alias ⟨_, card_pair⟩ := card_pair_eq_two_iff
144+
145+
/-- A three-element finset `{a, b, c}` has cardinality `3` iff `a`, `b`, `c` are pairwise
146+
distinct. -/
147+
theorem card_triple_eq_three_iff : #{a, b, c} = 3 ↔ a ≠ b ∧ a ≠ c ∧ b ≠ c := by
148+
aesop (add simp card_insert_eq_ite)
140149

141150
/-- $\#(s \setminus \{a\}) = \#s - 1$ if $a \in s$. -/
142151
@[simp, grind =]

0 commit comments

Comments
 (0)