skip to main content
article
Public Access

Ode on a random urn (functional pearl)

Published:07 September 2017Publication History
Skip Abstract Section

Abstract

We present the urn, a simple tree-based data structure that supports sampling from and updating discrete probability distributions in logarithmic time. We avoid the usual complexity of traditional self-balancing binary search trees by not keeping values in a specific order. Instead, we keep the tree maximally balanced at all times using a single machine word of overhead: its size.

Urns provide an alternative interface for the frequency combinator from the QuickCheck library that allows for asymptotically more efficient sampling from dynamically-updated distributions. They also facilitate backtracking in property-based random testing, and can be applied to such complex examples from the literature as generating well-typed lambda terms or information flow machine states, demonstrating significant speedups.

References

  1. A. Chlipala. Certified Programming with Dependent Types: A Pragmatic Introduction to the Coq Proof Assistant . MIT Press, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. K. Claessen and J. Hughes. QuickCheck: a lightweight tool for random testing of Haskell programs . In 5th ACM SIGPLAN International Conference on Functional Programming (ICFP). 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. R. Durstenfeld. Algorithm 235: Random permutation . Commun. ACM, 7(7):420–, 1964. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. C. Gibbard, B. Yorgey, et al. MonadRandom: Random-number generation monad. http://hackage.haskell.org/package/MonadRandom-0.4.2.3 , 2016.Google ScholarGoogle Scholar
  5. Haskell Libraries Team and R. Leshchinskiy. vector: Efficient arrays. http: //hackage.haskell.org/package/vector-0.11.0.0 , 2015.Google ScholarGoogle Scholar
  6. R. Hickey. The Clojure programming language. http://clojure.org , 2012.Google ScholarGoogle Scholar
  7. C. Hriţcu, J. Hughes, B. C. Pierce, A. Spector-Zabusky, D. Vytiniotis, A. Azevedo de Amorim, and L. Lampropoulos. Testing noninterference, quickly . In 18th ACM SIGPLAN International Conference on Functional Programming (ICFP). 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. D. A. Huffman. A method for the construction of minimum-redundancy codes. Proceedings of the IRE, 40(9):1098–1101, 1952.Google ScholarGoogle ScholarCross RefCross Ref
  9. L. Lampropoulos, D. Gallois-Wong, C. Hritcu, J. Hughes, B. C. Pierce, and L. Xia. Beginner’s Luck: a language for property-based generators . In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18-20, 2017, 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. C. Okasaki. Purely Functional Data Structures. Cambridge University Press, New York, NY, USA, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. B. O’Sullivan. Criterion: a Haskell microbenchmarking library. http://www. serpentine.com/criterion/ , 2014.Google ScholarGoogle Scholar
  12. M. H. Pałka. Testing an optimising compiler by generating random lambda terms. http://www.cse.chalmers.se/~palka/testingcompiler/ .Google ScholarGoogle Scholar
  13. M. H. Pałka, K. Claessen, A. Russo, and J. Hughes. Testing an optimising compiler by generating random lambda terms . In Proceedings of the 6th International Workshop on Automation of Software Test. 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Z. Paraskevopoulou, C. Hriţcu, M. Dénès, L. Lampropoulos, and B. C. Pierce. Foundational property-based testing . In C. Urban and X. Zhang, editors, 6th International Conference on Interactive Theorem Proving (ITP). 2015.Google ScholarGoogle ScholarCross RefCross Ref
  15. QuickCheck developers, N. Smallbone, B. Bringert, and K. Claessen. QuickCheck: Automatic testing of Haskell programs. http://hackage.haskell.org/package/ QuickCheck-2.8.2 , 2016.Google ScholarGoogle Scholar
  16. D. Steinitz and J. Cook. random-fu: Random number generation. http://hackage. haskell.org/package/random-fu-0.2.6.2 , 2015.Google ScholarGoogle Scholar

Index Terms

  1. Ode on a random urn (functional pearl)

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 52, Issue 10
      Haskell '17
      October 2017
      211 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/3156695
      • Editor:
      • Andy Gill
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell 2017: Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell
        September 2017
        211 pages
        ISBN:9781450351829
        DOI:10.1145/3122955

      Copyright © 2017 ACM

      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 7 September 2017

      Check for updates

      Qualifiers

      • article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader