Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Counting

Labelled branches of counting machines #

MultiTapeCTM specializes the shared multi-tape machine to lists of transition occurrences. An occurrence is identified by its list index: two equal actions in the list remain two choices. Deterministic instructions have singleton lists. Configurations, actions and tape operations are the existing Turing ones; no new machine storage or instruction model is introduced.

A branch records occurrence indices and stops at its first halted configuration. In contrast to the upstream unlabelled step relation, halted configurations have no further labelled steps. An empty list at a running configuration is stuck, not a rejecting halt.

Main definitions #

Main results #

This is operational counting semantics, without a claimed polynomial-time verifier or a new storage/instruction model. Canonical certificates are developed in MultiTape.Counting.Certificate.

References #

The shared machine calculus is adapted from the cslib crypto branch; its source and authors are credited in MultiTape.Machine and MultiTape.Machine.Equivalence. The counting layer retains the transition identities forgotten by the relation-based nondeterministic interface.

@[reducible, inline]
abbrev Turing.MultiTapeCTM (k : ℕ) (Symbol : Type u_1) (State : Type u_2) :
Type (max (max (max u_1 u_2) 0) u_1 u_2)

A shared-core machine with a finite list of transition occurrences at each local view.

def Turing.MultiTapeCTM.actions {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) :
List (Action k Symbol State)

The live transition occurrences, in their specified order. A halted state has no choices.

def Turing.MultiTapeCTM.toNTM {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (M : MultiTapeCTM k Symbol State) :
MultiTapeNTM k Symbol State

Forget the multiplicity of transition occurrences for reasoning about reachable configurations. Use the original counting machine when counting branches.

theorem Turing.MultiTapeCTM.initCfg_toNTM {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (machine : MultiTapeCTM k Symbol State) (input : List Symbol) :
machine.toNTM.initCfg input = (MultiTapeMachine.initialConfig machine input).tapes

Forgetting transition multiplicity preserves the initial configuration.

def Turing.MultiTapeCTM.Nonblocking {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (machine : MultiTapeCTM k Symbol State) :

Every running local view has a transition occurrence. This excludes stuck states even on unreachable configurations; a native HaltsWithin hypothesis only needs the reachable ones.

theorem Turing.MultiTapeCTM.Nonblocking.actions_ne_nil {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {machine : MultiTapeCTM k Symbol State} (h : machine.Nonblocking) (cfg : Cfg k Symbol State input) (hrun : cfg.state ≠ none) :
machine.actions cfg ≠ []

A nonblocking transition table has an occurrence at every running configuration.

def Turing.MultiTapeCTM.step? {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) (index : ℕ) :
Option (Cfg k Symbol State input)

Execute one occurrence. Invalid indices and attempts to step a halted configuration fail.

def Turing.MultiTapeCTM.lts {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (machine : MultiTapeCTM k Symbol State) (input : List Symbol) :
Cslib.LTS (Cfg k Symbol State input) ℕ

The native labelled transition system; labels identify occurrences, not their effects.

def Turing.MultiTapeCTM.runBranch {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) :
Cfg k Symbol State input → List ℕ → Option (Cfg k Symbol State input)

Replay actual transitions, with no implicit padding after halting.

@[simp]
theorem Turing.MultiTapeCTM.runBranch_nil {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) :
machine.runBranch cfg [] = some cfg
theorem Turing.MultiTapeCTM.runBranch_cons {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) (index : ℕ) (rest : List ℕ) :
machine.runBranch cfg (index :: rest) = (machine.step? cfg index).bind fun (next : Cfg k Symbol State input) => machine.runBranch next rest
theorem Turing.MultiTapeCTM.runBranch_eq_some_iff {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg final : Cfg k Symbol State input) (choices : List ℕ) :
machine.runBranch cfg choices = some final ↔ (machine.lts input).MTr cfg choices final

Replay is exactly the existing LTS multistep relation, with the occurrence labels retained.

theorem Turing.MultiTapeCTM.actions_of_halted {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) {cfg : Cfg k Symbol State input} (h : cfg.Halted) :
machine.actions cfg = []
theorem Turing.MultiTapeCTM.step?_of_halted {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) {cfg : Cfg k Symbol State input} (h : cfg.Halted) (index : ℕ) :
machine.step? cfg index = none
theorem Turing.MultiTapeCTM.runBranch_of_halted {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) {cfg : Cfg k Symbol State input} (h : cfg.Halted) (choices : List ℕ) :
machine.runBranch cfg choices = if choices = [] then some cfg else none

From a halted configuration, only the empty trace can be replayed.

theorem Turing.MultiTapeCTM.runBranch_append {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) (first second : List ℕ) :
machine.runBranch cfg (first ++ second) = (machine.runBranch cfg first).bind fun (next : Cfg k Symbol State input) => machine.runBranch next second

Replaying concatenated traces is sequential replay; a premature halt cannot be crossed.

def Turing.MultiTapeCTM.branches {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) :
ℕ → Cfg k Symbol State input → Finset (List ℕ)

Enumerate first-halting traces of at most the supplied number of actual transitions.

theorem Turing.MultiTapeCTM.branches_of_halted {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) {cfg : Cfg k Symbol State input} (h : cfg.Halted) (fuel : ℕ) :
machine.branches fuel cfg = {[]}
theorem Turing.MultiTapeCTM.step?_eq_some_iff {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg final : Cfg k Symbol State input) (index : ℕ) :
machine.step? cfg index = some final ↔ ∃ (h : index < (machine.actions cfg).length), (machine.actions cfg)[index].apply cfg = final

A labelled step is exactly an in-range list occurrence, even if other occurrences agree.

theorem Turing.MultiTapeCTM.step_toNTM_iff {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (M : MultiTapeCTM k Symbol State) {cfg next : Cfg k Symbol State input} (hrun : ¬cfg.Halted) :
M.toNTM.Step cfg next ↔ ∃ (i : ℕ), M.step? cfg i = some next

Before halting, a step of the unlabelled machine is precisely a valid occurrence.

@[simp]
theorem Turing.MultiTapeCTM.nil_mem_branches {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) (fuel : ℕ) :
[] ∈ machine.branches fuel cfg ↔ cfg.Halted
theorem Turing.MultiTapeCTM.cons_mem_branches {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) (fuel index : ℕ) (rest : List ℕ) :
index :: rest ∈ machine.branches (fuel + 1) cfg ↔ ∃ (next : Cfg k Symbol State input), machine.step? cfg index = some next ∧ rest ∈ machine.branches fuel next
theorem Turing.MultiTapeCTM.exists_runBranch_of_runningPath {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (M : MultiTapeCTM k Symbol State) (p : RelSeries (M.toNTM.runningStepRel input)) :
∃ (indices : List ℕ), M.runBranch p.head indices = some p.last ∧ indices.length = p.length

A path containing only running steps can be replayed by occurrence indices.

theorem Turing.MultiTapeCTM.exists_runningPath_of_runBranch {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (M : MultiTapeCTM k Symbol State) {c d : Cfg k Symbol State input} {indices : List ℕ} (h : M.runBranch c indices = some d) :
∃ (p : RelSeries (M.toNTM.runningStepRel input)), p.head = c ∧ p.last = d ∧ p.length = indices.length

A successful occurrence replay gives a path of running steps.

theorem Turing.MultiTapeCTM.mem_branches_iff {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (cfg : Cfg k Symbol State input) (fuel : ℕ) (choices : List ℕ) :
choices ∈ machine.branches fuel cfg ↔ choices.length ≤ fuel ∧ ∃ (final : Cfg k Symbol State input), machine.runBranch cfg choices = some final ∧ final.Halted

The finite enumeration is exactly the first-halting LTS traces within the given clock.

inductive Turing.MultiTapeCTM.HaltsWithin {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) :
ℕ → Cfg k Symbol State input → Prop

Every branch halts within this many actual transitions. Running configurations must have at least one occurrence, so a stuck branch cannot make a time bound hold vacuously.

theorem Turing.MultiTapeCTM.haltsWithin_of_paths {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {M : MultiTapeCTM k Symbol State} (hM : M.Nonblocking) {fuel : ℕ} {cfg : Cfg k Symbol State input} (h : ∀ (p : M.toNTM.RunPath input), RelSeries.head p = cfg → fuel ≤ p.length → (RelSeries.last p).Halted) :
M.HaltsWithin fuel cfg

An unlabelled time bound certifies termination of a nonblocking counting machine.

theorem Turing.MultiTapeCTM.haltsWithin_of_paths_of_haltsWithin {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {M : MultiTapeCTM k Symbol State} {t₁ t₂ : ℕ} {cfg : Cfg k Symbol State input} (h₁ : M.HaltsWithin t₁ cfg) (h₂ : ∀ (p : M.toNTM.RunPath input), RelSeries.head p = cfg → t₂ ≤ p.length → (RelSeries.last p).Halted) :
M.HaltsWithin t₂ cfg

If a MultiTapeCTM already satisfies HaltsWithin at some clock t₁ (ruling out stuck reachable configurations) and every unlabelled run path of length at least t₂ halts, then it also satisfies HaltsWithin at clock t₂.

theorem Turing.MultiTapeCTM.HaltsWithin.paths_halted {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {M : MultiTapeCTM k Symbol State} {fuel : ℕ} {cfg : Cfg k Symbol State input} (h : M.HaltsWithin fuel cfg) (p : M.toNTM.RunPath input) :
RelSeries.head p = cfg → fuel ≤ p.length → (RelSeries.last p).Halted

A counting-machine clock also bounds its unlabelled paths. Erasing the occurrence indices preserves the halting configuration of every path of at least that length.

theorem Turing.MultiTapeCTM.HaltsWithin.mono {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {machine : MultiTapeCTM k Symbol State} {cfg : Cfg k Symbol State input} {fuel larger : ℕ} (h : machine.HaltsWithin fuel cfg) (hle : fuel ≤ larger) :
machine.HaltsWithin larger cfg

Enlarging a sufficient clock does not add transitions after a branch halts.

theorem Turing.MultiTapeCTM.HaltsWithin.length_le {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {machine : MultiTapeCTM k Symbol State} {cfg final : Cfg k Symbol State input} {fuel : ℕ} (h : machine.HaltsWithin fuel cfg) {choices : List ℕ} (hrun : machine.runBranch cfg choices = some final) :
choices.length ≤ fuel

A successful replay cannot pass the all-branches halting bound.

theorem Turing.MultiTapeCTM.HaltsWithin.branches_eq {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {machine : MultiTapeCTM k Symbol State} {cfg : Cfg k Symbol State input} {fuel larger : ℕ} (h : machine.HaltsWithin fuel cfg) (hle : fuel ≤ larger) :
machine.branches larger cfg = machine.branches fuel cfg

A sufficient clock can be increased without changing any terminal branch multiplicity.

theorem Turing.MultiTapeCTM.HaltsWithin.branches_nonempty {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {machine : MultiTapeCTM k Symbol State} {cfg : Cfg k Symbol State input} {fuel : ℕ} (h : machine.HaltsWithin fuel cfg) :
(machine.branches fuel cfg).Nonempty

The no-stuck condition guarantees at least one terminal branch.

def Turing.MultiTapeCTM.branchCount {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (verdict : List Symbol → Bool) (fuel : ℕ) (cfg : Cfg k Symbol State input) :

Count terminal branches whose output satisfies a Boolean verdict. A failed replay is never counted, even for the complementary verdict.

theorem Turing.MultiTapeCTM.HaltsWithin.branchCount_pos_iff {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {M : MultiTapeCTM k Symbol State} {fuel : ℕ} {cfg : Cfg k Symbol State input} (h : M.HaltsWithin fuel cfg) (verdict : List Symbol → Bool) :
0 < M.branchCount verdict fuel cfg ↔ ∃ (p : M.toNTM.RunPath input), RelSeries.head p = cfg ∧ (RelSeries.last p).Halted ∧ verdict (RelSeries.last p).output = true

A terminal verdict occurs within a sufficient clock exactly when a halted unlabelled path realizes it.

theorem Turing.MultiTapeCTM.branchCount_add_not {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (machine : MultiTapeCTM k Symbol State) (verdict : List Symbol → Bool) (fuel : ℕ) (cfg : Cfg k Symbol State input) :
machine.branchCount verdict fuel cfg + machine.branchCount (fun (out : List Symbol) => !verdict out) fuel cfg = (machine.branches fuel cfg).card

Acceptance and rejection partition the terminal branches, without counting stuck states.

def Turing.MultiTapeCTM.acceptCount {k : ℕ} {State : Type u_2} (machine : MultiTapeCTM k Bool State) {input : List Bool} (fuel : ℕ) (cfg : Cfg k Bool State input) :

The accepting terminal count uses the standard one-bit true output convention.

def Turing.MultiTapeCTM.rejectCount {k : ℕ} {State : Type u_2} (machine : MultiTapeCTM k Bool State) {input : List Bool} (fuel : ℕ) (cfg : Cfg k Bool State input) :

Every terminal output other than the one-bit true word rejects. Invalid or stuck traces are not rejecting branches.

theorem Turing.MultiTapeCTM.acceptCount_add_rejectCount {k : ℕ} {State : Type u_2} (machine : MultiTapeCTM k Bool State) {input : List Bool} (fuel : ℕ) (cfg : Cfg k Bool State input) :
machine.acceptCount fuel cfg + machine.rejectCount fuel cfg = (machine.branches fuel cfg).card
theorem Turing.MultiTapeCTM.HaltsWithin.branchCount_eq {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} {machine : MultiTapeCTM k Symbol State} {cfg : Cfg k Symbol State input} {fuel larger : ℕ} (h : machine.HaltsWithin fuel cfg) (hle : fuel ≤ larger) (verdict : List Symbol → Bool) :
machine.branchCount verdict larger cfg = machine.branchCount verdict fuel cfg
theorem Turing.MultiTapeCTM.exists_branchBound {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (machine : MultiTapeCTM k Symbol State) [Finite State] [Finite Symbol] :
∃ (bound : ℕ), ∀ (input : List Symbol) (cfg : Cfg k Symbol State input), (machine.actions cfg).length ≤ bound

Finite control and a fixed finite alphabet give one fixed bound on transition occurrences. Repeated actions are counted separately; their multiplicity is not bounded by Nat.card Action.