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 static void
bsplit(fmpz_t P,fmpz_t T,fmpz_t Q,flint_bitcnt_t * Qexp,const fmpz_t x,flint_bitcnt_t r,slong a,slong b)15 bsplit(fmpz_t P, fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
16 const fmpz_t x, flint_bitcnt_t r, slong a, slong b)
17 {
18 if (b - a == 1)
19 {
20 fmpz_mul(P, x, x);
21 fmpz_set(T, P);
22
23 if (a % 2 == 0)
24 fmpz_neg_ui(Q, 2 * a + 3);
25 else
26 fmpz_set_ui(Q, 2 * a + 3);
27
28 *Qexp = 2 * r;
29 }
30 else
31 {
32 slong step, m;
33 flint_bitcnt_t Q2exp[1];
34 fmpz_t P2, Q2, T2;
35
36 step = (b - a) / 2;
37 m = a + step;
38
39 fmpz_init(P2);
40 fmpz_init(Q2);
41 fmpz_init(T2);
42
43 bsplit(P, T, Q, Qexp, x, r, a, m);
44 bsplit(P2, T2, Q2, Q2exp, x, r, m, b);
45
46 fmpz_mul(T, T, Q2);
47 fmpz_mul_2exp(T, T, *Q2exp);
48 fmpz_mul(T2, T2, Q);
49 fmpz_addmul(T, P, T2);
50 fmpz_mul(P, P, P2);
51 fmpz_mul(Q, Q, Q2);
52 *Qexp = *Qexp + *Q2exp;
53
54 fmpz_clear(P2);
55 fmpz_clear(Q2);
56 fmpz_clear(T2);
57 }
58 }
59
60 void
_arb_atan_sum_bs_simple(fmpz_t T,fmpz_t Q,flint_bitcnt_t * Qexp,const fmpz_t x,flint_bitcnt_t r,slong N)61 _arb_atan_sum_bs_simple(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
62 const fmpz_t x, flint_bitcnt_t r, slong N)
63 {
64 fmpz_t P;
65 fmpz_init(P);
66 bsplit(P, T, Q, Qexp, x, r, 0, N);
67 fmpz_clear(P);
68 }
69
70