Martin Escardo. Notes originally written for the module Advanced Functional Programming of the University of Birmingham, UK.

Isomorphism of Fin n with a Basic MLTT type

Fin' :   Type
Fin' 0       = 𝟘
Fin' (suc n) = 𝟙  Fin' n

zero' : {n : }  Fin' (suc n)
zero' = inl 

suc'  : {n : }  Fin' n  Fin' (suc n)
suc' = inr

open import Fin
open import isomorphisms

Fin-isomorphism : (n : )  Fin n  Fin' n
Fin-isomorphism n = record { bijection = f n ; bijectivity = f-is-bijection n }
 where
  f : (n : )  Fin n  Fin' n
  f (suc n) zero    = zero'
  f (suc n) (suc k) = suc' (f n k)

  g : (n : )  Fin' n  Fin n
  g (suc n) (inl ) = zero
  g (suc n) (inr k) = suc (g n k)

  gf : (n : )  g n  f n  id
  gf (suc n) zero    = refl zero
  gf (suc n) (suc k) = γ
   where
    IH : g n (f n k)  k
    IH = gf n k

    γ = g (suc n) (f (suc n) (suc k)) ≡⟨ refl _ 
        g (suc n) (suc' (f n k))      ≡⟨ refl _ 
        suc (g n (f n k))             ≡⟨ ap suc IH 
        suc k                         

  fg : (n : )  f n  g n  id
  fg (suc n) (inl ) = refl (inl )
  fg (suc n) (inr k) = γ
   where
    IH : f n (g n k)  k
    IH = fg n k

    γ = f (suc n) (g (suc n) (suc' k)) ≡⟨ refl _ 
        f (suc n) (suc (g n k))        ≡⟨ refl _ 
        suc' (f n (g n k))             ≡⟨ ap suc' IH 
        suc' k                         

  f-is-bijection : (n : )  is-bijection (f n)
  f-is-bijection n = record { inverse = g n ; η = gf n ; ε = fg n}

Exercise. Show that the type Fin n is isomorphic to the type Σ k : ℕ , k < n.

Go back to the table of contents