Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions Discrete Structure. L62 Functions. Basic-Terms. DEF: A function f : A  B is given by a domain set A, a codomain set B, and a rule which for.

Similar presentations


Presentation on theme: "Functions Discrete Structure. L62 Functions. Basic-Terms. DEF: A function f : A  B is given by a domain set A, a codomain set B, and a rule which for."— Presentation transcript:

1 Functions Discrete Structure

2 L62 Functions. Basic-Terms. DEF: A function f : A  B is given by a domain set A, a codomain set B, and a rule which for every element a of A, specifies a unique element f (a) in B. f (a) is called the image of a, while a is called the pre-image of f (a). The range (or image) of f is defined by f (A) = {f (a) | a  A }.

3 3 Functions Let us take a look at the function f:P  C with P = {Linda, Max, Kathy, Peter} C = {Boston, New York, Hong Kong, Moscow} f(Linda) = Moscow f(Max) = Boston f(Kathy) = Hong Kong f(Peter) = New York Here, the range of f is C.

4 L64 Functions. Basic-Terms. f : Z  R is given by f (x ) = x 2 A1: domain is Z, co-domain is R A2: image of -3 = f (-3) = 9 A3: pre-images of 3: none as  3 isn’t an integer! pre-images of 4: -2 and 2 A4: range is the set of perfect squares f (Z) = {0,1,4,9,16,25,…}

5 L65 Functions and Java Java: Functions are like non-void Java methods. The domain is the parameter type and the codomain is the return type. The image is the return value. EG: int f(double x){ return x<0 ? –1 : ( x>0 ? 1 : 0 ); } The domain is double the codomain is int. Q: What does this function do?

6 L66 One-to-One, Onto, Bijection. Intuitively. Represent functions using “node and arrow” notation: One-to-One means that no clashes occur. BAD:a clash occurred, not 1-to-1 GOOD:no clashes, is 1-to-1 Onto means that every possible output is hit BAD: 3 rd output missed, not onto GOOD:everything hit, onto

7 L67 One-to-One, Onto, Bijection. Intuitively. Bijection means that when arrows reversed, a function results. Equivalently, that both one-to-one’ness and onto’ness occur. BAD:not 1-to-1. Reverse over-determined: BAD:not onto. Reverse under-determined: GOOD:Bijection. Reverse is a function:

8 8 Properties of Functions Is f injective? Yes. Is f surjective? Yes. Is f bijective? Yes. Linda Max Kathy Peter Boston New York Hong Kong Moscow Lübeck Helena

9 L69 One-to-One, Onto, Bijection. Formal Definition. DEF: A function f : A  B is: one-to-one (or injective) if different elements of A always result in different images in B. onto (or surjective) if every element in B is hit by f. I.e., f (A ) = B. a one-to-one correspondence (or a bijection, or invertible) if f is both one-to-one as well as onto. If f is invertible, its inverse f -1 : B  A is well defined by taking the unique element in the pre- image of b, for each b  B.

10 L610 One-to-One, Onto, Bijection. Examples. 1. f : Z  R, f (x ) = x 2 : none 2. f : Z  Z, f (x ) = 2x : 1-1 3. f : R  R, f (x ) = x 3 : 1-1, onto, bijection, inverse is f (x ) = x (1/3) 4. f : Z  N, f (x ) = |x |: onto 5. f (x ) = the father of x : none

11 L611 Composition When a function f spits out elements of the same kind that another function g eats, f and g may be composed by letting g immediately eat each output of f. DEF: 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) )

12 L612 Composition. Examples. Q: Compute g  f where 1.f : Z  R, f (x ) = x 2 and g : R  R, g (x ) = x 3 2. f : Z  Z, f (x ) = x + 1 and g = f -1 so g (x ) = x – 1 3. f : {people}  {people}, f (x ) = the father of x, and g = f

13 L613 Composition. Examples. 1.f : Z  R, f (x ) = x 2 and g : R  R, g (x ) = x 3 f  g : Z  R, f  g (x ) = x 6 2. f : Z  Z, f (x ) = x + 1 and g = f -1 f  g (x ) = x (true for any function composed with its inverse) 3. f : {people}  {people}, f (x ) = g(x ) = the father of x f  g (x ) = grandfather of x from father’s side

14 14 Composition Example: f(x) = 7x – 4, g(x) = 3x, f:R  R, g:R  R (f  g)(5) = f(g(5)) = f(15) = 105 – 4 = 101 (f  g)(x) = f(g(x)) = f(3x) = 21x - 4

15 Ceiling and Floor DEF: Given a real number x : The floor of x is the biggest integer which is smaller or equal to x The ceiling of x is the smallest integer greater or equal to x. NOTATION: floor(x) =  x , ceiling(x) =  x  Q: Compute  1.7 ,  -1.7 ,  1.7 ,  - 1.7 .

16 L616 Ceiling and Floor A:  1.7  = 1,  -1.7  = -2,  1.7  = 2,  -1.7  = -1 Q: What’s the difference between the floor function and the (int) casting function in Java?

