code wiki / _hdl_build / nx_evo_cf.nx
nx_evo_cf.nx
buildroot/runtime/_hdl_build/nx_evo_cf.nx
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
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
structs
| none |
consts
| 25 | const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757 |
| 26 | const EVO_MAGIC_3037000493: i64 = 3037000493 |
| 27 | const EVO_MAGIC_2654435761: i64 = 2654435761 |
| 28 | const EVO_MAGIC_12345: i64 = 12345 |
| 29 | const EVO_MAGIC_1000000000: i64 = 1000000000 |
| 30 | const EVO_MAGIC_65536: i64 = 65536 |
| 32 | const EVO_L: i64 = 6 |
| 33 | const EVO_P: i64 = 256 |
| 34 | const EVO_G: i64 = 1200 |
| 35 | const EVO_T: i64 = 5 |
| 36 | const NTRAIN: i64 = 6 |
| 37 | const NHELD: i64 = 4 |
functions
| 39 | func cf_rand(state: *i64) -> i64 { state[0] = state[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (state[0] >> 17) & 0x3fffffff } |
| 40 | func cf_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } |
| 41 | func 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 |
| 42 | func 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 |
| 43 | func cf_target(id: i64, x: i64) -> i64 |
| 50 | func cf_eval(pop: *i64, base: i64, x: i64) -> i64 |
| 72 | func cf_fit(pop: *i64, base: i64, id: i64) -> i64 |
| 77 | func cf_randfill(pop: *i64, base: i64, state: *i64) -> i64 |
| 82 | func cf_tourney(fit: *i64, state: *i64) -> i64 |
| 87 | func 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 } |
| 88 | func cf_catn(dst: *u8, off: i64, v: i64) -> i64 |
| 98 | func 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 } |
| 99 | func 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 } |
| 100 | func cf_atoi(s: *u8) -> i64 called by 1: main |
| 108 | func cf_emit_op(buf: *u8, off: i64, op: i64, n: i64, indent: *u8) -> i64 |
| 124 | func main(argc: i64, argv: *i64) -> i64 |