Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: remove simpCtorEq from the default simprocs #5046

Closed
hrmacbeth opened this issue Aug 15, 2024 · 1 comment · Fixed by #5167
Closed

RFC: remove simpCtorEq from the default simprocs #5046

hrmacbeth opened this issue Aug 15, 2024 · 1 comment · Fixed by #5167
Labels
P-high We will work on this issue RFC Request for comments

Comments

@hrmacbeth
Copy link
Contributor

Proposal

Currently simp only simplifies an equality a = b to False, if a and b are different constructors for an inductive type. This is apparently done by the Meta.Simp.simpCtorEq simproc.

Would it be possible to turn off this simproc in simp only, while still keeping it in the set of rules used by simp? Here are three arguments in favour of this change:

  1. This simproc can cause unpredictable behaviour. For example,
example : (1:Nat) = 0 := by
  simp only -- goal `False`

example : (1:Int) = 0 := by
  simp only -- "simp made no progress"

example : (-1:Int) = 0 := by
  simp only -- goal `False`

The simpCtorEq simproc is applicable to the first and last of these goals but not to the middle one.

  1. This simproc can cause inefficient behaviour. For example (from @kmill):
example : 2^10000 = 2^9999 := by
  simp (config := Lean.Meta.Simp.neutralConfig) only
/-
exponent 10000 exceeds the threshold 256, exponentiation operation was not evaluated,
use `set_option exponentiation.threshold <num>` to set a new threshold
-/
  1. There are use cases where unambiguously this simproc is undesirable, so it's awkward to have it baked into simp only, where it is (AFAICT) impossible to turn off. For example, the simp tactic is used internally in the Mathlib ring tactic to clean up failures before they are presented to the user. This simproc actually cleans up some failures too aggressively, so that the information to the user is lost!
import Mathlib

-- simproc does not act, user gets useful error message
example (x : ℤ) : x + 1 - x = 0 := by ring
/-
error: unsolved goals
⊢ 1 = 0
-/

-- simproc acts, user does not get useful error message
example (x : ℤ) : x - 1 - x = 0 := by ring
/-
error: unsolved goals
⊢ False
-/

Community Feedback

Discussion at
https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/simp.20only.20on.20numeric.20goals

Impact

Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.

@hrmacbeth hrmacbeth added the RFC Request for comments label Aug 15, 2024
@Kha
Copy link
Member

Kha commented Aug 16, 2024

Side note: ring could likely be fixed by adjusting Methods.post in the simp call

@leanprover-bot leanprover-bot added the P-high We will work on this issue label Aug 16, 2024
leodemoura added a commit that referenced this issue Aug 26, 2024
The simproc is renamed to `reduceCtorEq`.

closes #5046
leodemoura added a commit that referenced this issue Aug 26, 2024
The simproc is renamed to `reduceCtorEq`.

closes #5046
github-merge-queue bot pushed a commit that referenced this issue Aug 26, 2024
`simp only` will not apply this simproc anymore. Users must now write
`simp only [reduceCtorEq]`. See RFC #5046 for motivation.
This PR also renames simproc to `reduceCtorEq`. 

close #5046 


@semorrison A few `simp only ...` tactics will probably break in
Mathlib. Fix: include `reduceCtorEq`.
github-merge-queue bot pushed a commit that referenced this issue Aug 26, 2024
PR #5167 implemented RFC #5046, but it required several workarounds due
to staging issues. This PR cleans up these workarounds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-high We will work on this issue RFC Request for comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants