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_evaluate_rectangular(acb_t y,acb_srcptr poly,slong len,const acb_t x,slong prec)15 _acb_poly_evaluate_rectangular(acb_t y, acb_srcptr poly,
16     slong len, const acb_t x, slong prec)
17 {
18     slong i, m, r;
19     acb_ptr xs;
20     acb_t s, t, c;
21 
22     if (len < 3)
23     {
24         if (len == 0)
25         {
26             acb_zero(y);
27         }
28         else if (len == 1)
29         {
30             acb_set_round(y, poly + 0, prec);
31         }
32         else if (len == 2)
33         {
34             acb_mul(y, x, poly + 1, prec);
35             acb_add(y, y, poly + 0, prec);
36         }
37         return;
38     }
39 
40     m = n_sqrt(len) + 1;
41     r = (len + m - 1) / m;
42 
43     xs = _acb_vec_init(m + 1);
44     acb_init(s);
45     acb_init(t);
46     acb_init(c);
47 
48     _acb_vec_set_powers(xs, x, m + 1, prec);
49     acb_dot(y, poly + (r - 1) * m, 0, xs + 1, 1,
50         poly + (r - 1) * m + 1, 1, len - (r - 1) * m - 1, prec);
51 
52     for (i = r - 2; i >= 0; i--)
53     {
54         acb_dot(s, poly + i * m, 0, xs + 1, 1,
55             poly + i * m + 1, 1, m - 1, prec);
56         acb_mul(y, y, xs + m, prec);
57         acb_add(y, y, s, prec);
58     }
59 
60     _acb_vec_clear(xs, m + 1);
61     acb_clear(s);
62     acb_clear(t);
63     acb_clear(c);
64 }
65 
66 void
acb_poly_evaluate_rectangular(acb_t res,const acb_poly_t f,const acb_t a,slong prec)67 acb_poly_evaluate_rectangular(acb_t res, const acb_poly_t f, const acb_t a, slong prec)
68 {
69     _acb_poly_evaluate_rectangular(res, f->coeffs, f->length, a, prec);
70 }
71 
72