Sitting in a coffee bar in Cambridge it seems like a good moment to push out a first rough version of my probabilistic DSL that's good enough to answer actual questions on the RPG stack exchange.

github.com/dpiponi/dice-nine

I know it can do this because I pulled down 50 examples from the stack exchange and used them as my tests - this being the version that finally runs all 50 successfully.

colab.research.google.com/driv

There's not a lot that's original about the code but it performs well compared to similar tools (eg. anydice) despite being 100% Python.

One thing that may be of interest - using Python generators allows you to support a degree of laziness which is really powerful. If you want exact computations for discrete distributions you need to be able to explore the entire probability space which means you want to "materialise" the smallest amount of state you can get away with. For example, `lazy_sum(1000 @ d(6))` sums the rolls of 1000 dice but `1000 @ d(6)` is a lazy sequence and so only ever materialises one die roll at a time and in the worst case it has thousands of states to manage rather than 6^1000.

Also fun was using Wang's rational reconstruction algorithm to implement fast parallel (in the sense of numpy) high precision rational arithmetic without having to leave Python. (Bit rough around the edges, currently the onus is on the user to detect overflows.)

en.wikipedia.org/wiki/Rational

0

If you have a fediverse account, you can quote this note from your own instance. Search https://mathstodon.xyz/users/dpiponi/statuses/115360321735964253 on your instance and quote it. (Note that quoting is not supported in Mastodon.)