示例#1
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 200 * arb_test_multiplier(); iter++)
    {
        slong m, n1, n2, bits1, bits2, bits3;
        acb_poly_t S, A, B, C;
        dirichlet_group_t G;
        dirichlet_char_t chi;
        ulong q;

        bits1 = 2 + n_randint(state, 200);
        bits2 = 2 + n_randint(state, 200);
        bits3 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 8);
        n1 = 1 + n_randint(state, 8);
        n2 = 1 + n_randint(state, 8);

        do {
            q = 1 + n_randint(state, 15);
        } while (q % 4 == 2);

        dirichlet_group_init(G, q);
        dirichlet_char_init(chi, G);
        do {
            dirichlet_char_index(chi, G, n_randint(state, G->phi_q));
        } while (!dirichlet_char_is_primitive(G, chi));

        acb_poly_init(S);
        acb_poly_init(A);
        acb_poly_init(B);
        acb_poly_init(C);

        acb_poly_randtest(S, state, m, bits1, 3);

        acb_dirichlet_hardy_z_series(A, S, G, chi, n1, bits2);
        acb_poly_set(B, S);  /* aliasing */
        if (q == 1 && n_randint(state, 2))
            acb_poly_neg(B, B);
        acb_dirichlet_hardy_z_series(B, B, G, chi, n2, bits3);

        acb_poly_set(C, A);
        acb_poly_truncate(C, FLINT_MIN(n1, n2));
        acb_poly_truncate(B, FLINT_MIN(n1, n2));

        if (!acb_poly_overlaps(B, C))
        {
            flint_printf("FAIL\n\n");
            flint_printf("S = "); acb_poly_printd(S, 15); 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_clear(S);
        acb_poly_clear(A);
        acb_poly_clear(B);
        acb_poly_clear(C);

        dirichlet_char_clear(chi);
        dirichlet_group_clear(G);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#2
0
文件: real_roots.c 项目: jdemeyer/arb
int main(int argc, char *argv[])
{
    arf_interval_ptr blocks;
    arb_calc_func_t function;
    int * info;
    long digits, low_prec, high_prec, i, num, found_roots, found_unknown;
    long maxdepth, maxeval, maxfound;
    int refine;
    double a, b;
    arf_t C;
    arf_interval_t t, interval;
    arb_t v, w, z;

    if (argc < 4)
    {
        printf("real_roots function a b [-refine d] [-verbose] "
               "[-maxdepth n] [-maxeval n] [-maxfound n] [-prec n]\n");
        printf("available functions:\n");
        printf("  0  Z(x), Riemann-Siegel Z-function\n");
        printf("  1  sin(x)\n");
        printf("  2  sin(x^2)\n");
        printf("  3  sin(1/x)\n");
        return 1;
    }

    switch (atoi(argv[1]))
    {
    case 0:
        function = z_function;
        break;
    case 1:
        function = sin_x;
        break;
    case 2:
        function = sin_x2;
        break;
    case 3:
        function = sin_1x;
        break;
    default:
        printf("require a function 0-3\n");
        return 1;
    }

    a = atof(argv[2]);
    b = atof(argv[3]);

    if (a >= b)
    {
        printf("require a < b!\n");
        return 1;
    }

    refine = 0;
    digits = 0;
    maxdepth = 30;
    maxeval = 100000;
    maxfound = 100000;
    low_prec = 30;

    for (i = 4; i < argc; i++)
    {
        if (!strcmp(argv[i], "-refine"))
        {
            refine = 1;
            digits = atol(argv[i+1]);
        }
        else if (!strcmp(argv[i], "-verbose"))
        {
            arb_calc_verbose = 1;
        }
        else if (!strcmp(argv[i], "-maxdepth"))
        {
            maxdepth = atol(argv[i+1]);
        }
        else if (!strcmp(argv[i], "-maxeval"))
        {
            maxeval = atol(argv[i+1]);
        }
        else if (!strcmp(argv[i], "-maxfound"))
        {
            maxfound = atol(argv[i+1]);
        }
        else if (!strcmp(argv[i], "-prec"))
        {
            low_prec = atol(argv[i+1]);
        }
    }

    high_prec = digits * 3.32192809488736 + 10;
    found_roots = 0;
    found_unknown = 0;

    arf_init(C);
    arf_interval_init(t);
    arf_interval_init(interval);
    arb_init(v);
    arb_init(w);
    arb_init(z);

    arf_set_d(&interval->a, a);
    arf_set_d(&interval->b, b);

    printf("interval: ");
    arf_interval_printd(interval, 15);
    printf("\n");
    printf("maxdepth = %ld, maxeval = %ld, maxfound = %ld, low_prec = %ld\n",
           maxdepth, maxeval, maxfound, low_prec);

    TIMEIT_ONCE_START

    num = arb_calc_isolate_roots(&blocks, &info, function,
                                 NULL, interval, maxdepth, maxeval, maxfound, low_prec);

    for (i = 0; i < num; i++)
    {
        if (info[i] != 1)
        {
            if (arb_calc_verbose)
            {
                printf("unable to count roots in ");
                arf_interval_printd(blocks + i, 15);
                printf("\n");
            }
            found_unknown++;
            continue;
        }

        found_roots++;

        if (!refine)
            continue;

        if (arb_calc_refine_root_bisect(t,
                                        function, NULL, blocks + i, 5, low_prec)
                != ARB_CALC_SUCCESS)
        {
            printf("warning: some bisection steps failed!\n");
        }

        if (arb_calc_verbose)
        {
            printf("after bisection 1: ");
            arf_interval_printd(t, 15);
            printf("\n");
        }

        if (arb_calc_refine_root_bisect(blocks + i,
                                        function, NULL, t, 5, low_prec)
                != ARB_CALC_SUCCESS)
        {
            printf("warning: some bisection steps failed!\n");
        }

        if (arb_calc_verbose)
        {
            printf("after bisection 2: ");
            arf_interval_printd(blocks + i, 15);
            printf("\n");
        }

        arf_interval_get_arb(v, t, high_prec);
        arb_calc_newton_conv_factor(C, function, NULL, v, low_prec);

        arf_interval_get_arb(w, blocks + i, high_prec);
        if (arb_calc_refine_root_newton(z, function, NULL,
                                        w, v, C, 10, high_prec) != ARB_CALC_SUCCESS)
        {
            printf("warning: some newton steps failed!\n");
        }

        printf("refined root:\n");
        arb_printd(z, digits + 2);
        printf("\n\n");
    }

    printf("---------------------------------------------------------------\n");
    printf("Found roots: %ld\n", found_roots);
    printf("Subintervals possibly containing undetected roots: %ld\n", found_unknown);
    printf("Function evaluations: %ld\n", eval_count);

    TIMEIT_ONCE_STOP
    SHOW_MEMORY_USAGE

    for (i = 0; i < num; i++)
        arf_interval_clear(blocks + i);
    flint_free(blocks);
    flint_free(info);

    arf_interval_clear(t);
    arf_interval_clear(interval);
    arf_clear(C);
    arb_clear(v);
    arb_clear(w);
    arb_clear(z);
    flint_cleanup();
    return 0;
}
示例#3
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        acb_poly_t ai, aip, bi, bip, ai2, aip2, bi2, bip2, z, w, t;
        acb_t c;
        slong n1, n2, prec1, prec2;
        unsigned int mask;

        acb_poly_init(ai); acb_poly_init(aip);
        acb_poly_init(bi); acb_poly_init(bip);
        acb_poly_init(ai2); acb_poly_init(aip2);
        acb_poly_init(bi2); acb_poly_init(bip2);
        acb_poly_init(z); acb_poly_init(w);
        acb_poly_init(t); acb_init(c);

        prec1 = 2 + n_randint(state, 300);
        prec2 = 2 + n_randint(state, 300);

        n1 = n_randint(state, 6);
        n2 = n_randint(state, 6);

        acb_poly_randtest(ai, state, 10, prec1, 10);
        acb_poly_randtest(aip, state, 10, prec1, 10);
        acb_poly_randtest(bi, state, 10, prec1, 10);
        acb_poly_randtest(bip, state, 10, prec1, 10);
        acb_poly_randtest(z, state, 1 + n_randint(state, 10), prec1, 10);

        acb_hypgeom_airy_series(ai, aip, bi, bip, z, n1, prec1);

        acb_poly_mullow(w, ai, bip, n1, prec1);
        acb_poly_mullow(t, bi, aip, n1, prec1);
        acb_poly_sub(w, w, t, prec1);

        acb_const_pi(c, prec1);
        acb_inv(c, c, prec1);
        acb_poly_set_acb(t, c);
        acb_poly_truncate(t, n1);

        if (!acb_poly_overlaps(w, t))
        {
            flint_printf("FAIL: wronskian\n\n");
            flint_printf("z = "); acb_poly_printd(z, 30); flint_printf("\n\n");
            flint_printf("ai = "); acb_poly_printd(ai, 30); flint_printf("\n\n");
            flint_printf("aip = "); acb_poly_printd(aip, 30); flint_printf("\n\n");
            flint_printf("bi = "); acb_poly_printd(bi, 30); flint_printf("\n\n");
            flint_printf("bip = "); acb_poly_printd(bip, 30); flint_printf("\n\n");
            flint_printf("w = "); acb_poly_printd(w, 30); flint_printf("\n\n");
            abort();
        }

        mask = n_randlimb(state);

        acb_hypgeom_airy_series((mask & 1) ? ai2 : NULL,
                                (mask & 2) ? aip2 : NULL,
                                (mask & 4) ? bi2 : NULL,
                                (mask & 8) ? bip2 : NULL, z, n2, prec2);

        acb_poly_truncate(ai, FLINT_MIN(n1, n2));
        acb_poly_truncate(aip, FLINT_MIN(n1, n2));
        acb_poly_truncate(bi, FLINT_MIN(n1, n2));
        acb_poly_truncate(bip, FLINT_MIN(n1, n2));
        acb_poly_truncate(ai2, FLINT_MIN(n1, n2));
        acb_poly_truncate(aip2, FLINT_MIN(n1, n2));
        acb_poly_truncate(bi2, FLINT_MIN(n1, n2));
        acb_poly_truncate(bip2, FLINT_MIN(n1, n2));

        if (((mask & 1) && (!acb_poly_overlaps(ai, ai2))) ||
            ((mask & 2) && (!acb_poly_overlaps(aip, aip2))) ||
            ((mask & 4) && (!acb_poly_overlaps(bi, bi2))) ||
            ((mask & 8) && (!acb_poly_overlaps(bip, bip2))))
        {
            flint_printf("FAIL: consistency (mask)\n\n");
            flint_printf("mask = %u\n\n", mask);
            flint_printf("len1 = %wd, len2 = %wd\n\n", n1, n2);
            flint_printf("z = "); acb_poly_printd(z, 30); flint_printf("\n\n");
            flint_printf("ai = "); acb_poly_printd(ai, 30); flint_printf("\n\n");
            flint_printf("ai2 = "); acb_poly_printd(ai2, 30); flint_printf("\n\n");
            flint_printf("aip = "); acb_poly_printd(aip, 30); flint_printf("\n\n");
            flint_printf("aip2 = "); acb_poly_printd(aip2, 30); flint_printf("\n\n");
            flint_printf("bi = "); acb_poly_printd(bi, 30); flint_printf("\n\n");
            flint_printf("bi2 = "); acb_poly_printd(bi2, 30); flint_printf("\n\n");
            flint_printf("bip = "); acb_poly_printd(bip, 30); flint_printf("\n\n");
            flint_printf("bip2 = "); acb_poly_printd(bip2, 30); flint_printf("\n\n");
            abort();
        }

        acb_poly_clear(ai); acb_poly_clear(aip);
        acb_poly_clear(bi); acb_poly_clear(bip);
        acb_poly_clear(ai2); acb_poly_clear(aip2);
        acb_poly_clear(bi2); acb_poly_clear(bip2);
        acb_poly_clear(z); acb_poly_clear(w);
        acb_poly_clear(t); acb_clear(c);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 100 * arb_test_multiplier(); iter++)
    {
        slong m, n1, n2, bits1, bits2, bits3;
        acb_poly_t S, A, B, C;
        acb_t z;

        bits1 = 2 + n_randint(state, 200);
        bits2 = 2 + n_randint(state, 200);
        bits3 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 10);
        n1 = 1 + n_randint(state, 10);
        n2 = 1 + n_randint(state, 10);

        acb_poly_init(S);
        acb_poly_init(A);
        acb_poly_init(B);
        acb_poly_init(C);
        acb_init(z);

        acb_poly_randtest(S, state, m, bits1, 3);
        acb_poly_randtest(A, state, m, bits1, 3);
        acb_poly_randtest(B, state, m, bits1, 3);
        acb_randtest(z, state, bits1, 3);

        acb_poly_elliptic_p_series(A, S, z, n1, bits2);
        acb_poly_elliptic_p_series(B, S, z, n2, bits3);

        acb_poly_set(C, A);
        acb_poly_truncate(C, FLINT_MIN(n1, n2));
        acb_poly_truncate(B, FLINT_MIN(n1, n2));

        if (!acb_poly_overlaps(B, C))
        {
            flint_printf("FAIL\n\n");
            flint_printf("S = "); acb_poly_printd(S, 15); flint_printf("\n\n");
            flint_printf("z = "); acb_printd(z, 15); 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_elliptic_p_series(S, S, z, n1, bits2);

        if (!acb_poly_overlaps(A, S))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        acb_poly_clear(S);
        acb_poly_clear(A);
        acb_poly_clear(B);
        acb_poly_clear(C);
        acb_clear(z);
    }

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

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

    flint_randinit(state);

    /* check rf(f, a) * rf(f + a, b) = rf(f, a + b) */
    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        slong bits, trunc;
        ulong a, b;
        arb_poly_t f, g, h1, h2, h1h2, h3;

        bits = 2 + n_randint(state, 200);
        trunc = 1 + n_randint(state, 20);
        a = n_randint(state, 10);
        b = n_randint(state, 10);

        arb_poly_init(f);
        arb_poly_init(g);
        arb_poly_init(h1);
        arb_poly_init(h2);
        arb_poly_init(h1h2);
        arb_poly_init(h3);

        arb_poly_randtest(f, state, 1 + n_randint(state, 20), bits, 4);
        arb_poly_set(g, f);

        /* g = f + 1 */
        if (g->length == 0)
        {
            arb_poly_fit_length(g, 1);
            arb_set_ui(g->coeffs, a);
            _arb_poly_set_length(g, 1);
            _arb_poly_normalise(g);
        }
        else
        {
            arb_add_ui(g->coeffs, g->coeffs, a, bits);
            _arb_poly_normalise(g);
        }

        arb_poly_rising_ui_series(h1, f, a, trunc, bits);
        arb_poly_rising_ui_series(h2, g, b, trunc, bits);
        arb_poly_rising_ui_series(h3, f, a + b, trunc, bits);

        arb_poly_mullow(h1h2, h1, h2, trunc, bits);

        if (!arb_poly_overlaps(h1h2, h3))
        {
            flint_printf("FAIL\n\n");
            flint_printf("bits = %wd\n", bits);
            flint_printf("trunc = %wd\n", trunc);
            flint_printf("a = %wu\n", a);
            flint_printf("b = %wu\n", a);

            flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n");
            flint_printf("g = "); arb_poly_printd(g, 15); flint_printf("\n\n");
            flint_printf("h1 = "); arb_poly_printd(h1, 15); flint_printf("\n\n");
            flint_printf("h2 = "); arb_poly_printd(h2, 15); flint_printf("\n\n");
            flint_printf("h1h2 = "); arb_poly_printd(h1h2, 15); flint_printf("\n\n");
            flint_printf("h3 = "); arb_poly_printd(h3, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_rising_ui_series(f, f, a, trunc, bits);

        if (!arb_poly_equal(f, h1))
        {
            flint_printf("FAIL (aliasing)\n\n");

            flint_printf("bits = %wd\n", bits);
            flint_printf("trunc = %wd\n", trunc);
            flint_printf("a = %wu\n", a);
            flint_printf("b = %wu\n", a);

            flint_printf("f = "); arb_poly_printd(f, 15); flint_printf("\n\n");
            flint_printf("h1 = "); arb_poly_printd(h1, 15); flint_printf("\n\n");

            abort();
        }

        arb_poly_clear(f);
        arb_poly_clear(g);
        arb_poly_clear(h1);
        arb_poly_clear(h2);
        arb_poly_clear(h1h2);
        arb_poly_clear(h3);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        fmpq_mat_t Q, Qinv;
        arb_mat_t A, Ainv;
        slong n, qbits, prec;
        int q_invertible, r_invertible, r_invertible2;

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

        fmpq_mat_init(Q, n, n);
        fmpq_mat_init(Qinv, n, n);

        arb_mat_init(A, n, n);
        arb_mat_init(Ainv, n, n);

        fmpq_mat_randtest(Q, state, qbits);
        q_invertible = fmpq_mat_inv(Qinv, Q);

        if (!q_invertible)
        {
            arb_mat_set_fmpq_mat(A, Q, prec);
            r_invertible = arb_mat_inv(Ainv, A, prec);
            if (r_invertible)
            {
                flint_printf("FAIL: matrix is singular over Q but not over R\n");
                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("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                flint_printf("Ainv = \n"); arb_mat_printd(Ainv, 15); flint_printf("\n\n");
                abort();
            }
        }
        else
        {
            /* now this must converge */
            while (1)
            {
                arb_mat_set_fmpq_mat(A, Q, prec);
                r_invertible = arb_mat_inv(Ainv, A, prec);

                if (r_invertible)
                {
                    break;
                }
                else
                {
                    if (prec > 10000)
                    {
                        flint_printf("FAIL: failed to converge at 10000 bits\n");
                        flint_printf("Q = \n"); fmpq_mat_print(Q); flint_printf("\n\n");
                        flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                        abort();
                    }
                    prec *= 2;
                }
            }

            if (!arb_mat_contains_fmpq_mat(Ainv, Qinv))
            {
                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("Qinv = \n"); fmpq_mat_print(Qinv); flint_printf("\n\n");

                flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                flint_printf("Ainv = \n"); arb_mat_printd(Ainv, 15); flint_printf("\n\n");

                abort();
            }

            /* test aliasing */
            r_invertible2 = arb_mat_inv(A, A, prec);
            if (!arb_mat_equal(A, Ainv) || r_invertible != r_invertible2)
            {
                flint_printf("FAIL (aliasing)\n");
                flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                flint_printf("Ainv = \n"); arb_mat_printd(Ainv, 15); flint_printf("\n\n");
                abort();
            }
        }

        fmpq_mat_clear(Q);
        fmpq_mat_clear(Qinv);
        arb_mat_clear(A);
        arb_mat_clear(Ainv);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 40; iter++)
    {
        slong m, r, a, b, maxdepth, maxeval, maxfound, prec, i, j, num;
        arf_interval_ptr blocks;
        int * info;
        arf_interval_t interval;
        arb_t t;
        fmpz_t nn;

        prec = 2 + n_randint(state, 50);

        m = n_randint(state, 80);
        r = 1 + n_randint(state, 80);
        a = m - r;
        b = m + r;

        maxdepth = 1 + n_randint(state, 60);
        maxeval = 1 + n_randint(state, 5000);
        maxfound = 1 + n_randint(state, 100);

        arf_interval_init(interval);
        arb_init(t);
        fmpz_init(nn);

        arf_set_si(&interval->a, a);
        arf_set_si(&interval->b, b);

        num = arb_calc_isolate_roots(&blocks, &info, sin_pi2_x, NULL,
            interval, maxdepth, maxeval, maxfound, prec);

        /* check that all roots are accounted for */
        for (i = a; i <= b; i++)
        {
            if (i % 2 == 0)
            {
                int found = 0;

                for (j = 0; j < num; j++)
                {
                    arf_interval_get_arb(t, blocks + j, ARF_PREC_EXACT);

                    if (arb_contains_si(t, i))
                    {
                        found = 1;
                        break;
                    }
                }

                if (!found)
                {
                    flint_printf("FAIL: missing root %wd\n", i);
                    flint_printf("a = %wd, b = %wd, maxdepth = %wd, maxeval = %wd, maxfound = %wd, prec = %wd\n",
                        a, b, maxdepth, maxeval, maxfound, prec);

                    for (j = 0; j < num; j++)
                    {
                        arf_interval_printd(blocks + j, 15);
                        flint_printf("   %d \n", info[i]);
                    }

                    abort();
                }
            }
        }

        /* check that all reported single roots are good */
        for (i = 0; i < num; i++)
        {
            if (info[i] == 1)
            {
                /* b contains unique 2n -> b/2 contains unique n */
                arf_interval_get_arb(t, blocks + i, ARF_PREC_EXACT);
                arb_mul_2exp_si(t, t, -1);

                if (!arb_get_unique_fmpz(nn, t))
                {
                    flint_printf("FAIL: bad root %wd\n", i);
                    flint_printf("a = %wd, b = %wd, maxdepth = %wd, maxeval = %wd, maxfound = %wd, prec = %wd\n",
                        a, b, maxdepth, maxeval, maxfound, prec);

                    for (j = 0; j < num; j++)
                    {
                        arf_interval_printd(blocks + j, 15);
                        flint_printf("   %d \n", info[i]);
                    }

                    abort();
                }
            }
        }

        _arf_interval_vec_clear(blocks, num);
        flint_free(info);

        arf_interval_clear(interval);
        arb_clear(t);
        fmpz_clear(nn);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#8
0
文件: t-acosh.c 项目: isuruf/arb
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000; iter++)
    {
        acb_t x, a, b;
        slong prec1, prec2;

        prec1 = 2 + n_randint(state, 1000);
        prec2 = prec1 + 30;

        acb_init(x);
        acb_init(a);
        acb_init(b);

        acb_randtest_special(x, state, 1 + n_randint(state, 1000), 2 + n_randint(state, 100));
        acb_randtest_special(a, state, 1 + n_randint(state, 1000), 2 + n_randint(state, 100));
        acb_randtest_special(b, state, 1 + n_randint(state, 1000), 2 + n_randint(state, 100));

        acb_acosh(a, x, prec1);
        acb_acosh(b, x, prec2);

        /* check consistency */
        if (!acb_overlaps(a, b))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("x = "); acb_printd(x, 15); flint_printf("\n\n");
            flint_printf("a = "); acb_printd(a, 15); flint_printf("\n\n");
            flint_printf("b = "); acb_printd(b, 15); flint_printf("\n\n");
            abort();
        }

        /* check cosh(acosh(x)) = x */
        acb_cosh(b, b, prec1);

        if (!acb_contains(b, x))
        {
            flint_printf("FAIL: functional equation\n\n");
            flint_printf("x = "); acb_printd(x, 15); flint_printf("\n\n");
            flint_printf("b = "); acb_printd(b, 15); flint_printf("\n\n");
            abort();
        }

        acb_acosh(x, x, prec1);

        if (!acb_overlaps(a, x))
        {
            flint_printf("FAIL: aliasing\n\n");
            flint_printf("a = "); acb_printd(a, 15); flint_printf("\n\n");
            flint_printf("x = "); acb_printd(x, 15); flint_printf("\n\n");
            abort();
        }

        acb_clear(x);
        acb_clear(a);
        acb_clear(b);
    }

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

    flint_printf("gamma_fmpq....");
    fflush(stdout);
    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t r, s;
        fmpq_t q;
        slong accuracy, prec, pp, qq;

        prec = 2 + n_randint(state, 1 << n_randint(state, 12));
        prec += 20;

        arb_init(r);
        arb_init(s);
        fmpq_init(q);

        pp = -100 + n_randint(state, 10000);
        qq = 1 + n_randint(state, 20);
        fmpq_set_si(q, pp, qq);

        arb_gamma_fmpq(r, q, prec);

        arb_set_fmpq(s, q, prec);
        arb_gamma(s, s, prec);

        if (!arb_overlaps(r, s))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("prec = %wd\n", prec);
            flint_printf("q = "); fmpq_print(q); flint_printf("\n\n");
            flint_printf("r = "); arb_printd(r, prec / 3.33); flint_printf("\n\n");
            flint_printf("s = "); arb_printd(s, prec / 3.33); flint_printf("\n\n");
            abort();
        }

        if (!(fmpz_is_one(fmpq_denref(q)) && fmpz_sgn(fmpq_numref(q)) <= 0)
            && FLINT_ABS(pp / qq) < 10)
        {
            accuracy = arb_rel_accuracy_bits(r);

            if (accuracy < prec - 6)
            {
                flint_printf("FAIL: poor accuracy\n\n");
                flint_printf("prec = %wd\n", prec);
                flint_printf("q = "); fmpq_print(q); flint_printf("\n\n");
                flint_printf("r = "); arb_printd(r, prec / 3.33); flint_printf("\n\n");
                abort();
            }
        }

        arb_clear(r);
        arb_clear(s);
        fmpq_clear(q);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#10
