This branch is a clean-room experiment in reducing arithmetic coding to the smallest probability interface we currently need.
The crate has three public concepts:
RankedPrefix: ordered conditional probabilities stored asu8 / 256;BigDyadic: exact arbitrary-precision dyadic boundaries; andCoder: a deliberately path-relativelocate/zoominterface.
For bytes x[i], define
p[i] = x[i] / 256
S(0) = 1
S(i + 1) = S(i) * (1 - p[i])
The explicit event at rank i has probability S(i) * p[i]. A finite prefix
of length N has one implicit tail event with probability S(N).
Stored probabilities are in [0, 1), not (0, 1]:
0is useful because an explicit event may be impossible;1is forbidden because it would make all following ranked events dead; and- certainty is represented structurally by truncating the prefix and selecting its implicit tail event.
Every finite tail therefore remains strictly positive by construction.
Every categorical boundary is already the tail event of a prefix. If
S(i) = product_{k < i} (1 - p[k])
then any contiguous interval is
P(i <= X < j) = S(i) - S(j).
Nothing after j can influence that interval. Consequently a coder zoom is
fully described by two prefixes:
denied = p[..i]
accepted = p[i..j]
with interval boundaries
lower = 1 - tail(denied)
upper = 1 - tail(denied) * tail(accepted).
For one stored byte x,
1 - p = (256 - x) / 256.
The implementation removes powers of two from each factor, then multiplies up
to eight remaining odd factors in a u64. This is safe because
255^8 < 2^64. Chunk products are merged through an online balanced BigUint
multiplication tree.
This structure is intentionally friendly to future SIMD work: the public semantics are exact and scalar, while the hot small-factor reduction can be replaced independently.
All exact boundaries are dyadic. BigDyadic stores the numerator as a fixed
bit string whose length encodes the denominator exponent:
bits = b0 b1 ... bk
value = integer(bits) / 2^k
There is no separately stored precision field. The type is intentionally a single owning bit-slice handle and asserts that its value representation is two machine words.
Coder intentionally guarantees only exact-path determinism.
Changing, merging, splitting, nesting, or otherwise reparameterizing a model is not promised to preserve coder state or output, even if the transformed model has mathematically equivalent aggregate probabilities. This prevents optimized implementations from accidentally acquiring a compositionality contract they cannot safely keep.
cargo bench --bench tail_probabilityThe Criterion suite measures exact tail computation across zero, maximum, half, and patterned inputs from tiny prefixes through 50k entries.