Improved radix division, helpers, sqrt(2) and exp(1) profile program#2583
Merged
fredrik-johansson merged 5 commits intoflintlib:mainfrom Feb 20, 2026
Merged
Improved radix division, helpers, sqrt(2) and exp(1) profile program#2583fredrik-johansson merged 5 commits intoflintlib:mainfrom
fredrik-johansson merged 5 commits intoflintlib:mainfrom
Conversation
…ate square roots of small integers
d5f7320 to
bbc2c95
Compare
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.
The main improvement in this PR is to speed up
radix_divremin the average case by incorporating the quotient trick: instead of computing the full remainder to determine the rounding of the quotient, compute an extra fraction limb of the quotient and see if this allows determining the correct rounding. With high probability, we then just need to compute the low half of the remainder, and we can skip the remainder completely when we want just the quotient.In order to make this legal, I had to work out an error bound for
radix_inv_approxand for the division code. The derivation of the bound is sketched in comments. I'm reasonably confident that the bound is correct, but I'll probably redo it more carefully in the future when the division code is more final (Karp-Markstein being the big missing optimization).Additional new helper functions added in this PR:
radix_mul_1radix_mul_tworadix_divrem_tworadix_rsqrt_1_approx_basecaseradix_rsqrt_1_approxNew profile for division with remainder:
New profile for truncating division:
The
radixdivision code is now quite competitive with ourmpn/fmpzcode and even slightly faster around 100000 digits, despite the Karp-Markstein trick not even being used yet. This hints that some decent improvements are possible for thempn/fmpzcode.This PR also adds a profile program for computing the constants$\sqrt{2}$ and $e$ with
radixfixed-point arithmetic and comparing these to the current Arb algorithms. (This will be more interesting with a futureradixball arithmetic type.)Sample run:
For$\sqrt{2}$ ,
radixis essentially as fastarb(suggesting thatarb_sqrtindeed can be improved), and much faster when one includes the time to convert to decimal.For$e$ ,
radixis slightly slower thanarb, but slightly faster overall when one includes the time to convert to decimal.