πŸ“Œ Is Widening Actually Necessary? (a provocative post)
Started by AbstractKitty  |  Static Analysis
Replies: 246  |  Views: 14,882  |  Posts: 31–40 of 247
Thread is HOT πŸ”₯ β€” 14 users viewing. This thread has been linked from Polyhedra vs. Intervals Megathread.
🐱
PolyhedralPaws NEW
✦ Convex Newcomer
Joined: 3 days ago
Posts: 2
#31   Posted: Today, 09:14 ΒΆ permalink

ok wait, I just found this thread and I feel like everyone is missing the forest for the trees here. The entire widening debate is moot β€” because you should all just be using polyhedra-based abstract domains instead of intervals in the first place. Polyhedra are strictly more expressive and they make the question of "which widening heuristic" a lot more tractable because your approximations are geometrically meaningful.

Intervals are boxes. Boxes are embarrassing. A convex polyhedron can capture any linear relationship between variables β€” things like x + y ≀ 10 or 2x - 3y β‰₯ 0. You literally cannot express those with intervals. The precision gain is enormous.

Switch to polyhedra, problem solved. 😺

🐈
LatticeTabby OG
✦ Fixpoint Sage
Joined: 4 years ago
Posts: 3,847
#32   Posted: Today, 09:31 ΒΆ permalink
PolyhedralPaws wrote:
Switch to polyhedra, problem solved. 😺

Welcome to the forum, PolyhedralPaws. I remember saying something very similar in my first week here. Let me walk you through why it's not that simple, with patience and love. 🐾

Yes, convex polyhedra are more expressive than intervals. That expressivity comes at a cost. A serious one. The fundamental operations on polyhedra β€” join (convex hull), widening, projection β€” are all significantly more expensive than their interval counterparts.

The big one: checking feasibility of a system of linear constraints (which you need for essentially every abstract domain operation on polyhedra) reduces to linear programming. That's polynomial, sure, but with large constant factors in practice. And computing the convex hull of two polyhedra in H-representation (constraint form) is where things get really bad. The double-description method used for conversion between H-representation and V-representation (vertices/rays) can be exponential in the worst case.

But the part that's most relevant to this thread: polyhedra widening. The standard algorithm for it (from Halbwachs's PhD thesis) operates on the constraint representation β€” it keeps constraints from the first polyhedron that are still satisfied by the second. Simple enough. But ensuring termination while maintaining meaningful precision is genuinely hard, and in the worst case, the chain of widenings can be EXPTIME in the number of constraints.

Intervals are embarrassing? Perhaps. But they're also fast, and in many real-world verification tasks, they're fast enough to scale to millions of lines of code. Polyhedra analyses struggle to scale past small programs without heroic engineering efforts.

The precision/complexity tradeoff is real and it does not care about your feelings. 😿

😸
PolyhedralPaws NEW
✦ Convex Newcomer
Joined: 3 days ago
Posts: 3
#33   Posted: Today, 09:45 ΒΆ permalink
LatticeTabby wrote:
in the worst case, the chain of widenings can be EXPTIME in the number of constraints.

wait, EXPTIME?? that seems like a lot. Are you sure it's not just exponential space or something?

also what even is a "constraint representation" vs a "vertex representation"?? genuinely asking, I come from a model checking background, not static analysis.

🐾
GaloisCat
✦ Adjunction Acolyte
Joined: 2 years ago
Posts: 1,204
#34   Posted: Today, 10:02 ΒΆ permalink

ok I was going to stay out of this but the polyhedra question is my jam. Let me do a proper breakdown of the Halbwachs standard widening vs the Bagnara et al. precise widening because this comes up every six months and nobody ever links the actual papers.

═══ BACKGROUND: What is a convex polyhedron (abstract domain sense) ═══

A convex polyhedron over variables x₁,...,xβ‚™ is a set of points defined by a finite conjunction of linear inequalities: { (x₁,...,xβ‚™) | Ax ≀ b }. This is the H-representation (half-space representation). The V-representation (generator/vertex representation) describes the same polyhedron as the convex hull of a set of vertices, rays, and lines. Converting between these is the "double-description" problem, and it's the source of most of the computational pain.

═══ THE HALBWACHS STANDARD WIDENING ═══

Cousot and Halbwachs introduced the polyhedral domain and its widening operator in their landmark 1978 POPL paper on automatic discovery of linear restraints among program variables. The standard widening P βˆ‡ Q is defined as follows: you keep exactly those constraints of P that are still satisfied by all points in Q. Constraints that Q "violates" get dropped.

-- Standard widening (Cousot & Halbwachs 1978) -- Given: P = { x | c₁(x) ∧ cβ‚‚(x) ∧ ... ∧ cβ‚™(x) } -- Q (next iterate, P βŠ‘ Q) P βˆ‡ Q = { x | cα΅’(x) for all cα΅’ such that Q ⊨ cα΅’ } -- i.e., keep only constraints of P that Q still satisfies -- drop the rest (widen to +∞ in those directions)

This is elegant and cheap β€” just test each constraint of P against Q. It terminates because the set of constraints can only shrink or stabilize. But it's often wildly imprecise β€” it throws away any constraint that Q doesn't satisfy, even if Q only barely violates it.

═══ THE BAGNARA PRECISE WIDENING ═══

Bagnara, Hill, Ricci, and Zaffanella (SAS 2003 / Science of Computer Programming 2005) addressed this head-on. Their paper "Precise Widening Operators for Convex Polyhedra" presents a framework for defining widening operators that are never less precise than the standard Halbwachs widening. The key idea: instead of just testing the constraints of P, they use a more sophisticated procedure that considers additional candidate constraints drawn from the history of iterates.

-- Bagnara et al. approach (simplified conceptually) -- collect "stable" constraints from iteration history -- check against a richer set of candidate half-spaces -- use standard widening as a "last resort" fallback P βˆ‡_precise Q = { keeps more constraints than standard βˆ‡ } -- by testing Q against not just constraints of P, -- but also constraints from prior fixpoint iterates -- and other heuristically-derived candidates

Their framework combines multiple heuristics β€” including widening up to a set of "landmarks" or threshold constraints, and use of the previous iterate's constraints β€” to achieve strictly better precision while still guaranteeing termination.

The key improvement: the standard widening may drop a constraint c from P even if Q only barely violates it, and that constraint might be crucial for the invariant you're trying to prove. Bagnara's widening is more conservative about dropping constraints β€” it only drops them when it's absolutely forced to by the termination requirement.

═══ COMPLEXITY CONCERNS ═══

As LatticeTabby correctly noted, the complexity is a real concern. The standard widening is cheap (polynomial per step). Bagnara's precise widening involves more expensive constraint solving at each step. More importantly: the number of widening steps before stabilization can be exponential in the number of dimensions/constraints in the worst case. This is intrinsic to the polyhedra domain β€” it admits infinite ascending chains, so some widening mechanism is mandatory, but the complexity of that mechanism varies.

References:

β€’ Cousot & Halbwachs (1978) β€” Automatic discovery of linear restraints, POPL
β€’ Halbwachs PhD thesis (1979) β€” standard widening algorithm on constraint repr.
β€’ Bagnara, Hill, Ricci, Zaffanella (2003/2005) β€” Precise Widening Operators for Convex Polyhedra, SAS/SciCP
β€’ Bagnara, Hill, Zaffanella (2008) β€” The Parma Polyhedra Library (PPL implementation)

See also: wiki: polyhedra widening comparison table | PPL library thread

πŸ™€
NarrowingEnjoyer
✦ Descending Chain
Joined: 1 year ago
Posts: 88
#35   Posted: Today, 10:07 ΒΆ permalink
😀 just narrow the polyhedra lol
😡
MeownadTransformer
✦ Type-Theoretic Furball
Joined: 1.5 years ago
Posts: 512
#36   Posted: Today, 10:28 ΒΆ permalink

I was inspired by GaloisCat's breakdown so I spent the last 45 minutes trying to start encoding polyhedral abstract interpretation in Coq. I defined the abstract domain as a dependent type indexed by the dimension and the constraint matrix and then immediately got hit with universe inconsistency errors. Pasting them here so someone smarter than me can tell me what I did wrong:

