0% found this document useful (0 votes)
17 views

MATH 211 - LECTURE NOTES Discrete Structures-1

Each bit position can be filled by one of two options (0 or 1). By the product rule, the number of possible bit strings of length n is 2 × 2 × ... × 2 = 2n.

Uploaded by

Kiki Kyms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

MATH 211 - LECTURE NOTES Discrete Structures-1

Each bit position can be filled by one of two options (0 or 1). By the product rule, the number of possible bit strings of length n is 2 × 2 × ... × 2 = 2n.

Uploaded by

Kiki Kyms
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

LECTURE NOTES: DISCRETE STRUCTURES

Set Theory

Introduction to Set Theory

A set is a structure, representing an unordered collection (group, plurality) of zero or more


distinct (different) objects.

Set theory deals with operations between, relations among, and statements about sets.

Basic notations for sets

For sets, we’ll use variables S, T, U, …

We can denote a set S in writing by listing all of its elements in curly braces:

{a, b, c} is the set of whatever 3 objects are denoted by a, b, c.

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).

e.g., {x | x is an integer where x>0 and x<5 }

Basic properties of sets

Sets are inherently unordered:

No matter what objects a, b, and c denote,


{a, b, c} = {a, c, b} = {b, a, c} =
{b, c, a} = {c, a, b} = {c, b, a}.

All elements are distinct (unequal);


multiple listings make no difference!

{a, b, c} = {a, a, b, a, b, c, c, c, c}.

This set contains at most 3 elements!

Definition of Set Equality

Two sets are declared to be equal if and only if they contain exactly the same elements.

In particular, it does not matter how the set is defined or denoted.

For example: The set {1, 2, 3, 4} =


{x | x is an integer where x>0 and x<5 } =

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).

Symbols for some special infinite sets:


N = {0, 1, 2, …} The natural numbers.
Z = {…, -2, -1, 0, 1, 2, …} The integers.
R = The “real” numbers, such as 374.1828471929498181917281943125…

Infinite sets come in different sizes!

Venn Diagrams

Basic Set Relations: Member of xS (“x is in S”) is the proposition that object x is an
lement or member of set S.

e.g. 3N, “a”{x | x is a letter of the alphabet}

Can define set equality in terms of  relation:


S,T: S=T  (x: xS  xT)
“Two sets are equal iff they have all the same members.”

xS : (xS) “x is not in S”

The Empty Set

 (“null”, “the empty set”) is the unique set that contains no elements whatsoever.

 = {} = {x|False}

No matter the domain of discourse,


we have the axiom

x: x.

Subset and Superset Relations

ST (“S is a subset of T”) means that every element of S is also an element of T.

ST  x (xS → xT)

S, SS.

ST (“S is a superset of T”) means TS.

2
Note S=T  ST ST.

means (ST), i.e. x(xS  xT)

Proper (Strict) Subsets & Supersets

ST (“S is a proper subset of T”) means that ST but . Similar for ST.

Sets Are Objects, Too!

The objects that are elements of a set may themselves be sets.

E.g. let S={x | x  {1,2,3}}


then S={,
{1}, {2}, {3},
{1,2}, {1,3}, {2,3},
{1,2,3}}

Note that 1  {1}  {{1}} !!!!

Cardinality and Finiteness

|S| (read “the cardinality of S”) is a measure of how many different elements S has.

E.g., ||=0, |{1,2,3}| = 3, |{a,b}| = 2,


|{{1,2,3},{4,5}}| = ____

We say S is infinite if it is not finite.

What are some infinite sets we’ve seen?

The Power Set Operation

The power set P(S) of a set S is the set of all subsets of S. P(S) = {x | xS}.

E.g. P({a,b}) = {, {a}, {b}, {a,b}}.

Sometimes P(S) is written 2S.


Note that for finite S, |P(S)| = 2|S|.

It turns out that |P(N)| > |N|.


There are different sizes of infinite sets!

Ordered n-tuples

For nN, 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 (1, 2)  (2, 1)  (2, 1, 1).

Empty sequence, singlets, pairs, triples, quadruples, quintuples, …, n-tuples.

Cartesian Products of Sets

For sets A, B, their Cartesian product


AB : {(a, b) | aA  bB }.

E.g. {a,b}{1,2} = {(a,1),(a,2),(b,1),(b,2)}

Note that for finite A, B, |AB|=|A||B|.

Note that the Cartesian product is not commutative: AB: AB =BA.

Extends to A1  A2  …  An...

The Union Operator

For sets A, B, their union AB is the set containing all elements that are either in A, or (“”)
in B (or, of course, in both).

Formally, A,B: AB = {x | xA  xB}.

Note that AB contains all the elements of A and it contains all the elements of B:
A, B: (AB  A)  (AB  B)

Union Examples

{a,b,c}{2,3} = {a,b,c,2,3}

{2,3,5}{3,5,7} = {2,3,5,3,5,7} ={2,3,5,7}

The Intersection Operator

For sets A, B, their intersection AB is the set containing all elements that are simultaneously
in A and (“”) in B.

Formally, A,B: AB{x | xA  xB}.

Note that AB is a subset of A and it is a subset of B:


A, B: (AB  A)  (AB  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.

(AB=)

Example: the set of even integers is disjoint with the set of odd integers.

Inclusion-Exclusion Principle

How many elements are in AB?


|AB| = |A| + |B| − |AB|

Example:

{2,3,5}{3,5,7} = {2,3,5,3,5,7} ={2,3,5,7}

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  xA  xB
= x  ( xA → xB ) 

Also called: The complement of B with respect to A.

Set Difference Examples

{1,2,3,4,5,6} − {2,3,5,7,9,11} = ___________

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 Difference - Venn Diagram

A-B is what’s left after B “takes a bite out of A”

Set Complements

The universe of discourse can itself be considered a set, call it U.

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,

More on Set Complements

An equivalent definition, when U is clear:

Set Identities

Identity: A=A AU=A

Domination: AU=U A=

Idempotent: AA = A = AA

Double complement:

Commutative: AB=BA AB=BA

Associative: A(BC)=(AB)C
A(BC)=(AB)C

DeMorgan’s Law for Sets

Exactly analogous to (and derivable from) DeMorgan’s Law for propositions.

Proving Set Identities

To prove statements about sets, of the form


E1 = E2 (where Es are set expressions), here are three useful techniques:

Prove E1  E2 and E2  E1 separately.

Use logical equivalences

Method 1: Mutual subsets

Example: Show A(BC)=(AB)(AC).

Show A(BC)(AB)(AC).

Assume xA(BC), & show x(AB)(AC).

We know that xA, and either xB or xC.

Case 1: xB. Then xAB, so x(AB)(AC).

6
Case 2: xC. Then xAC , so x(AB)(AC).

Therefore, x(AB)(AC).

Therefore, A(BC)(AB)(AC).

Show (AB)(AC)  A(BC). …

Method 3: Membership Tables

Just like truth tables for propositional logic.

Columns for different set expressions.

Rows for all combinations of memberships in constituent sets.

Use “1” to indicate membership in the derived set, “0” for non-membership.

Prove equivalence with identical columns.

Membership Table Example

Prove (AB)−B = A−B.

Membership Table Exercise

Prove (AB)−C = (A−C)(B−C).

Generalized Union

Binary union operator: AB

n-ary union:
AA2…An : ((…((A1 A2) …) An)
(grouping & order is irrelevant)

“Big U” notation:

Or for infinite sets of sets:

Generalized Intersection

Binary intersection operator: AB

n-ary intersection:
AA2…An((…((A1A2)…)An)
(grouping & order is irrelevant)

7
“Big Arch” notation:

Or for infinite sets of sets:

Counting Techniques

Counting techniques are important in programming design.

EG: How large an array or hash table or heap is needed?

EG: What is the average case complexity of quick-sort?

Answers depend on being able to count.

Counting is useful in the gambling arena also.

EG: What should your poker strategy be?

 Counting Basics
Set Cardinalities

Interested in answering questions such as:

 How many bit strings of length n are there?

 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?

 How many ways can a dating service match 13 men to 17 women?

COMMON THEME: convert to set cardinality problems so each question above is a about
counting the number of elements in some set:

Q: What is the corresponding set in each case?

 Counting Basics
Set Cardinalities

A: The set to measure the cardinality of is…

 How many bit strings of length n are there?

 {bit strings of length n}

 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?

 {length 11 bit strings with 0-streak of length 7}

 {length 11 bit strings with 1-streak of length 7}

 How many ways to match 13 M to 17 W ?

 { f :{1,2,…,13} → {1,2,…,17} | f is 1-to-1}

 Product Rule

As counting problems can be turned into set cardinality problems, useful to express counting
principles set theoretically.

Product-Rule: For finite sets A, B:

|AB| = |A||B|

Q: How many bit strings of length n are there?

 Product Rule

A: 2n.

Proof : Let S = {bit strings of length n}. S is in 1-to-1 correspondence with

Consequently the product rule implies:

 Cardinality of Power Set

THM: |P ({1,2,3,…,n})| = 2n

Proof . The set of bit strings of length

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.

Q: Which of the following should be counted:

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.

Q: Which of the following should be counted:

1. 10011001010

No!, longest streak has length 2.

1. 0110111101011 No! Too long.

2. 10000000011 No! Streak too long.

3. 10000000101 Yes!

4. 01111111010 Yes!

 Sum Rule

We are trying to compute the cardinality of:

{length 11 bit strings with 0-streak of length 7} {length 11 bit strings with 1-streak of length
7}

Call the first set A and the second set B.

Q: Are A and B disjoint?

 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!

When counting the cardinality of a disjoint union we use:

SUM RULE: If A and B are disjoint, then

|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

A = {length 11 bit strings with

0-streak of length exactly 7}

into more cases and use sum rule:

A1 = {00000001***} (* is either 0 or 1)

A2 = {100000001**}

A3 = {*100000001*}

A4 = {**100000001}

A5 = {***10000000}.

Apply sum rule:

|A| = |A1| +|A2| +|A3| +|A4| +|A5|

 Sum Rule

So let’s count each set.

A1 = {00000001***}. There are 3 *’s, each with 2 choices, so product rule gives |A1| = 23 = 8

A2 = {100000001**}. There are 2 *’s. Therefore, |A2| = 22 = 4

A3 = {*100000001*}, A4 = {**100000001}

Similarly: |A2| = |A3| = |A4| = 4

A5 = {***10000000}.

|A1| = |A5| = 8

|A| = |A1| +|A2| +|A3| +|A4| +|A5| = 8+4+4+4+8 = 28.

Therefore answer is 56.

Counting Functions

How many ways to match 13M to 17W ?

{ f :{1,2,…,13} → P {1,2,…,17} | f is 1-to-1}

11
Use product rule thoughtfully.

17 possible output values for f (1)

16 values remain for f (2)

i. 17-i+1 values remain for f (i )

17-13+1=5 values remain for f (13)

ANS: 17·16·15 ·14 ·… ·7·6·5 = 17! / 4!

Q: In general how many 1-to-1 functions from size k to size n set?

Counting Functions

A: The number of 1-to-1 functions from a size k set to a size n set is n ! / (n - k) !

As long as k is no larger than n. If k > n there are no 1-to-1 functions.

Q: How about general functions from size k sets to size n sets?

 Counting Functions

A: The number of functions from a size k set to a size n set is

nk

Inclusion-Exclusion

The principle of Inclusion-Exclusion generalized the sum rule the the case of non-empty
intersection:

INCLUSION-EXCLUSION: If A and B are sets, then

|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.

Diagram gives proof

Inclusion- Exclusion principle:

12
Exercise

How many positive integers with exactly three decimal digits are…

…divisible by 7?

…odd?

…have the same 3 digits?

…are not divisible by 3 or 4?

How many ways can the letters a,b,c,d be arranged such that a is not immediately followed by b?

The Pigeonhole Principle

The pigeonhole principle is the (rather obvious) statement:

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:

Pigeons: The 12 numbers

Pigeonholes: The sets

[0,0.1), [0.1,0.2), [0.2,0.3), … ,[0.9,1), {1}

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.

Pigeons –the n people (with n > 1).

Pigeonholes –the possible number of friends. I.e. the set {0,1,2,3,…n-1}


13
Pigeonhole Principle

The proof proceeds with 2 cases.

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! →

Generalized Pigeonhole Principle

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.

Generalized Pigeonhole Principle

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.

EG: f (x ) = 1 if x is odd, and 0 if x is even.

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.

EG: Let f : Z → R be given by f (x ) = x 2

Q1: What are the domain and co-domain?

Q2: What’s the image of -3 ?

Q3: What are the pre-images of 3, 4?

Q4: What is the range f (Z) ?

Functions. Basic-Terms.

f : Z → R is given by f (x ) = x 2

A1: domain is Z, co-domain is R

A2: image of -3 = f (-3) = 9

A3: pre-images of 3: none as 3 isn’t an integer!

pre-images of 4: -2 and 2
15
A4: range is the set of perfect squares

f (Z) = {0,1,4,9,16,25,…}

Functions and Java

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.

EG: int f(double x){

return x<0 ? –1 :

( x>0 ? 1 : 0 );}

The domain is double the codomain is int.

Q: What does this function do?

Functions and Java

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.

The effect of functions on subsets of the domain is often important.

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 }.

NOTE: Even when f is not invertible, the inverse image is defined!

Functions. Sub-ranges.

EG: f : Z → R with f (x ) = x 2

Q1: Calculate f –1(3)

Q2: Calculate f –1(4)

Q3: Calculate f ( {-9,-5,-3,0,1,2,3,4} )

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) = 

A2: f –1(4) = {-2, 2}

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}

One-to-One, Onto, Bijection. Intuitively.

Represent functions using “node and arrow” notation:

One-to-One means that no clashes occur.

BAD: a clash occurred, not 1-to-1

GOOD: no clashes, is 1-to-1

Onto means that every possible output is hit

BAD: 3rd output missed, not onto

GOOD: everything hit, onto

One-to-One, Onto, Bijection. Intuitively.

Bijection means that when arrows reversed, a function results. Equivalently, that both one-
to-one’ness and onto’ness occur.

BAD: not 1-to-1. Reverse over-


determined:

BAD: not onto. Reverse


under-determined:

GOOD: Bijection. Reverse


is a function:

One-to-One, Onto, Bijection. Formal Definition.

DEF: A function f : A →B is:


17
one-to-one (or injective) if different elements of A always result in different images in B.

onto (or surjective) if every element in B is hit by f. I.e., f (A ) = B.

a one-to-one correspondence (or a bijection, or invertible) if f is both one-to-one as well as


onto.

If f is invertible, its inverse f -1 : B →A is well defined by taking the unique element


in the pre-image of b, for each b  B.

One-to-One, Onto, Bijection. Examples.

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 : {people} → {people} is given by f (x ) = the father of x.

One-to-One, Onto, Bijection. Examples.

f : Z → R, f (x ) = x 2: none

f : Z → Z, f (x ) = 2x : 1-1

f : R → R, f (x ) = x 3: 1-1, onto, bijection, inverse is f (x ) = x (1/3)

f : Z → N, f (x ) = |x |: onto

f (x ) = the father of x : none

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.

DEF: Suppose that g : A → B and f : B → C are functions. Then the composite

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

f : {people} → {people}, f (x ) = the father of x, and g = f

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

f •g (x ) = x (true for any function composed with its inverse)

f : {people} → {people}, f (x ) = g(x ) = the father of x

f •g (x ) = grandfather of x from father’s side

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 )

where f appears n –times on the right side.

Q1: Given f : Z → Z, f (x ) = x 2 find f 4

Q2: Given g : Z → Z, g (x ) = x + 1 find g n

Q3: Given h(x ) = the father of x, find hn

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

A3: h (x ) = the father of x,

19
hn (x ) = x ’s n’th patrilineal ancestor

Ceiling and Floor

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.

NOTATION: floor(x) = x , ceiling(x) = x 

Q: Compute 1.7, -1.7, 1.7, -1.7.

Ceiling and Floor

A: 1.7 = 1, -1.7 = -2,

1.7 = 2, -1.7 = -1

Q: What’s the difference between the floor function and the (int) casting function in Java?

Ceiling and Floor

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

Consider the function f : R2 → R2 defined by the formula

f (x,y ) = ( ax+by, cx+dy )

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.

For finite sets, the basic model of size n is:

n = {1, 2, 3, 4, …, n-1, n }

Sequences

DEF: Given a set S, an (infinite) sequence in S is a function N → S. A finite sequence in S


is a function n → S.

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.

Q: Give the first 5 terms of the sequence defined by the formula

Sequence Examples

A: Plug in for i in sequence 0, 1, 2, 3, 4:

Formulas for sequences often represent patterns in the sequence.

Q: Provide a simple formula for each sequence:

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

A: Try to find the patterns between numbers.

3,6,11,18,27,38,51, …

a1=6=3+3, a2=11=6+5, a3=18=11+7, … and in general ai +1 = ai +(2i +3). This is actually a


good enough formula. Later we’ll learn techniques that show how to get the more explicit
formula:

ai = 6 + 4(i –1) + (i –1)2

b) 0,2,8,26,80,242,728,…

If you add 1 you’ll see the pattern more clearly.

21
ai = 3i –1

1,1,2,3,5,8,13,21,34,…

This is the famous Fibonacci sequence given by

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

Q: What sequence is defined by

a1 =1, a2 =1 ai+2 = ai ai+1

Bit Strings

A: a0 =1, a1 =1 ai+2 = ai ai+1:

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:

This is read as “the sum from i =0 to i =n of ai”

Note how “S” converts commas into plus signs.

One can also take sums over a set of numbers:

Summations

EG: Consider the identity sequence

ai = i

Or listing elements: 0, 1, 2, 3, 4, 5,…

The sum of the first n numbers is given by:

(The first term 0 is dropped)

22
Summation Formulas –Arithmetic

There is an explicit formula for the previous:

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 – Geometric

Geometric sequences are number sequences with a fixed constant of proportionality r


between consecutive terms. For example:

2, 6, 18, 54, 162, …

Q: What is r in this case?

Summation Formulas

2, 6, 18, 54, 162, …

A: r = 3.

In general, the terms of a geometric sequence have the form

ai = a r i

where a is the 1st term when i starts at 0.

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!

Q: Use the previous formulas to evaluate each of the following

Summation Examples

A:

Use the arithmetic sum formula and additivity of summation:

23
Summation Examples

A:

Apply the geometric sum formula directly by setting a = 1 and r = 2:

Cardinality and Countability

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:

{☺,}

{ , }

{Ø , {Ø,{Ø,{Ø}}} }

These all share “2-ness”.

Cardinality and Countability

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

{0, 2, 4, 6, 8, 10, 12, …}  N

So set of even numbers ought to be smaller than the set of natural number because of strict
containment.

Q: Any problems with this?

Cardinality and Countability

A: Set of even numbers is obtained from N by multiplication by 2. I.e.

{even numbers} = 2•N

For finite sets, since multiplication by 2 is a one-to-one function, the size doesn’t change.

EG: {1,7,11} – 2 → {2,14,22}

24
Another problem: set of even numbers is disjoint from set of odd numbers. Which one is
bigger?

Cardinality and Countability – Finite Sets

DEF: Two sets A and B have the same cardinality if there’s a bijection

f:A→B

For finite sets this is the same as the old definition:

{☺,}

{ , }

Cardinality and Countability – Infinite Sets

But for infinite sets…

…there are surprises.

DEF: If S is finite or has the same cardinality as N, S is called countable.

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

Q: Why are the following sets countable?

{0,2,4,6,8,…}

{1,3,5,7,9,…}

{1,3,5,7, }

Countability – Examples

{0,2,4,6,8,…}: Just set up the bijection f (n ) = 2n

{1,3,5,7,9,…} : Because of the bijection f (n ) = 2n + 1

{1,3,5,7, } has cardinality 5 so is therefore countable


25
Z: This one is more interesting. Continue on next page:

Countability of the Integers

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:

Demonstrating Countability. Useful Facts

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.

THM: Suppose A is a set. If there is an one-to-one function f : A → N, or there is an onto


function g : N → A then A is countable.

The proof requires the principle of mathematical induction, which we’ll get to at a later date.

Uncountable Sets

But R is uncountable (“not countable”)

Q: Why not ?

Uncountability of R

A: This is not a trivial matter. Here are some typical reasonings:

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

Last argument is the closest.

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.

What would this list look like?

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,…

DEF: A decimal number

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

Evaluate the double summation:

Show that if A is uncountable and B is countable then A-B is uncountable.

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.

E.G., of great importance in COMS 4180 “Network Security”.

Importance of Number Theory

The encryption algorithms depend heavily on modular arithmetic. We need to develop


various machinery (notations and techniques) for manipulating numbers before can describe
algorithms in a natural fashion.

First we start with divisors.

Divisors

DEF: Let a, b and c be integers such that

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

Q: Which of the following is true?

77 | 7

7 | 77

24 | 24

0 | 24

24 | 0

28
Divisors.
Examples

A:

77 | 7: false bigger number can’t divide smaller positive number

7 | 77: true because 77 = 7 · 11

24 | 24: true because 24 = 24 · 1

0 | 24: false, only 0 is divisible by 0

24 | 0: true, 0 is divisible by every number (0 = 24 · 0)

Formula for Number of Multiples up to given n

Q: How many positive multiples of 15 are less than 100?

Formula for Number of Multiples up to given n

A: Just list them:

15, 30, 45, 60, 75, 80, 95.

Therefore the answer is 6.

Q: How many positive multiples of 15 are less than 1,000,000?

Formula for Number of Multiples up to Given n

A: Listing is too much of a hassle. Since 1 out of 15 numbers is a multiple of 15, if


1,000,000 were were divisible by 15, answer would be exactly 1,000,000/15. However, since
1,000,000 isn’t divisible by 15, need to round down to the highest multiple of 15 less than
1,000,000 so answer is 1,000,000/15.

In general: The number of d-multiples less than N is given by:

|{m  Z+ | d |m and m  N }| = N/d

Divisor Theorem

THM: Let a, b, and c be integers. Then:

a|b  a|c → a|(b + c )

a|b → a|bc

29
a|b  b|c → a|c

EG:

17|34  17|170 → 17|204

17|34 → 17|340

6|12  12|144 → 6 | 144

Divisor Theorem
Proof of no. 2

In general, such statements are proved by starting from the definitions and manipulating to
get the desired results.

EG. Proof of no. 2 (a|b → a|bc ):

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.

Q: Which of the following are prime?

0,1,2,3,4,5,6,7,8,9,10

Prime Numbers

A: 0, and 1 not prime since not positive and greater or equal to 2

2 is prime as 1 and 2 are only factors

3 is prime as 1 and 3 are only factors.

4,6,8,10 not prime as non-trivially divisible by 2.

5, 7 prime.

9 = 3 · 3 not prime.

Last example shows that not all odd numbers are prime.

Fundamental Theorem of Arithmetic

30
THM: Any number n  2 is expressible as as a unique product of 1 or more prime numbers.

Note: prime numbers are considered to be “products” of 1 prime.

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

Fundamental Theorem of Arithmetic

A: 22 = 2·11, 100 = 2·2·5·5,

12 = 2·2·3, 17 = 17

Convention: Want 1 to also be expressible as a product of primes. To do this we define 1 to


be the “empty product”. Just as the sum of nothing is by convention 0, the product of
nothing is by convention 1.

➔Unique factorization of 1 is the factorization that uses no prime numbers at all.

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)

if ( n < 2 ) return false

for(i = 2 to n -1)

if( i |n ) // “divides”! not disjunction

return false

return true

Q: What is the running time of this algorithm?

Primality Testing

A: Assuming divisibility testing is a basic operation –so O (1) (this is an invalid


assumption)– then above primality testing algorithm is O (n).

Q: What is the running time in terms of the input size k ?

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

n = O (10k ). Therefore, running time is O (10k ). REALLY HORRIBLE!

Q: Can we improve algorithm?

Primality Testing

A:

Don’t try number bigger than n/2

After trying 2, don’t try any other even numbers, because know n is odd by this point.

In general, try only smaller prime numbers

In fact, only need to try to divide by prime numbers no larger than as we’ll see next:

Primality Testing

LEMMA: If n is a composite, then its smallest prime factor is 

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

EG: Test if 139 and 143 are prime.

List all primes up to and check if they divide the numbers.

2: Neither is even

3: Sum of digits trick: 1+3+9 = 13, 1+4+3 = 8 so neither divisible by 3

5: Don’t end in 0 or 5

7: 140 divisible by 7 so neither div. by 7

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 .

Conclude: 139 is prime, 143 is composite.

Division

Remember long 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.

Greatest Common Divisor


Relatively Prime

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.

Greatest Common Divisor


Relatively Prime

Q: Find the following gcd’s:

gcd(11,77)

gcd(33,77)

gcd(24,36)

gcd(24,25)

Greatest Common Divisor


Relatively Prime

33
A:

gcd(11,77) = 11

gcd(33,77) = 11

gcd(24,36) = 12

gcd(24,25) = 1. Therefore 24 and 25 are relatively prime.

NOTE: A prime number are relatively prime to all other numbers which it doesn’t divide.

Greatest Common Divisor


Relatively Prime

EG: More realistic. Find gcd(98,420).

Find prime decomposition of each number and find all the common factors:

98 = 2·49 = 2·7·7

420 = 2·210 = 2·2·105 = 2·2·3·35

= 2·2·3·5·7

Underline common factors: 2·7·7, 2·2·3·5·7

Therefore, gcd(98,420) = 14

Greatest Common Divisor


Relatively Prime

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.

Q: Find a maximal pairwise relatively prime subset of

{ 44, 28, 21, 15, 169, 17 }

Greatest Common Divisor


Relatively Prime

A: A maximal pairwise relatively prime subset of {44, 28, 21, 15, 169, 17} :

{17, 169, 28, 15} is one answer.

{17, 169, 44, 15} is another answer.

Least Common Multiple


34
DEF: The least common multiple of a, and b (lcm(a,b) ) is the smallest number m which is
divisible by both a and b.

Equivalently: lcm(a,b) is biggest number which divides any x divisible by both a and b

Q: Find the lcm’s:

lcm(10,100)

lcm(7,5)

lcm(9,21)

Least Common Multiple

A:

lcm(10,100) = 100

lcm(7,5) = 35

lcm(9,21) = 63

THM: lcm(a,b) = ab / gcd(a,b)

lcm in terms of gcd


Proof

THM: lcm(a,b) = ab / gcd(a,b)

Proof. Let g = gcd(a,b).

lcm in terms of gcd


Proof

THM: lcm(a,b) = ab / gcd(a,b)

Proof. Let g = gcd(a,b). Factor a and b using g: a = gx, b = gy where x and y are relatively
prime.

lcm in terms of gcd


Proof

THM: lcm(a,b) = ab / gcd(a,b)

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

THM: lcm(a,b) = ab / gcd(a,b)

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.

lcm in terms of gcd


Proof

THM: lcm(a,b) = ab / gcd(a,b)

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

There are two types of “mod” (confusing):

the mod function

Inputs a number a and a base b

Outputs a mod b a number between 0 and b –1 inclusive

This is the remainder of ab

Similar to Java’s % operator.

the (mod) congruence

Relates two numbers a, a’ to each other relative some base b

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.

-10 mod 3 = 2, but in Java –10%3 = -1.

Q: Compute

113 mod 24

36
-29 mod 7

mod function

A: Compute

113 mod 24:

-29 mod 7

mod function

A: Compute

113 mod 24:

-29 mod 7

mod function

A: Compute

113 mod 24:

-29 mod 7

mod function

A: Compute

113 mod 24:

-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’ ).

Equivalently: a mod b = a’ mod b

Q: Which of the following are true?

3  3 (mod 17)

3  -3 (mod 17)

172  177 (mod 5)

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)

3  -3 (mod 17) False. (3-(-3)) = 6 isn’t divisible by 17.

172  177 (mod 5) True. 172-177 = -5 is a multiple of 5

-13  13 (mod 26) True: -13-13 = -26 divisible by 26.

(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)

Suppose a  a’ (mod b) and c  c’ (mod b) Then:

a+c  (a’+c’ )(mod b)

ac  a’c’ (mod b)

a k  a’ k
(mod b)

Modular arithmetic
harder examples

Q: Compute the following.

3071001 mod 102

(-45 · 77) mod 17

Proving Modular Identities

We first need:

38
THM: a  a’ (mod b) → k a = a’ + kb

Proof.  direction: If a = a’ + kb, then (a-a’ ) = kb so that b | (a-a’ ) which by definition


means that a  a’ (mod b)

direction: If a  a’ (mod b), by definition

b | (a-a’ ) so for some k we have (a-a’ ) = kb which becomes a = a’ + kb •

This is a handy little theorem as we’ll see next:

Proving Modular Identities

Prove the identity

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

Thus ac = (a’ + bk)(c’ + bl ) = a’c’ +b(kc’+la’+bkl). Therefore

(ac-a’c’ ) = b(kc’+la’+bkl) is divisible by b and hence by definition, ac  a’ c’ (mod b)

Simple Encryption

Variations on the following have been used to encrypt messages for thousands of years.

Convert a message to capitals.

Think of each letter as a number between 1 and 26.

Apply an invertible modular function to each number.

Convert back to letters (0 becomes 26).

Letter → Number
Conversion Table

Encryption example

Let the encryption function be

f (a) = (3a + 9) mod 26

Encrypt “Stop Thief”

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.

EG: Find the inverse of

f (a) = (3a + 9) mod 26

If we didn’t have to deal with mod 26, inverse would be

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:

g (a) = 9 (a - 9) mod 26 = (9a – 3) mod 26

Caesar’s Cipher

f (a) = (a+3) mod 26

Exercise

Prove that there are infinitely many prime numbers. (Discovered by Euclid).

Importance of 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.

40
 Proofs

 Agenda

Proofs: General Techniques

 Direct Proof

 Indirect Proof

 Proof by Contradiction

 Proof Nuts and Bolts

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.

For example, consider the proposition:

If k is any integer such that k  1 (mod 3),

then k 3  1 (mod 9).

Let’s prove this fact:

 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

1. k 1(mod 3)

 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

1. k 1(mod 3)

2. n k-1 = 3n

41
 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

1. k 1(mod 3)

2. n k-1 = 3n

3. n k = 3n + 1

 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

1. k 1(mod 3)

2. n k-1 = 3n

3. n k = 3n + 1

4. n k 3 = (3n + 1)3

 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

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

PROVE: kZ k 1(mod 3) → k 31(mod 9)

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

6. n k 3-1 = 27n 3 + 27n 2 + 9n

 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

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

6. n k 3-1 = 27n 3 + 27n 2 + 9n

7. n k 3-1 = (3n 3 + 3n 2 + n)·9

 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

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

6. n k 3-1 = 27n 3 + 27n 2 + 9n

7. n k 3-1 = (3n 3 + 3n 2 + n)·9

8. m k 3-1 = m·9

43
 Proofs
Example

PROVE: kZ k 1(mod 3) → k 31(mod 9)

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

6. n k 3-1 = 27n 3 + 27n 2 + 9n

7. n k 3-1 = (3n 3 + 3n 2 + n)·9

8. m k 3-1 = m·9

9. k 31(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”.

Three basic steps in a direct proof:

 Direct Proofs

1) Deconstruct Axioms

Take the hypothesis and turn it into a usable form. Usually this amounts to just applying the
definition.

EG: k 1(mod 3) really means 3|(k-1) which actually means n k-1 = 3n

 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.

EG. k 31(mod 9) is readily gotten from

m k 3-1 = m·9 since the latter is the definition of the former.

 Proofs
Indirect

In addition to direct proofs, there are two other standard methods for proving

k P(k) → Q(k)

1. Indirect Proof

For any k assume: Q(k)

and derive: P(k)

Uses the contrapositive logical equivalence: P →Q  Q → P

 Proofs
Reductio Ad Absurdum

2. Proof by Contradiction (Reductio Ad Absurdum)

For any k assume: P(k)  Q(k)

and derive: P(k)  Q(k)

Uses the logical equivalence:

P →Q  P  Q  P  Q  P  Q

 (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

PROVE: The square of an even number is even. (Ex. 1.16.b)

 Indirect Proof
Example

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

 Indirect Proof
Example

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

2. So k 2 is odd.

 Indirect Proof
Example

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

2. So k 2 is odd.

3. n k 2 = 2n + 1

 Indirect Proof
Example

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

2. So k 2 is odd.

3. n k 2 = 2n + 1

4. n k 2 - 1 = 2n

46
 Indirect Proof
Example

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

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

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

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

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

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

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

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

PROVE: The square of an even number is even.

1. Suppose k 2 is not even.

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)

1. Suppose k 2 is not even.

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

10. In both cases k is odd

Indirect Proof

PROVE: The square of an even number is even. (Ex. 1.16.b)

1. Suppose k 2 is not even.

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

10. In both cases k is odd

11. So k is not even

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

Q = { p/q | p,q are integers with q  0 }

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.

Therefore [y must be rational] [implies P ]. This contradicts the hypotheses so the


assumption that the claim was false was incorrect and the claim must be true. •

Proofs
Disrefutation

Disproving claims is often much easier than proving them.

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

Disprove: The product of irrational numbers is irrational.

50
Recurrence Relations

A recurrence relation is the recursive part of a recursive definition of either a number sequence
or integer function.

Recursively Defined Sequences

EG: Recall the Fibonacci sequence:

{fn } = 0,1,1,2,3,5,8,13,21,34,55,…

Recursive definition for {fn }:

INITIALIZE: f0 = 0, f1 = 1

RECURSE: fn = fn-1+fn-2 for n > 1.

The recurrence relation is the recursive part

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.

Q: Is there another solution to the Fibonacci recurrence relation?

Recursively Defined Sequences

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,…

Q: How many solutions are there to the Fibonacci recursion relation?

Recursively Defined Sequences

A: Infinitely many solutions as each pair of integer initial conditions (a,b) generates a unique
solution.

Recurrence Relations for Counting

Often it is very hard to come up with a closed formula for counting a particular set, but coming
up with recurrence relation easier.

EG: Geometric example of counting the number of points of intersection of n lines.

Q: Find a recurrence relation for the number of bit strings of length n which contain the string
00.

51
Recurrence Relations for Counting

A: an= #(length n bit strings containing 00):

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

Solution: an = 2an-1 + 2n-3 - an-3

Q: What are the initial conditions:

Recurrence Relations for Counting

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.

a0 = a1 = 0 (strings to short to contain 00)

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.

Financial Recursion Relation

Most savings plans satisfy certain recursion relations.

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.

Financial Recursion Relation

A: Pn = (1+r)·Pn-1 +10

where r = 1 + 6%/12 = 1.005

Partition Function

A partition of a set is a way of grouping all the elements disjointly.

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} }

The partition function pn counts the number of partitions of {1,2,…,n}. Thus p3 = 5.

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:

0: n is all by itself  (e.g. {{1,2},{3}})

1: n has 1 friend (e.g. {{1},{2,3}})

2: n has 2 friends (e.g. {{1,2,3}})

n-1: n has n-1 friends on its team.

By the sum rule, we need to count the number of partitions of each kind, and then add together.

Partition Function

Consider the k’ th case:

k: n has k friends

There are C (n-1,k) ways of choosing fellow members of n’s team.

Furthermore, there are pn-k-1 ways of partitioning the rest of the n elements. Using the product and
sum rules we get:

Solving Recurrence Relations

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

Recursion + Lookup Table = Dynamic Programming

Consider a recurrence relation of the form:

an = f (a0,a1,…,an-2,an-1)

Then can always solve the recurrence relation for first n values by using following pseudocode:

integer-array a(integers n, a0)

table0 = a0

for(i = 1 to n)

tablei = f(table0,table1,…,tablei-1)

return table

Dynamic Program for String: Example

Solve an = 2an-1 + 2n-3 - an-3 up to n=7.

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

Dynamic Program for String Example

Solve an = 2an-1 + 2n-3 - an-3 up to n=7:

Dynamic Program for String Example

Solve an = 2an-1 + 2n-3 - an-3 up to n=7:

54
Dynamic Program for String Example

Solve an = 2an-1 + 2n-3 - an-3 up to n=7:

Dynamic Program for String Example

Solve an = 2an-1 + 2n-3 - an-3 up to n=7:

Dynamic Program for String Example

Solve an = 2an-1 + 2n-3 - an-3 up to n=7:

Dynamic Program for String Example

Solve an = 2an-1 + 2n-3 - an-3 up to n=7:

Dynamic Program for String Example

Solve up to n=6

Pseudocode becomes:

integer-array p(integer n)

table0 = 1 //unique partition of empty set

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.

Begin by showing how to solve Fibonacci:

Solving Fibonacci

Recipe solution has 3 basic steps:

1) Assume solution of the form an = r n

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.

3) Use initial conditions to find A,B and obtain specific solution.

 Solving Fibonacci

1) Assume exponential solution of the form an = r n :

Plug this into an = an-1 + an-2 : r n = r n-1 + r n-2

Notice that all three terms have a common r n-2 factor, so divide this out:

r n /r n-2 = (r n-1+r n-2 )/r n-2 ➔ r 2 = r + 1

This equation is called the characteristic equation of the recurrence relation.

 Solving Fibonacci

2) Find all possible r’s that solve characteristic r 2 = r + 1

Call these r1 and r2.1 General solution is an = Ar1n +Br2n where A,B are constants.

Quadratic formula2 gives:

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

3) Use initial conditions a0 = 0, a1 = 1 to find A,B and obtain specific solution.

0=a0 = A [(1+5)/2]0 +B [(1-5)/2]0 = A +B

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

First equation give B = -A. Plug into 2nd:

1 = 0 +2A5/2 so A = 1/5, B = -1/5

Linear Recurrences with Constant Coefficients

Q: Which of the following are linear with constant coefficients?

1. an = 2an-1

2. an = 2an-1 + 2n-3 - an-3

3. an = an-12

4. Partition function:

Linear Recurrences with Constant Coefficients

1. an = 2an-1: YES

2. an = 2an-1 + 2n-3 - an-3: YES

3. an = an-12: NO. Squaring is not a linear operation. Similarly an = an-1an-2 and


an = cos(an-2) are non-linear.

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.

Homogeneous Linear Recurrences

To solve such recurrences we must first know how to solve an easier type of recurrence relation:

DEF: A linear recurrence relation is said to be homogeneous if it is a linear combination of the


previous terms of the recurrence without an additional function of n.

Q: Which of the following are homogeneous?

1. an = 2an-1

2. an = 2an-1 + 2n-3 - an-3

3. Partition function:

57
Linear Recurrences with Constant Coefficients

1. an = 2an-1: YES

2. an = 2an-1 + 2n-3 - an-3: No. There’s an extra term f (n) = 2n-3

3. Partition function:

YES. No terms appear not involving the previous pi

Homogeneous Linear Recurrences with Const. Coeff.’s

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).

Complication: Repeating Roots

EG: Solve an = 2an-1-an-2 , a0 = 1, a1 = 2

Find characteristic equation by plugging in an = r n:

r 2 - 2r +1 = 0

Since r 2 - 2r +1 = (r -1)2 the root r = 1 repeats.

If we tried to solve by using general solution

an = Ar1n+Br2n = A1n+B1n = A+B

which forces an to be a constant function (→).

SOLUTION: Multiply second solution by n so general solution looks like:

an = Ar1n+Bnr1n

 Complication: Repeating Roots

58
Solve an = 2an-1-an-2, a0 = 1, a1 = 2

General solution: an = A1n+Bn1n = A+Bn

Plug into initial conditions

1 = a0 = A+B·0·10= A

2 = a0 = A·11+B·1·11= A+B

Plugging first equation A = 1 into second:

2 = 1+B implies B = 1.

Final answer: an = 1+n

The Nonhomogeneous Case

Consider the Tower of Hanoi recurrence (see Rosen p. 311-313) an = 2an-1+1.

Could solve using telescoping. Instead let’s solve it methodically. Rewrite:

an - 2an-1 = 1

1) Solve with the RHS set to 0, i.e. solve the homogeneous case.

2) Add a particular solution to get general solution. I.e. use rule:

The Nonhomogeneous Case

an - 2an-1 = 1

1) Solve with the RHS set to 0, i.e. solve

an - 2an-1 = 0

Characteristic equation: r - 2 = 0

so unique root is r = 2. General solution to homogeneous equation is

an = A·2n

The Nonhomogeneous Case

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.

Plug into the original recursion:

1 = bn – 2bn-1 = C – 2C = -C. Therefore C = -1.

General solution: an = A·2n -1.

The Nonhomogeneous Case

Finally, use initial conditions to get closed solution. In the case of the Towers of Hanoi
recursion, initial condition is:

a1 = 1

Using general solution an = A·2n -1 we get:

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

1) Rewrite as an - 2an-1 + an-3 = 2n-3 and solve homogeneous part:

Characteristic equation: r 3 - 2r +1 = 0.

Guess root r = 1 as integer roots divide.

r = 1 works, so divide out by (r -1) to get

r 3 - 2r +1 = (r -1)(r 2 +r -1).

 More Complicated

r 3 - 2r +1 = (r -1)(r 2 +r -1).

Quadratic formula on r 2 +r -1:

r = (-1  5)/2

So r1 = 1, r2 = (-1+5)/2, r3 = (-1-5)/2

General homogeneous solution:

60
an = A + B [(-1+5)/2]n +C [(-1-5)/2]n

2) Nonhomogeneous particular solution to an - 2an-1 + an-3 = 2n-3

Guess the form bn = k 2n. Plug guess in:

k 2n - 2k 2n-1 + k 2n-3 = 2n-3

Simplifies to: k =1.

So particular solution is bn = 2n

Final answer:

an=A + B [(-1+5)/2]n + C [(-1-5)/2]n + 2n

Exercise

Solve the following recurrence relation in terms of a1 assuming n is odd:

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?

Crazy Bagel Example

A: Same approach as before

Let xi = no. of bagels bought of type i.

Let i = 1 represents garlic and i = 2 onion.

Interested in counting the set

{x1+x2+…+x17 = 13 | x1  3 or x2  3}

Inclusion-Exclusion principle gives:

|{RHS=13 with x1  3 }|+|{RHS=13 with x2  3}|

-|{RHS=13 with x1  3 and x2  3}|

61
=|{RHS=10}| + |{RHS=10}|}| - |{RHS=7}|

=C (16+10,10)+C (16+10,10)-C (16+7,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

Q: How many numbers between 1 and 1000 are divisible by 3, 5, or 7.

 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 :

Total = 1000/3 + 1000/5 + 1000/7 - 1000/15 - 1000/21 - 1000/35


+ 1000/105

= 333 + 200 + 142 - 66 - 47 - 28 + 9

= 543

 Inclusion-Exclusion-Inclusion

Using induction, could prove:

THM: General Inclusion-Exclusion Principle:

union =

all terms

- all pairs

+ all triples

62

+/- total intersection

 Counting Pigeon Feedings

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?

Q: What are we counting?

 Counting Pigeon Feedings

A: Functions from crumbs to pigeons, so the answer is 36 = 729

Next, insist that every pigeon gets fed:

Q What sort of function are we counting now?

 Counting Onto Functions

A: Onto functions from crumbs to pigeons.

We calculate this number using generalized Inclusion-Exclusion.

|{onto functions}| = |{arbitrary}|-|{non-onto}|

A function is non-onto if it misses some element in the codomain. So consider following sets for
each pigeon i :

Ai = {functions which miss pigeon no. i }

|{non-onto}|=|A1A2A3|=

|A1|+|A2|+|A3|-|A1A2|-|A1A3|-|A2A3|

(don’t need |A1A2A3| term because impossible)

Counting Onto Functions

By symmetry, |A1|=|A2|=|A3| as no pigeon is special. Also, A1A2 is the set of functions which
miss both 1 and 2. Again, by symmetry |A1A2|=|A1A3|=|A1A3|. So:

|{non-onto}| = 3|A1| - 3|A1A2|

Finally, A1 is just the set of functions into {2,3} while A1A2 is the set of functions into {3} so:

63
|{non-onto}| = 3·26 - 3·16

Taking the complement:

|{onto functions}| = 36 - 3·26 + 3·16 = 540

 Counting Onto Functions


General Formula

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:

nm - C (n,1)·(n -1)m + C (n,2)·(n -2)m+…

+(-1)iC (n,i )·(n-i )m +…+ (-1)n-1C (n,n-1)·1m

Proof.

An Evil Witch Party

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.

Q: What is the probability that everyone dies?

 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.

So the answer to the witch problem is:

|{ derangements of {1,2,3,4} }| / |{permutations}|

Counting Derangements

Define: Ai = {permutations which bring i to i }

Inclusion-Exclusion and symmetry imply:

|{witch→poison derangements}|

= |{4-perm’s}|-C (4,1)|A1|+C (4,2)|A1A2|

64
-C (4,3)|A1A2A3|+C (4,4)|A1A2A3A4|

= 4!-C (4,1)3!+C (4,2)2!-C (4,3)1!+C (4,4)0!

= 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

THM: The number of derangements of a set with n elements is given by:

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

You might also like