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

Lecture 13

Uploaded by

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

Lecture 13

Uploaded by

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

Great Theoretical Ideas In Computer Science

Victor Adamchik CS 15-251 Spring 2010


Danny Sleator
Lecture 13 Feb 23, 2010 Carnegie Mellon University
Greatest Common Divisor:
k=GCD(x,y)
Number Theory greatest k ≥ 1 such that k|x and k|y.
and
Modular Arithmetic

p 1
Least Common Multiple:
k=LCM(x,y)
smallest k ≥ 1 such that x|k and y|k.

(a mod n) means the remainder


Fact: when a is divided by n.
GCD(x,y) × LCM(x,y) = x × y
a mod n = r

You can use
MAX(a,b) + MIN(a,b) = a+b a = d n + r for some integer d
to prove the above fact… or
a = n + r k for some integer k

Definition: Modular equivalence n induces a natural partition of the


a  b [mod n]
 (a mod n) = (b mod n)
integers into n “residue” classes.
 n | (a-b)

(“residue” = what left over = “remainder”)

31 81 [mod 2] Written as a n b,


31 2 81 and spoken Define residue class
“a and b are [k] = the set of all integers that
31 80 [mod 7] equivalent or

congruent modulo n”
are congruent to k modulo n.
31 7 80

1
Residue Classes Mod 3:
n is an equivalence relation
[0] = { …, -6, -3, 0, 3, 6, ..}
[1] = { …, -5, -2, 1, 4, 7, ..} In other words, it is
[2] = { …, -4, -1, 2, 5, 8, ..}
Reflexive: a n a
= [0]
[-6] = { …, -6, -3, 0, 3, 6, ..}
[7] = { …, -5, -2, 1, 4, 7, ..} = [1]
Symmetric: (a n b)  (b n a)
[-1] = { …, -4, -1, 2, 5, 8, ..} = [2]

Transitive: (a n b and b n c)  (a n c)

Why do we care about these


residue classes? Fundamental lemma of
plus and times mod n:
Because we can replace any member
of a residue class with another member
when doing addition or multiplication mod n If (x n y) and (a n b). Then
and the answer will not change
1) x + a n y + b
To calculate: 249 * 504 mod 251
2) x * a n y * b
just do -2 * 2 = -4 = 247

Another Simple Fact:


Proof of 2:
if (x n y) and (k|n), then: x k y
x a = y b (mod n)
Example: 10 6 16  10 3 16

Proof:
(x n y) => x = y + k n
x=y+mn
(a n b) => a = b + m n
n=ak
x a = y b + n (y m + b k + k m) x=y+amk
x k y

2
A Unique Representation System Unique representation system mod 2
Modulo n:
Finite set Z2 = {0, 1}
We pick one representative from
each residue class and do all our calculations
using these representatives.

+2 0 1 *2 0 1
XOR AND
Unsurprisingly, we use 0, 1, 2, …, n-1
0 0 1 0 0 0

1 1 0 1 0 1

Unique representation system mod 3 Unique representation system mod 4

Finite set S = {0, 1, 2} Finite set S = {0, 1, 2, 3}

+ and * defined on S: + and * defined on S:

+ 0 1 2 * 0 1 2 + 0 1 2 3 * 0 1 2 3

0 0 1 2 0 0 0 0 0 0 1 2 3 0 0 0 0 0
1 1 2 0 1 0 1 2 1 1 2 3 0 1 0 1 2 3
2 2 0 1 2 0 2 1 2 2 3 0 1 2 0 2 0 2
3 3 0 1 2 3 0 3 2 1

Notation Some properties of the operation +n

[“Closed”]
Zn = {0, 1, 2, …, n-1} x, y  Zn  x +n y  Zn

[“Associative”]
Define operations +n and *n: x, y, z  Zn  (x +n y) +n z = x +n (y +n z)

a +n b = (a + b mod n) [“Commutative”]
a *n b = (a * b mod n) x, y  Zn  x +n y = y +n x

Similar properties also hold for *n

3
For addition tables, rows and columns For multiplication, some rows and columns
always are a permutation of Zn are permutation of Zn, while others aren’t…

* 0 1 2 3 4 5
+ 0 1 2 3 4 * 0 1 2 3 4
+ 0 1 2 3 4 5
0 0 0 0 0 0 0
0 0 1 2 3 4 0 0 0 0 0 0
0 0 1 2 3 4 5
1 0 1 2 3 4 1 0 1 2 3 4 5
1 1 2 3 4 0
1 1 2 3 4 5 0
2 2 3 4 0 1 2 0 2 4 1 3 2 0 2 4 0 2 4
2 2 3 4 5 0 1
3 3 4 0 1 2 3 0 3 1 4 2 3 0 3 0 3 0 3
3 3 4 5 0 1 2
4 4 0 1 2 3 4 0 4 3 2 1 4 0 4 2 0 4 2
4 4 5 0 1 2 3
5 0 5 4 3 2 1
5 5 0 1 2 3 4
what’s happening here?

For addition, the permutation property For multiplication, if a row has a permutation
means you can solve, say, you can solve, say,
4 + ___ = 1 (mod 6) 5 * ___ = 4 (mod 6)
4 + ___ = x (mod 6) for any x in Z6 or, 5 * ___ = x (mod 6)
Subtraction mod n is * 0 1 2 3 4 5
well-defined + 0 1 2 3 4 5
0 0 0 0 0 0 0
0 0 1 2 3 4 5
1 0 1 2 3 4 5
Each row has a 0, 1 1 2 3 4 5 0
2 0 2 4 0 2 4
hence –a is that element 2 2 3 4 5 0 1
3 0 3 0 3 0 3
such that a + (-a) = 0 3 3 4 5 0 1 2
4 0 4 2 0 4 2
 a – b = a + (-b) 4 4 5 0 1 2 3
5 0 5 4 3 2 1
5 5 0 1 2 3 4

But if the row does not have the permutation Division


property, how do you solve
no solutions! 3 * ___ = 4 (mod 6) If you define 1/a (mod n) = a-1 (mod n)
as the element b in Zn
multiple solutions! 3 * ___ = 3 (mod 6)
such that a * b = 1 (mod n)
* 0 1 2 3 4 5
0 0 0 0 0 0 0 Then x/y (mod n)
1 0 1 2 3 4 5 =
3 * ___ = 1 (mod 6) 2 0 2 4 0 2 4 x * 1/y (mod n)
3 0 3 0 3 0 3
no multiplicative
inverse! 4 0 4 2 0 4 2 Hence we can divide out by only the y’s
5 0 5 4 3 2 1 for which 1/y is defined!

4
And which rows do have the permutation property?

* 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0 0 0
A visual way to understand 1 0 1 2 3 4 5 6 7

multiplication 2 0 2

and the 3 0 3 6 1 4 7 2 5

“permutation property”. 4 0
0
4
5
5
6 0 6

7 0 7

consider *8 on Z8

There are exactly 8 distinct There are exactly 2 distinct


multiples of 3 modulo 8. multiples of 4 modulo 8.
0 0
7 3k mod 8 7 4k mod 8
1 1

6 6
2 2

5 3 5 3

4 4

hit all numbers  row 3 has the “permutation property” row 4 does not have “permutation property” for *8 on Z8

There are exactly 1 distinct There are exactly 4 distinct


multiples of 8 modulo 8. multiples of 6 modulo 8.
0 0
7 7 6k mod 8
1 1

6 6
2 2

5 3 5 3

4 4

5
What’s the pattern? Theorem:

There are exactly


• exactly 8 distinct multiples of 3 modulo 8
• exactly 2 distinct multiples of 4 modulo 8 LCM(y,x)/x = y/GCD(x,y)
• exactly 1 distinct multiple of 8 modulo 8
• exactly 4 distinct multiples of 6 modulo 8 distinct multiples of x modulo y

y/GCD(x,y)
• exactly __________________ distinct
Hence,
multiples of x modulo y
only those values of x with GCD(x,y) = 1
have n distinct multiples
(i.e., the permutation property for *n on
Zn )

Fundamental lemma of division (or


cancelation) modulo n:
if GCD(c,n)=1, then ca n cb  a n b
If you want to extend to
general c and n
Proof:
ca n cb  a n/gcd(c,n) b
c a =n c b => n |(ca – cb) => n |c(a-b)

But GCD(n, c)=1, thus

n|(a-b) => a =n b

Fundamental lemmas mod n:


New definition:

If (x n y) and (a n b). Then


Zn* = {x  Zn | GCD(x,n) =1}

1) x + a n y + b
2) x * a n y * b Multiplication over this set Zn*
3) x - a n y – b has the cancellation property.
4) cx n cy  a n b
if gcd(c,n)=1

6
Z6 = {0,1,2,3,4,5}
We’ve got closure
Z6* = {1,5}
Recall we proved that Zn was “closed”
under addition and multiplication?
+ 0 1 2 3 4 5

What about Zn* under multiplication?


0 0 1 2 3 4 5

1 1 2 3 4 5 0

2 2 3 4 5 0 1 * 0 1 2 3 4 5

3 3 4 5 0 1 2 0 0 0 0 0 0 0 Fact: if a,b in Zn*, then a b in Zn*


4 4 5 0 1 2 3 1 0 1 2 3 4 5

5 5 0 1 2 3 4 2 0 2 4 0 2 4 Proof: if gcd(a,n) = gcd(b,n) = 1,


3 0 3 0 3 0 3
then gcd(a b, n) = 1
4 0 4 2 0 4 2
then gcd(a b mod n, n) = 1
5 0 5 4 3 2 1

Z12* = {0 ≤ x < 12 | gcd(x,12) = 1}

