www.math.sc.chula.ac.th

Download Report

Transcript www.math.sc.chula.ac.th

Outlines
2301233
Relations
2
Binary Relations
2301233
Relations
3
Binary Relations

Let A and B be sets. A binary
relation from A to B is a
subset of A  B.
1
2

1
a
5
3
b
2
3
4
A relation on the set A is a
relation from A to A.
4
c
{(1,1), (2,3), (3,2), (3,4),(4,3), (5,5)}
5
d
{(2,a), (3,b), (3,d), (4,c), (5,d)}
2301233
Relations
4
Directed Graphs
A directed graph (digraph) contains a set of vertices
(or nodes) and a set of edges coming from one node
to other node.
edge
vertex or node
A
B
C
D
E
F
Digraphs are used to represent binary relations.
2301233
Relations
5
Examples
R1 = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}.
R2 = {(a, b) | a, b  I, a < b}.
(3, 4)  R2 , (3, 3)  R2
R3 = {(a, b) | a, b  ℤ, a  b}.
(3, 3)  R3 , (4, 3)  R3
R4 = {(a, b) | a, b  ℤ, a  b}.
(3, -1)  R4 , (-1, 0)  R4
R5 = {(a, b)| a, b ℝ, a2 + b2  0} = {(a, b)| a,b  ℝ}.
(3, 4)  R5 , (4, 3)  R5
2301233
Relations
6
Properties of Relations
2301233
Relations
7
Reflexivity
A relation R on a set A is called reflexive if a  A (a,
a)  R.
Examples:
R1 = {(a, b) | a, b  ℤ, a  b}.
aℤ a  a. Then,aℤ (a, a)R1.
B
A
Thus, R1 is reflexive.
R2 = {(a, b) | a, b ℤ, a  b}.
C
D
aℤ a  a. Then,aℤ (a, a)R2.
Thus, R2 is reflexive.
2301233
Relations
8
Symmetric
A relation R on a set A is called symmetric if
a,b  A (a, b)  R iff (b, a)  R.
Examples:
A
B
C
D
R1 = {(a, b) | a,b  ℕ , a+b < 10}.
If (a, b) R1 , then a+b < 10 and b+a < 10.
Thus, (b,a)R1. Similarly, if (b,a) R1, then (a,b)R1.
Therefore, R1 is symmetric.
2301233
Relations
9
Anti-symmetric
A relation R on a set A is called anti-symmetric if
a,b  A if (a, b)  R and (b, a)  R then a=b.
Examples:
A
B
C
D
R1 = {(a, b) | a,b  ℤ , a  b}.
If (a, b) R1 and (b, a) R1 , then a  b and b  a.
That is, a=b. Therefore, R1is anti-symmetric.
2301233
Relations
10
Transitivity
A relation R on a set A is called transitive if
a,b,cA if (a, b)  R and (b, c)  R, then (a, c)  R.
Examples:
A
B
C
D
R1 = {(a, b) | a, b  ℤ, a  b}.
a,b,c ℤ if a  b and b  c, then a  c.
Thus, R1 is transitive.
2301233
Relations
11
Operations on relations
2301233
Relations
12
Set operations on relations
2301233
Relations
13
Composition
Let R and S be relations from A to B and B to C.
S  R = {(a, c)| there is b in B that (a, b) R and (b, c) S}.
R = {(1,a),(2,c),(3,b),(4,b)}
S = {(a,x),(b,x),(b,y),(d,y)}
S  R = {(1,x),(3,x),(3,y),(4,x),(4,y)}
1
2301233
R
a
2
b
3
c
4
d
S
1
x
2
y
3
z
4
Relations
SoR
x
y
z
14
Examples
Let P and S be relations on ℝ.
P = {(a, a +1)| a  ℝ }.
S = {(a, b)| a  ℝ, b  ℝ, b = a}.
S  P = {(a, b)| a  ℝ, b  ℝ, b = a+1}.
Let P and S be relations on ℤ.
P = {(a, b)| a, b  ℤ, c  ℤ, a2 + b2 = c2 }.
S = {(a, a+1)| a  ℤ }.
S  P = {(a, b+1)| a, b  ℤ, c  ℤ, a2 + b2 = c2 }.
= {(a, b)| a, b  I, c  I, a2 + (b-1)2 = c2 }.
2301233
Relations
15
Power of relations
Let R be a relation on A.
The powers Rn, n=1,2,…, are defined recursively
as follow.
2301233
Relations
16
THEOREM
The relation R on a set A is transitive if and only
if Rn  R, n=1,2,….
Proof:
(if part)
Let R be a relation on a set A and Rn  R, n=1,2,…
Then, R2  R. That is, R o R  R.
Then, any (a, c)  R  R is in R.
This means, if there is b in A that (a, b) R and (b,
c) R, (a, c)  R.
That is, R is transitive.
2301233
Relations
17
THEOREM
(Only-if part)
Let R be a transitive relation on a set A.
Basis: R1 = R  R.
Induction hypothesis: Assume Rn-1  R.
Induction step: Let (a, c) be any element in Rn .
Then, there is b such that (a, b) Rn-1 and (b, c) R.
Since Rn-1  R, (a, b) R.
Since R is transitive, (a, c)  R.
2301233
Relations
18
n-ary Relations
2301233
Relations
19
n-ary relations
Let A1, A2, …, An be sets. An n-ary relation on A1,
A2, …, An is a subset of A1  A2  …  An.
A1, A2, …, An are called domains of relations.
n is called the degree of relations.
Examples
Let R1, R2, R3 be the relations on ℕ  ℕ  ℕ.
 R1 = {(a, b, c) | c = a  b}.
 R2 = {(a, b, c) | a2 + b2 =c2}.
 R3 = {(a, b, c) | c= a mod b}.
2301233
Relations
20
Finite State Machine
state
q
control
tape head
0
2301233
1
1
tape
0
1
Relations
0
1
21
Finite State Machine
1,2,3
F1
4
3,4
F2
1,2
States
1
F3
2,3,4
Alphabet
state
F1
F1
F1
F1
F2
F2
F2
F2
F3
F3
F3
F3
symbol nextSt
1
F2
2
F2
3
F2
4
F3
1
F1
2
F1
3
F3
4
F3
1
F1
2
F2
3
F2
4
F2
Transition function
Start state
nextState=F(state, symbol)
Accepted (final)
states
2301233
Relations
22
How a Finite State Machine Works
state
Exactly one state in one moment
q
control
0
10
2301233
1
0
0
1
10
01
10
Relations
01
10
1
23
n-ary relations and databases
ID
52121223
51212123
name
Somsak Saksri
Somsri Somsak
dept
Math
Math
gpx
3.83
3.91
credit
36
61
…
…
…
…
…
A set of domains is a key if no two tuples in the relation have the same value
from this set of domains.
Extension
2301233
Intension
Relations
24
Operations on n-ary relations
2301233
Relations
25
Selection
Let R be an n-ary relation, and C be a condition that
tuples in R may satisfy.
The selection operator SCR can be defined as follow:
SC R = {tR | C(t) is true}. (sometimes, C R)
2301233
a1
a2
…
an
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Relations
26
Selection: Example
Let R be a relation with attributes AccNo,
AccName,AccType, Balance, shown below.
Let C = (AccType=“savings”  Balance>100000).
R
SC R
AccNo AccName
AccType Balance
AccNo AccName
AccType Balance
12010
Clinton
savings
287600
12010
Clinton
savings
23114
Bush
checking 419200
23114
Bush
16514
Candy
savings
200
16514
Candy
savings
200
16254
Rosen
savings
80209
16254
Rosen
savings
80209
13142
McNair
checking 221330
13142
McNair
2301233
Relations
287600
checking 419200
checking 221330
27
Projection
Let R be an n-ary relation.
The projection operator Pi1, i2,…, im R (sometimes, i1,
i2,…, im R) can be defined as follow:
Pi1, i2,…, im R = {(ai1, ai2,…, aim)|(a1, a2,…, an)  R}.
2301233
a1
a2
…
an
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Relations
28
Projection: Example
Let R be a relation with attributes AccNo,
AccName,AccType, Balance, shown below.
R
P1,4 R
2301233
AccNo AccName
AccType Balance
AccNo Balance
12010
Clinton
savings
287600
12010 287600
23114
Bush
checking 419200
23114 419200
16514
Candy
savings
…
…
…
…
…
…
…
…
…
…
…
…
16254
Rosen
savings
13142
McNair
200
80209
checking 221330
Relations
16514
16254
200
80209
13142 221330
29
Join
Let R be an m-ary relation, and S be an n-ary relation.
The join operator Jp(R, S) (sometimes, R ⊳⊲ S ), where
pm, pn, can be defined as follow:
Jp(R, S) = {(a1, a2,…, am-p,c1, c2,…, cp,b1, b2,…, bnp) |
(a1,a2,…,am-p,c1,c2,…,cp)R  (c1,c2,…,cp,b1,b2,…,bn-p)S }.
2301233
Relations
30
Join
R a ... a
… cp
1
m-p c1
…
…
…
Jp(R, S)
2301233
…
…
…
…
…
…
…
…
…
…
…
…
S c … c b ...
1
p
1
…
…
…
…
…
…
…
…
bn-p
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
a1
…
...
…
am-p
…
c1
…
…
…
cp
…
b1
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Relations
...
bn-p
…
31
Join: Example
Let R and S be relations shown below.
R AccName AccType AccNo
S
AccNo
Balance
Clinton
savings
12010
12010
287600
Bush
checking
23114
23114
419200
Candy
savings
16514
01211
981219
Rosen
saving
16254
16254
80209
McNair
checking
13142
13142
221330
AccNo
AccName
AccType
Balance
12010
Clinton
savings
287600
23114
Bush
checking
419200
16254
Rosen
saving
13142
McNair
checking
J1(R , S)
2301233
Relations
80209
221330
32
Representations of Relations
2301233
Relations
33
Representation of Binary Relations
a
b
c
d
a
b
c
d
e
a
1
1
0
0
0
b
0
1
0
0
0
c
0
1
1
1
0
d
0
0
0
1
0
e
0
0
0
0
0
Matrices
e
Digraphs
2301233
Relations
34
Representing Relations Using Matrices


A relation R from the set A
= {a1, a2, …, am} to the set
B = {b1, b2, …, bn} can be
represented by a 0-1 matrix
MR = [mij] where
mij = 1 if (ai, bj)  R.
mij = 0 if (ai, bj)  R.
Example:
Let A = {1, 2, 3, 4}.
Let R be a relation on A.
R= {(1, 2), (1, 3), (1, 4),
(2, 3), (2, 4), (3, 4)}.
MR =
2301233
Relations
0
0
0
0
1
0
0
0
1
1
0
0
1
1
1
0
35
Operations through Matrices
Let R and S be relations, represented by matrices MR
and MS.
 Inverse

 MR-1 = MRT

Union
 MRS = MR  MS

Intersection
 MRS = MR  MS
2301233
Relations
36
Matrices: Reflexive Relations
Reflexive
1
?
?
?
?
?
1
?
?
?
?
?
1
?
?
?
?
?
1
?
?
?
?
?
1
Let R be a relation on A, where |A|=n.
R is reflexive iff mii = 1 for any 1i n.
2301233
Relations
37
Matrices: Symmetric & Anti-symmetric Relations
R is symmetric iff MR = MRT.
? 1
1 ?
0 0
0 1
0 1
Symmetric
2301233
0
0
?
0
1
0
1
0
?
1
0
1
1
1
?
R is reflexive iff mij and mji
are not both 1 when i  j.
? 1 0 0
0 ? 1 0
0 0 ? 0
0 1 0 ?
0 0 0 0
Anti-symmetric
Relations
0
1
0
1
?
38
Closures of Relations
2301233
Relations
39
Closure
Let R be a relation on a set A.
Let P be a property of relations, e.g. reflexivity,
symmetry, and transitivity.
The closure of R with respect to P is the relation that
has the property P and contains R.
Reflexive closure
 Symmetric closure
 Transitive closure

2301233
Relations
40
Reflexive Closure
The reflexive closure of R is a reflexive relation that
contains R.
Let R be a relation on A.
Let  = {(a, a)| aA} be the diagonal relation on A.
The reflexive closure of R = R   .
Example: Let R = { (a,b)|a<b, a,bℤ }.
The reflexive closure of R
= { (a, b)|a<b, a,bℤ }  { (a, a) | a ℤ }
= { (a, b)|ab, a,bℤ }.

2301233
Relations
41
Symmetric Closure
The symmetric closure of R is a symmetric relation
that contains R.
Let R be a relation on A.
Let R-1 = {(a, b)| (b, a)  R}.
The symmetric closure of R = R  R-1 .
Example: Let R = {(a,b)|a<b, a,bℤ }.
The symmetric closure of R
= { (a,b)|a<b, a,bℤ }  { (b, a)|a<b, a,bℤ }
= { (a,b)|ab, a,bℤ }.

2301233
Relations
42
Transitive Closure
The transitive closure of R is a transitive relation that
contains R.
Let R be a relation on A.
Let T = R ⊙ S. tij =  rik  skj.
1kn
The transitive closure of R = R*=
.

Example: Let R =
2301233
1
1
0
0
0
0
0
1
0
1
0
0
0
0
0
0
1
0
1
1
0
0
0
0
0
Relations
43
Transitive Closure: Example
1
0
R= 0
0
0
1
0
0
1
0
0
1
0
0
0
0
0
0
1
0
1
0
R* = 0
0
0
2301233
0
1
0 R2=
1
0
1
0
0
1
0
0
1
0
0
0
0
0
0
1
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0 R3=
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
1
0
Relations
44
and

Which properties does the relation “friends” in
have?
 Reflexive
 symmetric

Which properties does the relation “friends” in
have?
 Reflexive
2301233
Relations
45
Congruence
Let n be an integer, and Rn = {(a,b) I | a  b (mod n)}.
R3 = { …, (0,-3), (0,0), (0,3), (0,6), (0,9), …,
…,(1,-2), (1,1), (1,4), (1,7), (1,10), …,
…,(2,-1), (2,2), (2,5), (2,8), (2,11), …}.
For any integer n, Rn is
reflexive, (because a  a (mod n) for any a in I )
symmetric, (because, for any a and b in I, a  b (mod n)
iff b  a (mod n) )
and transitive (because, for any a, b and c in I, if a  b
(mod n) and b  c (mod n) then a  c (mod n) ).
2301233
Relations
46
Equivalence Relations
2301233
Relations
47
Equivalence Relations
A relation on a set A is called an equivalence relation if it
is reflexive, symmetric, and transitive.
Two elements a and b that are related by an equivalence
relation are called equivalent. We write a~b.
OR
Let R be an equivalence relation. a and b are called
equivalent , denoted by a~b, if (a, b)R.
2301233
Relations
48
Equivalence Relations: Example
Let m be a natural number.
Let Rm = {(a, b)ℕℕ| a mod m = b mod m}.
Since aℕ a mod m = a mod m, Rm is reflexive.
a mod m = b mod m iff b mod m = a mod m, for any
natural numbers a and b. Then, Rm is symmetric.
a,b,cℕ if a mod m = b mod m and b mod m = c mod
m, then a mod m = c mod m. Then, Rm is transitive.
Then, Rm is an equivalence relation.
For R7 , 1~8~15~22…
2~9~16~23…
3~10~17~24…
4~11~18~25… 5~12~19~26…
6~13~20~27…
7~14~21~28…
Congruence class
2301233
Relations
49
Non-equivalence Relations: Example
Let R = {(a, b)ℤℤ | a  b}.
Since a ℤ a  a, R is reflexive.
a  b but b  a, for some integers a and b. Then, Rm is
not symmetric.
a,b,c ℤ if a  b and b  c, then a  c. Then, R is
transitive.
Then, R is not an equivalence relation.
2301233
Relations
50
Equivalence Classes
Let R be an equivalence relation on a set A. The set
of all elements that are related to an element a in
the set A is called an equivalence class of a, denoted
by [a].
OR
Let R be an equivalence relation on a set A, and a be
an element in A .
An equivalence class of a, denoted by [a],
= { bA | a~b}.
2301233
Relations
51
Equivalence Classes: Example
Let R7 = {(a, b)ℕℕ| a mod 3 = b mod 3}.
There are 3 equivalence classes of R7, say [0], [1], [2].
[0] = {0,3,6,9,12,15,…} = {3i| i ℕ}.
[1] = {1,4,7,10,13,16,…} = {3i+1| i ℕ}.
[2] = {2,5,8,11,14,17,…} = {3i+2| i ℕ}.
2301233
Relations
52
Equivalence Class: Example
3
9
0
15
6
10
4
12
2
17
7
1
8
14
13
16
2301233
11
5
Relations
53
About Equivalence Relations
Let R be an equivalence relation on a set A.
The following statements for elements a and b of A
are equivalent.
aRb
 [a] = [b] (or, [a]  [b] and [b]  [a] )
 [a]  [b] 
To prove this theorem, we show that
 a R b  [a] = [b]
 [a] = [b]  [a]  [b] 
 [a]  [b]   a R b
2301233
Relations
54
a R b  [a] = [b]
Let R be an equivalence relation on a set A.
For any elements a and b in A, a R b  [a] = [b].
Proof:
Let R be an equivalence relation on a set A.
Let a and b be elements in A and a R b.
Let c be any element in [a] . Then, a R c.
Since R is an equivalence relation, R is symmetric and
transitive.
Then, b R a. Since b R a and a R c, b R c.
That is, c is in [b] . Thus, [a]  [b].
Similarly, we can show [b]  [a]. Then, [a]=[b].
2301233
Relations
55
[a] = [b]  [a]  [b] 
Let R be an equivalence relation on a set A.
For any elements a and b in A, [a] = [b]  [a]  [b] .
Proof:
Let R be an equivalence relation on a set A.
Let a and b be elements in A and [a] = [b].
[a] and [b] are not empty because a is in [a] and b is in [b].
Thus, [a]  [b] .
2301233
Relations
56
[a]  [b]   a R b
Let R be an equivalence relation on a set A.
For any elements a and b in A, [a]  [b]   a R b.
Proof:
Let R be an equivalence relation on a set A.
Let a and b be elements in A and [a]  [b]  .
Then, there is an element c in both [a] and [b] .
Then, a R c and b R c.
Because R is symmetric, c R b.
Because R is transitive a R c and and c R b, a R b.
2301233
Relations
57
Partition
A partition of a set S is a collection of disjoint, nonempty subsets of S such that S is their union.
OR
The collection of subsets A1, A2, …, An forms a
partition of a set S iff
 Ai   , i=1,2,…,n.
 Ai  Aj =  when i  j.

.
2301233
Relations
58
Equivalence Classes 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 A1, A2, …, An of the set
S, there is an equivalence relation R that has the sets
A1, A2, …, An as its equivalence classes.

2301233
Relations
59