taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Volume C1 · Basic concepts · TAOCP Section 1.2.4

Integer functions and elementary number theory

Draft. This chapter is written and checked by the tools of the project, and a person has not reviewed it yet. Read it with care.

Read it next to Section 1.2.4 of the book. The nodes and the exercises of the section.

Contents
  1. Integer functions and elementary number theory

Integer functions and elementary number theory

Overview

Section 1.2.4 of TAOCP has two parts. The first part defines the floor ⌊x⌋\lfloor x \rfloor and the ceiling ⌈x⌉\lceil x \rceil of a real number, and then the remainder x mod yx \bmod y for real xx and yy. The second part defines congruence, states four laws for it (Laws A to D), and proves Fermat's theorem: ap≡aa^p \equiv a modulo a prime pp. The section uses the greatest common divisor of Section 1.1 and the induction of Section 1.2.1. Later sections use the floor in many analyses of algorithms, and Chapter 3 uses congruences in the study of random numbers.

The book leaves the proofs of the four laws to the exercises. C1 proves them here, because the proof of Fermat's theorem needs Law B, and Law B needs the fact that two relatively prime numbers have a combination equal to 11. C1 also proves that the factorization into primes exists and is unique, which is the claim of exercise 21.

The ideas

Two equivalences carry every proof about the floor. For an integer nn and a real xx, the statements n≤⌊x⌋n \le \lfloor x \rfloor and n≤xn \le x are equivalent, and so are ⌈x⌉≤n\lceil x \rceil \le n and x≤nx \le n. Each identity about the floor and the ceiling follows from these two equivalences, because an integer is fixed by the set of the integers that are at most it. C1 states them in the first block and uses them in all the later proofs.

The remainder is the part of xx that is left when the multiples of yy are taken away. The definition x mod y=x−y⌊x/y⌋x \bmod y = x - y\lfloor x/y \rfloor works for each real xx and yy. The result is zero or has the sign of yy, so x mod yx \bmod y lies in [0,y)[0, y) for y>0y > 0 and in (y,0](y, 0] for y<0y < 0. Many programming languages use another rule for a negative xx, and a reader must not mix the two.

Congruence is equality of remainders. The statement x≡y(modz)x \equiv y \pmod z says that xx and yy leave the same remainder on division by zz, and for integers it says that zz divides x−yx - y. The four laws say which operations keep a congruence true. Addition, subtraction and multiplication always keep it. Division needs a divisor that is relatively prime to the modulus.

Fermat's theorem is a counting argument. The numbers 0,a,2a,…,(p−1)a0, a, 2a, \ldots, (p-1)a leave pp different remainders when pp is a prime that does not divide aa. So the remainders are the numbers 0,1,…,p−10, 1, \ldots, p-1 in a new order. Multiply them all and cancel to get the theorem.

Definitions, results and proofs

Definition C1.1.2.4.1 (the floor and the ceiling, TAOCP Section 1.2.4). For a real number xx, the floor ⌊x⌋\lfloor x \rfloor is the greatest integer that is less than or equal to xx, and the ceiling ⌈x⌉\lceil x \rceil is the least integer that is greater than or equal to xx.

Node: TAH7HVKG6J · status: not stated yet

Explanation. The definition is meaningful for each real xx, since the integers that are at most xx are bounded above and not empty, and so they have a greatest one. The same holds for the integers that are at least xx. The important point is the sign: ⌊−12⌋=−1\lfloor -\tfrac12 \rfloor = -1, not 00. The floor goes down on the number line, and it does not cut off the digits after the point. The two equivalences below are the tools for all proofs. For an integer nn and a real xx:

  • n≤⌊x⌋n \le \lfloor x \rfloor if and only if n≤xn \le x, and ⌊x⌋<n\lfloor x \rfloor < n if and only if x<nx < n;
  • ⌈x⌉≤n\lceil x \rceil \le n if and only if x≤nx \le n, and n<⌈x⌉n < \lceil x \rceil if and only if n<xn < x;
  • ⌊x⌋≤n\lfloor x \rfloor \le n if and only if x<n+1x < n + 1, and n−1<⌈x⌉n - 1 < \lceil x \rceil if and only if n−1<xn - 1 < x.

In Lean, the floor is Int.floor with the notation ⌊x⌋, and the ceiling is Int.ceil with ⌈x⌉. The equivalences are Int.le_floor and Int.ceil_le.

Example. ⌊2⌋=1\lfloor \sqrt 2 \rfloor = 1 and ⌈2⌉=2\lceil \sqrt 2 \rceil = 2. ⌊1/2⌋=0\lfloor 1/2 \rfloor = 0 and ⌈−1/2⌉=0\lceil -1/2 \rceil = 0 and ⌊−1/2⌋=−1\lfloor -1/2 \rfloor = -1. For an integer, ⌈5⌉=⌊5⌋=5\lceil 5 \rceil = \lfloor 5 \rfloor = 5. ⌊1.1⌋=1\lfloor 1.1 \rfloor = 1, ⌈−1.1⌉=−1\lceil -1.1 \rceil = -1, ⌊−1.1⌋=−2\lfloor -1.1 \rfloor = -2, ⌊0.99999⌋=0\lfloor 0.99999 \rfloor = 0, and ⌊lg⁡35⌋=5\lfloor \lg 35 \rfloor = 5 because 25=32≤35<642^5 = 32 \le 35 < 64.

Proof of the equivalences. By the definition, ⌊x⌋≤x\lfloor x \rfloor \le x, and ⌊x⌋\lfloor x \rfloor is the greatest integer with this property. If n≤⌊x⌋n \le \lfloor x \rfloor, then n≤xn \le x. If n≤xn \le x, then nn is an integer that is at most xx, and so n≤⌊x⌋n \le \lfloor x \rfloor, since ⌊x⌋\lfloor x \rfloor is the greatest. The second claim is the negation of the first. The statement about the ceiling is the mirror image. For ⌊x⌋≤n\lfloor x \rfloor \le n if and only if x<n+1x < n + 1: take the negation of the first equivalence with the integer n+1n + 1: ⌊x⌋<n+1\lfloor x \rfloor < n + 1 if and only if x<n+1x < n + 1, and for integers ⌊x⌋<n+1\lfloor x \rfloor < n + 1 is the same as ⌊x⌋≤n\lfloor x \rfloor \le n. □\square

Consequences. Four facts follow at once from these equivalences.

First, x−1<⌊x⌋≤x≤⌈x⌉<x+1x - 1 < \lfloor x \rfloor \le x \le \lceil x \rceil < x + 1. The middle inequality is the definition of both. For x−1<⌊x⌋x - 1 < \lfloor x \rfloor: the integer ⌊x⌋+1\lfloor x \rfloor + 1 is above ⌊x⌋\lfloor x \rfloor, so it is not at most xx, and ⌊x⌋+1>x\lfloor x \rfloor + 1 > x. The bound for the ceiling is the same.

Second, ⌈x⌉=⌊x⌋\lceil x \rceil = \lfloor x \rfloor if and only if xx is an integer, and otherwise ⌈x⌉=⌊x⌋+1\lceil x \rceil = \lfloor x \rfloor + 1. If xx is an integer, then xx is the greatest integer at most xx and the least integer at least xx. If xx is not an integer, then ⌊x⌋<x<⌊x⌋+1\lfloor x \rfloor < x < \lfloor x \rfloor + 1, so ⌊x⌋+1\lfloor x \rfloor + 1 is an integer that is at least xx and no integer lies between ⌊x⌋\lfloor x \rfloor and ⌊x⌋+1\lfloor x \rfloor + 1.

Third, ⌊−x⌋=−⌈x⌉\lfloor -x \rfloor = -\lceil x \rceil. For each integer nn: n≤⌊−x⌋n \le \lfloor -x \rfloor if and only if n≤−xn \le -x, if and only if x≤−nx \le -n, if and only if ⌈x⌉≤−n\lceil x \rceil \le -n, if and only if n≤−⌈x⌉n \le -\lceil x \rceil. Two integers that are at most the same integers are equal.

Fourth, for integers mm and nn with n>0n > 0 and for real xx, ⌊(x+m)/n⌋=⌊(⌊x⌋+m)/n⌋\lfloor (x + m)/n \rfloor = \lfloor (\lfloor x \rfloor + m)/n \rfloor (exercise 35). The proof uses the first equivalence twice and is left to the exercise.

Definition C1.1.2.4.2 (the remainder, TAOCP eq. 1.2.4(1)). For real numbers xx and yy, x mod y=x−y⌊x/y⌋(y≠0),x mod 0=x.x \bmod y = x - y\lfloor x/y \rfloor \quad (y \ne 0), \qquad x \bmod 0 = x.

Node: TAJTHY87JS · Lean: TAOCP.kmod, TAOCP.S1_2_4.eq1_ne, TAOCP.S1_2_4.eq1_zero · status: not stated yet

Explanation. The number ⌊x/y⌋\lfloor x/y \rfloor is the quotient, and x mod yx \bmod y is the remainder. The case y=0y = 0 is defined separately, so that x mod yx \bmod y exists for every pair, and so that x−(x mod y)x - (x \bmod y) is a multiple of yy in all cases (the multiple 00 when y=0y = 0). For a negative yy the remainder is zero or negative. This differs from the remainder of the % operator of C, which has the sign of xx. In Lean, the book's rule for integers is Int.fmod, and Int.emod is another rule: it returns a result that is never negative. For real numbers and y>0y > 0, the book's x mod yx \bmod y is toIcoMod hy 0 x, the reduction of xx into the interval [0,y)[0, y), where hy is a proof of 0<y0 < y.

Example. 100 mod 3=1100 \bmod 3 = 1, 100 mod 7=2100 \bmod 7 = 2, −100 mod 7=5-100 \bmod 7 = 5 and −100 mod 0=−100-100 \bmod 0 = -100. For real numbers, 1.1 mod 1=0.11.1 \bmod 1 = 0.1 and 7.25 mod 1=0.257.25 \bmod 1 = 0.25. With a negative modulus, 5 mod (−3)=−15 \bmod (-3) = -1 and −2 mod (−3)=−2-2 \bmod (-3) = -2. A real example: 7.25 mod (−2)=−0.757.25 \bmod (-2) = -0.75. The note on the sine and the tangent: tan⁡x=tan⁡(x mod π)\tan x = \tan (x \bmod \pi) for each xx where the tangent is defined, because the tangent has the period π\pi.

Theorem C1.1.2.4.3 (the bounds of the remainder, TAOCP eq. 1.2.4(2)). For y≠0y \ne 0, 0≤xy−⌊xy⌋=x mod yy<1.0 \le \frac{x}{y} - \Bigl\lfloor \frac{x}{y} \Bigr\rfloor = \frac{x \bmod y}{y} < 1.

  • If y>0y > 0, then 0≤x mod y<y0 \le x \bmod y < y.
  • If y<0y < 0, then 0≥x mod y>y0 \ge x \bmod y > y.
  • For each yy, the quantity x−(x mod y)x - (x \bmod y) is an integral multiple of yy.

Node: TAW3XVE528 · Lean: TAOCP.S1_2_4.eq2, TAOCP.S1_2_4.eq2a, TAOCP.S1_2_4.eq2b, TAOCP.S1_2_4.eq2c · status: proved

Explanation. The first inequality is the statement ⌊t⌋≤t\lfloor t \rfloor \le t with t=x/yt = x/y, and the last is t<⌊t⌋+1t < \lfloor t \rfloor + 1. The middle equality is the definition of the remainder divided by yy. Multiplication by yy gives the bounds of the remainder, and for a negative yy the inequalities turn around. The remainder with a given sign of yy is unique: exercise 16 shows that if y>0y > 0, 0≤z<y0 \le z < y and (x−z)/y(x - z)/y is an integer, then z=x mod yz = x \bmod y.

Example. For x=−2x = -2 and y=3y = 3: x/y=−0.666…x/y = -0.666\ldots, the floor is −1-1, and x/y−⌊x/y⌋=0.333…=(x mod y)/y=1/3x/y - \lfloor x/y \rfloor = 0.333\ldots = (x \bmod y)/y = 1/3. For x=5x = 5 and y=−3y = -3: x/y=−1.666…x/y = -1.666\ldots, the floor is −2-2, the remainder is 5−(−3)(−2)=−15 - (-3)(-2) = -1, and −1/(−3)=0.333…-1/(-3) = 0.333\ldots equals x/y−⌊x/y⌋=0.333…x/y - \lfloor x/y \rfloor = 0.333\ldots. The remainder −1-1 lies in (−3,0](-3, 0].

Proof. By the consequences of the floor, t−1<⌊t⌋≤tt - 1 < \lfloor t \rfloor \le t for each real tt, so 0≤t−⌊t⌋<10 \le t - \lfloor t \rfloor < 1. Put t=x/yt = x/y. Then (x mod y)/y=(x−y⌊t⌋)/y=t−⌊t⌋(x \bmod y)/y = (x - y\lfloor t \rfloor)/y = t - \lfloor t \rfloor, which gives the displayed claim. If y>0y > 0, multiply the chain 0≤(x mod y)/y<10 \le (x \bmod y)/y < 1 by yy to get 0≤x mod y<y0 \le x \bmod y < y. If y<0y < 0, the multiplication by yy turns the signs around and gives 0≥x mod y>y0 \ge x \bmod y > y. The last claim: x−(x mod y)=y⌊x/y⌋x - (x \bmod y) = y\lfloor x/y \rfloor, which is yy times an integer. For y=0y = 0 the multiple is 0⋅00 \cdot 0 and the claim holds. □\square

Example C1.1.2.4.4 (three values of the remainder, TAOCP eq. 1.2.4(3)). 5 mod 3=25 \bmod 3 = 2, 18 mod 3=018 \bmod 3 = 0 and −2 mod 3=1-2 \bmod 3 = 1.

Node: TAMJAQRHM4 · Lean: TAOCP.S1_2_4.eq3_a, TAOCP.S1_2_4.eq3_b, TAOCP.S1_2_4.eq3_c · status: not stated yet

Explanation. The first two values are the usual remainders of the integers. The third is the point of the example: for a negative dividend the remainder is still in [0,3)[0, 3), and the quotient is ⌊−2/3⌋=−1\lfloor -2/3 \rfloor = -1, not 00. A language that has the quotient 00 here gives the remainder −2-2, and that is not the definition of the book. For integers, x mod y=0x \bmod y = 0 if and only if yy divides xx. The book writes y∣xy \mid x for "yy is a positive integer and x mod y=0x \bmod y = 0".

Example. Check by the definition. For 5 mod 35 \bmod 3: ⌊5/3⌋=1\lfloor 5/3 \rfloor = 1 and 5−3⋅1=25 - 3 \cdot 1 = 2. For 18 mod 318 \bmod 3: ⌊6⌋=6\lfloor 6 \rfloor = 6 and 18−18=018 - 18 = 0. For −2 mod 3-2 \bmod 3: ⌊−2/3⌋=−1\lfloor -2/3 \rfloor = -1 and −2−3(−1)=1-2 - 3(-1) = 1. Also, 3∣183 \mid 18, and 3∤53 \nmid 5, and 7∣10017 \mid 1001.

Theorem C1.1.2.4.5 (a number is its floor plus its fractional part, TAOCP eq. 1.2.4(4)). For each real number xx, the quantity x mod 1x \bmod 1 is the fractional part of xx, it lies in [0,1)[0, 1), and x=⌊x⌋+(x mod 1)x = \lfloor x \rfloor + (x \bmod 1).

Node: TASAKWKRBA · Lean: TAOCP.S1_2_4.eq4 · status: proved

Explanation. The identity is the definition (1) with y=1y = 1: x mod 1=x−⌊x⌋x \bmod 1 = x - \lfloor x \rfloor. The fractional part of a negative number is not the digits after the point of its decimal form: for x=−7.25x = -7.25 the floor is −8-8 and the fractional part is 0.750.75. In Lean, the fractional part is Int.fract x, and the lemma is Int.floor_add_fract.

Example. 7.25=7+0.257.25 = 7 + 0.25. −7.25=−8+0.75-7.25 = -8 + 0.75. 5=5+05 = 5 + 0. The rounding of exercise 5 is ⌊x+12⌋\lfloor x + \tfrac12 \rfloor for a positive xx: for x=2.5x = 2.5 it gives 33 and for x=2.4x = 2.4 it gives 22. For a negative xx the same formula rounds a half toward plus infinity, so ⌊−2.5+12⌋=−2\lfloor -2.5 + \tfrac12 \rfloor = -2.

Proof. Put y=1y = 1 in eq. 1.2.4(1): x mod 1=x−1⋅⌊x/1⌋=x−⌊x⌋x \bmod 1 = x - 1 \cdot \lfloor x/1 \rfloor = x - \lfloor x \rfloor. So x=⌊x⌋+(x mod 1)x = \lfloor x \rfloor + (x \bmod 1). The bounds are eq. 1.2.4(2) with y=1y = 1. □\square

Definition C1.1.2.4.6 (the greatest common divisor and relatively prime integers, TAOCP Section 1.2.4). The greatest common divisor gcd⁡(x,y)\gcd(x, y) of two integers that are not both zero is the greatest integer that divides both. The convention gcd⁡(0,n)=∣n∣\gcd(0, n) = |n| also gives gcd⁡(0,0)=0\gcd(0, 0) = 0. Two integers xx and yy are relatively prime, written x⊥yx \perp y, if gcd⁡(x,y)=1\gcd(x, y) = 1.

Node: TACCSNBG9G · status: not stated yet

Explanation. The number gcd⁡(x,y)\gcd(x, y) is 11 if and only if the only common divisors are 11 and −1-1. Each integer is relatively prime to 11, since 11 is the only positive divisor of 11. By the convention gcd⁡(0,n)=∣n∣\gcd(0, n) = |n|, the only integers relatively prime to 00 are 11 and −1-1. The fraction x/yx/y is in lowest terms if x⊥yx \perp y. In Lean, Nat.Coprime and IsCoprime are the two forms, and Int.gcd is the greatest common divisor. For integers, IsCoprime a b means that ua+vb=1ua + vb = 1 has an integer solution. The next fact proves that gcd⁡(a,b)=1\gcd(a, b) = 1 implies this. The converse holds because a common divisor of aa and bb divides ua+vb=1ua + vb = 1.

Example. gcd⁡(84,36)=12\gcd(84, 36) = 12. 35⊥1235 \perp 12 because the divisors of 3535 are 1,5,7,351, 5, 7, 35 and none of 5,7,355, 7, 35 divides 1212. gcd⁡(0,6)=6\gcd(0, 6) = 6, so 0⊥60 \perp 6 is false and 0⊥10 \perp 1 is true.

Fact (Bezout, the law of inverses of exercise 19). If x⊥mx \perp m, there are integers uu and vv with ux+vm=1ux + vm = 1. So there is an integer x′x' with xx′≡1(modm)xx' \equiv 1 \pmod m.

