XbTm (X-base Target Mapping) is a tool and DSL for generating canonical, entropy-efficient mappings from an x-way random source to an m-way target choice.
xbtm is a DSL for deterministically exploring and visualizing ways to emulate a uniform random generator with target outcomes using one with base outcomes.
DSL format
A complete program combines a header and a body with a colon.
X{base}T{target}:{body}
base and target are natural numbers. When target is at least 2, base must also be at least 2. When target is 1, base may be 1 because there is no outcome to choose between.
Every body starts at the ordinary state 1.
X2T5:1>2>4>8=5|3>6=5|(1)
States and termination
n: An ordinary, newly visited staten, written as a natural number.(n): A reference state that returns to the previously visited staten. A reference state terminates the body.!: A termination marker indicating that the current ordinary state exactly equalstarget. The implementation represents it as an operator token for convenience.
Thus, a body starts at an ordinary state, repeats transitions, and ends with either a reference state or !.
Transitions
There are two kinds of transition.
Expand: >
old_state>next_state
expand multiplies the current state by base.
next_state = old_state * base
Split: =
old_state=pxq|r
old_state=p|r # when q == 1
split divides the current state using target.
p = target
q = old_state // target
r = old_state % target
old_state = p * q + r
Here, p and q describe the split, and r is the next state. When q is 1, x1 is omitted. If the next state r was already visited, it is written as (r) and the body ends.
When the split has no remainder, it ends with |! instead of creating state 0.
old_state=pxq|!
For the full DSL rules, see the DSL specification.
Installation
pip install xbtm
Python usage
from xbtm import Program, generate
program = generate(2, 5)
print(program.text)
print(program.get_trials())
same_program = Program.parse("X2T5:1>2>4>8=5|3>6=5|(1)")
Examples
X2T8:1>2>4>8!
X7T8:1>7>49=8x6|(1)
X1T1:1!
X4T2:1>4=2x2|!
Metadata
Release files for xbtm 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xbtm-0.1.0.tar.gz | 44.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xbtm-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.7 kB
Release files / xbtm-0.1.0.tar.gz
| Download URL | xbtm-0.1.0.tar.gz |
|---|---|
| Size | 44.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7bb8ee882b7e99775ed5c67f1da704075ad2fa095d7463909b46b72a3c73e45d
|
|
BLAKE2b-256 checksum How to use checksums |
fe9649e140108dd94787f111e955d1f3082a7fb4773f0bce9df36bbb7c53a1f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / xbtm-0.1.0-py3-none-any.whl
| Download URL | xbtm-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b9459fcdab7f1544ba8cdc714e75ceeac27e70560374efcd67e7f6a917a50ea
|
|
BLAKE2b-256 checksum How to use checksums |
0ce8c0769663783a94c343b6feaacab2153ab6e6db89bc26fdbe7eb9c5493e01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|