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 
15 void
_acb_poly_atan_series(acb_ptr g,acb_srcptr h,slong hlen,slong n,slong prec)16 _acb_poly_atan_series(acb_ptr g, acb_srcptr h, slong hlen, slong n, slong prec)
17 {
18     acb_t c;
19     acb_init(c);
20 
21     acb_atan(c, h, prec);
22 
23     hlen = FLINT_MIN(hlen, n);
24 
25     if (hlen == 1)
26     {
27         _acb_vec_zero(g + 1, n - 1);
28     }
29     else
30     {
31         acb_ptr t, u;
32         slong ulen;
33 
34         t = _acb_vec_init(n);
35         u = _acb_vec_init(n);
36 
37         /* atan(h(x)) = integral(h'(x)/(1+h(x)^2)) */
38         ulen = FLINT_MIN(n, 2 * hlen - 1);
39         _acb_poly_mullow(u, h, hlen, h, hlen, ulen, prec);
40         acb_add_ui(u, u, 1, prec);
41 
42         _acb_poly_derivative(t, h, hlen, prec);
43         _acb_poly_div_series(g, t, hlen - 1, u, ulen, n, prec);
44         _acb_poly_integral(g, g, n, prec);
45 
46         _acb_vec_clear(t, n);
47         _acb_vec_clear(u, n);
48     }
49 
50     acb_swap(g, c);
51     acb_clear(c);
52 }
53 
54 void
acb_poly_atan_series(acb_poly_t g,const acb_poly_t h,slong n,slong prec)55 acb_poly_atan_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec)
56 {
57     slong hlen = h->length;
58 
59     if (hlen == 0 || n == 0)
60     {
61         acb_poly_zero(g);
62         return;
63     }
64 
65     acb_poly_fit_length(g, n);
66     _acb_poly_atan_series(g->coeffs, h->coeffs, hlen, n, prec);
67     _acb_poly_set_length(g, n);
68     _acb_poly_normalise(g);
69 }
70 
71