feat: auto eta-expand structures in grind when equality with constructor is present#12860
Draft
feat: auto eta-expand structures in grind when equality with constructor is present#12860
grind when equality with constructor is present#12860Conversation
Collaborator
Author
|
!radar |
c094082 to
7f3a54f
Compare
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
Collaborator
Author
|
!radar |
|
Benchmark results for 474e02b against 71ff366 are in. There are no significant changes. @kim-em
Medium changes (1🟥)
Small changes (3✅, 3🟥)
|
…uctor is present This PR adds automatic structure eta-expansion in `grind` when an equality `Eq α a b` is internalized where one side is a structure constructor and the other isn't. Previously, `grind` could only connect field equalities to structure equality for types explicitly marked `@[grind]` or `@[grind ext]`. Now goals like `r = ⟨0, some 0⟩` can be closed without requiring the annotation, as long as the constructor appears directly in an equality. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Eq-triggered eta-expansion causes grind to prove additional theorems about Array and Vector, so the #grind_lint #guard_msgs output changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Make `foo` irreducible so grind can't see the constructor through it, preserving the test's intent of exercising the `first_par` path in `try?`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…uct matching This PR fixes the grind_lint test files to use `#grind_lint skip` entries (in LintExceptions.lean and locally) instead of pinning exact `#guard_msgs` output for changed theorem counts. Also refactors `doEtaExpandStruct` to accept pre-matched structure info as parameters, avoiding redundant `matchConstNonRecStructure` calls, and reuses `αWhnf` from the Eq type in `propagateEtaStructForEq`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
221622b to
9ecc7e2
Compare
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Mar 10, 2026
mathlib-nightly-testing bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Mar 10, 2026
|
Mathlib CI status (docs):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds Eq-triggered eta-expansion for structures in
grind. WhengrindinternalizesEq α a bwhere one side is a structure constructor and the other isn't, it eta-expands the non-constructor side. This lets grind go from field equalities to structure equality without requiring@[grind]or@[grind ext]on the structure type.For example, this now works without any annotation on
LoopRange:Previously grind would deduce
r.start = 0andr.end_ = some 0but couldn't reconstructr = ⟨0, some 0⟩unlessLoopRangewas registered with@[grind ext].The approach is more targeted than unconditionally eta-expanding all structure terms — it only fires when a constructor appears in an equality, which avoids performance issues from cascading expansions on types like nested
Prod.Side effect: grind now proves additional theorems in the
#grind_linttest suite (e.g.Array.get_max?,Array.min_mem), so expected outputs are updated.🤖 Prepared with Claude Code