Appendix a Elementary Number Theory A.1 Introduction Let Denote the Set of Natural Numbers, the Set of Integers, and the Set of Real Numbers
Total Page:16
File Type:pdf, Size:1020Kb
Appendix A Elementary Number Theory A.1 Introduction Let denote the set of natural numbers, the set of integers, and the set of real numbers. An integer d divides an integer n, if for some We shall denote this by If such an integer k does not exist, d does not divide n. This will be denoted by To check if the integer d divides the integer n, the Mathematica function IntegerO can be used in the following way. The Mathematica function Divisor gives a list of all divisors of a number n. For instance: An integer is said to be prime, if 1 and p are its only positive divisors. With we introduce a natural numbering of the set of prime numbers. Valuable Mathematica functions in this context are Prime and PrimeO: generating the 35-th prime number. telling if the input (here 1234567) is prime. 344 APPENDICES Proof: Suppose the contrary. Let be the set of all primes. Next, we observe that the integer is not divisible by any of the primes Let n be the smallest integer n that is not divisible by any of the primes It can not be a prime number, because it is not in the list It follows that n has a non-trivial factor d. But then this factor d is divisible by at least of the primes and so does n. A contradiction. Between two consecutive primes there can be an arbitrary large gap of non-prime numbers. For example, the elements in the sequence are divisible by respectively Therefore none of them is prime. In Mathematica, this function is denoted by PrimePi [n]. The next theorem [see [HarW45], p.91] , which we shall not prove, tells us something about the relative frequency of the prime numbers in Two important definitions are those of the greatest common divisor and least common multiple of two integers. Elementary Number Theory 345 To show the existence of gcd, we introduce the set Let m denote the smallest element in U. We shall show that m satisfies (A.1) and (A.2). Clearly, if f divides both a and b then f also divides m. So, m does satisfy (A.2). Now, write (subtract or add m sufficiently often from (resp. to) a until the remainder r lies in between 0 and ). If then (since both a and m are in U). This contradicts the assumption on the minimality of m. So, which means that m divides a. Similarly, m divides b. So, m satisfies (A.1) too. The uniqueness of gcd(a, b) follows from (A.1) and (A.2). Indeed, if d and both satisfy (A1) and (A.2), it follows that and Since both d and are positive, it follows that In a similar way, the existence and uniqueness of lcm[a, b]can be proved. Alternative definitions of gcd(a, b) and 1cm[a, b] are: 346 APPENDICES The functions GCD and LCM can be evaluated by Mathematica as follows: If two integers have a gcd equal to 1, we say that they are coprime. A consequence of the above is the following important theorem. The following lemma seems too obvious to need a proof. Proof: Since Theorem A.3 implies that for some integers x and y. So, Since d divides a b, it follows that d also divides which equals b. Proof: Use Lemma A.4 and induction on k. With an induction argument the following theorem can now easily be proved. Elementary Number Theory 347 Let in and in Then one easily checks that The Mathematlca expression FactorInteger[n] gives the factorization of an integer n. The outcome is a list of pairs. Each pair contains a prime divisor of n and its exponent. 348 APPENDICES A.2 Euclid's Algorithm Let a and b be two positive integers with Clearly, any divisor of a and b is a divisor of a and and vice versa. So, Writing one has for the same reason that If (and we may conclude that otherwise we continue in the same way with a and r. So, we write have etc., until one of the arguments indeed divides the other. This algorithm is an extremely fast way of computing the gcd of two integers and it is known as Euclid's Algorithm. With the Mathematica functions While, ,Floor , and Print, the above algorithm runs like this If one also wants to find the coefficients u and v satisfying Theorem A.3, this algorithm can be adapted as described below. Note that by leaving out the lines involving the integers ui and vi, this (extended) algorithm reduces to the simple version above. Elementary Number Theory 349 Again Mathematica knows this extended version of Euclid's Algorithm as a standard function. It is called ExtendedGCD. Note that in the example above one indeed has that Proof of Algorithm A.8: First observe that the elements form a strictly decreasing sequence of non-negative integers. So the algorithm will terminate after at most b iterations. Later in this paragraph we shall analyze how fast Euclid's Algorithm really is. From the recurrence relation the algorithm it follows that This proves the first equality in (A.8). We shall now prove that for all k, Note that substitution of in this relation proves the second equality in (A.8). For and the above relation holds by our choice of the initialization values for and We now proceed by induction. It follows from the recurrence relations in the algorithm and from the induction hypothesis, that 350 APPENDICES Of course there is no need to keep all the previously calculated values of and stored in the program. Only the last two of each together with will suffice. The reason for introducing them in the algorithm was only to facilitate the readability of the proof above. With the Mathematica functions While, Floor, and Print , the above algorithm runs like this: We would like to conclude this section by saying something about the complexity of Euclid's Algorithm. It may be clear that this algorithm is at it slowest if at each step the quotient qk has value 1 (if possible). This is the case if for all and that In other words, the smallest value of b (and arbitrary such that the evaluation of gcd(a, b) takes steps is given by and where the sequence is the famous sequence of Fibonacci numbers defined by By letting Mathematica operate repeatedly on a list of two consecutive Fibonnacci numbers (the function Nest is used for this), one gets the following method to evaluate these numbers (in the example and are computed): Elementary Number Theory 351 This could also have been done directly with the function Fibonacci. The reader may check the above analysis in the following way. Note that the GCDiterations algorithm above does not affect the values of a and b (contrary to our implementation of the simple version of Euclid's algorithm). It also makes use of the Mathematica function Mod that will be discussed in the next section. 352 APPENDICES Plugging in in the defining recurrence relation of the Fibonacci numbers, so in leads to the quadratic equation which has as zero's: Without proof we state the following upperbound on the complexity of Euclid's Algorithm. The reader may prove it with induction on b (distinguish the cases and A.3 Congruences, Fermat, Euler, Chinese Remainder Theorem A.3.1 Congruences The Mathematica function gives the unique integer such that An easy test if the integers a and b are congruent of each other modulo m is given by the following example: Elementary Number Theory 353 The most commonly used complete residue systems modulo m are the sets {0, 1, ..., m – 1} and {1, 2, ..., m – 1}. With the Mathematica functions one can generate these systems. Clearly the m integers form a complete residue system modulo m if and only if for each pair one has that The congruence relation modulo defines an equivalence relation (see Definition B.5 ) on A complete residue system is just a set of representatives of the m equivalence classes. Proof: Write and with It follows from for some that Since it follows from Lemma A.4 that i.e. Proof: We use criterion (A.9). By Lemma A. 10, implies that This in turn implies that 354 APPENDICES A.3.2 Euler and Fermat Often we shall only be interested in representatives of those residue classes modulo m, whose elements have coprime with m. The number of these classes is denoted by the following function. In Mathematica, this function can be evaluated with the EulerPhi [n]function. For instance corresponding to the eight elements: 1, 2, ,4, 7, 8, 11, 13, and 14. Later on in this section, we see how the function can be efficiently computed. It is quite easy to see in an example which of the m integers in between 1 and m are contributing to which term with When we have the divisors 1, 3, 5 and 15 of m. The eight elements 1, 2, ,4, 7, 8, 11, 13, 14 all have gcd 1 with 15 (note that the four elements 3, 6, 9, 12 have with 15, the two elements 5, 10 have and the single element 0 has Proof of Theorem A.12: Let d divide m. By writing one sees immediately that the number of elements r, with is equal to the number of integers i with and therefore, this number is On the other hand, gcd(r, m) divides n for each integer r, It follows that This statement is equivalent to what needs to be proved.