1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 5 Relations and Functions.

Slides:



Advertisements
Similar presentations
Functions Reading: Epp Chp 7.1, 7.2, 7.4
Advertisements

Chapter 5 Relations and Functions
The Engineering Design of Systems: Models and Methods
Basic Properties of Relations
Algebraic Structures: Group Theory II
Chapter 7 Relations : the second time around
Functions Section 2.3 of Rosen Fall 2008
Discrete Structures Chapter 5 Relations Nurul Amelina Nasharuddin Multimedia Department.
Chapter 3 Review MATH130 Heidi Burgiel. Relation A relation R from X to Y is any subset of X x Y The matrix of a Relation R is a matrix that has a 1 in.
Discrete Structures Chapter 5 Relations and Functions Nurul Amelina Nasharuddin Multimedia Department.
Discrete Mathematics Lecture 7 Alexander Bukharovich New York University.
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,
Discrete Mathematics Lecture#11.
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,
Relations Chapter 9.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
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.
1 CMSC 250 Chapter 7, Functions. 2 CMSC 250 Function terminology l A relationship between elements of two sets such that no element of the first set is.
Relations: Operations & Properties. Power Sets Set of all subsets of a set A. –A = {1,2} –P(A) = 2 A = { {}, {1}, {2}, {1,2} } We note that each element.
FUNCTION Discrete Mathematics Asst. Prof. Dr. Choopan Rattanapoka.
Foundations of Discrete Mathematics Chapter 3 By Dr. Dalia M. Gil, Ph.D.
1 Relations and Functions Chapter 5 1 to many 1 to 1 many to many.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Week 15 - Wednesday.  What did we talk about last time?  Review first third of course.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
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.
R. Johnsonbaugh, Discrete Mathematics 5 th edition, 2001 Chapter 2 The Language of Mathematics.
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.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
1 Annoucement n Skills you need: (1) (In Thinking) You think and move by Logic Definitions Mathematical properties (Basic algebra etc.) (2) (In Exploration)
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Chap. 5 Relations and Functions. Cartesian Product For sets A, B the Cartesian product, or cross product, of A and B is denoted by A ╳ B and equals {(a,
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
Chapter 1 SETS, FUNCTIONs, ELEMENTARY LOGIC & BOOLEAN ALGEBRAs BY: MISS FARAH ADIBAH ADNAN IMK.
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.
Chapter 5 – Relations and Functions. 5.1Cartesian Products and Relations Definition 5.1: For sets A, B  U, the Cartesian product, or cross product, of.
Agenda Week 10 Lecture coverage: –Functions –Types of Function –Composite function –Inverse of a function.
Discrete Mathematics R. Johnsonbaugh
Discrete Mathematics Relation.
11 DISCRETE STRUCTURES DISCRETE STRUCTURES UNIT 5 SSK3003 DR. ALI MAMAT 1.
CHAPTER 3 FUZZY RELATION and COMPOSITION. 3.1 Crisp relation Product set Definition (Product set) Let A and B be two non-empty sets, the product.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
CS Lecture 14 Powerful Tools     !. Build your toolbox of abstract structures and concepts. Know the capacities and limits of each tool.
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
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.
Week 15 - Wednesday.  What did we talk about last time?  Review first third of course.
FUNCTIONS.
Week 8 - Monday.  What did we talk about last time?  Properties of functions  One-to-one  Onto  Inverses  Cardinality.
1 CMSC 250 Discrete Structures CMSC 250 Lecture 41 May 7, 2008.
Week 8 - Wednesday.  What did we talk about last time?  Relations  Properties of relations  Reflexive  Symmetric  Transitive.
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.
“It is impossible to define every concept.” For example a “set” can not be defined. But Here are a list of things we shall simply assume about sets. A.
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.
Relations Chapter 9 Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
Unit-III Algebraic Structures
Relations Chapter 9.
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.
CS201: Data Structures and Discrete Mathematics I
CSE15 Discrete Mathematics 02/27/17
Introduction to Relations and Functions
Discrete Mathematics 7th edition, 2009
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Presentation transcript:

1 Discrete and Combinatorial Mathematics R. P. Grimaldi, 5 th edition, 2004 Chapter 5 Relations and Functions

2 Relations For sets A and B, its Cartesian product (cross product) is the set of all ordered pairs (a,b) where a  A and b  B. In symbols A  B = {(a, b) | a  A and b  B} Example: A = {1, 2, 3} and B = {a, b} A  B = {(1,a),(1,b),(2,a),(2,b),(3,a),(3,b)}, A  = . For sets A and B, any subset of A  B is called a binary relation from A to B. R = {(1,a), (1,b), (2,b), (3,a)} is a relation from A to B. (1,a)  R also denotes 1Ra. For finite sets A and B with |A| = m and |B| = n, there are 2 mn relations from A to B, including the empty relation and the relation A  B itself.

3 Product on Set Operations Theorem 5.1 For any sets A, B, C   : (a) A  (B  C) = (A  B)  (A  C) (b) A  (B  C) = (A  B)  (A  C) (c) (A  B)  C = (A  C)  (B  C) (d) (A  B)  C = (A  C)  (B  C) Proof of (a). (a,b)  A  (B  C)  a  A and b  B  C  a  A and b  B and b  C  (a  A and b  B) and (a  A and b  C)  (a,b)  A  B and (a,b)  A  C  (a,b)  (A  B)  (A  C) #

4 Properties of Relations Let R be a relation on a set A, i.e., R is a subset of the Cartesian product A  A. R is reflexive ( 反身 ) if (x,x)  R, for all x  A  A = {1,2,3} reflexive: R = {(1,1),(2,2),(3,3)} not reflexive: R = {(1,1),(1,2),(2,2),(2,3)} R is symmetric ( 對稱 ) if (x,y)  R  (y,x)  R, for all x, y  A  A = {1,2,3} symmetric: R = {(1,2),(2,1),(3,3)} not symmetric: R = {(1,1),(1,2),(2,2)}

5 Properties of Relations (cont.) R is transitive ( 遞移 ) if (x,y)  R and (y,z)  R  (x,z)  R  A = {1,2,3} transitive: R = {(1,2),(2,3),(1,3),(3,1),(2,1),(1,1),(2,2),(3,2),(3,3)} not transitive: R = {(1,2),(2,3),(3,3)} R is antisymmetric ( 反對稱 ) if for all x,y  X such that x  y, if (x,y)  R  (y,x)  R  A = {1,2,3} antisymmetric: R = {(1,2),(2,3),(1,3),(1,1)} not antisymmetric: R = {(1,2),(2,1),(3,3)}

6 Relation Matrices Let X, Y be sets and R a relation from X to Y  Write the matrix M = (m ij ) of the relation as follows: Rows of M = elements of X Columns of M = elements of Y Element m i,j = 0 if the element of X in row i and the element of Y in column j are not related Element m i,j = 1 if the element of X in row i and the element of Y in column j are related

7 Example Let X = {1, 2, 3}, Y = {a, b, c, d} Let R = {(1,a), (1,d), (2,a), (2,b), (2,c)} The matrix M of the relation R is M =

8 Matrices  Let E = (e ij ) m  n, F = (f ij ) m  n be two m  n (0,1)- matrices. We say E  F if e ij  f ij for all i,j.  For n  Z +, (0,1)-matrix I n = (  ij ) n  n where  ij = 1 if i = j, otherwise  ij = 0.  Let A = (a ij ) m  n be a (0,1)-matrix. The transpose of A, denoted by A tr, is the matrix (a* ji ) n  m where a* ji = a ij for all i,j.

9 Properties of Relation Matrices Theorem 7.2 Given a set A with |A| = n and a relation R on A, Let M denote the relation matrix for R. Then (a) R is reflexive iff I n  M; (All terms m ii in the main diagonal of M are 1.) (b) R is symmetric iff M = M tr. (a ij = a ji for all i and j.) (c) R is transitive iff M 2  M. (c ij in M 2 is nonzero then entry m ij in M is also nonzero.) (d) R is antisymmetric iff M  M tr  I n.

10 M =M2=M2= M 2 32  0  m 31 m 12 +m 32 m 22 +m 33 m 32 +m 34 m 42  0  There exists k such that m 3k m k2  0  m 3k  0 and m k2  0  m 32  0. # Property (c)

11 Order Relations Let X be a set and R a relation on X.  R is a partial order on X if R is reflexive, antisymmetric and transitive. (e.g. “  ”) Let R be a partial order on X.  R is a total order (linear order) on X if every pair of elements x,y  X satisfies xRy or yRx. (e.g. topological sorting)

12 Topological Sorting a b c d e abcde 

13 Inverse of a Relation Given a relation R from X to Y, its inverse R -1 is the relation from Y to X defined by R -1 = { (y,x) | (x,y)  R } Example: If R = {(1,a), (1,d), (2,a), (2,b), (2,c)} then R -1 = {(a,1), (d,1), (a,2), (b,2), (c,2)}

14 Equivalence Relations Let X be a set and R a relation on X. R is an equivalence relation on X if R is reflexive, symmetric and transitive. (e.g. “=”)

15 Equivalence Classes Let R be an equivalence relation on a set A. For each x  A, the equivalence class of x, denoted by [x] ={ y  A | yRx }. Theorem 7.6 If R is an equivalence relation on a set A, and x, y  A, then (a) x  [x]; (b) xRy iff [x] = [y]; and (c) [x] = [y] or [x]∩[y] = .

16 Proof of Theorem 7.6 (a) By the reflexive property of R. (b) (  ) Let w  [x]. xRy and wRx  wRy. (R is transitive.)  w  [y]  [x]  [y]. R is symmetric  yRx  …  [y]  [x].  [x] = [y]. (  ) Let [x] = [y]. x  [x]  x  [y]  xRy.

17 Proof of Theorem 7.6 (cont.) (c) Assume [x]  [y] and [x]∩[y]  . Let v  A with v  [x] and v  [y].  vRx and vRy  xRv and vRy (symmetric)  xRy (transitive)  [x] = [y]. (by (b))  ∴ [x] = [y] or [x]∩[y] = . #

18 Partitions A partition S on a set X is a family {A 1, A 2,…, A n } of subsets of X, such that A 1 ∪ A 2 ∪ A 3 ∪ … ∪ A n = X A j ∩A k =  for every j,k with j  k, 1<j,k<n. Example: if X = {integers}, E = {even integers) and O = {odd integers}, then S = {E, O} is a partition of X.

19 Partitions and Equivalence Relations Theorem 7.7 If A is a set, then (a) any equivalence relation R on A induces a partition of A, and (b) any partition of A gives rise to an equivalence relation R on A. Proof. Part (a) follows from (a) and (c) of Theorem 7.6. Part (b): Let S be a partition of A. Define xRy if x, y are in the same set T for T  S. Let x  A.  x  T for some T  S. ∴ xRx and R is reflexive. Suppose xRy.  x,y  T for some T  S. ∴ yRx and R is symmetric. Suppose xRy and yRz.  x,y,z  T for some T  S. ∴ xRz and R is transitive. #

20 Functions For nonempty sets X, Y, a function, or mapping, f from X to Y, denoted by f : X  Y, is a relation from X to Y such that if two pairs (x,y) and (x,y’)  f, then y = y’.  Example: Dom(f) = X = {a, b, c, d}, Rng(f) = {1, 3, 5} f(a) = f(b) = 3, f(c) = 5, f(d) = 1.

21 How many functions? Let X,Y be nonempty sets with |X| = m and |Y| = n. Define the functions with domain X. x2x2 x1x1 xmxm y2y2 y1y1 ynyn For each x i we select one of the n elements of Y.  There are n m functions from X to Y.

22 One-to-one functions A function f : X  Y is one-to-one, injective  for each y  Y there exists at most one x  X with f(x) = y. Alternative definition: f : X  Y is one-to-one  for each pair of distinct elements x 1, x 2  X there exist two distinct elements y 1, y 2  Y such that f(x 1 ) = y 1 and f(x 2 ) = y 2. Examples: The function f(x) = 2x from the set of real numbers to itself is one-to-one The function f : R  R defined by f(x) = x 2 is not one- to-one, since for every real number x, f(x) = f(-x).

23 How many one-to-one functions? Let X,Y be nonempty sets with |X| = m and |Y| = n, where m  n. x2x2 x1x1 xmxm y2y2 y1y1 ynyn There are n choices for x 1, n-1 choices for x 2, n-2 choices for x 3, and so on.  There are P(n,m) one-to-one functions from X to Y.

24 Onto functions A function f : A  B is onto,or surjective  for each b  B there exists at least one a  A with f(a) = b, i.e. Rng(f) = B. Example: The function f: R  R defined by f(x) = x 3 is an onto function. The function g: R  R defined by g(x) = x 2 is not an onto function.

25 How many onto functions? Let X,Y be nonempty sets with |X| = 4 and |Y| = 3. x w z There are 3 4 functions from X to Y. There are 2 4 functions from X to {1,2} ({1,3},{2,3}). The set of these 2 4 functions contains the functions from X to {1} and the functions from X to {2}.  There are C(3,3)3 4 – C(3,2)2 4 + C(3,1)1 4 functions. y

26 How many onto functions? Let X,Y be nonempty sets with |X| = m and |Y| = n.  There are C(n,n)n m – C(n,n-1)(n-1) m + C(n,n-2)(n-2) m – … + (-1) n-1 C(n,1) 1 m = onto functions from X to Y. Stirling number of the second kind, denoted by S(m,n): The number of ways to distribute the m distinct objects into n identical containers, with no container left empty, is

27 Bijective functions A function f : X  Y is bijective  f is one-to-one and onto.  Examples: A linear function f(x) = ax + b is a bijective function from the set of real numbers to itself The function f(x) = x 3 is bijective from the set of real numbers to itself.  Question: Let X,Y be nonempty sets with |X| = n and |Y| = n. How many bijective functions are there from X to Y?

28 Inverse Given a function y = f(x), the inverse f -1 is the set {(y, x) | y = f(x)}.  The inverse f -1 of f is not necessarily a function. Example: if f(x) = x 2, then f -1 (4) = ± 4 1/2 = ± 2, not a unique value and therefore f -1 is not a function.  However, if f is a bijective function, it can be shown that f -1 is a function.

29 Composite Functions If f : A  B and g : B  C, we define the composite function, denoted by g ◦ f : A  C, by g ◦ f (a) = g(f(a)) for each a  A.  Example: f(x) = x 2 -1, g(x) = 3x + 5. Then f ◦ g(x) = f(g(x)) = f(3x + 5) = (3x + 5)  Composite functions are associative: f ◦ (g ◦ h) = (f ◦ g) ◦ h,  But, in general, it is not commutative: f ◦ g  g ◦ f.

30 Binary Operations For any nonempty sets A, B, any function f : A x A  B is called a binary operation on A. If B  A then the binary operation is said to closed (on A).  Examples The function f : Z x Z  Z, f(a,b) = a – b, is a closed binary operation on Z. The function g : Z + x Z +  Z, g(a,b) = a – b, is a binary operation on Z +, but it is not closed.

31 Unary Operations A function g : A  A is called a unary operation on A.  Examples: The function h : R +  R + defined by h(a) = 1/a is a unary operation on R +.

32 The Pigeonhole Principle If m pigeons occupy n pigeonholes and m > n, then at least one pigeonhole has two or more pigeons roosting in it.

33 Generalized Form If X and Y are finite sets with |X| = n, |Y| = m and k =  n/m , then there are at least k values a 1, a 2,…, a k  X such that f(a 1 ) = f(a 2 ) = … f(a k ).  Example: n = 5, m = 3 k =  n/m  =  5/3  = 2.

34 Example 1 Any subset of size 6 from the set S = {1, 2, 3, …, 9} must contains two elements whose sum is 10. Proof. Pigeons: the elements of a 6-element subset of S. Pigeonholes: the subsets {1,9},{2,8},{3,7},{4,6},{5}. By the pigeonhole principal, there are at least two elements whose sum is 10. #

35 Example 2 Prove that if 101 integers are selected from the set S = {1, 2, 3, …, 200}, then there are two integers such that one divides the other. Proof. The fundamental theorem of arithmetic: Every positive integer (except 1) can be represented in exactly one way apart from rearrangement as a product of one or more primes.  xS [x = 2 k y], with k  0, and gcd(2,y) = 1.  yT={1,3,5,…,199}. Pigeons: 101 selected integers. Pigeonholes: 100 elements of T.   two selected integers 2 m y and 2 n y. #

36 Example 3 Let m  Z + with m odd. Prove that there exists a positive integer n such that m divides 2 n – 1. Proof. Pick m+1 positive integers: 2 1 –1, 2 2 –1, 2 3 –1, …, 2 m –1, 2 m+1 –1.   s, t  Z + [( 2 s –1) mod m = ( 2 t –1) mod m], 1s<tm+1. ( By the pigeonhole principal and the division algorithm)  Let 2 s –1 = q 1 m+r and 2 t –1 = q 2 m+r.  2 t –2 s = (q 2 – q 1 )m = 2 s (2 t-s –1)  m is odd.  m| (2 t-s –1)  n = t-s. #

37 Brainstorm 假設有一座小鎮, (1) 鎮上每個人頭髮的數目都不 同﹔ (2) 沒有人的頭髮數目剛好是 500 ﹔ (3) 鎮的人口 比鎮裏任何一人頭髮的數目為多。 問題:鎮上最多有多少人?