Abstract
Distributions on integers are ubiquitous in probabilistic modeling but remain challenging for many of today’s probabilistic programming languages (PPLs). The core challenge comes from discrete structure: many of today’s PPL inference strategies rely on enumeration, sampling, or differentiation in order to scale, which fail for high-dimensional complex discrete distributions involving integers. Our insight is that there is structure in arithmetic that these approaches are not using. We present a binary encoding strategy for discrete distributions that exploits the rich logical structure of integer operations like summation and comparison. We leverage this structured encoding with knowledge compilation to perform exact probabilistic inference, and show that this approach scales to much larger integer distributions with arithmetic.
Introduction
Probabilistic programming allows developers to write code describing complex models with inherent uncertainty. However, random integers are a notorious bottleneck for inference. Most current PPLs handle integers in ways that lead to significant performance issues. Sampling methods like MCMC struggle with "hard" constraints, such as observing that the sum of two large random integers must equal a specific constant. Conversely, exact enumeration methods often use "one-hot" encoding, which treats an integer range of $N$ as $N$ separate possibilities. This leads to an exponential state space explosion during arithmetic operations like a + b.
The fundamental gap is the lack of a representation that exploits the logical structure of arithmetic. This paper introduces a binary encoding strategy that brings hardware-style efficiency—using bitwise logic and carry bits—to probabilistic inference.
Methodology: Bitwise Encoding and BDDs
The core of the proposed approach is representing integer distributions as joint distributions over binary bits.
Bitwise Encoding
Instead of a flat vector of probabilities, the authors use a divide-and-conquer algorithm to construct a distribution. For a multi-bit integer, the first "flip" determines the most significant bit, effectively deciding which half of the range the value falls into, with subsequent flips refining the value. This BITWISE_INT representation preserves the inherent structure of integers.
Knowledge Compilation
These probabilistic programs are compiled into Binary Decision Diagrams (BDDs). BDDs are compact data structures that represent Boolean functions by identifying and merging redundant paths. Because integers are represented as bit-vectors, operations like a < b or a + b can be implemented as standard logical circuits. BDDs automatically exploit conditional independence; for example, a comparison can often be decided by the most significant bits alone, allowing the inference engine to prune large sections of the search space.
Evaluation and Results
The authors evaluated their implementation, Dice.jl, against several benchmarks, including synthetic arithmetic and the Luhn algorithm used for credit card checksums.
As shown in the scaling tests for the Luhn algorithm, Dice.jl handles 10+ digits in seconds, while traditional exact PPLs like WebPPL and Psi fail or scale exponentially beyond 4-5 digits.
For synthetic arithmetic operations, the binary approach scales linearly or near-linearly with bit-width (up to 15 bits), whereas native one-hot methods typically time out after just 6-8 bits. The results indicate that binary encoding often turns hour-long timeouts into sub-second executions.
Conclusion
By leveraging binary encoding and knowledge compilation, this work enables exact probabilistic inference for complex integer arithmetic at scales previously unreachable. While challenges remain for operations with less logical structure, such as the modulo operator, this approach provides a powerful new tool for discrete probabilistic modeling and Bayesian learning.
Summary updated