1 Representing Relations Rosen, section 7.3 CS/APMA 202 Aaron Bloomfield.

Slides:



Advertisements
Similar presentations
Binomial Coefficients
Advertisements

Representing Relations Rosen 7.3. Using Matrices For finite sets we can use zero-one matrices. Elements of each set A and B must be listed in some particular.
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.
1 Section 7.3 Representing relations (part 1: matrices)
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.
Discrete Mathematics Lecture # 16 Inverse of Relations.
CS2210(22C:19) Discrete Structures Relations Spring 2015 Sukumar Ghosh.
1 Representing Relations Part 2: directed graphs.
1 Set Operations CS/APMA 202, Spring 2005 Rosen, section 1.7 Aaron Bloomfield.
1 The Pigeonhole Principle CS/APMA 202 Rosen section 4.2 Aaron Bloomfield.
1 Integers and Division CS/APMA 202 Rosen section 2.4 Aaron Bloomfield.
MATRICES. Matrices A matrix is a rectangular array of objects (usually numbers) arranged in m horizontal rows and n vertical columns. A matrix with m.
1 Representing Relations Epp section ??? CS 202 Aaron Bloomfield.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
Applied Discrete Mathematics Week 10: Equivalence Relations
Recursive Definitions and Structural Induction
1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield.
1 Partial Orderings Aaron Bloomfield CS 202 Rosen, section 7.6.
1 Permutations and Combinations CS/APMA 202 Rosen section 4.3 Aaron Bloomfield.
1 Relations and Their Properties Epp, section ??? CS 202 Aaron Bloomfield.
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
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.
1 Predicates and Quantifiers CS/APMA 202, Spring 2005 Rosen, section 1.3 Aaron Bloomfield.
Lecture 7 Matrices CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
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.
1 Relations and Their Properties Rosen, section 7.1 CS/APMA 202 Aaron Bloomfield.
Rosen, Section 8.5 Equivalence Relations
Representing Relations
Fall 2002CMSC Discrete Structures1 You Never Escape Your… Relations.
Matrices Section 2.6. Section Summary Definition of a Matrix Matrix Arithmetic Transposes and Powers of Arithmetic Zero-One matrices.
Lecture on Relations 1Developed by CSE Dept., CIST Bhopal.
1 Partial Orderings Aaron Bloomfield CS 202 Epp, section ???
1 Basics of Counting CS/APMA 202 Rosen section 4.1 Aaron Bloomfield.
CSNB143 – Discrete Structure Topic 3 – Matrices. Learning Outcomes Students should understand all matrices operations. Students should be able to differentiate.
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.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
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,
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.
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.
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.
1 Closures of Relations Based on Aaron Bloomfield Modified by Longin Jan Latecki Rosen, Section 8.4.
Section 9.3. Section Summary Representing Relations using Matrices Representing Relations using Digraphs.
CS 285- Discrete Mathematics Lecture 11. Section 3.8 Matrices Introduction Matrix Arithmetic Transposes and Power of Matrices Zero – One Matrices Boolean.
A very brief introduction to Matrix (Section 2.7) Definitions Some properties Basic matrix operations Zero-One (Boolean) matrices.
Chapter8 Relations 8.1: Relations and their properties.
Discrete Mathematical
Relations and Their Properties
Chapter 5 Relations and Operations
Relations.
Relations and Their Properties
Relations Chapter 9.
Aaron Bloomfield CS 202 Rosen, section 7.4
Relations and Digraphs
Representing Relations
RELATION KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS )
Relations and Their Properties
Permutations and Combinations
Applied Discrete Mathematics Week 10: Equivalence Relations
CS2210 Discrete Structures Relations
Relations and Their Properties
CS100: Discrete structures
Combining relations via relational composition
4.4 Properties of Relations
Presentation transcript:

1 Representing Relations Rosen, section 7.3 CS/APMA 202 Aaron Bloomfield

2 In this slide set… Matrix review Two ways to represent relations –Via matrices –Via directed graphs

3 Matrix review This is from Rosen, page 201 and 202 We will only be dealing with zero-one matrices –Each element in the matrix is either a 0 or a 1 These matrices will be used for Boolean operations –1 is true, 0 is false

4 Matrix transposition Given a matrix M, the transposition of M, denoted M t, is the matrix obtained by switching the columns and rows of M In a “square” matrix, the main diagonal stays unchanged

5 Matrix join A join of two matrices performs a Boolean OR on each relative entry of the matrices –Matrices must be the same size –Denoted by the or symbol: 

6 Matrix meet A meet of two matrices performs a Boolean AND on each relative entry of the matrices –Matrices must be the same size –Denoted by the or symbol: 

7 Matrix Boolean product A Boolean product of two matrices is similar to matrix multiplication –Instead of the sum of the products, it’s the conjunction (and) of the disjunctions (ors) –Denoted by the or symbol:  

8 Relations using matrices List the elements of sets A and B in a particular order –Order doesn’t matter, but we’ll generally use ascending order Create a matrix

9 Relations using matrices Consider the relation of who is enrolled in which class –Let A = { Alice, Bob, Claire, Dan } –Let B = { CS101, CS201, CS202 } –R = { (a,b) | person a is enrolled in course b } CS101CS201CS202 Alice X Bob XX Claire Dan XX

10 Relations using matrices What is it good for? –It is how computers view relations A 2-dimensional array –Very easy to view relationship properties We will generally consider relations on a single set –In other words, the domain and co-domain are the same set –And the matrix is square

11 Reflexivity Consider a reflexive relation: ≤ –One which every element is related to itself –Let A = { 1, 2, 3, 4, 5 } If the center (main) diagonal is all 1’s, a relation is reflexive

12 Irreflexivity Consider a reflexive relation: < –One which every element is not related to itself –Let A = { 1, 2, 3, 4, 5 } If the center (main) diagonal is all 0’s, a relation is irreflexive

13 Symmetry Consider an symmetric relation R –One which if a is related to b then b is related to a for all (a,b) –Let A = { 1, 2, 3, 4, 5 } If, for every value, it is the equal to the value in its transposed position, then the relation is symmetric

14 Asymmetry Consider an asymmetric relation: < –One which if a is related to b then b is not related to a for all (a,b) –Let A = { 1, 2, 3, 4, 5 } If, for every value and the value in its transposed position, if they are not both 1, then the relation is asymmetric An asymmetric relation must also be irreflexive Thus, the main diagonal must be all 0’s

15 Antisymmetry Consider an antisymmetric relation: ≤ –One which if a is related to b then b is not related to a unless a=b for all (a,b) –Let A = { 1, 2, 3, 4, 5 } If, for every value and the value in its transposed position, if they are not both 1, then the relation is antisymmetric The center diagonal can have both 1’s and 0’s

16 Transitivity Consider an transitive relation: ≤ –One which if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) –Let A = { 1, 2, 3, 4, 5 } If, for every spot (a,b) and (b,c) that each have a 1, there is a 1 at (a,c), then the relation is transitive Matrices don’t show this property easily

IOCCC winners 2004 winners: 2004 winners: –2004 anonymousRendering of a stroked font anonymous –2004 arachnidCurses maze displayer/navigator with only line-of-sight visibility arachnid –2004 burley A Poker game –2004 gavareA ray tracer gavare –2004 gavin Mini-OS –2004 hibachi A CGI capable HTTP server –2004 hoyleCurses based polynomial graphing with auto-scale hoyle –2004 jdalbec Conway's look'n'say sequence split into elements –2004 kopczynski OCR of 8, 9, 10 and 11 –2004 newbern Renders arbitary bitmapped fonts newbern –2004 omoikane A CRC inserter –2004 schnitzi Editor animation –2004 sds Space/tab/linefeed steganography –2004 vik1 X Windows car racing game –2004 vik2 Calculates prime numbers using only CPP At At

18 End of lecture on 21 April 2005  I think!

19 Combining relations: via Boolean operators Example 4 from Rosen, section 7.3 Let: Join: Meet:

20 Combining relations: via relation composition Example 4 from Rosen, section 7.3 Let: But why is this the case? abcabc defdef d e fg h i abcabc

21 Representing relations using directed graphs A directed graph consists of: –A set V of vertices (or nodes) –A set E of edges (or arcs) –If (a, b) is in the relation, then there is an arrow from a to b Will generally use relations on a single set Consider our relation R = { (a,b) | a divides b } Old way:

22 Reflexivity Consider a reflexive relation: ≤ –One which every element is related to itself –Let A = { 1, 2, 3, 4, 5 } If every node has a loop, a relation is reflexive

23 Irreflexivity Consider a reflexive relation: < –One which every element is not related to itself –Let A = { 1, 2, 3, 4, 5 } If every node does not have a loop, a relation is irreflexive

24 Symmetry Consider an symmetric relation R –One which if a is related to b then b is related to a for all (a,b) –Let A = { 1, 2, 3, 4, 5 } If, for every edge, there is an edge in the other direction, then the relation is symmetric Loops are allowed, and do not need edges in the “other” direction Note that this relation is neither reflexive nor irreflexive! Called anti- parallel pairs

25 Asymmetry Consider an asymmetric relation: < –One which if a is related to b then b is not related to a for all (a,b) –Let A = { 1, 2, 3, 4, 5 } A digraph is asymmetric if: 1.If, for every edge, there is not an edge in the other direction, then the relation is asymmetric 2.Loops are not allowed in an asymmetric digraph (recall it must be irreflexive)

26 Antisymmetry Consider an antisymmetric relation: ≤ –One which if a is related to b then b is not related to a unless a=b for all (a,b) –Let A = { 1, 2, 3, 4, 5 } If, for every edge, there is not an edge in the other direction, then the relation is antisymmetric Loops are allowed in the digraph

27 Transitivity Consider an transitive relation: ≤ –One which if a is related to b and b is related to c then a is related to c for all (a,b), (b,c) and (a,c) –Let A = { 1, 2, 3, 4, 5 } A digraph is transitive if, for there is a edge from a to c when there is a edge from a to b and from b to c

28 Applications of digraphs: MapQuest Start End Not reflexive Is irreflexive Not symmetric Not asymmetric Not antisymmetric Not transitive Not reflexive Is irreflexive Is symmetric Not asymmetric Not antisymmetric Not transitive

29 Rosen, questions 31 & 32, section 7.3 Which of the graphs are reflexive, irreflexive, symmetric, asymmetric, antisymmetric, or transitive Reflexive YYY Irreflexive YY Symmetric YY Asymmetric Y Anti- symmetric YY Transitive Y

30 Rosen, section 7.1 (sic) question 45 (a) How many symmetric relations are there on a set with n elements? Solution guide explanation is pretty poorly worded So instead we’ll use matrices

31 Rosen, section 7.1 (sic) question 45 (a) Consider the matrix representing symmetric relation R on a set with n elements: The center diagonal can have any values Once the “upper” triangle is determined, the “lower” triangle must be the transposed version of the “upper” one How many ways are there to fill in the center diagonal and the upper triangle? There are n 2 elements in the matrix There are n elements in the center diagonal –Thus, there are 2 n ways to fill in 0’s and 1’s in the diagonal Thus, there are (n 2 -n)/2 elements in each triangle –Thus, there are ways to fill in 0’s and 1’s in the triangle Answer: there are possible symmetric relations on a set with n elements

32 Quick survey I felt I understood the material in this slide set… I felt I understood the material in this slide set… a) Very well b) With some review, I’ll be good c) Not really d) Not at all

33 Quick survey The pace of the lecture for this slide set was… The pace of the lecture for this slide set was… a) Fast b) About right c) A little slow d) Too slow

34 Quick survey How interesting was the material in this slide set? Be honest! How interesting was the material in this slide set? Be honest! a) Wow! That was SOOOOOO cool! b) Somewhat interesting c) Rather borting d) Zzzzzzzzzzz

35 Biggest software errors Ariane 5 rocket explosion (1996) Ariane 5 rocket explosion (1996) –Due to loss of precision converting 64-bit double to 16-bit int Pentium division error (1994) Pentium division error (1994) –Due to incomplete look-up table (like an array) Patriot-Scud missile error (1991) Patriot-Scud missile error (1991) –Rounding error on the time –The missile did not intercept an incoming Scud missile, leaving 28 dead and 98 wounded Mars Climate Orbiter (1999) Mars Climate Orbiter (1999) –Onboard used metric units; ground computer used English units AT&T long distance (1990) AT&T long distance (1990) –Wrong break statement in C code Therac-25, X-ray ( ) Therac-25, X-ray ( ) –Badly designed software led to radiation overdose in chemotherapy patients NE US power blackout (2003) NE US power blackout (2003) –Flaw in GE software contributed to it References: References: