This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 70 Discrete Mathematics and Probability Theory Fall 2010 Tse/Wagner Note 5 Modular Arithmetic One way to think of modular arithmetic is that it limits numbers to a predefined range { , 1 ,..., m 1 } , and wraps around whenever you try to leave this range like the hand of a clock (where m = 12) or the days of the week (where m = 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 errorcorrecting codes and cryptography, as we shall see later. To define things more formally, for any integer m (such as 7) we say that 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 ) . When we write 29 5 ( mod 12 ) we use instead of = to remind us that this is not the ordinary equality, and ( mod 12 ) to indicate that we are ignoring multiples of 12. An equivalent definition is to say that x and y are congruent modulo m (written x y ( mod m ) ) iff 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. We will also use mod ( x , m ) to denote the function that, given integers x and m 1, returns the remainder of x modulo m . So for example, mod ( 23 , 7 ) = 2. When computing modulo m , it is often convenient to reduce any intermediate results mod m to simplify the calculation, as we did in the example above. This is justified by the following claim: Theorem 5.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
 Fall '11
 Rau

Click to edit the document details