Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - chore(data/int/gcd): streamline imports #16811

Closed
wants to merge 21 commits into from

Conversation

hrmacbeth
Copy link
Member

The file on gcds of integers is fundamentally very elementary, but it contained two lemmas about prime numbers, and data.nat.prime seems to import everything (modules! half the order library!).


Open in Gitpod

@hrmacbeth hrmacbeth added awaiting-review The author would like community review of the PR awaiting-CI The author would like to see what CI has to say before doing more work. t-number-theory Number theory (also use t-algebra or t-analysis to specialize) labels Oct 5, 2022
hrmacbeth and others added 3 commits October 5, 2022 02:32
Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com>
@YaelDillies
Copy link
Collaborator

Given that this doesn't seem to be API lemmas, would it make more sense to put in the tactic.norm_num folder?

@hrmacbeth
Copy link
Member Author

hrmacbeth commented Oct 5, 2022

I can even put it in the main norm_num later, but I want to avoid causing a merge conflict with PR 16588, because fixing the conflict would cause that PR to lose its seniority on the PR queue.

I'm also avoiding referencing that PR by hyperlink, for the same reason :)

@YaelDillies
Copy link
Collaborator

Surely referencing a PR doesn't reset its position on the PR queue?

@hrmacbeth
Copy link
Member Author

I don't know, but I'd rather not risk it :)

@alreadydone
Copy link
Collaborator

Let me try to reference my PR #16804

@YaelDillies
Copy link
Collaborator

YaelDillies commented Oct 6, 2022

Tough luck, it's not on the queue. #15289 is however.

EDIT: Indeed it doesn't move it.

@alreadydone
Copy link
Collaborator

alreadydone commented Oct 6, 2022

Result: it doesn't change its position in the github default ranking https://github.com/leanprover-community/mathlib/pulls (but I've observed that even adding one review comment without actually publicizing it will pop the PR up to the top of this page).

(The default uses sort:updated-desc which is exactly opposite to sort:updated-asc used by #queue, but the criterion for "updated" should be the same.)

Oh sorry, github default is actually descending numeric order if I'm not logged in; updated-desc is probably my personal preference setting.

@hrmacbeth
Copy link
Member Author

hrmacbeth commented Oct 6, 2022

#16588 is now merged, but I decided to move the norm_num plugin back into the file for this PR. It makes the diff clearer, and it's not nearly as heavy an import as data.nat.prime.

hrmacbeth and others added 6 commits October 6, 2022 21:41


Co-authored-by: Andrew Yang <36414270+erdOne@users.noreply.github.com>
## Historical background

This tackles a problem that we have had for six years (#2697 for its move to mathlib, before it was in core): `ordered_semiring` assumes that addition and multiplication are strictly monotone.

This led to weirdness within the algebraic order hierarchy:
* `ennreal`/`ereal`/`enat` needed custom lemmas (`∞ + 0 = ∞ = ∞ + 1`, `1 * ∞ = ∞ = 2 * ∞`).
* A `canonically_ordered_comm_semiring` was not an `ordered_comm_semiring`!

## What this PR does

This PR solves the problem minimally by renaming `ordered_(comm_)semiring` to `strict_ordered_(comm_)semiring` and adding a new class `ordered_(comm_)semiring` that doesn't assume strict monotonicity of addition and multiplication but only monotonicity:
```
class ordered_semiring (α : Type*) extends semiring α, ordered_add_comm_monoid α :=
(zero_le_one : (0 : α) ≤ 1)
(mul_le_mul_of_nonneg_left  : ∀ a b c : α, a ≤ b → 0 ≤ c → c * a ≤ c * b)
(mul_le_mul_of_nonneg_right : ∀ a b c : α, a ≤ b → 0 ≤ c → a * c ≤ b * c)

class ordered_comm_semiring (α : Type*) extends ordered_semiring α, comm_semiring α

class ordered_ring (α : Type u) extends ring α, ordered_add_comm_group α :=
(zero_le_one : 0 ≤ (1 : α))
(mul_nonneg : ∀ a b : α, 0 ≤ a → 0 ≤ b → 0 ≤ a * b)

class ordered_comm_ring (α : Type u) extends ordered_ring α, comm_ring α

class strict_ordered_semiring (α : Type*) extends semiring α, ordered_cancel_add_comm_monoid α :=
(zero_le_one : (0 : α) ≤ 1)
(mul_lt_mul_of_pos_left  : ∀ a b c : α, a < b → 0 < c → c * a < c * b)
(mul_lt_mul_of_pos_right : ∀ a b c : α, a < b → 0 < c → a * c < b * c)

class strict_ordered_comm_semiring (α : Type*) extends strict_ordered_semiring α, comm_semiring α

class strict_ordered_ring (α : Type u) extends ring α, ordered_add_comm_group α :=
(zero_le_one : 0 ≤ (1 : α))
(mul_pos     : ∀ a b : α, 0 < a → 0 < b → 0 < a * b)

class strict_ordered_comm_ring (α : Type*) extends strict_ordered_ring α, comm_ring α
```

## Whatever happened to the `decidable` lemmas?

Scrolling through the diff, you will see that only one lemma in the `decidable` namespace out of many survives this PR. Those lemmas were originally meant to avoid using choice in the proof of `nat` and `int` lemmas.

The need for decidability originated from the proofs of `mul_le_mul_of_nonneg_left`/`mul_le_mul_of_nonneg_right`.
```
protected lemma decidable.mul_le_mul_of_nonneg_left [@decidable_rel α (≤)]
  (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b :=
begin
  by_cases ba : b ≤ a, { simp [ba.antisymm h₁] },
  by_cases c0 : c ≤ 0, { simp [c0.antisymm h₂] },
  exact (mul_lt_mul_of_pos_left (h₁.lt_of_not_le ba) (h₂.lt_of_not_le c0)).le,
end
```
Now that these are fields to `ordered_semiring`, they are already choice-free. Instead, choice is now used in showing that an `ordered_cancel_semiring` is an `ordered_semiring`.
```
@[priority 100] -- see Note [lower instance priority]
instance ordered_cancel_semiring.to_ordered_semiring : ordered_semiring α :=
{ mul_le_mul_of_nonneg_left := λ a b c hab hc, begin
    obtain rfl | hab := hab.eq_or_lt,
    { refl },
    obtain rfl | hc := hc.eq_or_lt,
    { simp },
    { exact (mul_lt_mul_of_pos_left hab hc).le }
  end,
  mul_le_mul_of_nonneg_right := λ a b c hab hc, begin
    obtain rfl | hab := hab.eq_or_lt,
    { refl },
    obtain rfl | hc := hc.eq_or_lt,
    { simp },
    { exact (mul_lt_mul_of_pos_right hab hc).le }
  end,
  ..‹ordered_cancel_semiring α› }
```
It seems unreasonable to make that instance depend on `@decidable_rel α (≤)` even though it's only needed for the proofs.

## Other changes

To have some lemmas in the generality of the new `ordered_semiring`, I needed a few new lemmas:
* `bit0_mono`
* `bit0_strict_mono`

It was also simpler to golf `analysis.special_functions.stirling` using `positivity` rather than fixing it so I introduce the following (simple) `positivity` extensions:
* `positivity_succ`
* `positivity_factorial`
* `positivity_asc_factorial`
…degeneracy (#16779)

In this PR, it is shown that the Čech nerve of a split epimorphism has an extra degeneracy. It is also shown that if two augmented simplicial objects are isomorphic, then an extra degeneracy for one of these transports as an extra degeneracy for the other.
…6844)

Squeeze simps and replace a slow `convert` by `eq.subst` with explicit motive (maybe `convert` was unfolding the instances?).

From >20s to 4s on my machine.
@hrmacbeth hrmacbeth removed the awaiting-review The author would like community review of the PR label Oct 7, 2022
@github-actions github-actions bot removed the awaiting-CI The author would like to see what CI has to say before doing more work. label Oct 7, 2022
@hrmacbeth hrmacbeth added the awaiting-review The author would like community review of the PR label Oct 9, 2022
@sgouezel
Copy link
Collaborator

bors r+
Thanks!

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Oct 10, 2022
bors bot pushed a commit that referenced this pull request Oct 10, 2022
The file on gcds of integers is fundamentally very elementary, but it contained two lemmas about prime numbers, and `data.nat.prime` seems to import everything (modules! half the order library!).



Co-authored-by: Andrew Yang <the.erd.one@gmail.com>
Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>
Co-authored-by: Joël Riou <joel.riou@universite-paris-saclay.fr>
Co-authored-by: Junyan Xu <junyanxumath@gmail.com>
@bors
Copy link

bors bot commented Oct 10, 2022

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title chore(data/int/gcd): streamline imports [Merged by Bors] - chore(data/int/gcd): streamline imports Oct 10, 2022
@bors bors bot closed this Oct 10, 2022
@bors bors bot deleted the move-prime-from-gcd branch October 10, 2022 11:52
@eric-wieser eric-wieser added the hacktoberfest-accepted Without this label hacktoberfest is scared off by bors label Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Without this label hacktoberfest is scared off by bors ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) t-number-theory Number theory (also use t-algebra or t-analysis to specialize)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants