Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Corollary 4.11: Polynomial-Time Program Extraction from N-HA^ω

Open
ABHS2004.corollary_4_11

by kmehltretter82 · Oct 30, 2026 · Mathlib 0df444a (Lean v4.33.1)

implicit-computational-complexitypolynomial-timeproof-theoryrealizabilitytype-theory

Every numerical function f : ℕ^k → ℕ proven total (!∀x₁ ∈ N ... !∀xₖ ∈ N ∃y ∈ N. A(x⃗, y)) in N-HA^ω is represented by an extracted closed term t of the !-free affine λ-calculus and is therefore computable in polynomial time.

Preamble
import Definitions.Def_ABHS2004_Realizability
Formal statement
namespace ABHS2004

theorem corollary_4_11 {Δ Γ : ProofContext} {M : ProofTerm}
    {xs : List Var} {y : Var} {A : Formula}
    (hdata_xs : ∀ x ∈ xs, IsDataType x.ty ∧ cleanTy x.ty = x.ty ∧ x.ty ≠ .unit)
    (hdata_y : IsDataType y.ty ∧ cleanTy y.ty = y.ty ∧ y.ty ≠ .unit)
    (hnodup : (xs ++ [y]).Nodup)
    (hA : IsExistAndDisjFree A)
    (hac : IsAlmostClosedDerivation Δ Γ)
    (hd : Derives Δ Γ M
      (Formula.allRel xs (.ex y (.tensor (.existPred y.ty (.var y)) A))))
    (hfresh : FreshRealizerVars Δ Γ M
      (Formula.allRel xs (.ex y (.tensor (.existPred y.ty (.var y)) A)))) :
    ∃ (B : Nat → Nat) (k : Nat),
      BoundedByPolyOfDegree B (Nat.max (iterNesting (extractCleaned M)) 1) ∧
      ∀ ws : List Term,
        ValidDataInputs (extractCleaned M) (xs.map Var.ty) ws →
        ∃ (steps : Nat) (w : Term),
          RedSteps steps (Term.appMany (extractCleaned M) ws) w ∧
          IsDataObject y.ty w ∧
          steps ≤ B (totalTermLength ws) ∧
          termLength w ≤ totalTermLength ws + k ∧
          freeVarCount w ≤ totalFreeVarCount ws + k ∧
          Provable (mrContext (Δ ++ Γ)) []
            (substFormula (substFormulaMany A (xs.zip ws)) y w) := by sorry

end ABHS2004
Source
Klaus Aehlig, Ulrich Berger, Martin Hofmann, and Helmut Schwichtenberg, 'An arithmetic for non-size-increasing polynomial-time computation', Theoretical Computer Science 318(1-2), 2004, pp. 3-27 (doi:10.1016/j.tcs.2003.10.023). Corollary 4.11, p. 23.
Read-back

What the Lean code literally says, in plain math · Gemini 3.1 Pro (Independent Blind Auditor)

Blind Read-back: Thm_ABHS2004_corollary_4_11.lean

Declaration corollary_4_11. For any passive proof context Δ∈ProofContext\Delta \in \mathrm{ProofContext}Δ∈ProofContext, any active proof context Γ∈ProofContext\Gamma \in \mathrm{ProofContext}Γ∈ProofContext, any raw proof term M∈ProofTermM \in \mathrm{ProofTerm}M∈ProofTerm, any finite list of input term variables xs=[x1,…,xm]∈List(Var)xs = [x_1, \dots, x_m] \in \mathrm{List}(\mathrm{Var})xs=[x1​,…,xm​]∈List(Var) (including m=0m = 0m=0), any output term variable y∈Vary \in \mathrm{Var}y∈Var, and any formula A∈FormulaA \in \mathrm{Formula}A∈Formula, suppose that:

  1. for every variable x∈xsx \in xsx∈xs, its type x.tyx.\mathrm{ty}x.ty is a data type (IsDataType(x.ty)\mathrm{IsDataType}(x.\mathrm{ty})IsDataType(x.ty), meaning x.tyx.\mathrm{ty}x.ty is built from UUU using L(⋅)L(\cdot)L(⋅), ⊗\otimes⊗, and +++), cleaning leaves x.tyx.\mathrm{ty}x.ty unchanged (c(x.ty)=x.tyc(x.\mathrm{ty}) = x.\mathrm{ty}c(x.ty)=x.ty), and x.ty≠Ux.\mathrm{ty} \neq Ux.ty=U;
  2. the output variable's type y.tyy.\mathrm{ty}y.ty is a data type (IsDataType(y.ty)\mathrm{IsDataType}(y.\mathrm{ty})IsDataType(y.ty)), cleaning leaves y.tyy.\mathrm{ty}y.ty unchanged (c(y.ty)=y.tyc(y.\mathrm{ty}) = y.\mathrm{ty}c(y.ty)=y.ty), and y.ty≠Uy.\mathrm{ty} \neq Uy.ty=U;
  3. the combined list of variables xs+ ⁣+[y]=[x1,…,xm,y]xs \mathbin{+\!+} [y] = [x_1, \dots, x_m, y]xs++[y]=[x1​,…,xm​,y] has no duplicates (Nodup(xs+ ⁣+[y])\mathrm{Nodup}(xs \mathbin{+\!+} [y])Nodup(xs++[y]));
  4. AAA contains neither existence predicates Eρ(r)E_\rho(r)Eρ​(r) nor disjunctions B∨CB \lor CB∨C (IsExistAndDisjFree(A)\mathrm{IsExistAndDisjFree}(A)IsExistAndDisjFree(A));
  5. the contexts (Δ,Γ)(\Delta, \Gamma)(Δ,Γ) form an almost closed derivation (IsAlmostClosedDerivation(Δ,Γ)\mathrm{IsAlmostClosedDerivation}(\Delta, \Gamma)IsAlmostClosedDerivation(Δ,Γ), meaning every variable in extractCleanCtx(Δ)\mathrm{extractCleanCtx}(\Delta)extractCleanCtx(Δ) and extractCleanCtx(Γ)\mathrm{extractCleanCtx}(\Gamma)extractCleanCtx(Γ) has type ⋄\diamond⋄, i.e., every assumption in Δ∪Γ\Delta \cup \GammaΔ∪Γ has cleaned realizer type UUU or ⋄\diamond⋄);
  6. Δ∣Γ⊢M:F\Delta \mid \Gamma \vdash M : FΔ∣Γ⊢M:F (Derives(Δ,Γ,M,F)\mathrm{Derives}(\Delta, \Gamma, M, F)Derives(Δ,Γ,M,F)), where
F:=∀x1. (Ex1.ty(x1)→⋯→∀xm. (Exm.ty(xm)→∃y. (Ey.ty(y)⊗A))⋯)F := \forall x_1.\, \big(E_{x_1.\mathrm{ty}}(x_1) \to \cdots \to \forall x_m.\, \big(E_{x_m.\mathrm{ty}}(x_m) \to \exists y.\, (E_{y.\mathrm{ty}}(y) \otimes A)\big)\cdots\big)F:=∀x1​.(Ex1​.ty​(x1​)→⋯→∀xm​.(Exm​.ty​(xm​)→∃y.(Ey.ty​(y)⊗A))⋯)

(Formula.allRel(xs,Formula.ex(y,Formula.tensor(Formula.existPred(y.ty,y),A)))\mathrm{Formula.allRel}(xs, \mathrm{Formula.ex}(y, \mathrm{Formula.tensor}(\mathrm{Formula.existPred}(y.\mathrm{ty}, y), A)))Formula.allRel(xs,Formula.ex(y,Formula.tensor(Formula.existPred(y.ty,y),A)))); and 7. FreshRealizerVars(Δ,Γ,M,F)\mathrm{FreshRealizerVars}(\Delta, \Gamma, M, F)FreshRealizerVars(Δ,Γ,M,F) holds, meaning that across allU:=Δ+ ⁣+Γ+ ⁣+allAssumpVars(M)\mathit{allU} := \Delta \mathbin{+\!+} \Gamma \mathbin{+\!+} \mathrm{allAssumpVars}(M)allU:=Δ++Γ++allAssumpVars(M), any two assumption variables u,v∈allUu, v \in \mathit{allU}u,v∈allU with u.id=v.idu.\mathrm{id} = v.\mathrm{id}u.id=v.id are identical (u=vu = vu=v), and for every u∈allUu \in \mathit{allU}u∈allU, its realizer variable xu=(2 u.id+1,τ(u.formula))x_u = (2\,u.\mathrm{id} + 1, \tau(u.\mathrm{formula}))xu​=(2u.id+1,τ(u.formula)) does not occur free in FFF or in w.formulaw.\mathrm{formula}w.formula for any w∈Δ+ ⁣+Γw \in \Delta \mathbin{+\!+} \Gammaw∈Δ++Γ.

