code wiki / _hdl_build / nx_evolution_oracle_gate.nx
nx_evolution_oracle_gate.nx source
↩ module page · 137 lines · 8282 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3import "nx_gate_verdict.nx"
4// nx_evolution_oracle_gate.nx -- R10: the LINEAGE LIAR-KILLER (operator's insight). Use what is already
5// built FROM GOD as the benchmark for whether a fresh generation is EVOLVING WELL. For a generated
6// capability: find the SAME behavior in the lineage (the god-rooted best-so-far). Compare quality
7// (op-list length = efficiency; shorter is better, correctness required):
8// SUPERIOR (shorter, correct) -> evolving well; ADOPT it (the lineage improves).
9// EQUAL -> fine.
10// INFERIOR (longer) -> we DEFINITELY missed evolutions; do NOT adopt; BACKTRACK -- revisit
11// the parents back to GOD (the lineage holds the efficient ancestor) and
12// re-scaffold properly.
13// NEW behavior -> a genuine new evolution; adopt + extend the lineage.
14// This is a LIAR-KILLER: a scaffold that "reaches the target" but is WORSE than what we already built is
15// a REGRESSION dressed as progress -- a naive "did it work?" passes it; this catches it. Sovereign.
16// license_tier: ORIGINAL [[feedback-no-wave-measured-exceed]] [[project-genesis-genealogy-2026-06-16]]
17import "nx_syscalls.nx"
18
19const O_NPROBE: i64 = 4
20const O_MAXOPS: i64 = 8
21const O_MAXLIN: i64 = 16
22
23
24func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
25" as *u8); return ok }
26func o_sig(ops: *i64, args: *i64, len: i64, sig: *i64) -> i64 {
27 var p: i64 = 0
28 while p < O_NPROBE {
29 var acc: i64 = p; var k: i64 = 0
30 while k < len { let op: i64 = ops[k]; if op==0 { acc=acc+args[k] } if op==1 { acc=acc*args[k] } if op==2 { acc=acc*acc } k=k+1 }
31 sig[p] = acc; p = p + 1
32 }
33 return 0
34}
35func o_sigeq(a: *i64, b: *i64) -> i64 { var p: i64=0; while p<O_NPROBE { if a[p]!=b[p] { return 0 } p=p+1 } return 1 }
36
37// lineage store: per entry a sig + the god-rooted best op-list + its length.
38// find the lineage index whose sig matches `sig`, or -1.
39func lin_find(lin_sig: *i64, nlin: i64, sig: *i64) -> i64 {
40 var i: i64 = 0
41 while i < nlin { let e: *i64 = ((lin_sig as i64)+i*O_NPROBE*8) as *i64; if o_sigeq(e, sig)==1 { return i } i = i + 1 }
42 return 0 - 1
43}
44// store/overwrite lineage entry idx with (sig, ops, len).
45func lin_put(lin_sig: *i64, lin_len: *i64, lin_ops: *i64, idx: i64, sig: *i64, ops: *i64, args: *i64, len: i64) -> i64 {
46 var p: i64 = 0; while p < O_NPROBE { lin_sig[idx*O_NPROBE+p]=sig[p]; p=p+1 }
47 lin_len[idx] = len
48 var k: i64 = 0; while k < len { lin_ops[idx*O_MAXOPS+k]=ops[k]; k=k+1 } // (args omitted from store; len is the quality metric)
49 return 0
50}
51
52// GRADE a candidate vs the god-rooted lineage. returns 1=SUPERIOR 0=EQUAL -1=INFERIOR 2=NEW.
53// on SUPERIOR/NEW updates the lineage (evolution adopted). on INFERIOR sets bt_len[0]=the god-rooted best length.
54func o_grade(lin_sig: *i64, lin_len: *i64, lin_ops: *i64, nlin_p: *i64, ops: *i64, args: *i64, len: i64, bt_len: *i64) -> i64 {
55 let sig: *i64 = sys_mmap(8*O_NPROBE) as *i64
56 o_sig(ops, args, len, sig)
57 let nlin: i64 = nlin_p[0]
58 let idx: i64 = lin_find(lin_sig, nlin, sig)
59 if idx < 0 {
60 lin_put(lin_sig, lin_len, lin_ops, nlin, sig, ops, args, len)
61 nlin_p[0] = nlin + 1
62 return 2
63 }
64 let best: i64 = lin_len[idx]
65 if len < best { lin_put(lin_sig, lin_len, lin_ops, idx, sig, ops, args, len); return 1 }
66 if len == best { return 0 }
67 bt_len[0] = best
68 return 0 - 1
69}
70
71func main(argc: i64, argv: *i64) -> i64 {
72 gw("=== R10 LINEAGE LIAR-KILLER: grade evolution vs what's already built FROM GOD ===\n" as *u8)
73 let lin_sig: *i64 = sys_mmap(8*O_MAXLIN*O_NPROBE) as *i64
74 let lin_len: *i64 = sys_mmap(8*O_MAXLIN) as *i64
75 let lin_ops: *i64 = sys_mmap(8*O_MAXLIN*O_MAXOPS) as *i64
76 let nlin: *i64 = sys_mmap(16) as *i64
77 nlin[0] = 0
78 let to: *i64 = sys_mmap(8*O_MAXOPS) as *i64
79 let ta: *i64 = sys_mmap(8*O_MAXOPS) as *i64
80 let sig: *i64 = sys_mmap(8*O_NPROBE) as *i64
81 let bt: *i64 = sys_mmap(16) as *i64
82 // SEED the lineage (already built, god-rooted): x^2=[square] len1 ; 4x=[*2,*2] len2 (a suboptimal-known)
83 to[0]=2; ta[0]=0; o_sig(to,ta,1,sig); lin_put(lin_sig,lin_len,lin_ops,nlin[0],sig,to,ta,1); nlin[0]=nlin[0]+1
84 to[0]=1; ta[0]=2; to[1]=1; ta[1]=2; o_sig(to,ta,2,sig); lin_put(lin_sig,lin_len,lin_ops,nlin[0],sig,to,ta,2); nlin[0]=nlin[0]+1
85 gw("seeded lineage: x^2=[square] len1, 4x=[*2,*2] len2\n\n" as *u8)
86
87 // C1 INFERIOR: x^2 via [square,+1,-1] len3 (correct behavior, wasteful) -> vs lineage [square] len1
88 to[0]=2; ta[0]=0; to[1]=0; ta[1]=1; to[2]=0; ta[2]=0-1
89 bt[0]=0
90 let v1: i64 = o_grade(lin_sig,lin_len,lin_ops,nlin, to,ta,3, bt)
91 gw(" C1 x^2 via [square,+1,-1] len3 -> verdict=" as *u8); gn(v1)
92 if v1 == 0-1 { gw(" INFERIOR -> BACKTRACK to god-rooted form len=" as *u8); gn(bt[0]); gw(" (revisit parents to god, re-scaffold minimal)\n" as *u8) } else { gw("\n" as *u8) }
93
94 // C2 SUPERIOR: 4x via [*4] len1 -> vs lineage [*2,*2] len2 -> shorter -> adopt
95 to[0]=1; ta[0]=4
96 let v2: i64 = o_grade(lin_sig,lin_len,lin_ops,nlin, to,ta,1, bt)
97 gw(" C2 4x via [*4] len1 -> verdict=" as *u8); gn(v2); if v2==1 { gw(" SUPERIOR -> ADOPT (lineage 4x improves 2->1, evolving well)\n" as *u8) } else { gw("\n" as *u8) }
98
99 // C3 EQUAL: x^2 via [square] len1
100 to[0]=2; ta[0]=0
101 let v3: i64 = o_grade(lin_sig,lin_len,lin_ops,nlin, to,ta,1, bt)
102 gw(" C3 x^2 via [square] len1 -> verdict=" as *u8); gn(v3); if v3==0 { gw(" EQUAL -> fine\n" as *u8) } else { gw("\n" as *u8) }
103
104 // C4 NEW: x^2+5 via [square,+5] len2 -> no lineage entry -> new evolution
105 to[0]=2; ta[0]=0; to[1]=0; ta[1]=5
106 let v4: i64 = o_grade(lin_sig,lin_len,lin_ops,nlin, to,ta,2, bt)
107 gw(" C4 x^2+5 via [square,+5] len2 -> verdict=" as *u8); gn(v4); if v4==2 { gw(" NEW -> adopt as a genuine new evolution\n" as *u8) } else { gw("\n" as *u8) }
108
109 // verify the INFERIOR C1 was NOT adopted: lineage x^2 is STILL len1 (the god-rooted form held).
110 to[0]=2; ta[0]=0; o_sig(to,ta,1,sig)
111 let xidx: i64 = lin_find(lin_sig, nlin[0], sig)
112 var x2len: i64 = 0-1; if xidx >= 0 { x2len = lin_len[xidx] }
113 gw("\n post-check: lineage x^2 best length = " as *u8); gn(x2len); gw(" (the inferior C1 was REJECTED, god-form held)\n" as *u8)
114
115 // ---- GATE (no-fake-green) ----
116 var t1: i64 = 0; if v2 == 1 { t1 = 1 } // SUPERIOR detected (evolving well)
117 var t2: i64 = 0; if v3 == 0 { t2 = 1 } // EQUAL detected
118 var t3: i64 = 0; if v1 == 0-1 { if bt[0] == 1 { t3 = 1 } } // INFERIOR caught + BACKTRACK returns the god-rooted len1
119 var t4: i64 = 0; if v4 == 2 { t4 = 1 } // NEW behavior adopted as evolution
120 var t5: i64 = 0; if x2len == 1 { t5 = 1 } // NO-FAKE: the inferior regression was NOT adopted
121
122 gw("T1 superior=" as *u8); gn(t1); gw(" T2 equal=" as *u8); gn(t2); gw(" T3 inferior+backtrack-to-god=" as *u8); gn(t3); gw(" T4 new=" as *u8); gn(t4); gw(" T5 regression-rejected=" as *u8); gn(t5); gw("\n" as *u8)
123
124 // MIGRATED onto nx_gate_verdict (D001, 2026-08-11): five gv_check rows replace the hand-rolled
125 // "VERDICT:" spelling. The C1..C4 rows above print their own mid-output verdict= tokens, so the
126 // canonical verdict= line being LAST (positional anchoring) is what keeps this gate readable.
127 gw("WIRE-IN: every scaffolded capability is graded vs its god-rooted ancestor; inferior -> revisit parents to god + re-scaffold. (Toy domain; same mechanism applies to the real genesis_lineage.)\n" as *u8)
128 let ctr: *i64 = gv_ctr()
129 gv_check("T1 superior detected (evolving well)" as *u8, t1, ctr)
130 gv_check("T2 equal detected" as *u8, t2, ctr)
131 gv_check("T3 inferior caught + backtrack returns the god-rooted form" as *u8, t3, ctr)
132 gv_check("T4 new behavior adopted as evolution" as *u8, t4, ctr)
133 gv_check("T5 regression NOT adopted (no-fake)" as *u8, t5, ctr)
134 let rc: i64 = gv_verdict("EVOLUTION-ORACLE-GATE" as *u8, ctr, "the lineage from god grades evolution; the liar-killer works" as *u8)
135 sys_exit(rc)
136 return rc
137}