52
Relations and Functions Chapter 5 1 to many 1 to 1 many to many

1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

Embed Size (px)

Citation preview

Page 1: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

1

Relations and FunctionsChapter 5

1 to many

1 to 1

many to many

Page 2: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

2

5.1 Cartesian Products and Relations

Def. 5.1 For sets , , the Cartesian product, orcross product, of and is denoted by and equals {( , )| , }.

A B UA B A B

a b a A b B

•the elements of A B are ordered pairs•|A B|=|A| |B|=|B A|

But, in general AndA B B AA A A a a a a A i nn n i i

.{( , , , )| , }.1 2 1 2 1

Page 3: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

3

5.1 Cartesian Products and Relations

Ex. 5.3 The sample space by rolling a die first then flipping a coin

Tree structure

1 2 3 4 5 6

1,H 1,T 2,H 2,T 3,H 3,T 4,H 4,T 5,H 5,T 6,H 6,T

={1,2,3,4,5,6} {H,T}

Page 4: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

4

5.1 Cartesian Products and Relations

Trees are convenient tools for enumeration.

Ex. 5.4 At the Wimbledon Tennis Championships, women playat most 3 sets in a match. The winner is the first to win two sets.In how many ways can a match be won?

N

E

N

E

N

E

N

EN

E

Therefore, 6 ways.

(

, )

permutations of NNE and EEN:3!

2! for men:

5!

3! 2!

2 6 2 20

Page 5: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

5

5.1 Cartesian Products and Relations

.on

a called is ofsubset Any . to from

a called is ofsubset any ,, setsFor 5.2 Def.

Arelation

binaryAABArelation

BAUBA

In general, for finite sets A,B with |A|=m and |B|=n, thereare 2mn relations from A to B, including the empty relationas well as the relation A B itself.

Ex. 5.7 A=Z+, a binary relation, R, on A, {(x,y)|x<y}

(1,2), (7,11) is in R, but (2,2), (3,2) is not in Ror 1R2, 7R11 (infix notation)

Page 6: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

6

5.1 Cartesian Products and Relations

Theorem 5.1 For any set , , :(a) b)

(c) (d) ( ) = ( ) ( )Proof of (a): For any , , ( , ) ( )

A B C UA B C A B A CA B C A B A CA B C A C B CA B C A C B C

a b U a b A B C a Ab B C a A b B b C a b A Ba b A C a b A B A

( ) ( ) ( )( ( ) ( ) ( )

( ) ( ) ( )

( ) , , ( , ) ( ),( , ) ( ) ( , ) ( ) ( C)

Page 7: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

7

5.2 Functions: Plain and One-to-One

Def. 5.3 For nonempty sets, A,B, a function, or mapping, f fromA to B, denoted f:A B, is a relation from A to B in which everyelement of A appears exactly once as the first component of anordered pair in the relation.

set A set B

not allowed

Page 8: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

8

5.2 Functions: Plain and One-to-One

Def 5.4 Domain, Codomain, Range

abf(a)=b

domain codomain

range

A B

Page 9: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

9

5.2 Functions: Plain and One-to-One

Ex. 5.10 the greatest integer less than or equal to

the least integer greater than or equal to

the integer part of

storage of matrix, is an matrix.row major storage:

( )( ). , . ,

( )( ). , . ,

( )( )( . ) , ( . ) , ( )

( ) ( ), , , , , ,

a floor functionf x x x

b ceiling functionf x x x

c trunc functiontrunc x xtrunc trunc truncd A a n n

a a a aij n n

n

3 8 3 3 8 4 3 3

3 8 4 3 8 3 3 3

3 8 3 3 8 3 3 3

11 12 1 21 a a af a initial i n j

a a a a a a af a initial j n i

n nnij

n n nnij

2 31

11 21 1 12 2 13

1 1

1 1

, , ,( ) ( ) ( )

, , , , , , , , ,( ) ( ) ( )

column major storage:

Page 10: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

10

5.2 Functions: Plain and One-to-One

If |A|=m, |B|=n, then the number of possible functions from Ato B is nm.

Def 5.5 A function f:A B is called one-to-one, or injective, ifeach element of B appears at most once as the image of an element of A.

If : is one to one, with , finite, we must have For arbitrary sets , , if : is one to one,

then for a1

f A B A BA B A B f A B

a A f a f a a a

| | | |.

, , ( ) ( ) .2 1 2 1 2

For example, is one - to - one.

But, is not. (

f x x

g x x x g g

( )

( ) ( ) ( ) )

3 7

0 1 04

Page 11: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

11

5.2 Functions: Plain and One-to-One

If |A|=m, |B|=n, and , then the number of one-to-one functions from A to B is P(n,m)=n!/(n-m)!.

m n

Def. 5.6 If : and then( for some and( is called the image of under .

1

1

f A B A Af A b B b f a a Af A A f

,) { | ( ), })

1 11

Ex. 5.16 Let :R R be given by ( ) = Then(R) = the range of = [0,+ ). The image of Z under is(Z) = {0, 1, 4, 9, 16, } and for we get(

g g x xg g gg Ag A

2

11

2 10 4

.

[ , ]) [ , ].

Page 12: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

12

5.2 Functions: Plain and One-to-One

Theorem 5.2 Let : , with Then(a) ((b) ((c) ( when is injective.Proof: for part (b). For any , ( for some

= ( ) ( = ( ) and or ( = ( ) and or ( (

1

11

1 12 2

f A B A A Af A A f A f Af A A f A f Af A A f A f A f

b B b f A Aa A A b f a b f a a A b f aa A b f A b f A b f A

, .) ( ) ( )) ( ) ( )) ( ) ( )

), )

) ( ( )) )) ( )

21 2 1 2

2 1 22 1 2

1 22

1 1 f Ab f A f A b f A b f A

a A b f a a A b f aa A A b f a b f A A

( )) ( ) ( ) )

( , ,, ).

22 1

1 1 1 2 2 21 2 1 2

Conversely, ( or (for some = ( )) or (for some = ( ))

for some = ( ) (

1 2

1 2 3

a b

Page 13: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

13

5.3 Onto Functions: Stirling Number of the Second Kind

Def 5.9 A function : is called , or , if( ) = , that is, if for all there is at least one

with ( ) = .

f A B onto surjectivef A B b B a A

f a b

Ex 5.19 f:R R defined by f(x)=x3 is onto. But f(x)=x2 is not.

Ex. 5.20 f:Z Z where f(x)=3x+1 is not onto. g:Q Q where g(x)=3x+1 is onto. h:R R where h(x)=3x+1 is onto.

If A,B are finite sets, then for any onto function f:A B topossibly exist we must have |A| |B|. But how many ontofunctions are there?

Page 14: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

14

5.3 Onto Functions: Stirling Number of the Second Kind

Ex. 5.22 If = { , , } and = {1,2} then all functions: are onto except and

So there are | |onto functions from to .

In general, if | |= 2 and | |= 2, then there are 2 ontofunctions from to .

2| |

m

A x y z Bf A B f x y z

f x y z BA B

A m BA B

A

13

1 1 1

2 2 2 2 2 2 6

2

{( , ), ( , ), ( , )}

{( , ), ( , ), ( , )}.

Page 15: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

15

5.3 Onto Functions: Stirling Number of the Second Kind

Ex. 5.23 For A={w,x,y,z} and B={1,2,3}, there are 34 functionsfrom A to B. Among all functions:(1) {1} is not mapped: 24 functions from A to {2,3}(2) {2} is not mapped: 24 functions from A to {1,3}(1) {3} is not mapped: 24 functions from A to {1,2}But the functions A to {1} or {2} or {3} are all counted twice.Therefore, number of onto functions from A to B is

33

22

3

11 36

33

22

3

11

4 4 4

. In general, if | |= 3

and | |= 3, there are 3

3 onto

functions from to .

A m

B

A B

m m m

(What about m=1 or m=2?)

Page 16: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

16

5.3 Onto Functions: Stirling Number of the Second Kind

General formulaFor finite sets , with | |= and | |= , there areA B A m B nn

nn

n

nn

n

nn

n n n

n kn k

n

n kn k

m m m

n m n m k m

k

n

k m

k

n

11

22

12

2 11

1 1

1

2 1

0

1

0

( ) ( )

( ) ( ) ( ) ( )

( ) ( )

Page 17: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

17

5.3 Onto Functions: Stirling Number of the Second Kind

Examples at the beginning of this chapter (P217)

(1) seven contracts to be awarded to 4 companies such that every company is involved?

4

44

4

33

4

22

4

11 84007 7 7 7

ways

(2) How many seven-symbol quaternary (0,1,2,3) sequences have at least one occurrence of each of the symbols 0,1,2, and 3?(3) How many 7 by 4 zero-one matrices have exactly one 1 in each row and at least one 1 in each column?

Page 18: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

18

5.3 Onto Functions: Stirling Number of the Second Kind

Examples at the beginning of this chapter (P217)

(4) Seven unrelated people enter the lobby of a building which has four additional floors, and they all get on an elevator. What is the probability that the elevator must stop at every floor in order to let passengers off? 8400/47=8400/16384>0.5(5) For positive integers m,n with m<n, prove that

( ) ( )

1 00

k m

k

n n

n kn k

(6) For every positive integer n, verify that

nn

n kn kk m

k

n! ( ) ( )

10

Page 19: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

19

5.3 Onto Functions: Stirling Number of the Second Kind

Ex. 5.25 7 jobs to be distributed to 4 people, each one gets at leastone job and job 1 is assigned to person 1.Ans: case 1: person 1 gets only job 1 onto functions from 6 elements to 3 elements (persons)

( ) ( )

13

33 540

0

3 6k

k kk

case 2: person1 gets more than one job onto functions from 6 elements to 4 elements (persons)

( ) ( )

14

44 1560

0

4 6k

k kk 540+1560

Page 20: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

20

5.3 Onto Functions: Stirling Number of the Second Kind

The number of ways to distribute m distinct objects into n different containers with no container left empty is

( ) ( )

10

k m

k

n n

n kn k

If the containers are identical:1

10n

n

n kn kk m

k

n

!( ) ( )

S(m,n): Stirling number of the second kindn!S(m,n) onto functions

Ex. 5.27 distribute m distinct objects into n identical containerswith empty containers allowed

n

i)i,m(S

1

Page 21: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

21

5.3 Onto Functions: Stirling Number of the Second Kind

Theorem 5.3 Let , be positive integers with < .Then ( + , ) = ( , - ) + ( , ).

m n n mS m n S m n nS m n

11 1

A a a a am m= { 1 , , , , }2 1 Proof:

n identical containers

S(m+1,n)

am+1 is alone in one container am+1 is not alone in one container

S(m,n-1)Distribute other n objects firstinto n containers. Then am+1 canbe put into one of them.

nS(m,n)

Page 22: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

22

5.3 Onto Functions: Stirling Number of the Second Kind

Ex. 5.28 How many ways to factorize 30030 into at least twofactors (greater than 1) where order is not relevant?Ans: 30030 2 3 5 7 11 13

There are at most 6 factors.Therefore, the answer is S(6,2)+ S(6,3)+S(6,4)+S(6,5)+S(6,6)=202

Ex. Prove that for all m n mm

ii S n in

i

m, , ( !) ( , )

Z +

1Proof: mn: ways to distribute n distinct objects into m distinct containers

i!S(n,i): ways to distribute n distinct objects into i distinct containers with no empty containers

Page 23: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

23

5.4 Special Functions

Def 5.10 For any nonempty subset , , any function ::is called a on . If , then the binary operationis said to be closed on .

Def 5.11 A function : is called a , or ,operation on .

Ex. 5.29 (a) :Z Z Z, defined by ( , ) = - , is closed binaryoperation on Z.

(b) If :Z Z Z with ( , ) = - , then is not closed.

(c) :R R with ( ) = / is a unary operation on R

+ +

+ + +

A B f A A Bbinary operation A B A

A

g A A unary monaryA

f f a b a b

g g a b a b g

h h a a

1 .

Page 24: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

24

5.4 Special Functions

Def 5.12 Let : ; that is, is a binary operation on .(a) is said to be commutative if ( , ) = ( , ), ( , ) .(b) When (that is, when is closed), is said to be associative if for , , , ( ( , ), ) = ( , ( , )).

Ex. 5.32 (a) :Z Z Z with ( , ) = + - . Then is bothcommutative and associative.(b) :Z Z Z with ( , ) = | | . Then (3,-2) = 6 (-2,3). is not commutative. But (

f A A B f Af f a b f b a a b A A

B A f fa b c A f f a b c f a f b c

f f a b a b ab f

h h a b a b h h hh

3

h a b c h a b c a b ch a h b c a h b c a b c a b c a b c h

g g a b a b g

( , ), ) = ( , )| |= | | | | and( , ( , )) = | ( , )|= | | | |= | | | | | |= | | | | . So is

associative.(c) :R R Z with ( , ) = + then is commutative butnot associatve. g(g(3.2,4.7),6.4) = 15 but g(3.2,g(4.7,6.4)) = 16

,

Page 25: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

25

5.4 Special Functions

Ex 5.33 If = { , , , }, then | |= 16. Consequently,

there are 4 functions : , that is, 4 closed binary operations on . How many of them are commutative?

16 16A a b c d A A

f A A AA

a b c d

abcd

44

46

6 entries

Therefore, 4 46 4

Page 26: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

26

5.4 Special Functions

Def. 5.13 Let : be a binary operation on . Anelement is called an for if ( , ) = ( , )= , for all .

Ex. 5.34 (a) :Z Z Z with ( , ) = + has identityelement 0 since ( , ) = ( , ) = for any integer .(b) :Z Z Z with ( , ) = - has no identity element.(c) Let = {1,2,3,4,5,6,7}, and : be the closed binary operation defined by ( , ) = { , }. Then ( ,7) =

( , ) = . So 7 is t

f A A B Ax A identity element f f a x f x a

a a A

f f a b a bf a f a a a

f f a b a bA g A A A

g a b a b g ag a a

0 0

7min

he identity element of .g

Page 27: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

27

5.4 Special Functions

Theorem 5.4 Let : be a binary operation. If has anidentity, then that identity is unique.Proof: If are identities, then ( and

( Therefore,

f A A B f

x x f x x xf x x x x x

1 2 1 2 1

1 2 2 1 2

, , ), ) . .

identity identity

Page 28: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

28

5.4 Special Functions

A a a a f A A An { , , , }, :1 2

a1 a2 a3 . . . an

a1

a2

a3

.

.

.an

n2 entries, each has n choices

nn2 closed binary operations

Page 29: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

29

5.4 Special Functions

A a a a f A A An { , , , }, :1 2

n entries

n n2

2

entries

n nnn n2

2 commutative closed binary operations

a1 a2 a3 . . . an

a1

a2

a3

.

.

.an

Page 30: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

30

5.4 Special Functions

A a a a f A A An { , , , }, :1 2 If a1 is the identity

a1 a2 a3 . . . an

a2 a3 . . . ana1

a2

a3

.

.

.an

a1

a2

a3

.

.

.an

n n2 2 1 ( ) entries

nn nn n

11 1 12 2( ) ( ) = closed binary operations

with an identity

Page 31: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

31

5.4 Special Functions

A a a a f A A An { , , , }, :1 2 If a1 is the identitya1 a2 a3 . . . an

a2 a3 . . . ana1

a2

a3

.

.

.an

a1

a2

a3

.

.

.an n-1 entries

( ) ( )n n 1 1

2

2 entries

n

n n nnn n n n

11

1 1

2

2

2

2 2( ) ( )

commutative

closed binary operations with an identity

Page 32: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

32

5.4 Special Functions

Def. 5.14 For sets and , if , then defined by is called the on the firstcoordinate. is defined similarly. (used in relational databases)

Ex. 5.36 For = = Z, let = {( , )| =| |}, Z andN.

A B D A B D Aa b a projection

A B D x y y x DD

AAB

AB

: ,( , ) ,

( )( ) { , , , , . . .}0 1 2 3

Page 33: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

33

5.5 The Pigeonhole Principle

The Pigeonhole Principle: If m pigeons occupy n pigeonholes andm>n, then at least one pigeonhole has two or more pigeons roosting in it.

For example, of 3 people, two are of the same sex. Of 13 people,two are born in the same month.

Ex. 5.42 A tape contains 500,000 words of four or fewer lowerlowercase letters. Can it be that they are all different?

The number of different possible words is

26At least one word must be repeated.

4

26 26 26 475254 5000003 2

Page 34: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

34

5.5 The Pigeonhole Principle

Ex. 5.43 Let Z where | |= 37. Then contains twoelements that have the same remainder upon division by 36. 36 pigeonholes (r) and 37 pigeons ( )

Ex. 5.44 Prove that if 101 integers are selected from the set= {1,2,3, ,200}, then there are two integers such that one

divides the other.

Proof: For each , we may write = , with 0, and{1,3,5, ,199}. Since | |= 100 and 101 integers are

selected, there are two distinct integers of the form

= Either | or | .

+S S S

n q r rS

S

x S x y ky T T

a y b y a b b a

k

m n

,

,

, .

36 0 36

2

2 2

Page 35: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

35

5.5 The Pigeonhole Principle

Ex. 5.44 Any subset of size six from the set S={1,2,3,...,9} mustcontain two elements whose sum is 10. pigeonholes: {1,9},{2,8},{3,7},{4,6},(5} pigeons: six of themTherefore, at two elements must be from the same subset.

Ex. 5.45 Triangle ACE is equilateral with AC=1. If five points areselected from the interior of the triangle, there are at least two whosedistance apart is less than 1/2.

region 1 region 2 region 3 region 4 4 pigeonholes

5 pigeons

Page 36: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

36

5.5 The Pigeonhole Principle

Ex. 5.46 Let S be a set of six positive integers whose maximumis at most 14. Show that the sums of the elements in all thenonempty subsets of S cannot all be distinct.

For any nonempty subset A of S, the sum of the elements in A,denoted SA, satifies 1 9 10 14 69 SA , and there are

26-1=63 nonempty subsets of S. (two many pigeonholes!)

Consider the subset of less than 6 elements.pigeonholes=10+11+...+14=60pigeons=26-1-1=62

Page 37: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

37

5.5 The Pigeonhole Principle

.m.)mm

).(m)qq(q,q

,rmqrmq

mts

ts.

,,,,m

.mn

therem

sts

stsst

ts

ts

m

m

n

12| Hence 12,gcd( odd, is

Since 12222 So N.for

12 and 12 Hence m.by division upon

remainder same thehave 12 and 12 where1,+<1

withZ, exists thereprinciple, pigeonhole By the 12

121212 integers positive 1+ heConsider t :Proof

12 divides such that integer

positive a exists that Prove odd. m with ZLet 5.47 Ex.

-

1221

21

+1

21

+

Page 38: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

38

5.5 The Pigeonhole Principle

Ex. 5.48 28 days to play at most 40 sets of tennis and at least 1 play per day. Prove there is a consecutive span of days duringwhich exactly 15 sets are played.

For 1 28, let be the total number of sets played from the start to the end of ith day. Then 1

Of the 56 integers, since their maximum is 55, two of them must bethe same. Hence there exist 1 < 28 with From day + 1 to the end of day , exactly 15 sets are played.

i xx x x

x x x

j i x xj i

i

i j

1 2 281 2 28

4015 15 15 40 15 55

15

,.

.

Page 39: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

39

5.6 Function Composition and Inverse Functions

Inverse of addition: and -Inverse of multiplication: and 1 /

u uu u

Def 5.15 If f:A B, then f is said to be bijective, or to be aone-to-one correspondence, if f is both one-to-one and onto.

1234

wxyz

A B

must be |A|=|B|(if )but could be

Ex. 5.50

A B B A or

Page 40: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

40

5.6 Function Composition and Inverse Functions

Def 5.16 The function 1 defined by for all , is called the identity function for .

Def. 5.17 If , : , we say that and are equal and write= , if ( ) = ( ) for all .

Ex. 5.51 Let :Z Z, :Z Q where ( ) = = ( ) Z.Yet, ! is a one - to - one correspondence, whereas is one - to - one but not onto.

Ex. 5.52 , :R Z defined as follows:

( ) =,

- ( ) =

A AA A a aa A A

f g A B f gf g f a g a a A

f g f x x g x xf g f g

f g

f xx if x Z

x if x R Zg x x

: , ( )

,

1

1, for all R, then = .x f g

Page 41: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

41

5.6 Function Composition and Inverse Functions

Def. 5.18 If : and : , we define the compositefunction, which is denoted : , by ( )( ) = ( ( )),for each .

f A B g B Cg f A C g f a g f a

a A

Ex. 5.53

1234

AB

C

abc

wxyz

fg

( )( ) ( ( )) ( ) , ( ) , ( ) ,g f g f g a x gf x gf y 1 1 2 3 gf(4) = z

Page 42: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

42

5.6 Function Composition and Inverse Functions

Ex. 5.54 Let , :R R be defined by ( ) =

Then ( ) = ( , whereas ( ) = ( + ) =

( + ) Therefore, the composition is not commutative.

Theorem 5.5 Let : and :(a) If , are one - to - one, then is one to one.(b) If , are onto, then is onto.

f g f x x g x x

g f x g x x f g x f x

x

f A B g B Cf g g ff g g f

2

2 2

2

5

5 5

5

, ( ) .

)

.

A B Cf g

Page 43: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

43

5.6 Function Composition and Inverse Functions

Ex. 5.55 Let , , :R R where ( ) =

Then (( ) )( ) = (

Theorem 5.6 If : , : , : , then ( ) =( ).

f g h f x x g x x h x

x h g f x hg x h x

x h g f x h g f x

f A B g B C h C D h g fh g f

2

2 2 2

2 2

5

2 5

5 2

, ( ) , ( )

. ) ( )

( ) ( ( ))( ) ( ( ( )))

A B Cf g

Dh

gf

hg

h(gf)

(hg)f

Page 44: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

44

5.6 Function Composition and Inverse Functions

Def. 5.19 If : , we define and for Z

Ex. 5.56 = {1,2,3,4}, : defined by = {(1,2), (2,2),

(3,1), (4,3)}. Then

Def. 5.21 If : , then is said to be if there is afunction : such that = and =

1 +

.

f A A f f n

f f f

A f A A f

f f f

f f n

f A B f invertibleg B A g f f g

n n

n

A B

, ,

( ).

{( , ), ( , ), ( , ), ( , )},

{( , ), ( , ), ( , ), ( , )} ,

1

2

31 2 2 2 3 2 4 1

1 2 2 2 3 2 4 2 3

1 1

A B

f

g

Page 45: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

45

5.6 Function Composition and Inverse Functions

Ex. 5.58 , :R R, ( ) = + , ( ) = Then

( ) = ( + ) = and ( ) = (

and are both invertible functions

Theorem 5.7. invertible function of : is unique.Proof: If : is also inverse of , then = and

= Consequently, =

f g f x x g x x

gf x g x x x fg x f x

x x f g

f A Bh B A f h f

f h h h h f g h f gg g

A

B B

A

2 51

25

2 51

22 5 5

1

25

21

25 5

11 1

1

( ).

( ) ( ))

[ ( )] .

. ( ) ( )

.

(

Since it is unique, we use to represent the inverse of . )-1f f

Page 46: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

46

5.6 Function Composition and Inverse Functions

Theorem 5.8 A function : is invertible if and only ifit is one - to - one and onto.

Theorem 5.9 If : , : are invertible functions, then

: is invertible and (g f)

How to find the inverse of a function?Ex. 5.60 :R R = {( , )| = + }

-1

-1

f A B

f A B g B C

g f A C f g

f x y y mx b

f x y y mx b y x y mx b x y x my b

x y ym

x b f xm

x b

c

1 1

11 1

.

{( , )| } {( , )| } {( , )| }

{( , )| ( )}. ( ) ( )

Page 47: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

47

5.6 Function Composition and Inverse Functions

Ex. 5.61 f:R R , f(x) = e f is - - .

f

Theorem 5.11 Let : for finite sets and , where| |=| | . Then the following statements are equivalent:(a) is one - to - one(b) is onto(c) is invertible.

+ x

-1

.

{( , )| } {( , )| } {( , )| }

{( , )| ln }. ( ) ln .

one to one and onto

x y y e y x y e x y x e

x y y x f x x

f A B A BA B

fff

x c x y

1

Page 48: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

48

5.7 Computational Complexity

problem algorithm 1 algorithm 2

algorithm k

Which one is best?We need measures.

time-complexity or space-complexitya function f(n) where n is the size of the input

lower bounds, best cases, average cases, worst cases

Page 49: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

49

5.7 Computational Complexity

Def. 5.23 Let , :Z R. We say that dominates (or is

dominated by ) if there exit constants R and Z

such that | ( )| | ( )| for all Z where .(write as ( ), order or big - Oh of )

+

+ +

+

f g g f f

g m k

f n m g n n n kf O g g g

,

Big-Oh Form NameO(1) constantO(log2n) LogarithmicO(n) LinearO(nlog2n) nlog2nO(n2) QuadraticO(n3) CubicO(nm),m=0,1,2,3,... PolynomialO(cn),c>1 ExponentialO(n!) Factorial

Page 50: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

50

5.7 Computational Complexity

18 1019. microseconds 2.14 10 days 5845 centuries8

Order of Complexity

problem size n log2n n nlog2n n2 2n n!

2

16

64

1 2 2 4 4 2

4 16 64 256 6.5 104 2.1 1013

6 64 384 4096 1.84 1019 >1089

Page 51: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

51

Summaries (m objects, n containers)

Objects Containers Some Number Ar Are Containers ofDistinct Distinct May Be Empty Distributions Yes Yes Yes Yes Yes No Yes No Yes Yes No No No Yes Yes No Yes No

nn S m nS m S m S m nS m nn m

mn m n

m n

m

m n

m

n

m

! ( , )( , ) ( , ) ( , )( , )

( )

1 2

1

1 1 1

1

Put one object in each container first.

Page 52: 1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many

52

Exercise. P252: 7,12 P258: 6,14,20,27 P256: 7,9,10,12 P272: 5,6,8,14 P277: 6,7,10,13,20 P305: 12,25, 27