Overhaul tan-like functions of power series#2672
Merged
Merged
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.
We improve
gr_poly_tan_seriesand add the following variants (with their underscore methods):gr_poly_tanh_seriesgr_poly_cot_seriesgr_poly_coth_seriesgr_poly_tan_pi_seriesgr_poly_cot_pi_seriesWe also add wrappers of all these methods for
gr_seriesandgr_series_mod.Also,
arb_poly_tan_series,arb_poly_cot_pi_seriesacb_poly_tan_series,acb_poly_cot_pi_series,nmod_poly_tan_seriesandnmod_poly_tanh_seriesmethods are converted to wrappers or simplified in cases where they already partially relied on agr_polymethod. If wanted, one could trivially add more wrappers, e.g.arb_poly_tanh_series.Algorithm changes:
for the tangent coefficients themselves, which is more efficient.
gr_tan_series_basecase_sine_cosineas an alternative algorithm to explicitly use the sine/cosine quotient approach.gr_tan_series_exponentialwhich uses a quotient of exponentials. For numerical arguments, this attempts to choose the sign of the exponent so that the formula is numerically stable.Importantly: all six implemented functions (tan, tanh, cot, coth, tan_pi, cot_pi) use the same underlying code with the same heuristic for switching algorithms, the only difference between the functions being some signs and scaling factors. Note that previously
acb_poly_cot_pi_seriesswitched between sines, cosines and exponentials depending on the location of the input in the complex plane, butacb_poly_tan_seriesonly used the sine/cosine formula and would lose precision for large imaginary input. Now all functions should have the same numerical stability qualities.I let Claude write parts of the new code, but I'm not sure if this was faster than doing it entirely by hand as it got stuck long time unsuccessfully trying to debug a sign error in its Newton iteration code. I eventually gave up and fixed that myself.
Timings,
tan_series,nmodwith 64-bit modulus:Again
nmod,tanh_series:Timings for$h = \exp(x) - 1$ :
tan_serieswithfmpqcoefficients, input seriesResults for$h = \exp(x)$ :
tan_serieswitharbcoefficients, prec = 1024, inputResults for$h = \exp(x)-1 + (1/3 + 50i)$ :
cot_pi_serieswithacbcoefficients, prec = 1024, inputThere is actually some more precision loss in the new code for large
n, but I think this is due to differences inacb_poly_exp_seriesvsgr_poly_exp_seriesthat want independent fixing.Results for$h = \exp(x)-1 + (1/3 + 12345.6i)$ :
tan_serieswithacbcoefficients, prec = 1024, input