Algorithm Search⌘K

Definitioncore

Widening operator

Also called widening.

An upper bound operator whose iteration stabilizes in finitely many steps, used to force fixed-point iteration on infinite height domains to end.

A widening operator ∇\nabla takes the current approximation xx of a loop invariant and a new value yy, and returns an upper bound of both that grows in big jumps, so that any chain of widened values stops after finitely many steps. It lets an analysis over a domain of infinite height, such as intervals, reach an element xx with F♯(x)⊑xF^\sharp(x) \sqsubseteq x in a few steps, where plain iteration would run forever. A widening is not a join: it is not monotone, not commutative, and it gives up precision on purpose.

Definition

The setting is an abstract domain (A,⊑)(A, \sqsubseteq) in the Cousot order (lower is more precise) and an abstract function F♯:A→AF^\sharp : A \to A, for example the abstract transfer function of a loop. The general idea and the interval widening are on the abstract interpretation page; this page gives the definition, the proofs and the properties.

A widening is a map ∇:A×A→A\nabla : A \times A \to A with two properties.

  1. Upper bound. For all x,yx, y: x⊑x∇yx \sqsubseteq x \nabla y and y⊑x∇yy \sqsubseteq x \nabla y.
  2. Stabilization. For every increasing chain y0⊑y1⊑y2⊑⋯y_0 \sqsubseteq y_1 \sqsubseteq y_2 \sqsubseteq \cdots, the chain x0=y0x_0 = y_0, xk+1=xk∇yk+1x_{k+1} = x_k \nabla y_{k+1} is eventually stationary: there is a KK with xk=xKx_k = x_K for all k≥Kk \ge K.

Some texts require property 2 for every sequence (yk)(y_k), increasing or not. That stronger form is needed when F♯F^\sharp is not monotone. The interval widening has it: each bound of xkx_k can move only once, to an infinity, whatever yk+1y_{k+1} is.

The widened iteration. Start from z0=⊥z_0 = \bot. At step kk, if F♯(zk)⊑zkF^\sharp(z_k) \sqsubseteq z_k, stop and return zkz_k. Otherwise set zk+1=zk∇F♯(zk)z_{k+1} = z_k \nabla F^\sharp(z_k).

Theorem (termination). If F♯F^\sharp is monotone, the widened iteration stops, and it returns an element zz with F♯(z)⊑zF^\sharp(z) \sqsubseteq z.

Proof. Suppose the iteration never stops. Put y0=⊥y_0 = \bot and yk+1=F♯(zk)y_{k+1} = F^\sharp(z_k). Then z0=y0z_0 = y_0 and zk+1=zk∇yk+1z_{k+1} = z_k \nabla y_{k+1}. By property 1, zk⊑zk+1z_k \sqsubseteq z_{k+1} for each kk, so (zk)(z_k) is increasing. Since F♯F^\sharp is monotone, (yk)k≥1(y_k)_{k \ge 1} is increasing too, and y0=⊥y_0 = \bot is below y1y_1. So (yk)(y_k) is an increasing chain, and (zk)(z_k) is its widened chain. By property 2 there is a KK with zK+1=zKz_{K+1} = z_K. Then, by property 1,

F♯(zK)=yK+1⊑zK∇yK+1=zK+1=zK,F^\sharp(z_K) = y_{K+1} \sqsubseteq z_K \nabla y_{K+1} = z_{K+1} = z_K,

so the stop test holds at step KK, which contradicts the assumption. The iteration therefore stops at some zkz_k, and the stop test is exactly F♯(zk)⊑zkF^\sharp(z_k) \sqsubseteq z_k. □\square

With the stronger form of property 2 the same proof works without the monotonicity of F♯F^\sharp.

Soundness of the result. The result zz has F♯(z)⊑zF^\sharp(z) \sqsubseteq z. By the claim on the abstract domain page, γ(z)\gamma(z) contains the collecting semantics when F♯F^\sharp is sound; that proof does not use monotonicity either. When F♯F^\sharp is monotone on a complete lattice, the Knaster-Tarski theorem also gives lfp F♯⊑z\mathrm{lfp}\, F^\sharp \sqsubseteq z. Such a zz is a pre-fixed point in the naming of that page, and a post-fixed point in the naming of Cousot. It need not be a fixed point, and it is often above lfp F♯\mathrm{lfp}\, F^\sharp; a narrowing then improves it.

Where to widen. In a program with many blocks, F♯F^\sharp works on a map from blocks to AA. It is enough to widen at a set of blocks that cuts every cycle of the control flow graph, and to use the join elsewhere. The heads of a weak topological ordering form such a set, and that page proves that the iteration then stops.

A widening is not monotone. For intervals, [0,0]⊑[0,1][0, 0] \sqsubseteq [0, 1], but

[0,0]∇[0,1]=[0,+∞]and[0,1]∇[0,1]=[0,1],[0, 0] \nabla [0, 1] = [0, +\infty] \quad \text{and} \quad [0, 1] \nabla [0, 1] = [0, 1],

and [0,+∞]⋢[0,1][0, +\infty] \not\sqsubseteq [0, 1]. So a more precise first argument can give a less precise result: the widening looks at how far a bound moved, not only at where it ended. In practice this means that the result of an analysis depends on the order of the iteration, and that a more precise input fact can give a less precise output.

A widening is not a join. The join is commutative and gives the least upper bound. The interval widening is neither:

[0,1]∇[0,2]=[0,+∞],[0,2]∇[0,1]=[0,2].[0, 1] \nabla [0, 2] = [0, +\infty], \qquad [0, 2] \nabla [0, 1] = [0, 2].

The first argument is the old value and the second is the new one; the order matters. Using the join in place of the widening loses termination, and using the widening in place of the join at every block loses precision for nothing.

Widening against finite domains. A widening on a domain of infinite height can prove more than any finite domain. Take the family of programs PnP_n: x = 0, then while x < n: x = x + 1, for each constant n≥0n \ge 0. Intervals with widening and one narrowing step give x∈[0,n]x \in [0, n] at the loop head, the exact set {0,…,n}\{0, \dots, n\}. Now fix a finite domain BB with a concretization γ\gamma. To prove 0≤x≤n0 \le x \le n at the head of PnP_n, an analysis must return some bn∈Bb_n \in B with {0,…,n}⊆γ(bn)⊆{x:0≤x≤n}\{0, \dots, n\} \subseteq \gamma(b_n) \subseteq \{x : 0 \le x \le n\}, so γ(bn)={0,…,n}\gamma(b_n) = \{0, \dots, n\}. The sets differ for different nn, so the elements bnb_n are pairwise different, and BB has infinitely many elements. This contradicts the choice of BB. So for each finite domain, some program of the family has an invariant that it cannot prove; Cousot and Cousot (1992) make this point in general.

Examples and non-examples

A loop with two names. The loop sums i into s.

entry:
  i = 0
  s = 0
  jump head
head:
  t = i < 10
  br t body exit
body:
  s = s + i
  i = i + 1
  jump head
exit:
  ret s

At head, F♯(x)F^\sharp(x) joins the entry state (i,s∈[0,0]i, s \in [0, 0]) with the body applied to xx after the guard i≤9i \le 9. The widening is applied at head only, name by name.

step zkz_k at head F♯(zk)F^\sharp(z_k) stop?
0 ⊥\bot i∈[0,0]i \in [0, 0], s∈[0,0]s \in [0, 0] no
1 i∈[0,0]i \in [0, 0], s∈[0,0]s \in [0, 0] i∈[0,1]i \in [0, 1], s∈[0,0]s \in [0, 0] no
2 i∈[0,+∞]i \in [0, +\infty], s∈[0,0]s \in [0, 0] i∈[0,10]i \in [0, 10], s∈[0,9]s \in [0, 9] no
3 i∈[0,+∞]i \in [0, +\infty], s∈[0,+∞]s \in [0, +\infty] i∈[0,10]i \in [0, 10], s∈[0,+∞]s \in [0, +\infty] yes

Step 0 gives z1=⊥∇F♯(⊥)=F♯(⊥)z_1 = \bot \nabla F^\sharp(\bot) = F^\sharp(\bot). At step 1 the upper bound of i moves, so it jumps to +∞+\infty; s does not move. At step 2 the upper bound of s moves and jumps. At step 3 the test passes. The exit state is i∈[10,+∞]i \in [10, +\infty], s∈[0,+∞]s \in [0, +\infty]. The narrowing operator page continues from here and gets i∈[10,10]i \in [10, 10] at the exit.

Plain iteration does not stop on the same loop. Without widening, the iterates (F♯)k(⊥)(F^\sharp)^k(\bot) at head are i∈[0,k−1]i \in [0, k - 1] and s∈[0,(k−1)(k−2)/2]s \in [0, (k-1)(k-2)/2] for 1≤k≤111 \le k \le 11, which reaches i∈[0,10]i \in [0, 10] and s∈[0,45]s \in [0, 45]. From then on i stays at [0,10][0, 10], and each step adds the upper bound 9 of i to the upper bound of s: 54, 63, 72, and so on, without end. The loop runs ten times, but the interval domain does not know that ss and ii are linked. Here the least fixed point of F♯F^\sharp is i∈[0,10]i \in [0, 10], s∈[0,+∞]s \in [0, +\infty], and it is the limit of an infinite chain. The bound s≤45s \le 45 is lost by the domain, not by the widening.

Delayed widening. A common variant uses the join for the first dd steps and the widening after that. With d=2d = 2 in the loop above, the first widening takes the old value i∈[0,1]i \in [0, 1], s∈[0,0]s \in [0, 0] and the new value i∈[0,2]i \in [0, 2], s∈[0,1]s \in [0, 1]; both upper bounds jump at once, and the result is the same. In a loop whose bounds stop moving after a few passes, the delay keeps the exact bounds.

Thresholds. A widening with thresholds moves a bound to the next value of a fixed list, such as the constants of the program, before it moves it to infinity. With the list {10}\{10\} the first widening in the table gives i∈[0,10]i \in [0, 10], and the exit state gets i∈[10,10]i \in [10, 10] with no narrowing step. Each bound can move at most once per threshold plus once to infinity, so property 2 still holds.

Widening on other domains. The standard widening of the polyhedra domain keeps the constraints of the old polyhedron that the new one still satisfies; it terminates because each strict step either raises the dimension or drops a constraint. The octagon domain has a widening that works on the matrix of bounds, and its first argument must not be closed between steps, or the chain can grow forever.

Non-example: the join on intervals. The join is an upper bound, so property 1 holds. On the chain [0,0]⊑[0,1]⊑[0,2]⊑⋯[0, 0] \sqsubseteq [0, 1] \sqsubseteq [0, 2] \sqsubseteq \cdots the joined chain is the chain itself, which never stops. Property 2 fails.

Non-example: a jump to ⊤\top. The map x∇y=⊤x \nabla y = \top when y⋢xy \not\sqsubseteq x, and xx otherwise, is a widening: it is an upper bound, and a chain can change at most once. It is also useless: it gives i∈[−∞,+∞]i \in [-\infty, +\infty] in the loop above and loses the lower bound i≥0i \ge 0. A good widening keeps every bound that has not moved.

References

  1. Patrick Cousot and Radhia Cousot, Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints, POPL 1977, pages 238 to 252, the definition of a widening by its upper bound property and the stabilization of every widened increasing chain, and the upward iteration with widening
  2. Patrick Cousot and Radhia Cousot, Static determination of dynamic properties of programs, Proceedings of the Second International Symposium on Programming, B. Robinet (ed.), Dunod, Paris, 1976, pages 106 to 130, the first widening, on intervals, used to analyze loops in finitely many steps
  3. Patrick Cousot and Radhia Cousot, Comparing the Galois connection and widening/narrowing approaches to abstract interpretation, PLILP 1992, LNCS 631, pages 269 to 295, the argument that widenings on domains of infinite height give results that no single finite abstract lattice gives for all programs
  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 standard widening on polyhedra and a framework for widenings that are more precise
  5. Xavier Rival and Kwangkeun Yi, Introduction to Static Analysis, An Abstract Interpretation Perspective, MIT Press, 2020, Chapter 3 (the analysis of loops with widening) and Appendix B (the soundness proofs, including the widening iterates)

Where this leads

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/AKGMSN/text.yaml