CMPSCI 250: Introduction to Computation. Lecture #14: The Chinese Remainder Theorem David Mix Barrington 4 October 2013

Similar documents
CMPSCI 250: Introduction to Computation. Lecture #14: The Chinese Remainder Theorem David Mix Barrington 24 February 2012

The congruence relation has many similarities to equality. The following theorem says that congruence, like equality, is an equivalence relation.

6. Find an inverse of a modulo m for each of these pairs of relatively prime integers using the method

Calculators will not be permitted on the exam. The numbers on the exam will be suitable for calculating by hand.

1.6 Congruence Modulo m

Fermat s little theorem. RSA.

Modular arithmetic Math 2320

Applications of Fermat s Little Theorem and Congruences

Congruence. Solving linear congruences. A linear congruence is an expression in the form. ax b (modm)

Distribution of Primes

University of British Columbia. Math 312, Midterm, 6th of June 2017

Math 255 Spring 2017 Solving x 2 a (mod n)

Number Theory/Cryptography (part 1 of CSC 282)

Modular Arithmetic. claserken. July 2016

b) Find all positive integers smaller than 200 which leave remainder 1, 3, 4 upon division by 3, 5, 7 respectively.

Solutions for the Practice Questions

Solutions to Problem Set 6 - Fall 2008 Due Tuesday, Oct. 21 at 1:00

Number Theory. Konkreetne Matemaatika

Number Theory - Divisibility Number Theory - Congruences. Number Theory. June 23, Number Theory

Assignment 2. Due: Monday Oct. 15, :59pm

Solutions for the 2nd Practice Midterm

Wilson s Theorem and Fermat s Theorem

SOLUTIONS FOR PROBLEM SET 4

Introduction. and Z r1 Z rn. This lecture aims to provide techniques. CRT during the decription process in RSA is explained.

SOLUTIONS TO PROBLEM SET 5. Section 9.1

Math 127: Equivalence Relations

NUMBER THEORY AMIN WITNO

The Chinese Remainder Theorem

Modular Arithmetic. Kieran Cooney - February 18, 2016

MODULAR ARITHMETIC II: CONGRUENCES AND DIVISION

Discrete Math Class 4 ( )

Collection of rules, techniques and theorems for solving polynomial congruences 11 April 2012 at 22:02

Linear Congruences. The solutions to a linear congruence ax b (mod m) are all integers x that satisfy the congruence.

Primitive Roots. Chapter Orders and Primitive Roots

Lecture 8. Outline. 1. Modular Arithmetic. Clock Math!!! 2. Inverses for Modular Arithmetic: Greatest Common Divisor. 3. Euclid s GCD Algorithm

LECTURE 3: CONGRUENCES. 1. Basic properties of congruences We begin by introducing some definitions and elementary properties.

LECTURE 7: POLYNOMIAL CONGRUENCES TO PRIME POWER MODULI

Numbers (8A) Young Won Lim 6/21/17

Numbers (8A) Young Won Lim 5/24/17

Numbers (8A) Young Won Lim 5/22/17

Example Enemy agents are trying to invent a new type of cipher. They decide on the following encryption scheme: Plaintext converts to Ciphertext

Solutions for the Practice Final

Math 412: Number Theory Lecture 6: congruence system and

The Chinese Remainder Theorem

MAT Modular arithmetic and number theory. Modular arithmetic

CHAPTER 2. Modular Arithmetic

6.2 Modular Arithmetic

Data security (Cryptography) exercise book

Sheet 1: Introduction to prime numbers.

Grade 6/7/8 Math Circles April 1/2, Modular Arithmetic

Calculators will not be permitted on the exam. The numbers on the exam will be suitable for calculating by hand.

Constructions of Coverings of the Integers: Exploring an Erdős Problem

ON MODULI FOR WHICH THE FIBONACCI SEQUENCE CONTAINS A COMPLETE SYSTEM OF RESIDUES S. A. BURR Belt Telephone Laboratories, Inc., Whippany, New Jersey

Modular Arithmetic and Doomsday

The Chinese Remainder Theorem

ALGEBRA: Chapter I: QUESTION BANK

Discrete Mathematics & Mathematical Reasoning Multiplicative Inverses and Some Cryptography

Carmen s Core Concepts (Math 135)

An elementary study of Goldbach Conjecture

Cryptography. 2. decoding is extremely difficult (for protection against eavesdroppers);

