70
C-N Math 207 Discrete Math Kenneth Massey September 16, 2011 C-N Math 207 - Massey, 1 / 70

C-N Math 207 Discrete Math

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: C-N Math 207 Discrete Math

C-N Math 207Discrete Math

Kenneth Massey

September 16, 2011

C-N Math 207 - Massey, 1 / 70

Page 2: C-N Math 207 Discrete Math

Introduction

Question

What is the smallest positive number?

C-N Math 207 - Massey, 2 / 70

Page 3: C-N Math 207 Discrete Math

Introduction

Sets

I a set S is a collection of objects (members,elements)

I S = {VT ,UNC ,GT ,Mia ,UVA,Duke}I the cardinality (size) of S is written as |S |

I S is finite if |S | <∞, and infinite if |S | =∞I empty / null set ∅ = { }, |∅| = 0I “x is an element of S ” is denoted by x ∈ S

C-N Math 207 - Massey, 3 / 70

Page 4: C-N Math 207 Discrete Math

Introduction

Numbers

Abstract notions of quantity, position, or size.I natural numbers N = {0, 1, 2, 3, · · · }(use N+ to omit zero)

I integers Z = {· · · ,−2,−1, 0, 1, 2, 3, · · · }I set-builder notation:members “such that” conditions

I rational numbers Q = {nd | n , d ∈ Z, d 6= 0}I real numbers R is the continuumof all points on number lineincluding irrationals e.g.

√2, π

C-N Math 207 - Massey, 4 / 70

Page 5: C-N Math 207 Discrete Math

Introduction

Set Examples

1. S = {x ∈ Z | |x − 5| ≤ 2}2. S = {1, 12 ,

14,

18 , · · · }

3. S = {(x , y) ∈ R2 | x 2 + y2 ≤ 1}4. S = {ticker symbols of S&P 500 members}

C-N Math 207 - Massey, 5 / 70

Page 6: C-N Math 207 Discrete Math

Introduction

Discrete vs ContinuousI A set is discrete if its members can be listed(enumerated) so that each has a “next”(successor), with nothing in-between

I all finite sets are discrete (loop)I examples:

1. “digital” computers2. money (Office Space rounding)3. siblings (1

2 allowed)4. water discrete, but practically continuous5. “quantum” physics6. movie frames vs real time?7. Z vs R, Q ?

C-N Math 207 - Massey, 6 / 70

Page 7: C-N Math 207 Discrete Math

Introduction

Existence and Uniqueness

I “there exists” is denoted by ∃∃x ∈ Z | x 2 = 9

I ∃! means “there exists a unique”∃! x ∈ R | 3x + 4 = 10

I slash through a symbol means “not”@x ∈ Q | x 2 = 2

C-N Math 207 - Massey, 7 / 70

Page 8: C-N Math 207 Discrete Math

Introduction

If-Then Statements

“If (condition) then (conclusion)”I The conclusion must be true whenever thecondition is true.

I Any exception (counter-example) means theif-then statement is false.

I If c ∈ Z, then ∃x ∈ R | x 2 + 6x = c

C-N Math 207 - Massey, 8 / 70

Page 9: C-N Math 207 Discrete Math

Introduction

Function

f : A→ B is a function that pairs each memberof set A with a unique member of set B .I y = f (x ) where x ∈ A and y ∈ BI the set A is called the domainI the set B is called the codomainI {b ∈ B | ∃a ∈ A with f (a) = b} is called therange or image of f

C-N Math 207 - Massey, 9 / 70

Page 10: C-N Math 207 Discrete Math

Introduction

Function Examples

1. f : R→ R defined by y = f (x ) = x 2

2. f : Z→ N defined by y = f (x ) = x 2

3. f : N→ N defined by y = f (n) = b√

nc4. f : N+ → Q defined by f (n) = n+1

n

Which are onto (range equals codomain)?Which are one-to-one (no “y” value hit twice)?

C-N Math 207 - Massey, 10 / 70

Page 11: C-N Math 207 Discrete Math

Introduction

Invertible Function

I f is said to be invertible if each y in B ismapped to exactly once

I f −1 : B → A is a function that reverses fI To find the inverse, solve for x .

x = f −1(y)I the composition of a function and itsinverse is the identity function f −1 ◦ f = If −1(f (x )) = x and f (f −1(y) = y

C-N Math 207 - Massey, 11 / 70

Page 12: C-N Math 207 Discrete Math

Introduction

Sequence

A sequence is a function whose domain is somesubset of Z (often N).I an ordered indexed list, f (k) = fkI geometric sequence ak = r k for some r ∈ RI harmonic sequence

{ 1k

}∞k=1

C-N Math 207 - Massey, 12 / 70

Page 13: C-N Math 207 Discrete Math

Introduction

Sum NotationCapital Greek sigma Σ indicates “the sum of”indexed terms, e.g.

6∑k=3

k 2 = 32 + 42 + 53 + 62 = 86

∞∑k=1

110k = .1+ .01+ .001+ · · · = .11111 =

19

an =

n∑k=1

k =n(n + 1)

2

C-N Math 207 - Massey, 13 / 70

Page 14: C-N Math 207 Discrete Math

Introduction

Product Notation

Capital Greek pi Π indicates “the product of”indexed terms, e.g.

4∏k=1

k + 1k

= (2/1)(3/2)(4/3)(5/4) = 5

C-N Math 207 - Massey, 14 / 70

Page 15: C-N Math 207 Discrete Math

Introduction

Factorials

n factorial is defined for n ∈ N by

n ! =

{∏nk=1 k n ≥ 1

1 n = 0

I the sequence of factorials is1, 1, 2, 6, 24, 120, · · ·

I n ! = n · (n − 1)!

C-N Math 207 - Massey, 15 / 70

Page 16: C-N Math 207 Discrete Math

Integers

IntegersI Z is discrete, but infiniteI Subsets of Z can be used to label otherdiscrete sets.

I Arithmetic operations: addition (+) andmultiplication (·)

I Basic properties: closed, commutative,associative, distributive, identities, inverses,ordered

I Number theory is the branch ofmathematics that studiesthe properties of Z.

C-N Math 207 - Massey, 16 / 70

Page 17: C-N Math 207 Discrete Math

Integers

Division Algorithm

Note that 173 = 5+ 2

3 can be written as

17 = 3 · 5+ 2

Division algorithm: let a , b ∈ Z, with b 6= 0,then ∃! q , r ∈ Z such that

a = bq + r , 0 ≤ r < |b|

q is called the quotient, and r the remainder.

I example: a = ±73, b = 11

C-N Math 207 - Massey, 17 / 70

Page 18: C-N Math 207 Discrete Math

Integers

Place Value

I Ways to represent natural numbers:tally/tic marks, Egyptian, Roman numeral,place value (brilliant!).

I We are familiar with base 10, but othersocieties have used e.g. base 12 or 60.

I Computers use binary (base 2)octal (base 8), [hexadecimal] (base 16)

C-N Math 207 - Massey, 18 / 70

Page 19: C-N Math 207 Discrete Math

Integers

Place ValueEach x ∈ N can be uniquely represented in baseb as a linear combination of powers of b, witheach coefficient (digit) between 0 and b − 1.

x = (Dd−1 · · ·D2D1D0)b =

d−1∑k=0

Dkbk

I (75)10 = 7 · 101 + 5 · 100I (113)8 = 1 · 82 + 1 · 81 + 3 · 80I (300)5 = 3 · 52I (1001011)2 = 26 + 23 + 21 + 20

I (4B)16 = 4 · 161 + 11 · 160

C-N Math 207 - Massey, 19 / 70

Page 20: C-N Math 207 Discrete Math

Integers

Place Value

Write (146)10 in base 3 using the divisionalgorithm.

146 = 3 · 48+ 2= 3 · (3 · 16+ 0) + 2= 3 · (3 · (3 · 5+ 1) + 0) + 2= 3 · (3 · (3 · (3 · 1+ 2) + 1) + 0) + 2

So (146)10 = (12102)3.

C-N Math 207 - Massey, 20 / 70

Page 21: C-N Math 207 Discrete Math

Integers

Place Value

There are 10 types of people in the world: thosethat understand binary, and those that don’t.1. Coach Sparks decides to use hexadecimal

for the football team’s jersey numbers. If ajersey reads “AC”, find the decimal andbinary equivalents.

2. How many points did C-N win by if thescoreboard reads 53− 32 in base 7 ?

C-N Math 207 - Massey, 21 / 70

Page 22: C-N Math 207 Discrete Math

Integers

Place Value

Arithmetic algorithms work the same way inother bases.1. (234)5 + (312)52. (175)8 · (6)83. (11010)2 · (1011)2

C-N Math 207 - Massey, 22 / 70

Page 23: C-N Math 207 Discrete Math

Integers

Divides

Definition: Let a , b ∈ Z.Then b divides a , if and only if (iff) there existsq ∈ Z such that a = bq .

I in the division algorithm, r = 0I Equivalent statements:

I notation: b | aI b divides (evenly into) aI a is divisible by bI b is a factor/divisor of a

C-N Math 207 - Massey, 23 / 70

Page 24: C-N Math 207 Discrete Math

Integers

Generally True?

1. n | 02. 0 | n3. n | 14. 1 | n5. n | n6. n | n2

7. (a + b) | (a2 − b2)

C-N Math 207 - Massey, 24 / 70

Page 25: C-N Math 207 Discrete Math

Integers

Your First Proof

Theorem: If a | b and b | c, then a | c(divisibility is transitive)

Illustration: 4 | 12 and 12 | 72, therefore 4 | 72.

Proof: Suppose a | b and b | c.By definition, b = aq1 and c = bq2.Then by substitution,c = bq2 = (aq1)q2 = a(q1q2).Therefore a | c. �

C-N Math 207 - Massey, 25 / 70

Page 26: C-N Math 207 Discrete Math

Integers

Direct If-Then Proofs1. Understand what you are proving.

Work an example; believe it is true.

2. Scratch work:

I what do you know? (the “if” part)I what do you need to show? (the “then” part)I use definitions to translate symbols/terminologyI deduce the desired result using algebra,

substitution, tricks, previous theorems, etc

3. Rewrite your proof neatly.

I State the theorem.I Prove the theorem, clearly justifying

each step as you move fromassumptions to the conclusion.

C-N Math 207 - Massey, 26 / 70

Page 27: C-N Math 207 Discrete Math

Integers

Theorem: Suppose a , b ∈ N.If a | b and b | a , then a = b.

Proof:

C-N Math 207 - Massey, 27 / 70

Page 28: C-N Math 207 Discrete Math

Integers

Even and Odd

Definitions:I n ∈ Z is even iff ∃q ∈ Z | n = 2qI n ∈ Z is odd iff ∃q ∈ Z | n = 2q + 1

Prove that1. if n is odd, then n + 5 is even.2. if n is odd, then n2 is odd.

C-N Math 207 - Massey, 28 / 70

Page 29: C-N Math 207 Discrete Math

Integers

Modulo

As in the division algorithm, let a = bq + r .Then “a modulo b” is the remainder r .I notation: a (mod b) = rI b | a iff a (mod b) = 0I odd if a (mod 2) = 1I List the possible values of a (mod 5).

C-N Math 207 - Massey, 29 / 70

Page 30: C-N Math 207 Discrete Math

Integers

Congruence

a and b are congruent (aliases) mod n

a ≡ b (mod n)

Equivalent definitions:I n | (a − b)I a (mod n) = b (mod n)I (a − b) (mod n) = 0I a − b = qn for some q ∈ Z

C-N Math 207 - Massey, 30 / 70

Page 31: C-N Math 207 Discrete Math

Integers

Equivalence

Congruence is an equivalence relation:1. reflexive

a ≡ a (mod n)2. symmetric

if a ≡ b (mod n) then b ≡ a (mod n)3. transitive

if a ≡ b (mod n) and b ≡ c (mod n)then a ≡ c (mod n)

C-N Math 207 - Massey, 31 / 70

Page 32: C-N Math 207 Discrete Math

Integers

Integers (mod n)The equivalence class of a (mod n) is the set ofall of a ’s aliases.

[a ]n = {b ∈ Z | a ≡ b (mod n)}

Zn is the set of all equivalence classes (mod n)I Zn = {0, 1, 2, 3, · · ·n − 1}I “Z mod n” puts each integerinto exactly one class

I loop around like a clock

C-N Math 207 - Massey, 32 / 70

Page 33: C-N Math 207 Discrete Math

Integers

Proof of Transitivity

Theorem: if a ≡ b (mod n) and b ≡ c (mod n)then a ≡ c (mod n)Proof: Assume that a ≡ b (mod n).Then by definition a − b = nq1 for some q1 ∈ Z.Similarly b − c = nq2 for some q2 ∈ Z.∴ (therefore)

a−c = (a−b)+(b−c) = nq1+nq2 = n(q1+q2)

and hence by definition n | (a − c) anda ≡ c (mod n). �

C-N Math 207 - Massey, 33 / 70

Page 34: C-N Math 207 Discrete Math

Integers

Algrebra of CongruenceTheorem: if a ≡ b and c ≡ d ,then a + c ≡ b + d and ac ≡ bd .Proof: By assumption, and the definition of congruence,a − b = q1n and c − d = q2n . Therefore,

(a + c) − (b + d) = (a − b) + (c − d)

= q1n + q2n = (q1 + q2)n

ac − bd = (b + q1n)c − b(c − q2n) = (q1c + q2b)n

Thus by definition, a + c ≡ b + d and ac ≡ bd . �

C-N Math 207 - Massey, 34 / 70

Page 35: C-N Math 207 Discrete Math

Integers

Zn Algebra

Hence we may develop algebra of + and × onZn . See the Affine Cipher Project.I addition / [multiplication tables]I inversesI solving equations

C-N Math 207 - Massey, 35 / 70

Page 36: C-N Math 207 Discrete Math

Integers

Problems

1. Compute 75 (mod 11), reducing as you go.2. What day of the week will it be 10000 days

from now?3. Solve 4(6x − 5) ≡ 5 (mod 7).

C-N Math 207 - Massey, 36 / 70

Page 37: C-N Math 207 Discrete Math

Integers

Affine Cipher

The affine cipher transforms each character inan alphabet by the formula:

y = f (x ) = (ax + b) (mod n)

I Experiment with the [web app].I Using the alphabet (space, A-Z), decrypt“VWBTU” if y = 5x + 2 (mod 27).

C-N Math 207 - Massey, 37 / 70

Page 38: C-N Math 207 Discrete Math

Integers

Invertibility

I If n = 27, a = 3, and b = 5then ’J’ (letter 10) gets tranformed to ’H’,but so does ’A’

I To be decipherable, a cipher function mustbe invertible (reversible). Each charactermust be mapped to exactly once.

I If n = 27, what values of a make the affinecipher an invertible function?

I What if n = 28 ?

C-N Math 207 - Massey, 38 / 70

Page 39: C-N Math 207 Discrete Math

Integers

Affine De-Cipher

I if y = f (x ) = ax + b thenx = f −1(y) = a−1(y − b)

I y = ax + b is invertible iff a−1 existsI find 7−1 (mod 27) by writing {7k (mod 27)}I 7−1 (mod 28) DNEI inverses come in pairs (some may be theirown inverse)

I hypothesize about when a−1 (mod n) exists

C-N Math 207 - Massey, 39 / 70

Page 40: C-N Math 207 Discrete Math

Integers

A Weird Function

Let δ : N+ → N be defined by

δ(n) = |{q ∈ N | q | n}|

I Describe the function in words.I Compute δ(21).

C-N Math 207 - Massey, 40 / 70

Page 41: C-N Math 207 Discrete Math

Integers

Prime Numbers

Let n > 1 be a natural number.I Definition: n is prime if its only naturalnumber divisors are 1 and n itself.

I n is prime iff δ(n) = .I If n is not prime, then it is composite.I If n is composite, then it has a prime factorwhich is ≤

√n .

I Sieve of Eratosthenes

C-N Math 207 - Massey, 41 / 70

Page 42: C-N Math 207 Discrete Math

Integers

Fundamental Theorem of Arithmetic

Fundamental Theorem of Arithmetic:each n > 1 can be written uniquely (up toordering) as the product of prime factors

n =∏

pαii

e.g. the prime factorization of 21560 is

21560 = 23 · 5 · 72 · 11

C-N Math 207 - Massey, 42 / 70

Page 43: C-N Math 207 Discrete Math

Integers

Prime Number Theorem

Let π(n) be the number of primes p ≤ n .

π(n) ≈ nln(n)

This estimate was proved to be asymptotic in1896.

limn→∞ π(n)

n/ ln(n)= 1

C-N Math 207 - Massey, 43 / 70

Page 44: C-N Math 207 Discrete Math

Integers

Greatest Common Divisor

I Define the greatest common divisor ofa , b ∈ Z to be the largest integer that is adivisor of both a and b.

I e.g. gcd(36, 84) = 12 (can use prime factors)I If a 6= 0, then gcd(a , 0) = |a |.I a and b are relatively prime (coprime) ifgcd(a , b) = 1

C-N Math 207 - Massey, 44 / 70

Page 45: C-N Math 207 Discrete Math

Integers

Least Common Multiple

I Define the least common multiple ofa , b ∈ Z to be the smallest natural numberthat is a multiple of both a and b.

I e.g. lcm(14, 35) = 70 (can use prime factors)I If ` = lcm(a , b) then a | ` and b | `

I Define lcm(a , 0) = 0 as a special case.

C-N Math 207 - Massey, 45 / 70

Page 46: C-N Math 207 Discrete Math

Integers

GCD and LCM

I gcd and lcm are commutative functionsI Use prime factors to find gcd(24, 30) andlcm(24, 30).

I Convince yourself thatgcd(a , b) · lcm(a , b) = |ab|.

C-N Math 207 - Massey, 46 / 70

Page 47: C-N Math 207 Discrete Math

Integers

Proving or Disproving

Consider a general if-then statement.I To be true, it must hold for any conditionthat satisfies the “if” part. No exceptions.

I You can’t prove the statement bycherry-picking examples that work.

I You can disprove the statement by findingone counter-example: a case where the “if”part is true, but the “then” part is false.

C-N Math 207 - Massey, 47 / 70

Page 48: C-N Math 207 Discrete Math

Integers

Disprove

Find a counter-example to the following:1. if n > 0 then 22n

+ 1 is prime225

+ 1 = 4294967297 = (641)(6700417)2. if c | (ab) then either c | a or c | b3. gcd(ma ,nb) = gcd(m ,n) gcd(a , b)

C-N Math 207 - Massey, 48 / 70

Page 49: C-N Math 207 Discrete Math

Integers

Prove

1. If x ≡ 3 (mod 8) then x 2 ≡ 9 (mod 16).2. The product of two consecutive integers is

even. (rewrite as if/then)3. If n is odd, then 8 | (n2 − 1).4. If c | a and c | b, then for any m ,n ∈ Z,

c | (ma + nb).5. If n ∈ N, then gcd(n ,n + 1) = 1.

C-N Math 207 - Massey, 49 / 70

Page 50: C-N Math 207 Discrete Math

Integers

Prove or disprove

1. If p is prime, then p + 7 is composite.2. If n > 0, then 3n + 2 is prime.3. If a ≡ b (mod n) then a2 ≡ b2 (mod n2)

4. If a ≡ b (mod n) then a2 ≡ b2 (mod n)

C-N Math 207 - Massey, 50 / 70

Page 51: C-N Math 207 Discrete Math

Integers

Mathematical Statements

I conjecture: believed to be true, butunproven

I lemma: a precursor to a more noteworthytheorem

I theorem: has been provedI corollary: follows as a special case of atheorem

C-N Math 207 - Massey, 51 / 70

Page 52: C-N Math 207 Discrete Math

Integers

Fun Fact

(Liouville) Pick any n ∈ N+ and write down itsdivisors, e.g. if n = 50 then {1, 2, 5, 10, 25, 50}.Then count how many divisors each divisor has.C = {1, 2, 2, 4, 3, 6}. Then (

∑C x )2 =

∑C x 3.

(1+2+2+4+3+6)2 = 1+8+8+64+27+216

Proof is beyond the scope of this class.

C-N Math 207 - Massey, 52 / 70

Page 53: C-N Math 207 Discrete Math

Integers

E.A. Lemma 1

Lemma: For any k ∈ Z, x divides both a and bif and only if (iff) x divides both a + kb and bProof: Suppose x | a and x | b.Then a = xq1 and b = xq2.Therefore a + kb = x (q1 + kq2), and sox | (a + kb).

Now suppose x | (a + kb) and x | b.Then a + kb = xq1 and b = xq2.Therefore a = xq1 − kb = x (q1 − kq2), and sox | a . �

C-N Math 207 - Massey, 53 / 70

Page 54: C-N Math 207 Discrete Math

Integers

E.A. Lemma 2

Lemma: For any k ∈ Z,

gcd(a , b) = gcd(b, a + kb)

Proof: By the previous lemma, the set ofcommon divisors of a and b is identical to theset of common divisors of a + kb and b.Therefore the GCD’s must be the same. �

C-N Math 207 - Massey, 54 / 70

Page 55: C-N Math 207 Discrete Math

Integers

Euclidean Algorithm

Euclidean Algorithm Theorem:

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

Proof: Use the division algorithm towrite a = bq + r , where r = a (mod b).Then r = a − bq . Taking k = −q , the previouslemma says that

gcd(a , b) = gcd(b, a − bq) = gcd(b, r)

C-N Math 207 - Massey, 55 / 70

Page 56: C-N Math 207 Discrete Math

Integers

E.A. ExampleThe Euclidean algorithm repeatedly uses theprevious theorem to find the GCD of twonumbers.

gcd(952, 210) = gcd(210, 112)= gcd(112, 98)= gcd(98, 14)= gcd(14, 0)= 14

C-N Math 207 - Massey, 56 / 70

Page 57: C-N Math 207 Discrete Math

Integers

E.A. Exercises

1. Use the EA to find gcd(12540, 2002), thenfind the lcm.

2. Show that 495 and 392 are relatively prime.3. True or false?

gcd(a , b, c) = gcd(gcd(a , b), c)4. Draw a line from (0, 0) to (a , b) in the

Cartesian plane. How many integer latticepoints does it cross?

C-N Math 207 - Massey, 57 / 70

Page 58: C-N Math 207 Discrete Math

Integers

GCD as a Linear Combination

Back-substitution allows us to write the gcd as alinear combination of the two arguments, that isgcd(a , b) = c1a + c2b.

952 = (210)(4) + 112

210 = (112)(1) + 98

112 = (98)(1) + 14

98 = (14)(7) + 0

112 = 952(1) + (210)(−4)

98 = (952)(−1) + (210)(5)

14 = (952)(2) + (210)(−9)

C-N Math 207 - Massey, 58 / 70

Page 59: C-N Math 207 Discrete Math

Integers

GCD as a Linear CombinationTheorem a and b are relatively prime iff 1 canbe written as a linear combination of a and b.Proof First suppose a and b are relativelyprime. Then gcd(a , b) = 1, and the EA withback-substitution allows us to writec1a + c2b = gcd(a , b) = 1.

Now suppose c1a + c2b = 1, and suppose x is adivisor of both a and b. Say a = xq1 andb = xq2. Then x (c1q1 + c2q2) = 1, and sinceeverything is an integer, it must be that |x | = 1.Therefore gcd(a , b) = 1. �

C-N Math 207 - Massey, 59 / 70

Page 60: C-N Math 207 Discrete Math

Integers

Inverses in Zn

Theorem If gcd(a ,n) = 1, then a has an inverse in Zn .Proof Since gcd(a ,n) = 1, we can write c1a + c2n = 1.Therefore c1a ≡ 1 (mod n), and c1 is the candidateinverse. (existence)To be the inverse, c1 must be the unique solution toax ≡ 1 in Zn .If ax ≡ 1 then ac1 − ax ≡ 0, and thereforec1a(c1 − x ) ≡ 0.But since c1a ≡ 1,we get c1 − x ≡ 0 or x ≡ c1. (uniqueness)∴ a−1 = c1�

C-N Math 207 - Massey, 60 / 70

Page 61: C-N Math 207 Discrete Math

Integers

Inverses in Zn

Theorem The converse is also true:if a has in inverse in Zn , then gcd(a ,n) = 1.Proof Suppose ab ≡ 1 (mod n), so that ab = 1+ kn .Let d be a divisor of both a and n , so that a = dq1 andn = dq2.Then dq1b = 1+ kdq2, and d(q1b − kq2) = 1. The onlyinteger possibility is d = ±1. �

C-N Math 207 - Massey, 61 / 70

Page 62: C-N Math 207 Discrete Math

Integers

Finding an inverse in Zn

1. Show that a = 28 and n = 135 arerelatively prime, and write 1 as a linearcombination of a and n .

2. Find 28−1 (mod 135).3. Find 4−1 in Z27 (easy by inspection)4. Find 8−1 in Z27 (use EA)5. Solve 10(x − 7) = 6+ 2x in Z27

C-N Math 207 - Massey, 62 / 70

Page 63: C-N Math 207 Discrete Math

Integers

Affine Cipher Decryption

Recall the affine cipher function and its inverse:

y = ax + b (mod n) x = a−1(y − b)

I We now know that a−1 exists iffgcd(a ,n) = 1.

I In general, use the EA to writec1a + c2n = 1, and then a−1 = c1.

I If n = 27, a = 2, and b = 5, theny = 2x + 5 (mod 27)x = 14(y − 5).

C-N Math 207 - Massey, 63 / 70

Page 64: C-N Math 207 Discrete Math

CRT

Pirate Treasure

A band of ten pirates captured a treasure chestfull of gold coins. When they attempted todivide the coins evenly, 3 were left over. A fightensued and one pirate was killed. Again theyattempted to divide the coins, but now therewere 8 left over. This time two pirates werekilled fighting over the extras. On the third try,the coins divided evenly. How many coins werein the chest?

C-N Math 207 - Massey, 64 / 70

Page 65: C-N Math 207 Discrete Math

CRT

Pirate Treasure

Solve the system of congruences:

x ≡ 3 (mod 10)x ≡ 8 (mod 9)x ≡ 0 (mod 7)

C-N Math 207 - Massey, 65 / 70

Page 66: C-N Math 207 Discrete Math

CRT

Chinese Remainder Theorem

Chinese Remainder Theorem: if m1 and m2 arerelatively prime, then

x ≡ r1 (mod m1)

x ≡ r2 (mod m2)

has a unique solution (mod m1m2).This theorem can be extended to 3 or morecongruences by induction.

C-N Math 207 - Massey, 66 / 70

Page 67: C-N Math 207 Discrete Math

CRT

CRT Algorithm

Idea: absorb each congruence sequentially:

x = 3+ 10n

3+ 10n ≡ 8 (mod 9)

1n ≡ 5 (mod 9)

n ≡ 1−15 (mod 9)

n = 5

x = 53 (mod 90)

53+ 90n ≡ 0 (mod 7)

4+ 6n ≡ 0 (mod 7)

6n ≡ 3 (mod 7)

n = 6−13 (mod 7)

n = 4

x = 413 (mod 630)

C-N Math 207 - Massey, 67 / 70

Page 68: C-N Math 207 Discrete Math

CRT

Football Scores

Find all scores less than 100 that satisfy:

x ≡ 1 (mod 2)

x ≡ 2 (mod 3)

x ≡ 3 (mod 7)

C-N Math 207 - Massey, 68 / 70

Page 69: C-N Math 207 Discrete Math

CRT

CRT ConditionsThis system has solutions

x ≡ 3 (mod 4)x ≡ 5 (mod 6)

but this one is inconsistent, and has no solution.

x ≡ 2 (mod 4)x ≡ 5 (mod 6)

C-N Math 207 - Massey, 69 / 70

Page 70: C-N Math 207 Discrete Math

CRT

Eggs

An old woman goes to market and a horse steps on herbasket and crushes the eggs. The rider offers to pay forthe damages and asks her how many eggs she hadbrought. She does not remember the exact number, butwhen she had taken them out two at a time, there wasone egg left. The same happened when she picked themout three, four, five, and six at a time, but when she tookthem seven at a time they came out even. What is thesmallest number of eggs she could have had?

C-N Math 207 - Massey, 70 / 70