# The universal property of truncations

```agda
module foundation-core.universal-property-truncation where
```

<details><summary>Imports</summary>

```agda
open import foundation.dependent-pair-types
open import foundation.function-extensionality
open import foundation.universal-property-equivalences
open import foundation.universe-levels

open import foundation-core.contractible-maps
open import foundation-core.contractible-types
open import foundation-core.equivalences
open import foundation-core.function-types
open import foundation-core.functoriality-dependent-pair-types
open import foundation-core.homotopies
open import foundation-core.identity-types
open import foundation-core.precomposition-functions
open import foundation-core.sections
open import foundation-core.truncated-types
open import foundation-core.truncation-levels
open import foundation-core.type-theoretic-principle-of-choice
```

</details>

## Idea

We say that a map `f : A ā†’ B` into a `k`-truncated type `B` is a
**`k`-truncation** of `A` -- or that it **satisfies the universal property of
the `k`-truncation** of `A` -- if any map `g : A ā†’ C` into a `k`-truncated type
`C` extends uniquely along `f` to a map `B ā†’ C`.

## Definition

### The condition on a map to be a truncation

```agda
precomp-Trunc :
  {l1 l2 l3 : Level} {k : š•‹} {A : UU l1} {B : UU l2} (f : A ā†’ B)
  (C : Truncated-Type l3 k) ā†’
  (B ā†’ type-Truncated-Type C) ā†’ (A ā†’ type-Truncated-Type C)
precomp-Trunc f C = precomp f (type-Truncated-Type C)

module _
  {l1 l2 : Level} {k : š•‹} {A : UU l1}
  (B : Truncated-Type l2 k) (f : A ā†’ type-Truncated-Type B)
  where

  is-truncation : UUĻ‰
  is-truncation =
    {l : Level} (C : Truncated-Type l k) ā†’ is-equiv (precomp-Trunc f C)

  equiv-is-truncation :
    {l3 : Level} (H : is-truncation) (C : Truncated-Type l3 k) ā†’
    ( type-Truncated-Type B ā†’ type-Truncated-Type C) ā‰ƒ
    ( A ā†’ type-Truncated-Type C)
  pr1 (equiv-is-truncation H C) = precomp-Trunc f C
  pr2 (equiv-is-truncation H C) = H C
```

### The universal property of truncations

```agda
module _
  {l1 l2 : Level} {k : š•‹} {A : UU l1}
  (B : Truncated-Type l2 k) (f : A ā†’ type-Truncated-Type B)
  where

  universal-property-truncation : UUĻ‰
  universal-property-truncation =
    {l : Level} (C : Truncated-Type l k) (g : A ā†’ type-Truncated-Type C) ā†’
    is-contr (Ī£ (type-hom-Truncated-Type k B C) (Ī» h ā†’ h āˆ˜ f ~ g))
```

### The dependent universal property of truncations

```agda
precomp-Ī -Truncated-Type :
  {l1 l2 l3 : Level} {k : š•‹} {A : UU l1} {B : UU l2} (f : A ā†’ B)
  (C : B ā†’ Truncated-Type l3 k) ā†’
  ((b : B) ā†’ type-Truncated-Type (C b)) ā†’
  ((a : A) ā†’ type-Truncated-Type (C (f a)))
precomp-Ī -Truncated-Type f C h a = h (f a)

module _
  {l1 l2 : Level} {k : š•‹} {A : UU l1}
  (B : Truncated-Type l2 k) (f : A ā†’ type-Truncated-Type B)
  where

  dependent-universal-property-truncation : UUĻ‰
  dependent-universal-property-truncation =
    {l : Level} (X : type-Truncated-Type B ā†’ Truncated-Type l k) ā†’
    is-equiv (precomp-Ī -Truncated-Type f X)
```

## Properties

### Equivalences into `k`-truncated types are truncations

```agda
abstract
  is-truncation-id :
    {l1 : Level} {k : š•‹} {A : UU l1} (H : is-trunc k A) ā†’
    is-truncation (A , H) id
  is-truncation-id H B =
    is-equiv-precomp-is-equiv id is-equiv-id (type-Truncated-Type B)

abstract
  is-truncation-equiv :
    {l1 l2 : Level} {k : š•‹} {A : UU l1} (B : Truncated-Type l2 k)
    (e : A ā‰ƒ type-Truncated-Type B) ā†’
    is-truncation B (map-equiv e)
  is-truncation-equiv B e C =
    is-equiv-precomp-is-equiv
      ( map-equiv e)
      ( is-equiv-map-equiv e)
      ( type-Truncated-Type C)
```

### A map into a truncated type is a truncation if and only if it satisfies the universal property of the truncation

```agda
module _
  {l1 l2 : Level} {k : š•‹} {A : UU l1} (B : Truncated-Type l2 k)
  (f : A ā†’ type-Truncated-Type B)
  where

  abstract
    is-truncation-universal-property-truncation :
      universal-property-truncation B f ā†’ is-truncation B f
    is-truncation-universal-property-truncation H C =
      is-equiv-is-contr-map
        ( Ī» g ā†’
          is-contr-equiv
            ( Ī£ (type-hom-Truncated-Type k B C) (Ī» h ā†’ (h āˆ˜ f) ~ g))
            ( equiv-tot (Ī» h ā†’ equiv-funext))
            ( H C g))

  abstract
    universal-property-truncation-is-truncation :
      is-truncation B f ā†’ universal-property-truncation B f
    universal-property-truncation-is-truncation H C g =
      is-contr-equiv'
        ( Ī£ (type-hom-Truncated-Type k B C) (Ī» h ā†’ (h āˆ˜ f) ļ¼ g))
        ( equiv-tot (Ī» h ā†’ equiv-funext))
        ( is-contr-map-is-equiv (H C) g)

  map-is-truncation :
    is-truncation B f ā†’
    {l : Level} (C : Truncated-Type l k) (g : A ā†’ type-Truncated-Type C) ā†’
    type-hom-Truncated-Type k B C
  map-is-truncation H C g =
    pr1 (center (universal-property-truncation-is-truncation H C g))

  triangle-is-truncation :
    (H : is-truncation B f) ā†’
    {l : Level} (C : Truncated-Type l k) (g : A ā†’ type-Truncated-Type C) ā†’
    map-is-truncation H C g āˆ˜ f ~ g
  triangle-is-truncation H C g =
    pr2 (center (universal-property-truncation-is-truncation H C g))
```

### A map into a truncated type is a truncation if and only if it satisfies the dependent universal property of the truncation

```agda
module _
  {l1 l2 : Level} {k : š•‹} {A : UU l1} (B : Truncated-Type l2 k)
  (f : A ā†’ type-Truncated-Type B)
  where

  abstract
    dependent-universal-property-truncation-is-truncation :
      is-truncation B f ā†’
      dependent-universal-property-truncation B f
    dependent-universal-property-truncation-is-truncation H X =
      is-fiberwise-equiv-is-equiv-map-Ī£
        ( Ī» (h : A ā†’ type-Truncated-Type B) ā†’
          (a : A) ā†’ type-Truncated-Type (X (h a)))
        ( Ī» (g : type-Truncated-Type B ā†’ type-Truncated-Type B) ā†’ g āˆ˜ f)
        ( Ī» g (s : (b : type-Truncated-Type B) ā†’
          type-Truncated-Type (X (g b))) (a : A) ā†’ s (f a))
        ( H B)
        ( is-equiv-equiv
          ( inv-distributive-Ī -Ī£)
          ( inv-distributive-Ī -Ī£)
          ( ind-Ī£ (Ī» g s ā†’ refl))
          ( H (Ī£-Truncated-Type B X)))
        ( id)

  abstract
    is-truncation-dependent-universal-property-truncation :
      dependent-universal-property-truncation B f ā†’ is-truncation B f
    is-truncation-dependent-universal-property-truncation H X = H (Ī» _ ā†’ X)

  section-is-truncation :
    is-truncation B f ā†’
    {l3 : Level} (C : Truncated-Type l3 k)
    (h : A ā†’ type-Truncated-Type C) (g : type-hom-Truncated-Type k C B) ā†’
    f ~ g āˆ˜ h ā†’ section g
  section-is-truncation H C h g K =
    map-distributive-Ī -Ī£
      ( map-inv-is-equiv
        ( dependent-universal-property-truncation-is-truncation H
          ( fiber-Truncated-Type C B g))
        ( Ī» a ā†’ (h a , inv (K a))))
```