Cost Analysis of Programs Based on the Refinement of Cost Relations

Cost analysis aims at statically inferring the amount of resources, such as time or memory, needed to execute a program. This amount of resources is the cost of the program and it depends on its input parameters. Obtaining a function (in terms of the input parameters) that represents the cost of a program precisely is generally not possible. Thus, cost analyses attempt to infer functions that represent upper or lower bounds of the cost of programs instead. Many existing cost analyses approach the problem in two stages. First, the target program is transformed into an integer abstract representation where the resource consumption is explicit and second, the abstract representation is analyzed and cost bounds are inferred from it. The advantage of this approach is that the second part is language independent and resource independent. That is, it can be reused across different programming languages and to analyze the program cost with respect to different resources. Cost relations are a possible abstract representation. They are similar to constraint logic programs annotated with costs and they can easily represent both imperative and functional programs. Existing cost analyses based on cost relations have limited support for programs that have a complex control flow, or present amortized complexity, that is, when the sum of the cost of the parts yields a higher asymptotic cost than the cost of the whole. This thesis identifies these limitations, and presents a new analysis of cost relations that overcomes them. The analysis can obtain upper and lower bounds of programs expressed as cost relations and it contains three parts: 1. The first part reduces any mutually recursive cost relations to cost relations that only have direct recursion and performs some simplifications. 2. The second part consists of a refinement of cost relations that partitions all possible executions of the program into a finite set of execution patterns named chains. The refinement also infers precise invariants for each of the chains, discards unfeasible execution patterns and proves termination. 3. In the third part of the analysis, cost bounds are inferred compositionally. For that purpose, a novel cost representation, named cost structures, is presented. Cost structures reduce the computation of complex bounds to the inference of simple constraints using linear programming. They can represent polynomial upper and lower bounds of programs with max and min operators. The analysis is proven sound with respect to a new semantics of cost relations. This semantics distinguishes between terminating and non-terminating executions and models the behavior of nonterminating executions accurately. In addition, the analysis has been implemented in the tool CoFloCo and it has been extensively evaluated against other state-of-the-art tools and with respect to a variety of benchmarks. These benchmarks include imperative programs, functional programs, and term rewrite systems. CoFloCo performs well in all categories which demonstrates both the power of the analysis and its versatility.

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

[2]  Ankush Das,et al.  ML for ML: Learning Cost Semantics by Experiment , 2017, TACAS.

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

[4]  Helmut Veith,et al.  Difference constraints: an adequate abstraction for complexity analysis of imperative programs , 2015, 2015 Formal Methods in Computer-Aided Design (FMCAD).

[5]  Elvira Albert,et al.  Peak Cost Analysis of Distributed Systems , 2014, SAS.

[6]  Sumit Gulwani,et al.  Bound Analysis of Imperative Programs with the Size-Change Abstraction , 2011, SAS.

[7]  Zhong Shao,et al.  Type-based amortized resource analysis with integers and arrays , 2015, J. Funct. Program..

[8]  Samir Genaim,et al.  On the Limits of the Classical Approach to Cost Analysis , 2012, SAS.

[9]  Elvira Albert,et al.  Cost analysis of object-oriented bytecode programs , 2012, Theor. Comput. Sci..

[10]  Paul Feautrier,et al.  Multi-dimensional Rankings, Program Termination, and Complexity Bounds of Flowchart Programs , 2010, SAS.

[11]  Antoine Miné,et al.  A Decision Tree Abstract Domain for Proving Conditional Termination , 2014, SAS.

[12]  Nikolaj Bjørner,et al.  Horn Clause Solvers for Program Verification , 2015, Fields of Logic and Computation II.

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

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

[15]  Reiner Hähnle,et al.  A formal verification framework for static analysis , 2015, Software & Systems Modeling.

[16]  Elvira Albert,et al.  Rely-Guarantee Termination and Cost Analyses of Loops with Concurrent Interleavings , 2016, Journal of Automated Reasoning.

[17]  Antoine Miné,et al.  The octagon abstract domain , 2001, High. Order Symb. Comput..

[18]  Reiner Hähnle,et al.  ABS: A Core Language for Abstract Behavioral Specification , 2010, FMCO.

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

[20]  Jürgen Giesl,et al.  Lower Runtime Bounds for Integer Programs , 2016, IJCAR.

[21]  Markus Püschel,et al.  Fast polyhedra abstract domain , 2017, POPL.

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

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

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

[25]  Saumya K. Debray,et al.  Estimating the Computational Cost of Logic Programs , 1994, SAS.

[26]  Jürgen Giesl,et al.  Alternating Runtime and Size Complexity Analysis of Integer Programs , 2014, TACAS.

[27]  Helmut Veith,et al.  A simple and scalable static analysis for bound analysis and amortized complexity analysis , 2014, Software Engineering.

[28]  Andreas Podelski,et al.  A Complete Method for the Synthesis of Linear Ranking Functions , 2004, VMCAI.

[29]  Raúl Gutiérrez,et al.  A Transformational Approach to Resource Analysis with Typed-norms Inference , 2019, Theory and Practice of Logic Programming.

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

[31]  Kevin Hammond,et al.  Inferring Cost Equations for Recursive, Polymorphic and Higher-Order Functional Programs , 2003, IFL.

[32]  Jan Maluszy¿ski,et al.  Lower Bound Cost Estimation for Logic Programs , 1997 .

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

[34]  Zhong Shao,et al.  End-to-end verification of stack-space bounds for C programs , 2014, PLDI.

[35]  Ting Yu,et al.  A note on “On the conversion of indirect to direct recursion” , 1997, TOPL.

[36]  Elvira Albert,et al.  Analysis of May-Happen-in-Parallel in Concurrent Objects , 2012, FMOODS/FORTE.

[37]  Martin Hofmann,et al.  Amortised Resource Analysis and Typed Polynomial Interpretations , 2014, RTA-TLCA.

[38]  Elvira Albert,et al.  COSTA: Design and Implementation of a Cost and Termination Analyzer for Java Bytecode , 2008, FMCO.

[39]  Jürgen Giesl,et al.  Termination and complexity analysis for programs with bitvector arithmetic by symbolic execution , 2018, J. Log. Algebraic Methods Program..

[40]  Antonio Flores-Montoya,et al.  Upper and Lower Amortized Cost Bounds of Programs Expressed as Cost Relations , 2016, FM.

[41]  Jens Knoop,et al.  Symbolic Loop Bound Computation for WCET Analysis , 2011, Ershov Memorial Conference.

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

[43]  Ugo Dal Lago,et al.  Analysing the complexity of functional programs: higher-order meets first-order , 2015, ICFP.

[44]  Amir M. Ben-Amram,et al.  Ranking Functions for Linear-Constraint Loops , 2012, JACM.

[45]  J. Siam A LINEAR TIME ALGORITHM FOR FINDING MINIMUM CUTSETS IN REDUCIBLE GRAPHS , 1979 .

[46]  Martin Hofmann,et al.  Multivariate Amortised Resource Analysis for Term Rewrite Systems , 2015, TLCA.

[47]  Cosimo Laneve,et al.  Static analysis of cloud elasticity , 2017, Sci. Comput. Program..

[48]  Kerstin Eder,et al.  Static analysis of energy consumption for LLVM IR programs , 2014, SCOPES.

[49]  Ankush Das,et al.  Towards automatic resource bound analysis for OCaml , 2016, POPL.

[50]  Elvira Albert,et al.  Termination and Cost Analysis of Loops with Concurrent Interleavings , 2013, ATVA.

[51]  Jürgen Giesl,et al.  Termination of term rewriting using dependency pairs , 2000, Theor. Comput. Sci..

[52]  Reiner Hähnle,et al.  Resource Analysis of Complex Programs with Cost Equations , 2014, APLAS.

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

[54]  Jürgen Giesl,et al.  Complexity Analysis for Java with AProVE , 2017, IFM.

[55]  Panos M. Pardalos,et al.  Feedback Set Problems , 1999, Handbook of Combinatorial Optimization.

[56]  Saumya K. Debray,et al.  Task granularity analysis in logic programs , 1990, PLDI '90.

[57]  Daniel Larraz,et al.  Proving termination of imperative programs using Max-SMT , 2013, 2013 Formal Methods in Computer-Aided Design.

[58]  Manuel V. Hermenegildo,et al.  Resource Usage Analysis of Logic Programs via Abstract Interpretation Using Sized Types* , 2014, Theory and Practice of Logic Programming.

[59]  Georg Moser,et al.  A combination framework for complexity , 2013, Inf. Comput..

[60]  Elvira Albert,et al.  May-Happen-in-Parallel Analysis for Actor-Based Concurrency , 2015, ACM Trans. Comput. Log..

[61]  Elvira Albert,et al.  May-Happen-in-Parallel Analysis with Condition Synchronization , 2015, FOPARA.

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

[63]  Pavol Cerný,et al.  Segment Abstraction for Worst-Case Execution Time Analysis , 2015, ESOP.

[64]  Jakob Engblom,et al.  The worst-case execution-time problem—overview of methods and survey of tools , 2008, TECS.

[65]  René Thiemann,et al.  Certification of Complexity Proofs using CeTA , 2015, RTA.

[66]  Elvira Albert,et al.  SACO: Static Analyzer for Concurrent Objects , 2014, TACAS.

[67]  Aart Middeldorp,et al.  Tyrolean Termination Tool 2 , 2009, RTA.

[68]  Marc Brockschmidt,et al.  Better Termination Proving through Cooperation , 2013, CAV.

[69]  Elvira Albert,et al.  May-Happen-in-Parallel Based Deadlock Analysis for Concurrent Objects , 2013, FMOODS/FORTE.

[70]  Elvira Albert,et al.  Non-cumulative Resource Analysis , 2015, TACAS.

[71]  Samir Genaim,et al.  Precise Cost Analysis via Local Reasoning , 2013, ATVA.

[72]  Jürgen Giesl,et al.  Analyzing Innermost Runtime Complexity of Term Rewriting by Dependency Pairs , 2013, Journal of Automated Reasoning.

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

[74]  Elvira Albert,et al.  Heap space analysis for garbage collected languages , 2013, Sci. Comput. Program..

[75]  Elvira Albert,et al.  Cost Analysis of Concurrent OO Programs , 2011, APLAS.

[76]  Einar Broch Johnsen,et al.  Parallel Cost Analysis of Distributed Systems , 2015, SAS.

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

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

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

[80]  Nicolas Halbwachs,et al.  Automatic discovery of linear restraints among variables of a program , 1978, POPL.

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

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

[83]  Helmut Veith,et al.  Complexity and Resource Bound Analysis of Imperative Programs Using Difference Constraints , 2017, Journal of Automated Reasoning.

[84]  Georg Moser,et al.  Automated Complexity Analysis Based on the Dependency Pair Method , 2008, IJCAR.

[85]  Deepak Kapur,et al.  Termination Analysis of C Programs Using Compiler Intermediate Languages , 2011, RTA.

[86]  Jürgen Giesl,et al.  Complexity Analysis for Term Rewriting by Integer Transition Systems , 2017, FroCoS.

[87]  Paul Feautrier,et al.  Accelerated Invariant Generation for C Programs with Aspic and C2fsm , 2010, Electron. Notes Theor. Comput. Sci..

[88]  Matthias Heizmann,et al.  Ranking Templates for Linear Loops , 2015 .

[89]  Andy King,et al.  Inferring Argument Size Relationships with CLP(R) , 1996, LOPSTR.

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

[91]  Marc Brockschmidt,et al.  T2: Temporal Property Verification , 2016, TACAS.

[92]  Roberto Bagnara,et al.  The Parma Polyhedra Library: Toward a complete set of numerical abstractions for the analysis and verification of hardware and software systems , 2006, Sci. Comput. Program..

[93]  Georg Moser,et al.  TcT: Tyrolean Complexity Tool , 2016, TACAS.

[94]  Jochen Hoenicke,et al.  Termination Analysis by Learning Terminating Programs , 2014, CAV.