~/bend-docscommunity

main.bend checks

raw source on the hub · import mlbend-generative@0.1.0.0/main.bend as Main

mlbend-generative: the generative skeleton, natively in Bend 2.

import mlbend-generative@0.1.0.0/main.bend as G

What a generative model needs besides the network: randomness that a verifier can draw again, a noise schedule, and a time embedding. The randomness is a pure function of counters — murmur3's fmix32 finaliser over (step salt · φ, index), Box-Muller over uniforms on a 24-bit grid — so a NumPy twin draws the same numbers bit for bit. The schedule is the cosine one (Nichol & Dhariwal): ᾱ_t = f(t)/f(0) in closed form, so every entry is computed on its own and the table needs no running product.

What is proved: the shape — the noise of any counter is exactly m numbers (noise_length), a schedule over t steps is exactly t (alphas_length), an embedding of k rungs is exactly 2k (temb_length). The builders recurse on the count left, the current index riding after it, and the law's variables are ordered the same way — the structural variable before the riding one — which is what lets the checker follow the induction (NOTES.md, 2026-10-25). What is tested: every F32 number, against the NumPy twin (reference/test_generative.py), and the bijection of mix32: the inverse is closed form (the half-width xor-shift is an involution, the 13-shift inverts by the triple xor, the multiplies by their modular inverses mod 2^32) and generative/tests/ok.bend checks it on a grid — a law would need bit-level equational reasoning the kernel has not been asked to do, so the bijection is the debt of issue #10, not a claim.

1 import
import Base

Laws

law noise_length provedsource · line 98 · raw

@+s:Nat -> @+m:Nat -> @+from:Nat -> {List.length(&2, F32, noise_from(s, m, from)) == m : Nat}

LAW 1 (noise_length): m numbers asked for are m numbers built.

law alphas_length provedsource · line 149 · raw

@+t:Nat -> @+left:Nat -> @+from:Nat -> {List.length(&2, F32, alphas_from(t, left, from)) == left : Nat}

LAW 2 (alphas_length): a schedule of t entries is t entries.

law lin_alphas_length provedsource · line 194 · raw

@+t:Nat -> @+left:Nat -> @+from:Nat -> @+acc:F32 -> {List.length(&2, F32, lin_alphas_from(t, left, from, acc)) == left : Nat}

LAW 4 (lin_alphas_length): a linear schedule of t entries is t entries.

law temb_length provedsource · line 245 · raw

@+t:Nat -> @+steps:Nat -> @+k:Nat -> @+p:Nat -> {List.length(&2, F32, temb_from(t, steps, k, p)) == Nat.mul(k, 2n) : Nat}

LAW 3 (temb_length): an embedding of k rungs is 2k numbers.

Definitions

def mix32 source · line 33 · raw

@+z:U32 -> U32

murmur3's fmix32 finaliser, over U32 arithmetic that wraps

def unxor13 source · line 41 · raw

@+y:U32 -> U32

the 13-shift undone: xor the shifted value twice more

def mix32_inv source · line 48 · raw

@+z:U32 -> U32

the inverse of mix32, in closed form: the 16-shift is an involution on 32 bits; the 13-shift inverts by the triple xor; the multiplies invert by their modular inverses mod 2^32

def hash_of source · line 57 · raw

@+s:Nat -> @+i:Nat -> U32

the hash of one counter: the step salt times the golden ratio, the index added beside it

def uniform source · line 63 · raw

@+s:Nat -> @+i:Nat -> F32

a uniform in (0, 1]: the low 24 bits of the hash plus one, exactly representable, so log(u) is never log(0)

def gauss_body source · line 70 · raw

@is_even:Bool -> @+r:F32 -> @+ang:F32 -> F32

one Gaussian of a counter, by parity: the even index of the pair brings the radius, the odd one the angle

def gauss_at source · line 77 · raw

@+s:Nat -> @+j:Nat -> F32

def noise_from source · line 86 · raw

@+s:Nat -> @+left:Nat -> @+from:Nat -> List<&2, F32>

The noise of counter s, left numbers from index from on. The count left is the recursion; the index rides after it.

def noise_of source · line 94 · raw

@+s:Nat -> @+m:Nat -> List<&2, F32>

the noise of counter s: m numbers, the index 0 first

def cos_f source · line 120 · raw

@+t:Nat -> @+steps:Nat -> F32

def alpha_at source · line 126 · raw

@+t:Nat -> @+steps:Nat -> F32

ᾱ_t of the cosine schedule over steps steps (t = 1 .. steps)

def beta_at source · line 132 · raw

@+t:Nat -> @+steps:Nat -> F32

β_t, the ratio the reverse step removes: 1 - ᾱ_t/ᾱ_{t-1}, clamped at 0.99 — the cosine schedule's last ratio is 1 in F32 (ᾱ_T ~ 1e-15), and the reverse step's 1/sqrt(1-β) would amplify any prediction error

def alphas_from source · line 137 · raw

@+steps:Nat -> @+left:Nat -> @+from:Nat -> List<&2, F32>

The schedule from step from on, left entries. The count left is the recursion; the step rides after it.

def alphas source · line 145 · raw

@+steps:Nat -> List<&2, F32>

ᾱ_1 .. ᾱ_steps, in order

def lin_beta_at source · line 175 · raw

@+t:Nat -> @+steps:Nat -> F32

β_t of the linear schedule over steps steps (t = 1 .. steps)

def lin_alphas_from source · line 181 · raw

@+steps:Nat -> @+left:Nat -> @+from:Nat -> @+acc:F32 -> List<&2, F32>

The schedule ᾱ_1 .. from from on, left entries, the running product riding beside. The count left is the recursion; the step and the product ride after it.

def lin_alphas source · line 190 · raw

@+steps:Nat -> List<&2, F32>

ᾱ_1 .. ᾱ_steps of the linear schedule, in order

def freq_of source · line 216 · raw

@+p:Nat -> F32

the frequency of rung p: a decade ladder 0.001 .. 1.0

def temb_from source · line 230 · raw

@+t:Nat -> @+steps:Nat -> @+left:Nat -> @+p:Nat -> List<&2, F32>

The embedding of step t over steps, from rung p on, left rungs — each rung a sine and a cosine. The rungs left are the recursion; the rung index rides after them.

def temb_of source · line 241 · raw

@+t:Nat -> @+steps:Nat -> @+k:Nat -> List<&2, F32>

the embedding of step t: k rungs, the lowest frequency first