Discrete Math for CS Chapter 5: Functions. Discrete Math for CS New Relation Operations: Given R, a relation on A x B, we define the inverse relation,

Slides:



Advertisements
Similar presentations
Week 7 - Wednesday.  What did we talk about last time?  Set proofs and disproofs  Russell’s paradox.
Advertisements

Functions, Pigeonhole Principle Lecture 14: Nov 4 A B f( ) =
Functions Section 2.3 of Rosen Fall 2008
Discrete Structures Chapter 5 Relations and Functions Nurul Amelina Nasharuddin Multimedia Department.
Discrete Mathematics Lecture 7 Alexander Bukharovich New York University.
Functions f( ) = A B Lecture 15: Nov 4.
Pigeonhole.
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,
CS1022 Computer Programming & Principles Lecture 2 Functions.
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.
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.
Functions A B f( ) =. This Lecture We will define a function formally, and then in the next lecture we will use this concept in counting. We will also.
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.
Relations and Functions Another Foundational Concept Copyright © 2014 – Curt Hill.
Mathematics. Session Set, Relation & Function Session - 3.
 Let A and B be any sets A binary relation R from A to B is a subset of AxB Given an ordered pair (x, y), x is related to y by R iff (x, y) is in R. This.
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,
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Week 7 - Friday.  What did we talk about last time?  Set disproofs  Russell’s paradox  Function basics.
1 Chapter Facts about Functions. 2 Section 2.3 Properties of Functions Let ƒ : A → B be a function. There are three properties that ƒ might possess.
Discrete Math for CS Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation.
Chapter 9. Section 9.1 Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and.
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,
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 
Functions Reading: Chapter 6 (94 – 107) from the text book 1.
Basic Structures: Functions Muhammad Arief download dari
Sets Define sets in 2 ways  Enumeration  Set comprehension (predicate on membership), e.g., {n | n  N   k  k  N  n = 10  k  0  n  50} the set.
Agenda Week 10 Lecture coverage: –Functions –Types of Function –Composite function –Inverse of a function.
Functions. L62 Agenda Section 1.8: Functions Domain, co-domain, range Image, pre-image One-to-one, onto, bijective, inverse Functional composition and.
Discrete Mathematics Relation.
11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.
11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.
MATH 224 – Discrete Mathematics
Discrete Mathematics Lecture # 15 Types of Relations (contd.)
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
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.
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
CSC102 - Discrete Structures Functions
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 7 Functions Instructor: Hayk Melikyan Today we will review sections 7.3, 7.4 and 7.5.
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.
Functions CSRU1400 Spring 2008Ellen Zhang 1 CISC1400, Fall 2010 Ellen Zhang.
Discrete Mathematics 3. MATRICES, RELATIONS, AND FUNCTIONS Lecture 6 Dr.-Ing. Erwin Sitompul
Week 7 - Wednesday.  What did we talk about last time?  Proving the subset relationship  Proving set equality  Set counterexamples  Laws of set algebra.
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.
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.
Section 9.1. Section Summary Relations and Functions Properties of Relations Reflexive Relations Symmetric and Antisymmetric Relations Transitive Relations.
Binary Relation: A binary relation between sets A and B is a subset of the Cartesian Product A x B. If A = B we say that the relation is a relation on.
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
Relations Chapter 9.
Applied Discrete Mathematics Week 2: Functions and Sequences
MATH 224 – Discrete Mathematics
Relation and function.
Function Hubert Chan (Chapter 2.1, 2.2) [O1 Abstract Concepts]
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,
CSE15 Discrete Mathematics 02/27/17
CS100: Discrete structures
Introduction to Relations and Functions
Functions Rosen 6th ed., §2.3.
Functions Rosen 2.3, 2.5 f( ) = A B Lecture 5: Oct 1, 2.
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Presentation transcript:

Discrete Math for CS Chapter 5: Functions

Discrete Math for CS New Relation Operations: Given R, a relation on A x B, we define the inverse relation, R -1, as follows: Examples: R -1 = {(b,a): (a,b) ∈ R} If R is “is_parent_of” then R -1 is “is_child_of” In graphical terms, the inverse of a relation expressed as a digraph is the same graph with all the arrows reversed.

Discrete Math for CS Another Relation Operation: Let R be relation on A x B and S be a relation on B x C. The composition of R and S, written S ◦ R, is a binary relation on A x C defined as follows: Examples: S ◦ R = { (a,c): a ∈ A, c ∈ C while aRb and bRc for some b ∈ B} Suppose R is the relation “is_sister_of” and S is the relation “is_mother_of” then determine S ◦ R, S ◦ S and R ◦ R. S ◦ R is the relation “is_aunt_of” S ◦ S is the relation “is_grandmother_of” R ◦ R is the relation “is_sister_of”

Discrete Math for CS A Graph Example: R = {a,b}, S = {1,2,3} and C = {x,y}. a b x y a b x y RS S ◦ R

Discrete Math for CS Composition as a Matrix Multiplication: Let A = {a 1, a 2,..., a n }, B = {b 1, b 2,..., b m } and C = {c 1, c 2,..., c k }. Let R be a relation on A x B and S be a relation on B x C. The matrices representing R and S are: The matrix representing S ◦ R, called P is: M = [m ij ] where m ij = 1 if (a i,b j ) ∈ R; 0 otherwise N = [n ij ] where n ij = 1 if (b i,c j ) ∈ S; 0 otherwise P = [p ij ] where p ij = [(m i1 and n 1j ) or (m i2 and n 2j ) or... (m in and n nj )] = 1 if a i R b k and b k S c j for at least one k = 0 otherwise in which case we say a i (S ◦ R) c j.

Discrete Math for CS A Matrix Example; R = {a,b}, S = {1,2,3} and C = {x,y}. M R = 〚〛 M S = 〚〛 M S◦R = 〚〛

Discrete Math for CS Another Example: Let A = {1, 2, 3, 4, 5} and R be a relation of A x A defined by the following matrix. If R were transitive, R ◦ R would be a subset of R and we see that it isn't. So R is not transitive. M R =   M R◦ R =       = If R is transitive then whenever xRy and yRz we know xRz. In other words, if m xy = 1 and m yz = 1 then m xz = 1. m 43 = 1m 34 = 1m 44 = 1

Discrete Math for CS Functions: A function, f, from a set A to a set B is a binary relation R f on A x B such that for every a ∈ A, there is a unique b ∈ B such that b = f(a) (ie, aR f b). From the point of view of digraphs; only one arrow leaves each node labeled by an element of A x y RfRf A B

Discrete Math for CS Examples: Which if the following relations are functions: The relation x is a brother or sister of y on the set P of people. The relation on ℤ given as {(x,x 2 ): x ∈ ℤ } The relation on ℝ given as {(x,y): x = y 2 }

Discrete Math for CS Domain and Range If f is a function from A to B then for every a in A, there is a b in B such that b = f(a) (ie (a,b) ∈ f). b is called the image of a under f. We call A the domain of f, B the codomain of f and f(A) the range of f. A B f(A)‏ f

Discrete Math for CS Graphs of functions If A and B are infinite sets we can't draw digraphs so we plot the graph on any function on A and B Example: f: ℝ ℝ, given by f(x) = x 2. (2,4)‏ The graph of y = f(x) is a subset of the real plane, ℝ 2.

Discrete Math for CS Exercise: Plot the graph of g(x) = 2 – x and identify the point (2, g(2)). (2,0)‏ (0,2)‏

Discrete Math for CS Injective Functions: Let f: A → B be a function. We say that f is injective (or 1-1) if whenever f(a 1 ) = f(a 2 ) ⇒ a 1 = a 2 for all a 1, a 2 ∈ A. Contrapositively this is the same as saying a 1 ≠ a 2 ⇒ f(a 1 ) ≠ f(a 2 ), for all a 1, a 2 ∈ A. abcabc abcabc abcabc abab Which functions are injective?

Discrete Math for CS Surjective Functions: Let f: A → B be a function. We say that f is surjective (or onto) if the range and codomain of f coincide. abcabc abcabc abcabc abab Which functions are surjective?

Discrete Math for CS Bijective Functions: Let f: A → B be a function. We say that f is bijective (or 1-1 and onto) if f is both injective and surjective. abcabc abcabc abcabc abab Which functions are bijective?

Discrete Math for CS Exercise: Show h: ℤ → ℤ defined by h(x) = x 2 is neither injective nor surjective. not injective: sufficient to find two values, a 1, a 2 ∈ ℤ where a 1 ≠ a 2 but h(a 1 ) = h(a 2 )‏ not surjective: sufficient to find a value, a 1 ∈ ℤ that is not in the range of h.

Discrete Math for CS Exercise: Show f: ℝ ℝ, given by f(x) = 4x + 3 is bijective. (0,3)‏ (-3/4,0)‏ horizontal line test

Discrete Math for CS Inverse Functions: Let f: A → B be a function. Define the relation f -1 : B → A as f -1 (b) = a if f(a) = b. If f -1 is a function we call it the inverse of f. Which functions are invertible? Reverse the arrows and ask if the new relations are functions? abcabc abcabc abcabc abab

Discrete Math for CS Inverse Functions: Let f: A → B be a function. Define the relation f -1 : B → A as f -1 (b) = a if f(a) = b. If f -1 is a function we call it the inverse of f. Which functions are invertible? Reverse the arrows and ask if the new relations are functions? abcabc abcabc abcabc abab

Discrete Math for CS Inverse Function Formulae: y = 3x – 2 is a function, what is its inverse? The answer is a bit like the “reversing arrows” answer of the previous slide. Reverse the arrows and operations: Exchange x and y in the original equation and solve for y. x = 3y – 2 x + 2 = 3y (x + 2)/3 = y y = (x+2)/3 is the inverse of the original function. times 3minus 2 x3x 3x - 2 divide by 3 add 2 (x+2)/3 x + 2x

Discrete Math for CS Inverse Function Theorem: Let f: A → B be a function. f -1 is a function if and only f is both injective and surjective. A bijective function is invertible: f = {(a,b): a ∈ A, b ∈ B} while f -1 = {(b,a): b ∈ B, a ∈ A} Since f is surjective, every b ∈ B appears as at least one f(a). Since f is injective, there is only one such a. Hence the pairs (b,a) ∈ f -1 have the property that for every b ∈ B, there is only one a ∈ A such that a = f -1 (b). Thus f -1 is a function. An invertible function is bijective: Since f is invertible, for every b ∈ B there is a unique a A such that (b,a) ∈ f -1. This (a,b) ∈ f and this shows f is surjective. Suppose f(a 1 ) = f(a 2 ) = b. Then (b,a 1 ) and (b,a 2 ) belong to f -1. However, f -1 is a function and so a 1 = a 2. Thus f is injective.

Discrete Math for CS Example: Let A = { x: x ∈ ℝ, x = 1} and f: A A given by Show f is bijective and calculate its inverse. To calculate the inverse, switch x and y and solve for y. y = f(x) = x / (x-1) If a 1 /(a 1 – 1) = a 2 /(a 2 – 1) we know a 1 a 2 – a 1 = a 2 a 1 – a 2 a 1 = a 2. Hence f is injective. For any a ∈ A we must now solve a = b/(b-1). It is easy to see that b = a/(a-1) and since a 1, this is a real number. Hence f is surjective. x = y / (y-1)‏ x(y-1) = y xy -x = y xy – y = x y(x-1) = x y= x/(x-1) so f -1 (x) = x/(x=1)‏

Discrete Math for CS Composition: Let f: A → B and g: B → C be two functions. The composite function g ∘ f: A → C is defined as {(a,c): where there is a b ∈ B such that (a,b) ∈ f and (b,c) ∈ g}. Since b, above, exists and is unique given a, g ∘ f is a function.

Discrete Math for CS Examples: Consider f: ℝ ℝ, given by f(x) = x 2 and g: ℝ ℝ  4x + 3. Calculate g ∘ f, f ∘ g, g ∘ g and f ∘ f. g ∘ f(x) = g(f(x)) = 4x f ∘ g(x) = f(g(x)) = (4x+3) 2 = 16x x + 9 g ∘ g(x) = f(g(x)) = 4(4x+3) + 3 = 16x + 15 f ∘ f(x) = f(f(x)) = (x 2 ) 2 = x 4

