11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1

Preview:

Citation preview

11

DISCRETE STRUCTURES

UNIT 5SSK3003

DR. ALI MAMAT1

22

Relations and Functions

Objectives: On completion of this chapter, student should be able to:

1. Define a relation and function2. Determine the type of function (one-to-one,

onto, one-to-one correspondence)3. Find a composite function4. Find an inverse function

33

Contents

1. Cartesian product and relations2. Functions: Plain and One-to-One3. Onto Functions4. Function Composition and inverse functions

4

Relationship

Set

Cartesian Product

Relation

Function

55

RELATIONS AND FUNCTIONS  CARTESIAN PRODUCTS AND RELATIONS Definition 5.1  

For sets A, B, the Cartesian product, or cross product, of A

and B is denoted by A × B and equals {(a, b) | a A, b B}.∈ ∈

Elements of A × B are ordered pairs. For (a, b), (c, d) ∈

A × B , (a, b) = (c, d) if and only if a = c and b = d.

5

RELATIONS AND FUNCTIONSRELATIONS AND FUNCTIONS

666

If A, B are finite, it follows from the rule of product that |A

× B| = |A||B|.

Although we generally will not have A × B = B × A, we

will have |A×B|=|B×A|

Although A, B U, it is not necessary that A × B U. If ⊆ ⊆

(a1, a2, … , an), (b1, b2, ... ,bn) A∈ 1 × A2 × … × An, then

(a1, a2, …. , an) = (b1, b2, … , bn) if and only if ai = bi, ∀

1 ≤ i ≤ n.

77

Example 5.1

Let A = {2, 3, 4}, B = {4, 5}. Then

a) A × B = {(2, 4), (2, 5), (3, 4), (3, 5), (4, 4), (4, 5)}.

b) B × A = {(4, 2), (4, 3), (4, 4), (5, 2), (5, 3), (5, 4)}.

c) B2 = B × B = {(4, 4), (4, 5), (5, 4), (5, 5)}.

d) B3 = B × B × B = {(a, b, c) | a, b, c B}; for instance, ∈

(4, 5, 5) B3.∈

7

88

Example 5.3

An experiment E is conducted as follows:

A single dice is rolled and its outcome noted,

and then a coin is flipped and its outcome noted.

Determine a sample space S for E.

8

99

S1={1, 2, 3, 4, 5, 6} be a sample space dice.

S2= {H, T} be a sample space coin.

Then S = S1 × S2 is a sample space for E. This

sample space can be represented pictorically

with a tree diagram that exhibits all the possible

outcomes of experiment E.

101010

1111

Example 5.4

At the Wimbledon Tennis Championships, women play at most three sets in a match.The winner is the first to win two sets. If we let N and E denote the two players, the tree diagram indicates the six ways in which this match can be won.

For example, the starred line segment (edge) indicates that player E won the first set. The double starred edge indicates that player N has won the match by winning the first and third sets.

11

121212

1313

Definition 5.2 (relation)

For sets A, B, any subset of A × B is called a (binary)

relation from A to B.

Any subset of A × A is called a (binary) relation on

A.

13

1414

Example 5.5From Example 5.1

A = {2, 3, 4}, B = {4, 5}. Then

A × B = {(2, 4), (2, 5), (3, 4), (3, 5), (4, 4), (4, 5)}.The following are some of the relations from A to B.a) ∅b) {(2, 4)}c) {(2, 4), (2, 5)} d) {(2, 4), (3, 4), (4, 4)}e) {(2, 4), (3, 4), (4, 5)}f) A × BSince |A × B| = 6, it follows from Definition 5.2 that there are 26 possible relations from A to Β (for there are 26 possible subsets of A × B ).

14

1515

Example 5.6For B={1,2}, let A=P(B)= { ,{1},{2},{1,2}}.∅ |A×A| = 4.4 = 16.A×A = {( , ),∅ ∅ (∅,{1}),(∅,{2}),(∅,{1,2}), ({1},∅), ({1},{1}), ({1},{2}), ({1},{1,2}) ({2},∅),({2},{1}), ({2},{2}), ({2},{1,2}) ({1,2},∅),({1,2},{1}),({1,2},{2}, ({1,2},{1,2})}

The following is an example of a relation on A: R = {( , ), ( , {1}), ( , {2}), ( , {1, 2}), ({1}, {1}), ({1}, ∅ ∅ ∅ ∅ ∅{1, 2}), ({2}, {2}), ({2}, {1, 2}), ({1, 2}, {1, 2})}.

15

1616

Example 5.7

With A = Z+ (set of positive integers), we may define a relation R on set A as {(x, y) | x ≤ y}.

This is the familiar “is less than or equal to” relation for the set of positive integers.

It can be represented graphically as the set of points, with positive integer components, located on or above the line y = x in the Euclidean plane, as partially shown in the figure below.

16

171717

(7, 7), (7, 11) R∈ (8, 2) R∉

(7, 11) R or 7 R 11 (∈ infix notation)

18

Question

?????

1919

FUNCTIONS: ONE-TO-ONEDefinition 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.

19

2020

Function

2121

We often write f(a) = b when (a, b) is an ordered pair in the function f. For (a, b) f, b is called the ∈image of a under f, whereas a is a preimage of b. The definition suggests that f is a method for associating with each a A ∈ the unique element f (a) = b B. Consequently, (a, b), (a, c) f ∈ ∈implies b = c.

2222

Example 5.9

For A = {1, 2, 3} and B = {w, x, y, z}, f = {(1, w), (2, x), (3,

x)} is a function, and consequently a relation, from A to B.

R1 = {(1, w), (2, x)} and

R2 = {(1, w), (2, w), (2, x), (3, z)} are relations,

but not functions, from A to B. (Why?)

22

2323

Definition 5.4

For the function f: A → B, A is called the domain of f and

B the codomain of f. The subset of B consisting of those

elements that appear as second components in the ordered

pairs of f is called the range of f and is also denoted by f

(A) because it is the set of images (of the elements of A)

under f.

In Example 5.9, f = {(1, w), (2, x), (3, x)}

the domain of f = {1,2,3}, the codomain of f = {w, x, y, z},

and the range of f = f (A) = {w, x}.23

242424

a may be regarded as an input that is transformed by f into the corresponding output, f(a).

2525

Example 5.10

Many interesting functions arise in computer science.

a) A common function encountered is the greatest integer

function, or floor function. This function

f: R → Z, is given by

f (x) = ⎣x ⎦ = the greatest integer less than or equal to x.

Consequently, f (x) = x, if x ∈ Z; and, when x R – Z, f ∈

(x) is the integer to the

immediate left of x on the real number line. For this

function, we find that

25

2626

1) 3.8 = 3, 3 = 3, –3.8 = –4, –3 = –3;⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦

2) 7.1 + 8.2 = 15.3 = 15 = 7 + 8 = 7.1 + 8.2 ; ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦

and

3) 7.7 + 8.4 = 16.1 = 16 ≠ 15 = 7 + 8 = 7.7 + ⎣ ⎦ ⎣ ⎦ ⎣ ⎦

8.4 .⎣ ⎦

26

2727

b) A second function –one related to the floor function in

part (a) –is the ceiling function.

The function g: R → Z is defined by

g(x) = x = the least integer greater than or equal to x.⎡ ⎤

So g (x) = x when x Z, but when x R – Z, then g (x) is ∈ ∈

the integer to the immediate right of x on the real number

line.

27

2828

In dealing with the ceiling function, we find that

1) 3 = 3, 3.01 = 3.7 = 4 = 4 , –3 = –3, –3.01 ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤

= –3.7 = –3;⎡ ⎤

2) 3.6 + 4.5 = 8.1 = 9 = 4 + 5 = 3.6 + 4.5 ; and⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤

3) 3.3 + 4.2 = 7.5 = 8 ≠ 9 = 4 + 5 = 3.3 + 4.2 .⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤

28

2929

c) The function trunc (for truncation) is another integer –

valued function defined on R. This function deletes the

fractional part of a real number. For example, trunc (3.78)

= 3, trunc (5) = 5, trunc (–7.22) = –7. Note that trunc

(3.78) = 3.78 = 3 while trunc (–3.78) = –3.78 = –3.⎣ ⎦ ⎡ ⎤

29

3030

No. of Functions

In Example 5.9 (For A = {1, 2, 3} and B = {w, x, y,

z}, f = {(1, w), (2, x), (3, x)} ) there are 212 =

4096 relations from A to B.

We have examined one function among these

relations, and now we wish to count the total

number of functions from A to B.

3131

For general case, let A, B be nonempty sets with |A| = m, |

B| = n. Consequently, If A = {a1, a2, …, am} and B={b1,b2,

…,bn}, then a typical function f: A → B can be

described by

{(a1, x1), (a2, x2), (a3, x3), …, (am, xm)} – m ordered pairs.

x1 can selected from any of the n elements of B

x2 “

…………………..xm “

In this way, using the rule of product, there are nm = |B||A| functions from A to B. 31

3232

Therefore, for A, B in Example 5.9, there are 43= |B||A|

=64 functions from A to B, and 34 = |A||B| = 81 functions

from B to A. Unlike the situation for relations, we cannot always obtain a function from B to A by simply interchanging the components in the ordered pairs of a function from A to B (or vice versa).Try to interchange the components in the f!For A = {1, 2, 3} and B = {w, x, y, z}, f = {(1, w), (2, x), (3, x)} )

32

3333

Definition 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.

33

3434

3535

3636

One-to-one Function

If f: A → B is one-to-one, with A, B finite, we must

have |A|≤|B|. For arbitrary sets A, B, f: A → B is

one-to-one if and only if for all, a1, a2 A, f (a∈ 1) =

f (a2)

⇒ a1 = a2.

3737

Example 5.13

Consider the function f: R→ R where f (x) = 3x + 7 for all x R. ∈Then for all x1 , x2 , R, we find that∈

f (x1) = f (x2) 3x⇒ 1 + 7 = 3x2 + 7 ⇒ 3x1 = 3x2

⇒ x1 = x2 ,

so the given function f is one-to-one.

37

3838

One-to-one function

On the other hand, suppose that g: R → R is the function defined by g (x) = x4 – x for each real number x. Then

g(0) = (0)4 – 0 = 0 and g(1) = (1)4 – (1) = 1 – 1 = 0.

Consequently, g is not one-to-one, since g(0) = g (1) but 0 ≠ 1 – that is, g is not one to-one because there exist real numbers x1, x2 where g (x1) = g (x2) x⇒ 1 = x2.

3939

Example 5.14Let A = {1, 2, 3} and B = {1, 2, 3, 4, 5}. The function

f = {(1, 1), (2, 3), (3, 4)}is a one-to-one function from A to B;g = {(1, 1), (2, 3), (3, 3)}is a function from A to B, but fails to be one-to-one because g(2) = g(3) = 3 but 2 ≠ 3.

For A, B in the above example there are 215 relations from A to B and 53 of these are functions from A to B. The next question we want to answer is how many functions f: A → B are one-to-one.

39

4040

With A = {a1, a2, a3, …, am}, B = {b1, b2, b3, …, bn}, and m ≤ n , a one-to-one function f: A → B has the form {(a1, x1), (a2, x2), (a3, x3), …, (am, xm)},

where there are n choices for x1 n – 1 choices for x2 n - 2 choices for x3

………..

n–m+1 choices for xm., the number of one-to-one functions from A to B is n(n-1)(n-2)…(n-m+1)=n!/(n-m)!= P(n,m)= P(|B|,|A|)

40

4141

No. of One-to-One Functions

Consequently, for A, B in Example 5.14 (A = {1, 2, 3} and B = {1, 2, 3, 4, 5}), there are

P(5,3) = 5 . 4 . 3 = 60 one-to-one functions f: A → B.

42

Question

?????

4343

Onto Functions:

Definition 5.9

A function f: A→ B is called onto, or surjective, if f (A)=B – that is, if for all b B∈there is at least one a A ∈ with f (a) = b. a b

How to determine whether a function is onto?

43

4444

Onto function

4545

4646

Example 5.19The function f: R → R defined by f(x) = x3 is an onto

function.

if r is any real number in the codomain of f, then the real number 3√r is in the domain of f and f (3√r) = (3√r)3 = r.

e.g. f(3) = 27, f(-3) = -27

Hence the codomain of f = R = range of f, and the function f is onto.

4747

• The function g: R → R, where g(x) = x2 for each real number x, is not an onto function. • In this case, no negative real number appears in the range of g.

• For example, for –9 to be in the range of g, we would have to be able to find a real number r with g(r) = r2 = –9.

• Note, however, that the function h: R → [ 0, +∞ ) defined by h(x) = x2 is an onto function.

47

4848

Example 5.20Consider the function f: Z → Z, where f(x) = 3x + 1 for each x Z. ∈

Here the range of f = {…, –8, –5, –2, 1, 4, 7, …} Z, ⊂so f is not an onto function. E.g. f(x) = 3x + 1 = 8 then x = 7/3. Rational number 7/3 is not an integer –so there is no x in the domain Z with f(x) = 8.

48

4949

On the other hand, each of the functions1) g: Q → Q, where g(x) = 3x + 1 for x Q; and∈2) h: R → R, where h(x) = 3x + 1 for x R∈is an onto function. (Q is a set of rational numbers: a/b)

Furthermore, 3x1 + 1 = 3x2 + 1 3x⇒ 1= 3x2 x⇒ 1 = x2, regardless of whether x1 and x2 are integers, rational numbers, or real numbers.

Consequently, all three of the functions f, g and h are one-to-one.

49

5050

Example 5.21If A = {1, 2, 3, 4} and B = {x, y, z}, thenf1 = {(1, z), (2, y), (3, x), (4, y)} and f2 = {(1, x), (2, x), (3, y), (4, z)} are both functions from A onto B.

However, the function g = {(1, x), (2, x), (3, y), (4,y)} is not onto, because g (A) = {x, y} B.⊂

If A, B are finite sets, then for an onto function f: A → B to possibly exist we must have |A|≥ |B|where |A|=m≥ n= |B|.

*******

50

5151

Function Composition and Inverse FunctionsObjective (Continue)1. Define a relation and function2. Determine the type of function (one-to-one, onto) 3. Find a composite function4. Find an inverse function

51

5252

Contents

1. One-to-one correspondence function2. Composite function3. Inverse function

5353

Function Composition

Definition 5.15If 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.

Example 5.50If A = {1, 2, 3, 4} and B = {w, x, y, z}, then f = {(1,w),(2,x),(3,y),(4, z)} is a one-to-one correspondence from A (on) to B, Why?

f is one-to-one (every element of B appear at most once), and f is onto (f(A) = B)

53

5454

example

A = {1, 2, 3, 4} and B = {w, x, y, z},

and g = {(w, 1), (x, 2), (y, 3), (z, 4)} is a one-to-one

correspondence from B (on) to A.

because g is one-to-one

and g is onto.

5555

Identity Function

Definition 5.16

The function 1A: A → A, defined by 1A (a) = a for all a ∈

A, is called the identity function for A.

It is a function that always returns the same value that was

used as its argument. In terms of equations, the function is

given by f(x) = x.

55

5656

Function equality

When are f and g equal?Definition 5.17If f, g: A → B, we say that f and g are equal and

write f= g, if f (a) = g (a) for all a A.∈Example:Define f: R → R and g: R → R by the following

