Computing Fundamentals 1 Lecture 7 Relations Lecturer: Patrick Browne Room K308 Based on Chapter 14. A Logical approach.

Slides:



Advertisements
Similar presentations
Partial Orderings Section 8.6.
Advertisements

Relations Relations on a Set. Properties of Relations.
Discrete Mathematics Lecture 5 Alexander Bukharovich New York University.
Chapter 3 Relations. Section 3.1 Relations and Digraphs.
Chapter 7 Relations : the second time around
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
Discrete Mathematics Lecture#11.
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.
Sets.
1 Partial Orderings Aaron Bloomfield CS 202 Rosen, section 7.6.
Chapter 4 Relations and Digraphs
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Lecture 14 Relations CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
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.
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.
CS 103 Discrete Structures Lecture 10 Basic Structures: Sets (1)
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Math Chapter 6 Part II. POWER SETS In mathematics, given a set S, the power set of S, written P(S) or 2 n(S), is the set of all subsets of S. Remember.
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.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 8 Relations 歐亞書局.
Rosen, Section 8.5 Equivalence Relations
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
Discrete Mathematics Relation.
Relations and their Properties
Copyright © Cengage Learning. All rights reserved.
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.
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.
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
Discrete Mathematics Lecture # 15 Types of Relations (contd.)
1 Partial Orderings Aaron Bloomfield CS 202 Epp, section ???
DISCRETE COMPUTATIONAL STRUCTURES
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 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
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Relations.
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.
8.5 Equivalence Relations
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
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 CMSC 250 Discrete Structures CMSC 250 Lecture 41 May 7, 2008.
Chapter8 Relations 8.1: Relations and their properties.
1 Partial Orderings Epp, section Introduction An equivalence relation is a relation that is reflexive, symmetric, and transitive A partial ordering.
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
Unit-III Algebraic Structures
Introduction to Relations
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.
Relations and Digraphs
RELATION KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS )
Aaron Bloomfield CS 202 Epp, section ???
CSNB 143 Discrete Mathematical Structures
CS201: Data Structures and Discrete Mathematics I
Computing Fundamentals 1 Lecture 7 Relations
CS2210 Discrete Structures Relations
Applied Discrete Mathematics Week 6: Relations/Digraphs
교환 학생 프로그램 내년 1월 중순부터 6월 초 현재 학부 2,3 학년?
Relations: The Second Time Around
Foundations of Discrete Mathematics
Presentation transcript:

Computing Fundamentals 1 Lecture 7 Relations Lecturer: Patrick Browne Room K308 Based on Chapter 14. A Logical approach to Discrete Math By David Gries and Fred B. Schneider

The term tuple is used to describe a row in a database. Tuples are record like structure e.g.. Cross products represent the types (or sorts in CafeOBJ) in a tuple e.g. String  Nat Relations describe relationships between objects. Functions (covered in next lecture) are relations with some special properties. Relations and Functions

Given expressions b and c then  b,c  is called an ordered pair. Well known ordered pairs are  x,y  coordinates in the plane, or  name,address  in a database. Axiom, Pair equality:  b,c  =  b’,c’   b = b’  c = c’ A 2-tuple is called an ordered pair. Tuples 1

Cross Products The Cross product (or Cartesian product) S  T of two sets S and T is the set of all ordered pairs  b,c  such that b is in S and c is in T. Axiom Cross product (used in later proof): S  T = {b,c | b  S  c  T :  b,c  } Cross products can be extended to n sets producing n-tuples.

Cross Products A 2-tuple: S = {2,5} T = {1,2,3} S  T = {  2,1 ,  2,2 ,  2,3 ,  5,1 ,  5,2 ,  5,3  }

Cross Products Example of a 2-tuple: S = {Mary,John} T = {John,Bill,Brent} S  T = {  Mary, John ,  Mary,Bill ,  Mary,Brent ,  John, John ,  John,Bill ,  John,Brent  }

Cross Products Example S  T =/= T  S : S = {Mary,John} T = {John,Bill,Brent} T  S = {,,,,, } S  T = {  Mary, John ,  Mary,Bill ,  Mary,Brent ,  John, John ,  John,Bill ,  John,Brent  }

Some Theorems for Cross products Membership:  x,y   S  T  x  S  y  T Distributivity of  over  S  (T  U)  (S  T)  (S  U) (S  T)  U  (S  U)  (T  U) Monotonicity T  U  (S  T)  (S  U)

Relations A relation is a subset of a cross product B 1  B 2  …  B n A binary relation over B  C is a subset of B  C. It is possible to have a relation on B  B. Well know relation lessThan(i,j) is difficult to enumerate (or list), so use: {i,j :  | j-i is positive :  i,j  }

Relations A relation can be represented by: A Set of ordered pairs A table e.g. a tuple in a database A directed graph A set comprehension; a rule based description similar to the quantifications of Chapter 8 Two notations for membership of relation   b,c    (set of pairs) b  c (infix, conjunctional)

Relation as Directed Graph Set = {1,2,3,4,5,6} Relation = {,,,, } One vertex for each element of the set. There is a directed edge from each vertex b to vertex c iff is in the binary relation.

Diagraph of Relations Given the relation R ={,,,, } On the set {1,2,3} Below is the digraph of R

Digraph Relations is a set of ordered pairs: (a)P = {,, } (b)Q = {, } (a) (b)

Digraphs Relations as sets of ordered pairs and digraphs: (c) R = {,,, } (d) S = {,, } (c)(d)

A set of ordered pairs A Set of Relations (Ordered Pairs) With sets order is not significant {,, } = {,, } With relations order is significant =/= {,, }=/={,, }

Relations on Sets The relation R on {1,2,3,4} is defined by  R if x 2  y. The relation R can be written as a set of ordered pairs: R = {,,,,,,,,,,,, }

Some Relations The empty relation on S  T is the empty set . The identity relation i B on B is { x | x  B :  x,x  } The relation parent, b is a parent of c. The relation predecessor ( pred(x) ). The relation square root ( see book 1 ). The algorithm relation between input and output state.

Relations Lower case Greek letters represent relations. The Greek letter  is pronounced rho. The Greek letter  is pronounced sigma. The domain, Dom. , and range Ran.  of a relation  on B  C are defined as: –Dom.  = { Õ b:B | (  c |: b  c)} –Ran.  = { Õ c:C | (  b |: b  c)}

Relations Dom Ran  B C Dom.  = {b:B | (  c|: b  c)} Ran.  ={c:C | (  b|: b  c)}

Operations on Relations Let  be a relation on B  C and  be a relation C  D. The product (or composition) of  and  denoted    is defined by:  b,d       (  c | c  C :  b,c      c,d    ) B C D b c d   Alternative notation b(    )d holds iff b  c  d holds for some c.

Composing Relations

Powers of a relation For example parent  parent can be written parent 2.  0 = i B (the identity relation on B )  n+1 =  n   (for n  0)  n+m =  n   m  n  m = (  n ) m

Classes of relations NameProperty Reflexive (  b| b  b) Irreflexive (  b|  (b  b)) Symmetric (  b,c | (b  c)  (c  b))

Classes of relations Antisymmetric (  b,c | (b  c)  (c  b)  b=c) Asymmetric ( non-symmetric, see notes section ) (  b,c | (b  c)   (c  b)) Transitive (  b,c,d | (b  c)  (c  d)  b  d)

Relations Discussion Common relations

Relations Discussion  is a relation is on a set, A = {1,2,3} For  to be either reflexive and irreflexive it must hold for all of A. For  to be reflexive then  must contain the following ordered pairs {,, } The relation < (less than) is irreflexive. The relation = (equal to) is reflexive, transitive, symmetric, and antisymmetric

Relations Discussion Consider the relation square b square c iff b = c * c square is not reflexive because it does not contain { } square is not irreflexive because it does contains pair { } Thus square is neither reflexive or irreflexive. A relation that is not reflexive need not be irreflexive.

Relations Discussion For symmetric relations  does not have to hold for all of A, (b  c) need only hold where (c  b) holds and visa versa. The relation  on {1,2,3}  = {,, } is neither symmetric nor antisymmetric. It is not symmetric because there is no to match the (1,3). It is not antisymmetric because it has both and, but 1  2. Antisymmetric allows.

Relations Discussion The subset (  or  ) relation is antisymmetric. If A and B are two sets, and if A is a subset of B and B is a subset of A then A=B. (A  B)  (B  C)  (A = B) In general, a relation is antisymmetric if there is no pair of distinct elements of X each of which is related by R to each other.

Relation Properties S = { 1, 2, 3}. R2 = {,,, }. reflexive, yes symmetric, no, has and not Antisymmetric, yes, because it is not symmetric and has symmetry on. Asymmetric (which precludes ), no, because it is antisymmetric (which allows ).

Relation Properties S = { 1, 2, 3}. R1 = {,,, }. reflexive, no because doesn’t hold symmetric, yes for all then asymmetric, no, because it is symmetric. antisymmetric, no because no, with a=b.

Relation closure Example Let R = {,, } be a relation on the set A={a,b,c}. The reflexive closure is: r(R) = {,,,, } The symmetric closure is: s(R) = {,,,, }

Relation Properties Let X be the set of all four bit strings. Define a relation R on X as  R if a substring of s 1 of length 2 is equal to a substring of s 2 length 2. Examples  R  R Is this relation reflexive, symmetric, antisymmetric, and/or a partial order?

Relation Properties Is  R reflexive? Yes. Example:  R Is  R symmetric? Yes. Example:  R   R Is  R antisymmetric? No, because it is symmetric.

Relation Properties Is  R transitive? No, here is a counter example: 1000 R 1011 R 0011 Is  R partial order? No, because it is not reflexive, not antisymmetric, and not transitive. Partial order is a property of certain relations, we will look this at later in the lecture.

Reflexive or Symmetric? On the set {1, 2, 3, 4} we have relation {(1,1),(1,3),(2,2),(2,4),(3,1),(3,3),(4,2),(4,4)} We can use a matrix to check whether the relation is reflexive and symmetric. Using matrix operations we can identify the presence of many relations (not covered here)

Closure The closure of a relation  with respect to some property (e.g. reflexivity) is the smallest relation that both has the property and contains . To construct a closure, add pairs to , but not too many, until it has the property. The less-than relation is not reflexive, but the less-than-or-equal-to relation is. For example, the reflexive closure of < over integers is the relation constructed by adding to the relation all pairs (b,b) for b an integer. Therefore  is the reflexive closure of <.

Closures Reflexive closure r(<) of < on integers is . parent is the relation “b is a parent or a child of c”. Symmetric closure s(parent) of parent is (parent  child), since if is in the symmetric closure so is. Transitive closure parent + of parent is ancestor, since if and is in the transitive closure so is. The reflexive transitive closure parent* of parent-or-self.

Various Closures(OUT) Reflexive Closure r(  ) –(    0 ) Symmetric s(  ) –(    -1 ) Transitive closure  + – (  1   2   3   4..  n ) Reflexive Transitive closure  * –(  0   1   2   3   4..  n )

Sensible Closures(OUT) Let  be a relation on a set. The reflexive (symmetric, transitive) closure of  is the relation  ’ that satisfies: –  ’ is reflexive (symmetric, transitive) –    ’ –If  ’’ is reflexive (symmetric, transitive) and    ’’ then  ’   ’’. (i.e. smallest subset)

Closures Let R = {,, } be a relation on the set A={1,2,3}. Calculate the following closures: the reflexive closure, the symmetric closure,

Closures Reflexive Closure: r(R) = {,,,, } Symmetric Closure: s(R) = {,,,, } R = {,, } A={1,2,3}.

