This PR adds a `+locals` configuration option to the `simp`, `simp_all`, and `dsimp` tactics that automatically adds all definitions from the current file to unfold. Example usage: ```lean def foo (n : Nat) : Nat := n + 1 -- Without +locals, simp doesn't know about foo example (n : Nat) : foo n = n + 1 := by simp -- fails -- With +locals, simp can unfold foo example (n : Nat) : foo n = n + 1 := by simp +locals -- succeeds ``` The implementation iterates over `env.constants.map₂` (which contains constants defined in the current module) and adds definitions to unfold. Instance definitions and internal details are filtered out. **Note:** For local theorems, use `+suggestions` instead, which will include relevant local theorems via the library suggestion engine. 🤖 Prepared with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
49 lines
1.5 KiB
Text
49 lines
1.5 KiB
Text
|
|
module
|
|
/-!
|
|
# Test for `simp +locals` flag (using the module system)
|
|
|
|
This tests that `simp +locals` adds local definitions from the current file.
|
|
|
|
We have a separate test here as the current semantics for `isImplementationDetail` are poorly specified,
|
|
and we've had to work around it in deciding which declarations should be included via `+locals`.
|
|
-/
|
|
|
|
-- A simple definition that provides an equation simp can use
|
|
def foo (n : Nat) : Nat := n + 1
|
|
|
|
-- Without +locals, simp shouldn't know about foo
|
|
-- (This test verifies +locals is actually doing something)
|
|
/--
|
|
error: `simp` made no progress
|
|
-/
|
|
#guard_msgs in
|
|
example (n : Nat) : foo n = n + 1 := by simp
|
|
|
|
-- Test that simp +locals can use the equation `foo n = n + 1`
|
|
example (n : Nat) : foo n = n + 1 := by simp +locals
|
|
|
|
-- An irrelevant definition that should NOT appear in simp? suggestions
|
|
def bar (n : Nat) : Nat := n * 2
|
|
|
|
-- Test that simp? +locals suggests only the relevant definition (foo), not bar
|
|
/--
|
|
info: Try this:
|
|
[apply] simp only [foo, Nat.add_left_cancel_iff]
|
|
-/
|
|
#guard_msgs in
|
|
example (n : Nat) : foo n = n + 1 := by simp? +locals
|
|
|
|
-- Test with a definition that has multiple equations via pattern matching
|
|
def isZero : Nat → Bool
|
|
| 0 => true
|
|
| _ + 1 => false
|
|
|
|
example : isZero 0 = true := by simp +locals
|
|
example (n : Nat) : isZero (n + 1) = false := by simp +locals
|
|
|
|
-- Test simp_all +locals
|
|
example (n : Nat) (h : n = 0) : isZero n = true := by simp_all +locals
|
|
|
|
-- Test dsimp +locals
|
|
example : foo 5 = 6 := by dsimp +locals
|