---
layout: default
title : "Setoid.Terms.Operations module (The Agda Universal Algebra Library)"
date : "2021-09-25"
author: "agda-algebras development team"
---
#### 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.
<!--
```agda
{-# OPTIONS --cubical-compatible --exact-split --safe #-}
open import Overture using (π ; π₯ ; Signature)
module Setoid.Terms.Operations {π : Signature π π₯} where
open import Agda.Primitive using () renaming ( Set to Type )
open import Data.Product using ( _,_ )
open import Function.Base using ( _β_ )
open import Function.Bundles using () renaming ( Func to _βΆ_ )
open import Level using ( Level )
open import Relation.Binary using ( Setoid )
open import Relation.Binary.PropositionalEquality as β‘ using ( _β‘_ )
import Relation.Binary.Reasoning.Setoid as SetoidReasoning
open import Overture using ( projβ ; projβ ; OperationSymbolsOf ; ArityOf )
open import Overture.Terms {π = π} using ( Term )
open import Setoid.Algebras {π = π} using ( Algebra ; _^_ ; ov ; β¨
)
open import Setoid.Homomorphisms {π = π} using ( hom ; IsHom )
open import Setoid.Terms.Properties {π = π} using ( free-lift )
open import Setoid.Terms.Basic {π = π}
using ( module Environment ; π» ; _β_ ; β-isRefl )
open Term
open _βΆ_ using ( cong ) renaming ( to to _β¨$β©_ )
private variable
Ξ± Οα΅ Ξ² Οα΅ Ο Ο ΞΉ : Level
X : Type Ο
```
-->
It turns out that the intepretation of a term is the same as the `free-lift`
(modulo argument order and assuming function extensionality).
```agda
module _ {π¨ : Algebra Ξ± Οα΅} where
open Algebra π¨ using ( Interp ) renaming (Domain to A )
open Setoid A using ( _β_ ; refl ) renaming ( Carrier to β£Aβ£ )
open Environment π¨ using ( β¦_β§ )
free-lift-interp : (Ξ· : X β β£Aβ£)(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 _ {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
```agda
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 two important facts about term operations. The first of these, which is
used very often in the sequel, asserts that every term commutes with every
homomorphism.
```agda
module _ {π¨ : Algebra Ξ± Οα΅}{π© : Algebra Ξ² Οα΅}(hh : hom π¨ π©) where
open Algebra π¨ using () renaming (Domain to A )
open Setoid A using () renaming ( Carrier to β£Aβ£ )
open Algebra π© using () renaming (Domain to B ; Interp to Interpβ )
open Setoid B using ( _β_ ; refl )
open Environment π¨ using () renaming ( β¦_β§ to β¦_β§β )
open Environment π© using () renaming ( β¦_β§ to β¦_β§β )
open SetoidReasoning B
open IsHom
private
h : A βΆ B
h = projβ hh
comm-hom-term :
(t : Term X) (a : X β β£Aβ£) β 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 (projβ hh) β©
(f ^ π©)(Ξ» i β h β¨$β© (β¦ t i β§β β¨$β© a)) ββ¨ cong Interpβ (β‘.refl , Ξ» i β comm-hom-term (t i) a) β©
(f ^ π©)(Ξ» i β β¦ t i β§β β¨$β© Ξ» j β h β¨$β© a j) ββ¨ refl β©
β¦ 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.
```agda
_[_]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`.
```agda
Substerm : (X Y : Type Ο) β Type (ov Ο)
Substerm X Y = (y : Y) β Term X
_[_]t : {X Y : Type Ο } β Term Y β Substerm X Y β Term X
(β y) [ Ο ]t = Ο y
(node f t) [ Ο ]t = node f Ξ» z β (t z) [ Ο ]t
```