Martin Escardo, November 2019
Other interesting uses of the types Fin n is in the file
https://www.cs.bham.ac.uk/~mhe/TypeTopology/ArithmeticViaEquivalence.html
which proves commutativity of addition and multiplication, and more,
using the corresponding properties for (finite) types.
\begin{code}
{-# OPTIONS --safe --without-K #-}
module Fin.Topology where
open import Fin.Bishop
open import Fin.Properties
open import Fin.Type
open import MLTT.Spartan
open import MLTT.SpartanList
open import TypeTopology.CompactTypes
open import UF.DiscreteAndSeparated
open import UF.Equiv
open import UF.EquivalenceExamples
open import UF.ClassicalLogic
open import UF.FunExt
open import UF.PropTrunc
open import UF.Sets
open import UF.SubtypeClassifier
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
\end{code}
Recall that a type is discrete if it has decidable equality.
\begin{code}
Fin-is-discrete : {n : โ} โ is-discrete (Fin n)
Fin-is-discrete {0 } = ๐-is-discrete
Fin-is-discrete {succ n} = +-is-discrete (Fin-is-discrete {n}) ๐-is-discrete
Fin-is-set : {n : โ} โ is-set (Fin n)
Fin-is-set = discrete-types-are-sets Fin-is-discrete
\end{code}
The type Fin n is compact, or exhaustively searchable.
\begin{code}
Fin-Compact : {n : โ} โ is-Compact (Fin n) {๐ค}
Fin-Compact {๐ค} {0} = ๐-is-Compact
Fin-Compact {๐ค} {succ n} = +-is-Compact (Fin-Compact {๐ค} {n}) ๐-is-Compact
Fin-ฮ -Compact : (n : โ) โ is-ฮ -Compact (Fin n) {๐ค}
Fin-ฮ -Compact n = ฮฃ-Compact-types-are-ฮ -Compact (Fin n) Fin-Compact
Fin-Compactโ : (n : โ) โ is-Compactโ (Fin (succ n)) {๐ค}
Fin-Compactโ n = Compact-pointed-gives-Compactโ Fin-Compact ๐
\end{code}
Added 15th December 2019.
If the type X i is compact for every i : Fin n, then the product type
(i : Fin n) โ X i is also compact.
\begin{code}
finite-product-compact : (n : โ) (X : Fin n โ ๐ค ฬ )
โ ((i : Fin n) โ is-Compact (X i) {๐ค})
โ is-Compact (vec n X) {๐ค}
finite-product-compact zero X c = ๐-is-Compact
finite-product-compact (succ n) X c = ร-is-Compact
(c ๐)
(finite-product-compact n (X โ suc) (c โ suc))
finitely-indexed-product-compact : funext ๐คโ ๐ค
โ (n : โ) (X : Fin n โ ๐ค ฬ )
โ ((i : Fin n) โ is-Compact (X i))
โ is-Compact ((i : Fin n) โ X i)
finitely-indexed-product-compact fe n X c = Compact-closed-under-โ
(vec-โ fe n)
(finite-product-compact n X c)
\end{code}
Finite types are compact, or exhaustively searchable.
\begin{code}
module _ (pt : propositional-truncations-exist) where
open PropositionalTruncation pt
open CompactTypesPT pt
open finiteness pt
finite-โฅCompactโฅ : {X : ๐ค ฬ } โ is-finite X โ โฅ is-Compact X {๐ฅ} โฅ
finite-โฅCompactโฅ {๐ค} {๐ฅ} {X} (n , ฮฑ) =
โฅโฅ-functor (ฮป (e : X โ Fin n) โ Compact-closed-under-โ (โ-sym e) Fin-Compact) ฮฑ
finite-types-are-โ-Compact : Fun-Ext โ {X : ๐ค ฬ } โ is-finite X โ is-โ-Compact X {๐ฅ}
finite-types-are-โ-Compact fe ฯ = โฅCompactโฅ-gives-โ-Compact fe (finite-โฅCompactโฅ ฯ)
\end{code}
Finite types are discrete and hence sets:
\begin{code}
finite-types-are-discrete : FunExt โ {X : ๐ค ฬ } โ is-finite X โ is-discrete X
finite-types-are-discrete fe {X} (n , s) = โฅโฅ-rec (being-discrete-is-prop fe) ฮณ s
where
ฮณ : X โ Fin n โ is-discrete X
ฮณ (f , e) = lc-maps-reflect-discreteness f (equivs-are-lc f e) Fin-is-discrete
finite-types-are-sets : FunExt โ {X : ๐ค ฬ } โ is-finite X โ is-set X
finite-types-are-sets fe ฯ = discrete-types-are-sets (finite-types-are-discrete fe ฯ)
finite-propositions-are-decidable' : Fun-Ext
โ {P : ๐ค ฬ }
โ is-prop P
โ is-finite P
โ is-decidable P
finite-propositions-are-decidable' fe i j =
โ-Compact-propositions-are-decidable i (finite-types-are-โ-Compact fe j)
finite-propositions-are-decidable : {P : ๐ค ฬ }
โ is-prop P
โ is-finite P
โ is-decidable P
finite-propositions-are-decidable {๐ค} {P} i (0 , s) = inr ฮณ
where
ฮณ : P โ ๐
ฮณ p = โฅโฅ-rec ๐-is-prop (ฮป (f , _) โ f p) s
finite-propositions-are-decidable {๐ค} {P} i (succ n , s) = inl ฮณ
where
ฮณ : P
ฮณ = โฅโฅ-rec i (ฮป ๐ โ โ ๐ โโปยน ๐) s
summands-of-finite-sum-always-finite-gives-EM :
((๐ค ๐ฅ : Universe) (X : ๐ค ฬ ) (A : X โ ๐ฅ ฬ )
โ is-finite (ฮฃ A)
โ (x : X) โ is-finite (A x))
โ (๐ฆ : Universe) โ funext ๐ฆ ๐ฆ โ propext ๐ฆ โ EM ๐ฆ
summands-of-finite-sum-always-finite-gives-EM ฯ ๐ฆ fe pe P i = ฮณ
where
X : ๐ฆ โบ ฬ
X = ฮฉ ๐ฆ
A : X โ ๐ฆ ฬ
A p = p holds
e : ฮฃ A โ (ฮฃ P ๊ ๐ฆ ฬ , is-prop P ร P)
e = ฮฃ-assoc
s : is-singleton (ฮฃ A)
s = equiv-to-singleton e (the-true-props-form-a-singleton-type fe pe)
f : ฮฃ A โ Fin 1
f = singleton-โ s Fin1-is-singleton
j : is-finite (ฮฃ A)
j = 1 , โฃ f โฃ
k : is-finite P
k = ฯ (๐ฆ โบ) ๐ฆ X A j (P , i)
ฮณ : P + ยฌ P
ฮณ = finite-propositions-are-decidable i k
\end{code}