-
Notifications
You must be signed in to change notification settings - Fork 163
feat(Automata, LTS, and Turing): saturated multistep transitions, mapLabel for LTS, and Nondeterministic Turing Machines (NTM) #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d127bd9
85c2b86
ce3adec
ab47fad
eba8935
f7e8d84
2ba81ef
7ab5224
f9cef26
1338139
9721c91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /- | ||
| Copyright (c) 2026 Fabrizio Montesi. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Fabrizio Montesi, Bolton Bailey | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Foundations.Data.BiTape | ||
|
|
||
| /-! # Basic definitions for Turing Machines (TMs) -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Cslib.Computability.Turing.SingleTape | ||
|
|
||
| /-- The transition labels used by a single-tape Turing Machine. -/ | ||
| structure TrLabel (State Symbol : Type*) where | ||
| /-- Symbol to read from the tape. -/ | ||
| read : Option Symbol | ||
| /-- Symbol to write on the tape. -/ | ||
| write : Option Symbol | ||
| /-- Head movement of the tape. -/ | ||
| move : Option Turing.Dir | ||
|
|
||
| /-- Configuration of a single-tape Turing machine. -/ | ||
| structure Cfg (State Symbol : Type*) where | ||
| /-- The state that the machine is in. -/ | ||
| state : State | ||
| /-- Tape of the machine (memory). -/ | ||
| tape : Turing.BiTape Symbol | ||
|
|
||
| /-- Helper builder for a configuration with a given tape content. -/ | ||
| def Cfg.mk₁ (s : State) (xs : List Symbol) : Cfg State Symbol where | ||
| state := s | ||
| tape := Turing.BiTape.mk₁ xs | ||
|
|
||
| /-- The space used by a configuration is the space used by its tape. -/ | ||
| def Cfg.spaceUsed (cfg : Cfg State Symbol) : ℕ := cfg.tape.spaceUsed | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this definition might be misleading because it implement a rather uncommon notion of space (although it might be equivalent in the end). This definition is mainly used to prove that the output length is bounded by the number of steps. So maybe we should rather rename it to "tapeSize" or something like that. |
||
|
|
||
| end Cslib.Computability.Turing.SingleTape | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,11 +62,12 @@ We also provide ways of constructing polynomial-runtime TMs | |
|
|
||
| @[expose] public section | ||
|
|
||
| open Cslib Relation | ||
| open Relation | ||
|
|
||
| namespace Turing | ||
| namespace Cslib.Turing | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the idea here that we don't want to extend Mathlib's Turing namespace? |
||
|
|
||
| open BiTape StackTape | ||
| open _root_.Turing | ||
|
|
||
| variable {Symbol : Type} | ||
|
|
||
|
|
@@ -503,4 +504,4 @@ end PolyTimeComputable | |
|
|
||
| end SingleTapeTM | ||
|
|
||
| end Turing | ||
| end Cslib.Turing | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /- | ||
| Copyright (c) 2026 Fabrizio Montesi. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Fabrizio Montesi | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Foundations.Data.Relation | ||
| public import Cslib.Computability.Automata.NA.Basic | ||
| public import Cslib.Foundations.Data.BiTape | ||
| public import Cslib.Computability.Machines.Turing.SingleTape.Defs | ||
|
|
||
| /-! # Single-Tape Nondeterministic Turing Machines (NTMs) | ||
|
|
||
| Nondeterministic Turing Machines (NTMs), defined as nondeterministic automata (`NA`) that act on a | ||
| bidirectional tape (`BiTape`). | ||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| namespace Cslib.Computability.Turing.SingleTape | ||
|
|
||
| open Automata | ||
|
|
||
| /-- A (single-tape) Nondeterministic Turing Machine (NTM) is a nondeterministic automaton equipped | ||
| with a set of accepting halting states. -/ | ||
| structure SingleTapeNTM (State Symbol : Type*) | ||
| extends NA State (SingleTape.TrLabel State Symbol) where | ||
| /-- The set of accepting states. -/ | ||
| accept : Set State | ||
| /-- Proof that all accepting states are halting states. -/ | ||
| accept_halting (hmem : s ∈ accept) : ¬∃ μ s', Tr s μ s' | ||
|
|
||
| variable {State Symbol : Type*} | ||
|
|
||
| /-- An NTM yields a small-step operational semantics on configurations, which codifies an execution | ||
| step. -/ | ||
| @[scoped grind =] | ||
| def SingleTapeNTM.Red (m : SingleTapeNTM State Symbol) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be common for automata, but I myself would be able to understand this better if the documentation string would reference the abbreviation "Red" in some way ;) |
||
| (c c' : Cfg State Symbol) : Prop := | ||
| ∃ μ, m.Tr c.state μ c'.state ∧ -- The controller can perform the move | ||
| μ.read = c.tape.head ∧ -- The tape has the expected symbol to be read | ||
| c'.tape = (c.tape.write μ.write).optionMove μ.move -- Write effect on the tape | ||
|
|
||
| /-- Multistep execution of an NTM, defined as the reflexive and transitive closure of one-step | ||
| execution. | ||
| -/ | ||
| @[scoped grind =] | ||
| def SingleTapeNTM.MRed (m : SingleTapeNTM State Symbol) := | ||
| Relation.ReflTransGen m.Red | ||
|
|
||
| /-- An NTM is an acceptor of finite lists of symbols. -/ | ||
| @[simp, scoped grind =] | ||
| instance : Acceptor (SingleTapeNTM State Symbol) Symbol where | ||
| Accepts (m : SingleTapeNTM State Symbol) (xs : List Symbol) := | ||
| ∃ s ∈ m.start, ∃ c', c'.state ∈ m.accept ∧ m.MRed (Cfg.mk₁ s xs) c' | ||
|
|
||
| end Cslib.Computability.Turing.SingleTape | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be an inductive type. We can replace the transition function with the basic operations on a TM. For more discussion see Zulip thread for this PR