-
Notifications
You must be signed in to change notification settings - Fork 247
/
Basic.lean
1271 lines (1000 loc) · 49.3 KB
/
Basic.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
! This file was ported from Lean 3 source module data.fintype.basic
! leanprover-community/mathlib commit 9003f28797c0664a49e4179487267c494477d853
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Finset.Image
/-!
# Finite types
This file defines a typeclass to state that a type is finite.
## Main declarations
* `Fintype α`: Typeclass saying that a type is finite. It takes as fields a `Finset` and a proof
that all terms of type `α` are in it.
* `Finset.univ`: The finset of all elements of a fintype.
See `Data.Fintype.Card` for the cardinality of a fintype,
the equivalence with `Fin (Fintype.card α)`, and pigeonhole principles.
## Instances
Instances for `Fintype` for
* `{x // p x}` are in this file as `Fintype.subtype`
* `Option α` are in `Data.Fintype.Option`
* `α × β` are in `Data.Fintype.Prod`
* `α ⊕ β` are in `Data.Fintype.Sum`
* `Σ (a : α), β a` are in `Data.Fintype.Sigma`
These files also contain appropriate `Infinite` instances for these types.
`Infinite` instances for `ℕ`, `ℤ`, `Multiset α`, and `List α` are in `Data.Fintype.Lattice`.
Types which have a surjection from/an injection to a `Fintype` are themselves fintypes.
See `Fintype.ofInjective` and `Fintype.ofSurjective`.
-/
open Function
open Nat
universe u v
variable {α β γ : Type _}
/-- `Fintype α` means that `α` is finite, i.e. there are only
finitely many distinct elements of type `α`. The evidence of this
is a finset `elems` (a list up to permutation without duplicates),
together with a proof that everything of type `α` is in the list. -/
class Fintype (α : Type _) where
/-- The `Finset` containing all elements of a `Fintype` -/
elems : Finset α
/-- A proof that `elems` contains every element of the type -/
complete : ∀ x : α, x ∈ elems
#align fintype Fintype
namespace Finset
variable [Fintype α] {s t : Finset α}
/-- `univ` is the universal finite set of type `Finset α` implied from
the assumption `Fintype α`. -/
def univ : Finset α :=
@Fintype.elems α _
#align finset.univ Finset.univ
@[simp]
theorem mem_univ (x : α) : x ∈ (univ : Finset α) :=
Fintype.complete x
#align finset.mem_univ Finset.mem_univ
--Porting note: removing @[simp], simp can prove it
theorem mem_univ_val : ∀ x, x ∈ (univ : Finset α).1 :=
mem_univ
#align finset.mem_univ_val Finset.mem_univ_val
theorem eq_univ_iff_forall : s = univ ↔ ∀ x, x ∈ s := by simp [ext_iff]
#align finset.eq_univ_iff_forall Finset.eq_univ_iff_forall
theorem eq_univ_of_forall : (∀ x, x ∈ s) → s = univ :=
eq_univ_iff_forall.2
#align finset.eq_univ_of_forall Finset.eq_univ_of_forall
@[simp, norm_cast]
theorem coe_univ : ↑(univ : Finset α) = (Set.univ : Set α) := by ext; simp
#align finset.coe_univ Finset.coe_univ
@[simp, norm_cast]
theorem coe_eq_univ : (s : Set α) = Set.univ ↔ s = univ := by rw [← coe_univ, coe_inj]
#align finset.coe_eq_univ Finset.coe_eq_univ
theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ :=
by
rintro ⟨x, hx⟩
refine' eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x]
#align finset.nonempty.eq_univ Finset.Nonempty.eq_univ
theorem univ_nonempty_iff : (univ : Finset α).Nonempty ↔ Nonempty α := by
rw [← coe_nonempty, coe_univ, Set.nonempty_iff_univ_nonempty]
#align finset.univ_nonempty_iff Finset.univ_nonempty_iff
theorem univ_nonempty [Nonempty α] : (univ : Finset α).Nonempty :=
univ_nonempty_iff.2 ‹_›
#align finset.univ_nonempty Finset.univ_nonempty
theorem univ_eq_empty_iff : (univ : Finset α) = ∅ ↔ IsEmpty α := by
rw [← not_nonempty_iff, ← univ_nonempty_iff, not_nonempty_iff_eq_empty]
#align finset.univ_eq_empty_iff Finset.univ_eq_empty_iff
@[simp]
theorem univ_eq_empty [IsEmpty α] : (univ : Finset α) = ∅ :=
univ_eq_empty_iff.2 ‹_›
#align finset.univ_eq_empty Finset.univ_eq_empty
@[simp]
theorem univ_unique [Unique α] : (univ : Finset α) = {default} :=
Finset.ext fun x => iff_of_true (mem_univ _) <| mem_singleton.2 <| Subsingleton.elim x default
#align finset.univ_unique Finset.univ_unique
@[simp]
theorem subset_univ (s : Finset α) : s ⊆ univ := fun a _ => mem_univ a
#align finset.subset_univ Finset.subset_univ
instance : BoundedOrder (Finset α) :=
{ inferInstanceAs (OrderBot (Finset α)) with
top := univ
le_top := subset_univ }
@[simp]
theorem top_eq_univ : (⊤ : Finset α) = univ :=
rfl
#align finset.top_eq_univ Finset.top_eq_univ
theorem ssubset_univ_iff {s : Finset α} : s ⊂ univ ↔ s ≠ univ :=
@lt_top_iff_ne_top _ _ _ s
#align finset.ssubset_univ_iff Finset.ssubset_univ_iff
theorem codisjoint_left : Codisjoint s t ↔ ∀ ⦃a⦄, a ∉ s → a ∈ t := by
classical simp [codisjoint_iff, eq_univ_iff_forall, or_iff_not_imp_left]
#align finset.codisjoint_left Finset.codisjoint_left
theorem codisjoint_right : Codisjoint s t ↔ ∀ ⦃a⦄, a ∉ t → a ∈ s :=
Codisjoint_comm.trans codisjoint_left
#align finset.codisjoint_right Finset.codisjoint_right
section BooleanAlgebra
variable [DecidableEq α] {a : α}
instance : BooleanAlgebra (Finset α) :=
GeneralizedBooleanAlgebra.toBooleanAlgebra
theorem sdiff_eq_inter_compl (s t : Finset α) : s \ t = s ∩ tᶜ :=
sdiff_eq
#align finset.sdiff_eq_inter_compl Finset.sdiff_eq_inter_compl
theorem compl_eq_univ_sdiff (s : Finset α) : sᶜ = univ \ s :=
rfl
#align finset.compl_eq_univ_sdiff Finset.compl_eq_univ_sdiff
@[simp]
theorem mem_compl : a ∈ sᶜ ↔ a ∉ s := by simp [compl_eq_univ_sdiff]
#align finset.mem_compl Finset.mem_compl
theorem not_mem_compl : a ∉ sᶜ ↔ a ∈ s := by rw [mem_compl, not_not]
#align finset.not_mem_compl Finset.not_mem_compl
@[simp, norm_cast]
theorem coe_compl (s : Finset α) : ↑(sᶜ) = (↑s : Set α)ᶜ :=
Set.ext fun _ => mem_compl
#align finset.coe_compl Finset.coe_compl
@[simp]
theorem compl_empty : (∅ : Finset α)ᶜ = univ :=
compl_bot
#align finset.compl_empty Finset.compl_empty
@[simp]
theorem compl_univ : (univ : Finset α)ᶜ = ∅ :=
compl_top
#align finset.compl_univ Finset.compl_univ
@[simp]
theorem compl_eq_empty_iff (s : Finset α) : sᶜ = ∅ ↔ s = univ :=
compl_eq_bot
#align finset.compl_eq_empty_iff Finset.compl_eq_empty_iff
@[simp]
theorem compl_eq_univ_iff (s : Finset α) : sᶜ = univ ↔ s = ∅ :=
compl_eq_top
#align finset.compl_eq_univ_iff Finset.compl_eq_univ_iff
@[simp]
theorem union_compl (s : Finset α) : s ∪ sᶜ = univ :=
sup_compl_eq_top
#align finset.union_compl Finset.union_compl
@[simp]
theorem inter_compl (s : Finset α) : s ∩ sᶜ = ∅ :=
inf_compl_eq_bot
#align finset.inter_compl Finset.inter_compl
@[simp]
theorem compl_union (s t : Finset α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ :=
compl_sup
#align finset.compl_union Finset.compl_union
@[simp]
theorem compl_inter (s t : Finset α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ :=
compl_inf
#align finset.compl_inter Finset.compl_inter
@[simp]
theorem compl_erase : s.erase aᶜ = insert a (sᶜ) :=
by
ext
simp only [or_iff_not_imp_left, mem_insert, not_and, mem_compl, mem_erase]
#align finset.compl_erase Finset.compl_erase
@[simp]
theorem compl_insert : insert a sᶜ = sᶜ.erase a :=
by
ext
simp only [not_or, mem_insert, iff_self_iff, mem_compl, mem_erase]
#align finset.compl_insert Finset.compl_insert
@[simp]
theorem insert_compl_self (x : α) : insert x ({x}ᶜ : Finset α) = univ := by
rw [← compl_erase, erase_singleton, compl_empty]
#align finset.insert_compl_self Finset.insert_compl_self
@[simp]
theorem compl_filter (p : α → Prop) [DecidablePred p] [∀ x, Decidable ¬p x] :
univ.filter pᶜ = univ.filter fun x => ¬p x :=
ext <| by simp
#align finset.compl_filter Finset.compl_filter
theorem compl_ne_univ_iff_nonempty (s : Finset α) : sᶜ ≠ univ ↔ s.Nonempty := by
simp [eq_univ_iff_forall, Finset.Nonempty]
#align finset.compl_ne_univ_iff_nonempty Finset.compl_ne_univ_iff_nonempty
theorem compl_singleton (a : α) : ({a} : Finset α)ᶜ = univ.erase a := by
rw [compl_eq_univ_sdiff, sdiff_singleton_eq_erase]
#align finset.compl_singleton Finset.compl_singleton
theorem insert_inj_on' (s : Finset α) : Set.InjOn (fun a => insert a s) (sᶜ : Finset α) :=
by
rw [coe_compl]
exact s.insert_inj_on
#align finset.insert_inj_on' Finset.insert_inj_on'
theorem image_univ_of_surjective [Fintype β] {f : β → α} (hf : Surjective f) :
univ.image f = univ :=
eq_univ_of_forall <| hf.forall.2 fun _ => mem_image_of_mem _ <| mem_univ _
#align finset.image_univ_of_surjective Finset.image_univ_of_surjective
end BooleanAlgebra
theorem map_univ_of_surjective [Fintype β] {f : β ↪ α} (hf : Surjective f) : univ.map f = univ :=
eq_univ_of_forall <| hf.forall.2 fun _ => mem_map_of_mem _ <| mem_univ _
#align finset.map_univ_of_surjective Finset.map_univ_of_surjective
@[simp]
theorem map_univ_equiv [Fintype β] (f : β ≃ α) : univ.map f.toEmbedding = univ :=
map_univ_of_surjective f.surjective
#align finset.map_univ_equiv Finset.map_univ_equiv
@[simp]
theorem univ_inter [DecidableEq α] (s : Finset α) : univ ∩ s = s :=
ext fun a => by simp
#align finset.univ_inter Finset.univ_inter
@[simp]
theorem inter_univ [DecidableEq α] (s : Finset α) : s ∩ univ = s := by rw [inter_comm, univ_inter]
#align finset.inter_univ Finset.inter_univ
@[simp]
theorem piecewise_univ [∀ i : α, Decidable (i ∈ (univ : Finset α))] {δ : α → Sort _}
(f g : ∀ i, δ i) : univ.piecewise f g = f :=
by
ext i
simp [piecewise]
#align finset.piecewise_univ Finset.piecewise_univ
theorem piecewise_compl [DecidableEq α] (s : Finset α) [∀ i : α, Decidable (i ∈ s)]
[∀ i : α, Decidable (i ∈ sᶜ)] {δ : α → Sort _} (f g : ∀ i, δ i) :
sᶜ.piecewise f g = s.piecewise g f := by
ext i
simp [piecewise]
#align finset.piecewise_compl Finset.piecewise_compl
@[simp]
theorem piecewise_erase_univ {δ : α → Sort _} [DecidableEq α] (a : α) (f g : ∀ a, δ a) :
(Finset.univ.erase a).piecewise f g = Function.update f a (g a) := by
rw [← compl_singleton, piecewise_compl, piecewise_singleton]
#align finset.piecewise_erase_univ Finset.piecewise_erase_univ
theorem univ_map_equiv_to_embedding {α β : Type _} [Fintype α] [Fintype β] (e : α ≃ β) :
univ.map e.toEmbedding = univ :=
eq_univ_iff_forall.mpr fun b => mem_map.mpr ⟨e.symm b, mem_univ _, by simp⟩
#align finset.univ_map_equiv_to_embedding Finset.univ_map_equiv_to_embedding
@[simp]
theorem univ_filter_exists (f : α → β) [Fintype β] [DecidablePred fun y => ∃ x, f x = y]
[DecidableEq β] : (Finset.univ.filter fun y => ∃ x, f x = y) = Finset.univ.image f :=
by
ext
simp
#align finset.univ_filter_exists Finset.univ_filter_exists
/-- Note this is a special case of `(finset.image_preimage f univ _).symm`. -/
theorem univ_filter_mem_range (f : α → β) [Fintype β] [DecidablePred fun y => y ∈ Set.range f]
[DecidableEq β] : (Finset.univ.filter fun y => y ∈ Set.range f) = Finset.univ.image f := by
letI : DecidablePred (fun y => ∃ x, f x = y) := by simpa using ‹_›
exact univ_filter_exists f
#align finset.univ_filter_mem_range Finset.univ_filter_mem_range
theorem coe_filter_univ (p : α → Prop) [DecidablePred p] : (univ.filter p : Set α) = { x | p x } :=
by simp
#align finset.coe_filter_univ Finset.coe_filter_univ
end Finset
open Finset Function
namespace Fintype
instance decidablePiFintype {α} {β : α → Type _} [∀ a, DecidableEq (β a)] [Fintype α] :
DecidableEq (∀ a, β a) := fun f g =>
decidable_of_iff (∀ a ∈ @Fintype.elems α _, f a = g a)
(by simp [Function.funext_iff, Fintype.complete])
#align fintype.decidable_pi_fintype Fintype.decidablePiFintype
instance decidableForallFintype {p : α → Prop} [DecidablePred p] [Fintype α] :
Decidable (∀ a, p a) :=
decidable_of_iff (∀ a ∈ @univ α _, p a) (by simp)
#align fintype.decidable_forall_fintype Fintype.decidableForallFintype
instance decidableExistsFintype {p : α → Prop} [DecidablePred p] [Fintype α] :
Decidable (∃ a, p a) :=
decidable_of_iff (∃ a ∈ @univ α _, p a) (by simp)
#align fintype.decidable_exists_fintype Fintype.decidableExistsFintype
instance decidableMemRangeFintype [Fintype α] [DecidableEq β] (f : α → β) :
DecidablePred (· ∈ Set.range f) := fun _ => Fintype.decidableExistsFintype
#align fintype.decidable_mem_range_fintype Fintype.decidableMemRangeFintype
section BundledHoms
instance decidableEqEquivFintype [DecidableEq β] [Fintype α] : DecidableEq (α ≃ β) := fun a b =>
decidable_of_iff (a.1 = b.1) Equiv.coe_fn_injective.eq_iff
#align fintype.decidable_eq_equiv_fintype Fintype.decidableEqEquivFintype
instance decidableEqEmbeddingFintype [DecidableEq β] [Fintype α] : DecidableEq (α ↪ β) := fun a b =>
decidable_of_iff ((a : α → β) = b) Function.Embedding.coe_injective.eq_iff
#align fintype.decidable_eq_embedding_fintype Fintype.decidableEqEmbeddingFintype
@[to_additive]
instance decidableEqOneHomFintype [DecidableEq β] [Fintype α] [One α] [One β] :
DecidableEq (OneHom α β) := fun a b =>
decidable_of_iff ((a : α → β) = b) (Injective.eq_iff FunLike.coe_injective)
#align fintype.decidable_eq_one_hom_fintype Fintype.decidableEqOneHomFintype
#align fintype.decidable_eq_zero_hom_fintype Fintype.decidableEqZeroHomFintype
@[to_additive]
instance decidableEqMulHomFintype [DecidableEq β] [Fintype α] [Mul α] [Mul β] :
DecidableEq (α →ₙ* β) := fun a b =>
decidable_of_iff ((a : α → β) = b) (Injective.eq_iff FunLike.coe_injective)
#align fintype.decidable_eq_mul_hom_fintype Fintype.decidableEqMulHomFintype
#align fintype.decidable_eq_add_hom_fintype Fintype.decidableEqAddHomFintype
@[to_additive]
instance decidableEqMonoidHomFintype [DecidableEq β] [Fintype α] [MulOneClass α] [MulOneClass β] :
DecidableEq (α →* β) := fun a b =>
decidable_of_iff ((a : α → β) = b) (Injective.eq_iff FunLike.coe_injective)
#align fintype.decidable_eq_monoid_hom_fintype Fintype.decidableEqMonoidHomFintype
#align fintype.decidable_eq_add_monoid_hom_fintype Fintype.decidableEqAddMonoidHomFintype
instance decidableEqMonoidWithZeroHomFintype [DecidableEq β] [Fintype α] [MulZeroOneClass α]
[MulZeroOneClass β] : DecidableEq (α →*₀ β) := fun a b =>
decidable_of_iff ((a : α → β) = b) (Injective.eq_iff FunLike.coe_injective)
#align fintype.decidable_eq_monoid_with_zero_hom_fintype Fintype.decidableEqMonoidWithZeroHomFintype
instance decidableEqRingHomFintype [DecidableEq β] [Fintype α] [Semiring α] [Semiring β] :
DecidableEq (α →+* β) := fun a b =>
decidable_of_iff ((a : α → β) = b) (Injective.eq_iff RingHom.coe_inj)
#align fintype.decidable_eq_ring_hom_fintype Fintype.decidableEqRingHomFintype
end BundledHoms
instance decidableInjectiveFintype [DecidableEq α] [DecidableEq β] [Fintype α] :
DecidablePred (Injective : (α → β) → Prop) := fun x => by unfold Injective; infer_instance
#align fintype.decidable_injective_fintype Fintype.decidableInjectiveFintype
instance decidableSurjectiveFintype [DecidableEq β] [Fintype α] [Fintype β] :
DecidablePred (Surjective : (α → β) → Prop) := fun x => by unfold Surjective; infer_instance
#align fintype.decidable_surjective_fintype Fintype.decidableSurjectiveFintype
instance decidableBijectiveFintype [DecidableEq α] [DecidableEq β] [Fintype α] [Fintype β] :
DecidablePred (Bijective : (α → β) → Prop) := fun x => by unfold Bijective; infer_instance
#align fintype.decidable_bijective_fintype Fintype.decidableBijectiveFintype
instance decidableRightInverseFintype [DecidableEq α] [Fintype α] (f : α → β) (g : β → α) :
Decidable (Function.RightInverse f g) :=
show Decidable (∀ x, g (f x) = x) by infer_instance
#align fintype.decidable_right_inverse_fintype Fintype.decidableRightInverseFintype
instance decidableLeftInverseFintype [DecidableEq β] [Fintype β] (f : α → β) (g : β → α) :
Decidable (Function.LeftInverse f g) :=
show Decidable (∀ x, f (g x) = x) by infer_instance
#align fintype.decidable_left_inverse_fintype Fintype.decidableLeftInverseFintype
/-- Construct a proof of `Fintype α` from a universal multiset -/
def ofMultiset [DecidableEq α] (s : Multiset α) (H : ∀ x : α, x ∈ s) : Fintype α :=
⟨s.toFinset, by simpa using H⟩
#align fintype.of_multiset Fintype.ofMultiset
/-- Construct a proof of `Fintype α` from a universal list -/
def ofList [DecidableEq α] (l : List α) (H : ∀ x : α, x ∈ l) : Fintype α :=
⟨l.toFinset, by simpa using H⟩
#align fintype.of_list Fintype.ofList
instance (α : Type _) : Subsingleton (Fintype α) :=
⟨fun ⟨s₁, h₁⟩ ⟨s₂, h₂⟩ => by congr; simp [Finset.ext_iff, h₁, h₂]⟩
/-- Given a predicate that can be represented by a finset, the subtype
associated to the predicate is a fintype. -/
protected def subtype {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x) :
Fintype { x // p x } :=
⟨⟨s.1.pmap Subtype.mk fun x => (H x).1, s.nodup.pmap fun _ _ _ _ => congr_arg Subtype.val⟩,
fun ⟨x, px⟩ => Multiset.mem_pmap.2 ⟨x, (H x).2 px, rfl⟩⟩
#align fintype.subtype Fintype.subtype
/-- Construct a fintype from a finset with the same elements. -/
def ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : Fintype p :=
Fintype.subtype s H
#align fintype.of_finset Fintype.ofFinset
/-- If `f : α → β` is a bijection and `α` is a fintype, then `β` is also a fintype. -/
def ofBijective [Fintype α] (f : α → β) (H : Function.Bijective f) : Fintype β :=
⟨univ.map ⟨f, H.1⟩, fun b =>
let ⟨_, e⟩ := H.2 b
e ▸ mem_map_of_mem _ (mem_univ _)⟩
#align fintype.of_bijective Fintype.ofBijective
/-- If `f : α → β` is a surjection and `α` is a fintype, then `β` is also a fintype. -/
def ofSurjective [DecidableEq β] [Fintype α] (f : α → β) (H : Function.Surjective f) : Fintype β :=
⟨univ.image f, fun b =>
let ⟨_, e⟩ := H b
e ▸ mem_image_of_mem _ (mem_univ _)⟩
#align fintype.of_surjective Fintype.ofSurjective
end Fintype
namespace Finset
variable [Fintype α] [DecidableEq α] {s t : Finset α}
instance decidableCodisjoint : Decidable (Codisjoint s t) :=
decidable_of_iff _ codisjoint_left.symm
#align finset.decidable_codisjoint Finset.decidableCodisjoint
instance decidableIsCompl : Decidable (IsCompl s t) :=
decidable_of_iff' _ isCompl_iff
#align finset.decidable_is_compl Finset.decidableIsCompl
end Finset
section Inv
namespace Function
variable [Fintype α] [DecidableEq β]
namespace Injective
variable {f : α → β} (hf : Function.Injective f)
/-- The inverse of an `hf : injective` function `f : α → β`, of the type `↥(Set.range f) → α`.
This is the computable version of `Function.invFun` that requires `Fintype α` and `DecidableEq β`,
or the function version of applying `(Equiv.ofInjective f hf).symm`.
This function should not usually be used for actual computation because for most cases,
an explicit inverse can be stated that has better computational properties.
This function computes by checking all terms `a : α` to find the `f a = b`, so it is O(N) where
`N = Fintype.card α`.
-/
def invOfMemRange : Set.range f → α := fun b =>
Finset.choose (fun a => f a = b) Finset.univ
((exists_unique_congr (by simp)).mp (hf.exists_unique_of_mem_range b.property))
#align function.injective.inv_of_mem_range Function.Injective.invOfMemRange
theorem left_inv_of_invOfMemRange (b : Set.range f) : f (hf.invOfMemRange b) = b :=
(Finset.choose_spec (fun a => f a = b) _ _).right
#align function.injective.left_inv_of_inv_of_mem_range Function.Injective.left_inv_of_invOfMemRange
@[simp]
theorem right_inv_of_invOfMemRange (a : α) : hf.invOfMemRange ⟨f a, Set.mem_range_self a⟩ = a :=
hf (Finset.choose_spec (fun a' => f a' = f a) _ _).right
#align function.injective.right_inv_of_inv_of_mem_range Function.Injective.right_inv_of_invOfMemRange
theorem invFun_restrict [Nonempty α] : (Set.range f).restrict (invFun f) = hf.invOfMemRange :=
by
ext ⟨b, h⟩
apply hf
simp [hf.left_inv_of_invOfMemRange, @invFun_eq _ _ _ f b (Set.mem_range.mp h)]
#align function.injective.inv_fun_restrict Function.Injective.invFun_restrict
theorem invOfMemRange_surjective : Function.Surjective hf.invOfMemRange := fun a =>
⟨⟨f a, Set.mem_range_self a⟩, by simp⟩
#align function.injective.inv_of_mem_range_surjective Function.Injective.invOfMemRange_surjective
end Injective
namespace Embedding
variable (f : α ↪ β) (b : Set.range f)
/-- The inverse of an embedding `f : α ↪ β`, of the type `↥(Set.range f) → α`.
This is the computable version of `Function.invFun` that requires `Fintype α` and `DecidableEq β`,
or the function version of applying `(Equiv.ofInjective f f.injective).symm`.
This function should not usually be used for actual computation because for most cases,
an explicit inverse can be stated that has better computational properties.
This function computes by checking all terms `a : α` to find the `f a = b`, so it is O(N) where
`N = Fintype.card α`.
-/
def invOfMemRange : α :=
f.injective.invOfMemRange b
#align function.embedding.inv_of_mem_range Function.Embedding.invOfMemRange
@[simp]
theorem left_inv_of_invOfMemRange : f (f.invOfMemRange b) = b :=
f.injective.left_inv_of_invOfMemRange b
#align function.embedding.left_inv_of_inv_of_mem_range Function.Embedding.left_inv_of_invOfMemRange
@[simp]
theorem right_inv_of_invOfMemRange (a : α) : f.invOfMemRange ⟨f a, Set.mem_range_self a⟩ = a :=
f.injective.right_inv_of_invOfMemRange a
#align function.embedding.right_inv_of_inv_of_mem_range Function.Embedding.right_inv_of_invOfMemRange
theorem invFun_restrict [Nonempty α] : (Set.range f).restrict (invFun f) = f.invOfMemRange :=
by
ext ⟨b, h⟩
apply f.injective
simp [f.left_inv_of_invOfMemRange, @invFun_eq _ _ _ f b (Set.mem_range.mp h)]
#align function.embedding.inv_fun_restrict Function.Embedding.invFun_restrict
theorem invOfMemRange_surjective : Function.Surjective f.invOfMemRange := fun a =>
⟨⟨f a, Set.mem_range_self a⟩, by simp⟩
#align function.embedding.inv_of_mem_range_surjective Function.Embedding.invOfMemRange_surjective
end Embedding
end Function
end Inv
namespace Fintype
/-- Given an injective function to a fintype, the domain is also a
fintype. This is noncomputable because injectivity alone cannot be
used to construct preimages. -/
noncomputable def ofInjective [Fintype β] (f : α → β) (H : Function.Injective f) : Fintype α :=
letI := Classical.dec
if hα : Nonempty α then
letI := Classical.inhabited_of_nonempty hα
ofSurjective (invFun f) (invFun_surjective H)
else ⟨∅, fun x => (hα ⟨x⟩).elim⟩
#align fintype.of_injective Fintype.ofInjective
/-- If `f : α ≃ β` and `α` is a fintype, then `β` is also a fintype. -/
def ofEquiv (α : Type _) [Fintype α] (f : α ≃ β) : Fintype β :=
ofBijective _ f.bijective
#align fintype.of_equiv Fintype.ofEquiv
/-- Any subsingleton type with a witness is a fintype (with one term). -/
def ofSubsingleton (a : α) [Subsingleton α] : Fintype α :=
⟨{a}, fun _ => Finset.mem_singleton.2 (Subsingleton.elim _ _)⟩
#align fintype.of_subsingleton Fintype.ofSubsingleton
@[simp]
theorem univ_ofSubsingleton (a : α) [Subsingleton α] : @univ _ (ofSubsingleton a) = {a} :=
rfl
#align fintype.univ_of_subsingleton Fintype.univ_ofSubsingleton
-- see Note [lower instance priority]
instance (priority := 100) ofIsEmpty [IsEmpty α] : Fintype α :=
⟨∅, isEmptyElim⟩
#align fintype.of_is_empty Fintype.ofIsEmpty
-- no-lint since while `Finset.univ_eq_empty` can prove this, it isn't applicable for `dsimp`.
/-- Note: this lemma is specifically about `Fintype.of_isEmpty`. For a statement about
arbitrary `Fintype` instances, use `Finset.univ_eq_empty`. -/
@[simp, nolint simpNF]
theorem univ_of_isEmpty [IsEmpty α] : @univ α _ = ∅ :=
rfl
#align fintype.univ_of_is_empty Fintype.univ_of_isEmpty
end Fintype
namespace Set
variable {s t : Set α}
/-- Construct a finset enumerating a set `s`, given a `Fintype` instance. -/
def toFinset (s : Set α) [Fintype s] : Finset α :=
(@Finset.univ s _).map <| Function.Embedding.subtype _
#align set.to_finset Set.toFinset
@[congr]
theorem toFinset_congr {s t : Set α} [Fintype s] [Fintype t] (h : s = t) :
toFinset s = toFinset t := by subst h; congr; exact Subsingleton.elim _ _
#align set.to_finset_congr Set.toFinset_congr
@[simp]
theorem mem_toFinset {s : Set α} [Fintype s] {a : α} : a ∈ s.toFinset ↔ a ∈ s := by
simp [toFinset]
#align set.mem_to_finset Set.mem_toFinset
/-- Many `Fintype` instances for sets are defined using an extensionally equal `Finset`.
Rewriting `s.toFinset` with `Set.toFinset_ofFinset` replaces the term with such a `Finset`. -/
theorem toFinset_ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) :
@Set.toFinset _ p (Fintype.ofFinset s H) = s :=
Finset.ext fun x => by rw [@mem_toFinset _ _ (id _), H]
#align set.to_finset_of_finset Set.toFinset_ofFinset
/-- Membership of a set with a `Fintype` instance is decidable.
Using this as an instance leads to potential loops with `Subtype.fintype` under certain decidability
assumptions, so it should only be declared a local instance. -/
def decidableMemOfFintype [DecidableEq α] (s : Set α) [Fintype s] (a) : Decidable (a ∈ s) :=
decidable_of_iff _ mem_toFinset
#align set.decidable_mem_of_fintype Set.decidableMemOfFintype
@[simp]
theorem coe_toFinset (s : Set α) [Fintype s] : (↑s.toFinset : Set α) = s :=
Set.ext fun _ => mem_toFinset
#align set.coe_to_finset Set.coe_toFinset
@[simp]
theorem toFinset_nonempty {s : Set α} [Fintype s] : s.toFinset.Nonempty ↔ s.Nonempty := by
rw [← Finset.coe_nonempty, coe_toFinset]
#align set.to_finset_nonempty Set.toFinset_nonempty
@[simp]
theorem toFinset_inj {s t : Set α} [Fintype s] [Fintype t] : s.toFinset = t.toFinset ↔ s = t :=
⟨fun h => by rw [← s.coe_toFinset, h, t.coe_toFinset], fun h => by simp [h] ⟩
#align set.to_finset_inj Set.toFinset_inj
@[mono]
theorem toFinset_subset_toFinset [Fintype s] [Fintype t] : s.toFinset ⊆ t.toFinset ↔ s ⊆ t := by
simp [Finset.subset_iff, Set.subset_def]
#align set.to_finset_subset_to_finset Set.toFinset_subset_toFinset
@[simp]
theorem toFinset_ssubset [Fintype s] {t : Finset α} : s.toFinset ⊂ t ↔ s ⊂ t := by
rw [← Finset.coe_ssubset, coe_toFinset]
#align set.to_finset_ssubset Set.toFinset_ssubset
@[simp]
theorem subset_toFinset {s : Finset α} [Fintype t] : s ⊆ t.toFinset ↔ ↑s ⊆ t := by
rw [← Finset.coe_subset, coe_toFinset]
#align set.subset_to_finset Set.subset_toFinset
@[simp]
theorem ssubset_toFinset {s : Finset α} [Fintype t] : s ⊂ t.toFinset ↔ ↑s ⊂ t := by
rw [← Finset.coe_ssubset, coe_toFinset]
#align set.ssubset_to_finset Set.ssubset_toFinset
@[mono]
theorem toFinset_ssubset_toFinset [Fintype s] [Fintype t] : s.toFinset ⊂ t.toFinset ↔ s ⊂ t := by
simp only [Finset.ssubset_def, toFinset_subset_toFinset, ssubset_def]
#align set.to_finset_ssubset_to_finset Set.toFinset_ssubset_toFinset
@[simp]
theorem toFinset_subset [Fintype s] {t : Finset α} : s.toFinset ⊆ t ↔ s ⊆ t := by
rw [← Finset.coe_subset, coe_toFinset]
#align set.to_finset_subset Set.toFinset_subset
alias toFinset_subset_toFinset ↔ _ toFinset_mono
#align set.to_finset_mono Set.toFinset_mono
alias toFinset_ssubset_toFinset ↔ _ toFinset_strict_mono
#align set.to_finset_strict_mono Set.toFinset_strict_mono
@[simp]
theorem disjoint_toFinset [Fintype s] [Fintype t] :
Disjoint s.toFinset t.toFinset ↔ Disjoint s t := by simp only [← disjoint_coe, coe_toFinset]
#align set.disjoint_to_finset Set.disjoint_toFinset
section DecidableEq
variable [DecidableEq α] (s t) [Fintype s] [Fintype t]
@[simp]
theorem toFinset_inter [Fintype (s ∩ t : Set _)] : (s ∩ t).toFinset = s.toFinset ∩ t.toFinset :=
by
ext
simp
#align set.to_finset_inter Set.toFinset_inter
@[simp]
theorem toFinset_union [Fintype (s ∪ t : Set _)] : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset :=
by
ext
simp
#align set.to_finset_union Set.toFinset_union
@[simp]
theorem toFinset_diff [Fintype (s \ t : Set _)] : (s \ t).toFinset = s.toFinset \ t.toFinset :=
by
ext
simp
#align set.to_finset_diff Set.toFinset_diff
@[simp]
theorem toFinset_symmDiff [Fintype (s ∆ t : Set _)] : (s ∆ t).toFinset = s.toFinset ∆ t.toFinset :=
by
ext
simp [mem_symmDiff, Finset.mem_symmDiff]
#align set.to_finset_symm_diff Set.toFinset_symmDiff
@[simp]
theorem toFinset_compl [Fintype α] [Fintype (sᶜ : Set _)] : sᶜ.toFinset = s.toFinsetᶜ :=
by
ext
simp
#align set.to_finset_compl Set.toFinset_compl
end DecidableEq
-- TODO The `↥` circumvents an elaboration bug. See comment on `Set.toFinset_univ`.
@[simp]
theorem toFinset_empty [Fintype (∅ : Set α)] : (∅ : Set α).toFinset = ∅ :=
by
ext
simp
#align set.to_finset_empty Set.toFinset_empty
/- TODO Without the coercion arrow (`↥`) there is an elaboration bug in the following two;
it essentially infers `Fintype.{v} (Set.univ.{u} : Set α)` with `v` and `u` distinct.
Reported in leanprover-community/lean#672 -/
@[simp]
theorem toFinset_univ [Fintype α] [Fintype (Set.univ : Set α)] :
(Set.univ : Set α).toFinset = Finset.univ :=
by
ext
simp
#align set.to_finset_univ Set.toFinset_univ
@[simp]
theorem toFinset_eq_empty [Fintype s] : s.toFinset = ∅ ↔ s = ∅ := by
rw [← toFinset_empty, toFinset_inj]
#align set.to_finset_eq_empty Set.toFinset_eq_empty
@[simp]
theorem toFinset_eq_univ [Fintype α] [Fintype s] : s.toFinset = Finset.univ ↔ s = univ := by
rw [← coe_inj, coe_toFinset, coe_univ]
#align set.to_finset_eq_univ Set.toFinset_eq_univ
@[simp]
theorem toFinset_setOf [Fintype α] (p : α → Prop) [DecidablePred p] [Fintype { x | p x }] :
{ x | p x }.toFinset = Finset.univ.filter p := by
ext
simp
#align set.to_finset_set_of Set.toFinset_setOf
--@[simp] Porting note: removing simp, simp can prove it
theorem toFinset_ssubset_univ [Fintype α] {s : Set α} [Fintype s] :
s.toFinset ⊂ Finset.univ ↔ s ⊂ univ := by rw [← coe_ssubset, coe_toFinset, coe_univ]
#align set.to_finset_ssubset_univ Set.toFinset_ssubset_univ
@[simp]
theorem toFinset_image [DecidableEq β] (f : α → β) (s : Set α) [Fintype s] [Fintype (f '' s)] :
(f '' s).toFinset = s.toFinset.image f :=
Finset.coe_injective <| by simp
#align set.to_finset_image Set.toFinset_image
@[simp]
theorem toFinset_range [DecidableEq α] [Fintype β] (f : β → α) [Fintype (Set.range f)] :
(Set.range f).toFinset = Finset.univ.image f :=
by
ext
simp
#align set.to_finset_range Set.toFinset_range
theorem toFinset_singleton (a : α) [Fintype ({a} : Set α)] : ({a} : Set α).toFinset = {a} :=
by
ext
simp
#align set.to_finset_singleton Set.toFinset_singleton
@[simp]
theorem toFinset_insert [DecidableEq α] {a : α} {s : Set α} [Fintype (insert a s : Set α)]
[Fintype s] : (insert a s).toFinset = insert a s.toFinset :=
by
ext
simp
#align set.to_finset_insert Set.toFinset_insert
theorem filter_mem_univ_eq_toFinset [Fintype α] (s : Set α) [Fintype s] [DecidablePred (· ∈ s)] :
Finset.univ.filter (· ∈ s) = s.toFinset := by
ext
simp only [Finset.mem_univ, decide_eq_true_eq, forall_true_left, mem_filter,
true_and, mem_toFinset]
#align set.filter_mem_univ_eq_to_finset Set.filter_mem_univ_eq_toFinset
end Set
@[simp]
theorem Finset.toFinset_coe (s : Finset α) [Fintype (s : Set α)] : (s : Set α).toFinset = s :=
ext fun _ => Set.mem_toFinset
#align finset.to_finset_coe Finset.toFinset_coe
instance Fin.fintype (n : ℕ) : Fintype (Fin n) :=
⟨⟨List.finRange n, List.nodup_finRange n⟩, List.mem_finRange⟩
theorem Fin.univ_def (n : ℕ) : (univ : Finset (Fin n)) = ⟨List.finRange n, List.nodup_finRange n⟩ :=
rfl
#align fin.univ_def Fin.univ_def
@[simp]
theorem Fin.image_succAbove_univ {n : ℕ} (i : Fin (n + 1)) : univ.image i.succAbove = {i}ᶜ :=
by
ext m
simp
#align fin.image_succ_above_univ Fin.image_succAbove_univ
@[simp]
theorem Fin.image_succ_univ (n : ℕ) : (univ : Finset (Fin n)).image Fin.succ = {0}ᶜ := by
rw [← Fin.succAbove_zero, Fin.image_succAbove_univ]
#align fin.image_succ_univ Fin.image_succ_univ
@[simp]
theorem Fin.image_castSucc (n : ℕ) : (univ : Finset (Fin n)).image Fin.castSucc = {Fin.last n}ᶜ :=
by rw [← Fin.succAbove_last, Fin.image_succAbove_univ]
#align fin.image_cast_succ Fin.image_castSucc
/- The following three lemmas use `Finset.cons` instead of `insert` and `Finset.map` instead of
`Finset.image` to reduce proof obligations downstream. -/
/-- Embed `Fin n` into `Fin (n + 1)` by prepending zero to the `univ` -/
theorem Fin.univ_succ (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
cons 0 (univ.map ⟨Fin.succ, Fin.succ_injective _⟩) (by simp [map_eq_image]) :=
by simp [map_eq_image]
#align fin.univ_succ Fin.univ_succ
/-- Embed `Fin n` into `Fin (n + 1)` by appending a new `Fin.last n` to the `univ` -/
theorem Fin.univ_castSucc (n : ℕ) :
(univ : Finset (Fin (n + 1))) =
cons (Fin.last n) (univ.map Fin.castSucc.toEmbedding) (by simp [map_eq_image]) :=
by simp [map_eq_image]
#align fin.univ_cast_succ Fin.univ_castSucc
/-- Embed `Fin n` into `Fin (n + 1)` by inserting
around a specified pivot `p : Fin (n + 1)` into the `univ` -/
theorem Fin.univ_succAbove (n : ℕ) (p : Fin (n + 1)) :
(univ : Finset (Fin (n + 1))) = cons p (univ.map <| (Fin.succAbove p).toEmbedding) (by simp) :=
by simp [map_eq_image]
#align fin.univ_succ_above Fin.univ_succAbove
@[instance]
def Unique.fintype {α : Type _} [Unique α] : Fintype α :=
Fintype.ofSubsingleton default
#align unique.fintype Unique.fintype
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq (y : α) : Fintype { x // x = y } :=
Fintype.subtype {y} (by simp)
#align fintype.subtype_eq Fintype.subtypeEq
/-- Short-circuit instance to decrease search for `Unique.fintype`,
since that relies on a subsingleton elimination for `Unique`. -/
instance Fintype.subtypeEq' (y : α) : Fintype { x // y = x } :=
Fintype.subtype {y} (by simp [eq_comm])
#align fintype.subtype_eq' Fintype.subtypeEq'
--Porting note: removing @[simp], simp can prove it
theorem Fintype.univ_empty : @univ Empty _ = ∅ :=
rfl
#align fintype.univ_empty Fintype.univ_empty
--@[simp] Porting note: removing simp, simp can prove it
theorem Fintype.univ_pempty : @univ PEmpty _ = ∅ :=
rfl
#align fintype.univ_pempty Fintype.univ_pempty
instance : Fintype Unit :=
Fintype.ofSubsingleton ()
theorem Fintype.univ_unit : @univ Unit _ = {()} :=
rfl
#align fintype.univ_unit Fintype.univ_unit
instance : Fintype PUnit :=
Fintype.ofSubsingleton PUnit.unit
--@[simp] Porting note: removing simp, simp can prove it
theorem Fintype.univ_punit : @univ PUnit _ = {PUnit.unit} :=
rfl
#align fintype.univ_punit Fintype.univ_punit
instance : Fintype Bool :=
⟨⟨{true, false}, by simp⟩, fun x => by cases x <;> simp⟩
@[simp]
theorem Fintype.univ_bool : @univ Bool _ = {true, false} :=
rfl
#align fintype.univ_bool Fintype.univ_bool
instance Additive.fintype : ∀ [Fintype α], Fintype (Additive α) :=
Fintype.ofEquiv α Additive.ofMul
#align additive.fintype Additive.fintype
instance Multiplicative.fintype : ∀ [Fintype α], Fintype (Multiplicative α) :=
Fintype.ofEquiv α Multiplicative.ofAdd
#align multiplicative.fintype Multiplicative.fintype
/-- Given that `α × β` is a fintype, `α` is also a fintype. -/
def Fintype.prodLeft {α β} [DecidableEq α] [Fintype (α × β)] [Nonempty β] : Fintype α :=
⟨(@univ (α × β) _).image Prod.fst, fun a => by simp⟩
#align fintype.prod_left Fintype.prodLeft
/-- Given that `α × β` is a fintype, `β` is also a fintype. -/
def Fintype.prodRight {α β} [DecidableEq β] [Fintype (α × β)] [Nonempty α] : Fintype β :=
⟨(@univ (α × β) _).image Prod.snd, fun b => by simp⟩
#align fintype.prod_right Fintype.prodRight
instance (α : Type _) [Fintype α] : Fintype (ULift α) :=
Fintype.ofEquiv _ Equiv.ulift.symm
instance (α : Type _) [Fintype α] : Fintype (PLift α) :=
Fintype.ofEquiv _ Equiv.plift.symm
instance (α : Type _) [Fintype α] : Fintype αᵒᵈ :=
‹Fintype α›
instance (α : Type _) [Finite α] : Finite αᵒᵈ :=
‹Finite α›
instance (α : Type _) [Fintype α] : Fintype (Lex α) :=
‹Fintype α›
section Finset
/-! ### `Fintype (s : Finset α)` -/
instance Finset.fintypeCoeSort {α : Type u} (s : Finset α) : Fintype s :=
⟨s.attach, s.mem_attach⟩
#align finset.fintype_coe_sort Finset.fintypeCoeSort
@[simp]
theorem Finset.univ_eq_attach {α : Type u} (s : Finset α) : (univ : Finset s) = s.attach :=
rfl
#align finset.univ_eq_attach Finset.univ_eq_attach
end Finset
theorem Fintype.coe_image_univ [Fintype α] [DecidableEq β] {f : α → β} :
↑(Finset.image f Finset.univ) = Set.range f :=
by
ext x
simp
#align fintype.coe_image_univ Fintype.coe_image_univ
instance List.Subtype.fintype [DecidableEq α] (l : List α) : Fintype { x // x ∈ l } :=
Fintype.ofList l.attach l.mem_attach
#align list.subtype.fintype List.Subtype.fintype
instance Multiset.Subtype.fintype [DecidableEq α] (s : Multiset α) : Fintype { x // x ∈ s } :=
Fintype.ofMultiset s.attach s.mem_attach
#align multiset.subtype.fintype Multiset.Subtype.fintype
instance Finset.Subtype.fintype (s : Finset α) : Fintype { x // x ∈ s } :=
⟨s.attach, s.mem_attach⟩
#align finset.subtype.fintype Finset.Subtype.fintype
instance FinsetCoe.fintype (s : Finset α) : Fintype (↑s : Set α) :=
Finset.Subtype.fintype s
#align finset_coe.fintype FinsetCoe.fintype
theorem Finset.attach_eq_univ {s : Finset α} : s.attach = Finset.univ :=
rfl
#align finset.attach_eq_univ Finset.attach_eq_univ
instance PLift.fintypeProp (p : Prop) [Decidable p] : Fintype (PLift p) :=
⟨if h : p then {⟨h⟩} else ∅, fun ⟨h⟩ => by simp [h]⟩
#align plift.fintype_Prop PLift.fintypeProp
instance Prop.fintype : Fintype Prop :=
⟨⟨{True, False}, by simp [true_ne_false]⟩, Classical.cases (by simp) (by simp)⟩
#align Prop.fintype Prop.fintype