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 equaivalence. 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 is exactly what is required to prove J for the relation $R$. This is essentially the decomposition of J into contractibility of singletons, but with singletons replaced by $R$-singletons.

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


If we have a relation $R$ together with reflexivity witness $r$, then any equivalence $f : R(a, b) \simeq (a \equiv b)$ which maps $f(r) = \id{refl}$ equips $(R, r)$ with the structure of an identity system. Of course if we do not particularly care about the specific reflexivity witness, we can simply define $r$ as $f^{-1}(\id{refl})$.

equiv-path→identity-system
: ∀ {ℓ ℓ′} {A : Type ℓ} {R : A → A → Type ℓ′} {r : ∀ a → R a a}
→ (eqv : ∀ {a b} → R a b ≃ (a ≡ b))
→ (∀ a → Equiv.from eqv refl ≡ r a)
→ is-identity-system R r
equiv-path→identity-system {R = R} {r = r} eqv pres′ = ids where
contract : ∀ {a} → is-contr (Σ _ (R a))
contract = is-hlevel≃ 0 ((total (λ _ → eqv .fst) , equiv→total (eqv .snd)))
(contr _ Singleton-is-contr)

pres : ∀ {a} → eqv .fst (r a) ≡ refl
pres {a = a} = Equiv.injective₂ (eqv e⁻¹) (Equiv.η eqv _) (pres′ _)

ids : is-identity-system R r
ids .to-path = eqv .fst
ids .to-path-over {a = a} {b = b} p i =
is-prop→pathp
(λ i → is-contr→is-prop (eqv .snd .is-eqv λ j → eqv .fst p (i ∧ j)))
(r a , pres)
(p , refl)
i .fst


Note that for any $(R, r)$, the type of identity sytem data on $(R, r)$ is a proposition. This is because it is exactly equivalent to the type $\sum_a (R a)$ being contractible for every $a$, which is a proposition by standard results.

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 ids {a = a} =
ids .to-path {a = a}
, total→equiv {f = λ x → ids .to-path {a = a} {b = x}}
(is-contr→is-equiv (is-contr-ΣR ids) (contr _ Singleton-is-contr))


## In subtypes🔗

Let $f : A \mono B$ be an embedding. If $(R, r)$ is an identity system on $B$, then it can be pulled back along $f$ to an identity system on $A$.

module
_ {ℓ ℓ′ ℓ′′} {A : Type ℓ} {B : Type ℓ′}
{R : B → B → Type ℓ′′} {r : ∀ a → R a a}
(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 _)


## 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 $(R, r)$ on a type $A$ is that, if $R$ is pointwise an $n$-type, then $A$ is an $(n+1)$-type. Now, if $R$ is a reflexive family of propositions, then all we need for $(R, r)$ to be an identity system is that $R(x, y) \to x = y$, by the previous observation, this implies $A$ 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 $A$ 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.

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

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)