Equivalence Relations A relation is an equivalence relation iff it is reflexive, symmetric and transitive (e.g. =). An equivalence relation  on a set B partitions the set into non-empty disjoint subsets. Elements that are equivalent under  are placed in the same partition. Elements that are not equivalent under  are placed in different partitions. For example:  b,c   sameEye  b and c have same eye colour

Equivalence Relations Let  be an equivalence relation on B. Then [b] , the equivalence class of b, is the subset of elements of B that are equivalent (under  ) to b. x  [b]   x  b The sets [b]  form an equivalence  relation on B partition of B. Thus an equivalence relation on B induces a partition of B, where each partition element consists of equivalent elements.

Equivalence Relations [b] green b [c] green [d] blue c d Objects b and c are in the same partition and [b]=[c]

Equivalence Relations [b] green [c] green [d] blue Objects b and c are in the same partition and [b]green=[c]green

Equivalence Classes 1 Theorem: The equivalence classes of an equivalence relation R partition the set A into disjoint nonempty subsets whose union is the entire set. This partition is denoted A/R and called, the quotient set, or the partition of A induced by R, or A modulo R. Definition: Let S 1, S 2,..., S n be a collection of subsets of A. Then the collection forms a partition of A if the subsets are nonempty, disjoint and exhaust A : S i   S i  S j =  if i  j  S i = A

Equivalence Relations The relation b = 4 c on integers 0..9(must be +) b = 4 c  (b – c) is a multiple of 4 Their difference is a multiple of 4 We have 4 partitions [0] = [4] = [8] = {0,4,8} [1] = [5] = [9] = {1,5,9} [2] = [6] = {2,6} [3] = [7] = {3,7}

Equivalence Relations Consider the relation  defined on the set of people by: – (b  c) iff b and c are female or b and c are the same person or b is c’ s sister. Relation  is reflexive, symmetric, and transitive, so it is an equivalence relation. For female b, [b] consists of b and b ’s sisters, while the equivalence for a male c consists of only that male c.

Equivalence Relations There is a correspondence between equivalence in relations and partitions in sets.  b,c   sameEye  b and c have same eye colour

Equivalence Relations Theorem 1: Let S be a partition of a set X. Define (x R y) to mean that for some S’ in S, both x and y belong to S’. Then R is reflexive, symmetric, and transitive. Stating this another way, a relation that is reflexive, symmetric, and transitive is an equivalence relation.

Equivalence Relation(*) Let S be a partition of X which gives rise to an equivalence relation R on X. X = {1,2,3,4,5,6} S = {{1,3,5},{4},{2,6}} partition X The relation R on X is an equivalence relation therefore R is reflexive, symmetric, and transitive. Draw S. List the ordered pairs of the relation R on X. Draw the diagraph of R.

Equivalence Relation(*) Draw S = {{1,3,5},{4},{2,6}} [2] 2 2 [6] 2 [4] [1] 1 [3] 1 [5] 1 Venn Diagram The equivalence classes are subscripted according to their respective partitions

Equivalence Relation(*) List the ordered pairs of the relation R on X. R = {(1,1), (1,3),(1,5),(2,2),(2,6), (3,1),(3,3),(3,5),(4,4),(5,1), (5,3),(5,5),(6,2),(6,6)}

Equivalence Relation(*)

Graph of Equivalence Relation R = {(1,1), (1,3),(1,5),(2,2),(2,6), (3,1),(3,3),(3,5),(4,4),(5,1), (5,3),(5,5),(6,2),(6,6)}

Order Relations The order relation compares some members of a set. A typical order relation is < on integers. An order relation need not be a comparison of every member of a set, e.g. while A and B may be parents parent(A,B) may not hold.

Equivalence Relation(*) Draw P = {{a,c,e},{d},{b,f}} [b] 2 b [f] 2 [d] 3 f d a c e [a] 1 [c] 1 [e] 1 Venn Diagram The equivalence classes are subscripted according to their respective partitions

Equivalence Relation(*) Draw the diagraph of R. ac e f b d

