---
layout: default
title : "Legacy.Base.Varieties.Properties module (The Agda Universal Algebra Library)"
date : "2021-06-24"
author: "agda-algebras development team"
---
### <a id="properties-of-the-models-relation">Properties of the models relation</a>
We prove some closure and invariance properties of the relation `β§`. In particular,
we prove the following facts (which we use later in our proof of Birkhoff's HSP Theorem).
* [Algebraic invariance](#algebraic-invariance-of-models). `β§` is an *algebraic invariant*
(stable under isomorphism).
* [Subalgebraic invariance](#subalgebraic-invariance). Identities modeled by a
class of algebras are also modeled by all subalgebras of algebras in the class.
* [Product invariance](#product-invariance-of-models). Identities modeled by a class of
algebras are also modeled by all products of algebras in the class.
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
open import Overture using ( π ; π₯ ; Signature )
module Legacy.Base.Varieties.Properties {π : 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 ( Level ; _β_ )
open import Relation.Unary using ( Pred ; _β_ ; _β_ ; β )
open import Axiom.Extensionality.Propositional
using () renaming ( Extensionality to funext )
open import Relation.Binary.PropositionalEquality
using ( _β‘_ ; refl ; module β‘-Reasoning ; cong )
open import Overture using ( β£_β£ ; β₯_β₯ ; _β»ΒΉ )
open import Legacy.Base.Functions using ( IsInjective ; β-injective )
open import Legacy.Base.Equality using ( SwellDef ; DFunExt )
open import Legacy.Base.Algebras {π = π} using ( Algebra ; Lift-Alg ; ov ; β¨
)
open import Legacy.Base.Homomorphisms {π = π} using ( hom ; β-hom ; _β
_ ; mkiso )
using ( Lift-β
; β
-sym ; β
-trans )
open import Legacy.Base.Terms {π = π} using ( Term ; π» ; lift-hom ; _β¦_β§ )
using ( comm-hom-term ; interp-prod )
using ( term-agreement )
open import Legacy.Base.Subalgebras {π = π} using ( _β€_ ; SubalgebraOfClass )
using ( isoβinjective )
open import Legacy.Base.Varieties.EquationalLogic
{π = π} using ( _β§_β_ ; _β«_β_ )
```
#### <a id="algebraic-invariance-of-models">Algebraic invariance of β§</a>
The binary relation β§ would be practically useless if it were not an *algebraic
invariant* (invariant under isomorphism).
```agda
open Term
open β‘-Reasoning
open _β
_
module _ (wd : SwellDef){Ξ± Ξ² Ο : Level}{X : Type Ο}{π¨ : Algebra Ξ±}
(π© : Algebra Ξ²)(p q : Term X) where
β§-I-invar : π¨ β§ p β q β π¨ β
π© β π© β§ p β q
β§-I-invar Apq (mkiso f g fβΌg gβΌf) x =
(π© β¦ p β§) x β‘β¨ i p β©
(π© β¦ p β§) ((β£ f β£ β β£ g β£) β x) β‘β¨ (ii p) β»ΒΉ β©
β£ f β£ ((π¨ β¦ p β§) (β£ g β£ β x)) β‘β¨ cong β£ f β£ (Apq (β£ g β£ β x)) β©
β£ f β£ ((π¨ β¦ q β§) (β£ g β£ β x)) β‘β¨ ii q β©
(π© β¦ q β§) ((β£ f β£ β β£ g β£) β x) β‘β¨ (i q)β»ΒΉ β©
(π© β¦ q β§) x β
where
i : β t β (π© β¦ t β§) x β‘ (π© β¦ t β§) Ξ» xβ β β£ f β£ (β£ g β£ (x xβ))
i t = wd Ο Ξ² (π© β¦ t β§) x (β£ f β£ β β£ g β£ β x) Ξ» i β ( fβΌg (x i))β»ΒΉ
ii : β t
β β£ f β£((π¨ β¦ t β§) Ξ» xβ β β£ g β£(x xβ)) β‘ (π© β¦ t β§) Ξ» xβ β β£ f β£(β£ g β£(x xβ))
ii t = comm-hom-term (wd π₯ Ξ²) π© f t (β£ g β£ β x)
```
In the above proof we showed `π© β§ p β q` by showing that `π© β¦ p β§ β‘ π© β¦ q β§` holds
*extensionally*, that is, `β x, π© β¦ p β§ x β‘ π© β¦q β§ x`.
#### <a id="lift-invariance-of-models">Lift-invariance of β§</a>
The `β§` relation is also invariant under the algebraic lift and lower operations.
```agda
module _ (wd : SwellDef){Ξ± Ξ² Ο : Level}{X : Type Ο}{π¨ : Algebra Ξ±} where
β§-Lift-invar : (p q : Term X) β π¨ β§ p β q β Lift-Alg π¨ Ξ² β§ p β q
β§-Lift-invar p q Apq = β§-I-invar wd (Lift-Alg π¨ _) p q Apq Lift-β
β§-lower-invar : (p q : Term X) β Lift-Alg π¨ Ξ² β§ p β q β π¨ β§ p β q
β§-lower-invar p q lApq = β§-I-invar wd π¨ p q lApq (β
-sym Lift-β
)
```
#### <a id="subalgebraic-invariance">Subalgebraic invariance of β§</a>
Identities modeled by an algebra `π¨` are also modeled by every subalgebra of `π¨`,
which fact can be formalized as follows.
```agda
module _ (wd : SwellDef){Ο : Level}{π€ π¦ : Level}{X : Type Ο} where
β§-S-invar : {π¨ : Algebra π€}(π© : Algebra π¦){p q : Term X}
β π¨ β§ p β q β π© β€ π¨ β π© β§ p β q
β§-S-invar {π¨} π© {p}{q} Apq Bβ€A b = (β₯ Bβ€A β₯) (ΞΎ b)
where
h : hom π© π¨
h = β£ Bβ€A β£
ΞΎ : β b β β£ h β£ ((π© β¦ p β§) b) β‘ β£ h β£ ((π© β¦ q β§) b)
ΞΎ b = β£ h β£((π© β¦ p β§) b) β‘β¨ comm-hom-term (wd π₯ π€) π¨ h p b β©
(π¨ β¦ p β§)(β£ h β£ β b) β‘β¨ Apq (β£ h β£ β b) β©
(π¨ β¦ q β§)(β£ h β£ β b) β‘β¨ (comm-hom-term (wd π₯ π€) π¨ h q b)β»ΒΉ β©
β£ h β£((π© β¦ q β§) b) β
```
Next, identities modeled by a class of algebras is also modeled by all subalgebras
of the class. In other terms, every term equation `p β q` that is satisfied by all
`π¨ β π¦` is also satisfied by every subalgebra of a member of `π¦`.
```agda
β§-S-class-invar : {π¦ : Pred (Algebra π€)(ov π€)}(p q : Term X)
β π¦ β« p β q β (π© : SubalgebraOfClass π¦) β β£ π© β£ β§ p β q
β§-S-class-invar p q Kpq (π© , π¨ , SA , (ka , Bβ
SA)) =
β§-S-invar π© {p}{q}((Kpq ka)) (h , hinj)
where
h : hom π© π¨
h = β-hom π© π¨ (to Bβ
SA) β£ snd SA β£
hinj : IsInjective β£ h β£
hinj = β-injective (isoβinjective Bβ
SA) β₯ snd SA β₯
```
#### <a id="product-invariance-of-models">Product invariance of β§</a>
An identity satisfied by all algebras in an indexed collection is also satisfied
by the product of algebras in that collection.
```agda
module _ (fe : DFunExt)(wd : SwellDef)
{Ξ± Ξ² Ο : Level}{I : Type Ξ²}
(π : I β Algebra Ξ±){X : Type Ο} where
β§-P-invar : (p q : Term X) β (β i β π i β§ p β q) β β¨
π β§ p β q
β§-P-invar p q πpq a = goal
where
ΞΎ : (Ξ» i β (π i β¦ p β§) (Ξ» x β (a x) i)) β‘ (Ξ» i β (π i β¦ q β§) (Ξ» x β (a x) i))
ΞΎ = fe Ξ² Ξ± Ξ» i β πpq i (Ξ» x β (a x) i)
goal : (β¨
π β¦ p β§) a β‘ (β¨
π β¦ q β§) a
goal = (β¨
π β¦ p β§) a β‘β¨ interp-prod (wd π₯ (Ξ± β Ξ²)) p π a β©
(Ξ» i β (π i β¦ p β§)(Ξ» x β (a x)i)) β‘β¨ ΞΎ β©
(Ξ» i β (π i β¦ q β§)(Ξ» x β (a x)i)) β‘β¨ (interp-prod (wd π₯ (Ξ± β Ξ²)) q π a)β»ΒΉ β©
(β¨
π β¦ q β§) a β
```
An identity satisfied by all algebras in a class is also satisfied by the product
of algebras in the class.
```agda
β§-P-class-invar : (π¦ : Pred (Algebra Ξ±)(ov Ξ±)){p q : Term X}
β π¦ β« p β q β (β i β π i β π¦) β β¨
π β§ p β q
β§-P-class-invar π¦ {p}{q}Ο Kπ = β§-P-invar p q Ξ» i β Ο (Kπ i)
```
Another fact that will turn out to be useful is that a product of a collection of
algebras models ``p β q`` if the lift of each algebra in the collection models ``p β q``.
```agda
β§-P-lift-invar : (p q : Term X) β (β i β Lift-Alg (π i) Ξ² β§ p β q) β β¨
π β§ p β q
β§-P-lift-invar p q Ξ± = β§-P-invar p q Aipq
where
Aipq : β i β (π i) β§ p β q
Aipq i = β§-lower-invar wd p q (Ξ± i)
```
#### <a id="homomorphisc-invariance-of-models">Homomorphic invariance of β§</a>
If an algebra `π¨` models an identity `p β q`, then the pair `(p , q)`
belongs to the kernel of every homomorphism `Ο : hom (π» X) π¨` from the term
algebra to `π¨`; that is, every homomorphism from `π» X` to `π¨` maps `p` and
`q` to the same element of `π¨`.
```agda
module _ (wd : SwellDef){Ξ± Ο : Level}{X : Type Ο}{π¨ : Algebra Ξ±} where
β§-H-invar : {p q : Term X}(Ο : hom (π» X) π¨) β π¨ β§ p β q β β£ Ο β£ p β‘ β£ Ο β£ q
β§-H-invar {p}{q}Ο Ξ² = β£ Ο β£ p β‘β¨ i p β©
β£ Ο β£((π» X β¦ p β§) β) β‘β¨ ii p β©
(π¨ β¦ p β§) (β£ Ο β£ β β) β‘β¨ Ξ² (β£ Ο β£ β β ) β©
(π¨ β¦ q β§) (β£ Ο β£ β β) β‘β¨ (ii q)β»ΒΉ β©
β£ Ο β£ ((π» X β¦ q β§) β) β‘β¨ (i q)β»ΒΉ β©
β£ Ο β£ q β
where
i : β t β β£ Ο β£ t β‘ β£ Ο β£ ((π» X β¦ t β§) β)
i t = cong β£ Ο β£(term-agreement(wd π₯ (ov Ο)) t)
ii : β t β β£ Ο β£ ((π» X β¦ t β§) β) β‘ (π¨ β¦ t β§) (Ξ» x β β£ Ο β£ (β x))
ii t = comm-hom-term (wd π₯ Ξ±) π¨ Ο t β
```
More generally, an identity is satisfied by all algebras in a class if and only if
that identity is invariant under all homomorphisms from the term algebra `π» X`
into algebras of the class. More precisely, if `π¦` is a class of `π`-algebras and
`π`, `π` terms in the language of `π`, then,
π¦ β§ p β q β β π¨ β π¦, β Ο : hom (π» X) π¨, Ο β (π» X)β¦ p β§ = Ο β (π» X)β¦ q β§.
```agda
module _ (wd : SwellDef){Ξ± Ο : Level}{X : Type Ο}{π¦ : Pred (Algebra Ξ±)(ov Ξ±)} where
β§-H-class-invar : {p q : Term X}
β π¦ β« p β q β β π¨ Ο β π¨ β π¦ β β a
β β£ Ο β£ ((π» X β¦ p β§) a) β‘ β£ Ο β£ ((π» X β¦ q β§) a)
β§-H-class-invar {p = p}{q} Ο π¨ Ο ka a = ΞΎ
where
ΞΎ : β£ Ο β£ ((π» X β¦ p β§) a) β‘ β£ Ο β£ ((π» X β¦ q β§) a)
ΞΎ = β£ Ο β£ ((π» X β¦ p β§) a) β‘β¨ comm-hom-term (wd π₯ Ξ±) π¨ Ο p a β©
(π¨ β¦ p β§)(β£ Ο β£ β a) β‘β¨ (Ο ka) (β£ Ο β£ β a) β©
(π¨ β¦ q β§)(β£ Ο β£ β a) β‘β¨ (comm-hom-term (wd π₯ Ξ±) π¨ Ο q a)β»ΒΉ β©
β£ Ο β£ ((π» X β¦ q β§) a) β
β§-H-class-coinvar : {p q : Term X}
β (β π¨ Ο β π¨ β π¦ β β a β β£ Ο β£ ((π» X β¦ p β§) a) β‘ β£ Ο β£ ((π» X β¦ q β§) a))
β π¦ β« p β q
β§-H-class-coinvar {p}{q} Ξ² {π¨} ka = goal
where
Ο : (a : X β β£ π¨ β£) β hom (π» X) π¨
Ο a = lift-hom π¨ a
goal : π¨ β§ p β q
goal a = (π¨ β¦ p β§)(β£ Ο a β£ β β) β‘β¨(comm-hom-term (wd π₯ Ξ±) π¨ (Ο a) p β)β»ΒΉ β©
(β£ Ο a β£ β (π» X β¦ p β§)) β β‘β¨ Ξ² π¨ (Ο a) ka β β©
(β£ Ο a β£ β (π» X β¦ q β§)) β β‘β¨ (comm-hom-term (wd π₯ Ξ±) π¨ (Ο a) q β) β©
(π¨ β¦ q β§)(β£ Ο a β£ β β) β
```