Runtime() and survive
JSON transport. They supply reproducible random choices and exact monetary
arithmetic for the primitive corpus.
They do not require a market-specific callback.
Draws name their source of randomness
seeded_integer(seed, low, high, scope=..., key=...) returns an integer in
[low, high). Bounds must be integers, excluding booleans, with positive width
at most 2**256. Negative bounds are allowed. Sampling rejects the incomplete
remainder of the hash range before taking a modulus, avoiding modulo bias.
seeded_order(ids, seed=..., scope=..., key=...) returns unique, nonempty text
IDs ordered by their hash priorities. Arrival order has no effect. Removing an
ID preserves the relative order of the remaining IDs. Empty input returns an
empty list; duplicate IDs fail. To break a price tie, apply this expression to
the IDs in that tie group, then look up each associated record. It does not
reorder records by price for you.
Seed, scope, key, and IDs are nonempty text. They can be literals or expressions
resolving to text. Their Unicode content is encoded exactly, without case folding
or normalization; unpaired surrogates fail. Convert numeric identifiers to a
stable textual convention before authoring the definition.
Each operator is stateless: repeating the same arguments repeats the same
result. There is no implicit random stream, draw counter, wall clock, or global
Python RNG. Draw order and unrelated calls cannot perturb a result. Name each
purpose with a distinct key. Include a period, participant, or attempt identity
in the scope/key when that identity should receive its own draw. Changing only
the bounds reuses the same candidate stream; it is not a new independent draw.
Different keys separate streams but can still return equal values by chance.
The scope argument is explicit; the interpreter does not automatically insert
the SQLite scope or an execution ID. The lottery example supplies its cohort
as a Machine constant. A reused definition that needs different draws per host
scope must bind a stable host context value or supply distinct scope constants.
An idempotent retry must use the original logical draw identity.
These expressions provide reproducibility, not secret or manipulation-resistant
randomness. Seeds and IDs in public definitions are predictable; participants who
can choose their IDs can search for favorable priorities. The example assumes
study-assigned stable IDs. A commitment/reveal protocol is separate design work.
Version-1 byte protocol
The capability namesexpression:seeded_integer@1 and
expression:seeded_order@1 pin the following algorithms. Machine language version
remains 1; a receiver must advertise the individual capabilities. There is no
version= expression option. A future algorithm requires a distinct advertised
capability and matching interpreter support; it must not redefine these results.
Define L(text) as its strict UTF-8 bytes, prefixed with their byte count as an
unsigned four-byte big-endian integer. Each component must contain fewer than
2**32 bytes, with smaller host resource quotas still enforced. Concatenate:
seeded_integer, start counter = 0. Hash
SHA256(P || uint64_big_endian(counter)) and interpret the 32 digest bytes as an
unsigned big-endian integer h. Let width = high - low and
cutoff = 2**256 - (2**256 % width). If h < cutoff, return
low + (h % width); otherwise increment the counter and try again. Exhausting
the 64-bit counter fails. Hashing and every rejected attempt consume the shared
execution budget, so pathological work fails atomically rather than hanging.
For seeded_order, compute SHA256(P || L(id)) for each ID. Sort ascending by
digest bytes, then by the ID’s UTF-8 bytes if digests collide. This second rule
makes even a hash collision deterministic. The operator names separate integer
draws from ordering priorities.
Known-answer vectors, independently checked in Python and Node:
Full 256-bit integer vectors and forced rejection/collision checks are in
test_machine_portable.py.
Keep monetary balances in integer units
decimal_units(text, places=..., rounding=...) scales exact decimal text by
10**places and rounds once to an integer. places is a literal integer from
0 through 18; rounding is a literal mode from the table below. Both options are
required and serialized. Input text follows [+-]?[0-9]+(\.[0-9]+)?:
"+001.005" is valid; floats, exponents, whitespace, .5, 1., NaN, and infinity
are rejected. Write "0.5" for one half. Negative zero becomes integer zero.
round_ratio(numerator, denominator, rounding=...) rounds an exact ratio of
integers. The denominator must be positive; booleans and floating-point operands
fail. Use multiplication and addition on integer units, then round_ratio at
the declared settlement boundary. Ordinary / remains floating-point division.
There is no implicit currency, scale conversion, decimal state type, or default
rounding policy.
Use
StateType.integer() for stored units and annotate the currency/scale in your
mechanism’s constants or documentation. When splitting a payment, round the
gross amount once, calculate the fee from that integer, and give the recipient
gross - fee. Separately rounding both recipients’ shares can create or lose
units. The settlement example debits exactly the sum it credits.
Integer arithmetic is exact within the host’s resource limits. Decimal parsing
and powers of ten have conservative integer-size checks before allocation;
very long fractional representations can fail even if their rounded result would
be small. Hash work, sorting, and decimal input processing share the operation
budget. Failure leaves committed state and event history unchanged. The random
sampler’s fixed 256-bit hash arithmetic is internal and independent of the
integer-size limit on user values. See
execution limits.
JSON receivers must preserve integer values exactly. For example, a JavaScript
receiver must use an exact-integer parser when values exceed its safe integer
range; parsing through Number first loses information. Decimal text remains
text on the wire. These guarantees do not make the existing floating-point
LMSR expressions exact.
