indexsource

open import 1Lab.Prelude hiding (∥_∥³; ∥-∥³-elim-set; ∥-∥³-elim-prop; ∥-∥³-rec; ∥-∥³-is-prop; ∥-∥-rec-groupoid)
open import 1Lab.Path.Reasoning

-- Coherently constant maps into groupoids, now at https://1lab.dev/1Lab.HIT.Truncation.html#maps-into-groupoids
module CoherentlyConstant where

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 ∥³

∥-∥³-elim-set
  :  { ℓ'} {A : Type } {P :  A ∥³  Type ℓ'}
   (∀ a  is-set (P a))
   (f : (a : A)  P (inc a))
   (∀ a b  PathP  i  P (iconst a b i)) (f a) (f b))
    a  P a
∥-∥³-elim-set {P = P} sets f fconst = go where
  go :  a  P a
  go (inc x) = f x
  go (iconst a b i) = fconst a b i
  go (icoh a b c i j) = is-set→squarep  i j  sets (icoh a b c i j))
    refl  i  go (iconst a b i))  i  go (iconst a c i))  i  go (iconst b c i))
    i j
  go (squash a b p q r s i j k) = is-hlevel→is-hlevel-dep 2  _  is-hlevel-suc 2 (sets _))
    (go a) (go b)
     k  go (p k))  k  go (q k))
     j k  go (r j k))  j k  go (s j k))
    (squash a b p q r s) i j k

∥-∥³-elim-prop
  :  { ℓ'} {A : Type } {P :  A ∥³  Type ℓ'}
   (∀ a  is-prop (P a))
   (f : (a : A)  P (inc a))
    a  P a
∥-∥³-elim-prop props f = ∥-∥³-elim-set  _  is-hlevel-suc 1 (props _)) f
   _ _  is-prop→pathp  _  props _) _ _)

∥-∥³-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

∥-∥³-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)))

∥-∥-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