Title: Relations: Operations
1Relations Operations Properties
2Power Sets
- Set of all subsets of a set A.
- A 1,2
- P(A) 2A , 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 lta,b,c,dgt. - 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) - 2A, 2A 2 2 2 (A times)
- This motivates the notation 2A for the power set.
3Bit-String Operations on Power Sets
- With bit string representations
- Set intersection ? pairwise ?
- Set union ? pairwise ?
- Set complement bit complement
- Set minus mask out using 1s complement
2nd operand and do pairwise ? - E.g. using a,b,c,d
- 1011 ? 1101 1001 i.e. a,c,d ? a,b,d a,d
- 1011 ? 1101 1111 i.e. a,c,d ? a,b,d
a,b,c,d - 1011 0100 i.e. a,c,d b
- 1010 1100 0010 i.e. a,c a,b c
4Binary 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 RA ? 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
- lt N?N (where N is the set of natural numbers)
- (2,3) ? lt or 2lt3
- Predicates also define relations
- lt0,1,2??1,0,1,2 (x,y) x ? 0,1,2 ? y ?
?1,0,1,2 ? x lt y - (0,1), (0,2), (1,2)
5Representations for Binary Relations
lt -1 0 1 2
0 0 0 1 1
1 0 0 0 1
2 0 0 0 0
-1 0 1 2
0 0 0 1 1
1 0 0 0 1
2 0 0 0 0
Matrices
Graphs - directed graph or digraph - directed arcs
6Domains 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 ?XR
- Range of R ran R ran(R) y ?x((x,y) ? R)
- i.e. 1,2
- like ?YR
7Inverse
- 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)
- gt is the inverse of lt on the reals
- Note that R ? R
- The complement of lt is ?
- But the inverse of lt is gt
8Set 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).
9Restriction Extension
- Restriction decreases the domain space or range
space. - Example Let lt be the relation (1,2), (1,3),
(2,3). The restriction of the domain space to
1 restricts lt to (1,2), (1,3). - Extensions increase the domain space or range
space. - Example Let lt 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 lt to (1,2),
(1,3), (1,4), (2,3), (2,4), (3,4) - Extensions and restrictions need not change the
relation. - Suppose M1, M2, M3 are three males and F1, F2,
F3 are three females and married_to is (M1,F3),
(M2,F2). - Removing the unmarried male M3 or the unmarried
female F1 does nothing to the relation, and
adding the unmarried male M4 or the unmarried
female F4 does nothing to the relation.
10Composition
- Let RA?B and SB?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 RA?B and SB?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)
1234
12345
1234
11Composition Matrix Multiplication
- Relation matrices only contain 0s and 1s.
- For relational matrix multiplication, use ? for
, ? for , with 1T and 0F.
?
R?S(1,1) (1?0)?(0?1)?(1?0)?(0?0)?(0?0) 0
R?S (1,4), (4,1)
12Combined 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
13Properties 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)
14Reflexivity
- Reflexive ?x(xRx)
- , ?, is in same major as, etc.
Reflexive
Note
Irreflexive
Neither
e.g., loves
e.g., lt
15Symmetry
- Symmetric ?x?y(xRy ? yRx)
- Antisymmetric ?x?y(xRy ? yRx ? x y)
- sibling is symmetric
- ?, ? are antisymmetric (if a?b and b?a, then
ab) - is symmetric and antisymmetric
- loves is neither symmetric nor antisymmetric
Note antisymmetry is NOT asymmetry
16Transitivity
- Transitive ?x?y?z(xRy ? yRz ? xRz)
- taller is transitive
- lt is transitive xltyltz
- ancestor is transitive
- brother-in-law is not transitive
- Transitive If I can get there in two, then I
can get there in one.
17Transitivity (contd)
- Note xRy ? yRz corresponds to xR?Rz, which is
equivalent to xRRz xR2z thus we can define
transitivity as - ?x?y?z(xR2z ? 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)?R2, then (x,z)?R
- ? (x,z)?R2 ? (x,z)?R
- ? R2 ? R (recall our def. of subset x?A ? x?B,
then A?B)
18Transitivity (contd)
?
R
R2 ? R
R
Transitive
?
R
R
R2 ? R
Not Transitive
19Closures Equivalence Relations
20Closure
- Closure means adding something until done.
- Normally adding as little as possible until some
condition is satisfied - Least fixed point similarities
21Reflexive Closure
- Reflexive closure of a relation R(r)
- smallest reflexive relation that contains R (i.e.
fewest pairs added) - R(r) R ? IA (R is a relation on a set A,
and IA is the identity relation ? 1s on
the diagonal and 0s elsewhere.)
R
R(r)
?x (xRx)
22Symmetric 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)
R
R
R ? R
?x?y(xRy ? yRx)
23Transitive 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 ? R2 ? R3 ? ? RA. (No path can be
longer than A, the number of elements in A.)
24Transitive Closure Example 1
1
All paths of length 1
R
2
3
1
All paths of length 2
R2
2
3
1
All paths of length 3
RR2 R3
2
3
R?R2?R3
25Transitive Closure Example 2
1
R
All paths of length 1
2
3
1
R2
All paths of length 2
2
3
1
RR2 R3
All paths of length 3
2
3
1
R?R2?R3
Paths of any length
2
3
26Reflexive Transitive Closure
- Reflexive transitive closure of a relation R
- smallest reflexive and transitive relation that
contains R - R IA ? R R0 ? R R0 ? R1 ? R2 ? RA
- Example
IA R0
R1 ? R2 ? R3
1
R0 ? R1 ? R2 ? R3
2
3
27Equivalence 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 integers x x reflexive
- x y ? y x symmetric
- xy ? yz ? xz transitive
- for sets A A reflexive
- A B ? B A symmetric
- AB ? BC ? AC transitive
- 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
28Partitions
- A partition of a set S is
- a set of subsets Si1,2,n of S
- such that ?ni1 Si S, Sj ? Sk ? for j ? k.
- Each Si 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).
29Partitions (contd)
- Since individual elements can only appear in one
block (Sj ? Sk ? for j ? k), blocks can be
represented by any element within the block. - e.g. Nans Team
- Jimmers 2011 sweet-16 team
- Formally, x set of all elements related to x
and y ? x iff xRy - e.g. Nan represents Abe, Nan, Nans team
- Abe represents Abe, Nan, Abes team
- Jimmer represents the set of players who
played on BYUs 2011 sweet-16 team
30Partitions Equivalence Relations
Example
- 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,
31Partitions ? Equivalence Relations
Theorem If S1, , Sn is a partition of S, then
RS?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.
32Equivalence Relations ? Partitions
Theorem If RS?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 Sj and Sk (j?k) of P, Sj
? Sk ?. 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 Sj ? Sk
? ? for distinct blocks Sj and Sk of P. Then, at
least one element y is in both Sj and Sk. Let Sj
y, x1, xn and Sk y, z1, zm, then
yRxi, i1, 2, , n, and yRzp, p1, 2, , m.
Since R is symmetric, xiRy, and since R is
transitive xiRzp. But now, since the elements of
Sj are R-related to the elements of Sk, x1, ,
xn, y, z1, , zm are together in a block of P and
thus Si and Sk are not distinct blocks of P.
33Partial Orders
34Partial Orders
- 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
must be completed before
set inclusion, ?
foundation
framing
plumbing wiring
finishing
a, b, c
a, b a, c b, c
a b c
?
35Partial Order Definitions(Poset Definitions)
- A relation R S?S is called a (weak) partial
order if it is reflexive, antisymmetric, and
transitive.
e.g. ? on the integers
e.g. lt on the integers
- A relation R S?S is called a strict partial
order if it is irreflexive, antisymmetric, and
transitive.
36Total 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
1 2 3 4 5
R ? on 1, 2, 3, 4, 5 is total. Pick any two
theyre related one way or the other with respect
to ?.
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
a,b
a
b
?
37Hasse 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.
For ?
we write
a, b
?
b
a
?
38Upper 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).
39Maximal 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
40Least 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
c
x
y
41Functions
42Function Definition
- 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
y
x
43NOT Functions
f (1, a), (2, ß) For each violated
y
Some xs do not have corresponding ys
x
44NOT Functions
f (1, a), (2, ß), (3, ß), (3, ?) uniqueness
violated for 3 ? appears twice
y
Uniqueness violated for some xs
x
45Functionswith N-Dimensional Domains
- An (n1)-ary relation f ? A1 ? A2 ? ? An ? B
is a function if for each lt a1, a2, , angt ? A1 ?
A2 ? ? An there is a unique b ? B.
46Notation for Functions
- We can use various notation for functions for f
(1, a),(2, ß),(3, ß)
Notation (x, y) ? f f x?y y 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 ltx0, x1, ,
xngt in place of x.
47Function 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(yf(x))
- All rhs values in pairs (all that get hit)
- ?Bf
- ran f, ran(f), range(f)
- f D1 ? D2 ? ? Dn ? Z
- f Dn ? Z (when all domains are the same)
48Partial Functions
- Remove the requirement that each a ? A must
participate. Retain the uniqueness requirement.
Partial Function
Partial Function (A Total Function is also a
Partial Function.)
NOT a Partial Function
f (lt1,2gt, ß),(lt1,3gt, ß),(lt1,3gt, ?) lt1,3gt not
unique
49Special Functions
- Identity Function
- IA A ? A
- IA (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
50Overloading
- 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
51Composition of Functions
g
1
a
a
f
2
ß
b
3
4
c
- Composition is written
- Range space of f domain space of g
f(a) 2 g(2) a g(f(a)) a
gf(a) a
f(b) 2 g(2) a g(f(b)) a
gf(b) a
f(c) 4 g(4) ß g(f(c)) ß
gf(c) ß
52Injection
- 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
Injective
NOT Injective
a
1
a
1
b
b
2
2
c
c
d
3
d
3
y
y
x
x
53Surjection
- Surjection onto
- ?y?x(y f(x))
- For f A ? B, the elements in B are all hit at
least once
Surjective
NOT Surjective
a
a
1
1
2
2
b
b
3
3
c
c
4
4
y
y
not hit
x
x
54Bijection
- 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
NOT Surjective NOT injective
Bijective
NOT Bijective
a
a
1
1
2
2
b
b
3
3
c
c
4
y
y
x
x
55Notes on Bijection
- 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) - 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.
56Notes on Bijection (contd)
- The inverse of an injection is a partial
function. - If f A ?B is an injection, then f-1 is a
partial function
f
f-1
a
1
1
a
b
b
2
2
c
c
d
3
3
d
- Restricting the range space of an injective
function to the range yields a bijection - Remove b
57Which is bigger? N or R0..1?
Assume N R0..1, then there exists a
bijection 1 0.34234 2 0.34987 diagonalizati
on 3 0.00040 But now there exists a number in
R0..1 such that d1 not 3, d2 not 4, d3
not 0, . Hence, not surjective and thus not
bijective.
58Which is bigger? N or Z?
Since g f-1, there is a bijection from N to Z
and thus N Z. Countable if same
cardinality as some subset of N. Alternatively, a
set S is countable if there exists an injective
function from S to N.