# Reliable autocatalytic operation with a finite fuel–waste bath

Example for manuscript 76, SHA-256 `5627f554fdb4e90cf31a8f38761fd154b3d9c13f3e8d712819e81c462c9c9a5f`.

The fuel and waste are now actual changing inventories. Every driven forward event removes one fuel molecule and creates one waste molecule; the reverse event undoes that transfer. The next cycle starts from the actual reactor **and bath** endpoint. This package provides that count process, a density model, molecular interventions, finite food meters, complete mission ledgers and paper-conditional sizing tools.

## Run and configure

Python 3.11 was tested:

```sh
python -m venv .venv
# Activate the environment for your shell.
python -m pip install -r requirements.txt
python example.py
python -m unittest -v
python example.py --output replay
```

Edit the top of `example.py`: copy scale, mission length, confidence, bath tolerance, output demands, release/drive rates, molecular pulse, small-count simulation budget, and illustrative concentration/time units. The configured mission uses the sharp pure-bath service allowance and therefore requires drive `1/50`; use `MissionCertificate(..., sharp=False)` for the broader admitted class. The canonical three-way comparison remains a separate fixed paper benchmark. The full run takes roughly tens of seconds on a desktop.

Counts and normalized source time define the model. The displayed 1 mM and 60-second references are illustrative, not measured chemistry. The bath and reactor have distinct reference capacities; the density bath derivative contains `V/R`. Physical implementation of their contact requires an explicit convention beyond ordinary same-volume rate conversion.

## Reusable model layers

`chemistry.py` contains the six internal species `(U,W,X,C1,C2,Z)`, twenty reaction/feed/washout labels, falling-factorial count propensities and the three-outcome molecular pulse, adapted from the repeated-harvesting example. Reverse duplex formation uses `N_X*(N_X-1)` with no factorial divisor. `finite_bath.py` supplies the changed source; the internal model's fixed-activity convenience methods are not finite-bath certificates.

`Bath` holds integer reference capacity, fuel and waste. `FiniteBathReactor` multiplies directed drive propensities by current `fuel/capacity` and `waste/capacity`. Fuel zero disables forward consumption; waste zero disables reverse consumption. No logarithm, clipping or artificial replenishment appears at either boundary. The admitted theorem class is `19 <= r <= 21`, `d >= 0`, and `d*M <= R/25`; `d=0` is allowed.

```python
from finite_bath import Bath, FiniteBathReactor, CountMission, HistoryController

reactor = FiniteBathReactor(release='20', drive='1/50')
bath = Bath(capacity=3000, fuel=3000, waste=0)
result = CountMission(reactor).run(
    initial=(0,0,300,0,0,0), V=300, bath=bath, cycles=3,
    controller=HistoryController(), seed=123, event_budget=100000)
```

`CountMission` applies the exact independent molecular pulse, doses integer food, runs all twenty channels for four time units, and marks collection only during the final unit. Its five mission counters are collected template equivalents, included free templates, each food expenditure, and gross driven events. Additional ledgers track all template washout, signed internal synthesis, and both directed drive counts. Every sampled event checks the bath prefix identity `fuel = initial_fuel - forward + reverse`; each completed cycle checks the template inventory identity including withdrawal and extra loss. Bath extrema are tracked across **all events**, not just endpoints.

Controllers see completed returned history, including failures. The supplied controller retains more after a failed cycle. It does not replace the endpoint or reject a bad pulse. An exhausted event budget returns an unfinished status and no success verdict. The small-count run is outside the useful certificate scale and may fail; it illustrates the literal process rather than estimating the theorem probability.

`FoodMeter` implements finite external metered stocks. A requested feed or bolus that cannot be paid triggers shutdown. Before stockout the event rates are exactly the original rates; tests couple a generously funded and unmetered run with the same random draws. This is not a passive tank with concentration-dependent feed. To obtain the paper's no-stockout certificate, allocate each preparation charge **plus** `5*m*V+1`; the extra molecule and the preparation charge must not be omitted.

`DensityMission` uses the same stoichiometry with ordinary mass-action powers, eight changing state coordinates, retained bath, mean pulses and integrated counters. It splits the recovery and collection windows exactly. Radau and BDF endpoint comparisons and conservation residuals are saved. These are deterministic mechanism diagnostics, not finite-count probability validation.

## Certificates and mission design

`MissionCertificate` evaluates the complete error sum with outward interval arithmetic. Repeated material terms are retained. It distinguishes the original phase exponent from `kappa = 1839/8750000000000` and adds the extra sharp-service error when required. Its rational printed success lower bound is checked against the interval endpoint. The one-cycle theorem starts at `V >= 10^6`; the original single-exponential envelope requires `V >= 2*10^11`, the refined envelope `V >= 10^10`, and the simple inverse-design rule uses `V >= 5*10^10`.

The product bound iterates a **conditional** guarantee from actual successful returns. It does not assume cycle independence. It additionally requires an established restart state and admitted pulses; it does not prove startup from food alone. Both collected-output thresholds overlap: free X is included in template equivalents and must not be added as a disjoint yield.

```python
from certificates import design
mission = design(100, '21/1000000', '1/10',
                 template_demand=0, free_demand=0)
print(mission['V'], mission['R'])
```

The design takes the maximum of the useful scale floor, outward-rounded confidence requirement and the two output-demand requirements. A fresh rational positive Taylor sum certifies its chosen confidence scale. Reservoir capacity is integer-rounded from the gross allowance and tolerance. This is a sufficient design, not an optimum or a lower bound.

For the canonical hundred-cycle mission:

| Certificate | Copy scale | Pure fuel capacity | Guaranteed template equivalents |
|---|---:|---:|---:|
| Original | 200,000,000,000 | 40,000,000,000,000 | 357,142,857,200 |
| Refined, reduced scale | 96,000,000,000 | 9,600,000,000,000 | 171,428,571,500 |
| Refined, original scale | 200,000,000,000 | 20,000,000,000,000 | 357,142,857,200 |

The reduced-scale mission exceeds confidence 0.999979; at the original scale the refined failure bound is below `10^-13`. Reducing copy scale also reduces the promised output. `fixed_output_design.json` explicitly keeps the original demand and shows why that demand brings the required scale back up.

The **halved gross allowance `floor(V/10)` requires total bath inventory `M=R` and `d=1/50`**. A loaded bath initially `(R,R)` has `M=2R`, uses `floor(V/5)`, and still benefits from the improved phase exponent. The loaded-force inversion uses its actual larger gross bound; it does not import the pure-bath allowance merely because the manuscript's force corollary writes a hatted budget. At every supported prefix, absolute signed current is bounded by accumulated gross events. This supplies the activity corridor on the same mission event.

## Thermochemistry and what output does not imply

`neighbour_balance` compares the forward propensity to the reverse propensity at the **post-forward** state. This checks local detailed balance even from zero initial waste, where the post-state has one waste molecule. It rejects an inactive `d=0` ratio.

`bath_energy` retains exact symbolic factorial/binomial endpoint expressions. Numerical log-gamma values are separately labeled displays. Pure-bath net current lies in `[0,R]`; loaded-bath current lies in `[-R,R]`. Gross turnover, net current, bath free-energy decrease and extracted useful work are different quantities. Pumping, timing, feeding, collection and separation costs are not included in the bath state function.

The four density runs reproduce the paper's mechanism comparison: pure, loaded, small bath capacity, and zero drive. The small-capacity bath can become nearly depleted while collection continues; with zero drive, collected output remains positive and gross service is zero. Consequently reliable productive operation proves neither positive net fuel consumption nor a required amount of driven service. The code also exposes exact channel-specific quadratic-variation contributions for exploring a future sharper estimate, without treating that local diagnostic as a new theorem.

## Evidence and reuse

The adapted paper replay performs all **92 checks**, retaining the original distinction between exact comparisons and numerical thermochemical/unit displays. Scientific tests check finite-bath boundary propensities, exact material drifts, unconditioned molecular pulses, actual returned states, event-by-event bath accounting, template ledgers, metered shutdown, unfinished simulations, certificate scope, confidence rounding, demand constraints and neighboring detailed balance. PNG/SVG figures, JSON histories and CSV trajectories are downloadable with the code.

The operating-probability, nonexplosion and physical-process identification theorems are **imported from the manuscript**. This code freshly checks source algebra and certificate arithmetic; it does not rerun Lean or claim that simulations prove the process theorem. The source is schematic, has an effective trimolecular reverse drive, assumes an established catalyst stock, and relies on externally implemented feeds, pulses and timing. It certifies finite missions under declared assumptions, not an autonomous indefinitely surviving chemistry.

`source_provenance.json` records the adapted source files and hashes. MIT is proposed for newly written example code, pending the owner's decision; this note is not a license grant.
