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
∥-∥-elim₂ : ∀ {ℓ ℓ₁ ℓ₂} {A : Type ℓ} {B : Type ℓ₁}
              {P : ∥ A ∥ → ∥ B ∥ → Type ℓ₂}
          → (∀ x y → is-prop (P x y))
          → (∀ x y → P (inc x) (inc y))
          → ∀ x y → P x y
∥-∥-elim₂ {A = A} {B} {P} pprop work x y = go x y where
  go : ∀ x y → P x y
  go (inc x) (inc x₁) = work x x₁
  go (inc x) (squash y y₁ i) =
    is-prop→pathp (λ i → pprop (inc x) (squash y y₁ i))
                  (go (inc x) y) (go (inc x) y₁) i

  go (squash x x₁ i) z =
    is-prop→pathp (λ i → pprop (squash x x₁ i) z)
                  (go x z) (go x₁ z) i

∥-∥-rec : ∀ {ℓ ℓ'} {A : Type ℓ} {P : Type ℓ'}
         → is-prop P
         → (A → P)
         → (x : ∥ A ∥) → P
∥-∥-rec pprop = ∥-∥-elim (λ _ → pprop)

∥-∥-proj : ∀ {ℓ} {A : Type ℓ} → is-prop A → ∥ A ∥ → A
∥-∥-proj ap = ∥-∥-rec ap λ x → x

∥-∥-rec₂ : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ''} {P : Type ℓ'}
         → is-prop P
         → (A → B → P)
         → (x : ∥ A ∥) (y : ∥ B ∥) → P
∥-∥-rec₂ pprop = ∥-∥-elim₂ (λ _ _ → pprop)

∥-∥-rec!
  : ∀ {ℓ ℓ'} {A : Type ℓ} {P : Type ℓ'}
  → {@(tactic hlevel-tactic-worker) pprop : is-prop P}
  → (A → P)
  → (x : ∥ A ∥) → P
∥-∥-rec! {pprop = pprop} = ∥-∥-elim (λ _ → pprop)

∥-∥-proj! : ∀ {ℓ} {A : Type ℓ} → {@(tactic hlevel-tactic-worker) ap : is-prop A} → ∥ A ∥ → A
∥-∥-proj! {ap = ap} = ∥-∥-proj ap

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 = ∥ Σ A 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 (∥-∥-proj pprop)

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 _ _ _)

Throughout the 1Lab, we use the words “mere” and “merely” to modify a type to mean its propositional truncation. This terminology is adopted from the HoTT book. For example, a type XX is said merely equivalent to YY if the type ∥X≡Y∥\| X \equiv Y \| is inhabited.

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, provided we’re mapping into a set! In that case, the image of ff is a proposition, so that we can map from ∥A∥→im⁡f→B\| A \| \to \operatorname*{im}f \to B. In the next section, we’ll see a more general method for mapping into types that aren’t sets.

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 A↠im⁡f↪BA \twoheadrightarrow \operatorname*{im}f \hookrightarrow 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:A→Bf : A \to B is a constant function, then im⁡f\operatorname*{im}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(f∗a)=ap : f(f^*a) = a (resp q:f(f∗(b))=bq : f(f^*(b)) = b) — which would establish that a≡ba \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 pp and qq are hidden under propositional truncations, so we crucially need to use the fact that BB is a set so that a=ba = b is a proposition.

is-constant→image-is-prop bset f fconst (a , x) (b , y) =
  Σ-prop-path (λ _ → squash)
    (∥-∥-elim₂ (λ _ _ → bset _ _)
      (λ { (f*a , p) (f*b , q) → sym p ·· fconst 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 ℓ'}
            → is-set B
            → (f : A → B)
            → (∀ x y → f x ≡ f y)
            → ∥ A ∥ → B
∥-∥-rec-set {A = A} {B} bset f fconst x =
  ∥-∥-elim {P = λ _ → image f}
    (λ _ → is-constant→image-is-prop bset f fconst) (f-image f) x .fst

Maps into groupoids🔗

We can push this idea further: as discussed in (Kraus 2015), in general, functions ∥A∥→B\| A \| \to B are equivalent to coherently constant functions A→BA \to B. This involves an infinite tower of conditions, each relating to the previous one, which isn’t something we can easily formulate in the language of type theory.

However, when BB is an nn-type, it is enough to ask for the first nn levels of the tower. In the case of sets, we’ve seen that the naïve notion of constancy is enough. We now deal with the case of groupoids, which requires an additional step: we ask for a function f:A→Bf : A \to B equipped with a witness of constancy constx,y:fx≡fy\mathrm{const}_{x,y} : f x \equiv f y and a coherence cohx,y,z:constx,y∙consty,z≡constx,z\mathrm{coh}_{x,y,z} : \mathrm{const}_{x,y} \bullet \mathrm{const}_{y,z} \equiv \mathrm{const}_{x,z}.

This time, we cannot hope to show that the image of ff is a proposition: the image of a map ⊤→S1\top \to S^1 is S1S^1. Instead, we use the following higher inductive type, which can be thought of as the “codiscrete groupoid” on AA:

data ∥_∥³ {ℓ} (A : Type ℓ) : Type ℓ where
  inc : A → ∥ A ∥³
  iconst : ∀ a b → inc a ≡ inc b
  icoh : ∀ a b c → PathP (λ i → inc a ≡ iconst b c i) (iconst a b) (iconst a c)
  squash : is-groupoid ∥ A ∥³

The recursion principle for this type says exactly that any coherently constant function into a groupoid factors through ∥A∥3\| A \|^3!

∥-∥³-rec
  : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
  → is-groupoid B
  → (f : A → B)
  → (fconst : ∀ x y → f x ≡ f y)
  → (∀ x y z → fconst x y ∙ fconst y z ≡ fconst x z)
  → ∥ A ∥³ → B
∥-∥³-rec {A = A} {B} bgrpd f fconst fcoh = go where
  go : ∥ A ∥³ → B
  go (inc x) = f x
  go (iconst a b i) = fconst a b i
  go (icoh a b c i j) = ∙→square (sym (fcoh a b c)) i j
  go (squash x y a b p q i j k) = bgrpd
    (go x) (go y)
    (λ i → go (a i)) (λ i → go (b i))
    (λ i j → go (p i j)) (λ i j → go (q i j))
    i j k

All that remains to show is that ∥A∥3\| A \|^3 is a proposition1, which mainly requires writing more elimination principles.

∥-∥³-is-prop : ∀ {ℓ} {A : Type ℓ} → is-prop ∥ A ∥³
∥-∥³-is-prop = is-contr-if-inhabited→is-prop $
  ∥-∥³-elim-prop (λ _ → hlevel 1)
    (λ a → contr (inc a) (∥-∥³-elim-set (λ _ → squash _ _) (iconst a) (icoh a)))

Hence we get the desired recursion principle for the usual propositional truncation.

∥-∥-rec-groupoid
  : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
  → is-groupoid B
  → (f : A → B)
  → (fconst : ∀ x y → f x ≡ f y)
  → (∀ x y z → fconst x y ∙ fconst y z ≡ fconst x z)
  → ∥ A ∥ → B
∥-∥-rec-groupoid bgrpd f fconst fcoh =
  ∥-∥³-rec bgrpd f fconst fcoh ∘ ∥-∥-rec ∥-∥³-is-prop inc
As we hinted at above, this method generalises (externally) to nn-types; we sketch the details of the next level for the curious reader.

The next coherence involves a tetrahedron all of whose faces are coh\mathrm{coh}, or, since we’re doing cubical type theory, a “cubical tetrahedron”:

data ∥_∥⁴ {ℓ} (A : Type ℓ) : Type ℓ where
  inc : A → ∥ A ∥⁴
  iconst : ∀ a b → inc a ≡ inc b
  icoh : ∀ a b c → PathP (λ i → inc a ≡ iconst b c i) (iconst a b) (iconst a c)
  iassoc : ∀ a b c d → PathP (λ i → PathP (λ j → inc a ≡ icoh b c d i j)
                                          (iconst a b) (icoh a c d i))
                             (icoh a b c) (icoh a b d)
  squash : is-hlevel ∥ A ∥⁴ 4

∥-∥⁴-rec
  : ∀ {ℓ} {A : Type ℓ} {ℓ'} {B : Type ℓ'}
  → is-hlevel B 4
  → (f : A → B)
  → (fconst : ∀ a b → f a ≡ f b)
  → (fcoh : ∀ a b c → PathP (λ i → f a ≡ fconst b c i) (fconst a b) (fconst a c))
  → (∀ a b c d → PathP (λ i → PathP (λ j → f a ≡ fcoh b c d i j)
                                    (fconst a b) (fcoh a c d i))
                       (fcoh a b c) (fcoh a b d))
  → ∥ A ∥⁴ → B
unquoteDef ∥-∥⁴-rec = make-rec-n 4 ∥-∥⁴-rec (quote ∥_∥⁴)

  1. in fact, it’s even a propositional truncation of AA, in that it satisfies the same universal property as ∥A∥\| A \|↩︎


References