void
_arb_poly_revert_series_lagrange_fast(arb_ptr Qinv, arb_srcptr Q, long Qlen, long n, long prec)
{
    long i, j, k, m;
    arb_ptr R, S, T, tmp;
    arb_t t;

    if (n <= 2)
    {
        if (n >= 1)
            arb_zero(Qinv);
        if (n == 2)
            arb_inv(Qinv + 1, Q + 1, prec);
        return;
    }

    m = n_sqrt(n);

    arb_init(t);
    R = _arb_vec_init((n - 1) * m);
    S = _arb_vec_init(n - 1);
    T = _arb_vec_init(n - 1);

    arb_zero(Qinv);
    arb_inv(Qinv + 1, Q + 1, prec);

    _arb_poly_inv_series(Ri(1), Q + 1, FLINT_MIN(Qlen, n) - 1, n - 1, prec);
    for (i = 2; i <= m; i++)
        _arb_poly_mullow(Ri(i), Ri((i + 1) / 2), n - 1, Ri(i / 2), n - 1, n - 1, prec);

    for (i = 2; i < m; i++)
        arb_div_ui(Qinv + i, Ri(i) + i - 1, i, prec);

    _arb_vec_set(S, Ri(m), n - 1);

    for (i = m; i < n; i += m)
    {
        arb_div_ui(Qinv + i, S + i - 1, i, prec);

        for (j = 1; j < m && i + j < n; j++)
        {
            arb_mul(t, S + 0, Ri(j) + i + j - 1, prec);
            for (k = 1; k <= i + j - 1; k++)
                arb_addmul(t, S + k, Ri(j) + i + j - 1 - k, prec);
            arb_div_ui(Qinv + i + j, t, i + j, prec);
        }

        if (i + 1 < n)
        {
            _arb_poly_mullow(T, S, n - 1, Ri(m), n - 1, n - 1, prec);
            tmp = S; S = T; T = tmp;
        }
    }

    arb_clear(t);
    _arb_vec_clear(R, (n - 1) * m);
    _arb_vec_clear(S, n - 1);
    _arb_vec_clear(T, n - 1);
}
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_poly_integral(arb_ptr res, arb_srcptr poly, slong len, slong prec)
{
    slong k = len - 1;

    for (k = len - 1; k > 0; k--)
        arb_div_ui(res + k, poly + k - 1, k, prec);

    arb_zero(res);
}
Exemple #4
0
void
_arb_poly_sinh_cosh_series_basecase(arb_ptr s, arb_ptr c, arb_srcptr h, slong hlen,
        slong n, slong prec)
{
    slong j, k, alen = FLINT_MIN(n, hlen);
    arb_ptr a;
    arb_t t, u;

    arb_sinh_cosh(s, c, h, prec);

    if (hlen == 1)
    {
        _arb_vec_zero(s + 1, n - 1);
        _arb_vec_zero(c + 1, n - 1);
        return;
    }

    arb_init(t);
    arb_init(u);
    a = _arb_vec_init(alen);

    for (k = 1; k < alen; k++)
        arb_mul_ui(a + k, h + k, k, prec);

    for (k = 1; k < n; k++)
    {
        arb_zero(t);
        arb_zero(u);

        for (j = 1; j < FLINT_MIN(k + 1, hlen); j++)
        {
            arb_addmul(t, a + j, s + k - j, prec);
            arb_addmul(u, a + j, c + k - j, prec);
        }

        arb_div_ui(c + k, t, k, prec);
        arb_div_ui(s + k, u, k, prec);
    }

    arb_clear(t);
    arb_clear(u);
    _arb_vec_clear(a, alen);
}
Exemple #5
0
void
arb_div_2expm1_ui(arb_t y, const arb_t x, ulong n, long prec)
{
    if (n < FLINT_BITS)
    {
        arb_div_ui(y, x, (1UL << n) - 1, prec);
    }
    else if (n < 1024 + prec / 32 || n > LONG_MAX / 4)
    {
        arb_t t;
        fmpz_t e;

        arb_init(t);
        fmpz_init_set_ui(e, n);

        arb_one(t);
        arb_mul_2exp_fmpz(t, t, e);
        arb_sub_ui(t, t, 1, prec);
        arb_div(y, x, t, prec);

        arb_clear(t);
        fmpz_clear(e);
    }
    else
    {
        arb_t s, t;
        long i, b;

        arb_init(s);
        arb_init(t);

        /* x / (2^n - 1) = sum_{k>=1} x * 2^(-k*n)*/
        arb_mul_2exp_si(s, x, -n);
        arb_set(t, s);
        b = 1;

        for (i = 2; i <= prec / n + 1; i++)
        {
            arb_mul_2exp_si(t, t, -n);
            arb_add(s, s, t, prec);
            b = i;
        }

        /* error bound: sum_{k>b} x * 2^(-k*n) <= x * 2^(-b*n - (n-1)) */
        arb_mul_2exp_si(t, x, -b*n - (n-1));
        arb_abs(t, t);
        arb_add_error(s, t);

        arb_set(y, s);

        arb_clear(s);
        arb_clear(t);
    }
}
Exemple #6
0
/*
Bound for scaled Bessel function: 2/(2 pi x)^(1/2)
Bound for tail of integral: 2 N (k / (pi N))^(k / 2) / (k - 2).
*/
void
scaled_bessel_tail_bound(arb_t b, ulong k, const arb_t N, slong prec)
{
    arb_const_pi(b, prec);
    arb_mul(b, b, N, prec);
    arb_ui_div(b, k, b, prec);
    arb_sqrt(b, b, prec);
    arb_pow_ui(b, b, k, prec);
    arb_mul(b, b, N, prec);
    arb_mul_ui(b, b, 2, prec);
    arb_div_ui(b, b, k - 2, prec);
}
Exemple #7
0
void
acb_zeta_si(acb_t z, slong s, slong prec)
{
    if (s >= 0)
    {
        arb_zeta_ui(acb_realref(z), s, prec);
    }
    else
    {
        arb_bernoulli_ui(acb_realref(z), 1-s, prec);
        arb_div_ui(acb_realref(z), acb_realref(z), 1-s, prec);
        arb_neg(acb_realref(z), acb_realref(z));
    }

    arb_zero(acb_imagref(z));
    return;
}
/* 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 #9
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;
}
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

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

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

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

        arb_init(c1);
        arb_init(c2);

        _arb_cos_pi_fmpq_algebraic(c1, p, q, prec);

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

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

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

        arb_clear(c1);
        arb_clear(c2);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
void
gc_integrals_precomp(acb_ptr res, acb_srcptr u, slong d1, slong d, slong g, const gc_int_t gc, int flag, slong prec)
{
    slong l;
    arb_t w, x;
    acb_t y, yxi;
    void (*sqrt_pol) (acb_t y, acb_srcptr u, slong d1, slong d,
            const arb_t x, slong prec);

    arb_init(w);
    arb_init(x);
    acb_init(y);
    acb_init(yxi);
#if DEBUG
    flint_printf("\ngc integral : d1 = %ld, d = %ld, g = %ld, n = %ld, prec = %ld",
            d1, d, g, gc->n, prec);
#endif

    sqrt_pol = &sqrt_pol_turn;
    if (flag & AJ_ROOT_DEF)
        sqrt_pol = &sqrt_pol_def;
    else if (flag & AJ_ROOT_TURN)
        sqrt_pol = &sqrt_pol_turn;

    /* compute integral */
    _acb_vec_zero(res, g);

    for (l = 0; l < gc->len; l++)
    {

        /* compute 1/y(x) */
        sqrt_pol(y, u, d1, d, gc->x + l, prec);
        acb_inv(y, y, prec);

        /* differentials */
        acb_vec_add_geom_arb(res, g, y, gc->x + l, prec);

        /* now on -x */
        arb_neg(x, gc->x + l);

        sqrt_pol(y, u, d1, d, x, prec);
        acb_inv(y, y, prec);
        acb_vec_add_geom_arb(res, g, y, x, prec);
    }

    if (gc->n % 2)
    {
        arb_zero(x);
        /* FIXME: pb with turn */
        sqrt_pol_def(y, u, d1, d, x, prec);
#if DEBUG > 1
        flint_printf("\nend integration sum");
        _acb_vec_printd(res, g, 30, "\n");
        flint_printf("\nroots (d1=%ld, d=%ld)\n",d1,d);
        _acb_vec_printd(u, d, 30, "\n");
        flint_printf("\n -> y = ");
        acb_printd(y, 30);
#endif
        acb_inv(y, y, prec);
        acb_add(res + 0, res + 0, y, prec);
    }

    /* multiply by weight = Pi / n */
    arb_const_pi(w, prec);
    arb_div_ui(w, w, gc->n, prec);
    _acb_vec_scalar_mul_arb(res, res, g, w, prec);
#if DEBUG > 1
        flint_printf("\nend integration ");
        _acb_vec_printd(res, g, 30, "\n");
#endif

    arb_clear(x);
    arb_clear(w);
    acb_clear(y);
    acb_clear(yxi);
}
Exemple #12
0
void
acb_calc_cauchy_bound(arb_t bound, acb_calc_func_t func, void * param,
                      const acb_t x, const arb_t radius, slong maxdepth, slong prec)
{
    slong i, n, depth, wp;

    arb_t pi, theta, v, s1, c1, s2, c2, st, ct;
    acb_t t, u;
    arb_t b;

    arb_init(pi);
    arb_init(theta);
    arb_init(v);

    arb_init(s1);
    arb_init(c1);
    arb_init(s2);
    arb_init(c2);
    arb_init(st);
    arb_init(ct);

    acb_init(t);
    acb_init(u);
    arb_init(b);

    wp = prec + 20;

    arb_const_pi(pi, wp);
    arb_zero_pm_inf(b);

    for (depth = 0, n = 16; depth < maxdepth; n *= 2, depth++)
    {
        arb_zero(b);

        /* theta = 2 pi / n */
        arb_div_ui(theta, pi, n, wp);
        arb_mul_2exp_si(theta, theta, 1);

        /* sine and cosine of i*theta and (i+1)*theta */
        arb_zero(s1);
        arb_one(c1);
        arb_sin_cos(st, ct, theta, wp);
        arb_set(s2, st);
        arb_set(c2, ct);

        for (i = 0; i < n; i++)
        {
            /* sine and cosine of 2 pi ([i,i+1]/n) */

            /* since we use power of two subdivision points, the
               sine and cosine are monotone on each subinterval */
            arb_union(acb_realref(t), c1, c2, wp);
            arb_union(acb_imagref(t), s1, s2, wp);
            acb_mul_arb(t, t, radius, wp);
            acb_add(t, t, x, prec);

            /* next angle */
            arb_mul(v, c2, ct, wp);
            arb_mul(c1, s2, st, wp);
            arb_sub(c1, v, c1, wp);
            arb_mul(v, c2, st, wp);
            arb_mul(s1, s2, ct, wp);
            arb_add(s1, v, s1, wp);
            arb_swap(c1, c2);
            arb_swap(s1, s2);

            func(u, t, param, 1, prec);
            acb_abs(v, u, prec);
            arb_add(b, b, v, prec);
        }

        arb_div_ui(b, b, n, prec);

        if (arb_is_positive(b))
            break;
    }

    arb_set(bound, b);

    arb_clear(pi);
    arb_clear(theta);
    arb_clear(v);

    acb_clear(t);
    acb_clear(u);
    arb_clear(b);

    arb_clear(s1);
    arb_clear(c1);
    arb_clear(s2);
    arb_clear(c2);
    arb_clear(st);
    arb_clear(ct);
}
Exemple #13
0
void
_arb_poly_exp_series(arb_ptr f, arb_srcptr h, slong hlen, slong n, slong prec)
{
    hlen = FLINT_MIN(hlen, n);

    if (hlen == 1)
    {
        arb_exp(f, h, prec);
        _arb_vec_zero(f + 1, n - 1);
    }
    else if (n == 2)
    {
        arb_exp(f, h, prec);
        arb_mul(f + 1, f, h + 1, prec);  /* safe since hlen >= 2 */
    }
    else if (_arb_vec_is_zero(h + 1, hlen - 2)) /* h = a + bx^d */
    {
        slong i, j, d = hlen - 1;
        arb_t t;
        arb_init(t);
        arb_set(t, h + d);
        arb_exp(f, h, prec);
        for (i = 1, j = d; j < n; j += d, i++)
        {
            arb_mul(f + j, f + j - d, t, prec);
            arb_div_ui(f + j, f + j, i, prec);
            _arb_vec_zero(f + j - d + 1, hlen - 2);
        }
        _arb_vec_zero(f + j - d + 1, n - (j - d + 1));
        arb_clear(t);
    }
    else if (hlen <= arb_poly_newton_exp_cutoff)
    {
        _arb_poly_exp_series_basecase(f, h, hlen, n, prec);
    }
    else
    {
        arb_ptr g, t;
        arb_t u;
        int fix;

        g = _arb_vec_init((n + 1) / 2);
        fix = (hlen < n || h == f || !arb_is_zero(h));

        if (fix)
        {
            t = _arb_vec_init(n);
            _arb_vec_set(t + 1, h + 1, hlen - 1);
        }
        else
            t = (arb_ptr) h;

        arb_init(u);
        arb_exp(u, h, prec);

        _arb_poly_exp_series_newton(f, g, t, n, prec, 0, arb_poly_newton_exp_cutoff);

        if (!arb_is_one(u))
            _arb_vec_scalar_mul(f, f, n, u, prec);

        _arb_vec_clear(g, (n + 1) / 2);
        if (fix)
            _arb_vec_clear(t, n);
        arb_clear(u);
    }
}
Exemple #14
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;
}
Exemple #15
0
void Lib_Arb_Div_Ui(ArbPtr f, ArbPtr g,  uint32_t x, int32_t prec)
{
    arb_div_ui( (arb_ptr) f,  (arb_ptr) g,  x, prec);
}
Exemple #16
0
void
_acb_poly_zeta_em_bound(arb_ptr bound, const acb_t s, const acb_t a, ulong N, ulong M, slong len, slong wp)
{
    arb_t K, C, AN, S2M;
    arb_ptr F, R;
    slong k;

    arb_srcptr alpha = acb_realref(a);
    arb_srcptr beta  = acb_imagref(a);
    arb_srcptr sigma = acb_realref(s);
    arb_srcptr tau   = acb_imagref(s);

    arb_init(AN);
    arb_init(S2M);

    /* require alpha + N > 1, sigma + 2M > 1 */
    arb_add_ui(AN, alpha, N - 1, wp);
    arb_add_ui(S2M, sigma, 2*M - 1, wp);

    if (!arb_is_positive(AN) || !arb_is_positive(S2M) || N < 1 || M < 1)
    {
        arb_clear(AN);
        arb_clear(S2M);

        for (k = 0; k < len; k++)
            arb_pos_inf(bound + k);

        return;
    }

    /* alpha + N, sigma + 2M */
    arb_add_ui(AN, AN, 1, wp);
    arb_add_ui(S2M, S2M, 1, wp);

    R = _arb_vec_init(len);
    F = _arb_vec_init(len);

    arb_init(K);
    arb_init(C);

    /* bound for power integral */
    bound_C(C, AN, beta, wp);
    bound_K(K, AN, beta, tau, wp);
    bound_I(R, AN, S2M, C, len, wp);

    for (k = 0; k < len; k++)
    {
        arb_mul(R + k, R + k, K, wp);
        arb_div_ui(K, K, k + 1, wp);
    }

    /* bound for rising factorial */
    bound_rfac(F, s, 2*M, len, wp);

    /* product (TODO: only need upper bound; write a function for this) */
    _arb_poly_mullow(bound, F, len, R, len, len, wp);

    /* bound for bernoulli polynomials, 4 / (2pi)^(2M) */
    arb_const_pi(C, wp);
    arb_mul_2exp_si(C, C, 1);
    arb_pow_ui(C, C, 2 * M, wp);
    arb_ui_div(C, 4, C, wp);
    _arb_vec_scalar_mul(bound, bound, len, C, wp);

    arb_clear(K);
    arb_clear(C);
    arb_clear(AN);
    arb_clear(S2M);

    _arb_vec_clear(R, len);
    _arb_vec_clear(F, len);
}