)xqfwlrq 'hilqlwlrqvftang/courses/cs130/notes/functions.pdf&6 ±'lvfuhwh 6wuxfwxuhv...

25
CS 130 – Discrete Structures Section 4.4 Functions

Upload: others

Post on 11-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures

Section 4.4 Functions

Page 2: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 39

Function Definitions

• Let S and T be sets. A function f from S to T, f: S T, is a subset of S x T where each member of S appears exactly once as the first component of an ordered pair.– S is the domain of the function.– T is the codomain of the function.

• If (s, t) belongs to the function, then t is denoted by f(s)– t is the image of s under f– s is a preimage of t under f– f is said to map s to t

Page 3: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 40

Diagrams Representation

• If A and B are finite sets, an arrow diagram shows a function ffrom A to B by drawing an arrow from each element in A to the corresponding element of B

• Two properties must be held in the arrow diagram according to the definition of function:– Every element of A has an arrow coming out of it– No one element of A has two arrows coming out of it that point to

two different elements of B• Example

Page 4: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 41

Examples

• Which of the following are functions?– f: S T where S = T = {1, 2, 3}, f = {(1,1),(2,3),(2,1)}– g: Z N where g(x) = |x| (absolute value of x)– h: N N where h(x) = x – 4– f: R R where f(x) = 4x – 1– more examples from the book

• For f: Z Z where f(x) = x2

– what is the image of –4– what are the preimages of 9

Page 5: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 42

Several Common Math Functions

• Floor function– associates with each real number x the greatest integer

less than or equal to x– E.g., 2.8 = ?, - 2.8 = ?

• Ceiling function– associates with each real number x the smallest integer

greater than or equal to x– E.g, 2.8 = ?, -2.8 = ?

• Modulo function f(x) = x mod n– associates with x the remainder when x is divided by n– we can write x = qn+ r, r is between [0, n-1]– 10 mod 3 = 1

Page 6: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 43

Functions With Multiple Variables

• A function can include more than one variable. A function can be defined as– f: S1 S2 …… Sn T that associates with each

ordered n-tuple of elements (s1, s2, …, sn)– Example: f: Z Z Z is given by f(x,y) = x+y

Page 7: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 44

Properties of Functions: Surjective

• Three properties: surjective (onto), injective, bijective

• Let f: S T be an arbitrary function– every member of S has an image under f and all the images are

members of T– the set R of all such images is called the range of the function f

• A function f: S T is an onto, or surjective, function if the range of f equals the codomain of f

Page 8: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 45

Example of Surjective Functions

• To prove a function to be surjective: need to show that an arbitrary member of the codomain T is a member of the range R, thus it is the image of some member of the domain, we have T R

• To disprove it: if we can find one member of the codomain that is not the image of any member of the domain

• Let f: Q Q where f(x) = 3x + 2• Let g: Z N where g(x) = |x|• Let f: R R where f(x) = 4x – 1

Page 9: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 46

Properties of Functions: Injective, Bijective

• A function f: S T is an one-to-one or injective, if no member of T is the image under f of two distinct elements of S– To prove a function is injective: we assume that

there are elements s1 and s2 of S with f(s1) = f(s2) and then show that s1 = s2

– To disprove it: counterexample, where an element in the range has two preimages in the domain

• A function f: S T is bijective, if it is both surjective and injective

Page 10: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 47

Examples

• The function g: R R where g(x) = x3

– surjective, injective, bijective

• The function f: N N where f(x) = x2

– not surjective, injective, not bijective

Page 11: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 48

In General

Page 12: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 49

• Let and . Then the composition function, , is a function from S to U defined by .– Function f is applied first, and then function g– It is not always possible to take any two arbitrary

functions and compose them since the domain and the ranges have to be compatible.

– Note that composition preserves the properties of being onto and being one-to-one

• Composition on two bijections is a bijection

Composition of Functions

:f S T :g T Ug f

( )( ) ( ( ))g f s g f s

Page 13: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 50

Examples

• Let f: R R be defined by f(x) = x2 and g: R R be defined by g(x) = x– What is the value of (g f) (2.3) ?

• g(f(2.3)) = g(5.39) = 5

– What is the value of (f g) (2.3) ?• f(g(2.3)) = f(2) = 4

– Order is important in function composition

• The following functions map R to R. Give an equation describing the composition functions f g and g f in each case:– f(x) = 3x2, g(x) = 5x

Page 14: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 51

More Examples

• Given the following function, decide whether it is 1-to-1 or onto:

• f: NN, f(x) = x + 1

but 1-to-1

Proof that f is one-to-one.Let f(s1) = f(s2) for s1, s2 .Thens1 + 1 = s2 + 1 definition of fs1 = s2 algebraf is one-to-one

