Slides for Rosen, 5th edition

Module #4 - Functions
CS2013: Relations and Functions
14/07/2017
Kees van Deemter
1
Module #4 - Functions
Relations and Functions
• Some background for CS2013
• Necessary for understanding the difference
between
– Deterministic FSAs (DFSAs) and
– NonDeterministic FSAs (NDFSAs)
14/07/2017
Kees van Deemter
2
Module #4 - Functions
If what follows
is new or puzzling…
• … then read K.H.Rosen, Discrete
Mathematics and Its Applications, the
Chapters on sets, functions, and relations
(Chapters 2 and 9 in the 7th edition).
• Free copies in pdf can be found on the web
http://www2.fiit.stuba.sk/~kvasnicka/Mathematics%20for%20Informatics/Ros
en_Discrete_Mathematics_and_Its_Applications_7th_Edition.pdf
14/07/2017
Kees van Deemter
3
Module #4 - Functions
Relations and Functions
• Simple mathematical constructs
• Based on elementary set theory
• Can be used to model many things
– including the set of edges in a given FSA
14/07/2017
Kees van Deemter
4
Module #4 - Functions
Cartesian product
• The Cartesian product of n sets
A1 x A2 x … x An
First n=2 (a 2-place relation)
A x B = The Cartesian product of A and B
= {(x,y): xA and yB}. Example:
A= set of all students (e.g., John, Mary),
B=set of all CAS marks (e.g., 1-20)
14/07/2017
Kees van Deemter
5
Module #4 - Functions
• Student x CAS = {(John,1),(John,2),…
(John,20),(Mary,1),…,(Mary,20)}
• A1 x A2 x … x An = {(x1,x2,…,xn):
x1A and x2A and … and xnA}
14/07/2017
Kees van Deemter
6
Module #4 - Functions
Binary Relations
• Let A, B be sets. A binary relation R from A to B
is a subset of A×B. Analogous for n-ary relations
• E.g., < can be seen as {(n,m) | n < m}
– (a,b)R means that a is related to b (by R)
– Also written as aRb; also R(a,b)
• Can be used to model real-life facts.
E.g., Scored = {(xStudent,yCAS):
x scored y in last years’s CS2013 exam}
14/07/2017
Kees van Deemter
7
Module #4 - Functions
Binary Relations
Aside:
This way of modelling relations using sets
suggests some natural questions and
operations, e.g.,
14/07/2017
Kees van Deemter
8
Module #4 - Functions
Inverse Relations
Any binary relation R:A×B has an inverse
relation R−1:B×A, defined by
R−1 :≡ {(b,a) | (a,b)R}.
E.g., <−1 = {(b,a) | a<b} = {(b,a) | b>a}
=>
14/07/2017
Kees van Deemter
9
Module #4 - Functions
Reflexivity and relatives
• A relation R on A is reflexive
iff aA(aRa).
– E.g., the relation ≥ :≡ {(a,b) | a≥b} is reflexive.
• R is irreflexive iff aA(aRa)
• Note “irreflexive” does NOT mean “not
reflexive”, which is just aA(aRa).
• E.g., if Adore={(j,m),(b,m),(m,b)(j,j)} then this
relation is neither reflexive nor irreflexive
14/07/2017
Kees van Deemter
10
Module #4 - Functions
Some examples
•
Reflexive:
=, ‘have same cardinality’, 
<=, >=, , , etc.
14/07/2017
Kees van Deemter
11
Module #4 - Functions
Symmetry & relatives
• A binary relation R on A is symmetric iff
a,b((a,b)R ↔ (b,a)R).
– E.g., = (equality) is symmetric. < is not.
– “is married to” is symmetric, “likes” is not.
• A binary relation R is asymmetric if
a,b((a,b)R → (b,a)R).
– Examples: < is asymmetric, “Adores” is not.
• Let R={(j,m),(b,m),(j,j)}. Is R (a)symmetric?
14/07/2017
Kees van Deemter
12
Module #4 - Functions
Symmetry & relatives
• Let R={(j,m),(b,m),(j,j)}.
R is not symmetric (because it does not contain
(m,b) and because it does not contain (m,j)).
R is not asymmetric, due to (j,j)
14/07/2017
Kees van Deemter
13
Module #4 - Functions
Antisymmetry
•
•
•
•
•
Consider the relation xy
Is it symmetrical?
Is it asymmetrical?
Is it reflexive?
Is it irreflexive?
14/07/2017
Kees van Deemter
14
Module #4 - Functions
Antisymmetry
•
•
•
•
•
Consider the relation xy
Is it symmetrical? No
Is it asymmetrical?
Is it reflexive?
Is it irreflexive?
14/07/2017
Kees van Deemter
15
Module #4 - Functions
Antisymmetry
•
•
•
•
•
Consider the relation xy
Is it symmetrical? No
Is it asymmetrical? No
Is it reflexive?
Is it irreflexive?
14/07/2017
Kees van Deemter
16
Module #4 - Functions
Antisymmetry
•
•
•
•
•
Consider the relation xy
Is it symmetrical? No
Is it asymmetrical? No
Is it reflexive? Yes
Is it irreflexive?
14/07/2017
Kees van Deemter
17
Module #4 - Functions
Antisymmetry
•
•
•
•
•
Consider the relation xy
Is it symmetrical? No
Is it asymmetrical? No
Is it reflexive? Yes
Is it irreflexive? No
14/07/2017
Kees van Deemter
18
Module #4 - Functions
Antisymmetry
• Consider the relation xy
– It is not symmetric. (For instance,
56 but not 65)
– It is not asymmetric. (For instance, 5 5)
– The pattern: the only times when (a,b) 
and (b,a)  are when a=b
• This is called antisymmetry
14/07/2017
Kees van Deemter
19
Module #4 - Functions
Antisymmetry
• A binary relation R on A is antisymmetric iff
a,b((a,b)R  (b,a)R) a=b).
• Examples: , , 
• Another example: the earlier-defined relation
Adore={(j,m),(b,m),(j,j)}
14/07/2017
Kees van Deemter
20
Module #4 - Functions
Transitivity & relatives
• A relation R is transitive iff (for all a,b,c)
((a,b)R  (b,c)R) → (a,c)R.
• A relation is nontransitive iff it is not
transitive.
• A relation R is intransitive iff (for all a,b,c)
((a,b)R  (b,c)R) → (a,c)R.
14/07/2017
Kees van Deemter
21
Module #4 - Functions
Transitivity & relatives
• What about these examples:
– “x is an ancestor of y”
– “x likes y”
– “x is located within 1 mile of y”
– “x +1 =y”
– “x beat y in the tournament”
14/07/2017
Kees van Deemter
22
Module #4 - Functions
Transitivity & relatives
• What about these examples:
– “is an ancestor of” is transitive.
– “likes” is neither trans nor intrans.
– “is located within 1 mile of”
is neither trans nor intrans
– “x +1 =y” is intransitive
– “x beat y in the tournament” is neither trans nor
intrans
14/07/2017
Kees van Deemter
23
Module #4 - Functions
• End of aside
14/07/2017
Kees van Deemter
24
Module #4 - Functions
the difference between
relations and functions
Totality:
• A relation R:A×B is total if for every aA,
there is at least one bB such that (a,b)R.
– N.B., it does not follow that R−1 is total
– It does not follow that R is functional
(see over).
14/07/2017
Kees van Deemter
25
Module #4 - Functions
Functionality
Functionality:
• A relation R: A×B is functional iff, for every
aA, there is at most one bB such that (a,b)R.
– A functional relation R: A×B does not have to be
total (there may be aA such that ¬bB (aRb)).
14/07/2017
Kees van Deemter
26
Module #4 - Functions
Functionality
• R: A×B is functional iff, for every aA, there is
at most one bB such that (a,b)R.
aA: ¬ b1,b2 B (b1≠b2  aRb1  aRb2).
• If R is a functional and total relation, then R can
be seen as a function R: A→B
Hence one can write R(a)=b as well as aRb,
R(a,b), and (a,b) R. Each of these mean the
same.
14/07/2017
Kees van Deemter
27
Module #4 - Functions
Examples
•
•
•
•
14/07/2017
Consider the relation Scored again:
A relation between Student and CAS
Is it a total relation?
Is it a functional relation?
Kees van Deemter
28
Module #4 - Functions
Functionality for
3-place relations
• Consider a 3-place relation R
• R is a subset of A1 x A2 x A3,
(for some A1, A2, A3)
• R is functional in its first two arguments if
for all xA1 and yA2, there exists at most
one zA3 such that (x,y,z)  R.
• This is easy to generalise to n arguments
14/07/2017
Kees van Deemter
29
Module #4 - Functions
Examples
• Suppose you model addition of natural
numbers as a 3-place relation
(0,0,0),(0,1,1), (1,0,1), (1,1,2),…
This relation is functional in its first
two arguments.
14/07/2017
Kees van Deemter
30
Module #4 - Functions
Examples
• Let Scored’ be a subset of
Student x CAS x PASS, namely
{(student,casmark,yes/no): student scored
casmark and passed yes/no}
• Is the relation Scored’ functional in its first
two arguments?
14/07/2017
Kees van Deemter
31
Module #4 - Functions
Examples
• Let Scored’ be a subset of
Student x CAS x PASS, namely
{(student,casmark,yes/no): student scored
casmark and passed yes/no}
• Is the relation Scored’ functional in its first
two arguments?
• Yes: given (a student and) a CAS mark, you
cannot have both pass-yes and pass-no
14/07/2017
Kees van Deemter
32