Equivalence Relation(*) List the ordered pairs of the relation R on X. R = {(a,a), (a,c),(a,e),(b,b),(b,e), (c,a),(c,c),(c,e),(d,d),(e,a), (e,c),(e,e),(f,b),(f,f)}

Def. Partial Order Relation A binary relation  on a set b is called a partial order on B if it is Reflexive, Antisymmetric, and Transitive. is called a partially ordered set or poset. We will write partial orders using a  b and b  c. This notation differs from the course text book.

Partial Order Relation 1 Is this relation reflexive, antisymmetric, and transitive?

Hasse Diagrams Hasse diagrams are a form of simplified digraph that allow us to represent partial orders. They are simplified as follows. –Loops may be suppressed –Arrows not necessary, read from bottom to top. –Transitive arrows may be suppressed.

Order Relation on Power set. is a poset and  is a partial order on . Let B be a set. Then is a poset and  is a partial order on  B (the power set of B ), since is symmetric, antisymmetric, and transitive. Let C be the set of courses offered at DIT. Define the relation  by c1  c2 if c1=c2 or c1 is a prerequisite of c2. Then is a poset and  is a partial order on C.

Order Relation on Power set 1. A partially order set can be represented with using a POSET diagram. The POSET diagram on the right is based on the power set (all possible subsets) of the three element set {a, b, c}. These subsets form a special kind of partial order that is referred to as a lattice

Order Relation. The POSET diagram on the right is based on the power set (all possible subsets) of the three element set {1, 2, 3}.

Partial Order Relation on Divisibility 1. The set A = { 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60 } of all divisors of 60, partially ordered by divisibility.

Order Relations In the construction of a house, certain jobs have to be done before other jobs. Let J be the set of jobs and let defined on J be defined by j 1  j 2 if j 1 has to be completed before j 2 can be started. is a poset.

Total Order Relations With partial orders because not all elements need to be comparable. But some total relations give rise to “total order”. For example “less than or equal to" is a total relation over the set of real numbers, because for two numbers either the first is less than or equal to the second, or the second is less than or equal to the first. We can define a total order in two ways 1)in terms of membership and 2)in terms of operations on sets.

Total Order Definition A partial order  over B is called a total order or linear order if Def 1 (  b,c | : b  c  c  b) Def 2 iff  -1 = B  B is called a linearly ordered set or a chain.

Total Orders and are chains Let set S contain more than one element. Then  over  S is not a total order. Because if b and c are distinct elements of S, then neither {b}  {c} nor {c}  {b} holds. Any subset of a totally ordered set, with the restriction of the order on the whole set. Any partially ordered set X where every two elements are comparable (i.e. if a,b are members of X either a≤b or b≤a or both).

Partial but not Total Order Let C be the set of courses at DIT. Let b  c mean that b = c or b is a prerequisite for c. The relation is a partial order but not a total order.

Total Orders The letters of the alphabet ordered by the standard dictionary order (e.g., A < B < C ) is a partial order.

UML Association as a Relation A representation of a UML association as 1)a diagram and 2)a relation

UML Aggregation Relation Informal ‘whole-part’ relationships can be modelled using aggregation –a specialized form of an association –can have standard annotations on ends

UML: Cyclic Object Structures Aggregation is useful for ruling out invalid cyclic object structures –eg where an assembly contains itself, directly or indirectly

UML: Properties of Aggregation Aggregation rules this out because it is –antisymmetric: an object can’t link to itself –transitive: if a links to b and b to c, a links to c part end whole end

Meaning of Aggregation Sometimes there is a conflict E.g. people cannot be their own ancestors –this can be specified using aggregation –but a person’s ancestors are not a part of them! –The aggregation does not make sense in this case

Meaning (semantics) of Aggregation Relation A hand may be considered as part of a person and a person may be considered as part of an orchestra, but we would not consider hand as part of an orchestra. Heuristic: If the part moves, can one deduce that the whole moves with it in normal circumstances.