{-# OPTIONS --without-K --exact-split --safe #-} open import Overture using (π ; π₯ ; Signature) module Setoid.Varieties.FreeAlgebras {π : Signature π π₯} where -- Imports from Agda and the Agda Standard Library ------------------------------- 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 ( _β_ ; id ) renaming ( Func to _βΆ_ ) open import Level using ( Level ; _β_) open import Relation.Binary using ( Setoid ) open import Relation.Unary using ( Pred ; _β_ ; _β_ ) open import Relation.Binary.PropositionalEquality as β‘ using (_β‘_) -- Imports from the Agda Universal Algebra Library ------------------------------- open import Overture using ( β£_β£ ; β₯_β₯ ) open import Setoid.Relations using ( fkerPred ) open import Setoid.Functions using ( eq ; IsSurjective ) open import Base.Terms {π = π} using ( β ) open import Setoid.Algebras {π = π} using ( Algebra ; ov ; Lift-Alg ) open import Setoid.Homomorphisms {π = π} using ( epi ; IsEpi ; IsHom ; hom ; epiβhom ; β-epi ; ToLift-epi ) open import Setoid.Terms {π = π} using ( π» ; _β_ ; module Environment ; free-lift ; free-lift-interp ) open import Setoid.Varieties.Closure {π = π} using ( V ; S ) open import Setoid.Varieties.Preservation {π = π} using ( classIds-β-VIds ; S-id1 ) open import Setoid.Varieties.SoundAndComplete {π = π} using ( Eq ; _β«_ ; _βΜ_ ; _β’_βΉ_β_ ; Th ; Mod ; module Soundness ; module FreeAlgebra ) open _βΆ_ using ( cong ) renaming ( f to _β¨$β©_ ) open Algebra using ( Domain )
In the code below, X
will play the role of an arbitrary collection of variables; it would suffice to take X
to be the cardinality of the largest algebra in π¦, but since we donβt know that cardinality, we leave X
aribtrary for now.
Alternatively, we could let X
be the product of all algebras in the class π¦
, like so.
π : Type oΞ±
π = Carrier ( Domain (β¨
(π{π¦ = S π¦})) )
module FreeHom (Ο : Level){Ξ± Οα΅ β : Level} {π¦ : Pred(Algebra Ξ± Οα΅) (Ξ± β Οα΅ β ov β)} where private ΞΉ = ov(Ο β Ξ± β Οα΅ β β) open Eq
We now define the algebra π½
, which plays the role of the relatively free algebra, along with the natural epimorphism epiπ½ : epi (π» π) π½
from π» π
to π½
.
The relatively free algebra (relative to Th π¦
) is called M
and is derived from TermSetoid π
and TermInterp π
and imported from the EquationalLogic module.
-- β indexes the collection of equations modeled by π¦ β : Type ΞΉ β = Ξ£[ eq β Eq{Ο} ] π¦ β« ((lhs eq) βΜ (rhs eq)) β° : β β Eq β° (eqv , p) = eqv β°β’[_]βΉThπ¦ : (X : Type Ο) β β{p q} β β° β’ X βΉ p β q β π¦ β« (p βΜ q) β°β’[ X ]βΉThπ¦ x π¨ kA = sound (Ξ» i Ο β β₯ i β₯ π¨ kA Ο) x where open Soundness β° π¨ ----------- THE RELATIVELY FREE ALGEBRA ----------- open FreeAlgebra {ΞΉ = ΞΉ}{I = β} β° using ( π½[_] )
Finally, we define an epimorphism from π» X
onto the relatively free algebra
π½[ X ]
. Of course, the kernel of this epimorphism will be the congruence of
π» X
defined by identities modeled by (S π¦
, hence) π¦
.
epiπ½[_] : (X : Type Ο) β epi (π» X) π½[ X ] epiπ½[ X ] = h , hepi where open Algebra π½[ X ] using() renaming ( Domain to F ; Interp to InterpF ) open Setoid F using() renaming ( _β_ to _βFβ_ ; refl to reflF ) open Algebra (π» X) using() renaming (Domain to TX) open Setoid TX using() renaming ( _β_ to _βTβ_ ; refl to reflT ) open _β_ ; open IsEpi ; open IsHom c : β {x y} β x βTβ y β x βFβ y c (rfl {x}{y} β‘.refl) = reflF c (gnl {f}{s}{t} x) = cong InterpF (β‘.refl , c β x) h : TX βΆ F h = record { f = id ; cong = c } hepi : IsEpi (π» X) π½[ X ] h compatible (isHom hepi) = cong h reflT isSurjective hepi {y} = eq y reflF homπ½[_] : (X : Type Ο) β hom (π» X) π½[ X ] homπ½[ X ] = epiβhom (π» X) π½[ X ] epiπ½[ X ] homπ½[_]-is-epic : (X : Type Ο) β IsSurjective β£ homπ½[ X ] β£ homπ½[ X ]-is-epic = IsEpi.isSurjective (snd (epiπ½[ X ])) class-models-kernel : β{X p q} β (p , q) β fkerPred β£ homπ½[ X ] β£ β π¦ β« (p βΜ q) class-models-kernel {X = X}{p}{q} pKq = β°β’[ X ]βΉThπ¦ pKq kernel-in-theory : {X : Type Ο} β fkerPred β£ homπ½[ X ] β£ β Th (V β ΞΉ π¦) kernel-in-theory {X = X} {p , q} pKq vkA x = classIds-β-VIds {β = β} {p = p}{q} (class-models-kernel pKq) vkA x module _ {X : Type Ο} {π¨ : Algebra Ξ± Οα΅}{sA : π¨ β S {Ξ² = Ξ±}{Οα΅} β π¦} where open Environment π¨ using ( Equal ) kerπ½βEqual : β{p q} β (p , q) β fkerPred β£ homπ½[ X ] β£ β Equal p q kerπ½βEqual{p = p}{q} x = S-id1{β = β}{p = p}{q} (β°β’[ X ]βΉThπ¦ x) π¨ sA π¦β«ββ°β’ : {X : Type Ο} β β{p q} β π¦ β« (p βΜ q) β β° β’ X βΉ p β q π¦β«ββ°β’ {p = p} {q} pKq = hyp ((p βΜ q) , pKq) where open _β’_βΉ_β_ using (hyp) ------------------------------------------------------------------------------ module _ {Ξ± Οα΅ β : Level} {π¦ : Pred(Algebra Ξ± Οα΅) (Ξ± β Οα΅ β ov β)} where private ΞΉ = ov(Ξ± β Οα΅ β β) open IsEpi ; open IsHom module lower-universe-version {π¨ : Algebra Ξ± Οα΅} where open FreeHom Ξ± {Ξ±}{Οα΅}{β}{π¦} open FreeAlgebra {ΞΉ = ΞΉ}{I = β} β° using ( π½[_] ) open Algebra π¨ renaming (Domain to A) using( Interp ) open Setoid A renaming ( Carrier to β£Aβ£ ) using ( trans ; sym ; refl ) π½-ModTh-epi : π¨ β Mod (Th (V β ΞΉ π¦)) β epi π½[ β£Aβ£ ] π¨ π½-ModTh-epi AβModThK = Ο , isEpi where Ο : (Domain π½[ β£Aβ£ ]) βΆ A _β¨$β©_ Ο = free-lift{π¨ = π¨} id cong Ο {p} {q} pq = trans (sym (free-lift-interp{π¨ = π¨} id p)) ( trans (AβModThK{p = p}{q} (kernel-in-theory pq) id ) ( free-lift-interp{π¨ = π¨} id q) ) isEpi : IsEpi π½[ β£Aβ£ ] π¨ Ο compatible (isHom isEpi) = cong Interp (β‘.refl , (Ξ» _ β refl)) isSurjective isEpi {y} = eq (β y) refl π½-ModTh-epi-lift : π¨ β Mod (Th (V β ΞΉ π¦)) β epi π½[ β£Aβ£ ] (Lift-Alg π¨ (ov Ξ±) (ov Ξ±)) π½-ModTh-epi-lift AβModThK = β-epi (π½-ModTh-epi (Ξ» {p q} β AβModThK{p = p}{q})) ToLift-epi module _ -- higher-universe-version -- (HSP theorem needs π¨ in higher universe level) {π¨ : Algebra (Ξ± β Οα΅ β β) (Ξ± β Οα΅ β β)} where open FreeHom (Ξ± β Οα΅ β β) {Ξ±}{Οα΅}{β}{π¦} open FreeAlgebra {ΞΉ = ΞΉ}{I = β} β° using ( π½[_] ) open Algebra π¨ renaming (Domain to A) using( Interp ) open Setoid A renaming ( Carrier to β£Aβ£ ) using ( trans ; sym ; refl ) π½-ModTh-epi : π¨ β Mod (Th (V β ΞΉ π¦)) β epi π½[ β£Aβ£ ] π¨ π½-ModTh-epi AβModThK = Ο , isEpi where Ο : (Domain π½[ β£Aβ£ ]) βΆ A _β¨$β©_ Ο = free-lift{π¨ = π¨} id cong Ο {p} {q} pq = trans (sym (free-lift-interp{π¨ = π¨} id p)) ( trans (AβModThK{p = p}{q} (kernel-in-theory pq) id ) ( free-lift-interp{π¨ = π¨} id q) ) isEpi : IsEpi π½[ β£Aβ£ ] π¨ Ο compatible (isHom isEpi) = cong Interp (β‘.refl , (Ξ» _ β refl)) isSurjective isEpi {y} = eq (β y) refl π½-ModTh-epi-lift : π¨ β Mod (Th (V β ΞΉ π¦)) β epi π½[ β£Aβ£ ] (Lift-Alg π¨ ΞΉ ΞΉ) π½-ModTh-epi-lift AβModThK = β-epi (π½-ModTh-epi (Ξ» {p q} β AβModThK{p = p}{q})) ToLift-epi