# Conservative molecular inheritance and population risk

This package accompanies manuscript 71, *Conservative Molecular Inheritance and Population Risk*. Manuscript SHA-256: `2ae028e1227c6f80f7da47df7a035ea41fd4c68508e68112f623ae0b923cdc4b`.

One daughter has the same distribution in both models, and the mean population is the same. The daughters' joint distribution changes the nonlinear generating function, extinction probability, variance and substantial-regrowth risk. The example exposes that distinction without replacing a population by its mean or equating nondetection with extinction.

## Run and edit

Python 3.11 is the tested runtime. In a fresh environment:

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

The full driver rebuilds all exact certificates, including 30,000 outward Taylor steps and 41 rational 153-state slope cells. Allow several minutes. It does not read saved output as evidence. The source scripts' own command-line entry points retain their research archive paths; use `example.py` for this self-contained package.

Edit the clearly marked inputs at the top of `example.py`: site count, founder, molecular rates, readout, division rate and phases, horizon, capture and observation assumptions. Times are in the arbitrary unit used by the stated rates. There is no clinical calibration. The dense reusable model explicitly supports 1–32 sites; larger site counts need a sparse implementation rather than an unnoticed allocation of a huge dense matrix.

`REGROWTH_THRESHOLD` changes the eventual bound derived from the fixed two-site source. It does **not** apply that bound to an edited source. The finite-deadline certificate remains the paper's threshold 300 and deadline 300. Fixed certificates are always rebuilt and clearly separated from the configured numerical scenario.

## Components and equations

`MolecularSource` builds every state `(a,r)` with `a+r <= N`; inactive marks number `u=N-a-r`. The four molecular transitions write active/repressive marks at rates `u(w+ka/N)` and `u(w+kr/N)`, and erase them at rates `a(e+hr/N)` and `r(e+ha/N)`. The source returns the full generator, single-daughter kernel and complementary pair weights.

`Complementary` sends independently allocated active and repressive marks to one daughter and the exact complement to the other. `Independent` draws both daughters independently from that same marginal. Both implement a bilinear continuation product. They therefore share the mean generator `Q + b(2D-I) - diag(d)` but have different quadratic terms in the backward equation:

```text
du/dt = Q u + d (1-u) + b (D_pair(u,u)-u).
```

`BranchingPopulation` provides numerical least-fixed-point extinction, backward PGFs and first/second factorial moments. `StepHazard` and `SmoothHazard` are interchangeable; another object implementing `values(states, sites)` can supply a new hazard. The code accepts valid nonnegative hazards, but the paper's ordering theorem additionally requires a hazard decreasing in its molecular order. A custom hazard does not inherit that theorem automatically.

`phases=m` implements a state-independent Erlang clock with rate `mb` in each phase and daughter clocks reset to phase zero at division. Molecular transitions and death continue through every phase. Mean time is `1/b`; changing `m` changes the clock variance. The resulting PGF has all phase states, and the fixed-point map uses `V^m`, where `V=mb(mb I+diag(d)-Q)^-1`. New founders begin at phase zero. The phase-one certificate is not reused for another clock.

`IndependentCapture` evaluates nondetection at PGF argument `1-p`; it also supplies the binomial-thinning mean and variance. `PairedCloneObservation` separates heterogeneity, misclassification, missingness and independent-pair sampling error. `balanced_survival_bound` evaluates the paper's smooth-readout large-size theorem using logarithmic site counts, so astronomically large values need not be allocated as molecular state spaces.

Reuse without rerunning the paper certificates:

```python
from branching import *
source = MolecularSource(sites=8, erasure=.012)
for phases in (1, 2, 4):
    model = BranchingPopulation(source, SmoothHazard(7.5), Complementary(), phases=phases)
    q, iterations = model.extinction()
    mean, variance = model.moments([0., 10., 30.])
    missed = IndependentCapture(.2).nondetection(model, [30.])
    print(phases, q[source.index[4, 4]], missed[0, source.index[4, 4]])
```

A tolerance in the numerical fixed-point loop is a stopping condition, not a certified error bound. Exhausting its budget raises an error. Numerical ODE trajectories likewise carry no uniform rigorous enclosure.

## Rebuilt evidence

- `two_site.py` reconstructs exact rational molecular and pair kernels. It checks coarse supersolutions, eight downward iterations, weighted contraction, 250 fine downward iterations, strict supersolutions and the covariance-forcing response enclosure. `TwoSiteCertificate` also reconciles every coefficient of the independently supplied Taylor integrator with this rational source.
- `SmoothSlopeCertificate` reruns the source's rational exponential envelopes, exact upper residuals and downward integer iterations. It saves **all 153 coordinates** for every one of 40 cells in `[7,9]` and the single cell `[7.999,8.001]`. Individual states change hazard in opposite directions as slope changes; enclosing endpoints state by state is essential. A single wide envelope can fail while a partition succeeds. A failed sufficient bound is not evidence of reversed dynamics.
- `DeadlineCertificate` reruns the two 15,000-step, order-20 integer interval Taylor solves. The step is `1/50`, arithmetic denominator `10^40`, analytic radius `1/4`, and logarithmic growth bound `.09`. The global error bound uses an exactly verified upper bound on `exp(27)`. The lower enclosure for the zero-argument PGF and upper enclosure for the `299/300` PGF are used with the correct signs.
- Regrowth uses the strong-Markov threshold inequality from the paper: survival is a lower bound on ever hitting `L`, and `(1-q_founder)/(1-q_max^L)` is an upper bound, clipped only by the trivial upper bound one. The deadline argument lower-bounds first passage by an endpoint count event. It does not equate those events or compute an exact hitting probability.

For AA at two sites, complementary extinction is enclosed near `.220723`, independent extinction near `.335147`. The exact response gap lies between `.1144144` and `.1144331`. The threshold-300 eventual gap exceeds `.098`, and the deadline-300 gap exceeds `.084`. At 16 sites the `(9,7)` gap exceeds `.01427` on the narrow slope interval and `.0128` on `[7,9]`; the eventual threshold-2000 gap exceeds `.0122` on the wide interval. These are unconditional one-founder statements, without a preceding treatment or selection on later survival.

## What the demonstrations distinguish

The preparation sweep compares all-active and balanced founders at the same site count. The smooth-readout theorem gives vanishing survival for balanced large-size families, but its quantitative bound is uninformative at ordinary site counts; saved values above one are intentionally retained. The corresponding discontinuous step-readout limit is not proved by this argument. A large raw pair-law total variation distance is compatible with a small continuation-risk difference.

Monotone continuation functions have nonpositive complementary-sister covariance. The exact nonmonotone example instead has covariance `1/4`, showing why that condition matters. For the newborn active indicator, an AA mother has covariance `-1/16`; an equal mixture of AA and RR mothers has pooled covariance `7/64`. Mother heterogeneity can mask the conditional relationship. The observation sensitivity interval requires justified bounds on the mother's conditional mean range, misclassification and missingness, plus prospectively enrolled independent sister pairs. Its sampling confidence is not a deterministic model guarantee.

Capture assumes independent Bernoulli sampling of individual cells with known probability. Fixed-depth sequencing, state-dependent capture, barcode collisions and growth-biased enrollment need different observation models. Equal means and ordered variances do not imply stochastic dominance or a universal first-passage ordering. State-dependent division rates can invalidate the monotone-cone proof; no actual reversal is inferred merely from that obstruction.

## Files, provenance and checks

Outputs include exact risk/response boxes, full slope witnesses, validated deadline enclosures, numerical time courses and sweeps, observation accounts, large-size bounds, two PNG/SVG figures and hashes. Metadata identifies every module and the manuscript. Reproducible scientific JSON/CSV files exclude wall-clock timestamps.

`model.py`, `slope_certificate.py` and `deadline_validated.py` are unmodified paper source files. `two_site.py` wraps the two-site section of the paper's `check_paper.py` in a callable function; its computations are retained. Original hashes and adaptation notes are in `source_provenance.json`. The reusable objects, driver, observation layer, tests and presentation are example-specific additions. This is exact computation plus the paper's conventional probability arguments; Lean and an end-to-end formal proof are not rerun.

Seven tests check conserved sister allocations and marginal matching, the covariance obstruction, common means/ordered moments/PGFs and capture, phase clocks and a pure-birth limit, exact risk/response/threshold certificates, a fresh smooth envelope and observation limits, and invalid-input/budget behavior. The full example separately rebuilds every long certificate.

License: MIT is proposed for new example code, pending the owner's choice. No license grant is made here; attribution to the supplied paper source does not resolve its licensing.
