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_exponential(acb_ptr s,acb_ptr c,const acb_srcptr h,slong hlen,slong len,slong prec)15 _acb_poly_sinh_cosh_series_exponential(acb_ptr s, acb_ptr c,
16 const acb_srcptr h, slong hlen, slong len, slong prec)
17 {
18 acb_ptr t, u, v;
19 acb_t s0, c0;
20 hlen = FLINT_MIN(hlen, len);
21
22 if (hlen == 1)
23 {
24 acb_sinh_cosh(s, c, h, prec);
25 _acb_vec_zero(s + 1, len - 1);
26 _acb_vec_zero(c + 1, len - 1);
27 return;
28 }
29
30 acb_init(s0);
31 acb_init(c0);
32
33 t = _acb_vec_init(3 * len);
34 u = t + len;
35 v = u + len;
36
37 acb_sinh_cosh(s0, c0, h, prec);
38
39 _acb_vec_set(t + 1, h + 1, hlen - 1);
40 _acb_poly_exp_series(t, t, len, len, prec);
41
42 /* todo: part of the inverse could be avoided since exp computes
43 it internally to half the length */
44 _acb_poly_inv_series(u, t, len, len, prec);
45
46 /* hyperbolic sine */
47 _acb_vec_sub(s, t, u, len, prec);
48 _acb_vec_scalar_mul_2exp_si(s, s, len, -1);
49
50 /* hyperbolic cosine */
51 _acb_vec_add(c, t, u, len, prec);
52 _acb_vec_scalar_mul_2exp_si(c, c, len, -1);
53
54 /* sinh(h0 + h1) = cosh(h0) sinh(h1) + sinh(h0) cosh(h1)
55 cosh(h0 + h1) = cosh(h0) cosh(h1) + sinh(h0) sinh(h1) */
56 if (!acb_is_zero(s0))
57 {
58 _acb_vec_scalar_mul(t, s, len, c0, prec);
59 _acb_vec_scalar_mul(u, c, len, s0, prec);
60 _acb_vec_scalar_mul(v, s, len, s0, prec);
61 _acb_vec_add(s, t, u, len, prec);
62 _acb_vec_scalar_mul(t, c, len, c0, prec);
63 _acb_vec_add(c, t, v, len, prec);
64 }
65
66 _acb_vec_clear(t, 3 * len);
67
68 acb_clear(s0);
69 acb_clear(c0);
70 }
71
72 void
acb_poly_sinh_cosh_series_exponential(acb_poly_t s,acb_poly_t c,const acb_poly_t h,slong n,slong prec)73 acb_poly_sinh_cosh_series_exponential(acb_poly_t s, acb_poly_t c,
74 const acb_poly_t h, slong n, slong prec)
75 {
76 slong hlen = h->length;
77
78 if (n == 0)
79 {
80 acb_poly_zero(s);
81 acb_poly_zero(c);
82 return;
83 }
84
85 if (hlen == 0)
86 {
87 acb_poly_zero(s);
88 acb_poly_one(c);
89 return;
90 }
91
92 acb_poly_fit_length(s, n);
93 acb_poly_fit_length(c, n);
94 _acb_poly_sinh_cosh_series_exponential(s->coeffs, c->coeffs, h->coeffs, hlen, n, prec);
95 _acb_poly_set_length(s, n);
96 _acb_poly_normalise(s);
97 _acb_poly_set_length(c, n);
98 _acb_poly_normalise(c);
99 }
100
101