Equation lemmas fail to generate for `match id a, a with ...`: the hypothesis `id 0 = n + 1` is dropped from the statement

Aperta
#16,259 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Prerequisites
  • Check that your issue is not already filed: searched for failed to generate equational theorem, equational theorem match discriminant, equation lemma heq and isIrrelevant. Related: #15735 (a match on 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.

Lingua principale
Lean
Stelle
10.3k
Fork
1.1k
Merge medio
19h 8m
PR unite (30g)
421

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.