Martin Escardo, 8th April 2021.

\begin{code}

{-# OPTIONS --safe --without-K #-}

open import UF.PropTrunc

module Fin.Kuratowski (pt : propositional-truncations-exist) where

open import Factorial.PlusOneLC
open import Fin.Bishop
open import Fin.Properties
open import Fin.Topology
open import Fin.Type
open import MLTT.Spartan
open import MLTT.Two-Properties
open import TypeTopology.CompactTypes
open import UF.Base
open import UF.DiscreteAndSeparated
open import UF.Embeddings
open import UF.Equiv
open import UF.Equiv-FunExt
open import UF.EquivalenceExamples
open import UF.ClassicalLogic
open import UF.FunExt
open import UF.ImageAndSurjection pt
open import UF.Sets
open import UF.Sets-Properties
open import UF.SubtypeClassifier
open import UF.SubtypeClassifier-Properties
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.UA-FunExt
open import UF.Univalence
open import UF.UniverseEmbedding

open CompactTypesPT pt
open PropositionalTruncation pt
open finiteness pt

is-Kuratowski-finite : 𝓀 Μ‡ β†’ 𝓀 Μ‡
is-Kuratowski-finite X = βˆƒ n κž‰ β„• , Fin n β†  X

Kuratowski-data : 𝓀 Μ‡ β†’ 𝓀 Μ‡
Kuratowski-data X = Ξ£ n κž‰ β„• , Fin n β†  X

being-Kuratowski-finite-is-prop : {X : 𝓀 Μ‡ } β†’ is-prop (is-Kuratowski-finite X)
being-Kuratowski-finite-is-prop = βˆƒ-is-prop

Kuratowski-finite-types-are-βˆƒ-compact : Fun-Ext
                                      β†’ {X : 𝓀 Μ‡ }
                                      β†’ is-Kuratowski-finite X
                                      β†’ is-βˆƒ-Compact X {𝓀}
Kuratowski-finite-types-are-βˆƒ-compact fe {X} i = Ξ³
 where
  Ξ± : Kuratowski-data X β†’ is-Compact X
  Ξ± (n , f , s) = surjection-Compact f fe s Fin-Compact

  Ξ² : βˆ₯ is-Compact X βˆ₯
  Ξ² = βˆ₯βˆ₯-functor Ξ± i

  Ξ³ : is-βˆƒ-Compact X
  Ξ³ = βˆ₯Compactβˆ₯-gives-βˆƒ-Compact fe Ξ²

finite-types-are-Kuratowski-finite : {X : 𝓀 Μ‡ }
                                   β†’ is-finite X
                                   β†’ is-Kuratowski-finite X
finite-types-are-Kuratowski-finite {𝓀} {X} X-is-finite = Ξ³
 where
  Ξ΄ : finite-linear-order X β†’ is-Kuratowski-finite X
  Ξ΄ (n , 𝕗) = ∣ n , (⌜ 𝕗 ⌝⁻¹ , equivs-are-surjections (⌜⌝⁻¹-is-equiv 𝕗)) ∣

  Ξ³ : is-Kuratowski-finite X
  Ξ³ = βˆ₯βˆ₯-rec being-Kuratowski-finite-is-prop Ξ΄ (finite-gives-finite' X X-is-finite)

\end{code}

Conversely, if a Kuratowski finite is discrete (that is, it has
decidable equality) then it is finite, because we can use the
decidable equality to remove repetitions, as observed by Tom de Jong
(and implemented by Martin Escardo):

\begin{code}

dkf-lemma : funext 𝓀 𝓀₀
          β†’ {X : 𝓀 Μ‡ }
          β†’ is-discrete X
          β†’ Kuratowski-data X
          β†’ finite-linear-order X
dkf-lemma {𝓀} fe {X} Ξ΄ (n , 𝕗) = Ξ³ X Ξ΄ n 𝕗
 where
  Ξ³ : (X : 𝓀 Μ‡ ) β†’ is-discrete X β†’ (n : β„•) β†’ (Fin n β†  X) β†’ finite-linear-order X
  Ξ³ X Ξ΄ 0        (f , s) = 0 , empty-≃-𝟘 (Ξ» x β†’ βˆ₯βˆ₯-rec 𝟘-is-prop pr₁ (s x))
  Ξ³ X Ξ΄ (succ n) (f , s) = I Ξ”
   where
    A : Fin n β†’ 𝓀 Μ‡
    A j = f (suc j) = f 𝟎

    Ξ” : is-decidable (Ξ£ A)
    Ξ” = Fin-Compact A (Ξ» j β†’ Ξ΄ (f (suc j)) (f 𝟎))

    g : Fin n β†’ X
    g i = f (suc i)

    I : is-decidable (Ξ£ A) β†’ finite-linear-order X
    I (inl (j , p)) = IH
     where
      II : (x : X) β†’ (Ξ£ i κž‰ Fin (succ n) , f i = x) β†’ (Ξ£ i κž‰ Fin n , g i = x)
      II x (𝟎 ,     q) = j , (p βˆ™ q)
      II x (suc i , q) = i , q

      III : is-surjection g
      III x = βˆ₯βˆ₯-functor (II x) (s x)

      IH : finite-linear-order X
      IH = Ξ³ X Ξ΄ n (g , III)

    I (inr Ξ½) = succ n' , IX
     where
      X' = X βˆ– f 𝟎

      Ξ΄' : is-discrete X'
      Ξ΄' = lc-maps-reflect-discreteness pr₁ (pr₁-lc (negations-are-props fe)) Ξ΄

      g' : Fin n β†’ X'
      g' i = g i , (Ξ» (p : f (suc i) = f 𝟎) β†’ Ξ½ (i , p))

      IV : is-surjection g'
      IV (x , u) = VII
       where
        V : βˆƒ i κž‰ Fin (succ n) , f i = x
        V = s x

        VI : (Ξ£ i κž‰ Fin (succ n) , f i = x) β†’ (Ξ£ i κž‰ Fin n , g' i = (x , u))
        VI (𝟎     , p) = 𝟘-elim (u (p ⁻¹))
        VI (suc i , p) = i , to-subtype-= (Ξ» _ β†’ negations-are-props fe) p

        VII : βˆƒ i κž‰ Fin n , g' i = (x , u)
        VII = βˆ₯βˆ₯-functor VI V

      IH : finite-linear-order X'
      IH = Ξ³ X' Ξ΄' n (g' , IV)

      n' : β„•
      n' = pr₁ IH

      VIII : X' ≃ Fin n'
      VIII = prβ‚‚ IH

      IX = X           β‰ƒβŸ¨ remove-and-add-isolated-point fe (f 𝟎) (Ξ΄ (f 𝟎)) ⟩
          (X' + πŸ™)     β‰ƒβŸ¨ +-cong VIII (≃-refl πŸ™) ⟩
          (Fin n' + πŸ™) β– 

Kuratowski-finite-discrete-types-are-finite : funext 𝓀 𝓀₀
                                            β†’ {X : 𝓀 Μ‡ }
                                            β†’ is-discrete X
                                            β†’ is-Kuratowski-finite X
                                            β†’ is-finite X
Kuratowski-finite-discrete-types-are-finite {𝓀} fe {X} Ξ΄ ΞΊ =
 finite'-gives-finite X (βˆ₯βˆ₯-functor (dkf-lemma fe Ξ΄) ΞΊ)


surjections-preserve-K-finiteness : {X : 𝓀 Μ‡ } {Y : π“₯ Μ‡ } (f : X β†’ Y)
                                  β†’ is-surjection f
                                  β†’ is-Kuratowski-finite X
                                  β†’ is-Kuratowski-finite Y
surjections-preserve-K-finiteness {𝓀} {π“₯} {X} {Y} f s i = j
 where
  Ξ³ : Kuratowski-data X β†’ Kuratowski-data Y
  γ (n , g , t) = n , f ∘ g , ∘-is-surjection t s

  j : is-Kuratowski-finite Y
  j = βˆ₯βˆ₯-functor Ξ³ i


total-K-finite-gives-index-type-K-finite' : (X : 𝓀 Μ‡ ) (A : X β†’ π“₯ Μ‡ )
                                          β†’ is-Kuratowski-finite (Ξ£ A)
                                          β†’ is-Kuratowski-finite (Ξ£ x κž‰ X , βˆ₯ A x βˆ₯)
total-K-finite-gives-index-type-K-finite' X A i = Ξ³
 where
  ΞΆ : (x : X) β†’ A x β†’ βˆ₯ A x βˆ₯
  ΢ x a = ∣ a ∣

  ΞΆ-is-surjection : (x : X) β†’ is-surjection (ΞΆ x)
  ΞΆ-is-surjection x = pt-is-surjection

  f : Ξ£ A β†’ Ξ£ x κž‰ X , βˆ₯ A x βˆ₯
  f = NatΞ£ ΞΆ

  f-is-surjection : is-surjection f
  f-is-surjection = NatΞ£-is-surjection A (Ξ» x β†’ βˆ₯ A x βˆ₯) ΞΆ ΞΆ-is-surjection

  Ξ³ : is-Kuratowski-finite (Ξ£ x κž‰ X , βˆ₯ A x βˆ₯)
  Ξ³ = surjections-preserve-K-finiteness f f-is-surjection i

total-K-finite-gives-index-type-K-finite : {X : 𝓀 Μ‡ } (A : X β†’ π“₯ Μ‡ )
                                         β†’ is-Kuratowski-finite (Ξ£ A)
                                         β†’ ((x : X) β†’ βˆ₯ A x βˆ₯)
                                         β†’ is-Kuratowski-finite X
total-K-finite-gives-index-type-K-finite A i s =
 surjections-preserve-K-finiteness pr₁ (pr₁-is-surjection A s) i

\end{code}

The finiteness of all Kuratowski finite types gives the discreteness of
all sets (and hence excluded middle, because the type of truth values
is a set).

\begin{code}

doubleton : {X : 𝓀 Μ‡ } β†’ X β†’ X β†’ 𝓀 Μ‡
doubleton {𝓀} {X} xβ‚€ x₁ = Ξ£ x κž‰ X , (x = xβ‚€) ∨ (x = x₁)

doubleton-is-set : {X : 𝓀 Μ‡ } (xβ‚€ x₁ : X)
                 β†’ is-set X
                 β†’ is-set (doubleton xβ‚€ x₁)
doubleton-is-set {𝓀} {X} xβ‚€ x₁ i = subsets-of-sets-are-sets
                                     X (Ξ» x β†’ (x = xβ‚€) ∨ (x = x₁)) i ∨-is-prop

doubleton-map : {X : 𝓀 Μ‡ } (xβ‚€ x₁ : X) β†’ Fin 2 β†’ doubleton xβ‚€ x₁
doubleton-map xβ‚€ x₁ 𝟎 = xβ‚€ , ∣ inl refl ∣
doubleton-map xβ‚€ x₁ 𝟏 = x₁ , ∣ inr refl ∣

doubleton-map-is-surjection : {X : 𝓀 Μ‡ } {xβ‚€ x₁ : X}
                            β†’ is-surjection (doubleton-map xβ‚€ x₁)
doubleton-map-is-surjection {𝓀} {X} {xβ‚€} {x₁} (x , s) = βˆ₯βˆ₯-functor Ξ³ s
 where
  Ξ³ : (x = xβ‚€) + (x = x₁) β†’ Ξ£ n κž‰ Fin 2 , doubleton-map xβ‚€ x₁ n = (x , s)
  Ξ³ (inl p) = 𝟎 , to-subtype-= (Ξ» _ β†’ ∨-is-prop) (p ⁻¹)
  Ξ³ (inr q) = 𝟏 , to-subtype-= (Ξ» _ β†’ ∨-is-prop) (q ⁻¹)

doubletons-are-Kuratowki-finite : {X : 𝓀 Μ‡ } (xβ‚€ x₁ : X)
                                β†’ is-Kuratowski-finite (doubleton xβ‚€ x₁)
doubletons-are-Kuratowki-finite xβ‚€ x₁ = ∣ 2 , doubleton-map xβ‚€ x₁ , doubleton-map-is-surjection ∣


decidable-equality-gives-doubleton-finite : {X : 𝓀 Μ‡ } (xβ‚€ x₁ : X)
                                          β†’ is-set X
                                          β†’ is-decidable (xβ‚€ = x₁)
                                          β†’ is-finite (doubleton xβ‚€ x₁)
decidable-equality-gives-doubleton-finite xβ‚€ x₁ X-is-set Ξ΄ = Ξ³ Ξ΄
 where
  Ξ³ : is-decidable (xβ‚€ = x₁) β†’ is-finite (doubleton xβ‚€ x₁)
  Ξ³ (inl p) = 1 , ∣ singleton-≃ m l ∣
   where
    l : is-singleton (Fin 1)
    l = 𝟎 , c
     where
      c : is-central (Fin 1) 𝟎
      c 𝟎 = refl

    m : is-singleton (doubleton xβ‚€ x₁)
    m = (doubleton-map xβ‚€ x₁ 𝟎 , c)
     where
      c : is-central (doubleton xβ‚€ x₁) (doubleton-map xβ‚€ x₁ 𝟎)
      c (y , s) = to-subtype-= (Ξ» _ β†’ ∨-is-prop) (βˆ₯βˆ₯-rec X-is-set Ξ± s)
       where
        Ξ± : (y = xβ‚€) + (y = x₁) β†’ xβ‚€ = y
        α (inl q) = q ⁻¹
        Ξ± (inr q) = p βˆ™ q ⁻¹

  Ξ³ (inr Ξ½) = 2 , ∣ ≃-sym (doubleton-map xβ‚€ x₁ , f-is-equiv) ∣
   where
    doubleton-map-lc : left-cancellable (doubleton-map xβ‚€ x₁)
    doubleton-map-lc {𝟎} {𝟎} p = refl
    doubleton-map-lc {𝟎} {𝟏} p = 𝟘-elim (Ξ½ (ap pr₁ p))
    doubleton-map-lc {𝟏} {𝟎} p = 𝟘-elim (Ξ½ (ap pr₁ (p ⁻¹)))
    doubleton-map-lc {𝟏} {𝟏} p = refl

    doubleton-map-is-embedding : is-embedding (doubleton-map xβ‚€ x₁)
    doubleton-map-is-embedding = lc-maps-into-sets-are-embeddings
                                  (doubleton-map xβ‚€ x₁)
                                  doubleton-map-lc
                                  (doubleton-is-set xβ‚€ x₁ X-is-set)

    f-is-equiv : is-equiv (doubleton-map xβ‚€ x₁)
    f-is-equiv = surjective-embeddings-are-equivs
                  (doubleton-map xβ‚€ x₁)
                  doubleton-map-is-embedding
                  doubleton-map-is-surjection

doubleton-finite-gives-decidable-equality : funext 𝓀 𝓀₀
                                          β†’ {X : 𝓀 Μ‡ } (xβ‚€ x₁ : X)
                                          β†’ is-set X
                                          β†’ is-finite (doubleton xβ‚€ x₁)
                                          β†’ is-decidable (xβ‚€ = x₁)
doubleton-finite-gives-decidable-equality fe xβ‚€ x₁ X-is-set Ο• = Ξ΄
 where
  Ξ³ : is-finite (doubleton xβ‚€ x₁) β†’ is-decidable (xβ‚€ = x₁)
  Ξ³ (0 , s) = βˆ₯βˆ₯-rec (decidability-of-prop-is-prop fe X-is-set) Ξ± s
   where
    Ξ± : doubleton xβ‚€ x₁ ≃ 𝟘 β†’ is-decidable (xβ‚€ = x₁)
    Ξ± (g , i) = 𝟘-elim (g (xβ‚€ , ∣ inl refl ∣))

  Ξ³ (1 , s) = inl (βˆ₯βˆ₯-rec X-is-set Ξ² s)
   where
    Ξ± : is-prop (Fin 1)
    α 𝟎 𝟎 = refl

    Ξ² : doubleton xβ‚€ x₁ ≃ Fin 1 β†’ xβ‚€ = x₁
    Ξ² (g , i) = ap pr₁ (equivs-are-lc g i
                         (Ξ± (g (doubleton-map xβ‚€ x₁ 𝟎))
                         (g (doubleton-map xβ‚€ x₁ 𝟏))))

  Ξ³ (succ (succ n) , s) = βˆ₯βˆ₯-rec (decidability-of-prop-is-prop fe X-is-set) f s
   where
    f : doubleton xβ‚€ x₁ ≃ Fin (succ (succ n)) β†’ is-decidable (xβ‚€ = x₁)
    f (g , i) = Ξ²
     where
      h : xβ‚€ = x₁ β†’ doubleton-map xβ‚€ x₁ 𝟎 = doubleton-map xβ‚€ x₁ 𝟏
      h = to-subtype-= (Ξ» _ β†’ ∨-is-prop)

      Ξ± : is-decidable (g (doubleton-map xβ‚€ x₁ 𝟎) = g (doubleton-map xβ‚€ x₁ 𝟏))
        β†’ is-decidable (xβ‚€ = x₁)
      Ξ± (inl p) = inl (ap pr₁ (equivs-are-lc g i p))
      Ξ± (inr Ξ½) = inr (contrapositive (Ξ» p β†’ ap g (h p)) Ξ½)

      Ξ² : is-decidable (xβ‚€ = x₁)
      Ξ² = Ξ± (Fin-is-discrete
              (g (doubleton-map xβ‚€ x₁ 𝟎))
              (g (doubleton-map xβ‚€ x₁ 𝟏)))

  Ξ΄ : is-decidable (xβ‚€ = x₁)
  Ξ΄ = Ξ³ Ο•

all-K-finite-types-finite-gives-all-sets-discrete :

    funext 𝓀 𝓀₀
  β†’ ((A : 𝓀 Μ‡ ) β†’ is-Kuratowski-finite A β†’ is-finite A)
  β†’ (X : 𝓀 Μ‡ ) β†’ is-set X β†’ is-discrete X

all-K-finite-types-finite-gives-all-sets-discrete {𝓀} fe Ο• X X-is-set xβ‚€ x₁ =
 doubleton-finite-gives-decidable-equality
  fe xβ‚€ x₁ X-is-set
  (Ο• (doubleton xβ‚€ x₁)
  (doubletons-are-Kuratowki-finite xβ‚€ x₁))

all-K-finite-types-finite-gives-EM :

    ((𝓀 : Universe) (A : 𝓀 Μ‡ ) β†’ is-Kuratowski-finite A β†’ is-finite A)
  β†’ (𝓀 : Universe) β†’ FunExt β†’ PropExt β†’ EM 𝓀
all-K-finite-types-finite-gives-EM Ο• 𝓀 fe pe =
 Ξ©-discrete-gives-EM (fe 𝓀 𝓀) (pe 𝓀)
  (all-K-finite-types-finite-gives-all-sets-discrete
    (fe (𝓀 ⁺) 𝓀₀) (Ο• (𝓀 ⁺)) (Ξ© 𝓀) (Ξ©-is-set (fe 𝓀 𝓀) (pe 𝓀)))

\end{code}

Added 13 April 2021.

Can every Kuratowski finite discrete type be equipped with a linear
order?

Recall that a type is called discrete if it has decidable equality.

Steve Vickers asks this question for the internal language of a
1-topos, and provides a counter model for it in Section 2.4 of the
following paper:

  S.J. Vickers. Strongly Algebraic = SFP (Topically). Mathematical
  Structures in Computer Science 11 (2001) pp. 717-742,
  http://dx.doi.org/10.1017/S0960129501003437
  https://www.cs.bham.ac.uk/~sjv/SFP.pdf

We here work in MLTT with propositional truncations, in Agda notation,
and instead prove that, in the presence of univalence, it is false
that every (Kuratowski) finite type with decidable equality can be
equipped with a linear order.

We also include an open problem related to this.

The following no-selection lemma is contributed by Tom de Jong:

\begin{code}

no-selection : is-univalent 𝓀₀ β†’ Β¬ ((X : 𝓀₀ Μ‡ ) β†’ βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X)
no-selection ua Ο• = Ξ³
 where
  f : {X : 𝓀₀ Μ‡ } β†’ X = 𝟚 β†’ X ≃ 𝟚
  f {X} = idtoeq X 𝟚

  n : 𝟚
  n = Ο• 𝟚 ∣ ≃-refl 𝟚 ∣

  Ξ± : {X : 𝓀₀ Μ‡ } (p : X = 𝟚) β†’ Ο• X ∣ f p ∣ =  ⌜ f p ⌝⁻¹ n
  Ξ± refl = refl

  p : 𝟚 = 𝟚
  p = eqtoid ua 𝟚 𝟚 complement-≃

  q : ∣ f refl ∣ = ∣ f p ∣
  q = βˆ₯βˆ₯-is-prop ∣ f refl ∣ ∣ f p ∣

  r : f p = complement-≃
  r = idtoeq-eqtoid ua 𝟚 𝟚 complement-≃

  s = n                     =⟨ refl ⟩
      ⌜ f refl ⌝⁻¹ n        =⟨ (α refl)⁻¹ ⟩
      Ο• 𝟚 ∣ f refl ∣        =⟨ ap (Ο• 𝟚) q ⟩
      Ο• 𝟚 ∣ f p ∣           =⟨ Ξ± p ⟩
      ⌜ f p ⌝⁻¹ n           =⟨ ap (Ξ» - β†’ ⌜ - ⌝⁻¹ n) r ⟩
      ⌜ complement-≃ ⌝⁻¹ n  =⟨ refl ⟩
      complement n          ∎

  γ : 𝟘
  Ξ³ = complement-no-fp n s


𝟚-is-Fin2 : 𝟚 ≃ Fin 2
𝟚-is-Fin2 = qinveq (𝟚-cases 𝟎 𝟏) (g , η , Ρ)
 where
  g : Fin 2 β†’ 𝟚
  g 𝟎 = β‚€
  g 𝟏 = ₁

  η : g ∘ 𝟚-cases 𝟎 𝟏 ∼ id
  Ξ· β‚€ = refl
  Ξ· ₁ = refl

  Ρ : 𝟚-cases 𝟎 𝟏 ∘ g ∼ id
  Ρ 𝟎 = refl
  Ρ 𝟏 = refl

no-orderability-of-finite-types :

 Univalence β†’ Β¬ ((X : 𝓀 Μ‡ ) β†’ is-finite X β†’ finite-linear-order X)

no-orderability-of-finite-types {𝓀} ua ψ = Ξ³
 where
  fe : FunExt
  fe = Univalence-gives-FunExt ua

  Ξ± : (X : 𝓀₀ Μ‡ ) β†’ βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X ≃ 𝟚
  Ξ± X s = VII
   where
    X' : 𝓀 Μ‡
    X' = Lift 𝓀 X

    I : X ≃ 𝟚 β†’ X' ≃ Fin 2
    I 𝕗 = X'    β‰ƒβŸ¨ Lift-≃ 𝓀 X ⟩
          X     β‰ƒβŸ¨ 𝕗 ⟩
          𝟚     β‰ƒβŸ¨ 𝟚-is-Fin2 ⟩
          Fin 2 β– 

    II : βˆ₯ X' ≃ Fin 2 βˆ₯
    II = βˆ₯βˆ₯-functor I s

    III : is-finite X'
    III = 2 , II

    IV : finite-linear-order X'
    IV = ψ X' III

    n : β„•
    n = pr₁ IV

    π•˜ : X' ≃ Fin n
    π•˜ = prβ‚‚ IV

    V : βˆ₯ X' ≃ Fin n βˆ₯ β†’ βˆ₯ X' ≃ Fin 2 βˆ₯ β†’ n = 2
    V = βˆ₯βˆ₯-recβ‚‚ β„•-is-set (Ξ» 𝕗 π•˜ β†’ Fin-lc n 2 (≃-sym 𝕗 ● π•˜))

    VI : n = 2
    VI = V ∣ π•˜ ∣ II

    VII = X     β‰ƒβŸ¨ ≃-Lift 𝓀 X ⟩
          X'    β‰ƒβŸ¨ π•˜ ⟩
          Fin n β‰ƒβŸ¨ idtoeq (Fin n) (Fin 2) (ap Fin VI) ⟩
          Fin 2 β‰ƒβŸ¨ ≃-sym 𝟚-is-Fin2 ⟩
          𝟚     β– 

  Ο• : (X : 𝓀₀ Μ‡ ) β†’ βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X
  Ο• X s = ⌜ ≃-sym (Ξ± X s) ⌝ β‚€

  γ : 𝟘
  Ξ³ = no-selection (ua 𝓀₀) Ο•

\end{code}

Because univalence is consistent, it follows that, without univalence,
the statement

  (X : 𝓀 Μ‡ ) β†’ is-finite X β†’ finite-linear-order X

is not provable.

The same holds if we replace is-finite by is-Kuratowski-finite or if
we consider Kuratowski finite discrete types.

\begin{code}

no-orderability-of-K-finite-types :

 Univalence β†’ Β¬ ((X : 𝓀 Μ‡ ) β†’ is-Kuratowski-finite X β†’ finite-linear-order X)

no-orderability-of-K-finite-types {𝓀} ua Ο• = no-orderability-of-finite-types ua ψ
 where
  ψ : (X : 𝓀 Μ‡ ) β†’ is-finite X β†’ finite-linear-order X
  ψ X i = Ο• X (finite-types-are-Kuratowski-finite i)

\end{code}

And this gives an alternative answer to the question by Steve Vickers
mentioned above:

\begin{code}

no-orderability-of-K-finite-discrete-types :

 Univalence β†’ Β¬ ((X : 𝓀 Μ‡ ) β†’ is-Kuratowski-finite X β†’ is-discrete X β†’ finite-linear-order X)

no-orderability-of-K-finite-discrete-types {𝓀} ua Ο• = no-orderability-of-finite-types ua ψ
 where
  ψ : (X : 𝓀 Μ‡ ) β†’ is-finite X β†’ finite-linear-order X
  ψ X i = Ο• X (finite-types-are-Kuratowski-finite i)
              (finite-types-are-discrete pt (Univalence-gives-FunExt ua) i)
\end{code}

TODO. Without univalence, maybe it is the case that from

  (X : 𝓀 Μ‡ ) β†’ βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X

we can deduce excluded middle or some other constructive taboo.

(It seems not. More later.)

One more notion of finiteness:

\begin{code}

is-subfinite : 𝓀 Μ‡ β†’ 𝓀 Μ‡
is-subfinite X = βˆƒ n κž‰ β„• , X β†ͺ Fin n

subfiniteness-data : 𝓀 Μ‡ β†’ 𝓀 Μ‡
subfiniteness-data X = Ξ£ n κž‰ β„• , X β†ͺ Fin n

\end{code}

Steve Vickers remarked (personal communication) that, in view of
a remark given above, if a type is simultaneously Kuratowski finite
and subfinite, then it is finite, because subfinite types, being
subtypes of types with decidable equality, have decidable equality.

\begin{code}

Kuratowski-subfinite-types-are-finite : funext 𝓀 𝓀₀
                                      β†’ {X : 𝓀 Μ‡ }
                                      β†’ is-Kuratowski-finite X
                                      β†’ is-subfinite X
                                      β†’ is-finite X
Kuratowski-subfinite-types-are-finite fe {X} k = Ξ³
 where
 Ξ΄ : subfiniteness-data X β†’ is-finite X
 Ξ΄ (n , f , e) = Kuratowski-finite-discrete-types-are-finite fe
                  (embeddings-reflect-discreteness f e Fin-is-discrete) k

 Ξ³ : is-subfinite X β†’ is-finite X
 Ξ³ = βˆ₯βˆ₯-rec (being-finite-is-prop X) Ξ΄

\end{code}

Summary of finiteness notions for a type X:

     βˆƒ n κž‰ β„• , X ≃ Fin n  (is-finite X)
     Ξ£ n κž‰ β„• , X ≃ Fin n  (finite-linear-order X)

     βˆƒ n κž‰ β„• , Fin n β†  X  (is-Kuratowski-finite X)
     Ξ£ n κž‰ β„• , Fin n β†  X  (Kuratowski-data)

     βˆƒ n κž‰ β„• , X β†ͺ Fin n  (is-subfinite)
     Ξ£ n κž‰ β„• , X β†ͺ Fin n  (subfiniteness-data)

Addendum.

\begin{code}

select-equiv-with-𝟚-lemma₁ : FunExt
                           β†’ {X : 𝓀 Μ‡ } (xβ‚€ : X)
                           β†’ is-prop (Ξ£ x₁ κž‰ X , is-equiv (𝟚-cases xβ‚€ x₁))
select-equiv-with-𝟚-lemma₁ fe {X} xβ‚€ (y , i) (z , j) = V
 where
  f g : 𝟚 β†’ X
  f = 𝟚-cases xβ‚€ y
  g = 𝟚-cases xβ‚€ z

  f' g' : X β†’ 𝟚
  f' = inverse f i
  g' = inverse g j

  I : z β‰  xβ‚€
  I p = zero-is-not-one
         (β‚€        =⟨ (inverses-are-retractions g j β‚€)⁻¹ ⟩
          g' (g β‚€) =⟨ refl ⟩
          g' xβ‚€    =⟨ ap g' (p ⁻¹) ⟩
          g' z     =⟨ refl ⟩
          g' (g ₁) =⟨ inverses-are-retractions g j ₁ ⟩
          ₁        ∎)

  II : (n : 𝟚) β†’ f n = z β†’ ₁ = n
  II β‚€ p = 𝟘-elim (I (p ⁻¹))
  II ₁ p = refl

  III : f (f' z) = z
  III = inverses-are-sections f i z

  IV : y = z
  IV = equivs-are-lc f' (inverses-are-equivs f i)
        (f' y     =⟨ refl ⟩
         f' (f ₁) =⟨ inverses-are-retractions f i ₁ ⟩
         ₁        =⟨ II (f' z) III ⟩
         f' z     ∎)

  V : (y , i) = (z , j)
  V = to-subtype-= (Ξ» x₁ β†’ being-equiv-is-prop fe (𝟚-cases xβ‚€ x₁)) IV

select-equiv-with-𝟚-lemmaβ‚‚ : FunExt
                           β†’ {X : 𝓀 Μ‡ }
                           β†’ X ≃ 𝟚
                           β†’ (xβ‚€ : X) β†’ Ξ£ x₁ κž‰ X , is-equiv (𝟚-cases xβ‚€ x₁)
select-equiv-with-𝟚-lemmaβ‚‚ fe {X} (f , i) xβ‚€ = Ξ³ (f xβ‚€) xβ‚€ refl
 where
  Ξ³ : (n : 𝟚) (xβ‚€ : X) β†’ n = f xβ‚€ β†’ Ξ£ x₁ κž‰ X , is-equiv (𝟚-cases xβ‚€ x₁)
  Ξ³ β‚€ xβ‚€ p = (x₁ , j)
   where
    x₁ : X
    x₁ = inverse f i ₁

    h : inverse f i ∼ 𝟚-cases xβ‚€ x₁
    h β‚€ = inverse f i β‚€      =⟨ ap (inverse f i) p ⟩
          inverse f i (f xβ‚€) =⟨ inverses-are-retractions f i xβ‚€ ⟩
          xβ‚€                 =⟨ refl ⟩
          𝟚-cases xβ‚€ x₁ β‚€    ∎
    h ₁ = refl

    j : is-equiv (𝟚-cases xβ‚€ x₁)
    j = equiv-closed-under-∼' (inverses-are-equivs f i) h

  Ξ³ ₁ xβ‚€ p = (x₁ , j)
   where
    x₁ : X
    x₁ = inverse f i β‚€

    h : inverse f i ∘ complement ∼ 𝟚-cases xβ‚€ x₁
    h β‚€ = inverse f i (complement β‚€) =⟨ refl ⟩
          inverse f i ₁              =⟨ ap (inverse f i) p ⟩
          inverse f i (f xβ‚€)         =⟨ inverses-are-retractions f i xβ‚€ ⟩
          xβ‚€                         =⟨ refl  ⟩
          𝟚-cases xβ‚€ x₁ β‚€            ∎
    h ₁ = refl

    j : is-equiv (𝟚-cases xβ‚€ x₁)
    j = equiv-closed-under-∼'
        (∘-is-equiv complement-is-equiv (inverses-are-equivs f i)) h

select-equiv-with-𝟚 : FunExt
                    β†’ {X : 𝓀 Μ‡ }
                    β†’ βˆ₯ X ≃ 𝟚 βˆ₯
                    β†’ X
                    β†’ X ≃ 𝟚
select-equiv-with-𝟚 fe {X} s xβ‚€ = Ξ³
 where
  Ξ± : βˆ₯ X ≃ 𝟚 βˆ₯ β†’ Ξ£ x₁ κž‰ X , is-equiv (𝟚-cases xβ‚€ x₁)
  Ξ± = βˆ₯βˆ₯-rec (select-equiv-with-𝟚-lemma₁ fe xβ‚€)
            (Ξ» 𝕙 β†’ select-equiv-with-𝟚-lemmaβ‚‚ fe 𝕙 xβ‚€)

  Ξ² : Ξ£ x₁ κž‰ X , is-equiv (𝟚-cases xβ‚€ x₁)
  Ξ² = Ξ± s

  Ξ³ : X ≃ 𝟚
  Ξ³ = ≃-sym (𝟚-cases xβ‚€ (pr₁ Ξ²) , prβ‚‚ Ξ²)

\end{code}

Hence finding an equivalence from the existence of an equivalence is
logically equivalent to finding a point from the existence of an
equivalence (exercise: moreover, these two things are typally
equivalent):

\begin{code}

select-equiv-with-𝟚-theorem : FunExt
                            β†’ {X : 𝓀 Μ‡ }
                            β†’ (βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X ≃ 𝟚)
                            ↔ (βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X)
select-equiv-with-𝟚-theorem fe {X} = α , β
 where
  Ξ± : (βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X ≃ 𝟚) β†’ βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X
  Ξ± f s = ⌜ ≃-sym (f s) ⌝ β‚€

  Ξ² : (βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X) β†’ βˆ₯ X ≃ 𝟚 βˆ₯ β†’ X ≃ 𝟚
  β g s = select-equiv-with-𝟚 fe s (g s)

\end{code}