int main(void) { int cflags = 0, i, result; flint_rand_t state; printf("lcm...."); fflush(stdout); flint_randinit(state); /* Check aliasing of a and c */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_lcm(c, a, b); fmpq_poly_lcm(a, a, b); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Check aliasing of b and c */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_lcm(c, a, b); fmpq_poly_lcm(b, a, b); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(b, c) && !cflags); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Generic case when a, b are most likely co-prime ***********************/ /* Verify commutativity and that c is monic */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_lcm(c, a, b); fmpq_poly_lcm(a, b, a); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags && (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c))); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Verify that LCM(a, b) GCD(a, b) == a b */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, lcm, gcd; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(lcm); fmpq_poly_init(gcd); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_lcm(lcm, a, b); fmpq_poly_gcd(gcd, a, b); fmpq_poly_mul(lcm, lcm, gcd); fmpq_poly_mul(a, a, b); fmpq_poly_make_monic(a, a); result = fmpq_poly_equal(lcm, a); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(lcm), printf("\n\n"); fmpq_poly_debug(gcd), printf("\n\n"); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(lcm); fmpq_poly_clear(gcd); } /* Case when a, b are not co-prime ***************************************/ /* Verify commutativity and that c is monic */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c, t; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_init(t); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_randtest(t, state, n_randint(state, 50), 20); fmpq_poly_mul(a, a, t); fmpq_poly_mul(b, b, t); fmpq_poly_lcm(c, a, b); fmpq_poly_lcm(a, b, a); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags && (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c))); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); fmpq_poly_clear(t); } /* Verify that LCM(a, b) GCD(a, b) == a b */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, lcm, gcd, t; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(lcm); fmpq_poly_init(gcd); fmpq_poly_init(t); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_randtest(t, state, n_randint(state, 50), 20); fmpq_poly_mul(a, a, t); fmpq_poly_mul(b, b, t); fmpq_poly_lcm(lcm, a, b); fmpq_poly_gcd(gcd, a, b); fmpq_poly_mul(lcm, lcm, gcd); fmpq_poly_mul(a, a, b); fmpq_poly_make_monic(a, a); result = fmpq_poly_equal(lcm, a); if (!result) { printf("FAIL:\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(lcm), printf("\n\n"); fmpq_poly_debug(gcd), printf("\n\n"); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(lcm); fmpq_poly_clear(gcd); fmpq_poly_clear(t); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main(void) { int i, result; ulong cflags = UWORD(0); FLINT_TEST_INIT(state); flint_printf("scalar_div_fmpq...."); fflush(stdout); /* Check aliasing of a and b */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b; fmpq_t z; fmpq_init(z); fmpq_randtest_not_zero(z, state, 100); fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_fmpq(b, a, z); fmpq_poly_scalar_div_fmpq(a, a, z); 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 (aliasing):\n\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); fmpq_print(z), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_clear(z); fmpq_poly_clear(a); fmpq_poly_clear(b); } /* Check that (a / n1) / n2 == a / (n1 * n2) */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, lhs, rhs; fmpq_t z1, z2, z; fmpq_init(z1); fmpq_init(z2); fmpq_init(z); fmpq_randtest_not_zero(z1, state, 100); fmpq_randtest_not_zero(z2, state, 100); fmpq_mul(z, z1, z2); fmpq_poly_init(a); fmpq_poly_init(lhs); fmpq_poly_init(rhs); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_fmpq(lhs, a, z1); fmpq_poly_scalar_div_fmpq(lhs, lhs, z2); fmpq_poly_scalar_div_fmpq(rhs, a, z); cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1; cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2; result = (fmpq_poly_equal(lhs, rhs) && !cflags); if (!result) { flint_printf("FAIL (a / n1 / n2):\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_print(z1), flint_printf("\n\n"); fmpq_print(z2), flint_printf("\n\n"); fmpq_print(z), flint_printf("\n\n"); fmpq_poly_debug(lhs), flint_printf("\n\n"); fmpq_poly_debug(rhs), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_clear(z1); fmpq_clear(z2); fmpq_clear(z); fmpq_poly_clear(a); fmpq_poly_clear(lhs); fmpq_poly_clear(rhs); } /* Check that (a + b) / n == a/n + b/n */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b, lhs, rhs; fmpq_t z; fmpq_init(z); fmpq_randtest_not_zero(z, state, 100); fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(lhs); fmpq_poly_init(rhs); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_fmpq(lhs, a, z); fmpq_poly_scalar_div_fmpq(rhs, b, z); fmpq_poly_add(rhs, lhs, rhs); fmpq_poly_add(lhs, a, b); fmpq_poly_scalar_div_fmpq(lhs, lhs, z); cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1; cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2; result = (fmpq_poly_equal(lhs, rhs) && !cflags); if (!result) { flint_printf("FAIL ((a + b) / n):\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); fmpq_print(z), flint_printf("\n\n"); fmpq_poly_debug(lhs), flint_printf("\n\n"); fmpq_poly_debug(rhs), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpq_clear(z); fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(lhs); fmpq_poly_clear(rhs); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { int i, result; ulong cflags = UWORD(0); FLINT_TEST_INIT(state); flint_printf("derivative...."); fflush(stdout); /* Check aliasing */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_derivative(b, a); fmpq_poly_derivative(a, a); 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 constants have derivative zero */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest(a, state, n_randint(state, 2), 200); fmpq_poly_derivative(b, a); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; result = fmpq_poly_is_zero(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 (f g)' = f' g + f g' */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b, c, d, lhs, rhs; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_init(d); fmpq_poly_init(lhs); fmpq_poly_init(rhs); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_mul(lhs, a, b); fmpq_poly_derivative(lhs, lhs); fmpq_poly_derivative(c, a); fmpq_poly_derivative(d, b); fmpq_poly_mul(c, c, b); fmpq_poly_mul(d, a, d); fmpq_poly_add(rhs, c, d); cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1; cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2; result = fmpq_poly_equal(lhs, rhs) && !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); fmpq_poly_clear(c); fmpq_poly_clear(d); fmpq_poly_clear(lhs); fmpq_poly_clear(rhs); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { int i, result; ulong cflags = UWORD(0); FLINT_TEST_INIT(state); flint_printf("add...."); fflush(stdout); /* Check aliasing of a and c */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_add(c, a, b); fmpq_poly_add(a, a, b); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags); if (!result) { flint_printf("FAIL:\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); 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); } /* Check aliasing of b and c */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_add(c, a, b); fmpq_poly_add(b, a, b); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(b, c) && !cflags); if (!result) { flint_printf("FAIL:\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); 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(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(void) { int i, j, result; ulong cflags = UWORD(0); mpq_t n1, n2; FLINT_TEST_INIT(state); flint_printf("get/set_coeff_fmpz...."); fflush(stdout); mpq_init(n1); mpq_init(n2); for (i = 0; i < 100 * flint_test_multiplier(); i++) { fmpq_poly_t a; fmpz_t x1, x2; slong coeff, len; fmpq_poly_init(a); fmpz_init(x1); fmpz_init(x2); len = (slong) (n_randint(state, 100) + 1); for (j = 0; j < 100; j++) { fmpz_randtest(x1, state, 200); fmpz_get_mpz(mpq_numref(n1), x1); flint_mpz_set_si(mpq_denref(n1), 1); coeff = (slong) n_randint(state, len); fmpq_poly_set_coeff_fmpz(a, coeff, x1); fmpq_poly_get_coeff_mpq(n2, a, coeff); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; result = (mpq_equal(n1, n2) && !cflags); if (!result) { flint_printf("FAIL:\n\n"); flint_printf("a = "), fmpq_poly_debug(a), flint_printf("\n\n"); flint_printf("coeff = %wd\n\n", coeff); flint_printf("len = %wd\n\n", len); flint_printf("cflags = %wu\n\n", cflags); gmp_printf("n1 = %Qd\n\n", n1); gmp_printf("n2 = %Qd\n\n", n2); abort(); } } fmpz_clear(x1); fmpz_clear(x2); fmpq_poly_clear(a); } mpq_clear(n1); mpq_clear(n2); FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
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; 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(void) { int cflags = 0, i, result; flint_rand_t state; printf("xgcd...."); fflush(stdout); flint_randinit(state); /* Generic case, where a and b are coprime *******************************/ /* Verify d == s a + t b */ for (i = 0; i < 100; i++) { fmpq_poly_t a, b, d, e, f, s, t; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(d); fmpq_poly_init(e); fmpq_poly_init(f); fmpq_poly_init(s); fmpq_poly_init(t); fmpq_poly_randtest(a, state, n_randint(state, 60), 80); fmpq_poly_randtest(b, state, n_randint(state, 60), 80); fmpq_poly_xgcd(d, s, t, a, b); fmpq_poly_mul(e, s, a); fmpq_poly_mul(f, t, b); fmpq_poly_add(e, e, f); cflags |= fmpq_poly_is_canonical(d) ? 0 : 1; cflags |= fmpq_poly_is_canonical(s) ? 0 : 2; cflags |= fmpq_poly_is_canonical(t) ? 0 : 4; result = (fmpq_poly_equal(d, e) && !cflags); if (!result) { printf("FAIL (correctness #1):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(d), printf("\n\n"); fmpq_poly_debug(s), printf("\n\n"); fmpq_poly_debug(t), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(d); fmpq_poly_clear(e); fmpq_poly_clear(f); fmpq_poly_clear(s); fmpq_poly_clear(t); } /* Verify consistency with GCD */ for (i = 0; i < 100; i++) { fmpq_poly_t a, b, d, s, t; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(d); fmpq_poly_init(s); fmpq_poly_init(t); fmpq_poly_randtest(a, state, n_randint(state, 60), 80); fmpq_poly_randtest(b, state, n_randint(state, 60), 80); fmpq_poly_xgcd(d, s, t, a, b); fmpq_poly_gcd(a, a, b); cflags |= fmpq_poly_is_canonical(d) ? 0 : 1; cflags |= fmpq_poly_is_canonical(s) ? 0 : 2; cflags |= fmpq_poly_is_canonical(t) ? 0 : 4; result = (fmpq_poly_equal(d, a) && !cflags); if (!result) { printf("FAIL (GCD #1):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(d), printf("\n\n"); fmpq_poly_debug(s), printf("\n\n"); fmpq_poly_debug(t), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(d); fmpq_poly_clear(s); fmpq_poly_clear(t); } /* Generic case when a, b are most likely co-prime ***********************/ /* Verify d == s a + t b */ for (i = 0; i < 100; i++) { fmpq_poly_t a, b, d, s, t, z; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(d); fmpq_poly_init(s); fmpq_poly_init(t); fmpq_poly_init(z); fmpq_poly_randtest(a, state, n_randint(state, 60), 80); fmpq_poly_randtest(b, state, n_randint(state, 60), 80); fmpq_poly_randtest(z, state, n_randint(state, 20), 20); fmpq_poly_mul(a, a, z); fmpq_poly_mul(b, b, z); fmpq_poly_xgcd(d, s, t, a, b); fmpq_poly_mul(a, s, a); fmpq_poly_mul(b, t, b); fmpq_poly_add(a, a, b); cflags |= fmpq_poly_is_canonical(d) ? 0 : 1; cflags |= fmpq_poly_is_canonical(s) ? 0 : 2; cflags |= fmpq_poly_is_canonical(t) ? 0 : 4; result = (fmpq_poly_equal(d, a) && !cflags); if (!result) { printf("FAIL (correctness #2):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(d), printf("\n\n"); fmpq_poly_debug(s), printf("\n\n"); fmpq_poly_debug(t), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(d); fmpq_poly_clear(s); fmpq_poly_clear(t); fmpq_poly_clear(z); } /* Verify consistency with GCD */ for (i = 0; i < 100; i++) { fmpq_poly_t a, b, d, s, t, z; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(d); fmpq_poly_init(s); fmpq_poly_init(t); fmpq_poly_init(z); fmpq_poly_randtest(a, state, n_randint(state, 60), 80); fmpq_poly_randtest(b, state, n_randint(state, 60), 80); fmpq_poly_randtest(z, state, n_randint(state, 20), 20); fmpq_poly_mul(a, a, z); fmpq_poly_mul(b, b, z); fmpq_poly_xgcd(d, s, t, a, b); fmpq_poly_gcd(a, a, b); cflags |= fmpq_poly_is_canonical(d) ? 0 : 1; cflags |= fmpq_poly_is_canonical(s) ? 0 : 2; cflags |= fmpq_poly_is_canonical(t) ? 0 : 4; result = (fmpq_poly_equal(d, a) && !cflags); if (!result) { printf("FAIL (GCD #2):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(d), printf("\n\n"); fmpq_poly_debug(s), printf("\n\n"); fmpq_poly_debug(t), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(d); fmpq_poly_clear(s); fmpq_poly_clear(t); fmpq_poly_clear(z); } 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(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(void) { int cflags = 0, i, result; flint_rand_t state; printf("gcd...."); fflush(stdout); flint_randinit(state); /* Check aliasing of a and c */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_gcd(c, a, b); fmpq_poly_gcd(a, a, b); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags); if (!result) { printf("FAIL (aliasing a, c):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Check aliasing of b and c */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_gcd(c, a, b); fmpq_poly_gcd(b, a, b); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(b, c) && !cflags); if (!result) { printf("FAIL (aliasing b, c):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Generic case when a, b are most likely co-prime ***********************/ /* Verify commutativity and that c is monic */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_gcd(c, a, b); fmpq_poly_gcd(a, b, a); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags && (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c))); if (!result) { printf("FAIL (commutativity #1):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Verify that GCD(a, b) divides a, b */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c, r1, r2; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_init(r1); fmpq_poly_init(r2); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_gcd(c, a, b); if (!fmpq_poly_is_zero(c)) { fmpq_poly_rem(r1, a, c); fmpq_poly_rem(r2, b, c); } result = fmpq_poly_is_zero(r1) && fmpq_poly_is_zero(r2); if (!result) { printf("FAIL (division #1):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); fmpq_poly_clear(r1); fmpq_poly_clear(r2); } /* Case when a, b are not co-prime ***************************************/ /* Verify commutativity and that c is monic */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c, t; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_init(t); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_randtest(t, state, n_randint(state, 50), 20); fmpq_poly_mul(a, a, t); fmpq_poly_mul(b, b, t); fmpq_poly_gcd(c, a, b); fmpq_poly_gcd(a, b, a); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags && (fmpq_poly_is_zero(c) || fmpq_poly_is_monic(c))); if (!result) { printf("FAIL (commutativity #2):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); fmpq_poly_clear(t); } /* Verify that GCD(a, b) divides a, b */ for (i = 0; i < 1000; i++) { fmpq_poly_t a, b, c, r1, r2, t; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_init(r1); fmpq_poly_init(r2); fmpq_poly_init(t); fmpq_poly_randtest(a, state, n_randint(state, 100), 100); fmpq_poly_randtest(b, state, n_randint(state, 100), 100); fmpq_poly_randtest(t, state, n_randint(state, 50), 20); fmpq_poly_mul(a, a, t); fmpq_poly_mul(b, b, t); fmpq_poly_gcd(c, a, b); if (!fmpq_poly_is_zero(c)) { fmpq_poly_rem(r1, a, c); fmpq_poly_rem(r2, b, c); } result = fmpq_poly_is_zero(r1) && fmpq_poly_is_zero(r2); if (!result) { printf("FAIL (division #2):\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %d\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); fmpq_poly_clear(r1); fmpq_poly_clear(r2); fmpq_poly_clear(t); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main(void) { int i, result; ulong cflags = UWORD(0); FLINT_TEST_INIT(state); flint_printf("scalar_div_fmpz...."); fflush(stdout); /* Check aliasing of a and b */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b; fmpz_t n; fmpz_init(n); fmpz_randtest_not_zero(n, state, 200); fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_fmpz(b, a, n); fmpq_poly_scalar_div_fmpz(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 (aliasing):\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); fmpz_print(n); abort(); } fmpz_clear(n); fmpq_poly_clear(a); fmpq_poly_clear(b); } /* Compare with fmpq_poly_scalar_mul_si */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b, c; fmpz_t n1; slong n; n = z_randtest_not_zero(state); fmpz_init(n1); fmpz_set_si(n1, n); fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_fmpz(b, a, n1); fmpq_poly_scalar_div_si(c, a, n); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(b, c) && !cflags); if (!result) { flint_printf("FAIL (comparison with _si):\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpz_print(n1), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); fmpq_poly_debug(c), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpz_clear(n1); fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Check that (a / n1) / n2 == a / (n1 * n2) */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, lhs, rhs; fmpz_t n1, n2, n; fmpz_init(n1); fmpz_init(n2); fmpz_init(n); fmpz_randtest_not_zero(n1, state, 100); fmpz_randtest_not_zero(n2, state, 100); fmpz_mul(n, n1, n2); fmpq_poly_init(a); fmpq_poly_init(lhs); fmpq_poly_init(rhs); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_fmpz(lhs, a, n1); fmpq_poly_scalar_div_fmpz(lhs, lhs, n2); fmpq_poly_scalar_div_fmpz(rhs, a, n); cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1; cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2; result = (fmpq_poly_equal(lhs, rhs) && !cflags); if (!result) { flint_printf("FAIL (a / n1 / n2):\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpz_print(n1), flint_printf("\n\n"); fmpz_print(n2), flint_printf("\n\n"); fmpz_print(n), flint_printf("\n\n"); fmpq_poly_debug(lhs), flint_printf("\n\n"); fmpq_poly_debug(rhs), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpz_clear(n1); fmpz_clear(n2); fmpz_clear(n); fmpq_poly_clear(a); fmpq_poly_clear(lhs); fmpq_poly_clear(rhs); } /* Check that (a + b) / n == a/n + b/n */ for (i = 0; i < 1000 * flint_test_multiplier(); i++) { fmpq_poly_t a, b, lhs, rhs; fmpz_t n; fmpz_init(n); fmpz_randtest_not_zero(n, state, 100); fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(lhs); fmpq_poly_init(rhs); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_fmpz(lhs, a, n); fmpq_poly_scalar_div_fmpz(rhs, b, n); fmpq_poly_add(rhs, lhs, rhs); fmpq_poly_add(lhs, a, b); fmpq_poly_scalar_div_fmpz(lhs, lhs, n); cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1; cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2; result = (fmpq_poly_equal(lhs, rhs) && !cflags); if (!result) { flint_printf("FAIL ((a + b) / n):\n"); fmpq_poly_debug(a), flint_printf("\n\n"); fmpq_poly_debug(b), flint_printf("\n\n"); fmpz_print(n), flint_printf("\n\n"); fmpq_poly_debug(lhs), flint_printf("\n\n"); fmpq_poly_debug(rhs), flint_printf("\n\n"); flint_printf("cflags = %wu\n\n", cflags); abort(); } fmpz_clear(n); fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(lhs); fmpq_poly_clear(rhs); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(void) { int i, result; flint_rand_t state; ulong cflags = 0UL; printf("scalar_div_ui...."); fflush(stdout); flint_randinit(state); /* Check aliasing of a and b */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b; ulong n = n_randtest_not_zero(state); fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_ui(b, a, n); fmpq_poly_scalar_div_ui(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 (a / n1) / n2 = a / (n1 * n2) */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b, c; ulong n1 = n_randbits(state, FLINT_BITS / 2); ulong n2 = n_randbits(state, FLINT_BITS / 2); if (n1 == 0UL) n1 = 1UL; if (n2 == 0UL) n2 = 1UL; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_scalar_div_ui(b, a, n1); fmpq_poly_scalar_div_ui(c, b, n2); fmpq_poly_scalar_div_ui(b, a, n1 * n2); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(b, c) && !cflags); if (!result) { printf("FAIL:\n"); printf(" n1 = %lu, n2 = %lu:\n\n", n1, n2); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }
int main(void) { int i, result; flint_rand_t state; ulong cflags = 0UL; printf("sub...."); fflush(stdout); flint_randinit(state); /* Check a - b = a + neg(b) */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b, c, d; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_init(d); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_sub(c, a, b); fmpq_poly_neg(b, b); fmpq_poly_add(d, a, b); cflags |= fmpq_poly_is_canonical(c) ? 0 : 1; cflags |= fmpq_poly_is_canonical(d) ? 0 : 2; result = (fmpq_poly_equal(c, d) && !cflags); if (!result) { printf("FAIL:\n\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); fmpq_poly_debug(d), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); fmpq_poly_clear(d); } /* Check aliasing of a and c */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_sub(c, a, b); fmpq_poly_sub(a, a, b); cflags |= fmpq_poly_is_canonical(a) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(a, c) && !cflags); if (!result) { printf("FAIL:\n\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } /* Check aliasing of b and c */ for (i = 0; i < 10000; i++) { fmpq_poly_t a, b, c; fmpq_poly_init(a); fmpq_poly_init(b); fmpq_poly_init(c); fmpq_poly_randtest(a, state, n_randint(state, 100), 200); fmpq_poly_randtest(b, state, n_randint(state, 100), 200); fmpq_poly_sub(c, a, b); fmpq_poly_sub(b, a, b); cflags |= fmpq_poly_is_canonical(b) ? 0 : 1; cflags |= fmpq_poly_is_canonical(c) ? 0 : 2; result = (fmpq_poly_equal(b, c) && !cflags); if (!result) { printf("FAIL:\n\n"); fmpq_poly_debug(a), printf("\n\n"); fmpq_poly_debug(b), printf("\n\n"); fmpq_poly_debug(c), printf("\n\n"); printf("cflags = %lu\n\n", cflags); abort(); } fmpq_poly_clear(a); fmpq_poly_clear(b); fmpq_poly_clear(c); } flint_randclear(state); _fmpz_cleanup(); printf("PASS\n"); return 0; }