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_cos_series(acb_ptr g,acb_srcptr h,slong hlen,slong n,slong prec)15 _acb_poly_cos_series(acb_ptr g, acb_srcptr h, slong hlen, slong n, slong prec)
16 {
17 hlen = FLINT_MIN(hlen, n);
18
19 if (hlen == 1)
20 {
21 acb_cos(g, h, prec);
22 _acb_vec_zero(g + 1, n - 1);
23 }
24 else if (n == 2)
25 {
26 acb_t t;
27 acb_init(t);
28 acb_sin_cos(t, g, h, prec);
29 acb_neg(t, t);
30 acb_mul(g + 1, h + 1, t, prec); /* safe since hlen >= 2 */
31 acb_clear(t);
32 }
33 else
34 {
35 acb_ptr t = _acb_vec_init(n);
36 _acb_poly_sin_cos_series(t, g, h, hlen, n, prec);
37 _acb_vec_clear(t, n);
38 }
39 }
40
41 void
acb_poly_cos_series(acb_poly_t g,const acb_poly_t h,slong n,slong prec)42 acb_poly_cos_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec)
43 {
44 slong hlen = h->length;
45
46 if (n == 0)
47 {
48 acb_poly_zero(g);
49 return;
50 }
51
52 if (hlen == 0)
53 {
54 acb_poly_one(g);
55 return;
56 }
57
58 if (hlen == 1)
59 n = 1;
60
61 acb_poly_fit_length(g, n);
62 _acb_poly_cos_series(g->coeffs, h->coeffs, hlen, n, prec);
63 _acb_poly_set_length(g, n);
64 _acb_poly_normalise(g);
65 }
66
67