int main(void) { int i, result; flint_rand_t state; printf("content...."); fflush(stdout); flint_randinit(state); /* Check that content(a f) = abs(a) content(f) */ for (i = 0; i < 10000; i++) { fmpq_poly_t f, g; fmpq_t a, b, c; fmpq_poly_init(f); fmpq_poly_init(g); fmpq_init(a); fmpq_init(b); fmpq_init(c); fmpq_poly_randtest_not_zero(f, state, n_randint(state, 100) + 1, 100); fmpq_randtest_not_zero(a, state, 100); fmpq_poly_scalar_mul_fmpq(g, f, a); fmpq_poly_content(b, g); fmpq_poly_content(c, f); fmpq_mul(c, a, c); fmpq_abs(c, c); result = (fmpq_equal(b, c)); if (!result) { printf("FAIL:\n"); fmpq_poly_print(f), printf("\n\n"); fmpq_poly_print(g), printf("\n\n"); fmpq_print(a), printf("\n\n"); fmpq_print(b), printf("\n\n"); fmpq_print(c), printf("\n\n"); abort(); } fmpq_poly_clear(f); fmpq_poly_clear(g); fmpq_clear(a); fmpq_clear(b); fmpq_clear(c); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main() { long iter; flint_rand_t state; printf("log_series...."); fflush(stdout); flint_randinit(state); /* compare with fmpq_poly */ for (iter = 0; iter < 10000; iter++) { long m, n, qbits, rbits1, rbits2; fmpq_poly_t A, B; acb_poly_t a, b; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 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); acb_poly_init(a); acb_poly_init(b); fmpq_poly_randtest_not_zero(A, state, m, qbits); fmpq_poly_set_coeff_ui(A, 0, 1UL); fmpq_poly_log_series(B, A, n); acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5); acb_poly_log_series(b, a, n, rbits2); if (!acb_poly_contains_fmpq_poly(b, B)) { printf("FAIL\n\n"); printf("bits2 = %ld\n", rbits2); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("B = "); fmpq_poly_print(B); printf("\n\n"); printf("a = "); acb_poly_printd(a, 15); printf("\n\n"); printf("b = "); acb_poly_printd(b, 15); printf("\n\n"); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); acb_poly_clear(a); acb_poly_clear(b); } /* test aliasing */ for (iter = 0; iter < 10000; iter++) { long m, n, qbits, rbits1, rbits2; fmpq_poly_t A; acb_poly_t a, b; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); m = 1 + n_randint(state, 20); n = 1 + n_randint(state, 20); fmpq_poly_init(A); acb_poly_init(a); acb_poly_init(b); do { fmpq_poly_randtest_not_zero(A, state, m, qbits); } while (fmpz_sgn(A->coeffs + 0) <= 0); acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_log_series(b, a, n, rbits2); acb_poly_log_series(a, a, n, rbits2); if (!acb_poly_equal(a, b)) { printf("FAIL\n\n"); printf("bits2 = %ld\n", rbits2); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("a = "); acb_poly_printd(a, 15); printf("\n\n"); printf("b = "); acb_poly_printd(b, 15); printf("\n\n"); abort(); } fmpq_poly_clear(A); acb_poly_clear(a); acb_poly_clear(b); } /* test that exp(log(f)) contains f */ for (iter = 0; iter < 10000; iter++) { long m, n, qbits, rbits1, rbits2, rbits3; fmpq_poly_t A; acb_poly_t a, b, c; qbits = 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); acb_poly_init(a); acb_poly_init(b); acb_poly_init(c); do { fmpq_poly_randtest_not_zero(A, state, m, qbits); } while (fmpz_sgn(A->coeffs + 0) <= 0); acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5); acb_poly_log_series(b, a, n, rbits2); acb_poly_exp_series_basecase(c, b, n, rbits3); fmpq_poly_truncate(A, n); if (!acb_poly_contains_fmpq_poly(c, A)) { printf("FAIL\n\n"); printf("bits2 = %ld\n", rbits2); printf("bits3 = %ld\n", rbits3); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("a = "); acb_poly_printd(a, 15); printf("\n\n"); printf("b = "); acb_poly_printd(b, 15); printf("\n\n"); printf("c = "); acb_poly_printd(c, 15); printf("\n\n"); abort(); } fmpq_poly_clear(A); acb_poly_clear(a); acb_poly_clear(b); acb_poly_clear(c); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { long iter; flint_rand_t state; printf("divrem...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 100000; iter++) { long m, n, qbits1, qbits2, rbits1, rbits2, rbits3; fmpq_poly_t A, B, Q, R; arb_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); arb_poly_init(a); arb_poly_init(b); arb_poly_init(q); arb_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); arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_set_fmpq_poly(b, B, rbits2); arb_poly_divrem(q, r, a, b, rbits3); if (!arb_poly_contains_fmpq_poly(q, Q) || !arb_poly_contains_fmpq_poly(r, R)) { printf("FAIL\n\n"); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("B = "); fmpq_poly_print(B); printf("\n\n"); printf("Q = "); fmpq_poly_print(Q); printf("\n\n"); printf("R = "); fmpq_poly_print(R); printf("\n\n"); printf("a = "); arb_poly_printd(a, 15); printf("\n\n"); printf("b = "); arb_poly_printd(b, 15); printf("\n\n"); printf("q = "); arb_poly_printd(q, 15); printf("\n\n"); printf("r = "); arb_poly_printd(r, 15); printf("\n\n"); abort(); } arb_poly_divrem(a, r, a, b, rbits3); if (!arb_poly_equal(a, q)) { printf("FAIL (aliasing q, a)\n\n"); } arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_divrem(b, r, a, b, rbits3); if (!arb_poly_equal(b, q)) { printf("FAIL (aliasing q, b)\n\n"); abort(); } arb_poly_set_fmpq_poly(b, B, rbits2); arb_poly_divrem(q, a, a, b, rbits3); if (!arb_poly_equal(a, r)) { printf("FAIL (aliasing r, a)\n\n"); abort(); } arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_divrem(q, b, a, b, rbits3); if (!arb_poly_equal(b, r)) { printf("FAIL (aliasing r, b)\n\n"); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpq_poly_clear(Q); fmpq_poly_clear(R); arb_poly_clear(a); arb_poly_clear(b); arb_poly_clear(q); arb_poly_clear(r); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; ulong cflags = UWORD(0); FLINT_TEST_INIT(state); flint_printf("sqrt_series...."); fflush(stdout); /* Check aliasing of a and c */ for (i = 0; i < 50 * flint_test_multiplier(); i++) { fmpq_poly_t a, b; slong n = n_randint(state, 50) + 1; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50); fmpq_poly_set_coeff_ui(a, 0, UWORD(1)); fmpq_poly_canonicalise(a); fmpq_poly_sqrt_series(b, a, n); fmpq_poly_sqrt_series(a, a, n); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(b) ? 0 : 2; result = (fmpq_poly_equal(a, b) && !cflags); if (!result) { flint_printf("FAIL:\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); } /* Check sqrt(a)^2 = a */ for (i = 0; i < 50 * flint_test_multiplier(); i++) { fmpq_poly_t a, b, c; slong n = n_randint(state, 80) + 1; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest_not_zero(a, state, n_randint(state, 80) + 1, 80); fmpq_poly_set_coeff_ui(a, 0, UWORD(1)); fmpq_poly_sqrt_series(b, a, n); fmpq_poly_mullow(c, b, b, n); fmpq_poly_truncate(a, n); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; result = (fmpq_poly_equal(c, a) && !cflags); if (!result) { flint_printf("FAIL:\n"); flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n"); flint_printf("b = "), fmpq_poly_debug(b), flint_printf("\n\n"); flint_printf("c = "), fmpq_poly_debug(c), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main() { slong iter; flint_rand_t state; flint_printf("div_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++) { slong m, n, p, qbits, rbits1, rbits2; fmpq_poly_t A, B, C; arb_poly_t a, b, c, d; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 2 + n_randint(state, 200); m = 1 + n_randint(state, 20); n = 1 + n_randint(state, 20); p = 1 + n_randint(state, 20); fmpq_poly_init(A); fmpq_poly_init(B); fmpq_poly_init(C); arb_poly_init(a); arb_poly_init(b); arb_poly_init(c); arb_poly_init(d); fmpq_poly_randtest(A, state, m, qbits); do { fmpq_poly_randtest_not_zero(B, state, n, qbits); } while (B->coeffs[0] == 0); fmpq_poly_div_series(C, A, B, p); arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_set_fmpq_poly(b, B, rbits1); arb_poly_div_series(c, a, b, p, rbits2); if (!arb_poly_contains_fmpq_poly(c, C)) { flint_printf("FAIL\n\n"); flint_printf("bits2 = %wd\n", rbits2); flint_printf("A = "); fmpq_poly_print(A); flint_printf("\n\n"); flint_printf("B = "); fmpq_poly_print(B); flint_printf("\n\n"); flint_printf("C = "); fmpq_poly_print(C); 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_abort(); } arb_poly_set(d, a); arb_poly_div_series(d, d, b, p, rbits2); if (!arb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 1)\n\n"); flint_abort(); } arb_poly_set(d, b); arb_poly_div_series(d, a, d, p, rbits2); if (!arb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 2)\n\n"); flint_abort(); } arb_poly_set(d, b); arb_poly_div_series(c, d, d, p, rbits2); arb_poly_div_series(d, d, d, p, rbits2); if (!arb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 3)\n\n"); flint_abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpq_poly_clear(C); arb_poly_clear(a); arb_poly_clear(b); arb_poly_clear(c); arb_poly_clear(d); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main() { long iter; flint_rand_t state; printf("inv_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000; iter++) { long m, n, qbits, rbits1, rbits2; fmpq_poly_t A, B; fmpcb_poly_t a, b; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 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); fmpcb_poly_init(a); fmpcb_poly_init(b); do { fmpq_poly_randtest_not_zero(A, state, m, qbits); } while (A->coeffs[0] == 0); fmpq_poly_inv_series(B, A, n); fmpcb_poly_set_fmpq_poly(a, A, rbits1); fmpcb_poly_inv_series(b, a, n, rbits2); if (!fmpcb_poly_contains_fmpq_poly(b, B)) { printf("FAIL\n\n"); printf("bits2 = %ld\n", rbits2); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("B = "); fmpq_poly_print(B); printf("\n\n"); printf("a = "); fmpcb_poly_printd(a, 15); printf("\n\n"); printf("b = "); fmpcb_poly_printd(b, 15); printf("\n\n"); abort(); } fmpcb_poly_inv_series(a, a, n, rbits2); if (!fmpcb_poly_equal(a, b)) { printf("FAIL (aliasing)\n\n"); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpcb_poly_clear(a); fmpcb_poly_clear(b); } /* check f * f^-1 = 1 */ for (iter = 0; iter < 10000; iter++) { long bits, trunc; fmpcb_poly_t a, b, ab; fmpq_poly_t id; bits = 2 + n_randint(state, 200); trunc = 1 + n_randint(state, 10); fmpcb_poly_init(a); fmpcb_poly_init(b); fmpcb_poly_init(ab); fmpq_poly_init(id); do { fmpcb_poly_randtest(a, state, 1 + n_randint(state, 10), bits, 5); } while (a->length == 0 || fmpcb_contains_zero(a->coeffs + 0)); fmpcb_poly_inv_series(b, a, trunc, bits); fmpcb_poly_mullow(ab, a, b, trunc, bits); fmpq_poly_set_ui(id, 1); if (!fmpcb_poly_contains_fmpq_poly(ab, id)) { printf("FAIL\n\n"); printf("bits = %ld\n", bits); printf("trunc = %ld\n", trunc); printf("a = "); fmpcb_poly_printd(a, 15); printf("\n\n"); printf("b = "); fmpcb_poly_printd(b, 15); printf("\n\n"); printf("ab = "); fmpcb_poly_printd(ab, 15); printf("\n\n"); abort(); } fmpcb_poly_clear(a); fmpcb_poly_clear(b); fmpcb_poly_clear(ab); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { slong iter; flint_rand_t state; flint_printf("sqrt_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 5000; iter++) { slong m, n, qbits, rbits1, rbits2; fmpq_poly_t A; acb_poly_t a, b, c; 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); fmpq_poly_init(A); acb_poly_init(a); acb_poly_init(b); acb_poly_init(c); fmpq_poly_randtest_not_zero(A, state, m, qbits); acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_sqrt_series(b, a, n, rbits2); /* Check sqrt(a)^2 = a */ acb_poly_mullow(c, b, b, n, rbits2); fmpq_poly_truncate(A, n); if (!acb_poly_contains_fmpq_poly(c, A)) { 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 = "); 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"); abort(); } acb_poly_sqrt_series(a, a, n, rbits2); if (!acb_poly_equal(a, b)) { flint_printf("FAIL (aliasing)\n\n"); abort(); } fmpq_poly_clear(A); acb_poly_clear(a); acb_poly_clear(b); acb_poly_clear(c); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; ulong cflags = UWORD(0); FLINT_TEST_INIT(state); flint_printf("asinh_series...."); fflush(stdout); /* Check aliasing of a and c */ for (i = 0; i < 20 * flint_test_multiplier(); i++) { fmpq_poly_t a, b; slong n = n_randint(state, 50) + 1; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50); fmpq_poly_set_coeff_ui(a, 0, UWORD(0)); fmpq_poly_canonicalise(a); fmpq_poly_asinh_series(b, a, n); fmpq_poly_asinh_series(a, a, n); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(b) ? 0 : 2; result = (fmpq_poly_equal(a, b) && !cflags); if (!result) { flint_printf("FAIL:\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); } /* Check asinh(A) = atanh(A/sqrt(1+A^2)) */ for (i = 0; i < 20 * flint_test_multiplier(); i++) { fmpq_poly_t A, B, asinhA, atanhB; slong n = n_randint(state, 80) + 1; fmpq_poly_init(A); fmpq_poly_init(B); fmpq_poly_init(asinhA); fmpq_poly_init(atanhB); fmpq_poly_randtest_not_zero(A, state, n_randint(state, 80) + 1, 80); fmpq_poly_set_coeff_ui(A, 0, UWORD(0)); fmpq_poly_mullow(B, A, A, n); fmpq_poly_set_coeff_ui(B, 0, UWORD(1)); fmpq_poly_invsqrt_series(B, B, n); fmpq_poly_mullow(B, A, B, n); fmpq_poly_asinh_series(asinhA, A, n); fmpq_poly_atanh_series(atanhB, B, n); cflags |= fmpq_poly_is_canonical(asinhA) ? 0 : 1; cflags |= fmpq_poly_is_canonical(atanhB) ? 0 : 2; result = (fmpq_poly_equal(asinhA, atanhB) && !cflags); if (!result) { flint_printf("FAIL:\n"); flint_printf("A = "), fmpq_poly_debug(A), flint_printf("\n\n"); flint_printf("B = "), fmpq_poly_debug(B), flint_printf("\n\n"); flint_printf("asinh(A) = "), fmpq_poly_debug(asinhA), flint_printf("\n\n"); flint_printf("atanh(B) = "), fmpq_poly_debug(atanhB), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpq_poly_clear(asinhA); fmpq_poly_clear(atanhB); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { int i, result; flint_rand_t state; ulong cflags = 0UL; printf("rem...."); fflush(stdout); flint_randinit(state); /* Check aliasing of r and a */ for (i = 0; i < 2000; i++) { fmpq_poly_t a, b, r; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(r); fmpq_poly_randtest(a, state, n_randint(state, 50), 200); fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200); fmpq_poly_rem(r, a, b); fmpq_poly_rem(a, a, b); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(r) ? 0 : 2; result = (fmpq_poly_equal(r, a) && !cflags); if (!result) { printf("FAIL:\n"); printf("r = "), fmpq_poly_debug(r), printf("\n\n"); printf("a = "), fmpq_poly_debug(a), printf("\n\n"); printf("b = "), fmpq_poly_debug(b), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(r); } /* Check aliasing of r and b */ for (i = 0; i < 2000; i++) { fmpq_poly_t a, b, r; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(r); fmpq_poly_randtest(a, state, n_randint(state, 50), 200); fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200); fmpq_poly_rem(r, a, b); fmpq_poly_rem(b, a, b); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(r) ? 0 : 2; result = (fmpq_poly_equal(r, b) && !cflags); if (!result) { printf("FAIL:\n"); printf("r = "), fmpq_poly_debug(r), printf("\n\n"); printf("a = "), fmpq_poly_debug(a), printf("\n\n"); printf("b = "), fmpq_poly_debug(b), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(r); } /* Compare with divrem */ for (i = 0; i < 2000; i++) { fmpq_poly_t a, b, q, r, r2; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(q); fmpq_poly_init(r); fmpq_poly_init(r2); fmpq_poly_randtest(a, state, n_randint(state, 50), 200); fmpq_poly_randtest_not_zero(b, state, n_randint(state, 50) + 1, 200); fmpq_poly_divrem(q, r, a, b); fmpq_poly_rem(r2, a, b); cflags |= fmpq_poly_is_canonical(q) ? 0 : 1; cflags |= fmpq_poly_is_canonical(r2) ? 0 : 2; result = (fmpq_poly_equal(r, r2) && !cflags); if (!result) { printf("FAIL:\n"); printf("a = "), fmpq_poly_debug(a), printf("\n\n"); printf("b = "), fmpq_poly_debug(b), printf("\n\n"); printf("q = "), fmpq_poly_debug(q), printf("\n\n"); printf("r = "), fmpq_poly_debug(r), printf("\n\n"); printf("r2 = "), fmpq_poly_debug(r2), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(q); fmpq_poly_clear(r); fmpq_poly_clear(r2); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main(void) { int i, result; flint_rand_t state; ulong cflags = 0UL; printf("sinh_series...."); fflush(stdout); flint_randinit(state); /* Check aliasing of a and c */ for (i = 0; i < 200; i++) { fmpq_poly_t a, b; long n = n_randint(state, 50) + 1; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50); fmpq_poly_set_coeff_ui(a, 0, 0UL); fmpq_poly_canonicalise(a); fmpq_poly_sinh_series(b, a, n); fmpq_poly_sinh_series(a, a, n); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(b) ? 0 : 2; result = (fmpq_poly_equal(a, b) && !cflags); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); } /* Check asinh(sinh(a)) = a */ for (i = 0; i < 200; i++) { fmpq_poly_t a, sinha, asinhsinha; long n = n_randint(state, 80) + 1; fmpq_poly_init(a); fmpq_poly_init(sinha); fmpq_poly_init(asinhsinha); fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80); fmpq_poly_set_coeff_ui(a, 0, 0UL); fmpq_poly_sinh_series(sinha, a, n); fmpq_poly_asinh_series(asinhsinha, sinha, n); fmpq_poly_truncate(a, n); cflags |= fmpq_poly_is_canonical(sinha) ? 0 : 1; cflags |= fmpq_poly_is_canonical(asinhsinha) ? 0 : 2; result = (fmpq_poly_equal(asinhsinha, a) && !cflags); if (!result) { printf("FAIL:\n"); printf("a = "), fmpq_poly_debug(a), printf("\n\n"); printf("sinh(a) = "), fmpq_poly_debug(sinha), printf("\n\n"); printf("asinh(sinh(a)) = "), fmpq_poly_debug(asinhsinha), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(sinha); fmpq_poly_clear(asinhsinha); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main() { long iter; flint_rand_t state; printf("inv_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 10000; iter++) { long m, n, qbits, rbits1, rbits2; fmpq_poly_t A, B; fmprb_poly_t a, b; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 200); rbits2 = 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); fmprb_poly_init(a); fmprb_poly_init(b); do { fmpq_poly_randtest_not_zero(A, state, m, qbits); } while (A->coeffs[0] == 0); fmprb_poly_randtest(b, state, 1 + n_randint(state, 20), rbits1, 5); fmpq_poly_inv_series(B, A, n); fmprb_poly_set_fmpq_poly(a, A, rbits1); fmprb_poly_inv_series(b, a, n, rbits2); if (!fmprb_poly_contains_fmpq_poly(b, B)) { printf("FAIL\n\n"); printf("bits2 = %ld\n", rbits2); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("B = "); fmpq_poly_print(B); printf("\n\n"); printf("a = "); fmprb_poly_printd(a, 15); printf("\n\n"); printf("b = "); fmprb_poly_printd(b, 15); printf("\n\n"); abort(); } fmprb_poly_inv_series(a, a, n, rbits2); if (!fmprb_poly_equal(a, b)) { printf("FAIL (aliasing)\n\n"); abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmprb_poly_clear(a); fmprb_poly_clear(b); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main() { long iter; flint_rand_t state; printf("lgamma_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000; iter++) { long m, n1, n2, qbits, rbits1, rbits2, rbits3; fmpq_poly_t A; fmprb_poly_t a, b, c, d; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 400); rbits2 = 2 + n_randint(state, 400); rbits3 = 2 + n_randint(state, 400); m = 1 + n_randint(state, 30); n1 = 1 + n_randint(state, 30); n2 = 1 + n_randint(state, 30); fmpq_poly_init(A); fmprb_poly_init(a); fmprb_poly_init(b); fmprb_poly_init(c); fmprb_poly_init(d); fmpq_poly_randtest_not_zero(A, state, m, qbits); fmpz_abs(A->coeffs, A->coeffs); fmprb_poly_set_fmpq_poly(a, A, rbits1); fmprb_poly_lgamma_series(b, a, n1, rbits2); fmprb_poly_lgamma_series(c, a, n2, rbits3); fmprb_poly_set(d, b); fmprb_poly_truncate(d, FLINT_MIN(n1, n2)); fmprb_poly_truncate(c, FLINT_MIN(n1, n2)); if (!fmprb_poly_overlaps(c, d)) { printf("FAIL\n\n"); printf("n1 = %ld, n2 = %ld, bits2 = %ld, bits3 = %ld\n", n1, n2, rbits2, rbits3); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("a = "); fmprb_poly_printd(a, 15); printf("\n\n"); printf("b = "); fmprb_poly_printd(b, 15); printf("\n\n"); printf("c = "); fmprb_poly_printd(c, 15); printf("\n\n"); abort(); } /* check loggamma(a) + log(a) = loggamma(a+1) */ fmprb_poly_log_series(c, a, n1, rbits2); fmprb_poly_add(c, b, c, rbits2); fmprb_poly_set(d, a); fmprb_add_ui(d->coeffs, d->coeffs, 1, rbits2); fmprb_poly_lgamma_series(d, d, n1, rbits2); if (!fmprb_poly_overlaps(c, d)) { printf("FAIL (functional equation)\n\n"); printf("A = "); fmpq_poly_print(A); printf("\n\n"); printf("a = "); fmprb_poly_printd(a, 15); printf("\n\n"); printf("b = "); fmprb_poly_printd(b, 15); printf("\n\n"); printf("c = "); fmprb_poly_printd(c, 15); printf("\n\n"); printf("d = "); fmprb_poly_printd(d, 15); printf("\n\n"); abort(); } fmprb_poly_lgamma_series(a, a, n1, rbits2); if (!fmprb_poly_overlaps(a, b)) { printf("FAIL (aliasing)\n\n"); abort(); } fmpq_poly_clear(A); fmprb_poly_clear(a); fmprb_poly_clear(b); fmprb_poly_clear(c); fmprb_poly_clear(d); } flint_randclear(state); flint_cleanup(); printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i, result; flint_rand_t state; ulong cflags = 0UL; printf("exp_series...."); fflush(stdout); flint_randinit(state); /* Check aliasing of a and c */ for (i = 0; i < 200; i++) { fmpq_poly_t a, b; long n = n_randint(state, 50) + 1; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest_not_zero(a, state, n_randint(state, 50) + 1, 50); fmpq_poly_set_coeff_ui(a, 0, 0UL); fmpq_poly_canonicalise(a); fmpq_poly_exp_series(b, a, n); fmpq_poly_exp_series(a, a, n); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(b) ? 0 : 2; result = (fmpq_poly_equal(a, b) && !cflags); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); } /* Check exp(a+b) = exp(a) * exp(b) */ for (i = 0; i < 500; i++) { fmpq_poly_t a, b, ab, expa, expb, expab, expa_expb; long n = n_randint(state, 80) + 1; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(ab); fmpq_poly_init(expa); fmpq_poly_init(expb); fmpq_poly_init(expab); fmpq_poly_init(expa_expb); fmpq_poly_randtest_not_zero(a, state, n_randint(state, 60) + 1, 80); fmpq_poly_set_coeff_ui(a, 0, 0UL); fmpq_poly_randtest_not_zero(b, state, n_randint(state, 60) + 1, 80); fmpq_poly_set_coeff_ui(b, 0, 0UL); fmpq_poly_add(ab, a, b); fmpq_poly_exp_series(expab, ab, n); fmpq_poly_exp_series(expa, a, n); fmpq_poly_exp_series(expb, b, n); fmpq_poly_mullow(expa_expb, expa, expb, n); cflags |= fmpq_poly_is_canonical(expa) ? 0 : 1; cflags |= fmpq_poly_is_canonical(expb) ? 0 : 2; cflags |= fmpq_poly_is_canonical(expab) ? 0 : 4; result = (fmpq_poly_equal(expab, expa_expb) && !cflags); if (!result) { printf("FAIL:\n"); printf("a = "), fmpq_poly_debug(a), printf("\n\n"); printf("b = "), fmpq_poly_debug(b), printf("\n\n"); printf("exp(a) = "), fmpq_poly_debug(expa), printf("\n\n"); printf("exp(b) = "), fmpq_poly_debug(expb), printf("\n\n"); printf("exp(ab) = "), fmpq_poly_debug(expab), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(ab); fmpq_poly_clear(expa); fmpq_poly_clear(expb); fmpq_poly_clear(expab); fmpq_poly_clear(expa_expb); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main() { slong iter; flint_rand_t state; flint_printf("rgamma_series...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++) { slong m, n1, n2, qbits, rbits1, rbits2, rbits3; fmpq_poly_t A; arb_poly_t a, b, c, d; qbits = 2 + n_randint(state, 200); rbits1 = 2 + n_randint(state, 400); rbits2 = 2 + n_randint(state, 400); rbits3 = 2 + n_randint(state, 400); m = 1 + n_randint(state, 30); n1 = 1 + n_randint(state, 30); n2 = 1 + n_randint(state, 30); fmpq_poly_init(A); arb_poly_init(a); arb_poly_init(b); arb_poly_init(c); arb_poly_init(d); fmpq_poly_randtest_not_zero(A, state, m, qbits); arb_poly_set_fmpq_poly(a, A, rbits1); arb_poly_rgamma_series(b, a, n1, rbits2); arb_poly_rgamma_series(c, a, n2, rbits3); arb_poly_set(d, b); arb_poly_truncate(d, FLINT_MIN(n1, n2)); arb_poly_truncate(c, FLINT_MIN(n1, n2)); if (!arb_poly_overlaps(c, d)) { flint_printf("FAIL\n\n"); flint_printf("n1 = %wd, n2 = %wd, bits2 = %wd, bits3 = %wd\n", n1, n2, rbits2, rbits3); 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"); abort(); } /* check rgamma(a) = a gamma(a+1) */ arb_poly_add_si(d, a, 1, rbits2); arb_poly_rgamma_series(d, d, n1, rbits2); arb_poly_mullow(c, d, a, n1, rbits2); if (!arb_poly_overlaps(b, c)) { flint_printf("FAIL (functional equation, n1 = %wd)\n\n", n1); 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"); abort(); } arb_poly_rgamma_series(a, a, n1, rbits2); if (!arb_poly_overlaps(a, b)) { flint_printf("FAIL (aliasing)\n\n"); abort(); } fmpq_poly_clear(A); arb_poly_clear(a); arb_poly_clear(b); arb_poly_clear(c); arb_poly_clear(d); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }