LLM-Guided Loop Bound Generation for Program Termination Verification

Zan Gong, Biting Huang, Fei HeICML 2026

Introduction

In software verification, proving that a program will eventually finish—known as termination—is a fundamental "liveness" property. However, as Alan Turing famously proved in 1937 with the Halting Problem, this is an undecidable problem. There is no single algorithm that can determine if any arbitrary program will stop.

Traditionally, researchers have relied on ranking functions to prove termination. These are mathematical mappings that must strictly decrease with every loop iteration until they hit a predefined floor. While powerful, ranking functions are highly fragile: a tiny error in the mathematical expression invalidates the entire proof. Large Language Models (LLMs), despite their impressive coding capabilities, are prone to these small semantic errors. Furthermore, when an LLM proposes an incorrect proof, existing systems often fall into a "refutation gap," fruitlessly trying to prove a false statement instead of realizing the guess was wrong and iterating.

To overcome these challenges, researchers have introduced LIFT (Loop-bound Inference Framework for Termination), a novel framework that shifts the verification target from fragile ranking functions to more stable "loop bounds," backed by a rigorous formal verification feedback loop.

The LIFT Framework: A Guess-and-Check Workflow

LIFT operates on a sophisticated guess-and-check mechanism that pairs the creative generation capabilities of LLMs with the strict mathematical guarantees of formal solvers.

1. The Guess (LLM Generation): Instead of asking the LLM to generate exact ranking functions, LIFT asks it to generate loop bounds—expressions that estimate the maximum number of times a loop might execute. Loop bounds are inherently more stable because they only need to be conservative over-approximations. This provides a much friendlier and more forgiving target for LLMs.

2. The Check (Formal Validation): Once a bound is guessed, LIFT instruments the program with a counter based on the LLM's estimate. If the counter ever hits zero while the loop is still running, the bound is invalid. LIFT uses a combination of ICE-DT (a data-driven invariant learner) and SMT solvers to formally prove whether the bound holds across all possible executions.

3. The Feedback Loop (Bounded Violation Analysis): If the formal validator fails, LIFT does not simply time out or give up. It performs Bounded Violation Analysis to find a concrete "witness"—a specific set of variable values proving the bound was too small. This witness is fed back to the LLM as diagnostic feedback, allowing the model to learn from its mistake and generate a better bound in the next iteration.

Key Innovations

LIFT's success is driven by several core insights that optimize how LLMs interact with formal verifiers:

  • Stability over Precision: The shift from ranking functions to loop bounds is a critical breakthrough. Because a loop bound doesn't have to be exact (e.g., a bound of 100 is perfectly valid for a loop that only runs 10 times), the LLM has a much wider margin for error.
  • Closing the Refutation Gap: Most LLM-based verifiers fail because they cannot definitively prove a guess is wrong. LIFT’s ability to generate concrete violation witnesses closes this gap, enabling true iterative learning.
  • The "Const-Offset" Heuristic: Researchers observed that LLMs often deduce the correct logic but miss by a minor constant (e.g., guessing $x$ instead of $x+1$). LIFT incorporates a simple heuristic to automatically test small offsets, saving expensive LLM API calls and inference time.
  • Progressive Strategy: LIFT acts as a semantic scaffold by starting with requests for simple linear bounds. If those fail, it progressively moves to more complex "lexicographic" bounds (tuples of counters), preventing the LLM from over-complicating simple loops while providing structure for harder ones.

Experimental Results

LIFT was evaluated on a standard, publicly accessible termination benchmark suite consisting of 171 terminating programs designed to test the limits of automated verification tools.

  • State-of-the-Art Performance: Powered by Gemini-2.5-Flash, LIFT successfully verified 161 out of 171 benchmarks. This significantly outperforms the best conventional "white-box" tool, DDLTERM (134 solved), and the best previous LLM-based tool, PROTON 2.1 (144 solved).
  • Exclusive Solves: LIFT demonstrated strict superiority by solving numerous problems that all other baseline tools failed on, whereas the reverse was rarely true.
  • Model Agnosticism: The framework is robust across different LLM architectures. While Gemini performed best, LIFT also achieved strong results using DeepSeek-V3.1 (142 solved).
  • Mathematical Soundness: Unlike previous LLM approaches that rely on "bounded checks" (proving termination for only a few steps), LIFT's SMT-based verification ensures the termination proof is mathematically sound for all possible program executions.

Limitations and Future Work

While LIFT represents a major leap forward, it has a few limitations. Like all LLM-based systems, it suffers from higher latency compared to traditional tools due to model inference times and multiple feedback rounds. Additionally, if an LLM generates a bound involving complex nonlinear arithmetic (such as $x^2$ or trigonometric functions), current SMT solvers often struggle to validate it. Finally, while LIFT excels on logically dense benchmarks, scaling the framework to handle massive industrial codebases with thousands of interacting loops remains an exciting challenge for future research.

Summary updated

BibTeX
@inproceedings{gong2026llm,
  author = {Zan Gong and Biting Huang and Fei He},
  title = {{LLM-Guided Loop Bound Generation for Program Termination Verification}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=ym8FNvY5z4},
}
Figure