The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V03. Sets, finite structures and big operators

Mathlib.Data.Fintype.EquivFin

93 declarations. Mathlib docs · Source

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.

theorem Multiset.pmap.congr_simp E1 #

∀ {α : Type u_1} {β : Type v} {p : α → Prop} (f f_1 : (a : α) → p a → β),
  f = f_1 → ∀ (s s_1 : Multiset α) (e_s : s = s_1) (a : ∀ a ∈ s, p a), Multiset.pmap f s a = Multiset.pmap f_1 s_1 ⋯

def Fintype.truncEquivFin E3 #

(α : Type u_3) → [DecidableEq α] → [inst : Fintype α] → Trunc (α ≃ Fin (Fintype.card α))

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 Fintype.equivFin E3 #

(α : Type u_3) → [inst : Fintype α] → α ≃ Fin (Fintype.card α)

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.

def Fintype.truncFinBijection E1 #

(α : Type u_3) → [inst : Fintype α] → Trunc { f // Function.Bijective f }

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 Fintype.truncEquivFinOfCardEq E1 #

{α : Type u_1} → [inst : Fintype α] → [DecidableEq α] → {n : ℕ} → Fintype.card α = n → Trunc (α ≃ Fin n)

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 Fintype.equivFinOfCardEq E1 #

{α : Type u_1} → [inst : Fintype α] → {n : ℕ} → Fintype.card α = n → α ≃ Fin n

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 α).

def Fintype.truncEquivOfCardEq E3 #

{α : Type u_1} →
  {β : Type u_2} →
    [inst : Fintype α] →
      [inst_1 : Fintype β] → [DecidableEq α] → [DecidableEq β] → Fintype.card α = Fintype.card β → Trunc (α ≃ β)

Two Fintypes 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 Fintype.equivOfCardEq E3 #

{α : Type u_1} → {β : Type u_2} → [inst : Fintype α] → [inst_1 : Fintype β] → Fintype.card α = Fintype.card β → α ≃ β

Two Fintypes 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.

theorem Fintype.card_eq E0 #

∀ {α : Type u_3} {β : Type u_4} [_F : Fintype α] [_G : Fintype β], Fintype.card α = Fintype.card β ↔ Nonempty (α ≃ β)

theorem Fintype.finite E1 #

∀ {α : Type u_3} (_inst : Fintype α), Finite α

instance Finite.of_fintype E0 #

∀ (α : Type u_3) [Fintype α], Finite α

For efficiency reasons, we want Finite instances to have higher priority than ones coming from Fintype instances.

theorem finite_iff_nonempty_fintype E1 #

∀ (α : Type u_3), Finite α ↔ Nonempty (Fintype α)

def Fintype.ofFinite E1 #

(α : Type u_3) → [Finite α] → Fintype α

Noncomputably get a Fintype instance from a Finite instance. This is not an instance because we want Fintype instances to be useful for computations.

theorem Finite.of_injective E1 #

∀ {α : Sort u_3} {β : Sort u_4} [Finite β] (f : α → β), Function.Injective f → Finite α

instance Finite.of_subsingleton E0 #

∀ {α : Sort u_3} [Subsingleton α], Finite α

instance instFiniteProp E0 #

∀ (p : Prop), Finite p

instance Subtype.finite E0 #

∀ {α : Sort u_3} [Finite α] {p : α → Prop}, Finite { x // p x }

This instance also provides [Finite s] for s : Set α.

theorem Finite.of_surjective E1 #

∀ {α : Sort u_3} {β : Sort u_4} [Finite α] (f : α → β), Function.Surjective f → Finite β

instance Quot.finite E0 #

∀ {α : Sort u_3} [Finite α] (r : α → α → Prop), Finite (Quot r)

instance Quotient.finite E0 #

∀ {α : Sort u_3} [Finite α] (s : Setoid α), Finite (Quotient s)

theorem Fintype.card_eq_one_iff E0 #

∀ {α : Type u_1} [inst : Fintype α], Fintype.card α = 1 ↔ ∃ x, ∀ (y : α), y = x

theorem Fintype.card_eq_one_iff_nonempty_unique E1 #

∀ {α : Type u_1} [inst : Fintype α], Fintype.card α = 1 ↔ Nonempty (Unique α)

theorem Fintype.card_le_one_iff E0 #

∀ {α : Type u_1} [inst : Fintype α], Fintype.card α ≤ 1 ↔ ∀ (a b : α), a = b

theorem Fintype.card_le_one_iff_subsingleton E1 #

∀ {α : Type u_1} [inst : Fintype α], Fintype.card α ≤ 1 ↔ Subsingleton α

theorem Fintype.one_lt_card_iff_nontrivial E1 #

∀ {α : Type u_1} [inst : Fintype α], 1 < Fintype.card α ↔ Nontrivial α

theorem Fintype.exists_ne_of_one_lt_card E1 #

∀ {α : Type u_1} [inst : Fintype α], 1 < Fintype.card α → ∀ (a : α), ∃ b, b ≠ a

theorem Fintype.exists_pair_of_one_lt_card E1 #

∀ {α : Type u_1} [inst : Fintype α], 1 < Fintype.card α → ∃ a b, a ≠ b

theorem Fintype.card_eq_one_of_forall_eq E0 #

∀ {α : Type u_1} [inst : Fintype α] {i : α}, (∀ (j : α), j = i) → Fintype.card α = 1

theorem Fintype.one_lt_card E1 #

∀ {α : Type u_1} [inst : Fintype α] [h : Nontrivial α], 1 < Fintype.card α

theorem Fintype.one_lt_card_iff E0 #

∀ {α : Type u_1} [inst : Fintype α], 1 < Fintype.card α ↔ ∃ a b, a ≠ b

theorem Fintype.bijective_iff_injective_and_card E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (f : α → β),
  Function.Bijective f ↔ Function.Injective f ∧ Fintype.card α = Fintype.card β

theorem Fintype.bijective_iff_surjective_and_card E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (f : α → β),
  Function.Bijective f ↔ Function.Surjective f ∧ Fintype.card α = Fintype.card β

theorem Function.LeftInverse.rightInverse_of_card_le E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] {f : α → β} {g : β → α},
  Function.LeftInverse f g → Fintype.card α ≤ Fintype.card β → Function.RightInverse f g

theorem Function.RightInverse.leftInverse_of_card_le E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] {f : α → β} {g : β → α},
  Function.RightInverse f g → Fintype.card β ≤ Fintype.card α → Function.LeftInverse f g

def Equiv.ofLeftInverseOfCardLE E1 #

{α : Type u_1} →
  {β : Type u_2} →
    [inst : Fintype α] →
      [inst_1 : Fintype β] →
        Fintype.card β ≤ Fintype.card α → (f : α → β) → (g : β → α) → Function.LeftInverse g f → α ≃ β

Construct an equivalence from functions that are inverse to each other.

theorem Equiv.ofLeftInverseOfCardLE_apply E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (hβα : Fintype.card β ≤ Fintype.card α)
  (f : α → β) (g : β → α) (h : Function.LeftInverse g f) (a : α), (Equiv.ofLeftInverseOfCardLE hβα f g h) a = f a

theorem Equiv.ofLeftInverseOfCardLE_symm_apply E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (hβα : Fintype.card β ≤ Fintype.card α)
  (f : α → β) (g : β → α) (h : Function.LeftInverse g f) (a : β), (Equiv.ofLeftInverseOfCardLE hβα f g h).symm a = g a

def Equiv.ofRightInverseOfCardLE E1 #

{α : Type u_1} →
  {β : Type u_2} →
    [inst : Fintype α] →
      [inst_1 : Fintype β] →
        Fintype.card α ≤ Fintype.card β → (f : α → β) → (g : β → α) → Function.RightInverse g f → α ≃ β

Construct an equivalence from functions that are inverse to each other.

theorem Equiv.ofRightInverseOfCardLE_apply E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (hαβ : Fintype.card α ≤ Fintype.card β)
  (f : α → β) (g : β → α) (h : Function.RightInverse g f) (a : α), (Equiv.ofRightInverseOfCardLE hαβ f g h) a = f a

theorem Equiv.ofRightInverseOfCardLE_symm_apply E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (hαβ : Fintype.card α ≤ Fintype.card β)
  (f : α → β) (g : β → α) (h : Function.RightInverse g f) (a : β), (Equiv.ofRightInverseOfCardLE hαβ f g h).symm a = g a

def Finset.equivFin E1 #

{α : Type u_1} → (s : Finset α) → ↥s ≃ Fin s.card

Noncomputable equivalence between a finset s coerced to a type and Fin #s.

def Finset.equivFinOfCardEq E1 #

{α : Type u_1} → {s : Finset α} → {n : ℕ} → s.card = n → ↥s ≃ Fin n

Noncomputable equivalence between a finset s as a fintype and Fin n, when there is a proof that #s = n.

theorem Finset.card_eq_of_equiv_fin E1 #

∀ {α : Type u_1} {s : Finset α} {n : ℕ} (i : ↥s ≃ Fin n), s.card = n

theorem Finset.card_eq_of_equiv_fintype E1 #

∀ {α : Type u_1} {β : Type u_2} {s : Finset α} [inst : Fintype β] (i : ↥s ≃ β), s.card = Fintype.card β

def Finset.equivOfCardEq E1 #

{α : Type u_1} → {β : Type u_2} → {s : Finset α} → {t : Finset β} → s.card = t.card → ↥s ≃ ↥t

Noncomputable equivalence between two finsets s and t as fintypes when there is a proof that #s = #t.

theorem Finset.card_eq_of_equiv E1 #

∀ {α : Type u_1} {β : Type u_2} {s : Finset α} {t : Finset β} (i : ↥s ≃ ↥t), s.card = t.card

def Function.Embedding.equivOfFiniteSelfEmbedding E1 #

{α : Type u_1} → [Finite α] → (α ↪ α) → α ≃ α

An embedding from a Fintype to itself can be promoted to an equivalence.

theorem Function.Embedding.toEmbedding_equivOfFiniteSelfEmbedding E0 #

∀ {α : Type u_1} [inst : Finite α] (e : α ↪ α), e.equivOfFiniteSelfEmbedding.toEmbedding = e

def Equiv.embeddingEquivOfFinite E1 #

(α : Type u_3) → [Finite α] → (α ↪ α) ≃ (α ≃ α)

On a finite type, equivalence between the self-embeddings and the bijections.

theorem Equiv.embeddingEquivOfFinite_apply E0 #

∀ (α : Type u_3) [inst : Finite α] (e : α ↪ α), (Equiv.embeddingEquivOfFinite α) e = e.equivOfFiniteSelfEmbedding

theorem Equiv.embeddingEquivOfFinite_symm_apply_apply E0 #

∀ (α : Type u_3) [inst : Finite α] (e : α ≃ α) (a : α), ((Equiv.embeddingEquivOfFinite α).symm e) a = e a

def Function.Embedding.truncOfCardLE E1 #

{α : Type u_1} →
  {β : Type u_2} →
    [inst : Fintype α] →
      [inst_1 : Fintype β] → [DecidableEq α] → [DecidableEq β] → Fintype.card α ≤ Fintype.card β → Trunc (α ↪ β)

A constructive embedding of a fintype α in another fintype β when card α ≤ card β.

theorem Function.Embedding.nonempty_of_card_le E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β],
  Fintype.card α ≤ Fintype.card β → Nonempty (α ↪ β)

theorem Function.Embedding.nonempty_iff_card_le E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β],
  Nonempty (α ↪ β) ↔ Fintype.card α ≤ Fintype.card β

theorem Function.Embedding.exists_of_card_le_finset E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] {s : Finset β}, Fintype.card α ≤ s.card → ∃ f, Set.range ⇑f ⊆ ↑s

theorem Function.Embedding.exists_of_card_eq_finset E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] {s : Finset β},
  Fintype.card α = s.card → ∃ f, Finset.map f Finset.univ = s

theorem Finset.univ_map_embedding E0 #

∀ {α : Type u_3} [inst : Fintype α] (e : α ↪ α), Finset.map e Finset.univ = Finset.univ

theorem Fintype.card_lt_of_surjective_not_injective E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Fintype α] [inst_1 : Fintype β] (f : α → β),
  Function.Surjective f → ¬Function.Injective f → Fintype.card β < Fintype.card α

theorem Fintype.false E1 #

∀ {α : Type u_1} [Infinite α] (_h : Fintype α), False

theorem isEmpty_fintype E0 #

∀ {α : Type u_3}, IsEmpty (Fintype α) ↔ Infinite α

def fintypeOfNotInfinite E1 #

{α : Type u_3} → ¬Infinite α → Fintype α

A non-infinite type is a fintype.

def fintypeOrInfinite E1 #

(α : Type u_3) → Fintype α ⊕' Infinite α

Any type is (classically) either a Fintype, or Infinite.

One can obtain the relevant typeclasses via cases fintypeOrInfinite α.

theorem Infinite.of_not_fintype E1 #

∀ {α : Type u_1}, (∀ (a : Fintype α), False) → Infinite α

theorem Infinite.of_injective_to_set E1 #

∀ {α : Type u_1} {s : Set α}, s ≠ Set.univ → ∀ {f : α → ↑s}, Function.Injective f → Infinite α

If s : Set α is a proper subset of α and f : α → s is injective, then α is infinite.

theorem Infinite.of_surjective_from_set E1 #

∀ {α : Type u_1} {s : Set α}, s ≠ Set.univ → ∀ {f : ↑s → α}, Function.Surjective f → Infinite α

If s : Set α is a proper subset of α and f : s → α is surjective, then α is infinite.

theorem Infinite.exists_notMem_finset E1 #

∀ {α : Type u_1} [Infinite α] (s : Finset α), ∃ x, x ∉ s

instance Infinite.instNontrivial E0 #

∀ (α : Type u_3) [Infinite α], Nontrivial α

theorem Infinite.nonempty E1 #

∀ (α : Type u_3) [Infinite α], Nonempty α

theorem Infinite.of_injective E3 #

∀ {α : Sort u_3} {β : Sort u_4} [Infinite β] (f : β → α), Function.Injective f → Infinite α

theorem Infinite.of_surjective E3 #

∀ {α : Sort u_3} {β : Sort u_4} [Infinite β] (f : α → β), Function.Surjective f → Infinite α

instance Infinite.instSigmaOfNonempty E0 #

∀ {α : Type u_1} {β : α → Type u_3} [Infinite α] [∀ (a : α), Nonempty (β a)], Infinite ((a : α) × β a)

theorem Infinite.sigma_of_right E1 #

∀ {α : Type u_1} {β : α → Type u_3} {a : α} [Infinite (β a)], Infinite ((a : α) × β a)

instance Infinite.instSigmaOfNonempty_1 E0 #

∀ {α : Type u_1} {β : α → Type u_3} [Nonempty α] [∀ (a : α), Infinite (β a)], Infinite ((a : α) × β a)

instance instInfiniteNat E0 #

Infinite ℕ

instance Int.infinite E0 #

Infinite ℤ

instance instInfiniteMultisetOfNonempty E0 #

∀ {α : Type u_1} [Nonempty α], Infinite (Multiset α)

instance instInfiniteListOfNonempty E0 #

∀ {α : Type u_1} [Nonempty α], Infinite (List α)

instance String.infinite E0 #

Infinite String

instance Infinite.set E0 #

∀ {α : Type u_1} [Infinite α], Infinite (Set α)

instance instInfiniteFinset E0 #

∀ {α : Type u_1} [Infinite α], Infinite (Finset α)

instance instInfiniteOption E0 #

∀ {α : Type u_1} [Infinite α], Infinite (Option α)

instance Sum.infinite_of_left E0 #

∀ {α : Type u_1} {β : Type u_2} [Infinite α], Infinite (α ⊕ β)

instance Sum.infinite_of_right E0 #

∀ {α : Type u_1} {β : Type u_2} [Infinite β], Infinite (α ⊕ β)

instance Prod.infinite_of_right E0 #

∀ {α : Type u_1} {β : Type u_2} [Nonempty α] [Infinite β], Infinite (α × β)

instance Prod.infinite_of_left E0 #

∀ {α : Type u_1} {β : Type u_2} [Infinite α] [Nonempty β], Infinite (α × β)

instance instInfinitePerm E0 #

∀ {α : Type u_1} [Infinite α], Infinite (Equiv.Perm α)

def Infinite.natEmbedding E3 #

(α : Type u_3) → [Infinite α] → ℕ ↪ α

Embedding of ℕ into an infinite type.

theorem Infinite.exists_subset_card_eq E0 #

∀ (α : Type u_3) [Infinite α] (n : ℕ), ∃ s, s.card = n

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 Infinite.exists_superset_card_eq E0 #

∀ {α : Type u_1} [Infinite α] (s : Finset α) (n : ℕ), s.card ≤ n → ∃ t, s ⊆ t ∧ t.card = n

See Infinite.exists_subset_card_eq for a version that provides an arbitrary s : Finset α for any cardinality.

def fintypeOfFinsetCardLe E1 #

{ι : Type u_3} → (n : ℕ) → (∀ (s : Finset ι), s.card ≤ n) → Fintype ι

If every finset in a type has bounded cardinality, that type is finite.

theorem not_injective_infinite_finite E1 #

∀ {α : Sort u_3} {β : Sort u_4} [Infinite α] [Finite β] (f : α → β), ¬Function.Injective f

instance Function.Embedding.is_empty E0 #

∀ {α : Sort u_3} {β : Sort u_4} [Infinite α] [Finite β], IsEmpty (α ↪ β)

theorem not_surjective_finite_infinite E1 #

∀ {α : Sort u_3} {β : Sort u_4} [Finite α] [Infinite β] (f : α → β), ¬Function.Surjective f