52
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 that there exists an integer m for which b=am. Other ways of saying the same thing: a is a divisor of b a is a factor of b b is a multiple of a a goes evenly into b

3.4/3.5 The Integers and Division/ Primes and Greatest Common Divisors

Embed Size (px)

DESCRIPTION

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 that there exists an integer m for which b=am . Other ways of saying the same thing: a is a divisor of b a is a factor of b - PowerPoint PPT Presentation

Citation preview

Page 1: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

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 that there exists an integer m for which b=am.

• Other ways of saying the same thing:– a is a divisor of b– a is a factor of b– b is a multiple of a– a goes evenly into b

Page 2: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem

For all integers a, b, and c:

1. If a | b and a | c, then a | (b + c).

2. If a | b then a | bc.

3. If a | b and b | c, then a | c.

Corollary: If a | b and a | c, then for all integers m and n we have a | (mb+nc).

Page 3: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Prove that if and , then .

Page 4: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Primes

• A prime is ….

Page 5: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

The Fundamental Theorem of Arithmetic

Every positive integer is either a prime or can be expressed as a product of primes in a unique way

A composite is defined to be a positive integer > 1 which is not a prime.

Page 6: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Divisibility by 3 and 9

• Theorem: An integer is divisible by 3 if and only if the sum of the digits in its decimal representation is divisible by 3.

• Theorem: An integer is divisible by 9 if and only if the sum of the digits in its decimal representation is divisible by 9.

Page 7: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Divisibility by 7

• Theorem: A number of the form 10x + y is divisible by 7 if and only if x – 2y is divisible by 7.

Examples:

399 2164

Page 8: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem

If n is a composite, then n has a prime divisor less than or equal to

Let us use this fact to prove that 197 is prime.

n

Page 9: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Performing Prime Factorizations

• Use the above theorem, applied iteratively• Example: 980

Page 10: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem

There are infinitely many primes

Page 11: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

The Sieve of Eratosthenes

Page 12: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

The “Division Algorithm”

Let a be an integer and d a positive integer. Then there exist unique integers q and r for which

(i) a = dq + r, and

(ii) 0 ≤ r < d

Our symbolism for q is a div d (the quotient), and for r it is a mod d (the remainder).

Page 13: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Greatest Common Divisor and Least Common Multiple

Page 14: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem: Let p be a prime appearing m times in the prime factorization of a and n times in the prime factorization of b. Then (a) p appears times in the prime factorization of gcd(a,b), and (b) p appears times in the prime factorization of lcm(a,b).

Page 15: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Modular Arithmetic

• Define, for integers a and b and positive integer m,

a b (mod m) m | (b – a)

• Theorems:

1. a b (mod m) a mod m = b mod m

2. a b (mod m) kmbaZk such that

Page 16: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem

If a b (mod m) and c d (mod m) then

(a) a+c b+d (mod m), and

(b) ac bd (mod m)

Page 17: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Prove and then .

Page 18: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

General Principle for Modular Arithmetic

• When the answer to your computation is to be a “mod m” result, you may discard multiples of m freely as you compute!

• Note that the remainder mod 9 of any integer is the same as the remainder mod 9 of the sum of its digits.

• Example: – What is (23459 49823 + 297) mod 9?

Page 19: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Example

• Today is • On what day of the week will today’s date

fall…– Next year?– Ten years from now?

• When will today’s date next fall on a ?

Page 20: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Definition

• Two integers a and b are said to be relatively prime provided gcd(a,b) = 1

Page 21: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem

• For two positive integers a and b, the product gcd(a,b) lcm(a,b) is equal to the product ab.

Page 22: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Does the mod n Function work well as a hashing function?

KEYS:

1880189019001910Etc.

n = 15

Page 23: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Linear Congruential Pseudo-Random Number Generators

xn = (axn-1 + c) mod m

Example: m = 231–1, a = 75, c = 0

Example: m = 11, a = 5, c = 2, x0=3

Page 24: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem:

If a and b are positive integers, then

gcd(a,b) = gcd(a, b mod a)

3.6 Integers and Algorithms

Page 25: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

The Euclidean Algorithm

procedure gcd(a, b: positive integers)

x := a

y := b

while y 0begin

r := x mod y

x := y

y := r

end

{ The gcd of a and b is now stored in the variable x }

Page 26: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors
Page 27: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Theorem

Let bZ, b > 1. Then any positive integer n can be uniquely expressed as

n = akbk+ak-1bk-1+…+a1b+a0

where k is a non-negative integer, and a0, a1, …, ak are non-negative integers < b, and ak 0.

This is our authority for using the “base b” expansion of the positive integer n, where specific symbols (like the arabic digits) are assigned to the integers a with 0 ≤ a < b and we can write the number n as akak-1ak-2…a1a0

Page 28: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Examples

• Binary

• Octal

• Decimal

• Hexadecimal

Page 29: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Converting from Decimal to Binary

• Example: 190

Page 30: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Conversions Continued

• Decimal to hexadecimal

• Decimal to octal

Page 31: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Conversions Continued

• Hexadecimal to Decimal

• Octal to Decimal

Page 32: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Conversions Continued

• Binary to and from Hexadecimal

• Binary to and from Octal

Page 33: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Conversions Continued

• Octal to and from Hexadecimal – Just use binary as a go-between

Page 34: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

3.8 – Matrices

• A matrix is a rectangular array of numbers

• Notation

mnmm

n

n

aaa

aaa

aaa

A

...

............

...

...

21

22221

11211

Page 35: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Special Cases

• If m = 1 we have a row matrix• If n = 1 we have a column matrix• Shorthand notation: A = [aij]

mnmm

n

n

aaa

aaa

aaa

A

...

............

...

...

21

22221

11211

Page 36: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Matrix Arithmetic

• Addition and Subtraction

• Scalar product

5 [1 22 7 ]=¿

Page 37: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Matrix Multiplication

• If A = [aij] and B = [bij], where A is an m by n matrix and B is an n by p matrix, then their product AB is the m by p matrix C = [cij] whose entries are given by

n

kkjikij bac

pjmi

1

},,...,2,1{},,...,2,1{

Page 38: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Example of Matrix Multiplication

[ 1 2 4−1 − 3 0 ] [7 4

5 − 13 6 ]

Page 39: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Algorithm for Matrix Multiplication

procedure multiply(A: m by n matrix, B: n by p matrix)

for i:=1 to m do

for j:=1 to p do

begin

cij = 0

for k:=1 to n do

cij = cij + aikbkj

end

{ The matrix [cij] is the matrix product of A and B }

Page 40: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Matrix-Chain Multiplication

• What is the most efficient way to compute a three-way product ABC, where A is m by n, B is n by p, and C is p by q?

• Grouping as (AB)C, we get mnp + mpq multiplications

• Grouping as A(BC), we get npq + mnq multiplications

• Theoretically, the result is the same, so we should choose the order which gives the fewest multiplications.

• Example: 5 by 3 times 3 by 4 times 4 by 2

Page 41: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors
Page 42: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

The Identity Matrix

• For any positive integer n, the n by n matrices under matrix multiplication have an identity. It is

1...000

...............

0...100

0...010

0...001

nI

Page 43: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Powers of a Square Matrix

• For an n by n matrix A = [aij], we can define A2=AA, A3=AA2, etc.

• Example:

Page 44: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

𝐴=[1 10 1]

Example:

Find a formula for .

Page 45: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Transpose Matrix

• For an m by n matrix A = [aij], we can define the transpose At of A to be the n by m matrix whose rows are the columns of A and whose columns are the rows of A. i.e. if B = [bij] is A’s transpose, then for all relevant values of i and j, bij = aji

• Example:

[1 2 22 0 0

74 ]

𝑡

Page 46: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Symmetric Matrices

• A square matrix A is said to be symmetric if A = At

[ 3 0 3 73 0 127

−11250

1716

− 150164

]

Page 47: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Zero-One Matrices

• A zero-one matrix is one in which all the entries are zeros or ones.

• The join of two matrices and is the “pairwise ‘or’” of their entries

• The meet of two matrices and is the “pairwise ‘and’” of their entries

[0 1 01 1 10 0 1 ]∨[ 1 1 0

0 0 01 1 1]

Page 48: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Zero-One Matrix Multiplication

• If A = [aij] and B = [bij], where A is an m by n zero-one matrix and B is an n by p zero-one matrix, then their boolean product A B is the m by p matrix C = [cij] whose entries are given by

kjik

n

k

ij bac

pjmi

1

},,...,2,1{},,...,2,1{

Page 49: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Examples

=

Page 50: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Zero-One Matrix Powers

[1 11 0 ]=𝐴

𝐴[2 ]=¿

For a zero-one matrix, define

Example:

Page 51: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

For matrices (i.e. square matrices), we say that matrix has an inverse provided . We call the inverse of and denote by Not all square matrices have inverses. If a matrix does have an inverse, then it is unique.

Inverses

𝐴=[𝑎 𝑏𝑐 𝑑]𝐴−1=¿

Page 52: 3.4/3.5  The Integers and Division/ Primes and Greatest Common Divisors

Example: