Cardinalities of finite types #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Main declarations #
fintype.card α
: Cardinality of a fintype. Equal tofinset.univ.card
.fintype.trunc_equiv_fin
: A fintypeα
is computably equivalent tofin (card α)
. Thetrunc
-free, noncomputable version isfintype.equiv_fin
.fintype.trunc_equiv_of_card_eq
fintype.equiv_of_card_eq
: Two fintypes of same cardinality are equivalent. See above.fin.equiv_iff_eq
:fin m ≃ fin n
iffm = n
.infinite.nat_embedding
: An embedding ofℕ
into an infinite type.
We also provide the following versions of the pigeonholes principle.
fintype.exists_ne_map_eq_of_card_lt
andis_empty_of_card_lt
: Finitely many pigeons and pigeonholes. Weak formulation.finite.exists_ne_map_eq_of_infinite
: Infinitely many pigeons in finitely many pigeonholes. Weak formulation.finite.exists_infinite_fiber
: Infinitely many pigeons in finitely many pigeonholes. Strong formulation.
Some more pigeonhole-like statements can be found in data.fintype.card_embedding
.
Types which have an injection from/a surjection to an infinite
type are themselves infinite
.
See infinite.of_injective
and infinite.of_surjective
.
Instances #
We provide infinite
instances for
card α
is the number of elements in α
, defined when α
is a fintype.
Equations
There is (computably) an equivalence between α
and fin (card α)
.
Since it is not unique and depends on which permutation
of the universe list is used, the equivalence is wrapped in trunc
to
preserve computability.
See fintype.equiv_fin
for the noncomputable version,
and fintype.trunc_equiv_fin_of_card_eq
and fintype.equiv_fin_of_card_eq
for an equiv α ≃ fin n
given fintype.card α = n
.
See fintype.trunc_fin_bijection
for a version without [decidable_eq α]
.
Equations
- fintype.trunc_equiv_fin α = _.mpr (quot.rec_on_subsingleton finset.univ.val (λ (l : list α) (h : ∀ (x : α), x ∈ l) (nd : l.nodup), trunc.mk (list.nodup.nth_le_equiv_of_forall_mem_list l nd h).symm) finset.mem_univ_val _)
There is (noncomputably) an equivalence between α
and fin (card α)
.
See fintype.trunc_equiv_fin
for the computable version,
and fintype.trunc_equiv_fin_of_card_eq
and fintype.equiv_fin_of_card_eq
for an equiv α ≃ fin n
given fintype.card α = n
.
Equations
- fintype.equiv_fin α = let _inst : decidable_eq α := classical.dec_eq α in (fintype.trunc_equiv_fin α).out
There is (computably) a bijection between fin (card α)
and α
.
Since it is not unique and depends on which permutation
of the universe list is used, the bijection is wrapped in trunc
to
preserve computability.
See fintype.trunc_equiv_fin
for a version that gives an equivalence
given [decidable_eq α]
.
Equations
- fintype.trunc_fin_bijection α = id (quot.rec_on_subsingleton finset.univ.val (λ (l : list α) (h : ∀ (x : α), x ∈ l) (nd : l.nodup), trunc.mk (list.nodup.nth_le_bijection_of_forall_mem_list l nd h)) finset.mem_univ_val _)
If the cardinality of α
is n
, there is computably a bijection between α
and fin n
.
See fintype.equiv_fin_of_card_eq
for the noncomputable definition,
and fintype.trunc_equiv_fin
and fintype.equiv_fin
for the bijection α ≃ fin (card α)
.
Equations
- fintype.trunc_equiv_fin_of_card_eq h = trunc.map (λ (e : α ≃ fin (fintype.card α)), e.trans (fin.cast h).to_equiv) (fintype.trunc_equiv_fin α)
If the cardinality of α
is n
, there is noncomputably a bijection between α
and fin n
.
See fintype.trunc_equiv_fin_of_card_eq
for the computable definition,
and fintype.trunc_equiv_fin
and fintype.equiv_fin
for the bijection α ≃ fin (card α)
.
Equations
- fintype.equiv_fin_of_card_eq h = let _inst : decidable_eq α := classical.dec_eq α in (fintype.trunc_equiv_fin_of_card_eq h).out
Two fintype
s with the same cardinality are (computably) in bijection.
See fintype.equiv_of_card_eq
for the noncomputable version,
and fintype.trunc_equiv_fin_of_card_eq
and fintype.equiv_fin_of_card_eq
for
the specialization to fin
.
Equations
- fintype.trunc_equiv_of_card_eq h = (fintype.trunc_equiv_fin_of_card_eq h).bind (λ (e : α ≃ fin (fintype.card β)), trunc.map (λ (e' : β ≃ fin (fintype.card β)), e.trans e'.symm) (fintype.trunc_equiv_fin β))
Two fintype
s with the same cardinality are (noncomputably) in bijection.
See fintype.trunc_equiv_of_card_eq
for the computable version,
and fintype.trunc_equiv_fin_of_card_eq
and fintype.equiv_fin_of_card_eq
for
the specialization to fin
.
Equations
- fintype.equiv_of_card_eq h = let _inst : decidable_eq α := classical.dec_eq α, _inst_3 : decidable_eq β := classical.dec_eq β in (fintype.trunc_equiv_of_card_eq h).out
Note: this lemma is specifically about fintype.of_subsingleton
. For a statement about
arbitrary fintype
instances, use either fintype.card_le_one_iff_subsingleton
or
fintype.card_unique
.
Note: this lemma is specifically about fintype.of_is_empty
. For a statement about
arbitrary fintype
instances, use fintype.card_eq_zero_iff
.
fin
as a map from ℕ
to Type
is injective. Note that since this is a statement about
equality of types, using it should be avoided if possible.
Given that α ⊕ β
is a fintype, α
is also a fintype. This is non-computable as it uses
that sum.inl
is an injection, but there's no clear inverse if α
is empty.
Given that α ⊕ β
is a fintype, β
is also a fintype. This is non-computable as it uses
that sum.inr
is an injection, but there's no clear inverse if β
is empty.
Relation to finite
#
In this section we prove that α : Type*
is finite
if and only if fintype α
is nonempty.
See also nonempty_encodable
, nonempty_denumerable
.
The pigeonhole principle for finitely many pigeons and pigeonholes.
This is the fintype
version of finset.exists_ne_map_eq_of_card_lt_of_maps_to
.
Alias of the forward direction of finite.injective_iff_bijective
.
Alias of the forward direction of finite.surjective_iff_bijective
.
Alias of the forward direction of finite.injective_iff_surjective_of_equiv
.
Alias of the reverse direction of finite.injective_iff_surjective_of_equiv
.
Construct an equivalence from functions that are inverse to each other.
Construct an equivalence from functions that are inverse to each other.
If ‖β‖ < ‖α‖
there are no embeddings α ↪ β
.
This is a formulation of the pigeonhole principle.
Note this cannot be an instance as it needs h
.
A constructive embedding of a fintype α
in another fintype β
when card α ≤ card β
.
Equations
- function.embedding.trunc_of_card_le h = (fintype.trunc_equiv_fin α).bind (λ (ea : α ≃ fin (fintype.card α)), trunc.map (λ (eb : β ≃ fin (fintype.card β)), ea.to_embedding.trans ((fin.cast_le h).to_embedding.trans eb.symm.to_embedding)) (fintype.trunc_equiv_fin β))
If two subtypes of a fintype have equal cardinality, so do their complements.
A non-infinite type is a fintype.
Equations
Any type is (classically) either a fintype
, or infinite
.
One can obtain the relevant typeclasses via cases fintype_or_infinite α; resetI
.
Equations
- fintype_or_infinite α = dite (infinite α) (λ (h : infinite α), psum.inr h) (λ (h : ¬infinite α), psum.inl (fintype_of_not_infinite h))
The pigeonhole principle for infinitely many pigeons in finitely many pigeonholes. If there are infinitely many pigeons in finitely many pigeonholes, then there are at least two pigeons in the same pigeonhole.
See also: fintype.exists_ne_map_eq_of_card_lt
, finite.exists_infinite_fiber
.
The strong pigeonhole principle for infinitely many pigeons in finitely many pigeonholes. If there are infinitely many pigeons in finitely many pigeonholes, then there is a pigeonhole with infinitely many pigeons.
See also: finite.exists_ne_map_eq_of_infinite
A fintype
with positive cardinality constructively contains an element.
Equations
- trunc_of_card_pos h = let _inst : nonempty α := _ in trunc_of_nonempty_fintype α
A custom induction principle for fintypes. The base case is a subsingleton type,
and the induction step is for non-trivial types, and one can assume the hypothesis for
smaller types (via fintype.card
).
The major premise is fintype α
, so to use this with the induction
tactic you have to give a name
to that instance and use that name.