Abstract
A typical way of analyzing the time complexity of functional programs is to extract a recurrence expressing the running time of the program in terms of the size of its input, and then to solve the recurrence to obtain a big-O bound. For recurrence extraction to be compositional, it is also necessary to extract recurrences for the size of outputs of helper functions. Previous work has developed techniques for using logical relations to state a formal correctness theorem for a general recurrence extraction translation: a program is bounded by a recurrence when the operational cost is bounded by the extracted cost, and the output value is bounded, according to a value bounding relation defined by induction on types, by the extracted size. This previous work supports higher-order functions by viewing recurrences as programs in a lambda-calculus, or as mathematical entities in a denotational semantics thereof. In this paper, we extend these techniques to support amortized analysis, where costs are rearranged from one portion of a program to another to achieve more precise bounds. We give an intermediate language in which programs can be annotated according to the banker's method of amortized analysis; this language has an affine type system to ensure credits are not spent more than once. We give a recurrence extraction translation of this language into a recurrence language, a simply-typed lambda-calculus with a cost type, and state and prove a bounding logical relation expressing the correctness of this translation. The recurrence language has a denotational semantics in preorders, and we use this semantics to solve recurrences, e.g analyzing binary counters and splay trees.
Supplemental Material
- Elvira Albert, Puri Arenas, Samir Genaim, and Germán Puebla. 2011. Closed-form upper bounds in static cost analysis. Journal of Automated Reasoning 46 (2011), 161–203. Issue 2. Google ScholarDigital Library
- Elvira Albert, Puri Arenas, Samir Genaim, German Puebla, and Damiano Zanardini. 2012. Cost analysis of object-oriented bytecode programs. Theoretical Computer Science 413, 1 (2012), 142–159. Google ScholarDigital Library
- Elvira Albert, Samir Genaim, and Abu Naser Masud. 2013. On the Inference of Resource Usage Upper and Lower Bounds. ACM Transactions on Computational Logic 14, 3 (2013), 22:1–22:35. Google ScholarDigital Library
- Diego Esteban Alonso-Blas and Samir Genaim. 2012. On the limits of the classical approach to cost analysis. In Static Analysis (Lecture Notes in Computer Science), Antoine Miné and David Schmidt (Eds.), Vol. 7460. Springer Berlin Heidelberg, 405–421. Google ScholarDigital Library
- Robert Atkey. 2018. Syntax and semantics of quantitative type theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2018 (Oxford, United Kingdom). ACM Press, 56–65. Google ScholarDigital Library
- Ralph Benzinger. 2004. Automated higher-order complexity analysis. Theoretical Computer Science 318, 1-2 (2004), 79–103. Google ScholarDigital Library
- Joseph W. Cutler, Daniel R. Licata, and Norman Danner. 2020. Denotational recurrence extraction for amortized analysis. arXiv: 2006.15036Google Scholar
- Nils Anders Danielsson. 2008. Lightweight semiformal time complexity analysis for purely functional data structures. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2008, George Necula and Philip Wadler (Eds.). ACM Press, 133–144. Google ScholarDigital Library
- Norman Danner and Daniel R. Licata. 2020. Denotational semantics as a foundation for cost recurrence extraction for functional languages. arXiv: 2002.07262v1Google Scholar
- Norman Danner, Daniel R. Licata, and Ramyaa Ramyaa. 2015. Denotational cost semantics for functional languages with inductive types. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015 (Vancouver, BC, Canada), Kathleen Fisher and John Reppy (Eds.). ACM Press, 140–151. Google ScholarDigital Library
- Norman Danner, Jennifer Paykin, and James S. Royer. 2013. A static cost analysis for a higher-order language. In Proceedings of the 7th workshop on Programming languages meets program verification, PLPV 2013, Matthew Might and David Van Horn (Eds.). ACM Press, 25–34. Google ScholarDigital Library
- Norman Danner and James S. Royer. 2007. Adventures in time and space. Logical Methods in Computer Science 3, 9 (2007), 1–53. Google ScholarCross Ref
- Antonio Flores-Montoya. 2016. Upper and Lower Amortized Cost Bounds of Programs Expressed as Cost Relations. In FM 2016: Formal Methods (Lecture Notes in Computer Science), John Fitzgerald, Constance Heitmeyer, Stefania Gnesi, and Anna Philippou (Eds.), Vol. 9995. Springer International Publishing, 254–273. Google ScholarCross Ref
- Jean-Yves Girard, Andre Scedrov, and Philip J. Scott. 1992. Bounded linear logic: a modular approach to polynomial-time computability. Theoretical Computer Science 97, 1 (1992), 1–66. Google ScholarDigital Library
- Jan Hoffmann, Klaus Aehlig, and Martin Hofmann. 2012. Multivariate Amortized Resource Analysis. ACM Transactions on Programming Languages and Systems 34, 3 (2012), 14:1–14:62. Google ScholarDigital Library
- Jan Hoffmann, Ankush Das, and Shu-Chun Weng. 2017. Towards automatic resource bound analysis for OCaml. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Giuseppe Castagna and Andrew D. Gordon (Eds.). ACM Press, 359–373. Google ScholarDigital Library
- Jan Hoffmann and Zhong Shao. 2015. Automatic static cost analysis for parallel programs. In Programming Languages and Systems: 24th European Symposium on Programming, ESOP 2015 (Lecture Notes in Computer Science), Jan Vitek (Ed.), Vol. 9032. Springer-Verlag, 132–157. Google ScholarDigital Library
- Martin Hofmann. 2002. The Strength of Non-Size Increasing Computation. In Proceedings of the 29th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 260–269. Google ScholarDigital Library
- Martin Hofmann. 2003. Linear Types and Non-Size-Increasing Polynomial Time Computation. Information and Computation 183, 1 (2003), 57–85. Google ScholarDigital Library
- Martin Hofmann and Steffen Jost. 2003. Static prediction of heap space usage for first-order functional programs. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Alex Aiken and Greg Morrisett (Eds.). ACM Press, 185–197. Google ScholarDigital Library
- Hudson, Bowornmet. 2016. Computer-Checked Recurrence Extraction for Functional Programs. Master’s thesis. Wesleyan University.Google Scholar
- Steffen Jost, Pedro Vasconcelos, Mário Florido, and Kevin Hammond. 2017. Type-based cost analysis for lazy functional languages. Journal of Automated Reasoning 59, 1 (2017), 87–120. Google ScholarDigital Library
- G. A. Kavvos, Edward Morehouse, Daniel R. Licata, and Norman Danner. 2019. Recurrence Extraction for Functional Programs through Call-by-Push-Value. Proceedings of the ACM on Programming Languages 4, POPL, Article 15 (2019). Google ScholarDigital Library
- Zachary Kincaid, John Cyphert, Jason Breck, and Thomas Reps. 2017. Non-linear Reasoning for Invariant Synthesis. Proceedings of the ACM on Programming Languages 2, POPL, Article 54 (Dec. 2017), 33 pages. Google ScholarDigital Library
- Tristan Knoth, Di Wang, Nadia Polikarpova, and Jan Hoffmann. 2019. Resource-Guided Program Synthesis. In ACM SIGPLAN Conference on Programming Language Design and Implementation.Google Scholar
- Daniel Le Métayer. 1988. ACE: an automatic complexity evaluator. ACM Transactions on Programming Languages and Systems 10, 2 (1988), 248–266. Google ScholarDigital Library
- Daniel R. Licata, Michael Shulman, and Mitchell Riley. 2017. A fibrational framework for substructural and modal logics. In 2nd International Conference on Formal Structures for Computation and Deduction, FSCD 2017 (Leibniz International Proceedings in Informatics (LIPIcs)), Dale Miller (Ed.), Vol. 84. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, 25:1– 25:22. Google ScholarCross Ref
- Conor McBride. 2016. I got plenty o’ Nuttin’. In A List of Successes That Can Change the World: Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday (Lecture Notes in Computer Science), Sam Lindley, Conor McBride, Phil Trinder, and Don Sannella (Eds.), Vol. 9600. Springer-Verlag. Google ScholarCross Ref
- John C. Mitchell and Gordon D. Plotkin. 1985. Abstract types have existential types. In Proceedings of the 12th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL 1985. 37–51. Google ScholarDigital Library
- Yue Niu and Jan Hoffmann. 2018. Automatic Space Bound Analysis for Functional Programs with Garbage Collection. In LPAR-22. 22nd International Conference on Logic for Programming, Artificial Intelligence and Reasoning (EPiC Series in Computing), Gilles Barthe, Geoff Sutcliffe, and Margus Veanes (Eds.), Vol. 57. EasyChair, 543–563. Google ScholarCross Ref
- Chris Okasaki. 1998. Purely Functional Data Structures. Cambridge University Press.Google ScholarDigital Library
- Dominic Orchard, Vilem-Benjamin Liepelt, and Harley Eades III. 2019. Quantitative program reasoning with graded modal types. Proceedings of the ACM on Programming Languages 3, ICFP (2019), 110:1–110:30. Google ScholarDigital Library
- Jason Reed. [n.d.]. Names are (mostly) useless. ([n. d.]). https://www.cis.upenn.edu/~sweirich/wmm/wmm08- programme. html Presented at 3rd Informal ACM SIGPLAN Workshop on Mechanizing Metatheory 2008.Google Scholar
- Mads Rosendahl. 1989. Automatic complexity analysis. In Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, FPCA 1989, Joseph E. Stoy (Ed.). ACM Press, 144–156. Google ScholarDigital Library
- David Sands. 1990. Calculi for Time Analysis of Functional Programs. Ph.D. Dissertation. University of London.Google Scholar
- Jon Shultis. 1985. On the complexity of higher-order programs. Technical Report CU-CS-288-85. University of Colorado at Boulder.Google Scholar
- Daniel Dominic Sleator and Robert Endre Tarjan. 1985. Self-adjusting binary search trees. Journal of the ACM 32, 3 (1985).Google ScholarDigital Library
- Kathryn Van Stone. 2003. A Denotational Approach to Measuring Complexity in Functional Programs. Ph.D. Dissertation. Carnegie Mellon University.Google Scholar
- Robert Endre Tarjan. 1985. Amortized computational complexity. SIAM J. Algebraic Discrete Methods 6, 2 (1985), 306–318. Google ScholarDigital Library
- Peng Wang, Di Wang, and Adam Chlipala. 2017. TiML: A functional language for practical complexity analysis with invariants. Proceedings of the ACM on Programming Languages 1, OOPSLA, Article 79 (2017), 26 pages. Google ScholarDigital Library
- Ben Wegbreit. 1975. Mechanical program analysis. Communications of the Association for Computing Machinery 18, 9 (1975), 528–539. Google ScholarDigital Library
Index Terms
- Denotational recurrence extraction for amortized analysis
Recommendations
Recurrence extraction for functional programs through call-by-push-value
The main way of analysing the complexity of a program is that of extracting and solving a recurrence that expresses its running time in terms of the size of its input. We develop a method that automatically extracts such recurrences from the syntax of ...
A Methodology for Concurrent Languages Development Based on Denotational Semantics
SYNASC '09: Proceedings of the 2009 11th International Symposium on Symbolic and Numeric Algorithms for Scientific ComputingBy using the "continuation semantics for concurrency" (CSC) technique [6] denotational semantics can be used both as a method for formal specification and as a general method for designing tractable compositional prototypes for concurrent languages [8]. ...
Denotational Semantics for Symbolic Execution
Theoretical Aspects of Computing – ICTAC 2023AbstractSymbolic execution is a technique to systematically explore all possible paths through a program. This technique can be formally explained by means of small-step transition systems that update symbolic states and compute a precondition ...
Comments