(Imperfect) discrimination trees. We use a hybrid representation.
- A
PersistentHashMap
for the root node which usually contains many children. - A sorted array of key/node pairs for inner nodes.
The edges are labeled by keys:
- Constant names (and arity). Universe levels are ignored.
- Free variables (and arity). Thus, an entry in the discrimination tree may reference hypotheses from the local context.
- Literals
- Star/Wildcard. We use them to represent metavariables and terms we want to ignore. We ignore implicit arguments and proofs.
- Other. We use to represent other kinds of terms (e.g., nested lambda, forall, sort, etc).
We reduce terms using TransparencyMode.reducible
. Thus, all reducible
definitions in an expression e
are unfolded before we insert it into the
discrimination tree.
Recall that projections from classes are NOT reducible.
For example, the expressions Add.add α (ringAdd ?α ?s) ?x ?x
and Add.add Nat Nat.hasAdd a b
generates paths with the following keys
respctively
⟨Add.add, 4⟩, *, *, *, *
⟨Add.add, 4⟩, *, *, ⟨a,0⟩, ⟨b,0⟩
That is, we don't reduce Add.add Nat inst a b
into Nat.add a b
.
We say the Add.add
applications are the de-facto canonical forms in
the metaprogramming framework.
Moreover, it is the metaprogrammer's responsibility to re-pack applications such as
Nat.add a b
into Add.add Nat inst a b
.
Remark: we store the arity in the keys
1- To be able to implement the "skip" operation when retrieving "candidate"
unifiers.
2- Distinguish partial applications f a
, f a b
, and f a b c
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.DiscrTree.instLTKey = { lt := fun a b => Lean.Meta.DiscrTree.Key.lt a b = true }
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.DiscrTree.instInhabitedTrie = { default := Lean.Meta.DiscrTree.Trie.node #[] #[] }
Equations
- Lean.Meta.DiscrTree.empty = { root := { root := Lean.PersistentHashMap.Node.entries Lean.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }
Equations
- Lean.Meta.DiscrTree.instToFormatTrie = { format := Lean.Meta.DiscrTree.Trie.format }
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.DiscrTree.instToFormatDiscrTree = { format := Lean.Meta.DiscrTree.format }
Equations
- Lean.Meta.DiscrTree.instInhabitedDiscrTree = { default := { root := { root := Lean.PersistentHashMap.Node.entries Lean.PersistentHashMap.mkEmptyEntriesArray, size := 0 } } }
Equations
- Lean.Meta.DiscrTree.mkNoindexAnnotation e = Lean.mkAnnotation (Lean.Name.mkStr1 "noindex") e
Equations
- Lean.Meta.DiscrTree.hasNoindexAnnotation e = Option.isSome (Lean.annotation? (Lean.Name.mkStr1 "noindex") e)
whnf for the discrimination tree module
Equations
- Lean.Meta.DiscrTree.whnfDT e root = if root = true then Lean.Meta.DiscrTree.whnfUntilBadKey e else Lean.Meta.DiscrTree.whnfEta e
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.DiscrTree.insert d e v = do let keys ← Lean.Meta.DiscrTree.mkPath e pure (Lean.Meta.DiscrTree.insertCore d keys v)
Find values that match e
in d
.
Equations
- Lean.Meta.DiscrTree.getMatch d e = do let a ← Lean.Meta.DiscrTree.getMatchCore d e pure a.snd
Similar to getMatch
, but returns solutions that are prefixes of e
.
We store the number of ignored arguments in the result.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.