Title: Bogazici University Department of Computer Engineering CmpE 220 Discrete Mathematics 21' Relations H
1Bogazici UniversityDepartment of Computer
EngineeringCmpE 220 Discrete Mathematics21.
Relations Haluk Bingöl
2Module 21Relations
- Rosen 5th ed., ch. 7
- 35 slides (in progress), 2 lectures
3Binary Relations
- Def. Let A, B be any sets. A binary relation R
from A to B, written (with signature) RAB, or
RA,B, is (can be identified with) a subset of
the set AB. - E.g., let lt N?N (n,m) n lt m
- The notation a R b or aRb means that (a,b)?R.
- E.g., a lt b means (a,b)? lt
- If aRb we may say a is related to b (by relation
R), - or just a relates to b (under relation R).
- Ex. A binary relation R corresponds to a
predicate function PRAB?T,F defined over the
2 sets A,B - e.g., predicate eats (a,b) organism a eats
food b
4Complementary Relations
- Def. Let RA,B be any binary relation. Then,
RAB, the complement of R, is the binary
relation defined by R (a,b) (a,b)?R
(AB) - R - Note this is just R if the universe of discourse
is U AB thus the name complement. - Note the complement of R is R.
Example lt (a,b) (a,b)?lt (a,b) altb
5Inverse Relations
- Def. Any binary relation RAB has an inverse
relation R-1BA, defined by R-1 (b,a)
(a,b)?R. - Ex.lt-1 (b,a) altb (b,a) bgta gt.
- Ex. If RPeople?Foods is defined by a R
b ? a eats b, then b R-1 a ? b is eaten by
a. (Passive voice.)
6Relations on a Set
- Def. A (binary) relation from a set A to itself
is called a relation on the set A. - Ex.
- lt ? NN, lt (n,m) n lt m, n,m?N
- IA ? AA, IA (a,a)a?A.
7Reflexivity
- Def. A relation R on A is reflexive if ?a?A,
aRa. - Ex. (a,b) ab is reflexive.
- Def. A relation R is irreflexive iff its
complementary relation R is reflexive. - Ex. lt is irreflexive, because is reflexive.
- Remark. irreflexive does NOT mean not
reflexive! - Ex.The relation likes between people is not
reflexive, but it is not irreflexive either.
Since not everyone likes themselves, but not
everyone dislikes themselves either!
8Symmetry Antisymmetry
- Def. A binary relation R on A is symmetric iff R
R-1, that is, if (a,b)?R ? (b,a)?R. - Ex. (equality) is symmetric. lt is not.
- is married to is symmetric, likes is not.
- Def. A binary relation R is antisymmetric if
?a?b, (a,b)?R ? (b,a)?R. - Ex.
- lt is antisymmetric, likes is not.
- Prove this definition of antisymmetric is
equivalent to the statement that R?R-1 ? IA.
9Transitivity
- Def. A relation R is transitive iff (for all
a,b,c) (a,b)?R ? (b,c)?R ? (a,c)?R. - Def. A relation is intransitive iff it is not
transitive. - Ex.
- is an ancestor of is transitive.
- likes between people is intransitive.
- is located within 1 mile of is ?
10Totality
- Def. A relation RAB is total if ?a?A, b?B ?
(a,b)?R. - Def. If R is not total, then it is called
strictly partial. - Def. A partial relation is a relation that might
be strictly partial. (Or, it might be total.) - In other words, all relations are considered
partial.
11Functionality
- Def. A relation RAB is functional if, for any
a?A, there is at most 1 b?B such that (a,b)?R. - R is functional ? ?a?A ?b1?b2?B aRb1 ? aRb2.
- Iff R is functional, then it corresponds to a
partial function RA?B - where R(a)b ? aRb e.g.
- Ex. The relation aRb a b 0 yields the
function -(a) b. - Def. R is antifunctional if its inverse relation
R-1 is functional. - Note A functional relation (partial function)
that is also antifunctional is an invertible
partial function. - Def. R is a total function RA?B if it is both
functional and total, that is, for any a?A, there
is exactly 1 b such that (a,b)?R. I.e., ?a?A
?!b aRb. - If R is functional but not total, then it is a
strictly partial function. - Ex. Show that iff R is functional and
antifunctional, and both it and its inverse are
total, then it is a bijective function.
12Lambda Notation
- Def. The lambda calculus is a formal mathematical
language for defining and operating on functions. - It is the mathematical foundation of a number of
functional (recursive function-based) programming
languages, such as LISP and ML. - It is based on lambda notation, in which ?a
f(a) is a way to denote the function f without
ever assigning it a specific symbol. - E.g., (?x. 3x22x) is a name for the function
fR?R where f(x)3x22x. - Lambda notation and the such that operator ?
can also be used to compose an expression for the
function that corresponds to any given functional
relation. - Let RAB be any functional relation on A,B.
- Then the expression (?a b ? aRb) denotes the
function fA?B where f(a) b iff aRb. - E.g., If I write f (?a b ? ab 0),this is
one way of defining the function f(a)-a.
13Composite Relations
- Def. Let RAB, and SBC. Then the composite
S?R of R and S is defined as - S?R (a,c) ?b aRb ? bSc
- Note that function composition f?g is an example.
- Q. Prove that RAA is transitive iff R?R R.
- Def. The nth power Rn of a relation R on a set A
can be defined recursively by R0 IA Rn1
Rn?R for all n0. - Negative powers of R can also be defined if
desired, by R-n (R-1)n.
147.2 n-ary Relations
- Def. An n-ary relation R on sets A1,,An,
written (with signature) RA1An or RA1,,An,
is simply a subset R ? A1 An. - Def. The sets Ai are called the domains of R.
- The degree of R is n.
- Def. R is functional in the domain Ai if it
contains at most one n-tuple (, ai ,) for any
value ai within domain Ai.
15Relational Databases
- Remark.
- A relational database is essentially just an
n-ary relation R. - A domain Ai is a primary key for the database if
the relation R is functional in Ai. - A composite key for the database is a set of
domains Ai, Aj, such that R contains at most
1 n-tuple (,ai,,aj,) for each composite value
(ai, aj,)?AiAj
16Selection Operators
- Def. Let A be any n-ary domain AA1An, and let
CA?T,F be any condition (predicate) on
elements (n-tuples) of A. Then, the selection
operator sC is the operator that maps any (n-ary)
relation R on A to the n-ary relation of all
n-tuples from R that satisfy C. - I.e., ?R?A, sC(R) a?R sC(a) T
17Selection Operator Example
- Ex. Suppose we have a domain A StudentName
Standing SocSecNos - Suppose we define a certain condition on A,
UpperLevel(name,standing,ssn) (standing
junior) ? (standing senior) - Then, sUpperLevel is the selection operator that
takes any relation R on A (database of students)
and produces a relation consisting of just the
upper-level classes (juniors and seniors).
18Projection Operators
- Def. Let A A1An be any n-ary domain, and let
ik(i1,,im) be a sequence of indices all
falling in the range 1 to n,That is, where 1
ik n for all 1 k m.Then the projection
operator on n-tuplesis defined by
19Projection Example
- Suppose we have a ternary (3-ary) domain
CarsModelYearColor. (note n3). - Consider the index sequence ik 1,3. (m2)
- Then the projection P simply maps each tuple
(a1,a2,a3) (model,year,color) to its image - This operator can be usefully applied to a whole
relation R?Cars (a database of cars) to obtain a
list of the model/color combinations available.
ik
20Join Operator
- Puts two relations together to form a sort of
combined relation. - Def. If the tuple (A,B) appears in R1, and the
tuple (B,C) appears in R2, then the tuple (A,B,C)
appears in the join J(R1,R2). - A, B, and C here can also be sequences of
elements (across multiple fields), not just
single elements.
21Join Example
- Suppose R1 is a teaching assignment table,
relating Professors to Courses. - Suppose R2 is a room assignment table relating
Courses to Rooms,Times. - Then J(R1,R2) is like your class schedule,
listing (professor,course,room,time).
227.3 Representing Relations
- Some ways to represent n-ary relations
- With an explicit list or table of its tuples.
- With a function from the domain to T,F.
- Or with an algorithm for computing this function.
- Some special ways to represent binary relations
- With a zero-one matrix.
- With a directed graph.
23Using Zero-One Matrices
- Def. To represent a binary relation RAB by an
AB 0-1 matrix MR mij, let mij 1 iff
(ai,bj)?R. - Ex. Suppose Joe likes Susan and Mary, Fred likes
Mary, and Mark likes Sally.Then the 0-1 matrix
representationof the relationLikesBoysGirlsr
elation is
24Zero-One Reflexive, Symmetric
- Terms Reflexive, non-reflexive,
irreflexive,symmetric, asymmetric, and
antisymmetric. - These relation characteristics are very easy to
recognize by inspection of the zero-one matrix.
any-thing
any-thing
anything
anything
any-thing
any-thing
Reflexiveall 1s on diagonal
Irreflexiveall 0s on diagonal
Symmetricall identicalacross diagonal
Antisymmetricall 1s are acrossfrom 0s
25Using Directed Graphs
- Def. A directed graph or digraph G(VG,EG) is a
set VG of vertices (nodes) with a set EG?VGVG of
edges (arcs,links). Visually represented using
dots for nodes, and arrows for edges. Notice
that a relation RAB can be represented as a
graph GR(VGA?B, EGR).
Edge set EG(blue arrows)
Graph rep. GR
Matrix representation MR
Joe
Susan
Fred
Mary
Mark
Sally
Node set VG(black dots)
26Digraph Reflexive, Symmetric
- It is extremely easy to recognize the
reflexive/irreflexive/ symmetric/antisymmetric
properties by graph inspection.
?
?
?
?
?
?
?
?
?
?
?
ReflexiveEvery nodehas a self-loop
IrreflexiveNo nodelinks to itself
SymmetricEvery link isbidirectional
AntisymmetricNo link isbidirectional
These are asymmetric non-antisymmetric
These are non-reflexive non-irreflexive
277.4 Closures of Relations
- Def. For any property X, the X closure of a set
A is defined as the smallest superset of A that
has the given property.The reflexive closure of
a relation R on A is obtained by adding (a,a) to
R for each a?A. I.e., it is R ? IAThe
symmetric closure of R is obtained by adding
(b,a) to R for each (a,b) in R. I.e., it is R ?
R-1The transitive closure or connectivity
relation of R is obtained by repeatedly adding
(a,c) to R for each (a,b),(b,c) in R. - I.e., it is
28Paths in Digraphs/Binary Relations
- Def. A path of length n from node a to b in the
directed graph G (or the binary relation R) is a
sequence (a,x1), (x1,x2), , (xn-1,b) of n
ordered pairs in EG (or R). - An empty sequence of edges is considered a path
of length 0 from a to a. - If any path from a to b exists, then we say that
a is connected to b. (You can get there from
here.) - Def. A path of length n1 from a to itself is
called a circuit or a cycle. - Note that there exists a path of length n from a
to b in R if and only if (a,b)?Rn.
29Simple Transitive Closure Alg.
- A procedure to compute R with 0-1 matrices.
- procedure transClosure(MRrank-n 0-1 mat.)
- A B MR
- for i 2 to n begin A A?MR B B ? A
joinendreturn B Alg. takes T(n4) time
note A represents Ri, B represents
30A Faster Transitive Closure Alg.
- procedure transClosure(MRrank-n 0-1 mat.)
- A MR
- for i 1 to ?log2 n? begin A A?(AIn) A
represents endreturn A Alg. takes
only T(n3 log n) time!
31Roy-Warshall Algorithm
- Uses only T(n3) operations!
- Procedure Warshall(MR rank-n 0-1 matrix)
- W MR
- for k 1 to n for i 1 to n for j 1 to
n wij wij ? (wik ? wkj)return W this
represents R
wij 1 means there is a path from i to j going
only through nodes k
32(No Transcript)
337.5 Equivalence Relations
- Def. An equivalence relation (e.r.) on a set A is
simply any binary relation on A that is
reflexive, symmetric, and transitive. - Ex.
- itself is an equivalence relation.
- For any function fA?B, the relation have the
same f value, or f (a1,a2) f(a1)f(a2)
is an equivalence relation, - e.g., let mmother of then m have the same
mother is an e.r.
34Equivalence Relation Examples
- Strings a and b are the same length.
- Integers a and b have the same absolute value.
- Real numbers a and b have the same fractional
part. (i.e., a - b ? Z) - Integers a and b have the same residue modulo
m. (for a given mgt1)
35Equivalence Classes
- Def. Let R be any equiv. rel. on a set A.
- The equivalence class of a, aR b aRb
(optional subscript R) - It is the set of all elements of A that are
equivalent to a according to the eq.rel. R. - Each such b (including a itself) is called a
representative of aR. - Since f(a)aR is a function of a, any
equivalence relation R can be defined using aRb
a and b have the same f value, given f.
36Equivalence Class Examples
- Strings a and b are the same length.
- a the set of all strings of the same length
as a. - Integers a and b have the same absolute value.
- a the set a, -a
- Real numbers a and b have the same fractional
part (i.e., a - b ? Z). - a the set , a-2, a-1, a, a1, a2,
- Integers a and b have the same residue modulo
m. (for a given mgt1) - a the set , a-2m, a-m, a, am, a2m,
37Partitions
- Def. A partition of a set A is the set of all the
equivalence classes A1, A2, for some
equivalence relation on A. - The Ais are all disjoint and their union A.
- They partition the set into pieces. Within
each piece, all members of that set are
equivalent to each other.
387.6 Partial Orderings
- Def. A relation R on A is called a partial
ordering or partial order iff it is - reflexive,
- antisymmetric, and - transitive. - We often use a symbol looking something like ?
(or analogous shapes) for such relations. - Examples , on real numbers, ?, ? on sets.
- Another example the divides relation on Z.
- Note it is not necessarily the case that either
a?b or b?a. - A set A together with a partial order ? on A is
called a partially ordered set or poset and is
denoted (A, ?).
39Posets as Noncyclical Digraphs
- There is a one-to-one correspondence between
posets and the reflexivetransitive closures of
noncyclical digraphs. - Noncyclical Containing no directed cycles.
- Example consider the poset (0,,10,)
- Its minimaldigraph
2
4
8
6
3
1
0
9
5
10
7
40More to come
- More slides on partial orderings to be added in
the future
41References
- RosenDiscrete Mathematics and its Applications,
5eMc GrawHill, 2003