Then there exist a bounding function B:N→NB : \mathbb{N} \to \mathbb{N}B:N→N and an additive constant k∈Nk \in \mathbb{N}k∈N such that:

  1. BBB is bounded by a polynomial of degree at most d:=max⁡(iterNesting(⟦M⟧c),1)d := \max(\mathrm{iterNesting}(\llbracket M \rrbracket^c), 1)d:=max(iterNesting([[M]]c),1) (BoundedByPolyOfDegree(B,d)\mathrm{BoundedByPolyOfDegree}(B, d)BoundedByPolyOfDegree(B,d), meaning ∃c0,c1∈N, ∀n∈N, B(n)≤c0 (n+1)d+c1\exists c_0, c_1 \in \mathbb{N},\, \forall n \in \mathbb{N},\, B(n) \le c_0\,(n + 1)^d + c_1∃c0​,c1​∈N,∀n∈N,B(n)≤c0​(n+1)d+c1​, where ⟦M⟧c=extractCleaned(M)\llbracket M \rrbracket^c = \mathrm{extractCleaned}(M)[[M]]c=extractCleaned(M)); and
  2. for every list of input terms ws=[w1,…,wm]∈List(Term)ws = [w_1, \dots, w_m] \in \mathrm{List}(\mathrm{Term})ws=[w1​,…,wm​]∈List(Term) satisfying ValidDataInputs(⟦M⟧c,[x1.ty,…,xm.ty],ws)\mathrm{ValidDataInputs}(\llbracket M \rrbracket^c, [x_1.\mathrm{ty}, \dots, x_m.\mathrm{ty}], ws)ValidDataInputs([[M]]c,[x1​.ty,…,xm​.ty],ws) (meaning ∣ws∣=m|ws| = m∣ws∣=m, each wiw_iwi​ is an almost closed normal linearly well-typed term of type xi.tyx_i.\mathrm{ty}xi​.ty, and the free variables of ⟦M⟧c,w1,…,wm\llbracket M \rrbracket^c, w_1, \dots, w_m[[M]]c,w1​,…,wm​ are pairwise disjoint), there exist a step count steps∈N\mathit{steps} \in \mathbb{N}steps∈N and an output term w∈Termw \in \mathrm{Term}w∈Term such that:
    • the iterated application (⋯((⟦M⟧c w1) w2)⋯ ) wm(\cdots((\llbracket M \rrbracket^c\,w_1)\,w_2)\cdots)\,w_m(⋯(([[M]]cw1​)w2​)⋯)wm​ (Term.appMany(⟦M⟧c,ws)\mathrm{Term.appMany}(\llbracket M \rrbracket^c, ws)Term.appMany([[M]]c,ws)) reduces to www in steps\mathit{steps}steps steps (RedSteps(steps,Term.appMany(⟦M⟧c,ws),w)\mathrm{RedSteps}(\mathit{steps}, \mathrm{Term.appMany}(\llbracket M \rrbracket^c, ws), w)RedSteps(steps,Term.appMany([[M]]c,ws),w));
    • www is a data object of type y.tyy.\mathrm{ty}y.ty (IsDataObject(y.ty,w)\mathrm{IsDataObject}(y.\mathrm{ty}, w)IsDataObject(y.ty,w));
    • steps≤B(totalTermLength(ws))\mathit{steps} \le B(\mathrm{totalTermLength}(ws))steps≤B(totalTermLength(ws)), termLength(w)≤totalTermLength(ws)+k\mathrm{termLength}(w) \le \mathrm{totalTermLength}(ws) + ktermLength(w)≤totalTermLength(ws)+k, and freeVarCount(w)≤totalFreeVarCount(ws)+k\mathrm{freeVarCount}(w) \le \mathrm{totalFreeVarCount}(ws) + kfreeVarCount(w)≤totalFreeVarCount(ws)+k; and
    • the substituted formula
((⋯(A[w1/x1])⋯ )[wm/xm])[w/y]\big((\cdots(A[w_1/x_1])\cdots)[w_m/x_m]\big)[w/y]((⋯(A[w1​/x1​])⋯)[wm​/xm​])[w/y]
 ($\mathrm{substFormula}(\mathrm{substFormulaMany}(A, xs.\mathrm{zip}(ws)), y, w)$) is provable in passive context $\mathrm{mrContext}(\Delta \mathbin{+\!+} \Gamma)$ and empty active context $[]$ ($\mathrm{Provable}(\mathrm{mrContext}(\Delta \mathbin{+\!+} \Gamma), [], \dots)$).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me