9/8/2011lecture 2.4 -- functions1 lecture 2.4: functions cs 250, discrete structures, fall 2011...

13
9/8/2011 Lecture 2.4 -- Functions 1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag

Upload: david-morgan

Post on 27-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 1

Lecture 2.4: Functions

CS 250, Discrete Structures, Fall 2011

Nitesh Saxena

*Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag

Page 2: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 2

Course Admin HW1

Due at 11am 09/09/11 Please follow all instructions Recall: late submissions will not be accepted

Mid-Term 1 on Thursday, Sep 22 In-class (from 11am-12:15pm) Will cover everything until the lecture on Sep 15

No lecture on Sep 20 As announced previously, I will be traveling to Beijing to

attend and present a paper at the Ubicomp 2012 conference

This will not affect our overall topic coverage This will also give you more time to prepare for the exam

Page 3: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 3

Course Admin HW1 grading potentially delayed

TA/grader is sick with chicken pox We will try to finish it up as soon as

possible. Apologies for the delay. In any case, HW1 solution will be released in

a few days from now. So, you can prepare for your exam without any interruptions

Page 4: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 4

Outline

Functions compositions common examples

Page 5: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 5

Function Composition

When a function f outputs elements of the same kind that another function g takes as input, f and g may be composed by letting g immediately take as an input each output of f

Definition: Suppose that g : A B and f : B C are functions. Then the composite f g : A C is defined by setting

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

f g is also called fog

Page 6: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 6

Composition: Examples

Q: Compute gf where 1. f : Z R, f (x ) = x 2

and g : R R, g (x ) = x 3

2. f : Z Z, f (x ) = x + 1and g = f -1 so g (x ) = x – 1

3. f : {people} {people},f (x ) = the father of x, and g = f

Page 7: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 7

Composition: Examples1. f : Z R, f (x ) = x 2

and g : R R, g (x ) = x 3

gf : Z R , gf (x ) = x 6

2. f : Z Z, f (x ) = x + 1and g = f -1

gf (x ) = x (true for any function composed with its inverse)

3. f : {people} {people},f (x ) = g(x ) = the father of x

gf (x ) = grandfather of x from father’s side

Page 8: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 8

Repeated CompositionWhen the domain and codomain are equal, a function

may be self composed. The composition may be repeated as much as desired resulting in functional exponentiation. The whole process is denoted by

f n (x ) = f f f f … f (x )

where f appears n –times on the right side.Q1: Given f : Z Z, f (x ) = x 2 find f 4

Q2: Given g : Z Z, g (x ) = x + 1 find g n

Q3: Given h(x ) = the father of x, find hn

n

Page 9: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 9

Repeated Composition

A1: f : Z Z, f (x ) = x 2. f 4(x ) = x (2*2*2*2) = x 16

A2: g : Z Z, g (x ) = x + 1 gn (x ) = x + n

A3: h (x ) = the father of x, hn (x ) = x ’s n’th patrilineal ancestor

Page 10: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 10

Composition - a little problemLet f:AB, and g:BC be functions.

Prove that if f and g are one to one, then g o f :AC is one to one.

Recall defn of one to one: f:A->B is 1to1 if f(a)=b and f(c)=b a=c.

Suppose g(f(x)) = y and g(f(w)) = y. Show that x=w.

f(x) = f(w) since g is 1 to 1.

Then x = w since f is 1 to 1.

Page 11: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 11

Commonly Encountered FunctionsPolynomials:

f(x) = a0xn + a1xn-1 + … + an-1x1 + anx0

Ex: f(x) = x3 - 2x2 + 15; f(x) = 2x + 3

Exponentials:f(x) = cdx

Ex: f(x) = 310x, f(x) = ex

Logarithms:log2 x = y, where 2y = x.

Page 12: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 12

Some New functionsCeiling:

f(x) = x the least integer y so that x y.

Ex: 1.2 = 2; -1.2 = -1; 1 = 1

Floor:f(x) = x the greatest integer y so that x y.

Ex: 1.8 = 1; -1.8 = -2; -5 = -5

Quiz: what is -1.2 + 1.1 ? 0

Page 13: 9/8/2011Lecture 2.4 -- Functions1 Lecture 2.4: Functions CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda

9/8/2011 Lecture 2.4 -- Functions 13

Today’s Reading Rosen 2.3