Langlib

Langlib.Automata.Turing.DSL.ReverseBlockMachine

TM0 Reverse Block Machine #

The machine is parameterized by a separator sep that marks the right end of the block. It works on any separator as long as block elements are distinct from both default (the tape blank) and sep.

Key results #

State type #

Instances For
    Instances For
      Equations
      • One or more equations did not get rendered due to their size.
      @[reducible, inline]
      abbrev RevBlock.RSt (Γ : Type) :
      Equations
      Instances For

        Machine definition #

        noncomputable def RevBlock.MSep (Γ : Type) [Inhabited Γ] [DecidableEq Γ] (sep : Γ) :

        Reverse-block machine parameterized by separator sep.

        • grab / shifting / returning use sep to detect the right block boundary and as the temporary "erased" marker when a cell is grabbed.
        • rewind uses default to find the left edge of the tape.
        Equations
        Instances For
          noncomputable def RevBlock.M (Γ : Type) [Inhabited Γ] [DecidableEq Γ] :

          The original machine with default as separator.

          Equations
          Instances For

            Tape.mk₂ helpers #

            theorem RevBlock.mk₂_write {Γ : Type} [Inhabited Γ] (a : Γ) (L : List Γ) (x : Γ) (R : List Γ) :
            theorem RevBlock.mk₂_head {Γ : Type} [Inhabited Γ] (L : List Γ) (x : Γ) (R : List Γ) :

            Return loop #

            theorem RevBlock.return_loop {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep carry h : Γ) (elems L_orig R : List Γ) (hh : h sep) (helems : yelems, y sep) :
            Turing.Reaches (Turing.TM0.step (MSep Γ sep)) { q := Sum.inl (carry, CarryPhase.returning), Tape := Turing.Tape.mk₂ (elems ++ sep :: L_orig) (h :: R) } { q := Sum.inl (carry, CarryPhase.returning), Tape := Turing.Tape.mk₂ L_orig (sep :: elems.reverse ++ h :: R) }

            Return loop: from returning(carry), move left through non-sep head elements. Each step pops from the left and pushes the old head onto the right.

            Shift-to-grab #

            theorem RevBlock.shift_to_grab {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep carry : Γ) (rest shifted L_orig suffix : List Γ) (hcarry : carry sep) (hrest : yrest, y sep) (hshifted : yshifted, y sep) :
            Turing.Reaches (Turing.TM0.step (MSep Γ sep)) { q := Sum.inl (carry, CarryPhase.shifting), Tape := Turing.Tape.mk₂ (shifted ++ sep :: L_orig) (rest ++ sep :: suffix) } { q := Sum.inr NoCarryPhase.grab, Tape := Turing.Tape.mk₂ ((carry :: rest).getLast :: L_orig) (shifted.reverse ++ (carry :: rest).dropLast ++ sep :: suffix) }

            One iteration #

            theorem RevBlock.one_iteration {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep x : Γ) (rest L_orig suffix : List Γ) (hx : x sep) (hrest : yrest, y sep) :
            Turing.Reaches (Turing.TM0.step (MSep Γ sep)) { q := Sum.inr NoCarryPhase.grab, Tape := Turing.Tape.mk₂ L_orig (x :: rest ++ sep :: suffix) } { q := Sum.inr NoCarryPhase.grab, Tape := Turing.Tape.mk₂ ((x :: rest).getLast :: L_orig) ((x :: rest).dropLast ++ sep :: suffix) }

            Iteration loop #

            theorem RevBlock.iteration_loop {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (block suffix : List Γ) (hblock : yblock, y sep) :
            Turing.Reaches (Turing.TM0.step (MSep Γ sep)) { q := Sum.inr NoCarryPhase.grab, Tape := Turing.Tape.mk₂ [] (block ++ sep :: suffix) } { q := Sum.inr NoCarryPhase.grab, Tape := Turing.Tape.mk₂ block (sep :: suffix) }

            Rewind loop #

            theorem RevBlock.rewind_loop {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep s : Γ) (rest R_rest : List Γ) (hs : s default) (hrest : yrest, y default) :

            Rewind uses default (not sep) to find the left tape edge.

            Rewind phase #

            theorem RevBlock.rewind_phase {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (block suffix : List Γ) (hblock_nd : yblock, y default) (hblock_nsep : yblock, y sep) :
            Turing.Reaches (Turing.TM0.step (MSep Γ sep)) { q := Sum.inr NoCarryPhase.grab, Tape := Turing.Tape.mk₂ block (sep :: suffix) } { q := Sum.inr NoCarryPhase.rewindDone, Tape := Turing.Tape.mk₂ [] (block.reverse ++ sep :: suffix) }

            Full computation #

            theorem RevBlock.full_reaches {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (block suffix : List Γ) (hblock_nd : yblock, y default) (hblock_nsep : yblock, y sep) :
            Turing.Reaches (Turing.TM0.step (MSep Γ sep)) (Turing.TM0.init (block ++ sep :: suffix)) { q := Sum.inr NoCarryPhase.rewindDone, Tape := Turing.Tape.mk₁ (block.reverse ++ sep :: suffix) }
            theorem RevBlock.step_rewindDone {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (T : Turing.Tape Γ) :

            Backward compatibility wrappers #

            theorem RevBlock.full_reaches_default {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (block suffix : List Γ) (hblock : yblock, y default) (_hsuf : ysuffix, y default) :