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 #ifndef ARB_H
13 #define ARB_H
14
15 #ifdef ARB_INLINES_C
16 #define ARB_INLINE
17 #else
18 #define ARB_INLINE static __inline__
19 #endif
20
21 #include <stdio.h>
22 #include "mag.h"
23 #include "arf.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define __ARB_VERSION 2
30 #define __ARB_VERSION_MINOR 21
31 #define __ARB_VERSION_PATCHLEVEL 1
32 #define ARB_VERSION "2.21.1"
33 #define __ARB_RELEASE (__ARB_VERSION * 10000 + \
34 __ARB_VERSION_MINOR * 100 + \
35 __ARB_VERSION_PATCHLEVEL)
36
37 ARB_DLL extern const char * arb_version;
38 double arb_test_multiplier(void);
39
40 typedef struct
41 {
42 arf_struct mid;
43 mag_struct rad;
44 }
45 arb_struct;
46
47 typedef arb_struct arb_t[1];
48 typedef arb_struct * arb_ptr;
49 typedef const arb_struct * arb_srcptr;
50
51 #define arb_midref(x) (&(x)->mid)
52 #define arb_radref(x) (&(x)->rad)
53
54 #define ARB_IS_LAGOM(x) (ARF_IS_LAGOM(arb_midref(x)) && MAG_IS_LAGOM(arb_radref(x)))
55
56 #define ARB_RND ARF_RND_DOWN
57
58 ARB_INLINE void
arb_init(arb_t x)59 arb_init(arb_t x)
60 {
61 arf_init(arb_midref(x));
62 mag_init(arb_radref(x));
63 }
64
65 void arb_clear(arb_t x);
66
67 arb_ptr _arb_vec_init(slong n);
68 void _arb_vec_clear(arb_ptr v, slong n);
69
arb_mid_ptr(arb_t z)70 ARB_INLINE arf_ptr arb_mid_ptr(arb_t z) { return arb_midref(z); }
arb_rad_ptr(arb_t z)71 ARB_INLINE mag_ptr arb_rad_ptr(arb_t z) { return arb_radref(z); }
72
73 ARB_INLINE int
arb_is_exact(const arb_t x)74 arb_is_exact(const arb_t x)
75 {
76 return mag_is_zero(arb_radref(x));
77 }
78
79 ARB_INLINE int
arb_equal(const arb_t x,const arb_t y)80 arb_equal(const arb_t x, const arb_t y)
81 {
82 return arf_equal(arb_midref(x), arb_midref(y)) &&
83 mag_equal(arb_radref(x), arb_radref(y));
84 }
85
86 ARB_INLINE int
arb_equal_si(const arb_t x,slong y)87 arb_equal_si(const arb_t x, slong y)
88 {
89 return arf_equal_si(arb_midref(x), y) && mag_is_zero(arb_radref(x));
90 }
91
92 /* implementations are in arb/richcmp.c */
93 int arb_eq(const arb_t x, const arb_t y);
94 int arb_ne(const arb_t x, const arb_t y);
95 int arb_lt(const arb_t x, const arb_t y);
96 int arb_le(const arb_t x, const arb_t y);
97 int arb_gt(const arb_t x, const arb_t y);
98 int arb_ge(const arb_t x, const arb_t y);
99
100 void arb_zero(arb_t x);
101
102 ARB_INLINE int
arb_is_zero(const arb_t x)103 arb_is_zero(const arb_t x)
104 {
105 return arf_is_zero(arb_midref(x)) && mag_is_zero(arb_radref(x));
106 }
107
108 ARB_INLINE void
arb_pos_inf(arb_t x)109 arb_pos_inf(arb_t x)
110 {
111 arf_pos_inf(arb_midref(x));
112 mag_zero(arb_radref(x));
113 }
114
115 ARB_INLINE void
arb_neg_inf(arb_t x)116 arb_neg_inf(arb_t x)
117 {
118 arf_neg_inf(arb_midref(x));
119 mag_zero(arb_radref(x));
120 }
121
122 ARB_INLINE void
arb_zero_pm_inf(arb_t x)123 arb_zero_pm_inf(arb_t x)
124 {
125 arf_zero(arb_midref(x));
126 mag_inf(arb_radref(x));
127 }
128
129 ARB_INLINE void
arb_zero_pm_one(arb_t x)130 arb_zero_pm_one(arb_t x)
131 {
132 arf_zero(arb_midref(x));
133 mag_one(arb_radref(x));
134 }
135
136 ARB_INLINE void
arb_unit_interval(arb_t x)137 arb_unit_interval(arb_t x)
138 {
139 arf_one(arb_midref(x));
140 mag_one(arb_radref(x));
141 ARF_EXP(arb_midref(x))--;
142 MAG_EXP(arb_radref(x))--;
143 }
144
145 void arb_indeterminate(arb_t x);
146
147 int arb_is_finite(const arb_t x);
148
149 void arb_set(arb_t x, const arb_t y);
150
151 ARB_INLINE void
arb_swap(arb_t x,arb_t y)152 arb_swap(arb_t x, arb_t y)
153 {
154 arb_struct t = *x;
155 *x = *y;
156 *y = t;
157 }
158
159 void arb_set_round(arb_t z, const arb_t x, slong prec);
160
161 void arb_trim(arb_t y, const arb_t x);
162
163 void arb_neg(arb_t y, const arb_t x);
164
165 void arb_neg_round(arb_t x, const arb_t y, slong prec);
166
167 void arb_abs(arb_t y, const arb_t x);
168
169 void arb_sgn(arb_t res, const arb_t x);
170 int arb_sgn_nonzero(const arb_t x);
171
172 void _arb_digits_round_inplace(char * s, flint_bitcnt_t * shift, fmpz_t error, slong n, arf_rnd_t rnd);
173
174 int arb_set_str(arb_t res, const char * inp, slong prec);
175
176 #define ARB_STR_MORE UWORD(1)
177 #define ARB_STR_NO_RADIUS UWORD(2)
178 #define ARB_STR_CONDENSE UWORD(16)
179
180 char * arb_get_str(const arb_t x, slong n, ulong flags);
181
182
183 ARB_INLINE void
arb_set_arf(arb_t x,const arf_t y)184 arb_set_arf(arb_t x, const arf_t y)
185 {
186 arf_set(arb_midref(x), y);
187 mag_zero(arb_radref(x));
188 }
189
190 void arb_set_si(arb_t x, slong y);
191
192 void arb_set_ui(arb_t x, ulong y);
193
194 void arb_set_d(arb_t x, double y);
195
196 void arb_set_fmpz(arb_t x, const fmpz_t y);
197
198 ARB_INLINE void
arb_set_fmpz_2exp(arb_t x,const fmpz_t y,const fmpz_t exp)199 arb_set_fmpz_2exp(arb_t x, const fmpz_t y, const fmpz_t exp)
200 {
201 arf_set_fmpz_2exp(arb_midref(x), y, exp);
202 mag_zero(arb_radref(x));
203 }
204
205 void arb_set_round_fmpz_2exp(arb_t y, const fmpz_t x, const fmpz_t exp, slong prec);
206
207 void arb_set_round_fmpz(arb_t y, const fmpz_t x, slong prec);
208
209 ARB_INLINE int
arb_is_one(const arb_t f)210 arb_is_one(const arb_t f)
211 {
212 return arf_is_one(arb_midref(f)) && mag_is_zero(arb_radref(f));
213 }
214
215 void arb_one(arb_t f);
216
217 void arb_fprint(FILE * file, const arb_t x);
218
219 void arb_fprintd(FILE * file, const arb_t x, slong digits);
220
221 void arb_fprintn(FILE * file, const arb_t x, slong digits, ulong flags);
222
223 ARB_INLINE void
arb_print(const arb_t x)224 arb_print(const arb_t x)
225 {
226 arb_fprint(stdout, x);
227 }
228
229 ARB_INLINE void
arb_printd(const arb_t x,slong digits)230 arb_printd(const arb_t x, slong digits)
231 {
232 arb_fprintd(stdout, x, digits);
233 }
234
235 ARB_INLINE void
arb_printn(const arb_t x,slong digits,ulong flags)236 arb_printn(const arb_t x, slong digits, ulong flags)
237 {
238 arb_fprintn(stdout, x, digits, flags);
239 }
240
241 void arb_mul_2exp_si(arb_t y, const arb_t x, slong e);
242
243 ARB_INLINE void
arb_mul_2exp_fmpz(arb_t y,const arb_t x,const fmpz_t e)244 arb_mul_2exp_fmpz(arb_t y, const arb_t x, const fmpz_t e)
245 {
246 arf_mul_2exp_fmpz(arb_midref(y), arb_midref(x), e);
247 mag_mul_2exp_fmpz(arb_radref(y), arb_radref(x), e);
248 }
249
250 ARB_INLINE int
arb_is_int(const arb_t x)251 arb_is_int(const arb_t x)
252 {
253 return mag_is_zero(arb_radref(x)) &&
254 arf_is_int(arb_midref(x));
255 }
256
257 ARB_INLINE int
arb_is_int_2exp_si(const arb_t x,slong e)258 arb_is_int_2exp_si(const arb_t x, slong e)
259 {
260 return mag_is_zero(arb_radref(x)) &&
261 arf_is_int_2exp_si(arb_midref(x), e);
262 }
263
264 /* implementations are in arb/richcmp.c */
265 int arb_contains_zero(const arb_t x);
266 int arb_is_nonzero(const arb_t x);
267 int arb_is_positive(const arb_t x);
268 int arb_is_nonnegative(const arb_t x);
269 int arb_is_negative(const arb_t x);
270 int arb_is_nonpositive(const arb_t x);
271 int arb_contains_negative(const arb_t x);
272 int arb_contains_nonpositive(const arb_t x);
273 int arb_contains_positive(const arb_t x);
274 int arb_contains_nonnegative(const arb_t x);
275
276 void arb_get_mag_lower(mag_t z, const arb_t x);
277
278 void arb_get_mag_lower_nonnegative(mag_t z, const arb_t x);
279
280 ARB_INLINE void
arb_get_mag(mag_t z,const arb_t x)281 arb_get_mag(mag_t z, const arb_t x)
282 {
283 mag_t t;
284 mag_init_set_arf(t, arb_midref(x));
285 mag_add(z, t, arb_radref(x));
286 mag_clear(t);
287 }
288
289 ARB_INLINE void
arb_get_mid_arb(arb_t z,const arb_t x)290 arb_get_mid_arb(arb_t z, const arb_t x)
291 {
292 arf_set(arb_midref(z), arb_midref(x));
293 mag_zero(arb_radref(z));
294 }
295
296 ARB_INLINE void
arb_get_rad_arb(arb_t z,const arb_t x)297 arb_get_rad_arb(arb_t z, const arb_t x)
298 {
299 arf_set_mag(arb_midref(z), arb_radref(x));
300 mag_zero(arb_radref(z));
301 }
302
303 void arb_get_abs_ubound_arf(arf_t u, const arb_t x, slong prec);
304 void arb_get_abs_lbound_arf(arf_t u, const arb_t x, slong prec);
305 void arb_get_ubound_arf(arf_t u, const arb_t x, slong prec);
306 void arb_get_lbound_arf(arf_t u, const arb_t x, slong prec);
307
308 void arb_nonnegative_part(arb_t res, const arb_t x);
309
310 slong arb_rel_error_bits(const arb_t x);
311
312 ARB_INLINE slong
arb_rel_accuracy_bits(const arb_t x)313 arb_rel_accuracy_bits(const arb_t x)
314 {
315 return -arb_rel_error_bits(x);
316 }
317
318 slong arb_rel_one_accuracy_bits(const arb_t x);
319
320 ARB_INLINE slong
arb_bits(const arb_t x)321 arb_bits(const arb_t x)
322 {
323 return arf_bits(arb_midref(x));
324 }
325
326 void arb_randtest_exact(arb_t x, flint_rand_t state, slong prec, slong mag_bits);
327
328 void arb_randtest_wide(arb_t x, flint_rand_t state, slong prec, slong mag_bits);
329
330 void arb_randtest_precise(arb_t x, flint_rand_t state, slong prec, slong mag_bits);
331
332 void arb_randtest(arb_t x, flint_rand_t state, slong prec, slong mag_bits);
333
334 void arb_randtest_special(arb_t x, flint_rand_t state, slong prec, slong mag_bits);
335
336 void arb_urandom(arb_t x, flint_rand_t state, slong prec);
337
338 void arb_add_error_arf(arb_t x, const arf_t err);
339
340 void arb_add_error_2exp_si(arb_t x, slong err);
341
342 void arb_add_error_2exp_fmpz(arb_t x, const fmpz_t err);
343
344 void arb_add_error(arb_t x, const arb_t error);
345
346 ARB_INLINE void
arb_add_error_mag(arb_t x,const mag_t err)347 arb_add_error_mag(arb_t x, const mag_t err)
348 {
349 mag_add(arb_radref(x), arb_radref(x), err);
350 }
351
352 int arb_contains_arf(const arb_t x, const arf_t y);
353
354 int arb_contains_fmpq(const arb_t x, const fmpq_t y);
355
356 int arb_contains_fmpz(const arb_t x, const fmpz_t y);
357
358 int arb_contains_si(const arb_t x, slong y);
359
360 int arb_contains_mpfr(const arb_t x, const mpfr_t y);
361
362 int arb_overlaps(const arb_t x, const arb_t y);
363
364 int arb_contains(const arb_t x, const arb_t y);
365
366 int arb_contains_interior(const arb_t x, const arb_t y);
367
368 int arb_contains_int(const arb_t x);
369
370 void arb_get_interval_fmpz_2exp(fmpz_t a, fmpz_t b, fmpz_t exp, const arb_t x);
371 int arb_get_unique_fmpz(fmpz_t z, const arb_t x);
372
373 void arb_get_fmpz_mid_rad_10exp(fmpz_t mid, fmpz_t rad, fmpz_t exp, const arb_t x, slong n);
374
375 void arb_floor(arb_t z, const arb_t x, slong prec);
376 void arb_ceil(arb_t z, const arb_t x, slong prec);
377
378 void arb_set_interval_arf(arb_t x, const arf_t a, const arf_t b, slong prec);
379 void arb_set_interval_mpfr(arb_t x, const mpfr_t a, const mpfr_t b, slong prec);
380
381 void arb_get_interval_arf(arf_t a, arf_t b, const arb_t x, slong prec);
382 void arb_get_interval_mpfr(mpfr_t a, mpfr_t b, const arb_t x);
383
384 void arb_set_interval_mag(arb_t res, const mag_t a, const mag_t b, slong prec);
385 void arb_set_interval_neg_pos_mag(arb_t res, const mag_t a, const mag_t b, slong prec);
386
387 void arb_union(arb_t z, const arb_t x, const arb_t y, slong prec);
388 int arb_intersection(arb_t z, const arb_t x, const arb_t y, slong prec);
389 void arb_get_rand_fmpq(fmpq_t q, flint_rand_t state, const arb_t x, slong bits);
390
391 void arb_min(arb_t z, const arb_t x, const arb_t y, slong prec);
392 void arb_max(arb_t z, const arb_t x, const arb_t y, slong prec);
393
394 int arb_can_round_arf(const arb_t x, slong prec, arf_rnd_t rnd);
395 int arb_can_round_mpfr(const arb_t x, slong prec, mpfr_rnd_t rnd);
396
397 void arb_add(arb_t z, const arb_t x, const arb_t y, slong prec);
398 void arb_add_arf(arb_t z, const arb_t x, const arf_t y, slong prec);
399 void arb_add_ui(arb_t z, const arb_t x, ulong y, slong prec);
400 void arb_add_si(arb_t z, const arb_t x, slong y, slong prec);
401 void arb_add_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
402 void arb_add_fmpz_2exp(arb_t z, const arb_t x, const fmpz_t man, const fmpz_t exp, slong prec);
403
404 void arb_sub(arb_t z, const arb_t x, const arb_t y, slong prec);
405 void arb_sub_arf(arb_t z, const arb_t x, const arf_t y, slong prec);
406 void arb_sub_ui(arb_t z, const arb_t x, ulong y, slong prec);
407 void arb_sub_si(arb_t z, const arb_t x, slong y, slong prec);
408 void arb_sub_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
409
410 void arb_mul(arb_t z, const arb_t x, const arb_t y, slong prec);
411 void arb_mul_arf(arb_t z, const arb_t x, const arf_t y, slong prec);
412 void arb_mul_si(arb_t z, const arb_t x, slong y, slong prec);
413 void arb_mul_ui(arb_t z, const arb_t x, ulong y, slong prec);
414 void arb_mul_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
415
416 void arb_addmul(arb_t z, const arb_t x, const arb_t y, slong prec);
417 void arb_addmul_arf(arb_t z, const arb_t x, const arf_t y, slong prec);
418 void arb_addmul_si(arb_t z, const arb_t x, slong y, slong prec);
419 void arb_addmul_ui(arb_t z, const arb_t x, ulong y, slong prec);
420 void arb_addmul_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
421
422 void arb_submul(arb_t z, const arb_t x, const arb_t y, slong prec);
423 void arb_submul_arf(arb_t z, const arb_t x, const arf_t y, slong prec);
424 void arb_submul_si(arb_t z, const arb_t x, slong y, slong prec);
425 void arb_submul_ui(arb_t z, const arb_t x, ulong y, slong prec);
426 void arb_submul_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
427
428 void arb_fma(arb_t res, const arb_t x, const arb_t y, const arb_t z, slong prec);
429 void arb_fma_arf(arb_t res, const arb_t x, const arf_t y, const arb_t z, slong prec);
430 void arb_fma_ui(arb_t res, const arb_t x, ulong y, const arb_t z, slong prec);
431
432 void arb_dot_simple(arb_t res, const arb_t initial, int subtract,
433 arb_srcptr x, slong xstep, arb_srcptr y, slong ystep, slong len, slong prec);
434 void arb_dot_precise(arb_t res, const arb_t initial, int subtract,
435 arb_srcptr x, slong xstep, arb_srcptr y, slong ystep, slong len, slong prec);
436 void arb_dot(arb_t res, const arb_t initial, int subtract,
437 arb_srcptr x, slong xstep, arb_srcptr y, slong ystep, slong len, slong prec);
438
439 void arb_approx_dot(arb_t res, const arb_t initial, int subtract,
440 arb_srcptr x, slong xstep, arb_srcptr y, slong ystep, slong len, slong prec);
441
442 void arb_dot_ui(arb_t res, const arb_t initial, int subtract,
443 arb_srcptr x, slong xstep, const ulong * y, slong ystep, slong len, slong prec);
444 void arb_dot_si(arb_t res, const arb_t initial, int subtract,
445 arb_srcptr x, slong xstep, const slong * y, slong ystep, slong len, slong prec);
446 void arb_dot_uiui(arb_t res, const arb_t initial, int subtract,
447 arb_srcptr x, slong xstep, const ulong * y, slong ystep, slong len, slong prec);
448 void arb_dot_siui(arb_t res, const arb_t initial, int subtract,
449 arb_srcptr x, slong xstep, const ulong * y, slong ystep, slong len, slong prec);
450 void arb_dot_fmpz(arb_t res, const arb_t initial, int subtract,
451 arb_srcptr x, slong xstep, const fmpz * y, slong ystep, slong len, slong prec);
452
453 void arb_div(arb_t z, const arb_t x, const arb_t y, slong prec);
454 void arb_div_arf(arb_t z, const arb_t x, const arf_t y, slong prec);
455 void arb_div_si(arb_t z, const arb_t x, slong y, slong prec);
456 void arb_div_ui(arb_t z, const arb_t x, ulong y, slong prec);
457 void arb_div_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
458 void arb_fmpz_div_fmpz(arb_t z, const fmpz_t x, const fmpz_t y, slong prec);
459 void arb_ui_div(arb_t z, ulong x, const arb_t y, slong prec);
460
461 ARB_INLINE void
arb_inv(arb_t y,const arb_t x,slong prec)462 arb_inv(arb_t y, const arb_t x, slong prec)
463 {
464 arb_ui_div(y, 1, x, prec);
465 }
466
467 ARB_INLINE void
arb_set_fmpq(arb_t y,const fmpq_t x,slong prec)468 arb_set_fmpq(arb_t y, const fmpq_t x, slong prec)
469 {
470 arb_fmpz_div_fmpz(y, fmpq_numref(x), fmpq_denref(x), prec);
471 }
472
473 void arb_sqrt(arb_t z, const arb_t x, slong prec);
474 void arb_sqrt_arf(arb_t z, const arf_t x, slong prec);
475 void arb_sqrt_fmpz(arb_t z, const fmpz_t x, slong prec);
476 void arb_sqrt_ui(arb_t z, ulong x, slong prec);
477
478 void arb_sqrtpos(arb_t z, const arb_t x, slong prec);
479 void arb_hypot(arb_t z, const arb_t x, const arb_t y, slong prec);
480
481 void arb_rsqrt(arb_t z, const arb_t x, slong prec);
482 void arb_rsqrt_ui(arb_t z, ulong x, slong prec);
483 void arb_sqrt1pm1(arb_t r, const arb_t z, slong prec);
484
485 void arb_pow_fmpz_binexp(arb_t y, const arb_t b, const fmpz_t e, slong prec);
486 void arb_pow_fmpz(arb_t y, const arb_t b, const fmpz_t e, slong prec);
487 void arb_pow_ui(arb_t y, const arb_t b, ulong e, slong prec);
488 void arb_ui_pow_ui(arb_t y, ulong b, ulong e, slong prec);
489 void arb_si_pow_ui(arb_t y, slong b, ulong e, slong prec);
490 void arb_pow_fmpq(arb_t y, const arb_t x, const fmpq_t a, slong prec);
491
492 void arb_div_2expm1_ui(arb_t z, const arb_t x, ulong n, slong prec);
493 void arb_pow(arb_t z, const arb_t x, const arb_t y, slong prec);
494 void arb_root_ui(arb_t z, const arb_t x, ulong k, slong prec);
495 void arb_root(arb_t z, const arb_t x, ulong k, slong prec); /* back compat */
496 void arb_log(arb_t z, const arb_t x, slong prec);
497 void arb_log_arf(arb_t z, const arf_t x, slong prec);
498 void arb_log_ui(arb_t z, ulong x, slong prec);
499 void arb_log_fmpz(arb_t z, const fmpz_t x, slong prec);
500 void arb_log1p(arb_t r, const arb_t z, slong prec);
501 void arb_log_base_ui(arb_t res, const arb_t x, ulong b, slong prec);
502 void arb_log_hypot(arb_t res, const arb_t x, const arb_t y, slong prec);
503 void arb_exp(arb_t z, const arb_t x, slong prec);
504 void arb_expm1(arb_t z, const arb_t x, slong prec);
505 void arb_exp_invexp(arb_t z, arb_t w, const arb_t x, slong prec);
506 void arb_sin(arb_t s, const arb_t x, slong prec);
507 void arb_cos(arb_t c, const arb_t x, slong prec);
508 void arb_sin_cos(arb_t s, arb_t c, const arb_t x, slong prec);
509 void arb_sin_pi(arb_t s, const arb_t x, slong prec);
510 void arb_cos_pi(arb_t c, const arb_t x, slong prec);
511 void arb_sin_cos_pi(arb_t s, arb_t c, const arb_t x, slong prec);
512 void arb_tan(arb_t y, const arb_t x, slong prec);
513 void arb_cot(arb_t y, const arb_t x, slong prec);
514 void arb_tan_pi(arb_t y, const arb_t x, slong prec);
515 void arb_cot_pi(arb_t y, const arb_t x, slong prec);
516 void _arb_sin_pi_fmpq_algebraic(arb_t s, ulong p, ulong q, slong prec);
517 void _arb_cos_pi_fmpq_algebraic(arb_t c, ulong p, ulong q, slong prec);
518 void _arb_sin_cos_pi_fmpq_algebraic(arb_t s, arb_t c, ulong p, ulong q, slong prec);
519 void arb_sin_cos_pi_fmpq(arb_t s, arb_t c, const fmpq_t x, slong prec);
520 void arb_sin_pi_fmpq(arb_t s, const fmpq_t x, slong prec);
521 void arb_cos_pi_fmpq(arb_t c, const fmpq_t x, slong prec);
522 void arb_sinc(arb_t z, const arb_t x, slong prec);
523 void arb_sinc_pi(arb_t z, const arb_t x, slong prec);
524 void arb_sinh(arb_t z, const arb_t x, slong prec);
525 void arb_cosh(arb_t z, const arb_t x, slong prec);
526 void arb_sinh_cosh(arb_t s, arb_t c, const arb_t x, slong prec);
527 void arb_tanh(arb_t y, const arb_t x, slong prec);
528 void arb_coth(arb_t y, const arb_t x, slong prec);
529 void arb_atan_arf(arb_t z, const arf_t x, slong prec);
530 void arb_atan(arb_t z, const arb_t x, slong prec);
531 void arb_atan2(arb_t z, const arb_t b, const arb_t a, slong prec);
532 void arb_asin(arb_t z, const arb_t x, slong prec);
533 void arb_acos(arb_t z, const arb_t x, slong prec);
534 void arb_atanh(arb_t z, const arb_t x, slong prec);
535 void arb_asinh(arb_t z, const arb_t x, slong prec);
536 void arb_acosh(arb_t z, const arb_t x, slong prec);
537
538 void arb_sec(arb_t res, const arb_t x, slong prec);
539 void arb_csc(arb_t res, const arb_t x, slong prec);
540 void arb_csc_pi(arb_t res, const arb_t x, slong prec);
541 void arb_sech(arb_t res, const arb_t x, slong prec);
542 void arb_csch(arb_t res, const arb_t x, slong prec);
543
544 void arb_fac_ui(arb_t z, ulong n, slong prec);
545 void arb_doublefac_ui(arb_t z, ulong n, slong prec);
546 void arb_bin_ui(arb_t z, const arb_t n, ulong k, slong prec);
547 void arb_bin_uiui(arb_t z, ulong n, ulong k, slong prec);
548 void arb_fib_fmpz(arb_t z, const fmpz_t n, slong prec);
549 void arb_fib_ui(arb_t z, ulong n, slong prec);
550 void arb_const_pi(arb_t z, slong prec);
551 void arb_const_sqrt_pi(arb_t z, slong prec);
552 void arb_const_log_sqrt2pi(arb_t z, slong prec);
553 void arb_const_log2(arb_t z, slong prec);
554 void arb_const_log10(arb_t z, slong prec);
555 void arb_const_euler(arb_t z, slong prec);
556 void arb_const_catalan(arb_t z, slong prec);
557 void arb_const_e(arb_t z, slong prec);
558 void arb_const_khinchin(arb_t z, slong prec);
559 void arb_const_glaisher(arb_t z, slong prec);
560 void arb_agm(arb_t z, const arb_t x, const arb_t y, slong prec);
561 void arb_lgamma(arb_t z, const arb_t x, slong prec);
562 void arb_rgamma(arb_t z, const arb_t x, slong prec);
563 void arb_gamma(arb_t z, const arb_t x, slong prec);
564 void arb_gamma_fmpq(arb_t z, const fmpq_t x, slong prec);
565 void arb_gamma_fmpz(arb_t z, const fmpz_t x, slong prec);
566 void arb_digamma(arb_t y, const arb_t x, slong prec);
567 void arb_zeta(arb_t z, const arb_t s, slong prec);
568 void arb_hurwitz_zeta(arb_t z, const arb_t s, const arb_t a, slong prec);
569
570 void arb_rising_ui(arb_t z, const arb_t x, ulong n, slong prec);
571 void arb_rising_fmpq_ui(arb_t y, const fmpq_t x, ulong n, slong prec);
572 void arb_rising(arb_t z, const arb_t x, const arb_t n, slong prec);
573 void arb_rising2_ui(arb_t u, arb_t v, const arb_t x, ulong n, slong prec);
574
575 void arb_log_ui_from_prev(arb_t s, ulong k, arb_t log_prev, ulong prev, slong prec);
576
577 void arb_const_apery(arb_t s, slong prec);
578
579 void arb_zeta_ui_asymp(arb_t x, ulong s, slong prec);
580 void arb_zeta_ui_borwein_bsplit(arb_t x, ulong s, slong prec);
581 void arb_zeta_ui_euler_product(arb_t z, ulong s, slong prec);
582 void arb_zeta_ui_bernoulli(arb_t x, ulong n, slong prec);
583 void arb_zeta_ui_vec_borwein(arb_ptr z, ulong start, slong num, ulong step, slong prec);
584 void arb_zeta_ui(arb_t x, ulong n, slong prec);
585 void arb_zeta_ui_vec_even(arb_ptr x, ulong start, slong num, slong prec);
586 void arb_zeta_ui_vec_odd(arb_ptr x, ulong start, slong num, slong prec);
587 void arb_zeta_ui_vec(arb_ptr x, ulong start, slong num, slong prec);
588 void arb_bernoulli_ui(arb_t b, ulong n, slong prec);
589 void arb_bernoulli_ui_zeta(arb_t b, ulong n, slong prec);
590 void arb_bernoulli_fmpz(arb_t b, const fmpz_t n, slong prec);
591
592 void arb_bernoulli_poly_ui(arb_t res, ulong n, const arb_t x, slong prec);
593
594 void arb_polylog(arb_t w, const arb_t s, const arb_t z, slong prec);
595 void arb_polylog_si(arb_t w, slong s, const arb_t z, slong prec);
596
597 void arb_chebyshev_t_ui(arb_t a, ulong n, const arb_t x, slong prec);
598 void arb_chebyshev_t2_ui(arb_t a, arb_t b, ulong n, const arb_t x, slong prec);
599 void arb_chebyshev_u_ui(arb_t a, ulong n, const arb_t x, slong prec);
600 void arb_chebyshev_u2_ui(arb_t a, arb_t b, ulong n, const arb_t x, slong prec);
601
602 void arb_power_sum_vec(arb_ptr res, const arb_t a, const arb_t b, slong len, slong prec);
603 void arb_bell_sum_taylor(arb_t res, const fmpz_t n, const fmpz_t a, const fmpz_t b, const fmpz_t mmag, slong prec);
604 void arb_bell_sum_bsplit(arb_t res, const fmpz_t n, const fmpz_t a, const fmpz_t b, const fmpz_t mmag, slong prec);
605 void arb_bell_fmpz(arb_t res, const fmpz_t n, slong prec);
606 void arb_bell_ui(arb_t res, ulong n, slong prec);
607
608 void arb_euler_number_fmpz(arb_t res, const fmpz_t n, slong prec);
609 void arb_euler_number_ui(arb_t res, ulong n, slong prec);
610
611 void arb_partitions_fmpz(arb_t res, const fmpz_t n, slong prec);
612 void arb_partitions_ui(arb_t res, ulong n, slong prec);
613
614 void arb_lambertw(arb_t res, const arb_t x, int flags, slong prec);
615
616 ARB_INLINE void
arb_sqr(arb_t res,const arb_t val,slong prec)617 arb_sqr(arb_t res, const arb_t val, slong prec)
618 {
619 arb_mul(res, val, val, prec);
620 }
621
622 #define ARB_DEF_CACHED_CONSTANT(name, comp_func) \
623 TLS_PREFIX slong name ## _cached_prec = 0; \
624 TLS_PREFIX arb_t name ## _cached_value; \
625 void name ## _cleanup(void) \
626 { \
627 arb_clear(name ## _cached_value); \
628 name ## _cached_prec = 0; \
629 } \
630 void name(arb_t x, slong prec) \
631 { \
632 if (name ## _cached_prec < prec) \
633 { \
634 if (name ## _cached_prec == 0) \
635 { \
636 arb_init(name ## _cached_value); \
637 flint_register_cleanup_function(name ## _cleanup); \
638 } \
639 comp_func(name ## _cached_value, prec + 32); \
640 name ## _cached_prec = prec; \
641 } \
642 arb_set_round(x, name ## _cached_value, prec); \
643 }
644
645 /* vector functions */
646
647 ARB_INLINE arb_ptr
_arb_vec_entry_ptr(arb_ptr vec,slong i)648 _arb_vec_entry_ptr(arb_ptr vec, slong i)
649 {
650 return vec + i;
651 }
652
653 ARB_INLINE void
_arb_vec_printn(arb_srcptr vec,slong len,slong ndigits,ulong flags)654 _arb_vec_printn(arb_srcptr vec, slong len, slong ndigits, ulong flags)
655 {
656 slong i;
657 for (i = 0; i < len; i++)
658 {
659 arb_printn(vec + i, ndigits, flags);
660 if (i < len - 1)
661 flint_printf(", ");
662 }
663 }
664
665 ARB_INLINE void
_arb_vec_zero(arb_ptr A,slong n)666 _arb_vec_zero(arb_ptr A, slong n)
667 {
668 slong i;
669 for (i = 0; i < n; i++)
670 arb_zero(A + i);
671 }
672
673 ARB_INLINE int
_arb_vec_is_zero(arb_srcptr vec,slong len)674 _arb_vec_is_zero(arb_srcptr vec, slong len)
675 {
676 slong i;
677 for (i = 0; i < len; i++)
678 if (!arb_is_zero(vec + i))
679 return 0;
680 return 1;
681 }
682
683 ARB_INLINE int
_arb_vec_is_finite(arb_srcptr x,slong len)684 _arb_vec_is_finite(arb_srcptr x, slong len)
685 {
686 slong i;
687
688 for (i = 0; i < len; i++)
689 if (!arb_is_finite(x + i))
690 return 0;
691
692 return 1;
693 }
694
695 ARB_INLINE void
_arb_vec_set(arb_ptr res,arb_srcptr vec,slong len)696 _arb_vec_set(arb_ptr res, arb_srcptr vec, slong len)
697 {
698 slong i;
699 for (i = 0; i < len; i++)
700 arb_set(res + i, vec + i);
701 }
702
703 ARB_INLINE void
_arb_vec_set_round(arb_ptr res,arb_srcptr vec,slong len,slong prec)704 _arb_vec_set_round(arb_ptr res, arb_srcptr vec, slong len, slong prec)
705 {
706 slong i;
707 for (i = 0; i < len; i++)
708 arb_set_round(res + i, vec + i, prec);
709 }
710
711 ARB_INLINE void
_arb_vec_swap(arb_ptr res,arb_ptr vec,slong len)712 _arb_vec_swap(arb_ptr res, arb_ptr vec, slong len)
713 {
714 slong i;
715 for (i = 0; i < len; i++)
716 arb_swap(res + i, vec + i);
717 }
718
719 ARB_INLINE void
_arb_vec_neg(arb_ptr B,arb_srcptr A,slong n)720 _arb_vec_neg(arb_ptr B, arb_srcptr A, slong n)
721 {
722 slong i;
723 for (i = 0; i < n; i++)
724 arb_neg(B + i, A + i);
725 }
726
727 ARB_INLINE void
_arb_vec_sub(arb_ptr C,arb_srcptr A,arb_srcptr B,slong n,slong prec)728 _arb_vec_sub(arb_ptr C, arb_srcptr A,
729 arb_srcptr B, slong n, slong prec)
730 {
731 slong i;
732 for (i = 0; i < n; i++)
733 arb_sub(C + i, A + i, B + i, prec);
734 }
735
736 ARB_INLINE void
_arb_vec_add(arb_ptr C,arb_srcptr A,arb_srcptr B,slong n,slong prec)737 _arb_vec_add(arb_ptr C, arb_srcptr A,
738 arb_srcptr B, slong n, slong prec)
739 {
740 slong i;
741 for (i = 0; i < n; i++)
742 arb_add(C + i, A + i, B + i, prec);
743 }
744
745 ARB_INLINE void
_arb_vec_scalar_mul(arb_ptr res,arb_srcptr vec,slong len,const arb_t c,slong prec)746 _arb_vec_scalar_mul(arb_ptr res, arb_srcptr vec,
747 slong len, const arb_t c, slong prec)
748 {
749 slong i;
750 for (i = 0; i < len; i++)
751 arb_mul(res + i, vec + i, c, prec);
752 }
753
754 ARB_INLINE void
_arb_vec_scalar_div(arb_ptr res,arb_srcptr vec,slong len,const arb_t c,slong prec)755 _arb_vec_scalar_div(arb_ptr res, arb_srcptr vec,
756 slong len, const arb_t c, slong prec)
757 {
758 slong i;
759 for (i = 0; i < len; i++)
760 arb_div(res + i, vec + i, c, prec);
761 }
762
763 ARB_INLINE void
_arb_vec_scalar_mul_fmpz(arb_ptr res,arb_srcptr vec,slong len,const fmpz_t c,slong prec)764 _arb_vec_scalar_mul_fmpz(arb_ptr res, arb_srcptr vec,
765 slong len, const fmpz_t c, slong prec)
766 {
767 slong i;
768 arf_t t;
769 arf_init(t);
770 arf_set_fmpz(t, c);
771 for (i = 0; i < len; i++)
772 arb_mul_arf(res + i, vec + i, t, prec);
773 arf_clear(t);
774 }
775
776 ARB_INLINE void
_arb_vec_scalar_mul_2exp_si(arb_ptr res,arb_srcptr src,slong len,slong c)777 _arb_vec_scalar_mul_2exp_si(arb_ptr res, arb_srcptr src, slong len, slong c)
778 {
779 slong i;
780 for (i = 0; i < len; i++)
781 arb_mul_2exp_si(res + i, src + i, c);
782 }
783
784 ARB_INLINE void
_arb_vec_scalar_addmul(arb_ptr res,arb_srcptr vec,slong len,const arb_t c,slong prec)785 _arb_vec_scalar_addmul(arb_ptr res, arb_srcptr vec,
786 slong len, const arb_t c, slong prec)
787 {
788 slong i;
789 for (i = 0; i < len; i++)
790 arb_addmul(res + i, vec + i, c, prec);
791 }
792
793 void _arb_vec_get_mag(mag_t bound, arb_srcptr vec, slong len);
794
795 ARB_INLINE slong
_arb_vec_bits(arb_srcptr x,slong len)796 _arb_vec_bits(arb_srcptr x, slong len)
797 {
798 slong i, b, c;
799
800 b = 0;
801 for (i = 0; i < len; i++)
802 {
803 c = arb_bits(x + i);
804 b = FLINT_MAX(b, c);
805 }
806
807 return b;
808 }
809
810 void _arb_vec_set_powers(arb_ptr xs, const arb_t x, slong len, slong prec);
811
812 ARB_INLINE void
_arb_vec_add_error_arf_vec(arb_ptr res,arf_srcptr err,slong len)813 _arb_vec_add_error_arf_vec(arb_ptr res, arf_srcptr err, slong len)
814 {
815 slong i;
816 for (i = 0; i < len; i++)
817 arb_add_error_arf(res + i, err + i);
818 }
819
820 ARB_INLINE void
_arb_vec_add_error_mag_vec(arb_ptr res,mag_srcptr err,slong len)821 _arb_vec_add_error_mag_vec(arb_ptr res, mag_srcptr err, slong len)
822 {
823 slong i;
824 for (i = 0; i < len; i++)
825 mag_add(arb_radref(res + i), arb_radref(res + i), err + i);
826 }
827
828 ARB_INLINE void
_arb_vec_indeterminate(arb_ptr vec,slong len)829 _arb_vec_indeterminate(arb_ptr vec, slong len)
830 {
831 slong i;
832 for (i = 0; i < len; i++)
833 arb_indeterminate(vec + i);
834 }
835
836 ARB_INLINE void
_arb_vec_trim(arb_ptr res,arb_srcptr vec,slong len)837 _arb_vec_trim(arb_ptr res, arb_srcptr vec, slong len)
838 {
839 slong i;
840 for (i = 0; i < len; i++)
841 arb_trim(res + i, vec + i);
842 }
843
844 ARB_INLINE int
_arb_vec_get_unique_fmpz_vec(fmpz * res,arb_srcptr vec,slong len)845 _arb_vec_get_unique_fmpz_vec(fmpz * res, arb_srcptr vec, slong len)
846 {
847 slong i;
848 for (i = 0; i < len; i++)
849 if (!arb_get_unique_fmpz(res + i, vec + i))
850 return 0;
851 return 1;
852 }
853
854 /* arctangent implementation */
855
856 #define ARB_ATAN_TAB1_BITS 8
857 #define ARB_ATAN_TAB1_PREC 512
858 #define ARB_ATAN_TAB1_LIMBS (ARB_ATAN_TAB1_PREC / FLINT_BITS)
859
860 #define ARB_ATAN_TAB21_BITS 5
861 #define ARB_ATAN_TAB22_BITS 5
862 #define ARB_ATAN_TAB2_PREC 4608
863 #define ARB_ATAN_TAB2_LIMBS (ARB_ATAN_TAB2_PREC / FLINT_BITS)
864
865 ARB_DLL extern const mp_limb_t arb_atan_tab1[1 << ARB_ATAN_TAB1_BITS][ARB_ATAN_TAB1_LIMBS];
866 ARB_DLL extern const mp_limb_t arb_atan_tab21[1 << ARB_ATAN_TAB21_BITS][ARB_ATAN_TAB2_LIMBS];
867 ARB_DLL extern const mp_limb_t arb_atan_tab22[1 << ARB_ATAN_TAB22_BITS][ARB_ATAN_TAB2_LIMBS];
868 ARB_DLL extern const mp_limb_t arb_atan_pi2_minus_one[ARB_ATAN_TAB2_LIMBS];
869
870 void
871 _arb_atan_taylor_naive(mp_ptr y, mp_limb_t * error,
872 mp_srcptr x, mp_size_t xn, ulong N, int alternating);
873
874 void _arb_atan_taylor_rs(mp_ptr y, mp_limb_t * error,
875 mp_srcptr x, mp_size_t xn, ulong N, int alternating);
876
877 /* logarithm implementation */
878
879 #define ARB_LOG_TAB11_BITS 7
880 #define ARB_LOG_TAB12_BITS 7
881 #define ARB_LOG_TAB1_PREC 512
882 #define ARB_LOG_TAB1_LIMBS (ARB_LOG_TAB1_PREC / FLINT_BITS)
883
884 #define ARB_LOG_TAB21_BITS 5
885 #define ARB_LOG_TAB22_BITS 5
886 #define ARB_LOG_TAB2_PREC 4608
887 #define ARB_LOG_TAB2_LIMBS (ARB_LOG_TAB2_PREC / FLINT_BITS)
888
889 ARB_DLL extern const mp_limb_t arb_log_tab11[1 << ARB_LOG_TAB11_BITS][ARB_LOG_TAB1_LIMBS];
890 ARB_DLL extern const mp_limb_t arb_log_tab12[1 << ARB_LOG_TAB12_BITS][ARB_LOG_TAB1_LIMBS];
891 ARB_DLL extern const mp_limb_t arb_log_tab21[1 << ARB_LOG_TAB21_BITS][ARB_LOG_TAB2_LIMBS];
892 ARB_DLL extern const mp_limb_t arb_log_tab22[1 << ARB_LOG_TAB22_BITS][ARB_LOG_TAB2_LIMBS];
893 ARB_DLL extern const mp_limb_t arb_log_log2_tab[ARB_LOG_TAB2_LIMBS];
894
895 /* exponential implementation */
896
897 /* only goes up to log(2) * 256 */
898 #define ARB_EXP_TAB1_NUM 178
899 #define ARB_EXP_TAB1_BITS 8
900 #define ARB_EXP_TAB1_PREC 512
901 #define ARB_EXP_TAB1_LIMBS (ARB_EXP_TAB1_PREC / FLINT_BITS)
902
903 /* only goes up to log(2) * 32 */
904 #define ARB_EXP_TAB21_NUM 23
905 #define ARB_EXP_TAB21_BITS 5
906 #define ARB_EXP_TAB22_NUM (1 << ARB_EXP_TAB22_BITS)
907 #define ARB_EXP_TAB22_BITS 5
908 #define ARB_EXP_TAB2_PREC 4608
909 #define ARB_EXP_TAB2_LIMBS (ARB_EXP_TAB2_PREC / FLINT_BITS)
910
911 ARB_DLL extern const mp_limb_t arb_exp_tab1[ARB_EXP_TAB1_NUM][ARB_EXP_TAB1_LIMBS];
912 ARB_DLL extern const mp_limb_t arb_exp_tab21[ARB_EXP_TAB21_NUM][ARB_EXP_TAB2_LIMBS];
913 ARB_DLL extern const mp_limb_t arb_exp_tab22[ARB_EXP_TAB22_NUM][ARB_EXP_TAB2_LIMBS];
914
915 void _arb_exp_taylor_naive(mp_ptr y, mp_limb_t * error,
916 mp_srcptr x, mp_size_t xn, ulong N);
917
918 void _arb_exp_taylor_rs(mp_ptr y, mp_limb_t * error,
919 mp_srcptr x, mp_size_t xn, ulong N);
920
921 void arb_exp_arf_bb(arb_t z, const arf_t x, slong prec, int minus_one);
922 void arb_exp_arf_rs_generic(arb_t res, const arf_t x, slong prec, int minus_one);
923
924 int _arb_get_mpn_fixed_mod_log2(mp_ptr w, fmpz_t q, mp_limb_t * error,
925 const arf_t x, mp_size_t wn);
926
927 slong _arb_exp_taylor_bound(slong mag, slong prec);
928
929 void _arb_exp_sum_bs_powtab(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
930 const fmpz_t x, flint_bitcnt_t r, slong N);
931
932 void _arb_exp_sum_bs_simple(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
933 const fmpz_t x, flint_bitcnt_t r, slong N);
934
935 /* sin/cos implementation */
936
937 /* only goes up to (pi/4) * 256 */
938 #define ARB_SIN_COS_TAB1_NUM 203
939 #define ARB_SIN_COS_TAB1_BITS 8
940 #define ARB_SIN_COS_TAB1_PREC 512
941 #define ARB_SIN_COS_TAB1_LIMBS (ARB_SIN_COS_TAB1_PREC / FLINT_BITS)
942
943 /* only goes up to (pi/4) * 32 */
944 #define ARB_SIN_COS_TAB21_NUM 26
945 #define ARB_SIN_COS_TAB21_BITS 5
946 #define ARB_SIN_COS_TAB22_NUM (1 << ARB_SIN_COS_TAB22_BITS)
947 #define ARB_SIN_COS_TAB22_BITS 5
948 #define ARB_SIN_COS_TAB2_PREC 4608
949 #define ARB_SIN_COS_TAB2_LIMBS (ARB_SIN_COS_TAB2_PREC / FLINT_BITS)
950
951 ARB_DLL extern const mp_limb_t arb_sin_cos_tab1[2 * ARB_SIN_COS_TAB1_NUM][ARB_SIN_COS_TAB1_LIMBS];
952 ARB_DLL extern const mp_limb_t arb_sin_cos_tab21[2 * ARB_SIN_COS_TAB21_NUM][ARB_SIN_COS_TAB2_LIMBS];
953 ARB_DLL extern const mp_limb_t arb_sin_cos_tab22[2 * ARB_SIN_COS_TAB22_NUM][ARB_SIN_COS_TAB2_LIMBS];
954
955 #define ARB_PI4_TAB_LIMBS (4608 / FLINT_BITS)
956 ARB_DLL extern const mp_limb_t arb_pi4_tab[ARB_PI4_TAB_LIMBS];
957
958 void _arb_sin_cos_taylor_naive(mp_ptr ysin, mp_ptr ycos, mp_limb_t * error,
959 mp_srcptr x, mp_size_t xn, ulong N);
960
961 void _arb_sin_cos_taylor_rs(mp_ptr ysin, mp_ptr ycos,
962 mp_limb_t * error, mp_srcptr x, mp_size_t xn, ulong N,
963 int sinonly, int alternating);
964
965 int _arb_get_mpn_fixed_mod_pi4(mp_ptr w, fmpz_t q, int * octant,
966 mp_limb_t * error, const arf_t x, mp_size_t wn);
967
968 void arb_sin_cos_arf_bb(arb_t zsin, arb_t zcos, const arf_t x, slong prec);
969 void arb_sin_cos_arf_rs_generic(arb_t res_sin, arb_t res_cos, const arf_t x, slong prec);
970 void arb_sin_cos_arf_generic(arb_t res_sin, arb_t res_cos, const arf_t x, slong prec);
971
972 void _arb_sin_cos_wide(arb_t s, arb_t c, const arf_t x, const mag_t r, slong prec);
973 void arb_sin_cos_wide(arb_t s, arb_t c, const arb_t x, slong prec);
974
975 void _arb_sin_cos_generic(arb_t s, arb_t c, const arf_t x, const mag_t xrad, slong prec);
976 void arb_sin_cos_generic(arb_t s, arb_t c, const arb_t x, slong prec);
977
978 ARB_INLINE flint_bitcnt_t
_arb_mpn_leading_zeros(mp_srcptr d,mp_size_t n)979 _arb_mpn_leading_zeros(mp_srcptr d, mp_size_t n)
980 {
981 mp_limb_t t;
982 mp_size_t zero_limbs;
983 flint_bitcnt_t bits;
984
985 zero_limbs = 0;
986
987 while (1)
988 {
989 t = d[n - zero_limbs - 1];
990
991 if (t != 0)
992 {
993 count_leading_zeros(bits, t);
994 return bits + FLINT_BITS * zero_limbs;
995 }
996
997 zero_limbs++;
998
999 if (zero_limbs == n)
1000 return FLINT_BITS * zero_limbs;
1001 }
1002 }
1003
1004 void _arb_atan_sum_bs_simple(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
1005 const fmpz_t x, flint_bitcnt_t r, slong N);
1006
1007 void _arb_atan_sum_bs_powtab(fmpz_t T, fmpz_t Q, flint_bitcnt_t * Qexp,
1008 const fmpz_t x, flint_bitcnt_t r, slong N);
1009
1010 void arb_atan_arf_bb(arb_t z, const arf_t x, slong prec);
1011
1012 ARB_INLINE slong
arb_allocated_bytes(const arb_t x)1013 arb_allocated_bytes(const arb_t x)
1014 {
1015 return arf_allocated_bytes(arb_midref(x)) + mag_allocated_bytes(arb_radref(x));
1016 }
1017
1018 ARB_INLINE slong
_arb_vec_allocated_bytes(arb_srcptr vec,slong len)1019 _arb_vec_allocated_bytes(arb_srcptr vec, slong len)
1020 {
1021 slong i, size;
1022
1023 size = len * sizeof(arb_struct);
1024
1025 for (i = 0; i < len; i++)
1026 size += arb_allocated_bytes(vec + i);
1027
1028 return size;
1029 }
1030
1031 ARB_INLINE double
_arb_vec_estimate_allocated_bytes(slong len,slong prec)1032 _arb_vec_estimate_allocated_bytes(slong len, slong prec)
1033 {
1034 double size;
1035
1036 size = len * (double) sizeof(arb_struct);
1037
1038 if (prec > ARF_NOPTR_LIMBS * FLINT_BITS)
1039 size += len * (double) ((prec + FLINT_BITS - 1) / FLINT_BITS) * sizeof(mp_limb_t);
1040
1041 return size;
1042 }
1043
1044 int arb_load_str(arb_t res, const char * data);
1045
1046 char * arb_dump_str(const arb_t x);
1047
1048 int arb_load_file(arb_t res, FILE *stream);
1049
1050 int arb_dump_file(FILE* stream, const arb_t x);
1051
1052 #ifdef __cplusplus
1053 }
1054 #endif
1055
1056 #endif
1057