/* fold31.c -- independent enumeration of adjacent-kill pairs for T_29 folded by 31. * * Independence from research/a3-08-adjacent-pairs.js: * - T_23 is built from the DEFINITION (r and r+2 both coprime to 23#) by a * direct sieve over all 223,092,870 residues, not by the script's fold * recursion buildTiles(). * - T_29 is streamed from T_23 by the same definitional condition mod 29. * - the pair count walks all 31*D slots of the pre-deletion new tile in * POSITION order and asks of each slot only "does 31 delete it?" * (r == 0 or r == -2 mod 31). It never uses the gap criterion * (g = 0,+-2 mod p), the multiplicity argument, the copy-intersection * identity, or the histogram formula. * - the histogram prediction is computed afterwards from a gap histogram this * program builds itself, so PREDICT and ENUMERATE share no code path. * * Build: clang -O3 -march=native -o fold31 fold31.c */ #include #include #include #include #include #define W23 223092870ULL /* 23# */ #define P29 29 #define P31 31 #define MAXGAP 65536 static double now(void){ struct timespec t; clock_gettime(CLOCK_MONOTONIC,&t); return t.tv_sec+1e-9*t.tv_nsec; } int main(void){ const int qs[] = {2,3,5,7,11,13,17,19,23}; double t0 = now(); /* ---- 1. T_23 straight from the definition ---- */ unsigned char *dead = calloc(W23,1); if(!dead){ fprintf(stderr,"alloc dead failed\n"); return 1; } for(int j=0;j<9;j++){ unsigned q = qs[j]; for(uint64_t r=0;r=P29) m-=P29; if(m==0 || m==P29-2) continue; /* r = 0 or -2 mod 29 */ uint64_t r = base + T23[i]; if(D29==0) first=r; else { uint64_t g=r-prev; if(gG2) G2=g; } prev=r; uint32_t m31 = r31[i]+o31; if(m31>=P31) m31-=P31; if(D29>=D29cap){ fprintf(stderr,"D29 over cap\n"); return 1; } res31[D29++]=(uint8_t)m31; } } uint64_t wrap = first + W29 - prev; /* cyclic gap of T_29 */ if(wrapG2) G2=wrap; printf("T29: D = %llu (expect 214708725), W = %llu, G2 = %llu, wrap gap = %llu, mean gap %.4f [%.1fs]\n", (unsigned long long)D29,(unsigned long long)W29,(unsigned long long)G2, (unsigned long long)wrap,(double)W29/(double)D29, now()-t1); /* ---- 3. brute-force pair enumeration over all 31*D29 slots, position order ---- */ t1 = now(); const uint32_t cW = (uint32_t)(W29 % P31); uint64_t pairs=0, kills=0; uint64_t runs[64]; memset(runs,0,sizeof(runs)); uint64_t run=0, headRun=0; int seenAlive=0, prevDel=0, firstDel=0, lastDel=0; for(int k=0;k