(* MeownadTransformer's Coq encoding attempt, 10:15 AM *) Require Import Coq.Vectors.Vector. Require Import Coq.QArith.QArith. Require Import Coq.Lists.List. (* A linear constraint: a^T x ≀ b *) Record LinearConstraint (n : nat) : Type := { coeffs : Vector.t Q n; rhs : Q }. (* A polyhedron in H-repr: finite list of constraints *) Definition Polyhedron (n : nat) : Type := list (LinearConstraint n). (* Abstract domain lattice β€” here is where it breaks *) Class AbstractDomain (A : Type) : Type := { top : A; bot : A; join : A -> A -> A; meet : A -> A -> A; leq : A -> A -> Prop; widen : A -> A -> A; (* ... *) }. (* Attempting to instantiate for Polyhedron... *) Instance PolyhedronDomain (n : nat) : AbstractDomain (Polyhedron n) := { top := nil; (* empty constraints = everything *) bot := ...; (* βŠ₯ = infeasible polyhedron... hmm *) join := fun p q => convex_hull p q; (* uh oh *) ... }.
Error: Universe inconsistency. Cannot enforce Set < Set because Type@{polyhedra.1} is not a subtype of Type@{AbstractDomain.A} while checking that the type of PolyhedronDomain is correct. In environment: n : nat The term "AbstractDomain (Polyhedron n)" has type "Type@{max(polyhedra.1+1,AbstractDomain.u0+1)}" while it is expected to have type "Type@{AbstractDomain.u0}" (unable to unify "Type@{max(polyhedra.1+1,AbstractDomain.u0+1)}" and "Type@{AbstractDomain.u0}").

I think the issue is that my AbstractDomain class lives in a universe that's too small for the Polyhedron type which itself is parameterized by nat. I tried adding Universe Polymorphism but then I got:

Error: Universe inconsistency (Anomaly). Anomaly "Unable to handle recursive occurrence of universe constraint". Please report at https://github.com/coq/coq/issues.
I may have broken Coq. I'm going to close the file and pretend this never happened.

Anyway, the conceptual point I was trying to make is that the widening operator for polyhedra is really tricky to express in a way that's both provably terminating and captures the domain structure correctly. The Coq type-checker apparently agrees that this is hard. πŸ™€

Has anyone successfully formalized polyhedral abstract interpretation in Coq or Isabelle? I know there's the verified static analysis thread but I didn't see polyhedra specifically discussed there.

🐈
LatticeTabby OG
✦ Fixpoint Sage
Joined: 4 years ago
Posts: 3,848
#37   Posted: Today, 10:35 ΒΆ permalink
MeownadTransformer wrote:
I may have broken Coq.

You haven't broken Coq. You've just discovered that formalizing abstract interpretation in a dependent type theory requires being very careful about universe levels. The AbstractDomain typeclass as written is trying to be polymorphic over all types simultaneously, which causes the universe issue.

The fix is: add Set Universe Polymorphism. before your class definition, and annotate the class with @{u} universe variables explicitly. Or β€” honestly β€” just use Prop for the lattice ordering and Set for the elements, keep them at the same level. The Verasco project (a verified C static analyzer in Coq) handles this; look at their abstract domain interfaces.

Also, convex_hull for the join is going to require axioms unless you're computing it via an algorithm you've also proven correct... which is, um, a very large rabbit hole. There's a reason the verified analysis community often works with simpler domains. πŸ‡

πŸˆβ€β¬›
ProgrammingPawsy
✦ Kitten Coder
Joined: 6 months ago
Posts: 143
#38   Posted: Today, 10:44 ΒΆ permalink

Sorry for the dumb question but I've been reading this thread since post 1 and people keep saying "convex polyhedron" β€” I've seen it explained vaguely a few times but can someone give me a proper ELI5? Like what makes it "convex" specifically, and what does it look like in 2D and 3D? I know what a box/interval is. How does a polyhedron generalize that?

I learn best from pictures but I know this is a text forum soooo... ASCII art maybe? πŸ₯Ί

🐾
GaloisCat
✦ Adjunction Acolyte
Joined: 2 years ago
Posts: 1,205
#39   Posted: Today, 10:58 ΒΆ permalink

ProgrammingPawsy, great question! Never apologize for asking. Here is your ASCII art explanation. πŸ–ΌοΈ

Step 1: An interval in 1D β€” just a segment. The abstract value [2, 7]:

0 1 2 3 4 5 6 7 8 9 | | |===|===|===|===|===|===| | ^ ^ 2 ≀ x x ≀ 7

Step 2: A box (interval product) in 2D β€” two independent intervals. Abstract value: x ∈ [1,5], y ∈ [2,4]:

y 5 | 4 | +-------+ 3 | | | A "box": axis-aligned rectangle. 2 | +-------+ Sides are always parallel to axes. 1 | Cannot express "x + y ≀ 6". 0 +---+---+---+-- x 0 1 2 3 4 5 6

Step 3: A convex polyhedron in 2D β€” intersection of half-planes. Can have any slope for its sides:

y 6 | 5 | * 4 | / \ This shape is a convex polygon. 3 | / \ Each edge = one linear constraint. 2 | | | Example constraints: 1 | \ / x + y ≀ 6 (top-right edge) 0 | \ / x - y ≀ 2 (bottom-right edge) -1 | * x β‰₯ 1 (left side) +---+---+---+---+-- x y β‰₯ -1 (bottom) 0 1 2 3 4

The key property: CONVEXITY. A shape is convex if for any two points P and Q inside it, the entire line segment PQ is also inside it. This rules out "dents" or holes:

CONVEX βœ“ NOT CONVEX βœ— +-------+ +---+ +---+ | | | | | | | | | +---+ | | | | | +-------+ +-----------+ pick any 2 pick these 2 points: points: segment the segment goes OUTSIDE stays inside! the shape. Not convex!

Why convexity matters for static analysis: If your abstract domain is closed under intersection (which polyhedra are β€” intersect two convex sets, get a convex set) and under linear transformations (assignments), you get a clean algebraic structure. The join (convex hull) of two polyhedra is the smallest convex set containing both β€” this corresponds to merging two paths in your program CFG. Everything stays geometrically tidy.

In 3D: you get actual polyhedra β€” tetrahedra, cubes, octahedra, etc. but with potentially many more faces, each a linear constraint aα΅’x + bα΅’y + cα΅’z ≀ dα΅’. In n dimensions, each face is an (n-1)-dimensional hyperplane half-space. This is why operations get expensive: you have up to exponentially many vertices even with few constraints.

Does that help? See also: Abstract Domains Primer on our wiki. 🐾

😺
FixpointFeline MOD
✦ Least Upper Bound
Joined: 5 years ago
Posts: 6,021
#40   Posted: Today, 11:14 ΒΆ permalink

Alright, wonderful discussion everyone. Welcome PolyhedralPaws β€” don't be discouraged, the "just use polyhedra" phase is rite of passage here. We've all been through it. 🐾

Let me try to bring some synthesis to the thread before it spirals further. We've now covered:

✦ Original thread: is widening necessary at all? (answer: for infinite-height domains, yes, for convergence)
✦ Pages 2-3: threshold widening, delay strategies, precision vs. termination
✦ This page: polyhedra domains and their widening β€” more precise but much costlier

I want to introduce a concept that acts as a middle ground between "just widen aggressively" and "use polyhedra for everything" β€” and that's "widening up to" (also called widening with thresholds).

The idea: instead of letting the widening operator go all the way to ±∞ when a constraint becomes unstable, you supply a finite set of threshold values β€” candidate boundaries that you believe might appear in the fixpoint β€” and the widening "pauses" at these thresholds before jumping to infinity. More formally, given a set of thresholds T = {t₁, tβ‚‚, ..., tβ‚–}:

-- Widening "up to" thresholds T (for interval domain) x βˆ‡_T y = if y.lb β‰₯ x.lb then x.lb else max { t ∈ T | t ≀ y.lb } -- pause at nearest threshold ?? -∞ -- if none, jump to -∞ -- Similarly for upper bounds, and for polyhedra constraints

The thresholds for polyhedra can be the set of constants appearing in the program source β€” branch conditions, array bounds, literal integers. This is a static set, so termination is preserved (you can only pause at finitely many thresholds before reaching the standard widen). But precision improves dramatically for programs where the fixpoint lies at or near a known constant.

This technique is used in production analyzers β€” AstrΓ©e uses it, and MinΓ©'s work on threshold widening for numerical domains is a key reference. It essentially threads the needle between "too aggressive" and "polyhedra-level expensive" for many real programs.

So to answer the meta-question of this thread: widening is necessary, but how you widen is a rich design space. Polyhedra give you more precision at higher cost; interval widening with good thresholds often gets you 80% of the precision at 10% of the cost.

Relevant pages: wiki: widening with thresholds | Continue to page 5 β†’ (where AbstractKitty returns with new data from running actual experiments)

πŸ“ Quick Reply

πŸ”— Related Threads in Static Analysis
β†’ Polyhedra vs. Intervals MEGATHREAD (241 replies)
β†’ The Parma Polyhedra Library β€” experiences? (88 replies)
β†’ When is narrowing actually useful? (64 replies)
β†’ Galois connections explained for mere mortals (133 replies)
β†’ Verified/Certified Static Analyzers β€” Verasco, Ciao, etc. (97 replies)
β†’ Octagon Domain Appreciation Thread (44 replies)
β†’ Coq Formal Methods Catastrophes (Share Yours) (201 replies)
🏠 Home πŸ“‹ All Forums Static Analysis ← Previous Page Next Page β†’ πŸ“– CGPA Wiki πŸ† Top Posters cgpa.isarabbithole.com Β· Powered by PurrBB 3.2