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.
Integer functions and elementary number theory
Overview
Section 1.2.4 of TAOCP has two parts. The first part defines the floor and the ceiling of a real number, and then the remainder for real and . The second part defines congruence, states four laws for it (Laws A to D), and proves Fermat's theorem: modulo a prime . 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 . 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 and a real , the statements and are equivalent, and so are and . 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 that is left when the multiples of are taken away. The definition works for each real and . The result is zero or has the sign of , so lies in for and in for . Many programming languages use another rule for a negative , and a reader must not mix the two.
Congruence is equality of remainders. The statement says that and leave the same remainder on division by , and for integers it says that divides . 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 leave different remainders when is a prime that does not divide . So the remainders are the numbers 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 , the floor is the greatest integer that is less than or equal to , and the ceiling is the least integer that is greater than or equal to .
Node: TAH7HVKG6J · status: not stated yet
Explanation. The definition is meaningful for each real , since the integers that are at most are bounded above and not empty, and so they have a greatest one. The same holds for the integers that are at least . The important point is the sign: , not . 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 and a real :
- if and only if , and if and only if ;
- if and only if , and if and only if ;
- if and only if , and if and only if .
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. and . and and . For an integer, . , , , , and because .
Proof of the equivalences. By the definition, , and is the greatest integer with this property. If , then . If , then is an integer that is at most , and so , since is the greatest. The second claim is the negation of the first. The statement about the ceiling is the mirror image. For if and only if : take the negation of the first equivalence with the integer : if and only if , and for integers is the same as .
Consequences. Four facts follow at once from these equivalences.
First, . The middle inequality is the definition of both. For : the integer is above , so it is not at most , and . The bound for the ceiling is the same.
Second, if and only if is an integer, and otherwise . If is an integer, then is the greatest integer at most and the least integer at least . If is not an integer, then , so is an integer that is at least and no integer lies between and .
Third, . For each integer : if and only if , if and only if , if and only if , if and only if . Two integers that are at most the same integers are equal.
Fourth, for integers and with and for real , (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 and ,
Node: TAJTHY87JS · Lean: TAOCP.kmod, TAOCP.S1_2_4.eq1_ne, TAOCP.S1_2_4.eq1_zero · status: not stated yet
Explanation. The number is the quotient, and is the remainder. The case is defined separately, so that exists for every pair, and so that is a multiple of in all cases (the multiple when ). For a negative the remainder is zero or negative. This differs from the remainder of the % operator of C, which has the sign of . 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 , the book's is toIcoMod hy 0 x, the reduction of into the interval , where hy is a proof of .
Example. , , and . For real numbers, and . With a negative modulus, and . A real example: . The note on the sine and the tangent: for each where the tangent is defined, because the tangent has the period .
Theorem C1.1.2.4.3 (the bounds of the remainder, TAOCP eq. 1.2.4(2)). For ,
- If , then .
- If , then .
- For each , the quantity is an integral multiple of .
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 with , and the last is . The middle equality is the definition of the remainder divided by . Multiplication by gives the bounds of the remainder, and for a negative the inequalities turn around. The remainder with a given sign of is unique: exercise 16 shows that if , and is an integer, then .
Example. For and : , the floor is , and . For and : , the floor is , the remainder is , and equals . The remainder lies in .
Proof. By the consequences of the floor, for each real , so . Put . Then , which gives the displayed claim. If , multiply the chain by to get . If , the multiplication by turns the signs around and gives . The last claim: , which is times an integer. For the multiple is and the claim holds.
Example C1.1.2.4.4 (three values of the remainder, TAOCP eq. 1.2.4(3)). , and .
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 , and the quotient is , not . A language that has the quotient here gives the remainder , and that is not the definition of the book. For integers, if and only if divides . The book writes for " is a positive integer and ".
Example. Check by the definition. For : and . For : and . For : and . Also, , and , and .
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 , the quantity is the fractional part of , it lies in , and .
Node: TASAKWKRBA · Lean: TAOCP.S1_2_4.eq4 · status: proved
Explanation. The identity is the definition (1) with : . The fractional part of a negative number is not the digits after the point of its decimal form: for the floor is and the fractional part is . In Lean, the fractional part is Int.fract x, and the lemma is Int.floor_add_fract.
Example. . . . The rounding of exercise 5 is for a positive : for it gives and for it gives . For a negative the same formula rounds a half toward plus infinity, so .
Proof. Put in eq. 1.2.4(1): . So . The bounds are eq. 1.2.4(2) with .
Definition C1.1.2.4.6 (the greatest common divisor and relatively prime integers, TAOCP Section 1.2.4). The greatest common divisor of two integers that are not both zero is the greatest integer that divides both. The convention also gives . Two integers and are relatively prime, written , if .
Node: TACCSNBG9G · status: not stated yet
Explanation. The number is if and only if the only common divisors are and . Each integer is relatively prime to , since is the only positive divisor of . By the convention , the only integers relatively prime to are and . The fraction is in lowest terms if . 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 has an integer solution. The next fact proves that implies this. The converse holds because a common divisor of and divides .
Example. . because the divisors of are and none of divides . , so is false and is true.
Fact (Bezout, the law of inverses of exercise 19). If , there are integers and with . So there is an integer with .
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 and . The set of positive integers of the form is not empty, since is in it when are not both zero. Let be the least element of the set, . Divide by : with . Then has the same form, and , so cannot be positive. So and . In the same way . So is a common divisor, and , so . For the second claim, take : .
Example. For and : , so and , and . Check: . The numbers and 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 , and , the statement means .
Node: TA5WVCFA8D · Lean: TAOCP.S1_2_4.Congr, TAOCP.S1_2_4.eq5 · status: proved
Explanation. For integers and and an integer , the statement is the same as: divides . For , the convention makes it mean , 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 divides .
Example. , because . , since both leave . . For the modulus , and . An example of exercise 14: if and , then , since is the only number in with both remainders (the check is by the table of the fifteen numbers).
Proof that the two descriptions agree. Let and be integers and . If , then , a multiple of . If , then is a multiple of , and it lies in by eq. 1.2.4(2). The only multiple of in that range is . For the same argument holds with .
Law A (sums, differences and products, TAOCP Section 1.2.4). If and , then and .
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 . The new result is congruent to the old one. A power follows by induction on the exponent: implies . In Lean, the lemmas are Int.ModEq.add, Int.ModEq.sub and Int.ModEq.mul, and Int.ModEq.pow.
Example. and . Then and , so the sums agree. And and , so the products agree. Also and .
Proof. Take integers and (the case is equality, and the laws of equality give the claim). Write and for integers and . Then , and . So divides each difference.
Law B (cancelling a factor, TAOCP Section 1.2.4). If and and , then . In particular, if and , then .
Node: Law 1.2.4B · Lean: TAOCP.S1_2_4.lawB
Explanation. A common factor can be cancelled modulo if its gcd with is . The condition is needed: modulo , but , since . The proof uses the law of inverses. In Lean, Int.ModEq.cancel_left_div_gcd cancels from for and gives the modulus , which is when . For natural numbers, Nat.ModEq.cancel_left_of_coprime states the law with the coprime condition.
Example. Modulo : and , and , so , which is true. Modulo , the counterexample above: and , and the factor is not relatively prime to , so no cancellation is possible. Exercise 22 asks for such an example.
Proof. From and , Law A gives . With this gives (a congruence is transitive). Since , there is an with , by the law of inverses. Multiply both sides of by (Law A): , that is , since and Law A again.
Law C (changing the modulus by a factor, TAOCP Section 1.2.4). If , then if and only if .
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 of exercise 15, so Law C needs no coprime condition. In Lean, Int.ModEq.mul_left' gives the direction from to .
Example. . Multiply by : , which holds since . In the other direction, with the factor gives , which holds since .
Proof. For integers and : means , that is for an integer . Multiply by : , that is, . For the converse, divide the last equality by . For both statements say , since .
Law D (a product of relatively prime moduli, TAOCP Section 1.2.4). If , then if and only if and .
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 is needed: modulo and , the number is congruent to on both, but not modulo . 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. and : . With and (and ), divides , so the congruence holds modulo , and each of and holds. For the missing condition, take , , and : and , but .
Proof. If , then and , since and divide . Conversely, let , since . Since , . By Law B with , , so for an integer . Then .
Theorem F (Fermat's theorem, TAOCP Section 1.2.4). If is a prime number, then for all integers .
Node: Theorem 1.2.4F · Lean: TAOCP.S1_2_4.theoremF
Explanation. The statement is true for each , even if divides . A common form is for , which follows by Law B, and exercise 25 gives the form . The converse is false: a number with for each need not be a prime. The smallest example is . In Lean, the lemmas are ZMod.pow_card and Int.ModEq.pow_card_sub_one_eq_one.
Example. and : , so . : and . : both sides are . For with and , a computer run gives for each of the six values, and for . For , the run for each from to holds, although is not prime. The proof of the theorem is by the three equations that follow.
Equation (the multiples of , TAOCP eq. 1.2.4(6)). Let be a prime and let be an integer with . The numbers below are all different, so they are the numbers in some order:
Node: TAKTP5X6RW · Lean: TAOCP.S1_2_4.eq6 (partial) · status: proved
Explanation. The remainders are numbers of the set , and this set has elements. If they are all different, they use up the whole set. The first remainder is , so the others are . The map is a permutation of the set of the remainders. It is the multiplication by in the integers modulo .
Example. For and , the numbers are . Each of appears once. For the numbers are .
Proof. Suppose for . By eq. 1.2.4(5), . Since , Law B gives . Since and both lie in and differ by a multiple of that is less than in size, . So distinct give distinct remainders. By eq. 1.2.4(2), each remainder is in , and a set of different integers in a set of integers is the whole set.
Equation (the product of the multiples, TAOCP eq. 1.2.4(7)). Under the same hypotheses, .
Node: TAEYQ8RNSG · Lean: TAOCP.S1_2_4.eq7 · status: proved
Explanation. The left side is the product of the numbers for . By eq. 1.2.4(6), the numbers for these are 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 in the notation of Section 1.2.5.
Example. For and : and . The remainders are with the product . And .
Proof. The numbers and are congruent for each , by eq. 1.2.4(5). By Law A, applied times, the product of the is congruent to the product of the . The latter is the product of in some order, by eq. 1.2.4(6) (the term for is and is not in the product, and the other remainders are the numbers ). The product of integers does not depend on the order.
Equation (the last step before the cancellation, TAOCP eq. 1.2.4(8)). Under the same hypotheses, .
Node: TA5PWP5H4B · Lean: TAOCP.S1_2_4.eq8 · status: proved
Explanation. The left side of eq. 1.2.4(7) is , since each of the factors has one factor . Multiply both sides of eq. 1.2.4(7) by (Law A) to get eq. 1.2.4(8). The prime divides none of . So Law B removes these numbers from both sides one at a time, and Theorem F follows for . For a multiple of the theorem is trivial: .
Example. For , : and . The difference is , so the two sides are congruent. After the cancellation of (which is relatively prime to ) this gives .
Proof of Theorem F. If , both and are congruent to . Otherwise, since is prime. Multiply eq. 1.2.4(7) by and use to get eq. 1.2.4(8). Let . Then . For , : a positive common divisor of and is or , and . Take one factor of and write . Law B, with in the place of both its and its , and with and , turns into . Repeat this for each of the factors of . What remains is .
Definition C1.1.2.4.8 (a prime and the factorization, TAOCP Section 1.2.4). A prime number is an integer whose only positive divisors are and . Every integer is a product of primes with , 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 is not a prime, and that makes the uniqueness true. The factorization of a prime is the prime itself, with . 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. . . is prime. The primes below are , ten of them. For , the factorization is .
Proof of existence. Strong induction on . If is prime, take . If not, with . By the hypothesis, and are products of primes, and the product of the two lists, sorted, is a product for .
Proof of uniqueness. First, Euclid's lemma: if a prime divides , then or . If , then (the only positive divisors of are and ), and , so by Law B. By induction, a prime that divides a product of primes divides one of them, and so equals it. Now let be two factorizations of . The prime divides the right side, so for some . Cancel it (the cancellation of a nonzero factor in the integers) and apply the induction on , which is smaller, to the remaining factors. When both lists are empty. The two sorted lists are the same.
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 . 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 , and .
The points where Lean differs from the book are these.
- The floor and the ceiling are
Int.floorandInt.ceil, and the remainder of the book isTAOCP.kmod, withTAOCP.kmod x y = x - y * ⌊x / y⌋. It follows the sign of the divisor, as the book says, andTAOCP.kmod x 0 = x. It is notInt.emod, which is never negative, and it is notInt.tmod, which truncates toward zero. For a positive modulus,Int.emodandTAOCP.kmodagree. - The congruence is
TAOCP.S1_2_4.Congr x y z, for real numbers, defined byTAOCP.kmod.TAOCP.S1_2_4.eq5shows that it means for an integer .TAOCP.S1_2_4.congr_intCastshows that for integers it isInt.ModEq. Laws A to D are stated for integers withInt.ModEq,, with the notationa ≡ b [ZMOD m]. - Law B has the hypothesis
Int.gcd a m = 1for the relatively prime pair . - Eq. (6) in Lean says that the numbers for are distinct (
Set.InjOn). It does not state that they are the numbers in some order. The remainder here isInt.emod. TAOCP.S1_2_4.fundamental_theoremstates that each has exactly one list of primes in nondecreasing order with the product , andTAOCP.S1_2_4.prime_defis the definition of a prime of the book. The exercise 1.2.4-19, the law of inverses, isTAOCP.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 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 and in his book A Programming Language (1962). Older texts write , mostly for the floor, and some call the floor the entier function. The remainder 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 is a convention that keeps a multiple of for each pair, also for .
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 that is exercise 28. A number that is not prime and that satisfies for each 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 . 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 , and the digamma function satisfies it with .
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.