0
文件: t-mul.c 项目: certik/arb
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* test aliasing of c and a */
    for (iter = 0; iter < 100000; iter++)
    {
        fmpcb_t a, b, c;
        long prec;

        fmpcb_init(a);
        fmpcb_init(b);
        fmpcb_init(c);

        fmpcb_randtest(a, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(b, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(c, state, 1 + n_randint(state, 200), 10);

        prec = 2 + n_randint(state, 200);

        fmpcb_mul(c, a, b, prec);
        fmpcb_mul(a, a, b, prec);

        if (!fmpcb_equal(a, c))
        {
            printf("FAIL: aliasing c, a\n\n");
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            printf("c = "); fmpcb_print(c); printf("\n\n");
            abort();
        }

        fmpcb_clear(a);
        fmpcb_clear(b);
        fmpcb_clear(c);
    }

    /* test aliasing of c and b */
    for (iter = 0; iter < 100000; iter++)
    {
        fmpcb_t a, b, c;
        long prec;

        fmpcb_init(a);
        fmpcb_init(b);
        fmpcb_init(c);

        fmpcb_randtest(a, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(b, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(c, state, 1 + n_randint(state, 200), 10);

        prec = 2 + n_randint(state, 200);

        fmpcb_mul(c, a, b, prec);
        fmpcb_mul(b, a, b, prec);

        if (!fmpcb_equal(b, c))
        {
            printf("FAIL: aliasing b, a\n\n");
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            printf("c = "); fmpcb_print(c); printf("\n\n");
            abort();
        }

        fmpcb_clear(a);
        fmpcb_clear(b);
        fmpcb_clear(c);
    }

    /* test aliasing a, a */
    for (iter = 0; iter < 100000; iter++)
    {
        fmpcb_t a, b, c, d;
        long prec;

        fmpcb_init(a);
        fmpcb_init(b);
        fmpcb_init(c);
        fmpcb_init(d);

        fmpcb_randtest(a, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(b, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(c, state, 1 + n_randint(state, 200), 10);

        prec = 2 + n_randint(state, 200);

        fmpcb_set(b, a);
        fmpcb_mul(c, a, a, prec);
        fmpcb_mul(d, a, b, prec);

        if (!fmpcb_equal(c, d))
        {
            printf("FAIL: aliasing a, a\n\n");
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            printf("c = "); fmpcb_print(c); printf("\n\n");
            printf("d = "); fmpcb_print(d); printf("\n\n");
            abort();
        }

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

    /* test aliasing a, a, a */
    for (iter = 0; iter < 100000; iter++)
    {
        fmpcb_t a, b, c;
        long prec;

        fmpcb_init(a);
        fmpcb_init(b);
        fmpcb_init(c);

        fmpcb_randtest(a, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(b, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(c, state, 1 + n_randint(state, 200), 10);

        prec = 2 + n_randint(state, 200);

        fmpcb_set(b, a);
        fmpcb_mul(c, a, b, prec);
        fmpcb_mul(a, a, a, prec);

        if (!fmpcb_equal(a, c))
        {
            printf("FAIL: aliasing a, a, a\n\n");
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            printf("c = "); fmpcb_print(c); printf("\n\n");
            abort();
        }

        fmpcb_clear(a);
        fmpcb_clear(b);
        fmpcb_clear(c);
    }

    /* test a*(b+c) = a*b + a*c */
    for (iter = 0; iter < 100000; iter++)
    {
        fmpcb_t a, b, c, d, e, f;

        fmpcb_init(a);
        fmpcb_init(b);
        fmpcb_init(c);
        fmpcb_init(d);
        fmpcb_init(e);
        fmpcb_init(f);

        fmpcb_randtest(a, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(b, state, 1 + n_randint(state, 200), 10);
        fmpcb_randtest(c, state, 1 + n_randint(state, 200), 10);

        fmpcb_add(d, b, c, 2 + n_randint(state, 200));
        fmpcb_mul(e, a, d, 2 + n_randint(state, 200));

        fmpcb_mul(d, a, b, 2 + n_randint(state, 200));
        fmpcb_mul(f, a, c, 2 + n_randint(state, 200));
        fmpcb_add(f, d, f, 2 + n_randint(state, 200));

        if (!fmpcb_overlaps(e, f))
        {
            printf("FAIL: a*(b+c) = a*b + a*c\n\n");
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            printf("c = "); fmpcb_print(c); printf("\n\n");
            printf("e = "); fmpcb_print(e); printf("\n\n");
            printf("f = "); fmpcb_print(f); printf("\n\n");
            abort();
        }

        fmpcb_clear(a);
        fmpcb_clear(b);
        fmpcb_clear(c);
        fmpcb_clear(d);
        fmpcb_clear(e);
        fmpcb_clear(f);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#11
0
文件: t-union.c 项目: bluescarni/arb
int main()
{
    long iter;
    flint_rand_t state;

    printf("union....");
    fflush(stdout);
    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        arb_t x, y, z;
        long prec;
        int alias;

        arb_init(x);
        arb_init(y);
        arb_init(z);

        arb_randtest_special(x, state, 200, 10);
        arb_randtest_special(y, state, 200, 10);
        arb_randtest_special(z, state, 200, 10);

        prec = 2 + n_randint(state, 200);

        arb_union(z, x, y, prec);

        if (!arb_contains(z, x) || !arb_contains(z, y))
        {
            printf("FAIL:\n\n");
            printf("x = "); arb_print(x); printf("\n\n");
            printf("y = "); arb_print(y); printf("\n\n");
            printf("z = "); arb_print(z); printf("\n\n");
            abort();
        }

        if (n_randint(state, 2))
        {
            arb_union(x, x, y, prec);
            alias = arb_equal(x, z);
        }
        else
        {
            arb_union(y, x, y, prec);
            alias = arb_equal(y, z);
        }

        if (!alias)
        {
            printf("FAIL (aliasing):\n\n");
            printf("x = "); arb_print(x); printf("\n\n");
            printf("y = "); arb_print(y); printf("\n\n");
            printf("z = "); arb_print(z); printf("\n\n");
            abort();
        }

        arb_clear(x);
        arb_clear(y);
        arb_clear(z);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#12
0
文件: t-rsqrt.c 项目: bluescarni/arb
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        long bits, res;
        fmpr_t x, z, w;
        mpfr_t X, Z;

        bits = 2 + n_randint(state, 200);

        fmpr_init(x);
        fmpr_init(z);
        fmpr_init(w);

        mpfr_init2(X, 2 * (bits + 100));
        mpfr_init2(Z, bits);

        fmpr_randtest_special(x, state, bits + n_randint(state, 100), 10);
        fmpr_randtest_special(z, state, bits + n_randint(state, 100), 10);

        fmpr_get_mpfr(X, x, MPFR_RNDN);

        switch (n_randint(state, 4))
        {
            case 0:
                mpfr_rec_sqrt(Z, X, MPFR_RNDZ);
                res = fmpr_rsqrt(z, x, bits, FMPR_RND_DOWN);
                break;
            case 1:
                mpfr_rec_sqrt(Z, X, MPFR_RNDA);
                res = fmpr_rsqrt(z, x, bits, FMPR_RND_UP);
                break;
            case 2:
                mpfr_rec_sqrt(Z, X, MPFR_RNDD);
                res = fmpr_rsqrt(z, x, bits, FMPR_RND_FLOOR);
                break;
            default:
                mpfr_rec_sqrt(Z, X, MPFR_RNDU);
                res = fmpr_rsqrt(z, x, bits, FMPR_RND_CEIL);
                break;
        }

        fmpr_set_mpfr(w, Z);

        if (!fmpr_equal(z, w) || !fmpr_check_ulp(z, res, bits))
        {
            printf("FAIL\n\n");
            printf("bits = %ld\n", bits);
            printf("x = "); fmpr_print(x); printf("\n\n");
            printf("z = "); fmpr_print(z); printf("\n\n");
            printf("w = "); fmpr_print(w); printf("\n\n");
            abort();
        }

        fmpr_clear(x);
        fmpr_clear(z);
        fmpr_clear(w);

        mpfr_clear(X);
        mpfr_clear(Z);
    }

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

    flint_printf("euler_product_real_ui....");
    fflush(stdout);
    flint_randinit(state);

    for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++)
    {
        arb_t res1, res2;
        ulong s;
        slong prec1, prec2, accuracy;
        int choice, reciprocal1, reciprocal2;

        if (iter % 10 == 0)
        {
            s = n_randtest(state);
            prec1 = 2 + n_randint(state, 300);
            prec2 = 2 + n_randint(state, 300);
        }
        else
        {
            s = 6 + n_randint(state, 1 << n_randint(state, 12));
            prec1 = 2 + n_randint(state, 12 * s);
            prec2 = 2 + n_randint(state, 12 * s);
        }

        if (n_randint(state, 30)  == 0)
            prec1 = 2 + n_randint(state, 4000);

        choice = n_randint(state, 7);
        reciprocal1 = n_randint(state, 2);
        reciprocal2 = n_randint(state, 2);

        arb_init(res1);
        arb_init(res2);
        arb_randtest(res1, state, 200, 100);

        _acb_dirichlet_euler_product_real_ui(res1, s, chi[choice] + 1,
            chi[choice][0], reciprocal1, prec1);
        _acb_dirichlet_euler_product_real_ui(res2, s, chi[choice] + 1,
            chi[choice][0], reciprocal2, prec2);

        if (reciprocal1 != reciprocal2)
            arb_inv(res2, res2, prec2);

        if (!arb_overlaps(res1, res2))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("s = %wu\n\n", s);
            flint_printf("chi: %d\n", choice);
            flint_printf("res1 = "); arb_printd(res1, prec1 / 3.33); flint_printf("\n\n");
            flint_printf("res2 = "); arb_printd(res2, prec2 / 3.33); flint_printf("\n\n");
            abort();
        }

        if (s >= 6 && prec1 < 2 * s * log(s))
        {
            accuracy = arb_rel_accuracy_bits(res1);

            if (accuracy < prec1 - 4)
            {
                flint_printf("FAIL: accuracy = %wd, prec = %wd\n\n", accuracy, prec1);
                flint_printf("res1 = "); arb_printd(res1, prec1 / 3.33); flint_printf("\n\n");
                abort();
            }
        }

        if (s == 10)
        {
            arf_set_d(arb_midref(res2), L10[choice]);
            mag_set_d(arb_radref(res2), 1e-15);
            if (reciprocal1)
                arb_inv(res2, res2, 53);

            if (!arb_overlaps(res1, res2))
            {
                flint_printf("FAIL: overlap (2)\n\n");
                flint_printf("s = %wu\n\n", s);
                flint_printf("chi: %d\n", choice);
                flint_printf("res1 = "); arb_printd(res1, prec1 / 3.33); flint_printf("\n\n");
                flint_printf("res2 = "); arb_printd(res2, prec2 / 3.33); flint_printf("\n\n");
                abort();
            }
        }

        arb_clear(res1);
        arb_clear(res2);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 130 + 20 * arb_test_multiplier(); iter++)
    {
        arb_t t, x;
        fmpz_t N, n;
        slong prec1, prec2;

        arb_init(t);
        arb_init(x);
        fmpz_init(n);
        fmpz_init(N);

        if (iter < 130)
        {
            fmpz_set_si(n, iter - 1);
        }
        else
        {
            fmpz_randtest_unsigned(n, state, 20);
            fmpz_add_ui(n, n, 129);
        }

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

        acb_dirichlet_zeta_nzeros_gram(N, n);

        acb_dirichlet_gram_point(t, n, NULL, NULL, prec1);
        acb_dirichlet_zeta_nzeros(x, t, prec2);

        if (!arb_contains_fmpz(x, N))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("n = "); fmpz_print(n);
            flint_printf("   prec1 = %wd  prec2 = %wd\n\n", prec1, prec2);
            flint_printf("N = "); fmpz_print(N); flint_printf("\n\n");
            flint_printf("t = "); arb_printn(t, 100, 0); flint_printf("\n\n");
            flint_printf("x = "); arb_printn(x, 100, 0); flint_printf("\n\n");
            flint_abort();
        }

        arb_clear(t);
        arb_clear(x);
        fmpz_clear(n);
        fmpz_clear(N);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, s, t;
        arb_ptr res;
        slong aa, bb, k, n, len;
        slong prec;

        len = n_randint(state, 30);
        prec = 2 + n_randint(state, 500);
        aa = n_randint(state, 50) - 50;
        bb = aa + n_randint(state, 50);

        arb_init(a);
        arb_init(b);
        arb_init(s);
        arb_init(t);
        res = _arb_vec_init(len);

        arb_set_si(a, aa);
        arb_set_si(b, bb);
        arb_power_sum_vec(res, a, b, len, prec);

        for (n = 0; n < len; n++)
        {
            arb_zero(s);
            for (k = aa; k < bb; k++)
            {
                arb_set_si(t, k);
                arb_pow_ui(t, t, n, prec);
                arb_add(s, s, t, prec);
            }

            if (!arb_overlaps(res + n, s))
            {
                flint_printf("FAIL: overlap\n\n");
                flint_printf("a = %wd, b = %wd, n = %wd\n\n", aa, bb, n);
                flint_printf("res = "); arb_printd(res + n, 30); flint_printf("\n\n");
                flint_printf("s = "); arb_printd(s, 30); flint_printf("\n\n");
                abort();
            }
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(s);
        arb_clear(t);
        _arb_vec_clear(res, len);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#16
0
文件: t-divrem.c 项目: bluescarni/arb
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;
}
示例#17
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t c1, c2;
        ulong p, q, g;
        slong prec;

        prec = 2 + n_randint(state, 5000);
        q = 1 + n_randint(state, 500);
        p = n_randint(state, q / 2 + 1);

        g = n_gcd(q, p);
        q /= g;
        p /= g;

        arb_init(c1);
        arb_init(c2);

        _arb_cos_pi_fmpq_algebraic(c1, p, q, prec);

        arb_const_pi(c2, prec);
        arb_mul_ui(c2, c2, p, prec);
        arb_div_ui(c2, c2, q, prec);
        arb_cos(c2, c2, prec);

        if (!arb_overlaps(c1, c2))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("p/q = %wu/%wu", p, q); flint_printf("\n\n");
            flint_printf("c1 = "); arb_printd(c1, 15); flint_printf("\n\n");
            flint_printf("c2 = "); arb_printd(c2, 15); flint_printf("\n\n");
            abort();
        }

        if (arb_rel_accuracy_bits(c1) < prec - 2)
        {
            flint_printf("FAIL: accuracy\n\n");
            flint_printf("p/q = %wu/%wu", p, q); flint_printf("\n\n");
            flint_printf("prec=%wd eff=%wd\n", prec, arb_rel_accuracy_bits(c1));
            flint_printf("c1 = "); arb_printd(c1, 15); flint_printf("\n\n");
            flint_printf("c2 = "); arb_printd(c2, 15); flint_printf("\n\n");
            abort();
        }

        arb_clear(c1);
        arb_clear(c2);
    }

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

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

    flint_randinit(state);
    _flint_rand_init_gmp(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        mp_ptr x, y1, y2, t;
        mp_limb_t err1, err2;
        ulong N;
        mp_size_t xn;
        int alternating, cmp, result;

        N = n_randint(state, 256);
        alternating = n_randint(state, 2);
        xn = 1 + n_randint(state, 20);

        x = flint_malloc(sizeof(mp_limb_t) * xn);
        y1 = flint_malloc(sizeof(mp_limb_t) * xn);
        y2 = flint_malloc(sizeof(mp_limb_t) * xn);
        t = flint_malloc(sizeof(mp_limb_t) * xn);

        flint_mpn_rrandom(x, state->gmp_state, xn);
        x[xn - 1] &= (LIMB_ONES >> 4);

        _arb_atan_taylor_naive(y1, &err1, x, xn, N, alternating);
        _arb_atan_taylor_rs(y2, &err2, x, xn, N, alternating);

        cmp = mpn_cmp(y1, y2, xn);

        if (cmp == 0)
        {
            result = 1;
        }
        else if (cmp > 0)
        {
            mpn_sub_n(t, y1, y2, xn);
            result = flint_mpn_zero_p(t + 1, xn - 1) && (t[0] <= err2);
        }
        else
        {
            mpn_sub_n(t, y2, y1, xn);
            result = flint_mpn_zero_p(t + 1, xn - 1) && (t[0] <= err2);
        }

        if (!result)
        {
            flint_printf("FAIL\n");
            flint_printf("N = %wd xn = %wd alternating = %d\n", N, xn, alternating);
            flint_printf("x =");
            flint_mpn_debug(x, xn);
            flint_printf("y1 =");
            flint_mpn_debug(y1, xn);
            flint_printf("y2 =");
            flint_mpn_debug(y2, xn);
            abort();
        }

        flint_free(x);
        flint_free(y1);
        flint_free(y2);
        flint_free(t);
    }

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

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

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        fmpq_mat_t Q, QX, QB;
        arb_mat_t A, X, B;
        slong n, m, qbits, prec;
        int q_invertible, r_invertible, r_invertible2;

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

        fmpq_mat_init(Q, n, n);
        fmpq_mat_init(QX, n, m);
        fmpq_mat_init(QB, n, m);

        arb_mat_init(A, n, n);
        arb_mat_init(X, n, m);
        arb_mat_init(B, n, m);

        _fmpq_mat_randtest_positive_semidefinite(Q, state, qbits);
        fmpq_mat_randtest(QB, state, qbits);

        q_invertible = fmpq_mat_solve_fraction_free(QX, Q, QB);

        if (!q_invertible)
        {
            arb_mat_set_fmpq_mat(A, Q, prec);
            r_invertible = _spd_solve(X, A, B, prec);
            if (r_invertible)
            {
                flint_printf("FAIL: matrix is singular over Q but not over R\n");
                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("QX = \n"); fmpq_mat_print(QX); flint_printf("\n\n");
                flint_printf("QB = \n"); fmpq_mat_print(QB); flint_printf("\n\n");
                flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                flint_abort();
            }
        }
        else
        {
            /* now this must converge */
            while (1)
            {
                arb_mat_set_fmpq_mat(A, Q, prec);
                arb_mat_set_fmpq_mat(B, QB, prec);

                r_invertible = _spd_solve(X, A, B, prec);
                if (r_invertible)
                {
                    break;
                }
                else
                {
                    if (prec > 10000)
                    {
                        flint_printf("FAIL: failed to converge at 10000 bits\n");
                        flint_printf("Q = \n"); fmpq_mat_print(Q); flint_printf("\n\n");
                        flint_printf("QX = \n"); fmpq_mat_print(QX); flint_printf("\n\n");
                        flint_printf("QB = \n"); fmpq_mat_print(QB); flint_printf("\n\n");
                        flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                        flint_abort();
                    }
                    prec *= 2;
                }
            }

            if (!arb_mat_contains_fmpq_mat(X, QX))
            {
                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("QB = \n"); fmpq_mat_print(QB); flint_printf("\n\n");
                flint_printf("QX = \n"); fmpq_mat_print(QX); flint_printf("\n\n");

                flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                flint_printf("B = \n"); arb_mat_printd(B, 15); flint_printf("\n\n");
                flint_printf("X = \n"); arb_mat_printd(X, 15); flint_printf("\n\n");

                flint_abort();
            }

            /* test aliasing */
            r_invertible2 = _spd_solve(B, A, B, prec);
            if (!arb_mat_equal(X, B) || r_invertible != r_invertible2)
            {
                flint_printf("FAIL (aliasing)\n");
                flint_printf("A = \n"); arb_mat_printd(A, 15); flint_printf("\n\n");
                flint_printf("B = \n"); arb_mat_printd(B, 15); flint_printf("\n\n");
                flint_printf("X = \n"); arb_mat_printd(X, 15); flint_printf("\n\n");
                flint_abort();
            }
        }

        fmpq_mat_clear(Q);
        fmpq_mat_clear(QB);
        fmpq_mat_clear(QX);
        arb_mat_clear(A);
        arb_mat_clear(B);
        arb_mat_clear(X);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#20
0
文件: t-theta_sum.c 项目: isuruf/arb
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* Very weak test, just testing the error bounds and not
       that we compute the right functions */
    for (iter = 0; iter < 10000; iter++)
    {
        acb_ptr t1a, t1b, t2a, t2b, t3a, t3b, t4a, t4b;
        acb_t w, q;
        int w_is_unit;
        slong prec0, e0, prec1, prec2, len1, len2, i;

        acb_init(w);
        acb_init(q);

        e0 = 1 + n_randint(state, 100);
        prec0 = 2 + n_randint(state, 3000);
        prec1 = 2 + n_randint(state, 3000);
        prec2 = 2 + n_randint(state, 3000);
        len1 = 1 + n_randint(state, 30);
        len2 = 1 + n_randint(state, 30);

        t1a = _acb_vec_init(len1);
        t2a = _acb_vec_init(len1);
        t3a = _acb_vec_init(len1);
        t4a = _acb_vec_init(len1);

        t1b = _acb_vec_init(len2);
        t2b = _acb_vec_init(len2);
        t3b = _acb_vec_init(len2);
        t4b = _acb_vec_init(len2);

        if (n_randint(state, 2))
        {
            arb_randtest(acb_realref(q), state, prec0, e0);
            arb_zero(acb_imagref(q));
            acb_exp_pi_i(w, q, prec0);
            w_is_unit = n_randint(state, 2);
        }
        else
        {
            acb_randtest(w, state, prec0, e0);
            w_is_unit = 0;
        }

        acb_randtest(q, state, prec0, e0);

        for (i = 0; i < len1; i++)
        {
            acb_randtest(t1a + i, state, prec0, e0);
            acb_randtest(t2a + i, state, prec0, e0);
            acb_randtest(t3a + i, state, prec0, e0);
            acb_randtest(t4a + i, state, prec0, e0);
        }

        for (i = 0; i < len2; i++)
        {
            acb_randtest(t1b + i, state, prec0, e0);
            acb_randtest(t2b + i, state, prec0, e0);
            acb_randtest(t3b + i, state, prec0, e0);
            acb_randtest(t4b + i, state, prec0, e0);
        }

        acb_modular_theta_sum(t1a, t2a, t3a, t4a,
            w, w_is_unit, q, len1, prec1);

        acb_modular_theta_sum(t1b, t2b, t3b, t4b,
            w, w_is_unit & n_randint(state, 2), q, len2, prec2);

        for (i = 0; i < FLINT_MIN(len1, len2); i++)
        {
            if (!acb_overlaps(t1a + i, t1b + i)
                || !acb_overlaps(t2a + i, t2b + i)
                || !acb_overlaps(t3a + i, t3b + i)
                || !acb_overlaps(t4a + i, t4b + i))
            {
                flint_printf("FAIL (overlap)  iter = %wd\n", iter);
                flint_printf("len1 = %wd, len2 = %wd, prec1 = %wd, prec2 = %wd\n\n",
                    len1, len2, prec1, prec2);
                flint_printf("i = %wd\n\n", i);
                flint_printf("q = "); acb_printd(q, 50); flint_printf("\n\n");
                flint_printf("w = "); acb_printd(w, 50); flint_printf("\n\n");
                flint_printf("t1a = "); acb_printd(t1a + i, 50); flint_printf("\n\n");
                flint_printf("t1b = "); acb_printd(t1b + i, 50); flint_printf("\n\n");
                flint_printf("t2a = "); acb_printd(t2a + i, 50); flint_printf("\n\n");
                flint_printf("t2b = "); acb_printd(t2b + i, 50); flint_printf("\n\n");
                flint_printf("t3a = "); acb_printd(t3a + i, 50); flint_printf("\n\n");
                flint_printf("t3b = "); acb_printd(t3b + i, 50); flint_printf("\n\n");
                flint_printf("t4a = "); acb_printd(t4a + i, 50); flint_printf("\n\n");
                flint_printf("t4b = "); acb_printd(t4b + i, 50); flint_printf("\n\n");
                abort();
            }
        }

        _acb_vec_clear(t1a, len1);
        _acb_vec_clear(t2a, len1);
        _acb_vec_clear(t3a, len1);
        _acb_vec_clear(t4a, len1);
        _acb_vec_clear(t1b, len2);
        _acb_vec_clear(t2b, len2);
        _acb_vec_clear(t3b, len2);
        _acb_vec_clear(t4b, len2);

        acb_clear(w);
        acb_clear(q);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#21
0
文件: t-atan2.c 项目: bluescarni/arb
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        arb_t a, b, c;
        fmpq_t q, r;
        mpfr_t t, u;
        long prec = 2 + n_randint(state, 200);

        arb_init(a);
        arb_init(b);
        arb_init(c);
        fmpq_init(q);
        fmpq_init(r);
        mpfr_init2(t, prec + 100);
        mpfr_init2(u, prec + 100);

        arb_randtest(a, state, 1 + n_randint(state, 200), 3);
        arb_randtest(b, state, 1 + n_randint(state, 200), 3);
        arb_randtest(c, state, 1 + n_randint(state, 200), 3);

        arb_get_rand_fmpq(q, state, a, 1 + n_randint(state, 200));
        arb_get_rand_fmpq(r, state, b, 1 + n_randint(state, 200));

        fmpq_get_mpfr(t, q, MPFR_RNDN);
        fmpq_get_mpfr(u, r, MPFR_RNDN);
        mpfr_atan2(t, u, t, MPFR_RNDN);

        arb_atan2(c, b, a, prec);

        if (!arb_contains_mpfr(c, t))
        {
            printf("FAIL: containment\n\n");
            printf("a = "); arb_print(a); printf("\n\n");
            printf("b = "); arb_print(b); printf("\n\n");
            printf("c = "); arb_print(c); printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(c);
        fmpq_clear(q);
        fmpq_clear(r);
        mpfr_clear(t);
        mpfr_clear(u);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#22
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 5000; iter++)
    {
        acb_ptr a, b;
        acb_t z, s1, s2, t1, t2;
        long i, p, q, n, prec1, prec2;

        p = n_randint(state, 4);
        q = n_randint(state, 4);
        n = n_randint(state, 100);
        prec1 = 2 + n_randint(state, 500);
        prec2 = 2 + n_randint(state, 500);

        acb_init(z);
        acb_init(s1);
        acb_init(s2);
        acb_init(t1);
        acb_init(t2);

        acb_randtest(z, state, 1 + n_randint(state, 500), 1 + n_randint(state, 5));
        acb_randtest(s1, state, 1 + n_randint(state, 500), 1 + n_randint(state, 5));
        acb_randtest(t1, state, 1 + n_randint(state, 500), 1 + n_randint(state, 5));
        acb_randtest(s2, state, 1 + n_randint(state, 500), 1 + n_randint(state, 5));
        acb_randtest(t2, state, 1 + n_randint(state, 500), 1 + n_randint(state, 5));

        a = _acb_vec_init(p);
        b = _acb_vec_init(q);

        for (i = 0; i < p; i++)
            acb_randtest(a + i, state, 1 + n_randint(state, 100), 1 + n_randint(state, 5));
        for (i = 0; i < q; i++)
            acb_randtest(b + i, state, 1 + n_randint(state, 100), 1 + n_randint(state, 5));

        acb_hypgeom_pfq_sum_forward(s1, t1, a, p, b, q, z, n, prec1);
        acb_hypgeom_pfq_sum_fme(s2, t2, a, p, b, q, z, n, prec2);

        if (!acb_overlaps(s1, s2) || !acb_overlaps(t1, t2))
        {
            printf("FAIL: overlap\n\n");
            printf("z = "); acb_print(a); printf("\n\n");
            printf("s1 = "); acb_print(s1); printf("\n\n");
            printf("s2 = "); acb_print(s2); printf("\n\n");
            printf("t1 = "); acb_print(t1); printf("\n\n");
            printf("t2 = "); acb_print(t2); printf("\n\n");
            abort();
        }

        _acb_vec_clear(a, p);
        _acb_vec_clear(b, q);

        acb_clear(z);
        acb_clear(s1);
        acb_clear(s2);
        acb_clear(t1);
        acb_clear(t2);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#23
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

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

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

        fmpq_poly_mullow(C, A, B, trunc);

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

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

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

            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_mullow_transpose_gauss(d, d, b, trunc, rbits3);
        if (!fmpcb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 1)\n\n");
            abort();
        }

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

        /* test squaring */
        fmpcb_poly_set(b, a);
        fmpcb_poly_mullow_transpose_gauss(c, a, b, trunc, rbits3);
        fmpcb_poly_mullow_transpose_gauss(d, a, a, trunc, rbits3);
        if (!fmpcb_poly_overlaps(c, d))  /* not guaranteed to be identical */
        {
            printf("FAIL (squaring)\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_mullow_transpose_gauss(a, a, a, trunc, rbits3);
        if (!fmpcb_poly_equal(d, a))
        {
            printf("FAIL (aliasing, squaring)\n\n");

            printf("a = "); fmpcb_poly_printd(a, 15); printf("\n\n");
            printf("b = "); fmpcb_poly_printd(b, 15); printf("\n\n");
            printf("d = "); fmpcb_poly_printd(d, 15); printf("\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);
    }

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

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

        fmpcb_poly_init(a);
        fmpcb_poly_init(b);
        fmpcb_poly_init(ab);
        fmpcb_poly_init(ab2);

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

        fmpcb_poly_mullow_classical(ab, a, b, trunc, bits);
        fmpcb_poly_mullow_transpose_gauss(ab2, a, b, trunc, bits);

        if (!fmpcb_poly_overlaps(ab, ab2))
        {
            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");
            printf("ab2 = "); fmpcb_poly_printd(ab2, 15); printf("\n\n");

            abort();
        }

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

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#24
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        long prec, ret1, ret2;
        fmpz_t man, exp;
        fmpr_t x, y;
        mp_limb_t lo;
        fmpr_rnd_t rnd;
        int negative;

        fmpz_init(man);
        fmpz_init(exp);
        fmpr_init(x);
        fmpr_init(y);

        prec = 2 + n_randint(state, 1000);
        if (n_randint(state, 10) == 0)
            prec = FMPR_PREC_EXACT;

        negative = n_randint(state, 2);
        lo = n_randtest(state);
        fmpz_randtest(exp, state, 1 + n_randint(state, 100));
        if (negative)
            fmpz_neg_ui(man, lo);
        else
            fmpz_set_ui(man, lo);

        switch (n_randint(state, 4))
        {
            case 0: rnd = FMPR_RND_DOWN; break;
            case 1: rnd = FMPR_RND_UP; break;
            case 2: rnd = FMPR_RND_FLOOR; break;
            default: rnd = FMPR_RND_CEIL; break;
        }

        ret1 = fmpr_set_round_ui_2exp_fmpz(x, lo, exp, negative, prec, rnd);

        fmpr_set_fmpz_2exp(y, man, exp);
        ret2 = fmpr_set_round(y, y, prec, rnd);

        if (!fmpr_equal(x, y) || ret1 != ret2 ||
            !fmpr_check_ulp(x, ret1, prec) || !fmpr_check_ulp(y, ret2, prec))
        {
            printf("FAIL\n\n");
            printf("prec: %ld\n", prec);
            printf("man = "); fmpz_print(man); printf("\n\n");
            printf("exp = "); fmpz_print(exp); printf("\n\n");
            printf("x = "); fmpr_print(x); printf("\n\n");
            printf("y = "); fmpr_print(y); printf("\n\n");
            printf("ret1 = %ld, ret2 = %ld\n\n", ret1, ret2);
            abort();
        }

        fmpz_clear(man);
        fmpz_clear(exp);
        fmpr_clear(x);
        fmpr_clear(y);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#25
0
文件: t-root.c 项目: certik/arb
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* check (a^(1/m))^m = a */
    for (iter = 0; iter < 10000; iter++)
    {
        fmpcb_t a, b, c;
        long prec;
        ulong m, index;

        fmpcb_init(a);
        fmpcb_init(b);
        fmpcb_init(c);

        m = z_randtest_not_zero(state);
        index = z_randtest(state);

        fmpcb_randtest(a, state, 1 + n_randint(state, 2000), 3);
        fmpcb_randtest(b, state, 1 + n_randint(state, 2000), 3);

        prec = 2 + n_randint(state, 2000);

        fmpcb_root(b, a, m, index, prec);
        fmpcb_pow_si(c, b, m, prec);

        if (!fmpcb_contains(c, a))
        {
            printf("FAIL: containment\n\n");
            printf("m = %ld\n\n", m);
            printf("index = %ld\n\n", index);
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            printf("c = "); fmpcb_print(c); printf("\n\n");
            abort();
        }

        fmpcb_root(a, a, m, index, prec);
        if (!fmpcb_equal(a, b))
        {
            printf("FAIL: aliasing\n\n");
            printf("m = %ld\n\n", m);
            printf("index = %ld\n\n", index);
            printf("a = "); fmpcb_print(a); printf("\n\n");
            printf("b = "); fmpcb_print(b); printf("\n\n");
            abort();
        }

        fmpcb_clear(a);
        fmpcb_clear(b);
        fmpcb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#26
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 3000; iter++)
    {
        long 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))
        {
            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 = "); 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();
        }

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

        acb_poly_set(d, b);
        acb_poly_compose(d, a, d, rbits3);
        if (!acb_poly_equal(d, c))
        {
            printf("FAIL (aliasing 2)\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);
    }

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

    flint_printf("zeta_ui_vec_borwein....");
    fflush(stdout);
    flint_randinit(state);

    for (iter = 0; iter < 100; iter++)
    {
        arb_ptr r;
        ulong n;
        slong i, num, step;
        mpfr_t s;
        slong prec, accuracy;

        prec = 2 + n_randint(state, 1 << n_randint(state, 13));
        num = 1 + n_randint(state, 20);
        step = 1 + n_randint(state, 5);

        r = _arb_vec_init(num);
        mpfr_init2(s, prec + 100);

        do { n = n_randint(state, 1 << n_randint(state, 10)); } while (n < 2);

        arb_zeta_ui_vec_borwein(r, n, num, step, prec);

        for (i = 0; i < num; i++)
        {
            mpfr_zeta_ui(s, (unsigned long) FLINT_MIN(n + i * step, ULONG_MAX), MPFR_RNDN);

            if (!arb_contains_mpfr(r + i, s))
            {
                flint_printf("FAIL: containment\n\n");
                flint_printf("n = %wu\n\n", n + i * step);
                flint_printf("r = "); arb_printd(r + i, prec / 3.33); flint_printf("\n\n");
                flint_printf("s = "); mpfr_printf("%.275Rf\n", s); flint_printf("\n\n");
                abort();
            }

            accuracy = arb_rel_accuracy_bits(r + i);

            if (accuracy < prec - 4)
            {
                flint_printf("FAIL: accuracy = %wd, prec = %wd\n\n", accuracy, prec);
                flint_printf("n = %wu\n\n", n + i * step);
                flint_printf("r = "); arb_printd(r + i, prec / 3.33); flint_printf("\n\n");
                abort();
            }
        }

        _arb_vec_clear(r, num);
        mpfr_clear(s);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#28
0
文件: keiper_li.c 项目: isuruf/arb
int main(int argc, char *argv[])
{
    slong i, len, prec, num_threads;
    char * out_file;
    arb_ptr z;

    if (argc < 2)
    {
        flint_printf("keiper_li n [-prec prec] [-threads num_threads] [-out out_file]\n");
        return 1;
    }

    len = atol(argv[1]) + 1;
    prec = 1.1 * len + 50;
    num_threads = 1;
    out_file = NULL;

    for (i = 1; i < argc; i++)
    {
        if (!strcmp(argv[i], "-prec"))
            prec = atol(argv[i+1]);
        else if (!strcmp(argv[i], "-threads"))
            num_threads = atol(argv[i+1]);
        else if (!strcmp(argv[i], "-out"))
            out_file = argv[i+1];
    }

    flint_set_num_threads(num_threads);

    z = _arb_vec_init(len);

    keiper_li_series(z, len, prec);

    for (i = 0; i < len; i++)
    {
        if (i <= 10 || len - i <= 10)
        {
            flint_printf("%wd: ", i); arb_printd(z + i, 50); flint_printf("\n");
        }
    }

    SHOW_MEMORY_USAGE

    if (out_file != NULL)
    {
        fmpz_t man, exp;
        arf_t t;

        FILE * fp = fopen(out_file, "w");

        fmpz_init(man);
        fmpz_init(exp);
        arf_init(t);

        for (i = 0; i < len; i++)
        {
            arf_get_fmpz_2exp(man, exp, arb_midref(z + i));

            flint_fprintf(fp, "%wd ", i);
            fmpz_fprint(fp, man);
            flint_fprintf(fp, " ");
            fmpz_fprint(fp, exp);
            flint_fprintf(fp, " ");

            arf_set_mag(t, arb_radref(z + i));
            arf_get_fmpz_2exp(man, exp, t);

            fmpz_fprint(fp, man);
            flint_fprintf(fp, " ");
            fmpz_fprint(fp, exp);
            flint_fprintf(fp, "\n");
        }

        fclose(fp);

        fmpz_clear(man);
        fmpz_clear(exp);
        arf_clear(t);
    }

    _arb_vec_clear(z, len);
    flint_cleanup();
    return 0;
}
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 2000; iter++)
    {
        acb_t a0, a1, b, z, w0, w1, t, u;
        long prec0, prec1;
        int modified;

        acb_init(a0);
        acb_init(a1);
        acb_init(b);
        acb_init(z);
        acb_init(w0);
        acb_init(w1);
        acb_init(t);
        acb_init(u);

        modified = n_randint(state, 2);

        prec0 = 2 + n_randint(state, 1000);
        prec1 = 2 + n_randint(state, 1000);

        acb_randtest_maybe_half_int(a0, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest(z, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest(w0, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest(w1, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));

        acb_add_ui(a1, a0, 1, prec0);

        switch (n_randint(state, 4))
        {
            case 0:
                acb_hypgeom_gamma_upper_asymp(w0, a0, z, modified, prec0);
                break;
            case 1:
                acb_hypgeom_gamma_upper_1f1a(w0, a0, z, modified, prec0);
                break;
            case 2:
                acb_hypgeom_gamma_upper_1f1b(w0, a0, z, modified, prec0);
                break;
            default:
                acb_hypgeom_gamma_upper(w0, a0, z, modified, prec0);
        }

        switch (n_randint(state, 4))
        {
            case 0:
                acb_hypgeom_gamma_upper_asymp(w1, a0, z, modified, prec1);
                break;
            case 1:
                acb_hypgeom_gamma_upper_1f1a(w1, a0, z, modified, prec1);
                break;
            case 2:
                acb_hypgeom_gamma_upper_1f1b(w1, a0, z, modified, prec1);
                break;
            default:
                acb_hypgeom_gamma_upper(w1, a0, z, modified, prec1);
        }

        if (!acb_overlaps(w0, w1))
        {
            printf("FAIL: consistency\n\n");
            printf("nu = "); acb_printd(a0, 30); printf("\n\n");
            printf("z = "); acb_printd(z, 30); printf("\n\n");
            printf("w0 = "); acb_printd(w0, 30); printf("\n\n");
            printf("w1 = "); acb_printd(w1, 30); printf("\n\n");
            abort();
        }

        switch (n_randint(state, 4))
        {
            case 0:
                acb_hypgeom_gamma_upper_asymp(w1, a1, z, modified, prec1);
                break;
            case 1:
                acb_hypgeom_gamma_upper_1f1a(w1, a1, z, modified, prec1);
                break;
            case 2:
                acb_hypgeom_gamma_upper_1f1b(w1, a1, z, modified, prec1);
                break;
            default:
                acb_hypgeom_gamma_upper(w1, a1, z, modified, prec1);
        }

        /* a Gamma(a,z) + exp(-z) z^a = Gamma(a+1,z) */
        if (modified)
            acb_one(t);
        else
            acb_pow(t, z, a0, prec0);

        acb_neg(u, z);
        acb_exp(u, u, prec0);
        acb_mul(t, t, u, prec0);

        if (modified)
        {
            acb_mul(b, w1, z, prec0);
            acb_addmul(t, a0, w0, prec0);
            acb_sub(t, t, b, prec0);
        }
        else
        {
            acb_addmul(t, a0, w0, prec0);
            acb_sub(t, t, w1, prec0);
        }

        if (!acb_contains_zero(t))
        {
            printf("FAIL: contiguous relation\n\n");
            printf("nu = "); acb_printd(a0, 30); printf("\n\n");
            printf("z = ");  acb_printd(z, 30); printf("\n\n");
            printf("w0 = "); acb_printd(w0, 30); printf("\n\n");
            printf("w1 = "); acb_printd(w1, 30); printf("\n\n");
            printf("t = "); acb_printd(t, 30); printf("\n\n");
            abort();
        }

        acb_clear(a0);
        acb_clear(a1);
        acb_clear(b);
        acb_clear(z);
        acb_clear(w0);
        acb_clear(w1);
        acb_clear(t);
        acb_clear(u);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
示例#30
0
文件: t-2f1.c 项目: isuruf/arb
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("2f1....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 3000; iter++)
    {
        acb_t a, b, c, z, w1, w2, t;
        slong prec1, prec2;
        int reg1, reg2, ebits;
        int alg1, alg2;

        acb_init(a);
        acb_init(b);
        acb_init(c);
        acb_init(z);
        acb_init(w1);
        acb_init(w2);
        acb_init(t);

        prec1 = 2 + n_randint(state, 300);
        prec2 = 2 + n_randint(state, 300);

        if (n_randint(state, 20) == 0)
            ebits = 30;
        else
            ebits = 5;

        switch (n_randint(state, 3))
        {
            case 0:
                acb_set_si(a, n_randint(state, 500));
                acb_set_si(b, n_randint(state, 500));
                acb_set_si(c, n_randint(state, 10));
                break;
            case 1:
                acb_set_si(a, n_randint(state, 200) - 100);
                acb_set_si(b, n_randint(state, 200) - 100);
                acb_set_si(c, n_randint(state, 200) - 100);
                break;
            default:
                acb_randtest_param(a, state, 1 + n_randint(state, 400), 1 + n_randint(state, ebits));
                acb_randtest_param(b, state, 1 + n_randint(state, 400), 1 + n_randint(state, ebits));
                acb_randtest_param(c, state, 1 + n_randint(state, 400), 1 + n_randint(state, ebits));
        }

        acb_randtest_param(z, state, 1 + n_randint(state, 400), 1 + n_randint(state, ebits));
        acb_randtest(w1, state, 1 + n_randint(state, 400), 1 + n_randint(state, ebits));
        acb_randtest(w2, state, 1 + n_randint(state, 400), 1 + n_randint(state, ebits));

        reg1 = n_randint(state, 2);
        reg2 = n_randint(state, 2);

        alg1 = n_randint(state, 10);
        alg2 = n_randint(state, 10);

        switch (alg1)
        {
            case 0:
                acb_hypgeom_2f1_direct(w1, a, b, c, z, reg1, prec1);
                break;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                acb_hypgeom_2f1_transform(w1, a, b, c, z, reg1, alg1, prec1);
                break;
            case 6:
                acb_hypgeom_2f1_corner(w1, a, b, c, z, reg1, prec1);
                break;
            default:
                acb_hypgeom_2f1(w1, a, b, c, z, reg1, prec1);
        }

        switch (alg2)
        {
            case 0:
                acb_hypgeom_2f1_direct(w2, a, b, c, z, reg2, prec2);
                break;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                acb_hypgeom_2f1_transform(w2, a, b, c, z, reg2, alg2, prec2);
                break;
            case 6:
                acb_hypgeom_2f1_corner(w2, a, b, c, z, reg2, prec2);
                break;
            default:
                acb_hypgeom_2f1(w2, a, b, c, z, reg2, prec2);
        }

        if (reg1 != reg2)
        {
            acb_rgamma(t, c, prec2);

            if (reg1)
                acb_mul(w2, w2, t, prec2);
            else
                acb_mul(w1, w1, t, prec2);
        }

        if (!acb_overlaps(w1, w2))
        {
            flint_printf("FAIL: consistency\n\n");
            flint_printf("iter = %wd, prec1 = %wd, prec2 = %wd\n\n", iter, prec1, prec2);
            flint_printf("alg1 = %d, alg2 = %d\n\n", alg1, alg2);
            flint_printf("reg1 = %d, reg2 = %d\n\n", reg1, reg2);
            flint_printf("a = "); acb_printd(a, 30); flint_printf("\n\n");
            flint_printf("b = "); acb_printd(b, 30); flint_printf("\n\n");
            flint_printf("c = "); acb_printd(c, 30); flint_printf("\n\n");
            flint_printf("z = "); acb_printd(z, 30); flint_printf("\n\n");
            flint_printf("w1 = "); acb_printd(w1, 30); flint_printf("\n\n");
            flint_printf("w2 = "); acb_printd(w2, 30); flint_printf("\n\n");
            abort();
        }

        acb_clear(a);
        acb_clear(b);
        acb_clear(c);
        acb_clear(z);
        acb_clear(w1);
        acb_clear(w2);
        acb_clear(t);
    }

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