Transitive closure
In mathematics, the transitive closure of a binary relation R on a set X is the smallest relation on X that contains R and is transitive.
For example, if X is a set of airports and xRy means "there is a direct flight from airport x to airport y", then the transitive closure of R on X is the relation R+ such that x R+ y means "it is possible to fly from x to y in one or more flights". Informally, the transitive closure gives you the set of all places you can get to from any starting place.
More formally, the transitive closure of a binary relation R on a set X is the transitive relation R+ on set X such that R+ contains R and R+ is minimal. If the binary relation itself is transitive, then the transitive closure is that same binary relation; otherwise, the transitive closure is a different relation.
Transitive relations and examples
A relation R on a set X is transitive if, for all x, y, z in X, whenever and then. Examples of transitive relations include the equality relation on any set, the "less than or equal" relation on any linearly ordered set, and the relation "x was born before y" on the set of all people. Symbolically, this can be denoted as: if and then.One example of a non-transitive relation is "city x can be reached via a direct flight from city y" on the set of all cities. Simply because there is a direct flight from one city to a second city, and a direct flight from the second city to the third, does not imply there is a direct flight from the first city to the third. The transitive closure of this relation is a different relation, namely "there is a sequence of direct flights that begins at city x and ends at city y". Every relation can be extended in a similar way to a transitive relation.
An example of a non-transitive relation with a less meaningful transitive closure is "x is the day of the week after y". The transitive closure of this relation is "some day x comes after a day y on the calendar", which is trivially true for all days of the week x and y.
Existence and description
For any relation R, the transitive closure of R always exists. To see this, note that the intersection of any family of transitive relations is again transitive. Furthermore, there exists at least one transitive relation containing R, namely the trivial one: X × X. The transitive closure of R is then given by the intersection of all transitive relations containing R.For finite sets, we can construct the transitive closure step by step, starting from R and adding transitive edges.
This gives the intuition for a general construction. For any set X, we
can prove that transitive closure is given by the following expression
where is the i-th power of R, defined inductively by
and, for,
where denotes composition of relations.
To show that the above definition of R+ is the least transitive relation containing R, we show that it contains R, that it is transitive, and that it is the smallest set with both of those characteristics.
- : contains all of the, so in particular contains.
- is transitive: If, then and for some by definition of. Since composition is associative, ; hence by definition of and.
- is minimal, that is, if is any transitive relation containing, then : Given any such, induction on can be used to show for all as follows: Base: by assumption. Step: If holds, and, then and for some, by definition of. Hence, by assumption and by induction hypothesis. Hence by transitivity of ; this completes the induction. Finally, for all implies by definition of.
Properties
The union of two transitive relations need not be transitive. To preserve transitivity, one must take the transitive closure. This occurs, for example, when taking the union of two equivalence relations or two preorders. To obtain a new equivalence relation or preorder one must take the transitive closure.
In graph theory
In computer science, the concept of transitive closure can be thought of as constructing a data structure that makes it possible to answer reachability questions. That is, can one get from node a to node d in one or more hops? A binary relation tells you only that node a is connected to node b, and that node b is connected to node c, etc. After the transitive closure is constructed, as depicted in the following figure, in an O operation one may determine that node d is reachable from node a. The data structure is typically stored as a matrix, so if matrix = 1, then it is the case that node 1 can reach node 4 through one or more hops.The transitive closure of the adjacency relation of a directed acyclic graph is the reachability relation of the DAG and a strict partial order.
In logic and computational complexity
The transitive closure of a binary relation cannot, in general, be expressed in first-order logic.This means that one cannot write a formula using predicate symbols R and T that will be satisfied in
any model if and only if T is the transitive closure of R.
In finite model theory, first-order logic extended with a transitive closure operator is usually called transitive closure logic, and abbreviated FO or just TC. TC is a sub-type of fixpoint logics. The fact that FO is strictly more expressive than FO was discovered by Ronald Fagin in 1974; the result was then rediscovered by Alfred Aho and Jeffrey Ullman in 1979, who proposed to use fixpoint logic as a database query language. With more recent concepts of finite model theory, proof that FO is strictly more expressive than FO follows immediately from the fact that FO is not Gaifman-local.
In computational complexity theory, the complexity class NL corresponds precisely to the set of logical sentences expressible in TC. This is because the transitive closure property has a close relationship with the NL-complete problem STCON for finding directed paths in a graph. Similarly, the class L is first-order logic with the commutative, transitive closure. When transitive closure is added to second-order logic instead, we obtain PSPACE.
In database query languages
Since the 1980s Oracle Database has implemented a proprietary SQL extension CONNECT BY... START WITH that allows the computation of a transitive closure as part of a declarative query. The SQL 3 standard added a more general WITH RECURSIVE construct also allowing transitive closures to be computed inside the query processor; as of 2011 the latter is implemented in IBM DB2, Microsoft SQL Server, Oracle, and PostgreSQL, although not in MySQL.Datalog also implements transitive closure computations.
Algorithms
Efficient algorithms for computing the transitive closure of the adjacency relation of a graph can be found in Nuutila. The fastest worst-case methods, which are not practical, reduce the problem to matrix multiplication. The problem can also be solved by the Floyd–Warshall algorithm, or by repeated breadth-first search or depth-first search starting from each node of the graph.More recent research has explored efficient ways of computing transitive closure on distributed systems based on the MapReduce paradigm.