How does one divide in a finite world? The proof systems documented in this series do their arithmetic not with the unbounded integers of school algebra but with the finitely many remainders left upon division by a fixed, enormous prime. Every step a prover or verifier takes is an addition, a multiplication, or—the delicate case—a division of such remainders. Adding and multiplying remainders is easy to imagine: compute in , then discard multiples of the modulus. But what can it mean to divide, when “one half” names no remainder? The answer developed in this section is that division is multiplication by a modular inverse; that a remainder possesses an inverse exactly when a certain greatest common divisor equals one; and that an algorithm already in Euclid’s Elements, suitably extended, computes the inverse efficiently.
The integers are the arithmetical bedrock on which every algebraic and cryptographic structure in this monograph ultimately rests. The finite number systems underlying elliptic curves, the scalar arithmetic of Halo 2, and the polynomial commitments of Orchard (short values that bind a prover to entire polynomials, which a verifier then tests by evaluation) all reduce, in the end, to computations with congruence classes of integers. This section develops the theory of the integers from a small set of assumptions and arrives at the integers modulo —the set of congruence classes—together with its units and the algorithms that make arithmetic with them effective. We keep the treatment constructive throughout: every existence statement comes, wherever possible, with an algorithm that produces the object in question, since cryptography requires not merely that inverses and representatives exist but that one can compute them efficiently.
We take the basic algebraic properties of for granted: addition and multiplication are associative and commutative, and multiplication distributes over addition; the integers and are identities for addition and multiplication respectively; every integer has a negative ; there are no zero divisors (if then or ); and carries a total order compatible with the arithmetic. The single deep property we assume axiomatically is the following.
Every nonempty subset of the natural numbers has a least element: there exists such that for all .
The well-ordering principle is logically equivalent to the principle of mathematical induction; we use both freely. It is also the engine of this section: nearly every existence result below is, at bottom, an application of well-ordering, in which one exhibits a nonempty set of natural numbers and extracts its minimum. Four instances map the road ahead. The remainder in the division algorithm is the least element of the set ; the Euclidean algorithm terminates because a strictly decreasing sequence of nonnegative integers cannot be infinite; the Bézout identity extracts the least positive element of a set of integer combinations; and existence in the fundamental theorem of arithmetic proceeds by minimal counterexample.
Let . One says that divides , written , if there exists an integer with . In this case is called a divisor or factor of , and is a multiple of . If no such exists one writes .
Several immediate consequences of the definition deserve to be recorded; we shall use them constantly and usually without explicit citation.
Let . Then:
(reflexivity), , and .
If and then (transitivity).
If and then for all ; in particular .
If and then .
If and then .
if and only if .
(1) is immediate: , , . For (2), write and ; then , so . For (3), write and ; then . For (4), write with , so and hence ; then . For (5), if either is then by (6) so is the other and the claim holds; otherwise (4) gives and , so and . For (6), means ; conversely . □
The relation is thus reflexive and transitive; it is a partial order in the sense of §1.3 when restricted to the natural numbers (where (5) becomes ), but on all of it fails to be antisymmetric precisely because of signs. The units of —the integers dividing —are exactly , and two integers that divide each other are called associates; in the associates of are .
Divisibility is the special case of exact division. The fundamental fact that makes the arithmetic of tractable is that one can always divide with remainder, and that the quotient and remainder are uniquely determined once a convention for the remainder’s range is fixed.
Let and with . Then there exist unique integers (the quotient) and (the remainder) such that
Existence. Consider the set
First, . If then . If then, since , taking gives (a product of a nonpositive and a nonpositive factor), so . Thus is a nonempty subset of , and by the well-ordering principle (Theorem 2.1) it has a least element for some . By construction . If , then would lie in and be strictly smaller than , contradicting minimality. Hence .
Uniqueness. Suppose with . Then , so . But , and the only multiple of strictly between and is . Hence , and then with forces . □
The hypothesis is only for definiteness. For general one obtains unique with and , by applying the theorem to and adjusting the sign of . Note that the remainder convention differs from the truncation behaviour of many programming languages, where the remainder of a negative dividend may be negative; for the number-theoretic results below the convention above is the appropriate one.
We denote the remainder produced by the division algorithm by , and the quotient by when (the floor of the rational number ). With this notation, holds precisely when .
A common divisor of integers and is an integer with and . The greatest common divisor of and , not both zero, is the largest such ; it is denoted . By convention . Integers and are coprime (or relatively prime) if .
The greatest common divisor is well defined when : the set of common divisors is nonempty (it contains ) and bounded above (every common divisor of, say, the nonzero has absolute value at most by Proposition 2.3(4)), so it has a largest element, which is positive since is a common divisor. We establish a much stronger characterisation shortly: the gcd is not merely the numerically largest common divisor but is divisible by every common divisor. The key computational engine is the following observation.
Let . For any ,
In particular, if then , and .
It suffices to show the two pairs and have exactly the same common divisors; equal sets of common divisors have equal greatest elements (and the same coprimality status). If and , then by Proposition 2.3(3), so is a common divisor of and . Conversely, if and , then , so is a common divisor of and . The two sets of common divisors coincide. Finally because the common divisors of and are exactly the divisors of , the largest of which in absolute value is (and when ; the case is the convention ). □
Iterating the lemma with the division algorithm yields the oldest nontrivial algorithm in mathematics.
Let be integers with . Define a sequence of remainders by , , and, as long as , let , so that
The sequence of positive remainders is strictly decreasing, so some ; the last nonzero remainder satisfies .
The remainders are nonnegative integers and, while nonzero, strictly decreasing because . A strictly decreasing sequence of nonnegative integers cannot be infinite (again by well-ordering: otherwise the set of values would have no least element), so the algorithm terminates with some and . By Lemma 2.7, each step preserves the gcd:
using (signs do not affect common divisors). □
Compute :
The last nonzero remainder is , so . Indeed and , with .
The Euclidean algorithm is efficient. The number of division steps for inputs is ; the worst case occurs at consecutive Fibonacci numbers (Lamé’s theorem), where every quotient equals except the final one (which equals ) and the remainders shrink as slowly as possible. With schoolbook arithmetic on -bit inputs the whole computation costs bit operations. This efficiency is what renders gcd-based cryptographic operations—above all modular inversion, below—practical at the sizes used in Halo 2 and Orchard.
The Euclidean algorithm computes the gcd, but the back-substitution of its equations yields something more powerful: the gcd is an integer linear combination of the inputs. This is among the most useful facts in elementary number theory.
Let , not both zero, and let . Then there exist integers with
Moreover is the smallest positive integer expressible in the form with , and the set of all such combinations is exactly the set of multiples of :
Let . This set contains and and is closed under addition and under multiplication by any integer; concretely, if and lie in , then for any one has
Since are not both zero, contains a positive element (one of ), so the set of positive elements of is nonempty. By well-ordering it has a least element .
We claim that divides every element of . Indeed, let and write with by the division algorithm. Then because is closed under the operations just described. By minimality of among positive elements of , and , necessarily . Hence for every ; in particular and , so is a common divisor of and . Conversely, any common divisor of and divides by Proposition 2.3(3). Therefore is a common divisor that is divisible by every common divisor; being positive, it is in particular the greatest common divisor, so . The displayed equation follows, is the least positive element of , and because every element of is a multiple of , as shown, and conversely every multiple lies in . □
The proof yields a characterisation of the gcd that is independent of the order : is, up to sign, the unique common divisor of and that is divisible by every common divisor. This is the formulation that survives in settings where “largest” may make no sense but “divisible by every common divisor” still does; later sections adopt it when they leave the integers. We call a nonempty subset closed under addition and under multiplication by arbitrary integers an ideal; the content of Bézout’s identity is that every ideal of has the form for a single generator . Ideals recur in 4, where they drive a general construction whose prototype is the passage from integers to congruence classes carried out later in this section.
The Bézout coefficients are not unique. If , then for every ,
since the added terms and cancel; and these are all the solutions. To see this, note first that and are coprime: a common divisor of both makes a common divisor of and , so by Proposition 2.3(3), forcing . Now suppose . Subtracting and dividing by gives , so divides ; by Proposition 2.15(1) below (whose proof rests only on Bézout’s identity, already established), divides , say with . Substituting back gives , so when ; and when we have , , and places in the family. To compute a particular pair efficiently, we augment the Euclidean algorithm so that it carries each remainder as an explicit combination of and .
There is an algorithm that, on input not both zero, outputs together with integers satisfying , using the same number of division steps as the Euclidean algorithm.
Alongside the remainder sequence of Theorem 2.8, maintain two auxiliary sequences and with the invariant
Initialise (taking for clarity; we restore signs at the end)
so (2.5) holds for . At step , having from the division algorithm, set
Then
so induction preserves (2.5). When the algorithm terminates with and , the invariant for reads ; output , . If , then and termination is immediate with : no division step runs, the last nonzero remainder is (Lemma 2.7), and the invariant at already gives the output . If , termination and the value of are exactly as in Theorem 2.8. In either case each step does only a constant amount of extra work. For general inputs, run the algorithm on to obtain (recall ) and output , , so that . □
In practice it is convenient to lay the computation out as a table with columns , computing each new row from the previous two.
Run the extended algorithm on , (continuing Example 2.9). The quotients are .
For instance, row is row minus times row : , , and indeed . The last nonzero remainder is , with
Thus . The final row up to sign records the homogeneous solution: .
A first, decisive application of Bézout’s identity is Euclid’s lemma, the property of primes that ultimately forces unique factorisation.
Let .
If and , then .
If , , and , then .
If and , then .
(1) By Bézout there are with . Multiply by : . Since , divides both terms on the right, hence .
(2) Write . Since and , part (1) gives , say . Then , so .
(3) By Bézout, and for suitable integers. Multiplying,
which exhibits as an integer combination of and . Hence divides , so it equals . □
An integer is prime if its only positive divisors are and . An integer that is not prime is composite; thus is composite iff for some integers . The integer is a unit and is by convention neither prime nor composite.
The exclusion of from the primes is not arbitrary: it is exactly what makes factorisation into primes unique, since otherwise one could insert arbitrarily many factors of . The decisive property of primes is the prime case of Euclid’s lemma.
Let be prime and . If then or . More generally, if then for some .
The only positive divisors of are and , so . If then and the claim holds; otherwise , and Proposition 2.15(1) gives . The general statement follows by induction on : from it follows that or , and the inductive hypothesis handles the latter. □
Every integer can be written as a product of primes,
and this factorisation is unique up to the order of the factors. Equivalently, there is a unique expression
Existence. Suppose, for contradiction, that some integer is not a product of primes, and let be the least such (well-ordering). Then is not prime (a prime is trivially a product of one prime), so with . By minimality, each of is a product of primes; concatenating these factorisations expresses as a product of primes, a contradiction. Hence every factors into primes.
Uniqueness. Suppose
are two factorisations of the same integer into primes. The argument proceeds by induction on . If the product is the empty product , forcing as well (a nonempty product of primes is ). For the inductive step, divides the right-hand product, so by Lemma 2.17 for some . Since is prime, its only divisor is itself, so . Cancelling this common factor (legitimate as has no zero divisors) yields
where the hat denotes omission. By the inductive hypothesis these two factorisations agree up to order, with ; restoring shows the original factorisations agree up to order. Collecting equal primes into prime powers gives the canonical form, whose uniqueness is immediate from the uniqueness of the multiset of primes—the factors counted with multiplicity, without regard to order. □
Both halves of the theorem are needed and have different characters. Existence is a statement about the order structure (well-ordering) and would hold in any reasonable factorisation; uniqueness rests squarely on Euclid’s lemma, hence on Bézout, hence on the division algorithm. There are number systems with a division-like structure failing Euclid’s lemma in which factorisation into irreducibles is not unique; the integers avoid this pathology precisely because they admit division with remainder, from which the whole chain above flows.
The development now passes from divisibility to the arithmetic of remainders. Fix an integer , the modulus.
Let and . The integer is congruent to modulo , written
if , equivalently if and leave the same remainder upon division by .
The two formulations agree: if and with , then , and iff iff (since ).
Fix . Congruence modulo is an equivalence relation on that is moreover compatible with addition and multiplication: if and , then
Consequently for all , and one may substitute congruent values freely in any polynomial expression with integer coefficients.
Reflexivity (), symmetry (), and transitivity ( and give by Proposition 2.3(3)) are immediate. For compatibility, write and . Then
and
so both and . The statement about powers and polynomial expressions follows by induction from the multiplicative case. □
Because congruence is an equivalence relation, it partitions into disjoint congruence classes (also called residue classes).
The congruence class (or residue class) of modulo is
We write the set of all congruence classes as
By the division algorithm every integer is congruent modulo to exactly one of , namely its remainder; hence the classes are distinct and exhaust . The set is the standard system of representatives, called the least nonnegative residues.
Division is the inverse of multiplication, so the opening problem of the section comes down to a multiplicative question about congruences: for which does the congruence admit a solution? The Euclidean machinery characterises the solvable cases completely and computes the solutions.
Let . A class is a unit (or is invertible) if there exists an integer with . Any class with this property is the (modular) inverse of , written ; one also calls a modular inverse of modulo . We write the set of units as
The definition is well posed on classes: by Proposition 2.21, if and then , so whether holds depends only on the classes and , never on the representatives chosen. The definite article in “the inverse” is justified by the uniqueness part of the next theorem—the payoff of the section.
Let and . The class is a unit in if and only if . When , the inverse is unique, and the extended Euclidean algorithm computes a representative: if , then .
Suppose . By Bézout (Theorem 2.11) there are with . Reducing modulo , , so is an inverse of . The extended Euclidean algorithm (Theorem 2.13) produces such a explicitly.
Conversely, if is a unit, say , then for some , i.e. . Any common divisor of and divides the left side, hence divides ; thus .
Uniqueness: if and , then —a sandwich using only the associativity and commutativity of integer multiplication together with Proposition 2.21—so . □
Consider the computation of . The extended Euclidean algorithm on :
so . Back-substituting:
Hence , and . Check: , so .
Counting the units will matter as much as finding them: the count defined next carries structural weight in later sections, and we fix it here so that those sections can cite a definition rather than re-derive one.
Euler’s totient function is the number of integers with and . Equivalently, .
The two counts agree: the classes of run exactly once through all of (the class of being ), and by Theorem 2.24 the class is a unit precisely when .
We have , and for prime : for the positive divisor of is or , and rules out , so every one of the nonzero classes is a unit. By direct enumeration, .
The cheque presented at the head of the section is now cashed. To divide by in the finite world of remainders modulo is to multiply by the inverse class ; Theorem 2.24 says exactly when that inverse exists—precisely when , hence for every nonzero class when the modulus is prime—and the extended Euclidean algorithm computes it in division steps (Remark 2.10). The laws verified along the way—associativity, commutativity, distributivity, identities, negatives, and now inverses—have been stated concretely, for the integers and their congruence classes alone. They are instances of patterns that pervade mathematics; Sections 3 and 4 isolate those patterns, give them their standard names, and re-read in their light. Nothing proved there revises anything proved here.