Documentation

CslibFrontier.Computability.GenericRAM.Native.StackRecursion

Native Turing-machine certificates for explicit-stack recursion #

The pure explicit-stack depth-first recursion scheme (Cslib.Algorithms.StackRecursion.Scheme, Invariant, State, Scheme.Loop, Scheme.Eval, Scheme.step, Scheme.run) is defined without any machine model in CslibFrontier.Algorithms.Recursion.StackScheme.

The native certificate (Scheme.certificate). The leaf step is an arbitrary native certificate; the other components are polynomial-time (Scheme.PolyTime). One fixed machine runs the stack machine for a natively computed number fuel a of steps (NativeCertificate.iterate) and returns the register. When 2 * n - 1 ≤ fuel a the result is y (Scheme.run_eq_some). If every node, frame and value on the derivation has encoded length at most F and every leaf is evaluated within time TL and space SL, the time is at most fuel a + 1 times K ((h + 1) (F + 1)) ^ K + TL and the workspace at most K ((h + 1) (F + 1)) ^ K + SL, up to the cost of computing the fuel and the root and of the binary clock, for one constant K of the scheme (Scheme.certificate_le). Only the stack is kept, so the workspace grows with the depth, not with the number of nodes. The number of nodes of a recursion tree is bounded in CslibFrontier/Foundations/Data/Nat/RecursionTree.lean.

This is the depth-first evaluation of the recursion in the proof of Theorem D.1 of [OAI26k] (Appendix D.4.7, p. 64), which keeps one sum over mode tuples and one product over groups per stack level. The scheme is generic: the recursion of Appendix D.4 is one instance, with its leaves evaluated by direct summation.

Main definitions #

Main results #

References #

The native machine #

@[reducible, inline]
abbrev Cslib.Algorithms.StackRecursion.Scheme.encState {X A Y : Type} (encX : X ↪ List Bool) (encA : A ↪ List Bool) (encY : Y ↪ List Bool) :

The encoding of a machine state: the list of open frames, each a pair, then the optional pending node and the optional returned value.

structure Cslib.Algorithms.StackRecursion.Scheme.PolyTime {X A Y : Type} (R : Scheme X A Y) (encX : X ↪ List Bool) (encA : A ↪ List Bool) (encY : Y ↪ List Bool) :

The polynomial-time components of a scheme: everything but the leaf step.

noncomputable def Cslib.Algorithms.StackRecursion.Scheme.stepCertificate {X A Y : Type} {R : Scheme X A Y} {encX : X ↪ List Bool} {encA : A ↪ List Bool} {encY : Y ↪ List Bool} (h : R.PolyTime encX encA encY) (leaf : GenericRAM.NativeCertificate R.leaf encX encY) :
GenericRAM.NativeCertificate R.step (encState encX encA encY) (encState encX encA encY)

One step of the machine: the leaf certificate on a pending leaf, and a polynomial-time step otherwise.

def Cslib.Algorithms.StackRecursion.Scheme.leafCost {X A Y : Type} (R : Scheme X A Y) (cost : X → ℕ) (σ : State X A Y) :

The leaf cost of a state: the leaf certificate's bound at a pending leaf, and zero otherwise.

theorem Cslib.Algorithms.StackRecursion.Scheme.exists_stepCertificate_le {X A Y : Type} {R : Scheme X A Y} {encX : X ↪ List Bool} {encA : A ↪ List Bool} {encY : Y ↪ List Bool} (h : R.PolyTime encX encA encY) (leaf : GenericRAM.NativeCertificate R.leaf encX encY) :
∃ (K : ℕ), ∀ (σ : State X A Y), (stepCertificate h leaf).time σ ≤ K * (((encState encX encA encY) σ).length + 1) ^ K + R.leafCost leaf.time σ ∧ (stepCertificate h leaf).space σ ≤ K * (((encState encX encA encY) σ).length + 1) ^ K + R.leafCost leaf.space σ

The cost of one step: a polynomial in the state length, plus the leaf certificate at a pending leaf.

noncomputable def Cslib.Algorithms.StackRecursion.Scheme.certificate {X A Y : Type} {R : Scheme X A Y} {encX : X ↪ List Bool} {encA : A ↪ List Bool} {encY : Y ↪ List Bool} (h : R.PolyTime encX encA encY) (leaf : GenericRAM.NativeCertificate R.leaf encX encY) {I : Type} {encIn : I ↪ List Bool} {fuel : I → ℕ} {root : I → X} (cn : GenericRAM.NativeCertificate fuel encIn Turing.MultiTapeTM.encNat) (croot : GenericRAM.NativeCertificate root encIn encX) :

The native machine for the clocked run: one fixed machine, from native certificates for the fuel and the root.

theorem Cslib.Algorithms.StackRecursion.Scheme.length_encState_le {X A Y : Type} {encX : X ↪ List Bool} {encA : A ↪ List Bool} {encY : Y ↪ List Bool} {Inv : Invariant X A Y} {H F : ℕ} {σ : State X A Y} (hσ : Good Inv H σ) (hnode : ∀ (x : X), Inv.node x → (encX x).length ≤ F) (hframe : ∀ (x : X) (a : A), Inv.frame x a → ((Turing.MultiTapeTM.encPair encX encA) (x, a)).length ≤ F) (hvalue : ∀ (y : Y), Inv.value y → (encY y).length ≤ F) :
((encState encX encA encY) σ).length ≤ 5 * (H + 1) * (F + 1)

A good state is at most 5 (H + 1) (F + 1) long when the nodes, frames and values it holds are at most F long.

theorem Cslib.Algorithms.StackRecursion.Scheme.certificate_le {X A Y : Type} {R : Scheme X A Y} {encX : X ↪ List Bool} {encA : A ↪ List Bool} {encY : Y ↪ List Bool} (h : R.PolyTime encX encA encY) (leaf : GenericRAM.NativeCertificate R.leaf encX encY) :
∃ (K : ℕ), ∀ {I : Type} {encIn : I ↪ List Bool} {fuel : I → ℕ} {root : I → X} (cn : GenericRAM.NativeCertificate fuel encIn Turing.MultiTapeTM.encNat) (croot : GenericRAM.NativeCertificate root encIn encX) (Inv : Invariant X A Y) (F TL SL : ℕ), (∀ (x : X), Inv.node x → (encX x).length ≤ F ∧ (R.isLeaf x = true → leaf.time x ≤ TL ∧ leaf.space x ≤ SL)) → (∀ (x : X) (a : A), Inv.frame x a → ((Turing.MultiTapeTM.encPair encX encA) (x, a)).length ≤ F) → (∀ (y : Y), Inv.value y → (encY y).length ≤ F) → ∀ (a : I) (y : Y) (N H : ℕ), R.Eval Inv (root a) y N H → (certificate h leaf cn croot).time a ≤ cn.time a + croot.time a + 2 * (encIn a).length + (fuel a + 1) * (K * ((H + 1) * (F + 1)) ^ K + TL + ((Turing.MultiTapeTM.encNat (fuel a)).length + 1) ^ 2) ∧ (certificate h leaf cn croot).space a ≤ cn.space a + croot.space a + 2 * (encIn a).length + K * ((H + 1) * (F + 1)) ^ K + SL + (Turing.MultiTapeTM.encNat (fuel a)).length

The resources of the native machine. There is one constant K such that, for any fuel and root certificates, if the root has a derivation with N nodes and at most H open calls whose nodes, frames and values are at most F long, and whose leaves are evaluated by the leaf certificate within time TL and space SL, then the time is at most the cost of the fuel and the root plus fuel + 1 times K ((H + 1) (F + 1)) ^ K + TL (and the cost of the binary clock), and the workspace is at most the cost of the fuel and the root plus K ((H + 1) (F + 1)) ^ K + SL. The bounds hold for any fuel; with 2 * N - 1 ≤ fuel the result is the value (run_eq_some).