An Improved Tight Closure Algorithm for Integer Octagonal Constraints^{⋆}

Roberto Bagnara^{1}, Patricia M. Hill^{2}, and Enea Zaffanella^{1}

1 Department of Mathematics, University of Parma, Italy

               {bagnara,zaffanella}@cs.unipr.it

2 School of Computing, University of Leeds, UK

                    hill@comp.leeds.ac.uk

Abstract. Integer octagonal constraints (a.k.a. Unit Two Variables Per Inequality or UTVPI integer constraints) constitute an interesting class of constraints for the representation and solution of integer problems in the fields of constraint programming and formal analysis and verification of software and hardware systems, since they couple algorithms having polynomial complexity with a relatively good expressive power. The main algorithms required for the manipulation of such constraints are the satisfiability check and the computation of the inferential closure of a set of constraints. The latter is called tight closure to mark the difference with the (incomplete) closure algorithm that does not exploit the integrality of the variables. In this paper we present and fully justify an O(n^{3}) algorithm to compute the tight closure of a set of UTVPI integer constraints.

1 Introduction

Integer octagonal constraints, also called Unit Two Variables Per Inequality (UTVPI) integer constraints —that is, constraints of the form ax + by ≤ d where a, b ∈ {−1, 0, +1}, d ∈ ℤ and the variables x and y range over the integers—, constitute an interesting subclass of linear integer constraints admitting polynomial solvability. The place which these constraints occupy in the complexity/expressivity spectrum is, in fact, peculiar. Concerning complexity, relaxing the restriction of (at most) two variables per constraint and/or relaxing the restriction on coefficient make the satisfiability problem NP-complete [13, 14]. Concerning expressivity, integer octagonal constraints can be used for representing and solving many integer problems in the field of constraint programming, such as temporal reasoning and scheduling [13]. In the field of formal analysis and verification of software and hardware systems, these constraints have been successfully used in a number of applications [5, 6, 9, 18].

⋆ This work has been partly supported by MURST project “AIDA — Abstract Interpretation: Design and Applications,” and by a Royal Society (UK) International Joint Project (ESEP) award.

When (integer or rational) octagonal constraints are used to build abstract domains^{3} —such as the Octagon Abstract Domain implemented in the library with the same name [19] or the domain of octagonal shapes defined in [2] and implemented in the Parma Polyhedra Library [4]— the most critical operation is not the satisfiability check (although very important in constraint programming) but closure by entailment. This is the procedure whereby a set of octagonal constraints is augmented with (a finite representation of) all the octagonal constraints that can be inferred from it. The closure algorithms for rational octagonal constraints are sound but not complete for integer octagonal constraints. The latter require so-called tight closure algorithms that fully exploit the integrality of the variables.

In 2005, Lahiri and Musuvathi proposed an O(n^{3}) algorithm for the satisfiability check of a (non trivially redundant) system of UTVPI integer constraints [15]. They also sketched (without formal definitions and proofs) a tight closure algorithm with the same worst-case complexity bound. Still in 2005, Miné proposed a modification of the strong (i.e., non-tight) closure algorithm for rational octagonal constraints and argued that this would provide a good and efficient approximation of tight closure [18, 19]. In the same year we showed that the algorithm for computing the strong closure of rational octagonal constraints as described in [16, 18, 19] could be simplified with a consequential improvement in its efficiency [2, 3]. In this paper we show that our result can be extended so as to apply to integer octagonal constraints. This enables us to present and fully justify an O(n^{3}) algorithm to compute the tight closure of a set of UTVPI integer constraints. In particular, this is the first time that an algorithm achieving such a complexity bound is provided with a proof of correctness.

In Section 2 we briefly introduce the terminology and notation adopted throughout the paper and we recall a few standard results on weighted graphs. In Section 3, we give the definition of rational-weighted octagonal graphs and recall some of the results that were established in [2, 3]. In Section 4, we extend these results to the case of integer-weighted octagonal graphs. Finally, in Section 5 we conclude and briefly discuss future work.

2 Preliminaries

Let ℚ_{∞} := ℚ ∪ {+∞} be totally ordered by the extension of ‘<’ such that d < +∞ for each d ∈ ℚ. Let N be a finite set of nodes. A rational-weighted directed graph (graph, for short) G in N is a pair (N , w), where w: N ×N → ℚ_{∞} is the weight function for G.

Let G = (N , w) be a graph. A pair (n_{i}, n_{j}) ∈ N × N is an arc of G if w(n_{i}, n_{j}) < +∞; the arc is proper if n_{i} ≠ n_{j}. A path π = n_{0} ⋯ n_{p} in G is a non-empty and finite sequence of nodes such that (n_{i−1}, n_{i}) is an arc of G, for

3 In abstract interpretation theory [8], an abstract domain is an algebraic structure formalizing a set of assertions endowed with an approximation relation, plus various operations that correctly approximate the operations of some concrete domain, i.e., the domain being abstracted/approximated.

all i = 1, …, p. Each node n_{i} where i = 0, …, p and each arc (n_{i−1}, n_{i}) where i = 1, …, p is said to be in the path π. The length of the path π is the number p of occurrences of arcs in π and denoted by ∥π∥; the weight of the path π is ∑_{i=1}^{p} w(n_{i−1}, n_{i}) and denoted by w(π). The path π is simple if each node occurs at most once in π. The path π is proper if all the arcs in it are proper. The path π is a proper cycle if it is a proper path, n_{0} = n_{p} and p ≥ 2. If π_{1} = n_{0} ⋯ n_{h} and π_{2} = n_{h} ⋯ n_{p} are paths, where 0 ≤ h ≤ p, then the path concatenation π = n_{0} ⋯ n_{h} ⋯ n_{p} of π_{1} and π_{2} is denoted by π_{1} :: π_{2}; if π_{1} = n_{0}n_{1} (so that h = 1), then π_{1} :: π_{2} will also be denoted by n_{0}·π_{2}. Note that path concatenation is not the same as sequence concatenation.

A graph (N , w) can be interpreted as the system of potential constraints

C := { n_{i} − n_{j} ≤ w(n_{i}, n_{j}) | n_{i}, n_{j} ∈ N }.

Hence, the graph (N , w) is consistent if and only if the system of constraints it represents is satisfiable in ℚ, i.e., there exists a rational valuation ρ: N → ℚ such that, for each constraint (n_{i} − n_{j} ≤ d) ∈ C, the relation ρ(n_{i}) − ρ(n_{j}) ≤ d holds. It is well-known that a graph is consistent if and only if it has no negative weight cycles (see [7, Section 25.5] and [22]).

The set of consistent graphs in N is denoted by 𝔾. This set is partially ordered by the relation ‘⊴’ defined, for all G_{1} = (N , w_{1}) and G_{2} = (N , w_{2}), by

G_{1} ⊴ G_{2} ⟺ ∀i, j ∈ N : w_{1}(i, j) ≤ w_{2}(i, j).

We write G ◁ G′ when G ⊴ G′ and G ≠ G′. When augmented with a bottom element ⊥ representing inconsistency, this partially ordered set becomes a noncomplete lattice 𝔾_{⊥} = ⟨𝔾 ∪ {⊥}, ⊴, ⊓, ⊔⟩, where ‘⊓’ and ‘⊔’ denote the finitary greatest lower bound and least upper bound operators, respectively.

Definition 1. (Closed graph.) A consistent graph G = (N , w) is closed if the following properties hold:

∀i ∈ N : w(i, i) = 0;  (1)
∀i, j, k ∈ N : w(i, j) ≤ w(i, k) + w(k, j).  (2)

The (shortest-path) closure of a consistent graph G in N is

closure(G) := ⨆{ G′ ∈ 𝔾 | G′ ⊴ G and G′ is closed }.

Although the lattice of rational graphs is not complete, it will include the infinite least upper bound defining the closure of a rational graph G. Informally, this must hold since the weights of the least upper bound graph must be linear combinations of the rational weights of G and hence are also rational.

When trivially extended so as to behave as the identity function on the bottom element ⊥, shortest-path closure is a kernel operator (monotonic, idempotent and reductive) on the lattice 𝔾_{⊥}, therefore providing a canonical form.

The following lemma recalls a well-known result for closed graphs (for a proof, see Lemma 5 in [3]).

Lemma 1. Let G = (N , w) ∈ 𝔾 be a closed graph. Then, for any path π = i ⋯ j in G, it holds that w(i, j) ≤ w(π).

3 Rational Octagonal Graphs

We assume in the following that there is a fixed set V = {v_{0}, …, v_{n−1}} of n variables. The octagon abstract domain allows for the manipulation of octagonal constraints of the form av_{i} + bv_{j} ≤ d, where a, b ∈ {−1, 0, +1}, a ≠ 0, v_{i}, v_{j} ∈ V, v_{i} ≠ v_{j} and d ∈ ℚ. Octagonal constraints can be encoded using potential constraints by splitting each variable v_{i} into two forms: a positive form v_{i}^{+}, interpreted as +v_{i}; and a negative form v_{i}^{−}, interpreted as −v_{i}. Then any octagonal constraint av_{i} + bv_{j} ≤ d can be written as a potential constraint v − v′ ≤ d_{0} where v, v′ ∈ {v_{i}^{+}, v_{i}^{−}, v_{j}^{+}, v_{j}^{−}} and d_{0} ∈ ℚ. Namely, an octagonal constraint such as v_{i} + v_{j} ≤ d can be translated into the potential constraint v_{i}^{+} − v_{j}^{−} ≤ d; alternatively, the same octagonal constraint can be translated into v_{j}^{+} − v_{i}^{−} ≤ d. Furthermore, unary (octagonal) constraints such as v_{i} ≤ d and −v_{i} ≤ d can be encoded as v_{i}^{+} − v_{i}^{−} ≤ 2d and v_{i}^{−} − v_{i}^{+} ≤ 2d, respectively.

From now on, we assume that the set of nodes is N := {0, …, 2n−1}. These will denote the positive and negative forms of the variables in V: for all i ∈ N, if i = 2k, then i represents the positive form v_{k}^{+} and, if i = 2k+1, then i represents the negative form v_{k}^{−} of the variable v_{k}. To simplify the presentation, for each i ∈ N, we let \overline{ı} denote i + 1, if i is even, and i − 1, if i is odd, so that, for all i ∈ N, we also have \overline{ı} ∈ N and \overline{\overline{ı}} = i. Then we can rewrite a potential constraint v − v′ ≤ d where v ∈ {v_{k}^{+}, v_{k}^{−}} and v′ ∈ {v_{l}^{+}, v_{l}^{−}} as the potential constraint i − j ≤ d in N where, if v = v_{k}^{+}, i = 2k and if v = v_{k}^{−}, i = 2k + 1; similarly, if v′ = v_{l}^{+}, j = 2l and if v′ = v_{l}^{−}, j = 2l + 1.

It follows from the above translations that any finite system of octagonal constraints, translated into a set of potential constraints in N as above, can be encoded by a graph G in N. In particular, any finite satisfiable system of octagonal constraints can be encoded by a consistent graph in N. However, the converse does not hold since in any valuation ρ of an encoding of a set of octagonal constraints we must also have ρ(i) = −ρ(\overline{ı}), so that the arcs (i, j) and (\overline{ȷ}, \overline{ı}) should have the same weight. Therefore, to encode rational octagonal constraints, we restrict attention to consistent graphs over N where the arcs in all such pairs are coherent.

Definition 2. (Octagonal graph.) A (rational) octagonal graph is any consistent graph G = (N , w) that satisfies the coherence assumption:

∀i, j ∈ N : w(i, j) = w(\overline{ȷ}, \overline{ı}).  (3)

The set 𝕆 of all octagonal graphs (with the usual addition of the bottom element, representing an unsatisfiable system of constraints) is a sub-lattice of 𝔾_{⊥}, sharing the same least upper bound and greatest lower bound operators. Note that, at the implementation level, coherence can be automatically and efficiently enforced by letting arc (i, j) and arc (\overline{ȷ}, \overline{ı}) share the same representation. This also implies that an octagonal constraint such as v_{i} + v_{j} ≤ d will always be translated into both v_{i}^{+} − v_{j}^{−} ≤ d and v_{j}^{+} − v_{i}^{−} ≤ d.

When dealing with octagonal graphs, observe that the coherence assumption links the positive and negative forms of variables. A closure by entailment procedure should consider, besides transitivity, the following inference rule:

{i − \overline{ı} ≤ d_{1}  \overline{ȷ} − j ≤ d_{2} \atop i − j ≤ \frac{d_{1} + d_{2}}{2}}  (4)

Thus, the standard shortest-path closure algorithm is not enough to obtain a canonical form for octagonal graphs.

Definition 3. (Strongly closed graph.) An octagonal graph G = (N , w) is strongly closed if it is closed and the following property holds:

∀i, j ∈ N : 2w(i, j) ≤ w(i, \overline{ı}) + w(\overline{ȷ}, j).  (5)

The strong closure of an octagonal graph G in N is

S-closure(G) := ⨆{ G′ ∈ 𝕆 | G′ ⊴ G and G′ is strongly closed }.

When trivially extended with a bottom element, strong closure is a kernel operator on the lattice of octagonal graphs.

A modified closure procedure is defined in [16], yielding strongly closed octagonal graphs. A significant efficiency improvement can be obtained thanks to the following theorem (for a proof, see Theorem 2 in [3]).

Theorem 1. Let G = (N , w) be a closed octagonal graph. Consider the graph G_{S} = (N , w_{S}), where w_{S} is defined, for each i, j ∈ N, by

w_{S}(i, j) := min\{w(i, j), \frac{w(i, \overline{ı})}{2} + \frac{w(\overline{ȷ}, j)}{2}\}.

Then G_{S} = S-closure(G).

Intuitively, the theorem states that strong closure can be obtained by application of any shortest-path closure algorithm followed by a single local propagation step using the constraint inference rule (4). In contrast, in the strong closure algorithm of [16], the outermost iterations of (a variant of) the Floyd-Warshall shortest-path algorithm are interleaved with n applications of the inference rule (4), leading to a more complex and less efficient implementation.

4 Integer Octagonal Graphs

We now consider the case of integer octagonal constraints, i.e., octagonal constraints where the bounds are all integral and the variables are only allowed to take integral values. These can be encoded by suitably restricting the codomain of the weight function of octagonal graphs.

Definition 4. (Integer octagonal graph.) An integer octagonal graph is an octagonal graph G = (N , w) having an integral weight function:

∀i, j ∈ N : w(i, j) ∈ ℤ ∪ {+∞}.

As an integer octagonal graph is also a rational octagonal graph, the constraint system that it encodes will be satisfiable when interpreted to take values in ℚ. However, when interpreted to take values in ℤ, this system may be unsatisfiable since the arcs encoding unary constraints can have an odd weight; we say that an octagonal graph is ℤ-consistent if its encoded integer constraint system is satisfiable. For the same reason, the strong closure of an integer octagonal graph does not provide a canonical form for the integer constraint system that it encodes and we need to consider the following tightening inference rule:

{i − \overline{ı} ≤ d \atop i − \overline{ı} ≤ 2⌊d/2⌋}.  (6)

Definition 5. (Tightly closed graph.) An octagonal graph G = (N , w) is tightly closed if it is a strongly closed integer octagonal graph and the following property holds:

∀i ∈ N : w(i, \overline{ı}) is even.  (7)

The tight closure of an octagonal graph G in N is

T-closure(G) := ⨆{ G′ ∈ 𝕆 | G′ ⊴ G and G′ is tightly closed }.

By property (7), any tightly closed integer octagonal graph will encode a satisfiable integer constraint system and is therefore ℤ-consistent. Moreover, since the encoding of any satisfiable integer constraint system will result in a ℤconsistent integer octagonal graph G that satisfies property (7), its tight closure T-closure(G) will also be ℤ-consistent. This means that, if G is not ℤ-consistent, then T-closure(G) = ⨆ ∅ = ⊥; that is, the tight closure operator computes either a tightly closed graph or the bottom element. Therefore, tight closure is a kernel operator on the lattice of octagonal graphs, as was the case for strong closure.

An incremental closure procedure for obtaining the tight closure of an octagonal graph was defined in [13] and improved in [12]. The algorithm, which is also presented and discussed in [18, Section 4.3.5], maintains the tight closure of a system of octagonal constraints by performing at most O(n^{2}) operations each time a new constraint is added: thus, for m constraints, the worst case complexity is O(mn^{2}). In particular, for the case of a dense system of octagonal constraints where m ∈ O(n^{2}), the worst case complexity is O(n^{4}).

The following theorem shows that a more efficient tight closure algorithm can be obtained by a simple modification to the improved strong closure algorithm of Theorem 1. Basically, inference rule (6) must be applied to ensure property (7) holds before applying inference rule (4).

Theorem 2. Let G = (N , w) be a closed integer octagonal graph. Consider the graph G_{T} = (N , w_{T}), where w_{T} is defined, for each i, j ∈ N, by

w_{T}(i, j) := min\{w(i, j), ⌊\frac{w(i, \overline{ı})}{2}⌋ + ⌊\frac{w(\overline{ȷ}, j)}{2}⌋\}.

Then, if G_{T} is an octagonal graph, G_{T} = T-closure(G).

procedure tight closure if consistent(var w [0 . . 2n − 1] [0 . . 2n − 1]) { Classical Floyd-Warshall: O(n^{3}) } for k := 0 to 2n − 1 do

for i := 0 to 2n − 1 do

for j := 0 to 2n − 1 do

w[i, j] := min(w[i, j], w[i, k] + w[k, j]);

{ Tight coherence: O(n^{2}) } for i := 0 to 2n − 1 do

for j := 0 to 2n − 1 do
w[i, j] := min(w[i, j], floor(w[i, \overline{ı}]/2) + floor(w[\overline{ȷ}, j]/2));

Fig. 1. A O(n^{3}) tight closure algorithm for ℤ-consistent integer octagonal graphs

Figure 1 shows the pseudo-code for a O(n^{3}) tight closure algorithm based on Theorem 2 and on the classical Floyd-Warshall shortest-path closure algorithm. Note that the pseudo-code in Figure 1 assumes that the data structure recording the weight function w, here denoted to be similar to a two-dimensional array, automatically implements the coherence assumption for octagonal graphs (i.e., property (3) of Definition 2).

In the case of sparse graphs, a better complexity bound can be obtained by modifying the code in Figure 1 so as to compute the shortest path closure using Johnson’s algorithm [7]: the worst case complexity of such an implementation will be O(n^{2} log n + mn), which significantly improves upon the O(mn^{2}) worst case complexity of [12, 13] when, e.g., m ∈ Θ(n). However, as observed elsewhere [18, 23], some of the targeted applications (e.g., static analysis) typically require the computation of graphs that are dense, so that the Floyd-Warshall algorithm is often a better choice from a practical perspective.

It is possible to define an incremental variant of the tight closure algorithm in Figure 1, which is simply based on the corresponding incremental version of the Floyd-Warshall shortest path closure algorithm. In such a case, we obtain the same worst case complexity of [12, 13].

The proof of Theorem 2 relies on a few auxiliary lemmas. The first two were also used in [3] for the formal proof of Theorem 1 above (for their detailed proofs, see Lemmas 9 and 10 in [3]).

Lemma 2. Let G = (N , w) be an octagonal graph, G^{⋆} = (N , w^{⋆}) := closure(G) and (z_{1}, z_{2}) be an arc in G^{⋆}. Then there exists a simple path π = z_{1} ⋯ z_{2} in G such that w^{⋆}(z_{1}, z_{2}) = w(π).

Lemma 3. Let G = (N , w) be a closed octagonal graph and i, j ∈ N be such that i ≠ \overline{ȷ} and 2w(i, j) ≥ w(i, \overline{ı}) + w(\overline{ȷ}, j). Let G_{s}^{⋆} = (N , w_{s}^{⋆}) := closure(G_{s}) where G_{s} := (N , w_{s}) and, for each h_{1}, h_{2} ∈ N,

w_{s}(h_{1}, h_{2}) := \begin{cases}(w(i, \overline{ı}) + w(\overline{ȷ}, j))/2, & if (h_{1}, h_{2}) ∈ \{(i, j), (\overline{ȷ}, \overline{ı})\}; \\ w(h_{1}, h_{2}), & otherwise. \end{cases}

Let also z_{1}, z_{2} ∈ N. Then one or both of the following hold:

w_{s}^{⋆}(z_{1}, z_{2}) = w(z_{1}, z_{2});
2w_{s}^{⋆}(z_{1}, z_{2}) ≥ w(z_{1}, \overline{z}_{1}) + w(\overline{z}_{2}, z_{2}).

Informally, Lemma 3 states that if inference rule (4) is applied to a closed octagonal graph, then the resulting graph can be closed just by making further applications of inference rule (4). Note that, if G is an integer octagonal graph and property (7) holds, then the derived graph G_{s} will also be an integer octagonal graph. We now state a new lemma for integer octagonal graphs showing that when inference rule (6) is applied we obtain a similar conclusion to that for Lemma 3.

Lemma 4. Let G = (N , w) be a closed integer octagonal graph and i ∈ N. Let G_{t}^{⋆} := closure(G_{t}) where G_{t} := (N , w_{t}) is an octagonal graph and, for each h_{1}, h_{2} ∈ N,

w_{t}(h_{1}, h_{2}) := \begin{cases}w(i, \overline{ı}) − 1, & if (h_{1}, h_{2}) = (i, \overline{ı}); \\ w(h_{1}, h_{2}), & otherwise. \end{cases}  (8)

Let G_{t}^{⋆} = (N , w_{t}^{⋆}) and z_{1}, z_{2} ∈ N. Then one or both of the following hold:

w_{t}^{⋆}(z_{1}, z_{2}) = w(z_{1}, z_{2}),  (9)
w_{t}^{⋆}(z_{1}, z_{2}) ≥ ⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋.  (10)

Proof. By hypothesis and Definition 1, G_{t}^{⋆} ⊴ G_{t} ⊴ G. If (z_{1}, z_{2}) is not an arc in G_{t}^{⋆}, then w_{t}^{⋆}(z_{1}, z_{2}) = +∞; thus, as G_{t}^{⋆} ⊴ G, we also have w(z_{1}, z_{2}) = +∞ and hence property (9) holds. Suppose now that (z_{1}, z_{2}) is an arc in G_{t}^{⋆}. Then we can apply Lemma 2, so that there exists a simple path π = z_{1} ⋯ z_{2} in G_{t} such that w_{t}^{⋆}(z_{1}, z_{2}) = w_{t}(π).

Suppose first that w_{t}(π) = w(π). Then, as G is closed, by Lemma 1 we obtain w(π) ≥ w(z_{1}, z_{2}) so that w_{t}^{⋆}(z_{1}, z_{2}) ≥ w(z_{1}, z_{2}). However G_{t}^{⋆} ⊴ G so that w_{t}^{⋆}(z_{1}, z_{2}) ≤ w(z_{1}, z_{2}) and therefore property (9) holds.

Secondly, suppose that w_{t}(π) ≠ w(π). Then, by Equation (8), (i, \overline{ı}) must be an arc in π, so that

π = π_{1} :: (i \overline{ı}) :: π_{2},  (11)

where π_{1} = z_{1} ⋯ i, π_{2} = \overline{ı} ⋯ z_{2} are simple paths in G_{t} that do not contain the arc (i, \overline{ı}). Therefore, by Equation (8), we have w_{t}(π_{1}) = w(π_{1}), w_{t}(π_{2}) = w(π_{2}).

For π = j_{0} ⋯ j_{p} any path in a graph in N, let \overline{π} denote the path \overline{ȷ}_{p} ⋯ \overline{ȷ}_{0}. Consider (11) and let

π′_{1} = π_{1} :: (i \overline{ı}) :: \overline{π}_{1},  π′_{2} = \overline{π}_{2} :: (i \overline{ı}) :: π_{2}.

As G is an octagonal graph, we have w(π_{1}) = w(\overline{π}_{1}) and w(π_{2}) = w(\overline{π}_{2}) so that

w(π′_{1}) = 2w(π_{1}) + w(i, \overline{ı}),  w(π′_{2}) = 2w(π_{2}) + w(i, \overline{ı}).

As G is closed, by Lemma 1,

w(π′_{1}) ≥ w(z_{1}, \overline{z}_{1}),  w(π′_{2}) ≥ w(\overline{z}_{2}, z_{2})

so that

w(π_{1}) + \frac{w(i, \overline{ı})}{2} ≥ \frac{w(z_{1}, \overline{z}_{1})}{2},  w(π_{2}) + \frac{w(i, \overline{ı})}{2} ≥ \frac{w(\overline{z}_{2}, z_{2})}{2}.

Therefore

w_{t}(π) = w_{t}(π_{1}) + w_{t}(i, \overline{ı}) + w_{t}(π_{2})

= w(π_{1}) + \frac{w(i, \overline{ı}) − 1}{2} + w(π_{2}) + \frac{w(i, \overline{ı}) − 1}{2}

≥ \frac{w(z_{1}, \overline{z}_{1})}{2} − \frac{1}{2} + \frac{w(\overline{z}_{2}, z_{2})}{2} − \frac{1}{2}

≥ ⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋.

Hence, as w_{t}^{⋆}(z_{1}, z_{2}) = w_{t}(π), we obtain property (10), as required. ⊓ ⊔

The next result uses Lemmas 3 and 4 to derive a property relating the weight functions for a closed integer octagonal graph and its tight closure.

Lemma 5. Let G = (N , w) be a closed integer octagonal graph such that G^{T} = (N , w^{T}) := T-closure(G) is an octagonal graph and let z_{1}, z_{2} ∈ N. Then one or both of the following hold:

w^{T}(z_{1}, z_{2}) = w(z_{1}, z_{2});  (12)
w^{T}(z_{1}, z_{2}) = ⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋.  (13)

Proof. The proof is by contraposition; thus we assume that neither (12) nor (13) hold. Without loss of generality, let the graph G be ⊴-minimal in the set of all closed integer octagonal graphs such that T-closure(G) = G^{T} and for which neither (12) nor (13) hold. Clearly the negation of (12) implies that G ≠ G^{T}, so that G^{T} ◁ G.

As G is closed but not tightly closed, by Definitions 3 and 5, it follows that there exist i, j ∈ N such that either

(i) i = \overline{ȷ} and w(i, \overline{ı}) is odd; or (ii) property (7) holds and 2w(i, j) > w(i, \overline{ı}) + w(\overline{ȷ}, j).

Consider graph G_{1} = (N , w_{1}) where the weight function w_{1} is defined, for all h_{1}, h_{2} ∈ N, by

w_{1}(h_{1}, h_{2}) := \begin{cases}⌊\frac{w(i,\overline{ı})}{2}⌋ + ⌊\frac{w(\overline{ȷ},j)}{2}⌋, & if (h_{1}, h_{2}) ∈ \{(i, j), (\overline{ȷ}, \overline{ı})\}; \\ w(h_{1}, h_{2}), & otherwise. \end{cases}

Let G_{1}^{⋆} = closure(G_{1}). By Definitions 1, 3 and 5,

G^{T} ⊴ G_{1}^{⋆} ⊴ G_{1} ◁ G.  (14)

Thus T-closure(G_{1}^{⋆}) = G^{T} so that, by the minimality assumption on G, one or both of the following hold:

w^{T}(z_{1}, z_{2}) = w_{1}^{⋆}(z_{1}, z_{2});  (15)
w^{T}(z_{1}, z_{2}) = ⌊\frac{w_{1}^{⋆}(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w_{1}^{⋆}(\overline{z}_{2}, z_{2})}{2}⌋.  (16)

As G^{T} ≠ ⊥, by (14), G_{1} is consistent. Therefore, by construction, G_{1} is an integer octagonal graph. If property (i) holds for i, j, then Lemma 4 can be applied and, if property (ii) holds for i, j, then Lemma 3 can be applied and also, since property (7) holds, both w_{1}(z_{1}, \overline{z}_{1}) and w(\overline{z}_{2}, z_{2}) are even. Hence, letting G_{1}^{⋆} := (N , w_{1}^{⋆}), one or both of the following hold:

w_{1}^{⋆}(z_{1}, z_{2}) = w(z_{1}, z_{2});  (17)
w_{1}^{⋆}(z_{1}, z_{2}) ≥ ⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋.  (18)

Again by Lemmas 3 and 4,

w_{1}^{⋆}(z_{1}, \overline{z}_{1}) ≥ 2⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋,
w_{1}^{⋆}(\overline{z}_{2}, z_{2}) ≥ 2⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋;

since the lower bounds for w_{1}^{⋆}(z_{1}, \overline{z}_{1}) and w_{1}^{⋆}(\overline{z}_{2}, z_{2}) are even integers, we obtain

⌊\frac{w_{1}^{⋆}(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w_{1}^{⋆}(\overline{z}_{2}, z_{2})}{2}⌋ ≥ ⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋.  (19)

Suppose first that (15) and (17) hold. Then by transitivity we obtain (12), contradicting the contrapositive assumption for G.

If (15) and (18) hold, then it follows

w^{T}(z_{1}, z_{2}) ≥ ⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋.  (20)

On the other hand, if (16) holds, then, by (19), we obtain again property (20). However, by Definitions 3 and 5 we also have

w^{T}(z_{1}, z_{2}) ≤ ⌊\frac{w(z_{1}, \overline{z}_{1})}{2}⌋ + ⌊\frac{w(\overline{z}_{2}, z_{2})}{2}⌋.

By combining this inequality with (20) we obtain (13), contradicting the contrapositive assumption for G. ⊓ ⊔

Proof (of Theorem 2). Let G^{T} := T-closure(G). By definition of G_{T}, G_{T} ⊴ G so that T-closure(G_{T}) ⊴ G^{T}. As G_{T} is an octagonal graph, G_{T} is consistent, and hence G^{T} ≠ ⊥; let G^{T} = (N , w^{T}). Letting i, j ∈ N, to prove the result we need to show that w^{T}(i, j) = w_{T}(i, j). Let k_{ij} := ⌊w(i, \overline{ı})/2⌋ + ⌊w(\overline{ȷ}, j)/2⌋.

By Definitions 1, 3 and 5, it follows that both properties w^{T}(i, j) ≤ w(i, j) and w^{T}(i, j) ≤ k_{ij} hold so that, by definition of w_{T}, we have w^{T}(i, j) ≤ w_{T}(i, j). By Lemma 5, w^{T}(i, j) = w(i, j) and/or w^{T}(i, j) = k_{ij}. Therefore since, by definition, w_{T}(i, j) = min{w(i, j), k_{ij}}, we obtain w_{T}(i, j) ≤ w^{T}(i, j). ⊓ ⊔

It follows from the statement of Theorem 2 that an implementation based on it also needs to check the consistency of G_{T}. In principle, one could apply again a shortest-path closure procedure so as to check whether G_{T} contains some negative weight cycles. However, a much more efficient solution is obtained by the following result.

Theorem 3. Let G = (N , w) be a closed integer octagonal graph. Consider the graphs G_{t} = (N , w_{t}) and G_{T} = (N , w_{T}) where, for each i, j ∈ N,

w_{t}(i, j) := \begin{cases}2⌊w(i, j)/2⌋, & if j = \overline{ı}; \\ w(i, j), & otherwise; \end{cases}  (21)

w_{T}(i, j) := min\{w(i, j), ⌊\frac{w(i, \overline{ı})}{2}⌋ + ⌊\frac{w(\overline{ȷ}, j)}{2}⌋\}.  (22)

Suppose that, for all i ∈ N, w_{t}(i, \overline{ı}) + w_{t}(\overline{ı}, i) ≥ 0. Then G_{T} is an octagonal graph.

This result is a corollary of the following result proved in [15, Lemma 4].

Lemma 6. Let G = (N , w) be an integer octagonal graph with no negative weight cycles and G_{t} = (N , w_{t}), where w_{t} satisfies (21), have a negative weight cycle. Then there exists i, \overline{ı} ∈ N and a cycle π = (i · π_{1} · \overline{ı}) :: (\overline{ı} · π_{2} · i) in G such that w(π) = 0 and the weight of the shortest path in G from i to \overline{ı} is odd.

Proof (of Theorem 3). The proof is by contradiction; suppose G_{T} is not an octagonal graph; then by Definitions 1, 3 and 5, G_{T} is inconsistent. We show that G_{t} is also inconsistent. Again, we assume to the contrary that G_{t} is consistent and derive a contradiction. Let i, j ∈ N. By (21), we have w_{t}(i, j) ≤ w(i, j) and w_{t}(i, \overline{ı})/2 + w_{t}(\overline{ȷ}, j)/2 = k_{ij}, where k_{ij} := ⌊w(i, \overline{ı})/2⌋ + ⌊w(\overline{ȷ}, j)/2⌋. Letting S-closure(G_{t}) = (N , w_{t}^{S}), we have, by Definition 3, w_{t}^{S}(i, j) ≤ w_{t}(i, j) and w_{t}^{S}(i, j) ≤ w_{t}(i, \overline{ı})/2 + w_{t}(\overline{ȷ}, j)/2. Thus w_{t}^{S}(i, j) ≤ min(w(i, j), k_{ij}). As this holds for all i, j ∈ N, by (22), S-closure(G_{t}) ⊴ G_{T}, contradicting the assumption that G_{t} was consistent. Hence G_{t} is inconsistent and therefore contains a negative weight cycle.

By Lemma 6, there exists i, \overline{ı} ∈ N and a cycle π = (i · π_{1} · \overline{ı}) :: (\overline{ı} · π_{2} · i) in G such that w(π) = 0 and the weight of the shortest path in G from i to \overline{ı} is odd. As G is closed, w(i, \overline{ı}) ≤ w(i · π_{1} · \overline{ı}) and w(\overline{ı}, i) ≤ w(\overline{ı} · π_{2} · i). Thus w(i, \overline{ı}) + w(\overline{ı}, i) ≤ w(π) = 0. Moreover, (i\overline{ı}) is a path and hence the shortest path from i to \overline{ı} so that w(i\overline{ı}) is odd; hence, by (21), w(i, \overline{ı}) = w_{t}(i, \overline{ı}) + 1 and w(\overline{ı}, i) ≥ w_{t}(\overline{ı}, i). Therefore w_{t}(i, \overline{ı}) + w_{t}(\overline{ı}, i) < 0. ⊓ ⊔

function tight closure(var w [0 . . 2n − 1] [0 . . 2n − 1]) : bool { Initialization: O(n) } for i := 0 to 2n − 1 do w[i, i] := 0; { Classical Floyd-Warshall: O(n^{3}) } for k := 0 to 2n − 1 do

for i := 0 to 2n − 1 do

for j := 0 to 2n − 1 do

w[i, j] := min(w[i, j], w[i, k] + w[k, j]);

{ Check for ℚ-consistency: O(n) } for i := 0 to 2n − 2 step 2 do

if w[i, i] < 0 return false; { Tightening: O(n) } for i := 0 to 2n − 1 do

w[i, \overline{ı}] := 2 · floor(w[i, \overline{ı}]/2); { Check for ℤ-consistency: O(n) } for i := 0 to 2n − 2 step 2 do

if w[i, \overline{ı}] + w[\overline{ı}, i] < 0 return false; { Strong coherence: O(n^{2}) } for i := 0 to 2n − 1 do

for j := 0 to 2n − 1 do

w[i, j] := min(w[i, j], w[i, \overline{ı}]/2 + w[\overline{ȷ}, j]/2); return true;

Fig. 2. A O(n^{3}) tight closure algorithm for integer coherent graphs

The combination of the results stated in Theorems 2 and 3 (together with the well known result for rational consistency) leads to an O(n^{3}) tight closure algorithm, such as that given by the pseudo-code in Figure 2, that computes the tight closure of any (possibly inconsistent) coherent integer-weighted graph returning the Boolean value ‘true’ if and only if the input graph is ℤ-consistent.

5 Conclusion and Future Work

We have presented and fully justified an O(n^{3}) algorithm that computes the tight closure of a set of integer octagonal constraints. The algorithm —which is based on the extension to integer-weighted octagonal graphs of the one we proposed for rational-weighted octagonal graphs [2, 3]— and its proof of correctness means the issue about the possibility of computing the tight closure at a computational cost that is asymptotically not worse than the cost of computing all-pairs shortest paths is finally closed.

In the field of hardware and software verification, the integrality constraint that distinguishes integer-weighted from rational-weighted octagonal graphs can be seen as an abstraction of the more general imposition of a set of congruence relations. Such a set can be encoded by an element of a suitable abstract domain such as the non-relational congruence domain of [10] (that is, of the form x = a (mod b)), the weakly relational zone-congruence domain of [17] (that is, also allowing the form x − y = a (mod b)), the linear congruence domain of [11], and the more general fully relational rational grids domain developed in [1]. The combination of such domains with the abstract domain proposed in [2, 3] is likely to provide an interesting complexity-precision trade-off. Future work includes the investigation into such a combination, exploiting the ideas presented in this paper.

References

1. R. Bagnara, K. Dobson, P. M. Hill, M. Mundell, and E. Zaffanella. Grids: A domain for analyzing the distribution of numerical values. In G. Puebla, editor, Logic-based Program Synthesis and Transformation, 16th International Symposium, volume 4407 of Lecture Notes in Computer Science, pages 219–235, Venice, Italy, 2007. Springer-Verlag, Berlin.

2. R. Bagnara, P. M. Hill, E. Mazzi, and E. Zaffanella. Widening operators for weakly-relational numeric abstractions. In C. Hankin and I. Siveroni, editors, Static Analysis: Proceedings of the 12th International Symposium, volume 3672 of Lecture Notes in Computer Science, pages 3–18, London, UK, 2005. Springer-Verlag, Berlin.

3. R. Bagnara, P. M. Hill, E. Mazzi, and E. Zaffanella. Widening operators for weakly-relational numeric abstractions. Quaderno 399, Dipartimento di Matematica, Università di Parma, Italy, 2005. Available at http://www.cs.unipr.it/

Publications/.

4. R. Bagnara, P. M. Hill, and E. Zaffanella. The Parma Polyhedra Library: Toward a complete set of numerical abstractions for the analysis and verification of hardware and software systems. Quaderno 457, Dipartimento di Matematica, Università di

Parma, Italy, 2006. Available at http://www.cs.unipr.it/Publications/. Also
published as arXiv:cs.MS/0612085, available from http://arxiv.org/.

5. V. Balasundaram and K. Kennedy. A technique for summarizing data access and its use in parallelism enhancing transformations. In B. Knobe, editor, Proceedings of the ACM SIGPLAN’89 Conference on Programming Language Design and Implementation (PLDI), volume 24(7) of ACM SIGPLAN Notices, pages 41–53, Portland, Oregon, USA, 1989. ACM Press.

6. T. Ball, B. Cook, S. K. Lahiri, and L. Zhang. Zapato: Automatic theorem proving for predicate abstraction refinement. In R. Alur and D. Peled, editors, Computer Aided Verification: Proceedings of the 16th International Conference, volume 3114 of Lecture Notes in Computer Science, pages 457–461, Boston, MA, USA, 2004. Springer-Verlag, Berlin.

7. T. H. Cormen, T. E. Leiserson, and R. L. Rivest. Introduction to Algorithms. The MIT Press, Cambridge, MA, 1990.

8. P. Cousot and R. Cousot. Abstract interpretation: A unified lattice model for static analysis of programs by construction or approximation of fixpoints. In Proceedings of the Fourth Annual ACM Symposium on Principles of Programming Languages, pages 238–252, New York, 1977. ACM Press.

9. P. Cousot, R. Cousot, J. Feret, L. Mauborgne, A. Miné, D. Monniaux, and X. Rival. The ASTRÉE analyzer. In M. Sagiv, editor, Programming Languages and Systems, Proceedings of the 14th European Symposium on Programming, volume 3444 of Lecture Notes in Computer Science, pages 21–30, Edinburgh, UK, 2005. Springer-Verlag, Berlin.

10. P. Granger. Static analysis of arithmetical congruences. International Journal of Computer Mathematics, 30:165–190, 1989.

11. P. Granger. Static analysis of linear congruence equalities among variables of a program. In S. Abramsky and T. S. E. Maibaum, editors, TAPSOFT’91: Proceedings of the International Joint Conference on Theory and Practice of Software Development, Volume 1: Colloquium on Trees in Algebra and Programming (CAAP’91), volume 493 of Lecture Notes in Computer Science, pages 169–192, Brighton, UK, 1991. Springer-Verlag, Berlin.

12. W. Harvey and P. J. Stuckey. A unit two variable per inequality integer constraint solver for constraint logic programming. In M. Patel, editor, ACSC’97: Proceedings of the 20th Australasian Computer Science Conference, volume 19, pages 102–111. Australian Computer Science Communications, 1997.

13. J. Jaffar, M. J. Maher, P. J. Stuckey, and R. H. C. Yap. Beyond finite domains. In A. Borning, editor, Principles and Practice of Constraint Programming: Proceedings of the Second International Workshop, volume 874 of Lecture Notes in Computer Science, pages 86–94, Rosario, Orcas Island, Washington, USA, 1994. Springer-Verlag, Berlin.

14. J. C. Lagarias. The computational complexity of simultaneous Diophantine approximation problems. SIAM Journal on Computing, 14(1):196–209, 1985.

15. S. K. Lahiri and M. Musuvathi. An efficient decision procedure for UTVPI constraints. In B. Gramlich, editor, Frontiers of Combining Systems: Proceedings of the 5th International Workshop, FroCoS 2005, volume 3717 of Lecture Notes in Artificial Intelligence, pages 168–183, Vienna, Austria, 2005. Springer-Verlag, Berlin.

16. A. Miné. The octagon abstract domain. In Proceedings of the Eighth Working Conference on Reverse Engineering (WCRE’01), pages 310–319, Stuttgart, Germany, 2001. IEEE Computer Society Press.

17. A. Miné. A few graph-based relational numerical abstract domains. In M. V. Hermenegildo and G. Puebla, editors, Static Analysis: Proceedings of the 9th International Symposium, volume 2477 of Lecture Notes in Computer Science, pages 117–132, Madrid, Spain, 2002. Springer-Verlag, Berlin.

18. A. Miné. Weakly Relational Numerical Abstract Domains. PhD thesis, École Polytechnique, Paris, France, March 2005.

19. A. Miné. The octagon abstract domain. Higher-Order and Symbolic Computation, 19(1):31–100, 2006.

20. G. Nelson and D. C. Oppen. Fast decision algorithms based on Union and Find. In Proceedings of the 18th Annual Symposium on Foundations of Computer Science (FOCS’77), pages 114–119, Providence, RI, USA, 1977. IEEE Computer Society Press. The journal version of this paper is [21].

21. G. Nelson and D. C. Oppen. Fast decision procedures based on congruence closure. Journal of the ACM, 27(2):356–364, 1980. An earlier version of this paper is [20].

22. V. R. Pratt. Two easy theories whose combination is hard. Memo sent to Nelson and Oppen concerning a preprint of their paper [20], September 1977.

23. A. Venet and G. Brat. Precise and efficient static array bound checking for large embedded C programs. In Proceedings of the ACM SIGPLAN 2004 Conference on Programming Language Design and Implementation (PLDI’04), pages 231–242, Washington, DC, USA, 2004. ACM Press.