code wiki / _hdl_build / nx_evo_cf.nx

nx_evo_cf.nx

buildroot/runtime/_hdl_build/nx_evo_cf.nx

11503 B209 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic evo
docsdependenciesstructsconstsfunctions

about

nx_evo_cf.nx -- EVOLUTIONARY SYNTHESIS rung: CONTROL-FLOW GENOMES under example fitness (X-AUT-006O) -- discover ALGORITHMS (piecewise functions), not just polynomials, from examples. 006N (nx_evo_pbe) discovered POLYNOMIAL f(x) from examples but its op set cannot express a piecewise function like abs/relu (a kink is not polynomial). This rung gives the genome GENERAL control-flow primitives -- a linear-GP register machine with PREDICATED execution: NEGATE (0-acc), SUB-X, a SIGN-PREDICATE (skip the NEXT instruction when acc>=0, i.e. the next instr runs IFF acc<0), and NOP. None is target-specific; the search must COMPOSE [predicate, negate] to get abs, etc. Evolved under the 006N example-based fitness + HELD-OUT generalization check. nx_evo_cf <champion_basename> <target_id> <seed> target: 0=abs 1=relu 2=x*x op set: 0 +n,1 *n,2 -n,3 +x,4 *x,5 ^2,6 negate,7 PREDICATE(skip next if acc>=0), 8 nop,9 -x. train on x in {-3,-2,-1,1,2,3}; held-out {-5,-4,4,5}. -> champion materialized with REAL control flow: op7+next emits `if acc<0 { next }`. no-false-green: abs/relu need the conditional -> a polynomial genome can at best OVERFIT the training points and FAIL held-out (caught); the GENERALIZING (4/4) solution is the control-flow one, and the champion COMPILES+RUNS with a real if-branch. Sovereign, no gcc/.sh. HONEST: predicated linear-GP (one forward sign-predicate), integer fitness; loops-from-examples (gcd/fib) are the next rung. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_evo_cf.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main cf_p sys_write cf_atoi sys_mmap cf_randfill cf_rand cf_fit cf_trainx cf_abs cf_eval cf_target cf_abs ↻ cf_tourney cf_rand ↻ cf_rand ↻ cf_heldx cf_eval ↻ cf_target ↻ cf_pn sys_mmap ↻ cf_catn cf_catn ↻ sys_mmap ↻ sys_write ↻ cf_cat cf_catn ↻ cf_emit_op cf_cat ↻ cf_catn ↻ sys_openat_wr sys_write ↻ sys_close

structs

none

consts

25const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757
26const EVO_MAGIC_3037000493: i64 = 3037000493
27const EVO_MAGIC_2654435761: i64 = 2654435761
28const EVO_MAGIC_12345: i64 = 12345
29const EVO_MAGIC_1000000000: i64 = 1000000000
30const EVO_MAGIC_65536: i64 = 65536
32const EVO_L: i64 = 6
33const EVO_P: i64 = 256
34const EVO_G: i64 = 1200
35const EVO_T: i64 = 5
36const NTRAIN: i64 = 6
37const NHELD: i64 = 4

functions

39func cf_rand(state: *i64) -> i64 { state[0] = state[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (state[0] >> 17) & 0x3fffffff }
40func cf_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x }
called by 2: cf_targetcf_fit
41func cf_trainx(i: i64) -> i64 { if i == 0 { return 0 - 3 } if i == 1 { return 0 - 2 } if i == 2 { return 0 - 1 } if i == 3 { return 1 } if i == 4 { return 2 } return 3 }
called by 1: cf_fit
42func cf_heldx(i: i64) -> i64 { if i == 0 { return 0 - 5 } if i == 1 { return 0 - 4 } if i == 2 { return 4 } return 5 }
called by 1: main
43func cf_target(id: i64, x: i64) -> i64
called by 2: cf_fitmain calls 1: cf_abs
50func cf_eval(pop: *i64, base: i64, x: i64) -> i64
called by 2: cf_fitmain
72func cf_fit(pop: *i64, base: i64, id: i64) -> i64
77func cf_randfill(pop: *i64, base: i64, state: *i64) -> i64
called by 1: main calls 1: cf_rand
82func cf_tourney(fit: *i64, state: *i64) -> i64
called by 1: main calls 1: cf_rand
87func cf_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i }
called by 2: cf_emit_opmain
88func cf_catn(dst: *u8, off: i64, v: i64) -> i64
98func cf_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
99func cf_pn(v: i64) -> i64 { let b: *u8 = sys_mmap(32); let n: i64 = cf_catn(b, 0, v); sys_write(1, b, n); return 0 }
called by 1: main calls 3: sys_mmapcf_catnsys_write
100func cf_atoi(s: *u8) -> i64
called by 1: main
108func cf_emit_op(buf: *u8, off: i64, op: i64, n: i64, indent: *u8) -> i64
called by 1: main calls 2: cf_catcf_catn
124func main(argc: i64, argv: *i64) -> i64