Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Probabilistic.BlockNetwork

Block-counting tensor networks #

The block-counting identity, Lemma 2.2 of the note Deterministic simulations of nondeterministic and randomized time (30 October 2026) formalized in issue #1833. Fix a closed fair-coin table machine over Bool, an input, a block length b > 0 and a movement schedule σ of q > 0 intervals (Turing.MultiTapePTM.Schedule). The tensor network Turing.MultiTapePTM.blockNetwork counts the accepting choice strings of q * b bits whose run has schedule σ (Turing.MultiTapePTM.contraction_blockNetwork), so summing over the schedules gives the accepting count A_M(x) (Turing.MultiTapePTM.sum_contraction_blockNetwork). The proof idea is original to that note, building on the blocking of Hopcroft, Paul and Valiant [HPV77] (compare [Wil25], Lemma 2.1 and §3.2).

The network. The schedule fixes the block index of every head at the start of every interval (Turing.MultiTapePTM.scheduleBlock), and hence the window of three blocks around each work head.

Edges carry letters of Turing.MultiTapePTM.BlockLetter, a control record or the contents of a block. A letter of the wrong kind on an edge gives weight zero, because the interval leaving it requires the right kind.

The identity. Expanding every interval tensor as a sum over its bit strings writes the contraction as a sum over q strings of b bits, that is over choice strings of q * b bits. For a fixed choice string, induction over the intervals shows that an assignment of letters with nonzero weight is forced to be the true run's: the control records and the window contents of the true run at the end of each interval, and the run is forced to follow σ. Between two appearances of a block in windows, the block is untouched (Turing.MultiTapePTM.workTapes_intervalStart_eq_of_notMem_blockWindow), and within an interval the embedded window is matched to the true run (Turing.MultiTapePTM.intervalStep_view_iff). Conversely the true run's letters have weight one exactly when the run has schedule σ and accepts.

Size. The network has q * (3 k + 1) edges and q * (3 k + 2) vertices, no loops, maximum degree at most 2 * (3 k + 1), and entries at most 2 ^ b. Its letters have O(b) bits, so binarizing (Cslib.Circuits.Frontier.TensorNetwork.binarize) and subdividing it gives a bipartite Boolean network with O(q b) edges and degree O(b), as in the note.

Main definitions #

Main results #

References #

Block indices prescribed by a schedule #

def Turing.MultiTapePTM.scheduleBlock {k q : ℕ} (σ : Schedule k q) :
ℕ → Option (Fin k) → ℤ

The block index of every head at the start of interval i under the schedule σ, when every head starts in block 0: the sum of the entries of σ for the intervals before i.

@[simp]
theorem Turing.MultiTapePTM.scheduleBlock_zero {k q : ℕ} (σ : Schedule k q) :
scheduleBlock σ 0 = fun (x : Option (Fin k)) => 0
theorem Turing.MultiTapePTM.scheduleBlock_succ {k q : ℕ} (σ : Schedule k q) {i : ℕ} (hi : i < q) (head : Option (Fin k)) :
scheduleBlock σ (i + 1) head = scheduleBlock σ i head + ↑(σ ⟨i, hi⟩ head)
theorem Turing.MultiTapePTM.blockIndex_intervalStart_eq_scheduleBlock {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) {input : List Bool} (b : ℕ) [NeZero b] (coins : List Bool) (σ : Schedule k q) {i : ℕ} (hi : i ≤ q) (hσ : ∀ (j : Fin q), ↑j < i → machine.schedule b q coins (Cfg.init machine.initial input) j = σ j) :
Cfg.blockIndex b (machine.intervalStart b coins (Cfg.init machine.initial input) i) = scheduleBlock σ i

A run following σ has the block indices of σ. If the run replaying coins from the start has schedule entries σ j for the intervals j < i, it starts interval i with the block indices scheduleBlock σ i.

Appearances of a block in windows #

def Turing.MultiTapePTM.firstAfter {q : ℕ} (p : Fin q → Prop) [DecidablePred p] (i : Fin q) :

The first index after i satisfying p, if any.

def Turing.MultiTapePTM.lastBefore {q : ℕ} (p : Fin q → Prop) [DecidablePred p] (i : Fin q) :

The last index before i satisfying p, if any.

theorem Turing.MultiTapePTM.firstAfter_eq_some_iff {q : ℕ} {p : Fin q → Prop} [DecidablePred p] {i i' : Fin q} :
firstAfter p i = some i' ↔ i < i' ∧ p i' ∧ ∀ (j : Fin q), i < j → j < i' → ¬p j
theorem Turing.MultiTapePTM.lastBefore_eq_some_iff {q : ℕ} {p : Fin q → Prop} [DecidablePred p] {i i' : Fin q} :
lastBefore p i = some i' ↔ i' < i ∧ p i' ∧ ∀ (j : Fin q), i' < j → j < i → ¬p j
theorem Turing.MultiTapePTM.lastBefore_eq_none_iff {q : ℕ} {p : Fin q → Prop} [DecidablePred p] {i : Fin q} :
lastBefore p i = none ↔ ∀ j < i, ¬p j
theorem Turing.MultiTapePTM.firstAfter_eq_none_iff {q : ℕ} {p : Fin q → Prop} [DecidablePred p] {i : Fin q} :
firstAfter p i = none ↔ ∀ (j : Fin q), i < j → ¬p j
theorem Turing.MultiTapePTM.firstAfter_of_lastBefore {q : ℕ} {p : Fin q → Prop} [DecidablePred p] {i i' : Fin q} (hi : p i) (h : lastBefore p i = some i') :

Consecutive appearances: the last appearance before i has i as its next appearance.

theorem Turing.MultiTapePTM.lastBefore_of_firstAfter {q : ℕ} {p : Fin q → Prop} [DecidablePred p] {i i' : Fin q} (hi' : p i') (h : firstAfter p i' = some i) :
@[reducible, inline]
abbrev Turing.MultiTapePTM.InWindow {k q : ℕ} (σ : Schedule k q) (h : Fin k) (j : ℤ) (i : Fin q) :

Block j of work tape h lies in the window of interval i under σ.

def Turing.MultiTapePTM.portBlock {k q : ℕ} (σ : Schedule k q) (i : Fin q) (h : Fin k) (d : Fin 3) :

The block of the window entry d of work tape h in interval i.

def Turing.MultiTapePTM.portOf {k q : ℕ} (σ : Schedule k q) (i : Fin q) (h : Fin k) (j : ℤ) :
Fin 3

The window entry of block j of work tape h in interval i.

theorem Turing.MultiTapePTM.portBlock_portOf {k q : ℕ} {σ : Schedule k q} {i : Fin q} {h : Fin k} {j : ℤ} (hj : InWindow σ h j i) :
portBlock σ i h (portOf σ i h j) = j
theorem Turing.MultiTapePTM.inWindow_portBlock {k q : ℕ} (σ : Schedule k q) (i : Fin q) (h : Fin k) (d : Fin 3) :
InWindow σ h (portBlock σ i h d) i

The network #

@[reducible, inline]

The edges of a block-counting network of q intervals: .inl i carries the control record leaving interval i, and .inr (i, h, d) the contents of window entry d of work tape h leaving interval i.

@[reducible, inline]
abbrev Turing.MultiTapePTM.BlockLetter (k : ℕ) (State : Type) (b : ℕ) :

The letters on the edges: a control record or the contents of a block.

Instances For
    def Turing.MultiTapePTM.BlockLetter.control {k : ℕ} {State : Type} {b : ℕ} :
    BlockLetter k State b → BlockControl k State b

    The control record of a letter, or a default for block contents.

    def Turing.MultiTapePTM.BlockLetter.contents {k : ℕ} {State : Type} {b : ℕ} :
    BlockLetter k State b → ZMod b → Option Bool

    The block contents of a letter, or blank for a control record.

    def Turing.MultiTapePTM.acceptWeight {k : ℕ} {State : Type} {b : ℕ} :
    BlockLetter k State b → ℕ

    The weight of the last control record: one when its output track is accept.

    def Turing.MultiTapePTM.inControl {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (b : ℕ) (i : Fin q) (x : BlockEdge k q → BlockLetter k State b) :
    BlockControl k State b

    The control record entering interval i: the initial record for i = 0, and otherwise the letter on the control edge leaving interval i - 1.

    def Turing.MultiTapePTM.inWindow {k q : ℕ} {State : Type} {b : ℕ} (σ : Schedule k q) (i : Fin q) (x : BlockEdge k q → BlockLetter k State b) :
    Fin k → Fin 3 → ZMod b → Option Bool

    The window contents entering interval i: each block is read from the edge leaving the previous interval whose window contains it, and is blank if there is none.

    def Turing.MultiTapePTM.IntervalHolds {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) (i : Fin q) (x : BlockEdge k q → BlockLetter k State b) (u : Fin b → Bool) :

    The edge condition at interval i for the bits u: an interval step from the entering record and window to the letters on the edges leaving i, which must be of the right kinds, moving the blocks as σ i prescribes.

    def Turing.MultiTapePTM.edgeTarget {k q : ℕ} (σ : Schedule k q) :
    BlockEdge k q → Fin q ⊕ BlockEdge k q

    The target of an edge: the interval reading it next, or its sink.

    noncomputable def Turing.MultiTapePTM.blockNetwork {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) :

    The block-counting network of the schedule σ. It has a vertex for every interval (.inl i) and a sink for every edge (.inr e). Every edge e leaves its interval and ends at edgeTarget σ e. The tensor of interval i counts the bit strings u ∈ {0,1}^b for which IntervalHolds holds; the sink of the last control edge requires the output track accept, and every other sink is 1.

    The counting identity #

    theorem Turing.MultiTapePTM.notMem_blockWindow {k : ℕ} {State : Type} {input : List Bool} {b : ℕ} [NeZero b] {c : Cfg k Bool State input} {h : Fin k} {j : ℤ} (hj : ¬|Cfg.blockIndex b c (some h) - j| ≤ 1) (r : ZMod b) :
    ↑b * j + ↑r.val ∉ Cfg.blockWindow b c h

    A work-tape cell of a block outside the window of a configuration is outside its three blocks.

    theorem Turing.MultiTapePTM.contraction_blockNetwork {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) [NeZero b] (σ : Schedule k q) [Fintype State] (hq : 0 < q) :
    (machine.blockNetwork input b σ).contraction = {y : Fin (q * b) → Bool | machine.runClosedCoins (List.ofFn y) input = [true] ∧ machine.schedule b q (List.ofFn y) (Cfg.init machine.initial input) = σ}.card

    The block-counting identity for one schedule. The contraction of the network of σ is the number of choice strings of q * b bits on which the machine accepts and whose run has movement schedule σ.

    theorem Turing.MultiTapePTM.sum_contraction_blockNetwork {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) [NeZero b] [Fintype State] (hq : 0 < q) :
    ∑ σ : Schedule k q, (machine.blockNetwork input b σ).contraction = machine.acceptCount input (q * b)

    The block-counting identity (the note's Lemma 2.2, equation (2)). Summed over the movement schedules of q > 0 intervals of b bits, the contractions of the block-counting networks are the accepting count on q * b bits.

    Size, degree and entries #

    A block-counting network has q * (3 * k + 1) edges: one control edge and three block edges per work tape for each interval.

    A block-counting network has q * (3 * k + 2) vertices: the intervals and the sinks.

    theorem Turing.MultiTapePTM.tensor_blockNetwork_le {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) (v : Fin q ⊕ BlockEdge k q) (x : BlockEdge k q → BlockLetter k State b) :
    (machine.blockNetwork input b σ).tensor v x ≤ 2 ^ b

    Every entry of a block-counting network is at most 2 ^ b: an interval tensor counts bit strings of length b, and a sink is 0 or 1.

    theorem Turing.MultiTapePTM.blockNetwork_src {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) (e : BlockEdge k q) :
    (machine.blockNetwork input b σ).src e = Sum.inl (Sum.elim id Prod.fst e)

    The source of an edge is its interval.

    theorem Turing.MultiTapePTM.blockNetwork_tgt {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) (e : BlockEdge k q) :
    (machine.blockNetwork input b σ).tgt e = edgeTarget σ e

    The target of an edge is the interval reading it next, or its sink.

    theorem Turing.MultiTapePTM.blockNetwork_tensor_interval {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) (i : Fin q) (x : BlockEdge k q → BlockLetter k State b) :
    (machine.blockNetwork input b σ).tensor (Sum.inl i) x = {u : Fin b → Bool | machine.IntervalHolds input b σ i x u}.card

    The tensor of an interval counts the bit strings satisfying its condition.

    theorem Turing.MultiTapePTM.blockNetwork_tensor_controlSink {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) (i : Fin q) (x : BlockEdge k q → BlockLetter k State b) :
    (machine.blockNetwork input b σ).tensor (Sum.inr (Sum.inl i)) x = if ↑i + 1 = q then acceptWeight (x (Sum.inl i)) else 1

    The sink of a control edge accepts the last control record, and is 1 otherwise.

    theorem Turing.MultiTapePTM.blockNetwork_tensor_blockSink {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) (e : Fin q × Fin k × Fin 3) (x : BlockEdge k q → BlockLetter k State b) :
    (machine.blockNetwork input b σ).tensor (Sum.inr (Sum.inr e)) x = 1

    The sink of a block edge is the constant 1.

    theorem Turing.MultiTapePTM.loopless_blockNetwork {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) :
    (machine.blockNetwork input b σ).Loopless

    A block-counting network has no loops.

    theorem Turing.MultiTapePTM.maxDegreeLE_blockNetwork {k q : ℕ} {State : Type} (machine : MultiTapePTM k Bool State) (input : List Bool) (b : ℕ) (σ : Schedule k q) :
    (machine.blockNetwork input b σ).MaxDegreeLE (2 * (3 * k + 1))

    The degree bound. An interval has its 3 k + 1 leaving edges and at most 3 k + 1 entering edges, and a sink has at most one edge.