formulas: f(x) =|x| for all x R∈ g(x) = √x2 for all x R∈ Does f = g? Yes, |x| = √x2 for all x R∈

57

Objectives

1. Define a relation and function2. Determine the type of function (one-to-one,

onto) 3. Find a composite function4. Find an inverse function

5858

Composite FunctionFunction composition is an operation for combining two functions.

Definition 5.18If f: A → B and g: B → C, we define the composite function, which is denoted g o f: A → C, by (g o f ) (a) = g (f (a)), for each a A.∈

(i.e. element a of g is replaced by f(a))

58

5959

Example 5.53

Let A = {1, 2, 3, 4}, B = {a, b, c}, and C = {w, x, y, z} with f: A → B and g: B →

C given by f = {(1, a), (2, a), (3, b), (4, c)} and g = {(a, x), (b, y), (c, z)}. For

each element of A we find:

(g o f) (1) = g (f (1))= g (a) = x

(g o f) (2) = g (f (2))= g (a) = x

(g o f) (3) = g (f (3))= g (b) = y

(g o f) (4) = g (f (4))= g (c) = z

Sog o f = {(1, x), (2, x), (3, y), (4, z)}.

Note: The composition f o g is not defined(domain of f is A and codomain of g is C). 59

Function f

1 ------ a

2 ------ a

3 ------ b

4 ------ c

6060

Example 5.54

Are f o g and g o f equal?Let f: R → R, g: R → R be defined by f (x) = x2,g(x) = x + 5. Then(g o f) (x) = g (f (x)) = g (x2) = x2 + 5,whereas(f o g) (x) = f (g (x)) = f (x+ 5) = (x+ 5)2 = x2 + 10x + 25.Here g o f: R → R and f o g: R → R, but (g o f) (1) = 6 ≠ 36 = (f o g) (1), so even though both composites f o g and g o f can be formed, we do not have f o g = g o f.

60

6161

Consequently, the composition of functions is not, in

general, a commutative operation.

The definition and examples for composite functions (g o f)

required that the

codomain of f = domain of g.

Also, for any f: A → B, we observed that f o 1A = f = 1B o f.

61

6262

Theorem 5.5

Let f: A → B and g: B → C.

a) If f, g are one-to-one, then g o f is one-to-one.

b) If f, g are onto, then g o f is onto.

62

63

Proof:

How to prove a function f is one-to-one?f(x1) = f(x2) → x1 = x2

a) To prove that g o f: A → C is one-to-one, let a1, a2 A with (g o f )(a1) = (g o f∈ ) (a2). Then

(g o f)(a1)=(g o f)(a2) g(f(a⇒ 1)) = g(f(a2)) f(a1) = ⇒f(a2), because g is one-to-one.

Also, f(a1) = f(a2) a⇒ 1 = a2, because f is one-to-one. Consequently, g o f is one-to-one.

6464

b) For g o f: A → C, let z C. Since g is onto, there∈

exists y B with g (y) = z. ∈

With f onto and y B, ∈ there exists x A with f (x) = y.∈

Hence z = g (y) = g ( f (x)) = (g o f ) (x),

so the range of g o f = C = the codomain of g o f, and g o f

is onto.

64

x f(x)=y g(y)=z

A B C

f g

656565

666666

67

Question

?????

6868

Theorem 5.6 (associative property)

If f: A → B, g: B → C, and h: C → D,

then (h o g) o f = h o (g o f ).

Proof:

Since the two functions have the same domain, A, and

codomain, D, the result will follow by showing that for

every x A, ((h o g) o f)(x) = (h o (g o f ))(x). (See the ∈

diagram shown in Fig 5.9).

68

6969

Using the definition of the composite function, we find that

((h o g) o f) (x) = (h o g) (f (x)) = h ( g (f (x))), whereas

(h o (g o f )) (x) = h ((g o f ) (x)) = h (g (f (x))).

Since ((h o g) o f ) (x) = h (g ( f (x))) = (h o ( g o f )) (x), for

