skip to main content
research-article
Open Access

A unifying type-theory for higher-order (amortized) cost analysis

Published:04 January 2021Publication History
Skip Abstract Section

Abstract

This paper presents λ-amor, a new type-theoretic framework for amortized cost analysis of higher-order functional programs and shows that existing type systems for cost analysis can be embedded in it. λ-amor introduces a new modal type for representing potentials – costs that have been accounted for, but not yet incurred, which are central to amortized analysis. Additionally, λ-amor relies on standard type-theoretic concepts like affineness, refinement types and an indexed cost monad. λ-amor is proved sound using a rather simple logical relation. We embed two existing type systems for cost analysis in λ-amor showing that, despite its simplicity, λ-amor can simulate cost analysis for different evaluation strategies (call-by-name and call-by-value), in different styles (effect-based and coeffect-based), and with or without amortization. One of the embeddings also implies that λ-amor is relatively complete for all terminating PCF programs.

References

  1. Amal Jamil Ahmed. 2004. Semantics of types for mutable state. Ph.D. Dissertation. Princeton university.Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Robert Atkey. 2018. Syntax and Semantics of Quantitative Type Theory. In Annual ACM/IEEE Symposium on Logic in Computer Science.Google ScholarGoogle Scholar
  3. Martin Avanzini and Ugo Dal Lago. 2017. Automating Sized-type Inference for Complexity Analysis. Proc. ACM Program. Lang. 1, ICFP ( 2017 ).Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Aloïs Brunel, Marco Gaboardi, Damiano Mazza, and Steve Zdancewic. 2014. A Core Quantitative Coefect Calculus. In Proceedings of the European Symposium on Programming Languages and Systems.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Quentin Carbonneaux, Jan Hofmann, and Zhong Shao. 2015. Compositional certified resource bounds. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation.Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Arthur Charguéraud and François Pottier. 2019. Verifying the Correctness and Amortized Complexity of a Union-Find Implementation in Separation Logic with Time Credits. J. Autom. Reasoning 62, 3 ( 2019 ).Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Ezgi Çiçek, Gilles Barthe, Marco Gaboardi, Deepak Garg, and Jan Hofmann. 2017. Relational cost analysis. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Cliford Stein. 2009. Introduction to Algorithms, 3rd Edition. MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Karl Crary and Stephanie Weirich. 2000. Resource Bound Certification. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Ugo Dal Lago and Marco Gaboardi. 2011. Linear Dependent Types and Relative Completeness. Logical Methods in Computer Science 8, 4 ( 2011 ).Google ScholarGoogle Scholar
  11. Ugo Dal Lago and Barbara Petit. 2012. Linear Dependent Types in a Call-by-value Scenario. Science of Computer Programming 84 ( 2012 ).Google ScholarGoogle Scholar
  12. Nils Anders Danielsson. 2008. Lightweight Semiformal Time Complexity Analysis for Purely Functional Data Structures. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Norman Danner, Daniel R. Licata, and Ramyaa. 2015. Denotational cost semantics for functional languages with inductive types. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming. 140-151.Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Marco Gaboardi, Shin-ya Katsumata, Dominic Orchard, Flavien Breuvart, and Tarmo Uustalu. 2016. Combining Efects and Coefects via Grading. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming.Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ).Google ScholarGoogle Scholar
  16. Martin A. T. Handley, Niki Vazou, and Graham Hutton. 2020. Liquidate your assets: reasoning about resource usage in liquid Haskell. Proc. ACM Program. Lang. 4, POPL ( 2020 ).Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Maximilian P. L. Haslbeck and Tobias Nipkow. 2018. Hoare Logics for Time Bounds-A Study in Meta Theory. In Tools and Algorithms for the Construction and Analysis of Systems, Vol. 10805.Google ScholarGoogle Scholar
  18. Jan Hofman. 2011. Types with Potential: Polynomial Resource Bounds via Automatic Amortized Analysis. Ph.D. Dissertation. Ludwig-Maximilians-Universität München.Google ScholarGoogle Scholar
  19. Jan Hofmann, Klaus Aehlig, and Martin Hofmann. 2011. Multivariate Amortized Resource Analysis. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Jan Hofmann, Ankush Das, and Shu-Chun Weng. 2017. Towards Automatic Resource Bound Analysis for OCaml. In Proceedings of the ACM SIGPLAN Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Jan Hofmann and Martin Hofmann. 2010. Amortized Resource Analysis with Polynomial Potential: A Static Inference of Polynomial Bounds for Functional Programs. In Proceedings of the European Conference on Programming Languages and Systems.Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Martin Hofmann and Stefen Jost. 2003. Static Prediction of Heap Space Usage for First-order Functional Programs. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Stefen Jost, Kevin Hammond, Hans-Wolfgang Loidl, and Martin Hofmann. 2010. Static Determination of Quantitative Resource Usage for Higher-order Programs. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Stefen Jost, Hans-Wolfgang Loidl, Kevin Hammond, Norman Scaife, and Martin Hofmann. 2009. "Carbon Credits" for Resource-Bounded Computations Using Amortised Analysis. In Proceedings of Formal Methods.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Stefen Jost, Pedro Vasconcelos, Mário Florido, and Kevin Hammond. 2017. Type-Based Cost Analysis for Lazy Functional Languages. J. Autom. Reason. 59, 1 ( 2017 ).Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. G. A. Kavvos, Edward Morehouse, Daniel R. Licata, and Norman Danner. 2020. Recurrence extraction for functional programs through call-by-push-value. Proc. ACM Program. Lang. 4, POPL ( 2020 ).Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Tristan Knoth, Di Wang, Nadia Polikarpova, and Jan Hofmann. 2019. Resource-guided program synthesis. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation.Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Jean-Louis Krivine. 2007. A Call-by-name Lambda-calculus Machine. Higher Order Symbolic Computation 20, 3 ( 2007 ).Google ScholarGoogle Scholar
  29. Ravichandhran Madhavan, Sumith Kulal, and Viktor Kuncak. 2017. Contract-based Resource Verification for Higher-order Functions with Memoization. In Proceedings of the ACM SIGPLAN Symposium on Principles of Programming Languages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Dylan McDermott and Alan Mycroft. 2018. Call-by-need efects via coefects. Open Comput. Sci. 8, 1 ( 2018 ).Google ScholarGoogle Scholar
  31. Glen Mével, Jacques-Henri Jourdan, and François Pottier. 2019. Time credits and time receipts in Iris. In European Symposium on Programming.Google ScholarGoogle ScholarCross RefCross Ref
  32. Eugenio Moggi. 1991. Notions of Computation and Monads. Information and Computation 93, 1 ( 1991 ).Google ScholarGoogle Scholar
  33. Georg Neis, Derek Dreyer, and Andreas Rossberg. 2011. Non-parametric parametricity. J. Funct. Program. 21, 4-5 ( 2011 ).Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Chris Okasaki. 1996. Purely Functional Data Structures. Ph.D. Dissertation. Carnegie Mellon University.Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Tomas Petricek, Dominic Orchard, and Alan Mycroft. 2014. Coefects: A Calculus of Context-dependent Computation. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming.Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Tomas Petricek, Dominic A. Orchard, and Alan Mycroft. 2013. Coefects: Unified Static Analysis of Context-Dependence. In Automata, Languages, and Programming-International Colloquium.Google ScholarGoogle Scholar
  37. David J. Pym, Peter W. O'Hearn, and Hongseok Yang. 2004. Possible worlds and resources: the semantics of BI. Theoretical Computer Science 315, 1 ( 2004 ).Google ScholarGoogle Scholar
  38. Robert E. Tarjan. 1985. Amortized computational complexity. SIAM J. Algebraic Discrete Methods 6, 2 ( 1985 ).Google ScholarGoogle ScholarCross RefCross Ref
  39. Hongwei Xi. 2007. Dependent ML An approach to practical programming with dependent types. J. Funct. Program. 17, 2 ( 2007 ).Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A unifying type-theory for higher-order (amortized) cost analysis

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image Proceedings of the ACM on Programming Languages
          Proceedings of the ACM on Programming Languages  Volume 5, Issue POPL
          January 2021
          1789 pages
          EISSN:2475-1421
          DOI:10.1145/3445980
          Issue’s Table of Contents

          Copyright © 2021 Owner/Author

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 4 January 2021
          Published in pacmpl Volume 5, Issue POPL

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!