Binary Relations Closures CITS2211 Discrete Structures Lectures for Semester 2 2013 Part 4: Binary Relations Unit coordinator: Mark Reynolds Notes: Rachel Cardell-Oliver Lecturer: Gordon Royle September 3, 2013 Functions Binary Relations Closures Functions Cartesian product Definition: The Cartesian product of sets S and T is a set of pairs: S × T = {(s, t) | s ∈ S ∧ t ∈ T } The Cartesian product can be generalised to n-tuples for more than 2 sets: S1 × S2 × . . . × Sn = {(s1 , s2 , . . . sn ) | s1 ∈ S1 ∧ . . . ∧ sn ∈ Sn } Binary Relations Closures Functions Binary Relations Definition: Given sets A and B, a binary relation R between A and B is a subset of A × B. The sets A and B are called the domain and codomain of R, respectively. We commonly use the notation a R b or a ∼R b or R(a, b) to denote that (a, b) ∈ R Relations are used in Computer Science to specify and reason about data, for example, in data base theory and theories of object-orientation. Binary Relations Closures Functions Defining Relations Given that binary relations are sets, they can be defined by any of the methods already given for defining sets: Enumeration: {(0, 0), (1, −1), (2, −2)} Abstraction: {(x, y ) | x ≤ y } Relations can be combined using the set operations ∪ and ∩ and complement. Binary Relations Closures Types of Relations Exercise: Express each of these characteristics using a predicate. Functions Binary Relations Closures Examples The relation describing students and student numbers is Functions Binary Relations Closures Examples The relation describing students and student numbers is one-to-one The relation describing students and computer accounts is Functions Binary Relations Closures Examples The relation describing students and student numbers is one-to-one The relation describing students and computer accounts is one-to-many The relation describing students and degree programmes is Functions Binary Relations Closures Examples The relation describing students and student numbers is one-to-one The relation describing students and computer accounts is one-to-many The relation describing students and degree programmes is many-to-one The relation describing students and unit enrolments is Functions Binary Relations Closures Examples The relation describing students and student numbers is one-to-one The relation describing students and computer accounts is one-to-many The relation describing students and degree programmes is many-to-one The relation describing students and unit enrolments is many-to-many Note that not all s ∈ S nor t ∈ T need appear in the relation. ∅ is a perfectly good relation! Functions Binary Relations Closures Properties of Relations For any relation R : A → A Definition: Reflexivity R is reflexive iff ∀x ∈ A. xRx Example: Everyone likes themselves. Definition: Symmetry R is symmetric iff ∀x, y ∈ A. xRy → yRx Example: If x likes y, then y likes x. Definition: Transitivity R is transitive iff ∀x, y , z ∈ A. xRy ∧ yRz → xRz Example: If x likes y and y likes z, then x likes z too. Functions Binary Relations Closures Case study lecture State the type of each of the following sets, stating any assumptions you make. Which are relations? likes, motherof , ancestorof , parentsof , connectedto <, ≥, +, =, → For each binary relation above, state whether it is reflexive, transitive, symmetric. Give reasons to justify your answer. Functions Binary Relations Closures Functions Definition: Antisymmetry R is antisymmetric iff ∀x, y ∈ A. xRy ∧ yRx → x = y Example: If x likes y and y likes x then x is the same as y, that is no pair of distinct people like each other Definition: Asymmetry R is asymmetric iff ¬∃x, y ∈ A. xRy ∧ yRx No one likes themselves and no pair of people like each other. Definition: Irreflexivity R is irreflexive iff ¬∃x ∈ A. xRx Example: No one likes themselves. Binary Relations Closures Functions Every relation R : A → B can be represented as a bipartite graph G = (V , E ) by creating a left node for each element of A and a right node for each element of B. We then create an edge between a left node u and a right node v whenever uRv Every relation on a single set A can be modelled as a directed graph (albeit one that may contain loops). Example: What relation is this? What properties does it have? Binary Relations Closures Two important relations Two of the most common operations on data are 1 ordering the data in some way 2 grouping the data in some way Two important classes of relations that capture this are (respectively) 1 partial orderings 2 equivalence relations (or partitions) Functions Binary Relations Closures Functions Definition: A partial ordering on a set S is a binary relation R on S that is reflexive, transitive, and antisymmetric. Intuitively, the relation R orders pairs of elements in the set S, although not necessarily every pair is ordered (hence partial). Sometimes this definition is called a weak partial order. Example: The relation ≤ on the integers Z is a partial order. Example: The relation ⊆ on P(S) is a partial order on set S. Exercise: Prove the above claims from the definitions. Binary Relations Closures Functions Definition: The pair (S, R) of relation R on set S is called a partially-ordered set or poset. Definition: A total order is a partial order in which every pair of distinct elements is comparable. Example: The relation ≤ on the reals R is a total order because for any reals x and y either x ≤ y or y ≤ x. Binary Relations Closures Functions Definition: A Hasse diagram is a way to visualise a poset. Conventions: 1 Every element of the relation set is shown as a vertex in the graph 2 An edge is shown between each vertex and its immediate successor vertices 3 Minimal element(s) at the bottom of the page and max(s) at the top 4 Reflexive pairs, xRx are implied, not shown 5 Transitive pairs, xRz where xRy and yRz are given, are implied, not shown 6 There is more than one way to lay out most Hasse diagrams - finding a good layout can be hard Binary Relations Closures Functions Examples for this Lecture Find a piece of paper and draw diagrams (or list the pairs) for each of the following relations on the sets R = {1, 2, 3, 4} and S = {1, 2, 3, 4, 5, 6, 7, 8} Example: x 6= y on R × R Example: x = y + 1 on R × R Example: x | y (that is x divides y, with no remainder) on S × S Example: x =mod3 y (that is, x mod 3 = y mod 3) on S × S Binary Relations Closures Functions Questions 1 For each of your example relations, state whether it is reflexive, transitive, symmetric, antisymmetric. Justify each answer. 2 Make a note of any visual properties of the graph that will help you remember these definitions. (following the material from the remainder of this lecture) 3 Construct the reflexive and transitive closures of the first two example relations on R × R 4 Construct a topological sort of the poset x | y Binary Relations Closures Functions Definition: An equivalence relation on a set S is a binary relation r on S that is reflexive, transitive, and symmetric. Intuitively, the relation r partitions elements in the set S. Example: The relation = is an equivalence relation on set S. Example: Congruence modulo n is an equivalence relation. Example: Consider a relation “connected to” represented by R : V → V on an undirected graph G = (V , E ) where uRv iff there is a path in the graph from u to v . R is an equivalence relation. Binary Relations Closures Definition: Given an equivalence relation R : A → A, the equivalence class of an element x ∈ A is the set of all elements of A related to x by R. The equivalence class of x is denoted [x] Definition: A partition of a set S is a set of non-empty, pairwise-disjoint subsets of S whose union is S. Functions Binary Relations Closures Functions Theorem: An equivalence relation on a set S uniquely determines a partition of S, and a partition of S uniquely determines an equivalence relation on S Binary Relations Closures Partial orderings and Hasse diagrams are often used to represent problems in task scheduling. By convention the minimal task of the poset is shown on the left and the maximal task on the right, so the task orders read from left to right. Each task is associated with the time taken to complete it: executionTime : tasks → N Functions Binary Relations Closures Functions Definition: We can define a partial ordering on tasks, such that xPy iff task x is a prerequisite for task y . P is a poset: it is reflexive, antisymmetric and transitive. The Hasse diagram for the poset (tasks, P) is called a PERT chart (program evaluation and review technique chart). Source http://www.yourdon.com/strucanalysis/ Binary Relations Closures Definition: the minimum time-to-completion for a process can be calculated from a PERT chart: The earliest start time (EST) for a task t is given by EST (t) = max{ECT (u)|u is an immediate prereq. of t} The earliest completion time (ECT) for a task t is given by ECT (t) = EST (t) + executionTime(t) The ECTs of tasks are calculated left-to-right, starting with the minimal tasks The minimum time-to-completion of a process is the latest ECT of the tasks making up the process Functions Binary Relations Closures Definition: The critical path of a PERT chart is the sequence of tasks that contribute to the minimum time-to-completion: tasks on the critical path are called critical tasks if any critical task is delayed, the minimum time-to-completion of the process is increased if any non-critical task is delayed, the critical path should be re-computed. Critical paths need not be unique. Functions Binary Relations Closures Functions The process of learning to fly a plane can be broken down into the following set of tasks. Task Days to perform Pre-requisite tasks 1. Pass medical test 1 None 2. Learn flight theory 7 1 3. Master plane controls 12 1 4. Learn engine maintenance 5 1 5. Pass initial flying test 1 3, 4 6. Pass theory exams 5 2 7. Learn navigation 7 5, 6 8. Learn ATC procedures 3 5 9. Pass final flying test 1 7, 8 Example: Construct a PERT chart for this process. Binary Relations Closures Functions Example: Use your PERT chart to determine the minimum time-to-completion for the process (show working). Example: Use your PERT chart to determine the critical path for the process. Example: Use your PERT chart to determine a topological sort for the process. Binary Relations Closures Functions Definition: The transitive closure of a binary relation R on a set A is the transitive relation R + on set A such that R ⊆ R + and R + is minimal in that no smaller relation is a transitive closure of R. Example: The reachability relation of a graph tells us which points can be reached in any number of moves from each point. The reachability relation is the transitive closure of the edge relation E of a directed graph G = (V , E ) Binary Relations Closures Functions Definition: The reflexive closure and symmetric closure are defined similarly, as the smallest relation containing R that satisfies the given property. Example: There can be no antisymmetric closure of a relation because antisymmetry is about the absence of pairs from a relation (xRy and yRx must have x = y ) so adding pairs can’t make a relation antisymmetric. Binary Relations Closures Topological Sorting A poset need not have every element comparable. But given a poset (S, p), we can construct a new poset (S, q) by adding tuples until it becomes a total order. That is, a topological sort is a linear order that does not violate the underlying partial order. q is called a topological sort of p. q is not usually unique. In computer science, topological sorting is used for instruction scheduling in compiler optimisation, cell evaluation order for spreadsheets, determining compilation order in makefiles. Functions Binary Relations Closures Functions Topological Sort in Practice This process is easy to visualise from the Hasse diagram: the topological sort gives a single path from min to max elements. If p represents a PERT chart, then q defines a sequential order for the tasks that respects the pre-requisite requirements Topological sorts are not (usually) unique. Binary Relations Closures Functions Binary Relations Closures Algorithm to Construct a Topological Sort Input: A finite poset (S, p) Output: A sequence of elements from S preserving the order p A := S while ( A 6= ∅ ) { pick a minimal element b ∈ A; A := A − {b}; output b } where a minimal element is one with no incoming edges: ¬∃ y ∈ S.(y , b) ∈ p Functions Binary Relations Closures Functions A function is a binary relation R : A → B that can only associate at most one element of B (namely, f (a)) with each element a ∈ A. There will be more about functions in later units, but not in cits2211.
© Copyright 2025 Paperzz