each x in A, it now follows that (h o g) o f = h o (g o f).

Consequently, the composition of functions is an

associative operation.69

707070

7171

Converse of relation

Definition 5.20

For sets A, B, if R is a relation from A to B, then the

converse of R, denoted Rc, is the relation from B to A

defined by R = {(b, a)|(a, b) R}.∈

A = {1, 2, 3, 4}, B = {w, x, y},

and R = {(1, w), (2, w), (3, x)},

then Rc = {(w, 1), (w, 2), (x, 3)},

a relation from B to A. 71

7272

Since a function is a relation we can also form the converse

of a function. For the same preceding sets

A, B, let f: A → B where f = {(1, w), (2, x), (3, y), (4, x)}.

Then f c = {(w, 1), (x, 2), (y, 3), (x, 4)}, a relation, but not a

function, from B to A.

What is a condition for converse of a function yields a

function? (f must be invertible)

72

7373

Example 5.57For A = {1, 2, 3} and B = {w, x, y}, let f: A → B be given by f = {(1, w), (2, x), (3, y)}.Then f c = {(w, 1), (x, 2), (y, 3)} is a function from B to A, and we observe that f c o f = 1A and f o f c = 1B.

f c o f(1) = f c(w) = 1f c o f(2) = f c(x) = 2f c o f(3) = f c(y) = 3 f c o f = {(1,1), (2,2), (3,3)} = 1A

73

74

Invertibility

Definition 5.21

If f: A → B, then f is said to be invertible if there is a

function g: B → A such that g o f = 1A and f o g =

1B.

7575

Example 5.58

Let f, g: R → R be defined by

f (x) = 2x + 5,

g (x) = (1/2)(x – 5). Then

(g o f) (x) = g( f (x)) = g (2x + 5) = (1/2)[(2x + 5) – 5] = x,

and (f o g )(x) = f(g (x)) = f((1/2)(x –5))

=2[(1/2)(x– 5)] + 5 = x,

so f o g = 1R and g o f = 1R. Consequently, f and g are both

invertible functions. 75

76

Question

?????

7777

Inverse Function

Theorem 5.7

If a function f: A → B is invertible and a function g: B→A

satisfies g o f = 1A and f o g = 1B, then this function g is

unique.

We shall call the function g the inverse of f and denoted

g = f –1. Theorem 5.7 also implies that f –1 = f c.

77

7878

Theorem 5.8

A function f: A → B is invertible if and only if it is one-to-

one and onto.

Example 5.59

From Theorem 5.8 it follows that the function f1: R → R

defined by f1(x) = x2 is not invertible (it is neither one-to-one

nor onto), but f2: [0, +∞) → [0, +∞) defined by f2(x)

= x2 is invertible with f2–1(x) = √ x .

78

7979

Theorem 5.9

If f: A → B, g: B → C are invertible functions, then

g o f: A → C is invertible and (g o f ) –1 = f –1 o g –1.

Example

Let f:R→ R defined by f(x)=3x+5

f(x) = y, hence f-1(y) = x

79

xy=f(x)

f

f -1

8080

Inverse Function

f(x) = y = 3x + 5x = (y- 5)/3f -1(y) = x, hence f -1(y) = (y-5)/3Rename y by x,f -1(x) = (x-5)/3

8181

Activity

1. Let f: Z→Z be the successor function and let g: Z→Z be the squaring function. Then f(n) = n + 1 for all n ε Z and g(n) = n2 for all n ε Z

a. Find the compositions g o f and f o g. b. Is g o f = f o g? Explain2. Let X = {a,b,c,d} and Y= {u,v,w}, and

suppose f:X → Y is given by {(a,u),(b,v),(c,v),(d,u)}.

Find f o 1X

and 1Y o f

3. f: R → R is defined by f(x) = 4x – 1. Find its inverse function.

8282

8383

END

THANK YOU

Last updated 15/09/2009