# Material and kinetic costs of productive chemical memory

Runnable example for manuscript 74, SHA-256 `e95aab6b325f1d7d500ee7f13bf8d287e15f308bf38a561f02e5ebf3d819e32c`.

A chemical batch must do two things **on the same path**: make the product quota and leave enough intact memory carriers that both complementary daughters restart correctly. Product formation consumes the pool that also supplies those carriers. This package models that competition, reproduces exact finite-count guarantees, and exposes the material and mechanism costs of two different encodings.

## Run and edit

Python 3.11 was tested:

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

The complete default replay takes several minutes on one core. Inputs at the top of `example.py` set inventory, quota, deadline, release band, partition bias, uncertainty, search budgets, corridor parameters and simulation seed. Rational strings retain exact input values. The support deadline must be an integer for this particular uniformization block implementation. A search/event/overflow limit raises an error rather than claiming a failed design. The two illustrative comparison bars are explicitly the paper's canonical benchmarks; edited experiment values are in the JSON/CSV outputs.

**Units:** these are molecule counts at fixed reference volume and constructed count-rate constants per model time. Neither the time unit nor a physical volume is calibrated. Reverse replication uses `n(n-1)`, without an extra factor one-half. Changing volume at fixed concentration requires converting rate constants and is not the same experiment as changing the inventory here. A material unit or fuel token is not a unit of chemical work.

## Reusable components

`memory.py` separates kinetics, finite state-space assembly, allocation, protocol, certificates and cooperative-gate architecture. There is no shared framework required by other papers.

```python
from fractions import Fraction as F
from memory import SupportRates, SupportReactor, ComplementaryAllocation, SerialProtocol
import numpy as np

# Untie the two complex exits to explore their competing effects.
reactor = SupportReactor(32, SupportRates(dissociation=F(10), release=F(20)))
states, diagnostics = reactor.deadline(5, 4, ComplementaryAllocation(F(1,2)))
history = SerialProtocol(reactor, 5, 4).lineage(
    (31,0,0), 10, np.random.default_rng(123))
```

The state `(n,c,p)` contains free carriers, intact complexes and product. Food is reconstructed as `K-n-2c-p`. Complexes weigh two material units but are **one allocation object**. `SupportReactor.transitions` supplies all six channels, `generator` returns the full finite generator, and `deadline` solves its backward equation on payoff columns (no transpose). Diagnostic columns are joint success, quota failure, quota-met allocation failure, expected carriers, food and product. The two failure columns are disjoint and sum with success to one.

`SerialProtocol` harvests all product, partitions free carriers, complexes and remaining food once, refills **both** daughters, and continues with predesignated daughter A, even after failure. It does not select successful descendants. Each record verifies `refill_A + refill_B = K + harvested_product`. Total supply is the initial `K` plus all refills. At ten successful cycles, `K=32,q=4` costs at least 392 units and yields at least 40 products; the sibling inventories are included. A sample path is an illustration, not a reliability estimator or certificate.

`IntegerEnvelope` accepts groups of channels driven by shared rational parameter intervals. Every channel must occur exactly once. It uses the supplied paper kernel: a rowwise minimum over endpoint **one-step kernels**, downward integer rounding and a truncated Poisson sum. It never minimizes an already exponentiated deadline matrix. The complementary payoff supplies upper bounds. Values are integers over `2**31`; the implementation checks overflow margins before iterating. The source kernel requires positive integer channel multipliers; put rational factors in the group's interval endpoints.

```python
from memory import IntegerEnvelope
from ctmc_certificate import nominal_groups
certificate = IntegerEnvelope(32, tuple(nominal_groups(10,20)), 5, 4).run()
# lower / denominator is a uniform lower bound, not an exact probability.
```

`Corridor` defines allowed daughter counts and the growth increment. `CooperativeGate` supplies the literal four mirrored mass-action channels on `(X,Y,F,H,W,PX,PY)`, exact falling-factorial propensities, normalized rational rate constants, exact partition probabilities and a rational clock lower bound. `transitions` checks both conserved pools. At every admitted newborn only the selected forward channel is enabled; at its successor only its reverse is enabled. Tests check this closure for both labels against the independently calculated pair rates. The two-state formula is consequently exact for this architecture, not a quasi-steady-state reduction.

`frontier_proportion.frontier` exhaustively searches the stated gate class using endpoint reduction. The partition probability must be **strictly** above target, because finite positive rates give a clock factor below one. The adapted source fixes its non-strict comparison and rejects a cap that does not enclose the incumbent. Neither change alters the published witnesses. Extend the cap before interpreting a new search; a cap exception means unresolved. For each returned design the driver constructs actual positive rational kinetics and reports whether the configured clock bound meets the target.

## What the default run demonstrates

* The support model's robust minimum is **32**, with exact lower numerator **2145514420** over `2**31` for tied release constants in `[10,20]`. Every smaller inventory is excluded by the carrier ceiling or a fresh upper certificate, not an assumed monotonicity.
* Untying the exits to dissociation 20/product release 10 raises this particular source's minimum to **42**. Changing only product release from 10 to 20 also excludes inventory 32, this time at a bound seed: better harvest can mean worse daughter retention. `failure_mechanisms.csv` explains the two failures with the full floating backward equation; it is not used by the exact certifier.
* The support bias `[0.39,0.61]` and tied-rate-box half-width `1/300` are separate guarantees. The rate box has **five independent groups**, with the two exit constants tied. It is not six independent rate uncertainties, and these two robustness results are not combined. The wider `1/250` box is reported as undetermined when its lower and upper bounds straddle the target.
* The cooperative reference uses core **414** plus one token, reaction molecularity **229**, and has a fresh joint lower bound above **0.9997**, hence a ten-cycle bound above **0.997**. Its bias result above 0.9996 on `[0.49,0.51]` belongs to that reference construction. It is not inherited by smaller optimized gates.
* The cooperative class minima are core **230** at target 0.999, **253** at 0.9995, and **375** at 0.9995 with at least eight minority molecules per daughter. Add one token to initial supply. The 253-core result is **not** at target 0.9997. Rate spread and molecularity remain mechanistic costs even though the search allows arbitrarily fast rational clocks.
* The six reliability-scaling points are freshly searched. The observed coefficient near `33.3 log(1/delta)` is empirical; the paper's order bound has different constants. No support-model scaling law is inferred from its finite table.

## Evidence and limits

Saved JSON records exact integer certificates, search witnesses, exact rational allocation/clock bounds and one complete lineage ledger. CSV records numerical terminal diagnostics and exact-frontier sizes with numerical display ratios. PNG/SVG figures explain the two failure modes and the architecture-specific comparison. `run_metadata.json` hashes the manuscript, modules, inputs and outputs; timings are excluded from scientific replay comparisons.

The source certificate kernel and probability helpers are attributed in `source_provenance.json`; the class search has the two explicitly recorded guards above. Tests compare an exact envelope to independently assembled full finite generators, check complement dependence, weighted conservation, intact-complex partition, both-daughter refill, exact gate closure and endpoint reduction under bias, and regenerate the three class minima.

The paper's generator-to-protocol argument, search exhaustiveness and integer recurrence execution remain conventional computer-assisted evidence. Lean is **not rerun** here. Source hashes establish provenance, not correctness. The support frontier concerns one elementary source and rate/deadline specification; the cooperative frontier concerns a permissive high-order gate class. Neither establishes a universal lower bound for every possible proportion-memory chemistry. Elementary refinements, contamination correction, clumped allocation, post-division repair and whole-family-tree reliability require new models and proofs.

The text's descriptions of a fully independent six-rate box and a twentyfold bias-tolerance difference should not be propagated: the implemented box ties the exits; the quoted symmetric bias half-widths differ elevenfold, and the two encodings' displayed bias results have different targets/constructions. This example states each verified claim separately.

## Reuse permission

MIT is proposed for the new example code, pending the owner's license decision. This note is not a license grant. The source-derived numerical helpers are identified separately in the provenance file.
