# Finite-resource amplification and readout windows

A blank reaction starts with zero active units. A loaded reaction starts with a
Poisson number of active units. Both then gain one unit at rate
`(background + growth * count) * (1 - count / capacity)` until the detector
latches at the threshold. A later deadline reduces missed calls but increases
blank-positive calls. This code determines whether those constraints overlap,
and whether an instrument's observation grid reaches that overlap.

The source is *Finite-resource amplification can eliminate diagnostic readout
windows: certified small-threshold instances and large-threshold regimes*,
16 September 2026. The source model, Table 1 witnesses, rate-scaling result,
robustness endpoints, and large-threshold gamma laws are implemented here.
The manuscript hash is in `example.py`. Code is original, written from the
equations; the author's scripts and formal development are not bundled.

## Inputs and reusable components

Edit USER INPUTS near the top of `example.py`. Threshold and capacities are
integer effective counts, with capacity at least threshold. The default
background rate .01 units/minute and growth rate 1/minute, loading mean 4,
threshold 5, capacities 5 through 10, blank limit .01, and miss limit .05 are
the paper's illustrative preset. They are not laboratory calibration or clinical
performance estimates. The observation grid is every .1 minutes from zero.
Rates must be positive, loading nonnegative, and error limits strictly between
zero and one. Decimal strings preserve exact rational input for certificates.

`BirthSource` owns the finite-resource rate law. `PoissonLoading` owns activation
weights. `FiniteChain` builds a row-sum-zero generator, including its absorbing
state; it can also accept independent positive multipliers of each state rate.
`ErrorLimits` locates the numerical interval and feasible grid frames.
`ExactWitness` independently builds rational spectral coefficients and encloses
the exponential factors with exact Taylor/remainder arithmetic. `LimitLaw`
evaluates the large-threshold gamma or product-gamma distribution independently
of any finite-state matrix. No base-class framework is needed to compose them.

For example, change loading and an observation schedule without changing the
reaction model or plotting code:

```python
from example import BirthSource, PoissonLoading, FiniteChain, ErrorLimits

source = BirthSource(threshold=20, capacity=40)
chain = FiniteChain(source, PoissonLoading('4.5'))
print(ErrorLimits(blank=.01, miss=.05).window(chain, grid_step=.05))
print(chain.errors(4.8))
```

The dense matrix method is capped at threshold 200 to avoid accidental huge
allocations. Exact spectral checks are capped at threshold 20 and require
distinct transient rates. Repeated rates remain supported by `FiniteChain`.
The large-threshold evaluator uses harmonic/digamma identities to evaluate the
paper's deadline sums without allocating a hundred-million-state chain.

## Run and test

Python 3.11 or newer; direct dependency pins are in `requirements.txt`.

Windows PowerShell:

```powershell
py -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txt
.\.venv\Scripts\python.exe example.py --output outputs
.\.venv\Scripts\python.exe -m unittest -v
```

POSIX:

```sh
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python example.py --output outputs
.venv/bin/python -m unittest -v
```

No network access is needed after dependencies are installed. Outputs include
tradeoff curves, numerical window endpoints and grid frames, limiting error
probabilities, exact rational witness intervals, summary, actual console output,
and source/environment/output hashes. PNG figures have editable SVG counterparts.
The direct pins are not a complete transitive lock.

## Read the outputs

At threshold five, capacities 5, 6, and 7 have a separating deadline where both
errors exceed their limits. Before that time sensitivity fails; afterwards blank
control fails. This excludes *every* deadline by monotonicity, rather than just
every sampled point. Capacity 8 admits 3.45 minutes, but the miss at 3.4 and blank
at 3.5 exclude every frame on the .1-minute grid. Capacity 9 reaches that grid.
Capacity 10 is feasible throughout 3.15 to 3.30 minutes. The program checks these
strict comparisons using exact rational interval endpoints. It also checks the
two endpoint inequalities behind the paper's 2% fixed-rate uncertainty result.

About 37.1% of the loaded default reactions start above threshold. The code keeps
that probability: it does not condition the Poisson load on being below threshold.
The small-threshold example is therefore an effective counting model. At large
threshold, this initial detection probability disappears while the resource
effect remains.

Multiplying *all* rates by two replaces time t by 2t and leaves the continuous
error tradeoff unchanged. Increasing capacity changes individual state delays,
which affects blank and loaded reactions differently. The capacity sweep fixes
background, growth, loading, and threshold. A laboratory intervention that also
changes these parameters is a different comparison.

In the fixed-headroom limit, the startup Gamma variable is multiplied by an
independent Gamma variable with shape `headroom + 1`. Integrating their product
law reproduces the paper's limiting misses: about 5.0274% for two units and
4.6395% for three. Growing reserve removes the terminal randomness and gives
about 3.9625%. These are limiting laws, not finite-threshold error bounds.
In particular the narrow two-unit margin must not be generalized to arbitrary
finite thresholds.

## Evidence and numerical limits

- `exact_witnesses.json` contains exact fraction endpoints. Signed spectral
  coefficients are propagated with sign-aware interval operations. Positive
  exponential Taylor tails use a geometric bound, with exact outward rounding.
  These Python rational certificates check finite inequalities; they do not
  compile or replace the paper's Lean proof.
- Finite window endpoints and plotted probabilities use SciPy matrix
  exponentials/root finding. A numerical near-tie is reported unresolved.
- Limit curves use adaptive quadrature. Saved error estimates describe that
  numerical method, not rigorous interval bounds. The omitted Poisson loading
  mass is separately bounded and is below 1e-13 in the default.
- The large-threshold output evaluates the paper's theorem at h >= 1e8 using
  its four published scalar bounds plus exact rational concentration allowances.
  It explicitly imports those bounds; it does not replay their directed-integral
  certificates or claim a full finite-h probability calculation. Deadlines use
  floating-point digamma evaluations. The evaluator is enabled only for the
  paper's background/growth ratio, loading and error limits.
- Tests independently compare exponential bounds to 90-digit Decimal arithmetic,
  compare finite probabilities to rational witnesses, check probability
  accounting and a one-birth analytic limit, test coincident rates, verify clock
  scaling and rate order, and check the fixed-headroom decision margin.

The code concerns per-reaction model probabilities. It neither fits experimental
data nor establishes specimen-level performance, molecular realization, or
patient-specific decisions.

MIT is proposed for this new original code pending the owner's licensing choice;
no repository-wide software license was present. This does not relicense the
manuscript, third-party packages, or the author's existing code.
