Diophantine reduction for exp, sin, cos, tan in the fixed module - #2845
Merged
Merged
Conversation
fredrik-johansson
force-pushed
the
diophantine2
branch
from
September 18, 2026 22:19
c78b689 to
6a15460
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.
This reimplements arb's Diophantine argument reduction for elementary functions in the
fixedmodule along with larger lookup tables allowing one to use more primes than arb's default n = 13, currently up to n = 48.fixed_exp_diophantine- exp on [0, 1) by reduction against logarithms of the first n primes.fixed_sin_cos_diophantine,fixed_tan_diophantine- the trigonometric counterpart using Gaussian primes.fixed_rel_table) - precomputed for n = 2, 4, 6, 8, 10, 12, 13, 16, 20, 24, 32, 40, 48 in both the rational and Gaussian cases; any other n up to 64 is generated on first use and cached per thread. arb's 13-prime tables are removed in favour of thesefixed_machin_table) - arb's sets, plus new ones for n = 32, 40, 48 of each kind and every intermediate size up to 32, taken from fredrik-johansson/machin. The coefficient matrices are not stored: they are reconstructed on first use by factoring the arguments and inverting the exponent matrix (<1 ms, under 1% of an evaluation at 10⁵ bits and above), which keeps the table file at ~50 KB instead of ~275 KB.arb_log_primes_vec_bsplit/arb_atan_gauss_primes_vec_bsplitnow use the shared tables, so they gain the larger sets and the intermediate sizes; their previous hand-written size dispatch and 32-bit-only fallback sets are gone.examples/machin.cadditionally verifies some of FLINT's tabulated formulas exactly withcaDeveloped using Claude Fable 5.1 and Opus 5.
Baselines
Absolute time to evaluate the elementary functions without any precomputations:
exp_notabsin_cos_notabsin_cos_notab/exp_notabexp
Timings (precomp / warm) are relative to computing the exponential function with the table-free
fixed_exp_notab. So15.22 / 0.246means that a first call requires 15x as much time as a table-free evaluation for precomputations, while subsequent evaluations with a warm cache are 4x faster than the table-free evaluation.sin_cos
Break-even
How many times one needs to call the function for the precomputation to pay off vs no precomputation at all.
exp
sin_cos
bitwise against diophantine (32 primes)
Note:
fixed_exp_diophantineandfixed_sin_cos_diophantineare 1.2-1.6x faster thanarb_expandarb_sin_coswhen using arb's default n=13.