You're viewing the readable version of this site. The interactive extras (search, diagrams, read-aloud) need JavaScript and a current browser. Enable JavaScript; if it is already enabled, update your browser.

Learn · The Concrete Discrete Math of Real Systems

growing

Midnight Is Zero Again

Remainders turn repetition into a finite world where addition, multiplication, schedules, checksums, and inverses obey one reusable set of laws.

·

discrete-math, modular-arithmetic, congruence, groups, checksums, learn

If a number divides the difference of two numbers aa and bb, then aa and bb are said to be congruent.

Carl Friedrich Gauss, Disquisitiones Arithmeticae, article 1, 1801 English translation

The preceding chapter ended with a finite machine returning to a state it had visited before. Here that repetition becomes arithmetic. You will define congruence; prove that addition and multiplication respect it; find when division is legal by computing inverses; and use the laws to explain schedules, circular storage, and check digits. You will also retrieve the book's earlier distinction between a value and its equivalence class.

Four hours after twenty-three

Write the hours after 23 without stopping:

23, 24, 25, 26, 27, …

Now write what the clock displays:

23, 0, 1, 2, 3, …

The clock has not made 2727 equal to 33 as integers. It has declared them equivalent for the purpose of hour-of-day: their difference, 24, is a whole number of revolutions. We write

273(mod24). 27 \equiv 3 (mod 24).

More generally, ab(modn)a \equiv b (mod n) exactly when nn divides aba-b. Every integer belongs to one of nn equivalence classes, labeled by the remainders 0,1,,n10,1,\ldots,n-1.

Congruence modulo n — equality of remainders after division by nn. It is an equivalence relation: reflexive, symmetric, and transitive. See MIT Mathematics for Computer Science, number theory readings.

Note

The person behind congruence notation. Carl Friedrich Gauss (1777–1855) introduced the systematic notation and theory of congruences in Disquisitiones Arithmeticae. Arithmetic with remainders long predates him, including the Chinese remainder problem; the attribution is to Gauss's formulation, not the invention of remainder reasoning.

Prediction — equality depends on the modulus.

Reduce whenever you like

The useful miracle is compatibility. If aaa \equiv a' and bbb \equiv b' modulo nn, then

a+ba+b(modn) a+b \equiv a'+b' (mod n)

and

abab(modn). ab \equiv a'b' (mod n).

For addition, subtract the right side from the left: (aa)+(bb)(a-a')+(b-b'). Both pieces are multiples of nn, so their sum is. Multiplication follows by writing abab=a(bb)+b(aa)ab-a'b'=a(b-b')+b'(a-a').

That proof grants an engineering license: reduce before an operation, after it, or between every step. The final remainder cannot change. Large exponents become manageable by repeated squaring and reduction; ring-buffer indices become (index + 1) mod capacity; weekday arithmetic never leaves seven states.

The remainder classes support addition and multiplication, with 00 and 11 as identities and additive inverses obtained by walking around the circle backward. This is the ring of integers modulo nn.

Ring — a set with addition and multiplication obeying the familiar associative and distributive laws, with additive inverses. Modular integers form a ring. See Wolfram MathWorld's reference definition.

Division has a gate

On an ordinary calculator, divide by any nonzero number. On a clock, division means multiplying by an inverse. The inverse of aa modulo nn is a number xx satisfying

ax1(modn). ax \equiv 1 (mod n).

Modulo 7, the inverse of 3 is 5 because 35=1513\cdot5=15\equiv1. Modulo 6, 3 has no inverse: its multiples visit only 0 and 3. The exact boundary is gcd(a,n) = 1. Bézout's identity proves it. If ax+ny=1ax+ny=1, reducing modulo nn leaves ax1ax\equiv1; conversely, an inverse gives such an integer equation.

The gate in motion. The first cell checks the divisor's inverse; the second performs the division. Pliara Math publishes both results as one inert transcript that the reader's browser verifies before adding MathML.

denominator := modular(2, 7)
inverse_witness := modular(4, 7)
expect(denominator * inverse_witness == modular(1, 7))
inverse_witness
4 (mod 7)exact · claimed observation
numerator := modular(3, 7)
denominator := modular(2, 7)
expect(denominator == modular(2, 7))
numerator / denominator
5 (mod 7)exact · claimed observation
Notebook evidence
Language
pliara.math/1
Profile
pliara.math.exact-v1
Artifact
1e7af9fb56e50ca87b672b5a10d94645f21f4da105de4a440d33619a8de4015c
Cells
2
Initial trust
claimed observation
Completion — determine whether division is legal.

When nn is prime, every nonzero remainder is coprime to nn, so every nonzero value has an inverse. The modular ring becomes a field. This is why prime moduli appear so often: division regains its ordinary shape everywhere except zero.

A check digit is a conserved remainder

Suppose a code chooses its final digit so the weighted digit sum is congruent to zero modulo 10. At the receiver, recompute the sum. A single changed digit usually changes the remainder, exposing damage. The check does not prove the message is correct—different damaged messages can share one remainder, as the pigeonhole chapter already guaranteed. It purchases a quantified class of detectable errors, not certainty.

The Luhn method, patented by IBM researcher Hans Peter Luhn, uses alternating weights and decimal digit sums so common transcription errors disturb the final congruence.

Note

The person behind the Luhn algorithm. Hans Peter Luhn (1896–1964) was an IBM researcher whose work also shaped information retrieval and keyword indexing. His 1954 filing, granted as US Patent 2,950,048, describes the checking method now bearing his name. A check digit detects selected mistakes; it is not a cryptographic signature and does not establish who produced the number.

Where the circle runs out

  • Modular equality always names its modulus. Omitting it changes the claim.
  • Cancellation is unsafe without an inverse. From abacab\equiv ac one may cancel aa only when aa is invertible modulo nn.
  • Wraparound in machine integers resembles modular arithmetic, but language rules differ. Signed overflow may trap, wrap, or be undefined.
  • A small checksum has unavoidable collisions. It detects a promised error family; it does not authenticate adversarial data.

Lessons

  • Congruence groups integers by equal remainder.
  • Addition and multiplication respect congruence, so reduction may happen at any point.
  • A remainder is divisible only by values coprime to the modulus; prime moduli make every nonzero class invertible.
  • Circular schedules, buffer indices, and check digits are the same algebra in different clothing.

Practice

  1. Without looking back, compute 2102^{10} modulo 7 by reducing after each squaring.
  2. Explain why 2x2(mod6)2x\equiv2 (mod 6) has more than one solution and which failed cancellation would hide them.
  3. A service rotates among 11 shards by request number modulo 11. Which shard receives request 10,000? Show a reduction that never handles a large number.
  4. One day later, reconstruct the rule for modular invertibility from the phrase “shares no factor with the clock.”

The next question is about damage

A check digit can say that a word probably moved to the wrong remainder class. It usually cannot say which digit changed, much less repair it. To correct damage, valid messages must be placed far enough apart that a received word remains closest to only one of them. The next chapter turns redundancy into geometry.

References

  1. Gauss. “Disquisitiones Arithmeticae.” 1801. — articles 1–12 introduce congruence systematically
  2. Lehman, Leighton, Meyer. “Mathematics for Computer Science.” MIT OpenCourseWare, 2024. — the number-theory chapters prove the laws and Bézout's identity
  3. Luhn. “Computer for Verifying Numbers.” US Patent 2,950,048, 1960. — the primary specification of the decimal checking method