Setoid.Terms.Properties¶
Basic properties of terms on setoids¶
This is the Setoid.Terms.Properties module of the Agda Universal Algebra Library.
This module proves that the term algebra is free.
Given an algebra π¨ and an arbitrary map h : X β π[ π¨ ] sending variables to
elements,
free-liftextendshto all ofπ» Xby structural recursion,free-lift-funcshows the extension respects term equality,lift-homshows the extension is a homomorphism,free-uniquesupplies the other half of the universal property: two homomorphisms out ofπ» Xthat agree on the variables agree everywhere.
Together the last two are the universal property of π» X: a map on
variables extends to a homomorphism, and to only one. The existence half is used
in Setoid.Varieties.HSP where lift-hom maps the term algebra
into each algebra of a class.
free-unique is a terminal result here, with no consumer in
the live trees at present. lift-of-epi-is-epi records that
surjectivity of the variable assignment survives the lift, which is how
epimorphisms out of the term algebra are obtained.
The term algebra π» X is absolutely free (or universal, or initial) for
algebras in the signature π. That is, for every π-algebra π¨, the following hold.
- Every function from
πtoπ[ π¨ ]lifts to a homomorphism fromπ» Xtoπ¨. - The homomorphism that exists by item 1 is unique.
We now formalize this, starting with the fact that every map from X to π[ π¨ ]
lifts to a map from π[ π» X ] to π[ π¨ ] in a natural way, by induction on the
structure of the given term.
module _ {π : Signature π π₯}{π¨ : Algebra {π = π} Ξ± Ο}(h : X β π[ π¨ ]) where open Algebra π¨ using ( Interp ) renaming ( Domain to A ) open Setoid A using ( _β_ ; reflexive ) open Algebra (π» {π = π} X) using () renaming ( Domain to TX ) free-lift : π[ π» {π = π} X ] β π[ π¨ ] free-lift (β x) = h x free-lift (node f t) = (f ^ π¨) (Ξ» i β free-lift (t i)) free-lift-of-surj-isSurj : isSurj{π¨ = setoid X}{π© = A} h β isSurj{π¨ = TX}{π© = A} free-lift free-lift-of-surj-isSurj hE {y} = mp p where p : Img h β y p = hE mp : Img h β y β Img free-lift β y mp (eq a x) = eq (β a) x free-lift-func : TX βΆ A free-lift-func β¨$β© x = free-lift x free-lift-func .βcong = flcong where open _β_ flcong : β {s t} β s β t β free-lift s β free-lift t flcong (rfl xβ‘y) = reflexive (cong h xβ‘y) flcong (gnl sβt) = βcong Interp (refl , flcong β sβt)
Naturally, at the base step of the induction, when the term has the form generator
x, the free lift of h agrees with h. For the inductive step, when the given term
has the form node f t, the free lift is defined as follows: Assuming (the induction
hypothesis) that we know the image of each subterm t i under the free lift of h,
define the free lift at the full term by applying f ^ π¨ to the images of the subterms.
The free lift so defined is a homomorphism by construction. Indeed, here is the trivial proof.
lift-hom : hom (π» X) π¨ lift-hom = free-lift-func , hhom where hfunc : TX βΆ A hfunc = free-lift-func hcomp : compatible-map (π» X) π¨ free-lift-func hcomp {f}{a} = βcong Interp (refl , (Ξ» i β (βcong free-lift-func){a i} β-isRefl)) hhom : IsHom (π» X) π¨ hfunc hhom = record { compatible = Ξ»{f}{a} β hcomp{f}{a} }
If we further assume that each of the mappings from X to π[ π¨ ] is surjective,
then the homomorphisms constructed with free-lift and lift-hom are
epimorphisms, as we now prove.
lift-of-epi-is-epi : isSurj{π¨ = setoid X}{π© = A} h β IsSurjective free-lift-func lift-of-epi-is-epi hE = isSurjβIsSurjective free-lift-func (free-lift-of-surj-isSurj hE)
Finally, we prove that the homomorphism is unique. Recall, when we proved this in the module
Legacy.Base.Terms.Properties, we needed function extensionality. Here, by using setoid equality,
we can omit the swelldef hypothesis we needed previously to prove free-unique.
module _ {π : Signature π π₯}{π¨ : Algebra {π = π} Ξ± Ο}{gh hh : hom (π» X) π¨} where open Algebra π¨ using ( Interp ) renaming ( Domain to A ) open Setoid A using ( _β_ ) open Algebra (π» {π = π} X) using () renaming ( Domain to TX ) open SetoidReasoning A open _β_ open IsHom private g h : TX βΆ A g = projβ gh h = projβ hh free-unique : (β x β g β¨$β© (β x) β h β¨$β© (β x)) β β (t : Term {π = π} X) β g β¨$β© t β h β¨$β© t free-unique p (β x) = p x free-unique p (node f t) = begin g β¨$β© (node f t) ββ¨ compatible (projβ gh) β© (f ^ π¨)(Ξ» i β (g β¨$β© (t i))) ββ¨ βcong Interp (refl , Ξ» i β free-unique p (t i)) β© (f ^ π¨)(Ξ» i β (h β¨$β© (t i))) βΛβ¨ compatible (projβ hh) β© h β¨$β© (node f t) β
Naturality of the free lift¶
Existence (lift-hom) and uniqueness (free-unique) together say that π» X is a
free (initial) object, and freeness always brings a third, slightly less quotable
property: the assignment "generator map β¦ induced homomorphism" is natural in the
target algebra. Concretely, lifting Ξ· : X β π[ π¨ ] into π¨ and then applying a
homomorphism h : π¨ βΆ π© is the same as lifting the composite map h β Ξ· into π©
directly:
lift-hom Ξ·
π» X βββββββββββββββββββββ π¨
β² β
β² β h
lift-hom β² β
(h β Ξ·) β β
π©
The proof is a one-liner, and that is the point: both routes around the triangle
are homomorphisms π» X βΆ π© that agree on the generators (both send β x to
h (Ξ· x), definitionally), so free-unique forces them to agree on every term. No
induction over terms appears here β it is already packaged inside free-unique.
This is the way category theory pays rent: theorems about all terms become
theorems about generators only.
(The same fact in environment form β h (β¦ t β§ a) β β¦ t β§ (h β a) β is
comm-hom-term in Setoid.Terms.Operations, proved there by direct induction;
free-lift-interp, also in that module, mediates between the two phrasings. The
companion naturality in the signature argument, where the algebra is fixed and the
signature varies along a morphism, is reduct-interp in
Setoid.Varieties.Invariance.)
module _ {π : Signature π π₯}{π¨ : Algebra {π = π} Ξ± Οα΅}{π© : Algebra {π = π} Ξ² Οα΅}(h : hom π¨ π©)(Ξ· : X β π[ π¨ ]) where open Setoid π»[ π© ] using () renaming ( _β_ to _βα΅_ ; refl to reflα΅ ) free-lift-natural : (t : Term {π = π} X) β projβ h β¨$β© free-lift{π¨ = π¨} Ξ· t βα΅ free-lift{π¨ = π©} (Ξ» x β projβ h β¨$β© Ξ· x) t free-lift-natural = free-unique {π¨ = π©} {gh = β-hom (lift-hom Ξ·) h} {hh = lift-hom (Ξ» x β projβ h β¨$β© Ξ· x)} (Ξ» _ β reflα΅)