code wiki / _hdl_build / nx_genome_gate.nx
nx_genome_gate.nx source
↩ module page · 194 lines · 9475 B
1// nx_genome_gate.nx -- certifies the genetics/breeding part (capability 30, F1066, plan Lane B1).
2// METHOD: every equality tooth carries a NON-VACUITY guard; the flagship tooth is the ADULT
3// INVARIANT (breeding with a minor parent REFUSES with output bit-untouched), and the mutation test
4// breaks exactly that and must drive T4 RED while anti-vacuity T7 holds.
5// license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_gamesave.nx"
8import "nx_breeding.nx"
9
10const GG_BREED_N: i64 = 100 // offspring per uniqueness sweep
11const GG_BOUND_N: i64 = 200 // breedings per bounds/heritability sweep
12const GG_GEN_N: i64 = 25 // chained generations for the drift sweep
13const GG_SAVEAT: i64 = 1785200000
14const GG_SENT: i64 = 424242 // sentinel fill: proves REFUSAL leaves output untouched
15const GG_FMODE: i64 = 0x1a4
16
17func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
18func pn(v: i64) -> i64 {
19 if v==0 { sys_write(1,"0" as *u8,1); return 0 }
20 var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m }
21 let t: *u8=sys_mmap(32); var k: i64=0
22 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
23 let o: *u8=sys_mmap(32); var q: i64=k-1; var i: i64=0
24 while q>=0 { o[i]=t[q]; i=i+1; q=q-1 }
25 sys_write(1,o,i); return 0
26}
27func line_g(nm: *u8) -> i64 { pw(" " as *u8); pw(nm as *u8); pw(" GREEN\n" as *u8); return 0 }
28func line_r(nm: *u8) -> i64 { pw(" " as *u8); pw(nm as *u8); pw(" RED\n" as *u8); return 0 }
29func stamp(path: *u8, s: *u8) -> i64 {
30 let fd: i64 = sys_openat_wr(path, GG_FMODE)
31 if fd < 0 { return 0-1 }
32 var n: i64=0; while s[n]!=(0 as u8){n=n+1}
33 sys_write(fd, s, n)
34 sys_fsync(fd); sys_close(fd)
35 return 0
36}
37
38func main(argc: i64, argv: *i64) -> i64 {
39 pw("=== nx_genome_gate: is breeding INHERITANCE, or a reroll with extra steps? ===\n\n" as *u8)
40 var pass: i64 = 0
41 let pa: *i64 = sys_mmap(GN_LEN*8) as *i64
42 let pb: *i64 = sys_mmap(GN_LEN*8) as *i64
43 gn_wild(pa, 11, GN_ADULT_AGE)
44 gn_wild(pb, 22, GN_ADULT_AGE)
45 let ch: *i64 = sys_mmap(GN_LEN*8) as *i64
46 let c2: *i64 = sys_mmap(GN_LEN*8) as *i64
47
48 // T1 determinism
49 gn_breed(pa, pb, 7, ch)
50 gn_breed(pa, pb, 7, c2)
51 var t1: i64 = 0
52 if gn_ck(ch) == gn_ck(c2) { if gn_ck(ch) != 0 { t1 = 1 } }
53 if t1==1 { pass=pass+1; line_g("T1 deterministic: same parents+seed -> bit-identical child" as *u8) }
54 if t1==0 { line_r("T1 deterministic: same parents+seed -> bit-identical child" as *u8) }
55
56 // T2 bounded heritability: child trait within the parents' span widened by <= the mutation step
57 var viol: i64 = 0
58 var k: i64 = 0
59 while k < GG_BOUND_N {
60 gn_breed(pa, pb, 100+k, ch)
61 var t: i64 = 0
62 while t < GN_NT {
63 if t != GN_T_SPECIES {
64 var lo: i64 = gn_get(pa,t)
65 var hi: i64 = gn_get(pb,t)
66 if hi < lo { let sw: i64 = lo; lo = hi; hi = sw }
67 let m: i64 = gn_mut(t)
68 let v: i64 = gn_get(ch,t)
69 if v < lo-m { viol = viol + 1 }
70 if v > hi+m { viol = viol + 1 }
71 }
72 t = t + 1
73 }
74 k = k + 1
75 }
76 var t2: i64 = 0
77 if viol == 0 { t2 = 1 }
78 if t2==1 { pass=pass+1; line_g("T2 bounded heritability: 200 breedings, 0 traits outside parent-span+step" as *u8) }
79 if t2==0 { line_r("T2 bounded heritability" as *u8) }
80 pw(" span violations=" as *u8); pn(viol); pw("\n" as *u8)
81
82 // T3 uniqueness: the 0-dup law -- 100 seeds, 100 distinct children
83 let cks: *i64 = sys_mmap(GG_BREED_N*8) as *i64
84 var dup: i64 = 0
85 k = 0
86 while k < GG_BREED_N {
87 gn_breed(pa, pb, 1000+k, ch)
88 cks[k] = gn_ck(ch)
89 var j: i64 = 0
90 while j < k { if cks[j] == cks[k] { dup = dup + 1 } j = j + 1 }
91 k = k + 1
92 }
93 var t3: i64 = 0
94 if dup == 0 { t3 = 1 }
95 if t3==1 { pass=pass+1; line_g("T3 unique offspring: 100 seeds -> 100 distinct children (0-dup law)" as *u8) }
96 if t3==0 { line_r("T3 unique offspring" as *u8) }
97 pw(" duplicates=" as *u8); pn(dup); pw("\n" as *u8)
98
99 // T4 FLAGSHIP: the adult invariant, fail-closed, output bit-untouched
100 let pm: *i64 = sys_mmap(GN_LEN*8) as *i64
101 gn_wild(pm, 33, GN_ADULT_AGE - 2) // a minor
102 var i: i64 = 0
103 while i < GN_LEN { ch[i] = GG_SENT; i = i + 1 }
104 let rcm: i64 = gn_breed(pa, pm, 7, ch)
105 var sent_ok: i64 = 1
106 i = 0
107 while i < GN_LEN { if ch[i] != GG_SENT { sent_ok = 0 } i = i + 1 }
108 // and the emitted child of two ADULTS is adult BY CONSTRUCTION
109 gn_breed(pa, pb, 7, c2)
110 var t4: i64 = 0
111 if rcm == GN_E_MINOR { if sent_ok == 1 { if c2[GN_F_AGE] == GN_ADULT_AGE { t4 = 1 } } }
112 if t4==1 { pass=pass+1; line_g("T4 ADULT INVARIANT: minor parent REFUSED output-untouched; children adult by construction" as *u8) }
113 if t4==0 { line_r("T4 ADULT INVARIANT: minor parent REFUSED output-untouched; children adult by construction" as *u8) }
114 pw(" rc=" as *u8); pn(rcm); pw(" sentinel-intact=" as *u8); pn(sent_ok)
115 pw(" child-age=" as *u8); pn(c2[GN_F_AGE]); pw("\n" as *u8)
116
117 // T5 generational bounds: 25 chained generations never leave legal ranges
118 let ga: *i64 = sys_mmap(GN_LEN*8) as *i64
119 let gb: *i64 = sys_mmap(GN_LEN*8) as *i64
120 var w: i64 = 0
121 while w < GN_LEN { ga[w] = pa[w]; gb[w] = pb[w]; w = w + 1 }
122 var oob: i64 = 0
123 k = 0
124 while k < GG_GEN_N {
125 gn_breed(ga, gb, 5000+k, ch)
126 var t: i64 = 0
127 while t < GN_NT {
128 if gn_get(ch,t) < gn_lo(t) { oob = oob + 1 }
129 if gn_get(ch,t) > gn_hi(t) { oob = oob + 1 }
130 t = t + 1
131 }
132 w = 0
133 while w < GN_LEN { ga[w] = gb[w]; gb[w] = ch[w]; w = w + 1 }
134 k = k + 1
135 }
136 var t5: i64 = 0
137 if oob == 0 { t5 = 1 }
138 if t5==1 { pass=pass+1; line_g("T5 generational bounds: 25 chained generations, 0 traits out of range" as *u8) }
139 if t5==0 { line_r("T5 generational bounds" as *u8) }
140
141 // T6 save round-trip through the certified save part (compose-forever)
142 gn_breed(pa, pb, 7, ch)
143 gs_save("knowledge/nx_genome_child.sav" as *u8, GN_SCHEMA, ch, GN_LEN, GG_SAVEAT)
144 let lo6: *i64 = sys_mmap(GN_LEN*8) as *i64
145 let meta: *i64 = sys_mmap(8*8) as *i64
146 let lrc: i64 = gs_load("knowledge/nx_genome_child.sav" as *u8, lo6, GN_LEN, meta)
147 var t6: i64 = 0
148 if lrc == GN_LEN { if gn_ck(lo6) == gn_ck(ch) { t6 = 1 } }
149 if t6==1 { pass=pass+1; line_g("T6 child rides nx_gamesave bit-exact (parts compose)" as *u8) }
150 if t6==0 { line_r("T6 child rides nx_gamesave bit-exact (parts compose)" as *u8) }
151
152 // T7 ANTI-VACUITY: breeding MIXES and INHERITS. Children must (a) sometimes differ from both
153 // parents, and (b) sit closer to the mid-parent than an unrelated wild genome does.
154 var differ: i64 = 0
155 var dchild: i64 = 0
156 var dwild: i64 = 0
157 let wg: *i64 = sys_mmap(GN_LEN*8) as *i64
158 k = 0
159 while k < GG_BREED_N {
160 gn_breed(pa, pb, 9000+k, ch)
161 if gn_dist(ch, pa) > 0 { if gn_dist(ch, pb) > 0 { differ = differ + 1 } }
162 dchild = dchild + gn_dist(ch, pa) + gn_dist(ch, pb)
163 gn_wild(wg, 70000+k, GN_ADULT_AGE)
164 dwild = dwild + gn_dist(wg, pa) + gn_dist(wg, pb)
165 k = k + 1
166 }
167 var t7: i64 = 0
168 if differ * 10 >= GG_BREED_N * 3 { if dchild * 2 < dwild { t7 = 1 } }
169 if t7==1 { pass=pass+1; line_g("T7 ANTI-VACUITY: children vary AND are 2x+ closer to parents than wild genomes" as *u8) }
170 if t7==0 { line_r("T7 ANTI-VACUITY: children vary AND are 2x+ closer to parents than wild genomes" as *u8) }
171 pw(" differ-from-both=" as *u8); pn(differ); pw("/" as *u8); pn(GG_BREED_N)
172 pw(" child-dist-sum=" as *u8); pn(dchild); pw(" wild-dist-sum=" as *u8); pn(dwild); pw("\n" as *u8)
173
174 // T8 morph: ONLY the target trait moves, clamped; invalid trait REFUSED
175 gn_breed(pa, pb, 7, ch)
176 i = 0
177 while i < GN_LEN { c2[i] = ch[i]; i = i + 1 }
178 gn_morph(ch, GN_T_MUSC, 5000) // clamps at hi
179 var others_ok: i64 = 1
180 i = 0
181 while i < GN_LEN { if i != GN_O_TRAIT + GN_T_MUSC { if ch[i] != c2[i] { others_ok = 0 } } i = i + 1 }
182 let rbad: i64 = gn_morph(ch, GN_NT + 3, 1)
183 var t8: i64 = 0
184 if others_ok == 1 { if gn_get(ch, GN_T_MUSC) == gn_hi(GN_T_MUSC) { if rbad == GN_E_TRAIT { t8 = 1 } } }
185 if t8==1 { pass=pass+1; line_g("T8 morph: one trait moves (clamped), all other words bit-identical; bad trait REFUSED" as *u8) }
186 if t8==0 { line_r("T8 morph: one trait moves (clamped), all other words bit-identical; bad trait REFUSED" as *u8) }
187
188 pw("\n=== nx_genome_gate " as *u8); pn(pass); pw("/8 " as *u8)
189 if pass==8 { pw("GREEN ===\n" as *u8) }
190 if pass!=8 { pw("RED ===\n" as *u8); return 1 }
191 stamp("knowledge/nx_genome_proof.txt" as *u8,
192 "nx_genome 8/8 GREEN. Breeding is INHERITANCE, proven: deterministic per (parents,seed); every child trait within the parents' span + one mutation step (200 breedings, 0 violations); 100 seeds -> 100 distinct children (0-dup law); 25 chained generations never leave legal bounds; children 2x+ closer to parents than wild genomes while still varying. ADULT INVARIANT FAIL-CLOSED: a minor parent refuses with output bit-untouched, and every emitted child is adult by construction. Morph = bounded single-trait delta (the transformation mechanism). Child rides nx_gamesave bit-exact.\n" as *u8)
193 return 0
194}