Algorithm Search⌘K

Definitionadvanced

Convex polyhedra abstract domain

Also called Cousot-Halbwachs polyhedra, linear relation analysis.

A relational domain of conjunctions of linear inequalities between variables, precise but exponential in the worst case.

The polyhedra domain describes the numeric names of a program by a conjunction of linear inequalities a1x1+⋯+avxv≤ba_1 x_1 + \cdots + a_v x_v \le b with rational coefficients, such as y=2xy = 2x and 0≤x≤100 \le x \le 10. The set of points that satisfy them is a convex polyhedron. It is the most precise of the classic numeric domains: it keeps every linear relation that holds on all paths through a join. Patrick Cousot and Nicolas Halbwachs introduced it in 1978, and it is also called linear relation analysis. Its cost is the price. A polyhedron is kept in two forms at once, as inequalities and as generators, and the size of either form can be exponential in the number of names vv.

Definition

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

Polyhedra. A convex polyhedron in Qv\mathbb{Q}^v is a set P={ x:Ax≤b }P = \{\, x : Ax \le b \,\} for a rational matrix AA and vector bb. An equality is a pair of inequalities. The elements of the domain are the polyhedra, with the empty one as ⊥\bot and Qv\mathbb{Q}^v as ⊤\top. For a program over integers, γ(P)=P∩Zv\gamma(P) = P \cap \mathbb{Z}^v. This is sound, but integer facts that need rounding, such as 2x=12x = 1 being impossible, are lost unless the analyzer adds them.

The double description. By the Minkowski-Weyl theorem, every polyhedron also has a generator form

P={ ∑iλipi+∑jμjrj+∑kνkℓk : λi,μj≥0, ∑iλi=1, νk∈Q },P = \Bigl\{\, \sum_i \lambda_i p_i + \sum_j \mu_j r_j + \sum_k \nu_k \ell_k \ :\ \lambda_i, \mu_j \ge 0,\ \textstyle\sum_i \lambda_i = 1,\ \nu_k \in \mathbb{Q} \,\Bigr\},

with points pip_i, rays rjr_j and lines ℓk\ell_k. A double description of PP is a pair (a constraint system CC, a generator system GG) that describe the same polyhedron. The name and the method come from Motzkin, Raiffa, Thompson and Thrall (1953). Each operation uses the form in which it is easy, and the conversion from one form to the other is done by Chernikova's algorithm, which adds one constraint (or one generator) at a time and keeps both forms in step. A system is minimal when no constraint (or generator) can be dropped; for a polyhedron of full dimension the minimal constraint system is unique up to scaling, one inequality per facet.

Order, meet and join.

  • P⊑QP \sqsubseteq Q when every generator of PP satisfies every constraint of QQ: points satisfy them, rays rr satisfy a⋅r≤0a \cdot r \le 0, and lines ℓ\ell satisfy a⋅ℓ=0a \cdot \ell = 0. This is exact inclusion.
  • P⊓QP \sqcap Q is the union of the two constraint systems. It is exact.
  • P⊔QP \sqcup Q is the union of the two generator systems. It gives the closed convex hull of P∪QP \cup Q, the least polyhedron that contains both. A union of two polyhedra is not convex in general, so the join loses precision, but it is the best that the domain can do.

Abstraction. There is no best abstraction in general. The disk x2+y2≤1x^2 + y^2 \le 1 is contained in polyhedra that come closer and closer to it, and no least one exists; the Galois connection page shows this. So the domain is used with a concretization only, and soundness is proved operation by operation.

Transfer functions.

  • Guard a⋅x≤ba \cdot x \le b: add the constraint (a meet). Exact. A strict guard a⋅x<ba \cdot x < b over integer coefficients and integer names is the same as a⋅x≤b−1a \cdot x \le b - 1. A nonlinear guard is ignored or replaced by a linear consequence.
  • Forget xix_i: add the line eie_i to the generators. On the constraint side this is Fourier-Motzkin elimination of xix_i, which can square the number of constraints in one step.
  • Assignment xi←a⋅x+cx_i \leftarrow a \cdot x + c with ai≠0a_i \ne 0: the map is invertible, so substitute xi=(xi′−∑j≠iajxj−c)/aix_i = (x_i' - \sum_{j \ne i} a_j x_j - c)/a_i in the constraints, or apply the map to the generators. Exact.
  • Assignment xi←a⋅x+cx_i \leftarrow a \cdot x + c with ai=0a_i = 0: forget xix_i, then add the equality xi=a⋅x+cx_i = a \cdot x + c. Exact.
  • Any other assignment: forget xix_i, then add what is known, for example interval bounds. Sound.

Widening. The domain has infinite ascending chains, so it needs a widening. Let CPC_P be a minimal constraint system of PP. The standard widening of Cousot and Halbwachs, as completed by Halbwachs (1979), is

P∇Q={ c∈CP:Q satisfies c } ∪ { c∈CQ:some c′∈CP can be replaced by c without changing P }.P \mathbin{\nabla} Q = \{\, c \in C_P : Q \text{ satisfies } c \,\} \ \cup\ \{\, c \in C_Q : \text{some } c' \in C_P \text{ can be replaced by } c \text{ without changing } P \,\}.

The first part keeps the constraints of PP that are stable. The second part was added because a polyhedron of lower dimension has many minimal systems: its equalities can be written in many ways, and the first part alone would give results that depend on the choice. A strict step either raises the dimension of the polyhedron or drops at least one constraint, which can happen only finitely often, so the widened chain stops. Bagnara, Hill, Ricci and Zaffanella (2005) define widenings that are never less precise than this one. Delayed widening (join for the first few steps) and widening with thresholds are often used with polyhedra.

Cost. Meet, guard and the constraint side of inclusion are linear in the size of the constraint system; join and forget are linear in the size of the generator system. Inclusion costs O(∣GP∣⋅∣CQ∣⋅v)O(|G_P| \cdot |C_Q| \cdot v). The conversion between the forms is the expensive part, and so is keeping the systems minimal. Each form can be exponential in vv while the other is small, as the examples show. The total cost of an analysis is therefore exponential in the worst case, and in practice analyzers split the names into small groups that are known to be related, and keep one polyhedron per group.

Examples and non-examples

A loop with a linear relation.

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

Write PkP_k for the value at head after kk steps and FF for the value computed from entry and the end of body.

step value at head how
0 the point (0,0)(0, 0) from entry
1, before widening the segment y=2xy = 2x, 0≤x≤10 \le x \le 1 join of (0,0)(0, 0) and (1,2)(1, 2)
1, after widening y=2xy = 2x, x≥0x \ge 0 standard widening, see below
2 stable: FF gives y=2xy = 2x, 0≤x≤100 \le x \le 10 the guard x≤9x \le 9, then +1+1 and +2+2
exit y=2xy = 2x, x≥10x \ge 10 the guard x≥10x \ge 10
exit, after one decreasing step x=10x = 10, y=20y = 20 head becomes FF, so 0≤x≤100 \le x \le 10

At step 1, P0P_0 is a point. If its minimal system is written as x≤0x \le 0, x≥0x \ge 0, y≤0y \le 0, y≥0y \ge 0, the first part of the widening keeps only x≥0x \ge 0 and y≥0y \ge 0. The second part adds y≤2xy \le 2x and y≥2xy \ge 2x from the segment, because each can replace y≤0y \le 0 or y≥0y \ge 0 in the system of the point without changing it. So the standard widening keeps y=2xy = 2x. With the first part alone, the head would become the quarter plane x≥0x \ge 0, y≥0y \ge 0, and the exit would get only x=10x = 10 and y≥2y \ge 2 after one decreasing step (a narrowing of the simplest kind). A delayed widening, which joins once before it widens, also keeps y=2xy = 2x, since the segment of step 1 has the stable equality y=2xy = 2x in every minimal system. Neither intervals nor octagons can express y=2xy = 2x; octagons would keep only bounds such as y−x≥0y - x \ge 0.

The cross-polytope: exponentially many constraints. Join the 2v2v points ±e1,…,±ev\pm e_1, \ldots, \pm e_v. The result is the cross-polytope

Xv={ x:∣x1∣+⋯+∣xv∣≤1 }={ x:s⋅x≤1 for every s∈{−1,1}v }.X_v = \{\, x : |x_1| + \cdots + |x_v| \le 1 \,\} = \{\, x : s \cdot x \le 1 \text{ for every } s \in \{-1, 1\}^v \,\}.

Each of the 2v2^v inequalities s⋅x≤1s \cdot x \le 1 defines a facet: it holds with equality at the vv points s1e1,…,svevs_1 e_1, \ldots, s_v e_v, which are affinely independent, and XvX_v has full dimension. Different sign vectors give different facets. So the minimal constraint system has exactly 2v2^v rows, while the generator system has 2v2v points. An analysis that joins 2v2v simple states and then applies one guard must convert to constraints and write 2v2^v rows.

The hypercube: exponentially many generators. The box [0,1]v[0, 1]^v has 2v2v constraints and 2v2^v vertices, each a point of every generator system. An analysis that adds 2v2v interval guards and then joins the result with one point must write 2v2^v points. Together the two families show that neither form is small in the worst case, and that converting between them takes exponential time just to write the output.

Not a polyhedron. The set { (x,y):y=x2 }\{\, (x, y) : y = x^2 \,\} and the set { x:x even }\{\, x : x \text{ even} \,\} have no exact polyhedral description. The first one is not convex; its best linear facts on a bounded range come from the join of sample points. The second needs a congruence domain, which is often combined with polyhedra by a reduced product.

Not a join. Taking the union of the two constraint systems as the join gives the intersection, which is unsound. Taking only the constraints common to both systems (as written) is sound but depends on how the constraints are written: x≤1x \le 1 in one state and 2x≤22x \le 2 in the other would be dropped.

References

  1. Patrick Cousot and Nicolas Halbwachs, Automatic discovery of linear restraints among variables of a program, POPL 1978, pages 84 to 96, the polyhedra domain, the convex hull as join, the transfer functions for linear assignments and tests, and the widening that keeps the stable constraints
  2. Nicolas Halbwachs, Détermination automatique de relations linéaires vérifiées par les variables d'un programme, thèse de troisième cycle, Université scientifique et médicale de Grenoble, 1979, the standard widening, with the constraints of the new polyhedron that can replace a constraint of the old one, and the use of the double description
  3. T. S. Motzkin, H. Raiffa, G. L. Thompson and R. M. Thrall, The double description method, in H. W. Kuhn and A. W. Tucker (eds.), Contributions to the Theory of Games II, Annals of Mathematics Studies 28, Princeton University Press, 1953, pages 51 to 73, the method that keeps a cone both as a system of inequalities and as a set of generating rays, and adds one inequality at a time
  4. Roberto Bagnara, Patricia M. Hill, Elisa Ricci and Enea Zaffanella, Precise widening operators for convex polyhedra, Science of Computer Programming 58(1-2), 2005, pages 28 to 56, the statement of the standard widening, its termination, and a family of widenings that are never less precise
  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/FC44XR/text.yaml