Skip to main content

Reification by Parametricity

Fast Setup for Proof by Reflection, in Two Lines of Ltac

  • Conference paper
  • First Online:
Book cover Interactive Theorem Proving (ITP 2018)

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 10895))

Included in the following conference series:

Abstract

We present a new strategy for performing reification in Coq. That is, we show how to generate first-class abstract syntax trees from “native” terms of Coq’s logic, suitable as inputs to verified compilers or procedures in the proof-by-reflection style. Our new strategy, based on simple generalization of subterms as variables, is straightforward, short, and fast. In its pure form, it is only complete for constants and function applications, but “let” binders, eliminators, lambdas, and quantifiers can be accommodated through lightweight coding conventions or preprocessing.

We survey the existing methods of reification across multiple Coq metaprogramming facilities, describing various design choices and tricks that can be used to speed them up, as well as various limitations. We report benchmarking results for 18 variants, in addition to our own, finding that our own reification outperforms 16 of these methods in all cases, and one additional method in some cases; writing an OCaml plugin is the only method tested to be faster. Our method is the most concise of the strategies we considered, reifying terms using only two to four lines of Ltac—beyond lists of the identifiers to reify and their reified variants. Additionally, our strategy automatically provides error messages that are no less helpful than Coq’s own error messages.

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

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 79.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 99.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    Note that for the refine to be fast, we must issue something like Strategy -10 [denote] to tell Coq to unfold denote before Let_In.

  2. 2.

    https://github.com/mit-plv/reification-by-parametricity.

  3. 3.

    More realistically, we might have a function that represents big numbers using multiple words of a user-specified width. In this case, we may want to specialize the procedure to a couple of different bitwidths, then reifying the resulting partially reduced term.

  4. 4.

    We discovered this method in the process of needing to reify implementations of cryptographic primitives [6] for a couple hundred different choices of numeric parameters (e.g., prime modulus of arithmetic). A couple hundred is enough to beat the overhead.

  5. 5.

    The generalize tactic returns \(\forall \) rather than \(\lambda \), and it only works on types.

References

  1. Anand, A., Boulier, S., Tabareau, N., Sozeau, M.: Typed Template Coq. CoqPL 2018, January 2018. https://popl18.sigplan.org/event/coqpl-2018-typed-template-coq

  2. Boutin, S.: Using reflection to build efficient and certified decision procedures. In: Abadi, M., Ito, T. (eds.) TACS 1997. LNCS, vol. 1281, pp. 515–529. Springer, Heidelberg (1997). https://doi.org/10.1007/BFb0014565

    Chapter  Google Scholar 

  3. de Bruijn, N.G.: Lambda-calculus notation with nameless dummies: a tool for automatic formal manipulation with application to the Church-Rosser theorem. Indagationes Mathematicae (Proceedings) 34(5), 381–392 (1972). https://doi.org/10.1016/1385-7258(72)90034-0. http://www.sciencedirect.com/science/article/pii/1385725872900340

  4. Chlipala, A.: Parametric higher-order abstract syntax for mechanized semantics. In: Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, ICFP 2008, September 2008. http://adam.chlipala.net/papers/PhoasICFP08/

  5. Coq Development Team: The Coq Proof Assistant Reference Manual, chap. 10.3 Detailed examples of tactics (quote). INRIA, 8.7.1 edn. (2017). https://coq.inria.fr/distrib/V8.7.1/refman/tactic-examples.html#quote-examples

  6. Erbsen, A., Philipoom, J., Gross, J., Sloan, R., Chlipala, A.: Simple high-level code for cryptographic arithmetic - with proofs, without compromises. In: Proceedings of IEEE Symposium on Security & Privacy, May 2019

    Google Scholar 

  7. Gonthier, G., Mahboubi, A., Tassi, E.: A small scale reflection extension for the Coq system. Technical report, Inria Saclay Ile de France, November 2016. https://hal.inria.fr/inria-00258384/

  8. Gonthier, G., Ziliani, B., Nanevski, A., Dreyer, D.: How to make ad hoc proof automation less ad hoc. J. Funct. Programm. 23(4), 357–401 (2013). https://doi.org/10.1017/S0956796813000051. https://people.mpi-sws.org/~beta/lessadhoc/lessadhoc-extended.pdf

  9. Malecha, G., Chlipala, A., Braibant, T.: Compositional computational reflection. In: Proceedings of the 5th International Conference on Interactive Theorem Proving, ITP 2014 (2014). http://adam.chlipala.net/papers/MirrorShardITP14/

  10. Pédrot, P.M.: Fast REL lookup #6506, December 2017. https://github.com/coq/coq/pull/6506

  11. Pfenning, F., Elliot, C.: Higher-order abstract syntax. In: Proceedings of PLDI, pp. 199–208 (1988). https://www.cs.cmu.edu/~fp/papers/pldi88.pdf

  12. Sozeau, M., Oury, N.: First-class type classes. In: Mohamed, O.A., Muñoz, C., Tahar, S. (eds.) TPHOLs 2008. LNCS, vol. 5170, pp. 278–293. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-71067-7_23. https://www.irif.fr/~sozeau/research/publications/

Download references

Acknowledgments and Historical Notes

We would like to thank Hugo Herbelin for sharing the trick with type of to propagate universe constraints (https://github.com/coq/coq/issues/5996#issuecomment-338405694) as well as useful conversations on Coq’s bug tracker that allowed us to track down performance issues (https://github.com/coq/coq/issues/6252). We would like to thank Pierre-Marie Pédrot for conversations on Coq’s Gitter and his help in tracking down performance bottlenecks in earlier versions of our reification scripts and in Coq’s tactics. We would like to thank Beta Ziliani for his help in using Mtac2, as well as his invaluable guidance in figuring out how to use canonical structures to reify to PHOAS. We also thank John Wiegley for feedback on the paper.

For those interested in history, our method of reification by parametricity was inspired by the evm_compute tactic [9]. We first made use of pattern to allow vm_compute to replace cbv-with-an-explicit-blacklist when we discovered cbv was too slow and the blacklist too hard to maintain. We then noticed that in the sequence of doing abstraction; vm_compute; application; \(\beta \)-reduction; reification, we could move \(\beta \)-reduction to the end of the sequence if we fused reification with application, and thus reification by parametricity was born.

This work was supported in part by a Google Research Award and National Science Foundation grants CCF-1253229, CCF-1512611, and CCF-1521584.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jason Gross .

Editor information

Editors and Affiliations

1 Electronic supplementary material

Below is the link to the electronic supplementary material.

Supplementary material 1 (zip 39167 KB)

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Springer International Publishing AG, part of Springer Nature

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Gross, J., Erbsen, A., Chlipala, A. (2018). Reification by Parametricity. In: Avigad, J., Mahboubi, A. (eds) Interactive Theorem Proving. ITP 2018. Lecture Notes in Computer Science(), vol 10895. Springer, Cham. https://doi.org/10.1007/978-3-319-94821-8_17

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-94821-8_17

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-94820-1

  • Online ISBN: 978-3-319-94821-8

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics