Documentation

CslibFrontier.Computability.TreeEval.Ary.Iterative

Iterative control for fan-in-d Cook–Mertz #

The controller unravels Ary.procWith into calls and returns over one shared register bank. A frame retains a round number, child index, forward/undo phase, coefficient and target register; it stores neither a tree nor a saved register bank. Reading a node is parameterized by the existing Tree.Node lookup at a path. The path is recovered from the stack's child indices.

A forward phase scales a child's register and calls that child with coefficient one. After the last forward call, it performs the supplied gate update. Undo phases call each child with coefficient minus one and undo its scaling upon return. Children in both phases are processed in increasing order, exactly as in Ary.gateRoundWith.

Main definitions #

References #

This is pure control semantics for positive fan-in. Node lookup and the supplied gate extension are parameters; their native implementation and space costs are separate obligations.

structure Cslib.TreeEval.Ary.Iter.Frame (K : Type u_1) (d : ℕ) :
Type u_1

A suspended call, retaining control data only.

  • round : ℕ

    The unit-round index.

  • child : Fin d

    The child currently being evaluated or just returned.

  • undo : Bool

    False during forward calls and true during undo calls.

  • coeff : K

    The coefficient of the suspended call.

  • target : Fin (d + 1)

    The register targeted by the suspended call.

@[instance_reducible]
instance Cslib.TreeEval.Ary.Iter.instDecidableEqFrame {K✝ : Type u_1} {d✝ : ℕ} [DecidableEq K✝] :
DecidableEq (Frame K✝ d✝)
def Cslib.TreeEval.Ary.Iter.instDecidableEqFrame.decEq {K✝ : Type u_1} {d✝ : ℕ} [DecidableEq K✝] (x✝ x✝¹ : Frame K✝ d✝) :
Decidable (x✝ = x✝¹)
inductive Cslib.TreeEval.Ary.Iter.Mode (K : Type u_1) (d : ℕ) :
Type u_1

Calling a node with a coefficient and target, or returning from one.

  • call {K : Type u_1} {d : ℕ} (coeff : K) (target : Fin (d + 1)) : Mode K d

    Evaluate the current node into the target with the supplied coefficient.

  • ret {K : Type u_1} {d : ℕ} : Mode K d

    Continue the innermost suspended call, or halt if there is none.

@[instance_reducible]
instance Cslib.TreeEval.Ary.Iter.instDecidableEqMode {K✝ : Type u_1} {d✝ : ℕ} [DecidableEq K✝] :
DecidableEq (Mode K✝ d✝)
def Cslib.TreeEval.Ary.Iter.instDecidableEqMode.decEq {K✝ : Type u_1} {d✝ : ℕ} [DecidableEq K✝] (x✝ x✝¹ : Mode K✝ d✝) :
Decidable (x✝ = x✝¹)
structure Cslib.TreeEval.Ary.Iter.Cfg (K : Type u_1) (d r : ℕ) :
Type u_1

One shared register bank, the suspended calls and the current mode.

  • regs : State K d r

    Registers shared by all levels.

  • stack : List (Frame K d)

    Suspended calls, innermost first.

  • mode : Mode K d

    The current call or return.

@[instance_reducible]
instance Cslib.TreeEval.Ary.Iter.instDecidableEqCfg {K✝ : Type u_1} {d✝ r✝ : ℕ} [DecidableEq K✝] :
DecidableEq (Cfg K✝ d✝ r✝)
def Cslib.TreeEval.Ary.Iter.instDecidableEqCfg.decEq {K✝ : Type u_1} {d✝ r✝ : ℕ} [DecidableEq K✝] (x✝ x✝¹ : Cfg K✝ d✝ r✝) :
Decidable (x✝ = x✝¹)
def Cslib.TreeEval.Ary.Iter.path {K : Type u_1} {d : ℕ} (st : List (Frame K d)) :
List (Fin d)

The root-to-current-node path, read from the suspended calls.

@[simp]
@[simp]
theorem Cslib.TreeEval.Ary.Iter.path_cons {K : Type u_1} {d : ℕ} (fr : Frame K d) (st : List (Frame K d)) :
path (fr :: st) = path st ++ [fr.child]
@[simp]
theorem Cslib.TreeEval.Ary.Iter.length_path {K : Type u_1} {d : ℕ} (st : List (Frame K d)) :
def Cslib.TreeEval.Ary.Iter.initialCfg {K : Type u_1} {d r : ℕ} (S : State K d r) (c : K) (t : Fin (d + 1)) :
Cfg K d r

Start a root call from arbitrary global registers.

def Cslib.TreeEval.Ary.Iter.halted {K : Type u_1} {d r : ℕ} (q : Cfg K d r) :

A returned value with no suspended caller is final.

@[simp]
theorem Cslib.TreeEval.Ary.Iter.halted_ret_nil {K : Type u_1} {d r : ℕ} (S : State K d r) :
halted { regs := S, stack := [], mode := Mode.ret } = true
def Cslib.TreeEval.Ary.Iter.unitAt {K : Type u_1} [Field K] (us : List Kˣ) (i : ℕ) :

Read a unit round by index; the fallback makes malformed control states total.

def Cslib.TreeEval.Ary.Iter.updateAt {K : Type u_1} {d b r : ℕ} [Field K] (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (read : List (Fin d) → Tree.Node d b) (P : List (Fin d)) (c : K) (t : Fin (d + 1)) (S : State K d r) :
State K d r

Update at a gate, leaving the registers unchanged if the requested path is invalid.

def Cslib.TreeEval.Ary.Iter.beginRound {K : Type u_1} {d r : ℕ} [Field K] (hd : 0 < d) (us : List Kˣ) (i : ℕ) (c : K) (t : Fin (d + 1)) (S : State K d r) (st : List (Frame K d)) :
Cfg K d r

Begin the first forward child of a round, scaling before the recursive call.

def Cslib.TreeEval.Ary.Iter.step {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (q : Cfg K d r) :
Cfg K d r

One control step of the fan-in-d procedure.

def Cslib.TreeEval.Ary.Iter.runFrom {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (q : Cfg K d r) (n : ℕ) :
Cfg K d r

Iterate control steps from any supplied configuration.

@[simp]
theorem Cslib.TreeEval.Ary.Iter.runFrom_zero {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (q : Cfg K d r) :
runFrom hd e E us read q 0 = q
@[simp]
theorem Cslib.TreeEval.Ary.Iter.runFrom_one {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (q : Cfg K d r) :
runFrom hd e E us read q 1 = step hd e E us read q
theorem Cslib.TreeEval.Ary.Iter.runFrom_succ {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (q : Cfg K d r) (n : ℕ) :
runFrom hd e E us read q (n + 1) = step hd e E us read (runFrom hd e E us read q n)

A successor clock performs one more control step.

theorem Cslib.TreeEval.Ary.Iter.runFrom_add {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (q : Cfg K d r) (m n : ℕ) :
runFrom hd e E us read q (m + n) = runFrom hd e E us read (runFrom hd e E us read q m) n

Consecutive runs compose without resetting registers or continuation frames.

@[simp]
theorem Cslib.TreeEval.Ary.Iter.step_ret_nil {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) :
step hd e E us read { regs := S, stack := [], mode := Mode.ret } = { regs := S, stack := [], mode := Mode.ret }

A final return is stationary.

theorem Cslib.TreeEval.Ary.Iter.step_call_leaf {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (st : List (Frame K d)) (c : K) (t : Fin (d + 1)) (v : Fin b → Bool) (hv : read (path st) = Tree.Node.leaf v) :
step hd e E us read { regs := S, stack := st, mode := Mode.call c t } = { regs := Function.update S t (S t + c • e v), stack := st, mode := Mode.ret }

A leaf call uses one control step and leaves its continuation stack intact.

theorem Cslib.TreeEval.Ary.Iter.step_call_gate_cons {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (u : Kˣ) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (st : List (Frame K d)) (c : K) (t : Fin (d + 1)) (f : Gate d b) (hf : read (path st) = Tree.Node.gate f) :
step hd e E (u :: us) read { regs := S, stack := st, mode := Mode.call c t } = beginRound hd (u :: us) 0 c t S st

A gate starts the first round when the unit enumeration is nonempty.

theorem Cslib.TreeEval.Ary.Iter.step_call_gate_nil {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (st : List (Frame K d)) (c : K) (t : Fin (d + 1)) (f : Gate d b) (hf : read (path st) = Tree.Node.gate f) :
step hd e E [] read { regs := S, stack := st, mode := Mode.call c t } = { regs := S, stack := st, mode := Mode.ret }

With no unit rounds a gate call immediately returns unchanged registers.

theorem Cslib.TreeEval.Ary.Iter.updateAt_gate {K : Type u_1} {d b r : ℕ} [Field K] (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (read : List (Fin d) → Tree.Node d b) (P : List (Fin d)) (c : K) (t : Fin (d + 1)) (S : State K d r) (f : Gate d b) (hf : read P = Tree.Node.gate f) :
updateAt E read P c t S = gateUpdateWith E f c t S

Reading a valid gate performs exactly the supplied algebraic gate update.

theorem Cslib.TreeEval.Ary.Iter.step_ret_forward_next {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (fr : Frame K d) (st : List (Frame K d)) (hu : fr.undo = false) (hj : ↑fr.child + 1 < d) :
step hd e E us read { regs := S, stack := fr :: st, mode := Mode.ret } = { regs := scale (reg fr.target ⟨↑fr.child + 1, hj⟩) (↑(unitAt us fr.round)) S, stack := { round := fr.round, child := ⟨↑fr.child + 1, hj⟩, undo := fr.undo, coeff := fr.coeff, target := fr.target } :: st, mode := Mode.call 1 (reg fr.target ⟨↑fr.child + 1, hj⟩) }

After a forward child returns, scale and call the next child if one remains.

theorem Cslib.TreeEval.Ary.Iter.step_ret_forward_last {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (fr : Frame K d) (st : List (Frame K d)) (hu : fr.undo = false) (hj : ¬↑fr.child + 1 < d) :
step hd e E us read { regs := S, stack := fr :: st, mode := Mode.ret } = { regs := updateAt E read (path st) fr.coeff fr.target S, stack := { round := fr.round, child := ⟨0, hd⟩, undo := true, coeff := fr.coeff, target := fr.target } :: st, mode := Mode.call (-1) (reg fr.target ⟨0, hd⟩) }

The last forward return performs the gate update and calls the first undo child.

theorem Cslib.TreeEval.Ary.Iter.step_ret_undo_next {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (fr : Frame K d) (st : List (Frame K d)) (hu : fr.undo = true) (hj : ↑fr.child + 1 < d) :
step hd e E us read { regs := S, stack := fr :: st, mode := Mode.ret } = { regs := scale (reg fr.target fr.child) (↑(unitAt us fr.round)⁻¹) S, stack := { round := fr.round, child := ⟨↑fr.child + 1, hj⟩, undo := fr.undo, coeff := fr.coeff, target := fr.target } :: st, mode := Mode.call (-1) (reg fr.target ⟨↑fr.child + 1, hj⟩) }

An undo return first cancels the scaling, then calls the next child without scaling it.

theorem Cslib.TreeEval.Ary.Iter.step_ret_undo_round {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (fr : Frame K d) (st : List (Frame K d)) (hu : fr.undo = true) (hj : ¬↑fr.child + 1 < d) (hi : fr.round + 1 < us.length) :
step hd e E us read { regs := S, stack := fr :: st, mode := Mode.ret } = beginRound hd us (fr.round + 1) fr.coeff fr.target (scale (reg fr.target fr.child) (↑(unitAt us fr.round)⁻¹) S) st

The last undo return begins the next round if one remains.

theorem Cslib.TreeEval.Ary.Iter.step_ret_undo_last {K : Type u_1} {d b r : ℕ} [Field K] (hd : 0 < d) (e : (Fin b → Bool) → Fin r → K) (E : Gate d b → (Fin d → Fin r → K) → Fin r → K) (us : List Kˣ) (read : List (Fin d) → Tree.Node d b) (S : State K d r) (fr : Frame K d) (st : List (Frame K d)) (hu : fr.undo = true) (hj : ¬↑fr.child + 1 < d) (hi : ¬fr.round + 1 < us.length) :
step hd e E us read { regs := S, stack := fr :: st, mode := Mode.ret } = { regs := scale (reg fr.target fr.child) (↑(unitAt us fr.round)⁻¹) S, stack := st, mode := Mode.ret }

The final undo return pops exactly the current call's frame.