Abstract
We present a framework to verify both, functional correctness and worst-case complexity of practically efficient algorithms. We implemented a stepwise refinement approach, using the novel concept of resource currencies to naturally structure the resource analysis along the refinement chain, and allow a fine-grained analysis of operation counts. Our framework targets the LLVM intermediate representation. We extend its semantics from earlier work with a cost model. As case study, we verify the correctness and \(O(n\log n)\) worst-case complexity of an implementation of the introsort algorithm, whose performance is on par with the state-of-the-art implementation found in the GNU C++ Library.
Chapter PDF
Similar content being viewed by others
References
Atkey, R.: Amortised resource analysis with separation logic. In: Gordon, A.D. (ed.) European Symposium on Programming, ESOP 2010. Lecture Notes in Computer Science, vol. 6012, pp. 85–103. Springer (2010). https://doi.org/10.1007/978-3-642-11957-6_6, https://doi.org/10.1007/978-3-642-11957-6_6
Blazy, S., Leroy, X.: Mechanized semantics for the Clight subset of the C language. J. Autom. Reason. 43(3), 263–288 (2009). https://doi.org/10.1007/s10817-009-9148-3, https://doi.org/10.1007/s10817-009-9148-3
Calcagno, C., O’Hearn, P.W., Yang, H.: Local action and abstract separation logic. In: Symposium on Logic in Computer Science (LICS 2007). pp. 366–378. IEEE Computer Society (2007). https://doi.org/10.1109/LICS.2007.30, https://doi.org/10.1109/LICS.2007.30
Carbonneaux, Q., Hoffmann, J., Ramananandro, T., Shao, Z.: End-to-end verification of stack-space bounds for C programs. In: O’Boyle, M.F.P., Pingali, K. (eds.) ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’14, Edinburgh, United Kingdom - June 09 - 11, 2014. pp. 270–281. ACM (2014). https://doi.org/10.1145/2594291.2594301, https://doi.org/10.1145/2594291.2594301
Charguéraud, A.: Separation logic for sequential programs (functional pearl). Proc. ACM Program. Lang. 4(ICFP), 116:1–116:34 (2020). https://doi.org/10.1145/3408998, https://doi.org/10.1145/3408998
Charguéraud, A., Pottier, F.: Verifying the correctness and amortized complexity of a union-find implementation in separation logic with time credits. J. Autom. Reason. 62(3), 331–365 (2019). https://doi.org/10.1007/s10817-017-9431-7, https://doi.org/10.1007/s10817-017-9431-7
cppreference: C++ standard library specification of sort. https://en.cppreference.com/w/cpp/algorithm/sort, accessed: 2020-10-12
The GNU C++ library, https://gcc.gnu.org/onlinedocs/libstdc++/, version 7.4.0
Guéneau, A., Charguéraud, A., Pottier, F.: A fistful of dollars: Formalizing asymptotic complexity claims via deductive program verification. In: Ahmed, A. (ed.) Programming Languages and Systems - 27th European Symposium on Programming, ESOP 2018. Lecture Notes in Computer Science, vol. 10801, pp. 533–560. Springer (2018). https://doi.org/10.1007/978-3-319-89884-1_19, https://doi.org/10.1007/978-3-319-89884-1_19
Guéneau, A., Jourdan, J., Charguéraud, A., Pottier, F.: Formal proof and analysis of an incremental cycle detection algorithm. In: Harrison, J., O’Leary, J., Tolmach, A. (eds.) 10th International Conference on Interactive Theorem Proving, ITP 2019. LIPIcs, vol. 141, pp. 18:1–18:20. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2019). https://doi.org/10.4230/LIPIcs.ITP.2019.18, https://doi.org/10.4230/LIPIcs.ITP.2019.18
Haslbeck, M.P.L., Lammich, P.: Refinement with time - refining the run-time of algorithms in Isabelle/HOL. In: Harrison, J., O’Leary, J., Tolmach, A. (eds.) 10th International Conference on Interactive Theorem Proving, ITP 2019. LIPIcs, vol. 141, pp. 20:1–20:18. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2019). https://doi.org/10.4230/LIPIcs.ITP.2019.20, https://doi.org/10.4230/LIPIcs.ITP.2019.20
Hoare, C.A.R.: Algorithm 64: Quicksort. Commun. ACM 4(7), 321– (Jul 1961). https://doi.org/10.1145/366622.366644, https://doi.org/10.1145/366622.366644
Krauss, A.: Recursive definitions of monadic functions. In: Bove, A., Komendantskaya, E., Niqui, M. (eds.) Proceedings Workshop on Partiality and Recursion in Interactive Theorem Provers, PAR 2010, Edinburgh, UK, 15th July 2010. EPTCS, vol. 43, pp. 1–13 (2010). https://doi.org/10.4204/EPTCS.43.1, https://doi.org/10.4204/EPTCS.43.1
Lammich, P.: Refinement to Imperative/HOL. In: Urban, C., Zhang, X. (eds.) Interactive Theorem Proving - 6th International Conference, ITP 2015. Lecture Notes in Computer Science, vol. 9236, pp. 253–269. Springer (2015). https://doi.org/10.1007/978-3-319-22102-1_17, https://doi.org/10.1007/978-3-319-22102-1_17
Lammich, P.: Generating verified LLVM from Isabelle/HOL. In: Harrison, J., O’Leary, J., Tolmach, A. (eds.) 10th International Conference on Interactive Theorem Proving, ITP 2019. LIPIcs, vol. 141, pp. 22:1–22:19. Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2019). https://doi.org/10.4230/LIPIcs.ITP.2019.22, https://doi.org/10.4230/LIPIcs.ITP.2019.22
Lammich, P.: Refinement to Imperative HOL. J. Autom. Reason. 62(4), 481–503 (2019). https://doi.org/10.1007/s10817-017-9437-1, https://doi.org/10.1007/s10817-017-9437-1
Lammich, P.: Efficient verified implementation of introsort and pdqsort. In: Peltier, N., Sofronie-Stokkermans, V. (eds.) IJCAR 2020. Lecture Notes in Computer Science, vol. 12167, pp. 307–323. Springer (2020). https://doi.org/10.1007/978-3-030-51054-1_18, https://doi.org/10.1007/978-3-030-51054-1_18
Lammich, P., Meis, R.: A Separation Logic Framework for Imperative HOL. Archive of Formal Proofs (Nov 2012), http://isa-afp.org/entries/Separation_Logic_Imperative_HOL.html, Formal proof development
Lammich, P., Tuerk, T.: Applying data refinement for monadic programs to Hopcroft’s algorithm. In: Beringer, L., Felty, A.P. (eds.) Interactive Theorem Proving - Third International Conference, ITP 2012. Lecture Notesin Computer Science, vol. 7406, pp. 166–182. Springer (2012). https://doi.org/10.1007/978-3-642-32347-8_12, https://doi.org/10.1007/978-3-642-32347-8_12
”libc++” c++ standard library, https://libcxx.llvm.org/
Mével, G., Jourdan, J., Pottier, F.: Time credits and time receipts in Iris. In: Caires, L. (ed.) Programming Languages and Systems - 28th European Symposium on Programming, ESOP 2019. Lecture Notes in Computer Science, vol. 11423, pp. 3–29. Springer (2019). https://doi.org/10.1007/978-3-030-17184-1_1, https://doi.org/10.1007/978-3-030-17184-1_1
Musser, D.R.: Introspective sorting and selection algorithms. Softw. Pract. Exp. 27(8), 983–993 (1997)
Nipkow, T., Eberl, M., Haslbeck, M.P.L.: Verified textbook algorithms - A biased survey. In: Hung, D.V., Sokolsky, O. (eds.) Automated Technology for Verification and Analysis - 18th International Symposium, ATVA 2020. Lecture Notes in Computer Science, vol. 12302, pp. 25–53. Springer (2020). https://doi.org/10.1007/978-3-030-59152-6_2, https://doi.org/10.1007/978-3-030-59152-6_2
Wadler, P.: Comprehending monads. In: Proceedings of the 1990 ACM Conference on LISP and Functional Programming. p. 6178. LFP ’90, Association for Computing Machinery, New York, NY, USA (1990). https://doi.org/10.1145/91556.91592, https://doi.org/10.1145/91556.91592
Wang, P., Wang, D., Chlipala, A.: TiML: a functional language for practical complexity analysis with invariants. Proc. ACM Program. Lang. 1(OOPSLA), 79:1–79:26 (2017). https://doi.org/10.1145/3133903, https://doi.org/10.1145/3133903
Zhan, B., Haslbeck, M.P.L.: Verifying asymptotic time complexity of imperative programs in Isabelle. In: Galmiche, D., Schulz, S., Sebastiani, R. (eds.) Automated Reasoning - 9th International Joint Conference, IJCAR 2018. Lecture Notes in Computer Science, vol. 10900, pp. 532–548. Springer (2018). https://doi.org/10.1007/978-3-319-94205-6_35, https://doi.org/10.1007/978-3-319-94205-6_35
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
Copyright information
© 2021 The Author(s)
About this paper
Cite this paper
Haslbeck, M.P.L., Lammich, P. (2021). For a Few Dollars More. In: Yoshida, N. (eds) Programming Languages and Systems. ESOP 2021. Lecture Notes in Computer Science(), vol 12648. Springer, Cham. https://doi.org/10.1007/978-3-030-72019-3_11
Download citation
DOI: https://doi.org/10.1007/978-3-030-72019-3_11
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-72018-6
Online ISBN: 978-3-030-72019-3
eBook Packages: Computer ScienceComputer Science (R0)