Langlib

Langlib.Automata.Turing.DSL.InnerBlockRealizability

Inner-Block Realizability #

This file shows that any TM0RealizesBlockSep Γ sep f can be lifted to operate on an inner block of a two-separator tape, preserving the prefix.

Main definitions #

Main result #

Strategy #

The construction composes five sub-machines (three distinct):

  1. Reverse (sep₁-delimited): reverses the outer block, bringing inner.reverse to the front where the left boundary is blank.
  2. Reverse (sep₂-delimited): un-reverses the inner block back to inner.
  3. Apply f (sep₂-delimited): applies f to the inner block.
  4. Reverse (sep₂-delimited): reverses f(inner) back.
  5. Reverse (sep₁-delimited): reverses the outer block, restoring prefix.

Steps 2–4 are composed into reverse ∘ f ∘ reverse via tm0RealizesBlockSep_comp, producing a single TM0RealizesBlockSep Γ sep₂ machine. The full construction is then a three-machine composition: reverse(sep₁) → revFRev(sep₂) → reverse(sep₁).

Inner Block Realizability Definition #

def TM0RealizesInnerBlockSep (Γ : Type) [Inhabited Γ] (sep₁ sep₂ : Γ) (f : List ΓList Γ) :

A TM0 machine that applies f to the inner block of a two-separator tape.

Given tape pfx ++ [sep₂] ++ inner ++ [sep₁] ++ suffix, produces pfx ++ [sep₂] ++ f(inner) ++ [sep₁] ++ suffix.

The prefix pfx, both separators sep₁ and sep₂, and the suffix are all preserved. Only the inner block between sep₂ and sep₁ is modified.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def TM0RealizesInnerBlockSepAnySuffix (Γ : Type) [Inhabited Γ] (sep₁ sep₂ : Γ) (f : List ΓList Γ) :

    Strong suffix version of TM0RealizesInnerBlockSep.

    The machine applies f to the block between sep₂ and sep₁, preserving the entire suffix after sep₁ without requiring it to be blank-free.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem tm0RealizesInnerBlockSep_of_anySuffix {Γ : Type} [Inhabited Γ] {sep₁ sep₂ : Γ} {f : List ΓList Γ} (hf : TM0RealizesInnerBlockSepAnySuffix Γ sep₁ sep₂ f) :
      TM0RealizesInnerBlockSep Γ sep₁ sep₂ f

      Forget that an inner-block machine is suffix-opaque.

      def TM0RealizesInnerBlockDefaultSep (Γ : Type) [Inhabited Γ] (sep₂ : Γ) (f : List ΓList Γ) :

      A default-delimited version of TM0RealizesInnerBlockSep.

      This is the shape needed by invariant while-loop bodies: the whole active block is default-delimited, and an internal separator sep₂ splits the preserved prefix from the inner block transformed by f.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def TM0RealizesInnerBlockDefaultViaSep (Γ : Type) [Inhabited Γ] (tmp sep₂ : Γ) (f : List ΓList Γ) :

        Default-delimited inner-block realizability using a temporary non-default outer separator.

        The extra separator tmp is not part of the input/output tape. It is the marker used internally to turn the outer default boundary into a real separator, run the non-default prefix/suffix lift, then restore the boundary to default. The contract records exactly the freshness facts needed for that construction.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          List Reversal Helpers #

          theorem reverse_append_cons {α : Type} (l₁ : List α) (a : α) (l₂ : List α) :
          (l₁ ++ a :: l₂).reverse = l₂.reverse ++ a :: l₁.reverse

          Reversing l₁ ++ a :: l₂ gives l₂.reverse ++ a :: l₁.reverse.

          theorem forall_mem_append_cons {α : Type} {P : αProp} {a : α} {l₁ l₂ : List α} :
          (∀ gl₁ ++ a :: l₂, P g) (∀ gl₁, P g) P a gl₂, P g

          All elements of l₁ ++ a :: l₂ satisfy P iff elements of l₁, a, and elements of l₂ all satisfy P.

          Boundary replacement helper #

          noncomputable def boundaryReplaceMachine {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (target repl : Γ) :

          Scan to the first occurrence of target, replace it by repl, then rewind to the left edge of the active block.

          Equations
          Instances For
            theorem boundaryReplace_rewind_loop {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (target repl : Γ) (revBlock acc : List Γ) (hrevBlock : xrevBlock, x default) :
            Turing.Reaches (Turing.TM0.step (boundaryReplaceMachine target repl)) { q := BoundaryReplaceSt.rewind, Tape := { head := revBlock.headI, left := Turing.ListBlank.mk revBlock.tail, right := Turing.ListBlank.mk acc } } { q := BoundaryReplaceSt.rewind, Tape := { head := default, left := Turing.ListBlank.mk [], right := Turing.ListBlank.mk (revBlock.reverse ++ acc) } }
            theorem boundaryReplace_scan_gen {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (target repl : Γ) (block suffix revL : List Γ) (hblock_default : gblock, g default) (hblock_target : gblock, g target) (hrevL_default : grevL, g default) :
            Turing.Reaches (Turing.TM0.step (boundaryReplaceMachine target repl)) { q := BoundaryReplaceSt.scan, Tape := { head := (block ++ target :: suffix).headI, left := Turing.ListBlank.mk revL, right := Turing.ListBlank.mk (block ++ target :: suffix).tail } } { q := BoundaryReplaceSt.done, Tape := Turing.Tape.mk₁ (revL.reverse ++ block ++ repl :: suffix) }
            theorem boundaryReplace_reaches {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (target repl : Γ) (block suffix : List Γ) (hblock_default : gblock, g default) (hblock_target : gblock, g target) :
            Turing.Reaches (Turing.TM0.step (boundaryReplaceMachine target repl)) (Turing.TM0.init (block ++ target :: suffix)) { q := BoundaryReplaceSt.done, Tape := Turing.Tape.mk₁ (block ++ repl :: suffix) }
            theorem tm0_boundaryReplace {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (target repl : Γ) (block suffix : List Γ) :
            (∀ gblock, g default)(∀ gblock, g target)(TM0Seq.evalCfg (boundaryReplaceMachine target repl) (block ++ target :: suffix)).Dom ∀ (h : (TM0Seq.evalCfg (boundaryReplaceMachine target repl) (block ++ target :: suffix)).Dom), ((TM0Seq.evalCfg (boundaryReplaceMachine target repl) (block ++ target :: suffix)).get h).Tape = Turing.Tape.mk₁ (block ++ repl :: suffix)
            theorem tm0RealizesBlock_toBlockSep {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep : Γ} {f : List ΓList Γ} (hf : TM0RealizesBlock Γ f) :

            Any default-delimited block machine can be run before an arbitrary non-default separator by temporarily replacing that separator with default, running the machine, and restoring the separator.

            Any strong default-delimited block machine can be run before an arbitrary non-default separator by temporarily replacing that separator with default, running the machine, and restoring the separator.

            Unlike tm0RealizesBlock_toBlockSep, this preserves an entirely opaque suffix: the wrapped machine must already be a strong TM0RealizesBlockAnySuffix machine, and the boundary replacement machines only touch the first boundary cell.

            Composition: reverse ∘ f ∘ reverse #

            theorem tm0RealizesBlockSep_revFRev {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep : Γ} {f : List ΓList Γ} (hf : TM0RealizesBlockSep Γ sep f) (hf_nd : ∀ (block : List Γ), (∀ gblock, g default)gf block, g default) (hf_nsep : ∀ (block : List Γ), (∀ gblock, g sep)gf block, g sep) :

            If f is TM0RealizesBlockSep Γ sep, then reverse ∘ f ∘ reverse is also TM0RealizesBlockSep Γ sep, provided f preserves the non-defaultness and non-separator properties.

            This is a reusable sub-machine composition: it takes any block-sep-realizable function and produces a machine for the "conjugated" function reverse ∘ f ∘ reverse.

            theorem tm0RealizesBlockSepAnySuffix_revFRev {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep : Γ} {f : List ΓList Γ} (hf : TM0RealizesBlockSepAnySuffix Γ sep f) (hf_nd : ∀ (block : List Γ), (∀ gblock, g default)gf block, g default) (hf_nsep : ∀ (block : List Γ), (∀ gblock, g sep)gf block, g sep) :

            Strong suffix version of tm0RealizesBlockSep_revFRev. This is the form needed by prefix/suffix lifting when the preserved suffix after sep may itself contain default.

            theorem tm0_appendList_blockSep_anySuffix {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep : Γ} (suf : List Γ) (hsuf_nd : gsuf, g default) (hsuf_nsep : gsuf, g sep) :
            TM0RealizesBlockSepAnySuffix Γ sep fun (block : List Γ) => block ++ suf

            Appending a fixed non-default, non-separator list is realizable before a separator, with no invariant on the suffix. This follows by reversing the active block, prepending the reversed fixed suffix, and reversing back.

            theorem tm0_appendList_blockSep {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep : Γ} (suf : List Γ) (hsuf_nd : gsuf, g default) (hsuf_nsep : gsuf, g sep) :
            TM0RealizesBlockSep Γ sep fun (block : List Γ) => block ++ suf

            Main Theorem: Lifting to Inner Block #

            theorem tm0RealizesBlockSep_toInner_nondefault {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep₁ sep₂ : Γ} {f : List ΓList Γ} (hsep₁ : sep₁ default) (hsep₂ : sep₂ default) (h₁₂ : sep₁ sep₂) (hf : TM0RealizesBlockSep Γ sep₂ f) (hf_nd : ∀ (block : List Γ), (∀ gblock, g default)gf block, g default) (hf_nsep : ∀ (block : List Γ), (∀ gblock, g sep₂)gf block, g sep₂) :
            TM0RealizesInnerBlockSep Γ sep₁ sep₂ f
            theorem tm0RealizesBlockSepAnySuffix_toInner {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep₁ sep₂ : Γ} {f : List ΓList Γ} (hsep₂ : sep₂ default) (h₁₂ : sep₁ sep₂) (hf : TM0RealizesBlockSepAnySuffix Γ sep₂ f) (hf_nd : ∀ (block : List Γ), (∀ gblock, g default)gf block, g default) (hf_nsep : ∀ (block : List Γ), (∀ gblock, g sep₂)gf block, g sep₂) :

            Strong suffix version of the prefix/suffix lift.

            This is the construction that works uniformly for sep₁ = default and sep₁ ≠ default: after reversing the outer block, the middle machine runs on inner.reverse ++ sep₂ :: pfx.reverse ++ sep₁ :: suffix, so the hypothesis on f must be TM0RealizesBlockSepAnySuffix.

            theorem tm0RealizesBlockSep_toInnerOuterSep {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep₁ sep₂ : Γ} {f : List ΓList Γ} (hsep₁ : sep₁ default) (hsep₂ : sep₂ default) (h₁₂ : sep₁ sep₂) (hf : TM0RealizesBlockSep Γ sep₂ f) (hf_nd : ∀ (block : List Γ), (∀ gblock, g default)gf block, g default) (hf_nsep : ∀ (block : List Γ), (∀ gblock, g sep₂)gf block, g sep₂) :
            TM0RealizesInnerBlockSep Γ sep₁ sep₂ f

            Separator-delimited version of the default-boundary lift.

            This is the form to use when the outer delimiter after the inner block should be a real separator sep₁, not the tape blank. The tape shape is pfx ++ sep₂ :: inner ++ sep₁ :: suffix.

            theorem tm0RealizesBlockSep_toInnerDefaultViaSep {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {tmp sep₂ : Γ} {f : List ΓList Γ} (htmp : tmp default) (hsep₂ : sep₂ default) (htmp₂ : tmp sep₂) (hf : TM0RealizesBlockSep Γ sep₂ f) (hf_nd : ∀ (block : List Γ), (∀ gblock, g default)gf block, g default) (hf_nsep : ∀ (block : List Γ), (∀ gblock, g sep₂)gf block, g sep₂) :

            Default-boundary inner-block lift through a temporary real separator.

            Operationally this is:

            1. rewrite the boundary default after inner to tmp;
            2. use tm0RealizesBlockSep_toInner_nondefault with outer separator tmp;
            3. rewrite the resulting boundary tmp back to default.

            The freshness assumptions on tmp are carried by TM0RealizesInnerBlockDefaultViaSep, because the temporary marker must not be confused with data in the prefix, inner block, or transformed inner block.

            theorem tm0RealizesBlockSep_toInnerDefault {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] {sep₂ : Γ} {f : List ΓList Γ} (hsep₂ : sep₂ default) (hf : TM0RealizesBlockSep Γ sep₂ f) (hf_nd : ∀ (block : List Γ), (∀ gblock, g default)gf block, g default) (hf_nsep : ∀ (block : List Γ), (∀ gblock, g sep₂)gf block, g sep₂) :

            Default-delimited inner-block lift with no suffix after the final blank.

            The construction is the same three-machine composition: reverse before the outer default, run reverse ∘ f ∘ reverse before the internal separator, then reverse before the outer default again. The middle phase is applied to a list without the trailing default; evalCfg_append_default identifies that with the actual intermediate tape.