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 Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
3 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Array-Carrying Symbolic Execution for Function Contract Generation cites Polynomial invariant generation for non-deterministic recursive programs
- Array-Carrying Symbolic Execution for Function Contract Generation cites LLM-Generated Invariants for Bounded Model Checking Without Loop Unrolling
- Array-Carrying Symbolic Execution for Function Contract Generation cites Polynomial reachability witnesses via Stellensätze
- Demystifying Template-Based Invariant Generation for Bit-Vector Programs cites Polynomial invariant generation for non-deterministic recursive programs
- Demystifying Template-Based Invariant Generation for Bit-Vector Programs cites Interval counterexamples for loop invariant learning
- Demystifying Template-Based Invariant Generation for Bit-Vector Programs cites Templates and recurrences: better together
- LLM-Generated Invariants for Bounded Model Checking Without Loop Unrolling cites Polynomial invariant generation for non-deterministic recursive programs
- Polynomial reachability witnesses via Stellensätze cites Polynomial invariant generation for non-deterministic recursive programs
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
