Setoid.Terms.Translation¶
Laws of term translation¶
This is the Setoid.Terms.Translation module of the Agda Universal Algebra Library.
The translation Ο βΆ t of terms along a signature morphism is defined in
Overture.Terms.Translation, where it needs nothing but the signatures.
Its laws, proved here, compare functions on node positions (Ξ» i β β¦) and therefore
live at the level of the equality-of-terms relation _β_ of Setoid.Terms.Basic
β the same division of labor as Term (Overture) versus π» X and _β_ (Setoid).
None of the laws below can be strengthened to propositional _β‘_ under --safe:
each compares position functions that agree pointwise but are not definitionally
equal, which is exactly the situation _β_ exists for.
Together the laws say that _βΆ_ is as well-behaved as it could possibly be β it is
a functorial family of monad morphisms:
βΆ-congβ translation respects term equality, soΟ βΆ_is a setoid function between term setoids (βΆ-funcpackages it as aFunc).βΆ-idandβΆ-ββ translating along the identity morphism changes nothing, and translating along a composite is translating twice: the assignmentΟ β¦ Ο βΆ_is a functor from the categorySigof signatures (Overture.Signatures.Morphisms) to term-setoid endomaps. This lifts the functoriality ofβ¦_β§(single applications, Setoid.Signatures.Functor) from one operation deep to arbitrarily deep terms.βΆ-subβ the monad morphism square: translating after substituting is substituting after translating,
_[ Ο ]
Termβ Y βββββββββββββββββββββββ Termβ X
β β
Ο βΆ_ β β Ο βΆ_
β β
Termβ Y βββββββββββββββββββββββ Termβ X
_[ (Ξ» y β Ο βΆ Ο y) ]
where the bottom edge substitutes the translated terms. In monad vocabulary
(Setoid.Terms.Monad), Ο βΆ_ commutes with the units (definitionally β
Ο βΆ β x is β x) and with the multiplications (this square), which is the
definition of a morphism between the term monads of πβ and πβ. Equivalently,
it is a functor between their Kleisli categories that is the identity on objects.
Looking one subissue ahead: M4-5f's theory interpretations replace the
symbol-to-symbol ΞΉ by a symbol-to-derived-term assignment, and βΆ-sub is the law
that makes interpretations compose β substitute first or interpret first, same
result.
Congruence: translation is a setoid function¶
Equal terms translate to equal terms. The leaf case is immediate (translation fixes
variables); at a node, the inductive hypotheses are consulted at the reindexed
positions, mirroring the node clause of _βΆ_ itself.
module _ {πβ πβ : Signature π π₯} {Ο : SigMorphism πβ πβ} where βΆ-cong : {s t : Term {π = πβ} X} β s β t β (Ο βΆ s) β (Ο βΆ t) βΆ-cong (rfl xβ‘y) = rfl xβ‘y βΆ-cong (gnl {f = f} ps) = gnl (Ξ» j β βΆ-cong (ps (ΞΊ Ο f j))) -- The packaged form: translation as a map of term setoids. βΆ-func : (X : Type Ο) β Func (TermSetoid {π = πβ} X) (TermSetoid {π = πβ} X) βΆ-func X β¨$β© t = Ο βΆ t βΆ-func X .cong = βΆ-cong
The monad-morphism square¶
Translation commutes with substitution. (It commutes with the units by definition:
Ο βΆ β x reduces to β x.)
βΆ-sub : (t : Term {π = πβ} Y) (Ο : Sub {π = πβ} X Y) β Ο βΆ t [ Ο ] β (Ο βΆ t) [ (Ξ» y β Ο βΆ Ο y) ] βΆ-sub (β y) Ο = β-isRefl βΆ-sub (node f ts) Ο = gnl (Ξ» j β βΆ-sub (ts (ΞΊ Ο f j)) Ο)
Functoriality in the signature morphism¶
Translating along the identity signature morphism is the identity (up to _β_ β the
node clause rebuilds the position function, so the two sides are pointwise, not
definitionally, equal), and translating along a composite is the composite of the
translations.
module _ {π : Signature π π₯} where βΆ-id : (t : Term {π = π} X) β (id-morphism βΆ t) β t βΆ-id (β x) = β-isRefl βΆ-id (node f ts) = gnl (Ξ» i β βΆ-id (ts i)) module _ {πβ πβ πβ : Signature π π₯} {Ο : SigMorphism πβ πβ} {Ο : SigMorphism πβ πβ} where βΆ-β : (t : Term {π = πβ} X) β (Ο ββ Ο) βΆ t β Ο βΆ (Ο βΆ t) βΆ-β (β x) = β-isRefl βΆ-β (node f ts) = gnl (Ξ» i β βΆ-β (ts (ΞΊ Ο f (ΞΊ Ο (ΞΉ Ο f) i))))