# Thermochemically consistent realization of an autocatalytic exporter

This example connects explicit reversible chemistry to a marked finite-copy reactor, a joint operating certificate and physical supply accounting. It follows manuscript entry 41, SHA-256 `2b3d026fac78d73fdb8733abd0fb3b79a45b4a8f50f454159589c97a298eae6c`. The model is a schematic construction with illustrative units, not fitted elementary reaction chemistry.

## Run and change inputs

Use Python 3.11 or newer in an isolated environment:

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

Edit the constants at the top of `example.py`: copy scale, paired release and cleavage speeds, maintained fuel/waste activities, duration, target failure, concentration, time unit and temperature. Rational strings preserve exact coefficients. The main run takes several seconds and evaluates bounds plus deterministic illustrations; it does not simulate the enormous number of individual events in the default physical reactor.

`--simulate` adds a direct stochastic path with a configurable event budget. An unfinished path returns no operating verdict. Food feeds alone create order V events per time unit, so the default 20,000-event budget is deliberately insufficient to classify a V=100,000,000 run. Reduce V to inspect individual-event behavior, while remembering that the large-scale success bounds can then be uninformative. Observation boundaries do not reset the chemical state or resource ledgers.

## Chemical objects and their roles

Internal species are foods U,W, free template X, complexes C1,C2 and duplex Z. Fuel F and waste P are explicit in the chemical completion, then maintained externally for the projected reactor. Six reversible pairs are:

| Pair | Forward / reverse constants |
|---|---|
| U+W <-> X | epsilon / (epsilon/10) |
| X+U <-> C1 | 20 / 20 |
| C1+W <-> C2 | 20 / 20 |
| C2 <-> Z | 20 / 2 |
| Z <-> 2X | r / r |
| X+F <-> U+W+P | delta / (delta eta) |

Here epsilon=1/500,000,000 and eta=1/8,000,000,000. The certificate covers paired speeds 19<=r<=21 and 1/50<=delta<=1/25, with unit maintained activities. Both directions of a pair change together. The main demonstration uses r=20 and delta=3/100. Food immigration has rate V per food; each internal species washes out at its own molecule count.

`ChemicalPair` keeps full reactant/product labels, coefficients and projected channel labels together. `CompletedExporter` constructs the completed chemistry independently of the bundled source reactor. At unit activities, its exact coefficient, jump and mark for every label agree with `reference_source.DrivenReactor`. That module is a self-contained extraction of this repository's entry-25 example, recorded in `provenance.json`, and supplies generic propensity, event and observation machinery. No other example folder is needed to run the ZIP.

Material compositions in the order U,W,X,C1,C2,Z,F,P are (1,0,0), (0,1,0), (1,1,0), (2,1,0), (2,2,0), (2,2,0), (0,0,1), (0,0,1). All species carry nonzero conserved composition in the closed chemistry. One common set of standard potentials g/RT is

```text
0, 0, -log(10), -log(10), -log(10), -2 log(10), log(8e10), 0.
```

Rational Boltzmann weights exp(-g/RT) verify every rate ratio exactly. The internal stoichiometric matrix has rank four and two cycle generators: (-1,1,1,1,1,0) is passive; (1,0,0,0,0,1) converts F to P. Their affinities are zero and log(8e10). The full chemical matrix has rank five. Feed and collection operations are external services; this does not assert that the complete open apparatus is an equilibrium system.

`neighboring_ratio()` checks local detailed balance between a forward event's initial count state and its reverse event's final count state. Its count potential includes log(n!) and -n log(V), plus the reservoir contribution. In particular, 2X association uses r*nX*(nX-1)/V without an extra factor 1/2. Testing a forward/reverse ratio at the same state would not check this identity.

## What operation means

Preparation is food only: (V,V,0,0,0,0). The inherited observation model uses food-equivalent totals A and B and the weighted catalyst

```text
Y = X + (9/8) C1 + (7/5) C2 + (9/5) Z.
```

Over T=500+H, the joint event requires both resources to stay between 0.9V and 1.1V, Y to reach V/2500 by time 500 and thereafter stay above V/5000, and every complete unit output window after startup to export at least V/5000 marks. Washout of X,C1,C2 contributes four marks; Z contributes eight. Thus export divided by four counts mixed template equivalents, including bound species. It is not a count of purified free X.

The same event bounds each food-feed ledger by 2VT and the gross driven ledger QF+QP by VT/8. Gross exchange counts both directions; it is not net fuel depletion. Fractional final durations contribute to resource accounting but do not create an incomplete output window.

`OperatingCertificate` evaluates all nine error terms, omitting the window term when floor(H)=0. Their sum B gives max(0,1-B) as the success lower bound. Log-domain arithmetic prevents underflow; outward mpmath intervals check target claims and the downward-rounded six-decimal result. The probability inequality itself is the paper's theorem, not established by this numerical calculation. The certificate rejects changed activities, out-of-rectangle speeds and a disabled reactor.

| V, with H=100 | Certified success lower bound | Disabled output-schedule upper bound |
|---|---|---|
| 100,000,000 | 0.923849 | <10^-21699 |
| 200,000,000 | 0.994201 | <10^-43414 |
| 300,000,000 | 0.999558 | <10^-65128 |

The disabled comparison removes only labels 6 and 7, the C2/Z ligation pair. It preserves the food process, basal channels, driving channels, marks and window schedule. Its theorem bounds the output schedule, without requiring successful catalyst entry. The displayed disabled bound is implemented for integer H>=1; an uninformative bound is not displayed as a probability claim.

**Arithmetic correction:** the prose after the paper's Corollary 6.2 says the full budget certifies 99% at V=10^8. Direct evaluation gives about 92.3849%, consistent with its Table 5. For failure 1/100 and H=100, a monotone integer search over V>=10^8 finds 178,838,783 as the smallest interval-accepted full-budget scale in that domain. The simpler sufficient formula gives 264,915,869. Neither number is the smallest physically successful reactor.

Before the first template, only basal assembly and reverse driven cleavage seed X. The paper's initiation argument gives a failure floor exp[-500*(epsilon+delta*eta)*V]. Using the largest allowed delta gives the uniform necessary integer scale 4,593,686 for 99% success. The necessary and sufficient scales leave a substantial gap. The initiation argument uses a reference immigration/death food process; it does not assume that actual foods conditioned on no seeding retain an independent stationary law.

## Density illustration and physical accounting

`CompletedExporter.deterministic()` integrates all six concentrations and eight cumulative ledgers, with the mass-action density field and food-only preparation. Radau and BDF provide an independent numerical comparison. These trajectories are not finite-copy probability estimates. The density method supports 1<=H<=10,000; `OperatingCertificate` separately supports H>=0 without requiring ODE integration.

At c*=1 mM, tau=60 s and 298.15 K, V=10^8 corresponds to 0.1660539 pL. Startup takes 500 minutes; H=100 gives a ten-hour total run. Conditional on operation, every complete minute after startup exports at least 5,000 template equivalents, with 500,000 across all 100 windows. Each feed allowance is 120 billion molecules, in addition to the initial 100 million molecules of each food. The gross driving allowance is 7.5 billion events; its ratio to the guaranteed export is at most 15,000 events per equivalent.

`PhysicalAccounting` scales each full chemical coefficient as k/(tau*c*^(order-1)); the reverse driven step is third order before chemostatting P. Its coefficient must not be dimensionalized as though the original full reaction were bimolecular. The reservoir force is about 62.235 kJ/mol and the specified chemical-work allowance is about 0.775 nJ. These values exclude food preparation, pumping, reservoir maintenance and product purification; they are not a total process-energy or entropy-production claim.

`FiniteBath` tracks forward/reverse exchange explicitly. If each bath initially contains R molecules, a gross-exchange bound G and R>=G/rho imply activities within 1±rho. With rho=1/100, the configured allowance requires 750 billion molecules in each stock, about 1.245 nL each at 1 mM. The reverse/forward effective ratio and affinity then vary within the exported corridors. This implication is conditional accounting on the finite bath's own path: the maintained-activity probability theorem does not transfer to it. A moving bath requires a new operating analysis.

## Reuse and evidence

```python
from example import CompletedExporter, OperatingCertificate, PhysicalAccounting

reactor = CompletedExporter(release='21', delta='1/50')
reactor.certificates()                         # exact chemistry and source identity
for V in (100_000_000, 200_000_000, 300_000_000):
    print(OperatingCertificate(V, 100, reactor).evaluate())
print(OperatingCertificate.sufficient_scales(100, '1/100', reactor))
print(PhysicalAccounting(200_000_000, 100).evaluate(reactor))

# Exploring a changed reservoir law is allowed; its maintained-law certificate is not.
changed = CompletedExporter(fuel='3/2', waste='2/3')
trajectory = changed.deterministic(100)
```

To extend chemistry, preserve reaction labels and explicit marks where relevant, and derive new conservation/thermodynamic identities and probability hypotheses. The existing theorem is not automatically inherited by an added channel. The secondary resident-model completion in the paper is outside this exporter-focused package.

Outputs include all projected channels, full density and ledger trajectories (ledgers normalized by V), completed-window exports, a scale sweep, exact chemical checks, probability and physical-accounting results, figures and reproducibility hashes. Seven test groups check material/cycle identities throughout the speed rectangle, symbolic labeled propensities and selective deletion, neighboring-count balance, interval bounds and rejected assumptions, initiation/sizing, dimensional accounting and bath exchange, and independent dynamics plus natural count ledgers.

Exact algebra and interval comparisons are freshly evaluated. Infinite-state process identification and probability bounds use the paper's stated results. Lean is not rerun, and a finite collection of count-state checks is not a replacement for the symbolic local-detailed-balance argument.

MIT is proposed for the example code, pending owner approval; this README grants no license and does not change manuscript rights.
