# Global production optima and sharp response capacity

A reusable mass-action construction for *Global Production Optima and Sharp Response Capacity*. Original PDF SHA-256: `bcdd5807347a31ab417f017f3dc921ae79bbf33d3cc9a184b3ed089b73e0720b`.

The controlled species X is held at a chosen concentration; the remaining species relax internally. A stationary production state has every reaction current proportional to the positive source mode g, so the net internal production is zero and the net X production is J. The paper asks how to design a **global maximum of this stationary production current**, and what thermodynamic and reverse-turnover costs that design entails.

## Run and edit

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

Use Python 3.11 or later. Editable inputs at the top select recycling order, response ratio, production current, reverse one-way flux budgets, equilibrium constants, and transient initial states. Defaults are the manuscript's dimensionless theoretical examples, not measured chemical parameters. Outputs include exact algebra/linear-program certificates, four CSV tables, two figure pairs, console output and hashed provenance. No Lean project is run.

The default two-reaction system is `X <-> Y`, `2Y <-> 2X+Y`. With response ratio `r=3/2` and current `J=1`, the code constructs forward rate constants `(3,7)` and reverse constants `(2,6)`. The positive stationary curve has a unique global production maximum at `(X,Y)=(1,1)`, with current 1. Its thermodynamic response product is `Phi=7/4`; the sharp infimum for this family is `L=3/2`, which no strictly forward-response profile attains.

## Construction and reusable components

`SquareSource` accepts nonnegative integer reactant and product arrays with species as rows and reactions as columns. Both the reactant matrix `Sp` and net matrix `S=Sm-Sp` must be invertible. It computes `T=Sp^-1 Sm` and `g=S^-1 eX`, and requires `T>=0`, `g>0`. These restrictions are material: this example is not a general theorem for arbitrary reaction networks. Natural integer thermodynamic weights are `w=N*g`, using a common denominator N.

A `ResponseProfile` starts with a vector `f>0` satisfying `T.T*f>f`. The component ratios are `q=(T.T*f)/f>1`. The species logarithmic tangent is `u=Sp^-T*f`; the code normalizes it to `u_X=1`. The reaction responses f need not all be 1. The thermodynamic product is `Phi=product(q_i**w_i)`.

`MassActionRealization` constructs reverse and forward one-way fluxes `vminus=J*g/(q-1)` and `vplus=q*vminus`. At the unit reference composition these are the rate constants. Its exact symbolic currents, vector field, numerical field, controlled ODE integration and local branch curvature are separate interfaces; callers can replace the integration or analysis layer without altering the reaction model.

If equilibrium constants K are prescribed, the constructor computes `log(z*)=S^-T log(K/q)`, then divides each one-way flux by its reference-state monomial to obtain rate constants. For default `K=(9/4,14/9)`, the reference is `(2,3)`, forward constants `(3/2,7/9)` and reverse constants `(2/3,1/2)`. The design currents and response product are unchanged. The identity `Phi=(Xeq/X*)**N` connects the product to the controlled concentration relative to equilibrium.

```python
from example import RecyclingFamily, ReverseBudget

family = RecyclingFamily(m=3)
model = family.realize(r='4/3', current='1/2')
print(model.kp, model.km)
print(model.field([1.0, 1.0]))
print(ReverseBudget(family.source, [3, 10]).certificate('1/2'))
times, internal = model.controlled_trajectory([0.2], end=3)
```

The controlled trajectory holds X at its design concentration. During transients the external controller may supply X as well as remove it. The source construction guarantees a stationary current optimum; it does not guarantee attraction for every source matrix. Negative numerical trial states can be evaluated by the polynomial field during implicit integration, but all reported trajectories must remain positive.

## Why the maximum is global

Normalize any positive composition by the reference state and set `xi=Sp.T*log(z/z*)`. Select a reaction k that minimizes `xi_i/f_i`. Nonnegativity of T implies `(T.T*xi)_k >= q_k*xi_k`. The resulting normalized reaction current obeys

`C_k <= [q_k*exp(xi_k)-exp(q_k*xi_k)]/(q_k-1) <= 1`.

This is an **all-state bottleneck inequality**. At a stationary state all `C_i=J/J0`, so it bounds the production current on every positive stationary component, not just a branch near the design. Away from stationarity, other individual reaction currents can exceed 1. `bottleneck` returns the selected index, all normalized currents and the two nonnegative gap terms. Its floating-point evaluations illustrate the analytic argument; random samples do not establish the general theorem.

Graph edges are `i -> j` when `T[j,i]>0`. A strongly connected graph yields uniqueness of the maximizing state. The more general implemented sufficient criterion is a unique terminal strongly connected component plus a positive vector b on each transient block satisfying `T_CC*b<=b`. `HomogeneousCone` returns an exact rational primal or Farkas dual witness. A failed subcritical criterion alone is not labelled a proof of nonuniqueness.

`local_curvature` checks the rank of the bordered stationary equations and a nonnegative left null vector, then evaluates the exact negative second derivative with respect to log controlled concentration. This is stationary-branch curvature, not a dynamical eigenvalue.

## Capacity, finite budgets and current rescaling

`RecyclingFamily(m)` implements `X <-> Y`, `mY <-> 2X+(m-1)Y`, with `m>=2`. Its forward cone is exactly `1<r<2` and

`Phi = r+(2-r)/m`, `L=1+1/m`, `vminus1=J/(r-1)`, `vminus2=J*m*r/(2-r)`.

As r approaches 1, Phi approaches L but the first reverse one-way flux diverges **at fixed positive output J**. Scaling J toward zero can keep both rates bounded; that gives up a fixed output requirement. The CSV records both constructions so these claims cannot be confused.

`ReverseBudget` encodes required output and reverse one-way flux caps as `D*f>=0`, `f>=1`, where `D=T.T-diag(1+J*g/beta)`. It obtains a rational witness and rechecks every inequality. If infeasible, it solves for `y>=0`, `y.T*D<=0` with strictly negative row sum and checks that certificate exactly. Solver status alone is not accepted. These are budgets on reverse one-way flux at the design state, not universal bounds on rate constants or flux along a transient.

For the recycling family the feasible interval is `[1+J/beta1, 2*beta2/(beta2+m*J)]`. Its lower endpoint minimizes Phi when the interval is nonempty. Default caps `(2,6)` allow at most `J=1`; at that current the interval is the singleton `r=3/2`, giving `Phi=7/4`. Requiring `J=6/5` is ruled out by an exact dual witness. The example does not claim to solve the general nonlinear capacity minimization problem by a linear program.

## A rooted counterexample prevents overgeneralization

The second source model in `rooted_example` has a unique terminal graph component but a supercritical transient block. The same rate constants have exactly two globally maximizing positive stationary states: `(1,1,1)` and `(5/sqrt(3),sqrt(3),1)`. The code records the exact currents and the polynomial reduction that exhausts the maximizing solutions. They occur at different values of controlled X; this is not two stable states at a single control value.

At the unit maximum the internal Jacobian determinant is `-15/2`, so the optimum is a saddle. At the second maximum the thermodynamic product is `96/25`, below the source's forward-response capacity 4, but its reaction response is `(10,18,-6)`. It lies outside the forward-response cone, so there is no contradiction. The forward capacity 4 is itself an unattained infimum approached by profiles `(1,1,epsilon)`.

## Validation and limits

Seven scientific test groups check several recycling orders, reconstruction and source balance, the full positive stationary-curve parameterization, bottleneck decomposition, exact primal/dual budget witnesses, prescribed equilibrium constants, controlled integration against the manuscript's closed solution, the rooted example and fixed-output versus vanishing-output limits. The one-species source is an independent generic-constructor check. Tests use exact rational/algebraic identities where possible and stated tolerances for numerical trajectories. The general global comparison is a mathematical result of the paper; a finite test suite is not its proof. No global dynamical stability claim is made for arbitrary models.

Licensing: MIT is proposed, pending the owner's decision. No new license grant is made by this example.
