Skip to content

feat(MultiTapeTM): add input and work tape rewinding - #873

Open
SamuelSchlesinger wants to merge 2 commits into
samschles/tm-03-tape-adaptersfrom
samschles/tm-04-rewind
Open

feat(MultiTapeTM): add input and work tape rewinding#873
SamuelSchlesinger wants to merge 2 commits into
samschles/tm-03-tape-adaptersfrom
samschles/tm-04-rewind

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Add a shared controller for rewinding native input and contiguous work-tape contents. Use it to transform any machine into one that halts with its input head at the initial position, preserving output and work tapes.

Part 4/6 of the TM composition stack. Depends on #872. Next: #874.

Validation: strict build, import checks, full tests, and linters.

This PR was composed with Astra via Codex.

contributes one visited cell to space. Arbitrary data on unused tapes is preserved.
- `OutputToWorkTape` redirects output to one fresh tape, including the symbol on a halting step.
- `InputFromWorkTape` simulates the native input on a work tape, preserving boundary clamping.
- `Rewind` shares one controller between native-input and work-tape rewinding. Work-tape rewind

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.

I think this explanation makes uses too many terms that only become clear once you read the files.

Comment on lines +15 to +17
One controller rewinds either the native input head or a selected work-tape head. It first moves
left, scans left through nonblank cells, then moves right and halts. The initial left move handles
a head starting on the right blank boundary, including when the contents are empty.

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
One controller rewinds either the native input head or a selected work-tape head. It first moves
left, scans left through nonblank cells, then moves right and halts. The initial left move handles
a head starting on the right blank boundary, including when the contents are empty.
This file defines a Turing machine that can rewind one tape in the sense of resetting the tape head
to the start of the tape contents:
If the tape contents are contiguous starting from the initial head position to the right and the
head is positioned one cell right of the contents, then this machine will move the head to the
leftmost non-blank cell.
It first moves one cell left, scans left through non-blank cells, then moves right and halts.
This proceduce also works when the tape is empty.

are allowed. Only the input head and control state change. -/
lemma runFrom_input (cfg : Cfg k Symbol State input) :
(rewind .input).runFrom (inputCfg cfg (some .start) cfg.inputPos)
(cfg.inputPos.val - 1 + 2) = inputCfg cfg none 1 := by

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.

Is the -1 useful?

/-!
# Halting with the input head rewound

`rewindInput` follows an arbitrary machine with the native-input rewind controller. It preserves

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
`rewindInput` follows an arbitrary machine with the native-input rewind controller. It preserves
`rewindInput` establishes "rewound input normal form" for a Turing machine: It preserves

Comment on lines +33 to +34
(u : ℕ) (hhalt : (tm.runFrom cfg u).state = none)
(hactive : ∀ m < u, (tm.runFrom cfg m).state ≠ none) :

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.

I saw this multiple times now (the step where the machine halts) - maybe we should create a definition for that?

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.

2 participants