71
CS3518 Functions 07/04/22 Kees van Deemter 1 Functions and infinite sets (Approx 2-3 lectures. Initial (Approx 2-3 lectures. Initial sections adapted from slides for a sections adapted from slides for a course by Michael P. Frank) course by Michael P. Frank)

CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

Embed Size (px)

Citation preview

Page 1: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 1

Functions and infinite sets

(Approx 2-3 lectures. Initial sections adapted from (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael P. Frank)slides for a course by Michael P. Frank)

Page 2: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 2

Reading: relevant chapters of any book on Discrete Maths. For example, Rosen 5th ed., §1.8

Page 3: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 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

• Roughly, functions say “the so-and-so of …”Roughly, functions say “the so-and-so of …”• Functions are also called operations, mappings, Functions are also called operations, mappings,

etc.etc.

Page 4: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 4

Functions

• To understand functions more precisely, one needs To understand functions more precisely, one needs the mathematical notion of a setthe mathematical notion of a set

• We assume you are familiar with “naïve set We assume you are familiar with “naïve set theory” (as opposed to axiomatic set theory).theory” (as opposed to axiomatic set theory).

• In a nutshell: In a nutshell:

Page 5: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

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

Reminder of main set concepts

, , , , , , , , ,,

• =, =, , , , , , , , , , etc., etc.

• {a,b,...} (def. of a set by enumeration){a,b,...} (def. of a set by enumeration){{x x | | PP((xx)} (def. by set builder notation))} (def. by set builder notation)

• xxSS, , SSTT, , SS==TT, , SSTT. .

• PP((SS) (power set of S), ) (power set of S),

• AAB (Cartesian product of A and B)B (Cartesian product of A and B)

S

Page 6: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

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

Reminder of main set concepts

• Important sets of numbers: N, Z, Q, RImportant sets of numbers: N, Z, Q, R

• A relation on A is a subset of AxA. E.g.,A relation on A is a subset of AxA. E.g.,on, N, the relation < is {(0,1),(0,2), (1,2),…}on, N, the relation < is {(0,1),(0,2), (1,2),…}

• Set equality proof techniquesSet equality proof techniques

E.g., to prove A=B, prove each of:E.g., to prove A=B, prove each of:AABB

BBAA

Page 7: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 7

Function: Formal Definition

• A A functionfunction f from (or f from (or ““mappingmapping””) A to B) 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.

• Generalisations:Generalisations:– 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 8: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 8

Functions precisely

• 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 9: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 9

Useful diagrams

• 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 10: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 10

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 11: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 11

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 12: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 12

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 13: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 13

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 14: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 14

A new notation

• YYXX is the set is 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 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 15: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 15

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 16: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 16

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.

Page 17: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 17

Choosing the right (co)domain

Consider the function f such that f (x) = 100/xConsider the function f such that 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 the function g such that g(x) = √xConsider the function g such that 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 18: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 18

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 19: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 19

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

Page 20: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 20

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,

““ff is injectiveis 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 21: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 21

• Codomain may be larger.Codomain may be larger.

Page 22: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 22

One-to-One Illustration

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

••••

••

••••

••

••

•••••

••

••

Page 23: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 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

••••

••

••

•••••

••

••

Page 24: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 24

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 25: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 25

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 26: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 26

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 27: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 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 codomain (codomain (bbBB, , aaAA: : ff((aa)=)=bb).).

• ConsiderConsider ““country of birth ofcountry 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 28: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 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

• ConsiderConsider ““country of birth ofcountry 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 29: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 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 codomaincodomain

• In predicate logic:In predicate logic:

Page 30: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 30

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 31: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 31

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 32: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 32

Claim: if f:ZClaim: if f:ZZ and f(x) = x+1 thenZ and f(x) = 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=w.u=w.

Page 33: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 33

Onto/surjective functions

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

••••

••

• ••••

••

• ••••

•••

• ••••

•••

Page 34: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 34

Onto/surjective functions

• Are these functions Are these functions ontoonto??

••••

••

• ••••

••

• ••••

•••

• ••••

•••

Page 35: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 35

Onto/surjective functions

• Are these functions Are these functions ontoonto??

onto

••••

••

not onto

••••

••

onto

••••

•••

not onto

••••

•••

Page 36: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 36

1-1/injective functions

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

onto

••••

••

not onto

••••

••

onto

••••

•••

not onto

••••

•••

Page 37: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 37

1-1/injective functions

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

not 1-1onto

••••

••

not 1-1not onto

••••

••

1-1onto

••••

•••

1-1not onto

••••

•••

Page 38: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 38

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 39: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 39

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 40: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 40

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, itFormally, it’’s the unique function such that s the unique function such that

......

Page 41: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 41

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, itFormally, it’’s the unique function such that s the unique function such that

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

AIff 1

Page 42: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 42

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 43: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 43

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 44: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 44

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 45: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

Cardinality (informal)

• The cardinality of a finite set is its number The cardinality of a finite set is its number of elementsof elements

• E.g., card({a,b,c}) = card({e,f,g}) = 3E.g., card({a,b,c}) = card({e,f,g}) = 3

• Note: for finite sets X and Y, Note: for finite sets X and Y, card(X)=card(Y) if and only if there exists a card(X)=card(Y) if and only if there exists a bijection between X and Y bijection between X and Y

04/21/23 Kees van Deemter 45

Page 46: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

infinity

• This is straightforward if a set has 0 or 1 or This is straightforward if a set has 0 or 1 or 2 or … n (any natural number) elements2 or … n (any natural number) elements

• But what if the set has more elements than But what if the set has more elements than that? Some examples:that? Some examples:– The set of all natural numbers itselfThe set of all natural numbers itself– The set of all even natural numbersThe set of all even natural numbers– L(1*) = 1, 11,111,1111,11111, etc.L(1*) = 1, 11,111,1111,11111, etc.– L(0*1*) = 01,001,011,0001,0011, etcL(0*1*) = 01,001,011,0001,0011, etc

04/21/23 Kees van Deemter 46

Page 47: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 47

The Diagonalisation Method• Georg Cantor (1873): What’s the size of an Georg Cantor (1873): What’s the size of an

infiniteinfinite set? set?• E.g., is card(L(1E.g., is card(L(1**)) = card(L(0)) = card(L(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 48: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 48

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

– EE the set of even pos. natural numbers { the set of even pos. 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 49: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 49

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

Page 50: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 50

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) Q’s One way is to enumerate (i.e., to list) Q’s elements.elements.

– Pair the first element of Q with 1 (first elt. of Pair the first element of Q with 1 (first elt. of 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 51: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 51

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 52: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 52

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 53: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 53

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 54: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 54

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 55: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 55

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 56: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 56

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 57: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 57

showing how an arbitrary list might start:showing how an arbitrary list might start:

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 58: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 58

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 59: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

• This proof of the non-countability of the set This proof of the non-countability of the set of Real numbers is known as Cantorof Real numbers is known as Cantor’’s s diagonalisation diagonalisation argumentargument

• It proved to be the start of a large new area It proved to be the start of a large new area of set theory, involving the cardinalities of of set theory, involving the cardinalities of infinite setsinfinite sets

04/21/23 Kees van Deemter 59

Page 60: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 60

The Russell Paradox

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

Page 61: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 61

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 62: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 62

Axiomatic set theory

• Various axioms, e.g., saying that the union of a set of sets Various axioms, e.g., saying that the union of a set of sets is a set; the intersection of a set of sets is a set; etc. is a set; the intersection of a set of sets is a set; etc.

• One key axiom: One key axiom: Given a Predicate P, one can construct a Given a Predicate P, one can construct a set. It consists of all those elements x such that P(x) is true.set. It 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 exists set theory proposition This means, there exists set theory proposition pp such that such that

both both pp and and pp follow logically from the axioms of the theory! follow logically from the axioms of the theory! The conjunction of the axioms is a contradictionThe conjunction of the axioms is a contradiction– This makes the theory is fundamentally uninteresting, because This makes the theory is fundamentally uninteresting, because any any

possible statement in it can be (very trivially) proven!possible statement in it can be (very trivially) proven!

Page 63: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 63

Prove:

TheoremTheorem: Given a contradiction, any statement can be : Given a contradiction, any statement can be provenproven

Page 64: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 64

Prove:

TheoremTheorem: Given a contradiction, any statement can be : Given a contradiction, any statement can be provenproven

ProofProof: Let your contradiction be : Let your contradiction be pp & &p p (the assumption is you (the assumption is you’’ve proven it before)ve proven it before)

Suppose you want to prove Suppose you want to prove qq

(p(p & &p) --> q p) --> q is a tautology of propositional logicis a tautology of propositional logic(Check truth table of the formula, given p(Check truth table of the formula, given p & &p is false)p is false)

YouYou’’ve proven ve proven pp & &p p q q follows with Modus Ponens. Note that follows with Modus Ponens. Note that q q is arbitrary! is arbitrary!

Page 65: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 65

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 66: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 66

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

other wordsother words, , SSSSWith Proof by Contradiction, we have SWith Proof by Contradiction, we have SSS

• If If SSSS, then S is not one of those , then S is not one of those 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

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

Page 67: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 67

• To avoid inconsistency, set theory had to To avoid inconsistency, set theory had to somehow changesomehow change

Bertrand Russell1872-1970

Page 68: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 68

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’ll seen this technique in use when we You’ll seen this technique in use when we get to the programming language Haskell, get to the programming language Haskell, where we can write where we can write [x | x [x | x [1..] , even x], but not [1..] , even x], but not

[x | even x]. [x | even x].

Page 69: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 69

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 funny things like we can write funny things like xxxx (or(or x xxx, , for that matter). One solution:for that matter). One solution:forbid such expressions using forbid such expressions using typestypes..

• You’ll seen this technique in use as well: You’ll seen this technique in use as well: Haskell’s use of typing.Haskell’s use of typing.

Page 70: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 70

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

• But first we need to talk about Formal But first we need to talk about Formal Languages, Haskell, and Turing MachinesLanguages, Haskell, and Turing Machines

Page 71: CS3518 Functions 9/21/2015Kees van Deemter1 Functions and infinite sets (Approx 2-3 lectures. Initial sections adapted from slides for a course by Michael

CS3518 Functions

04/21/23 Kees van Deemter 71