Documentation

Complexitylib.Interop.Mathlib.TM0.Guard.Internal

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.run_add (M : BinaryMachine) (t u : ℕ) (c : M.Config) :
M.run (t + u) c = (M.run t c).bind (M.run u)

Consecutive source runs compose by option bind.

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.

Moving right consumes the next explicit tape cell.

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.

Rewinding crosses the input once and returns from the preceding blank.

Tag a source configuration with the execution phase.

Equations
Instances For

    The execution phase preserves one source transition.

    theorem Complexity.MathlibTM0.BinaryMachine.Guard.run_lift (M : BinaryMachine) {σ : Type} [Fintype σ] (D : DFA Bool σ) (t : ℕ) (c : M.Config) :
    (M.guarded D).run t (liftCfg M D c) = Option.map (liftCfg M D) (M.run t c)

    The execution phase preserves any finite source run.

    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) :
    (M.guarded D).OutputsWithin w output (2 * w.length + time + 2)

    A valid input incurs just the scan-and-rewind overhead.

    A rejected input halts at the first blank with empty output.