0% found this document useful (0 votes)
91 views

Discrete Structure

The document discusses linear congruences and the Chinese Remainder Theorem. It provides examples and proofs of how to find solutions to linear congruences using inverses modulo m. It then explains the Chinese Remainder Theorem, which guarantees a unique solution exists for a system of congruences when the moduli are relatively prime. An example is worked through. Finally, it describes how large integers can be represented and arithmetic performed on them using remainders modulo relatively prime numbers to avoid data overflow issues.

Uploaded by

Subina Dhakal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Discrete Structure

The document discusses linear congruences and the Chinese Remainder Theorem. It provides examples and proofs of how to find solutions to linear congruences using inverses modulo m. It then explains the Chinese Remainder Theorem, which guarantees a unique solution exists for a system of congruences when the moduli are relatively prime. An example is worked through. Finally, it describes how large integers can be represented and arithmetic performed on them using remainders modulo relatively prime numbers to avoid data overflow issues.

Uploaded by

Subina Dhakal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Discrete Structure

___________________
Linear congruences
Chinese remainder theorem
Computer Arithmetic with large integers
Linear Congruences

 Generally, a congruence of form

ax  ≡ b (mod m),

where m is a positive integer, a and b are integers, is called


linear congruence.

 To find all integer x that satisfy this congruence we need an


integer () such that ≡ 1 (mod m), if such an integer exists. Such
an integer is said to be an inverse of modulo m.

 Theorem : Guarantees that an inverse of a modulo m exists


whenever a and m are relatively prime.
Linear Congruences

 Theorem: If a and m are relatively prime integers and m > 1, then


an inverse of a modulo m exists. Furthermore, this inverse is
unique modulo m. (That is, there is a unique positive integer less
than m that is an inverse of a modulo m and every other inverse of
a modulo m is congruent to modulo m.)

Proof:
Because g c d (a, m) = 1, there are integers s and t such that

s a + t m = 1.

This implies that, s a + t m ≡ 1 (mod m).

Because t m ≡ 0 (mod m), it follows that s a ≡ 1 (mod m).

Consequently, s is an inverse of a modulo m.


Linear Congruences
Example: find the solution of linear congruence 13x = 6 (mod 37)
Solution:
step 1:
gcd (13, 37)=1
Using division algorithm,
37 = 13(2) +11 => 11= 1(37)-2(13)
13 = 11(1) + 2 => 2 = 1(13)-1(11)
11 = 2(5) + 1 => 1= -5(2)+1(11)
2 =1(2) +0

Step 2 : writing the value in the form of linear combination.


1 = 1(11) – 5(2)
= 1(11) – 5(1(13) – 1(11))
= 1(11) – 5(13) + 5(11)
= 6(11) – 5(13)
= 6(1(37) – 2(13)) – 5(13)
= 6(37) – 12(13) – 5(13)
= 6(37) – 17(13)
Linear Congruences

Step 3: finding inverse


So we get 1= 6(37) + (– 17(13)) where 6(37)=0 as from theorem 1:
1≡ -17(13) (mod 37)
so inverse = -17

Step 4 : -17(13x) = -17 . 6 (mod 37)


x = -102 (mod 37 )

Solutions: -102, -65, -28, 9, 46, . . . . . . . . . . . . . .


since 9 is the smallest positive integer so
Solution is x = 9 (mod 37)
The Chinese Remainder Theorem

Statement:
 Let m1,m2,…….mn be pairwise relativity prime positive integers
greater than one and a1,a2,…..an arbitrary integers. Then the
system
x a1(mod m1)
x a2(mod m2)
.
.
.
x an(mod mn)

Has a unique solution modulo m=m1m2….mn. (That is, there is a


solution x with 0≤x<m, and all other solutions are congruent modulo
m to this solution.)
The Chinese Remainder Theorem

Proof: To establish this theorem, we need to show that a solution exists and
that it is unique modulo m. we will know that a solution exists by describing
a way to construct this solution; showing that the solution is unique modulo
m.
first let
m = m1m2m3……………mn then
for k = 1,2,3…………n
Mk =m / mk
=(m1m2m3………m(k-1)m(k)m(k+1))/m(k)
= m1m2m3………m(k-1)……..mn

M1=m/m1=m2m3……mn
M2=m/m2=m1m3.…..mn
Since m1,m2………,mn are relatively prime then
(M1,m1)=1=(M2,m2)=1=……………………..=(Mn,mn)
Then there exists an integers
c1,c2,…….,cn such that
M1c1 ≡ 1 (mod m1)
M2c2 ≡ 1(mod m2)…….. Mncn ≡ 1 (mod mn)
The Chinese Remainder Theorem
Now, let us construct an integer
u = M1c1a1 + M2c2a2+…………………………+Mn cn an
Such that
u ≡ M1 c1 a1 (mod m1)
u ≡ M2 c2 a2 (mod m2)
.
.
u ≡ Mn cn an (mod mn)
Let s denotes the set of all common solution of given congruences,
u∈s
To show uniqueness
Now, we want to show that s = residue class m of u
Suppose s
≡ a1 (mod m1)
≡ a2 (mod m2)
.
.
≡ an (mod mn)
The Chinese Remainder Theorem

Þm1,m2……….mn divides u-
Þm1m2………..mn divides u-
Þm| u-
Þu
Thus the given congruences have unique solution modulo
(m1,m2……………mn)
The Chinese Remainder Theorem
Example: Consider the 3 congruences from Sun-Tsu’s problem:
x ≡ 2 ( mod 3), x ≡ 3 ( mod 5), x ≡ 2 ( mod 7).
Given ,
b1=2,b2=3,b3=2 and (3,5)=(5,7)=(2,7)=1
so,m1, m2, m3 are relatively prime numbers so, by Chinese theorem given
congruencies have a unique solution (mod m1.m2.m3) i.e (mod 3.5.7)
Now,

m=m1.m2.m3=3*5*7=105
M1=m/m1=105/3=35
M2=m/m2=105/5=21
M3=m/m3=105/7=15

The given system of congruences becomes


M1x1 i.e 35 x1
M2x2 i.e 21 x2
M3x3 i.e 15 x3
The Chinese Remainder Theorem

By using division algorithm, we get the value of x1=2,x2=1,x3=1


By Chinese remainder theorem solution of congruence is given by,
x M1x1b1 + M2x2b2 + M3x3b3
x 35*2*2 + 21*3*1 + 15*1*2
x 233
x 233 ( mod 3*7*5)
x 233 ( mod 105)

To find smallest possible integer we get ,


X 23 ( mod 105)

X 23 ( mod 105) is a required unique solution.


Computer Arithmetic with large integers

Suppose that m1, m2, . . . . . . .mn are pairwise relativity prime


moduli and let m be their product. By the Chinese remainder
theorem we can show that an integer a with 0≤a<m can be
uniquely represented by the n-tuple consisting of its remainders
upon division by mi , i = 1, 2, . . . . . . . ,n. that is, we can uniquely
represent a by

(a mod m1, a mod m2, . . . . . . . . . . . , a mod mn).


Computer Arithmetic with large integers

Large data=> data overflow =>Malfunction


First, we have to create or select n moduli

n:m1,m2……..mn

n-tuples for a=(a mod m1, a mod m2,……..a mod mn)


n-tuples for b=(b mod m1, b mod m2,……..b mod mn)
a mod mi = ai and b mod mi = bi

For addition
a+b=(a1+b1, a2+b2, ………..an+bn)
For multiplication
ab=(a1b1, a2b2, ………..anbn)
Computer Arithmetic with large integers

a+b=> ci =ai+bi

N-tuple=(c1,c2,……..cn)

ab=> ci =aibi
x
x
.
.
.
x

m = m1m2…………….mn
𝑚 𝑛
Mi=
Solution :x = ∑
𝑚𝑖 𝑐𝑖 𝑥𝑖 𝑀𝑖𝑚𝑜𝑑 𝑚
𝑖=1
Computer Arithmetic with large integers

Example:
a=15 ; b = 27
m1 = 2 ;m2 = 3 ; m3 = 5 ; m4 = 7
Now,

a=15 b=27
15 mod 2 = 1 27 mod 2 = 1
15 mod 3 = 0 27 mod 3 = 0
15 mod 5 = 0 27 mod 5 = 2
15 mod 7 = 1 27 mod 7 = 6
4-tuples a=(1, 0, 0, 1) 4-tuples b=(1, 0, 2, 6)

c = a + b = (1, 0, 0, 1) + (1, 0, 2, 6) = (2, 0, 2, 7)=(0, 0, 2, 0)


x
x
x
x
Computer Arithmetic with large integers

m= 2*3*5*7 = 210
M1 = = 105
M2 = = 70
M3 = = 42
M4 = = 30
105 x1 42 x3

x1 x2 x3 x4
So,
x1 = 1
x2 = 1
x3 =2
x4 = 4
Computer Arithmetic with large integers

= 168 mod 210

= 42

a + b = 15 + 27 = 42
Computer Arithmetic with large integers

Suppose that performing arithmetic with integers less than 100 on a certain
processor is much quicker than doing arithmetic with larger integers. We can
restrict almost all our computations to integers less than 100 if we represent
integers using their remainders modulo pairwise relatively prime integers less
than 100. For example, we can use the moduli of 99, 98, 97, and 95. (These
integers are relatively prime pairwise, because no two have a common factor
greater than 1.)

By the Chinese remainder theorem, every nonnegative integer less than 99 ·


98 · 97 · 95 = 89,403,930 can be represented uniquely by its remainders when
divided by these four moduli.

For example, we represent 123,684 as (33, 8, 9, 89)


Because 123,684 mod 99 = 33; 123,684 mod 98 = 8; 123,684 mod 97 = 9; and
123,684 mod 95 = 89. Similarly, we represent 413,456 as (32, 92, 42, 16).
Computer Arithmetic with large integers

To find the sum of 123,684 and 413,456, we work with these 4-tuples instead
of these two integers directly. We add the 4-tuples component wise and
reduce each component with respect to the appropriate modulus. This yields
(33, 8, 9, 89) + (32, 92, 42, 16)
= (65 mod 99, 100 mod 98, 51 mod 97, 105 mod 95)
= (65, 2, 51, 10).
To find the sum, that is, the integer represented by (65, 2, 51, 10), we need to
solve the system of congruence’s
x ≡ 65 (mod 99),
x ≡ 2 (mod 98),
x ≡ 51 (mod 97),
x ≡ 10 (mod 95).
It can be shown that 537,140 is the unique nonnegative solution of this
system less than 89,403,930. Consequently, 537,140 is the sum. Note that it is
only when we have to recover the integer represented by (65, 2, 51, 10) that
we have to do arithmetic with integers larger than 100.
Thank you!

You might also like