-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Tactic):
erw
tries rw
first and warns if that succeeds
This PR adds a macro rule to the `erw` tactic that first tries `rw` at reducible transparency, and displays a "Try this:" if that succeeded. This should help us get rid of uselessly slow `erw`s. This is a relatively simple implementation that does not verify if `erw` and `rw` would have resulted in the same exact rewrite. So it is possible that `erw` and `rw` both succeed but rewrite different occurrences, and there would be a suggestion to replace `erw` with `rw` in that case. I think the complication of running both at the same time and checking the goal state afterwards doesn't weigh up to accepting that this happens and adding an explanation to the warning generated by `erw`. I import the `erw` extension in `Tactic.Common`: it might be nice to migrate this up even earlier in the import hierarchy but `Mathlib.Tactic.TryThis` is a somewhat heavy import to put in `Mathlib.Tactic.Core`.
- Loading branch information
1 parent
344c0bb
commit 109e158
Showing
4 changed files
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/- | ||
Copyright (c) 2024 Anne Baanen. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Anne Baanen | ||
-/ | ||
|
||
import Mathlib.Tactic.TryThis | ||
|
||
/-! | ||
# Extension to the `erw` tactic | ||
This file adds a macro rule to the `erw` tactic that first tries to run the `rw` tactic at the | ||
faster `reducible` transparency, and adds a suggestion if that also succeeds. | ||
Note that `rw` succeeding is not the same as `rw` and `erw` doing exactly the same rewrite: they may | ||
have operated on different subterms. Since the suggested `rw` may not be an exact replacement, we | ||
display a hint explaining what to do if this happens. | ||
-/ | ||
|
||
/-- If we call `erw`, first try running regular `rw` and warn if that succeds. -/ | ||
macro_rules | ||
| `(tactic| erw $s $(loc)?) => | ||
`(tactic| | ||
try_this rw $(.none)? $s $(loc)?; | ||
trace "Hint: `rw` succeeded here, but may have performed a different rewrite than `erw` would. | ||
If `erw` really is needed, try preceding this line with a `rw` to get rid of the other occurrences, | ||
or use `conv` to specify exactly which subterm to rewrite.") |