Download presentation
Presentation is loading. Please wait.
Published byEric Chandler Modified over 8 years ago
1
Relations: Operations & Properties
2
Power Sets Set of all subsets of a set A. –A = {1,2} –P(A) = 2 A = { {}, {1}, {2}, {1,2} } We note that each element of A is either present (1) or not present (0). If we treat the elements of A as a sequence, we get a bit-string that represents the set. –If A = {a,b,c,d}, we can order the elements in a sequence. –Then, we can let the bit-string say which elements are present: e.g. 0110 means {b,c}. –We can represent all the subsets of A, from = 0000 to U = 1111. This bit-string notation also helps us know the number of subsets in the powerset (just count in binary) –2 #A, 2 |A| = 2 · 2 · … · 2(|A| times) –This motivates the notation 2 A for the power set.
3
Bit-String Operations on Power Sets With bit string representations –Set intersection: = pairwise –Set union: = pairwise –Set complement: ~ = bit complement –Set minus: – = mask out using 1’s = complement 2 nd operand and do pairwise E.g. using {a,b,c,d} –1011 1101 = 1001i.e. {a,c,d} {a,b,d} = {a,d} –1011 1101 = 1111i.e. {a,c,d} {a,b,d} = {a,b,c,d} –~1011 = 0100i.e. ~{a,c,d} = {b} –1010 – 1100 = 0010i.e. {a,c} – {a,b} = {c}
4
Binary Relations Sets of ordered 2-tuples (pairs) with values selected from domains (sets) Formally, a relation R from set A to set B is a set of pairs (x,y) such that x A and y B. We may write R:A B to express this. –R A B –If (x,y) R, we say that x is R-related to y; we may also write xRy. –Example: NNN<: N N (where N is the set of natural numbers) (2,3) < or 2<3 –Predicates also define relations <:{0,1,2} { 1,0,1,2}= {(x,y) | x {0,1,2} y { 1,0,1,2} x < y} = { (0,1), (0,2), (1,2) }
5
Representations for Binary Relations Tables <012 00011 10001 20000 2 1 0 2 1 0 Matrices Graphs - directed graph or digraph - directed arcs 012 0 0011 1 0001 2 0000
6
Domains and Ranges for Binary Relations Let R = {(0,1), (0,2), (1,2)}, then Domain of R = dom R = dom(R) = {x | y((x,y) R)} –i.e. {0,1} –like X R Range of R = ran R = ran(R) = {y | x((x,y) R)} –i.e. {1,2} –like Y R 2 1 0 2 1 0 Range Space Range Domain Space Domain
7
Inverse If R: A B, then the inverse of R is R ~ : B A. R -1 is also a common notation R ~ is defined by {(y,x) | (x,y) R}. –If R = {(a,b), (a,c)}, then R ~ = {(b,a), (c,a)} –> is the inverse of < on the reals Note that R ~ ~R –The complement of < is –But the inverse of
8
Set Operations Since relations are sets, set operations apply (just like relational algebra). The arity must be the same indeed, the sets for the domain space and range space must be the same (just like in relational algebra).
9
Restriction & Extension Restriction decreases the domain space or range space. Example: Let < be the relation {(1,2), (1,3), (2,3)}. The restriction of the domain space to {1} restricts < to {(1,2), (1,3)}. Extensions increase the domain space or range space. Example: Let < be the relation {(1,2), (1,3), (2,3)}. The extension of both the domain space and range space to {1,2,3,4} extends < to {(1,2), (1,3), (1,4), (2,3), (2,4), (3,4)} Extensions and restrictions need not change the relation. –Suppose {M 1, M 2, M 3 } are three males and {F 1, F 2, F 3 } are three females and married_to is {(M 1,F 3 ), (M 2,F 2 )}. –Removing the unmarried male M 3 or the unmarried female F 1 does nothing to the relation, and adding the unmarried male M 4 or the unmarried female F 4 does nothing to the relation.
10
1234512345 12341234 12341234 Composition Let R:A B and S:B C be two relations. The composition of R and S, denoted by R S, contains the pairs (x,z) if and only if there is an intermediate object y such that (x,y) is in R and (y,z) is in S. Given R:A B and S:B C, with A = {1,2,3,4}, B = {1,2,3,4,5}, C = {1,2,3,4}, and R = {(1,3), (4,2), (1,1)} and S = {(3,4), (2,1), (4,2)}, we have: R S = {(1,4), (4,1)} S R = {(3,2), (2,3), (2,1)} (i.e. not commutative) R (S R) = {(1,2), (4,3), (4,1)} (R S) R = {(1,2), (4,3), (4,1)} (i.e. is associative) R S Graphically:
11
Composition & Matrix Multiplication Relation matrices only contain 0’s and 1’s. For relational matrix multiplication, use for *, for +, with 1=T and 0=F. 0001 0000 0000 1000 00010 4 00000 3 00000 2 00101 1 54321 R 0000 5 0010 4 1000 3 0001 2 0000 1 4321 S R S (1,1) = (1 0) (0 1) (1 0) (0 0) (0 0) = 0 4 3 2 1 4321 RSRS = R S = {(1,4), (4,1)}
12
Combined Operations All operations we have discussed can be combined so long as the compatibility requirements are met. Example: R = {(1,1), (3,1), (1,2)} S = {(1,1), (2,3)} (R S) ~ R = {(1,1), (3,1), (1,2), (2,3)} ~ R = {(1,1), (1,3), (2,1), (3,2)} R = {(1,1), (1,2), (2,1), (2,2)} R: A B S: B A A = {1,2,3} B = {1,2,3}
13
Properties of Binary Relations Properties of binary relations on a set R: A A help us with lots of things groupings, orderings, … Because there is only one set A: –matrices are square |A| |A| –graphs can be drawn with only one set of nodes R = {(1,3), (4,2), (3,3), (3,4)} 0010 4 1100 3 0000 2 0100 1 4321 1313 2424
14
Reflexivity Reflexive: x(xRx) =, , “is in same major as”, etc. Reflexive IrreflexiveNeither 1 3 1 2 1 1 321 0 3 0 2 0 1 321 1 3 1 2 0 1 321 Note: e.g., “loves”e.g., <
15
Symmetry Symmetric: x y(xRy yRx) Antisymmetric: x y(xRy yRx x = y) “sibling” is symmetric are antisymmetric (if a b and b a, then a=b) = is symmetric and antisymmetric “loves” is neither symmetric nor antisymmetric (always both ways) (but to self is ok) (never both ways) 11 3 10 2 10 1 321 01 3 1 2 0 1 321 Note: antisymmetry is NOT asymmetry
16
Transitivity Transitive: x y z(xRy yRz xRz) “taller” is transitive < is transitivex<y<z “ancestor” is transitive “brother-in-law” is not transitive Transitive: “If I can get there in two, then I can get there in one.” (for every x, y, z) if and then x y z
17
Transitivity (cont’d) Note: xRy yRz corresponds to xR Rz, which is equivalent to xR×Rz = xR 2 z; thus we can define transitivity as: x y z(xR 2 z xRz) “If I can get there in two, then I can get there in one.” For transitivity: –if reachable through an intermediate, then reachable directly is required. –if (x,z) R 2, then (x,z) R (x,z) R 2 (x,z) R R 2 R ( recall our def. of subset: x A x B, then A B)
18
Transitivity (cont’d) 100 3 100 2 110 1 321 100 3 100 2 110 1 321 100 3 100 2 100 1 321 000 3 100 2 010 1 321 000 3 100 2 010 1 321 000 3 000 2 100 1 321 = = R R R 2 R R R 1 2 3 Not Transitive Transitive 1 2 3
19
Closures & Equivalence Relations
20
Closure Closure means adding something until done. –Normally adding as little as possible until some condition is satisfied –Least fixed point similarities
21
Reflexive Closure Reflexive closure of a relation: R (r) –smallest reflexive relation that contains R (i.e. fewest pairs added) –R (r) = R I A (R is a relation on a set A, and I A is the identity relation 1’s on the diagonal and 0’s elsewhere.) 111 3 100 2 010 1 321 111 3 110 2 011 1 321 R = R (r) = x (xRx)
22
Symmetric Closure Symmetric closure of a relation: R (s) –smallest symmetric relation that contains R (i.e. fewest pairs added) –R (s) = R R ~ (R ~ is R inverse) 111 3 100 2 010 1 321 110 3 101 2 100 1 321 R = R ~ = 111 3 101 2 110 1 321 R R ~ = x y(xRy yRx)
23
Transitive Closure Transitive closure of a relation: R (t) = R + –smallest transitive relation that contains R (i.e. fewest pairs added) –for each path of length i, there must be a direct path. (This follows from x y, y z x z; since, if we also have v x, we must have v z, a path of length 3.) –R (t) = R R 2 R 3 … R |A|. (No path can be longer than |A|, the number of elements in A.)
24
R R 2 R 3 = R×R 2 = R 3 = Transitive Closure – Example 1 111 3 100 2 010 1 321 111 3 111 2 100 1 321 R = R 2 = 111 3 111 2 111 1 321 1 2 3 1 2 3 1 2 3 All paths of length 3 All paths of length 2 All paths of length 1 111 3 111 2 111 1 321
25
Transitive Closure – Example 2 010 3 100 2 000 1 321 100 3 010 2 000 1 321 R = R 2 = 010 3 100 2 000 1 321 R×R 2 = R 3 = 1 2 3 1 2 3 1 2 3 110 3 110 2 000 1 321 R R 2 R 3 = 1 2 3 All paths of length 3 All paths of length 2 Paths of any length All paths of length 1
26
Reflexive Transitive Closure Reflexive transitive closure of a relation: R * –smallest reflexive and transitive relation that contains R –R * = I A R + = R 0 R + = R 0 R 1 R 2 …R |A| Example: 100 3 010 2 001 1 321 I A = R 0 = 110 3 110 2 001 1 321 1 2 3 R 1 R 2 R 3 = 110 3 110 2 000 1 321 R 0 R 1 R 2 R 3 =
27
Equivalence Relations A relation R on a set A is an equivalence relation if R is reflexive, symmetric, and transitive. –Equivalence relations are about “equivalence” –Examples: = for integersx = xreflexive x = y y = xsymmetric x=y y=z x=ztransitive = for setsA = Areflexive A = B B = Asymmetric A=B B=C A=Ctransitive Let R be “has same major as” for college students xRx reflexive: same major as self xRy yRx symmetric: same major as each other xRy yRz xRz transitive: same as, same as same as
28
Partitions A partition of a set S is –a set of subsets S i=1,2,…n of S –such that n i=1 S i = S, S j S k = for j k. Each S i is called a block (also called an equivalence class) Example: –Suppose we form teams (e.g. for a doubles tennis tournament) from the set: {Abe, Kay, Jim, Nan, Pat, Zed} then teams could be: { {Abe, Nan}, {Kay, Jim}, {Pat, Zed} } Note: “on same team as” is reflexive, symmetric, transitive an equivalence relation. Equivalence relations and partitions are the same thing (two sides of the same coin).
29
Partitions (cont’d) Since individual elements can only appear in one block (S j S k = for j k), blocks can be represented by any element within the block. e.g.Nan’s Team Jimmer’s 2011 sweet-16 team Formally, [x] = set of all elements related to x and y [x] iff xRy e.g.[Nan] represents {Abe, Nan}, Nan’s team [Abe] represents {Abe, Nan}, Abe’s team [Jimmer] represents the set of players who played on BYU’s 2011 sweet-16 team
30
Partitions & Equivalence Relations The mod function partitions the natural numbers into equivalence classes. –0 mod 3 = 0 so 0 forms a class [0] –1 mod 3 = 1 so 1 forms new class [1] –2 mod 3 = 2 so 2 forms new class [2] –3 mod 3 = 0 so 3 belongs to [0] –4 mod 3 = 1 so 4 belongs to [1] –5 mod 3 = 2 so 5 belongs to [2] –6 mod 3 = 0 so 6 belongs to [0] –… Thus, the mod function partitions the natural numbers into equivalence classes. –[0] = {0, 3, 6, …} –[1] = {1, 4, 7,…} –[2] = {2, 5, 8, …} Example:
31
Partitions Equivalence Relations Theorem: If {S 1, …, S n } is a partition of S, then R:S S is an equivalence relation, where R is “in same block as.” Note: to prove that R is an equivalence relation, we must prove that R is reflexive, symmetric, and transitive. Proof: Reflexive: since every element is in the same block as itself. Symmetric: since if x is in the same block as y, y is in the same block as x. Transitive: since if x and y are in the same block and y and z are in the same block, x and z are in the same block.
32
Equivalence Relations Partitions Theorem: If R:S S is an equivalence relation and [x] = { y | xRy }, then { [x] | x S } is a partition P of S. Note: to prove that we have a partition, we must prove (1) that every element of S is in a block of P, and (2) that for every pair of distinct blocks S j and S k (j k) of P, S j S k = . Proof: (1) Since R is reflexive, xRx, every element of S is at least in its own block and thus in some block of P. (2) Suppose S j S k for distinct blocks S j and S k of P. Then, at least one element y is in both S j and S k. Let S j = {y, x 1, … x n } and S k = {y, z 1, … z m }, then yRx i, i=1, 2, …, n, and yRz p, p=1, 2, …, m. Since R is symmetric, x i Ry, and since R is transitive x i Rz p. But now, since the elements of S j are R-related to the elements of S k, x 1, …, x n, y, z 1, …, z m are together in a block of P and thus S i and S k are not distinct blocks of P.
33
Partial Orders
34
Total orderings: single sequence of elements Partial orderings: some elements may come before/after others, but some need not be ordered Examples of partial orderings: foundation framing plumbingwiring finishing {a, b, c} {a, b}{a, c}{b, c} {a}{b}{c} “must be completed before” “set inclusion, ”
35
Partial Order Definitions (Poset Definitions) A relation R: S S is called a (weak) partial order if it is reflexive, antisymmetric, and transitive. 1 2 3 A relation R: S S is called a strict partial order if it is irreflexive, antisymmetric, and transitive. 1 2 3 e.g. on the integers e.g. < on the integers
36
Total Order A total ordering is a partial ordering in which every element is related to every other element. (This forces a linear order or chain.) Examples: R: on {1, 2, 3, 4, 5} is total. Pick any two; they’re related one way or the other with respect to . {a,b} {a} {b} R: on {{a, b}, {a}, {b}, } is not total. We can find a pair not related one way or the other with respect to . {a} & {b}: neither {a} {b} nor {b} {a} 1234512345
37
Hasse Diagrams We produce Hasse Diagrams from directed graphs of relations by doing a transitive reduction plus a reflexive reduction (if weak) and (usually) dropping arrowheads (using, instead, “above” to give direction) 1) Transitive reduction discard all arcs except those that “directly cover” an element. 2) Reflexive reduction discard all self loops. {b}{a} {a, b} {b}{a} {a, b} For we write:
38
Upper and Lower Bounds If a poset is built from relation R on set A, then any x A satisfying xRy is an upper bound of y, and any x A satisfying yRx is a lower bound of y. Examples: If A = {a, b, c} and R is , then {a, c} - is an upper bound of {a}, {c}, and . - is also an upper bound of {a, c} (weak poset). - is a lower bound of {a, b, c}. - is also a lower bound of {a, c} (weak poset).
39
Maximal and Minimal Elements If a poset is built from relation R on set A, then y A is a maximal element if there is no x such that xRy, and x A is a minimal element if there is no y such that xRy. (Note: We either need the poset to be strict or x y.) In a Hasse diagram, every element with no element “above” it is a maximal element, whereas every element with no element “below” it is a minimal element. Maximal elements Minimal elements
40
Least Upper and Greatest Lower Bounds A least upper bound of two elements x and y is a minimal element in the intersection of the upper bounds of x and y. A greatest lower bound is a maximal element in the intersection of the lower bounds of x and y. Examples: –For , {a, c} is a least upper bound of {a} and {c}, is a greatest lower bound of {a} and {b, c}, and {a} is a least upper bound of {a} and . –For the following strict poset, lub(x,y) = {a,b}, lub(y,y) = {a,b,c}, lub(a,y) = , glb(a,b) = {x,y}, glb(a,c) = {y} a b x y c
41
Functions
42
A function is a special kind of binary relation. A binary relation f A B is a function if for each a A there is a unique b B Function Definition 1 2 3 α β γ x y
43
NOT Functions 1 2 3 α β γ f = {(1, α), (2, β)} “For each” violated Some x’s do not have corresponding y’s x y
44
NOT Functions Uniqueness violated for some x’s x y 1 2 3 α β γ f = {(1, α), (2, β), (3, β), (3, γ)} uniqueness violated for 3 appears twice
45
An (n+1)-ary relation f A 1 A 2 … A n B is a function if for each A 1 A 2 … A n there is a unique b B. Functions with N-Dimensional Domains α β γ
46
We can use various notation for functions: for f = {(1, α),(2, β),(3, β)} Notation for Functions Notation (x, y) f f : x→yy = f(x) Example (2, β) f f : 2→ββ = f(2) In the notation, x is the argument or preimage and y is the image. We can also have the image of a set of arguments. For functions with n-ary domains, use in place of x.
47
Function Domain and Range f : A → B –A is the domain space same as the domain (since all elements participate) dom f, dom(f), or domain(f) –B is the range space may or may not be the same as the range, which is: –{y | x(y=f(x))} –All rhs values in pairs (all that get “hit”) – B f ran f, ran(f), range(f) f : D 1 D 2 … D n → Z f : D n → Z (when all domains are the same)
48
Remove the requirement that each a A must participate. Retain the uniqueness requirement. Partial Functions Partial Function: α β γ f = {(, β),(, β),(, γ)} not unique α β γ NOT a Partial Function: α β γ Partial Function: (A Total Function is also a Partial Function.)
49
Identity Function –I A : A → A –I A = {(x, x) | x A} Constant Function –C : A → B –C = {(x, c) | x A c B } –Often A and B are the same C : A → A C= {(x, c) | x A c A} Special Functions
50
Overloading The same name can be used for different functions depending on the domain. Examples a – b Means number subtraction if a and b are numbers Means set subtraction if a and b are sets a + b Implemented differently for integers and reals Could potentially be overridden and implemented by a programmer for very long integers
51
Composition of Functions Composition is written “°” Range space of f = domain space of g a c 1 2 4 f g b α β 3 f(a) = 2g(2) = αg(f(a)) = α g ° f(a) = α f(b) = 2g(2) = αg(f(b)) = α g ° f(b) = α f(c) = 4g(4) = βg(f(c)) = β g ° f(c) = β
52
Injection: “one-to-one” or “1-1” – x y(f(x) = f(y) x = y) –For f : A → B, the elements in B are “ hit ” at most once Injection a b d 1 2 3 c Injective a b d 1 2 3 c NOT Injective x y x y
53
Surjection: “onto” – y x(y = f(x)) –For f : A → B, the elements in B are all “ hit ” at least once Surjection 1 2 4 a b c 3 SurjectiveNOT Surjective x y x y 1 2 4 a b c 3 { not “hit”
54
Bijection: “one-to-one and onto” or “1-1 correspondence” – x y(f(x) = f(y) x = y) y x(y = f(x)) –For f : A → B, every B element is “ hit ” once and only once Bijection 1 2 a b c 3 BijectiveNOT Bijective x y x y 1 2 4 a b c 3 NOT Surjective NOT injective
55
Notes on Bijection 1.|A| = |B| –An “extra” B cannot be “hit” (not a surjection) –An “extra” A requires that at least one B must be “hit” twice (not an injection) 2.If f is a bijection, swapping the elements of the ordered pairs is a function –Called the inverse –Denoted f -1 –Is also a bijection –f -1 (f(x)) is the identity function, i.e. f -1 (f(x)) = x.
56
Notes on Bijection (cont’d) 3.The inverse of an injection is a partial function. If f : A →B is an injection, then f -1 is a partial function 4.Restricting the range space of an injective function to the range yields a bijection Remove b a b d 1 2 3 c f a b d 1 2 3 c f -1
57
NR[0..1] Which is bigger? N or R[0..1]? NR[0..1] Assume |N| = |R[0..1]|, then there exists a bijection: 1 0.34234… 2 0.34987…diagonalization 3 0.00040… R[0..1] But now there exists a number in R[0..1] such that d 1 = not 3, d 2 = not 4, d 3 = not 0, …. Hence, not surjective and thus not bijective.
58
NZ Which is bigger? N or Z? f(x) = x odd: (x+1)/−2 x even: x/2 y negative: −2x−1 y positive: 2x g(y) = { { x y 0 0 1 −1 2 1 3 −2 4 2 NZNZ Since g = f −1, there is a bijection from N to Z and thus |N| = |Z|. N Countable if same cardinality as some subset of N. N Alternatively, a set S is countable if there exists an injective function from S to N.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.