Polynomial invariant generation for non-deterministic recursive programs

Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady, Ehsan Kafshdar Goharshady

Abstract

This paper presents a significant advancement in formal verification: a sound and semi-complete method for automatically generating polynomial invariants for programs featuring non-determinism and recursion. By leveraging deep results from real algebraic geometry, specifically Putinar’s Positivstellensatz, the authors reduce the complex problem of invariant synthesis to a Quadratic Constrained Linear Programming (QCLP) problem. This approach achieves subexponential complexity, a major improvement over previous complete methods that were limited by doubly-exponential runtimes.

Introduction

In software verification, an invariant is a condition that holds true at a specific point in a program's execution regardless of the path taken. Finding these invariants is critical for proving safety properties in complex systems. While linear invariants (e.g., $x + y < 10$) are well-understood, modern applications in robotics and control systems often require polynomial invariants (e.g., $x^2 + y^2 < r^2$).

Existing approaches to polynomial invariant generation typically face a trade-off: they are either fast but incomplete (failing to find existing invariants) or complete but computationally infeasible due to reliance on doubly-exponential quantifier elimination. Furthermore, most tools struggle with recursion and non-determinism. This work addresses these challenges by shifting the problem from symbolic logic to numerical optimization.

A comparison of the proposed approach against existing state-of-the-art methods, highlighting its unique combination of polynomial support, recursion handling, and subexponential complexity.

Methodology

The authors propose a four-step workflow to synthesize invariants:

  1. Template Generation: Unknown coefficients are used to create a "template" polynomial for each program location.
  2. Constraint Encoding: Mathematical constraints are generated to ensure these templates are inductive—meaning if the property holds before a step, it must hold after.
  3. Positivstellensätze Application: The authors use Putinar’s Positivstellensatz to transform the "always positive" requirement into a Sum-of-Squares (SOS) representation. This effectively converts a logical property into an algebraic one.
  4. Reduction to QCLP: The problem is reduced to Quadratic Programming, allowing the use of highly efficient industrial solvers.

For recursive programs, the framework simultaneously synthesizes post-conditions for functions, treating recursive calls as abstract paths that must satisfy the synthesized conditions.

A control flow graph (CFG) illustrating the type of non-deterministic and looping program structures handled by the proposed invariant generation framework.

Key Results and Evaluation

The tool was evaluated on standard academic benchmarks, Reinforcement Learning (RL) safety verification tasks, and recursive programs. Key findings include:

  • Efficiency: On standard benchmarks, the tool typically generated invariants in under a minute.
  • Superiority over State-of-the-Art: Previous complete methods timed out on nearly all benchmarks where this tool succeeded. It was the only tool capable of handling the high-degree polynomial guards found in RL benchmarks.
  • Complexity Handling: The tool successfully generated degree-5 polynomial invariants for a recursive program approximating $\sqrt{2}$ via continued fractions, a task beyond the reach of prior automated tools.
  • Theoretical Breakthrough: The authors proved that for rational coefficients, the problem can be solved in subexponential time, a massive improvement over the previous doubly-exponential standard.

Discussion and Limitations

While the method is a major step forward, it relies on a "compactness assumption"—assuming program variables stay within some large but finite bounds. In practice, this is rarely a limitation for physical hardware. However, the tool's reliance on QCLP solvers makes it sensitive to numerical stability, necessitating verification of outputs with infinite-precision arithmetic. Future work will focus on improving solver integration and optimizing for massive codebases by exploiting sparsity in control flow graphs.

Summary updated

BibTeX
@inproceedings{chatterjee2019polynomial,
  author = {Krishnendu Chatterjee and Hongfei Fu and Amir Kafshdar Goharshady and Ehsan Kafshdar Goharshady},
  title = {{Polynomial invariant generation for non-deterministic recursive programs}},
  booktitle = {PLDI},
  year = {2019},
  doi = {10.1145/3385412.3385969},
}
Figure