17 a0a0 a1a1 a2a2 anan a n-1 a 0 =0 a 1 =2 a 2 =6 a 3 =12 a 4 =20

18 Recursive Definitions F(0) = 0; F(n + 1) = F(n) + 1; F(0) = 1; F(n + 1) = 2  F(n); F(0) = 1; F(n + 1) = 2 F(n)

19 The First-Order Linear Recurrence Relation There are many sequences that satisfy For example, 5,15,45,135,... or 7,21,63,189,.... To pinpoint the particular sequence described, we need to know one of the terms of the sequence. (boundary condition, or initial condition since usually a 0 is specified)

20 The First-Order Linear Recurrence Relation nonhomogeneous linear recurrence relation Ex. 10.4 time complexity of bubble sort algorithm a n =a n-1 +(n-1), n>1, a 1 =0, where a n =the number of comparisons to sort n numbers a n - a n-1 = n-1 a n-1 - a n-2 = n-2 a n-2 - a n-3 = n-3 a 2 - a 1 = 1 + a n =1+2+3+...+(n-1)=(n 2 -n)/2

21 The Second-Order Linear Homogeneous Recurrence Relation with Constant Coefficients Be careful not to draw conclusions from a few (or even, perhaps, many) particular instances. Ex. 10.14 Arrange pennies contiguously in each row where each penny above the bottom row touches two pennies in the row below it. a 1 =1,a 2 =1,a 3 =2,a 4 =3,a 5 =5,a 6 =8,... Is a n =F n ? NO

22 Sequences DEF: Given a set S, an (infinite) sequence in S is a function N  S. Symbolically, a sequence is represented using the subscript notation a i. This gives a way of specifying formulaically Note: Other sets can be taken as ordering models. Q: Give the first 5 terms of the sequence defined by the formula

23 Sequence Examples A: Plug in for i in sequence 0, 1, 2, 3, 4: Formulas for sequences often represent patterns in the sequence. Q: Provide a simple formula for each sequence: a) 3,6,11,18,27,38,51, … b) 0,2,8,26,80,242,728,… c) 1,1,2,3,5,8,13,21,34,…

24 L624 Sequence Examples A: Try to find the patterns between numbers. a) 3,6,11,18,27,38,51, … a 1 =6=3+3, a 2 =11=6+5, a 3 =18=11+7, … and in general a i +1 = a i +(2i +3). This is actually a good enough formula. Later we’ll learn techniques that show how to get the more explicit formula: a i = 6 + 4(i –1) + (i –1) 2 b) 0,2,8,26,80,242,728,… If you add 1 you’ll see the pattern more clearly. a i = 3 i –1 c) 1,1,2,3,5,8,13,21,34,… This is the famous Fibonacci sequence given by a i +1 = a i + a i-1

25 Definition of Finite Automaton The finite automaton has 5-tuple (Q, ∑, δ, q0, F) Q is a set of states ∑ is a set of input alphabet δ is a transition function or rule for moving q0 is a start state F is a set of accept states

26 Finite automaton If the input is: 0101010101 & 0100 & 110000 & 0101000000 & 101000 What is the outputs? q3 q2 q1 1 0 1 0 0, 1

27 The finite automaton M is (Q, ∑, δ, q0, F) Where Q = {q1, q2, q3} ∑ = {0, 1} q0 is the state q1 F = {q2} q3 q2 q1 1 0 1 0 0, 1

28 δ is describes as 0 1 q1q1q2 q2q3q2 q3q2q2 q3 q2 q1 1 0 0 0, 1

29 Example r2 q1 s b a b a r1 q2 b a aab b

30 For the start state, is even because it is possible to input 0 so far q even q odd 1 0 1 0 For the accept state, we consider qodd because we want to test odd numbers qodd

31 Example The inputs a, b, baba, baa, bbb,  q2 q1 a  q3 b a a, b

32 0 0,1 0 0 1 1 1 The machine accepts a string if the process ends in a double circle Anatomy of a Deterministic Finite Automaton states q0q0 q1q1 q2q2 q3q3 start state (q 0 ) accept states (F)

33 Anatomy of a Deterministic Finite Automaton 0 0,1 0 0 1 1 1 q0q0 q1q1 q2q2 q3q3 The alphabet of a finite automaton is the set where the symbols come from: The language of a finite automaton is the set of strings that it accepts {0,1}

34 Q = {q 0, q 1, q 2, q 3 } Σ = {0,1}  : Q  Σ → Q transition function * q 0  Q is start state F = {q 1, q 2 }  Q accept states M = (Q, Σ, , q 0, F) where  01 q0q0 q0q0 q1q1 q1q1 q2q2 q2q2 q2q2 q3q3 q2q2 q3q3 q0q0 q2q2 * q2q2 0 0,1 0 0 1 1 1 q0q0 q1q1 q3q3 M


Download ppt "Functions Discrete Structure. L62 Functions. Basic-Terms. DEF: A function f : A  B is given by a domain set A, a codomain set B, and a rule which for."

Similar presentations


Ads by Google