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.
- A. Chlipala. Certified Programming with Dependent Types: A Pragmatic Introduction to the Coq Proof Assistant . MIT Press, 2013. Google ScholarDigital Library
- 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 ScholarDigital Library
- R. Durstenfeld. Algorithm 235: Random permutation . Commun. ACM, 7(7):420–, 1964. Google ScholarDigital Library
- C. Gibbard, B. Yorgey, et al. MonadRandom: Random-number generation monad. http://hackage.haskell.org/package/MonadRandom-0.4.2.3 , 2016.Google Scholar
- Haskell Libraries Team and R. Leshchinskiy. vector: Efficient arrays. http: //hackage.haskell.org/package/vector-0.11.0.0 , 2015.Google Scholar
- R. Hickey. The Clojure programming language. http://clojure.org , 2012.Google Scholar
- 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 ScholarDigital Library
- D. A. Huffman. A method for the construction of minimum-redundancy codes. Proceedings of the IRE, 40(9):1098–1101, 1952.Google ScholarCross Ref
- 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 ScholarDigital Library
- C. Okasaki. Purely Functional Data Structures. Cambridge University Press, New York, NY, USA, 1998. Google ScholarDigital Library
- B. O’Sullivan. Criterion: a Haskell microbenchmarking library. http://www. serpentine.com/criterion/ , 2014.Google Scholar
- M. H. Pałka. Testing an optimising compiler by generating random lambda terms. http://www.cse.chalmers.se/~palka/testingcompiler/ .Google Scholar
- 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 ScholarDigital Library
- 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 ScholarCross Ref
- 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 Scholar
- D. Steinitz and J. Cook. random-fu: Random number generation. http://hackage. haskell.org/package/random-fu-0.2.6.2 , 2015.Google Scholar
Index Terms
- Ode on a random urn (functional pearl)
Recommendations
Ode on a random urn (functional pearl)
Haskell 2017: Proceedings of the 10th ACM SIGPLAN International Symposium on HaskellWe 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 ...
ArbitCheck: A Highly Automated Property-Based Testing Tool for Java
ICSTW '14: Proceedings of the 2014 IEEE International Conference on Software Testing, Verification, and Validation WorkshopsLightweight property-based testing tools are becoming popular these days. With property-based testing, developers can test properties of the system under test against large varieties of randomly generated inputs without writing test cases. Despite the ...
Comments