= {1,5,7,11} Z5* = {1,2,3,4} = Z5 \ {0}

*5 1 2 3 4
*12 1 5 7 11
1 1 2 3 4

1 1 5 7 11 2 2 4 1 3
3 3 1 4 2
5 5 1 11 7
4 4 3 2 1
7 7 11 1 5
11 11 7 5 1

Euler Phi Function (n)


For prime p, the set Zp = Zp \ {0} *

(n) = size of Zn*


= number of 1 ≤ k < n that
Proof: are relatively prime to n.
It just follows from the
definition! p prime

For prime p, all 0 < x < p satisfy  Zp*= {1,2,3,…,p-1}


gcd(x,p) = 1
 (p) = p-1

7
Z12* = {0 ≤ x < 12 | gcd(x,12) = 1}
Theorem: if p,q distinct primes then
= {1,5,7,11} (p q) = (p-1)(q-1)

(12) = 4
pq = # of numbers from 1 to pq
*12 1 5 7 11 p = # of multiples of q up to pq
q = # of multiples of p up to pq
1 1 5 7 11 1 = # of multiple of both p and q up
5 5 1 11 7 to pq
7 7 11 1 5
11 11 7 5 1 (pq) = pq – p – q + 1 = (p-1)(q-1)

Additive inverse of a mod n


= number b such that a+b=0 (mod n)
Additive
and
Multiplicative
Inverses What is the additive inverse
of a = 342952340 in
Zn = 4230493243?

Answer: n – a
= 4230493243-342952340
=3887540903

Multiplicative inverse of a mod n Multiplicative inverse of a mod n


= number b such that a*b=1 (mod n) = number b such that a*b=1 (mod n)

Remember, What is the multiplicative inverse


only defined for numbers a in Zn* of a = 342952340 in
Z4230493243 = Zn?

Answer: a-1 = 583739113

8
Theorem: given positive integers X, Y, there
How do you find exist integers r, s such that
multiplicative inverses r X + s Y = gcd(X, Y)
fast ?
and we can find these integers fast!

Now take n, and a in Zn*

gcd(a, n) ? a in Zn*  gcd(a, n) = 1

suppose ra + sn = 1
then ra =n 1
so, r = a-1 mod n

Theorem: given positive integers X, Y, there Euclid’s Algorithm for GCD


exist integers r, s such that
r X + s Y = gcd(X, Y) Euclid(A,B)
If B=0 then return A
and we can find these integers fast! else return Euclid(B, A mod B)

How?
Euclid(67,29) 67 – 2*29 = 67 mod 29 = 9
Euclid(29,9) 29 – 3*9 = 29 mod 9 = 2
Extended Euclid Algorithm
Euclid(9,2) 9 – 4*2 = 9 mod 2 = 1
Euclid(2,1) 2 – 2*1 = 2 mod 1 = 0
Euclid(1,0) outputs 1

Extended Euclid Algorithm Finally, a puzzle…


Let <r,s> denote the number r*67 + s*29.
Calculate all intermediate values in this You have a 5 gallon bottle,
representation.
a 3 gallon bottle,
and lots of water.
67=<1,0> 29=<0,1>

Euclid(67,29) 9=<1,0> – 2*<0,1> 9 =<1,-2> Can you measure out


Euclid(29,9) 2=<0,1> – 3*<1,-2> 2=<-3,7> exactly 4 gallons?
Euclid(9,2) 1=<1,-2> – 4*<-3,7> 1=<13,-30>
Euclid(2,1) 0=<-3,7> – 2*<13,-30> 0=<-29,67>

Euclid(1,0) outputs 1 = 13*67 – 30*29

9
Diophantine equations New bottles of water puzzle

You have a 6 gallon bottle,


Does the equality a 3 gallon bottle,
3x + 5y = 4 and lots of water.
have a solution where x,y are integers?
How can you measure out
exactly 4 gallons?

The linear equation


Theorem a x + b y = c
has an integer solution in x and y iff gcd(a,b)|c

The linear equation =>) gcd(a,b)|a and gcd(a,b)|b => gcd(a,b)|(a x + b y)

a x + b y = c
<=) gcd(a,b)|c => c = z * gcd(a,b)
has an integer solution in x and y iff gcd(a,b)|c
On the other hand, gcd(a,b) = x1 a + y1 b

z gcd(a,b) = z x1 a + z y1 b

c = z x1 a + z y1 b

Hilbert’s 10th problem • Working modulo integer n


• Definitions of Zn, Zn*
• Fundamental lemmas of +,-,*,/
Hilbert asked for a universal method of solving all • Extended Euclid Algorithm
Diophantine equations
• Euler phi function (n) = |Zn*|
P(x1,x2,…,xn)=0
with any number of unknowns and integer
coefficients.

Study Bee
In 1970 Y. Matiyasevich proved that the
Diophantine problem is unsolvable.

10

You might also like