A follow-up exploration of computing posterior distributions for RPG dice rolls conditioned on unlikely survival scenarios. The author builds a performant Python DSL using numpy that avoids brute-force Monte Carlo inefficiency through three key techniques: a backward liveness pass to eliminate unnecessary state and prevent combinatorial explosion, lazy generators for future state, and auto-batching of numpy operations across many states simultaneously. The DSL operates over a general semiring, enabling exact rational arithmetic via the Chinese Remainder Theorem without bignum libraries. The approach is validated against RPG Stack Exchange questions and connects to provenance semirings from database theory. GPU targeting was explored but numpy proved competitive with PyTorch on the author's Mac.
Table of contents
Biased posteriors the hard wayBiased posteriors an easier wayAuto batchingLet's work in a general semiringNot just PythonSort: