doc-next-gen

Mathlib.Data.Fintype.EquivFin

Module docstring

{"# Equivalences between Fintype, Fin and Finite

This file defines the bijection between a Fintype α and Fin (Fintype.card α), and uses this to relate Fintype with Finite. From that we can derive properties of Finite and Infinite, and show some instances of Infinite.

Main declarations

  • Fintype.truncEquivFin: A fintype α is computably equivalent to Fin (card α). The Trunc-free, noncomputable version is Fintype.equivFin.
  • Fintype.truncEquivOfCardEq Fintype.equivOfCardEq: Two fintypes of same cardinality are equivalent. See above.
  • Fin.equiv_iff_eq: Fin m ≃ Fin n iff m = n.
  • Infinite.natEmbedding: An embedding of into an infinite type.

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 * specific types: , , String * type constructors: Multiset α, List α

","### Relation to Finite

In this section we prove that α : Type* is Finite if and only if Fintype α is nonempty. "}

Fintype.truncEquivFin definition
(α) [DecidableEq α] [Fintype α] : Trunc (α ≃ Fin (card α))
Full source
/-- 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.equivFin` for the noncomputable version,
and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq`
for an equiv `α ≃ Fin n` given `Fintype.card α = n`.

See `Fintype.truncFinBijection` for a version without `[DecidableEq α]`.
-/
def truncEquivFin (α) [DecidableEq α] [Fintype α] : Trunc (α ≃ Fin (card α)) := by
  unfold card Finset.card
  exact
    Quot.recOnSubsingleton
      (motive := fun s : Multiset α =>
        (∀ x : α, x ∈ s) → s.NodupTrunc (α ≃ Fin (Multiset.card s)))
      univ.val
      (fun l (h : ∀ x : α, x ∈ l) (nd : l.Nodup) => Trunc.mk (nd.getEquivOfForallMemList _ h).symm)
      mem_univ_val univ.2
Computable equivalence between a finite type and $\text{Fin} (|\alpha|)$
Informal description
For any finite type $\alpha$ with decidable equality, there exists a computable equivalence (bijection with inverse) between $\alpha$ and the finite type $\text{Fin} (|\alpha|)$, where $|\alpha|$ denotes the cardinality of $\alpha$. This equivalence is wrapped in a truncation to preserve computability, as it depends on the specific enumeration of elements in $\alpha$.
Fintype.equivFin definition
(α) [Fintype α] : α ≃ Fin (card α)
Full source
/-- There is (noncomputably) an equivalence between `α` and `Fin (card α)`.

See `Fintype.truncEquivFin` for the computable version,
and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq`
for an equiv `α ≃ Fin n` given `Fintype.card α = n`.
-/
noncomputable def equivFin (α) [Fintype α] : α ≃ Fin (card α) :=
  letI := Classical.decEq α
  (truncEquivFin α).out
Bijection between a finite type and $\text{Fin}(|\alpha|)$
Informal description
For any finite type $\alpha$, there exists a bijection between $\alpha$ and the finite type $\text{Fin}(|\alpha|)$, where $|\alpha|$ denotes the cardinality of $\alpha$. This bijection is constructed noncomputably by selecting a representative from the truncation of the equivalence between $\alpha$ and $\text{Fin}(|\alpha|)$.
Fintype.truncFinBijection definition
(α) [Fintype α] : Trunc { f : Fin (card α) → α // Bijective f }
Full source
/-- 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.truncEquivFin` for a version that gives an equivalence
given `[DecidableEq α]`.
-/
def truncFinBijection (α) [Fintype α] : Trunc { f : Fin (card α) → α // Bijective f } := by
  unfold card Finset.card
  refine
    Quot.recOnSubsingleton
      (motive := fun s : Multiset α =>
        (∀ x : α, x ∈ s) → s.NodupTrunc {f : Fin (Multiset.card s) → α // Bijective f})
      univ.val
      (fun l (h : ∀ x : α, x ∈ l) (nd : l.Nodup) => Trunc.mk (nd.getBijectionOfForallMemList _ h))
      mem_univ_val univ.2
Bijection between $\text{Fin} (\text{card} \alpha)$ and $\alpha$ for finite types
Informal description
For any finite type $\alpha$, there exists a bijection between the finite type $\text{Fin} (\text{card} \alpha)$ and $\alpha$, where $\text{card} \alpha$ denotes the cardinality of $\alpha$. The bijection is not unique and depends on the specific enumeration of elements in $\alpha$, so it is wrapped in a truncation to preserve computability.
Fintype.truncEquivFinOfCardEq definition
[DecidableEq α] {n : ℕ} (h : Fintype.card α = n) : Trunc (α ≃ Fin n)
Full source
/-- If the cardinality of `α` is `n`, there is computably a bijection between `α` and `Fin n`.

See `Fintype.equivFinOfCardEq` for the noncomputable definition,
and `Fintype.truncEquivFin` and `Fintype.equivFin` for the bijection `α ≃ Fin (card α)`.
-/
def truncEquivFinOfCardEq [DecidableEq α] {n : } (h : Fintype.card α = n) : Trunc (α ≃ Fin n) :=
  (truncEquivFin α).map fun e => e.trans (finCongr h)
Computable bijection between a finite type and $\mathrm{Fin}(n)$ given equal cardinality
Informal description
Given a finite type $\alpha$ with decidable equality and a natural number $n$ such that the cardinality of $\alpha$ is $n$, there exists a computable bijection between $\alpha$ and the finite type $\mathrm{Fin}(n)$. This bijection is constructed by composing the equivalence between $\alpha$ and $\mathrm{Fin}(|\alpha|)$ with the equivalence $\mathrm{finCongr}(h)$ induced by the equality $h : |\alpha| = n$.
Fintype.equivFinOfCardEq definition
{n : ℕ} (h : Fintype.card α = n) : α ≃ Fin n
Full source
/-- If the cardinality of `α` is `n`, there is noncomputably a bijection between `α` and `Fin n`.

See `Fintype.truncEquivFinOfCardEq` for the computable definition,
and `Fintype.truncEquivFin` and `Fintype.equivFin` for the bijection `α ≃ Fin (card α)`.
-/
noncomputable def equivFinOfCardEq {n : } (h : Fintype.card α = n) : α ≃ Fin n :=
  letI := Classical.decEq α
  (truncEquivFinOfCardEq h).out
Bijection between a finite type and $\mathrm{Fin}(n)$ given equal cardinality
Informal description
Given a finite type $\alpha$ with cardinality $n$, there exists a noncomputable bijection between $\alpha$ and the finite type $\mathrm{Fin}(n)$. This bijection is constructed by selecting a representative from the truncation of the equivalence between $\alpha$ and $\mathrm{Fin}(n)$ using the axiom of choice.
Fintype.truncEquivOfCardEq definition
[DecidableEq α] [DecidableEq β] (h : card α = card β) : Trunc (α ≃ β)
Full source
/-- Two `Fintype`s with the same cardinality are (computably) in bijection.

See `Fintype.equivOfCardEq` for the noncomputable version,
and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq` for
the specialization to `Fin`.
-/
def truncEquivOfCardEq [DecidableEq α] [DecidableEq β] (h : card α = card β) : Trunc (α ≃ β) :=
  (truncEquivFinOfCardEq h).bind fun e => (truncEquivFin β).map fun e' => e.trans e'.symm
Computable bijection between finite types of equal cardinality
Informal description
Given two finite types $\alpha$ and $\beta$ with decidable equality and the same cardinality, there exists a computable bijection (equivalence) between them. This is constructed by first obtaining a bijection from $\alpha$ to $\mathrm{Fin}(n)$ (where $n$ is their common cardinality) and then composing it with the inverse of a bijection from $\beta$ to $\mathrm{Fin}(n)$. The result is wrapped in a truncation to preserve computability.
Fintype.equivOfCardEq definition
(h : card α = card β) : α ≃ β
Full source
/-- Two `Fintype`s with the same cardinality are (noncomputably) in bijection.

See `Fintype.truncEquivOfCardEq` for the computable version,
and `Fintype.truncEquivFinOfCardEq` and `Fintype.equivFinOfCardEq` for
the specialization to `Fin`.
-/
noncomputable def equivOfCardEq (h : card α = card β) : α ≃ β := by
  letI := Classical.decEq α
  letI := Classical.decEq β
  exact (truncEquivOfCardEq h).out
Bijection between finite types of equal cardinality
Informal description
Given two finite types $\alpha$ and $\beta$ with the same cardinality, there exists a noncomputable bijection (equivalence) between them. This is constructed by first obtaining a computable bijection (wrapped in a truncation) using `Fintype.truncEquivOfCardEq` and then selecting a representative from the truncation using the axiom of choice.
Fintype.card_eq theorem
{α β} [_F : Fintype α] [_G : Fintype β] : card α = card β ↔ Nonempty (α ≃ β)
Full source
theorem card_eq {α β} [_F : Fintype α] [_G : Fintype β] : cardcard α = card β ↔ Nonempty (α ≃ β) :=
  ⟨fun h =>
    haveI := Classical.propDecidable
    (truncEquivOfCardEq h).nonempty,
    fun ⟨f⟩ => card_congr f⟩
Cardinality Equality Implies Bijection for Finite Types
Informal description
For any two finite types $\alpha$ and $\beta$ with given `Fintype` instances, the cardinalities of $\alpha$ and $\beta$ are equal if and only if there exists a bijection between $\alpha$ and $\beta$.
Fintype.finite theorem
{α : Type*} (_inst : Fintype α) : Finite α
Full source
protected theorem Fintype.finite {α : Type*} (_inst : Fintype α) : Finite α :=
  ⟨Fintype.equivFin α⟩
Finiteness from Fintype Instance
Informal description
For any type $\alpha$, if $\alpha$ has a `Fintype` instance (i.e., it is a finite type with computable enumeration), then $\alpha$ is finite (i.e., it satisfies the `Finite` property).
Finite.of_fintype instance
(α : Type*) [Fintype α] : Finite α
Full source
/-- For efficiency reasons, we want `Finite` instances to have higher
priority than ones coming from `Fintype` instances. -/
instance (priority := 900) Finite.of_fintype (α : Type*) [Fintype α] : Finite α :=
  Fintype.finite ‹_›
Finiteness from Fintype Instance
Informal description
For any type $\alpha$ with a `Fintype` instance, $\alpha$ is finite.
Fintype.ofFinite definition
(α : Type*) [Finite α] : Fintype α
Full source
/-- Noncomputably get a `Fintype` instance from a `Finite` instance. This is not an
instance because we want `Fintype` instances to be useful for computations. -/
noncomputable def Fintype.ofFinite (α : Type*) [Finite α] : Fintype α :=
  (nonempty_fintype α).some
Noncomputable construction of finite type structure from finiteness
Informal description
Given a finite type $\alpha$, the function `Fintype.ofFinite` noncomputably constructs a `Fintype` instance for $\alpha$, providing a finite enumeration of its elements. This is derived from the existence of such an instance (guaranteed by `nonempty_fintype`) using the axiom of choice.
Finite.of_injective theorem
{α β : Sort*} [Finite β] (f : α → β) (H : Injective f) : Finite α
Full source
theorem Finite.of_injective {α β : Sort*} [Finite β] (f : α → β) (H : Injective f) : Finite α := by
  rcases Finite.exists_equiv_fin β with ⟨n, ⟨e⟩⟩
  classical exact .of_equiv (Set.range (e ∘ f)) (Equiv.ofInjective _ (e.injective.comp H)).symm
Finiteness via injective maps
Informal description
Let $\alpha$ and $\beta$ be types, with $\beta$ finite. If there exists an injective function $f \colon \alpha \to \beta$, then $\alpha$ is also finite.
prop instance
(p : Prop) : Finite p
Full source
instance prop (p : Prop) : Finite p :=
  Finite.of_subsingleton
Finiteness of Propositions
Informal description
Every proposition $p$ is finite.
Subtype.finite instance
{α : Sort*} [Finite α] {p : α → Prop} : Finite { x // p x }
Full source
/-- This instance also provides `[Finite s]` for `s : Set α`. -/
instance Subtype.finite {α : Sort*} [Finite α] {p : α → Prop} : Finite { x // p x } :=
  Finite.of_injective Subtype.val Subtype.coe_injective
Finiteness of Subtypes of Finite Types
Informal description
For any finite type $\alpha$ and any predicate $p$ on $\alpha$, the subtype $\{x \in \alpha \mid p(x)\}$ is also finite.
Finite.of_surjective theorem
{α β : Sort*} [Finite α] (f : α → β) (H : Surjective f) : Finite β
Full source
theorem Finite.of_surjective {α β : Sort*} [Finite α] (f : α → β) (H : Surjective f) : Finite β :=
  Finite.of_injective _ <| injective_surjInv H
Finiteness via Surjective Maps
Informal description
Let $\alpha$ and $\beta$ be types, with $\alpha$ finite. If there exists a surjective function $f \colon \alpha \to \beta$, then $\beta$ is also finite.
Quot.finite instance
{α : Sort*} [Finite α] (r : α → α → Prop) : Finite (Quot r)
Full source
instance Quot.finite {α : Sort*} [Finite α] (r : α → α → Prop) : Finite (Quot r) :=
  Finite.of_surjective _ Quot.mk_surjective
Finiteness of Quotient Types
Informal description
For any finite type $\alpha$ and any binary relation $r$ on $\alpha$, the quotient type $\operatorname{Quot} r$ is also finite.
Quotient.finite instance
{α : Sort*} [Finite α] (s : Setoid α) : Finite (Quotient s)
Full source
instance Quotient.finite {α : Sort*} [Finite α] (s : Setoid α) : Finite (Quotient s) :=
  Quot.finite _
Finiteness of Quotient Types by Setoids
Informal description
For any finite type $\alpha$ and any setoid $s$ on $\alpha$, the quotient type $\alpha / s$ is also finite.
Fintype.card_eq_one_iff theorem
: card α = 1 ↔ ∃ x : α, ∀ y, y = x
Full source
theorem card_eq_one_iff : cardcard α = 1 ↔ ∃ x : α, ∀ y, y = x := by
  rw [← card_unit, card_eq]
  exact
    ⟨fun ⟨a⟩ => ⟨a.symm (), fun y => a.injective (Subsingleton.elim _ _)⟩,
     fun ⟨x, hx⟩ =>
      ⟨⟨fun _ => (), fun _ => x, fun _ => (hx _).trans (hx _).symm, fun _ =>
          Subsingleton.elim _ _⟩⟩⟩
Finite Type Has Cardinality One if and only if it is a Singleton
Informal description
For a finite type $\alpha$, the cardinality of $\alpha$ is equal to 1 if and only if there exists an element $x \in \alpha$ such that every element $y \in \alpha$ is equal to $x$.
Fintype.card_eq_one_iff_nonempty_unique theorem
: card α = 1 ↔ Nonempty (Unique α)
Full source
theorem card_eq_one_iff_nonempty_unique : cardcard α = 1 ↔ Nonempty (Unique α) :=
  ⟨fun h =>
    let ⟨d, h⟩ := Fintype.card_eq_one_iff.mp h
    ⟨{  default := d
        uniq := h }⟩,
    fun ⟨_h⟩ => Fintype.card_unique⟩
Cardinality One iff Unique Element Exists in Finite Type
Informal description
For a finite type $\alpha$, the cardinality of $\alpha$ is equal to 1 if and only if there exists a unique element in $\alpha$ (i.e., $\alpha$ is a singleton type).
Fintype.instNeZeroNatCardOfNonempty_1 instance
[Nonempty α] : NeZero (card α)
Full source
instance [Nonempty α] : NeZero (card α) := ⟨card_ne_zero⟩
Nonempty Finite Types Have Nonzero Cardinality
Informal description
For any nonempty finite type $\alpha$, the cardinality of $\alpha$ is a nonzero natural number.
Fintype.card_le_one_iff theorem
: card α ≤ 1 ↔ ∀ a b : α, a = b
Full source
theorem card_le_one_iff : cardcard α ≤ 1 ↔ ∀ a b : α, a = b :=
  let n := card α
  have hn : n = card α := rfl
  match n, hn with
  | 0, ha =>
    ⟨fun _h => fun a => (card_eq_zero_iff.1 ha.symm).elim a, fun _ => ha ▸ Nat.le_succ _⟩
  | 1, ha =>
    ⟨fun _h => fun a b => by
      let ⟨x, hx⟩ := card_eq_one_iff.1 ha.symm
      rw [hx a, hx b], fun _ => ha ▸ le_rfl⟩
  | n + 2, ha =>
    ⟨fun h => False.elim <| by rw [← ha] at h; cases h with | step h => cases h; , fun h =>
      card_unit ▸ card_le_of_injective (fun _ => ()) fun _ _ _ => h _ _⟩
Finite Type Has Cardinality At Most One if and only if it is a Subsingleton
Informal description
For a finite type $\alpha$, the cardinality of $\alpha$ is at most 1 if and only if any two elements $a$ and $b$ in $\alpha$ are equal, i.e., $\alpha$ has at most one element.
Fintype.one_lt_card_iff_nontrivial theorem
: 1 < card α ↔ Nontrivial α
Full source
theorem one_lt_card_iff_nontrivial : 1 < card α ↔ Nontrivial α := by
  rw [← not_iff_not, not_lt, not_nontrivial_iff_subsingleton, card_le_one_iff_subsingleton]
Cardinality Greater Than One Characterizes Nontrivial Finite Types
Informal description
For a finite type $\alpha$, the cardinality of $\alpha$ is greater than 1 if and only if $\alpha$ is nontrivial (i.e., contains at least two distinct elements).
Fintype.exists_ne_of_one_lt_card theorem
(h : 1 < card α) (a : α) : ∃ b : α, b ≠ a
Full source
theorem exists_ne_of_one_lt_card (h : 1 < card α) (a : α) : ∃ b : α, b ≠ a :=
  haveI : Nontrivial α := one_lt_card_iff_nontrivial.1 h
  exists_ne a
Existence of Distinct Element in Finite Types with Cardinality Greater Than One
Informal description
For any finite type $\alpha$ with cardinality greater than 1 and any element $a \in \alpha$, there exists an element $b \in \alpha$ such that $b \neq a$.
Fintype.card_eq_one_of_forall_eq theorem
{i : α} (h : ∀ j, j = i) : card α = 1
Full source
theorem card_eq_one_of_forall_eq {i : α} (h : ∀ j, j = i) : card α = 1 :=
  Fintype.card_eq_one_iff.2 ⟨i, h⟩
Cardinality One for Singleton Finite Type
Informal description
For a finite type $\alpha$, if there exists an element $i \in \alpha$ such that every element $j \in \alpha$ is equal to $i$, then the cardinality of $\alpha$ is $1$.
Fintype.one_lt_card theorem
[h : Nontrivial α] : 1 < Fintype.card α
Full source
theorem one_lt_card [h : Nontrivial α] : 1 < Fintype.card α :=
  Fintype.one_lt_card_iff_nontrivial.mpr h
Cardinality Greater Than One for Nontrivial Finite Types
Informal description
For any nontrivial finite type $\alpha$, the cardinality of $\alpha$ is greater than 1, i.e., $1 < \text{card}(\alpha)$.
Fintype.bijective_iff_injective_and_card theorem
(f : α → β) : Bijective f ↔ Injective f ∧ card α = card β
Full source
theorem bijective_iff_injective_and_card (f : α → β) :
    BijectiveBijective f ↔ Injective f ∧ card α = card β :=
  ⟨fun h => ⟨h.1, card_of_bijective h⟩, fun h =>
    ⟨h.1, h.1.surjective_of_fintype <| equivOfCardEq h.2⟩⟩
Bijectivity Criterion for Finite Types: Injectivity and Equal Cardinality
Informal description
For a function $f : \alpha \to \beta$ between finite types $\alpha$ and $\beta$, $f$ is bijective if and only if it is injective and the cardinalities of $\alpha$ and $\beta$ are equal.
Fintype.bijective_iff_surjective_and_card theorem
(f : α → β) : Bijective f ↔ Surjective f ∧ card α = card β
Full source
theorem bijective_iff_surjective_and_card (f : α → β) :
    BijectiveBijective f ↔ Surjective f ∧ card α = card β :=
  ⟨fun h => ⟨h.2, card_of_bijective h⟩, fun h =>
    ⟨h.1.injective_of_fintype <| equivOfCardEq h.2, h.1⟩⟩
Bijectivity Criterion for Finite Types: Surjectivity and Equal Cardinality
Informal description
For any function $f : \alpha \to \beta$ between finite types $\alpha$ and $\beta$, $f$ is bijective if and only if $f$ is surjective and the cardinalities of $\alpha$ and $\beta$ are equal.
Function.LeftInverse.rightInverse_of_card_le theorem
{f : α → β} {g : β → α} (hfg : LeftInverse f g) (hcard : card α ≤ card β) : RightInverse f g
Full source
theorem _root_.Function.LeftInverse.rightInverse_of_card_le {f : α → β} {g : β → α}
    (hfg : LeftInverse f g) (hcard : card α ≤ card β) : RightInverse f g :=
  have hsurj : Surjective f := surjective_iff_hasRightInverse.2 ⟨g, hfg⟩
  rightInverse_of_injective_of_leftInverse
    ((bijective_iff_surjective_and_card _).2
        ⟨hsurj, le_antisymm hcard (card_le_of_surjective f hsurj)⟩).1
    hfg
Left Inverse Becomes Right Inverse When Domain Cardinality is Bounded by Codomain
Informal description
Let $f : \alpha \to \beta$ and $g : \beta \to \alpha$ be functions between finite types $\alpha$ and $\beta$. If $g$ is a left inverse of $f$ (i.e., $g \circ f = \text{id}_\alpha$) and the cardinality of $\alpha$ is less than or equal to that of $\beta$, then $f$ is also a right inverse of $g$ (i.e., $f \circ g = \text{id}_\beta$).
Function.RightInverse.leftInverse_of_card_le theorem
{f : α → β} {g : β → α} (hfg : RightInverse f g) (hcard : card β ≤ card α) : LeftInverse f g
Full source
theorem _root_.Function.RightInverse.leftInverse_of_card_le {f : α → β} {g : β → α}
    (hfg : RightInverse f g) (hcard : card β ≤ card α) : LeftInverse f g :=
  Function.LeftInverse.rightInverse_of_card_le hfg hcard
Right Inverse Becomes Left Inverse When Codomain Cardinality is Bounded by Domain
Informal description
Let $f : \alpha \to \beta$ and $g : \beta \to \alpha$ be functions between finite types $\alpha$ and $\beta$. If $g$ is a right inverse of $f$ (i.e., $f \circ g = \text{id}_\beta$) and the cardinality of $\beta$ is less than or equal to that of $\alpha$, then $f$ is also a left inverse of $g$ (i.e., $g \circ f = \text{id}_\alpha$).
Equiv.ofLeftInverseOfCardLE definition
(hβα : card β ≤ card α) (f : α → β) (g : β → α) (h : LeftInverse g f) : α ≃ β
Full source
/-- Construct an equivalence from functions that are inverse to each other. -/
@[simps]
def ofLeftInverseOfCardLE (hβα : card β ≤ card α) (f : α → β) (g : β → α) (h : LeftInverse g f) :
    α ≃ β where
  toFun := f
  invFun := g
  left_inv := h
  right_inv := h.rightInverse_of_card_le hβα
Equivalence from left inverse with cardinality condition
Informal description
Given two finite types $\alpha$ and $\beta$ with $\text{card}(\beta) \leq \text{card}(\alpha)$, and functions $f : \alpha \to \beta$ and $g : \beta \to \alpha$ such that $g$ is a left inverse of $f$ (i.e., $g \circ f = \text{id}_\alpha$), then there exists an equivalence (bijection) between $\alpha$ and $\beta$ where $f$ is the forward map and $g$ is its inverse. The right inverse property is automatically satisfied due to the cardinality condition.
Equiv.ofRightInverseOfCardLE definition
(hαβ : card α ≤ card β) (f : α → β) (g : β → α) (h : RightInverse g f) : α ≃ β
Full source
/-- Construct an equivalence from functions that are inverse to each other. -/
@[simps]
def ofRightInverseOfCardLE (hαβ : card α ≤ card β) (f : α → β) (g : β → α) (h : RightInverse g f) :
    α ≃ β where
  toFun := f
  invFun := g
  left_inv := h.leftInverse_of_card_le hαβ
  right_inv := h
Equivalence from right inverse with cardinality condition
Informal description
Given two finite types $\alpha$ and $\beta$ with $\text{card}(\alpha) \leq \text{card}(\beta)$, and functions $f : \alpha \to \beta$ and $g : \beta \to \alpha$ such that $g$ is a right inverse of $f$ (i.e., $f \circ g = \text{id}_\beta$), then there exists an equivalence (bijection) between $\alpha$ and $\beta$ where $f$ is the forward map and $g$ is its inverse. The left inverse property is automatically satisfied due to the cardinality condition.
Finset.equivFin definition
(s : Finset α) : s ≃ Fin #s
Full source
/-- Noncomputable equivalence between a finset `s` coerced to a type and `Fin #s`. -/
noncomputable def Finset.equivFin (s : Finset α) : s ≃ Fin #s :=
  Fintype.equivFinOfCardEq (Fintype.card_coe _)
Bijection between a finset and $\mathrm{Fin}(n)$
Informal description
For any finset $s$ of elements of type $\alpha$, there is a noncomputable bijection between the subtype $\{x \mid x \in s\}$ and the finite type $\mathrm{Fin}(n)$, where $n$ is the cardinality of $s$.
Finset.equivFinOfCardEq definition
{s : Finset α} {n : ℕ} (h : #s = n) : s ≃ Fin n
Full source
/-- Noncomputable equivalence between a finset `s` as a fintype and `Fin n`, when there is a
proof that `#s = n`. -/
noncomputable def Finset.equivFinOfCardEq {s : Finset α} {n : } (h : #s = n) : s ≃ Fin n :=
  Fintype.equivFinOfCardEq ((Fintype.card_coe _).trans h)
Bijection between a finset and $\mathrm{Fin}(n)$ given equal cardinality
Informal description
Given a finset $s$ of elements of type $\alpha$ and a natural number $n$ such that the cardinality of $s$ is equal to $n$, there exists a noncomputable bijection between $s$ and the finite type $\mathrm{Fin}(n)$. This bijection is constructed by first establishing that the subtype $\{x \mid x \in s\}$ has cardinality $n$ and then using the axiom of choice to select a representative from the truncation of the equivalence between this subtype and $\mathrm{Fin}(n)$.
Finset.card_eq_of_equiv_fin theorem
{s : Finset α} {n : ℕ} (i : s ≃ Fin n) : #s = n
Full source
theorem Finset.card_eq_of_equiv_fin {s : Finset α} {n : } (i : s ≃ Fin n) : #s = n :=
  Fin.equiv_iff_eq.1 ⟨s.equivFin.symm.trans i⟩
Cardinality of Finset via Equivalence to $\mathrm{Fin}(n)$
Informal description
For any finset $s$ of elements of type $\alpha$ and a natural number $n$, if there exists a bijection $i : s \simeq \mathrm{Fin}(n)$, then the cardinality of $s$ is equal to $n$, i.e., $|s| = n$.
Finset.card_eq_of_equiv_fintype theorem
{s : Finset α} [Fintype β] (i : s ≃ β) : #s = Fintype.card β
Full source
theorem Finset.card_eq_of_equiv_fintype {s : Finset α} [Fintype β] (i : s ≃ β) :
    #s = Fintype.card β := card_eq_of_equiv_fin <| i.trans <| Fintype.equivFin β
Cardinality of Finset via Equivalence to Finite Type
Informal description
For any finset $s$ of elements of type $\alpha$ and any finite type $\beta$, if there exists a bijection $i : s \simeq \beta$, then the cardinality of $s$ is equal to the cardinality of $\beta$, i.e., $|s| = |\beta|$.
Finset.equivOfCardEq definition
{s : Finset α} {t : Finset β} (h : #s = #t) : s ≃ t
Full source
/-- Noncomputable equivalence between two finsets `s` and `t` as fintypes when there is a proof
that `#s = #t`. -/
noncomputable def Finset.equivOfCardEq {s : Finset α} {t : Finset β} (h : #s = #t) :
    s ≃ t := Fintype.equivOfCardEq ((Fintype.card_coe _).trans (h.trans (Fintype.card_coe _).symm))
Bijection between finite sets of equal cardinality
Informal description
Given two finite sets $s$ and $t$ with the same cardinality, there exists a noncomputable bijection between them. This is constructed by first showing that their corresponding fintypes (subtypes of elements belonging to $s$ and $t$ respectively) have the same cardinality, and then using the general bijection between finite types of equal cardinality.
Finset.card_eq_of_equiv theorem
{s : Finset α} {t : Finset β} (i : s ≃ t) : #s = #t
Full source
theorem Finset.card_eq_of_equiv {s : Finset α} {t : Finset β} (i : s ≃ t) : #s = #t :=
  (card_eq_of_equiv_fintype i).trans (Fintype.card_coe _)
Cardinality Equality via Bijection between Finite Sets
Informal description
For any two finite sets $s$ (of elements of type $\alpha$) and $t$ (of elements of type $\beta$), if there exists a bijection $i : s \simeq t$, then the cardinalities of $s$ and $t$ are equal, i.e., $|s| = |t|$.
Function.Embedding.equivOfFiniteSelfEmbedding definition
[Finite α] (e : α ↪ α) : α ≃ α
Full source
/-- An embedding from a `Fintype` to itself can be promoted to an equivalence. -/
noncomputable def equivOfFiniteSelfEmbedding [Finite α] (e : α ↪ α) : α ≃ α :=
  Equiv.ofBijective e e.2.bijective_of_finite
Bijection from finite self-embedding
Informal description
Given a finite type $\alpha$ and an injective function embedding $e : \alpha \hookrightarrow \alpha$, the function $e$ is bijective and thus induces an equivalence (bijection) $\alpha \simeq \alpha$.
Function.Embedding.toEmbedding_equivOfFiniteSelfEmbedding theorem
[Finite α] (e : α ↪ α) : e.equivOfFiniteSelfEmbedding.toEmbedding = e
Full source
@[simp]
theorem toEmbedding_equivOfFiniteSelfEmbedding [Finite α] (e : α ↪ α) :
    e.equivOfFiniteSelfEmbedding.toEmbedding = e := by
  ext
  rfl
Embedding Equality from Finite Self-Bijection
Informal description
For any finite type $\alpha$ and any injective function embedding $e : \alpha \hookrightarrow \alpha$, the embedding obtained from the bijection induced by $e$ is equal to $e$ itself. In other words, if we convert the bijection $\alpha \simeq \alpha$ (which exists because $\alpha$ is finite and $e$ is injective) back to an embedding, we recover the original embedding $e$.
Equiv.embeddingEquivOfFinite definition
(α : Type*) [Finite α] : (α ↪ α) ≃ (α ≃ α)
Full source
/-- On a finite type, equivalence between the self-embeddings and the bijections. -/
@[simps] noncomputable def _root_.Equiv.embeddingEquivOfFinite (α : Type*) [Finite α] :
    (α ↪ α) ≃ (α ≃ α) where
  toFun e := e.equivOfFiniteSelfEmbedding
  invFun e := e.toEmbedding
  left_inv e := rfl
  right_inv e := by ext; rfl
Equivalence between self-embeddings and self-bijections of a finite type
Informal description
For a finite type $\alpha$, there is a natural equivalence (bijection) between the type of self-embeddings $\alpha \hookrightarrow \alpha$ and the type of self-equivalences (bijections) $\alpha \simeq \alpha$. This equivalence is constructed by: - Mapping an embedding $e : \alpha \hookrightarrow \alpha$ to its induced bijection $e.\text{equivOfFiniteSelfEmbedding} : \alpha \simeq \alpha$ - Mapping a bijection $f : \alpha \simeq \alpha$ to its underlying embedding $f.\text{toEmbedding} : \alpha \hookrightarrow \alpha$ These operations are inverse to each other, establishing the claimed equivalence.
Function.Embedding.truncOfCardLE definition
[Fintype α] [Fintype β] [DecidableEq α] [DecidableEq β] (h : Fintype.card α ≤ Fintype.card β) : Trunc (α ↪ β)
Full source
/-- A constructive embedding of a fintype `α` in another fintype `β` when `card α ≤ card β`. -/
def truncOfCardLE [Fintype α] [Fintype β] [DecidableEq α] [DecidableEq β]
    (h : Fintype.card α ≤ Fintype.card β) : Trunc (α ↪ β) :=
  (Fintype.truncEquivFin α).bind fun ea =>
    (Fintype.truncEquivFin β).map fun eb =>
      ea.toEmbedding.trans ((Fin.castLEEmb h).trans eb.symm.toEmbedding)
Constructive embedding between finite types of bounded cardinality
Informal description
Given two finite types $\alpha$ and $\beta$ with decidable equality, and a proof that the cardinality of $\alpha$ is less than or equal to that of $\beta$, there exists a constructive embedding of $\alpha$ into $\beta$. This embedding is constructed by first obtaining equivalences between $\alpha$ and $\mathrm{Fin}(|\alpha|)$, and between $\beta$ and $\mathrm{Fin}(|\beta|)$, then using the embedding $\mathrm{Fin}(|\alpha|) \hookrightarrow \mathrm{Fin}(|\beta|)$ induced by the cardinality inequality, and finally composing these maps to obtain the desired embedding $\alpha \hookrightarrow \beta$. The result is wrapped in a truncation to preserve computability.
Function.Embedding.nonempty_of_card_le theorem
[Fintype α] [Fintype β] (h : Fintype.card α ≤ Fintype.card β) : Nonempty (α ↪ β)
Full source
theorem nonempty_of_card_le [Fintype α] [Fintype β] (h : Fintype.card α ≤ Fintype.card β) :
    Nonempty (α ↪ β) := by classical exact (truncOfCardLE h).nonempty
Existence of Embedding for Finite Types with Cardinality Bound
Informal description
For any two finite types $\alpha$ and $\beta$, if the cardinality of $\alpha$ is less than or equal to that of $\beta$, then there exists an injective function from $\alpha$ to $\beta$.
Function.Embedding.nonempty_iff_card_le theorem
[Fintype α] [Fintype β] : Nonempty (α ↪ β) ↔ Fintype.card α ≤ Fintype.card β
Full source
theorem nonempty_iff_card_le [Fintype α] [Fintype β] :
    NonemptyNonempty (α ↪ β) ↔ Fintype.card α ≤ Fintype.card β :=
  ⟨fun ⟨e⟩ => Fintype.card_le_of_embedding e, nonempty_of_card_le⟩
Existence of Embedding Between Finite Types is Equivalent to Cardinality Inequality
Informal description
For any two finite types $\alpha$ and $\beta$, there exists an injective function from $\alpha$ to $\beta$ if and only if the cardinality of $\alpha$ is less than or equal to the cardinality of $\beta$.
Function.Embedding.exists_of_card_le_finset theorem
[Fintype α] {s : Finset β} (h : Fintype.card α ≤ #s) : ∃ f : α ↪ β, Set.range f ⊆ s
Full source
theorem exists_of_card_le_finset [Fintype α] {s : Finset β} (h : Fintype.card α ≤ #s) :
    ∃ f : α ↪ β, Set.range f ⊆ s := by
  rw [← Fintype.card_coe] at h
  rcases nonempty_of_card_le h with ⟨f⟩
  exact ⟨f.trans (Embedding.subtype _), by simp [Set.range_subset_iff]⟩
Existence of Embedding from Finite Type to Finset with Cardinality Bound
Informal description
For any finite type $\alpha$ and any finset $s$ of elements of type $\beta$, if the cardinality of $\alpha$ is less than or equal to the size of $s$, then there exists an injective function $f : \alpha \hookrightarrow \beta$ such that the range of $f$ is contained in $s$.
Finset.univ_map_embedding theorem
{α : Type*} [Fintype α] (e : α ↪ α) : univ.map e = univ
Full source
@[simp]
theorem Finset.univ_map_embedding {α : Type*} [Fintype α] (e : α ↪ α) : univ.map e = univ := by
  rw [← e.toEmbedding_equivOfFiniteSelfEmbedding, univ_map_equiv_to_embedding]
Universal Set Preservation under Self-Embedding for Finite Types
Informal description
For any finite type $\alpha$ and any injective function embedding $e : \alpha \hookrightarrow \alpha$, the image of the universal finite set under $e$ is equal to the universal finite set itself, i.e., $e[\text{univ}] = \text{univ}$.
Fintype.card_lt_of_surjective_not_injective theorem
[Fintype α] [Fintype β] (f : α → β) (h : Function.Surjective f) (h' : ¬Function.Injective f) : card β < card α
Full source
theorem card_lt_of_surjective_not_injective [Fintype α] [Fintype β] (f : α → β)
    (h : Function.Surjective f) (h' : ¬Function.Injective f) : card β < card α :=
  card_lt_of_injective_not_surjective _ (Function.injective_surjInv h) fun hg =>
    have w : Function.Bijective (Function.surjInv h) := ⟨Function.injective_surjInv h, hg⟩
    h' <| h.injective_of_fintype (Equiv.ofBijective _ w).symm
Cardinality Inequality for Non-Injective Surjection between Finite Types
Informal description
Let $\alpha$ and $\beta$ be finite types. If there exists a surjective function $f : \alpha \to \beta$ that is not injective, then the cardinality of $\beta$ is strictly less than the cardinality of $\alpha$, i.e., $|\beta| < |\alpha|$.
Fintype.false theorem
[Infinite α] (_h : Fintype α) : False
Full source
protected theorem Fintype.false [Infinite α] (_h : Fintype α) : False :=
  not_finite α
Infinite Types Cannot Have Finite Structures
Informal description
For any infinite type $\alpha$, the existence of a finite structure on $\alpha$ (i.e., a `Fintype α` instance) leads to a contradiction.
isEmpty_fintype theorem
{α : Type*} : IsEmpty (Fintype α) ↔ Infinite α
Full source
@[simp]
theorem isEmpty_fintype {α : Type*} : IsEmptyIsEmpty (Fintype α) ↔ Infinite α :=
  ⟨fun ⟨h⟩ => ⟨fun h' => (@nonempty_fintype α h').elim h⟩, fun ⟨h⟩ => ⟨fun h' => h h'.finite⟩⟩
Empty Finite Structures iff Infinite Type
Informal description
For any type $\alpha$, the type of finite structures on $\alpha$ (i.e., `Fintype α`) is empty if and only if $\alpha$ is infinite. In other words, $\alpha$ has no finite structure precisely when it is infinite.
fintypeOfNotInfinite definition
{α : Type*} (h : ¬Infinite α) : Fintype α
Full source
/-- A non-infinite type is a fintype. -/
noncomputable def fintypeOfNotInfinite {α : Type*} (h : ¬Infinite α) : Fintype α :=
  @Fintype.ofFinite _ (not_infinite_iff_finite.mp h)
Finite type structure from non-infinite type
Informal description
Given a type $\alpha$ that is not infinite, the function `fintypeOfNotInfinite` constructs a `Fintype` instance for $\alpha$, providing a finite enumeration of its elements.
fintypeOrInfinite definition
(α : Type*) : Fintype α ⊕' Infinite α
Full source
/-- Any type is (classically) either a `Fintype`, or `Infinite`.

One can obtain the relevant typeclasses via `cases fintypeOrInfinite α`.
-/
noncomputable def fintypeOrInfinite (α : Type*) : FintypeFintype α ⊕' Infinite α :=
  if h : Infinite α then PSum.inr h else PSum.inl (fintypeOfNotInfinite h)
Finite or Infinite Type
Informal description
For any type $\alpha$, it is either finite (i.e., has a `Fintype` instance) or infinite (i.e., has an `Infinite` instance). This is a classical result that provides a way to obtain the relevant typeclasses by case analysis on `fintypeOrInfinite α`.
Finset.exists_minimal theorem
{α : Type*} [Preorder α] (s : Finset α) (h : s.Nonempty) : ∃ m ∈ s, ∀ x ∈ s, ¬x < m
Full source
theorem Finset.exists_minimal {α : Type*} [Preorder α] (s : Finset α) (h : s.Nonempty) :
    ∃ m ∈ s, ∀ x ∈ s, ¬x < m := by
  obtain ⟨c, hcs : c ∈ s⟩ := h
  have : WellFounded (@LT.lt { x // x ∈ s } _) := Finite.wellFounded_of_trans_of_irrefl _
  obtain ⟨⟨m, hms : m ∈ s⟩, -, H⟩ := this.has_min Set.univ ⟨⟨c, hcs⟩, trivial⟩
  exact ⟨m, hms, fun x hx hxm => H ⟨x, hx⟩ trivial hxm⟩
Existence of Minimal Elements in Nonempty Finite Sets under Preorders
Informal description
Let $\alpha$ be a type with a preorder $\leq$ and let $s$ be a nonempty finite subset of $\alpha$. Then there exists an element $m \in s$ such that for all $x \in s$, $x \not< m$ (i.e., $m$ is a minimal element of $s$ with respect to the strict order $<$).
Finset.exists_maximal theorem
{α : Type*} [Preorder α] (s : Finset α) (h : s.Nonempty) : ∃ m ∈ s, ∀ x ∈ s, ¬m < x
Full source
theorem Finset.exists_maximal {α : Type*} [Preorder α] (s : Finset α) (h : s.Nonempty) :
    ∃ m ∈ s, ∀ x ∈ s, ¬m < x :=
  @Finset.exists_minimal αᵒᵈ _ s h
Existence of Maximal Elements in Nonempty Finite Sets under Preorders
Informal description
Let $\alpha$ be a type equipped with a preorder $\leq$, and let $s$ be a nonempty finite subset of $\alpha$. Then there exists an element $m \in s$ such that for all $x \in s$, $m \not< x$ (i.e., $m$ is a maximal element of $s$ with respect to the strict order $<$).
Infinite.of_not_fintype theorem
(h : Fintype α → False) : Infinite α
Full source
theorem of_not_fintype (h : Fintype α → False) : Infinite α :=
  isEmpty_fintype.mp ⟨h⟩
Infinite Type from Nonexistence of Finite Structure
Informal description
If there exists no finite structure on a type $\alpha$ (i.e., `Fintype α` is empty), then $\alpha$ is infinite.
Infinite.of_injective_to_set theorem
{s : Set α} (hs : s ≠ Set.univ) {f : α → s} (hf : Injective f) : Infinite α
Full source
/-- If `s : Set α` is a proper subset of `α` and `f : α → s` is injective, then `α` is infinite. -/
theorem of_injective_to_set {s : Set α} (hs : s ≠ Set.univ) {f : α → s} (hf : Injective f) :
    Infinite α :=
  of_not_fintype fun h => by
    classical
      refine lt_irrefl (Fintype.card α) ?_
      calc
        Fintype.card α ≤ Fintype.card s := Fintype.card_le_of_injective f hf
        _ = #s.toFinset := s.toFinset_card.symm
        _ < Fintype.card α :=
          Finset.card_lt_card <| by rwa [Set.toFinset_ssubset_univ, Set.ssubset_univ_iff]
Infinite Type via Injection to Proper Subset
Informal description
Let $\alpha$ be a type and $s$ be a proper subset of $\alpha$ (i.e., $s \subset \alpha$). If there exists an injective function $f : \alpha \to s$, then $\alpha$ is infinite.
Infinite.of_surjective_from_set theorem
{s : Set α} (hs : s ≠ Set.univ) {f : s → α} (hf : Surjective f) : Infinite α
Full source
/-- If `s : Set α` is a proper subset of `α` and `f : s → α` is surjective, then `α` is infinite. -/
theorem of_surjective_from_set {s : Set α} (hs : s ≠ Set.univ) {f : s → α} (hf : Surjective f) :
    Infinite α :=
  of_injective_to_set hs (injective_surjInv hf)
Infinite Type via Surjection from Proper Subset
Informal description
Let $\alpha$ be a type and $s$ be a proper subset of $\alpha$ (i.e., $s \neq \alpha$). If there exists a surjective function $f : s \to \alpha$, then $\alpha$ is infinite.
Infinite.exists_not_mem_finset theorem
[Infinite α] (s : Finset α) : ∃ x, x ∉ s
Full source
theorem exists_not_mem_finset [Infinite α] (s : Finset α) : ∃ x, x ∉ s :=
  not_forall.1 fun h => Fintype.false ⟨s, h⟩
Existence of Element Outside Any Finite Subset of an Infinite Type
Informal description
For any infinite type $\alpha$ and any finite subset $s$ of $\alpha$ (represented as a `Finset`), there exists an element $x \in \alpha$ such that $x \notin s$.
Infinite.nonempty theorem
(α : Type*) [Infinite α] : Nonempty α
Full source
protected theorem nonempty (α : Type*) [Infinite α] : Nonempty α := by infer_instance
Nonemptiness of Infinite Types
Informal description
For any infinite type $\alpha$, there exists at least one element in $\alpha$.
Infinite.of_injective theorem
{α β} [Infinite β] (f : β → α) (hf : Injective f) : Infinite α
Full source
theorem of_injective {α β} [Infinite β] (f : β → α) (hf : Injective f) : Infinite α :=
  ⟨fun _I => (Finite.of_injective f hf).false⟩
Infinite Type via Injective Map
Informal description
Let $\alpha$ and $\beta$ be types, with $\beta$ infinite. If there exists an injective function $f \colon \beta \to \alpha$, then $\alpha$ is also infinite.
Infinite.of_surjective theorem
{α β} [Infinite β] (f : α → β) (hf : Surjective f) : Infinite α
Full source
theorem of_surjective {α β} [Infinite β] (f : α → β) (hf : Surjective f) : Infinite α :=
  ⟨fun _I => (Finite.of_surjective f hf).false⟩
Infinite Type via Surjective Map
Informal description
Let $\alpha$ and $\beta$ be types, with $\beta$ infinite. If there exists a surjective function $f \colon \alpha \to \beta$, then $\alpha$ is also infinite.
Infinite.instSigmaOfNonempty instance
{β : α → Type*} [Infinite α] [∀ a, Nonempty (β a)] : Infinite ((a : α) × β a)
Full source
instance {β : α → Type*} [Infinite α] [∀ a, Nonempty (β a)] : Infinite ((a : α) × β a) :=
  Infinite.of_surjective Sigma.fst Sigma.fst_surjective
Infinite Dependent Sum from Infinite Base and Nonempty Fibers
Informal description
For any type family $\beta \colon \alpha \to \text{Type}$ where $\alpha$ is infinite and $\beta(a)$ is nonempty for every $a \in \alpha$, the dependent sum type $\Sigma (a : \alpha), \beta(a)$ is infinite.
Infinite.sigma_of_right theorem
{β : α → Type*} {a : α} [Infinite (β a)] : Infinite ((a : α) × β a)
Full source
theorem sigma_of_right {β : α → Type*} {a : α} [Infinite (β a)] :
    Infinite ((a : α) × β a) :=
  Infinite.of_injective (f := fun x ↦ ⟨a,x⟩) fun _ _ ↦ by simp
Infinite Dependent Sum from Infinite Fiber
Informal description
For any type family $\beta \colon \alpha \to \text{Type}$ and a fixed element $a \in \alpha$, if the type $\beta(a)$ is infinite, then the dependent sum type $\Sigma (a : \alpha), \beta(a)$ is also infinite.
Infinite.instSigmaOfNonempty_1 instance
{β : α → Type*} [Nonempty α] [∀ a, Infinite (β a)] : Infinite ((a : α) × β a)
Full source
instance {β : α → Type*} [Nonempty α] [∀ a, Infinite (β a)] : Infinite ((a : α) × β a) :=
  Infinite.sigma_of_right (a := Classical.arbitrary α)
Infinite Dependent Sum from Infinite Fibers
Informal description
For any nonempty type $\alpha$ and a type family $\beta \colon \alpha \to \text{Type}$ where each $\beta(a)$ is infinite, the dependent sum type $\Sigma (a : \alpha), \beta(a)$ is infinite.
instInfiniteOption instance
[Infinite α] : Infinite (Option α)
Full source
instance [Infinite α] : Infinite (Option α) :=
  Infinite.of_injective some (Option.some_injective α)
Infinite Option Type from Infinite Base Type
Informal description
For any infinite type $\alpha$, the type $\operatorname{Option} \alpha$ (the type $\alpha$ with an added element $\operatorname{none}$) is also infinite.
Infinite.natEmbedding definition
(α : Type*) [Infinite α] : ℕ ↪ α
Full source
/-- Embedding of `ℕ` into an infinite type. -/
noncomputable def natEmbedding (α : Type*) [Infinite α] : ℕ ↪ α :=
  ⟨_, natEmbeddingAux_injective α⟩
Embedding of natural numbers into an infinite type
Informal description
Given an infinite type $\alpha$, there exists an injective function embedding from the natural numbers $\mathbb{N}$ into $\alpha$. This embedding is constructed using an auxiliary function `natEmbeddingAux` and its injectivity is ensured by the proof `natEmbeddingAux_injective`.
Infinite.exists_subset_card_eq theorem
(α : Type*) [Infinite α] (n : ℕ) : ∃ s : Finset α, #s = n
Full source
/-- See `Infinite.exists_superset_card_eq` for a version that, for an `s : Finset α`,
provides a superset `t : Finset α`, `s ⊆ t` such that `#t` is fixed. -/
theorem exists_subset_card_eq (α : Type*) [Infinite α] (n : ) : ∃ s : Finset α, #s = n :=
  ⟨(range n).map (natEmbedding α), by rw [card_map, card_range]⟩
Existence of finite subsets with arbitrary cardinality in infinite types
Informal description
For any infinite type $\alpha$ and any natural number $n$, there exists a finite subset $s$ of $\alpha$ with cardinality $n$.
Infinite.exists_superset_card_eq theorem
[Infinite α] (s : Finset α) (n : ℕ) (hn : #s ≤ n) : ∃ t : Finset α, s ⊆ t ∧ #t = n
Full source
/-- See `Infinite.exists_subset_card_eq` for a version that provides an arbitrary
`s : Finset α` for any cardinality. -/
theorem exists_superset_card_eq [Infinite α] (s : Finset α) (n : ) (hn : #s ≤ n) :
    ∃ t : Finset α, s ⊆ t ∧ #t = n := by
  induction' n with n IH generalizing s
  · exact ⟨s, subset_refl _, Nat.eq_zero_of_le_zero hn⟩
  · rcases hn.eq_or_lt with hn' | hn'
    · exact ⟨s, subset_refl _, hn'⟩
    obtain ⟨t, hs, ht⟩ := IH _ (Nat.le_of_lt_succ hn')
    obtain ⟨x, hx⟩ := exists_not_mem_finset t
    refine ⟨Finset.cons x t hx, hs.trans (Finset.subset_cons _), ?_⟩
    simp [hx, ht]
Existence of Finite Superset with Specified Cardinality in Infinite Types
Informal description
For any infinite type $\alpha$, given a finite subset $s$ of $\alpha$ and a natural number $n$ such that the cardinality of $s$ is at most $n$, there exists a finite subset $t$ of $\alpha$ containing $s$ with cardinality exactly $n$.
fintypeOfFinsetCardLe definition
{ι : Type*} (n : ℕ) (w : ∀ s : Finset ι, #s ≤ n) : Fintype ι
Full source
/-- If every finset in a type has bounded cardinality, that type is finite. -/
noncomputable def fintypeOfFinsetCardLe {ι : Type*} (n : ) (w : ∀ s : Finset ι, #s ≤ n) :
    Fintype ι := by
  apply fintypeOfNotInfinite
  intro i
  obtain ⟨s, c⟩ := Infinite.exists_subset_card_eq ι (n + 1)
  specialize w s
  rw [c] at w
  exact Nat.not_succ_le_self n w
Finite type from bounded cardinality of finite subsets
Informal description
If every finite subset of a type $\iota$ has cardinality bounded above by a fixed natural number $n$, then $\iota$ is finite. In other words, if there exists a natural number $n$ such that for all finite subsets $s$ of $\iota$, the cardinality of $s$ is at most $n$, then $\iota$ is a finite type.
not_injective_infinite_finite theorem
{α β} [Infinite α] [Finite β] (f : α → β) : ¬Injective f
Full source
theorem not_injective_infinite_finite {α β} [Infinite α] [Finite β] (f : α → β) : ¬Injective f :=
  fun hf => (Finite.of_injective f hf).false
No Injection from Infinite to Finite Types
Informal description
For any infinite type $\alpha$ and finite type $\beta$, there does not exist an injective function $f \colon \alpha \to \beta$.
not_surjective_finite_infinite theorem
{α β} [Finite α] [Infinite β] (f : α → β) : ¬Surjective f
Full source
theorem not_surjective_finite_infinite {α β} [Finite α] [Infinite β] (f : α → β) : ¬Surjective f :=
  fun hf => (Infinite.of_surjective f hf).not_finite ‹_›
No Surjection from Finite to Infinite Types
Informal description
For any finite type $\alpha$ and infinite type $\beta$, there does not exist a surjective function $f \colon \alpha \to \beta$.