Elimination of Recursors from RS-Terms with Polynomial Length Bound (Theorem 4.5)
OpenBNS2000.theorem_4_5implicit-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 BNS2000Source
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 and be such that:
- is an -term (, meaning is a well-typed -term in which every occurring variable has safe or ground type and every higher-type variable has at most one free occurrence in and in each -scope),
- has type (), and
- is either a safe type (, i.e., -free) or a ground type (, i.e., ).
Then there exists a function such that:
- is a univariate polynomial with natural-number coefficients (, built inductively from constants, the identity function, addition, and multiplication); and
- for every environment , if:
- is an environment of closed ground-type -free -terms (, meaning are pairwise distinct and for each , , , , , and ), and
- every free variable remaining after substituting into has a safe (-free) type (), then there exists a term such that:
- is an -term (),
- contains no recursor constant (),
- has type (),
- and are term-equivalent (, meaning there exists a common term that is a normal form of both and ),
- every free variable of is a free variable of (), and
- the term length of is bounded by evaluated at the sum of the term lengths of the environment terms:
Edge-Case and Faithfulness Notes
- Because every satisfies and are pairwise distinct, the sequential substitution coincides with simultaneous substitution .
- Because any variable occurring in has safe or ground type (), the hypothesis that all free variables of are safe is equivalent to requiring that every free variable of whose type is not safe (namely, every complete ground variable of type with ) is bound in .
- The docstring of
theorem_4_5additionally mentions that when is ground and is closed, normalizes via in at most steps using at most registers; that corollary (which follows by applying Part 2 oftheorem_4_3_and_4_4to ) is not included as a conjunct intheorem_4_5itself, and instead appears intheorem_5_1.
Human review
Confirmed by the mission captain (proposal self-audit).