code wiki / _hdl_build / nx_evo_loop.nx

nx_evo_loop.nx

buildroot/runtime/_hdl_build/nx_evo_loop.nx

10865 B194 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic evo
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_evo_loop.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 lp_p sys_write lp_atoi sys_mmap lp_randfill lp_rand lp_fit lp_trainx lp_abs lp_eval lp_target lp_tourney lp_rand ↻ lp_rand ↻ lp_heldx lp_eval ↻ lp_target ↻ lp_pn sys_mmap ↻ lp_catn lp_catn ↻ sys_mmap ↻ sys_write ↻ lp_cat lp_catn ↻ lp_emit_body_op lp_cat ↻ lp_catn ↻ sys_openat_wr sys_write ↻ sys_close

structs

none

consts

21const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757
22const EVO_MAGIC_3037000493: i64 = 3037000493
23const EVO_MAGIC_2654435761: i64 = 2654435761
24const EVO_MAGIC_12345: i64 = 12345
25const EVO_MAGIC_1000000000: i64 = 1000000000
26const EVO_MAGIC_65536: i64 = 65536
28const EVO_BODY: i64 = 3
29const EVO_P: i64 = 256
30const EVO_G: i64 = 1500
31const EVO_T: i64 = 5
32const NTRAIN: i64 = 6
33const NHELD: i64 = 4
34const LOOP_CAP: i64 = 64 // runaway guard (examples use x<=10)

functions

36func lp_rand(state: *i64) -> i64 { state[0] = state[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (state[0] >> 17) & 0x3fffffff }
37func lp_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x }
called by 1: lp_fit
38func lp_trainx(i: i64) -> i64 { return i + 1 } // n = 1..6
called by 1: lp_fit
39func lp_heldx(i: i64) -> i64 { return NTRAIN + 1 + i } // n = 7..10
called by 1: main
40func lp_target(id: i64, n: i64) -> i64
called by 2: lp_fitmain
47func lp_eval(pop: *i64, base: i64, x: i64) -> i64
called by 2: lp_fitmain
71func lp_fit(pop: *i64, base: i64, id: i64) -> i64
76func lp_randfill(pop: *i64, base: i64, state: *i64) -> i64
called by 1: main calls 1: lp_rand
82func lp_tourney(fit: *i64, state: *i64) -> i64
called by 1: main calls 1: lp_rand
87func 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 }
called by 2: lp_emit_body_opmain
88func lp_catn(dst: *u8, off: i64, v: i64) -> i64
98func 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 }
called by 1: main calls 1: sys_write
99func 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 }
called by 1: main calls 3: sys_mmaplp_catnsys_write
100func lp_atoi(s: *u8) -> i64
called by 1: main
107func lp_emit_body_op(buf: *u8, off: i64, op: i64, n: i64) -> i64
called by 1: main calls 2: lp_catlp_catn
121func main(argc: i64, argv: *i64) -> i64