The Euclidean Algorithm

Slides:



Advertisements
Similar presentations
Chapter Matrices Matrix Arithmetic
Advertisements

February 26, 2015Applied Discrete Mathematics Week 5: Mathematical Reasoning 1 Addition of Integers Example: Add a = (1110) 2 and b = (1011) 2. a 0 + b.
CSE115/ENGR160 Discrete Mathematics 03/13/12 Ming-Hsuan Yang UC Merced 1.
Number Theory and Cryptography
CSE115/ENGR160 Discrete Mathematics 03/17/11 Ming-Hsuan Yang UC Merced 1.
1 Section 2.5 Integers and Algorithms. 2 Euclidean algorithm for finding gcd Where L is a larger number, and S is a smaller number, to find gcd(L,S):
Fall 2002CMSC Discrete Structures1 Let us get into… Number Theory.
CSCI 1900 Discrete Structures
CSE 504 Discrete Mathematics & Foundations of Computer Science
February 25, 2002Applied Discrete Mathematics Week 5: Mathematical Reasoning 1 Addition of Integers How do we (humans) add two integers? Example: 7583.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
February 24, 2015Applied Discrete Mathematics Week 4: Number Theory 1 Modular Arithmetic Let a be an integer and m be a positive integer. We denote by.
3.4/3.5 The Integers and Division/ Primes and Greatest Common Divisors Let each of a and b be integers. We say that a divides b, in symbols a | b, provided.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
Chapter Integers and Algorithms Representations of integers
Prepared by Deluar Jahan Moloy Lecturer Northern University Bangladesh
Foundations of Discrete Mathematics Chapter 4 By Dr. Dalia M. Gil, Ph.D.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
Module #9 – Number Theory 1/5/ Algorithms, The Integers and Matrices.
Greatest Common Divisors & Least Common Multiples  Definition 4 Let a and b be integers, not both zero. The largest integer d such that d|a and d|b is.
2.5 – Determinants and Multiplicative Inverses of Matrices.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
Systems of Equations and Matrices Review of Matrix Properties Mitchell.
Ch04-Number Theory and Cryptography 1. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic.
Module #9 – Number Theory 6/11/20161 Chapter 3 Algorithms, Integers and Matrices.
Number Theory Lecture 1 Text book: Discrete Mathematics and its Applications, 7 th Edition.
Chapter 3 The Fundamentals: Algorithms, the integers, and matrices Section 3.4: The integers and division Number theory: the part of mathematics involving.
Number Theory. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic principles of divisibility,
Linear Algebra by Dr. Shorouk Ossama.
CSE15 Discrete Mathematics 03/01/17
CSE 504 Discrete Mathematics & Foundations of Computer Science
CSNB 143 Discrete Mathematical Structures
13.4 Product of Two Matrices
Matrices and Matrix Operations
Properties and Applications of Matrices
MATRICES.
CSE15 Discrete Mathematics 03/15/17
Discrete Structures – CNS2300
Applied Discrete Mathematics Week 5: Mathematical Reasoning
1.5 Matricies.
MATHEMATICS Matrix Algebra
CMSC Discrete Structures
DETERMINANTS A determinant is a number associated to a square matrix. Determinants are possible only for square matrices.
CSE 504 Discrete Mathematics & Foundations of Computer Science
Number Theory and Cryptography
Dr. Ameria Eldosoky Discrete mathematics
Applied Discrete Mathematics Week 4: Number Theory
Applied Discrete Mathematics Week 4: Number Theory
Section 7.4 Matrix Algebra.
Sequences and Summations
Number Theory.
Foundations of Discrete Mathematics
Enough Mathematical Appetizers!
Week #5 – 23/25/27 September 2002 Prof. Marie desJardins
Section 2.4 Matrices.
Matrices Introduction.
CS100: Discrete structures
CMSC 203, Section 0401 Discrete Structures Fall 2004 Matt Gaston
Matrix Algebra.
Representations of Integers
Properties of Relations
Divisibility and Modular Arithmetic
Section 9.4 Matrix Operations
Discrete Mathematics and its Applications
Number Theory.
3.8 Matrices L Al-zaid Math1101.
Applied Discrete Mathematics Week 4: Functions
Presentation transcript:

The Euclidean Algorithm In pseudocode, the algorithm can be implemented as follows: procedure gcd(a, b: positive integers) x := a y := b while y  0 begin r := x mod y x := y y := r end {x is gcd(a, b)} February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Representations of Integers Let b be a positive integer greater than 1. Then if n is a positive integer, it can be expressed uniquely in the form: n = akbk + ak-1bk-1 + … + a1b + a0, where k is a nonnegative integer, a0, a1, …, ak are nonnegative integers less than b, and ak  0. Example for b=10: 859 = 8102 + 5101 + 9100 February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Representations of Integers Example for b=2 (binary expansion): (10110)2 = 124 + 122 + 121 = (22)10 Example for b=16 (hexadecimal expansion): (we use letters A to F to indicate numbers 10 to 15) (3A0F)16 = 3163 + 10162 + 15160 = (14863)10 February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Representations of Integers How can we construct the base b expansion of an integer n? First, divide n by b to obtain a quotient q0 and remainder a0, that is, n = bq0 + a0, where 0  a0 < b. The remainder a0 is the rightmost digit in the base b expansion of n. Next, divide q0 by b to obtain: q0 = bq1 + a1, where 0  a1 < b. a1 is the second digit from the right in the base b expansion of n. Continue this process until you obtain a quotient equal to zero. February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Representations of Integers Example: What is the base 8 expansion of (12345)10 ? First, divide 12345 by 8: 12345 = 81543 + 1 1543 = 8192 + 7 192 = 824 + 0 24 = 83 + 0 3 = 80 + 3 The result is: (12345)10 = (30071)8. February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Representations of Integers procedure base_b_expansion(n, b: positive integers) q := n k := 0 while q  0 begin ak := q mod b q := q/b k := k + 1 end {the base b expansion of n is (ak-1 … a1a0)b } February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Addition of Integers How do we (humans) add two integers? Example: 7583 + 4932 1 1 1 carry 1 2 5 1 5 1 1 carry Binary expansions: (1011)2 + (1010)2 ( )2 1 1 1 February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Addition of Integers Let a = (an-1an-2…a1a0)2, b = (bn-1bn-2…b1b0)2. How can we algorithmically add these two binary numbers? First, add their rightmost bits: a0 + b0 = c02 + s0, where s0 is the rightmost bit in the binary expansion of a + b, and c0 is the carry. Then, add the next pair of bits and the carry: a1 + b1 + c0 = c12 + s1, where s1 is the next bit in the binary expansion of a + b, and c1 is the carry. February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Addition of Integers Continue this process until you obtain cn-1. The leading bit of the sum is sn = cn-1. The result is: a + b = (snsn-1…s1s0)2 February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Addition of Integers Example: Add a = (1110)2 and b = (1011)2. a0 + b0 = 0 + 1 = 02 + 1, so that c0 = 0 and s0 = 1. a1 + b1 + c0 = 1 + 1 + 0 = 12 + 0, so c1 = 1 and s1 = 0. a2 + b2 + c1 = 1 + 0 + 1 = 12 + 0, so c2 = 1 and s2 = 0. a3 + b3 + c2 = 1 + 1 + 1 = 12 + 1, so c3 = 1 and s3 = 1. s4 = c3 = 1. Therefore, s = a + b = (11001)2. February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Addition of Integers procedure add(a, b: positive integers) c := 0 for j := 0 to n-1 {larger integer (a or b) has n digits} begin d := (aj + bj + c)/2 sj := aj + bj + c – 2d c := d end sn := c {the binary expansion of the sum is (snsn-1…s1s0)2} February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Matrices A matrix is a rectangular array of numbers. A matrix with m rows and n columns is called an mn matrix. Example: is a 32 matrix. A matrix with the same number of rows and columns is called square. Two matrices are equal if they have the same number of rows and columns and the corresponding entries in every position are equal. February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Matrices A general description of an mn matrix A = [aij]: j-th column of A i-th row of A February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Applied Discrete Mathematics Week 4: Number Theory Matrix Addition Let A = [aij] and B = [bij] be mn matrices. The sum of A and B, denoted by A+B, is the mn matrix that has aij + bij as its (i, j)th element. In other words, A+B = [aij + bij]. Example: February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Matrix Multiplication Let A be an mk matrix and B be a kn matrix. The product of A and B, denoted by AB, is the mn matrix with (i, j)th entry equal to the sum of the products of the corresponding elements from the i-th row of A and the j-th column of B. In other words, if AB = [cij], then February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Matrix Multiplication A more intuitive description of calculating C = AB: - Take the first column of B Turn it counterclockwise by 90 and superimpose it on the first row of A Multiply corresponding entries in A and B and add the products: 32 + 00 + 13 = 9 Enter the result in the upper-left corner of C February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Matrix Multiplication Now superimpose the first column of B on the second, third, …, m-th row of A to obtain the entries in the first column of C (same order). Then repeat this procedure with the second, third, …, n-th column of B, to obtain to obtain the remaining columns in C (same order). After completing this algorithm, the new matrix C contains the product AB. February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory

Matrix Multiplication Let us calculate the complete matrix C: 9 7 8 15 15 20 -2 -2 February 16, 2017 Applied Discrete Mathematics Week 4: Number Theory