Пример #1
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t q;
        mpfr_t t;
        slong prec = 2 + n_randint(state, 200);

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

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

        fmpq_get_mpfr(t, q, MPFR_RNDN);
        mpfr_sinh(t, t, MPFR_RNDN);

        arb_sinh(b, a, prec);

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

        arb_sinh(a, a, prec);

        if (!arb_equal(a, b))
        {
            flint_printf("FAIL: aliasing\n\n");
            flint_abort();
        }

        arb_clear(a);
        arb_clear(b);
        fmpq_clear(q);
        mpfr_clear(t);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #2
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 500 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        mag_t u, v;
        slong aprec, bprec;
        slong abits, bbits;

        aprec = 2 + n_randint(state, 1000);
        bprec = 2 + n_randint(state, 1000);
        abits = 2 + n_randint(state, 100);
        bbits = 2 + n_randint(state, 100);

        arb_init(a);
        arb_init(b);
        mag_init(u);
        mag_init(v);

        arb_randtest(a, state, aprec, abits);
        arb_randtest(b, state, bprec, bbits);

        if (arb_is_nonnegative(a) && arb_is_nonnegative(b))
        {
            acb_dirichlet_backlund_s_bound(u, a);
            acb_dirichlet_backlund_s_bound(v, b);

            if ((arb_lt(a, b) && mag_cmp(u, v) > 0) ||
                (arb_gt(a, b) && mag_cmp(u, v) < 0))
            {
                flint_printf("FAIL: increasing on t >= 0\n\n");
                flint_printf("a = "); arb_print(a); flint_printf("\n\n");
                flint_printf("b = "); arb_print(b); flint_printf("\n\n");
                flint_printf("u = "); mag_print(u); flint_printf("\n\n");
                flint_printf("v = "); mag_print(v); flint_printf("\n\n");
                flint_abort();
            }
        }

        arb_clear(a);
        arb_clear(b);
        mag_clear(u);
        mag_clear(v);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #3
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, c;
        ulong k;
        slong prec;

        prec = 2 + n_randint(state, 2000);
        k = n_randtest_not_zero(state);

        arb_init(a);
        arb_init(b);
        arb_init(c);

        arb_randtest(a, state, 1 + n_randint(state, 2000), 1 + n_randint(state, 100));
        arb_randtest(b, state, 1 + n_randint(state, 2000), 1 + n_randint(state, 100));

        arb_root_ui(b, a, k, prec);
        arb_pow_ui(c, b, k, prec);

        if (!arb_contains(c, a))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("k = %wu\n", k);
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            abort();
        }

        arb_root_ui(a, a, k, prec);

        if (!arb_equal(a, b))
        {
            flint_printf("FAIL: aliasing\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_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("sin_cos_pi....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, c, d, e;
        slong prec = 2 + n_randint(state, 200);

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

        arb_randtest(a, state, 1 + n_randint(state, 200), 10);
        arb_randtest(b, state, 1 + n_randint(state, 200), 10);
        arb_randtest(c, state, 1 + n_randint(state, 200), 10);
        arb_randtest(d, state, 1 + n_randint(state, 200), 10);
        arb_randtest(e, state, 1 + n_randint(state, 200), 10);

        arb_const_pi(b, prec);
        arb_mul(b, b, a, prec);
        arb_sin_cos(b, d, b, prec);

        arb_sin_cos_pi(c, e, a, prec);

        if (!arb_overlaps(b, c) || !arb_overlaps(d, e))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            flint_printf("d = "); arb_print(d); flint_printf("\n\n");
            flint_printf("e = "); arb_print(e); flint_printf("\n\n");
            flint_abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(c);
        arb_clear(d);
        arb_clear(e);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #5
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_poly_t f, g;
        arb_t x, y1, z1, y2, z2;

        arb_init(x);
        arb_init(y1);
        arb_init(z1);
        arb_init(y2);
        arb_init(z2);
        arb_poly_init(f);
        arb_poly_init(g);

        arb_randtest(x, state, 2 + n_randint(state, 1000), 5);
        arb_poly_randtest(f, state, 2 + n_randint(state, 100), 2 + n_randint(state, 1000), 5);
        arb_poly_derivative(g, f, 2 + n_randint(state, 1000));

        arb_poly_evaluate2_rectangular(y1, z1, f, x, 2 + n_randint(state, 1000));

        arb_poly_evaluate_horner(y2, f, x, 2 + n_randint(state, 1000));
        arb_poly_evaluate_horner(z2, g, x, 2 + n_randint(state, 1000));

        if (!arb_overlaps(y1, y2) || !arb_overlaps(z1, z2))
        {
            flint_printf("FAIL\n\n");
            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("x = "); arb_printd(x, 15); flint_printf("\n\n");
            flint_printf("y1 = "); arb_printd(y1, 15); flint_printf("\n\n");
            flint_printf("z1 = "); arb_printd(z1, 15); flint_printf("\n\n");
            flint_printf("y2 = "); arb_printd(y2, 15); flint_printf("\n\n");
            flint_printf("z2 = "); arb_printd(z2, 15); flint_printf("\n\n");
            abort();
        }

        arb_poly_clear(f);
        arb_poly_clear(g);
        arb_clear(x);
        arb_clear(y1);
        arb_clear(z1);
        arb_clear(y2);
        arb_clear(z2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #6
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    for (iter = 0; iter < 100000; iter++)
    {
        arb_t x;
        arf_t y;
        fmpz_t a, b, exp;

        arb_init(x);
        arf_init(y);
        fmpz_init(a);
        fmpz_init(b);
        fmpz_init(exp);

        arb_randtest(x, state, 200, 10);

        arb_get_interval_fmpz_2exp(a, b, exp, x);

        arf_set_fmpz_2exp(y, a, exp);
        if (!arb_contains_arf(x, y))
        {
            flint_printf("FAIL:\n\n");
            flint_printf("x = "); arb_print(x); flint_printf("\n\n");
            flint_printf("a = "); fmpz_print(a);
            flint_printf(" exp = "); fmpz_print(exp); flint_printf("\n\n");
            abort();
        }

        arf_set_fmpz_2exp(y, b, exp);
        if (!arb_contains_arf(x, y))
        {
            flint_printf("FAIL:\n\n");
            flint_printf("x = "); arb_print(x); flint_printf("\n\n");
            flint_printf("b = "); fmpz_print(b);
            flint_printf(" exp = "); fmpz_print(exp); flint_printf("\n\n");
            abort();
        }

        arb_clear(x);
        arf_clear(y);
        fmpz_clear(a);
        fmpz_clear(b);
        fmpz_clear(exp);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #7
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        arb_t a, b, c;
        slong prec = 2 + n_randint(state, 200);

        arb_init(a);
        arb_init(b);
        arb_init(c);

        arb_randtest(a, state, 1 + n_randint(state, 200), 10);

        arb_rsqrt(b, a, prec);

        arb_inv(c, b, prec);
        arb_mul(c, c, c, prec);

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

        arb_rsqrt(a, a, prec);

        if (!arb_equal(a, b))
        {
            flint_printf("FAIL: aliasing\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #8
0
void
arb_mat_randtest(arb_mat_t mat, flint_rand_t state, slong prec, slong mag_bits)
{
    slong i, j;

    if (n_randint(state, 2))
        for (i = 0; i < arb_mat_nrows(mat); i++)
            for (j = 0; j < arb_mat_ncols(mat); j++)
                arb_randtest(arb_mat_entry(mat, i, j), state, prec, mag_bits);
    else
        for (i = 0; i < arb_mat_nrows(mat); i++)
            for (j = 0; j < arb_mat_ncols(mat); j++)
                arb_randtest_precise(arb_mat_entry(mat, i, j), state, prec, mag_bits);
}
Пример #9
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_ptr x, y;
        arb_t s1, s2, z;
        slong i, len, prec, xbits, ybits, ebits;
        int initial, subtract, revx, revy;

        if (n_randint(state, 100) == 0)
            len = n_randint(state, 100);
        else if (n_randint(state, 10) == 0)
            len = n_randint(state, 10);
        else
            len = n_randint(state, 3);

        if (n_randint(state, 10) != 0 || len > 10)
        {
            prec = 2 + n_randint(state, 500);
            xbits = 2 + n_randint(state, 500);
            ybits = 2 + n_randint(state, 500);
        }
        else
        {
            prec = 2 + n_randint(state, 4000);
            xbits = 2 + n_randint(state, 4000);
            ybits = 2 + n_randint(state, 4000);
        }

        if (n_randint(state, 100) == 0)
            ebits = 2 + n_randint(state, 100);
        else
            ebits = 2 + n_randint(state, 10);

        initial = n_randint(state, 2);
        subtract = n_randint(state, 2);
        revx = n_randint(state, 2);
        revy = n_randint(state, 2);

        x = _arb_vec_init(len);
        y = _arb_vec_init(len);
        arb_init(s1);
        arb_init(s2);
        arb_init(z);

        switch (n_randint(state, 3))
        {
            case 0:
                for (i = 0; i < len; i++)
                {
                    arb_randtest(x + i, state, xbits, ebits);
                    arb_randtest(y + i, state, ybits, ebits);
                }
                break;

            /* Test with cancellation */
            case 1:
                for (i = 0; i < len; i++)
                {
                    if (i <= len / 2)
                    {
                        arb_randtest(x + i, state, xbits, ebits);
                        arb_randtest(y + i, state, ybits, ebits);
                    }
                    else
                    {
                        arb_neg(x + i, x + len - i - 1);
                        arb_set(y + i, y + len - i - 1);
                    }
                }
                break;

            default:
                for (i = 0; i < len; i++)
                {
                    if (i <= len / 2)
                    {
                        arb_randtest(x + i, state, xbits, ebits);
                        arb_randtest(y + i, state, ybits, ebits);
                    }
                    else
                    {
                        arb_neg_round(x + i, x + len - i - 1, 2 + n_randint(state, 500));
                        arb_set_round(y + i, y + len - i - 1, 2 + n_randint(state, 500));
                    }
                }
                break;
        }

        arb_randtest(s1, state, 200, 100);
        arb_randtest(s2, state, 200, 100);
        arb_randtest(z, state, xbits, ebits);

        arb_approx_dot(s1, initial ? z : NULL, subtract,
            revx ? (x + len - 1) : x, revx ? -1 : 1,
            revy ? (y + len - 1) : y, revy ? -1 : 1,
            len, prec);
        mag_zero(arb_radref(s1));

        /* With the fast algorithm, we expect identical results when
           reversing the vectors. */
        if (ebits <= 12)
        {
            arb_approx_dot(s2, initial ? z : NULL, subtract,
                !revx ? (x + len - 1) : x, !revx ? -1 : 1,
                !revy ? (y + len - 1) : y, !revy ? -1 : 1,
                len, prec);
            mag_zero(arb_radref(s2));

            if (!arb_equal(s1, s2))
            {
                flint_printf("FAIL (reversal)\n\n");
                flint_printf("iter = %wd, len = %wd, prec = %wd, ebits = %wd\n\n", iter, len, prec, ebits);

                if (initial)
                {
                    flint_printf("z = ", i); arb_printn(z, 100, ARB_STR_MORE); flint_printf(" (%wd)\n\n", arb_bits(z));
                }

                for (i = 0; i < len; i++)
                {
                    flint_printf("x[%wd] = ", i); arb_printn(x + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(x + i));
                    flint_printf("y[%wd] = ", i); arb_printn(y + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(y + i));
                }
                flint_printf("\n\n");
                flint_printf("s1 = "); arb_printn(s1, 100, ARB_STR_MORE); flint_printf("\n\n");
                flint_printf("s2 = "); arb_printn(s2, 100, ARB_STR_MORE); flint_printf("\n\n");
                flint_abort();
            }
        }

        /* Verify that radii are ignored */
        for (i = 0; i < len; i++)
        {
            arb_get_mid_arb(x + i, x + i);
            arb_get_mid_arb(y + i, y + i);
        }
        arb_get_mid_arb(z, z);

        arb_approx_dot(s2, initial ? z : NULL, subtract,
            revx ? (x + len - 1) : x, revx ? -1 : 1,
            revy ? (y + len - 1) : y, revy ? -1 : 1,
            len, prec);
        mag_zero(arb_radref(s2));

        if (!arb_equal(s1, s2))
        {
            flint_printf("FAIL (radii)\n\n");
            flint_printf("iter = %wd, len = %wd, prec = %wd, ebits = %wd\n\n", iter, len, prec, ebits);

            if (initial)
            {
                flint_printf("z = ", i); arb_printn(z, 100, ARB_STR_MORE); flint_printf(" (%wd)\n\n", arb_bits(z));
            }

            for (i = 0; i < len; i++)
            {
                flint_printf("x[%wd] = ", i); arb_printn(x + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(x + i));
                flint_printf("y[%wd] = ", i); arb_printn(y + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(y + i));
            }
            flint_printf("\n\n");
            flint_printf("s1 = "); arb_printn(s1, 100, ARB_STR_MORE); flint_printf("\n\n");
            flint_printf("s2 = "); arb_printn(s2, 100, ARB_STR_MORE); flint_printf("\n\n");
            flint_abort();
        }

        /* Compare with arb_dot */
        arb_approx_dot(s2, initial ? z : NULL, subtract,
            revx ? (x + len - 1) : x, revx ? -1 : 1,
            revy ? (y + len - 1) : y, revy ? -1 : 1,
            len, prec);

        {
            mag_t err, xx, yy;

            mag_init(err);
            mag_init(xx);
            mag_init(yy);

            if (initial)
                arb_get_mag(err, z);

            for (i = 0; i < len; i++)
            {
                arb_get_mag(xx, revx ? x + len - 1 - i : x + i);
                arb_get_mag(yy, revx ? y + len - 1 - i : y + i);
                mag_addmul(err, xx, yy);
            }

            mag_mul_2exp_si(err, err, -prec + 2);
            arb_add_error_mag(s2, err);

            if (!arb_contains(s2, s1))
            {
                flint_printf("FAIL (inclusion)\n\n");
                flint_printf("iter = %wd, len = %wd, prec = %wd, ebits = %wd\n\n", iter, len, prec, ebits);

                if (initial)
                {
                    flint_printf("z = ", i); arb_printn(z, 100, ARB_STR_MORE); flint_printf(" (%wd)\n\n", arb_bits(z));
                }

                for (i = 0; i < len; i++)
                {
                    flint_printf("x[%wd] = ", i); arb_printn(x + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(x + i));
                    flint_printf("y[%wd] = ", i); arb_printn(y + i, 100, ARB_STR_MORE); flint_printf(" (%wd)\n", arb_bits(y + i));
                }
                flint_printf("\n\n");
                flint_printf("s1 = "); arb_printn(s1, 100, ARB_STR_MORE); flint_printf("\n\n");
                flint_printf("s2 = "); arb_printn(s2, 100, ARB_STR_MORE); flint_printf("\n\n");
                flint_abort();
            }

            mag_clear(err);
            mag_clear(xx);
            mag_clear(yy);
        }

        arb_clear(s1);
        arb_clear(s2);
        arb_clear(z);
        _arb_vec_clear(x, len);
        _arb_vec_clear(y, len);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #10
0
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;
}
Пример #11
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 500; iter++)
    {
        long m, n1, n2, bits1, bits2, bits3;
        int deflate;
        arb_poly_t S, A, B, C, D, E, F;
        arb_t a, a1;

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

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

        arb_poly_init(S);
        arb_poly_init(A);
        arb_poly_init(B);
        arb_poly_init(C);
        arb_poly_init(D);
        arb_poly_init(E);
        arb_poly_init(F);
        arb_init(a);
        arb_init(a1);

        deflate = n_randint(state, 2);

        arb_poly_randtest(S, state, m, bits1, 3);
        arb_randtest_precise(a, state, bits1, 3);
        arb_poly_set_coeff_arb(S, 0, a);

        if (n_randint(state, 2))
            arb_randtest(a, state, bits1, 3);
        else
            arb_one(a);

        arb_poly_zeta_series(A, S, a, deflate, n1, bits2);
        arb_poly_zeta_series(B, S, a, deflate, n2, bits3);

        arb_poly_set(C, A);
        arb_poly_truncate(C, FLINT_MIN(n1, n2));
        arb_poly_truncate(B, FLINT_MIN(n1, n2));

        if (!arb_poly_overlaps(B, C))
        {
            printf("FAIL\n\n");
            printf("S = "); arb_poly_printd(S, 15); printf("\n\n");
            printf("a = "); arb_printd(a, 15); printf("\n\n");
            printf("A = "); arb_poly_printd(A, 15); printf("\n\n");
            printf("B = "); arb_poly_printd(B, 15); printf("\n\n");
            abort();
        }

        /* check zeta(s,a) = zeta(s,a+1) + a^(-s) */
        arb_poly_set_arb(D, a);
        arb_poly_log_series(D, D, n1, bits2);
        arb_poly_mullow(D, D, S, n1, bits2);
        arb_poly_neg(D, D);
        arb_poly_exp_series(D, D, n1, bits2);

        arb_add_ui(a1, a, 1, bits2);
        arb_poly_zeta_series(E, S, a1, deflate, n1, bits2);
        arb_poly_add(E, E, D, bits2);

        if (!arb_poly_overlaps(A, E))
        {
            printf("FAIL (functional equation)\n\n");
            printf("S = "); arb_poly_printd(S, 15); printf("\n\n");
            printf("a = "); arb_printd(a, 15); printf("\n\n");
            printf("A = "); arb_poly_printd(A, 15); printf("\n\n");
            printf("E = "); arb_poly_printd(A, 15); printf("\n\n");
            abort();
        }

        arb_poly_zeta_series(S, S, a, deflate, n1, bits2);
        if (!arb_poly_overlaps(A, S))
        {
            printf("FAIL (aliasing)\n\n");
            abort();
        }

        arb_poly_clear(S);
        arb_poly_clear(A);
        arb_poly_clear(B);
        arb_poly_clear(C);
        arb_poly_clear(D);
        arb_poly_clear(E);
        arb_poly_clear(F);
        arb_clear(a);
        arb_clear(a1);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #12
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;
}
Пример #13
0
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;
}
Пример #14
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, c;
        fmpq_t q, r;
        mpfr_t t, u;
        slong 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_agm(c, a, b, prec);

        if (arb_equal(a, b))
        {
            if (!arb_contains(c, a))
            {
                flint_printf("FAIL: containment (identity)\n\n");
                flint_printf("a = "); arb_print(a); flint_printf("\n\n");
                flint_printf("b = "); arb_print(b); flint_printf("\n\n");
                flint_printf("c = "); arb_print(c); flint_printf("\n\n");
                abort();
            }
        }
        else
        {
            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_agm(t, t, u, MPFR_RNDN);

            if (!arb_contains_mpfr(c, t))
            {
                flint_printf("FAIL: containment\n\n");
                flint_printf("a = "); arb_print(a); flint_printf("\n\n");
                flint_printf("b = "); arb_print(b); flint_printf("\n\n");
                flint_printf("c = "); arb_print(c); flint_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();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #15
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, c;
        fmpq_t x, y, z;

        arb_init(a);
        arb_init(b);
        arb_init(c);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));

        arb_mul(c, a, b, 2 + n_randint(state, 200));
        fmpq_mul(z, x, y);

        if (!arb_contains_fmpq(c, z))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("x = "); fmpq_print(x); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("y = "); fmpq_print(y); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            flint_printf("z = "); fmpq_print(z); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(c);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of c and a */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t x, y, z;

        arb_init(a);
        arb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));

        arb_mul(a, a, b, 2 + n_randint(state, 200));
        fmpq_mul(z, x, y);

        if (!arb_contains_fmpq(a, z))
        {
            flint_printf("FAIL: aliasing (c, a)\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("x = "); fmpq_print(x); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("y = "); fmpq_print(y); flint_printf("\n\n");
            flint_printf("z = "); fmpq_print(z); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of c and b */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t x, y, z;

        arb_init(a);
        arb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));

        arb_mul(b, a, b, 2 + n_randint(state, 200));
        fmpq_mul(z, x, y);

        if (!arb_contains_fmpq(b, z))
        {
            flint_printf("FAIL: aliasing (c, b)\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("x = "); fmpq_print(x); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("y = "); fmpq_print(y); flint_printf("\n\n");
            flint_printf("z = "); fmpq_print(z); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #16
0
int main()
{
    slong iter, iter2;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, c;
        fmpq_t x, y, z;

        arb_init(a);
        arb_init(b);
        arb_init(c);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));

        arb_mul(c, a, b, 2 + n_randint(state, 200));
        fmpq_mul(z, x, y);

        if (!arb_contains_fmpq(c, z))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("x = "); fmpq_print(x); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("y = "); fmpq_print(y); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            flint_printf("z = "); fmpq_print(z); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(c);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of c and a */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t x, y, z;

        arb_init(a);
        arb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));

        arb_mul(a, a, b, 2 + n_randint(state, 200));
        fmpq_mul(z, x, y);

        if (!arb_contains_fmpq(a, z))
        {
            flint_printf("FAIL: aliasing (c, a)\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("x = "); fmpq_print(x); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("y = "); fmpq_print(y); flint_printf("\n\n");
            flint_printf("z = "); fmpq_print(z); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of c and b */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t x, y, z;

        arb_init(a);
        arb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        arb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));

        arb_mul(b, a, b, 2 + n_randint(state, 200));
        fmpq_mul(z, x, y);

        if (!arb_contains_fmpq(b, z))
        {
            flint_printf("FAIL: aliasing (c, b)\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("x = "); fmpq_print(x); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("y = "); fmpq_print(y); flint_printf("\n\n");
            flint_printf("z = "); fmpq_print(z); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* main test */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t x, y, z, v;
        slong prec;

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

        for (iter2 = 0; iter2 < 100; iter2++)
        {
            arb_randtest_special(x, state, n_randint(state,2) ? 2000 : 200, 200);
            arb_randtest_special(y, state, n_randint(state,2) ? 2000 : 200, 200);

            prec = 2 + n_randint(state, 2000);

            switch (n_randint(state, 5))
            {
            case 0:
                arb_mul(z, x, y, prec);
                arb_mul_naive(v, x, y, prec);

                if (!arf_equal(arb_midref(z), arb_midref(v))
                    || !mag_close(arb_radref(z), arb_radref(v)))
                {
                    flint_printf("FAIL!\n");
                    flint_printf("x = "); arb_print(x); flint_printf("\n\n");
                    flint_printf("y = "); arb_print(y); flint_printf("\n\n");
                    flint_printf("z = "); arb_print(z); flint_printf("\n\n");
                    flint_printf("v = "); arb_print(v); flint_printf("\n\n");
                    abort();
                }
                break;

            case 1:
                arb_set(y, x);
                arb_mul(z, x, y, prec);
                arb_mul(v, x, x, prec);

                if (!arf_equal(arb_midref(z), arb_midref(v))
                    || !mag_close(arb_radref(z), arb_radref(v)))
                {
                    flint_printf("FAIL (aliasing 1)!\n");
                    flint_printf("x = "); arb_print(x); flint_printf("\n\n");
                    flint_printf("z = "); arb_print(z); flint_printf("\n\n");
                    flint_printf("v = "); arb_print(v); flint_printf("\n\n");
                    abort();
                }
                break;

            case 2:
                arb_mul(v, x, x, prec);
                arb_mul(x, x, x, prec);

                if (!arb_equal(v, x))
                {
                    flint_printf("FAIL (aliasing 2)!\n");
                    flint_printf("x = "); arb_print(x); flint_printf("\n\n");
                    flint_printf("z = "); arb_print(z); flint_printf("\n\n");
                    flint_printf("v = "); arb_print(v); flint_printf("\n\n");
                    abort();
                }
                break;

            case 3:
                arb_mul(v, x, y, prec);
                arb_mul(x, x, y, prec);

                if (!arb_equal(v, x))
                {
                    flint_printf("FAIL (aliasing 3)!\n");
                    flint_printf("x = "); arb_print(x); flint_printf("\n\n");
                    flint_printf("y = "); arb_print(y); flint_printf("\n\n");
                    flint_printf("v = "); arb_print(v); flint_printf("\n\n");
                    abort();
                }
                break;

            default:
                arb_mul(v, x, y, prec);
                arb_mul(x, y, x, prec);

                if (!arf_equal(arb_midref(x), arb_midref(v))
                    || !mag_close(arb_radref(x), arb_radref(v)))
                {
                    flint_printf("FAIL (aliasing 4)!\n");
                    flint_printf("x = "); arb_print(x); flint_printf("\n\n");
                    flint_printf("y = "); arb_print(y); flint_printf("\n\n");
                    flint_printf("v = "); arb_print(v); flint_printf("\n\n");
                    abort();
                }
                break;
            }
        }

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

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #17
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* compare with mpfr */
    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t q;
        mpfr_t t;
        slong prec = 2 + n_randint(state, 200);

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

        do {
            arb_randtest(a, state, 1 + n_randint(state, 200), 10);
        } while (arb_contains_nonpositive(a));

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

        fmpq_get_mpfr(t, q, MPFR_RNDN);

        /* todo: estimate cancellation precisely */
        if (mpfr_cmp_d(t, 1 - 1e-10) > 0 && mpfr_cmp_d(t, 1 + 1e-10) < 0)
        {
            mpfr_set_prec(t, prec + 1000);
            fmpq_get_mpfr(t, q, MPFR_RNDN);
        }

        mpfr_log(t, t, MPFR_RNDN);

        arb_log(b, a, prec);

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

        arb_log(a, a, prec);

        if (!arb_equal(a, b))
        {
            flint_printf("FAIL: aliasing\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        fmpq_clear(q);
        mpfr_clear(t);
    }

    /* compare with mpfr (higher precision) */
    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t q;
        mpfr_t t;
        slong prec = 2 + n_randint(state, 6000);

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

        do {
            arb_randtest(a, state, 1 + n_randint(state, 6000), 10);
        } while (arb_contains_nonpositive(a));

        arb_randtest(b, state, 1 + n_randint(state, 6000), 10);
        arb_get_rand_fmpq(q, state, a, 1 + n_randint(state, 200));

        fmpq_get_mpfr(t, q, MPFR_RNDN);

        /* todo: estimate cancellation precisely */
        if (mpfr_cmp_d(t, 1 - 1e-10) > 0 && mpfr_cmp_d(t, 1 + 1e-10) < 0)
        {
            mpfr_set_prec(t, prec + 10000);
            fmpq_get_mpfr(t, q, MPFR_RNDN);
        }

        mpfr_log(t, t, MPFR_RNDN);

        arb_log(b, a, prec);

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

        arb_log(a, a, prec);

        if (!arb_equal(a, b))
        {
            flint_printf("FAIL: aliasing\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        fmpq_clear(q);
        mpfr_clear(t);
    }

    /* test large numbers */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, ab, lab, la, lb, lalb;
        slong prec = 2 + n_randint(state, 6000);

        arb_init(a);
        arb_init(b);
        arb_init(ab);
        arb_init(lab);
        arb_init(la);
        arb_init(lb);
        arb_init(lalb);

        arb_randtest(a, state, 1 + n_randint(state, 400), 400);
        arb_randtest(b, state, 1 + n_randint(state, 400), 400);

        arb_log(la, a, prec);
        arb_log(lb, b, prec);
        arb_mul(ab, a, b, prec);
        arb_log(lab, ab, prec);
        arb_add(lalb, la, lb, prec);

        if (!arb_overlaps(lab, lalb))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("la = "); arb_print(la); flint_printf("\n\n");
            flint_printf("lb = "); arb_print(lb); flint_printf("\n\n");
            flint_printf("ab = "); arb_print(ab); flint_printf("\n\n");
            flint_printf("lab = "); arb_print(lab); flint_printf("\n\n");
            flint_printf("lalb = "); arb_print(lalb); flint_printf("\n\n");
            abort();
        }

        arb_log(a, a, prec);
        if (!arb_overlaps(a, la))
        {
            flint_printf("FAIL: aliasing\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        arb_clear(ab);
        arb_clear(lab);
        arb_clear(la);
        arb_clear(lb);
        arb_clear(lalb);
    }

    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_arf_bb....");
    fflush(stdout);

    flint_randinit(state);

    for (iter = 0; iter < 5000; iter++)
    {
        arb_t x, y, z;
        slong prec, prec2;

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

        prec = 2 + n_randint(state, 8000);

        arb_randtest(x, state, 1 + n_randint(state, 8000), 3);
        mag_zero(arb_radref(x));

        if (n_randint(state, 2))
            arb_mul_2exp_si(x, x, 1 + n_randint(state, 40));
        else
            arb_mul_2exp_si(x, x, -n_randint(state, 1.5 * prec));

        if (!arf_is_special(arb_midref(x)))
            prec2 = prec + 100 + 2 * (-ARF_EXP(arb_midref(x)));
        else
            prec2 = prec + 100;

        arb_atan_arf_via_mpfr(y, arb_midref(x), prec2);
        arb_atan_arf_bb(z, arb_midref(x), prec);

        if (!arb_contains(z, y))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("prec = %wd\n\n", prec);
            flint_printf("x = "); arb_printd(x, 50); flint_printf("\n\n");
            flint_printf("y = "); arb_printd(y, 50); flint_printf("\n\n");
            flint_printf("z = "); arb_printd(z, 50); flint_printf("\n\n");
            abort();
        }

        if (arb_rel_accuracy_bits(z) < prec - 2)
        {
            flint_printf("FAIL: poor accuracy\n\n");
            flint_printf("prec = %wd,  acc = %wd\n\n", prec, arb_rel_accuracy_bits(z));
            flint_printf("x = "); arb_printd(x, 50); flint_printf("\n\n");
            flint_printf("y = "); arb_printd(y, 50); flint_printf("\n\n");
            flint_printf("z = "); arb_printd(z, 50); flint_printf("\n\n");
            abort();
        }

        arb_atan_arf_bb(x, arb_midref(x), prec);

        if (!arb_overlaps(x, z))
        {
            flint_printf("FAIL: aliasing\n\n");
            abort();
        }

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

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #19
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_t a;
        arf_t b;
        fmpq_t am, ar, bm, t;
        int c1, c2;

        arb_init(a);
        arf_init(b);

        fmpq_init(am);
        fmpq_init(ar);
        fmpq_init(bm);
        fmpq_init(t);

        arb_randtest(a, state, 1 + n_randint(state, 500), 14);
        arf_randtest(b, state, 1 + n_randint(state, 500), 14);

        arf_get_fmpq(am, arb_midref(a));
        mag_get_fmpq(ar, arb_radref(a));
        arf_get_fmpq(bm, b);

        c1 = arb_contains_arf(a, b);

        fmpq_sub(t, am, ar);
        c2 = fmpq_cmp(t, bm) <= 0;

        fmpq_add(t, am, ar);
        c2 = c2 && (fmpq_cmp(t, bm) >= 0);

        if (c1 != c2)
        {
            flint_printf("FAIL:\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arf_print(b); flint_printf("\n\n");
            flint_printf("am = "); fmpq_print(am); flint_printf("\n\n");
            flint_printf("ar = "); fmpq_print(ar); flint_printf("\n\n");
            flint_printf("bm = "); fmpq_print(bm); flint_printf("\n\n");
            flint_printf("t = "); fmpq_print(t); flint_printf("\n\n");
            flint_printf("c1 = %d, c2 = %d\n\n", c1, c2);
            abort();
        }

        arb_clear(a);
        arf_clear(b);

        fmpq_clear(am);
        fmpq_clear(ar);
        fmpq_clear(bm);
        fmpq_clear(t);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #20
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

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

        arb_init(a);
        arb_init(b);
        arb_init(c);
        fmpq_init(q);
        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));

        fmpq_get_mpfr(t, q, MPFR_RNDN);
        mpfr_sinh_cosh(t, u, t, MPFR_RNDN);

        arb_sinh_cosh(b, c, a, prec);

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

        if (!arb_contains_mpfr(c, u))
        {
            flint_printf("FAIL: containment (cos)\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            abort();
        }

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

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #21
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        acb_t s, a;
        acb_ptr z1, z2;
        slong i, len, prec1, prec2;
        int deflate;

        acb_init(s);
        acb_init(a);

        if (n_randint(state, 2))
        {
            acb_randtest(s, state, 1 + n_randint(state, 300), 3);
        }
        else
        {
            arb_set_ui(acb_realref(s), 1);
            arb_mul_2exp_si(acb_realref(s), acb_realref(s), -1);
            arb_randtest(acb_imagref(s), state, 1 + n_randint(state, 300), 4);
        }

        switch (n_randint(state, 3))
        {
            case 0:
                acb_randtest(a, state, 1 + n_randint(state, 300), 3);
                break;
            case 1:
                arb_randtest(acb_realref(a), state, 1 + n_randint(state, 300), 3);
                break;
            case 2:
                acb_one(a);
                break;
        }

        prec1 = 2 + n_randint(state, 300);
        prec2 = prec1 + 30;
        len = 1 + n_randint(state, 20);

        deflate = n_randint(state, 2);

        z1 = _acb_vec_init(len);
        z2 = _acb_vec_init(len);

        _acb_poly_zeta_cpx_series(z1, s, a, deflate, len, prec1);
        _acb_poly_zeta_cpx_series(z2, s, a, deflate, len, prec2);

        for (i = 0; i < len; i++)
        {
            if (!acb_overlaps(z1 + i, z2 + i))
            {
                flint_printf("FAIL: overlap\n\n");
                flint_printf("iter = %wd\n", iter);
                flint_printf("deflate = %d, len = %wd, i = %wd\n\n", deflate, len, i);
                flint_printf("s = "); acb_printd(s, prec1 / 3.33); flint_printf("\n\n");
                flint_printf("a = "); acb_printd(a, prec1 / 3.33); flint_printf("\n\n");
                flint_printf("z1 = "); acb_printd(z1 + i, prec1 / 3.33); flint_printf("\n\n");
                flint_printf("z2 = "); acb_printd(z2 + i, prec2 / 3.33); flint_printf("\n\n");
                abort();
            }
        }

        acb_clear(a);
        acb_clear(s);
        _acb_vec_clear(z1, len);
        _acb_vec_clear(z2, len);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #22
0
int main()
{
    slong iter;

    FLINT_TEST_INIT(state);

    {
        ulong k;

        arb_t a,b;
        arf_t c,d;

        fmpq_poly_t p;

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

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

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

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

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

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

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

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

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

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

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

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

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


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

        arb_t a,b;
        arf_t c,d;

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

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

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

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

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

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

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

    FLINT_TEST_CLEANUP(state);

    return 0;
}
Пример #23
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

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

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

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

        fmpq_get_mpfr(t, q, MPFR_RNDN);
        mpfr_asin(t, t, MPFR_RNDN);

        arb_asin(b, a, prec);

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

        arb_asin(a, a, prec);

        if (!arb_equal(a, b))
        {
            printf("FAIL: aliasing\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        fmpq_clear(q);
        mpfr_clear(t);
    }

    /* check large arguments */
    for (iter = 0; iter < 10000; iter++)
    {
        arb_t a, b, c;
        long prec1, prec2;

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

        arb_init(a);
        arb_init(b);
        arb_init(c);

        arb_randtest_precise(a, state, 1 + n_randint(state, 1000), 100);

        arb_asin(b, a, prec1);
        arb_asin(c, a, prec2);

        if (!arb_overlaps(b, c))
        {
            printf("FAIL: overlap\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();
        }

        /* check sin(asin(x)) = x */
        arb_sin(c, b, prec1);

        if (!arb_contains(c, a))
        {
            printf("FAIL: functional equation\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);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #24
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t am, ar, bm, br, t, u;
        int c1, c2;

        arb_init(a);
        arb_init(b);

        fmpq_init(am);
        fmpq_init(ar);
        fmpq_init(bm);
        fmpq_init(br);
        fmpq_init(t);
        fmpq_init(u);

        arb_randtest(a, state, 1 + n_randint(state, 500), 14);
        arb_randtest(b, state, 1 + n_randint(state, 500), 14);

        arf_get_fmpq(am, arb_midref(a));
        mag_get_fmpq(ar, arb_radref(a));
        arf_get_fmpq(bm, arb_midref(b));
        mag_get_fmpq(br, arb_radref(b));

        fmpq_sub(t, am, bm);
        fmpz_abs(fmpq_numref(t), fmpq_numref(t));
        fmpq_add(u, ar, br);

        c1 = arb_overlaps(a, b);

        c2 = (fmpq_cmp(t, u) <= 0);

        if (c1 != c2)
        {
            flint_printf("FAIL:\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("am = "); fmpq_print(am); flint_printf("\n\n");
            flint_printf("ar = "); fmpq_print(ar); flint_printf("\n\n");
            flint_printf("bm = "); fmpq_print(bm); flint_printf("\n\n");
            flint_printf("br = "); fmpq_print(br); flint_printf("\n\n");
            flint_printf("t = "); fmpq_print(t); flint_printf("\n\n");
            flint_printf("u = "); fmpq_print(u); flint_printf("\n\n");
            flint_printf("c1 = %d, c2 = %d\n\n", c1, c2);
            flint_abort();
        }

        arb_clear(a);
        arb_clear(b);

        fmpq_clear(am);
        fmpq_clear(ar);
        fmpq_clear(bm);
        fmpq_clear(br);
        fmpq_clear(t);
        fmpq_clear(u);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #25
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* compare with fmpq */
    for (iter = 0; iter < 1000; iter++)
    {
        arb_t a, b;
        fmpq_t x, y, z;
        ulong n, step;
        slong i;

        arb_init(a);
        arb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

        arb_randtest(a, state, 1 + n_randint(state, 1000), 10);
        arb_randtest(b, state, 1 + n_randint(state, 1000), 10);
        n = n_randint(state, 80);

        arb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 10));

        step = n_randint(state, 20);
        arb_rising_ui_rs(b, a, n, step, 2 + n_randint(state, 1000));

        fmpq_one(y);
        for (i = 0; i < n; i++)
        {
            fmpq_set_si(z, i, 1);
            fmpq_add(z, x, z);
            fmpq_mul(y, y, z);
        }

        if (!arb_contains_fmpq(b, y))
        {
            flint_printf("FAIL: containment\n\n");
            flint_printf("n = %wu\n", n);
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("x = "); fmpq_print(x); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("y = "); fmpq_print(y); flint_printf("\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of y and x */
    for (iter = 0; iter < 500; iter++)
    {
        arb_t x, y;
        ulong n, step;
        slong prec;

        arb_init(x);
        arb_init(y);

        arb_randtest(x, state, 1 + n_randint(state, 200), 10);
        arb_randtest(y, state, 1 + n_randint(state, 200), 10);
        n = n_randint(state, 100);

        prec = 2 + n_randint(state, 1000);

        step = n_randint(state, 20);
        arb_rising_ui_rs(y, x, n, step, prec);
        arb_rising_ui_rs(x, x, n, step, prec);

        if (!arb_equal(x, y))
        {
            flint_printf("FAIL: aliasing\n\n");
            flint_printf("x = "); arb_print(x); flint_printf("\n\n");
            flint_printf("y = "); arb_print(y); flint_printf("\n\n");
            flint_printf("n = %wu\n", n);
            abort();
        }

        arb_clear(x);
        arb_clear(y);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #26
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        arb_poly_t a;
        arb_ptr roots;
        arb_t t;
        mag_t mag1, mag2;
        slong i, deg, prec;

        prec = 10 + n_randint(state, 400);
        deg = n_randint(state, 10);

        arb_init(t);
        arb_poly_init(a);
        mag_init(mag1);
        mag_init(mag2);
        roots = _arb_vec_init(deg);

        for (i = 0; i < deg; i++)
            arb_randtest(roots + i, state, prec, 1 + n_randint(state, 20));

        arb_poly_product_roots(a, roots, deg, prec);
        arb_randtest(t, state, prec, 1 + n_randint(state, 20));
        arb_poly_scalar_mul(a, a, t, prec);

        arb_poly_root_bound_fujiwara(mag1, a);

        for (i = 0; i < deg; i++)
        {
            arb_get_mag(mag2, roots + i);

            /* arb_get_mag gives an upper bound which due to rounding
               could be larger than mag1, so we pick a slightly
               smaller number */
            mag_mul_ui(mag2, mag2, 10000);
            mag_div_ui(mag2, mag2, 10001);

            if (mag_cmp(mag2, mag1) > 0)
            {
                flint_printf("FAIL\n");
                flint_printf("a = "); arb_poly_printd(a, 15); flint_printf("\n\n");
                flint_printf("root = "); arb_printd(roots + i, 15); flint_printf("\n\n");
                flint_printf("mag1 = "); mag_printd(mag1, 10); flint_printf("\n\n");
                flint_printf("mag2 = "); mag_printd(mag2, 10); flint_printf("\n\n");
                abort();
            }
        }

        _arb_vec_clear(roots, deg);
        arb_clear(t);
        arb_poly_clear(a);
        mag_clear(mag1);
        mag_clear(mag2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #27
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++)
    {
        slong prec1, prec2;
        arb_poly_t f, g;
        arb_t c, d, e;

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

        arb_poly_init(f);
        arb_poly_init(g);

        arb_init(c);
        arb_init(d);
        arb_init(e);

        arb_poly_randtest(f, state, 1 + n_randint(state, 40), 1 + n_randint(state, 500), 10);
        arb_poly_randtest(g, state, 1 + n_randint(state, 20), 1 + n_randint(state, 500), 10);

        if (n_randint(state, 2))
            arb_set_si(c, n_randint(state, 5) - 2);
        else
            arb_randtest(c, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100));

        if (n_randint(state, 2))
            arb_set_si(d, n_randint(state, 5) - 2);
        else
            arb_randtest(d, state, 1 + n_randint(state, 500), 1 + n_randint(state, 100));

        arb_add(e, c, d, prec1);

        /* check f(x+c)(x+d) = f(x+c+d) */
        arb_poly_taylor_shift_convolution(g, f, e, prec2);
        arb_poly_taylor_shift_convolution(f, f, c, prec1);
        arb_poly_taylor_shift_convolution(f, f, d, prec1);

        if (!arb_poly_overlaps(f, g))
        {
            flint_printf("FAIL\n\n");

            flint_printf("c = ");
            arb_printd(c, 15);
            flint_printf("\n\n");
            flint_printf("d = ");
            arb_printd(d, 15);
            flint_printf("\n\n");

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

            abort();
        }

        arb_poly_clear(f);
        arb_poly_clear(g);

        arb_clear(c);
        arb_clear(d);
        arb_clear(e);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #28
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b;
        fmpq_t q;
        mpfr_t t;
        slong prec0, prec;

        prec0 = 400;
        if (iter % 100 == 0)
            prec0 = 8000;

        prec = 2 + n_randint(state, prec0);

        arb_init(a);
        arb_init(b);
        fmpq_init(q);
        mpfr_init2(t, prec0 + 100);

        arb_randtest(a, state, 1 + n_randint(state, prec0), 6);
        arb_randtest(b, state, 1 + n_randint(state, prec0), 6);
        arb_get_rand_fmpq(q, state, a, 1 + n_randint(state, prec0));

        fmpq_get_mpfr(t, q, MPFR_RNDN);
        mpfr_sin(t, t, MPFR_RNDN);

        arb_sin(b, a, prec);

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

        arb_sin(a, a, prec);

        if (!arb_equal(a, b))
        {
            flint_printf("FAIL: aliasing\n\n");
            abort();
        }

        arb_clear(a);
        arb_clear(b);
        fmpq_clear(q);
        mpfr_clear(t);
    }

    /* check large arguments */
    for (iter = 0; iter < 100000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, c, d;
        slong prec0, prec1, prec2;

        if (iter % 10 == 0)
            prec0 = 10000;
        else
            prec0 = 1000;

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

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

        arb_randtest_special(a, state, 1 + n_randint(state, prec0), prec0);
        arb_randtest_special(b, state, 1 + n_randint(state, prec0), 100);
        arb_randtest_special(c, state, 1 + n_randint(state, prec0), 100);
        arb_randtest_special(d, state, 1 + n_randint(state, prec0), 100);

        arb_sin(b, a, prec1);
        arb_sin(c, a, prec2);

        if (!arb_overlaps(b, c))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            abort();
        }

        /* check sin(2a) = 2sin(a)cos(a) */
        arb_mul_2exp_si(c, a, 1);
        arb_sin(c, c, prec1);

        arb_cos(d, a, prec1);
        arb_mul(b, b, d, prec1);
        arb_mul_2exp_si(b, b, 1);

        if (!arb_overlaps(b, c))
        {
            flint_printf("FAIL: functional equation\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); flint_printf("\n\n");
            flint_printf("c = "); arb_print(c); flint_printf("\n\n");
            abort();
        }

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

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #29
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        arb_t a, b, c;
        ulong n;
        long prec, acc1, acc2;
        fmpz_t t;

        arb_init(a);
        arb_init(b);
        arb_init(c);
        fmpz_init(t);

        prec = 2 + n_randint(state, 10000);
        arb_randtest(a, state, 1 + n_randint(state, 10000), 10);

        if (n_randint(state, 2))
            n = 1 + (n_randtest(state) % (10 * prec));
        else
            n = n_randtest(state);

        arb_div_2expm1_ui(b, a, n, prec);

        arb_one(c);
        if (n >= (1UL << (FLINT_BITS-1)))
        {
            arb_mul_2exp_si(c, c, (1UL << (FLINT_BITS-2)));
            arb_mul_2exp_si(c, c, (1UL << (FLINT_BITS-2)));
            arb_mul_2exp_si(c, c, n - (1UL << (FLINT_BITS-1)));
        }
        else
        {
            arb_mul_2exp_si(c, c, n);
        }

        arb_sub_ui(c, c, 1, prec);
        arb_div(c, a, c, prec);

        acc1 = arb_rel_accuracy_bits(a);
        acc2 = arb_rel_accuracy_bits(b);

        if (!arb_overlaps(b, c))
        {
            printf("FAIL: containment\n\n");
            printf("n = %lu\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();
        }

        if (n > 0 && (acc2 < FLINT_MIN(prec, acc1) - 10) &&
                !(acc1 == -ARF_PREC_EXACT && acc2 == -ARF_PREC_EXACT))
        {
            printf("FAIL: poor accuracy\n\n");
            printf("prec=%ld, acc1=%ld, acc2=%ld\n\n", prec, acc1, acc2);
            printf("n = %lu\n\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);
        fmpz_clear(t);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #30
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000; iter++)
    {
        arb_t a, u, v, u2, v2;
        fmpz *f;
        arb_ptr g;
        ulong n;
        slong i, prec;

        arb_init(a);
        arb_init(u);
        arb_init(v);
        arb_init(u2);
        arb_init(v2);

        arb_randtest(a, state, 1 + n_randint(state, 4000), 10);
        arb_randtest(u, state, 1 + n_randint(state, 4000), 10);
        arb_randtest(v, state, 1 + n_randint(state, 4000), 10);
        n = n_randint(state, 120);

        f = _fmpz_vec_init(n + 1);
        g = _arb_vec_init(n + 1);

        prec = 2 + n_randint(state, 4000);
        arb_rising2_ui(u, v, a, n, prec);

        arith_stirling_number_1u_vec(f, n, n + 1);
        for (i = 0; i <= n; i++)
            arb_set_fmpz(g + i, f + i);
        _arb_poly_evaluate(u2, g, n + 1, a, prec);

        _arb_poly_derivative(g, g, n + 1, prec);
        _arb_poly_evaluate(v2, g, n, a, prec);

        if (!arb_overlaps(u, u2) || !arb_overlaps(v, v2))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("n = %wu\n", n);
            flint_printf("a = "); arb_printd(a, 15); flint_printf("\n\n");
            flint_printf("u = "); arb_printd(u, 15); flint_printf("\n\n");
            flint_printf("u2 = "); arb_printd(u2, 15); flint_printf("\n\n");
            flint_printf("v = "); arb_printd(v, 15); flint_printf("\n\n");
            flint_printf("v2 = "); arb_printd(v2, 15); flint_printf("\n\n");
            abort();
        }

        arb_set(u2, a);
        arb_rising2_ui(u2, v, u2, n, prec);

        if (!arb_equal(u2, u))
        {
            flint_printf("FAIL: aliasing 1\n\n");
            flint_printf("a = "); arb_printd(a, 15); flint_printf("\n\n");
            flint_printf("u = "); arb_printd(u, 15); flint_printf("\n\n");
            flint_printf("u2 = "); arb_printd(u2, 15); flint_printf("\n\n");
            flint_printf("n = %wu\n", n);
            abort();
        }

        arb_set(v2, a);
        arb_rising2_ui(u, v2, v2, n, prec);

        if (!arb_equal(v2, v))
        {
            flint_printf("FAIL: aliasing 2\n\n");
            flint_printf("a = "); arb_printd(a, 15); flint_printf("\n\n");
            flint_printf("v = "); arb_printd(v, 15); flint_printf("\n\n");
            flint_printf("v2 = "); arb_printd(v2, 15); flint_printf("\n\n");
            flint_printf("n = %wu\n", n);
            abort();
        }

        arb_clear(a);
        arb_clear(u);
        arb_clear(v);
        arb_clear(u2);
        arb_clear(v2);
        _fmpz_vec_clear(f, n + 1);
        _arb_vec_clear(g, n + 1);
    }

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