Skip to content

feat(MultiTapeTM): Nondeterministic multi-tape Turing machines - #820

Open
barni120400 wants to merge 1 commit into
leanprover:mainfrom
barni120400:multitape/ntm
Open

feat(MultiTapeTM): Nondeterministic multi-tape Turing machines#820
barni120400 wants to merge 1 commit into
leanprover:mainfrom
barni120400:multitape/ntm

Conversation

@barni120400

@barni120400 barni120400 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Adds nondeterministic multi-tape Turing machines: the transition function is replaced by a transition relation, and a computation path is the list of configurations it passes through together with a proof that they form a chain of steps from the initial configuration to the one it ends at, so List.IsChainFromTo carries the whole validity condition. MultiTapeTM.toNTM embeds the deterministic machine and preserves computation in bounded time and space.

Configurations and the effect of an action move to a shared MultiTape/Configuration.lean. No existing statement changes meaning.

NB: claude was used heavily throughout.

Comment thread Cslib/Computability/Machines/Turing/MultiTape/Nondeterministic.lean
Comment thread Cslib/Computability/Machines/Turing/MultiTape/Deterministic.lean Outdated
Comment thread Cslib/Computability/Machines/Turing/MultiTape/Nondeterministic.lean
Comment thread Cslib/Computability/Machines/Turing/MultiTape/NonDeterministic.lean Outdated
Comment thread Cslib/Computability/Machines/Turing/MultiTape/NonDeterministic.lean Outdated
Comment thread Cslib/Computability/Machines/Turing/MultiTape/NonDeterministic.lean Outdated
Comment thread Cslib/Computability/Machines/Turing/MultiTape/NonDeterministic.lean Outdated
Comment thread Cslib/Computability/Machines/Turing/MultiTape/Configuration.lean
/-- the configurations passed through, starting with the initial one -/
cfgs : List (Cfg k Symbol State input)
/-- a path visits at least one configuration -/
ne_nil : cfgs ≠ []

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK this is a bit weird. ne_nil is already enforced by isChainFromTo, but you need it for cfg.getLast ne_nil below. Is there a nicer way to do it? Maybe

start : cfgs.head? = some (ntm.initCfg input)
isChain : cfgs.IsChain ntm.Step

@crei crei Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way would be

last : Cfg k Symbol State input
isChainFromTo : cfgs.IsChainFromTo ntm.Step (ntm.initCfg input) last

then you don't need def last below.

@barni120400 barni120400 Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the second suggestion. It's still a bit weird that we duplicate the last element - it's written both at "last" and it's the last element in the chain.

@crei crei Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet more options:

structure ComputationPath (ntm : MultiTapeNTM k Symbol State) (input : List Symbol) where
  /-- the configurations passed through after the initial one -/
  tail : List (Cfg k Symbol State input)
  isChain : ((ntm.initCfg input) :: tail).IsChain ntm.Step

def ComputationPath.last (p : ntm.ComputationPath input) : Cfg k Symbol State input :=
    ((ntm.initCfg input) :: tail).getLast sorry

or just

def _root_.List.IsComputationPathTo {ntm : MultiTapeNTM k Symbol State} {input : List Symbol}
    (cfgs : List (Cfg k Symbol State input)) (last : Cfg k Symbol State input) :=
  List.IsChainFromTo ntm.Step (ntm.initCfg input) last

Comment thread Cslib/Computability/Machines/Turing/MultiTape/Nondeterministic.lean Outdated
Comment thread Cslib/Computability/Machines/Turing/MultiTape/Nondeterministic.lean Outdated
A nondeterministic machine replaces the transition function by a
transition relation. Configurations and the effect of an action move to a
shared `MultiTape/Configuration.lean`; no existing statement changes
meaning.

A computation path is the list of configurations it passes through
together with a proof that they form a chain of steps from the initial
configuration to the one it ends at, so `List.IsChainFromTo` carries the
whole validity condition. `MultiTapeTM.toNTM` embeds the deterministic
machine and `toNTM_computes` shows the embedding preserves computation in
bounded time and space.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@crei

crei commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

This looks good as it is, maybe some fine tuning for ComputationPath, but also not needed. In the worst case, we can adjust it if we see it doesn't work well for proofs.

@barni120400

Copy link
Copy Markdown
Contributor Author

This looks good as it is, maybe some fine tuning for ComputationPath, but also not needed. In the worst case, we can adjust it if we see it doesn't work well for proofs.

Ok sounds good

step that does not depend on how the action was chosen.
-/
@[simp]
def Action.apply (out : Action k Symbol State) (cfg : Cfg k Symbol State input) :

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def Action.apply (out : Action k Symbol State) (cfg : Cfg k Symbol State input) :
def Action.apply (action : Action k Symbol State) (cfg : Cfg k Symbol State input) :

output := cfg.output ++ out.outS.toList

/-- A work tape head moves by at most one cell when an action is applied. -/
lemma workTapePos_apply_le (out : Action k Symbol State)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lemma workTapePos_apply_le (out : Action k Symbol State)
lemma workTapePos_apply_le (action : Action k Symbol State)

@crei

crei commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Just noticed that this includes #827, which is probably fine, but please rename all mentions of out / transitionout to action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants