module Data.Set.Coequaliser where
Set coequalisers🔗
In their most general form, colimits can be pictured as taking disjoint unions and then “gluing together” some parts. The “gluing together” part of that definition is where coequalisers come in: If you have parallel maps , then the coequaliser can be thought of as “, with the images of and identified”.
data Coeq (f g : A → B) : Type (level-of A ⊔ level-of B) where
: B → Coeq f g
inc : ∀ x → inc (f x) ≡ inc (g x)
glue : is-set (Coeq f g) squash
The universal property of coequalisers, being a type of colimit, is a
mapping-out property: Maps from
are maps out of
,
satisfying a certain property. Specifically, for a map
,
if we have
,
then the map
factors (uniquely) through inc
. The
situation can be summarised with the diagram below.
We refer to this unique factoring as Coeq-rec
.
: ∀ {ℓ} {C : Type ℓ} {f g : A → B}
Coeq-rec → is-set C → (h : B → C)
→ (∀ x → h (f x) ≡ h (g x)) → Coeq f g → C
(inc x) = h x
Coeq-rec cset h h-coeqs (glue x i) = h-coeqs x i
Coeq-rec cset h h-coeqs (squash x y p q i j) =
Coeq-rec cset h h-coeqs (g x) (g y) (λ i → g (p i)) (λ i → g (q i)) i j
cset where g = Coeq-rec cset h h-coeqs
An alternative phrasing of the desired universal property is
precomposition with inc
induces an
equivalence between the “space of maps
which coequalise
and
”
and the maps
.
In this sense, inc
is the universal
map which coequalises
and
.
To construct the map above, we used Coeq-elim-prop
, which has not yet been
defined. It says that, to define a dependent function from Coeq
to a family of propositions, it
suffices to define how it acts on inc
: The path constructions don’t
matter.
: ∀ {ℓ} {f g : A → B} {C : Coeq f g → Type ℓ}
Coeq-elim-prop → (∀ x → is-prop (C x))
→ (∀ x → C (inc x))
→ ∀ x → C x
(inc x) = cinc x Coeq-elim-prop cprop cinc
Since C was assumed to be a family of propositions, we automatically
get the necessary coherences for glue
and squash
.
{f = f} {g = g} cprop cinc (glue x i) =
Coeq-elim-prop (λ i → cprop (glue x i)) (cinc (f x)) (cinc (g x)) i
is-prop→pathp (squash x y p q i j) =
Coeq-elim-prop cprop cinc (λ i j → cprop (squash x y p q i j))
is-prop→squarep (λ i → g x) (λ i → g (p i)) (λ i → g (q i)) (λ i → g y) i j
where g = Coeq-elim-prop cprop cinc
Since “the space of maps
which coequalise
and
”
is a bit of a mouthful, we introduce an abbreviation: Since a colimit is
defined to be a certain universal (co)cone, we call these Coeq-cone
s.
private
: ∀ {ℓ} (f g : A → B) → Type ℓ → Type _
coeq-cone {B = B} f g C = Σ[ h ∈ (B → C) ] (h ∘ f ≡ h ∘ g) coeq-cone
The universal property of Coeq
then says that Coeq-cone
is
equivalent to the maps
,
and this equivalence is given by inc
, the “universal Coequalising
map”.
: ∀ {ℓ} {C : Type ℓ} {f g : A → B}
Coeq-univ → is-set C
→ is-equiv {A = Coeq f g → C} {B = coeq-cone f g C}
(λ h → h ∘ inc , λ i z → h (glue z i))
{C = C} {f = f} {g = g} cset =
Coeq-univ (iso cr' (λ x → refl) islinv)
is-iso→is-equiv where
open is-iso
: coeq-cone f g C → Coeq f g → C
cr' (f , f-coeqs) = Coeq-rec cset f (happly f-coeqs)
cr'
: is-left-inverse cr' (λ h → h ∘ inc , λ i z → h (glue z i))
islinv = funext (Coeq-elim-prop (λ x → cset _ _) λ x → refl) islinv f
Elimination🔗
Above, we defined what it means to define a dependent function when is a family of propositions, and what it means to define a non-dependent function . Now, we combine the two notions, and allow dependent elimination into families of sets:
: ∀ {ℓ} {f g : A → B} {C : Coeq f g → Type ℓ}
Coeq-elim → (∀ x → is-set (C x))
→ (ci : ∀ x → C (inc x))
→ (∀ x → PathP (λ i → C (glue x i)) (ci (f x)) (ci (g x)))
→ ∀ x → C x
(inc x) = ci x
Coeq-elim cset ci cg (glue x i) = cg x i
Coeq-elim cset ci cg (squash x y p q i j) =
Coeq-elim cset ci cg (λ i j → cset (squash x y p q i j))
is-set→squarep (λ i → g x) (λ i → g (p i)) (λ i → g (q i)) (λ i → g y) i j
where g = Coeq-elim cset ci cg
There is a barrage of combined eliminators, whose definitions are not
very enlightening — you can mouse over these links to see their types:
Coeq-elim-prop₂
Coeq-elim-prop₃
Coeq-rec₂
.
Quotients🔗
With dependent sums, we can recover quotients as a special case of coequalisers. Observe that, by taking the total space of a relation , we obtain two projection maps which have as image all of the possible related elements in . By coequalising these projections, we obtain a space where any related objects are identified: The quotient .
private
: ∀ {ℓ} → (A → A → Type ℓ) → Type (level-of A ⊔ ℓ)
tot {A = A} R = Σ[ x ∈ A ] Σ[ y ∈ A ] R x y
tot
: ∀ {ℓ} {R : A → A → Type ℓ} → tot R → A
/-left (x , _ , _) = x
/-left
: ∀ {ℓ} {R : A → A → Type ℓ} → tot R → A
/-right (_ , x , _) = x /-right
We form the quotient as the aforementioned coequaliser of the two projections from the total space of :
_/_ : ∀ {ℓ ℓ'} (A : Type ℓ) (R : A → A → Type ℓ') → Type (ℓ ⊔ ℓ')
= Coeq (/-left {R = R}) /-right
A / R
: ∀ {ℓ ℓ'} {A : Type ℓ} {R : A → A → Type ℓ'} {x y : A} → R x y
quot → Path (A / R) (inc x) (inc y)
= glue (_ , _ , r) quot r
Using Coeq-elim
, we can recover
the elimination principle for quotients:
: ∀ {ℓ} {B : A / R → Type ℓ}
Quot-elim → (∀ x → is-set (B x))
→ (f : ∀ x → B (inc x))
→ (∀ x y (r : R x y) → PathP (λ i → B (quot r i)) (f x) (f y))
→ ∀ x → B x
= Coeq-elim bset f λ { (x , y , w) → r x y w } Quot-elim bset f r
Effectivity🔗
The most well-behaved case of quotients is when
takes values in propositions, is reflexive, transitive and symmetric (an
equivalence relation). In this case, we have that the quotient
is effective: The map quot
is an equivalence.
record Congruence {ℓ} (A : Type ℓ) ℓ' : Type (ℓ ⊔ lsuc ℓ') where
field
_∼_ : A → A → Type ℓ'
: ∀ x y → is-prop (x ∼ y)
has-is-prop : ∀ {x} → x ∼ x
reflᶜ _∙ᶜ_ : ∀ {x y z} → x ∼ y → y ∼ z → x ∼ z
: ∀ {x y} → x ∼ y → y ∼ x
symᶜ
= _∼_
relation
: Type _
quotient = A / _∼_ quotient
We will show this using an encode-decode method. For each , we define a type family , which represents an equality . Importantly, the fibre over will be , so that the existence of functions converting between and paths is enough to establish effectivity of the quotient.
private
: A → quotient → Prop ℓ'
Code = Quot-elim
Code x (λ x → n-Type-is-hlevel 1)
(λ y → el (x ∼ y) (has-is-prop x y) {- 1 -})
λ y z r →
(prop-ext (has-is-prop _ _) (has-is-prop _ _)
n-ua (λ z → z ∙ᶜ r)
λ z → z ∙ᶜ (symᶜ r))
We do quotient induction into the type of propositions
, which by univalence is a set
.
Since the fibre over
must be
,
that’s what we give for the inc
constructor ({- 1 -}
, above).
For this to respect the quotient, it suffices to show that, given
,
we have
,
which follows from the assumption that
is an equivalence relation ({- 2 -}
).
: ∀ x y (p : inc x ≡ y) → ∣ Code x y ∣
encode = subst (λ y → ∣ Code x y ∣) p reflᶜ
encode x y p
: ∀ x y (p : ∣ Code x y ∣) → inc x ≡ y
decode =
decode x y p {C = λ y → (p : ∣ Code x y ∣) → inc x ≡ y}
Coeq-elim-prop (λ _ → Π-is-hlevel 1 λ _ → squash _ _) (λ y r → quot r) y p
For encode
, it suffices to
transport the proof that
is reflexive along the given proof, and for decoding, we eliminate from
the quotient to a proposition. It boils down to establishing that
,
which is what the constructor quot
says. Putting this all together, we get a proof that equivalence
relations are effective
.
: ∀ {x y : A} → is-equiv (quot {R = relation})
is-effective {x = x} {y} =
is-effective (has-is-prop x y) (squash _ _) (decode x (inc y)) (encode x (inc y)) .snd prop-ext
Relation to surjections🔗
As mentioned in the definition of surjection, we can view a cover as expressing a way of gluing together the type by adding paths between the elements of . When and are sets, this sounds a lot like a quotient! And, indeed, we can prove that every surjection induces an equivalence between its codomain and a quotient of its domain.
First, we define the kernel pair of a function , the congruence on defined to be identity under .
Kernel-pair: ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → is-set B → (A → B)
→ Congruence A ℓ'
._∼_ a b = f a ≡ f b
Kernel-pair b-set f .has-is-prop x y = b-set (f x) (f y)
Kernel-pair b-set f .reflᶜ = refl
Kernel-pair b-set f ._∙ᶜ_ = _∙_
Kernel-pair b-set f .symᶜ = sym Kernel-pair b-set f
We can then set about proving that, if is a surjection into a set, then is the quotient of under the kernel pair of .
The construction is pretty straightforward: each fibre defines an element ; If we have another fibre , then because
so the function is constant, and factors through the propositional truncation .
: ∀ {x} → fibre f x → c.quotient
g₀ (a , p) = inc a
g₀
abstract
: ∀ {x} (p₁ p₂ : fibre f x) → g₀ p₁ ≡ g₀ p₂
g₀-const (_ , p) (_ , q) = quot (p ∙ sym q)
g₀-const
: ∀ {x} → ∥ fibre f x ∥ → c.quotient
g₁ = ∥-∥-rec-set hlevel! g₀ g₀-const f g₁ f
Since each is inhabited, all of these functions glue together to give a function . A simple calculation shows that this function is both injective and surjective; since its codomain is a set, that means it’s an equivalence.
: B → c.quotient
g' = g₁ (surj x)
g' x
: injective g'
g'-inj {x} {y} = ∥-∥-elim₂ {P = λ a b → g₁ a ≡ g₁ b → x ≡ y}
g'-inj (λ _ _ → fun-is-hlevel 1 (b-set _ _))
(λ (_ , p) (_ , q) r → sym p ∙ c.effective r ∙ q)
(surj x) (surj y)
: is-surjective g'
g'-surj = do
g'-surj x (y , p) ← inc-is-surjective x
(f y , ap g₁ (squash (surj (f y)) (inc (y , refl))) ∙ p) pure