Esempio n. 1
0
File: div.c Progetto: bluescarni/arb
void
arb_ui_div(arb_t z, ulong x, const arb_t y, long prec)
{
    arb_t t;
    arb_init(t);
    arb_set_ui(t, x);
    arb_div(z, t, y, prec);
    arb_clear(t);
}
Esempio n. 2
0
void arb_twobytwo_diag(arb_t u1, arb_t u2, const arb_t a, const arb_t b, const arb_t d, slong prec) {
    // Compute the orthogonal matrix that diagonalizes
    //
    //    A = [a b]
    //        [b d]
    //
    // This matrix will have the form
    //
    //    U = [cos x , -sin x]
    //        [sin x, cos x]
    //
    // where the diagonal matrix is U^t A U.
    // We set u1 = cos x, u2 = -sin x.

    if(arb_contains_zero(b)) {
        // this is not quite right (doesn't set error intervals)
        arb_set_ui(u1, 1);
        arb_set_ui(u2, 0);
        return;
    }
    arb_t x; arb_init(x);

    arb_mul(u1, b, b, prec);            // u1 = b^2
    arb_sub(u2, a, d, prec);            // u2 = a - d
    arb_mul_2exp_si(u2, u2, -1);        // u2 = (a - d)/2
    arb_mul(u2, u2, u2, prec);          // u2 = ( (a - d)/2 )^2
    arb_add(u1, u1, u2, prec);          // u1 = b^2 + ( (a-d)/2 )^2
    arb_sqrt(u1, u1, prec);             // u1 = sqrt(above)

    arb_mul_2exp_si(u1, u1, 1);         // u1 = 2 (sqrt (above) )
    arb_add(u1, u1, d, prec);           // u1 += d
    arb_sub(u1, u1, a, prec);           // u1 -= a
    arb_mul_2exp_si(u1, u1, -1);        // u1 = (d - a)/2 + sqrt(b^2 + ( (a-d)/2 )^2)

    arb_mul(x, u1, u1, prec);
    arb_addmul(x, b, b, prec);          // x = u1^2 + b^2
    arb_sqrt(x, x, prec);               // x = sqrt(u1^2 + b^2)
    arb_div(u2, u1, x, prec);
    arb_div(u1, b, x, prec);
    arb_neg(u1, u1);

    arb_clear(x);
}
Esempio n. 3
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100; iter++)
    {
        arb_t b, radius, ans;
        acb_t x;
        slong r, prec, maxdepth;

        arb_init(b);
        arb_init(radius);
        arb_init(ans);
        acb_init(x);

        acb_set_ui(x, 5);

        r = 1 + n_randint(state, 10);
        arb_set_ui(radius, r);

        prec = 2 + n_randint(state, 100);
        maxdepth = n_randint(state, 10);

        acb_calc_cauchy_bound(b, sin_x, NULL, x, radius, maxdepth, prec);

        arf_set_d(arb_midref(ans), answers[r-1]);
        mag_set_d(arb_radref(ans), 1e-8);

        if (!arb_overlaps(b, ans))
        {
            flint_printf("FAIL\n");
            flint_printf("r = %wd, prec = %wd, maxdepth = %wd\n\n", r, prec, maxdepth);
            arb_printd(b, 15); flint_printf("\n\n");
            arb_printd(ans, 15); flint_printf("\n\n");
            abort();
        }

        arb_clear(b);
        arb_clear(radius);
        arb_clear(ans);
        acb_clear(x);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
int
acb_modular_is_in_fundamental_domain(const acb_t z, const arf_t tol, long prec)
{
    arb_t t;
    arb_init(t);

    /* require re(w) + 1/2 >= 0 */
    arb_set_ui(t, 1);
    arb_mul_2exp_si(t, t, -1);
    arb_add(t, t, acb_realref(z), prec);
    arb_add_arf(t, t, tol, prec);
    if (!arb_is_nonnegative(t))
    {
        arb_clear(t);
        return 0;
    }

    /* require re(w) - 1/2 <= 0 */
    arb_set_ui(t, 1);
    arb_mul_2exp_si(t, t, -1);
    arb_sub(t, acb_realref(z), t, prec);
    arb_sub_arf(t, t, tol, prec);
    if (!arb_is_nonpositive(t))
    {
        arb_clear(t);
        return 0;
    }

    /* require |w| >= 1 - tol, i.e. |w| - 1 + tol >= 0 */
    acb_abs(t, z, prec);
    arb_sub_ui(t, t, 1, prec);
    arb_add_arf(t, t, tol, prec);
    if (!arb_is_nonnegative(t))
    {
        arb_clear(t);
        return 0;
    }

    arb_clear(t);
    return 1;
}
Esempio n. 5
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        arb_t a, b, c, d;
        ulong x;
        long prec;

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

        arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100);
        x = n_randtest(state);

        prec = 2 + n_randint(state, 2000);

        arb_set_ui(b, x);
        arb_div_ui(c, a, x, prec);
        arb_div(d, a, b, prec);

        if (!arb_equal(c, d))
        {
            printf("FAIL\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");
            printf("d = ");
            arb_print(d);
            printf("\n\n");
            abort();
        }

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

    /* aliasing */
    for (iter = 0; iter < 10000; iter++)
    {
        arb_t a, b, c;
        ulong x;
        long prec;

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

        arb_randtest_special(a, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(b, state, 1 + n_randint(state, 2000), 100);
        arb_randtest_special(c, state, 1 + n_randint(state, 2000), 100);
        x = n_randtest(state);

        prec = 2 + n_randint(state, 2000);

        arb_set_ui(b, x);
        arb_div_ui(c, a, x, prec);
        arb_div_ui(a, a, x, prec);

        if (!arb_equal(a, c))
        {
            printf("FAIL (aliasing)\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;
}
Esempio n. 6
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;
}
Esempio n. 7
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;
}
Esempio n. 8
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++)
    {
        arb_mat_t A, X, B, Y;
        slong rows, cols, prec, i, j;
        int unit;

        prec = 2 + n_randint(state, 200);
        if (n_randint(state, 10) == 0)
        {
            rows = n_randint(state, 60);
            cols = n_randint(state, 60);
        }
        else
        {
            rows = n_randint(state, 10);
            cols = n_randint(state, 10);
        }
        unit = n_randint(state, 2);

        arb_mat_init(A, rows, rows);
        arb_mat_init(B, rows, cols);
        arb_mat_init(X, rows, cols);
        arb_mat_init(Y, rows, cols);

        arb_mat_randtest(A, state, prec, 10);
        arb_mat_randtest(X, state, prec, 10);
        arb_mat_randtest(Y, state, prec, 10);

        for (i = 0; i < rows; i++)
        {
            if (unit)
                arb_one(arb_mat_entry(A, i, i));
            else
                arb_set_ui(arb_mat_entry(A, i, i), 1 + n_randint(state, 100));

            for (j = i + 1; j < rows; j++)
                arb_zero(arb_mat_entry(A, i, j));
        }

        arb_mat_mul(B, A, X, prec);

        if (unit)  /* check that diagonal entries are ignored */
        {
            for (i = 0; i < rows; i++)
                arb_set_ui(arb_mat_entry(A, i, i), 1 + n_randint(state, 100));
        }

        /* Check Y = A^(-1) * (A * X) = X */
        arb_mat_solve_tril(Y, A, B, unit, prec);

        if (!arb_mat_overlaps(Y, X))
        {
            flint_printf("FAIL\n");
            flint_printf("A = \n"); arb_mat_printd(A, 10); flint_printf("\n\n");
            flint_printf("B = \n"); arb_mat_printd(B, 10); flint_printf("\n\n");
            flint_printf("X = \n"); arb_mat_printd(X, 10); flint_printf("\n\n");
            flint_printf("Y = \n"); arb_mat_printd(Y, 10); flint_printf("\n\n");
            flint_abort();
        }

        /* Check aliasing */
        arb_mat_solve_tril(B, A, B, unit, prec);
        if (!arb_mat_equal(B, Y))
        {
            flint_printf("FAIL (aliasing)\n");
            flint_printf("A = \n"); arb_mat_printd(A, 10); flint_printf("\n\n");
            flint_printf("B = \n"); arb_mat_printd(B, 10); flint_printf("\n\n");
            flint_printf("X = \n"); arb_mat_printd(X, 10); flint_printf("\n\n");
            flint_printf("Y = \n"); arb_mat_printd(Y, 10); flint_printf("\n\n");
            flint_abort();
        }

        arb_mat_clear(A);
        arb_mat_clear(B);
        arb_mat_clear(X);
        arb_mat_clear(Y);
    }

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

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

    flint_randinit(state);

    /* test multiplication theorem */
    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        arb_t x, t, res1, res2;
        ulong n, m, k;
        slong prec;

        n = n_randint(state, 50);
        m = 1 + n_randint(state, 5);
        prec = 2 + n_randint(state, 200);

        arb_init(x);
        arb_init(t);
        arb_init(res1);
        arb_init(res2);

        arb_randtest(x, state, 2 + n_randint(state, 200), 20);
        arb_randtest(res1, state, 2 + n_randint(state, 200), 20);

        arb_mul_ui(t, x, m, prec);
        arb_bernoulli_poly_ui(res1, n, t, prec);

        arb_zero(res2);
        for (k = 0; k < m; k++)
        {
            arb_set_ui(t, k);
            arb_div_ui(t, t, m, prec);
            arb_add(t, t, x, prec);
            arb_bernoulli_poly_ui(t, n, t, prec);
            arb_add(res2, res2, t, prec);
        }

        if (n > 0)
        {
            arb_ui_pow_ui(t, m, n - 1, prec);
            arb_mul(res2, res2, t, prec);
        }
        else
        {
            arb_div_ui(res2, res2, m, prec);
        }

        if (!arb_overlaps(res1, res2))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("n = %wu, m = %wu\n\n", n, m);
            flint_printf("x = "); arb_printd(x, 15); flint_printf("\n\n");
            flint_printf("res1 = "); arb_printd(res1, 15); flint_printf("\n\n");
            flint_printf("res2 = "); arb_printd(res2, 15); flint_printf("\n\n");
            abort();
        }

        arb_clear(x);
        arb_clear(t);
        arb_clear(res1);
        arb_clear(res2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 10
0
File: fib.c Progetto: argriffing/arb
void arb_fib_fmpz(arb_t f, const fmpz_t n, slong prec)
{
    arb_t t, u;
    slong wp, sign, i;

    if (fmpz_sgn(n) < 0)
    {
        fmpz_t m;
        fmpz_init(m);
        fmpz_neg(m, n);
        arb_fib_fmpz(f, m, prec);
        if (fmpz_is_even(m))
            arb_neg(f, f);
        fmpz_clear(m);
        return;
    }

    if (fmpz_cmp_ui(n, 4) <= 0)
    {
        ulong x = fmpz_get_ui(n);
        arb_set_ui(f, x - (x > 1));
        return;
    }

    wp = ARF_PREC_ADD(prec, 3 * fmpz_bits(n));

    arb_init(u);
    arb_init(t);
    arb_set_ui(f, UWORD(1));
    arb_set_ui(u, UWORD(1));
    sign = -1;

    for (i = fmpz_flog_ui(n, UWORD(2)) - 1; i > 0; i--)
    {
        arb_mul(t, f, f, wp);
        arb_add(f, f, u, wp);
        arb_mul_2exp_si(f, f, -1);
        arb_mul(f, f, f, wp);
        arb_mul_2exp_si(f, f, 1);
        arb_submul_ui(f, t, 3, wp);
        arb_sub_si(f, f, 2 * sign, wp);
        arb_mul_ui(u, t, 5, wp);
        arb_add_si(u, u, 2 * sign, wp);
        sign = 1;

        if (fmpz_tstbit(n, i))
        {
            arb_set(t, f);
            arb_add(f, f, u, wp);
            arb_mul_2exp_si(f, f, -1);
            arb_mul_2exp_si(t, t, 1);
            arb_add(u, f, t, wp);
            sign = -1;
        }
    }

    if (fmpz_tstbit(n, 0))
    {
        arb_add(f, f, u, wp);
        arb_mul_2exp_si(f, f, -1);
        arb_mul(f, f, u, wp);
        arb_sub_si(f, f, sign, prec);
    }
    else
    {
        arb_mul(f, f, u, prec);
    }

    arb_clear(u);
    arb_clear(t);
}
Esempio n. 11
0
File: set_str.c Progetto: isuruf/arb
static int
arb_set_float_str(arb_t res, const char * inp, slong prec)
{
    char * emarker;
    char * buf;
    int error;
    slong i;
    fmpz_t exp;
    fmpz_t man;
    slong num_int, num_frac;
    int after_radix;

    if (inp[0] == '+')
    {
        return arb_set_float_str(res, inp + 1, prec);
    }

    if (inp[0] == '-')
    {
        error = arb_set_float_str(res, inp + 1, prec);
        arb_neg(res, res);
        return error;
    }

    if (strcmp(inp, "inf") == 0)
    {
        arb_pos_inf(res);
        return 0;
    }

    if (strcmp(inp, "nan") == 0)
    {
        arb_indeterminate(res);
        return 0;
    }

    error = 0;
    fmpz_init(exp);
    fmpz_init(man);
    buf = flint_malloc(strlen(inp) + 1);

    emarker = strchr(inp, 'e');

    /* parse exponent (0 by default) */
    if (emarker != NULL)
    {
        /* allow e+42 as well as e42 */
        if (emarker[1] == '+')
        {
            if (!(emarker[2] >= '0' && emarker[2] <= '9'))
                error = 1;
            else
                error = fmpz_set_str(exp, emarker + 2, 10);
        }
        else
            error = fmpz_set_str(exp, emarker + 1, 10);

        if (error)
            goto cleanup;
    }

    /* parse floating-point part */
    {
        num_int = 0;
        num_frac = 0;
        after_radix = 0;

        for (i = 0; inp + i != emarker && inp[i] != '\0'; i++)
        {
            if (inp[i] == '.' && !after_radix)
            {
                after_radix = 1;
            }
            else if (inp[i] >= '0' && inp[i] <= '9')
            {
                buf[num_int + num_frac] = inp[i];

                num_frac += after_radix;
                num_int += !after_radix;
            }
            else
            {
                error = 1;
                goto cleanup;
            }
        }

        buf[num_int + num_frac] = '\0';

        /* put trailing zeros into the exponent */
        while (num_int + num_frac > 1 && buf[num_int + num_frac - 1] == '0')
        {
            buf[num_int + num_frac - 1] = '\0';
            num_frac--;
        }

        fmpz_sub_si(exp, exp, num_frac);

        error = fmpz_set_str(man, buf, 10);
        if (error)
            goto cleanup;
    }

    if (fmpz_is_zero(man))
    {
        arb_zero(res);
    }
    else if (fmpz_is_zero(exp))
    {
        arb_set_round_fmpz(res, man, prec);
    }
    else
    {
        arb_t t;
        arb_init(t);
        arb_set_ui(t, 10);
        arb_set_fmpz(res, man);

        if (fmpz_sgn(exp) > 0)
        {
            arb_pow_fmpz_binexp(t, t, exp, prec + 4);
            arb_mul(res, res, t, prec);
        }
        else
        {
            fmpz_neg(exp, exp);
            arb_pow_fmpz_binexp(t, t, exp, prec + 4);
            arb_div(res, res, t, prec);
        }

        arb_clear(t);
    }

cleanup:
    fmpz_clear(exp);
    fmpz_clear(man);
    flint_free(buf);

    if (error)
        arb_indeterminate(res);

    return error;
}
Esempio n. 12
0
void Lib_Arb_Set_Ui(ArbPtr x, uint32_t a)
{
    arb_set_ui( (arb_ptr) x, a);
}
Esempio n. 13
0
void Lib_Arb_Mat_Set_Ui(ArbMatPtr A, int32_t i, int32_t j, int32_t u)
{
    arb_set_ui ( arb_mat_entry ((arb_mat_struct*)A, i, j), u);
}
Esempio n. 14
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        arb_t b1, b2, t;
        ulong n;
        slong prec1, prec2, acc1;

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

        arb_init(b1);
        arb_init(b2);
        arb_init(t);

        arb_hypgeom_central_bin_ui(b1, n, prec1);

        arb_set_ui(t, n);
        arb_add_ui(t, t, n, prec2);
        arb_add_ui(t, t, 1, prec2);
        arb_gamma(t, t, prec2);
        arb_set_ui(b2, n);
        arb_add_ui(b2, b2, 1, prec2);
        arb_rgamma(b2, b2, prec2);
        arb_mul(b2, b2, b2, prec2);
        arb_mul(b2, b2, t, prec2);

        if (!arb_overlaps(b1, b2))
        {
            flint_printf("FAIL: overlap\n\n");
            flint_printf("n = %wu\n\n", n);
            flint_printf("b1 = "); arb_printn(b1, 50, 0); flint_printf("\n\n");
            flint_printf("b2 = "); arb_printn(b2, 50, 0); flint_printf("\n\n");
            flint_abort();
        }

        acc1 = arb_rel_accuracy_bits(b1);

        if (acc1 < prec1 - 2)
        {
            flint_printf("FAIL: poor accuracy\n\n");
            flint_printf("prec1 = %wd, acc1 = %wd\n", prec1, acc1);
            flint_printf("b1 = "); arb_printn(b1, prec1 / 3.33, 0); flint_printf("\n\n");
            flint_printf("b2 = "); arb_printn(b2, prec2 / 3.33, 0); flint_printf("\n\n");
            flint_abort();
        }

        arb_clear(b1);
        arb_clear(b2);
        arb_clear(t);
    }

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