SlideShare a Scribd company logo
Modular Arithmetic
Victor Adamchik
Fall of 2005
Plan
1. Review
2. Applications of Modular Arithmetic
3. Solving Linear Congruences
4. Chinese Remainder Theorem
5. Arithmetic with Large Integers
Review
Definition. a mod n means the remainder when a is divided by n
a q n r
Definition. (modulo equivalence)
a b mod n if and only if n a b
We will say that a and b are equivalent modulo n. We will also write modulo equivalence as
a n b
Theorem. n is an equivalence relation on the integers.
An equivalence class consists of those integers which have the same remainder on division by n.
The equivalence classes are also known as congruence classes modulo n. Rather than say the
integers a and b are equivalent we say that they are congruent modulo n.
Definition.The set of all integers congruent to a modulo n is called the residue class a .
Example. Residue classes mod 3:
V. Adamchik 1
[0]={...,-6,-3,0,3,6,...}
[1]={...,-5,-2,1,4,7,...}
[2]={...,-4,-1,2,5,8,...}
Definition. The set of residue classes is denoted by Zn
Zn 0, 1, 2, ..., n 1
Theorem (arithmetic on Zn) When we are doing +, - or * modulo n, we can replace a number by
another number in the same residue class.
Example. Compute
414 * 463 mod 413
1 * 50 = 50
Note (cancelation property). Though it seems that arithmetic on Zn is the same as on Z, do not be
deceived. The product of two non-zero elements of Zn can sometimes be 0.
Question. Is the following implication correct?
x a n x b a n b
Only if GCD x, n 1.
Proof.
x a n x b n x a x b n x a b n a b a n b
Definition.
Zn x Zn GCD x, n 1
Example.
Z0 0, 1, 2, 3, 4, 5
Z6 1, 5
V. Adamchik 21-127: Concepts of Mathematics
Advantage of Zn is that it has a cancelation property.
Definition. Euler's phi function (or totient function) is the size of Zn
n Zn
n is the number of integers 1 k n coprime to n.
Example.
12 1, 5, 7, 11 4
It's easy to see that if p is prime then p p 1. More on this function later.
Note. A number's multiplicative inverse x 1 defined by
x x 1
1
is another difference between Zn and Z. In Z only two elements have inverses: 1 and -1. We have
proved that if p is prime then each element in Zp has an inverse. We say that Zp is a finite field. a
set in which we can , , , . The prove is based on the following theorem
Theorem (Ferma's little theorem) If p is prime and p a, then
ap 1
p 1
According to this theorem, the inverse is defined by (assuming p is prime)
a 1 ap 2
Applications of Modular Arithmetic
Problem 1. How do we efficiently store people's records?
If we use Social Security number as the key, we will have to deal with an array of size 1010
.
The solution - hashing. Store records in the table at index h k defined by
h k k mod N
Here, h is a hash function, and N is an array size. Regardless of chosen N, collisions might happen
h k1 h k2
V. Adamchik 3
You will deal with collisions in 15-211.
Problem 2. How do we generate a random number?
There is nothing random about random() or rand() function. The standard technique is to create a
pseudorandom sequence. The most commonly used procedure for generating pseudorandom num-
bers is the linear congruential method (Lehmer, 1949). We generate a sequence of pseudorandom
numbers xk, by successively using the congruence
xn 1 a xn b mod m , n 0
x0 m is the seed
with appropriate values of 0 a m, 0 b m, m 0 and GCD b, m 1
For example,
xn 1 7 xn 4 mod 9 , n 0
x0 3
This generates the following sequence
x1 7 x0 4 7 3 4 25 7 mod 9
x2 7 x1 4 7 7 4 53 8 mod 9
x3 7 x2 4 7 8 4 60 6 mod 9
and so on
This recurrence is eventually periodic. So, it is desirable to use a recurence with the long period.
Problem 3. ISBN numbers for published books.
The ISBN number for our textbook is 0-13-184-868-2.
The information is decoded in the first 9 digits. The last digit is for parity check
1 a1 2 a2 ... 9 a9 a10 mod 11
Applying this to our textbook
1 0 2 1 3 3 4 1 5 8 6 4 7 8 8 6 9 8 255 2 mod 11
V. Adamchik 21-127: Concepts of Mathematics
The sum of 9 digits is 255 and it equals to the last digit mod 11.
Problem 4. The Gauss' Easter formula.
The church set the Easter on first Sunday after the first full moon in spring. The Easter sunday
always moves in the period of 22nd March until 25th April. F. Gauss developed the exact formula
to calculate the date of Easter. Here is its short version
a year mod 11
b year mod 4
c year mod 7
d 19 a M mod 30
e 2 b 4 c 6 d N mod 7
where constants M and N are
M 24
N 5
valid throughout the period between 1900 and 2099 years. Then Easter falls on 22 d e March
or d e 9 April.
year 2006;
a Mod year, 19 ; b Mod year, 4 ; c Mod year, 7 ;
M 24; n 5; 1900 2099
d Mod 19 a M, 30 ;
e Mod 2 b 4 c 6 d n, 7 ;
22 d e march , d e 9 april
47, 16
In 2006 the catholic church will celebrate Easter on April 16. Dates are according the Gregorian
calendar.
Here i sthe full version of the algorithm (see http://www.smart.net/~mmontes/nature1876.html), published
in Nature, 1876 April 20, vol. 13, p. 487.
V. Adamchik 5
year 2006;
a Mod year, 19 ;
b IntegerPart year 100 ;
c Mod year, 100 ;
d IntegerPart b 4 ;
e Mod b, 4 ;
f IntegerPart b 8 25 ;
g IntegerPart b f 1 3 ;
h Mod 19 a b d g 15, 30 ;
i IntegerPart c 4 ;
k Mod c, 4 ;
l Mod 32 2 e 2 i h k, 7 ;
m IntegerPart a 11 h 22 l 451 ;
EasterMonth IntegerPart h l 7 m 114 31 ; 3 March,4 April
p Mod h l 7 m 114, 31 ;
EasterDate p 1;
EasterDate, EasterMonth
16, 4
Solving Linear Congruences.
Definition. A relation of the form
a x b mod n
is called a linear congruence. We will also write this as
a x n b
How many solutions does it have? It's clear that if x0 is a solution then every element from a congru-
ent class is also a solution.
Example.
x 3 mod 4
Here are solutions
..., 1, 3, 7, 10, ...
Therefore, uniqueness can only be mod n.
x 3 4 k, where k Z
V. Adamchik 21-127: Concepts of Mathematics
Example.
2 x 2 mod 4
The congruence is satisfied for two representatives
x 1 and x 3
Therefore, the equations has two solutions
x 1 4 k and x 3 4 k, where k Z
Theorem. The linear congruence
a x b mod n
has a unique solution iff GCD a, n 1.
Proof. )
First we prove that the equation has a solution. To solve the equation means to find the inverse of a
x b a 1
mod n
But as we know the inverse is not necessarely exists in Zn. Therefore, some restrictions required. In
the next paragraph we show how to find an inverse using the Extended Euclidean Algorithm.
Given GCD a, n 1, it follows by the EEA that s, r Z
a r n s 1
Consider this equation mod n
a r 1 mod n
This means that r is the multiplicative inverse of a
r a 1
mod n
Therefore, the solution is
V. Adamchik 7
x b r mod n
Next, we prove uniqueness. We assume that there are two solutions X and Y.
a X b mod n
a Y b mod n
a X a Y mod n
n a X Y n X Y X Y mod n
The proof in ) direction is left as an exercise.
QED.
Chinese Remainder Theorem.
Suppose we want to solve a system of linear congruences
x 2 mod 3
x 3 mod 5
x 2 mod 7
Does a solution exist? Is it unique?
Let us build a solution. We solve the first equation x 2 mod 3
y1 2 mod 3
assuming that the solution is 0 modulo 5 and 7
y1 0 mod 5
y1 0 mod 7
The straightforward answer is defined by
5 7 z 2 mod 3
Therefore,
z 1 y1 35
V. Adamchik 21-127: Concepts of Mathematics
Next we solve the second equation x 3 mod 5 , again assuming that the solution is 0 modulo 3
and 7.
3 7 z 3 mod 5
It follows
z 3 y2 63
In the same manner, solving the last equation x 2 mod 7 yields
3 5 z 2 mod 7
z 2 y3 30
What is the general solution?
y1 y2 y3 35 63 30 128
Clearly, this is the solution modulo 3*5*7
x 128 mod 105
In the parameteric form
x 23 105 k, k Z
Thereom. (Chinese Remainder Theorem) Let m1, m2, ..., mn Z be pairwise relatively prime.
The system
x ak mod mk , k 1, 2, ..., n
has a unique solution modulo M m1 m2 ... mn.
Proof.
First we prove that the system has a solution. Proceeding as in the above example, we define
solution to each equation as
yk ak mod mk
yk 0 mod mj , k j
Combining them together yeilds the equation
V. Adamchik 9
M
mk
z ak mod mk
which definitely has a solution (why-?) with respect to z. Thus
yk
M
mk
z
Next we define the general solution by
y1 y2 ... yn
Clearly this is a solution to a given system by modulo M.
Uniqueness.
Suppose there are two solutions, say X, and Y. Then we would have
X mk
Y for all k
Therefore, they are the same modulo M
X M Y
Arithmetic with Large Integers
Problem. Compute 7! without ever encountering a number larger than 28
.
First, we find moduli mk relatively prime and m1 m2 ... mn 7
We choose 13, 11, 9 and 7.
Next we do all computations using these moduli
2 5 10, 10, 1, 3
3 4 12, 1, 3, 5
5 120, 10, 3, 15 3, 10, 3, 1
6 18, 60, 18, 6 5, 5, 0, 6
7 35, 35, 0, 42 9, 2, 0, 0
V. Adamchik 21-127: Concepts of Mathematics
The last step we recover 7! by applying the CRT
x 9 mod 13
x 2 mod 11
x 0 mod 9
x 0 mod 7
We find such a number x that 0 x 13 11 9 7.
Note. Solving the above system, you should not generate numbers bigger then 28.
Here we outline another method of solving the system of congruences. We denote the list of mod-
uli and the list of remainders by
m 13, 11, 9, 7
r 9, 2, 0, 0
respectively. On the first step, we find the inverses of each modulo with respect to each later mod-
ulo in the list. This can be done by the extended Euclidean algorithm (see the proof of the theorem
for solving linear congruence.)
13 1
6 mod 11, 13 1
7 mod 9, 13 1
6 mod 7
11 1
5 mod 9, 11 1
2 mod 7
9 1
4 mod 7
Let us denote the list of inverse (padded with zeros om the left) by
inv = {{0, 6, 7, 6}, {0, 0, 5, 2}, {0, 0, 0, 4}};
Then
invj,k mj 1 mod mk
Next, starting with a given list of remainders we do
V. Adamchik 11
for(j = 1, j < n, j++,
for(k = j+1, k <= n, k++,
r[k] = (r[k]-r[j])*inv[j][k]) % m[k];
]]
Finally, the solution is built up by
x
k 1
R
remk
j 1
k 1
mk
One can check that 0 x M m1 m2 ..., mn. In case of four moduli the solution is
x r1 m1 v1 m1 m2 v2 m1 m2 m3 v3 mod M
where
v1 r2 r1 inv1,2 mod m2
v2 r3 r1 inv1,3 v1 inv2,3 mod m3
v3 r4 r1 inv1,4 v1 inv2,4 v2 inv3,4 mod m4
To verify that this is indeed a solution, we compute x mod mk, k 1, 2, 3, 4. Obviously
x r1 mod m1
since the each term of x is divible by m1 except the first one. Next, we compute x mod m2 . Apply-
ing mod m2, we obtain
x r1 m1 v1 mod m2
Replacing v1
x r1 r2 r1 m1 inv1,2 mod m2
and using
m1 inv1,2 1 mod m2
yeilds
V. Adamchik 21-127: Concepts of Mathematics
x r2 mod m2
In the same manner we prove other two cases.
Here is the Mathematica code
n 4;
m 13, 11, 9, 7 ;
rem 9, 2, 0, 0 ;
inv 0, 6, 7, 6 , 0, 0, 5, 2 , 0, 0, 0, 4 ;
For j 1, j n, j ,
For k j 1, k n, k ,
rem k Mod rem k rem j inv j, k , m k
;
Sum rem k Product m j , j, 1, k 1 ,
k, 1, n
5040
Generally, choosing the following five relatively prime numbers as moduli
235
1, 234
1, 233
1, 229
1, 223
1
we can add and multiply positive integers up to the size of 2154
M
k 1
5
mk 2154
Compare this with the size of the largest integer 232 1 on a 32-bit CPU.
V. Adamchik 13

More Related Content

What's hot

New Formulas for the Euler-Mascheroni Constant
New Formulas for the Euler-Mascheroni Constant New Formulas for the Euler-Mascheroni Constant
New Formulas for the Euler-Mascheroni Constant
nikos mantzakouras
 
Proof of Beal's conjecture
Proof of Beal's conjecture Proof of Beal's conjecture
Proof of Beal's conjecture
nikos mantzakouras
 
First order non-linear partial differential equation & its applications
First order non-linear partial differential equation & its applicationsFirst order non-linear partial differential equation & its applications
First order non-linear partial differential equation & its applications
Jayanshu Gundaniya
 
Solve Equations
Solve EquationsSolve Equations
Solve Equations
nikos mantzakouras
 
MIT Math Syllabus 10-3 Lesson 6: Equations
MIT Math Syllabus 10-3 Lesson 6: EquationsMIT Math Syllabus 10-3 Lesson 6: Equations
MIT Math Syllabus 10-3 Lesson 6: Equations
Lawrence De Vera
 
MATH 10 Week 1 2 linear equations (2)
MATH 10 Week 1  2 linear equations (2)MATH 10 Week 1  2 linear equations (2)
MATH 10 Week 1 2 linear equations (2)I.j. Carido
 
formulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equationformulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equation
Mahaswari Jogia
 
