Example #1
0
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()
{
    slong iter;
    flint_rand_t state;

    flint_printf("legendre_p_ui_root....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 100 * arb_test_multiplier(); iter++)
    {
        ulong n, k;
        slong prec;
        arb_ptr roots, weights;
        arb_poly_t pol;
        arb_t s;
        fmpq_poly_t pol2;

        n = 1 + n_randint(state, 100);
        prec = 20 + n_randint(state, 500);

        roots = _arb_vec_init(n);
        weights = _arb_vec_init(n);
        arb_poly_init(pol);
        fmpq_poly_init(pol2);
        arb_init(s);

        for (k = 0; k < n; k++)
        {
            if (k > n / 2 && n_randint(state, 2))
            {
                arb_neg(roots + k, roots + n - k - 1);
                arb_set(weights + k, weights + n - k - 1);
            }
            else
            {
                arb_hypgeom_legendre_p_ui_root(roots + k, weights + k, n, k, prec);
            }
        }

        arb_poly_product_roots(pol, roots, n, prec);
        /* fmpq_poly_legendre_p(pol2, n); */
        arith_legendre_polynomial(pol2, n);
        arb_set_fmpz(s, pol2->coeffs + n);
        arb_div_fmpz(s, s, pol2->den, prec);
        arb_poly_scalar_mul(pol, pol, s, prec);

        if (!arb_poly_contains_fmpq_poly(pol, pol2))
        {
            flint_printf("FAIL: polynomial containment\n\n");
            flint_printf("n = %wu, prec = %wd\n\n", n, prec);
            flint_printf("pol = "); arb_poly_printd(pol, 30); flint_printf("\n\n");
            flint_printf("pol2 = "); fmpq_poly_print(pol2); flint_printf("\n\n");
            flint_abort();
        }

        arb_zero(s);
        for (k = 0; k < n; k++)
        {
            arb_add(s, s, weights + k, prec);
        }

        if (!arb_contains_si(s, 2))
        {
            flint_printf("FAIL: sum of weights\n\n");
            flint_printf("n = %wu, prec = %wd\n\n", n, prec);
            flint_printf("s = "); arb_printn(s, 30, 0); flint_printf("\n\n");
            flint_abort();
        }

        _arb_vec_clear(roots, n);
        _arb_vec_clear(weights, n);
        arb_poly_clear(pol);
        fmpq_poly_clear(pol2);
        arb_clear(s);
    }

    for (iter = 0; iter < 500 * arb_test_multiplier(); iter++)
    {
        arb_t x1, x2, w1, w2;
        ulong n, k;
        slong prec1, prec2;

        arb_init(x1);
        arb_init(x2);
        arb_init(w1);
        arb_init(w2);

        n = 1 + n_randtest(state) % 100000;
        if (n_randint(state, 2) || n == 1)
            k = n_randtest(state) % n;
        else
            k = n / 2 - (n_randtest(state) % (n / 2));

        prec1 = 2 + n_randtest(state) % 2000;
        prec2 = 2 + n_randtest(state) % 2000;

        arb_hypgeom_legendre_p_ui_root(x1, w1, n, k, prec1);
        if (n_randint(state, 10) == 0)
            arb_hypgeom_legendre_p_ui_root(x1, NULL, n, k, prec1);

        arb_hypgeom_legendre_p_ui_root(x2, w2, n, k, prec2);

        if (!arb_overlaps(x1, x2) || !arb_overlaps(w1, w2))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("n = %wu, k = %wu, prec1 = %wd, prec2 = %wd\n\n", n, k, prec1, prec2);
            flint_printf("x1 = "); arb_printn(x1, 100, 0); flint_printf("\n\n");
            flint_printf("x2 = "); arb_printn(x2, 100, 0); flint_printf("\n\n");
            flint_printf("w1 = "); arb_printn(w1, 100, 0); flint_printf("\n\n");
            flint_printf("w2 = "); arb_printn(w2, 100, 0); flint_printf("\n\n");
            flint_abort();
        }

        if (arb_rel_accuracy_bits(x1) < prec1 - 3 || arb_rel_accuracy_bits(w1) < prec1 - 3)
        {
            flint_printf("FAIL: accuracy\n\n");
            flint_printf("n = %wu, k = %wu, prec1 = %wd\n\n", n, k, prec1);
            flint_printf("acc(x1) = %wd, acc(w1) = %wd\n\n", arb_rel_accuracy_bits(x1), arb_rel_accuracy_bits(w1));
            flint_printf("x1 = "); arb_printn(x1, prec1, ARB_STR_CONDENSE * 30); flint_printf("\n\n");
            flint_printf("w1 = "); arb_printn(w1, prec1, ARB_STR_CONDENSE * 30); flint_printf("\n\n");
            flint_abort();
        }

        if (arb_rel_accuracy_bits(x2) < prec2 - 3 || arb_rel_accuracy_bits(w2) < prec2 - 3)
        {
            flint_printf("FAIL: accuracy 2\n\n");
            flint_printf("n = %wu, k = %wu, prec2 = %wd\n\n", n, k, prec2);
            flint_printf("acc(x2) = %wd, acc(w2) = %wd\n\n", arb_rel_accuracy_bits(x2), arb_rel_accuracy_bits(w2));
            flint_printf("x2 = "); arb_printn(x2, prec2, ARB_STR_CONDENSE * 30); flint_printf("\n\n");
            flint_printf("w2 = "); arb_printn(w2, prec2, ARB_STR_CONDENSE * 30); flint_printf("\n\n");
            flint_abort();
        }

        arb_clear(x1);
        arb_clear(x2);
        arb_clear(w1);
        arb_clear(w2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #3
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;
}
Example #4
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("mullow_block....");
    fflush(stdout);

    flint_randinit(state);

    /* compare with fmpq_poly */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong qbits1, qbits2, rbits1, rbits2, rbits3, trunc;
        fmpq_poly_t A, B, C;
        arb_poly_t a, b, c, d;

        qbits1 = 2 + n_randint(state, 1000);
        qbits2 = 2 + n_randint(state, 1000);
        rbits1 = 2 + n_randint(state, 1000);
        rbits2 = 2 + n_randint(state, 1000);
        rbits3 = 2 + n_randint(state, 1000);
        trunc = n_randint(state, 100);

        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, 1 + n_randint(state, 100), qbits1);
        fmpq_poly_randtest(B, state, 1 + n_randint(state, 100), qbits2);
        fmpq_poly_mullow(C, A, B, trunc);

        arb_poly_set_fmpq_poly(a, A, rbits1);
        arb_poly_set_fmpq_poly(b, B, rbits2);
        arb_poly_mullow_block(c, a, b, trunc, rbits3);

        if (!arb_poly_contains_fmpq_poly(c, C))
        {
            flint_printf("FAIL\n\n");
            flint_printf("bits3 = %wd\n", rbits3);
            flint_printf("trunc = %wd\n", trunc);

            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");

            abort();
        }

        arb_poly_set(d, a);
        arb_poly_mullow_block(d, d, b, trunc, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        arb_poly_set(d, b);
        arb_poly_mullow_block(d, a, d, trunc, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        /* test squaring */
        arb_poly_set(b, a);
        arb_poly_mullow_block(c, a, b, trunc, rbits3);
        arb_poly_mullow_block(d, a, a, trunc, rbits3);
        if (!arb_poly_overlaps(c, d))  /* not guaranteed to be identical */
        {
            flint_printf("FAIL (squaring)\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();
        }

        arb_poly_mullow_block(a, a, a, trunc, rbits3);
        if (!arb_poly_equal(d, a))
        {
            flint_printf("FAIL (aliasing, squaring)\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("d = "); arb_poly_printd(d, 15); flint_printf("\n\n");

            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);
    }

    for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++)
    {
        slong rbits1, rbits2, rbits3, trunc;
        arb_poly_t a, b, c, ab, ac, bc, abc, abc2;

        rbits1 = 2 + n_randint(state, 300);
        rbits2 = 2 + n_randint(state, 300);
        rbits3 = 2 + n_randint(state, 300);
        trunc = n_randint(state, 100);

        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);
        arb_poly_init(ab);
        arb_poly_init(ac);
        arb_poly_init(bc);
        arb_poly_init(abc);
        arb_poly_init(abc2);

        arb_poly_randtest(a, state, 1 + n_randint(state, 100), rbits1, 1 + n_randint(state, 100));
        arb_poly_randtest(b, state, 1 + n_randint(state, 100), rbits2, 1 + n_randint(state, 100));
        arb_poly_randtest(c, state, 1 + n_randint(state, 100), rbits2, 1 + n_randint(state, 100));

        /* check a*(b+c) = a*b + a*c */
        arb_poly_mullow_block(ab, a, b, trunc, rbits3);
        arb_poly_mullow_block(ac, a, c, trunc, rbits3);
        arb_poly_add(abc, ab, ac, rbits3);

        arb_poly_add(bc, b, c, rbits3);
        arb_poly_mullow_block(abc2, a, bc, trunc, rbits3);

        if (!arb_poly_overlaps(abc, abc2))
        {
            flint_printf("FAIL (a*(b+c) = a*b + a*c) \n\n");
            flint_printf("bits3 = %wd\n", rbits3);
            flint_printf("trunc = %wd\n", trunc);

            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 (b+c)^2 = b^2 + 2bc + c^2 */
        arb_poly_mullow_block(a, b, c, trunc, rbits3);
        arb_poly_scalar_mul_2exp_si(a, a, 1);
        arb_poly_mullow_block(abc, b, b, trunc, rbits3);
        arb_poly_mullow_block(abc2, c, c, trunc, rbits3);
        arb_poly_add(abc, abc, a, rbits3);
        arb_poly_add(abc, abc, abc2, rbits3);

        arb_poly_mullow_block(abc2, bc, bc, trunc, rbits3);

        if (!arb_poly_overlaps(abc, abc2))
        {
            flint_printf("FAIL ((b+c)^2 = b^2 + 2bc + c^2) \n\n");
            flint_printf("bits3 = %wd\n", rbits3);
            flint_printf("trunc = %wd\n", trunc);

            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("abc  = "); arb_poly_printd(abc, 15); flint_printf("\n\n");
            flint_printf("abc2 = "); arb_poly_printd(abc2, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_clear(a);
        arb_poly_clear(b);
        arb_poly_clear(c);
        arb_poly_clear(ab);
        arb_poly_clear(ac);
        arb_poly_clear(bc);
        arb_poly_clear(abc);
        arb_poly_clear(abc2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #5
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("mullow_transpose....");
    fflush(stdout);

    flint_randinit(state);

    /* compare with fmpq_poly */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong qbits1, qbits2, rbits1, rbits2, rbits3, trunc;
        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);
        trunc = n_randint(state, 10);

        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, 10), qbits1);
        fmpq_poly_randtest(B, state, 1 + n_randint(state, 10), qbits2);

        fmpq_poly_mullow(C, A, B, trunc);

        acb_poly_set_fmpq_poly(a, A, rbits1);
        acb_poly_set_fmpq_poly(b, B, rbits2);

        acb_poly_mullow_transpose(c, a, b, trunc, rbits3);

        if (!acb_poly_contains_fmpq_poly(c, C))
        {
            flint_printf("FAIL\n\n");
            flint_printf("bits3 = %wd\n", rbits3);
            flint_printf("trunc = %wd\n", trunc);

            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");

            abort();
        }

        acb_poly_set(d, a);
        acb_poly_mullow_transpose(d, d, b, trunc, rbits3);
        if (!acb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        acb_poly_set(d, b);
        acb_poly_mullow_transpose(d, a, d, trunc, rbits3);
        if (!acb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        /* test squaring */
        acb_poly_set(b, a);
        acb_poly_mullow_transpose(c, a, b, trunc, rbits3);
        acb_poly_mullow_transpose(d, a, a, trunc, rbits3);
        if (!acb_poly_overlaps(c, d))  /* not guaranteed to be identical */
        {
            flint_printf("FAIL (squaring)\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_mullow_transpose(a, a, a, trunc, rbits3);
        if (!acb_poly_equal(d, a))
        {
            flint_printf("FAIL (aliasing, squaring)\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("d = "); acb_poly_printd(d, 15); flint_printf("\n\n");

            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);
    }

    /* compare with classical */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong bits, trunc;
        acb_poly_t a, b, ab, ab2;

        bits = 2 + n_randint(state, 200);
        trunc = n_randint(state, 10);

        acb_poly_init(a);
        acb_poly_init(b);
        acb_poly_init(ab);
        acb_poly_init(ab2);

        acb_poly_randtest(a, state, 1 + n_randint(state, 10), bits, 5);
        acb_poly_randtest(b, state, 1 + n_randint(state, 10), bits, 5);

        acb_poly_mullow_classical(ab, a, b, trunc, bits);
        acb_poly_mullow_transpose(ab2, a, b, trunc, bits);

        if (!acb_poly_overlaps(ab, ab2))
        {
            flint_printf("FAIL\n\n");
            flint_printf("bits = %wd\n", bits);
            flint_printf("trunc = %wd\n", trunc);

            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("ab = "); acb_poly_printd(ab, 15); flint_printf("\n\n");
            flint_printf("ab2 = "); acb_poly_printd(ab2, 15); flint_printf("\n\n");

            abort();
        }

        acb_poly_clear(a);
        acb_poly_clear(b);
        acb_poly_clear(ab);
        acb_poly_clear(ab2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #6
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("evaluate_vec_fast....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong i, n, qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t F;
        fmpq * X, * Y;
        arb_poly_t f;
        arb_ptr x, y;

        qbits1 = 2 + n_randint(state, 100);
        qbits2 = 2 + n_randint(state, 100);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        rbits3 = 2 + n_randint(state, 200);

        n = n_randint(state, 10);

        fmpq_poly_init(F);
        X = _fmpq_vec_init(n);
        Y = _fmpq_vec_init(n);

        arb_poly_init(f);
        x = _arb_vec_init(n);
        y = _arb_vec_init(n);

        fmpq_poly_randtest(F, state, 1 + n_randint(state, 20), qbits1);
        for (i = 0; i < n; i++)
            fmpq_randtest(X + i, state, qbits2);
        for (i = 0; i < n; i++)
            fmpq_poly_evaluate_fmpq(Y + i, F, X + i);

        arb_poly_set_fmpq_poly(f, F, rbits1);
        for (i = 0; i < n; i++)
            arb_set_fmpq(x + i, X + i, rbits2);
        arb_poly_evaluate_vec_fast(y, f, x, n, rbits3);

        for (i = 0; i < n; i++)
        {
            if (!arb_contains_fmpq(y + i, Y + i))
            {
                flint_printf("FAIL (%wd of %wd)\n\n", i, n);

                flint_printf("F = "); fmpq_poly_print(F); flint_printf("\n\n");
                flint_printf("X = "); fmpq_print(X + i); flint_printf("\n\n");
                flint_printf("Y = "); fmpq_print(Y + i); flint_printf("\n\n");

                flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n");
                flint_printf("x = "); arb_printd(x + i, 15); flint_printf("\n\n");
                flint_printf("y = "); arb_printd(y + i, 15); flint_printf("\n\n");

                abort();
            }
        }

        fmpq_poly_clear(F);
        _fmpq_vec_clear(X, n);
        _fmpq_vec_clear(Y, n);

        arb_poly_clear(f);
        _arb_vec_clear(x, n);
        _arb_vec_clear(y, n);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #7
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;
}
Example #8
0
int main()
{
    long iter;
    flint_rand_t state;

    printf("compose_series_brent_kung....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 3000; iter++)
    {
        long qbits1, qbits2, rbits1, rbits2, rbits3, n;
        fmpq_poly_t A, B, C;
        fmpcb_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);
        n = 2 + n_randint(state, 25);

        fmpq_poly_init(A);
        fmpq_poly_init(B);
        fmpq_poly_init(C);

        fmpcb_poly_init(a);
        fmpcb_poly_init(b);
        fmpcb_poly_init(c);
        fmpcb_poly_init(d);

        fmpq_poly_randtest(A, state, 1 + n_randint(state, 25), qbits1);
        fmpq_poly_randtest(B, state, 1 + n_randint(state, 25), qbits2);
        fmpq_poly_set_coeff_ui(B, 0, 0);
        fmpq_poly_compose_series(C, A, B, n);

        fmpcb_poly_set_fmpq_poly(a, A, rbits1);
        fmpcb_poly_set_fmpq_poly(b, B, rbits2);
        fmpcb_poly_compose_series_brent_kung(c, a, b, n, rbits3);

        if (!fmpcb_poly_contains_fmpq_poly(c, C))
        {
            printf("FAIL\n\n");
            printf("n = %ld, bits3 = %ld\n", n, rbits3);

            printf("A = "); fmpq_poly_print(A); printf("\n\n");
            printf("B = "); fmpq_poly_print(B); printf("\n\n");
            printf("C = "); fmpq_poly_print(C); printf("\n\n");

            printf("a = "); fmpcb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); fmpcb_poly_printd(b, 15); printf("\n\n");
            printf("c = "); fmpcb_poly_printd(c, 15); printf("\n\n");

            abort();
        }

        fmpcb_poly_set(d, a);
        fmpcb_poly_compose_series_brent_kung(d, d, b, n, rbits3);
        if (!fmpcb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        fmpcb_poly_set(d, b);
        fmpcb_poly_compose_series_brent_kung(d, a, d, n, rbits3);
        if (!fmpcb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(C);

        fmpcb_poly_clear(a);
        fmpcb_poly_clear(b);
        fmpcb_poly_clear(c);
        fmpcb_poly_clear(d);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #9
0
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;
}
Example #10
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("acos_series....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A;
        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, 30);
        n = 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(A, state, m, qbits);
        arb_poly_set_fmpq_poly(a, A, rbits1);

        arb_poly_randtest(b, state, 1 + n_randint(state, 30), rbits1, 5);

        arb_poly_acos_series(b, a, n, rbits2);

        /* Check cos(acos(x)) = x */
        arb_poly_sin_cos_series_basecase(d, c, b, n, rbits2, 0);

        fmpq_poly_truncate(A, n);
        if (!arb_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 = "); 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_acos_series(a, a, n, rbits2);
        if (!arb_poly_equal(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;
}
Example #11
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;
}
Example #12
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("atan_series....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        slong m, n, qbits, rbits1, rbits2;
        fmpq_poly_t A;
        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, 30);
        n = 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(A, state, m, qbits);
        arb_poly_set_fmpq_poly(a, A, rbits1);

        arb_poly_randtest(b, state, 1 + n_randint(state, 30), rbits1, 5);

        arb_poly_atan_series(b, a, n, rbits2);

        /* Check 2 atan(x) = atan(2x/(1-x^2)) + C */
        arb_poly_mullow(c, a, a, n, rbits2);
        arb_poly_one(d);
        arb_poly_sub(c, d, c, rbits2);
        arb_poly_add(d, a, a, rbits2);

        if (arb_poly_length(c) != 0)
        {
            arb_poly_div_series(c, d, c, n, rbits2);
            arb_poly_atan_series(c, c, n, rbits2);
            arb_poly_add(d, b, b, rbits2);

            /* TODO: also check the first coefficient */
            arb_poly_set_coeff_si(c, 0, 0);
            arb_poly_set_coeff_si(d, 0, 0);

            if (!arb_poly_overlaps(c, d))
            {
                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");

                abort();
            }
        }

        arb_poly_atan_series(a, a, n, rbits2);
        if (!arb_poly_equal(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;
}
Example #13
0
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_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;
}
Example #15
0
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;
}
Example #16
0
int main()
{
    long iter;
    flint_rand_t state;

    printf("sin_cos_series_tangent....");
    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, c, d, e;

        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);
        fmpq_poly_init(B);
        fmprb_poly_init(a);
        fmprb_poly_init(b);
        fmprb_poly_init(c);
        fmprb_poly_init(d);
        fmprb_poly_init(e);

        fmpq_poly_randtest(A, state, m, qbits);
        fmprb_poly_set_fmpq_poly(a, A, rbits1);

        fmprb_poly_sin_cos_series_tangent(b, c, a, n, rbits2);

        /* Check sin(x)^2 + cos(x)^2 = 1 */
        fmprb_poly_mullow(d, b, b, n, rbits2);
        fmprb_poly_mullow(e, c, c, n, rbits2);
        fmprb_poly_add(d, d, e, rbits2);

        fmpq_poly_one(B);
        if (!fmprb_poly_contains_fmpq_poly(d, B))
        {
            printf("FAIL\n\n");
            printf("bits2 = %ld\n", rbits2);

            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_set(d, a);
        fmprb_poly_sin_cos_series_tangent(d, c, d, n, rbits2);
        if (!fmprb_poly_equal(b, d))
        {
            printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        fmprb_poly_set(d, a);
        fmprb_poly_sin_cos_series_tangent(b, d, d, n, rbits2);
        if (!fmprb_poly_equal(c, d))
        {
            printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmprb_poly_clear(a);
        fmprb_poly_clear(b);
        fmprb_poly_clear(c);
        fmprb_poly_clear(d);
        fmprb_poly_clear(e);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #17
0
File: t-sub.c Project: certik/arb
int main()
{
    long iter;
    flint_rand_t state;

    printf("sub....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        long qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t A, B, C;
        fmprb_poly_t a, b, c;

        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);

        fmprb_poly_init(a);
        fmprb_poly_init(b);
        fmprb_poly_init(c);

        fmpq_poly_randtest(A, state, 1 + n_randint(state, 10), qbits1);
        fmpq_poly_randtest(B, state, 1 + n_randint(state, 10), qbits2);
        fmpq_poly_sub(C, A, B);

        fmprb_poly_set_fmpq_poly(a, A, rbits1);
        fmprb_poly_set_fmpq_poly(b, B, rbits2);
        fmprb_poly_sub(c, a, b, rbits3);

        if (!fmprb_poly_contains_fmpq_poly(c, C))
        {
            printf("FAIL\n\n");
            printf("bits3 = %ld\n", rbits3);

            printf("A = "); fmpq_poly_print(A); printf("\n\n");
            printf("B = "); fmpq_poly_print(B); printf("\n\n");
            printf("C = "); fmpq_poly_print(C); 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();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);
        fmpq_poly_clear(C);

        fmprb_poly_clear(a);
        fmprb_poly_clear(b);
        fmprb_poly_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #18
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("mul....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        slong qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t A, B, C;
        arb_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);

        arb_poly_init(a);
        arb_poly_init(b);
        arb_poly_init(c);
        arb_poly_init(d);

        fmpq_poly_randtest(A, state, 1 + n_randint(state, 10), qbits1);
        fmpq_poly_randtest(B, state, 1 + n_randint(state, 10), qbits2);
        fmpq_poly_mul(C, A, B);

        arb_poly_set_fmpq_poly(a, A, rbits1);
        arb_poly_set_fmpq_poly(b, B, rbits2);
        arb_poly_mul(c, a, b, rbits3);

        if (!arb_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 = "); 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();
        }

        arb_poly_set(d, a);
        arb_poly_mul(d, d, b, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 1)\n\n");
            abort();
        }

        arb_poly_set(d, b);
        arb_poly_mul(d, a, d, rbits3);
        if (!arb_poly_equal(d, c))
        {
            flint_printf("FAIL (aliasing 2)\n\n");
            abort();
        }

        /* test squaring */
        arb_poly_set(b, a);
        arb_poly_mul(c, a, b, rbits3);
        arb_poly_mul(d, a, a, rbits3);
        if (!arb_poly_overlaps(c, d))  /* not guaranteed to be identical */
        {
            flint_printf("FAIL (squaring)\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();
        }

        arb_poly_mul(a, a, a, rbits3);
        if (!arb_poly_equal(d, a))
        {
            flint_printf("FAIL (aliasing, squaring)\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("d = "); arb_poly_printd(d, 15); flint_printf("\n\n");

            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;
}
Example #19
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("revert_series....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        slong qbits1, rbits1, rbits2, n;
        fmpq_poly_t A, B;
        acb_poly_t a, b, c;

        qbits1 = 2 + n_randint(state, 200);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        n = 2 + n_randint(state, 25);

        fmpq_poly_init(A);
        fmpq_poly_init(B);

        acb_poly_init(a);
        acb_poly_init(b);
        acb_poly_init(c);

        do {
            fmpq_poly_randtest(A, state, 1 + n_randint(state, 25), qbits1);
            fmpq_poly_set_coeff_ui(A, 0, 0);
        } while (A->length < 2 || fmpz_is_zero(A->coeffs + 1));

        fmpq_poly_revert_series(B, A, n);

        acb_poly_set_fmpq_poly(a, A, rbits1);
        acb_poly_revert_series(b, a, n, rbits2);

        if (!acb_poly_contains_fmpq_poly(b, B))
        {
            flint_printf("FAIL\n\n");
            flint_printf("n = %wd, bits2 = %wd\n", 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("a = "); acb_poly_printd(a, 15); flint_printf("\n\n");
            flint_printf("b = "); acb_poly_printd(b, 15); flint_printf("\n\n");

            abort();
        }

        acb_poly_set(c, a);
        acb_poly_revert_series(c, c, n, rbits2);
        if (!acb_poly_equal(c, b))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        fmpq_poly_clear(A);
        fmpq_poly_clear(B);

        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;
    FLINT_TEST_INIT(state);

    flint_printf("resultant_div....");
    fflush(stdout);

    for (i = 0; i < 50; i++)
    {
        fmpq_poly_t f, g, h, p;
        fmpq_t x, y, z, zz;
        fmpz_t den;
        slong nbits;

        fmpq_poly_init(f);
        fmpq_poly_init(g);
        fmpq_poly_init(p);
        fmpq_poly_init(h);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);
        fmpq_init(zz);
        
        fmpz_init(den);

        fmpq_poly_randtest(f, state, n_randint(state, 50), 100);
        fmpq_poly_randtest(g, state, n_randint(state, 50), 100);
        fmpq_poly_randtest(h, state, n_randint(state, 50), 100);

        fmpz_set(den, fmpq_poly_denref(f));
        fmpq_poly_scalar_mul_fmpz(f, f, den);

        fmpz_set(den, fmpq_poly_denref(g));
        fmpq_poly_scalar_mul_fmpz(g, g, den);

        fmpz_set(den, fmpq_poly_denref(h));
        fmpq_poly_scalar_mul_fmpz(h, h, den);

        fmpq_poly_mul(p, f, g);

        fmpq_poly_resultant(x, f, h);
        
        if (!fmpz_is_one(fmpq_denref(x)))
        {
            flint_printf("FAIL resultant not integral\n");
            flint_printf("f = "), fmpq_poly_print(f), flint_printf("\n\n");
            flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
            flint_printf("y = "), fmpq_print(y), flint_printf("\n\n");
            abort();
        }

        fmpq_poly_resultant(y, g, h);
        
        if (!fmpz_is_one(fmpq_denref(y)))
        {
            flint_printf("FAIL resultant not integral\n");
            flint_printf("h = "), fmpq_poly_print(f), flint_printf("\n\n");
            flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
            flint_printf("z = "), fmpq_print(y), flint_printf("\n\n");
            abort();
        }

        fmpq_poly_resultant(z, p, h);

        if (!fmpz_is_one(fmpq_denref(z)))
        {
            flint_printf("FAIL resultant not integral\n");
            flint_printf("p = "), fmpq_poly_print(f), flint_printf("\n\n");
            flint_printf("g = "), fmpq_poly_print(g), flint_printf("\n\n");
            flint_printf("y = "), fmpq_print(y), flint_printf("\n\n");
            abort();
        }

        if (fmpq_is_zero(z)) 
        {
            fmpq_poly_clear(f);
            fmpq_poly_clear(g);
            fmpq_poly_clear(h);
            fmpq_poly_clear(p);

            fmpq_clear(x);
            fmpq_clear(y);
            fmpq_clear(z);
            fmpq_clear(zz);
        
            fmpz_clear(den);
            continue;
        }
    
        nbits = (slong)fmpz_bits(fmpq_numref(y)) + 1;

        fmpq_poly_resultant_div(z, p, h, fmpq_numref(x), nbits);
        fmpq_poly_resultant(zz, p, h);

        result = fmpq_equal(z, y);
        
        if (!result)
        {
            flint_printf("FAIL (res(p, g)/div == res(p, g)/div:\n");
            flint_printf("p = "), fmpq_poly_print_pretty(p, "x"), flint_printf("\n\n");
            flint_printf("h = "), fmpq_poly_print_pretty(h, "x"), flint_printf("\n\n");
            flint_printf("res(p, h) = "), fmpq_print(zz), flint_printf("\n\n");
            flint_printf("res(p, h) = "), fmpq_print(x), flint_printf(" * "), fmpq_print(y), flint_printf("\n\n");
            flint_printf("supplied divisor = "), fmpq_print(x), flint_printf("\n\n");
            flint_printf("nbits = %wu\n\n", nbits);
            flint_printf("divisor found = "), fmpq_print(z), flint_printf("\n\n");
            flint_printf("correct result = "), fmpq_print(y), flint_printf("\n\n");
            abort();
        }
        
        fmpq_poly_clear(f);
        fmpq_poly_clear(g);
        fmpq_poly_clear(h);
        fmpq_poly_clear(p);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
        fmpq_clear(zz);
        
        fmpz_clear(den);
    }

    FLINT_TEST_CLEANUP(state);
    
    flint_printf("PASS\n");
    return 0;
}
Example #21
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("evaluate_horner....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; 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_horner(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_horner(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;
}
Example #22
0
int main()
{
    slong iter;

    FLINT_TEST_INIT(state);

    {
        ulong k;

        arb_t a,b;
        arf_t c,d;

        fmpq_poly_t p;

        arb_init(a);
        arb_init(b);
        arf_init(c);
        arf_init(d);

        /* x+1 */
        fmpq_poly_init(p);
        fmpq_poly_set_coeff_si(p, 0, 1);
        fmpq_poly_set_coeff_si(p, 1, 1);
        for (iter = 0; iter < 5000; iter++)
        {
            k = n_randint(state, 10000);
            arb_set_si(a, k);
            fmpq_poly_evaluate_arb(b, p, a, 30 + n_randint(state, 100));
            if (!arb_equal_si(b, k + 1))
            {
                printf("FAIL (fmpq_poly_evaluate_arb):\n");
                printf("a = "); arb_print(a); printf("\n");
                printf("b = "); arb_print(b); printf("\n");
                printf("p = "); fmpq_poly_print(p); printf("\n");
                abort();
            }
            arf_set_si(c, k);
            fmpq_poly_evaluate_arf(d, p, c, 30 + n_randint(state, 100));
            if (!arf_equal_si(d, k + 1))
            {
                printf("FAIL (fmpq_poly_evaluate_arf):\n");
                printf("c = "); arf_print(c); printf("\n");
                printf("d = "); arf_print(d); printf("\n");
                printf("p = "); fmpq_poly_print(p); printf("\n");
                abort();
            }
        }

        /* x^2 */
        fmpq_poly_zero(p);
        fmpq_poly_set_coeff_si(p, 2, 1);
        for (iter = 0; iter < 1000; iter++)
        {
            k = n_randint(state, 10000);

            arb_set_si(a, k);
            fmpq_poly_evaluate_arb(b, p, a, 30 + n_randint(state, 100));
            if (!arb_equal_si(b, k * k))
            {
                printf("Error (test_fmpq_poly_evaluate_arb):\n");
                printf("a = "); arb_print(a); printf("\n");
                printf("b = "); arb_print(b); printf("\n");
                printf("p = "); fmpq_poly_print(p); printf("\n");
                abort();
            }

            arf_set_si(c, k);
            fmpq_poly_evaluate_arf(d, p, c, 30 + n_randint(state, 100));
            if (!arf_equal_si(d, k * k))
            {
                printf("Error (test_fmpq_poly_evaluate_arf):\n");
                printf("c = "); arf_print(c); printf("\n");
                printf("d = "); arf_print(d); printf("\n");
                printf("p = "); fmpq_poly_print(p); printf("\n");
                abort();
            }
        }

        fmpq_poly_clear(p);
        arb_clear(a);
        arb_clear(b);
        arf_clear(c);
        arf_clear(d);
    }

    /* check evaluate_arb agains exact evaluate_fmpq */
    for (iter = 0; iter < 1000; iter++)
    {
        fmpq_poly_t p;
        fmpq_t x,y;
        arb_t a,b;

        fmpq_poly_init(p);
        fmpq_init(x);
        fmpq_init(y);
        arb_init(a);
        arb_init(b);

        fmpq_poly_randtest(p, state, 1 + n_randint(state,100), 10);
        fmpq_randtest(x, state, 10);
        arb_set_fmpq(a, x, 64);

        fmpq_poly_evaluate_fmpq(y, p, x);
        fmpq_poly_evaluate_arb(b, p, a, 60);

        if (!arb_contains_fmpq(b, y))
        {
            printf("FAIL (y not in b):\n");
            printf("p = "); fmpq_poly_print(p); printf("\n");
            printf("x = "); fmpq_print(x); printf("\n");
            printf("y = "); fmpq_print(y); printf("\n");
            printf("a = "); arb_print(a); printf("\n");
            printf("b = "); arb_print(b); printf("\n");
            abort();
        }

        fmpq_poly_evaluate_arb(a, p, a, 60);
        if (!arb_equal(a,b))
        {
            printf("FAIL (a not equal b):\n");
            printf("p = "); fmpq_poly_print(p); printf("\n");
            printf("x = "); fmpq_print(x); printf("\n");
            printf("y = "); fmpq_print(y); printf("\n");
            printf("a = "); arb_print(a); printf("\n");
            printf("b = "); arb_print(b); printf("\n");
            abort();
        }

        fmpq_poly_clear(p);
        fmpq_clear(x);
        fmpq_clear(y);
        arb_clear(a);
        arb_clear(b);
    }


    /* test aliasing */
    for (iter = 0; iter < 1000; iter++)
    {
        fmpq_poly_t p;

        arb_t a,b;
        arf_t c,d;

        fmpq_poly_init(p);
        arb_init(a);
        arb_init(b);
        arf_init(c);
        arf_init(d);

        fmpq_poly_randtest(p, state, 1 + n_randint(state,100), 10);
        arb_randtest(a, state, 60, 10);
        arb_randtest(b, state, 60, 10);
        arf_randtest(c, state, 60, 10);
        arf_randtest(d, state, 60, 10);

        fmpq_poly_evaluate_arb(b, p, a, 60);
        fmpq_poly_evaluate_arb(a, p, a, 60);

        if (!arb_equal(a, b))
        {
            printf("FAIL (a not equal b):\n");
            printf("p = "); fmpq_poly_print(p); printf("\n");
            printf("a = "); arb_print(a); printf("\n");
            printf("b = "); arb_print(b); printf("\n");
            abort();
        }

        fmpq_poly_evaluate_arf(d, p, c, 60);
        fmpq_poly_evaluate_arf(c, p, c, 60);

        if (!arf_equal(c, d))
        {
            printf("FAIL (c not equal d):\n");
            printf("p = "); fmpq_poly_print(p); printf("\n");
            printf("c = "); arf_print(c); printf("\n");
            printf("d = "); arf_print(d); printf("\n");
        }

        fmpq_poly_clear(p);
        arb_clear(a);
        arb_clear(b);
        arf_clear(c);
        arf_clear(d);
    }

    FLINT_TEST_CLEANUP(state);

    return 0;
}
Example #23
0
int main()
{
    long iter;
    flint_rand_t state;

    printf("interpolate_fast....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        long i, n, qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t P;
        arb_poly_t R, S;
        fmpq_t t, u;
        arb_ptr xs, ys;

        fmpq_poly_init(P);
        arb_poly_init(R);
        arb_poly_init(S);
        fmpq_init(t);
        fmpq_init(u);

        qbits1 = 2 + n_randint(state, 200);
        qbits2 = 2 + n_randint(state, 5);
        rbits1 = 2 + n_randint(state, 200);
        rbits2 = 2 + n_randint(state, 200);
        rbits3 = 2 + n_randint(state, 200);

        fmpq_poly_randtest(P, state, 1 + n_randint(state, 20), qbits1);
        n = P->length;

        xs = _arb_vec_init(n);
        ys = _arb_vec_init(n);

        arb_poly_set_fmpq_poly(R, P, rbits1);

        if (n > 0)
        {
            fmpq_randtest(t, state, qbits2);
            arb_set_fmpq(xs, t, rbits2);

            for (i = 1; i < n; i++)
            {
                fmpq_randtest_not_zero(u, state, qbits2);
                fmpq_abs(u, u);
                fmpq_add(t, t, u);
                arb_set_fmpq(xs + i, t, rbits2);
            }
        }

        for (i = 0; i < n; i++)
            arb_poly_evaluate(ys + i, R, xs + i, rbits2);

        arb_poly_interpolate_fast(S, xs, ys, n, rbits3);

        if (!arb_poly_contains_fmpq_poly(S, P))
        {
            printf("FAIL:\n");
            printf("P = "); fmpq_poly_print(P); printf("\n\n");
            printf("R = "); arb_poly_printd(R, 15); printf("\n\n");
            printf("S = "); arb_poly_printd(S, 15); printf("\n\n");
            abort();
        }

        fmpq_poly_clear(P);
        arb_poly_clear(R);
        arb_poly_clear(S);
        fmpq_clear(t);
        fmpq_clear(u);
        _arb_vec_clear(xs, n);
        _arb_vec_clear(ys, n);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #24
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;
        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;
}
Example #25
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;
}
Example #26
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;
}