Langlib

Langlib.Grammars.Indexed.NormalForm.Aho.Scheduler.Invariant

Aho scheduler state and invariants #

Ghost tasks, cursor invariants, schedule reachability, and canonical endpoints.

Ghost annotations and the global scheduling invariant #

inductive IndexedGrammar.Aho.TaskMode {T : Type} {g : IndexedGrammar T} {A : g.nt} {stack : List g.flag} {w : List T} (p : g.NFParse A stack w) :

Whether a pending parse task must retain the compressed stack to its right. A plain task does not consume the top inherited occurrence; prefix closure then says it consumes no inherited occurrence. A live task does consume the top occurrence and must be scheduled against the next compressed-index token.

Instances For
    structure IndexedGrammar.Aho.ScheduleTask {T : Type} (g : IndexedGrammar T) (input : List T) :

    A pending parse task, together with the terminal position which owns its work-tape payload. The scheduler uses the left endpoint of the task's nonempty yield interval as owner.

    Instances For
      def IndexedGrammar.Aho.ScheduleTask.owner {T : Type} {g : IndexedGrammar T} {input : List T} (task : ScheduleTask g input) :
      Fin input.length

      The first terminal position in a pending task's nonempty yield.

      Equations
      Instances For
        def IndexedGrammar.Aho.ScheduleTask.workSym {T : Type} {g : IndexedGrammar T} {input : List T} (task : ScheduleTask g input) :

        Erase the ghost parse and retain the finite work symbol seen by the machine.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          structure IndexedGrammar.Aho.ScheduleIndex {T : Type} (g : IndexedGrammar T) [Fintype g.nt] (input : List T) :

          A compressed-index occurrence with its concrete denotation and terminal-position owner. Only the finite relation and mark survive ghost erasure.

          Instances For
            inductive IndexedGrammar.Aho.ScheduleAtom {T : Type} (g : IndexedGrammar T) [Fintype g.nt] (input : List T) :

            Ghost-annotated symbols used by the parse-directed scheduler.

            Instances For

              Owners of task/terminal payloads.

              Equations
              Instances For
                def IndexedGrammar.Aho.ScheduleAtom.indexOwner? {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} :
                ScheduleAtom g inputOption (Fin (10 * input.length))

                Owners of compressed-index payloads.

                Equations
                Instances For
                  def IndexedGrammar.Aho.ScheduleAtom.closeOwner? {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} :
                  ScheduleAtom g inputOption (Fin (10 * input.length))

                  The selected persistent-index owner charged by an open frame.

                  Equations
                  Instances For
                    structure IndexedGrammar.Aho.ScheduleCursor {T : Type} (g : IndexedGrammar T) [Fintype g.nt] (input : List T) :

                    A zipper over the ghost-annotated scheduler word.

                    Instances For
                      def IndexedGrammar.Aho.ScheduleCursor.word {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (cursor : ScheduleCursor g input) :
                      List (ScheduleAtom g input)

                      The complete ghost word.

                      Equations
                      Instances For
                        def IndexedGrammar.Aho.ScheduleCursor.erase {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (cursor : ScheduleCursor g input) :

                        Erase a ghost cursor to the finite machine cursor.

                        Equations
                        Instances For
                          @[simp]
                          @[simp]
                          theorem IndexedGrammar.Aho.ScheduleCursor.erase_word_length {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (cursor : ScheduleCursor g input) :
                          cursor.erase.word.length = cursor.word.length
                          def IndexedGrammar.Aho.ScheduleCursor.taskOwners {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (cursor : ScheduleCursor g input) :
                          List (Fin input.length)

                          Task/terminal owners present in the cursor.

                          Equations
                          Instances For
                            def IndexedGrammar.Aho.ScheduleCursor.indexOwners {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (cursor : ScheduleCursor g input) :
                            List (Fin (10 * input.length))

                            Compressed-index owners present in the cursor.

                            Equations
                            Instances For
                              def IndexedGrammar.Aho.ScheduleCursor.frameOwners {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (cursor : ScheduleCursor g input) :
                              List (Fin (10 * input.length))

                              Persistent-index owners currently charged by open $/close frames.

                              Equations
                              Instances For

                                Number of currently open $/close frames.

                                Equations
                                Instances For
                                  structure IndexedGrammar.Aho.ScheduleInvariant {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (cursor : ScheduleCursor g input) :

                                  Global invariant maintained by the compressed scheduler. Tasks are charged to terminal positions, while persistent physical blocks satisfy the 6|input| reusable-owner cap. shape_bound accounts for one task/index square per payload, two delimiters per open frame, and the fixed outer $/# pair.

                                  Instances For
                                    theorem IndexedGrammar.Aho.ScheduleInvariant.of_owner_nodup {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {cursor : ScheduleCursor g input} (htasks : cursor.taskOwners.Nodup) (hindices : cursor.indexOwners.Nodup) (hframes : cursor.frameOwners.Nodup) (hframeSubset : cursor.frameOwners cursor.indexOwners) (hindexCount : cursor.indexOwners.length 6 * input.length) (hshape : cursor.word.length cursor.taskOwners.length + cursor.indexOwners.length + 2 * cursor.frameCount + 2) :

                                    Construct the global invariant from its qualitative ownership facts, the explicit persistent owner bound, and the delimiter-shape bound. Unlike task owners, persistent owners live in an ambient carrier larger than their reusable bank, so their 6|input| bound is supplied explicitly.

                                    Distinct open frames inject into the persistent indices which own them.

                                    theorem IndexedGrammar.Aho.ScheduleInvariant.word_length_le_twenty_one_mul {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {cursor : ScheduleCursor g input} (hinv : ScheduleInvariant cursor) (hinput : 0 < input.length) :
                                    cursor.word.length 21 * input.length

                                    The accounting invariant implies a uniform twenty-one-squares-per-input-symbol bound.

                                    theorem IndexedGrammar.Aho.ScheduleInvariant.erase_within {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {cursor : ScheduleCursor g input} (hinv : ScheduleInvariant cursor) (hinput : 0 < input.length) (inputPos : ) :
                                    Config.Within (21 * input.length) { inputPos := inputPos, work := cursor.erase }

                                    Erasing scheduler annotations preserves the bound needed by BoundedReaches.

                                    theorem IndexedGrammar.Aho.ScheduleInvariant.erase_within_max_two {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {cursor : ScheduleCursor g input} (hinv : ScheduleInvariant cursor) (inputPos : ) :
                                    Config.Within (max 2 (21 * input.length)) { inputPos := inputPos, work := cursor.erase }

                                    The two fixed boundary cells also cover the vacuous zero-length ambient carrier.

                                    Invariant-carrying schedule witnesses #

                                    structure IndexedGrammar.Aho.ScheduleState {T : Type} (g : IndexedGrammar T) [Fintype g.nt] (input : List T) :

                                    A scheduler state consists of a ghost cursor, its input position, and the global ownership invariant. Erasing it gives an ordinary composite-machine configuration.

                                    Instances For
                                      def IndexedGrammar.Aho.ScheduleState.config {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (state : ScheduleState g input) :

                                      Forget all scheduler annotations.

                                      Equations
                                      Instances For
                                        theorem IndexedGrammar.Aho.ScheduleState.config_within {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (state : ScheduleState g input) (hinput : 0 < input.length) :
                                        Config.Within (21 * input.length) state.config

                                        Every scheduler state is inside the target tape bound.

                                        def IndexedGrammar.Aho.ScheduleStep {T : Type} (g : IndexedGrammar T) [Fintype g.nt] (input : List T) (state state' : ScheduleState g input) :

                                        A scheduler edge erases to one composite-machine edge. Ownership data is carried by the endpoint states, so a schedule is bounded by construction.

                                        Equations
                                        Instances For
                                          def IndexedGrammar.Aho.ScheduleReaches {T : Type} (g : IndexedGrammar T) [Fintype g.nt] (input : List T) (state state' : ScheduleState g input) :

                                          An invariant-carrying finite schedule, recorded extensionally at the erased machine configurations. Ghost-owner relabellings therefore cost no executable step.

                                          Equations
                                          Instances For
                                            theorem IndexedGrammar.Aho.ScheduleReaches.refl {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (state : ScheduleState g input) :
                                            ScheduleReaches g input state state

                                            The empty schedule at an invariant-carrying state.

                                            theorem IndexedGrammar.Aho.ScheduleReaches.single {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {state state' : ScheduleState g input} (step : CompositeStep g input state.config state'.config) :
                                            ScheduleReaches g input state state'

                                            Package one verified composite-machine edge between invariant-carrying scheduler states.

                                            theorem IndexedGrammar.Aho.ScheduleReaches.trans {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {state₁ state₂ state₃ : ScheduleState g input} (first : ScheduleReaches g input state₁ state₂) (second : ScheduleReaches g input state₂ state₃) :
                                            ScheduleReaches g input state₁ state₃

                                            Concatenate two invariant-carrying schedules at their common scheduler state.

                                            theorem IndexedGrammar.Aho.ScheduleReaches.congr_config {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {state state' relabelled relabelled' : ScheduleState g input} (schedule : ScheduleReaches g input state state') (hstart : relabelled.config = state.config) (hend : relabelled'.config = state'.config) :
                                            ScheduleReaches g input relabelled relabelled'

                                            Change either endpoint's ghost annotations without changing its erased configuration.

                                            theorem IndexedGrammar.Aho.ScheduleReaches.toBoundedReaches {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} {state state' : ScheduleState g input} (hinput : 0 < input.length) (schedule : ScheduleReaches g input state state') :
                                            BoundedReaches g input (21 * input.length) state.config state'.config

                                            Erasing an invariant-carrying schedule produces BoundedReaches directly.

                                            Canonical endpoints #

                                            def IndexedGrammar.Aho.initialScheduleTask {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (parse : g.NFParse g.initial [] input) :
                                            ScheduleTask g input

                                            The initial pending task is plain because its inherited stack is empty.

                                            Equations
                                            Instances For
                                              def IndexedGrammar.Aho.initialScheduleCursor {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (parse : g.NFParse g.initial [] input) :

                                              Ghost cursor for Aho's initial $ S # configuration.

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

                                                Ghost cursor for the final $ # configuration.

                                                Equations
                                                Instances For
                                                  def IndexedGrammar.Aho.initialScheduleState {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (parse : g.NFParse g.initial [] input) :

                                                  Canonical invariant-carrying initial state.

                                                  Equations
                                                  Instances For

                                                    Canonical invariant-carrying accepting state.

                                                    Equations
                                                    Instances For
                                                      def IndexedGrammar.Aho.ParseScheduled {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (parse : g.NFParse g.initial [] input) :

                                                      The exact remaining semantic obligation: construct an ownership-preserving schedule from a concrete parse.

                                                      Equations
                                                      Instances For
                                                        theorem IndexedGrammar.Aho.complete_bounded_of_parseScheduled {T : Type} {g : IndexedGrammar T} [Fintype g.nt] {input : List T} (parse : g.NFParse g.initial [] input) (schedule : ParseScheduled parse) :
                                                        BoundedReaches g input (21 * input.length) (initialConfig g) (finalConfig g input.length)

                                                        Once the parse-directed schedule is constructed, its endpoint and ownership invariants give full bounded completeness without any additional accounting argument.