arXiv:2610.35523cs.SEOct 2026

Manuscript Offprint

arXiv:2610.35523

Ranking Function Generation with LLMs for Termination

Rongkang Li, Jiaxin Hu, Taolue Chen, Yong Li, Fu Song, Zhilin Wu

RONGKANG LI*, Key Laboratory of System Software (Chinese Academy of Sciences), China, Institute of Software, Chinese Academy of Sciences, China, and University of Chinese Academy of Sciences, China

JIAXIN HU†, Key Laboratory of System Software (Chinese Academy of Sciences), China, Institute of Software, Chinese Academy of Sciences, China, and University of Chinese Academy of Sciences, China

TAOLUE CHEN, School of Computing and Mathematical Sciences, Birkbeck, University of London, UK

YONG LI‡, Key Laboratory of System Software (Chinese Academy of Sciences), China, Institute of Software, Chinese Academy of Sciences, China, and University of Chinese Academy of Sciences, China

FU SONG§¶, Key Laboratory of System Software (Chinese Academy of Sciences), China, Institute of Software, Chinese Academy of Sciences, China, and University of Chinese Academy of Sciences, China

ZHILIN WU, Key Laboratory of System Software (Chinese Academy of Sciences), China, Institute of Software, Chinese Academy of Sciences, China, and University of Chinese Academy of Sciences, China

Ranking functions are a fundamental technique for proving loop termination, but constructing them manually is challenging and requires substantial expertise. Existing automated approaches are limited when handling, for instance, nonlinear updates and complex control flows in real-world programs. Meanwhile, large language models (LLMs) have recently demonstrated remarkable capabilities across a wide range of software engineering tasks. Motivated by these advances, we explore LLM-based ranking function generation for proving loop termination, a key component of establishing total program correctness.

We propose RAINFALL, a neuro-symbolic framework which follows the generate-verify-refine paradigm and tightly integrates LLMs with symbolic verification. RAINFALL formulates ranking function synthesis as a code-completion task by inserting placeholders into the input program and constraining the LLM to fill four predefined slots for each loop. The completed program is then checked by a symbolic verifier. If

*Also with Nanjing Institute of Software Technology.

†Also with Nanjing Institute of Software Technology.

‡Corresponding author.

§ Also with Nanjing Institute of Software Technology.

¶Corresponding author.

Authors' Contact Information: Rongkang Li, Key Laboratory of System Software (Chinese Academy of Sciences), Beijing, China and Institute of Software, Chinese Academy of Sciences, Beijing, China, lirongkang25@mails.ucas.ac.cn and University of Chinese Academy of Sciences, Beijing, China; Jiaxin Hu, Key Laboratory of System Software (Chinese Academy of Sciences), Beijing, China and Institute of Software, Chinese Academy of Sciences, Beijing, China, hjx18061369179@126.com and University of Chinese Academy of Sciences, Beijing, China; Taolue Chen, School of Computing and Mathematical Sciences, Birkbeck, University of London, London, UK, t.chen@bbk.ac.uk; Yong Li, Key Laboratory of System Software (Chinese Academy of Sciences), Beijing, China and Institute of Software, Chinese Academy of Sciences, Beijing, China, liyong@ios.ac.cn and University of Chinese Academy of Sciences, Beijing, China; Fu Song, Key Laboratory of System Software (Chinese Academy of Sciences), Beijing, China and Institute of Software, Chinese Academy of Sciences, Beijing, China, songfu@ios.ac.cn and University of Chinese Academy of Sciences, Beijing, China; Zhilin Wu, Key Laboratory of System Software (Chinese Academy of Sciences), Beijing, China and Institute of Software, Chinese Academy of Sciences, Beijing, China, wuzl@ios.ac.cn and University of Chinese Academy of Sciences, Beijing, China.

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.

© 2026 Copyright held by the owner/author(s). Publication rights licensed to ACM.

ACM XXXX-XXXX/2026/10-ART

https://doi.org/10.1145/nnnnnnn.nnnnnnn

Li et al.

verification succeeds, a valid ranking function is obtained; otherwise, the verifier's diagnostics are translated into natural-language feedback that guides iterative refinement of the LLM's output.

We evaluate RAINFALL on two public benchmark suites comprising 358 terminating C programs. Using MiniMax V2.7, RAINFALL synthesizes verifiable ranking functions for 323 programs (90.22%), outperforming all promising baselines. In particular, it solves 12 more programs than PROTON 2.1, the best-performing baseline and winner of the SV-COMP 2026 Termination category. Furthermore, combining RAINFALL with PROTON 2.1 increases the success rate to 96.65% (346/358 programs). We also conduct ablation study confirming individual contributions of placeholder contracts, few-shot examples, symbolic verification, and diagnostic information feedback. Experiments across LLMs further confirm the effectiveness of RAINFALL.

Our results suggest a generic, sound framework for ranking-function synthesis and, beyond termination, LLM-assisted synthesis of formally checkable liveness certificates, both of which represent new directions of software engineering research.

CCS Concepts: • Software and its engineering → Software verification; • Theory of computation → Automated reasoning; Logic and verification; • Computing methodologies → Knowledge representation and reasoning.

Additional Key Words and Phrases: Program termination, Software verification, Large language model, Ranking function

ACM Reference Format:

Rongkang Li, Jiaxin Hu, Taolue Chen, Yong Li, Fu Song, and Zhilin Wu. 2026. Ranking Function Generation with LLMs for Termination. 1, 1 (October 2026), 24 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn

1 Introduction

Program termination is a fundamental liveness property for ensuring software reliability and total correctness [38], and plays an important role in software verification [10, 35, 79]. While program termination is undecidable in general [81], automated techniques have been developed over the years to prove termination for many classes of programs. A standard approach is to synthesize a ranking function that maps program states to a well-founded set such that the function value strictly decreases with each loop iteration and is bounded below by a constant. The existence of such a function (referred to as a valid ranking function) guarantees that the loop can execute only finitely many times when the bound entails the termination of the loop.

Classical symbolic techniques for ranking function synthesis typically formulate the problem as constraint solving over predefined parameterized ranking templates, such as linear expressions, lexicographic orders, or multiphase combinations [13, 15, 21, 47, 57, 62, 76, 77]. Instantiating the ranking template with a satisfying assignment gives rise to a ranking function. While these approaches have been largely successful, their effectiveness heavily depends on the availability of suitable templates. In practice, designing new ranking templates for diverse loop programs remains challenging and continues to be an active area of research (cf., e.g. [62]). In general, classical approaches often require substantial manual effort or expensive template exploration, which limits their scalability and degree of automation.

To address these limitations, recent work has explored leveraging machine learning, particularly (pre-trained) Large Language Models (LLMs), to generate ranking functions. This is motivated by the remarkable capabilities in assisting software development tasks [26, 45, 51, 78, 84], including specification and loop invariant generation [24, 33, 36, 41, 44, 54, 56, 64, 65, 68, 69, 71, 72, 75].

For instance, [8, 40] train neural networks as candidate ranking functions, which are subsequently verified via SMT solving to ensure soundness. These techniques heavily rely on the quality and quantity of execution traces for training neural networks. [39] trains neural networks to simultaneously represent ranking functions and inductive invariants. Unlike earlier approaches, they do not require execution traces. Instead, the neural networks are trained through a sequence of

MILP solving in a counterexample-guided inductive synthesis loop and are designed for hardware verification rather than proving termination of software programs. Note that the decision variant of MILP is NP-complete.

PROTON 2.1 [73] fine-tunes the Llama-3.2-1B-Instruct model to generate candidate ranking functions. Its effectiveness, however, is limited by the relatively small model size (1B-parameter), the small-scale fine-tuning dataset (321 programs) and the restricted reasoning context. LOOPY [53], in contrast, prompts LLMs to generate loop invariants and candidate ranking functions directly from natural-language definitions, and then identifies valid candidates using Frama-C [12]. As an early attempt, LOOPY primarily focuses on loop invariant generation and only utilizes the feedback produced by Frama-C to repair incorrect invariants. When a candidate ranking function is incorrect, LOOPY initiates a new interaction with the LLM without incorporating the verification feedback. Although LOOPY has demonstrated the potential of LLMs for ranking function generation, its effectiveness remains limited. Even after embedding expert knowledge (i.e., natural language description of lexicographic and multi-phase ranking functions) into prompts, LOOPY only solves 181 out of 281 benchmarks, much fewer than the state-of-the-art symbolic baseline UAutomizer [48], which solves 236 benchmarks.

There are two major challenges in effectively leveraging LLM for ranking function generation.

• Challenge 1: limited LLM capability. LLMs generate outputs based on statistical patterns learned from training data. As training data usually consists of large-scale natural language text and code corpora, LLMs typically perform well on tasks such as natural language processing and code generation. In contrast, ranking functions are relatively underexplored and is not supported by large or representative training datasets. Consequently, LLMs may have limited capability in reasoning about ranking functions and often struggle with complicated or subtle definitions expressed in natural language. Indeed, out-of-the-box Llama-1B failed to synthesize valid ranking functions even for trivial programs [73].

• Challenge 2: identifying and resolving incorrect outputs. Despite the promising performance of LLMs for code generation, they frequently generate incorrect code, often due to limited reasoning context. A particular serious issue is hallucinations [86] where LLMs generate outputs that appear plausible but fail to satisfy the intended specification [23, 43]. For instance, GPT-4 has been shown to generate incomplete assertions as post-conditions so that buggy programs do not violate them [36]. We indeed observe similar behavior in our experiments, highlighting the development of techniques that can effectively identify and correct such subtle errors with minimal interaction overhead.

Our work. To tackle these challenges, we propose a neuro-symbolic framework, RAINFALL (RAnkING Function generation with LLM), within the generate-verify-refine paradigm, which combines the generative capabilities of modern LLMs with the rigor of symbolic techniques. This integration enables RAINFALL to discover richer termination arguments and prove termination for a broader class of loop programs. We remark that LLM fine-tuning could also be adopted, as demonstrated by PROTON 2.1. We avoid fine-tuning because it is not only cost- and resource-intensive, but also requires large-scale, high-quality training datasets, which otherwise risks overfitting.

Specifically, to address the first challenge, RAINFALL first transforms the synthesis of ranking functions into a code-assertion generation problem, motivated by the observation that LLMs are very effective in code and specification generation. This transformation avoids requiring LLMs to interpret complicated definitions of ranking functions and improves the quality of the generated candidate ranking functions. Second, we embed expert knowledge about termination arguments (e.g., lexicographic and multi-phase ranking functions) with few-shot examples into structured

Li et al.

prompts which can enhance the reasoning ability and in-context learning of LLMs for code-assertion generation.

To address the second challenge, we present a symbolic verification pipeline which checks whether the LLM outputs satisfy the required correctness criteria, thereby providing soundness guarantees. In this pipeline, we first ensure that the LLM does not modify the original program by applying a lightweight, syntactic equivalence check. This step prevents potential cheating where the LLM modifies the program and generates assertions that hold only in the modified version. After this, we check the completeness of the generated code-assertion statements required to induce a ranking function (e.g., whether assertions include strict decrease, non-negativity and termination conditions). Without these conditions, valid ranking functions cannot be extracted even if the program satisfies the assertions (e.g., an LLM outputs true as the assertion, which would not be useful). Finally, we verify whether the program satisfies the assertions via safety checking. To repair incorrect outputs with minimal interactions, we re-prompt LLMs by incorporating fine-grained diagnostic information (e.g., the detected program modification, missing ranking function conditions, or counterexample produced by the safety verifier). The corresponding ranking functions can then be extracted and used as a witness to program termination. Remark that we do not copy the LLM-generated code-assertions into the original program and then verify them using the later checks because such code-assertions typically cannot induce a valid ranking function and subsequent checks would incur substantial computational overhead.

We evaluate RAINFALL on two public benchmark suites comprising 358 terminating C programs. Using MiniMax (V2.7) [5], RAINFALL generates verifiable ranking functions for 323 programs (90.22%), outperforming six state-of-the-art tools such as AProVE [66] (78.77%), UAutomizer (79.05%), LOOPY (73.74%) and PROTON 2.1 (86.87%). Ablation studies confirm that formulating ranking-function synthesis as a code-assertion generation task, together with few-shot examples and diagnostic information feedback is critical to this performance. We further show that RAINFALL remains effective across LLMs (e.g., proved more programs in less time using GPT V5.5 [4] and Claude-Opus V4.7 [2]) and complements other tools (e.g., a 96.65% success rate, solving 346 tasks when combined with the symbolic counterpart of PROTON 2.1).

This paper focuses on synthesizing ranking functions for proving termination of loop programs using three common classes of ranking functions. More broadly, however, our promising results point toward a generic, sound framework for ranking-function synthesis and, beyond termination, LLM-assisted synthesis of formally checkable liveness certificates, both of which represent frontiers of software engineering research.

First, the framework naturally accommodates new classes of ranking functions. Rather than developing specialized synthesis algorithms for each new class, one can extend the structured prompts with domain knowledge and few-shot examples, while adapting only the symbolic verification stage to the corresponding proof obligations. This substantially lowers the engineering effort required to support richer ranking-function templates.

Second, ranking functions have already been generalized beyond loop termination, serving as certificates for software progress properties [30] and, more recently, as neural certificates for liveness properties of hardware designs [39]. In this broader setting, RAINFALL illustrates a promising neuro-symbolic methodology in which LLMs propose expressive candidate proof artifacts, while symbolic verification guarantees soundness through validation and iterative refinement. The strong empirical performance of RAINFALL, together with its complementarity with existing symbolic termination tools, suggests that LLM-assisted certificate synthesis could extend beyond termination to the verification of progress, fairness, response, and other temporal properties of software systems.

Finally, although this paper considers only unconditional termination, the same framework could potentially be extended to infer termination conditions by integrating recent advances in conditional termination analysis [52].

Summary. This paper makes the following contributions:

  • A new perspective that reformulates ranking-function synthesis as a code-assertion generation task, enabling a seamless integration of LLM generation with sound symbolic techniques.

  • A novel neuro-symbolic framework within the generate-verify-refine paradigm, which combines expert knowledge, few-shot examples, symbolic checking, and diagnostic information to guide generation, suppress hallucinations and ensure soundness.

• An extensive evaluation showing that RAINFALL outperforms six state-of-the-art tools including LLM-based ones and top-3 tools of SV-COMP 2026 termination category.

Structure. Section 2 reviews the basic definition of rank functions. Section 3 reviews the related work, which also introduces more technical background. Section 4 presents the RAINFALL approach. Section 5 reports the experimental results and discusses potential threats to the validity of the work. Finally, Section 6 concludes the paper.

References (46)