Yes! Your "lazy bounding box" intuition is exactly right. And yes, β₯ means unreachable β that's a perfect understanding π
Now: The Grave Widening Momentβ’
The problem with loops:
Consider analyzing this simple loop:
int x = 0;
while (x < 10) {
x = x + 1;
}
When we analyze this, we repeatedly re-analyze the loop body. Let's trace what happens to x's abstract value at the loop header:
// Naive iteration without widening:
Iteration 0: x β [0, 0] // just initialized
Iteration 1: x β [0, 1] // join with [1,1] from loop back edge
Iteration 2: x β [0, 2] // join with [2,2]
Iteration 3: x β [0, 3]
Iteration 4: x β [0, 4]
...
Iteration k: x β [0, k] // this will NEVER stabilize!
The interval keeps growing by 1 each iteration. The interval lattice has infinite ascending chains β there's no upper bound on how many distinct intervals you can make by incrementing the upper bound. So naive iteration does not terminate. π±
Enter: Widening (β)
Widening is a special operator that aggressively extrapolates to force convergence. The classic interval widening says: "if your upper bound grew between iterations, just set it to +β immediately. If your lower bound shrank, set it to -β."
// Widening rule: [a,b] β [c,d]
// If c < a: new lower bound = -β
// Else: new lower bound = a
// If d > b: new upper bound = +β
// Else: new upper bound = b
Example:
[0, 0] β [0, 1] = [0, +β]
// upper bound grew (1 > 0), so we jump to +β immediately
Now let's redo the loop analysis with widening:
Iteration 0: x β [0, 0]
Iteration 1: [0,0] β [0,1] = [0, +β] // widened!
Iteration 2: [0,+β] β [0,+β] = [0, +β] // stable! fixpoint reached β
We stabilize in just 2 iterations. The trade-off: our result is [0, +β] β we've lost the information that x stays below 10. That's imprecise, but it's sound (we didn't say x was in a range that excludes real values) and it terminates.
β οΈ The Widening Trade-off
Widening sacrifices precision to gain termination. It's like saying "I don't know exactly how high this number could go, so I'll just say it could go to infinity." You might then get false alarms from your analyzer β places that look unsafe but are actually fine β but you'll never miss a real bug (soundness!).
The Grave Widening Moment is real: it's when you realize your beautiful precise analysis would run forever without this blunt instrument π
There's also a narrowing phase that can recover some precision after widening stabilizes, but that's for another post!