Proof. This proof takes the least element of a set. Exercise 19 asks for a proof by Algorithm 1.2.1E instead, which also computes uu and vv. The set of positive integers of the form ux+vmux + vm is not empty, since x2+m2x^2 + m^2 is in it when x,mx, m are not both zero. Let dd be the least element of the set, d=u0x+v0md = u_0 x + v_0 m. Divide xx by dd: x=qd+rx = qd + r with 0≤r<d0 \le r < d. Then r=x−qd=(1−qu0)x+(−qv0)mr = x - qd = (1 - qu_0)x + (-qv_0)m has the same form, and r<dr < d, so rr cannot be positive. So r=0r = 0 and d∣xd \mid x. In the same way d∣md \mid m. So dd is a common divisor, and d≤gcd⁡(x,m)=1d \le \gcd(x, m) = 1, so d=1d = 1. For the second claim, take x′=u0x' = u_0: xx′=1−v0m≡1(modm)xx' = 1 - v_0 m \equiv 1 \pmod m. □\square

Example. For x=35x = 35 and m=12m = 12: 35⋅(−1)+12⋅3=135 \cdot (-1) + 12 \cdot 3 = 1, so u=−1u = -1 and v=3v = 3, and x′=−1≡11(mod12)x' = -1 \equiv 11 \pmod{12}. Check: 35⋅11=385=32⋅12+135 \cdot 11 = 385 = 32 \cdot 12 + 1. The numbers uu and vv come from the extension of Euclid's algorithm of Section 1.2.1.

Definition C1.1.2.4.7 (congruence, TAOCP eq. 1.2.4(5)). For numbers xx, yy and zz, the statement x≡y(modz)x \equiv y \pmod z means x mod z=y mod zx \bmod z = y \bmod z.

Node: TA5WVCFA8D · Lean: TAOCP.S1_2_4.Congr, TAOCP.S1_2_4.eq5 · status: proved

Explanation. For integers xx and yy and an integer z≠0z \ne 0, the statement is the same as: zz divides x−yx - y. For z=0z = 0, the convention x mod 0=xx \bmod 0 = x makes it mean x=yx = y, and exercise 11 asks for this. A congruence is an equivalence relation, since it is an equality of remainders. In Lean, the relation is Int.ModEq z x y, written x ≡ y [ZMOD z], and it is defined as equality of Int.emod. For integers it is the same as the book's relation, because both are the relation that zz divides x−yx - y.

Example. 17≡3(mod7)17 \equiv 3 \pmod 7, because 17−3=1417 - 3 = 14. −2≡1(mod3)-2 \equiv 1 \pmod 3, since both leave 11. 5≢2(mod4)5 \not\equiv 2 \pmod 4. For the modulus 00, 4≡44 \equiv 4 and 4≢54 \not\equiv 5. An example of exercise 14: if x mod 3=2x \bmod 3 = 2 and x mod 5=3x \bmod 5 = 3, then x mod 15=8x \bmod 15 = 8, since 88 is the only number in 0,…,140, \ldots, 14 with both remainders (the check is by the table of the fifteen numbers).

Proof that the two descriptions agree. Let xx and yy be integers and z>0z > 0. If x mod z=y mod zx \bmod z = y \bmod z, then x−y=z(⌊x/z⌋−⌊y/z⌋)x - y = z(\lfloor x/z \rfloor - \lfloor y/z \rfloor), a multiple of zz. If x−y=zkx - y = zk, then (x mod z)−(y mod z)=(x−y)−z(⌊x/z⌋−⌊y/z⌋)(x \bmod z) - (y \bmod z) = (x - y) - z(\lfloor x/z \rfloor - \lfloor y/z \rfloor) is a multiple of zz, and it lies in (−z,z)(-z, z) by eq. 1.2.4(2). The only multiple of zz in that range is 00. For z<0z < 0 the same argument holds with ∣z∣|z|. □\square

Law A (sums, differences and products, TAOCP Section 1.2.4). If a≡ba \equiv b and x≡y(modm)x \equiv y \pmod m, then a±x≡b±ya \pm x \equiv b \pm y and ax≡by(modm)ax \equiv by \pmod m.

Node: Law 1.2.4A · Lean: TAOCP.S1_2_4.lawA

Explanation. In a sum, a difference or a product, a number can be replaced by any number that is congruent to it modulo mm. The new result is congruent to the old one. A power follows by induction on the exponent: a≡ba \equiv b implies ak≡bka^k \equiv b^k. In Lean, the lemmas are Int.ModEq.add, Int.ModEq.sub and Int.ModEq.mul, and Int.ModEq.pow.

Example. 17≡317 \equiv 3 and 11≡4(mod7)11 \equiv 4 \pmod 7. Then 17+11=28≡017 + 11 = 28 \equiv 0 and 3+4=7≡03 + 4 = 7 \equiv 0, so the sums agree. And 17⋅11=187=26⋅7+517 \cdot 11 = 187 = 26 \cdot 7 + 5 and 3⋅4=12≡53 \cdot 4 = 12 \equiv 5, so the products agree. Also 172=289=41⋅7+217^2 = 289 = 41 \cdot 7 + 2 and 32=9≡23^2 = 9 \equiv 2.

Proof. Take integers and m≠0m \ne 0 (the case m=0m = 0 is equality, and the laws of equality give the claim). Write a−b=mra - b = mr and x−y=msx - y = ms for integers rr and ss. Then (a±x)−(b±y)=m(r±s)(a \pm x) - (b \pm y) = m(r \pm s), and ax−by=a(x−y)+(a−b)y=m(as+ry)ax - by = a(x - y) + (a - b)y = m(as + ry). So mm divides each difference. □\square

Law B (cancelling a factor, TAOCP Section 1.2.4). If ax≡byax \equiv by and a≡b(modm)a \equiv b \pmod m and a⊥ma \perp m, then x≡y(modm)x \equiv y \pmod m. In particular, if ax≡ay(modm)ax \equiv ay \pmod m and a⊥ma \perp m, then x≡y(modm)x \equiv y \pmod m.

Node: Law 1.2.4B · Lean: TAOCP.S1_2_4.lawB

Explanation. A common factor can be cancelled modulo mm if its gcd with mm is 11. The condition is needed: modulo 66, 2⋅1≡2⋅42 \cdot 1 \equiv 2 \cdot 4 but 1≢41 \not\equiv 4, since gcd⁡(2,6)=2\gcd(2, 6) = 2. The proof uses the law of inverses. In Lean, Int.ModEq.cancel_left_div_gcd cancels cc from ca≡cb(modm)ca \equiv cb \pmod m for m>0m > 0 and gives the modulus m/gcd⁡(m,c)m/\gcd(m, c), which is mm when c⊥mc \perp m. For natural numbers, Nat.ModEq.cancel_left_of_coprime states the law with the coprime condition.

