Algorithm Search⌘K

Definitionadvanced

Octagon abstract domain

Also called octagons.

A relational domain of constraints plus or minus x plus or minus y <= c, kept in a difference-bound matrix with cubic time closure.

The octagon domain describes the numeric names of a program by constraints of the form ±x±y≤c\pm x \pm y \le c, such as x+y≤10x + y \le 10 or x−y≤3x - y \le 3, together with bounds ±x≤c\pm x \le c on one name. In the plane, such a set is a polygon with at most eight sides, which gives the domain its name. It keeps relations between names that the interval domain loses, but it costs much less than the polyhedra domain: O(v2)O(v^2) space and O(v3)O(v^3) time for its most expensive operation, for vv names. Antoine Miné introduced it in 2001. An octagon is stored as a difference-bound matrix over two copies of each name, one for +x+x and one for −x-x, so the closure of the matrix is a shortest-path computation followed by one extra step.

Definition

The order is the Cousot order: lower is more precise, and ⊥\bot means that no state reaches the point. On the dataflow pages that use Kildall's convention the order is the other way round. The general framework is on the abstract domain page.

Octagonal constraints. Let the names be x0,…,xv−1x_0, \ldots, x_{v-1}. An octagonal constraint is ±xi±xj≤c\pm x_i \pm x_j \le c with i≠ji \ne j, or ±xi≤c\pm x_i \le c. A bound on one name is the same as ±xi±xi≤2c\pm x_i \pm x_i \le 2c, so it needs no special case below.

The doubled names. For each name xix_i take two forms, w2i=xiw_{2i} = x_i and w2i+1=−xiw_{2i+1} = -x_i. For an index aa write aˉ\bar a for the index of the other form of the same name, so aˉ=a⊕1\bar a = a \oplus 1 (flip the last bit) and waˉ=−waw_{\bar a} = -w_a. Each octagonal constraint becomes one or two differences wa−wb≤cw_a - w_b \le c:

constraint differences
xi−xj≤cx_i - x_j \le c w2i−w2j≤cw_{2i} - w_{2j} \le c and w2j+1−w2i+1≤cw_{2j+1} - w_{2i+1} \le c
xi+xj≤cx_i + x_j \le c w2i−w2j+1≤cw_{2i} - w_{2j+1} \le c and w2j−w2i+1≤cw_{2j} - w_{2i+1} \le c
−xi−xj≤c-x_i - x_j \le c w2i+1−w2j≤cw_{2i+1} - w_{2j} \le c and w2j+1−w2i≤cw_{2j+1} - w_{2i} \le c
xi≤cx_i \le c w2i−w2i+1≤2cw_{2i} - w_{2i+1} \le 2c
−xi≤c-x_i \le c w2i+1−w2i≤2cw_{2i+1} - w_{2i} \le 2c

The matrix. An octagon is ⊥\bot or a 2v×2v2v \times 2v matrix mm with entries in Z∪{+∞}\mathbb{Z} \cup \{+\infty\} (or Q∪{+∞}\mathbb{Q} \cup \{+\infty\} for rational names). The entry m[a][b]m[a][b] is a bound on wa−wbw_a - w_b, so mm is a difference-bound matrix over the 2v2v forms. Its meaning is

γ(m)={ x∈Zv:wa−wb≤m[a][b] for all a,b, where w2i=xi, w2i+1=−xi }.\gamma(m) = \{\, x \in \mathbb{Z}^v : w_a - w_b \le m[a][b] \text{ for all } a, b, \text{ where } w_{2i} = x_i,\ w_{2i+1} = -x_i \,\}.

The two differences in one row of the table are the same fact, since wa−wb=wbˉ−waˉw_a - w_b = w_{\bar b} - w_{\bar a}. A matrix is coherent when m[a][b]=m[bˉ][aˉ]m[a][b] = m[\bar b][\bar a] for all a,ba, b. Every operation below keeps matrices coherent, so half the matrix can be stored.

Strong closure. Many matrices have the same meaning. The difference-bound matrix page computes the tightest bounds of a DBM as all-pairs shortest paths with Floyd-Warshall. For octagons this is not enough, because the forms are linked by waˉ=−waw_{\bar a} = -w_a. From x≤1x \le 1 and y≤2y \le 2 follows x+y≤3x + y \le 3, but no path in the graph of the matrix gives it. One more rule is needed. The entry m[a][aˉ]m[a][\bar a] bounds wa−waˉ=2waw_a - w_{\bar a} = 2w_a, and m[bˉ][b]m[\bar b][b] bounds −2wb-2w_b, so

wa−wb≤12(m[a][aˉ]+m[bˉ][b]).w_a - w_b \le \tfrac{1}{2}\bigl(m[a][\bar a] + m[\bar b][b]\bigr).

The strong closure m∙m^\bullet is computed in two steps:

  1. Run Floyd-Warshall on mm, as on a DBM with 2v2v vertices. If some diagonal entry becomes negative, the octagon is empty, and the result is ⊥\bot.
  2. For all a,ba, b, set m[a][b]←min⁡(m[a][b],12(m[a][aˉ]+m[bˉ][b]))m[a][b] \leftarrow \min\bigl(m[a][b], \tfrac{1}{2}(m[a][\bar a] + m[\bar b][b])\bigr).

Miné's first algorithm applied the strengthening of step 2 inside every round of Floyd-Warshall. Bagnara, Hill and Zaffanella (2009) proved that one pass at the end gives the same result. Step 1 costs (2v)3=8v3(2v)^3 = 8v^3 updates and step 2 costs 4v24v^2, so the closure takes O(v3)O(v^3) time. For a non-empty octagon over the rationals, m∙[a][b]=sup⁡{ wa−wb:x∈γ(m) }m^\bullet[a][b] = \sup\{\, w_a - w_b : x \in \gamma(m) \,\} for every pair: each entry is the best bound that the octagon implies. So two octagons have the same meaning if and only if they have the same strong closure, and the strong closure is a normal form.

Integers. Over Z\mathbb{Z} the strong closure can miss facts, because 2x≤32x \le 3 means x≤1x \le 1. The tight closure rounds each unary bound m[a][aˉ]m[a][\bar a] down to an even number between steps 1 and 2. The integer octagon is then empty exactly when step 1 finds a negative diagonal entry or, after the rounding, some m[a][aˉ]+m[aˉ][a]<0m[a][\bar a] + m[\bar a][a] < 0. Bagnara, Hill and Zaffanella (2008) showed that this also takes O(v3)O(v^3) time. This is notable, because integer linear constraints in general are NP-hard to solve.

Order, join and meet. Let mm and nn be octagons that are not ⊥\bot.

  • m⊑nm \sqsubseteq n when m∙[a][b]≤n[a][b]m^\bullet[a][b] \le n[a][b] for all a,ba, b. Over Q\mathbb{Q} this is exact: it holds if and only if γ(m)⊆γ(n)\gamma(m) \subseteq \gamma(n). Only the left side needs to be closed. Over Z\mathbb{Z} it is exact only with the tight closure in place of m∙m^\bullet: m={2x≤3}m = \{2x \le 3\} and n={x≤1}n = \{x \le 1\} have the same integer points, but m∙[0][1]=3>2=n[0][1]m^\bullet[0][1] = 3 > 2 = n[0][1].
  • m⊔nm \sqcup n is the entry-wise maximum of m∙m^\bullet and n∙n^\bullet. Over Q\mathbb{Q} it is the least octagon that contains both, so the join is the best one. Over Z\mathbb{Z} this needs the tight closure of both arguments: with 2x≤32x \le 3 and 2y≤32y \le 3 on one side and x≤1x \le 1 and y≤1y \le 1 on the other, the strong closures give x+y≤3x + y \le 3, while both sides have x+y≤2x + y \le 2. The result is again strongly closed. The maximum of matrices that are not closed is still sound, but it can lose relations (see the examples).
  • m⊓nm \sqcap n is the entry-wise minimum. It is exact: γ(m⊓n)=γ(m)∩γ(n)\gamma(m \sqcap n) = \gamma(m) \cap \gamma(n). It is not closed in general.

Abstraction. Over Z\mathbb{Z}, the map α(S)[a][b]=sup⁡{ wa−wb:x∈S }\alpha(S)[a][b] = \sup\{\, w_a - w_b : x \in S \,\} is a Galois connection between sets of integer points and matrices. It is not a Galois insertion on all matrices, because many matrices share a meaning; on tightly closed matrices plus ⊥\bot it is. Over the rationals, with rational bounds, there is no best abstraction in general: the sup of x+yx + y over the rational points of the disk x2+y2≤1x^2 + y^2 \le 1 is 2\sqrt 2, and there is no least rational bound above it.

