Monoids
Keywords: main

Next: The Typed Polymorphic -Calculus Up: Technical Background Previous: The Relational Model

##
Monoids

In this section, all notions and notations relating to monoids as they are used in this paper are recalled and justified.

Mathematically, a monoid is a non-empty set equipped with an associative internal binary operation and an identity element for this operation. Formally, let S be a set, a function from to S, and ; then, is a monoid iff, for any x, y, z in S:

| (3)

and

| (4)

Most familiar mathematical binary operations define monoids. For example, taking the set of natural numbers , and the set of boolean values , the following are monoids:

- ,
- ,
- ,
- ,
- .

The operations of these monoids are so familiar that they need not be explicated. For us, they have a ``built -in'' semantics that allows us to compute with them since primary school. Indeed, we shall refer to such readily interpreted monoids as primitive monoids.3

Note that the definition of a monoid does not preclude additional algebraic structure. Such structure may be specified by other equations augmenting the basic monoid equational theory given by the conjunction of equations (3) and (4). For example, all five monoids listed above are commutative; namely, they also obey equation (5):

| (5)

for any x, y. In addition, the three last ones (i.e., , , and ) are also idempotent; namely, they also obey equation (6):

| (6)

for any x.

Not all monoids are primitive monoids. That is, one may define a monoid purely syntactically whose operation only builds a syntactic structure rather than being interpreted using some semantic computation. For example, linear lists have such a structure: the operation is list concatenation and builds a list out of two lists; its identity element is the empty list. A syntactic monoid may also have additional algebraic structure. For example, the monoid of bags is also defined as a commutative syntactic monoid with the disjunct union operation and the empty bag as identity. Or, the monoid of sets is a commutative and idempotent syntactic monoid with the union operation and the empty set as identity.

Because they are not interpreted, syntactic monoids pose a problem as far as representation of its elements is concerned. To illustrate this, let us consider an empty-theory algebraic structure; that is, one without any equations--not even associativity nor identity. Let us take such a structure with one binary operation on, say, the natural numbers . Saying that is a ``syntactic'' operation means that it constructs a syntactic term (i.e., an expression tree) by composing two other syntactic terms. We thus can define the set of -terms on some base set, say the natural numbers, inductively as the limit where,

| (7)

Clearly, the set is well defined and so is the operation over it. Indeed, is a bona fide function from to mapping two terms t1 and t2 in into a unique term in --namely, . This is why is called the syntactic algebra.4

Let us now assume that the operation is associative--i.e., that -terms verify Equation (3). Note that this equation defines a (syntactic) congruence on which identifies terms such as, say, and . In fact, for such an associative operation, the set defined in Equation (7) is not the appropriate domain. Rather, the right domain is the quotient set whose elements are (syntactic) congruence classes modulo associativity of . Therefore, this creates an ambiguity of representation of the syntactic structures.5

Similarly, more algebraic structure defined by larger equational theories induces coarser quotients of the empty-theory algebra by putting together in common congruence classes all the syntactic expressions that can be identified modulo the theory's equations. The more equations, the more ambiguous the syntactic structures of expressions. Mathematically, this poses no problem as one can always abstract away from individuals to congruence classes. However, operationally one must resort to some concrete artifact to obtain a unique representation for all members of the same congruence class. One way is to devise a canonical representation into which to transform all terms. For example, an associative operation could systematically ``move'' nested subtrees from its left argument to its right argument--in effect using Equation (3) as a one-way rewrite rule. However, while this is possible for some equational theories, it is not so in general--e.g., take commutativity.6

From a programming standpoint (which is ours), we can abstract away from the ambiguity of canonical representations of syntactic monoid terms using a flat notation. For example, in LISP and Prolog, a list is seen as the (flat) sequence of its constituents. Typically, a programmer writes [1,2,1] to represent the list whose elements are 1, 2 and 1 in this order, and does not care (nor need s/he be aware) of its concrete representation. A set--i.e., a commutative idempotent syntactic monoid--is usually denoted by the usual mathematical notation , implicitly relying on disallowing duplicate elements, not minding the order in which the elements appear. A bag, or multiset--i.e., a commutative but non-idempotent syntactic monoid--uses a similar notation, allowing duplicate elements but paying no heed to the order in wich they appear; i.e., is the bag containing 1 twice, and 2 once.

Syntactic monoids are quite useful for programming as they provide adquate data structures to represent collections of objects of a given type. Thus, we refer to them as collection monoids. Now, a definition such as Equation (7) for a syntactic monoid, although sound mathematically, is not quite adequate for programming purposes. This is because it defines the operations on two distinct types of elements; namely, the base elements (here natural numbers) and constructed elements. In programming, it is desirable that operations be given a crisp type. A way to achieve this is by systematically ``wrapping'' each base element x into a term such as . This ``wrapping'' is achieve by associating to the monoid a function from the base set into the monoid domain called its unit injection. For example, if is the list monoid operation for concatenating two lists, and one may view the list [a,b,c] as . Similarly, the set is viewed as , and the bag as . Clearly, this bases the constructions on an isomorphic view of the base set rather than the base set itself, while using a uniform type for the monoid operator. Also, because the type of the base elements is irrelevant for the construction other than imposing the constraint that all such elements be of the same type, we present a collection monoid as a polymorphic data type. This justifies the formal view of monoids we give next using the programming notion of type.

Because it is characterized by its operation , a monoid is often simply referred to as . Thus, a monoid operation is used as a subscript to denote its characteristic attributes. Namely, for a monoid ,

- is its type (i.e., ),

- is its identity element,

- is its equational theory (i.e., a subset of the set , where C stands for ``commutative'' and I for ``idempotent'');

and, if it is a collection monoid,

- is its type constructor (i.e., ),

- is its unit injection.

Table 1 summarizes the monoid attributes of a few usual monoids.

Table 1: Attributes of a few common monoids
+ |  | 0 |
* |  | 1 |
|  | 0 |
|  |  | [] | [x] |
Primitive monoids | Collection monoids

Next: The Typed Polymorphic -Calculus Up: Technical Background Previous: The Relational Model