Example #1
0
void
_arb_poly_log1p_series(arb_ptr res, arb_srcptr f, slong flen, slong n, slong prec)
{
    arb_t a;

    flen = FLINT_MIN(flen, n);

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

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

        arb_add_ui(res, f + 0, 1, prec);

        for (i = 1, j = d; j < n; j += d, i++)
        {
            if (i == 1)
                arb_div(res + j, f + d, res, 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);
    }
    else
    {
        arb_ptr f_diff, f_inv;
        slong alloc;

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

        arb_add_ui(f_diff, f, 1, prec);
        _arb_vec_set(f_diff + 1, f + 1, flen - 1);
        _arb_poly_inv_series(f_inv, f_diff, flen, n, prec);
        _arb_poly_derivative(f_diff, f, flen, prec);
        _arb_poly_mullow(res, f_inv, n - 1, f_diff, flen - 1, n - 1, prec);
        _arb_poly_integral(res, res, n, prec);

        _arb_vec_clear(f_inv, alloc);
    }

    arb_swap(res, a);
    arb_clear(a);
}
Example #2
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);
}
Example #3
0
File: lu.c Project: bluescarni/arb
int
arb_mat_lu(long * P, arb_mat_t LU, const arb_mat_t A, long prec)
{
    arb_t d, e;
    arb_ptr * a;
    long i, j, m, n, r, row, col;
    int result;

    m = arb_mat_nrows(A);
    n = arb_mat_ncols(A);

    result = 1;

    if (m == 0 || n == 0)
        return result;

    arb_mat_set(LU, A);

    a = LU->rows;

    row = col = 0;
    for (i = 0; i < m; i++)
        P[i] = i;

    arb_init(d);
    arb_init(e);

    while (row < m && col < n)
    {
        r = arb_mat_find_pivot_partial(LU, row, m, col);

        if (r == -1)
        {
            result = 0;
            break;
        }
        else if (r != row)
            arb_mat_swap_rows(LU, P, row, r);

        arb_set(d, a[row] + col);

        for (j = row + 1; j < m; j++)
        {
            arb_div(e, a[j] + col, d, prec);
            arb_neg(e, e);
            _arb_vec_scalar_addmul(a[j] + col,
                a[row] + col, n - col, e, prec);
            arb_zero(a[j] + col);
            arb_neg(a[j] + row, e);
        }

        row++;
        col++;
    }

    arb_clear(d);
    arb_clear(e);

    return result;
}
Example #4
0
void
arb_sech(arb_t res, const arb_t x, slong prec)
{
    if (arf_cmpabs_2exp_si(arb_midref(x), 0) > 0)
    {
        arb_t t;
        arb_init(t);

        if (arf_sgn(arb_midref(x)) > 0)
        {
            arb_neg(t, x);
            arb_exp(t, t, prec + 4);
        }
        else
        {
            arb_exp(t, x, prec + 4);
        }

        arb_mul(res, t, t, prec + 4);
        arb_add_ui(res, res, 1, prec + 4);
        arb_div(res, t, res, prec);
        arb_mul_2exp_si(res, res, 1);
        arb_clear(t);
    }
    else
    {
        arb_cosh(res, x, prec + 4);
        arb_inv(res, res, prec);
    }
}
Example #5
0
void
_arb_poly_sqrt_series(arb_ptr g,
    arb_srcptr h, long hlen, long len, long prec)
{
    hlen = FLINT_MIN(hlen, len);

    if (hlen == 1)
    {
        arb_sqrt(g, h, prec);
        _arb_vec_zero(g + 1, len - 1);
    }
    else if (len == 2)
    {
        arb_sqrt(g, h, prec);
        arb_div(g + 1, h + 1, h, prec);
        arb_mul(g + 1, g + 1, g, prec);
        arb_mul_2exp_si(g + 1, g + 1, -1);
    }
    else
    {
        arb_ptr t;
        t = _arb_vec_init(len);
        _arb_poly_rsqrt_series(t, h, hlen, len, prec);
        _arb_poly_mullow(g, t, len, h, hlen, len, prec);
        _arb_vec_clear(t, len);
    }
}
Example #6
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 3000 * arb_test_multiplier(); iter++)
    {
        arb_t a, b, c;
        slong 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), 3);

        arb_rgamma(b, a, prec1);
        arb_rgamma(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 1/gamma(z+1) = 1/gamma(z)/z */
        arb_div(b, b, a, prec1);
        arb_add_ui(c, a, 1, prec1);
        arb_rgamma(c, c, prec1);

        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);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Example #7
0
void
arb_rising_fmpq_ui(arb_t y, const fmpq_t x, ulong n, long prec)
{
    if (n == 0)
    {
        arb_one(y);
    }
    else if (n == 1)
    {
        arb_set_fmpq(y, x, prec);
    }
    else
    {
        long wp;

        wp = ARF_PREC_ADD(prec, FLINT_BIT_COUNT(n));

        bsplit(y, fmpq_numref(x), fmpq_denref(x), 0, n, wp);

        if (fmpz_is_one(fmpq_denref(x)))
        {
            arb_set_round(y, y, prec);
        }
        else
        {
            arb_t t;
            arb_init(t);
            arb_set_fmpz(t, fmpq_denref(x));
            arb_pow_ui(t, t, n, wp);
            arb_div(y, y, t, prec);
            arb_clear(t);
        }
    }
}
Example #8
0
static void
_interpolate_newton(arb_ptr ys, arb_srcptr xs, long n, long prec)
{
    arb_t p, q, t;
    long i, j;

    arb_init(p);
    arb_init(q);
    arb_init(t);

    for (i = 1; i < n; i++)
    {
        arb_set(t, ys + i - 1);

        for (j = i; j < n; j++)
        {
            arb_sub(p, ys + j, t, prec);
            arb_sub(q, xs + j, xs + j - i, prec);
            arb_set(t, ys + j);
            arb_div(ys + j, p, q, prec);
        }
    }

    arb_clear(p);
    arb_clear(q);
    arb_clear(t);
}
Example #9
0
void
nd_accum_accumulate(nd_accum_t a, int *coords, arb_struct *value, slong prec)
{
    int axis_idx;
    int offset, coord, stride;
    nd_axis_struct *axis;
    arb_struct *p;
    arb_t x;

    arb_init(x);
    arb_set(x, value);
    offset = 0;
    for (axis_idx = 0; axis_idx < a->ndim; axis_idx++)
    {
        axis = a->axes + axis_idx;
        coord = coords[axis_idx];
        stride = a->strides[axis_idx];

        /*
        flint_printf("debug:\n");
        flint_printf("ndim=%wd axis=%d coord=%d\n", a->ndim, axis_idx, coord);
        flint_printf("strides:\n");
        {
            int j;
            for (j = 0; j < a->ndim; j++)
            {
                flint_printf("%d : %d\n", j, a->strides[j]);
            }
        }
        */

        if (axis->agg_weights)
        {
            arb_mul(x, x, axis->agg_weights + coord, prec);

            /* todo: delay this division */
            arb_div(x, x, axis->agg_weight_divisor, prec);
        }
        else
        {
            offset += coord * stride;
        }
    }
    if (offset < 0)
    {
        fprintf(stderr, "internal error: negative offset\n");
        abort();
    }
    if (offset >= a->size)
    {
        fprintf(stderr, "internal error: offset=%d >= size=%d\n",
                offset, a->size);
        abort();
    }
    p = a->data + offset;
    arb_add(p, p, x, prec);
    arb_clear(x);
}
Example #10
0
File: tan.c Project: bluescarni/arb
void
arb_tan(arb_t y, const arb_t x, long prec)
{
    arb_t u;
    arb_init(u);
    arb_sin_cos(y, u, x, prec + 4);
    arb_div(y, y, u, prec);
    arb_clear(u);
}
Example #11
0
File: div.c Project: 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);
}
Example #12
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);
}
Example #13
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);
    }
}
Example #14
0
/* 0.5*(B/AN)^2 + |B|/AN */
static void
bound_C(arb_t C, const arb_t AN, const arb_t B, slong wp)
{
    arb_t t;
    arb_init(t);
    arb_abs(t, B);
    arb_div(t, t, AN, wp);
    arb_mul_2exp_si(C, t, -1);
    arb_add_ui(C, C, 1, wp);
    arb_mul(C, C, t, wp);
    arb_clear(t);
}
Example #15
0
void
_arb_sinc_direct(arb_t z, const arb_t x, slong prec)
{
    /* z = sin(x) / x */
    slong wp;
    arb_t y;
    wp = prec + 2;
    arb_init(y);
    arb_sin(y, x, wp);
    arb_div(z, y, x, prec);
    arb_clear(y);
}
void 
_arb_poly_div_series(arb_ptr Q, arb_srcptr A, long Alen,
    arb_srcptr B, long Blen, long n, long prec)
{
    Alen = FLINT_MIN(Alen, n);
    Blen = FLINT_MIN(Blen, n);

    if (Blen == 1)
    {
        _arb_vec_scalar_div(Q, A, Alen, B, prec);
        _arb_vec_zero(Q + Alen, n - Alen);
    }
    else if (n == 2)
    {
        if (Alen == 1)
        {
            arb_div(Q, A, B, prec);
            arb_div(Q + 1, Q, B, prec);
            arb_mul(Q + 1, Q + 1, B + 1, prec);
            arb_neg(Q + 1, Q + 1);
        }
        else
        {
            arb_div(Q, A, B, prec);
            arb_mul(Q + 1, Q, B + 1, prec);
            arb_sub(Q + 1, A + 1, Q + 1, prec);
            arb_div(Q + 1, Q + 1, B, prec);
        }
    }
    else
    {
        arb_ptr Binv;
        Binv = _arb_vec_init(n);
        _arb_poly_inv_series(Binv, B, Blen, n, prec);
        _arb_poly_mullow(Q, Binv, n, A, Alen, n, prec);
        _arb_vec_clear(Binv, n);
    }
}
Example #17
0
void
arb_mat_solve_cho_precomp(arb_mat_t X,
    const arb_mat_t L, const arb_mat_t B, slong prec)
{
    slong i, j, c, n, m;

    n = arb_mat_nrows(X);
    m = arb_mat_ncols(X);

    arb_mat_set(X, B);

    for (c = 0; c < m; c++)
    {
        /* solve Ly = b */
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < i; j++)
            {
                arb_submul(arb_mat_entry(X, i, c),
                    arb_mat_entry(L, i, j), arb_mat_entry(X, j, c), prec);
            }
            arb_div(arb_mat_entry(X, i, c), arb_mat_entry(X, i, c),
                arb_mat_entry(L, i, i), prec);
        }

        /* solve Ux = y */
        for (i = n - 1; i >= 0; i--)
        {
            for (j = i + 1; j < n; j++)
            {
                arb_submul(arb_mat_entry(X, i, c),
                    arb_mat_entry(L, j, i), arb_mat_entry(X, j, c), prec);
            }
            arb_div(arb_mat_entry(X, i, c), arb_mat_entry(X, i, c),
                arb_mat_entry(L, i, i), prec);
        }
    }
}
Example #18
0
int arb_calc_newton_step(arb_t xnew, arb_calc_func_t func,
    void * param, const arb_t x, const arb_t conv_region,
    const arf_t conv_factor, slong prec)
{
    mag_t err, v;
    arb_t t;
    arb_struct u[2];
    int result;

    mag_init(err);
    mag_init(v);
    arb_init(t);
    arb_init(u + 0);
    arb_init(u + 1);

    mag_mul(err, arb_radref(x), arb_radref(x));
    arf_get_mag(v, conv_factor);
    mag_mul(err, err, v);

    arf_set(arb_midref(t), arb_midref(x));
    mag_zero(arb_radref(t));

    func(u, t, param, 2, prec);

    arb_div(u, u, u + 1, prec);
    arb_sub(u, t, u, prec);

    mag_add(arb_radref(u), arb_radref(u), err);

    if (arb_contains(conv_region, u) &&
        (mag_cmp(arb_radref(u), arb_radref(x)) < 0))
    {
        arb_swap(xnew, u);
        result = ARB_CALC_SUCCESS;
    }
    else
    {
        arb_set(xnew, x);
        result = ARB_CALC_NO_CONVERGENCE;
    }

    arb_clear(t);
    arb_clear(u);
    arb_clear(u + 1);
    mag_clear(err);
    mag_clear(v);

    return result;
}
Example #19
0
int
_arb_poly_newton_step(arb_t xnew, arb_srcptr poly, long len,
    const arb_t x,
    const arb_t convergence_interval,
    const arf_t convergence_factor, long prec)
{
    arf_t err;
    arb_t t, u, v;
    int result;

    arf_init(err);
    arb_init(t);
    arb_init(u);
    arb_init(v);

    arf_set_mag(err, arb_radref(x));
    arf_mul(err, err, err, MAG_BITS, ARF_RND_UP);
    arf_mul(err, err, convergence_factor, MAG_BITS, ARF_RND_UP);

    arf_set(arb_midref(t), arb_midref(x));
    mag_zero(arb_radref(t));

    _arb_poly_evaluate2(u, v, poly, len, t, prec);

    arb_div(u, u, v, prec);
    arb_sub(u, t, u, prec);

    arb_add_error_arf(u, err);

    if (arb_contains(convergence_interval, u) &&
        (mag_cmp(arb_radref(u), arb_radref(x)) < 0))
    {
        arb_swap(xnew, u);
        result = 1;
    }
    else
    {
        arb_set(xnew, x);
        result = 0;
    }

    arb_clear(t);
    arb_clear(u);
    arb_clear(v);
    arf_clear(err);

    return result;
}
Example #20
0
void arb_mat_cholesky(arb_mat_t out, const arb_mat_t in, slong prec) {
    int nrows = arb_mat_nrows(in);
    for(int j = 0; j < nrows; j++) {
        for(int i = j; i < nrows; i++) {
            arb_set(arb_mat_entry(out, i, j), arb_mat_entry(in, i, j));
            for(int k = 0; k < j; k++) {
                arb_submul(arb_mat_entry(out, i, j), arb_mat_entry(out, i, k), arb_mat_entry(out, j, k), prec);
            }
            if(i == j) {
                arb_sqrt(arb_mat_entry(out, i, j), arb_mat_entry(out, i, j), prec);
            }
            else {
                arb_div(arb_mat_entry(out, i, j), arb_mat_entry(out, i, j), arb_mat_entry(out, j, j), prec);
            }
        }
    }
}
Example #21
0
void
arb_bernoulli_fmpz(arb_t res, const fmpz_t n, slong prec)
{
    if (fmpz_cmp_ui(n, UWORD_MAX) <= 0)
    {
        if (fmpz_sgn(n) >= 0)
            arb_bernoulli_ui(res, fmpz_get_ui(n), prec);
        else
            arb_zero(res);
    }
    else if (fmpz_is_odd(n))
    {
        arb_zero(res);
    }
    else
    {
        arb_t t;
        slong wp;

        arb_init(t);
        wp = prec + 2 * fmpz_bits(n);

        /* zeta(n) ~= 1 */
        arf_one(arb_midref(res));
        mag_one(arb_radref(res));
        mag_mul_2exp_si(arb_radref(res), arb_radref(res), WORD_MIN);

        /* |B_n| = 2 * n! / (2*pi)^n * zeta(n) */
        arb_gamma_fmpz(t, n, wp);
        arb_mul_fmpz(t, t, n, wp);
        arb_mul(res, res, t, wp);

        arb_const_pi(t, wp);
        arb_mul_2exp_si(t, t, 1);
        arb_pow_fmpz(t, t, n, wp);

        arb_div(res, res, t, prec);
        arb_mul_2exp_si(res, res, 1);

        if (fmpz_fdiv_ui(n, 4) == 0)
            arb_neg(res, res);

        arb_clear(t);
    }
}
Example #22
0
void
arb_zeta_ui_borwein_bsplit(arb_t x, ulong s, slong prec)
{
    zeta_bsplit_t sum;
    mag_t err;
    slong wp, n;

    /* zeta(0) = -1/2 */
    if (s == 0)
    {
        arb_set_si(x, -1);
        arb_mul_2exp_si(x, x, -1);
        return;
    }

    if (s == 1)
    {
        flint_printf("zeta_ui_borwein_bsplit: zeta(1)");
        abort();
    }

    n = prec / ERROR_B + 2;
    wp = prec + 30;

    zeta_bsplit_init(sum);
    zeta_bsplit(sum, 0, n + 1, n, s, 0, wp);

    /*  A/Q3 - B/Q3 / (C/Q1) = (A*C - B*Q1) / (Q3*C)    */
    arb_mul(sum->A, sum->A, sum->C, wp);
    arb_mul(sum->B, sum->B, sum->Q1, wp);
    arb_sub(sum->A, sum->A, sum->B, wp);
    arb_mul(sum->Q3, sum->Q3, sum->C, wp);
    arb_div(sum->C, sum->A, sum->Q3, wp);

    mag_init(err);
    mag_borwein_error(err, n);
    mag_add(arb_radref(sum->C), arb_radref(sum->C), err);
    mag_clear(err);

    /* convert from eta(s) to zeta(s) */
    arb_div_2expm1_ui(x, sum->C, s - 1, wp);
    arb_mul_2exp_si(x, x, s - 1);

    zeta_bsplit_clear(sum);
}
Example #23
0
void
arb_fac2_ui(arb_t res, ulong n, long prec)
{
    if (n % 2 == 0)
    {
        arb_fac_ui(res, n / 2, prec);
        arb_mul_2exp_si(res, res, n / 2);
    }
    else
    {
        arb_t t;
        arb_init(t);
        arb_fac2_ui(t, n - 1, prec + 5);
        arb_fac_ui(res, n, prec + 5);
        arb_div(res, res, t, prec);
        arb_clear(t);
    }
}
Example #24
0
static void
bound_K(arb_t C, const arb_t AN, const arb_t B, const arb_t T, slong wp)
{
    if (arb_is_zero(B) || arb_is_zero(T))
    {
        arb_one(C);
    }
    else
    {
        arb_div(C, B, AN, wp);
        /* TODO: atan is dumb, should also bound by pi/2 */
        arb_atan(C, C, wp);
        arb_mul(C, C, T, wp);
        if (arb_is_nonpositive(C))
            arb_one(C);
        else
            arb_exp(C, C, wp);
    }
}
Example #25
0
void
_arb_poly_borel_transform(arb_ptr res, arb_srcptr poly, long len, long prec)
{
    long i;

    arb_t t;
    arb_init(t);

    arb_one(t);

    for (i = 0; i < len; i++)
    {
        if (i > 1)
            arb_mul_ui(t, t, i, prec);

        arb_div(res + i, poly + i, t, prec);
    }

    arb_clear(t);
}
Example #26
0
void arb_calc_newton_conv_factor(arf_t conv_factor,
    arb_calc_func_t func, void * param,
    const arb_t conv_region, long prec)
{
    arb_struct t[3];

    arb_init(t);
    arb_init(t + 1);
    arb_init(t + 2);

    func(t, conv_region, param, 3, prec);

    arb_div(t, t + 2, t + 1, prec);
    arb_mul_2exp_si(t, t, -1);

    arb_get_abs_ubound_arf(conv_factor, t, prec);

    arb_clear(t);
    arb_clear(t + 1);
    arb_clear(t + 2);
}
Example #27
0
void
arb_const_e_eval(arb_t s, slong prec)
{
    hypgeom_t series;
    arb_t t;

    arb_init(t);
    hypgeom_init(series);

    fmpz_poly_set_str(series->A, "1  1");
    fmpz_poly_set_str(series->B, "1  1");
    fmpz_poly_set_str(series->P, "1  1");
    fmpz_poly_set_str(series->Q, "2  0 1");

    prec += FLINT_CLOG2(prec);
    arb_hypgeom_infsum(s, t, series, prec, prec);
    arb_div(s, s, t, prec);

    hypgeom_clear(series);
    arb_clear(t);
}
Example #28
0
void
arb_const_catalan_eval(arb_t s, slong prec)
{
    hypgeom_t series;
    arb_t t;

    arb_init(t);
    hypgeom_init(series);

    fmpz_poly_set_str(series->A, "3  19 56 40");
    fmpz_poly_set_str(series->B, "1  1");
    fmpz_poly_set_str(series->P, "5  0 0 0 32 -64");
    fmpz_poly_set_str(series->Q, "5  9 96 352 512 256");

    prec += FLINT_CLOG2(prec);
    arb_hypgeom_infsum(s, t, series, prec, prec);
    arb_mul_ui(t, t, 18, prec);
    arb_div(s, s, t, prec);

    hypgeom_clear(series);
    arb_clear(t);
}
Example #29
0
File: atanh.c Project: isuruf/arb
void
arb_atanh(arb_t z, const arb_t x, slong prec)
{
    if (arb_is_zero(x))
    {
        arb_zero(z);
    }
    else
    {
        arb_t t;
        arb_init(t);

        arb_sub_ui(t, x, 1, prec + 4);
        arb_div(t, x, t, prec + 4);
        arb_mul_2exp_si(t, t, 1);
        arb_neg(t, t);
        arb_log1p(z, t, prec);
        arb_mul_2exp_si(z, z, -1);

        arb_clear(t);
    }
}
Example #30
0
void
_arb_poly_inv_series(arb_ptr Qinv,
    arb_srcptr Q, slong Qlen, slong len, slong prec)
{
    arb_inv(Qinv, Q, prec);

    if (Qlen == 1)
    {
        _arb_vec_zero(Qinv + 1, len - 1);
    }
    else if (len == 2)
    {
        arb_div(Qinv + 1, Qinv, Q, prec);
        arb_mul(Qinv + 1, Qinv + 1, Q + 1, prec);
        arb_neg(Qinv + 1, Qinv + 1);
    }
    else
    {
        slong Qnlen, Wlen, W2len;
        arb_ptr W;

        W = _arb_vec_init(len);

        NEWTON_INIT(1, len)
        NEWTON_LOOP(m, n)

        Qnlen = FLINT_MIN(Qlen, n);
        Wlen = FLINT_MIN(Qnlen + m - 1, n);
        W2len = Wlen - m;
        MULLOW(W, Q, Qnlen, Qinv, m, Wlen, prec);
        MULLOW(Qinv + m, Qinv, m, W + m, W2len, n - m, prec);
        _arb_vec_neg(Qinv + m, Qinv + m, n - m);

        NEWTON_END_LOOP
        NEWTON_END

        _arb_vec_clear(W, len);
    }
}