Documentation

CslibFrontier.Computability.Complexity.Reduction.BoundedOracle

Oracle reductions with explicit query and answer lengths #

Cslib.Complexity.PolyTimeTuringReducible (CslibFrontier/Computability/Complexity/Reduction/Turing.lean) and Cslib.Complexity.ComputableInPolyTimeWithOracle (CslibFrontier/Computability/Complexity/Classes/Oracle.lean) quantify over adaptive deterministic WordQueryComp programs certified by IsOraclePPTOn against one-bit language oracles. Fine-grained and exact exponential complexity require explicit quantitative accounting of the oracle interaction across both decision and multi-bit function oracles:

In addition to identity, zero-query polynomial-time lifts, single-query many-one/function lifts, and bridges to PolyTimeTuringReducible and PWithOracleQueries, this module extends Turing.MultiTapePTM simulation from one-bit receiveBit to arbitrary word replies receiveWord, proving:

  1. Composition (BoundedOracleProgram.comp, BoundedOracleReduction.trans): explicit worst-case composition via wordMax and sharper linear totalQlen composition when the inner total query length is affine in the outer query length.
  2. Polynomial-time and polynomial-space multi-bit oracle transfer (BoundedOracleProgram.computableInPolyTime, BoundedOracleProgram.exists_computableInO_polySpace): simulator workspace is bounded in terms of input length, clock, answer-length cap, and simulated oracle workspace — never as a polynomial in simulated oracle running time.
  3. Parameterized exponential and subexponential time transfer (BoundedOracleReduction.decidableInExpTime, BoundedOracleReduction.decidableInSubexpTime): guarding oracle calls by a polynomial-time validity/length predicate that holds along queriesWith transfers 2 ^ (δ * μB) deciders to 2 ^ (scale * δ * μA) with polynomial overhead absorbing query count and construction cost.

Main definitions #

Main results #

References #

Multi-bit oracle simulation on Turing.MultiTapePTM #

def Turing.MultiTapePTM.receiveWord {k : ℕ} {Control Operation : Type} [DecidableEq Operation] (machine : MultiTapePTM k Bool Control Operation) (p : MultiTapeMachine.FiniteConfig k Bool Control Operation × List Bool) :

Install a multi-bit word reply to the pending query on p.1; leave p.1 unchanged when no query is pending.

theorem Turing.MultiTapePTM.answerStep_word {k : ℕ} {Control Operation : Type} [DecidableEq Operation] (machine : MultiTapePTM k Bool Control Operation) (oracle : List Bool → List Bool) (cfg : MultiTapeMachine.FiniteConfig k Bool Control Operation) :
machine.answerStep (fun (q : Operation × List Bool) => oracle q.2) cfg = if (machine.pendingQuery cfg).isSome = true then machine.receiveWord (cfg, oracle (machine.pendingRequest cfg)) else machine.localStep cfg

Against any word oracle oracle : List Bool → List Bool, one answerStep either installs oracle (machine.pendingRequest cfg) via receiveWord or executes localStep.

theorem Turing.MultiTapePTM.spaceBound_answerStep_word {k : ℕ} {Control Operation : Type} [DecidableEq Operation] (machine : MultiTapePTM k Bool Control Operation) (oracle : List Bool → List Bool) {inputSize steps answerSize : ℕ} {cfg : MultiTapeMachine.FiniteConfig k Bool Control Operation} (h : MultiTapeMachine.FiniteConfig.SpaceBound inputSize steps answerSize cfg) (hans : ∀ (w : List Bool), w.length ≤ steps → (oracle w).length ≤ answerSize) :
MultiTapeMachine.FiniteConfig.SpaceBound inputSize (steps + 1) answerSize (machine.answerStep (fun (q : Operation × List Bool) => oracle q.2) cfg)

When every reply to a request of length at most steps has length at most answerSize, one answerStep advances FiniteConfig.SpaceBound from steps to steps + 1 with the same answerSize.

