Agda UALib ↑


Basic Definitions

This section presents the Terms.Basic module of the Agda Universal Algebra Library.

The theoretical background that begins each subsection below is based on Cliff Bergman’s textbook Bergman (2012), specifically, Section 4.3. Apart from notation, our presentation is similar to Bergman’s, but we will be more concise, omitting some details and all examples, in order to more quickly arrive at our objective, which is to use type theory to express the concepts and formalize them in the Agda language. We refer the reader to Bergman (2012) for a more complete exposition of classical (informal) universal algebra.


{-# OPTIONS --without-K --exact-split --safe #-}

open import Algebras.Signatures using (Signature; π“ž; π“₯)

module Terms.Basic {𝑆 : Signature π“ž π“₯} where

open import Homomorphisms.HomomorphicImages{𝑆 = 𝑆} public

The type of terms

Fix a signature 𝑆 and let X denote an arbitrary nonempty collection of variable symbols. Assume the symbols in X are distinct from the operation symbols of 𝑆, that is X ∩ ∣ 𝑆 ∣ = βˆ….

By a word in the language of 𝑆, we mean a nonempty, finite sequence of members of X βˆͺ ∣ 𝑆 ∣. We denote the concatenation of such sequences by simple juxtaposition.

Let Sβ‚€ denote the set of nullary operation symbols of 𝑆. We define by induction on n the sets 𝑇ₙ of words over X βˆͺ ∣ 𝑆 ∣ as follows (cf. Bergman (2012) Def. 4.19):

𝑇₀ := X βˆͺ Sβ‚€ and π‘‡β‚™β‚Šβ‚ := 𝑇ₙ βˆͺ 𝒯ₙ

where 𝒯ₙ is the collection of all 𝑓 𝑑 such that 𝑓 : ∣ 𝑆 ∣ and 𝑑 : βˆ₯ 𝑆 βˆ₯ 𝑓 β†’ 𝑇ₙ. (Recall, βˆ₯ 𝑆 βˆ₯ 𝑓 is the arity of the operation symbol 𝑓.)

We define the collection of terms in the signature 𝑆 over X by Term X := ⋃ₙ 𝑇ₙ. By an 𝑆-term we mean a term in the language of 𝑆.

The definition of Term X is recursive, indicating that an inductive type could be used to represent the semantic notion of terms in type theory. Indeed, such a representation is given by the following inductive type.


data Term {𝓧 : Universe}(X : 𝓧 Μ‡ ) : ov 𝓧 Μ‡  where
  generator : X β†’ Term X
  node : (f : ∣ 𝑆 ∣)(𝑑 : βˆ₯ 𝑆 βˆ₯ f β†’ Term X) β†’ Term X

open Term

This is a very basic inductive type that represents each term as a tree with an operation symbol at each node and a variable symbol at each leaf (generator).

Notation. As usual, the type X represents an arbitrary collection of variable symbols. Recall, ov 𝓧 Μ‡ is our shorthand notation for the universe π“ž βŠ” π“₯ βŠ” 𝓧 ⁺ Μ‡. Throughout this module the name of the first constructor of the Term type will remain generator. However, in all of the modules that follow this one, we will use the shorthand β„Š to denote the generator constructor.

The term algebra

For a given signature 𝑆, if the type Term X is nonempty (equivalently, if X or ∣ 𝑆 ∣ is nonempty), then we can define an algebraic structure, denoted by 𝑻 X and called the term algebra in the signature 𝑆 over X. Terms are viewed as acting on other terms, so both the domain and basic operations of the algebra are the terms themselves.

In Agda the term algebra can be defined as simply as one could hope.


𝑻 : {𝓧 : Universe}(X : 𝓧 Μ‡ ) β†’ Algebra (ov 𝓧) 𝑆
𝑻 X = Term X , node

The universal property

The term algebra 𝑻 X is absolutely free (or universal, or initial) for algebras in the signature 𝑆. That is, for every 𝑆-algebra 𝑨, the following hold.

  1. Every function from 𝑋 to ∣ 𝑨 ∣ lifts to a homomorphism from 𝑻 X to 𝑨.
  2. The homomorphism that exists by item 1 is unique.

We now prove this in Agda, 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 _ {𝓀 𝓧 : Universe}{X : 𝓧 Μ‡ } where

 free-lift : (𝑨 : Algebra 𝓀 𝑆)(h : X β†’ ∣ 𝑨 ∣) β†’ ∣ 𝑻 X ∣ β†’ ∣ 𝑨 ∣

 free-lift _ h (generator x) = h x

 free-lift 𝑨 h (node f 𝑑) = (f Μ‚ 𝑨) (Ξ» i β†’ free-lift 𝑨 h (𝑑 i))

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 𝑑, the free lift is defined as follows: Assuming (the induction hypothesis) that we know the image of each subterm 𝑑 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 : (𝑨 : Algebra 𝓀 𝑆) β†’ (X β†’ ∣ 𝑨 ∣) β†’ hom (𝑻 X) 𝑨

 lift-hom 𝑨 h = free-lift 𝑨 h , Ξ» f a β†’ ap (f Μ‚ 𝑨) refl

Finally, we prove that the homomorphism is unique. This requires funext π“₯ 𝓀 (i.e., function extensionality at universe levels π“₯ and 𝓀) which we postulate by making it part of the premise in the following function type definition.


 free-unique : funext π“₯ 𝓀 β†’ (𝑨 : Algebra 𝓀 𝑆)(g h : hom (𝑻 X) 𝑨)
  β†’            (βˆ€ x β†’ ∣ g ∣ (generator x) ≑ ∣ h ∣ (generator x))
               ----------------------------------------------------
  β†’            βˆ€ (t : Term X) β†’  ∣ g ∣ t ≑ ∣ h ∣ t

 free-unique _ _ _ _ p (generator x) = p x

 free-unique fe 𝑨 g h p (node 𝑓 𝑑) = ∣ g ∣ (node 𝑓 𝑑)  β‰‘βŸ¨ βˆ₯ g βˆ₯ 𝑓 𝑑 ⟩
                                    (𝑓 Μ‚ 𝑨)(∣ g ∣ ∘ 𝑑)  β‰‘βŸ¨ Ξ± ⟩
                                    (𝑓 Μ‚ 𝑨)(∣ h ∣ ∘ 𝑑)  β‰‘βŸ¨ (βˆ₯ h βˆ₯ 𝑓 𝑑)⁻¹ ⟩
                                    ∣ h ∣ (node 𝑓 𝑑)   ∎
  where
  Ξ± : (𝑓 Μ‚ 𝑨) (∣ g ∣ ∘ 𝑑) ≑ (𝑓 Μ‚ 𝑨) (∣ h ∣ ∘ 𝑑)
  Ξ± = ap (𝑓 Μ‚ 𝑨) (fe Ξ» i β†’ free-unique fe 𝑨 g h p (𝑑 i))

Let’s account for what we have proved thus far about the term algebra. If we postulate a type X : 𝓧 Μ‡ (representing an arbitrary collection of variable symbols) such that for each 𝑆-algebra 𝑨 there is a map from X to the domain of 𝑨, then it follows that for every 𝑆-algebra 𝑨 there is a homomorphism from 𝑻 X to ∣ 𝑨 ∣ that β€œagrees with the original map on X,” by which we mean that for all x : X the lift evaluated at generator x is equal to the original function evaluated at x.

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 : {𝑨 : Algebra 𝓀 𝑆}{hβ‚€ : X β†’ ∣ 𝑨 ∣}
                      ---------------------------------
  β†’                   Epic hβ‚€ β†’ Epic ∣ lift-hom 𝑨 hβ‚€ ∣

 lift-of-epi-is-epi {𝑨}{hβ‚€} hE y = Ξ³
  where
  h₀⁻¹y = Inv hβ‚€ (hE y)

  Ξ· : y ≑ ∣ lift-hom 𝑨 hβ‚€ ∣ (generator h₀⁻¹y)
  Ξ· = (InvIsInv hβ‚€ (hE y))⁻¹

  Ξ³ : Image ∣ lift-hom 𝑨 hβ‚€ ∣ βˆ‹ y
  Ξ³ = eq y (generator h₀⁻¹y) Ξ·

The lift-hom and lift-of-epi-is-epi types will be called to action when such epimorphisms are needed later (e.g., in the Varieties module).


↑ Terms Terms.Operations β†’