Module 4 Functions CS 2013 Relations and Functions
































- Slides: 32
Module #4 - Functions CS 2013: Relations and Functions 16/09/2020 Kees van Deemter 1
Module #4 - Functions Relations and Functions • Some background for CS 2013 • Necessary for understanding the difference between – Deterministic FSAs (DFSAs) and – Non. Deterministic FSAs (NDFSAs) 16/09/2020 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 7 th edition). • Free copies in pdf can be found on the web http: //www 2. fiit. stuba. sk/~kvasnicka/Mathematics%20 for%20 Informatics/Ros en_Discrete_Mathematics_and_Its_Applications_7 th_Edition. pdf 16/09/2020 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 16/09/2020 Kees van Deemter 4
Module #4 - Functions Cartesian product • The Cartesian product of n sets A 1 x A 2 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) 16/09/2020 Kees van Deemter 5
Module #4 - Functions • Student x CAS = {(John, 1), (John, 2), … (John, 20), (Mary, 1), …, (Mary, 20)} • A 1 x A 2 x … x An = {(x 1, x 2, …, xn): x 1 A and x 2 A and … and xn A} 16/09/2020 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 a. Rb; 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 CS 2013 exam} 16/09/2020 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. , 16/09/2020 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} = > 16/09/2020 Kees van Deemter 9
Module #4 - Functions Reflexivity and relatives • A relation R on A is reflexive iff a A(a. Ra). – E. g. , the relation ≥ : ≡ {(a, b) | a≥b} is reflexive. R is irreflexive iff a A( a. Ra) Note “irreflexive” does NOT mean “not reflexive”, which is just a A(a. Ra). • E. g. , if Adore={(j, m), (b, m), (m, b)(j, j)} then this relation is neither reflexive nor irreflexive • • 16/09/2020 Kees van Deemter 10
Module #4 - Functions Some examples • Reflexive: =, ‘have same cardinality’, <=, >=, , , etc. 16/09/2020 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? 16/09/2020 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) 16/09/2020 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? 16/09/2020 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? 16/09/2020 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? 16/09/2020 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? 16/09/2020 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 16/09/2020 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 16/09/2020 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)} 16/09/2020 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. 16/09/2020 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” 16/09/2020 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 16/09/2020 Kees van Deemter 23
Module #4 - Functions • End of aside 16/09/2020 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). 16/09/2020 Kees van Deemter 25
Module #4 - Functions 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 (a. Rb)). 16/09/2020 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: ¬ b 1, b 2 B (b 1≠b 2 a. Rb 1 a. Rb 2). • 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 a. Rb, R(a, b), and (a, b) R. Each of these mean the same. 16/09/2020 Kees van Deemter 27
Module #4 - Functions Examples • • 16/09/2020 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 A 1 x A 2 x A 3, (for some A 1, A 2, A 3) • R is functional in its first two arguments if for all x A 1 and y A 2, there exists at most one z A 3 such that (x, y, z) R. • This is easy to generalise to n arguments 16/09/2020 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. 16/09/2020 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? 16/09/2020 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 16/09/2020 Kees van Deemter 32