Skip to content

fix: make unfold on non-recursive definitions independent of eq_def realization - #15687

Merged
Kha merged 1 commit into
masterfrom
unfold-nonrec-eq-def
Nov 20, 2026
Merged

Kha merged 1 commit into
masterfrom
unfold-nonrec-eq-def

Conversation

@Kha

@Kha Kha commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

This PR makes the result of unfold f for a non-recursive definition f independent of what was elaborated earlier. Previously, a match on a constructor in the unfolded body was reduced only if an earlier tactic such as fun_cases f, possibly in another module, happened to have been run. Now unfold f never reduces it; proofs that relied on the reduction can do it explicitly, for example with dsimp -zeta only.

The reduction happened when unfold rewrote with f.eq_def, which it did whenever that theorem already existed, and otherwise it fell back to delta expansion. getUnfoldEqnFor? with nonRec := false now returns none for every non-recursive definition, so unfold always uses delta expansion for them: the lookup of an existing eq_def is only done for recursive definitions or when nonRec is set. The lookup also moves behind the shouldGenerateEqnThms guard, so a hand-written X.eq_def for a constant X that is not a definition, where the name is not reserved, is no longer returned as the unfold theorem of X.

@Kha Kha added the downstream Request a downstream-lean4 adaptation PR. label Oct 14, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Oct 14, 2026
@Kha
Kha force-pushed the unfold-nonrec-eq-def branch from 53e036e to 3df1a61 Compare November 19, 2026 08:47
…f` realization

This PR makes `unfold f` on a non-recursive definition `f` always unfold by plain delta expansion. Previously, it rewrote with `f.eq_def` and reduced the resulting matcher application whenever that theorem happened to exist already, so the resulting goal depended on whether some earlier tactic such as `fun_cases f` had realized it and, across modules, on whether that realization was visible to the importing module.

`getUnfoldEqnFor?` with `nonRec := false` now returns `none` for every non-recursive definition: the lookup of an existing `eq_def` is only done for recursive definitions or when `nonRec` is set. The lookup also moves behind the `shouldGenerateEqnThms` guard, so a hand-written `X.eq_def` for a constant `X` that is not a definition, where the name is not reserved, is no longer returned as the unfold theorem of `X`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Kha
Kha force-pushed the unfold-nonrec-eq-def branch from 3df1a61 to 02cc066 Compare November 19, 2026 16:17
@Kha
Kha force-pushed the unfold-nonrec-eq-def branch from 02cc066 to 8a98cb7 Compare November 20, 2026 09:05
@Kha
Kha changed the base branch from downstream-green to master November 20, 2026 09:05
@Kha
Kha force-pushed the unfold-nonrec-eq-def branch from 8a98cb7 to 1a21a14 Compare November 20, 2026 09:06
@Kha
Kha added this pull request to stack #16625 November 20, 2026 09:08
@Kha
Kha marked this pull request as ready for review November 20, 2026 09:09
@Kha Kha added the changelog-tactics User facing tactics label Nov 20, 2026
@downstream-lean4

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#265.

@Kha
Kha added this pull request to the merge queue Nov 20, 2026
Merged via the queue into master with commit 1ee6b41 Nov 20, 2026
32 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-tactics User facing tactics downstream Request a downstream-lean4 adaptation PR. toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant