code wiki / _hdl_build / nx_evo_lcm.nx
nx_evo_lcm.nx
buildroot/runtime/_hdl_build/nx_evo_lcm.nx
about
nx_evo_lcm.nx -- COMPOUNDING derivation toward self-sufficiency ("adam+eve making kids,
their kids making kids"): derive lcm by COMPOSING the already-DERIVED gcd (a prior kid)
as a primitive. lcm(a,b) = a*b / gcd(a,b). The op-set gives the search the inputs a,b,
multiply, and a DIV-by-gcd op that calls gcd_evolved -- the structure the SEARCH derived
earlier (nx_evo_gcd, body [1 3 0 2]), inlined verbatim. So the derived gcd (KID) becomes
the building block for deriving lcm (GRANDKID) -- the lineage growing on itself, not a
one-off. Self-verifies the derived lcm vs true lcm across a grid. I author the MACHINE
(substrate); the SEARCH composes lcm; full self-sufficiency (team authors the machine +
an unattended loop) is the horizon this steps toward. license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.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
| 12 | const LCM_MAGIC_2862933555777941757: i64 = 2862933555777941757 |
| 13 | const LCM_MAGIC_3037000493: i64 = 3037000493 |
| 14 | const LCM_MAGIC_2000000: i64 = 2000000 |
| 15 | const LCM_MAGIC_1000000: i64 = 1000000 |
| 16 | const LCM_MAGIC_2654435761: i64 = 2654435761 |
| 17 | const LCM_MAGIC_12345: i64 = 12345 |
| 18 | const LCM_MAGIC_1000000000: i64 = 1000000000 |
| 20 | const LCM_LEN: i64 = 4 |
| 21 | const EVO_P: i64 = 256 |
| 22 | const EVO_G: i64 = 2000 |
| 23 | const EVO_T: i64 = 5 |
| 24 | const NTRAIN: i64 = 6 |
| 25 | const NHELD: i64 = 4 |
functions
| 27 | func lm_rand(state: *i64) -> i64 { state[0] = state[0] * LCM_MAGIC_2862933555777941757 + LCM_MAGIC_3037000493; return (state[0] >> 17) & 0x3fffffff } |
| 28 | func lm_abs(x: i64) -> i64 { if x < 0 { return 0 - x } return x } called by 1: lcm_fit |
| 31 | func gcd_evolved(a: i64, b: i64) -> i64 called by 1: lcm_eval |
| 45 | func lm_euclid(a: i64, b: i64) -> i64 { var x: i64 = a; var y: i64 = b; while y != 0 { let t: i64 = x % y; x = y; y = t } return x } called by 1: lcm_true |
| 46 | func lcm_true(a: i64, b: i64) -> i64 { let g: i64 = lm_euclid(a, b); if g == 0 { return 0 } return (a * b) / g } |
| 49 | func lm_a(i: i64) -> i64 { if i == 0 { return 6 } if i == 1 { return 4 } if i == 2 { return 3 } if i == 3 { return 8 } if i == 4 { return 9 } if i == 5 { return 10 } if i == 6 { return 7 } if i == 7 { return 12 } if i == 8 { return 5 } return 14 } |
| 50 | func lm_b(i: i64) -> i64 { if i == 0 { return 4 } if i == 1 { return 6 } if i == 2 { return 5 } if i == 3 { return 12 } if i == 4 { return 6 } if i == 5 { return 15 } if i == 6 { return 3 } if i == 7 { return 8 } if i == 8 { return 10 } return 21 } |
| 53 | func lcm_eval(pop: *i64, base: i64, a: i64, b: i64) -> i64 |
| 67 | func lcm_fit(pop: *i64, base: i64) -> i64 |
| 80 | func lm_randfill(pop: *i64, base: i64, state: *i64) -> i64 { var j: i64 = 0; while j < LCM_LEN { pop[base + j] = lm_rand(state) % 6; j = j + 1 } return 0 } |
| 81 | func lm_tourney(fit: *i64, state: *i64) -> i64 |
| 86 | func lm_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 91 | func lm_pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 93 | func main() -> i64 |