Top Banner
odule #4 - Functions 05/13/22 Michael P. Frank / Kees van Deemter 1 Lecture adapted from CS3511,Discrete Methods Kees van Deemter Slides originally adapted from Slides originally adapted from Michael P. Frank’s Michael P. Frank’s Course Based on the Text Course Based on the Text Discrete Mathematics & Its Applications Discrete Mathematics & Its Applications (5 (5 th th Edition) Edition) by Kenneth H. Rosen by Kenneth H. Rosen
64

Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Mar 28, 2015

Download

Documents

Chase Bell
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 1

Lecture adapted from CS3511,Discrete Methods

Kees van Deemter

Slides originally adapted from Michael P. Frank’s Slides originally adapted from Michael P. Frank’s Course Based on the TextCourse Based on the Text

Discrete Mathematics & Its ApplicationsDiscrete Mathematics & Its Applications (5(5thth Edition) Edition)

by Kenneth H. Rosenby Kenneth H. Rosen

Page 2: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 2

Adaptation of Module #4:1. Functions

Rosen 5Rosen 5thth ed., §1.8 ed., §1.8~45 slides, ~1 lecture~45 slides, ~1 lecture

Page 3: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 3

Functions

• From calculus, you know the concept of a real-From calculus, you know the concept of a real-valued function valued function ff, , which assigns to each number which assigns to each number xxRR one particular value one particular value yy==ff((xx), where ), where yyRR..

• ExampleExample: : ff defined by the rule defined by the rule f(x)=xf(x)=x22

• The notion of a function can be generalized to the The notion of a function can be generalized to the concept of assigning elements of concept of assigning elements of anyany set to set to elements of elements of anyany set. set.

• Functions are also called operators.Functions are also called operators.

Page 4: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 4

Functions

• Functions were the key concept in lambda Functions were the key concept in lambda calculus and Haskell:calculus and Haskell:

x.x+2x.x+2 is the function that sends any appropriate is the function that sends any appropriate argument x to the corresponding value x+2argument x to the corresponding value x+2

• After the Haskell definition After the Haskell definition f x = x+2,f x = x+2,

f denotes that same function f denotes that same function x.x+2x.x+2• Let’s be more precise about functions, working Let’s be more precise about functions, working

towards a classification of functionstowards a classification of functions

Page 5: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 5

Function: Formal Definition

• A A functionfunction f from (or “mapping”) A to Bf from (or “mapping”) A to B ((ff::AABB) is an assignment of ) is an assignment of exactly oneexactly one element element ff((xx))BB to each element to each element xxA.A.

• Generalizations:Generalizations:– Functions of Functions of nn arguments: arguments:

ff: (A: (A11 x A x A22... x A... x Ann)) B. B.

– A A partial partial (non-(non-totaltotal)) function function ff assigns assigns zero or zero or oneone elements of elements of BB to each element to each element xxAA..

Page 6: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 6

Graphs of Functions

• We can represent a function We can represent a function ff::AABB as a set of ordered as a set of ordered pairs pairs f f =={({(aa,,ff((aa)) | )) | aaAA}}..

• This makes This makes ff a a relationrelation between A and B: between A and B:f is a subset of f is a subset of A x B. A x B. But functions are special:But functions are special:– for every for every aaAA, there is at least one pair , there is at least one pair ((aa,,bb)). Formally: . Formally:

aaAAbbB((a,b)B((a,b)f) f) – for every for every aaAA, there is at most one pair , there is at most one pair ((aa,,bb)). Formally: . Formally:

a,b,c((a,b)a,b,c((a,b)f f (a,c) (a,c)f f b bc) c) • A relation over numbers can be represent as a set of A relation over numbers can be represent as a set of

points on a plane. (A point is a pair points on a plane. (A point is a pair ((x,yx,y)).).)– A function is then a curve (set of points), A function is then a curve (set of points),

with only one with only one yy for each for each xx. .

Page 7: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 7

• Functions can be represented graphically in Functions can be represented graphically in several ways:several ways:

• •

AB

a b

f

f

••••

••

• x

y

PlotBipartite GraphLike Venn diagrams

A B

Page 8: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 8

