Documentation

CslibFrontier.Computability.Complexity.FineGrained.DisjointInstances

Size-sensitive reductions, summed disjoint-instance lists, and live-workspace accumulation #

Fine-grained and exact exponential reductions fall into three reusable patterns:

  1. Single-instance size-sensitive reductions (Cslib.Complexity.SizeSensitiveReduction): a polynomial-time map toFun : α → β with an explicit affine parameter bound μB (toFun a) ≤ scale * μA a + offset. Keeping scale and offset separate preserves the exact multiplicative rate scale * δ when transferring 2 ^ (δ * μB) bounds, while absorbing 2 ^ (δ * offset) into the leading constant (SizeSensitiveReduction.decidableInExpTime, SizeSensitiveReduction.decidableInSubexpTime) and bounding workspace in terms of input, intermediate instance length, and simulated space rather than simulated running time (SizeSensitiveReduction.exists_computableInO_comp).
  2. Materialized disjoint-instance batches (Cslib.Complexity.InstanceBatch, Cslib.Complexity.CNFInstanceBatch, Cslib.Complexity.DisjointBatchReduction): a batch of instances xs : InstanceBatch β with summed parameter xs.sumMeasure μ = (xs.items.map μ).sum processed sequentially via Turing.MultiTapeTM.ComputableInO.foldl, together with a capped binary counter Cslib.Complexity.CappedNatAcc keeping live accumulator bit-length polynomial during exact counting sums.
  3. Depth-first stack accumulation (Cslib.Complexity.StackAccumulationSpec): sequential depth-first generation and accumulation over up to 2 ^ ν(a) leaf subinstances without materializing the exponentially long output list, abstracting the disjoint-list / sparsification search pattern (Cslib.BinaryBranching). Time accumulates across all rounds while maximum live workspace depends only on the live stack, accumulator, binary round counter, and single-leaf solver space.

Main definitions #

Main results #

References #

Single-instance size-sensitive reductions #

structure Cslib.Complexity.SizeSensitiveReduction {α β : Type} (encA : α ↪ List Bool) (encB : β ↪ List Bool) (μA : α → ℕ) (μB : β → ℕ) :

A size-sensitive reduction from (α, encA, μA) to (β, encB, μB) [IPZ01]: a polynomial-time map toFun : α → β with explicit multiplicative scale scale and additive offset offset bounding μB (toFun a) ≤ scale * μA a + offset.

def Cslib.Complexity.SizeSensitiveReduction.refl {α : Type} (encA : α ↪ List Bool) (μA : α → ℕ) :
SizeSensitiveReduction encA encA μA μA

Identity size-sensitive reduction (scale = 1, offset = 0).

def Cslib.Complexity.SizeSensitiveReduction.trans {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} {μC : γ → ℕ} (r : SizeSensitiveReduction encA encB μA μB) (s : SizeSensitiveReduction encB encC μB μC) :
SizeSensitiveReduction encA encC μA μC

Composition of size-sensitive reductions, multiplying scales and composing offsets.

@[simp]
theorem Cslib.Complexity.SizeSensitiveReduction.refl_toFun {α : Type} (encA : α ↪ List Bool) (μA : α → ℕ) :
(refl encA μA).toFun = id
@[simp]
theorem Cslib.Complexity.SizeSensitiveReduction.trans_toFun {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} {μC : γ → ℕ} (r : SizeSensitiveReduction encA encB μA μB) (s : SizeSensitiveReduction encB encC μB μC) :
theorem Cslib.Complexity.SizeSensitiveReduction.polyBounded_output_length {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) :
Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) fun (a : α) => (encB (r.toFun a)).length

Encoded output length of a size-sensitive reduction is polynomially bounded in encoded input length.

theorem Cslib.Complexity.SizeSensitiveReduction.toPolyTimeReducible {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) {A : Set α} {B : Set β} (hAB : ∀ (a : α), a ∈ A ↔ r.toFun a ∈ B) :
PolyTimeReducible encA encB A B

A membership-preserving SizeSensitiveReduction induces PolyTimeReducible.

theorem Cslib.Complexity.SizeSensitiveReduction.toParsimoniousReducible {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) {f : α → ℕ} {g : β → ℕ} (hfg : ∀ (a : α), f a = g (r.toFun a)) :
ParsimoniousReducible encA encB f g

A count-preserving SizeSensitiveReduction induces ParsimoniousReducible.

theorem Cslib.Complexity.SizeSensitiveReduction.decidableInExpTime {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) {A : Set α} {B : Set β} (hAB : ∀ (a : α), a ∈ A ↔ r.toFun a ∈ B) {δ : ℝ} (hδ : 0 ≤ δ) (hB : DecidableInExpTime B encB μB δ) :
DecidableInExpTime A encA μA (↑r.scale * δ)

Exact-scale exponential-time transfer. A decider for B within time 2 ^ (δ * μB b) * poly(|b|) transfers along r to a decider for A within time 2 ^ (r.scale * δ * μA a) * poly(|a|), keeping r.scale * δ independent of r.offset.

theorem Cslib.Complexity.SizeSensitiveReduction.decidableInSubexpTime {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) {A : Set α} {B : Set β} (hAB : ∀ (a : α), a ∈ A ↔ r.toFun a ∈ B) (hB : DecidableInSubexpTime B encB μB) :

Subexponential-time transfer along a size-sensitive reduction.

theorem Cslib.Complexity.SizeSensitiveReduction.exists_computableInO_comp {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) {g : β → γ} {Tg Sg : β → ℕ} (hg : Turing.MultiTapeTM.ComputableInO g encB encC Tg Sg) (hSg : Turing.MultiTapeTM.PolyBounded (fun (b : β) => (encB b).length) Sg) :
∃ (d : ℕ) (S : α → ℕ), Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) S ∧ Turing.MultiTapeTM.ComputableInO (g ∘ r.toFun) encA encC (fun (a : α) => ((encA a).length + 1) ^ d + Tg (r.toFun a)) S

Independent time and live-workspace composition. Composing g (ComputableInO g encB encC Tg Sg) with r bounds workspace by a polynomial in |encA a| plus Sg (r.toFun a) (never by Tg (r.toFun a)), so polynomial space transfers without bounding space by simulated time.

theorem Cslib.Complexity.SizeSensitiveReduction.computableInPolySpace_comp {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) {g : β → γ} (hg : Turing.MultiTapeTM.ComputableInPolySpace g encB encC) :

Polynomial space transfers along any SizeSensitiveReduction.

Summed parameter lists and capped binary accumulators #

A batch of subinstances items : List α, used to track summed and maximum parameter measures across disjoint-instance reductions.

  • items : List α

    The ordered list of subinstances.

Instances For
    theorem Cslib.Complexity.InstanceBatch.ext {α : Type} {x y : InstanceBatch α} (items : x.items = y.items) :
    x = y
    def Cslib.Complexity.instDecidableEqInstanceBatch.decEq {α✝ : Type} [DecidableEq α✝] (x✝ x✝¹ : InstanceBatch α✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    @[instance_reducible]

    The empty batch of subinstances.

    A single-element batch.

    Concatenation of two subinstance batches.

    Number of subinstances in the batch.

    Summed parameter measure ∑ a ∈ xs.items, μ a.

    Maximum parameter measure max_{a ∈ xs.items} μ a (0 on the empty batch).

    @[simp]
    theorem Cslib.Complexity.InstanceBatch.sumMeasure_singleton {α : Type} (μ : α → ℕ) (a : α) :
    sumMeasure μ (singleton a) = μ a
    @[simp]
    theorem Cslib.Complexity.InstanceBatch.sumMeasure_append {α : Type} (μ : α → ℕ) (xs ys : InstanceBatch α) :
    sumMeasure μ (xs.append ys) = sumMeasure μ xs + sumMeasure μ ys
    theorem Cslib.Complexity.InstanceBatch.le_sumMeasure_of_mem {α : Type} (μ : α → ℕ) {xs : InstanceBatch α} {a : α} (ha : a ∈ xs.items) :
    μ a ≤ sumMeasure μ xs

    Every subinstance in a batch has measure at most the batch's summed measure.

    The maximum subinstance measure is bounded by the summed measure.

    Encoding of InstanceBatch α as the framed list of its items (encList encA).

    A concrete batch of CNF formulas over a shared number declaredVars of declared variables, as produced by disjoint/counting sparsification.

    • declaredVars : ℕ

      Shared number of declared variables 0, …, declaredVars - 1.

    • formulas : List (Logic.PL.CNF ℕ)

      Disjoint subformulas whose satisfying assignments partition or cover the target set.

    Instances For
      theorem Cslib.Complexity.encCNFInstanceBatch_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget x0 : γ → ℕ} {x1 : γ → List (Logic.PL.CNF ℕ)} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encUnary budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn (Turing.MultiTapeTM.encList encCNF) budget) :
      Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { declaredVars := x0 x, formulas := x1 x }) encIn encCNFInstanceBatch budget
      theorem Cslib.Complexity.encCNFInstanceBatch_declaredVars_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → CNFInstanceBatch} :

      Framed encoding of a CNFInstanceBatch: declaredVars in unary followed by the framed list of CNF formulas.

      theorem Cslib.Complexity.encCNFInstanceBatch_formulas_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → CNFInstanceBatch} :
      theorem Cslib.Complexity.encCNFInstanceBatch_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 T0 S0 : γ → ℕ} {x1 : γ → List (Logic.PL.CNF ℕ)} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encUnary T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encList encCNF) T1 S1) :
      Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { declaredVars := x0 x, formulas := x1 x }) encIn encCNFInstanceBatch (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x

      Sum of declared-variable model counts across all formulas in b.

      Disjunctive satisfiability across the formulas in b.

      Summed distinct-variable measure across the formulas in b.

      A capped binary accumulator (cap, total) keeping total ≤ cap at every step so its encoded bit-length stays bounded by O(log₂ cap) regardless of the number of accumulated terms.

      • cap : ℕ

        Upper cap on the running sum.

      • total : ℕ

        Current capped sum (total ≤ cap along initialized runs).

      Instances For
        theorem Cslib.Complexity.CappedNatAcc.ext {x y : CappedNatAcc} (cap : x.cap = y.cap) (total : x.total = y.total) :
        x = y
        theorem Cslib.Complexity.encCappedNatAcc_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 T0 S0 x1 T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encNat T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) :
        Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { cap := x0 x, total := x1 x }) encIn encCappedNatAcc (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
        theorem Cslib.Complexity.encCappedNatAcc_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget x0 x1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encNat budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) :
        Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { cap := x0 x, total := x1 x }) encIn encCappedNatAcc budget
        @[reducible, inline]

        The tuple of the fields of encCappedNatAcc.

        theorem Cslib.Complexity.encCappedNatAcc_total_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → CappedNatAcc} :
        theorem Cslib.Complexity.encCappedNatAcc_cap_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → CappedNatAcc} :

        Initialize a capped accumulator at 0 with cap c.

        Add v to acc, clamping at acc.cap.

        @[simp]
        @[simp]
        theorem Cslib.Complexity.CappedNatAcc.add_total (acc : CappedNatAcc) (v : ℕ) :
        (acc.add v).total = min acc.cap (acc.total + v)
        theorem Cslib.Complexity.CappedNatAcc.foldl_add_eq {β : Type} (g : β → ℕ) (xs : List β) (acc : CappedNatAcc) (hacc : acc.total ≤ acc.cap) :
        List.foldl (fun (s : CappedNatAcc) (b : β) => s.add (g b)) acc xs = { cap := acc.cap, total := min acc.cap (acc.total + (List.map g xs).sum) }

        Folding CappedNatAcc.add over xs preserves cap and computes min cap (acc.total + sum).

        theorem Cslib.Complexity.CappedNatAcc.foldl_add_init_total {β : Type} (g : β → ℕ) (xs : List β) (c : ℕ) :
        (List.foldl (fun (s : CappedNatAcc) (b : β) => s.add (g b)) (init c) xs).total = min c (List.map g xs).sum

        Folding CappedNatAcc.add from init c yields min c ((xs.map g).sum).

        theorem Cslib.Complexity.CappedNatAcc.foldl_add_init_total_eq_sum {β : Type} (g : β → ℕ) (xs : List β) {c : ℕ} (hsum : (List.map g xs).sum ≤ c) :
        (List.foldl (fun (s : CappedNatAcc) (b : β) => s.add (g b)) (init c) xs).total = (List.map g xs).sum

        When the true sum does not exceed c, the capped fold computes (xs.map g).sum exactly.

        theorem Cslib.Complexity.CappedNatAcc.length_encCappedNatAcc_le_of_le_two_pow {acc : CappedNatAcc} {k : ℕ} (htot : acc.total ≤ acc.cap) (hcap : acc.cap ≤ 2 ^ k) :
        (encCappedNatAcc acc).length ≤ 3 * (k + 1) + 2

        Whenever acc.total ≤ acc.cap and acc.cap ≤ 2 ^ k, the framed binary encoding of acc has length at most 3 * (k + 1) + 2.

        Materialized disjoint-instance list reductions with summed measure #

        structure Cslib.Complexity.DisjointBatchReduction {α β : Type} (encA : α ↪ List Bool) (encB : β ↪ List Bool) (μA : α → ℕ) (μB : β → ℕ) :

        A polynomial-time reduction mapping each source instance a : α to an InstanceBatch β whose summed target measure sumMeasure μB is bounded by scale * μA a + offset.

        def Cslib.Complexity.DisjointBatchReduction.ofSizeSensitive {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : SizeSensitiveReduction encA encB μA μB) :
        DisjointBatchReduction encA encB μA μB

        Every SizeSensitiveReduction embeds as a singleton DisjointBatchReduction with the same scale and offset.

        theorem Cslib.Complexity.DisjointBatchReduction.measure_mem_le {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : DisjointBatchReduction encA encB μA μB) (a : α) {b : β} (hb : b ∈ (r.toBatch a).items) :
        μB b ≤ r.scale * μA a + r.offset

        Every subinstance in r.toBatch a individually satisfies μB b ≤ r.scale * μA a + r.offset.

        theorem Cslib.Complexity.DisjointBatchReduction.polyBounded_batch_length {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : DisjointBatchReduction encA encB μA μB) :
        Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) fun (a : α) => ((Turing.MultiTapeTM.encList encB) (r.toBatch a).items).length

        Encoded length of the materialized batch r.toBatch a is polynomially bounded in |encA a|.

        theorem Cslib.Complexity.DisjointBatchReduction.exists_computableInO_foldl {α β γ δ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : DisjointBatchReduction encA encB μA μB) {init : α → δ} (hinit : Turing.MultiTapeTM.ComputableInPolyTime init encA encD) {combine : δ → γ → δ} (hcombine : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : δ × γ) => combine p.1 p.2) (Turing.MultiTapeTM.encPair encD encG) encD) {g : β → γ} {Tg Sg : β → ℕ} (hg : Turing.MultiTapeTM.ComputableInO g encB encG Tg Sg) (hSg : Turing.MultiTapeTM.PolyBounded (fun (b : β) => (encB b).length) Sg) {accBound : α → ℕ} (haccPoly : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) accBound) (hacc : ∀ (a : α), ∀ i ≤ (r.toBatch a).items.length, (encD (List.foldl (fun (s : δ) (b : β) => combine s (g b)) (init a) (List.take i (r.toBatch a).items))).length ≤ accBound a) :
        ∃ (c : ℕ) (e : ℕ) (S : α → ℕ), Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) S ∧ Turing.MultiTapeTM.ComputableInO (fun (a : α) => List.foldl (fun (s : δ) (b : β) => combine s (g b)) (init a) (r.toBatch a).items) encA encD (fun (a : α) => c * ((encA a).length + 1) ^ e + ((r.toBatch a).length + 1) * (c * ((encA a).length + 1) ^ e + Turing.MultiTapeTM.listMax Tg (r.toBatch a).items)) S

        Sequential left-fold resource transfer with bounded live workspace. Evaluating g : β → γ sequentially across (r.toBatch a).items and folding answers via a polynomial-time combine : δ → γ → δ whose prefix accumulators stay polynomially bounded in bit length runs in polynomial live workspace whenever g has polynomial workspace Sg, and within accumulated time O(poly(|a|) + ((r.toBatch a).length + 1) * (poly(|a|) + listMax Tg ...)).

        theorem Cslib.Complexity.DisjointBatchReduction.decidableInExpTime_or {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : DisjointBatchReduction encA encB μA μB) {A : Set α} {B : Set β} (hAB : ∀ (a : α), a ∈ A ↔ ∃ b ∈ (r.toBatch a).items, b ∈ B) {δ : ℝ} (hδ : 0 ≤ δ) (hB : DecidableInExpTime B encB μB δ) :
        DecidableInExpTime A encA μA (↑r.scale * δ)

        Exponential-time OR transfer over a summed-measure disjoint-instance batch. If a ∈ A ↔ ∃ b ∈ (r.toBatch a).items, b ∈ B, then a decider for B within time 2 ^ (δ * μB b) * poly(|b|) transfers to a decider for A within time 2 ^ (r.scale * δ * μA a) * poly(|a|).

        theorem Cslib.Complexity.DisjointBatchReduction.decidableInSubexpTime_or {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : DisjointBatchReduction encA encB μA μB) {A : Set α} {B : Set β} (hAB : ∀ (a : α), a ∈ A ↔ ∃ b ∈ (r.toBatch a).items, b ∈ B) (hB : DecidableInSubexpTime B encB μB) :

        Subexponential-time OR transfer over a summed-measure disjoint-instance batch.

        theorem Cslib.Complexity.DisjointBatchReduction.exists_computableInO_cappedSum {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {μA : α → ℕ} {μB : β → ℕ} (r : DisjointBatchReduction encA encB μA μB) {countA : α → ℕ} {countB : β → ℕ} {capBits : α → ℕ} (hcap : Turing.MultiTapeTM.ComputableInPolyTime capBits encA Turing.MultiTapeTM.encUnary) (hsum : ∀ (a : α), countA a = (List.map countB (r.toBatch a).items).sum) (hle : ∀ (a : α), countA a ≤ 2 ^ capBits a) {Tg Sg : β → ℕ} (hg : Turing.MultiTapeTM.ComputableInO countB encB Turing.MultiTapeTM.encNat Tg Sg) (hSg : Turing.MultiTapeTM.PolyBounded (fun (b : β) => (encB b).length) Sg) {δ : ℝ} (hδ : 0 ≤ δ) {k e : ℕ} (hTg : ∀ (b : β), ↑(Tg b) ≤ ↑k * (2 ^ (δ * ↑(μB b)) * (↑(encB b).length + 1) ^ e) + ↑k) :
        ∃ (T : α → ℕ) (S : α → ℕ) (C₀ : ℕ) (E : ℕ), Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) S ∧ Turing.MultiTapeTM.ComputableInO countA encA Turing.MultiTapeTM.encNat T S ∧ Turing.MultiTapeTM.ComputableInPolySpace countA encA Turing.MultiTapeTM.encNat ∧ ∀ (a : α), ↑(T a) ≤ ↑C₀ * (2 ^ (↑r.scale * δ * ↑(μA a)) * (↑(encA a).length + 1) ^ E) + ↑C₀

        Capped summed-counting transfer with polynomial live workspace. When countA a = ((r.toBatch a).items.map countB).sum ≤ 2 ^ capBits a with capBits computable in polynomial time in unary, and countB has ComputableInO countB encB encNat Tg Sg with PolyBounded length Sg and Tg b ≤ k * (2 ^ (δ * μB b) * (|b| + 1) ^ e) + k, countA is computable in time O(2 ^ (r.scale * δ * μA a) * (|a| + 1) ^ E) AND polynomial live workspace (ComputableInPolySpace countA encA encNat).

        Depth-first stack accumulation over exponentially many disjoint subinstances #

        State of a depth-first stack accumulation: immutable runtime context ctx, live node stack stack, and running answer accumulator acc.

        • ctx : κ

          Captured runtime context.

        • stack : List σ

          Pending search nodes (top of stack is head).

        • acc : δ

          Running answer accumulator.

        Instances For
          theorem Cslib.Complexity.StackSearchState.ext {κ σ δ : Type} {x y : StackSearchState κ σ δ} (ctx : x.ctx = y.ctx) (stack : x.stack = y.stack) (acc : x.acc = y.acc) :
          x = y
          theorem Cslib.Complexity.StackSearchState.ext_iff {κ σ δ : Type} {x y : StackSearchState κ σ δ} :
          x = y ↔ x.ctx = y.ctx ∧ x.stack = y.stack ∧ x.acc = y.acc
          @[instance_reducible]
          instance Cslib.Complexity.instDecidableEqStackSearchState {κ✝ σ✝ δ✝ : Type} [DecidableEq κ✝] [DecidableEq σ✝] [DecidableEq δ✝] :
          DecidableEq (StackSearchState κ✝ σ✝ δ✝)
          def Cslib.Complexity.instDecidableEqStackSearchState.decEq {κ✝ σ✝ δ✝ : Type} [DecidableEq κ✝] [DecidableEq σ✝] [DecidableEq δ✝] (x✝ x✝¹ : StackSearchState κ✝ σ✝ δ✝) :
          Decidable (x✝ = x✝¹)
          def Cslib.Complexity.instReprStackSearchState.repr {κ✝ σ✝ δ✝ : Type} [Repr κ✝] [Repr σ✝] [Repr δ✝] :
          StackSearchState κ✝ σ✝ δ✝ → ℕ → Std.Format
          @[instance_reducible]
          instance Cslib.Complexity.instReprStackSearchState {κ✝ σ✝ δ✝ : Type} [Repr κ✝] [Repr σ✝] [Repr δ✝] :
          Repr (StackSearchState κ✝ σ✝ δ✝)

          Node-inspection input pairing the runtime context with the current top-of-stack node.

          • ctx : κ

            Captured runtime context.

          • node : σ

            Current node inspected at the top of the stack.

          Instances For
            theorem Cslib.Complexity.StackNodeInput.ext {κ σ : Type} {x y : StackNodeInput κ σ} (ctx : x.ctx = y.ctx) (node : x.node = y.node) :
            x = y
            @[instance_reducible]
            def Cslib.Complexity.instDecidableEqStackNodeInput.decEq {κ✝ σ✝ : Type} [DecidableEq κ✝] [DecidableEq σ✝] (x✝ x✝¹ : StackNodeInput κ✝ σ✝) :
            Decidable (x✝ = x✝¹)
            def Cslib.Complexity.instReprStackNodeInput.repr {κ✝ σ✝ : Type} [Repr κ✝] [Repr σ✝] :
            StackNodeInput κ✝ σ✝ → ℕ → Std.Format
            @[instance_reducible]
            instance Cslib.Complexity.instReprStackNodeInput {κ✝ σ✝ : Type} [Repr κ✝] [Repr σ✝] :
            Repr (StackNodeInput κ✝ σ✝)

            Leaf-update input pairing the runtime context, current accumulator, and leaf solver answer.

            • ctx : κ

              Captured runtime context.

            • acc : δ

              Current running accumulator.

            • leafVal : γ

              Leaf solver output on the popped leaf subinstance.

            Instances For
              theorem Cslib.Complexity.StackCombineInput.ext {κ δ γ : Type} {x y : StackCombineInput κ δ γ} (ctx : x.ctx = y.ctx) (acc : x.acc = y.acc) (leafVal : x.leafVal = y.leafVal) :
              x = y
              @[instance_reducible]
              instance Cslib.Complexity.instDecidableEqStackCombineInput {κ✝ δ✝ γ✝ : Type} [DecidableEq κ✝] [DecidableEq δ✝] [DecidableEq γ✝] :
              DecidableEq (StackCombineInput κ✝ δ✝ γ✝)
              def Cslib.Complexity.instDecidableEqStackCombineInput.decEq {κ✝ δ✝ γ✝ : Type} [DecidableEq κ✝] [DecidableEq δ✝] [DecidableEq γ✝] (x✝ x✝¹ : StackCombineInput κ✝ δ✝ γ✝) :
              Decidable (x✝ = x✝¹)
              def Cslib.Complexity.instReprStackCombineInput.repr {κ✝ δ✝ γ✝ : Type} [Repr κ✝] [Repr δ✝] [Repr γ✝] :
              StackCombineInput κ✝ δ✝ γ✝ → ℕ → Std.Format
              @[instance_reducible]
              instance Cslib.Complexity.instReprStackCombineInput {κ✝ δ✝ γ✝ : Type} [Repr κ✝] [Repr δ✝] [Repr γ✝] :
              Repr (StackCombineInput κ✝ δ✝ γ✝)
              def Cslib.Complexity.encStackSearchState {κ σ δ : Type} (encK : κ ↪ List Bool) (encS : σ ↪ List Bool) (encD : δ ↪ List Bool) :

              Framed encoding of StackSearchState κ σ δ.

              @[simp]

              Framed encoding of StackNodeInput κ σ.

              @[simp]
              theorem Cslib.Complexity.encStackNodeInput_apply {κ σ : Type} (encK : κ ↪ List Bool) (encS : σ ↪ List Bool) (s : StackNodeInput κ σ) :
              def Cslib.Complexity.encStackCombineInput {κ δ γ : Type} (encK : κ ↪ List Bool) (encD : δ ↪ List Bool) (encG : γ ↪ List Bool) :

              Framed encoding of StackCombineInput κ δ γ.

              theorem Cslib.Complexity.computableInPolyTime_stackSearchState_ctx {α κ σ δ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encD : δ ↪ List Bool} {f : α → StackSearchState κ σ δ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackSearchState encK encS encD)) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => (f a).ctx) encIn encK
              theorem Cslib.Complexity.computableInPolyTime_stackSearchState_stack {α κ σ δ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encD : δ ↪ List Bool} {f : α → StackSearchState κ σ δ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackSearchState encK encS encD)) :
              theorem Cslib.Complexity.computableInPolyTime_stackSearchState_acc {α κ σ δ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encD : δ ↪ List Bool} {f : α → StackSearchState κ σ δ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackSearchState encK encS encD)) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => (f a).acc) encIn encD
              theorem Cslib.Complexity.computableInPolyTime_stackSearchState_mk {α κ σ δ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encD : δ ↪ List Bool} {c : α → κ} {stk : α → List σ} {ac : α → δ} (hc : Turing.MultiTapeTM.ComputableInPolyTime c encIn encK) (hstk : Turing.MultiTapeTM.ComputableInPolyTime stk encIn (Turing.MultiTapeTM.encList encS)) (hac : Turing.MultiTapeTM.ComputableInPolyTime ac encIn encD) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => { ctx := c a, stack := stk a, acc := ac a }) encIn (encStackSearchState encK encS encD)
              theorem Cslib.Complexity.computableInPolyTime_stackNodeInput_ctx {α κ σ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {f : α → StackNodeInput κ σ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackNodeInput encK encS)) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => (f a).ctx) encIn encK
              theorem Cslib.Complexity.computableInPolyTime_stackNodeInput_node {α κ σ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {f : α → StackNodeInput κ σ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackNodeInput encK encS)) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => (f a).node) encIn encS
              theorem Cslib.Complexity.computableInPolyTime_stackNodeInput_mk {α κ σ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {c : α → κ} {nd : α → σ} (hc : Turing.MultiTapeTM.ComputableInPolyTime c encIn encK) (hnd : Turing.MultiTapeTM.ComputableInPolyTime nd encIn encS) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => { ctx := c a, node := nd a }) encIn (encStackNodeInput encK encS)
              theorem Cslib.Complexity.computableInPolyTime_stackCombineInput_ctx {α κ δ γ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encD : δ ↪ List Bool} {encG : γ ↪ List Bool} {f : α → StackCombineInput κ δ γ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackCombineInput encK encD encG)) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => (f a).ctx) encIn encK
              theorem Cslib.Complexity.computableInPolyTime_stackCombineInput_acc {α κ δ γ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encD : δ ↪ List Bool} {encG : γ ↪ List Bool} {f : α → StackCombineInput κ δ γ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackCombineInput encK encD encG)) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => (f a).acc) encIn encD
              theorem Cslib.Complexity.computableInPolyTime_stackCombineInput_leafVal {α κ δ γ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encD : δ ↪ List Bool} {encG : γ ↪ List Bool} {f : α → StackCombineInput κ δ γ} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encIn (encStackCombineInput encK encD encG)) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => (f a).leafVal) encIn encG
              theorem Cslib.Complexity.computableInPolyTime_stackCombineInput_mk {α κ δ γ : Type} {encIn : α ↪ List Bool} {encK : κ ↪ List Bool} {encD : δ ↪ List Bool} {encG : γ ↪ List Bool} {c : α → κ} {ac : α → δ} {lv : α → γ} (hc : Turing.MultiTapeTM.ComputableInPolyTime c encIn encK) (hac : Turing.MultiTapeTM.ComputableInPolyTime ac encIn encD) (hlv : Turing.MultiTapeTM.ComputableInPolyTime lv encIn encG) :
              Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => { ctx := c a, acc := ac a, leafVal := lv a }) encIn (encStackCombineInput encK encD encG)
              structure Cslib.Complexity.StackAccumulationSpec {α κ σ β γ δ : Type} (encA : α ↪ List Bool) (encK : κ ↪ List Bool) (encS : σ ↪ List Bool) (encB : β ↪ List Bool) (encG : γ ↪ List Bool) (encD : δ ↪ List Bool) :

              Depth-first stack accumulation specification. Packages a polynomial-time stack generator and accumulator over nodes σ producing leaf subinstances β whose solver outputs γ are folded into δ over rounds a binary-counted iterations without materializing the exponentially long leaf list.

              def Cslib.Complexity.StackAccumulationSpec.initState {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (a : α) :

              Initial StackSearchState on input a.

              def Cslib.Complexity.StackAccumulationSpec.topNode {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (st : StackSearchState κ σ δ) :

              Current (ctx, head) node pair on top of st.stack.

              def Cslib.Complexity.StackAccumulationSpec.isActiveLeaf {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (st : StackSearchState κ σ δ) :

              Whether st is at an active leaf step (st.stack is nonempty and its head is a leaf).

              def Cslib.Complexity.StackAccumulationSpec.step {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (g : β → γ) (st : StackSearchState κ σ δ) :

              One step of depth-first stack accumulation with leaf solver g : β → γ.

              def Cslib.Complexity.StackAccumulationSpec.run {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (g : β → γ) (a : α) :
              δ

              Execute S.rounds a depth-first steps and return the final accumulator.

              @[simp]
              theorem Cslib.Complexity.StackAccumulationSpec.step_empty {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (g : β → γ) (c : κ) (ac : δ) :
              S.step g { ctx := c, stack := [], acc := ac } = { ctx := c, stack := [], acc := ac }
              theorem Cslib.Complexity.StackAccumulationSpec.iterate_step_empty {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (g : β → γ) (c : κ) (ac : δ) (n : ℕ) :
              (S.step g)^[n] { ctx := c, stack := [], acc := ac } = { ctx := c, stack := [], acc := ac }
              theorem Cslib.Complexity.StackAccumulationSpec.iterate_step_ctx {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (g : β → γ) (st : StackSearchState κ σ δ) (n : ℕ) :
              ((S.step g)^[n] st).ctx = st.ctx
              theorem Cslib.Complexity.StackAccumulationSpec.exists_computableInO_step {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) {g : β → γ} {Tg Sg : β → ℕ} (hg : Turing.MultiTapeTM.ComputableInO g encB encG Tg Sg) :
              ∃ (d : ℕ), Turing.MultiTapeTM.ComputableInO (S.step g) (encStackSearchState encK encS encD) (encStackSearchState encK encS encD) (fun (st : StackSearchState κ σ δ) => (((encStackSearchState encK encS encD) st).length + 1) ^ d + if st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true then Tg (S.leafInstance (S.topNode st)) + (((encStackSearchState encK encS encD) st).length + (encG (g (S.leafInstance (S.topNode st)))).length + 1) ^ d else 0) fun (st : StackSearchState κ σ δ) => (((encStackSearchState encK encS encD) st).length + 1) ^ d + if st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true then Sg (S.leafInstance (S.topNode st)) + (((encStackSearchState encK encS encD) st).length + (encG (g (S.leafInstance (S.topNode st)))).length + 1) ^ d else 0

              Single-step independent time and space bound via exists_computableInO_searchStep.

              theorem Cslib.Complexity.StackAccumulationSpec.exists_computableInO_run {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) {g : β → γ} {Tg Sg : β → ℕ} (hg : Turing.MultiTapeTM.ComputableInO g encB encG Tg Sg) (hSg : Turing.MultiTapeTM.PolyBounded (fun (b : β) => (encB b).length) Sg) {stateBound ansBound leafMax : α → ℕ} (hstatePoly : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) stateBound) (hansPoly : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) ansBound) (hstate : ∀ (a : α), ∀ i ≤ S.rounds a, ((encStackSearchState encK encS encD) ((S.step g)^[i] (S.initState a))).length ≤ stateBound a) (hans : ∀ (a : α), ∀ i ≤ S.rounds a, have st := (S.step g)^[i] (S.initState a); st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true → (encG (g (S.leafInstance (S.topNode st)))).length ≤ ansBound a) (htime : ∀ (a : α), ∀ i ≤ S.rounds a, have st := (S.step g)^[i] (S.initState a); st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true → Tg (S.leafInstance (S.topNode st)) ≤ leafMax a) :
              ∃ (c : ℕ) (e : ℕ) (Space : α → ℕ), Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) Space ∧ Turing.MultiTapeTM.ComputableInO (S.run g) encA encD (fun (a : α) => c * ((encA a).length + 1) ^ e + (S.rounds a + 1) * (c * ((encA a).length + 1) ^ e + leafMax a)) Space ∧ Turing.MultiTapeTM.ComputableInPolySpace (S.run g) encA encD

              Accumulated-time and polynomial-live-workspace transfer for S.run g. When the live encoded search state and leaf answers are polynomially bounded along S.rounds a and g has polynomial workspace Sg, S.run g runs in polynomial live workspace (ComputableInPolySpace (S.run g) encA encD) and within accumulated time O(poly(|a|) + (S.rounds a + 1) * (poly(|a|) + leafMax a)), without materializing the leaf list.

              theorem Cslib.Complexity.StackAccumulationSpec.decidableInExpTime_of_stack {α κ σ β : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB Turing.MultiTapeTM.encBool Turing.MultiTapeTM.encBool) {A : Set α} {B : Set β} {μA : α → ℕ} {μB : β → ℕ} {ν : α → ℕ} {K₀ M K₁ scale offset : ℕ} (hrounds : ∀ (a : α), S.rounds a ≤ K₀ * 2 ^ ν a) (hν : ∀ (a : α), ν a ≤ μA a / M + K₁) {stateBound : α → ℕ} (hstatePoly : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) stateBound) (hAB : ∀ (g : β → Bool), (∀ (b : β), b ∈ B ↔ g b = true) → ∀ (a : α), (a ∈ A ↔ S.run g a = true) ∧ (∀ i ≤ S.rounds a, ((encStackSearchState encK encS Turing.MultiTapeTM.encBool) ((S.step g)^[i] (S.initState a))).length ≤ stateBound a) ∧ ∀ i ≤ S.rounds a, have st := (S.step g)^[i] (S.initState a); st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true → μB (S.leafInstance (S.topNode st)) ≤ scale * μA a + offset) {δ : ℝ} (hδ : 0 ≤ δ) (hB : DecidableInExpTime B encB μB δ) :
              DecidableInExpTime A encA μA (1 / ↑M + ↑scale * δ)

              Exponential-time decision transfer along a Boolean-OR StackAccumulationSpec. When S.rounds a ≤ K₀ * 2 ^ (ν a) with ν a ≤ μA a / M + K₁ and every active leaf subinstance satisfies μB b ≤ scale * μA a + offset, a decider for B within time 2 ^ (δ * μB b) * poly(|b|) transfers to A within time 2 ^ ((1 / M + scale * δ) * μA a) * poly(|a|).

              theorem Cslib.Complexity.StackAccumulationSpec.decidableInSubexpTime_of_stack {α κ σ β : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} {μA : α → ℕ} {μB : β → ℕ} {scale : ℕ} (hfamily : ∀ M > 0, ∃ (S : StackAccumulationSpec encA encK encS encB Turing.MultiTapeTM.encBool Turing.MultiTapeTM.encBool) (ν : α → ℕ) (stateBound : α → ℕ) (K₀ : ℕ) (K₁ : ℕ) (offset : ℕ), (∀ (a : α), S.rounds a ≤ K₀ * 2 ^ ν a) ∧ (∀ (a : α), ν a ≤ μA a / M + K₁) ∧ Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) stateBound ∧ ∀ (g : β → Bool), (∀ (b : β), b ∈ B ↔ g b = true) → ∀ (a : α), (a ∈ A ↔ S.run g a = true) ∧ (∀ i ≤ S.rounds a, ((encStackSearchState encK encS Turing.MultiTapeTM.encBool) ((S.step g)^[i] (S.initState a))).length ≤ stateBound a) ∧ ∀ i ≤ S.rounds a, have st := (S.step g)^[i] (S.initState a); st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true → μB (S.leafInstance (S.topNode st)) ≤ scale * μA a + offset) (hB : DecidableInSubexpTime B encB μB) :

              Subexponential-time decision transfer along a family of Boolean-OR stack reductions.

              theorem Cslib.Complexity.StackAccumulationSpec.exists_computableInO_cappedSum_of_stack {α κ σ β : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB Turing.MultiTapeTM.encNat encCappedNatAcc) {countA : α → ℕ} {countB : β → ℕ} {μA : α → ℕ} {μB : β → ℕ} {ν stateBound ansBound : α → ℕ} {K₀ M K₁ scale offset : ℕ} (hrounds : ∀ (a : α), S.rounds a ≤ K₀ * 2 ^ ν a) (hν : ∀ (a : α), ν a ≤ μA a / M + K₁) (hstatePoly : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) stateBound) (hansPoly : Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) ansBound) (hcorrect : ∀ (a : α), (S.run countB a).total = countA a) (hstate : ∀ (a : α), ∀ i ≤ S.rounds a, ((encStackSearchState encK encS encCappedNatAcc) ((S.step countB)^[i] (S.initState a))).length ≤ stateBound a) (hans : ∀ (a : α), ∀ i ≤ S.rounds a, have st := (S.step countB)^[i] (S.initState a); st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true → (Turing.MultiTapeTM.encNat (countB (S.leafInstance (S.topNode st)))).length ≤ ansBound a) (hmeas : ∀ (a : α), ∀ i ≤ S.rounds a, have st := (S.step countB)^[i] (S.initState a); st.stack.isEmpty = false ∧ S.isLeaf (S.topNode st) = true → μB (S.leafInstance (S.topNode st)) ≤ scale * μA a + offset) {Tg Sg : β → ℕ} (hg : Turing.MultiTapeTM.ComputableInO countB encB Turing.MultiTapeTM.encNat Tg Sg) (hSg : Turing.MultiTapeTM.PolyBounded (fun (b : β) => (encB b).length) Sg) {δ : ℝ} (hδ : 0 ≤ δ) {k e : ℕ} (hTg : ∀ (b : β), ↑(Tg b) ≤ ↑k * (2 ^ (δ * ↑(μB b)) * (↑(encB b).length + 1) ^ e) + ↑k) :
              ∃ (T : α → ℕ) (Space : α → ℕ) (C₀ : ℕ) (E : ℕ), Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) Space ∧ Turing.MultiTapeTM.ComputableInO countA encA Turing.MultiTapeTM.encNat T Space ∧ Turing.MultiTapeTM.ComputableInPolySpace countA encA Turing.MultiTapeTM.encNat ∧ ∀ (a : α), ↑(T a) ≤ ↑C₀ * (2 ^ ((1 / ↑M + ↑scale * δ) * ↑(μA a)) * (↑(encA a).length + 1) ^ E) + ↑C₀

              Capped summed-counting transfer along StackAccumulationSpec with polynomial live workspace. Given a CappedNatAcc-accumulating stack specification S whose final (S.run countB a).total equals countA a, with S.rounds a ≤ K₀ * 2 ^ (ν a), ν a ≤ μA a / M + K₁, leaf measure μB b ≤ scale * μA a + offset, and leaf counter ComputableInO countB encB encNat Tg Sg with PolyBounded length Sg, countA is computable in polynomial live workspace AND time O(2 ^ ((1 / M + scale * δ) * μA a) * (|a| + 1) ^ E).

              Bridge to BinaryBranching and disjoint sparsification #

              theorem Cslib.Complexity.StackAccumulationSpec.iterate_step_eq_binaryBranching {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (g : β → γ) (c : κ) (T : BinaryBranching σ) (hleaf : ∀ (s : σ), S.isLeaf { ctx := c, node := s } = true ↔ T.IsLeaf s) (hexp : ∀ (s : σ), ¬T.IsLeaf s → S.expand { ctx := c, node := s } = [T.next s false, T.next s true]) (n : ℕ) (stk : List σ) (ac : δ) :
              (S.step g)^[n] { ctx := c, stack := stk, acc := ac } = have p := (T.searchStep fun (d : δ) (s : σ) => S.combine { ctx := c, acc := d, leafVal := g (S.leafInstance { ctx := c, node := s }) })^[n] (stk, ac); { ctx := c, stack := p.1, acc := p.2 }

              When S expands inner states to the two children [T.next s false, T.next s true] of a BinaryBranching rule T, iterating S.step g agrees at every step with T.searchStep.

              theorem Cslib.Complexity.StackAccumulationSpec.run_eq_foldl_leafWords {α κ σ β γ δ : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} {encG : γ ↪ List Bool} {encD : δ ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB encG encD) (g : β → γ) (a : α) (T : BinaryBranching σ) (hT : T.Terminating) {root : σ} (hinit : S.initStack a = [root]) (hleaf : ∀ (s : σ), S.isLeaf { ctx := S.initCtx a, node := s } = true ↔ T.IsLeaf s) (hexp : ∀ (s : σ), ¬T.IsLeaf s → S.expand { ctx := S.initCtx a, node := s } = [T.next s false, T.next s true]) {h : ℕ} (hh : ∀ (w : List Bool), T.IsLeafWord root w → w.length ≤ h) (hrounds : ∀ (L : List (List Bool)), L.Nodup → (∀ (w : List Bool), w ∈ L ↔ T.IsLeafWord root w) → 2 * L.length ≤ S.rounds a + 1) :
              ∃ (L : List (List Bool)), L.Nodup ∧ (∀ (w : List Bool), w ∈ L ↔ T.IsLeafWord root w) ∧ S.run g a = List.foldl (fun (d : δ) (s : σ) => S.combine { ctx := S.initCtx a, acc := d, leafVal := g (S.leafInstance { ctx := S.initCtx a, node := s }) }) (S.initAcc a) (List.map (T.walk root) L) ∧ ∀ i ≤ S.rounds a, have st := (S.step g)^[i] (S.initState a); st.stack.length ≤ h + 1 ∧ (∀ t ∈ st.stack, ∃ (w : List Bool), T.IsNodeWord root w ∧ w.length ≤ h ∧ T.walk root w = t) ∧ ∃ (L' : List (List Bool)), L' <+: L ∧ st.acc = List.foldl (fun (d : δ) (s : σ) => S.combine { ctx := S.initCtx a, acc := d, leafVal := g (S.leafInstance { ctx := S.initCtx a, node := s }) }) (S.initAcc a) (List.map (T.walk root) L')

              Leaf-word fold theorem (BinaryBranching / sparsification bridge). For a terminating BinaryBranching rule T on input a starting at [root] with leaf depth at most h and 2 * L.length ≤ S.rounds a on the duplicate-free list L of leaf words, S.run g a equals the fold over all leaf states L.map (T.walk root) while every intermediate stack has length at most h + 1 and holds only tree nodes of depth at most h.

              theorem Cslib.Complexity.StackAccumulationSpec.run_cappedSum_eq_root {α κ σ β : Type} {encA : α ↪ List Bool} {encK : κ ↪ List Bool} {encS : σ ↪ List Bool} {encB : β ↪ List Bool} (S : StackAccumulationSpec encA encK encS encB Turing.MultiTapeTM.encNat encCappedNatAcc) (g : β → ℕ) (a : α) (T : BinaryBranching σ) (hT : T.Terminating) {root : σ} {cap : ℕ} (hinit : S.initStack a = [root]) (hinitAcc : S.initAcc a = CappedNatAcc.init cap) (hcombine : ∀ (d : CappedNatAcc) (v : ℕ), S.combine { ctx := S.initCtx a, acc := d, leafVal := v } = d.add v) (hleaf : ∀ (s : σ), S.isLeaf { ctx := S.initCtx a, node := s } = true ↔ T.IsLeaf s) (hexp : ∀ (s : σ), ¬T.IsLeaf s → S.expand { ctx := S.initCtx a, node := s } = [T.next s false, T.next s true]) {h : ℕ} (hh : ∀ (w : List Bool), T.IsLeafWord root w → w.length ≤ h) (hrounds : ∀ (L : List (List Bool)), L.Nodup → (∀ (w : List Bool), w ∈ L ↔ T.IsLeafWord root w) → 2 * L.length ≤ S.rounds a + 1) {val : σ → ℕ} (hadd : ∀ (t : σ), ¬T.IsLeaf t → val t = val (T.next t false) + val (T.next t true)) (hval_leaf : ∀ (t : σ), T.IsLeaf t → g (S.leafInstance { ctx := S.initCtx a, node := t }) = val t) (hcap : val root ≤ cap) :
              (S.run g a).total = val root

              Exact additive root recovery for capped disjoint-branching sums. When val : σ → ℕ is additive across the children of every inner state (val t = val (next false) + val (next true)), g computes val on leaves, and val root ≤ cap, a CappedNatAcc stack traversal recovers val root exactly.