Skip to content

Comments

chore(NumberTheory/Zsqrtd): inline duplicated order lemmas into instances#35481

Open
FrankieeW wants to merge 11 commits intoleanprover-community:masterfrom
FrankieeW:addpro-2
Open

chore(NumberTheory/Zsqrtd): inline duplicated order lemmas into instances#35481
FrankieeW wants to merge 11 commits intoleanprover-community:masterfrom
FrankieeW:addpro-2

Conversation

@FrankieeW
Copy link

@FrankieeW FrankieeW commented Feb 18, 2026

This PR follows reviewer feedback by removing duplicated order/additive wrapper theorems in Zsqrtd and inlining the proofs into the corresponding typeclass instances.

Changes include:

  • remove redundant wrappers such as Zsqrtd.le_total, Zsqrtd.add_le_add_left, Zsqrtd.le_of_add_le_add_left, Zsqrtd.add_lt_add_left, and Zsqrtd.le_antisymm
  • keep the canonical API through LinearOrder / ordered additive structure fields
  • update downstream use in PellMatiyasevic to the canonical theorem (_root_.le_antisymm)

This reduces namespace-level duplicate APIs and keeps proofs aligned with standard typeclass lemmas.


Open in Gitpod

@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Feb 18, 2026
@github-actions
Copy link

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions
Copy link

github-actions bot commented Feb 18, 2026

PR summary 965b9674be

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

@github-actions github-actions bot added the t-number-theory Number theory (also use t-algebra or t-analysis to specialize) label Feb 18, 2026
Copy link
Collaborator

@vihdzp vihdzp left a comment

Choose a reason for hiding this comment

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

For precisely the reason you give, we should not have this theorem! It should either be made private, or inlined into the linear order instance.

There's a few other theorems in this file like this, such as ZSqrtd.le_total and ZSqrtd.add_le_add_left. Could you fix these too?

FrankieeW and others added 2 commits February 19, 2026 20:16
Inline `le_antisymm`, `le_total`, `add_le_add_left` into the
`LinearOrder`, `Preorder`, and `IsOrderedAddMonoid` instances
respectively, and remove the standalone theorems that shadowed
root namespace names.

Also remove `le_of_add_le_add_left` and `add_lt_add_left` which
were only used internally.

Update `PellMatiyasevic.lean` to use typeclass `le_antisymm`.
@FrankieeW FrankieeW changed the title chore(NumberTheory/Zsqrtd): mark le_antisymm theorem as protected chore(NumberTheory/Zsqrtd): inline duplicated order lemmas into instances Feb 19, 2026
@FrankieeW
Copy link
Author

Addressed, thanks! I inlined the duplicated order/additive wrapper lemmas into the corresponding instances (including le_total / add_le_add_left / le_antisymm-related wrappers), updated downstream usage to canonical typeclass lemmas, and CI is now green. I also updated the PR title/body to match the final scope. Could you please take another look?

@FrankieeW FrankieeW requested a review from vihdzp February 19, 2026 20:46
| ⟨(_ + 1 : ℕ), -[_+1]⟩ => Nat.le_total _ _
| ⟨-[_+1], (_ + 1 : ℕ)⟩ => Nat.le_total _ _

protected theorem le_total (a b : ℤ√d) : a ≤ b ∨ b ≤ a := by
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you deprecate these instead of removing them outright? As an example:

@[deprecated (since := "2026-02-19") _root_.le_total]

le_trans a b c hab hbc := by simpa [sub_add_sub_cancel'] using hab.add hbc
lt_iff_le_not_ge _ _ := (and_iff_right_of_imp (Zsqrtd.le_total _ _).resolve_left).symm
lt_iff_le_not_ge a b := by
have ht : b ≤ a ∨ a ≤ b := by
Copy link
Collaborator

Choose a reason for hiding this comment

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

This lemma is used twice before the linear order instance is properly built, perhaps that means it should stay but as a private lemma?

exact (and_iff_right_of_imp ht.resolve_left).symm

open Int in
theorem le_arch (a : ℤ√d) : ∃ n : ℕ, a ≤ n := by
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a duplicate of exists_nat_ge, which is implied by the Archimedean typeclass.

@vihdzp vihdzp added the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Feb 20, 2026
Copy link
Collaborator

@vihdzp vihdzp left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM. Thanks for taking care of this, and welcome to Mathlib!

exact (and_iff_right_of_imp ht.resolve_left).symm

open Int in
@[deprecated "Use `exists_nat_ge` where available." (since := "2026-02-19")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just checked, turns out we don't have an Archimedean instance yet! Can you please leave a TODO for this?

@github-actions github-actions bot removed the awaiting-CI This PR does not pass CI yet. This label is automatically removed once it does. label Feb 20, 2026
@FrankieeW
Copy link
Author

Thank you for the review and the helpful guidance! I addressed the requested changes and left a TODO on le_arch noting that an Archimedean (Zsqrtd) instance is not available yet, so callers can migrate to exists_nat_ge once that instance is in place. I will keep watching CI.

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

Labels

new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! 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.

3 participants