Termination Analysis of Probabilistic Programs through Positivstellensatz's

Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady

Introduction

In the realm of formal verification, the "Halting Problem" remains a fundamental challenge. While proving that a program will eventually terminate is undecidable in the general case, real-world software requires rigorous guarantees of completion. This task becomes significantly more complex when programs incorporate probability (randomness, such as coin flips) and nondeterminism (unpredictable choices, such as network latency or user input). This paper presents a novel framework for automatically proving the termination of such programs by synthesizing polynomial ranking functions through advanced mathematical optimization.

The Challenge of Probabilistic Termination

To prove termination, researchers typically search for a "ranking function"—a mathematical expression that decreases with every program step until a termination condition is met. For probabilistic programs, this concept evolves into Ranking Supermartingales (RSMs). An RSM is a function that decreases on average at each step, ensuring that the program will terminate with a probability of one.

Historically, automated tools have been restricted to finding linear RSMs. However, many programs utilize complex logic involving polynomials (e.g., $x^2$ or $xy$) in their guards or variable assignments. For these programs, linear functions are mathematically insufficient to prove termination. Previous attempts to handle non-linear logic were often computationally expensive or relied on heuristics that lacked scalability.

A probabilistic program with nondeterministic choices and its corresponding control flow graph.

As illustrated in the figure above, a program may contain both probabilistic branches (e.g., prob(0.51)) and nondeterministic choices (represented by *). Modeling these as a control flow graph allows for a structured analysis of state transitions, but finding a function that decreases across all possible paths requires a more sophisticated approach than simple linear modeling.

Methodology: Leveraging Positivstellensatz's

The core contribution of this research is the bridge between program analysis and convex optimization. The authors introduce a framework to synthesize Polynomial Ranking Supermartingales (pRSMs) by applying three key theorems from real algebraic geometry known as Positivstellensatz's:

  1. Schmüdgen’s and Putinar’s Positivstellensatz: These theorems allow the search for a positive polynomial to be transformed into a Semi-Definite Programming (SDP) problem. SDP is a powerful optimization technique that can be solved efficiently in polynomial time.
  2. Handelman’s Theorem: In cases where the program logic is linear but the ranking function must be polynomial, Handelman’s Theorem enables the use of Linear Programming (LP). LP is faster and more numerically stable than SDP, making the analysis nearly instantaneous for a specific class of programs.

By utilizing these theorems, the authors can define a polynomial "template" (such as $ax^2 + bxy + c$) and use standard solvers like CPLEX or SOSTOOLS to find the coefficients that satisfy the termination requirements.

Experimental Evaluation

The algorithm was evaluated against a suite of six classical benchmark programs known for their analytical difficulty, including the Gambler’s Ruin, Random Walk (within non-linear regions), and the Logistic Map (a chaotic system).

The results demonstrated both versatility and high efficiency:

  • Speed: Many proofs were synthesized in under 0.01 seconds using Linear Programming. Even complex SDP tasks typically concluded in less than a second.
  • Power: The tool successfully handled the Logistic Map, which previously required much more complex Lagrangian relaxation techniques.
  • New Capabilities: The method synthesized quadratic ranking functions for programs where linear ones were mathematically proven not to exist, such as specific variants of the Gambler's Ruin.
  • Concentration Bounds: Beyond proving termination, the method can calculate mathematical guarantees on the likelihood of a program running beyond a certain duration.

Key Insights and Future Work

A primary takeaway of this work is that linearity is often a dead end for complex program verification; polynomials are essential for capturing the nuances of stochastic behavior. By reframing the logic problem as an optimization search, the authors have created a significant shortcut in program analysis.

However, challenges remain. Current Semi-Definite Programming solvers can struggle with numerical precision, and the "invariants" (logical facts about program state) used in this study were manually provided. Future work will focus on automating invariant discovery and improving the numerical stability of the underlying solvers to handle an even broader class of probabilistic systems.

Summary updated

BibTeX
@inproceedings{chatterjee2016termination,
  author = {Krishnendu Chatterjee and Hongfei Fu and Amir Kafshdar Goharshady},
  title = {{Termination Analysis of Probabilistic Programs through Positivstellensatz's}},
  booktitle = {CAV},
  year = {2016},
  doi = {10.1007/978-3-319-41528-4\_1},
}
Figure