theorem Turing.MultiTapePTM.answerStep_word_inO {k : ℕ} {Control Operation : Type} [DecidableEq Operation] (machine : MultiTapePTM k Bool Control Operation) [Finite Control] [Fintype Operation] {oracle : List Bool → List Bool} {Tg Sg : List Bool → ℕ} (horacle : MultiTapeTM.ComputableInO oracle MultiTapeTM.encBits MultiTapeTM.encBits Tg Sg) :
∃ (d : ℕ), MultiTapeTM.ComputableInO (machine.answerStep fun (q : Operation × List Bool) => oracle q.2) MultiTapeTM.encFiniteConfig MultiTapeTM.encFiniteConfig (fun (cfg : MultiTapeMachine.FiniteConfig k Bool Control Operation) => ((MultiTapeTM.encFiniteConfig cfg).length + 1) ^ d + if (machine.pendingQuery cfg).isSome = true then Tg (machine.pendingRequest cfg) + ((MultiTapeTM.encFiniteConfig cfg).length + (oracle (machine.pendingRequest cfg)).length + 1) ^ d else 0) fun (cfg : MultiTapeMachine.FiniteConfig k Bool Control Operation) => ((MultiTapeTM.encFiniteConfig cfg).length + 1) ^ d + if (machine.pendingQuery cfg).isSome = true then Sg (machine.pendingRequest cfg) + ((MultiTapeTM.encFiniteConfig cfg).length + (oracle (machine.pendingRequest cfg)).length + 1) ^ d else 0

Independent time and space of one multi-bit oracle instruction. Charges Tg and Sg only when (machine.pendingQuery cfg).isSome = true.

theorem Turing.MultiTapePTM.computableInPolyTime_answerStep_word {k : ℕ} {Control Operation : Type} [DecidableEq Operation] (machine : MultiTapePTM k Bool Control Operation) [Finite Control] [Fintype Operation] {oracle : List Bool → List Bool} (horacle : MultiTapeTM.ComputableInPolyTime oracle MultiTapeTM.encBits MultiTapeTM.encBits) :
theorem Turing.MultiTapePTM.computableInPolyTime_run_word {k : ℕ} {Control Operation : Type} [DecidableEq Operation] (machine : MultiTapePTM k Bool Control Operation) [Finite Control] [Finite Operation] {α : Type} {input : α ↪ List Bool} {oracle : List Bool → List Bool} (horacle : MultiTapeTM.ComputableInPolyTime oracle MultiTapeTM.encBits MultiTapeTM.encBits) (c d : ℕ) :
MultiTapeTM.ComputableInPolyTime (fun (a : α) => Cslib.OracleComp.interpret (fun (q : Operation × List Bool) => oracle q.2) (machine.run (pure false) (fun (op : Operation) (word : List Bool) => Cslib.OracleComp.query (op, word)) (c * ((input a).length + 1) ^ d) (input a))) input MultiTapeTM.encBits

A clocked multi-bit oracle run against a polynomial-time word oracle is polynomial-time.

theorem Turing.MultiTapePTM.exists_computableInO_run_word {k : ℕ} {Control Operation : Type} [DecidableEq Operation] (machine : MultiTapePTM k Bool Control Operation) [Finite Control] [Finite Operation] {α : Type} {input : α ↪ List Bool} {oracle : List Bool → List Bool} {Tg Sg : List Bool → ℕ} (horacle : MultiTapeTM.ComputableInO oracle MultiTapeTM.encBits MultiTapeTM.encBits Tg Sg) (hSg : MultiTapeTM.PolyBounded List.length Sg) (c d : ℕ) :
∃ (c₀ : ℕ) (e₀ : ℕ) (S : α → ℕ), MultiTapeTM.PolyBounded (fun (a : α) => (input a).length) S ∧ MultiTapeTM.ComputableInO (fun (a : α) => Cslib.OracleComp.interpret (fun (q : Operation × List Bool) => oracle q.2) (machine.run (pure false) (fun (op : Operation) (word : List Bool) => Cslib.OracleComp.query (op, word)) (c * ((input a).length + 1) ^ d) (input a))) input MultiTapeTM.encBits (fun (a : α) => c₀ * ((input a).length + 1) ^ e₀ + (c * ((input a).length + 1) ^ d + 1) * (c₀ * ((input a).length + 1) ^ e₀ + MultiTapeTM.wordMax Tg (c * ((input a).length + 1) ^ d))) S

