module #9 – number theory 1/5/20161 3. algorithms, the integers and matrices

Post on 19-Jan-2016

224 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Module #9 – Number Theory

04/21/23 1

3. Algorithms, The Integers and Matrices

Module #9 – Number Theory

04/21/23 2

Section 3.4: The Integers and Division

Division:

Let a, b Z with a 0.• a |b “a divides b”.

We say that “a is a factor of b”, “a is a divisor of b”, and “b is a multiple of a”.

• a does not divide b is denoted by a | b.• We can express a | b using the quantifier

c (b = ac), Domain = Z.

3 12 True, but 3 7 False.

Module #9 – Number Theory

04/21/23 3

The Divides Relations

• For every a, b, c Z, we have1. 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 .

Examples: 3 12 and 3 9 3 (12 + 9) 3 21 (21 ÷ 3 = 7) 2 6 2 (6 × 3) 2 18 (18 ÷ 2 = 9) 4 8 and 8 64 4 64 (64 ÷ 4 = 16)

Module #9 – Number Theory

04/21/23 4

The Division Algorithm

• let a be an integer and d a positive integer, then there exist unique integers q and r such that:

a = d × q + r , 0 r < d .• d is called divisor and a is called dividend.• q is the quotient and r is the remainder (must be

positive integer).

q = a div d , r = a mod d .

Module #9 – Number Theory

04/21/23 5

Examples

• What are the quotient and remainder when 101 is divided by 11?

101 = 11 × 9 + 2,q = 101 div 11 = 9, r = 101 – 11 × 9 = 2 = 101 mod 9

• What are the quotient and the remainder when −11 is divided by 3?

−11 = 3 × (−4) + 1 , q = −4 , r = 1

• Note: − 11 3 × (− 3) − 2 because r can't be negative.

3 mod 1113)4(11

46.33

113 div 11

r

q

Module #9 – Number Theory

04/21/23 6

Examples

• Find a and b if :

2a + b = 46 mod 7 and a + 2b = 47 div 9.

46 = 6 × 7 + 4 and 47 = 5 × 9 + 2

46 mod 7 = 4 and 47 div 9 = 5

2a + b = 4 (1)

a + 2b = 5 (2)

(1) – 2×(2) → – 3b = – 6

b = 2 and a = 1.

Module #9 – Number Theory

04/21/23 7

Modular Congruence

Theorem: Let a, b Z, m Z+. We say that a is congruent to b modulo m written

a b (mod m),

if and only if

1) a mod m = b mod m , or

2) m | (a b ) i.e. (a b) mod m = 0.

Module #9 – Number Theory

04/21/23

Examples

Is 17 congruent to 5 modulo 6?

17 mod 6 = 5 and 5 mod 6 = 5,

also 6 | (17 − 5) 6 | 12 where 12 ÷ 6 = 2,

then 17 ≡ 5 (mod 6)

Is 24 congruent to 14 modulo 6?

Since, 24 mod 6 = 0 and 14 mod 6 = 2,

also 6 | (24 − 14) 6 | 10,

then, 24 ≡ 14 (mod 6).

Module #9 – Number Theory

04/21/23 9

Useful Congruence Theorems

Let a, b, c, d Z, m Z+.

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

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

2) ac bd (mod m)

e.g. Let 7 ≡ 2 (mod 5) and 11 ≡ 1 (mod 5) then:

(7 + 11) ≡ (2 + 1) (mod 5) 18 ≡ 3 (mod 5) and

(7 × 11) ≡ (2 × 1) (mod 5) 77 ≡ 2 (mod 5).

Module #9 – Number Theory

04/21/23 10

Cryptology• Caesar’s encryption method can be represented by the

function f (p) = (p + 3) mod 26, 0 ≤ p ≤ 25. The letter “A” is replaced by 0, “B” by 1, …, and “Z” by 25.

e.g. What is the secret message produce from the message “GOOD MORNING ZERO”?

First replace the letters in the message with numbers

p : 6 14 14 3 12 14 17 13 8 13 6 25 4 17 14

Second replace p by f (p)

f (p) : 9 17 17 6 15 17 20 16 11 16 9 2 7 20 17

Translate this back to letters produces the encrypted message

“JRRG PRUQLQJ CHUR ”

• To recover the original message from a secrete message. The inverse function f -1(p) = (p – 3) mod 26 can be used. This process is called decryption.

Module #9 – Number Theory

04/21/23 11

Hashing Functions

Suppose that a computer has only the 20 memory locations 0, 1, 2, …, 19. Use the hashing function h where

h(x) = (x + 5) mod 20

to determine the memory locations in which 57, 32, and 98 are stored.

•h(57) = (57 +5) mod 20 = 62 mod 20 = 2

•h(32) = 37 mod 20 = 17

•h(98) = 103 mod 20 = 3

Module #9 – Number Theory

04/21/23 12

Section 3.5: Primes and Greatest Common Divisors

• A positive integer p > 1 is prime if the only positive factors of p are 1 and p.

Some primes: 2, 3, 5, 7, 11, 13, 17, ...• Non-prime integer greater than 1 are called

composite, because they can be composed by multiplying two integers greater than 1.

Module #9 – Number Theory

04/21/23 13

Fundamental Theorem of Arithmetic

• Every positive integer greater than 1 has a unique representation as a prime or as the product of two or more primes where the prime factors are written in order of non-decreasing size. (tree or division) 100 = 2·2·5·5 = 2252 13 = 13

1024 = 2·2·2·2·2·2·2·2·2·2 = 210

Module #9 – Number Theory

04/21/23 14

Theorem

• If n is a composite integer, then n has prime divisor ≤

e.g. 49 prime numbers less than are 2, 3, 5, 7

16 prime numbers less than are 2, 3.

• An integer n is prime if it is not divisible by any prime ≤

e.g. 13 where = 3.6 so the prime numbers are 2, 3 but non of them divides 13 so 13 is prime.

.n

.n

16

49

13

Module #9 – Number Theory

04/21/23 15

• To find the prime factor of an integer n :1. Find 2. List all primes ≤ 2, 3, 5, 7, … , up to 3. Find all prime factors that divides n.

.n

,n

Prime Factorization Technique

.n

Module #9 – Number Theory

04/21/23 16

Example 1

Module #9 – Number Theory

04/21/23 17

Example 2

Module #9 – Number Theory

04/21/23

Example 3

Module #9 – Number Theory

04/21/23 19

Greatest Common Divisors

• The greatest common divisor gcd(a, b) of integers a, b (not both 0) is the largest (most positive) integer d that is a divisor both of a and of b.

• To find gcd: 1. Find all positive common divisors of both a and b, then take the largest divisor:

e.g Find gcd (24, 36)? Divisors of 24: 1, 2, 3, 4, 6, 8, 12, 24 Divisors of 36: 1, 2, 3, 4, 6, 9, 12, 18, 36 Common divisors: 1, 2, 3, 4, 6, 12 Maximum = 12, so gcd (24, 36) = 12

Module #9 – Number Theory

04/21/23 20

2. Use prime factorization:

Take the minimum power of common factors

Example: Find gcd(24, 180)

24 = 2×2×2×3 = 23×3

180 = 2×2×3×3 = 22×32×5

gcd(24, 36) = 2min(3,2)×3min(1,2)×5min(0,1) = 22×31 = 12

Ways to Find GCD

Module #9 – Number Theory

04/21/23 21

• Find gcd (360, 3500)?360 = 23 × 32 × 53500 = 22 × 53 × 7

gcd (360, 3500) = 22 × 5 = 20

• Find gcd(17, 22)? No common divisors so gcd(17, 22) = 1 so, the

numbers 17 and 22 are called relatively prime.

Examples

Module #9 – Number Theory

04/21/23 22

Least Common Multiple

• lcm(a, b) of positive integers, a and b, is the smallest positive integer that is a multiple both of a and of b.

• Find lcm(6, 10)? Take the maximum power of all factors

6 = 2 × 3 , 10 = 2 × 5 lcm(6, 10) = 2max(1,1)×3max(1,0)×5max(0,1) = 2×3×5 = 30

• Find lcm (24, 180)?24 = 23 × 31 , 180 = 22 × 32 × 5

lcm (24, 36) = 23 × 32 × 5 = 360.

Module #9 – Number Theory

Section 3.6: Integers and Algorithms

Introduction:

The term algorithm originally referred to procedures for performing arithmetic operations using the decimal representations of integers. These algorithms, adapted for use with binary representations, are the basis for computer arithmetic.

04/21/23 23

Module #9 – Number Theory

Representations of Integers

In everyday life we use decimal notation to express integers.

For example, 965 is used to denote

9·102 + 6·10 + 5 .

However, it is often convenient to use bases other than 10.

Module #9 – Number Theory

Computers usually use binary notation (with 2 as the base) when carrying out arithmetic, and octal (base 8) or hexadecimal (base 16) notation when expressing characters, such as letters or digits. In fact, we can use any positive integer greater than 1 as the base when expressing integers.

04/21/23 25

Representations of Integers

Module #9 – Number Theory

Binary Expansions (Binary to Decimal)

What is the decimal expansion of the integer that has (101011111)2 as its binary expansion?

Solution: We have

(l 01011111)2 = 1·28 + 0·27 + 1·26 + 0·25 + 1·24

+ 1·23 + 1· 22 + 1·21 + 1·20

= 256 + 64 + 16 + 8 + 4 + 2 + 1

= 351.

04/21/23 26

Module #9 – Number Theory

Decimal system0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 1 2 3 4 5 6 7 8 9 A B C D E F

Hexadecimal system

Hexadecimal Expansions

Module #9 – Number Theory

28

• What is the decimal expansion of the hexadecimal expansion of (2AE0B)16 ?

Solution: We have

(2AE0B)16 = 2·164 + 10·163 + 14·162 + 0·16 + 11

= (175627)10 .

• (3016)7 = 3·73 + 0·72 + 1·7 + 6 = (356)10 .

Any to Decimal

Module #9 – Number Theory

Find the binary expansion of (241)10 .

Solution: First divide 241 by 2 to obtain

241 = 2 . 120 + 1 .

Successively dividing quotients by 2 gives

120 = 2 · 60 + 0

60 = 2 · 30 + 0

30 = 2 · 15 + 0

15 = 2 · 7 + 1

7 = 2 · 3 + 1

3 = 2 · 1 + 1

1 = 2 · 0 + 1

Therefore, (241)10 = (11110001)2 29

Base Conversion (Decimal to Any)

divmod

0

1

3

7

15

30

60

120

2241

1

1

1

1

0

0

0

1

Module #9 – Number Theory

Find the base 8 expansion of (12345)10 .

Solution:

First, divide l2345 by 8 to obtain

12345 = 8 · 1543 + 1.

Successively dividing quotients by 8 gives:

1543 = 8 · 192 + 7,

192 = 8 · 24 + 0,

24 = 8 · 3 + 0,

3 = 8 · 0 + 3.

Therefore, (12345)10 = (30071)8.30

Decimal to Any

0

3

24

192

1543

12345

3

0

0

7

1

Module #9 – Number Theory

Find the hexadecimal expansion of (177130)10.

Solution:

177130 = 16 · 11070 + 10

11070 = 16 · 691 + 14 ,

691 = 16 · 43 + 3 ,

43 = 16 · 2 + 11 ,

2 = 16 · 0 + 2.

Therefore, (177130)10 = (2B3EA)16

31

Example

0

2

43

691

11070

177130

2

11

3

14

10

Module #9 – Number Theory

32

Binary Octal Hexadecimal

1117

1106

1015

1004

0113

0102

0011

0000

BinaryOctal

1111F

1110E

1101D

1100C

1011B

1010A

10019

10008

01117

01106

01015

01004

00113

00102

00011

00000

BinarylHexadecima

216

28

)011110110101()7B5(

)111000011()307(

16

2

2

)D53(

)1101,0011,0101(

)11010011110(

162

28

)7A1()0111,1000,0001(

)111,000,110()607(

Module #9 – Number Theory

04/21/23 33

Section 3.8: Matrices

• An m×n matrix is a rectangular array of mn objects (usually numbers) arranged in m horizontal rows and n vertical columns.

• An nn matrix is called a square matrix, whose order is n.

07

15

32

32

13

12

22

Module #9 – Number Theory

04/21/23 34

Matrix Equality

• Two matrices A and B are equal if and only if they have the same number of rows, the same number of columns, and all corresponding elements are equal.

061

023

61

23

Module #9 – Number Theory

04/21/23 35

Row and Column Order

• The rows in a matrix are usually indexed 1 to m from top to bottom. The columns are usually indexed 1 to n from left to right. Elements are indexed by row, then column.

mnmm

n

n

ij

aaa

aaa

aaa

aA

21

22221

11211

][

Module #9 – Number Theory

04/21/23 36

Matrix Sums

• The sum A + B of two matrices A, B (which must have the same number of rows, and the same number of columns) is the matrix given by adding corresponding elements.

• A + B = [aij + bij]

8

9

1

4

4

9

6

1

5

3

4

7

2

8

6

1

0

2

Module #9 – Number Theory

04/21/23 37

Matrix Products

For an mk matrix A and a kn matrix B, the product AB is the mn matrix:

i.e. The element (i, j ) of AB is given by the vector dot product of the ith row of A and the jth column of B (considered as vectors).

Note: Matrix multiplication is not commutative!

k

ppjipij bacCAB

1

][

Module #9 – Number Theory

04/21/23 38

Matrix Product Example

31123

1501

1301

0202

0110

302

110

2×3 3×4 2×4

Module #9 – Number Theory

04/21/23 39

Identity Matrices

• The identity matrix of order n, In , is the order-n matrix with 1’s along the upper-left to lower-right diagonal and 0’s everywhere else.

• A In = A

100

010

001

if 0

if 1

ji

jiIn

Module #9 – Number Theory

04/21/23 40

Powers of Matrices

• If A is an nn square matrix and p 0, then:

Ap AAA ··· A (A0 In)

p times

23

34

12

23

01

12

01

12

01

12

01

12

01

123

Module #9 – Number Theory

04/21/23 41

• If A is an mn matrix, then the transpose of A is the nm matrix AT given by interchanging the rows and the columns of A.

Matrix Transposition

23

11

02

210

312 TAA

Module #9 – Number Theory

04/21/23 42

Symmetric Matrices

• A square matrix A is symmetric if and only if AT = A.

• Which is symmetric?

A B C

211

120

103

213

101

312

11

11

11

Module #9 – Number Theory

04/21/23 43

Zero-One Matrices

All elements of a zero-one matrix are 0 or 1, representing False & True respectively.

• The join of A and B (both mn zero-one matrices) is

A B : [aij bij].

• The meet of A and B is:

A B [aij bij].

Module #9 – Number Theory

04/21/23 44

Example

A = B =

• The join between A and B is A B =

• The meet between A and B is A B =

010

101

011

010

011

111

010

000

Module #9 – Number Theory

04/21/23 45

Boolean Products

• Let A be an m k zero-one matrix and B be a k n zero-one matrix,

• The Boolean product A⊙B of A and B is like

normal matrix product, but using instead +

and using instead .

Module #9 – Number Theory

04/21/23 46

Boolean Powers

• For a square zero-one matrix A, and any k 0, the kth Boolean power of A is simply the Boolean product of k copies of A.

A[k] A⊙A⊙…⊙A

k times

Module #9 – Number Theory

04/21/23 47

Example

Let A = and B =

01

10

01

110

011

A⊙B =

(1 1) (0 0) (1 1) (0 1) (1 0) (0 1)

(0 1) (1 0) (0 1) (1 1) (0 0) (1 1)

(1 1) (0 0) (1 1) (0 1) (1 0) (0 1)

011

110

011

top related