740 likes | 753 Views
Learn about binary relations, their properties, and graphical representations. Explore reflexive, symmetric, antisymmetric, and transitive relations. Understand closures of relations like reflexive and symmetric closures. Discover matrices and operations in relational algebra.
E N D
Section 9.1 Relations and their Properties
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.
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?
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.
Example Let: R1 = { (a,x), (c,y) } R2 = { (a,y), (b,x) } Notation a R1x b R1 x b R2 x
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
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.
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
How Many Relations? If |A| = n then |AxA| = n2 . Since a relation is a subset of AxA then the number of possible relations is
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)}
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)}
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)}
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)
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)}
Section 9.2 n-ary Relations
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.
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
Relational Algebra Demo • reldb.py • 4 Tables: • parts • suppliers • projects • spj (a table that connects the other 3 tables)
Section 9.3 Representing Relations
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
Symmetric SYMMETRIC NOTSYMMETRIC
Boolean Matrices Join of Matrices Union of Relations Meet of Matrices Intersection of Relations Boolean Product of Matrices Composite Relations
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 = {
Spotting Properties via Graphs • How can you spot the following properties from a graph? • Reflexive • Symmetric • Antisymmetric • Transitive
Section 9.4 Closures of Relations
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).
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).
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
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…
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
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).
Section 9.5 Equivalence Relations
Equivalence Relations A relation on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive.
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.
Is this an equivalence relation? Which elements are “equivalent” (related to each other)?
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.
[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,…}
Partition A partition of a set S is a collection of disjoint, nonempty subsets of S that have S as their union.
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.
Section 9.6 Partial Orderings
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)