Skip to content

[Merged by Bors] - chore: abel_nf bug - #29778

Closed
hrmacbeth wants to merge 3 commits into
masterfrom
abel_nf-bugfix
Closed

hrmacbeth wants to merge 3 commits into
masterfrom
abel_nf-bugfix

Conversation

@hrmacbeth

@hrmacbeth hrmacbeth commented Sep 18, 2025 •

Copy link
Copy Markdown
Member

Fix the bug reported at https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/abel_nf.20bug/with/540086130.

Context: when abel_nf runs on a statement e, it is supposed to run abelian-group-normalization only on subexpressions of e which would not be treated as atoms by the normalization algorithm. For example, in the statement log (sin (x + y + y)) + log (sin (y + x + y)) = z the normalization should be run

  • on x + y + y => x + 2y
  • on y + x + y => x + 2y
  • on log (sin (x + 2y)) + log (sin (x + 2y)) => 2 log (sin (x + 2y))

but not on x, y, z, sin (x + 2y), log (sin (x + 2y)) or 2 log (sin (x + 2y)) = z. This saves work, and also keeps the table of atoms smaller (e.g. in the above example z, sin (x + 2y) and 2 log (sin (x + 2y)) = z never join the atoms table since they never appear as atomic subexpressions of abelian-group expressions).

The issue fixed in this PR was that the atoms check was logically incorrect: instead of testing whether a subexpression t was non-atomic before normalizing it, we tested -- after normalizing it! -- whether its normalized form t' was non-atomic.


Open in Gitpod

@hrmacbeth hrmacbeth added the t-meta Tactics, attributes or user commands label Sep 18, 2025
@github-actions

github-actions Bot commented Sep 18, 2025 •

Copy link
Copy Markdown

PR summary 937c0944a5

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ isAtom

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

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

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


No changes to technical debt.

You can run this locally as

./scripts/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).

Comment thread Mathlib/Tactic/Abel.lean Resolved
@JovanGerb

Copy link
Copy Markdown
Contributor

Could you explain somewhere what went wrong before and how this is now fixed?

@hrmacbeth

Copy link
Copy Markdown
Member Author

Could you explain somewhere what went wrong before and how this is now fixed?

I added an explanation to the PR description, and a cross-reference to this PR in the test.

@JovanGerb

Copy link
Copy Markdown
Contributor

Thanks!

maintainer merge

@github-actions

Copy link
Copy Markdown

🚀 Pull request has been placed on the maintainer queue by JovanGerb.

