1 /*
2 Copyright (C) 2012 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 static void
_acb_poly_exp_series_basecase_rec(acb_ptr f,acb_ptr a,acb_srcptr h,slong hlen,slong n,slong prec)15 _acb_poly_exp_series_basecase_rec(acb_ptr f, acb_ptr a,
16 acb_srcptr h, slong hlen, slong n, slong prec)
17 {
18 slong k;
19
20 acb_t s;
21 acb_init(s);
22
23 acb_exp(f, h, prec);
24
25 for (k = 1; k < hlen; k++)
26 acb_mul_ui(a + k, h + k, k, prec);
27
28 for (k = 1; k < n; k++)
29 {
30 acb_dot(s, NULL, 0, a + 1, 1, f + k - 1, -1, FLINT_MIN(k, hlen - 1), prec);
31 acb_div_ui(f + k, s, k, prec);
32 }
33
34 acb_clear(s);
35 }
36
37 void
_acb_poly_exp_series_basecase(acb_ptr f,acb_srcptr h,slong hlen,slong n,slong prec)38 _acb_poly_exp_series_basecase(acb_ptr f,
39 acb_srcptr h, slong hlen, slong n, slong prec)
40 {
41 hlen = FLINT_MIN(n, hlen);
42
43 if (n < 20 || hlen < 0.9 * n || prec <= 2 * FLINT_BITS || n < 1000.0 / log(prec + 10) - 70)
44 {
45 acb_ptr t = _acb_vec_init(hlen);
46 _acb_poly_exp_series_basecase_rec(f, t, h, hlen, n, prec);
47 _acb_vec_clear(t, hlen);
48 }
49 else
50 {
51 slong m, v;
52 acb_ptr t, u;
53
54 m = (n + 2) / 3;
55 v = m * 2;
56
57 t = _acb_vec_init(n);
58 u = _acb_vec_init(n - m);
59
60 _acb_poly_mullow(t, h + m, hlen - m, h + m, hlen - m, n - v, prec);
61 _acb_vec_scalar_mul_2exp_si(t, t, n - v, -1);
62
63 _acb_vec_set(u, h + m, v - m);
64 _acb_poly_add(u + v - m, t, n - v, h + v, hlen - v, prec);
65 _acb_poly_exp_series_basecase_rec(f, t, h, m, n, prec);
66 _acb_poly_mullow(t, f, n, u, n - m, n - m, prec);
67 _acb_poly_add(f + m, f + m, n - m, t, n - m, prec);
68
69 _acb_vec_clear(t, n);
70 _acb_vec_clear(u, n - m);
71 }
72 }
73
74 void
acb_poly_exp_series_basecase(acb_poly_t f,const acb_poly_t h,slong n,slong prec)75 acb_poly_exp_series_basecase(acb_poly_t f, const acb_poly_t h, slong n, slong prec)
76 {
77 slong hlen = h->length;
78
79 if (n == 0)
80 {
81 acb_poly_zero(f);
82 return;
83 }
84
85 if (hlen == 0)
86 {
87 acb_poly_one(f);
88 return;
89 }
90
91 acb_poly_fit_length(f, n);
92 _acb_poly_exp_series_basecase(f->coeffs, h->coeffs, hlen, n, prec);
93 _acb_poly_set_length(f, n);
94 _acb_poly_normalise(f);
95 }
96