Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Logic, Sets and Functions - Elements of Discrete Mathematics | MAT 2345, Assignments of Discrete Mathematics

Material Type: Assignment; Professor: Cleave; Class: Elements of Discrete Mathematics; Subject: Mathematics; University: Eastern Illinois University; Term: Fall 2007;

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-15y
koofers-user-15y 🇺🇸

10 documents

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Mat 2345 Discrete Math
Chapter One
Logic, Sets, & Functions
Nancy Van Cleave
Fall 2007
1
General Guidelines
ISyllabus
ISchedule (note exam dates)
IHomework & Programs
IAcademic Integrity Guidelines
ICourse Web Site
2
Mat2345 Course Overview
An introduction to the mathematical foundations
needed by computer scientists.
A survey of discrete sturctures and methods
Ilogic
Isets
Ifunctions
Ialgorithms developing and analyzing
Iinduction proofs
Irecursion relations
Irelations
IBoolean algebra, logic gates, circuits
Imodeling computation Finite State and Turing
Machines
3
Course Themes
IMathematical Reasoning induction
IMathematical Analysis comparison of algorithms /
functions
IDiscrete Structures abstract math structures,
the relationship between discrete and abstract
structures
IAlgorithmic Thinking algorithmic paradigms
IApplications and Modeling can we predict behavior?
4
Student Responsibilities Week 1
IReading: Textbook, Sections 1.1 & 1.2
IHomework 1.1: 2a–d, 4a–e, 6a–e, 8a–d, 20a–c, 35 (show
work); Table of T/F combinations and simple
propositions due in class on Friday
IHomework 1.2: 4, 8a–b, 10a–b, 18, 30, 32 due in class
on Monday
IAttendance
5
Logic
IThe rules of logic are used to distinguish between valid
and invalid mathematical arguments.
ILogic rules have many applications in computer science.
They are used in:
Ithe design of computer circuits
Ithe construction of computer programs
Ithe verication of the correctness of programs
Ias the basis of some Articial Intelligence programming
languages.
Iand many other ways as well
6
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Logic, Sets and Functions - Elements of Discrete Mathematics | MAT 2345 and more Assignments Discrete Mathematics in PDF only on Docsity!

Mat 2345 ó Discrete Math

Chapter One

Logic, Sets, & Functions

Nancy Van Cleave

Fall 2007

1

General Guidelines

I (^) Syllabus

I Schedule (note exam dates)

I (^) Homework & Programs

I (^) Academic Integrity Guidelines

I Course Web Site

2

Mat2345 Course Overview

An introduction to the mathematical foundations needed by computer scientists. A survey of discrete sturctures and methods I (^) logic I (^) sets I (^) functions I (^) algorithms ñ developing and analyzing I (^) induction proofs I (^) recursion relations I (^) relations I (^) Boolean algebra, logic gates, circuits I (^) modeling computation ñ Finite State and Turing Machines

3

Course Themes

I (^) Mathematical Reasoning ñ induction

I (^) Mathematical Analysis ñ comparison of algorithms / functions

I (^) Discrete Structures ñ abstract math structures, the relationship between discrete and abstract structures

I (^) Algorithmic Thinking ñ algorithmic paradigms

I (^) Applications and Modeling ñ can we predict behavior?

4

Student Responsibilities ó Week 1

I (^) Reading : Textbook, Sections 1.1 & 1.

I (^) Homework 1.1 : 2añd, 4añe, 6añe, 8añd, 20añc, 35 (show

work); Table of T/F combinations and simple

propositions ó due in class on Friday

I (^) Homework 1.2 : 4, 8añb, 10añb, 18, 30, 32 ó due in class on Monday

I (^) Attendance

Logic

I (^) The rules of logic are used to distinguish between valid and invalid mathematical arguments.

I (^) Logic rules have many applications in computer science. They are used in: I (^) the design of computer circuits I (^) the construction of computer programs I (^) the verication of the correctness of programs I (^) as the basis of some Articial Intelligence programming languages. I (^) and many other ways as well

Propositions

I PROPOSITION : a statement that is either true or

false, but not both.

Examples (which are true ?):

I (^) The zip code for Charleston, IL is 61920. I (^) The Will Roger's Theater is on Monroe Street. I (^1) + 4 = 5 I (^1) + 3 = 5 I (^) The title of our course is Mathemagics.

Counterexamples : I (^) Where am I? I (^) Stop! I (^) x + 2 y = 4

7

I (^) Variables are generally used to represent propositions: p ; q ; r ; s ; : : :

I Tautology : a proposition which is always true.

I Contradiction : a proposition which is always false.

I Compound Proposition : a new proposition formed

from existing propositions using logical

operators (aka connectives ).

I Negation : let p be a propostion. The negation of p is

the proposition ì It is not the case that p ,î

denoted by : p.

8

Truth Tables

Truth Tables display the relationship between the truth

values of propositions.

The truth table for negation :

p : p

T F F T

When proposition p is true, its negation is false. When it is false, its negation is true.

The negation of ìToday is Mondayî is ìToday is not Mondayî or ìIt is not the case that today is Mondayî

9

Conjunction

Conjunction : the compound proposition p and q , or p ∧ q

which is true when both p and q are true

and false otherwise.

Let p = Today is Monday, and q = It is raining. What is the value of each of the following conjunctions?

p ∧ q

p ∧ : q

10

Disjunction

Disjunction : the compound proposition p or q , or p ∨ q

which is false when both p and q are false

and true otherwise.

p q p ∧ q p ∨ q

T T T T T F F T F T F T F F F F

Exclusive Or

Exclusive Or : p ⊕ q , the proposition that is true when

exactly one of p and q is true , and is false otherwise.

I ìFries or baked potato come with your mealî I (^) ìDo the dishes or go to your roomî

p q p ⊕ q

T T F T F T F T T F F F

Tricky Question

For pq , write each of the following:

Direct Statement :

Converse :

Inverse :

Contrapositive :

19

Alternate Conditional Forms

Common translations of pq If p , then q p is sufcient for q If p , q q is necessary for p p implies q All p 's are q 's p only if q q if p

These translations do not in any way depend upon the truth value of pq.

ì If you get home late, then you are grounded î ≡ You are grounded if you get home late. Getting home late is sufcient for you to get grounded. Getting grounded is necessary when you get home late. Getting home late implies that you are grounded. 20

Logical and Bit Operations

I bit ≡ binary digit : smallest unit of storage in

computer memory, has two possible values ó true (1)

and false (0).

I Boolean Variable : program unit of storage that

can contain one of two values ó either true or false ,

and can thus be represented by a bit.

I Bit Operations : correspond to logical connectives:

I Bit String : a sequence of zero or more bits. The

length of the string is the number of bits in it.

Bitwise OR , Bitwise AND , and Bitwise XOR can be

applied to bit strings.

21

An Exercise

0101 1101 0011 p 1110 1011 0110 q bitwise OR bitwise AND bitwise XOR

22

1.2 Propositional Equivalences

Contingency : a proposition which is neither a tautology

nor a contradiction.

p : p p ∨ : p p ∧ : p

tautology contradiction

T F T F F T T F

Logical Equivalence

Logically Equivalent : two compound propositions

which always have the same truth value (given the same truth assignments to any Boolean Variables).

p q p ∧ q p ∨ q :( p ∨ q ) : p : q : p ∧ : q

T T T T F F F F

T F F T F F T F F T F T F T F F

F F F F T T T T

On Worksheet Provided

Using a truth table, show that pq is logically equivalent to :[ p → (: q )]

Using a truth table, show that pq is logically equivalent to (: p ) → q

Using a truth table, show that p ∨ ( qr ) is logically equivalent to ( pq ) ∧ ( pr )

25

Write as a proposition:

If I go to Harry’s or go to the

country, I will not go shopping.

Begin by breaking the compound into separate propositions:

I H =

I C =

I S =

Then write as a compound proposition using H , C , and S :

26

Name that Term!

What is a proposition which

1. is always true?

2. is always false?

3. is neither 1. nor 2.?

27

I (^) Two propositions, p and q , are logically equivalent if pq is a tautology.

I (^) We write pq

I (^) Example: ( pq ) ∧ ( qp ) ⇔ pq

To show a proposition is not a tautology, use an abbreviated truth table and

I (^) try to nd a counter example or to disprove the assertion I (^) search for a case where the proposition is false

28

Proving Logical Equivalence

Prove these expressions are logically equivalent: ( pq ) ∧ ( qp ) ⇔ pq

