Example #1
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 #2
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;
}
Example #3
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        fmpq_mat_t Q;
        fmpq_t Qdet;
        acb_mat_t A;
        acb_t Adet, imagunit;
        long n, qbits, prec;
        int imaginary;

        n = n_randint(state, 8);
        qbits = 1 + n_randint(state, 100);
        prec = 2 + n_randint(state, 200);
        imaginary = n_randint(state, 2);

        fmpq_mat_init(Q, n, n);
        fmpq_init(Qdet);

        acb_mat_init(A, n, n);
        acb_init(Adet);
        acb_init(imagunit);

        fmpq_mat_randtest(Q, state, qbits);
        fmpq_mat_det(Qdet, Q);

        acb_mat_set_fmpq_mat(A, Q, prec);

        if (imaginary)
        {
            acb_onei(imagunit);
            acb_mat_scalar_mul_acb(A, A, imagunit, prec);
        }

        acb_mat_det(Adet, A, prec);

        if (imaginary)
        {
            acb_onei(imagunit);
            acb_inv(imagunit, imagunit, prec);
            acb_pow_ui(imagunit, imagunit, n, prec);
            acb_mul(Adet, Adet, imagunit, prec);
        }

        if (!acb_contains_fmpq(Adet, Qdet))
        {
            printf("FAIL (containment, iter = %ld)\n", iter);
            printf("n = %ld, prec = %ld\n", n, prec);
            printf("\n");

            printf("Q = \n"); fmpq_mat_print(Q); printf("\n\n");
            printf("Qdet = \n"); fmpq_print(Qdet); printf("\n\n");

            printf("A = \n"); acb_mat_printd(A, 15); printf("\n\n");
            printf("Adet = \n"); acb_printd(Adet, 15); printf("\n\n");
            printf("Adet = \n"); acb_print(Adet); printf("\n\n");

            abort();
        }

        fmpq_mat_clear(Q);
        fmpq_clear(Qdet);
        acb_mat_clear(A);
        acb_clear(Adet);
        acb_clear(imagunit);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #4
0
File: t-trace.c Project: isuruf/arb
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* check that the acb trace contains the fmpq trace */
    for (iter = 0; iter < 10000; iter++)
    {
        fmpq_mat_t Q;
        fmpq_t Qtrace;
        acb_mat_t A;
        acb_t Atrace;
        slong n, qbits, prec;

        n = n_randint(state, 8);
        qbits = 1 + n_randint(state, 100);
        prec = 2 + n_randint(state, 200);

        fmpq_mat_init(Q, n, n);
        fmpq_init(Qtrace);

        acb_mat_init(A, n, n);
        acb_init(Atrace);

        fmpq_mat_randtest(Q, state, qbits);
        fmpq_mat_trace(Qtrace, Q);

        acb_mat_set_fmpq_mat(A, Q, prec);
        acb_mat_trace(Atrace, A, prec);

        if (!acb_contains_fmpq(Atrace, Qtrace))
        {
            flint_printf("FAIL (containment, iter = %wd)\n", iter);
            flint_printf("n = %wd, prec = %wd\n", n, prec);
            flint_printf("\n");

            flint_printf("Q = \n"); fmpq_mat_print(Q); flint_printf("\n\n");
            flint_printf("Qtrace = \n"); fmpq_print(Qtrace); flint_printf("\n\n");

            flint_printf("A = \n"); acb_mat_printd(A, 15); flint_printf("\n\n");
            flint_printf("Atrace = \n"); acb_printd(Atrace, 15); flint_printf("\n\n");
            flint_printf("Atrace = \n"); acb_print(Atrace); flint_printf("\n\n");

            abort();
        }

        fmpq_mat_clear(Q);
        fmpq_clear(Qtrace);
        acb_mat_clear(A);
        acb_clear(Atrace);
    }

    /* check trace(A*B) = trace(B*A) */
    for (iter = 0; iter < 10000; iter++)
    {
        slong m, n, prec;
        acb_mat_t a, b, ab, ba;
        acb_t trab, trba;

        prec = 2 + n_randint(state, 200);

        m = n_randint(state, 10);
        n = n_randint(state, 10);

        acb_mat_init(a, m, n);
        acb_mat_init(b, n, m);
        acb_mat_init(ab, m, m);
        acb_mat_init(ba, n, n);

        acb_init(trab);
        acb_init(trba);

        acb_mat_randtest(a, state, 2 + n_randint(state, 100), 10);
        acb_mat_randtest(b, state, 2 + n_randint(state, 100), 10);

        acb_mat_mul(ab, a, b, prec);
        acb_mat_mul(ba, b, a, prec);

        acb_mat_trace(trab, ab, prec);
        acb_mat_trace(trba, ba, prec);

        if (!acb_overlaps(trab, trba))
        {
            flint_printf("FAIL (overlap, iter = %wd)\n", iter);
            flint_printf("m = %wd, n = %wd, prec = %wd\n", m, n, prec);
            flint_printf("\n");

            flint_printf("a = \n"); acb_mat_printd(a, 15); flint_printf("\n\n");
            flint_printf("b = \n"); acb_mat_printd(b, 15); flint_printf("\n\n");
            flint_printf("ab = \n"); acb_mat_printd(ab, 15); flint_printf("\n\n");
            flint_printf("ba = \n"); acb_mat_printd(ba, 15); flint_printf("\n\n");

            flint_printf("trace(ab) = \n"); acb_printd(trab, 15); flint_printf("\n\n");
            flint_printf("trace(ba) = \n"); acb_printd(trba, 15); flint_printf("\n\n");
        }

        acb_clear(trab);
        acb_clear(trba);

        acb_mat_clear(a);
        acb_mat_clear(b);
        acb_mat_clear(ab);
        acb_mat_clear(ba);
    }

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