Functions that you’ve seen before

• A A setset SS over universe over universe UU can be viewed as a can be viewed as a function from the elements of function from the elements of U U to …to …

Page 9: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 9

Still More Functions

• A A setset SS over universe over universe UU can be viewed as a can be viewed as a function from the elements of function from the elements of U U to …to …

… … {{TT, , FF}, saying for each element of }, saying for each element of UU whether it is in whether it is in SS. (This is called the . (This is called the characteristic functioncharacteristic function of of SS))

Suppose U={0,1,2,3,4}. ThenSuppose U={0,1,2,3,4}. Then SS={1,3}={1,3}

SS(0)=(0)=SS(2)=(2)=SS(4)=(4)=FF, , SS(1)=(1)=SS(3)=(3)=TT..

Page 10: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 10

Still More Functions

• A A set operator,set operator, such as such as or or , can be , can be viewed as a function from … to …viewed as a function from … to …

Page 11: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 11

Still More Functions

• A A set operatorset operator such as such as or or can be can be viewed as a function …viewed as a function …

… from (ordered) pairs of sets, … from (ordered) pairs of sets, to sets. to sets. – Example: Example: (({1,3},{3,4})) = {3}(({1,3},{3,4})) = {3}

Page 12: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 12

A new notation

• Sometimes we write Sometimes we write YYXX to denote the set to denote the set FF of of allall possible functions possible functions ff: : XXYY..

• Thus,Thus, f f YYXX is another way of saying is another way of saying that that ff: : XXYY..

• (This notation is especially appropriate, (This notation is especially appropriate, because for finite because for finite XX, , YY, we have , we have ||FF| = || = |YY||||XX||.. ))

Page 13: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 13

Some Function Terminology

• If If ff::AABB, and , and ff((aa)=)=b b (where (where aaAA & & bbBB), ), then we say:then we say:– AA is the is the domaindomain of of ff. . – BB is the is the codomaincodomain of of ff..– bb is the is the imageimage of of a a under under ff..– aa is a is a pre-imagepre-image of of bb under under f.f.

• In general, In general, bb may have more than 1 pre-image. may have more than 1 pre-image.

– The The rangerange RRBB of of f f is is RR={={bb | | aa ff((aa)=)=bb } }..

We also saythe signatureof f is A→B.

Page 14: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 14

Range versus Codomain

• The range of a function may not be its whole The range of a function may not be its whole codomain.codomain.

• The codomain is the set that the function is The codomain is the set that the function is declareddeclared to map all domain values into. to map all domain values into.

• The range is the The range is the particularparticular set of values in the set of values in the codomain that the function codomain that the function actuallyactually maps elements maps elements of the domain to.of the domain to.

• (The range is the smallest set that could be used as (The range is the smallest set that could be used as its codomain.)its codomain.)

Page 15: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 15

Choosing the right (co)domain

Consider the function f = λx.100/xConsider the function f = λx.100/xIs f a (total) function from Int to R?Is f a (total) function from Int to R?• f is a partial function from Int to Rf is a partial function from Int to R• f is a (total) function from Int-{0} to Rf is a (total) function from Int-{0} to R

Consider g = λx.√xConsider g = λx.√xIs g a (total) function from R to R?Is g a (total) function from R to R?g is a total function from R+ to RxRg is a total function from R+ to RxRe.g. g(4)= (2,-2)e.g. g(4)= (2,-2)

Page 16: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 16

Images of Sets under Functions

• Given Given ff::AABB, and , and SSAA,,

• The The imageimage of of SS under under ff is the set of all is the set of all images (under images (under ff) of the elements of ) of the elements of SS..

ff((SS) :) : { {ff((ss) | ) | ssSS}} : : { {bb | | ssSS: : ff((ss)=)=bb}}..

• The range of The range of ff equals equalsthe image (under the image (under ff) of ...) of ...

Page 17: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 17

Images of Sets under Functions

• Given Given ff::AABB, and , and SSAA,,

• The The imageimage of of SS under under ff is the set of all is the set of all images (under images (under ff) of the elements of ) of the elements of SS..

ff((SS) :) : { {ff((ss) | ) | ssSS}} : : { {bb | | ssSS: : ff((ss)=)=bb}}..

• The range of The range of ff equals equalsthe image (under the image (under ff) of ) of ff’s domain’s domain..

Page 18: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 18

One-to-One Functions

• A function is A function is one-to-one (1-1)one-to-one (1-1), or , or injectiveinjective, or , or an an injectioninjection, iff every element of its range has , iff every element of its range has onlyonly 1 1 pre-image. pre-image. – Formally: given Formally: given ff::AAB,B,

“f“f is injective” :is injective” : ( (xx,,yy: : xxy y ff((xx))ff((yy))).).

• In other words: only In other words: only one element of the domain is element of the domain is mapped mapped toto any given any given oneone element of the range. element of the range.– In this case, domain & range have same cardinality. In this case, domain & range have same cardinality.

What about codomain?What about codomain?

Page 19: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 19

• Codomain may be larger.Codomain may be larger.

Page 20: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 20

One-to-One Illustration

• Are these relations one-to-one functions?Are these relations one-to-one functions?

••••

••

••••

••

••

•••••

••

••

Page 21: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 21

One-to-One Illustration

• Are these relations one-to-one functions?Are these relations one-to-one functions?

••••

••

One-to-one

••••

••

••

•••••

••

••

Page 22: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 22

One-to-One Illustration

• Are these relations one-to-one functions?Are these relations one-to-one functions?

••••

••

One-to-one

••••

••

••

•Not one-to-one

••••

••

••

Page 23: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 23

One-to-One Illustration

• Are these relations one-to-one functions?Are these relations one-to-one functions?

••••

••

One-to-one

••••

••

••

•Not one-to-one

••••

••

••

•Not even a function!

Page 24: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 24

Sufficient Conditions for 1-1ness

• For functions For functions ff over numbers, we say: over numbers, we say:– ff is is strictlystrictly increasingincreasing iff iff x>y x>y ff((xx))>f>f((yy)) for all for all

x,yx,y in domain; in domain;– ff is is strictlystrictly decreasingdecreasing iff iff x>y x>y ff((xx))<f<f((yy)) for for

all all x,yx,y in domain; in domain;

• If If ff is either strictly increasing or strictly is either strictly increasing or strictly decreasing, then decreasing, then ff must be one-to-one. must be one-to-one.– Does the converse hold?Does the converse hold?

Page 25: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 25

Onto (Surjective) Functions

• A function A function ff::AABB is is ontoonto or or surjectivesurjective or or a a surjectionsurjection iff its range is equal to its iff its range is equal to its codomain (codomain (bbBB, , aaAA: : ff((aa)=)=bb).).

• ConsiderConsider “country of birth of” “country of birth of”: A: AB,B,where A=people, B=countries. where A=people, B=countries. Is this a function? Is this a function? Is it an injection? Is it an injection? Is it a surjection?Is it a surjection?

Page 26: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 26

Onto (Surjective) Functions

• A function A function ff::AABB is is ontoonto or or surjectivesurjective or or a a surjectionsurjection iff its range is equal to its iff its range is equal to its codomain codomain

• ConsiderConsider “country of birth of” “country of birth of”: A: AB,B,where A=people, B=countries. where A=people, B=countries. Is this a function? Is this a function? Yes (always 1 c.o.b.) Yes (always 1 c.o.b.) Is it an injection? Is it an injection? No (many have same c.o.b.)No (many have same c.o.b.) Is it a surjection? Is it a surjection? Probably yes ..Probably yes ..

Page 27: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 27

Onto (Surjective) Functions

• A function A function ff::AABB is is ontoonto or or surjectivesurjective or or a a surjectionsurjection iff its range is equal to its iff its range is equal to its codomaincodomain

• In predicate logic:In predicate logic:

Page 28: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 28

Onto (Surjective) Functions

• A function A function ff::AABB is is ontoonto or or surjectivesurjective or or a a surjectionsurjection iff its range is equal to its iff its range is equal to its codomain. codomain.

• In predicate logic:In predicate logic:

bbBBaaAA ff((aa)=)=bb

Page 29: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 29

Onto (Surjective) Functions

• A function A function ff::AABB is is ontoonto or or surjectivesurjective or or a a surjectionsurjection iff its range is equal to its iff its range is equal to its codomain (codomain (bbBBaaAA ff((aa)=)=bb).).

• E.g.E.g., for domain & codomain Z, the , for domain & codomain Z, the function function x.x+1 is injective and surjective.x.x+1 is injective and surjective.

Page 30: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 30

Claim: if f:ZClaim: if f:ZZ and f =Z and f =x.x+1 thenx.x+1 thenf is 1-to-1 and also onto.f is 1-to-1 and also onto. ((ZZ is the set of is the set of allall integers) integers)

• Proof that Proof that f is ontof is onto: Consider any arbitrary : Consider any arbitrary element a of Z. We have f(a-1)=a, where a element a of Z. We have f(a-1)=a, where a Z. Z.

• Proof that Proof that f is 1-to-1f is 1-to-1: Suppose f(u)=f(w)=a. In : Suppose f(u)=f(w)=a. In other words, u+1=a and w+1=a. It follows that other words, u+1=a and w+1=a. It follows that u=a-1 and w=a-1, so u=w.u=a-1 and w=a-1, so u=w.

Page 31: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 31

Illustration of Onto

• Are these functions Are these functions onto onto their depicted co-their depicted co-domains?domains?

••••

••

• ••••

••

• ••••

•••

• ••••

•••

Page 32: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 32

Illustration of Onto

• Are these functions Are these functions ontoonto??

••••

••

• ••••

••

• ••••

•••

• ••••

•••

Page 33: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 33

Illustration of Onto

• Are these functions Are these functions ontoonto??

onto

••••

••

not onto

••••

••

onto

••••

•••

not onto

••••

•••

Page 34: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 34

Illustration of Onto

• Are these functions 1-1?Are these functions 1-1?

onto

••••

••

not onto

••••

••

onto

••••

•••

not onto

••••

•••

Page 35: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 35

Illustration of Onto

• Are these functions 1-1?Are these functions 1-1?

not 1-1onto

••••

••

not 1-1not onto

••••

••

1-1onto

••••

•••

1-1not onto

••••

•••

Page 36: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 36

Bijections

• A function is said to be A function is said to be a one-to-one a one-to-one correspondencecorrespondence, or , or a a bijectionbijection iff it is iff it is bothboth one-to-one one-to-one and and onto.onto.

Page 37: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 37

Two terminologies for talking about functions

1.1. injectioninjection = one-to-one = one-to-one

2.2. surjectionsurjection = onto = onto

3.3. bijectionbijection = one-to-one correspondence = one-to-one correspondence

3 = 1&23 = 1&2

Page 38: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 38

Bijections

• For bijections For bijections f:Af:ABB, there exists a function , there exists a function that is the that is the inverse inverse of of ff, , written written f f 11: : BBAA

• Intuitively, this is the function that undoes Intuitively, this is the function that undoes everything that everything that ff does does

• Formally, it’s the unique function such that Formally, it’s the unique function such that

......

Page 39: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 39

Bijections

• For bijections For bijections f:Af:ABB, there exists an , there exists an inverse inverse of of ff, written , written f f 11: : BBAA

• Intuitively, this is the function that undoes Intuitively, this is the function that undoes everything that everything that ff does does

• Formally, it’s the unique function such that Formally, it’s the unique function such that

(the identity function on (the identity function on AA))

AIff 1

Page 40: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 40

Bijections

• Example 1: Let f: Example 1: Let f: ZZZZ be defined as be defined as f(x)= f(x)= x+1x+1. . What is fWhat is f1 1 ??

• Example 2: Let gExample 2: Let g: : ZN be defined as be defined as g(x)= g(x)= |x||x|. What is g. What is g1 1 ??

Page 41: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 41

Bijections

• Example 1: Let f: Example 1: Let f: ZZZZ be defined as be defined as f(x)=x+1. f(x)=x+1. What is fWhat is f1 1 ??

• ff11 is the function (let’s call it h) is the function (let’s call it h) h: h: ZZZZ defined as h(x)=x-1. defined as h(x)=x-1.

• Proof: Proof: Ifh

h(f(x)) = (x+1)-1 = x

Page 42: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 42

Bijections

• Example 2: Let gExample 2: Let g: : ZN be defined as be defined as g(x)=|x|g(x)=|x|. What is g. What is g1 1 ??

• This was a trick question:This was a trick question: there is no such there is no such function, since g is not a bijection:function, since g is not a bijection:There is no There is no functionfunction h such that h such that h(|x|)=x and h(|x|)=h(|x|)=x and h(|x|)=x x

• (NB There is a (NB There is a relationrelation h h for which this is true.)for which this is true.)

Page 43: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 43

The Diagonalisation Method• Georg Cantor (1873): Can we compare the sizes Georg Cantor (1873): Can we compare the sizes

of of infiniteinfinite sets? sets?• Example: card(Example: card(N N ) = card({0) = card({0**11**})?})?

– Both are infiniteBoth are infinite– But is one larger than the other?But is one larger than the other?

• Cantor’s idea:Cantor’s idea:– The size (cardinality) of a set should not depend on The size (cardinality) of a set should not depend on

the the identityidentity of its elements of its elements– Two finite sets Two finite sets AA and and BB have the have the same sizesame size if we can if we can

pair the elements of pair the elements of AA with elements of with elements of BB– Formally: there exists a Formally: there exists a bijection bijection between between AA and and BB

Page 44: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 44

Correspondences (Cont’d)• Example: LetExample: Let– N N be the set of natural numbers {1, 2, 3, …} be the set of natural numbers {1, 2, 3, …}

– EE be the set of even natural numbers { be the set of even natural numbers {22, , 44, , 66, …}, …}

• Using Cantor’s definition of size, we can show that Using Cantor’s definition of size, we can show that N N and and EE have the have the same sizesame size::– Bijection (!): Bijection (!): ff ( (nn) = ) = 22nn

• Intuitively, Intuitively, EE is smaller than is smaller than NN, but, but– Pairing each element of Pairing each element of NN with its corresponding with its corresponding

element in element in EE is possible, is possible, – So we declare these two set to be the same sizeSo we declare these two set to be the same size

– This even thoughThis even though E E NN ( (E E is a real subset ofis a real subset of NN ) )

663344222211

ff ( (nn))nn

… …

Page 45: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 45

Countable sets• A set X is finite if it has n elements, A set X is finite if it has n elements, for some n in for some n in NN..

• A set is A set is countablecountable if either if either – It is It is finitefinite or or– It has the It has the same sizesame size as as NN, the natural numbers, the natural numbers

• For example,For example,– NN is countable, and so are all its subsets: is countable, and so are all its subsets:

– EE is countable is countable– {0,1,2,3} is countable{0,1,2,3} is countable is countableis countable

• How about supersets of How about supersets of NN??

Page 46: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 46

An Even Stranger Example…• Let Let QQ be the set of positive rational numbers be the set of positive rational numbers

QQ = { m/n | m,n = { m/n | m,n NN } }

• Just like Just like EE, the set , the set QQ has the same size as has the same size as N N !!– We show this giving a We show this giving a bijectionbijection from from QQ to to N N – QQ is thus is thus countablecountable

• One way is to enumerate (i.e., to list) X’s One way is to enumerate (i.e., to list) X’s elements. For example, for X=elements. For example, for X=Q Q ::

– Pair the first element of X with 1 from Pair the first element of X with 1 from N N

And so on, making sure every member of And so on, making sure every member of QQ

appears only appears only onceonce in the list in the list

Page 47: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 47

An Even Stranger Example… (Cont’d)

• To build a list with the elements of To build a list with the elements of QQ– make inf. matrix with all positive rational numbersmake inf. matrix with all positive rational numbers– ii -th row contains all numbers with numerator -th row contains all numbers with numerator ii– jj -th column has all numbers with denominator -th column has all numbers with denominator jj– ii //jj is in is in ii -th row and -th row and jj -th column-th column 1/1 1/2 1/3 1/4 1/5

2/1 2/2 2/3 2/4 2/5

3/1 3/2 3/3 3/4 3/5

4/1 4/2 4/3 4/4 4/5

5/1 5/2 5/3 5/4 5/5

