leanprover / leanprover/lean4

isDefEq can ignore the proofIrrelevance setting

Open
#9,612 0 comments 4 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

Please put an X between the brackets as you perform the following steps:

Description

isDefEqArgsFirstPass in ExprDefEq implicitly encodes proof irrelevance, causing isDefEq to have some proof-irrelevance behavior regardless of the Lean.Meta.Context.proofIrrelevance setting.

When proof arguments are being compared, if neither is of the form fun x_1 ... x_n => ?m y_1 ... y_m, the argument is skipped unconditionally. This can be problematic if, for instance, the proof argument on one side has the form (p x) and the other has the form (p ?m). In this case, ?m will not be assigned to x due to proof irrelevance, regardless of the setting.

Context

I reported this issue on Zulip. Parts of the explanation above were provided by @kmill.

Steps to Reproduce

In the following code, observe the dbg_trace output.

import Lean
open Lean Meta Expr Elab Tactic Core

axiom p : Unit → ∃ x : Unit, True
noncomputable def concrete := fun x => (p x).choose

-- set_option trace.Meta.isDefEq true
#eval (do
  let value := (← getConstInfo ``concrete).value!
  let e1 := value.bindingBody!.instantiate1 (.const ``Unit.unit [])
  let e2 := value.bindingBody!.instantiate1 (← mkFreshExprMVar (Expr.const ``Unit []))
  withConfig (fun c => { c with proofIrrelevance := false }) do
    let _ ← isDefEq e1 e2
    dbg_trace (← instantiateMVars e2)
)

This code performs isDefEq on (p Unit.unit).choose and (p ?m).choose with the proofIrrelevance setting set to false.

Expected behavior: I expect ?m to be set to Unit.unit.

Although (p Unit.unit) and (p ?m) are proof arguments to the Exists.choose function, we have explicitly asked isDefEq to ignore proof irrelevance, so these arguments should not be skipped.

Actual behavior: The metavariable remains unassigned.

Versions

Lean 4.23.0-nightly-2025-07-28

Additional Information

N/A

Impact

I am developing a tactic and subsystem for Canonical that requires this functionality, by an update to isDefEq or by some workaround.

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 isDefEqArgsFirstPass in ExprDefEq and the surrounding isDefEq implementation. Run the minimal Lean reproduction from the issue with proofIrrelevance := false, then trace the comparison of (p Unit.unit).choose and (p ?m).choose. Done means the behavior respects that setting and the metavariable is assigned as expected.

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
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.