leanprover / leanprover/lean4

`grind` reaches maximum recursion depth on relatively simple goal

Open
#13,089 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
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
  1. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.