static void acb_set_dddd(acb_t z, double a, double ar, double b, double br) { arf_set_d(arb_midref(acb_realref(z)), a); mag_set_d(arb_radref(acb_realref(z)), ar); arf_set_d(arb_midref(acb_imagref(z)), b); mag_set_d(arb_radref(acb_imagref(z)), br); }
int main() { flint_printf("spherical_y...."); fflush(stdout); { slong i, n, m; acb_t z, w, x, y; acb_init(z); acb_init(w); acb_init(x); acb_init(y); i = 0; arb_set_str(acb_realref(x), "0.2", 64); arb_set_str(acb_imagref(x), "0.3", 64); arb_set_str(acb_realref(y), "0.3", 64); arb_set_str(acb_imagref(y), "0.4", 64); for (n = -4; n <= 4; n++) { for (m = -4; m <= 4; m++) { acb_hypgeom_spherical_y(z, n, m, x, y, 64); acb_set_d_d(w, testdata[2 * i], testdata[2 * i + 1]); mag_set_d(arb_radref(acb_realref(w)), 1e-13); mag_set_d(arb_radref(acb_imagref(w)), 1e-13); if (!acb_overlaps(z, w)) { flint_printf("FAIL: value\n\n"); flint_printf("n = %wd, m = %wd\n", n, m); flint_printf("z = "); acb_printd(z, 20); flint_printf("\n\n"); flint_printf("w = "); acb_printd(w, 20); flint_printf("\n\n"); abort(); } i++; } } acb_clear(z); acb_clear(w); acb_clear(x); acb_clear(y); } flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("set_d...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { fmpr_t a, b, c; mag_t m; double x; fmpr_init(a); fmpr_init(b); fmpr_init(c); mag_init(m); x = d_randtest2(state); x = ldexp(x, 100 - n_randint(state, 200)); if (n_randint(state, 100) == 0) x = 0.0; fmpr_set_d(a, x); mag_set_d(m, x); mag_get_fmpr(b, m); fmpr_set(c, a); fmpr_mul_ui(c, c, 1025, MAG_BITS, FMPR_RND_UP); fmpr_mul_2exp_si(c, c, -10); MAG_CHECK_BITS(m) if (!(fmpr_cmpabs(a, b) <= 0 && fmpr_cmpabs(b, c) <= 0)) { flint_printf("FAIL\n\n"); flint_printf("a = "); fmpr_print(a); flint_printf("\n\n"); flint_printf("b = "); fmpr_print(b); flint_printf("\n\n"); flint_printf("c = "); fmpr_print(c); flint_printf("\n\n"); abort(); } fmpr_clear(a); fmpr_clear(b); fmpr_clear(c); mag_clear(m); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("cauchy_bound...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100; iter++) { arb_t b, radius, ans; acb_t x; slong r, prec, maxdepth; arb_init(b); arb_init(radius); arb_init(ans); acb_init(x); acb_set_ui(x, 5); r = 1 + n_randint(state, 10); arb_set_ui(radius, r); prec = 2 + n_randint(state, 100); maxdepth = n_randint(state, 10); acb_calc_cauchy_bound(b, sin_x, NULL, x, radius, maxdepth, prec); arf_set_d(arb_midref(ans), answers[r-1]); mag_set_d(arb_radref(ans), 1e-8); if (!arb_overlaps(b, ans)) { flint_printf("FAIL\n"); flint_printf("r = %wd, prec = %wd, maxdepth = %wd\n\n", r, prec, maxdepth); arb_printd(b, 15); flint_printf("\n\n"); arb_printd(ans, 15); flint_printf("\n\n"); abort(); } arb_clear(b); arb_clear(radius); arb_clear(ans); acb_clear(x); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
/* - is contained in emb +/- rad 2 */ void randomized_embedding(arb_t res, double emb, double rad1, double rad2) { double t; /* in +/- (rad2 - rad1) / 2 */ double r; /* in [rad1 + |t|, rad2 - |t|]*/ if (rad1 <= 0 || rad2 <= 0 || rad1 >= rad2) abort(); t = (rad1 - rad2) / 2 + (rand() * (rad2 - rad1)) / RAND_MAX; if (2 * fabs(t) > (rad2 - rad1)) abort(); r = (rad1 + fabs(t)) + (rand() * (rad2 - rad1 - 2 * fabs(t))) / RAND_MAX; if (r < rad1 + fabs(t) || r > rad2 - fabs(t)) abort(); arf_set_d(arb_midref(res), emb + t); mag_set_d(arb_radref(res), r); }
int main() { slong iter; flint_rand_t state; flint_printf("euler_product_real_ui...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++) { arb_t res1, res2; ulong s; slong prec1, prec2, accuracy; int choice, reciprocal1, reciprocal2; if (iter % 10 == 0) { s = n_randtest(state); prec1 = 2 + n_randint(state, 300); prec2 = 2 + n_randint(state, 300); } else { s = 6 + n_randint(state, 1 << n_randint(state, 12)); prec1 = 2 + n_randint(state, 12 * s); prec2 = 2 + n_randint(state, 12 * s); } if (n_randint(state, 30) == 0) prec1 = 2 + n_randint(state, 4000); choice = n_randint(state, 7); reciprocal1 = n_randint(state, 2); reciprocal2 = n_randint(state, 2); arb_init(res1); arb_init(res2); arb_randtest(res1, state, 200, 100); _acb_dirichlet_euler_product_real_ui(res1, s, chi[choice] + 1, chi[choice][0], reciprocal1, prec1); _acb_dirichlet_euler_product_real_ui(res2, s, chi[choice] + 1, chi[choice][0], reciprocal2, prec2); if (reciprocal1 != reciprocal2) arb_inv(res2, res2, prec2); if (!arb_overlaps(res1, res2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("s = %wu\n\n", s); flint_printf("chi: %d\n", choice); flint_printf("res1 = "); arb_printd(res1, prec1 / 3.33); flint_printf("\n\n"); flint_printf("res2 = "); arb_printd(res2, prec2 / 3.33); flint_printf("\n\n"); abort(); } if (s >= 6 && prec1 < 2 * s * log(s)) { accuracy = arb_rel_accuracy_bits(res1); if (accuracy < prec1 - 4) { flint_printf("FAIL: accuracy = %wd, prec = %wd\n\n", accuracy, prec1); flint_printf("res1 = "); arb_printd(res1, prec1 / 3.33); flint_printf("\n\n"); abort(); } } if (s == 10) { arf_set_d(arb_midref(res2), L10[choice]); mag_set_d(arb_radref(res2), 1e-15); if (reciprocal1) arb_inv(res2, res2, 53); if (!arb_overlaps(res1, res2)) { flint_printf("FAIL: overlap (2)\n\n"); flint_printf("s = %wu\n\n", s); flint_printf("chi: %d\n", choice); flint_printf("res1 = "); arb_printd(res1, prec1 / 3.33); flint_printf("\n\n"); flint_printf("res2 = "); arb_printd(res2, prec2 / 3.33); flint_printf("\n\n"); abort(); } } arb_clear(res1); arb_clear(res2); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("agm1...."); fflush(stdout); flint_randinit(state); /* check particular values against table */ { acb_t z, t; acb_ptr w1; slong i, j, prec, cnj; acb_init(z); acb_init(t); w1 = _acb_vec_init(NUM_DERIVS); for (prec = 32; prec <= 512; prec *= 4) { for (i = 0; i < NUM_TESTS; i++) { for (cnj = 0; cnj < 2; cnj++) { if (cnj == 1 && agm_testdata[i][0] < 0 && agm_testdata[i][1] == 0) continue; acb_zero(z); arf_set_d(arb_midref(acb_realref(z)), agm_testdata[i][0]); arf_set_d(arb_midref(acb_imagref(z)), cnj ? -agm_testdata[i][1] : agm_testdata[i][1]); acb_agm1_cpx(w1, z, NUM_DERIVS, prec); for (j = 0; j < NUM_DERIVS; j++) { arf_set_d(arb_midref(acb_realref(t)), agm_testdata[i][2+2*j]); mag_set_d(arb_radref(acb_realref(t)), fabs(agm_testdata[i][2+2*j]) * EPS); arf_set_d(arb_midref(acb_imagref(t)), cnj ? -agm_testdata[i][2+2*j+1] : agm_testdata[i][2+2*j+1]); mag_set_d(arb_radref(acb_imagref(t)), fabs(agm_testdata[i][2+2*j+1]) * EPS); if (!acb_overlaps(w1 + j, t)) { flint_printf("FAIL\n\n"); flint_printf("j = %wd\n\n", j); flint_printf("z = "); acb_printd(z, 15); flint_printf("\n\n"); flint_printf("t = "); acb_printd(t, 15); flint_printf("\n\n"); flint_printf("w1 = "); acb_printd(w1 + j, 15); flint_printf("\n\n"); abort(); } } } } } _acb_vec_clear(w1, NUM_DERIVS); acb_clear(z); acb_clear(t); } /* self-consistency test */ for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { acb_ptr m1, m2; acb_t z1, z2, t; slong i, len1, len2, prec1, prec2; len1 = n_randint(state, 10); len2 = n_randint(state, 10); prec1 = 2 + n_randint(state, 2000); prec2 = 2 + n_randint(state, 2000); m1 = _acb_vec_init(len1); m2 = _acb_vec_init(len2); acb_init(z1); acb_init(z2); acb_init(t); acb_randtest(z1, state, prec1, 1 + n_randint(state, 100)); if (n_randint(state, 2)) { acb_set(z2, z1); } else { acb_randtest(t, state, prec2, 1 + n_randint(state, 100)); acb_add(z2, z1, t, prec2); acb_sub(z2, z2, t, prec2); } acb_agm1_cpx(m1, z1, len1, prec1); acb_agm1_cpx(m2, z2, len2, prec2); for (i = 0; i < FLINT_MIN(len1, len2); i++) { if (!acb_overlaps(m1 + i, m2 + i)) { flint_printf("FAIL (overlap)\n\n"); flint_printf("iter = %wd, i = %wd, len1 = %wd, len2 = %wd, prec1 = %wd, prec2 = %wd\n\n", iter, i, len1, len2, prec1, prec2); flint_printf("z1 = "); acb_printd(z1, 30); flint_printf("\n\n"); flint_printf("z2 = "); acb_printd(z2, 30); flint_printf("\n\n"); flint_printf("m1 = "); acb_printd(m1, 30); flint_printf("\n\n"); flint_printf("m2 = "); acb_printd(m2, 30); flint_printf("\n\n"); abort(); } } _acb_vec_clear(m1, len1); _acb_vec_clear(m2, len2); acb_clear(z1); acb_clear(z2); acb_clear(t); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
void mag_log1p(mag_t z, const mag_t x) { if (mag_is_special(x)) { if (mag_is_zero(x)) mag_zero(z); else mag_inf(z); } else { fmpz exp = MAG_EXP(x); if (!COEFF_IS_MPZ(exp)) { /* Quick bound by x */ if (exp < -10) { mag_set(z, x); return; } else if (exp < 1000) { double t; t = ldexp(MAG_MAN(x), exp - MAG_BITS); t = (1.0 + t) * (1 + 1e-14); t = mag_d_log_upper_bound(t); mag_set_d(z, t); return; } } else if (fmpz_sgn(MAG_EXPREF(x)) < 0) { /* Quick bound by x */ mag_set(z, x); return; } /* Now we must have x >= 2^1000 */ /* Use log(2^(exp-1) * (2*v)) = exp*log(2) + log(2*v) */ { double t; fmpz_t b; mag_t u; mag_init(u); fmpz_init(b); /* incrementing the mantissa gives an upper bound for x+1 */ t = ldexp(MAG_MAN(x) + 1, 1 - MAG_BITS); t = mag_d_log_upper_bound(t); mag_set_d(u, t); /* log(2) < 744261118/2^30 */ _fmpz_add_fast(b, MAG_EXPREF(x), -1); fmpz_mul_ui(b, b, 744261118); mag_set_fmpz(z, b); _fmpz_add_fast(MAG_EXPREF(z), MAG_EXPREF(z), -30); mag_add(z, z, u); mag_clear(u); fmpz_clear(b); } } }