Lecture 6: semirings, cancellation, inverses, integers, rationals, rings, fields, division [01C8]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
These lecture notes were prepared by Jon Sterling using Marcelo Fiore’s lectures as source material. Any mistakes were introduced by Jon Sterling. Generative AI was not used to write these lecture notes.
Distributive laws between additive and multiplicative structure [01C9]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
The additive and multiplicative structures of the natural numbers interact nicely in that the satisfy the following distributive laws:
\begin {aligned} l \cdot 0 &= 0 \\ l\cdot (m+n) &= l\cdot m + l\cdot n \end {aligned}It is very common for a set to carry both an additive and multiplicative monoid structure and for the former to distributive over the latter in the above sense. This makes (\mathbb {N}, +,0,\cdot ,1) into what mathematicians call a commutative semiring.
Definition Semiring [01CA]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
A semiring (or, as some call it, a rig) is an set A equipped with
- a commutative monoid structure, say (\oplus , 0),
- a monoid structure, say (\otimes ,1),
- 0\otimes x = 0 = x\otimes 0,
- x\otimes (y\oplus z) = (x\otimes y)\oplus (x\otimes z), and (y\oplus z)\otimes x = (y\otimes x) \oplus (z \otimes x).
(A,\oplus ,0) is called the additive monoid of the semiring, and (A,\otimes ,1) is called the multiplicative monoid of the semiring.
A semiring is called commutative when its multiplicative monoid is commutative, i.e. we have x\otimes y = y\otimes x. (The additive monoid is always required to be commutative!)
Cancellation laws [01CE]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Cancellation properties of the natural numbers [01CB]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Both the additive and multiplicative monoids of the natural numbers satisfy cancellation laws.
- The additive cancellation law: k+m = k+n \implies m=n.
- The multiplicative cancellation law: k\not =0 \land k\cdot m = k\cdot n \implies m = n
The multiplicative cancellation law requires the side condition that k\not =0, because we have 0\cdot m =0\cdot n for all m,n. We will see shortly how to formulate cancellation laws generally in a way that accounts for such side conditions.
Definition Cancellation, cancellable elements [01CC]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
A binary operation \bullet \colon A\times A\to A is said to allow cancellation on the left by an element c:A when c\bullet x = c\bullet y implies x=y for all x,y. Similarly, \bullet is said to allow cancellation on the right by an element c:A when x\bullet c = y\bullet c implies x=y for all x,y.
We say that an element c is cancellable on the (left, right) when \bullet allows cancellation (on the left, on the right) by c. When an element is cancellable on both the left and the right, we just say that it is cancellable.
Example Cancellation for list append [01CD]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
The append operation on lists allows cancellation by any list on both the left and the right.
Inverse elements in monoids; groups, rings, and fields [01CF]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Definition Left, right, and two-sided inverses [01CG]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Let (A,\bullet ,e) be a monoid.
- A left inverse of an element x:A is defined to be an element l such that l\bullet x = e.
- A right inverse of an element x:A is defined to be an element r such that x\bullet r = e.
- A two-sided inverse of an element x:A is defined to be an element that is simultaneously a left and a right inverse of x. Two-sided inverses are often simply called inverses.
An element x:A is said to be
- invertible on the left when there exists some left inverse for x,
- invertible on the right when there exists some right inverse for x, and
- invertible when there exists a left inverse and a right inverse for x.
Proposition Uniqueness of inverses [01CH]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
If an element x of a monoid (A,\bullet ,e) is invertible, then it admits a unique left inverse and a unique right inverse, and these are moreover equal.
Proof.
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Let x be invertible, so that we have some l and r satisfying l\bullet x = e = x \bullet r. Then,
l = l \bullet e = l \bullet (x\bullet r) = (l\bullet x) \bullet r = e \bullet r = r\text {.}Thus l=r and so l is a right inverse and r is a left inverse.
Be careful: although we have shown that when x is invertible, any two left (or right) inverses of x are equal, this need not hold otherwise.
Proposition Invertible elements are cancellable [01CI]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
A left-invertible element of a monoid is cancellable on the left. Similarly, right-invertible elements are cancelleable on the right. Hence, invertible elements are cancellable.
Proof.
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Without loss of generality, we consider only the left version of the statement.
Let c:A be an element of a monoid (A,\bullet ,e) which is invertible on the left, so we may assume some l:A such that l\bullet c = e. We need to show that c is cancellable on the left , which is to say that \forall x,y:A\mathpunct {.} c\bullet x = c\bullet y \implies x = y \text {.}
To that end, we fix x,y such that c\bullet x = c\bullet y to show that x=y. We calculate as follows:
\begin {aligned} c\bullet x &= c \bullet y \\ l\bullet (c\bullet x) &= l\bullet (c\bullet y) \\ (l\bullet c) \bullet x &= (l\bullet c)\bullet y \\ e \bullet x &= e \bullet y \\ x &= y \end {aligned}In a monoid, the neutral element is always invertible by itself, but it is possible for a monoid to have no other invertible elements. In certain very important monoids, however, all elements are invertible: these are called groups.
Definition Group [01CJ]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
A group is a monoid in which every element is invertible. A group is called Abelian when the underlying monoid is commutative.
Definition Additive and multiplicative inverses in a semiring [01CK]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Let x be an element of a semiring (A,\oplus ,0,\otimes ,1).
- An additive inverse of x is an inverse of x in the additive monoid of A, i.e. an element y:A such that x\oplus y = 0. (Because the additive monoid is commutative, we have y\oplus x=0 automaticaly.)
- A multiplicative inverse of x is an inverse of x in the multiplicative monoid of A, i.e. an element y:A such that x\otimes y = 1 = y \otimes x.
By uniqueness of inverses, the additive and multiplicative inverses of x are unique if they exist. When they exist, we might as well write -x and x^{-1} respectively for them.
Terminology Negations and reciprocals in a semiring [01CO]
- September 30, 2026
- Jon Sterling
Sometimes the following suggestive terminology is also in a semiring:
- A negation of an element x is the same thing as an additive inverse of x.
- A reciprocal of an element x is the same thing as a multiplicative inverse of x.
Warning Cancellation need not imply invertibility! [01CL]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
In the presence of inverses, we have cancellation as we saw in Proposition [01CI]; the converse, however, does not necessarily hold. For example, in the system of natural numbers, we have all the cancellation laws and yet 0 is the only element that admits an additive inverse -0 \coloneqq 0, and similarly 1 is the only element that admits a multiplicative inverse 1^{-1}\coloneqq 1.
Definition Ring [01CM]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
A ring is a semiring whose additive monoid is a group. A ring is called commutative when it is commutative as a semiring, i.e. the multiplicative monoid is commutative.
Joke Why semirings are sometimes called “rigs” [01CN]
- September 30, 2026
Looking at the definition of a ring, we see that the only difference with semirings is that all elements are required to admit an additive inverse, or in other words, a negation. Removing negations from a ring leaves just a rig.
Definition Field [01CP]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
A field is a commutative ring in which every non-zero element has a reciprocal, i.e. a multiplicative inverse.
Remark From natural numbers to integers to rationals [01CQ]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Just as a commutative ring has an underlying commutative semiring and a field has an underlying commutative ring, it is possible to go in the other direction by completing a commutative ring to a commutative semiring, and completing a commutative ring to a field. We won’t learn in this course the tools needed to speak formally about this kind of completion in general (but you can look up left adjoints if you want), but the point is that when we complete the natural numbers in this way, we get some very interesting results:
- If you complete the natural numbers to obtain a commutative ring by adding in all additive inverses, then you get the ring of integers \mathbb {Z}.
- If you complete the ring of integers to obtain a field by adding in all multiplicative inverses, then you get the field of rational numbers \mathbb {Q}.
We won’t talk about it in this course, but the reals can be obtained from the rationals by any number of analogous completion procedures, e.g. completion under limits of Cauchy sequences.
Returning to something we discussed before, in grade school you were taught to think of the naturals, integers, and rationals as derived from the reals by removing elements. From the point of view of Mathematics, this is exactly wrong: the integers are what you get when you add negation to the naturals, and the rationals are what you get when you add reciprocals to the integers, and the reals are what you get when you add limits of Cauchy sequences to the rationals.
The division theorem and algorithm [01CR]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Our goal is to prove the division theorem for natural numbers, or at least explore some evidence for it (since we cannot rigorously prove it without induction, which we will learn later).
Theorem The Division Theorem [01CS]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
For every natural number m and positive natural number n, there exists a unique pair of natural numbers (q,r) such that r < n and m = q\cdot n + r.
Definition Quotient and remainder [01CT]
- September 30, 2026
- Jon Sterling
Because the pair of naturals (q,r) associated to a given (m,n) by the division theorem are uniquely determined, we may express them as functions of (m,n). In particular, we shall write \operatorname {quo}{\mathopen {}\left (m,n\right )\mathclose {}} and \operatorname {rem}{\mathopen {}\left (m,n\right )\mathclose {}} for the unique naturals satisfying \operatorname {rem}{\mathopen {}\left (m,n\right )\mathclose {}}<n \quad \text {and}\quad m = \operatorname {quo}{\mathopen {}\left (m,n\right )\mathclose {}}\cdot n + \operatorname {rem}{\mathopen {}\left (m,n\right )\mathclose {}} \text {.}
Recalling our exploration of unique existence, a unique existence statement is often best proved by separately establishing uniqueness and existence. We will especially favour existence proofs that contain within them the idea of an algorithm, in this case the division algorithm.
First, we show uniqueness of the quotient and remainder.
Lemma Uniqueness of quotient and remainder [01CU]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Let m and n be naturals with n positive. Then any two pairs pairs of naturals (q_0,r_0) and (q_1,r_1) satisfying r_0,r_1<n and m=q_0n+r_0=q_1n+r_1 are equal.
Proof.
- September 30, 2026
- Marcelo Fiore, Jon Sterling
We will first show that r_0=r_1. We recall Example [01AZ] from Lecture 3, which states that congruence modulo n uniquely determines the natural numbers strictly below n. In particular, because we have r_0,r_1<n, to prove r_0=r_1 it suffices to show that r_0 and r_1 are congruent modulo n, i.e. r_0\equiv r_1\mod n.
To that end, we calculate the difference r_0-r_1:
\begin {aligned} r_0-r_1 &= (m - q_0n) - (m - q_1n) \\ &= m - q_0n - m + q_1n \\ &= q_0n + q_1n \\ &= n(q_0 + q_1) \end {aligned}Hence n\mid r_0-r_1 and thus r_0 \equiv r_1 \mod n from which it follows, by Example [01AZ], that r_0=r_1. Because they are equal, we will simply write r for either r_0 or r_1.
Now it remains to show that q_0=q_1. We have q_0n = r-m = q_1n; because n is assumed positive, we may use the multiplicative cancellation law for the naturals to deduce q_0 = q_1.
For existence, we first consider an algorithm to compute the quotient and remainder.
Algorithm The division algorithm [01CV]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
We write the division algorithm in the notation of OCaml below:
let rec iterate_division n (q, r) : int * int = if r < n then (q, r) else iterate_division n (q + 1, r - n) let divide (m, n) : int * int = iterate_division n (0, m) let quo (m, n) = fst (divide (m, n)) let rem (m, n) = snd (divide (m, n))
Lemma Correctness of the division algorithm [01CW]
- September 30, 2026
- Marcelo Fiore, Jon Sterling
The division algorithm terminates on the appropriate inputs: for any natural number m and positive natural number n, the evaluation of \mathtt {divide}~m~n terminates with a pair {\mathopen {}\left (q,r\right )\mathclose {}} such that r < n and m = qn + r.
Proof.
- September 30, 2026
- Marcelo Fiore, Jon Sterling
Let m and n be natural numbers with n positive. We first consider the circumstances under which the evaluation of \mathtt {divide}~m~n terminates. We have \mathtt {divide}~m~n = \mathtt {iterate\_division}~n~(0,m) so \mathsf {terminates}(\mathtt {divide}~m~n) \Longleftrightarrow \mathsf {terminates}(\mathtt {iterate\_division}~n~(0,m)) \text {.}
\mathtt {iterate\_division}~n~(q,r) is defined so to terminate as soon as r gets small enough, and in each recursive call, r is getting smaller. Therefore, so long as n is positive, \mathtt {iterate\_division}~n~(q,r) is guaranteed to terminate and thus \mathtt {divide}~m~n is guaranteed to terminate.
We may now consider whether the values of \mathtt {divide}~m~n are pairs (q,r) such that r<n and m=qn+r. It is clear by inspection that the first condition holds. For the second, write P(q,r) for the statement m=qn+r. We will show that every call to \mathtt {iterate\_division} is with a pair satisfying P.
- The first call to \mathtt {iterate\_division} is with the pair (0,m), and we have m=0n+m.
- In the recursive call, we assume that P(q,r) holds and must show that P(q+1,r-n) holds. We see below that this is equivalent to our assumption: \begin {aligned} P(q+1,r-n) &\Longleftrightarrow m = (q+1)n + (r-n) \\ &\Longleftrightarrow m = qn+n + r - n \\ &\Longleftrightarrow m = qn + r \\ &\Longleftrightarrow P(q,r) \end {aligned}
We have shown above that if \mathtt {divide}~m~n terminates, then it terminates with a pair satisfying the desired property. Combining this with our earlier argument that \mathtt {divide}~m~n alwyas terminates, we are finished.
The division theorem therefore follows as a corollary of Lemma [01CU] and Lemma [01CW].
Proposition Congruence in terms of remainders [01CX]
- October 1, 2026
- Marcelo Fiore, Jon Sterling
Let m be a positive integer. For all natural numbers k and l, k \equiv l \mod m \Longleftrightarrow \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}} = \operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}}
Proof.
- October 1, 2026
- Marcelo Fiore, Jon Sterling
Let m be positive, and fix arbitrary naturals k and l.
In the forward direction, we assume k \equiv l \mod m. Recalling that \operatorname {rem}{\mathopen {}\left (x,m\right )\mathclose {}} < m and the fact that equality of modular integers is congruence, it suffices to show \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}}\equiv \operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}}\mod m\text {,} or in other words that m divides the difference between the two remainders. We introduce the following notations to simplify what follows:
\begin {aligned} \Delta {q} &\coloneqq \operatorname {quo}{\mathopen {}\left (k,m\right )\mathclose {}}-\operatorname {quo}{\mathopen {}\left (l,m\right )\mathclose {}} \\ \Delta {r} &\coloneqq \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}}-\operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}} \end {aligned}We want to show that m\mid \Delta {r}. To isolate \Delta r we first consider the difference k-l:
\begin {aligned} k-l &= m\cdot \operatorname {quo}{\mathopen {}\left (k,m\right )\mathclose {}}+\operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}} - {\mathopen {}\left (m\cdot \operatorname {quo}{\mathopen {}\left (l,m\right )\mathclose {}}+\operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}}\right )\mathclose {}} \\ &= m\cdot \Delta {q} + \Delta {r} \end {aligned}Hence, we have \Delta {r} = {\mathopen {}\left (k - l\right )\mathclose {}} - m \cdot \Delta {q} , and recalling our assumption k\equiv l \mod m we may assume some p such that pm = k-l. Hence \Delta {r} = pm - m\cdot \Delta q = m(p - \Delta q) and therefore m \mid \Delta {r}.
- In the backward direction, we assume \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}} = \operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}}, so that in the notation established above we have \Delta {r}=0. Therefore k-l = m\cdot \Delta q and hence k\equiv l\mod m.
Corollary The modular normal form of an integer [01CY]
- October 1, 2026
- Marcelo Fiore, Jon Sterling
Let m be a positive integer. Then:
- For every natural number n, we have n \equiv \operatorname {rem}{\mathopen {}\left (n,m\right )\mathclose {}}\mod m.
- For every integer k there exists a unique integer [k]_m such that 0 \leq [k]_m < m\quad \text {and}\quad k \equiv [k]_m\mod m\text {.}
Proof.
- October 1, 2026
- Marcelo Fiore, Jon Sterling
- By definition, we have n = \operatorname {quo}{\mathopen {}\left (n,m\right )\mathclose {}}\cdot m + \operatorname {rem}{\mathopen {}\left (n,m\right )\mathclose {}} and hence n - \operatorname {rem}{\mathopen {}\left (n,m\right )\mathclose {}} = m\cdot \operatorname {quo}{\mathopen {}\left (n,m\right )\mathclose {}}, so it follows that n \equiv \operatorname {rem}{\mathopen {}\left (n,m\right )\mathclose {}} \mod m.
-
For any integer k, we will establish the existence and uniqueness of [k]_m with the specified property sequentially.
- For existence, we note that k+\lvert k \rvert \cdot m is a natural number congruent to k modulo m (indeed, that it is non-negative can be established by considering the worst case scenario, when m = 1). We now choose [k]_m \coloneqq \operatorname {rem}{\mathopen {}\left (k+\lvert k\rvert \cdot m, m\right )\mathclose {}}\text {.} The reason for choosing k+\lvert k\rvert \cdot m is precisely to get a natural number that is congruent to k modulo m. The first condition 0\leq [k]_m < m holds by definition of remainders. The second condition k \equiv [k]_m\mod m can be seen to hold as follows: \begin {aligned} k &\equiv k + \lvert k\rvert \cdot m &\mod m \\ &\equiv \operatorname {rem}{\mathopen {}\left (k+\lvert k\rvert \cdot m,m\right )\mathclose {}} &\mod m \\ &= [k]_m \end {aligned}
For uniqueness, we will prove the following statement:
For all integers l such that 0\leq l < m and k\equiv l\mod m, we have l = [k]_m.
To that end, let l be an integer such that 0 \leq l < m and k\equiv l\mod m.
- We have l \equiv \operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}}\mod m and therefore l = \operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}} because 0\leq l < m and because equality of modular integers is congruence.
- We have \operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}}=\operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}}=\operatorname {rem}{\mathopen {}\left ([k]_m,m\right )\mathclose {}} because l\equiv k \equiv [k]_m\mod m via our characterisation of congruence in terms of remainders.
Hence we have the folowing sequence of equations:
l = \operatorname {rem}{\mathopen {}\left (l,m\right )\mathclose {}} = \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}} = \operatorname {rem}{\mathopen {}\left ([k]_m,m\right )\mathclose {}} = [k]_m
Observation The modular normal form of a natural number [01D1]
- October 8, 2026
- Jon Sterling
We previously showed that the normal form of an intger k modulo m can be expressed as the remainder [k]_m = \operatorname {rem}{\mathopen {}\left (k+\lvert k \rvert \cdot m, m\mathbf {}.\right )\mathclose {}}
When k\geq 0, a simpler characterisation is possible: in that case, we have [k]_m = \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}}.
Proof.
- October 8, 2026
- Jon Sterling
To see that [k]_m=\operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}} assuming k\geq 0, it suffices to show that 0 \leq \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}} < m and k \equiv \operatorname {rem}{\mathopen {}\left (k,m\right )\mathclose {}}\mod m. Why is this enough? Because we already showed that these two properties uniquely determine the normal form of k modulo m.
The first property is immediate by definition of remainders. For the second property, is the first observation of Corollary [01CY].
Example/Warning Modular exponentiation [01FA]
- October 31, 2026
- Jon Sterling
Let n:\mathbb {N} be natural number and let k:\mathbb {Z}_m be an integer modulo m. Then the modular exponentiation of k by n is defined to be the normal form {\mathopen {}\left [k^n\right ]\mathclose {}}_m of k^n modulo m.
Warning: modular exponentiation respects congruence in the base, but not the exponent: in other words, even if n\equiv n'\mod m, it need not be the case that k^n \equiv k^{n'} \mod m.