. . .

Page 48: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 48

An Even Stranger Example… (Cont’d)

• Now we turn the previous matrix into a listNow we turn the previous matrix into a list

• A bad way: begin list with first rowA bad way: begin list with first row– Since rows are infinite, we will never get to 2Since rows are infinite, we will never get to 2ndnd row! row!

Page 49: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 49

An Even Stranger Example… (Cont’d)

• Instead, we list the elements along diagonals:Instead, we list the elements along diagonals:

1/1 1/2 1/3 1/4 1/5

2/1 2/2 2/3 2/4 2/5

3/1 3/2 3/3 3/4 3/5

4/1 4/2 4/3 4/4 4/5

5/1 5/2 5/3 5/4 5/5

. . ..

. .

We should, however, eliminate repeated elements

Page 50: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 50

An Even Stranger Example… (Cont’d)

• We list elements along diagonals We list elements along diagonals w/o repetitionsw/o repetitions::

1/1 1/2 1/3 1/4 1/5

2/1 2/2 2/3 2/4

3/1 3/2 3/3

4/1 4/2

5/1

. . ..

. .

1/1, 2/1, 1/2, 3/1, 1/3, …

Page 51: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 51

Uncountable sets• Some sets have no correspondence with Some sets have no correspondence with NN• These sets are simply too big!These sets are simply too big!

– They are not countable: we say They are not countable: we say uncountableuncountable

• Theorem:Theorem:– The set of real numbers between 0 and 1The set of real numbers between 0 and 1

(e.g., 0.244, 0.3141592323....) is (e.g., 0.244, 0.3141592323....) is uncountableuncountableCall this set RCall this set R0,10,1

(Some sets are even larger. “Serious” set theory is (Some sets are even larger. “Serious” set theory is all about theorems that concern infinite sets. – all about theorems that concern infinite sets. – Most of this is irrelevant for this course.)Most of this is irrelevant for this course.)

Page 52: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 52

Finally: diagonalisation

Theorem: | RTheorem: | R0,10,1 | > |N|. | > |N|. ProofProof strategy: strategy:

| R| R0,10,1 |>=|N|. Suppose | R |>=|N|. Suppose | R0,10,1 |=|N| and derive |=|N| and derive a contradiction: Each member of Ra contradiction: Each member of R0,10,1 can can be written as a zero followed by a dot and be written as a zero followed by a dot and a countable sequence of digits. Suppose a countable sequence of digits. Suppose there existed a complete enumeration of R, there existed a complete enumeration of R, (using (using whatever whatever order) <e1,e2,e3,...>.order) <e1,e2,e3,...>.

Page 53: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 53

Cantor’s diagonalisation trick:

(starting from an arbitrary list)(starting from an arbitrary list)

e1. 0.e1. 0.00000000000000000000000....000000000000000000000....e2. 0.0e2. 0.01100000000000000000000....00000000000000000000....e3. 0.82e3. 0.82000000000000000000000....0000000000000000000....e4. 0.171e4. 0.17100000000000000000000....000000000000000000..........

Page 54: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 54

Now construct a Real number n that’s not in the enumeration:

nn’s first digit (after the dot) = ’s first digit (after the dot) = [e1’s first digit] + 1[e1’s first digit] + 1

nn’s second digit = [e2’s second digit] + 1 ...’s second digit = [e2’s second digit] + 1 ...GeneralGeneral:: nn’s i-th difit = [e-i’s i-th digit] + 1’s i-th difit = [e-i’s i-th digit] + 1 i: i: nn differs from e-i in its i-th digit differs from e-i in its i-th digitContradiction: <e1,e2,e3,...> is not a Contradiction: <e1,e2,e3,...> is not a

(complete) enumeration after all. (complete) enumeration after all. QEDQED

Page 55: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 55

Adaptation of Module #3:2. Sets and the Russell Paradox

Rosen 5Rosen 5thth ed., §1.6 ed., §1.6especially ex. 30 on p. 86especially ex. 30 on p. 86

Page 56: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 56

Basic Set Notations

• Set enumeration {a, b, c} Set enumeration {a, b, c}

