Copyright © Zeph Grunschlag, 2001-2002. Relations Zeph Grunschlag.

Slides:



Advertisements
Similar presentations
Chapter 2 Revision of Mathematical Notations and Techniques
Advertisements

CSE115/ENGR160 Discrete Mathematics 04/26/12 Ming-Hsuan Yang UC Merced 1.
8.3 Representing Relations Connection Matrices Let R be a relation from A = {a 1, a 2,..., a m } to B = {b 1, b 2,..., b n }. Definition: A n m  n connection.
Representing Relations Using Matrices
5/16/20151 You Never Escape Your… Relations. 5/16/20152Relations If we want to describe a relationship between elements of two sets A and B, we can use.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
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,
Discrete Mathematics Lecture#11.
Relations Chapter 9.
Applied Discrete Mathematics Week 10: Equivalence Relations
Logics for Data and Knowledge Representation Introduction to Algebra Chiara Ghidini, Luciano Serafini, Fausto Giunchiglia and Vincenzo Maltese.
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.
Exam 2 Review 7.5, 7.6, |A1  A2  A3| =∑|Ai| - ∑|Ai ∩ Aj| + |A1∩ A2 ∩ A3| |A1  A2  A3  A4| =∑|Ai| - ∑|Ai ∩ Aj| + ∑ |Ai∩ Aj ∩ Ak| - |A1∩
Relations (1) Rosen 6 th ed., ch. 8. Binary Relations Let A, B be any two sets. A binary relation R from A to B, written (with signature) R:A↔B, is a.
Module #18: Relations, part I
CS Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, 9:30-11:30a Fall 2002KSU - Discrete Structures1.
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
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.
An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered.
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.
Discrete Structures1 You Never Escape Your… Relations.
Discrete Mathematics Relation.
Relations and their Properties
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.
Fall 2002CMSC Discrete Structures1 You Never Escape Your… Relations.
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.
Lecture on Relations 1Developed by CSE Dept., CIST Bhopal.
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.
Lecture 4.2: Relations Basics CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Representing Relations Using Matrices A relation between finite sets can be represented using a zero-one matrix Suppose R is a relation from A = {a 1,
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
Lecture 4.2: Relations CS 250, Discrete Structures, Fall 2013 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
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.
Relations. L222 Agenda –Relations 7.3 Representing Relations As subsets of Cartesian products Column/line diagrams Boolean matrix Digraph Operations on.
RelationsCSCE 235, Spring Introduction A relation between elements of two sets is a subset of their Cartesian products (set of all ordered pairs.
Set Theory Concepts Set – A collection of “elements” (objects, members) denoted by upper case letters A, B, etc. elements are lower case brackets are used.
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.
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 B = {a,b} {( 0, a), (
Section 7.3: Representing Relations In this section, we will cover two ways to represent a relation over a finite set other than simply listing the relation.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
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.
Discrete Mathematical
Relations and Their Properties
Chapter 5 Relations and Operations
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 
Relations Chapter 9.
Lecture # 14 Types of Relations
CSE115/ENGR160 Discrete Mathematics 04/28/11
CMSC Discrete Structures
Applied Discrete Mathematics Week 10: Equivalence Relations
MimarTebebi revaz grigolia.
Applied Discrete Mathematics Week 6: Relations/Digraphs
CS 250, Discrete Structures, Fall 2014
CS 250, Discrete Structures, Fall 2015
REVISION Relation. REVISION Relation Introduction to Relations and Functions.
Agenda Lecture Content: Relations (Relasi)
Relations 12/7/2019.
Presentation transcript:

Copyright © Zeph Grunschlag, Relations Zeph Grunschlag

L222 Announcements HW9 due now HWs 10 and 11 are available Midterm 2 regrades: bring to my attention Monday 4/29 Clerical errors regarding scores can be fixed through reading period

L223 Agenda –Relations Representing Relations As subsets of Cartesian products Column/line diagrams Boolean matrix Digraph Operations on Relations Boolean Inverse Composition Exponentiation Projection Join

L224 Relational Databases Relational databases standard organizing structure for large databases Simple design Powerful functionality Allows for efficient algorithms Not all databases are relational Ancient database systems XML –tree based data structure Modern database must: easy conversion to relational

L225 Example 1 A relational database with schema : 1Kate WinsletLeonardo DiCaprio 2DoveDial 3PurpleGreen 4Movie star 1Name 2Favorite Soap 3Favorite Color 4Occupation …etc.

L226 Example 2 The table for mod 2 addition:

L227 Example 3 Example of a pigeon to crumb pairing where pigeons may share a crumb: Crumb 1 Pigeon 1 Crumb 2 Pigeon 2 Crumb 3 Pigeon 3 Crumb 4 Crumb 5

L228 Example 4 The concept of “siblinghood”.

L229 Relations: Generalizing Functions Some of the examples were function-like (e.g. mod 2 addition, or crumbs to pigeons) but violations of definition of function were allowed (not well-defined, or multiple values defined). All of the 4 examples had a common thread: They related elements or properties with each other.

L2210 Relations: Represented as Subsets of Cartesian Products In more rigorous terms, all 4 examples could be represented as subsets of certain Cartesian products. Q: How is this done for examples 1, 2, 3 and 4?

L2211 Relations: Represented as Subsets of Cartesian Products The 4 examples: 1) Database  2) mod 2 addition  3) Pigeon-Crumb feeding  4) Siblinghood 

L2212 Relations: Represented as Subsets of Cartesian Products A: 1) Database  {Names}×{Soaps}×{Colors}×{Jobs} 2) mod 2 addition  {0,1}×{0,1}×{0,1} 3) Pigeon-Crumb feeding  {pigeons}×{crumbs} 4) Siblinghood  {people}×{people} Q: What is the actual subset for mod 2 addition?

L2213 Relations as Subsets of Cartesian Products A: The subset for mod 2 addition: { (0,0,0), (0,1,1), (1,0,1), (1,1,0) }

L2214 Relations as Subsets of Cartesian Products DEF: Let A 1, A 2, …, A n be sets. An n-ary relation on these sets (in this order) is a subset of A 1 ×A 2 × … ×A n. Most of the time we consider n = 2 in which case have a binary relation and also say the the relation is “from A 1 to A 2 ”. With this terminology, all functions are relations, but not vice versa. Q: What additional property ensures that a relation is a function?

L2215 Relations as Subsets of Cartesian Products A: Vertical line test : For every a in A 1 there is a unique b in A 2 for which (a,b) is in the relation. Here A 1 is thought of as the x-axis, A 2 is the y-axis and the relation is represented by a graph. Q: How can this help us visualize the square root function:

L2216 Graph Example A: Visualize both branches of solution to x = y 2 as the graph of a relation: x y

L2217 Relations as Subsets of Cartesian Products Q: How many n-ary relations are there on A 1, A 2, …, A n ?

L2218 Relations as Subsets of Cartesian Products A: Just the number of subsets of A 1 ×A 2 × … ×A n or 2 |A1|·|A2|· … ·|An| DEF: A relation on the set A is a subset of A × A. Q: Which of examples 1, 2, 3, 4 was a relation on A for some A ? (Celebrity Database, mod 2 addition, Pigeon-Crumb feeding, Siblinghood)

L2219 Relations as Subsets: , , , -,  A: Siblinghood. A = {people} Because relations are just subsets, all the usual set theoretic operations are defined between relations which belong to the same Cartesian product. Q: Suppose we have relations on {1,2} given by R = {(1,1), (2,2)}, S = {(1,1),(1,2)}. Find: 1. The union R  S 2. The intersection R  S 3. The symmetric difference R  S 4. The difference R-S 5. The complement R

L2220 Relations as Subsets: , , , -,  A: R = {(1,1),(2,2)}, S = {(1,1),(1,2)} 1. R  S = {(1,1),(1,2),(2,2)} 2. R  S = {(1,1)} 3. R  S = {(1,2),(2,2)}. 4. R-S = {(2,2)}. 5. R = {(1,2),(2,1)}

L2221 Relations as Bit-Valued Functions In general subsets can be thought of as functions from their universe into {0,1}. The function outputs 1 for elements in the set and 0 for elements not in the set. This works for relations also. In general, a relation R on A 1 ×A 2 × … ×A n is also a bit function R (a 1,a 2, …,a n ) = 1 iff (a 1,a 2, …,a n )  R. Q: Suppose that R = “mod 2 addition” 1) What is R (0,1,0) ? 2) What is R (1,1,0) ? 3) What is R (1,1,1) ?

L2222 Relations as Bit-Valued Functions A: R = “mod 2 addition” 1) R (0,1,0) = 0 2) R (1,1,0) = 1 3) R (1,1,1) = 0 Q: Give a Java method for R (allowing true to be 1 and false to be 0)

L2223 Binary Relations A: boolean R(int a, int b, int c){ return (a + b) % 2 == c; } For binary relations, often use infix notation aRb instead of prefix notation R (a,b). EG: R = “<”. Thus can express the fact that 3 isn’t less than two with following equivalent (and confusing) notation: (3,2)  <, <(3,2) = 0, (3 < 2) = 0

L2224 Representing Binary Relations -Boolean Matrices Can represent binary relations using Boolean matrices, i.e. 2 dimensional tables consisting of 0’s and 1’s. For a relation R from A to B define matrix M R by: Rows –one for each element of A Columns –one for each element of B Value at i th row and j th column is 1 if i th element of A is related to j th element of B 0 otherwise Usually whole block is parenthesized. Q: How is the pigeon-crumb relation represented?

L2225 Representing Binary Relations -Boolean Matrices Crumb 1 Pigeon 1 Crumb 2 Pigeon 2 Crumb 3 Pigeon 3 Crumb 4 Crumb 5

L2226 Representing Binary Relations -Boolean Matrices Crumb 1 Pigeon 1 Crumb 2 Pigeon 2 Crumb 3 Pigeon 3 Crumb 4 Crumb 5 A: Q: What’s M R ’s shape for a relation on A?

L2227 Properties of Binary Relations A: Square. Special properties for relation on a set A: reflexive : every element is self-related. I.e. aRa for all a  A symmetric : order is irrelevant. I.e. for all a,b  A aRb iff bRa transitive : when a is related to b and b is related to c, it follows that a is related to c. I.e. for all a,b,c  A aRb and bRc implies aRc Q: Which of these properties hold for: 1) “Siblinghood”2) “<”3) “  ”

L2228 Properties of Binary Relations A: 1) “Siblinghood”: not reflexive (I’m not my brother), is symmetric, is transitive. If ½-brothers allowed, not transitive. 2) “<”: not reflexive, not symmetric, is transitive 3) “  ”: is reflexive, not symmetric, is transitive DEF: An equivalence relation is a relation on A which is reflexive, symmetric and transitive. Generalizes the notion of “equals”.

L2229 Properties of Binary Relations Warnings Warnings: there are additional concepts with confusing names antisymmetric : not equivalent to “not symmetric”. Meaning: it’s never the case for a  b that both aRb and bRa hold. asymmetric : also not equivalent to “not symmetric”. Meaning: it’s never the case that both aRb and bRa hold. irreflexive : not equivalent to “not reflexive”. Meaning: it’s never the case that aRa holds.

L2230 Visualizing the Properties For relations R on a set A. Q: What does M R look like when when R is reflexive?

L2231 Visualizing the Properties A: Reflexive. Upper-Left corner to Lower- Right corner diagonal is all 1’s. EG: M R = Q: How about if R is symmetric?

L2232 Visualizing the Properties A: A symmetric matrix. I.e., flipping across diagonal does not change matrix. EG: M R =

L2233 Inverting Relations Relational inversion amounts to just reversing all the tuples of a binary relation. DEF: If R is a relation from A to B, the composite of R is the relation R -1 from B to A defined by setting cR -1 a if and only aRc. Q: Suppose R defined on N by: xRy iff y = x 2. What is the inverse R -1 ?

L2234 Inverting Relations A: xRy iff y = x 2. R is the square function so R -1 is sqaure root: i.e. the union of the two square- root branches. I.e: yR -1 x iff y = x 2 or in terms of square root: xR -1 y iff y = ±  x where x is non-negative

L2235 Composing Relations Just as functions may be composed, so can binary relations: DEF: If R is a relation from A to B, and S is a relation from B to C then the composite of R and S is the relation S  R (or just SR ) from A to C defined by setting a (S  R )c if and only if there is some b such that aRb and bSc. Notation is weird because generalizing functional composition: f  g (x) = f (g (x)).

L2236 Composing Relations Q: Suppose R defined on N by: xRy iff y = x 2 and S defined on N by: xSy iff y = x 3 What is the composite SR ?

L2237 Composing Relations Picture xRy iff y = x 2 xSy iff y = x 3 A: These are functions (squaring and cubing) so the composite SR is just the function composition (raising to the 6 th power). xSRy iff y = x 6 (in this odd case RS = SR ) Q: Compose the following:

L2238 Composing Relations Picture A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4

L2239 Composing Relations Picture A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4

L2240 Composing Relations Picture A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4

L2241 Composing Relations Picture A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4

L2242 Composing Relations Picture A: Draw all possible shortcuts. In our case, all shortcuts went through 1:123 4

L2243 Exponentiation A relation R on A can be composed with itself, so can exponentiate: DEF: Q: Find R 3 if R is given by:1234

L2244 Exponentiation A:R R

L2245 Exponentiation A:R R R

L2246 Exponentiation A:R R R R 2 R

L2247 Exponentiation A:R R R R 2 R R

L2248 Digraph Representation The last way of representing a relation R on a set A is with a digraph which stands for “directed graph”. The set A is represented by nodes (or vertices) and whenever aRb occurs, a directed edge (or arrow) a  b is created. Self pointing edges (or loops) are used to represent aRa. Q: Represent previous page’s R 3 by a digraph.

L2249 Digraph Representation R 31234

L2250 Digraph Representation R A:

L2251 Database Operations Many more operations are useful for databases. We’ll study 2 of these: Join: a generalization of intersection as well as Cartesian product. Projection: restricting to less coordinates.

L2252 Join The join of two relations R, S is the combination of the relations with respect to the last few types of R and the first few types of S (assuming these types are the same). The result is a relation with the special types of S the common types of S and R and the special types of R. I won’t give the formal definition (see the book). Instead I’ll give examples:

L2253 Join EG: Suppose R is mod 2 addition and S is mod 2 multiplication: R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) } S = { (0,0,0), (0,1,0), (1,0,0), (1,1,1) } In the 2-join we look at the last two coordinates of R and the first two coordinates of S. When these are the same we join the coordinates together and keep the information from R and S. For example, we generate an element of the join as follows: (0,1,1) (1,1,1) 2-join (0,1,1,1)

L2254 Join R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) } S = { (0,0,0), (0,1,0), (1,0,0), (1,1,1) } We use the notation J 2 (R,S) for the 2-join. J 2 (R,S) = { (0,0,0,0), (0,1,1,1), (1,0,1,0), (1,1,0,0) } Q: For general R,S, what does each of the following represent? 1) J 0 (R,S) 2) J n (R,S) assuming n is the number of coordinates for both R and S.

L2255 Join For general R,S, what does each of the following represent? 1) J 0 (R,S) is the Cartesian product 2) J n (R,S) is the intersection when n is the number of coordinates

L2256 Projection Projection is a “forgetful” operation. You simply forget certain unmentioned coordinates. EG, consider R again: R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) } By projecting on to the 1 st and 3 rd coordinates, we simply forget the 2 nd coordinate. we generate an element of the 1,3 projection as follows: 1,3 projection (0,1,1)(0,1)

L2257 Projection R = { (0,0,0), (0,1,1), (1,0,1), (1,1,0) } We use the notation P 1,3 (R) for 1,3 projection. P 1,3 (R) = { (0,0), (0,1), (1,1),(1,0) }

L2258 Relations Blackboard Exercises 1. Define the relation R by setting R(a,b,c) = “a b = c“ with a,b,c non-negative integers. Describe in English what P 1,3 (R ) represents. 2. Define composition in terms of projection and join.