You are on page 1of 49

LOGIKA MATEMATIKA

2006/2007

Relasi dan Fungsi

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},

„ C = {Mercedes, BMW, tricycle}

„ D = {(Carl, Mercedes), (Suzanne, Mercedes),


(Suzanne, BMW), (Peter, tricycle)}
™ This means that Carl drives a Mercedes, Suzanne
drives a Mercedes and a BMW, Peter drives a
tricycle, and Carla does not drive any of these
vehicles.

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?

¾ Suppose A={black, white, grey} and B={large,


small}
™ then A×B = {(black, large), (black, small),
(white , large), (white, small),
(grey, large), (grey, small)}
¾ Can you explain why #(A×B) = #A × #B ?
™ Note that the first × is the Cartesian Product of sets
and the second is multiplication of numbers
¾ Why are (small, grey) and (large, large) not included in
A×B?
9
Relations on a Set

¾Definition: A relation on the set A is a


relation from A to A.
™ In other words, a relation on the set A is
a subset of A×A.
™ Example: Let A = {1, 2, 3, 4}. Which
ordered pairs are in the relation R = {(a,
b) | a < b} ?

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)}

¾R = {(1, 1), (2, 2), (3, 3)}

•Definition: A relation on a set A is called irreflexive if (a, a)∉R for


every element a∈A.
13
How can we check for the reflexive 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 Loops must exist
2 on EVERY vertex.

3
4
14
Properties of Relations

¾ A relation R on a set A is called transitive if


whenever (a, b)∈R and (b, c)∈R, then (a, c)∈R
for a, b, c∈A.
™ Are the following relations on {1, 2, 3, 4}
transitive?
¾R = {(1, 1), (1, 2), (2, 2), (2, 1), (3, 3)}

¾R = {(1, 3), (3, 2), (2, 1)}

¾R = {(2, 4), (4, 3), (2, 3), (4, 1)}

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

Is R transitive? No Is it symmetric? Yes

Is it reflexive? Yes Is it anti-symmetric? No

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

¾ … and there is another important way to combine


relations.
¾ Definition: Let R be a relation from a set A to a set
B and S a relation from B to a set C. The composite
of R and S is the relation consisting of ordered
pairs (a, c), where a∈A, c∈C, and for which there
exists an element b∈B such that (a, b)∈R and
(b, c)∈S. We denote the composite of R and S by
S°R.
¾ In other words, if relation R contains a pair (a, b)
and relation S contains a pair (b, c), then S°R
contains a pair (a, c).
24
Let R be a relation from A to B (R ⊆ AxB), and let S
be a relation from B to C (S ⊆ BxC). The composition
of R and S is the relation from A to C (S°R ⊆ AxC):
S°R = {(a,c): ∃ b∈B, (a,b) ∈ R, (b,c) ∈ S}
A B C
R S
1 x s
2 y t
3 z u
4 v

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)}

¾ D maps an element a to the element (5 – a), and


afterwards S maps (5 – a) to all elements larger than
(5 – a), resulting in S°D = {(a,b) | b > 5 – a} or S°D =
{(a,b) | a + b > 5}.
26
A function is a type of relation

¾ A relation between two sets A, B which


relates each element in A to one and only one
element in B is called a “function of A into B”
¾ Written f: A→B, where f is its name
„ Don’t confuse → with the implication sign
„ A is the domain set, B the co-domain set
„ It is a (special) relation and still a subset of A×B

27
¾ a function is a relation containing
each element of A in exactly one pair

AxB relation function

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 set A The set B

• •
• •
• 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

f maps each element in the domain to exactly one


element, its image, in the range.

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

¾ Bipartite (2-part) graph representations


of functions that are (or not) one-to-one:

• • • •
• • •
• • •
• • •
• • • •
• • •
• • • •
• • •
Not one-to-one Not even a
One-to-one function!

41
Illustration of Onto

¾ Some functions that are, or are not, onto


their codomains:


• • • • • • • •
• • • • • •
• •
• • • •
• • • •
• • • •
• • • •
• •
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

¾ If • (“dot”) is any operator over B, then we


can extend • to also denote an operator
over functions f:A→B.
¾ E.g.: Given any binary operator •:B×B→B,
and functions f,g:A→B, we define
(f • g):A→B to be the function defined by:
∀a∈A, (f • g)(a) = f(a)•g(a).

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.

¾ For functions g:A→B and f:B→C, there is a


special operator called compose (“○”).
™ It composes (creates) a new function out of
f and g by applying f to the result of
applying g.
™ We say (f○g):A→C, where (f○g)(a) :≡ f(g(a)).
™ Note g(a)∈B, so f(g(a)) is defined and ∈C.
™ Note that ○ (like Cartesian ×, but unlike
+,∧,∪) is non-commuting. (Generally, f○g ≠
g○f.)
46
Soal
¾ Misalkan f dan g didefinisikan oleh
™ f(x)= 2x + 1 dan g(x) = x2 – 2
™ Tentukan
„ (g o f) (4)
ƒ g(f(4)) = g(9) = 79
„ (f o g) (4)
ƒ f(g(4)) = f(14) = 29

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

You might also like