TM Combinators #
This file provides TM constructions for composing machines, used to prove closure properties of complexity classes.
Main definitions #
TM.unionTM— Giventm₁ : TM n₁decidingL₁andtm₂ : TM n₂decidingL₂, construct aTM (n₁ + 1 + n₂)that decidesL₁ ∪ L₂.TM.complementTM— Given a TM decidingL, construct a TM (with the same number of work tapes) decidingLᶜby flipping the output bit.TM.seqTM— Sequential composition: runtm₁to completion, thentm₂on the same tapes.TM.ifTM— Conditional branching: run a test machine, then branch to a "then" or "else" machine based on its output.TM.loopTM— Loop combinator: repeatedly run a body machine then a test machine, halting when the test outputsΓ.one.TM.scannerTM— Generic finite-state scanner: fold a finite-state transition function over the input bits and emit a final symbol.TM.retargetInput— GivenM : TM k, construct aTM (k + 1)that runsMbut reads its "input" from work tapekinstead of the input tape.
Design #
The union machine has three phases:
- Phase 1: Simulate
tm₁, redirecting its output to work tapen₁(a "fake output" tape). The real output tape stays pristine. - Transition: Rewind the fake output to cell 1 and check the result.
If
Γ.one(tm₁ accepted), writeΓ.oneto the real output and halt. Otherwise rewind the input tape and reset Phase-2 tapes to cell 0. - Phase 2: Simulate
tm₂using work tapesn₁+1..n₁+n₂and the real output tape.
Work tape layout (0-indexed) #
0 .. n₁-1— Phase 1's work tapes (mirrorstm₁.work)n₁— Phase 1's redirected output (mirrorstm₁.output)n₁+1 .. n₁+n₂— Phase 2's work tapes (mirrorstm₂.work)
State space #
Q₁ ⊕ UnionPhase ⊕ Q₂ where UnionPhase encodes the four transition states
between Phase 1 and Phase 2.