Transfer functions. On a closed matrix:

  • xi←xi+cx_i \leftarrow x_i + c is exact. Add cc to the bounds of w2i−wbw_{2i} - w_b, subtract it from those of w2i+1−wbw_{2i+1} - w_b, and do the reverse on column 2i2i and 2i+12i+1. Cost O(v)O(v).
  • xi←cx_i \leftarrow c, xi←xj+cx_i \leftarrow x_j + c and xi←−xj+cx_i \leftarrow -x_j + c are exact. Forget xix_i (set its rows and columns to +∞+\infty, except the diagonal), then add the new constraints, for example xi−xj≤cx_i - x_j \le c and xj−xi≤−cx_j - x_i \le -c. Cost O(v2)O(v^2), with the incremental closure for the few new constraints.
  • Any other assignment forgets xix_i and then bounds it by interval arithmetic on the bounds of the operands. This is sound but not best.
  • A guard ±xi±xj≤c\pm x_i \pm x_j \le c is exact: take the meet with the constraint and close again, in O(v2)O(v^2) time for one constraint. Other guards, such as x<2yx < 2y, are applied through their interval bounds or ignored.

Widening and narrowing. The widening keeps the stable bounds and drops the others:

(m∇n)[a][b]={m[a][b]if n[a][b]≤m[a][b],+∞otherwise.(m \mathbin{\nabla} n)[a][b] = \begin{cases} m[a][b] & \text{if } n[a][b] \le m[a][b], \\ +\infty & \text{otherwise.} \end{cases}

The right argument may be closed, and should be, for precision. The left argument must be the previous widened iterate exactly as it is, and must not be closed. Each strict widening step then turns at least one finite entry into +∞+\infty, so a chain of widened iterates that starts from a matrix has at most 4v24v^2 strict steps. Closing the left argument can make +∞+\infty entries finite again, and Miné (2006) gives a sequence where the iteration then never stops. The narrowing replaces only the +∞+\infty entries: (mΔn)[a][b]=n[a][b](m \mathbin{\Delta} n)[a][b] = n[a][b] if m[a][b]=+∞m[a][b] = +\infty, and m[a][b]m[a][b] otherwise.

Cost. An octagon takes 4v24v^2 entries, or about 2v22v^2 with coherence. Closure, and so an exact inclusion test or a join on unclosed inputs, costs O(v3)O(v^3). Join, meet, widening and the simple transfer functions cost O(v2)O(v^2) on closed inputs.

Examples and non-examples

Strengthening. Take x=x0x = x_0 and y=x1y = x_1, with x≤1x \le 1 and y≤2y \le 2. Then m[0][1]=2m[0][1] = 2 and m[2][3]=4m[2][3] = 4, and all other entries off the diagonal are +∞+\infty. Floyd-Warshall finds no new bound, since no path leads from form 0 to form 3. Step 2 gives m[0][3]=12(m[0][1]+m[2][3])=3m[0][3] = \tfrac{1}{2}(m[0][1] + m[2][3]) = 3, which is w0−w3=x+y≤3w_0 - w_3 = x + y \le 3.

An absolute value. The interval domain page analyzes this program, where the parameter x has the precondition −5≤x≤7-5 \le x \le 7:

entry:
  t = x < 0
  br t neg pos
neg:
  y = 0 - x
  jump join
pos:
  y = x
  jump join
join:
  d = y - x
  ret d

In neg the octagon holds −5≤x≤−1-5 \le x \le -1 and x+y=0x + y = 0; in pos it holds 0≤x≤70 \le x \le 7 and y−x=0y - x = 0. After closure each branch bounds all four sums and differences, and the join takes the larger bound of each.

bound neg pos join
xx [−5,−1][-5, -1] [0,7][0, 7] [−5,7][-5, 7]
yy [1,5][1, 5] [0,7][0, 7] [0,7][0, 7]
y−xy - x [2,10][2, 10] [0,0][0, 0] [0,10][0, 10]
x+yx + y [0,0][0, 0] [0,14][0, 14] [0,14][0, 14]

So d ∈[0,10]\in [0, 10], and the true set is {0,2,…,10}\{0, 2, \ldots, 10\}. The intervals give d∈[−7,12]d \in [-7, 12], because they lose y≥xy \ge x and y≥−xy \ge -x.

A loop with two counters.

entry:
  x = 0
  y = 10
  jump head
head:
  t = x < 10
  br t body exit
body:
  x = x + 1
  y = y - 1
  jump head
exit:
  ret y

The analysis widens at head, the head of the loop in the weak topological ordering. The guard on the edge to body adds x≤9x \le 9; the guard on the edge to exit adds x≥10x \ge 10. Both assignments in body are exact.

step point xx yy x+yx + y y−xy - x
1 head [0,0][0, 0] [10,10][10, 10] [10,10][10, 10] [10,10][10, 10]
1 end of body [1,1][1, 1] [9,9][9, 9] [10,10][10, 10] [8,8][8, 8]
2 head, before widening [0,1][0, 1] [9,10][9, 10] [10,10][10, 10] [8,10][8, 10]
2 head, after widening [0,+∞][0, +\infty] [−∞,10][-\infty, 10] [10,10][10, 10] [−∞,10][-\infty, 10]
2 end of body [1,10][1, 10] [0,9][0, 9] [10,10][10, 10] [−10,8][-10, 8]
3 head stable
exit [10,+∞][10, +\infty] [−∞,0][-\infty, 0] [10,10][10, 10] [−∞,−10][-\infty, -10]
head, after narrowing [0,10][0, 10] [0,10][0, 10] [10,10][10, 10] [−10,10][-10, 10]
exit, after narrowing [10,10][10, 10] [0,0][0, 0] [10,10][10, 10] [−10,−10][-10, -10]

The relation x+y=10x + y = 10 is stable from the start, so the widening keeps it. With it, the guard x≤9x \le 9 in the body gives y≥1y \ge 1, and the exit gets y=0y = 0 after one narrowing step. Intervals alone get y∈[−∞,10]y \in [-\infty, 10] at exit, even with narrowing, because nothing bounds yy from below.

A join without closure. In the loop above, the state after entry holds only the unary bounds x=0x = 0 and y=10y = 10. If the analyzer takes the entry-wise maximum with the state x=1x = 1, y=9y = 9 without closing either matrix first, the entries for x+yx + y are +∞+\infty in both, so the result is the box [0,1]×[9,10][0, 1] \times [9, 10] and the relation x+y=10x + y = 10 is gone. The join must close its arguments.

Not octagonal. The constraint x≤2yx \le 2y has a coefficient 2, and x+y+z≤1x + y + z \le 1 has three names. An octagon can only keep their consequences of the form ±x±y≤c\pm x \pm y \le c. The polyhedra domain keeps them exactly.

A widening that closes its left argument. Using (m∙)∇n(m^\bullet) \mathbin{\nabla} n in place of m∇nm \mathbin{\nabla} n looks harmless, since m∙m^\bullet has the same meaning as mm. It is not a widening: an entry dropped to +∞+\infty by one step can come back as a finite sum of other entries after the closure, and Miné (2006) gives an increasing chain on which the iterates then never stabilize.

  • Difference-bound matrix: the zones x−y≤cx - y \le c, used for the clocks of timed automata. An octagon is a DBM over the 2v2v forms, with coherence and the extra strengthening step.
  • Difference constraints: systems xj−xi≤cx_j - x_i \le c solved by shortest paths, the graph view behind both DBMs and octagons.
  • Interval domain: the octagons with only unary constraints; an octagon analysis costs about v2v^2 times more per operation.
  • Polyhedra domain: any linear constraints, more precise and exponential in the worst case. Octagons sit between intervals and polyhedra.
  • Reduced product: octagons are often combined with other domains, such as congruences, by a reduced product.
  • Widening operator and narrowing operator: the general definitions behind the octagon widening and narrowing.

References

  1. Antoine Miné, The octagon abstract domain, Higher-Order and Symbolic Computation 19(1), 2006, pages 31 to 100, the encoding of octagonal constraints in a difference-bound matrix over the positive and negative forms of each name, coherence, strong closure, the lattice operations, the transfer functions, and the widening whose left argument must not be closed
  2. Antoine Miné, The octagon abstract domain, Proceedings of the Eighth Working Conference on Reverse Engineering (WCRE 2001), IEEE, 2001, the first presentation of the domain and of its cubic closure
  3. Roberto Bagnara, Patricia M. Hill and Enea Zaffanella, Weakly-relational shapes for numeric abstractions: improved algorithms and proofs of correctness, Formal Methods in System Design 35(3), 2009, pages 279 to 323, the proof that one strengthening pass after the shortest-path closure gives the strong closure, and the semantic view of octagons as shapes
  4. Roberto Bagnara, Patricia M. Hill and Enea Zaffanella, An improved tight closure algorithm for integer octagonal constraints, VMCAI 2008, LNCS 4905, pages 8 to 21, the tight closure of integer octagons in cubic time, with the rounding of the unary bounds and the test for emptiness
  5. Xavier Rival and Kwangkeun Yi, Introduction to Static Analysis, An Abstract Interpretation Perspective, MIT Press, 2020, Chapter 3 (relational abstract domains for numeric states, among them octagons and convex polyhedra)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/RFWPGY/text.yaml