Skip to main content

Program Extraction for Mutable Arrays

  • Conference paper
  • First Online:

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

Abstract

We present a mutable array programming library for the Coq proof assistant which enables simple reasoning method based on Ssreflect/Mathematical Components, and extractions of the efficient OCaml programs using in-place updates. To refine the performance of extracted programs, we improved the extraction plugin of Coq. The improvements are based on trivial transformations for purely functional programs and reduce the construction and destruction costs of (co)inductive objects, and function call costs effectively. As a concrete application for our library and the improved extraction plugin, we provide efficient implementations, proofs, and benchmarks of two algorithms: the union–find data structure and the quicksort algorithm.

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

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.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

Learn about institutional subscriptions

Notes

  1. 1.

    In OCaml programs, arguments of constructors are parenthesized and comma separated. If a constructor is replaced with some function by the command, arguments of the constructor are interpreted as tuples.

  2. 2.

    The specification language of Coq.

  3. 3.

    is the canonical instance of nat.

  4. 4.

    expressions are syntax sugar for match expressions in Coq.

  5. 5.

    Implementing it as a part of the simplification of MiniML terms is difficult, because MiniML is a type-free language.

  6. 6.

    It is extracted by disabling new optimization mechanisms described in Sect. 4, but compiled with same OCaml compiler and optimization flags.

  7. 7.

    Here we assume that is a total order and means “less than or equal to” in some sense.

References

  1. Brady, E.: Programming and reasoning with algebraic effects and dependent types. In: ICFP 2013, pp. 133–144. ACM (2013)

    Google Scholar 

  2. Bulwahn, L., Krauss, A., Haftmann, F., Erkök, L., Matthews, J.: Imperative functional programming with Isabelle/HOL. In: Mohamed, O.A., Muñoz, C., Tahar, S. (eds.) TPHOLs 2008. LNCS, vol. 5170, pp. 134–149. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-71067-7_14

    Chapter  Google Scholar 

  3. Chlipala, A., Malecha, G., Morrisett, G., Shinnar, A., Wisnesky, R.: Effective interactive proofs for higher-order imperative programs. In: ICFP 2009, pp. 79–90. ACM (2009)

    Google Scholar 

  4. Garillot, F., Gonthier, G., Mahboubi, A., Rideau, L.: Packaging mathematical structures. In: Berghofer, S., Nipkow, T., Urban, C., Wenzel, M. (eds.) TPHOLs 2009. LNCS, vol. 5674, pp. 327–342. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-03359-9_23

    Chapter  Google Scholar 

  5. Launchbury, J., Peyton Jones, S.L.: Lazy functional state threads. In: PLDI 1994, pp. 24–35. ACM (1994)

    Google Scholar 

  6. Leroy, X.: A formally verified compiler back-end. J. Autom. Reason. 43(4), 363–446 (2009)

    Article  MathSciNet  Google Scholar 

  7. Letouzey, P.: A new extraction for Coq. In: Geuvers, H., Wiedijk, F. (eds.) TYPES 2002. LNCS, vol. 2646, pp. 200–219. Springer, Heidelberg (2003). https://doi.org/10.1007/3-540-39185-1_12

    Chapter  MATH  Google Scholar 

  8. Letouzey, P.: Programmation fonctionnelle certifiée - L’extraction de programmes dans l’assistant Coq. Ph.D. thesis, Université Paris-Sud (2004)

    Google Scholar 

  9. Letouzey, P.: Extraction in Coq: an overview. In: Beckmann, A., Dimitracopoulos, C., Löwe, B. (eds.) CiE 2008. LNCS, vol. 5028, pp. 359–369. Springer, Heidelberg (2008). https://doi.org/10.1007/978-3-540-69407-6_39

    Chapter  Google Scholar 

  10. Mahboubi, A., Tassi, E.: Canonical structures for the working Coq user. In: Blazy, S., Paulin-Mohring, C., Pichardie, D. (eds.) ITP 2013. LNCS, vol. 7998, pp. 19–34. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-39634-2_5

    Chapter  Google Scholar 

  11. Mahboubi, A., Tassi, E.: Mathematical components (2016). https://math-comp.github.io/mcb/book.pdf

  12. Nanevski, A., Morrisett, G., Birkedal, L.: Hoare type theory, polymorphism and separation. J. Funct. Prog 18(5–6), 865–911 (2008)

    Article  MathSciNet  Google Scholar 

  13. Nanevski, A., Morrisett, G., Shinnar, A., Govereau, P., Birkedal, L.: Ynot: dependent types for imperative programs. In: ICFP 2008, pp. 229–240. ACM (2008)

    Article  Google Scholar 

  14. O’Hearn, P., Reynolds, J., Yang, H.: Local reasoning about programs that alter data structures. In: Fribourg, L. (ed.) CSL 2001. LNCS, vol. 2142, pp. 1–19. Springer, Heidelberg (2001). https://doi.org/10.1007/3-540-44802-0_1

    Chapter  Google Scholar 

  15. Paulin-Mohring, C.: Extracting \({F}_{\omega }\)’s programs from proofs in the Calculus of Constructions. In: POPL 1989, pp. 89–104. ACM (1989)

    Google Scholar 

  16. Sakaguchi, K., Kameyama, Y.: Efficient finite-domain function library for the Coq proof assistant. IPSJ Trans. Prog. 10(1), 14–28 (2017)

    Google Scholar 

  17. Swamy, N., Hriţcu, C., Keller, C., Rastogi, A., Delignat-Lavaud, A., Forest, S., Bhargavan, K., Fournet, C., Strub, P.Y., Kohlweiss, M., Zinzindohoue, J.K., Zanella-Béguelin, S.: Dependent types and multi-monadic effects in F\(^\star \). In: POPL 2016, pp. 256–270. ACM (2016)

    Google Scholar 

  18. Tarjan, R.E.: Efficiency of a good but not linear set union algorithm. J. ACM 22(2), 215–225 (1975)

    Article  MathSciNet  Google Scholar 

  19. Tarjan, R.E., van Leeuwen, J.: Worst-case analysis of set union algorithms. J. ACM 31(2), 245–281 (1984)

    Article  MathSciNet  Google Scholar 

  20. The Coq Development Team: The Coq Proof Assistant Reference Manual (2017). https://coq.inria.fr/distrib/V8.7.0/refman/

  21. The Mathematical Components Project: The mathematical components repository. https://github.com/math-comp/math-comp

  22. Wadler, P.: Monads for functional programming. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 24–52. Springer, Heidelberg (1995). https://doi.org/10.1007/3-540-59451-5_2

    Chapter  Google Scholar 

Download references

Acknowledgments

We thank Yukiyoshi Kameyama and anonymous referees for valuable comments on an earlier version of this paper. This work was supported by JSPS KAKENHI Grant Number 17J01683.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Kazuhiko Sakaguchi .

Editor information

Editors and Affiliations

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

Sakaguchi, K. (2018). Program Extraction for Mutable Arrays. In: Gallagher, J., Sulzmann, M. (eds) Functional and Logic Programming. FLOPS 2018. Lecture Notes in Computer Science(), vol 10818. Springer, Cham. https://doi.org/10.1007/978-3-319-90686-7_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-90686-7_4

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-90685-0

  • Online ISBN: 978-3-319-90686-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics