code wiki / _hdl_build / nx_underbuilt_gate.nx
nx_underbuilt_gate.nx source
↩ module page · 136 lines · 5991 B
1// nx_underbuilt_gate.nx -- teeth for the R6 underbuilt-part signal (nx_underbuilt_lib on the REAL banked
2// NHTSA raws). T1 all 3 complaint files parse (count>=50, records>0) + 3 recall files (Count>=1) ·
3// T2 tokens >= records per file (multi-component records split) · T3 the 2013 Altima top-3 contains
4// POWER TRAIN (the known CVT signal, on real data) · T4 NEG-CONTROL: tallying a NON-JSON file (banked
5// explodeview HTML) yields 0 records / 0 distinct (no false positives) · T5 determinism: two fresh tallies
6// of the same file agree on records/tokens/ndistinct/top-count. expect_exit: 0 license_tier: ORIGINAL
7import "nx_underbuilt_lib.nx"
8
9func ubg_tooth(name: *u8, pass: i64, fails: *i64) -> i64 {
10 ubl_puts(" " as *u8); ubl_puts(name); ubl_puts(" -> " as *u8)
11 if pass == 1 { ubl_puts("PASS\n" as *u8); return 0 }
12 ubl_puts("FAIL\n" as *u8)
13 fails[0] = fails[0] + 1
14 return 0
15}
16
17func ubg_cfile(path: *u8, buf: *u8, t: *i64, fails: *i64) -> i64 {
18 let n: i64 = ubl_read(path, buf, 16777216)
19 var pass: i64 = 1
20 if n < 1000 { pass = 0 }
21 let total: i64 = ubl_key_int(buf, n, "count" as *u8, 5)
22 if total < 50 { pass = 0 }
23 let ig: i64 = ubl_reset(t)
24 let recs: i64 = ubl_tally(t, buf, n, "components" as *u8, 10)
25 if recs <= 0 { pass = 0 }
26 if t[7] < recs { pass = 0 }
27 ubl_puts(" file " as *u8); ubl_puts(path)
28 ubl_puts(" bytes=" as *u8); ubl_putn(n)
29 ubl_puts(" count=" as *u8); ubl_putn(total)
30 ubl_puts(" records=" as *u8); ubl_putn(recs)
31 ubl_puts(" tokens=" as *u8); ubl_putn(t[7])
32 ubl_puts(" distinct=" as *u8); ubl_putn(t[5]); ubl_puts("\n" as *u8)
33 return pass
34}
35
36func ubg_rfile(path: *u8, buf: *u8, t: *i64, fails: *i64) -> i64 {
37 let n: i64 = ubl_read(path, buf, 16777216)
38 var pass: i64 = 1
39 if n < 100 { pass = 0 }
40 let total: i64 = ubl_key_int(buf, n, "Count" as *u8, 5)
41 if total < 1 { pass = 0 }
42 let ig: i64 = ubl_reset(t)
43 let recs: i64 = ubl_tally(t, buf, n, "Component" as *u8, 9)
44 if recs < 1 { pass = 0 }
45 if t[5] < 1 { pass = 0 }
46 ubl_puts(" file " as *u8); ubl_puts(path)
47 ubl_puts(" recalls=" as *u8); ubl_putn(total)
48 ubl_puts(" records=" as *u8); ubl_putn(recs)
49 ubl_puts(" distinct=" as *u8); ubl_putn(t[5]); ubl_puts("\n" as *u8)
50 return pass
51}
52
53func main() -> i64 {
54 ubl_puts("=== nx_underbuilt_gate -- teeth on the REAL banked NHTSA data ===\n" as *u8)
55 let buf: *u8 = sys_mmap(16777216)
56 let arena: *u8 = sys_mmap(65536)
57 let offs: *i64 = sys_mmap(8192) as *i64
58 let lens: *i64 = sys_mmap(8192) as *i64
59 let cnts: *i64 = sys_mmap(8192) as *i64
60 let t: *i64 = sys_mmap(256) as *i64
61 t[0] = arena as i64
62 t[2] = offs as i64
63 t[3] = lens as i64
64 t[4] = cnts as i64
65 t[8] = 65536
66 let rank: *i64 = sys_mmap(1024) as *i64
67 let fails: *i64 = sys_mmap(8) as *i64
68 fails[0] = 0
69
70 ubl_puts("T1 complaint files parse (count>=50, records>0, tokens>=records):\n" as *u8)
71 let a1: i64 = ubg_cfile("knowledge/fetched/ub_alt13c.raw" as *u8, buf, t, fails)
72 let a2: i64 = ubg_cfile("knowledge/fetched/ub_crz11c.raw" as *u8, buf, t, fails)
73 let a3: i64 = ubg_cfile("knowledge/fetched/ub_civ16c.raw" as *u8, buf, t, fails)
74 var t1: i64 = 0
75 if a1 == 1 { if a2 == 1 { if a3 == 1 { t1 = 1 } } }
76 let ig1: i64 = ubg_tooth("T1 complaints parse x3" as *u8, t1, fails)
77
78 ubl_puts("T2 recall files parse (Count>=1, distinct>=1):\n" as *u8)
79 let b1: i64 = ubg_rfile("knowledge/fetched/ub_alt13r.raw" as *u8, buf, t, fails)
80 let b2: i64 = ubg_rfile("knowledge/fetched/ub_crz11r.raw" as *u8, buf, t, fails)
81 let b3: i64 = ubg_rfile("knowledge/fetched/ub_civ16r.raw" as *u8, buf, t, fails)
82 var t2: i64 = 0
83 if b1 == 1 { if b2 == 1 { if b3 == 1 { t2 = 1 } } }
84 let ig2: i64 = ubg_tooth("T2 recalls parse x3" as *u8, t2, fails)
85
86 // T3 the known 2013 Altima signal: POWER TRAIN in top-3 components (real-data witness)
87 let n3: i64 = ubl_read("knowledge/fetched/ub_alt13c.raw" as *u8, buf, 16777216)
88 let ig3: i64 = ubl_reset(t)
89 let recs3: i64 = ubl_tally(t, buf, n3, "components" as *u8, 10)
90 let m3: i64 = ubl_top(t, rank, 3)
91 var t3: i64 = 0
92 var q: i64 = 0
93 while q < m3 {
94 let idx: i64 = rank[q]
95 if idx >= 0 {
96 let hit: i64 = ubl_name_is(t, idx, "POWER TRAIN" as *u8)
97 if hit == 1 { t3 = 1 }
98 }
99 q = q + 1
100 }
101 let ig4: i64 = ubg_tooth("T3 Altima13 top-3 has POWER TRAIN" as *u8, t3, fails)
102
103 // T4 NEG-CONTROL: non-JSON file must yield 0 records / 0 distinct
104 let n4: i64 = ubl_read("knowledge/fetched/ct_explodeview.raw" as *u8, buf, 16777216)
105 let ig5: i64 = ubl_reset(t)
106 let recs4: i64 = ubl_tally(t, buf, n4, "components" as *u8, 10)
107 var t4: i64 = 0
108 if n4 > 0 { if recs4 == 0 { if t[5] == 0 { t4 = 1 } } }
109 let ig6: i64 = ubg_tooth("T4 neg-control non-JSON -> 0 records" as *u8, t4, fails)
110
111 // T5 determinism: two fresh tallies agree
112 let n5: i64 = ubl_read("knowledge/fetched/ub_alt13c.raw" as *u8, buf, 16777216)
113 let ig7: i64 = ubl_reset(t)
114 let ra: i64 = ubl_tally(t, buf, n5, "components" as *u8, 10)
115 let ta: i64 = t[7]
116 let da: i64 = t[5]
117 let ma: i64 = ubl_top(t, rank, 1)
118 let cnts5: *i64 = t[4] as *i64
119 let ia: i64 = rank[0]
120 let ca: i64 = cnts5[ia]
121 let ig8: i64 = ubl_reset(t)
122 let rb: i64 = ubl_tally(t, buf, n5, "components" as *u8, 10)
123 let tb: i64 = t[7]
124 let db: i64 = t[5]
125 let mb: i64 = ubl_top(t, rank, 1)
126 let ib: i64 = rank[0]
127 let cb: i64 = cnts5[ib]
128 var t5: i64 = 0
129 if ra == rb { if ta == tb { if da == db { if ca == cb { t5 = 1 } } } }
130 let ig9: i64 = ubg_tooth("T5 determinism (records/tokens/distinct/top-count)" as *u8, t5, fails)
131
132 ubl_puts("\nfails=" as *u8); ubl_putn(fails[0]); ubl_puts("\n" as *u8)
133 if fails[0] == 0 { ubl_puts("GREEN -- underbuilt signal teeth 5/5 on real NHTSA data\n" as *u8); return 0 }
134 ubl_puts("RED\n" as *u8)
135 return 1
136}