Martin Escardo, 16th August 2023, with more improvements 18th June 2025.
Injectivity of types of mathematical structures, such as pointed
types, โ-magmas, magmas, monoids, groups etc.
We give a sufficient condition for types of mathematical structures to
be injective, and we apply it to examples such as the above.
This file improves InjectiveTypes.MathematicalStructuresOriginal at
the cost of perhaps being harder to understand, but with the benefit
of at the same time being more general and allowing shorter proofs in
applications. It relies on the file InjectiveTypes.Sigma, which also
arises as a generalization of the above original file.
\begin{code}
{-# OPTIONS --safe --without-K --lossy-unification #-}
import InjectiveTypes.MathematicalStructuresOriginal
open import UF.Univalence
\end{code}
We assume univalence (and hence function extensionality, which,
follows from it), but no other HoTT/UF extensions, not even
propositional truncations.
\begin{code}
module InjectiveTypes.MathematicalStructures
(ua : Univalence)
where
open import UF.FunExt
open import UF.UA-FunExt
private
fe : FunExt
fe = Univalence-gives-FunExt ua
fe' : Fun-Ext
fe' {๐ค} {๐ฅ} = fe ๐ค ๐ฅ
open import InjectiveTypes.Blackboard fe
open import InjectiveTypes.Sigma fe
open import MLTT.Spartan
open import Taboos.Decomposability fe
open import UF.Base
open import UF.Equiv
open import UF.ClassicalLogic
open import UF.PropIndexedPiSigma
open import UF.Retracts
open import UF.Sets
open import UF.Sets-Properties
open import UF.SubtypeClassifier
\end{code}
It is convenient to work with the following definition of (algebraic)
flabbiness of a universe, which uses equivalence of types rather than
equality.
\begin{code}
Flabby : (๐ค : Universe) โ ๐ค โบ ฬ
Flabby ๐ค = ฮฃ โจ ๊ ((p : ฮฉ ๐ค) โ (p holds โ ๐ค ฬ ) โ ๐ค ฬ )
, ((p : ฮฉ ๐ค) (A : p holds โ ๐ค ฬ) (h : p holds) โ โจ p A โ A h)
\end{code}
In the presence of univalence we can convert to the usual definition,
and we can always convert in the other direction, but in this file we
need the first one only.
\begin{code}
to-aflabby : Flabby ๐ค โ aflabby (๐ค ฬ ) ๐ค
to-aflabby {๐ค} (โจ , e) P i A =
โจ (P , i) A , (ฮป h โ eqtoid (ua ๐ค) _ _ (e (P , i) A h))
from-afabbly : aflabby (๐ค ฬ ) ๐ค โ Flabby ๐ค
from-afabbly {๐ค} aflab =
aflabby-extension aflab ,
(ฮป p A h โ idtoeq _ _ (aflabby-extension-property aflab p A h))
\end{code}
We already know that universes are flabby in two ways, using โจ := ฮ
and โจ := ฮฃ, but we give constructions that they are Flabby without
univalence, and hence have better computational behaviour, which will
simplify the applications we have in mind.
If the index type is a proposition, then the projection out of a
ฮ -type is an equivalence.
\begin{code}
ฮ -๐ก๐ฃ๐ ๐ : (p : ฮฉ ๐ค) {A : p holds โ ๐ค ฬ } (h : p holds)
โ ฮ A โ A h
ฮ -๐ก๐ฃ๐ ๐ p h = ฮ -proj h , ฮ -proj-is-equiv h fe' (holds-is-prop p)
universes-are-Flabby-ฮ : Flabby ๐ค
universes-are-Flabby-ฮ = (ฮป p A โ ฮ A) ,
(ฮป p A โ ฮ -๐ก๐ฃ๐ ๐ p)
universes-are-flabby-ฮ : aflabby (๐ค ฬ) ๐ค
universes-are-flabby-ฮ = to-aflabby universes-are-Flabby-ฮ
ฮฃ-๐๐ : (p : ฮฉ ๐ค) {A : p holds โ ๐ค ฬ } (h : p holds)
โ A h โ ฮฃ A
ฮฃ-๐๐ p h = ฮฃ-in h , ฮฃ-in-is-equiv h (holds-is-prop p)
universes-are-Flabby-ฮฃ : Flabby ๐ค
universes-are-Flabby-ฮฃ = (ฮป p A โ ฮฃ A) ,
(ฮป p A h โ โ-sym (ฮฃ-๐๐ p h))
universes-are-flabby-ฮฃ : aflabby (๐ค ฬ) ๐ค
universes-are-flabby-ฮฃ = to-aflabby universes-are-Flabby-ฮฃ
\end{code}
In this file we apply the above constructions only for the case of ฮ ,
but we include those for ฮฃ for the sake illustration (and perhaps for
future use).
We now work with an arbitrary notion S of structure on ๐ค. E.g. for
monoids we will take S X := X โ X โ X, the type of the multiplication
operation.
\begin{code}
module _ (S : ๐ค ฬ โ ๐ฅ ฬ ) where
\end{code}
By the results of InjectiveTypes.Sigma, we get that ฮฃ S is aflabby in
two ways, assuming the compatibility condition for the flabbiness
data.
\begin{code}
module _ (ฯ : aflabby (๐ค ฬ ) ๐ค) where
aflabbiness-of-type-of-structured-types : compatibility-data S ฯ
โ aflabby (ฮฃ S) ๐ค
aflabbiness-of-type-of-structured-types = ฮฃ-is-aflabby S ฯ
ainjectivity-of-type-of-structures : compatibility-data S ฯ
โ ainjective-type (ฮฃ S) ๐ค ๐ค
ainjectivity-of-type-of-structures = aflabby-types-are-ainjective (ฮฃ S)
โ aflabbiness-of-type-of-structured-types
\end{code}
We will apply this to get our desired examples with ฯ taken to be the
above canonical ฮ -flabby structure on the universe.
Next we want to simplify working with compatibility data (as defined
in the module InjectiveTypes.Sigma), where we avoid transports by
working with the following function treq and suitable choices of T and
T-refl in the examples below. Notice that the definition of treq uses
univalence. The point of T and T-refl below is that they won't use
univalence in our examples of interest, so that they will have a
better computational behaviour than treq.
\begin{code}
treq : {X Y : ๐ค ฬ } โ X โ Y โ S X โ S Y
treq {X} {Y} ๐ = transport S (eqtoid (ua ๐ค) X Y ๐)
\end{code}
The main additional work in this file on top of InjectiveTypes.Sigma
is to make it easier to work with the compatibility condition for the
purpose of injectivity of types of mathematical structures.
We work with hypothetical T and T-refl with the following types.
\begin{code}
module _ (T : {X Y : ๐ค ฬ } โ X โ Y โ S X โ S Y)
(T-refl : {X : ๐ค ฬ } โ T (โ-refl X) โผ id)
where
\end{code}
The point is that any such T can be equivalently expressed as a
transport and hence we may apply the theorems of the imported file
InjectiveTypes.Sigma, but it may be easier to check the compatibility
condition using T rather than transport (see examples below).
\begin{code}
T-is-treq : {X Y : ๐ค ฬ } (๐ : X โ Y)
โ T ๐ โผ treq ๐
T-is-treq {X} {Y} ๐ s = JEq (ua ๐ค) X A I Y ๐
where
A : (Y : ๐ค ฬ ) (๐ : X โ Y) โ ๐ฅ ฬ
A Y ๐ = T ๐ s ๏ผ treq ๐ s
I : A X (โ-refl X)
I = T (โ-refl X) s ๏ผโจ T-refl s โฉ
s ๏ผโจ refl โฉ
transport S refl s ๏ผโจ II โฉ
transport S (eqtoid (ua ๐ค) X X (โ-refl X)) s ๏ผโจ refl โฉ
treq (โ-refl X) s โ
where
II = (ap (ฮป - โ transport S - s) (eqtoid-refl (ua ๐ค) X))โปยน
\end{code}
In order to be able to apply the results of InjectiveTypes.Sigma, we
perform the following construction. That file requires compatibility
data of a certain kind, which we reduce to compatibility of another
kind, which will be easier to produce in our sample applications.
\begin{code}
module compatibility-data-construction (ฯ@(โจ , ฮต) : Flabby ๐ค) where
derived-ฯ : (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
โ S (โจ p A) โ ((h : p holds) โ S (A h))
derived-ฯ p A s h = T (ฮต p A h) s
compatibility-data-for-derived-ฯ : ๐ค โบ โ ๐ฅ ฬ
compatibility-data-for-derived-ฯ = (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
โ has-section (derived-ฯ p A)
construction : compatibility-data-for-derived-ฯ
โ compatibility-data S (to-aflabby ฯ)
construction t p A = III
where
II : derived-ฯ p A โผ ฯ S (to-aflabby ฯ) p A
II s =
derived-ฯ p A s ๏ผโจ refl โฉ
(ฮป h โ T (ฮต p A h) s) ๏ผโจ Iโ โฉ
(ฮป h โ treq (ฮต p A h) s) ๏ผโจ refl โฉ
(ฮป h โ transport S (eqtoid (ua ๐ค) _ _ (ฮต p A h)) s) ๏ผโจ refl โฉ
ฯ S (to-aflabby ฯ) p A s โ
where
Iโ = dfunext fe' (ฮป h โ T-is-treq (ฮต p A h) s)
III : has-section (ฯ S (to-aflabby ฯ) p A)
III = has-section-closed-under-โผ (derived-ฯ p A) _ (t p A) (โผ-sym II)
\end{code}
This completes the construction, but we record that the section map of
the above construction is literally the same as that of the
hypothesis t.
\begin{code}
_ = section-map (ฯ S (to-aflabby ฯ) p A) III ๏ผโจ refl โฉ
section-map (derived-ฯ p A) (t p A) โ
\end{code}
What is necessarily different is the proof that this map is a
section. In fact, it is different in the strong sense that the
comparison for equality doesn't even make sense - it wouldn't even
typecheck.
A way to verify this in Agda is to try to supply the following naive
definition.
construction' : compatibility-data-for-derived-ฯ
โ compatibility-data S (to-aflabby ฯ)
construction' t = t -- Doesn't type check (of course).
We can sensibly have only that the *section map* of the construction
agrees with the given section map, which is what we have already
observed in the above proof, but record again with full type
information, outside the above proof.
\begin{code}
construction-fact : (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ)
(t : compatibility-data-for-derived-ฯ)
โ section-map (ฯ S (to-aflabby ฯ) p A) (construction t p A)
๏ผ section-map (derived-ฯ p A) (t p A)
construction-fact p A t = refl
\end{code}
This fact about the construction will be rather useful in practice,
for the applications we have in mind.
We can specialize this to the ฮ and ฮฃ flabbiness structures discussed
above, to get the following.
\begin{code}
module _ where
open compatibility-data-construction universes-are-Flabby-ฮ
ฯฮ : (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
โ S (ฮ A) โ ((h : p holds) โ S (A h))
ฯฮ = derived-ฯ
compatibility-data-ฮ : ๐ค โบ โ ๐ฅ ฬ
compatibility-data-ฮ = (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
โ has-section (ฯฮ p A)
ฮ -construction : compatibility-data-ฮ
โ compatibility-data S universes-are-flabby-ฮ
ฮ -construction = construction
\end{code}
We use the following definitional equality a number of times (and we
try to record this explicitly when we do so).
\begin{code}
_ : ฯฮ ๏ผ ฮป p A s h โ T (ฮ -๐ก๐ฃ๐ ๐ p h) s
_ = refl
\end{code}
For our examples below, we only need the above functions ฯฮ ,
compatibility-data-ฮ and ฮ -construction, but we take the opportunity
to remark that we also have the following, with ฮ replaced by ฮฃ (for
which we don't have any application so far).
\begin{code}
module _ where
open compatibility-data-construction universes-are-Flabby-ฮฃ
ฯฮฃ : (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
โ S (ฮฃ A) โ ((h : p holds) โ S (A h))
ฯฮฃ = derived-ฯ
compatibility-data-ฮฃ : ๐ค โบ โ ๐ฅ ฬ
compatibility-data-ฮฃ = (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
โ has-section (ฯฮฃ p A)
ฮฃ-construction : compatibility-data-ฮฃ
โ compatibility-data S universes-are-flabby-ฮฃ
ฮฃ-construction = construction
\end{code}
Example. The type of pointed types is algebraically injective. We use
the ฮ -flabbiness of the universe.
\begin{code}
Pointed-type : (๐ค : Universe) โ ๐ค โบ ฬ
Pointed-type ๐ค = ฮฃ X ๊ ๐ค ฬ , X
Pointed : ๐ค ฬ โ ๐ค ฬ
Pointed X = X
Pointed-ฮ -data : compatibility-data (Pointed {๐ค}) universes-are-flabby-ฮ
Pointed-ฮ -data {๐ค} = ฮ -construction Pointed T T-refl c
where
S = Pointed
T : {X Y : ๐ค ฬ } โ (X โ Y) โ X โ Y
T = โ_โ
T-refl : {X : ๐ค ฬ } โ T (โ-refl X) โผ id
T-refl x = refl
_ : (p : ฮฉ ๐ค) (A : p holds โ ๐ค ฬ) โ ฯฮ S T T-refl p A ๏ผ ๐๐ (S (ฮ A))
_ = ฮป p A โ refl
c : compatibility-data-ฮ S T T-refl
c p A = equivs-have-sections id (id-is-equiv (ฮ A))
\end{code}
Hence we conclude that the type of pointed types is ainjective.
\begin{code}
ainjectivity-of-type-of-pointed-types : ainjective-type (Pointed-type ๐ค) ๐ค ๐ค
ainjectivity-of-type-of-pointed-types =
ainjectivity-of-type-of-structures
Pointed
universes-are-flabby-ฮ
Pointed-ฮ -data
\end{code}
Example. The type of โ-magmas is algebraically injective. The proof is
an entirely routine application of the above general theorem after we
guess what T should be.
\begin{code}
โ-Magma : (๐ค : Universe) โ ๐ค โบ ฬ
โ-Magma ๐ค = ฮฃ X ๊ ๐ค ฬ , (X โ X โ X)
โ-magma-structure : ๐ค ฬ โ ๐ค ฬ
โ-magma-structure = ฮป X โ X โ X โ X
โ-Magma-structure-ฮ -data : compatibility-data
(โ-magma-structure {๐ค})
universes-are-flabby-ฮ
โ-Magma-structure-ฮ -data {๐ค} =
ฮ -construction S T T-refl ฯฮ -has-section
where
S = โ-magma-structure
T : {X Y : ๐ค ฬ } โ (X โ Y) โ S X โ S Y
T ๐ _ยท_ = ฮป y y' โ โ ๐ โ (โ ๐ โโปยน y ยท โ ๐ โโปยน y')
T-refl : {X : ๐ค ฬ } โ T (โ-refl X) โผ id
T-refl _ยท_ = refl
module _ (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
where
ฯ : (h : p holds) โ ฮ A โ A h
ฯ = ฮ -๐ก๐ฃ๐ ๐ p
r : S (ฮ A) โ ((h : p holds) โ S (A h))
r _ยท_ h a b = โ ฯ h โ (โ ฯ h โโปยน a ยท โ ฯ h โโปยน b)
_ : r ๏ผ ฯฮ S T T-refl p A
_ = refl
ฯ : ((h : p holds) โ S (A h)) โ S (ฮ A)
ฯ g ฮฑ ฮฒ h = g h (โ ฯ h โ ฮฑ) (โ ฯ h โ ฮฒ)
rฯ : r โ ฯ โผ id
rฯ g =
r (ฯ g) ๏ผโจ refl โฉ
(ฮป h a b โ g h (โ ฯ h โ (โ ฯ h โโปยน a)) (โ ฯ h โ (โ ฯ h โโปยน b))) ๏ผโจ II โฉ
(ฮป h a b โ g h a b) ๏ผโจ refl โฉ
g โ
where
II = dfunext fe' (ฮป h โ
dfunext fe' (ฮป a โ
dfunext fe' (ฮป b โ
apโ (g h)
(inverses-are-sections' (ฯ h) a)
(inverses-are-sections' (ฯ h) b))))
ฯฮ -has-section : has-section (ฯฮ S T T-refl p A)
ฯฮ -has-section = ฯ , rฯ
ainjectivity-of-โ-Magma : ainjective-type (โ-Magma ๐ค) ๐ค ๐ค
ainjectivity-of-โ-Magma =
ainjectivity-of-type-of-structures
โ-magma-structure
universes-are-flabby-ฮ
โ-Magma-structure-ฮ -data
\end{code}
A corollary is that the type โ-Magma ๐ค doesn't have any non-trivial
decidable property unless weak excluded middle holds.
\begin{code}
decomposition-of-โ-Magma-gives-WEM : decomposition (โ-Magma ๐ค) โ typal-WEM ๐ค
decomposition-of-โ-Magma-gives-WEM {๐ค} =
decomposition-of-ainjective-type-gives-WEM
(univalence-gives-propext (ua ๐ค))
(โ-Magma ๐ค)
ainjectivity-of-โ-Magma
\end{code}
The same is true for the type of pointed types, of course, and for any
injective type.
Example. The type of pointed โ-magmas is injective.
\begin{code}
open import UF.SIP-Examples
open monoid
โ-Magmaโ : (๐ค : Universe) โ ๐ค โบ ฬ
โ-Magmaโ ๐ค = ฮฃ X ๊ ๐ค ฬ , (X โ X โ X) ร X
โ-Magmaโ-structure : ๐ค ฬ โ ๐ค ฬ
โ-Magmaโ-structure = monoid-structure
โ-Magmaโ-structure-ฮ -data : compatibility-data
(โ-Magmaโ-structure {๐ค})
universes-are-flabby-ฮ
โ-Magmaโ-structure-ฮ -data =
compatibility-data-ร
universes-are-flabby-ฮ
โ-Magma-structure-ฮ -data
Pointed-ฮ -data
ainjectivity-of-โ-Magmaโ : ainjective-type (โ-Magmaโ ๐ค) ๐ค ๐ค
ainjectivity-of-โ-Magmaโ =
ainjectivity-of-type-of-structures
โ-Magmaโ-structure
universes-are-flabby-ฮ
โ-Magmaโ-structure-ฮ -data
\end{code}
Example. The type of monoids is injective. We just have to check that
the monoid axioms are closed under ฮ .
\begin{code}
Monoid-ฮ -data : compatibility-data {๐ค โบ}
(ฮป X โ ฮฃ s ๊ monoid-structure X , monoid-axioms X s)
universes-are-flabby-ฮ
Monoid-ฮ -data {๐ค} =
compatibility-data-with-axioms
universes-are-flabby-ฮ
monoid-structure
โ-Magmaโ-structure-ฮ -data
monoid-axioms
(monoid-axioms-is-prop fe')
axioms-ฮ -data
where
ฯ : (p : ฮฉ ๐ค) (A : p holds โ ๐ค ฬ )
โ ((h : p holds) โ monoid-structure (A h)) โ monoid-structure (ฮ A)
ฯ p A = section-map
(ฯ monoid-structure universes-are-flabby-ฮ p A)
(โ-Magmaโ-structure-ฮ -data p A)
axioms-ฮ -data
: (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
(ฮฑ : (h : p holds) โ monoid-structure (A h))
(F : (h : p holds) โ monoid-axioms (A h) (ฮฑ h))
โ monoid-axioms (ฮ A) (ฯ p A ฮฑ)
axioms-ฮ -data p A ฮฑ F = I , II , III , IV
where
_*_ : {h : p holds} โ A h โ A h โ A h
_*_ {h} = prโ (ฮฑ h)
_ยท_ : ฮ A โ ฮ A โ ฮ A
f ยท g = ฮป h โ f h * g h
e : ฮ A
e h = prโ (ฮฑ h)
_ : ฯ p A ฮฑ ๏ผ (_ยท_ , e)
_ = refl
I : is-set (ฮ A)
I = ฮ -is-set fe' (ฮป h โ
case F h of
ฮป (Ah-is-set , ln , rn , assoc) โ Ah-is-set)
II : left-neutral e _ยท_
II f = dfunext fe' (ฮป h โ
case F h of
ฮป (Ah-is-set , ln , rn , assoc) โ ln (f h))
III : right-neutral e _ยท_
III g = dfunext fe' (ฮป h โ
case F h of
ฮป (Ah-is-set , ln , rn , assoc) โ rn (g h))
IV : associative _ยท_
IV f g k = dfunext fe' (ฮป h โ
case F h of
ฮป (Ah-is-set , ln , rn , assoc) โ assoc (f h) (g h) (k h))
ainjectivity-of-Monoid : ainjective-type (Monoid {๐ค}) ๐ค ๐ค
ainjectivity-of-Monoid {๐ค} =
ainjectivity-of-type-of-structures
(ฮป X โ ฮฃ s ๊ monoid-structure X , monoid-axioms X s)
universes-are-flabby-ฮ
Monoid-ฮ -data
\end{code}
It is easy to add further axioms to monoids to get groups, and then
show that the type of groups is injective using the above
technique. This is just as routine as the example of monoids. All one
needs to do is to show that the group axioms are closed under
prop-indexed products.
TODO. Maybe implement this.
NB. The type Ordinal ๐ค of well-ordered sets in ๐ค is also injective,
but for different reasons, two of them given in two different modules.
Added 20th June 2025. The type of all families in a universe is
injective.
\begin{code}
Fam : (๐ค : Universe) โ ๐ค โบ ฬ
Fam ๐ค = ฮฃ X ๊ ๐ค ฬ , (X โ ๐ค ฬ)
Fam-structure : ๐ค ฬ โ ๐ค โบ ฬ
Fam-structure {๐ค} X = X โ ๐ค ฬ
open import UF.EquivalenceExamples
open import UF.Subsingletons
Fam-ฮ -data : compatibility-data (Fam-structure {๐ค}) universes-are-flabby-ฮ
Fam-ฮ -data {๐ค} = ฮ -construction Fam-structure T T-refl c
where
S = Fam-structure
T : {X Y : ๐ค ฬ} โ X โ Y โ (X โ ๐ฃ ฬ ) โ (Y โ ๐ฃ ฬ )
T ๐ R = ฮป y โ R (โ ๐ โโปยน y)
T-refl : {X : ๐ค ฬ} โ T (โ-refl X) โผ id
T-refl R = refl
module _ (p : ฮฉ ๐ค) (A : p holds โ ๐ค ฬ) where
r : S (ฮ A) โ ((h : p holds) โ S (A h))
r s h a = s (โ ฮ -๐ก๐ฃ๐ ๐ p h โโปยน a)
_ : ฯฮ S T T-refl p A ๏ผ r
_ = refl
ฯ : ((h : p holds) โ S (A h)) โ S (ฮ A)
ฯ g f = (h : p holds) โ g h (f h)
rฯ : r โ ฯ โผ id
rฯ g = dfunext fe' (ฮป h โ dfunext fe' (II h))
where
module _ (h : p holds) (a : A h) where
ฯ : ฮ A โ A h
ฯ = ฮ -๐ก๐ฃ๐ ๐ p h
I = ((h' : p holds) โ g h' (โ ฯ โโปยน a h')) โโจ Iโ โฉ
(p holds โ g h (โ ฯ โโปยน a h)) โโจ Iโ โฉ
(๐ โ g h (โ ฯ โโปยน a h)) โโจ Iโ โฉ
g h (โ ฯ โโปยน a h) โ
where
Iโ = ฮ -cong fe' fe'
(ฮป h' โ transport (ฮป - โ g - (โ ฯ โโปยน a -))
(holds-is-prop p h' h) ,
transports-are-equivs (holds-is-prop p h' h))
Iโ = ฮ -change-of-variable-โ {๐ค} {๐ค} fe
(ฮป _ โ g h (โ ฯ โโปยน a h))
(logically-equivalent-props-are-equivalent
(holds-is-prop p) ๐-is-prop unique-to-๐ (ฮป _ โ h))
Iโ = โ-sym (๐โ fe')
II = r (ฯ g) h a ๏ผโจ refl โฉ
ฯ g (โ ฯ โโปยน a) ๏ผโจ refl โฉ
((h' : p holds) โ g h' (โ ฯ โโปยน a h')) ๏ผโจ IIโ โฉ
g h (โ ฯ โโปยน a h) ๏ผโจ refl โฉ
g h (โ ฯ โ (โ ฯ โโปยน a)) ๏ผโจ IIโ โฉ
g h a โ
where
IIโ = eqtoid (ua ๐ค) _ _ I
IIโ = ap (g h) (inverses-are-sections' ฯ a)
c : compatibility-data-ฮ Fam-structure T T-refl
c p A = ฯ p A , rฯ p A
ainjectivity-of-Fam : ainjective-type (Fam ๐ค) ๐ค ๐ค
ainjectivity-of-Fam =
ainjectivity-of-type-of-structures
Fam-structure
universes-are-flabby-ฮ
Fam-ฮ -data
\end{code}
A corollary is that the type of all functions in a universe is injective.
\begin{code}
open import UF.Classifiers
ainjectivity-of-type-of-all-functions
: ainjective-type (ฮฃ X ๊ ๐ค ฬ , ฮฃ Y ๊ ๐ค ฬ , (X โ Y)) ๐ค ๐ค
ainjectivity-of-type-of-all-functions {๐ค}
= transport
(ฮป - โ ainjective-type - ๐ค ๐ค)
(eqtoid (ua (๐ค โบ)) _ _ (โ-sym I))
ainjectivity-of-Fam
where
open classifier-single-universe ๐ค
I = (ฮฃ X ๊ ๐ค ฬ , ฮฃ Y ๊ ๐ค ฬ , (X โ Y)) โโจ ฮฃ-flip โฉ
(ฮฃ Y ๊ ๐ค ฬ , ฮฃ X ๊ ๐ค ฬ , (X โ Y)) โโจ ฮฃ-cong (classification (ua ๐ค) fe') โฉ
(ฮฃ Y ๊ ๐ค ฬ , (Y โ ๐ค ฬ)) โโจ โ-refl _ โฉ
Fam ๐ค โ
\end{code}
The type of all type-valued relations, or multigraphs, in a universe
is injective. The proof is the binary version of the above unary proof.
\begin{code}
Graph : (๐ค : Universe) โ ๐ค โบ ฬ
Graph ๐ค = ฮฃ X ๊ ๐ค ฬ , (X โ X โ ๐ค ฬ)
graph-structure : ๐ค ฬ โ ๐ค โบ ฬ
graph-structure {๐ค} X = X โ X โ ๐ค ฬ
open import UF.EquivalenceExamples
open import UF.Subsingletons
Graph-ฮ -data : compatibility-data (graph-structure {๐ค}) universes-are-flabby-ฮ
Graph-ฮ -data {๐ค} =
ฮ -construction graph-structure T T-refl c
where
S = graph-structure
T : {X Y : ๐ค ฬ} โ X โ Y โ (X โ X โ ๐ฃ ฬ ) โ (Y โ Y โ ๐ฃ ฬ )
T ๐ R y y' = R (โ ๐ โโปยน y) (โ ๐ โโปยน y')
T-refl : {X : ๐ค ฬ} โ T (โ-refl X) โผ id
T-refl R = refl
module _ (p : ฮฉ ๐ค) (A : p holds โ ๐ค ฬ) where
r : S (ฮ A) โ ((h : p holds) โ S (A h))
r s h a a' = s (โ ฮ -๐ก๐ฃ๐ ๐ p h โโปยน a) (โ ฮ -๐ก๐ฃ๐ ๐ p h โโปยน a')
_ : r ๏ผ ฯฮ S T T-refl p A
_ = refl
ฯ : ((h : p holds) โ S (A h)) โ S (ฮ A)
ฯ g f f' = (h : p holds) โ g h (f h) (f' h)
rฯ : r โ ฯ โผ id
rฯ g = dfunext fe' (ฮป h โ
dfunext fe' (ฮป a โ
dfunext fe' (ฮป a' โ II h a a')))
where
module _ (h : p holds) (a a' : A h) where
ฯ : ฮ A โ A h
ฯ = ฮ -๐ก๐ฃ๐ ๐ p h
I = ((h' : p holds) โ g h' (โ ฯ โโปยน a h') (โ ฯ โโปยน a' h')) โโจ Iโ โฉ
(p holds โ g h (โ ฯ โโปยน a h) (โ ฯ โโปยน a' h)) โโจ Iโ โฉ
(๐ โ g h (โ ฯ โโปยน a h) (โ ฯ โโปยน a' h)) โโจ Iโ โฉ
g h (โ ฯ โโปยน a h) (โ ฯ โโปยน a' h) โ
where
Iโ = ฮ -cong fe' fe'
(ฮป h' โ transport (ฮป - โ g - (โ ฯ โโปยน a -) (โ ฯ โโปยน a' -))
(holds-is-prop p h' h) ,
transports-are-equivs (holds-is-prop p h' h))
Iโ = ฮ -change-of-variable-โ {๐ค} {๐ค} fe
(ฮป _ โ g h (โ ฯ โโปยน a h) (โ ฯ โโปยน a' h))
(logically-equivalent-props-are-equivalent
(holds-is-prop p) ๐-is-prop unique-to-๐ (ฮป _ โ h))
Iโ = โ-sym (๐โ fe')
II = r (ฯ g) h a a' ๏ผโจ refl โฉ
ฯ g (โ ฯ โโปยน a) (โ ฯ โโปยน a') ๏ผโจ refl โฉ
((h' : p holds) โ g h' (โ ฯ โโปยน a h') (โ ฯ โโปยน a' h')) ๏ผโจ IIโ โฉ
g h (โ ฯ โโปยน a h) (โ ฯ โโปยน a' h) ๏ผโจ refl โฉ
g h (โ ฯ โ (โ ฯ โโปยน a)) (โ ฯ โ (โ ฯ โโปยน a')) ๏ผโจ IIโ โฉ
g h a a' โ
where
IIโ = eqtoid (ua ๐ค) _ _ I
IIโ = apโ (g h)
(inverses-are-sections' ฯ a)
(inverses-are-sections' ฯ a')
c : compatibility-data-ฮ graph-structure T T-refl
c p A = ฯ p A , rฯ p A
ainjectivity-of-Graph : ainjective-type (Graph ๐ค) ๐ค ๐ค
ainjectivity-of-Graph =
ainjectivity-of-type-of-structures
graph-structure
universes-are-flabby-ฮ
Graph-ฮ -data
\end{code}
As a consequence, we get the injectivity of the type of posets.
\begin{code}
poset-axioms : (X : ๐ค ฬ ) โ graph-structure X โ ๐ค ฬ
poset-axioms X _โค_ = is-set X
ร ((x y : X) โ is-prop (x โค y))
ร reflexive _โค_
ร transitive _โค_
ร antisymmetric _โค_
Poset : (๐ค : Universe) โ ๐ค โบ ฬ
Poset ๐ค = ฮฃ X ๊ ๐ค ฬ , ฮฃ s ๊ graph-structure X , poset-axioms X s
open import UF.Subsingletons-FunExt
poset-axioms-is-prop : (X : ๐ค ฬ ) (s : graph-structure X)
โ is-prop (poset-axioms X s)
poset-axioms-is-prop X _โค_ = prop-criterion I
where
I : poset-axioms X _โค_ โ is-prop (poset-axioms X _โค_)
I (s , pv , r , t , a) =
รโ
-is-prop
(being-set-is-prop fe')
(ฮ โ-is-prop fe' (ฮป x y โ being-prop-is-prop fe'))
(ฮ -is-prop fe' (ฮป x โ pv x x))
(ฮ โ
-is-prop fe' (ฮป x _ z _ _ โ pv x z))
(ฮ โ-is-prop fe' (ฮป _ _ _ _ โ s))
Poset-ฮ -data : compatibility-data {๐ค โบ}
(ฮป X โ ฮฃ s ๊ graph-structure X , poset-axioms X s)
universes-are-flabby-ฮ
Poset-ฮ -data {๐ค} =
compatibility-data-with-axioms
universes-are-flabby-ฮ
graph-structure
Graph-ฮ -data
poset-axioms
poset-axioms-is-prop
axioms-ฮ -data
where
ฯ : (p : ฮฉ ๐ค) (A : p holds โ ๐ค ฬ )
โ ((h : p holds) โ graph-structure (A h)) โ graph-structure (ฮ A)
ฯ p A = section-map
(ฯ graph-structure universes-are-flabby-ฮ p A)
(Graph-ฮ -data p A)
axioms-ฮ -data
: (p : ฮฉ ๐ค)
(A : p holds โ ๐ค ฬ )
(ฮฑ : (h : p holds) โ graph-structure (A h))
(F : (h : p holds) โ poset-axioms (A h) (ฮฑ h))
โ poset-axioms (ฮ A) (ฯ p A ฮฑ)
axioms-ฮ -data p A ฮฑ F = I , II , III , IV , V
where
_โ_ : {h : p holds} โ A h โ A h โ ๐ค ฬ
_โ_ {h} = ฮฑ h
_โค_ : ฮ A โ ฮ A โ ๐ค ฬ
f โค g = (h : p holds) โ f h โ g h
_ : ฯ p A ฮฑ ๏ผ _โค_
_ = refl
I : is-set (ฮ A)
I = ฮ -is-set fe' (ฮป h โ
case F h of
ฮป (s , pv , r , t , a) โ s)
II : (f g : ฮ A) โ is-prop (f โค g)
II f g = ฮ -is-prop fe' (ฮป h โ
case F h of
ฮป (s , pv , r , t , a) โ pv (f h) (g h))
III : reflexive _โค_
III f h =
case F h of
ฮป (s , pv , r , t , a) โ r (f h)
IV : transitive _โค_
IV fโ fโ fโ l m h =
case F h of
ฮป (s , pv , r , t , a) โ t (fโ h) (fโ h) (fโ h) (l h) (m h)
V : antisymmetric _โค_
V fโ fโ l m = dfunext fe' (ฮป h โ
case F h of
ฮป (s , pv , r , t , a) โ a (fโ h) (fโ h) (l h) (m h))
ainjectivity-of-Poset : ainjective-type (Poset ๐ค) ๐ค ๐ค
ainjectivity-of-Poset {๐ค} =
ainjectivity-of-type-of-structures
(ฮป X โ ฮฃ s ๊ graph-structure X , poset-axioms X s)
universes-are-flabby-ฮ
Poset-ฮ -data
\end{code}
Notice that, just as in the case for monoids, the proof amounts to
showing that posets are closed under prop-indexed products. Using the
same idea, it is straightforward to show that the types of dcpos,
continuous dcpos, suplattices, frames etc. are all injective. (Notice
that this is different from e.g. saying that the underlying type of a
dcpos is injective, which is also true and is proved in another
module.)
TODO. Maybe implement (some of) these examples.
TODO. More techniques are needed to show that the type of 1-categories
would be injective. A category can be seen as a graph equipped with
operations (identity and composition) satisfying properties (identity
laws, associativity, univalence).