A clocked multi-bit oracle run against a polynomial-space word oracle runs in polynomial workspace, with explicit time O(poly(|a|) + (clock a + 1) * (poly(|a|) + wordMax Tg (clock a))) charging Tg only up to the clock and bounding space solely by input, simulated space, and counters (never by simulated time Tg).

OracleCallBound, BoundedOracleProgram, and BoundedOracleReduction #

Explicit quantitative profile of an oracle call budget on a single input: qcount queries, each of bit-length at most qlen, with total bit-length at most totalQlen, and each answer of bit-length at most alen.

  • qcount : ℕ

    Maximum number of oracle queries issued along the run.

  • qlen : ℕ

    Maximum bit-length of any single query word issued along the run.

  • totalQlen : ℕ

    Maximum sum of bit-lengths of all query words issued along the run.

  • alen : ℕ

    Maximum bit-length of any oracle answer read along the run.

Instances For
    theorem Cslib.Complexity.OracleCallBound.ext {x y : OracleCallBound} (qcount : x.qcount = y.qcount) (qlen : x.qlen = y.qlen) (totalQlen : x.totalQlen = y.totalQlen) (alen : x.alen = y.alen) :
    x = y
    @[reducible, inline]

    The tuple of the fields of encOracleCallBound.

    theorem Cslib.Complexity.encOracleCallBound_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget x0 x1 x2 x3 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encNat budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) (h2 : Turing.MultiTapeTM.ComputableInSpace x2 encIn Turing.MultiTapeTM.encNat budget) (h3 : Turing.MultiTapeTM.ComputableInSpace x3 encIn Turing.MultiTapeTM.encNat budget) :
    Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { qcount := x0 x, qlen := x1 x, totalQlen := x2 x, alen := x3 x }) encIn encOracleCallBound budget
    theorem Cslib.Complexity.encOracleCallBound_qcount_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → OracleCallBound} :
    theorem Cslib.Complexity.encOracleCallBound_alen_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → OracleCallBound} :
    theorem Cslib.Complexity.encOracleCallBound_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 T0 S0 x1 T1 S1 x2 T2 S2 x3 T3 S3 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encNat T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn Turing.MultiTapeTM.encNat T2 S2) (h3 : Turing.MultiTapeTM.ComputableInO x3 encIn Turing.MultiTapeTM.encNat T3 S3) :
    Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { qcount := x0 x, qlen := x1 x, totalQlen := x2 x, alen := x3 x }) encIn encOracleCallBound (fun (x : γ) => T0 x + (T1 x + (T2 x + T3 x))) fun (x : γ) => S0 x + (S1 x + (S2 x + S3 x))
    theorem Cslib.Complexity.encOracleCallBound_qlen_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → OracleCallBound} :
    theorem Cslib.Complexity.encOracleCallBound_totalQlen_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → OracleCallBound} :
    theorem Cslib.Complexity.encOracleCallBound_mk_deg :
    Turing.MultiTapeTM.ComputableInDegree (fun (p : ℕ × ℕ × ℕ × ℕ) => { qcount := p.1, qlen := p.2.1, totalQlen := p.2.2.1, alen := p.2.2.2 }) encOracleCallBoundFields encOracleCallBound 1 1

    Single-query profile (1, ql, ql, al) for a query of length ≤ ql and reply of length ≤ al.

    Coordinatewise dominance between OracleCallBound profiles.

    prog respects b against the word oracle oracle : List Bool → List Bool: along the deterministic run queriesWith (fun q => oracle q.2) prog, query count is ≤ b.qcount, each query has length ≤ b.qlen, total query length is ≤ b.totalQlen, and each reply has length ≤ b.alen.

    theorem Cslib.Complexity.OracleCallBound.Respects.mono {β : Type} {oracle : List Bool → List Bool} {prog : WordQueryComp Unit β} {b₁ b₂ : OracleCallBound} (h : Respects oracle prog b₁) (hle : b₁.Le b₂) :
    Respects oracle prog b₂
    theorem Cslib.Complexity.OracleCallBound.respects_pure {β : Type} (oracle : List Bool → List Bool) (x : β) (b : OracleCallBound) :
    Respects oracle (pure x) b
    theorem Cslib.Complexity.OracleCallBound.respects_map {β γ : Type} (oracle : List Bool → List Bool) (f : β → γ) (prog : WordQueryComp Unit β) (b : OracleCallBound) :
    Respects oracle (f <$> prog) b ↔ Respects oracle prog b

    Composed call bound when an outer run with bound b₁ answers each query w (|w| ≤ b₁.qlen) using an inner oracle program with profile b₂ w.

    structure Cslib.Complexity.BoundedOracleProgram {α β : Type} (encA : α ↪ List Bool) (encB : β ↪ List Bool) (oracle : List Bool → List Bool) (f : α → β) :

    Deterministic adaptive oracle program with explicit query and answer length bounds. Packages a WordQueryComp program computing f : α → β relative to oracle : List Bool → List Bool, certified by IsOraclePPTOn, together with an explicit OracleCallBound profile bound a and a polynomial-time unary reply-length allowance alenCap a ((bound a).alen ≤ alenCap a) used when composing open oracle handlers.

    def Cslib.Complexity.BoundedOracleProgram.qcount {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} (R : BoundedOracleProgram encA encB oracle f) (a : α) :

    Number of queries budgeted on a.

    def Cslib.Complexity.BoundedOracleProgram.qlen {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} (R : BoundedOracleProgram encA encB oracle f) (a : α) :

    Per-query length budgeted on a.

    def Cslib.Complexity.BoundedOracleProgram.totalQlen {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} (R : BoundedOracleProgram encA encB oracle f) (a : α) :

    Total query length budgeted on a.

    def Cslib.Complexity.BoundedOracleProgram.alen {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} (R : BoundedOracleProgram encA encB oracle f) (a : α) :

    Per-answer length budgeted on a.

    def Cslib.Complexity.BoundedOracleProgram.mono {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} (R : BoundedOracleProgram encA encB oracle f) {bound' : α → OracleCallBound} {alenCap' : α → ℕ} (hbound : ∀ (a : α), (R.bound a).Le (bound' a)) (hcap_pt : Turing.MultiTapeTM.ComputableInPolyTime alenCap' encA Turing.MultiTapeTM.encUnary) (hcap_le : ∀ (a : α), (bound' a).alen ≤ alenCap' a) :
    BoundedOracleProgram encA encB oracle f

    Weaken the OracleCallBound profile of R to any coordinatewise larger bound'.

    def Cslib.Complexity.BoundedOracleProgram.ofPolyTime {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {f : α → β} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encA encB) (oracle : List Bool → List Bool) :
    BoundedOracleProgram encA encB oracle f

    A plain polynomial-time function f : α → β lifts to a 0-query BoundedOracleProgram with OracleCallBound.zero relative to every word oracle.

    def Cslib.Complexity.BoundedOracleProgram.map {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} {g : β → γ} (R : BoundedOracleProgram encA encB oracle f) (hg : Turing.MultiTapeTM.ComputableInPolyTime g encB encC) :
    BoundedOracleProgram encA encC oracle (g ∘ f)

    Polynomial-time postprocessing g : β → γ preserves bound and alenCap.

    def Cslib.Complexity.BoundedOracleProgram.preprocess {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} {p : γ → α} (R : BoundedOracleProgram encA encB oracle f) (hp : Turing.MultiTapeTM.ComputableInPolyTime p encC encA) :
    BoundedOracleProgram encC encB oracle (f ∘ p)

    Polynomial-time preprocessing p : γ → α pulls back bound and alenCap along p.

    def Cslib.Complexity.BoundedOracleProgram.ofSingleQuery {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle : List Bool → List Bool} {req : α → List Bool} {alenCap : α → ℕ} {decode : α × List Bool → β} (hreq : Turing.MultiTapeTM.ComputableInPolyTime req encA Turing.MultiTapeTM.encBits) (halen : Turing.MultiTapeTM.ComputableInPolyTime alenCap encA Turing.MultiTapeTM.encUnary) (hdec : Turing.MultiTapeTM.ComputableInPolyTime decode (Turing.MultiTapeTM.encPair encA Turing.MultiTapeTM.encBits) encB) (hle : ∀ (a : α), (oracle (req a)).length ≤ alenCap a) :
    BoundedOracleProgram encA encB oracle fun (a : α) => decode (a, oracle (req a))

    Single-query oracle call with explicit request generator req : α → List Bool, unary answer-length cap alenCap : α → ℕ, and polynomial-time reply decoder decode : α × List Bool → β. Issues 1 query of length (req a).length and reads at most alenCap a reply bits.

    Identity word-oracle program on List Bool given a polynomial-time unary bound alenCap on (oracle w).length: makes 1 query w of length w.length and returns oracle w.

    noncomputable def Cslib.Complexity.BoundedOracleProgram.compCapPoly {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) :

    Polynomial reply-length allowance for BoundedOracleProgram.comp.

    noncomputable def Cslib.Complexity.BoundedOracleProgram.comp {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) :
    BoundedOracleProgram encA encB oracle₂ f

    Composition of BoundedOraclePrograms with explicit query and answer length accounting. Substitutes R₂ : BoundedOracleProgram encBits encBits oracle₂ oracle₁ for each query of R₁ : BoundedOracleProgram encA encB oracle₁ f, truncating replies to R₁.alenCap a so open machine realization (IsOraclePPTOn.interpret_preprocess_open') holds against every stateful external oracle while OracleCallBound.comp records the composed (qcount, qlen, totalQlen, alen) budget (with alen additionally capped by the polynomial machine reply bound).

    @[simp]
    theorem Cslib.Complexity.BoundedOracleProgram.qcount_comp {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) (a : α) :
    (R₁.comp R₂).qcount a = R₁.qcount a * Turing.MultiTapeTM.wordMax R₂.qcount (R₁.qlen a)
    @[simp]
    theorem Cslib.Complexity.BoundedOracleProgram.qlen_comp {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) (a : α) :
    (R₁.comp R₂).qlen a = Turing.MultiTapeTM.wordMax R₂.qlen (R₁.qlen a)
    @[simp]
    theorem Cslib.Complexity.BoundedOracleProgram.totalQlen_comp {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) (a : α) :
    (R₁.comp R₂).totalQlen a = R₁.qcount a * Turing.MultiTapeTM.wordMax R₂.totalQlen (R₁.qlen a)
    theorem Cslib.Complexity.BoundedOracleProgram.alen_comp_le {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) (a : α) :
    (R₁.comp R₂).alen a ≤ Turing.MultiTapeTM.wordMax R₂.alen (R₁.qlen a)
    theorem Cslib.Complexity.BoundedOracleProgram.totalQueryLength_comp_affine {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) {scale offset : ℕ} (haff : ∀ (w : List Bool), R₂.totalQlen w ≤ scale * w.length + offset) (a : α) :
    (List.map (fun (q' : Unit × List Bool) => q'.2.length) (OracleComp.queriesWith (fun (q' : Unit × List Bool) => oracle₂ q'.2) ((R₁.comp R₂).program a))).sum ≤ scale * R₁.totalQlen a + offset * R₁.qcount a

    Sharper affine totalQlen bound under composition: when R₂.totalQlen w ≤ scale * |w| + offset, the actual sum of inner query lengths along (R₁.comp R₂).program a is bounded by scale * R₁.totalQlen a + offset * R₁.qcount a, preserving total-query-length sparsity rather than multiplying qcount * qlen.

    noncomputable def Cslib.Complexity.BoundedOracleProgram.compAffine {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle₁ oracle₂ : List Bool → List Bool} {f : α → β} (R₁ : BoundedOracleProgram encA encB oracle₁ f) (R₂ : BoundedOracleProgram Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits oracle₂ oracle₁) {scale offset : ℕ} (haff : ∀ (w : List Bool), R₂.totalQlen w ≤ scale * w.length + offset) :
    BoundedOracleProgram encA encB oracle₂ f

    Composed BoundedOracleProgram refining comp with the sharper linear totalQlen budget scale * R₁.totalQlen a + offset * R₁.qcount a when R₂.totalQlen is affine in query length.

    Polynomial-time transfer for multi-bit word oracles: if oracle : List Bool → List Bool is computable in polynomial time, any BoundedOracleProgram relative to oracle is computable in polynomial time.

    theorem Cslib.Complexity.BoundedOracleProgram.exists_computableInO_polySpace {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {oracle : List Bool → List Bool} {f : α → β} {Tg Sg : List Bool → ℕ} (R : BoundedOracleProgram encA encB oracle f) (horacle : Turing.MultiTapeTM.ComputableInO oracle Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits Tg Sg) (hSg : Turing.MultiTapeTM.PolyBounded List.length Sg) :
    ∃ (c₀ : ℕ) (e₀ : ℕ) (S : α → ℕ), Turing.MultiTapeTM.PolyBounded (fun (a : α) => (encA a).length) S ∧ ∃ (c₁ : ℕ) (d₁ : ℕ), Turing.MultiTapeTM.ComputableInO f encA encB (fun (a : α) => c₀ * ((encA a).length + 1) ^ e₀ + (c₁ * ((encA a).length + 1) ^ d₁ + 1) * (c₀ * ((encA a).length + 1) ^ e₀ + Turing.MultiTapeTM.wordMax Tg (c₁ * ((encA a).length + 1) ^ d₁))) S

    Explicit ComputableInO transfer in polynomial workspace for multi-bit word oracles: simulating R against ComputableInO oracle encBits encBits Tg Sg uses polynomial workspace (depending only on input length, machine clock, answer-length growth, and Sg — never on Tg) and charges Tg at most once per step up to the polynomial clock.

    Polynomial-space transfer for multi-bit word oracles: if oracle : List Bool → List Bool is computable in polynomial space, any BoundedOracleProgram relative to oracle is computable in polynomial space.

    BoundedOracleReduction: language oracle reductions with explicit call profiles #

    noncomputable def Cslib.Complexity.encodedDecisionOracle {β : Type} (encB : β ↪ List Bool) (B : Set β) (w : List Bool) :

    Word-oracle adapter for a typed decision problem (B, encB): maps w : List Bool to [decide (w ∈ encB '' B)], matching languageOracle (encB '' B) ((), w).

    @[simp]
    theorem Cslib.Complexity.length_encodedDecisionOracle {β : Type} (encB : β ↪ List Bool) (B : Set β) (w : List Bool) :
    structure Cslib.Complexity.BoundedOracleReduction {α β : Type} (encA : α ↪ List Bool) (encB : β ↪ List Bool) (A : Set α) (B : Set β) :

    Deterministic adaptive oracle reduction between decision problems (A, encA) and (B, encB) with explicit (qcount, qlen, totalQlen, alen) call accounting.

    def Cslib.Complexity.BoundedOracleReduction.qcount {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) (a : α) :

    Number of oracle queries budgeted on a.

    def Cslib.Complexity.BoundedOracleReduction.qlen {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) (a : α) :

    Per-query length budgeted on a.

    def Cslib.Complexity.BoundedOracleReduction.totalQlen {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) (a : α) :

    Total query length budgeted on a.

    def Cslib.Complexity.BoundedOracleReduction.alen {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) (a : α) :

    Per-answer length budgeted on a.

    def Cslib.Complexity.BoundedOracleReduction.mono {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) {bound' : α → OracleCallBound} (h : ∀ (a : α), (R.bound a).Le (bound' a)) :

    Weaken the call bound of a BoundedOracleReduction to any coordinatewise larger profile.

    def Cslib.Complexity.BoundedOracleReduction.ofProgram {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} {f : α → Bool} (P : BoundedOracleProgram encA Turing.MultiTapeTM.encBool (encodedDecisionOracle encB B) f) (hf : ∀ (a : α), a ∈ A ↔ f a = true) :

    Build a BoundedOracleReduction from a BoundedOracleProgram computing a decider f for A against encodedDecisionOracle encB B.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.toProgram {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) :

    View a BoundedOracleReduction as a BoundedOracleProgram computing fun a => decide (a ∈ A) with unary answer-length cap 1.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.ofPolyTime {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} (B : Set β) {f : α → Bool} (hf : Turing.MultiTapeTM.ComputableInPolyTime f encA Turing.MultiTapeTM.encBool) (hA : ∀ (a : α), a ∈ A ↔ f a = true) :

    A problem in P has a 0-query BoundedOracleReduction to every problem B.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.ofSizeSensitive {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} {μA : α → ℕ} {μB : β → ℕ} (R : SizeSensitiveReduction encA encB μA μB) (hAB : ∀ (a : α), a ∈ A ↔ R.toFun a ∈ B) :

    Single-query lift from SizeSensitiveReduction: a many-one SizeSensitiveReduction lifts to a 1-query BoundedOracleReduction with qlen = totalQlen = |encB (R.toFun a)| and alen = 1.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.refl {α : Type} (encA : α ↪ List Bool) (A : Set α) :

    Identity / reflexivity (refl) of BoundedOracleReduction: 1 query of length |encA a| and 1-bit reply.

    def Cslib.Complexity.BoundedOracleReduction.complLeft {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) :

    Complement the source language Aᶜ without changing the OracleCallBound profile.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.complSelf {α : Type} (encA : α ↪ List Bool) (A : Set α) :

    Every language's complement reduces to the language itself via 1 query (Aᶜ ≤ B for B = A).

    Lift a typed BoundedOracleReduction encB encC B C to a word-level BoundedOracleProgram answering encodedDecisionOracle encB B via a total polynomial-time D : Decoder encB: non-canonical words (encB (D.decode w) ≠ w) are rejected in 0 queries, while canonical encodings run R₂.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.transDecoded {α β γ : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {encC : γ ↪ List Bool} {A : Set α} {B : Set β} {C : Set γ} (D : Turing.MultiTapeTM.Decoder encB) (R₁ : BoundedOracleReduction encA encB A B) (R₂ : BoundedOracleReduction encB encC B C) :

    Transitivity (transDecoded) across any typed intermediate language (B, encB) equipped with D : Decoder encB, tracking explicit (qcount, qlen, totalQlen, alen) composition.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.trans {α γ : Type} {encA : α ↪ List Bool} {encC : γ ↪ List Bool} {A : Set α} {B : Set (List Bool)} {C : Set γ} (R₁ : BoundedOracleReduction encA Turing.MultiTapeTM.encBits A B) (R₂ : BoundedOracleReduction Turing.MultiTapeTM.encBits encC B C) :

    Transitivity (trans) across word-encoded intermediate languages (B, encBits).

    Bridges to PolyTimeTuringReducible, PWithOracleQueries, P, and PSPACE #

    theorem Cslib.Complexity.BoundedOracleReduction.polyTimeTuringReducible {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) :

    Every BoundedOracleReduction witnesses PolyTimeTuringReducible (A ≤ᵖ_T B).

    theorem Cslib.Complexity.BoundedOracleReduction.mem_PWithOracleQueries {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (R : BoundedOracleReduction encA encB A B) {r : ℕ → ℕ} (hr : ∀ (a : α), R.qcount a ≤ r (encA a).length) :
    A ∈ PWithOracleQueries (⇑encB '' B) r encA

    If R.qcount a ≤ r (encA a).length for all a, then R places A in PWithOracleQueries (encB '' B) r encA.

    noncomputable def Cslib.Complexity.BoundedOracleReduction.ofPWithOracleQueries {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} {r : ℕ → ℕ} (h : A ∈ PWithOracleQueries (⇑encB '' B) r encA) :

    Conversely, any membership witness A ∈ PWithOracleQueries (encB '' B) r encA yields a BoundedOracleReduction encA encB A B with qcount a = r |encA a|, polynomial qlen, totalQlen = qcount * qlen, and alen = 1.

    theorem Cslib.Complexity.BoundedOracleReduction.mem_P {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (D : Turing.MultiTapeTM.Decoder encB) (R : BoundedOracleReduction encA encB A B) (hB : B ∈ P encB) :
    A ∈ P encA

    Polynomial-time transfer (mem_P) across BoundedOracleReduction when D : Decoder encB and B ∈ P encB.

    theorem Cslib.Complexity.BoundedOracleReduction.mem_PSPACE {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} (D : Turing.MultiTapeTM.Decoder encB) (R : BoundedOracleReduction encA encB A B) (hB : B ∈ PSPACE encB) :
    A ∈ PSPACE encA

    Polynomial-space transfer (mem_PSPACE) across BoundedOracleReduction when D : Decoder encB and B ∈ PSPACE encB.

    Parameterized exponential and subexponential oracle transfer #

    theorem Cslib.Complexity.BoundedOracleReduction.decidableInExpTime {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} {μA : α → ℕ} {μB : β → ℕ} (D : Turing.MultiTapeTM.Decoder encB) (R : BoundedOracleReduction encA encB A B) {scale offset : ℕ} (hμA : Turing.MultiTapeTM.ComputableInPolyTime μA encA Turing.MultiTapeTM.encNat) (hμB : Turing.MultiTapeTM.ComputableInPolyTime μB encB Turing.MultiTapeTM.encNat) (hparam : ∀ (a : α), ∀ q ∈ OracleComp.queriesWith (languageOracle (⇑encB '' B)) (R.program a), ∀ (b : β), encB b = q.2 → μB b ≤ scale * μA a + offset) {δ : ℝ} (hδ : 0 ≤ δ) (hB : DecidableInExpTime B encB μB δ) :
    DecidableInExpTime A encA μA (↑scale * δ)

    Parameterized exponential-time transfer across BoundedOracleReduction: when D : Decoder encB decodes canonical encB-words in polynomial time, μA and μB are polynomial-time computable, and every query q issued by R.program a against encB '' B with encB b = q.2 satisfies μB b ≤ scale * μA a + offset, any 2 ^ (δ * μB b) * poly(|b|) decider for B transfers to a 2 ^ ((scale * δ) * μA a) * poly(|a|) decider for A — with polynomial overhead absorbing both query count and query construction cost.

    theorem Cslib.Complexity.BoundedOracleReduction.decidableInSubexpTime {α β : Type} {encA : α ↪ List Bool} {encB : β ↪ List Bool} {A : Set α} {B : Set β} {μA : α → ℕ} {μB : β → ℕ} (D : Turing.MultiTapeTM.Decoder encB) (R : BoundedOracleReduction encA encB A B) {scale offset : ℕ} (hμA : Turing.MultiTapeTM.ComputableInPolyTime μA encA Turing.MultiTapeTM.encNat) (hμB : Turing.MultiTapeTM.ComputableInPolyTime μB encB Turing.MultiTapeTM.encNat) (hparam : ∀ (a : α), ∀ q ∈ OracleComp.queriesWith (languageOracle (⇑encB '' B)) (R.program a), ∀ (b : β), encB b = q.2 → μB b ≤ scale * μA a + offset) (hB : DecidableInSubexpTime B encB μB) :

    Parameterized subexponential-time transfer across BoundedOracleReduction.