Skip to main content

A Machine-Checked Proof of the Average-Case Complexity of Quicksort in Coq

  • Conference paper
Types for Proofs and Programs (TYPES 2008)

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

Included in the following conference series:

Abstract

As a case-study in machine-checked reasoning about the complexity of algorithms in type theory, we describe a proof of the average-case complexity of Quicksort in Coq. The proof attempts to follow a textbook development, at the heart of which lies a technical lemma about the behaviour of the algorithm for which the original proof only gives an intuitive justification.

We introduce a general framework for algorithmic complexity in type theory, combining some existing and novel techniques: algorithms are given a shallow embedding as monadically expressed functional programs; we introduce a variety of operation-counting monads to capture worst- and average-case complexity of deterministic and nondeterministic programs, including the generalization to count in an arbitrary monoid; and we give a small theory of expectation for such non-deterministic computations, featuring both general map-fusion like results, and specific counting arguments for computing bounds.

Our formalization of the average-case complexity of Quicksort includes a fully formal treatment of the ‘tricky’ textbook lemma, exploiting the generality of our monadic framework to support a key step in the proof, where the expected comparison count is translated into the expected length of a recorded list of all comparisons.

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

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Hoare, C.: Quicksort. The Computer Journal 5, 10–15 (1962)

    Article  MathSciNet  MATH  Google Scholar 

  2. The Coq Development Team: The Coq Proof Assistant Reference Manual – Version V8.2 (February 2009), http://coq.inria.fr

  3. Bertot, Y., Castéran, P.: Coq’Art: Interactive Theorem Proving and Program Development. Texts in Theoretical Computer Science. Springer, Heidelberg (2004)

    Book  MATH  Google Scholar 

  4. Constable, R.L.: Expressing computational complexity in constructive type theory. In: Leivant, D. (ed.) LCC 1994. LNCS, vol. 960, pp. 131–144. Springer, Heidelberg (1995)

    Chapter  Google Scholar 

  5. Wadler, P.: Monads for functional programming. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 24–52. Springer, Heidelberg (1995)

    Chapter  Google Scholar 

  6. Sedgewick, R.: The analysis of quicksort programs. Acta Inf. 7, 327–355 (1977)

    Article  MathSciNet  MATH  Google Scholar 

  7. Sozeau, M.: Subset coercions in Coq. In: Altenkirch, T., McBride, C. (eds.) TYPES 2006. LNCS, vol. 4502, pp. 237–252. Springer, Heidelberg (2007)

    Chapter  Google Scholar 

  8. Liang, S., Hudak, P., Jones, M.P.: Monad transformers and modular interpreters. In: POPL 1995, pp. 333–343. ACM, New York (1995)

    Google Scholar 

  9. Cormen, T., Leiserson, C., Rivest, R., Stein, C.: Introduction to Algorithms, 2nd edn. MIT Press, Cambridge (2001)

    MATH  Google Scholar 

  10. Schellekens, M.: A Modular Calculus for the Average Cost of Data Structuring. Springer, Heidelberg (2008)

    Book  Google Scholar 

  11. Audebaud, P., Paulin-Mohring, C.: Proofs of Randomized Algorithms in Coq. In: Uustalu, T. (ed.) MPC 2006. LNCS, vol. 4014, pp. 49–68. Springer, Heidelberg (2006)

    Chapter  Google Scholar 

  12. Hurd, J.: Formal Verification of Probabilistic Algorithms. PhD thesis, University of Cambridge (2002)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2009 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

van der Weegen, E., McKinna, J. (2009). A Machine-Checked Proof of the Average-Case Complexity of Quicksort in Coq. In: Berardi, S., Damiani, F., de’Liguoro, U. (eds) Types for Proofs and Programs. TYPES 2008. Lecture Notes in Computer Science, vol 5497. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-02444-3_16

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-02444-3_16

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-02443-6

  • Online ISBN: 978-3-642-02444-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics