module Data.Fin.Finite where
Finite types🔗
This module pieces together a couple of pre-existing constructions: In terms of the standard finite sets (which are defined for natural numbers ) and deloopings of automorphism groups, we construct the type of finite types. By univalence, the space of finite types classifies maps with finite fibres.
But what does it mean for a type to be finite? A naïve first approach is to define “ is finite” to mean “ is equipped with and ” but this turns out to be too strong: This doesn’t just equip the type with a cardinality, but also with a choice of total order. Additionally, defined like this, the type of finite types is a set!
: is-set (Σ[ X ∈ Type ] Σ[ n ∈ Nat ] Fin n ≃ X)
naïve-fin-is-set = is-hlevel≃ 2 Σ-swap₂ $
naïve-fin-is-set 2 (hlevel 2) λ x → is-prop→is-hlevel-suc {n = 1} $
Σ-is-hlevel (Fin x) is-contr→is-prop $ Equiv-is-contr
That’s because, as the proof above shows, it’s equivalent to the type of natural numbers: The type is equivalent to the type and univalence says (rather directly) that the sum of as ranges over a universe is contractible, so we’re left with the type of natural numbers.
This simply won’t do: we want the type of finite sets to be equivalent to the (core of the) category of finite sets, where the automorphism group of has elements, not exactly one element. What we do is appeal to a basic intuition: A groupoid is the sum over its connected components, and we have representatives for every connected component (given by the standard finite sets):
: Type (lsuc lzero)
Fin-type = Σ[ n ∈ Nat ] BAut (Fin n)
Fin-type
: is-hlevel Fin-type 3
Fin-type-is-groupoid = Σ-is-hlevel 3 (hlevel 3) λ _ →
Fin-type-is-groupoid (Fin _) 2 (hlevel 2) BAut-is-hlevel
Informed by this, we now express the correct definition of “being finite”, namely, being merely equivalent to some standard finite set. Rather than using Σ types for this, we can set up typeclass machinery for automatically deriving boring instances of finiteness, i.e. those that follow directly from the closure properties.
record Finite {ℓ} (T : Type ℓ) : Type ℓ where
constructor fin
field
{cardinality} : Nat
: ∥ T ≃ Fin cardinality ∥ enumeration
instance
: ∀ {n} → Finite (Fin n)
Finite-Fin : ⦃ Finite A ⦄ → ⦃ Finite B ⦄ → Finite (A ⊎ B)
Finite-⊎
Finite-Σ: {P : A → Type ℓ} → ⦃ Finite A ⦄ → ⦃ ∀ {x} → Finite (P x) ⦄ → Finite (Σ A P)
Finite-Π: {P : A → Type ℓ} → ⦃ Finite A ⦄ → ⦃ ∀ {x} → Finite (P x) ⦄ → Finite (∀ x → P x)
: Finite ⊥
Finite-⊥ : Finite ⊤
Finite-⊤ : Finite Bool
Finite-Bool
Finite-PathP: ∀ {A : I → Type ℓ} ⦃ s : Finite (A i1) ⦄ {x y}
→ Finite (PathP A x y)
: ∀ {ℓ} → ⦃ Finite A ⦄ → Finite (Lift ℓ A) Finite-Lift