---
layout: default
title : "Legacy.Base.Homomorphisms.Basic module (The Agda Universal Algebra Library)"
date : "2021-01-13"
author: "agda-algebras development team"
---
### <a id="basic-definitions">Basic Definitions</a>
This is the [Legacy.Base.Homomorphisms.Basic] module of the [Agda Universal Algebra Library][].
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
open import Overture using ( Signature; π ; π₯ )
module Legacy.Base.Homomorphisms.Basic {π : Signature π π₯} where
open import Agda.Primitive renaming ( Set to Type ) using ()
open import Data.Product renaming ( projβ to fst )
using ( _,_ ; Ξ£ ; _Γ_ ; Ξ£-syntax)
open import Function using ( _β_ ; id )
open import Level using ( Level ; _β_ )
open import Relation.Binary.PropositionalEquality using ( _β‘_ ; refl )
open import Overture using ( β£_β£ ; β₯_β₯ )
open import Legacy.Base.Functions using ( IsInjective ; IsSurjective )
open import Legacy.Base.Algebras {π = π} using ( Algebra ; _Μ_ ; Lift-Alg )
private variable Ξ± Ξ² : Level
```
#### <a id="homomorphisms">Homomorphisms</a>
If `π¨` and `π©` are `π`-algebras, then a *homomorphism* from `π¨` to `π©` is a
function `h : β£ π¨ β£ β β£ π© β£` from the domain of `π¨` to the domain of `π©` that is
*compatible* (or *commutes*) with all of the basic operations of the signature;
that is, for all operation symbols `π : β£ π β£` and tuples `a : β₯ π β₯ π β β£ π¨ β£` of
`π¨`, the following holds:
`h ((π Μ π¨) a) β‘ (π Μ π©) (h β a)`.
**Remarks**. Recall, `h β π` is the tuple whose i-th component is `h (π i)`.
Instead of "homomorphism," we sometimes use the nickname "hom" to refer to such
a map.
To formalize this concept, we first define a type representing the assertion that
a function `h : β£ π¨ β£ β β£ π© β£` commutes with a single basic operation `π`. With
Agda's extremely flexible syntax the defining equation above can be expressed
unadulterated.
```agda
module _ (π¨ : Algebra Ξ±)(π© : Algebra Ξ²) where
compatible-op-map : β£ π β£ β (β£ π¨ β£ β β£ π© β£) β Type(Ξ± β π₯ β Ξ²)
compatible-op-map π h = β π β h ((π Μ π¨) π) β‘ (π Μ π©) (h β π)
```
Agda infers from the shorthand `β π` that `π` has type `β₯ π β₯ π β β£ π¨ β£` since it
must be a tuple on `β£ π¨ β£` of "length" `β₯ π β₯ π` (the arity of `π`).
We now define the type `hom π¨ π©` of homomorphisms from `π¨` to `π©` by first
defining the type `is-homomorphism` which represents the property of being a
homomorphism.
```agda
is-homomorphism : (β£ π¨ β£ β β£ π© β£) β Type(π β π₯ β Ξ± β Ξ²)
is-homomorphism g = β π β compatible-op-map π g
hom : Type(π β π₯ β Ξ± β Ξ²)
hom = Ξ£ (β£ π¨ β£ β β£ π© β£) is-homomorphism
```
#### <a id="important-exmples-of-homomorphisms">Important examples of homomorphisms</a>
Let's look at a few important examples of homomorphisms. These examples are
actually quite special in that every algebra has such a homomorphism.
We begin with the identity map, which is proved to be (the underlying map of) a
homomorphism as follows.
```agda
πΎπΉ : (π¨ : Algebra Ξ±) β hom π¨ π¨
πΎπΉ _ = id , Ξ» π π β refl
```
Next, the lifting of an algebra to a higher universe level is, in fact, a
homomorphism. Dually, the lowering of a lifted algebra to its original universe
level is a homomorphism.
```agda
open Level
ππΎπ»π : {Ξ² : Level}(π¨ : Algebra Ξ±) β hom π¨ (Lift-Alg π¨ Ξ²)
ππΎπ»π _ = lift , Ξ» π π β refl
πβ΄πβ―π : {Ξ² : Level}(π¨ : Algebra Ξ±) β hom (Lift-Alg π¨ Ξ²) π¨
πβ΄πβ―π _ = lower , Ξ» π π β refl
```
#### <a id="monomorphisms-and-epimorphisms">Monomorphisms and epimorphisms</a>
A *monomorphism* is an injective homomorphism and an *epimorphism* is a surjective
homomorphism. These are represented in the [agda-algebras][] library by the following
types.
```agda
is-monomorphism : (π¨ : Algebra Ξ±)(π© : Algebra Ξ²) β (β£ π¨ β£ β β£ π© β£) β Type _
is-monomorphism π¨ π© g = is-homomorphism π¨ π© g Γ IsInjective g
mon : Algebra Ξ± β Algebra Ξ² β Type(π β π₯ β Ξ± β Ξ²)
mon π¨ π© = Ξ£[ g β (β£ π¨ β£ β β£ π© β£) ] is-monomorphism π¨ π© g
is-epimorphism : (π¨ : Algebra Ξ±)(π© : Algebra Ξ²) β (β£ π¨ β£ β β£ π© β£) β Type _
is-epimorphism π¨ π© g = is-homomorphism π¨ π© g Γ IsSurjective g
epi : Algebra Ξ± β Algebra Ξ² β Type(π β π₯ β Ξ± β Ξ²)
epi π¨ π© = Ξ£[ g β (β£ π¨ β£ β β£ π© β£) ] is-epimorphism π¨ π© g
```
It will be convenient to have a function that takes an inhabitant of `mon` (or
`epi`) and extracts the homomorphism part, or *hom reduct* (that is, the pair
consisting of the map and a proof that the map is a homomorphism).
```agda
monβhom : (π¨ : Algebra Ξ±){π© : Algebra Ξ²} β mon π¨ π© β hom π¨ π©
monβhom π¨ Ο = β£ Ο β£ , fst β₯ Ο β₯
epiβhom : {π¨ : Algebra Ξ±}(π© : Algebra Ξ²) β epi π¨ π© β hom π¨ π©
epiβhom _ Ο = β£ Ο β£ , fst β₯ Ο β₯
```