Monoid (source code)

= Monoid
{title2=$(M,\ast,e)$}
{wiki}

A <monoid> is a <semigroup> with a two-sided <identity element> $e$: $e\ast a=a\ast e=a$ for every element $a$. <Associativity> handles the grouping of a nonempty sequence; the <identity element> also supplies the result for an empty sequence. This makes the same rules apply to combining zero, one, or many contributions. <Group Theory (v4.01) by James S. Milne>{ref}.

The nonnegative <integers> $\{0,1,2,\ldots\}$ with <addition> form a <commutative monoid>, with <identity element> zero. They do not form a <group>: a positive <integer> has no <additive inverse> in that <set>. All <words over an alphabet> with <concatenation> form a <free monoid>, whose <identity element> is the <empty word>. The <full transformation monoid> consists of all <self-maps> of a <set>, with <function composition> and the <identity function>.

These examples explain why <monoids> are useful: accumulation needs an operation and a starting value, but it need not be reversible. Adding counts, joining <strings>, and composing transformations all share the same grouping and identity laws. Requiring every element to have an <inverse element> gives a <group>, a stronger structure suitable for reversible operations.