Example Enemy agents are trying to invent a new type of cipher. They decide on the following encryption scheme: Plaintext converts to Ciphertext

To be able to determine the quadratic character of an arbitrary number mod p (p an odd prime), we. The first (and most delicate) case concerns 2

Discrete Square Root. Çetin Kaya Koç Winter / 11

Mark Kozek. December 7, 2010

A Quick Introduction to Modular Arithmetic

p 1 MAX(a,b) + MIN(a,b) = a+b n m means that m is a an integer multiple of n. Greatest Common Divisor: We say that n divides m.

Number-Theoretic Algorithms

Modular Arithmetic: refresher.

Exam 1 7 = = 49 2 ( ) = = 7 ( ) =

by Michael Filaseta University of South Carolina

LUCAS-SIERPIŃSKI AND LUCAS-RIESEL NUMBERS

Mathematics Explorers Club Fall 2012 Number Theory and Cryptography

Algorithmic Number Theory and Cryptography (CS 303)

12. Let Rm = {0,1,2,..., m 1} be a complete residue system modulo ra. Let a be an integer. When is a Rm = {0,1 a, 2 a,...

Goldbach Conjecture (7 th june 1742)

Groups, Modular Arithmetic and Geometry

Introduction to Modular Arithmetic

1 = 3 2 = 3 ( ) = = = 33( ) 98 = = =

Lecture 32. Handout or Document Camera or Class Exercise. Which of the following is equal to [53] [5] 1 in Z 7? (Do not use a calculator.

Outline Introduction Big Problems that Brun s Sieve Attacks Conclusions. Brun s Sieve. Joe Fields. November 8, 2007

ELEMENTS OF NUMBER THEORY & CONGRUENCES. Lagrange, Legendre and Gauss. Mth Mathematicst

An interesting class of problems of a computational nature ask for the standard residue of a power of a number, e.g.,

Practice Midterm 2 Solutions

DUBLIN CITY UNIVERSITY

Power = 36² mod 99 Power = 9 5 a 5 = 0 x = 81 Power = 9² mod 99 Power = 81 6 a 6 = 1 x = 81 x 81 mod 99 x = 27 7 a 7 = 1 x = 27 x 27 mod 99 x = 36

MA/CSSE 473 Day 9. The algorithm (modified) N 1

Number Theory and Security in the Digital Age

Cryptography Math 1580 Silverman First Hour Exam Mon Oct 2, 2017

Public Key Encryption

Overview. The Big Picture... CSC 580 Cryptography and Computer Security. January 25, Math Basics for Cryptography

Cryptography, Number Theory, and RSA

Two congruences involving 4-cores

SESAME Modular Arithmetic. MurphyKate Montee. March 2018 IN,Z, We think numbers should satisfy certain rules, which we call axioms:

Solutions to Exercises Chapter 6: Latin squares and SDRs

MATH 324 Elementary Number Theory Solutions to Practice Problems for Final Examination Monday August 8, 2005

#A3 INTEGERS 17 (2017) A NEW CONSTRAINT ON PERFECT CUBOIDS. Thomas A. Plick

Diffie-Hellman key-exchange protocol

Goldbach conjecture (1742, june, the 7 th )

MAT199: Math Alive Cryptography Part 2

Solutions to Exam 1. Problem 1. a) State Fermat s Little Theorem and Euler s Theorem. b) Let m, n be relatively prime positive integers.

Transcription:

CMPSCI 250: Introduction to Computation Lecture #14: The Chinese Remainder Theorem David Mix Barrington 4 October 2013

The Chinese Remainder Theorem Infinitely Many Primes Reviewing Inverses and the Inverse Theorem Systems of Congruences, Examples The Simple (Two Modulus) Version Proving the Simple Version The Full (Many Modulus) Version Working With Really Big Numbers

Infinitely Many Primes There is one argument I want to squeeze in at least briefly, although its section (3.4) is not on the syllabus. How do we know that there are always more prime numbers, no matter how high in the naturals we look? We now know enough to prove this, as did the ancient Greeks. Let z be arbitrary -- we will prove that there exists a prime number greater than z. The factorial of z, written z!, is the product of all the numbers from 1 through z (so for example 7! = 1 2 3 4 5 6 7 = 5040).

Infinitely Many Primes Look at the number z! + 1. It is not divisible by any number k in the range from 2 through z, because k must divide z! and thus z! + 1 1 (mod k). But z! + 1 must have a prime factorization because every positive natural does. It is either prime itself or is divisible by some smaller prime, and that prime cannot be less than or equal to z. So we know that some prime greater than z must exist, though we haven t explicitly computed it.

Clicker Question #1 If we let z = 5 in the previous argument, we compute that 5! + 1 = 1 2 3 4 5 + 1 = 121. Which of these conclusions is false? (a) 121 is divisible by some prime greater than 5. (b) There exists a prime greater than 5. (c) If x is a natural and 2 x 5, then 121 is congruent to 1 modulo x. (d) 121 is a prime that is greater than 5.

Answer #1 If we let z = 5 in the previous argument, we compute that 5! + 1 = 1 2 3 4 5 + 1 = 121. Which of these conclusions is false? (a) 121 is divisible by some prime greater than 5. (b) There exists a prime greater than 5. (c) If x is a natural and 2 x 5, then 121 is congruent to 1 modulo x. (d) 121 is a prime that is greater than 5.

Reviewing Inverses We have been working with arithmetic where the numbers are congruence classes modulo m. A class [x] (the set {n: n x}) has a multiplicative inverse if there is another class [y] such that [x][y] = [1], or xy 1 (mod m). The Inverse Theorem says that a number z has a multiplicative inverse modulo m if and only if z and m are relatively prime, or gcd(z, m) = 1.

The Inverse Algorithm It s fairly clear that if z and m have a common factor g > 1, then a multiplicative inverse for z modulo m is impossible. The Euclidean Algorithm is our method to compute gcd s and thus test for relative primality. The Extended Euclidean Algorithm takes z and m as inputs and uses the arithmetic from the Euclidean Algorithm, but gets an additional result at each step.

The Inverse Algorithm We write each number that occurs as an integer linear combination of z and m. If z and m are relatively prime, we compute numbers a and b such that az + bm = 1. Then a is an inverse of z modulo m and b is an inverse of m modulo z. 119 % 65 = 54 65 % 54 = 11 54 % 11 = 10 11 % 10 = 1 10 % 1 = 0 119 = 1 65 + 54 65 = 1 54 + 11 54 = 4 11 + 10 11 = 1 10 + 1 10 = 10 1 + 0 119 = 1 119 + 0 65 65 = 0 119 + 1 65 54 = 1 119-1 65 11 = -1 119 + 2 65 10 = 5 119-9 65 1 = -6 119 + 11 65

Systems of Congruences Modular arithmetic was invented to deal with periodic processes. We ve seen how to work with multiple congruences that have the same period -- for example, we know that if a b (mod m) and c d (mod m), then ac bd (mod m). But we sometimes have interacting periodic processes with different moduli. For example, days of the week have period 7. Suppose you have to take a pill every five days. How often do you take a pill on a Wednesday? Every 35 days, as it turns out.

Systems of Congruences A mod-5 process and a mod-7 process interact to give a mod-35 process, and something similar happens whenever the moduli are relatively prime. If two moduli are not relatively prime, the two congruences may not have any common solution -- consider x 1 (mod 4) and x 4 (mod 6).

Examples of Congruence Systems Suppose we have around a thousand soldiers marching along the road and we would like to know exactly how many there are. We tell them to line up in rows of 7 and determine how many are left over. Then we do the same for rows of 8, then again for rows of 9. The full form of the Chinese Remainder Theorem lets us use these three remainders to find the number of soldiers modulo 7 8 9 = 504. It might say, for example, that the number is either 806 or 1310, and then we can tell which.

Examples of Congruence Systems The pseudoscientific (i.e. wrong ) theory of biorhythms says that a person has three cycles started at birth, of 23, 28, and 33 days. According to the full form of the Chinese Remainder Theorem, a person would be at the initial position of all three cycles again exactly 23 28 33 = 21252 days, or about 58.2 years, after birth.

The Simple (Two-Modulus) Version How can we find a common solution to the two congruences x a (mod m) and x b (mod n)? The Simple Version of the Chinese Remainder Theorem says that if m and n are relatively prime, this pair of congruences is equivalent to the single congruence x c (mod mn), where c is a number that we can calculate from a, b, m, and n.

Clicker Question #2 Suppose that x is a natural satisfying the congruences x 5 (mod 9) and x 2 (mod 15). What does the Chinese Remainder Theorem tell us? (a) x 32 (mod 45) (b) It tells us nothing, because 9 and 15 are not relatively prime. (c) There can be no such x, because 9 and 15 are not relatively prime. (d) x 2 (mod 3)

Answer #2 Suppose that x is a natural satisfying the congruences x 5 (mod 9) and x 2 (mod 15). What does the Chinese Remainder Theorem tell us? (a) x 32 (mod 45) (b) It tells us nothing, because 9 and 15 are not relatively prime. (c) There can be no such x, because 9 and 15 are not relatively prime. (d) x 2 (mod 3)

The Simple Version Note first that if x is a solution to the two congruences, so is any y that satisfies x y (mod mn). This is because in this case y = x + kmn for some integer k. When we divide y by m, for example, we get the remainder for x plus the remainder for kmn, and the latter is 0 because m divides kmn. We need a c that gives us a solution to both congruences, and we must show that any solution x to both congruences must satisfy x c (mod mn).

Proving the Simple Version Since m and n are assumed to be relatively prime, the Inverse Algorithm gives us integers y and z such that ym + zn = 1. Our number c will be bym + azn. Let s verify that this works. When we divide bym + azn by m, the first term gives remainder 0 and the second gives [azn] = [a] [zn] = [a][1] = [a].

Proving the Simple Version Dividing bym + azn by n, the first term gives [b][ym] = [b][1] = [b], and the second term gives 0. A good way to think of this is that the original equation ym + zn = 1 tells us how to get a number whose remainders are 1 (mod m) and 1(mod n). To get arbitrary a and b we can adjust either term without affecting the remainder for the other modulus.

Proving the Simple Version Let x be any solution to x a (mod m) and x b (mod n), and let d be x - c. Then d is divisible by both m and n. Use the Euclidean Algorithm to find the gcd of d and mn (or -d and mn, if d is negative) -- call this q. But q is a common multiple of m and n, and the least common multiple of two relatively prime numbers is their product.

The Full (Many-Modulus) Version More generally, as in our examples, suppose we have several congruences x = a1 (mod m1), x = a2 (mod m2),... x = ak (mod mk), and that the moduli are pairwise relatively prime. (This means that any two of them are relatively prime to each other.) Then the Full Form of the Chinese Remainder Theorem says that this system of congruences is equivalent to a single congruence x c (mod M).

Clicker Question #3 Suppose that x is a natural satisfying x 1 (mod 3), x 2 (mod 4), and x 3 (mod 5). What conclusion can we draw from the Chinese Remainder Theorem? (a) None, because 3, 4, and 5 are not pairwise relatively prime. (b) x 6 (mod 60) (c) x 58 (mod 60) (d) x 43 (mod 60)

Answer #3 Suppose that x is a natural satisfying x 1 (mod 3), x 2 (mod 4), and x 3 (mod 5). What conclusion can we draw from the Chinese Remainder Theorem? (a) None, because 3, 4, and 5 are not pairwise relatively prime. (b) x 6 (mod 60) (c) x 58 (mod 60) (d) x 43 (mod 60)

The Full Version Specifically, M is the product of the mi s and c is a number that can be calculated from the ai s and the mi s. We can prove the Full Version from the Simple Version. If k = 3, for example, we first use the Simple Version to find a c such that the first two congruences are equivalent to x c (mod m1m2). Then we have two congruences, that and x a3 (mod m3).

The Full Version We now just use the Simple Version again to get a common solution to these two congruences. (The pairwise relatively prime property guarantees that m1m2 will be relatively prime to m3.) This clearly extends to larger k. In the book, it is shown how we can calculate the single c directly.

Working With Very Big Numbers If I have some very very big integers, each too big to store in a single computer word, the Chinese Remainder Theorem gives me an alternate way to calculate with them. Say I want to multiply n of these numbers together. I pick a bunch of different prime numbers, so many that their product is bigger than the product of my big numbers.

Working With Very Big Numbers How do we know that such primes exist? A more sophisticated analysis shows that there are lots of primes that fit in a single machine word, so I can get to very very big numbers by multiplying them together.) I then find the remainder of each big number modulo each prime.

Working With Very Big Numbers If I multiply together all the remainders for a given prime p, and take the result modulo p, I have my product s remainder modulo p. And this can be done with calculations on reasonably-sized numbers, because I can do this in parallel for each prime. Then running the Chinese Remainder calculation once, I can get my product in the regular notation.