---
layout: default
file: "src/Setoid/Categories/Algebra.lagda.md"
title: "Setoid.Categories.Algebra module"
date: "2026-06-08"
author: "the agda-algebras development team"
---

### The category of `𝑆`-algebras

This is the [Setoid.Categories.Algebra][] module of the [Agda Universal Algebra Library][].

`Alg 𝑆 Ξ± ρ` assembles the `𝑆`-algebras at levels `(Ξ± , ρ)` into a
[`Category`][Setoid.Categories.Category]: objects are `Algebra α ρ`, homs are the
setoid homomorphisms `hom` of [Setoid.Homomorphisms][], identity and composition are
`𝒾𝒹` and `βŠ™-hom`, and the hom-equality `_≋_` is **pointwise** β€” two homomorphisms are
equal when their underlying maps agree on every element, in the codomain's setoid
equality.  This pointwise hom-setoid is exactly what `_≑_` cannot provide under
`--safe`, and is why the `Category` record carries `_β‰ˆ_` as a field.

The `assoc` and identity laws hold by the codomain's `refl` (the underlying maps are
definitionally equal β€” `βŠ™-hom` is function composition, `𝒾𝒹` the identity map);
`∘-resp-β‰ˆ` is the one law with content, combining the codomain's `trans` with a hom's
`cong`.

<!--
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}

open import Overture using ( π“ž ; π“₯ ; Signature )

module Setoid.Categories.Algebra {𝑆 : Signature π“ž π“₯} where

open import Agda.Primitive using () renaming ( Set to Type )

-- Imports from the Agda Standard Library -----------------------------------
open import Data.Product     using ( proj₁ )
open import Function         using ( Func )
open import Level            using ( Level ; _βŠ”_ ) renaming ( suc to lsuc )
open import Relation.Binary  using ( Setoid ; IsEquivalence )

-- Imports from the Agda Universal Algebra Library ----------------------------
open import Setoid.Algebras.Basic {𝑆 = 𝑆}    using ( Algebra ; π•Œ[_] ; 𝔻[_] )
open import Setoid.Homomorphisms.Basic       using ( hom ; 𝒾𝒹 )
open import Setoid.Homomorphisms.Properties  using ( βŠ™-hom )
open import Setoid.Categories.Category       using ( Category )

open Func using (cong) renaming ( to to _⟨$⟩_ )

private variable α ρ : Level
```
-->

#### Pointwise equality of homomorphisms

```agda
_≋_ : {𝑨 𝑩 : Algebra Ξ± ρ} β†’ hom 𝑨 𝑩 β†’ hom 𝑨 𝑩 β†’ Type (Ξ± βŠ” ρ)
_≋_ {𝑨 = 𝑨} {𝑩} f g = βˆ€ (x : π•Œ[ 𝑨 ]) β†’ Setoid._β‰ˆ_ 𝔻[ 𝑩 ] (proj₁ f ⟨$⟩ x) (proj₁ g ⟨$⟩ x)

≋-equiv : {𝑨 𝑩 : Algebra Ξ± ρ} β†’ IsEquivalence (_≋_ {𝑨 = 𝑨} {𝑩})
≋-equiv {𝑩 = 𝑩} = record
  { refl = Ξ» _ β†’ Setoid.refl 𝔻[ 𝑩 ]
  ; sym = Ξ» f≋g x β†’ Setoid.sym 𝔻[ 𝑩 ] (f≋g x)
  ; trans = Ξ» f≋g g≋h x β†’ Setoid.trans 𝔻[ 𝑩 ] (f≋g x) (g≋h x)
  }
```

#### The category

```agda
Alg : (Ξ± ρ : Level) β†’ Category (π“ž βŠ” π“₯ βŠ” lsuc (Ξ± βŠ” ρ)) (π“ž βŠ” π“₯ βŠ” Ξ± βŠ” ρ) (Ξ± βŠ” ρ)
Alg α ρ = record
  { Obj       = Algebra α ρ
  ; Hom       = hom
  ; _β‰ˆ_       = _≋_
  ; id        = 𝒾𝒹
  ; _∘_       = Ξ» g f β†’ βŠ™-hom f g
  ; β‰ˆ-equiv   = ≋-equiv
  ; assoc     = Ξ» {_} {_} {_} {𝑫} _ β†’ Setoid.refl 𝔻[ 𝑫 ]
  ; identityΛ‘ = Ξ» {_} {𝑩} _ β†’ Setoid.refl 𝔻[ 𝑩 ]
  ; identityΚ³ = Ξ» {_} {𝑩} _ β†’ Setoid.refl 𝔻[ 𝑩 ]
  ; ∘-resp-β‰ˆ  = Ξ» {_} {_} {π‘ͺ} {_} {g} {h} f≋g h≋i x β†’
                  Setoid.trans 𝔻[ π‘ͺ ] (f≋g (proj₁ h ⟨$⟩ x)) (cong (proj₁ g) (h≋i x))
  }
```