Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Elimination of Recursors from RS-Terms with Polynomial Length Bound (Theorem 4.5)

Open
BNS2000.theorem_4_5

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

implicit-computational-complexitypolynomial-timeproof-theoryramified-recursiontype-theory

Theorem 4.5 (pp. 25-26): For every RS-term t whose free variables are ground, there is a polynomial q_t such that for any closed R-free RS-terms n⃗, t[n⃗/x⃗] is equivalent to an R-free RS-term rf_t(n⃗) of length at most q_t(∑ |n_i|).

Preamble
import Definitions.Def_BNS2000_Terms
Formal statement
namespace BNS2000

/-- **Theorem 4.5 (`R`-Elimination)** (Section 4, p. 24):
Let `t` be an `RS`-term of safe or ground type `τ`. Then there exists a univariate polynomial
`q_t : Nat → Nat` (`IsUnivariatePoly q_t`) such that for every environment `n⃗; x⃗` of closed
ground-type `R`-free `RS`-terms (`IsClosedGroundRFreeRSEnv env`) with `FV(t[n⃗/x⃗])` all safe,
there exists an `R`-free `RS`-term `rf_t` equivalent to `t[n⃗/x⃗]` (with `FV(rf_t) ⊆ FV(t[n⃗/x⃗])`
and `|rf_t| ≤ q_t(∑ |nᵢ|)`) such that if `τ` is ground and `t[n⃗/x⃗]` is closed, `rf_t`
normalizes via `NFEval` in at most `2 · q_t(∑ |nᵢ|)` steps using at most `q_t(∑ |nᵢ|)` registers. -/
theorem theorem_4_5
    (t : Term) (τ : Ty)
    (ht : IsRSTerm t)
    (hτ : HasType t τ)
    (hSafeOrGround : τ.isSafe = true ∨ τ.isGround = true) :
    ∃ q_t : Nat → Nat,
      IsUnivariatePoly q_t ∧
      ∀ env : List (Var × Term),
        IsClosedGroundRFreeRSEnv env →
        (∀ v ∈ freeVars (substEnv t env), v.ty.isSafe = true) →
        ∃ rf_t : Term,
          IsRSTerm rf_t ∧
          isRFree rf_t = true ∧
          HasType rf_t τ ∧
          TermEquiv rf_t (substEnv t env) ∧
          (∀ v ∈ freeVars rf_t, v ∈ freeVars (substEnv t env)) ∧
          termLength rf_t ≤ q_t (sumEnvTermLength env) := by
  sorry

end BNS2000
Source
Stephen Bellantoni, Karl-Heinz Niggl, and Helmut Schwichtenberg, 'Higher type recursion, ramification and polynomial time', Annals of Pure and Applied Logic 104, 2000, pp. 17-30 (doi:10.1016/S0168-0072(00)00006-3). Section 4, Theorem 4.5, pp. 25-26.
Read-back

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

Read-back: Thm_BNS2000_theorem_4_5.lean

theorem_4_5

Let t∈Termt \in \mathsf{Term}t∈Term and τ∈Ty\tau \in \mathsf{Ty}τ∈Ty be such that:

  • ttt is an RS\mathsf{RS}RS-term (IsRSTerm(t)\mathsf{IsRSTerm}(t)IsRSTerm(t), meaning ttt is a well-typed RA\mathsf{RA}RA-term in which every occurring variable has safe or ground type and every higher-type variable has at most one free occurrence in ttt and in each λ\lambdaλ-scope),
  • ttt has type τ\tauτ (HasType(t,τ)\mathsf{HasType}(t, \tau)HasType(t,τ)), and
  • τ\tauτ is either a safe type (isSafe(τ)=true\mathsf{isSafe}(\tau) = \mathsf{true}isSafe(τ)=true, i.e., !!!-free) or a ground type (isGround(τ)=true\mathsf{isGround}(\tau) = \mathsf{true}isGround(τ)=true, i.e., l(τ)=0l(\tau) = 0l(τ)=0).