Solution 1
Solution 1Solution 1
Solution 1aldrins
 
Solution 1
Solution 1Solution 1
Solution 1aldrins
 
MIT Math Syllabus 10-3 Lesson 7: Quadratic equations
MIT Math Syllabus 10-3 Lesson 7: Quadratic equationsMIT Math Syllabus 10-3 Lesson 7: Quadratic equations
MIT Math Syllabus 10-3 Lesson 7: Quadratic equations
Lawrence De Vera
 
Recursion & methods of proof in algorithm analysis
Recursion & methods of proof in algorithm analysisRecursion & methods of proof in algorithm analysis
Recursion & methods of proof in algorithm analysis
AnujaTungar1
 
A Proof of Twin primes and Golbach's Conjecture
A Proof of Twin primes and Golbach's ConjectureA Proof of Twin primes and Golbach's Conjecture
A Proof of Twin primes and Golbach's Conjecture
nikos mantzakouras
 
Second order homogeneous linear differential equations
Second order homogeneous linear differential equations Second order homogeneous linear differential equations
Second order homogeneous linear differential equations Viraj Patel
 
Differential equations
Differential equationsDifferential equations
Differential equationsCharan Kumar
 

What's hot (20)

New Formulas for the Euler-Mascheroni Constant
New Formulas for the Euler-Mascheroni Constant New Formulas for the Euler-Mascheroni Constant
New Formulas for the Euler-Mascheroni Constant
 
IIT JEE Maths 2000
IIT JEE Maths   2000IIT JEE Maths   2000
IIT JEE Maths 2000
 
Proof of Beal's conjecture
Proof of Beal's conjecture Proof of Beal's conjecture
Proof of Beal's conjecture
 
Differential equations
Differential equationsDifferential equations
Differential equations
 
First order non-linear partial differential equation & its applications
First order non-linear partial differential equation & its applicationsFirst order non-linear partial differential equation & its applications
First order non-linear partial differential equation & its applications
 
Solve Equations
Solve EquationsSolve Equations
Solve Equations
 
Higher order differential equations
Higher order differential equationsHigher order differential equations
Higher order differential equations
 
MIT Math Syllabus 10-3 Lesson 6: Equations
MIT Math Syllabus 10-3 Lesson 6: EquationsMIT Math Syllabus 10-3 Lesson 6: Equations
MIT Math Syllabus 10-3 Lesson 6: Equations
 
MATH 10 Week 1 2 linear equations (2)
MATH 10 Week 1  2 linear equations (2)MATH 10 Week 1  2 linear equations (2)
MATH 10 Week 1 2 linear equations (2)
 
formulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equationformulation of first order linear and nonlinear 2nd order differential equation
formulation of first order linear and nonlinear 2nd order differential equation
 
Solution 1
Solution 1Solution 1
Solution 1
 
Sect3 1
Sect3 1Sect3 1
Sect3 1
 
Solution 1
Solution 1Solution 1
Solution 1
 
Ch03 1
Ch03 1Ch03 1
Ch03 1
 
IITJEE Mathematics 2007
IITJEE Mathematics   2007IITJEE Mathematics   2007
IITJEE Mathematics 2007
 
MIT Math Syllabus 10-3 Lesson 7: Quadratic equations
MIT Math Syllabus 10-3 Lesson 7: Quadratic equationsMIT Math Syllabus 10-3 Lesson 7: Quadratic equations
MIT Math Syllabus 10-3 Lesson 7: Quadratic equations
 
Recursion & methods of proof in algorithm analysis
Recursion & methods of proof in algorithm analysisRecursion & methods of proof in algorithm analysis
Recursion & methods of proof in algorithm analysis
 
A Proof of Twin primes and Golbach's Conjecture
A Proof of Twin primes and Golbach's ConjectureA Proof of Twin primes and Golbach's Conjecture
A Proof of Twin primes and Golbach's Conjecture
 
Second order homogeneous linear differential equations
Second order homogeneous linear differential equations Second order homogeneous linear differential equations
Second order homogeneous linear differential equations
 
Differential equations
Differential equationsDifferential equations
Differential equations
 

Similar to modul pembelajaran 4

UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
UmeshReddy49
 
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
Mohamedshabana38
 
Algebraic techniques in combinatorics
Algebraic techniques in combinatoricsAlgebraic techniques in combinatorics
Algebraic techniques in combinatorics
Vui Lên Bạn Nhé
 
Mathematical formulation of inverse scattering and korteweg de vries equation
Mathematical formulation of inverse scattering and korteweg de vries equationMathematical formulation of inverse scattering and korteweg de vries equation
Mathematical formulation of inverse scattering and korteweg de vries equation
Alexander Decker
 
Imc2017 day1-solutions
Imc2017 day1-solutionsImc2017 day1-solutions
Imc2017 day1-solutions
Christos Loizos
 
Statistical Method In Economics
Statistical Method In EconomicsStatistical Method In Economics
Statistical Method In Economics
Economics Homework Helper
 
Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...
Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...
Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...
Steven Duplij (Stepan Douplii)
 
factoring
factoringfactoring
factoring
Harish Sahu
 
annals-v181-n1-p06-p
annals-v181-n1-p06-pannals-v181-n1-p06-p
annals-v181-n1-p06-pRobert Hough
 
1. introduction to complex numbers
1. introduction to complex numbers1. introduction to complex numbers
1. introduction to complex numbers
جليل الممتاز
 
Consistency of linear equations in two and three variables
Consistency of linear equations in two and three variablesConsistency of linear equations in two and three variables
Consistency of linear equations in two and three variables
Aamlan Saswat Mishra
 
Exact Matrix Completion via Convex Optimization Slide (PPT)
Exact Matrix Completion via Convex Optimization Slide (PPT)Exact Matrix Completion via Convex Optimization Slide (PPT)
Exact Matrix Completion via Convex Optimization Slide (PPT)
Joonyoung Yi
 
published research papers
published research paperspublished research papers
published research papers
graphicdesigner79
 
journal of mathematics research
journal of mathematics researchjournal of mathematics research
journal of mathematics research
rikaseorika
 
research paper publication journals
research paper publication journalsresearch paper publication journals
research paper publication journals
rikaseorika
 
MC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceMC0082 –Theory of Computer Science
MC0082 –Theory of Computer Science
Aravind NC
 
Logarithm
LogarithmLogarithm
Logarithm
Febri Arianti
 
U3 08 ecuaciones
U3   08 ecuacionesU3   08 ecuaciones
U3 08 ecuaciones
UNEFA Zulia
 
Machine learning (10)
Machine learning (10)Machine learning (10)
Machine learning (10)NYversity
 

Similar to modul pembelajaran 4 (20)

UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
 
Algebraic techniques in combinatorics
Algebraic techniques in combinatoricsAlgebraic techniques in combinatorics
Algebraic techniques in combinatorics
 
Mathematical formulation of inverse scattering and korteweg de vries equation
Mathematical formulation of inverse scattering and korteweg de vries equationMathematical formulation of inverse scattering and korteweg de vries equation
Mathematical formulation of inverse scattering and korteweg de vries equation
 
Imc2017 day1-solutions
Imc2017 day1-solutionsImc2017 day1-solutions
Imc2017 day1-solutions
 
Number theory
Number theoryNumber theory
Number theory
 
Statistical Method In Economics
Statistical Method In EconomicsStatistical Method In Economics
Statistical Method In Economics
 
Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...
Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...
Conformal symmetry transformations and nonlinear Maxwell equations, G.A.Goldi...
 
factoring
factoringfactoring
factoring
 
annals-v181-n1-p06-p
annals-v181-n1-p06-pannals-v181-n1-p06-p
annals-v181-n1-p06-p
 
1. introduction to complex numbers
1. introduction to complex numbers1. introduction to complex numbers
1. introduction to complex numbers
 
Consistency of linear equations in two and three variables
Consistency of linear equations in two and three variablesConsistency of linear equations in two and three variables
Consistency of linear equations in two and three variables
 
Exact Matrix Completion via Convex Optimization Slide (PPT)
Exact Matrix Completion via Convex Optimization Slide (PPT)Exact Matrix Completion via Convex Optimization Slide (PPT)
Exact Matrix Completion via Convex Optimization Slide (PPT)
 
published research papers
published research paperspublished research papers
published research papers
 
journal of mathematics research
journal of mathematics researchjournal of mathematics research
journal of mathematics research
 
research paper publication journals
research paper publication journalsresearch paper publication journals
research paper publication journals
 
MC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceMC0082 –Theory of Computer Science
MC0082 –Theory of Computer Science
 
Logarithm
LogarithmLogarithm
Logarithm
 
U3 08 ecuaciones
U3   08 ecuacionesU3   08 ecuaciones
U3 08 ecuaciones
 
Machine learning (10)
Machine learning (10)Machine learning (10)
Machine learning (10)
 

More from Ajrina Pia

Contoh rpp-kurikulum-2013
Contoh rpp-kurikulum-2013Contoh rpp-kurikulum-2013
Contoh rpp-kurikulum-2013Ajrina Pia
 
Aritmatik social
Aritmatik socialAritmatik social
Aritmatik socialAjrina Pia
 
Aritmatika sosial
Aritmatika sosialAritmatika sosial
Aritmatika sosialAjrina Pia
 
Pengertian strategi pembelajaran lengkap
Pengertian strategi pembelajaran lengkapPengertian strategi pembelajaran lengkap
Pengertian strategi pembelajaran lengkapAjrina Pia
 
Laporan evaluasi pembelajaran
Laporan evaluasi pembelajaranLaporan evaluasi pembelajaran
Laporan evaluasi pembelajaranAjrina Pia
 
Kisi kisi timss
Kisi kisi timssKisi kisi timss
Kisi kisi timssAjrina Pia
 
Kisi kisi pisa
Kisi kisi pisaKisi kisi pisa
Kisi kisi pisaAjrina Pia
 
Penentuan tetapan kesetimbangan
Penentuan tetapan kesetimbangan Penentuan tetapan kesetimbangan
Penentuan tetapan kesetimbangan Ajrina Pia
 
modul pembelajaran 5
modul pembelajaran 5modul pembelajaran 5
modul pembelajaran 5Ajrina Pia
 
modul pembelajaran 7
modul pembelajaran 7modul pembelajaran 7
modul pembelajaran 7Ajrina Pia
 
modul pembelajaran 3
modul pembelajaran 3modul pembelajaran 3
modul pembelajaran 3Ajrina Pia
 

More from Ajrina Pia (20)

Contoh rpp-kurikulum-2013
Contoh rpp-kurikulum-2013Contoh rpp-kurikulum-2013
Contoh rpp-kurikulum-2013
 
Bukusiswa
BukusiswaBukusiswa
Bukusiswa
 
Aritmatik social
Aritmatik socialAritmatik social
Aritmatik social
 
Dppm2
Dppm2Dppm2
Dppm2
 
Aritmatika sosial
Aritmatika sosialAritmatika sosial
Aritmatika sosial
 
Pengertian strategi pembelajaran lengkap
Pengertian strategi pembelajaran lengkapPengertian strategi pembelajaran lengkap
Pengertian strategi pembelajaran lengkap
 
Deskripsi vb
Deskripsi vbDeskripsi vb
Deskripsi vb
 
Soal timss
Soal timssSoal timss
Soal timss
 
Soal pisa
Soal pisaSoal pisa
Soal pisa
 
Rubrik timss
Rubrik timssRubrik timss
Rubrik timss
 
Rubrik pisa
Rubrik pisaRubrik pisa
Rubrik pisa
 
Laporan evaluasi pembelajaran
Laporan evaluasi pembelajaranLaporan evaluasi pembelajaran
Laporan evaluasi pembelajaran
 
Kisi kisi timss
Kisi kisi timssKisi kisi timss
Kisi kisi timss
 
Kisi kisi pisa
Kisi kisi pisaKisi kisi pisa
Kisi kisi pisa
 
rpp
rpp rpp
rpp
 
Penentuan tetapan kesetimbangan
Penentuan tetapan kesetimbangan Penentuan tetapan kesetimbangan
Penentuan tetapan kesetimbangan
 
modul pembelajaran 5
modul pembelajaran 5modul pembelajaran 5
modul pembelajaran 5
 
modul pembelajaran 7
modul pembelajaran 7modul pembelajaran 7
modul pembelajaran 7
 
modul pembelajaran 3
modul pembelajaran 3modul pembelajaran 3
modul pembelajaran 3
 
kumpulan soal
kumpulan soalkumpulan soal
kumpulan soal
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

modul pembelajaran 4

  • 1. Modular Arithmetic Victor Adamchik Fall of 2005 Plan 1. Review 2. Applications of Modular Arithmetic 3. Solving Linear Congruences 4. Chinese Remainder Theorem 5. Arithmetic with Large Integers Review Definition. a mod n means the remainder when a is divided by n a q n r Definition. (modulo equivalence) a b mod n if and only if n a b We will say that a and b are equivalent modulo n. We will also write modulo equivalence as a n b Theorem. n is an equivalence relation on the integers. An equivalence class consists of those integers which have the same remainder on division by n. The equivalence classes are also known as congruence classes modulo n. Rather than say the integers a and b are equivalent we say that they are congruent modulo n. Definition.The set of all integers congruent to a modulo n is called the residue class a . Example. Residue classes mod 3: V. Adamchik 1
  • 2. [0]={...,-6,-3,0,3,6,...} [1]={...,-5,-2,1,4,7,...} [2]={...,-4,-1,2,5,8,...} Definition. The set of residue classes is denoted by Zn Zn 0, 1, 2, ..., n 1 Theorem (arithmetic on Zn) When we are doing +, - or * modulo n, we can replace a number by another number in the same residue class. Example. Compute 414 * 463 mod 413 1 * 50 = 50 Note (cancelation property). Though it seems that arithmetic on Zn is the same as on Z, do not be deceived. The product of two non-zero elements of Zn can sometimes be 0. Question. Is the following implication correct? x a n x b a n b Only if GCD x, n 1. Proof. x a n x b n x a x b n x a b n a b a n b Definition. Zn x Zn GCD x, n 1 Example. Z0 0, 1, 2, 3, 4, 5 Z6 1, 5 V. Adamchik 21-127: Concepts of Mathematics
  • 3. Advantage of Zn is that it has a cancelation property. Definition. Euler's phi function (or totient function) is the size of Zn n Zn n is the number of integers 1 k n coprime to n. Example. 12 1, 5, 7, 11 4 It's easy to see that if p is prime then p p 1. More on this function later. Note. A number's multiplicative inverse x 1 defined by x x 1 1 is another difference between Zn and Z. In Z only two elements have inverses: 1 and -1. We have proved that if p is prime then each element in Zp has an inverse. We say that Zp is a finite field. a set in which we can , , , . The prove is based on the following theorem Theorem (Ferma's little theorem) If p is prime and p a, then ap 1 p 1 According to this theorem, the inverse is defined by (assuming p is prime) a 1 ap 2 Applications of Modular Arithmetic Problem 1. How do we efficiently store people's records? If we use Social Security number as the key, we will have to deal with an array of size 1010 . The solution - hashing. Store records in the table at index h k defined by h k k mod N Here, h is a hash function, and N is an array size. Regardless of chosen N, collisions might happen h k1 h k2 V. Adamchik 3
  • 4. You will deal with collisions in 15-211. Problem 2. How do we generate a random number? There is nothing random about random() or rand() function. The standard technique is to create a pseudorandom sequence. The most commonly used procedure for generating pseudorandom num- bers is the linear congruential method (Lehmer, 1949). We generate a sequence of pseudorandom numbers xk, by successively using the congruence xn 1 a xn b mod m , n 0 x0 m is the seed with appropriate values of 0 a m, 0 b m, m 0 and GCD b, m 1 For example, xn 1 7 xn 4 mod 9 , n 0 x0 3 This generates the following sequence x1 7 x0 4 7 3 4 25 7 mod 9 x2 7 x1 4 7 7 4 53 8 mod 9 x3 7 x2 4 7 8 4 60 6 mod 9 and so on This recurrence is eventually periodic. So, it is desirable to use a recurence with the long period. Problem 3. ISBN numbers for published books. The ISBN number for our textbook is 0-13-184-868-2. The information is decoded in the first 9 digits. The last digit is for parity check 1 a1 2 a2 ... 9 a9 a10 mod 11 Applying this to our textbook 1 0 2 1 3 3 4 1 5 8 6 4 7 8 8 6 9 8 255 2 mod 11 V. Adamchik 21-127: Concepts of Mathematics
  • 5. The sum of 9 digits is 255 and it equals to the last digit mod 11. Problem 4. The Gauss' Easter formula. The church set the Easter on first Sunday after the first full moon in spring. The Easter sunday always moves in the period of 22nd March until 25th April. F. Gauss developed the exact formula to calculate the date of Easter. Here is its short version a year mod 11 b year mod 4 c year mod 7 d 19 a M mod 30 e 2 b 4 c 6 d N mod 7 where constants M and N are M 24 N 5 valid throughout the period between 1900 and 2099 years. Then Easter falls on 22 d e March or d e 9 April. year 2006; a Mod year, 19 ; b Mod year, 4 ; c Mod year, 7 ; M 24; n 5; 1900 2099 d Mod 19 a M, 30 ; e Mod 2 b 4 c 6 d n, 7 ; 22 d e march , d e 9 april 47, 16 In 2006 the catholic church will celebrate Easter on April 16. Dates are according the Gregorian calendar. Here i sthe full version of the algorithm (see http://www.smart.net/~mmontes/nature1876.html), published in Nature, 1876 April 20, vol. 13, p. 487. V. Adamchik 5
  • 6. year 2006; a Mod year, 19 ; b IntegerPart year 100 ; c Mod year, 100 ; d IntegerPart b 4 ; e Mod b, 4 ; f IntegerPart b 8 25 ; g IntegerPart b f 1 3 ; h Mod 19 a b d g 15, 30 ; i IntegerPart c 4 ; k Mod c, 4 ; l Mod 32 2 e 2 i h k, 7 ; m IntegerPart a 11 h 22 l 451 ; EasterMonth IntegerPart h l 7 m 114 31 ; 3 March,4 April p Mod h l 7 m 114, 31 ; EasterDate p 1; EasterDate, EasterMonth 16, 4 Solving Linear Congruences. Definition. A relation of the form a x b mod n is called a linear congruence. We will also write this as a x n b How many solutions does it have? It's clear that if x0 is a solution then every element from a congru- ent class is also a solution. Example. x 3 mod 4 Here are solutions ..., 1, 3, 7, 10, ... Therefore, uniqueness can only be mod n. x 3 4 k, where k Z V. Adamchik 21-127: Concepts of Mathematics
  • 7. Example. 2 x 2 mod 4 The congruence is satisfied for two representatives x 1 and x 3 Therefore, the equations has two solutions x 1 4 k and x 3 4 k, where k Z Theorem. The linear congruence a x b mod n has a unique solution iff GCD a, n 1. Proof. ) First we prove that the equation has a solution. To solve the equation means to find the inverse of a x b a 1 mod n But as we know the inverse is not necessarely exists in Zn. Therefore, some restrictions required. In the next paragraph we show how to find an inverse using the Extended Euclidean Algorithm. Given GCD a, n 1, it follows by the EEA that s, r Z a r n s 1 Consider this equation mod n a r 1 mod n This means that r is the multiplicative inverse of a r a 1 mod n Therefore, the solution is V. Adamchik 7
  • 8. x b r mod n Next, we prove uniqueness. We assume that there are two solutions X and Y. a X b mod n a Y b mod n a X a Y mod n n a X Y n X Y X Y mod n The proof in ) direction is left as an exercise. QED. Chinese Remainder Theorem. Suppose we want to solve a system of linear congruences x 2 mod 3 x 3 mod 5 x 2 mod 7 Does a solution exist? Is it unique? Let us build a solution. We solve the first equation x 2 mod 3 y1 2 mod 3 assuming that the solution is 0 modulo 5 and 7 y1 0 mod 5 y1 0 mod 7 The straightforward answer is defined by 5 7 z 2 mod 3 Therefore, z 1 y1 35 V. Adamchik 21-127: Concepts of Mathematics
  • 9. Next we solve the second equation x 3 mod 5 , again assuming that the solution is 0 modulo 3 and 7. 3 7 z 3 mod 5 It follows z 3 y2 63 In the same manner, solving the last equation x 2 mod 7 yields 3 5 z 2 mod 7 z 2 y3 30 What is the general solution? y1 y2 y3 35 63 30 128 Clearly, this is the solution modulo 3*5*7 x 128 mod 105 In the parameteric form x 23 105 k, k Z Thereom. (Chinese Remainder Theorem) Let m1, m2, ..., mn Z be pairwise relatively prime. The system x ak mod mk , k 1, 2, ..., n has a unique solution modulo M m1 m2 ... mn. Proof. First we prove that the system has a solution. Proceeding as in the above example, we define solution to each equation as yk ak mod mk yk 0 mod mj , k j Combining them together yeilds the equation V. Adamchik 9
  • 10. M mk z ak mod mk which definitely has a solution (why-?) with respect to z. Thus yk M mk z Next we define the general solution by y1 y2 ... yn Clearly this is a solution to a given system by modulo M. Uniqueness. Suppose there are two solutions, say X, and Y. Then we would have X mk Y for all k Therefore, they are the same modulo M X M Y Arithmetic with Large Integers Problem. Compute 7! without ever encountering a number larger than 28 . First, we find moduli mk relatively prime and m1 m2 ... mn 7 We choose 13, 11, 9 and 7. Next we do all computations using these moduli 2 5 10, 10, 1, 3 3 4 12, 1, 3, 5 5 120, 10, 3, 15 3, 10, 3, 1 6 18, 60, 18, 6 5, 5, 0, 6 7 35, 35, 0, 42 9, 2, 0, 0 V. Adamchik 21-127: Concepts of Mathematics
  • 11. The last step we recover 7! by applying the CRT x 9 mod 13 x 2 mod 11 x 0 mod 9 x 0 mod 7 We find such a number x that 0 x 13 11 9 7. Note. Solving the above system, you should not generate numbers bigger then 28. Here we outline another method of solving the system of congruences. We denote the list of mod- uli and the list of remainders by m 13, 11, 9, 7 r 9, 2, 0, 0 respectively. On the first step, we find the inverses of each modulo with respect to each later mod- ulo in the list. This can be done by the extended Euclidean algorithm (see the proof of the theorem for solving linear congruence.) 13 1 6 mod 11, 13 1 7 mod 9, 13 1 6 mod 7 11 1 5 mod 9, 11 1 2 mod 7 9 1 4 mod 7 Let us denote the list of inverse (padded with zeros om the left) by inv = {{0, 6, 7, 6}, {0, 0, 5, 2}, {0, 0, 0, 4}}; Then invj,k mj 1 mod mk Next, starting with a given list of remainders we do V. Adamchik 11
  • 12. for(j = 1, j < n, j++, for(k = j+1, k <= n, k++, r[k] = (r[k]-r[j])*inv[j][k]) % m[k]; ]] Finally, the solution is built up by x k 1 R remk j 1 k 1 mk One can check that 0 x M m1 m2 ..., mn. In case of four moduli the solution is x r1 m1 v1 m1 m2 v2 m1 m2 m3 v3 mod M where v1 r2 r1 inv1,2 mod m2 v2 r3 r1 inv1,3 v1 inv2,3 mod m3 v3 r4 r1 inv1,4 v1 inv2,4 v2 inv3,4 mod m4 To verify that this is indeed a solution, we compute x mod mk, k 1, 2, 3, 4. Obviously x r1 mod m1 since the each term of x is divible by m1 except the first one. Next, we compute x mod m2 . Apply- ing mod m2, we obtain x r1 m1 v1 mod m2 Replacing v1 x r1 r2 r1 m1 inv1,2 mod m2 and using m1 inv1,2 1 mod m2 yeilds V. Adamchik 21-127: Concepts of Mathematics
  • 13. x r2 mod m2 In the same manner we prove other two cases. Here is the Mathematica code n 4; m 13, 11, 9, 7 ; rem 9, 2, 0, 0 ; inv 0, 6, 7, 6 , 0, 0, 5, 2 , 0, 0, 0, 4 ; For j 1, j n, j , For k j 1, k n, k , rem k Mod rem k rem j inv j, k , m k ; Sum rem k Product m j , j, 1, k 1 , k, 1, n 5040 Generally, choosing the following five relatively prime numbers as moduli 235 1, 234 1, 233 1, 229 1, 223 1 we can add and multiply positive integers up to the size of 2154 M k 1 5 mk 2154 Compare this with the size of the largest integer 232 1 on a 32-bit CPU. V. Adamchik 13