`grind` reaches maximum recursion depth on relatively simple goal
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
Here is some code:
module
namespace Char
def flipCase (c : Char) : Char :=
if c.isLower then
c.toUpper
else if c.isUpper then
c.toLower
else
c
@[simp]
theorem toNat_mk' {val : UInt32} {h} : (Char.mk val h).toNat = val.toNat := by
simp [← toNat_val]
theorem isLower_flipCase {c : Char} : c.flipCase.isLower ↔ c.isUpper := by
-- This proof works
grind [flipCase, isUpper, isLower, toUpper, toLower]
theorem toLower_flipCase {c : Char} : c.flipCase.toLower = c.toLower := by
-- This proof does not work. It fails with `maximum recursion depth has been reached`
-- grind [flipCase, isUpper, isLower, toUpper, toLower]
-- This proof works
simp [flipCase, isUpper, isLower, toUpper, toLower, ← toNat_inj, apply_dite Char.toNat,
apply_ite Char.toNat, UInt32.le_iff_toNat_le]
grind
end Char
Context
Discovered during human-eval-lean.
Steps to Reproduce
- Copy the above code into live.lean-lang.org
Expected behavior: grind [flipCase, isUpper, isLower, toUpper, toLower] solves the theorem toLower_flipCase.
Actual behavior: maximum recursion depth has been reached
Versions
4.30.0-nightly-2026-03-24 on live.lean-lang.org
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the self-contained Char example in live.lean-lang.org and reproduce the failure in toLower_flipCase with grind [flipCase, isUpper, isLower, toUpper, toLower]. Compare it with the working isLower_flipCase proof and the expanded workaround; done means the direct grind invocation solves the theorem without reaching maximum recursion depth.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100