Blame isl-0.14/doc/implementation.tex

Packit fb9d21
\section{Sets and Relations}
Packit fb9d21
Packit fb9d21
\begin{definition}[Polyhedral Set]
Packit fb9d21
A {\em polyhedral set}\index{polyhedral set} $S$ is a finite union of basic sets
Packit fb9d21
$S = \bigcup_i S_i$, each of which can be represented using affine
Packit fb9d21
constraints
Packit fb9d21
$$
Packit fb9d21
S_i : \Z^n \to 2^{\Z^d} : \vec s \mapsto
Packit fb9d21
S_i(\vec s) =
Packit fb9d21
\{\, \vec x \in \Z^d \mid \exists \vec z \in \Z^e :
Packit fb9d21
A \vec x + B \vec s + D \vec z + \vec c \geq \vec 0 \,\}
Packit fb9d21
,
Packit fb9d21
$$
Packit fb9d21
with $A \in \Z^{m \times d}$,
Packit fb9d21
$B \in \Z^{m \times n}$,
Packit fb9d21
$D \in \Z^{m \times e}$
Packit fb9d21
and $\vec c \in \Z^m$.
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Parameter Domain of a Set]
Packit fb9d21
Let $S \in \Z^n \to 2^{\Z^d}$ be a set.
Packit fb9d21
The {\em parameter domain} of $S$ is the set
Packit fb9d21
$$\pdom S \coloneqq \{\, \vec s \in \Z^n \mid S(\vec s) \ne \emptyset \,\}.$$
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Polyhedral Relation]
Packit fb9d21
A {\em polyhedral relation}\index{polyhedral relation}
Packit fb9d21
$R$ is a finite union of basic relations
Packit fb9d21
$R = \bigcup_i R_i$ of type
Packit fb9d21
$\Z^n \to 2^{\Z^{d_1+d_2}}$,
Packit fb9d21
each of which can be represented using affine
Packit fb9d21
constraints
Packit fb9d21
$$
Packit fb9d21
R_i = \vec s \mapsto
Packit fb9d21
R_i(\vec s) =
Packit fb9d21
\{\, \vec x_1 \to \vec x_2 \in \Z^{d_1} \times \Z^{d_2}
Packit fb9d21
\mid \exists \vec z \in \Z^e :
Packit fb9d21
A_1 \vec x_1 + A_2 \vec x_2 + B \vec s + D \vec z + \vec c \geq \vec 0 \,\}
Packit fb9d21
,
Packit fb9d21
$$
Packit fb9d21
with $A_i \in \Z^{m \times d_i}$,
Packit fb9d21
$B \in \Z^{m \times n}$,
Packit fb9d21
$D \in \Z^{m \times e}$
Packit fb9d21
and $\vec c \in \Z^m$.
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Parameter Domain of a Relation]
Packit fb9d21
Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
Packit fb9d21
The {\em parameter domain} of $R$ is the set
Packit fb9d21
$$\pdom R \coloneqq \{\, \vec s \in \Z^n \mid R(\vec s) \ne \emptyset \,\}.$$
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Domain of a Relation]
Packit fb9d21
Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
Packit fb9d21
The {\em domain} of $R$ is the polyhedral set
Packit fb9d21
$$\domain R \coloneqq \vec s \mapsto
Packit fb9d21
\{\, \vec x_1 \in \Z^{d_1} \mid \exists \vec x_2 \in \Z^{d_2} :
Packit fb9d21
(\vec x_1, \vec x_2) \in R(\vec s) \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Range of a Relation]
Packit fb9d21
Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
Packit fb9d21
The {\em range} of $R$ is the polyhedral set
Packit fb9d21
$$
Packit fb9d21
\range R \coloneqq \vec s \mapsto
Packit fb9d21
\{\, \vec x_2 \in \Z^{d_2} \mid \exists \vec x_1 \in \Z^{d_1} :
Packit fb9d21
(\vec x_1, \vec x_2) \in R(\vec s) \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Composition of Relations]
Packit fb9d21
Let $R \in \Z^n \to 2^{\Z^{d_1+d_2}}$ and
Packit fb9d21
$S \in \Z^n \to 2^{\Z^{d_2+d_3}}$ be two relations,
Packit fb9d21
then the composition of
Packit fb9d21
$R$ and $S$ is defined as
Packit fb9d21
$$
Packit fb9d21
S \circ R \coloneqq
Packit fb9d21
\vec s \mapsto
Packit fb9d21
\{\, \vec x_1 \to \vec x_3 \in \Z^{d_1} \times \Z^{d_3}
Packit fb9d21
\mid \exists \vec x_2 \in \Z^{d_2} :
Packit fb9d21
\vec x_1 \to \vec x_2 \in R(\vec s) \wedge
Packit fb9d21
\vec x_2 \to \vec x_3 \in S(\vec s)
Packit fb9d21
\,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Difference Set of a Relation]
Packit fb9d21
Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation.
Packit fb9d21
The difference set ($\Delta \, R$) of $R$ is the set
Packit fb9d21
of differences between image elements and the corresponding
Packit fb9d21
domain elements,
Packit fb9d21
$$
Packit fb9d21
\diff R \coloneqq
Packit fb9d21
\vec s \mapsto
Packit fb9d21
\{\, \vec \delta \in \Z^{d} \mid \exists \vec x \to \vec y \in R :
Packit fb9d21
\vec \delta = \vec y - \vec x
Packit fb9d21
\,\}
Packit fb9d21
$$
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\section{Simple Hull}\label{s:simple hull}
Packit fb9d21
Packit fb9d21
It is sometimes useful to have a single
Packit fb9d21
basic set or basic relation that contains a given set or relation.
Packit fb9d21
For rational sets, the obvious choice would be to compute the
Packit fb9d21
(rational) convex hull.  For integer sets, the obvious choice
Packit fb9d21
would be the integer hull.
Packit fb9d21
However, {\tt isl} currently does not support an integer hull operation
Packit fb9d21
and even if it did, it would be fairly expensive to compute.
Packit fb9d21
The convex hull operation is supported, but it is also fairly
Packit fb9d21
expensive to compute given only an implicit representation.
Packit fb9d21
Packit fb9d21
Usually, it is not required to compute the exact integer hull,
Packit fb9d21
and an overapproximation of this hull is sufficient.
Packit fb9d21
The ``simple hull'' of a set is such an overapproximation
Packit fb9d21
and it is defined as the (inclusion-wise) smallest basic set
Packit fb9d21
that is described by constraints that are translates of
Packit fb9d21
the constraints in the input set.
Packit fb9d21
This means that the simple hull is relatively cheap to compute
Packit fb9d21
and that the number of constraints in the simple hull is no
Packit fb9d21
larger than the number of constraints in the input.
Packit fb9d21
\begin{definition}[Simple Hull of a Set]
Packit fb9d21
The {\em simple hull} of a set
Packit fb9d21
$S = \bigcup_{1 \le i \le v} S_i$, with
Packit fb9d21
$$
Packit fb9d21
S : \Z^n \to 2^{\Z^d} : \vec s \mapsto
Packit fb9d21
S(\vec s) =
Packit fb9d21
\left\{\, \vec x \in \Z^d \mid \exists \vec z \in \Z^e :
Packit fb9d21
\bigvee_{1 \le i \le v}
Packit fb9d21
A_i \vec x + B_i \vec s + D_i \vec z + \vec c_i \geq \vec 0 \,\right\}
Packit fb9d21
$$
Packit fb9d21
is the set
Packit fb9d21
$$
Packit fb9d21
H : \Z^n \to 2^{\Z^d} : \vec s \mapsto
Packit fb9d21
S(\vec s) =
Packit fb9d21
\left\{\, \vec x \in \Z^d \mid \exists \vec z \in \Z^e :
Packit fb9d21
\bigwedge_{1 \le i \le v}
Packit fb9d21
A_i \vec x + B_i \vec s + D_i \vec z + \vec c_i + \vec K_i \geq \vec 0
Packit fb9d21
\,\right\}
Packit fb9d21
,
Packit fb9d21
$$
Packit fb9d21
with $\vec K_i$ the (component-wise) smallest non-negative integer vectors
Packit fb9d21
such that $S \subseteq H$.
Packit fb9d21
\end{definition}
Packit fb9d21
The $\vec K_i$ can be obtained by solving a number of
Packit fb9d21
LP problems, one for each element of each $\vec K_i$.
Packit fb9d21
If any LP problem is unbounded, then the corresponding constraint
Packit fb9d21
is dropped.
Packit fb9d21
Packit fb9d21
\section{Parametric Integer Programming}
Packit fb9d21
Packit fb9d21
\subsection{Introduction}\label{s:intro}
Packit fb9d21
Packit fb9d21
Parametric integer programming \shortcite{Feautrier88parametric}
Packit fb9d21
is used to solve many problems within the context of the polyhedral model.
Packit fb9d21
Here, we are mainly interested in dependence analysis \shortcite{Fea91}
Packit fb9d21
and in computing a unique representation for existentially quantified
Packit fb9d21
variables.  The latter operation has been used for counting elements
Packit fb9d21
in sets involving such variables
Packit fb9d21
\shortcite{BouletRe98,Verdoolaege2005experiences} and lies at the core
Packit fb9d21
of the internal representation of {\tt isl}.
Packit fb9d21
Packit fb9d21
Parametric integer programming was first implemented in \texttt{PipLib}.
Packit fb9d21
An alternative method for parametric integer programming
Packit fb9d21
was later implemented in {\tt barvinok} \cite{barvinok-0.22}.
Packit fb9d21
This method is not based on Feautrier's algorithm, but on rational
Packit fb9d21
generating functions \cite{Woods2003short} and was inspired by the
Packit fb9d21
``digging'' technique of \shortciteN{DeLoera2004Three} for solving
Packit fb9d21
non-parametric integer programming problems.
Packit fb9d21
Packit fb9d21
In the following sections, we briefly recall the dual simplex
Packit fb9d21
method combined with Gomory cuts and describe some extensions
Packit fb9d21
and optimizations.  The main algorithm is applied to a matrix
Packit fb9d21
data structure known as a tableau.  In case of parametric problems,
Packit fb9d21
there are two tableaus, one for the main problem and one for
Packit fb9d21
the constraints on the parameters, known as the context tableau.
Packit fb9d21
The handling of the context tableau is described in \autoref{s:context}.
Packit fb9d21
Packit fb9d21
\subsection{The Dual Simplex Method}
Packit fb9d21
Packit fb9d21
Tableaus can be represented in several slightly different ways.
Packit fb9d21
In {\tt isl}, the dual simplex method uses the same representation
Packit fb9d21
as that used by its incremental LP solver based on the \emph{primal}
Packit fb9d21
simplex method.  The implementation of this LP solver is based
Packit fb9d21
on that of {\tt Simplify} \shortcite{Detlefs2005simplify}, which, in turn,
Packit fb9d21
was derived from the work of \shortciteN{Nelson1980phd}.
Packit fb9d21
In the original \shortcite{Nelson1980phd}, the tableau was implemented
Packit fb9d21
as a sparse matrix, but neither {\tt Simplify} nor the current
Packit fb9d21
implementation of {\tt isl} does so.
Packit fb9d21
Packit fb9d21
Given some affine constraints on the variables,
Packit fb9d21
$A \vec x + \vec b \ge \vec 0$, the tableau represents the relationship
Packit fb9d21
between the variables $\vec x$ and non-negative variables
Packit fb9d21
$\vec y = A \vec x + \vec b$ corresponding to the constraints.
Packit fb9d21
The initial tableau contains $\begin{pmatrix}
Packit fb9d21
\vec b & A
Packit fb9d21
\end{pmatrix}$ and expresses the constraints $\vec y$ in the rows in terms
Packit fb9d21
of the variables $\vec x$ in the columns.  The main operation defined
Packit fb9d21
on a tableau exchanges a column and a row variable and is called a pivot.
Packit fb9d21
During this process, some coefficients may become rational.
Packit fb9d21
As in the \texttt{PipLib} implementation,
Packit fb9d21
{\tt isl} maintains a shared denominator per row.
Packit fb9d21
The sample value of a tableau is one where each column variable is assigned
Packit fb9d21
zero and each row variable is assigned the constant term of the row.
Packit fb9d21
This sample value represents a valid solution if each constraint variable
Packit fb9d21
is assigned a non-negative value, i.e., if the constant terms of
Packit fb9d21
rows corresponding to constraints are all non-negative.
Packit fb9d21
Packit fb9d21
The dual simplex method starts from an initial sample value that
Packit fb9d21
may be invalid, but that is known to be (lexicographically) no
Packit fb9d21
greater than any solution, and gradually increments this sample value
Packit fb9d21
through pivoting until a valid solution is obtained.
Packit fb9d21
In particular, each pivot exchanges a row variable
Packit fb9d21
$r = -n + \sum_i a_i \, c_i$ with negative
Packit fb9d21
sample value $-n$ with a column variable $c_j$
Packit fb9d21
such that $a_j > 0$.  Since $c_j = (n + r - \sum_{i\ne j} a_i \, c_i)/a_j$,
Packit fb9d21
the new row variable will have a positive sample value $n$.
Packit fb9d21
If no such column can be found, then the problem is infeasible.
Packit fb9d21
By always choosing the column that leads to the (lexicographically)
Packit fb9d21
smallest increment in the variables $\vec x$,
Packit fb9d21
the first solution found is guaranteed to be the (lexicographically)
Packit fb9d21
minimal solution \cite{Feautrier88parametric}.
Packit fb9d21
In order to be able to determine the smallest increment, the tableau
Packit fb9d21
is (implicitly) extended with extra rows defining the original
Packit fb9d21
variables in terms of the column variables.
Packit fb9d21
If we assume that all variables are non-negative, then we know
Packit fb9d21
that the zero vector is no greater than the minimal solution and
Packit fb9d21
then the initial extended tableau looks as follows.
Packit fb9d21
$$
Packit fb9d21
\begin{tikzpicture}
Packit fb9d21
\matrix (m) [matrix of math nodes]
Packit fb9d21
{
Packit fb9d21
& {} & 1 & \vec c \\
Packit fb9d21
\vec x && |(top)| \vec 0 & I \\
Packit fb9d21
\vec r && \vec b & |(bottom)|A \\
Packit fb9d21
};
Packit fb9d21
\begin{pgfonlayer}{background}
Packit fb9d21
\node (core) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)] {};
Packit fb9d21
\end{pgfonlayer}
Packit fb9d21
\end{tikzpicture}
Packit fb9d21
$$
Packit fb9d21
Each column in this extended tableau is lexicographically positive
Packit fb9d21
and will remain so because of the column choice explained above.
Packit fb9d21
It is then clear that the value of $\vec x$ will increase in each step.
Packit fb9d21
Note that there is no need to store the extra rows explicitly.
Packit fb9d21
If a given $x_i$ is a column variable, then the corresponding row
Packit fb9d21
is the unit vector $e_i$.  If, on the other hand, it is a row variable,
Packit fb9d21
then the row already appears somewhere else in the tableau.
Packit fb9d21
Packit fb9d21
In case of parametric problems, the sign of the constant term
Packit fb9d21
may depend on the parameters.  Each time the constant term of a constraint row
Packit fb9d21
changes, we therefore need to check whether the new term can attain
Packit fb9d21
negative and/or positive values over the current set of possible
Packit fb9d21
parameter values, i.e., the context.
Packit fb9d21
If all these terms can only attain non-negative values, the current
Packit fb9d21
state of the tableau represents a solution.  If one of the terms
Packit fb9d21
can only attain non-positive values and is not identically zero,
Packit fb9d21
the corresponding row can be pivoted.
Packit fb9d21
Otherwise, we pick one of the terms that can attain both positive
Packit fb9d21
and negative values and split the context into a part where
Packit fb9d21
it only attains non-negative values and a part where it only attains
Packit fb9d21
negative values.
Packit fb9d21
Packit fb9d21
\subsection{Gomory Cuts}
Packit fb9d21
Packit fb9d21
The solution found by the dual simplex method may have
Packit fb9d21
non-integral coordinates.  If so, some rational solutions
Packit fb9d21
(including the current sample value), can be cut off by
Packit fb9d21
applying a (parametric) Gomory cut.
Packit fb9d21
Let $r = b(\vec p) + \sp {\vec a} {\vec c}$ be the row
Packit fb9d21
corresponding to the first non-integral coordinate of $\vec x$,
Packit fb9d21
with $b(\vec p)$ the constant term, an affine expression in the
Packit fb9d21
parameters $\vec p$, i.e., $b(\vec p) = \sp {\vec f} {\vec p} + g$.
Packit fb9d21
Note that only row variables can attain
Packit fb9d21
non-integral values as the sample value of the column variables is zero.
Packit fb9d21
Consider the expression
Packit fb9d21
$b(\vec p) - \ceil{b(\vec p)} + \sp {\fract{\vec a}} {\vec c}$,
Packit fb9d21
with $\ceil\cdot$ the ceiling function and $\fract\cdot$ the
Packit fb9d21
fractional part.  This expression is negative at the sample value
Packit fb9d21
since $\vec c = \vec 0$ and $r = b(\vec p)$ is fractional, i.e.,
Packit fb9d21
$\ceil{b(\vec p)} > b(\vec p)$.  On the other hand, for each integral
Packit fb9d21
value of $r$ and $\vec c \ge 0$, the expression is non-negative
Packit fb9d21
because $b(\vec p) - \ceil{b(\vec p)} > -1$.
Packit fb9d21
Imposing this expression to be non-negative therefore does not
Packit fb9d21
invalidate any integral solutions, while it does cut away the current
Packit fb9d21
fractional sample value.  To be able to formulate this constraint,
Packit fb9d21
a new variable $q = \floor{-b(\vec p)} = - \ceil{b(\vec p)}$ is added
Packit fb9d21
to the context.  This integral variable is uniquely defined by the constraints
Packit fb9d21
$0 \le -d \, b(\vec p) - d \, q \le d - 1$, with $d$ the common
Packit fb9d21
denominator of $\vec f$ and $g$.  In practice, the variable
Packit fb9d21
$q' = \floor{\sp {\fract{-f}} {\vec p} + \fract{-g}}$ is used instead
Packit fb9d21
and the coefficients of the new constraint are adjusted accordingly.
Packit fb9d21
The sign of the constant term of this new constraint need not be determined
Packit fb9d21
as it is non-positive by construction.
Packit fb9d21
When several of these extra context variables are added, it is important
Packit fb9d21
to avoid adding duplicates.
Packit fb9d21
Recent versions of {\tt PipLib} also check for such duplicates.
Packit fb9d21
Packit fb9d21
\subsection{Negative Unknowns and Maximization}
Packit fb9d21
Packit fb9d21
There are two places in the above algorithm where the unknowns $\vec x$
Packit fb9d21
are assumed to be non-negative: the initial tableau starts from
Packit fb9d21
sample value $\vec x = \vec 0$ and $\vec c$ is assumed to be non-negative
Packit fb9d21
during the construction of Gomory cuts.
Packit fb9d21
To deal with negative unknowns, \shortciteN[Appendix A.2]{Fea91}
Packit fb9d21
proposed to use a ``big parameter'', say $M$, that is taken to be
Packit fb9d21
an arbitrarily large positive number.  Instead of looking for the
Packit fb9d21
lexicographically minimal value of $\vec x$, we search instead
Packit fb9d21
for the lexicographically minimal value of $\vec x' = \vec M + \vec x$.
Packit fb9d21
The sample value $\vec x' = \vec 0$ of the initial tableau then
Packit fb9d21
corresponds to $\vec x = -\vec M$, which is clearly not greater than
Packit fb9d21
any potential solution.  The sign of the constant term of a row
Packit fb9d21
is determined lexicographically, with the coefficient of $M$ considered
Packit fb9d21
first.  That is, if the coefficient of $M$ is not zero, then its sign
Packit fb9d21
is the sign of the entire term.  Otherwise, the sign is determined
Packit fb9d21
by the remaining affine expression in the parameters.
Packit fb9d21
If the original problem has a bounded optimum, then the final sample
Packit fb9d21
value will be of the form $\vec M + \vec v$ and the optimal value
Packit fb9d21
of the original problem is then $\vec v$.
Packit fb9d21
Maximization problems can be handled in a similar way by computing
Packit fb9d21
the minimum of $\vec M - \vec x$.
Packit fb9d21
Packit fb9d21
When the optimum is unbounded, the optimal value computed for
Packit fb9d21
the original problem will involve the big parameter.
Packit fb9d21
In the original implementation of {\tt PipLib}, the big parameter could
Packit fb9d21
even appear in some of the extra variables $\vec q$ created during
Packit fb9d21
the application of a Gomory cut.  The final result could then contain
Packit fb9d21
implicit conditions on the big parameter through conditions on such
Packit fb9d21
$\vec q$ variables.  This problem was resolved in later versions
Packit fb9d21
of {\tt PipLib} by taking $M$ to be divisible by any positive number.
Packit fb9d21
The big parameter can then never appear in any $\vec q$ because
Packit fb9d21
$\fract {\alpha M } = 0$.  It should be noted, though, that an unbounded
Packit fb9d21
problem usually (but not always)
Packit fb9d21
indicates an incorrect formulation of the problem.
Packit fb9d21
Packit fb9d21
The original version of {\tt PipLib} required the user to ``manually''
Packit fb9d21
add a big parameter, perform the reformulation and interpret the result
Packit fb9d21
\shortcite{Feautrier02}.  Recent versions allow the user to simply
Packit fb9d21
specify that the unknowns may be negative or that the maximum should
Packit fb9d21
be computed and then these transformations are performed internally.
Packit fb9d21
Although there are some application, e.g.,
Packit fb9d21
that of \shortciteN{Feautrier92multi},
Packit fb9d21
where it is useful to have explicit control over the big parameter,
Packit fb9d21
negative unknowns and maximization are by far the most common applications
Packit fb9d21
of the big parameter and we believe that the user should not be bothered
Packit fb9d21
with such implementation issues.
Packit fb9d21
The current version of {\tt isl} therefore does not
Packit fb9d21
provide any interface for specifying big parameters.  Instead, the user
Packit fb9d21
can specify whether a maximum needs to be computed and no assumptions
Packit fb9d21
are made on the sign of the unknowns.  Instead, the sign of the unknowns
Packit fb9d21
is checked internally and a big parameter is automatically introduced when
Packit fb9d21
needed.  For compatibility with {\tt PipLib}, the {\tt isl\_pip} tool
Packit fb9d21
does explicitly add non-negativity constraints on the unknowns unless
Packit fb9d21
the \verb+Urs_unknowns+ option is specified.
Packit fb9d21
Currently, there is also no way in {\tt isl} of expressing a big
Packit fb9d21
parameter in the output.  Even though
Packit fb9d21
{\tt isl} makes the same divisibility assumption on the big parameter
Packit fb9d21
as recent versions of {\tt PipLib}, it will therefore eventually
Packit fb9d21
produce an error if the problem turns out to be unbounded.
Packit fb9d21
Packit fb9d21
\subsection{Preprocessing}
Packit fb9d21
Packit fb9d21
In this section, we describe some transformations that are
Packit fb9d21
or can be applied in advance to reduce the running time
Packit fb9d21
of the actual dual simplex method with Gomory cuts.
Packit fb9d21
Packit fb9d21
\subsubsection{Feasibility Check and Detection of Equalities}
Packit fb9d21
Packit fb9d21
Experience with the original {\tt PipLib} has shown that Gomory cuts
Packit fb9d21
do not perform very well on problems that are (non-obviously) empty,
Packit fb9d21
i.e., problems with rational solutions, but no integer solutions.
Packit fb9d21
In {\tt isl}, we therefore first perform a feasibility check on
Packit fb9d21
the original problem considered as a non-parametric problem
Packit fb9d21
over the combined space of unknowns and parameters.
Packit fb9d21
In fact, we do not simply check the feasibility, but we also
Packit fb9d21
check for implicit equalities among the integer points by computing
Packit fb9d21
the integer affine hull.  The algorithm used is the same as that
Packit fb9d21
described in \autoref{s:GBR} below.
Packit fb9d21
Computing the affine hull is fairly expensive, but it can
Packit fb9d21
bring huge benefits if any equalities can be found or if the problem
Packit fb9d21
turns out to be empty.
Packit fb9d21
Packit fb9d21
\subsubsection{Constraint Simplification}
Packit fb9d21
Packit fb9d21
If the coefficients of the unknown and parameters in a constraint
Packit fb9d21
have a common factor, then this factor should be removed, possibly
Packit fb9d21
rounding down the constant term.  For example, the constraint
Packit fb9d21
$2 x - 5 \ge 0$ should be simplified to $x - 3 \ge 0$.
Packit fb9d21
{\tt isl} performs such simplifications on all sets and relations.
Packit fb9d21
Recent versions of {\tt PipLib} also perform this simplification
Packit fb9d21
on the input.
Packit fb9d21
Packit fb9d21
\subsubsection{Exploiting Equalities}\label{s:equalities}
Packit fb9d21
Packit fb9d21
If there are any (explicit) equalities in the input description,
Packit fb9d21
{\tt PipLib} converts each into a pair of inequalities.
Packit fb9d21
It is also possible to write $r$ equalities as $r+1$ inequalities
Packit fb9d21
\shortcite{Feautrier02}, but it is even better to \emph{exploit} the
Packit fb9d21
equalities to reduce the dimensionality of the problem.
Packit fb9d21
Given an equality involving at least one unknown, we pivot
Packit fb9d21
the row corresponding to the equality with the column corresponding
Packit fb9d21
to the last unknown with non-zero coefficient.  The new column variable
Packit fb9d21
can then be removed completely because it is identically zero,
Packit fb9d21
thereby reducing the dimensionality of the problem by one.
Packit fb9d21
The last unknown is chosen to ensure that the columns of the initial
Packit fb9d21
tableau remain lexicographically positive.  In particular, if
Packit fb9d21
the equality is of the form $b + \sum_{i \le j} a_i \, x_i = 0$ with
Packit fb9d21
$a_j \ne 0$, then the (implicit) top rows of the initial tableau
Packit fb9d21
are changed as follows
Packit fb9d21
$$
Packit fb9d21
\begin{tikzpicture}
Packit fb9d21
\matrix [matrix of math nodes]
Packit fb9d21
{
Packit fb9d21
 & {} & |(top)| 0 & I_1 & |(j)| &  \\
Packit fb9d21
j && 0 & & 1 & \\
Packit fb9d21
  && 0 & & & |(bottom)|I_2 \\
Packit fb9d21
};
Packit fb9d21
\node[overlay,above=2mm of j,anchor=south]{j};
Packit fb9d21
\begin{pgfonlayer}{background}
Packit fb9d21
\node (m) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)] {};
Packit fb9d21
\end{pgfonlayer}
Packit fb9d21
\begin{scope}[xshift=4cm]
Packit fb9d21
\matrix [matrix of math nodes]
Packit fb9d21
{
Packit fb9d21
 & {} & |(top)| 0 & I_1 &  \\
Packit fb9d21
j && |(left)| -b/a_j & -a_i/a_j & \\
Packit fb9d21
  && 0 & & |(bottom)|I_2 \\
Packit fb9d21
};
Packit fb9d21
\begin{pgfonlayer}{background}
Packit fb9d21
\node (m2) [inner sep=0pt,fill=black!20,right delimiter=),left delimiter=(,fit=(top)(bottom)(left)] {};
Packit fb9d21
\end{pgfonlayer}
Packit fb9d21
\end{scope}
Packit fb9d21
 \draw [shorten >=7mm,-to,thick,decorate,
Packit fb9d21
        decoration={snake,amplitude=.4mm,segment length=2mm,
Packit fb9d21
                    pre=moveto,pre length=5mm,post length=8mm}]
Packit fb9d21
   (m) -- (m2);
Packit fb9d21
\end{tikzpicture}
Packit fb9d21
$$
Packit fb9d21
Currently, {\tt isl} also eliminates equalities involving only parameters
Packit fb9d21
in a similar way, provided at least one of the coefficients is equal to one.
Packit fb9d21
The application of parameter compression (see below)
Packit fb9d21
would obviate the need for removing parametric equalities.
Packit fb9d21
Packit fb9d21
\subsubsection{Offline Symmetry Detection}\label{s:offline}
Packit fb9d21
Packit fb9d21
Some problems, notably those of \shortciteN{Bygde2010licentiate},
Packit fb9d21
have a collection of constraints, say
Packit fb9d21
$b_i(\vec p) + \sp {\vec a} {\vec x} \ge 0$,
Packit fb9d21
that only differ in their (parametric) constant terms.
Packit fb9d21
These constant terms will be non-negative on different parts
Packit fb9d21
of the context and this context may have to be split for each
Packit fb9d21
of the constraints.  In the worst case, the basic algorithm may
Packit fb9d21
have to consider all possible orderings of the constant terms.
Packit fb9d21
Instead, {\tt isl} introduces a new parameter, say $u$, and
Packit fb9d21
replaces the collection of constraints by the single
Packit fb9d21
constraint $u + \sp {\vec a} {\vec x} \ge 0$ along with
Packit fb9d21
context constraints $u \le b_i(\vec p)$.
Packit fb9d21
Any solution to the new system is also a solution
Packit fb9d21
to the original system since
Packit fb9d21
$\sp {\vec a} {\vec x} \ge -u \ge -b_i(\vec p)$.
Packit fb9d21
Conversely, $m = \min_i b_i(\vec p)$ satisfies the constraints
Packit fb9d21
on $u$ and therefore extends a solution to the new system.
Packit fb9d21
It can also be plugged into a new solution.
Packit fb9d21
See \autoref{s:post} for how this substitution is currently performed
Packit fb9d21
in {\tt isl}.
Packit fb9d21
The method described in this section can only detect symmetries
Packit fb9d21
that are explicitly available in the input.
Packit fb9d21
See \autoref{s:online} for the detection
Packit fb9d21
and exploitation of symmetries that appear during the course of
Packit fb9d21
the dual simplex method.
Packit fb9d21
Packit fb9d21
\subsubsection{Parameter Compression}\label{s:compression}
Packit fb9d21
Packit fb9d21
It may in some cases be apparent from the equalities in the problem
Packit fb9d21
description that there can only be a solution for a sublattice
Packit fb9d21
of the parameters.  In such cases ``parameter compression''
Packit fb9d21
\shortcite{Meister2004PhD,Meister2008} can be used to replace
Packit fb9d21
the parameters by alternative ``dense'' parameters.
Packit fb9d21
For example, if there is a constraint $2x = n$, then the system
Packit fb9d21
will only have solutions for even values of $n$ and $n$ can be replaced
Packit fb9d21
by $2n'$.  Similarly, the parameters $n$ and $m$ in a system with
Packit fb9d21
the constraint $2n = 3m$ can be replaced by a single parameter $n'$
Packit fb9d21
with $n=3n'$ and $m=2n'$.
Packit fb9d21
It is also possible to perform a similar compression on the unknowns,
Packit fb9d21
but it would be more complicated as the compression would have to
Packit fb9d21
preserve the lexicographical order.  Moreover, due to our handling
Packit fb9d21
of equalities described above there should be
Packit fb9d21
no need for such variable compression.
Packit fb9d21
Although parameter compression has been implemented in {\tt isl},
Packit fb9d21
it is currently not yet used during parametric integer programming.
Packit fb9d21
Packit fb9d21
\subsection{Postprocessing}\label{s:post}
Packit fb9d21
Packit fb9d21
The output of {\tt PipLib} is a quast (quasi-affine selection tree).
Packit fb9d21
Each internal node in this tree corresponds to a split of the context
Packit fb9d21
based on a parametric constant term in the main tableau with indeterminate
Packit fb9d21
sign.  Each of these nodes may introduce extra variables in the context
Packit fb9d21
corresponding to integer divisions.  Each leaf of the tree prescribes
Packit fb9d21
the solution in that part of the context that satisfies all the conditions
Packit fb9d21
on the path leading to the leaf.
Packit fb9d21
Such a quast is a very economical way of representing the solution, but
Packit fb9d21
it would not be suitable as the (only) internal representation of
Packit fb9d21
sets and relations in {\tt isl}.  Instead, {\tt isl} represents
Packit fb9d21
the constraints of a set or relation in disjunctive normal form.
Packit fb9d21
The result of a parametric integer programming problem is then also
Packit fb9d21
converted to this internal representation.  Unfortunately, the conversion
Packit fb9d21
to disjunctive normal form can lead to an explosion of the size
Packit fb9d21
of the representation.
Packit fb9d21
In some cases, this overhead would have to be paid anyway in subsequent
Packit fb9d21
operations, but in other cases, especially for outside users that just
Packit fb9d21
want to solve parametric integer programming problems, we would like
Packit fb9d21
to avoid this overhead in future.  That is, we are planning on introducing
Packit fb9d21
quasts or a related representation as one of several possible internal
Packit fb9d21
representations and on allowing the output of {\tt isl\_pip} to optionally
Packit fb9d21
be printed as a quast.
Packit fb9d21
Packit fb9d21
Currently, {\tt isl} also does not have an internal representation
Packit fb9d21
for expressions such as $\min_i b_i(\vec p)$ from the offline
Packit fb9d21
symmetry detection of \autoref{s:offline}.
Packit fb9d21
Assume that one of these expressions has $n$ bounds $b_i(\vec p)$.
Packit fb9d21
If the expression
Packit fb9d21
does not appear in the affine expression describing the solution,
Packit fb9d21
but only in the constraints, and if moreover, the expression
Packit fb9d21
only appears with a positive coefficient, i.e.,
Packit fb9d21
$\min_i b_i(\vec p) \ge f_j(\vec p)$, then each of these constraints
Packit fb9d21
can simply be reduplicated $n$ times, once for each of the bounds.
Packit fb9d21
Otherwise, a conversion to disjunctive normal form
Packit fb9d21
leads to $n$ cases, each described as $u = b_i(\vec p)$ with constraints
Packit fb9d21
$b_i(\vec p) \le b_j(\vec p)$ for $j > i$
Packit fb9d21
and
Packit fb9d21
$b_i(\vec p)  < b_j(\vec p)$ for $j < i$.
Packit fb9d21
Note that even though this conversion leads to a size increase
Packit fb9d21
by a factor of $n$, not detecting the symmetry could lead to
Packit fb9d21
an increase by a factor of $n!$ if all possible orderings end up being
Packit fb9d21
considered.
Packit fb9d21
Packit fb9d21
\subsection{Context Tableau}\label{s:context}
Packit fb9d21
Packit fb9d21
The main operation that a context tableau needs to provide is a test
Packit fb9d21
on the sign of an affine expression over the elements of the context.
Packit fb9d21
This sign can be determined by solving two integer linear feasibility
Packit fb9d21
problems, one with a constraint added to the context that enforces
Packit fb9d21
the expression to be non-negative and one where the expression is
Packit fb9d21
negative.  As already mentioned by \shortciteN{Feautrier88parametric},
Packit fb9d21
any integer linear feasibility solver could be used, but the {\tt PipLib}
Packit fb9d21
implementation uses a recursive call to the dual simplex with Gomory
Packit fb9d21
cuts algorithm to determine the feasibility of a context.
Packit fb9d21
In {\tt isl}, two ways of handling the context have been implemented,
Packit fb9d21
one that performs the recursive call and one, used by default, that
Packit fb9d21
uses generalized basis reduction.
Packit fb9d21
We start with some optimizations that are shared between the two
Packit fb9d21
implementations and then discuss additional details of each of them.
Packit fb9d21
Packit fb9d21
\subsubsection{Maintaining Witnesses}\label{s:witness}
Packit fb9d21
Packit fb9d21
A common feature of both integer linear feasibility solvers is that
Packit fb9d21
they will not only say whether a set is empty or not, but if the set
Packit fb9d21
is non-empty, they will also provide a \emph{witness} for this result,
Packit fb9d21
i.e., a point that belongs to the set.  By maintaining a list of such
Packit fb9d21
witnesses, we can avoid many feasibility tests during the determination
Packit fb9d21
of the signs of affine expressions.  In particular, if the expression
Packit fb9d21
evaluates to a positive number on some of these points and to a negative
Packit fb9d21
number on some others, then no feasibility test needs to be performed.
Packit fb9d21
If all the evaluations are non-negative, we only need to check for the
Packit fb9d21
possibility of a negative value and similarly in case of all
Packit fb9d21
non-positive evaluations.  Finally, in the rare case that all points
Packit fb9d21
evaluate to zero or at the start, when no points have been collected yet,
Packit fb9d21
one or two feasibility tests need to be performed depending on the result
Packit fb9d21
of the first test.
Packit fb9d21
Packit fb9d21
When a new constraint is added to the context, the points that
Packit fb9d21
violate the constraint are temporarily removed.  They are reconsidered
Packit fb9d21
when we backtrack over the addition of the constraint, as they will
Packit fb9d21
satisfy the negation of the constraint.  It is only when we backtrack
Packit fb9d21
over the addition of the points that they are finally removed completely.
Packit fb9d21
When an extra integer division is added to the context,
Packit fb9d21
the new coordinates of the
Packit fb9d21
witnesses can easily be computed by evaluating the integer division.
Packit fb9d21
The idea of keeping track of witnesses was first used in {\tt barvinok}.
Packit fb9d21
Packit fb9d21
\subsubsection{Choice of Constant Term on which to Split}
Packit fb9d21
Packit fb9d21
Recall that if there are no rows with a non-positive constant term,
Packit fb9d21
but there are rows with an indeterminate sign, then the context
Packit fb9d21
needs to be split along the constant term of one of these rows.
Packit fb9d21
If there is more than one such row, then we need to choose which row
Packit fb9d21
to split on first.  {\tt PipLib} uses a heuristic based on the (absolute)
Packit fb9d21
sizes of the coefficients.  In particular, it takes the largest coefficient
Packit fb9d21
of each row and then selects the row where this largest coefficient is smaller
Packit fb9d21
than those of the other rows.
Packit fb9d21
Packit fb9d21
In {\tt isl}, we take that row for which non-negativity of its constant
Packit fb9d21
term implies non-negativity of as many of the constant terms of the other
Packit fb9d21
rows as possible.  The intuition behind this heuristic is that on the
Packit fb9d21
positive side, we will have fewer negative and indeterminate signs,
Packit fb9d21
while on the negative side, we need to perform a pivot, which may
Packit fb9d21
affect any number of rows meaning that the effect on the signs
Packit fb9d21
is difficult to predict.  This heuristic is of course much more
Packit fb9d21
expensive to evaluate than the heuristic used by {\tt PipLib}.
Packit fb9d21
More extensive tests are needed to evaluate whether the heuristic is worthwhile.
Packit fb9d21
Packit fb9d21
\subsubsection{Dual Simplex + Gomory Cuts}
Packit fb9d21
Packit fb9d21
When a new constraint is added to the context, the first steps
Packit fb9d21
of the dual simplex method applied to this new context will be the same
Packit fb9d21
or at least very similar to those taken on the original context, i.e.,
Packit fb9d21
before the constraint was added.  In {\tt isl}, we therefore apply
Packit fb9d21
the dual simplex method incrementally on the context and backtrack
Packit fb9d21
to a previous state when a constraint is removed again.
Packit fb9d21
An initial implementation that was never made public would also
Packit fb9d21
keep the Gomory cuts, but the current implementation backtracks
Packit fb9d21
to before the point where Gomory cuts are added before adding
Packit fb9d21
an extra constraint to the context.
Packit fb9d21
Keeping the Gomory cuts has the advantage that the sample value
Packit fb9d21
is always an integer point and that this point may also satisfy
Packit fb9d21
the new constraint.  However, due to the technique of maintaining
Packit fb9d21
witnesses explained above,
Packit fb9d21
we would not perform a feasibility test in such cases and then
Packit fb9d21
the previously added cuts may be redundant, possibly resulting
Packit fb9d21
in an accumulation of a large number of cuts.
Packit fb9d21
Packit fb9d21
If the parameters may be negative, then the same big parameter trick
Packit fb9d21
used in the main tableau is applied to the context.  This big parameter
Packit fb9d21
is of course unrelated to the big parameter from the main tableau.
Packit fb9d21
Note that it is not a requirement for this parameter to be ``big'',
Packit fb9d21
but it does allow for some code reuse in {\tt isl}.
Packit fb9d21
In {\tt PipLib}, the extra parameter is not ``big'', but this may be because
Packit fb9d21
the big parameter of the main tableau also appears
Packit fb9d21
in the context tableau.
Packit fb9d21
Packit fb9d21
Finally, it was reported by \shortciteN{Galea2009personal}, who
Packit fb9d21
worked on a parametric integer programming implementation
Packit fb9d21
in {\tt PPL} \shortcite{PPL},
Packit fb9d21
that it is beneficial to add cuts for \emph{all} rational coordinates
Packit fb9d21
in the context tableau.  Based on this report,
Packit fb9d21
the initial {\tt isl} implementation was adapted accordingly.
Packit fb9d21
Packit fb9d21
\subsubsection{Generalized Basis Reduction}\label{s:GBR}
Packit fb9d21
Packit fb9d21
The default algorithm used in {\tt isl} for feasibility checking
Packit fb9d21
is generalized basis reduction \shortcite{Cook1991implementation}.
Packit fb9d21
This algorithm is also used in the {\tt barvinok} implementation.
Packit fb9d21
The algorithm is fairly robust, but it has some overhead.
Packit fb9d21
We therefore try to avoid calling the algorithm in easy cases.
Packit fb9d21
In particular, we incrementally keep track of points for which
Packit fb9d21
the entire unit hypercube positioned at that point lies in the context.
Packit fb9d21
This set is described by translates of the constraints of the context
Packit fb9d21
and if (rationally) non-empty, any rational point
Packit fb9d21
in the set can be rounded up to yield an integer point in the context.
Packit fb9d21
Packit fb9d21
A restriction of the algorithm is that it only works on bounded sets.
Packit fb9d21
The affine hull of the recession cone therefore needs to be projected
Packit fb9d21
out first.  As soon as the algorithm is invoked, we then also
Packit fb9d21
incrementally keep track of this recession cone.  The reduced basis
Packit fb9d21
found by one call of the algorithm is also reused as initial basis
Packit fb9d21
for the next call.
Packit fb9d21
Packit fb9d21
Some problems lead to the
Packit fb9d21
introduction of many integer divisions.  Within a given context,
Packit fb9d21
some of these integer divisions may be equal to each other, even
Packit fb9d21
if the expressions are not identical, or they may be equal to some
Packit fb9d21
affine combination of other variables.
Packit fb9d21
To detect such cases, we compute the affine hull of the context
Packit fb9d21
each time a new integer division is added.  The algorithm used
Packit fb9d21
for computing this affine hull is that of \shortciteN{Karr1976affine},
Packit fb9d21
while the points used in this algorithm are obtained by performing
Packit fb9d21
integer feasibility checks on that part of the context outside
Packit fb9d21
the current approximation of the affine hull.
Packit fb9d21
The list of witnesses is used to construct an initial approximation
Packit fb9d21
of the hull, while any extra points found during the construction
Packit fb9d21
of the hull is added to this list.
Packit fb9d21
Any equality found in this way that expresses an integer division
Packit fb9d21
as an \emph{integer} affine combination of other variables is
Packit fb9d21
propagated to the main tableau, where it is used to eliminate that
Packit fb9d21
integer division.
Packit fb9d21
Packit fb9d21
\subsection{Experiments}
Packit fb9d21
Packit fb9d21
\autoref{t:comparison} compares the execution times of {\tt isl}
Packit fb9d21
(with both types of context tableau)
Packit fb9d21
on some more difficult instances to those of other tools,
Packit fb9d21
run on an Intel Xeon W3520 @ 2.66GHz.
Packit fb9d21
Easier problems such as the
Packit fb9d21
test cases distributed with {\tt Pip\-Lib} can be solved so quickly
Packit fb9d21
that we would only be measuring overhead such as input/output and conversions
Packit fb9d21
and not the running time of the actual algorithm.
Packit fb9d21
We compare the following versions:
Packit fb9d21
{\tt piplib-1.4.0-5-g0132fd9},
Packit fb9d21
{\tt barvinok-0.32.1-73-gc5d7751},
Packit fb9d21
{\tt isl-0.05.1-82-g3a37260}
Packit fb9d21
and {\tt PPL} version 0.11.2.
Packit fb9d21
Packit fb9d21
The first test case is the following dependence analysis problem
Packit fb9d21
originating from the Phideo project \shortcite{Verhaegh1995PhD}
Packit fb9d21
that was communicated to us by Bart Kienhuis:
Packit fb9d21
\begin{lstlisting}[flexiblecolumns=true,breaklines=true]{}
Packit fb9d21
lexmax { [j1,j2] -> [i1,i2,i3,i4,i5,i6,i7,i8,i9,i10] : 1 <= i1,j1 <= 8 and 1 <= i2,i3,i4,i5,i6,i7,i8,i9,i10 <= 2 and 1 <= j2 <= 128 and i1-1 = j1-1 and i2-1+2*i3-2+4*i4-4+8*i5-8+16*i6-16+32*i7-32+64*i8-64+128*i9-128+256*i10-256=3*j2-3+66 };
Packit fb9d21
\end{lstlisting}
Packit fb9d21
This problem was the main inspiration
Packit fb9d21
for some of the optimizations in \autoref{s:GBR}.
Packit fb9d21
The second group of test cases are projections used during counting.
Packit fb9d21
The first nine of these come from \shortciteN{Seghir2006minimizing}.
Packit fb9d21
The remaining two come from \shortciteN{Verdoolaege2005experiences} and
Packit fb9d21
were used to drive the first, Gomory cuts based, implementation
Packit fb9d21
in {\tt isl}.
Packit fb9d21
The third and final group of test cases are borrowed from
Packit fb9d21
\shortciteN{Bygde2010licentiate} and inspired the offline symmetry detection
Packit fb9d21
of \autoref{s:offline}.  Without symmetry detection, the running times
Packit fb9d21
are 11s and 5.9s.
Packit fb9d21
All running times of {\tt barvinok} and {\tt isl} include a conversion
Packit fb9d21
to disjunctive normal form.  Without this conversion, the final two
Packit fb9d21
cases can be solved in 0.07s and 0.21s.
Packit fb9d21
The {\tt PipLib} implementation has some fixed limits and will
Packit fb9d21
sometimes report the problem to be too complex (TC), while on some other
Packit fb9d21
problems it will run out of memory (OOM).
Packit fb9d21
The {\tt barvinok} implementation does not support problems
Packit fb9d21
with a non-trivial lineality space (line) nor maximization problems (max).
Packit fb9d21
The Gomory cuts based {\tt isl} implementation was terminated after 1000
Packit fb9d21
minutes on the first problem.  The gbr version introduces some
Packit fb9d21
overhead on some of the easier problems, but is overall the clear winner.
Packit fb9d21
Packit fb9d21
\begin{table}
Packit fb9d21
\begin{center}
Packit fb9d21
\begin{tabular}{lrrrrr}
Packit fb9d21
    & {\tt PipLib} & {\tt barvinok} & {\tt isl} cut & {\tt isl} gbr & {\tt PPL} \\
Packit fb9d21
\hline
Packit fb9d21
\hline
Packit fb9d21
% bart.pip
Packit fb9d21
Phideo & TC    & 793m   & $>$999m &   2.7s  & 372m \\
Packit fb9d21
\hline
Packit fb9d21
e1 & 0.33s & 3.5s & 0.08s & 0.11s & 0.18s \\
Packit fb9d21
e3 & 0.14s & 0.13s & 0.10s & 0.10s & 0.17s \\
Packit fb9d21
e4 & 0.24s & 9.1s & 0.09s & 0.11s & 0.70s \\
Packit fb9d21
e5 & 0.12s & 6.0s & 0.06s & 0.14s & 0.17s \\
Packit fb9d21
e6 & 0.10s & 6.8s & 0.17s & 0.08s & 0.21s \\
Packit fb9d21
e7 & 0.03s & 0.27s & 0.04s & 0.04s & 0.03s \\
Packit fb9d21
e8 & 0.03s & 0.18s & 0.03s & 0.04s & 0.01s \\
Packit fb9d21
e9 & OOM & 70m & 2.6s & 0.94s & 22s \\
Packit fb9d21
vd & 0.04s & 0.10s & 0.03s & 0.03s & 0.03s \\
Packit fb9d21
bouleti & 0.25s & line & 0.06s & 0.06s & 0.15s \\
Packit fb9d21
difficult & OOM & 1.3s & 1.7s & 0.33s & 1.4s \\
Packit fb9d21
\hline
Packit fb9d21
cnt/sum & TC & max & 2.2s & 2.2s & OOM \\
Packit fb9d21
jcomplex & TC & max & 3.7s & 3.9s & OOM \\
Packit fb9d21
\end{tabular}
Packit fb9d21
\caption{Comparison of Execution Times}
Packit fb9d21
\label{t:comparison}
Packit fb9d21
\end{center}
Packit fb9d21
\end{table}
Packit fb9d21
Packit fb9d21
\subsection{Online Symmetry Detection}\label{s:online}
Packit fb9d21
Packit fb9d21
Manual experiments on small instances of the problems of
Packit fb9d21
\shortciteN{Bygde2010licentiate} and an analysis of the results
Packit fb9d21
by the approximate MPA method developed by \shortciteN{Bygde2010licentiate}
Packit fb9d21
have revealed that these problems contain many more symmetries
Packit fb9d21
than can be detected using the offline method of \autoref{s:offline}.
Packit fb9d21
In this section, we present an online detection mechanism that has
Packit fb9d21
not been implemented yet, but that has shown promising results
Packit fb9d21
in manual applications.
Packit fb9d21
Packit fb9d21
Let us first consider what happens when we do not perform offline
Packit fb9d21
symmetry detection.  At some point, one of the
Packit fb9d21
$b_i(\vec p) + \sp {\vec a} {\vec x} \ge 0$ constraints,
Packit fb9d21
say the $j$th constraint, appears as a column
Packit fb9d21
variable, say $c_1$, while the other constraints are represented
Packit fb9d21
as rows of the form $b_i(\vec p) - b_j(\vec p) + c$.
Packit fb9d21
The context is then split according to the relative order of
Packit fb9d21
$b_j(\vec p)$ and one of the remaining $b_i(\vec p)$.
Packit fb9d21
The offline method avoids this split by replacing all $b_i(\vec p)$
Packit fb9d21
by a single newly introduced parameter that represents the minimum
Packit fb9d21
of these $b_i(\vec p)$.
Packit fb9d21
In the online method the split is similarly avoided by the introduction
Packit fb9d21
of a new parameter.  In particular, a new parameter is introduced
Packit fb9d21
that represents
Packit fb9d21
$\left| b_j(\vec p) - b_i(\vec p) \right|_+ =
Packit fb9d21
\max(b_j(\vec p) - b_i(\vec p), 0)$.
Packit fb9d21
Packit fb9d21
In general, let $r = b(\vec p) + \sp {\vec a} {\vec c}$ be a row
Packit fb9d21
of the tableau such that the sign of $b(\vec p)$ is indeterminate
Packit fb9d21
and such that exactly one of the elements of $\vec a$ is a $1$,
Packit fb9d21
while all remaining elements are non-positive.
Packit fb9d21
That is, $r = b(\vec p) + c_j - f$ with $f = -\sum_{i\ne j} a_i c_i \ge 0$.
Packit fb9d21
We introduce a new parameter $t$ with
Packit fb9d21
context constraints $t \ge -b(\vec p)$ and $t \ge 0$ and replace
Packit fb9d21
the column variable $c_j$ by $c' + t$.  The row $r$ is now equal
Packit fb9d21
to $b(\vec p) + t + c' - f$.  The constant term of this row is always
Packit fb9d21
non-negative because any negative value of $b(\vec p)$ is compensated
Packit fb9d21
by $t \ge -b(\vec p)$ while and non-negative value remains non-negative
Packit fb9d21
because $t \ge 0$.
Packit fb9d21
Packit fb9d21
We need to show that this transformation does not eliminate any valid
Packit fb9d21
solutions and that it does not introduce any spurious solutions.
Packit fb9d21
Given a valid solution for the original problem, we need to find
Packit fb9d21
a non-negative value of $c'$ satisfying the constraints.
Packit fb9d21
If $b(\vec p) \ge 0$, we can take $t = 0$ so that
Packit fb9d21
$c' = c_j - t = c_j \ge 0$.
Packit fb9d21
If $b(\vec p) < 0$, we can take $t = -b(\vec p)$.
Packit fb9d21
Since $r = b(\vec p) + c_j - f \ge 0$ and $f \ge 0$, we have 
Packit fb9d21
$c' = c_j + b(\vec p) \ge 0$.
Packit fb9d21
Note that these choices amount to plugging in
Packit fb9d21
$t = \left|-b(\vec p)\right|_+ = \max(-b(\vec p), 0)$.
Packit fb9d21
Conversely, given a solution to the new problem, we need to find
Packit fb9d21
a non-negative value of $c_j$, but this is easy since $c_j = c' + t$
Packit fb9d21
and both of these are non-negative.
Packit fb9d21
Packit fb9d21
Plugging in $t = \max(-b(\vec p), 0)$ can be performed as in
Packit fb9d21
\autoref{s:post}, but, as in the case of offline symmetry detection,
Packit fb9d21
it may be better to provide a direct representation for such
Packit fb9d21
expressions in the internal representation of sets and relations
Packit fb9d21
or at least in a quast-like output format.
Packit fb9d21
Packit fb9d21
\section{Coalescing}\label{s:coalescing}
Packit fb9d21
Packit fb9d21
See \shortciteN{Verdoolaege2009isl}, for now.
Packit fb9d21
More details will be added later.
Packit fb9d21
Packit fb9d21
\section{Transitive Closure}
Packit fb9d21
Packit fb9d21
\subsection{Introduction}
Packit fb9d21
Packit fb9d21
\begin{definition}[Power of a Relation]
Packit fb9d21
Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation and
Packit fb9d21
$k \in \Z_{\ge 1}$
Packit fb9d21
a positive number, then power $k$ of relation $R$ is defined as
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:power}
Packit fb9d21
R^k \coloneqq
Packit fb9d21
\begin{cases}
Packit fb9d21
R & \text{if $k = 1$}
Packit fb9d21
\\
Packit fb9d21
R \circ R^{k-1} & \text{if $k \ge 2$}
Packit fb9d21
.
Packit fb9d21
\end{cases}
Packit fb9d21
\end{equation}
Packit fb9d21
\end{definition}
Packit fb9d21
Packit fb9d21
\begin{definition}[Transitive Closure of a Relation]
Packit fb9d21
Let $R \in \Z^n \to 2^{\Z^{d+d}}$ be a relation,
Packit fb9d21
then the transitive closure $R^+$ of $R$ is the union
Packit fb9d21
of all positive powers of $R$,
Packit fb9d21
$$
Packit fb9d21
R^+ \coloneqq \bigcup_{k \ge 1} R^k
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
\end{definition}
Packit fb9d21
Alternatively, the transitive closure may be defined
Packit fb9d21
inductively as
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:inductive}
Packit fb9d21
R^+ \coloneqq R \cup \left(R \circ R^+\right)
Packit fb9d21
.
Packit fb9d21
\end{equation}
Packit fb9d21
Packit fb9d21
Since the transitive closure of a polyhedral relation
Packit fb9d21
may no longer be a polyhedral relation \shortcite{Kelly1996closure},
Packit fb9d21
we can, in the general case, only compute an approximation
Packit fb9d21
of the transitive closure.
Packit fb9d21
Whereas \shortciteN{Kelly1996closure} compute underapproximations,
Packit fb9d21
we, like \shortciteN{Beletska2009}, compute overapproximations.
Packit fb9d21
That is, given a relation $R$, we will compute a relation $T$
Packit fb9d21
such that $R^+ \subseteq T$.  Of course, we want this approximation
Packit fb9d21
to be as close as possible to the actual transitive closure
Packit fb9d21
$R^+$ and we want to detect the cases where the approximation is
Packit fb9d21
exact, i.e., where $T = R^+$.
Packit fb9d21
Packit fb9d21
For computing an approximation of the transitive closure of $R$,
Packit fb9d21
we follow the same general strategy as \shortciteN{Beletska2009}
Packit fb9d21
and first compute an approximation of $R^k$ for $k \ge 1$ and then project
Packit fb9d21
out the parameter $k$ from the resulting relation.
Packit fb9d21
Packit fb9d21
\begin{example}
Packit fb9d21
As a trivial example, consider the relation
Packit fb9d21
$R = \{\, x \to x + 1 \,\}$.  The $k$th power of this map
Packit fb9d21
for arbitrary $k$ is
Packit fb9d21
$$
Packit fb9d21
R^k = k \mapsto \{\, x \to x + k \mid k \ge 1 \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
The transitive closure is then
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
R^+ & = \{\, x \to y \mid \exists k \in \Z_{\ge 1} : y = x + k \,\}
Packit fb9d21
\\
Packit fb9d21
& = \{\, x \to y \mid y \ge x + 1 \,\}
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
\end{example}
Packit fb9d21
Packit fb9d21
\subsection{Computing an Approximation of $R^k$}
Packit fb9d21
\label{s:power}
Packit fb9d21
Packit fb9d21
There are some special cases where the computation of $R^k$ is very easy.
Packit fb9d21
One such case is that where $R$ does not compose with itself,
Packit fb9d21
i.e., $R \circ R = \emptyset$ or $\domain R \cap \range R = \emptyset$.
Packit fb9d21
In this case, $R^k$ is only non-empty for $k=1$ where it is equal
Packit fb9d21
to $R$ itself.
Packit fb9d21
Packit fb9d21
In general, it is impossible to construct a closed form
Packit fb9d21
of $R^k$ as a polyhedral relation.
Packit fb9d21
We will therefore need to make some approximations.
Packit fb9d21
As a first approximations, we will consider each of the basic
Packit fb9d21
relations in $R$ as simply adding one or more offsets to a domain element
Packit fb9d21
to arrive at an image element and ignore the fact that some of these
Packit fb9d21
offsets may only be applied to some of the domain elements.
Packit fb9d21
That is, we will only consider the difference set $\Delta\,R$ of the relation.
Packit fb9d21
In particular, we will first construct a collection $P$ of paths
Packit fb9d21
that move through
Packit fb9d21
a total of $k$ offsets and then intersect domain and range of this
Packit fb9d21
collection with those of $R$.
Packit fb9d21
That is, 
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:approx}
Packit fb9d21
K = P \cap \left(\domain R \to \range R\right)
Packit fb9d21
,
Packit fb9d21
\end{equation}
Packit fb9d21
with
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:path}
Packit fb9d21
P = \vec s \mapsto \{\, \vec x \to \vec y \mid
Packit fb9d21
\exists k_i \in \Z_{\ge 0}, \vec\delta_i \in k_i \, \Delta_i(\vec s) :
Packit fb9d21
\vec y = \vec x + \sum_i \vec\delta_i
Packit fb9d21
\wedge
Packit fb9d21
\sum_i k_i = k > 0
Packit fb9d21
\,\}
Packit fb9d21
\end{equation}
Packit fb9d21
and with $\Delta_i$ the basic sets that compose
Packit fb9d21
the difference set $\Delta\,R$.
Packit fb9d21
Note that the number of basic sets $\Delta_i$ need not be
Packit fb9d21
the same as the number of basic relations in $R$.
Packit fb9d21
Also note that since addition is commutative, it does not
Packit fb9d21
matter in which order we add the offsets and so we are allowed
Packit fb9d21
to group them as we did in \eqref{eq:transitive:path}.
Packit fb9d21
Packit fb9d21
If all the $\Delta_i$s are singleton sets
Packit fb9d21
$\Delta_i = \{\, \vec \delta_i \,\}$ with $\vec \delta_i \in \Z^d$,
Packit fb9d21
then \eqref{eq:transitive:path} simplifies to
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:singleton}
Packit fb9d21
P = \{\, \vec x \to \vec y \mid
Packit fb9d21
\exists k_i \in \Z_{\ge 0} :
Packit fb9d21
\vec y = \vec x + \sum_i k_i \, \vec \delta_i
Packit fb9d21
\wedge
Packit fb9d21
\sum_i k_i = k > 0
Packit fb9d21
\,\}
Packit fb9d21
\end{equation}
Packit fb9d21
and then the approximation computed in \eqref{eq:transitive:approx}
Packit fb9d21
is essentially the same as that of \shortciteN{Beletska2009}.
Packit fb9d21
If some of the $\Delta_i$s are not singleton sets or if
Packit fb9d21
some of $\vec \delta_i$s are parametric, then we need
Packit fb9d21
to resort to further approximations.
Packit fb9d21
Packit fb9d21
To ease both the exposition and the implementation, we will for
Packit fb9d21
the remainder of this section work with extended offsets
Packit fb9d21
$\Delta_i' = \Delta_i \times \{\, 1 \,\}$.
Packit fb9d21
That is, each offset is extended with an extra coordinate that is
Packit fb9d21
set equal to one.  The paths constructed by summing such extended
Packit fb9d21
offsets have the length encoded as the difference of their
Packit fb9d21
final coordinates.  The path $P'$ can then be decomposed into
Packit fb9d21
paths $P_i'$, one for each $\Delta_i$,
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:decompose}
Packit fb9d21
P' = \left(
Packit fb9d21
(P_m' \cup \identity) \circ \cdots \circ
Packit fb9d21
(P_2' \cup \identity) \circ
Packit fb9d21
(P_1' \cup \identity)
Packit fb9d21
\right) \cap
Packit fb9d21
\{\,
Packit fb9d21
\vec x' \to \vec y' \mid y_{d+1} - x_{d+1} = k > 0
Packit fb9d21
\,\}
Packit fb9d21
,
Packit fb9d21
\end{equation}
Packit fb9d21
with
Packit fb9d21
$$
Packit fb9d21
P_i' = \vec s \mapsto \{\, \vec x' \to \vec y' \mid
Packit fb9d21
\exists k \in \Z_{\ge 1}, \vec \delta \in k \, \Delta_i'(\vec s) :
Packit fb9d21
\vec y' = \vec x' + \vec \delta
Packit fb9d21
\,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
Note that each $P_i'$ contains paths of length at least one.
Packit fb9d21
We therefore need to take the union with the identity relation
Packit fb9d21
when composing the $P_i'$s to allow for paths that do not contain
Packit fb9d21
any offsets from one or more $\Delta_i'$.
Packit fb9d21
The path that consists of only identity relations is removed
Packit fb9d21
by imposing the constraint $y_{d+1} - x_{d+1} > 0$.
Packit fb9d21
Taking the union with the identity relation means that
Packit fb9d21
that the relations we compose in \eqref{eq:transitive:decompose}
Packit fb9d21
each consist of two basic relations.  If there are $m$
Packit fb9d21
disjuncts in the input relation, then a direct application
Packit fb9d21
of the composition operation may therefore result in a relation
Packit fb9d21
with $2^m$ disjuncts, which is prohibitively expensive.
Packit fb9d21
It is therefore crucial to apply coalescing (\autoref{s:coalescing})
Packit fb9d21
after each composition.
Packit fb9d21
Packit fb9d21
Let us now consider how to compute an overapproximation of $P_i'$.
Packit fb9d21
Those that correspond to singleton $\Delta_i$s are grouped together
Packit fb9d21
and handled as in \eqref{eq:transitive:singleton}.
Packit fb9d21
Note that this is just an optimization.  The procedure described
Packit fb9d21
below would produce results that are at least as accurate.
Packit fb9d21
For simplicity, we first assume that no constraint in $\Delta_i'$
Packit fb9d21
involves any existentially quantified variables.
Packit fb9d21
We will return to existentially quantified variables at the end
Packit fb9d21
of this section.
Packit fb9d21
Without existentially quantified variables, we can classify
Packit fb9d21
the constraints of $\Delta_i'$ as follows
Packit fb9d21
\begin{enumerate}
Packit fb9d21
\item non-parametric constraints
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:non-parametric}
Packit fb9d21
A_1 \vec x + \vec c_1 \geq \vec 0
Packit fb9d21
\end{equation}
Packit fb9d21
\item purely parametric constraints
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:parametric}
Packit fb9d21
B_2 \vec s + \vec c_2 \geq \vec 0
Packit fb9d21
\end{equation}
Packit fb9d21
\item negative mixed constraints
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:mixed}
Packit fb9d21
A_3 \vec x + B_3 \vec s + \vec c_3 \geq \vec 0
Packit fb9d21
\end{equation}
Packit fb9d21
such that for each row $j$ and for all $\vec s$,
Packit fb9d21
$$
Packit fb9d21
\Delta_i'(\vec s) \cap
Packit fb9d21
\{\, \vec \delta' \mid B_{3,j} \vec s + c_{3,j} > 0 \,\}
Packit fb9d21
= \emptyset
Packit fb9d21
$$
Packit fb9d21
\item positive mixed constraints
Packit fb9d21
$$
Packit fb9d21
A_4 \vec x + B_4 \vec s + \vec c_4 \geq \vec 0
Packit fb9d21
$$
Packit fb9d21
such that for each row $j$, there is at least one $\vec s$ such that
Packit fb9d21
$$
Packit fb9d21
\Delta_i'(\vec s) \cap
Packit fb9d21
\{\, \vec \delta' \mid B_{4,j} \vec s + c_{4,j} > 0 \,\}
Packit fb9d21
\ne \emptyset
Packit fb9d21
$$
Packit fb9d21
\end{enumerate}
Packit fb9d21
We will use the following approximation $Q_i$ for $P_i'$:
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:Q}
Packit fb9d21
\begin{aligned}
Packit fb9d21
Q_i = \vec s \mapsto
Packit fb9d21
\{\,
Packit fb9d21
\vec x' \to \vec y'
Packit fb9d21
\mid {} & \exists k \in \Z_{\ge 1}, \vec f \in \Z^d :
Packit fb9d21
\vec y' = \vec x' + (\vec f, k)
Packit fb9d21
\wedge {}
Packit fb9d21
\\
Packit fb9d21
&
Packit fb9d21
A_1 \vec f + k \vec c_1 \geq \vec 0
Packit fb9d21
\wedge
Packit fb9d21
B_2 \vec s + \vec c_2 \geq \vec 0
Packit fb9d21
\wedge
Packit fb9d21
A_3 \vec f + B_3 \vec s + \vec c_3 \geq \vec 0
Packit fb9d21
\,\}
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
\end{equation}
Packit fb9d21
To prove that $Q_i$ is indeed an overapproximation of $P_i'$,
Packit fb9d21
we need to show that for every $\vec s \in \Z^n$, for every
Packit fb9d21
$k \in \Z_{\ge 1}$ and for every $\vec f \in k \, \Delta_i(\vec s)$
Packit fb9d21
we have that
Packit fb9d21
$(\vec f, k)$ satisfies the constraints in \eqref{eq:transitive:Q}.
Packit fb9d21
If $\Delta_i(\vec s)$ is non-empty, then $\vec s$ must satisfy
Packit fb9d21
the constraints in \eqref{eq:transitive:parametric}.
Packit fb9d21
Each element $(\vec f, k) \in k \, \Delta_i'(\vec s)$ is a sum
Packit fb9d21
of $k$ elements $(\vec f_j, 1)$ in $\Delta_i'(\vec s)$.
Packit fb9d21
Each of these elements satisfies the constraints in
Packit fb9d21
\eqref{eq:transitive:non-parametric}, i.e.,
Packit fb9d21
$$
Packit fb9d21
\left[
Packit fb9d21
\begin{matrix}
Packit fb9d21
A_1 & \vec c_1
Packit fb9d21
\end{matrix}
Packit fb9d21
\right]
Packit fb9d21
\left[
Packit fb9d21
\begin{matrix}
Packit fb9d21
\vec f_j \\ 1
Packit fb9d21
\end{matrix}
Packit fb9d21
\right]
Packit fb9d21
\ge \vec 0
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
The sum of these elements therefore satisfies the same set of inequalities,
Packit fb9d21
i.e., $A_1 \vec f + k \vec c_1 \geq \vec 0$.
Packit fb9d21
Finally, the constraints in \eqref{eq:transitive:mixed} are such
Packit fb9d21
that for any $\vec s$ in the parameter domain of $\Delta$,
Packit fb9d21
we have $-\vec r(\vec s) \coloneqq B_3 \vec s + \vec c_3 \le \vec 0$,
Packit fb9d21
i.e., $A_3 \vec f_j \ge \vec r(\vec s) \ge \vec 0$
Packit fb9d21
and therefore also $A_3 \vec f \ge \vec r(\vec s)$.
Packit fb9d21
Note that if there are no mixed constraints and if the
Packit fb9d21
rational relaxation of $\Delta_i(\vec s)$, i.e.,
Packit fb9d21
$\{\, \vec x \in \Q^d \mid A_1 \vec x + \vec c_1 \ge \vec 0\,\}$,
Packit fb9d21
has integer vertices, then the approximation is exact, i.e.,
Packit fb9d21
$Q_i = P_i'$.  In this case, the vertices of $\Delta'_i(\vec s)$
Packit fb9d21
generate the rational cone
Packit fb9d21
$\{\, \vec x' \in \Q^{d+1} \mid \left[
Packit fb9d21
\begin{matrix}
Packit fb9d21
A_1 & \vec c_1
Packit fb9d21
\end{matrix}
Packit fb9d21
\right] \vec x' \,\}$ and therefore $\Delta'_i(\vec s)$ is
Packit fb9d21
a Hilbert basis of this cone \shortcite[Theorem~16.4]{Schrijver1986}.
Packit fb9d21
Packit fb9d21
Note however that, as pointed out by \shortciteN{DeSmet2010personal},
Packit fb9d21
if there \emph{are} any mixed constraints, then the above procedure may
Packit fb9d21
not compute the most accurate affine approximation of
Packit fb9d21
$k \, \Delta_i(\vec s)$ with $k \ge 1$.
Packit fb9d21
In particular, we only consider the negative mixed constraints that
Packit fb9d21
happen to appear in the description of $\Delta_i(\vec s)$, while we
Packit fb9d21
should instead consider \emph{all} valid such constraints.
Packit fb9d21
It is also sufficient to consider those constraints because any
Packit fb9d21
constraint that is valid for $k \, \Delta_i(\vec s)$ is also
Packit fb9d21
valid for $1 \, \Delta_i(\vec s) = \Delta_i(\vec s)$.
Packit fb9d21
Take therefore any constraint
Packit fb9d21
$\spv a x + \spv b s + c \ge 0$ valid for $\Delta_i(\vec s)$.
Packit fb9d21
This constraint is also valid for $k \, \Delta_i(\vec s)$ iff
Packit fb9d21
$k \, \spv a x + \spv b s + c \ge 0$.
Packit fb9d21
If $\spv b s + c$ can attain any positive value, then $\spv a x$
Packit fb9d21
may be negative for some elements of $\Delta_i(\vec s)$.
Packit fb9d21
We then have $k \, \spv a x < \spv a x$ for $k > 1$ and so the constraint
Packit fb9d21
is not valid for $k \, \Delta_i(\vec s)$.
Packit fb9d21
We therefore need to impose $\spv b s + c \le 0$ for all values
Packit fb9d21
of $\vec s$ such that $\Delta_i(\vec s)$ is non-empty, i.e.,
Packit fb9d21
$\vec b$ and $c$ need to be such that $- \spv b s - c \ge 0$ is a valid
Packit fb9d21
constraint of $\Delta_i(\vec s)$.  That is, $(\vec b, c)$ are the opposites
Packit fb9d21
of the coefficients of a valid constraint of $\Delta_i(\vec s)$.
Packit fb9d21
The approximation of $k \, \Delta_i(\vec s)$ can therefore be obtained
Packit fb9d21
using three applications of Farkas' lemma.  The first obtains the coefficients
Packit fb9d21
of constraints valid for $\Delta_i(\vec s)$.  The second obtains
Packit fb9d21
the coefficients of constraints valid for the projection of $\Delta_i(\vec s)$
Packit fb9d21
onto the parameters.  The opposite of the second set is then computed
Packit fb9d21
and intersected with the first set.  The result is the set of coefficients
Packit fb9d21
of constraints valid for $k \, \Delta_i(\vec s)$.  A final application
Packit fb9d21
of Farkas' lemma is needed to obtain the approximation of
Packit fb9d21
$k \, \Delta_i(\vec s)$ itself.
Packit fb9d21
Packit fb9d21
\begin{example}
Packit fb9d21
Consider the relation
Packit fb9d21
$$
Packit fb9d21
n \to \{\, (x, y) \to (1 + x, 1 - n + y) \mid n \ge 2 \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
The difference set of this relation is
Packit fb9d21
$$
Packit fb9d21
\Delta = n \to \{\, (1, 1 - n) \mid n \ge 2 \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
Using our approach, we would only consider the mixed constraint
Packit fb9d21
$y - 1 + n \ge 0$, leading to the following approximation of the
Packit fb9d21
transitive closure:
Packit fb9d21
$$
Packit fb9d21
n \to \{\, (x, y) \to (o_0, o_1) \mid n \ge 2 \wedge o_1 \le 1 - n + y \wedge o_0 \ge 1 + x \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
If, instead, we apply Farkas's lemma to $\Delta$, i.e.,
Packit fb9d21
\begin{verbatim}
Packit fb9d21
D := [n] -> { [1, 1 - n] : n >= 2 };
Packit fb9d21
CD := coefficients D;
Packit fb9d21
CD;
Packit fb9d21
\end{verbatim}
Packit fb9d21
we obtain
Packit fb9d21
\begin{verbatim}
Packit fb9d21
{ rat: coefficients[[c_cst, c_n] -> [i2, i3]] : i3 <= c_n and
Packit fb9d21
  i3 <= c_cst + 2c_n + i2 }
Packit fb9d21
\end{verbatim}
Packit fb9d21
The pure-parametric constraints valid for $\Delta$,
Packit fb9d21
\begin{verbatim}
Packit fb9d21
P := { [a,b] -> [] }(D);
Packit fb9d21
CP := coefficients P;
Packit fb9d21
CP;
Packit fb9d21
\end{verbatim}
Packit fb9d21
are
Packit fb9d21
\begin{verbatim}
Packit fb9d21
{ rat: coefficients[[c_cst, c_n] -> []] : c_n >= 0 and 2c_n >= -c_cst }
Packit fb9d21
\end{verbatim}
Packit fb9d21
Negating these coefficients and intersecting with \verb+CD+,
Packit fb9d21
\begin{verbatim}
Packit fb9d21
NCP := { rat: coefficients[[a,b] -> []]
Packit fb9d21
              -> coefficients[[-a,-b] -> []] }(CP);
Packit fb9d21
CK := wrap((unwrap CD) * (dom (unwrap NCP)));
Packit fb9d21
CK;
Packit fb9d21
\end{verbatim}
Packit fb9d21
we obtain
Packit fb9d21
\begin{verbatim}
Packit fb9d21
{ rat: [[c_cst, c_n] -> [i2, i3]] : i3 <= c_n and
Packit fb9d21
  i3 <= c_cst + 2c_n + i2 and c_n <= 0 and 2c_n <= -c_cst }
Packit fb9d21
\end{verbatim}
Packit fb9d21
The approximation for $k\,\Delta$,
Packit fb9d21
\begin{verbatim}
Packit fb9d21
K := solutions CK;
Packit fb9d21
K;
Packit fb9d21
\end{verbatim}
Packit fb9d21
is then
Packit fb9d21
\begin{verbatim}
Packit fb9d21
[n] -> { rat: [i0, i1] : i1 <= -i0 and i0 >= 1 and i1 <= 2 - n - i0 }
Packit fb9d21
\end{verbatim}
Packit fb9d21
Finally, the computed approximation for $R^+$,
Packit fb9d21
\begin{verbatim}
Packit fb9d21
T := unwrap({ [dx,dy] -> [[x,y] -> [x+dx,y+dy]] }(K));
Packit fb9d21
R := [n] -> { [x,y] -> [x+1,y+1-n] : n >= 2 };
Packit fb9d21
T := T * ((dom R) -> (ran R));
Packit fb9d21
T;
Packit fb9d21
\end{verbatim}
Packit fb9d21
is
Packit fb9d21
\begin{verbatim}
Packit fb9d21
[n] -> { [x, y] -> [o0, o1] : o1 <= x + y - o0 and
Packit fb9d21
         o0 >= 1 + x and o1 <= 2 - n + x + y - o0 and n >= 2 }
Packit fb9d21
\end{verbatim}
Packit fb9d21
\end{example}
Packit fb9d21
Packit fb9d21
Existentially quantified variables can be handled by
Packit fb9d21
classifying them into variables that are uniquely
Packit fb9d21
determined by the parameters, variables that are independent
Packit fb9d21
of the parameters and others.  The first set can be treated
Packit fb9d21
as parameters and the second as variables.  Constraints involving
Packit fb9d21
the other existentially quantified variables are removed.
Packit fb9d21
Packit fb9d21
\begin{example}
Packit fb9d21
Consider the relation
Packit fb9d21
$$
Packit fb9d21
R =
Packit fb9d21
n \to \{\, x \to y \mid \exists \, \alpha_0, \alpha_1: 7\alpha_0 = -2 + n \wedge 5\alpha_1 = -1 - x + y \wedge y \ge 6 + x \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
The difference set of this relation is
Packit fb9d21
$$
Packit fb9d21
\Delta = \Delta \, R =
Packit fb9d21
n \to \{\, x \mid \exists \, \alpha_0, \alpha_1: 7\alpha_0 = -2 + n \wedge 5\alpha_1 = -1 + x \wedge x \ge 6 \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
The existentially quantified variables can be defined in terms
Packit fb9d21
of the parameters and variables as
Packit fb9d21
$$
Packit fb9d21
\alpha_0 = \floor{\frac{-2 + n}7}
Packit fb9d21
\qquad
Packit fb9d21
\text{and}
Packit fb9d21
\qquad
Packit fb9d21
\alpha_1 = \floor{\frac{-1 + x}5}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
$\alpha_0$ can therefore be treated as a parameter,
Packit fb9d21
while $\alpha_1$ can be treated as a variable.
Packit fb9d21
This in turn means that $7\alpha_0 = -2 + n$ can be treated as
Packit fb9d21
a purely parametric constraint, while the other two constraints are
Packit fb9d21
non-parametric.
Packit fb9d21
The corresponding $Q$~\eqref{eq:transitive:Q} is therefore
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
n \to \{\, (x,z) \to (y,w) \mid
Packit fb9d21
\exists\, \alpha_0, \alpha_1, k, f : {} &
Packit fb9d21
k \ge 1 \wedge
Packit fb9d21
y = x + f \wedge
Packit fb9d21
w = z + k \wedge {} \\
Packit fb9d21
&
Packit fb9d21
7\alpha_0 = -2 + n \wedge
Packit fb9d21
5\alpha_1 = -k + x \wedge
Packit fb9d21
x \ge 6 k
Packit fb9d21
\,\}
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
Projecting out the final coordinates encoding the length of the paths,
Packit fb9d21
results in the exact transitive closure
Packit fb9d21
$$
Packit fb9d21
R^+ =
Packit fb9d21
n \to \{\, x \to y \mid \exists \, \alpha_0, \alpha_1: 7\alpha_1 = -2 + n \wedge 6\alpha_0 \ge -x + y \wedge 5\alpha_0 \le -1 - x + y \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
\end{example}
Packit fb9d21
Packit fb9d21
The fact that we ignore some impure constraints clearly leads
Packit fb9d21
to a loss of accuracy.  In some cases, some of this loss can be recovered
Packit fb9d21
by not considering the parameters in a special way.
Packit fb9d21
That is, instead of considering the set
Packit fb9d21
$$
Packit fb9d21
\Delta = \diff R =
Packit fb9d21
\vec s \mapsto
Packit fb9d21
\{\, \vec \delta \in \Z^{d} \mid \exists \vec x \to \vec y \in R :
Packit fb9d21
\vec \delta = \vec y - \vec x
Packit fb9d21
\,\}
Packit fb9d21
$$
Packit fb9d21
we consider the set
Packit fb9d21
$$
Packit fb9d21
\Delta' = \diff R' =
Packit fb9d21
\{\, \vec \delta \in \Z^{n+d} \mid \exists
Packit fb9d21
(\vec s, \vec x) \to (\vec s, \vec y) \in R' :
Packit fb9d21
\vec \delta = (\vec s - \vec s, \vec y - \vec x)
Packit fb9d21
\,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
The first $n$ coordinates of every element in $\Delta'$ are zero.
Packit fb9d21
Projecting out these zero coordinates from $\Delta'$ is equivalent
Packit fb9d21
to projecting out the parameters in $\Delta$.
Packit fb9d21
The result is obviously a superset of $\Delta$, but all its constraints
Packit fb9d21
are of type \eqref{eq:transitive:non-parametric} and they can therefore
Packit fb9d21
all be used in the construction of $Q_i$.
Packit fb9d21
Packit fb9d21
\begin{example}
Packit fb9d21
Consider the relation
Packit fb9d21
$$
Packit fb9d21
% [n] -> { [x, y] -> [1 + x, 1 - n + y] | n >= 2 }
Packit fb9d21
R = n \to \{\, (x, y) \to (1 + x, 1 - n + y) \mid n \ge 2 \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
We have
Packit fb9d21
$$
Packit fb9d21
\diff R = n \to \{\, (1, 1 - n) \mid n \ge 2 \,\}
Packit fb9d21
$$
Packit fb9d21
and so, by treating the parameters in a special way, we obtain
Packit fb9d21
the following approximation for $R^+$:
Packit fb9d21
$$
Packit fb9d21
n \to \{\, (x, y) \to (x', y') \mid n \ge 2 \wedge y' \le 1 - n + y \wedge x' \ge 1 + x \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
If we consider instead
Packit fb9d21
$$
Packit fb9d21
R' = \{\, (n, x, y) \to (n, 1 + x, 1 - n + y) \mid n \ge 2 \,\}
Packit fb9d21
$$
Packit fb9d21
then
Packit fb9d21
$$
Packit fb9d21
\diff R' = \{\, (0, 1, y) \mid y \le -1 \,\}
Packit fb9d21
$$
Packit fb9d21
and we obtain the approximation
Packit fb9d21
$$
Packit fb9d21
n \to \{\, (x, y) \to (x', y') \mid n \ge 2 \wedge x' \ge 1 + x \wedge y' \le x + y - x' \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
If we consider both $\diff R$ and $\diff R'$, then we obtain
Packit fb9d21
$$
Packit fb9d21
n \to \{\, (x, y) \to (x', y') \mid n \ge 2 \wedge y' \le 1 - n + y \wedge x' \ge 1 + x \wedge y' \le x + y - x' \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
Note, however, that this is not the most accurate affine approximation that
Packit fb9d21
can be obtained.  That would be
Packit fb9d21
$$
Packit fb9d21
n \to \{\, (x, y) \to (x', y') \mid y' \le 2 - n + x + y - x' \wedge n \ge 2 \wedge x' \ge 1 + x \,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
\end{example}
Packit fb9d21
Packit fb9d21
\subsection{Checking Exactness}
Packit fb9d21
Packit fb9d21
The approximation $T$ for the transitive closure $R^+$ can be obtained
Packit fb9d21
by projecting out the parameter $k$ from the approximation $K$
Packit fb9d21
\eqref{eq:transitive:approx} of the power $R^k$.
Packit fb9d21
Since $K$ is an overapproximation of $R^k$, $T$ will also be an
Packit fb9d21
overapproximation of $R^+$.
Packit fb9d21
To check whether the results are exact, we need to consider two
Packit fb9d21
cases depending on whether $R$ is {\em cyclic}, where $R$ is defined
Packit fb9d21
to be cyclic if $R^+$ maps any element to itself, i.e.,
Packit fb9d21
$R^+ \cap \identity \ne \emptyset$.
Packit fb9d21
If $R$ is acyclic, then the inductive definition of
Packit fb9d21
\eqref{eq:transitive:inductive} is equivalent to its completion,
Packit fb9d21
i.e.,
Packit fb9d21
$$
Packit fb9d21
R^+ = R \cup \left(R \circ R^+\right)
Packit fb9d21
$$
Packit fb9d21
is a defining property.
Packit fb9d21
Since $T$ is known to be an overapproximation, we only need to check
Packit fb9d21
whether
Packit fb9d21
$$
Packit fb9d21
T \subseteq R \cup \left(R \circ T\right)
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
This is essentially Theorem~5 of \shortciteN{Kelly1996closure}.
Packit fb9d21
The only difference is that they only consider lexicographically
Packit fb9d21
forward relations, a special case of acyclic relations.
Packit fb9d21
Packit fb9d21
If, on the other hand, $R$ is cyclic, then we have to resort
Packit fb9d21
to checking whether the approximation $K$ of the power is exact.
Packit fb9d21
Note that $T$ may be exact even if $K$ is not exact, so the check
Packit fb9d21
is sound, but incomplete.
Packit fb9d21
To check exactness of the power, we simply need to check
Packit fb9d21
\eqref{eq:transitive:power}.  Since again $K$ is known
Packit fb9d21
to be an overapproximation, we only need to check whether
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
K'|_{y_{d+1} - x_{d+1} = 1} & \subseteq R'
Packit fb9d21
\\
Packit fb9d21
K'|_{y_{d+1} - x_{d+1} \ge 2} & \subseteq R' \circ K'|_{y_{d+1} - x_{d+1} \ge 1}
Packit fb9d21
,
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
where $R' = \{\, \vec x' \to \vec y' \mid \vec x \to \vec y \in R
Packit fb9d21
\wedge y_{d+1} - x_{d+1} = 1\,\}$, i.e., $R$ extended with path
Packit fb9d21
lengths equal to 1.
Packit fb9d21
Packit fb9d21
All that remains is to explain how to check the cyclicity of $R$.
Packit fb9d21
Note that the exactness on the power is always sound, even
Packit fb9d21
in the acyclic case, so we only need to be careful that we find
Packit fb9d21
all cyclic cases.  Now, if $R$ is cyclic, i.e.,
Packit fb9d21
$R^+ \cap \identity \ne \emptyset$, then, since $T$ is
Packit fb9d21
an overapproximation of $R^+$, also
Packit fb9d21
$T \cap \identity \ne \emptyset$.  This in turn means
Packit fb9d21
that $\Delta \, K'$ contains a point whose first $d$ coordinates
Packit fb9d21
are zero and whose final coordinate is positive.
Packit fb9d21
In the implementation we currently perform this test on $P'$ instead of $K'$.
Packit fb9d21
Note that if $R^+$ is acyclic and $T$ is not, then the approximation
Packit fb9d21
is clearly not exact and the approximation of the power $K$
Packit fb9d21
will not be exact either.
Packit fb9d21
Packit fb9d21
\subsection{Decomposing $R$ into strongly connected components}
Packit fb9d21
Packit fb9d21
If the input relation $R$ is a union of several basic relations
Packit fb9d21
that can be partially ordered
Packit fb9d21
then the accuracy of the approximation may be improved by computing
Packit fb9d21
an approximation of each strongly connected components separately.
Packit fb9d21
For example, if $R = R_1 \cup R_2$ and $R_1 \circ R_2 = \emptyset$,
Packit fb9d21
then we know that any path that passes through $R_2$ cannot later
Packit fb9d21
pass through $R_1$, i.e.,
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:components}
Packit fb9d21
R^+ = R_1^+ \cup R_2^+ \cup \left(R_2^+ \circ R_1^+\right)
Packit fb9d21
.
Packit fb9d21
\end{equation}
Packit fb9d21
We can therefore compute (approximations of) transitive closures
Packit fb9d21
of $R_1$ and $R_2$ separately.
Packit fb9d21
Note, however, that the condition $R_1 \circ R_2 = \emptyset$
Packit fb9d21
is actually too strong.
Packit fb9d21
If $R_1 \circ R_2$ is a subset of $R_2 \circ R_1$
Packit fb9d21
then we can reorder the segments
Packit fb9d21
in any path that moves through both $R_1$ and $R_2$ to
Packit fb9d21
first move through $R_1$ and then through $R_2$.
Packit fb9d21
Packit fb9d21
This idea can be generalized to relations that are unions
Packit fb9d21
of more than two basic relations by constructing the
Packit fb9d21
strongly connected components in the graph with as vertices
Packit fb9d21
the basic relations and an edge between two basic relations
Packit fb9d21
$R_i$ and $R_j$ if $R_i$ needs to follow $R_j$ in some paths.
Packit fb9d21
That is, there is an edge from $R_i$ to $R_j$ iff
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:edge}
Packit fb9d21
R_i \circ R_j
Packit fb9d21
\not\subseteq
Packit fb9d21
R_j \circ R_i
Packit fb9d21
.
Packit fb9d21
\end{equation}
Packit fb9d21
The components can be obtained from the graph by applying
Packit fb9d21
Tarjan's algorithm \shortcite{Tarjan1972}.
Packit fb9d21
Packit fb9d21
In practice, we compute the (extended) powers $K_i'$ of each component
Packit fb9d21
separately and then compose them as in \eqref{eq:transitive:decompose}.
Packit fb9d21
Note, however, that in this case the order in which we apply them is
Packit fb9d21
important and should correspond to a topological ordering of the
Packit fb9d21
strongly connected components.  Simply applying Tarjan's
Packit fb9d21
algorithm will produce topologically sorted strongly connected components.
Packit fb9d21
The graph on which Tarjan's algorithm is applied is constructed on-the-fly.
Packit fb9d21
That is, whenever the algorithm checks if there is an edge between
Packit fb9d21
two vertices, we evaluate \eqref{eq:transitive:edge}.
Packit fb9d21
The exactness check is performed on each component separately.
Packit fb9d21
If the approximation turns out to be inexact for any of the components,
Packit fb9d21
then the entire result is marked inexact and the exactness check
Packit fb9d21
is skipped on the components that still need to be handled.
Packit fb9d21
Packit fb9d21
It should be noted that \eqref{eq:transitive:components}
Packit fb9d21
is only valid for exact transitive closures.
Packit fb9d21
If overapproximations are computed in the right hand side, then the result will
Packit fb9d21
still be an overapproximation of the left hand side, but this result
Packit fb9d21
may not be transitively closed.  If we only separate components based
Packit fb9d21
on the condition $R_i \circ R_j = \emptyset$, then there is no problem,
Packit fb9d21
as this condition will still hold on the computed approximations
Packit fb9d21
of the transitive closures.  If, however, we have exploited
Packit fb9d21
\eqref{eq:transitive:edge} during the decomposition and if the
Packit fb9d21
result turns out not to be exact, then we check whether
Packit fb9d21
the result is transitively closed.  If not, we recompute
Packit fb9d21
the transitive closure, skipping the decomposition.
Packit fb9d21
Note that testing for transitive closedness on the result may
Packit fb9d21
be fairly expensive, so we may want to make this check
Packit fb9d21
configurable.
Packit fb9d21
Packit fb9d21
\begin{figure}
Packit fb9d21
\begin{center}
Packit fb9d21
\begin{tikzpicture}[x=0.5cm,y=0.5cm,>=stealth,shorten >=1pt]
Packit fb9d21
\foreach \x in {1,...,10}{
Packit fb9d21
    \foreach \y in {1,...,10}{
Packit fb9d21
	\draw[->] (\x,\y) -- (\x,\y+1);
Packit fb9d21
    }
Packit fb9d21
}
Packit fb9d21
\foreach \x in {1,...,20}{
Packit fb9d21
    \foreach \y in {5,...,15}{
Packit fb9d21
	\draw[->] (\x,\y) -- (\x+1,\y);
Packit fb9d21
    }
Packit fb9d21
}
Packit fb9d21
\end{tikzpicture}
Packit fb9d21
\end{center}
Packit fb9d21
\caption{The relation from \autoref{ex:closure4}}
Packit fb9d21
\label{f:closure4}
Packit fb9d21
\end{figure}
Packit fb9d21
\begin{example}
Packit fb9d21
\label{ex:closure4}
Packit fb9d21
Consider the relation in example {\tt closure4} that comes with
Packit fb9d21
the Omega calculator~\shortcite{Omega_calc}, $R = R_1 \cup R_2$,
Packit fb9d21
with
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
R_1 & = \{\, (x,y) \to (x,y+1) \mid 1 \le x,y \le 10 \,\}
Packit fb9d21
\\
Packit fb9d21
R_2 & = \{\, (x,y) \to (x+1,y) \mid 1 \le x \le 20 \wedge 5 \le y \le 15 \,\}
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
This relation is shown graphically in \autoref{f:closure4}.
Packit fb9d21
We have
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
R_1 \circ R_2 &=
Packit fb9d21
\{\, (x,y) \to (x+1,y+1) \mid 1 \le x \le 9 \wedge 5 \le y \le 10 \,\}
Packit fb9d21
\\
Packit fb9d21
R_2 \circ R_1 &=
Packit fb9d21
\{\, (x,y) \to (x+1,y+1) \mid 1 \le x \le 10 \wedge 4 \le y \le 10 \,\}
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
Clearly, $R_1 \circ R_2 \subseteq R_2 \circ R_1$ and so
Packit fb9d21
$$
Packit fb9d21
\left(
Packit fb9d21
R_1 \cup R_2
Packit fb9d21
\right)^+
Packit fb9d21
=
Packit fb9d21
\left(R_2^+ \circ R_1^+\right)
Packit fb9d21
\cup R_1^+
Packit fb9d21
\cup R_2^+
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
\end{example}
Packit fb9d21
Packit fb9d21
\begin{figure}
Packit fb9d21
\newcounter{n}
Packit fb9d21
\newcounter{t1}
Packit fb9d21
\newcounter{t2}
Packit fb9d21
\newcounter{t3}
Packit fb9d21
\newcounter{t4}
Packit fb9d21
\begin{center}
Packit fb9d21
\begin{tikzpicture}[>=stealth,shorten >=1pt]
Packit fb9d21
\setcounter{n}{7}
Packit fb9d21
\foreach \i in {1,...,\value{n}}{
Packit fb9d21
    \foreach \j in {1,...,\value{n}}{
Packit fb9d21
	\setcounter{t1}{2 * \j - 4 - \i + 1}
Packit fb9d21
	\setcounter{t2}{\value{n} - 3 - \i + 1}
Packit fb9d21
	\setcounter{t3}{2 * \i - 1 - \j + 1}
Packit fb9d21
	\setcounter{t4}{\value{n} - \j + 1}
Packit fb9d21
	\ifnum\value{t1}>0\ifnum\value{t2}>0
Packit fb9d21
	\ifnum\value{t3}>0\ifnum\value{t4}>0
Packit fb9d21
	    \draw[thick,->] (\i,\j) to[out=20] (\i+3,\j);
Packit fb9d21
	\fi\fi\fi\fi
Packit fb9d21
	\setcounter{t1}{2 * \j - 1 - \i + 1}
Packit fb9d21
	\setcounter{t2}{\value{n} - \i + 1}
Packit fb9d21
	\setcounter{t3}{2 * \i - 4 - \j + 1}
Packit fb9d21
	\setcounter{t4}{\value{n} - 3 - \j + 1}
Packit fb9d21
	\ifnum\value{t1}>0\ifnum\value{t2}>0
Packit fb9d21
	\ifnum\value{t3}>0\ifnum\value{t4}>0
Packit fb9d21
	    \draw[thick,->] (\i,\j) to[in=-20,out=20] (\i,\j+3);
Packit fb9d21
	\fi\fi\fi\fi
Packit fb9d21
	\setcounter{t1}{2 * \j - 1 - \i + 1}
Packit fb9d21
	\setcounter{t2}{\value{n} - 1 - \i + 1}
Packit fb9d21
	\setcounter{t3}{2 * \i - 1 - \j + 1}
Packit fb9d21
	\setcounter{t4}{\value{n} - 1 - \j + 1}
Packit fb9d21
	\ifnum\value{t1}>0\ifnum\value{t2}>0
Packit fb9d21
	\ifnum\value{t3}>0\ifnum\value{t4}>0
Packit fb9d21
	    \draw[thick,->] (\i,\j) to (\i+1,\j+1);
Packit fb9d21
	\fi\fi\fi\fi
Packit fb9d21
    }
Packit fb9d21
}
Packit fb9d21
\end{tikzpicture}
Packit fb9d21
\end{center}
Packit fb9d21
\caption{The relation from \autoref{ex:decomposition}}
Packit fb9d21
\label{f:decomposition}
Packit fb9d21
\end{figure}
Packit fb9d21
\begin{example}
Packit fb9d21
\label{ex:decomposition}
Packit fb9d21
Consider the relation on the right of \shortciteN[Figure~2]{Beletska2009},
Packit fb9d21
reproduced in \autoref{f:decomposition}.
Packit fb9d21
The relation can be described as $R = R_1 \cup R_2 \cup R_3$,
Packit fb9d21
with
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
R_1 &= n \mapsto \{\, (i,j) \to (i+3,j) \mid
Packit fb9d21
i \le 2 j - 4 \wedge
Packit fb9d21
i \le n - 3 \wedge
Packit fb9d21
j \le 2 i - 1 \wedge
Packit fb9d21
j \le n \,\}
Packit fb9d21
\\
Packit fb9d21
R_2 &= n \mapsto \{\, (i,j) \to (i,j+3) \mid
Packit fb9d21
i \le 2 j - 1 \wedge
Packit fb9d21
i \le n \wedge
Packit fb9d21
j \le 2 i - 4 \wedge
Packit fb9d21
j \le n - 3 \,\}
Packit fb9d21
\\
Packit fb9d21
R_3 &= n \mapsto \{\, (i,j) \to (i+1,j+1) \mid
Packit fb9d21
i \le 2 j - 1 \wedge
Packit fb9d21
i \le n - 1 \wedge
Packit fb9d21
j \le 2 i - 1 \wedge
Packit fb9d21
j \le n - 1\,\}
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
The figure shows this relation for $n = 7$.
Packit fb9d21
Both
Packit fb9d21
$R_3 \circ R_1 \subseteq R_1 \circ R_3$
Packit fb9d21
and
Packit fb9d21
$R_3 \circ R_2 \subseteq R_2 \circ R_3$,
Packit fb9d21
which the reader can verify using the {\tt iscc} calculator:
Packit fb9d21
\begin{verbatim}
Packit fb9d21
R1 := [n] -> { [i,j] -> [i+3,j] : i <= 2 j - 4 and i <= n - 3 and
Packit fb9d21
                                  j <= 2 i - 1 and j <= n };
Packit fb9d21
R2 := [n] -> { [i,j] -> [i,j+3] : i <= 2 j - 1 and i <= n and
Packit fb9d21
                                  j <= 2 i - 4 and j <= n - 3 };
Packit fb9d21
R3 := [n] -> { [i,j] -> [i+1,j+1] : i <= 2 j - 1 and i <= n - 1 and
Packit fb9d21
                                    j <= 2 i - 1 and j <= n - 1 };
Packit fb9d21
(R1 . R3) - (R3 . R1);
Packit fb9d21
(R2 . R3) - (R3 . R2);
Packit fb9d21
\end{verbatim}
Packit fb9d21
$R_3$ can therefore be moved forward in any path.
Packit fb9d21
For the other two basic relations, we have both
Packit fb9d21
$R_2 \circ R_1 \not\subseteq R_1 \circ R_2$
Packit fb9d21
and
Packit fb9d21
$R_1 \circ R_2 \not\subseteq R_2 \circ R_1$
Packit fb9d21
and so $R_1$ and $R_2$ form a strongly connected component.
Packit fb9d21
By computing the power of $R_3$ and $R_1 \cup R_2$ separately
Packit fb9d21
and composing the results, the power of $R$ can be computed exactly
Packit fb9d21
using \eqref{eq:transitive:singleton}.
Packit fb9d21
As explained by \shortciteN{Beletska2009}, applying the same formula
Packit fb9d21
to $R$ directly, without a decomposition, would result in
Packit fb9d21
an overapproximation of the power.
Packit fb9d21
\end{example}
Packit fb9d21
Packit fb9d21
\subsection{Partitioning the domains and ranges of $R$}
Packit fb9d21
Packit fb9d21
The algorithm of \autoref{s:power} assumes that the input relation $R$
Packit fb9d21
can be treated as a union of translations.
Packit fb9d21
This is a reasonable assumption if $R$ maps elements of a given
Packit fb9d21
abstract domain to the same domain.
Packit fb9d21
However, if $R$ is a union of relations that map between different
Packit fb9d21
domains, then this assumption no longer holds.
Packit fb9d21
In particular, when an entire dependence graph is encoded
Packit fb9d21
in a single relation, as is done by, e.g.,
Packit fb9d21
\shortciteN[Section~6.1]{Barthou2000MSE}, then it does not make
Packit fb9d21
sense to look at differences between iterations of different domains.
Packit fb9d21
Now, arguably, a modified Floyd-Warshall algorithm should
Packit fb9d21
be applied to the dependence graph, as advocated by
Packit fb9d21
\shortciteN{Kelly1996closure}, with the transitive closure operation
Packit fb9d21
only being applied to relations from a given domain to itself.
Packit fb9d21
However, it is also possible to detect disjoint domains and ranges
Packit fb9d21
and to apply Floyd-Warshall internally.
Packit fb9d21
Packit fb9d21
\LinesNumbered
Packit fb9d21
\begin{algorithm}
Packit fb9d21
\caption{The modified Floyd-Warshall algorithm of
Packit fb9d21
\protect\shortciteN{Kelly1996closure}}
Packit fb9d21
\label{a:Floyd}
Packit fb9d21
\SetKwInput{Input}{Input}
Packit fb9d21
\SetKwInput{Output}{Output}
Packit fb9d21
\Input{Relations $R_{pq}$, $0 \le p, q < n$}
Packit fb9d21
\Output{Updated relations $R_{pq}$ such that each relation
Packit fb9d21
$R_{pq}$ contains all indirect paths from $p$ to $q$ in the input graph}
Packit fb9d21
%
Packit fb9d21
\BlankLine
Packit fb9d21
\SetAlgoVlined
Packit fb9d21
\DontPrintSemicolon
Packit fb9d21
%
Packit fb9d21
\For{$r \in [0, n-1]$}{
Packit fb9d21
    $R_{rr} \coloneqq R_{rr}^+$ \nllabel{l:Floyd:closure}\;
Packit fb9d21
    \For{$p \in [0, n-1]$}{
Packit fb9d21
	\For{$q \in [0, n-1]$}{
Packit fb9d21
	    \If{$p \ne r$ or $q \ne r$}{
Packit fb9d21
		$R_{pq} \coloneqq R_{pq} \cup \left(R_{rq} \circ R_{pr}\right)
Packit fb9d21
			     \cup \left(R_{rq} \circ R_{rr} \circ R_{pr}\right)$
Packit fb9d21
	     \nllabel{l:Floyd:update}
Packit fb9d21
	     }
Packit fb9d21
	}
Packit fb9d21
    }
Packit fb9d21
}
Packit fb9d21
\end{algorithm}
Packit fb9d21
Packit fb9d21
Let the input relation $R$ be a union of $m$ basic relations $R_i$.
Packit fb9d21
Let $D_{2i}$ be the domains of $R_i$ and $D_{2i+1}$ the ranges of $R_i$.
Packit fb9d21
The first step is to group overlapping $D_j$ until a partition is
Packit fb9d21
obtained.  If the resulting partition consists of a single part,
Packit fb9d21
then we continue with the algorithm of \autoref{s:power}.
Packit fb9d21
Otherwise, we apply Floyd-Warshall on the graph with as vertices
Packit fb9d21
the parts of the partition and as edges the $R_i$ attached to
Packit fb9d21
the appropriate pairs of vertices.
Packit fb9d21
In particular, let there be $n$ parts $P_k$ in the partition.
Packit fb9d21
We construct $n^2$ relations
Packit fb9d21
$$
Packit fb9d21
R_{pq} \coloneqq \bigcup_{i \text{ s.t. } \domain R_i \subseteq P_p \wedge
Packit fb9d21
				 \range R_i \subseteq P_q} R_i
Packit fb9d21
,
Packit fb9d21
$$
Packit fb9d21
apply \autoref{a:Floyd} and return the union of all resulting
Packit fb9d21
$R_{pq}$ as the transitive closure of $R$.
Packit fb9d21
Each iteration of the $r$-loop in \autoref{a:Floyd} updates
Packit fb9d21
all relations $R_{pq}$ to include paths that go from $p$ to $r$,
Packit fb9d21
possibly stay there for a while, and then go from $r$ to $q$.
Packit fb9d21
Note that paths that ``stay in $r$'' include all paths that
Packit fb9d21
pass through earlier vertices since $R_{rr}$ itself has been updated
Packit fb9d21
accordingly in previous iterations of the outer loop.
Packit fb9d21
In principle, it would be sufficient to use the $R_{pr}$
Packit fb9d21
and $R_{rq}$ computed in the previous iteration of the
Packit fb9d21
$r$-loop in Line~\ref{l:Floyd:update}.
Packit fb9d21
However, from an implementation perspective, it is easier
Packit fb9d21
to allow either or both of these to have been updated
Packit fb9d21
in the same iteration of the $r$-loop.
Packit fb9d21
This may result in duplicate paths, but these can usually
Packit fb9d21
be removed by coalescing (\autoref{s:coalescing}) the result of the union
Packit fb9d21
in Line~\ref{l:Floyd:update}, which should be done in any case.
Packit fb9d21
The transitive closure in Line~\ref{l:Floyd:closure}
Packit fb9d21
is performed using a recursive call.  This recursive call
Packit fb9d21
includes the partitioning step, but the resulting partition will
Packit fb9d21
usually be a singleton.
Packit fb9d21
The result of the recursive call will either be exact or an
Packit fb9d21
overapproximation.  The final result of Floyd-Warshall is therefore
Packit fb9d21
also exact or an overapproximation.
Packit fb9d21
Packit fb9d21
\begin{figure}
Packit fb9d21
\begin{center}
Packit fb9d21
\begin{tikzpicture}[x=1cm,y=1cm,>=stealth,shorten >=3pt]
Packit fb9d21
\foreach \x/\y in {0/0,1/1,3/2} {
Packit fb9d21
    \fill (\x,\y) circle (2pt);
Packit fb9d21
}
Packit fb9d21
\foreach \x/\y in {0/1,2/2,3/3} {
Packit fb9d21
    \draw (\x,\y) circle (2pt);
Packit fb9d21
}
Packit fb9d21
\draw[->] (0,0) -- (0,1);
Packit fb9d21
\draw[->] (0,1) -- (1,1);
Packit fb9d21
\draw[->] (2,2) -- (3,2);
Packit fb9d21
\draw[->] (3,2) -- (3,3);
Packit fb9d21
\draw[->,dashed] (2,2) -- (3,3);
Packit fb9d21
\draw[->,dotted] (0,0) -- (1,1);
Packit fb9d21
\end{tikzpicture}
Packit fb9d21
\end{center}
Packit fb9d21
\caption{The relation (solid arrows) on the right of Figure~1 of
Packit fb9d21
\protect\shortciteN{Beletska2009} and its transitive closure}
Packit fb9d21
\label{f:COCOA:1}
Packit fb9d21
\end{figure}
Packit fb9d21
\begin{example}
Packit fb9d21
Consider the relation on the right of Figure~1 of
Packit fb9d21
\shortciteN{Beletska2009},
Packit fb9d21
reproduced in \autoref{f:COCOA:1}.
Packit fb9d21
This relation can be described as
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
\{\, (x, y) \to (x_2, y_2) \mid {} & (3y = 2x \wedge x_2 = x \wedge 3y_2 = 3 + 2x \wedge x \ge 0 \wedge x \le 3) \vee {} \\
Packit fb9d21
& (x_2 = 1 + x \wedge y_2 = y \wedge x \ge 0 \wedge 3y \ge 2 + 2x \wedge x \le 2 \wedge 3y \le 3 + 2x) \,\}
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
Note that the domain of the upward relation overlaps with the range
Packit fb9d21
of the rightward relation and vice versa, but that the domain
Packit fb9d21
of neither relation overlaps with its own range or the domain of
Packit fb9d21
the other relation.
Packit fb9d21
The domains and ranges can therefore be partitioned into two parts,
Packit fb9d21
$P_0$ and $P_1$, shown as the white and black dots in \autoref{f:COCOA:1},
Packit fb9d21
respectively.
Packit fb9d21
Initially, we have
Packit fb9d21
$$
Packit fb9d21
\begin{aligned}
Packit fb9d21
R_{00} & = \emptyset
Packit fb9d21
\\
Packit fb9d21
R_{01} & = 
Packit fb9d21
\{\, (x, y) \to (x+1, y) \mid 
Packit fb9d21
(x \ge 0 \wedge 3y \ge 2 + 2x \wedge x \le 2 \wedge 3y \le 3 + 2x) \,\}
Packit fb9d21
\\
Packit fb9d21
R_{10} & =
Packit fb9d21
\{\, (x, y) \to (x_2, y_2) \mid (3y = 2x \wedge x_2 = x \wedge 3y_2 = 3 + 2x \wedge x \ge 0 \wedge x \le 3) \,\}
Packit fb9d21
\\
Packit fb9d21
R_{11} & = \emptyset
Packit fb9d21
.
Packit fb9d21
\end{aligned}
Packit fb9d21
$$
Packit fb9d21
In the first iteration, $R_{00}$ remains the same ($\emptyset^+ = \emptyset$).
Packit fb9d21
$R_{01}$ and $R_{10}$ are therefore also unaffected, but
Packit fb9d21
$R_{11}$ is updated to include $R_{01} \circ R_{10}$, i.e.,
Packit fb9d21
the dashed arrow in the figure.
Packit fb9d21
This new $R_{11}$ is obviously transitively closed, so it is not
Packit fb9d21
changed in the second iteration and it does not have an effect
Packit fb9d21
on $R_{01}$ and $R_{10}$.  However, $R_{00}$ is updated to
Packit fb9d21
include $R_{10} \circ R_{01}$, i.e., the dotted arrow in the figure.
Packit fb9d21
The transitive closure of the original relation is then equal to
Packit fb9d21
$R_{00} \cup R_{01} \cup R_{10} \cup R_{11}$.
Packit fb9d21
\end{example}
Packit fb9d21
Packit fb9d21
\subsection{Incremental Computation}
Packit fb9d21
\label{s:incremental}
Packit fb9d21
Packit fb9d21
In some cases it is possible and useful to compute the transitive closure
Packit fb9d21
of union of basic relations incrementally.  In particular,
Packit fb9d21
if $R$ is a union of $m$ basic maps,
Packit fb9d21
$$
Packit fb9d21
R = \bigcup_j R_j
Packit fb9d21
,
Packit fb9d21
$$
Packit fb9d21
then we can pick some $R_i$ and compute the transitive closure of $R$ as
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:incremental}
Packit fb9d21
R^+ = R_i^+ \cup
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{j \ne i}
Packit fb9d21
R_i^* \circ R_j \circ R_i^*
Packit fb9d21
\right)^+
Packit fb9d21
.
Packit fb9d21
\end{equation}
Packit fb9d21
For this approach to be successful, it is crucial that each
Packit fb9d21
of the disjuncts in the argument of the second transitive
Packit fb9d21
closure in \eqref{eq:transitive:incremental} be representable
Packit fb9d21
as a single basic relation, i.e., without a union.
Packit fb9d21
If this condition holds, then by using \eqref{eq:transitive:incremental},
Packit fb9d21
the number of disjuncts in the argument of the transitive closure
Packit fb9d21
can be reduced by one.
Packit fb9d21
Now, $R_i^* = R_i^+ \cup \identity$, but in some cases it is possible
Packit fb9d21
to relax the constraints of $R_i^+$ to include part of the identity relation,
Packit fb9d21
say on domain $D$.  We will use the notation
Packit fb9d21
${\cal C}(R_i,D) = R_i^+ \cup \identity_D$ to represent
Packit fb9d21
this relaxed version of $R^+$.
Packit fb9d21
\shortciteN{Kelly1996closure} use the notation $R_i^?$.
Packit fb9d21
${\cal C}(R_i,D)$ can be computed by allowing $k$ to attain
Packit fb9d21
the value $0$ in \eqref{eq:transitive:Q} and by using
Packit fb9d21
$$
Packit fb9d21
P \cap \left(D \to D\right)
Packit fb9d21
$$
Packit fb9d21
instead of \eqref{eq:transitive:approx}.
Packit fb9d21
Typically, $D$ will be a strict superset of both $\domain R_i$
Packit fb9d21
and $\range R_i$.  We therefore need to check that domain
Packit fb9d21
and range of the transitive closure are part of ${\cal C}(R_i,D)$,
Packit fb9d21
i.e., the part that results from the paths of positive length ($k \ge 1$),
Packit fb9d21
are equal to the domain and range of $R_i$.
Packit fb9d21
If not, then the incremental approach cannot be applied for
Packit fb9d21
the given choice of $R_i$ and $D$.
Packit fb9d21
Packit fb9d21
In order to be able to replace $R^*$ by ${\cal C}(R_i,D)$
Packit fb9d21
in \eqref{eq:transitive:incremental}, $D$ should be chosen
Packit fb9d21
to include both $\domain R$ and $\range R$, i.e., such
Packit fb9d21
that $\identity_D \circ R_j \circ \identity_D = R_j$ for all $j\ne i$.
Packit fb9d21
\shortciteN{Kelly1996closure} say that they use
Packit fb9d21
$D = \domain R_i \cup \range R_i$, but presumably they mean that
Packit fb9d21
they use $D = \domain R \cup \range R$.
Packit fb9d21
Now, this expression of $D$ contains a union, so it not directly usable.
Packit fb9d21
\shortciteN{Kelly1996closure} do not explain how they avoid this union.
Packit fb9d21
Apparently, in their implementation,
Packit fb9d21
they are using the convex hull of $\domain R \cup \range R$
Packit fb9d21
or at least an approximation of this convex hull.
Packit fb9d21
We use the simple hull (\autoref{s:simple hull}) of $\domain R \cup \range R$.
Packit fb9d21
Packit fb9d21
It is also possible to use a domain $D$ that does {\em not\/}
Packit fb9d21
include $\domain R \cup \range R$, but then we have to
Packit fb9d21
compose with ${\cal C}(R_i,D)$ more selectively.
Packit fb9d21
In particular, if we have
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:right}
Packit fb9d21
\text{for each $j \ne i$ either }
Packit fb9d21
\domain R_j \subseteq D \text{ or } \domain R_j \cap \range R_i = \emptyset
Packit fb9d21
\end{equation}
Packit fb9d21
and, similarly,
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:transitive:left}
Packit fb9d21
\text{for each $j \ne i$ either }
Packit fb9d21
\range R_j \subseteq D \text{ or } \range R_j \cap \domain R_i = \emptyset
Packit fb9d21
\end{equation}
Packit fb9d21
then we can refine \eqref{eq:transitive:incremental} to
Packit fb9d21
$$
Packit fb9d21
R_i^+ \cup
Packit fb9d21
\left(
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\domain R_j \subseteq D $\\
Packit fb9d21
		     $\scriptstyle\range R_j \subseteq D$}}
Packit fb9d21
{\cal C} \circ R_j \circ {\cal C}
Packit fb9d21
\right)
Packit fb9d21
\cup
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\domain R_j \cap \range R_i = \emptyset$\\
Packit fb9d21
		     $\scriptstyle\range R_j \subseteq D$}}
Packit fb9d21
\!\!\!\!\!
Packit fb9d21
{\cal C} \circ R_j
Packit fb9d21
\right)
Packit fb9d21
\cup
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\domain R_j \subseteq D $\\
Packit fb9d21
		     $\scriptstyle\range R_j \cap \domain R_i = \emptyset$}}
Packit fb9d21
\!\!\!\!\!
Packit fb9d21
R_j \circ {\cal C}
Packit fb9d21
\right)
Packit fb9d21
\cup
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\domain R_j \cap \range R_i = \emptyset$\\
Packit fb9d21
		     $\scriptstyle\range R_j \cap \domain R_i = \emptyset$}}
Packit fb9d21
\!\!\!\!\!
Packit fb9d21
R_j
Packit fb9d21
\right)
Packit fb9d21
\right)^+
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
If only property~\eqref{eq:transitive:right} holds,
Packit fb9d21
we can use
Packit fb9d21
$$
Packit fb9d21
R_i^+ \cup
Packit fb9d21
\left(
Packit fb9d21
\left(
Packit fb9d21
R_i^+ \cup \identity
Packit fb9d21
\right)
Packit fb9d21
\circ
Packit fb9d21
\left(
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\domain R_j \subseteq D $}}
Packit fb9d21
R_j \circ {\cal C}
Packit fb9d21
\right)
Packit fb9d21
\cup
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\domain R_j \cap \range R_i = \emptyset$}}
Packit fb9d21
\!\!\!\!\!
Packit fb9d21
R_j
Packit fb9d21
\right)
Packit fb9d21
\right)^+
Packit fb9d21
\right)
Packit fb9d21
,
Packit fb9d21
$$
Packit fb9d21
while if only property~\eqref{eq:transitive:left} holds,
Packit fb9d21
we can use
Packit fb9d21
$$
Packit fb9d21
R_i^+ \cup
Packit fb9d21
\left(
Packit fb9d21
\left(
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\range R_j \subseteq D $}}
Packit fb9d21
{\cal C} \circ R_j
Packit fb9d21
\right)
Packit fb9d21
\cup
Packit fb9d21
\left(
Packit fb9d21
\bigcup_{\shortstack{$\scriptstyle\range R_j \cap \domain R_i = \emptyset$}}
Packit fb9d21
\!\!\!\!\!
Packit fb9d21
R_j
Packit fb9d21
\right)
Packit fb9d21
\right)^+
Packit fb9d21
\circ
Packit fb9d21
\left(
Packit fb9d21
R_i^+ \cup \identity
Packit fb9d21
\right)
Packit fb9d21
\right)
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
Packit fb9d21
It should be noted that if we want the result of the incremental
Packit fb9d21
approach to be transitively closed, then we can only apply it
Packit fb9d21
if all of the transitive closure operations involved are exact.
Packit fb9d21
If, say, the second transitive closure in \eqref{eq:transitive:incremental}
Packit fb9d21
contains extra elements, then the result does not necessarily contain
Packit fb9d21
the composition of these extra elements with powers of $R_i$.
Packit fb9d21
Packit fb9d21
\subsection{An {\tt Omega}-like implementation}
Packit fb9d21
Packit fb9d21
While the main algorithm of \shortciteN{Kelly1996closure} is
Packit fb9d21
designed to compute and underapproximation of the transitive closure,
Packit fb9d21
the authors mention that they could also compute overapproximations.
Packit fb9d21
In this section, we describe our implementation of an algorithm
Packit fb9d21
that is based on their ideas.
Packit fb9d21
Note that the {\tt Omega} library computes underapproximations
Packit fb9d21
\shortcite[Section 6.4]{Omega_lib}.
Packit fb9d21
Packit fb9d21
The main tool is Equation~(2) of \shortciteN{Kelly1996closure}.
Packit fb9d21
The input relation $R$ is first overapproximated by a ``d-form'' relation
Packit fb9d21
$$
Packit fb9d21
\{\, \vec i \to \vec j \mid \exists \vec \alpha :
Packit fb9d21
\vec L \le \vec j - \vec i \le \vec U
Packit fb9d21
\wedge
Packit fb9d21
(\forall p : j_p - i_p = M_p \alpha_p)
Packit fb9d21
\,\}
Packit fb9d21
,
Packit fb9d21
$$
Packit fb9d21
where $p$ ranges over the dimensions and $\vec L$, $\vec U$ and
Packit fb9d21
$\vec M$ are constant integer vectors.  The elements of $\vec U$
Packit fb9d21
may be $\infty$, meaning that there is no upper bound corresponding
Packit fb9d21
to that element, and similarly for $\vec L$.
Packit fb9d21
Such an overapproximation can be obtained by computing strides,
Packit fb9d21
lower and upper bounds on the difference set $\Delta \, R$.
Packit fb9d21
The transitive closure of such a ``d-form'' relation is
Packit fb9d21
\begin{equation}
Packit fb9d21
\label{eq:omega}
Packit fb9d21
\{\, \vec i \to \vec j \mid \exists \vec \alpha, k :
Packit fb9d21
k \ge 1 \wedge
Packit fb9d21
k \, \vec L \le \vec j - \vec i \le k \, \vec U
Packit fb9d21
\wedge
Packit fb9d21
(\forall p : j_p - i_p = M_p \alpha_p)
Packit fb9d21
\,\}
Packit fb9d21
.
Packit fb9d21
\end{equation}
Packit fb9d21
The domain and range of this transitive closure are then
Packit fb9d21
intersected with those of the input relation.
Packit fb9d21
This is a special case of the algorithm in \autoref{s:power}.
Packit fb9d21
Packit fb9d21
In their algorithm for computing lower bounds, the authors
Packit fb9d21
use the above algorithm as a substep on the disjuncts in the relation.
Packit fb9d21
At the end, they say
Packit fb9d21
\begin{quote}
Packit fb9d21
If an upper bound is required, it can be calculated in a manner
Packit fb9d21
similar to that of a single conjunct [sic] relation.
Packit fb9d21
\end{quote}
Packit fb9d21
Presumably, the authors mean that a ``d-form'' approximation
Packit fb9d21
of the whole input relation should be used.
Packit fb9d21
However, the accuracy can be improved by also trying to
Packit fb9d21
apply the incremental technique from the same paper,
Packit fb9d21
which is explained in more detail in \autoref{s:incremental}.
Packit fb9d21
In this case, ${\cal C}(R_i,D)$ can be obtained by
Packit fb9d21
allowing the value zero for $k$ in \eqref{eq:omega},
Packit fb9d21
i.e., by computing
Packit fb9d21
$$
Packit fb9d21
\{\, \vec i \to \vec j \mid \exists \vec \alpha, k :
Packit fb9d21
k \ge 0 \wedge
Packit fb9d21
k \, \vec L \le \vec j - \vec i \le k \, \vec U
Packit fb9d21
\wedge
Packit fb9d21
(\forall p : j_p - i_p = M_p \alpha_p)
Packit fb9d21
\,\}
Packit fb9d21
.
Packit fb9d21
$$
Packit fb9d21
In our implementation we take as $D$ the simple hull
Packit fb9d21
(\autoref{s:simple hull}) of $\domain R \cup \range R$.
Packit fb9d21
To determine whether it is safe to use ${\cal C}(R_i,D)$,
Packit fb9d21
we check the following conditions, as proposed by
Packit fb9d21
\shortciteN{Kelly1996closure}:
Packit fb9d21
${\cal C}(R_i,D) - R_i^+$ is not a union and for each $j \ne i$
Packit fb9d21
the condition
Packit fb9d21
$$
Packit fb9d21
\left({\cal C}(R_i,D) - R_i^+\right)
Packit fb9d21
\circ
Packit fb9d21
R_j
Packit fb9d21
\circ
Packit fb9d21
\left({\cal C}(R_i,D) - R_i^+\right)
Packit fb9d21
=
Packit fb9d21
R_j
Packit fb9d21
$$
Packit fb9d21
holds.