Você está na página 1de 52

Discrete Math by R.S. Chang, Dept.

CSIE, NDHU 1
Relations and Functions
Chapter 5
1 to many
1 to 1 many to many
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 2
Chapter 5 Relations and Functions
5.1 Cartesian Products and Relations
Def. 5.1 For sets , , the Cartesian product, or
cross product, of and is denoted by and
equals {( , )| , }.
A B U
A B A B
a b a A b B
e

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

But, in general And A B B A


A A A a a a a A i n
n n i i
=
= e s s
.
{( , , , )| , }.
1 2 1 2
1
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 3
Chapter 5 Relations and Functions
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}

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 4


Chapter 5 Relations and Functions
5.1 Cartesian Products and Relations
Trees are convenient tools for enumeration.
Ex. 5.4 At the Wimbledon Tennis Championships, women play
at 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
E
N
E
Therefore, 6 ways.
(
, )
permutations of NNE and EEN:
3!
2!
for men:
5!
3! 2!
=

= 2 6 2 20
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 5
Chapter 5 Relations and Functions
5.1 Cartesian Products and Relations
. on
a called is of subset Any . to from
a called is of subset any , , sets For 5.2 Def.
A relation
binary A A B A relation
B A U B A

e
In general, for finite sets A,B with |A|=m and |B|=n, there
are 2
mn
relations from A to B, including the empty relation
as 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 R
or 1R2, 7R11 (infix notation)
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 6
Chapter 5 Relations and Functions
5.1 Cartesian Products and Relations
Theorem 5.1 For any set , , :
(a)
b)
(c)
(d) ( ) = ( ) ( )
Proof of (a): For any , , ( , ) ( )
A B C U
A B C A B A C
A B C A B A C
A B C A C B C
A B C A C B C
a b U a b A B C a A
b B C a A b B b C a b A B
a b A C a b A B A
_
=
=
=

e e e .
e e e e e
e e
( ) ( ) ( )
( ( ) ( ) ( )
( ) ( ) ( )
( ) , , ( , ) ( ),
( , ) ( ) ( , ) ( ) ( C)
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 7
Chapter 5 Relations and Functions
5.2 Functions: Plain and One-to-One
Def. 5.3 For nonempty sets, A,B, a function, or mapping, f from
A to B, denoted f:A B, is a relation from A to B in which every
element of A appears exactly once as the first component of an
ordered pair in the relation.

set A
set B
not allowed
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 8
Chapter 5 Relations and Functions
5.2 Functions: Plain and One-to-One
Def 5.4 Domain, Codomain, Range
a
b
f(a)=b
domain codomain
range
A B
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 9
Chapter 5 Relations and Functions
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 function
f x x x
b ceiling function
f x x x
c trunc function
trunc x x
trunc trunc trunc
d A a n n
a a a a
ij n n
n
= =
= = =
= =
= = =
=
= = =
=

38 3 38 4 3 3
38 4 38 3 3 3
38 3 38 3 3 3
11 12 1 21
a a a
f a initial i n j
a a a a a a a
f a initial j n i
n nn
ij
n n nn
ij
2 31
11 21 1 12 2 13
1 1
1 1
, , ,
( ) ( ) ( )
, , , , , , , , ,
( ) ( ) ( )


= + +
= + +
column major storage:
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 10
Chapter 5 Relations and Functions
5.2 Functions: Plain and One-to-One
If |A|=m, |B|=n, then the number of possible functions from A
to B is n
m
.
Def 5.5 A function f:A B is called one-to-one, or injective, if
each 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 a
1
f A B A B
A B A B f A B
a A f a f a a a

s
e = =
| | | |.
, , ( ) ( ) .
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 0
4
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 11
Chapter 5 Relations and Functions
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 s
Def. 5.6 If : and then
( for some and
( is called the image of under .
1
1
f A B A A
f A b B b f a a A
f A A f
_
= e = e
,
) { | ( ), }
)
1 1
1
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 x
g g g
g A
g A

=
=
2
1
1
21
0 4
.
[ , ]
) [ , ].

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 12
Chapter 5 Relations and Functions
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
1
1
1 1
2 2
f A B A A A
f A A f A f A
f A A f A f A
f A A f A f A f
b B b f A A
a A A b f a b f a a A b f a
a A b f A b f A b f A
_
=
_
=
e e
e e
e e e e
, .
) ( ) ( )
) ( ) ( )
) ( ) ( )
)
, )
) ( ( )) )) ( )
2
1 2 1 2
2 1 2
2 1 2
1 2
2
1 1
f A
b f A f A b f A b f A
a A b f a a A b f a
a A A b f a b f A A
( )
) ( ) ( ) )
( , ,
, ).
2
2 1
1 1 1 2 2 2
1 2 1 2
Conversely, ( or (
for some = ( )) or (for some = ( ))
for some = ( ) (
1 2
e e e
e e
e e
1 2 3
a
b
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 13
Chapter 5 Relations and Functions
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 surjective
f A B b B a A
f a b

e e
Ex 5.19 f:R R defined by f(x)=x
3
is onto. But f(x)=x
2
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 to
possibly exist we must have |A| |B|. But how many onto
functions are there?
>

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 14
Chapter 5 Relations and Functions
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 onto
functions from to .
2
| |
m
A x y z B
f A B f x y z
f x y z B
A B
A m B
A B
A
=
= = =
>
1
3
1 1 1
2 2 2 2 2 2 6
2
{( , ), ( , ), ( , )}
{( , ), ( , ), ( , )}.
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 15
Chapter 5 Relations and Functions
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 3
4
functions
from A to B. Among all functions:
(1) {1} is not mapped: 2
4
functions from A to {2,3}
(2) {2} is not mapped: 2
4
functions from A to {1,3}
(1) {3} is not mapped: 2
4
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
3
3
2
2
3
1
1 36
3
3
2
2
3
1
1
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?)
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 16
Chapter 5 Relations and Functions
5.3 Onto Functions: Stirling Number of the Second Kind
General formula
For finite sets , with | | = and | | = , there are A B A m B n
n
n
n
n
n
n
n
n
n
n n n
n k
n k
n
n k
n k
m m m
n m n m k m
k
n
k m
k
n
|
\

|
.
|

|
\

|
.
|
+

|
\

|
.
|

+
|
\

|
.
|
+
|
\

|
.
|
=

|
\

|
.
|

|
\

|
.
|

=
1
1
2
2
1
2
2 1
1
1 1
1
2 1
0
1
0
( ) ( )
( ) ( ) ( ) ( )
( ) ( )

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 17


Chapter 5 Relations and Functions
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
4
4
4
3
3
4
2
2
4
1
1 8400
7 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?
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 18
Chapter 5 Relations and Functions
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/4
7
=8400/16384>0.5
(5) For positive integers m,n with m<n, prove that
( ) ( )

|
\

|
.
|

=
=
1 0
0
k m
k
n
n
n k
n k
(6) For every positive integer n, verify that
n
n
n k
n k
k m
k
n
! ( ) ( ) =

|
\

|
.
|

=
1
0
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 19
Chapter 5 Relations and Functions
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 least
one 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)
( ) ( )

|
\

|
.
|

=
=
1
3
3
3 540
0
3
6 k
k
k
k
case 2: person1 gets more than one job
onto functions from 6 elements to 4 elements (persons)
( ) ( )

|
\

|
.
|

=
=
1
4
4
4 1560
0
4
6 k
k
k
k
540+1560
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 20
Chapter 5 Relations and Functions
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
( ) ( )

|
\

|
.
|

=
1
0
k m
k
n
n
n k
n k
If the containers are identical:
1
1
0
n
n
n k
n k
k m
k
n
!
( ) ( )

|
\

|
.
|

=
S(m,n): Stirling number of the second kind
n!S(m,n) onto functions
Ex. 5.27 distribute m distinct objects into n identical containers
with empty containers allowed

=
n
i
) i , m ( S
1
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 21
Chapter 5 Relations and Functions
5.3 Onto Functions: Stirling Number of the Second Kind
Theorem 5.3 Let , be positive integers with < .
Then ( + , ) = ( , - ) + ( , ).
m n n m
S m n S m n nS m n
1
1 1
s
A a a a a
m m
= {
1
, , , , }
2 1

+
Proof:

n identical containers
S(m+1,n)
a
m+1
is alone in one container a
m+1
is not alone in one container
S(m,n-1)
Distribute other n objects first
into n containers. Then a
m+1
can
be put into one of them.
nS(m,n)
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 22
Chapter 5 Relations and Functions
5.3 Onto Functions: Stirling Number of the Second Kind
Ex. 5.28 How many ways to factorize 30030 into at least two
factors (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 m
m
i
i S n i
n
i
m
, , ( !) ( , ) e =
|
\

|
.
|

=
Z
+
1
Proof: m
n
: 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
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 23
Chapter 5 Relations and Functions
5.4 Special Functions
Def 5.10 For any nonempty subset , , any function ::
is called a on . If , then the binary operation
is 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 binary
operation 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 B
binary operation A B A
A
g A A unary monary
A
f f a b a b
g g a b a b g
h h a a

_



1 .
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 24
Chapter 5 Relations and Functions
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 both
commutative and associative.
(b) :Z Z Z with ( , ) = | | . Then (3,-2) = 6 (-2,3).
is not commutative. But (
f A A B f A
f f a b f b a a b A A
B A f f
a 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 h
h

e
_
e

=
3
(
h a b c h a b c a b c
h 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 but
not associatve. g(g(3.2,4.7),6.4) =15 but g(3.2, g(4.7,6.4)) =16
,
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 25
Chapter 5 Relations and Functions
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 16
A a b c d A A
f A A A
A


a b c d
a
b
c
d
4
4
4
6
6 entries
Therefore, 4 4
6 4

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 26


Chapter 5 Relations and Functions
5.4 Special Functions
Def. 5.13 Let : be a binary operation on . An
element is called an for if ( , ) = ( , )
= , for all .
Ex. 5.34 (a) :Z Z Z with ( , ) = + has identity
element 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 A
x A identity element f f a x f x a
a a A
f f a b a b
f a f a a a
f f a b a b
A g A A A
g a b a b g a
g a a

e
e



0 0
7
min
he identity element of . g
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 27
Chapter 5 Relations and Functions
5.4 Special Functions
Theorem 5.4 Let : be a binary operation. If has an
identity, then that identity is unique.
Proof: If are identities, then ( and
( Therefore,
f A A B f
x x f x x x
f x x x x x

=
= =
1 2 1 2 1
1 2 2 1 2
, , )
, ) . .
identity identity
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 28
Chapter 5 Relations and Functions
5.4 Special Functions
A a a a f A A A
n
= { , , , }, :
1 2

a
1
a
2
a
3
. . . a
n
a
1

a
2

a
3

.
.
.
a
n
n
2
entries, each has n choices
n
n
2
closed binary operations
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 29
Chapter 5 Relations and Functions
5.4 Special Functions
A a a a f A A A
n
= { , , , }, :
1 2

n entries
n n
2
2

entries


n n
n
n n
2
2
commutative closed binary operations
a
1
a
2
a
3
. . . a
n
a
1

a
2

a
3

.
.
.
a
n
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 30
Chapter 5 Relations and Functions
5.4 Special Functions
A a a a f A A A
n
= { , , , }, :
1 2

If a
1
is the identity
a
1
a
2
a
3
. . . a
n
a
2
a
3
. . . a
n
a
1

a
2

a
3

.
.
.
a
n
a
1

a
2

a
3

.
.
.
a
n
n n
2
2 1 ( ) entries

|
\

|
.
|
+
n
n n
n n
1
1 1 1
2 2
( ) ( )
= closed binary operations
with an identity
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 31
Chapter 5 Relations and Functions
5.4 Special Functions
A a a a f A A A
n
= { , , , }, :
1 2

If a
1
is the identity
a
1
a
2
a
3
. . . a
n
a
2
a
3
. . . a
n
a
1

a
2

a
3

.
.
.
a
n
a
1

a
2

a
3

.
.
.
a
n
n-1 entries
( ) ( ) n n 1 1
2
2
entries
( )

|
\

|
.
|
|
\

|
.
|
|
|
=

+
n
n n n
n
n n n n
1
1
1 1
2
2
2
2 2
( ) ( )
commutative
closed binary operations with an identity
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 32
Chapter 5 Relations and Functions
5.4 Special Functions
Def. 5.14 For sets and , if , then
defined by is called the on the first
coordinate. is defined similarly. (used in relational databases)
Ex. 5.36 For = = Z, let = {( , )| =| |}, Z and
N.
A B D A B D A
a b a projection
A B D x y y x D
D
A
A
B
A
B
_
=
=
= =
t
t
t
t
t
: ,
( , ) ,
( )
( ) { , , , , . . .} 012 3
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 33
Chapter 5 Relations and Functions
5.5 The Pigeonhole Principle
The Pigeonhole Principle: If m pigeons occupy n pigeonholes and
m>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 lower
lowercase letters. Can it be that they are all different?
The number of different possible words is
26
At least one word must be repeated.
4
+ + + = <

26 26 26 475254 500000
3 2
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 34
Chapter 5 Relations and Functions
5.5 The Pigeonhole Principle
Ex. 5.43 Let Z where | | = 37. Then contains two
elements 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 r
S
S
x S x y k
y T T
a y b y a b b a
k
m n
c
= + s <
e >
e =
=
,
,
, .
36 0 36
2
2 2

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 35


Chapter 5 Relations and Functions
5.5 The Pigeonhole Principle
Ex. 5.44 Any subset of size six from the set S={1,2,3,...,9} must
contain two elements whose sum is 10.
pigeonholes: {1,9},{2,8},{3,7},{4,6},(5}
pigeons: six of them
Therefore, at two elements must be from the same subset.
Ex. 5.45 Triangle ACE is equilateral with AC=1. If five points are
selected from the interior of the triangle, there are at least two whose
distance apart is less than 1/2.
region 1 region 2 region 3 region 4 4 pigeonholes
5 pigeons
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 36
Chapter 5 Relations and Functions
5.5 The Pigeonhole Principle
Ex. 5.46 Let S be a set of six positive integers whose maximum
is at most 14. Show that the sums of the elements in all the
nonempty 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 s s + + + = S
A

, and there are
2
6
-1=63 nonempty subsets of S. (two many pigeonholes!)
Consider the subset of less than 6 elements.
pigeonholes=10+11+...+14=60
pigeons=2
6
-1-1=62
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 37
Chapter 5 Relations and Functions
5.5 The Pigeonhole Principle
. m . ) m m
). ( m ) q q ( q , q
, r m q r m q
m t s
t s .
, , , , m
. m n
there m
s t s
s t s s t
t s
t s
m
m
n
1 2 | Hence 1 2 , gcd( odd, is
Since 1 2 2 2 2 So N. for
1 2 and 1 2 Hence m. by division upon
remainder same the have 1 2 and 1 2 where 1, + < 1
with Z , exists there principle, pigeonhole By the 1 2
1 2 1 2 1 2 integers positive 1 + he Consider t : Proof
1 2 divides such that integer
positive a exists that Prove odd. m with Z Let 5.47 Ex.
-
1 2 2 1
2 1
+ 1
2 1
+
=
= = e
+ = + =
s s
e

+

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 38
Chapter 5 Relations and Functions
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 during
which 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 be
the same. Hence there exist 1 < 28 with
From day +1 to the end of day , exactly 15 sets are played.
s s
s < < < s
+ < + < < + s + =
s s = +
i x
x x x
x x x
j i x x
j i
i
i j
1 2 28
1 2 28
40
15 15 15 40 15 55
15

,
.
.
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 39
Chapter 5 Relations and Functions
5.6 Function Composition and Inverse Functions
Inverse of addition: and -
Inverse of multiplication: and 1/
u u
u u
Def 5.15 If f:A B, then f is said to be bijective, or to be a
one-to-one correspondence, if f is both one-to-one and onto.

1
2
3
4
w
x
y
z
A
B
must be |A|=|B|
(if )
but could be
Ex. 5.50
=
A B B A _ _ or
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 40
Chapter 5 Relations and Functions
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 A
A A a a
a A A
f g A B f g
f g f a g a a A
f g f x x g x x
f g f g
f g
f x
x if x Z
x if x R Z
g x x
: , ( )
,
=
e

e
e
=

e
+ e

1
1
, for all R, then = . x f g e
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 41
Chapter 5 Relations and Functions
5.6 Function Composition and Inverse Functions
Def. 5.18 If : and : , we define the composite
function, which is denoted : , by ( )( ) = ( ( )),
for each .
f A B g B C
g f A C g f a g f a
a A

e

Ex. 5.53
1
2
3
4
A
B
C
a
b
c
w
x
y
z
f
g
( )( ) ( ( )) ( ) , ( ) , ( ) , g f g f g a x gf x gf y 1 1 2 3 = = = = = gf(4) = z
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 42
Chapter 5 Relations and Functions
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 C
f g g f
f g g f
= +
= +

2
2 2
2
5
5 5
5
, ( ) .
)
.

A
B C
f
g
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 43
Chapter 5 Relations and Functions
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 f
h g f
= + =
+ = + =
+ + = =

2
2 2 2
2 2
5
2 5
5 2
, ( ) , ( )
. ) ( )
( ) ( ( ))( ) ( ( ( )))




A
B C
f
g
D
h
gf
hg
h(gf)
(hg)f
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 44
Chapter 5 Relations and Functions
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 a
function : 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 invertible
g B A g f f g
n n
n
A B
= e
=

= =
= = >

+
, ,
( ).
{( , ), ( , ), ( , ), ( , )},
{( , ), ( , ), ( , ), ( , )} ,
1
2
3
12 2 2 32 41
12 2 2 32 4 2 3
1 1


A B
f
g
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 45
Chapter 5 Relations and Functions
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 B
h B A f h f
f h h h h f g h f g
g g
A
B B
A

+ =
= + =

= = =
=
2 5
1
2
5
2 5
1
2
2 5 5
1
2
5
2
1
2
5 5
1
1 1
1
( ).
( ) ( ))
[ ( )] .
. ( ) ( )
.
(

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


-1
f f
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 46
Chapter 5 Relations and Functions
5.6 Function Composition and Inverse Functions
Theorem 5.8 A function : is invertible if and only if
it 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 y
m
x b f x
m
x b
c

= = + = = + = = +
= = =


1 1
1
1 1
.
{( , )| } {( , )| } {( , )| }
{( , )| ( )}. ( ) ( )
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 47
Chapter 5 Relations and Functions
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 B
A B
f
f
f
x c x y
1
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 48
Chapter 5 Relations and Functions
5.7 Computational Complexity
problem algorithm 1
algorithm 2

algorithm k
Which one is best?
We need measures.
time-complexity or space-complexity
a function f(n) where n is the size of the input
lower bounds, best cases, average cases, worst cases
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 49
Chapter 5 Relations and Functions
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 k
f O g g g

e e
s e >
e
,
Big-Oh Form Name
O(1) constant
O(log
2
n) Logarithmic
O(n) Linear
O(nlog
2
n) nlog
2
n
O(n
2
) Quadratic
O(n
3
) Cubic
O(n
m
),m=0,1,2,3,... Polynomial
O(c
n
),c>1 Exponential
O(n!) Factorial
Discrete Math by R.S. Chang, Dept. CSIE, NDHU 50
Chapter 5 Relations and Functions
5.7 Computational Complexity
18 10
19
. ~ ~ microseconds 2.14 10 days 5845 centuries
8
Order of Complexity
problem size n log
2
n n nlog
2
n n
2
2
n
n!
2

16
64
1 2 2 4 4 2
4 16 64 256 6.5 10
4
2.1 10
13
6 64 384 4096 1.84 10
19
>10
89

Discrete Math by R.S. Chang, Dept. CSIE, NDHU 51


Chapter 5 Relations and Functions
Summaries (m objects, n containers)
Objects Containers Some Number
Ar Are Containers of
Distinct Distinct May Be Empty Distributions

Yes Yes Yes
Yes Yes No
Yes No Yes
Yes No No
No Yes Yes
No Yes No
n
n S m n
S m S m S m n
S m n
n m
m
n m n
m n
m
m n
m
n
m
! ( , )
( , ) ( , ) ( , )
( , )
( )
1 2
1
1 1 1
1
+ + +
+
|
\

|
.
|
+

|
\

|
.
|
=

|
\

|
.
|
=

|
\

|
.
|

Put one object in each container first.


Discrete Math by R.S. Chang, Dept. CSIE, NDHU 52
Chapter 5 Relations and Functions
Exercise. P230:27
P237: 6,18
P244: 14
P249: 18,20

Você também pode gostar