module 1Lab.Path.IdentitySystem where

Identity systemsπŸ”—

An identity system is a way of characterising the path spaces of a particular type, without necessarily having to construct a full encode-decode equivalence. Essentially, the data of an identity system is precisely the data required to implement path induction, a.k.a. the J eliminator. Any type with the data of an identity system satisfies its own J, and conversely, if the type satisfies J, it is an identity system.

We unravel the definition of being an identity system into the following data, using a translation that takes advantage of cubical type theory’s native support for paths-over-paths:

record
  is-identity-system {β„“ β„“'} {A : Type β„“}
    (R : A β†’ A β†’ Type β„“')
    (refl : βˆ€ a β†’ R a a)
    : Type (β„“ βŠ” β„“')
  where
  no-eta-equality
  field
    to-path      : βˆ€ {a b} β†’ R a b β†’ a ≑ b
    to-path-over
      : βˆ€ {a b} (p : R a b)
      β†’ PathP (Ξ» i β†’ R a (to-path p i)) (refl a) p

  is-contr-Ξ£R : βˆ€ {a} β†’ is-contr (Ξ£ A (R a))
  is-contr-Ξ£R .centre    = _ , refl _
  is-contr-Ξ£R .paths x i = to-path (x .snd) i , to-path-over (x .snd) i

open is-identity-system public

As mentioned before, the data of an identity system gives us exactly what is required to prove J for the relation This is essentially the decomposition of J into contractibility of singletons, but with singletons replaced by

IdsJ
  : βˆ€ {β„“ β„“' β„“''} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a} {a : A}
  β†’ is-identity-system R r
  β†’ (P : βˆ€ b β†’ R a b β†’ Type β„“'')
  β†’ P a (r a)
  β†’ βˆ€ {b} s β†’ P b s
IdsJ ids P pr s =
  transport (Ξ» i β†’ P (ids .to-path s i) (ids .to-path-over s i)) pr
IdsJ-refl
  : βˆ€ {β„“ β„“' β„“''} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a} {a : A}
  β†’ (ids : is-identity-system R r)
  β†’ (P : βˆ€ b β†’ R a b β†’ Type β„“'')
  β†’ (x : P a (r a))
  β†’ IdsJ ids P x (r a) ≑ x
IdsJ-refl {R = R} {r = r} {a = a} ids P x =
  transport (Ξ» i β†’ P (ids .to-path (r a) i) (ids .to-path-over (r a) i)) x β‰‘βŸ¨βŸ©
  subst P' (Ξ» i β†’ ids .to-path (r a) i , ids .to-path-over (r a) i) x      β‰‘βŸ¨ ap (Ξ» e β†’ subst P' e x) lemma βŸ©β‰‘
  subst P' refl x                                                          β‰‘βŸ¨ transport-refl x βŸ©β‰‘
  x ∎
  where
    P' : Ξ£ _ (R a) β†’ Type _
    P' (b , r) = P b r

    lemma : Ξ£-pathp (ids .to-path (r a)) (ids .to-path-over (r a)) ≑ refl
    lemma = is-contr→is-set (is-contr-ΣR ids) _ _ _ _

to-path-refl-coh
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a}
  β†’ (ids : is-identity-system R r)
  β†’ βˆ€ a
  β†’ (Ξ£-pathp (ids .to-path (r a)) (ids .to-path-over (r a))) ≑ refl
to-path-refl-coh {r = r} ids a =
  is-contr→is-set (is-contr-ΣR ids) _ _
    (Ξ£-pathp (ids .to-path (r a)) (ids .to-path-over (r a)))
    refl

to-path-refl
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a} {a : A}
  β†’ (ids : is-identity-system R r)
  β†’ ids .to-path (r a) ≑ refl
to-path-refl {r = r} {a = a} ids = ap (ap fst) $ to-path-refl-coh ids a

to-path-over-refl
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a} {a : A}
  β†’ (ids : is-identity-system R r)
  β†’ PathP (Ξ» i β†’ PathP (Ξ» j β†’ R a (to-path-refl {a = a} ids i j)) (r a) (r a))
      (ids .to-path-over (r a))
      refl
to-path-over-refl {a = a} ids = ap (ap snd) $ to-path-refl-coh ids a

Note that for any the type of identity system data on is a proposition. This is because it is exactly equivalent to the type being contractible for every which is a proposition by standard results.

contr→identity-system
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a}
  β†’ (βˆ€ {a} β†’ is-contr (Ξ£ _ (R a)))
  β†’ is-identity-system R r
