code wiki / _hdl_build / nx_autonomy_grow_loop.nx

nx_autonomy_grow_loop.nx source

↩ module page · 127 lines · 9424 B

1// nx_autonomy_grow_loop.nx -- Implements a continuous authoring engine that synthesizes and registers novel, generalizing constructs from datasets. 2import "nx_gate_gn.nx" 3import "nx_gate_base.nx" 4// nx_autonomy_grow_loop.nx -- #2: the TRIANGULATION-GATED continuous authoring engine. Compounds the proven lever 5// (team-authoring) WITHOUT Claude hand-feeding grammar: each beat the team meets a dataset, SYNTHESIZES a closed 6// form (nx_ncf_synth), and registers author=emitter ONLY IF it clears the bar -- GENERALIZES on a held-out point 7// (independently computed) AND is NOVEL (not already in the library). Anti-wave BY CONSTRUCTION: duplicates are 8// DEDUPED and out-of-grammar data is REFUSED, so the meter grows ONLY by genuine novel triangulated families. 9// This is the loop that drives nx_autonomy_create on a beat -> A2 accrues, honestly. 10// T1 PROCESSED: the loop ran every candidate on its own (no Claude between). 11// T2 AUTHORED-GENUINE: only families that GENERALIZE (held-out) + are NOVEL got author=emitter. 12// T3 DEDUP (anti-wave): a repeat dataset was SKIPPED, not re-registered (no meter-gaming by repetition). 13// T4 REFUSED (anti-wave): out-of-grammar data (primes) authored NOTHING (no fabrication). 14// T5 MEASURABLE: A2 grows by exactly the genuine-novel count -> wire this beat into nx_governed_pulse. 15// license_tier: ORIGINAL 16import "nx_ncf_synth.nx" 17import "nx_synth_fit.nx" 18import "nx_cap_register.nx" 19import "nx_capreg_librarian.nx" 20import "nx_syscalls.nx" 21const GL_MAGIC_1024: i64 = 1024 22const GL_MAGIC_40320: i64 = 40320 23 24const GL_MAXLIB: i64 = 16 25 26 27func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 28" as *u8); return ok } 29func sg_reg_emitter(desc: *u8) -> i64 { 30 let eng: i64=ig_engineer(1,1,1,1) 31 let council: i64=ig_council(eng,1,1,2) 32 let dec: i64=ig_decision(eng,council,1) 33 if dec!=IG_INGEST { return 0 } 34 if cr_can_register(5,2,6,dec)!=1 { return 0 } 35 let lp: *u8="/tmp/nishi_cap_registry.log" as *u8 36 let jp: *u8="knowledge/status/cap_registry_durable.log" as *u8 37 let idx: i64=cl_next_idx(lp,jp) 38 if cl_register_dual(lp,jp,idx,5,2,desc)!=1 { return 0 } 39 return 1 40} 41// triangulation bar: synthesize a construct that GENERALIZES to an independently-computed held-out point. 42func genuine_fit(xs: *i64, ys: *i64, n: i64, hx: i64, hy: i64, form_out: *i64) -> i64 { 43 let kind: i64=ncf_synth(xs, ys, n, form_out) 44 if kind==0 { return 0 } 45 if ncf_eval(kind, form_out, hx)!=hy { return 0 } 46 return kind 47} 48// dedup: is this sequence already an authored family? (anti-wave -- repetition must NOT accrue) 49func seq_in_lib(ys: *i64, n: i64, lib: *i64, libn: i64) -> i64 { 50 var e: i64=0 51 while e<libn { var mt: i64=1; var i: i64=0; while i<n { if lib[e*8+i]!=ys[i] { mt=0 } i=i+1 } if mt==1 { return 1 } e=e+1 } 52 return 0 53} 54// one beat: dedup -> synthesize+triangulate -> register-if-genuine-and-novel. returns 1=authored,2=dup,0=refused. 55func process_one(xs: *i64, ys: *i64, n: i64, hx: i64, hy: i64, desc: *u8, lib: *i64, libnp: *i64, form: *i64) -> i64 { 56 if seq_in_lib(ys, n, lib, libnp[0])==1 { return 2 } // DEDUP 57 let kind: i64=genuine_fit(xs, ys, n, hx, hy, form) 58 if kind==0 { return 0 } // REFUSED (no generalizing fit) 59 sg_reg_emitter(desc) // genuine + novel -> author=emitter 60 var i: i64=0; while i<n { lib[libnp[0]*8+i]=ys[i]; i=i+1 } 61 libnp[0]=libnp[0]+1 62 return 1 63} 64 65func main() -> i64 { 66 gw("=== nx_autonomy_grow_loop (#2): triangulation-GATED continuous authoring -- A2 grows ONLY by genuine novel families ===\n" as *u8) 67 var pass: i64=0; var total: i64=0 68 let lib: *i64=sys_mmap(8*GL_MAXLIB*8) as *i64; let libn: *i64=sys_mmap(16) as *i64; libn[0]=0 69 let form: *i64=sys_mmap(128) as *i64 70 let xs: *i64=sys_mmap(128) as *i64; let ys: *i64=sys_mmap(128) as *i64 71 var i: i64=0; while i<8 { xs[i]=i; i=i+1 } 72 var authored: i64=0; var dup: i64=0; var refused: i64=0; var beats: i64=0 73 74 // beat 1: 2^x (novel exponential family) -> authored. 75 var p: i64=1; i=0; while i<8 { ys[i]=p; p=p*2; i=i+1 } 76 let r1: i64=process_one(xs, ys, 8, 10, GL_MAGIC_1024, "EMITTER-AUTHORED FAMILY exp2 (2^x): team SYNTHESIZED a multiplicative-loop closed form, generalizes held-out a(10)=1024, NOVEL (non-powersum), author=emitter, triangulation-gated" as *u8, lib, libn, form) 77 beats=beats+1; if r1==1 { authored=authored+1 } else { if r1==2 { dup=dup+1 } else { refused=refused+1 } } 78 gw(" beat1 exp2(2^x) -> " as *u8); if r1==1 { gw("AUTHORED" as *u8) } else { if r1==2 { gw("DUP" as *u8) } else { gw("REFUSED" as *u8) } } gw("\n" as *u8) 79 80 // beat 2: Fibonacci (distinct family) -> authored. 81 ys[0]=0; ys[1]=1; i=2; while i<8 { ys[i]=ys[i-1]+ys[i-2]; i=i+1 } 82 let r2: i64=process_one(xs, ys, 8, 9, 34, "EMITTER-AUTHORED FAMILY fibonacci: team SYNTHESIZED a multi-state recurrence, generalizes fib(9)=34, NOVEL, author=emitter, triangulation-gated" as *u8, lib, libn, form) 83 beats=beats+1; if r2==1 { authored=authored+1 } else { if r2==2 { dup=dup+1 } else { refused=refused+1 } } 84 gw(" beat2 fibonacci -> " as *u8); if r2==1 { gw("AUTHORED" as *u8) } else { if r2==2 { gw("DUP" as *u8) } else { gw("REFUSED" as *u8) } } gw("\n" as *u8) 85 86 // beat 3: factorial (distinct family) -> authored (if in grammar). 87 ys[0]=1; var f: i64=1; i=1; while i<8 { f=f*i; ys[i]=f; i=i+1 } 88 let r3: i64=process_one(xs, ys, 8, 8, GL_MAGIC_40320, "EMITTER-AUTHORED FAMILY factorial: team SYNTHESIZED an acc*i loop, generalizes 8!=40320, NOVEL, author=emitter, triangulation-gated" as *u8, lib, libn, form) 89 beats=beats+1; if r3==1 { authored=authored+1 } else { if r3==2 { dup=dup+1 } else { refused=refused+1 } } 90 gw(" beat3 factorial -> " as *u8); if r3==1 { gw("AUTHORED" as *u8) } else { if r3==2 { gw("DUP" as *u8) } else { gw("REFUSED" as *u8) } } gw("\n" as *u8) 91 92 // beat 4: 2^x AGAIN -> DEDUP (anti-wave: repetition must not accrue). 93 p=1; i=0; while i<8 { ys[i]=p; p=p*2; i=i+1 } 94 let r4: i64=process_one(xs, ys, 8, 10, GL_MAGIC_1024, "exp2-REPEAT (should be deduped)" as *u8, lib, libn, form) 95 beats=beats+1; if r4==1 { authored=authored+1 } else { if r4==2 { dup=dup+1 } else { refused=refused+1 } } 96 gw(" beat4 exp2-repeat -> " as *u8); if r4==1 { gw("AUTHORED" as *u8) } else { if r4==2 { gw("DUP" as *u8) } else { gw("REFUSED" as *u8) } } gw("\n" as *u8) 97 98 // beat 5: primes -> REFUSED (anti-wave: out-of-grammar must not fabricate). 99 ys[0]=2; ys[1]=3; ys[2]=5; ys[3]=7; ys[4]=11; ys[5]=13; ys[6]=17; ys[7]=19 100 let r5: i64=process_one(xs, ys, 8, 8, 23, "primes (should be refused)" as *u8, lib, libn, form) 101 beats=beats+1; if r5==1 { authored=authored+1 } else { if r5==2 { dup=dup+1 } else { refused=refused+1 } } 102 gw(" beat5 primes -> " as *u8); if r5==1 { gw("AUTHORED" as *u8) } else { if r5==2 { gw("DUP" as *u8) } else { gw("REFUSED" as *u8) } } gw("\n" as *u8) 103 104 total=total+1; if beats==5 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 105 gw("T1 PROCESSED: ran " as *u8); gn(beats); gw(" beats on its own (no Claude between)\n" as *u8) 106 107 total=total+1; if authored==3 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 108 gw("T2 AUTHORED-GENUINE: " as *u8); gn(authored); gw(" families authored (exp2, fibonacci, factorial -- each GENERALIZES held-out + NOVEL), author=emitter\n" as *u8) 109 110 total=total+1; if dup==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 111 gw("T3 DEDUP (anti-wave): " as *u8); gn(dup); gw(" repeat dataset SKIPPED -- repetition does NOT accrue to the meter (no gaming)\n" as *u8) 112 113 total=total+1; if refused==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 114 gw("T4 REFUSED (anti-wave): " as *u8); gn(refused); gw(" out-of-grammar (primes) authored NOTHING -- no fabrication\n" as *u8) 115 116 total=total+1; if authored==3 { if dup==1 { if refused==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } 117 gw("T5 MEASURABLE: A2 grows by EXACTLY the 3 genuine-novel families (not 5) -> wire this beat into nx_governed_pulse for continuous, honest accrual\n" as *u8) 118 119 gw("\n THE GATED ENGINE: each beat the team synthesizes a closed form and registers author=emitter ONLY through the triangulation\n" as *u8) 120 gw(" bar (generalizes on independent held-out) AND novelty (dedup). Repetition deduped, out-of-grammar refused -> the meter\n" as *u8) 121 gw(" grows ONLY by genuine novel families. Honest: WITHIN-run dedup here; production needs PERSISTENT dedup vs the registry\n" as *u8) 122 gw(" (else re-running re-registers) -- the one refinement before wiring to the unbounded pulse. Targets here are a fixed set;\n" as *u8) 123 gw(" autonomous target-discovery (an environment/stream) is the next step past Claude-curated candidates.\n" as *u8) 124 gw("AUTONOMY-GROW-LOOP verdict=" as *u8) 125 if pass==total { gw("GREEN passes=" as *u8); gn(pass); gw("/" as *u8); gn(total); gw(" -- triangulation-gated continuous authoring (authored 3 genuine, deduped 1, refused 1)\n" as *u8); sys_exit(0); return 0 } 126 gw("RED passes=" as *u8); gn(pass); gw("/" as *u8); gn(total); gw("\n" as *u8); sys_exit(1); return 1 127}