code wiki / _hdl_build / nx_evo_gcd.nx
nx_evo_gcd.nx
buildroot/runtime/_hdl_build/nx_evo_gcd.nx
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
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
| 15 | const EVO_MAGIC_2862933555777941757: i64 = 2862933555777941757 |
| 16 | const EVO_MAGIC_3037000493: i64 = 3037000493 |
| 17 | const EVO_MAGIC_2000000: i64 = 2000000 |
| 18 | const EVO_MAGIC_1000000: i64 = 1000000 |
| 19 | const EVO_MAGIC_2654435761: i64 = 2654435761 |
| 20 | const EVO_MAGIC_12345: i64 = 12345 |
| 21 | const EVO_MAGIC_1000000000: i64 = 1000000000 |
| 22 | const EVO_MAGIC_65536: i64 = 65536 |
| 24 | const EVO_BODY: i64 = 4 |
| 25 | const EVO_P: i64 = 256 |
| 26 | const EVO_G: i64 = 1500 |
| 27 | const EVO_T: i64 = 5 |
| 28 | const NTRAIN: i64 = 6 |
| 29 | const NHELD: i64 = 4 |
| 30 | const GCD_CAP: i64 = 256 |
functions
| 32 | func gd_rand(state: *i64) -> i64 { state[0] = state[0] * EVO_MAGIC_2862933555777941757 + EVO_MAGIC_3037000493; return (state[0] >> 17) & 0x3fffffff } |
| 33 | func gd_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } called by 1: gd_fit |
| 36 | func 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 } |
| 37 | func 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 } |
| 38 | func 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 } |
| 41 | func gd_eval(pop: *i64, base: i64, a: i64, b: i64) -> i64 |
| 67 | func gd_fit(pop: *i64, base: i64) -> i64 |
| 80 | func gd_randfill(pop: *i64, base: i64, state: *i64) -> i64 |
| 86 | func gd_tourney(fit: *i64, state: *i64) -> i64 |
| 92 | func 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 } |
| 93 | func gd_catn(dst: *u8, off: i64, v: i64) -> i64 |
| 103 | func 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 } |
| 104 | func 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 } |
| 105 | func gd_atoi(s: *u8) -> i64 called by 1: main |
| 114 | func gd_emit_op(buf: *u8, off: i64, op: i64) -> i64 |
| 124 | func main(argc: i64, argv: *i64) -> i64 |