Binary Operations and Closure
What You’ll Learn
Section titled “What You’ll Learn”In this lesson you’ll learn the precise definition of a binary operation, how to test closure, associativity, commutativity, identities, and inverses, and how to read an operation table. Every structure in this section is a set plus an operation, so this is the ground floor.
The Concept
Section titled “The Concept”What a binary operation is
Section titled “What a binary operation is”A binary operation on a set is a rule that takes two elements of , in a definite order, and returns exactly one element of .
“Binary” refers to two inputs. Three requirements hide in that one-line definition, and each is worth naming:
- Two inputs, in order. The pair is not the pair . The operation may or may not care, but it is allowed to.
- Exactly one output. No ambiguity. is not a legal operation because it returns two things.
- The output is in . This is closure, and it’s built into the definition.
That last point trips people up. An operation is not just a formula; it’s a formula together with the set it acts on. Division is a perfectly good operation on the nonzero rationals and not an operation on the integers at all.
Closure
Section titled “Closure”is closed under if for every .
The even integers are closed under addition: even plus even is even, always. The odd integers are not, and it takes only one counterexample to say so. , which is not odd. One escape is enough.
To show closure fails, exhibit a single pair. To show it holds, you need an argument covering all pairs. Even numbers are and , and , which is even. That’s a proof, not a spot check.
Associativity
Section titled “Associativity”is associative if
This says grouping doesn’t matter, so a chain like is unambiguous and parentheses can be dropped. Nearly every useful operation has it, and the ones that don’t are genuinely awkward to work with.
Addition and multiplication of numbers are associative. Subtraction and division are not. Function composition and matrix multiplication are.
Associativity is not the same as commutativity, and the two are constantly confused.
Commutativity
Section titled “Commutativity”is commutative if
This says order doesn’t matter. Note carefully:
- Associativity is about parentheses.
- Commutativity is about order.
They’re independent. Matrix multiplication is associative but not commutative. Averaging two numbers, , is commutative but not associative.
Commutativity is deliberately not a group axiom. Groups that have it are called abelian, and treating it as optional is what lets group theory describe physical symmetry, where order usually does matter.
Identity elements
Section titled “Identity elements”An element is an identity for if
The identity does nothing. Both sides of the equation are required, because an operation can have a one-sided identity that fails on the other side.
- is the identity for addition.
- is the identity for multiplication.
- The identity matrix is the identity for matrix multiplication.
- The empty string is the identity for concatenation.
An identity is unique when it exists. Suppose and are both identities. Then (because is an identity) and (because is one). So . That short argument is your first abstract proof, and notice it used nothing but the definition.
Inverses
Section titled “Inverses”Given an identity , an element is an inverse of if
The inverse undoes the element. For addition, the inverse of is . For multiplication, the inverse of is , which is why has no multiplicative inverses but does.
Inverses only make sense once you have an identity, since appears in the definition. Order matters here too: some structures have elements with a left inverse and no right inverse.
Operation tables
Section titled “Operation tables”For a small finite set, write the whole operation out. The entry in row , column is .
| + | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 |
| 1 | 1 | 2 | 3 | 0 |
| 2 | 2 | 3 | 0 | 1 |
| 3 | 3 | 0 | 1 | 2 |
Every entry is one of the four elements, so the set is closed. Each row and column contains every element exactly once, which is what guarantees inverses.
Identity: 0. Cells holding it mark inverse pairs.
A table answers three of the four questions at a glance:
- Closure - every entry is in the set. Scan for strays.
- Identity - a row that reproduces the column headings in order, with the matching column doing the same.
- Inverses - the identity appears in every row and every column.
- Commutativity - the table is symmetric about the main diagonal.
Associativity is the one you can’t see. Checking it on a table of elements means verifying triples, which is why we normally inherit it from a known operation instead.
Tables like these are called Cayley tables, after Arthur Cayley.
Worked Examples
Section titled “Worked Examples”Example 1: Is a binary operation on ? Is it associative?
Solution. Closure first: , , and are integers, so is an integer. It’s a binary operation on .
Associativity requires expanding both groupings.
Both come to . Associative.
It’s also commutative, since swapping and leaves unchanged. The identity is , because .
Example 2: Find the identity for on .
Solution. We need with for every .
Check the other side: . ✓
The identity is , not . The identity depends on the operation, not on the set. Assuming it must be or is a standard mistake.
Inverses exist too: solving gives , so . Every element has one, so this is a group.
Example 3: Is subtraction commutative or associative on ?
Solution. Neither.
Commutativity: but . Fails.
Associativity: but . Fails.
It is closed, and it does have a right identity, since . But in general, so is not a two-sided identity. This is exactly the one-sided case mentioned earlier.
Example 4: Reading a table.
| ∗ | e | a | b | c |
|---|---|---|---|---|
| e | e | a | b | c |
| a | a | e | c | b |
| b | b | c | e | a |
| c | c | b | a | e |
Symmetric across the diagonal, so the operation is commutative. The identity sits on every diagonal entry, so each element is its own inverse.
Identity: e. Cells holding it mark inverse pairs.
Solution. Work through the checklist.
- Closure. Every entry is one of . ✓
- Identity. The row for reads , matching the headings, and the column for does the same. So is the identity. ✓
- Inverses. appears in every row and column. Reading the diagonal, , , . Every element is its own inverse. ✓
- Commutativity. The table is symmetric about the main diagonal. ✓
This is the Klein four-group, and it will return several times. Note it is not the same as addition mod 4, even though both have four elements: here every element squares to the identity, and in the element does not.
Example 5: Where does fail?
Solution. On the rationals it’s closed and commutative. Associativity:
These differ unless . Take : the first gives , the second gives . Not associative.
Averaging is the cleanest example of commutative-but-not-associative, and it shows why the two properties need separate names. It has no identity either: forces , which depends on .
Example 6: A one-sided identity.
On the set of matrices, is there an identity for the operation restricted to matrices with first column zero?
Solution. Let be matrices of the form . First check closure:
Closed. ✓ Associativity is inherited from matrix multiplication. ✓
For an identity we’d need with . The usual identity matrix is not in , since its first column isn’t zero. Trying : then ✓, but unless .
So is a right identity only. The structure is closed and associative with no two-sided identity, which makes it a semigroup and not a group.
Real-World Applications
Section titled “Real-World Applications”Type systems and generics. A binary operation is exactly a function of type (T, T) -> T. Languages with interfaces let you write code once against that shape. Rust’s Add trait, Haskell’s Semigroup and Monoid classes, and Java’s BinaryOperator<T> are all this definition rendered as code. Monoid is literally “associative binary operation with an identity.”
Parallel reduction. Summing a billion numbers across many cores requires splitting the work and combining partial results. That regrouping is only valid if the operation is associative, which is why reduce in parallel frameworks demands an associative combiner. Floating-point addition is not quite associative, which is why parallel sums can give slightly different answers run to run.
Databases. Aggregate functions that can be computed incrementally are ones with associative combiners. COUNT, SUM, MIN and MAX parallelize cleanly. MEDIAN does not, for essentially the reason averaging fails associativity.
Version control. Merging branches is a binary operation on repository states. It is not associative in general, and it is not commutative, which is a fair part of why merge conflicts are unpleasant.
Cryptographic hashing. Concatenation of bit strings is an associative operation with an identity (the empty string), and Merkle trees exploit exactly that structure to let you verify a piece of a large dataset without downloading all of it.
Retrying will remove your ✅ checkmark until you pass again.