Skip to content

Commit 4b6e2ca

Browse files
Merge pull request #2663 from fredrik-johansson/series
Improve sine and cosine of power series
2 parents 1f650d0 + 0e7d2cd commit 4b6e2ca

27 files changed

Lines changed: 1344 additions & 640 deletions

doc/source/gr_poly.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,34 @@ Power series special functions
11651165
int _gr_poly_exp_series(gr_ptr res, gr_srcptr f, slong flen, slong len, gr_ctx_t ctx)
11661166
int gr_poly_exp_series(gr_poly_t f, const gr_poly_t h, slong n, gr_ctx_t ctx)
11671167

1168+
.. function:: int _gr_poly_sin_cos_series(gr_ptr s, gr_ptr c, gr_srcptr h, slong hlen, slong n, gr_ctx_t ctx)
1169+
int _gr_poly_sin_cos_pi_series(gr_ptr s, gr_ptr c, gr_srcptr h, slong hlen, slong n, gr_ctx_t ctx)
1170+
int gr_poly_sin_cos_series(gr_poly_t s, gr_poly_t c, const gr_poly_t h, slong n, gr_ctx_t ctx)
1171+
int gr_poly_sin_cos_pi_series(gr_poly_t s, gr_poly_t c, const gr_poly_t h, slong n, gr_ctx_t ctx)
1172+
int _gr_poly_sin_series(gr_ptr s, gr_srcptr h, slong hlen, slong n, gr_ctx_t ctx)
1173+
int gr_poly_sin_series(gr_poly_t s, const gr_poly_t h, slong n, gr_ctx_t ctx)
1174+
int _gr_poly_sin_pi_series(gr_ptr s, gr_srcptr h, slong hlen, slong n, gr_ctx_t ctx)
1175+
int gr_poly_sin_pi_series(gr_poly_t s, const gr_poly_t h, slong n, gr_ctx_t ctx)
1176+
int _gr_poly_cos_series(gr_ptr c, gr_srcptr h, slong hlen, slong n, gr_ctx_t ctx)
1177+
int gr_poly_cos_series(gr_poly_t c, const gr_poly_t h, slong n, gr_ctx_t ctx)
1178+
int _gr_poly_cos_pi_series(gr_ptr c, gr_srcptr h, slong hlen, slong n, gr_ctx_t ctx)
1179+
int gr_poly_cos_pi_series(gr_poly_t c, const gr_poly_t h, slong n, gr_ctx_t ctx);
1180+
1181+
Compute `s = \sin(h)`, `c = \cos(h)` as power series truncated to length `m`,
1182+
or `s = \sin(\pi h)`, `c = \cos(\pi h)` for the ``pi`` variants.
1183+
The underscore methods allow aliasing.
1184+
11681185
.. function:: int _gr_poly_sin_cos_series_basecase(gr_ptr s, gr_ptr c, gr_srcptr h, slong hlen, slong n, int times_pi, gr_ctx_t ctx)
11691186
int gr_poly_sin_cos_series_basecase(gr_poly_t s, gr_poly_t c, const gr_poly_t h, slong n, int times_pi, gr_ctx_t ctx)
11701187
int _gr_poly_sin_cos_series_tangent(gr_ptr s, gr_ptr c, gr_srcptr h, slong hlen, slong n, int times_pi, gr_ctx_t ctx)
11711188
int gr_poly_sin_cos_series_tangent(gr_poly_t s, gr_poly_t c, const gr_poly_t h, slong n, int times_pi, gr_ctx_t ctx)
1189+
int _gr_poly_sin_cos_series_newton(gr_ptr s, gr_ptr c, gr_srcptr h, slong hlen, slong n, slong cutoff, int times_pi, gr_ctx_t ctx)
1190+
int gr_poly_sin_cos_series_newton(gr_poly_t s, gr_poly_t c, const gr_poly_t h, slong n, slong cutoff, int times_pi, gr_ctx_t ctx)
1191+
1192+
Various algorithms to compute sine and cosine of power series.
1193+
The default functions (:func:`_gr_poly_sin_cos_series` et al.)
1194+
choose an algorithm automatically.
1195+
The *times_pi* flag specifies that the input is to be multiplied by `\pi`.
11721196

11731197
The *basecase* version uses a simple recurrence for the coefficients,
11741198
requiring `O(nm)` operations where `m` is the length of `h`.
@@ -1181,8 +1205,10 @@ Power series special functions
11811205
`\sin(h_0 + h_1) = \cos(h_0) \sin(h_1) + \sin(h_0) \cos(h_1)`,
11821206
`\cos(h_0 + h_1) = \cos(h_0) \cos(h_1) - \sin(h_0) \sin(h_1)`.
11831207

1184-
The *basecase* and *tangent* versions take a flag *times_pi*
1185-
specifying that the input is to be multiplied by `\pi`.
1208+
The *newton* version uses Newton iteration for `\exp(ih)`. The complex
1209+
parts are represented formally; complex arithmetic is not required.
1210+
The *cutoff* parameter specifies the cutoff for using the basecase
1211+
algorithm.
11861212

