Correctness of the DFA input guard #
The scan takes one step per input bit. On acceptance, returning to the start takes another input-length plus two steps. Rejection halts with empty output.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.step_scan_bit
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
(q : σ)
(T : Turing.Tape M.Alphabet)
(b : Bool)
(h : M.readBit T.head = some b)
:
(M.guarded D).step { q := GuardState.scan q, Tape := T } = some { q := GuardState.scan (D.step q b), Tape := Turing.Tape.move Turing.Dir.right T }
Reading a bit advances the DFA and moves right.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.move_right
(M : BinaryMachine)
(L R : List M.Alphabet)
(a : M.Alphabet)
:
Moving right consumes the next explicit tape cell.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.move_left
(M : BinaryMachine)
(L R : List M.Alphabet)
(a : M.Alphabet)
:
Moving left exposes the nearest cell on the left.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.scan
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
(w : List Bool)
(L : List M.Alphabet)
(q : σ)
:
The guard scans an explicit binary suffix without changing the tape.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.rewind
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
(w : List Bool)
(R : List M.Alphabet)
:
(M.guarded D).run (w.length + 1)
{ q := GuardState.rewind, Tape := Turing.Tape.move Turing.Dir.left (Turing.Tape.mk₂ (List.map M.bit w) R) } = some { q := GuardState.run default, Tape := Turing.Tape.mk₂ [] ((List.map M.bit w).reverse ++ R) }
Rewinding crosses the input once and returns from the preceding blank.
def
Complexity.MathlibTM0.BinaryMachine.Guard.liftCfg
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
(c : M.Config)
:
Tag a source configuration with the execution phase.
Equations
- Complexity.MathlibTM0.BinaryMachine.Guard.liftCfg M D c = { q := Complexity.MathlibTM0.BinaryMachine.GuardState.run c.q, Tape := c.Tape }
Instances For
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.step_lift
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
(c : M.Config)
:
The execution phase preserves one source transition.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.prepare
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
{w : List Bool}
(hw : w ∈ D.accepts)
:
An accepted input is restored at the source's initial state in linear time.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.accepted
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
{w output : List Bool}
{time : ℕ}
(hw : w ∈ D.accepts)
(h : M.OutputsWithin w output time)
:
A valid input incurs just the scan-and-rewind overhead.
theorem
Complexity.MathlibTM0.BinaryMachine.Guard.rejected
(M : BinaryMachine)
{σ : Type}
[Fintype σ]
(D : DFA Bool σ)
{w : List Bool}
(hw : w ∉ D.accepts)
:
(M.guarded D).OutputsWithin w [] w.length
A rejected input halts at the first blank with empty output.