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_evaluate2_horner(acb_t y,acb_t z,acb_srcptr poly,slong len,const acb_t x,slong prec)15 _acb_poly_evaluate2_horner(acb_t y, acb_t z, acb_srcptr poly,
16 slong len, const acb_t x, slong prec)
17 {
18 if (len == 0)
19 {
20 acb_zero(y);
21 acb_zero(z);
22 }
23 else if (len == 1)
24 {
25 acb_set_round(y, poly + 0, prec);
26 acb_zero(z);
27 }
28 else if (acb_is_zero(x))
29 {
30 acb_set_round(y, poly + 0, prec);
31 acb_set_round(z, poly + 1, prec);
32 }
33 else if (len == 2)
34 {
35 acb_mul(y, x, poly + 1, prec);
36 acb_add(y, y, poly + 0, prec);
37 acb_set_round(z, poly + 1, prec);
38 }
39 else
40 {
41 acb_t t, u, v;
42 slong i;
43
44 acb_init(t);
45 acb_init(u);
46 acb_init(v);
47
48 acb_set_round(u, poly + len - 1, prec);
49 acb_zero(v);
50
51 for (i = len - 2; i >= 0; i--)
52 {
53 acb_mul(t, v, x, prec);
54 acb_add(v, u, t, prec);
55 acb_mul(t, u, x, prec);
56 acb_add(u, t, poly + i, prec);
57 }
58
59 acb_swap(y, u);
60 acb_swap(z, v);
61
62 acb_clear(t);
63 acb_clear(u);
64 acb_clear(v);
65 }
66 }
67
68 void
acb_poly_evaluate2_horner(acb_t r,acb_t s,const acb_poly_t f,const acb_t a,slong prec)69 acb_poly_evaluate2_horner(acb_t r, acb_t s, const acb_poly_t f, const acb_t a, slong prec)
70 {
71 _acb_poly_evaluate2_horner(r, s, f->coeffs, f->length, a, prec);
72 }
73
74