code wiki / _hdl_build / nx_connect_match.nx

nx_connect_match.nx source

↩ module page · 100 lines · 6652 B

1// nx_connect_match.nx -- R1 of CONNECT: the RECIPROCAL language-exchange MATCH ENGINE + its gate. 2// The language-exchange wedge is COMPLEMENTARY, not similarity: a good partner TEACHES what you 3// want to LEARN *and* LEARNS what you can TEACH. So the core signal is a HARMONIC MEAN of the two 4// directional fits -- one-sided pairs collapse to 0 (you cannot reciprocally exchange). Interests 5// modulate; reciprocity is NECESSARY. Pure INTEGER math (no floats). The output is an INTERNAL 6// ranking weight 0..100 -- NEVER a user-facing "compatibility score" (PNAS 2020: profile traits 7// ~5% of long-term variance; we surface reciprocal interest, conversation decides). 8// 9// SAFETY BY CONSTRUCTION (launch prerequisite, proven here in the gate): romance/dating lane edges 10// are UNREACHABLE to/from minors -- a minor who is a PERFECT reciprocal+interest match is still 11// EXCLUDED from a dating-lane query (both directions), while remaining free to language-exchange. 12// 13// Gate has 7 checks incl. a measured NEGATIVE CONTROL: the naive arithmetic mean would wrongly 14// surface a one-sided pair (score 25), proving the harmonic mean is what enforces reciprocity. 15// Mirrors the nx_*_census/gate idiom. 100% sovereign. license_tier: ORIGINAL expect_exit: 0 16// 2026-07-23 LIBRARY SPLIT: the engine moved to nx_connect_match_lib.nx so THIS gate and the LIVE app 17// (nx_connect_serve /partners) bind ONE implementation. Before the split the live page printed hardcoded 18// scores while crediting "the gated match engine" -- it asserted a computation it never ran. This file is 19// now purely the VERIFIER; its emitted output is byte-identical to the pre-split version, which is the 20// proof that the extraction changed no behavior. 21import "nx_syscalls.nx" 22import "nx_connect_match_lib.nx" 23 24func sw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 25func sn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" 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(1,bb,k); return 0 } 26 27func tcheck(pass: i64, label: *u8, fails: *i64) -> i64 { 28 sw(" " as *u8); sw(label); sw(": " as *u8) 29 if pass==1 { sw("PASS\n" as *u8) } else { sw("FAIL\n" as *u8); fails[0]=fails[0]+1 } 30 return 0 31} 32 33func main() -> i64 { 34 let fails: *i64 = sys_mmap(16) as *i64 35 fails[0]=0 36 37 // language bits: EN=1 ES=2 FR=4 DE=8 JA=16 AR=32 ; interest bits: MUSIC=1 SPORTS=2 COOK=4 TECH=8 ART=16 TRAVEL=32 38 // synthetic corpus (deterministic, ZERO real PHI): 39 // ALICE age30 teach EN(1) learn ES(2) int MUSIC+COOK(5) 40 // BOB age28 teach ES(2) learn EN(1) int MUSIC+TECH(9) -> perfect reciprocal w/ ALICE 41 // CARL age35 teach ES(2) learn FR(4) int TECH(8) -> ONE-SIDED (Alice can learn, Carl cannot) 42 // DAN age40 teach FR(4) learn DE(8) int ART(16) -> NO complementarity 43 // EVE age26 teach ES(2) learn EN(1) int MUSIC+COOK+TECH(13) -> reciprocal + MORE shared interests 44 // MIA age15 teach ES(2) learn EN(1) int MUSIC+COOK(5) -> MINOR; a perfect reciprocal+interest match 45 46 let v_bob: i64 = mx_match_weight(30,2,1,5, 28,1,2,9, MX_LANE_LANG) 47 let v_carl: i64 = mx_match_weight(30,2,1,5, 35,4,2,8, MX_LANE_LANG) 48 let v_dan: i64 = mx_match_weight(30,2,1,5, 40,8,4,16, MX_LANE_LANG) 49 let v_eve: i64 = mx_match_weight(30,2,1,5, 26,1,2,13, MX_LANE_LANG) 50 let v_mia_lang: i64 = mx_match_weight(30,2,1,5, 15,1,2,5, MX_LANE_LANG) 51 let v_mia_date: i64 = mx_match_weight(30,2,1,5, 15,1,2,5, MX_LANE_DATE) // adult queries dating, minor candidate 52 let v_mia_date_rev: i64 = mx_match_weight(15,1,2,5, 30,2,1,5, MX_LANE_DATE) // minor queries dating, adult candidate 53 let hm_carl: i64 = mx_recip_score(2,1,4,2) 54 let am_carl: i64 = mx_recip_arith(2,1,4,2) 55 56 sw("=== nx_connect_match R1 -- reciprocal language-exchange match engine (honest 2026-06-20) ===\n" as *u8) 57 sw("internal rank weights 0..100 (NOT a user-facing compatibility score):\n" as *u8) 58 sw(" ALICE x BOB (reciprocal) = " as *u8); sn(v_bob); sw("\n" as *u8) 59 sw(" ALICE x CARL (one-sided) = " as *u8); sn(v_carl); sw("\n" as *u8) 60 sw(" ALICE x DAN (no complementarity) = " as *u8); sn(v_dan); sw("\n" as *u8) 61 sw(" ALICE x EVE (reciprocal+interests) = " as *u8); sn(v_eve); sw("\n" as *u8) 62 sw(" ALICE x MIA LANGUAGE lane (minor) = " as *u8); sn(v_mia_lang); sw("\n" as *u8) 63 sw(" ALICE x MIA DATING lane (minor) = " as *u8); sn(v_mia_date); sw(" (EXCLUDED by construction)\n" as *u8) 64 sw(" one-sided: harmonic=" as *u8); sn(hm_carl); sw(" vs naive arithmetic=" as *u8); sn(am_carl); sw("\n" as *u8) 65 sw("-- gate checks --\n" as *u8) 66 67 // T1: one-sided pair -> 0 (reciprocity necessary) 68 var t1: i64=0; if v_carl==0 { t1=1 } 69 tcheck(t1, "T1 one-sided -> 0 (reciprocity necessary)" as *u8, fails) 70 71 // T2: reciprocal pair rewarded AND strictly beats the one-sided pair 72 var t2: i64=0; if v_bob>=40 { if v_bob>v_carl { t2=1 } } 73 tcheck(t2, "T2 reciprocal rewarded (>=40) and > one-sided" as *u8, fails) 74 75 // T3: no complementarity -> 0 76 var t3: i64=0; if v_dan==0 { t3=1 } 77 tcheck(t3, "T3 no-complementarity -> 0" as *u8, fails) 78 79 // T4: more shared interests ranks higher (EVE > BOB, same languages) 80 var t4: i64=0; if v_eve>v_bob { t4=1 } 81 tcheck(t4, "T4 more shared interests ranks higher" as *u8, fails) 82 83 // T5: SAFETY -- minor excluded from dating lane in BOTH directions, despite a high underlying score 84 var t5: i64=0; if v_mia_date<0 { if v_mia_date_rev<0 { t5=1 } } 85 tcheck(t5, "T5 SAFETY minor<->dating EXCLUDED by construction (both directions)" as *u8, fails) 86 87 // T6: minor NOT over-blocked -- can still language-exchange (and scores well) 88 var t6: i64=0; if v_mia_lang>0 { t6=1 } 89 tcheck(t6, "T6 minor still free to language-exchange (not over-blocked)" as *u8, fails) 90 91 // T7: NEG-CONTROL -- harmonic mean zeros the one-sided pair where naive arithmetic mean would surface it 92 var t7: i64=0; if hm_carl==0 { if am_carl>0 { t7=1 } } 93 tcheck(t7, "T7 NEG-CONTROL harmonic=0 but naive arithmetic>0 (HM enforces reciprocity)" as *u8, fails) 94 95 sw(" fails=" as *u8); sn(fails[0]); sw("\n" as *u8) 96 if fails[0]==0 { sw("VERDICT: GREEN (reciprocal match engine works; minor<->dating walled by construction; HM measured-necessary)\n" as *u8); sys_exit(0) } 97 sw("VERDICT: RED\n" as *u8) 98 sys_exit(1) 99 return 1 100}