code wiki / (root) / nx_career_fair.nx

nx_career_fair.nx source

↩ module page · 116 lines · 5496 B

1// nx_career_fair.nx -- FAIRNESS BY CONSTRUCTION for the career matcher (career ring rung 3; the number-one 2// 2025/26 frontier wave, gapmap momentum 228). The mechanical claim, PROVEN not asserted: MATCH-SCORE is a 3// function of SKILLS ALONE. A candidate RECORD may carry name / gender / age / zip -- the scorer extracts only 4// the skills field, and this gate proves INVARIANCE: records identical in skills but different in every 5// demographic field score BYTE-IDENTICALLY (direct discrimination impossible by construction), while a skills 6// change DOES move the score (sensitivity control -- ignoring everything would trivially "pass"), and skill 7// ORDER does not matter. HONEST SCOPE: this is attribute-blindness; proxy fairness (skills themselves 8// correlating with demographics) is the open research frontier and is NOT claimed here. 9// Record form: name|gender|age|zip|skills-csv. Argless = selftest gate; CLI: score <record> <need-csv>. 10// expect_exit: 0 license_tier: ORIGINAL 11import "nx_career.nx" 12const K_MAGIC_1024: i64 = 1024 13 14// pipe-field extractor (local; nx_send's twin lives behind its own main) 15func cf_field(s: *u8, idx: i64, out: *u8, cap: i64) -> i64 { 16 var segidx: i64 = 0 17 var t: i64 = 0 18 var i: i64 = 0 19 var found: i64 = 0 20 var go: i64 = 1 21 while go == 1 { 22 let c: i64 = s[i] as i64 23 if c == 0 { go = 0 } 24 if go == 1 { 25 if c == 124 { segidx = segidx + 1 } else { 26 if segidx == idx { found = 1; if t < cap - 1 { out[t] = s[i]; t = t + 1 } } 27 } 28 i = i + 1 29 } 30 } 31 out[t] = 0 as u8 32 if segidx > idx { return 1 } 33 return found 34} 35 36// score a full candidate RECORD vs a requirement csv: extracts ONLY the skills field (index 4). 37// -1 = malformed record (loud), else 0..100. 38func cf_score(rec: *u8, needcsv: *u8) -> i64 { 39 let sk: *u8 = sys_mmap(K_MAGIC_1024) 40 if cf_field(rec, 4, sk, K_MAGIC_1024) != 1 { return 0 - 1 } 41 if sk[0] == (0 as u8) { return 0 - 1 } 42 let nb: *u8 = sys_mmap(64 * 16) 43 let nb2: *u8 = sys_mmap(64 * 16) 44 let hn: *i64 = sys_mmap(8 * 16) as *i64 45 let hl: *i64 = sys_mmap(8 * 16) as *i64 46 let rn: *i64 = sys_mmap(8 * 16) as *i64 47 let rl: *i64 = sys_mmap(8 * 16) as *i64 48 let hc: i64 = skills_parse(sk, hn, hl, 16, nb) 49 let rc: i64 = skills_parse(needcsv, rn, rl, 16, nb2) 50 return match_score(hn, hl, hc, rn, rl, rc) 51} 52 53func cf_selftest() -> i64 { 54 p("=== NX-CAREER-FAIR SELFTEST (FAIR-INVARIANT: score = f(skills) ONLY, proven not asserted) ===\n" as *u8) 55 var ok: i64 = 1 56 let reqAE: *u8 = "sales:3,crm:3" as *u8 57 let reqSD: *u8 = "sales:5,leadership:4,forecasting:3" as *u8 58 59 // four candidates: IDENTICAL skills, maximally different demographics 60 let cands: *i64 = sys_mmap(8 * 8) as *i64 61 cands[0] = "Emma Andelin|female|29|62704|sales:4,crm:3,writing:5" as *u8 as i64 62 cands[1] = "Ethan Brown|male|61|10001|sales:4,crm:3,writing:5" as *u8 as i64 63 cands[2] = "Aiko Tanaka|female|22|94103|sales:4,crm:3,writing:5" as *u8 as i64 64 cands[3] = "DeShawn Carter|male|45|60614|sales:4,crm:3,writing:5" as *u8 as i64 65 66 // T1 invariance across demographics, on TWO different jobs 67 let a0: i64 = cf_score(cands[0] as *u8, reqAE) 68 let d0: i64 = cf_score(cands[0] as *u8, reqSD) 69 var i: i64 = 1 70 var inv: i64 = 1 71 while i < 4 { 72 let ai: i64 = cf_score(cands[i] as *u8, reqAE) 73 let di: i64 = cf_score(cands[i] as *u8, reqSD) 74 if ai != a0 { inv = 0 } 75 if di != d0 { inv = 0 } 76 i = i + 1 77 } 78 p(" FAIR-INVARIANT T1 demographics-invariance: AE=" as *u8); pn(a0); p(" SD=" as *u8); pn(d0) 79 if inv == 1 { p(" across 4 demographic variants = IDENTICAL\n" as *u8) } else { p(" = VARIED (FAIL)\n" as *u8); ok = 0 } 80 if a0 != 100 { ok = 0 } 81 if d0 != 26 { ok = 0 } 82 83 // T2 sensitivity: the score MUST move with skills (no trivial constant) 84 let weak: i64 = cf_score("Sam Lee|male|30|11111|sales:1" as *u8, reqAE) 85 p(" FAIR-INVARIANT T2 sensitivity: sales:1 vs AE = " as *u8); pn(weak); p(" (must differ from 100)\n" as *u8) 86 if weak == a0 { ok = 0 } 87 if weak != 16 { ok = 0 } 88 89 // T3 skill-ORDER invariance 90 let reord: i64 = cf_score("Emma Andelin|female|29|62704|writing:5,crm:3,sales:4" as *u8, reqAE) 91 p(" FAIR-INVARIANT T3 order-invariance: reordered csv = " as *u8); pn(reord); p("\n" as *u8) 92 if reord != a0 { ok = 0 } 93 94 // T4 loud-fail on malformed record (missing skills field) 95 let bad: i64 = cf_score("Bob|male|40" as *u8, reqAE) 96 p(" FAIR-INVARIANT T4 malformed record -> " as *u8); pn(bad); p(" (must be -1, loud)\n" as *u8) 97 if bad != (0 - 1) { ok = 0 } 98 99 p(" honest scope: attribute-BLINDNESS proven by construction; proxy fairness = open frontier, not claimed.\n" as *u8) 100 p("NX-CAREER-FAIR-SELFTEST variants=4 jobs=2 " as *u8) 101 if ok == 1 { p("verdict=GREEN\n" as *u8); return 0 } 102 p("verdict=RED\n" as *u8) 103 return 1 104} 105 106func main(argc: i64, argv: *i64) -> i64 { 107 if argc < 2 { return cf_selftest() } 108 if seq(argv[1] as *u8, "score" as *u8) == 1 { 109 if argc < 4 { p("usage: score <record name|gender|age|zip|skills> <need-csv>\n" as *u8); return 1 } 110 let s: i64 = cf_score(argv[2] as *u8, argv[3] as *u8) 111 if s < 0 { p("FAIR-SCORE ERROR malformed record -- fail loud\n" as *u8); return 1 } 112 p("FAIR-SCORE " as *u8); pn(s); p("/100 (skills-only by construction)\n" as *u8) 113 return 0 114 } 115 return cf_selftest() 116}