Equation lemmas fail to generate for `match id a, a with ...`: the hypothesis `id 0 = n + 1` is dropped from the statement
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
- Mostly clear
- Activity status
- Active
- Domain
- compilers
Research direction
Start with the minimal EqnDiscr.lean examples in the issue and compare equation lemma generation for match id a, a with and match a, a with. Reproduce the failure on a current Lean build, then trace how match discriminant hypotheses are carried into generated equation theorems. Done when the equation lemmas retain the necessary hypothesis and the shown simp [f] case succeeds.
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 discriminant,equation lemma heqandisIrrelevant. Related: #15735 (amatchon the decreasing argument and a non-variable value, with structural recursion and a bind), #5667, #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 but cannot generate its equation lemmas:
def f (a : Nat) : Nat :=
match id a, a with
| 0, _ => 1
| _+1, 0 => 2
| _, _+1 => 3
#check @f.eq_1
lean EqnDiscr.lean
EqnDiscr.lean:7:8: error: Failed to realize constant f.eq_1:
failed to generate equational theorem for `f`
case h_1
x a : Nat
heq✝ : id 0 = 0
⊢ 1 = 2
EqnDiscr.lean:7:8: error(lean.unknownIdentifier): Unknown identifier `f.eq_1`
For the second alternative, the statement Lean computes is f 0 = 2 without the hypothesis id 0 = n.succ from the split, and that statement is false (f 0 is 1). simp [f] and rw [f] fail the same way (unfold f works). A closed discriminant gives the same failure:
def g (a : Nat) : Nat :=
match 7 - 0, a with
| 0, _ => 1
| _+1, 0 => 2
| _, _+1 => 3
example : g 0 = 2 := by simp [g]
-- error: failed to generate equational theorem for `g`
With match a, a with the lemmas are generated.
Expected behavior: the equation lemmas are generated, with the hypothesis kept, for example f.eq_2 (n : Nat) : id 0 = n.succ → f 0 = 2.
Actual behavior: generation fails, so f.eq_1 does not exist and simp [f] fails.
Versions
4.37.0-nightly-2026-11-04 fails
master 92016b6068 fails
4.35.0 fails
4.22.0 fails (times out instead)
These are on macOS arm64 (official toolchains via elan); master was built on Linux.
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