Discrete Structure
Discrete Structure
___________________
Linear congruences
Chinese remainder theorem
Computer Arithmetic with large integers
Linear Congruences
Proof:
Because g c d (a, m) = 1, there are integers s and t such that
s a + t m = 1.
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)
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
n:m1,m2……..mn
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)
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
= 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.)
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!