Functions (2) - 1ICOM 4075 (Spring, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez ICOM 4075: Foundations.

Slides:



Advertisements
Similar presentations
Recursive Definitions and Structural Induction
Advertisements

Definitions: Sum, Difference, Product, and Quotient of Functions
Function Composition Fancy way of denoting and performing SUBSTITUTION But first …. Let’s review.
Functions CSLU Fall 2007 Cameron McInally Fordham University.
1 Chapter Facts about Functions. 2 Section 2.1 Functions: Definitions and Examples A function ƒ from A to B associates each element of A with exactly.
Discrete Structure Li Tak Sing( 李德成 ) Lectures
Discrete Structures Chapter 5 Relations and Functions
Copyright © Cengage Learning. All rights reserved.
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
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,
CS 2210 (22C:019) Discrete Structures Sets and Functions Spring 2015 Sukumar Ghosh.
Chapter 7 Functions Dr. Curry Guinn. Outline of Today Section 7.1: Functions Defined on General Sets Section 7.2: One-to-One and Onto Section 7.3: The.
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.
12.1 Inverse Functions For an inverse function to exist, the function must be one-to-one. One-to-one function – each x-value corresponds to only one y-value.
Math 3121 Abstract Algebra I Lecture 3 Sections 2-4: Binary Operations, Definition of Group.
Relations and Functions Another Foundational Concept Copyright © 2014 – Curt Hill.
1.7 Combination of Functions
Logarithmic Functions Section 8.4. WHAT YOU WILL LEARN: 1.How to evaluate logarithmic functions.
Foundations of Discrete Mathematics Chapter 3 By Dr. Dalia M. Gil, Ph.D.
Composition of Functions. Definition of Composition of Functions The composition of the functions f and g are given by (f o g)(x) = f(g(x))
Construction Techniques (2) - 1ICOM 4075 (Spring, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez 2005.
3 DERIVATIVES. In this section, we will learn about: Differentiating composite functions using the Chain Rule. DERIVATIVES 3.5 The Chain Rule.
Construction Techniques (1) - 1ICOM 4075 (Fall, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez 2005.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
FUNCTIONS.
College Algebra Fifth Edition James Stewart Lothar Redlin Saleem Watson.
8.4 Logarithms and Logarithmic Functions Goal: Evaluate and graph logarithmic functions Correct Section 8.3.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
Chapter 7 7.6: Function Operations. Function Operations.
Propositional Calculus CS 270: Mathematical Foundations of Computer Science Jeremy Johnson.
1.3 New functions from old functions: Transformations.
Discrete Mathematics R. Johnsonbaugh
11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.
NEW FUNCTIONS FROM OLD New Functions from Old Functions In this section, we will learn: How to obtain new functions from old functions and how.
11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.
FUNCTIONS AND MODELS New Functions from Old Functions In this section, we will learn: How to obtain new functions from old functions and how to.
Discrete Structure Li Tak Sing( 李德成 ) Lecture 13 1.
3 DERIVATIVES.  Remember, they are valid only when x is measured in radians.  For more details see Chapter 3, Section 4 or the PowerPoint file Chapter3_Sec4.ppt.
R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 9 Boolean Algebras and Combinatorial Circuits.
CSC102 - Discrete Structures Functions
Aim: What is the composition of functions? Do Now: Given: Express z in terms of x HW: Work sheet.
1 Functions CS 202 Epp section ??? Aaron Bloomfield.
Chapter 7 – Radical Equations and Inequalities 7.2 – Inverse Functions and Relations.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
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.
1 Discrete Mathematical Functions Examples.
Notions & Notations (2) - 1ICOM 4075 (Spring 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez Spring.
Discrete Structures Li Tak Sing( 李德成 ) Lectures
August 2003 CIS102/LECTURE 9/FKS 1 Mathematics for Computing Lecture 9 LOGIC Chapter 3.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
FUNCTIONS.
Notions & Notations - 1ICOM 4075 (Fall 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez Fall 2010 ICOM.
Objectives: 1)Students will be able to find the inverse of a function or relation. 2)Students will be able to determine whether two functions or relations.
7-8: Inverse Functions and Relations. Terms to Know Inverse relation: the set of ordered pairs obtained by reversing the coordinates of each original.
Discrete Mathematics Functions
Functions.
Functions Section 2.3.
Function Compositions and Inverses
Functions CS 202 Epp section 7.1.
Section 5.1 Composite Functions.
Functions.
Ch 5 Functions Chapter 5: Functions
Domain, range and composite functions
Function Operations Function Composition
Functions Section 2.3.
Function And Relations Review
Function Operations Function Composition
Section 6.1 Composite Functions.
Do Now: Given: Express z in terms of x HW: p.159 # 4,6,8,
Presentation transcript:

Functions (2) - 1ICOM 4075 (Spring, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez ICOM 4075: Foundations of Computing Lecture 6 Functions (2) Lecture Notes Originally Written By Prof. Yi Qian

Functions (2) - 2ICOM 4075 (Spring, 2010) UPRM Homework 4 – Due Tuesday March 9, 2010 Section 2.1: (pp.88-90) 1. b. d. 2. b. d. f. 3. b. d. 4. b. 6. b. d. 7. b. d. f. 8. b b. 13. b. d. 14. b. d. 15. b. d. f. 17.

Functions (2) - 3ICOM 4075 (Spring, 2010) UPRM Reading Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 2 nd edition, Chapter 2. Section 2.2

Functions (2) - 4ICOM 4075 (Spring, 2010) UPRM Constructing Functions Composition of Functions –Composition of functions is a natural process that we often use without even thinking. E.g., floor(log 2 (6)) involves the composition of the two functions floor and log 2. To evaluate the expression, we first evaluate log 2 (6), which is a number between 2 and 3. Then we apply the floor function to this number, obtaining the value 2. Definition of Composition –The composition of two functions f and g is the function denoted by f○g and defined by (f○g)(x) = f(g(x)). Notice that composition makes sense only for values of x in the domain of g such that g(x) is in the domain of f. –So if g: A→B and f: C→D and B C, then the composition f○g makes sense. In other words, for every x A it follows that g(x) B, and since B C it follows that f(g(x)) D. It also follows that f○g: A→D. –E.g., log 2 : R + →R and floor: R→Z, where R + denotes the set of positive real numbers. So for any positive real number x, the expression log 2 (x) is a real number and thus floor(log 2 (x)) is an integer. So the composition floor○log 2 : R + →Z.

Functions (2) - 5ICOM 4075 (Spring, 2010) UPRM Composition of Functions Composition of functions is associative: –If f, g, and h are functions of the right type such that (f○g)○h and f○(g○h) make sense, then (f○g)○h = f○(g○h). Composition of functions is not commutative: –E.g., suppose that f and g are defined by f(x) = x + 1 and g(x) = x 2. To show that f○g ≠ g○f, we only need to find one number x such that (f○g)(x) ≠ (g○f)(x). We’ll try x = 3 and observe that (f○g)(3) = f(g(3)) = f(3 2 ) = = 10. (g○f)(3) = g(f(3)) = g(3 + 1) = (3 + 1) 2 = 16. Therefore, (f○g)(3) ≠ (g○f)(3) A function that always returns its argument is called an identity function. For a set A we sometimes write “id A ” to denote the identity function defined by id A (a) = a for all a A. If f: A→B, then we always have the following equation: f○ id A = f = id B ○f

Functions (2) - 6ICOM 4075 (Spring, 2010) UPRM The Sequence, Distribute, and Pairs Functions The sequence function “seq” has type N→lists(N) and is defined as follows for any natural number n: seq(n) =. –E.g., seq(0) =, seq(2) =, seq(5) =. The distribute function “dist” has type A x lists(B) → lists(A x B). It takes an element x from A and a list y from lists(B) and returns the list of pairs made up by pairing x with each element of y. –E.g., dist(x, ) =. The pairs function takes two lists of equal length and returns the list of pairs of corresponding elements. –E.g., pairs(, ) =. –Since the domain of pairs is a proper subset of lists(A) x lists(B), it is a partial function of type lists(A) x lists(B) → lists(A x B).

Functions (2) - 7ICOM 4075 (Spring, 2010) UPRM Composing Functions with Different Arities Composition can also occur between functions with different arities. –E.g., suppose we define the following functionf(x, y) = dist(x, seq(y)). In this case dist has two arguments and seq has one argument. For example, we’ll evaluate the expression f(5, 3). f(5, 3) = dist(5, seq(3)) = dist(5, ) =.

Functions (2) - 8ICOM 4075 (Spring, 2010) UPRM Distribute a Sequence We’ll show that the definition f(x, y) = dist(x, seq(y)) is a special case of the following more general form of composition, where X can be replaced by any number of arguments. f(X) = h(g 1 (X),…,g n (X)). Distribute a Sequence –We’ll show that the definition f(x, y) = dist(x, seq(y)) fits the general form of composition. To make it fit the form, we’ll define the functions one(x, y) = x and two(x, y) = y. Then we have the following representation of f. f(x, y) = dist(x, seq(y)) = dist(one(x, y), seq(two(x, y))) = dist(one(x, y), (seq○two(x, y))). The last expression has the general form of composition f(X) = h(g 1 (X), g 2 (X)), where X = (x, y), h = dist, g 1 = one, and g 2 = seq○two

Functions (2) - 9ICOM 4075 (Spring, 2010) UPRM The Max Function –Suppose we define the function “max”, to return the maximum of two numbers as follows: max(x, y) = if x < y then y else x. Then we can use max to define the function “max3”, which returns the maximum of three numbers, by the following composition: max3(x, y, z) = max(max(x, y), z).

Functions (2) - 10ICOM 4075 (Spring, 2010) UPRM Minimum Depth of a Binary Tree To find the minimum depth of a binary tree in terms of the numbers of nodes: –The following figure lists a few sample cases in which the trees are as compact as possible, which means that they have the least depth for the number of nodes. Let n denote the number of nodes. Notice that when 4 ≤ n < 8, the depth is 2. Similarly, the depth is 3 whenever 8 ≤ n < 16. –At the same time we know that log 2 (4) =2, log 2 (8) = 3, and for 4 ≤ n < 8 we have 2 ≤ log 2 (n) < 3. So log 2 (n) almost works as the depth function. –In general, we have the minimum depth function as the composition of the floor function and the log 2 function: minDepth(n) = floor(log 2 (n)). Binary treeNodesDepth

Functions (2) - 11ICOM 4075 (Spring, 2010) UPRM List of Pairs Suppose we want to construct a definition for the following function in terms of known functions f(n) = for any n N. Starting with this informal definition, we’ll transform it into a composition of known functions. Suppose we want to construct a definition for the following function in terms of known functions g(k) = for any k N. Starting with this informal definition, we’ll transform it into a composition of known functions. f(n) = = pairs(, ) = pairs(seq(n), seq(n)). g(k)= = dist(k, ) = dist(k, seq(k)).

Functions (2) - 12ICOM 4075 (Spring, 2010) UPRM The Map Function Definition of the Map Function: –Let f be a function with domain A and let be a list of elements from A. Then map(f, ) =. So the type of the map function can be written as map: (A→B) x list(A) → lists(B). –E.g., map(floor, ) = =. map(floor○log 2, ) = =. map(+, ) = –The map function is an example of a higher-order function, which is any function that either has a function as an argument or has a function as a value. This is an important property that most good programming languages possess.

Functions (2) - 13ICOM 4075 (Spring, 2010) UPRM A List of Squares Suppose we want to compute sequences of squares of natural numbers, such as 0, 1, 4, 9, 16. In other words, we want to compute f: N → lists(N) defined by f(n) =. We have two different ways: –First way: define s(x) = x*x and then construct a definition for f in terms of map, s, and seq as follows. f(n) = = = map(s, ) = map(s, seq(n)). –Second way: construct a definition for f without using the function s that we defined for the first way. f(n) = = = map(*, ) = map(*, pairs(, )) = map(*, pairs(seq(n), seq(n))).