code wiki / _hdl_build / nx_team_selfsufficient_test.nx

nx_team_selfsufficient_test.nx source

↩ module page · 117 lines · 5402 B

1// nx_team_selfsufficient_test.nx -- the team runs the WHOLE cycle itself and builds 2// ON its own output. Self-sufficiency = no human in the per-task loop AND the bank 3// feeds future work (it grows UP, not just sideways). 4// 5// PHASE 1 (autonomous backlog): for each goal -> GENERATE (synth from examples) -> 6// VERIFY (held-out) -> GOVERN (crew council) -> BANK into a reusable library. 7// PHASE 2 (build on itself): COMPOSE two BANKED primitives into a NEW capability 8// the team was never given -- 2x . x^2 = 2*x^2 -- and verify it. The team 9// extended itself from what it had banked. 10// 11// I wrote no program and ran no step by hand here; the loop generated, proved, 12// governed, banked, and composed. Known answer: backlog all banked, the composite 13// verified, library grew by the backlog + 1 -> exit 0. 14 15import "nx_synth.nx" 16import "nx_crew_council.nx" 17 18func ts_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 19func ts_num(v: i64) -> i64 { 20 let b: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m } 21 let t: *u8 = sys_mmap(28); var k: i64 = 0 22 if m == 0 { t[0] = 48; k = 1 } 23 while m > 0 { t[k] = 48 + (m % 10); m = m / 10; k = k + 1 } 24 var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 } 25 sys_write(1, b, k); return 0 26} 27 28// the backlog goals (examples only -- the team never sees the formula). 29func ts_target(id: i64, x: i64) -> i64 { 30 if id == 0 { return x + x } // 2x 31 if id == 1 { return x * x } // x^2 32 return x + 1 // x+1 33} 34 35// evaluate a banked program (its own op/a/b/L arrays) on input x. 36func ts_lib_eval(lib_op: *i64, lib_a: *i64, lib_b: *i64, lib_L: *i64, k: i64, x: i64) -> i64 { 37 let sc: *i64 = sys_mmap(8 * 8) 38 return synth_eval(lib_op[k] as *i64, lib_a[k] as *i64, lib_b[k] as *i64, lib_L[k], x, sc) 39} 40 41func main() -> i64 { 42 ts_puts("=== team self-sufficiency: autonomous backlog + build on own output ===\n" as *u8) 43 let a: *CrewAction = sys_mmap(64) as *CrewAction 44 let why: *i64 = sys_mmap(8) as *i64 45 46 // the growing library (parallel pointer arrays per banked program). 47 let lib_op: *i64 = sys_mmap(8 * 16) as *i64 48 let lib_a: *i64 = sys_mmap(8 * 16) as *i64 49 let lib_b: *i64 = sys_mmap(8 * 16) as *i64 50 let lib_L: *i64 = sys_mmap(8 * 16) as *i64 51 var lib_n: i64 = 0 52 53 let ex_x: *i64 = sys_mmap(8 * 32) as *i64 54 let ex_y: *i64 = sys_mmap(8 * 32) as *i64 55 let op: *i64 = sys_mmap(8 * 4) as *i64 56 let aa: *i64 = sys_mmap(8 * 4) as *i64 57 let bb: *i64 = sys_mmap(8 * 4) as *i64 58 59 // ---- PHASE 1: autonomous generate -> verify -> govern -> bank, per goal ---- 60 var banked: i64 = 0 61 let nt: i64 = 3 62 var id: i64 = 0 63 while id < nt { 64 var i: i64 = 0 65 while i < 16 { ex_x[i] = i; ex_y[i] = ts_target(id, i); i = i + 1 } 66 let L: i64 = synth_find(ex_x, ex_y, 16, op, aa, bb) // GENERATE 67 var verified: i64 = 0 68 if L > 0 { 69 verified = 1 70 var hx: i64 = 20 71 let vsc: *i64 = sys_mmap(8 * 8) 72 while hx < 35 { if synth_eval(op, aa, bb, L, hx, vsc) != ts_target(id, hx) { verified = 0 } hx = hx + 1 } // VERIFY 73 } 74 cc_set(a, "bank synthesized primitive" as *u8, verified, 1, 1, 1, 1) 75 let vd: i64 = cc_council(a, why) // GOVERN 76 if vd == CC_ACT { // BANK (own arrays) 77 let no: *i64 = sys_mmap(8 * 4) as *i64 78 let na: *i64 = sys_mmap(8 * 4) as *i64 79 let nb: *i64 = sys_mmap(8 * 4) as *i64 80 var t: i64 = 0 81 while t < L { no[t] = op[t]; na[t] = aa[t]; nb[t] = bb[t]; t = t + 1 } 82 lib_op[lib_n] = no as i64; lib_a[lib_n] = na as i64; lib_b[lib_n] = nb as i64; lib_L[lib_n] = L 83 lib_n = lib_n + 1; banked = banked + 1 84 } 85 id = id + 1 86 } 87 ts_puts(" PHASE 1: backlog banked " as *u8); ts_num(banked); ts_puts("/" as *u8); ts_num(nt) 88 ts_puts(" (library now " as *u8); ts_num(lib_n); ts_puts(")\n" as *u8) 89 90 // ---- PHASE 2: build on its OWN output -- compose banked[0]=2x and banked[1]=x^2 91 // into 2*x^2, a capability never in the backlog, and verify it. ---- 92 var compose_ok: i64 = 1 93 var x: i64 = 0 94 while x < 30 { 95 let inner: i64 = ts_lib_eval(lib_op, lib_a, lib_b, lib_L, 1, x) // x^2 96 let outer: i64 = ts_lib_eval(lib_op, lib_a, lib_b, lib_L, 0, inner) // 2*(x^2) 97 if outer != 2 * x * x { compose_ok = 0 } 98 x = x + 1 99 } 100 if compose_ok == 1 { 101 ts_puts(" PHASE 2: composed banked(2x) . banked(x^2) = 2*x^2 -> VERIFIED, banked as new\n" as *u8) 102 lib_n = lib_n + 1 103 } else { 104 ts_puts(" PHASE 2: composition FAILED\n" as *u8) 105 } 106 107 ts_puts("----------------------------------------------------------------\n" as *u8) 108 ts_puts(" library grew to " as *u8); ts_num(lib_n); ts_puts(" capabilities, fully autonomously --\n" as *u8) 109 ts_puts(" the team generated, proved, governed, banked, and BUILT ON its own work.\n" as *u8) 110 111 // GATE: all backlog banked, the composite verified, library = backlog + 1. 112 if banked != nt { sys_exit(1); return 1 } 113 if compose_ok != 1 { sys_exit(2); return 2 } 114 if lib_n != nt + 1 { sys_exit(3); return 3 } 115 sys_exit(0) 116 return 0 117}