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.
Project description
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|!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xbtm-0.1.0.tar.gz.
File metadata
- Download URL: xbtm-0.1.0.tar.gz
- Upload date:
- Size: 44.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bb8ee882b7e99775ed5c67f1da704075ad2fa095d7463909b46b72a3c73e45d
|
|
| MD5 |
c441ddd20a2cba5fa0f127547090933d
|
|
| BLAKE2b-256 |
fe9649e140108dd94787f111e955d1f3082a7fb4773f0bce9df36bbb7c53a1f8
|
File details
Details for the file xbtm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xbtm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b9459fcdab7f1544ba8cdc714e75ceeac27e70560374efcd67e7f6a917a50ea
|
|
| MD5 |
83ed4c91db7ed978ca990c1428d0bfa8
|
|
| BLAKE2b-256 |
0ce8c0769663783a94c343b6feaacab2153ab6e6db89bc26fdbe7eb9c5493e01
|