1 /*
2 Copyright (C) 2014 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 "arb.h"
13
14 void
arb_chebyshev_t2_ui(arb_t a,arb_t b,ulong n,const arb_t x,slong prec)15 arb_chebyshev_t2_ui(arb_t a, arb_t b, ulong n, const arb_t x, slong prec)
16 {
17 int i;
18
19 arb_set_round(a, x, prec);
20 arb_one(b);
21
22 if (n <= 1)
23 {
24 if (n == 0)
25 arb_swap(a, b);
26 return;
27 }
28
29 for (i = FLINT_BIT_COUNT(n - 1) - 1; i >= 0; i--)
30 {
31 if (((n - 1) >> i) & 1)
32 {
33 arb_mul(b, b, a, prec);
34 arb_mul_2exp_si(b, b, 1);
35 arb_sub(b, b, x, prec);
36 arb_mul(a, a, a, prec);
37 arb_mul_2exp_si(a, a, 1);
38 arb_sub_ui(a, a, 1, prec);
39 }
40 else
41 {
42 arb_mul(a, a, b, prec);
43 arb_mul_2exp_si(a, a, 1);
44 arb_sub(a, a, x, prec);
45 arb_mul(b, b, b, prec);
46 arb_mul_2exp_si(b, b, 1);
47 arb_sub_ui(b, b, 1, prec);
48 }
49 }
50 }
51
52