Affine Loop Invariant Generation via Matrix Algebra
Yucheng Ji, Hongfei Fu, Bin Fang, Haibo Chen
Abstract
Abstract Loop invariant generation, which automates the generation of assertions that always hold at the entry of a while loop, has many important applications in program analysis and formal verification. In this work, we target an important category of while loops, namely affine while loops, that are unnested while loops with affine loop guards and variable updates. Such a class of loops widely exists in many programs yet still lacks a general but efficient approach to invariant generation. We propose a novel matrix-algebra approach to automatically synthesizing affine inductive invariants in the form of an affine inequality. The main novelty of our approach is that (i) the approach is general in the sense that it theoretically addresses all the cases of affine invariant generation over an affine while loop, and (ii) it can be efficiently automated through matrix-algebra (such as eigenvalue, matrix inverse) methods. The details of our approach are as follows. First, for the case where the loop guard is a tautology (i.e., ‘true’), we show that the eigenvalues and their eigenvectors of the matrices derived from the variable updates of the loop body encompass all meaningful affine inductive invariants. Second, for the more general case where the loop guard is a conjunction of affine inequalities, our approach completely addresses the invariant-generation problem by first establishing through matrix inverse the relationship between the invariants and a key parameter in the application of Farkas’ lemma, then solving the feasible domain of the key parameter from the inductive conditions, and finally illustrating that a finite number of values suffices for the key parameter w.r.t a tightness condition for the invariants to be generated. Experimental results show that compared with previous approaches, our approach generates much more accurate affine inductive invariants over affine while loops from existing and new benchmarks within a few seconds, demonstrating the generality and efficiency of our approach.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Cited by top-tier papers3
- LLM-Generated Invariants for Bounded Model Checking Without Loop UnrollingMuhammad A. A. Pirzada, Giles Reger, Ahmed Bhayat, Lucas C. CordeiroASE 2024 · 7 citations
- Demystifying Template-Based Invariant Generation for Bit-Vector ProgramsPeisen Yao, Jingyu Ke, Jiahui Sun, Hongfei Fu et al.ASE 2023 · 3 citations
- Array-Carrying Symbolic Execution for Function Contract GenerationWeijie Lu, Jingyu Ke, Hongfei Fu, Zhouyue Sun et al.FM 2026
Builds on10
- Polynomial invariant generation for non-deterministic recursive programsKrishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady, Ehsan Kafshdar GoharshadyPLDI 2020 · 46 citations
- Templates and recurrences: better togetherJason Breck, John Cyphert, Zachary Kincaid, Thomas W. RepsPLDI 2020 · 30 citations
- Polynomial reachability witnesses via StellensätzeAli Asadi, Krishnendu Chatterjee, Hongfei Fu, Amir Kafshdar Goharshady et al.PLDI 2021 · 28 citations
- Interval counterexamples for loop invariant learningRongchen Xu, Fei He, Bow-Yaw WangFSE 2020 · 19 citations
- What's decidable about linear loops?Toghrul Karimov, Engel Lefaucheux, Joël Ouaknine, David Purser et al.POPL 2022 · 19 citations
Related papers
- Scalable linear invariant generation with Farkas' lemmaHongming Liu, Hongfei Fu, Zhiyong Yu, Jiaxin Song et al.OOPSLA 2022 · 15 citations
- Simple Linear Loops: Algebraic Invariants and ApplicationsRida Ait El Manssour, George Kenison, Mahsa Shirmohammadi, Anton VaronkaPOPL 2025 · 2 citations
- Solvable Polynomial Ideals: The Ideal Reflection for Program AnalysisJohn Cyphert, Zachary KincaidPOPL 2024 · 11 citations
- Clause2Inv: A Generate-Combine-Check Framework for Loop Invariant InferenceWeining Cao, Guangyuan Wu, Tangzhi Xu, Yuan Yao et al.ISSTA 2025 · 2 citations
- Multi-phase invariant synthesisDaniel Riley, Grigory FedyukovichFSE 2022 · 13 citations
