Skip to content

[Merged by Bors] - fix(Tactic): make eta_expand idempotent#35607

Closed
gasparattila wants to merge 3 commits intoleanprover-community:masterfrom
gasparattila:eta_expand-idempotent
Closed

[Merged by Bors] - fix(Tactic): make eta_expand idempotent#35607
gasparattila wants to merge 3 commits intoleanprover-community:masterfrom
gasparattila:eta_expand-idempotent

Conversation

@gasparattila
Copy link
Copy Markdown
Contributor

The docstring of eta_expand says that it puts terms into a normal form, implying that it is idempontent, however, this is not the case in some tricky cases. This PR changes eta_expand so that it gives the normal form in one step.


Open in Gitpod

The docstring of `eta_expand` says that it puts terms into a normal form, implying that it is idempontent, however, this is not the case in some tricky cases. This PR changes `eta_expand` so that it gives the normal form in one step.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 21, 2026

PR summary fadcf92bfc

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

No declarations were harmed in the making of this PR! 🐙

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions bot added the t-meta Tactics, attributes or user commands label Feb 21, 2026
@gasparattila gasparattila marked this pull request as draft February 21, 2026 19:18
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Feb 21, 2026

This pull request is now in draft mode. No active bors state needed cleanup.

While this PR remains draft, bors will ignore commands on this PR. Mark it ready for review before using commands like bors r+ or bors try.

Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why the original use of transform needs to be replaced with this new loop? Since the new version is more verbose and likely less efficient, I'd like to go back to transform if possible.

@Vierkantor Vierkantor added the awaiting-author A reviewer has asked the author a question or requested changes. label Mar 4, 2026
@gasparattila
Copy link
Copy Markdown
Contributor Author

When the current implementation encounters an application, say f x, it first recursively eta-expands f and x, turning it into (fun x => f x) x, then it beta-reduces the application to f x. But if f : (_ -> _) -> _, then the argument itself could get eta-expanded, resulting in (fun x => f (fun y => x y)) (fun y => x y). So we would first need to recursively eta-reduce the argument, then do the beta-reduction.

This could be avoided if we could eta-expand only the subterms of the function in the application, but I couldn't find a way to do this using transform.

-awaiting-author

@github-actions github-actions bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Mar 4, 2026
| e@(.app ..) =>
let f := e.getAppFn
let args := e.getAppArgs
if f.etaExpandedStrict?.isSome then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if f.etaExpandedStrict?.isSome then
-- Note that we call `expandSubterms` instead of `etaExpandAll` below,
-- because we also want to eta-expand the arguments to `f` (without beta-reducing them)
-- in case those arguments are functions themselves.
if f.etaExpandedStrict?.isSome then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this explanation, so instead, I added a comment below to clarify that this implementation doesn't create new beta-redexes. In expandSubterms (f.beta args), I believe that etaExpandAll would give the same result, but expandSubterms avoids an unnecessary call to inferType.

Copy link
Copy Markdown
Contributor

@Vierkantor Vierkantor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! Let's add an explanatory comment in that case. I think I got my explanation correct, please check.

bors d+

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 5, 2026

✌️ gasparattila can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@mathlib-triage mathlib-triage bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Mar 5, 2026
@gasparattila
Copy link
Copy Markdown
Contributor Author

bors r+

mathlib-bors bot pushed a commit that referenced this pull request Mar 6, 2026
The docstring of `eta_expand` says that it puts terms into a normal form, implying that it is idempontent, however, this is not the case in some tricky cases. This PR changes `eta_expand` so that it gives the normal form in one step.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 6, 2026

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title fix(Tactic): make eta_expand idempotent [Merged by Bors] - fix(Tactic): make eta_expand idempotent Mar 6, 2026
@mathlib-bors mathlib-bors bot closed this Mar 6, 2026
xroblot pushed a commit to xroblot/mathlib4 that referenced this pull request Mar 9, 2026
The docstring of `eta_expand` says that it puts terms into a normal form, implying that it is idempontent, however, this is not the case in some tricky cases. This PR changes `eta_expand` so that it gives the normal form in one step.
seewoo5 pushed a commit to seewoo5/mathlib4 that referenced this pull request Mar 9, 2026
The docstring of `eta_expand` says that it puts terms into a normal form, implying that it is idempontent, however, this is not the case in some tricky cases. This PR changes `eta_expand` so that it gives the normal form in one step.
xroblot pushed a commit to xroblot/mathlib4 that referenced this pull request Mar 10, 2026
The docstring of `eta_expand` says that it puts terms into a normal form, implying that it is idempontent, however, this is not the case in some tricky cases. This PR changes `eta_expand` so that it gives the normal form in one step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants