Binary Operations, Semigroups & Monoids

This deck builds the algebraic ladder from magma to semigroup to monoid from the ground up, treating closure, associativity, and identity as separate axioms that you must actually check. It targets the misconceptions that closure comes for free, that every operation is associative or commutative, and that an identity element is the same thing as an absorbing element. The free monoid of strings and the monoid of function composition anchor the ideas in computer science.

Subject: Foundations of Higher Mathematics · 122 slides · symbolic lesson

Open the interactive version of this deck · Homework for this lesson

What this lesson covers

The lesson, slide by slide

1. What you will be able to do

Objectives

This deck builds the first rung of abstract algebra: the ladder from a bare set-with-operation up to a monoid.

By the end you can:

1. Say exactly what a binary operation is, and check that a candidate operation is actually closed.

2. Test associativity and produce a counterexample when it fails.

3. Locate the identity element, prove it is unique, and separate it from an absorbing element.

4. Place a structure on the ladder magma to semigroup to monoid, and recognize the free monoid of strings and the composition monoid.

2. What survived from Cardinality II: Uncountability & the Continuum?

Warm-up

Discussion prompt

Before we open Binary Operations, Semigroups & Monoids: without looking back, what was the main idea of Cardinality II: Uncountability & the Continuum, and what could you do by the end of it that you could not do before?

Hint: One sentence for the idea, one for the skill. If the second one is blank, that is the part to revisit.

Answer:

That deck covers Cantor's diagonal argument that the reals are uncountable and Cantor's theorem that every set is strictly smaller than its power set, then the cardinal arithmetic of the continuum, the Continuum Hypothesis, and its independence from ZFC. It ends with the collision between set theory and computation: there are only countably many programs but uncountably many reals, so most reals must be uncomputable. It targets the misconceptions that the diagonal number is already in the list, that uncountable simply means infinite, that the Continuum Hypothesis is merely unproven rather than independent, and that a bijection between the line and the plane is impossible.

3. A binary operation combines two inputs into one output

Concept

Addition takes two numbers and returns a number. Concatenation takes two strings and returns a string. Abstractly, a binary operation is a function that eats an ordered pair from a set and returns a single element of the same set.

\[ \ast : S \times S \longrightarrow S \]

binary operation — A total function from the set of ordered pairs of S back into S. It must be defined for every pair, and the result must land inside S. We write the output of the pair (a, b) in infix form.

\[ \ast(a, b) \;=\; a \ast b \]

4. Closure is not a bonus, it is the definition

Concept

The phrase to internalize is closure: applying the operation to two members of the set never takes you outside the set. This is baked into the codomain being S.

\[ \forall a, b \in S \;:\; a \ast b \in S \]

So when someone hands you a set and a rule, the first question is never assumed: does the rule stay inside the set? If not, it is not a binary operation on that set at all.

5. Break it if you can: Closure is not a bonus, it is the definition

Counterexample

Discussion prompt

The phrase to internalize is closure: applying the operation to two members of the set never takes you outside the set. This is baked into the codomain being S.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

6. Picture it first: Picture the operation as a filled-in table

Picture it

Figure (svg): A 3 by 3 operation table with row and column headers a, b, c and every one of the nine cells filled in.

Discussion prompt

Read the picture before the words. What is this showing, and what is the one thing it is built to make obvious? Commit to an answer, then read on.

Hint: Name the parts, then say what changes between them — and if nothing changes, say what is being held still.

Answer:

For a small finite set, a binary operation is just a fully filled grid: rows indexed by the left input, columns by the right input, and every cell holds the output.

7. Picture the operation as a filled-in table

Intuition

For a small finite set, a binary operation is just a fully filled grid: rows indexed by the left input, columns by the right input, and every cell holds the output.

Figure (svg): A 3 by 3 operation table with row and column headers a, b, c and every one of the nine cells filled in.

Closure says every cell contains an element that is also a row and column header. A blank cell, or an entry from outside the set, breaks it.

8. By analogy: Picture the operation as a filled-in table

Analogy

Discussion prompt

Explain Picture the operation as a filled-in table by analogy to something with no Foundations of Higher Mathematics in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

For a small finite set, a binary operation is just a fully filled grid: rows indexed by the left input, columns by the right input, and every cell holds the output.

9. What has to happen first: Worked example: is subtraction an operation on the…

Ranking

Put in order

Put the moves of Worked example: is subtraction an operation on the naturals? into the order they have to happen.

  1. Write the closure requirement
  2. Probe a pair where the left input is smaller
  3. Conclude it is not closed on the naturals
  4. Verify the fix on the integers

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. A binary operation must return an element of the same set for every pair.

10. Worked example: is subtraction an operation on the naturals?

Worked example

Take the natural numbers (here starting at 0) with ordinary subtraction as the candidate rule. Is it a binary operation on that set?

Write the closure requirement

Why: A binary operation must return an element of the same set for every pair.

\[ \forall a, b \in \mathbb{N} \;:\; a - b \in \mathbb{N} \;? \]

Probe a pair where the left input is smaller

Why: To break a universal claim you only need one counterexample; small minus large is the danger zone.

\[ 3 - 5 \;=\; -2 \;\notin\; \mathbb{N} \]

Conclude it is not closed on the naturals

Why: One pair escaped the set, so the rule is not a function into the naturals.

Subtraction is a binary operation on the integers, where the result always stays inside. The set you choose is part of the claim.

Verify the fix on the integers

Why: Check the boundary case again in the larger set to confirm closure is restored.

\[ 3 - 5 = -2 \in \mathbb{Z}, \quad 5 - 3 = 2 \in \mathbb{Z} \]

11. is subtraction an operation on the naturals? — line by line

Picture it

Animation

Shows: Each line of the worked example "is subtraction an operation on the naturals?", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check the boundary case again in the larger set to confirm closure is restored.

12. Something is wrong here: assuming closure comes for free

Anomaly

Predict first

A student writes this, and it looks reasonable:

A strong student reads the naturals under subtraction and starts checking associativity, quietly assuming the operation is well defined.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: This treats closure as automatic, which is the whole error.

Check closure first, always. It is the entry ticket.

Why: This treats closure as automatic, which is the whole error.

13. Trap: assuming closure comes for free

Trap

The trap

A strong student reads the naturals under subtraction and starts checking associativity, quietly assuming the operation is well defined.

Skip straight to associativity

Why: This treats closure as automatic, which is the whole error.

\[ (a - b) - c \;\overset{?}{=}\; a - (b - c) \]

But the structure was already dead on arrival: subtraction leaves the naturals, so there is nothing to check.

The fix

Check closure first, always. It is the entry ticket.

Test membership of the output for a bad pair

Why: Closure is a universal statement, so one escaping pair settles it.

\[ 0 - 1 = -1 \notin \mathbb{N} \]

Verdict: not even a magma on the naturals. Only after closure passes do the deeper axioms become meaningful questions.

14. Decode the notation: Trap: assuming closure comes for free

Notation

Annotate

From Trap: assuming closure comes for free — read this one piece at a time. What is each part doing?

On: \( (a - b) - c \;\overset{?}{=}\; a - (b - c) \)

  • This treats closure as automatic, which is the whole error.
  • Closure is a universal statement, so one escaping pair settles it.

15. Notation: the operation is abstract, the symbol is a placeholder

Concept

We use a neutral star for a generic operation so nothing carries over from arithmetic. It might be addition, multiplication, concatenation, composition, maximum, or something exotic.

\[ a \ast b, \qquad a \cdot b, \qquad ab \]

Juxtaposition (writing ab) is the common shorthand once the operation is fixed. None of the familiar laws of numbers are assumed; each must be proved or refuted for the specific operation.

16. Teach it back: Notation: the operation is abstract, the symbol is a…

Explain it

Discussion prompt

Explain Notation: the operation is abstract, the symbol is a placeholder to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

We use a neutral star for a generic operation so nothing carries over from arithmetic. It might be addition, multiplication, concatenation, composition, maximum, or something exotic.

17. Associativity: regrouping does not change the result

Concept

Associativity is the law that lets you drop parentheses. It says the two ways of folding three inputs agree.

\[ \forall a, b, c \in S \;:\; (a \ast b) \ast c \;=\; a \ast (b \ast c) \]

It is a statement about grouping, not order. It never lets you swap inputs; it only lets you rebracket them.

18. Why associativity is the axiom that earns its keep

Intuition

With associativity a long chain has an unambiguous value no matter how you parenthesize it, so you can write it with no brackets at all.

\[ a \ast b \ast c \ast d \]

For a programmer this is exactly what makes a fold or reduce well defined and safe to run in parallel: you can split the chain anywhere and combine the pieces. Without it, the grouping you pick changes the answer.

19. Plan first: Worked example: subtraction on the integers is not…

Step zero

Discussion prompt

Worked example: subtraction on the integers is not associative — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Write both bracketings for a concrete triple

Answer:

  1. Write both bracketings for a concrete triple
  2. Evaluate the left grouping
  3. Evaluate the right grouping
  4. Verify the two results disagree

20. Worked example: subtraction on the integers is not associative

Worked example

Subtraction is closed on the integers, so it is a legitimate binary operation there. Is it associative?

Write both bracketings for a concrete triple

Why: One triple where the two sides differ refutes the universal law.

\[ (8 - 4) - 2 \quad\text{versus}\quad 8 - (4 - 2) \]

Evaluate the left grouping

Why: Innermost bracket first.

\[ (8 - 4) - 2 = 4 - 2 = 2 \]

Evaluate the right grouping

Why: The inner bracket is now on the right pair.

\[ 8 - (4 - 2) = 8 - 2 = 6 \]

Verify the two results disagree

Why: Two equals four minus two on the left but six on the right; a single counterexample is enough.

\[ 2 \neq 6 \;\Longrightarrow\; \text{subtraction is not associative} \]

21. subtraction on the integers is not associative — line by line

Picture it

Animation

Shows: Each line of the worked example "subtraction on the integers is not associative", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Two equals four minus two on the left but six on the right; a single counterexample is enough.

22. Guess the shape of the answer: Worked example: the averaging operation is…

Estimation

Predict first

On the rationals define the operation that returns the midpoint of its two inputs. It is closed and commutative. Is it associative?

Commit before you compute: what does Worked example: the averaging operation is not associative come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify the counterexample

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. Four versus two on the same triple confirms non-associativity directly.

23. Worked example: the averaging operation is not associative

Worked example

On the rationals define the operation that returns the midpoint of its two inputs. It is closed and commutative. Is it associative?

\[ a \ast b \;=\; \frac{a + b}{2} \]

Compute the left grouping on a test triple

Why: Take an easy triple to expose the asymmetry in weighting.

\[ (0 \ast 0) \ast 8 = 0 \ast 8 = \frac{0 + 8}{2} = 4 \]

Compute the right grouping

Why: The same three inputs, regrouped to the right.

\[ 0 \ast (0 \ast 8) = 0 \ast 4 = \frac{0 + 4}{2} = 2 \]

See why it fails structurally

Why: Averaging weights the earlier inputs less each time it is nested, so grouping shifts the weights.

\[ (a \ast b) \ast c = \tfrac{a}{4} + \tfrac{b}{4} + \tfrac{c}{2} \]

Verify the counterexample

Why: Four versus two on the same triple confirms non-associativity directly.

\[ 4 \neq 2 \;\Longrightarrow\; \text{averaging is not associative} \]

24. the averaging operation is not associative — line by line

Picture it

Animation

Shows: Each line of the worked example "the averaging operation is not associative", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Four versus two on the same triple confirms non-associativity directly.

25. Trap: assuming every operation is associative

Trap

The trap

Because plus and times are associative, it is tempting to treat associativity as a property operations just have.

So a student writes a bracket-free chain for subtraction or exponentiation and evaluates left to right without justification.

\[ a - b - c - d, \qquad a \wedge b \wedge c \]

The written expression is ambiguous for these operations, and different groupings give different numbers.

The fix

Associativity is a property to be proved, and many everyday operations lack it: subtraction, division, averaging, exponentiation.

Keep the brackets until associativity is established

Why: Only an associativity proof licenses dropping them.

\[ 2^{(2^{3})} = 2^{8} = 256 \;\neq\; (2^{2})^{3} = 4^{3} = 64 \]

Verified: exponentiation gives 256 one way and 64 the other, so the unbracketed tower is meaningless.

26. Break it on purpose: assuming every operation is associative

Break the constraint

Discussion prompt

The rule this trap just fixed:

Only an associativity proof licenses dropping them.

Now break it on purpose. Build a case that violates it and follow the consequences until something visibly fails. Where does the failure first show up — and would you have noticed it if you had not been looking?

Hint: The dangerous rules are the ones whose violation still produces an answer. If yours fails loudly, try to find one that fails quietly.

27. Magma and semigroup: the first two rungs

Concept

Now we name the ladder. A set with a single closed binary operation, and nothing else required, is a magma.

magma — A set S together with a binary operation on S. The only axiom is closure. No associativity, no identity.

semigroup — A magma whose operation is associative. Closure plus associativity, and nothing more.

\[ \text{magma} \;\xrightarrow{\;+\text{ associativity}\;}\; \text{semigroup} \]

28. Take the definitions apart: binary operation vs magma

Definition probe

Sort into buckets

Every line below is part of the definition of binary operation or of magma — one or the other, never both. Put each where it belongs.

binary operation
A total function from the set of ordered pairs of S back into S.; It must be defined for every pair, and the result must land inside S.; We write the output of the pair (a, b) in infix form.
magma
A set S together with a binary operation on S.; No associativity, no identity.
b1
A total function from the set of ordered pairs of S back into S. It must be defined for every pair, and the result must land inside S. We write the output of the pair (a, b) in infix form.
b2
A set S together with a binary operation on S. The only axiom is closure. No associativity, no identity.

29. An identity element leaves everything unchanged

Concept

The next rung asks for a special element that does nothing when combined with anything. Combining it on either side returns the other input untouched.

\[ e \ast a \;=\; a \;=\; a \ast e \qquad \text{for all } a \in S \]

identity element — A two-sided identity e is an element satisfying e * a = a and a * e = a for every a in S. It is the do-nothing element of the operation.

30. One-sided identities: left and right can disagree

Concept

The identity axiom has two halves, and they can come apart. An element might do nothing from the left but change things from the right, or the reverse.

\[ e_L \ast a = a \;\;(\text{left identity}), \qquad a \ast e_R = a \;\;(\text{right identity}) \]

Only when a single element is both a left and a right identity do we call it the identity. That two-sidedness is what the monoid axiom demands.

31. Why the two-sided version is the one that matters

Intuition

A merely one-sided identity is fragile: it only helps you cancel from one direction, and an operation can even have many left identities at once while having no right identity.

A two-sided identity, by contrast, is unique the moment it exists. That uniqueness is what lets us speak of the neutral element and build everything above it, including inverses in the next deck.

32. What has to be given first: Worked example: division has a right…

Missing information

Discussion prompt

On the nonzero rationals, take division as the operation. It is closed. Does it have an identity?

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

A right identity must satisfy a divided by it equals a.

33. Worked example: division has a right identity but no left identity

Worked example

On the nonzero rationals, take division as the operation. It is closed. Does it have an identity?

Test the right side with the candidate 1

Why: A right identity must satisfy a divided by it equals a.

\[ a \div 1 = a \quad \text{for all } a \Rightarrow 1 \text{ is a right identity} \]

Now test 1 on the left

Why: A two-sided identity would also fix a from the left.

\[ 1 \div a = \tfrac{1}{a} \neq a \quad\text{unless } a = 1 \]

Search for any left identity

Why: A left identity e would need e divided by a to equal a for every a, forcing e to depend on a, which is impossible.

\[ e \div a = a \Rightarrow e = a^{2} \;\text{depends on } a \]

Verify the asymmetry on a number

Why: Plug in a equals 2: right side fixes it, left side does not, confirming there is no two-sided identity.

\[ 2 \div 1 = 2, \qquad 1 \div 2 = \tfrac{1}{2} \neq 2 \]

34. division has a right identity but no left identity — line by line

Picture it

Animation

Shows: Each line of the worked example "division has a right identity but no left identity", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Plug in a equals 2: right side fixes it, left side does not, confirming there is no two-sided identity.

35. Worked example: a two-sided identity is unique

Worked example

Claim: in any magma, if a two-sided identity exists, there is exactly one. This is why we may say the identity.

Assume two identities and combine them

Why: Suppose e and f are both two-sided identities; look at the single product e times f.

\[ e, f \text{ both satisfy } x \ast a = a = a \ast x \]

Read the product using f as an identity

Why: Because f is an identity, combining it on the right of e leaves e unchanged.

\[ e \ast f = e \]

Read the same product using e as an identity

Why: Because e is an identity, combining it on the left of f leaves f unchanged.

\[ e \ast f = f \]

Verify the two readings force equality

Why: The same element e times f equals both e and f, so e equals f; uniqueness holds, and no associativity was even needed.

\[ e = e \ast f = f \;\Longrightarrow\; e = f \]

36. Monoid: a semigroup with an identity

Concept

Now the top rung of this deck. Add a two-sided identity to a semigroup and you have a monoid.

monoid — A set with a binary operation that is (1) closed, (2) associative, and (3) has a two-sided identity element. Three axioms, each independently checkable.

\[ \text{semigroup} \;\xrightarrow{\;+\text{ identity}\;}\; \text{monoid} \]

37. The whole ladder in one glance

Intuition

Each step up the ladder adds exactly one requirement. Nothing is inherited automatically; you earn each rung with a proof.

Figure (svg): A ladder of four levels: magma with closure, semigroup adds associativity, monoid adds identity, group adds inverses, each level a box stacked above the previous.

This deck lives on the bottom three boxes. The next deck adds inverses to reach a group.

38. Complete the line: Worked example: is the integers under a special rule a…

Fill the middle

Fill in the blanks

From Worked example: is the integers under a special rule a… — finish the line. Write what belongs on the right of the equals sign before you look.

a \ast b = a + b - ab

Why: Producing the right-hand side unprompted is the difference between recognising this line and being able to use it. Sums and products of integers are integers, so the output is always an integer.

39. Worked example: is the integers under a special rule a monoid?

Worked example

On the integers define a new operation and decide whether it is a monoid.

\[ a \ast b = a + b - ab \]

Closure is immediate

Why: Sums and products of integers are integers, so the output is always an integer.

\[ a + b - ab \in \mathbb{Z} \]

Find the identity by solving the identity equation

Why: Require a star e equals a and solve for e independent of a.

\[ a + e - ae = a \Rightarrow e(1 - a) = 0 \;\forall a \Rightarrow e = 0 \]

Confirm associativity by expanding both groupings

Why: Both bracketings expand to the same symmetric polynomial.

\[ (a \ast b)\ast c = a+b+c-ab-ac-bc+abc = a \ast (b \ast c) \]

Verify identity and associativity on numbers

Why: Check e equals 0 does nothing and a sample triple associates.

\[ 5 \ast 0 = 5, \quad (1\ast 2)\ast 3 = 1 = 1 \ast(2 \ast 3) \]

40. is the integers under a special rule a monoid? — line by line

Picture it

Animation

Shows: Each line of the worked example "is the integers under a special rule a monoid?", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check e equals 0 does nothing and a sample triple associates.

41. The absorbing element is a different animal

Concept

Some monoids also contain an element that swallows everything it touches, returning itself no matter the partner. This is an absorbing or zero element.

\[ z \ast a = z = a \ast z \qquad \text{for all } a \in S \]

absorbing (zero) element — An element z such that combining it with anything returns z. It is the opposite of the identity: the identity preserves its partner, the absorber destroys it.

42. Term to definition: Binary Operations, Semigroups & Monoids

Matching

Match the pairs

Match each term to the definition this lesson gave it — not the one you would guess from the word.

  • t1. magma
  • t2. semigroup
  • t3. identity element
  • t4. monoid
  • t5. absorbing (zero) element
  • d1. A set S together with a binary operation on S. The only axiom is closure. No associativity, no identity.
  • d2. A magma whose operation is associative. Closure plus associativity, and nothing more.
  • d3. A two-sided identity e is an element satisfying e * a = a and a * e = a for every a in S. It is the do-nothing element of the operation.
  • d4. A set with a binary operation that is (1) closed, (2) associative, and (3) has a two-sided identity element. Three axioms, each independently checkable.
  • d5. An element z such that combining it with anything returns z. It is the opposite of the identity: the identity preserves its partner, the absorber destroys it.

Why: These are the working definitions of magma, semigroup, identity element, monoid, absorbing (zero) element as Binary Operations, Semigroups & Monoids uses them. Pairing them correctly is the test of whether you could state each one with the slide switched off.

43. Something is wrong here: confusing the identity with the absorbing element

Anomaly

Predict first

A student writes this, and it looks reasonable:

In ordinary multiplication a student points to 0 and calls it special, then blurs it together with the identity.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: This confuses does nothing with swallows everything.

Keep the two roles apart: the identity preserves, the absorber destroys.

Why: This confuses does nothing with swallows everything.

44. Trap: confusing the identity with the absorbing element

Trap

The trap

In ordinary multiplication a student points to 0 and calls it special, then blurs it together with the identity.

Claim 0 behaves like the neutral element

Why: This confuses does nothing with swallows everything.

\[ 0 \ast a \overset{?}{=} a \]

But zero times anything is zero, not the partner. Zero is the absorber; treating it as neutral corrupts every later computation.

The fix

Keep the two roles apart: the identity preserves, the absorber destroys.

State both roles side by side in the multiplicative monoid

Why: One is neutral, the other is absorbing; they are never the same element in a nontrivial monoid.

\[ 1 \ast a = a \;(\text{identity}), \qquad 0 \ast a = 0 \;(\text{absorber}) \]

Verified: 1 keeps a, 0 kills a. In a monoid with more than one element the identity and an absorber are always distinct.

45. Say it in words: Trap: confusing the identity with the absorbing…

Translation

\( 0 \ast a \overset{?}{=} a \)

Draw it

Translate both ways. First write the expression above as a sentence with no symbols in it at all. Then cover it, and write your sentence back as notation. If the two versions disagree, the disagreement is the thing to fix.

46. Plan first: Worked example: the naturals under addition form a monoid

Step zero

Discussion prompt

Worked example: the naturals under addition form a monoid — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Associativity

Answer:

  1. Associativity
  2. Identity is 0
  3. Verify on a value

47. Worked example: the naturals under addition form a monoid

Worked example

Confirm the most familiar monoid rung by rung.

Closure

Why: The sum of two naturals is a natural.

\[ a + b \in \mathbb{N} \]

Associativity

Why: Addition of naturals regroups freely, a standard fact of arithmetic.

\[ (a + b) + c = a + (b + c) \]

Identity is 0

Why: Adding zero on either side changes nothing.

\[ 0 + a = a = a + 0 \]

Verify on a value

Why: Check the identity concretely and note it is also commutative.

\[ 0 + 7 = 7 = 7 + 0 \]

48. the naturals under addition form a monoid — line by line

Picture it

Animation

Shows: Each line of the worked example "the naturals under addition form a monoid", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check the identity concretely and note it is also commutative.

49. Worked example: the naturals under multiplication form a monoid

Worked example

Same set, different operation, a different identity.

Closure and associativity

Why: Products of naturals are naturals and multiplication regroups freely.

\[ ab \in \mathbb{N}, \quad (ab)c = a(bc) \]

Identity is 1, not 0

Why: Multiplying by 1 preserves; multiplying by 0 absorbs.

\[ 1 \cdot a = a, \qquad 0 \cdot a = 0 \]

Verify the identity and spot the absorber

Why: Confirm 1 is neutral and 0 is the absorbing element of this monoid.

\[ 1 \cdot 9 = 9, \qquad 0 \cdot 9 = 0 \]

50. the naturals under multiplication form a monoid — line by line

Picture it

Animation

Shows: Each line of the worked example "the naturals under multiplication form a monoid", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Confirm 1 is neutral and 0 is the absorbing element of this monoid.

51. Commutativity is an extra property, not part of the ladder

Concept

None of magma, semigroup, or monoid requires the inputs to be swappable. When an operation happens to be symmetric in its two arguments, we flag it separately.

\[ a \ast b = b \ast a \qquad \text{for all } a, b \]

commutative monoid — A monoid whose operation also satisfies a * b = b * a for all elements. Addition on the naturals is commutative; string concatenation and matrix multiplication are not.

52. Commutativity versus associativity, kept separate

Intuition

Associativity is about grouping; commutativity is about order. They are independent: an operation can have either, both, or neither.

Matrix multiplication is associative but not commutative. The midpoint operation is commutative but not associative. Addition is both. Subtraction is neither.

53. Something is wrong here: silently assuming commutativity

Anomaly

Predict first

A student writes this, and it looks reasonable:

A student proves a fact about a monoid and freely swaps ab for ba mid-argument.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: This assumes commutativity, which the monoid axioms never grant.

Only swap order if you have proved the operation is commutative. Otherwise preserve it.

Why: This assumes commutativity, which the monoid axioms never grant.

54. Trap: silently assuming commutativity

Trap

The trap

A student proves a fact about a monoid and freely swaps ab for ba mid-argument.

Rewrite a product in the opposite order

Why: This assumes commutativity, which the monoid axioms never grant.

\[ AB \overset{?}{=} BA \]

For matrices this is generally false, so the argument collapses.

The fix

Only swap order if you have proved the operation is commutative. Otherwise preserve it.

Exhibit a non-commuting pair of matrices

Why: A single counterexample shows the swap is illegal in a general monoid.

\[ \begin{pmatrix}1&1\\0&1\end{pmatrix}\begin{pmatrix}1&0\\1&1\end{pmatrix} = \begin{pmatrix}2&1\\1&1\end{pmatrix}, \;\; \begin{pmatrix}1&0\\1&1\end{pmatrix}\begin{pmatrix}1&1\\0&1\end{pmatrix} = \begin{pmatrix}1&1\\1&2\end{pmatrix} \]

Verified: the two products differ, so order matters in this monoid.

55. Decode the notation: Trap: silently assuming commutativity

Notation

Annotate

From Trap: silently assuming commutativity — read this one piece at a time. What is each part doing?

On: \( AB \overset{?}{=} BA \)

  • This assumes commutativity, which the monoid axioms never grant.
  • A single counterexample shows the swap is illegal in a general monoid.

56. Idempotent elements: doing it twice is the same as once

Concept

A separate flavor of element repeats harmlessly: combining it with itself gives it back. These are idempotent.

\[ a \ast a = a \]

The identity is always idempotent, but in operations like set union or logical and, every element is idempotent. Idempotence is the algebraic signature of absorb duplicates.

57. Idempotence shows up all over CS

Intuition

Setting a flag you have already set changes nothing. Inserting an element already in a set changes nothing. Taking the maximum of a value with itself changes nothing.

That applying it again is free property is exactly idempotence, and it is why retries and re-runs of such operations are safe.

58. State the rule before it runs: Worked example: the power set under union…

Hypothesis

Predict first

Worked example: the power set under union is a monoid is about to be worked. State your hypothesis first: which rule or definition decides this one, and what is the first move it forces? Then watch whether the example agrees with you.

Correct: Closure and associativity

Why: A union of subsets of X is a subset of X, and union regroups freely.

A hypothesis you wrote down is falsifiable; a vague sense of how it will go is not. If the example opens somewhere else, that gap is the thing worth chasing.

59. Worked example: the power set under union is a monoid

Worked example

Fix a set and take all its subsets, with union as the operation.

\[ (\,\mathcal{P}(X),\, \cup\,) \]

Closure and associativity

Why: A union of subsets of X is a subset of X, and union regroups freely.

\[ A \cup B \subseteq X, \quad (A \cup B)\cup C = A \cup (B \cup C) \]

Identify the identity

Why: Unioning with the empty set adds nothing.

\[ \varnothing \cup A = A = A \cup \varnothing \]

Verify identity and idempotence on a concrete set

Why: Check the empty set is neutral and every element repeats harmlessly.

\[ \varnothing \cup \{1,2\} = \{1,2\}, \quad \{1,2\}\cup\{1,2\} = \{1,2\} \]

60. the power set under union is a monoid — line by line

Picture it

Animation

Shows: Each line of the worked example "the power set under union is a monoid", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check the empty set is neutral and every element repeats harmlessly.

61. What has to happen first: Worked example: the power set under intersection is a…

Ranking

Put in order

Put the moves of Worked example: the power set under intersection is a monoid into the order they have to happen.

  1. Closure and associativity
  2. Identify the identity as the whole set
  3. Verify identity and note the absorber

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. An intersection of subsets of X is a subset of X and intersection regroups freely.

62. Worked example: the power set under intersection is a monoid

Worked example

Same subsets, now with intersection. The identity flips to the other extreme.

Closure and associativity

Why: An intersection of subsets of X is a subset of X and intersection regroups freely.

\[ A \cap B \subseteq X, \quad (A \cap B)\cap C = A \cap (B \cap C) \]

Identify the identity as the whole set

Why: Intersecting with the full ground set keeps everything.

\[ X \cap A = A = A \cap X \]

Verify identity and note the absorber

Why: The whole set is neutral, the empty set is absorbing, mirroring one and zero in multiplication.

\[ X \cap \{1\} = \{1\}, \qquad \varnothing \cap \{1\} = \varnothing \]

63. the power set under intersection is a monoid — line by line

Picture it

Animation

Shows: Each line of the worked example "the power set under intersection is a monoid", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The whole set is neutral, the empty set is absorbing, mirroring one and zero in multiplication.

64. Guess the shape of the answer: Worked example: the booleans under AND and…

Estimation

Predict first

The two-element set of truth values gives two commutative monoids, dual to each other.

Commit before you compute: what does Worked example: the booleans under AND and under OR come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify neutrality on both values

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. Check true is neutral for and, false is neutral for or, on each input.

65. Worked example: the booleans under AND and under OR

Worked example

The two-element set of truth values gives two commutative monoids, dual to each other.

Under logical and, the identity is true

Why: True and p returns p, so true does nothing; false is the absorber.

\[ \top \wedge p = p, \qquad \bot \wedge p = \bot \]

Under logical or, the identity is false

Why: False or p returns p, so false does nothing; true is the absorber.

\[ \bot \vee p = p, \qquad \top \vee p = \top \]

Verify neutrality on both values

Why: Check true is neutral for and, false is neutral for or, on each input.

\[ \top \wedge \bot = \bot, \quad \top \wedge \top = \top, \quad \bot \vee \top = \top \]

66. the booleans under AND and under OR — line by line

Picture it

Animation

Shows: Each line of the worked example "the booleans under AND and under OR", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check true is neutral for and, false is neutral for or, on each input.

67. The free monoid: strings under concatenation

Concept

The monoid a computer scientist meets first is strings. Fix an alphabet, and let the elements be all finite strings over it. The operation is concatenation: glue the second string onto the end of the first.

\[ u = ab, \; v = ba \;\Longrightarrow\; u \cdot v = abba \]

free monoid — The set of all finite strings over an alphabet, with concatenation as the operation and the empty string as the identity. Free means the only equations that hold are those forced by the monoid axioms.

68. The empty string is the do-nothing element

Intuition

Concatenating the empty string onto either end of a word leaves the word exactly as it was. That is precisely the identity axiom, made of text.

\[ \varepsilon \cdot w = w = w \cdot \varepsilon \]

The empty string is easy to forget, but without it strings would be only a semigroup. It is the reason concatenation reaches the monoid rung.

69. Complete the line: Worked example: strings under concatenation form a…

Fill the middle

Fill in the blanks

From Worked example: strings under concatenation form a monoid — finish the line. Write what belongs on the right of the equals sign before you look.

(u \cdot v)\cdot w = u \cdot (v \cdot w)

Why: Producing the right-hand side unprompted is the difference between recognising this line and being able to use it. Gluing two finite strings yields a finite string over the same alphabet.

70. Worked example: strings under concatenation form a monoid

Worked example

Verify the three axioms for the free monoid on an alphabet.

Closure

Why: Gluing two finite strings yields a finite string over the same alphabet.

\[ u, v \in \Sigma^{*} \Rightarrow u \cdot v \in \Sigma^{*} \]

Associativity

Why: Concatenation only records the order of symbols, and regrouping does not change that order.

\[ (u \cdot v)\cdot w = u \cdot (v \cdot w) \]

Identity is the empty string

Why: Adding no symbols on either side changes nothing.

\[ \varepsilon \cdot w = w = w \cdot \varepsilon \]

Verify on concrete words

Why: Check associativity and the empty-string identity on short strings.

\[ (ab \cdot c)\cdot d = abcd = ab \cdot (c \cdot d), \quad \varepsilon \cdot ab = ab \]

71. strings under concatenation form a monoid — line by line

Picture it

Animation

Shows: Each line of the worked example "strings under concatenation form a monoid", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check associativity and the empty-string identity on short strings.

72. The Kleene star names the free monoid

Concept

The notation for all finite strings over the alphabet is the alphabet with a star. It collects strings of every length, including the length-zero empty string.

\[ \Sigma^{*} = \bigcup_{n \ge 0} \Sigma^{n} = \{\varepsilon\} \cup \Sigma \cup \Sigma^{2} \cup \cdots \]

Free has a precise meaning: every element is a unique sequence of alphabet symbols, so no surprise equations hold. This universal, relation-free quality is what makes it the model monoid.

73. Something is wrong here: treating concatenation as commutative

Anomaly

Predict first

A student writes this, and it looks reasonable:

Because addition of lengths commutes, a student assumes the strings themselves commute.

It is wrong. Say what breaks — and say it before you turn the page.

Correct: This assumes concatenation is commutative, which it is not.

The free monoid is non-commutative for any alphabet with at least two symbols. Keep the order.

Why: This assumes concatenation is commutative, which it is not.

74. Trap: treating concatenation as commutative

Trap

The trap

Because addition of lengths commutes, a student assumes the strings themselves commute.

Swap the order of two words

Why: This assumes concatenation is commutative, which it is not.

\[ ab \cdot ba \overset{?}{=} ba \cdot ab \]

The two gluings produce different strings, so the swap is invalid.

The fix

The free monoid is non-commutative for any alphabet with at least two symbols. Keep the order.

Compute both orders explicitly

Why: A single differing pair proves non-commutativity.

\[ ab \cdot ba = abba \;\neq\; baab = ba \cdot ab \]

Verified: abba is not baab. Length is the same but the strings differ, which is exactly why length forgets information.

75. Which of these survive contact with Binary Operations, Semigroups & Monoids?

Two truths and a lie

Sort into buckets

Some of these hold up and some are the exact mistakes this lesson is built to prevent. Sort them.

Holds up
The phrase to internalize is closure: applying the operation to two members of the set never takes you outside the set. This is baked into the codomain being S.; For a small finite set, a binary operation is just a fully filled grid: rows indexed by the left input, columns by the right input, and every cell holds the output.; Associativity is the law that lets you drop parentheses. It says the two ways of folding three inputs agree.
Breaks
A strong student reads the naturals under subtraction and starts checking associativity, quietly assuming the operation is well defined.; Because plus and times are associative, it is tempting to treat associativity as a property operations just have.
sound
These are stated as this lesson states them — each one survives the edge cases Binary Operations, Semigroups & Monoids puts it through.
flawed
Each of these is lifted from a trap in this deck: reasonable-sounding, and wrong in a way that only shows up once you rely on it.

76. A homomorphism is a structure-preserving map of monoids

Concept

Once you have two monoids, you ask which maps respect their operations. A homomorphism sends products to products and identity to identity.

\[ \varphi(a \ast b) = \varphi(a) \star \varphi(b), \qquad \varphi(e_M) = e_N \]

monoid homomorphism — A function between monoids that carries the operation of the source to the operation of the target and sends the source identity to the target identity. It preserves the algebraic shape while possibly forgetting detail.

77. A homomorphism is a lossy but faithful translator

Intuition

Think of it as translating between two worlds so that combine, then translate always equals translate, then combine. The diagram commutes.

It may forget information (many inputs can map to the same output), but it never distorts the operation. This single idea returns for groups, rings, and vector spaces as the definition of a well-behaved map.

78. Plan first: Worked example: length is a monoid homomorphism

Step zero

Discussion prompt

Worked example: length is a monoid homomorphism — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Check the operation is preserved

Answer:

  1. Check the operation is preserved
  2. Check the identity is preserved
  3. Verify both laws on a concrete pair

79. Worked example: length is a monoid homomorphism

Worked example

Map each string to its number of symbols, sending the free monoid to the naturals under addition.

\[ \operatorname{len} : (\Sigma^{*}, \cdot, \varepsilon) \longrightarrow (\mathbb{N}, +, 0) \]

Check the operation is preserved

Why: The length of a concatenation is the sum of the lengths, so products go to products.

\[ \operatorname{len}(u \cdot v) = \operatorname{len}(u) + \operatorname{len}(v) \]

Check the identity is preserved

Why: The empty string has length zero, the identity of the target.

\[ \operatorname{len}(\varepsilon) = 0 \]

Verify both laws on a concrete pair

Why: Confirm the length of a glued word equals the sum of the pieces.

\[ \operatorname{len}(ab \cdot cde) = 5 = 2 + 3 = \operatorname{len}(ab) + \operatorname{len}(cde) \]

80. length is a monoid homomorphism — line by line

Picture it

Animation

Shows: Each line of the worked example "length is a monoid homomorphism", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: The length of a concatenation is the sum of the lengths, so products go to products.

81. The composition monoid of a set

Concept

Take all functions from a fixed set to itself, with composition as the operation. This is the monoid that secretly underlies most of computing: state transformers, string rewriters, and pipelines all live here.

\[ \operatorname{End}(X) = \{\, f : X \to X \,\}, \qquad (f \circ g)(x) = f(g(x)) \]

endomorphism monoid — The set of all self-maps of X under composition. It is a monoid for every X, with the identity function as its identity element, and it is non-commutative once X has at least two elements.

82. Composition is the operation; the identity map does nothing

Intuition

Applying one transformation after another is itself a transformation, so composition is a genuine binary operation on self-maps. Chaining is associative because it just records do this, then that.

The do-nothing transformation, the identity map that returns its input unchanged, is the neutral element. Running it before or after any pipeline leaves the pipeline untouched.

83. Teach it back: Composition is the operation; the identity map does nothing

Explain it

Discussion prompt

Explain Composition is the operation; the identity map does nothing to a student a year behind you. No notation, no jargon they have not met — and it still has to be true.

Hint: If your explanation needs a symbol they have never seen, you are describing the notation rather than the idea.

Answer:

Applying one transformation after another is itself a transformation, so composition is a genuine binary operation on self-maps. Chaining is associative because it just records do this, then that.

84. Worked example: self-maps under composition form a monoid

Worked example

Check the three axioms for composition on the self-maps of a set.

Closure

Why: The composite of two self-maps of X is again a self-map of X.

\[ f, g : X \to X \Rightarrow f \circ g : X \to X \]

Associativity

Why: Composition of functions is always associative because both sides send x to f(g(h(x))).

\[ (f \circ g)\circ h = f \circ (g \circ h) \]

Identity is the identity map

Why: Composing with the map that returns its input changes nothing.

\[ \mathrm{id}_X \circ f = f = f \circ \mathrm{id}_X \]

Verify the identity on a sample map

Why: Take f with f of 1 equal to 2 on a small set and confirm the identity map leaves it unchanged.

\[ (\mathrm{id}_X \circ f)(1) = \mathrm{id}_X(f(1)) = f(1) = 2 \]

85. self-maps under composition form a monoid — line by line

Picture it

Animation

Shows: Each line of the worked example "self-maps under composition form a monoid", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Take f with f of 1 equal to 2 on a small set and confirm the identity map leaves it unchanged.

86. Complete the line: Worked example: square matrices under multiplication…

Fill the middle

Fill in the blanks

From Worked example: square matrices under multiplication form a… — finish the line. Write what belongs on the right of the equals sign before you look.

A, B \in M_n(\mathbbA(BC)) \Rightarrow AB \in M_n(\mathbb___), \quad (AB)C = ___

Why: Producing the right-hand side unprompted is the difference between recognising this line and being able to use it. A product of two n by n matrices is n by n, and matrix multiplication is associative.

87. Worked example: square matrices under multiplication form a monoid

Worked example

Fix a size and take all square matrices of that size over the reals, with matrix multiplication.

Closure and associativity

Why: A product of two n by n matrices is n by n, and matrix multiplication is associative.

\[ A, B \in M_n(\mathbb{R}) \Rightarrow AB \in M_n(\mathbb{R}), \quad (AB)C = A(BC) \]

Identity is the identity matrix

Why: Multiplying by the identity matrix on either side returns the original matrix.

\[ I_n A = A = A I_n \]

Note it is not commutative and not a group

Why: Order matters, and singular matrices have no inverse, so this is a monoid but not a group.

Verify the identity on a concrete matrix

Why: Multiply a sample two by two matrix by the identity and recover it.

\[ \begin{pmatrix}1&2\\3&4\end{pmatrix}\begin{pmatrix}1&0\\0&1\end{pmatrix} = \begin{pmatrix}1&2\\3&4\end{pmatrix} \]

88. square matrices under multiplication form a monoid — line by line

Picture it

Animation

Shows: Each line of the worked example "square matrices under multiplication form a monoid", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Multiply a sample two by two matrix by the identity and recover it.

89. What has to be given first: Worked example: integers modulo n under…

Missing information

Discussion prompt

Take the residue classes modulo a fixed n with addition carried out modulo n. Use n equal to 5 as the running case.

What do you need to know — or decide — before the first line can be written? List everything the problem has to hand you.

Hint: Anything you would have to invent to get started is a thing the problem must supply.

Answer:

Reducing a sum modulo n stays in the residue set, and addition inherits associativity.

90. Worked example: integers modulo n under addition

Worked example

Take the residue classes modulo a fixed n with addition carried out modulo n. Use n equal to 5 as the running case.

\[ \mathbb{Z}/5\mathbb{Z} = \{0,1,2,3,4\} \]

Closure and associativity

Why: Reducing a sum modulo n stays in the residue set, and addition inherits associativity.

\[ (a + b) \bmod n \in \mathbb{Z}/n\mathbb{Z} \]

Identity is 0

Why: Adding the class of 0 changes nothing.

\[ 0 + a \equiv a \pmod{n} \]

Verify closure and identity modulo 5

Why: Check a sum wraps back into the set and that 0 is neutral.

\[ 3 + 4 = 7 \equiv 2 \pmod 5, \qquad 0 + 3 = 3 \]

91. integers modulo n under addition — line by line

Picture it

Animation

Shows: Each line of the worked example "integers modulo n under addition", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check a sum wraps back into the set and that 0 is neutral.

92. A submonoid is a monoid living inside a monoid

Concept

A subset can be a monoid in its own right, using the same operation, provided it holds together. It must contain the identity and be closed.

\[ e \in T \quad\text{and}\quad a, b \in T \Rightarrow a \ast b \in T \]

submonoid — A subset of a monoid that contains the identity element and is closed under the operation. Associativity is inherited automatically, so only these two conditions need checking.

93. By analogy: A submonoid is a monoid living inside a monoid

Analogy

Discussion prompt

Explain A submonoid is a monoid living inside a monoid by analogy to something with no Foundations of Higher Mathematics in it at all — a queue, a recipe, a map, a bank balance, whatever fits. Then say where your analogy breaks.

Hint: An analogy that never breaks is not an analogy, it is the same idea wearing a hat. Find the seam — that is the part that is actually new.

Answer:

A subset can be a monoid in its own right, using the same operation, provided it holds together. It must contain the identity and be closed.

94. Guess the shape of the answer: Worked example: the even naturals are a…

Estimation

Predict first

Inside the monoid of naturals under addition, take just the even numbers.

Commit before you compute: what does Worked example: the even naturals are a submonoid of… come out to? A rough magnitude and the right form is enough — the point is to have something concrete to be wrong about.

Correct: Verify with a concrete sum

Why: A prediction you can defend turns the computation into a check rather than a leap of faith — and an answer that contradicts it is caught on the spot. Check that 0 is inside and a sample sum of evens is even.

95. Worked example: the even naturals are a submonoid of addition

Worked example

Inside the monoid of naturals under addition, take just the even numbers.

\[ E = \{0, 2, 4, 6, \dots\} \]

Contains the identity

Why: Zero is even, so the identity of the parent monoid is present.

\[ 0 \in E \]

Closed under addition

Why: A sum of two even numbers is even, so the subset does not leak.

\[ 2m + 2k = 2(m + k) \in E \]

Verify with a concrete sum

Why: Check that 0 is inside and a sample sum of evens is even.

\[ 2 + 4 = 6 \in E, \qquad 0 \in E \]

96. the even naturals are a submonoid of addition — line by line

Picture it

Animation

Shows: Each line of the worked example "the even naturals are a submonoid of addition", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check that 0 is inside and a sample sum of evens is even.

97. Plan first: Worked example: the naturals under maximum

Step zero

Discussion prompt

Worked example: the naturals under maximum — before any calculation: what is the plan? Name the moves in order, in plain English, without doing the arithmetic.

Hint: It starts with: Closure, associativity, commutativity

Answer:

  1. Closure, associativity, commutativity
  2. Find the identity
  3. Verify the identity and a non-trivial max

98. Worked example: the naturals under maximum

Worked example

Take the naturals with the operation that returns the larger of two inputs.

Closure, associativity, commutativity

Why: The maximum of naturals is a natural, and taking maxima regroups and reorders freely.

\[ \max(\max(a,b),c) = \max(a,\max(b,c)) \]

Find the identity

Why: The identity must not raise any value, so it is the least element.

\[ \max(a, 0) = a \Rightarrow e = 0 \]

Verify the identity and a non-trivial max

Why: Check that 0 is neutral and that maximum genuinely selects the larger input.

\[ \max(3, 0) = 3, \qquad \max(3, 5) = 5 \]

99. the naturals under maximum — line by line

Picture it

Animation

Shows: Each line of the worked example "the naturals under maximum", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Check that 0 is neutral and that maximum genuinely selects the larger input.

100. What has to happen first: Worked example: positive integers under gcd stop at…

Ranking

Put in order

Put the moves of Worked example: positive integers under gcd stop at semigroup into the order they have to happen.

  1. Closure and associativity
  2. Hunt for an identity
  3. See why no such positive integer exists
  4. Verify the classification

Why: These are the moves of the worked example in the order it makes them, and each one is set up by the one before it. The gcd of positive integers is a positive integer, and gcd is associative and commutative.

101. Worked example: positive integers under gcd stop at semigroup

Worked example

Take the positive integers with the greatest common divisor as the operation. How high up the ladder does it climb?

Closure and associativity

Why: The gcd of positive integers is a positive integer, and gcd is associative and commutative.

\[ \gcd(\gcd(a,b),c) = \gcd(a,\gcd(b,c)) \]

Hunt for an identity

Why: An identity e would need gcd of a and e to return a for every a, forcing e to be a multiple of every positive integer.

\[ \gcd(a, e) = a \;\forall a \Rightarrow a \mid e \;\forall a \]

See why no such positive integer exists

Why: No positive integer is divisible by every positive integer, so there is no identity; the candidate 1 fails at once.

\[ \gcd(a, 1) = 1 \neq a \quad (a \ge 2) \]

Verify the classification

Why: Closure and associativity hold but no identity exists, so this is a commutative semigroup that is not a monoid.

\[ \gcd(6, 1) = 1 \neq 6 \Rightarrow \text{no identity} \]

102. positive integers under gcd stop at semigroup — line by line

Picture it

Animation

Shows: Each line of the worked example "positive integers under gcd stop at semigroup", appearing one at a time.

The same working the example does, in the order a tutor would write it.

Takeaway: Closure and associativity hold but no identity exists, so this is a commutative semigroup that is not a monoid.

103. Monoids are exactly what a fold needs

Concept

The reason monoids matter to a programmer: a monoid is precisely the structure you can fold or reduce a list with. Associativity lets you split the list anywhere, and the identity handles the empty list.

\[ \operatorname{fold}(\ast, e, [a_1, a_2, \dots, a_k]) = a_1 \ast a_2 \ast \cdots \ast a_k \]

Sum, product, string concatenation, maximum, and set union are all folds over their monoid. Associativity is exactly what makes the parallel or chunked version give the same answer as the sequential one.

104. The identity is what an empty fold returns

Intuition

Folding an empty list has to return something, and the only sensible choice is the identity: nothing combined is the do-nothing element.

The empty sum is 0, the empty product is 1, the empty concatenation is the empty string, and the empty union is the empty set. Each is that monoid's identity. This is why the identity is not optional decoration but the base case of every accumulation.

105. Break it if you can: The identity is what an empty fold returns

Counterexample

Discussion prompt

Folding an empty list has to return something, and the only sensible choice is the identity: nothing combined is the do-nothing element.

That is stated as though it always holds. Do one of two things: produce a case where it fails, or say precisely what rules such a case out. "It just does" is not on the menu.

Hint: Hunt at the extremes first — zero, one, negative, empty, equal. If every extreme survives, the reason they survive is the proof.

106. The zoo, sorted by how far up the ladder it climbs

Concept

Collecting the running examples makes the three axioms concrete. Read each row as does it clear closure, associativity, identity?

set and operationhighest rungidentity
naturals, subtractionnot even a magmanone
integers, subtractionmagma onlynone (not associative)
positive integers, gcdcommutative semigroupnone
naturals, additioncommutative monoid0
strings, concatenationmonoid (non-commutative)empty string
self-maps, compositionmonoid (non-commutative)identity map

The pattern to carry forward: closure is the gate, associativity is the workhorse, and the identity is the base case. A group, in the next deck, adds inverses on top of all three.

107. Fill in: highest rung for The zoo, sorted by how far up the ladder it…

Comparison

Comparison matrix

From The zoo, sorted by how far up the ladder it climbs: refill the highest rung column from what you know. The rest of the table is as it appeared.

set and operationhighest rungidentity
naturals, subtractionnot even a magmanone
integers, subtractionmagma onlynone (not associative)
positive integers, gcdcommutative semigroupnone
naturals, additioncommutative monoid0
strings, concatenationmonoid (non-commutative)empty string
self-maps, compositionmonoid (non-commutative)identity map

108. The recipe: is this set-with-operation a monoid?

Pattern

1. Test closure

Why: Confirm the operation is total and its output always lands back in the set. If a single pair escapes, stop: it is not even a magma.

2. Test associativity

Why: Prove the two bracketings always agree, or kill it with one counterexample triple. Passing here promotes it to a semigroup.

3. Find the identity

Why: Solve the identity equation for a single element that works on both sides for every input. Passing here promotes it to a monoid.

4. Record the extras

Why: Separately note commutativity, idempotence, and any absorbing element. These refine the description but are not required for monoidhood.

109. Where this shows up: Binary Operations, Semigroups & Monoids

Real world

Discussion prompt

Outside this lesson: where does Binary Operations, Semigroups & Monoids actually turn up? Name one concrete situation — a job, a piece of software someone ships, a decision somebody has to make — and say which part of The recipe: is this set-with-operation a monoid? is doing the work in it.

Hint: Vague is the failure mode here. "Engineering" is not a situation; "deciding whether this build is fast enough to ship" is.

Answer:

Builds the algebraic ladder magma to semigroup to monoid from the ground up: closure, associativity, and identity as separate axioms you must actually check. Targets the misconceptions that closure is automatic, that every operation is associative or commutative, and that the identity is the same thing as an absorbing element.

110. Rule out three: Check: which set breaks closure?

Elimination

Eliminate the wrong options

On which set is subtraction NOT a binary operation because closure fails?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. The integers
  • B. The rational numbers
  • C. The natural numbers starting at 0
  • D. The real numbers

Survives elimination: C

Why: Subtraction on the naturals can produce a negative result, for example 0 minus 1 equals negative 1, which is not a natural number. That single escaping pair breaks closure, so subtraction is not a binary operation on the naturals.

111. Check: which set breaks closure?

Check

Subtraction is the operation. On which set does it fail to be a binary operation because the result can leave the set?

Check your understanding

On which set is subtraction NOT a binary operation because closure fails?

  • A. The integers
  • B. The rational numbers
  • C. The natural numbers starting at 0 (correct)
  • D. The real numbers

Answer: C

Why: Subtraction on the naturals can produce a negative result, for example 0 minus 1 equals negative 1, which is not a natural number. That single escaping pair breaks closure, so subtraction is not a binary operation on the naturals.

Why A tempts people
The integers are closed under subtraction: any integer minus an integer is an integer, so closure holds there.
Why B tempts people
The rationals are closed under subtraction, so no pair ever escapes the set.
Why D tempts people
The reals are closed under subtraction as well, so closure is not the failing property here.

112. Answer it before you see the options: Check: evaluate a custom operation

Prediction

Predict first

Under the operation a * b = a + b - ab on the integers, what is 2 * 3?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: negative 1

Why: Substitute directly: 2 plus 3 minus the product 2 times 3 equals 5 minus 6, which is negative 1. The subtracted product term is what pulls the value below the plain sum.

113. Check: evaluate a custom operation

Check

Use the operation from the earlier worked example.

\[ a \ast b = a + b - ab \]

Check your understanding

Under the operation a * b = a + b - ab on the integers, what is 2 * 3?

  • A. negative 1 (correct)
  • B. 5
  • C. 6
  • D. 11

Answer: A

Why: Substitute directly: 2 plus 3 minus the product 2 times 3 equals 5 minus 6, which is negative 1. The subtracted product term is what pulls the value below the plain sum.

Why B tempts people
This dropped the minus ab term entirely and computed only 2 plus 3, the ordinary sum.
Why C tempts people
This computed only the product term ab equals 6 and ignored the a plus b part.
Why D tempts people
This added the product instead of subtracting it, giving 2 plus 3 plus 6 rather than 2 plus 3 minus 6.

114. Check: the identity of the free monoid

Check

Consider all finite strings over an alphabet, under concatenation.

Check your understanding

In the monoid of strings under concatenation, what is the identity element?

  • A. The empty string (correct)
  • B. A single blank space character
  • C. The first letter of the alphabet
  • D. There is no identity

Answer: A

Why: Concatenating the empty string onto either end of any word leaves the word unchanged, which is exactly the identity axiom. So the empty string is the identity of the free monoid.

Why B tempts people
A blank space is a real symbol of length one, so gluing it on lengthens the word rather than leaving it unchanged.
Why C tempts people
A specific letter is a length-one string, so concatenating it changes the word; it cannot be neutral.
Why D tempts people
The identity does exist: the empty string is precisely the element that changes nothing under concatenation.

115. How sure are you: Check: identity versus absorber

Commit first

Predict first

In the monoid of natural numbers under multiplication, which statement is correct?

Commit to an answer, then rate it — certain, fairly sure, or guessing — and write the rating down before you turn the page.

Correct: 1 is the identity and 0 is an absorbing element

Why: Multiplying by 1 returns the partner unchanged, so 1 is the identity, while multiplying by 0 always returns 0, so 0 absorbs. The two roles are distinct and opposite.

The rating matters as much as the answer: confident-and-wrong is the combination that survives revision, because nothing about it feels like it needs revisiting.

116. Check: identity versus absorber

Check

Consider the natural numbers under ordinary multiplication.

Check your understanding

In the monoid of natural numbers under multiplication, which statement is correct?

  • A. 1 is the identity and 0 is an absorbing element (correct)
  • B. 0 is the identity
  • C. 1 is an absorbing element
  • D. Multiplication has no identity

Answer: A

Why: Multiplying by 1 returns the partner unchanged, so 1 is the identity, while multiplying by 0 always returns 0, so 0 absorbs. The two roles are distinct and opposite.

Why B tempts people
This confuses the absorber with the identity: 0 times a is 0, not a, so 0 destroys rather than preserves.
Why C tempts people
This swaps the roles: 1 preserves its partner, so it is the identity, not an absorber.
Why D tempts people
The identity does exist and is 1, since 1 times a equals a for every natural number a.

117. Answer it before you see the options: Check: the homomorphism condition

Prediction

Predict first

For length to be a monoid homomorphism, which equation must hold for all strings u and v?

Answer it in your own words, now, with nothing to choose from. The options are on the next slide — and picking the right one off a list is an easier skill than producing it.

Correct: length(uv) = length(u) + length(v)

Why: A homomorphism carries the source operation (concatenation) to the target operation (addition), so the length of a concatenation must equal the sum of the lengths. It also sends the empty string to 0.

118. Check: the homomorphism condition

Check

The length map sends strings to the naturals under addition.

Check your understanding

For length to be a monoid homomorphism, which equation must hold for all strings u and v?

  • A. length(uv) = length(u) + length(v) (correct)
  • B. length(uv) = length(u) times length(v)
  • C. length(uv) = length(u) minus length(v)
  • D. length(u) = length(v) for all u and v

Answer: A

Why: A homomorphism carries the source operation (concatenation) to the target operation (addition), so the length of a concatenation must equal the sum of the lengths. It also sends the empty string to 0.

Why B tempts people
The target operation is addition, not multiplication, so products of lengths do not match concatenation.
Why C tempts people
Subtraction is not the target operation, and it would even give negative values, so it cannot be preserved.
Why D tempts people
This says the map is constant on all strings, which is false and is not what preserving the operation means.

119. Rule out three: Check: how high does gcd climb?

Elimination

Eliminate the wrong options

The positive integers under gcd form which structure?

3 of these 4 are wrong. Strike them one at a time, and say what rules each one out before you strike the next. The survivor is the answer.

  • A. A commutative semigroup with no identity element
  • B. A monoid with identity 1
  • C. A group
  • D. Not even a magma

Survives elimination: A

Why: gcd is closed, associative, and commutative, but no positive integer is divisible by every positive integer, so there is no identity. That makes it a commutative semigroup that fails to be a monoid.

120. Check: how high does gcd climb?

Check

Take the positive integers with the greatest common divisor as the operation.

Check your understanding

The positive integers under gcd form which structure?

  • A. A commutative semigroup with no identity element (correct)
  • B. A monoid with identity 1
  • C. A group
  • D. Not even a magma

Answer: A

Why: gcd is closed, associative, and commutative, but no positive integer is divisible by every positive integer, so there is no identity. That makes it a commutative semigroup that fails to be a monoid.

Why B tempts people
The number 1 is not an identity: gcd of a and 1 is 1, not a, so 1 fails the identity condition for every a above 1.
Why C tempts people
A group needs an identity and inverses, and gcd has neither, so it cannot be a group.
Why D tempts people
gcd of two positive integers is a positive integer, so closure holds and it is at least a magma.

121. Connect it up: Binary Operations, Semigroups & Monoids

Connect it up

Draw it

One page, no notation unless you need it: draw how these connect — The recipe: is this set-with-operation a monoid? · A binary operation combines two inputs into one output · Closure is not a bonus, it is the definition · Picture the operation as a filled-in table · Notation: the operation is abstract, the symbol is a placeholder. Put an arrow wherever one of them is what makes another possible, and label the arrow with why.

122. What you can do now

Recap

You climbed the first algebraic ladder, one independently checkable axiom per rung: magma (closure), semigroup (adds associativity), monoid (adds a two-sided identity).

The three habits to keep: check closure first, never assume associativity or commutativity, and keep the identity distinct from an absorbing element.

rungnew axiomexample
magmaclosureintegers under subtraction
semigroupassociativitypositive integers under gcd
monoidtwo-sided identitystrings under concatenation

The identity is unique whenever it exists, the free monoid of strings is the CS-native model, and a homomorphism such as length is a map that preserves the whole structure. Next deck: add inverses to every element and the monoid becomes a group.

Sources

  1. Dummit & Foote, Abstract Algebra, Chapter 1 (Introduction to Groups); Wikipedia articles on Magma, Semigroup, Monoid, Free monoid.
  2. All definitions, theorem statements, proof sketches, witnesses and counterexamples re-derived and checked by hand. — Verified 2026-07-21.

Want this taught 1-on-1? Alexander tutors Foundations of Higher Mathematics — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108