1 / 74

Section 9.1

Section 9.1. Relations and their Properties. Binary Relation from A to B. Let A and B be sets. A binary relation from A to B is a subset of A x B. Example. Let A = { a, b, c } and B = { x, y } then A x B = {(a,x), (a,y), (b,x), (b,y), (c,x), (c,y)}

svelasco
Download Presentation

Section 9.1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Section 9.1 Relations and their Properties

  2. Binary Relation from A to B Let A and B be sets. A binaryrelation from A to B is a subset of A x B.

  3. Example Let A = { a, b, c } and B = { x, y } then A x B = {(a,x), (a,y), (b,x), (b,y), (c,x), (c,y)} Any subset of A x B is a relation from A to B. Therefore let, for example: R1 = {(a,x), (c,y)} R2 = {(a,y), (b,x)} ¿How many relations from A to B are there?

  4. Binary Relation from A to B. A binary relation from A to B is a set R of ordered pairs where the first element of each ordered pair comes from A and the second element comes from B. aRb denotes that (a,b) is an element of R and aRb indicates that (a,b) is not an element of R. When (a,b) belongs to R then a is related tob by R.

  5. Example Let: R1 = { (a,x), (c,y) } R2 = { (a,y), (b,x) } Notation a R1x b R1 x b R2 x

  6. Depicting Relations • Directed Graphs • Tables • Example: • Suppose A = {0, 1, 2} and B = {a, b}. • Let R be the relation on A x B defined as: • {(0, a), (0, b), (1, a), (2, b)} • Diagrams on next slide

  7. Functions as Relations A function is a relation from A to B such that every element in A is the first element of exactly one ordered pair of R.

  8. Relations on a Set A relation on the set A is a relation from A to A. A relation on the set A is a subset of AxA

  9. How Many Relations? If |A| = n then |AxA| = n2 . Since a relation is a subset of AxA then the number of possible relations is

  10. Reflexive Relations Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} {(2,4),(4,2)} {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

  11. Symmetric Relations Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} {(2,4),(4,2)} {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

  12. Antisymmetric Relations Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} {(2,4),(4,2)} {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

  13. Examples • The relation ≤ on the real numbers is antisymmetric • The relation ⊆ on sets is antisymmetric • The equality relation, =, on the real numbers is bothsymnmetric and antisymmetric • (antisymmetric ≠ asymmetric!) • Anther way to define antisymmetry: • aRb ∧a≠b →¬(bRa)

  14. Transitive Relations Consider the following relations on the set {1,2,3,4} {(2,2),(2,3),(2,4),(3,2),(3,3),(3,4)} {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)} {(2,4),(4,2)} {(1,2),(2,3),(3,4)} {(1,1),(2,2),(3,3),(4,4)} {(1,3),(1,4),(2,3),(2,4),(3,1),(3,4)}

  15. Composition of Relations

  16. Rn

  17. Transitivity

  18. Section 9.2 n-ary Relations

  19. Definition Let A1, A2, … , An be sets. An n-ary relation on these sets is a subset of A1 x A2 x … x An. The sets A1, A2, … , An are called the domains of the relation, and n is called its degree.

  20. Databases and Relations

  21. Operations • Selection • Chooses tuples (rows) that satisfy a condition • Projection • Chooses slots (columns) by position number or name • Join • Combines tuples from two tables with a common key

  22. Relational Algebra Demo • reldb.py • 4 Tables: • parts • suppliers • projects • spj (a table that connects the other 3 tables)

  23. Section 9.3 Representing Relations

  24. Using Matrices Let A = {1,2,3} and B={1,2}. Let the relation from A to B containing (a,b) if a>b. R would then equal {(2,1), (3,1), (3,2)} 1 2 1 2 3

  25. Reflexive Relations

  26. Symmetric SYMMETRIC NOTSYMMETRIC

  27. Antisymmetric

  28. Boolean Matrices Join of Matrices Union of Relations Meet of Matrices Intersection of Relations Boolean Product of Matrices Composite Relations

  29. a b V = {a,b,c,d} (a,b), (a,d), (c,b), (c,a), d c (b,b), (d,b), (b,d)} Digraph Example E = {

  30. Spotting Properties via Graphs • How can you spot the following properties from a graph? • Reflexive • Symmetric • Antisymmetric • Transitive

  31. Section 9.4 Closures of Relations

  32. Reflexive Closure • The reflexive closure of a relation, R, is the minimal relation containing R that is reflexive • If R is already reflexive, it is its own reflexive closure • Otherwise, add pairs (a,a) for all elements a, that are not already related to themselves. • For example, if R = {(1,1), (1,2), (2,1), (3,2)}, the we add the following pairs: (2,2), (3,3).

  33. Symmetric Closure • The symmetric closure of a relation, R, is the minimal relation containing R that is symmetric • If R is already symmetric, it is its own symmetric closure • Otherwise, add pairs (b,a) for all pairs (a,b) in R that are not already there. • For example, if R = {(1,1), (1,2), (2,1), (3,2)}, the we add the following pair: (2,3).

  34. Can You Get There From Here? • Often we want to know if there is a “path” from a to b (meaning a chain of pairs (a,x1), (x1,x2), … (xn,b)). • We say that b is “reachable in R” from a. • Forming this relation is harder than it appears

  35. Transitive Closure • The transitive closure of a relation, R, is the minimal relation containing R that is transitive. • Theorem 1: There is a path from a to b in R of length n, if and only if (a,b) ⋲ Rn. (The composition of R with itself n-1 times). • R defines paths of length 1 • R2 adds paths of length 2, and so on…

  36. Computing the Transitive Closure • Rn computes paths of length n. This means that n+1 objects have been visited, forcing a repeat (cycle). So everything has been traversed! • So all possible connected endpoints are computed by

  37. Matrix Representation • M* = M v M2 v M3 v … v Mn. • See Example 7 in section 9.4, page 602-603. • A more efficient algorithm (Warshall’s algorithm) is on page 606 (Algorithm 2 in section 9.4).

  38. Section 9.5 Equivalence Relations

  39. Equivalence Relations A relation on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive.

  40. Examples: Let R be the relation on the set of strings such that a R b if and only if l(a) = l (b) where l (x) is the length of x. Let R be the relation on the set of real numbers such that a R b if and only if a-b is an integer.

  41. Is this an equivalence relation? Which elements are “equivalent” (related to each other)?

  42. Equivalence Classes Let R be an equivalence relation on a set A. The set of all elements that are related to an element a of A is called the equivalence class of a. The equivalence class of a with respect to R is denoted by [a]R. When only one relation is under consideration, we will delete the subscript R and write [a] for this equivalence class.

  43. [0] = {…-14, -7, 0, 7, 14, 21,…} [1] = {…-13, -6, 1, 8, 15, 22,…} [2] = {…-12, -5, 2, 9, 16, 23,…} [3] = {…-11, -4, 3, 10, 17, 24,…} [4] = {…-10, -3, 4, 11, 18, 25,…} [5] = {…-9, -2, 5, 12, 19, 26,…} [6] = {…-8, -1, 6, 13, 20, 27,…}

  44. Partition A partition of a set S is a collection of disjoint, nonempty subsets of S that have S as their union.

  45. Equivalence Relations and Partitions Let R be an equivalence relation on a set S. Then the equivalence classes of R form a partition of S. Conversely, given a partition of the set S, there is an equivalence relation R that has the sets as its equivalence classes.

  46. Section 9.6 Partial Orderings

  47. Partially Ordered Set (POSET) A relation R on a set S is called a partial ordering or partial order if it is reflexive, antisymmetric, and transitive. A set S together with a partial ordering R is called a partially ordered set, or poset, and is denoted by (S, R)

More Related