Neural Termination Analysis

Mirco Giacobbe, Daniel Kroening, Julian Parsert · DOI

Introduction

Termination analysis—the task of proving that a computer program will eventually stop for any valid input—remains a fundamental challenge in computer science. While theoretically undecidable, practical approaches rely on ranking functions. These functions map program states to a well-founded domain (typically non-negative integers or reals), ensuring that the value decreases with every loop iteration. If such a function exists, the program is guaranteed to terminate.

However, traditional symbolic reasoning tools often struggle with complex loop conditions involving disjunctions (e.g., while (x < y || x < z)) or nonlinear expressions (e.g., while (x*x < n)). This paper introduces $ν$Term, a tool that leverages the pattern-matching capabilities of neural networks to "guess" ranking functions, which are then rigorously "checked" by formal solvers.

The $ν$Term Framework

The authors propose a hybrid "guess-and-check" architecture that combines the flexibility of deep learning with the absolute certainty of formal verification. The process consists of three primary stages:

  1. Tracing: The target program is executed with sampled inputs to generate execution traces—snapshots of variable values at each loop header.
  2. Learning: A Neural Ranking Function (NRF) is trained on these traces. The NRF is a feed-forward neural network with ReLU activations. A specialized loss function penalizes the model if its output does not decrease by a minimum margin ($δ$) between consecutive steps in a trace. By using non-negative weights in the final layer, the network's output is naturally bounded from below by zero.
  3. Verification: Because a trained network is an approximation, it must be formally validated. The program logic and the neural network are encoded into a Satisfiability Modulo Theories (SMT) formula. An SMT solver (Z3) then attempts to prove that the ranking function holds for all possible program states. If successful, the NRF serves as a formal certificate of termination.
The ν$Term framework: Traces are used to learn a candidate ranking function, which is then formally verified against the program code using an SMT solver.

Key Insights: The Power of Small Networks

A surprising finding of this research is that termination proofs do not require massive models. The piecewise-linear nature of ReLU activations is a natural fit for the piecewise-linear ranking functions often found in code.

Experimental results demonstrate that "tiny" networks are remarkably effective. As shown in the evaluation, increasing the number of neurons beyond a small threshold yields diminishing returns. Networks with as few as 7 to 10 neurons were sufficient to solve over 75% of the standard benchmarks. This efficiency allows $ν$Term to find and verify proofs in less than a second for many nonlinear loops where traditional tools frequently time out.

Percentage of problems solved relative to the number of neurons in the hidden layer. Performance plateaus quickly, indicating that small networks are sufficient for most termination proofs.

Evaluation and Performance

$ν$Term was evaluated against state-of-the-art symbolic tools like AProVE and Ultimate across several benchmark sets, including a new nuTerm-advantage set designed to highlight traditional weaknesses.

  • General Benchmarks: $ν$Term solved 78.4% of combined problems, performing on par with leading symbolic analyzers.
  • Nonlinear and Disjunctive Logic: On the nuTerm-advantage set, $ν$Term achieved a 92.9% success rate, vastly outperforming AProVE (21.4%) and Ultimate (7.8%).

Conclusion

By treating neural networks as generators of candidate proofs rather than black-box oracles, $ν$Term demonstrates a powerful synergy between machine learning and formal methods. While limitations remain—such as dependency on high-quality execution traces and difficulty with very large constants—the approach provides a scalable path forward for verifying complex, nonlinear software systems.

Summary updated

BibTeX
@inproceedings{giacobbe2021neural,
  author = {Mirco Giacobbe and Daniel Kroening and Julian Parsert},
  title = {{Neural Termination Analysis}},
  booktitle = {ESEC/SIGSOFT FSE},
  year = {2021},
  doi = {10.1145/3540250.3549120},
}
Figure