33
1 Functions Functions CS/APMA 202 CS/APMA 202 Rosen section 1.8 Rosen section 1.8 Aaron Bloomfield Aaron Bloomfield

Functions

Embed Size (px)

DESCRIPTION

Functions. CS/APMA 202 Rosen section 1.8 Aaron Bloomfield. Definition of a function. A function takes an element from a set and maps it to a UNIQUE element in another set. Function terminology. f maps R to Z. f. R. Z. Co-domain. Domain. f(4.3). 4. 4.3. Pre-image of 4. - PowerPoint PPT Presentation

Citation preview

Page 1: Functions

11

FunctionsFunctions

CS/APMA 202CS/APMA 202

Rosen section 1.8Rosen section 1.8

Aaron BloomfieldAaron Bloomfield

Page 2: Functions

22

Definition of a functionDefinition of a function

A function takes an element from a set A function takes an element from a set and maps it to a UNIQUE element in and maps it to a UNIQUE element in another setanother set

Page 3: Functions

33

Function terminologyFunction terminology

R Zf

4.3 4

Domain Co-domain

Pre-image of 4 Image of 4.3

f maps R to Z

f(4.3)

Page 4: Functions

44

More functionsMore functions

1

2

3

4

5

“a”

“bb“

“cccc”

“dd”

“e”

A string length function

A

B

C

D

F

Alice

Bob

Chris

Dave

Emma

A class grade function

Domain Co-domainA pre-image

of 1

The imageof A

Page 5: Functions

55

Even more functionsEven more functions

1

2

3

4

5

“a”

“bb“

“cccc”

“dd”

“e”

Not a valid function!Also not a valid function!

1

2

3

4

5

a

e

i

o

u

Some function…

Range

Page 6: Functions

66

Function arithmeticFunction arithmetic

Let fLet f11(x) = 2x(x) = 2x

Let fLet f22(x) = x(x) = x22

ff11+f+f22 = (f = (f11+f+f22)(x) = f)(x) = f11(x)+f(x)+f22(x) = 2x+x(x) = 2x+x22

ff11*f*f22 = (f = (f11*f*f22)(x) = f)(x) = f11(x)*f(x)*f22(x) = 2x*x(x) = 2x*x22 = 2x = 2x33

Page 7: Functions

77

One-to-one functionsOne-to-one functions

1

2

3

4

5

a

e

i

o

A one-to-one function

1

2

3

4

5

a

e

i

o

A function that is not one-to-one

A function is one-to-one if each element in A function is one-to-one if each element in the co-domain has a unique pre-imagethe co-domain has a unique pre-image

Page 8: Functions

88

More on one-to-oneMore on one-to-one

Injective is synonymous with one-to-oneInjective is synonymous with one-to-one ““A function is injective”A function is injective”

A function is an injection if it is one-to-oneA function is an injection if it is one-to-one

Note that there can Note that there can be un-used elements be un-used elements in the co-domainin the co-domain

1

2

3

4

5

a

e

i

o

A one-to-one function

Page 9: Functions

99

Onto functionsOnto functions

1

2

3

4

5

a

e

i

o

A function that is not onto

A function is onto if each element in the A function is onto if each element in the co-domain is an image of some pre-imageco-domain is an image of some pre-image

1

2

3

4

a

e

i

o

u

An onto function

Page 10: Functions

1010

1

2

3

4

a

e

i

o

u

An onto function

More on ontoMore on onto

Surjective is synonymous with ontoSurjective is synonymous with onto ““A function is surjective”A function is surjective”

A function is an surjection if it is ontoA function is an surjection if it is onto

Note that there can Note that there can be multiply used be multiply used elements in the elements in the co-domainco-domain

Page 11: Functions

1111

Onto vs. one-to-oneOnto vs. one-to-oneAre the following functions onto, one-to-Are the following functions onto, one-to-one, both, or neither?one, both, or neither?

1

2

3

4

a

b

c

1

2

3

a

b

c

d

1

2

3

4

a

b

c

d

1

2

3

4

a

b

c

d

1

2

3

4

a

b

c

1-to-1, not onto

Onto, not 1-to-1

Both 1-to-1 and onto Not a valid function

Neither 1-to-1 nor onto

Page 12: Functions

1313

BijectionsBijections

Consider a function that isConsider a function that isboth one-to-one and onto:both one-to-one and onto:

Such a function is a one-to-one Such a function is a one-to-one correspondence, or a bijectioncorrespondence, or a bijection

1

2

3

4

a

b

c

d

Page 13: Functions

1414

Identity functionsIdentity functions

A function such that the image and the A function such that the image and the pre-image are ALWAYS equalpre-image are ALWAYS equal

f(x) = 1*xf(x) = 1*x

f(x) = x + 0f(x) = x + 0

The domain and the co-domain must be The domain and the co-domain must be the same setthe same set

Page 14: Functions

1515

Inverse functionsInverse functions

R Rf

4.3 8.6

Let f(x) = 2*x

f-1

f(4.3)

f-1(8.6)

Then f-1(x) = x/2

Page 15: Functions

1616

More on inverse functionsMore on inverse functions

Can we define the inverse of the following Can we define the inverse of the following functions?functions?

An inverse function can ONLY be done defined An inverse function can ONLY be done defined on a bijectionon a bijection

1

2

3

4

a

b

c

1

2

3

a

b

c

d

What is f-1(2)?Not onto!

What is f-1(2)?Not 1-to-1!

Page 16: Functions

1717

Compositions of functionsCompositions of functions

Let (f ○ g)(x) = f(g(x))Let (f ○ g)(x) = f(g(x))

Let f(x) = 2x+3Let f(x) = 2x+3 Let g(x) = 3x+2Let g(x) = 3x+2

g(1) = 5, f(5) = 13g(1) = 5, f(5) = 13

Thus, (f ○ g)(1) = f(g(1)) = 13Thus, (f ○ g)(1) = f(g(1)) = 13

Page 17: Functions

1818

Compositions of functionsCompositions of functions

g f

f ○ g

g(a) f(a)

(f ○ g)(a)

g(a)f(g(a))a

A B C

Page 18: Functions

1919

Compositions of functionsCompositions of functions

g f

f ○ g

g(1) f(5)

(f ○ g)(1)

g(1)=5

f(g(1))=131

R R R

Let f(x) = 2x+3 Let g(x) = 3x+2

f(g(x)) = 2(3x+2)+3 = 6x+7

Page 19: Functions

2020

Compositions of functionsCompositions of functions

Does f(g(x)) = g(f(x))?Does f(g(x)) = g(f(x))?

Let f(x) = 2x+3Let f(x) = 2x+3 Let g(x) = 3x+2Let g(x) = 3x+2

f(g(x)) = 2(3x+2)+3 = 6x+7f(g(x)) = 2(3x+2)+3 = 6x+7

g(f(x)) = 3(2x+3)+2 = 6x+11g(f(x)) = 3(2x+3)+2 = 6x+11

Function composition is not commutative!Function composition is not commutative!

Not equal!

Page 20: Functions

2121

Graphs of functionsGraphs of functions

Let f(x)=2x+1

Plot (x, f(x))

This is a plotof f(x)

x=1

f(x)=3

x=2

f(x)=5

Page 21: Functions

2222

Useful functionsUseful functions

Floor: Floor: xx means take the greatest integer means take the greatest integer less than or equal to the numberless than or equal to the number

Ceiling: Ceiling: xx means take the lowest integer means take the lowest integer greater than or equal to the numbergreater than or equal to the number

round(x) = floor(x+0.5)round(x) = floor(x+0.5)

Page 22: Functions

2323

Rosen, question 8 (§1.8)Rosen, question 8 (§1.8)

Find these valuesFind these values

1.11.11.11.1-0.1-0.1-0.1-0.12.992.99-2.99-2.99½+½+½½½½ + + ½½ + ½ + ½

1122-1-10033-2-2½+1½+1 = = 3/23/2 = 1 = 10 + 1 + ½0 + 1 + ½ = = 3/23/2 = 2 = 2

Page 23: Functions

2424

Ceiling and floor propertiesCeiling and floor properties

Let n be an integerLet n be an integer(1a)(1a) xx = n if and only if n ≤ x < n+1 = n if and only if n ≤ x < n+1(1b)(1b) xx = n if and only if n-1 < x ≤ n = n if and only if n-1 < x ≤ n(1c)(1c) xx = n if and only if x-1 < n ≤ x = n if and only if x-1 < n ≤ x(1d)(1d) xx = n if and only if x ≤ n < x+1 = n if and only if x ≤ n < x+1(2)(2) x-1 < x-1 < xx ≤ x ≤ = ≤ x ≤ = xx < x+1 < x+1 (3a)(3a) -x-x = - = - xx(3b)(3b) -x-x = - = - xx(4a)(4a) x+nx+n = = xx+n +n (4b)(4b) x+nx+n = = xx+n+n

Page 24: Functions

2525

Ceiling property proofCeiling property proof

Prove rule 4a: Prove rule 4a: x+nx+n = = xx+n+n Where n is an integerWhere n is an integer Will use rule 1a: Will use rule 1a: xx = n if and only if n ≤ x < = n if and only if n ≤ x <

n+1n+1

Direct proof!Direct proof! Let m = Let m = xx Thus, m ≤ x < m+1 (by rule 1a)Thus, m ≤ x < m+1 (by rule 1a) Add n to both sides: m+n ≤ x+n < m+n+1Add n to both sides: m+n ≤ x+n < m+n+1 By rule 4a, m+n = By rule 4a, m+n = x+nx+n Since m = Since m = xx, m+n also equals , m+n also equals xx+n+n Thus, Thus, xx+n = m+n = +n = m+n = x+nx+n

Page 25: Functions

2626

FactorialFactorial

Factorial is denoted by n!Factorial is denoted by n!

n! = n * (n-1) * (n-2) * … * 2 * 1n! = n * (n-1) * (n-2) * … * 2 * 1

Thus, 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720Thus, 6! = 6 * 5 * 4 * 3 * 2 * 1 = 720

Note that 0! is defined to equal 1Note that 0! is defined to equal 1

Page 26: Functions

2727

Proving function problemsProving function problems

Rosen, question 32, §1.8Rosen, question 32, §1.8

Let Let ff be a function from A to B, and let S be a function from A to B, and let S and T be subsets of A. Show thatand T be subsets of A. Show that

)()()( )

)()()( )

TfSfTSfb

TfSfTSfa

Page 27: Functions

2828

Proving function problemsProving function problems

Rosen, question 32 (a): f(SUT) = f(S) U f(T)Rosen, question 32 (a): f(SUT) = f(S) U f(T)Will show that each side is a subset of the otherWill show that each side is a subset of the otherTwo cases!Two cases!Show that f(SUT) Show that f(SUT) f(S) U f(T) f(S) U f(T)

Let b Let b f(SUT). Thus, b=f(a) for some a f(SUT). Thus, b=f(a) for some aS U TS U T Either aEither aS, in which case bS, in which case bf(S)f(S) Or aOr aT, in which case bT, in which case bf(T)f(T) Thus, bThus, bf(S) U f(T)f(S) U f(T)

Show that f(S) U f(T) Show that f(S) U f(T) f(S U T) f(S U T) Let b Let b f(S) U f(T) f(S) U f(T) Either b Either b f(S) or b f(S) or b f(T) (or both!) f(T) (or both!) Thus, b = f(a) for some a Thus, b = f(a) for some a S or some a S or some a T T In either case, b = f(a) for some a In either case, b = f(a) for some a S U T S U T

Page 28: Functions

2929

Proving function problemsProving function problems

Rosen, question 32 (b): f(S∩T) Rosen, question 32 (b): f(S∩T) f(S) ∩ f(T) f(S) ∩ f(T)

Let b Let b f(S∩T). Then b = f(a) for some a f(S∩T). Then b = f(a) for some a S∩T S∩T

This implies that a This implies that a S and a S and a T T

Thus, b Thus, b f(S) and b f(S) and b f(T) f(T)

Therefore, b Therefore, b f(S) ∩ f(T) f(S) ∩ f(T)

Page 29: Functions

3030

Proving function problemsProving function problems

Rosen, question 62, §1.8Rosen, question 62, §1.8

Let Let ff be an invertible function from Y to Z be an invertible function from Y to Z

Let Let gg be an invertible function from X to Y be an invertible function from X to Y

Show that the inverse of f○g is:Show that the inverse of f○g is: (f○g)(f○g)-1-1 = g = g-1 -1 ○ f○ f-1-1

Page 30: Functions

3131

Proving function problemsProving function problems

Rosen, question 62, §1.8Rosen, question 62, §1.8Thus, we want to show, Thus, we want to show, for all for all zzZ and Z and xxXX

The second equality is similarThe second equality is similar

xxgffg

zzfggf

)(

)(11

11

z

zff

zfggf

zfggf

zfggfzfggf

)(

)(

)(

)()(

1

11

11

1111

Page 31: Functions

32

Quick surveyQuick survey

I felt I understood the material in this I felt I understood the material in this slide set…slide set…

a)a) Very wellVery well

b)b) With some review, I’ll be goodWith some review, I’ll be good

c)c) Not reallyNot really

d)d) Not at allNot at all

Page 32: Functions

33

Quick surveyQuick survey

The pace of the lecture for this The pace of the lecture for this slide set was…slide set was…

a)a) FastFast

b)b) About rightAbout right

c)c) A little slowA little slow

d)d) Too slowToo slow

Page 33: Functions

34

Quick surveyQuick survey

How interesting was the material in How interesting was the material in this slide set? Be honest!this slide set? Be honest!

a)a) Wow! That was SOOOOOO cool!Wow! That was SOOOOOO cool!

b)b) Somewhat interestingSomewhat interesting

c)c) Rather bortingRather borting

d)d) ZzzzzzzzzzzZzzzzzzzzzz