@ghost ghost added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Sep 19, 2025
Comment thread Mathlib/Tactic/Abel.lean
`Mathlib.Tactic.Abel.eval` metaprogram. -/
def isAtom (e : Expr) : Bool :=
match e.getAppFnArgs with
| (``HAdd.hAdd, #[_, _, _, _, _, _])

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.

Here and in the remaining match-arms, why are you also enforcing that the number of arguments is what it is? Why not using

Suggested change
| (``HAdd.hAdd, #[_, _, _, _, _, _])
| (``HAdd.hAdd, _)

instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The immediate reason is that this function is supposed to have the same expression-parsing structure as the above (more important) function Mathlib.Tactic.Abel.eval, and eval does it this way!

The reason (I suppose) why eval does it this way is that an HAdd.hAdd expression with fewer inputs, like @HAdd.hAdd Nat Nat Nat instHAdd x, i.e. fun y ↦ x + y, cannot be handled by the abel-normalization algorithm.

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.

Ah, I had not thought of partial applications, thanks!

bors merge

@ghost ghost added ready-to-merge This PR has been sent to bors. and removed maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. labels Sep 19, 2025
mathlib-bors Bot pushed a commit that referenced this pull request Sep 19, 2025
Fix the bug reported at https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/abel_nf.20bug/with/540086130.

Context: when `abel_nf` runs on a statement `e`, it is supposed to run abelian-group-normalization only on subexpressions of `e` which would not be treated as atoms by the normalization algorithm.  For example, in the statement `log (sin (x + y + y)) + log (sin (y + x + y)) = z` the normalization should be run
- on `x + y + y` => `x + 2y`
- on `y + x + y` => `x + 2y`
- on `log (sin (x + 2y)) + log (sin (x + 2y))` =>  `2 log (sin (x + 2y))`

but not on `x`, `y`, `z`, `sin (x + 2y)`, `log (sin (x + 2y))` or `2 log (sin (x + 2y)) = z`. This saves work, and also keeps the table of atoms smaller (e.g. in the above example `z`, `sin (x + 2y)` and `2 log (sin (x + 2y)) = z` never join the atoms table since they never appear as atomic subexpressions of abelian-group expressions).

The issue fixed in this PR was that the atoms check was logically incorrect: instead of testing whether a subexpression `t` was non-atomic *before* normalizing it, we tested -- *after* normalizing it! -- whether its normalized form `t'` was non-atomic.
@mathlib-bors

mathlib-bors Bot commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title chore: abel_nf bug [Merged by Bors] - chore: abel_nf bug Sep 19, 2025
@mathlib-bors mathlib-bors Bot closed this Sep 19, 2025
@mathlib-bors
mathlib-bors Bot deleted the abel_nf-bugfix branch September 19, 2025 09:07
joelriou pushed a commit to joelriou/mathlib4 that referenced this pull request Oct 2, 2025
Fix the bug reported at https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/abel_nf.20bug/with/540086130.

Context: when `abel_nf` runs on a statement `e`, it is supposed to run abelian-group-normalization only on subexpressions of `e` which would not be treated as atoms by the normalization algorithm.  For example, in the statement `log (sin (x + y + y)) + log (sin (y + x + y)) = z` the normalization should be run
- on `x + y + y` => `x + 2y`
- on `y + x + y` => `x + 2y`
- on `log (sin (x + 2y)) + log (sin (x + 2y))` =>  `2 log (sin (x + 2y))`

but not on `x`, `y`, `z`, `sin (x + 2y)`, `log (sin (x + 2y))` or `2 log (sin (x + 2y)) = z`. This saves work, and also keeps the table of atoms smaller (e.g. in the above example `z`, `sin (x + 2y)` and `2 log (sin (x + 2y)) = z` never join the atoms table since they never appear as atomic subexpressions of abelian-group expressions).

The issue fixed in this PR was that the atoms check was logically incorrect: instead of testing whether a subexpression `t` was non-atomic *before* normalizing it, we tested -- *after* normalizing it! -- whether its normalized form `t'` was non-atomic.
zhuyizheng pushed a commit to zhuyizheng/mathlib4 that referenced this pull request Oct 2, 2025
Fix the bug reported at https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/abel_nf.20bug/with/540086130.

Context: when `abel_nf` runs on a statement `e`, it is supposed to run abelian-group-normalization only on subexpressions of `e` which would not be treated as atoms by the normalization algorithm.  For example, in the statement `log (sin (x + y + y)) + log (sin (y + x + y)) = z` the normalization should be run
- on `x + y + y` => `x + 2y`
- on `y + x + y` => `x + 2y`
- on `log (sin (x + 2y)) + log (sin (x + 2y))` =>  `2 log (sin (x + 2y))`

but not on `x`, `y`, `z`, `sin (x + 2y)`, `log (sin (x + 2y))` or `2 log (sin (x + 2y)) = z`. This saves work, and also keeps the table of atoms smaller (e.g. in the above example `z`, `sin (x + 2y)` and `2 log (sin (x + 2y)) = z` never join the atoms table since they never appear as atomic subexpressions of abelian-group expressions).

The issue fixed in this PR was that the atoms check was logically incorrect: instead of testing whether a subexpression `t` was non-atomic *before* normalizing it, we tested -- *after* normalizing it! -- whether its normalized form `t'` was non-atomic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors. t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants