Extended Euclidean Algorithm and Modular Arithmetic - Prof. Shaojie Zhang, Study notes of Computer Science

The extended euclidean algorithm, which is used to find the greatest common divisor (gcd) of two integers and determines the bezout coefficients. It also covers the concept of modular arithmetic, including the definition of congruence and theorems related to it. Examples and proofs to illustrate the concepts.

Typology: Study notes

2010/2011

Uploaded on 05/06/2011

jww1990
jww1990 🇺🇸

20 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Extended Euclidean Algorithm
After finding the GCD with the Euclidean Algorithm, start
by solving for the remainder of the step next to the last
step.
From the previous example, it would be the 3rd step:
4=3(1)+1
Solve for 1.
1=4-3(1)
Next, you want to go to the step before the one that was
worked on and solve for that remainder.
For the example, solve for 3 from the second step.
2nd step: 7=4(1)+3
3=7-4(1)
Substitute the result into the 3 in the previous equation,
1=4-3(1)
1=4-(7-4)
1=4-3(1)
Keep working your way up until you get an equation with
your GCD equaling to your arguments
Modular Definition 1:
If a and b are integers with a≠0, we say that a divides b if there is
an intger c such that b =ac. When a divides b we say that a is a
factor of b and that b is a multiple of a. The notation a|b denotes
that a divides b. We write a b when a does not divide b.∤b when a does not divide b.
Ex1:
a|b a|bc
a|b: b=a(t) b is equal to a times some num t
b(c)=a(t)(c)
Therefore, a|bc
Ex2:
Premise:
a|b, b|a, a and b are some integers
Therefore, a=b or a=-b
For a|b, a=b(t)
For b|a, b=a(s)
a=a(s)(t), then divide both sides by a (a≠0)
1=st, with s=t=1, or s=t=-1
Then, go to the previous formulas.
a mod m a=q1m + r
Euclidean Algorithm
GCD(someNum1, someNum2)
Whichever number is greater, put it on the left hand side
of the equation. For the other number, have it multiply as
many times as it can into the greater number and add the
remainder.
Ex: GCD(7, 25)
1st step: 25=7(3) + 4
Afterwards, you want to shift everything to the left. Take
the 7 and put it on the left hand side and multiply 4 into 7
as many times as it can without going over and add the
remainder.
2nd step: 7=4(1) + 3
Just rinse and repeat from here until you get a remainder
of zero. Once you get to that point, then the number
added to zero is the GCD.
3rd step: 4=3(1) + 1
4th step: 3=1(3) + 0
GCD=1
Modular Theorems
1) Let a, b, and c be a set of all integers
a) a|b + a|c a|(b+c)
b) a|b a|bc for all integers c.
c) a|b + b|c a|c
2) The Division Algorithm:
Let a be an integer. Then there are unique integers q and
r, with 0≤r<d, such that a=dq+r
3) Let a and b be integers, and let m be a positive integer.
Then a≡b(mod m) if and only if a mod m = b mod m.
4) Let m be a positive integer. The integers a and b are
congruent to modulo m if and only if there is an integer k
such that a=b+km.
5) Let m be a positive integer. If a≡b(mod m) and c≡d(mod
m), then a+c≡b+d(mod m) and ac≡bd(mod m)
a≡b mod m, m|a-b
Summations
k=0
n
a rk(r 0)
a r
n+1
a
r1,r 1
k=1
n
k
n
(
n+1
)
2
k=1
n
k2
n
(
n+1
) (
2n+1
)
6
k=1
n
k3
Prove by induction that
5|3^2n + 4^n+1 for n≥0
N=0, 3^2*0 + 4^0+1 = 5 5|5
Induction hypothesis
Assume that for n=k, kϵZ+ is followsZ+ is follows
5|[3^2k + 4^(k+1)]
Induction step
Based on the IH we have to show that 5|[3^2(k+1) + 4^(k+2)]
5|[3^(k+2)+4^(k+2)=3^2k * 3^2 + 4^(k+1) * 4]
5|[3^(k+2) + 4^(k+2) = 9*3^(2k) + 4^(k+1)*4]
(5+4)3^(2k) + 4^(k+1)*4
5(3^2k) + 3^(2k)*4 + 4^(k+1)*4
5[3^(2k) + 4(3^(2k) + 4^(k+1))]
5*3^(2k) + 4*5*someConstant
5(3^(2k) + 4*someConstant)
POOF
GCD(A, B) *LCM(A,B) = A*B
Set proof: Odd-positive integers
1 ε S
x ε S x + 2 ε S
∀xP(x)
Therefore, P(c) Universal Instantiation
P(c) for arbitrary c
Therefore, ∀xP(x) Universal generalization
∃xP(x)
Therefore, P(c) for some element C Existential
instantiation
P(c) for some element C
Therefore, ∃xP(x) Existential generalization
pf2

Partial preview of the text

Download Extended Euclidean Algorithm and Modular Arithmetic - Prof. Shaojie Zhang and more Study notes Computer Science in PDF only on Docsity!

Extended Euclidean Algorithm  After finding the GCD with the Euclidean Algorithm, start by solving for the remainder of the step next to the last step.  From the previous example, it would be the 3rd^ step:  4=3(1)+  Solve for 1.  1=4-3(1)  Next, you want to go to the step before the one that was worked on and solve for that remainder.  For the example, solve for 3 from the second step.  2 nd^ step: 7=4(1)+  3=7-4(1)  Substitute the result into the 3 in the previous equation, 1=4-3(1)  1=4-(7-4)  1=4-3(1)

 Keep working your way up until you get an equation with

your GCD equaling to your arguments Modular Definition 1: If a and b are integers with a≠0, we say that a divides b if there is an intger c such that b =ac. When a divides b we say that a is a factor of b and that b is a multiple of a. The notation a|b denotes that a divides b. We write a ∤b when a does not divide b.b when a does not divide b. Ex1: a|b  a|bc a|b: b=a(t)  b is equal to a times some num t b(c)=a(t)(c) Therefore, a|bc Ex2: Premise: a|b, b|a, a and b are some integers Therefore, a=b or a=-b For a|b, a=b(t) For b|a, b=a(s) a=a(s)(t), then divide both sides by a (a≠0) 1=st, with s=t=1, or s=t=- Then, go to the previous formulas. a mod m  a=q1m + r Euclidean Algorithm  GCD(someNum1, someNum2)  Whichever number is greater, put it on the left hand side of the equation. For the other number, have it multiply as many times as it can into the greater number and add the remainder.  Ex: GCD(7, 25)  1 st^ step: 25=7(3) + 4  Afterwards, you want to shift everything to the left. Take the 7 and put it on the left hand side and multiply 4 into 7 as many times as it can without going over and add the remainder.  2 nd^ step: 7=4(1) + 3  Just rinse and repeat from here until you get a remainder of zero. Once you get to that point, then the number added to zero is the GCD.  3 rd^ step: 4=3(1) + 1  4 th^ step: 3=1(3) + 0  GCD= Modular Theorems

  1. Let a, b, and c be a set of all integers a) a|b + a|c a|(b+c) b) a|b a|bc for all integers c. c) a|b + b|c  a|c 2) The Division Algorithm: Let a be an integer. Then there are unique integers q and r, with 0≤r<d, such that a=dq+r
  2. Let a and b be integers, and let m be a positive integer. Then a≡b(mod m) if and only if a mod m = b mod m.
  3. Let m be a positive integer. The integers a and b are congruent to modulo m if and only if there is an integer k such that a=b+km.
  4. Let m be a positive integer. If a≡b(mod m) and c≡d(mod m), then a+c≡b+d(mod m) and ac≡bd(mod m) a≡b mod m, m|a-b Summations

k = 0 n

a r

k

( r ≠ 0 ) 

a r

n + 1

− a

r − 1

,r ≠ 1

k = 1 n

k 

n ( n + 1 )

k = 1 n

k

2 

n ( n + 1 ) ( 2 n + 1 )

k = 1 n

k

3  n

2

( n + 1 )

2

Prove by induction that 5|3^2n + 4^n+1 for n≥ N=0, 3^20 + 4^0+1 = 5  5| Induction hypothesis Assume that for n=k, kϵZ+ is followsZ+ is follows 5|[3^2k + 4^(k+1)] Induction step Based on the IH we have to show that 5|[3^2(k+1) + 4^(k+2)] 5|[3^(k+2)+4^(k+2)=3^2k * 3^2 + 4^(k+1) * 4] 5|[3^(k+2) + 4^(k+2) = 93^(2k) + 4^(k+1)4] (5+4)3^(2k) + 4^(k+1) 5(3^2k) + 3^(2k)4 + 4^(k+1) 5[3^(2k) + 4(3^(2k) + 4^(k+1))] 53^(2k) + 45someConstant 5(3^(2k) + 4someConstant) POOF

GCD(A, B) LCM(A,B) = AB

Set proof: Odd-positive integers

1 ε S

x ε S  x + 2 ε S

∀xP(x)

Therefore, P(c) Universal Instantiation

P(c) for arbitrary c

Therefore, ∀xP(x) Universal generalization

∃xP(x)

Therefore, P(c) for some element C Existential

instantiation

P(c) for some element C

Therefore, ∃xP(x) Existential generalization

Modular proof examples Ex a(mod m) = b(mod m) a=q1m+r b=q2m+r a-b=(q1-q2)m a=b+(q1-q2)m q1-q2 = k a=b+km a=b(mod m) Ex a≡b(mod m)  a = b + km c≡d(mod m)  c = d + jm Theorem: a-c≡b-d(mod m) a-c ≡ b-d + (km-jm) a-c ≡ b-d+(k-j)m a-c ≡ b-d + qm a-c ≡ b-d(mod m) Set notation examples 1 ____ _ _ A∩B = A U B = {x | x ∉ A∩B} A∩B} Definition of set notation = {x | ⌐(xϵZ+ is follows(A∩B))} Definition of the negation sign = {x | ⌐(x ϵZ+ is follows A ∧ x xϵZ+ is follows B)} Definition of intersection/Distributive law = {x | ⌐(x ϵZ+ is follows A) v ⌐(x ϵZ+ is follows B)} DeMorgan’s Law = {x | x ∉ A∩B} A v x ∉ A∩B} B} Definition of negation sign _ _ = {x | x ϵZ+ is follows A v x ϵZ+ is follows B} Definition of negation sign _ _ = {x| x ϵZ+ is follows A U B } Definition of union _ _ = A U B Answer 2 A ∩ (B U C) = (A ∩ B) U (A ∩ C) ={x | x ϵZ+ is follows A ∩ (B U C)} Definition of set notation ={x | x ϵZ+ is follows A ∧ x x ϵZ+ is follows (B U C)} Definition of intersection ={x | x ϵZ+ is follows A ∧ x (x ϵZ+ is follows B v x ϵZ+ is follows C)} Definition of union ={x | (x ϵZ+ is follows A ∧ x x ϵZ+ is follows B) v (x ϵZ+ is follows A ∧ x x ϵZ+ is follows C)} Distributive law ={x | x ϵZ+ is follows (A ∩ B) U (A ∩ C)} Definitions of union and intersection = (A ∩ B) U (A ∩ C) Answer. Inductive proofs Basis step: usually P(1). -Solve for P(1) and verify that both sides are equal. Inductive hypothesis: Assume P(k) is true. -Replace n in P(n) with k. Inductive step: P(k) P(k+1) -Find P(k+1). -For the left side: Just add the next iteration to the summation. *Ex (For the left side): P(k)=1 + 2 + … + k P(k+1)=1 + 2 + … + k + (k+1) -For the right side, just plug in (k+1) for every k *Ex (For the right side): P(k)=k^ P(k+1) = (k+1)^ -Next, take the solution for P(k+1) of the right side and equate it to the P(k) of the right side plus the last term of the P(k+1) of the left side. *Ex: Consider the examples above.

  • (k+1)^2 = (k^2) + (k+1) -Manipulate algebraically until you get the right side equaling the left side. Conclusion: Since we proved that the Basis and inductive steps hold true, the statement, P(n) is true due to mathematical induction. Permutations and Combinations

Permutations : If you're picking r elements

from a set of n elements, no duplicates are

allowed, and order DOES matter, the

number of ways is:

P(n, r) = n! ( nr )!

Combinations : If you're picking r elements

from a set of n elements, no duplicates are

allowed, and order DOESN'T matter, the

number of ways is:

C(n, r) = n! r! ( nr )! List of primes 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

Induction with sets

Show set S definitely by 1 ε S and s+t ε S

when s ε S and t ε S is the set of positive

integers

Basis: 1 ε S

I.H.: Assume n ε S

I.S.: Based on I.S. and B.S.: 1 ε S thus

applying definition of S where s = n, t = 1.

It follows s + t = n + 1.

Equivalence Relations

Let R be a relation on a set A

  • R is reflexive iff a R a for every a in A
  • R is irreflexive iff a R a for no a in A
  • R is symmetric iff a R bb R a for

every a and b in A

  • R is antisymmetric iff for every distinct

a and b in A, a R b  (b, a) ∉ A∩B} R

  • R is transitive iff for every a , b , and c

in a , ( a R b ᴧ b R c )  a R c