Templates and recurrences: better together

This paper is the confluence of two streams of ideas in the literature on generating numerical invariants, namely: (1) template-based methods, and (2) recurrence-based methods. A template-based method begins with a template that contains unknown quantities, and finds invariants that match the template by extracting and solving constraints on the unknowns. A disadvantage of template-based methods is that they require fixing the set of terms that may appear in an invariant in advance. This disadvantage is particularly prominent for non-linear invariant generation, because the user must supply maximum degrees on polynomials, bases for exponents, etc. On the other hand, recurrence-based methods are able to find sophisticated non-linear mathematical relations, including polynomials, exponentials, and logarithms, because such relations arise as the solutions to recurrences. However, a disadvantage of past recurrence-based invariant-generation methods is that they are primarily loop-based analyses: they use recurrences to relate the pre-state and post-state of a loop, so it is not obvious how to apply them to a recursive procedure, especially if the procedure is non-linearly recursive (e.g., a tree-traversal algorithm). In this paper, we combine these two approaches and obtain a technique that uses templates in which the unknowns are functions rather than numbers, and the constraints on the unknowns are recurrences. The technique synthesizes invariants involving polynomials, exponentials, and logarithms, even in the presence of arbitrary control-flow, including any combination of loops, branches, and (possibly non-linear) recursion. For instance, it is able to show that (i) the time taken by merge-sort is O(n log(n)), and (ii) the time taken by Strassen’s algorithm is O(nlog2(7)).

[1]  Jochen Hoenicke,et al.  Ultimate Automizer with SMTInterpol - (Competition Contribution) , 2013, TACAS.

[2]  Laura Kovács,et al.  Reasoning Algebraically About P-Solvable Loops , 2008, TACAS.

[3]  Jan Hoffmann,et al.  Exponential Automatic Amortized Resource Analysis , 2020, FoSSaCS.

[4]  Zachary Kincaid,et al.  Closed forms for numerical loops , 2019, Proc. ACM Program. Lang..

[5]  Martin Hofmann,et al.  Resource Aware ML , 2012, CAV.

[6]  Thomas W. Reps,et al.  Newtonian Program Analysis via Tensor Product , 2017, ACM Trans. Program. Lang. Syst..

[7]  David Cachera,et al.  Inference of Polynomial Invariants for Imperative Programs: A Farewell to Gröbner Bases , 2012, SAS.

[8]  Ben Wegbreit,et al.  Mechanical program analysis , 1975, CACM.

[9]  Elvira Albert,et al.  Closed-Form Upper Bounds in Static Cost Analysis , 2011, Journal of Automated Reasoning.

[10]  Jochen Hoenicke,et al.  Ultimate Taipan with Dynamic Block Encoding - (Competition Contribution) , 2018, TACAS.

[11]  Elvira Albert,et al.  On the Inference of Resource Usage Upper and Lower Bounds , 2013, TOCL.

[12]  Laura Kovács,et al.  Automated Generation of Non-Linear Loop Invariants Utilizing Hypergeometric Sequences , 2017, ISSAC.

[13]  Fangzhen Lin,et al.  VIAP - Automated System for Verifying Integer Assignment Programs with Loops , 2017, 2017 19th International Symposium on Symbolic and Numeric Algorithms for Scientific Computing (SYNASC).

[14]  Laura Kovács,et al.  Invariant Generation for Multi-Path Loops with Polynomial Assignments , 2018, VMCAI.

[15]  Henny B. Sipma,et al.  Constraint-Based Linear-Relations Analysis , 2004, SAS.

[16]  D. Kapur Automatically Generating Loop Invariants Using Quantifier Elimination † -Preliminary Report- , 2004 .

[17]  Enric Rodríguez-Carbonell,et al.  Automatic Generation of Polynomial Loop Invariants: Algebraic Foundations , 2004, ISSAC '04.

[18]  Kensuke Kojima,et al.  Generalized Homogeneous Polynomials for Efficient Template-Based Nonlinear Invariant Synthesis , 2016, SAS.

[19]  Jürgen Giesl,et al.  Analyzing Runtime and Size Complexity of Integer Programs , 2016, ACM Trans. Program. Lang. Syst..

[20]  Manuel Kauers,et al.  The Concrete Tetrahedron - Symbolic Sums, Recurrence Equations, Generating Functions, Asymptotic Estimates , 2011, Texts & Monographs in Symbolic Computation.

[21]  Antonio Flores-Montoya Cost Analysis of Programs Based on the Refinement of Cost Relations , 2017 .

[22]  Patrick Cousot,et al.  Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints , 1977, POPL.

[23]  Zachary Kincaid,et al.  Compositional recurrence analysis , 2015, 2015 Formal Methods in Computer-Aided Design (FMCAD).

[24]  Henny B. Sipma,et al.  Linear Invariant Generation Using Non-linear Constraint Solving , 2003, CAV.

[25]  Zachary Kincaid,et al.  Non-linear reasoning for invariant synthesis , 2017, Proc. ACM Program. Lang..

[26]  Zachary Kincaid,et al.  Compositional recurrence analysis revisited , 2017, PLDI.

[27]  Zhong Shao,et al.  Compositional certified resource bounds , 2015, PLDI.

[28]  Deepak Kapur Automatically Generating Loop Invariants Using Quantifier Elimination , 2005, Deduction and Applications.

[29]  Krishnendu Chatterjee,et al.  Non-polynomial Worst-Case Analysis of Recursive Programs , 2017, CAV.

[30]  Virgile Prevosto,et al.  Polynomial Invariants by Linear Algebra , 2016, ATVA.

[31]  Henny B. Sipma,et al.  Non-linear loop invariant generation using Gröbner bases , 2004, POPL.