@@ -641,6 +641,13 @@ by simp [to_finset]
641
641
@[simp] theorem mem_to_finset_val {s : set α} [fintype s] {a : α} : a ∈ s.to_finset.1 ↔ a ∈ s :=
642
642
mem_to_finset
643
643
644
+ /-- Membership of a set with a `fintype` instance is decidable.
645
+
646
+ Using this as an instance leads to potential loops with `subtype.fintype` under certain decidability
647
+ assumptions, so it should only be declared a local instance. -/
648
+ def decidable_mem_of_fintype [decidable_eq α] (s : set α) [fintype s] (a) : decidable (a ∈ s) :=
649
+ decidable_of_iff _ mem_to_finset
650
+
644
651
-- We use an arbitrary `[fintype s]` instance here,
645
652
-- not necessarily coming from a `[fintype α]`.
646
653
@[simp]
@@ -667,9 +674,46 @@ by simp only [finset.ssubset_def, to_finset_mono, ssubset_def]
667
674
disjoint s.to_finset t.to_finset ↔ disjoint s t :=
668
675
by simp only [disjoint_iff_disjoint_coe, coe_to_finset]
669
676
677
+ lemma to_finset_inter {α : Type *} [decidable_eq α] (s t : set α) [fintype (s ∩ t : set α)]
678
+ [fintype s] [fintype t] : (s ∩ t).to_finset = s.to_finset ∩ t.to_finset :=
679
+ by { ext, simp }
680
+
681
+ lemma to_finset_union {α : Type *} [decidable_eq α] (s t : set α) [fintype (s ∪ t : set α)]
682
+ [fintype s] [fintype t] : (s ∪ t).to_finset = s.to_finset ∪ t.to_finset :=
683
+ by { ext, simp }
684
+
685
+ lemma to_finset_diff {α : Type *} [decidable_eq α] (s t : set α) [fintype s] [fintype t]
686
+ [fintype (s \ t : set α)] : (s \ t).to_finset = s.to_finset \ t.to_finset :=
687
+ by { ext, simp }
688
+
689
+ lemma to_finset_ne_eq_erase {α : Type *} [decidable_eq α] [fintype α] (a : α)
690
+ [fintype {x : α | x ≠ a}] : {x : α | x ≠ a}.to_finset = finset.univ.erase a :=
691
+ by { ext, simp }
692
+
670
693
theorem to_finset_compl [decidable_eq α] [fintype α] (s : set α) [fintype s] [fintype ↥sᶜ] :
671
694
(sᶜ).to_finset = s.to_finsetᶜ :=
672
- by { ext a, simp }
695
+ by { ext, simp }
696
+
697
+ /- TODO Without the coercion arrow (`↥`) there is an elaboration bug;
698
+ it essentially infers `fintype.{v} (set.univ.{u} : set α)` with `v` and `u` distinct.
699
+ Reported in leanprover-community/lean#672 -/
700
+ @[simp] lemma to_finset_univ [fintype ↥(set.univ : set α)] [fintype α] :
701
+ (set.univ : set α).to_finset = finset.univ :=
702
+ by { ext, simp }
703
+
704
+ @[simp] lemma to_finset_range [decidable_eq α] [fintype β] (f : β → α) [fintype (set.range f)] :
705
+ (set.range f).to_finset = finset.univ.image f :=
706
+ by { ext, simp }
707
+
708
+ /- TODO The `↥` circumvents an elaboration bug. See comment on `set.to_finset_univ`. -/
709
+ lemma to_finset_singleton (a : α) [fintype ↥({a} : set α)] : ({a} : set α).to_finset = {a} :=
710
+ by { ext, simp }
711
+
712
+ /- TODO The `↥` circumvents an elaboration bug. See comment on `set.to_finset_univ`. -/
713
+ @[simp] lemma to_finset_insert [decidable_eq α] {a : α} {s : set α}
714
+ [fintype ↥(insert a s : set α)] [fintype s] :
715
+ (insert a s).to_finset = insert a s.to_finset :=
716
+ by { ext, simp }
673
717
674
718
lemma filter_mem_univ_eq_to_finset [fintype α] (s : set α) [fintype s] [decidable_pred (∈ s)] :
675
719
finset.univ.filter (∈ s) = s.to_finset :=
@@ -1168,23 +1212,12 @@ instance Prop.fintype : fintype Prop :=
1168
1212
instance subtype.fintype (p : α → Prop ) [decidable_pred p] [fintype α] : fintype {x // p x} :=
1169
1213
fintype.subtype (univ.filter p) (by simp)
1170
1214
1171
- /- TODO Without the coercion arrow (`↥`) there is an elaboration bug;
1172
- it essentially infers `fintype.{v} (set.univ.{u} : set α)` with `v` and `u` distinct.
1173
- Reported in leanprover-community/lean#672 -/
1174
- @[simp] lemma set.to_finset_univ [fintype ↥(set.univ : set α)] [fintype α] :
1175
- (set.univ : set α).to_finset = finset.univ :=
1176
- by { ext, simp only [set.mem_univ, mem_univ, set.mem_to_finset] }
1177
-
1178
1215
@[simp] lemma set.to_finset_eq_empty_iff {s : set α} [fintype s] : s.to_finset = ∅ ↔ s = ∅ :=
1179
- by simp [ext_iff, set.ext_iff]
1216
+ by simp only [ext_iff, set.ext_iff, set.mem_to_finset, not_mem_empty, set.mem_empty_eq ]
1180
1217
1181
1218
@[simp] lemma set.to_finset_empty : (∅ : set α).to_finset = ∅ :=
1182
1219
set.to_finset_eq_empty_iff.mpr rfl
1183
1220
1184
- @[simp] lemma set.to_finset_range [decidable_eq α] [fintype β] (f : β → α) [fintype (set.range f)] :
1185
- (set.range f).to_finset = finset.univ.image f :=
1186
- by simp [ext_iff]
1187
-
1188
1221
/-- A set on a fintype, when coerced to a type, is a fintype. -/
1189
1222
def set_fintype [fintype α] (s : set α) [decidable_pred (∈ s)] : fintype s :=
1190
1223
subtype.fintype (λ x, x ∈ s)
@@ -1412,6 +1445,26 @@ begin
1412
1445
simp
1413
1446
end
1414
1447
1448
+ @[simp]
1449
+ lemma fintype.card_subtype_compl [fintype α]
1450
+ (p : α → Prop ) [fintype {x // p x}] [fintype {x // ¬ p x}] :
1451
+ fintype.card {x // ¬ p x} = fintype.card α - fintype.card {x // p x} :=
1452
+ begin
1453
+ classical,
1454
+ rw [fintype.card_of_subtype (set.to_finset pᶜ), set.to_finset_compl p, finset.card_compl,
1455
+ fintype.card_of_subtype (set.to_finset p)];
1456
+ intro; simp only [set.mem_to_finset, set.mem_compl_eq]; refl,
1457
+ end
1458
+
1459
+ /-- If two subtypes of a fintype have equal cardinality, so do their complements. -/
1460
+ lemma fintype.card_compl_eq_card_compl [fintype α]
1461
+ (p q : α → Prop )
1462
+ [fintype {x // p x}] [fintype {x // ¬ p x}]
1463
+ [fintype {x // q x}] [fintype {x // ¬ q x}]
1464
+ (h : fintype.card {x // p x} = fintype.card {x // q x}) :
1465
+ fintype.card {x // ¬ p x} = fintype.card {x // ¬ q x} :=
1466
+ by simp only [fintype.card_subtype_compl, h]
1467
+
1415
1468
theorem fintype.card_quotient_le [fintype α] (s : setoid α) [decidable_rel ((≈) : α → α → Prop )] :
1416
1469
fintype.card (quotient s) ≤ fintype.card α :=
1417
1470
fintype.card_le_of_surjective _ (surjective_quotient_mk _)
0 commit comments