Then there exists a function qt:N→Nq_t : \mathbb{N} \to \mathbb{N}qt​:N→N such that:

  1. qtq_tqt​ is a univariate polynomial with natural-number coefficients (IsUnivariatePoly(qt)\mathsf{IsUnivariatePoly}(q_t)IsUnivariatePoly(qt​), built inductively from constants, the identity function, addition, and multiplication); and
  2. for every environment env=[(x1,n1),…,(xk,nk)]∈List(Var×Term)\mathsf{env} = [(x_1, n_1), \dots, (x_k, n_k)] \in \mathsf{List}(\mathsf{Var} \times \mathsf{Term})env=[(x1​,n1​),…,(xk​,nk​)]∈List(Var×Term), if:
    • env\mathsf{env}env is an environment of closed ground-type RRR-free RS\mathsf{RS}RS-terms (IsClosedGroundRFreeRSEnv(env)\mathsf{IsClosedGroundRFreeRSEnv}(\mathsf{env})IsClosedGroundRFreeRSEnv(env), meaning x1,…,xkx_1, \dots, x_kx1​,…,xk​ are pairwise distinct and for each (xi,ni)∈env(x_i, n_i) \in \mathsf{env}(xi​,ni​)∈env, HasType(ni,xi.ty)\mathsf{HasType}(n_i, x_i.\mathsf{ty})HasType(ni​,xi​.ty), l(xi.ty)=0l(x_i.\mathsf{ty}) = 0l(xi​.ty)=0, freeVars(ni)=[]\mathsf{freeVars}(n_i) = []freeVars(ni​)=[], isRFree(ni)=true\mathsf{isRFree}(n_i) = \mathsf{true}isRFree(ni​)=true, and IsRSTerm(ni)\mathsf{IsRSTerm}(n_i)IsRSTerm(ni​)), and
    • every free variable v∈freeVars(substEnv(t,env))v \in \mathsf{freeVars}(\mathsf{substEnv}(t, \mathsf{env}))v∈freeVars(substEnv(t,env)) remaining after substituting env\mathsf{env}env into ttt has a safe (!!!-free) type (isSafe(v.ty)=true\mathsf{isSafe}(v.\mathsf{ty}) = \mathsf{true}isSafe(v.ty)=true), then there exists a term rf_t∈Term\mathsf{rf\_t} \in \mathsf{Term}rf_t∈Term such that:
    • rf_t\mathsf{rf\_t}rf_t is an RS\mathsf{RS}RS-term (IsRSTerm(rf_t)\mathsf{IsRSTerm}(\mathsf{rf\_t})IsRSTerm(rf_t)),
    • rf_t\mathsf{rf\_t}rf_t contains no recursor constant RσR_\sigmaRσ​ (isRFree(rf_t)=true\mathsf{isRFree}(\mathsf{rf\_t}) = \mathsf{true}isRFree(rf_t)=true),
    • rf_t\mathsf{rf\_t}rf_t has type τ\tauτ (HasType(rf_t,τ)\mathsf{HasType}(\mathsf{rf\_t}, \tau)HasType(rf_t,τ)),
    • rf_t\mathsf{rf\_t}rf_t and substEnv(t,env)\mathsf{substEnv}(t, \mathsf{env})substEnv(t,env) are term-equivalent (TermEquiv(rf_t,substEnv(t,env))\mathsf{TermEquiv}(\mathsf{rf\_t}, \mathsf{substEnv}(t, \mathsf{env}))TermEquiv(rf_t,substEnv(t,env)), meaning there exists a common term uuu that is a normal form of both rf_t\mathsf{rf\_t}rf_t and substEnv(t,env)\mathsf{substEnv}(t, \mathsf{env})substEnv(t,env)),
    • every free variable of rf_t\mathsf{rf\_t}rf_t is a free variable of substEnv(t,env)\mathsf{substEnv}(t, \mathsf{env})substEnv(t,env) (∀v∈freeVars(rf_t),  v∈freeVars(substEnv(t,env))\forall v \in \mathsf{freeVars}(\mathsf{rf\_t}),\; v \in \mathsf{freeVars}(\mathsf{substEnv}(t, \mathsf{env}))∀v∈freeVars(rf_t),v∈freeVars(substEnv(t,env))), and
    • the term length of rf_t\mathsf{rf\_t}rf_t is bounded by qtq_tqt​ evaluated at the sum of the term lengths of the environment terms:
∣rf_t∣≤qt ⁣(∑i=1k∣ni∣).|\mathsf{rf\_t}| \le q_t\!\left(\sum_{i=1}^k |n_i|\right).∣rf_t∣≤qt​(i=1∑k​∣ni​∣).

Edge-Case and Faithfulness Notes

  • Because every (xi,ni)∈env(x_i, n_i) \in \mathsf{env}(xi​,ni​)∈env satisfies IsClosed(ni)\mathsf{IsClosed}(n_i)IsClosed(ni​) and x1,…,xkx_1, \dots, x_kx1​,…,xk​ are pairwise distinct, the sequential substitution substEnv(t,env)\mathsf{substEnv}(t, \mathsf{env})substEnv(t,env) coincides with simultaneous substitution t[n⃗/x⃗]t[\vec{n}/\vec{x}]t[n/x].
  • Because any variable vvv occurring in ttt has safe or ground type (AllVarsSafeOrGround(t)\mathsf{AllVarsSafeOrGround}(t)AllVarsSafeOrGround(t)), the hypothesis that all free variables of substEnv(t,env)\mathsf{substEnv}(t, \mathsf{env})substEnv(t,env) are safe is equivalent to requiring that every free variable of ttt whose type is not safe (namely, every complete ground variable of type !mι!^m \iota!mι with m≥1m \ge 1m≥1) is bound in env\mathsf{env}env.
  • The docstring of theorem_4_5 additionally mentions that when τ\tauτ is ground and t[n⃗/x⃗]t[\vec{n}/\vec{x}]t[n/x] is closed, rf_t\mathsf{rf\_t}rf_t normalizes via NFEval\mathsf{NFEval}NFEval in at most 2⋅qt(∑∣ni∣)2 \cdot q_t(\sum |n_i|)2⋅qt​(∑∣ni​∣) steps using at most qt(∑∣ni∣)q_t(\sum |n_i|)qt​(∑∣ni​∣) registers; that corollary (which follows by applying Part 2 of theorem_4_3_and_4_4 to rf_t\mathsf{rf\_t}rf_t) is not included as a conjunct in theorem_4_5 itself, and instead appears in theorem_5_1.
Human review
  • Endorsed by Shuze Chen · Nov 20, 2026

  • Endorsed by kmehltretter82 · Nov 20, 2026

    Confirmed by the mission captain (proposal self-audit).

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