void arb_log_arf_huge(arb_t z, const arf_t x, slong prec) { arf_t t; arb_t c; fmpz_t exp; slong wp; arf_init(t); arb_init(c); fmpz_init(exp); fmpz_neg(exp, ARF_EXPREF(x)); arf_mul_2exp_fmpz(t, x, exp); wp = prec + 4 - fmpz_bits(exp); wp = FLINT_MAX(wp, 4); arb_log_arf(z, t, wp); arb_const_log2(c, prec + 4); arb_submul_fmpz(z, c, exp, prec); arf_clear(t); arb_clear(c); fmpz_clear(exp); }
void arb_log_ui(arb_t z, ulong x, slong prec) { arf_t t; arf_init(t); arf_set_ui(t, x); arb_log_arf(z, t, prec); arf_clear(t); }
void arb_log_fmpz(arb_t z, const fmpz_t x, slong prec) { arf_t t; arf_init(t); arf_set_fmpz(t, x); arb_log_arf(z, t, prec); arf_clear(t); }
void arb_log(arb_t y, const arb_t x, slong prec) { if (arb_is_exact(x)) { arb_log_arf(y, arb_midref(x), prec); } else { /* Let the input be [a-b, a+b]. We require a > b >= 0 (otherwise the interval contains zero or a negative number and the logarithm is not defined). The error is largest at a-b, and we have log(a) - log(a-b) = log(1 + b/(a-b)). */ mag_t err; mag_init(err); arb_get_mag_lower_nonnegative(err, x); if (mag_is_zero(err)) { mag_inf(err); } else { mag_div(err, arb_radref(x), err); mag_log1p(err, err); } arb_log_arf(y, arb_midref(x), prec); mag_add(arb_radref(y), arb_radref(y), err); mag_clear(err); } }
int main() { slong iter; flint_rand_t state; flint_printf("log_arf...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 5000 * arb_test_multiplier(); iter++) { arf_t x; arb_t y1, y2; slong prec1, prec2, acc1, acc2; prec1 = 2 + n_randint(state, 9000); prec2 = 2 + n_randint(state, 9000); arf_init(x); arb_init(y1); arb_init(y2); arf_randtest_special(x, state, 1 + n_randint(state, 9000), 200); arb_randtest_special(y1, state, 1 + n_randint(state, 9000), 200); arb_randtest_special(y2, state, 1 + n_randint(state, 9000), 200); if (n_randint(state, 2)) arf_add_ui(x, x, 1, 2 + n_randint(state, 9000), ARF_RND_DOWN); arb_log_arf(y1, x, prec1); arb_log_arf(y2, x, prec2); if (!arb_overlaps(y1, y2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("prec1 = %wd, prec2 = %wd\n\n", prec1, prec2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y1 = "); arb_print(y1); flint_printf("\n\n"); flint_printf("y2 = "); arb_print(y2); flint_printf("\n\n"); abort(); } acc1 = arb_rel_accuracy_bits(y1); acc2 = arb_rel_accuracy_bits(y2); if (arf_sgn(x) > 0) { if (acc1 < prec1 - 2 || acc2 < prec2 - 2) { flint_printf("FAIL: accuracy\n\n"); flint_printf("prec1 = %wd, prec2 = %wd\n\n", prec1, prec2); flint_printf("acc1 = %wd, acc2 = %wd\n\n", acc1, acc2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y1 = "); arb_print(y1); flint_printf("\n\n"); flint_printf("y2 = "); arb_print(y2); flint_printf("\n\n"); abort(); } } arf_clear(x); arb_clear(y1); arb_clear(y2); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }