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.
Supplemental Material
Available for Download
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Ralph Benzinger. 2001. Automated Complexity Analysis of Nuprl Extracted Programs. Journal of Functional Programming 11, 1 (Jan. 2001), 3–31. Google Scholar
Digital Library
- Ralph Benzinger. 2004. Automated Higher-order Complexity Analysis. Theoretical Computer Science 318, 1-2 (June 2004), 79–103.Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. 2009. Introduction to Algorithms, Third Edition (3rd ed.). The MIT Press.Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Robert Harper. 2014. Structure and Efficiency of Computer Programs. (2014). http://www.cs.cmu.edu/~rwh/papers/secp/ secp.pdfGoogle Scholar
- 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 Scholar
Digital 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). ACM, 359–373. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital 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 (POPL 2003). ACM, 185–197. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Chris Okasaki. 1997. Three Algorithms on Braun Trees. Journal of Functional Programming 7, 6 (Nov. 1997), 661–666. Google Scholar
Digital Library
- Chris Okasaki. 1999. Purely Functional Data Structures. Cambridge University Press.Google Scholar
Digital Library
- Benjamin C. Pierce. 2002. Types and Programming Languages (1st ed.). The MIT Press.Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Robert Endre Tarjan. 1985. Amortized Computational Complexity. SIAM Journal on Algebraic Discrete Methods 6, 2 (1985), 306–318. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
TiML: a functional language for practical complexity analysis with invariants
Recommendations
Sums of uncertainty: refinements go gradual
POPL '17A long-standing shortcoming of statically typed functional languages is that type checking does not rule out pattern-matching failures (run-time match exceptions). Refinement types distinguish different values of datatypes; if a program annotated with ...
Self-certification: bootstrapping certified typecheckers in F* with Coq
POPL '12Well-established dependently-typed languages like Agda and Coq provide reliable ways to build and check formal proofs. Several other dependently-typed languages such as Aura, ATS, Cayenne, Epigram, F*, F7, Fine, Guru, PCML5, and Ur also explore reliable ...
Sums of uncertainty: refinements go gradual
POPL '17: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming LanguagesA long-standing shortcoming of statically typed functional languages is that type checking does not rule out pattern-matching failures (run-time match exceptions). Refinement types distinguish different values of datatypes; if a program annotated with ...






Comments