Final
Final
Ingredients:
hypotheses of the theorem
axioms assumed to be true
You get:
previously proven theorems
rules of inference
truth of the
statement
being proved
Usefulness
Computer Science
Verifying that computer programs are correct.
Establishing that operating systems are secure.
Making inferences in artificial intelligence.
Showing that system specifications are consistent.
Mathematics
Defining Formalism.
Providing specification in a common language.
Justification for the results.
Definitions
1. An integer n is even if, and only if, n = 2k for some integer k.
2. An integer n is odd if, and only if, n = 2k + 1 for some integer k.
3. An integer n is prime if, and only if, n > 1 and for all positive integers
r and s, if n = r·s, then r = 1 or s = 1.
4. An integer n > 1 is composite if, and only if, n = r·s for some positive
integers r and s with r ≠ 1 and s ≠ 1.
𝑎
5. A real number r is rational if, and only if, r= for some integers a and
𝑏
b with b ≠ 0.
6. If n and d are integers and d ≠ 0, then d divides n, written d|n if, and
only if, n = d.k for some integers k.
7. An integer n is called a perfect square if, and only if, n = 𝑘 2 for some
integer k.
Types of Proofs
Proving conditional Statements
Direct Proofs
Indirect Proofs
Proof by Contraposition
Proofs by Contradiction
Proving Non-conditional Statements
Indirect Proofs
If-And-Only-If Proof
Constructive Versus Non-constructive Proofs
Existence Proofs; Existence and Uniqueness Proofs
Disproofs (Counterexample, Contradiction, Existence Statement)
Proofs Involving Sets
Mathematical Induction
Direct Proofs
p q
first step is the assumption that p is true
subsequent steps constructed using rules of inference.
final step showing that q must also be true
Solution:
17 ≡ 5 (mod 6) because 6 divides 17 − 5 = 12.
24 ≢ 14 (mod 6) since 6 divides 24 − 14 = 10 is not divisible by 6.
More on Congruences
Theorem 4: Let m be a positive integer. The integers a
and b are congruent modulo m if and only if there is
an integer k such that a = b + km.
Proof:
If a ≡ b (mod m), then (by the definition of
congruence) m | a – b. Hence, there is an integer k such
that a – b = km and equivalently a = b + km.
Conversely, if there is an integer k such that a = b + km,
then km = a – b. Hence, m | a – b and a ≡ b (mod m).
The Relationship between
(mod m) and mod m Notations
The use of “mod” in a ≡ b (mod m) and a mod m = b
are different.
a ≡ b (mod m) is a relation on the set of integers.
In a mod m = b, the notation mod denotes a function.
The relationship between these notations is made
clear in this theorem.
Theorem 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. (Proof in the exercises)
Congruencies of Sums and Products
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)
Example: Because 7 ≡ 2 (mod 5) and 11 ≡ 1 (mod 5)
, it follows from Theorem 5 that
18 = 7 + 11 ≡ 2 + 1 = 3 (mod 5)
77 = 7 11 ≡ 2 * 1 = 2 (mod 5)
Algebraic Manipulation of Congruencies
Multiplying both sides of a valid congruence by an integer
preserves validity.
If a ≡ b (mod m) holds then c∙a ≡ c∙b (mod m), where c is any
integer, holds by Theorem 5 with d = c.
Adding an integer to both sides of a valid congruence preserves
validity.
If a ≡ b (mod m) holds then c + a ≡ c + b (mod m), where c is any
integer, holds by Theorem 5 with d = c.
Dividing a congruence by an integer does not always produce a
valid congruence.
Example: The congruence 14≡ 8 (mod 6) holds. But dividing
both sides by 2 does not produce a valid congruence since
14/2 = 7 and 8/2 = 4, but 7≢4 (mod 6).
Computing the mod m Function of
Products and Sums
We use the following corollary to Theorem 5 to
compute the remainder of the product or sum of two
integers when divided by m from the remainders when
each is divided by m.
Corollary: Let m be a positive integer and let a and b
be integers. Then
(a + b) (mod m) = ((a mod m) + (b mod m)) mod m
and
ab mod m = ((a mod m) (b mod m)) mod m.
(proof in text)
Section Summary
Hashing Functions
Pseudorandom Numbers
Check Digits
Hashing Functions
Definition: A hashing function h assigns memory location h(k) to the record that has
k as its key.
A common hashing function is h(k) = k mod m, where m is the number of
memory locations.
Because this hashing function is onto, all memory locations are possible.
Example: Let h(k) = k mod 111. This hashing function assigns the records of
customers with social security numbers as keys to memory locations in the following
manner:
h(064212848) = 064212848 mod 111 = 14
h(037149212) = 037149212 mod 111 = 65
h(107405723) = 107405723 mod 111 = 14, but since location 14 is already
occupied, the record is assigned to the next available position, which is 15.
The hashing function is not one-to-one as there are many more possible keys than
memory locations. When more than one record is assigned to the same location, we
say a collision occurs. Here a collision has been resolved by assigning the record to
the first free location.
For collision resolution, we can use a linear probing function:
h(k,i) = (h(k) + i) mod m, where i runs from 0 to m − 1.
There are many other methods of handling with collisions. You may cover these in a
later CS course.
Pseudorandom Numbers
Randomly chosen numbers are needed for many purposes,
including computer simulations.
Pseudorandom numbers are not truly random since they are
generated by systematic methods.
The linear congruential method is one commonly used procedure
for generating pseudorandom numbers.
Four integers are needed: the modulus m, the multiplier a, the
increment c, and seed x0, with 2 ≤ a < m, 0 ≤ c < m, 0 ≤ x0 < m.
We generate a sequence of pseudorandom numbers {xn}, with
0 ≤ xn < m for all n, by successively using the recursively defined
function
xn+1 = (axn + c) mod m.
(an example of a recursive definition, discussed in Section 5.3)
If psudorandom numbers between 0 and 1 are needed, then the
generated numbers are divided by the modulus, xn /m.
Pseudorandom Numbers
Example: Find the sequence of pseudorandom numbers generated by the linear
congruential method with modulus m = 9, multiplier a = 7, increment c = 4, and
seed x0 = 3.
Solution: Compute the terms of the sequence by successively using the
congruence xn+1 = (7xn + 4) mod 9, with x0 = 3.
x1 = 7x0 + 4 mod 9 = 7∙3 + 4 mod 9 = 25 mod 9 = 7,
x2 = 7x1 + 4 mod 9 = 7∙7 + 4 mod 9 = 53 mod 9 = 8,
x3 = 7x2 + 4 mod 9 = 7∙8 + 4 mod 9 = 60 mod 9 = 6,
x4 = 7x3 + 4 mod 9 = 7∙6 + 4 mod 9 = 46 mod 9 = 1,
x5 = 7x4 + 4 mod 9 = 7∙1 + 4 mod 9 = 11 mod 9 = 2,
x6 = 7x5 + 4 mod 9 = 7∙2 + 4 mod 9 = 18 mod 9 = 0,
x7 = 7x6 + 4 mod 9 = 7∙0 + 4 mod 9 = 4 mod 9 = 4,
x8 = 7x7 + 4 mod 9 = 7∙4 + 4 mod 9 = 32 mod 9 = 5,
x9 = 7x8 + 4 mod 9 = 7∙5 + 4 mod 9 = 39 mod 9 = 3.
The sequence generated is 3,7,8,6,1,2,0,4,5,3,7,8,6,1,2,0,4,5,3,…
It repeats after generating 9 terms.
Commonly, computers use a linear congruential generator with increment c = 0.
This is called a pure multiplicative generator. Such a generator with modulus 231 −
1 and multiplier 75 = 16,807 generates 231 − 2 numbers before repeating.
Check Digits: UPCs
A common method of detecting errors in strings of digits is to add an extra digit at
the end, which is evaluated using a function. If the final digit is not correct, then
the string is assumed not to be correct.
Example: Retail products are identified by their Universal Product Codes (UPCs).
Usually these have 12 decimal digits, the last one being the check digit. The check
digit is determined by the congruence:
3x1 + x2 + 3x3 + x4 + 3x5 + x6 + 3x7 + x8 + 3x9 + x10 + 3x11 + x12 ≡ 0 (mod 10).
a. Suppose that the first 11 digits of the UPC are 79357343104. What is the check
digit?
b. Is 041331021641 a valid UPC?
Solution:
a. 3∙7 + 9 + 3∙3 + 5 + 3∙7 + 3 + 3∙4 + 3 + 3∙1 + 0 + 3∙4 + x12 ≡ 0 (mod 10)
21 + 9 + 9 + 5 + 21 + 3 + 12+ 3 + 3 + 0 + 12 + x12 ≡ 0 (mod 10)
98 + x12 ≡ 0 (mod 10)
x12 ≡ 0 (mod 10) So, the check digit is 2.
b. 3∙0 + 4 + 3∙1 + 3 + 3∙3 + 1 + 3∙0 + 2 + 3∙1 + 6 + 3∙4 + 1 ≡ 0 (mod 10)
0 + 4 + 3 + 3 + 9 + 1 + 0+ 2 + 3 + 6 + 12 + 1 = 44 ≡ 4 ≢ (mod 10)
Hence, 041331021641 is not a valid UPC.
Check Digits:ISBNs
Books are identified by an International Standard Book Number (ISBN-10), a 10 digit code. The
first 9 digits identify the language, the publisher, and the book. The tenth digit is a check digit,
which is determined by the following congruence
a. Suppose that the first 9 digits of the ISBN-10 are 007288008. What is the check digit?
b. Is 084930149X a valid ISBN10?
Solution: X is used
a. X10 ≡ 1∙0 + 2∙0 + 3∙7 + 4∙2 + 5∙8 + 6∙8 + 7∙ 0 + 8∙0 + 9∙8 (mod 11). for the
X10 ≡ 0 + 0 + 21 + 8 + 40 + 48 + 0 + 0 + 72 (mod 11). digit 10.
X10 ≡ 189 ≡ 2 (mod 11). Hence, X10 = 2.
b. 1∙0 + 2∙8 + 3∙4 + 4∙9 + 5∙3 + 6∙0 + 7∙ 1 + 8∙4 + 9∙9 + 10∙10 =
0 + 16 + 12 + 36 + 15 + 0 + 7 + 32 + 81 + 100 = 299 ≡ 2 ≢ 0 (mod 11)
Hence, 084930149X is not a valid ISBN-10.
A single error is an error in one digit of an identification number and a transposition error is
the accidental interchanging of two digits. Both of these kinds of errors can be detected by
the check digit for ISBN-10. (see text for more details)
Arithmetic Modulo m
Definitions: Let Zm be the set of nonnegative integers less
than m: {0,1, …., m−1}
The operation +m is defined as a +m b = (a + b) mod m.
This is addition modulo m.
The operation ∙m is defined as a ∙m b = (a . b) mod m. This
is multiplication modulo m.
Using these operations is said to be doing arithmetic
modulo m.
Example: Find 7 +11 9 and 7 ∙11 9.
Solution: Using the definitions above:
7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5
7 ∙11 9 = (7 ∙ 9) mod 11 = 63 mod 11 = 8
Arithmetic Modulo m
The operations +m and ∙m satisfy many of the same properties as
ordinary addition and multiplication.
Closure: If a and b belong to Zm , then a +m b and a ∙m b belong
to Zm .
Associativity: If a, b, and c belong to Zm , then
(a +m b) +m c = a +m (b +m c) and (a ∙m b) ∙m c = a ∙m (b ∙m c).
Commutativity: If a and b belong to Zm , then
a +m b = b +m a and a ∙m b = b ∙m a.
Identity elements: The elements 0 and 1 are identity elements
for addition and multiplication modulo m, respectively.
If a belongs to Zm , then a +m 0 = a and a ∙m 1 = a.
continued →
Arithmetic Modulo m
Additive inverses: If a≠ 0 belongs to Zm , then m− a is the additive
inverse of a modulo m and 0 is its own additive inverse.
a +m (m− a ) = 0 and 0 +m 0 = 0
Mersenne Primes
Definition: Prime numbers of the form 2p − 1 , where p is
prime, are called Mersenne primes.
22 − 1 = 3, 23 − 1 = 7, 25 − 1 = 37 , and 27 − 1 = 127 are
Mersenne primes.
211 − 1 = 2047 is not a Mersenne prime since 2047 = 23∙89.
There is an efficient test for determining if 2p − 1 is prime.
The largest known prime numbers are Mersenne primes.
As of mid 2011, 47 Mersenne primes were known, the largest
is 243,112,609 − 1, which has nearly 13 million decimal digits.
The Great Internet Mersenne Prime Search (GIMPS) is a
distributed computing project to search for new Mersenne
Primes.
http://www.mersenne.org/
Greatest Common Divisor
Definition: Let a and b be integers, not both zero. The
largest integer d such that d | a and also d | b is called the
greatest common divisor of a and b. The greatest common
divisor of a and b is denoted by gcd(a,b).
This formula is valid since the integer on the right (of the equals sign)
divides both a and b. No larger integer can divide both a and b.
Example: 120 = 23 ∙3 ∙5 500 = 22 ∙53
gcd(120,500) = 2min(3,2) ∙3min(1,0) ∙5min(1,3) = 22 ∙30 ∙51 = 20
Finding the gcd of two positive integers using their prime factorizations
is not efficient because there is no efficient algorithm for finding the
prime factorization of a positive integer.
Least Common Multiple
Definition: The least common multiple of the positive integers a and b
is the smallest positive integer that is divisible by both a and b. It is
denoted by lcm(a,b).
The least common multiple can also be computed from the prime
factorizations.
This method illustrated above is a two pass method. It first uses the
Euclidian algorithm to find the gcd and then works backwards to
express the gcd as a linear combination of the original two integers. A
one pass method, called the extended Euclidean algorithm, is
developed in the exercises.
Dividing Congruencies by an
Integer
Dividing both sides of a valid congruence by an integer
does not always produce a valid congruence (see
Section 4.1).
But dividing by an integer relatively prime to the
modulus does produce a valid congruence:
Theorem 7: Let m be a positive integer and let a, b,
and c be integers. If ac ≡ bc (mod m) and gcd(c,m) = 1,
then a ≡ b (mod m).
Proof: Since ac ≡ bc (mod m), m | ac − bc = c(a − b)
by Lemma 2 and the fact that gcd(c,m) = 1, it follows
that m | a − b. Hence, a ≡ b (mod m).
Section 4.4
Section Summary
Linear Congruencies
The Chinese Remainder Theorem
Fermat’s Little Theorem
Pseudo primes
Linear Congruencies
Definition: A congruence of the form
ax ≡ b( mod m),
where m is a positive integer, a and b are integers, and x is a variable, is
called a linear congruence.
Note that because Mj ≡ 0 ( mod mk) whenever j ≠k , all terms except the kth
term in this sum are congruent to 0 modulo mk .
Because Mk yk ≡ 1 ( mod mk ), we see that x ≡ ak Mk yk ≡ ak( mod mk), for k
= 1,2,…,n.
Hence, x is a simultaneous solution to the n congruences.
x ≡ a1 ( mod m1)
x ≡ a2 ( mod m2)
∙
∙
∙
x ≡ an ( mod mn)
The Chinese Remainder Theorem
Example: Consider the 3 congruences from Sun-Tsu’s problem:
x ≡ 2 ( mod 3), x ≡ 3 ( mod 5), x ≡ 2 ( mod 7).
Let m = 3∙ 5 ∙ 7 = 105, M1 = m/3 = 35, M3 = m/5 = 21,
M3 = m/7 = 15.
We see that
2 is an inverse of M1 = 35 modulo 3 since 35 ∙ 2 ≡ 2 ∙ 2 ≡ 1 (mod 3)
1 is an inverse of M2 = 21 modulo 5 since 21 ≡ 1 (mod 5)
1 is an inverse of M3 = 15 modulo 7 since 15 ≡ 1 (mod 7)
Hence,
Solution:
Each bit (binary digit) is either 0 or 1.
Hence, there are 2 ways to choose each bit. Since we have
to choose four bits therefore,
The first two letters places are fixed (to be filled with A and B),
so there is only one way to fill them. The third letter place
should contain a letter different from A & B, so there
are 24 ways to fill it.
The three digit positions can be filled in 10 and 8 ways to have
distinct digits. Hence, desired number of license plates are
1 × 1 × 24 × 10 × 9 × 8 = 17280
Telephone Numbering Plan
Example: The North American numbering plan (NANP) specifies that a
telephone number consists of 10 digits, consisting of a three-digit area code,
a three-digit office code, and a four-digit station code. There are some
restrictions on the digits.
Let X denote a digit from 0 through 9.
Let N denote a digit from 2 through 9.
Let Y denote a digit that is 0 or 1.
In the old plan (in use in the 1960s) the format was NYX-NNX-XXXX.
In the new plan, the format is NXX-NXX-XXXX.
How many different telephone numbers are possible under the old plan and
the new plan?
where the inequality ⌈N/k⌉ < ⌈N/k⌉ + 1 has been used. This
is a contradiction because there are a total of n objects.
Pigeonhole Principle
Example: Among any group of 367 people, there must
be at least two with the same birthday, because there
are only 366 possible birthdays. ⌈367/366⌉ = 2
Example: Among 100 people there are at least
⌈100/12⌉ = 9 who were born in the same month.
Example: In any set of 27 English , must be at least
two that begin with the same letter, since there are 26
letters in the English alphabet. ⌈27/26⌉ = 2
The Generalized Pigeonhole Principle
Example: What is the minimum number of students required
in a Discrete Mathematics class to be sure that at least six will
receive the same grade, if there are five possible grades, A, B, C,
D, and F.
Solution:
The minimum number of students needed to guarantee that at
least six students receive the same grade is the smallest integer
N such that ⌈ N/K ⌉ = ⌈ N/5 ⌉ = 6. The smallest such integer is
N = K(⌈ N/K ⌉-1)+1 = 5(6-1)+1=5 ⋅ 5 + 1 = 26.
Thus 26 is the minimum number of students needed to be sure
that at least 6 students will receive the same grades.
Section 6.3
Section Summary
Permutations
Combinations
Combinatorial Proofs
Permutations
Definition: A permutation of a set of distinct objects
is an ordered arrangement of these objects. An ordered
arrangement of r elements of a set is called an
r-permutation.
Example: Let S = {1,2,3}.
The ordered arrangement 3,1,2 is a permutation of S.
The ordered arrangement 3,2 is a 2-permutation of S.
The number of r-permutations of a set with n
elements is denoted by P(n,r).
The 2-permutations of S = {1,2,3} are 1,2; 1,3; 2,1; 2,3;
3,1; and 3,2. Hence, P(3,2) = 6.
A Formula for the Number of
Permutations
Theorem 1: If n is a positive integer and r is an integer with
1 ≤ r ≤ n, then there are
P(n, r) = n(n − 1)(n − 2) ∙∙∙ (n − r + 1)
r-permutations of a set with n distinct elements.
Proof: Use the product rule. The first element can be chosen in n
ways. The second in n − 1 ways, and so on until there are
(n − ( r − 1)) ways to choose the last element.
Note that P(n,0) = 1, since there is only one way to order zero
elements.
Corollary 1: If n and r are integers with 1 ≤ r ≤ n, then
Solving Counting Problems by
Counting Permutations
Example: How many ways are there to select a first-
prize winner, a second prize winner, and a third-prize
winner from 100 different people who have entered a
contest?
Solution:
P(100,3) = 100 ∙ 99 ∙ 98 = 970,200
Solving Counting Problems by
Counting Permutations (continued)
Example: Suppose that there are eight runners in a race.
The winner receives a gold medal, the second place
finisher receives a silver medal, and the third-place
finisher receives a bronze medal. How many different
ways are there to award these medals, if all possible
outcomes of the race can occur and there are no ties?
Solution: The number of different ways to award the
medals is the number of 3-permutations of a set with
eight elements. Hence, there are
P(8, 3) = 8 · 7 · 6 = 336
possible ways to award the medals.
Solving Counting Problems by
Counting Permutations (continued)
Example: Suppose that a saleswoman has to visit eight
different cities. She must begin her trip in a specified city,
but she can visit the other seven cities in any order she
wishes. How many possible orders can the saleswoman use
when visiting these cities?
Solution: The first city is chosen, and the rest are ordered
arbitrarily. Hence the orders are:
P(7,7)= 7! = 7 ∙ 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 5040
If she wants to find the tour with the shortest path that
visits all the cities, she must consider 5040 paths!
Solving Counting Problems by
Counting Permutations (continued)
Example: How many permutations of the letters
ABCDEFGH contain the string ABC ?
P(6,6)= 6! = 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 720
Combinations
Definition: An r-combination of elements of a set is
an unordered selection of r elements from the set.
Thus, an r-combination is simply a subset of the set
with r elements.
The number of r-combinations of a set with n distinct
elements is denoted by C(n, r).
and
Pascal’s Identity
Pascal’s Identity: If n and k are integers with n ≥ k ≥ 0, then