Monoids: the humble structure behind text strings, logic gates and surfaces
Gluing words end to end, adding whole numbers and combining true-or-false values with AND all share the same bare skeleton. Each has a way of combining two things where grouping does not matter, plus a do-nothing element. Mathematicians call that skeleton a monoid, and it turns up everywhere from programming to the shapes of surfaces.
Formally, a monoid is a set with a binary operation that is associative, so that combining a with b and then c gives the same result as combining a with the combination of b and c, together with an identity element that leaves everything unchanged. The natural numbers under addition form one, with 0 as the identity; under multiplication they form another, with 1. A monoid in which every element can also be undone is a group, so groups are the special, more demanding case. Order may still matter: nothing requires a combined with b to equal b combined with a.
Strings of characters show this well. Concatenation is associative, the empty string is the identity, and with at least two letters available the operation is not commutative, since joining cat to dog differs from joining dog to cat. This is the free monoid on an alphabet, and computer scientists use related monoids to describe finite-state machines and concurrent processes, and to study automata and formal languages.
Logic offers a tidy count. Of the 16 possible operations on two truth values, exactly four are associative, commutative and have an identity. AND and XNOR use True as their identity; OR and XOR use False. Functions from a set to itself form a monoid under composition, and for a set of n elements there are n to the power n of them.
One example is almost playful. Take compact surfaces and combine two by cutting a hole in each and sewing them together. The ordinary sphere acts as the identity, and every surface can be written using tori and projective planes, with the curious rule that three projective planes sewn together equal one torus plus one projective plane.
Source: Monoid