Discrete Structure Li Tak Sing( 李德成 ) Lectures 16,17,18,19 1.

Slides:



Advertisements
Similar presentations
Partial Orderings Section 8.6.
Advertisements

Chapter 2 Revision of Mathematical Notations and Techniques
Relations Relations on a Set. Properties of Relations.
Equivalence, Order, and Inductive Proof
Chapter 3 Relations. Section 3.1 Relations and Digraphs.
1 Chapter Equivalence, Order, and Inductive Proof.
8.6 Partial Orderings. Definition Partial ordering– a relation R on a set S that is Reflexive, Antisymmetric, and Transitive Examples? R={(a,b)| a is.
Chap6 Relations Def 1: Let A and B be sets. A binary relation from A
Chapter 7 Relations : the second time around
Discrete Structures Chapter 5 Relations Nurul Amelina Nasharuddin Multimedia Department.
CSE115/ENGR160 Discrete Mathematics 05/03/11 Ming-Hsuan Yang UC Merced 1.
Relations binary relations xRy on sets x  X y  Y R  X  Y Example: “less than” relation from A={0,1,2} to B={1,2,3} use traditional notation 0 < 1,
Equivalence Relations: Selected Exercises
Discrete Mathematics Lecture#11.
1 Partial Orderings Based on Slides by Chuck Allison from Rosen, Chapter 8.6 Modified by.
Partially Ordered Sets (POSets)
Relations Chapter 9.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
Exam 2 Review 8.2, 8.5, 8.6, Thm. 1 for 2 roots, Thm. 2 for 1 root Theorem 1: Let c 1, c 2 be elements of the real numbers. Suppose r 2 -c 1.
Mathematical Preliminaries Strings and Languages Preliminaries 1.
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.
Chapter 5 Context-Free Grammars
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.
2.6 Equivalence Relation §1.Equivalence relation §Definition 2.18: A relation R on a set A is called an equivalence relation if it is reflexive, symmetric,
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.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
8.3 Representing Relations Directed Graphs –Vertex –Arc (directed edge) –Initial vertex –Terminal vertex.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Relations and their Properties
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Mathematical Preliminaries
Sets and Subsets Set A set is a collection of well-defined objects (elements/members). The elements of the set are said to belong to (or be contained in)
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Discrete Mathematics Lecture # 15 Types of Relations (contd.)
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Problem Statement How do we represent relationship between two related elements ?
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.)
1 Section 4.3 Order Relations A binary relation is an partial order if it transitive and antisymmetric. If R is a partial order over the set S, we also.
Chapter Relations and Their Properties
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Relations Section 9.1, 9.3—9.5 of Rosen Spring 2012
Chapter 8: Relations. 8.1 Relations and Their Properties Binary relations: Let A and B be any two sets. A binary relation R from A to B, written R : A.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
1 Section 4.2 Equivalence Relations A binary relation is an equivalence relation if it has the three properties reflexive, symmetric, and transitive (RST).
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
1 Partial Orderings Based on Slides by Chuck Allison from Rosen, Chapter 8.6 Modified by.
Advanced Digital Designs Jung H. Kim. Chapter 1. Sets, Relations, and Lattices.
1 CMSC 250 Discrete Structures CMSC 250 Lecture 41 May 7, 2008.
Chapter8 Relations 8.1: Relations and their properties.
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.
Relations and Their Properties
Chapter 5 Relations and Operations
CSE 2813 Discrete Structures
Unit-III Algebraic Structures
Partial Orderings CSE 2813 Discrete Structures.
CSE15 Discrete Mathematics 05/03/17
Relations Binary relations represent relationships between the elements of two sets. A binary relation R from set A to set B is defined by: R  A 
Equivalence Relations
Relations Chapter 9.
Partial Orderings.
Introductory Material
Chapter 1 Introduction to the Theory of Computation
Relations.
교환 학생 프로그램 내년 1월 중순부터 6월 초 현재 학부 2,3 학년?
Foundations of Discrete Mathematics
Introductory Material
Presentation transcript:

Discrete Structure Li Tak Sing( 李德成 ) Lectures 16,17,18,19 1

