Documentation

Mathlib.Lean.Meta.RefinedDiscrTree.Basic

Basic Definitions for RefinedDiscrTree #

We define

Discrimination tree key.

  • star : Key

    A metavariable. This key matches with anything.

  • labelledStar (id : ) : Key

    A metavariable. This key matches with anything. It stores an identifier.

  • opaque : Key

    An opaque variable. This key only matches with Key.star.

  • const (declName : Name) (nargs : ) : Key

    A constant. It stores the name and the arity.

  • fvar (fvarId : FVarId) (nargs : ) : Key

    A free variable. It stores the FVarId and the arity.

  • bvar (deBruijnIndex nargs : ) : Key

    A bound variable, from a lambda or forall binder. It stores the De Bruijn index and the arity.

  • lit (v : Literal) : Key

    A literal.

  • sort : Key

    A sort. Universe levels are ignored.

  • lam : Key

    A lambda function.

  • forall : Key

    A dependent arrow.

  • proj (typeName : Name) (idx nargs : ) : Key

    A projection. It stores the structure name, the projection index and the arity.

Instances For
    @[implicit_reducible]

    Compute the hash of a RefinedDiscrTree.Key.

    Note: at the root, .const is the most common key, and it is very uncommon to get the same constant name with a different arity. So for performance, we just use hash name to hash .const name _.

    Instances For
      @[implicit_reducible]
      @[implicit_reducible]
      def Lean.Meta.RefinedDiscrTree.keysAsPattern (keys : Array Key) :
      CoreM MessageData

      Converts an entry (i.e., List Key) to the discrimination tree into MessageData that is more user-friendly.

      This is a copy of Lean.Meta.DiscrTree.keysAsPattern

      Instances For
        def Lean.Meta.RefinedDiscrTree.keysAsPattern.next (keys : Array Key) :
        StateRefT' IO.RealWorld (List Key) CoreM Key

        Get the next key.

        Instances For
          partial def Lean.Meta.RefinedDiscrTree.keysAsPattern.mkApp (keys : Array Key) (f : MessageData) (nargs : ) (paren : Bool) :
          StateRefT' IO.RealWorld (List Key) CoreM MessageData

          Format the application f args.

          partial def Lean.Meta.RefinedDiscrTree.keysAsPattern.go (keys : Array Key) (paren : Bool := true) :
          StateRefT' IO.RealWorld (List Key) CoreM MessageData

          Format the next expression.

          def Lean.Meta.RefinedDiscrTree.keysAsPattern.parenthesize (msg : MessageData) (paren : Bool) :
          MessageData

          Add parentheses if paren == true.

          Instances For

            Return the number of arguments that the Key takes.

            Instances For

              The information for computing the keys of a subexpression.

              • expr : Expr

                The expression

              • bvars : List FVarId

                Variables that come from a lambda or forall binder. The list index gives the De Bruijn index.

              • lctx : LocalContext

                The local context, which contains the introduced bound variables.

              • localInsts : LocalInstances

                The local instances, which may contain the introduced bound variables.

              • cfg : Config

                The Meta.Config used by this entry.

              Instances For
                def Lean.Meta.RefinedDiscrTree.mkExprInfo (expr : Expr) (bvars : List FVarId) :
                MetaM ExprInfo

                Creates an ExprInfo using the current context.

                Instances For

                  The possible values that can appear in the stack

                  Instances For

                    A LazyEntry represents a snapshot of the computation of encoding an Expr as Array Key. This is used for computing the keys one by one.

                    • previous : Option ExprInfo

                      If an expression creates more entries in the stack, for example because it is an application, then instead of pushing to the stack greedily, we only extend the stack once we need to. So, the field previous is used to extend the stack before looking in the stack.

                      For example in 10.add (20.add 30), after computing the key ⟨Nat.add, 2⟩, the stack is still empty, and previous will be 10.add (20.add 30).

                    • stack : List StackEntry

                      The stack, used to emulate recursion. It contains the list of all expressions for which the keys still need to be computed, in that order.

                      For example in 10.add (20.add 30), after computing the keys ⟨Nat.add, 2⟩ and 10, the stack will be a list of length 1 containing the expression 20.add 30.

                    • mctx : MetavarContext

                      The metavariable context, which may contain variables appearing in this entry.

                    • labelledStars? : Option (Array MVarId)

                      MVarIds corresponding to the .labelledStar labels. The index in the array is the label. It is none if we use .star instead of labelledStar, for example when encoding the lookup expression.

                    • computedKeys : List Key

                      The Keys that have already been computed.

                      Sometimes, more than one Key ends up being computed in one go. This happens when there are lambda binders (because it depends on the body whether the lambda key should be indexed or not). In that case the remaining Keys are stored in results.

                    Instances For
                      def Lean.Meta.RefinedDiscrTree.mkInitLazyEntry (labelledStars : Bool) :
                      MetaM LazyEntry

                      Creates a LazyEntry using the current metavariable context.

                      Instances For
                        @[reducible, inline]

                        Array index of a Trie α in the tries of a RefinedDiscrTree.

                        Instances For

                          Discrimination tree trie. See RefinedDiscrTree.

                          A Trie will normally have exactly one of the following

                          Instances For
                            @[implicit_reducible]

                            Lazy refined discrimination tree. It is an index from expressions to values of type α.

                            We store all of the nodes in one Array, tries, instead of using a 'normal' inductive type. This is so that we can modify the tree globally, which is very useful when evaluating lazy entries and saving the result globally.

                            • root : Std.HashMap Key TrieIndex

                              Tries at the root based of the Key.

                            • tries : Array (Trie α)

                              Array of trie entries. Should be owned by this trie.

                            Instances For
                              @[implicit_reducible]
                              def Lean.Meta.RefinedDiscrTree.format {α : Type} [ToFormat α] (tree : RefinedDiscrTree α) :
                              Format

                              Format a RefinedDiscrTree as a flowchart.

                              • Non-terminal nodes are of the form {key} =>, followed by all of the following nodes, indented with 2 more spaces.
                              • Terminal nodes have either "entries", containing the return values, or "pending entries", for nodes that have not been evaluated/expanded.

                              For example:

                              Discrimination tree flowchart:
                              ⟨HMul.hMul, 6⟩ =>
                                ⟨Int, 0⟩ =>
                                  ⟨Int, 0⟩ =>
                                    * =>
                                      * =>
                                        *0 =>
                                          *0 =>
                                            pending entries: #[mul_self]
                                          *1 =>
                                            entries: #[mul_comm]
                                          ⟨Neg.neg, 3⟩ =>
                                            ⟨Int, 0⟩ =>
                                              * =>
                                                *1 =>
                                                  entries: #[mul_neg]
                                          1 =>
                                            pending entries: #[mul_one]
                                        ⟨Neg.neg, 3⟩ =>
                                          pending entries: #[neg_mul]
                                        1 =>
                                          *0 =>
                                            entries: #[one_mul]
                              
                              Instances For
                                partial def Lean.Meta.RefinedDiscrTree.format.go {α : Type} [ToFormat α] (tree : RefinedDiscrTree α) (trie : TrieIndex) :
                                Format

                                Auxiliary function for RefinedDiscrTree.format.

                                @[implicit_reducible]
                                instance Lean.Meta.RefinedDiscrTree.instToFormat {α : Type} [ToFormat α] :
                                ToFormat (RefinedDiscrTree α)