© by kenneth h. rosen, discrete mathematics & its applications, sifth edition, mc graw-hill,...

62
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Chapter 2: Basic Structures: Sets, Basic Structures: Sets, Functions, Sequences and Functions, Sequences and Sums Sums Sets Sets (Section 2.1) (Section 2.1) Set Operations Set Operations (Section 2.2) (Section 2.2) Functions Functions (Section 2.3) (Section 2.3) Sequences and Summations Sequences and Summations (Section 2.4) (Section 2.4)

Upload: ellen-little

Post on 27-Dec-2015

240 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007

Chapter 2:Chapter 2: Basic Structures: Sets, Basic Structures: Sets, Functions, Sequences and Functions, Sequences and SumsSums

Sets Sets (Section 2.1)(Section 2.1)

Set Operations Set Operations (Section 2.2)(Section 2.2)

FunctionsFunctions (Section 2.3)(Section 2.3)

Sequences and Summations Sequences and Summations (Section (Section 2.4)2.4)

Page 2: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

2

Sets (2.1)Sets (2.1)

A set is a collection or group of objects or A set is a collection or group of objects or elementselements or or membersmembers.. (Cantor 1895) (Cantor 1895)

A set is said to contain its elements.A set is said to contain its elements.

There must be an underlying universal set U, There must be an underlying universal set U, either specifically stated or understood.either specifically stated or understood.

Page 3: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

3

Sets (2.1) (cont.)Sets (2.1) (cont.)

Notation:Notation:

list the elements between braces:list the elements between braces:S = {a, b, c, d}={b, c, a, d, d}S = {a, b, c, d}={b, c, a, d, d}

(Note: listing an object more than once does not change (Note: listing an object more than once does not change the set. Ordering means nothing.)the set. Ordering means nothing.)

specification by predicates:specification by predicates:S= {x| P(x)},S= {x| P(x)},

S contains all the elements from U which make the S contains all the elements from U which make the predicate P true.predicate P true.

brace notation with ellipses:brace notation with ellipses:S = { . . . , -3, -2, -1},S = { . . . , -3, -2, -1},

the negative integers.the negative integers.

Page 4: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

4

Sets (2.1) (cont.)Sets (2.1) (cont.)

Common Universal SetsCommon Universal Sets

R = realsR = reals N = natural numbers = {0,1, 2, 3, . . . }, the N = natural numbers = {0,1, 2, 3, . . . }, the

countingcounting numbers numbers Z = all integers = {. . , -3, -2, -1, 0, 1, 2, 3, 4, . .}Z = all integers = {. . , -3, -2, -1, 0, 1, 2, 3, 4, . .} ZZ++ is the set of positive integers is the set of positive integers

Notation:Notation:x is a member of S or x is an element of S:x is a member of S or x is an element of S:

x x S. S.x is not an element of S:x is not an element of S:

x x S. S.

Page 5: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

5

Sets (2.1) (cont.)Sets (2.1) (cont.)

SubsetsSubsets

Definition:Definition: The set A is a The set A is a subsetsubset of the set B, denoted of the set B, denoted A A B, iff B, iff

x [x x [x A A x x B] B]

Definition:Definition: The The voidvoid set, the set, the nullnull set, the set, the emptyempty set, set, denoted denoted , is the set with no members., is the set with no members.

Note:Note: the assertion x the assertion x is is alwaysalways false. Hence false. Hencex [x x [x x x B] B]

is always true(vacuously). Therefore, is always true(vacuously). Therefore, is a subset of is a subset of every set.every set.

Note:Note: A set B is always a subset of itself. A set B is always a subset of itself.

Page 6: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

6

Sets (2.1) (cont.)Sets (2.1) (cont.)

Definition:Definition: If A If A B but A B but A B the we say A is a B the we say A is a properproper subset of B, denoted A subset of B, denoted A B (in some texts). B (in some texts).

Definition:Definition: The set of all subset of a set A, denoted The set of all subset of a set A, denoted P(A), is called the P(A), is called the power setpower set of A. of A.

Example:Example: If A = {a, b} then If A = {a, b} thenP(A) = {P(A) = {, {a}, {b}, {a,b}}, {a}, {b}, {a,b}}

Page 7: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

7

Sets (2.1) (cont.)Sets (2.1) (cont.)

Definition:Definition: The number of (distinct) elements in A, The number of (distinct) elements in A, denoted |A|, is called the denoted |A|, is called the cardinalitycardinality of A. of A.

If the cardinality is a natural number (in N), then If the cardinality is a natural number (in N), then the set is called the set is called finitefinite, else , else infiniteinfinite..

Example: Example: A = {a, b},A = {a, b},

|{a, b}| = 2,|{a, b}| = 2,

|P({a, b})| = 4.|P({a, b})| = 4.

A is finite and so is P(A).A is finite and so is P(A).

Useful Fact: |A|=n implies |P(A)| = 2Useful Fact: |A|=n implies |P(A)| = 2nn

Page 8: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

8

Sets (2.1) (cont.)Sets (2.1) (cont.)

N is infinite since |N| is not a natural number. It is called a N is infinite since |N| is not a natural number. It is called a transfinite cardinal numbertransfinite cardinal number..

Note:Note: Sets can be both Sets can be both membersmembers and and subsetssubsets of other sets. of other sets.

Example:Example:A = {A = {,{,{}}.}}.A has two elements and hence four subsets:A has two elements and hence four subsets:, {, {}, {{}, {{}}. {}}. {,{,{}}}}Note that Note that is both a member of A and a subset of A! is both a member of A and a subset of A!

Russell's paradox:Russell's paradox: Let S be the set of all sets which are not Let S be the set of all sets which are not members of themselves. Is S a member of itself?members of themselves. Is S a member of itself?

Another paradox:Another paradox: Henry is a barber who shaves all people Henry is a barber who shaves all people who do not shave themselves. Does Henry shave himself?who do not shave themselves. Does Henry shave himself?

Page 9: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

9

Sets (2.1) (cont.)Sets (2.1) (cont.)

Definition:Definition: The The Cartesian productCartesian product of A with B, denoted of A with B, denotedA x B, is the set of A x B, is the set of ordered pairsordered pairs {<a, b> | a {<a, b> | a A A b b B} B}

Notation: Notation:

Note: The Cartesian product of anything with Note: The Cartesian product of anything with is is . (why?). (why?)

Example:Example:

A = {a,b}, B = {1, 2, 3}A = {a,b}, B = {1, 2, 3}

AxB = {<a, 1>, <a, 2>, <a, 3>, <b, 1>, <b, 2>, <b, 3>}AxB = {<a, 1>, <a, 2>, <a, 3>, <b, 1>, <b, 2>, <b, 3>}

What is BxA? AxBxA?What is BxA? AxBxA?

If |A| = m and |B| = n, what is |AxB|?If |A| = m and |B| = n, what is |AxB|?

iin21i

n

1iAaa,...,a,aA

Page 10: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

10

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.) Propositional calculus and set theory are Propositional calculus and set theory are

both instances of an algebraic system called both instances of an algebraic system called aa

Boolean AlgebraBoolean Algebra..

The operators in set theory are defined in The operators in set theory are defined in terms of the corresponding operator in terms of the corresponding operator in propositional calculuspropositional calculus

As always there must be a universe U. All As always there must be a universe U. All sets are assumed to be subsets of Usets are assumed to be subsets of U

Page 11: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

11

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Definition:Definition:

Two sets A and B are equal, denoted A = B, Two sets A and B are equal, denoted A = B, iffiff

x [x x [x A A x x B]. B].

Note:Note: By a previous logical equivalence we have By a previous logical equivalence we have

A = B iff A = B iff x [(x x [(x A A x x B) B) (x (x B B x x A)] A)]

oror

A = B iff A A = B iff A B and B B and B A A

Page 12: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

12

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Definitions:Definitions:

The The unionunion of A and B, denoted A U B, is the set {x | x of A and B, denoted A U B, is the set {x | x A A x x B} B}

The The intersectionintersection of A and B, denoted A of A and B, denoted A B, is the set B, is the set

{x | x {x | x A A x x B} B}Note: If the intersection is void, A and B are said to be Note: If the intersection is void, A and B are said to be disjointdisjoint..

The The complementcomplement of A, denoted , is the set {x | of A, denoted , is the set {x | (x (x A)} A)}Note: Alternative notation is ANote: Alternative notation is Acc, and {x|x , and {x|x A}. A}.

The The differencedifference of A and B, or the of A and B, or the complementcomplement of B of B relativerelative to A, denoted to A, denoted A - B, is the set A A - B, is the set A

Note: The (absolute) complement of A is U - A.Note: The (absolute) complement of A is U - A.

The The symmetric differencesymmetric difference of A and B, denoted A of A and B, denoted A B, is the set B, is the set (A - B) U (B - A)(A - B) U (B - A)

A

B

Page 13: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

13

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Examples:Examples: U = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}U = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

A= {1, 2, 3, 4, 5}, A= {1, 2, 3, 4, 5}, B = {4, 5, 6, 7, 8}. ThenB = {4, 5, 6, 7, 8}. Then

AAB = {1, 2, 3, 4, 5, 6, 7, 8}B = {1, 2, 3, 4, 5, 6, 7, 8} A A B = {4, 5} B = {4, 5} = {0, 6, 7, 8, 9, 10}= {0, 6, 7, 8, 9, 10} = {0, 1, 2, 3, 9, 10}= {0, 1, 2, 3, 9, 10} A - B = {1, 2, 3}A - B = {1, 2, 3} B - A = {6, 7, 8}B - A = {6, 7, 8} AAB = {1, 2, 3, 6, 7, 8}B = {1, 2, 3, 6, 7, 8}

A

B

Page 14: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

14

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.) Venn DiagramsVenn Diagrams

A useful geometric visualization tool (for 3 or less sets)A useful geometric visualization tool (for 3 or less sets) The Universe U is the rectangular boxThe Universe U is the rectangular box Each set is represented by a circle and its interiorEach set is represented by a circle and its interior All possible combinations of the sets must be representedAll possible combinations of the sets must be represented

Shade the appropriate region to represent the given set Shade the appropriate region to represent the given set operation.operation.

U U

AA

BC

B

For 2 sets For 3 sets

Page 15: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

15

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Set IdentitiesSet Identities

Set identities correspond to the logical equivalences.Set identities correspond to the logical equivalences.

Example:Example:The complement of the union is the intersection of theThe complement of the union is the intersection of thecomplements:complements:

= = Proof: To show:Proof: To show:

x [x x [x x x ] ]To show two sets are equal we show for all x that x is 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 a member of one set if and only if it is a member of the other.the other.

A B

A B

BA

BA

Page 16: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

16

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

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

Universal InstantiationUniversal Instantiation

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

Page 17: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

17 We sayWe say

'Let x be arbitrary.''Let x be arbitrary.'

ThenThen we can treat the predicates as propositions: we can treat the predicates as propositions:

Page 18: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

18

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

HenceHencex x x x

is a tautology.is a tautology.

SinceSince

• • x was arbitraryx was arbitrary

• • we have used only logically equivalent assertions we have used only logically equivalent assertions and definitionsand definitions

BA A B

Page 19: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

19

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

we can apply another rule of inference calledwe can apply another rule of inference called

Universal GeneralizationUniversal Generalization

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

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

x [x x [x x x ] ]

Q. E. D. (Latin phrase “Quod Erat Demonstrandum”)Q. E. D. (Latin phrase “Quod Erat Demonstrandum”)

BA A B

Page 20: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

20

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Note: As an alternative which might be easier in some cases, Note: As an alternative which might be easier in some cases, use the identityuse the identity

A = B A = B [A [A B and B B and B A] A]

Example:Example:

Show A Show A (B - A) = (B - A) =

The void set is a subset of every set. Hence,The void set is a subset of every set. Hence,A (B - A)

Therefore, it suffices to showTherefore, it suffices to show

A A (B - A) (B - A) or or x [xx [xA A (B - A) (B - A) x x ]]

So as before we say 'let x be arbitrary’.So as before we say 'let x be arbitrary’.

Page 21: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

21

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Example (cont.)Example (cont.)

Show xShow xA A (B - A) (B - A) x x is a tautology.is a tautology.

But the consequent is always false.But the consequent is always false.

Therefore, the antecedent better always be false Therefore, the antecedent better always be false also.also.

Apply the definitions:Apply the definitions:

Page 22: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

22

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Example (cont.)Example (cont.)

Hence, because P Hence, because P P is always false, the P is always false, the implication is a tautology.implication is a tautology.

The result follows by Universal Generalization.The result follows by Universal Generalization.

Q. E. D.Q. E. D.

Page 23: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

23

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

Union and Intersection of Indexed CollectionsUnion and Intersection of Indexed Collections

Let ALet A11,A,A22 ,..., A ,..., Ann be an indexed collection of sets. be an indexed collection of sets. Union and intersection are associative (because Union and intersection are associative (because

'and' and 'or' are) we have:'and' and 'or' are) we have:

n21i

n

1i

n21i

n

1i

A...AAA

and

A...AAA

Page 24: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

24

Set Operations (2.2) (cont.)Set Operations (2.2) (cont.)

ExamplesExamples

Let Let

),n[A

),1[A

i1),,i[A

i

n

1i

i

n

1i

i

),n[A

),1[A

i1),,i[A

i

n

1i

i

n

1i

i

Page 25: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

25

Functions (2.3)Functions (2.3)

Definition:Definition:

Let A and B be sets. A function (mapping, Let A and B be sets. A function (mapping, map) f from A to B, denoted f :Amap) f from A to B, denoted f :AB, is a B, is a subset of A*B such thatsubset of A*B such that

x [x x [x A A y [y y [y B B < x, y > < x, y > f ]] f ]]

andand

[< x, y[< x, y11 > > f f < x, y < x, y22 > > f ] f ] y y11 = y = y22

Page 26: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

26

Functions (2.3) (cont.)Functions (2.3) (cont.)

Note:Note: f associates with each x in A one and only one y in f associates with each x in A one and only one y in B.B.

A is called the A is called the domaindomain and andB is called the B is called the codomaincodomain..

If f(x) = yIf f(x) = yy is called they is called the image image of x under f of x under fx is called a x is called a preimagepreimage of y of y

(note there may be more than one preimage of y but (note there may be more than one preimage of y but therethere

is only one image of x).is only one image of x).

The The rangerange of f is the set of all images of points in A under of f is the set of all images of points in A underf. We denote it by f(A).f. We denote it by f(A).

Page 27: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

27

Functions (2.3) (cont.)Functions (2.3) (cont.)

If S is a subset of A thenIf S is a subset of A then

f(S) = {f(s) | s in S}.f(S) = {f(s) | s in S}.

Example:Example:

• • f(a) = Zf(a) = Z

• • the image of d is Zthe image of d is Z

• • the domain of f is A = {a, b, c, d}the domain of f is A = {a, b, c, d}

• • the codomain is B = {X, Y, Z}the codomain is B = {X, Y, Z}

• • f(A) = {Y, Z}f(A) = {Y, Z}

• • the preimage of Y is bthe preimage of Y is b

• • the preimages of Z are a, c and dthe preimages of Z are a, c and d

• • f({c,d}) = {Z}f({c,d}) = {Z}

A Ba

b

c

d

X

Y

Z

Page 28: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

28

Functions (2.3) (cont.)Functions (2.3) (cont.)

Injections, Surjections and BijectionsInjections, Surjections and Bijections

Let f be a function from A to B.Let f be a function from A to B.

Definition:Definition: f is f is one-to-oneone-to-one (denoted 1-1) or (denoted 1-1) or injective injective if if preimages are unique.preimages are unique.

Note:Note: this means that if a this means that if a b then f(a) b then f(a) f(b). f(b).

Definition:Definition: f is f is ontoonto or or surjectivesurjective if every y in B has a if every y in B has a preimage.preimage.

Note:Note: this means that for every y in B there must be an x in A this means that for every y in B there must be an x in A such that f(x) = y.such that f(x) = y.

Definition:Definition: f is f is bijectivebijective if it is surjective and injective (one- if it is surjective and injective (one-to-one and onto).to-one and onto).

Page 29: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

29

Functions (2.3) (cont.)Functions (2.3) (cont.)

Examples:Examples:

The previous Example function is neither an The previous Example function is neither an injection nor a surjection. Hence it is not a injection nor a surjection. Hence it is not a bijection.bijection. A B

a

b

c

d

X

Y

Z

Surjection but not an injectionSurjection but not an injection

Page 30: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

30

Functions (2.3) (cont.)Functions (2.3) (cont.)

A Ba

b

c

dX

Y

Z

W

V

A Ba

b

c

dX

Y

W

V

Injection but not a surjectionInjection but not a surjection

Injection & a surjection, Injection & a surjection, hence a bijectionhence a bijection

Page 31: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

31

Functions (2.3) (cont.)Functions (2.3) (cont.)

Note:Note: Whenever there is a bijection from A to B, Whenever there is a bijection from A to B, the two sets must have the same number of the two sets must have the same number of elements elements

or the same or the same cardinalitycardinality..

That will become our That will become our definitiondefinition, especially for , especially for infinite sets.infinite sets.

Page 32: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

32

Functions (2.3) (cont.)Functions (2.3) (cont.)

Examples:Examples:

Let A = B = R, the reals. Determine which are Let A = B = R, the reals. Determine which are injections, surjections, bijections:injections, surjections, bijections:

• • f(x) = x,f(x) = x,

• • f(x) = xf(x) = x22,,

• • f(x) = xf(x) = x33,,

• • f(x) = x + sin(x),f(x) = x + sin(x),

• • f(x) = | x |f(x) = | x |

Page 33: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

33

Functions (2.3) (cont.)Functions (2.3) (cont.)

Let E be the set of even integers {0, 2, 4, Let E be the set of even integers {0, 2, 4, 6, . . . .}.6, . . . .}.

Then there is a bijection f from Then there is a bijection f from NN to to EE , the even , the even nonnegative integers, defined bynonnegative integers, defined by

f(x) = 2x.f(x) = 2x.

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

OH, NO! IT CAN’T BE....OH, NO! IT CAN’T BE....EE IS ONLY HALF AS BIG!!! IS ONLY HALF AS BIG!!!

Sorry! It gets worse before it gets better.Sorry! It gets worse before it gets better.

Page 34: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

34

Functions (2.3) (cont.)Functions (2.3) (cont.)

Inverse FunctionsInverse Functions

Definition: Definition:

Let f be a bijection from A to B. Then the Let f be a bijection from A to B. Then the inverseinverse of f, denoted fof f, denoted f-1-1, is the function from B to A , is the function from B to A defined asdefined as

ff-1-1(y) = x iff f(x) = y(y) = x iff f(x) = y

Page 35: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

35

Functions (2.3) (cont.)Functions (2.3) (cont.)

Example:Example: Let f be defined by the diagram: Let f be defined by the diagram:

A Ba

b

c

dX

Y

W

V

f A Ba

b

c

dX

Y

W

V

f-1

Note: No inverse exists Note: No inverse exists unless f is a bijectionunless f is a bijection

Page 36: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

36

Functions (2.3) (cont.)Functions (2.3) (cont.)

Definition:Definition: Let S be a subset of B. Then Let S be a subset of B. Then

f-1(S) = {x | f(x) f-1(S) = {x | f(x) S} S}

Note: f need not be a bijection for this definition to Note: f need not be a bijection for this definition to hold.hold.

Example:Example: Let f be the following function: Let f be the following function:

ff-1-1({Z}) = {c, d}({Z}) = {c, d}ff-1-1({X, Y}) = {a, b}({X, Y}) = {a, b}

A Ba

b

c

d

X

Y

Z

Page 37: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

37

Functions (2.3) (cont.)Functions (2.3) (cont.)

CompositionComposition

Definition:Definition:

Let f: BLet f: B C, g: A C, g: A B. The B. The composition of f with gcomposition of f with g, , denoted fdenoted fg, is the function from A to C defined byg, is the function from A to C defined by

f f g(x) = f(g(x)) g(x) = f(g(x))

Page 38: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

38

Examples:Examples:

A Ba

b

c

d

X

Y

W

V

g

j

i

h

Cf

Aa

b

c

dj

i

h

Cfg

Page 39: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

39

Functions (2.3) (cont.)Functions (2.3) (cont.)

If f(x) = xIf f(x) = x22 and g(x) = 2x + 1, then f(g(x)) = and g(x) = 2x + 1, then f(g(x)) = (2x+1)(2x+1)22 and g(f(x)) = 2x and g(f(x)) = 2x22 + 1 + 1

Definition:Definition:

The The floorfloor function, denoted f ( x) = function, denoted f ( x) = xx or or f(x) = floor(x), is the largest integer less than or equal to f(x) = floor(x), is the largest integer less than or equal to x.x.

TheThe ceiling ceiling function, denoted f ( x) = function, denoted f ( x) = xx or f(x) = or f(x) = ceiling(x), is the smallest integer greater than or equal to ceiling(x), is the smallest integer greater than or equal to x.x.

Page 40: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

40

Functions (2.3) (cont.)Functions (2.3) (cont.) Examples:Examples: 3.53.5 = 3, = 3, 3.53.5 = 4. = 4.

Note: the floor function is equivalent to truncation for positive Note: the floor function is equivalent to truncation for positive numbers.numbers.

Example:Example:

Suppose f: B Suppose f: B C, g: A C, g: A B and f B and f g is injective. g is injective.

What can we say about f and g?What can we say about f and g?

• • We know that if a We know that if a b then f(g(a)) b then f(g(a)) f(g(b)) since the f(g(b)) since the composition is injective.composition is injective.

• • Since f is a function, it cannot be the case that g(a) = g(b) since Since f is a function, it cannot be the case that g(a) = g(b) since then f would have two different images for the same point.then f would have two different images for the same point.

• • Hence, g(a) Hence, g(a) g(b) g(b)

It follows that g must be an injection.It follows that g must be an injection.

However, f need not be an injection (you show).However, f need not be an injection (you show).

Page 41: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

41Sequences and Summations Sequences and Summations (2.4)(2.4)

Definition:Definition: A A sequencesequence is a function from a subset is a function from a subset of the natural numbers (usually of the form {0, 1, of the natural numbers (usually of the form {0, 1, 2, . . . } to a set S.2, . . . } to a set S.Note: the setsNote: the sets

{0, 1, 2, 3, . . . , k} and {1, 2, 3, 4, . . . , k}{0, 1, 2, 3, . . . , k} and {1, 2, 3, 4, . . . , k}

are called are called initial segmentsinitial segments of N. of N.

Notation: if f is a function from {0, 1, 2, . . .} to S we Notation: if f is a function from {0, 1, 2, . . .} to S we usually denote f(i) by ausually denote f(i) by aii and we write and we write

where k is the upper limit (usually where k is the upper limit (usually ).).

k0i

k0ii210 aa,...a,a,a

Page 42: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

42Sequences and Summations (2.4) Sequences and Summations (2.4) (cont.)(cont.)

Examples:Examples:

Using zero-origin indexing, if f(i) = 1/(i + 1). then Using zero-origin indexing, if f(i) = 1/(i + 1). then thethe

SequenceSequence

f = {1, 1/'2,1/3,1/4, . . . } = {af = {1, 1/'2,1/3,1/4, . . . } = {a00, a, a11, a, a22, a, a33, . . }, . . }

Using one-origin indexing the sequence f becomesUsing one-origin indexing the sequence f becomes

{1/2, 1/3, . . .} = {a{1/2, 1/3, . . .} = {a11, a, a22, a, a33, . . .}, . . .}

Page 43: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

43Sequences and Summations (2.4) Sequences and Summations (2.4) (cont.)(cont.)

Summation NotationSummation Notation

Given a sequence we can add together a Given a sequence we can add together a subset of the sequence by using the summation subset of the sequence by using the summation and function notationand function notation

or more generallyor more generally

Sj

ja

n

mj)j(g)n(g)1m(g)m(g aa...aa

k0ia

Page 44: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

44Sequences and Summations (2.4) Sequences and Summations (2.4) (cont.)(cont.)

Examples:Examples:

Sj10752j

n

mjj2)n(2)1m(2m2

1

n

0

jn210

aaaaa then {2,5,7,10}S if

aa...aa

i

1...

4

1

3

1

2

11

rr...rrr

Similarity for theSimilarity for the product product notation: notation:

n

mjn1mmj a...aaa

Page 45: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

45Sequences and Summations (2.4) Sequences and Summations (2.4) (cont.)(cont.)

Definition:Definition: A A geometric progressiongeometric progression is a sequence of the form is a sequence of the form

a, ar, ara, ar, ar22, ar, ar33, ar, ar44, . . . ., . . . .Your book has a proof thatYour book has a proof that

(you can figure out what it is if r = 1).(you can figure out what it is if r = 1).

You should also be able to determine the sumYou should also be able to determine the sum• • if the index starts at k vs. 0if the index starts at k vs. 0• • if the index ends at something other than n if the index ends at something other than n

(e.g., n-1, n+1, etc.).(e.g., n-1, n+1, etc.).

1r if1r

1rr

n

0i

1ni

Page 46: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

46Sequences and Summations (2.4) Sequences and Summations (2.4) (cont.)(cont.)

CardinalityCardinality

Definition:Definition:

The cardinality of a set A is equal to the The cardinality of a set A is equal to the cardinality of a set B, denoted cardinality of a set B, denoted

| A | = | B |, | A | = | B |,

if there exists a bijection from A to B.if there exists a bijection from A to B.

Page 47: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

47

Sequences and Summations (2.4)Sequences and Summations (2.4)

Definition:Definition:

If a set has the same cardinality as a subset of the If a set has the same cardinality as a subset of the natural numbers N, then the set is called natural numbers N, then the set is called countablecountable..

If |A| = |N|, the set A is If |A| = |N|, the set A is countably infinitecountably infinite..

The (transfinite) cardinal number of the set N isThe (transfinite) cardinal number of the set N is

aleph nullaleph null = = 00..

If a set is not countable we say it is If a set is not countable we say it is uncountableuncountable..

Page 48: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

48

Sequences and Summations (2.4)Sequences and Summations (2.4)

Examples:Examples:

The following sets are uncountable (we show later)The following sets are uncountable (we show later)

The real numbers in [0, 1]The real numbers in [0, 1] P(N), the power set of NP(N), the power set of N

Note:Note: With infinite sets proper subsets can have the With infinite sets proper subsets can have the same cardinality. This cannot happen with finite sets.same cardinality. This cannot happen with finite sets.

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

Page 49: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

49

Sequences and Summations (2.4)Sequences and Summations (2.4) Definition:Definition: | A | | A | | B | if there is an injection from A to B. | B | if there is an injection from A to B.

Note: as you would hope,Note: as you would hope,

Theorem:Theorem: If | A | If | A | | B | and | B | | B | and | B | | A | then | A | = | B |. | A | then | A | = | B |.

This impliesThis implies if there is an injection from A to Bif there is an injection from A to B if there is an injection from B to Aif there is an injection from B to A thenthen there must be a bijection from A to Bthere must be a bijection from A to B

This is This is difficultdifficult to prove but is an example of demonstrating to prove but is an example of demonstrating existence without construction.existence without construction.

It is often easier to build the injections and then conclude the It is often easier to build the injections and then conclude the bijection exists.bijection exists.

Page 50: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

50

Sequences and Summations (2.4)Sequences and Summations (2.4)

Example:Example:

Theorem:Theorem: If A is a subset of B then | A | If A is a subset of B then | A | | B |. | B |.

Proof:Proof: the function f(x) = x is an injection from A to B. the function f(x) = x is an injection from A to B.

Example: Example: {0, 2, 5}| {0, 2, 5}| 00

The injection f: {0, 2, 5} The injection f: {0, 2, 5} N defined by f(x) = x is N defined by f(x) = x is shown below:shown below:

0 1 2 3 4 5 6 …0 1 2 3 4 5 6 …

0 2 50 2 5

Page 51: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

51

Sequences and Summations (2.4)Sequences and Summations (2.4)

Some Countably Infinite SetsSome Countably Infinite Sets

The set of even integers E ( 0 is considered even) is The set of even integers E ( 0 is considered even) is countably infinite. Note that E is a proper subset of countably infinite. Note that E is a proper subset of N,N,

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

ZZ++, the set of positive integers is countably infinite., the set of positive integers is countably infinite.

0 1 2 3 4 5 6 …0 1 2 3 4 5 6 …

0 2 4 6 8 10 12 …0 2 4 6 8 10 12 …

Page 52: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

52

Sequences and Summations (2.4)Sequences and Summations (2.4)

The set of positive rational numbers QThe set of positive rational numbers Q++ is is countably infinite.countably infinite.

Proof: ZProof: Z++ is a subset of Q is a subset of Q++ so |Z so |Z++| = | = 00 |Q |Q++|.|.

Now we have to show that |QNow we have to show that |Q++| | 00..

To do this we show that the positive rational To do this we show that the positive rational numbers with repetitions, Qnumbers with repetitions, QRR, is countably infinite., is countably infinite.

Then, since QThen, since Q++ is a subset of Q is a subset of QRR, it follows that , it follows that

|Q|Q++| | 00 and hence |Q and hence |Q++| = | = 00..

Page 53: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

53

Sequences and Summations (2.4)Sequences and Summations (2.4)

Page 54: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

54

Sequences and Summations (2.4)Sequences and Summations (2.4)

The position on the path (listing) indicates the The position on the path (listing) indicates the image of the bijective function f from N to Qimage of the bijective function f from N to QRR::

f(0) = 1/1, f(1) = 1/2, f(2) = 2/1, f(3) = 3/1, and so f(0) = 1/1, f(1) = 1/2, f(2) = 2/1, f(3) = 3/1, and so forth.forth.

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

Hence, |N| = |QHence, |N| = |QRR| = | = 00. Q. E. D. Q. E. D

The set of all rational numbers Q, positive and The set of all rational numbers Q, positive and negative, is countably infinite.negative, is countably infinite.

Page 55: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

55

Sequences and Summations (2.4)Sequences and Summations (2.4) The set of (finite length) strings S over a finite alphabet A is The set of (finite length) strings S over a finite alphabet A is

countably infinite.countably infinite.

To show this we assume thatTo show this we assume that A is nonvoidA is nonvoid There is an “alphabetical” ordering of the symbols in AThere is an “alphabetical” ordering of the symbols in A

Proof: List the strings in lexicographic order:Proof: List the strings in lexicographic order: all the strings of zero length,all the strings of zero length, then all the strings of length 1 in alphabetical order,then all the strings of length 1 in alphabetical order, then all the strings of length 2 in alphabetical order,then all the strings of length 2 in alphabetical order, etc.etc.

This implies a bijection from N to the list of strings and This implies a bijection from N to the list of strings and hence it is a countably infinite set.hence it is a countably infinite set.

Page 56: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

56

Sequences and Summations (2.4)Sequences and Summations (2.4)

For For exampleexample: :

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

Then the lexicographic ordering of A isThen the lexicographic ordering of A is

{{ , a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, , a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, aab,aab,

aac, aba, ....} = {f(0), f(1), f(2), f(3), f(4), . . . .}aac, aba, ....} = {f(0), f(1), f(2), f(3), f(4), . . . .}

Page 57: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

57

Sequences and Summations (2.4)Sequences and Summations (2.4) The set of all C programs isThe set of all C programs is countable countable..

Proof:Proof: Let S be the set of legitimate characters which can Let S be the set of legitimate characters which can appear in a C program.appear in a C program.

A C compiler will determine if an input program is a syntactically A C compiler will determine if an input program is a syntactically correct C program (the program doesn't have to do anything useful).correct C program (the program doesn't have to do anything useful).

Use the lexicographic ordering of S and feed the strings into the Use the lexicographic ordering of S and feed the strings into the compiler.compiler.

– If the compiler says YES, this is a syntactically correct C program, we If the compiler says YES, this is a syntactically correct C program, we add the program to the list.add the program to the list.

– Else we move on to the next string.Else we move on to the next string.

In this way we construct a list or an implied bijection from N to In this way we construct a list or an implied bijection from N to the set of C programs.the set of C programs.

Hence, the set of C programs is countable. Q. E. Hence, the set of C programs is countable. Q. E. D.D.

Page 58: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

58

Sequences and Summations (2.4)Sequences and Summations (2.4) Cantor DiagonalizationCantor Diagonalization

An important technique used to construct an object which is not a An important technique used to construct an object which is not a member of a countable set of objects with (possibly) infinite member of a countable set of objects with (possibly) infinite descriptionsdescriptions

Theorem:Theorem: The set of real numbers between 0 and 1 is The set of real numbers between 0 and 1 is uncountable.uncountable.Proof:Proof: We assume that it is countable and derive a contradiction. We assume that it is countable and derive a contradiction.

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

We show that no matter what list you produce we can construct a 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.real number between 0 and 1 which is not in the list.

Hence, there cannot exist a list and therefore the set is not Hence, there cannot exist a list and therefore the set is not countablecountable

Page 59: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

59

Sequences and Summations (2.4)Sequences and Summations (2.4)

It's actually much bigger than countable. It is said It's actually much bigger than countable. It is said to have the to have the cardinality of the continuumcardinality of the continuum, c., c.

Represent each real number in the list using Represent each real number in the list using its its decimal expansion.decimal expansion.

e.g., 1/3 = .3333333........e.g., 1/3 = .3333333........ 1/2 = .5000000........1/2 = .5000000........ = .4999999........= .4999999........

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

Page 60: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

60

Sequences and Summations (2.4)Sequences and Summations (2.4) THE LIST....THE LIST....

rr11 = .d = .d1111dd1212dd1313dd1414dd1515dd1616. . . . .. . . . .

rr22 = .d = .d2121dd2222dd2323dd2424dd2525dd2626 . . . . . . . .

rr33 = .d = .d3131dd3232dd3333dd3434dd3535dd3636 . . . . . . . .......

Now construct the number x = .xNow construct the number x = .x11xx22xx33xx44xx55xx66xx77. . . .. . . .

xxii = 3 if d = 3 if diiii 3 3

xxii = 4 if d = 4 if diiii = 3 = 3

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

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

Hence, no such list can exist and hence the interval (0,1) is Hence, no such list can exist and hence the interval (0,1) is uncountable. Q. E. D.uncountable. Q. E. D.

Page 61: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

61

Sequences and Summations (2.4)Sequences and Summations (2.4)

An extra goody:An extra goody:

Definition:Definition: a number x between 0 and 1 is a number x between 0 and 1 is computablecomputable if there is a C program which when if there is a C program which when given the input i, will produce the ith digit in the given the input i, will produce the ith digit in the decimal expansion of x.decimal expansion of x.

Example:Example:

The number 1/3 is computable.The number 1/3 is computable.

The C program which always outputs the digit 3,The C program which always outputs the digit 3,regardless if the input, computes the number.regardless if the input, computes the number.

Page 62: © by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sifth Edition, Mc Graw-Hill, 2007 Chapter 2: Basic Structures: Sets, Functions, Sequences

CSE 504, Ch.1 (part 3): The foundations: Logic & Proof, Sets, and Functions

62

Sequences and Summations (2.4)Sequences and Summations (2.4)

Theorem:Theorem: There is exists a number x between 0 There is exists a number x between 0 and 1 which is and 1 which is not computablenot computable..

There There does not existdoes not exist a C program (or a program in a C program (or a program in any other language) which will compute it!any other language) which will compute it!

Why? Because there are more numbers between 0 Why? Because there are more numbers between 0 and 1 than there are C programs to compute them.and 1 than there are C programs to compute them.

(in fact there are c such numbers!)(in fact there are c such numbers!)

Our second example of the Our second example of the nonexistencenonexistence of of programs to compute things!programs to compute things!