"failed to generate equational theorem" when a `match` discriminant such as `1 - a` becomes a closed term after unfolding
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- compilers
Research direction
Start with the minimal reproducer in the issue and inspect src/Lean/Elab/PreDefinition/Eqns.lean, which the report identifies as the equation theorem generation code. Compare the generated proof for a closed arithmetic match discriminant with the working id 3 case, then check whether the stated hypothesis is used. Done when the equation theorem is generated and simp [f] proves f 0 = 0.
Written by the indexing model from the issue text.
Description
Prerequisites
- Check that your issue is not already filed: searched for
failed to generate equational theorem,equational theorem match discriminantandclosed discriminant. Related: #16259 (same kind ofmatch, but there the hypothesis is dropped from the statement), #7841, #15735, #10431. - 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.
Description
Lean accepts this definition and states a true equation lemma for it, but cannot prove that lemma:
def f (a : Nat) : Nat :=
match 1 - a, a with
| n+1, 0 => n
| _, _ => 0
#check @f.eq_1
example : f 0 = 0 := by simp [f]
Eqn.lean:6:8: error: Failed to realize constant f.eq_1:
failed to generate equational theorem for `f`
n : Nat
h : 1 - 0 = n.succ
⊢ 0 = n
Eqn.lean:6:8: error(lean.unknownIdentifier): Unknown identifier `f.eq_1`
Eqn.lean:7:30: error: failed to generate equational theorem for `f`
...
Eqn.lean:7:24: error: `simp` made no progress
The hypothesis h : 1 - 0 = n.succ is in the goal and gives n = 0, but the proof doesn't use it. example : f 0 = 0 := rfl and by unfold f; rfl are both accepted. Unlike #16259, the generated statement here is correct; only its proof fails. 5 - a fails the same way, while match id 3, a with ... works (h.eq_1 : ∀ n, id 3 = n.succ → h 0 = n).
Expected behavior: f.eq_1 : ∀ (n : Nat), 1 - 0 = n.succ → f 0 = n is generated and simp [f] proves f 0 = 0.
Actual behavior: the errors above.
Versions
4.37.0-nightly-2026-11-05 failed to generate equational theorem
4.35.0 failed to generate equational theorem (hypothesis named heq)
4.22.0 (deterministic) timeout at `whnf`
These are on macOS arm64 (official toolchains via elan), and Linux x86_64 gives the same results. Since the nightly, the only change on master to src/Lean/Elab/PreDefinition/Eqns.lean is #16275, which is about over-applied matchers.
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask
them to add 👍 to it.
Found by an automated differential tester (ephyra); this report was drafted with AI assistance.
- Dominant language
- Lean
- Stars
- 10.3k
- Forks
- 1.1k
- Avg merge
- 19h 8m
- Merged PRs (30d)
- 421
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from leanprover/lean4
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
leanprover/lean4#16305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
leanprover/lean4#16299 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16257 ·
Maintainers usually reply within 1 day
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
leanprover/lean4#15683 ·
Maintainers usually reply within 1 day
All issues in leanprover/lean4
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
swc-project/swc-next-issues#817 ·
-
Magma mode: div:=, mod:= and the other keyword assignments (join:=, meet:=, diff:=, sdiff:=, and:=, or:=, xor:=) are refusedPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sagemathinc/sagebrush#1683 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
microts: a model local that every branch assigns raises unused_assignments in the generated RustOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
pocket-stack/pocketjs#756 ·
-
bot-triaged module: aotinductor module: compile-time module: inductor module: performance module: rocm oncall: export oncall: pt2 triaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day