---
layout: default
title : "Setoid.Varieties.Preservation (The Agda Universal Algebra Library)"
date : "2021-09-24"
author: "agda-algebras development team"
---
### Equation preservation for setoid algebras
This is the [Setoid.Varieties.Preservation][] module of the [Agda Universal Algebra Library][] where we show
that the classes \af H `π¦`{.AgdaBound}, \af S `π¦`{.AgdaBound}, \af P `π¦`{.AgdaBound}, and \af V `π¦`{.AgdaBound} all satisfy the
same identities.
<!--
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
open import Overture using (π ; π₯ ; Signature)
module Setoid.Varieties.Preservation {π : Signature π π₯} where
open import Agda.Primitive using () renaming ( Set to Type )
open import Data.Product using ( _,_ )
open import Data.Unit.Polymorphic using ( β€ )
open import Function using () renaming ( Func to _βΆ_ )
open import Level using ( Level ; _β_ )
open import Relation.Binary using ( Setoid )
open import Relation.Unary using ( Pred ; _β_ ; _β_ )
open import Overture using ( projβ ; projβ )
open import Overture.Terms {π = π} using ( Term )
open import Setoid.Algebras {π = π} using ( Algebra ; ov ; β¨
)
open import Setoid.Homomorphisms {π = π} using ( β
β¨
βΊ-refl ; β
-refl
; IdHomImage ; β
-sym )
open import Setoid.Subalgebras {π = π} using ( _β€_ ; β¨
-β€ ; β
-trans-β€
; β€-reflexive )
open import Setoid.Terms {π = π} using ( module Environment)
open import Setoid.Varieties.Closure {π = π} using ( H ; S ; P ; S-expa
; H-expa ; V ; P-expa
; V-expa ;Level-closure )
open import Setoid.Varieties.Properties {π = π} using ( β§-H-invar ; β§-S-invar
; β§-P-invar ; β§-I-invar )
open import Setoid.Varieties.SoundAndComplete {π = π} using ( _β§_ ; _β«_ ; β«-proof
; _βΜ_ ; _β’_βΉ_β_ ; Th)
open _βΆ_ using () renaming ( to to _β¨$β©_ )
open Algebra using ( Domain )
```
-->
#### Closure properties
The types defined above represent operators with useful closure properties. We now
prove a handful of such properties that we need later.
```agda
module _ {Ξ± Οα΅ β : Level}{π¦ : Pred(Algebra Ξ± Οα΅) (Ξ± β Οα΅ β ov β)} where
private
a = Ξ± β Οα΅
oaβ = ov (a β β)
SβSP : β{ΞΉ} β S β π¦ β S {Ξ² = Ξ±}{Οα΅} (a β β β ΞΉ) (P {Ξ² = Ξ±}{Οα΅} β ΞΉ π¦)
SβSP {ΞΉ} (π¨ , (kA , Bβ€A )) = π¨ , (pA , Bβ€A)
where
pA : π¨ β P β ΞΉ π¦
pA = β€ , (Ξ» _ β π¨) , (Ξ» _ β kA) , β
β¨
βΊ-refl
PβSP : β{ΞΉ} β P β ΞΉ π¦ β S (a β β β ΞΉ) (P {Ξ² = Ξ±}{Οα΅}β ΞΉ π¦)
PβSP {ΞΉ} x = S-expa{β = a β β β ΞΉ} x
PβHSP : β{ΞΉ} β P {Ξ² = Ξ±}{Οα΅} β ΞΉ π¦ β H (a β β β ΞΉ) (S (a β β β ΞΉ) (P β ΞΉ π¦))
PβHSP {ΞΉ} x = H-expa{β = a β β β ΞΉ} (S-expa{β = a β β β ΞΉ} x)
PβV : β{ΞΉ} β P β ΞΉ π¦ β V β ΞΉ π¦
PβV = PβHSP
SPβV : β{ΞΉ} β S{Ξ² = Ξ±}{Οα΅ = Οα΅} (a β β β ΞΉ) (P {Ξ² = Ξ±}{Οα΅} β ΞΉ π¦) β V β ΞΉ π¦
SPβV {ΞΉ} x = H-expa{β = a β β β ΞΉ} x
```
Finally, we are in a position to prove that a product of subalgebras of algebras
in a class π¦ is a subalgebra of a product of algebras in π¦.
```agda
PSβSP : P (a β β) oaβ (S{Ξ² = Ξ±}{Οα΅} β π¦) β S oaβ (P β oaβ π¦)
PSβSP {π©} (I , ( π , sA , Bβ
β¨
A )) = Goal
where
β¬ : I β Algebra Ξ± Οα΅
β¬ i = sA i .projβ
kB : (i : I) β β¬ i β π¦
kB i = sA i .projβ .projβ
β¨
Aβ€β¨
B : β¨
π β€ β¨
β¬
β¨
Aβ€β¨
B = β¨
-β€ Ξ» i β projβ (projβ (sA i))
Goal : π© β S{Ξ² = oaβ}{oaβ}oaβ (P {Ξ² = oaβ}{oaβ} β oaβ π¦)
Goal = β¨
β¬ , (I , (β¬ , (kB , β
-refl))) , (β
-trans-β€ Bβ
β¨
A β¨
Aβ€β¨
B)
```
#### H preserves identities
First we prove that the closure operator H is compatible with identities that hold in the given class.
```agda
module _ {Ξ± Οα΅ β Ο : Level}
{π¦ : Pred(Algebra Ξ± Οα΅) (Ξ± β Οα΅ β ov β)}
{X : Type Ο}
{p q : Term X}
where
H-id1 : π¦ β« (p βΜ q) β H {Ξ² = Ξ±}{Οα΅}β π¦ β« (p βΜ q)
H-id1 Ο .β«-proof π© (π¨ , kA , BimgA) = β§-H-invar{p = p}{q} (Ο .β«-proof π¨ kA) BimgA
```
The converse of the foregoing result is almost too obvious to bother with. Nonetheless, we formalize it for completeness.
```agda
H-id2 : H β π¦ β« (p βΜ q) β π¦ β« (p βΜ q)
H-id2 Hpq .β«-proof π¨ kA = Hpq .β«-proof π¨ (π¨ , (kA , IdHomImage))
```
#### S preserves identities
```agda
S-id1 : π¦ β« (p βΜ q) β (S {Ξ² = Ξ±}{Οα΅} β π¦) β« (p βΜ q)
S-id1 Ο .β«-proof π© (π¨ , kA , Bβ€A) = β§-S-invar{p = p}{q} (Ο .β«-proof π¨ kA) Bβ€A
S-id2 : S β π¦ β« (p βΜ q) β π¦ β« (p βΜ q)
S-id2 Spq .β«-proof π¨ kA = Spq .β«-proof π¨ (π¨ , (kA , β€-reflexive))
```
#### P preserves identities
```agda
P-id1 : β{ΞΉ} β π¦ β« (p βΜ q) β P {Ξ² = Ξ±}{Οα΅}β ΞΉ π¦ β« (p βΜ q)
P-id1 Ο .β«-proof π¨ (I , π , kA , Aβ
β¨
A) = β§-I-invar π¨ p q IH (β
-sym Aβ
β¨
A)
where
ih : β i β π i β§ (p βΜ q)
ih i = Ο .β«-proof (π i) (kA i)
IH : β¨
π β§ (p βΜ q)
IH = β§-P-invar {p = p}{q} π ih
P-id2 : β{ΞΉ} β P β ΞΉ π¦ β« (p βΜ q) β π¦ β« (p βΜ q)
P-id2{ΞΉ} PKpq .β«-proof π¨ kA = PKpq .β«-proof π¨ (P-expa {β = β}{ΞΉ} kA)
```
#### V preserves identities
Finally, we prove the analogous preservation lemmas for the closure operator `V`.
```agda
module _
{Ξ± Οα΅ β ΞΉ Ο : Level}
{π¦ : Pred(Algebra Ξ± Οα΅) (Ξ± β Οα΅ β ov β)}
{X : Type Ο}
{p q : Term X}
where
private aβΞΉ = Ξ± β Οα΅ β β β ΞΉ
V-id1 : π¦ β« (p βΜ q) β V β ΞΉ π¦ β« (p βΜ q)
V-id1 Ο .β«-proof π© (π¨ , (β¨
A , pβ¨
A , Aβ€β¨
A) , BimgA) =
H-id1{β = aβΞΉ}{π¦ = S aβΞΉ (P {Ξ² = Ξ±}{Οα΅}β ΞΉ π¦)} spKβ§pq .β«-proof π© (π¨ , (spA , BimgA))
where
spA : π¨ β S aβΞΉ (P {Ξ² = Ξ±}{Οα΅}β ΞΉ π¦)
spA = β¨
A , (pβ¨
A , Aβ€β¨
A)
spKβ§pq : S aβΞΉ (P β ΞΉ π¦) β« (p βΜ q)
spKβ§pq = S-id1{β = aβΞΉ} (P-id1{β = β} {π¦ = π¦} Ο)
V-id2 : V β ΞΉ π¦ β« (p βΜ q) β π¦ β« (p βΜ q)
V-id2 Vpq .β«-proof π¨ kA = Vpq .β«-proof π¨ (V-expa β ΞΉ kA)
Lift-id1 : β{Ξ² Οα΅} β π¦ β« (p βΜ q) β Level-closure{Ξ±}{Οα΅}{Ξ²}{Οα΅} β π¦ β« (p βΜ q)
Lift-id1 pKq .β«-proof π¨ (π© , kB , Bβ
A) Ο = Goal
where
open Environment π¨
open Setoid (Domain π¨) using (_β_)
Goal : β¦ p β§ β¨$β© Ο β β¦ q β§ β¨$β© Ο
Goal = β§-I-invar π¨ p q (pKq .β«-proof π© kB) Bβ
A Ο
```
#### Class identities
From `V-id1` it follows that if π¦ is a class of structures, then the set of identities
modeled by all structures in `π¦` is equivalent to the set of identities modeled by all
structures in `V π¦`. In other terms, `Th (V π¦)` is precisely the set of identities
modeled by `π¦`. We formalize this observation as follows.
```agda
classIds-β-VIds : π¦ β« (p βΜ q) β (p , q) β Th (V β ΞΉ π¦)
classIds-β-VIds pKq = V-id1 pKq
VIds-β-classIds : (p , q) β Th (V β ΞΉ π¦) β π¦ β« (p βΜ q)
VIds-β-classIds Thpq = V-id2 Thpq
```