this fixes a usability paper cut that just annoyed me. When editing a larger simp proof, I usually want to see the goal state after the simp, and this is what I see while the `simp` command is complete. But then, when I start typing, and necessarily type incomplete lemma names, that error makes `simp` do nothing again and I see the original goal state. In fact, if a prefix of the simp theorem name I am typing is a valid identifier, it jumps even more around. With this PR, using `logException`, I still get the red squiggly lines for the unknown identifer, but `simp` just ignores that argument and still shows me the final goal. Much nicer. I also demoted the message for `[-foo]` when `foo` isn’t `simp` to a warning and gave it the correct `ref`. See it in action here: (in the middle, when you suddenly see the terminal, I am switching lean versions.) https://github.com/leanprover/lean4/assets/148037/8cb3c563-1354-4c2d-bcee-26dfa1005ae0
37 lines
1 KiB
Text
37 lines
1 KiB
Text
import Lean.Meta.Tactic.Simp.BuiltinSimprocs
|
|
import Lean.Elab.Command
|
|
|
|
def foo (x : Nat) : Nat :=
|
|
x + 10
|
|
|
|
open Lean Meta
|
|
|
|
/-- doc-comment for reduceFoo -/
|
|
simproc reduceFoo (foo _) := fun e => do
|
|
unless e.isAppOfArity ``foo 1 do return .continue
|
|
let some n ← Nat.fromExpr? e.appArg! | return .continue
|
|
return .done { expr := mkNatLit (n+10) }
|
|
|
|
run_meta do
|
|
guard <| (← findDocString? (← getEnv) ``reduceFoo) = some "doc-comment for reduceFoo "
|
|
|
|
example : x + foo 2 = 12 + x := by
|
|
set_option simprocs false in fail_if_success simp
|
|
simp_arith
|
|
|
|
example : x + foo 2 = 12 + x := by
|
|
-- `simp only` must not use the default simproc set
|
|
fail_if_success simp only
|
|
simp_arith
|
|
|
|
example : x + foo 2 = 12 + x := by
|
|
-- `simp only` does not use the default simproc set, but we can provide simprocs as arguments
|
|
simp only [reduceFoo]
|
|
simp_arith
|
|
|
|
example : x + foo 2 = 12 + x := by
|
|
-- We can use `-` to disable `simproc`s
|
|
fail_if_success simp [-reduceFoo]
|
|
simp_arith
|
|
|
|
example (x : Nat) (h : x < 86) : ¬100 ≤ x + 14 := by simp; exact h
|