[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
research-article
Open access

TiML: a functional language for practical complexity analysis with invariants

Published: 12 October 2017 Publication History

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.

Supplementary Material

Auxiliary Archive (oopsla17-oopsla56-aux.zip)

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.
[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.
[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.
[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.
[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.
[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.
[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.
[8]
Ralph Benzinger. 2001. Automated Complexity Analysis of Nuprl Extracted Programs. Journal of Functional Programming 11, 1 (Jan. 2001), 3–31.
[9]
Ralph Benzinger. 2004. Automated Higher-order Complexity Analysis. Theoretical Computer Science 318, 1-2 (June 2004), 79–103.
[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.
[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.
[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.
[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.
[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.
[15]
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. 2009. Introduction to Algorithms, Third Edition (3rd ed.). The MIT Press.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[28]
Robert Harper. 2014. Structure and Efficiency of Computer Programs. (2014). http://www.cs.cmu.edu/~rwh/papers/secp/ secp.pdf
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[42]
Chris Okasaki. 1997. Three Algorithms on Braun Trees. Journal of Functional Programming 7, 6 (Nov. 1997), 661–666.
[43]
Chris Okasaki. 1999. Purely Functional Data Structures. Cambridge University Press.
[44]
Benjamin C. Pierce. 2002. Types and Programming Languages (1st ed.). The MIT Press.
[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.
[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.
[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.
[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.
[49]
Robert Endre Tarjan. 1985. Amortized Computational Complexity. SIAM Journal on Algebraic Discrete Methods 6, 2 (1985), 306–318.
[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.
[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.
[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.
[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.
[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.

Cited By

View all
  • (2023)Inferring Complexity Bounds from Recurrence RelationsProceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering10.1145/3611643.3617853(2198-2200)Online publication date: 30-Nov-2023
  • (2023)Focusing on Refinement TypingACM Transactions on Programming Languages and Systems10.1145/361040845:4(1-62)Online publication date: 20-Dec-2023
  • (2023)Fine-Tuning Data Structures for Query ProcessingProceedings of the 21st ACM/IEEE International Symposium on Code Generation and Optimization10.1145/3579990.3580016(149-161)Online publication date: 17-Feb-2023
  • Show More Cited By

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 1, Issue OOPSLA
October 2017
1786 pages
EISSN:2475-1421
DOI:10.1145/3152284
Issue’s Table of Contents
Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for third-party components of this work must be honored. For all other uses, contact the Owner/Author.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 12 October 2017
Published in PACMPL Volume 1, Issue OOPSLA

Check for updates

Badges

Author Tags

  1. asymptotic complexity
  2. refinement types
  3. resource-aware type systems

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)146
  • Downloads (Last 6 weeks)29
Reflects downloads up to 02 Mar 2025

Other Metrics

Citations

Cited By

View all
  • (2023)Inferring Complexity Bounds from Recurrence RelationsProceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering10.1145/3611643.3617853(2198-2200)Online publication date: 30-Nov-2023
  • (2023)Focusing on Refinement TypingACM Transactions on Programming Languages and Systems10.1145/361040845:4(1-62)Online publication date: 20-Dec-2023
  • (2023)Fine-Tuning Data Structures for Query ProcessingProceedings of the 21st ACM/IEEE International Symposium on Code Generation and Optimization10.1145/3579990.3580016(149-161)Online publication date: 17-Feb-2023
  • (2023)A Statistical Relational Learning Approach Towards Products, Software Vulnerabilities and ExploitsIEEE Transactions on Network and Service Management10.1109/TNSM.2023.323455420:3(3782-3802)Online publication date: 1-Sep-2023
  • (2023)Automatic Amortized Resource Analysis with Regular Recursive Types2023 38th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS)10.1109/LICS56636.2023.10175720(1-14)Online publication date: 26-Jun-2023
  • (2022)A cost-aware logical frameworkProceedings of the ACM on Programming Languages10.1145/34986706:POPL(1-31)Online publication date: 12-Jan-2022
  • (2022)For a Few Dollars More: Verified Fine-Grained Algorithm Analysis Down to LLVMACM Transactions on Programming Languages and Systems10.1145/348616944:3(1-36)Online publication date: 15-Jul-2022
  • (2022)Denotational semantics as a foundation for cost recurrence extraction for functional languagesJournal of Functional Programming10.1017/S095679682200003X32Online publication date: 5-Jul-2022
  • (2022)The Next 700 Smart Contract LanguagesPrinciples of Blockchain Systems10.1007/978-3-031-01807-7_3(69-94)Online publication date: 18-Mar-2022
  • (2021)A flat reachability-based measure for CakeML’s cost semanticsProceedings of the 33rd Symposium on Implementation and Application of Functional Languages10.1145/3544885.3544887(1-9)Online publication date: 1-Sep-2021
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media