code wiki / _hdl_build / nx_evo_loop.nx
nx_evo_loop.nx
buildroot/runtime/_hdl_build/nx_evo_loop.nx
about
nx_evo_loop.nx -- EVOLUTIONARY SYNTHESIS rung: LOOP GENOMES from examples
(X-AUT-006P) -- discover ITERATIVE algorithms (factorial, 2^n, sum) from data.
006O evolved BRANCHES (abs/relu). This evolves LOOPS: the genome = an evolved
acc INIT + a loop BODY that runs `for i in 1..x` (x = the input), the body ops
referencing the counter i, the input x, and constants -- so the search can
discover ITERATIVE algorithms that are not closed-form polynomials (factorial,
2^n). A runaway GUARD caps iterations. Evolved under example fitness + held-out.
nx_evo_loop <champion_basename> <target_id> <seed> target: 0=n! 1=sum 2=2^n
genome = INIT gene + EVO_BODY body ops; body op: 0 acc+i,1 acc*i,2 acc+x,
3 acc+n,4 acc*n,5 acc-i,6 nop. train n=1..6, held-out n=7..10.
-> champion materialized as a REAL `var acc=INIT; var i=1; while i<=x { body; i+=1 }`.
no-false-green: factorial/2^n are non-polynomial -> need the loop; champion
verified on HELD-OUT (n the search never trained on) + compiles+runs the loop.
Sovereign, no gcc/.sh. HONEST: one fixed `for i=1..x` loop, small body, integer
fitness; nested/while-with-condition loops + 2-input (gcd) are later rungs.
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
| 21 | const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757 |
| 22 | const EVO_MAGIC_3037000493: i64 = 3037000493 |
| 23 | const EVO_MAGIC_2654435761: i64 = 2654435761 |
| 24 | const EVO_MAGIC_12345: i64 = 12345 |
| 25 | const EVO_MAGIC_1000000000: i64 = 1000000000 |
| 26 | const EVO_MAGIC_65536: i64 = 65536 |
| 28 | const EVO_BODY: i64 = 3 |
| 29 | const EVO_P: i64 = 256 |
| 30 | const EVO_G: i64 = 1500 |
| 31 | const EVO_T: i64 = 5 |
| 32 | const NTRAIN: i64 = 6 |
| 33 | const NHELD: i64 = 4 |
| 34 | const LOOP_CAP: i64 = 64 // runaway guard (examples use x<=10) |
functions
| 36 | func lp_rand(state: *i64) -> i64 { state[0] = state[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (state[0] >> 17) & 0x3fffffff } |
| 37 | func lp_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } called by 1: lp_fit |
| 38 | func lp_trainx(i: i64) -> i64 { return i + 1 } // n = 1..6 called by 1: lp_fit |
| 39 | func lp_heldx(i: i64) -> i64 { return NTRAIN + 1 + i } // n = 7..10 called by 1: main |
| 40 | func lp_target(id: i64, n: i64) -> i64 |
| 47 | func lp_eval(pop: *i64, base: i64, x: i64) -> i64 |
| 71 | func lp_fit(pop: *i64, base: i64, id: i64) -> i64 |
| 76 | func lp_randfill(pop: *i64, base: i64, state: *i64) -> i64 |
| 82 | func lp_tourney(fit: *i64, state: *i64) -> i64 |
| 87 | func lp_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 lp_catn(dst: *u8, off: i64, v: i64) -> i64 |
| 98 | func lp_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 lp_pn(v: i64) -> i64 { let b: *u8 = sys_mmap(32); let n: i64 = lp_catn(b, 0, v); sys_write(1, b, n); return 0 } |
| 100 | func lp_atoi(s: *u8) -> i64 called by 1: main |
| 107 | func lp_emit_body_op(buf: *u8, off: i64, op: i64, n: i64) -> i64 |
| 121 | func main(argc: i64, argv: *i64) -> i64 |