Exemple #1
0
void
_arb_poly_log_series(arb_ptr res, arb_srcptr f, slong flen, slong n, slong prec)
{
    flen = FLINT_MIN(flen, n);

    if (flen == 1)
    {
        arb_log(res, f, prec);
        _arb_vec_zero(res + 1, n - 1);
    }
    else if (n == 2)
    {
        arb_div(res + 1, f + 1, f + 0, prec);  /* safe since hlen >= 2 */
        arb_log(res, f, prec);
    }
    else if (_arb_vec_is_zero(f + 1, flen - 2))  /* f = a + bx^d */
    {
        slong i, j, d = flen - 1;

        for (i = 1, j = d; j < n; j += d, i++)
        {
            if (i == 1)
                arb_div(res + j, f + d, f + 0, prec);
            else
                arb_mul(res + j, res + j - d, res + d, prec);
            _arb_vec_zero(res + j - d + 1, flen - 2);
        }
        _arb_vec_zero(res + j - d + 1, n - (j - d + 1));

        for (i = 2, j = 2 * d; j < n; j += d, i++)
            arb_div_si(res + j, res + j, i % 2 ? i : -i, prec);

        arb_log(res, f, prec); /* done last to allow aliasing */
    }
    else
    {
        arb_ptr f_diff, f_inv;
        arb_t a;
        slong alloc;

        alloc = n + flen - 1;
        f_inv = _arb_vec_init(alloc);
        f_diff = f_inv + n;

        arb_init(a);
        arb_log(a, f, prec);

        _arb_poly_derivative(f_diff, f, flen, prec);
        _arb_poly_inv_series(f_inv, f, flen, n, prec);
        _arb_poly_mullow(res, f_inv, n - 1, f_diff, flen - 1, n - 1, prec);
        _arb_poly_integral(res, res, n, prec);
        arb_swap(res, a);

        arb_clear(a);
        _arb_vec_clear(f_inv, alloc);
    }
}
Exemple #2
0
void
arb_root_ui_exp(arb_t res, const arb_t x, ulong k, slong prec)
{
    arb_log(res, x, prec + 4);
    arb_div_ui(res, res, k, prec + 4);
    arb_exp(res, res, prec);
}
Exemple #3
0
void
arb_log1p(arb_t r, const arb_t z, slong prec)
{
    slong magz;

    if (arb_is_zero(z))
    {
        arb_zero(r);
        return;
    }

    magz = arf_abs_bound_lt_2exp_si(arb_midref(z));

    if (magz < -prec)
    {
        arb_log1p_tiny(r, z, prec);
    }
    else
    {
        if (magz < 0)
            arb_add_ui(r, z, 1, prec + (-magz) + 4);
        else
            arb_add_ui(r, z, 1, prec + 4);

        arb_log(r, r, prec);
    }
}
Exemple #4
0
Fichier : pow.c Projet : akobel/arb
void
_arb_pow_exp(arb_t z, const arb_t x, int negx, const arb_t y, long prec)
{
    arb_t t;
    arb_init(t);

    if (negx)
    {
        arb_neg(t, x);
        arb_log(t, t, prec);
    }
    else
        arb_log(t, x, prec);

    arb_mul(t, t, y, prec);
    arb_exp(z, t, prec);
    arb_clear(t);
}
Exemple #5
0
static void
bound_I(arb_ptr I, const arb_t A, const arb_t B, const arb_t C, slong len, slong wp)
{
    slong k;

    arb_t D, Dk, L, T, Bm1;

    arb_init(D);
    arb_init(Dk);
    arb_init(Bm1);
    arb_init(T);
    arb_init(L);

    arb_sub_ui(Bm1, B, 1, wp);
    arb_one(L);

    /* T = 1 / (A^Bm1 * Bm1) */
    arb_inv(T, A, wp);
    arb_pow(T, T, Bm1, wp);
    arb_div(T, T, Bm1, wp);

    if (len > 1)
    {
        arb_log(D, A, wp);
        arb_add(D, D, C, wp);
        arb_mul(D, D, Bm1, wp);
        arb_set(Dk, D);
    }

    for (k = 0; k < len; k++)
    {
        if (k > 0)
        {
            arb_mul_ui(L, L, k, wp);
            arb_add(L, L, Dk, wp);
            arb_mul(Dk, Dk, D, wp);
        }

        arb_mul(I + k, L, T, wp);
        arb_div(T, T, Bm1, wp);
    }

    arb_clear(D);
    arb_clear(Dk);
    arb_clear(Bm1);
    arb_clear(T);
    arb_clear(L);
}
/* series of c^(d+x) */
static __inline__ void
_arb_poly_pow_cpx(arb_ptr res, const arb_t c, const arb_t d, long trunc, long prec)
{
    long i;
    arb_t logc;

    arb_init(logc);
    arb_log(logc, c, prec);
    arb_mul(res + 0, logc, d, prec);
    arb_exp(res + 0, res + 0, prec);

    for (i = 1; i < trunc; i++)
    {
        arb_mul(res + i, res + i - 1, logc, prec);
        arb_div_ui(res + i, res + i, i, prec);
    }

    arb_clear(logc);
}
Exemple #7
0
void
arb_acosh(arb_t z, const arb_t x, slong prec)
{
    if (arb_is_one(x))
    {
        arb_zero(z);
    }
    else
    {
        arb_t t;
        arb_init(t);

        arb_mul(t, x, x, prec + 4);
        arb_sub_ui(t, t, 1, prec + 4);
        arb_sqrt(t, t, prec + 4);
        arb_add(t, t, x, prec + 4);
        arb_log(z, t, prec);

        arb_clear(t);
    }
}
Exemple #8
0
void
arb_pow_fmpq(arb_t y, const arb_t x, const fmpq_t a, long prec)
{
    if (fmpz_is_one(fmpq_denref(a)))
    {
        arb_pow_fmpz(y, x, fmpq_numref(a), prec);
    }
    else if (fmpz_cmp_ui(fmpq_denref(a), 36) <= 0)
    {
        arb_root(y, x, *fmpq_denref(a), prec);
        arb_pow_fmpz(y, y, fmpq_numref(a), prec);
    }
    else
    {
        long wp;

        wp = prec + 10;

        arb_log(y, x, wp);
        arb_mul_fmpz(y, y, fmpq_numref(a), wp);
        arb_div_fmpz(y, y, fmpq_denref(a), wp);
        arb_exp(y, y, prec);
    }
}
Exemple #9
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;
}
Exemple #10
0
void
keiper_li_series(arb_ptr z, slong len, slong prec)
{
    arb_ptr t, u, v;

    t = _arb_vec_init(len);
    u = _arb_vec_init(len);
    v = _arb_vec_init(len);

    /* -zeta(s) */
    flint_printf("zeta: ");
    TIMEIT_ONCE_START
    arb_zero(t + 0);
    arb_one(t + 1);
    arb_one(u);
    _arb_poly_zeta_series(v, t, 2, u, 0, len, prec);
    _arb_vec_neg(v, v, len);
    TIMEIT_ONCE_STOP

    SHOW_MEMORY_USAGE

    /* logarithm */
    flint_printf("log: ");
    TIMEIT_ONCE_START
    _arb_poly_log_series(t, v, len, len, prec);
    TIMEIT_ONCE_STOP

    /* add log(gamma(1+s/2)) */
    flint_printf("gamma: ");
    TIMEIT_ONCE_START
    arb_one(u);
    arb_one(u + 1);
    arb_mul_2exp_si(u + 1, u + 1, -1);
    _arb_poly_lgamma_series(v, u, 2, len, prec);
    _arb_vec_add(t, t, v, len, prec);
    TIMEIT_ONCE_STOP

    /* subtract 0.5 s log(pi) */
    arb_const_pi(u, prec);
    arb_log(u, u, prec);
    arb_mul_2exp_si(u, u, -1);
    arb_sub(t + 1, t + 1, u, prec);

    /* add log(1-s) */
    arb_one(u);
    arb_set_si(u + 1, -1);
    _arb_poly_log_series(v, u, 2, len, prec);
    _arb_vec_add(t, t, v, len, prec);

    /* binomial transform */
    flint_printf("binomial transform: ");
    TIMEIT_ONCE_START
    arb_set(z, t);
    _arb_vec_neg(t + 1, t + 1, len - 1);
    _arb_poly_binomial_transform(z + 1, t + 1, len - 1, len - 1, prec);
    TIMEIT_ONCE_STOP

    _arb_vec_clear(t, len);
    _arb_vec_clear(u, len);
    _arb_vec_clear(v, len);
}
Exemple #11
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 20000; 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), 100);
        arb_randtest_special(b, state, 1 + n_randint(state, prec0), 100);
        arb_randtest_special(c, state, 1 + n_randint(state, prec0), 100);

        arb_log1p(b, a, prec1);
        arb_log1p(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();
        }

        /* compare with log */
        arb_add_ui(d, a, 1, prec2);
        arb_log(d, d, prec2);

        if (!arb_overlaps(c, d))
        {
            flint_printf("FAIL: comparison with log\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");
            abort();
        }

        arb_log1p(a, a, prec1);

        if (!arb_overlaps(a, b))
        {
            flint_printf("FAIL: aliasing\n\n");
            flint_printf("a = "); arb_print(a); flint_printf("\n\n");
            flint_printf("b = "); arb_print(b); 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;
}