# Early-refresh cohort arithmetic

Original Hesela teaching calculation, 2026-11-20. No observed workload data.

For m simultaneous requests, remaining lifetime r, previous recomputation duration
delta > 0 and beta > 0, use p = exp(-r/(beta*delta)). Independent refresh choices
give K ~ Binomial(m,p). The JSON reports E[K], P(K=0), P(K=1), P(K>=2).
Metadata is fixed and all decisions precede any refresh completion. This is not
expected stampede size sampled over a renewal workload and not a throughput result.

The three rows use m=20, delta=1 second, beta=1 and r=1,3,5 seconds. Inputs are
illustrative. No confidence interval is appropriate: no population was sampled.
Decimal evaluation uses 70 digits internally before conversion to JSON numbers;
display rounding is not physical accuracy. Positive binomial terms avoid subtracting
nearly equal numbers when computing the multiple-refresh tail.
The API accepts integer request counts from 0 through 1000. Nonzero numeric inputs
must remain nonzero and finite when represented as Python floats. Extreme scales
can round probabilities to zero or one; those boundaries return a degenerate
distribution rather than attempting Decimal zero to the zeroth power.

Python 3.12+ standard library, no external dependencies or seed:

    python3 -B model.py --check
    python3 -B -m unittest discover -s . -p test_model.py

The independent oracle convolves Bernoulli probabilities over 270 configurations.
Boundary cases include zero/one request, the deadline, invalid/nonfinite inputs,
time-unit invariance and very small multiple-refresh tails. No deployed-cache API
or concurrency implementation is tested. Recompute durations can change with load;
the calculation holds the previous duration fixed.

Source of the refresh rule: Vattani, Chierichetti and Lowenstein, PVLDB 2015,
section 5, Figure 3: https://cseweb.ucsd.edu/~avattani/papers/cache_stampede.pdf
The code implements probability arithmetic, not copied paper pseudocode.
Original code: MIT, see LICENSE. Source papers retain their own licenses.
