Skip to main content

Equational Reasoning with Applicative Functors

  • Conference paper
  • First Online:
Interactive Theorem Proving (ITP 2016)

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

Included in the following conference series:

Abstract

In reasoning about effectful computations, it often suffices to focus on the effect-free parts. We present a package for automatically lifting equations to effects modelled by applicative functors. It exploits properties of the concrete functor thanks to a modular classification based on combinators. We formalise the meta theory and demonstrate the usability of our Isabelle/HOL package with two case studies. This is a first step towards practical reasoning with effectful computations.

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 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

Institutional subscriptions

Notes

  1. 1.

    As lifting wraps the types of free variables in F, it does not look into abstractions, but treats them like constants. For example, is lifted to rather than . Thus, lifting effectively operates on first-order terms.

  2. 2.

    Hinze briefly considers functors with the combinators S and C and notes that the case with only the combinator C might be interesting, too, but omits the details.

  3. 3.

    The following shows the equivalence (bold face denotes doubling and underlining dropping of a repetition): .

References

  1. Berghofer, S.: Proofs, Programs and Executable Specifications in Higher Order Logic. Ph.D. thesis, Institut für Informatik, Technische Universität München (2003)

    Google Scholar 

  2. Berstel, J., Reutenauer, C.: Square-free words and idempotent semigroups. In: Lothaire, M. (ed.) Combinatorics on Words, 2nd edn., pp. 18–38. Cambridge University Press (1997)

    Google Scholar 

  3. 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)

    Google Scholar 

  4. 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)

    Chapter  Google Scholar 

  5. Bunder, M.W.: Lambda terms definable as combinators. Theoret. Comput. Sci. 169(1), 3–21 (1996)

    Article  MathSciNet  MATH  Google Scholar 

  6. Church, A.: The Calculi of Lambda-Conversion. Princeton University Press, Princeton (1941)

    MATH  Google Scholar 

  7. Dijkstra, E.W.: An exercise for Dr. R.M. Burstall. In: Selected Writings on Computing: A Personal Perspective. Texts and Monographs in Computer Science, pp. 215–216. Springer, New York (1982)

    Google Scholar 

  8. Eberl, M., Hölzl, J., Nipkow, T.: A verified compiler for probability density functions. In: Vitek, J. (ed.) ESOP 2015. LNCS, vol. 9032, pp. 80–104. Springer, Heidelberg (2015)

    Chapter  Google Scholar 

  9. Gammie, P., Lochbihler, A.: The Stern-Brocot tree. Archive of Formal Proofs, (2015). http://isa-afp.org/entries/Stern_Brocot.shtml, Formal proof development

  10. Gibbons, J., Bird, R.: Be kind, rewind: a modest proposal about traversal (2012). http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/backwards.pdf

  11. Gibbons, J., Hinze, R.: Just do it: simple monadic equational reasoning. In: ICFP 2011, pp. 2–14. ACM (2011)

    Google Scholar 

  12. Graham, R.L., Knuth, D.E., Patashnik, O.: Concrete Mathematics-A Foundation for Computer Science, 2nd edn. Addison-Wesley, Reading (1994)

    Google Scholar 

  13. Green, J.A., Rees, D.: On semi-groups in which \(x^r = x\). Math. Proc. Camb. Philos. Soc. 48, 35–40 (1952)

    Article  MathSciNet  MATH  Google Scholar 

  14. Hinze, R.: The Bird tree. J. Func. Programm. 19(5), 491–508 (2009)

    Article  MathSciNet  MATH  Google Scholar 

  15. Hinze, R.: Lifting operators and laws (2010). http://www.cs.ox.ac.uk/ralf.hinze/Lifting.pdf

  16. Homeier, P.V.: The HOL-omega logic. In: Berghofer, S., Nipkow, T., Urban, C., Wenzel, M. (eds.) TPHOLs 2009. LNCS, vol. 5674, pp. 244–259. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  17. Huffman, B.: Transfer principle proof tactic for nonstandard analysis. In: Kanovich, M., White, G., Gottliebsen, H., Oliva, P. (eds.) NetCA 2005, pp. 18–26. Queen Mary, University of London, Dept. of Computer Science, Research report RR-05-06 (2005)

    Google Scholar 

  18. Huffman, B., Kunčar, O.: Lifting and Transfer: a modular design for quotients in Isabelle/HOL. In: Gonthier, G., Norrish, M. (eds.) CPP 2013. LNCS, vol. 8307, pp. 131–146. Springer, Heidelberg (2013)

    Chapter  Google Scholar 

  19. Hutton, G., Fulger, D.: Reasoning about effects: seeing the wood through the trees. In: Trends in Functional Programming (TFP 2008) (2008)

    Google Scholar 

  20. Krebbers, R.: The C standard formalized in Coq. Ph.D. thesis, Radboud University (2015)

    Google Scholar 

  21. Lammich, P., Tuerk, T.: Applying data refinement for monadic programs to Hopcroft’s algorithm. In: Beringer, L., Felty, A. (eds.) ITP 2012. LNCS, vol. 7406, pp. 166–182. Springer, Heidelberg (2012)

    Chapter  Google Scholar 

  22. Lochbihler, A.: Probabilistic functions and cryptographic oracles in higher order logic. In: Thiemann, P. (ed.) ESOP 2016. LNCS, vol. 9632, pp. 503–531. Springer, Heidelberg (2016)

    Chapter  Google Scholar 

  23. Lochbihler, A., Schneider, J.: Applicative lifting. Archive of Formal Proofs (2015). http://isa-afp.org/entries/Applicative_Lifting.shtml

  24. Marlow, S., Peyton Jones, S., Kmett, E., Mokhov, A.: Desugaring Haskell’s do-notation into applicative operations (2016). http://research.microsoft.com/en-us/um/people/simonpj/papers/list-comp/applicativedo.pdf

  25. McBride, C., Paterson, R.: Applicative programming with effects. J. Funct. Program. 18(1), 1–13 (2008)

    Article  MATH  Google Scholar 

  26. Nipkow, T.: More Church-Rosser proofs (in Isabelle/HOL). J. Automat. Reason. 26, 51–66 (2001)

    Article  MathSciNet  MATH  Google Scholar 

  27. Paulson, L.: A higher-order implementation of rewriting. Sci. Comput. Program 3(2), 119–149 (1983)

    Article  MathSciNet  MATH  Google Scholar 

  28. Reynolds, J.C.: Types, abstraction and parametric polymorphism. In: IFIP 1983. Information Processing, vol. 83, pp. 513–523. North-Holland/IFIP (1983)

    Google Scholar 

  29. Schropp, A., Popescu, A.: Nonfree datatypes in Isabelle/HOL. In: Gonthier, G., Norrish, M. (eds.) CPP 2013. LNCS, vol. 8307, pp. 114–130. Springer, Heidelberg (2013)

    Chapter  Google Scholar 

  30. Tuong, F., Wolff, B.: A meta-model for the Isabelle API. Archive of Formal Proofs (2015). http://isa-afp.org/entries/Isabelle_Meta_Model.shtml

Download references

Acknowledgements

Peter Gammie triggered our interest in reasoning about applicative functors and helped with the Stern-Brocot tree. We thank Dmitriy Traytel, Joachim Breitner, and the anonymous reviewers for suggesting many textual improvements. The first author was supported by SNSF grant 153217 “Formalising Computational Soundness for Protocol Implementations”.

Author information

Authors and Affiliations

Authors

Corresponding authors

Correspondence to Andreas Lochbihler or Joshua Schneider .

Editor information

Editors and Affiliations

A Definitions of Applicative Functors

A Definitions of Applicative Functors

This appendix lists Isabelle/HOL definitions for the idioms mentioned in this paper. The definitional packages and their syntaxes are documented in the Isabelle/Isar reference manual. The proofs of the applicative laws and combinators are available online [23].

Environment (Reader)

figure h

Stream

figure i

Infinite binary tree

figure j

Non-standard numbers as used in non-standard analysis in Isabelle/HOL [17]. The type \(\alpha \) star is the quotient of the environment idiom (\(\alpha \), nat) env over equality in some free ultrafilter \(\mathcal {U}\) on nat.

figure k

Option

figure l

Zip list

figure m

Probability

figure n

Subprobability

figure o

Set

figure p

Non-empty set

figure q

Monoid, commutative monoid, idempotent monoid

figure r

The type variable \(\alpha \) must have sort monoid-add. If \(\alpha \) has sort comm-monoid-add, then monoid-ap has C. If \(\alpha \) has sort idemp-monoid-add, then monoid-ap has W.

Either

figure s

Distinct non-empty list. The function remdups removes duplicates from a list by retaining only the last occurrence of each element.

figure t

State

figure u

List

figure v

Parser. The function apfst applies a function to the first component of a tuple.

figure w

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing Switzerland

About this paper

Cite this paper

Lochbihler, A., Schneider, J. (2016). Equational Reasoning with Applicative Functors. In: Blanchette, J., Merz, S. (eds) Interactive Theorem Proving. ITP 2016. Lecture Notes in Computer Science(), vol 9807. Springer, Cham. https://doi.org/10.1007/978-3-319-43144-4_16

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-43144-4_16

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-43143-7

  • Online ISBN: 978-3-319-43144-4

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics