code wiki / (root) / nx_semruler_gate.nx

nx_semruler_gate.nx source

↩ module page · 151 lines · 7960 B

1// nx_semruler_gate.nx -- GATE for nx_semruler_lib (the semantic ruler's decision core, /compare/mediaingest). 2// license_tier: ORIGINAL 3// 4// In-process, no fixtures, no network, no filesystem: every subject is arithmetic on planted numbers, so 5// this gate cannot be poisoned by a shared fixture and has nothing to clean up. The subject is the one 6// predicate that did not already exist in the estate -- admissibility -- plus the abstention and the 7// partition, which are the two places a ruler like this normally starts lying. 8// 9// THE TWO TEETH THAT CARRY THE FILE, both written as neg-controls because a green from a subject that 10// could never go red is decoration: 11// neg-control-mirrored-duplicate-is-inadmissible 12// the obvious one-line predicate tests only the copy distance. A mirrored re-upload has a LARGE 13// copy distance and a TINY orient distance, so that version admits every mirrored duplicate and 14// re-measures tier 1 while claiming to measure semantics. This tooth plants exactly that pair 15// (copy 60, orient 2) and requires refusal. It is the tooth that fails if anyone "simplifies" 16// sr_pair_admissible back to a single argument. 17// neg-control-empty-admitted-set-abstains 18// a rate over zero subjects must be UNOBSERVABLE, never 0 and never 1000. A tooth that passes on 19// the empty set is not a tooth, and this is the direction that flatters. 20 21import "nx_syscalls.nx" 22import "nx_imgsearch_tier.nx" 23import "nx_semruler_lib.nx" 24import "nx_gate_verdict.nx" 25 26// Planted distances. Named because a bare 60 beside a bare 2 is two magic numbers in the one file whose 27// job is to stop a number being taken on trust. 28const G_FAR_COPY: i64 = 40 // comfortably above NX_IT_COPY_THRESH on both tiers: a genuine pair 29const G_FAR_ORIENT: i64 = 44 30const G_DUP_COPY: i64 = 3 // a plain near-duplicate: both tiers see it 31const G_DUP_ORIENT: i64 = 3 32const G_MIRROR_COPY: i64 = 60 // a MIRRORED duplicate: copy tier is blind to it by construction ... 33const G_MIRROR_ORIENT: i64 = 2 // ... and the dihedral-invariant tier is not. This pair is the trap. 34const G_BAD_CLASS: i64 = 99 // not NX_IT_CLASS_IDENTITY and not NX_IT_CLASS_SIMILAR 35const G_HITS: i64 = 3 36const G_ADMITTED: i64 = 4 37const G_EXPECT_PERMIL: i64 = 750 // 3/4 -- computed by hand so the assertion does not restate the code 38 39func main() -> i64 { 40 gv_head("=== nx_semruler_gate -- the semantic ruler's decision core (mediaingest) ===" as *u8) 41 let c: *i64 = gv_ctr() 42 43 // ---- the floor is the copy tier's own threshold, not a private copy of it ---- 44 var floor_shared: i64 = 0 45 if NX_IT_COPY_THRESH > 0 { floor_shared = 1 } 46 gv_check("fixture-reached-copy-threshold-is-a-positive-shared-const" as *u8, floor_shared, c) 47 gv_puts(" REPORT floor=NX_IT_COPY_THRESH=" as *u8); gv_num(NX_IT_COPY_THRESH) 48 gv_puts(" of max " as *u8); gv_num(NX_IT_COPY_MAX); gv_puts(" bits\n" as *u8) 49 50 // ---- sr_min ---- 51 var min_ok: i64 = 0 52 if sr_min(G_MIRROR_COPY, G_MIRROR_ORIENT) == G_MIRROR_ORIENT { min_ok = 1 } 53 gv_check("min-picks-the-smaller-distance" as *u8, min_ok, c) 54 55 // ---- admissibility: the genuine pair ---- 56 var adm: i64 = 0 57 if sr_pair_admissible(G_FAR_COPY, G_FAR_ORIENT) == 1 { adm = 1 } 58 gv_check("distant-pair-is-admissible" as *u8, adm, c) 59 60 // ---- neg-controls: both duplicate shapes ---- 61 var dup_refused: i64 = 0 62 if sr_pair_admissible(G_DUP_COPY, G_DUP_ORIENT) == 0 { dup_refused = 1 } 63 gv_check("neg-control-near-duplicate-is-inadmissible" as *u8, dup_refused, c) 64 65 var mirror_refused: i64 = 0 66 if sr_pair_admissible(G_MIRROR_COPY, G_MIRROR_ORIENT) == 0 { mirror_refused = 1 } 67 gv_check("neg-control-mirrored-duplicate-is-inadmissible" as *u8, mirror_refused, c) 68 69 // and prove the trap is a real trap: a copy-distance-only predicate WOULD have admitted it 70 var trap_is_real: i64 = 0 71 if G_MIRROR_COPY > NX_IT_COPY_THRESH { trap_is_real = 1 } 72 gv_check("fixture-reached-mirror-pair-would-pass-a-copy-only-predicate" as *u8, trap_is_real, c) 73 74 // ---- the boundary, in both directions: fail CLOSED exactly at the bar ---- 75 var at_bar: i64 = 0 76 if sr_pair_admissible(NX_IT_COPY_THRESH, NX_IT_COPY_THRESH) == 0 { at_bar = 1 } 77 gv_check("distance-exactly-at-the-floor-is-inadmissible-fail-closed" as *u8, at_bar, c) 78 79 var above_bar: i64 = 0 80 if sr_pair_admissible(NX_IT_COPY_THRESH + 1, NX_IT_COPY_THRESH + 1) == 1 { above_bar = 1 } 81 gv_check("distance-one-above-the-floor-is-admissible" as *u8, above_bar, c) 82 83 // ---- neg-control: an uncomputable distance is inadmissible, not admitted-by-default ---- 84 var unknown_refused: i64 = 0 85 if sr_pair_admissible(0 - 1, G_FAR_ORIENT) == 0 { 86 if sr_pair_admissible(G_FAR_COPY, 0 - 1) == 0 { unknown_refused = 1 } 87 } 88 gv_check("neg-control-unknown-distance-is-inadmissible-on-either-axis" as *u8, unknown_refused, c) 89 90 // ---- the rate ---- 91 var rate_ok: i64 = 0 92 if sr_rate_permil(G_HITS, G_ADMITTED) == G_EXPECT_PERMIL { rate_ok = 1 } 93 gv_check("rate-three-of-four-is-750-permil" as *u8, rate_ok, c) 94 95 var full_ok: i64 = 0 96 if sr_rate_permil(G_ADMITTED, G_ADMITTED) == SR_PERMIL { full_ok = 1 } 97 gv_check("rate-all-hits-is-1000-permil" as *u8, full_ok, c) 98 99 // ---- THE ABSTENTION TOOTH: zero admitted is UNOBSERVABLE, never zero ---- 100 var empty_abstains: i64 = 0 101 if sr_rate_permil(0, 0) == SR_UNOBSERVABLE { empty_abstains = 1 } 102 gv_check("neg-control-empty-admitted-set-abstains-rather-than-scoring-zero" as *u8, empty_abstains, c) 103 104 var zero_is_not_abstain: i64 = 0 105 if sr_rate_permil(0, G_ADMITTED) == 0 { zero_is_not_abstain = 1 } 106 gv_check("an-honest-zero-over-a-real-population-is-zero-not-abstention" as *u8, zero_is_not_abstain, c) 107 108 var impossible_abstains: i64 = 0 109 if sr_rate_permil(G_ADMITTED + 1, G_ADMITTED) == SR_UNOBSERVABLE { impossible_abstains = 1 } 110 gv_check("neg-control-more-hits-than-subjects-abstains-rather-than-clamping-to-1000" as *u8, impossible_abstains, c) 111 112 // ---- class reading ---- 113 var sim_ok: i64 = 0 114 if sr_hit_is_semantic(NX_IT_CLASS_SIMILAR) == 1 { 115 if sr_hit_is_identity(NX_IT_CLASS_SIMILAR) == 0 { sim_ok = 1 } 116 } 117 gv_check("similar-class-reads-semantic-and-not-identity" as *u8, sim_ok, c) 118 119 var id_ok: i64 = 0 120 if sr_hit_is_identity(NX_IT_CLASS_IDENTITY) == 1 { 121 if sr_hit_is_semantic(NX_IT_CLASS_IDENTITY) == 0 { id_ok = 1 } 122 } 123 gv_check("identity-class-reads-identity-and-not-semantic" as *u8, id_ok, c) 124 125 var unknown_neither: i64 = 0 126 if sr_hit_is_semantic(G_BAD_CLASS) == 0 { 127 if sr_hit_is_identity(G_BAD_CLASS) == 0 { 128 if sr_klass_known(G_BAD_CLASS) == 0 { unknown_neither = 1 } 129 } 130 } 131 gv_check("neg-control-unknown-class-is-its-own-bucket-not-a-known-one" as *u8, unknown_neither, c) 132 133 // ---- the partition must sum ---- 134 var part_ok: i64 = 0 135 if sr_partition_sums(2, 1, 1, 4) == 1 { part_ok = 1 } 136 gv_check("partition-that-reconciles-is-accepted" as *u8, part_ok, c) 137 138 var part_bad: i64 = 0 139 if sr_partition_sums(2, 1, 1, 5) == 0 { part_bad = 1 } 140 gv_check("neg-control-partition-that-does-not-sum-is-refused" as *u8, part_bad, c) 141 142 // ---- the headline routes through the same abstention ---- 143 var head_abstains: i64 = 0 144 if sr_semantic_permil(0, 0) == SR_UNOBSERVABLE { head_abstains = 1 } 145 gv_check("neg-control-semantic-headline-abstains-on-an-all-duplicate-pair-set" as *u8, head_abstains, c) 146 147 // The note states SCOPE, never a tally: every tooth already states itself, and a note that recites 148 // counts or strengths silently goes stale the moment a tooth is added. 149 return gv_verdict("nx_semruler_gate" as *u8, c, 150 "subject: sr_pair_admissible, sr_rate_permil and the tier-class partition -- in-process arithmetic on planted numbers, no fixture, no filesystem, no network" as *u8) 151}