When would they not be equivalent?

Case 1. left side false, right side true... Subcase a. pq is false Subcase b. qp is false

Case 2. left side true, right side false... Subcase a. p = T , q = F Subcase b. p = F , q = T There are no more possibilities, so the two propositions must be logically equivalent.

Note, Table 5 in section 1.2 ó these are important for simplifying propositions and proving logical equivalences.

The Porsche & The Tiger

A prisoner must make a choice between two doors: behind one is a beautiful red Porsche, and behind the other is a hungry tiger. Each door has a sign posted on it, but only one sign is true.

Door #1. IN THIS ROOM THERE IS A PORSCHE AND IN THE OTHER ROOM THERE IS A TIGER.

Door #2. IN ONE OF THESE ROOMS THERE IS A PORSCHE AND IN ONE OF THESE ROOMS THERE IS A TIGER.

With this information, the prisoner is able to choose the correct door... Which one is it?

Existential Quantication

I Existential quantification asserts a

proposition is true if and only if it is true for at least one value in the universe of discourse.

I The Existential quantification of P ( x ) is

the proposition that P ( x ) is true for some x in the Universe of Discourse I (^) Existential quantication is written as: ∃ x P ( x ) I (^) For example, let U = f 1 ; 2 ; 3 g. Then ∃ x P ( x ) ⇔ P ( 1 ) ∨ P ( 2 ) ∨ P ( 3 ).

I Unique Existential Quantification asserts

a proposition is true for one and only one xU , and is written ∃! x P ( x )

I Remember : a predicate is not a proposition until all

variables have been bound either by quantication or assignment of a value. 37

Equivalences Involving Negation

: ∀ x P ( x ) ⇔ ∃ x : P ( x ) ì P ( x ) is not true for all x î is logically equivalent to ì there is some x for which P ( x ) is not true î

: ∃ x P ( x ) ⇔ ∀ x : P ( x ) ì There is no x for which P ( x ) is true î is logically equivalent to ì P ( x ) is not true for every x”

I (^) Distributing a negation operator across a quantier changes a universal to an existential, and vice versa

I (^) If there are multiple quantiers, they are read from left to right

38

Examples

Let U = R, the real numbers. Then consider P ( x ; y ) : xy = 0 Which of the following are TRUE? I (^) ∀ xy P ( x ; y )

I (^) ∀ xy P ( x ; y )

I (^) ∃ xy P ( x ; y )

I (^) ∃ xy P ( x ; y )

Suppose P ( x ; y ) : xy = 1... now which are TRUE?

39

Conversions

Let U = f 1 ; 2 ; 3 g. Find an expression equivalent to: ∀ xy P ( x ; y ) where the variables are bound by substitution instead of quantication. We can expand from the inside out, or the ouside in... Outside in, we get: ∃ y P ( 1 ; y ) ∧ ∃ y P ( 2 ; y ) ∧ ∃ y P ( 3 ; y ) ⇔ [ P ( 1 ; 1 ) ∨ P ( 1 ; 2 ) ∨ P ( 1 ; 3 ) ] ∧ [ P ( 2 ; 1 ) ∨ P ( 2 ; 2 ) ∨ P ( 2 ; 3 ) ] ∧ [ P ( 3 ; 1 ) ∨ P ( 3 ; 2 ) ∨ P ( 3 ; 3 ) ]

40

English to symbolsóI

Let U = f all EIU students g, and F ( x ) : x speaks French uently C ( x ) : x knows C++

I (^) Someone can speak French and knows C++ ∃ x ( F ( x ) ∧ C ( x ))

I (^) Someone speaks French, but doesn't know C++

I (^) Everyone can either speak French or knows C++

I (^) No one speaks French or knows C++

I (^) If a student knows C++, they can speak French

English to SymbolsóII Let U = f eegles, snurds, thingamabobs g, and F ( x ) : x is a eegle S ( x ) : x is a snurd T ( x ) : x is a thingamabob I (^) Everything is a eegle ∀ x F ( x ) ⇔ :∃ x : F ( x )

I (^) Nothing is a snurd

I (^) All eegles are snurds

I (^) Some eegles are thingamabobs

I No snurd is a thingamabob

I (^) If any eegle is a snurd then it's also a thingamabob

1.4 Sets

I Set : a collection or group of objects, elements , or

members

I Contain : a set is said to contain its elements

I Universal Set, U : there must be an underlying

universal set, U , either specically stated or understood

43

Notation used to specify sets

I list the elements between braces ; listing an object more than once does not change the setóordering means nothing. S = f a ; b ; c ; d g = f b ; c ; a ; d ; d g

I (^) specify by predicate ; here, S contains all elements from U which make the predicate P TRUE S = f x j P ( x ) g

I (^) brace notation with ellipses ; here, the negative integers: S = f: : : ; 3 ; 2 ; 1 g

44

Common Universal Sets

I (^) R ó Real Numbers

I (^) N ó Natural or Counting Numbers: f 0 ; 1 ; 2 ; 3 ; : : : g

I (^) Z ó Integers: f: : : ; 3 ; 2 ; 1 ; 0 ; 1 ; 2 ; 3 ; : : : g

I (^) Z+^ ó Positive Integers

Notation I (^) xS ó x is a member of S , or X is an element of S I (^) x ∈= S ó x is not an element of S

45

Subsets

I Subset : Let A and B be sets. Then

AB ⇔ ∀ x j xAxB j

I Empty, void, or Null Set : ∅ is the set with no

members I (^) the assertion x ∈ ∅ is always FALSE, thus

I (^) ∀ x j x ∈ ∅ → xB j is always (vacuously) TRUE, therefore

I (^) ∅ is a subset of every set

I (^) Note : a set B is always a subset of itself

I Proper subset : A ⊂ B if A ⊆ B , but A 6 = B

46

Power Set

I Power Set : P( A ) is the set of all possible subsets of

the set A

I (^) If A = f a ; b g, then P( A ) = f∅; f a g; f b g; f a ; b gg

I (^) What is the power set of the set B = f 0 ; 1 ; 2 g?

I How many elements would P(f a ; b ; c ; d g) have?

Cardinality

I Cardinality : j A j is the number of distinct elements

in A

I (^) If the cardinality is a natural number (in N), then the set is called nite ; otherwise, it's called innite

I (^) Example : Let A = f a ; b g I (^) jf a ; b gj = 2 I (^) jP( A )j = jP(f a ; b g)j = 4 I (^) A is nite, and so is P( A )

I (^) Note : j A j = n → jP( A )j = 2 n I (^) Note : N is innite since jNj is not a natural number; it is called a transnite cardinal number I (^) Note : Sets can be both members and subsets of other sets

Examples

U = f 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 g

A = f 1 ; 2 ; 3 ; 4 ; 5 g and B = f 4 ; 5 ; 6 ; 7 ; 8 g

I (^) AB = f 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 g

I (^) AB = f 4 ; 5 g

I (^) A = f 0 ; 6 ; 7 ; 8 ; 9 ; 10 g

I (^) B = f 0 ; 1 ; 2 ; 3 ; 9 ; 10 g

I (^) A B = f 1 ; 2 ; 3 g

I (^) B A = f 6 ; 7 ; 8 g

I (^) AB = f 1 ; 2 ; 3 ; 6 ; 7 ; 8 g

55

Venn Diagrams

Venn Diagrams are a useful geometric visualization tool for 3 or fewer sets.

I (^) The Universal set U is a rectangular box

I (^) Each set is represented by a circle and its interior

I (^) All possible combinations of the sets must be represented

I (^) Shade the appropriate region to represent the given set operation

56

U

A B

For 2 sets

U

A B

C

For 3 sets

57

Set Identities

Set identities correspond to the logical equivalences.

Example The complement of the union is the intersection of the complements: AB = AB

To prove this statement, we need to show: ∀ x [ xABxAB ]

To show two sets are equal , we show for all x that x is a member of one set if and only if it is a member of the other.

58

Universal Instantiation

We now apply an important rule of inference (dened later) called

Universal Instantiation

In a proof, we can eliminate the universal quantier which binds a variable if we do not assume anything about the variable other than it is an arbitrary member of the Uni- verse. We can then treat the resulting predicate as a proposition.

We say, ìLet x be arbitrary.î Then we can treat the predicates as propositions.

Assertion Reason xABx ∈= [ AB ] Defn of complement x ∈= AB ⇔ :[ xAB ] Defn of ∈=

⇔ :[ xAxB ] Defn of union ⇔ : xA ∧ : xB DeMorgan's Laws ⇔ x ∈= Ax ∈= B Defn of ∈= ⇔ xAxB Defn of complement

xAB Defn of intersection

Hence, xABxAB is a tautology since I (^) x was arbitrary I (^) we have used only logically equivalent assertions and denitions

Universal Generalization

We can apply another rule of inference

Universal Generalization

We can apply a universal quantier to bind a variable if we have shown the predicate to be true for all values of the variable in the Universe

and claim the assertion is true for all x , i.e.,

x [ xABxAB ]

Q.E.D. ó an abbreviation for the Latin phrase “Quod Erat Demonstrandum” ñ ìwhich was to be demonstratedî ñ used to signal the end of a proof.

61

Alternative Identity

Note: as an alternative which might be easier in some cases, use the identity: A = B ⇔ [ AB and BA ]

Example Show A ∩ ( B A ) = The empty set is a subset of every set. Hence, A ∩ ( B A ) ⊇

Therefore, it sufces to show A ∩ ( B A ) ⊆ or ∀ x [ xA ∩ ( B A ) → x ∈ ]

So, as before, we say ìlet x be arbitraryî

62

Now we need to show xA ∩ ( B A ) → x ∈ is a tautology. But the consequent is always false. Therefore, the antecedent had better always be false also.

63

We procede by applying the denitions:

Assertion Reason xA ∩ ( B A ) ⇔ xAx ∈ ( B A ) Defn of intersection ⇔ xA ∧ ( xBx ∈= A ) Defn of difference ⇔ ( xAx ∈= A ) ∧ xB Properties of AND ⇔ 0 ∧ xB Table 6 in textbook ⇔ 0 Domination

Hence, because P ∧ : P is always false, the implication is a tautology. The result follows by Universal Generalization. Q.E.D.

64

Indexed Collections

Let A 1 ; A 2 ; : : : ; An be an indexed collection of sets. Union and intersection are associative (because AND nad OR are), we have: (^) ⋃ n i = 1 Ai^ =^ A^1 ∪^ A^2 ∪^   ^ ∪^ An and ⋂ n i = 1 Ai^ =^ A 1 ∩^ A 2 ∩^   ^ ∩^ An

Examples Let Ai = [ i ; 1 ); 1  i < 1 ⋃ n i = 1 Ai^ =^ [1;^1 ) ⋂ n i = 1 Ai^ =^ [ n ;^1 )

1.6 Functions

I Function : Let A and B be sets. Then a function

(mapping, map) f from A to B , denoted f : AB , is a subset of A  B such that ∀ x [ xA → ∃ y [ yB ∧ < x ; y > ∈ f ]]

and

[ < x ; y 1 > ∈ f ∧ < x ; y 2 > ∈ f ] → y 1 = y 2

I (^) Note: f associates with each x in A one and only one y in B.

I (^) A is called the domain of f

I (^) B is called the codomain of f

Example IV

X

Y

A B

a

b

c

d

h

W

V

  1. Is this an injection?
  2. Is this a surjection?
  3. Is this a bijection?

73

Cardinality

I (^) Note : whenever there is a bijection from A to B , the two sets must have the same number of elements or the same cardinality

I That will become our denition, especially for innite sets.

Let A = B = R, the reals Determine which are injections, surjections, bijections: I (^) f ( x ) = x I (^) f ( x ) = x^2 I (^) f ( x ) = x^3 I (^) f ( x ) = j x j

74

Let E be the set of even nonnegative integers, f 0 ; 2 ; 4 ; 6 ; : : : g

Then there is a bijection f from N to E , the even nonnegative integers, dened by: f ( x ) = 2 x

Hence, the set of even nonnegative integers has the same cardinality as the set of natural numbers...

OH, NO! IT CAN'T BE... E is only half as big!!

75

Inverse Functions

I Inverse Function : Let f be a bijection from A to

B. Then the inverse of f , denoted f ^1 , is the function from B to A dened as:

f ^1 ( y ) = x IFF f ( x ) = y

I (^) Note: no inverse exists unless f is a bijection.

76

Example Let f be dened by the diagram ñ

X Y

A (^) B a b c d

W

V

f

Then f ^1 is dened as ñ

X Y

