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 <math.h>
13 #include "acb_poly.h"
14 
15 void
_acb_poly_binomial_transform_convolution(acb_ptr b,acb_srcptr a,slong alen,slong len,slong prec)16 _acb_poly_binomial_transform_convolution(acb_ptr b, acb_srcptr a, slong alen, slong len, slong prec)
17 {
18     slong i;
19     acb_ptr c, d;
20 
21     alen = FLINT_MIN(alen, len);
22 
23     c = _acb_vec_init(alen);
24     d = _acb_vec_init(len);
25 
26     _acb_poly_borel_transform(c, a, alen, prec);
27     for (i = 1; i < alen; i += 2)
28         acb_neg(c + i, c + i);
29 
30     acb_one(d);
31     for (i = 1; i < len; i++)
32         acb_div_ui(d + i, d + i - 1, i, prec);
33 
34     _acb_poly_mullow(b, d, len, c, alen, len, prec);
35 
36     _acb_poly_inv_borel_transform(b, b, len, prec);
37 
38     _acb_vec_clear(c, alen);
39     _acb_vec_clear(d, len);
40 }
41 
42 void
acb_poly_binomial_transform_convolution(acb_poly_t b,const acb_poly_t a,slong len,slong prec)43 acb_poly_binomial_transform_convolution(acb_poly_t b, const acb_poly_t a, slong len, slong prec)
44 {
45     if (len == 0 || a->length == 0)
46     {
47         acb_poly_zero(b);
48         return;
49     }
50 
51     if (b == a)
52     {
53         acb_poly_t c;
54         acb_poly_init2(c, len);
55         _acb_poly_binomial_transform_convolution(c->coeffs, a->coeffs, a->length, len, prec);
56         acb_poly_swap(b, c);
57         acb_poly_clear(c);
58     }
59     else
60     {
61         acb_poly_fit_length(b, len);
62         _acb_poly_binomial_transform_convolution(b->coeffs, a->coeffs, a->length, len, prec);
63     }
64 
65     _acb_poly_set_length(b, len);
66     _acb_poly_normalise(b);
67 }
68 
69