Improve sine and cosine of power series#2663
Merged
fredrik-johansson merged 10 commits intoflintlib:mainfrom May 7, 2026
Merged
Improve sine and cosine of power series#2663fredrik-johansson merged 10 commits intoflintlib:mainfrom
fredrik-johansson merged 10 commits intoflintlib:mainfrom
Conversation
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.
Until now, we computed sine and cosine of power series of high order via the tangent, which in turn uses Newton iteration to invert the arctangent. It is faster to use a direct simultaneous Newton iteration for the sine and cosine, which can be derived from that for$\exp(i h)$ (without actually using complex arithmetic). Detailed PR content:
Add
_gr_poly_sin_cos_series_newton/gr_poly_sin_cos_series_newton(implemented using Claude, first by asking it to adapt_gr_poly_exp_seriesfor sine and cosine computation, then making various improvements to the initial working version).Add the following functions (and their underscore versions), with automatic selection between basecase and Newton algorithms, plus test code:
gr_poly_sin_cos_pi_seriesgr_poly_sin_pi_seriesgr_poly_cos_pi_seriesgr_poly_sin_cos_seriesgr_poly_sin_seriesgr_poly_cos_seriesAdd their wrappers for power series and truncated power series in the
gr_seriesmodule:gr_series_mod_singr_series_mod_cosgr_series_mod_sin_pigr_series_mod_cos_pigr_series_mod_sin_cosgr_series_mod_sin_cos_pigr_series_singr_series_cosgr_series_sin_pigr_series_cos_pigr_series_sin_cosgr_series_sin_cos_piUse the new GR algorithm in
nmod_poly_sin_series,nmod_poly_cos_series,arb_poly_sin_series,arb_poly_cos_series,arb_poly_sin_pi_series,arb_poly_cos_pi_series,arb_poly_sin_cos_series,arb_poly_sin_cos_pi_series,acb_poly_sin_series,acb_poly_cos_series,acb_poly_sin_pi_series,acb_poly_cos_pi_series,acb_poly_sin_cos_series,acb_poly_sin_cos_pi_series, improving performance of these methodsMajor bug fix:
_acb_poly_sin_cos_seriesalways computed with 53 bit precision (for n > 2).Small optimization (reciprocal precomputation) of
_gr_poly_sin_cos_series_basecasewhen used in finite characteristicOther minor cleanup and fixes
Still missing is an
fmpq_polyversion of the Newton algorithm.Timings for
nmod_poly_sin_series, 64-bit modulus:Timings for$\log(1+x)$ :
arb_poly_sin_series, 1024-bit precision, inputYou may note that the new algorithm is a lot more numerically stable for large n, though this may vary with the input.
Timings for
arb_poly_sin_cos_serieswith the same input: