Langlib

Langlib.Grammars.Indexed.Shrinking.Scope

Flag scopes in normal-form indexed parse trees #

This file formalizes the scope construction used in Gilman's shrinking lemma. For one occurrence in the root flag stack, NFParse.scopeAt follows every branch until that occurrence is consumed. Its ordered frontier consists of terminals and of the continuation parses immediately below the consuming pop. Carrying those continuation parses makes both the frontier derivation and the corresponding factorization of the terminal yield explicit.

Reference #

inductive IndexedGrammar.ScopePiece {T : Type} (g : IndexedGrammar T) (suffix : List g.flag) :

One leaf of a flag scope. A pending leaf remembers the complete parse below the pop which consumed the distinguished flag occurrence.

Instances For
    def IndexedGrammar.ScopePiece.word {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} :
    g.ScopePiece suffixList T

    The terminal factor contributed by one scope-frontier leaf.

    Equations
    Instances For
      def IndexedGrammar.ScopePiece.symbol {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} :
      g.ScopePiece suffixg.nt T

      The unstacked sentential symbol displayed by a scope-frontier leaf.

      Equations
      Instances For
        def IndexedGrammar.ScopePiece.asISym {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} :
        g.ScopePiece suffixg.ISym

        Interpret a scope piece as an indexed-grammar sentential symbol.

        Equations
        Instances For
          @[simp]
          theorem IndexedGrammar.ScopePiece.word_terminal {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (a : T) :
          @[simp]
          theorem IndexedGrammar.ScopePiece.word_pending {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} {A : g.nt} {w : List T} (p : g.NFParse A suffix w) :
          (pending p).word = w
          @[simp]
          @[simp]
          theorem IndexedGrammar.ScopePiece.symbol_pending {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} {A : g.nt} {w : List T} (p : g.NFParse A suffix w) :
          @[simp]
          theorem IndexedGrammar.ScopePiece.asISym_pending {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} {A : g.nt} {w : List T} (p : g.NFParse A suffix w) :
          theorem IndexedGrammar.ScopePiece.word_ne_nil {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (piece : g.ScopePiece suffix) :
          piece.word []
          def IndexedGrammar.NFParse.scopeAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) (k : ) :
          List (g.ScopePiece (List.drop (k + 1) sigma))

          Cut a concrete parse at the first consumption of the root-stack occurrence numbered k. The remaining stack below that occurrence is sigma.drop (k + 1), which is exactly the stack carried by pending frontier leaves.

          Equations
          Instances For
            def IndexedGrammar.NFParse.scopeWord {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (pieces : List (g.ScopePiece suffix)) :

            Concatenate the terminal factors represented by a scope frontier.

            Equations
            Instances For
              def IndexedGrammar.NFParse.scopeSymbols {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (pieces : List (g.ScopePiece suffix)) :
              List (g.nt T)

              Forget continuation certificates and retain the unstacked frontier word.

              Equations
              Instances For

                Interpret an unstacked frontier word as a sentential form.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  def IndexedGrammar.NFParse.scopeForm {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (pieces : List (g.ScopePiece suffix)) :

                  Interpret a scope frontier at the concrete suffix carried by its pieces.

                  Equations
                  Instances For
                    @[simp]
                    theorem IndexedGrammar.NFParse.scopeWord_cons {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (piece : g.ScopePiece suffix) (pieces : List (g.ScopePiece suffix)) :
                    scopeWord (piece :: pieces) = piece.word ++ scopeWord pieces
                    @[simp]
                    theorem IndexedGrammar.NFParse.scopeWord_append {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (left right : List (g.ScopePiece suffix)) :
                    scopeWord (left ++ right) = scopeWord left ++ scopeWord right
                    @[simp]
                    theorem IndexedGrammar.NFParse.scopeSymbols_length {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (pieces : List (g.ScopePiece suffix)) :
                    (scopeSymbols pieces).length = pieces.length
                    theorem IndexedGrammar.NFParse.scopeWord_scopeAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) (k : ) :

                    Cutting a scope partitions, but never changes, the terminal yield.

                    theorem IndexedGrammar.NFParse.derives_scopeWord {T : Type} {g : IndexedGrammar T} {suffix : List g.flag} (pieces : List (g.ScopePiece suffix)) :
                    g.Derives (scopeForm pieces) (List.map (fun (a : T) => ISym.terminal a) (scopeWord pieces))

                    Independently finish every pending scope piece.

                    theorem IndexedGrammar.NFParse.derives_scopeForm_scopeAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) (k : ) :

                    The concrete parse derives its scope frontier at the suffix below the distinguished occurrence.

                    theorem IndexedGrammar.NFParse.derives_unstackedForm_scopeAt {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) (k : ) :

                    Remove the common suffix below a scope. The same rule certificates derive the unstacked frontier from the prefix ending at the distinguished occurrence.

                    def IndexedGrammar.NFParse.beta {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) :
                    List (g.nt T)

                    Gilman's beta(p): the full terminal yield at an empty stack, and the unstacked frontier of the top flag scope at a nonempty stack.

                    Equations
                    Instances For
                      def IndexedGrammar.NFParse.betaPieces {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) :
                      List (g.ScopePiece sigma.tail)

                      The concrete scope pieces whose symbol word is beta. At an empty stack the pieces are the individual terminal leaves.

                      Equations
                      Instances For
                        @[simp]
                        theorem IndexedGrammar.NFParse.scopeSymbols_betaPieces {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) :
                        @[simp]
                        theorem IndexedGrammar.NFParse.scopeWord_betaPieces {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) :
                        @[simp]
                        theorem IndexedGrammar.NFParse.betaPieces_length {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) :
                        theorem IndexedGrammar.NFParse.derives_beta {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) :

                        Every parse-tree beta word is derivable from its unstacked source.

                        theorem IndexedGrammar.NFParse.derives_scopeWord_of_derives_unstacked {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {x : List (g.nt T)} (hder : g.Derives (betaSource A sigma) (unstackedForm x)) (kept : List (g.ScopePiece sigma.tail)) (hkept : scopeSymbols kept = x) :
                        g.Derives [ISym.indexed A sigma] (List.map (fun (a : T) => ISym.terminal a) (scopeWord kept))

                        A derivable unstacked subfrontier can be reattached to the concrete suffix and its surviving pieces can then finish their original parses.

                        @[simp]
                        theorem IndexedGrammar.NFParse.beta_length_of_empty {T : Type} {g : IndexedGrammar T} {A : g.nt} {w : List T} (p : g.NFParse A [] w) :
                        theorem IndexedGrammar.NFParse.beta_length_eq_yield_of_stack_eq_nil {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) (hstack : sigma = []) :
                        @[simp]
                        theorem IndexedGrammar.NFParse.beta_length_of_nonempty {T : Type} {g : IndexedGrammar T} {A : g.nt} {f : g.flag} {suffix : List g.flag} {w : List T} (p : g.NFParse A (f :: suffix) w) :
                        theorem IndexedGrammar.NFParse.beta_length_eq_scopeAt_zero_of_stack_ne_nil {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {w : List T} (p : g.NFParse A sigma w) (hstack : sigma []) :
                        @[simp]
                        theorem IndexedGrammar.NFParse.beta_binary {T : Type} {g : IndexedGrammar T} {A B C : g.nt} {sigma : List g.flag} {u v : List T} {r : IRule T g.nt g.flag} (hr : r g.rules) (hlhs : r.lhs = A) (hc : r.consume = none) (hrhs : r.rhs = [IRhsSymbol.nonterminal B none, IRhsSymbol.nonterminal C none]) (left : g.NFParse B sigma u) (right : g.NFParse C sigma v) :
                        (binary hr hlhs hc hrhs left right).beta = left.beta ++ right.beta
                        @[simp]
                        theorem IndexedGrammar.NFParse.beta_pop {T : Type} {g : IndexedGrammar T} {A B : g.nt} {f : g.flag} {suffix : List g.flag} {w : List T} {r : IRule T g.nt g.flag} (hr : r g.rules) (hlhs : r.lhs = A) (hc : r.consume = some f) (hrhs : r.rhs = [IRhsSymbol.nonterminal B none]) (rest : g.NFParse B suffix w) :
                        (pop hr hlhs hc hrhs rest).beta = [Sum.inl B]
                        @[simp]
                        theorem IndexedGrammar.NFParse.beta_terminal {T : Type} {g : IndexedGrammar T} {A : g.nt} {sigma : List g.flag} {a : T} {r : IRule T g.nt g.flag} (hr : r g.rules) (hlhs : r.lhs = A) (hc : r.consume = none) (hrhs : r.rhs = [IRhsSymbol.terminal a]) :
                        (terminal hr hlhs hc hrhs).beta = [Sum.inr a]
                        @[simp]
                        theorem IndexedGrammar.NFParse.beta_length_push_empty {T : Type} {g : IndexedGrammar T} {A B : g.nt} {f : g.flag} {w : List T} {r : IRule T g.nt g.flag} (hr : r g.rules) (hlhs : r.lhs = A) (hc : r.consume = none) (hrhs : r.rhs = [IRhsSymbol.nonterminal B (some f)]) (rest : g.NFParse B [f] w) :
                        (push hr hlhs hc hrhs rest).beta.length = w.length
                        @[simp]
                        theorem IndexedGrammar.NFParse.beta_length_push_nonempty {T : Type} {g : IndexedGrammar T} {A B : g.nt} {pushed top : g.flag} {suffix : List g.flag} {w : List T} {r : IRule T g.nt g.flag} (hr : r g.rules) (hlhs : r.lhs = A) (hc : r.consume = none) (hrhs : r.rhs = [IRhsSymbol.nonterminal B (some pushed)]) (rest : g.NFParse B (pushed :: top :: suffix) w) :
                        (push hr hlhs hc hrhs rest).beta.length = (rest.scopeAt 1).length