feat: add Dyadic.divAtPrec for round-down dyadic division at given precision#13654
Open
kim-em wants to merge 5 commits into
Open
feat: add Dyadic.divAtPrec for round-down dyadic division at given precision#13654kim-em wants to merge 5 commits into
kim-em wants to merge 5 commits into
Conversation
…ecision This PR adds `Dyadic.divAtPrec a b prec`, returning the greatest dyadic with precision at most `prec` which is less than or equal to `a/b` (and `0` when `b = 0`). Mirroring the existing `invAtPrec`, the characterising lemmas `divAtPrec_mul_le` and `lt_divAtPrec_add_inc_mul` are also provided. Compared to composing `invAtPrec` with multiplication, `divAtPrec` rounds `a/b` down uniformly (no sign-dependent rounding flip), states the precision at the output rather than requiring callers to back-solve from `‖a‖`, and fuses the bignum division with renormalisation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
Discharges the existing TODOs by adding `eq_invAtPrec` and `eq_divAtPrec`, factored through a public helper `eq_toDyadic_of_precision_le`: any dyadic with precision at most `prec` lying in `[y.toRat, y.toRat + 2 ^ (-prec))` is the floor of `q` at that precision. Adds a (non-public) import of `Init.Data.Int.Order` for `Int.le_antisymm` and `Int.lt_add_one_iff`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Hoist the `hxr`/`hbr` bridges from `0 < x` to `0 < x.toRat` to the top of each proof and inline them at the use sites, replacing the repeated `have h_pos`, `have h_le`, and inline `Rat.ne_of_gt`/`Rat.le_of_lt` derivations. Also drops the trailing intermediate `have`s in favour of direct `calc` steps. No semantic changes; ~38 fewer lines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 7, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 7, 2026
…q_divAtPrec_one` Add `invAtPrec_eq_divAtPrec_one`, the (theorem-level only) equality `invAtPrec x prec = divAtPrec 1 x prec`. The definition of `invAtPrec` is left untouched so its runtime path remains tight. The three characterising lemmas about `invAtPrec` now follow as one-line corollaries of their `divAtPrec` counterparts. Also add two strict bounds relating `a * invAtPrec b prec` to `divAtPrec a b prec` (which are *not* equal in general): each isolates `a * invAtPrec b prec` on one side, with the two pinning the gap to within `2 ^ (-prec)` and `a * 2 ^ (-prec)` respectively. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 8, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 8, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
May 8, 2026
…ic.Inv The previous commit's docstrings overstated two things. `invAtPrec` is now only propositionally equal to `divAtPrec 1`, not definitionally; and the gap between `a * invAtPrec b prec` and `divAtPrec a b prec` is asymmetric — bounded by `2 ^ (-prec)` on one side and by `a * 2 ^ (-prec)` on the other, not by `a * 2 ^ (-prec)` in both directions. Update the prose to match the theorems. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 11, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 11, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds
Dyadic.divAtPrec a b prec, returning the greatest dyadic with precision at mostprecwhich is less than or equal toa/b(and0whenb = 0). Mirroring the existinginvAtPrec, the characterising lemmasdivAtPrec_mul_leandlt_divAtPrec_add_inc_mulare also provided.Compared to composing
invAtPrecwith multiplication,divAtPrecroundsa/bdown uniformly (no sign-dependent rounding flip), states the precision at the output rather than requiring callers to back-solve from‖a‖, and fuses the bignum division with renormalisation.invAtPrecremains the right primitive when the reciprocal is reused.Closes #13653.
🤖 Prepared with Claude Code