---
layout: default
file: "src/Legacy/Base/Varieties/FreeAlgebras.lagda.md"
title: "Legacy.Base.Varieties.FreeAlgebras module (Agda Universal Algebra Library)"
date: "2021-03-01"
author: "the agda-algebras development team"
---
### <a id="free-algebras-and-birkhoffs-theorem">Free Algebras and Birkhoff's Theorem</a>
> **Legacy notice**. This module is part of the frozen `Legacy.Base/` tree. The canonical statement and proof of Birkhoff's HSP theorem in agda-algebras now lives in [Setoid.Varieties.HSP](https://ualib.org/Setoid.Varieties.HSP.html), designated canonical under [issue #259](https://github.com/ualib/agda-algebras/issues/259) (M2-4). The proof below is the original bare-types development from v2.x; it relies on function-extensionality, propositional-extensionality, and set-truncation postulates that the canonical `Setoid/` proof retires by construction. It is preserved for v2.x downstream-user continuity and historical reference; new work does not land here. See [ADR-001](https://github.com/ualib/agda-algebras/blob/master/docs/adr/001-setoid-as-canonical.md) for the rationale of the Setoid-as-canonical migration, and the self-contained pedagogical companion at [Demos.HSP](https://ualib.org/Demos.HSP.html) for the TYPES 2021 single-file rendition.
This is the [Legacy.Base.Varieties.FreeAlgebras][] module of the [Agda Universal Algebra Library][].
First we will define the relatively free algebra in a variety, which is the "freest" algebra among (universal for) those algebras that model all identities holding in the variety. Then we give a formal proof of Birkhoff's theorem which says that a variety is an equational class. In other terms, a class `π¦` of algebras is closed under the operators `H`, `S`, and `P` if and only if `π¦` is the class of algebras that satisfy some set of identities.
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
open import Level using ( Level )
open import Overture using ( π ; π₯ ; Signature )
module Legacy.Base.Varieties.FreeAlgebras {Ξ± : Level} {π : Signature π π₯} where
open import Agda.Primitive using ( _β_ )renaming ( Set to Type )
open import Data.Product using ( _,_ ; Ξ£-syntax ; _Γ_ )
renaming ( projβ to fst ; projβ to snd )
open import Function using ( _β_ )
open import Level using ( suc )
open import Relation.Binary using ( IsEquivalence ) renaming ( Rel to BinRel )
open import Relation.Unary using ( Pred ; _β_ ; _β_ ; ο½_ο½ ; _βͺ_ )
open import Axiom.Extensionality.Propositional
using () renaming (Extensionality to funext)
open import Relation.Binary.PropositionalEquality as β‘
using ( _β‘_ ; module β‘-Reasoning )
open import Overture using ( β£_β£ ; β₯_β₯ ; _β_ ; _β»ΒΉ )
open import Legacy.Base.Functions using ( IsSurjective )
open import Legacy.Base.Relations using ( kernel ; βͺ_β« )
open import Legacy.Base.Equality
using ( SwellDef ; swelldef ; is-set ; blk-uip ; hfunext ; DFunExt; pred-ext )
open import Legacy.Base.Algebras {π = π}
using ( Algebra ; Lift-Alg ; compatible; _Μ_ ; ov ; β¨
; Con; mkcon ; IsCongruence )
open import Legacy.Base.Homomorphisms {π = π}
using ( hom ; epi ; epiβhom ; kercon ; ker-in-con ; Οker ; ker[_β_]_βΎ_ ; β-hom )
using ( β¨
-hom-co ; HomFactor ; HomFactorEpi ; _β
_ ; β
-refl ; β
-sym ; Lift-β
)
open import Legacy.Base.Terms {π = π}
using ( Term ; π» ; free-lift ; lift-hom ; free-unique ; _β¦_β§ )
using ( lift-of-epi-is-epi ; comm-hom-term; free-lift-interp )
open import Legacy.Base.Subalgebras {π = π}
using ( _β€_ ; FirstHomCorollary|Set )
open import Legacy.Base.Varieties.EquationalLogic {π = π}
using ( _β«_β_; _β§_β_; Th; Mod )
open import Legacy.Base.Varieties.Closure {π = π}
using ( S ; P ; V )
open import Legacy.Base.Varieties.Preservation {π = π}
using ( module class-products-with-maps ; class-ids-β ; class-ids ; SPβV')
open Term ; open S ; open V
π πβΊ : Level
π = ov Ξ±
πβΊ = suc (ov Ξ±)
```
#### <a id="the-free-algebra-in-theory">The free algebra in theory</a>
Recall, we proved in the [Legacy.Base.Terms.Basic][] module that the term algebra `π» X` is absolutely free in the class of all `π`-structures.
In this section, we formalize, for a given class `π¦` of `π`-algebras, the (relatively) free algebra in `S(P π¦)` over `X`.
We use the next definition to take a free algebra *for* a class `π¦` and produce the free algebra *in* `π¦`.
Let `Ξ(π¦, π¨) := {ΞΈ β Con π¨ : π¨ / ΞΈ β (S π¦)}`, and let `Ο(π¦, π¨) := β Ξ(π¦, π¨)`.
(Notice that `Ξ(π¦, π¨)` may be empty, in which case `Ο(π¦, π¨) = 1` and then `π¨ / Ο(π¦, π¨)` is trivial.)
The free algebra is constructed by applying the definitions of `ΞΈ` and `Ο` to the special case in which `π¨` is the algebra `π» X` of `π`-terms over `X`.
Since `π» X` is free for (and in) the class of all `π`-algebras, it follows that `π» X` is free for every class `π¦` of `π`-algebras. Of course, `π» X` is not necessarily a member of `π¦`, but if we form the quotient of `π» X` modulo the congruence `Ο(π¦, π» X)`, which we denote by `π½[ X ] := (π» X) / Ο(π¦, π» X)`, then it's not hard to see that `π½[ X ]` is a subdirect product of the algebras in `{(π» π) / ΞΈ}`, where `ΞΈ` ranges over `Ξ(π¦, π» X)`, so `π½[ X ]` belongs to `SP(π¦)`, and must therefore satisfy all identities modeled by all members of `π¦`. Indeed, for each pair `p q : π» X`, if `π¦ β§ p β q`, then `p` and `q` belong to the same `Ο(π¦, π» X)`-class, so `p` and `q` are identified in the quotient `π½[ X ]`.
The `π½[ X ]` that we have just defined is called the *free algebra over* `π¦` *generated by* `X` and (because of what we just observed) we may say that `π½[ X ]` is free *in* `SP(π¦)`.
**Remarks**. Since `X` is not a subset of `π½[ X ]`, technically it doesn't make sense to say "`X` generates `π½[ X ]`." But as long as `π¦` contains a nontrivial algebra, we will have `Ο(π¦, π» π) β© XΒ² β β
`, and we can identify `X` with `X / Ο(π¦, π» X)` which *is* a subset of `π½[ X ]`.
#### <a id="the-free-algebra-in-agda">The free algebra in Agda</a>
Before we attempt to represent the free algebra in Agda we construct the congruence `Ο(π¦, π» π)` described above.
First, we represent the congruence relation `ΟCon`, modulo which `π» X` yields the relatively free algebra, `π½[ X ] := π» X β± ΟCon`. We let `Ο` be the collection of identities `(p, q)` satisfied by all subalgebras of algebras in `π¦`.
```agda
module _ {X : Type Ξ±}(π¦ : Pred (Algebra Ξ±) π) where
Ο : Pred (β£ π» X β£ Γ β£ π» X β£) π
Ο (p , q) = β(π¨ : Algebra Ξ±)(sA : π¨ β S{Ξ±}{Ξ±} π¦)(h : X β β£ π¨ β£ )
β (free-lift π¨ h) p β‘ (free-lift π¨ h) q
```
We convert the predicate `Ο` into a relation by [currying](https://en.wikipedia.org/wiki/Currying).
```agda
ΟRel : BinRel β£ π» X β£ π
ΟRel p q = Ο (p , q)
```
To express `ΟRel` as a congruence of the term algebra `π» X`, we must prove that
1. `ΟRel` is compatible with the operations of `π» X` (which are jsut the terms themselves) and
2. `ΟRel` it is an equivalence relation.
```agda
open β‘-Reasoning
Οcompatible : swelldef π₯ Ξ± β compatible (π» X) ΟRel
Οcompatible wd π {p} {q} Οpq π¨ sA h = Ξ³
where
Ο : hom (π» X) π¨
Ο = lift-hom π¨ h
Ξ³ : β£ Ο β£ ((π Μ π» X) p) β‘ β£ Ο β£ ((π Μ π» X) q)
Ξ³ = β£ Ο β£ ((π Μ π» X) p) β‘β¨ β₯ Ο β₯ π p β©
(π Μ π¨) (β£ Ο β£ β p) β‘β¨ wd (π Μ π¨)(β£ Ο β£ β p)(β£ Ο β£ β q)(Ξ» x β Οpq x π¨ sA h) β©
(π Μ π¨) (β£ Ο β£ β q) β‘β¨ (β₯ Ο β₯ π q)β»ΒΉ β©
β£ Ο β£ ((π Μ π» X) q) β
ΟIsEquivalence : IsEquivalence ΟRel
ΟIsEquivalence = record { refl = Ξ» π¨ sA h β β‘.refl
; sym = Ξ» x π¨ sA h β (x π¨ sA h)β»ΒΉ
; trans = Ξ» pΟq qΟr π¨ sA h β (pΟq π¨ sA h) β (qΟr π¨ sA h) }
```
We have collected all the pieces necessary to express the collection of identities satisfied by all subalgebras of algebras in the class as a congruence relation of the term algebra. We call this congruence `ΟCon` and define it using the Congruence constructor `mkcon`.
```agda
ΟCon : swelldef π₯ Ξ± β Con (π» X)
ΟCon wd = ΟRel , mkcon ΟIsEquivalence (Οcompatible wd)
```
#### <a id="hsp-theorem">HSP Theorem</a>
To complete the proof of the HSP theorem, it remains to show that `Mod X (Th (V π¦))` is contained in `V π¦`; that is, every algebra that models the equations in `Th (V π¦)` belongs to `V π¦`. This will prove that `V π¦` is an equational class. (The converse, that every equational class is a variety was already proved; see the remarks at the end of this module.)
We accomplish this goal by constructing an algebra `π½` with the following properties:
1. `π½ β V π¦` and
2. Every `π¨ β Mod X (Th (V π¦))` is a homomorphic image of `π½`.
We denote by `β` the product of all subalgebras of algebras in `π¦`, and by `homβ` the homomorphism from `π» X` to `β` defined as follows: `homβ := β¨
-hom-co (π» X) π homπ`. Here, `β¨
-hom-co` (defined in the [Legacy.Base.Homomorphisms.Properties][] module) takes the term algebra `π» X`, a family `{π : I β Algebra Ξ±}` of `π`-algebras, and a family `homπ : β i β hom (π» X) (π i)` of homomorphisms and constructs the natural homomorphism `homβ` from `π» X` to the product `β := β¨
π`. The homomorphism `homβ : hom (π» X) (β¨
β)` is "natural" in the sense that the `i`-th component of the image of `t : Term X` under `homβ` is the image `β£ homπ i β£ t` of `t` under the i-th homomorphism `homπ i`.
#### <a id="F-in-classproduct">π½ β€ β¨
S(π¦)</a>
Now we come to a step in our approach to formalizing the HSP theorem that turned out to be more technically challenging than we anticipated. We must prove that the free algebra embeds in the product `β` of all subalgebras of algebras in the class `π¦`. This is really the only stage in the proof of Birkhoff's theorem that requires the truncation assumption that `β` be a *set* (that is, `β` has the [UIP][] property). We will also need to assume several local function extensionality postulates and, as a result, the next submodule will take as given the parameter `fe : (β a b β funext a b)`. This allows us to postulate local function extensionality when and where we need it in the proof. For example, if we want to assume function extensionality at universe levels `π₯` and `Ξ±`, we simply apply `fe` to those universes: `fe π₯ Ξ±`. (Earlier versions of the library used just a single *global* function extensionality postulate at the start of most modules, but we have since decided to exchange that elegant but crude option for greater precision and transparency.)
```agda
module _ {fe : DFunExt}{wd : SwellDef}{X : Type Ξ±} {π¦ : Pred (Algebra Ξ±) π} where
open class-products-with-maps {X = X}{fe π Ξ±}{fe πβΊ πβΊ}{fe π π} π¦
```
We begin by constructing `β`, using the techniques described in the section on <a href="https://ualib.gitlab.io/Base.Varieties.Base.Varieties.html#products-of-classes">products of classes</a>.
```agda
β : Algebra π
β = β¨
π'
```
Observe that the inhabitants of `β` are maps from `β` to `{π i : i β β}`. A homomorphism from `π» X` to `β` is obtained as follows.
```agda
homβ : hom (π» X) β
homβ = β¨
-hom-co π' (fe π Ξ±){π}(π» X) Ξ» i β lift-hom (π' i)(snd β₯ i β₯)
```
#### <a id="the-free-algebra">The free algebra</a>
As mentioned, the initial version of the [agda-algebras](https://github.com/ualib/agda-algebras) library used the free algebra `π` developed above. However, our new, more direct proof uses the algebra `π½`, which we now define, along with the natural epimorphism `epiπ½ : epi (π» X) π½` from `π» X` to `π½`.
We now define the algebra `π½`, which plays the role of the free algebra, along with the natural epimorphism `epiπ½ : epi (π» X) π½` from `π» X` to `π½`.
```agda
π½ : Algebra πβΊ
π½ = ker[ π» X β β ] homβ βΎ (wd π₯ (ov Ξ±))
epiπ½ : epi (π» X) π½
epiπ½ = Οker (wd π₯ (ov Ξ±)) {β} homβ
homπ½ : hom (π» X) π½
homπ½ = epiβhom π½ epiπ½
homπ½-is-epic : IsSurjective β£ homπ½ β£
homπ½-is-epic = snd β₯ epiπ½ β₯
```
We will need the following facts relating `homβ`, `homπ½`, `and Ο`.
```agda
Οlemma0 : β p q β β£ homβ β£ p β‘ β£ homβ β£ q β (p , q) β Ο π¦
Οlemma0 p q phomβq π¨ sA h = β‘.cong-app phomβq (π¨ , sA , h)
Οlemma0-ap : {π¨ : Algebra Ξ±}{h : X β β£ π¨ β£} β π¨ β S{Ξ±}{Ξ±} π¦
β kernel β£ homπ½ β£ β kernel (free-lift π¨ h)
Οlemma0-ap {π¨}{h} skA {p , q} x = Ξ³ where
Ξ½ : β£ homβ β£ p β‘ β£ homβ β£ q
Ξ½ = ker-in-con {Ξ± = (ov Ξ±)}{ov Ξ±}{π» X}{wd π₯ (suc (ov Ξ±))}(kercon (wd π₯ (ov Ξ±)) {β} homβ) {p}{q} x
Ξ³ : (free-lift π¨ h) p β‘ (free-lift π¨ h) q
Ξ³ = ((Οlemma0 p q) Ξ½) π¨ skA h
```
We now use `Οlemma0-ap` to prove that every map `h : X β β£ π¨ β£`, from `X` to a subalgebra `π¨ β S π¦` of `π¦`, lifts to a homomorphism from `π½` to `π¨`.
```agda
π½-lift-hom : (π¨ : Algebra Ξ±) β π¨ β S{Ξ±}{Ξ±} π¦ β (X β β£ π¨ β£) β hom π½ π¨
π½-lift-hom π¨ skA h = fst(HomFactor (wd π₯ (suc (ov Ξ±))) π¨ (lift-hom π¨ h) homπ½ (Οlemma0-ap skA) homπ½-is-epic)
```
#### <a id="k-models-psi">π¦ models Ο</a>
The goal of this subsection is to prove that `π¦` models `Ο π¦`. In other terms, for all pairs `(p , q) β Term X Γ Term X` of terms, if `(p , q) β Ο π¦`, then `π¦ β« p β q`.
Next we define the lift of the natural embedding from `X` into `π½`. We denote this homomorphism by `π : hom (π» X) π½` and define it as follows.
```agda
open IsCongruence
Xβͺπ½ : X β β£ π½ β£
Xβͺπ½ x = βͺ β x β«
π : hom (π» X) π½
π = lift-hom π½ Xβͺπ½
```
It turns out that the homomorphism so defined is equivalent to `homπ½`.
```agda
open β‘-Reasoning
homπ½-is-lift-hom : β p β β£ π β£ p β‘ β£ homπ½ β£ p
homπ½-is-lift-hom (β x) = β‘.refl
homπ½-is-lift-hom (node π π) =
β£ π β£ (node π π) β‘β¨ β₯ π β₯ π π β©
(π Μ π½)(Ξ» i β β£ π β£(π i)) β‘β¨ wd-proof β©
(π Μ π½)(Ξ» i β β£ homπ½ β£ (π i)) β‘β¨ (β₯ homπ½ β₯ π π)β»ΒΉ β©
β£ homπ½ β£ (node π π) β
where wd-proof = wd π₯ (suc (ov Ξ±))
(π Μ π½) (Ξ» i β β£ π β£(π i)) (Ξ» i β β£ homπ½ β£ (π i))
(Ξ» x β homπ½-is-lift-hom(π x))
```
We need a three more lemmas before we are ready to tackle our main goal.
```agda
Οlemma1 : kernel β£ π β£ β Ο π¦
Οlemma1 {p , q} πpq π¨ sA h = Ξ³
where
f : hom π½ π¨
f = π½-lift-hom π¨ sA h
h' Ο : hom (π» X) π¨
h' = β-hom (π» X) π¨ π f
Ο = lift-hom π¨ h
hβ‘Ο : β t β (β£ f β£ β β£ π β£) t β‘ β£ Ο β£ t
hβ‘Ο t = free-unique (wd π₯ Ξ±) π¨ h' Ο (Ξ» x β β‘.refl) t
Ξ³ : β£ Ο β£ p β‘ β£ Ο β£ q
Ξ³ = β£ Ο β£ p β‘β¨ (hβ‘Ο p)β»ΒΉ β©
β£ f β£ ( β£ π β£ p ) β‘β¨ β‘.cong β£ f β£ πpq β©
β£ f β£ ( β£ π β£ q ) β‘β¨ hβ‘Ο q β©
β£ Ο β£ q β
Οlemma2 : kernel β£ homπ½ β£ β Ο π¦
Οlemma2 {p , q} x = Οlemma1 {p , q} Ξ³
where
Ξ³ : (free-lift π½ Xβͺπ½) p β‘ (free-lift π½ Xβͺπ½) q
Ξ³ = (homπ½-is-lift-hom p) β x β (homπ½-is-lift-hom q)β»ΒΉ
Οlemma3 : β p q β (p , q) β Ο{X = X} π¦ β π¦ β« p β q
Οlemma3 p q pΟq {π¨} kA h = goal
where
goal : (π¨ β¦ p β§) h β‘ (π¨ β¦ q β§) h
goal = (π¨ β¦ p β§) h β‘β¨ free-lift-interp (wd π₯ Ξ±) π¨ h p β©
(free-lift π¨ h) p β‘β¨ pΟq π¨ (siso (sbase kA) (β
-sym Lift-β
)) h β©
(free-lift π¨ h) q β‘β¨ (free-lift-interp (wd π₯ Ξ±) π¨ h q)β»ΒΉ β©
(π¨ β¦ q β§) h β
```
With these results in hand, it is now trivial to prove the main theorem of this subsection.
```agda
class-models-kernel : β p q β (p , q) β kernel β£ homπ½ β£ β π¦ β« p β q
class-models-kernel p q x = Οlemma3 p q (Οlemma2 x)
ππ¦ : Pred (Algebra πβΊ) (suc πβΊ)
ππ¦ = V{Ξ± = Ξ±}{Ξ² = πβΊ} π¦
kernel-in-theory' : kernel β£ homπ½ β£ β Th (V π¦)
kernel-in-theory' {p , q} pKq = (class-ids-β fe wd p q (class-models-kernel p q pKq))
kernel-in-theory : kernel β£ homπ½ β£ β Th ππ¦
kernel-in-theory {p , q} pKq vkA x = class-ids fe wd p q (class-models-kernel p q pKq) vkA x
_β _ : Type Ξ± β Algebra πβΊ β Type πβΊ
X β π¨ = Ξ£[ h β (X β β£ π¨ β£) ] IsSurjective h
π½-ModTh-epi : (π¨ : Algebra πβΊ) β (X β π¨) β π¨ β Mod (Th ππ¦) β epi π½ π¨
π½-ModTh-epi π¨ (Ξ· , Ξ·E) AinMTV = goal
where
Ο : hom (π» X) π¨
Ο = lift-hom π¨ Ξ·
ΟE : IsSurjective β£ Ο β£
ΟE = lift-of-epi-is-epi π¨ Ξ·E
pqlem2 : β p q β (p , q) β kernel β£ homπ½ β£ β π¨ β§ p β q
pqlem2 p q z = Ξ» x β AinMTV p q (kernel-in-theory z) x
kerincl : kernel β£ homπ½ β£ β kernel β£ Ο β£
kerincl {p , q} x = β£ Ο β£ p β‘β¨ (free-lift-interp (wd π₯ πβΊ) π¨ Ξ· p)β»ΒΉ β©
(π¨ β¦ p β§) Ξ· β‘β¨ pqlem2 p q x Ξ· β©
(π¨ β¦ q β§) Ξ· β‘β¨ free-lift-interp (wd π₯ πβΊ) π¨ Ξ· q β©
β£ Ο β£ q β
goal : epi π½ π¨
goal = fst (HomFactorEpi (wd π₯ (suc (ov Ξ±))) π¨ Ο homπ½ kerincl homπ½-is-epic ΟE)
```
#### <a id="the-homomorphic-images-of-F">The homomorphic images of π½</a>
Finally we come to one of the main theorems of this module; it asserts that every algebra in `Mod X (Th ππ¦)` is a homomorphic image of `π½`. We prove this below as the function (or proof object) `π½-ModTh-epi`. Before that, we prove two auxiliary lemmas.
```agda
module _ (pe : pred-ext (ov Ξ±)(ov Ξ±))(wd : SwellDef)
(Cset : is-set β£ β β£)
(kuip : blk-uip(Term X)β£ kercon (wd π₯ (ov Ξ±)){β}homβ β£)
where
π½β€β : (ker[ π» X β β ] homβ βΎ (wd π₯ (ov Ξ±))) β€ β
π½β€β = FirstHomCorollary|Set (π» X) β homβ pe (wd π₯ (ov Ξ±)) Cset kuip
```
The last piece we need to prove that every model of `Th ππ¦` is a homomorphic image of `π½` is a crucial assumption that is taken for granted throughout informal universal algebra---namely, that our collection `X` of variable symbols is arbitrarily large and that we have an *environment* which interprets the variable symbols in every algebra under consideration. In other terms, an environment provides, for every algebra `π¨`, a surjective mapping `Ξ· : X β β£ π¨ β£` from `X` onto the domain of `π¨`.
We do *not* assert that for an arbitrary type `X` such surjective maps exist. Indeed, our `X` must is quite special to have this property. Later, we will construct such an `X`, but for now we simply postulate its existence. Note that this assumption that an environment exists is only required in the proof of the theorem `π½-ModTh-epi`.
#### <a id="F-in-VK">π½ β V(π¦)</a>
With this result in hand, along with what we proved earlier---namely, `PS(π¦) β SP(π¦) β HSP(π¦) β‘ V π¦`---it is not hard to show that `π½` belongs to `V π¦`.
```agda
π½βSP : hfunext (ov Ξ±)(ov Ξ±) β π½ β (S{π}{πβΊ} (P{Ξ±}{π} π¦))
π½βSP hfe = ssub (class-prod-s-β-sp hfe) π½β€β
π½βπ : hfunext (ov Ξ±)(ov Ξ±) β π½ β V π¦
π½βπ hfe = SPβV' {Ξ±}{fe π Ξ±}{fe πβΊ πβΊ}{fe π π}{π¦} (π½βSP hfe)
```
#### The HSP Theorem
Now that we have all of the necessary ingredients, it is all but trivial to
combine them to prove Birkhoff's HSP theorem. (Note that since the proof enlists
the help of the `π½-ModTh-epi` theorem, we must assume an environment exists,
which is manifested in the premise `β π¨ β X β π¨`.
```agda
Birkhoff : hfunext (ov Ξ±)(ov Ξ±) β (β π¨ β X β π¨) β Mod (Th (V π¦)) β V π¦
Birkhoff hfe π {π¨} Ξ± = vhimg{π© = π¨} (π½βπ hfe) (π¨ , epiβhom π¨ ΟE , snd β₯ ΟE β₯)
where
ΟE : epi π½ π¨
ΟE = π½-ModTh-epi π¨ (π π¨) Ξ±
```
The converse inclusion, `V π¦ β Mod X (Th (V π¦))`, is a simple consequence of the
fact that `Mod Th` is a closure operator. Nonetheless, completeness demands
that we formalize this inclusion as well, however trivial the proof.
```agda
Birkhoff-converse : V{Ξ±}{π} π¦ β Mod{X = X} (Th (V π¦))
Birkhoff-converse Ξ± p q pThq = pThq Ξ±
```
We have thus proved that every variety is an equational class. Readers familiar
with the classical formulation of the Birkhoff HSP theorem, as an "if and only
if" result, might worry that we haven't completed the proof. But recall that
in the [Legacy.Base.Varieties.Preservation][] module we proved the following identity
preservation lemmas:
* `π¦ β« p β q β H π¦ β« p β q`
* `π¦ β« p β q β S π¦ β« p β q`
* `π¦ β« p β q β P π¦ β« p β q`
From these it follows that every equational class is a variety. Thus, our formal
proof of Birkhoff's theorem is complete.