Stochastic invariants for probabilistic termination

Krishnendu Chatterjee, Petr Novotný, Dorde Zikelic

TL;DR

This paper introduces stochastic invariants and repulsing supermartingales to provide quantitative lower bounds on the termination probability of probabilistic programs. Unlike previous methods that only answer "does it terminate with probability 1?", this approach can handle programs that might fail to terminate and provides a formal way to calculate exactly how likely they are to finish.

What Problem Does This Paper Address?

Probabilistic programs—code that incorporates random choices or samples from distributions—are everywhere, from randomized algorithms to AI controllers. A fundamental question in verifying these programs is the termination problem.

Until now, research has mostly focused on the qualitative problem: does the program terminate "almost-surely" (with probability 1)? The standard tool for this is the Ranking Supermartingale (RSM), a function that decreases on average at every step until the program ends. However, existing methods rely on "pure" invariants—logical constraints that must hold in every possible execution.

The authors identify a major gap: in probabilistic settings, pure invariants are often too restrictive. A program might have a tiny, one-in-a-million chance of entering a state that violates a pure invariant, causing standard verification tools to fail even if the program terminates with 99.999% probability. This paper tackles the quantitative problem: how can we compute a reliable lower bound on the probability of termination when almost-sure termination cannot be proven?

Methods

The authors introduce two core concepts to bridge this gap:

  1. Stochastic Invariants: Instead of a constraint that always holds, 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$.
  2. Repulsing Supermartingales (RepSMs): This is the "dual" to the well-known Ranking Supermartingale. While an RSM shows that a program is being "pulled" toward termination, a RepSM shows that the program is being "pushed away" from "bad" non-terminating regions of the state space.

The Workflow: * Synthesis: The authors show that finding these invariants and martingales for linear-arithmetic programs can be reduced to the existential first-order theory of reals. * Verification: If the invariants are already provided (e.g., via abstract interpretation), checking for the existence of a linear RepSM can be done efficiently in polynomial time using Linear Programming (LP). * Combining Tools: By combining an RSM (which proves the program wants to terminate) with a RepSM (which bounds the probability of falling into a "trap" where it won't terminate), they derive a formal lower bound for the total termination probability.

Datasets

The paper does not use large-scale real-world datasets, as is typical for fundamental formal methods research. Instead, it evaluates the approach on three academic benchmarks representing complex random walks:

  • Example 1: A 1D random walk that drifts toward termination but has a "trap" region (if $x > 1000$) where it drifts away forever.
  • Example 2: A 2D random walk where one variable drifts toward termination while another might get stuck in an infinite loop.
  • Example 3: A 3D random walk with non-proportional increments and decrements.

Key Insights and Ideas

  • The "Aha!" Moment: The realization that "pure" invariants are the bottleneck. By allowing invariants to be "mostly true" (stochastic), we can reason about programs that are practically reliable even if they aren't theoretically perfect.
  • Repulsion as a Witness: RepSMs aren't just for bounds; they can serve as formal "witnesses" to refute almost-sure termination. If you can find a RepSM that shows the program drifts away from the exit, you've proven it doesn't terminate with probability 1.
  • Persistence: The authors show their tools can also prove "persistence"—the property that once a program reaches a desired "good" state, it is likely to stay there indefinitely.

Key Results

  • Quantitative Bounds: On the benchmark examples, the authors were able to compute extremely tight bounds. For instance, in their 1D random walk example, they proved the probability of violating the invariant was less than $5.1 \times 10^{-5}$.
  • High Confidence: In more complex 3D scenarios, they calculated violation probabilities as low as $10^{-17}$, effectively proving that termination is nearly certain.
  • Algorithmic Efficiency: They successfully reduced the complex problem of reasoning about infinite-state probabilistic systems to standard optimization problems (LP) that modern solvers can handle in seconds.

Limitations and Future Work

  • Linearity Constraint: The current framework is optimized for linear-arithmetic programs. While many programs fit this, those with non-linear dynamics (like $x := x^2 \cdot \text{sample}()$) would require non-linear RepSMs.
  • Synthesis Complexity: While checking is fast (LP), the synthesis of these invariants from scratch relies on the existential theory of reals, which can be computationally expensive for very large programs.
  • Future Directions: The authors suggest exploring polynomial repulsing supermartingales and developing more "practical" (heuristic-based) synthesis techniques to handle larger-scale software.

Summary updated

BibTeX
@inproceedings{chatterjee2017stochastic,
  author = {Krishnendu Chatterjee and Petr Novotný and Dorde Zikelic},
  title = {{Stochastic invariants for probabilistic termination}},
  booktitle = {POPL},
  year = {2017},
  doi = {10.1145/3009837.3009873},
}
Figure