Types with potential: polynomial resource bounds via automatic amortized analysis

A primary feature of a computer program is its quantitative performance characteristics: the amount of resources such as time, memory, and power the program needs to perform its task. Concrete resource bounds for specific hardware have many important applications in software development but their manual determination is tedious and error-prone. This dissertation studies the problem of automatically determining concrete worst-case bounds on the quantitative resource consumption of functional programs. Traditionally, automatic resource analyses are based on recurrence relations. The difficulty of both extracting and solving recurrence relations has led to the development of type-based resource analyses that are compositional, modular, and formally verifiable. However, existing automatic analyses based on amortization or sized types can only compute bounds that are linear in the sizes of the arguments of a function. This work presents a novel type system that derives polynomial bounds from first-order functional programs. As pioneered by Hofmann and Jost for linear bounds, it relies on the potential method of amortized analysis. Types are annotated with multivariate resource polynomials, a rich class of functions that generalize non-negative linear combinations of binomial coefficients. The main theorem states that type derivations establish resource bounds that are sound with respect to the resource-consumption of programs which is formalized by a big-step operational semantics. Simple local type rules allow for an efficient inference algorithm for the type annotations which relies on linear constraint solving only. This gives rise to an analysis system that is fully automatic if a maximal degree of the bounding polynomials is given. The analysis is generic in the resource of interest and can derive bounds on time and space usage. The bounds are naturally closed under composition and eventually summarized in closed, easily understood formulas. The practicability of this automatic amortized analysis is verified with a publicly available implementation and a reproducible experimental evaluation. The experiments with a wide range of examples from functional programming show that the inference of the bounds only takes a couple of seconds in most cases. The derived heap-space and evaluation-step bounds are compared with the measured worst-case behavior of the programs. Most bounds are asymptotically tight, and the constant factors are close or even identical to the optimal ones. For the first time we are able to automatically and precisely analyze the resource consumption of involved programs such as quick sort for lists of lists, longest common subsequence via dynamic programming, and multiplication of a list of matrices with different, fitting dimensions.

[1]  Sumit Gulwani,et al.  Control-flow refinement and progress invariants for bound analysis , 2009, PLDI '09.

[2]  Sumit Gulwani,et al.  The reachability-bound problem , 2010, PLDI '10.

[3]  R. Tarjan Amortized Computational Complexity , 1985 .

[4]  Elvira Albert,et al.  Cost Analysis of Java Bytecode , 2007, ESOP.

[5]  Sumit Gulwani,et al.  A Numerical Abstract Domain Based on Expression Abstraction and Max Operator with Application in Timing Analysis , 2008, CAV.

[6]  Sumit Gulwani,et al.  SPEED: precise and efficient static estimation of program computational complexity , 2009, POPL '09.

[7]  Ronald L. Graham,et al.  Concrete Mathematics, a Foundation for Computer Science , 1991, The Mathematical Gazette.

[8]  Igor Pak,et al.  AN ALGEBRAIC EXTENSION OF THE MACMAHON MASTER THEOREM , 2006 .

[9]  Martin Hofmann,et al.  Amortized Resource Analysis with Polynomial Potential , 2010, ESOP.

[10]  Nicolas Halbwachs,et al.  LUSTRE: a declarative language for real-time programming , 1987, POPL '87.

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

[12]  Saumya K. Debray,et al.  Cost analysis of logic programs , 1993, TOPL.

[13]  Mohamad A. Akra,et al.  On the Solution of Linear Recurrence Equations , 1998 .

[14]  Björn Lisper,et al.  An Efficient Algorithm for Parametric WCET Calculation , 2009, 2009 15th IEEE International Conference on Embedded and Real-Time Computing Systems and Applications.

[15]  M. Hofmann A Type System for Bounded Space and Functional In-Place Update , 2000, Nord. J. Comput..

[16]  Jacques Cohen,et al.  Computer-assisted microanalysis of programs , 1982, CACM.

[17]  Elvira Albert,et al.  More Precise Yet Widely Applicable Cost Analysis , 2011, VMCAI.

[18]  Lyle Harold Ramshaw,et al.  Formalizing the analysis of algorithms , 1979 .

[19]  Patrick Cousot,et al.  Inductive definitions, semantics and abstract interpretations , 1992, POPL '92.

[20]  Martin Hofmann,et al.  Efficient Type-Checking for Amortised Heap-Space Analysis , 2009, CSL.

[21]  Philippe Clauss,et al.  Symbolic Polynomial Maximization Over Convex Sets and Its Application to Memory Requirement Estimation , 2009, IEEE Transactions on Very Large Scale Integration (VLSI) Systems.

[22]  Martin Hofmann,et al.  Static determination of quantitative resource usage for higher-order programs , 2010, POPL '10.

[23]  John C. Reynolds,et al.  Definitional Interpreters for Higher-Order Programming Languages , 1972, ACM '72.

[24]  Ralph Benzinger,et al.  Automated complexity analysis of Nuprl extracted programs , 2001, Journal of Functional Programming.

[25]  Andre Scedrov,et al.  Bounded Linear Logic , 1991 .

[26]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[27]  Andrew M. Wallace,et al.  The Embounded Project , 2006 .

[28]  Shengchao Qin,et al.  Analysing memory resource bounds for low-level programs , 2008, ISMM '08.

[29]  Sebastian Altmeyer,et al.  Parametric Timing Analysis for Complex Architectures , 2008, 2008 14th IEEE International Conference on Embedded and Real-Time Computing Systems and Applications.

[30]  Wei-Ngan Chin,et al.  Calculating Sized Types , 1999, PEPM '00.

[31]  John Hughes,et al.  Recursion and dynamic data-structures in bounded space: towards embedded ML programming , 1999, ICFP '99.

[32]  Robert Atkey,et al.  Amortised Resource Analysis with Separation Logic , 2010, ESOP.

[33]  Hervé Grall,et al.  Coinductive big-step operational semantics , 2009, Inf. Comput..

[34]  Martin Hofmann,et al.  Type-Based Amortised Heap-Space Analysis , 2006, ESOP.

[35]  Elvira Albert,et al.  Automatic Inference of Upper Bounds for Recurrence Relations in Cost Analysis , 2008, SAS.

[36]  Stavros Tripakis,et al.  From simulink to SCADE/lustre to TTA: a layered approach for distributed embedded applications , 2003 .

[37]  Pedro B. Vasconcelos Space cost analysis using sized types , 2008 .

[38]  Daniel Le Métayer,et al.  ACE: an automatic complexity evaluator , 1988, TOPL.

[39]  Wolf Zimmermann,et al.  The automatic complexity analysis of divide-and-conquer algorithms , 1989 .

[40]  Marc Pouzet Lucid Synchrone: tutorial and reference manual , 2001 .

[41]  Amr Sabry,et al.  Proving the correctness of reactive systems using sized types , 1996, POPL '96.

[42]  John N. Tsitsiklis,et al.  Introduction to linear optimization , 1997, Athena scientific optimization and computation series.

[43]  Sergio Yovine,et al.  Parametric prediction of heap memory requirements , 2008, ISMM '08.

[44]  Björn Lisper,et al.  Fully Automatic, Parametric Worst-Case Execution Time Analysis , 2003, WCET.

[45]  Martin Hofmann,et al.  Amortized Resource Analysis with Polymorphic Recursion and Partial Big-Step Operational Semantics , 2010, APLAS.

[46]  Donald Ervin Knuth,et al.  The Art of Computer Programming , 1968 .

[47]  Jacques Cohen,et al.  Automating program analysis , 1988, JACM.

[48]  Ernst Althaus,et al.  Precise and efficient parametric path analysis , 2011, LCTES '11.

[49]  Ralph Benzinger,et al.  Automated higher-order complexity analysis , 2004, Theor. Comput. Sci..

[50]  Salvador Roura,et al.  Improved master theorems for divide-and-conquer recurrences , 2001, JACM.

[51]  Walid Taha,et al.  Generating Heap-Bounded Programs in a Functional Setting , 2003, EMSOFT.

[52]  Nils Anders Danielsson Lightweight semiformal time complexity analysis for purely functional data structures , 2008, POPL '08.

[53]  Philippe Flajolet,et al.  Automatic Average-Case Analysis of Algorithm , 1991, Theor. Comput. Sci..

[54]  Martin Hofmann,et al.  "Carbon Credits" for Resource-Bounded Computations Using Amortised Analysis , 2009, FM.

[55]  Martin Hofmann,et al.  Automatic Certification of Heap Consumption , 2004, LPAR.

[56]  Martin Hofmann,et al.  Multivariate amortized resource analysis , 2011, POPL '11.

[57]  Elvira Albert,et al.  Asymptotic Resource Usage Bounds , 2009, APLAS.

[58]  Donald E. Knuth,et al.  The Art of Computer Programming, Volume I: Fundamental Algorithms, 2nd Edition , 1997 .

[59]  Chris Okasaki,et al.  Purely functional data structures , 1998 .

[60]  Roberto Bagnara,et al.  PURRS: Towards Computer Algebra Support for Fully Automatic Worst-Case Complexity Analysis , 2005, ArXiv.

[61]  Philippe Flajolet,et al.  Analytic Combinatorics , 2009 .

[62]  Bernd Grobauer,et al.  Cost recurrences for DML programs , 2001, ICFP '01.

[63]  Gabor Karsai,et al.  Model-integrated development of embedded software , 2003, Proc. IEEE.

[64]  Karl Crary,et al.  Resource bound certification , 2000, POPL '00.

[65]  Mads Rosendahl,et al.  Automatic complexity analysis , 1989, FPCA.

[66]  Greg J. Michaelson,et al.  Hume: A Domain-Specific Language for Real-Time Embedded Systems , 2003, GPCE.

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

[68]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[69]  Marko C. J. D. van Eekelen,et al.  Polynomial Size Analysis of First-Order Functions , 2007, TLCA.

[70]  Martin Hofmann,et al.  Static prediction of heap space usage for first-order functional programs , 2003, POPL '03.

[71]  Clifford Stein,et al.  Introduction to Algorithms, 2nd edition. , 2001 .

[72]  Martin Hofmann,et al.  The strength of non-size increasing computation , 2002, POPL '02.