FUNCTIONS.

Slides:



Advertisements
Similar presentations
Functions Section 2.3 of Rosen Fall 2008
Advertisements

Discrete Mathematics Lecture 7 Alexander Bukharovich New York University.
Lecture 3 Set Operations & Set Functions. Recap Set: unordered collection of objects Equal sets have the same elements Subset: elements in A are also.
CSE115/ENGR160 Discrete Mathematics 02/22/11 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 02/16/12 Ming-Hsuan Yang UC Merced 1.
Discrete Structures Chapter 5 Relations and Functions
CSE115/ENGR160 Discrete Mathematics 02/21/12
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.
Functions. Let A and B be sets A function is a mapping from elements of A to elements of B and is a subset of AxB i.e. can be defined by a set of tuples!
Functions, Sequences, and Sums
Discrete Structures Functions Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore.
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.
Basic Structures: Sets, Functions, Sequences, Sums, and Matrices
Sets Set Operations Functions. 1. Sets 1.1 Introduction and Notation 1.2 Cardinality 1.3 Power Set 1.4 Cartesian Products.
2.1 Sets 2.2 Set Operations 2.3 Functions ‒Functions ‒ Injections, Surjections and Bijections ‒ Inverse Functions ‒Composition 2.4 Sequences and Summations.
FUNCTION Discrete Mathematics Asst. Prof. Dr. Choopan Rattanapoka.
Mathematics. Session Set, Relation & Function Session - 3.
Foundations of Discrete Mathematics Chapter 3 By Dr. Dalia M. Gil, Ph.D.
February 12, 2015Applied Discrete Mathematics Week 2: Functions and Sequences 1Exercises Question 1: Given a set A = {x, y, z} and a set B = {1, 2, 3,
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.
ICS 253: Discrete Structures I
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFunctions.
Chapter 2: Basic Structures: Sets, Functions, Sequences, and Sums (2)
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
Fall 2002CMSC Discrete Structures1 … and the following mathematical appetizer is about… Functions.
10/26/20151 … and the following mathematical appetizer is about… Functions.
Discrete Mathematics CS 2610 September 12, Agenda Last class Functions  Vertical line rule  Ordered pairs  Graphical representation  Predicates.
Functions Section 2.3 of Rosen Spring 2012 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions: Use Piazza.
MSU/CSE 260 Fall Functions Read Section 1.8.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
1 Discrete Structures – CNS 2300 Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 1 The Foundations: Logic, Sets,
Chapter 1 SETS, FUNCTIONs, ELEMENTARY LOGIC & BOOLEAN ALGEBRAs BY: MISS FARAH ADIBAH ADNAN IMK.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl Module #4.
1.4 Sets Definition 1. A set is a group of objects . The objects in a set are called the elements, or members, of the set. Example 2 The set of positive.
Example Prove that: “IF 3n + 2 is odd, then n is odd” Proof by Contradiction: -p = 3n + 2 is odd, q = n is odd. -Assume that ~(p  q) is true OR -(p 
2. 1 Basic structures Sets Set Operations Functions Sequences & Sums
Basic Structures: Functions Muhammad Arief download dari
Agenda Week 10 Lecture coverage: –Functions –Types of Function –Composite function –Inverse of a function.
CompSci 102 Discrete Math for Computer Science January 31, 2012 Prof. Rodger Slides modified from Rosen AB a b c d x y z.
Functions Section 2.3. Section Summary Definition of a Function. – Domain, Cdomain – Image, Preimage Injection, Surjection, Bijection Inverse Function.
Basic Structures: Sets, Functions, Sequences, and Sums.
Sets Definition: A set is an unordered collection of objects, called elements or members of the set. A set is said to contain its elements. We write a.
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.
Relations and Functions ORDERED PAIRS AND CARTESIAN PRODUCT An ordered pair consists of two elements, say a and b, in which one of them, say a is designated.
1 Discrete Mathematical Functions Examples.
1 Lecture 5 Functions. 2 Functions in real applications Curve of a bridge can be described by a function Converting Celsius to Fahrenheit.
Section 2.3. Section Summary  Definition of a Function. o Domain, Cdomain o Image, Preimage  One-to-one (Injection), onto (Surjection), Bijection 
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.
Discrete Mathematics Lecture # 17 Function. Relations and Functions  A function F from a set X to a set Y is a relation from X to Y that satisfies the.
Discrete Mathematics Functions
ICS 253: Discrete Structures I
Functions Section 2.3.
Functions.
Relation and function.
Chapter 3 Relation and Function Homework 4 For each of the following relations on set A = { 1,2,3,4 }, check each of them whether they are reflexive, irreflexive,
Functions Section 2.3.
Discrete Math (2) Haiming Chen Associate Professor, PhD
CSE15 Discrete Mathematics 02/27/17
CS100: Discrete structures
Functions CS 202 Epp section 7.1.
CS 220: Discrete Structures and their Applications
Functions.
ICS 253: Discrete Structures I
Functions Rosen 6th ed., §2.3.
Functions Rosen 2.3, 2.5 f( ) = A B Lecture 5: Oct 1, 2.
Functions Section 2.3.
Presentation transcript:

FUNCTIONS

Introduction The concept of function is extremely important in discrete mathematics. Functions are used in the definition of such discrete structures as sequences and strings. Functions are also used to represent how long it takes a computer to solve problems of a given size. Recursive functions, which are functions defined in terms of themselves, are used throughout computer science.

Definition 1 Let A and B be sets. A function f from A to B is an assignment of exactly one element of B to each element of A. We write f(a) = b if b is the unique element of B assigned by the function f to the element a of A. If f is a function from A to B, we write f: A  B.

Definition 2 If f is a function from A to B, we say that A is the domain of f and B is the codomain of f. If f(a) = b, we say that b is the image of a and a is a pre-image of b. The range of f is the set of all images of elements of A. Also, if f is a function from A to B, we say that f maps A to B.

The Function f Maps A to B b = f(a) A B f

Example 1 Let f be the function that assigns the last two bits of a bit string of length 2 or greater to that string. Then, the domain of f is the set of all bit strings of length 2 or greater, and both the codomain and range are the set {00,01,10,11}.

Example 2 Let f: Z  Z assign the square of an integer to this integer. Then f(x) = x2, where the domain of f is the set of all integers, the codomain of f can be chosen to be the set of all integers, and the range of f is the set of all nonnegative integers that are perfect squares, namely, {0,1,4,9,…}.

Example 3 The domain and codomain of functions are often specified in programming languages. For instance, the Java statement int floor(float real){…} int factorial(int x){…}

Definition 3 Let f1 and f2 be functions from A to R. Then f1 + f2 and f1f2 are also functions from A to R defined by: (f1 + f2)(x) = f1(x) + f2(x), (f1f2)(x) = f1(x)f2(x)  Two real-valued functions with the same domain can be added and multiplied.

Example 4 Let f1 and f2 be functions from R to R such that f1(x) = x2 and f2(x) = x – x2. What are the functions f1 + f2 and f1f2? (f1 + f2)(x) = f1(x) + f2(x) = x2 + (x – x2) = x and (f1f2)(x) = f1(x)f2(x) = x2(x – x2) = x3 – x4

Definition 4 Let f be a function from the set A to the set B and let S be a subset of A. The image of S is the subset of B that consists of images of the elements of S. We denote the image of S by f(S), so that f(S) = {f(s) | s  S}

Example 5 Let A = {a,b,c,d,e} and B = {1,2,3,4} with f(a)=2, f(b)=1, f(c)=4, f(d)=1, and f(e)=1. The image of the subset S = {b,c,d} is the set f(S) = {1,4}.

ONE-TO-ONE AND ONTO FUNCTIONS

Definition 5 A function f is said to be one-to-one, or injective, if and only if f(x) = f(y) implies that x = y for all x and y in the domain of f. A function is said to be an injection if it is one-to-one.

A One-to-One Function a 1 b 2 c 3 d 4 5

Example 6 f(x) = x + 1 is a one-to-one function because x+1  y+1 when x  y. f(x) = x2 is not one-to-one because f(1)=f(-1)=1, but 1  -1. The function is one-to-one if its domain is restricted to Z+.

Definition 6 A function f whose domain and codomain are subsets of the set of real numbers is called strictly increasing if f(x) < f(y) whenever x < y and x and y are in the domain of f. Similarly, f is called strictly decreasing if f(x) > f(y) whenever x < y and x and y are in the domain of f. A function that is either strictly increasing or strictly decreasing must be one-to-one.

Definition 7 A function f from A to B is called onto, or surjective, if and only if for every element b  B there is an element a  A with f(a) = b. A function f is called a surjection if it is onto. Onto functions are function whose range and codomain are equal. That is, every member of the codomain is the image of some element of the domain. yx(f(x) = y)

Example 7 Let f be the function from {a,b,c,d} to {1,2,3} defined by f(a)=3, f(b)=2, f(c)=1, and f(d)=3. Is f an onto function? Is the function f(x)=x2 from the set of integers to the set of integers onto? Is the function f(x)=x+1 from the set of integers to the set of integers onto?

Definition 8 The function f is a one-to-one correspondence, or a bijection, if it is both one-to-one and onto.

Example 8 Let f be the function from {a,b,c,d} to {1,2,3,4} with f(a)=4, f(b)=2, f(c)=1, and f(d)=3. Is f a bijection? The function f is one-to-one and onto. It is one-to-one since the function takes on distinct values. It is onto since all four elements of the codomain are images of elements in the domain. Hence, f is a bijection.

Different Types of Correspondence (a) One-to-one, not onto (b) Onto, not one-to-one 1 2 3 4 a b c 1 2 3 a b c d

Different Types of Correspondence (c) One-to-one, and onto (d) Neither one-to-one nor onto 1 2 3 4 a b c d 1 2 3 4 a b c d

Different Types of Correspondence (e) Not a function 1 2 3 4 a b c

Exercise 1 Why is f not a function from R to R if f(x) = 1/x? f(x) = x ? f(x) = (x2+1) ? Determine whether f is a function from Z to R if f(n) = n. f(n) = (n2+1). f(n) = 1/(n2 – 4).

Exercise 2 Find the domain and range of these functions. the function that assigns to each bit string the difference between the number of ones and the number of zeros the function that assigns to each nonnegative integer its last digit the function that assigns to each bit string twice the number of zeros in that string the function that assigns to each positive integer the largest perfect square not exceeding this integer

Exercise 3 Determine whether each of these functions from Z to Z is one-to-one. f(n) = n – 1 f(n) = n2 + 1 f(n) = n3 f(n) = n/2 Which functions are onto?

INVERSE FUNCTIONS AND COMPOSITIONS OF FUNCTIONS

Definition 9 Let f be a one-to-one correspondence from the set A to the set B. The inverse function of f is the function that assigns to an element b belonging to B the unique element a in A such that f(a)=b. The inverse function of f is denoted by f-1. Hence, f-1(b)=a when f(a)=b.

A one-to-one correspondence is called invertible since we can define an inverse of this function. A funtion is not invertible if it is not a one-to-one correspondence, since the inverse of such a function does not exist.

Example 9 Let f be the function from {a,b,c} to {1,2,3} such that f(a)=2, f(b)=3, f(c)=1. Is f invertible, and if it is, what is the inverse? The function f is invertible since it is one-to-one correspondence. The inverse function f-1 reverses the correspondence given by f, so that f-1(1)=c, f-1(2)=a, and f-1(3)=b.

Example 10 Let f be the function from the set of integers to the set of integers such that f(x)=x+1. Is f invertible, and if it is, what is the inverse? The function f has an inverse since it is a one-to-one correspondence. To reverse the correspondence, suppose that y is the image of x, so that y=x+1. Then x=y-1. This means that y-1 is the unique element of Z that is sent to y by f. Consequently, f-1(y)=y-1.

Definition 10 Let g be a function from the set A to the set B and let f be a function from the set B to the set C. The composition of the functions f and g, denoted by , is defined by

Example 11 Let f and g be the functions from the set of integers to the set of integers defined by f(x)=2x+3 and g(x)=3x+2. What is the composition of f and g? What is the composition of g and f? (f  g)(x) = f(g(x)) = f(3x+2) = 2(3x+2)+3 = 6x+7 (g  f)(x) = g(f(x)) = g(2x+3) = 3(2x+3)+2 = 6x+11

Remark Note that even though f  g and g  f are defined for the functions f and g, f  g and g  f are not necessarily equal. In other words, the commutative law does not hold for the composition of functions.

GRAPH OF FUNCTIONS

Definition 11 Let f be a function from the set A to the set B. The graph of the function f is the set of ordered pairs {(a,b) | a  A and f(a)=b}.

Example 12 Display the graph of the function f(n)=2n+1 from the set of integers to the set of integers. The graph of f is the set of ordered pairs of the form (n, 2n+1) where n is an integer. Display the graph of the function f(x)=x2 from the set of integers to the set of integers. The graph of f is the set of ordered pairs of the form (x, f(x)) = (x, x2) where x is an integer.

SOME IMPORTANT FUNCTIONS

The Floor and Ceiling Functions The floor function assigns to the real number x the largest integer that is less than or equal to x. The value of the floor function at x is denoted by x. The ceiling function assigns to the real number x the smallest integer that is greater than or equal to x. The value of the ceiling function at x is denoted by x. Remark: The floor function is often also called the greatest integer function. It is often denoted by [x].

Table 1. Some Useful Properties of the Floor and Ceiling Functions Table 1. Some Useful Properties of the Floor and Ceiling Functions. (n  Z) (1a) x = n iff n  x < n+1 (1b) x = n iff n-1 < x  n (1c) x = n iff x-1 < n  x (1d) x =n iff x  n < x+1 (2) x-1 < x  x  x < x+1 (3a) -x = - x (3b) -x = - x (4a) x+n = x + n (4b) x+n = x + n

The Factorial Function The factorial function f: N  Z+, denoted by f(n) = n! is the product of the first n positive integers, so that f(n) = 12(n-1)n [and f(0) = 0! = 1]. Example: f(6) = 6! = 1*2*3*4*5*6 = 720

The Mod and Div Functions Let m and n be natural numbers. The integer division, m div n, returns the whole number result of dividing one natural number, m, by another natural number, n (provided that n is not 0), while m mod n returns the remainder of that division.

Hashing Functions A hashing function h assigns memory location h(k) to the record/item that has k as its key. In practice, many different hashing functions are used. One of the most common is the function h(k) = k mod m. A collision occurs for a hash function H if H(x)=H(y), but xy. To handle collisions, a collision resolution policy is required.

One simple collision resolution policy is to find the next highest unoccupied cell. If we want to locate a stored value k, we compute m=h(k) and begin looking at location m. If k is not in this position, we proceed to the next highest position, and so on. If we reach an empty cell or return to our original position, we conclude that k is not present, otherwise we obtain the position of k.