11871213
.. function:: int _gr_poly_tan_series_basecase(gr_ptr f, gr_srcptr h, slong hlen, slong n, gr_ctx_t ctx)
11881214
int gr_poly_tan_series_basecase(gr_poly_t f, const gr_poly_t h, slong n, gr_ctx_t ctx)

doc/source/gr_series.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,16 @@ directly.
117117
int gr_series_mod_mul(gr_poly_t res, const gr_poly_t x, const gr_poly_t y, gr_ctx_t ctx)
118118
int gr_series_mod_inv(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
119119
int gr_series_mod_div(gr_poly_t res, const gr_poly_t x, const gr_poly_t y, gr_ctx_t ctx)
120-
int gr_series_mod_exp(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
121-
int gr_series_mod_log(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
122120
int gr_series_mod_sqrt(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
123121
int gr_series_mod_rsqrt(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
122+
int gr_series_mod_exp(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
123+
int gr_series_mod_log(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
124+
int gr_series_mod_sin(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
125+
int gr_series_mod_cos(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
126+
int gr_series_mod_sin_pi(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
127+
int gr_series_mod_cos_pi(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
128+
int gr_series_mod_sin_cos(gr_poly_t res1, gr_poly_t res2, const gr_poly_t x, gr_ctx_t ctx)
129+
int gr_series_mod_sin_cos_pi(gr_poly_t res1, gr_poly_t res2, const gr_poly_t x, gr_ctx_t ctx)
124130
int gr_series_mod_tan(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
125131
int gr_series_mod_asin(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
126132
int gr_series_mod_acos(gr_poly_t res, const gr_poly_t x, gr_ctx_t ctx)
@@ -247,6 +253,12 @@ directly.
247253
int gr_series_rsqrt(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
248254
int gr_series_exp(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
249255
int gr_series_log(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
256+
int gr_series_sin(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
257+
int gr_series_cos(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
258+
int gr_series_sin_pi(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
259+
int gr_series_cos_pi(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
260+
int gr_series_sin_cos(gr_series_t res1, gr_series_t res2, const gr_series_t x, gr_ctx_t ctx)
261+
int gr_series_sin_cos_pi(gr_series_t res1, gr_series_t res2, const gr_series_t x, gr_ctx_t ctx)
250262
int gr_series_tan(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
251263
int gr_series_asin(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)
252264
int gr_series_acos(gr_series_t res, const gr_series_t x, gr_ctx_t ctx)

doc/source/nmod_poly.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,23 +2431,19 @@ of polynomial multiplication.
24312431

24322432
Set `g = \operatorname{asinh}(h) + O(x^n)`.
24332433

2434-
.. function:: void _nmod_poly_sin_series(nn_ptr g, nn_srcptr h, slong n, nmod_t mod)
2434+
.. function:: void _nmod_poly_sin_series(nn_ptr g, nn_srcptr h, slong hlen, slong n, nmod_t mod)
24352435

2436-
Set `g = \operatorname{sin}(h) + O(x^n)`. Assumes `n > 0` and that `h`
2437-
is zero-padded as necessary to length `n`. Aliasing of `g` and `h` is
2438-
allowed. The value is computed using the identity
2439-
`\sin(x) = 2 \tan(x/2)) / (1 + \tan^2(x/2)).`
2436+
Set `g = \operatorname{sin}(h) + O(x^n)`. Assumes `n > 0` and `hlen > 0`.
2437+
Aliasing of `g` and `h` is allowed.
24402438

24412439
.. function:: void nmod_poly_sin_series(nmod_poly_t g, const nmod_poly_t h, slong n)
24422440

24432441
Set `g = \operatorname{sin}(h) + O(x^n)`.
24442442

2445-
.. function:: void _nmod_poly_cos_series(nn_ptr g, nn_srcptr h, slong n, nmod_t mod)
2443+
.. function:: void _nmod_poly_cos_series(nn_ptr g, nn_srcptr h, slong hlen, slong n, nmod_t mod)
24462444

2447-
Set `g = \operatorname{cos}(h) + O(x^n)`. Assumes `n > 0` and that `h`
2448-
is zero-padded as necessary to length `n`. Aliasing of `g` and `h` is
2449-
allowed. The value is computed using the identity
2450-
`\cos(x) = (1-\tan^2(x/2)) / (1 + \tan^2(x/2)).`
2445+
Set `g = \operatorname{cos}(h) + O(x^n)`. Assumes `n > 0` and `hlen > 0`.
2446+
Aliasing of `g` and `h` is allowed.`
24512447

24522448
.. function:: void nmod_poly_cos_series(nmod_poly_t g, const nmod_poly_t h, slong n)
24532449

src/acb_poly/cos_pi_series.c

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/acb_poly/cos_series.c

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)