Professional Documents
Culture Documents
2006/2007
1
Relating sets of data
¾ In information systems work we expend a great deal
of effort analysing how data sets are related to one
another.
¾ The rules determining how these relationships work
must be accurately translated into software if the IS
is to serve its purpose effectively.
¾ These rules can be formally modeled using an
application of set theory called
The Theory of Relations
¾ We begin with the set theoretic operation that forms
ordered pairs of the elements of two sets.
2
¾ If we want to describe a relationship between
elements of two sets A and B, we can use ordered
pairs with their first element taken from A and
their second element taken from B.
¾ Since this is a relation between two sets, it is
called a binary relation.
Definition: Let A and B be sets. A binary relation
from A to B is a subset of A×B.
¾ In other words, for a binary relation R we have
R ⊆ A×B. We use the notation aRb to denote that
(a, b)∈R and aRb to denote that (a, b)∉R.
3
¾ When (a, b) belongs to R, a is said to be related to
b by R.
Example: Let P be a set of people, C be a set of
cars, and D be the relation describing which person
drives which car(s).
P = {Carl, Suzanne, Peter, Carla},
4
Ordered Pairs are not Sets
¾ (x,y) ≠ {x,y}
the first is a pair, the second is a set
¾ Duplication is permitted
The elements of a pair may be equal
¾ The order is significant
(x,y) ≠ (y,x) unless, of course, x=y
5
Cartesian product
¾ Ordered pairs are generated by a set operation
called the Cartesian product.
¾ It is a binary operation on sets and is written
A×B (say “A cross B”)
¾ The output is the set of ordered pairs:
A×B = { (a, b) | a∈A and b∈B }
A B
6
Tree structure
1 2 3 4 5 6
1,H 1,T 2,H 2,T 3,H 3,T 4,H 4,T 5,H 5,T 6,H 6,T
={1,2,3,4,5,6}× {H,T}
7
Types of Relations
¾ One-to-one correspondence
¾ Many-to-one correspondence
¾ One-to-many correspondence
¾ Many-to-many correspondence
8
How many pairs in a product?
10
Relations on a Set
¾ Solution: R = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}
1 1 R 1 2 3 4
1 X X X
2 2
2 X X
3 3 3 X
4
4 4
11
Domain and Range
¾ The domain is the set of elements which
appear in the 1st column.
¾ The range is the set of elements which
appear in the 2nd column
12
Properties of Relations
¾ Definition: A relation R on a set A is called
reflexive if (a, a)∈R for every element a∈A.
Are the following relations on {1, 2, 3, 4}
reflexive?
¾R = {(1, 1), (1, 2), (2, 3), (3, 3), (4, 4)}
¾R = {(1, 1), (2, 2), (2, 3), (3, 3), (4, 4)}
3
4
14
Properties of Relations
15
How can we check for transitivity?
Draw a picture of the relation (called a “graph”).
Vertex for every element of A
Edge for every element of R
Now, what’s R?
{(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}
1 A “short cut”
2 must be present
for EVERY path
of length 2.
3
4
16
¾ A relation R on a set A is called symmetric if
(b, a)∈R whenever (a, b)∈R for all a, b∈A.
¾ A relation R on a set A is called antisymmetric
if a = b whenever (a, b)∈R and (b, a)∈R.
¾ A relation R on a set A is called asymmetric if
(a, b)∈R implies that (b, a)∉R for all a, b∈A.
17
How can we check for the symmetric property?
Draw a picture of the relation (called a “graph”).
Vertex for every element of A
Edge for every element of R
Now, what’s R?
{(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}
1 EVERY edge
2 must have a
return edge.
3
4
18
Anti-symmetric Relations
¾ A homogeneous relation, R:A↔A, is anti-
symmetric if and only if
∀a,b:A. aRb ∧ bRa → a=b
For example, ≤: N↔N is anti-symmetric
because if a≤b and b≤a then a must be equal
to b.
Note <:N↔N is also anti-symmetric, but this
is less obvious.
The proposition a<b ∧ b<a → a=b is True
because the premise of the implication is
false!
19
How can we check for the anti-symmetric property?
Draw a picture of the relation (called a “graph”).
Vertex for every element of A
Edge for every element of R
Now, what’s R?
{(1,1),(1,2),(1,3),(1,4),(2,2),(2,3),(2,4),(3,3),(3,4),(4,4)}
1 No edge can
2 have a return
edge.
3
4
20
Let R be a relation on People,
R={(x,y): x and y have lived in the same country}
?
1 2
?
?
3
21
Soal
¾ Misal A = {1,2,3,4} kemudian
R = {(1,1),(1,2),(2,3),(1,3),(3,3)}
T = {(1,1),(1,2),(2,2),(2,3)}
S = {(1,1),(1,2),(2,1),(2,2),(3,3),(4,4)}
¾ Mana yang refleksif ? Æ S
¾ Mana yang simetris ? Æ S
¾ Mana yang transitif ? Æ S dan R
¾ Mana yang antisimetris ? Æ R dan T
22
¾ Untuk relasi pada bilangan positif
R : x lebih besar dari y
S : x + y = 10
T : x + 4y = 10
¾ Tentukan mana yang memiliki sifat refleksif,
simetris, transitif dan antisimetri ?
refleksif Æ tak ada
Simetri Æ S
Transitif Æ R,T
Antisimetri Æ R dan T
23
Combining Relations
S°R = {(1,u),(1,v),(2,t),(3,t),(4,u)}
25
¾Example: Let D and S be relations on A = {1, 2, 3, 4}.
D = {(a, b) | b = 5 - a} “b equals (5 – a)”
S = {(a, b) | a < b} “a is smaller than b”
D = {(1, 4), (2, 3), (3, 2), (4, 1)}
S = {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}
S°D = {(2,4),(3,3),(3,4), (4,2), (4,3),(4,4)}
27
¾ a function is a relation containing
each element of A in exactly one pair
A B A B A f B
28
example: A={1,2,3,4}, B={1,4,9,16,25}
¾ A X B contains 4x5 = 20 pairs
¾ sample relation:
E ={(1,1), (1,4), (1,9), (2,9), (3,9)}
¾ sample function:
F ={(1,1), (2,4), (3,9), (4,16)}
29
For nonempty sets, A,B, a function, or mapping, f from
A to B, denoted f:A →B, is a relation from A to B in which
every element of A appears exactly once as the first
component of an ordered pair in the relation.
not allowed
set A set B
30
A diagram of ‘function’
• •
• •
• The dotted
• arrow is
•
• NOT
permitted
A function f: A→B
31
¾ Functions can be represented graphically
in several ways:
f A B
• •
f • •
a• • • y
b •
•
•
• x
A
B Bipartite Graph Plot
Like Venn diagrams
32
Domain, Codomain, Range
A B
f(a)=b range
b
a
domain codomain
33
Functions
¾ domain set of elements
¾ codomain set of elements
¾ formula procedure to determine an
element of codomain associated with every
element of domain
f: A Æ B
34
Some Function Terminology
¾ If it is written that f:A→B, and f(a)=b
(where a∈A & b∈B), then we say:
A is the domain of f.
We also say
B is the codomain of f. the signature
b is the image of a under f. of f is A→B.
a is a pre-image of b under f.
In general, b may have more than 1 pre-image.
The range R⊆B of f is R={b | ∃a f(a)=b }.
35
A tabular view of a function
Let A={a1,a2,a3,a4,a5} and B={b1,b2,b3,b4,b5,b6}
and let f:A→B be represented, in extension, by the table
C o lu m n A C o lu m n B
[d o m a in d a ta ] [ c o -d o m a in d a ta ]
a1 b1
a2 b2
a3 b3
a4 b2
a5 b4
36
¾ Misalkan A adalah himpunan dari mahasiswa
di kampus. Manakah dari pemetaan berikut
ini yang merupakan fungsi ?
Setiap mahasiswa memetakan usianya
Setiap mahasiswa memetakan dosennya
Setiap mahasiswa memetakan jenis
kelaminnya
Setiap mahasiswa memetakan suami dan
istrinya
37
Notation
¾ Given a function f: A→B,
and a pair (a,b) in f, we can write
(a,b) ∈f afb f(a) = b
These are all equivalent.
¾ Formally, we define a function as a relation
f:A↔B in which
∀x:A.∀y,z:B. (xfy ∧ xfz → y=z)
38
The inverse of a function
¾ The relation which relates the outputs of
f to the input(s) which generate them is
called the inverse of f and written f-1
Think of tables and columns again!
Why is f
-1 not necessarily a
function?
39
Functions with special qualities
¾ A one-to-one function (injective) is one in which
every image is unique.
If f:A→B is injective then
∀a:A.∀b:B. f(a)=f(b) → a=b
¾ An onto function (surjective) is one whose range is
equal to its co-domain set.
If f:A→B is surjective then {b:B | ∃a:A.f(a) =b} = B
¾ A one-to-one and onto function (bijective) is both
injective and surjective.
If f:A→B is surjective then the elements of B are
effectively ‘renamed’ by the elements of A.
40
One-to-One Illustration
• • • •
• • •
• • •
• • •
• • • •
• • •
• • • •
• • •
Not one-to-one Not even a
One-to-one function!
41
Illustration of Onto
•
• • • • • • • •
• • • • • •
• •
• • • •
• • • •
• • • •
• • • •
• •
Onto Not Onto Both 1-1 1-1 but
(but not 1-1) (or 1-1) and onto not onto
42
Function? One-to-one? Onto?
A f B A f B A f B
A f B A f B A f B
43
Constructing Function Operators
44
Function Operator Example
¾ +,× (“plus”,“times”) are binary operators
over R. (Normal addition & multiplication.)
¾ Therefore, we can also add and multiply
functions f,g:R→R:
(f + g):R→R, where (f + g)(x) = f(x) + g(x)
(f × g):R→R, where (f × g)(x) = f(x) × g(x)
45
Function Composition Operator
Note match here.
47
¾ Misalkan f dan g didefinisikan oleh
f(x)= 2x + 1 dan g(x) = x2 – 2
Tentukan fungsi komposisi dari g o f dan
fog
(g o f) (x) = g (f(x)) = g (2x + 1) = (2x+1)2-2
= 4x2 + 4x – 1
(f o g) (x) = f(g(x)) = f(x2-2) = 2(x2-2) + 1
= 2x2-3
Tentukan : f o f dan g o g
48
49