modular - CS 70 Discrete Mathematics for CS Fall 2006...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 70 Discrete Mathematics for CS Fall 2006 Papadimitriou & Vazirani Notes 7 Modular Arithmetic One way to think of modular arithmetic is that it limits numbers to a predefined range { , 1 ,..., N- 1 } , and wraps around whenever you try to leave this range — like the hand of a clock (where N = 12) or the days of the week (where N = 7). Example: Calculating the day of the week. Suppose that you have mapped the sequence of days of the week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) to the sequence of numbers ( , 1 , 2 , 3 , 4 , 5 , 6 ) so that Sunday is 0, Monday is 1, etc. Suppose that today is Thursday (=4), and you want to calculate what day of the week will be 10 days from now. Intuitively, the answer is the remainder of 4 + 10 = 14 when divided by 7, that is, 0 —Sunday. In fact, it makes little sense to add a number like 10 in this context, you should probably find its remainder modulo 7, namely 3, and then add this to 4, to find 7, which is 0. What if we want to continue this in 10 day jumps? After 5 such jumps, we would have day 4 + 3 · 5 = 19 , which gives 5 modulo 7 (Friday). This example shows that in certain circumstances it makes sense to do arithmetic within the confines of a particular number (7 in this example), that is, to do arithmetic by always finding the remainder of each number modulo 7, say, and repeating this for the results, and so on. As well as being efficient in the sense of keeping intermediate values as small as possible, this actually has several important applications, including error-correcting codes and cryptography, as we shall see later. More formally, x and y are congruent modulo m if they differ by a multiple of m , or in symbols, x ≡ y ( mod m ) ⇔ m divides ( x- y ) For example, 29 ≡ 5 mod 12 because 29- 5 is a multiple of 12. We can also write 22 ≡ - 2 mod 12. One way to think about arithmetic modulo m is that it limits the numbers used to the range { , 1 ,..., m- 1 } . Thus while working modulo 12, as on a clock, we wrap around to 0 every time we reach 12. Or in other words, we just retain the remainder when we divide the number under consideration by 12. The second way is a little more sophisticated. If m is an integer (such as 7), define the following relation between integers: x and y are called congruent modulo m , written x = y mod m , iff they differ by a multiple of m — that is, x- y = k · m for some integer k (possibly negative). To put it otherwise, x and y are congruent modulo m if they have the same remainder modulo m . Notice that “congruent modulo m ” is an equivalence relation : it partitions the integers into m equivalence classes 0 , 1 , 2 ,..., m- 1. While computing modulo m , it is often convenient to reduce any intermediate results mod m to simplify the calculation. This is justified by the following claim: Theorem 7.1 : If a = c mod m and b = d mod m, then a + b = c + d mod m and a · b = c · d mod m....
View Full Document

{[ snackBarMessage ]}

Page1 / 5

modular - CS 70 Discrete Mathematics for CS Fall 2006...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online