Affine Loop Invariant Generation via Matrix Algebra - Archive ouverte HAL Access content directly
Preprints, Working Papers, ... Year :

Affine Loop Invariant Generation via Matrix Algebra


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.
Fichier principal
Vignette du fichier
loop-20220525-long.pdf (519.57 Ko) Télécharger le fichier
Origin : Files produced by the author(s)

Dates and versions

hal-03494611 , version 1 (19-12-2021)
hal-03494611 , version 2 (25-05-2022)


  • HAL Id : hal-03494611 , version 2


Yucheng Ji, Hongfei Fu, Bin Fang, Haibo Chen. Affine Loop Invariant Generation via Matrix Algebra. 2022. ⟨hal-03494611v2⟩
309 View
183 Download


Gmail Facebook Twitter LinkedIn More