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_sinh_cosh_series(acb_ptr s,acb_ptr c,acb_srcptr h,slong hlen,slong n,slong prec)15 _acb_poly_sinh_cosh_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_sinh_cosh(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_sinh_cosh(s, c, h, prec);
31         acb_mul(s + 1, c, t, prec);
32         acb_mul(c + 1, s, t, prec);
33         acb_clear(t);
34     }
35     else
36     {
37         slong cutoff;
38 
39         if (prec <= 128)
40             cutoff = 400;
41         else
42             cutoff = 30000 / pow(log(prec), 3);
43 
44         if (hlen < cutoff)
45             _acb_poly_sinh_cosh_series_basecase(s, c, h, hlen, n, prec);
46         else
47             _acb_poly_sinh_cosh_series_exponential(s, c, h, hlen, n, prec);
48     }
49 }
50 
51 void
acb_poly_sinh_cosh_series(acb_poly_t s,acb_poly_t c,const acb_poly_t h,slong n,slong prec)52 acb_poly_sinh_cosh_series(acb_poly_t s, acb_poly_t c,
53                                     const acb_poly_t h, slong n, slong prec)
54 {
55     slong hlen = h->length;
56 
57     if (n == 0)
58     {
59         acb_poly_zero(s);
60         acb_poly_zero(c);
61         return;
62     }
63 
64     if (hlen == 0)
65     {
66         acb_poly_zero(s);
67         acb_poly_one(c);
68         return;
69     }
70 
71     if (hlen == 1)
72         n = 1;
73 
74     acb_poly_fit_length(s, n);
75     acb_poly_fit_length(c, n);
76     _acb_poly_sinh_cosh_series(s->coeffs, c->coeffs, h->coeffs, hlen, n, prec);
77     _acb_poly_set_length(s, n);
78     _acb_poly_normalise(s);
79     _acb_poly_set_length(c, n);
80     _acb_poly_normalise(c);
81 }
82