Algorithm Search⌘K

Definitionadvanced

Narrowing operator

Also called narrowing in abstract interpretation.

An operator applied after widening that refines a post-fixed point downward while staying sound, in finitely many steps.

A narrowing operator Δ\Delta refines the result of a widened analysis. The widening stops at an element zz with F♯(z)⊑zF^\sharp(z) \sqsubseteq z, often far above the least fixed point. Each narrowing step moves the value down toward F♯F^\sharp of the value, but only so far that the result stays above the least fixed point and the steps stop after finitely many. On intervals the usual narrowing replaces an infinite bound by the finite bound that F♯F^\sharp computes, and keeps every finite bound.

Definition

The setting is an abstract domain (A,⊑)(A, \sqsubseteq) in the Cousot order and a monotone abstract function F♯:A→AF^\sharp : A \to A. The widening operator page explains how to reach the start point.

A narrowing is a map Δ:A×A→A\Delta : A \times A \to A with two properties.

  1. Between the arguments. For all x,yx, y with y⊑xy \sqsubseteq x: y⊑x Δ y⊑xy \sqsubseteq x \,\Delta\, y \sqsubseteq x.
  2. Stabilization. For every decreasing chain y0⊒y1⊒y2⊒⋯y_0 \sqsupseteq y_1 \sqsupseteq y_2 \sqsupseteq \cdots, the chain x0=y0x_0 = y_0, xk+1=xk Δ yk+1x_{k+1} = x_k \,\Delta\, y_{k+1} is eventually stationary.

The narrowed iteration. Start from w0w_0 with F♯(w0)⊑w0F^\sharp(w_0) \sqsubseteq w_0, for example the result of the widened iteration. Set wk+1=wk Δ F♯(wk)w_{k+1} = w_k \,\Delta\, F^\sharp(w_k), and stop when wk+1=wkw_{k+1} = w_k.

Theorem (soundness is kept). For every kk: wk+1⊑wkw_{k+1} \sqsubseteq w_k and F♯(wk)⊑wkF^\sharp(w_k) \sqsubseteq w_k. Hence lfp F♯⊑wk\mathrm{lfp}\, F^\sharp \sqsubseteq w_k when AA is a complete lattice, and γ(wk)\gamma(w_k) contains the collecting semantics when F♯F^\sharp is sound.

Proof. By induction on kk. For k=0k = 0, F♯(w0)⊑w0F^\sharp(w_0) \sqsubseteq w_0 holds by the choice of w0w_0. Assume F♯(wk)⊑wkF^\sharp(w_k) \sqsubseteq w_k. Property 1 with x=wkx = w_k and y=F♯(wk)y = F^\sharp(w_k) gives

F♯(wk)⊑wk+1⊑wk.F^\sharp(w_k) \sqsubseteq w_{k+1} \sqsubseteq w_k .

Since F♯F^\sharp is monotone and wk+1⊑wkw_{k+1} \sqsubseteq w_k, we get F♯(wk+1)⊑F♯(wk)⊑wk+1F^\sharp(w_{k+1}) \sqsubseteq F^\sharp(w_k) \sqsubseteq w_{k+1}. This closes the induction. Each wkw_k is an element xx with F♯(x)⊑xF^\sharp(x) \sqsubseteq x, so the Knaster-Tarski theorem puts lfp F♯\mathrm{lfp}\, F^\sharp below it, and the claim on the abstract domain page gives Coll⊆γ(wk)\mathit{Coll} \subseteq \gamma(w_k). □\square

In the naming of the Knaster-Tarski page each wkw_k is a pre-fixed point; Cousot calls it a post-fixed point. Either way, every step of the narrowed iteration is a sound result, so an analyzer may stop at any step, for example when a time budget runs out.

Theorem (termination). The narrowed iteration stops.

Proof. Put y0=w0y_0 = w_0 and yk+1=F♯(wk)y_{k+1} = F^\sharp(w_k). The chain (wk)(w_k) is decreasing by the first theorem, so (F♯(wk))(F^\sharp(w_k)) is decreasing by monotonicity, and y1=F♯(w0)⊑w0=y0y_1 = F^\sharp(w_0) \sqsubseteq w_0 = y_0. So (yk)(y_k) is a decreasing chain, w0=y0w_0 = y_0 and wk+1=wk Δ yk+1w_{k+1} = w_k \,\Delta\, y_{k+1}. By property 2 the chain (wk)(w_k) is eventually stationary, so some step has wk+1=wkw_{k+1} = w_k. □\square

The monotonicity of F♯F^\sharp is used in both proofs. Without it, wk+1w_{k+1} may fail F♯(wk+1)⊑wk+1F^\sharp(w_{k+1}) \sqsubseteq w_{k+1}, and the narrowed value may be unsound. The widening has no such need in its stronger form.

The interval narrowing. For intervals,

⊥ Δ y=⊥,x Δ ⊥=⊥,[a,b] Δ [c,d]=[ a=−∞ ? c:a,  b=+∞ ? d:b ].\bot \,\Delta\, y = \bot, \qquad x \,\Delta\, \bot = \bot, \qquad [a, b] \,\Delta\, [c, d] = [\, a = -\infty \,?\, c : a,\ \ b = +\infty \,?\, d : b \,].

Property 1: if [c,d]⊑[a,b][c, d] \sqsubseteq [a, b], then a≤ca \le c and d≤bd \le b, and the new lower bound is cc or aa, both between aa and cc; the upper bound is the same. Property 2: a finite bound never changes, and an infinite bound changes at most once, to a finite one. So a chain of narrowed values changes at most three times: once for each bound and once to ⊥\bot. On a map from names to intervals the narrowing works name by name, and the chain changes at most 2v+12v + 1 times for vv names.

A narrowing is not a meet. For y⊑xy \sqsubseteq x the meet gives x⊓y=yx \sqcap y = y, which is the plain decreasing step wk+1=F♯(wk)w_{k+1} = F^\sharp(w_k). It satisfies property 1 but not property 2, as the second example below shows. A narrowing may stop above F♯(wk)F^\sharp(w_k), and the interval narrowing does so whenever a finite bound could still go down.

A narrowing is not a dual widening. A narrowing never jumps below its second argument; it stops early instead. To compute a greatest fixed point from above, which some backward analyses need, an analyzer uses a dual widening: an operator that jumps downward and makes every decreasing chain stop.

Examples and non-examples

Continuing the widened loop. The loop that sums i from 0 to 9 into s is on the widening operator page. The widening stops at w0w_0 with i∈[0,+∞]i \in [0, +\infty], s∈[0,+∞]s \in [0, +\infty] at the loop head.

step wkw_k at head F♯(wk)F^\sharp(w_k) wk+1=wk Δ F♯(wk)w_{k+1} = w_k \,\Delta\, F^\sharp(w_k)
0 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] i∈[0,10]i \in [0, 10], s∈[0,+∞]s \in [0, +\infty]
1 i∈[0,10]i \in [0, 10], s∈[0,+∞]s \in [0, +\infty] i∈[0,10]i \in [0, 10], s∈[0,+∞]s \in [0, +\infty] no change

The infinite upper bound of i becomes 10. The upper bound of s stays infinite, because F♯F^\sharp itself gives +∞+\infty: here w1w_1 is the least fixed point of F♯F^\sharp, and the bound on s is lost by the domain. At the exit the guard i≥10i \ge 10 gives i∈[10,10]i \in [10, 10], s∈[0,+∞]s \in [0, +\infty].

Plain decreasing iteration may not stop. Take F♯(X)=(X⊓[0,+∞])+1F^\sharp(X) = (X \sqcap [0, +\infty]) + 1 on intervals, the equation of a loop head that only its back edge reaches. Its least fixed point is ⊥\bot. Start from w0=[0,+∞]w_0 = [0, +\infty], which satisfies F♯(w0)=[1,+∞]⊑w0F^\sharp(w_0) = [1, +\infty] \sqsubseteq w_0. The plain decreasing steps give

[0,+∞]⊐[1,+∞]⊐[2,+∞]⊐⋯[0, +\infty] \sqsupset [1, +\infty] \sqsupset [2, +\infty] \sqsupset \cdots

and never stop. The interval narrowing gives [0,+∞] Δ [1,+∞]=[0,+∞][0, +\infty] \,\Delta\, [1, +\infty] = [0, +\infty], because the lower bound is finite, and it stops at once with a sound result.

The narrowing keeps a finite bound that is too large. Analyze the loop i = 0; while i < 10: i = i + 1 with a widening with the threshold list {100}\{100\}. The widening gives [0,0]∇[0,1]=[0,100][0, 0] \nabla [0, 1] = [0, 100], and then F♯([0,100])=[0,10]⊑[0,100]F^\sharp([0, 100]) = [0, 10] \sqsubseteq [0, 100]. The interval narrowing gives [0,100] Δ [0,10]=[0,100][0, 100] \,\Delta\, [0, 10] = [0, 100] and stops, because both bounds are finite. One plain decreasing step gives [0,10][0, 10]. For this reason many analyzers use a fixed number of plain steps after the widening, for example one or two; a bounded number of steps always stops, and each step is sound by the first theorem.

Non-example: a narrowing that goes below its second argument. The map x Δ y=⊥x \,\Delta\, y = \bot makes every chain stop at once, but ⊥⊑F♯(wk)\bot \sqsubseteq F^\sharp(w_k) is in general strictly below F♯(wk)F^\sharp(w_k), so property 1 fails. The result describes no state, and the analysis would claim that the loop head is unreachable. The lower bound y⊑x Δ yy \sqsubseteq x \,\Delta\, y is what keeps soundness in the proof above.

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 narrowing and the downward iteration that starts from the limit of 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 decreasing iteration on intervals that refines the infinite bounds found by the widening
  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 use of widening and narrowing together, and the dual operators for iterations from above
  4. Xavier Rival and Kwangkeun Yi, Introduction to Static Analysis, An Abstract Interpretation Perspective, MIT Press, 2020, Chapter 3 (the refinement of loop invariants after widening) and Appendix B (the soundness proofs)
  5. Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Chapter 4 (Abstract Interpretation), the treatment of narrowing operators after the widening

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