Repository navigation
refactor(MultiTape): express simulations and tape specifications through run paths - #1117
Conversation
0940347 to
9b2cf9a
Compare
…1116) Adds `RunPath.ofDeterministic` and `ComputationPath.ofDeterministic`, built directly from `step`, and proves that every deterministic path is the canonical path from its head. The halted-run and output-to-tape proofs reuse the shared path API. First step toward counting time and space only on run and computation paths. The stack continues in leanprover#1117. Composed with Codex; description written with Claude Code. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
9b2cf9a to
66e9d12
Compare
66e9d12 to
be5e7fa
Compare
crei
left a comment
There was a problem hiding this comment.
I love the homomorphism formalism, just some questions and docstring clarifications.
| Cfg k Symbol State input := | ||
| Cfg.init ntm.q₀ input | ||
|
|
||
| /-- The one-step relation on configurations for `input`, as a set of pairs. A map of configurations |
There was a problem hiding this comment.
I think the second sentence is more confusing than helpful.
| attains its per-tape space usage at a single step, which makes a bound that holds at every point | ||
| in time usable as a bound for the whole run. | ||
|
|
||
| A simulation maps every run path of one machine to a run path of another with `RunPath.map`. |
There was a problem hiding this comment.
This reads like it would introduce the term simulation - could you put MultiTapeNTM.RunPath.space_map_le at the front, so it's clear that this paragraph is about explaining that lemma?
| the tapes `j` of the source path, and the head of every other tape `l` stays in `S l`, then the | ||
| mapped path uses the space of the source path plus the cells of `S l` for every other tape `l`. -/ | ||
| lemma space_map_le (p : ntm.RunPath input) (f : (ntm.stepRel input).Hom (ntm'.stepRel input')) | ||
| (e : Fin k ↪ Fin k') (S : Fin k' → Finset ℤ) |
There was a problem hiding this comment.
S should be lowercase and could also use more than one letter - this lemma has a lot of variables.
| exact Finset.card_le_card (tm.visitedByTapeHead_mono cfg i h) | ||
|
|
||
| /-- The total space used is monotone in the number of steps. -/ | ||
| lemma spaceUsed_mono (tm : MultiTapeTM k Symbol State) (cfg : Cfg k Symbol State input) : |
There was a problem hiding this comment.
Why did you delete this? I see that a proof that used it before does not need it any more - is it somehow obvious with the new definitions?
There was a problem hiding this comment.
I think that because we switched to RunPath the proof that used it don't need anymore to compare runs of different lengths.
| exact tm.mem_visitedByTapeHead_self cfg τ i | ||
|
|
||
| /-- After the machine has halted the heads no longer move, so the space usage stops growing. -/ | ||
| lemma spaceUsed_eq_of_halt (cfg : Cfg k Symbol State input) {τ t : ℕ} (hle : τ ≤ t) |
There was a problem hiding this comment.
The halting lemmas are also gone - is that obvious with the homomorphism formalism?
There was a problem hiding this comment.
Not because of the homomorphism, it's because we use RunPath which make it very simple.
| wordsCfg input none ws' (out ++ emitted) ∧ | ||
| Q input ws ws' emitted ∧ | ||
| tm.spaceUsed (wordsCfg input (some tm.q₀) ws out) t ≤ s | ||
| (RunPath.ofDeterministic tm (wordsCfg input (some tm.q₀) ws out) t).space ≤ s |
There was a problem hiding this comment.
This is a bit difficult to read, do we not have the spaceUsed definition any more? Or is this a matter of it just being defeq and easier to use in this form?
There was a problem hiding this comment.
Thats a good point. Now spaceUsed is a duplicated definition we don't want, but I change it to be a convenient wrapper for (RunPath.ofDeterministic tm cfg t).space which makes it readable
There was a problem hiding this comment.
To be consistent with the naming I'll just call it space. But it will be in the next PR as there are still consumers of spaceUsed I haven't changed
d4d32b2 to
c32d63c
Compare
Package the configuration maps of `extendTapes`, `outputToTape` and `inputFromTape` as step-preserving maps that transport run paths, and state their space bounds on the mapped path. Runs of the simulating machine follow from `runFrom_map` instead of per-file iteration proofs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generate the hom apply lemmas with `simps`, derive the deterministic `spaceUsedByTape_le_card` from the shared path lemma, and drop the unused `space_map_noTapes_le` and the single-use projection lemma. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing used `withOutputHom`. Remove it together with the lemmas and definitions only it relied on: `step_outputToTape_withOutput`, `RunPath.space_map_eq` and `Cfg.withOutput`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
State the space clause of `TransformsTapes` like `RunsInSpace`: every run from the start visits at most `s` cells. Sequential composition then bounds its space through the existing state-free invariant, without splitting the run at the first halt, and the deterministic space lemmas used only by the plumbing are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
State the space clause of `TransformsTapes` on the path of its first `t` steps, the path counterpart of the old `spaceUsed`. The halting argument moves into `TransformsTapes.imp`, through `runFrom_mem_ofDeterministic` and `RunPath.space_le_of_subset`, and the other specifications return to their original shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`stepHom` reads a `Function.Semiconj` of the step functions as a homomorphism of the step relations; state the simulation step lemmas in that form and explain the construction in `embedHom`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`RunPath.space_map_le` now takes sets containing the head positions of the extra tapes instead of a space bound for each of them, so the simulations state where their extra heads stay and the conversion to space happens once. `spaceUsedByTape_map_le_card` is removed. Explain `embedHom` in its docstring. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Define `spaceUsed` as an abbreviation for the space of the path of the first `t` steps, so `TransformsTapes` keeps its original statement while space is counted on paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`ConfinedRun` now states that every head stays within `[-r, r]` at each step, so a round splits its run with `runFrom_add` and the final space bound comes from `RunPath.space_le_sum_card`. This removes the uses of the deterministic splitting, monotonicity and halting space lemmas, and the now unused `spaceUsed_le_of_visited_subset_Icc`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`ConfinedRun` now reads the canonical path of the run: its last configuration and `RunPath.InWindow`, which says every head stays in `window r`. Runs compose with `ConfinedRun.trans` through the new `RunPath.ofDeterministic_add` (the path analogue of `runFrom_add`), and a halted run extends with `ConfinedRun.add_of_halted`, so the final space bound is `InWindow.space_le`. Moves `window` from `ConfigBound` to `TapeLemmas` and replaces `visitedByTapeHead_subset_Icc` with `inWindow_ofDeterministic`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b7713cc to
4e0fecf
Compare
`ConfinedRun` was the canonical path of a run together with its last configuration and `InWindow`, which for a deterministic machine is just a run path in a window. The rounds of `repeatUntilBlank` are now run paths joined with `smash`, and the joined path gives the run and its space through `runFrom_head_eq_last` and `spaceUsed_head_le`. This removes `ConfinedRun` and `RunPath.ofDeterministic_add`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…paths `TransformsTapes` now asks for a run path to the halted normal form, with its time and space bounded. Combinators compose these paths: `seq` and `repeatUntilBlank` map the running steps of their parts with `runningStepHom` and join them with `smash`, and `tapeEmb` and the output generality map whole paths. `RunPath.exists_running` cuts a path at its first halted configuration, which replaces `HaltsAt`, `exists_haltsAt` and `existsUnique_haltsAt`. Mapping running steps replaces `runFrom_runCfg`, `runFrom_leftCfg`, `runFrom_rightCfg`, `HaltsAt.runFrom_seq`, `runFrom_seq` and `forgetState_runFrom_seq`, now `exists_runPath_seq`. This also removes `runFrom_succ`, `runFrom_add`, `runFrom_mem_ofDeterministic`, `runFrom_head_eq_last` and `spaceUsed_head_le`, and states the window bound as `RunPath.inWindow_of_space_le`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Renames `MultiTapeTM.spaceUsed` to `space`, matching `RunPath.space` and `ComputationPath.space`: `tm.space cfg t` is the space of the path of the first `t` steps from `cfg`. The lemmas named after it follow. Depends on leanprover#1117: its commits are included temporarily and will leave this diff when that PR merges. The stack continues in leanprover#1122. Composed with Claude Code. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Expresses the tape simulations, tape specifications and sequential composition through run paths.
stepHomreads a semiconjugation ofstepas a homomorphism of the step relations, which maps run paths, and each ofextendTapes,outputToTapeandinputFromTapebounds the space of the mapped path throughRunPath.space_map_le, replacing the per-file iteration and space proofs.spaceUsedbecomes an abbreviation for the space of the path of the firsttsteps, soTransformsTapeskeeps its statement. Sequential composition derives its space bound from the existing state-free invariant. The deterministic space lemmas used only by these proofs and the unusedCfg.withOutputare removed.The stack continues in #1133.
Composed with Claude Code.