Skip to main content
Log in

Efficient Extensional Binary Tries

  • Published:
Journal of Automated Reasoning Aims and scope Submit manuscript

Abstract

Lookup tables (finite maps) are a ubiquitous data structure. In pure functional languages they are best represented using trees instead of hash tables. In pure functional languages within constructive logic, without a primitive integer type, they are well represented using binary tries instead of search trees. In this work, we introduce canonical binary tries, an improved binary-trie data structure that enjoys a natural extensionality property, quite useful in proofs, and supports sparseness more efficiently. We provide full proofs of correctness in Coq. We provide microbenchmark measurements of canonical binary tries versus several other data structures for finite maps, in a variety of application contexts; as well as measurement of canonical versus original tries in two big, real systems. The application context of data structures contained in theorem statements imposes unusual requirements for which canonical tries are particularly well suited.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

Notes

  1. All proofs mentioned in this paper are machine-checked unless explicitly noted otherwise.

  2. Persistent arrays give a functional semantics layered on an imperative (destructive-update) implementation, but these are not suitable because they would require extending the logic’s kernel of axioms.

  3. In fact, no programming language has a primitive integer type with constant-time comparisons; they typically have a range-limited integer type \(-2^k\le i < 2^k\) or a modular integer type \((i \bmod 2^k)\). Most versions of Coq 2005-present have not had a built-in integer type with fast comparisons; and relying on them would increase the size of the trusted base, that is, Coq kernel code, Coq axioms, Coq extraction to OCaml, and OCaml operations upon which we rely.

  4. In OCaml, an arity-k constructor applied to arguments takes \(k+1\) words, including one for the constructor-tag. In Coq, an arity-k constructor is represented as one arity-2 OCaml construction plus one length-k array, which take (respectively) 3 words and \(k+1\) words as represented in OCaml within the Coq kernel. The arity-2 OCaml construction also points to a description of the constructor, but that description is shared among all its uses so we don’t count it.

  5. Andreas Abel, personal communications, Aug-Sept 2022. Examples of problematic unifications can be found at https://github.com/agda/agda/issues/483.

  6. In table 1, performance of PTrees in VST could be predicted in row “Coq execution, vm_compute, Sparse test,” column Sigma versus columns Original and Canonical; whereas PTree performance in CompCert could be predicted in row “Extraction to OCaml, Sparse test”, same columns.

  7. This Coq verification is at https://github.com/PrincetonUniversity/VST/releases/tag/v2.9.1 in subdirectory progs/VSUpile.

  8. , , , , , ,

  9. Measurements were performed on a Lenovo t440p laptop with Intel Core i7-4810MQ @ 2.8GHz with 32GB memory, using Coq 8.14/8.15.1 in 32-bit mode with virtual-memory limit of 1GB. The Clight abstract-syntax-tree files were produced by in its default mode.

References

  1. Abel, A., Coquand, T., Pagano, M.: A modular type-checking algorithm for type theory with singleton types and proof irrelevance. Log. Methods Comput. Sci. (2011). https://doi.org/10.2168/LMCS-7(2:4)2011

    Article  MathSciNet  MATH  Google Scholar 

  2. Appel, A.W.: Verified Software Toolchain. In: 20th European Symposium on Programming (ESOP’11), LNCS, vol. 6602, 1–17. Springer (2011). https://doi.org/10.1007/978-3-642-19718-5_1

  3. Appel, A.W.: Verified Functional Algorithms, Software Foundations, vol. 3. softwarefoundations.org (2017). https://softwarefoundations.cis.upenn.edu/vfa-current

  4. Appel, A.W., Dockins, R., Hobor, A., Beringer, L., Dodds, J., Stewart, G., Blazy, S., Leroy, X.: Program logics for certified compilers. Cambridge University Press, Cambridge (2014)

    Book  MATH  Google Scholar 

  5. Beringer, L.: Verified software units. In: 30th European Symposium on Programming (ESOP’21), LNCS, vol. 12648, 118–147. Springer (2021). https://doi.org/10.1007/978-3-030-72019-3_5

  6. Beringer, L., Appel, A.W.: Abstraction and subsumption in modular verification of C programs. Formal Methods Syst. Des. 58(1), 322–345 (2021). https://doi.org/10.1007/s10703-020-00353-1

    Article  MATH  Google Scholar 

  7. Boyer, R.S., Moore, J.S.: Single-threaded objects in ACL2. In: Practical Aspects of Declarative Languages, 4th International Symposium (PADL’02), LNCS, vol. 2257, pp. 9–27. Springer (2002). https://doi.org/10.1007/3-540-45587-6_3

  8. Cao, Q., Beringer, L., Gruetter, S., Dodds, J., Appel, A.W.: VST-Floyd: a separation logic tool to verify correctness of C programs. J. Autom. Reason. 61(1–4), 367–422 (2018). https://doi.org/10.1007/s10817-018-9457-5

    Article  MathSciNet  MATH  Google Scholar 

  9. Filliâtre, J.-C., Letouzey, P.: Functors for proofs and programs. In: 13th European Symposium on Programming, ESOP 2004, LNCS, vol. 2986, pp. 370–384. Springer (2004). https://doi.org/10.1007/978-3-540-24725-8_26

  10. Gordon, M.J., Milner, R., Wadsworth, C.P.: Edinburgh LCF: A Mechanised Logic of Computation. Lecture Notes in Computer Science, vol. 78. Springer, New York (1979)

  11. Jourdan, J.H., Laporte, V., Blazy, S., Leroy, X., Pichardie, D.: A formally-verified C static analyzer. In: POPL 2015: 42nd symposium Principles of Programming Languages, pp. 247–259. ACM (2015). https://doi.org/10.1145/2676726.2676966

  12. Krebbers, R., et al.: The Coq-std++ extended standard library, module stdpp.pmap (2012–2021). https://plv.mpi-sws.org/coqdoc/stdpp/stdpp.pmap.html

  13. Leroy, X.: Formal verification of a realistic compiler. Commun. ACM 52(7), 107–115 (2009). https://doi.org/10.1145/1538788.1538814

    Article  Google Scholar 

  14. Leroy, X., Appel, A.W.: Canonical binary trees, the Coq development, version 2 (2022). https://github.com/xavierleroy/canonical-binary-tries/tree/v2. Software Heritage ID swh:1:dir:02996583ae02411d8e1e7c3f20bc12b0eebbf96a

  15. Leroy, X., Appel, A.W., Doligez, D.: The CompCert verified C compiler, module Maps (2021–2022). https://compcert.org/doc-3.10/html/compcert.lib.Maps.html. Software Heritage ID swh:1:cnt:0d83aa98a1d7cc150a3164ad487d9cde9c00a64f

  16. Leroy, X., Doligez, D.: The CompCert verified C compiler, module Maps (2005–2021). https://compcert.org/doc-3.9/html/compcert.lib.Maps.html. Software Heritage ID swh:1:cnt:6bc6e14bf54f778029e13b192aaab53dd5e819a4

  17. Letouzey, P.: MMaps: Modular finite maps over ordered types (2015–2020). https://github.com/letouzey/coq-mmaps

  18. Nipkow, T., Blanchette, J., Eberl, M., Gómez-Londoño, A., Lammich, P., Sternagel, C., Wimmer, S., Zhan, B.: Functional Algorithms, Verified! (2021). https://functional-algorithms-verified.org

  19. Pujet, L., Tabareau, N.: Observational equality: now for good. Proc. ACM Program. Lang. (2022). https://doi.org/10.1145/3498693

    Article  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Xavier Leroy.

Ethics declarations

Conflict of interest

There are no conflicts of interest.

Code availability

Code is available at https://github.com/xavierleroy/canonical-binary-tries/tree/v2.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Appel, A.W., Leroy, X. Efficient Extensional Binary Tries. J Autom Reasoning 67, 8 (2023). https://doi.org/10.1007/s10817-022-09655-x

Download citation

  • Received:

  • Accepted:

  • Published:

  • DOI: https://doi.org/10.1007/s10817-022-09655-x

Keywords

Navigation