code wiki / _hdl_build / nx_nofloat_grammar_gate.nx

nx_nofloat_grammar_gate.nx

buildroot/runtime/_hdl_build/nx_nofloat_grammar_gate.nx

9303 B150 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_grammar_gate.nx -- CAP-NF-GRAMMAR: the AFFORDABLE "landing" step the sovereign researcher identified (knowledge/research/2026-06-23-nofloat-affordable-land-roadmap.md, R1, grounded in TinyStories arXiv 2305.07759 + Textbooks arXiv 2306.11644: a tiny model is COHERENT iff the DOMAIN is constrained). Instead of memorizing one fixed sentence, the model learns a small GRAMMAR and GENERATES coherent NOVEL sentences. Grammar: a stream of [ARTICLE, NOUN, VERB] triples. Vocab 8: articles {the=0,a=1}, nouns {cat=2,dog=3,bird=4}, verbs {ran=5,sat=6,ate=7}. EVERY training stream is fresh-random members -> the model cannot memorize sentences; it must learn the CATEGORY GRAMMAR (article->noun->verb->article ...). T1 GENERATES coherent grammar: from a seed, free argmax-decode produces a stream whose every token is in the grammatically-correct category for its position (>= 90%, vs ~33% chance) = coherent NOVEL generation. T2 learned the grammar on HELD-OUT streams: teacher-forced next-token category accuracy >= 90% (>> chance). Pure integer Q16, attention-only block, 3 clm_fwd sites in separate helpers (nx_cc-lean). Sovereign. HONEST: a CONSTRAINED grammar domain (the affordable landing per the research), not open prose. expect_exit: 0

dependencies 3 imports · 0 importers

nx_nofloat_autograd.nx nx_syscalls.nx nx_gate_emit_lib.nx nx_nofloat_grammar_gate.nx

imports: nx_nofloat_autograd.nxnx_syscalls.nxnx_gate_emit_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write sys_mmap dini do_train make_stream lcg clm_fwd nfa_leaf nfa_new nfa_embed nfa_new ↻ nfa_rmsnorm_rows nfa_new ↻ nfa_qmul nfa_isqrt nfa_matmul nfa_new ↻ nfa_rope nfa_new ↻ nfa_fxexp nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul ↻ nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_qmul ↻ nfa_matmul_nt nfa_new ↻ nfa_cmul nfa_new ↻ nfa_qmul ↻ nfa_softmax_rows nfa_new ↻ nfa_fxexp ↻ nfa_vadd

structs

none

consts

16const Q16: i64 = 65536

functions

19func dini(a: *i64, n: i64, sd: i64) -> i64 { var i: i64=0; while i<n { a[i]=(((i*7+sd*13+1)%11)-5)*13107; i=i+1 } return 0 }
called by 1: main
20func lcg(st: *i64) -> i64 { st[0]=(st[0]*1103515245 + 12345) & 2147483647; return (st[0] >> 15) }
called by 1: make_stream
21func cat_of(tok: i64) -> i64 { if tok<2 { return 0 } if tok<5 { return 1 } return 2 }
23func make_stream(S: *i64, tgt: *i64, P: i64, st: *i64) -> i64
called by 2: do_traineval_tf calls 1: lcg
31func clm_fwd(tape: *i64, vals: *i64, st: *i64, W: *i64, ids: *i64, tgt: *i64, T: i64, dm: i64, V: i64, scale: i64, leaves: *i64) -> i64
59func step_all(tape: *i64, grads: *i64, W: *i64, WN: *i64, leaves: *i64, nW: i64, lr: i64, clip: i64, gb: *i64) -> i64
called by 1: do_train calls 2: nfa_gradnfa_sgd
64func amx(tape: *i64, vals: *i64, logn: i64, r: i64, V: i64) -> i64 { let o: i64=tape[7*logn+5]; var b: i64=0; var bv: i64=vals[o+r*V]; var j: i64=1; while j<V { if vals[o+r*V+j]>bv { bv=vals[o+r*V+j]; b=j } j=j+1 } return b }
called by 2: eval_tfgen_coherent
66func do_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, W: *i64, WN: *i64, S: *i64, tgt: *i64, P: i64, dm: i64, V: i64, scale: i64, leaves: *i64, gb: *i64, steps: i64, sdat: *i64) -> i64
72func eval_tf(tape: *i64, vals: *i64, st: *i64, W: *i64, S: *i64, tgt: *i64, P: i64, dm: i64, V: i64, scale: i64, leaves: *i64, N: i64, sdat: *i64, totp: *i64) -> i64
called by 1: main calls 4: make_streamclm_fwdcat_ofamx
85func gen_coherent(tape: *i64, vals: *i64, st: *i64, W: *i64, gen: *i64, P: i64, dm: i64, V: i64, scale: i64, leaves: *i64, outtok: *i64) -> i64
called by 1: main calls 3: clm_fwdamxcat_of
100func main() -> i64