skip to main content

Reasoning about the garden of forking paths

Published:19 August 2021Publication History
Skip Abstract Section

Abstract

Lazy evaluation is a powerful tool for functional programmers. It enables the concise expression of on-demand computation and a form of compositionality not available under other evaluation strategies. However, the stateful nature of lazy evaluation makes it hard to analyze a program's computational cost, either informally or formally. In this work, we present a novel and simple framework for formally reasoning about lazy computation costs based on a recent model of lazy evaluation: clairvoyant call-by-value. The key feature of our framework is its simplicity, as expressed by our definition of the clairvoyance monad. This monad is both simple to define (around 20 lines of Coq) and simple to reason about. We show that this monad can be effectively used to mechanically reason about the computational cost of lazy functional programs written in Coq.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is a presentation of the paper Reasoning about the Garden of Forking Paths published at ICFP 2021. The abstract of the paper: Lazy evaluation is a powerful tool for functional programmers. It enables the concise expression of on-demand computation and a form of compositionality not available under other evaluation strategies. However, the stateful nature of lazy evaluation makes it hard to analyze a program's computational cost, either informally or formally. In this work, we present a novel and simple framework for formally reasoning about lazy computation costs based on a recent model of lazy evaluation: clairvoyant call-by-value. The key feature of our framework is its simplicity, as expressed by our definition of the clairvoyance monad. This monad is both simple to define (around 20 lines of Coq) and simple to reason about. We show that this monad can be effectively used to mechanically reason about the computational cost of lazy functional programs written in Coq.

3473585.mp4

Presentation Videos

References

  1. Andreas Abel, Marcin Benke, Ana Bove, John Hughes, and Ulf Norell. 2005. Verifying Haskell programs using constructive type theory. In Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell 2005, Tallinn, Estonia, September 30, 2005, Daan Leijen (Ed.). ACM, 62–73. https://doi.org/10.1145/1088348.1088355 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Joachim Breitner, Antal Spector-Zabusky, Yao Li, Christine Rizkallah, John Wiegley, Joshua Cohen, and Stephanie Weirich. 2021. Ready, Set, Verify! Applying hs-to-coq to real-world Haskell code. Journal of Functional Programming, 31 (2021), e5. https://doi.org/10.1017/S0956796820000283 Google ScholarGoogle ScholarCross RefCross Ref
  3. 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. Reason., 62, 3 (2019), 331–365. https://doi.org/10.1007/s10817-017-9431-7 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Jan Christiansen. 2011. Sloth - A Tool for Checking Minimal-Strictness. In Practical Aspects of Declarative Languages - 13th International Symposium, PADL 2011, Austin, TX, USA, January 24-25, 2011. Proceedings, Ricardo Rocha and John Launchbury (Eds.) (Lecture Notes in Computer Science, Vol. 6539). Springer, 160–174. https://doi.org/10.1007/978-3-642-18378-2_14 Google ScholarGoogle ScholarCross RefCross Ref
  5. Jan Christiansen and Daniel Seidel. 2011. Minimally strict polymorphic functions. In Proceedings of the 13th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, July 20-22, 2011, Odense, Denmark, Peter Schneider-Kamp and Michael Hanus (Eds.). ACM, 53–64. https://doi.org/10.1145/2003476.2003487 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Karl Crary and Stephanie Weirich. 2000. Resource Bound Certification. In POPL 2000, Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Boston, Massachusetts, USA, January 19-21, 2000, Mark N. Wegman and Thomas W. Reps (Eds.). ACM, 184–198. https://doi.org/10.1145/325694.325716 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Joseph W. Cutler, Daniel R. Licata, and Norman Danner. 2020. Denotational recurrence extraction for amortized analysis. Proc. ACM Program. Lang., 4, ICFP (2020), 97:1–97:29. https://doi.org/10.1145/3408979 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Nils Anders Danielsson. 2008. Lightweight semiformal time complexity analysis for purely functional data structures. In Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2008, San Francisco, California, USA, January 7-12, 2008, George C. Necula and Philip Wadler (Eds.). ACM, 133–144. https://doi.org/10.1145/1328438.1328457 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Edsko de Vries and Vasileios Koutavas. 2011. Reverse Hoare Logic. In Software Engineering and Formal Methods - 9th International Conference, SEFM 2011, Montevideo, Uruguay, November 14-18, 2011. Proceedings, Gilles Barthe, Alberto Pardo, and Gerardo Schneider (Eds.) (Lecture Notes in Computer Science, Vol. 7041). Springer, 155–171. https://doi.org/10.1007/978-3-642-24690-6_12 Google ScholarGoogle ScholarCross RefCross Ref
  10. Edsger W. Dijkstra. 1975. Guarded Commands, Nondeterminacy and Formal Derivation of Programs. Commun. ACM, 18, 8 (1975), 453–457. https://doi.org/10.1145/360933.360975 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Sandra Dylus, Jan Christiansen, and Finn Teegen. 2019. One Monad to Prove Them All. Art Sci. Eng. Program., 3, 3 (2019), 8. https://doi.org/10.22152/programming-journal.org/2019/3/8Google ScholarGoogle ScholarCross RefCross Ref
  12. Manuel Eberl. 2021. Asymptotic Reasoning in a Proof Assistant. Technical University of Munich, Munich, Germany. http://nbn-resolving.de/urn/resolver.pl?urn:nbn:de:bvb:91-diss-20210121-1554821-1-2Google ScholarGoogle Scholar
  13. Kenneth Foner, Hengchu Zhang, and Leonidas Lampropoulos. 2018. Keep your laziness in check. Proc. ACM Program. Lang., 2, ICFP (2018), 102:1–102:30. https://doi.org/10.1145/3236797 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Daniel P. Friedman and David S. Wise. 1974. Unwinding Structured Recursions into Iterations. Indiana University. https://help.luddy.indiana.edu/techreports/TRNNN.cgi?trnum=TR19Google ScholarGoogle Scholar
  15. Armaël Guéneau. 2019. Mechanized Verification of the Correctness and Asymptotic Complexity of Programs. (Vérification mécanisée de la correction et complexité asymptotique de programmes). Ph.D. Dissertation. Inria, Paris, France. https://tel.archives-ouvertes.fr/tel-02437532Google ScholarGoogle Scholar
  16. Armaël Guéneau, Arthur Charguéraud, and François Pottier. 2018. A Fistful of Dollars: Formalizing Asymptotic Complexity Claims via Deductive Program Verification. In Programming Languages and Systems - 27th European Symposium on Programming, ESOP 2018, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2018, Thessaloniki, Greece, April 14-20, 2018, Proceedings, Amal Ahmed (Ed.) (Lecture Notes in Computer Science, Vol. 10801). Springer, 533–560. https://doi.org/10.1007/978-3-319-89884-1_19 Google ScholarGoogle ScholarCross RefCross Ref
  17. Jennifer Hackett and Graham Hutton. 2019. Call-by-need is clairvoyant call-by-value. Proc. ACM Program. Lang., 3, ICFP (2019), 114:1–114:23. https://doi.org/10.1145/3341718 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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), 24:1–24:27. https://doi.org/10.1145/3371092 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Peter Henderson and James H. Morris, Jr.. 1976. A Lazy Evaluator. In Conference Record of the Third ACM Symposium on Principles of Programming Languages, Atlanta, Georgia, USA, January 1976, Susan L. Graham, Robert M. Graham, Michael A. Harrison, William I. Grosky, and Jeffrey D. Ullman (Eds.). ACM Press, 95–103. https://doi.org/10.1145/800168.811543 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. C. A. R. Hoare. 1969. An Axiomatic Basis for Computer Programming. Commun. ACM, 12, 10 (1969), 576–580. https://doi.org/10.1145/363235.363259 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Jan Hoffmann, Klaus Aehlig, and Martin Hofmann. 2012. Multivariate amortized resource analysis. ACM Trans. Program. Lang. Syst., 34, 3 (2012), 14:1–14:62. https://doi.org/10.1145/2362389.2362393 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. John Hughes. 1986. A Novel Representation of Lists and its Application to the Function "reverse". Inf. Process. Lett., 22, 3 (1986), 141–144. https://doi.org/10.1016/0020-0190(86)90059-1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. John Hughes. 1989. Why Functional Programming Matters. Comput. J., 32, 2 (1989), 98–107. https://doi.org/10.1093/comjnl/32.2.98 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Mark B. Josephs. 1989. The Semantics of Lazy Functional Languages. Theor. Comput. Sci., 68, 1 (1989), 105–111. https://doi.org/10.1016/0304-3975(89)90122-9 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Ugo Dal Lago. 2011. A Short Introduction to Implicit Computational Complexity. In Lectures on Logic and Computation - ESSLLI 2010 Copenhagen, Denmark, August 2010, ESSLLI 2011, Ljubljana, Slovenia, August 2011, Selected Lecture Notes, Nick Bezhanishvili and Valentin Goranko (Eds.) (Lecture Notes in Computer Science, Vol. 7388). Springer, 89–109. https://doi.org/10.1007/978-3-642-31485-8_3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. John Launchbury. 1993. A Natural Semantics for Lazy Evaluation. In Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Charleston, South Carolina, USA, January 1993, Mary S. Van Deusen and Bernard Lang (Eds.). ACM Press, 144–154. https://doi.org/10.1145/158511.158618 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Yao Li, Li-yao Xia, and Stephanie Weirich. 2021. Reasoning about the garden of forking paths (artifact). https://doi.org/10.5281/zenodo.4771438 GitHub repository at: Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Sheng Liang, Paul Hudak, and Mark P. Jones. 1995. Monad Transformers and Modular Interpreters. In Conference Record of POPL’95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, USA, January 23-25, 1995, Ron K. Cytron and Peter Lee (Eds.). ACM Press, 333–343. https://doi.org/10.1145/199448.199528 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Ravichandhran Madhavan, Sumith Kulal, and Viktor Kuncak. 2017. Contract-based resource verification for higher-order functions with memoization. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18-20, 2017, Giuseppe Castagna and Andrew D. Gordon (Eds.). ACM, 330–343. http://dl.acm.org/citation.cfm?id=3009874Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Kenji Maillard, Danel Ahman, Robert Atkey, Guido Martínez, Catalin Hritcu, Exequiel Rivas, and Éric Tanter. 2019. Dijkstra monads for all. Proc. ACM Program. Lang., 3, ICFP (2019), 104:1–104:29. https://doi.org/10.1145/3341708 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. John Maraist, Martin Odersky, David N. Turner, and Philip Wadler. 1995. Call-by-name, call-by-value, call-by-need and the linear lambda calculus. In Eleventh Annual Conference on Mathematical Foundations of Programming Semantics, MFPS 1995, Tulane University, New Orleans, LA, USA, March 29 - April 1, 1995, Stephen D. Brookes, Michael G. Main, Austin Melton, and Michael W. Mislove (Eds.) (Electronic Notes in Theoretical Computer Science, Vol. 1). Elsevier, 370–392. https://doi.org/10.1016/S1571-0661(04)00022-2 Google ScholarGoogle ScholarCross RefCross Ref
  32. Coq development team. 2021. The Coq proof assistant. http://coq.inria.fr Version 8.13.2.Google ScholarGoogle Scholar
  33. Eugenio Moggi. 1991. Notions of Computation and Monads. Inf. Comput., 93, 1 (1991), 55–92. https://doi.org/10.1016/0890-5401(91)90052-4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Andrew Moran and David Sands. 1999. Improvement in a Lazy Context: An Operational Theory for Call-by-Need. In POPL ’99, Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Antonio, TX, USA, January 20-22, 1999, Andrew W. Appel and Alex Aiken (Eds.). ACM, 43–56. https://doi.org/10.1145/292540.292547 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Aleksandar Nanevski, J. Gregory Morrisett, and Lars Birkedal. 2008. Hoare type theory, polymorphism and separation. J. Funct. Program., 18, 5-6 (2008), 865–911. https://doi.org/10.1017/S0956796808006953 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Peter W. O’Hearn. 2020. Incorrectness logic. Proc. ACM Program. Lang., 4, POPL (2020), 10:1–10:32. https://doi.org/10.1145/3371078 Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Chris Okasaki. 1999. Purely functional data structures. Cambridge University Press. isbn:978-0-521-66350-2Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Tomas Petricek. 2012. Evaluation strategies for monadic computations. In Proceedings Fourth Workshop on Mathematically Structured Functional Programming, [email protected] 2012, Tallinn, Estonia, 25 March 2012, James Chapman and Paul Blain Levy (Eds.) (EPTCS, Vol. 76). 68–89. https://doi.org/10.4204/EPTCS.76.7 Google ScholarGoogle ScholarCross RefCross Ref
  39. Vineet Rajani, Marco Gaboardi, Deepak Garg, and Jan Hoffmann. 2021. A unifying type-theory for higher-order (amortized) cost analysis. Proc. ACM Program. Lang., 5, POPL (2021), 1–28. https://doi.org/10.1145/3434308 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Amr Sabry and Matthias Felleisen. 1992. Reasoning About Programs in Continuation-Passing Style. In Proceedings of the Conference on Lisp and Functional Programming, LFP 1992, San Francisco, California, USA, 22-24 June 1992. ACM, 288–298. https://doi.org/10.1145/141471.141563 Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Dana S. Scott. 1976. Data Types as Lattices. SIAM J. Comput., 5, 3 (1976), 522–587. https://doi.org/10.1137/0205037 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Antal Spector-Zabusky, Joachim Breitner, Yao Li, and Stephanie Weirich. 2019. Embracing a mechanized formalization gap. CoRR, abs/1910.11724 (2019), arxiv:1910.11724. arxiv:1910.11724Google ScholarGoogle Scholar
  43. Antal Spector-Zabusky, Joachim Breitner, Christine Rizkallah, and Stephanie Weirich. 2018. Total Haskell is reasonable Coq. In Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2018, Los Angeles, CA, USA, January 8-9, 2018, June Andronick and Amy P. Felty (Eds.). ACM, 14–27. https://doi.org/10.1145/3167092 Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Nikhil Swamy, Joel Weinberger, Cole Schlesinger, Juan Chen, and Benjamin Livshits. 2013. Verifying higher-order programs with the Dijkstra monad. In ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’13, Seattle, WA, USA, June 16-19, 2013, Hans-Juergen Boehm and Cormac Flanagan (Eds.). ACM, 387–398. https://doi.org/10.1145/2491956.2491978 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Wouter Swierstra. 2009. A Hoare Logic for the State Monad. In Theorem Proving in Higher Order Logics, 22nd International Conference, TPHOLs 2009, Munich, Germany, August 17-20, 2009. Proceedings, Stefan Berghofer, Tobias Nipkow, Christian Urban, and Makarius Wenzel (Eds.) (Lecture Notes in Computer Science, Vol. 5674). Springer, 440–451. https://doi.org/10.1007/978-3-642-03359-9_30 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Wouter Swierstra and Tim Baanen. 2019. A predicate transformer semantics for effects (functional pearl). Proc. ACM Program. Lang., 3, ICFP (2019), 103:1–103:26. https://doi.org/10.1145/3341707 Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. D. A. Turner. 2004. Total Functional Programming. J. Univers. Comput. Sci., 10, 7 (2004), 751–768. https://doi.org/10.3217/jucs-010-07-0751 Google ScholarGoogle ScholarCross RefCross Ref
  48. Tarmo Uustalu. 2002. Monad Translating Inductive and Coinductive Types. In Types for Proofs and Programs, Second International Workshop, TYPES 2002, Berg en Dal, The Netherlands, April 24-28, 2002, Selected Papers, Herman Geuvers and Freek Wiedijk (Eds.) (Lecture Notes in Computer Science, Vol. 2646). Springer, 299–315. https://doi.org/10.1007/3-540-39185-1_17 Google ScholarGoogle ScholarCross RefCross Ref
  49. Niki Vazou. 2016. Liquid Haskell: Haskell as a Theorem Prover. Ph.D. Dissertation. University of California, San Diego, USA. http://www.escholarship.org/uc/item/8dm057wsGoogle ScholarGoogle Scholar
  50. Philip Wadler. 1992. Comprehending Monads. Math. Struct. Comput. Sci., 2, 4 (1992), 461–493. https://doi.org/10.1017/S0960129500001560 Google ScholarGoogle ScholarCross RefCross Ref
  51. Peng Wang, Di Wang, and Adam Chlipala. 2017. TiML: a functional language for practical complexity analysis with invariants. Proc. ACM Program. Lang., 1, OOPSLA (2017), 79:1–79:26. https://doi.org/10.1145/3133903 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Reasoning about the garden of forking paths

            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

            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!