and set-builder {and set-builder {xx||PP((xx)}.)}. relation, and the empty set relation, and the empty set ..

• Set relations =, Set relations =, , , , , , , , , , etc., etc.

• Venn diagrams.Venn diagrams.

• Cardinality |Cardinality |SS| and infinite sets | and infinite sets NN, , ZZ, , RR..

• Power sets P(Power sets P(SS).).

Page 57: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 57

Axiomatic set theory

• Various axioms, e.g., saying that the union of two sets is Various axioms, e.g., saying that the union of two sets is also a setalso a set

• One key axiom: One key axiom: Given a Predicate P, construct a set. The Given a Predicate P, construct a set. The set consists of all those elements x such that P(x) is true.set consists of all those elements x such that P(x) is true.

• But, the resulting theory turns out to be But, the resulting theory turns out to be logically logically inconsistentinconsistent! ! – This means, there exist set theory propositions This means, there exist set theory propositions pp such that you can such that you can

prove that both prove that both pp and and pp follow logically from the axioms of the follow logically from the axioms of the theory!theory!

The conjunction of the axioms is a contradiction!The conjunction of the axioms is a contradiction!– This theory is fundamentally uninteresting, because any possible This theory is fundamentally uninteresting, because any possible

statement in it can be (very trivially) “proved” by contradiction!statement in it can be (very trivially) “proved” by contradiction!

Page 58: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 58

This version of Set Theory is inconsistent

Russell’s paradox:Russell’s paradox:

• Consider the set that corresponds with the Consider the set that corresponds with the predicate predicate x x x x ::

S S = {= {x x | | xxxx }. }.

• Now ask: is Now ask: is SSSS??

Page 59: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 59

Russell’s paradox• LLet et S S = {= {x x | | xxxx }. Is }. Is SSSS??• If If SSSS, then S is one of those objects , then S is one of those objects xx for which for which

xxx. x. In other wordsIn other words, , SSSSWith Proof by Contradiction, we have SWith Proof by Contradiction, we have SSS

• If If SSSS, then S is not one of those objects , then S is not one of those objects xx for for which which xxx. x. In other wordsIn other words, , SSSSWith Proof by Contradiction, we have SWith Proof by Contradiction, we have SSS

• We conclude that both We conclude that both SSSS nor nor SSSS• Paradox!Paradox!

Page 60: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 60

• To avoid inconsistency, set theory must To avoid inconsistency, set theory must somehow changesomehow change

Bertrand Russell1872-1970

Page 61: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 61

One technique to avoid the problem:

• Given a Given a setset S S and a predicate P, construct a and a predicate P, construct a new set, consisting of those elements x of S new set, consisting of those elements x of S such that P(x) is true.such that P(x) is true.

• You’ve seen this technique in use: You’ve seen this technique in use: Haskell’s list comprehensions allow us to Haskell’s list comprehensions allow us to write write [x | x [x | x [1..] , even x], but not simply [1..] , even x], but not simply [x | even x], [x | even x],

Page 62: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 62

Another technique to avoid the problem:

• Russell’s paradox arises from the fact that Russell’s paradox arises from the fact that we can write we can write xxxx (or(or x xxx, for that matter)., for that matter).Forbid such expressions using Forbid such expressions using typestypes..

• You’ve seen this technique in use: You’ve seen this technique in use: Haskell’s use of typing.Haskell’s use of typing.Applied to the present case: give Applied to the present case: give a type a type that forbids it from relating two things of that forbids it from relating two things of the same type.the same type.

Page 63: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 63

Our focus: computability

• We shall not worry about “saving” set We shall not worry about “saving” set theory from paradoxes like Russell’stheory from paradoxes like Russell’s

• Instead, we shall use the Russell paradox in Instead, we shall use the Russell paradox in a different settinga different setting

• Before we do this, we need to talk about Before we do this, we need to talk about computability and Turing Machines.computability and Turing Machines.

Page 64: Module #4 - Functions 4/6/2014Michael P. Frank / Kees van Deemter1 Lecture adapted from CS3511, Discrete Methods Kees van Deemter Slides originally adapted.

Module #4 - Functions

04/10/23 Michael P. Frank / Kees van Deemter 64