Introduction
Probabilistic programs—code incorporating random choices or samples from distributions—are increasingly prevalent in randomized algorithms and AI controllers. A fundamental challenge in verifying these programs is the termination problem. Traditionally, research has focused on the qualitative question: does the program terminate "almost-surely" (with probability 1)? The standard tool for this is the Ranking Supermartingale (RSM), which identifies a function that decreases on average at every step until termination.
However, existing methods often rely on "pure" invariants—logical constraints that must hold in every possible execution. In probabilistic settings, pure invariants can be overly restrictive. A program might have a negligible chance of entering a state that violates a pure invariant, causing standard tools to fail even if termination is nearly certain (e.g., 99.999% probability). This research addresses the quantitative problem: computing reliable lower bounds on termination probability when almost-sure termination cannot be proven.
Methodology: Stochastic Invariants and RepSMs
To bridge the gap between qualitative and quantitative verification, the authors introduce two core concepts:
- Stochastic Invariants: Unlike traditional invariants, a stochastic invariant is a pair consisting of a constraint and a probability bound $p$. It guarantees that the constraint is violated with a probability no greater than $p$.
- Repulsing Supermartingales (RepSMs): Acting as the "dual" to Ranking Supermartingales, a RepSM demonstrates that a program is being "pushed away" from "bad" non-terminating regions of the state space.
The verification workflow involves synthesizing these invariants and martingales. For linear-arithmetic programs, synthesis can be reduced to the existential first-order theory of reals. Once invariants are established (e.g., via abstract interpretation), checking for a linear RepSM is efficiently performed using Linear Programming (LP). By combining an RSM (proving the program "wants" to terminate) with a RepSM (bounding the probability of falling into a "trap" where it won't terminate), a formal lower bound for total termination probability is derived.
Evaluation on Complex Random Walks
The approach was evaluated on several academic benchmarks representing complex random walks that challenge traditional verification methods.
Key benchmarks included:
- 1D Random Walk: A process drifting toward termination with a "trap" region (e.g., $x > 1000$) where it drifts away indefinitely.
- 2D Random Walk: A scenario where one variable drifts toward termination while another may enter an infinite loop (see Figure 5).
- 3D Random Walk: A system with non-proportional increments and decrements.
Key Results and Insights
The framework yielded high-precision results across the benchmarks:
- Quantitative Tightness: For the 1D random walk, the authors proved the probability of violating the invariant was less than $5.1 \times 10^{-5}$. In 3D scenarios, violation probabilities as low as $10^{-17}$ were calculated, effectively proving near-certain termination.
- Repulsion as a Witness: RepSMs serve as formal "witnesses" to refute almost-sure termination. Finding a RepSM that shows a drift away from the exit proves a program does not terminate with probability 1.
- Efficiency: The reduction of infinite-state probabilistic reasoning to standard optimization problems (LP) allows modern solvers to handle these verification tasks in seconds.
Limitations and Future Directions
While powerful, the current framework is primarily optimized for linear-arithmetic programs. Programs with non-linear dynamics (e.g., $x := x^2 \cdot \text{sample}()$) would require the development of non-linear RepSMs. Additionally, while verification is fast, the synthesis of invariants from scratch remains computationally expensive for very large programs. Future work will explore polynomial repulsing supermartingales and heuristic-based synthesis techniques to scale the approach to larger software systems.
Summary updated