code wiki / _hdl_build / nx_evo_gcd.nx

nx_evo_gcd.nx

buildroot/runtime/_hdl_build/nx_evo_gcd.nx

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

about

nx_evo_gcd.nx -- EVOLUTIONARY SYNTHESIS rung: 2-REGISTER CONDITIONAL-WHILE GENOMES (eve rung #1 -- the evo arc's own stated next step: "2-input (gcd)"). Discovers gcd's STRUCTURE (the Euclid step swap+mod under a while-nonzero loop) from (a,b)->gcd(a,b) examples + HELD-OUT, zero Claude composing the algorithm. The MACHINE is authored (Bar-C role: representation/eval/fitness/materialize); the SEARCH derives the body. 2 regs r0,r1 (init a,b); control = while r1!=0 (guard- capped); body = evolved ops over {0 r0%=r1, 1 r1%=r0, 2 swap, 3 r0-=r1, 4 r1-=r0, 5 nop}; out r0. gcd is reachable as body [swap, r1%=r0]. Champion materialized as a REAL 2-input while-loop organ run at a HELD-OUT pair (prints RESULT=<gcd>). no-false-green: a body that can't drive r1->0 hits the guard / a wrong op FAILS held-out; only the GENERALIZING (4/4) champion is the real Euclid. Sovereign, no gcc/.sh. HONEST: loop condition FIXED (while r1!=0); evolving the condition + >2 registers + nested loops are later rungs. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_evo_gcd.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 gd_atoi sys_mmap gd_randfill gd_rand gd_fit gd_eval gd_a gd_b gd_abs gd_g gd_tourney gd_rand ↻ gd_rand ↻ gd_eval ↻ gd_a ↻ gd_b ↻ gd_g ↻ gd_p sys_write gd_pn sys_mmap ↻ gd_catn gd_catn ↻ sys_mmap ↻ sys_write ↻ gd_cat gd_catn ↻ gd_emit_op gd_cat ↻ sys_openat_wr sys_write ↻ sys_close

structs

none

consts

15const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757
16const EVO_MAGIC_3037000493: i64 = 3037000493
17const EVO_MAGIC_2000000: i64 = 2000000
18const EVO_MAGIC_1000000: i64 = 1000000
19const EVO_MAGIC_2654435761: i64 = 2654435761
20const EVO_MAGIC_12345: i64 = 12345
21const EVO_MAGIC_1000000000: i64 = 1000000000
22const EVO_MAGIC_65536: i64 = 65536
24const EVO_BODY: i64 = 4
25const EVO_P: i64 = 256
26const EVO_G: i64 = 1500
27const EVO_T: i64 = 5
28const NTRAIN: i64 = 6
29const NHELD: i64 = 4
30const GCD_CAP: i64 = 256

functions

32func gd_rand(state: *i64) -> i64 { state[0] = state[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (state[0] >> 17) & 0x3fffffff }
33func gd_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x }
called by 1: gd_fit
36func gd_a(i: i64) -> i64 { if i == 0 { return 12 } if i == 1 { return 15 } if i == 2 { return 7 } if i == 3 { return 100 } if i == 4 { return 9 } if i == 5 { return 14 } if i == 6 { return 48 } if i == 7 { return 17 } if i == 8 { return 81 } return 1000 }
called by 2: gd_fitmain
37func gd_b(i: i64) -> i64 { if i == 0 { return 8 } if i == 1 { return 5 } if i == 2 { return 3 } if i == 3 { return 60 } if i == 4 { return 6 } if i == 5 { return 21 } if i == 6 { return 36 } if i == 7 { return 5 } if i == 8 { return 27 } return 625 }
called by 2: gd_fitmain
38func gd_g(i: i64) -> i64 { if i == 0 { return 4 } if i == 1 { return 5 } if i == 2 { return 1 } if i == 3 { return 20 } if i == 4 { return 3 } if i == 5 { return 7 } if i == 6 { return 12 } if i == 7 { return 1 } if i == 8 { return 27 } return 125 }
called by 2: gd_fitmain
41func gd_eval(pop: *i64, base: i64, a: i64, b: i64) -> i64
called by 2: gd_fitmain
67func gd_fit(pop: *i64, base: i64) -> i64
called by 1: main calls 5: gd_evalgd_agd_bgd_absgd_g
80func gd_randfill(pop: *i64, base: i64, state: *i64) -> i64
called by 1: main calls 1: gd_rand
86func gd_tourney(fit: *i64, state: *i64) -> i64
called by 1: main calls 1: gd_rand
92func gd_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: gd_emit_opmain
93func gd_catn(dst: *u8, off: i64, v: i64) -> i64
called by 3: gd_catngd_pnmain calls 2: gd_catnsys_mmap
103func gd_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
104func gd_pn(v: i64) -> i64 { let b: *u8 = sys_mmap(32); let n: i64 = gd_catn(b, 0, v); sys_write(1, b, n); return 0 }
called by 1: main calls 3: sys_mmapgd_catnsys_write
105func gd_atoi(s: *u8) -> i64
called by 1: main
114func gd_emit_op(buf: *u8, off: i64, op: i64) -> i64
called by 1: main calls 1: gd_cat
124func main(argc: i64, argv: *i64) -> i64