EDAA40 EDAA40 Discrete Structures in Computer Science Discrete Structures in Computer Science 2: Relations 2: Relations Jörn W. Janneck, Dept. of Computer Science, Lund University where this journey is headed, part 1 sets relations functions infinity 2 relations Mathematical relations are about connections between objects. relations between numbers a divides b, a is greater than b, a and b are prime to each other relations between sets subset of, same size as, smaller than relations between people customer/client, parent/child, spouse, employer/employee We will focus on relations between two things. Often, they have distinct roles in a relation (superset/subset, parent/child, …), i.e. we cannot model them simply as unordered pairs {a, b}. In order to properly model relations, we first need to introduce ordered pairs . 3
ordered pairs, tuples ordered pair corollary: n-tuple 4 cartesian product The ( cartesian) product of a pair of sets, or more generally a finite family of sets, is the set of all ordered pairs or n-tuples. When the sets are the same, we also write If A and B are different, then Occasionally, to avoid fussiness, the following are treated as equal: 5 cartesian product Examples: Note: 6
relations A (binary, dyadic) relation R from A to B (or over A x B ) is a subset of the cartesian product: If A and B are the same, i.e. , we also say that R is a binary relation over A. Of course, this generalizes to... An n-place relation R over A 1 x … x A n is a subset of that product: 7 notation, examples For binary relations , these are equivalent: Therefore: but 8 examples Suppose Let's define What does this relation signify? When is ? 9
source, target, domain, range For binary relations : A is a source . B is a target . Note that for any R, source and target are not uniquely determined : For any and , we have . By contrast, these are uniquely determined: the domain of R: the range of R: For any relation it is always the case that and 10 example We can represent the same information as a relation from P to Q: So that but . 11 relations as tables Mrs Othmar Schroeder Charlie Violet LRHG Patty Peggy Lydia Q Linus Lucy Sally Charlie 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 Linus 0 0 0 0 0 0 0 0 1 0 0 Lucy 1 0 0 0 0 0 0 0 0 0 0 Patty 0 1 0 0 0 0 0 0 0 0 0 Sally 0 0 0 0 0 1 0 0 0 0 0 Violet 1 0 0 0 0 0 0 0 0 0 0 Peggy 0 0 0 0 0 0 0 0 0 0 0 Lydia Schroeder 0 0 0 0 0 0 0 0 0 0 0 P 12
drawing relations: digraphs Charlie Charlie P Q Linus Linus Lucy Sally Sally Patty Patty Violet Violet Lucy Peggy Peggy Lydia Lydia Schroeder Schroeder LRHG Mrs. Othmar 13 drawing relations: digraphs Q Sally Linus Mrs. Othmar LRHG Charlie Patty Lydia Violet Peggy Lucy Schroeder 14 converse, complement For a binary relation its converse ( inverse ) is the relation some properties: For a binary relation its complement is the relation some properties: Notation: There is no firm standard for denoting converse or complement. Notation: There is no firm standard for denoting converse or complement. When using symbols such as or , the complement is often indicated When using symbols such as or , the complement is often indicated by striking through the symbol, i.e. or , while the converse is denoted by striking through the symbol, i.e. or , while the converse is denoted by reversing the symbol . by reversing the symbol . 15
converse vs complement Especially when source and target are the same, converse and complement seem to have a lot in common. Hence the importance of understanding the differences. A A a a A A a a b b c c b b c c A A converse: invert the arrows a a complement: absent arrows b b For finite A, B, given c c What are and ? 16 converse vs complement R a b c a 1 1 0 b 0 1 1 c 1 0 1 R a b c R a b c 1 0 1 0 0 1 a a b 1 1 0 b 1 0 0 c 0 1 1 c 0 1 0 converse: mirror at the diagonal complement: flip zeros and ones 17 composition Given two binary relations and their composition is a binary relation on B C A x 1 a y 2 b z 1 a 2 b 18
composition s R x y z S 1 2 a 1 1 0 x 1 0 i b 0 1 1 y 1 0 d z 0 1 e SoR 1 2 b 1 0 a b 1 1 a r What is the relationship between the tables for R and S, and their composition? 19 image Given a binary relation from A to B, for any its image under R , written R(a), is defined as Can be “lifted” to subsets : Note: 1. What is ? 2. What does it mean? 20 properties: refmexivity A binary relation is reflexive iff for all A binary relation is irreflexive iff there is no such that A A a a R a b c a 1 1 0 b b b 0 1 1 c c c 1 0 1 Other examples? What is the difference between irreflexive and not reflexive? 21
properties: transitivity A binary relation is transitive iff for all A A A A a a a a b b b b c c c c R a b c R a b c a 1 1 1 1 1 1 a b 0 1 1 b 0 0 1 c 0 0 1 c 0 0 1 Other examples? 22 properties: symmetry A binary relation is symmetric iff for all A A a a R a b c a 1 0 1 b b b 0 1 0 c c c 1 0 1 Other examples? 23 properties: a(nti)symmetry Consider and on the natural numbers. Neither is symmetric, but in slightly different ways. For , it is never the case that and . This is called asymmetry . For , it sometimes is, but only when . This is called antisymmetry . Both relations are antisymmetric. Only is asymmetric. A binary relation is asymmetric iff for all A binary relation is antisymmetric iff for all 24
equivalence relations A binary relation is an equivalence relation iff it is 1. reflexive 2. symmetric 3. transitive What about these: - equality - having the same number of elements: - divides: - relatively prime: 25 partitions Given a set A, a partition of A is a set of pairwise disjoint sets , such that A: EU citizens, I: EU member states, B i : citizens of country i A: atoms, I: elements, B i : atoms of element i A: natural numbers, I: primes, B i : multiples of i (excluding i) 26 equivalence class, quotient set Equivalence relations and partitions are really the same thing! Given a set A and an equivalence relation on A, for any we define the equivalence class of a as Alternative syntax: when the relation is understood SLAM Given a set A and an equivalence relation on A, the quotient (set) is defined as SLAM 2.5.4: 1. Every partition is the quotient of an equivalence relation. 2. Every quotient set is a partition. Review the proof in the book. Connect it to these definitions. 27
similarity relations A binary relation is a similarity relation iff it is 1. reflexive 2. symmetric What about these: - divides: - close to: Why is close-to not an equivalence relation? 28 order relation, poset A binary relation is an ( inclusive or non-strict ) ( partial ) order iff it is 1. reflexive 2. antisymmetric 3. transitive What about these: - divides: - set inclusion: - on numbers: and - proper set inclusion: A pair where A is a set and a partial order on A is called a partially ordered set or poset . Examples: 29 strict (partial) order A binary relation is a strict ( partial ) order iff it is 1. irreflexive 2. transitive Note: Irreflexivity and transitivity imply asymmetry. How? irreflexivity: transitivity: asymmetry: 30
total (or linear) order A binary relation is a ( non-strict ) total (or linear) order iff it is 1. reflexive 2. antisymmetric 3. transitive 4. total (complete): What about these: - divides: - set inclusion: - on numbers: and 31 transitive closure The transitive closure of a binary relation is defined as follows: What is the meaning of ? What are its properties? 32 how stufg is represented: pairs If all you have is (unordered) sets, s how do you represent (ordered) pairs? i For a pair (a, b), we need to be able to tell which is the first element, and which is the second. This is how (Kuratowski, 1921) : d e So the singleton set contains the first element, and the one with two elements the second. Suppose they are the same, what does (a, a) look like? b a Show that Show that r 33
Recommend
More recommend