contr→identity-system {R = R} {r} c = ids where
  paths' : βˆ€ {a} (p : Ξ£ _ (R a)) β†’ (a , r a) ≑ p
  paths' _ = is-contr→is-prop c _ _

  ids : is-identity-system R r
  ids .to-path p = ap fst (paths' (_ , p))
  ids .to-path-over p = ap snd (paths' (_ , p))

If we have a relation together with reflexivity witness then any equivalence equips with the structure of an identity system, by contractibility of singletons. Of course if we do not particularly care about the specific reflexivity witness, we can simply define as

equiv-path→identity-system
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a}
  β†’ (βˆ€ {a b} β†’ R a b ≃ (a ≑ b))
  β†’ is-identity-system R r
equiv-path→identity-system eqv = contr→identity-system $
  Equiv→is-hlevel 0 ((total (λ _ → eqv .fst) , equiv→total (eqv .snd)))
    (contr _ Singleton-is-contr)

Conversely, any identity system implies an equivalence

identity-system-gives-path
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a}
  β†’ is-identity-system R r
  β†’ βˆ€ {a b} β†’ R a b ≃ (a ≑ b)
identity-system-gives-path {R = R} {r = r} ids =
  Iso→Equiv (ids .to-path , iso from ri li) where
    from : βˆ€ {a b} β†’ a ≑ b β†’ R a b
    from {a = a} p = transport (Ξ» i β†’ R a (p i)) (r a)

    ri : βˆ€ {a b} β†’ is-right-inverse (from {a} {b}) (ids .to-path)
    ri = J (Ξ» y p β†’ ids .to-path (from p) ≑ p)
           ( ap (ids .to-path) (transport-refl _)
           βˆ™ to-path-refl ids)

    li : βˆ€ {a b} β†’ is-left-inverse (from {a} {b}) (ids .to-path)
    li = IdsJ ids (Ξ» y p β†’ from (ids .to-path p) ≑ p)
          ( ap from (to-path-refl ids)
          βˆ™ transport-refl _ )

In subtypesπŸ”—

Let be an embedding. If is an identity system on then it can be pulled back along to an identity system on

module
  _ {β„“ β„“' β„“''} {A : Type β„“} {B : Type β„“'}
    {R : B β†’ B β†’ Type β„“''} {r : βˆ€ b β†’ R b b}
    (ids : is-identity-system R r)
    (f : A β†ͺ B)
  where

  pullback-identity-system
    : is-identity-system (Ξ» x y β†’ R (f .fst x) (f .fst y)) (Ξ» _ β†’ r _)
  pullback-identity-system .to-path {a} {b} x = ap fst $
    f .snd (f .fst b) (a , ids .to-path x) (b , refl)
  pullback-identity-system .to-path-over {a} {b} p i =
    comp
      (Ξ» j β†’ R (f .fst a) (f .snd (f .fst b) (a , ids .to-path p) (b , refl) i .snd (~ j)))
      (βˆ‚ i) Ξ» where
      k (k = i0) β†’ ids .to-path-over p (~ k)
      k (i = i0) β†’ ids .to-path-over p (~ k ∨ i)
      k (i = i1) β†’ p

This is actually part of an equivalence: if the equality identity system on (thus any identity system) can be pulled back along then is an embedding.

identity-system→embedding
  : βˆ€ {β„“ β„“'} {A : Type β„“} {B : Type β„“'}
  β†’ (f : A β†’ B)
  β†’ is-identity-system (Ξ» x y β†’ f x ≑ f y) (Ξ» _ β†’ refl)
  β†’ is-embedding f
identity-system→embedding f ids = cancellable→embedding
  (identity-system-gives-path ids)

UnivalenceπŸ”—

Note that univalence is precisely the statement that equivalences are an identity system on the universe:

univalence-identity-system
  : βˆ€ {β„“} β†’ is-identity-system {A = Type β„“} _≃_ Ξ» _ β†’ id , id-equiv
univalence-identity-system .to-path = ua
univalence-identity-system .to-path-over p =
  Σ-prop-pathp (λ _ → is-equiv-is-prop) $ funextP $ λ a → path→ua-pathp p refl
Path-identity-system
  : βˆ€ {β„“} {A : Type β„“} β†’ is-identity-system (Path A) (Ξ» _ β†’ refl)
