---
layout: default
title : "Setoid.Subalgebras.Basic module (The Agda Universal Algebra Library)"
date : "2021-07-17"
author: "agda-algebras development team"
---
#### Subalgebras of setoid algebras
This is the [Setoid.Subalgebras.Basic][] module of the [Agda Universal Algebra Library][].
`π¨` is a **subalgebra** of `π©`, written `π¨ β€ π©`, just in case `π¨` can be
*homomorphically embedded* in `π©`: there is a homomorphism from `π¨` to `π©` whose
underlying map is injective.
Note that the notion of subalgebra that we define here is different from the
standard textbook definition, which defines a *subuniverse* to be a subset of
the carrier of an algebra that is closed under the operations (as we do in the
[Setoid.Subalgebras.Subuniverses][] module); a subalgebra is then a subuniverse
together with the operations of the larger algebra restricted to it. Nothing in
our definition requires the carrier of a subalgebra of `π©` to be a subset of the
carrier of `π©`.[^1]
Our subalgebra relation `_β€_`{.AgdaFunction} is clearly reflexive and transitive,
so it is a *preorder*; that is exactly what [Setoid.Subalgebras.Properties][]
proves, as `β€-preorder`{.AgdaFunction}, and it is the only order-theoretic fact
about `_β€_`{.AgdaFunction} that this subtree establishes.
It is not a partial order. Antisymmetry would require that `π¨ β€ π©` and `π© β€ π¨`
imply `π¨ β π©` for some suitable `β`, and read as "on the nose" equality that
plainly fails. The tempting repair is to read `β` as isomorphism, but that fails
too: `π¨ β€ π©` and `π© β€ π¨` supply injective homomorphisms in both directions, and a
pair of injections is not an isomorphism. Neither map need invert the other, and
in general no isomorphism need exist at all β the free groups on two and on three
generators embed in each other yet are not isomorphic, as their abelianizations
`β€Β²` and `β€Β³` already show. Extracting a bijection from two injections is
CantorβBernstein, which is unavailable constructively, and the bijection it
yields classically need not be a homomorphism.
For **finite** algebras the repair does work, and that is the setting much of this
library's later work lives in. Mutual injections between finite carriers force
equal cardinality; an injective map between finite sets of equal cardinality is
surjective; and an injective, surjective homomorphism is an isomorphism, by
`Bijectiveββ
`{.AgdaFunction} of [Setoid.Homomorphisms.Isomorphisms][]. So on
finite algebras `_β€_`{.AgdaFunction} is antisymmetric up to isomorphism, hence a
partial order on isomorphism classes. That chain of reasoning is *not* formalized
here; only `Bijectiveββ
`{.AgdaFunction}, its last step, is.
This module defines the subalgebra relation `_β€_`{.AgdaFunction} and the several
ways of packaging it: as a record bundling both algebras, as a Ξ£-type over the
smaller algebra with the larger one fixed, and relative to a whole class rather
than to a single algebra. The class-relative form `_β€c_`{.AgdaFunction} is the
one the closure operator `S`{.AgdaFunction} of [Setoid.Varieties.Closure][] is
built from.
<!--
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
module Setoid.Subalgebras.Basic where
open import Agda.Primitive using () renaming ( Set to Type )
open import Data.Product using ( _,_ ; Ξ£-syntax ) renaming ( _Γ_ to _β§_ )
open import Level using ( Level ; _β_ )
open import Relation.Binary using ( REL )
open import Relation.Unary using ( Pred ; _β_ )
open import Overture using ( projβ ; projβ ; Signature ; π ; π₯ )
open import Setoid.Algebras using ( Algebra ; ov )
open import Setoid.Functions using ( IsInjective )
open import Setoid.Homomorphisms using ( hom ; mon ; monβintohom ; kerquo ; FirstHomTheorem )
private variable Ξ± Οα΅ Ξ² Οα΅ β : Level
```
-->
The relation comes in two directions and three packagings.
+ `_IsSubalgebraOf_`{.AgdaFunction}, with the infix alias `_β€_`{.AgdaFunction},
is the relation itself: `π¨ β€ π©` is the type of pairs `(h , inj)` with
`h : hom π¨ π©` and `inj` a proof that the underlying map of `h` is injective.
+ `_IsSupalgebraOf_`{.AgdaFunction}, aliased `_β₯_`{.AgdaFunction}, is the
converse, and is *definitionally* the same type read the other way round:
`π¨ β€ π©` and `π© β₯ π¨` both unfold to an injective homomorphism from `π¨` into
`π©`.
+ `monββ€`{.AgdaFunction} turns a monomorphism into a proof of the subalgebra
relation. It is immediate, because `monβintohom`{.AgdaFunction} of
[Setoid.Homomorphisms.Basic][] already produces exactly this type.
+ `SubalgebraOf`{.AgdaRecord} bundles both algebras and the proof into a single
record. `Subalgebra`{.AgdaFunction} instead fixes the larger algebra and
collects the smaller one with its embedding, so an inhabitant of
`Subalgebra π¨` is a pair `(π© , p)` with `p : π© β€ π¨`.
```agda
module _ {π : Signature π π₯} where
_β₯_
_IsSupalgebraOf_ : Algebra {π = π} Ξ± Οα΅ β Algebra {π = π} Ξ² Οα΅ β Type (π β π₯ β Ξ± β Οα΅ β Ξ² β Οα΅)
π¨ IsSupalgebraOf π© = Ξ£[ h β hom π© π¨ ] IsInjective (projβ h)
_β€_
_IsSubalgebraOf_ : Algebra {π = π} Ξ± Οα΅ β Algebra {π = π} Ξ² Οα΅ β Type (π β π₯ β Ξ± β Οα΅ β Ξ² β Οα΅)
π¨ IsSubalgebraOf π© = Ξ£[ h β hom π¨ π© ] IsInjective (projβ h)
π¨ β₯ π© = π¨ IsSupalgebraOf π©
π¨ β€ π© = π¨ IsSubalgebraOf π©
monββ€ : {π¨ : Algebra {π = π} Ξ± Οα΅}{π© : Algebra {π = π} Ξ² Οα΅} β mon π¨ π© β π¨ β€ π©
monββ€ {π¨ = π¨}{π©} x = monβintohom π¨ π© x
record SubalgebraOf : Type (ov {π = π} (Ξ± β Ξ² β Οα΅ β Οα΅)) where
field
algebra : Algebra {π = π} Ξ± Οα΅
subalgebra : Algebra {π = π} Ξ² Οα΅
issubalgebra : subalgebra β€ algebra
Subalgebra : Algebra {π = π} Ξ± Οα΅ β {Ξ² Οα΅ : Level} β Type _
Subalgebra π¨ {Ξ²}{Οα΅} = Ξ£[ π© β (Algebra Ξ² Οα΅) ] π© β€ π¨
```
From now on we will use `π© β€ π¨` to express the assertion that `π©` is a subalgebra of `π¨`.
#### Subalgebras of classes of setoid algebras
Suppose `π¦ : Pred (Algebra Ξ± π) Ξ³` denotes a class of `π`-algebras and `π© : Algebra Ξ² Οα΅`
denotes an arbitrary `π`-algebra. Consider the assertion that `π©` is a subalgebra of
an algebra in the class `π¦`. With the next definition we can express this
assertion as `π© IsSubalgebraOfClass π¦`.
```agda
_β€c_
_IsSubalgebraOfClass_ : Algebra {π = π} Ξ² Οα΅ β Pred (Algebra {π = π} Ξ± Οα΅) β β Type _
π© IsSubalgebraOfClass π¦ = Ξ£[ π¨ β Algebra _ _ ] ((π¨ β π¦) β§ (π© β€ π¨))
π© β€c π¦ = π© IsSubalgebraOfClass π¦
record SubalgebraOfClass : Type (ov {π = π} (Ξ± β Ξ² β Οα΅ β Οα΅ β β)) where
field
class : Pred (Algebra {π = π} Ξ± Οα΅) β
subalgebra : Algebra {π = π} Ξ² Οα΅
issubalgebraofclass : subalgebra β€c class
record SubalgebraOfClass' : Type (ov {π = π} (Ξ± β Ξ² β Οα΅ β Οα΅ β β)) where
field
class : Pred (Algebra {π = π} Ξ± Οα΅) β
classalgebra : Algebra {π = π} Ξ± Οα΅
isclassalgebra : classalgebra β class
subalgebra : Algebra {π = π} Ξ² Οα΅
issubalgebra : subalgebra β€ classalgebra
SubalgebrasOfClass : Pred (Algebra {π = π} Ξ± Οα΅) β β {Ξ² Οα΅ : Level} β Type _
SubalgebrasOfClass π¦ {Ξ²}{Οα΅} = Ξ£[ π© β Algebra Ξ² Οα΅ ] π© β€c π¦
```
#### Consequences of First Homomorphism Theorem
As an example use-case of the `IsSubalgebraOf` type defined above, we prove the
following easy but useful corollary of the First Homomorphism Theorem (proved
in the [Setoid.Homomorphisms.Noether][] module): If `π¨` and `π©` are `π`-algebras
and `h : hom π¨ π©` a homomorphism from `π¨` to `π©`, then the quotient `π¨ β± ker h`
is (isomorphic to) a subalgebra of `π©`.
```agda
FirstHomCorollary : {π¨ : Algebra {π = π} Ξ± Οα΅} {π© : Algebra {π = π} Ξ² Οα΅}
(hh : hom π¨ π©) β (kerquo hh) IsSubalgebraOf π©
FirstHomCorollary hh = projβ (FirstHomTheorem hh) , projβ (projβ (FirstHomTheorem hh))
```
---
[^1]: Note that we denote both the subalgebra and subuniverse relations by the
same symbol, `_β€_`{.AgdaFunction}. The two do not collide, because the
subuniverse order lives inside the named module `Sublattice`{.AgdaModule} of
[Setoid.Subalgebras.CompleteLattice][], which qualifies it rather than
exporting it. So importing the [Setoid.Subalgebras][] barrel gives the
subalgebra relation unqualified, and the subuniverse order becomes available
as `_β€_`{.AgdaFunction} only where `Sublattice`{.AgdaModule} is opened, as in
`open Sublattice π¨ ββ`.