Example. Modulo 77: 3⋅5=15≡13 \cdot 5 = 15 \equiv 1 and 3⋅12=36≡13 \cdot 12 = 36 \equiv 1, and 3⊥73 \perp 7, so 5≡125 \equiv 12, which is true. Modulo 66, the counterexample above: 2⋅1=22 \cdot 1 = 2 and 2⋅4=8≡22 \cdot 4 = 8 \equiv 2, and the factor 22 is not relatively prime to 66, so no cancellation is possible. Exercise 22 asks for such an example.

Proof. From a≡ba \equiv b and y≡yy \equiv y, Law A gives by≡ayby \equiv ay. With ax≡byax \equiv by this gives ax≡ayax \equiv ay (a congruence is transitive). Since a⊥ma \perp m, there is an a′a' with aa′≡1(modm)aa' \equiv 1 \pmod m, by the law of inverses. Multiply both sides of ax≡ayax \equiv ay by a′a' (Law A): a′ax≡a′aya'ax \equiv a'ay, that is x≡yx \equiv y, since a′a≡1a'a \equiv 1 and Law A again. □\square

Law C (changing the modulus by a factor, TAOCP Section 1.2.4). If n≠0n \ne 0, then a≡b(modm)a \equiv b \pmod m if and only if an≡bn(modmn)an \equiv bn \pmod{mn}.

Node: Law 1.2.4C · Lean: TAOCP.S1_2_4.lawC

Explanation. A common factor can enter the modulus and both sides together. It follows at once from the distributive law z(x mod y)=(zx) mod (zy)z(x \bmod y) = (zx) \bmod (zy) of exercise 15, so Law C needs no coprime condition. In Lean, Int.ModEq.mul_left' gives the direction from a≡b(modm)a \equiv b \pmod m to na≡nb(modnm)na \equiv nb \pmod{nm}.

Example. 7≡1(mod6)7 \equiv 1 \pmod 6. Multiply by 55: 35≡5(mod30)35 \equiv 5 \pmod{30}, which holds since 30∣3030 \mid 30. In the other direction, 20≡8(mod12)20 \equiv 8 \pmod{12} with the factor 44 gives 5≡2(mod3)5 \equiv 2 \pmod 3, which holds since 5−2=35 - 2 = 3.

Proof. For integers and m≠0m \ne 0: a≡b(modm)a \equiv b \pmod m means m∣a−bm \mid a - b, that is a−b=mka - b = mk for an integer kk. Multiply by nn: (a−b)n=(mn)k(a - b)n = (mn)k, that is, mn∣an−bnmn \mid an - bn. For the converse, divide the last equality by n≠0n \ne 0. For m=0m = 0 both statements say a=ba = b, since n≠0n \ne 0. □\square

Law D (a product of relatively prime moduli, TAOCP Section 1.2.4). If r⊥sr \perp s, then a≡b(modrs)a \equiv b \pmod{rs} if and only if a≡b(modr)a \equiv b \pmod r and a≡b(mods)a \equiv b \pmod s.

Node: Law 1.2.4D · Lean: TAOCP.S1_2_4.lawD

Explanation. A congruence modulo a composite number splits into congruences modulo its coprime factors, and the pieces can be put back together. This is the base of the Chinese remainder theorem. The condition r⊥sr \perp s is needed: modulo 44 and 66, the number 1212 is congruent to 00 on both, but not modulo 2424. Exercise 23 asks for such an example. In Lean, the law is Int.modEq_and_modEq_iff_modEq_mul, with the condition that the absolute values of the two moduli are coprime.

Example. a=100a = 100 and b=16b = 16: 100−16=84100 - 16 = 84. With r=3r = 3 and s=28s = 28 (and 3⊥283 \perp 28), rs=84rs = 84 divides 8484, so the congruence holds modulo 8484, and each of 3∣843 \mid 84 and 28∣8428 \mid 84 holds. For the missing condition, take a=12a = 12, b=0b = 0, r=4r = 4 and s=6s = 6: 4∣124 \mid 12 and 6∣126 \mid 12, but 24∤1224 \nmid 12.

Proof. If rs∣a−brs \mid a - b, then r∣a−br \mid a - b and s∣a−bs \mid a - b, since rr and ss divide rsrs. Conversely, let a−b=rka - b = rk, since r∣a−br \mid a - b. Since s∣rks \mid rk, rk≡0≡r⋅0(mods)rk \equiv 0 \equiv r \cdot 0 \pmod s. By Law B with r⊥sr \perp s, k≡0(mods)k \equiv 0 \pmod s, so k=slk = sl for an integer ll. Then a−b=rsla - b = rsl. □\square

Theorem F (Fermat's theorem, TAOCP Section 1.2.4). If pp is a prime number, then ap≡a(modp)a^p \equiv a \pmod p for all integers aa.

Node: Theorem 1.2.4F · Lean: TAOCP.S1_2_4.theoremF

Explanation. The statement is true for each aa, even if pp divides aa. A common form is ap−1≡1(modp)a^{p-1} \equiv 1 \pmod p for a⊥pa \perp p, which follows by Law B, and exercise 25 gives the form ap−1 mod p=[a is not a multiple of p]a^{p-1} \bmod p = [a \text{ is not a multiple of } p]. The converse is false: a number nn with an≡a(modn)a^n \equiv a \pmod n for each aa need not be a prime. The smallest example is 561=3⋅11⋅17561 = 3 \cdot 11 \cdot 17. In Lean, the lemmas are ZMod.pow_card and Int.ModEq.pow_card_sub_one_eq_one.

Example. p=7p = 7 and a=3a = 3: 37=2187=312⋅7+33^7 = 2187 = 312 \cdot 7 + 3, so 37≡33^7 \equiv 3. a=10a = 10: 107 mod 7=310^7 \bmod 7 = 3 and 10 mod 7=310 \bmod 7 = 3. a=14a = 14: both sides are 00. For ap−1a^{p-1} with p=7p = 7 and a=1,…,6a = 1, \ldots, 6, a computer run gives a6 mod 7=1a^6 \bmod 7 = 1 for each of the six values, and 00 for a=0a = 0. For n=561n = 561, the run a561 mod 561=a mod 561a^{561} \bmod 561 = a \bmod 561 for each aa from 00 to 560560 holds, although 561561 is not prime. The proof of the theorem is by the three equations that follow.

Equation (the multiples of aa, TAOCP eq. 1.2.4(6)). Let pp be a prime and let aa be an integer with a⊥pa \perp p. The pp numbers below are all different, so they are the numbers 0,1,…,p−10, 1, \ldots, p - 1 in some order: 0 mod p, a mod p, 2a mod p, …, (p−1)a mod p.0 \bmod p,\ a \bmod p,\ 2a \bmod p,\ \ldots,\ (p-1)a \bmod p.

Node: TAKTP5X6RW · Lean: TAOCP.S1_2_4.eq6 (partial) · status: proved

Explanation. The remainders are pp numbers of the set {0,…,p−1}\{0, \ldots, p-1\}, and this set has pp elements. If they are all different, they use up the whole set. The first remainder is 00, so the others are 1,…,p−11, \ldots, p - 1. The map k↦ka mod pk \mapsto ka \bmod p is a permutation of the set of the remainders. It is the multiplication by aa in the integers modulo pp.

Example. For p=7p = 7 and a=3a = 3, the numbers are 0,3,6,2,5,1,40, 3, 6, 2, 5, 1, 4. Each of 0,…,60, \ldots, 6 appears once. For a=5a = 5 the numbers are 0,5,3,1,6,4,20, 5, 3, 1, 6, 4, 2.

Proof. Suppose ax mod p=ay mod pax \bmod p = ay \bmod p for 0≤x,y≤p−10 \le x, y \le p - 1. By eq. 1.2.4(5), ax≡ay(modp)ax \equiv ay \pmod p. Since a⊥pa \perp p, Law B gives x≡y(modp)x \equiv y \pmod p. Since xx and yy both lie in [0,p)[0, p) and differ by a multiple of pp that is less than pp in size, x=yx = y. So distinct xx give distinct remainders. By eq. 1.2.4(2), each remainder is in [0,p)[0, p), and a set of pp different integers in a set of pp integers is the whole set. □\square

Equation (the product of the multiples, TAOCP eq. 1.2.4(7)). Under the same hypotheses, (a)(2a)⋯((p−1)a)≡1⋅2⋯(p−1)(modp)(a)(2a)\cdots((p-1)a) \equiv 1 \cdot 2 \cdots (p-1) \pmod p.

Node: TAEYQ8RNSG · Lean: TAOCP.S1_2_4.eq7 · status: proved

Explanation. The left side is the product of the numbers kaka for k=1,…,p−1k = 1, \ldots, p-1. By eq. 1.2.4(6), the numbers ka mod pka \bmod p for these kk are 1,…,p−11, \ldots, p - 1 in another order, and the product does not depend on the order. By Law A, each factor can be replaced by its remainder. The right side is (p−1)!(p-1)! in the notation of Section 1.2.5.

Example. For p=7p = 7 and a=3a = 3: 3⋅6⋅9⋅12⋅15⋅18=5248803 \cdot 6 \cdot 9 \cdot 12 \cdot 15 \cdot 18 = 524880 and 6!=7206! = 720. The remainders are 3,6,2,5,1,43, 6, 2, 5, 1, 4 with the product 720720. And 524880 mod 7=6=720 mod 7524880 \bmod 7 = 6 = 720 \bmod 7.

Proof. The numbers kaka and ka mod pka \bmod p are congruent for each kk, by eq. 1.2.4(5). By Law A, applied p−2p - 2 times, the product of the kaka is congruent to the product of the ka mod pka \bmod p. The latter is the product of 1,…,p−11, \ldots, p - 1 in some order, by eq. 1.2.4(6) (the term for k=0k = 0 is 00 and is not in the product, and the other p−1p - 1 remainders are the numbers 1,…,p−11, \ldots, p-1). The product of integers does not depend on the order. □\square

Equation (the last step before the cancellation, TAOCP eq. 1.2.4(8)). Under the same hypotheses, ap(1⋅2⋯(p−1))≡a(1⋅2⋯(p−1))(modp)a^p(1 \cdot 2 \cdots (p-1)) \equiv a(1 \cdot 2 \cdots (p-1)) \pmod p.

Node: TA5PWP5H4B · Lean: TAOCP.S1_2_4.eq8 · status: proved

Explanation. The left side of eq. 1.2.4(7) is ap−1(1⋅2⋯(p−1))a^{p-1}(1 \cdot 2 \cdots (p-1)), since each of the p−1p - 1 factors has one factor aa. Multiply both sides of eq. 1.2.4(7) by aa (Law A) to get eq. 1.2.4(8). The prime pp divides none of 1,…,p−11, \ldots, p-1. So Law B removes these numbers from both sides one at a time, and Theorem F follows for a⊥pa \perp p. For aa a multiple of pp the theorem is trivial: ap≡0≡aa^p \equiv 0 \equiv a.

Example. For p=7p = 7, a=3a = 3: 37⋅720=15746403^7 \cdot 720 = 1574640 and 3⋅720=21603 \cdot 720 = 2160. The difference is 1572480=7⋅2246401572480 = 7 \cdot 224640, so the two sides are congruent. After the cancellation of 720720 (which is relatively prime to 77) this gives 37≡3(mod7)3^7 \equiv 3 \pmod 7.

Proof of Theorem F. If p∣ap \mid a, both apa^p and aa are congruent to 00. Otherwise, a⊥pa \perp p since pp is prime. Multiply eq. 1.2.4(7) by aa and use a⋅ap−1=apa \cdot a^{p-1} = a^p to get eq. 1.2.4(8). Let Q=1⋅2⋯(p−1)Q = 1 \cdot 2 \cdots (p-1). Then apQ≡aQ(modp)a^p Q \equiv a Q \pmod p. For 0<k<p0 < k < p, k⊥pk \perp p: a positive common divisor of kk and pp is 11 or pp, and p>kp > k. Take one factor kk of QQ and write Q=kRQ = kR. Law B, with kk in the place of both its aa and its bb, and with x=apRx = a^p R and y=aRy = aR, turns k(apR)≡k(aR)k(a^p R) \equiv k(aR) into apR≡aRa^p R \equiv aR. Repeat this for each of the p−1p - 1 factors of QQ. What remains is ap≡a(modp)a^p \equiv a \pmod p. □\square

Definition C1.1.2.4.8 (a prime and the factorization, TAOCP Section 1.2.4). A prime number is an integer p>1p > 1 whose only positive divisors are 11 and pp. Every integer n>1n > 1 is a product n=p1p2⋯pkn = p_1 p_2 \cdots p_k of primes with p1≤p2≤⋯≤pkp_1 \le p_2 \le \cdots \le p_k, and this representation is unique.

Node: TA0W7S7P57 · Lean: TAOCP.S1_2_4.prime_def, TAOCP.S1_2_4.fundamental_theorem · status: not stated yet

Explanation. The number 11 is not a prime, and that makes the uniqueness true. The factorization of a prime is the prime itself, with k=1k = 1. Existence follows from exercise 1.2.1-5 and uniqueness is exercise 21. In Lean, Nat.Prime is the definition, Nat.primeFactorsList is the sorted list, and Nat.prod_primeFactorsList and Nat.primeFactorsList_unique state the two parts of the theorem.

Example. 360=2⋅2⋅2⋅3⋅3⋅5360 = 2 \cdot 2 \cdot 2 \cdot 3 \cdot 3 \cdot 5. 1001=7⋅11⋅131001 = 7 \cdot 11 \cdot 13. 9797 is prime. The primes below 3030 are 2,3,5,7,11,13,17,19,23,292, 3, 5, 7, 11, 13, 17, 19, 23, 29, ten of them. For n=561n = 561, the factorization is 3⋅11⋅173 \cdot 11 \cdot 17.

Proof of existence. Strong induction on n≥2n \ge 2. If nn is prime, take k=1k = 1. If not, n=abn = ab with 1<a,b<n1 < a, b < n. By the hypothesis, aa and bb are products of primes, and the product of the two lists, sorted, is a product for nn.

Proof of uniqueness. First, Euclid's lemma: if a prime pp divides abab, then p∣ap \mid a or p∣bp \mid b. If p∤ap \nmid a, then a⊥pa \perp p (the only positive divisors of pp are 11 and pp), and ab≡0≡a⋅0(modp)ab \equiv 0 \equiv a \cdot 0 \pmod p, so b≡0(modp)b \equiv 0 \pmod p by Law B. By induction, a prime that divides a product of primes q1⋯qjq_1 \cdots q_j divides one of them, and so equals it. Now let p1⋯pk=q1⋯qlp_1 \cdots p_k = q_1 \cdots q_l be two factorizations of nn. The prime p1p_1 divides the right side, so p1=qip_1 = q_i for some ii. Cancel it (the cancellation of a nonzero factor in the integers) and apply the induction on n/p1n / p_1, which is smaller, to the remaining factors. When n/p1=1n / p_1 = 1 both lists are empty. The two sorted lists are the same. □\square

Algorithms and programs

Section 1.2.4 has no algorithm and no program. The extension of Euclid's algorithm that finds the inverse of the law of inverses is Algorithm 1.2.1E, and C1 gave it in Section 1.2.1.

The exercises

The table has the exercises of Section 1.2.4. The kind is the class of spec 06.3 that C1 proposes, and the Lean column names the solved theorem of tamnd/taocp-lean at main, when one exists. The marker ▶ is the book's mark of a recommended exercise.

Exercise Rating Markers Kind Lean Solution
1.2.4-1 00 K3 TAOCP.S1_2_4.Ex1.solved X1, 1.2.4-1
1.2.4-2 01 ▶ K3 TAOCP.S1_2_4.Ex2.solved X1, 1.2.4-2
1.2.4-3 10 M K1 TAOCP.S1_2_4.Ex3.solved X1, 1.2.4-3
1.2.4-4 10 ▶ M K1 TAOCP.S1_2_4.Ex4.solved X1, 1.2.4-4
1.2.4-5 16 K3 TAOCP.S1_2_4.Ex5.solved X1, 1.2.4-5
1.2.4-6 20 ▶ K2 TAOCP.S1_2_4.Ex6.solved X1, 1.2.4-6
1.2.4-7 15 M K1 TAOCP.S1_2_4.Ex7.solved X1, 1.2.4-7
1.2.4-8 00 K3 TAOCP.S1_2_4.Ex8.solved X1, 1.2.4-8
1.2.4-9 05 K3 TAOCP.S1_2_4.Ex9.solved X1, 1.2.4-9
1.2.4-10 10 ▶ K3 TAOCP.S1_2_4.Ex10.solved X1, 1.2.4-10
1.2.4-11 00 K3 TAOCP.S1_2_4.Ex11.solved X1, 1.2.4-11
1.2.4-12 00 K3 TAOCP.S1_2_4.Ex12.solved X1, 1.2.4-12
1.2.4-13 00 M K3 TAOCP.S1_2_4.Ex13.solved X1, 1.2.4-13
1.2.4-14 12 ▶ K3 TAOCP.S1_2_4.Ex14.solved X1, 1.2.4-14
1.2.4-15 10 K1 TAOCP.S1_2_4.Ex15.solved X1, 1.2.4-15
1.2.4-16 10 M K1 TAOCP.S1_2_4.Ex16.solved X1, 1.2.4-16
1.2.4-17 15 M K1 TAOCP.S1_2_4.Ex17.solved X1, 1.2.4-17
1.2.4-18 15 M K1 TAOCP.S1_2_4.Ex18.solved X1, 1.2.4-18
1.2.4-19 10 ▶ M K1 TAOCP.S1_2_4.Ex19.solved X1, 1.2.4-19
1.2.4-20 15 M K1 TAOCP.S1_2_4.Ex20.solved X1, 1.2.4-20
1.2.4-21 22 M K1 TAOCP.S1_2_4.Ex21.solved X1, 1.2.4-21
1.2.4-22 10 ▶ M K1 TAOCP.S1_2_4.Ex22.solved X1, 1.2.4-22
1.2.4-23 10 M K1 TAOCP.S1_2_4.Ex23.solved X1, 1.2.4-23
1.2.4-24 20 ▶ M informal not yet stated X1, 1.2.4-24
1.2.4-25 02 M K1 TAOCP.S1_2_4.Ex25.solved X1, 1.2.4-25
1.2.4-26 15 M K1 TAOCP.S1_2_4.Ex26.solved X1, 1.2.4-26
1.2.4-27 15 M K1 TAOCP.S1_2_4.Ex27.solved X1, 1.2.4-27
1.2.4-28 25 ▶ M K1 TAOCP.S1_2_4.Ex28.solved X1, 1.2.4-28
1.2.4-29 22 M K1 TAOCP.S1_2_4.Ex29.solved X1, 1.2.4-29
1.2.4-30 30 M informal TAOCP.S1_2_4.Ex30.solved X1, 1.2.4-30
1.2.4-31 22 M K1 TAOCP.S1_2_4.Ex31.solved X1, 1.2.4-31
1.2.4-32 18 M K1 TAOCP.S1_2_4.Ex32.solved X1, 1.2.4-32
1.2.4-33 18 M K3 TAOCP.S1_2_4.Ex33.solved X1, 1.2.4-33
1.2.4-34 21 ▶ M K3 TAOCP.S1_2_4.Ex34.solved X1, 1.2.4-34
1.2.4-35 20 ▶ M informal not yet stated X1, 1.2.4-35
1.2.4-36 23 M informal not yet stated X1, 1.2.4-36
1.2.4-37 30 ▶ M informal not yet stated X1, 1.2.4-37
1.2.4-38 26 M informal not yet stated X1, 1.2.4-38
1.2.4-39 35 HM informal not yet stated X1, 1.2.4-39
1.2.4-40 46 HM informal not yet stated X1, 1.2.4-40
1.2.4-41 23 M informal not yet stated X1, 1.2.4-41
1.2.4-42 24 M informal not yet stated X1, 1.2.4-42
1.2.4-43 23 M informal not yet stated X1, 1.2.4-43
1.2.4-44 24 M informal not yet stated X1, 1.2.4-44
1.2.4-45 28 ▶ M informal not yet stated X1, 1.2.4-45
1.2.4-46 29 M informal not yet stated X1, 1.2.4-46

The order to do them. Start with exercises 1 to 13. They fix the meaning of the floor, the ceiling and the remainder for negative and non-integer arguments. The six equivalences of exercise 3 are the tools for all other proofs about the floor. Then do exercises 14 to 23, which prove the laws, the law of inverses and the unique factorization, and give the counterexamples for Laws B and D. Exercises 24 to 28 use the laws: real arguments, Fermat's theorem, Euler's theorem and the function φ\varphi. Exercises 29 to 32 are about multiplicative functions. The rest, exercises 33 to 46, are about sums with the floor: they use exercise 3 and the manipulation of sums of Section 1.2.3. Exercise 38 (E. Busche, 1909) and the reciprocity law of exercises 45 and 46 are the hardest of these, and exercise 40 is an open research problem.

Lean

The Lean code of tamnd/taocp-lean at main has the file TAOCP/V1/S1_2_4.lean, in the namespace TAOCP.S1_2_4. It states eqs. (1) to (8), Laws A to D, Theorem F and the facts about the prime numbers. The Node lines name the declarations. Where the Lean statement is weaker, the Node line says "partial".

Not yet stated: the definition of the floor and the ceiling as such, and the definition of the greatest common divisor and of relatively prime integers. The file has facts about the floor and the ceiling that are not numbered items: TAOCP.S1_2_4.floor_neg, TAOCP.S1_2_4.floor_ceil_chain, TAOCP.S1_2_4.ceil_eq_floor_iff and TAOCP.S1_2_4.ceil_eq_floor_add_one_iff. It also has the values of the floor and the ceiling of 2\sqrt2, 1/21/2 and −1/2-1/2.

The points where Lean differs from the book are these.

  • The floor and the ceiling are Int.floor and Int.ceil, and the remainder of the book is TAOCP.kmod, with TAOCP.kmod x y = x - y * ⌊x / y⌋. It follows the sign of the divisor, as the book says, and TAOCP.kmod x 0 = x. It is not Int.emod, which is never negative, and it is not Int.tmod, which truncates toward zero. For a positive modulus, Int.emod and TAOCP.kmod agree.
  • The congruence is TAOCP.S1_2_4.Congr x y z, for real numbers, defined by TAOCP.kmod. TAOCP.S1_2_4.eq5 shows that it means x−y=kzx - y = kz for an integer kk. TAOCP.S1_2_4.congr_intCast shows that for integers it is Int.ModEq. Laws A to D are stated for integers with Int.ModEq,, with the notation a ≡ b [ZMOD m].
  • Law B has the hypothesis Int.gcd a m = 1 for the relatively prime pair a⊥ma \perp m.
  • Eq. (6) in Lean says that the pp numbers ka mod pka \bmod p for 0≤k<p0 \le k < p are distinct (Set.InjOn). It does not state that they are the numbers 0,…,p−10, \ldots, p - 1 in some order. The remainder here is Int.emod.
  • TAOCP.S1_2_4.fundamental_theorem states that each n>1n > 1 has exactly one list of primes in nondecreasing order with the product nn, and TAOCP.S1_2_4.prime_def is the definition of a prime of the book. The exercise 1.2.4-19, the law of inverses, is TAOCP.S1_2_4.law_of_inverses.

The Mathlib names that the statements use are these. For real numbers, toIcoMod and toIocMod give the remainder on a half-open interval, and they need a positive period. Euler's theorem (exercise 28) is Nat.ModEq.pow_totient, and the function φ\varphi is Nat.totient. The factorization is Nat.primeFactorsList, with Nat.prod_primeFactorsList and Nat.primeFactorsList_unique.

Each exercise of the table with a name in the Lean column has a statement in TAOCP/Problems/S1_2_4/ and a solution in TAOCP/Solutions/S1_2_4/. The name in the table is the theorem solved of the solution file.

Notes and history

K. E. Iverson introduced the signs ⌊x⌋\lfloor x \rfloor and ⌈x⌉\lceil x \rceil in his book A Programming Language (1962). Older texts write [x][x], mostly for the floor, and some call the floor the entier function. The remainder x mod yx \bmod y for real numbers is a definition of the book: the congruence notation for integers is from C. F. Gauss, who used it in his book on number theory of 1801. The clause x mod 0=xx \bmod 0 = x is a convention that keeps x−(x mod y)x - (x \bmod y) a multiple of yy for each pair, also for y=0y = 0.

Fermat stated his theorem in a letter of 1640. L. Euler gave the first published proof, which he presented in 1736 and which was printed in 1741. Euler later proved the generalization aφ(m)≡1(modm)a^{\varphi(m)} \equiv 1 \pmod m that is exercise 28. A number that is not prime and that satisfies an≡a(modn)a^n \equiv a \pmod n for each aa is called a Carmichael number, after R. D. Carmichael, who studied them in 1910. V. Šimerka had already listed the smallest ones in 1885, and the smallest is 561561. The theorem on the unique factorization into primes is found in Euclid's Elements in a weak form, and a full proof is in the Disquisitiones of Gauss.

The exercises on the sums with the floor lead to the reciprocity laws of Section 3.3.3 and to the Dedekind sums. The Bernoulli polynomials satisfy the multiplication formula of exercise 40 with bn=0b_n = 0, and the digamma function ψ\psi satisfies it with bn≠0b_n \ne 0.

The project has no errata of Section 1.2.4 to report.

Section 1.2.4 of TAOCP gives the floor and ceiling functions, the remainder x mod y for real numbers, and the notation for congruence. It states four laws for congruences, with a note on when a common factor can be cancelled, and it proves Fermat's theorem from them. This chapter of C1 explains each item of the section, proves the laws that the book leaves to the exercises, adds the proof that every integer above 1 is a product of primes in one way only, and checks each example by computation.

The source of this page. Something is wrong? Report it.