Basic Arithmetic. Chapter Integer Arithmetic

Size: px
Start display at page:

Download "Basic Arithmetic. Chapter Integer Arithmetic"

Transcription

1 Chapter 1 Basic Arithmetic All rings in this lecture are unitary and commutative. In this chapter, we will analyze basic arithmetic operations with the point of view of implementing them on a computer. All computers provide basic integer arithmetic, but in general only in a very specific way. More precisely, computes usually allow to do arithmetic in Z/2 k Z for a fixed k, the machine word-width, where k {8, 16, 32, 64, 128}. (Most modern computers have k = 64.) Since 2 64 = is quite large, this is often no restriction. But sometimes, especially when doing computations in mathematics, numbers tend to grow larger than that. If one still wants to know the precise result, one has to invest some work to simulate larger integers with what the CPU supports. The basic approach to do this is covered in Section 1.1. Afterwards, we will introduce some notation from complexity theory to simplify discussing the running time needed for arithmetic. We will count the running time in different units, most prominently basic b-operations, which correspond to what the CPU can do natively with one operation, and to ring or field operations, which obviously depend on the underlying ring respectively field. The next topics we will cover are univariate polynomials and the Euclidean Algorithm, one of the most important algorithms in arithmetic. The later sections in this chapter are merely applications of the content of the first four sections, which will enable us to do arithmetic in the rational numbers Q, in residue class rings Z/nZ of the integers, in residue class rings of K[X], and in finite fields. 1.1 Integer Arithmetic A very fundamental problem in computer algebra is integer arithmetic. The basic questions are: How to represent integers on a computer? How to do basic arithmetic addition, subtraction, multiplication, division with remainder in this representation? How fast can we do arithmetic? The most used representation is a positional notation; 1 the decimal notation we learned in school is also one. 1 The first counting system with positional notation was used by the Babylonians with base 60. 1

2 2 CHAPTER 1. BASIC ARITHMETIC Definition Let N N be a natural number and b 2 be another natural number. An (n + 1)-tuple (a n,..., a 0 ) {0,..., b 1} n+1 is called a b-adic representation of N if and only if n N = a i b i. i=0 In case n = 0 or a n 0, we say that this representation is reduced. We say that this representation has size n. The number system we use is the one of reduced 10-adic representations. Remarks (a) For every b 2, every natural number has a unique reduced b-adic representation. (b) One could also accept n = 1, which corresponds to the empty list (). This would introduce another representation of zero (compare Section 1.3). The reason why this is usually not done for integers is that in this way, one can work more efficiently with integers which fit into one digit because no list size changes are necessary as long as the result fits into one digit. (c) If (a n,..., a 0 ) and (c m,..., c 0 ) are b-adic representations of the same number, then a i = c i for i = 0,..., min{n, m} and a i = 0 for m < i n and c j = 0 for n < j m. (d) The maximal number b-adicly representable with (a n,..., a 0 ) is n (b 1)b i = (b 1) i=0 n i=0 b i = (b 1) bn+1 1 b 1 = b n+1 1. If N is an arbitrary number, this shows that it can be represented b-adicly by (a n,..., a 0 ) if and only if N b n+1 1 N + 1 b n+1 log b (N + 1) n + 1 log b (N + 1) 1 n. Moreover, since N is an integer and (b n+1 1) + 1 = b n+1, we also obtain N b n+1 1 log b N < n + 1. (e) Therefore, the size of the reduced b-adic representation of N > 0 is size b (N) := log b (N + 1) 1 = log b (N + 1) 1 = log b (N). Moreover, for N > 0, size b (N) C b log N D b for C b := 1 log b > 0 and D b := max{1, log 2 log b } = 1. For N = 0, size b(0) = 0 = log(n + 1) 1.

3 1.1. INTEGER ARITHMETIC 3 (f) Internally, a computer uses non-reduced 2-adic representations with a fixed n. This n is usually one less than a power of two, for example 31 = or 63 = Therefore, a computer can internally represent natural numbers {0,..., } respectively {0,..., }. Such an internal representation is called a CPU integer. We exploit this to represent larger numbers by choosing b as 2 32 respectively An arbitrary natural number is thus given as a list of CPU integers together with its length. Note that we identify the set of CPU integers with Z/2 32 Z respectively Z/2 64 Z. Also note that in fact, negative numbers can be represented as well by choosing a fitting representative system of the residue class ring Z/2 m Z, for example in case m is even. 2 2 m/2, 2 m/2 + 1,..., 1, 0, 1,..., 2 m/2 2, 2 m/2 1 (g) To represent arbitrary integers and not just natural numbers, we add a sign bit, an element in {+, } which indicates the sign of the number. Note that the number 0 has two such representations. We will now explain how to do basic arithmetic with such b-adic representations. We will assume that we already know how to do all required operations with arguments in the range {0,..., b 1}; we refer to such operations as basic b-operations. We define them in more detail in the following: Remarks Let a, c {0,..., b 1}. (a) Let γ {0, 1}. The sum a + c + γ is either in {0,..., b 1}, or a + c + γ b {0,..., b 1}. Write a + c + γ = q b + r with q, r N and r < b; thus q {0, 1}. We define a b,γ c := r and Carry add,b (a, c, γ) := q {0, 1}. The latter is called the carry bit. 3 (b) Let γ {0, 1}. In case a c γ 0, define a b,γ c := a c γ, and in case a c γ < 0, define a b,γ c := b+a c γ. We also define 4 Carry sub,b (a, c, γ) := 0 in case a c γ 0 and Carry sub,b (a, c, γ) := 1 in case a c γ < 0. 5 (c) Write a c = q b + r with q, r N and r < b. We define a b c := r and Carry mul,b (a, c) := q {0,..., b 2}. 6 (Note that a, c b 1 implies a c (b 1) 2 = b 2 2b + 1, whence q b 2.) 2 This system of representing negative numbers is called two s complement. If an element of Z/2 m Z is represented by a bitstring, one can compute the negative by flipping all bits and adding 1 to the result. 3 In x86 assembler, this is done by the ADC instruction (add with carry). If γ = 0 is known, one can use the ADD instruction. The value of Carry add,b is returned via the carry flag. 4 Instead of carry, a more meaningful name would be borrow. To minimize the number of different names, we use carry here as well. In x86 assembler, the borrow bit is stored and retrieved from the carry flag. 5 In x86 assembler, this is done by the SBB instruction (subtraction with borrow). If γ = 0 is known, one can use the SUB instruction. The value of Carry sub,b is returned via the carry flag. 6 In x86 assembler, this is done by the MUL instruction (unsigned multiplication). This command returns simultaneously q and r, and indicates via the overflow and carry flag whether q 0 or not.

4 4 CHAPTER 1. BASIC ARITHMETIC (d) Note that ({0,..., b 1}, b,0, b ) is a model of the residue class ring Z/bZ. Also note that b equals subtraction of natural numbers modulo b. 7 (e) Assume that c 0 and let a {0,..., b 2 1}. We assume that a is given in the form a 1 b + a 2, where a 1, a 2 {0,..., b 1}, and we assume that a/c < b (if this is not satisfied, the values of the following expressions will not be defined). Let q, r N with 0 r < c such that a = q c + r. We denote a div b c := q and a rem b c := r. Obtaining q and r is also called Euclidean (long) division. 8 (f) By basic b-operation, we mean the operations b,, b,, b, div b, rem b, Carry add,b, Carry sub,b and Carry mul,b, as well as comparisons of elements in {0,..., b 1}. Using these basic operations, we can explain how to do arithmetic with b-adic representations: Theorem (Basic Integer Arithmetic). Let b 2 be a natural number, and let N and M be two natural numbers with reduced b-adic representations (a n,..., a 0 ) of N and (c m,..., c 0 ) of M. (a) Testing whether N < M, N = M or N > M can be done in at most min{n, m}+ 2 comparisons of elements {0,..., b 1}. (b) Computing a reduced b-adic representation of N + M can be done in at most max{n, m} + 1 evaluations of b, and Carry add,b. (c) Computing a reduced b-adic representation of N M together with 9 sgn(n M) can be done in at most max{n, m} + 2 evaluations of b, and Carry sub,b and min{n, m} + 2 comparisons of elements {0,..., b 1}. (d) Computing a reduced b-adic representation of N M can be done in at most (m + 1)(n + 1) evaluations of b and Carry mul,b, at most (2m + 1)(n + 1) + m evaluations of b, and at most (2m + 1)n + 2m evaluations of Carry add,b. (e) Assume that M 0. Computing reduced b-adic representations of two numbers Q, R N with N = Q M + R and R < M can be done in at most max{0, 2m(n m)+4n+2m+6} evaluations of b and Carry mul,b, max{0, 5m(n m) + 12n + 3m + 21} evaluations of b,, max{0, 5m(n m) + 9n + 6m + 12} evaluations of Carry add,b, max{0, 3m(n m) + 9n 6m + 9} evaluations of b, and Carry sub,b and comparisons of elements {0,..., b 1}, n + 2 evaluations of div b and m + 1 evaluations of rem b. We will later see that except for comparison, addition and subtraction, we can improve upon these operations by making them faster, at least in case n and m are sufficiently large. Proof of Theorem The x86 assembler also features a signed multiplication instruction, IMUL. If the result modulo b = 2 l is taken, where l is the bit-width of the CPU, the output is identical to the one of MUL. The main difference is the handling of the flags and sign extension for the q part of the result. 8 In x86 assembler, this is done by the DIV instruction (unsigned division). The numerator can actually be in range {0,..., b 2 1}, and the instruction computes both q and r. In case the quotient does not fit into the range {0,..., b 1}, or if the divisor is zero, an error will occur. If the numerator is in range {0,..., b 1} and the denominator is 0, no error will occur. 9 Here, sgn(x) = 1 for x < 0, sgn(0) = 0 and sgn(x) = 1 for x > 0.

5 1.1. INTEGER ARITHMETIC 5 (a) In case n m, we right away know that N > M (in case of n > m) or N < M (in case of n < m). If n = m, we find the largest index i with a i c i. If no such index exists, N = M. Otherwise, we know that N < M in case a i < c i, and N > M in case a i > c i. Therefore, we need at most n + 1 comparisons to find the index i, and at most one more comparison to distinguish between a i < c i and a i > c i. (b) For i > n, we interpret a i = 0, and for i > m, we interpret c i = 0. To compute a reduced b-adic representation of N + M, we start with γ := 0 and iterate i from 0 up to max{n, m}. In step i, we compute d i := a i b,γ c i and γ := Carry add,b (a i, c i, γ). After the last iteration, (d max{n,m},..., d 0 ) is the reduced b-adic representation of N + M in case γ = 0, and (1, d max{n,m},..., d 0 ) is the reduced b-adic representation of N + M in case γ = 1. In case i > n (or i > m) and γ = 0, we do not need to use b,γ and Carry add,b anymore to determine the last d i s. In fact, in case i > n, we will have that the resulting reduced b-adic representation is (c m,..., c i+1, d i,..., d 0 ). This shows that we need at most max{n, m} + 1 evaluations of b,γ and Carry add,b. (c) We proceed as in (a) to find out whether N < M, N = M or N > M, and to find the largest k with a k c k in case N M, where again we interpret a i = 0 for i > n and c i = 0 for i > m. In case N = M, return (). Otherwise, swap N and M if necessary so that N > M, set γ := 0 and iterate i = 0,..., k. In iteration i, compute d i := a i b,γ c i and γ := Carry sub,b (a i, c i, γ). After all iterations, we must have γ = 0 as N > M. We then find the largest index i {0,..., k} with d i 0 and return (d i,..., d 0 ). Since k max{n, m}, we need at most max{n, m} + 1 evaluations of b, and Carry sub,b. For the comparison, we need at most k (for finding i) +(max{n, m} k + 2) (for finding k) comparisons, which yields max{n, m} + 2 comparisons in total. (d) Note that M = m i=0 c ib i. Therefore, MN = m i=0 (c in)b i. Multiplication of N by b i is easy: in case N > 0, N b i has the reduced representation (a n,..., a 0, 0,..., 0), where at the end we have added i zeros. We call such multiplications also shifts by i positions. 10 Therefore, to compute NM, we compute c i N for i = 0,..., m (as long as c i 0), and add the correctly shifted results together. To compute c i N, we use b and Carry mul,b together with b, and Carry add,b : first note that c i N = n j=0 a jc i b j. The following diagram shows how a (not necessarily reduced) b-ary representation (d n+1, d n,..., d 0 ) of c i N can be com- 10 Computers usually offer special instructions to multiply with powers of 2, since they can be implemented very efficiently in the same way. The same is true for division by powers of 2. In x86 assembler, the instructions SHL and SHR execute shifts to the left (multiplication) and right (division).

6 6 CHAPTER 1. BASIC ARITHMETIC puted: a 0 c i a 1 c i... a 2 c i a n c i = d n+1 d n d 3 d 2 d 1 d 0 (The long boxes with the multiplications inside should be interpreted as two entries, the left one being Carry mul,b (a j, c i ) and the right one being a j b c i. The bend arrows should be interpreted as Carry add,b.) Here, we execute n + 1 evaluations of b and Carry mul,b, one assignment, n + 1 evaluations of b,, and n evaluations of Carry add,b (note that in the last addition, which computes d n+1, there will be no carry, since Carry mul,b (a n, c i ) b 2. If k 1 i=0 c inb i is already computed and we just computed c k N, we need at most n + 2 evaluations of b, and Carry add,b to compute k i=0 c inb i (see (b)). This is only needed for k = 1,..., m. Therefore, the maximum total number of operations are: at most (m + 1)(n + 1) evaluations of b and Carry mul,b, (m + 1)(n + 1) + m(n + 2) = (2m + 1)(n + 1) + m evaluations of b,, and (m + 1)n + m(n + 2) = (2m + 1)n + 2m evaluations of Carry add,b. (e) [Knu81, Section 4.3.1] In case n < m, we set Q = (0) and R = (a n,..., a 0 ) and we are done. If this is not the case, we proceed with two simplifications: We first normalize N and M so that c m b/2. If this is not already the case, we multiply 11 both N and M by x := b/(c m + 1) {1,..., b/2 }, and after the whole computation, we divide R by x. We then reduce to n m + 1 divisions for two numbers of almost the same size as follows: first, compute Q, R such that (0, a n,..., a n m ) = (c m,..., c 0 ) Q + R with (r m,..., r 0 ) := R < (c m,..., c 0 ); then 0 Q b 1. Multiplying this identity with b n m and adding (a n m 1,..., a 0 ), we obtain (a n,..., a 0 ) = (c m,..., c 0 ) (Q, 0,..., 0 ) + (r }{{} m,..., r 0, a n m 1,..., a 0 )), n m times 11 To see that this works, first note that c mx b/2 : this is clear for c m = 1, and for c m 2, we consider the two cases c m b/4 and c m < b/4. In case c m < b/4, 2c 2 m/(c m 1) 4c < b implies c m(b c m)/(c m + 1) b/2, which in turn implies c m b/(c m + 1) b/2. In case c m b/4 we have b/4 < c m + 1 b/2, which yields 2 b/ b/2 < b/(c m + 1) < 4, whence x {2, 3}. Now b/2 b/2 2c m 3c m completes the proof that c mx { b/2,..., b 1}. We now want to show that xm < b m+1, which shows that the reduced b-adic representation of xm has size m; the above then shows that the leading digit is at least b/2. Note that M/b m < c m + 1, whence xm < x (c m + 1)b m b/(c m + 1) (c m + 1)b m = b m+1.

7 1.1. INTEGER ARITHMETIC 7 where (r m,..., r 0, a n m 1,..., a 0 ) < (c m,..., c 0 )b n m. We then continue by dividing (r m,..., r 0, a n m 1) by (c m,..., c 0 ) to compute the next digit of Q. This will be iterated until we are done. For the above, we have to discuss two special cases: (i) Exact division by a number in {1,..., b 1}; (ii) Long division with remainder for two numbers (a m+1,..., a 0 ) by (c m,..., c 0 ), where (a m+1,..., a 0 ) < (c m,..., c 0 )b and c m b/2. Note that for (ii), the quotient will be in {0,..., b 1}. We now discuss the two steps (i) and (ii) in more detail. (i) We can essentially proceed as in the second reduction mentioned above, since the long division of a two-digit b-adic number by a one-digit b-adic number is a basic b-operation. Given N = (e k,..., e 0 ) and q {2,..., b 1}, we want to compute N/q, knowing that N/q N. We proceed by extending N to (e k+1, e k,..., e 0 ) with e k+1 = 0; then (e k+1, e k,..., e 0 ) < qb k+1. We compute (q k,..., q 0 ) {0,..., b 1} k+1 by iterating i = k,..., 0. In iteration i, we compute q i := (e i+1 b + e i ) div b q and e i := (e i+1 b + e i ) rem b q. Before iteration i, if we have (e i+1, e i,..., e 0 ) < qb i+1, then (e i+1, e i ) < qb, whence (e i+1 b + e i ) div b q and (e i+1 b + e i ) rem b q are defined. Since ((e i+1 b + e i ) rem b q) b 1, we will have that (e i, e i 1,..., e 0 ) < qb i after e i is redefined. Hence, during all iterations, div b and rem b are well-defined. Note that here, we have used k + 1 evaluations of div b and rem b. This shows that the whole normalization process needs at most 2(n + 1) + 2(m + 1) evaluations of b and Carry mul,b, 5(n + 1) + 5(m + 1) + 4 evaluations of b,, 5n + 5m + 8 evaluations of Carry add,b (to multiply N and M by x; compare (d)), and m + 1 evaluations of div b and rem b (to divide R by x). (ii) Define ˆq := min{ (a m+1 b + a m )/c m, b 1}. If q is the quotient q = (a m+1,..., a 0 )/(c m,..., c 0 ), then ˆq is a good approximation of q: Claim: ˆq q ˆq 2. [Knu81, p. 256, Theorems A and B] For the first inequality, assume that ˆq = (a m+1 b + a m )/c m, since q < b implies the claim when ˆq = b 1. Now c mˆq a m+1 b + a m (c m 1), whence (a m+1,..., a 0 ) ˆq(c m,..., c 0 ) m+1 i=0 m+1 i=0 a i b i (a m+1 b + a m c m + 1)b m a i b i ˆqc m b m m 1 = (c m 1)b m + a i b i < c m b m (c m,..., c 0 ), i=0

8 8 CHAPTER 1. BASIC ARITHMETIC which implies ˆq q. For the other inequality, assume that ˆq 3 q. We have ˆq a m+1b + a m c m = a m+1b m+1 + a m b m c m b m (a m+1,..., a 0 ) c m b m < (a m+1,..., a 0 ) (c m,..., c 0 ) b m, where the last denominator is > 0 since otherwise, c m = 1 and c m 1 = = c 0 = 0 would imply q = ˆq. As q > (a m+1,..., a 0 )/(c m,..., c 0 ) 1, 3 ˆq q < (a m+1,..., a 0 ) (c m,..., c 0 ) b m (a m+1,..., a 0 ) + 1 (c m,..., c 0 ) = (a m+1,..., a 0 ) b m (c m,..., c 0 ) (c m,..., c 0 ) b m + 1. This implies We conclude with (a m+1,..., a 0 ) (c m,..., c 0 ) > 2 (c m,..., c 0 ) b m b m m 1 = 2(c m 1) + 2 c i b i m 2(c m 1) Z. i=0 b 4 ˆq 3 q = (am+1,..., a 0 ) (c m,..., c 0 ) 2(c m 1) 2 b = b 3, a contradiction. Therefore, ˆq 3 < q, whence q ˆq 2. Thus we first compute (a m+1,..., a 0 ) max{0, ˆq 2} (c m,..., c 0 ) and compare it to (c m,..., c 0 ). If the former is less than the latter, we subtract (c m,..., c 0 ), and repeat if necessary. After at most two subtractions, the remainder will be less than (c m,..., c 0 ). For the one multiplication and (at most) two comparisons and three subtractions, we need at most such many basic b-operations (compare (c) and (d)): 2(m + 1) evaluations of b and Carry mul,b, 5(m + 1) + 2 evaluations of b,, 5m + 4 evaluations of Carry add,b, 3(m + 3) evaluations of b, and Carry sub,b, 3(m + 3) comparisons of elements {0,..., b 1}. For computation of ˆq, we need one evaluation of div b. Now, to sum up, we need to do the normalization step at most once, and the division in (ii) at most n m+1 times. Therefore, the total number of operations needed at most are:

9 1.2. A BIT OF COMPLEXITY THEORY 9 2(n + 1) + 2(m + 1) + 2(m + 1)(n m + 1) = 2m(n m) + 4n + 2m + 6 evaluations of b and Carry mul,b, 5(n+1)+5(m+1)+4+(5(m+1)+2)(n m+1) = 5m(n m)+12n+3m+21 evaluations of b,, 5n + 5m (5m + 4)(n m + 1) = 5m(n m) + 9n + 6m + 12 evaluations of Carry add,b, 3(m + 3)(n m + 1) = 3m(n m) + 9n 6m + 9 evaluations of b, and Carry sub,b and comparisons of elements {0,..., b 1}, m (n m + 1) = n + 2 evaluations of div b, m + 1 evaluations of rem b. Note that it is in general not recommended to implement such integer arithmetic by one-selves, but to use libraries which provide such arithmetic. A prime example is the GNU Multiprecision library [GMP]. In some programming languages, such as Python [Py], support for multiprecision arithmetic is already included. In fact, while Python offers two integer types, int (for CPU integers) and long (for arbitrary precision integers), values of type int will automatically 12 turn into type long if the result of an expression does not fit into int. 1.2 A Bit of Complexity Theory In the last section we have seen how to do integer arithmetic using b-adic representations. For example, multiplying two b-adic representations of integers N and M require assuming a reduced representation (size b (M) + 1)(size b (N) + 1) evaluations of b and Carry mul,b, at most (2 size b (M) + 1)(size b (N) + 1) + size b (M) evaluations of b, and at most (2 size b (M) + 1) size b (N) + 2 size b (M) evaluations of Carry add,b. Carrying these numbers around is quite annoying, and in many cases does not say a lot. If we just use basic b-operations as the measure, it gets simpler: multiplication of two b-adic reduced representations of integers N and M requires at most 2(size b (M) + 1)(size b (N) + 1) + (2 size b (M) + 1)(size b (N) + 1) + size b (M) + (2 size b (M) + 1) size b (N) + 2 size b (M) = 6 size b (N) size b (M) + 7 size b (M) + 4 size b (N) + 3 basic b-operations. This expression is still somewhat complicated. Moreover, since we have seen that size b (N) log N log b in Remark (d), we see that the number of basic b-operations is 6 7 log N log M + log b log b log M + 4 log b log N + 3 log b 6 log N log M, log b where for the last, we assume that both N and M are large. Note that except for the constant, the expression only depends on log N and log M, and not at all on the choice of b. Thus, in case b is fixed which it usually is, after fixing a 12 This was implemented in Python 2.2. In Python 3, there is only one integer type. Also see Section

10 10 CHAPTER 1. BASIC ARITHMETIC concrete architecture on which we implement algorithms on, what only matters is the expression following the constant, namely the log N log M. In the following, for a set K, we will consider functions f : N K R. If K = {1,..., m}, then f : N K R is a function in m natural variables to the reals. For a, b N K we will write a b if and only if a k b k for all k K. Definition Let K be an index set and let f, g : N K R be two functions. (a) We write f O(g) if and only if n 0 N K c > 0 n N K : n n 0 f(n) c g(n). We say that f is in big-o of g. (b) We write f o(g) if and only if We say that f is in little-o of g. (c) We write f Θ(g) if and only if We say that f is in Theta of g. f O(g) g O(f). f O(g) g O(f). Remarks For (a), (b) and (c), assume that g(n) 0 for all n K. f(n) (a) Then f o(g) if and only if lim n g(n) this case. 13 (b) Moreover, f O(g) if and only if lim sup n f(n) g(n) <. = 0. In particular, the limit exists in (c) Finally, f Θ(g) if and only if g Θ(f), which is the case if and only if f(n) 0 < lim inf n g(n) lim sup f(n) n g(n) <. (d) If f = a m X m + a m 1 X m a 0 is a univariate polynomial with a m 0, then f O(g), where g(x) := x m. That is, we only take the largest term of the polynomial and are only interested in the exponent, but not in its coefficient. Using the big-o notation, we can simply state that multiplication of two b-adic reduced representations of positive integers N and M can be done with O(log N log M) basic b-operations. A restatement of Theorem using the new notation is the following: Corollary (Basic Integer Arithmetic). Let b 2 be a natural number, and let N and M be two integers. Assume that we are given reduced b-adic representations of N and M. We assume that the sign is given separately as a value in { 1, +1}. (a) Testing whether N < M, N = M or N > M using the reduced b-adic representations of N and M can be done in O(min{log N, log M}) basic b-operations. 13 Here, with n, we mean that n = (n k k K) is a family of variables which all converge to uniformly. For K <, this is equivalent to pointwise convergence of the n k.

11 1.3. POLYNOMIAL ARITHMETIC 11 (b) Computing a reduced b-adic representation of N + M using the reduced b-adic representations of N and M can be done in O(max{log N, log M}) basic b- operations. (c) Computing a reduced b-adic representation of N M using the reduced b-adic representations of N and M can be done in O(max{log N, log M}) basic b- operations. (d) Computing a reduced b-adic representation of N M using the reduced b-adic representations of N and M can be done in O(log M log N) basic b-operations. (e) Assume that M 0. Computing reduced b-adic representations of two numbers Q, R N with N = Q M +R and R < M using the reduced b-adic representations of N and M can be done in O(max{log M (log N log M + 1), 1}) basic b-operations. 1.3 Polynomial Arithmetic Two fundamental arithmetics in computer algebra are arithmetic in Z and polynomial arithmetic. As with integers, one first has to think on how to represent polynomials on a computer. There are essentially two general representations: A dense representation: a polynomial n i=0 a ix i over a ring R is specified by a list (a n,..., a 0 ) R n+1 of coefficients. A sparse representation: a polynomial n i=1 a ix e i with e 1 < < e n is specified by a list ((a 1, e 1 ),..., (a n, e n )) of pairs (a i, e i ) R N. Both representations have advantages and disadvantages, depending on how they are used. In some cases, mixing these two representations can yield improvements. For example, when representing the polynomial X q X for a huge prime power q, the sparse representation is the representation of choice. On the other hand, to represent the quotient Xn 1 X 1 of the two sparse polynomials Xn 1 and X 1 as a polynomial, one obtains n 1 i=0 Xi, for which a dense representation is better suited. In this lecture, and in particular for the rest of this section, we will almost exclusively work with dense representations of polynomials. Remark (a) Similar to b-adic representations of natural numbers, the dense representation (a n,..., a 0 ) of n i=0 a ix i can be made unique by forcing n = 1 (the empty list () ) or a n 0. As before, we call such representations reduced. (b) We define the degree of the zero polynomial as 1. (As opposed to, which is common in many parts of mathematics.) Then the degree of the polynomial equals the length of the list minus one for the reduced dense representation. (c) We denote the leading coefficient a n of a polynomial f = n i=0 a ix i with a n 0 by LC(f). In case f = 0, we define LC(0) := 0. (d) If (a n,..., a 0 ) represents the polynomial f = n i=0 a ix i, we will often write f = (a n,..., a 0 ) in the following. The four basic operations for polynomials are

12 12 CHAPTER 1. BASIC ARITHMETIC addition and subtraction, multiplication, and Euclidean (long) division with remainder. We present some simple algorithms for these operations and analyze their running time in terms of operations in the underlying ring R. Note that in particular for R = Z and R = Q, these operations can be very expensive, and for such rings, special algorithms can perform much faster. Theorem (Polynomial Arithmetic). Let f, g R[X] be two polynomials with n = deg f and m = deg g, given by their dense representation. Let λ R. (a) We can compute a dense representation of λf using at most n+1 multiplications and n + 2 comparisons in R. (If R is zero-divisor free, one comparison suffices to check whether λ 0). The total number of operations in R is thus in O(n). (b) We can compute a dense representation of f + g and f g using min{n, m} + 1 additions respective subtractions in R, max{n, m} min{n, m} duplication of elements or negations, and at most min{n, m} + 1 comparisons. The total number of operations in R is thus in O(max{n, m}). (c) We can compute a dense representation of f g using mn additions and (m + 1)(n + 1) multiplications in R and at most n + m + 1 comparisons in R. The total number of operations in R is thus in O(mn). (d) Assume that LC(g) is a unit in R. We can compute a dense representation of q, r R[X] with f = qg+r and deg r < m = deg g using one inversion of a unit, at most (n m + 1)m subtractions, at most (n m + 1)(m + 1) multiplications in R, at most n + 1 duplications of elements of R and at most m comparisons in R. The total number of operations in R is thus in O(nm). In case LC(g) = 1, it suffices to do at most (n m + 1)m subtractions, (n m + 1)m multiplications and m comparisons in R. Proof. Let f = (a n,..., a 0 ) and g = (b m,..., b 0 ). (a) In case λ = 0, the result is (). Otherwise, λf = (λa n,..., λa 0 ). In case R is zero-divisor free, this representation is already reduced; otherwise, one can start with λa n ; if λa n = = λa i = 0 and λa i+1 0, then (λa i+1,..., λa 0 ) is reduced and can be returned. In case no such i exists, return (). This algorithm clearly requires n + 1 multiplications in R (in case λ 0). Normalization of the result requires at most n+1 comparisons of the coefficients to 0 R. (b) Without loss of generality, assume that n m. Then f ± g = (±b m,..., ±b n+1, a n ± b n,..., a 0 ± b 0 ). In case m > n, this is already a reduced representation; in case m = n, one starts with the largest index i such that a i ± b i 0, or returns () in case no such index exists. We need at most min{n, m} + 1 comparisons to 0 R for this. In case n = m, we have n+1 additions resp. subtractions and 0 duplications. In case n < m, we have n + 1 additions resp. subtractions and m n duplications resp. negations (for ( b m,..., b n+1 )). In case n > m, we have m + 1 additions resp. subtractions and n m duplications.

13 1.4. EUCLIDEAN ALGORITHM 13 (c) Note that f g = (c m+n,..., c 0 ), where c i = min{i,n} j=max{0,i m} a j b i j. This coefficient can be computed using N i := min{i, n} max{0, i m} additions and N i + 1 multiplications. Therefore, all coefficients together can be computed using n+m i=0 N i = n+m i=0 ( n = i + i=0 ( 1 = = 1 2 n+m min{i, n} n+m i=n+1 n(n + 1) + mn 2 i=0 max{0, i m} ) ( m n 0 + ) i=0 ( m+n i=0 m+n i=m+1 i m i=0 ) (i m) ) i nm ( n(n + 1) + m(m + 1) + 4mn (m + n)(m + n + 1) ) = mn additions and n+m i=0 (N i+1) = mn+(n+m+1) = (m+1)(n+1) multiplications. Finally, to normalize the result, we need at most n + m + 1 comparisons with 0 R. (d) In case n < m, we set q := () and r := f. This requires n + 1 duplications. Now assume n m. Then deg q = n m. In case LC(g) 1, we invert LC(g) and store it, say in u. We start with r := f = (a n,..., a 0 ) =: (r n,..., r 0 ) and q := (c n m,..., c 0 ) with all c i = 0 in the beginning. We proceed iteratively from i = n m down to i = 0. Before and after each iteration, f = q g + r. For each i, we set c i := ur m+i and subtract c i X i g from r. For the latter, we subtract c i b j from r j+i, j = 0,..., m. (Note that c i b m = r m+i ub m = r m+i, whence after this, r m+i = 0. In fact, we do not subtract c i b m from r i+m, but simply set r i+m = 0.) Therefore, in iteration i, we do m + 1 (or just m if u = 1) multiplications and m subtractions in case c i 0, and nothing in case c i = 0. After all iterations, we will have r m = = r n+m = 0, and we determine the smallest i such that r i = = r n+m = 0 and set r = (r i 1,..., r 0 ); in case no such i exists, we set r = (). As we have n m + 1 iterations, we perform at most (n m + 1)(m + 1) multiplications (or just (n m+1)m if u = 1), at most (n m+1)m subtractions and at most m comparisons (to normalize r) to compute q and r. 1.4 Euclidean Algorithm A class of integral domains with very nice division properties are Euclidean rings, rings in which one has an Euclidean division. Prime examples are the integers (Z) and polynomial rings over fields (K[x]).

14 14 CHAPTER 1. BASIC ARITHMETIC Definition An integral domain R is called Euclidean if there exists a function ν : R Z { }, ν(r \ {0}) N such that (a) for every a, b R, b 0, we have ν(a) ν(ab); and (b) for every a, b R, b 0, there exist q, r N with a = qb + r and ν(r) < ν(b). We will call ν an (Euclidean) valuation. Remarks (a) [Rog71] Note that any ring R with valuation ν which satisfies the definition except part (a) can be made Euclidean by defining ˆν(x) := min{ν(xa) a R, a 0}: then (R, ˆν) satisfies both (a) and (b). (b) [vzgg03, p. 60, Exercise 3.5] Moreover, one can consider the set X R := {ν ν satisfies condition (b)} and define ν min (x) := min{ν(x) ν X R }. Then ν min satisfies both (a) and (b). (c) Note that if a, b R are associated, i.e. a = be with e R, then ν(a) = ν(b). 14 (d) Moreover, note that ν(0) < ν(1) < ν(a) for every non-zero non-unit a R \ (R {0}). 15 Example For R = Z, the function ν : Z N, x x satisfies the conditions of the definition. Here, ν(a) = ν(b) if and only if a and b are associated, which is the case if and only if a = ±b. One can show that the minimal function ν min is ν min (x) = log 2 x with ν min (0) = [vzgg03, p. 61, Exercise 3.5 (vi)]. Example For R = K[x], ν = deg satisfies the conditions of the definition. (In fact, ν = ν min [vzgg03, p. 61, Exercise 3.5 (vi)].) Here, q and r are uniquely determined by a and b: if a = qb+r = q b+r for q, q, r, r K[x] with deg r, deg r < deg b, then r r = b(q q ) implies deg(r r ) = deg b + deg(q q ), which is only possible if r r = 0 = q q. In this case, ν(a) = ν(b) does not imply that a and b are associated: for example, consider a = x and b = x + 1. Euclidean domains are principal ideal domains and thus also factorial, which means that they have unique factorization of non-zero elements as a product of a unit and prime elements. Another advantage is that they allow to compute greatest common divisors very efficiently. The basic technique of doing this was first described by Euclid in his books Elements VII and X. His original treatment only uses subtraction and comparison of integers, but it can be sped up dramatically by using Euclidean (long) division. This yields the modern form of one of the most fundamental algorithms, which we will now state in full detail: Theorem (Euclidean Algorithm). Let R be an Euclidean domain with valuation ν. Assume that we are given a 0, a 1 R \ {0}. Define sequences (a i ) i 0, (b i ) i 0, (c i ) i 0, (q i ) i 0, (T i ) i 0, as follows: 14 We have ν(a) = ν(be) ν(bee 1 ) = ν(b) by part (a), and conversely, ν(b) = ν(ae 1 ) ν(ae 1 e) = ν(a). 15 First, ν(1) ν(1 a) = ν(a) shows that every non-zero non-unit s valuation is at least ν(1). Hence, 0 = q 1+r with ν(r) < ν(1) implies that r = 0 and ν(0) < ν(1). Finally, consider 1 = q a+r with ν(r) < ν(a). It is not possible that r = 0, as this implies 1 = q a, which is absurd as a is a non-unit. Therefore, ν(1) ν(r) < ν(a).

15 1.4. EUCLIDEAN ALGORITHM 15 ( ) b0 b define 1 := c 0 c 1 ( ) 1 0 ; 0 1 if a i 2 and a i 1 are defined, define q i, a i, T i, b i and c i as follows: (i) let q i, a i R with a i 2 = q i a i 1 + a i such that ν(a i ) < ν(a i 1 ) (Euclidean division) in case a i 1 0, and q i = a i = 0 in case a i 1 = 0; ( ) 0 1 (ii) define T i := R 1 q 2 2 ; i (iii) define ( ) bi 2 c (b i, c i ) := (1, q i ) i 2. Then there exists an index i with a i = 0. Let n 1 be the largest index such that a n 0. Then the following holds: (a) for 1 j i n + 1, ( ) ai 1 b i 1 c i 1 a i b i c i b i 1 c i 1 ( ) aj 1 b = T i T i 1 T j 1 c j 1 j+1 ; a j b j c j (b) for i = 1,..., n + 1, ( ) bi 1 c A i := i 1 = T i T i 1 T 2 b i c i and det A i = ( 1) i 1 ; (c) for i = 1,..., n + 1, a i = b i a 0 + c i a 1 and b i, c i are coprime; (d) a n = b n a 0 + c n a 1 (Bézout equation) is a greatest common divisor of a 0 and a 1 ; (e) ( 1) i 1 a 0 = c i a i 1 c i 1 a i and ( 1) i a 1 = b i a i 1 b i 1 a i for i = 1,..., n + 1; in particular, a 0 = ( 1) n c n+1 a n and a 1 = ( 1) n+1 b n+1 a n ; (f) we have q i 0, 2 < i n+1, and for i = 2, we have q i = 0 only if ν(a 1 ) > ν(a 0 ). During the rest of this section, as well as the next section, we will always use the notation from the theorem. Note that if we are only interested in a greatest common divisor of a 0 and a 1, we do not have to carry b i, c i around. In fact, one can implement this algorithm in very few lines, as the following Python example for integers shows: 1 def gcd (a, b): Listing 1.1: GCD of Integers 2 " Compute GCD of its two inputs " 3 while b!= 0: 4 a, b = b, a % b 5 return a If we want to compute x, y Z such that ax+by = gcd(a, b), we need to invest more work. This processes is often called the Extended Euclidean Algorithm. Fortunately, we can read off the required formulas directly from the theorem:

16 16 CHAPTER 1. BASIC ARITHMETIC 1 def gcdex (a, b): Listing 1.2: Extended GCD of Integers 2 " Compute extended GCD ( with Bé zout equation ) of its two inputs. Returns the GCD followed by the coefficients of the linear combination." 3 ai = b # ai stands for : a with index i 4 aim1 = a # aim1 stands for : a with index i -1 5 bi = 0 # bi stands for : b with index i 6 bim1 = 1 # bim1 stands for : b with index i -1 7 ci = 1 # ci stands for : c with index i 8 cim1 = 0 # cim1 stands for : c with index i -1 9 while ai!= 0: 10 q, r = divmod ( aim1, ai) # compute both quotient and remainder 11 aim1, ai = ai, r 12 bim1, bi = bi, bim1 - q * bi 13 cim1, ci = ci, cim1 - q * ci 14 return aim1, bim1, cim1 Note that divmod(a, b) for integers a, b does an Euclidean division: it returns a pair (q, r) with a = q * b + r and abs(r) < abs(b). In fact, q = a b. Instead of q, r = divmod(aim1, ai), we could have also written q, r = aim1 / ai, aim1 % ai, or q = aim1 / ai; r = aim1 % ai. We can accelerate the algorithm, since in the first loop iteration, bi and ci are very easy to compute: 1 def gcdex (a, b): Listing 1.3: Optimized Extended GCD of Integers 2 " Compute extended GCD ( with Bé zout equation ) of its two inputs. Returns the GCD followed by the coefficients of the linear combination." 3 ai = b # ai stands for : a with index i 4 aim1 = a # aim1 stands for : a with index i -1 5 # We can accelerate the first step 6 if ai!= 0: 7 q, r = divmod ( aim1, ai) # compute both quotient and remainder 8 aim1, ai = ai, r 9 bim1, bi = 0, 1 # before : bi = 0, bim1 = 1 10 cim1, ci = 1, - q # before : ci = 1, cim1 = 0 11 # Now continue 12 while ai!= 0: 13 q, r = divmod ( aim1, ai) # compute both quotient and remainder 14 aim1, ai = ai, r 15 bim1, bi = bi, bim1 - q * bi 16 cim1, ci = ci, cim1 - q * ci 17 else : 18 bim1 = 1 19 cim1 = 0 20 return aim1, bim1, cim1 Here, in lines 7 to 10, we essentially unroll 16 the first loop iteration and specialize it. We can test the function as follows: 16 Unrolling loops is an important optimization done by many compilers, which translate (human-

17 1.4. EUCLIDEAN ALGORITHM 17 1 a,b = 5, 7 2 d,x,y = gcdex (a, b) 3 print d == x*a + y*b 4 a, b = , d,x,y = gcdex (a, b) 6 print d == x*a + y*b Python instantaneous prints out the answer True in both cases. Note that 1 = ( ) , whence the two large numbers are coprime. Proof. Note that ν(a 1 ) > ν(a 2 ) > ν(a 3 ) >. Since ν(a i ) 0 is an integer while a i 0, there must be some index i such that a i = 0. As further a 0 0 a 1, a maximal n 1 exists with a n 0. (a) one checks this quickly for j = i 1, and it is trivial for j = i; the general case then follows by induction on i j. ( ) ( ) b0 b (b) Apply (a) for j = 2 and use = ; this yields A c 0 c i = T i T i 1 T 2. Now det T i = 1, whence det A i = ( 1) i 1. ( ) (c) Since (0, 1) (1, 0, 0) a i T = a i, we can apply (a) and (b) to obtain a i = ( 0 1 )( )( ) b i 1 c i 1 a0 b 0 c = ( ) ( ) a b b i c i a 1 b 1 c i c 0 i, 1 a 0 1 which simplifies to b i a 0 + c i a 1. Since 1 = det A i = b i 1 c i c i 1 b i, we see that c i and b i are coprime. readable) program code into machine code. The rationale is that conditional jumps (like: repeat the code block if the counter is less than something) are costly on modern CPUs, since the CPUs try to look ahead what will happen soon and might even already execute later instructions (out of order execution) under very special circumstances. In case of a conditional jump, the CPU does not know in advance whether it will jump or not, and so cannot really look ahead. Therefore, code such as 1 for i in xrange (4) : 2 x[i] = i will often automatically be translated to 1 x [0] = 0 2 x [1] = 1 3 x [2] = 2 4 x [3] = 3 by the compiler.

