Finite types #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 afinset
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 asfintype.subtype
option α
are indata.fintype.option
α × β
are indata.fintype.prod
α ⊕ β
are indata.fintype.sum
Σ (a : α), β a
are indata.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.of_injective
and fintype.of_surjective
.
- elems : finset α
- complete : ∀ (x : α), x ∈ fintype.elems α
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.
Instances of this typeclass
- unique.fintype
- fintype.of_is_empty
- set.fintype_insert'
- set_like.fintype
- nonempty_fin_lin_ord.to_fintype
- fin_enum.fintype
- is_simple_order.fintype
- fin.fintype
- fintype.subtype_eq
- fintype.subtype_eq'
- unit.fintype
- punit.fintype
- bool.fintype
- additive.fintype
- multiplicative.fintype
- ulift.fintype
- plift.fintype
- order_dual.fintype
- lex.fintype
- finset.fintype_coe_sort
- list.subtype.fintype
- multiset.subtype.fintype
- finset.subtype.fintype
- finset_coe.fintype
- plift.fintype_Prop
- Prop.fintype
- subtype.fintype
- quotient.fintype
- psigma.fintype_prop_left
- psigma.fintype_prop_right
- psigma.fintype_prop_prop
- pfun_fintype
- option.fintype
- finset.fintype
- set.fintype
- sigma.fintype
- psigma.fintype
- sum.fintype
- pi.fintype
- function.embedding.fintype
- vector.fintype
- sym.sym'.fintype
- sym.fintype
- prod.fintype
- set.fintype_univ
- set.fintype_union
- set.fintype_sep
- set.fintype_inter
- set.fintype_inter_of_left
- set.fintype_inter_of_right
- set.fintype_diff
- set.fintype_diff_left
- set.fintype_Union
- set.fintype_sUnion
- set.fintype_bUnion'
- set.fintype_bind'
- set.fintype_empty
- set.fintype_singleton
- set.fintype_pure
- set.fintype_insert
- set.fintype_image
- set.fintype_range
- set.fintype_map
- set.fintype_lt_nat
- set.fintype_le_nat
- set.fintype_prod
- set.fintype_off_diag
- set.fintype_image2
- set.fintype_seq
- set.fintype_seq'
- set.fintype_mem_finset
- dfinsupp.fintype
- linear_map.fintype_range
- ring_hom.fintype_srange
- ring_hom.fintype_range
- set.fintype_Icc
- set.fintype_Ico
- set.fintype_Ioc
- set.fintype_Ioo
- set.fintype_Ici
- set.fintype_Ioi
- set.fintype_Iic
- set.fintype_Iio
- set.fintype_uIcc
- conj_act.fintype
- quotient_group.fintype_quotient_right_rel
- quotient_add_group.fintype_quotient_right_rel
- quotient_group.fintype
- quotient_add_group.fintype
- subgroup.fintype
- add_subgroup.fintype
- subgroup.fintype_bot
- add_subgroup.fintype_bot
- monoid_hom.fintype_mrange
- add_monoid_hom.fintype_mrange
- monoid_hom.fintype_range
- add_monoid_hom.fintype_range
- submodule.quotient_top.fintype
- submodule.quotient.fintype
- alg_hom.fintype_range
- polynomial.root_set_fintype
- zmod.fintype
- fintype_nodup_list
- cycle.fintype_nodup_cycle
- cycle.fintype_nodup_nontrivial_cycle
- is_noetherian.basis.of_vector_space_index.fintype
- module.free.choose_basis_index.fintype
- finite_dimensional.basis.of_vector_space_index.fintype
- composition_as_set_fintype
- composition_fintype
- nat.partition.fintype
- equiv.fintype
- equiv.perm.vectors_prod_eq_one.fintype
- matrix.fintype
- minpoly.alg_hom.fintype
- ring_hom.fintype_field_range
- finsupp.fintype
- units_int.fintype
- units.fintype
- abelianization.fintype
- polynomial.is_splitting_field.polynomial.splitting_field.fintype
- alg_equiv.fintype
- galois_field.fintype
- sign_type.fintype
- polynomial.gal.fintype
- roots_of_unity.fintype
- free_group.subtype.fintype
- category_theory.discrete_fintype
- category_theory.discrete_hom_fintype
- category_theory.fin_category.fintype_obj
- category_theory.fin_category.fintype_hom
- category_theory.limits.fintype_walking_parallel_pair
- category_theory.limits.walking_parallel_pair_hom.fintype
- category_theory.limits.wide_pullback_shape.fintype_obj
- category_theory.limits.wide_pullback_shape.fintype_hom
- category_theory.limits.wide_pushout_shape.fintype_obj
- category_theory.limits.wide_pushout_shape.fintype_hom
- category_theory.limits.fintype_walking_pair
- Fintype.fintype
- FinPartOrd.is_fintype
- alexandroff.fintype
- category_theory.fin_bicone
- category_theory.fin_bicone_hom
- category_theory.Mat_.F
- module.End.eigenvalues.fintype
- class_group.fintype
- truncated_witt_vector.fintype
- finpartition.fintype
- FinBddDistLat.is_fintype
- FinBoolAlg.is_fintype
- simplicial_object.splitting.index_set.fintype
- lucas_lehmer.X.fintype
- function_field.ring_of_integers.class_group.fintype
- number_field.embeddings.ring_hom.fintype
- number_field.infinite_place.number_field.infinite_place.fintype
- number_field.ring_of_integers.class_group.fintype
- affine.simplex.points_with_circumcenter_index.fintype
- pgame.fintype_left_moves
- pgame.fintype_right_moves
- pgame.fintype_left_moves_of_state_aux
- pgame.fintype_right_moves_of_state_aux
- conj_classes.fintype
- conjugates_of.fintype
- conj_classes.carrier.fintype
- turing.TM2to1.Γ'.fintype
- turing.partrec_to_TM2.Γ'.fintype
- computability.Γ.fintype
- computability.Γ'.fintype
- rel.image.fintype
- configuration.dual.fintype
- derangements.fintype
- simple_graph.fintype
- simple_graph.fintype_edge_set
- simple_graph.fintype_edge_set_bot
- simple_graph.fintype_edge_set_sup
- simple_graph.fintype_edge_set_inf
- simple_graph.fintype_edge_set_sdiff
- simple_graph.edge_set.fintype
- simple_graph.dart.fintype
- simple_graph.incidence_set_fintype
- simple_graph.neighbor_set_fintype
- simple_graph.hom.fintype
- simple_graph.coloring.fintype
- simple_graph.subgraph.finite_at
- simple_graph.subgraph.neighbor_set.fintype
- simple_graph.subgraph.coe_finite_at
- simple_graph.fintype_set_walk_length
- simple_graph.fintype_set_path_length
- simple_graph.connected_component.fintype
- simple_graph.box_prod_fintype_neighbor_set
- set_of.fintype
- multiset.fintype_coe
- d_array.fintype
- array.fintype
- hamming.fintype
- algebraic_geometry.Scheme.J.fintype
- sylow.fintype
- has_quotient.quotient.fintype
- alternating_group.fintype
- dihedral_group.fintype
- quaternion_group.fintype
- sensitivity.Q.fintype
- konigsberg.verts.fintype
- imo1987_q1.fiber.fintype
Instances of other typeclasses for fintype
- fintype.has_sizeof_inst
- fintype.subsingleton
- equiv_functor_fintype
Equations
- finset.bounded_order = {top := finset.univ _inst_1, le_top := _, bot := order_bot.bot finset.order_bot, bot_le := _}
Note this is a special case of (finset.image_preimage f univ _).symm
.
Equations
- fintype.decidable_pi_fintype = λ (f g : Π (a : α), β a), decidable_of_iff (∀ (a : α), a ∈ fintype.elems α → f a = g a) _
Equations
- fintype.decidable_forall_fintype = decidable_of_iff (∀ (a : α), a ∈ finset.univ → p a) fintype.decidable_forall_fintype._proof_1
Equations
- fintype.decidable_exists_fintype = decidable_of_iff (∃ (a : α) (H : a ∈ finset.univ), p a) fintype.decidable_exists_fintype._proof_1
Equations
Equations
- fintype.decidable_eq_equiv_fintype = λ (a b : α ≃ β), decidable_of_iff (a.to_fun = b.to_fun) _
Equations
- fintype.decidable_eq_embedding_fintype = λ (a b : α ↪ β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_one_hom_fintype = λ (a b : one_hom α β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_zero_hom_fintype = λ (a b : zero_hom α β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_mul_hom_fintype = λ (a b : α →ₙ* β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_add_hom_fintype = λ (a b : add_hom α β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_add_monoid_hom_fintype = λ (a b : α →+ β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_monoid_hom_fintype = λ (a b : α →* β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_monoid_with_zero_hom_fintype = λ (a b : α →*₀ β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_eq_ring_hom_fintype = λ (a b : α →+* β), decidable_of_iff (⇑a = ⇑b) _
Equations
- fintype.decidable_injective_fintype = λ (x : α → β), _.mpr fintype.decidable_forall_fintype
Equations
- fintype.decidable_surjective_fintype = λ (x : α → β), _.mpr fintype.decidable_forall_fintype
Equations
- fintype.decidable_bijective_fintype = λ (x : α → β), _.mpr and.decidable
Equations
- fintype.decidable_right_inverse_fintype f g = show decidable (∀ (x : α), g (f x) = x), from fintype.decidable_forall_fintype
Equations
- fintype.decidable_left_inverse_fintype f g = show decidable (∀ (x : β), f (g x) = x), from fintype.decidable_forall_fintype
Construct a proof of fintype α
from a universal multiset
Construct a proof of fintype α
from a universal list
Given a predicate that can be represented by a finset, the subtype associated to the predicate is a fintype.
Equations
- fintype.subtype s H = {elems := {val := multiset.pmap subtype.mk s.val _, nodup := _}, complete := _}
Construct a fintype from a finset with the same elements.
Equations
- fintype.of_finset s H = fintype.subtype s H
If f : α → β
is a bijection and α
is a fintype, then β
is also a fintype.
Equations
- fintype.of_bijective f H = {elems := finset.map {to_fun := f, inj' := _} finset.univ, complete := _}
If f : α → β
is a surjection and α
is a fintype, then β
is also a fintype.
Equations
- fintype.of_surjective f H = {elems := finset.image f finset.univ, complete := _}
Equations
- finset.decidable_codisjoint = decidable_of_iff (∀ ⦃a : α⦄, a ∉ s → a ∈ t) finset.decidable_codisjoint._proof_1
Equations
- finset.decidable_is_compl = decidable_of_iff' (disjoint s t ∧ codisjoint s t) finset.decidable_is_compl._proof_1
The inverse of an hf : injective
function f : α → β
, of the type ↥(set.range f) → α
.
This is the computable version of function.inv_fun
that requires fintype α
and decidable_eq β
,
or the function version of applying (equiv.of_injective 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 α
.
Equations
- hf.inv_of_mem_range = λ (b : ↥(set.range f)), finset.choose (λ (a : α), f a = ↑b) finset.univ _
The inverse of an embedding f : α ↪ β
, of the type ↥(set.range f) → α
.
This is the computable version of function.inv_fun
that requires fintype α
and decidable_eq β
,
or the function version of applying (equiv.of_injective 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 α
.
Equations
- f.inv_of_mem_range b = _.inv_of_mem_range b
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.
Equations
- fintype.of_injective f H = let _inst : Π (p : Prop), decidable p := classical.dec in dite (nonempty α) (λ (hα : nonempty α), let _inst_2 : inhabited α := classical.inhabited_of_nonempty hα in fintype.of_surjective (function.inv_fun f) _) (λ (hα : ¬nonempty α), {elems := ∅, complete := _})
If f : α ≃ β
and α
is a fintype, then β
is also a fintype.
Equations
- fintype.of_equiv α f = fintype.of_bijective ⇑f _
Any subsingleton type with a witness is a fintype (with one term).
Equations
- fintype.of_subsingleton a = {elems := {a}, complete := _}
Note: this lemma is specifically about fintype.of_is_empty
. For a statement about
arbitrary fintype
instances, use finset.univ_eq_empty
.
Construct a finset enumerating a set s
, given a fintype
instance.
Equations
- s.to_finset = finset.map (function.embedding.subtype (λ (x : α), x ∈ s)) finset.univ
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.
Equations
Equations
- fin.fintype n = {elems := {val := ↑(list.fin_range n), nodup := _}, complete := _}
Embed fin n
into fin (n + 1)
by appending a new fin.last n
to the univ
Short-circuit instance to decrease search for unique.fintype
,
since that relies on a subsingleton elimination for unique
.
Equations
- fintype.subtype_eq y = fintype.subtype {y} _
Short-circuit instance to decrease search for unique.fintype
,
since that relies on a subsingleton elimination for unique
.
Equations
- fintype.subtype_eq' y = fintype.subtype {y} _
Equations
Equations
- punit.fintype = fintype.of_subsingleton punit.star
Equations
Equations
Given that α × β
is a fintype, α
is also a fintype.
Equations
- fintype.prod_left = {elems := finset.image prod.fst (fintype.elems (α × β)), complete := _}
Given that α × β
is a fintype, β
is also a fintype.
Equations
- fintype.prod_right = {elems := finset.image prod.snd (fintype.elems (α × β)), complete := _}
Equations
Equations
Equations
- order_dual.fintype α = _inst_1
Equations
- lex.fintype α = _inst_1
Equations
Equations
Equations
Equations
A set on a fintype, when coerced to a type, is a fintype.
Equations
- set_fintype s = subtype.fintype (λ (x : α), x ∈ s)
The αˣ
type is equivalent to a subtype of α × α
.
In a group_with_zero
α
, the unit group αˣ
is equivalent to the subtype of nonzero
elements.
Equations
Equations
- psigma.fintype_prop_right = fintype.of_equiv {a // β a} {to_fun := λ (_x : {a // β a}), psigma.fintype_prop_right._match_1 _x, inv_fun := λ (_x : Σ' (a : α), β a), psigma.fintype_prop_right._match_2 _x, left_inv := _, right_inv := _}
- psigma.fintype_prop_right._match_1 ⟨x, y⟩ = ⟨x, y⟩
- psigma.fintype_prop_right._match_2 ⟨x, y⟩ = ⟨x, y⟩
Given a fintype α
and a predicate p
, associate to a proof that there is a unique element of
α
satisfying p
this unique element, as an element of the corresponding subtype.
Equations
- fintype.choose_x p hp = ⟨finset.choose p finset.univ _, _⟩
Given a fintype α
and a predicate p
, associate to a proof that there is a unique element of
α
satisfying p
this unique element, as an element of α
.
Equations
- fintype.choose p hp = ↑(fintype.choose_x p hp)
bij_inv f
is the unique inverse to a bijection f
. This acts
as a computable alternative to function.inv_fun
.
Equations
- fintype.bij_inv f_bij b = fintype.choose (λ (a : α), f a = b) _
For s : multiset α
, we can lift the existential statement that ∃ x, x ∈ s
to a trunc α
.
Equations
- trunc_of_multiset_exists_mem s = quotient.rec_on_subsingleton s (λ (l : list α) (h : ∃ (x : α), x ∈ ⟦l⟧), trunc_of_multiset_exists_mem._match_1 l h l h)
- trunc_of_multiset_exists_mem._match_1 l h (a :: _x) _x_1 = trunc.mk a
- trunc_of_multiset_exists_mem._match_1 l h list.nil _x = false.elim _
By iterating over the elements of a fintype, we can lift an existential statement ∃ a, P a
to trunc (Σ' a, P a)
, containing data.
Equations
- trunc_sigma_of_exists h = trunc_of_nonempty_fintype (Σ' (a : α), P a)
Auxiliary definition to show exists_seq_of_forall_finset_exists
.
Equations
- seq_of_forall_finset_exists_aux P r h n = classical.some _
Induction principle to build a sequence, by adding one point at a time satisfying a given relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set s
, one can find another point satisfying
some relation r
with respect to all the points in s
. Then one may construct a
function f : ℕ → α
such that r (f m) (f n)
holds whenever m < n
.
We also ensure that all constructed points satisfy a given predicate P
.
Induction principle to build a sequence, by adding one point at a time satisfying a given symmetric relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set s
, one can find another point satisfying
some relation r
with respect to all the points in s
. Then one may construct a
function f : ℕ → α
such that r (f m) (f n)
holds whenever m ≠ n
.
We also ensure that all constructed points satisfy a given predicate P
.