The Chinese Remainder Theorem

Similar documents
Computing Quotient and Remainder. Prime Numbers. Factoring by Trial Division. The Fundamental Theorem of Arithmetic

MATH 25 CLASS 12 NOTES, OCT Contents 1. Simultaneous linear congruences 1 2. Simultaneous linear congruences 2

Primitive Roots and Discrete Logarithms

4.4 Solving Congruences using Inverses

Notes on Systems of Linear Congruences

CHAPTER 3. Congruences. Congruence: definitions and properties

The security of RSA (part 1) The security of RSA (part 1)

Math From Scratch Lesson 20: The Chinese Remainder Theorem

MATH 433 Applied Algebra Lecture 4: Modular arithmetic (continued). Linear congruences.

Generalized Splines. Madeline Handschy, Julie Melnick, Stephanie Reinders. Smith College. April 1, 2013

Chinese Remainder Theorem

ax b mod m. has a solution if and only if d b. In this case, there is one solution, call it x 0, to the equation and there are d solutions x m d

Simultaneous Linear, and Non-linear Congruences

Chinese Remainder Algorithms. Çetin Kaya Koç Spring / 22

MTH 346: The Chinese Remainder Theorem

Exam 2 Solutions. In class questions

MATH 2112/CSCI 2112, Discrete Structures I Winter 2007 Toby Kenney Homework Sheet 5 Hints & Model Solutions

10 Problem 1. The following assertions may be true or false, depending on the choice of the integers a, b 0. a "

Chinese Remainder Theorem explained with rotations

LECTURE 4: CHINESE REMAINDER THEOREM AND MULTIPLICATIVE FUNCTIONS

Course 2BA1: Trinity 2006 Section 9: Introduction to Number Theory and Cryptography

ICS141: Discrete Mathematics for Computer Science I

Math 5330 Spring Notes Congruences

M381 Number Theory 2004 Page 1

COMP239: Mathematics for Computer Science II. Prof. Chadi Assi EV7.635

Elementary factoring algorithms

Solutions to Problem Set 3 - Fall 2008 Due Tuesday, Sep. 30 at 1:00

Part V. Chapter 19. Congruence of integers

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

Carmen s Core Concepts (Math 135)

Course MA2C02, Hilary Term 2013 Section 9: Introduction to Number Theory and Cryptography

1 Overview and revision

MATH 145 Algebra, Solutions to Assignment 4

3 The fundamentals: Algorithms, the integers, and matrices

Discrete Structures Lecture Solving Congruences. mathematician of the eighteenth century). Also, the equation gggggg(aa, bb) =

Discrete Mathematics and Probability Theory Summer 2017 Course Notes Note 6

1 Adeles over Q. 1.1 Absolute values

1. multiplication is commutative and associative;

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

MATH 3240Q Introduction to Number Theory Homework 4

CHAPTER 6. Prime Numbers. Definition and Fundamental Results

Chapter 2 - Relations

[Part 2] Asymmetric-Key Encipherment. Chapter 9. Mathematics of Cryptography. Objectives. Contents. Objectives

Mathematics of Cryptography Part I

Definition 6.1 (p.277) A positive integer n is prime when n > 1 and the only positive divisors are 1 and n. Alternatively

a = mq + r where 0 r m 1.

The Chinese Remainder Theorem

4 Number Theory and Cryptography

Number Theory and Group Theoryfor Public-Key Cryptography

Number Theory Homework.

The answer is given in Sunzi Suanjing, and in 1592 Dawei Cheng put it as a poem:

Mathematics of Cryptography

Numbers. Çetin Kaya Koç Winter / 18

The Chinese Remainder Theorem

Partial Sums of Powers of Prime Factors

Chapter 3 Basic Number Theory

Homework #2 solutions Due: June 15, 2012

Spatial Navigation. Zaneta Navratilova and Mei Yin. March 6, Theoretical Neuroscience Journal Club University of Arizona

Basic elements of number theory

MATH 310: Homework 7

Basic elements of number theory

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

Chapter 1 : The language of mathematics.

3.2 Solving linear congruences. v3

3.7 Non-linear Diophantine Equations

Chapter 5. Modular arithmetic. 5.1 The modular ring

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

Congruences. September 16, 2006

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

MA4H9 Modular Forms: Problem Sheet 2 Solutions

Math 109 HW 9 Solutions

Introduction to Arithmetic Geometry Fall 2013 Lecture #2 09/10/2013

Lecture 7 Number Theory Euiseong Seo

Mathematical Writing and Methods of Proof

7. Prime Numbers Part VI of PJE

Tomáš Madaras Congruence classes

An Introduction to Proof-based Mathematics Harvard/MIT ESP: Summer HSSP Isabel Vogt

On Syndrome Decoding of Chinese Remainder Codes

8 Primes and Modular Arithmetic

2x 1 7. A linear congruence in modular arithmetic is an equation of the form. Why is the solution a set of integers rather than a unique integer?

Modular Arithmetic Instructor: Marizza Bailey Name:

Name: Solutions Final Exam

This exam contains 5 pages (including this cover page) and 4 questions. The total number of points is 100. Grade Table

LECTURE NOTES IN CRYPTOGRAPHY

Congruences for Fishburn numbers modulo prime powers

CS 514, Mathematics for Computer Science Mid-semester Exam, Autumn 2017 Department of Computer Science and Engineering IIT Guwahati

Computer Architecture 10. Residue Number Systems

Individual Solutions

SOLUTIONS TO PROBLEM SET 1. Section = 2 3, 1. n n + 1. k(k + 1) k=1 k(k + 1) + 1 (n + 1)(n + 2) n + 2,

Congruence of Integers

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

MATH 433 Applied Algebra Lecture 19: Subgroups (continued). Error-detecting and error-correcting codes.

Euler s, Fermat s and Wilson s Theorems

Proofs Not Based On POMI

Part II. Number Theory. Year

Blankits and Covers Finding Cover with an Arbitrarily Large Lowest Modulus

Number Theory Proof Portfolio

PMA225 Practice Exam questions and solutions Victor P. Snaith

A Readable Introduction to Real Mathematics

Discrete Mathematics with Applications MATH236

Transcription:

The Chinese Remainder Theorem L. Felipe Martins Department of Mathematics Cleveland State University l.martins@csuohio.edu Work licensed under a Creative Commons License available at http://creativecommons.org/licenses/by-nc-sa/3.0/us/ January 30, 2009 1 Initial Examples We start by looking at a simple example. Example 1.1. Suppose we want to find all integers x such that: x 5 pmod 10q (1) x 2 pmod 27q (2) The first equation implies that x 5 10y for some y P Z. Plugging this into the second equation, we get 5 10y 7 pmod 27q, which we can rearrange as 10y 2 5 3 24 pmod 27q. Since gcdp10,27q 1, 10 is invertible modulo 27, so we compute: 10 1 mod 27 19. So, we get: y 24 19 24 pmod 27q. Now we have to plug this back into x 5 10y. We have to be somewhat careful, however, if we want to find all solutions. We have found above infinitely many solutions for y, of the form y 24 27k, for k P Z. From this we get x 5 10y 5 10 p24 27kq 245 270k, for k P Z. Thas is: x 245 pmod 270q 1

We conclude that solutions of the system (1), (2) are the elements of the congruence class r245s, modulo 270 10 27. Another important point to notice is that the soution method presented here requires that 10 and 27 are relatively prime. We now generalize the observations made above, and also introduce a slightly different method of solution. Consider the system: We assume that gcdpm1,m2q 1. Let x x 1 m 2 determined. Notice that: x b 1 pmod m 1 q (3) x b 2 pmod m 2 q (4) x x 1 m 2 x 2 m 1 x 1 m 2 pmod m 1 q x x 1 m 2 x 2 m 1 x 2 m 1 pmod m 2 q Plugging these values into equations (3), (4) we get: x 2 m 1, where x 1 and x 2 are to be x 1 m 2 b 1 pmod m 1 q (5) x 2 m 1 b 2 pmod m 2 q (6) Since m 1 and m 2 are relatively prime, these equations have solutions: x 1 b 1 pm 1 2 mod m 1 q (7) x 2 b 2 pm 1 1 mod m 2 q. (8) The set of all solutions x of (3), (4) is then characterized by: x x 1 m 2 x 2 m 1 pmod m 1 m 2 q where x 1 and x 2 are given by (7) and (8). Example 1.2. Let s solve system (1), (2) by this method, using Sage for the computations: sage: b1,b2,m1,m2 = 5,2,10,27 1,x2 = b1* inverse_mod (m2,m1),b2* inverse_mod (m1,m2) 1,x2 (15, 38) = b1*m2+b2*m1;x 155 %10,x%27 (5, 20) 2

2 The Chinese Remainder Theorem In this section, we extend the method of the previous section to the case of more than two congruences. To get started, consider the following example, with three congruences: Example 2.1. x 4 pmod 6q (9) x 33 pmod 55q (10) x 18 pmod 49q (11) We make the requirement that the moduli are pairwise coprime: gcdp6,55q gcdp6,49q gcdp55,49q 1 (12) We let M be the product of the moduli: M 6 55 49 16170, and let N i M{m i for i 1,2,3: N 1 55 49 2695, N 2 6 49 294, N 3 6 55 330. The numbers N 1, N 2 and N 3 have the following two important properties: 1. gcdpm i,n i q 1, since m 1, m 2, m 3 are pairwise coprime. 2. m i N j if i j We seek a solution to (9), (10), (11) of the form: x x 1 N 1 x 2 N 2 x 3 N 3, where x 1, x 2, x 3 are to be determined. Taking x modulo m i for i 1,2,3, and using property (2) above we have: x x i N i pmod m i q, so that we want: x i N i b i pmod m i q 3

By property (1) above, N i is invertible modulo m i, so that these congruences have the solutions: Thus we have a solution: x 1 b 1 pn 1 1 mod m 1 q 4 4 pmod 6q x 2 b 2 pn 2 1 mod m 2 q 957 22 pmod 55q x 3 b 3 pn 3 1 mod m 3 q 270 25 pmod 18q, x 4 2695 22 294 24 330 25498. This is indeed a solution, as can be verified by substitution in (9), (10), (11). We want, however, to find all solutions of the system. To this end, suppose that x 1 and x 2 are two solutions. Then we have: pmod m 1 q pmod m 2 q pmod m 3 q Since m 1, m 2, m 3 are pairwise coprime, this is equivalent to: mod pmq, where M m 1 m 2 m 3 16170. This means that solutions can be reduced modulo 16170, and the general solution of the system is: x 25498 9328 pmod 16170q. We now state and prove the general theorem. Theorem 2.2 (Chinese Remainder Theorem ( CRT )). Suppose we are give integers b i, m i for 1 i n. Assume that the m i are pairwise coprime: Then, there is a x such that: gcdpm i,m j q 1 for 1 i, j n, ı j. x b i pmod m i q for 1 i n. (13) Furthermore, the solution of the system is unique modulo M m 1 m 2...m n. 4

Proof. To prove existence, let M be as in the statement of the theorem and let N i M{m i for 1 i n. Then, gcdpn i,m i q 1, so N i is invertible modulo m i, and it is possible to find x i such that x i N i b i pmod m i q. We then let: Then, since m i N j if i j, we have x x 1 N 1 x 2 N 2 x n N n. x m i N i b i pmod m i q. To prove uniqueness modulo M, suppose that x 1 and x 2 are both solutions of the system (13). Then, pmod m i q for 1 i n, that is, m i x 1 x 2. Since m 1, m 2,..., m n have no common factors, this implies M m 1 m 2...m n x 1 x 2, that is, pmod Mq. 3 The CRT in Sage We can solve system (13) in Sage by following the steps outlined in the previous section, both in Example 2.1 and in the proof of the CRT. We use lists to represent the problem data, so that our solution can be easily generalized to an arbitrary number of equations. sage: blist = [4,33,18] sage: mlist = [6,55,49] Now, we check that the assumption that the moduli are pairwise coprime: sage: all ([ gcd(u,v)==1 for u,v in zip(mlist,mlist) if u<v]) True Next compute M, the product of the moduli and N i M{m i for i 1,...,n: sage: M=prod(mlist) sage: Nlist =[M//m for m in mlist] sage: M,Nlist (16170, [2695, 294, 330]) Now compute the x i, which are solutions of x i N i b i pmod m i q list = [b* inverse_mod (N,m)%m for b,n,m in zip(blist,nlist,mlist )] list [4, 22, 25] Then, we can find x using: 5

=sum(x*n for x, N in zip(xlist,nlist )) 25498 Of course, we want reduce x modulo M: %= M 9328 Verifying that the computation is correct: sage: [ x % m for m in mlist] [4, 33, 18] Sage has functions to solve CRT systems directly. If we have only two equations, such as the ones in (1) and (2), we can use: =crt (5,2,10,27) 245 % 10, x%27 (5, 2) Notice the order of the arguments in the call: crt(b1,b2,m1,m2) returns a x such that x%m1==b1 and x%m2==b2 (if b1 and b2 are between 0 and x-1). It is said that, in ancient China, the CRT was used to determine the size of armies. Suppose, for example, that, by asking the soldiers to reposition themselves in the field, it is determined that: When the soldiers stand in rows of 7, no soldiers are left. When the soldiers stand in rows of 11, 5 soldiers are left. When the soldiers stand in rows of 13, 8 soldiers are left. When the soldiers stand in rows of 17, 13 soldiers are left. This means that the number of soldiers, x, satisfies: x 0 x 5 x 8 x 13 pmod 7q pmod 11q pmod 13q pmod 17q This can be solved in Sage with: 6

= CRT_list ([0,5,8,13],[7,11,13,17]) 10213 Notice that this method will give the wrong answer if the army has more than 17016 soldiers. Do you see why? What can be done if the army is larger than 17016? 7