Skip to content

[Merged by Bors] - refactor: optimize proofs with omega#11093

Closed
dwrensha wants to merge 94 commits intomasterfrom
tryAtEachStep-omega
Closed

[Merged by Bors] - refactor: optimize proofs with omega#11093
dwrensha wants to merge 94 commits intomasterfrom
tryAtEachStep-omega

Conversation

@dwrensha
Copy link
Copy Markdown
Member

@dwrensha dwrensha commented Mar 1, 2024

I ran tryAtEachStep on all files under Mathlib to find all locations where omega succeeds. For each that was a linarith without an only, I tried replacing it with omega, and I verified that elaboration time got smaller. (In almost all cases, there was a noticeable speedup.) I also replaced some slow aesops along the way.


Open in Gitpod

@dwrensha
Copy link
Copy Markdown
Member Author

dwrensha commented Mar 1, 2024

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit d94f33d.
There were significant changes against commit ab90a4e:

  Benchmark                                                    Metric         Change
  ==================================================================================
+ ~Mathlib.Algebra.Homology.HomotopyCategory.HomComplex        instructions   -15.3%
+ ~Mathlib.Algebra.Homology.HomotopyCategory.HomComplexShift   instructions   -16.8%
+ ~Mathlib.Algebra.Homology.HomotopyCategory.MappingCone       instructions   -21.6%
+ ~Mathlib.AlgebraicTopology.DoldKan.Faces                     instructions   -46.9%
+ ~Mathlib.AlgebraicTopology.SimplexCategory                   instructions   -26.1%
+ ~Mathlib.Computability.AkraBazzi.AkraBazzi                   instructions    -6.5%
+ ~Mathlib.Order.RelSeries                                     instructions   -25.7%

Copy link
Copy Markdown
Contributor

@mattrobball mattrobball left a comment

Choose a reason for hiding this comment

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

Great!

(h₂ : Cochain.ofHom (inr φ ≫ f₁) = δ (-1) 0 γ₂ + Cochain.ofHom (inr φ ≫ f₂)) :
Homotopy f₁ f₂ :=
(Cochain.equivHomotopy f₁ f₂).symm ⟨descCochain φ γ₁ γ₂ (by linarith), by
(Cochain.equivHomotopy f₁ f₂).symm ⟨descCochain φ γ₁ γ₂ (by norm_num), by
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.

One of these is not like the other.

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.

omega works here, but norm_num is even faster.

@mattrobball
Copy link
Copy Markdown
Contributor

bors delegate+

Once CI is green, please send it. Thanks!

@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 2, 2024

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

comp_v z₁ z₂ rfl p (p + n₁) (p + n₁ + n₂) (by linarith) (by linarith),
comp_v z₁ (z₂.comp z₃ rfl) (add_assoc n₁ n₂ n₃).symm p (p + n₁) q (by linarith) (by linarith),
comp_v z₂ z₃ rfl (p + n₁) (p + n₁ + n₂) q (by linarith) (by linarith), assoc]
rw [comp_v _ _ rfl p (p + n₁ + n₂) q (add_assoc _ _ _).symm (by omega),
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.

I added the explicit term add_assoc here because omega seemed to be actually a bit slower than linarith, and writing the term like this was easy enough.

@github-actions github-actions bot added delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed awaiting-review labels Mar 2, 2024
@dwrensha
Copy link
Copy Markdown
Member Author

dwrensha commented Mar 2, 2024

bors r+

mathlib-bors bot pushed a commit that referenced this pull request Mar 2, 2024
I ran [tryAtEachStep](https://github.com/dwrensha/tryAtEachStep) on all files under `Mathlib` to find all locations where `omega` succeeds. For each that was a `linarith` without an `only`, I tried replacing it with `omega`, and I verified that elaboration time got smaller. (In almost all cases, there was a noticeable speedup.) I also replaced some slow `aesop`s along the way.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 2, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title refactor: optimize proofs with omega [Merged by Bors] - refactor: optimize proofs with omega Mar 2, 2024
@mathlib-bors mathlib-bors bot closed this Mar 2, 2024
@mathlib-bors mathlib-bors bot deleted the tryAtEachStep-omega branch March 2, 2024 00:27
kbuzzard pushed a commit that referenced this pull request Mar 12, 2024
I ran [tryAtEachStep](https://github.com/dwrensha/tryAtEachStep) on all files under `Mathlib` to find all locations where `omega` succeeds. For each that was a `linarith` without an `only`, I tried replacing it with `omega`, and I verified that elaboration time got smaller. (In almost all cases, there was a noticeable speedup.) I also replaced some slow `aesop`s along the way.
dagurtomas pushed a commit that referenced this pull request Mar 22, 2024
I ran [tryAtEachStep](https://github.com/dwrensha/tryAtEachStep) on all files under `Mathlib` to find all locations where `omega` succeeds. For each that was a `linarith` without an `only`, I tried replacing it with `omega`, and I verified that elaboration time got smaller. (In almost all cases, there was a noticeable speedup.) I also replaced some slow `aesop`s along the way.
utensil pushed a commit that referenced this pull request Mar 26, 2024
I ran [tryAtEachStep](https://github.com/dwrensha/tryAtEachStep) on all files under `Mathlib` to find all locations where `omega` succeeds. For each that was a `linarith` without an `only`, I tried replacing it with `omega`, and I verified that elaboration time got smaller. (In almost all cases, there was a noticeable speedup.) I also replaced some slow `aesop`s along the way.
xgenereux pushed a commit that referenced this pull request Apr 15, 2024
I ran [tryAtEachStep](https://github.com/dwrensha/tryAtEachStep) on all files under `Mathlib` to find all locations where `omega` succeeds. For each that was a `linarith` without an `only`, I tried replacing it with `omega`, and I verified that elaboration time got smaller. (In almost all cases, there was a noticeable speedup.) I also replaced some slow `aesop`s along the way.
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.
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).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants