Setoid.Terms.Operations¶
Term Operations for Setoid Algebras¶
This section presents the Setoid.Terms.Operations module of the Agda Universal Algebra Library.
Here we define term operations which are simply terms interpreted in a particular algebra, and we prove some compatibility properties of term operations.
It turns out that the intepretation of a term is the same as the free-lift
(modulo argument order and assuming function extensionality).
module _ {π¨ : Algebra {π = π} Ξ± Οα΅} where open Algebra π¨ using ( Interp ) open Setoid π»[ π¨ ] using ( _β_ ; refl ) open Environment π¨ using ( β¦_β§ ) free-lift-interp : (Ξ· : X β π[ π¨ ])(p : Term {π = π} X) β β¦ p β§ β¨$β© Ξ· β (free-lift{π¨ = π¨} Ξ·) p free-lift-interp Ξ· (β x) = refl free-lift-interp Ξ· (node f t) = cong Interp (β‘.refl , (free-lift-interp Ξ·) β t) module _ {π : Signature π π₯}{X : Type Ο} where open Algebra (π» {π = π} X) using ( Interp ) renaming (Domain to TX ) open Setoid TX using ( _β_ ; refl ) open Environment (π» {π = π} X) using ( β¦_β§ ; ββEqual ) open SetoidReasoning TX term-interp : (f : OperationSymbolsOf π){s t : ArityOf π f β Term {π = π} X} β (β i β s i β t i) β β Ξ· β β¦ node f s β§ β¨$β© Ξ· β β¦ node f t β§ β¨$β© Ξ· term-interp f {s}{t} st Ξ· = cong Interp (β‘.refl , Ξ» i β ββEqual (s i) (t i) (st i) Ξ· ) term-agreement : (p : Term {π = π} X) β p β β¦ p β§ β¨$β© β term-agreement (β x) = refl term-agreement (node f t) = cong Interp (β‘.refl , (Ξ» i β term-agreement (t i)))
Interpretation of terms in product algebras¶
interp-prod says that interpreting a term in a product is the
same as interpreting it in each factor and collecting the results: for every term
p and every environment Ο, the value of p in β¨
π under Ο agrees, at each
coordinate i, with the value of p in π i under the i-th component of Ο.
This is the term-level counterpart of the way β¨
of
Setoid.Algebras.Products interprets operation symbols in the first place,
and the proof is the induction that says so: the variable case is reflexivity, and
the operation case pushes the induction hypothesis through the product's
Interp.
module _ {X : Type Ο }{I : Type ΞΉ}(π : I β Algebra {π = π} Ξ± Οα΅) where open Algebra (β¨ π) using (Interp) renaming ( Domain to β¨ A ) open Setoid β¨ A using ( _β_ ; refl ) open Environment (β¨ π) using () renaming ( β¦_β§ to β¦_β§β ) open Environment using ( β¦_β§ ; ββEqual ) interp-prod : (p : Term {π = π} X) β β Ο β β¦ p β§β β¨$β© Ο β Ξ» i β (β¦ π i β§ p) β¨$β© Ξ» x β (Ο x) i interp-prod (β x) = Ξ» Ο i β ββEqual (π i) (β x) (β x) β-isRefl Ξ» x' β (Ο x) i interp-prod (node f t) = Ξ» Ο i β cong Interp (β‘.refl , (Ξ» j k β interp-prod (t j) Ο k)) i
Compatibility of terms¶
We now prove the most important fact about term operations
(comm-hom-term): every term commutes with every homomorphism.
module _ {π : Signature π π₯} {π¨ : Algebra {π = π} Ξ± Οα΅} {π© : Algebra {π = π} Ξ² Οα΅} ((h , hhom) : hom π¨ π©) where open Algebra π© using (Interp) open Setoid π»[ π© ] using ( _β_ ; refl ) open Environment π¨ using () renaming ( β¦_β§ to β¦_β§β ) open Environment π© using () renaming ( β¦_β§ to β¦_β§β ) open SetoidReasoning π»[ π© ] open IsHom comm-hom-term : (t : Term {π = π} X) (a : X β π[ π¨ ]) β h β¨$β© (β¦ t β§β β¨$β© a) β β¦ t β§β β¨$β© Ξ» i β h β¨$β© a i comm-hom-term (β x) a = refl comm-hom-term (node f t) a = goal where goal : h β¨$β© (β¦ node f t β§β β¨$β© a) β β¦ node f t β§β β¨$β© Ξ» i β h β¨$β© a i goal = begin h β¨$β© (β¦ node f t β§β β¨$β© a) ββ¨ compatible (hhom) β© (f ^ π©)(Ξ» i β h β¨$β© (β¦ t i β§β β¨$β© a)) ββ¨ cong Interp (β‘.refl , Ξ» i β comm-hom-term (t i) a) β© β¦ node f t β§β β¨$β© (Ξ» j β h β¨$β© a j) β
Substitution¶
A substitution from Y to X is simply a function from Y to X, and the
application of a substitution is represented as follows.
_[_]s : {Ο : Level}{X Y : Type Ο} β Term {π = π} Y β (Y β X) β Term {π = π} X (β y) [ Ο ]s = β (Ο y) (node f t) [ Ο ]s = node f Ξ» i β t i [ Ο ]s
Alternatively, we may want a substitution that replaces each variable symbol in Y,
not with an element of X, but with a term from Term X.
-- Substerm X Y, an inhabitant of which replaces each variable symbol in Y with a term from Term X. Substerm : {π : Signature π π₯}(X Y : Type Ο) β Type (ov {π = π} Ο) Substerm {π = π} X Y = (y : Y) β Term {π = π} X -- Application of a Substerm. _[_]t : {X Y : Type Ο } β Term {π = π} Y β Substerm {π = π} X Y β Term {π = π} X (β y) [ Ο ]t = Ο y (node f t) [ Ο ]t = node f Ξ» z β (t z) [ Ο ]t