Discrete Math for CS Functions and Programming: Functions are the basis, in programming, of the common divide- and-conquer strategy of dealing with program complexity. Functions also are the basis of member methods in OOP. Program functions often have “side effects”. x = 3; is a function that returns the value of the right-hand-side as its value. As a side effect it assigns a new value to x. What does the function x++; return? What is its side effect?

Discrete Math for CS Functional Programming Languages: Programming languages exist that depend heavily on the concept of composition of functions. We'll look at one at the end of the chapter.

Discrete Math for CS Pigeon Hole Principle: Let A and B be two finite sets, |A| > |B| and f: A → B a function from A to B. The Pigeon Hole Principle says that there exist at least two distinct elements of A, a 1, a 2 ∈ A, a 1 != a 2 but f(a 1 ) = f(a 2 ). a1a1 a2a2 A B b If A = {a 1,..., a n } then { f(a 1 ),..., f(a n ) } B. So | { f(a 1 ),..., f(a n ) } | <= |B| <|A|. So there are fewer elements in { f(a 1 ),..., f(a n ) } than in A. This can only happen if at least two of the images under f are the same.

Discrete Math for CS 10 pigeons, 9 holes means 2 pigeons in 1 hole

Discrete Math for CS Example 1: There are 15 people on a bus. Show that at least two of them are born in the same month. Answer: PHP People Months birth month

Discrete Math for CS Observation: That wasn't so hard. We could have done that without a lot of mathematics. It turns out that not all problems that can be solved using PHP are as easy to recognize.

Discrete Math for CS Example 2: How many last names must appear in a phonebook in order to guarantee that at least two of the last names must have the same first letter and the same last letter? Let A be the set of people's last names. Let B be the set of pairs of letters from the alphabet. |B| = 26*26 = 676 In order to use the PHP we must have |A| > 676. AB f(last name) =

Discrete Math for CS Example 3: Five numbers are selected from the set of numbers 1, 2,..., 8. Show that there will always be at least two of the numbers that sum to 9. The pairs that sum to 9 are {1,8}, {2,7}, {3,6}, {4,5}. {1,8} {2,7} {3,6} {4,5} B A = any 5 numbers from 1 to 9 a1a2a3a4a5a1a2a3a4a5 f f: map the number to the set it belongs to PHP: At least two numbers must map to the same set.

Discrete Math for CS Generalization of PHP: Suppose A and B are two finite sets such that |A| > k|B| for some positive integer k. Suppose f: A → B is a function from A to B. Some element of B appears as the image of at least k+1 elements of A. Reasoning: If this were not true; each image under f would appear at most k times and so |A|/k < |B|. Hence |A| < k|B|, contradiction.

Discrete Math for CS Example 4: How many names must appear in a phone book in order to guarantee that at least 5 of the names begin with the same letter and end with the same letter. Go back to f: A → B of Example 2. B contains 676 elements. In order to 5 names to begin and end with the same letters we need to have |A| > 4|B|. In other words, at least 2705 names in the phone book.

Discrete Math for CS Example 5: In any group of 6 people, show there are either 3 people who all know each other or 3 complete strangers. Let x be one of the six people. Let A be the other 5. Let B = {0,1}. Consider the function f: A → B given by f(a) = 1 if a knows x f(a) = 0 if a does not know x. Since |A| > 2|B|, there must be - either three people who know x (f(a) = 1) or - three people who do not know x (f(a) = 0). Case 1 (three people, say a, b and c know x): Either two of a, b and c know each other. In which case, these two together with x, make three people who know each other. Or none of the three who know x, know each other so there is a set of 3 people who are mutual strangers. Case 2: (three people, a, b and c do not know x): Either two of a, b and c do not know each other. In which case, these two together with x, make three people who do not know each other.Or all three know each other so make a set of three people who know each other.

Discrete Math for CS Unexpected Implications: There are at least two people in NYC with the same number of hairs in their heads.

Discrete Math for CS Unexpected Implications: If 187 people meet at a party and there is a general shaking of hands all round, everyone greeting lots of people. Show there must be at least two people at the party who shake hands with the same number of people.

Discrete Math for CS Computer Science Uses of PHP In a hash table collisions occur when two different values hash to the same location in the table. Suppose we have a lossless compression algorithm that is used to reduce the size of input files. There must be at least one file where the algorithm actually produces a bigger file and not a smaller file