Functions.

Slides:



Advertisements
Similar presentations
1.6 Functions. Chapter 1, section 6 Functions notation: f: A B x in A, y in B, f(x) = y. concepts: –domain of f, –codomain of f, –range of f, –f maps.
Advertisements

modified from UCI ICS/Math 6D, Fall Sets+Functions-1 Sets “Set”=Unordered collection of Objects “Set Elements”
Functions Goals Introduce the concept of function Introduce injective, surjective, & bijective functions.
1 Section 1.8 Functions. 2 Loose Definition Mapping of each element of one set onto some element of another set –each element of 1st set must map to something,
Functions.
Section 1.8: Functions A function is a mapping from one set to another that satisfies certain properties. We will first introduce the notion of a mapping.
Relations And Functions. Objective All students will be able to determine whether a relation is a function and identify the domain and range of a function.
Relations and Functions Another Foundational Concept Copyright © 2014 – Curt Hill.
Functions. Copyright © Peter Cappello2 Definition Let D and C be nonempty sets. A function f from D to C, for each element d  D, assigns exactly 1 element.
1 Annoucement n Skills you need: (1) (In Thinking) You think and move by Logic Definitions Mathematical properties (Basic algebra etc.) (2) (In Exploration)
FUNCTIONS.
1 Discrete Structures – CNS 2300 Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 1 The Foundations: Logic, Sets,
Functions Reading: Chapter 6 (94 – 107) from the text book 1.
CSE 2353 – October 1 st 2003 Functions. For Real Numbers F: R->R –f(x) = 7x + 5 –f(x) = sin(x)
Agenda Week 10 Lecture coverage: –Functions –Types of Function –Composite function –Inverse of a function.
Chapter 7 7.6: Function Operations. Function Operations.
Relations And Functions. A relation is a set of ordered pairs {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} This is a relation The domain is the set of all x.
Do Now: Find f(g(x)) and g(f(x)). f(x) = x + 4, g(x) = x f(x) = x + 4, g(x) = x
CSC102 - Discrete Structures Functions
1 Functions CS 202 Epp section ??? Aaron Bloomfield.
FUNCTIONS COSC-1321 Discrete Structures 1. Function. Definition Let X and Y be sets. A function f from X to Y is a relation from X to Y with the property.
Warm Up What algebraic equation shows the sentence four plus a number divided by six is equal to the product of twelve and the same number?
Relations And Functions © 2002 by Shawna Haider. A relation is a set of ordered pairs. {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} This is a relation The domain.
FUNCTIONS.
Functions 7/7/2016COCS - Discrete Structures1. Functions A function f from a set A to a set B is an assignment of exactly one element of B to each element.
Functions Goals Introduce the concept of function
Functions Section 2.3.
Operations with Functions
Applied Discrete Mathematics Week 2: Functions and Sequences
Cartesian product Given two sets A, B we define their Cartesian product is the set of all the pairs whose first element is in A and second in B. Note that.
Functions.
Chapter 2 Sets and Functions.
Relation and function.
… and the following mathematical appetizer is about…
Functions.
Functions Section 2.3.
CS201: Data Structures and Discrete Mathematics I
Functions.
Relations And Functions.
CS100: Discrete structures
… and the following mathematical appetizer is about…
Functions CS 202 Epp section 7.1.
Functions.
Activity 2.8 Study Time.
Ch 5 Functions Chapter 5: Functions
Objectives The student will be able to:
… and the following mathematical appetizer is about…
Functions Rosen 6th ed., §2.3.
Functions Rosen 2.3, 2.5 f( ) = A B Lecture 5: Oct 1, 2.
Relations And Functions.
Relations And Functions.
Relations And Functions © 2002 by Shawna Haider.
Relations And Functions.
Day 76 Today’s Agenda: Go over Re-test Unit 4: Functions
Relations And Functions.
Unit 4: Functions Learning Target: Students can understand that a function is a rule that assigns to each input exactly one output. The graph of a function.
Functions.
Lecture # 18 Types of Functions
Relations and functions
Functions Section 2.3.
Function Composition.
Relations And Functions.
Composite Function: Combining a function within another function.
Relations And Functions.
Lesson 5.3 What is a Function?
Day 76 Today’s Agenda: Go over Re-test Unit 4: Functions
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Common Core Math 8 India Walton
Relations And Functions.
Relations Vs. Functions.
Presentation transcript:

Functions

Functions Are Relations A function is a relation where for a given input the output is unique. A relation may produce many different outputs for the same input. All functions are relations but most relations are not functions. Target set x y z w Source set a c b Relations are the theoretical basis for Relational programming languages such as Prolog and SQL. The theoretical basis for Imperative languages such as Java and VB is a lot more complicated than relations and functions. Functions are the theoretical basis for Functional programming languages such as Miranda and Haskell.

Relations are much more powerful than functions. And therefore relations take a lot more computer power to process than functions. That’s why Relational databases are relatively slow. The advantages of Relational databases totally outweigh this disadvantage though.

Relations Are Not (Often) Functions This diagram shows a relation, not a function. Given an input of b the output may be any member of the set { w, y, z }. Target set x y z w Source set a c b A query of a Relational database will usually produce a set as a result. Database people tend to call such a set a table. For example parent(X, dave) would get you the set (or table) { (jim, dave), (theresa, dave) }.

Functions Are Relations II Since functions are relations a function has a source and target. The source is the set of all possible inputs. The target is the set of all possible outputs. For a total function dom f = source, ran f  target For a partial function dom f  source, ran f  target For a given input the output of a function is unique. x  dom f; y, z  ran f  f(x) = y  f(x) = z  y = z

Notation Essentially a function and a program are the same thing. Each takes an input value and transforms it into an output value. To emphasise the input  output transformation we usually use one directional arrows when defining functions. Just as we use the two directional arrow when defining relations. R  X  Y If f is a function from A to B, we write f:A→B The words mapping, transformation, correspondence, and operator are used as synonyms for function.

No x has more than one y assigned All x’s are assigned A total function f from set A to set B is a rule of correspondence that assigns to each element x in the set A exactly one element y in the set B. A total function f from set A to set B is a rule of correspondence that assigns to each element x in the set A exactly one element y in the set B. A total function f from set A to set B is a rule of correspondence that assigns to each element x in the set A exactly one element y in the set B. Set A is the domain 1 2 3 4 5 Set B is the range 2 10 8 6 4 No x has more than one y assigned All x’s are assigned Whew! What did that say? This is a total function ---it meets our conditions Must use all the x’s The x value can only be assigned to one y

Let’s look at another relation and decide if it is a total function. The second condition says each x can have only one y, but it CAN be the same y as another x gets assigned to. Set A is the domain 1 2 3 4 5 Set B is the range 2 10 8 6 4 No x has more than one y assigned All x’s are assigned This is a total function ---it meets our conditions Must use all the x’s The x value can only be assigned to one y

A good example that you can “relate” to is students in our maths class this semester are set A. The grade they earn out of the class is set B. Each student must be assigned a grade and can only be assigned ONE grade, but more than one student can get the same grade (we hope so---we want lots of A’s). The example shown on the previous screen had each student getting the same grade. That’s okay. A good example that you can “relate” to is students in our maths class this semester are set A. The grade they earn out of the class is set B. Each student must be assigned a grade and can only be assigned ONE grade, but more than one student can get the same grade (we hope so---we want lots of A’s). The example show on the previous screen had each student getting the same grade. That’s okay. 1 2 2 4 3 6 4 8 10 5 2 was assigned both 4 and 10 Is the relation shown above a function? NO Why not???

This is not a total function---it doesn’t assign each x with a y Check this relation out to determine if it is a TOTAL function. It is not---3 didn’t get assigned to anything Comparing to our example, a student in maths must receive a grade Set A is the domain 1 2 3 4 5 Set B is the range 2 10 8 6 4 This is not a total function---it doesn’t assign each x with a y Must use all the x’s The x value can only be assigned to one y

This is a total function Check this relation out to determine if it is a total function. This is fine—each student gets only one grade. More than one can get an A and I don’t have to give any D’s (so all y’s don’t need to be used). Set A is the domain 1 2 3 4 5 Set B is the range 2 10 8 6 4 Must use all the x’s This is a total function The x value can only be assigned to one y

One – to – One Function (Injection) Types of Functions: One – to – One Function (Injection) An injective function (or one-to-one) is a function whose range elements are mapped to by a unique element of the domain. ( or ) No element of B is the image of more than one element in A.

Onto Function(surjection) A surjective function (or onto) is a function whose range is the whole of the target set. Or A function f:A → B is onto iff ran f = B.

One – to – One correspondence Function (bijection) A bijective function (or bijection) is a function which is total, surjective and injective

Inverse Function The inverse of a function is obtained by swapping the order of the elements in the pairs. The result will not be function unless the original function is injective.

Identity And Function Composition The identity function returns a value equal to its input and is denoted by Ix. x  X  Ix (x) = x Composition : f(x) = x + 1 g(x) = 5 * x g(f(3)) = g(3 + 1) = g(4) = 5 * 4 = 20 f(g(2)) = f(5 * 2) = f(10) = 10 + 1 = 11 Function composition (e.g. f(g(x))) is only possible if the output of the inner function can be the input to the outer function. ran g  dom f Obviously, a composition defines a new function. 1 2 3 4 10 11 20 f(3) g(f(3)) 1 2 3 4 10 11 20 1 2 3 4 10 11 20 g(2) f(g(2)) 1 2 3 4 10 11 20

Function Composition Another way of writing composition is to use o. g o f where (g o f) x = g(f(x)) (g o f) 3 = g(f(3)) = g(4) = 20 Both g o f and f o g are functions but in general they will not be the same function. Generally g o f ≠ f o g For example : x  Z  f(x) = x - 1 x  N  g(x) = 6 * x (g o f) 2 = g(f(2)) = g(1) = 6 (f o g) 2 = f(g(2)) = f(12) = 11 Clearly, these are not equal. Functional programmers use function composition in much the same way as Imperative programmers use ;. In Java we could write x = f(a, b); y = g(x) ; meaning apply the method f to the parameters a and b and then apply the method g to the result of f. The closest equivalent in Haskell would be let y = (f.g) a b in y meaning exactly the same thing (. Is Haskell’s equivalent of o).

Function Override The override of f by g is denoted by f  g. x  Z  f(x) = x - 1 x  N  g(x) = 6 * x (f  g) 2 = g(2) = 12 (f  g) -1 = f(-1) = -2 In the first case, 2  dom g so we apply g. In the second case -1  dom g so we apply f. Note that if the argument is not in the domain of either function then the result is undefined : if x  dom f  dom g then(f  g) x =  Of course, the last bullet point is true of any function. If the input to a function is not in that function’s domain then the result of applying the function is undefined. In our terms, given an unexpected input the program may well crash.