Langlib

Langlib.Automata.Turing.DSL.TakeWhileNeSepMachine

TakeWhile (· ≠ sep) is Block-Realizable #

We prove List.takeWhile (· ≠ sep) is block-realizable by showing:

takeWhile (· ≠ sep) = reverse ∘ dropFromLastSep sep ∘ reverse

and proving dropFromLastSep sep is block-realizable via a simple 7-state TM0 machine that iteratively scans for sep and erases the block prefix up to (and including) the first sep, repeating until no sep remains.

Key results #

Mathematical lemmas #

theorem takeWhile_eq_rev_dropFromLastSep_rev' {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (l : List Γ) :
List.takeWhile (fun (x : Γ) => !decide (x = sep)) l = (dropFromLastSep sep l.reverse).reverse
theorem takeWhile_eq_comp_rev_drop_rev {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) :
(fun (l : List Γ) => List.takeWhile (fun (x : Γ) => !decide (x = sep)) l) = List.reverse ∘ dropFromLastSep sep ∘ List.reverse

dropUntilFirstSep #

def dropUntilFirstSep {Γ : Type} [DecidableEq Γ] (sep : Γ) :
List Γ → List Γ

Drop everything up to and including the FIRST occurrence of sep. If sep ∉ l, returns [].

Equations
Instances For
    theorem dropUntilFirstSep_length_lt {Γ : Type} [DecidableEq Γ] (sep : Γ) (block : List Γ) (hmem : sep ∈ block) :
    (dropUntilFirstSep sep block).length < block.length
    theorem dropUntilFirstSep_ne_default {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (block : List Γ) (hblock : ∀ g ∈ block, g ≠ default) (g : Γ) :
    g ∈ dropUntilFirstSep sep block → g ≠ default
    theorem dropUntilFirstSep_append_cons {Γ : Type} [DecidableEq Γ] (sep : Γ) (left right : List Γ) (hleft : ∀ g ∈ left, g ≠ sep) :
    dropUntilFirstSep sep (left ++ sep :: right) = right
    theorem dropFromLastSep_eq_of_dropUntilFirstSep {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (block : List Γ) (hmem : sep ∈ block) :
    theorem block_first_sep_decomp {Γ : Type} [DecidableEq Γ] (sep : Γ) (block : List Γ) (hmem : sep ∈ block) :
    ∃ (pfx : List Γ) (rest : List Γ), block = pfx ++ sep :: rest ∧ (∀ g ∈ pfx, g ≠ sep) ∧ dropUntilFirstSep sep block = rest

    Machine definition #

    inductive DFLState :

    State type for the dropFromLastSep TM0 machine. Only 7 plain states.

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

      Key tape lemma #

      Phase lemmas #

      theorem dfl_scan_right {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (_hsep : sep ≠ default) (L pfx rest : List Γ) (hpfx_nsep : ∀ g ∈ pfx, g ≠ sep) (hpfx_nd : ∀ g ∈ pfx, g ≠ default) :
      theorem dfl_erase_loop {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (_hsep : sep ≠ default) (pfx rest : List Γ) (hpfx_nsep : ∀ g ∈ pfx, g ≠ sep) (hpfx_nd : ∀ g ∈ pfx, g ≠ default) :

      Combined iteration lemmas #

      theorem dfl_one_cycle {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (hsep : sep ≠ default) (block' suffix : List Γ) (hblock : ∀ g ∈ block', g ≠ default) (hmem : sep ∈ block') :
      theorem dfl_no_sep_cycle {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (hsep : sep ≠ default) (block' suffix : List Γ) (hblock : ∀ g ∈ block', g ≠ default) (hnot : sep ∉ block') :

      Full computation #

      theorem dfl_step_done {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (T : Turing.Tape Γ) :

      The machine halts in state done.

      theorem dfl_full_reaches {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (sep : Γ) (hsep : sep ≠ default) (block suffix : List Γ) (hblock : ∀ g ∈ block, g ≠ default) (_hsuffix : ∀ g ∈ suffix, g ≠ default) :

      Main results #

      theorem tm0_dropFromLastSep_direct {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (sep : Γ) (hsep : sep ≠ default) :

      dropFromLastSep sep is block-realizable.

      theorem tm0_takeWhileNeSep' {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (sep : Γ) (hsep : sep ≠ default) :
      TM0RealizesBlock Γ (List.takeWhile fun (x : Γ) => !decide (x = sep))

      takeWhile (· ≠ sep) is block-realizable.