Documentation

CslibFrontier.Computability.StreamArithmetic.QueryTree

Uncompiled conditional query trees for signed-digit streams #

This module provides uncompiled deterministic conditional query-tree semantics and active-query tracing as an intermediate helper after, and not a formalization of, [OpenAI2026LogSpace, Section 10.1, Lemma 10.2]. Native Turing-machine or counter-program space realization of regenerated gate evaluation remains open and is tracked in #9181.

A QueryProg Op Struct α represents a deterministic finite query tree that:

Continuations in QueryProg (queryDigit, queryStruct), post-processing maps (QueryProg.map), and leaf predicates (CondBoolTree.digitBit) are arbitrary host Lean functions. Accordingly, this module certifies only exact evaluation semantics (eval), executed-query tracing (activeQueries) with unselected-branch exclusion, query substitution (substDigits), and a query-count bound for CondBoolTree.toQueryProg. It makes no claim about uniformity, computability, or Turing-machine workspace.

Main definitions #

Main results #

References #

inductive Cslib.StreamArithmetic.QueryEvent (Op : Type u) (Struct : Type v) :
Type (max u v)

An oracle query event executed along the active branch of a QueryProg, recording the requested operand/place or structural predicate.

@[instance_reducible]
instance Cslib.StreamArithmetic.instDecidableEqQueryEvent {Op✝ : Type u_1} {Struct✝ : Type u_2} [DecidableEq Op✝] [DecidableEq Struct✝] :
DecidableEq (QueryEvent Op✝ Struct✝)
def Cslib.StreamArithmetic.instDecidableEqQueryEvent.decEq {Op✝ : Type u_1} {Struct✝ : Type u_2} [DecidableEq Op✝] [DecidableEq Struct✝] (x✝ x✝¹ : QueryEvent Op✝ Struct✝) :
Decidable (x✝ = x✝¹)
inductive Cslib.StreamArithmetic.QueryProg (Op : Type u) (Struct : Type v) (α : Type w) :
Type (max u v w)

Uncompiled deterministic finite conditional query tree over operand streams Op and structural predicates Struct, returning α. Continuations are arbitrary host Lean functions; this type carries no machine-space or uniformity semantics (see #9181).

def Cslib.StreamArithmetic.QueryProg.eval {Op : Type u} {Struct : Type v} {α : Type w} (prog : QueryProg Op Struct α) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
α

Evaluate a QueryProg against operand streams env and structural predicates sEnv.

def Cslib.StreamArithmetic.QueryProg.activeQueries {Op : Type u} {Struct : Type v} {α : Type w} (prog : QueryProg Op Struct α) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
List (QueryEvent Op Struct)

Ordered trace of all oracle queries actually executed along (env, sEnv). Unselected branches are not traversed and do not appear in the trace.

def Cslib.StreamArithmetic.QueryProg.map {Op : Type u} {Struct : Type v} {α : Type w} {β : Type w'} (f : α → β) :
QueryProg Op Struct α → QueryProg Op Struct β

Host-level post-processing of the return value; preserves activeQueries.

def Cslib.StreamArithmetic.QueryProg.bind {Op : Type u} {Struct : Type v} {α : Type w} {β : Type w'} (p : QueryProg Op Struct α) (k : α → QueryProg Op Struct β) :
QueryProg Op Struct β

Sequential composition of conditional query trees: run p, then pass its result to k.

@[simp]
theorem Cslib.StreamArithmetic.QueryProg.eval_map {Op : Type u} {Struct : Type v} {α : Type w} {β : Type w'} (f : α → β) (p : QueryProg Op Struct α) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(map f p).eval env sEnv = f (p.eval env sEnv)
@[simp]
theorem Cslib.StreamArithmetic.QueryProg.activeQueries_map {Op : Type u} {Struct : Type v} {α : Type w} {β : Type w'} (f : α → β) (p : QueryProg Op Struct α) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(map f p).activeQueries env sEnv = p.activeQueries env sEnv
@[simp]
theorem Cslib.StreamArithmetic.QueryProg.eval_bind {Op : Type u} {Struct : Type v} {α : Type w} {β : Type w'} (p : QueryProg Op Struct α) (k : α → QueryProg Op Struct β) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(p.bind k).eval env sEnv = (k (p.eval env sEnv)).eval env sEnv
@[simp]
theorem Cslib.StreamArithmetic.QueryProg.activeQueries_bind {Op : Type u} {Struct : Type v} {α : Type w} {β : Type w'} (p : QueryProg Op Struct α) (k : α → QueryProg Op Struct β) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(p.bind k).activeQueries env sEnv = p.activeQueries env sEnv ++ (k (p.eval env sEnv)).activeQueries env sEnv
def Cslib.StreamArithmetic.QueryProg.substDigits {Op : Type u} {Struct : Type v} {Op₂ : Type u'} {α : Type w} (prog : QueryProg Op Struct α) (child : Op → ℕ → QueryProg Op₂ Struct ℤ) :
QueryProg Op₂ Struct α

Substitute child query trees child op u for every operand digit query (op, u) in prog. Structural queries on Struct pass through unchanged.

theorem Cslib.StreamArithmetic.QueryProg.eval_substDigits {Op : Type u} {Struct : Type v} {Op₂ : Type u'} {α : Type w} (prog : QueryProg Op Struct α) (child : Op → ℕ → QueryProg Op₂ Struct ℤ) (env₂ : Op₂ → ℕ → ℤ) (sEnv : Struct → Bool) :
(prog.substDigits child).eval env₂ sEnv = prog.eval (fun (op : Op) (u : ℕ) => (child op u).eval env₂ sEnv) sEnv

Semantic soundness of substDigits: evaluating the composed query tree equals evaluating prog against the stream environment produced by child.

theorem Cslib.StreamArithmetic.QueryProg.mem_activeQueries_substDigits {Op : Type u} {Struct : Type v} {Op₂ : Type u'} {α : Type w} (prog : QueryProg Op Struct α) (child : Op → ℕ → QueryProg Op₂ Struct ℤ) (env₂ : Op₂ → ℕ → ℤ) (sEnv : Struct → Bool) {ev : QueryEvent Op₂ Struct} (hev : ev ∈ (prog.substDigits child).activeQueries env₂ sEnv) :
(∃ (sOp : Struct), QueryEvent.struct sOp ∈ prog.activeQueries (fun (op : Op) (u : ℕ) => (child op u).eval env₂ sEnv) sEnv ∧ ev = QueryEvent.struct sOp) ∨ ∃ (op : Op) (u : ℕ), QueryEvent.digit op u ∈ prog.activeQueries (fun (op : Op) (u : ℕ) => (child op u).eval env₂ sEnv) sEnv ∧ ev ∈ (child op u).activeQueries env₂ sEnv

Characterization of every oracle query emitted by prog.substDigits child: it is either a pass-through structural query of prog, or a query emitted by child op u for some active digit query (op, u) of prog.

inductive Cslib.StreamArithmetic.CondBoolTree (Op : Type u) (Struct : Type v) :
Type (max u v)

Uncompiled bounded-fan-in conditional Boolean tree after, and not a machine-space formalization of, [OpenAI2026LogSpace, Lemma 10.2] (native space realization is tracked in #9181):

  • constants const b,
  • unary negation notGate c,
  • binary andGate c₁ c₂ and orGate c₁ c₂,
  • conditional selector condGate sel onTrue onFalse (evaluates sel first, then only the selected branch),
  • digit-bit leaf digitBit op j bitPred testing a host Lean predicate of digit (op, j),
  • structural leaf structLeaf sOp.
def Cslib.StreamArithmetic.CondBoolTree.eval {Op : Type u} {Struct : Type v} (tree : CondBoolTree Op Struct) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :

Direct mathematical Boolean evaluation of a CondBoolTree.

def Cslib.StreamArithmetic.CondBoolTree.depth {Op : Type u} {Struct : Type v} :
CondBoolTree Op Struct → ℕ

Longest root-to-leaf syntactic depth of a CondBoolTree.

def Cslib.StreamArithmetic.CondBoolTree.toQueryProg {Op : Type u} {Struct : Type v} :
CondBoolTree Op Struct → QueryProg Op Struct Bool

Uncompiled depth-first query-tree translation of a CondBoolTree (helper after, and not a formalization of, [OpenAI2026LogSpace, Lemma 10.2]; native gate regeneration and stack-space realization are tracked in #9181). Evaluating condGate sel t f queries sel first and then only the selected branch.

@[simp]
theorem Cslib.StreamArithmetic.CondBoolTree.toQueryProg_eval {Op : Type u} {Struct : Type v} (tree : CondBoolTree Op Struct) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
tree.toQueryProg.eval env sEnv = tree.eval env sEnv

Evaluation-equivalence helper for uncompiled CondBoolTree.toQueryProg (not a machine-space formalization of [OpenAI2026LogSpace, Lemma 10.2]; see #9181).

theorem Cslib.StreamArithmetic.CondBoolTree.length_activeQueries_toQueryProg_le {Op : Type u} {Struct : Type v} (tree : CondBoolTree Op Struct) (env : Op → ℕ → ℤ) (sEnv : Struct → Bool) :
(tree.toQueryProg.activeQueries env sEnv).length ≤ 2 ^ tree.depth

Uncompiled query-count helper for CondBoolTree.toQueryProg (not a machine-space formalization of [OpenAI2026LogSpace, Lemma 10.2]; see #9181): because condGate evaluates only its selected branch, the number of executed leaf queries is at most 2 ^ tree.depth.