A B a b c d

W

V

f

Inverse Applied to a Subset

I Inverse Function over Subsets : Let S be a

subset of B. Then f ^1 ( S ) = f x j f ( x ) ∈ S g

I (^) Example: Let f be the following function ñ

Y Z

X

A (^) B a b c d

f

f ^1 (f Z g) = f c ; d g

f ^1 (f X ; Y g) = f a ; b g

Composition

I Composition : Let f : B → C ; g : A → B. The

composition of f with g , denoted fg , is the function from A to C dened by fg ( x ) = f ( g ( x ))

I (^) Example:

X Y

A (^) B a b c d

W

V

g

H I

J

f C a b c d

H

I

J

A f g C

79

Another Example

Let f ( x ) = x^2 and g ( x ) = 2 x + 1

Then fg ( x ) = ( 2 x + 1 )^2 = 4 x^2 + 4 x + 1

And gf ( x ) = 2 x^2 + 1

80

Discussion

I (^) Suppose f : BC , g : AB , and fg is injective

I What can we say about f and g?

I (^) Using the denition of injective , we know that if a 6 = b , then f ( g ( a )) 6 = f ( g ( b )) f , since the composition is injective I (^) Since f is a function, it cannot be the case that g ( a ) = g ( b ), since f would have two different images for the same point. I (^) Hence, g ( a ) 6 = g ( b )

I (^) It follows that g must be an injection

I (^) However, f need not be an injection... how could you show this?

81

FLOOR and CEILING Functions

I Floor : The FLOOR function, denoted

f ( x ) = b x c or f ( x ) = FLOOR( x )

is the largest integer less than or equal to x.

I Ceiling : The CEILING function, denoted

f ( x ) = d x e or f ( x ) = CEILING( x )

is the smallest integer greater than or equal to x.

I (^) Examples: b 3 : 5 c = 3 ; d 3 : 5 e = 4

I (^) Note: The FLOOR function is equivalent to truncation for positive numbers

82

1.7 Sequences, Summations, and Cardinality of Innite Sets

I Sequence : A sequence is a function from a subset of

