leanprover / lean4

Lean 4 programming language and theorem prover
https://lean-lang.org
Apache License 2.0
4.65k stars 418 forks source link

simp tries using the forward version of user-specified backward theorems #4290

Closed YaelDillies closed 4 months ago

YaelDillies commented 5 months ago

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

In Lean 3 (at least, Lean 3 community version), simp [<- thm] would automatically remove "forward thm" from the local list of simp lemmas. In Lean 4, it doesn't, meaning that simp [<- thm] is (mostly) doomed to fail if thm is a simp lemma.

Context

Personally I don't know how this issue has stayed unreported for so long. It keeps on happening to me (latest one in date) and is a major blocker to using simp in moderately complicated situations.

Steps to Reproduce

The following code

def foo : Nat := 0
def bar : Nat := 0

@[simp] theorem foo_eq_bar : foo = bar := rfl

example : foo = bar := by simp [← foo_eq_bar]
example : foo = bar + 1 := by simp [← foo_eq_bar]

Actual behavior: throws

tactic 'simp' failed, nested error:
maximum recursion depth has been reached

on both nightly and 4.8.0-rc2. I believe it works on every previous Lean 4 version but I haven't tried specifically.

Expected behavior: is expected to close the first example and leave the second example as ⊢ bar = bar + 1

I have included both examples because sometimes simp sneakily avoids the loop by performing a further simplification. Here it does seem to fall into the loop before it gets to try reflexivity.

Versions

4.9.0-nightly-2024-05-25 on live.lean-lang.org

Impact

Add :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.

kim-em commented 5 months ago

Personally I don't know how this issue has stayed unreported for so long.

Partly on you, I guess! :-) We rely on users making bug reports here.

But yes, I agree this is a usability improvement that we can hopefully implement soon.

YaelDillies commented 5 months ago

Sometimes the issues feel so big that you don't even bother checking the issue tracker because it has to be that someone has already reported it 🙃

Telltale for myself, I guess.

YaelDillies commented 4 months ago

Thanks for the quick turnaround!