nx_slopmeter_gate.nx source
↩ module page · 119 lines · 6431 B
1// nx_slopmeter_gate.nx -- REFEREE for nx_slopmeter_lib (output repetition measurement).
2//
3// THE HARD PART IS PROVING A METER WITHOUT INVENTING A THRESHOLD. Any cutoff I picked here would be
4// a magic number wearing a gate's authority. So the teeth are ORDERING and IDENTITY properties,
5// which a broken meter cannot satisfy and which need no constant:
6//
7// [T1] u2605BITE: fires on looped text, silent on varied text -- the whole claim, stated once.
8// [T2] MONOTONE: looped scores STRICTLY above varied. A meter that ranks them equal is useless
9// even if both numbers look plausible.
10// [T3] floor: text with no repeated 3-gram scores exactly 0 -- not "small", 0.
11// [T4] ceiling: text that is one phrase looped scores the full scale. Both ends pinned means the
12// scale is real and not a squashed middle.
13// [T5] u2605the 2-gram trap: "she said ... she said" repeats a BIGRAM but no trigram. A 2-gram meter
14// would condemn ordinary prose; this must read 0 and prove the width choice is load-bearing.
15// [T6] tokenizer counts words, not bytes, and treats an apostrophe as interior.
16// [T7] u2605NEG-CONTROL: text too short to contain a window returns SM_UNMEASURABLE, never 0 --
17// "no measurement was possible" must not be averaged in as "clean".
18// [T8] distinct-vocabulary is an INDEPENDENT axis: all-unique text is 1000 permil, one word
19// repeated is a small fraction of it.
20// [T9] case-insensitivity: "The Map" and "the map" are the same phrase repeated.
21//
22// Hermetic: in-memory fixtures, no filesystem, no engine, no network.
23// Sovereign x86_64. license_tier: ORIGINAL expect_exit: 0
24import "nx_gate_verdict.nx"
25import "nx_slopmeter_lib.nx"
26
27const SG_TOKCAP: i64 = 4096
28
29func sq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 }
30
31// measure a NUL-terminated fixture; returns repetition permil
32func sg_rep(s: *u8) -> i64 {
33 let n: i64 = tx_len(s)
34 let st: *i64 = sys_mmap(SG_TOKCAP * 8) as *i64
35 let ln: *i64 = sys_mmap(SG_TOKCAP * 8) as *i64
36 let nt: i64 = sm_tokenize(s, n, st, ln, SG_TOKCAP)
37 return sm_repeat_permil(s, st, ln, nt)
38}
39func sg_dist(s: *u8) -> i64 {
40 let n: i64 = tx_len(s)
41 let st: *i64 = sys_mmap(SG_TOKCAP * 8) as *i64
42 let ln: *i64 = sys_mmap(SG_TOKCAP * 8) as *i64
43 let nt: i64 = sm_tokenize(s, n, st, ln, SG_TOKCAP)
44 return sm_distinct_permil(s, st, ln, nt)
45}
46func sg_ntok(s: *u8) -> i64 {
47 let n: i64 = tx_len(s)
48 let st: *i64 = sys_mmap(SG_TOKCAP * 8) as *i64
49 let ln: *i64 = sys_mmap(SG_TOKCAP * 8) as *i64
50 return sm_tokenize(s, n, st, ln, SG_TOKCAP)
51}
52
53func main(argc: i64, argv: *i64) -> i64 {
54 let ctr: *i64 = gv_ctr()
55 gv_head("NX-SLOPMETER-GATE -- measures the OUTPUT, not the registry: degenerate self-repetition" as *u8)
56
57 // varied prose: no trigram occurs twice
58 let varied: *u8 = "the cartographer folded her map while rain moved across a grey harbour and someone counted boats" as *u8
59 // looped prose: the failure mode of a small model at a long token budget
60 let looped: *u8 = "he walked to the door he walked to the door he walked to the door he walked to the door" as *u8
61
62 let rv: i64 = sg_rep(varied)
63 let rl: i64 = sg_rep(looped)
64
65 // u2605T1 BITE: the meter must FIRE on the loop and stay SILENT on the varied text.
66 var fires: i64 = 0
67 if rl > 0 { fires = 1 }
68 var quiet: i64 = 0
69 if rv > 0 { quiet = 1 }
70 gv_bite("T1 repetition detector (looped vs varied)" as *u8, fires, quiet, ctr)
71
72 // T2 MONOTONE -- the property that makes the number usable for ranking
73 var mono: i64 = 0
74 if rl > rv { mono = 1 }
75 gv_check("T2 looped scores strictly above varied" as *u8, mono, ctr)
76
77 // T3/T4 both ends of the scale are pinned
78 gv_check("T3 floor: varied text is exactly 0 permil" as *u8, sq(rv, 0), ctr)
79 // u26a0T4 ORIGINALLY ASSERTED THE 5-WORD LOOP WOULD SCORE 1000, AND THAT WAS ARITHMETICALLY
80 // IMPOSSIBLE -- the first cycle's trigrams are genuinely novel, so "he walked to the door" x4 is
81 // 20 tokens -> 18 windows -> 13 repeats of 17 candidates = 764 permil. The meter was right and
82 // the EXPECTATION was wrong. u2605u2605u2605u2605u2605A RED FROM A TEST THAT ENCODES AN IMPOSSIBLE EXPECTATION IS A
83 // DEFECT IN THE RULER, AND "FIXING" THE ORGAN TO SATISFY IT WOULD HAVE BROKEN A CORRECT METER.
84 // The true ceiling is a SINGLE token repeated -- every window is the same trigram, so only the
85 // first is novel and the ratio is exactly 1.
86 gv_check("T4 ceiling: one word repeated = full scale" as *u8,
87 sq(sg_rep("rain rain rain rain rain rain rain rain" as *u8), SM_PERMIL), ctr)
88 // and the phrase-loop sits high but strictly below it -- the scale has a real interior
89 var interior: i64 = 0
90 if rl > 0 { if rl < SM_PERMIL { interior = 1 } }
91 gv_check("T4b a multi-word loop is high but below the ceiling" as *u8, interior, ctr)
92
93 // u2605T5 the 2-gram trap: a repeated BIGRAM with no repeated trigram must read 0
94 let bigram: *u8 = "she said nothing and he said everything before she said goodbye" as *u8
95 gv_check("T5 repeated bigram, no repeated trigram -> 0" as *u8, sq(sg_rep(bigram), 0), ctr)
96
97 // T6 tokenizer: words not bytes, apostrophe interior
98 gv_check("T6 tokenizer counts 4 words" as *u8, sq(sg_ntok("don't stop the rain" as *u8), 4), ctr)
99
100 // u2605T7 NEG-CONTROL: unmeasurable must be distinguishable from clean
101 gv_check("T7 too short -> SM_UNMEASURABLE not 0" as *u8, sq(sg_rep("two words" as *u8), SM_UNMEASURABLE), ctr)
102
103 // T8 distinct-vocabulary is an independent axis
104 gv_check("T8 all-unique vocabulary = 1000 permil" as *u8, sq(sg_dist("alpha beta gamma delta" as *u8), SM_PERMIL), ctr)
105 var narrow: i64 = 0
106 if sg_dist("rain rain rain rain rain rain rain rain" as *u8) < SM_PERMIL { narrow = 1 }
107 gv_check("T8b one word repeated collapses vocabulary" as *u8, narrow, ctr)
108
109 // T9 case-insensitivity: the same phrase in different case is the same phrase
110 let cased: *u8 = "Into The Harbour again into the harbour again" as *u8
111 var cfire: i64 = 0
112 if sg_rep(cased) > 0 { cfire = 1 }
113 gv_check("T9 case-differing repeat is still a repeat" as *u8, cfire, ctr)
114
115 let rc: i64 = gv_verdict("SLOPMETER-GATE" as *u8, ctr,
116 "output repetition measured; monotone and both ends pinned, with no invented threshold" as *u8)
117 sys_exit(rc)
118 return rc
119}