the natural numbers (usually of the form f 0 ; 1 ; 2 ; : : : g to a set S

I (^) The sets f 0 ; 1 ; 2 ; 3 ; : : : ; k g and f 1 ; 2 ; 3 ; : : : ; k g are called initial segments of N

I Notation: if f is a function from f 0 ; 1 ; 2 ; : : : g to S , we usually denote f ( i ) by ai and we write: f a 0 ; a 1 ; a 2 ; a 3 ; : : : g = f ai g ki = 0 = f ai g k 0 where k is the upper limit (usually 1 )

Sequence Examples

I (^) Using zeroñorigin indexing, if f ( i ) = (^) ( i +^11 ) , then the sequence

f = f 1 ; 21 ; 31 ; 41 ; : : : g = f a 0 ; a 1 ; a 2 ; a 3 ; : : : g

I (^) Using oneñorigin indexing, the sequence f becomes

f = f 21 ; 31 ; 41 ; : : : g = f a 1 ; a 2 ; a 3 ; : : : g

Note : with innite sets, proper subsets can have the same cardinality. This cannot happen with nite sets

Countability carries with it the implication that there is a listing of the elements of the set

Denition : j A j  j B j if there is an injection from A to B.

Theorem. If j A j  j B j and j B j  j A j, then j A j = j B j. This implies I (^) if there is an injection from A to B and I (^) if there is an injection from B to A

then I (^) there must be a bijection from A to B

91

I (^) This is difcult to prove, but is an example of demonstrating existence without construction.

I (^) It is often easier to build the injections and then conclude the bijection exists.

I (^) Example I. Theorem : If A is a subset of B , then j A j  j B j. Proof: the function f ( x ) = x is an injection from A to B

I (^) Example II. jf 0 ; 2 ; 5 gj  ℵ 0 The injection f f 0 ; 2 ; 5 g → N dened by f ( x ) = x is:

92

Some Countably Innite Sets

I (^) The set of even integers E is countably innite... Note that E is a proper subset of N

Proof: Let f ( x ) = 2 x. Then f is a bijection from N to E

I (^) Z+, the set of positive integers is countably innite

I (^) The set of positive rational numbers, Q+, is countably innite

93

Proof: Q+^ is countably innite

I (^) Z+^ is a subset of Q+, so jZ+j = ℵ 0  jQ+j

I (^) Next, we must show that jQ+j  ℵ 0.

I (^) To do this, we show that the positive rational numbers with repetitions, QR, is countably innite.

I (^) Then, since Q+^ is a subset of QR, it follows that jQ+j  ℵ 0 , and hence jQ+j = ℵ 0

94

x y 1 2 3 4 5 6 7 1 2 3 4 5

2 1 3 1 4 1 5 1 6 1 7 1 1 1 2 2 3 2 4 2 5 2 6 2 7 2 1 2 2 3 3 3 4 3 5 3 6 7 3 1 3 2 4 3 4 4 4 5 4 6 4 7 4 1 4 2 5 3 5 4 5

5 5 6 5 7 5 1 5

3

6

I (^) The position on the path (listing) indicates the image of the bijection function f from N to QR: f ( 0 ) = 11 , f ( 1 ) = 12 , f ( 2 ) = 21 , f ( 3 ) = 31 , etc.

I (^) Every rational number appears on the list at least once, some many times (repetitions).

I (^) Hence, jNj = jQRj = ℵ 0

More Examples of Countably Innite

I (^) The set of all rational numbers, Q, positive and negative, is countably innite.

I (^) The set of (nite length) strings S over a nite alphabet A is countably innite. To show this, we assume that: I (^) A is nonñvoid I (^) There is an ìalphabeticalî ordering of the symbols in A

Proof: List the strings in lexicographic order ó I (^) all the strings of zero length I (^) then all the strings of length 1 in alphabetical order, I (^) then all the strings of length 2 in alphabetical order, I (^) etc. This implies a bijection from N to the list of strings and hence it is a countably innite set

String Example

Let A = f a ; b ; c g

Then the lexicographic ordering of A is:

f; a ; b ; c ; aa ; ab ; ac ; ba ; bb ; bc ; ca ; cb ; cc ; aaa ; aab ; aac ; aba ; : : : g

= f f ( 0 ); f ( 1 ); f ( 2 ); f ( 3 ); f ( 4 ); : : : g

97

The Set of All C++ Programs is countable Proof : Let S be the set of legitimate characters which can appear in a C++ program. I (^) A C++ compiler will determine if an input program is a syntactically correct C++ program (the program doesn't have to do anything useful).

I (^) Use the lexicographic ordering of S and feed the strings into the compiler.

I (^) If the compiler says YES, this is a syntactically correct C++ program, we add the program to the list.

I (^) Else, we move on to the next string In this way we construct a list or an implied bijection from N to the set of C++ programs.

Hence, the set of C++ programs is countable. 98

Cantor Diagonalization

An important technique used to construct an object which is not a member of a countable set of objets with (possibly) innite descriptions

Theorem : The set of real numbers between 0 and 1 is uncountable.

Proof : We assume that it is countable and derive a contradiction.

If the set is countable, we can list all the real numbers (i.e., there is a bijection from a subset of N to the set).

99

We show that no matter what list you produce we can construct a real number between 0 and 1 which is not in the list.

Hence, the number we constructed cannot exist in the list and therefore the set is not countable.

It's actually much bigger than countable ó it's said to have

the cardinality of the continuum , c

100

Represent each real number in the list using its decimal expansion

E.g., 31 = 0 : 3333333 : : : : : :

1

2 =^0 :^5000000 : : : : : :

If there is more than one expansion for a number, it doesn't matter as long as our construction takes this into account.

The resulting list:

r 1 = 0 : d 11 d 12 d 13 d 14 d 15 d 16 : : : : : :

r 2 = 0 : d 21 d 22 d 23 d 24 d 25 d 26 : : : : : :

r 3 = 0 : d 31 d 32 d 33 d 34 d 35 d 36 : : : : : :

Now, construct the number x = 0 : x 1 x 2 x 3 x 4 x 5 x 6 x 7 : : : : : :

xi = 3 if dii 6 = 3

xi = 4 if dii = 3

Note: choosing 0 and 9 is not a good idea because of the nonñuniqueness of decimal expansions.

Then x is not equal to any number in the list.

Hence, no such list can exist, and thus the interval ( 0 ; 1 ) is uncountable.

Proving Asymptotic Domination

time

k

g(x)

f(x)

size of input

To prove fO ( g ), given f and g : I (^) Determine / choose some positive k

I (^) Determine / choose a positive C (may depend upon choice of k )

I Once k and C are chosen, the implication must be proven true 109

Three Important Complexity Classes

Bounds from above

Growth rates equivalent

Bounds from below

Big − Oh

Theta

Big − Omega

Omega Man 110

Complexity Classes

The sets O ( g ), o ( g ), Ω( g ), !( g ), and Θ( g ) are called

complexity classes.

O ( g ) is a set which contains all the functions which g

dominates.

f is O ( g ) means fO ( g )

We say f ∈ Ω( g ) if there are positive constants k and C such that F ( n )  Cg ( n ) whenever n > k

If fO ( g ) and f ∈ Ω( g ), then f ∈ Θ( g )

We use îlittle-ohî and îlittleñomegaî when we have strict inequality

111

Example

Let f ( n ) = 4 n + 5 and g ( n ) = n^2. We wish to show that fO ( g )

We need to nd k and C , and show the implication

n > k ; f ( n )  Cg ( n )

is true for the values we choose.

To nd k , we can set the functions equal, and solve for n :

4 n + 5 = n^2 0 = n^2 4 n 5 0 = ( n 5 )( n + 1 )

So, n = 5 or n = 1 : : : but n is the size of input and therefore cannot be negative. Thus, k must be at least 5.

112

If we choose K = 6, then C can be any positive number greater than or equal to 1.

All that is left is the proof that ∀ n > k ; f ( n )  Cg ( n ), which we shall revisit when we discuss induction proofs.

BigñOh Properties

I (^) f is O ( g ) IFF O ( f ) ⊆ O ( g )

I If fO ( g ) and gO ( f ), then O ( f ) = O ( g )

I (^) The set O ( g ) is closed under addition : If fO ( g ) and hO ( g ), then f + hO ( g )

I (^) O ( g ) is closed under multiplication by a scalar a ∈ R:

If fO ( g ) then afO ( g ) I.e., O ( g ) is a vector space

I (^) Also, as you would expect, If fO ( g ) and gO ( h ), then fO ( h )

In particular, O ( f ) ⊆ O ( g ) ⊆ O ( h )

115

Theorem

If f 1 ∈ O ( g 1 ) and f 2 ∈ O ( g 2 ), then:

  1. f 1 f 2 ∈ O ( g 1 g 2 )
  2. f 1 + f 2 ∈ O ( max f g 1 ; g 2 g)

116

Functional Values for Small n

log 2 n

n n n^2 2 n^ n! nn

117

Approximate Functional Values for Powers of n

log 2 nn n n^2 2 n^ n! nn 3.32 3.16 101 102 1024 3 : 63 ( 106 ) 1010 6.64 10 102 104 1 : 27 ( 1030 ) 9 : 3 ( 10157 ) 10200 9.97 31.62 103 106 1 : 07 ( 10301 ) 4 ( 102567 ) 103000 13.29 100 104 108 2 ( 103010 ) 2 : 9 ( 1035 ;^659 ) 1040 ;^000 16.61 316.2 105 1010 1030 ;^103 2 : 9 ( 10456 ;^573 ) 10500 ;^000 19.93 1000 106 1012 10301 ;^030 8 : 3 ( 105 ;^565 ;^708 1060 ;^000 ;^000 39.86 106 1012 1024 BIG LARGE HUGE

118

Important Complexity Classes

Theorem. The hierarchy of several familiar sequences in the sense that each sequence is BigñOh of any sequence to its right:

1 ; log 2 n ; : : : ; 4 √ n ; 3 √ n ; √ n ; n ; n log 2 n ; nn ; n^2 ; n^3 ; n^4 ; : : : ; 2 n^ ; n !; nn

Similarly, stated in set notation:

O ( c ) ⊆ O (log n ) ⊆ O ( n ) ⊆ O ( n log n ) ⊆ O ( n^2 ) ⊆ O ( nj^ ) ⊆ O ( cn^ ) ⊆ O ( n !)

where j > 2 and c > 1

Time Equivalencies

SECOND 1 100

MILLISECONDS 1,000 103

MICROSECONDS 1,000,000 106

NANOSECONDS 1,000,000,000 109