# Mixed degradation: one positive state at most

This package accompanies **Unistationarity of Type II_l and Type V autocatalytic cores with nonnegative degradation**, manuscript entry 26, SHA-256 `6d260d5d6596b099430287d32563d91ebf3f22ccbee5c5b9a889b54470ccf3ed`.

The paper asks whether selectively degrading only some species can create two positive stationary states in either of these minimal autocatalytic core families. It cannot, even if every degradation coefficient is zero. The challenge is that arguments dividing by a degradation flux no longer make sense at zero. This example exposes the two mechanisms that avoid that division: exact passive-path elimination for Type V, and an admissible-flow factorization for separated Type II skeletons.

## Run

Python 3.11 or newer; the tested direct dependencies are pinned.

```sh
python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS/Linux: source .venv/bin/activate
python -m pip install -r requirements.txt
python -m unittest -v test_example.py
python example.py --output outputs
```

The run writes two figure pairs, three CSV tables, a structured exact/numerical result, a console summary and provenance hashes. Tests and the default calculation take seconds on an ordinary workstation. No network services or original-paper files are needed after downloading the package.

## The literal model

`SourceNetwork` stores the species names and integer product matrix P: reaction r consumes one molecule of X_r and produces column r of P. `MassActionModel` attaches strictly positive forward and reverse constants and nonnegative losses. With N=P-I, its field is

    p = a * x
    q = b * exp(P.T @ log(x))
    dx/dt = N @ (p-q) - d*x.

The reverse rates retain the full nonlinear monomials. The model is a diluted-core reversible extension with implicit external resources, not an atom-balanced, calibrated reactor. Inputs at the top of `example.py` are dimensionless constructive examples. Changing a stoichiometric exponent changes the units that a physical reverse rate would require; physical use needs an explicit reference concentration/time and chemical calibration.

`field(x)` works with exact rational or symbolic positive states. `numeric(x)` returns a floating-point field and **H = Df(x) diag(x)**. For an ODE solver, use the field and divide H by concentrations columnwise to obtain the physical Jacobian. Path compression is an exact **stationary** reduction, not an ODE approximation: use the expanded literal model for transients.

## Build, reuse and sweep

- `separated_type_ii(weights)` creates at least three cyclic forks, arbitrary nonempty active gaps and unit terminal return edges. A tuple such as `((2,3),(1,),(2,1))` preserves all active integer multipliers. `coincident_type_ii((2,1,3))` constructs the separate three-fork branch.
- `TypeVTopology((3,0,2))` constructs three sectors: a three-edge unit path, one identified pair, and a two-edge path. Each nonnegative edge count is independent, so all eight linked/collapsed patterns and arbitrary finite path lengths are supported.
- `SourceNetwork.realize(x,d,margin)` constructs exact positive reversible constants that make the chosen positive state stationary. It solves J=N^-1(d*x), then q=max(0,-J)+margin and p=q+J. Net currents may be negative. This is an **inverse construction of a model**, not a solver for pre-existing kinetic constants.
- For measured constants, instantiate `MassActionModel(source, forward, reverse, loss)` directly. Its `continuation(scales)` holds those reversible constants fixed and varies only the loss vector. The zero-loss initial point is available analytically. Each later solve is numerical and local; a failed or bounded-out solve is reported as unresolved. Log coordinates and residual f/x prevent the origin from being accepted merely because f becomes small.
- `UnitPath` computes exact transmissions and endpoint leaks, and reconstructs every internal concentration with an independent tridiagonal solve. `expand_unit_edge(start,end,path)` returns a literal expanded Type II model and its effective stationary skeleton. It rejects nonlinear active or fork edges; only genuine one-to-one edges are eligible. Its supplied path rates **replace** the selected unit reaction's constants.
- `TypeVTopology.reduce(model)` returns `ReducedTypeV`, with coefficients alpha, beta, lambda and mu, its three equations, the logarithmic tangent, a strict ratio witness and full state reconstruction. The reduction validates the supplied literal topology.

For example, insert an internally degraded return path while preserving its effect:

```python
from example import Q, UnitPath, separated_type_ii
source = separated_type_ii()
model = source.realize([1]*6, [0]*6)
literal, effective = model.expand_unit_edge(
    'T1', 'F1', UnitPath((1,1), (1,1), (Q(1,3),)))
# Solve effective at stationarity; reconstruct the eliminated internal species.
# Simulate literal if transient dynamics matter.
```

The all-unit two-edge path X <-> Z <-> Y with d_Z=1 reduces to c=beta=lambda_left=lambda_right=1/3. Neither endpoint needs a direct loss. The second figure varies that internal loss at fixed endpoints X=2,Y=3: the difference of the two endpoint currents is exactly d_Z Z. Dropping leakage would change the stationary equations.

## What the computed result teaches

The default Type II model has six retained species and losses only at F0 and T2. The constructed state x=1 is exactly stationary. `StationaryCertificate` first demands **exact stationarity**, then forms

    J = N^-1 e,  s = max(0,-J),  t = q-s = min(p,q),
    B = (diag(J)-N^-1 diag(e)) N^-T,
    A = diag(s)-B,
    -H = N (diag(q)-B) N.T.

All 64 principal minors of A are nonnegative. The determinant expansion over those minors reproduces det(-H)=90368/1125, above the bound (det N)^2 product(t)=36. The paper proves this for every stationary triple of a separated Type II skeleton. Here it is an independently checked exact certificate for the specified rational triple. The routine can audit other invertible sources, but a successful finite audit does not extend the paper's universal theorem to those sources. A budget of 1,024 minors prevents accidental exponential work; exhausting it returns unresolved.

The determinant bound is not a condition-number bound or a smallest-singular-value bound. The paper does not claim this bound for expanded return paths, the coincident branch or Type V. Their models and reductions remain usable without attaching that bound to them.

The default Type V example has eight literal species and an exact three-variable reduction. If u and v were different positive solutions, the ratios u_i/v_i would select an extremal row whose terms all have one sign and whose reverse-fork term has a strict sign. `ratio_witness` exposes this contradiction using exact arithmetic. This is why vanishing degradation does not destroy uniqueness: reverse-fork constants remain positive.

The first figure varies the mixed-loss scale while holding reversible constants fixed. Its concentrations and eigenvalues are numerical diagnostics. At zero degradation, detailed balance supplies an analytic positive root and a Jacobian similar to a symmetric negative-definite matrix; the paper guarantees existence and local stability for sufficiently small nonnegative degradation. The computation does not determine that neighbourhood rigorously.

## Scope and verification

Seven test groups independently differentiate the source field; check arbitrary path balances and leakage; compare expanded and compressed equations; reconstruct all eight Type V patterns at every singleton loss support; check strict ratio signs and tangent determinants; expand all principal minors including zero-loss cases; verify negative-current admissibility and the coincident inverse; and compare continuation with a separate root solver and the exact endpoint.

The theorem is **at most one strictly positive stationary state** within the classified minimal families. The origin is also stationary. Arbitrary loss need not admit a positive state; uniqueness does not imply stability, attraction or global continuation. Nonsingularity rules out an interior saddle-node, not a Hopf bifurcation. Adding other reactions can leave the theorem's scope. Sampling roots is not a proof of uniqueness. This package reproduces source equations and finite algebraic checks, and does not rerun the manuscript's Lean development.

Manuscript map: stationary equations and normal forms, Section 2; paths, Section 3; Type V reduction and ratios, Section 4; Type II stationary factorization/admissibility, Section 6; coincident branch, Section 7; determinant bound, local continuation and zero-loss stability, Section 8.

Licensing: MIT is proposed for these original example files, pending the owner's decision. No license grant is made here; manuscript licensing remains separate.
