-
Notifications
You must be signed in to change notification settings - Fork 177
feat(MultiTapeTM): Prove time upper-bounds for space-bounded classes #767
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
Draft
crei
wants to merge
2
commits into
leanprover:main
Choose a base branch
from
crei:tm_estimate_reachable_space_bounded
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
Cslib/Computability/Machines/Turing/MultiTape/Classes.lean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /- | ||
| Copyright (c) 2026 Christian Reitwiessner. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Christian Reitwiessner | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Mathlib.Order.Monotone.Defs | ||
|
|
||
| import Mathlib.Tactic.Ring | ||
| public import Cslib.Computability.Machines.Turing.MultiTape.Deterministic | ||
|
|
||
| /-! | ||
| # Complexity classes for deterministic multi-tape Turing machines | ||
|
|
||
| This file defines the resource-bounded complexity classes for deterministic multi-tape Turing | ||
| machines on top of `DecidableInTimeAndSpace`. | ||
|
|
||
| ## Design | ||
|
|
||
| The general classes `DTIME` and `DSPACE` are defined using a single bound function `ℕ → ℕ` but allow | ||
| for `O`-fuzzyness. Some textbooks use exact bounds ([Papadimitriou94]), while others use a | ||
| definition similar to this one ([AroraBarak09], [Sipser2013]). The fuzzy definition is justified by | ||
| the space and time compression / speedup theorems (which are not proven here) and allow for | ||
| easier proofs and simpler theorem statements. Once we have better machinery, we can prove the | ||
| compression / speedup theorems and potentially move to exact bounds. | ||
|
|
||
| The classes are always relative to an alphabet `Symbol`. | ||
|
|
||
| ## Important Declarations | ||
|
|
||
| * `DTIME` - the class of languages decidable in time `O(t(n))` for some function `t : ℕ → ℕ`. | ||
| * `DSPACE` - the class of languages decidable in space `O(s(n))` for some function `s : ℕ → ℕ`. | ||
|
|
||
| Some named complexity classes are defined in the `Classes` namespace: | ||
|
|
||
| * `P`, `E`, `EXP` | ||
| * `L`, `PSPACE`, `ESPACE`, `EXPSPACE` | ||
|
|
||
| ## References | ||
|
|
||
| * [C. Papadimitriou, *Computational Complexity*][Papadimitriou94] | ||
| * [S. Arora, B. Barak, *Computational Complexity: A Modern Approach*][AroraBarak09] | ||
| * [M. Sipser, *Introduction to the Theory of Computation*][Sipser2013] | ||
|
|
||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| open Cslib | ||
|
|
||
| namespace Turing.MultiTapeTM | ||
|
|
||
| variable {Symbol : Type} [Inhabited Symbol] | ||
|
|
||
| /-- Monotonicity of `DecidableInTimeAndSpace` in the time bound. -/ | ||
| lemma DecidableInTimeAndSpace.mono_time {L : Language Symbol} {s : ℕ → ℕ} : | ||
| Monotone (DecidableInTimeAndSpace L · s) := by | ||
| intro t₁ t₂ h hd | ||
| obtain ⟨k, sym, state, emb, tm, hcomp⟩ := hd | ||
| refine ⟨k, sym, state, emb, tm, fun input => ?_⟩ | ||
| obtain ⟨t', ht', s', hs', hcs⟩ := hcomp input | ||
| exact ⟨t', ht'.trans (h _), s', hs', hcs⟩ | ||
|
|
||
| /-- Monotonicity of `DecidableInTimeAndSpace` in the space bound. -/ | ||
| lemma DecidableInTimeAndSpace.mono_space {L : Language Symbol} {t : ℕ → ℕ} : | ||
| Monotone (DecidableInTimeAndSpace L t ·) := by | ||
| intro s₁ s₂ h hd | ||
| obtain ⟨k, sym, state, emb, tm, hcomp⟩ := hd | ||
| refine ⟨k, sym, state, emb, tm, fun input => ?_⟩ | ||
| obtain ⟨t', ht', s', hs', hcs⟩ := hcomp input | ||
| exact ⟨t', ht', s', hs'.trans (h _), hcs⟩ | ||
|
|
||
| /-- The complexity class of languages decidable in time linear in `t` by a deterministic multi-tape | ||
| Turing machine, disregarding the space requirement. -/ | ||
| def DTIME (t : ℕ → ℕ) := | ||
| {L : Language Symbol | ∃ c₁ c₂ : ℕ, ∃ s, DecidableInTimeAndSpace L (c₁ * t · + c₂) s} | ||
|
Collaborator
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. It would be nice if these definitions used big-O notation instead. I understand you're adding the additive constant here, but is that really necessary or standard? |
||
|
|
||
| /-- The complexity class of languages decidable in space linear in `s` by a deterministic multi-tape | ||
| Turing machine, for some time bound. -/ | ||
| def DSPACE (s : ℕ → ℕ) := | ||
| {L : Language Symbol | ∃ c₁ c₂ : ℕ, ∃ t, DecidableInTimeAndSpace L t (c₁ * s · + c₂)} | ||
|
|
||
| /-- `DTIME` is monotone in the time bound. -/ | ||
| lemma DTIME_mono {t₁ t₂ : ℕ → ℕ} (h : t₁ ≤ t₂) : | ||
| DTIME (Symbol := Symbol) t₁ ⊆ DTIME t₂ := by | ||
| rintro L ⟨c₁, c₂, s, hs⟩ | ||
| exact ⟨c₁, c₂, s, hs.mono_time fun n => by gcongr; exact h n⟩ | ||
|
|
||
| /-- `DSPACE` is monotone in the space bound. -/ | ||
| lemma DSPACE_mono {s₁ s₂ : ℕ → ℕ} (h : ∀ n, s₁ n ≤ s₂ n) : | ||
| DSPACE s₁ ⊆ (DSPACE s₂ : Set (Language Symbol)) := by | ||
| rintro L ⟨c₁, c₂, t, ht⟩ | ||
| exact ⟨c₁, c₂, t, ht.mono_space fun n => by gcongr; exact h n⟩ | ||
|
|
||
| namespace Classes | ||
|
|
||
| /-- Deterministic polynomial time. -/ | ||
| def P : Set (Language Symbol) := ⋃ k, DTIME (· ^ k) | ||
|
|
||
| /-- Deterministic exponential time (linear exponent). -/ | ||
| def E : Set (Language Symbol) := ⋃ k, DTIME fun n => 2 ^ (k * n) | ||
|
|
||
| /-- Deterministic exponential time (polynomial exponent). -/ | ||
| def EXP : Set (Language Symbol) := ⋃ k, DTIME fun n => 2 ^ (n ^ k) | ||
|
|
||
| /-- Deterministic logarithmic space. -/ | ||
| def L : Set (Language Symbol) := DSPACE Nat.log2 | ||
|
|
||
| /-- Deterministic polynomial space. -/ | ||
| def PSPACE : Set (Language Symbol) := ⋃ k, DSPACE fun n => n ^ k | ||
|
|
||
| /-- Deterministic exponential space. -/ | ||
| def ESPACE : Set (Language Symbol) := ⋃ k, DSPACE fun n => 2 ^ (k * n) | ||
|
|
||
| /-- Deterministic exponential space. -/ | ||
| def EXPSPACE : Set (Language Symbol) := ⋃ k, DSPACE fun n => 2 ^ (n ^ k) | ||
|
|
||
| end Classes | ||
|
|
||
| end Turing.MultiTapeTM | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I prefer the fuzzy definitions as they are more likely to be TM-definition independent.