MATH 211 - LECTURE NOTES Discrete Structures-1
MATH 211 - LECTURE NOTES Discrete Structures-1
Set Theory
Set theory deals with operations between, relations among, and statements about sets.
We can denote a set S in writing by listing all of its elements in curly braces:
Set builder notation: For any proposition P(x) over any universe of discourse, {x|P(x)} is the
set of all x such that P(x).
Two sets are declared to be equal if and only if they contain exactly the same elements.
1
{x | x is a positive integer whose square
is >0 and <25}
Infinite Sets
Conceptually, sets may be infinite (i.e., not finite, without end, unending).
Venn Diagrams
Basic Set Relations: Member of xS (“x is in S”) is the proposition that object x is an
lement or member of set S.
(“null”, “the empty set”) is the unique set that contains no elements whatsoever.
= {} = {x|False}
x: x.
ST (“S is a subset of T”) means that every element of S is also an element of T.
S, SS.
2
Note S=T ST ST.
ST (“S is a proper subset of T”) means that ST but . Similar for ST.
|S| (read “the cardinality of S”) is a measure of how many different elements S has.
The power set P(S) of a set S is the set of all subsets of S. P(S) = {x | xS}.
Ordered n-tuples
For nN, an ordered n-tuple or a sequence of length n is written (a1, a2, …, an). The first
element is a1, etc.
3
These are like sets, except that duplicates matter, and the order makes a difference.
Note that the Cartesian product is not commutative: AB: AB =BA.
Extends to A1 A2 … An...
For sets A, B, their union AB is the set containing all elements that are either in A, or (“”)
in B (or, of course, in both).
Note that AB contains all the elements of A and it contains all the elements of B:
A, B: (AB A) (AB B)
Union Examples
{a,b,c}{2,3} = {a,b,c,2,3}
For sets A, B, their intersection AB is the set containing all elements that are simultaneously
in A and (“”) in B.
Intersection Examples
4
{a,b,c}{2,3} = ___
{2,4,6}{3,4,5} = ______
Disjointedness
Two sets A, B are called disjoint (i.e., unjoined) iff their intersection is empty.
(AB=)
Example: the set of even integers is disjoint with the set of odd integers.
Inclusion-Exclusion Principle
Example:
Set Difference
For sets A, B, the difference of A and B, written A−B, is the set of all elements that are in A
but not B.
A − B : x xA xB
= x ( xA → xB )
Z − N = {… , -1, 0, 1, 2, … } − {0, 1, … }
= {x | x is an integer but not a nat. #}
= {x | x is a negative integer}
= {… , -3, -2, -1}
Set Complements
5
The complement of A, written , is the complement of A w.r.t. U, i.e., it is U−A.
E.g., If U=N,
Set Identities
Double complement:
Associative: A(BC)=(AB)C
A(BC)=(AB)C
Show A(BC)(AB)(AC).
6
Case 2: xC. Then xAC , so x(AB)(AC).
Therefore, x(AB)(AC).
Therefore, A(BC)(AB)(AC).
Use “1” to indicate membership in the derived set, “0” for non-membership.
Generalized Union
n-ary union:
AA2…An : ((…((A1 A2) …) An)
(grouping & order is irrelevant)
“Big U” notation:
Generalized Intersection
n-ary intersection:
AA2…An((…((A1A2)…)An)
(grouping & order is irrelevant)
7
“Big Arch” notation:
Counting Techniques
Counting Basics
Set Cardinalities
How many ways are there to buy 13 different bagels from a shop that sells 17 types?
How many bit strings of length 11 contain a streak of one type of bit of exact length 7?
COMMON THEME: convert to set cardinality problems so each question above is a about
counting the number of elements in some set:
Counting Basics
Set Cardinalities
How many ways are there to buy 13 different bagels from a shop that sells 17 types?
8
{S {1, 2, … 17} | |S | = 13 } (…arguable)
How many bit strings of length 11 contain a streak of one type of bit of exact length 7?
Product Rule
As counting problems can be turned into set cardinality problems, useful to express counting
principles set theoretically.
|AB| = |A||B|
Product Rule
A: 2n.
THM: |P ({1,2,3,…,n})| = 2n
n is in 1-to-1 correspondence with the P({1,2,3,…,n}) since subsets are represented by length n
bit strings.•
Sum Rule
Next the number of length 11 bit strings with a streak of length exactly 7.
1. 10011001010
2. 0110111101011
9
3. 10000000011
4. 10000000101
5. 01111111010
Sum Rule
Next the number of length 11 bit strings with a streak of length exactly 7.
1. 10011001010
3. 10000000101 Yes!
4. 01111111010 Yes!
Sum Rule
{length 11 bit strings with 0-streak of length 7} {length 11 bit strings with 1-streak of length
7}
Sum Rule
A: Yes. If had both a 0-streak and a 1-streak of length 7 each, string would have length at least
14!
|A B| = |A|+|B|
By symmetry, in our case A and B have the same cardinality. Therefore the answer would be
2|A|.
10
Sum Rule
Break up
A1 = {00000001***} (* is either 0 or 1)
A2 = {100000001**}
A3 = {*100000001*}
A4 = {**100000001}
A5 = {***10000000}.
Sum Rule
A1 = {00000001***}. There are 3 *’s, each with 2 choices, so product rule gives |A1| = 23 = 8
A3 = {*100000001*}, A4 = {**100000001}
A5 = {***10000000}.
|A1| = |A5| = 8
Counting Functions
11
Use product rule thoughtfully.
Counting Functions
Counting Functions
nk
Inclusion-Exclusion
The principle of Inclusion-Exclusion generalized the sum rule the the case of non-empty
intersection:
|A B | = |A|+|B |- |A B |
This says that when counting all the elements in A or B, if we just add the the sets, we have
double-counted the intersection, and must therefore subtract it out.
Inclusion-Exclusion
Visualize.
12
Exercise
How many positive integers with exactly three decimal digits are…
…divisible by 7?
…odd?
How many ways can the letters a,b,c,d be arranged such that a is not immediately followed by b?
If there are n+1 pigeons, which must fit into n pigeonholes then some pigeonhole contains 2 or
more pigeons.
Less obvious: Why this would ever be useful… Principle often applied in surprising ways.
Pigeonhole Principle
EG: Given 12 or more numbers between 0 and 1 inclusive, there are 2 (or more) numbers x,y
whose strictly within 0.1 of each other.
Proof. Any pigeonhole principle application involves discovering who are the pigeons, and who
are the pigeonholes. In our case:
There are 11 pigeonholes so some x,y fall in one of these sets, and have difference < 0.1
Pigeonhole Principle
Harder Example: In a party of 2 or more people, there are 2 people with the same number of
friends in the party. (Assuming you can’t be your own friend and that friendship is mutual.)
Proof.
I) There is a pigeonhole which isn’t hit. In that case, left with n -1 remaining pigeonholes,
but n pigeons, so done.
II) Every pigeonhole hit. In particular, the friendship numbers n-1 as well as 0 were hit.
Thus someone is friends with everyone while someone else is friends with no-one. This
is a contradiction so this case cannot happen! →
If N objects are placed into k boxes, there is at least one box containing N/k objects.
Specialize to N = n+1 and k = n, gives at least (n+1)/n = 2 objects in one box, which is the
regular pigeonhole principle.
Q: Suppose that NYC has more than 7,000,000 inhabitants and that the human head contains at
most 500,000 hairs. Find a guaranteed minimum number of people in NYC that all have the
same number of hairs on their heads.
A: 7,000,000 / 500,001 = 14
Exercises
1. Show that if S {1,2,3,…,50} & |S |> 9 then there are at least 2 different 5 element
subsets in S all having the same sum.
2. Problem 4.3.27: There are 38 different time periods during which classes at a university
can be scheduled. If there are 677 different classes, how many different rooms will be
needed?
14
Functions; Sequences, Sums, Countability
Functions
In high-school, functions are often identified with the formulas that define them.
EG: f (x ) = x 2
This point of view does not suffice in Discrete Math. In discrete math, functions are not
necessarily defined over the real numbers.
So in addition to specifying the formula one needs to define the set of elements which are
acceptable as inputs, and the set of elements into which the function outputs.
Basic-Terms
DEF: A function f : A →B is given by a domain set A, a codomain set B, and a rule which
for every element a of A, specifies a unique element f (a) in B. f (a) is called the image of a,
while a is called the pre-image of f (a). The range (or image) of f is defined by
f (A) = {f (a) | a A }.
Functions. Basic-Terms.
Functions. Basic-Terms.
f : Z → R is given by f (x ) = x 2
pre-images of 4: -2 and 2
15
A4: range is the set of perfect squares
f (Z) = {0,1,4,9,16,25,…}
Java: Functions are like non-void Java methods. The domain is the parameter type and the
codomain is the return type. The image is the return value.
return x<0 ? –1 :
( x>0 ? 1 : 0 );}
A: This is the signature function which returns the sign of a given number. The range of f is
{-1,0,+1}.
Functions: Sub-ranges.
DEF: Given a function f : A →B. The pre-image set (or inverse image) of b is defined by f -
1
(b) = {a A | f (a)=b }. Given subsets S A and T B, the image set of S is defined by f (S
) = {f(a ) | a S } and the pre-image set (or inverse image) of T is defined by
f -1(T ) = {a A | f (a)T }.
Functions. Sub-ranges.
EG: f : Z → R with f (x ) = x 2
Q4: Calculate
f –1({-9,-5,-3,0,0.25,1,2,2.25,3,4})
16
Functions. Sub-ranges.
EG: f : Z → R with f (x ) = x 2
A1: f –1(3) =
A3: f ( {-9,-5,-3,0,1,2,3,4} )
= {81,25,9,0,1,4,16}
A4: f –1({-9,-5,-3,0,0.25,1,2,2.25,3,4})
= {0,-1,1,-2,2}
Bijection means that when arrows reversed, a function results. Equivalently, that both one-
to-one’ness and onto’ness occur.
Q: Which of the following are 1-to-1, onto, a bijection? If f is invertible, what is its inverse?
f : Z → R is given by f (x ) = x 2
f : Z → R is given by f (x ) = 2x
f : R → R is given by f (x ) = x 3
f : Z → N is given by f (x ) = |x |
f : Z → R, f (x ) = x 2: none
f : Z → Z, f (x ) = 2x : 1-1
f : Z → N, f (x ) = |x |: onto
Composition
When a function f spits out elements of the same kind that another function g eats, f and g
may be composed by letting g immediately eat each output of f.
f •g : A → C is defined by setting
f •g (a) = f ( g (a) )
Composition: Examples.
18
Q: Compute g •f where
f : Z → R, f (x ) = x 2 and g : R → R, g (x ) = x 3
f : Z → Z, f (x ) = x + 1 and g = f -1 so g (x ) = x – 1
Composition. Examples.
f : Z → R, f (x ) = x 2 and g : R → R, g (x ) = x 3
f •g : Z → R , f •g (x ) = x 6
f : Z → Z, f (x ) = x + 1 and g = f -1
Repeated Composition
When the domain and codomain are equal, a function may be self composed. The
composition may be repeated as much as desired resulting in functional exponentiation.
The whole process is denoted by
f n (x ) = f •f •f •f • … •f (x )
Repeated Composition
A1: f : Z → Z, f (x ) = x 2.
f 4(x ) = x (2*2*2*2) = x 16
A2: g : Z → Z, g (x ) = x + 1
gn (x ) = x + n
19
hn (x ) = x ’s n’th patrilineal ancestor
This being a course on discrete math, it is often useful to discretise numbers, sets and
functions. For this purpose the ceiling and floor functions come in handy.
DEF: Given a real number x : The floor of x is the biggest integer which is smaller or equal
to x The ceiling of x is the smallest integer greater or equal to x.
1.7 = 2, -1.7 = -1
Q: What’s the difference between the floor function and the (int) casting function in Java?
A: Casting to int in Java always truncates towards 0. Ceiling and floor are not symmetric in
this way.
EG: (int)(-1.7) == -1
-1.7 = -2
Example
where a,b,c,d are constants. Give a condition on the constants which guarantees that f is one-
to-one.
Sequences
Sequences are a way of ordering lists of objects. Java arrays are a type of sequence of finite
size. Usually, mathematical sequences are infinite.
To give an ordering to arbitrary elements, one has to start with a basic model of order. The
basic model to start with is the set
20
N = {0, 1, 2, 3, …} of natural numbers.
n = {1, 2, 3, 4, …, n-1, n }
Sequences
Symbolically, a sequence is represented using the subscript notation ai . This gives a way of
specifying formulaically
Note: Other sets can be taken as ordering models. The book often uses the positive numbers
Z+ so counting starts at 1 instead of 0. I’ll usually assume the ordering model N.
Sequence Examples
3,6,11,18,27,38,51, …
0,2,8,26,80,242,728,…
1,1,2,3,5,8,13,21,34,…
Sequence Examples
3,6,11,18,27,38,51, …
b) 0,2,8,26,80,242,728,…
21
ai = 3i –1
1,1,2,3,5,8,13,21,34,…
ai +1 = ai + ai-1
Bit Strings
Bit strings are finite sequences of 0’s and 1’s. Often there is enough pattern in the bit-string
to describe its bits by a formula.
EG: The bit-string 1111111 is described by the formula ai =1, where we think of the string of
being represented by the finite sequence a1a2a3a4a5a6a7
Bit Strings
1,1,0,1,1,0,1,1,0,1,…
Summations
The symbol “S” takes a sequence of numbers and turns it into a sum.
Symbolically:
Summations
ai = i
22
Summation Formulas –Arithmetic
Intuitive reason: The smallest term is 1, the biggest term is n so the avg. term is (n+1)/2.
There are n terms. To obtain the formula simply multiply the average by the number of
terms.
Summation Formulas
A: r = 3.
ai = a r i
A geometric sum is a sum of a portion of a geometric sequence and has the following
explicit formula:
Summation Examples
If you are curious about how one could prove such formulas, your curiosity will soon be
“satisfied” as you will become adept at proving such formulas a few lectures from now!
Summation Examples
A:
23
Summation Examples
A:
Up to now cardinality has been the number of elements in a finite sets. Really, cardinality is
a much deeper concept. Cardinality allows us to generalize the notion of number to infinite
collections and it turns out that many type of infinities exist.
EG:
{☺,}
{ , }
{Ø , {Ø,{Ø,{Ø}}} }
For finite sets, can just count the elements to get cardinality. Infinite sets are harder.
First Idea: Can tell which set is bigger by seeing if one contains the other.
{1, 2, 4} N
So set of even numbers ought to be smaller than the set of natural number because of strict
containment.
For finite sets, since multiplication by 2 is a one-to-one function, the size doesn’t change.
24
Another problem: set of even numbers is disjoint from set of odd numbers. Which one is
bigger?
DEF: Two sets A and B have the same cardinality if there’s a bijection
f:A→B
{☺,}
{ , }
Notation, the Hebrew letter Aleph is often used to denote infinite cardinalities. Countable
sets are said to have cardinality .
Intuitively, countable sets can be counted in the sense that if you allocate 1 second to count
each member, eventually any particular member will be counted after a finite time period.
Paradoxically, you won’t be able to count the whole set in a finite time period!
Countability – Examples
{0,2,4,6,8,…}
{1,3,5,7,9,…}
{1,3,5,7, }
Countability – Examples
Let’s try to set up a bijection between N and Z. One way is to just write a sequence down
whose pattern shows that every element is hit (onto) and none is hit twice (one-to-one). The
most common way is to alternate back and forth between the positives and negatives. I.e.:
0,1,-1,2,-2,3,-3,…
It’s possible to write an explicit formula down for this sequence which makes it easier to
check for bijectivity:
Because is the smallest kind of infinity, it turns out that to show that a set is countable
one can either demonstrate an injection into N or a surjection from N.
The proof requires the principle of mathematical induction, which we’ll get to at a later date.
Uncountable Sets
Q: Why not ?
Uncountability of R
R strictly contains N so has bigger cardinality. What’s wrong with this argument?
R contains infinitely many numbers between any two numbers. Surprisingly, this is not a
valid argument. Q has the same property, yet is countable.
Many numbers in R are infinitely complex in that they have infinite decimal expansions. An
infinite set with infinitely complex numbers should be bigger than N.
Uncountability of R
Here’s the real reason: Suppose that R were countable. In particular, any subset of R, being
smaller, would be countable also. So the interval [0,1] would be countable. Thus it would be
26
possible to find a bijection from Z+ to [0,1] and hence list all the elements of [0,1] in a
sequence.
r1 , r2 , r3 , r4 , r5 , r6 , r7, …
Impossible Computations
Notice that the set of all bit strings is countable. Here’s how the list looks:
0,1,00,01,10,11,000,001,010,011,100,101,110,111,0000,…
0.d1d2d3d4d5d6d7…
Is said to be computable if there is a computer program that outputs a particular digit upon
request.
EG:
0.11111111…
0.12345678901234567890…
0.10110111011110….
Exercise
27
Basic Number Theory
Before the dawn of computers, many viewed number theory as last bastion of “pure math”
which could not be useful and must be enjoyed only for its aesthetic beauty.
No longer the case. Number theory is crucial for encryption algorithms. Of utmost
importance to everyone from Bill Gates, to the CIA, to Osama Bin Laden.
Divisors
a = b ·c .
Then b and c are said to divide (or are factors) of a, while a is said to be a multiple of b (as
well as of c). The pipe symbol “|” denotes “divides” so the situation is summarized by:
b|a c|a.
NOTE: Students find notation confusing, and think of “|” in the reverse fashion, perhaps
confuse pipe with forward slash “/”
Divisors
Examples
77 | 7
7 | 77
24 | 24
0 | 24
24 | 0
28
Divisors.
Examples
A:
Divisor Theorem
a|b → a|bc
29
a|b b|c → a|c
EG:
17|34 → 17|340
Divisor Theorem
Proof of no. 2
In general, such statements are proved by starting from the definitions and manipulating to
get the desired results.
Suppose a|b. By definition, there is a number m such that b = am. Multiply both sides by c
to get bc = amc = a (mc ). Consequently, bc has been expressed as a times the integer mc so
by definition of “|”, a|bc •
Prime Numbers
DEF: A number n 2 prime if it is only divisible by 1 and itself. A number n 2 which isn’t
prime is called composite.
0,1,2,3,4,5,6,7,8,9,10
Prime Numbers
5, 7 prime.
9 = 3 · 3 not prime.
Last example shows that not all odd numbers are prime.
30
THM: Any number n 2 is expressible as as a unique product of 1 or more prime numbers.
We’ll need induction and some more number theory tools to prove this.
Q: Express each of the following number as a product of primes: 22, 100, 12, 17
12 = 2·2·3, 17 = 17
Primality Testing
Prime numbers are very important in encryption schemes. Essential to be able to verify if a
number is prime or not. It turns out that this is quite a difficult problem. First try:
boolean isPrime(integer n)
for(i = 2 to n -1)
return false
return true
Primality Testing
Primality Testing
31
A: Consider n = 1,000,000. The input size is k = 7 because n was described using only 7
digits. In general we have
Primality Testing
A:
After trying 2, don’t try any other even numbers, because know n is odd by this point.
In fact, only need to try to divide by prime numbers no larger than as we’ll see next:
Primality Testing
Proof (by contradiction). Suppose the smallest prime factor is > . Then by the
fundamental theorem of arithmetic we can decompose n = pqx where p and q are primes >
and x is some integer. Therefore
implying that n>n, which is impossible showing that the original supposition was
false and the theorem is correct. •
Primality Testing.
Example
2: Neither is even
5: Don’t end in 0 or 5
11: Alternating sum trick: 1-3+9 = 7 so 139 not div. By 11. 1-4+3 = 0 so 143 is divisible by
11.
32
STOP! Next prime 13 need not be examined since bigger than .
Division
117 = 31·3 + 24
a = dq + r
Division
THM: Let a be an integer, and d be a positive integer. There are unique integers q, r with r
{0,1,2,…,d-1} satisfying
a = dq + r
The proof is a simple application of long-division. The theorem is called the division
algorithm though really, it’s long division that’s the algorithm, not the theorem.
DEF Let a,b be integers, not both zero. The greatest common divisor of a and b (or
gcd(a,b) ) is the biggest number d which divides both a and b.
Equivalently: gcd(a,b) is smallest number which divisibly by any x dividing both a and b.
DEF: a and b are said to be relatively prime if gcd(a,b) = 1, so no prime common divisors.
gcd(11,77)
gcd(33,77)
gcd(24,36)
gcd(24,25)
33
A:
gcd(11,77) = 11
gcd(33,77) = 11
gcd(24,36) = 12
NOTE: A prime number are relatively prime to all other numbers which it doesn’t divide.
Find prime decomposition of each number and find all the common factors:
98 = 2·49 = 2·7·7
= 2·2·3·5·7
Therefore, gcd(98,420) = 14
Pairwise relatively prime: the numbers a, b, c, d, … are said to be pairwise relatively prime
if any two distinct numbers in the list are relatively prime.
A: A maximal pairwise relatively prime subset of {44, 28, 21, 15, 169, 17} :
Equivalently: lcm(a,b) is biggest number which divides any x divisible by both a and b
lcm(10,100)
lcm(7,5)
lcm(9,21)
A:
lcm(10,100) = 100
lcm(7,5) = 35
lcm(9,21) = 63
Proof. Let g = gcd(a,b). Factor a and b using g: a = gx, b = gy where x and y are relatively
prime.
Proof. Let g = gcd(a,b). Factor a and b using g: a = gx, b = gy where x and y are relatively
prime. Therefore, ab/gcd(a,b) = gxgy/g = gxy. Notice that a and b both divide gxy. On the
other hand, let m be divisible by both a and b.
35
lcm in terms of gcd
Proof
Proof. (continued) On the other hand, let m be divisible by both a and b: So m/g is divisible
by both x and y. As x and y have no common prime factors, the fundamental theorem of
arithmetic implies that m/g must be divisible by xy.
Proof. (continued) …m/g must be divisible by xy. Therefore, m must be divisible by gxy.
This shows that any multiple of a and b is bigger than gxy so by definition, gxy = ab/gcd(a,b)
is the lcm.
Modular Arithmetic
a a’ (mod b) means that a and a’ have the same remainder when dividing by b
mod function
Similar to Java’s “%” operator except that answer is always positive. E.G.
Q: Compute
113 mod 24
36
-29 mod 7
mod function
A: Compute
-29 mod 7
mod function
A: Compute
-29 mod 7
mod function
A: Compute
-29 mod 7
mod function
A: Compute
-29 mod 7
(mod) congruence
Formal Definition
DEF: Let a,a’ be integers and b be a positive integer. We say that a is congruent to a’
modulo b (denoted by a a’ (mod b) ) iff b | (a – a’ ).
3 3 (mod 17)
3 -3 (mod 17)
37
-13 13 (mod 26)
(mod) congruence
A:
3 3 (mod 17) True. any number is congruent to itself (3-3 = 0, divisible by all)
(mod) congruence
Identities
The (mod) congruence is useful for manipulating expressions involving the mod function. It
lets us view modular arithmetic relative a fixed base, as creating a number system inside of
which all the calculations can be carried out.
a mod b a (mod b)
ac a’c’ (mod b)
a k a’ k
(mod b)
Modular arithmetic
harder examples
We first need:
38
THM: a a’ (mod b) → k a = a’ + kb
a a’ (mod b) c c’ (mod b)
---→ ac a’ c’ (mod b)
Proof. By the previous, we can assume that there are k and l such that
a = a’ + bk and c = c’ + bl
Simple Encryption
Variations on the following have been used to encrypt messages for thousands of years.
Letter → Number
Conversion Table
Encryption example
39
STOP THIEF (capitals)
19,20,15,16 20,8,9,5,6
14,17,2,5 17,7,10,24,1
NQBE QGJXA
Decryption example
Decryption works the same, except that you apply the inverse function.
g (a) = 3-1 (a - 9)
We’ll see that since gcd(3,26) = 1, the inverse of 3 is actually well defined modulo 26 and is
the number 9. This gives:
Caesar’s Cipher
Exercise
Prove that there are infinitely many prime numbers. (Discovered by Euclid).
Before the dawn of computers, many viewed number theory as last bastion of “pure math”
which could not be useful and must be enjoyed only for its aesthetic beauty.
No longer the case. Number theory is crucial for encryption algorithms. Of utmost
importance to everyone from Bill Gates, to the CIA, to Osama Bin Laden.
40
Proofs
Agenda
Direct Proof
Indirect Proof
Proof by Contradiction
A proof is a logically structured argument which demonstrates that a certain proposition is true.
When the proof is complete, the resulting proposition becomes a theorem, or if it is rather
simple, a lemma.
Proofs
Example
Proofs
Example
1. k 1(mod 3)
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
41
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
3. n k = 3n + 1
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
3. n k = 3n + 1
4. n k 3 = (3n + 1)3
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
3. n k = 3n + 1
4. n k 3 = (3n + 1)3
5. n k 3 = 27n 3 + 27n 2 + 9n + 1
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
42
3. n k = 3n + 1
4. n k 3 = (3n + 1)3
5. n k 3 = 27n 3 + 27n 2 + 9n + 1
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
3. n k = 3n + 1
4. n k 3 = (3n + 1)3
5. n k 3 = 27n 3 + 27n 2 + 9n + 1
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
3. n k = 3n + 1
4. n k 3 = (3n + 1)3
5. n k 3 = 27n 3 + 27n 2 + 9n + 1
8. m k 3-1 = m·9
43
Proofs
Example
1. k 1(mod 3)
2. n k-1 = 3n
3. n k = 3n + 1
4. n k 3 = (3n + 1)3
5. n k 3 = 27n 3 + 27n 2 + 9n + 1
8. m k 3-1 = m·9
9. k 31(mod 9)
Direct Proofs
Previous was an example of a direct proof. I.e., to prove that a proposition of the form “k P(k)
→ Q(k)” is true, needed to derive that “Q(k) is true” for any k which satisfied “P(k) is true”.
Direct Proofs
1) Deconstruct Axioms
Take the hypothesis and turn it into a usable form. Usually this amounts to just applying the
definition.
Direct Proofs
2) Mathematical Insights
Use your human intellect and get at “real reason” behind theorem.
44
EG: looking at what we’re trying to prove, we see that we’d really like to understand k 3. So let’s
take the cube of k ! From here, we’ll have to use some algebra to get the formula into a form
usable by the final step:
Direct Proofs
3) Reconstruct Conclusion
This is the reverse of step 1. At the end of step 2 we should have a simple form that could be
derived by applying the definition of the conclusion.
Proofs
Indirect
In addition to direct proofs, there are two other standard methods for proving
k P(k) → Q(k)
1. Indirect Proof
Proofs
Reductio Ad Absurdum
P →Q P Q P Q P Q
(P Q ) → (P Q )
45
Intuitively: Assume claim is false (so P must be true and Q false). Show that assumption was
absurd (so P false or Q true) so claim true!
Indirect Proof
Example
Indirect Proof
Example
Indirect Proof
Example
2. So k 2 is odd.
Indirect Proof
Example
2. So k 2 is odd.
3. n k 2 = 2n + 1
Indirect Proof
Example
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
46
Indirect Proof
Example
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
5. n (k - 1)(k + 1) = 2n
Indirect Proof
Example
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
5. n (k - 1)(k + 1) = 2n
6. 2 | (k - 1)(k + 1)
Indirect Proof
Example
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
5. n (k - 1)(k + 1) = 2n
6. 2 | (k - 1)(k + 1)
47
7. 2 | (k - 1) 2 | (k + 1) since 2 is prime
Indirect Proof
Example
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
5. n (k - 1)(k + 1) = 2n
6. 2 | (k - 1)(k + 1)
7. 2 | (k - 1) 2 | (k + 1) since 2 is prime
8. a k - 1 = 2a b k+1 = 2b
Indirect Proof
Example
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
5. n (k - 1)(k + 1) = 2n
6. 2 | (k - 1)(k + 1)
7. 2 | (k - 1) 2 | (k + 1) since 2 is prime
8. a k - 1 = 2a b k+1 = 2b
9. a k = 2a + 1 b k = 2b – 1
Indirect Proof
Example
48
PROVE: The square of an even number is even. (Ex. 1.16.b)
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
5. n (k - 1)(k + 1) = 2n
6. 2 | (k - 1)(k + 1)
7. 2 | (k - 1) 2 | (k + 1) since 2 is prime
8. a k - 1 = 2a b k+1 = 2b
9. a k = 2a + 1 b k = 2b – 1
Indirect Proof
2. So k 2 is odd.
3. n k 2 = 2n + 1
4. n k 2 - 1 = 2n
5. n (k - 1)(k + 1) = 2n
6. 2 | (k - 1)(k + 1)
7. 2 | (k - 1) 2 | (k + 1) since 2 is prime
8. a k - 1 = 2a b k+1 = 2b
9. a k = 2a + 1 b k = 2b – 1
49
Rational Numbers an Easier Characterization
Recall the set of rational numbers Q = the set of numbers with decimal expansion which is
periodic past some point (I.e. repeatinginginginginging…)
Easier characterization
Prove that the sum of any irrational number with a rational number is irrational:
Reductio Ad Absurdum
Example –English!
You don’t have to use a sequence of formulas. Usually an English proof is preferable! EG:
Suppose that claim is false. So [x is rational and y irrational] [=P] and [x+y is rational] [= Q].
But y = (x+y ) - x. The difference of rational number is rational since a/b –
c/d = (ad-bc)/bd.
Proofs
Disrefutation
Claims are usually of the form k P(k). Thus to disprove, enough to find one k –called a
counterexample– which makes P(k) false.
Disrefutation by Counterexample
50
Recurrence Relations
A recurrence relation is the recursive part of a recursive definition of either a number sequence
or integer function.
{fn } = 0,1,1,2,3,5,8,13,21,34,55,…
INITIALIZE: f0 = 0, f1 = 1
fn = fn-1+fn-2.Thus a recurrence relation for a sequence consists of an equation that expresses each
term in terms of lower terms.
A: Yes, for example could give a different set of initial conditions such as f0=1, f1= -1 in which
case would get the sequence
{fn } = 1,-1,0,-1,-2,-3,-5,-8,-13,-21,…
A: Infinitely many solutions as each pair of integer initial conditions (a,b) generates a unique
solution.
Often it is very hard to come up with a closed formula for counting a particular set, but coming
up with recurrence relation easier.
Q: Find a recurrence relation for the number of bit strings of length n which contain the string
00.
51
Recurrence Relations for Counting
I. If the first n-1 letters contain 00 then so does the string of length n. As last bit is free to
choose get contribution of 2an-1
II. Else, string must be of the form u00 with u a string of length n-2 not containing 00 and
not ending in 0 (why not?). But the number of strings of length n-3 which don’t contain
00 is the total number of strings minus the number that do. Thus get contribution of 2 n-3-
an-3
A: Need to give enough initial conditions to avoid ensure well-definedness. The smallest n for
which length is well defined is n=0. Thus the smallest n for which an = 2an-1 + 2n-3 - an-3 makes
sense is n=3. Thus need to give a0, a1 and a2 explicitly.
a2 = 1 (must be 00).
Note: example 6 on p. 313 gives the simpler recursion relation bn = bn-1 + bn-2 for strings which
do not contain two consecutive 0’s.
Q: Consider a savings plan in which $10 is deposited per month, and a 6%/year interest rate
given with payments made every month. If Pn represents the amount in the account after n
months, find a recurrence relation for Pn.
A: Pn = (1+r)·Pn-1 +10
Partition Function
52
EG: All the partitions of {1,2,3} are:
1. { {1,2,3} }
2. { {1,2}, {3} }
3. { {1,3}, {2} }
4. { {2,3}, {1} }
5. { {1},{2},{3} }
Partition Function
Let’s find a recursion relation for the partition function. There are n possible scenarios for the
number of members on n’s team:
By the sum rule, we need to count the number of partitions of each kind, and then add together.
Partition Function
k: n has k friends
Furthermore, there are pn-k-1 ways of partitioning the rest of the n elements. Using the product and
sum rules we get:
We will learn how to give closed solutions to certain kinds of recurrence relations.
Unfortunately, most recurrence relations cannot be solved analytically.
EG: If you can find a closed formula for partition function tell me!
53
However, recurrence relations can all be solved quickly by using dynamic programming.
Numerical Solutions
Dynamic Programming
an = f (a0,a1,…,an-2,an-1)
Then can always solve the recurrence relation for first n values by using following pseudocode:
table0 = a0
for(i = 1 to n)
tablei = f(table0,table1,…,tablei-1)
return table
Pseudocode becomes:
integer-array a(integer n)
table0 = table1 = 0
table2 = 1
for(i = 3 to n)
tablei = 2i-3-tablei-3+2*tablei-1
return table
54
Dynamic Program for String Example
Solve up to n=6
Pseudocode becomes:
integer-array p(integer n)
for(i = 1 to n)
sum = 1
for(j = 1 to n-1)
sum += tablej*C(n-1,n-1-j)
tablen = sum
return table
There is a class of recurrence relations which can be solved analytically in general. These are
called linear recurrences and include the Fibonacci recurrence.
Linear Recurrences
The only case for which telescoping works with a high probability is when the recurrence gives
the next value in terms of a single previous value. But…
55
There is a class of recurrence relations which can be solved analytically in general. These are
called linear recurrences and include the Fibonacci recurrence.
Solving Fibonacci
2) Find all possible r’s that seem to make this work. Call these 1 r1 and r2. Modify assumed
solution to general solution an = Ar1n +Br2n where A,B are constants.
Solving Fibonacci
Notice that all three terms have a common r n-2 factor, so divide this out:
Solving Fibonacci
Call these r1 and r2.1 General solution is an = Ar1n +Br2n where A,B are constants.
r = (1 5)/2
So r1 = (1+5)/2, r2 = (1-5)/2
General solution:
an = A [(1+5)/2]n +B [(1-5)/2]n
Solving Fibonacci
56
1=a1 = A [(1+5)/2]1 +B [(1-5)/2]1 = A(1+5)/2 +B (1-5)/2 =
(A+B )/2 + (A-B )5/2
1. an = 2an-1
3. an = an-12
4. Partition function:
1. an = 2an-1: YES
Partition function
NO. This is linear, but coefficients are not constant as C (n -1, n -1-i ) is a non-constant function
of n.
To solve such recurrences we must first know how to solve an easier type of recurrence relation:
1. an = 2an-1
3. Partition function:
57
Linear Recurrences with Constant Coefficients
1. an = 2an-1: YES
3. Partition function:
The 3-step process used for the Fibonacci recurrence works well for general homogeneous linear
recurrence relations with constant coefficients. There are a few instances where some
modification is necessary.
Homogeneous- Complications
1) Repeating roots in characteristic equation. Repeating roots imply that don’t learn
anything new from second root, so may not have enough information to solve formula
with given initial conditions. We’ll see how to deal with this on next slide.
2) Non-real number roots in characteristic equation. If the sequence has periodic behavior,
may get complex roots (for example an = -an-2)1. We won’t worry about this case (in
principle, same method works as before, except use complex arithmetic).
r 2 - 2r +1 = 0
an = Ar1n+Bnr1n
58
Solve an = 2an-1-an-2, a0 = 1, a1 = 2
1 = a0 = A+B·0·10= A
2 = a0 = A·11+B·1·11= A+B
2 = 1+B implies B = 1.
an - 2an-1 = 1
1) Solve with the RHS set to 0, i.e. solve the homogeneous case.
an - 2an-1 = 1
an - 2an-1 = 0
Characteristic equation: r - 2 = 0
an = A·2n
2) Add a particular solution to get general solution for an - 2an-1 = 1. Use rule:
There are little tricks for guessing particular nonhomogeneous solutions. For example, when the
RHS is constant, the guess should also be a constant.1
59
So guess a particular solution of the form bn=C.
Finally, use initial conditions to get closed solution. In the case of the Towers of Hanoi
recursion, initial condition is:
a1 = 1
1 = a1 = A·21 -1 = 2A –1.
Therefore, 2 = 2A, so A = 1.
Final answer: an = 2n -1
More Complicated
EG: Find the general solution to recurrence from the bit strings example: an = 2an-1 + 2n-3 - an-3
Characteristic equation: r 3 - 2r +1 = 0.
r 3 - 2r +1 = (r -1)(r 2 +r -1).
More Complicated
r 3 - 2r +1 = (r -1)(r 2 +r -1).
r = (-1 5)/2
So r1 = 1, r2 = (-1+5)/2, r3 = (-1-5)/2
60
an = A + B [(-1+5)/2]n +C [(-1-5)/2]n
So particular solution is bn = 2n
Final answer:
Exercise
an = (n-1)an-2
Example
Suppose need to buy bagels for 13 students (1 each) out of 17 types but George and Harry are
totally in love with Francesca and will only want the type of bagel that she has. Furthermore,
Francesca only likes garlic or onion bagels.
Q: How many ways are there of buying 13 bagels from 17 types if repetitions are allowed, order
doesn’t matter and at least 3 are garlic or at least 3 are onion?
{x1+x2+…+x17 = 13 | x1 3 or x2 3}
61
=|{RHS=10}| + |{RHS=10}|}| - |{RHS=7}|
=10,378,313.
Standard Inclusion-Exclusion
Inclusion-Exclusion principle:
Inclusion-Exclusion-Inclusion
“Inclusion-Exclusion-Inclusion” principle:
Proof of
Inclusion-Exclusion-Inclusion
Inclusion-Exclusion-Inclusion
Inclusion-Exclusion-Inclusion
A: Use the formula that the number of positive integers up to N which are divisible by d is
N/d. With I-E-I principle get and the fact that for relatively prime a, b both numbers divide x
iff their product ab divides x :
= 543
Inclusion-Exclusion-Inclusion
union =
all terms
- all pairs
+ all triples
62
…
Suppose you throw 6 crumbs in the park and 3 pigeons eat all the crumbs. How many ways
could the 3 pigeons have eaten the crumbs if we only care about which pigeons ate which
crumbs?
A function is non-onto if it misses some element in the codomain. So consider following sets for
each pigeon i :
|{non-onto}|=|A1A2A3|=
|A1|+|A2|+|A3|-|A1A2|-|A1A3|-|A2A3|
By symmetry, |A1|=|A2|=|A3| as no pigeon is special. Also, A1A2 is the set of functions which
miss both 1 and 2. Again, by symmetry |A1A2|=|A1A3|=|A1A3|. So:
Finally, A1 is just the set of functions into {2,3} while A1A2 is the set of functions into {3} so:
63
|{non-onto}| = 3·26 - 3·16
THM: The number of onto functions from a set with m elements to a set with n elements (m n)
is given by the formula:
Proof.
4 evil but naïve witches decide to have a trick-or-treat party. Each witch is supposed to bring a
treat. The treats are thrown inside a bag and are randomly redistributed, 1 treat per witch.
Suppose that each treat is poisonous, but that each witch assumes that he/she is the only one that
brought a poisonous treat.
Counting Derangements
A: What we are asking to count is the number of derangements from a set of 4 elements to itself.
DEF: A derangement of {1,2,3,…,n} is a permutation f on the set such that for no element i
does f (i ) = i.
Counting Derangements
|{witch→poison derangements}|
64
-C (4,3)|A1A2A3|+C (4,4)|A1A2A3A4|
= 4!-4·3!/1!+ 4·3·2!/2!-4·3·2·1!/3!+4·3·2·1/4!
Witch Problem
Finally, divide the number of derangements by the number of permutations to get the probability
that all die:
Counting Derangements
General Formula
The proof is just a generalization of the argument in the witch party problem.
Exercise:
Find the number of positive integers not exceeding 100 which are either odd or the
square of an integer.
65