-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `simp` tactic uses a discrimination tree to select candidate theorems that will be used to rewrite an expression. This indexing data structure minimizes the number of theorems that need to be tried and improves performance. However, indexing modulo reducibility is challenging, and a theorem that could be applied, when taking reduction into account, may be missed. For example, suppose we have a `simp` theorem `foo : forall x y, f x (x, y).2 = y`, and we are trying to simplify the expression `f a b <= b`. `foo` will not be tried by `simp` because the second argument of `f a b` is not a projection of a pair. However, `f a b` is definitionally equal to `f a (a, b).2` since we can reduce `(a, b).2`. In Lean 3, we had a much simpler indexing data structure where only the head symbol was taken into account. For the theorem `foo`, the head symbol is `f`. Thus, the theorem would be considered by `simp`. This commit adds the option `Simp.Config.index`. When `simp (config := { index := false })`, only the head symbol is considered when retrieving theorems, as in Lean 3. Moreover, if `set_option diagnostics true`, `simp` will check whether every applied theorem would also have been applied if `index := true`, and report them. This feature can help users diagnose tricky issues in code that has been ported from libraries developed using Lean 3 and then ported to Lean 4. In the following example, it will report that `foo` is a problematic theorem. ```lean opaque f : Nat → Nat → Nat @[simp] theorem foo : f x (x, y).2 = y := by sorry example : f a b ≤ b := by set_option diagnostics true in simp (config := { index := false }) ``` In the example above, the following diagnostic message is produced. ```lean [simp] theorems with bad keys foo, key: [f, *, Prod.1, Prod.mk, Nat, Nat, *, *] ``` With the information above, users can annotate theorems such as `foo` using `no_index` for problematic subterms. Example: ```lean opaque f : Nat → Nat → Nat @[simp] theorem foo : f x (no_index (x, y).2) = y := by sorry example : f a b ≤ b := by simp -- `foo` is still applied ``` cc @semorrison cc @PatrickMassot
- Loading branch information
1 parent
1382e9f
commit ee0bcc8
Showing
6 changed files
with
938 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.