leanprover / leanprover/lean4

Cannot derive eq_def for an @[irreducible] well-founded definition

Open
#14,957 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
Description

@[irreducible] on a well-founded recursive definition makes it fail to
elaborate:

@[irreducible] def f (n : Nat) (u : Unit) : Nat := if h : n = 0 then 0 else f (n-1) u
  termination_by n
error: Cannot derive f.eq_def from f._unary.eq_def
  Tactic `apply` failed: could not unify the conclusion of 'f._unary.eq_def'
Context

Found by an experimental fuzzer.

Steps to Reproduce
  1. Put these two lines in Repro.lean:

    @[irreducible] def f (n : Nat) (u : Unit) : Nat := if h : n = 0 then 0 else f (n-1) u
      termination_by n
    
  2. Run lean Repro.lean.

Expected behavior: the file elaborates, as it does without the attribute.

Actual behavior:

Repro.lean:1:0: error: Cannot derive f.eq_def from f._unary.eq_def
  Tactic `apply` failed: could not unify the conclusion of 'f._unary.eq_def'
    f._unary ?u ?n = if h : ?n = 0 then 0 else f._unary ?u (?n - 1)
  with the goal
    f._unary u n = if h : n = 0 then 0 else f (n - 1) u
  
  Note: The full type of 'f._unary.eq_def' is
    ∀ (u : Unit) (n : Nat), f._unary u n = if h : n = 0 then 0 else f._unary u (n - 1)
  
  n : Nat
  u : Unit
  ⊢ f._unary u n = if h : n = 0 then 0 else f (n - 1) u
Versions
Lean 4.35.0-nightly-2026-08-27
Target: x86_64-unknown-linux-gnu Linux
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 with the minimal reproducer in Repro.lean and run it with the specified Lean nightly version. Investigate how the irreducible attribute affects derivation of f.eq_def from f._unary.eq_def for the well-founded definition. Done means the reproducer elaborates successfully with @[irreducible], as it does without the attribute.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.