Invariant and Type Inference for Matrices

  • Thomas A. Henzinger
  • Thibaud Hottelier
  • Laura Kovács
  • Andrei Voronkov
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5944)


We present a loop property generation method for loops iterating over multi-dimensional arrays. When used on matrices, our method is able to infer their shapes (also called types), such as upper-triangular, diagonal, etc. To generate loop properties, we first transform a nested loop iterating over a multi-dimensional array into an equivalent collection of unnested loops. Then, we infer quantified loop invariants for each unnested loop using a generalization of a recurrence-based invariant generation technique. These loop invariants give us conditions on matrices from which we can derive matrix types automatically using theorem provers. Invariant generation is implemented in the software package Aligator and types are derived by theorem provers and SMT solvers, including Vampire and Z3. When run on the Java matrix package JAMA, our tool was able to infer automatically all matrix types describing the matrix shapes guaranteed by JAMA’s API.


Theorem Prover Nest Loop Matrix Type Proof Obligation Invariant Generation 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Beyer, D., Henzinger, T., Majumdar, R., Rybalchenko, A.: Invariant Synthesis for Combined Theories. In: Cook, B., Podelski, A. (eds.) VMCAI 2007. LNCS, vol. 4349, pp. 346–362. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  2. 2.
    Birkeland, B.: Calculus and Algebra with MathCad 2000. Haeftad. Studentlitteratur (2000)Google Scholar
  3. 3.
    Buchberger, B.: An Algorithm for Finding the Basis Elements of the Residue Class Ring of a Zero Dimensional Polynomial Ideal. J. of Symbolic Computation 41(3-4), 475–511 (2006)zbMATHCrossRefMathSciNetGoogle Scholar
  4. 4.
    Danaila, I., Joly, P., Kaber, S.M., Postel, M.: An Introduction to Scientific Computing: Twelve Computational Projects Solved with MATLAB. Springer, Heidelberg (2007)zbMATHGoogle Scholar
  5. 5.
    de Moura, L., Bjorner, N.: Z3: An Efficient SMT Solver. In: Ramakrishnan, C.R., Rehof, J. (eds.) TACAS 2008. LNCS, vol. 4963, pp. 337–340. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  6. 6.
    Denney, E., Fischer, B.: A Generic Annotation Inference Algorithm for the Safety Certification of Automatically Generated Code. In: GPCE, pp. 121–130 (2006)Google Scholar
  7. 7.
    Dijkstra, E.W.: Guarded Commands, Nondeterminacy and Formal Derivation of Programs. Communications of the ACM 18(8), 453–457 (1975)zbMATHCrossRefMathSciNetGoogle Scholar
  8. 8.
    Flanagan, C., Qadeer, S.: Predicate Abstraction for Software Verification. In: Proc. of POPL, pp. 191–202 (2002)Google Scholar
  9. 9.
    Golub, G.H., van Loan, C.F.: Matrix Computations. Johns Hopkins Univ. Press (1996)Google Scholar
  10. 10.
    Gopan, D., Reps, T.W., Sagiv, M.: A Framework for Numeric Analysis of Array Operations. In: Proc. of POPL, pp. 338–350 (2005)Google Scholar
  11. 11.
    Gulwani, S., McCloskey, B., Tiwari, A.: Lifting Abstract Interpreters to Quantified Logical Domains. In: Proc. of POPL, pp. 235–246 (2008)Google Scholar
  12. 12.
    Halbwachs, N., Peron, M.: Discovering Properties about Arrays in Simple Programs. In: Proc. of PLDI, pp. 339–348 (2008)Google Scholar
  13. 13.
    Hicklin, J., Moler, C., Webb, P., Boisvert, R.F., Miller, B., Pozo, R., Remington, K.: JAMA: A Java Matrix Package (2005),
  14. 14.
    Jhala, R., McMillan, K.L.: Array Abstractions from Proofs. In: Damm, W., Hermanns, H. (eds.) CAV 2007. LNCS, vol. 4590, pp. 193–206. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  15. 15.
    Korovin, K.: iProver - An Instantiation-based Theorem Prover for First-order Logic. In: Proc. of IJCAR, pp. 292–298 (2009)Google Scholar
  16. 16.
    Korovin, K., Voronkov, A.: Integrating Linear Arithmetic into Superposition Calculus. In: Duparc, J., Henzinger, T.A. (eds.) CSL 2007. LNCS, vol. 4646, pp. 223–237. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  17. 17.
    Kovacs, L.: Aligator: A Mathematica Package for Invariant Generation. In: Armando, A., Baumgartner, P., Dowek, G. (eds.) IJCAR 2008. LNCS (LNAI), vol. 5195, pp. 275–282. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  18. 18.
    Kovacs, L.: Reasoning Algebraically About P-Solvable Loops. In: Ramakrishnan, C.R., Rehof, J. (eds.) TACAS 2008. LNCS, vol. 4963, pp. 249–264. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  19. 19.
    Kovacs, L., Voronkov, A.: Finding Loop Invariants for Programs over Arrays Using a Theorem Prover. In: Chechik, M., Wirsing, M. (eds.) FASE 2009. LNCS, vol. 5503, pp. 470–485. Springer, Heidelberg (2009)Google Scholar
  20. 20.
    Kuncak, V., Rinard, M.: An overview of the Jahob analysis system: Project goals and current status. In: NSF Next Generation Software Workshop (2006)Google Scholar
  21. 21.
    McMillan, K.L.: Quantified Invariant Generation Using an Interpolating Saturation Prover. In: Ramakrishnan, C.R., Rehof, J. (eds.) TACAS 2008. LNCS, vol. 4963, pp. 413–427. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  22. 22.
    Müller-Olm, M., Seidl, H.: Computing Polynomial Program Invariants. Indormation Processing Letters 91(5), 233–244 (2004)zbMATHCrossRefGoogle Scholar
  23. 23.
    Riazanov, A., Voronkov, A.: The Design and Implementation of Vampire. AI Communications 15(2-3), 91–110 (2002)zbMATHGoogle Scholar
  24. 24.
    Rodriguez-Carbonell, E., Kapur, D.: Generating All Polynomial Invariants in Simple Loops. J. of Symbolic Computation 42(4), 443–476 (2007)zbMATHCrossRefMathSciNetGoogle Scholar
  25. 25.
    Sankaranaryanan, S., Sipma, H.B., Manna, Z.: Non-Linear Loop Invariant Generation using Gröbner Bases. In: Proc. of POPL, pp. 318–329 (2004)Google Scholar
  26. 26.
    Schulz, S.: E — a brainiac theorem prover. AI Communications 15(2-3), 111–126 (2002)zbMATHGoogle Scholar
  27. 27.
    Srivastava, S., Gulwani, S.: Program Verification using Templates over Predicate Abstraction. In: Proc. of PLDI, pp. 223–234 (2009)Google Scholar
  28. 28.
    Stewart, G.W.: JAMPACK: A Java Package For Matrix Computations,
  29. 29.
    Sutcliffe, G.: The TPTP Problem Library and Associated Infrastructure. The FOF and CNF Parts, v3.5.0. J. of Automated Reasoning (to appear, 2009)Google Scholar
  30. 30.
    Wolfram, S.: The Mathematica Book. Version 5.0. Wolfram Media (2003)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Thomas A. Henzinger
    • 1
  • Thibaud Hottelier
    • 2
  • Laura Kovács
    • 3
  • Andrei Voronkov
    • 4
  1. 1.IST Austria (Institute of Science and TechnologyAustria)
  2. 2.UC Berkeley 
  3. 3.ETH Zürich 
  4. 4.University of Manchester 

Personalised recommendations