1 /*
2 Copyright (C) 2013 Fredrik Johansson
3
4 This file is part of Arb.
5
6 Arb is free software: you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version. See <http://www.gnu.org/licenses/>.
10 */
11
12 #include "acb_poly.h"
13
14 void
_acb_poly_sin_cos_series(acb_ptr s,acb_ptr c,acb_srcptr h,slong hlen,slong n,slong prec)15 _acb_poly_sin_cos_series(acb_ptr s, acb_ptr c, acb_srcptr h, slong hlen, slong n, slong prec)
16 {
17 hlen = FLINT_MIN(hlen, n);
18
19 if (hlen == 1)
20 {
21 acb_sin_cos(s, c, h, prec);
22 _acb_vec_zero(s + 1, n - 1);
23 _acb_vec_zero(c + 1, n - 1);
24 }
25 else if (n == 2)
26 {
27 acb_t t;
28 acb_init(t);
29 acb_set(t, h + 1);
30 acb_sin_cos(s, c, h, prec);
31 acb_mul(s + 1, c, t, prec);
32 acb_neg(t, t);
33 acb_mul(c + 1, s, t, prec);
34 acb_clear(t);
35 }
36 else
37 {
38 slong cutoff;
39
40 if (prec <= 128)
41 {
42 cutoff = 1400;
43 }
44 else
45 {
46 cutoff = 100000 / pow(log(prec), 3);
47 cutoff = FLINT_MIN(cutoff, 700);
48 }
49
50 if (hlen < cutoff)
51 _acb_poly_sin_cos_series_basecase(s, c, h, hlen, n, prec, 0);
52 else
53 _acb_poly_sin_cos_series_tangent(s, c, h, hlen, n, prec, 0);
54 }
55 }
56
57 void
acb_poly_sin_cos_series(acb_poly_t s,acb_poly_t c,const acb_poly_t h,slong n,slong prec)58 acb_poly_sin_cos_series(acb_poly_t s, acb_poly_t c,
59 const acb_poly_t h, slong n, slong prec)
60 {
61 slong hlen = h->length;
62
63 if (n == 0)
64 {
65 acb_poly_zero(s);
66 acb_poly_zero(c);
67 return;
68 }
69
70 if (hlen == 0)
71 {
72 acb_poly_zero(s);
73 acb_poly_one(c);
74 return;
75 }
76
77 if (hlen == 1)
78 n = 1;
79
80 acb_poly_fit_length(s, n);
81 acb_poly_fit_length(c, n);
82 _acb_poly_sin_cos_series(s->coeffs, c->coeffs, h->coeffs, hlen, n, prec);
83 _acb_poly_set_length(s, n);
84 _acb_poly_normalise(s);
85 _acb_poly_set_length(c, n);
86 _acb_poly_normalise(c);
87 }
88
89