This section presents the Algebras.Algebras module of the Agda Universal Algebra Library.

{-# OPTIONS --without-K --exact-split --safe #-} module Algebras.Algebras where open import Algebras.Signatures public

Recall, the type `Signature π π₯`

was defined in the Algebras.Signatures module as the dependent pair type `Ξ£ F κ π Μ , (F β π₯ Μ)`

, and the type \af{Op} of operation symbols was defined in Relations.Discrete as the function type `Op I A = (I β A) β A`

.

For a fixed signature `π : Signature π π₯`

and universe `π€`

, we define the type of *algebras in the signature* π (or π-*algebras*) and with *domain* (or *carrier*) of type `π€ Μ`

as follows.^{1}

Algebra : (π€ : Universe)(π : Signature π π₯) β π β π₯ β π€ βΊ Μ Algebra π€ π = Ξ£ A κ π€ Μ , -- the domain Ξ f κ β£ π β£ , Op (β₯ π β₯ f) A -- the basic operations

We might refer to inhabitants of this type as β-*algebras* because their domains can be of arbitrary type and need not be truncated at some level and, in particular, need to be a set. (See the Relations.Truncation module.)

We might take this opportunity to define the type of 0-*algebras*, that is, algebras whose domains are sets, which is probably closer to what most of us think of when doing informal universal algebra. However, below we will only need to know that the domains of certain algebras are sets in a few places in the UALib, so it seems preferable to work with general (β-)algebras throughout and then explicitly postulate uniquness of identity proofs when and only when necessary.

Some people prefer to represent algebraic structures in type theory using records, and for those folks we offer the following (equivalent) definition.

record algebra (π€ : Universe) (π : Signature π π₯) : (π β π₯ β π€) βΊ Μ where constructor mkalg field univ : π€ Μ op : (f : β£ π β£) β ((β₯ π β₯ f) β univ) β univ

This representation of algebras as inhabitants of a record type is equivalent to the representation using Sigma types in the sense that a bi-implication between the two representations is obvious.

module _ {π : Signature π π₯} where open algebra algebraβAlgebra : algebra π€ π β Algebra π€ π algebraβAlgebra π¨ = (univ π¨ , op π¨) Algebraβalgebra : Algebra π€ π β algebra π€ π Algebraβalgebra π¨ = mkalg β£ π¨ β£ β₯ π¨ β₯

We now define a convenient shorthand for the interpretation of an operation symbol. This looks more similar to the standard notation one finds in the literature as compared to the double bar notation we started with, so we will use this new notation almost exclusively in the remaining modules of the UALib.

_Μ_ : (π : β£ π β£)(π¨ : Algebra π€ π) β (β₯ π β₯ π β β£ π¨ β£) β β£ π¨ β£ π Μ π¨ = Ξ» π β (β₯ π¨ β₯ π) π

So, if `π : β£ π β£`

is an operation symbol in the signature `π`

, and if `π : β₯ π β₯ π β β£ π¨ β£`

is a tuple of the appropriate arity, then `(π Μ π¨) π`

denotes the operation `π`

interpreted in `π¨`

and evaluated at `π`

.

Recall, in the section on level lifting and lowering, we described the difficulties one may encounter when working with a noncumulative universe hierarchy. We made a promise to provide some domain-specific level lifting and level lowering methods. Here we fulfill this promise by supplying a couple of bespoke tools designed specifically for our operation and algebra types.

module _ {π : Universe} {I : π Μ}{A : π€ Μ} where open Lift Lift-op : Op I A β (π¦ : Universe) β Op I (Lift{π¦} A) Lift-op f π¦ = Ξ» x β lift (f (Ξ» i β lower (x i))) module _ {π : Signature π π₯} where Lift-alg : Algebra π€ π β (π¦ : Universe) β Algebra (π€ β π¦) π Lift-alg π¨ π¦ = Lift β£ π¨ β£ , (Ξ» (π : β£ π β£) β Lift-op (π Μ π¨) π¦) open algebra Lift-alg-record-type : algebra π€ π β (π¦ : Universe) β algebra (π€ β π¦) π Lift-alg-record-type π¨ π¦ = mkalg (Lift (univ π¨)) (Ξ» (f : β£ π β£) β Lift-op ((op π¨) f) π¦)

What makes the `Lift-alg`

type so useful for resolving type level errors involving algebras is the nice properties it possesses. Indeed, the UALib contains formal proofs of the following facts.

`Lift-alg`

is a homomorphism (see Homomorphisms.Basic)`Lift-alg`

is an algebraic invariant (see Homomorphisms.Isomorphisms)`Lift-alg`

of a subalgebra is a subalgebra (see Subalgebras.Subalgebras)`Lift-alg`

preserves identities) (see Varieties.EquationalLogic)

We now define the function `compatible`

so that, if `π¨`

is an algebra and `R`

a binary relation, then `compatible π¨ R`

will represents the assertion that `R`

is *compatible* with all basic operations of `π¨`

.
<!β Recall (from Relations.Discrete) that informally this means for every operation symbol `π : β£ π β£`

and all pairs `u v : β₯ π β₯ π β β£ π¨ β£`

of tuples from the domain of π¨, the following implication holds:

Β Β `(Ξ i κ I , R (u i) (u i))`

Β Β `β`

Β Β `R ((π Μ π¨) u) ((π Μ π¨) v)`

.

In other terms, `β π β (π Μ π¨) |: R`

. β>
The formal definition is immediate since all the work is done by the relation `|:`

(which we already defined in Relations.Discrete).

compatible : (π¨ : Algebra π€ π) β Rel β£ π¨ β£ π¦ β π β π€ β π₯ β π¦ Μ compatible π¨ R = β π β (π Μ π¨) |: R

Recall, the `|:`

type was defined in Relations.Discrete module.

In the Relations.Continuous module, we defined a function called `cont-compatible-op`

to represent the assertion that a given continuous relation is compatible with a given operation. With that, it is easy to define a function, which we call `cont-compatible`

, representing compatibility of a continuous relation with all operations of an algebra. Similarly, we define the analogous `dep-compatible`

function for the (even more general) type of *dependent relations*.

module _ {π€ π¦ : Universe} {I : π₯ Μ} {π : Signature π π₯} where open import Relations.Continuous using (ContRel; DepRel; cont-compatible-op; dep-compatible-op) cont-compatible : (π¨ : Algebra π€ π) β ContRel I β£ π¨ β£ π¦ β π β π€ β π₯ β π¦ Μ cont-compatible π¨ R = Ξ π κ β£ π β£ , cont-compatible-op (π Μ π¨) R dep-compatible : (π : I β Algebra π€ π) β DepRel I (Ξ» i β β£ π i β£) π¦ β π β π€ β π₯ β π¦ Μ dep-compatible π R = Ξ π κ β£ π β£ , dep-compatible-op (Ξ» i β π Μ (π i)) R

^{β
} Sections marked with an asterisk include new types that are more abstract and general (and frankly more interesting) than the ones presented in other sections. Consequently, such sections expect a higher degree of sophistication and/or effort from the reader/user. Moreover, the types defined in starred sections are used in only a few other places in the Agda UALib, so they may be safely skimmed over or skipped.

^{[1]} In classical universal algebra, the domain of an algebra `π¨`

is usualled called the βuniverseβ of `π¨`

. We avoid this terminology and reserve universe for use in defining the type hierarchy. (See the Agda Universes</a> section of the Overture.Preliminaries module.