// lossscan2113.c -- job #2113: certificate-loss fractions, arithmetic tile vs independent-thinning null. // Same conventions and exact reductions as lossscan762.c (return #1076): support = offsets s in [1,L]; prime q at // phase t kills s iff (s+t) mod q in {0,q-2}; envelope loss l = min(exact, quadruple, smallest pair-only atom) > 0 // needs a quadruply killed position (16N candidate phases); chordal loss l_c = min(exact, smallest atom) > 0 needs // two disjoint pair-only positions (16N^2 candidate phases). Both maxima over ALL phases equal the maxima over the // candidates. Modes: // arith L q0 q1 q2 q3 : all W=510510 starts of the tile T17 (grain: slots are == 5 mod 6) // thin L q0 q1 q2 q3 M seed p : M random windows; each grain offset s in [1,L] with s == 5 mod 6 kept w.p. p // Output: JSON with counts of windows having positive envelope loss and positive chordal loss (and N histogram). #include #include #include #include #include #define MAX_N 96 typedef struct { uint64_t lo, hi; } Mask; static int pop(Mask a){ return __builtin_popcountll(a.lo)+__builtin_popcountll(a.hi); } static Mask band(Mask a, Mask b){ return (Mask){a.lo&b.lo,a.hi&b.hi}; } static Mask bor(Mask a, Mask b){ return (Mask){a.lo|b.lo,a.hi|b.hi}; } static Mask bnot(Mask a){ return (Mask){~a.lo,~a.hi}; } static const int EDGE[6][2]={{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}}; static const int COMP[6][2]={{2,3},{1,3},{1,2},{0,3},{0,2},{0,1}}; static int gcd_int(int a,int b){ while(b){int r=a%b;a=b;b=r;} return a; } static uint64_t rng_s; static uint64_t rng(void){ rng_s ^= rng_s<<13; rng_s ^= rng_s>>7; rng_s ^= rng_s<<17; return rng_s; } /* returns 2 bits: bit0 = envelope loss > 0 at some phase, bit1 = chordal loss > 0 at some phase */ static int losses(const int *offsets, int N, const int *q){ if(N==0) return 0; Mask masks[4][37]; for(int i=0;i<4;i++) for(int t=0;t>i)&1 ? q[i]-2 : 0; int sref=(i<2)?s0:s1; t[i]=((target-sref)%q[i]+q[i])%q[i]; m[i]=masks[i][t[i]]; } Mask un=bor(bor(m[0],m[1]),bor(m[2],m[3])); int exact=N-pop(un); int minatom=1<<30; for(int e=0;e<6;e++){ int a=pop(band(band(m[EDGE[e][0]],m[EDGE[e][1]]),bnot(bor(m[COMP[e][0]],m[COMP[e][1]])))); if(a0) env=1; } else { int l=exact; if(minatom0) chord=1; } } if(mode==0 && env) break; if(mode==1 && chord) break; } } return env | (chord<<1); } int main(int argc,char**argv){ if(argc<7){ fprintf(stderr,"usage: arith L q0..q3 | thin L q0..q3 M seed p\n"); return 2; } int L=atoi(argv[2]), q[4]; for(int i=0;i<4;i++) q[i]=atoi(argv[3+i]); clock_t c0=clock(); long long n_env=0, n_chord=0, n_win=0; long long hist[MAX_N+1]; memset(hist,0,sizeof hist); int offsets[MAX_N]; if(!strcmp(argv[1],"arith")){ int W=510510; unsigned char*slot=malloc(W); for(int r=0;r=MAX_N) return 3; offsets[N++]=s; } int r=losses(offsets,N,q); n_win++; hist[N]++; if(r&1) n_env++; if(r&2) n_chord++; } free(slot); } else if(!strcmp(argv[1],"thinN")){ /* matched-N null: N drawn from a histogram file (pairs "N count" per line), then N distinct grain offsets uniformly */ long long M=atoll(argv[7]); rng_s=strtoull(argv[8],NULL,10)*2654435761ULL+88172645463325252ULL; FILE*hf=fopen(argv[9],"r"); int hn[MAX_N+1]; long long hc[MAX_N+1]; int nh=0; long long tot=0; int a,b_; while(hf && fscanf(hf,"%d %d",&a,&b_)==2){ hn[nh]=a; hc[nh]=b_; tot+=b_; nh++; } if(hf) fclose(hf); int G=(L>=5)?((L-5)/6+1):0; int grain[MAX_N*8]; for(int g=0; gG) N=G; int pool[MAX_N*8]; for(int g=0; g>11)*(1.0/9007199254740992.0); if(u=MAX_N) break; offsets[N++]=s; } } int r=losses(offsets,N,q); n_win++; hist[N]++; if(r&1) n_env++; if(r&2) n_chord++; } } printf("{\"mode\":\"%s\",\"L\":%d,\"q\":[%d,%d,%d,%d],\"windows\":%lld,\"env_positive\":%lld,\"chordal_positive\":%lld,\"env_frac\":%.6f,\"chordal_frac\":%.6f,\"N_hist\":[", argv[1],L,q[0],q[1],q[2],q[3],n_win,n_env,n_chord,(double)n_env/n_win,(double)n_chord/n_win); int comma=0; for(int v=0;v<=MAX_N;v++) if(hist[v]){ printf("%s[%d,%lld]",comma?",":"",v,hist[v]); comma=1; } printf("]}\n"); fprintf(stderr,"[timing] %s L=%d cpu=%.1fs\n",argv[1],L,(double)(clock()-c0)/CLOCKS_PER_SEC); return 0; }