Documentation

CslibFrontier.Computability.Machines.AuxPDA.StackTransfer

Native Boolean work words and stack transfers #

The counting auxiliary pushdown automaton can push a local work-tape word in reverse order, or pop a top-first word into nonblank work cells. Each transfer scans to the first blank and uses exactly one transition per bit, plus a halting transition. The supplied tape interval bounds the visited positions of the moving work head. The same marked interval can be filled nondeterministically with one occurrence trace per bit word while preserving the stack.

Transferring words between a work tape and the stack #

Scan the designated work tape to the right up to its first blank, pushing each encountered bit onto the stack. Each configuration has at most one transition occurrence. The input head, work-tape contents and output are preserved.

theorem Turing.CountingAuxPDA.pushWorkWord_runBranch {k : ℕ} {wordIn : List Bool} (tape : Fin k) (cfg : AuxPDA.Cfg k Bool Bool Unit wordIn) (word : List Bool) (hstate : cfg.tapes.state = some ()) (hword : ∀ j ≤ word.length, cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑j) = word[j]?) :
(pushWorkWord tape).runBranch cfg (List.replicate (word.length + 1) 0) = some { tapes := have __src := cfg.tapes; { state := none, inputPos := __src.inputPos, workTapes := __src.workTapes, workTapePos := Function.update cfg.tapes.workTapePos tape (cfg.tapes.workTapePos tape + ↑word.length), output := __src.output }, stack := word.reverse ++ cfg.stack }

A blank-terminated word of length n is pushed in exactly n + 1 transitions, including the final read of the blank. The top of the stack receives the last bit read, and only the designated work head moves.

theorem Turing.CountingAuxPDA.pushWorkWord_haltsWithin {k : ℕ} {wordIn : List Bool} (tape : Fin k) (cfg : AuxPDA.Cfg k Bool Bool Unit wordIn) (word : List Bool) (hstate : cfg.tapes.state = some ()) (hword : ∀ j ≤ word.length, cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑j) = word[j]?) :
(pushWorkWord tape).HaltsWithin (word.length + 1) cfg

Every push branch halts within the word length plus the closing blank test.

Pop a bit into every nonblank cell encountered on the designated work tape, moving right. The first blank terminates the transfer. If the stack runs out first, the machine halts with a false output instead of attempting to pop an empty stack.

theorem Turing.CountingAuxPDA.popWorkWord_runBranch {k : ℕ} {wordIn : List Bool} (tape : Fin k) (cfg : AuxPDA.Cfg k Bool Bool Unit wordIn) (word rest : List Bool) (hstate : cfg.tapes.state = some ()) (hstack : cfg.stack = word ++ rest) (hmarks : ∀ j < word.length, (cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑j)).isSome = true) (hblank : cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑word.length) = none) :
(popWorkWord tape).runBranch cfg (List.replicate (word.length + 1) 0) = some { tapes := have __src := cfg.tapes; { state := none, inputPos := __src.inputPos, workTapes := Function.update cfg.tapes.workTapes tape (MultiTapeTM.CopyBlock.writeBlock (cfg.tapes.workTapes tape) (cfg.tapes.workTapePos tape) (fun (j : ℤ) => word[j.toNat]?) word.length), workTapePos := Function.update cfg.tapes.workTapePos tape (cfg.tapes.workTapePos tape + ↑word.length), output := __src.output }, stack := rest }

With one nonblank work cell per bit, followed by a blank, the native transfer pops the specified top-first word. It writes the word into those same cells and stops at the blank.

theorem Turing.CountingAuxPDA.popWorkWord_haltsWithin {k : ℕ} {wordIn : List Bool} (tape : Fin k) (cfg : AuxPDA.Cfg k Bool Bool Unit wordIn) (word rest : List Bool) (hstate : cfg.tapes.state = some ()) (hstack : cfg.stack = word ++ rest) (hmarks : ∀ j < word.length, (cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑j)).isSome = true) (hblank : cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑word.length) = none) :
(popWorkWord tape).HaltsWithin (word.length + 1) cfg

Every pop branch for the marked word halts within its length plus the closing blank test.

Guessing a word into a marked interval #

def Turing.CountingAuxPDA.guessWorkWord {k : ℕ} {StackSym : Type u_1} (tape : Fin k) :

Guess one bit per nonblank cell on a selected work tape, in left-to-right order. The first blank terminates the phase. The transition indices are the guessed bits, with a singleton halt.

theorem Turing.CountingAuxPDA.guessWorkWord_runBranch {k : ℕ} {StackSym : Type u_1} {wordIn : List Bool} (tape : Fin k) (cfg : AuxPDA.Cfg k Bool StackSym Unit wordIn) (word : List Bool) (hstate : cfg.tapes.state = some ()) (hmarks : ∀ j < word.length, (cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑j)).isSome = true) (hblank : cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑word.length) = none) :
(guessWorkWord tape).runBranch cfg (MultiTapeCTM.GuessMachine.trace word) = some { tapes := have __src := cfg.tapes; { state := none, inputPos := __src.inputPos, workTapes := Function.update cfg.tapes.workTapes tape (MultiTapeTM.CopyBlock.writeBlock (cfg.tapes.workTapes tape) (cfg.tapes.workTapePos tape) (fun (j : ℤ) => word[j.toNat]?) word.length), workTapePos := Function.update cfg.tapes.workTapePos tape (cfg.tapes.workTapePos tape + ↑word.length), output := __src.output }, stack := cfg.stack }

Every bit word has its canonical occurrence trace on a marked interval of the same length. The guess overwrites exactly that interval, and preserves the input head, output and stack.

theorem Turing.CountingAuxPDA.guessWorkWord_haltsWithin {k : ℕ} {StackSym : Type u_1} {wordIn : List Bool} (tape : Fin k) (cfg : AuxPDA.Cfg k Bool StackSym Unit wordIn) (n : ℕ) (hstate : cfg.tapes.state = some ()) (hmarks : ∀ j < n, (cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑j)).isSome = true) (hblank : cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑n) = none) :
(guessWorkWord tape).HaltsWithin (n + 1) cfg

Guessing on a marked interval of length n has an all-branches clock of n + 1.

theorem Turing.CountingAuxPDA.guessWorkWord_mem_branches {k : ℕ} {StackSym : Type u_1} {wordIn : List Bool} (tape : Fin k) (cfg : AuxPDA.Cfg k Bool StackSym Unit wordIn) (n : ℕ) (hstate : cfg.tapes.state = some ()) (hmarks : ∀ j < n, (cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑j)).isSome = true) (hblank : cfg.tapes.workTapes tape (cfg.tapes.workTapePos tape + ↑n) = none) (indices : List ℕ) :
indices ∈ (guessWorkWord tape).branches (n + 1) cfg ↔ ∃ (word : List Bool), word.length = n ∧ indices = MultiTapeCTM.GuessMachine.trace word

The halting branches of a marked guess are exactly the canonical traces of the words of that width. The inherited trace injection therefore gives one branch per word.