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 generalizes InjectiveTypes.MathematicalStructures at the
cost of perhaps being harder to understand. It relies on the file
InjectiveTypes.Sigma, which also arises as a generalization of the
above original file.
Added 5 November 2025 by Tom de Jong: The type of metric spaces is
injective and this relies on the generalizations developed here. This
is the first example that make uses of the added generality of this file.
\begin{code}
{-# OPTIONS --safe --without-K --lossy-unification #-}
import InjectiveTypes.MathematicalStructures
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.MathematicalStructuresMoreGeneral
(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}
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 in most cases, and
at least one with the canonical Ξ£-flabby structure.
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 most examples below, we only need the above functions ΟΞ ,
compatibility-data-Ξ and Ξ -construction, but at least one of them uses
their Ξ£ versions defined below.
\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).
Added 24 July 2025 by Tom de Jong.
In InjectiveTypes.InhabitedTypesTaboo we showed that the type of nonempty types
is injective by exhibiting it as a retract of the universe. In line with the
condition from InjectiveTypes.Subtypes, the argument there shows that a type is
nonempty if and only if it is a fixed point of the map X β¦ (¬¬ X β X).
Here is an alternative proof, using that
(Ξ (p : P) , ¬¬ A p) β ¬¬ Ξ (p : P) , A p
holds when P is a proposition.
\begin{code}
Nonempty-Ξ -data : compatibility-data (is-nonempty {π€}) universes-are-flabby-Ξ
Nonempty-Ξ -data {π€} = Ξ -construction is-nonempty T T-refl c
where
S = is-nonempty
T : {X Y : π€ Μ } β (X β Y) β S X β S Y
T e = ¬¬-functor β e β
T-refl : {X : π€ Μ } β T (β-refl X) βΌ id
T-refl x = refl
Ο : (p : Ξ© π€) (A : p holds β π€ Μ )
β ((h : p holds) β S (A h)) β S (Ξ A)
Ο p A Ο Ξ½ = III
where
I : (h : p holds) β Β¬ A h
I h a = Ξ½ (Ξ» h' β transport A (holds-is-prop p h h') a)
II : Β¬ (p holds)
II h = Ο h (I h)
III : π
III = Ξ½ (Ξ» h β π-elim (II h))
c : compatibility-data-Ξ S T T-refl
c p A = Ο p A , (Ξ» Ο β dfunext fe' (Ξ» h β negations-are-props fe' _ _))
ainjectivity-of-type-of-nonempty-types
: ainjective-type (Ξ£ X κ π€ Μ , is-nonempty X) π€ π€
ainjectivity-of-type-of-nonempty-types =
ainjectivity-of-type-of-structures
is-nonempty
universes-are-flabby-Ξ
Nonempty-Ξ -data
\end{code}
Added 5 November 2025 by Tom de Jong.
All previous examples used the Ξ -flabbiness structure on the universe. In what
follows we put the extra generality of our machinery to good use by instead
employing the Ξ£-flabbiness structure to prove that the type of metric spaces is
injective.
As a first step we show that the collection of types with an R-valued relation
(for an arbitrary type R, later taken to be β) to be injective.
We denote this type by Graph' as it generalizes the type Graph of graphs defined
above. Indeed, the injectivity proof mirrors the above construction for Graph.
\begin{code}
open import UF.Subsingletons-Properties
module _ (R : π₯ Μ ) where
Graph' : (π€ : Universe) β π€ βΊ β π₯ Μ
Graph' π€ = Ξ£ X κ π€ Μ , (X β X β R)
graph'-structure : π€ Μ β π₯ β π€ Μ
graph'-structure X = (X β X β R)
Graph'-Ξ£-data
: compatibility-data (graph'-structure {π€}) universes-are-flabby-Ξ£
Graph'-Ξ£-data {π€} =
Ξ£-construction S T T-refl c
where
S = graph'-structure
T : {X Y : π€ Μ } β X β Y β S X β S Y
T π ΞΌ y y' = ΞΌ (β π ββ»ΒΉ 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 ΞΌ h a a' = ΞΌ (h , a) (h , a')
_ : r οΌ ΟΞ£ S T T-refl p A
_ = refl
Ο : ((h : p holds) β S (A h)) β S (Ξ£ A)
Ο g (h , a) (h' , a') =
g h (β Ξ£-ππ p {A} h ββ»ΒΉ (h , a)) (β Ξ£-ππ p h ββ»ΒΉ (h' , a'))
rΟ : r β Ο βΌ id
rΟ g = dfunext fe' (Ξ» h β
dfunext fe' (Ξ» a β
dfunext fe' (Ξ» a' β
apβ (g h) (transport-over-prop (holds-is-prop p))
(transport-over-prop (holds-is-prop p)))))
c : compatibility-data-Ξ£ S 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}
We now take R = β, the type of Dedekind reals, and additionally impose the
axioms of a metric space.
This mirrors the above construction for the type of posets.
\begin{code}
open import UF.PropTrunc
module _
(pt : propositional-truncations-exist)
where
open PropositionalTruncation pt
private
pe : PropExt
pe = Univalence-gives-PropExt ua
pe' : Prop-Ext
pe' {π€} = pe π€
open import DedekindReals.Addition fe' pe' pt
renaming (_+_ to _+β_) hiding (_-_)
open import DedekindReals.Order fe' pe' pt
open import DedekindReals.Type fe' pe' pt
open import MetricSpaces.StandardDefinition fe' pe' pt
Metric-Space-Ξ£-data : compatibility-data {(π€ β π€β) βΊ}
(Ξ» M β Ξ£ d κ (M β M β β) , metric-axioms M d)
universes-are-flabby-Ξ£
Metric-Space-Ξ£-data =
compatibility-data-with-axioms
universes-are-flabby-Ξ£
(graph'-structure β)
(Graph'-Ξ£-data β)
metric-axioms
metric-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) β metric-axioms (A h) (Ξ± h))
β metric-axioms (Ξ£ A) (Ο p A Ξ±)
axioms-Ξ£-data p A Ξ± F = I , II , III
where
dβ : {h : p holds} β A h β A h β β
dβ {h} = Ξ± h
dβ-reflexive : {h : p holds} β reflexivity (A h) dβ
dβ-reflexive {h} = prβ (F h)
dβ-symmetric : {h : p holds} β symmetry (A h) dβ
dβ-symmetric {h} = prβ (prβ (F h))
dβ-triangle-inequality : {h : p holds} β triangle-inequality (A h) dβ
dβ-triangle-inequality {h} = prβ (prβ (F h))
i : {h h' : p holds} β h οΌ h'
i = holds-is-prop p _ _
Ο : {h h' : p holds} β A h β A h'
Ο = transport A i
d : Ξ£ A β Ξ£ A β β
d (hβ , aβ) (hβ , aβ) = Ξ± hβ (Ο aβ) (Ο aβ)
generalized-lemma : {hβ hβ : p holds} {aβ : A hβ} {aβ : A hβ}
(eβ : hβ οΌ hβ) (eβ : hβ οΌ hβ)
(eβ : hβ οΌ hβ) (eβ : hβ οΌ hβ)
β Ξ± hβ (transport A eβ aβ) (transport A eβ aβ)
οΌ Ξ± hβ (transport A eβ aβ) (transport A eβ aβ)
generalized-lemma {hβ} {hβ} {aβ} {aβ} refl eβ eβ eβ =
apβ (Ξ± hβ)
((transport-over-prop' (holds-is-prop p) eβ) β»ΒΉ)
(ap (Ξ» - β transport A - aβ)
(props-are-sets (holds-is-prop p) eβ eβ))
dβ-equals-d : {hβ hβ : p holds} {aβ : A hβ} {aβ : A hβ}
β dβ (Ο aβ) (Ο aβ) οΌ d (hβ , aβ) (hβ , aβ)
dβ-equals-d = refl
dβ-equals-d-left : {hβ hβ : p holds} {aβ : A hβ} {aβ : A hβ}
β dβ (Ο aβ) aβ οΌ d (hβ , aβ) (hβ , aβ)
dβ-equals-d-left = generalized-lemma i refl i i
dβ-equals-d-right : {hβ hβ : p holds} {aβ : A hβ} {aβ : A hβ}
β dβ aβ (Ο aβ) οΌ d (hβ , aβ) (hβ , aβ)
dβ-equals-d-right = generalized-lemma refl refl i refl
_ : Ο p A Ξ± οΌ d
_ = refl
I : reflexivity (Ξ£ A) (Ο p A Ξ±)
I x@(hβ , a) y@(hβ , a') = Iβ , Iβ
where
Iβ : d x y οΌ 0β β x οΌ y
Iβ e = to-Ξ£-οΌ (i , lr-implication (dβ-reflexive (Ο a) a') (dβ-equals-d-left β e))
Iβ : x οΌ y β d x y οΌ 0β
Iβ refl = rl-implication (dβ-reflexive (Ο a) (Ο a)) refl
II : symmetry (Ξ£ A) d
II (hβ , aβ) (hβ , aβ) =
dβ {hβ} (Ο aβ) (Ο aβ) οΌβ¨ dβ-symmetric (Ο aβ) (Ο aβ) β©
dβ {hβ} (Ο aβ) (Ο aβ) οΌβ¨ generalized-lemma i i i i β©
dβ {hβ} (Ο aβ) (Ο aβ) β
III : triangle-inequality (Ξ£ A) (Ο p A Ξ±)
III x@(hβ , aβ) y@(hβ , aβ) z@(hβ , aβ) = IIIβ
where
IIIβ : dβ {hβ} (Ο aβ) aβ +β dβ {hβ} aβ (Ο aβ) β€β dβ {hβ} (Ο aβ) (Ο aβ)
IIIβ = dβ-triangle-inequality (Ο aβ) aβ (Ο aβ)
IIIβ : d x y +β d y z β€β d x z
IIIβ = transportβ (Ξ» rβ rβ rβ β rβ +β rβ β€β rβ)
dβ-equals-d-left dβ-equals-d-right (lem i i) IIIβ
where
lem : (eβ : hβ οΌ hβ) (eβ : hβ οΌ hβ)
β dβ {hβ} (transport A eβ aβ) (transport A eβ aβ)
οΌ d (hβ , aβ) (hβ , aβ)
lem refl refl = generalized-lemma refl refl i i
ainjectivity-of-Metric-Space
: ainjective-type (Metric-Space (π€β β π€)) (π€β β π€) (π€β β π€)
ainjectivity-of-Metric-Space {π€} =
ainjectivity-of-type-of-structures
(Ξ» M β Ξ£ d κ (M β M β β) , metric-axioms M d)
universes-are-flabby-Ξ£
(Metric-Space-Ξ£-data {π€})
\end{code}