Documentation

LeanPool.OrderMaintenance.Model.State

Level F: state #

The functional model of the algorithm (docs/LEAN.md §4), a transliteration of the Python prototype (prototype/core.py, pq.py, top_wbbt.py, wrapper.py). It is executable and is tested against the prototype by trace replay (OrderMaintenance/Test/Replay.lean).

Conventions:

@[reducible, inline]

The zero index reserved for absent pointers and dummy array entries.

Equations
Instances For

    Parameters of one core (prototype/core.py Params, plus the top structure's).

    • N : Nat

      Capacity parameter for the core.

    • L : Nat

      Logarithmic scale used in the capacity formulas.

    • G : Nat

      Element threshold for beginning a group split.

    • T : Nat

      Element threshold for beginning a chunk split.

    • theta : Nat

      Quiet-chunk size threshold for entering the priority queue.

    • elementBits : Nat

      Bit width of element labels.

    • groupBits : Nat

      Bit width of group labels.

    • elementSpacing : Nat

      Spacing used when appending an element label.

    • groupSpacing : Nat

      Spacing used when appending a group label.

    • groupBudget : Nat

      Group split steps scheduled per insertion.

    • chunkBudget : Nat

      Chunk split steps scheduled per insertion.

    • reservationBudget : Nat

      Reservation steps scheduled per insertion.

    • a : Nat

      Tree balance parameter controlling child capacity.

    • s : Nat

      Number of tree sweep steps scheduled at each visit.

    • beta : Nat

      Bit width of one level of a chunk’s composite tag.

    • H : Nat

      Maximum height of the top tree.

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

        Lifecycle of a group or chunk during incremental splitting.

        • quiet : St
        • overflow : St
        • splitting : St
        • dead : St
        Instances For
          @[instance_reducible]
          Equations
          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            An allocated element, including its order label and external handle.

            • next : Nat

              Next element index in the core list.

            • prev : Nat

              Previous element index in the core list.

            • grp : Nat

              Containing group index.

            • lab : Nat

              Order label within the containing group.

            • live : Bool

              Whether this element represents a live external handle.

            • h : Nat

              External handle represented by this element.

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

                A labelled run of elements and its incremental split state.

                • next : Nat

                  Next group index in the core list.

                • prev : Nat

                  Previous group index in the core list.

                • first : Nat

                  First element index, or the absent-pointer sentinel.

                • last : Nat

                  Last element index, or the absent-pointer sentinel.

                • chk : Nat

                  Containing chunk index.

                • lab : Nat

                  Order label within the containing chunk.

                • size : Nat

                  Number of elements in the group.

                • st : St

                  Current incremental split state.

                • src : Nat

                  Source group of an overflow sibling.

                • l : Nat

                  Left overflow sibling of a splitting group.

                • r : Nat

                  Right overflow sibling of a splitting group.

                • alive : Bool

                  Whether this group record is currently allocated.

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

                    A tagged run of groups and its incremental split state.

                    • next : Nat

                      Next chunk index in the core list.

                    • prev : Nat

                      Previous chunk index in the core list.

                    • first : Nat

                      First group index, or the absent-pointer sentinel.

                    • last : Nat

                      Last group index, or the absent-pointer sentinel.

                    • size : Nat

                      Number of elements in the chunk.

                    • st : St

                      Current incremental split state.

                    • src : Nat

                      Source chunk of an overflow sibling.

                    • l : Nat

                      Left overflow sibling of a splitting chunk.

                    • r : Nat

                      Right overflow sibling of a splitting chunk.

                    • tag : Nat

                      Order tag assembled from the top-tree path.

                    • alive : Bool

                      Whether this chunk record is live rather than a tombstone.

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

                        The side of a split receiving a table entry.

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

                            A node of the top tree (prototype/top_wbbt.py Node). The prototype's lab dictionary and order list are merged into table: the entries with their labels, in label order.

                            • height : Nat

                              Height above chunks, which occupy height zero.

                            • livePar : Nat

                              Parent in the live top tree.

                            • children : List Nat

                              Ordered live child indices.

                            • weight : Nat

                              Weight used by the tree balance and drain rules.

                            • table : List (Nat × Nat)

                              Entries and labels in increasing label order.

                            • inTables : List Nat

                              Tables in which this node occurs as an entry.

                            • first : Nat

                              First chunk in the node’s represented range.

                            • last : Nat

                              Last chunk in the node’s represented range.

                            • draining : Bool

                              Whether this node is undergoing a drain.

                            • t1 : Nat

                              Left target node of an active drain.

                            • t2 : Nat

                              Right target node of an active drain.

                            • side : List (Nat × Side)

                              Destination side assigned to each entry during a drain.

                            • overflowOf : Nat

                              Source of this node when it is an overflow drain target.

                            • alive : Bool

                              Whether this node record is in use.

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

                                The program counter of a top-structure job (top_wbbt.py _job, a Python generator). Each constructor is a point where the generator is suspended.

                                • copy (j : Nat) : JobPc

                                  Before copying level j of x's path.

                                • walk (v : Option Nat) : JobPc

                                  At the head of the upward walk; none means "start from lpar[y]".

                                • afterDrain (v up : Nat) : JobPc

                                  Right after _start_drain(v) (its yield).

                                • fund (v up src k : Nat) : JobPc

                                  Inside the sweep funding loop of v, after k sweep steps.

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

                                    A suspended reservation job splitting a chunk into two replacements.

                                    • x : Nat

                                      Source chunk being split.

                                    • y : Nat

                                      Left replacement chunk.

                                    • z : Nat

                                      Right replacement chunk.

                                    • pc : JobPc

                                      Suspended position of the reservation computation.

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

                                        Deferred construction of the top structure (init_steps, a Python generator).

                                        • chunk : Nat

                                          Initial chunk whose ancestor chain is being prepared.

                                        • h : Nat

                                          The next height to build (starts at 1; H + 1 means "finish").

                                        • below : Nat
                                        • tag : Nat

                                          Composite chunk tag accumulated during preparation.

                                        • path : Array Nat

                                          Ancestor path accumulated during preparation.

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

                                            One insert-only core with its priority queue and top structure.

                                            • P : Params

                                              Parameters governing this core’s capacities and scheduled work.

                                            • Element records, including a dummy record at index zero.

                                            • Group records, including a dummy record at index zero.

                                            • Chunk records, including a dummy record at index zero.

                                            • freeG : List Nat

                                              Reusable group indices outside the live group list.

                                            • count : Nat

                                              Number of elements inserted into this core.

                                            • head : Nat

                                              Head of the element list, including the dead sentinel.

                                            • tail : Nat

                                              Last allocated element in list order.

                                            • firstGroup : Nat

                                              Head of the live group list.

                                            • firstChunk : Nat

                                              Head of the allocated chunk list.

                                            • ready : Bool

                                              Whether deferred top-tree preparation is complete.

                                            • prep : Option Prep

                                              Suspended top-tree preparation, if any.

                                            • resJob : Option Job

                                              Suspended chunk reservation job, if any.

                                            • fallbacks : Nat

                                              Number of fallback rebuilds performed.

                                            • pqHead : Array Nat

                                              Head chunk index of each size bucket.

                                            • pqNext : Array Nat

                                              Next queued chunk within the same size bucket.

                                            • pqPrev : Array Nat

                                              Previous queued chunk within the same size bucket.

                                            • pqWhere : Array Nat

                                              The bucket of a chunk in the queue, 0 if absent (sizes in the queue exceed theta ≥ 1).

                                            • nbNext : Array Nat

                                              Next nonempty size bucket.

                                            • nbPrev : Array Nat

                                              Previous nonempty size bucket.

                                            • pqHi : Nat

                                              Largest and smallest non-empty bucket, 0 if the queue is empty.

                                            • pqLo : Nat

                                              Smallest nonempty bucket, or zero for an empty queue.

                                            • nodes : Array Node

                                              Allocated top-tree node records.

                                            • path : Array (Array Nat)

                                              Top-tree ancestor paths indexed by chunk.

                                            • cin : Array (List Nat)

                                              Containing-table lists for chunk entries.

                                            • lpar : Array Nat

                                              Live parents of chunks at height zero.

                                            Instances For

                                              Guard failures permit rebuilding; bug failures represent invalid program states.

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

                                                  Stateful core computations that retain the reached state on failure.

                                                  Equations
                                                  Instances For

                                                    Arrays as total maps #

                                                    def Array.setX {α : Type} [Inhabited α] (a : Array α) (i : Nat) (v : α) :

                                                    Write v at i, extending the array with defaults if needed.

                                                    Equations
                                                    Instances For
                                                      def Array.getX {α : Type} [Inhabited α] (a : Array α) (i : Nat) :
                                                      α

                                                      Read an array as a total map, returning the default value outside its bounds.

                                                      Equations
                                                      Instances For

                                                        Accessors #

                                                        Raise a recoverable guard failure without discarding the current core.

                                                        Equations
                                                        Instances For
                                                          def OrderMaintenance.Model.bug {α : Type} (msg : String) :
                                                          CM α

                                                          Raise an internal failure indicating an invalid program state.

                                                          Equations
                                                          Instances For

                                                            Fail the guard msg unless ok.

                                                            Equations
                                                            Instances For
                                                              @[inline]

                                                              Read an element record, with the default record for an absent index.

                                                              Equations
                                                              Instances For
                                                                @[inline]

                                                                Read a group record, with the default record for an absent index.

                                                                Equations
                                                                Instances For
                                                                  @[inline]

                                                                  Read a chunk record, with the default record for an absent index.

                                                                  Equations
                                                                  Instances For
                                                                    @[inline]

                                                                    Read a top-tree node, with the default record for an absent index.

                                                                    Equations
                                                                    Instances For
                                                                      @[inline]

                                                                      Read the parameters of the current core.

                                                                      Equations
                                                                      Instances For
                                                                        @[inline]

                                                                        Modify an existing element record without extending the array.

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

                                                                          Modify an existing group record without extending the array.

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

                                                                            Modify an existing chunk record without extending the array.

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

                                                                              Modify an existing top-tree node without extending the array.

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

                                                                                Small list helpers #

                                                                                def List.idx? (l : List Nat) (x : Nat) :

                                                                                The position of x in l, if present.

                                                                                Equations
                                                                                Instances For
                                                                                  def List.replace1 (l : List Nat) (x : Nat) (ys : List Nat) :

                                                                                  Replace the first occurrence of x by the list ys.

                                                                                  Equations
                                                                                  Instances For
                                                                                    def List.remove1 (l : List Nat) (x : Nat) :

                                                                                    Remove the first occurrence of x.

                                                                                    Equations
                                                                                    Instances For
                                                                                      def OrderMaintenance.Model.lookup {β : Type} (l : List (Nat × β)) (k : Nat) :

                                                                                      Read the value at the first occurrence of a key in an association list.

                                                                                      Equations
                                                                                      Instances For

                                                                                        Look up the label assigned to an entry in a node table.

                                                                                        Equations
                                                                                        Instances For

                                                                                          List the entries of a node table in their stored label order.

                                                                                          Equations
                                                                                          Instances For