code wiki / (root) / nx_arousal_gate.nx

nx_arousal_gate.nx source

↩ module page · 195 lines · 13396 B

1// nx_arousal_gate.nx -- liar-killed GATE for the arousal-state engine. 2// Forks the REAL built elf and proves the physiology CONFORMS to the published human envelopes, 3// and -- the part that matters -- proves the gate can FAIL: every tooth has a negative control 4// that a naive/wrong model would trip. A gate that cannot refuse is not a measurement. 5// 6// CONFORMANCE ANCHORS (each traceable to a citation in nx_arousal.nx's header): 7// T1/T2 Kukkonen 2007: genital temp at time-to-peak ~33.89C (model 33.846 / 33.842) 8// T3/T4 Chivers 2010: subjective-genital agreement r=.66 M vs .26 W -> subj MUST diverge on identical input 9// T5 Masters&Johnson: systolic peaks at PLATEAU ONSET, not orgasm -> bp(700) == bp(1000) 10// T6/T7 Bohlen 1982: intercontraction interval +0.1s per contraction; amplitude rises then falls 11// T8 Bohlen 1982: 2 of 11 women reported orgasm with NO regular contraction train 12// T9/T10 Loken 2009: C-tactile tuned to LOG velocity, peak 3 cm/s -> ct(1) == ct(10) by symmetry 13// usage: nx_arousal_gate [elf] Exit 0 on 16/16. 14// license_tier: ORIGINAL expect_exit: 0 15import "nx_syscalls.nx" 16 17const G_OUTCAP: i64 = 16384 18// Tooth total is DERIVED (g_bool counts every attempt); G_MIN_TEETH is a FLOOR so a deleted tooth 19// still trips RED. A hand-maintained total drifts from the real count on every edit. 20const G_MIN_TEETH: i64 = 18 21 22func g_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 23func g_putn(v: i64) -> i64 { 24 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 25 var m: i64 = v 26 let d: *u8 = sys_mmap(24); var k: i64 = 0 27 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 28 let o: *u8 = sys_mmap(24); var w: i64 = 0 29 while w < k { o[w] = d[k-1-w]; w = w + 1 } 30 sys_write(1, o, k) 31 sys_munmap(d, 24); sys_munmap(o, 24) 32 return 0 33} 34func g_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 35func g_bool(name: *u8, got: i64, want: i64, passp: *i64) -> i64 { 36 passp[1] = passp[1] + 1 37 g_puts("T " as *u8); g_puts(name); g_puts(" got=" as *u8); g_putn(got) 38 if got == want { g_puts(" PASS\n" as *u8); passp[0] = passp[0] + 1 } else { g_puts(" FAIL\n" as *u8) } 39 return 0 40} 41func g_write(path: *u8, s: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 420); if fd < 0 { return 0 - 1 } sys_write(fd, s, g_slen(s)); sys_close(fd); return 0 } 42func g_has(hay: *u8, hn: i64, needle: *u8) -> i64 { 43 let nl: i64 = g_slen(needle) 44 if nl == 0 { return 0 } 45 var i: i64 = 0 46 while i + nl <= hn { var k: i64 = 0; var ok: i64 = 1; while k < nl { if hay[i+k] != needle[k] { ok = 0; k = nl } k = k + 1 } if ok == 1 { return 1 } i = i + 1 } 47 return 0 48} 49func g_run(elf: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8, a6: *u8, a7: *u8, out: *u8, cap: i64) -> i64 { 50 let pb: *i64 = sys_mmap(16) as *i64 51 sys_pipe2(pb, 0) 52 let rfd: i64 = pb[0] & 0xFFFFFFFF 53 let wfd: i64 = (pb[0] >> 32) & 0xFFFFFFFF 54 let pid: i64 = sys_fork() 55 if pid == 0 { 56 sys_dup3(wfd, 1, 0) 57 sys_close(rfd); sys_close(wfd) 58 let av: *i64 = sys_mmap(96) as *i64 59 av[0] = elf as i64 60 var ac: i64 = 1 61 if a1 as i64 != 0 { av[ac] = a1 as i64; ac = ac + 1 } 62 if a2 as i64 != 0 { av[ac] = a2 as i64; ac = ac + 1 } 63 if a3 as i64 != 0 { av[ac] = a3 as i64; ac = ac + 1 } 64 if a4 as i64 != 0 { av[ac] = a4 as i64; ac = ac + 1 } 65 if a5 as i64 != 0 { av[ac] = a5 as i64; ac = ac + 1 } 66 if a6 as i64 != 0 { av[ac] = a6 as i64; ac = ac + 1 } 67 if a7 as i64 != 0 { av[ac] = a7 as i64; ac = ac + 1 } 68 av[ac] = 0 69 sys_execve(elf, av, 0 as *i64) 70 sys_exit(127) 71 } 72 sys_close(wfd) 73 var tot: i64 = 0 74 var n: i64 = sys_read(rfd, out, cap - 1) 75 while n > 0 { tot = tot + n; if tot >= cap - 1 { n = 0 } else { n = sys_read(rfd, (out as i64 + tot) as *u8, cap - 1 - tot) } } 76 sys_close(rfd) 77 let st: *i64 = sys_mmap(16) as *i64 78 sys_wait4(pid, st, 0) 79 out[tot] = 0 as u8 80 return tot 81} 82 83func main(argc: i64, argv: *i64) -> i64 { 84 var elf: *u8 = "_build/nx_arousal.sov.elf" as *u8 85 if argc >= 2 { elf = argv[1] as *u8 } 86 let pass: *i64 = sys_mmap(16) as *i64 87 pass[0] = 0 88 pass[1] = 0 89 // pin the conf so a drifted table can never fake a conformance tooth 90 // CONF IS VERIFIED, NEVER OVERWRITTEN. 91 // This used to be a whole-file g_write "pin". That pin had to restate every key any consumer 92 // reads, so adding skin/morphology keys SILENTLY STRIPPED them -- it happened twice, and the 93 // second time only because the first fix restated the string instead of removing the duplication. 94 // A gate that rewrites the config it is testing against also MASKS drift instead of catching it. 95 // Reading and asserting is strictly better: drift becomes RED, and new keys are none of its 96 // business. 97 let ccl: *i64 = sys_mmap(16) as *i64 98 ccl[0] = 0 99 let ccb: *u8 = sys_read_file("arousal_params.conf" as *u8, ccl) 100 let ccn: i64 = ccl[0] 101 g_bool("conf-readable" as *u8, g_has(ccb, ccn, "tau_slow_m_ms=" as *u8), 1, pass) 102 g_bool("conf-tau-male-185000" as *u8, g_has(ccb, ccn, "tau_slow_m_ms=185000" as *u8), 1, pass) 103 g_bool("conf-tau-female-210000" as *u8, g_has(ccb, ccn, "tau_slow_f_ms=210000" as *u8), 1, pass) 104 g_bool("conf-concordance-coup-f-260" as *u8, g_has(ccb, ccn, "coup_f=260" as *u8), 1, pass) 105 g_bool("conf-bp-plateau-700" as *u8, g_has(ccb, ccn, "bp_plateau_drive=700" as *u8), 1, pass) 106 let out: *u8 = sys_mmap(G_OUTCAP) 107 var n: i64 = 0 108 109 // T1 thermal conformance, male, at published time-to-peak 664.6s 110 n = g_run(elf, "traj" as *u8, "0" as *u8, "664600" as *u8, "1000" as *u8, "1000" as *u8, "0" as *u8, "0" as *u8, out, G_OUTCAP) 111 g_bool("thermal-male-at-ttp-33.846C" as *u8, g_has(out, n, "temp_mc=33846" as *u8), 1, pass) 112 // T2 thermal conformance, female, at published time-to-peak 743s 113 n = g_run(elf, "traj" as *u8, "1" as *u8, "743000" as *u8, "1000" as *u8, "1000" as *u8, "0" as *u8, "0" as *u8, out, G_OUTCAP) 114 g_bool("thermal-female-at-ttp-33.842C" as *u8, g_has(out, n, "temp_mc=33842" as *u8), 1, pass) 115 116 // T3/T4 THE CONCORDANCE LAW: identical stimulus+time, subjective MUST diverge by sex. 117 n = g_run(elf, "traj" as *u8, "0" as *u8, "600000" as *u8, "1000" as *u8, "1000" as *u8, "0" as *u8, "0" as *u8, out, G_OUTCAP) 118 g_bool("concordance-male-high-subj863" as *u8, g_has(out, n, "subj=863" as *u8), 1, pass) 119 n = g_run(elf, "traj" as *u8, "1" as *u8, "600000" as *u8, "1000" as *u8, "1000" as *u8, "0" as *u8, "0" as *u8, out, G_OUTCAP) 120 g_bool("concordance-female-low-subj244" as *u8, g_has(out, n, "subj=244" as *u8), 1, pass) 121 // NEG CONTROL: the female twin must NOT produce the male subjective value on the same input. 122 g_bool("NEG-female-is-not-male-subj" as *u8, g_has(out, n, "subj=863" as *u8), 0, pass) 123 124 // T5 systolic peaks at PLATEAU ONSET, not orgasm: bp identical at drive 700 and 1000. 125 n = g_run(elf, "traj" as *u8, "0" as *u8, "600000" as *u8, "700" as *u8, "1000" as *u8, "0" as *u8, "0" as *u8, out, G_OUTCAP) 126 g_bool("bp-at-plateau-drive700-is-141" as *u8, g_has(out, n, "bp=141" as *u8), 1, pass) 127 n = g_run(elf, "traj" as *u8, "0" as *u8, "600000" as *u8, "1000" as *u8, "1000" as *u8, "0" as *u8, "0" as *u8, out, G_OUTCAP) 128 g_bool("bp-does-not-rise-past-plateau" as *u8, g_has(out, n, "bp=141" as *u8), 1, pass) 129 130 // T6 Bohlen chirp: interval grows +100ms per contraction 131 n = g_run(elf, "contract" as *u8, "1" as *u8, "0" as *u8, "10" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 132 g_bool("contraction-first-interval-800ms" as *u8, g_has(out, n, "interval_ms=800" as *u8), 1, pass) 133 n = g_run(elf, "contract" as *u8, "1" as *u8, "5" as *u8, "10" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 134 g_bool("contraction-chirps-to-1300ms" as *u8, g_has(out, n, "interval_ms=1300" as *u8), 1, pass) 135 // NEG CONTROL: a fixed-frequency train would still read 800ms at n=5. 136 g_bool("NEG-train-is-not-fixed-freq" as *u8, g_has(out, n, "interval_ms=800" as *u8), 0, pass) 137 // T7 amplitude envelope peaks mid-series then falls 138 g_bool("amplitude-peaks-midseries" as *u8, g_has(out, n, "amp=1000" as *u8), 1, pass) 139 n = g_run(elf, "contract" as *u8, "1" as *u8, "9" as *u8, "10" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 140 g_bool("amplitude-falls-late-series" as *u8, g_has(out, n, "amp=200" as *u8), 1, pass) 141 142 // T8 Bohlen type III: orgasm with NO contraction train must be representable, not erased. 143 n = g_run(elf, "contract" as *u8, "3" as *u8, "0" as *u8, "10" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 144 g_bool("bohlen-type3-no-train-refuses" as *u8, g_has(out, n, "REFUSED reason=no_contraction_train" as *u8), 1, pass) 145 146 // T9 C-tactile LOG symmetry: 1 cm/s and 10 cm/s are equidistant from the 3 cm/s peak. 147 n = g_run(elf, "ct" as *u8, "100" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 148 g_bool("ct-band-low-1cms-625" as *u8, g_has(out, n, "ct=625" as *u8), 1, pass) 149 n = g_run(elf, "ct" as *u8, "1000" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 150 g_bool("ct-band-high-10cms-625-LOGSYM" as *u8, g_has(out, n, "ct=625" as *u8), 1, pass) 151 // T10 two-compartment separation: fast neurogenic leads the slow vascular envelope by ~2 orders of tau 152 n = g_run(elf, "traj" as *u8, "0" as *u8, "2500" as *u8, "1000" as *u8, "1000" as *u8, "0" as *u8, "0" as *u8, out, G_OUTCAP) 153 g_bool("two-compartment-fast635-slow13" as *u8, g_has(out, n, "pfast=635 pslow=13" as *u8), 1, pass) 154 155 // T11/T12 THE FIT RATCHET: residual is 0 at the true tau and large at a wrong one. 156 // This is what lets us iterate past the thin literature instead of inheriting its ceiling. 157 n = g_run(elf, "residual" as *u8, "185000" as *u8, "1000" as *u8, "100000" as *u8, "416" as *u8, "400000" as *u8, "883" as *u8, out, G_OUTCAP) 158 g_bool("fit-residual-zero-at-truth" as *u8, g_has(out, n, "residual=0" as *u8), 1, pass) 159 n = g_run(elf, "residual" as *u8, "5000000" as *u8, "1000" as *u8, "100000" as *u8, "416" as *u8, "400000" as *u8, "883" as *u8, out, G_OUTCAP) 160 g_bool("fit-residual-discriminates-1209" as *u8, g_has(out, n, "residual=1209" as *u8), 1, pass) 161 162 // --- MALE GENITAL: tumescence and rigidity are two different things ------------------------- 163 // At 5s there is real volume and ZERO rigidity: pressure has not developed yet. A one-scalar 164 // "erection" model cannot represent this and would report partial rigidity here. 165 n = g_run(elf, "male" as *u8, "5000" as *u8, "1000" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 166 g_bool("tumescence-283-with-zero-rigidity" as *u8, g_has(out, n, "tume=283 rig_base=0" as *u8), 1, pass) 167 n = g_run(elf, "male" as *u8, "60000" as *u8, "1000" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 168 g_bool("rigidity-develops-by-60s-746tip" as *u8, g_has(out, n, "rig_base=957 rig_tip=746" as *u8), 1, pass) 169 g_bool("NEG-rigidity-is-not-zero-once-developed" as *u8, g_has(out, n, "rig_base=0" as *u8), 0, pass) 170 171 // ★THE CLINICAL TOOTH: the 60% and 70% RigiScan criteria DISAGREE over a real band of men, which 172 // is why the 70% threshold overestimates organic ED. The twin must land inside that band. 173 n = g_run(elf, "male" as *u8, "300000" as *u8, "900" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 174 g_bool("rigiscan-criteria-disagree-tip604" as *u8, g_has(out, n, "rig_tip=604 potent60=1 potent70=0" as *u8), 1, pass) 175 // NEG: a model that merged the two criteria into one verdict would report them agreeing. 176 g_bool("NEG-criteria-do-not-both-pass-at-900" as *u8, g_has(out, n, "potent60=1 potent70=1" as *u8), 0, pass) 177 n = g_run(elf, "male" as *u8, "300000" as *u8, "1000" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 178 g_bool("both-criteria-pass-at-full-drive" as *u8, g_has(out, n, "potent60=1 potent70=1" as *u8), 1, pass) 179 180 // refractory suppression -- PHENOMENOLOGICAL (prolactin mechanism disproven, Comm Biol 2021) 181 n = g_run(elf, "male" as *u8, "300000" as *u8, "1000" as *u8, "0" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 182 g_bool("refractory-total-at-t0" as *u8, g_has(out, n, "eff_drive=0 tume=0" as *u8), 1, pass) 183 n = g_run(elf, "male" as *u8, "300000" as *u8, "1000" as *u8, "1200000" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 184 g_bool("refractory-decays-one-tau-368" as *u8, g_has(out, n, "refractory=368" as *u8), 1, pass) 185 n = g_run(elf, "male" as *u8, "300000" as *u8, "1000" as *u8, "3600000" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, out, G_OUTCAP) 186 g_bool("refractory-mostly-recovered-49" as *u8, g_has(out, n, "refractory=49" as *u8), 1, pass) 187 // NEG: recovery must NOT be complete -- still inside the criteria disagreement band at 3 tau 188 g_bool("NEG-recovery-still-below-70pct" as *u8, g_has(out, n, "potent70=1" as *u8), 0, pass) 189 190 g_puts("AROUSAL-GATE pass=" as *u8); g_putn(pass[0]); g_puts("/" as *u8); g_putn(pass[1]); g_puts(" verdict=" as *u8) 191 if pass[1] < G_MIN_TEETH { g_puts("RED reason=teeth_deleted\n" as *u8); return 1 } 192 if pass[0] == pass[1] { g_puts("GREEN\n" as *u8); return 0 } 193 g_puts("RED\n" as *u8) 194 return 1 195}