Monoids: One Structure Behind Sums, Strings, and Functions

Abstract algebra can feel like math has floated away from reality. Monoids are a good antidote to that feeling because they are abstract, but not empty. They show up in ordinary addition, string concatenation, function composition, movement instructions, data aggregation, and parallel computing.

A monoid is a set with an operation satisfying three rules:

  1. Closure: combining two things from the set gives another thing in the set.
  2. Associativity: grouping does not change the result.
  3. Identity: there is a do-nothing element.

That definition is short. The examples are where it becomes meaningful.

Addition as a monoid

The nonnegative integers with addition form a monoid.

  • Closure: adding two nonnegative integers gives a nonnegative integer.
  • Associativity: (a + b) + c = a + (b + c).
  • Identity: 0 does nothing because a + 0 = a.

This example may feel too obvious. That is useful. A good first abstraction should begin with something students already trust.

Strings as a monoid

Now consider strings of text with concatenation. If we combine “math” and “circle,” we get “mathcircle.” The set of all strings is closed under concatenation. Concatenation is associative:

("a" + "b") + "c" = "a" + ("b" + "c")

Both give “abc.” The identity is the empty string, because adding it changes nothing.

This example shows why a monoid is not just arithmetic wearing a new name. The operation can be something other than plus. The objects can be something other than numbers.

Why associativity matters

Associativity is the quiet rule that makes large computations flexible. Suppose a computer has to add a million numbers. If addition is associative, it can split the work into chunks, add each chunk separately, and then combine the results. The grouping does not matter.

The same idea works for strings, matrices under multiplication, and many kinds of data summaries. If an operation is associative, we can rearrange the parentheses to fit the computation.

This matters in parallel computing. A non-associative operation is harder to distribute because chunking the input might change the answer.

Students should see that associativity is not just a property to check on homework. It is a permission slip for reorganizing work.

Function composition

Functions from a set to itself form a monoid under composition. If f and g are both functions from the set to itself, then f ∘ g is also a function from the set to itself. Composition is associative:

(f ∘ g) ∘ h = f ∘ (g ∘ h)

The identity element is the identity function, which sends every input to itself.

This example connects algebra to transformations. A move in a game, a rotation of a shape, or a state update in a program can be treated as a function. Combining moves is composition.

Not everything is a monoid

Subtraction on integers is not associative. For example:

(10 - 3) - 2 = 5

but

10 - (3 - 2) = 9

So integers under subtraction do not form a monoid. The operation exists, but the structure is not stable under regrouping.

Positive integers under multiplication almost form a monoid, and actually they do: closure holds, associativity holds, and 1 is the identity. Positive integers under addition do not form a monoid if 0 is not included, because there is no additive identity in the set.

This is an important lesson: the set and operation must be considered together. A structure is not just an operation. It is a relationship between a collection and a way of combining its elements.

A COSMO sorting activity

Give students cards. Each card has a set and operation:

  • integers with addition
  • integers with subtraction
  • strings with concatenation
  • nonzero real numbers with multiplication
  • positive integers with addition
  • functions from a set to itself with composition
  • lists with append
  • maximum of two numbers

Ask students to sort the cards into “monoid,” “not monoid,” and “not sure.” The discussion is more valuable than the sorting. Students have to test closure, associativity, and identity one at a time.

For the operation “maximum,” the real numbers form a monoid if we include an identity such as negative infinity. But the ordinary real numbers do not contain negative infinity, so the identity issue becomes subtle. That kind of edge case is where students learn to be precise.

The deeper message

Monoids teach students that different-looking situations can share the same operating logic. Sums, strings, functions, and transformations are not the same objects. But if they can be combined associatively with an identity, some reasoning transfers between them.

That is what abstraction does at its best. It does not erase examples. It lets examples talk to each other.

← Back to All Resources