skip to main content
research-article
Open Access
Artifacts Available
Artifacts Evaluated & Functional

TiML: a functional language for practical complexity analysis with invariants

Published:12 October 2017Publication History
Skip Abstract Section

Abstract

We present TiML (Timed ML), an ML-like functional language with time-complexity annotations in types. It uses indexed types to express sizes of data structures and upper bounds on running time of functions; and refinement kinds to constrain these indices, expressing data-structure invariants and pre/post-conditions. Indexed types are flexible enough that TiML avoids a built-in notion of ≴size,≵ and the programmer can choose to index user-defined datatypes in any way that helps her analysis. TiML's distinguishing characteristic is supporting highly automated time-bound verification applicable to data structures with nontrivial invariants. The programmer provides type annotations, and the typechecker generates verification conditions that are discharged by an SMT solver. Type and index inference are supported to lower annotation burden, and, furthermore, big-O complexity can be inferred from recurrences generated during typechecking by a recurrence solver based on heuristic pattern matching (e.g. using the Master Theorem to handle divide-and-conquer-like recurrences). We have evaluated TiML's usability by implementing a broad suite of case-study modules, demonstrating that TiML, though lacking full automation and theoretical completeness, is versatile enough to verify worst-case and/or amortized complexities for algorithms and data structures like classic list operations, merge sort, Dijkstra's shortest-path algorithm, red-black trees, Braun trees, functional queues, and dynamic tables with bounds like m n logn. The learning curve and annotation burden are reasonable, as we argue with empirical results on our case studies. We formalized TiML's type-soundness proof in Coq.

Skip Supplemental Material Section

Supplemental Material

References

  1. Elvira Albert, Puri Arenas, Samir Genaim, and Germán Puebla. 2008. Automatic Inference of Upper Bounds for Recurrence Relations in Cost Analysis. In Proceedings of the 15th International Symposium on Static Analysis (SAS 2008). SpringerVerlag, 221–237. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. E. Albert, P. Arenas, S. Genaim, G. Puebla, and D. Zanardini. 2007. Cost Analysis of Java Bytecode. In Proceedings of the 16th European Symposium on Programming (ESOP 2007). Springer-Verlag, 157–172. Google ScholarGoogle ScholarCross RefCross Ref
  3. Elvira Albert, Puri Arenas, Samir Genaim, German Puebla, and Damiano Zanardini. 2008. COSTA: Design and Implementation of a Cost and Termination Analyzer for Java Bytecode. In Formal Methods for Components and Objects: 6th International Symposium (FMCO 2007). Springer Berlin Heidelberg, 113–132.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Elvira Albert, Samir Genaim, and Miguel Gómez-Zamalloa Gil. 2009. Live Heap Space Analysis for Languages with Garbage Collection. In Proceedings of the 2009 International Symposium on Memory Management (ISMM 2009). ACM, 129–138. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. David Aspinall, Lennart Beringer, Martin Hofmann, Hans-Wolfgang Loidl, and Alberto Momigliano. 2007. A Program Logic for Resources. Theoretical Computer Science 389, 3 (Dec. 2007), 411–445. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Robert Atkey. 2010. Amortised Resource Analysis with Separation Logic. In Proceedings of the 19th European Conference on Programming Languages and Systems (ESOP 2010). Springer-Verlag, 85–103. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Martin Avanzini, Ugo Dal Lago, and Georg Moser. 2015. Analysing the Complexity of Functional Programs: Higher-order Meets First-order. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015). ACM, 152–164. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Ralph Benzinger. 2001. Automated Complexity Analysis of Nuprl Extracted Programs. Journal of Functional Programming 11, 1 (Jan. 2001), 3–31. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Ralph Benzinger. 2004. Automated Higher-order Complexity Analysis. Theoretical Computer Science 318, 1-2 (June 2004), 79–103.Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Marc Brockschmidt, Fabian Emmes, Stephan Falke, Carsten Fuhs, and Jürgen Giesl. 2014. Alternating Runtime and Size Complexity Analysis of Integer Programs. In Tools and Algorithms for the Construction and Analysis of Systems: 20th International Conference (TACAS 2014). Springer Berlin Heidelberg, 140–155. Google ScholarGoogle ScholarCross RefCross Ref
  11. Ezgi Çiçek, Gilles Barthe, Marco Gaboardi, Deepak Garg, and Jan Hoffmann. 2017. Relational Cost Analysis. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, 316–329. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Ezgi Çiçek, Zoe Paraskevopoulou, and Deepak Garg. 2016. A Type Theory for Incremental Computational Complexity with Control Flow Changes. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). ACM, 132–145. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Arthur Charguéraud and François Pottier. 2015. Machine-Checked Verification of the Correctness and Amortized Complexity of an Efficient Union-Find Implementation. In Interactive Theorem Proving: 6th International Conference (ITP 2015). Springer International Publishing, 137–153. Google ScholarGoogle ScholarCross RefCross Ref
  14. Ezgi Çiçek, Deepak Garg, and Umut Acar. 2015. Refinement Types for Incremental Computational Complexity. In Programming Languages and Systems: 24th European Symposium on Programming (ESOP 2015). Springer Berlin Heidelberg, 406–431. Google ScholarGoogle ScholarCross RefCross Ref
  15. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. 2009. Introduction to Algorithms, Third Edition (3rd ed.). The MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Karl Crary and Stephnie Weirich. 2000. Resource Bound Certification. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2000). ACM, 184–198. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Scott A. Crosby and Dan S. Wallach. 2003. Denial of Service via Algorithmic Complexity Attacks. In Proceedings of the 12th Conference on USENIX Security Symposium - Volume 12 (SSYM 2003). USENIX Association, 3–3.Google ScholarGoogle Scholar
  18. Ugo Dal Lago and Barbara Petit. 2013. The Geometry of Types. In Proceedings of the 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2013). ACM, 167–178. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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). ACM, 133–144. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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). ACM, 140–151. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Leonardo De Moura and Nikolaj Bjørner. 2008. Z3: An Efficient SMT Solver. In Proceedings of the Theory and Practice of Software, 14th International Conference on Tools and Algorithms for the Construction and Analysis of Systems (TACAS 2008/ETAPS 2008). Springer-Verlag, 337–340.Google ScholarGoogle ScholarCross RefCross Ref
  22. Dan R. Ghica and Alex Smith. 2011. Geometry of Synthesis III: Resource Management Through Type Inference. In Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2011). ACM, 345–356. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Stéphane Gimenez and Georg Moser. 2016. The Complexity of Interaction. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2016). ACM, 243–255. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Bernd Grobauer. 2001. Cost Recurrences for DML Programs. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP 2001). ACM, 253–264. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Bhargav S. Gulavani and Sumit Gulwani. 2008. A Numerical Abstract Domain Based on Expression Abstraction and Max Operator with Application in Timing Analysis. In Proceedings of the 20th International Conference on Computer Aided Verification (CAV 2008). Springer-Verlag, 370–384. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Sumit Gulwani, Krishna K. Mehra, and Trishul Chilimbi. 2009. SPEED: Precise and Efficient Static Estimation of Program Computational Complexity. In Proceedings of the 36th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2009). ACM, 127–139. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Sumit Gulwani and Florian Zuleger. 2010. The Reachability-bound Problem. In Proceedings of the 31st ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2010). ACM, 292–304. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Robert Harper. 2014. Structure and Efficiency of Computer Programs. (2014). http://www.cs.cmu.edu/~rwh/papers/secp/ secp.pdfGoogle ScholarGoogle Scholar
  29. Jan Hoffmann, Klaus Aehlig, and Martin Hofmann. 2011. Multivariate Amortized Resource Analysis. In Proceedings of the 38th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2011). ACM, 357–370. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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). ACM, 359–373. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Jan Hoffmann and Martin Hofmann. 2010. Amortized Resource Analysis with Polynomial Potential: A Static Inference of Polynomial Bounds for Functional Programs. In Proceedings of the 19th European Conference on Programming Languages and Systems (ESOP 2010). Springer-Verlag, 287–306. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Jan Hoffmann and Zhong Shao. 2015. Automatic Static Cost Analysis for Parallel Programs. In Proceedings of the 24th European Symposium on Programming Languages and Systems (ESOP 2015). Springer-Verlag New York, Inc., 132–157. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 (POPL 2003). ACM, 185–197. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. John Hughes, Lars Pareto, and Amr Sabry. 1996. Proving the Correctness of Reactive Systems Using Sized Types. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 1996). ACM, 410–423. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Steffen Jost, Kevin Hammond, Hans-Wolfgang Loidl, and Martin Hofmann. 2010. Static Determination of Quantitative Resource Usage for Higher-order Programs. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2010). ACM, 223–236. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Paul C. Kocher. 1996. Timing Attacks on Implementations of Diffie-Hellman, RSA, DSS, and Other Systems. In Proceedings of the 16th Annual International Cryptology Conference on Advances in Cryptology (CRYPTO 1996). Springer-Verlag, 104– 113. Google ScholarGoogle ScholarCross RefCross Ref
  37. K. Rustan M. Leino. 2010. Dafny: An Automatic Program Verifier for Functional Correctness. In Proceedings of the 16th International Conference on Logic for Programming, Artificial Intelligence, and Reasoning (LPAR 2010). Springer-Verlag, 348–370.Google ScholarGoogle ScholarCross RefCross Ref
  38. 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). ACM, 330–343. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Ravichandhran Madhavan and Viktor Kuncak. 2014. Symbolic Resource Bound Inference for Functional Programs. In Proceedings of the 16th International Conference on Computer Aided Verification - Volume 8559 (CAV 2014). Springer-Verlag New York, Inc., 762–778. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Jay McCarthy, Burke Fetscher, Max New, Daniel Feltey, and Robert Bruce Findler. 2016. A Coq Library for Internal Verification of Running-Times. In Functional and Logic Programming: 13th International Symposium (FLOPS 2016). Springer International Publishing, 144–162. Google ScholarGoogle ScholarCross RefCross Ref
  41. George C. Necula. 1997. Proof-carrying Code. In Proceedings of the 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 1997). ACM, 106–119. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Chris Okasaki. 1997. Three Algorithms on Braun Trees. Journal of Functional Programming 7, 6 (Nov. 1997), 661–666. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Chris Okasaki. 1999. Purely Functional Data Structures. Cambridge University Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Benjamin C. Pierce. 2002. Types and Programming Languages (1st ed.). The MIT Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Brian Reistad and David K. Gifford. 1994. Static Dependent Costs for Estimating Execution Time. In Proceedings of the 1994 ACM Conference on LISP and Functional Programming (LFP 1994). ACM, 65–78. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Patrick M. Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid Types. In Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2008). ACM, 159–169. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Akhilesh Srikanth, Burak Sahin, and William R. Harris. 2017. Complexity Verification Using Guided Theorem Enumeration. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, 639– 652. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Nikhil Swamy, Joel Weinberger, Cole Schlesinger, Juan Chen, and Benjamin Livshits. 2013. Verifying Higher-order Programs with the Dijkstra Monad. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2013). ACM, 387–398. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Robert Endre Tarjan. 1985. Amortized Computational Complexity. SIAM Journal on Algebraic Discrete Methods 6, 2 (1985), 306–318. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Pedro B. Vasconcelos and Kevin Hammond. 2004. Inferring Cost Equations for Recursive, Polymorphic and Higher-order Functional Programs. In Proceedings of the 15th International Conference on Implementation of Functional Languages (IFL 2003). Springer-Verlag, 86–101. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Niki Vazou, Alexander Bakst, and Ranjit Jhala. 2015. Bounded Refinement Types. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015). ACM, 48–61. Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Niki Vazou, Patrick M. Rondon, and Ranjit Jhala. 2013. Abstract Refinement Types. In Proceedings of the 22nd European Conference on Programming Languages and Systems (ESOP 2013). Springer-Verlag, 209–228. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Hongwei Xi and Frank Pfenning. 1998. Eliminating Array Bound Checking Through Dependent Types. In Proceedings of the ACM SIGPLAN 1998 Conference on Programming Language Design and Implementation (PLDI 1998). ACM, 249–257. Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. Hongwei Xi and Frank Pfenning. 1999. Dependent Types in Practical Programming. In Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 1999). ACM, 214–227. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. TiML: a functional language for practical complexity analysis with invariants

            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!