open import 1Lab.HLevel.Retracts
open import 1Lab.Type.Sigma
open import 1Lab.HLevel
open import 1Lab.Equiv
open import 1Lab.Path
open import 1Lab.Type

module 1Lab.HIT.Truncation where

Propositional Truncation🔗

Let AA be a type. The propositional truncation of AA is a type which represents the proposition “A is inhabited”. In MLTT, propositional truncations can not be constructed without postulates, even in the presence of impredicative prop. However, Cubical Agda provides a tool to define them: higher inductive types.

data ∥_∥ {} (A : Type ) : Type  where
  inc    : A   A 
  squash : is-prop  A 

The two constructors that generate ∥_∥ state precisely that the truncation is inhabited when A is (inc), and that it is a proposition (squash).

is-prop-∥-∥ :  {} {A : Type }  is-prop  A 
is-prop-∥-∥ = squash

The eliminator for ∥_∥ says that you can eliminate onto PP whenever it is a family of propositions, by providing a case for inc.

∥-∥-elim :  { ℓ'} {A : Type }
             {P :  A   Type ℓ'}
          ((x : _)  is-prop (P x))
          ((x : A)  P (inc x))
          (x :  A )  P x
∥-∥-elim pprop incc (inc x) = incc x
∥-∥-elim pprop incc (squash x y i) =
  is-prop→pathp  j  pprop (squash x y j)) (∥-∥-elim pprop incc x)
                                             (∥-∥-elim pprop incc y)
                                             i

The propositional truncation can be called the free proposition on a type, because it satisfies the universal property that a left adjoint would have. Specifically, let B be a proposition. We have:

∥-∥-univ :  {} {A : Type } {B : Type }
          is-prop B  ( A   B)  (A  B)
∥-∥-univ {A = A} {B = B} bprop = Iso→Equiv (inc' , iso rec  _  refl) beta) where
  inc' : (x :  A   B)  A  B
  inc' f x = f (inc x)

  rec : (f : A  B)   A   B
  rec f (inc x) = f x
  rec f (squash x y i) = bprop (rec f x) (rec f y) i

  beta : _
  beta f = funext (∥-∥-elim  _  is-prop→is-set bprop _ _)  _  refl))

Furthermore, as required of a free construction, the propositional truncation extends to a functor:

∥-∥-map :  { ℓ'} {A : Type } {B : Type ℓ'}
         (A  B)   A    B 
∥-∥-map f (inc x)        = inc (f x)
∥-∥-map f (squash x y i) = squash (∥-∥-map f x) (∥-∥-map f y) i

Using the propositional truncation, we can define the existential quantifier as a truncated Σ.

 :  {a b} (A : Type a) (B : A  Type b)  Type _
 A B =  Σ B 

syntax  A  x  B) = ∃[ x  A ] B

Note that if PP is already a proposition, then truncating it does nothing:

is-prop→equiv∥-∥ :  {} {P : Type }  is-prop P  P   P 
is-prop→equiv∥-∥ pprop = prop-ext pprop squash inc (∥-∥-elim  x  pprop) λ x  x)

In fact, an alternative definition of is-prop is given by “being equivalent to your own truncation”:

is-prop≃equiv∥-∥ :  {} {P : Type }
                is-prop P  (P   P )
is-prop≃equiv∥-∥ {P = P} =
  prop-ext is-prop-is-prop eqv-prop is-prop→equiv∥-∥ inv
  where
    inv : (P   P )  is-prop P
    inv eqv = equiv→is-hlevel 1 ((eqv e⁻¹) .fst) ((eqv e⁻¹) .snd) squash

    eqv-prop : is-prop (P   P )
    eqv-prop x y = Σ-path  i p  squash (x .fst p) (y .fst p) i)
                          (is-equiv-is-prop _ _ _)

Maps into Sets🔗

The elimination principle for A\| A \| says that we can only use the AA inside in a way that doesn’t matter: the motive of elimination must be a family of propositions, so our use of AA must not matter in a very strong sense. Often, it’s useful to relax this requirement slightly: Can we map out of A\| A \| using a constant function?

The answer is yes! However, the witness of constancy we use must be very coherent indeed. In particular, we need enough coherence on top of a family of paths (x y:A)fxBfy(x\ y : A) \to f x \equiv_B f y to ensure that the image of ff is a proposition; Then we can map from Aim(f)B\| A \| \to \id{im}(f) \to B.

From the discussion in 1Lab.Counterexamples.Sigma, we know the definition of image, or more properly of (1)(-1)-image:

image :  { ℓ'} {A : Type } {B : Type ℓ'}  (A  B)  Type _
image {A = A} {B = B} f = Σ[ b  B ] ∃[ a  A ] (f a  b)

To see that the image indeed implements the concept of image, we define a way to factor any map through its image. By the definition of image, we have that the map f-image is always surjective, and since is a family of props, the first projection out of image is an embedding. Thus we factor a map ff as Aimage(f)BA \epi \id{image}(f) \mono B.

f-image
  :  { ℓ'} {A : Type } {B : Type ℓ'}
   (f : A  B)  A  image f
f-image f x = f x , inc (x , refl)

We now prove the theorem that will let us map out of a propositional truncation using a constant function into sets: if BB is a set, and f:ABf : A \to B is a constant function, then image(f)\id{image}(f) is a proposition.

is-constant→image-is-prop
  :  { ℓ'} {A : Type } {B : Type ℓ'}
   is-set B
   (f : A  B)  (∀ x y  f x  f y)  is-prop (image f)

This is intuitively true (if the function is constant, then there is at most one thing in the image!), but formalising it turns out to be slightly tricky, and the requirement that BB be a set is perhaps unexpected.

A sketch of the proof is as follows. Suppose that we have some (a,x)(a, x) and (b,y)(b, y) in the image. We know, morally, that xx (respectively yy) give us some f(a):Af^*(a) : A and p:f(fa)=ap : f(f^*a) = a (resp q:f(f(b))=bq : f(f^*(b)) = b) — which would establish that aba \equiv b, as we need, since we have a=f(f(a))=f(f(b))=ba = f(f^*(a)) = f(f^*(b)) = b, where the middle equation is by constancy of ff — but crucially, the

is-constant→image-is-prop bset f f-const (a , x) (b , y) =
  Σ-prop-path  _  squash)
    (∥-∥-elim₂  _ _  bset _ _)
       { (f*a , p) (f*b , q)  sym p ·· f-const f*a f*b ·· q }) x y)

Using the image factorisation, we can project from a propositional truncation onto a set using a constant map.

∥-∥-rec-set :  { ℓ'} {A : Type } {B : Type ℓ'}
             (f : A  B)
             (∀ x y  f x  f y)
             is-set B
              A   B
∥-∥-rec-set {A = A} {B} f f-const bset x =
  ∥-∥-elim {P = λ _  image f}
     _  is-constant→image-is-prop bset f f-const) (f-image f) x .fst