From grammar to inductive definition Consider the following grammar:  S  |aB  B  b|bB Basis: , ab  L(G) Induction: if ay  L(G), then aby  L(G). 2

Constructing grammars 1.{a n |n  N} S  |aS 2.{a n b n |n  N} S  |aSb 3.{(ab) n |n  N} S  |abS 3

Combining grammars Suppose M and N are languages whose grammars have disjoint sets of non-terminals. Suppose also that the start symbols for the grammars of M and N are A and B respectively. Then we have the following new languages and grammars:  Union rule: the language M  N starts with the two productions: S  A|B  Product Rule: the language MN starts with the productions: S  AB  Closure Rule: The language M* starts with the productions: S  AS|  4

Examples Write the grammar for each of the following languages. 1.{a n bc m |m,n  N} 2.{ , a, ab, aab, aaab,....} 3.{a, ba, bba, bbba,....} 4.{a n b n |n  N}* 5.{a n b n |n  N}  {c n |n  1} 5

Solution 1.S  aS|Sc|b 2.S  |aB B  |bB 3.S  bS|a 4.S  AS|  A  aAb|  5.S  A|B A  aAb|  B  c|cB 6

Meaning and ambiguity A grammar is said to be ambiguous if its language contains some string that has two different parse trees. This is equivalent to saying that some string has two distinct leftmost derivations or that some string has two distinct rightmost derivations. 7

Ambiguity Consider the grammar.  E  a|b|E-E The string a-b-a has the following distinct derivations. E  E-E  a-E  a-E-E  a-b-E  a-b-a E  E-E  E-E-E  a-E-E  a-b-E  a-b-a The former one has the meaning of a-(b-a) The latter one has the meaning of (a-b)-a 8

Removing the ambiguity If we change the grammar as this:  E  E-T|T  T  a|b In the above grammar, T can only be replaced by a or b. So only the right operand can be further expands to another expression that have -. So a-b-a will only be expanded to have the meaning of (a-b)- a 9

Ambiguity Show that each of the following grammers is ambiguous. In other words, find a string that has two different parse trees (equivalently, two different leftmost derivations or two different rightmost derivations) 1.S  a|SbS. 2.S  abB|AB and A  |Aa and B  |bB. 3.S  aS|Sa|a 4.S  aS|Sa|b 5.S  Ab|A and A  b|bA 10

Solution 1.Consider the string ababa. This can be expanded as: S  SbS  abS  abSbS  ababS  ababa, or S  SbS  SbSbS  abSbS  ababS  ababa 2.Consider the string abb S  abB  abbB  abb, or S  AB  AaB  aB  abB  abbB  abb 11

Solution 3.Consider the string aaa S  aS  aaS  aaa, or S  Sa  Saa  aaa 4.Consider the string aba S  aS  aSa  aba,or S  Sa  aSa  aba 5.Consider the string bb S  Ab  bb, or S  A  bA  bb 12

More Examples Find grammars for the following languages: 1.{a n b m c m d n | m,n  N} 2.{a n b m cd n | m,n  N} 3.{a n b m c m d| m,n  N} 4.{ab m c m d| m,n  N} 5.ab m cd m | m  N} 13

Solution 1.S  aSd|A A  bAc|  2.S  aSd|A A  bA|c 3.S  aS|Ad A  bAc|  4.S  aAd A  bAc|  5.S  aA A  bAd|c 14

Chapter 4 Properties of Binary Relations Three special properties  For a binary relation R on a set A, we have the following definitions. R is reflexive if xRx for all x  A. R is symmetric if xRy implies yRx for all x,y  A R is transitive if xRy and yRz implies xRz for all x,y,z  A 15

Two opposite properties For a binary relation R on a set A, we have the following definitions.  R is irreflexive if (x,x)  R for all x  A.  R is antisymmetric if xRy and yRx implies x=y for all x,y  A. 16

Example R is a binary relation on N aRb if (a+b) mod 2 = 0 R is reflexive because (a+a) mod 2 =0 for all a  N R is symmetric because if aRb, then (a+b) mod 2 = 0, then (b+a) mod 2 =0, then bRa R is transitive, because if aRb and bRc, then (a+b) mod 2 =0 and (b+c) mod 2 =0, then (a+2b+c) mod 2 =0, then (a+c) mod 2 =0, then aRc 17

Example Give examples of binary relations over the set {a,b,c,d} with the stated properties: 1.Reflexive and not symmetric and not transitive 2.Symmetric and not reflexive and not transitive 3.transitive and not reflexive and not symmetric 18

Solution 1.{(a,a),(b,b),(c,c),(d,d),(a,b),(b,c)} 2.{(a,b),(b,a)} 3.{(a,b),(b,b)} 19

Composition of relations If R and S are binary relations, then the composition of R and S, which we denote by S  R, is the following relation: S  R={(a,c)|(a,b)  R and (b,c)  S for some element b} 20

More examples For each of the following binary relations state which of the three properties, reflexive, symmetric and transitive are satisfied. 1.xRy iff |x-y| is odd, over the integers. 2.xRy iff x is a parent of y, over the set of people. 21

Solution 1.Not reflexive, symmetric, not transitive, irreflexive, not anti-symmetric 2.Not reflexive, not symmetric, not transitive, irreflexive, anit-symmetric 22

Grandparents Given the isParentOf relation. So a isParentOf b represents the fact that a is the parent of b. isGrandparentOf can then be defined in terms of isParentOf. isGrandparentOf=isParentOf  isParentOf So a isGrandparentOf b if there is c so that a isParentOf c and c isPrentOf b. 23

More examples Given the following binary relations over {a,b,c,d}. R={(a,a),(a,c),(b,a),(b,d),(c,b)} S={(a,b),(a,c),(c,b),(d,c)} 1.Find S  R 2.Find R  S 24

Solution 1.{(a,b),(a,c),(b,b),(b,c)} 2.{(a,a),(a,d),(a,b),(c,a),(c,d),(d,b)} 25

Representations If R is a binary relation on A, then we'll denote the composition of R with itself n times by writing R n. For example,  isGrandparentOf=isParentOf 2  isGreatGrandParentOf=isParentOf 3 26

Inheritance properties If R is reflexive, then R n is reflexive. If R is symmetric, then R n is symmetric. If R is transitive, then R n is transitive. 27

Example Let R={(x,y)  Z  Z|x+y is odd}. We want to find out R 2 and R 3. 28

Solution R 2 ={(x,y)|x+y is even} R 3 =R 29

Closures If R is a binary relation and p is some property, then the p closure of R is the smallest binary relation containing R that satisfies property p. 30

Reflexive closure A reflexive closure of R is the smallest reflexive relation that contains R. A reflexive closure of R is denoted as r(R) R is a relation over {a,b,c} and R={(a,b),(b,c)} Then, r(R)={(a,a),(b,b),(c,c),(a,b),(b,c)} 31

Symmetric closure A symmetric closure of R is the smallest symmetric relation that contains R. A symmetric closure of R is denoted as s(R) R={(a,b),(b,c)}, s(R)={(a,b),(b,a),(b,c),(c,b)} 32

Transitive closure A transitive closure of R is the smallest transitive relation that contains R. It is denoted as t(R). R= {(a,b),(b,c)}, then t(R)= {(a,b),(b,c),(a,c)} 33

Constructing Closures If R is a binary relation over a set A, then:  r(R)=R  R o (R o is the equality relation)  s(R)=R  R c (R c is the converse relation)  t(R)=R  R 2  R 3  R  If A is finite with n elements, then t(R)= R  R 2  R 3  R  R n 34

Example Given the set A={a,b,c,d}. Draw a directed graph to represent the indicated closure for each of the following binary relations over A. 1.r(R), where R={(a,d)} 2.s(R) where R={(a,b), (c,d)} 3.t(R) where R={(a,b),(d,a),(d,c),(c,b)} 35

Solution 1.r(R)={(a,a),(b,b),(c,c),(d,d),(a,d)} 2.s(R)={(a,b),(b,a),(c,d),(d,c)} 1.t(R) ={(a,b),(d,a),(d,c),(c,b),(d,b)} 36

Equivalence relations Any binary relation that is reflexive, symmetric, and transitive is called an equivalence relation. 37

Sample equivalence relations R is over N, xRy means x+y is even R is over real number, xRy means sin(x)=sin(y) 38

Examples 1.Let R be defined on N by xRy iff |x-y| is odd. Show that R is not an equivalance relation on N. 2.Given the relation over the integers defined by a~b iff |a|=|b|, either prove that ~ is an equivalence relation or prove that ~ not an equivalence relation. 39

Solution 1.R is not reflexive, is symmetric, is not transitive. 2.~ is an equivalence relation. It is reflexive because |a|=|a| for all a  Z. It is symmetric because a~b  |a|=|b|  |b|=|a|  b~a It is transitive because a~b and b~c  |a|=|b| and |b|=|c|  |a|=|c|  a~c 40

Intersection property of equivalence If E and F are equivalence relations on the set A, then E  F is an equivalence relation on A. 41

Kernel relations If f is a function with domain A, then the relation ~ defined by x~y iff f(x)=f(y) is an equivalence relation on A, and it is called the kernel relation of f. 42

Equivalence classes Let R be an equivalence relation on a set S. If a  S, then the equivalence class of a, denoted by [a], is the subset of S consisting of all elements that are equivalent to a. In other words, we have [a]={x  S | xRa} 43

Example of equivalence class a~b iff a+b is even a~b iff sin(a)=sin(b) 44

Property of equivalences Let S be a set with an equivalence relation R. If a, b  S, then either [a]=[b] or [a]  [b]= . Proof. If [a]  [b], and [a]  [b]  , there is an element c so that c  [a] and c  [b]. So we have aRc and cRb, therefore aRb. Now, for any x  [a], xRa. Since aRb, therefore we have xRb which implies that x  [b]. Therefore, [a]  [b]. Similarly, we have [b]  [a]. 45

Partitions By a partition of a set we mean a collection of nonempty subsets that are disjoint from each other and whose union is the whole set. If R is an equivalence relation on the set S, then the equivalence classes form a partition of S. Conversely, if P is a partition of a set S, then there is an equivalence relation on S whose equivalence classes are sets of P. 46

Refinement of a partition Suppose that P and Q are two partitions of a set S. If each set of P is a subset of a set in Q, then P is a refinement of Q. The finest of all partitions on S is the collection of singleton sets. The coarsest of all partitions of S is the set S itself. 47

Example aRb iff a  b (mod 2) aSb iff a  b (mod 4) 48

Example Given the following set of words. {rot, tot, root, toot, roto, toto, too, to,otto}. 1.Let f be the function that maps word to its set of letters. For kernel relation of f, describe the equivalence classes. 2.Let f be the function that maps a word to its bag of letters. For the kernel relation of f, describe the equivalence classes. 49

Solution 1.[rot]={rot,root,roto} [to]={to,toot,toto,too,to,otto} 50

Kruskai's algorithm for minimal spanning trees In the spanning tree problems, we can define a relation R so that aRb if there is a path between a and b. The algorithm is: 51

Kruskal's Algorithm Sort the edges of the graph by weight, and let L be the sorted list. Let T be the minimal spanning tree and initialize T:= . For each vertex v of the graph, create the equivalence class [v]={v} while there are 2 or more equivalence classes do Let {a,b} be the edge at the head of L; L:=tail(L); if [a]  [b] then T:=T  {{a,b}}; Replace the equivalence classes [a] and [b] by [a]  [b] fi od 52

Spanning trees 53

Solution 54 L[v]T ad,bc,cf,ea,ab,ed,dc,ef{a},{b},{c},{d},{e},{f} bc,cf,ea,ab,ed,dc,ef{a,d},{b},{c},{e},{f}ad cf,ea,ab,ed,dc,ef{a,d},{b,c},{e},{f}ad,bc ea,ad,ed,dc,ef{a,d},{b,c,f},{e}ad,bc,cf ad,ed,dc,ef{a,d,e},{b,c,f}ad,bc,cf,ea ed,dc,ef{a,d,e},{b,c,f}ad,bc,cf,ea dc,ef{a,d,e},{b,c,f}ad,bc,cf,ea ef{a,d,e,b,c,f}ad,bc,cf,ea,dc

Spanning trees 55

Solution L{v}T ab,bf,bc,dc,ea,ac,ed,ef,fd{a},{b},{c},{d},{e},{f} bf,bc,dc,ea,ac,ed,ef,fd{b,f},{a},{c},{d},{e}ab bc,dc,ea,ac,ed,ef,fd{b,c,f},{a},{d},{e}ab,bf dc,ea,ac,ed,ef,fd{b,c,f},{a},{d},{e}ab,bf ea,ac,ed,ef,fd{b,c,f,d},{a},{e}ab,bf,dc ac,ed,ef,fd{b,c,f,d},{a,e}ab,bf,dc,ea ed,ef,fd{b,c,f,d,a,e}ab,bf,dc,ea,ac 56

Order relations Two essential properties of order  it is transitive: if a>b and b>c then a>c  it is anitsymetric: we cannot have a<b and b<a. If a  b and b  a, then a=b. 57

A Pancake recipe Suppose we have the following recipe for making pancakes. 1.Mix the dry ingredients (flour, sugar, baking powder) in a bowl. 2.Mix the wet ingredients (milk, eggs) in a bowl. 3.Mix the wet and dry ingredients together. 4.Oil the pan. 5.Heat the pan. 6.Make a test pancake and throw it away. 7.Make pancakes. 58

A Pancake recipe We see that some steps are need to be done before others. We can show this order as a digraph: 59

A Pancake recipe We can see that there can be many valid orders:  4,5,2,1,3,6,7  1,2,3,4,5,6,7 

A Pancake recipe We can define a relation R as: xRy means that step x must be done before step y R is irreflexive because a step cannot be done before itself. R is antisymetric because when a step has to be done before another, it cannot done the other way round. R is transitive. 61

Partial order A binary relation is called a partial order if it is anitsysmetric and transitive. The set over which a partial order is defined is called a partially ordered set- or poset for short. If we want to emphasize the fact that R is the partial order that makes S a poset, we'll write and call it a poset. It is called partial order because not all elements are related. For example, steps 1 and 2 of the pancake example are not related, i.e., there is no order of steps 1,2. 62

Total order Suppose R is a binary relation on a set S and x, y in S. We say that x and y are comparable if either xRy or yRx. In other words, elements that are related are comparable. If every pair of distinct elements in a partial order are comparable, then the order is called a total order (also called a linear order). If R is a total order on the set S, then we also say that S is a totally ordered set or linearly ordered set. 63

Example is a poset because  | is transitive: a|b and b|c implies a|c  | is antisymmetric: if a|b, then either a=b or b does not divides b.  is not total ordered because there are some elements in N that is not related under |. For example, 3 and 5 are not related under |. is a totally ordered set because for any m,n  N, either 2 n |2 m or 2 m |2 n. 64

reflexive partial order and irreflexive partial order If a partial order is reflexive, we call it reflexive partial order. If a partial order is irreflexive, we call it irreflexive partial order. is reflexive partial order. is irreflexive partial order. 65

Notation for Partial orders 66

Notation for Partial orders 67

Notation for Partial orders 68

Chains 69

Predecessors and Successors 70

Poset diagrams 71

Example Draw a poset diagram of the partial order defined by the subset relation on power({a,b,c}). 72

Maxima, Minima, and Bounds 73

Maxima, Minima, and Bounds For example: has a least element  <{{a,b},{a},{b}} has two minimal elements, {a} and {b} but no least element. has two minimal elements, 2 and 5 but no least element. 74

Maxima, Minima, and Bounds 75

Maxima, Minima, and Bounds For example: has a greatest element {a,b,c} <{{a,b},{a},{b}} has a greatest element {a,b} has two maximal elements, 4 and

Maxima, Minima, and Bounds Some sets may not have any minimal elements, yet still be bounded below by some element. For example, the set of positive rational numbers has no least element yet is bounded below by the number 0. 77

Maxima, Minima, and Bounds 78

Maxima, Minima, and Bounds 79

Example 80

Example 5.The lower bounds of S. 6.The upper bounds of S. 7.The lub of S. 8.The glb of S. 81

Solution 82