Page 15: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 52

Proofs

• Let f: S T and g: T U, and assume that both f and g are one-to-one (injective) functions. Prove that g f is a one-to-one function.

• Let f: S T and g: T U be functions– Prove that if g f is 1-to-1, so is f.– Prove that if g f is onto, so is g.– Find an example where g f is 1-to-1, but g is not 1-

to-1.– Find an example where g f is onto but f is not onto.

Page 16: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 53

Inverse Functions

• Bijective functions have another property:– Every element s in S has an image in T and every element

of T has a unique inverse image in S since the f is onto and one-to-one

• If there is a function f which has a one-to-one correspondence from a set S to a set T, then there is a function g from T to S that "undoes" the action of f. This function g is called the inverse function for f.

• Then g f (s) = s maps each element to itself. Such a function which leave an element unchanged is called the identity function on S and is denoted by is

• Show that f g = iT

Page 17: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 54

Inverse Functions

• Definition: Let f: S T. If there exists a function g: T S, such that – g f = iS and f g = iT

– Then g is called the inverse function of f and is denoted by f –1

• Example: f: R R given by f(x) = 3x + 4 is a bijection. Describe f –1

• Theorem on Bijections and Inverse Functions:– Let f: S T. Then f is a bijection if and only if f –1

exists

Page 18: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 55

More Proofs

• Let f and g be bijections, f: ST and g: TU. Then f-1 and g-1 exist. Also g f is a bijection from S to U.

Page 19: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 56

Summary of Function Terminologies

Term Meaning

function A function f from set S to set T is a relationship between elements of S and elements of T where each element of S is related to a unique element of T. It is denoted by f: S T.

domain Starting set for a function

codomain Ending set for a function

image Point that results from a mapping

preimage Starting point for a mapping

range Collection of all images of a domain

onto (surjective) Range is the whole codomain; every codomain element has a preimage

one-to-one (injective) No two elements in a domain map to the same place

bijection One-to-one and onto

identity function Maps each element of set to itself

inverse function For a bijection, a new function that maps each codomain element back where it came from

Page 20: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 57

Exercises

• Let S = {0, 2, 4, 6} and T = {1, 3, 5, 7}. Determine whether each of the following sets of ordered pairs is a function with domain S and codomain T. If so, it is 1-to-1? Is it onto?

a. {(0, 2), (2, 4), (4, 6), (6, 0)}b. {(6, 3), (2, 1), (0, 3), (4, 5)}c. {(2, 3), (4, 7), (0, 1), (6, 5)}d. {(2, 1), (4, 5), (6, 3)}e. {(6, 1), (0, 3), (4, 1), (0, 7), (2, 5)}

Page 21: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 58

Exercises

• Which of the following are functions from the domain to the codomain given? Which functions are 1-to-1 or onto or both? Describe the inverse function for any bijective function.

a. f: ZN where f(x) = x2 + 1b. g: NQ where g(x) = 1/xc. h: Z x N Q where h(z, n) = z/(n+1)d. f: {1, 2, 3} {p, q, r} where f = {(1, q), (2, p), (3, r)}e. g: NN where g(x) = 2x

f. h: R2 R2 where h(x, y) = (y + 1, x + 1)

Page 22: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 59

Exercises

• Let P be the power set of {a, b, c}. A function f: PZ follows: for A in P, f(A) = the number of elements in A. – Is f 1-to-1?– Is f onto?

Page 23: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 60

Exercises

• Let f: NN be defined by f(x) = x + 1. Let g: NN be defined by g(x) = 3x. Calculate the following:

a. (gf)(x)

b. (fg)(x)

c. (ff)(x)

d. (gg)(x)

Page 24: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 61

Exercises

• The following functions map R to R. Give an equation describing the composition functions (gf) and (fg) in each case.

a. f(x) = 6x3, g(x) = 2xb. f(x) = (x-1)/2, g(x) = 4x3

c. f(x) = x , g(x) = x

Page 25: )XQFWLRQ 'HILQLWLRQVftang/courses/CS130/notes/functions.pdf&6 ±'LVFUHWH 6WUXFWXUHV )XQFWLRQ 'HILQLWLRQV /HW 6DQG 7EH VHWV $ IXQFWLRQ fIURP 6WR 7 I 6 o7 LV D VXEVHW RI 6 [ 7ZKHUH HDFK

CS 130 – Discrete Structures 62

Exercises

• For each of the following bijections f: RR, and g: R2 R2 find f-1 and g-1.

a. f(x) = 2xb. f(x) = x3

c. f(x) = (x+4)/3d. g(x, y) = (2x, y+1)