code wiki / _hdl_build / nx_connect_graph.nx
nx_connect_graph.nx source
↩ module page · 101 lines · 6444 B
1// nx_connect_graph.nx -- R4 of CONNECT: the UNIFIED heterogeneous interest graph (HIN) + one
2// meta-path matching model. The core product promise: incumbents SILO language / hobby / faith /
3// dating as separate products or flat filters; we put person + language + hobby + faith + place on
4// ONE graph and match across all of them with ONE model, parameterized by the relationship LANE.
5//
6// A person is a node; attributes are typed edges (teach/learn-language, likes-hobby, faith, place).
7// Meta-path connection strengths (integer, no floats): reciprocal-language (the R1 path), shared-
8// hobby, shared-faith, co-location. gx_graph_score(A,B,lane) combines them with LANE-appropriate
9// weights -- so the SAME model serves language-exchange, friendship, community and dating.
10//
11// Proven here: (1) it GENERALIZES R1 -- the language lane still requires reciprocal language;
12// (2) it UNIFIES across silos -- a pair with NO shared language but strong shared hobby+faith is
13// found for the friendship lane, where a language-only matcher returns nothing; (3) faith is
14// CONSENT-GATED (contributes only if BOTH opted into faith discovery -- GDPR Art.9 by construction);
15// (4) the minor<->romance safety wall is preserved. 7 checks incl. negative controls.
16// (DRY note: the small match primitives are re-stated here to keep the gate self-contained;
17// production extracts them into a shared library organ.) 100% sovereign.
18// license_tier: ORIGINAL expect_exit: 0
19import "nx_syscalls.nx"
20
21import "nx_connect_graph_lib.nx"
22
23// thin allocating wrapper so the gate's call sites stay unchanged (the lib exposes the no-alloc gx_mk)
24func mkp(band: i64, teach: i64, learn: i64, hob: i64, faith: i64, optin: i64, place: i64) -> *i64 {
25 let p: *i64 = sys_mmap(GX_NODE_SLOTS*8) as *i64
26 gx_mk(p, band, teach, learn, hob, faith, optin, place)
27 return p
28}
29
30func sw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
31func 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 }
32
33
34func tcheck(pass: i64, label: *u8, fails: *i64) -> i64 {
35 sw(" " as *u8); sw(label); sw(": " as *u8)
36 if pass==1 { sw("PASS\n" as *u8) } else { sw("FAIL\n" as *u8); fails[0]=fails[0]+1 }
37 return 0
38}
39
40func main() -> i64 {
41 let fails: *i64 = sys_mmap(16) as *i64
42 fails[0]=0
43
44 // lang bits EN=1 ES=2 FR=4 DE=8 ; hobby bits MUSIC=1 SPORTS=2 COOK=4 TECH=8 ART=16 ; faith 1=LDS 2=Catholic
45 let a: *i64 = mkp(GX_BAND_ADULT, 1, 2, 5, 1, 1, 10) // teach EN, learn ES, hob MUSIC+COOK, LDS optin, place10
46 let b: *i64 = mkp(GX_BAND_ADULT, 2, 1, 9, 1, 1, 10) // reciprocal-lang w/ A; shared MUSIC; same faith+place
47 let c: *i64 = mkp(GX_BAND_ADULT, 4, 8, 21, 1, 1, 10) // NO reciprocal lang w/ A; shared hobby+faith+place (cross-silo)
48 let e: *i64 = mkp(GX_BAND_MINOR, 2, 1, 5, 1, 1, 10) // MINOR; perfect match otherwise
49 let f: *i64 = mkp(GX_BAND_ADULT, 2, 1, 9, 1, 0, 10) // like B but faith_optin=0 (no consent)
50
51 let ab_lang: i64 = gx_graph_score(a,b,GX_LANE_LANG)
52 let ac_lang: i64 = gx_graph_score(a,c,GX_LANE_LANG)
53 let ac_friend: i64 = gx_graph_score(a,c,GX_LANE_FRIEND)
54 let ab_friend: i64 = gx_graph_score(a,b,GX_LANE_FRIEND)
55 let ae_date: i64 = gx_graph_score(a,e,GX_LANE_DATE)
56 let ae_lang: i64 = gx_graph_score(a,e,GX_LANE_LANG)
57
58 sw("=== nx_connect_graph R4 -- unified interest graph (HIN) + one meta-path model ===\n" as *u8)
59 sw("ONE model over language+hobby+faith+place, parameterized by lane (incumbents silo these):\n" as *u8)
60 sw(" A x B language lane (reciprocal) = " as *u8); sn(ab_lang); sw("\n" as *u8)
61 sw(" A x C language lane (no shared lang)= " as *u8); sn(ac_lang); sw(" (siloed language matcher finds nothing)\n" as *u8)
62 sw(" A x C FRIEND lane (hobby+faith+place)= " as *u8); sn(ac_friend); sw(" (unified graph FINDS them across silos)\n" as *u8)
63 sw(" A x B FRIEND lane = " as *u8); sn(ab_friend); sw("\n" as *u8)
64 sw(" A x E DATE lane (E is a minor) = " as *u8); sn(ae_date); sw(" (EXCLUDED) ; LANGUAGE lane = " as *u8); sn(ae_lang); sw("\n" as *u8)
65 sw("-- gate checks --\n" as *u8)
66
67 // T1: generalizes R1 -- language lane still requires reciprocal language
68 var t1: i64=0; if ab_lang>0 { if ac_lang==0 { t1=1 } }
69 tcheck(t1, "T1 generalizes R1 (language lane requires reciprocal language)" as *u8, fails)
70
71 // T2: unifies across silos -- friendship found where a language-only matcher returns 0
72 var t2: i64=0; if ac_friend>0 { if ac_lang==0 { t2=1 } }
73 tcheck(t2, "T2 UNIFIES across silos (friend match w/ no shared language)" as *u8, fails)
74
75 // T3: meta-path computations correct
76 var t3: i64=0
77 if gx_inter_popc(a[3],c[3])==2 { if gx_mp_faith(a[4],a[5],b[4],b[5])==100 { if a[6]==b[6] { t3=1 } } }
78 tcheck(t3, "T3 meta-paths correct (shared-hobby, shared-faith, co-location)" as *u8, fails)
79
80 // T4: faith CONSENT-gated -- same faith but one party not opted-in -> 0 (Art.9). NEG-CONTROL.
81 var t4: i64=0; if gx_mp_faith(a[4],a[5],f[4],f[5])==0 { if gx_mp_faith(a[4],a[5],b[4],b[5])==100 { t4=1 } }
82 tcheck(t4, "T4 faith consent-gated (no opt-in -> 0; naive would leak faith)" as *u8, fails)
83
84 // T5: one model adapts per lane -- same pair scores differently by intent
85 var t5: i64=0; if ab_lang!=ab_friend { t5=1 }
86 tcheck(t5, "T5 one model, lane-appropriate weighting (same pair, different lane)" as *u8, fails)
87
88 // T6: SAFETY preserved -- minor excluded from dating, still free to language-exchange
89 var t6: i64=0; if ae_date<0 { if ae_lang>0 { t6=1 } }
90 tcheck(t6, "T6 SAFETY minor<->romance wall preserved in the graph" as *u8, fails)
91
92 // T7: NEG-CONTROL quantified -- unified finds strictly more connection than the language silo
93 var t7: i64=0; if ac_friend>ac_lang { t7=1 }
94 tcheck(t7, "T7 NEG-CONTROL unified > language-silo (cross-type connection found)" as *u8, fails)
95
96 sw(" fails=" as *u8); sn(fails[0]); sw("\n" as *u8)
97 if fails[0]==0 { sw("VERDICT: GREEN (one graph unifies language+hobby+faith+place; generalizes R1; faith consent-gated; safe)\n" as *u8); sys_exit(0) }
98 sw("VERDICT: RED\n" as *u8)
99 sys_exit(1)
100 return 1
101}