Skip to content

[Merged by Bors] - perf: replace many instances of 'linarith' with 'omega'#19951

Closed
dwrensha wants to merge 2 commits intomasterfrom
linarith-to-omega
Closed

[Merged by Bors] - perf: replace many instances of 'linarith' with 'omega'#19951
dwrensha wants to merge 2 commits intomasterfrom
linarith-to-omega

Conversation

@dwrensha
Copy link
Copy Markdown
Member

@dwrensha dwrensha commented Dec 14, 2024

Replaces 63 usages of linarith or nlinarith with omega. In all of these cases I have observed the new proof to be faster.

I found these improvements by running tryAtEachStep to try omega at every tactic step in mathlib.

This is a continuation of the work from #11093.


Open in Gitpod

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 14, 2024

PR summary 47605f6eb5

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

@dwrensha
Copy link
Copy Markdown
Member Author

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 9bf532e.
There were no significant changes against commit d1fa45b.

Copy link
Copy Markdown
Contributor

@grunweg grunweg left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this change, would review again! I double-check against the benchmarking output that all changed files really got faster (some very substantially so).
If you find more of these, I'll be happy to review that PR also.
maintainer merge

mul_comm (2 : K), add_sub_cancel, neg_neg, add_sub, Nat.cast_inj,
eq_sub_iff_add_eq, ← Nat.cast_add, ← sub_eq_neg_add, sub_eq_iff_eq_add] at this
linarith [this, hn]
omega
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.

This change seems to be within noise, but it's shorter - I'll take it.

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.

Actually: perhaps this change didn't get benchmarked yet --- that would explain things.

exact (cs.length_mul_simple w i).resolve_right (by omega)
· intro _
linarith
omega
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.

This file even sped up by 25%, nice!

obtain ⟨⟨x, m, (rfl : algebraMap R S t ^ m = x)⟩, e⟩ := hp'
by_cases hp' : 1 ≤ p.natDegree; swap
· obtain rfl : p = 1 := eq_one_of_monic_natDegree_zero hp (by nlinarith)
· obtain rfl : p = 1 := eq_one_of_monic_natDegree_zero hp (by omega)
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.

This change speeds up the file by 8%, nice!

@grunweg grunweg changed the title chore: replace many instances of 'linarith' with 'omega' perf: replace many instances of 'linarith' with 'omega' Dec 14, 2024
@github-actions
Copy link
Copy Markdown

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

@github-actions github-actions bot added the maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. label Dec 14, 2024
@jcommelin
Copy link
Copy Markdown
Member

Thanks 🎉

bors merge

@ghost ghost added the ready-to-merge This PR has been sent to bors. label Dec 14, 2024
mathlib-bors bot pushed a commit that referenced this pull request Dec 14, 2024
Replaces 63 usages of `linarith` or `nlinarith` with `omega`. In all of these cases I have observed the new proof to be faster.

I found these improvements by running [tryAtEachStep](https://github.com/dwrensha/tryAtEachStep) to try `omega` at every tactic step in mathlib.

This is a continuation of the work from #11093.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Dec 14, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title perf: replace many instances of 'linarith' with 'omega' [Merged by Bors] - perf: replace many instances of 'linarith' with 'omega' Dec 14, 2024
@mathlib-bors mathlib-bors bot closed this Dec 14, 2024
@mathlib-bors mathlib-bors bot deleted the linarith-to-omega branch December 14, 2024 10:55
@dwrensha
Copy link
Copy Markdown
Member Author

I maybe should have also mentioned:
tryAtEachStep reported that in all of these cases the new proof term is smaller than the old one (based on length of pretty-printed string).

tryAtEachStep does not report elaboration time or kernel checking time, but that's something I'd like to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer-merge A reviewer has approved the changed; awaiting maintainer approval. ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants