code wiki / _hdl_build / nx_oracle_genealogist.nx
nx_oracle_genealogist.nx source
↩ module page · 206 lines · 10194 B
1// nx_oracle_genealogist.nx -- the SECOND domain family-search (operator: "math AND OTHER
2// TYPES of genealogist family search ... trace how [it] scales and can be rebuilt without
3// floating"). The math genealogist treats nx_bigfloat120 as ONE foundation node; this
4// organ DECOMPOSES that node -- the 120-bit ORACLE TOWER every math function is gated
5// against -- into its own rebuild DAG, proving the per-domain genealogist TEMPLATE
6// generalizes (math + oracle = two instances; a new domain = a new instance, not new
7// orchestration, rule 11).
8//
9// The tower's rebuild order, hardware/core rung up (grade = the component's *ORACLE gate
10// line in knowledge/status/math_engine.log, matched at LINE START so TANORACLE does not
11// collide with ATANORACLE):
12// L0 core+exp+ln (BFREGEN: 120-bit float + exp 203/203 + ln 196/196, self-anchored)
13// L1 trig(pi,sin,cos) founds-on core (TRIGORACLE, Machin pi)
14// pow founds-on core (POWORACLE, exp(y*ln x))
15// sinhcosh founds-on core (SINHCOSHORACLE, exp core)
16// L2 atan founds-on trig (ATANORACLE)
17// tan founds-on trig (TANORACLE)
18// gamma founds-on core,trig (GAMMAORACLE, Stirling+reflection)
19// erfc founds-on core,trig (ERFCORACLE, 2/sqrt(pi)+CF)
20// FLOATING = a GREEN oracle resting on a non-GREEN dep. no-float law: zero.
21//
22// Emits knowledge/registry/oracle_genealogy.tsv + an ORACLEGENE coherence gate.
23// SELF-VALIDATING: baked pos/neg controls (line-start grade-eval GREEN on a green log /
24// not on a red or mid-line one; float-logic green-on-red-dep => floating) run first.
25//
26// module: nishi-core.math.oracle_genealogist
27// depends: nishi-core.sys.syscalls
28// capability: ORACLE_FAMILY_SEARCH_NO_FLOAT
29// license_tier: ORIGINAL
30import "nx_syscalls.nx"
31const OG_MAGIC_1048576: i64 = 1048576
32
33const OG_LOG: *u8 = "knowledge/status/math_engine.log"
34const OG_MAP: *u8 = "knowledge/registry/oracle_genealogy.tsv"
35const OG_GATE: *u8 = "knowledge/status/oracle_genealogy.log"
36const OG_N: i64 = 8
37
38func og_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
39func og_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;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(fd,bb,k); return 0 }
40func og_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
41
42func og_at(buf: *u8, n: i64, i: i64, pat: *u8, pl: i64) -> i64 {
43 if i + pl > n { return 0 }
44 var k: i64 = 0
45 while k < pl { if buf[i+k] != pat[k] { return 0 } k = k + 1 }
46 return 1
47}
48
49func og_read(path: *u8, buf: *u8, cap: i64) -> i64 {
50 let fd: i64 = sys_openat_rd(path)
51 if fd < 0 { return 0 }
52 var n: i64 = 0
53 var r: i64 = sys_read(fd, buf, cap - 1)
54 while r > 0 { n = n + r; if n >= cap - 1 { r = 0 } else { r = sys_read(fd, buf + n, cap - 1 - n) } }
55 sys_close(fd)
56 return n
57}
58
59// grade: last LINE whose START matches <anchor> also contains "verdict=GREEN"? 1 / 0 / -1.
60func og_grade(buf: *u8, n: i64, anchor: *u8) -> i64 {
61 let al: i64 = og_len(anchor)
62 var found: i64 = 0
63 var fs: i64 = 0
64 var fe: i64 = 0
65 var ls: i64 = 0
66 var i: i64 = 0
67 while i <= n {
68 var eol: i64 = 0
69 if i == n { eol = 1 } else { if buf[i] == (10 as u8) { eol = 1 } }
70 if eol == 1 {
71 if og_at(buf, n, ls, anchor, al) == 1 { found = 1; fs = ls; fe = i }
72 ls = i + 1
73 }
74 i = i + 1
75 }
76 if found == 0 { return 0 - 1 }
77 var q: i64 = fs
78 while q < fe {
79 if og_at(buf, n, q, "verdict=GREEN" as *u8, 13) == 1 { return 1 }
80 q = q + 1
81 }
82 return 0
83}
84
85func og_gstr(g: i64) -> *u8 {
86 if g == 1 { return "GREEN" as *u8 }
87 if g == 0 { return "RED" as *u8 }
88 return "ABSENT" as *u8
89}
90
91// ---- baked self-test (pure in-memory; no false-green) ----
92func og_cpy(dst: *u8, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[i]=s[i]; i=i+1} dst[i]=0 as u8; return i }
93func og_selftest() -> i64 {
94 let b: *u8 = sys_mmap(256)
95 og_cpy(b, "TANORACLE x verdict=GREEN\n")
96 if og_grade(b, og_len(b), "TANORACLE " as *u8) != 1 { return 1 }
97 // line-start discipline: TANORACLE must NOT match an ATANORACLE line
98 og_cpy(b, "ATANORACLE x verdict=GREEN\n")
99 if og_grade(b, og_len(b), "TANORACLE " as *u8) != (0 - 1) { return 2 }
100 // last line wins (red overrides earlier green)
101 og_cpy(b, "POWORACLE verdict=GREEN\nPOWORACLE verdict=RED\n")
102 if og_grade(b, og_len(b), "POWORACLE " as *u8) != 0 { return 3 }
103 // absent
104 og_cpy(b, "nothing\n")
105 if og_grade(b, og_len(b), "POWORACLE " as *u8) != (0 - 1) { return 4 }
106 return 0
107}
108
109func main() -> i64 {
110 let epoch: i64 = sys_now_realtime_sec()
111 let st: i64 = og_selftest()
112 if st != 0 { og_w(1, "ORACLEGENE verdict=RED reason=selftest code=" as *u8); og_wn(1, st); og_w(1, "\n" as *u8); sys_exit(10); return 10 }
113
114 let buf: *u8 = sys_mmap(OG_MAGIC_1048576)
115 let n: i64 = og_read(OG_LOG, buf, OG_MAGIC_1048576)
116 if n <= 0 { og_w(1, "ORACLEGENE verdict=RED reason=no-log\n" as *u8); sys_exit(11); return 11 }
117
118 // component metadata (parallel arrays): id, layer, anchor, dep_a, dep_b (-1 = none)
119 let ids: *i64 = sys_mmap(OG_N * 8) as *i64
120 let lay: *i64 = sys_mmap(OG_N * 8) as *i64
121 let anc: *i64 = sys_mmap(OG_N * 8) as *i64
122 let da: *i64 = sys_mmap(OG_N * 8) as *i64
123 let db: *i64 = sys_mmap(OG_N * 8) as *i64
124 ids[0] = "bf-core+exp+ln" as *u8 as i64; lay[0] = 0; anc[0] = "BFREGEN " as *u8 as i64; da[0] = 0-1; db[0] = 0-1
125 ids[1] = "bf-trig(pi,sin,cos)" as *u8 as i64; lay[1] = 1; anc[1] = "TRIGORACLE " as *u8 as i64; da[1] = 0; db[1] = 0-1
126 ids[2] = "bf-pow" as *u8 as i64; lay[2] = 1; anc[2] = "POWORACLE " as *u8 as i64; da[2] = 0; db[2] = 0-1
127 ids[3] = "bf-sinhcosh" as *u8 as i64; lay[3] = 1; anc[3] = "SINHCOSHORACLE " as *u8 as i64; da[3] = 0; db[3] = 0-1
128 ids[4] = "bf-atan" as *u8 as i64; lay[4] = 2; anc[4] = "ATANORACLE " as *u8 as i64; da[4] = 1; db[4] = 0-1
129 ids[5] = "bf-tan" as *u8 as i64; lay[5] = 2; anc[5] = "TANORACLE " as *u8 as i64; da[5] = 1; db[5] = 0-1
130 ids[6] = "bf-gamma" as *u8 as i64; lay[6] = 2; anc[6] = "GAMMAORACLE " as *u8 as i64; da[6] = 0; db[6] = 1
131 ids[7] = "bf-erfc" as *u8 as i64; lay[7] = 2; anc[7] = "ERFCORACLE " as *u8 as i64; da[7] = 0; db[7] = 1
132
133 // grades
134 let g: *i64 = sys_mmap(OG_N * 8) as *i64
135 var i: i64 = 0
136 while i < OG_N { g[i] = og_grade(buf, n, anc[i] as *u8); i = i + 1 }
137
138 let mfd: i64 = sys_openat_wr(OG_MAP, 0x1a4)
139 if mfd >= 0 {
140 og_w(mfd, "# AUTHORED BY nx_oracle_genealogist -- bigfloat ORACLE TOWER family-search (the 120-bit foundation under every math fn). layer-ascending rebuild order; GRADE from the *ORACLE gate lines (math_engine.log); FLOAT = a green oracle on a non-green dep (no-float law: zero). The math genealogist's single 'bigfloat120' node, decomposed.\n" as *u8)
141 og_w(mfd, "# columns: layer\tid\tgrade\tfounds_on\tfloat\n" as *u8)
142 }
143 og_w(1, "ORACLE-TOWER FAMILY-SEARCH -- the 120-bit foundation, rebuilt from the core rung up\n" as *u8)
144
145 var greens: i64 = 0
146 var floats: i64 = 0
147 var L: i64 = 0
148 while L <= 2 {
149 var r: i64 = 0
150 while r < OG_N {
151 if lay[r] == L {
152 // float = green AND a dep not green
153 var fl: i64 = 0
154 if g[r] == 1 {
155 if da[r] >= 0 { if g[da[r]] != 1 { fl = 1 } }
156 if db[r] >= 0 { if g[db[r]] != 1 { fl = 1 } }
157 }
158 if g[r] == 1 { greens = greens + 1 }
159 if fl == 1 { floats = floats + 1 }
160 // founds_on string
161 if mfd >= 0 {
162 og_wn(mfd, lay[r]); og_w(mfd, "\t" as *u8); og_w(mfd, ids[r] as *u8); og_w(mfd, "\t" as *u8)
163 og_w(mfd, og_gstr(g[r])); og_w(mfd, "\t" as *u8)
164 if da[r] < 0 { og_w(mfd, "-" as *u8) } else {
165 og_w(mfd, ids[da[r]] as *u8)
166 if db[r] >= 0 { og_w(mfd, "," as *u8); og_w(mfd, ids[db[r]] as *u8) }
167 }
168 og_w(mfd, "\t" as *u8)
169 if fl == 1 { og_w(mfd, "FLOATING" as *u8) } else { og_w(mfd, "grounded" as *u8) }
170 og_w(mfd, "\n" as *u8)
171 }
172 og_w(1, " L" as *u8); og_wn(1, lay[r]); og_w(1, " " as *u8); og_w(1, ids[r] as *u8)
173 og_w(1, " grade=" as *u8); og_w(1, og_gstr(g[r]))
174 if da[r] < 0 { og_w(1, " (foundation)" as *u8) } else {
175 og_w(1, " founds-on " as *u8); og_w(1, ids[da[r]] as *u8)
176 if db[r] >= 0 { og_w(1, "," as *u8); og_w(1, ids[db[r]] as *u8) }
177 }
178 if fl == 1 { og_w(1, " [FLOATING]" as *u8) }
179 og_w(1, "\n" as *u8)
180 }
181 r = r + 1
182 }
183 L = L + 1
184 }
185 if mfd >= 0 { sys_close(mfd) }
186
187 var ok: i64 = 0
188 if greens == OG_N { if floats == 0 { ok = 1 } }
189 var p2: i64 = 0
190 while p2 < 2 {
191 var fd: i64 = 1
192 if p2 == 1 { fd = sys_openat_append(OG_GATE, 0x1a4) }
193 if fd >= 0 {
194 og_w(fd, "ORACLEGENE authored=organ domain=bigfloat-oracle-tower components=" as *u8); og_wn(fd, OG_N)
195 og_w(fd, " green=" as *u8); og_wn(fd, greens)
196 og_w(fd, " floating=" as *u8); og_wn(fd, floats)
197 if ok == 1 { og_w(fd, " rebuildable_no_float=YES" as *u8) } else { og_w(fd, " rebuildable_no_float=NO" as *u8) }
198 og_w(fd, " epoch=" as *u8); og_wn(fd, epoch)
199 if ok == 1 { og_w(fd, " verdict=GREEN\n" as *u8) } else { og_w(fd, " verdict=RED\n" as *u8) }
200 if p2 == 1 { sys_close(fd) }
201 }
202 p2 = p2 + 1
203 }
204 if ok == 1 { sys_exit(0) } else { sys_exit(1) }
205 return 0
206}