Example #1
0
void
acb_mat_set_fmpq_mat(acb_mat_t dest, const fmpq_mat_t src, slong prec)
{
    slong i, j;

    if (acb_mat_ncols(dest) != 0)
    {
        for (i = 0; i < acb_mat_nrows(dest); i++)
            for (j = 0; j < acb_mat_ncols(dest); j++)
                acb_set_fmpq(acb_mat_entry(dest, i, j),
                    fmpq_mat_entry(src, i, j), prec);
    }
}
Example #2
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        long qbits1, qbits2, rbits1, rbits2, rbits3;
        fmpq_poly_t F;
        fmpq_t X, Y;
        acb_poly_t f;
        acb_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);

        acb_poly_init(f);
        acb_init(x);
        acb_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);

        acb_poly_set_fmpq_poly(f, F, rbits1);
        acb_set_fmpq(x, X, rbits2);
        acb_poly_evaluate(y, f, x, rbits3);

        if (!acb_contains_fmpq(y, Y))
        {
            printf("FAIL\n\n");

            printf("F = "); fmpq_poly_print(F); printf("\n\n");
            printf("X = "); fmpq_print(X); printf("\n\n");
            printf("Y = "); fmpq_print(Y); printf("\n\n");

            printf("f = "); acb_poly_printd(f, 15); printf("\n\n");
            printf("x = "); acb_printd(x, 15); printf("\n\n");
            printf("y = "); acb_printd(y, 15); printf("\n\n");

            abort();
        }

        /* aliasing */
        acb_poly_evaluate(x, f, x, rbits3);
        if (!acb_contains_fmpq(x, Y))
        {
            printf("FAIL (aliasing)\n\n");
            abort();
        }

        fmpq_poly_clear(F);
        fmpq_clear(X);
        fmpq_clear(Y);

        acb_poly_clear(f);
        acb_clear(x);
        acb_clear(y);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #3
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;
        acb_poly_t R, S;
        fmpq_t t, u;
        acb_ptr xs, ys;

        fmpq_poly_init(P);
        acb_poly_init(R);
        acb_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 = _acb_vec_init(n);
        ys = _acb_vec_init(n);

        acb_poly_set_fmpq_poly(R, P, rbits1);

        if (n > 0)
        {
            fmpq_randtest(t, state, qbits2);
            acb_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);
                acb_set_fmpq(xs + i, t, rbits2);
            }
        }

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

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

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

        fmpq_poly_clear(P);
        acb_poly_clear(R);
        acb_poly_clear(S);
        fmpq_clear(t);
        fmpq_clear(u);
        _acb_vec_clear(xs, n);
        _acb_vec_clear(ys, n);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #4
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;
        acb_poly_t f;
        acb_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);

        acb_poly_init(f);
        x = _acb_vec_init(n);
        y = _acb_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);

        acb_poly_set_fmpq_poly(f, F, rbits1);
        for (i = 0; i < n; i++)
            acb_set_fmpq(x + i, X + i, rbits2);
        acb_poly_evaluate_vec_fast(y, f, x, n, rbits3);

        for (i = 0; i < n; i++)
        {
            if (!acb_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 = ");
                acb_poly_printd(f, 15);
                flint_printf("\n\n");
                flint_printf("x = ");
                acb_printd(x + i, 15);
                flint_printf("\n\n");
                flint_printf("y = ");
                acb_printd(y + i, 15);
                flint_printf("\n\n");

                abort();
            }
        }

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

        acb_poly_clear(f);
        _acb_vec_clear(x, n);
        _acb_vec_clear(y, n);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}