Path-identity-system .to-path p = p
Path-identity-system .to-path-over p i j = p (i ∧ j)

is-identity-system-is-prop
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a}
  β†’ is-prop (is-identity-system R r)
is-identity-system-is-prop {A = A} {R} {r} =
  retract→is-hlevel 1 from to cancel λ x y i a → is-contr-is-prop (x a) (y a) i
  where
    to : is-identity-system R r β†’ βˆ€ x β†’ is-contr (Ξ£ A (R x))
    to ids x = is-contr-Ξ£R ids

    from : (βˆ€ x β†’ is-contr (Ξ£ A (R x))) β†’ is-identity-system R r
    from x = contr→identity-system (x _)

    cancel'
      : βˆ€ (x : is-identity-system R r) {a b} (s : R a b)
      β†’ PathP (Ξ» i β†’ (a , r a) ≑ (b , s))
        (is-contr-Ξ£R (from (to x)) .paths (b , s))
        (is-contr-Ξ£R x .paths (b , s))
    cancel' x s = is-prop→squarep (λ _ _ → is-contr→is-prop (is-contr-ΣR x)) _ _ _ _

    cancel : is-left-inverse from to
    cancel x i .to-path s = ap fst (cancel' x s i)
    cancel x i .to-path-over s = ap snd (cancel' x s i)

instance
  H-Level-is-identity-system
    : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ a β†’ R a a} {n}
    β†’ H-Level (is-identity-system R r) (suc n)
  H-Level-is-identity-system = prop-instance is-identity-system-is-prop

identity-system→hlevel
  : βˆ€ {β„“ β„“'} {A : Type β„“} n {R : A β†’ A β†’ Type β„“'} {r : βˆ€ x β†’ R x x}
  β†’ is-identity-system R r
  β†’ (βˆ€ x y β†’ is-hlevel (R x y) n)
  β†’ is-hlevel A (suc n)
identity-system→hlevel zero ids hl x y = ids .to-path (hl _ _ .centre)
identity-system→hlevel (suc n) ids hl x y =
  Equivβ†’is-hlevel (suc n) (identity-system-gives-path ids e⁻¹) (hl x y)

Sets and Hedberg’s theoremπŸ”—

We now apply the general theory of identity systems to something a lot more mundane: recognising sets. An immediate consequence of having an identity system on a type is that, if is pointwise an then is an Now, if is a reflexive family of propositions, then all we need for to be an identity system is that by the previous observation, this implies is a set.

set-identity-system
  : βˆ€ {β„“ β„“'} {A : Type β„“} {R : A β†’ A β†’ Type β„“'} {r : βˆ€ x β†’ R x x}
  β†’ (βˆ€ x y β†’ is-prop (R x y))
  β†’ (βˆ€ {x y} β†’ R x y β†’ x ≑ y)
  β†’ is-identity-system R r
set-identity-system rprop rpath .to-path = rpath
set-identity-system rprop rpath .to-path-over p =
  is-prop→pathp (λ i → rprop _ _) _ p

If is a type with ¬¬-stable equality, then by the theorem above, the pointwise double negation of its identity types is an identity system: and so, if a type has decidable (thus ¬¬-stable) equality, it is a set. This is known as Hedberg’s theorem.

¬¬-stable-identity-system
  : βˆ€ {β„“} {A : Type β„“}
  β†’ (βˆ€ {x y} β†’ Β¬ Β¬ Path A x y β†’ x ≑ y)
  β†’ is-identity-system (Ξ» x y β†’ Β¬ Β¬ Path A x y) Ξ» a k β†’ k refl
¬¬-stable-identity-system = set-identity-system Ξ» x y f g β†’
  funext Ξ» h β†’ absurd (g h)

opaque
  Discreteβ†’is-set : βˆ€ {β„“} {A : Type β„“} β†’ Discrete A β†’ is-set A
  Discrete→is-set {A = A} dec =
    identity-systemβ†’hlevel 1 (¬¬-stable-identity-system stable) Ξ» x y f g β†’
      funext Ξ» h β†’ absurd (g h)
    where
      stable : {x y : A} β†’ Β¬ Β¬ x ≑ y β†’ x ≑ y
      stable {x = x} {y = y} ¬¬p with dec {x} {y}
      ... | yes p = p
      ... | no ¬p = absurd (¬¬p ¬p)