code wiki / _hdl_build / nx_atlas_recombine.nx
nx_atlas_recombine.nx source
↩ module page · 146 lines · 6897 B
1// nx_atlas_recombine.nx -- F225: PRODUCT-recombination over the LIVE atlas (ecograph_full). v2.
2// Walks the whole 16k-node import graph: ranks INTEGRATIVE nodes by fan-out (Ce = capabilities composed),
3// FILTERS OUT test/gate/probe/bench scaffolding (not products), then for each real integrative node emits its
4// single BEST orthogonal partner (no direct edge, low shared-deps) = a diverse, one-per-anchor set of novel
5// recombination candidates, scored by combined-capability minus shared-overlap. HONEST: STRUCTURAL candidates
6// (novelty=graph-orthogonality, value=capability-richness), NOT semantic products -- semantic/market rank is
7// the next rung (match dmktneeds- + a judge). Scale-aware: top-K by Ce, then per-node best-partner scan.
8// v2 emits to stdout; persist to recombine- + diversify-partner + product-filter refine = follow-ons. seq66
9// dup-edges inflate Ce (flagged). usage: nx_atlas_recombine [store-prefix] [ce-min] [topK] license_tier: ORIGINAL
10import "nx_eco_graph.nx"
11import "nx_syscalls.nx"
12
13const RC_TOPK_MAX: i64 = 96
14const RC_CEMIN_DEF: i64 = 8
15const RC_TOPK_DEF: i64 = 60
16
17func rc_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
18func rc_wn(fd: i64, v: i64) -> i64 { let b: *u8 = sys_mmap(24); var m: i64 = v; if m < 0 { sys_write(fd, "-" as *u8, 1); m = 0 - m } let t: *u8 = sys_mmap(24); 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 j: i64 = 0; while j < k { b[j] = t[k-1-j]; j = j + 1 } sys_write(fd, b, k); return 0 }
19func rc_wname(fd: i64, g: *EcoGraph, idx: i64) -> i64 {
20 let off: i64 = g.node_off[idx]
21 var n: i64 = 0
22 while g.arena[off+n] != (0 as u8) { n = n + 1 }
23 var e: i64 = n
24 if n > 3 { if g.arena[off+n-3] == (46 as u8) { if g.arena[off+n-2] == (110 as u8) { if g.arena[off+n-1] == (120 as u8) { e = n - 3 } } } }
25 sys_write(fd, ((g.arena as i64)+off) as *u8, e)
26 return 0
27}
28func rc_atoi(s: *u8) -> i64 { var v: i64 = 0; var i: i64 = 0; while s[i] != (0 as u8) { let c: i64 = s[i]; if c >= 48 { if c <= 57 { v = v*10 + (c-48) } } i = i + 1 } return v }
29func rc_name_has(g: *EcoGraph, idx: i64, sub: *u8) -> i64 {
30 let off: i64 = g.node_off[idx]
31 var nl: i64 = 0
32 while g.arena[off+nl] != (0 as u8) { nl = nl + 1 }
33 var sl: i64 = 0
34 while sub[sl] != (0 as u8) { sl = sl + 1 }
35 if sl == 0 { return 0 }
36 var i: i64 = 0
37 while i + sl <= nl {
38 var m: i64 = 1
39 var j: i64 = 0
40 while j < sl { if g.arena[off+i+j] != sub[j] { m = 0; j = sl } else { j = j + 1 } }
41 if m == 1 { return 1 }
42 i = i + 1
43 }
44 return 0
45}
46func rc_is_scaffold(g: *EcoGraph, idx: i64) -> i64 {
47 if rc_name_has(g, idx, "_test" as *u8) == 1 { return 1 }
48 if rc_name_has(g, idx, "_gate" as *u8) == 1 { return 1 }
49 if rc_name_has(g, idx, "_probe" as *u8) == 1 { return 1 }
50 if rc_name_has(g, idx, "_bench" as *u8) == 1 { return 1 }
51 return 0
52}
53func rc_imports(g: *EcoGraph, a: i64, b: i64) -> i64 {
54 var p: i64 = g.out_head[a]
55 let e: i64 = g.out_head[a+1]
56 var f: i64 = 0
57 while p < e { if g.out_list[p] == b { f = 1; p = e } else { p = p + 1 } }
58 return f
59}
60func rc_shared(g: *EcoGraph, a: i64, b: i64) -> i64 {
61 var sh: i64 = 0
62 var p: i64 = g.out_head[a]
63 let e: i64 = g.out_head[a+1]
64 while p < e {
65 let d: i64 = g.out_list[p]
66 var q: i64 = g.out_head[b]
67 let eb: i64 = g.out_head[b+1]
68 var h: i64 = 0
69 while q < eb { if g.out_list[q] == d { h = 1; q = eb } else { q = q + 1 } }
70 if h == 1 { sh = sh + 1 }
71 p = p + 1
72 }
73 return sh
74}
75
76func main(argc: i64, argv: *i64) -> i64 {
77 var storep: *u8 = "knowledge/store/ecograph_full" as *u8
78 var cemin: i64 = RC_CEMIN_DEF
79 var topk: i64 = RC_TOPK_DEF
80 if argc > 1 { storep = argv[1] as *u8 }
81 if argc > 2 { cemin = rc_atoi(argv[2] as *u8) }
82 if argc > 3 { topk = rc_atoi(argv[3] as *u8) }
83 if topk > RC_TOPK_MAX { topk = RC_TOPK_MAX }
84 let g: *EcoGraph = eg_load(storep)
85 if (g as i64) == 0 { rc_w(2, "atlas graph not found (unseeded)\n" as *u8); return 1 }
86 let n: i64 = g.node_count
87 let topi: *i64 = sys_mmap((RC_TOPK_MAX+2)*8) as *i64
88 let topc: *i64 = sys_mmap((RC_TOPK_MAX+2)*8) as *i64
89 var nk: i64 = 0
90 var i: i64 = 0
91 while i < n {
92 let ce: i64 = g.ce_arr[i]
93 if ce >= cemin {
94 if rc_is_scaffold(g, i) == 0 {
95 if nk < topk { topi[nk] = i; topc[nk] = ce; nk = nk + 1 } else {
96 var mj: i64 = 0
97 var mv: i64 = topc[0]
98 var j: i64 = 1
99 while j < nk { if topc[j] < mv { mv = topc[j]; mj = j } j = j + 1 }
100 if ce > mv { topi[mj] = i; topc[mj] = ce }
101 }
102 }
103 }
104 i = i + 1
105 }
106 if nk < 2 { rc_w(2, "fewer than 2 integrative product nodes at ce-min\n" as *u8); return 0 }
107 rc_w(1, "=== nx_atlas_recombine v2: novel PRODUCT-recombination candidates (live atlas, scaffolding-filtered) ===\n" as *u8)
108 rc_w(1, "over-nodes=" as *u8); rc_wn(1, n); rc_w(1, " integrative-topK=" as *u8); rc_wn(1, nk); rc_w(1, " Ce-min=" as *u8); rc_wn(1, cemin); rc_w(1, " (best orthogonal partner per node)\n" as *u8)
109 var nout: i64 = 0
110 var ai: i64 = 0
111 while ai < nk {
112 var best_bi: i64 = 0 - 1
113 var best_sc: i64 = 0 - 1
114 var best_sh: i64 = 0
115 var bi: i64 = 0
116 while bi < nk {
117 if bi != ai {
118 let a: i64 = topi[ai]
119 let b: i64 = topi[bi]
120 var linked: i64 = rc_imports(g, a, b)
121 if linked == 0 { linked = rc_imports(g, b, a) }
122 if linked == 0 {
123 let sh: i64 = rc_shared(g, a, b)
124 var score: i64 = topc[ai]
125 if topc[bi] < score { score = topc[bi] }
126 score = score - sh*4
127 if score < 0 { score = 0 }
128 if score > best_sc { best_sc = score; best_bi = bi; best_sh = sh }
129 }
130 }
131 bi = bi + 1
132 }
133 if best_bi >= 0 {
134 if best_sc >= cemin {
135 rc_w(1, "RCB" as *u8); rc_wn(1, nout); rc_w(1, " " as *u8)
136 rc_wname(1, g, topi[ai]); rc_w(1, " X " as *u8); rc_wname(1, g, topi[best_bi])
137 rc_w(1, " score=" as *u8); rc_wn(1, best_sc)
138 rc_w(1, " [composes " as *u8); rc_wn(1, topc[ai]); rc_w(1, "+" as *u8); rc_wn(1, topc[best_bi]); rc_w(1, ", shared " as *u8); rc_wn(1, best_sh); rc_w(1, "]\n" as *u8)
139 nout = nout + 1
140 }
141 }
142 ai = ai + 1
143 }
144 rc_w(1, "RECOMBINED proposals=" as *u8); rc_wn(1, nout); rc_w(1, " (structural; semantic/market rank = next rung via dmktneeds- + judge)\n" as *u8)
145 return 0
146}