← All Research Notes
Formal verificationEngineering noteTechnical Monograph v1.0.3 · Lean 4.36.0

Formally verifying FactorForge's discrete dynamic programming model in Lean 4

Complete mathematical blueprint, locked Lean 4.36.0 specifications, inductive proof sketches, 12-state BsaI constructive trace, and sampled Python correspondence for FactorForge's discrete integer DP core.

Mun-Kyu Kim (Eijex Research)20 min readStandalone Lean 4.36.0 proofs and finite Python correspondence tests; no full Python refinement proof and no biological validation
Abstract & Formal Verification Scopeleanprover/lean4:v4.36.0 · 20+3 Theorems · 14 Witnesses · 0 sorry

Constraint-aware coding-sequence (CDS) optimization selects synonymous codons preserving a target protein while avoiding forbidden motifs across flanks and inter-codon junctions, satisfying global nucleotide GC bounds, and maximizing an additive codon-fitness objective. Finite unit suites test sampled inputs, whereas informal or unconstrained AI-generated proofs risk silent specification weakening unless checked by an independent proof kernel. Here we present the full mathematical blueprint of FactorForgeFormal, a zero-dependency Lean 4.36.0 formalization (14 modules, >2,500 lines, 0 sorry, verified transitively via leanchecker) proving 20 core theorems, 3 helper lemmas, and 14 concrete witnesses across Tropical max-plus algebra, construct-level DFA safety, the 64-triplet Standard Genetic Code (ValidCodonForAA), constructive backtracking DP optimality (dpOptimizeEndToEnd), exact rational pause-ramp interpolation (ExactRat), and conditional integer perturbation margins - alongside a fail-closed Python correspondence and 8/8 reference-copy mutation suite.

Figure 1 · Lean 4 Kernel Dependency Blueprint

Module & Theorem Dependency Graph (FactorForgeFormal, 14 Modules, 0 sorry)

Locked Spec (6)Kernel Theorems (20+3)Witnesses & Audit (14)
Spec/Tropical.leanTrop(Z) = Z u {-inf}Spec/Automaton.leanstepSeq, safeSeq, stepCodonSafeSpec/GeneticCode.lean64 triplets (61 sense + 3 stop)Spec/KineticAndParityExactRat, pathLexLt, MarginstropIntSemiringLawstropIntOrderLawsstepCodonSafeSound/CompfullConstructSafegeneticCodePartition64proteinPreservationAndGCtasepRampBounds · zeroParitypathLexTotal · approxExactdpSoundness & dpCompletenessexactGlobalOptimality · exactOpt_witness_eqgcEnvelopeAndPruningAdmissiblesynonymousEnvelopeUnsat · candToTrop_dpTrackEvalCrown Jewel Theorem: dpOptimizeEndToEnd (Proofs/ExactDP.lean)Value Parity + none-iff-Unsat + Translation(D)=P + GC in [g_min,g_max] + Flank Safety + Max ScoreWitnesses.lean (14 Concrete Theorems)12-State BsaI "GGTC"+"SL"+"TAA" -> AGCCTG (-357)Audit.lean + leanchecker Replay34 #print axioms Checks · Zero Custom Axioms · Exit 0
Every box represents a compiled Lean 4 module or kernel-checked theorem family in FactorForgeFormal. Arrows point from foundational specifications and lemmas to dependent theorems, culminating in constructive solver verification (dpOptimizeEndToEnd), concrete BsaI automaton instantiation (Witnesses.lean), and fresh-kernel replay (leanchecker).

1. Verification Architecture and Role-Separated Trust

Checking a dynamic-programming (DP) coding-sequence compiler solely through finite unit tests verifies input-output agreement on chosen examples, yet cannot prove universal invariants across arbitrary protein lengths LL, tight integer GC intervals [gmin⁡,gmax⁡][g_{\min}, g_{\max}], or cross-junction motif bridges spanning 5′5' flanks, coding triplets, and 3′3' stop/terminator tails. Conversely, delegating both specification design and proof authoring to a single unconstrained automated workflow creates two well-known failure modes:

  1. Specification weakening and vacuity: A formalization can silently omit synonymous translation invariance (Translate(D)=P\mathrm{Translate}(D) = P), trust unverified metadata fields on candidate records (such as a codon record AAA claiming gc = 3, or a stop triplet TAA inside a sense menu), or prove universal implications whose hypotheses are accidentally uninhabited.
  2. Model-to-code conflation: Proving Bellman optimality for a discrete integer model over Z∪{−∞}\mathbb{Z} \cup \{-\infty\} is not the same claim as proving universal code refinement for an operational Python optimizer that accumulates IEEE-754 binary64 math.log floats, applies a 1e-12 intra-state tie tolerance, and reconstructs paths via mutable tuple backpointers.

To guard against silent specification drift and measure runtime boundaries explicitly, FactorForgeFormal enforces a four-layer trust separation:

  • Locked Lean 4 specifications (formal/FactorForgeFormal/Spec/): Six modules (Tropical.lean, Automaton.lean, GeneticCode.lean, ExactDP.lean, KineticAndParity.lean, and aggregator Spec.lean) declare all data structures, algorithms, and target propositions (Prop_*) with zero sorry placeholders, bound to locked file digests in spec_lock_manifest.json.
  • Isolated tactic proofs (formal/FactorForgeFormal/Proofs/): Five proof modules import Spec/ read-only and establish 20 core theorems plus 3 structural helper lemmas using structural induction, fold-invariant lifting, kernel reduction (decide), and linear integer arithmetic (omega), with zero external Mathlib dependencies and zero native_decide.
  • Concrete non-vacuity witnesses and kernel axiom audit (Witnesses.lean, Audit.lean): Fourteen kernel-checked theorems instantiate the specifications on a 12-state BsaI (GGTCTC / GAGACC) automaton across construct "GGTC" + "SL" + "TAA", refuting malformed codons and proving constructive selection of AGCCTG at quantized score -357. Audit.lean runs #print axioms across all 34 declarations, followed by fresh-process kernel replay via leanchecker.
  • Sampled Python correspondence & reference-mutation harness (tests/): Cross-checks the self-contained factorforge_snapshot/ against an Aho-Corasick-independent substring enumerator (BruteForceCDSOracle), an exact integer mirror (LeanExactMirrorDP), a 200-instance shrinking fuzzer across four PYTHONHASHSEED settings, and an 8-defect reference-copy mutation suite. Importantly, internal multi-agent adversarial review performed during development is an automated engineering check, not an independent audit by external human mathematicians or software verification specialists.

2. Tropical Max-Plus Algebra (Spec/Tropical.lean)

Additive log-CAI maximization over reachable finite states is formalized over the extended integer semiring Trop(Z)=Z∪{−∞}\mathrm{Trop}(\mathbb{Z}) = \mathbb{Z} \cup \{-\infty\}, where unreachable (gc, state) cells carry −∞-\infty, path extension adds integer step scores, and state relaxation takes the pointwise maximum.

Definition 2.1 (Tropical Carrier, Operations, and Partial Order). For carrier type α\alpha, inductive type Trop α has constructors negInf (−∞-\infty, additive identity 0\mathbb{0}) and finite a (with multiplicative identity 1=finite(0)\mathbb{1} = \mathrm{finite}(0)). Over α=Z\alpha = \mathbb{Z}, relaxation ⊕\oplus, extension ⊗\otimes, and partial order ≤\le are defined by:

x⊕y:={yif x=−∞,xif y=−∞,finite(max⁡(a,b))if x=finite(a),  y=finite(b),x⊗y:={−∞if x=−∞ or y=−∞,finite(a+b)if x=finite(a),  y=finite(b).x \oplus y := \begin{cases} y & \text{if } x = -\infty, \\ x & \text{if } y = -\infty, \\ \mathrm{finite}(\max(a,b)) & \text{if } x = \mathrm{finite}(a),\; y = \mathrm{finite}(b), \end{cases} \qquad x \otimes y := \begin{cases} -\infty & \text{if } x = -\infty \text{ or } y = -\infty, \\ \mathrm{finite}(a + b) & \text{if } x = \mathrm{finite}(a),\; y = \mathrm{finite}(b). \end{cases}
inductive Trop (alpha : Type u) where
  | negInf : Trop alpha
  | finite : alpha -> Trop alpha
  deriving DecidableEq, Repr

def oplus {alpha : Type u} [Max alpha] : Trop alpha -> Trop alpha -> Trop alpha
  | Trop.negInf, b => b
  | a, Trop.negInf => a
  | Trop.finite a, Trop.finite b => Trop.finite (max a b)

def otimes {alpha : Type u} [Add alpha] : Trop alpha -> Trop alpha -> Trop alpha
  | Trop.negInf, _ => Trop.negInf
  | _, Trop.negInf => Trop.negInf
  | Trop.finite a, Trop.finite b => Trop.finite (a + b)

Theorem 2.1 (tropIntSemiringLaws) & Theorem 2.2 (tropIntOrderLaws). (Trop(Z),⊕,⊗,−∞,0)(\mathrm{Trop}(\mathbb{Z}), \oplus, \otimes, -\infty, 0) satisfies all 12 idempotent max-plus semiring identities - associativity, commutativity, idempotence (a⊕a=aa \oplus a = a), and identity of ⊕\oplus; associativity, unit 00, and −∞-\infty annihilation of ⊗\otimes; left and right distributivity a⊗(b⊕c)=(a⊗b)⊕(a⊗c)a \otimes (b \oplus c) = (a \otimes b) \oplus (a \otimes c) - and (Trop(Z),≤)(\mathrm{Trop}(\mathbb{Z}), \le) is a partial order for which ⊕\oplus is the least upper bound and ⊗\otimes is monotone in both arguments.

Proof sketch (Proofs/Tropical.lean). Proved by exhaustive 3-way constructor case analysis (cases a <;> cases b <;> cases c), reducing finite branches to linear integer max and + goals closed by omega (#print axioms: [propext, Quot.sound]).

3. Construct-Level Finite-State Automaton Safety (Spec/Automaton.lean)

Forbidden restriction endonuclease recognition sites (such as BsaI GGTCTC and reverse complement GAGACC) and sequence motifs can span 5′5'-flank-to-CDS junctions, inter-codon boundaries, and CDS-to-stop/terminator junctions. Spec/Automaton.lean models bounded nucleotide DFAs over Σ={A,C,G,T}\Sigma = \{\mathrm{A}, \mathrm{C}, \mathrm{G}, \mathrm{T}\}.

Definition 3.1 (Bounded DFA and Prefix-Safe Stepping). An Automaton M=(N,q0,δ,T,h0,hδ)M = (N, q_0, \delta, T, h_0, h_\delta) comprises state count N=numStatesN = \text{numStates}, initial state q0<Nq_0 < N, state-closed transition map δ:N×Σ→N\delta : \mathbb{N} \times \Sigma \to \mathbb{N} (q<N  ⟹  δ(q,b)<Nq < N \implies \delta(q,b) < N), and forbidden terminal indicator T:N→BT : \mathbb{N} \to \mathbb{B}. Multi-symbol stepping δ∗=stepSeq\delta^* = \text{stepSeq} and prefix-wise terminal avoidance safeSeq\mathrm{safeSeq} recurse over base lists, while stepCodonSafe mirrors CompiledAutomaton.step_codon by halting immediately with (s', false) if any intermediate base visits a terminal state.

structure Automaton where
  numStates : Nat
  initState : Nat
  stepSym : Nat -> Base -> Nat
  isTerminal : Nat -> Bool
  init_lt : initState < numStates
  step_lt : ∀ s b, s < numStates -> stepSym s b < numStates

def safeSeq (M : Automaton) (s : Nat) : List Base -> Bool
  | [] => true
  | b :: bs =>
    let s' := M.stepSym s b
    if M.isTerminal s' then false else safeSeq M s' bs

def stepCodonSafe (M : Automaton) (s : Nat) (codon : List Base) : Nat × Bool :=
  match codon with
  | [] => (s, true)
  | b :: bs =>
    let s' := M.stepSym s b
    if M.isTerminal s' then (s', false) else stepCodonSafe M s' bs

Theorems 3.1–3.5 (stepSeqAppend, safeSeqAppend, stepCodonSafeSound, stepCodonSafeComplete, fullConstructSafe). Multi-base transitions compose homomorphically (δ∗(q,u∥v)=δ∗(δ∗(q,u),v)\delta^*(q, u \mathbin{\Vert} v) = \delta^*(\delta^*(q,u), v)), prefix safety factors cleanly across intermediate states (safeSeq(M,q,u∥v)=safeSeq(M,q,u)∧safeSeq(M,δ∗(q,u),v)\mathrm{safeSeq}(M, q, u \mathbin{\Vert} v) = \mathrm{safeSeq}(M, q, u) \land \mathrm{safeSeq}(M, \delta^*(q, u), v)), and stepCodonSafe is both sound and complete for (stepSeq, safeSeq). Consequently, for any 5′5' flank FLF_L, codon list CC, and 3′3' tail FRF_R with qL=δ∗(q0,FL)q_L = \delta^*(q_0, F_L) and qend=δ∗(qL,flatten(C))q_{\mathrm{end}} = \delta^*(q_L, \mathrm{flatten}(C)):

safeSeq(M,q0,FL)  ∧  safeCodonList(M,qL,C)  ∧  safeSeq(M,qend,FR)  ⟹  safeSeq(M,q0,FL∥flatten(C)∥FR).\mathrm{safeSeq}(M, q_0, F_L) \;\land\; \mathrm{safeCodonList}(M, q_L, C) \;\land\; \mathrm{safeSeq}(M, q_{\mathrm{end}}, F_R) \;\Longrightarrow\; \mathrm{safeSeq}\bigl(M, q_0, F_L \mathbin{\Vert} \mathrm{flatten}(C) \mathbin{\Vert} F_R\bigr).

Proof sketch (Proofs/Automaton.lean). Structural list induction on xs generalizing starting state s, splitting on M.isTerminal (M.stepSym s b). Helper safeCodonList_implies_safeSeq lifts stepCodonSafeSound across cds : List (List Base), after which fullConstructSafe rewrites List.append_assoc and applies safeSeqAppend twice (#print axioms: [propext] only).

4. Standard 64-Triplet Genetic Code and Synonymous Menu Validity (Spec/GeneticCode.lean)

To prevent malformed candidate menus from bypassing amino-acid fidelity or falsifying stored GC counts, Spec/GeneticCode.lean encodes all 43=644^3 = 64 triplets (translateTriplet) and recursive frame-exact sense decoding (translateDNA), checked 64-for-64 against Python's STANDARD_GENETIC_CODE.

Definition 4.1 (ValidCodonForAA & WellFormedMenu). A candidate codon record c=(seq,gc,score)c = (\mathrm{seq}, \mathrm{gc}, \mathrm{score}) is valid for target residue a∈Aa \in \mathcal{A} iff it has exact length 3, nucleotide GC count matching its stored gc field, and sense translation equal to aa:

ValidCodonForAA(c,a)  ⟺  ∣c.seq∣=3  ∧  c.gc=seqGC(c.seq)  ∧  translateCodonSeq(c.seq)=some(aa  a).\mathrm{ValidCodonForAA}(c, a) \;\Longleftrightarrow\; |c.\mathrm{seq}| = 3 \;\land\; c.\mathrm{gc} = \mathrm{seqGC}(c.\mathrm{seq}) \;\land\; \mathrm{translateCodonSeq}(c.\mathrm{seq}) = \mathrm{some}(\mathrm{aa}\;a).
def ValidCodonForAA (c : CodonSpec) (a : AminoAcid) : Bool :=
  c.seq.length == 3 && c.gc == seqGC c.seq && translateCodonSeq c.seq == some (.aa a)

def WellFormedMenu : List AminoAcid -> List (List CodonSpec) -> Prop
  | [], [] => True
  | a :: as, opts :: rest =>
    (∀ c ∈ opts, ValidCodonForAA c a = true) ∧ WellFormedMenu as rest
  | _, _ => False

Theorem 4.1 (geneticCodePartition64, zero axioms), Lemmas 4.2–4.3 (validCodonForAA_destruct, translateDNA_cons3), & Theorems 4.4–4.5 (gcConservation, proteinPreservationAndGC). Inside Lean's kernel with zero axioms, the 64 DNA triplets partition into exactly 61 sense codons and 3 stop codons (TAA, TAG, TGA). Under WellFormedMenu P L, every ValidPath M s0 L C flattens to coding DNA D=flatMap(seq,C)D = \mathrm{flatMap}(\mathrm{seq}, C) satisfying:

∣D∣=3∣P∣,pathGC(C)=∑i=1∣P∣ci.gc=seqGC(D),translateDNA(D)=some(P),|D| = 3|P|, \qquad \mathrm{pathGC}(C) = \sum_{i=1}^{|P|} c_i.\mathrm{gc} = \mathrm{seqGC}(D), \qquad \mathrm{translateDNA}(D) = \mathrm{some}(P),

guaranteeing zero reading-frame shifts and zero internal or terminal stop codons.

5. Bellman Optimality and Constructive Witness Extraction (Spec/ExactDP.lean)

5.1 Tropical Bellman Table vs. Constructive Candidate Solver

Over the discrete state lattice (g,s)∈{0,…,Gmax⁡}×{0,…,N−1}(g, s) \in \{0,\dots,G_{\max}\} \times \{0,\dots,N-1\}, Spec/ExactDP.lean defines both the Tropical value recurrence dpEval / dpBestScore and the constructive prefix-tracking solver dpTrackEval / dpOptimize.

Vi(g′,s′):=⨁s=0N−1  ⨁c∈Oi:c.gc≤g′stepCodonSafe(M,s,c.seq)=(s′,true)(Vi−1(g′−c.gc,s)⊗finite(c.score)),V0(g,s)={0(g,s)=(0,s0),−∞otherwise.V_i(g', s') := \bigoplus_{s = 0}^{N - 1} \;\bigoplus_{\substack{c \in O_i : \; c.\mathrm{gc} \le g' \\ \mathrm{stepCodonSafe}(M, s, c.\mathrm{seq}) = (s', \mathrm{true})}} \Bigl(V_{i-1}(g' - c.\mathrm{gc}, s) \otimes \mathrm{finite}(c.\mathrm{score})\Bigr), \qquad V_0(g, s) = \begin{cases} 0 & (g,s)=(0,s_0), \\ -\infty & \text{otherwise.} \end{cases}

To return an explicit optimal codon list some (v, cs) rather than an existential value proof, DPCandidate := Option (Int × List CodonSpec) pairs integer scores with prefix codon lists via deterministic relaxation relaxCand (retaining first-seen on exact score ties) and extendCand.

def Prop_DPOptimizeEndToEnd : Prop :=
  ∀ (M : Automaton) (leftFlank : List Base) (minGC maxGC : Nat) (tail : List Base)
    (protein : List AminoAcid) (layers : List (List CodonSpec)),
    WellFormedMenu protein layers ->
    let s0 := M.stepSeq M.initState leftFlank
    (M.safeSeq M.initState leftFlank = true ->
      candToTrop (dpOptimize M leftFlank minGC maxGC tail layers) =
        dpBestScore M s0 minGC maxGC tail layers) ∧
    (dpOptimize M leftFlank minGC maxGC tail layers = none ↔
      M.safeSeq M.initState leftFlank = false ∨
      ∀ cs, ¬ FeasibleCDS M s0 minGC maxGC tail layers cs) ∧
    (∀ (v : Int) (cs : List CodonSpec),
      dpOptimize M leftFlank minGC maxGC tail layers = some (v, cs) ->
      let dna := cs.flatMap (·.seq)
      FeasibleCDS M s0 minGC maxGC tail layers cs ∧
      pathScore cs = v ∧
      dna.length = 3 * protein.length ∧
      translateDNA dna = some protein ∧
      minGC ≤ seqGC dna ∧
      seqGC dna ≤ maxGC ∧
      M.safeSeq M.initState (leftFlank ++ dna ++ tail) = true ∧
      ∀ cs', FeasibleCDS M s0 minGC maxGC tail layers cs' -> pathScore cs' ≤ v)

5.2 Soundness, Completeness, Pruning, and Crown Theorem dpOptimizeEndToEnd

Theorems 5.1–5.3 (dpSoundness, dpCompleteness, exactGlobalOptimality) & Lemma (exactOpt_witness_eq). For s0<M.numStatess_0 < M.\mathrm{numStates}, every finite entry VL(g,s)=finite(v)V_L(g, s) = \mathrm{finite}(v) witnesses an authentic ValidPath with matching (g,s,v)(g, s, v), and every ValidPath is upper-bounded by VL(pathGC(C),δ∗(s0,D))V_L(\mathrm{pathGC}(C), \delta^*(s_0, D)). Terminal projection dpBestScore upper-bounds all FeasibleCDS paths and attains every finite global optimum.

Theorem 5.4 (Crown Theorem: dpOptimizeEndToEnd). Under WellFormedMenu P L with s0=δ∗(q0,FL)s_0 = \delta^*(q_0, F_L):

  1. Value refinement: When safeSeq(M,q0,FL)=true\mathrm{safeSeq}(M, q_0, F_L) = \mathrm{true}, candToTrop(dpOptimize(… ))=dpBestScore(… )\mathrm{candToTrop}(\mathrm{dpOptimize}(\dots)) = \mathrm{dpBestScore}(\dots).
  2. Complete infeasibility certificate: dpOptimize(… )=none\mathrm{dpOptimize}(\dots) = \mathrm{none} if and only if FLF_L is unsafe or zero FeasibleCDS paths exist.
  3. 8-part constructive sequence optimality: Whenever dpOptimize(… )=some(v,C)\mathrm{dpOptimize}(\dots) = \mathrm{some}(v, C) with D=flatMap(seq,C)D = \mathrm{flatMap}(\mathrm{seq}, C), CC is feasible, pathScore(C)=v\mathrm{pathScore}(C) = v, ∣D∣=3∣P∣|D| = 3|P|, translateDNA(D)=some(P)\mathrm{translateDNA}(D) = \mathrm{some}(P), gmin⁡≤seqGC(D)≤gmax⁡g_{\min} \le \mathrm{seqGC}(D) \le g_{\max}, the full construct FL∥D∥FRF_L \mathbin{\Vert} D \mathbin{\Vert} F_R is motif-safe from q0q_0, and pathScore(C′)≤v\mathrm{pathScore}(C') \le v for every feasible competitor C′C'.

Theorems 5.5–5.6 (gcEnvelopeAndPruningAdmissible, synonymousEnvelopeUnsat). Any feasible split C=Cpre∥CsufC = C_{\mathrm{pre}} \mathbin{\Vert} C_{\mathrm{suf}} satisfies gmin⁡≤pathGC(Cpre)+totalMaxGC(Lsuf)g_{\min} \le \mathrm{pathGC}(C_{\mathrm{pre}}) + \mathrm{totalMaxGC}(\mathcal{L}_{\mathrm{suf}}) and pathGC(Cpre)+totalMinGC(Lsuf)≤gmax⁡\mathrm{pathGC}(C_{\mathrm{pre}}) + \mathrm{totalMinGC}(\mathcal{L}_{\mathrm{suf}}) \le g_{\max}, proving suffix GC pruning never drops an optimal completion, and any target window disjoint from [totalMinGC(L),totalMaxGC(L)][\mathrm{totalMinGC}(\mathcal{L}), \mathrm{totalMaxGC}(\mathcal{L})] has zero feasible solutions.

Proof sketch (Proofs/ExactDP.lean, 1,225 lines). Uses snoc-list induction (list_snoc_rec) over DP layers and nested fold-invariant lemmas across List.range M.numStates and opts. Homomorphism lemma candToTrop_dpTrackEval proves candToTrop (dpTrackEval ...) = dpEval ... via candToTrop (relaxCand x y) = oplus (candToTrop x) (candToTrop y), while dpTrackSoundness lifts witness validity to compose proteinPreservationAndGC, fullConstructSafe, and exactGlobalOptimality.

6. Exact Rational Kinetics, Tie Orders, and Perturbation Margins (Spec/KineticAndParity.lean)

Definition 6.1 (ExactRat & rampTau). Exact rationals ExactRat={(p,q)∈Z2:q>0}\mathrm{ExactRat} = \{(p, q) \in \mathbb{Z}^2 : q > 0\} compare fractions via cross-multiplication (a.p⋅b.q<b.p⋅a.qa.p \cdot b.q < b.p \cdot a.q) with zero rounding. Upstream deceleration ramp interpolation τramp(τp,d,W)=τp+dW(1−τp)\tau_{\mathrm{ramp}}(\tau_p, d, W) = \tau_p + \frac{d}{W}(1 - \tau_p) is represented exactly as:

rampTau((p,q),d,W):=pW+d(q−p)qW,(q>0,  W>0).\mathrm{rampTau}\bigl((p, q), d, W\bigr) := \frac{pW + d(q - p)}{qW}, \qquad (q > 0,\; W > 0).

Theorems 6.1–6.4 (tasepRampBoundsAndMonotonicity, zeroWeightParity, pathLexTotalOrder, approxScoreExactness).

  • Exact ramp interiority & monotonicity: For 0<τp<10 < \tau_p < 1 and 1≤d<W1 \le d < W, τp<QrampTau(τp,d,W)<Q1\tau_p <_{\mathbb{Q}} \mathrm{rampTau}(\tau_p, d, W) <_{\mathbb{Q}} 1; rampTau\mathrm{rampTau} is strictly increasing in dd and invariant at τp=1\tau_p = 1.
  • Zero-weight pause parity: When all active pause weights equal 00, structure-aware structFitness collapses identically to baseline fitness across every (g,s)(g, s) entry of dpEval.
  • Lexicographic strict total order: Prefix rank comparator pathLexLt is irreflexive, transitive, asymmetric, and trichotomous on List Nat.
  • Conditional integer perturbation margin (List Int): If pointwise integer error satisfies ∣ai−ti∣≤ε|a_i - t_i| \le \varepsilon across LL steps, then ∣∑i=1Lai−∑i=1Lti∣≤Lε\bigl|\sum_{i=1}^L a_i - \sum_{i=1}^L t_i\bigr| \le L\varepsilon, and S~alt+2Δ<S~opt\tilde{S}_{\mathrm{alt}} + 2\Delta < \tilde{S}_{\mathrm{opt}} with ∣S~−S∣≤Δ|\tilde{S} - S| \le \Delta guarantees Salt<SoptS_{\mathrm{alt}} < S_{\mathrm{opt}}.

Runtime boundary (float vs. List Int / ExactRat). approxScoreExactness is a conditional theorem over List Int (fixed-point integer quantization), not a binary64 math.log floating-point error proof. Likewise, Python's round(..., 3) in TASEPKineticsEngine collapses strict <1.0< 1.0 interiority when τp≥0.999\tau_p \ge 0.999 (for instance, τp=0.999,d=2,W=3↦1.0\tau_p = 0.999, d = 2, W = 3 \mapsto 1.0).

7. Concrete 12-State BsaI Automaton & Constructive Refutation Trace (Witnesses.lean)

To prove non-vacuity inside Lean's kernel, Witnesses.lean encodes the deterministic 12-state Aho-Corasick automaton for BsaI (GGTCTC →\to terminal state 6; reverse complement GAGACC →\to terminal state 11) and optimizes dipeptide "SL" ([.S, .L]) across 5′5' flank "GGTC", 3′3' stop tail "TAA", and GC window [2, 4]:

  1. Flank stepping (witness_leftFlank_safe): "GGTC" transitions 0→G1→G2→T3→C40 \xrightarrow{\mathrm{G}} 1 \xrightarrow{\mathrm{G}} 2 \xrightarrow{\mathrm{T}} 3 \xrightarrow{\mathrm{C}} 4 safely (s0 = 4).
  2. Junction violation refutation (witness_tct_rejected): Highest-scoring Serine codon TCT (quantized score -223) steps 4→T5→C64 \xrightarrow{\mathrm{T}} 5 \xrightarrow{\mathrm{C}} \mathbf{6}, completing "GGTCTC" across the 5′5' junction and halting with (6, false).
  3. Malformed candidate refutation (witness_malformed_codon_rejected): Kernel decide rejects AAA claiming gc = 3, AAA claiming Serine .S, and stop triplet TAA claiming Tyrosine .Y.
  4. Constructive global optimum (witness_dpOptimize_sl_end_to_end): dpOptimize selects AGC (4→0→1→04 \to 0 \to 1 \to 0, score -357, gc = 2) followed by CTG (0→0→0→10 \to 0 \to 0 \to 1, score 0, gc = 2) and safe stop tail "TAA" (1→0→0→01 \to 0 \to 0 \to 0), outputting some (-357, [AGC, CTG]) ("AGCCTG", seqGC = 4).
theorem witness_malformed_codon_rejected :
    ValidCodonForAA ⟨[.A, .A, .A], 3, 100⟩ .K = false ∧
    ValidCodonForAA ⟨[.A, .A, .A], 0, 100⟩ .S = false ∧
    ValidCodonForAA ⟨[.T, .A, .A], 0, 0⟩ .Y = false := by
  decide

theorem witness_dpOptimize_sl_end_to_end :
    ∃ cs : List CodonSpec,
      dpOptimize bsaiAutomaton leftFlankGGTC 2 4 tailStopTAA slLayers = some (-357, cs) ∧
      translateDNA (cs.flatMap (·.seq)) = some [.S, .L] ∧
      2 ≤ seqGC (cs.flatMap (·.seq)) ∧
      seqGC (cs.flatMap (·.seq)) ≤ 4 ∧
      bsaiAutomaton.safeSeq bsaiAutomaton.initState
        (leftFlankGGTC ++ cs.flatMap (·.seq) ++ tailStopTAA) = true

8. Complete Theorem, Witness, Mutation, and Coverage Catalogs

8.1 Catalog of 20 Core Theorems + 3 Structural Helper Lemmas

Audit.lean directly prints 20 core theorem declarations and 14 witnesses (34 total). The three helper rows belong to the proof-module catalog; their axiom footprints are separately reproducible with #print axioms.

Axiom legend: none = zero axioms; P = [propext]; P, Q = [propext, Quot.sound]; P, C, Q = [propext, Classical.choice, Quot.sound] (zero sorryAx and zero custom axioms).

ModuleLean Theorem / Lemma Identifier#print axiomsVerified Mathematical Statement
TropicaltropIntSemiringLawsP, Q12 idempotent max-plus semiring laws over Trop(Z)\mathrm{Trop}(\mathbb{Z}).
TropicaltropIntOrderLawsP, QPartial order, least upper bound, and ⊕\oplus/⊗\otimes monotonicity.
AutomatonstepSeqAppendPδ∗(q,u∥v)=δ∗(δ∗(q,u),v)\delta^*(q, u \mathbin{\Vert} v) = \delta^*(\delta^*(q, u), v) for all base lists u,vu, v.
AutomatonsafeSeqAppendPsafeSeq(q,u∥v)=safeSeq(q,u)∧safeSeq(δ∗(q,u),v)\mathrm{safeSeq}(q, u \mathbin{\Vert} v) = \mathrm{safeSeq}(q, u) \land \mathrm{safeSeq}(\delta^*(q, u), v).
AutomatonstepCodonSafeSoundPstepCodonSafe(q, c) = (q', true) implies δ∗(q,c)=q′\delta^*(q, c) = q' and safeSeq(q, c).
AutomatonstepCodonSafeCompletePsafeSeq(q, c) = true implies stepCodonSafe(q, c) = (stepSeq(q, c), true).
AutomatonfullConstructSafePSafe 5′5' flank, safe codons, and safe 3′3' tail yield safe full construct.
GeneticCodegeneticCodePartition64none64 DNA triplets partition into 61 sense codons and 3 stop codons.
GeneticCodevalidCodonForAA_destruct (helper)P, C, QDecomposes ValidCodonForAA into 3 bases, exact GC, and sense AA.
GeneticCodetranslateDNA_cons3 (helper)PSense triplet prefix preserves recursive translateDNA decoding.
ExactDPgcConservationP, C, QSum of well-formed codon gc fields equals flattened nucleotide seqGC.
ExactDPproteinPreservationAndGCP, C, QValid paths over WellFormedMenu preserve length 3∣P∣3\lvert P\rvert, seqGC, and some P.
ExactDPdpSoundnessP, C, QEvery finite dpEval entry witnesses an authentic ValidPath at (g,s,v)(g, s, v).
ExactDPdpCompletenessP, C, QEvery ValidPath score is upper-bounded by dpEval at (g,s)(g, s).
ExactDPexactGlobalOptimalityP, C, QdpBestScore upper-bounds all FeasibleCDS and attains finite optima.
ExactDPexactOpt_witness_eq (helper)P, C, QFeasible witness upper-bounding all feasible competitors equals dpBestScore.
ExactDPdpOptimizeEndToEndP, C, QConstructive dpOptimize value parity, none-iff-unsat, and 8-part optimality.
ExactDPgcEnvelopeAndPruningAdmissibleP, C, QAchievable suffix GC bounds [Gmin⁡,Gmax⁡][G_{\min}, G_{\max}] preserve all feasible completions.
ExactDPsynonymousEnvelopeUnsatP, C, QTarget GC bands disjoint from [Gmin⁡,Gmax⁡][G_{\min}, G_{\max}] admit zero feasible paths.
KineticAndParitytasepRampBoundsAndMonotonicityP, QExact rational ramp interiority (τp,1)(\tau_p, 1), strict monotonicity, and τp=1\tau_p = 1 invariance.
KineticAndParityzeroWeightParityP, QZero-weight pause maps collapse step fitness and full DP tables to baseline.
KineticAndParitypathLexTotalOrderP, QIrreflexivity, transitivity, asymmetry, and trichotomy of pathLexLt.
KineticAndParityapproxScoreExactnessP, QConditional List Int error bound LεL\varepsilon and 2Δ2\Delta strict argmax preservation.

8.2 All 14 Concrete Witness & Refutation Theorems (Witnesses.lean)

Witness Theorem Identifier#print axiomsConcrete Kernel-Verified Property
witness_malformed_codon_rejectedPRejects AAA claiming gc = 3, AAA for .S, and stop TAA for .Y.
witness_sl_wellFormedMenuPCertifies 6 Serine + 6 Leucine options satisfy WellFormedMenu [.S, .L].
witness_leftFlank_safeP, QLeft flank "GGTC" is safe on 12-state BsaI DFA and reaches state 4.
witness_sl_feasibleP, QPath AGCCTG satisfies FeasibleCDS across "GGTC" + "SL" + "TAA".
witness_dpBest_sl_exactP, C, QProves dpBestScore(...) = finite (-357) via exactOpt_witness_eq.
witness_dpOptimize_sl_end_to_endP, C, QConstructively extracts some (-357, cs) translating to [.S, .L].
witness_tct_rejectedP, QProves Serine codon TCT from state 4 hits forbidden BsaI state 6.
witness_gc_and_protein_preservationP, C, QInstantiates proteinPreservationAndGC on optPathSL (AGCCTG).
witness_gc_pruning_admissibleP, C, QVerifies prefix AGC + suffix Leucine GC envelope bounds [2, 4].
witness_tasep_rampP, QCertifies 720<rampTau(720,1,3)<1\frac{7}{20} < \mathrm{rampTau}(\frac{7}{20}, 1, 3) < 1 in ExactRat.
witness_zero_weight_parityP, QConfirms zero-weight pause entries preserve score -357 identically.
witness_path_lex_orderP, QCertifies [14, 19] < [15, 19] < [48, 19] => [14, 19] < [48, 19].
witness_approx_margin_exactnessP, QCertifies 2-codon margin −511+2(2)<−357  ⟹  −510<−356-511 + 2(2) < -357 \implies -510 < -356.
witness_unsat_gcP, C, QCertifies zero feasible paths exist when target GC band is [5, 6] > 4.

8.3 Reference-Copy Mutation Audit (8/8 Injected Semantic Defects Killed)

Across 200 seeded random instances repeated over PYTHONHASHSEED ∈{0,1,2,3}\in \{0, 1, 2, 3\}, operational DPV2Optimizer matched BruteForceCDSOracle on feasibility, amino-acid translation, motif safety, and optimal score, while exposing a concrete tie-breaking difference on homodipeptides (FF: TTTTTC vs TTCTTT, identical score at (g = 1, s = 0)). In test_mutation_detection_audit.py, eight semantic defects were injected into an instrumented reference solver copy:

Mutant IDAudit OutcomeInjected Defect & Killing Oracle Assertion
M1_WRONG_SYNONYMOUS_CODONKilledInjects Lysine AAA (gc = 0) into Serine menu on "SL" ([0.30, 0.67] GC); caught by translate_dna(seq) != "SL".
M2_GC_COUNT_DROP_CKilledCounts only 'G' instead of 'G' + 'C' on "TT" ([0.66, 0.67] GC); caught by nucleotide GC window & oracle set check.
M3_DROP_REVERSE_COMPLEMENTKilledOmits reverse complement GAGACC on "GA" + "DL"; emits junction GAGACC, caught by raw substring check.
M4_IGNORE_LEFT_FLANKKilledStarts at s0 = 0 instead of step("GGTC") = 4 on "GGTC" + "SL" + "TAA"; emits TCT (GGTCTC), caught by substring check.
M5_IGNORE_RIGHT_FLANKKilledSkips terminal right-flank transition on "" + "G" + "CTC"; emits GGT (GGTCTC), caught by substring check.
M6_OFF_BY_ONE_MAX_GCKilledReplaces g <= max_gc with g < max_gc on "TT" (min_gc = max_gc = 4); falsely raises No in-band candidate.
M7_MIN_INSTEAD_OF_MAXKilledMinimizes rather than maximizes log-CAI during state relaxation; caught by optimal score check against BruteForceCDSOracle.
M8_CORRUPT_BACKPOINTERKilledStores prev_g = g + 1 in forward pass; fails backtracking with KeyError or mismatched sequence.

8.4 Mathematical Formulation Coverage Matrix (F1–F28)

Tiers: L1 = Lean 4 kernel proof; O1 = brute-force/fuzzer/mutation suite in this archive; C1 = deterministic unit tests in the main repository; (B) = documented runtime divergence.

IDFormulationLean 4 / Python AnchorVerification TierScope Note
F1Codon frequency f(c)f(c)load_codon_usage_tableC1Table loader
F2Relative adaptiveness w(c)w(c)_build_codon_weightsC1 + O1Clamped at 10−610^{-6}
F3Geometric CAI & log sumpathScore, approxScoreExactnessL1 + O1 (B)Int vs binary64 float
F4Nucleotide GC count & percentseqGC, gcConservationL1 + O1Exact integer GC
F564-triplet Genetic CodetranslateTriplet, geneticCodePartition64L1 + O164/64 bijection
F6Sense translation Translate(D)=P\mathrm{Translate}(D)=PValidCodonForAA, proteinPreservationAndGCL1 + O1Menu soundness
F7Forbidden motif + RC closureAutomaton, AutomatonCompilerL1 + O1 (B)Supplied DFA table
F8Full-construct junction safetyfullConstructSafeL1 + O1Arbitrary flanks
F9Feasible CDS set F(P,θ)\mathcal{F}(P,\theta)FeasibleCDS, synonymousEnvelopeUnsatL1 + O1Integer GC band
F10–F14Random, Greedy, Balanced, GC-target, SOP / local rewriterreverse_translator.py, sop_balancer.py, local_rewriter.pyC1Non-DP heuristics
F15Tropical max-plus semiringtropIntSemiringLaws, tropIntOrderLawsL1 + O1Z∪{−∞}\mathbb{Z}\cup\{-\infty\} algebra
F16Forward Bellman layer stepdpStep, dpSoundness, dpCompletenessL1 + O1 (B)5′5' ramp outside Lean
F17Terminal filter & global optimumdpBestScore, exactGlobalOptimalityL1 + O1 (B)Fallback in O1
F18Constructive backtracking & tiesdpOptimizeEndToEnd, pathLexTotalOrderL1 + O1 (B)3 distinct tie rules
F19Suffix GC pruning & TASEP rampgcEnvelopeAndPruningAdmissible, tasepRampBoundsAndMonotonicityL1 + O1 (B)round(..., 3) near 1.01.0
F20–F26Candidate pass gate, window GC, homopolymer, dinucleotide, meansSharedEvaluator, BenchmarkRunnerC1 (+ O1)Descriptive metrics
F27Manifest file-integrity bindingverify_all.py, REPRODUCIBILITY_MANIFEST.jsonO1229-file lock
F28Epistemic classification gateUNVERIFIED_PUBLIC_CORPUSGovernanceZero wet-lab claim

9. Exact Proof Boundaries and Fail-Closed Replay Protocol

This milestone proves the mathematical soundness of FactorForge's explicitly specified discrete integer DP model, not a universal formal verification of the entire Python software stack:

Scope AreaCurrent StatusExact Technical Boundary
Discrete integer DP core & 64-codon translation (FactorForgeFormal)Verified in Lean 420 core theorems + 3 helper lemmas, 14 witnesses, 34 #print axioms checks (0 sorry), leanchecker verified. Optimality is relative to supplied WellFormedMenu menus (supplied-menu soundness; universal runtime menu correspondence is not proved here).
Sampled Python DP correspondence & reproducible archiveCompleted (finite suite)28 pytest checks, 4 PYTHONHASHSEED runs, 8/8 reference-copy mutant kills, and 229-file manifest integrity checks (python verify_all.py).
Universal Python-to-Lean refinement & backpointer proofNot proved (future scope)Lean's dpOptimize tracks prefix lists; operational Python reconstructs mutable (prev_g, prev_s) backpointers and is not extracted from Lean.
IEEE-754 float & 1e-12 epsilon error boundsNot proved (future scope)Operational DP accumulates binary64 math.log floats with a non-transitive 1e-12 intra-state tie window (relaxCand first-seen, LeanExactMirrorDP PathRank, and operational DPV2Optimizer last-codon tie-breaking follow three distinct tie policies). approxScoreExactness is conditional over List Int.
General substring motif compiler & non-DP heuristicsNot proved in LeanLean assumes a supplied DFA transition table rather than proving general Aho-Corasick fail-link compilation for arbitrary motif sets; AutomatonCompiler permutes internal state IDs with PYTHONHASHSEED; Python round(..., 3) collapses ramp strictness near 1.01.0; 5′5' initiation clamping and heuristics lie outside ExactDP.lean.
Biological expression & wet-lab performanceNot availableUNVERIFIED_PUBLIC_CORPUS · Biological validation: NOT_AVAILABLE. Mathematical optimization correctness implies zero wet-lab expression, folding, or yield guarantee.

To replay the entire verification archive locally from clean state (with Python 3.11+, pytest, ruff, and elan leanprover/lean4:v4.36.0 installed), unpack FactorForge_Lean4_Verification_Package.zip to a short directory path and run:

python verify_all.py

Want to inspect all 2,749 lines of Lean 4 specifications & tactic proofs?

Switch to Full Proof mode to browse all 14 modules (including FactorForgeFormal.lean, Spec/, Proofs/, Witnesses.lean, Audit.lean) and the 34 #print axioms kernel outputs inline, or download the Complete Full Monograph PDF.