18 18 CHAPTER 1. BASIC ARITHMETIC (d) That a n = b n a 0 + c n a 1 follows from (c); this equation implies that every divisor of a 0 and a 1 also divides a n. So we are left to show a n a 0, a 1. For that, we show by induction on j that a n divides both a n+1 j and a n j, for j = 0,..., n. For j = 0, a n+1 j = a n+1 = 0 and a n j = a n, whence this is clear. Now assume a n a n+1 j, a n j. As a n+1 (j+1) = a n j and a n (j+1) = a n j 1 = q n+1 j a n j + a n+1 j, we see using the induction hypothesis that a n also divides a n+1 (j+1) and a n (j+1). (e) Note that for i = 1,..., n + 1, we have ( ) i = ( 1) i 1 ci c i 1 b i b i 1 A 1 (since det A i = ( 1) i 1 ). Using this together with parts (a) and (b), we obtain ( 1) i 1 a 0 = c i a i 1 c i 1 a i and ( 1) i a 1 = b i a i 1 b i 1 a i. (1.1) Plugging in i = n + 1, we obtain ( 1) n a 0 = c n+1 a n and ( 1) n+1 a 1 = b n+1 a n. (f) If ν(a i 2 ) > ν(a i 1 ) (which is always satisfied for i = 3,..., n + 1), then we cannot have q i = 0, as otherwise a i = a i 2 and thus ν(a i ) > ν(a i 1 ), which contradicts the construction of q i and a i. In the following lemma, we prove two further results for the special cases of integers with a more rigid definition of Euclidean division and polynomials over a field. These will be very useful when analyzing the algorithm in the next section. Lemma Assume that we have either of the following two cases: R = Z, ν(x) = x and for Euclidean division a = qb + r, we assume that a r < a in case r 0, which is equivalent to ar 0; R = K[X] for some field K and ν(f) = deg f. Further assume that ν(a 0 ) ν(a 1 ). Then during the Euclidean algorithm, the following properties hold: (a) For i = 2,..., n + 1, ν(b i 1 ) ν(b i ) and ν(c i 1 ) ν(c i ). In the case of R = Z, we have strict inequality except possibly ν(b 3 ) = ν(b 2 ), which happens if and only if ν(q 3 ) = 1, and ν(c 2 ) = ν(c 1 ), which happens if and only if ν(q 2 ) = 1. In the case of R = K[X], we have strict inequality except possibly ν(c 1 ) ν(c 2 ), which happens if and only if ν(a 0 ) = ν(a 1 ). (b) For i = 1,..., n + 1, ν(b i a i 1 ) ν(a 1 ) and ν(c i a i 1 ) ν(a 0 ), and in the case of R = K[X], we have equality. Remark Note that in case R = Z of Lemma 1.4.6, we need the additional assumption that a r 0 (which is equivalent to a r < a if r 0). Consider a 0 = 7 and a 1 = 5. Since 7 = and 3 < 5,

19 1.4. EUCLIDEAN ALGORITHM 19 we could choose q 2 = 2 and a 2 = 3. This would result in b 2 = 1 and c 2 = 2, whence ν(c 2 a 1 ) = 10 > 7 = ν(a 0 ). If we continue as follows: 5 = ( 2) ( 3) 1 since 1 < 3, we obtain q 3 = 2, a 3 = 1, b 3 = 6 and c 3 = 9. Here, both ν(c 3 a 2 ) = 9 > 7 = ν(a 0 ) and ν(b 3 a 2 ) = 6 > 5 = ν(a 1 ). This violates part (b) of the lemma. Proof of Lemma Note that since det T i = 1, we have that gcd(b i 1, b i ) = 1 = gcd(c i 1, c i ) for i = 2,..., n + 1; we also have the coprimeness for i = 1, since b 0 = 1 = c 1. Therefore, for i = 2,..., n + 1, we have b i = b i 2 q i b i 1 0 and c i = c i 2 q i c i 1 0 except possibly c 2 = 0 if q 2 = 0. But since ν(a 0 ) ν(a 1 ) we must have q 2 0 as well, whence also c 2 0. We consider the two cases R = Z and R = K[X] separately. We begin with R = K[X]. First note that except possibly for i = 2 (where it could happen that deg a 0 = deg a 1 ), deg q i > 0 since deg a i 2 > deg a i 1. (a) We proceed by induction on i. For i = 2, b 1 = 0, b 2 = 1 and c 1 = 1, c 2 = q 2 0. Now assume that the statement holds for some i 2. Since b i+1 = b i 1 q i+1 b i and deg b i 1 < deg b i, deg b i+1 = deg(q i+1 b i ) = deg q i+1 + deg b i > deg b i since deg q i+1 > 0. The claim holds analogous for c i+1. (b) Since ( 1) i 1 a 0 = c i a i 1 c i 1 a i and deg c i > deg c i 1 and deg a i 1 > deg a i, deg a 0 = deg(c i a i 1 ). The claim holds analogous for deg a 1 = deg(b i a i 1 ). Now we consider R = Z. We begin with proving some auxiliary claims. Claim (iii) directly implies (a), and claim (v) directly implies (b). (i) Claim: If a 0 and a 1 have the same sign, then all q i 0, i = 2,..., n; otherwise, all q i 0, i = 2,..., n. First note that a i always has the same sign as a i+2. If both a 0 and a 1 have the same sign, then all a i 0. As a i < a i 1 a i 2 and a i 2 = q i a i 1 + a i, it must be that q i 0. If a 0 a 1 < 0, we have that a i 2 and q i a i 1 have the same sign. Since a i 2 a i 1 0, it must be that q i 0. (ii) Claim: If a 0 and a 1 have the same sign, ( 1) i b i, ( 1) i+1 c i 0 for i = 0,..., n + 1, and if a 0 and a 1 have different signs, b i, c i 0 for i = 0,..., n + 1. First assume that a 0 a 1 > 0. We prove the claim by induction on (i 1, i). For i = 0, ( 1) i b i = 1 0 and ( 1) i+1 c i = 0 0. For i = 1, ( 1) i b i = 0 0 and ( 1) i+1 c i = 1 0. Now assume that the claim is true for i 1 and i. Then ( 1) i+1 b i+1 = ( 1) i+1 b i 1 q i+1 ( 1) i+1 b i = ( 1) i 1 b i 1 + q i+1 ( 1) i b i. Since by claim (i), q i+1 0, and by induction hypothesis, ( 1) i 1 b i 1, ( 1) i b i 0, we get ( 1) i+1 b i+1 0. Similarly, ( 1) (i+1)+1 c i+1 = ( 1) i+2 c i 1 q i+1 ( 1) i+2 c i = ( 1) (i 1)+1 c i 1 + q i+1 ( 1) i+1 c i 0.

20 20 CHAPTER 1. BASIC ARITHMETIC Now assume that a 0 a 1 < 0. We again proceed by induction on (i 1, i). For i = 0 and i = 1, all b i and c i are 0 by definition. Now assume that the claim is true for i 1 and i. Then b i+1 = b i 1 q i+1 b i 0 since by induction hypothesis, b i 1, b i 0 and by claim (i), q i 0. The proof for c i+1 0 proceeds the same way. (iii) Claim: We have b i = q i b i 1 + b i 2 > b i 1 and c i = q i c i 1 + c i 2 > c i 1 for i = 2,..., n + 1. First assume that a 0 a 1 > 0. By claim (ii), b i = ( 1) i b i, whence b i = ( 1) i b i 2 ( 1) i q i b i 1 = ( 1) i 2 b i 2 + q i ( 1) i 1 b i 1. Using claim (ii) again yields b i 2 = ( 1) i 2 b i 2 and b i 1 = ( 1) i 1 b i 1, and by claim (i), q i = q i. Therefore, b i = q i b i 1 + b i 1. Similarly, c i = q i c i 1 + c i 1. Now assume that a 0 a 1 < 0. By claim (ii), b i = b i = b i 2 q i b i 1 = b i 2 + ( q i )b i 1. By claim (ii), b i 2 = b i 2 and b i 1 = b i 1, and by claim (i), q i = q i. Therefore, b i = q i b i 1 + b i 1. Similarly, c i = q i c i 1 + c i 1. We now prove the statement on the inequality by strong induction on i. Note that b 0 = 1, b 1 = 0, b 2 = 1 and b 3 = q 3. Therefore, b 2 > b 1 and q 3 = b 3 b 2 = 1 as q 3 0 (part (f) of theorem); moreover, we have b 3 > b 2 if and only if q 3 1. Now c 0 = 0, c 1 = 1, c 2 = q 2 and c 3 = 1 + q 2 q 3. As q 2 q 3 0 by claim (i) and q 2, q 3 0 by part (f) of the theorem, c 3 = 1 + q 2 q q 2 > q 2 = c 2 c 1 = 1; moreover, we have c 2 > c 1 if and only if q 2 1. Finally, assume that i > 3 and that the (not necessarily strict) inequality statement is true for all less i. The above show that b i 0 c i for i > 1, whence b i = q i b i 1 + b i 1 > q i b i 1 b i 1 since q i 0. Similarly, c i = q i c i 1 + c i 1 > q i c i 1 c i 1. (iv) Claim: If i, j {0,..., n+1} with i j (mod 2), we have ( 1) j a i b j a 1 0 and ( 1) i a i c j a 0 0. We have ( 1) i a i has the same sign as a 0 and ( 1) i+1 a i has the same sign as a 1. (See note in claim (i).) Now first consider that a 0 and a 1 have the same sign; then all a i have the same sign. By claim (ii), ( 1) j b j, ( 1) j+1 c j 0. Combining this yields 0 ( 1) j b j ai a 1 and 0 ( 1) j+1 c j ai a 0. Now assume that a 0 and a 1 have different signs. By claim (ii), b j, c j 0 for all j. Now 0 b j ( 1)i+1 a i a 1 and 0 c j ( 1)i a i a 0, and since ( 1) i+1 = ( 1) j and ( 1) j+1 = ( 1) i the claim follows. (v) Claim: For i = 1,..., n + 1, b i a 1 /a i 1 and c i a 0 /a i 1.

21 1.4. EUCLIDEAN ALGORITHM 21 We show this claim by induction over i. For i = 1, b i = 0, c i = 1 and a 0 /a i 1 = a 0 /a 0 = 1. Hence, b i = 0 a 0 /a i 1 and c i = 1 = a 0 /a i 1. Now assume that the statement is true for some i. As a i+1 < a i 1, the induction hypothesis yields a i+1 b i a 1 < a i 1 b i 1 and a i+1 c i < a i 1 c i 1. a 1 By claim (iv), ( 1) i a i+1 b i a 1 0, whence the above yields a i+1 b i ( 1) i a 1 = a i+1b i a 1 ( 1)i 1 a 1 1. Since a i+1 b i ( 1) i a 1 = a i b i+1 by part (e) of the theorem, we obtain a i b i+1 a 1. Similarly, by claim (iv), ( 1) i+1 a i+1 c i a 0 0, whence the above yields a i+1 c i + ( 1) i a 0 = ( 1) i+1 a i+1 c i a 0 1 a 0 1. Since a i+1 c i + ( 1) i a 0 = a i c i+1 by part (e) of the theorem, we finally obtain a i c i+1 a Analyzing the Euclidean Algorithm In this section, we still use the notation of Theorem Theorem (Euclidean Algorithm for Polynomials). Let K be a field and f, g K[x] \ {0} two non-zero polynomials given via their dense representation. Assume that we use the basic polynomial arithmetic described in Section 1.3 with dense representations. (a) Then the Euclidean algorithm needs at most 2 deg f deg g + deg f + deg g + 1 field operations (without inversion), min{deg f, deg g} + 1 comparisons (with 0 K) and at most min{deg f, deg g} 2 inversions in K to compute a dense representation of a greatest common divisor of f and g. (b) The Euclidean algorithm needs at most 6 deg f deg g 2 max{deg f, deg g} 4 min{deg f, deg g}+6 field operations (without inversion), min{deg f, deg g}+1 comparisons (with 0 K) and at most min{deg f, deg g} 2 inversions in K to compute both a dense representation of a greatest common divisor d K[x] of f and g as well as dense representations of x, y K[x] such that d = fx + gy. Proof. Set m i := deg a i, 0 i n + 1, and assume that m 0 m 1 ; then m 0 m 1 > m 2 > > m n+1. Since the number of field operations to compute Euclidean long division for polynomials of degree m i 1 and m i is at most (2m i + 1)(m i 1 m i + 1) (Theorem (d)), and additionally m i m i+1 comparisons (since m i+1 is the degree of the remainder), the total number of field operations required for the Euclidean algorithm for just computing a GCD is at most n i=1 (2m i + 1)(m i 1 m i + 1) and n i=1 (m i m i+1 ) = m comparisons. For a sequence m 0 m 1 > > m n 0, define f(m 0,..., m n ) := n i=1 (2m i + 1)(m i 1 m i + 1). We will show the following three claims: a 0 a 0

Remainders. We learned how to multiply and divide in elementary

Remainders. We learned how to multiply and divide in elementary Remainders We learned how to multiply and divide in elementary school. As adults we perform division mostly by pressing the key on a calculator. This key supplies the quotient. In numerical analysis and

More information

1. multiplication is commutative and associative;

1. multiplication is commutative and associative; Chapter 4 The Arithmetic of Z In this chapter, we start by introducing the concept of congruences; these are used in our proof (going back to Gauss 1 ) that every integer has a unique prime factorization.

More information

2 Arithmetic. 2.1 Greatest common divisors. This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}.

2 Arithmetic. 2.1 Greatest common divisors. This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}. 2 Arithmetic This chapter is about properties of the integers Z = {..., 2, 1, 0, 1, 2,...}. (See [Houston, Chapters 27 & 28]) 2.1 Greatest common divisors Definition 2.16. If a, b are integers, we say

More information

Finite Fields: An introduction through exercises Jonathan Buss Spring 2014

Finite Fields: An introduction through exercises Jonathan Buss Spring 2014 Finite Fields: An introduction through exercises Jonathan Buss Spring 2014 A typical course in abstract algebra starts with groups, and then moves on to rings, vector spaces, fields, etc. This sequence

More information

CS 4424 GCD, XGCD

CS 4424 GCD, XGCD CS 4424 GCD, XGCD eschost@uwo.ca GCD of polynomials First definition Let A and B be in k[x]. k[x] is the ring of polynomials with coefficients in k A Greatest Common Divisor of A and B is a polynomial

More information

Contribution of Problems

Contribution of Problems Exam topics 1. Basic structures: sets, lists, functions (a) Sets { }: write all elements, or define by condition (b) Set operations: A B, A B, A\B, A c (c) Lists ( ): Cartesian product A B (d) Functions

More information

1 Overview and revision

1 Overview and revision MTH6128 Number Theory Notes 1 Spring 2018 1 Overview and revision In this section we will meet some of the concerns of Number Theory, and have a brief revision of some of the relevant material from Introduction

More information

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

5 + 9(10) + 3(100) + 0(1000) + 2(10000) = Chapter 5 Analyzing Algorithms So far we have been proving statements about databases, mathematics and arithmetic, or sequences of numbers. Though these types of statements are common in computer science,

More information

Lecture 4: Number theory

Lecture 4: Number theory Lecture 4: Number theory Rajat Mittal IIT Kanpur In the next few classes we will talk about the basics of number theory. Number theory studies the properties of natural numbers and is considered one of

More information

Number Theory Solutions Packet

Number Theory Solutions Packet Number Theory Solutions Pacet 1 There exist two distinct positive integers, both of which are divisors of 10 10, with sum equal to 157 What are they? Solution Suppose 157 = x + y for x and y divisors of

More information

2 Elementary number theory

2 Elementary number theory 2 Elementary number theory 2.1 Introduction Elementary number theory is concerned with properties of the integers. Hence we shall be interested in the following sets: The set if integers {... 2, 1,0,1,2,3,...},

More information

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013 Fall 2013 Student Responsibilities Reading: Textbook, Section 3.7, 4.1, & 5.2 Assignments: Sections 3.6, 3.7, 4.1 Proof Worksheets Attendance: Strongly Encouraged Overview 3.6 Integers and Algorithms 3.7

More information

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd()

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd() Student Responsibilities Week 8 Mat 2345 Week 8 Reading: Textbook, Section 3.7, 4.1, & 5.2 Assignments: Sections 3.6, 3.7, 4.1 Induction Proof Worksheets Attendance: Strongly Encouraged Fall 2013 Week

More information

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Algorithms (II) Yu Yu. Shanghai Jiaotong University Algorithms (II) Yu Yu Shanghai Jiaotong University Chapter 1. Algorithms with Numbers Two seemingly similar problems Factoring: Given a number N, express it as a product of its prime factors. Primality:

More information

CSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal

CSE 311 Lecture 13: Primes and GCD. Emina Torlak and Kevin Zatloukal CSE 311 Lecture 13: Primes and GCD Emina Torlak and Kevin Zatloukal 1 Topics Modular arithmetic applications A quick wrap-up of Lecture 12. Primes Fundamental theorem of arithmetic, Euclid s theorem, factoring.

More information

Fast Polynomial Multiplication

Fast Polynomial Multiplication Fast Polynomial Multiplication Marc Moreno Maza CS 9652, October 4, 2017 Plan Primitive roots of unity The discrete Fourier transform Convolution of polynomials The fast Fourier transform Fast convolution

More information

2. THE EUCLIDEAN ALGORITHM More ring essentials

2. THE EUCLIDEAN ALGORITHM More ring essentials 2. THE EUCLIDEAN ALGORITHM More ring essentials In this chapter: rings R commutative with 1. An element b R divides a R, or b is a divisor of a, or a is divisible by b, or a is a multiple of b, if there

More information

NUMBER SYSTEMS. Number theory is the study of the integers. We denote the set of integers by Z:

NUMBER SYSTEMS. Number theory is the study of the integers. We denote the set of integers by Z: NUMBER SYSTEMS Number theory is the study of the integers. We denote the set of integers by Z: Z = {..., 3, 2, 1, 0, 1, 2, 3,... }. The integers have two operations defined on them, addition and multiplication,

More information

6.S897 Algebra and Computation February 27, Lecture 6

6.S897 Algebra and Computation February 27, Lecture 6 6.S897 Algebra and Computation February 7, 01 Lecture 6 Lecturer: Madhu Sudan Scribe: Mohmammad Bavarian 1 Overview Last lecture we saw how to use FFT to multiply f, g R[x] in nearly linear time. We also

More information

MATH 361: NUMBER THEORY FOURTH LECTURE

MATH 361: NUMBER THEORY FOURTH LECTURE MATH 361: NUMBER THEORY FOURTH LECTURE 1. Introduction Everybody knows that three hours after 10:00, the time is 1:00. That is, everybody is familiar with modular arithmetic, the usual arithmetic of the

More information

Part IX ( 45-47) Factorization

Part IX ( 45-47) Factorization Part IX ( 45-47) Factorization Satya Mandal University of Kansas, Lawrence KS 66045 USA January 22 45 Unique Factorization Domain (UFD) Abstract We prove evey PID is an UFD. We also prove if D is a UFD,

More information

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers ALGEBRA CHRISTIAN REMLING 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers by Z = {..., 2, 1, 0, 1,...}. Given a, b Z, we write a b if b = ac for some

More information

CHAPTER 4: EXPLORING Z

CHAPTER 4: EXPLORING Z CHAPTER 4: EXPLORING Z MATH 378, CSUSM. SPRING 2009. AITKEN 1. Introduction In this chapter we continue the study of the ring Z. We begin with absolute values. The absolute value function Z N is the identity

More information

Mathematical Foundations of Cryptography

Mathematical Foundations of Cryptography Mathematical Foundations of Cryptography Cryptography is based on mathematics In this chapter we study finite fields, the basis of the Advanced Encryption Standard (AES) and elliptical curve cryptography

More information

Chapter 14: Divisibility and factorization

Chapter 14: Divisibility and factorization Chapter 14: Divisibility and factorization Matthew Macauley Department of Mathematical Sciences Clemson University http://www.math.clemson.edu/~macaule/ Math 4120, Summer I 2014 M. Macauley (Clemson) Chapter

More information

INTEGERS. In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes.

INTEGERS. In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes. INTEGERS PETER MAYR (MATH 2001, CU BOULDER) In this section we aim to show the following: Goal. Every natural number can be written uniquely as a product of primes. 1. Divisibility Definition. Let a, b

More information

Chapter 1 : The language of mathematics.

Chapter 1 : The language of mathematics. MAT 200, Logic, Language and Proof, Fall 2015 Summary Chapter 1 : The language of mathematics. Definition. A proposition is a sentence which is either true or false. Truth table for the connective or :

More information

Definition For a set F, a polynomial over F with variable x is of the form

Definition For a set F, a polynomial over F with variable x is of the form *6. Polynomials Definition For a set F, a polynomial over F with variable x is of the form a n x n + a n 1 x n 1 + a n 2 x n 2 +... + a 1 x + a 0, where a n, a n 1,..., a 1, a 0 F. The a i, 0 i n are the

More information

4 Number Theory and Cryptography

4 Number Theory and Cryptography 4 Number Theory and Cryptography 4.1 Divisibility and Modular Arithmetic This section introduces the basics of number theory number theory is the part of mathematics involving integers and their properties.

More information

2WF15 - Discrete Mathematics 2 - Part 1. Algorithmic Number Theory

2WF15 - Discrete Mathematics 2 - Part 1. Algorithmic Number Theory 1 2WF15 - Discrete Mathematics 2 - Part 1 Algorithmic Number Theory Benne de Weger version 0.54, March 6, 2012 version 0.54, March 6, 2012 2WF15 - Discrete Mathematics 2 - Part 1 2 2WF15 - Discrete Mathematics

More information

1. Algebra 1.5. Polynomial Rings

1. Algebra 1.5. Polynomial Rings 1. ALGEBRA 19 1. Algebra 1.5. Polynomial Rings Lemma 1.5.1 Let R and S be rings with identity element. If R > 1 and S > 1, then R S contains zero divisors. Proof. The two elements (1, 0) and (0, 1) are

More information

Notes on arithmetic. 1. Representation in base B

Notes on arithmetic. 1. Representation in base B Notes on arithmetic The Babylonians that is to say, the people that inhabited what is now southern Iraq for reasons not entirely clear to us, ued base 60 in scientific calculation. This offers us an excuse

More information

The Fundamental Theorem of Arithmetic

The Fundamental Theorem of Arithmetic Chapter 1 The Fundamental Theorem of Arithmetic 1.1 Primes Definition 1.1. We say that p N is prime if it has just two factors in N, 1 and p itself. Number theory might be described as the study of the

More information

MATH FINAL EXAM REVIEW HINTS

MATH FINAL EXAM REVIEW HINTS MATH 109 - FINAL EXAM REVIEW HINTS Answer: Answer: 1. Cardinality (1) Let a < b be two real numbers and define f : (0, 1) (a, b) by f(t) = (1 t)a + tb. (a) Prove that f is a bijection. (b) Prove that any

More information

Divisibility. Chapter Divisors and Residues

Divisibility. Chapter Divisors and Residues Chapter 1 Divisibility Number theory is concerned with the properties of the integers. By the word integers we mean the counting numbers 1, 2, 3,..., together with their negatives and zero. Accordingly

More information

LECTURE NOTES IN CRYPTOGRAPHY

LECTURE NOTES IN CRYPTOGRAPHY 1 LECTURE NOTES IN CRYPTOGRAPHY Thomas Johansson 2005/2006 c Thomas Johansson 2006 2 Chapter 1 Abstract algebra and Number theory Before we start the treatment of cryptography we need to review some basic

More information

Chinese Remainder Theorem

Chinese Remainder Theorem Chinese Remainder Theorem Theorem Let R be a Euclidean domain with m 1, m 2,..., m k R. If gcd(m i, m j ) = 1 for 1 i < j k then m = m 1 m 2 m k = lcm(m 1, m 2,..., m k ) and R/m = R/m 1 R/m 2 R/m k ;

More information

Finite Fields. Mike Reiter

Finite Fields. Mike Reiter 1 Finite Fields Mike Reiter reiter@cs.unc.edu Based on Chapter 4 of: W. Stallings. Cryptography and Network Security, Principles and Practices. 3 rd Edition, 2003. Groups 2 A group G, is a set G of elements

More information

3 The fundamentals: Algorithms, the integers, and matrices

3 The fundamentals: Algorithms, the integers, and matrices 3 The fundamentals: Algorithms, the integers, and matrices 3.4 The integers and division This section introduces the basics of number theory number theory is the part of mathematics involving integers

More information

CMPUT 403: Number Theory

CMPUT 403: Number Theory CMPUT 403: Number Theory Zachary Friggstad February 26, 2016 Outline Factoring Sieve Multiplicative Functions Greatest Common Divisors Applications Chinese Remainder Theorem Factoring Theorem (Fundamental

More information

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications

cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications cse 311: foundations of computing Fall 2015 Lecture 12: Primes, GCD, applications n-bit unsigned integer representation Represent integer x as sum of powers of 2: If x = n 1 i=0 b i 2 i where each b i

More information

Factorization in Polynomial Rings

Factorization in Polynomial Rings Factorization in Polynomial Rings Throughout these notes, F denotes a field. 1 Long division with remainder We begin with some basic definitions. Definition 1.1. Let f, g F [x]. We say that f divides g,

More information

4. Number Theory (Part 2)

4. Number Theory (Part 2) 4. Number Theory (Part 2) Terence Sim Mathematics is the queen of the sciences and number theory is the queen of mathematics. Reading Sections 4.8, 5.2 5.4 of Epp. Carl Friedrich Gauss, 1777 1855 4.3.

More information

EUCLID S ALGORITHM AND THE FUNDAMENTAL THEOREM OF ARITHMETIC after N. Vasiliev and V. Gutenmacher (Kvant, 1972)

EUCLID S ALGORITHM AND THE FUNDAMENTAL THEOREM OF ARITHMETIC after N. Vasiliev and V. Gutenmacher (Kvant, 1972) Intro to Math Reasoning Grinshpan EUCLID S ALGORITHM AND THE FUNDAMENTAL THEOREM OF ARITHMETIC after N. Vasiliev and V. Gutenmacher (Kvant, 1972) We all know that every composite natural number is a product

More information

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime.

PUTNAM TRAINING NUMBER THEORY. Exercises 1. Show that the sum of two consecutive primes is never twice a prime. PUTNAM TRAINING NUMBER THEORY (Last updated: December 11, 2017) Remark. This is a list of exercises on Number Theory. Miguel A. Lerma Exercises 1. Show that the sum of two consecutive primes is never twice

More information

MATH 2400 LECTURE NOTES: POLYNOMIAL AND RATIONAL FUNCTIONS. Contents 1. Polynomial Functions 1 2. Rational Functions 6

MATH 2400 LECTURE NOTES: POLYNOMIAL AND RATIONAL FUNCTIONS. Contents 1. Polynomial Functions 1 2. Rational Functions 6 MATH 2400 LECTURE NOTES: POLYNOMIAL AND RATIONAL FUNCTIONS PETE L. CLARK Contents 1. Polynomial Functions 1 2. Rational Functions 6 1. Polynomial Functions Using the basic operations of addition, subtraction,

More information

Number Theory. Zachary Friggstad. Programming Club Meeting

Number Theory. Zachary Friggstad. Programming Club Meeting Number Theory Zachary Friggstad Programming Club Meeting Outline Factoring Sieve Multiplicative Functions Greatest Common Divisors Applications Chinese Remainder Theorem Throughout, problems to try are

More information

Lecture 7: Polynomial rings

Lecture 7: Polynomial rings Lecture 7: Polynomial rings Rajat Mittal IIT Kanpur You have seen polynomials many a times till now. The purpose of this lecture is to give a formal treatment to constructing polynomials and the rules

More information

Rings If R is a commutative ring, a zero divisor is a nonzero element x such that xy = 0 for some nonzero element y R.

Rings If R is a commutative ring, a zero divisor is a nonzero element x such that xy = 0 for some nonzero element y R. Rings 10-26-2008 A ring is an abelian group R with binary operation + ( addition ), together with a second binary operation ( multiplication ). Multiplication must be associative, and must distribute over

More information

PRACTICE PROBLEMS: SET 1

PRACTICE PROBLEMS: SET 1 PRACTICE PROBLEMS: SET MATH 437/537: PROF. DRAGOS GHIOCA. Problems Problem. Let a, b N. Show that if gcd(a, b) = lcm[a, b], then a = b. Problem. Let n, k N with n. Prove that (n ) (n k ) if and only if

More information

a + bi by sending α = a + bi to a 2 + b 2. To see properties (1) and (2), it helps to think of complex numbers in polar coordinates:

a + bi by sending α = a + bi to a 2 + b 2. To see properties (1) and (2), it helps to think of complex numbers in polar coordinates: 5. Types of domains It turns out that in number theory the fact that certain rings have unique factorisation has very strong arithmetic consequences. We first write down some definitions. Definition 5.1.

More information

1/30: Polynomials over Z/n.

1/30: Polynomials over Z/n. 1/30: Polynomials over Z/n. Last time to establish the existence of primitive roots we rely on the following key lemma: Lemma 6.1. Let s > 0 be an integer with s p 1, then we have #{α Z/pZ α s = 1} = s.

More information

PRIME NUMBERS YANKI LEKILI

PRIME NUMBERS YANKI LEKILI PRIME NUMBERS YANKI LEKILI We denote by N the set of natural numbers: 1,2,..., These are constructed using Peano axioms. We will not get into the philosophical questions related to this and simply assume

More information

Lecture 7.5: Euclidean domains and algebraic integers

Lecture 7.5: Euclidean domains and algebraic integers Lecture 7.5: Euclidean domains and algebraic integers Matthew Macauley Department of Mathematical Sciences Clemson University http://www.math.clemson.edu/~macaule/ Math 4120, Modern Algebra M. Macauley

More information

8 Primes and Modular Arithmetic

8 Primes and Modular Arithmetic 8 Primes and Modular Arithmetic 8.1 Primes and Factors Over two millennia ago already, people all over the world were considering the properties of numbers. One of the simplest concepts is prime numbers.

More information

The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem.

The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem. CS 70 Discrete Mathematics for CS Fall 2003 Wagner Lecture 10 The next sequence of lectures in on the topic of Arithmetic Algorithms. We shall build up to an understanding of the RSA public-key cryptosystem.

More information

1. Factorization Divisibility in Z.

1. Factorization Divisibility in Z. 8 J. E. CREMONA 1.1. Divisibility in Z. 1. Factorization Definition 1.1.1. Let a, b Z. Then we say that a divides b and write a b if b = ac for some c Z: a b c Z : b = ac. Alternatively, we may say that

More information

Algebra for error control codes

Algebra for error control codes Algebra for error control codes EE 387, Notes 5, Handout #7 EE 387 concentrates on block codes that are linear: Codewords components are linear combinations of message symbols. g 11 g 12 g 1n g 21 g 22

More information

CYCLICITY OF (Z/(p))

CYCLICITY OF (Z/(p)) CYCLICITY OF (Z/(p)) KEITH CONRAD 1. Introduction For each prime p, the group (Z/(p)) is cyclic. We will give seven proofs of this fundamental result. A common feature of the proofs that (Z/(p)) is cyclic

More information

Number theory (Chapter 4)

Number theory (Chapter 4) EECS 203 Spring 2016 Lecture 10 Page 1 of 8 Number theory (Chapter 4) Review Questions: 1. Does 5 1? Does 1 5? 2. Does (129+63) mod 10 = (129 mod 10)+(63 mod 10)? 3. Does (129+63) mod 10 = ((129 mod 10)+(63

More information

CSE 311: Foundations of Computing. Lecture 12: Two s Complement, Primes, GCD

CSE 311: Foundations of Computing. Lecture 12: Two s Complement, Primes, GCD CSE 311: Foundations of Computing Lecture 12: Two s Complement, Primes, GCD n-bit Unsigned Integer Representation Represent integer as sum of powers of 2: If 2 where each {0,1} then representation is b

More information

Discrete Mathematics CS October 17, 2006

Discrete Mathematics CS October 17, 2006 Discrete Mathematics CS 2610 October 17, 2006 Uncountable sets Theorem: The set of real numbers is uncountable. If a subset of a set is uncountable, then the set is uncountable. The cardinality of a subset

More information

2a 2 4ac), provided there is an element r in our

2a 2 4ac), provided there is an element r in our MTH 310002 Test II Review Spring 2012 Absractions versus examples The purpose of abstraction is to reduce ideas to their essentials, uncluttered by the details of a specific situation Our lectures built

More information

9. Integral Ring Extensions

9. Integral Ring Extensions 80 Andreas Gathmann 9. Integral ing Extensions In this chapter we want to discuss a concept in commutative algebra that has its original motivation in algebra, but turns out to have surprisingly many applications

More information

Further linear algebra. Chapter II. Polynomials.

Further linear algebra. Chapter II. Polynomials. Further linear algebra. Chapter II. Polynomials. Andrei Yafaev 1 Definitions. In this chapter we consider a field k. Recall that examples of felds include Q, R, C, F p where p is prime. A polynomial is

More information

CPSC 467: Cryptography and Computer Security

CPSC 467: Cryptography and Computer Security CPSC 467: Cryptography and Computer Security Michael J. Fischer Lecture 9 September 30, 2015 CPSC 467, Lecture 9 1/47 Fast Exponentiation Algorithms Number Theory Needed for RSA Elementary Number Theory

More information

Direct Proof MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Direct Proof Fall / 24

Direct Proof MAT231. Fall Transition to Higher Mathematics. MAT231 (Transition to Higher Math) Direct Proof Fall / 24 Direct Proof MAT231 Transition to Higher Mathematics Fall 2014 MAT231 (Transition to Higher Math) Direct Proof Fall 2014 1 / 24 Outline 1 Overview of Proof 2 Theorems 3 Definitions 4 Direct Proof 5 Using

More information

= 1 2x. x 2 a ) 0 (mod p n ), (x 2 + 2a + a2. x a ) 2

= 1 2x. x 2 a ) 0 (mod p n ), (x 2 + 2a + a2. x a ) 2 8. p-adic numbers 8.1. Motivation: Solving x 2 a (mod p n ). Take an odd prime p, and ( an) integer a coprime to p. Then, as we know, x 2 a (mod p) has a solution x Z iff = 1. In this case we can suppose

More information

0 Sets and Induction. Sets

0 Sets and Induction. Sets 0 Sets and Induction Sets A set is an unordered collection of objects, called elements or members of the set. A set is said to contain its elements. We write a A to denote that a is an element of the set

More information

Basic elements of number theory

Basic elements of number theory Cryptography Basic elements of number theory Marius Zimand 1 Divisibility, prime numbers By default all the variables, such as a, b, k, etc., denote integer numbers. Divisibility a 0 divides b if b = a

More information

Basic elements of number theory

Basic elements of number theory Cryptography Basic elements of number theory Marius Zimand By default all the variables, such as a, b, k, etc., denote integer numbers. Divisibility a 0 divides b if b = a k for some integer k. Notation

More information

Places of Number Fields and Function Fields MATH 681, Spring 2018

Places of Number Fields and Function Fields MATH 681, Spring 2018 Places of Number Fields and Function Fields MATH 681, Spring 2018 From now on we will denote the field Z/pZ for a prime p more compactly by F p. More generally, for q a power of a prime p, F q will denote

More information

Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald)

Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald) Lecture notes: Algorithms for integers, polynomials (Thorsten Theobald) 1 Euclid s Algorithm Euclid s Algorithm for computing the greatest common divisor belongs to the oldest known computing procedures

More information

NOTES ON FINITE FIELDS

NOTES ON FINITE FIELDS NOTES ON FINITE FIELDS AARON LANDESMAN CONTENTS 1. Introduction to finite fields 2 2. Definition and constructions of fields 3 2.1. The definition of a field 3 2.2. Constructing field extensions by adjoining

More information

Some Facts from Number Theory

Some Facts from Number Theory Computer Science 52 Some Facts from Number Theory Fall Semester, 2014 These notes are adapted from a document that was prepared for a different course several years ago. They may be helpful as a summary

More information

COT 3100 Applications of Discrete Structures Dr. Michael P. Frank

COT 3100 Applications of Discrete Structures Dr. Michael P. Frank University of Florida Dept. of Computer & Information Science & Engineering COT 3100 Applications of Discrete Structures Dr. Michael P. Frank Slides for a Course Based on the Text Discrete Mathematics

More information

(Rgs) Rings Math 683L (Summer 2003)

(Rgs) Rings Math 683L (Summer 2003) (Rgs) Rings Math 683L (Summer 2003) We will first summarise the general results that we will need from the theory of rings. A unital ring, R, is a set equipped with two binary operations + and such that

More information

4 Powers of an Element; Cyclic Groups

4 Powers of an Element; Cyclic Groups 4 Powers of an Element; Cyclic Groups Notation When considering an abstract group (G, ), we will often simplify notation as follows x y will be expressed as xy (x y) z will be expressed as xyz x (y z)

More information

Computational Complexity - Pseudocode and Recursions

Computational Complexity - Pseudocode and Recursions Computational Complexity - Pseudocode and Recursions Nicholas Mainardi 1 Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it June 6, 2018 1 Partly Based on Alessandro

More information

Modular Arithmetic and Elementary Algebra

Modular Arithmetic and Elementary Algebra 18.310 lecture notes September 2, 2013 Modular Arithmetic and Elementary Algebra Lecturer: Michel Goemans These notes cover basic notions in algebra which will be needed for discussing several topics of

More information

THE DIVISION THEOREM IN Z AND R[T ]

THE DIVISION THEOREM IN Z AND R[T ] THE DIVISION THEOREM IN Z AND R[T ] KEITH CONRAD 1. Introduction In both Z and R[T ], we can carry out a process of division with remainder. Theorem 1.1. For any integers a and b, with b nonzero, there

More information

Elementary Algebra Chinese Remainder Theorem Euclidean Algorithm

Elementary Algebra Chinese Remainder Theorem Euclidean Algorithm Elementary Algebra Chinese Remainder Theorem Euclidean Algorithm April 11, 2010 1 Algebra We start by discussing algebraic structures and their properties. This is presented in more depth than what we

More information

CHAPTER 6. Prime Numbers. Definition and Fundamental Results

CHAPTER 6. Prime Numbers. Definition and Fundamental Results CHAPTER 6 Prime Numbers Part VI of PJE. Definition and Fundamental Results 6.1. Definition. (PJE definition 23.1.1) An integer p is prime if p > 1 and the only positive divisors of p are 1 and p. If n

More information

Groups, Rings, and Finite Fields. Andreas Klappenecker. September 12, 2002

Groups, Rings, and Finite Fields. Andreas Klappenecker. September 12, 2002 Background on Groups, Rings, and Finite Fields Andreas Klappenecker September 12, 2002 A thorough understanding of the Agrawal, Kayal, and Saxena primality test requires some tools from algebra and elementary

More information

CDM. Recurrences and Fibonacci

CDM. Recurrences and Fibonacci CDM Recurrences and Fibonacci Klaus Sutner Carnegie Mellon University 20-fibonacci 2017/12/15 23:16 1 Recurrence Equations Second Order The Fibonacci Monoid Recurrence Equations 3 We can define a sequence

More information

Honors Algebra 4, MATH 371 Winter 2010 Assignment 3 Due Friday, February 5 at 08:35

Honors Algebra 4, MATH 371 Winter 2010 Assignment 3 Due Friday, February 5 at 08:35 Honors Algebra 4, MATH 371 Winter 2010 Assignment 3 Due Friday, February 5 at 08:35 1. Let R 0 be a commutative ring with 1 and let S R be the subset of nonzero elements which are not zero divisors. (a)

More information

CS 5319 Advanced Discrete Structure. Lecture 9: Introduction to Number Theory II

CS 5319 Advanced Discrete Structure. Lecture 9: Introduction to Number Theory II CS 5319 Advanced Discrete Structure Lecture 9: Introduction to Number Theory II Divisibility Outline Greatest Common Divisor Fundamental Theorem of Arithmetic Modular Arithmetic Euler Phi Function RSA

More information

Module 1. Integers, Induction, and Recurrences

Module 1. Integers, Induction, and Recurrences Module 1. Integers, Induction, and Recurrences This module will look at The integers and the natural numbers. Division and divisors, greatest common divisors Methods of reasoning including proof by contradiction

More information

Applied Cryptography and Computer Security CSE 664 Spring 2017

Applied Cryptography and Computer Security CSE 664 Spring 2017 Applied Cryptography and Computer Security Lecture 11: Introduction to Number Theory Department of Computer Science and Engineering University at Buffalo 1 Lecture Outline What we ve covered so far: symmetric

More information

FILTERED RINGS AND MODULES. GRADINGS AND COMPLETIONS.

FILTERED RINGS AND MODULES. GRADINGS AND COMPLETIONS. FILTERED RINGS AND MODULES. GRADINGS AND COMPLETIONS. Let A be a ring, for simplicity assumed commutative. A filtering, or filtration, of an A module M means a descending sequence of submodules M = M 0

More information

Olympiad Number Theory Through Challenging Problems

Olympiad Number Theory Through Challenging Problems Olympiad Number Theory Justin Stevens Page 1 Olympiad Number Theory Through Challenging Problems Authors Justin Stevens Editor and L A TEX Manager David Altizio Dedicated to my sister. Justin Contents

More information

Discrete valuation rings. Suppose F is a field. A discrete valuation on F is a function v : F {0} Z such that:

Discrete valuation rings. Suppose F is a field. A discrete valuation on F is a function v : F {0} Z such that: Discrete valuation rings Suppose F is a field. A discrete valuation on F is a function v : F {0} Z such that: 1. v is surjective. 2. v(ab) = v(a) + v(b). 3. v(a + b) min(v(a), v(b)) if a + b 0. Proposition:

More information

Elementary Properties of the Integers

Elementary Properties of the Integers Elementary Properties of the Integers 1 1. Basis Representation Theorem (Thm 1-3) 2. Euclid s Division Lemma (Thm 2-1) 3. Greatest Common Divisor 4. Properties of Prime Numbers 5. Fundamental Theorem of

More information

MATH 501 Discrete Mathematics. Lecture 6: Number theory. German University Cairo, Department of Media Engineering and Technology.

MATH 501 Discrete Mathematics. Lecture 6: Number theory. German University Cairo, Department of Media Engineering and Technology. MATH 501 Discrete Mathematics Lecture 6: Number theory Prof. Dr. Slim Abdennadher, slim.abdennadher@guc.edu.eg German University Cairo, Department of Media Engineering and Technology 1 Number theory Number

More information

Math 120 HW 9 Solutions

Math 120 HW 9 Solutions Math 120 HW 9 Solutions June 8, 2018 Question 1 Write down a ring homomorphism (no proof required) f from R = Z[ 11] = {a + b 11 a, b Z} to S = Z/35Z. The main difficulty is to find an element x Z/35Z

More information

a = a i 2 i a = All such series are automatically convergent with respect to the standard norm, but note that this representation is not unique: i<0

a = a i 2 i a = All such series are automatically convergent with respect to the standard norm, but note that this representation is not unique: i<0 p-adic Numbers K. Sutner v0.4 1 Modular Arithmetic rings integral domains integers gcd, extended Euclidean algorithm factorization modular numbers add Lemma 1.1 (Chinese Remainder Theorem) Let a b. Then

More information

Chapter 4. Greatest common divisors of polynomials. 4.1 Polynomial remainder sequences

Chapter 4. Greatest common divisors of polynomials. 4.1 Polynomial remainder sequences Chapter 4 Greatest common divisors of polynomials 4.1 Polynomial remainder sequences If K is a field, then K[x] is a Euclidean domain, so gcd(f, g) for f, g K[x] can be computed by the Euclidean algorithm.

More information

Chapter 3. Rings. The basic commutative rings in mathematics are the integers Z, the. Examples

Chapter 3. Rings. The basic commutative rings in mathematics are the integers Z, the. Examples Chapter 3 Rings Rings are additive abelian groups with a second operation called multiplication. The connection between the two operations is provided by the distributive law. Assuming the results of Chapter

More information

The Euclidean Algorithm and Multiplicative Inverses

The Euclidean Algorithm and Multiplicative Inverses 1 The Euclidean Algorithm and Multiplicative Inverses Lecture notes for Access 2009 The Euclidean Algorithm is a set of instructions for finding the greatest common divisor of any two positive integers.

More information

CDM. Recurrences and Fibonacci. 20-fibonacci 2017/12/15 23:16. Terminology 4. Recurrence Equations 3. Solution and Asymptotics 6.

CDM. Recurrences and Fibonacci. 20-fibonacci 2017/12/15 23:16. Terminology 4. Recurrence Equations 3. Solution and Asymptotics 6. CDM Recurrences and Fibonacci 1 Recurrence Equations Klaus Sutner Carnegie Mellon University Second Order 20-fibonacci 2017/12/15 23:16 The Fibonacci Monoid Recurrence Equations 3 Terminology 4 We can

More information