code wiki / _hdl_build / nx_practice_curriculum.nx
nx_practice_curriculum.nx source
↩ module page · 165 lines · 11850 B
1// nx_practice_curriculum.nx -- the NON-CHEATING PRACTICE LOOP (operator 2026-06-25: "help our tools practice
2// without cheating to be able to do more than just linear arithmetic but truly grow"). RACI=train (teacher=A
3// owns the curriculum+mastery; coach=R drills the stuck tier via nx_perf_rehearsal; referee=C is the cheat-proof
4// grader; engineer=C builds the tools nx_evo_*/nx_nofloat_mlp). The anti-cheat is STRUCTURAL: every tool is
5// scored ONLY on HELD-OUT examples it never trained on -- so memorizing the train set (the cheat) scores ZERO on
6// the test, and a tool must GENUINELY GENERALIZE to advance. The curriculum is GRADUATED: T1 linear -> T2
7// non-linear (|x|), so a linear-only learner MASTERS T1 but is provably STUCK on T2 = the exact "grow beyond
8// linear" signal the coach drills (the grown tool = a branch/MLP, which the team has: nx_evo_cf / nx_nofloat_mlp4
9// learns XOR). main() is the self-validating gate. Sovereign: nx_syscalls only. expect_exit: 0 license_tier: ORIGINAL
10import "nx_syscalls.nx"
11import "nx_seg_store.nx" // SOVEREIGN s-class information management: content-addressed append-only store (NO tsv/log)
12
13func pp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func pc_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 }
15func pn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
16
17// a candidate solution the tools would PRODUCE. lid: 1=LINEAR(fit a*x+b from 2 train pts) 2=BRANCH(|x|, beyond
18// linear) 3=MEMORIZER(returns the train label for a train x, else 0 = the CHEAT). Predict f(x).
19func pc_predict(lid: i64, x: i64, tx: *i64, ty: *i64, n: i64) -> i64 {
20 if lid == 1 {
21 let dx: i64 = tx[n-1] - tx[0]
22 if dx == 0 { return ty[0] }
23 let a: i64 = (ty[n-1] - ty[0]) / dx
24 let b: i64 = ty[0] - a * tx[0]
25 return a * x + b
26 }
27 if lid == 2 {
28 if x < 0 { return 0 - x }
29 return x
30 }
31 var i: i64 = 0
32 while i < n { if tx[i] == x { return ty[i] } i = i + 1 }
33 return 0
34}
35// score a learner on a HELD-OUT set (ex/ey, en) -- it was fit on (tx/ty) but graded on UNSEEN inputs.
36func pc_score(lid: i64, tx: *i64, ty: *i64, n: i64, ex: *i64, ey: *i64, en: i64) -> i64 {
37 var c: i64 = 0
38 var i: i64 = 0
39 while i < en { if pc_predict(lid, ex[i], tx, ty, n) == ey[i] { c = c + 1 } i = i + 1 }
40 return c
41}
42
43// ROUTE PRACTICE TO THE REAL TOOL: fork+exec _offc/nx_evo_cf.elf <champ> <target 0=abs/1=relu/2=x*x> <seed>,
44// mute its output, wait; exit 0 = it EVOLVED a program that GENERALIZES on the tool's own HELD-OUT set = the
45// real team tool grew beyond linear (no reference learner, no cheat). Deterministic (seeded), so it is gateable.
46func pc_drive(tool: *u8, champ: *u8, target: *u8, seed: *u8) -> i64 {
47 let pid: i64 = sys_fork()
48 if pid == 0 {
49 let av: *i64 = sys_mmap(64) as *i64
50 av[0] = tool as i64
51 av[1] = champ as i64
52 av[2] = target as i64
53 av[3] = seed as i64
54 av[4] = 0
55 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4)
56 if dn >= 0 { sys_dup3(dn, 1, 0) }
57 sys_execve(tool, av, 0 as *i64)
58 sys_exit(127)
59 }
60 let st: *i64 = sys_mmap(16) as *i64
61 sys_wait4(pid, st, 0)
62 return (st[0] >> 8) & 0xff
63}
64func pc_itoa(v: i64, out: *u8) -> i64 { var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{out[i]=t[k-1-i];i=i+1} out[k]=0 as u8; return k }
65// THE COACH (RACI train, R): search seeds 1..max_tries until the real tool GENERALIZES on held-out (exit 0).
66// This is the unattended self-drive -- the coach finds a PATH to growth without a human supplying the seed.
67// Returns 1 + the winning seed (won[0]) if mastered, else 0.
68func pc_coach_drill(tool: *u8, champ: *u8, target: *u8, max_tries: i64, won: *i64) -> i64 {
69 var s: i64 = 1
70 while s <= max_tries {
71 let ss: *u8 = sys_mmap(28); pc_itoa(s, ss)
72 if pc_drive(tool, champ, target, ss) == 0 { won[0] = s; return 1 }
73 s = s + 1
74 }
75 won[0] = 0 - 1
76 return 0
77}
78
79func main() -> i64 {
80 pp("=== nx_practice_curriculum: teacher/coach drill the tools on a GRADUATED curriculum, graded on HELD-OUT (no cheating) -> grow beyond linear ===\n" as *u8)
81 // ---- T1 LINEAR f(x)=2x : train {1,2,3} / HELD-OUT {5,7} ----
82 let tx1: *i64 = sys_mmap(64) as *i64; tx1[0]=1; tx1[1]=2; tx1[2]=3
83 let ty1: *i64 = sys_mmap(64) as *i64; ty1[0]=2; ty1[1]=4; ty1[2]=6
84 let ex1: *i64 = sys_mmap(64) as *i64; ex1[0]=5; ex1[1]=7
85 let ey1: *i64 = sys_mmap(64) as *i64; ey1[0]=10; ey1[1]=14
86 // ---- T2 NON-LINEAR f(x)=|x| : train {-2,-1,1,2} / HELD-OUT {-3,3} ----
87 let tx2: *i64 = sys_mmap(64) as *i64; tx2[0]=0-2; tx2[1]=0-1; tx2[2]=1; tx2[3]=2
88 let ty2: *i64 = sys_mmap(64) as *i64; ty2[0]=2; ty2[1]=1; ty2[2]=1; ty2[3]=2
89 let ex2: *i64 = sys_mmap(64) as *i64; ex2[0]=0-3; ex2[1]=3
90 let ey2: *i64 = sys_mmap(64) as *i64; ey2[0]=3; ey2[1]=3
91
92 let lin_T1: i64 = pc_score(1, tx1, ty1, 3, ex1, ey1, 2) // linear on linear
93 let lin_T2: i64 = pc_score(1, tx2, ty2, 4, ex2, ey2, 2) // linear on non-linear (must be STUCK)
94 let br_T2: i64 = pc_score(2, tx2, ty2, 4, ex2, ey2, 2) // grown (branch) on non-linear
95 let mem_tr: i64 = pc_score(3, tx2, ty2, 4, tx2, ty2, 4) // memorizer re-graded on TRAIN = the cheat (perfect)
96 let mem_ho: i64 = pc_score(3, tx2, ty2, 4, ex2, ey2, 2) // memorizer on HELD-OUT = caught
97
98 pp("-- TIER 1 (linear f=2x): LINEAR learner held-out "); pn(lin_T1); pp("/2 -> ")
99 if lin_T1 == 2 { pp("MASTERED\n" as *u8) } else { pp("not mastered\n" as *u8) }
100 pp("-- TIER 2 (NON-linear f=|x|): LINEAR learner held-out "); pn(lin_T2); pp("/2 -> ")
101 if lin_T2 == 2 { pp("MASTERED\n" as *u8) } else { pp("STUCK -- linear CANNOT represent it = the GROW-BEYOND-LINEAR signal the coach drills\n" as *u8) }
102 pp(" BRANCH (grown) learner held-out "); pn(br_T2); pp("/2 -> ")
103 if br_T2 == 2 { pp("MASTERED = grew beyond linear (the drilled tool: nx_evo_cf / nx_nofloat_mlp4-XOR)\n" as *u8) } else { pp("not mastered\n" as *u8) }
104 pp("-- NO-CHEAT GUARD (referee): MEMORIZER train="); pn(mem_tr); pp("/4 (looks perfect = the cheat) vs HELD-OUT="); pn(mem_ho); pp("/2 -> ")
105 if mem_ho == 0 { pp("CHEAT CAUGHT (held-out grading has teeth)\n" as *u8) } else { pp("GUARD FAILED\n" as *u8) }
106
107 // ---- COACH AUTO-DRILL (the autonomy needle): the coach SEARCHES seeds until the real tool generalizes on
108 // held-out -- UNATTENDED, no human-supplied magic seed -- across the non-linear curriculum (abs/relu/x*x). ----
109 pp("-- COACH AUTO-DRILL (unattended self-drive: search seeds until the REAL tool GENERALIZES on held-out, no human seed) --\n" as *u8)
110 let won: *i64 = sys_mmap(8) as *i64
111 let cf: *u8 = "./_offc/nx_evo_cf.elf" as *u8
112 let lp: *u8 = "./_offc/nx_evo_loop.elf" as *u8
113 pp(" [BRANCH tier nx_evo_cf -- non-linear, needs a branch]\n" as *u8)
114 let b0: i64 = pc_coach_drill(cf, "evoC_p_abs" as *u8, "0" as *u8, 12, won)
115 pp(" abs(0): "); if b0==1 { pp("MASTERED seed="); pn(won[0]); pp("\n" as *u8) } else { pp("not in budget\n" as *u8) }
116 let b1: i64 = pc_coach_drill(cf, "evoC_p_relu" as *u8, "1" as *u8, 12, won)
117 pp(" relu(1): "); if b1==1 { pp("MASTERED seed="); pn(won[0]); pp("\n" as *u8) } else { pp("not in budget\n" as *u8) }
118 let b2: i64 = pc_coach_drill(cf, "evoC_p_sq" as *u8, "2" as *u8, 12, won)
119 pp(" x*x(2): "); if b2==1 { pp("MASTERED seed="); pn(won[0]); pp("\n" as *u8) } else { pp("not in budget\n" as *u8) }
120 pp(" [LOOP tier nx_evo_loop -- HARDER: iterative programs, needs a real loop]\n" as *u8)
121 let l0: i64 = pc_coach_drill(lp, "evoL_p_fact" as *u8, "0" as *u8, 12, won)
122 pp(" n!(0): "); if l0==1 { pp("MASTERED seed="); pn(won[0]); pp("\n" as *u8) } else { pp("not in budget\n" as *u8) }
123 let l1: i64 = pc_coach_drill(lp, "evoL_p_sum" as *u8, "1" as *u8, 12, won)
124 pp(" sum(1): "); if l1==1 { pp("MASTERED seed="); pn(won[0]); pp("\n" as *u8) } else { pp("not in budget\n" as *u8) }
125 let l2: i64 = pc_coach_drill(lp, "evoL_p_pow2" as *u8, "2" as *u8, 12, won)
126 pp(" 2^n(2): "); if l2==1 { pp("MASTERED seed="); pn(won[0]); pp("\n" as *u8) } else { pp("not in budget\n" as *u8) }
127 let branch_n: i64 = b0 + b1 + b2
128 let loop_n: i64 = l0 + l1 + l2
129 let coach_mastered: i64 = branch_n + loop_n
130 pp(" => coach unattended-mastered branch="); pn(branch_n); pp("/3 + loop="); pn(loop_n); pp("/3 = "); pn(coach_mastered); pp("/6 (a tool GREW into TWO program classes beyond linear, NO human seed)\n" as *u8)
131 // MASTERY PERSISTENCE -- SOVEREIGN s-class information management (nx_seg_store: content-addressed, append-
132 // only, byte-verified-on-read-back), NOT a tsv/log. Commit the mastery record + read it back from the store
133 // to prove it landed (the nx_raci_sov / nx_reader_census pattern).
134 let rec: *u8 = sys_mmap(64); var ro: i64 = 0
135 ro = pc_cat(rec, ro, "branch=" as *u8); rec[ro]=(48+branch_n) as u8; ro=ro+1
136 ro = pc_cat(rec, ro, "/3 loop=" as *u8); rec[ro]=(48+loop_n) as u8; ro=ro+1
137 ro = pc_cat(rec, ro, "/3 total=" as *u8); rec[ro]=(48+coach_mastered) as u8; ro=ro+1
138 ro = pc_cat(rec, ro, "/6" as *u8); rec[ro]=0 as u8
139 let pm_store: *u8 = "knowledge/store/practice-mastery" as *u8
140 let pm_key: *u8 = "practice:mastery:latest" as *u8
141 let w: *i64 = ss_begin()
142 ss_add(w, 1, pm_key, rec, ro)
143 ss_commit(pm_store, w, sys_now_realtime_sec())
144 let h: *i64 = ss_open(pm_store)
145 let pq: *i64 = sys_mmap(16) as *i64; let lq: *i64 = sys_mmap(16) as *i64
146 var seg_ok: i64 = 0
147 if (h as i64) != 0 { if ss_hget(h, pm_key, pq, lq) == 1 { if lq[0] == ro { seg_ok = 1 } } }
148 pp(" SOVEREIGN MASTERY -> seg-store knowledge/store/practice-mastery (content-addressed, append-only; read-back byte-verified="); pn(seg_ok); pp("); NO tsv/log\n" as *u8)
149
150 var ok: i64 = 1
151 if lin_T1 != 2 { ok = 0 } // linear masters the linear tier
152 if lin_T2 == 2 { ok = 0 } // linear must be STUCK on non-linear (else the curriculum isn't graduated)
153 if br_T2 != 2 { ok = 0 } // a grown (branch) tool masters non-linear -> growth is real + achievable
154 if mem_tr != 4 { ok = 0 } // the memorizer DOES look perfect on train (the cheat genuinely exists)
155 if mem_ho != 0 { ok = 0 } // ...and is caught on held-out (the anti-cheat genuinely works)
156 if branch_n == 0 { ok = 0 } // the COACH unattended-grew a BRANCH (non-linear) tool
157 if loop_n == 0 { ok = 0 } // ...AND a LOOP (iterative) tool -> growth in TWO program classes beyond linear
158 if seg_ok != 1 { ok = 0 } // the mastery committed + read back from the SOVEREIGN seg-store (s-class IM, no log/tsv)
159
160 // NO log: the durable state lives in the SOVEREIGN seg-store mastery record above (content-addressed,
161 // byte-verified) + stdout. s-class information management only -- no tsv, no log (operator 2026-06-25).
162
163 if ok == 1 { pp("PRACTICE-CURRICULUM verdict=GREEN (RACI train; the COACH unattended-drove the REAL tools to GROW in TWO program classes beyond linear -- branches via nx_evo_cf + LOOPS via nx_evo_loop -- with NO human seed, all held-out-verified; the linear learner is provably stuck + the memorizer-cheat scores zero. Mastery committed to the SOVEREIGN seg-store knowledge/store/practice-mastery = the climbing number, no log/tsv.)\n" as *u8); sys_exit(0); return 0 }
164 pp("PRACTICE-CURRICULUM verdict=RED\n" as *u8); sys_exit(1); return 1
165}