int main() { slong iter; flint_rand_t state; flint_printf("set_d_2exp_fmpz...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { fmpr_t a, b, c; fmpz_t e; mag_t m; double x; fmpr_init(a); fmpr_init(b); fmpr_init(c); fmpz_init(e); mag_init(m); x = d_randtest2(state); x = ldexp(x, 100 - n_randint(state, 200)); if (n_randint(state, 100) == 0) x = 0.0; fmpz_randtest(e, state, 10); fmpr_set_d(a, x); fmpr_mul_2exp_fmpz(a, a, e); mag_set_d_2exp_fmpz(m, x, e); 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); fmpz_clear(e); 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("set_round...."); fflush(stdout); flint_randinit(state); { arf_t x, y, z; arf_init(x); arf_init(y); arf_init(z); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { slong bits1, bits2; int ret1, ret2; mpfr_t g1, g2; fmpz_t e; arf_rnd_t rnd; bits1 = 1 + n_randint(state, 1000); bits2 = 2 + n_randint(state, 1000); if (n_randint(state, 100) == 0) bits2 = ARF_PREC_EXACT; switch (n_randint(state, 5)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } fmpz_init(e); mpfr_init2(g1, FLINT_MAX(2, bits1)); mpfr_init2(g2, FLINT_MIN(bits2, 10000)); if (n_randint(state, 100) == 0) { arf_clear(x); arf_clear(y); arf_clear(z); arf_init(x); arf_init(y); arf_init(z); } /* dirty output variables */ if (n_randint(state, 2)) { arf_randtest_special(y, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); arf_randtest_special(z, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); } arf_randtest_special(x, state, bits1, 1 + n_randint(state, 10)); arf_get_mpfr(g1, x, MPFR_RNDD); /* exact */ /* test large exponents */ if (n_randint(state, 4) == 0) fmpz_randtest(e, state, 1 + n_randint(state, 100)); if (!arf_is_special(x)) fmpz_add(ARF_EXPREF(x), ARF_EXPREF(x), e); ret1 = arf_set_round(y, x, bits2, rnd); ret2 = mpfr_set(g2, g1, arf_rnd_to_mpfr(rnd)); arf_set_mpfr(z, g2); if (!arf_is_special(y)) fmpz_sub(ARF_EXPREF(y), ARF_EXPREF(y), e); if (!arf_equal(y, z) || ((ret1 == ARF_RESULT_EXACT) != (ret2 == 0))) { flint_printf("FAIL\n\n"); flint_printf("bits1: %wd\n", bits1); flint_printf("bits2: %wd\n", bits2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("ret1 = %d, ret2 = %d\n\n", ret1, ret2); flint_abort(); } if (!arf_is_special(x)) fmpz_add(ARF_EXPREF(x), ARF_EXPREF(x), e); ret1 = arf_set_round(y, x, bits2, rnd); arf_set(z, x); ret2 = arf_set_round(z, z, bits2, rnd); if (!arf_equal(y, z) || ret1 != ret2) { flint_printf("FAIL (aliasing)\n\n"); flint_printf("bits1: %wd\n", bits1); flint_printf("bits2: %wd\n", bits2); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("ret1 = %d, ret2 = %d\n\n", ret1, ret2); flint_abort(); } mpfr_clear(g1); mpfr_clear(g2); fmpz_clear(e); } arf_clear(x); arf_clear(y); arf_clear(z); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("sum...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000000 * arb_test_multiplier(); iter++) { slong i, len, prec, bits, expbits, res1, res2; fmpr_t s1, s2, s3, err, err_bound; fmpr_struct terms[20]; fmpr_rnd_t rnd; len = n_randint(state, 20); bits = 2 + n_randint(state, 1000); prec = 2 + n_randint(state, 1000); expbits = n_randint(state, 14); fmpr_init(s1); fmpr_init(s2); fmpr_init(s3); fmpr_init(err); fmpr_init(err_bound); for (i = 0; i < len; i++) { fmpr_init(terms + i); fmpr_randtest_special(terms + i, state, bits, expbits); } switch (n_randint(state, 4)) { case 0: rnd = FMPR_RND_DOWN; break; case 1: rnd = FMPR_RND_UP; break; case 2: rnd = FMPR_RND_FLOOR; break; default: rnd = FMPR_RND_CEIL; break; } res1 = fmpr_sum(s1, terms, len, prec, rnd); fmpr_zero(s2); for (i = 0; i < len; i++) fmpr_add(s2, s2, terms + i, FMPR_PREC_EXACT, FMPR_RND_DOWN); res2 = fmpr_set_round(s3, s2, prec, rnd); if (!fmpr_equal(s1, s3) || res1 != res2 || !fmpr_check_ulp(s1, res1, prec) || !fmpr_check_ulp(s3, res2, prec)) { flint_printf("FAIL (%wd)\n\n", iter); flint_printf("prec = %wd\n\n", prec); for (i = 0; i < len; i++) { flint_printf("terms[%wd] = ", i); fmpr_print(terms + i); flint_printf("\n\n"); } flint_printf("s1 = "); fmpr_print(s1); flint_printf("\n\n"); flint_printf("s2 = "); fmpr_print(s2); flint_printf("\n\n"); flint_printf("s3 = "); fmpr_print(s3); flint_printf("\n\n"); flint_printf("res1 = %wd, res2 = %wd\n\n", res1, res2); abort(); } fmpr_sub(err, s1, s2, FMPR_PREC_EXACT, FMPR_RND_DOWN); fmpr_abs(err, err); fmpr_set_error_result(err_bound, s1, res1); if (fmpr_cmp(err, err_bound) > 0) { flint_printf("FAIL (error bound)!\n"); flint_printf("prec = %wd\n\n", prec); for (i = 0; i < len; i++) { flint_printf("terms[%wd] = ", i); fmpr_print(terms + i); flint_printf("\n\n"); } flint_printf("s1 = "); fmpr_print(s1); flint_printf("\n\n"); flint_printf("s2 = "); fmpr_print(s2); flint_printf("\n\n"); flint_printf("s3 = "); fmpr_print(s3); flint_printf("\n\n"); flint_printf("error: "); fmpr_print(err); flint_printf("\n\n"); flint_printf("error bound: "); fmpr_print(err_bound); flint_printf("\n\n"); flint_printf("res1 = %wd, res2 = %wd\n\n", res1, res2); abort(); } fmpr_clear(s1); fmpr_clear(s2); fmpr_clear(s3); fmpr_clear(err); fmpr_clear(err_bound); for (i = 0; i < len; i++) fmpr_clear(terms + i); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("taylor_shift_convolution...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++) { slong prec1, prec2; acb_poly_t f, g; acb_t c, d, e; prec1 = 2 + n_randint(state, 500); prec2 = 2 + n_randint(state, 500); acb_poly_init(f); acb_poly_init(g); acb_init(c); acb_init(d); acb_init(e); acb_poly_randtest(f, state, 1 + n_randint(state, 40), 1 + n_randint(state, 500), 10); acb_poly_randtest(g, state, 1 + n_randint(state, 20), 1 + n_randint(state, 500), 10); if (n_randint(state, 2)) acb_set_si(c, n_randint(state, 5) - 2); else acb_randtest(c, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100)); if (n_randint(state, 2)) acb_set_si(d, n_randint(state, 5) - 2); else acb_randtest(d, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100)); acb_add(e, c, d, prec1); /* check f(x+c)(x+d) = f(x+c+d) */ acb_poly_taylor_shift_convolution(g, f, e, prec2); acb_poly_taylor_shift_convolution(f, f, c, prec1); acb_poly_taylor_shift_convolution(f, f, d, prec1); if (!acb_poly_overlaps(f, g)) { flint_printf("FAIL\n\n"); flint_printf("c = "); acb_printd(c, 15); flint_printf("\n\n"); flint_printf("d = "); acb_printd(d, 15); flint_printf("\n\n"); flint_printf("f = "); acb_poly_printd(f, 15); flint_printf("\n\n"); flint_printf("g = "); acb_poly_printd(g, 15); flint_printf("\n\n"); flint_abort(); } acb_poly_clear(f); acb_poly_clear(g); acb_clear(c); acb_clear(d); acb_clear(e); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("sin_cos_series_basecase...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { slong m, n, qbits, rbits1, rbits2; fmpq_poly_t A, B; arb_poly_t a, b, c, d, e; int times_pi; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); m = 1 + n_randint(state, 30); n = 1 + n_randint(state, 30); times_pi = n_randint(state, 2); fmpq_poly_init(A); fmpq_poly_init(B); arb_poly_init(a); arb_poly_init(b); arb_poly_init(c); arb_poly_init(d); arb_poly_init(e); fmpq_poly_randtest(A, state, m, qbits); arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_sin_cos_series_basecase(b, c, a, n, rbits2, times_pi); /* Check sin(x)^2 + cos(x)^2 = 1 */ arb_poly_mullow(d, b, b, n, rbits2); arb_poly_mullow(e, c, c, n, rbits2); arb_poly_add(d, d, e, rbits2); fmpq_poly_one(B); if (!arb_poly_contains_fmpq_poly(d, B)) { flint_printf("FAIL\n\n"); flint_printf("bits2 = %wd\n", rbits2); flint_printf("A = "); fmpq_poly_print(A); flint_printf("\n\n"); flint_printf("a = "); arb_poly_printd(a, 15); flint_printf("\n\n"); flint_printf("b = "); arb_poly_printd(b, 15); flint_printf("\n\n"); flint_printf("c = "); arb_poly_printd(c, 15); flint_printf("\n\n"); flint_printf("d = "); arb_poly_printd(d, 15); flint_printf("\n\n"); flint_abort(); } arb_poly_set(d, a); arb_poly_sin_cos_series_basecase(d, c, d, n, rbits2, times_pi); if (!arb_poly_equal(b, d)) { flint_printf("FAIL (aliasing 1)\n\n"); flint_abort(); } arb_poly_set(d, a); arb_poly_sin_cos_series_basecase(b, d, d, n, rbits2, times_pi); if (!arb_poly_equal(c, d)) { flint_printf("FAIL (aliasing 2)\n\n"); flint_abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); arb_poly_clear(a); arb_poly_clear(b); arb_poly_clear(c); arb_poly_clear(d); arb_poly_clear(e); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("erfi_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 200 * arb_test_multiplier(); iter++) { slong m, n1, n2, bits1, bits2, bits3; acb_poly_t S, A, B, C; acb_t I; bits1 = 2 + n_randint(state, 200); bits2 = 2 + n_randint(state, 200); bits3 = 2 + n_randint(state, 200); m = 1 + n_randint(state, 10); n1 = 1 + n_randint(state, 10); n2 = 1 + n_randint(state, 10); acb_poly_init(S); acb_poly_init(A); acb_poly_init(B); acb_poly_init(C); acb_init(I); acb_poly_randtest(S, state, m, bits1, 3); acb_poly_randtest(A, state, m, bits1, 3); acb_poly_randtest(B, state, m, bits1, 3); acb_hypgeom_erfi_series(A, S, n1, bits2); acb_onei(I); acb_poly_set_acb(C, I); acb_poly_mul(B, S, C, bits3); acb_hypgeom_erf_series(B, B, n2, bits3); acb_poly_neg(C, C); acb_poly_mul(B, B, C, bits3); acb_poly_set(C, A); acb_poly_truncate(C, FLINT_MIN(n1, n2)); acb_poly_truncate(B, FLINT_MIN(n1, n2)); if (!acb_poly_overlaps(B, C)) { flint_printf("FAIL\n\n"); flint_printf("S = "); acb_poly_printd(S, 15); flint_printf("\n\n"); flint_printf("A = "); acb_poly_printd(A, 15); flint_printf("\n\n"); flint_printf("B = "); acb_poly_printd(B, 15); flint_printf("\n\n"); abort(); } acb_hypgeom_erfi_series(S, S, n1, bits2); if (!acb_poly_overlaps(A, S)) { flint_printf("FAIL (aliasing)\n\n"); abort(); } acb_poly_clear(S); acb_poly_clear(A); acb_poly_clear(B); acb_poly_clear(C); acb_clear(I); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("bernoulli_poly_ui...."); fflush(stdout); flint_randinit(state); /* test multiplication theorem */ for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { arb_t x, t, res1, res2; ulong n, m, k; slong prec; n = n_randint(state, 50); m = 1 + n_randint(state, 5); prec = 2 + n_randint(state, 200); arb_init(x); arb_init(t); arb_init(res1); arb_init(res2); arb_randtest(x, state, 2 + n_randint(state, 200), 20); arb_randtest(res1, state, 2 + n_randint(state, 200), 20); arb_mul_ui(t, x, m, prec); arb_bernoulli_poly_ui(res1, n, t, prec); arb_zero(res2); for (k = 0; k < m; k++) { arb_set_ui(t, k); arb_div_ui(t, t, m, prec); arb_add(t, t, x, prec); arb_bernoulli_poly_ui(t, n, t, prec); arb_add(res2, res2, t, prec); } if (n > 0) { arb_ui_pow_ui(t, m, n - 1, prec); arb_mul(res2, res2, t, prec); } else { arb_div_ui(res2, res2, m, prec); } if (!arb_overlaps(res1, res2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("n = %wu, m = %wu\n\n", n, m); flint_printf("x = "); arb_printd(x, 15); flint_printf("\n\n"); flint_printf("res1 = "); arb_printd(res1, 15); flint_printf("\n\n"); flint_printf("res2 = "); arb_printd(res2, 15); flint_printf("\n\n"); abort(); } arb_clear(x); arb_clear(t); 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("div...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arb_t a, b, c; fmpq_t x, y, z; arb_init(a); arb_init(b); arb_init(c); fmpq_init(x); fmpq_init(y); fmpq_init(z); do { arb_randtest(a, state, 1 + n_randint(state, 200), 10); arb_randtest(b, state, 1 + n_randint(state, 200), 10); arb_randtest(c, state, 1 + n_randint(state, 200), 10); arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200)); arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200)); } while (fmpq_is_zero(y)); arb_div(c, a, b, 2 + n_randint(state, 200)); fmpq_div(z, x, y); if (!arb_contains_fmpq(c, z)) { flint_printf("FAIL: containment\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("x = "); fmpq_print(x); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); flint_printf("z = "); fmpq_print(z); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } /* aliasing of c and a */ for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arb_t a, b; fmpq_t x, y, z; arb_init(a); arb_init(b); fmpq_init(x); fmpq_init(y); fmpq_init(z); do { arb_randtest(a, state, 1 + n_randint(state, 200), 10); arb_randtest(b, state, 1 + n_randint(state, 200), 10); arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200)); arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200)); } while (fmpq_is_zero(y)); arb_div(a, a, b, 2 + n_randint(state, 200)); fmpq_div(z, x, y); if (!arb_contains_fmpq(a, z)) { flint_printf("FAIL: aliasing (c, a)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("x = "); fmpq_print(x); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpq_print(z); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } /* aliasing of c and b */ for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arb_t a, b; fmpq_t x, y, z; arb_init(a); arb_init(b); fmpq_init(x); fmpq_init(y); fmpq_init(z); do { arb_randtest(a, state, 1 + n_randint(state, 200), 10); arb_randtest(b, state, 1 + n_randint(state, 200), 10); arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200)); arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200)); } while (fmpq_is_zero(y)); arb_div(b, a, b, 2 + n_randint(state, 200)); fmpq_div(z, x, y); if (!arb_contains_fmpq(b, z)) { flint_printf("FAIL: aliasing (c, b)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("x = "); fmpq_print(x); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpq_print(z); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } /* test special values */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arb_t a, b, c, d; arb_init(a); arb_init(b); arb_init(c); arb_init(d); arb_randtest_special(a, state, 1 + n_randint(state, 200), 1 + n_randint(state, 100)); arb_randtest_special(b, state, 1 + n_randint(state, 200), 1 + n_randint(state, 100)); arb_randtest_special(c, state, 1 + n_randint(state, 200), 1 + n_randint(state, 100)); arb_div(c, a, b, 2 + n_randint(state, 200)); arb_mul(d, c, b, 2 + n_randint(state, 200)); if (!arb_contains(d, a)) { flint_printf("FAIL: containment\n\n"); flint_printf("a = "); arb_printd(a, 15); flint_printf("\n\n"); flint_printf("b = "); arb_printd(b, 15); flint_printf("\n\n"); flint_printf("c = "); arb_printd(c, 15); flint_printf("\n\n"); flint_printf("d = "); arb_printd(d, 15); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arb_clear(d); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("l_euler_product...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 500 * arb_test_multiplier(); iter++) { acb_t s, t, u; dirichlet_group_t G; dirichlet_char_t chi; ulong q, k; slong prec; acb_init(s); acb_init(t); acb_init(u); q = 1 + n_randint(state, 50); prec = 2 + n_randint(state, 500); k = n_randint(state, n_euler_phi(q)); dirichlet_group_init(G, q); dirichlet_char_init(chi, G); dirichlet_char_index(chi, G, k); if (n_randint(state, 2)) { acb_set_ui(s, 2 + n_randint(state, prec + 50)); } else { acb_randtest(s, state, 2 + n_randint(state, 200), 2); arb_abs(acb_realref(s), acb_realref(s)); if (n_randint(state, 2)) acb_add_ui(s, s, n_randtest(state), prec); } if (n_randint(state, 2)) acb_dirichlet_l_hurwitz(t, s, NULL, G, chi, prec); else acb_dirichlet_l_euler_product(t, s, G, chi, prec * 1.5); acb_dirichlet_l_euler_product(u, s, G, chi, prec); if (!acb_overlaps(t, u)) { flint_printf("FAIL: overlap\n\n"); flint_printf("iter = %ld q = %lu k = %lu prec = %ld\n\n", iter, q, k, prec); flint_printf("s = "); acb_printn(s, 100, 0); flint_printf("\n\n"); flint_printf("t = "); acb_printn(t, 100, 0); flint_printf("\n\n"); flint_printf("u = "); acb_printn(u, 100, 0); flint_printf("\n\n"); flint_abort(); } dirichlet_char_clear(chi); dirichlet_group_clear(G); acb_clear(s); acb_clear(t); acb_clear(u); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("divrem...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { slong m, n, qbits1, qbits2, rbits1, rbits2, rbits3; fmpq_poly_t A, B, Q, R; acb_poly_t a, b, q, r; qbits1 = 2 + n_randint(state, 200); qbits2 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); rbits3 = 2 + n_randint(state, 200); m = 1 + n_randint(state, 20); n = 1 + n_randint(state, 20); fmpq_poly_init(A); fmpq_poly_init(B); fmpq_poly_init(Q); fmpq_poly_init(R); acb_poly_init(a); acb_poly_init(b); acb_poly_init(q); acb_poly_init(r); fmpq_poly_randtest(A, state, m, qbits1); fmpq_poly_randtest_not_zero(B, state, n, qbits2); fmpq_poly_divrem(Q, R, A, B); acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_set_fmpq_poly(b, B, rbits2); acb_poly_divrem(q, r, a, b, rbits3); if (!acb_poly_contains_fmpq_poly(q, Q) || !acb_poly_contains_fmpq_poly(r, R)) { flint_printf("FAIL\n\n"); flint_printf("A = "); fmpq_poly_print(A); flint_printf("\n\n"); flint_printf("B = "); fmpq_poly_print(B); flint_printf("\n\n"); flint_printf("Q = "); fmpq_poly_print(Q); flint_printf("\n\n"); flint_printf("R = "); fmpq_poly_print(R); flint_printf("\n\n"); flint_printf("a = "); acb_poly_printd(a, 15); flint_printf("\n\n"); flint_printf("b = "); acb_poly_printd(b, 15); flint_printf("\n\n"); flint_printf("q = "); acb_poly_printd(q, 15); flint_printf("\n\n"); flint_printf("r = "); acb_poly_printd(r, 15); flint_printf("\n\n"); abort(); } acb_poly_divrem(a, r, a, b, rbits3); if (!acb_poly_equal(a, q)) { flint_printf("FAIL (aliasing q, a)\n\n"); } acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_divrem(b, r, a, b, rbits3); if (!acb_poly_equal(b, q)) { flint_printf("FAIL (aliasing q, b)\n\n"); abort(); } acb_poly_set_fmpq_poly(b, B, rbits2); acb_poly_divrem(q, a, a, b, rbits3); if (!acb_poly_equal(a, r)) { flint_printf("FAIL (aliasing r, a)\n\n"); abort(); } acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_divrem(q, b, a, b, rbits3); if (!acb_poly_equal(b, r)) { flint_printf("FAIL (aliasing r, b)\n\n"); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpq_poly_clear(Q); fmpq_poly_clear(R); acb_poly_clear(a); acb_poly_clear(b); acb_poly_clear(q); acb_poly_clear(r); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter, iter2; flint_rand_t state; flint_printf("add_si...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arf_t x, z, v; slong y; slong prec, r1, r2; arf_rnd_t rnd; arf_init(x); arf_init(z); arf_init(v); for (iter2 = 0; iter2 < 100; iter2++) { arf_randtest_special(x, state, 2000, 10); y = z_randtest(state); prec = 2 + n_randint(state, 2000); if (n_randint(state, 10) == 0 && fmpz_bits(ARF_EXPREF(x)) < 10) { prec = ARF_PREC_EXACT; } switch (n_randint(state, 5)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } switch (n_randint(state, 1)) { case 0: r1 = arf_add_si(z, x, y, prec, rnd); r2 = arf_add_si_naive(v, x, y, prec, rnd); if (!arf_equal(z, v) || r1 != r2) { flint_printf("FAIL! (ha iter %ld, %ld)\n", iter, iter2); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); flint_printf("%wd", y); flint_printf("\n\n"); flint_printf("z = "); arf_print(z); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; default: r2 = arf_add_si_naive(v, x, y, prec, rnd); r1 = arf_add_si(x, x, y, prec, rnd); if (!arf_equal(x, v) || r1 != r2) { flint_printf("FAIL (aliasing)!\n"); flint_printf("prec = %wd, rnd = %d\n\n", prec, rnd); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); flint_printf("%wd", y); flint_printf("\n\n"); flint_printf("v = "); arf_print(v); flint_printf("\n\n"); flint_printf("r1 = %wd, r2 = %wd\n", r1, r2); abort(); } break; } } arf_clear(x); arf_clear(z); arf_clear(v); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("mul_more...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arb_t a, b, c; fmpq_t x, y, z; arb_init(a); arb_init(b); arb_init(c); fmpq_init(x); fmpq_init(y); fmpq_init(z); arb_randtest(a, state, 1 + n_randint(state, 200), 10); arb_randtest(b, state, 1 + n_randint(state, 200), 10); arb_randtest(c, state, 1 + n_randint(state, 200), 10); arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200)); arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200)); arb_mul(c, a, b, 2 + n_randint(state, 200)); fmpq_mul(z, x, y); if (!arb_contains_fmpq(c, z)) { flint_printf("FAIL: containment\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("x = "); fmpq_print(x); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); flint_printf("z = "); fmpq_print(z); flint_printf("\n\n"); flint_abort(); } arb_clear(a); arb_clear(b); arb_clear(c); fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } /* aliasing of c and a */ for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arb_t a, b; fmpq_t x, y, z; arb_init(a); arb_init(b); fmpq_init(x); fmpq_init(y); fmpq_init(z); arb_randtest(a, state, 1 + n_randint(state, 200), 10); arb_randtest(b, state, 1 + n_randint(state, 200), 10); arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200)); arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200)); arb_mul(a, a, b, 2 + n_randint(state, 200)); fmpq_mul(z, x, y); if (!arb_contains_fmpq(a, z)) { flint_printf("FAIL: aliasing (c, a)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("x = "); fmpq_print(x); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpq_print(z); flint_printf("\n\n"); flint_abort(); } arb_clear(a); arb_clear(b); fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } /* aliasing of c and b */ for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arb_t a, b; fmpq_t x, y, z; arb_init(a); arb_init(b); fmpq_init(x); fmpq_init(y); fmpq_init(z); arb_randtest(a, state, 1 + n_randint(state, 200), 10); arb_randtest(b, state, 1 + n_randint(state, 200), 10); arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200)); arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200)); arb_mul(b, a, b, 2 + n_randint(state, 200)); fmpq_mul(z, x, y); if (!arb_contains_fmpq(b, z)) { flint_printf("FAIL: aliasing (c, b)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("x = "); fmpq_print(x); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("y = "); fmpq_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpq_print(z); flint_printf("\n\n"); flint_abort(); } arb_clear(a); arb_clear(b); fmpq_clear(x); fmpq_clear(y); fmpq_clear(z); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("sub_si...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arb_t a, b, c, d; slong x; slong prec; arb_init(a); arb_init(b); arb_init(c); arb_init(d); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100); x = z_randtest(state); prec = 2 + n_randint(state, 2000); arb_set_si(b, x); arb_sub_si(c, a, x, prec); arb_sub(d, a, b, prec); if (!arb_equal(c, d)) { flint_printf("FAIL\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); flint_printf("d = "); arb_print(d); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); arb_clear(d); } /* aliasing */ for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { arb_t a, b, c; slong x; slong prec; arb_init(a); arb_init(b); arb_init(c); arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100); arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100); x = z_randtest(state); prec = 2 + n_randint(state, 2000); arb_set_si(b, x); arb_sub_si(c, a, x, prec); arb_sub_si(a, a, x, prec); if (!arb_equal(a, c)) { flint_printf("FAIL (aliasing)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("add...."); fflush(stdout); flint_randinit(state); /* test exact addition: (x + y) + z == x + (y + z) */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { slong bits, res1, res2, res3, res4; fmpr_t x, y, z, t, u; bits = 2 + n_randint(state, 200); fmpr_init(x); fmpr_init(y); fmpr_init(z); fmpr_init(t); fmpr_init(u); fmpr_randtest_special(x, state, bits, 10); fmpr_randtest_special(y, state, bits, 10); fmpr_randtest_special(z, state, bits, 10); fmpr_randtest_special(t, state, bits, 10); fmpr_randtest_special(u, state, bits, 10); res1 = fmpr_add(t, x, y, FMPR_PREC_EXACT, FMPR_RND_DOWN); res2 = fmpr_add(t, t, z, FMPR_PREC_EXACT, FMPR_RND_DOWN); res3 = fmpr_add(u, y, z, FMPR_PREC_EXACT, FMPR_RND_DOWN); res4 = fmpr_add(u, x, u, FMPR_PREC_EXACT, FMPR_RND_DOWN); if (!fmpr_equal(t, u) || res1 != FMPR_RESULT_EXACT || res2 != FMPR_RESULT_EXACT || res3 != FMPR_RESULT_EXACT || res4 != FMPR_RESULT_EXACT) { flint_printf("FAIL\n\n"); flint_printf("bits = %wd\n", bits); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); flint_printf("t = "); fmpr_print(t); flint_printf("\n\n"); flint_printf("u = "); fmpr_print(u); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(y); fmpr_clear(z); fmpr_clear(t); fmpr_clear(u); } /* compare with add_naive */ for (iter = 0; iter < 1000000 * arb_test_multiplier(); iter++) { slong prec, ret1, ret2; fmpr_t x, y, z, w; fmpr_rnd_t rnd; fmpr_init(x); fmpr_init(y); fmpr_init(z); fmpr_init(w); fmpr_randtest_special(x, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 200)); fmpr_randtest_special(y, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 200)); fmpr_randtest_special(z, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 200)); prec = 2 + n_randint(state, 1000); if (n_randint(state, 10) == 0 && fmpz_bits(fmpr_expref(x)) < 10 && fmpz_bits(fmpr_expref(y)) < 10) prec = FMPR_PREC_EXACT; switch (n_randint(state, 4)) { case 0: rnd = FMPR_RND_DOWN; break; case 1: rnd = FMPR_RND_UP; break; case 2: rnd = FMPR_RND_FLOOR; break; default: rnd = FMPR_RND_CEIL; break; } ret1 = fmpr_add(z, x, y, prec, rnd); ret2 = fmpr_add_naive(w, x, y, prec, rnd); if (!fmpr_equal(z, w) || ret1 != ret2 || !fmpr_check_ulp(z, ret1, prec) || !fmpr_check_ulp(w, ret2, prec)) { flint_printf("FAIL\n\n"); flint_printf("iter %wd\n", iter); flint_printf("prec = %wd\n", prec); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); flint_printf("w = "); fmpr_print(w); flint_printf("\n\n"); flint_printf("ret1 = %wd, ret2 = %wd\n", ret1, ret2); abort(); } fmpr_clear(x); fmpr_clear(y); fmpr_clear(z); fmpr_clear(w); } /* compare rounding with mpfr */ for (iter = 0; iter < 1000000 * arb_test_multiplier(); iter++) { slong bits, res; int mpfr_res; fmpr_t x, y, z, w; mpfr_t X, Y, Z; bits = 2 + n_randint(state, 500); fmpr_init(x); fmpr_init(y); fmpr_init(z); fmpr_init(w); mpfr_init2(X, bits + 500); mpfr_init2(Y, bits + 500); mpfr_init2(Z, bits); fmpr_randtest_special(x, state, bits + n_randint(state, 500), 10); fmpr_randtest_special(y, state, bits + n_randint(state, 500), 10); fmpr_randtest_special(z, state, bits, 10); fmpr_get_mpfr(X, x, MPFR_RNDN); fmpr_get_mpfr(Y, y, MPFR_RNDN); switch (n_randint(state, 4)) { case 0: mpfr_res = mpfr_add(Z, X, Y, MPFR_RNDZ); res = fmpr_add(z, x, y, bits, FMPR_RND_DOWN); break; case 1: mpfr_res = mpfr_add(Z, X, Y, MPFR_RNDA); res = fmpr_add(z, x, y, bits, FMPR_RND_UP); break; case 2: mpfr_res = mpfr_add(Z, X, Y, MPFR_RNDD); res = fmpr_add(z, x, y, bits, FMPR_RND_FLOOR); break; default: mpfr_res = mpfr_add(Z, X, Y, MPFR_RNDU); res = fmpr_add(z, x, y, bits, FMPR_RND_CEIL); break; } fmpr_set_mpfr(w, Z); if (!fmpr_equal(z, w) || (res == FMPR_RESULT_EXACT) != (mpfr_res == 0) || !fmpr_check_ulp(z, res, bits)) { flint_printf("FAIL\n\n"); flint_printf("iter %wd\n", iter); flint_printf("bits = %wd\n", bits); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); flint_printf("w = "); fmpr_print(w); flint_printf("\n\n"); flint_printf("returned: %wd, %d\n", res, mpfr_res); abort(); } /* check error bound */ if (!fmpr_is_nan(z) && !fmpr_is_inf(z)) { fmpr_t z_exact, error_bound, true_error; fmpr_init(z_exact); fmpr_init(error_bound); fmpr_init(true_error); fmpr_set_error_result(error_bound, z, res); fmpr_add(z_exact, x, y, FMPR_PREC_EXACT, FMPR_RND_DOWN); fmpr_sub(true_error, z, z_exact, FMPR_PREC_EXACT, FMPR_RND_DOWN); fmpr_abs(true_error, true_error); if (fmpr_is_zero(error_bound) != fmpr_is_zero(true_error) || fmpr_cmp(true_error, error_bound) > 0) { flint_printf("FAIL: error bound\n\n"); flint_printf("bits = %wd\n", bits); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("y = "); fmpr_print(y); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); flint_printf("z_exact = "); fmpr_print(z_exact); flint_printf("\n\n"); flint_printf("true_error = "); fmpr_print(true_error); flint_printf("\n\n"); flint_printf("error_bound = "); fmpr_print(error_bound); flint_printf("\n\n"); abort(); } fmpr_clear(z_exact); fmpr_clear(error_bound); fmpr_clear(true_error); } fmpr_clear(x); fmpr_clear(y); fmpr_clear(z); fmpr_clear(w); mpfr_clear(X); mpfr_clear(Y); mpfr_clear(Z); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("add_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { acb_poly_t a, b, c, d; slong len, prec; acb_poly_init(a); acb_poly_init(b); acb_poly_init(c); acb_poly_init(d); acb_poly_randtest(a, state, 1 + n_randint(state, 10), 100, 10); acb_poly_randtest(b, state, 1 + n_randint(state, 10), 100, 10); acb_poly_randtest(c, state, 1 + n_randint(state, 10), 100, 10); acb_poly_randtest(d, state, 1 + n_randint(state, 10), 100, 10); prec = 2 + n_randint(state, 100); len = n_randint(state, 10); acb_poly_add_series(c, a, b, len, prec); acb_poly_add(d, a, b, prec); acb_poly_truncate(d, len); if (!acb_poly_equal(c, d)) { flint_printf("FAIL\n\n"); flint_printf("a = "); acb_poly_printd(a, 15); flint_printf("\n\n"); flint_printf("b = "); acb_poly_printd(b, 15); flint_printf("\n\n"); flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n"); flint_printf("c = "); acb_poly_printd(c, 15); flint_printf("\n\n"); flint_abort(); } acb_poly_set(d, a); acb_poly_add_series(d, d, b, len, prec); if (!acb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 1)\n\n"); flint_abort(); } acb_poly_set(d, b); acb_poly_add_series(d, a, d, len, prec); if (!acb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 2)\n\n"); flint_abort(); } acb_poly_clear(a); acb_poly_clear(b); acb_poly_clear(c); acb_poly_clear(d); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("isolate_roots...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 40 * arb_test_multiplier(); iter++) { slong m, r, a, b, maxdepth, maxeval, maxfound, prec, i, j, num; arf_interval_ptr blocks; int * info; arf_interval_t interval; arb_t t; fmpz_t nn; prec = 2 + n_randint(state, 50); m = n_randint(state, 80); r = 1 + n_randint(state, 80); a = m - r; b = m + r; maxdepth = 1 + n_randint(state, 60); maxeval = 1 + n_randint(state, 5000); maxfound = 1 + n_randint(state, 100); arf_interval_init(interval); arb_init(t); fmpz_init(nn); arf_set_si(&interval->a, a); arf_set_si(&interval->b, b); num = arb_calc_isolate_roots(&blocks, &info, sin_pi2_x, NULL, interval, maxdepth, maxeval, maxfound, prec); /* check that all roots are accounted for */ for (i = a; i <= b; i++) { if (i % 2 == 0) { int found = 0; for (j = 0; j < num; j++) { arf_interval_get_arb(t, blocks + j, ARF_PREC_EXACT); if (arb_contains_si(t, i)) { found = 1; break; } } if (!found) { flint_printf("FAIL: missing root %wd\n", i); flint_printf("a = %wd, b = %wd, maxdepth = %wd, maxeval = %wd, maxfound = %wd, prec = %wd\n", a, b, maxdepth, maxeval, maxfound, prec); for (j = 0; j < num; j++) { arf_interval_printd(blocks + j, 15); flint_printf(" %d \n", info[i]); } flint_abort(); } } } /* check that all reported single roots are good */ for (i = 0; i < num; i++) { if (info[i] == 1) { /* b contains unique 2n -> b/2 contains unique n */ arf_interval_get_arb(t, blocks + i, ARF_PREC_EXACT); arb_mul_2exp_si(t, t, -1); if (!arb_get_unique_fmpz(nn, t)) { flint_printf("FAIL: bad root %wd\n", i); flint_printf("a = %wd, b = %wd, maxdepth = %wd, maxeval = %wd, maxfound = %wd, prec = %wd\n", a, b, maxdepth, maxeval, maxfound, prec); for (j = 0; j < num; j++) { arf_interval_printd(blocks + j, 15); flint_printf(" %d \n", info[i]); } flint_abort(); } } } _arf_interval_vec_clear(blocks, num); flint_free(info); arf_interval_clear(interval); arb_clear(t); fmpz_clear(nn); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("rsqrt...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { slong bits, res; fmpr_t x, z, w; mpfr_t X, Z; bits = 2 + n_randint(state, 200); fmpr_init(x); fmpr_init(z); fmpr_init(w); mpfr_init2(X, 2 * (bits + 100)); mpfr_init2(Z, bits); fmpr_randtest_special(x, state, bits + n_randint(state, 100), 10); fmpr_randtest_special(z, state, bits + n_randint(state, 100), 10); fmpr_get_mpfr(X, x, MPFR_RNDN); switch (n_randint(state, 4)) { case 0: mpfr_rec_sqrt(Z, X, MPFR_RNDZ); res = fmpr_rsqrt(z, x, bits, FMPR_RND_DOWN); break; case 1: mpfr_rec_sqrt(Z, X, MPFR_RNDA); res = fmpr_rsqrt(z, x, bits, FMPR_RND_UP); break; case 2: mpfr_rec_sqrt(Z, X, MPFR_RNDD); res = fmpr_rsqrt(z, x, bits, FMPR_RND_FLOOR); break; default: mpfr_rec_sqrt(Z, X, MPFR_RNDU); res = fmpr_rsqrt(z, x, bits, FMPR_RND_CEIL); break; } fmpr_set_mpfr(w, Z); if (!fmpr_equal(z, w) || !fmpr_check_ulp(z, res, bits)) { flint_printf("FAIL\n\n"); flint_printf("bits = %wd\n", bits); flint_printf("x = "); fmpr_print(x); flint_printf("\n\n"); flint_printf("z = "); fmpr_print(z); flint_printf("\n\n"); flint_printf("w = "); fmpr_print(w); flint_printf("\n\n"); abort(); } fmpr_clear(x); fmpr_clear(z); fmpr_clear(w); mpfr_clear(X); mpfr_clear(Z); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("mul_naive...."); fflush(stdout); flint_randinit(state); /* test aliasing of c and a */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { acb_t a, b, c; slong prec; acb_init(a); acb_init(b); acb_init(c); acb_randtest(a, state, 1 + n_randint(state, 200), 10); acb_randtest(b, state, 1 + n_randint(state, 200), 10); acb_randtest(c, state, 1 + n_randint(state, 200), 10); prec = 2 + n_randint(state, 200); acb_mul_naive(c, a, b, prec); acb_mul_naive(a, a, b, prec); if (!acb_equal(a, c)) { flint_printf("FAIL: aliasing c, a\n\n"); flint_printf("a = "); acb_print(a); flint_printf("\n\n"); flint_printf("b = "); acb_print(b); flint_printf("\n\n"); flint_printf("c = "); acb_print(c); flint_printf("\n\n"); abort(); } acb_clear(a); acb_clear(b); acb_clear(c); } /* test aliasing of c and b */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { acb_t a, b, c; slong prec; acb_init(a); acb_init(b); acb_init(c); acb_randtest(a, state, 1 + n_randint(state, 200), 10); acb_randtest(b, state, 1 + n_randint(state, 200), 10); acb_randtest(c, state, 1 + n_randint(state, 200), 10); prec = 2 + n_randint(state, 200); acb_mul_naive(c, a, b, prec); acb_mul_naive(b, a, b, prec); if (!acb_equal(b, c)) { flint_printf("FAIL: aliasing b, a\n\n"); flint_printf("a = "); acb_print(a); flint_printf("\n\n"); flint_printf("b = "); acb_print(b); flint_printf("\n\n"); flint_printf("c = "); acb_print(c); flint_printf("\n\n"); abort(); } acb_clear(a); acb_clear(b); acb_clear(c); } /* test aliasing a, a */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { acb_t a, b, c, d; slong prec; acb_init(a); acb_init(b); acb_init(c); acb_init(d); acb_randtest(a, state, 1 + n_randint(state, 200), 10); acb_randtest(b, state, 1 + n_randint(state, 200), 10); acb_randtest(c, state, 1 + n_randint(state, 200), 10); prec = 2 + n_randint(state, 200); acb_set(b, a); acb_mul_naive(c, a, a, prec); acb_mul_naive(d, a, b, prec); if (!acb_overlaps(c, d)) { flint_printf("FAIL: aliasing a, a\n\n"); flint_printf("a = "); acb_print(a); flint_printf("\n\n"); flint_printf("b = "); acb_print(b); flint_printf("\n\n"); flint_printf("c = "); acb_print(c); flint_printf("\n\n"); flint_printf("d = "); acb_print(d); flint_printf("\n\n"); abort(); } acb_clear(a); acb_clear(b); acb_clear(c); acb_clear(d); } /* test aliasing a, a, a */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { acb_t a, b, c; slong prec; acb_init(a); acb_init(b); acb_init(c); acb_randtest(a, state, 1 + n_randint(state, 200), 10); acb_randtest(b, state, 1 + n_randint(state, 200), 10); acb_randtest(c, state, 1 + n_randint(state, 200), 10); prec = 2 + n_randint(state, 200); acb_set(b, a); acb_mul_naive(c, a, b, prec); acb_mul_naive(a, a, a, prec); if (!acb_overlaps(a, c)) { flint_printf("FAIL: aliasing a, a, a\n\n"); flint_printf("a = "); acb_print(a); flint_printf("\n\n"); flint_printf("b = "); acb_print(b); flint_printf("\n\n"); flint_printf("c = "); acb_print(c); flint_printf("\n\n"); abort(); } acb_clear(a); acb_clear(b); acb_clear(c); } /* test a*(b+c) = a*b + a*c */ for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { acb_t a, b, c, d, e, f; acb_init(a); acb_init(b); acb_init(c); acb_init(d); acb_init(e); acb_init(f); acb_randtest(a, state, 1 + n_randint(state, 200), 10); acb_randtest(b, state, 1 + n_randint(state, 200), 10); acb_randtest(c, state, 1 + n_randint(state, 200), 10); acb_add(d, b, c, 2 + n_randint(state, 200)); acb_mul_naive(e, a, d, 2 + n_randint(state, 200)); acb_mul_naive(d, a, b, 2 + n_randint(state, 200)); acb_mul_naive(f, a, c, 2 + n_randint(state, 200)); acb_add(f, d, f, 2 + n_randint(state, 200)); if (!acb_overlaps(e, f)) { flint_printf("FAIL: a*(b+c) = a*b + a*c\n\n"); flint_printf("a = "); acb_print(a); flint_printf("\n\n"); flint_printf("b = "); acb_print(b); flint_printf("\n\n"); flint_printf("c = "); acb_print(c); flint_printf("\n\n"); flint_printf("e = "); acb_print(e); flint_printf("\n\n"); flint_printf("f = "); acb_print(f); flint_printf("\n\n"); abort(); } acb_clear(a); acb_clear(b); acb_clear(c); acb_clear(d); acb_clear(e); acb_clear(f); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("mul...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { slong m, n, k, qbits1, qbits2, rbits1, rbits2, rbits3; fmpq_mat_t A, B, C; acb_mat_t a, b, c, d; qbits1 = 2 + n_randint(state, 200); qbits2 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); rbits3 = 2 + n_randint(state, 200); m = n_randint(state, 10); n = n_randint(state, 10); k = n_randint(state, 10); fmpq_mat_init(A, m, n); fmpq_mat_init(B, n, k); fmpq_mat_init(C, m, k); acb_mat_init(a, m, n); acb_mat_init(b, n, k); acb_mat_init(c, m, k); acb_mat_init(d, m, k); fmpq_mat_randtest(A, state, qbits1); fmpq_mat_randtest(B, state, qbits2); fmpq_mat_mul(C, A, B); acb_mat_set_fmpq_mat(a, A, rbits1); acb_mat_set_fmpq_mat(b, B, rbits2); acb_mat_mul(c, a, b, rbits3); if (!acb_mat_contains_fmpq_mat(c, C)) { flint_printf("FAIL\n\n"); flint_printf("m = %wd, n = %wd, k = %wd, bits3 = %wd\n", m, n, k, rbits3); flint_printf("A = "); fmpq_mat_print(A); flint_printf("\n\n"); flint_printf("B = "); fmpq_mat_print(B); flint_printf("\n\n"); flint_printf("C = "); fmpq_mat_print(C); flint_printf("\n\n"); flint_printf("a = "); acb_mat_printd(a, 15); flint_printf("\n\n"); flint_printf("b = "); acb_mat_printd(b, 15); flint_printf("\n\n"); flint_printf("c = "); acb_mat_printd(c, 15); flint_printf("\n\n"); abort(); } /* test aliasing with a */ if (acb_mat_nrows(a) == acb_mat_nrows(c) && acb_mat_ncols(a) == acb_mat_ncols(c)) { acb_mat_set(d, a); acb_mat_mul(d, d, b, rbits3); if (!acb_mat_equal(d, c)) { flint_printf("FAIL (aliasing 1)\n\n"); abort(); } } /* test aliasing with b */ if (acb_mat_nrows(b) == acb_mat_nrows(c) && acb_mat_ncols(b) == acb_mat_ncols(c)) { acb_mat_set(d, b); acb_mat_mul(d, a, d, rbits3); if (!acb_mat_equal(d, c)) { flint_printf("FAIL (aliasing 2)\n\n"); abort(); } } fmpq_mat_clear(A); fmpq_mat_clear(B); fmpq_mat_clear(C); acb_mat_clear(a); acb_mat_clear(b); acb_mat_clear(c); acb_mat_clear(d); } /* check algebraic properties like associativity and distributivity */ for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { slong m, n, k, l; slong rbits; acb_mat_t a, b, c, d, ab, ac, bd, cd, s; rbits = 2 + n_randint(state, 200); m = n_randint(state, 10); n = n_randint(state, 10); k = n_randint(state, 10); l = n_randint(state, 10); _acb_mat_init_randtest(a, m, n, state); _acb_mat_init_randtest(b, n, k, state); _acb_mat_init_randtest(c, n, k, state); _acb_mat_init_randtest(d, k, l, state); acb_mat_init(ab, m, k); acb_mat_init(ac, m, k); acb_mat_init(bd, n, l); acb_mat_init(cd, n, l); acb_mat_init(s, n, k); acb_mat_mul(ab, a, b, rbits); acb_mat_mul(ac, a, c, rbits); acb_mat_mul(bd, b, d, rbits); acb_mat_mul(cd, c, d, rbits); acb_mat_add(s, b, c, rbits); /* check associativity of multiplication */ /* (A*B)*D = A*(B*D) */ { acb_mat_t lhs, rhs; acb_mat_init(lhs, m, l); acb_mat_init(rhs, m, l); acb_mat_mul(lhs, ab, d, rbits); acb_mat_mul(rhs, a, bd, rbits); if (!acb_mat_overlaps(lhs, rhs)) { flint_printf("FAIL\n\n"); flint_printf("m, n, k, l = %wd, %wd, %wd, %wd\n", m, n, k, l); flint_printf("rbits = %wd\n", rbits); _acb_mat_nprintd("a", a); _acb_mat_nprintd("b", b); _acb_mat_nprintd("d", d); _acb_mat_nprintd("(a*b)*d", lhs); _acb_mat_nprintd("a*(b*d)", rhs); abort(); } acb_mat_clear(lhs); acb_mat_clear(rhs); } /* check left distributivity of multiplication over addition */ /* A*(B + C) = A*B + A*C */ { acb_mat_t lhs, rhs; acb_mat_init(lhs, m, k); acb_mat_init(rhs, m, k); acb_mat_mul(lhs, a, s, rbits); acb_mat_add(rhs, ab, ac, rbits); if (!acb_mat_overlaps(lhs, rhs)) { flint_printf("FAIL\n\n"); flint_printf("m, n, k, l = %wd, %wd, %wd, %wd\n", m, n, k, l); flint_printf("rbits = %wd\n", rbits); _acb_mat_nprintd("a", a); _acb_mat_nprintd("b", b); _acb_mat_nprintd("c", c); _acb_mat_nprintd("a*(b + c)", lhs); _acb_mat_nprintd("a*b + b*c", rhs); abort(); } acb_mat_clear(lhs); acb_mat_clear(rhs); } /* check right distributivity of multiplication over addition */ /* (B + C)*D = B*D + C*D */ { acb_mat_t lhs, rhs; acb_mat_init(lhs, n, l); acb_mat_init(rhs, n, l); acb_mat_mul(lhs, s, d, rbits); acb_mat_add(rhs, bd, cd, rbits); if (!acb_mat_overlaps(lhs, rhs)) { flint_printf("FAIL\n\n"); flint_printf("m, n, k, l = %wd, %wd, %wd, %wd\n", m, n, k, l); flint_printf("rbits = %wd\n", rbits); _acb_mat_nprintd("b", b); _acb_mat_nprintd("c", c); _acb_mat_nprintd("d", d); _acb_mat_nprintd("(b + c)*d", lhs); _acb_mat_nprintd("b*d + c*d", rhs); abort(); } acb_mat_clear(lhs); acb_mat_clear(rhs); } /* check left multiplicative identity I*D = D */ { acb_mat_t one, lhs; acb_mat_init(one, k, k); acb_mat_init(lhs, k, l); acb_mat_one(one); acb_mat_mul(lhs, one, d, rbits); if (!acb_mat_contains(lhs, d)) { flint_printf("FAIL\n\n"); flint_printf("k = %wd, l = %wd\n", k, l); flint_printf("rbits = %wd\n", rbits); _acb_mat_nprintd("identity * d", lhs); _acb_mat_nprintd("d", d); abort(); } acb_mat_clear(one); acb_mat_clear(lhs); } /* check right multiplicative identity A*I = A */ { acb_mat_t one, lhs; acb_mat_init(one, n, n); acb_mat_init(lhs, m, n); acb_mat_one(one); acb_mat_mul(lhs, a, one, rbits); if (!acb_mat_contains(lhs, a)) { flint_printf("FAIL\n\n"); flint_printf("m = %wd, n = %wd\n", m, n); flint_printf("rbits = %wd\n", rbits); _acb_mat_nprintd("a * identity", lhs); _acb_mat_nprintd("a", a); abort(); } acb_mat_clear(one); acb_mat_clear(lhs); } acb_mat_clear(a); acb_mat_clear(b); acb_mat_clear(c); acb_mat_clear(d); acb_mat_clear(ab); acb_mat_clear(ac); acb_mat_clear(bd); acb_mat_clear(cd); acb_mat_clear(s); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("quadratic_roots_fmpz...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { acb_t r1, r2, x, y; fmpz_t a, b, c; slong prec; fmpz_init(a); fmpz_init(b); fmpz_init(c); acb_init(r1); acb_init(r2); acb_init(x); acb_init(y); prec = 2 + n_randint(state, 1000); fmpz_randtest_not_zero(a, state, 1 + n_randint(state, 1000)); fmpz_randtest(b, state, 1 + n_randint(state, 1000)); fmpz_randtest(c, state, 1 + n_randint(state, 1000)); acb_randtest(r1, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); acb_randtest(r2, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100)); acb_quadratic_roots_fmpz(r1, r2, a, b, c, prec); acb_mul(x, r1, r1, prec); acb_mul_fmpz(x, x, a, prec); acb_addmul_fmpz(x, r1, b, prec); acb_add_fmpz(x, x, c, prec); acb_mul(y, r2, r2, prec); acb_mul_fmpz(y, y, a, prec); acb_addmul_fmpz(y, r2, b, prec); acb_add_fmpz(y, y, c, prec); if (!acb_contains_zero(x) || !acb_contains_zero(y) || acb_rel_accuracy_bits(r1) < prec - 4 || acb_rel_accuracy_bits(r2) < prec - 4) { flint_printf("FAIL: containment / accuracy\n\n"); flint_printf("prec = %wd\n", prec); flint_printf("a = "); fmpz_print(a); flint_printf("\n\n"); flint_printf("b = "); fmpz_print(b); flint_printf("\n\n"); flint_printf("c = "); fmpz_print(c); flint_printf("\n\n"); flint_printf("r1 = "); acb_printd(r1, 30); flint_printf("\n\n"); flint_printf("r2 = "); acb_printd(r2, 30); flint_printf("\n\n"); abort(); } fmpz_clear(a); fmpz_clear(b); fmpz_clear(c); acb_clear(r1); acb_clear(r2); acb_clear(x); acb_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("chi...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { acb_t zn1, zn2, zn1n2, zn1zn2; dirichlet_group_t G; dirichlet_char_t chi; ulong q, m, n1, n2, iter2; int res; q = 1 + n_randint(state, 1000); dirichlet_group_init(G, q); dirichlet_char_init(chi, G); acb_init(zn1); acb_init(zn2); acb_init(zn1n2); acb_init(zn1zn2); /* check chi(n1) chi(n2) = chi(n1 n2) */ for (iter2 = 0; iter2 < 10; iter2++) { do { m = 1 + n_randint(state, q); } while (n_gcd(q, m) != 1); dirichlet_char_log(chi, G, m); n1 = n_randint(state, 1000); n2 = n_randint(state, 1000); acb_dirichlet_chi(zn1, G, chi, n1, 53); acb_dirichlet_pairing(zn2, G, m, n1, 53); if (!acb_overlaps(zn1, zn2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("m = %wu\n\n", m); flint_printf("n = %wu\n\n", n1); flint_printf("char = "); acb_printd(zn1, 15); flint_printf("\n\n"); flint_printf("pairing = "); acb_printd(zn2, 15); flint_printf("\n\n"); dirichlet_char_print(G, chi); dirichlet_char_log(chi, G, m); flint_printf("log(m) = "); dirichlet_char_print(G, chi); dirichlet_char_log(chi, G, n1); flint_printf("log(n1) = "); dirichlet_char_print(G, chi); flint_abort(); } acb_dirichlet_pairing(zn2, G, m, n2, 53); acb_dirichlet_pairing(zn1n2, G, m, n1 * n2, 53); acb_mul(zn1zn2, zn1, zn2, 53); if (!acb_overlaps(zn1n2, zn1zn2)) { flint_printf("FAIL: overlap\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("m = %wu\n\n", m); flint_printf("n1 = %wu\n\n", n1); flint_printf("n2 = %wu\n\n", n2); flint_printf("zn1 = "); acb_printd(zn1, 15); flint_printf("\n\n"); flint_printf("zn2 = "); acb_printd(zn2, 15); flint_printf("\n\n"); flint_printf("zn1n2 = "); acb_printd(zn1n2, 15); flint_printf("\n\n"); flint_printf("zn1zn2 = "); acb_printd(zn1zn2, 15); flint_printf("\n\n"); flint_abort(); } } if (iter % 10 == 0) { /* check orthogonality */ acb_zero(zn1); n1 = n_randint(state, 1000); for (m = 1; m <= q; m++) { if (n_gcd(q, m) == 1) { acb_dirichlet_pairing(zn2, G, m, n1, 53); acb_add(zn1, zn1, zn2, 53); } } if (n1 % q == 1 % q) res = arb_contains_si(acb_realref(zn1), n_euler_phi(q)) && arb_contains_zero(acb_imagref(zn1)); else res = acb_contains_zero(zn1); if (!res) { flint_printf("FAIL: orthogonality\n\n"); flint_printf("q = %wu\n\n", q); flint_printf("phi = %wu\n\n", n_euler_phi(q)); flint_printf("n1 = %wu\n\n", n1); flint_printf("zn1 = "); acb_printd(zn1, 15); flint_printf("\n\n"); flint_abort(); } } dirichlet_group_clear(G); dirichlet_char_clear(chi); acb_clear(zn1); acb_clear(zn2); acb_clear(zn1n2); acb_clear(zn1zn2); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("sinh_cosh...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arb_t a, b, c; fmpq_t q; mpfr_t t, u; slong prec = 2 + n_randint(state, 200); arb_init(a); arb_init(b); arb_init(c); fmpq_init(q); mpfr_init2(t, prec + 100); mpfr_init2(u, prec + 100); arb_randtest(a, state, 1 + n_randint(state, 200), 3); arb_randtest(b, state, 1 + n_randint(state, 200), 3); arb_randtest(c, state, 1 + n_randint(state, 200), 3); arb_get_rand_fmpq(q, state, a, 1 + n_randint(state, 200)); fmpq_get_mpfr(t, q, MPFR_RNDN); mpfr_sinh_cosh(t, u, t, MPFR_RNDN); arb_sinh_cosh(b, c, a, prec); if (!arb_contains_mpfr(b, t)) { flint_printf("FAIL: containment (sin)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); abort(); } if (!arb_contains_mpfr(c, u)) { flint_printf("FAIL: containment (cos)\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("c = "); arb_print(c); flint_printf("\n\n"); abort(); } arb_clear(a); arb_clear(b); arb_clear(c); fmpq_clear(q); mpfr_clear(t); mpfr_clear(u); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("overlaps...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arb_t a, b; fmpq_t am, ar, bm, br, t, u; int c1, c2; arb_init(a); arb_init(b); fmpq_init(am); fmpq_init(ar); fmpq_init(bm); fmpq_init(br); fmpq_init(t); fmpq_init(u); arb_randtest(a, state, 1 + n_randint(state, 500), 14); arb_randtest(b, state, 1 + n_randint(state, 500), 14); arf_get_fmpq(am, arb_midref(a)); mag_get_fmpq(ar, arb_radref(a)); arf_get_fmpq(bm, arb_midref(b)); mag_get_fmpq(br, arb_radref(b)); fmpq_sub(t, am, bm); fmpz_abs(fmpq_numref(t), fmpq_numref(t)); fmpq_add(u, ar, br); c1 = arb_overlaps(a, b); c2 = (fmpq_cmp(t, u) <= 0); if (c1 != c2) { flint_printf("FAIL:\n\n"); flint_printf("a = "); arb_print(a); flint_printf("\n\n"); flint_printf("b = "); arb_print(b); flint_printf("\n\n"); flint_printf("am = "); fmpq_print(am); flint_printf("\n\n"); flint_printf("ar = "); fmpq_print(ar); flint_printf("\n\n"); flint_printf("bm = "); fmpq_print(bm); flint_printf("\n\n"); flint_printf("br = "); fmpq_print(br); flint_printf("\n\n"); flint_printf("t = "); fmpq_print(t); flint_printf("\n\n"); flint_printf("u = "); fmpq_print(u); flint_printf("\n\n"); flint_printf("c1 = %d, c2 = %d\n\n", c1, c2); flint_abort(); } arb_clear(a); arb_clear(b); fmpq_clear(am); fmpq_clear(ar); fmpq_clear(bm); fmpq_clear(br); fmpq_clear(t); fmpq_clear(u); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("fresnel...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { acb_t z, z2, s, c, u, v; slong prec1, prec2; int normalized; prec1 = 2 + n_randint(state, 500); prec2 = 2 + n_randint(state, 500); acb_init(z); acb_init(z2); acb_init(s); acb_init(c); acb_init(u); acb_init(v); acb_randtest_special(z, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100)); acb_randtest_special(s, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100)); acb_randtest_special(c, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100)); normalized = n_randint(state, 2); /* test S(z) + i C(z) = sqrt(pi/2) (1+i)/2 erf((1+i)/sqrt(2) z) */ /* u = rhs */ acb_onei(u); acb_sqrt(u, u, prec1); acb_mul(u, u, z, prec1); acb_hypgeom_erf(u, u, prec1); acb_mul_onei(v, u); acb_add(u, u, v, prec1); acb_mul_2exp_si(u, u, -1); acb_const_pi(v, prec1); acb_mul_2exp_si(v, v, -1); acb_sqrt(v, v, prec1); acb_mul(u, u, v, prec1); if (normalized) { acb_const_pi(v, prec2); acb_mul_2exp_si(v, v, -1); acb_sqrt(v, v, prec2); acb_div(z2, z, v, prec2); } else { acb_set(z2, z); } switch (n_randint(state, 4)) { case 0: acb_hypgeom_fresnel(s, c, z2, normalized, prec2); break; case 1: acb_hypgeom_fresnel(s, NULL, z2, normalized, prec2); acb_hypgeom_fresnel(NULL, c, z2, normalized, prec2); break; case 2: acb_set(s, z2); acb_hypgeom_fresnel(s, c, s, normalized, prec2); break; case 3: acb_set(c, z2); acb_hypgeom_fresnel(s, c, c, normalized, prec2); break; default: acb_hypgeom_fresnel(s, c, z2, normalized, prec2); } if (normalized) { acb_mul(s, s, v, prec2); acb_mul(c, c, v, prec2); } acb_mul_onei(v, c); acb_add(v, v, s, prec2); if (!acb_overlaps(u, v)) { flint_printf("FAIL: overlap\n\n"); flint_printf("z = "); acb_printd(z, 30); flint_printf("\n\n"); flint_printf("s = "); acb_printd(s, 30); flint_printf("\n\n"); flint_printf("c = "); acb_printd(c, 30); flint_printf("\n\n"); flint_printf("u = "); acb_printd(u, 30); flint_printf("\n\n"); flint_printf("v = "); acb_printd(v, 30); flint_printf("\n\n"); abort(); } acb_clear(z); acb_clear(z2); acb_clear(s); acb_clear(c); acb_clear(u); acb_clear(v); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("gamma...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++) { acb_t a, b, c; slong prec1, prec2; prec1 = 2 + n_randint(state, 1000); prec2 = prec1 + 30; acb_init(a); acb_init(b); acb_init(c); arb_randtest_precise(acb_realref(a), state, 1 + n_randint(state, 1000), 3); arb_randtest_precise(acb_imagref(a), state, 1 + n_randint(state, 1000), 3); acb_gamma(b, a, prec1); acb_gamma(c, a, prec2); if (!acb_overlaps(b, c)) { flint_printf("FAIL: overlap\n\n"); flint_printf("a = "); acb_print(a); flint_printf("\n\n"); flint_printf("b = "); acb_print(b); flint_printf("\n\n"); flint_printf("c = "); acb_print(c); flint_printf("\n\n"); abort(); } /* check gamma(z+1) = z gamma(z) */ acb_mul(b, b, a, prec1); acb_add_ui(c, a, 1, prec1); acb_gamma(c, c, prec1); if (!acb_overlaps(b, c)) { flint_printf("FAIL: functional equation\n\n"); flint_printf("a = "); acb_print(a); flint_printf("\n\n"); flint_printf("b = "); acb_print(b); flint_printf("\n\n"); flint_printf("c = "); acb_print(c); flint_printf("\n\n"); abort(); } acb_clear(a); acb_clear(b); acb_clear(c); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("frobenius_norm...."); fflush(stdout); flint_randinit(state); /* compare to the exact rational norm */ for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { fmpq_mat_t Q; fmpq_t q; arb_mat_t A; slong n, qbits, prec; n = n_randint(state, 8); qbits = 1 + n_randint(state, 100); prec = 2 + n_randint(state, 200); fmpq_mat_init(Q, n, n); fmpq_init(q); arb_mat_init(A, n, n); fmpq_mat_randtest(Q, state, qbits); _fmpq_mat_sum_of_squares(q, Q); arb_mat_set_fmpq_mat(A, Q, prec); /* check that the arb interval contains the exact value */ { arb_t a; arb_init(a); arb_mat_frobenius_norm(a, A, prec); arb_mul(a, a, a, prec); if (!arb_contains_fmpq(a, q)) { flint_printf("FAIL (containment, iter = %wd)\n", iter); flint_printf("n = %wd, prec = %wd\n", n, prec); flint_printf("\n"); flint_printf("Q = \n"); fmpq_mat_print(Q); flint_printf("\n\n"); flint_printf("frobenius_norm(Q)^2 = \n"); fmpq_print(q); flint_printf("\n\n"); flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n"); flint_printf("frobenius_norm(A)^2 = \n"); arb_printd(a, 15); flint_printf("\n\n"); flint_printf("frobenius_norm(A)^2 = \n"); arb_print(a); flint_printf("\n\n"); abort(); } arb_clear(a); } /* check that the upper bound is not less than the exact value */ { mag_t b; fmpq_t y; mag_init(b); fmpq_init(y); arb_mat_bound_frobenius_norm(b, A); mag_mul(b, b, b); mag_get_fmpq(y, b); if (fmpq_cmp(q, y) > 0) { flint_printf("FAIL (bound, iter = %wd)\n", iter); flint_printf("n = %wd, prec = %wd\n", n, prec); flint_printf("\n"); flint_printf("Q = \n"); fmpq_mat_print(Q); flint_printf("\n\n"); flint_printf("frobenius_norm(Q)^2 = \n"); fmpq_print(q); flint_printf("\n\n"); flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n"); flint_printf("bound_frobenius_norm(A)^2 = \n"); mag_printd(b, 15); flint_printf("\n\n"); flint_printf("bound_frobenius_norm(A)^2 = \n"); mag_print(b); flint_printf("\n\n"); abort(); } mag_clear(b); fmpq_clear(y); } fmpq_mat_clear(Q); fmpq_clear(q); arb_mat_clear(A); } /* check trace(A^T A) = frobenius_norm(A)^2 */ for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { slong m, n, prec; arb_mat_t A, AT, ATA; arb_t t; prec = 2 + n_randint(state, 200); m = n_randint(state, 10); n = n_randint(state, 10); arb_mat_init(A, m, n); arb_mat_init(AT, n, m); arb_mat_init(ATA, n, n); arb_init(t); arb_mat_randtest(A, state, 2 + n_randint(state, 100), 10); arb_mat_transpose(AT, A); arb_mat_mul(ATA, AT, A, prec); arb_mat_trace(t, ATA, prec); arb_sqrt(t, t, prec); /* check the norm bound */ { mag_t low, frobenius; mag_init(low); arb_get_mag_lower(low, t); mag_init(frobenius); arb_mat_bound_frobenius_norm(frobenius, A); if (mag_cmp(low, frobenius) > 0) { flint_printf("FAIL (bound)\n", iter); flint_printf("m = %wd, n = %wd, prec = %wd\n", m, n, prec); flint_printf("\n"); flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n"); flint_printf("lower(sqrt(trace(A^T A))) = \n"); mag_printd(low, 15); flint_printf("\n\n"); flint_printf("bound_frobenius_norm(A) = \n"); mag_printd(frobenius, 15); flint_printf("\n\n"); abort(); } mag_clear(low); mag_clear(frobenius); } /* check the norm interval */ { arb_t frobenius; arb_init(frobenius); arb_mat_frobenius_norm(frobenius, A, prec); if (!arb_overlaps(t, frobenius)) { flint_printf("FAIL (overlap)\n", iter); flint_printf("m = %wd, n = %wd, prec = %wd\n", m, n, prec); flint_printf("\n"); flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n"); flint_printf("sqrt(trace(A^T A)) = \n"); arb_printd(t, 15); flint_printf("\n\n"); flint_printf("frobenius_norm(A) = \n"); arb_printd(frobenius, 15); flint_printf("\n\n"); abort(); } arb_clear(frobenius); } arb_mat_clear(A); arb_mat_clear(AT); arb_mat_clear(ATA); arb_clear(t); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("approx_dot...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++) { arb_ptr x, y; arb_t s1, s2, z; slong i, len, prec, xbits, ybits, ebits; int initial, subtract, revx, revy; if (n_randint(state, 100) == 0) len = n_randint(state, 100); else if (n_randint(state, 10) == 0) len = n_randint(state, 10); else len = n_randint(state, 3); if (n_randint(state, 10) != 0 || len > 10) { prec = 2 + n_randint(state, 500); xbits = 2 + n_randint(state, 500); ybits = 2 + n_randint(state, 500); } else { prec = 2 + n_randint(state, 4000); xbits = 2 + n_randint(state, 4000); ybits = 2 + n_randint(state, 4000); } if (n_randint(state, 100) == 0) ebits = 2 + n_randint(state, 100); else ebits = 2 + n_randint(state, 10); initial = n_randint(state, 2); subtract = n_randint(state, 2); revx = n_randint(state, 2); revy = n_randint(state, 2); x = _arb_vec_init(len); y = _arb_vec_init(len); arb_init(s1); arb_init(s2); arb_init(z); switch (n_randint(state, 3)) { case 0: for (i = 0; i < len; i++) { arb_randtest(x + i, state, xbits, ebits); arb_randtest(y + i, state, ybits, ebits); } break; /* Test with cancellation */ case 1: for (i = 0; i < len; i++) { if (i <= len / 2) { arb_randtest(x + i, state, xbits, ebits); arb_randtest(y + i, state, ybits, ebits); } else { arb_neg(x + i, x + len - i - 1); arb_set(y + i, y + len - i - 1); } } break; default: for (i = 0; i < len; i++) { if (i <= len / 2) { arb_randtest(x + i, state, xbits, ebits); arb_randtest(y + i, state, ybits, ebits); } else { arb_neg_round(x + i, x + len - i - 1, 2 + n_randint(state, 500)); arb_set_round(y + i, y + len - i - 1, 2 + n_randint(state, 500)); } } break; } arb_randtest(s1, state, 200, 100); arb_randtest(s2, state, 200, 100); arb_randtest(z, state, xbits, ebits); arb_approx_dot(s1, initial ? z : NULL, subtract, revx ? (x + len - 1) : x, revx ? -1 : 1, revy ? (y + len - 1) : y, revy ? -1 : 1, len, prec); mag_zero(arb_radref(s1)); /* With the fast algorithm, we expect identical results when reversing the vectors. */ if (ebits <= 12) { arb_approx_dot(s2, initial ? z : NULL, subtract, !revx ? (x + len - 1) : x, !revx ? -1 : 1, !revy ? (y + len - 1) : y, !revy ? -1 : 1, len, prec); mag_zero(arb_radref(s2)); if (!arb_equal(s1, s2)) { flint_printf("FAIL (reversal)\n\n"); flint_printf("iter = %wd, len = %wd, prec = %wd, ebits = %wd\n\n", iter, len, prec, ebits); if (initial) { flint_printf("z = ", i); arb_printn(z, 100, ARB_STR_MORE); flint_printf(" (%wd)\n\n", arb_bits(z)); } for (i = 0; i < len; i++) { flint_printf("x[%wd] = ", i); arb_printn(x + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(x + i)); flint_printf("y[%wd] = ", i); arb_printn(y + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(y + i)); } flint_printf("\n\n"); flint_printf("s1 = "); arb_printn(s1, 100, ARB_STR_MORE); flint_printf("\n\n"); flint_printf("s2 = "); arb_printn(s2, 100, ARB_STR_MORE); flint_printf("\n\n"); flint_abort(); } } /* Verify that radii are ignored */ for (i = 0; i < len; i++) { arb_get_mid_arb(x + i, x + i); arb_get_mid_arb(y + i, y + i); } arb_get_mid_arb(z, z); arb_approx_dot(s2, initial ? z : NULL, subtract, revx ? (x + len - 1) : x, revx ? -1 : 1, revy ? (y + len - 1) : y, revy ? -1 : 1, len, prec); mag_zero(arb_radref(s2)); if (!arb_equal(s1, s2)) { flint_printf("FAIL (radii)\n\n"); flint_printf("iter = %wd, len = %wd, prec = %wd, ebits = %wd\n\n", iter, len, prec, ebits); if (initial) { flint_printf("z = ", i); arb_printn(z, 100, ARB_STR_MORE); flint_printf(" (%wd)\n\n", arb_bits(z)); } for (i = 0; i < len; i++) { flint_printf("x[%wd] = ", i); arb_printn(x + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(x + i)); flint_printf("y[%wd] = ", i); arb_printn(y + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(y + i)); } flint_printf("\n\n"); flint_printf("s1 = "); arb_printn(s1, 100, ARB_STR_MORE); flint_printf("\n\n"); flint_printf("s2 = "); arb_printn(s2, 100, ARB_STR_MORE); flint_printf("\n\n"); flint_abort(); } /* Compare with arb_dot */ arb_approx_dot(s2, initial ? z : NULL, subtract, revx ? (x + len - 1) : x, revx ? -1 : 1, revy ? (y + len - 1) : y, revy ? -1 : 1, len, prec); { mag_t err, xx, yy; mag_init(err); mag_init(xx); mag_init(yy); if (initial) arb_get_mag(err, z); for (i = 0; i < len; i++) { arb_get_mag(xx, revx ? x + len - 1 - i : x + i); arb_get_mag(yy, revx ? y + len - 1 - i : y + i); mag_addmul(err, xx, yy); } mag_mul_2exp_si(err, err, -prec + 2); arb_add_error_mag(s2, err); if (!arb_contains(s2, s1)) { flint_printf("FAIL (inclusion)\n\n"); flint_printf("iter = %wd, len = %wd, prec = %wd, ebits = %wd\n\n", iter, len, prec, ebits); if (initial) { flint_printf("z = ", i); arb_printn(z, 100, ARB_STR_MORE); flint_printf(" (%wd)\n\n", arb_bits(z)); } for (i = 0; i < len; i++) { flint_printf("x[%wd] = ", i); arb_printn(x + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(x + i)); flint_printf("y[%wd] = ", i); arb_printn(y + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(y + i)); } flint_printf("\n\n"); flint_printf("s1 = "); arb_printn(s1, 100, ARB_STR_MORE); flint_printf("\n\n"); flint_printf("s2 = "); arb_printn(s2, 100, ARB_STR_MORE); flint_printf("\n\n"); flint_abort(); } mag_clear(err); mag_clear(xx); mag_clear(yy); } arb_clear(s1); arb_clear(s2); arb_clear(z); _arb_vec_clear(x, len); _arb_vec_clear(y, len); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("set_round_uiui...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000000 * arb_test_multiplier(); iter++) { arf_t x, y; slong prec, fix1, fix2; int ret1, ret2, sgnbit; mp_limb_t t[2]; arf_rnd_t rnd; prec = 2 + n_randint(state, 1000); arf_init(x); arf_init(y); arf_randtest_special(x, state, 1 + n_randint(state, 200), 1 + n_randint(state, 100)); arf_randtest_special(y, state, 1 + n_randint(state, 200), 1 + n_randint(state, 100)); do { t[0] = n_randtest(state); t[1] = n_randtest(state); } while (t[0] == 0 && t[1] == 0); sgnbit = n_randint(state, 2); switch (n_randint(state, 10)) { case 0: rnd = ARF_RND_DOWN; break; case 1: rnd = ARF_RND_UP; break; case 2: rnd = ARF_RND_FLOOR; break; case 3: rnd = ARF_RND_CEIL; break; default: rnd = ARF_RND_NEAR; break; } if (t[1] != 0) { ret1 = _arf_set_round_mpn(x, &fix1, t, 2, sgnbit, prec, rnd); fmpz_set_si(ARF_EXPREF(x), 2 * FLINT_BITS + fix1); } else { ret1 = _arf_set_round_mpn(x, &fix1, t, 1, sgnbit, prec, rnd); fmpz_set_si(ARF_EXPREF(x), FLINT_BITS + fix1); } ret2 = _arf_set_round_uiui(y, &fix2, t[1], t[0], sgnbit, prec, rnd); fmpz_set_si(ARF_EXPREF(y), 2 * FLINT_BITS + fix2); if (!arf_equal(x, y) || (ret1 != ret2)) { flint_printf("FAIL\n\n"); flint_printf("prec = %wd", prec); flint_printf("\n\n"); flint_printf("hi = %wu, lo = %wu\n\n", t[1], t[0]); flint_printf("x = "); arf_print(x); flint_printf("\n\n"); flint_printf("y = "); arf_print(y); flint_printf("\n\n"); flint_printf("ret1 = %d, ret2 = %d\n\n", ret1, ret2); flint_abort(); } arf_clear(x); arf_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("gamma_upper_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { slong m, n1, n2, bits1, bits2, bits3; acb_poly_t S, A, B, C; acb_t s, t, c; int regularized; regularized = n_randint(state, 3); bits1 = 2 + n_randint(state, 200); bits2 = 2 + n_randint(state, 200); bits3 = 2 + n_randint(state, 200); m = 1 + n_randint(state, 10); n1 = 1 + n_randint(state, 10); n2 = 1 + n_randint(state, 10); acb_poly_init(S); acb_poly_init(A); acb_poly_init(B); acb_poly_init(C); acb_init(s); acb_init(t); acb_init(c); acb_poly_randtest(S, state, m, bits1, 3); acb_poly_randtest(A, state, m, bits1, 3); acb_poly_randtest(B, state, m, bits1, 3); acb_randtest(s, state, bits1, 3); acb_hypgeom_gamma_upper_series(A, s, S, regularized, n1, bits2); acb_hypgeom_gamma_upper_series(B, s, S, regularized, n2, bits3); acb_poly_set(C, A); acb_poly_truncate(C, FLINT_MIN(n1, n2)); acb_poly_truncate(B, FLINT_MIN(n1, n2)); if (!acb_poly_overlaps(B, C)) { flint_printf("FAIL (consistency)\n\n"); flint_printf("regularized = %d\n\n", regularized); flint_printf("S = "); acb_poly_printd(S, 15); flint_printf("\n\n"); flint_printf("A = "); acb_poly_printd(A, 15); flint_printf("\n\n"); flint_printf("B = "); acb_poly_printd(B, 15); flint_printf("\n\n"); flint_printf("C = "); acb_poly_printd(C, 15); flint_printf("\n\n"); flint_abort(); } /* f(h(x)) = -exp(-h(x)) h(x)^(s-1) */ acb_poly_neg(C, S); acb_poly_exp_series(C, C, n1, bits2); acb_sub_ui(t, s, 1, bits2); acb_poly_pow_acb_series(B, S, t, n1, bits2); acb_poly_mullow(C, C, B, n1, bits2); acb_poly_neg(C, C); if (regularized == 0) { /* integral(f(h(x)) h'(x))' = f(h(x)) h'(x) */ acb_poly_derivative(B, S, bits2); acb_poly_mullow(C, C, B, n1, bits2); acb_poly_truncate(C, n1 - 1); } else if (regularized == 1) { /* (integral(f(h(x)) h'(x)) / c)' = (f(h(x)) h'(x)) / c */ acb_poly_derivative(B, S, bits2); acb_poly_mullow(C, C, B, n1, bits2); acb_gamma(c, s, bits2); acb_poly_scalar_div(C, C, c, bits2); acb_poly_truncate(C, n1 - 1); } else if (regularized == 2) { /* (h(x)^-s integral(f(h(x)) h'(x)))' = * h(x)^-(s+1) (h(x) f(h(x)) - s integral(f(h(x)) h'(x))) h'(x) */ acb_poly_t D; acb_poly_init(D); acb_poly_derivative(B, S, bits2); acb_poly_mullow(D, C, B, n1, bits2); acb_poly_integral(D, D, bits2); acb_poly_scalar_mul(D, D, s, bits2); acb_poly_mullow(C, C, S, n1, bits2); acb_poly_sub(D, C, D, bits2); acb_add_ui(t, s, 1, bits2); acb_neg(t, t); acb_poly_pow_acb_series(B, S, t, n1, bits2); acb_poly_mullow(C, D, B, n1, bits2); acb_poly_derivative(B, S, bits2); acb_poly_mullow(C, C, B, n1, bits2); acb_poly_truncate(C, n1 - 1); acb_poly_clear(D); } acb_poly_derivative(B, A, bits2); if (!acb_poly_overlaps(B, C)) { flint_printf("FAIL (derivative)\n\n"); flint_printf("regularized = %d\n\n", regularized); flint_printf("S = "); acb_poly_printd(S, 15); flint_printf("\n\n"); flint_printf("A = "); acb_poly_printd(A, 15); flint_printf("\n\n"); flint_printf("B = "); acb_poly_printd(B, 15); flint_printf("\n\n"); flint_printf("C = "); acb_poly_printd(C, 15); flint_printf("\n\n"); flint_abort(); } acb_hypgeom_gamma_upper_series(S, s, S, regularized, n1, bits2); if (!acb_poly_overlaps(A, S)) { flint_printf("FAIL (aliasing)\n\n"); flint_printf("regularized = %d\n\n", regularized); flint_printf("S = "); acb_poly_printd(S, 15); flint_printf("\n\n"); flint_printf("A = "); acb_poly_printd(A, 15); flint_printf("\n\n"); flint_abort(); } acb_poly_clear(S); acb_poly_clear(A); acb_poly_clear(B); acb_poly_clear(C); acb_clear(s); acb_clear(t); acb_clear(c); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("evaluate...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { slong qbits1, qbits2, rbits1, rbits2, rbits3; fmpq_poly_t F; fmpq_t X, Y; arb_poly_t f; arb_t x, y; qbits1 = 2 + n_randint(state, 200); qbits2 = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); rbits3 = 2 + n_randint(state, 200); fmpq_poly_init(F); fmpq_init(X); fmpq_init(Y); arb_poly_init(f); arb_init(x); arb_init(y); fmpq_poly_randtest(F, state, 1 + n_randint(state, 20), qbits1); fmpq_randtest(X, state, qbits2); fmpq_poly_evaluate_fmpq(Y, F, X); arb_poly_set_fmpq_poly(f, F, rbits1); arb_set_fmpq(x, X, rbits2); arb_poly_evaluate(y, f, x, rbits3); if (!arb_contains_fmpq(y, Y)) { flint_printf("FAIL\n\n"); flint_printf("F = "); fmpq_poly_print(F); flint_printf("\n\n"); flint_printf("X = "); fmpq_print(X); flint_printf("\n\n"); flint_printf("Y = "); fmpq_print(Y); flint_printf("\n\n"); flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n"); flint_printf("x = "); arb_printd(x, 15); flint_printf("\n\n"); flint_printf("y = "); arb_printd(y, 15); flint_printf("\n\n"); abort(); } /* aliasing */ arb_poly_evaluate(x, f, x, rbits3); if (!arb_contains_fmpq(x, Y)) { flint_printf("FAIL (aliasing)\n\n"); abort(); } fmpq_poly_clear(F); fmpq_clear(X); fmpq_clear(Y); arb_poly_clear(f); arb_clear(x); arb_clear(y); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }