code wiki / _hdl_build / nx_source_grade_gate.nx
nx_source_grade_gate.nx source
↩ module page · 111 lines · 6248 B
1// nx_source_grade_gate.nx -- ENGINEER gate for the SOURCE-CRITICISM organ (RACI: Builder authored
2// nx_source_grade.nx, Engineer verifies here, Doctor heals on RED). KATs prove: the Admiralty
3// cannot-judge states never act, the independence rule rejects echo-pairs and rewards opposed
4// agreement, the score is monotone in every axis, the ICD-203 bands and the confidence/likelihood
5// separation law hold, and grading is deterministic. Hand-computed expectations throughout.
6// license_tier: ORIGINAL
7import "nx_source_grade.nx"
8import "nx_syscalls.nx"
9
10func sgg_wf(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 }
11func sgg_wnf(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 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(fd,bb,k); return 0 }
12func sgg_w(s: *u8) -> i64 { return sgg_wf(1, s) }
13func sgg_wn(v: i64) -> i64 { return sgg_wnf(1, v) }
14
15func main() -> i64 {
16 let r: *i64 = sys_mmap(8*40) as *i64
17 var t: i64 = 0
18
19 // KAT1: the best source there is -- A1, primary, measured record -> full marks, actionable
20 r[t]=0; if sg_score_permil(1,1,1,5) == 1000 { r[t]=1 } t=t+1
21 r[t]=0; if sg_actionable(1,1) == 1 { r[t]=1 } t=t+1
22
23 // KAT2: F6 cannot-judge -> score 0, NEVER actionable, owes a fetch-task (honest, not middling)
24 r[t]=0; if sg_score_permil(6,6,3,1) == 0 { r[t]=1 } t=t+1
25 r[t]=0; if sg_actionable(6,6) == 0 { r[t]=1 } t=t+1
26 r[t]=0; if sg_fetch_owed(6,2) == 1 { r[t]=1 } t=t+1
27 r[t]=0; if sg_fetch_owed(2,6) == 1 { r[t]=1 } t=t+1
28 r[t]=0; if sg_fetch_owed(2,2) == 0 { r[t]=1 } t=t+1
29 // D/E reliability or 4/5 credibility: graded (nonzero) but not actionable
30 r[t]=0; if sg_actionable(4,2) == 0 { r[t]=1 } t=t+1
31 r[t]=0; if sg_actionable(2,4) == 0 { r[t]=1 } t=t+1
32
33 // KAT3: invalid grades fail LOUD (-1), never a silent zero
34 r[t]=0; if sg_score_permil(0,1,1,5) == 0-1 { r[t]=1 } t=t+1
35 r[t]=0; if sg_score_permil(1,7,1,5) == 0-1 { r[t]=1 } t=t+1
36 r[t]=0; if sg_score_permil(1,1,4,5) == 0-1 { r[t]=1 } t=t+1
37 r[t]=0; if sg_score_permil(1,1,1,6) == 0-1 { r[t]=1 } t=t+1
38
39 // KAT4: MONOTONE -- degrading any single axis from the apex lowers the score
40 r[t]=0; if sg_score_permil(2,1,1,5) == 800 { r[t]=1 } t=t+1 // reliability A->B
41 r[t]=0; if sg_score_permil(1,2,1,5) == 800 { r[t]=1 } t=t+1 // credibility 1->2
42 r[t]=0; if sg_score_permil(1,1,2,5) == 850 { r[t]=1 } t=t+1 // primary->secondary
43 r[t]=0; if sg_score_permil(1,1,1,4) == 850 { r[t]=1 } t=t+1 // measured->systematic
44
45 // KAT5: the INDEPENDENCE RULE -- echo-pair rejected, cross-class accepted, opposed strongest
46 let cls: *i64 = sys_mmap(8*8) as *i64
47 cls[0]=1; cls[1]=1
48 r[t]=0; if sg_distinct(cls, 2) == 1 { r[t]=1 } t=t+1
49 r[t]=0; if sg_strength(sg_distinct(cls,2), 0) == SG_ECHO { r[t]=1 } t=t+1 // two echoes != corroboration
50 cls[1]=2
51 r[t]=0; if sg_distinct(cls, 2) == 2 { r[t]=1 } t=t+1
52 r[t]=0; if sg_strength(2, 0) == SG_CORROB { r[t]=1 } t=t+1
53 r[t]=0; if sg_strength(2, 1) == SG_OPPOSED { r[t]=1 } t=t+1 // opposed agreement = strongest
54 r[t]=0; if sg_has_opposed(cls, 2, 1, 2) == 1 { r[t]=1 } t=t+1
55 cls[1]=3
56 r[t]=0; if sg_has_opposed(cls, 2, 1, 2) == 0 { r[t]=1 } t=t+1
57 r[t]=0; if sg_independent(4, 4) == 0 { r[t]=1 } t=t+1
58 r[t]=0; if sg_independent(4, 5) == 1 { r[t]=1 } t=t+1
59 // distinct over a longer list: 5,5,7,5,9 -> 3 classes
60 cls[0]=5; cls[1]=5; cls[2]=7; cls[3]=5; cls[4]=9
61 r[t]=0; if sg_distinct(cls, 5) == 3 { r[t]=1 } t=t+1
62
63 // KAT6: ICD-203 confidence from the weakest admitted link; echo evidence is ALWAYS LOW
64 r[t]=0; if sg_confidence(SG_ECHO, 999) == SG_CONF_LOW { r[t]=1 } t=t+1
65 r[t]=0; if sg_confidence(SG_CORROB, 820) == SG_CONF_HIGH { r[t]=1 } t=t+1
66 r[t]=0; if sg_confidence(SG_CORROB, 640) == SG_CONF_MED { r[t]=1 } t=t+1
67 r[t]=0; if sg_confidence(SG_CORROB, 499) == SG_CONF_LOW { r[t]=1 } t=t+1
68 r[t]=0; if sg_confidence(SG_OPPOSED, 820) == SG_CONF_HIGH { r[t]=1 } t=t+1
69
70 // KAT7: ICD-203 estimative bands -- every edge hand-checked
71 r[t]=0; if sg_wep_band(50) == 1 { r[t]=1 } t=t+1
72 r[t]=0; if sg_wep_band(51) == 2 { r[t]=1 } t=t+1
73 r[t]=0; if sg_wep_band(200) == 2 { r[t]=1 } t=t+1
74 r[t]=0; if sg_wep_band(451) == 4 { r[t]=1 } t=t+1
75 r[t]=0; if sg_wep_band(551) == 5 { r[t]=1 } t=t+1
76 r[t]=0; if sg_wep_band(801) == 6 { r[t]=1 } t=t+1
77 r[t]=0; if sg_wep_band(951) == 7 { r[t]=1 } t=t+1
78
79 // KAT8: the SEPARATION LAW -- confidence + likelihood in one sentence is ILLEGAL
80 r[t]=0; if sg_separation_ok(1) == 0 { r[t]=1 } t=t+1
81 r[t]=0; if sg_separation_ok(0) == 1 { r[t]=1 } t=t+1
82
83 // KAT9: real Case-001 source grades, hand-computed (the case module must match these)
84 r[t]=0; if sg_score_permil(3,3,3,3) == 163 { r[t]=1 } t=t+1 // S1 lead-gen price guide
85 r[t]=0; if sg_score_permil(2,2,2,4) == 462 { r[t]=1 } t=t+1 // S5 200+ P&L aggregation
86 r[t]=0; if sg_score_permil(1,2,1,5) == 800 { r[t]=1 } t=t+1 // S7 SEC filing
87
88 // KAT10: determinism
89 r[t]=0; if sg_is_reproducible(2,2,2,4) == 1 { r[t]=1 } t=t+1
90
91 var pass: i64 = 0
92 var i: i64 = 0
93 while i < t { pass = pass + r[i]; i = i + 1 }
94 sgg_w("=== SOURCE-GRADE GATE (Engineer): Admiralty 6x6, independence rule, ICD-203 laws ===\n" as *u8)
95 var j: i64 = 0
96 while j < t {
97 if r[j] == 0 { sgg_w(" FAIL kat#" as *u8); sgg_wn(j); sgg_w("\n" as *u8) }
98 j = j + 1
99 }
100 sgg_w(" passed " as *u8); sgg_wn(pass); sgg_w("/" as *u8); sgg_wn(t); sgg_w("\n" as *u8)
101 // durable anchor for the Examiner's arc table
102 let dfd: i64 = sys_openat_append("knowledge/status/analyst_sources_gate.log" as *u8, 0x1a4)
103 if dfd >= 0 {
104 if pass == t { sgg_wf(dfd, "SRCGRADE-GATE verdict=GREEN " as *u8) }
105 if pass != t { sgg_wf(dfd, "SRCGRADE-GATE verdict=RED " as *u8) }
106 sgg_wnf(dfd, pass); sgg_wf(dfd, "/" as *u8); sgg_wnf(dfd, t); sgg_wf(dfd, "\n" as *u8)
107 sys_close(dfd)
108 }
109 if pass == t { sys_exit(0); return 0 }
110 sys_exit(1); return 1
111}