In mathematics, the transitive closure of a homogeneous binary relation on a set is the smallest relation on that contains and is transitive. For finite sets, "smallest" can be taken in its usual sense, of having the fewest related pairs; for infinite sets is the unique minimal transitive superset of .
For example, if is a set of airports and means "there is a direct flight from airport to airport " (for and in), then the transitive closure of on is the relation such that means "it is possible to fly from to in one or more flights".
More formally, the transitive closure of a binary relation on a set is the smallest (w.r.t. ⊆) transitive relation on such that ⊆ ; see . We have = if, and only if, itself is transitive.
Conversely, transitive reduction adduces a minimal relation from a given relation such that they have the same closure, that is, ; however, many different with this property may exist.
Both transitive closure and transitive reduction are also used in the closely related area of graph theory.
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 (and thus equivalent to the Cartesian square, which is "x and y are both days of the week").
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, wecan prove that transitive closure is given by the following expression
R+
infty | |
=cup | |
i=1 |
Ri.
Ri
R1=R
i>0
Ri+1=R\circRi
\circ
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.
R\subseteqR+
R+
Ri
R+
R
R+
(s1,s2),(s2,s3)\inR+
(s1,s2)\inRj
(s2,s3)\inRk
j,k
R+
Rj+k=Rj\circRk
(s1,s3)\inRj+k\subseteqR+
\circ
R+
R+
T
R
R+\subseteqT
T
i
Ri\subseteqT
i
R1=R\subseteqT
Ri\subseteqT
(s1,s3)\inRi+1=R\circRi
(s1,s2)\inR
(s2,s3)\inRi
s2
\circ
(s1,s2),(s2,s3)\inT
(s1,s3)\inT
T
Ri\subseteqT
i
R+\subseteqT
R+
The intersection of two transitive relations is transitive.
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 (reflexivity and symmetry—in the case of equivalence relations—are automatic).
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(1) operation one may determine that node d is reachable from node a. The data structure is typically stored as a Boolean matrix, so if matrix[1][4] = true, 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 (DAG) is the reachability relation of the DAG and a strict partial order.
The transitive closure of an undirected graph produces a cluster graph, a disjoint union of cliques. Constructing the transitive closure is an equivalent formulation of the problem of finding the components of the graph.
The transitive closure of a binary relation cannot, in general, be expressed in first-order logic (FO).This means that one cannot write a formula using predicate symbols R and T that will be satisfied inany model if and only if T is the transitive closure of R.In finite model theory, first-order logic (FO) extended with a transitive closure operator is usually called transitive closure logic, and abbreviated FO(TC) or just TC. TC is a sub-type of fixpoint logics. The fact that FO(TC) 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.[1] With more recent concepts of finite model theory, proof that FO(TC) is strictly more expressive than FO follows immediately from the fact that FO(TC) is not Gaifman-local.[2]
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.
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 (1999) 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, PostgreSQL, and MySQL (v8.0+). SQLite released support for this in 2014.
Datalog also implements transitive closure computations.[3]
MariaDB implements Recursive Common Table Expressions, which can be used to compute transitive closures. This feature was introduced in release 10.2.2 of April 2016.[4]
Efficient algorithms for computing the transitive closure of the adjacency relation of a graph can be found in . Reducing the problem to multiplications of adjacency matrices achieves the time complexity of matrix multiplication,[5]
O(n2.3728596)
O(n3)
For directed graphs, Purdom's algorithm solves the problem by first computing its condensation DAG and its transitive closure, then lifting it to the original graph. Its runtime is
O(m+\mun)
\mu
More recent research has explored efficient ways of computing transitive closure on distributed systems based on the MapReduce paradigm.[10]