Written by Nate Soares, et al. last updated

A monoid is a pair where is a set and is an associative binary operator with an identity. is often interpreted as concatenation; data structures that support concatenation and have an "empty element" (such as lists, strings, and the natural numbers under addition) are examples of monoids.

Monoids are algebraic structures. We write for the application of to , which must be defined. is commonly abbreviated when can be inferred from context. The monoid axioms (which govern the behavior of ) are as follows.

  1. (Closure) For all in , is also in .
  2. (Associativity) For all in , .
  3. (Identity) There is an in such that, for all in ,

The axiom of closure says that , i.e. that combining two elements of using yields another element of . In other words, is closed under .

The axiom of associativity says that is an associative operation, which justifies omitting parenthesis when describing the application of to many elements in sequence..

The axiom of identity says that there is some element in that treats as "empty": If you apply to and , then simply returns . The identity is unique: Given two elements and that satisfy the axiom of identity, we have Thus, we can speak of "the identity" of . is often written or .

Equivalently, a monoid is a category with exactly one object.

Monoids are semigroups equipped with an identity. Groups are monoids with inverses. For more on how monoids relate to other algebraic structures, refer to the tree of algebraic structures.

Notation

Given a monoid , we say " forms a monoid under ." For example, the set of finite bitstrings forms a monoid under concatenation: The set of finite bitstrings is closed under concatenation; concatenation is an associative operation; and the empty bitstring is a finite bitstring that acts like an identity under concatenation.

is called the underlying set of , and is called the monoid operation. is usually abbreviated . is generally allowed to substitute for when discussing the monoid. For example, we say that the elements are "in ," and sometimes write "" or talk about the "elements of ."

Examples

Bitstrings form a monoid under concatenation, with the empty string as the identity.

The set of finite lists of elements drawn from (for any set ) form a monoid under concatenation, with the empty list as the identity.

The natural numbers form a monid under addition, with as the identity.

Monoids have found some use in functional programming languages such as Haskell and Scala, where they are used to generalize over data types in which values can be "combined" (by some operation ) and which include an "empty" value (the identity).