int main(void) { int i, result; ulong cflags = UWORD(0); FLINT_TEST_INIT(state); flint_printf("compose...."); fflush(stdout); /* Check aliasing of the first argument */ for (i = 0; i < 10 * flint_test_multiplier(); i++) { fmpq_poly_t f, g, h; fmpq_poly_init(f); fmpq_poly_init(g); fmpq_poly_init(h); fmpq_poly_randtest(g, state, n_randint(state, 50), 100); fmpq_poly_randtest(h, state, n_randint(state, 20), 50); fmpq_poly_compose(f, g, h); fmpq_poly_compose(g, g, h); cflags |= fmpq_poly_is_canonical(f) ? 0 : 1; cflags |= fmpq_poly_is_canonical(g) ? 0 : 2; result = (fmpq_poly_equal(f, g) && !cflags); if (!result) { flint_printf("FAIL (aliasing 1):\n"); fmpq_poly_debug(f), flint_printf("\n\n"); fmpq_poly_debug(g), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_poly_clear(f); fmpq_poly_clear(g); fmpq_poly_clear(h); } /* Check aliasing of the second argument */ for (i = 0; i < 10 * flint_test_multiplier(); i++) { fmpq_poly_t f, g, h; fmpq_poly_init(f); fmpq_poly_init(g); fmpq_poly_init(h); fmpq_poly_randtest(g, state, n_randint(state, 50), 100); fmpq_poly_randtest(h, state, n_randint(state, 20), 50); fmpq_poly_compose(f, g, h); fmpq_poly_compose(h, g, h); cflags |= fmpq_poly_is_canonical(f) ? 0 : 1; cflags |= fmpq_poly_is_canonical(h) ? 0 : 2; result = (fmpq_poly_equal(f, h) && !cflags); if (!result) { flint_printf("FAIL (aliasing 2):\n"); fmpq_poly_debug(f), flint_printf("\n\n"); fmpq_poly_debug(h), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_poly_clear(f); fmpq_poly_clear(g); fmpq_poly_clear(h); } /* Compare with the naive method for g(h(t)) */ for (i = 0; i < 10 * flint_test_multiplier(); i++) { fmpq_poly_t f, g, h, s, t, u; mpq_t c; slong k; fmpq_poly_init(f); fmpq_poly_init(g); fmpq_poly_init(h); fmpq_poly_init(s); fmpq_poly_init(t); fmpq_poly_init(u); mpq_init(c); fmpq_poly_randtest(g, state, n_randint(state, 20), 65); fmpq_poly_randtest(h, state, n_randint(state, 20), 65); fmpq_poly_zero(s); fmpq_poly_set_ui(t, UWORD(1)); for (k = WORD(0); k < g->length; k++) { fmpq_poly_get_coeff_mpq(c, g, k); fmpq_poly_scalar_mul_mpq(u, t, c); fmpq_poly_add(s, s, u); fmpq_poly_mul(t, t, h); } fmpq_poly_compose(f, g, h); result = (fmpq_poly_equal(f, s)); if (!result) { flint_printf("FAIL (compare with naive):\n"); flint_printf("g = "), fmpq_poly_debug(g), flint_printf("\n\n"); flint_printf("h = "), fmpq_poly_debug(h), flint_printf("\n\n"); flint_printf("f = "), fmpq_poly_debug(f), flint_printf("\n\n"); flint_printf("s = "), fmpq_poly_debug(s), flint_printf("\n\n"); abort(); } fmpq_poly_clear(f); fmpq_poly_clear(g); fmpq_poly_clear(h); fmpq_poly_clear(s); fmpq_poly_clear(t); fmpq_poly_clear(u); mpq_clear(c); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main() { slong iter; flint_rand_t state; flint_printf("compose...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++) { slong qbits1, qbits2, rbits1, rbits2, rbits3; fmpq_poly_t A, B, C; acb_poly_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); fmpq_poly_init(A); fmpq_poly_init(B); fmpq_poly_init(C); acb_poly_init(a); acb_poly_init(b); acb_poly_init(c); acb_poly_init(d); fmpq_poly_randtest(A, state, 1 + n_randint(state, 20), qbits1); fmpq_poly_randtest(B, state, 1 + n_randint(state, 10), qbits2); fmpq_poly_compose(C, A, B); acb_poly_randtest(c, state, 1 + n_randint(state, 20), rbits1, 4); acb_poly_set_fmpq_poly(a, A, rbits1); acb_poly_set_fmpq_poly(b, B, rbits2); acb_poly_compose(c, a, b, rbits3); if (!acb_poly_contains_fmpq_poly(c, C)) { flint_printf("FAIL\n\n"); flint_printf("bits3 = %wd\n", rbits3); 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 = "); 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_poly_set(d, a); acb_poly_compose(d, d, b, rbits3); if (!acb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 1)\n\n"); flint_abort(); } acb_poly_set(d, b); acb_poly_compose(d, a, d, rbits3); if (!acb_poly_equal(d, c)) { flint_printf("FAIL (aliasing 2)\n\n"); flint_abort(); } fmpq_poly_clear(A); fmpq_poly_clear(B); fmpq_poly_clear(C); 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(void) { int i, result; FLINT_TEST_INIT(state); flint_printf("compose_series_brent_kung...."); fflush(stdout); /* Check aliasing of the first argument */ for (i = 0; i < 10 * flint_test_multiplier(); i++) { fmpq_poly_t f, g, h; slong n; fmpq_poly_init(f); fmpq_poly_init(g); fmpq_poly_init(h); fmpq_poly_randtest(g, state, n_randint(state, 40), 80); fmpq_poly_randtest(h, state, n_randint(state, 20), 50); fmpq_poly_set_coeff_ui(h, 0, 0); n = n_randint(state, 20); fmpq_poly_compose_series_brent_kung(f, g, h, n); fmpq_poly_compose_series_brent_kung(g, g, h, n); result = (fmpq_poly_equal(f, g)); if (!result) { flint_printf("FAIL (aliasing 1):\n"); fmpq_poly_print(f), flint_printf("\n\n"); fmpq_poly_print(g), flint_printf("\n\n"); abort(); } fmpq_poly_clear(f); fmpq_poly_clear(g); fmpq_poly_clear(h); } /* Check aliasing of the second argument */ for (i = 0; i < 10 * flint_test_multiplier(); i++) { fmpq_poly_t f, g, h; slong n; fmpq_poly_init(f); fmpq_poly_init(g); fmpq_poly_init(h); fmpq_poly_randtest(g, state, n_randint(state, 40), 80); fmpq_poly_randtest(h, state, n_randint(state, 20), 50); fmpq_poly_set_coeff_ui(h, 0, 0); n = n_randint(state, 20); fmpq_poly_compose_series_brent_kung(f, g, h, n); fmpq_poly_compose_series_brent_kung(h, g, h, n); result = (fmpq_poly_equal(f, h)); if (!result) { flint_printf("FAIL (aliasing 2):\n"); fmpq_poly_print(f), flint_printf("\n\n"); fmpq_poly_print(h), flint_printf("\n\n"); abort(); } fmpq_poly_clear(f); fmpq_poly_clear(g); fmpq_poly_clear(h); } /* Compare with compose */ for (i = 0; i < 20 * flint_test_multiplier(); i++) { fmpq_poly_t f, g, h, s, t; slong n; fmpq_poly_init(f); fmpq_poly_init(g); fmpq_poly_init(h); fmpq_poly_init(s); fmpq_poly_init(t); fmpq_poly_randtest(g, state, n_randint(state, 40), 80); fmpq_poly_randtest(h, state, n_randint(state, 20), 50); fmpq_poly_set_coeff_ui(h, 0, 0); n = n_randint(state, 20); fmpq_poly_compose(s, g, h); fmpq_poly_truncate(s, n); fmpq_poly_compose_series_brent_kung(f, g, h, n); result = (fmpq_poly_equal(f, s)); if (!result) { flint_printf("FAIL (comparison):\n"); flint_printf("n = %wd\n", n); flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n"); flint_printf("h = "), fmpq_poly_print(h), flint_printf("\n\n"); flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n"); flint_printf("s = "), fmpq_poly_print(s), flint_printf("\n\n"); abort(); } fmpq_poly_clear(f); fmpq_poly_clear(g); fmpq_poly_clear(h); fmpq_poly_clear(s); fmpq_poly_clear(t); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }