Esempio n. 1
0
File: tanh.c Progetto: certik/arb
void
fmprb_tanh(fmprb_t y, const fmprb_t x, long prec)
{
    fmprb_t t, u;

    fmprb_init(t);
    fmprb_init(u);

    fmprb_mul_2exp_si(t, x, 1);

    if (fmpr_sgn(fmprb_midref(x)) >= 0)
    {
        fmprb_neg(t, t);
        fmprb_expm1(t, t, prec + 4);
        fmprb_add_ui(y, t, 2, prec + 4);
        fmprb_div(y, t, y, prec);
        fmprb_neg(y, y);
    }
    else
    {
        fmprb_expm1(t, t, prec + 4);
        fmprb_add_ui(y, t, 2, prec + 4);
        fmprb_div(y, t, y, prec);
    }

    fmprb_clear(t);
    fmprb_clear(u);
}
Esempio n. 2
0
File: lu.c Progetto: certik/arb
int
fmprb_mat_lu(long * P, fmprb_mat_t LU, const fmprb_mat_t A, long prec)
{
    fmprb_t d, e;
    fmprb_ptr * a;
    long i, j, m, n, r, row, col;
    int result;

    m = fmprb_mat_nrows(A);
    n = fmprb_mat_ncols(A);

    result = 1;

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

    fmprb_mat_set(LU, A);

    a = LU->rows;

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

    fmprb_init(d);
    fmprb_init(e);

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

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

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

        for (j = row + 1; j < m; j++)
        {
            fmprb_div(e, a[j] + col, d, prec);
            fmprb_neg(e, e);
            _fmprb_vec_scalar_addmul(a[j] + col,
                a[row] + col, n - col, e, prec);
            fmprb_zero(a[j] + col);
            fmprb_neg(a[j] + row, e);
        }

        row++;
        col++;
    }

    fmprb_clear(d);
    fmprb_clear(e);

    return result;
}
Esempio n. 3
0
File: cos_pi.c Progetto: certik/arb
void
fmpcb_cos_pi(fmpcb_t r, const fmpcb_t z, long prec)
{
#define a fmpcb_realref(z)
#define b fmpcb_imagref(z)

    fmprb_t sa, ca, sb, cb;

    fmprb_init(sa);
    fmprb_init(ca);
    fmprb_init(sb);
    fmprb_init(cb);

    fmprb_sin_cos_pi(sa, ca, a, prec);
    fmprb_const_pi(cb, prec);
    fmprb_mul(cb, cb, b, prec);
    fmprb_sinh_cosh(sb, cb, cb, prec);

    fmprb_mul(fmpcb_realref(r), ca, cb, prec);
    fmprb_mul(fmpcb_imagref(r), sa, sb, prec);
    fmprb_neg(fmpcb_imagref(r), fmpcb_imagref(r));

    fmprb_clear(sa);
    fmprb_clear(ca);
    fmprb_clear(sb);
    fmprb_clear(cb);

#undef a
#undef b
}
Esempio n. 4
0
/* x(x+1)...(x+7) = (28 + 98x + 63x^2 + 14x^3 + x^4)^2 - 16 (7+2x)^2 */
static void
rfac_eight(fmprb_t t, const fmprb_t x, long prec)
{
    fmprb_t u, v;

    fmprb_init(u);
    fmprb_init(v);

    /* t = x^2, v = x^3, u = x^4 */
    fmprb_mul(t, x, x, prec);
    fmprb_mul(v, x, t, prec);
    fmprb_mul(u, t, t, prec);

    /* u = (28 + ...)^2 */
    fmprb_addmul_ui(u, v, 14UL, prec);
    fmprb_addmul_ui(u, t, 63UL, prec);
    fmprb_addmul_ui(u, x, 98UL, prec);
    fmprb_add_ui(u, u, 28UL, prec);
    fmprb_mul(u, u, u, prec);

    /* 16 (7+2x)^2 = 784 + 448x + 64x^2 */
    fmprb_sub_ui(u, u, 784UL, prec);
    fmprb_submul_ui(u, x, 448UL, prec);
    fmprb_mul_2exp_si(t, t, 6);
    fmprb_sub(t, u, t, prec);

    fmprb_clear(u);
    fmprb_clear(v);
}
Esempio n. 5
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 3000; iter++)
    {
        fmprb_t a, b, c;
        long prec1, prec2;

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

        fmprb_init(a);
        fmprb_init(b);
        fmprb_init(c);

        fmprb_randtest_precise(a, state, 1 + n_randint(state, 1000), 3);

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

        if (!fmprb_overlaps(b, c))
        {
            printf("FAIL: overlap\n\n");
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("c = "); fmprb_print(c); printf("\n\n");
            abort();
        }

        /* check 1/gamma(z+1) = 1/gamma(z)/z */
        fmprb_div(b, b, a, prec1);
        fmprb_add_ui(c, a, 1, prec1);
        fmprb_rgamma(c, c, prec1);

        if (!fmprb_overlaps(b, c))
        {
            printf("FAIL: functional equation\n\n");
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("c = "); fmprb_print(c); printf("\n\n");
            abort();
        }

        fmprb_clear(a);
        fmprb_clear(b);
        fmprb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 6
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        fmprb_poly_t f, g;
        fmprb_t x, y1, z1, y2, z2;

        fmprb_init(x);
        fmprb_init(y1);
        fmprb_init(z1);
        fmprb_init(y2);
        fmprb_init(z2);
        fmprb_poly_init(f);
        fmprb_poly_init(g);

        fmprb_randtest(x, state, 2 + n_randint(state, 1000), 5);
        fmprb_poly_randtest(f, state, 2 + n_randint(state, 100), 2 + n_randint(state, 1000), 5);
        fmprb_poly_derivative(g, f, 2 + n_randint(state, 1000));

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

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

        if (!fmprb_overlaps(y1, y2) || !fmprb_overlaps(z1, z2))
        {
            printf("FAIL\n\n");
            printf("f = "); fmprb_poly_printd(f, 15); printf("\n\n");
            printf("g = "); fmprb_poly_printd(g, 15); printf("\n\n");
            printf("x = "); fmprb_printd(x, 15); printf("\n\n");
            printf("y1 = "); fmprb_printd(y1, 15); printf("\n\n");
            printf("z1 = "); fmprb_printd(z1, 15); printf("\n\n");
            printf("y2 = "); fmprb_printd(y2, 15); printf("\n\n");
            printf("z2 = "); fmprb_printd(z2, 15); printf("\n\n");
            abort();
        }

        fmprb_poly_clear(f);
        fmprb_poly_clear(g);
        fmprb_clear(x);
        fmprb_clear(y1);
        fmprb_clear(z1);
        fmprb_clear(y2);
        fmprb_clear(z2);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 7
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        fmprb_t a, b, c;
        ulong k;
        long prec;

        prec = 2 + n_randint(state, 200);
        k = 1 + n_randint(state, 10);

        fmprb_init(a);
        fmprb_init(b);
        fmprb_init(c);

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

        fmprb_root(b, a, k, prec);
        fmprb_pow_ui(c, b, k, prec);

        if (!fmprb_contains(c, a))
        {
            printf("FAIL: containment\n\n");
            printf("k = %lu\n", k);
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("c = "); fmprb_print(c); printf("\n\n");
            abort();
        }

        fmprb_root(a, a, k, prec);

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

        fmprb_clear(a);
        fmprb_clear(b);
        fmprb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 8
0
void
_fmprb_poly_evaluate_rectangular(fmprb_t y, fmprb_srcptr poly,
    long len, const fmprb_t x, long prec)
{
    long i, j, m, r;
    fmprb_ptr xs;
    fmprb_t s, t, c;

    if (len < 3)
    {
        if (len == 0)
        {
            fmprb_zero(y);
        }
        else if (len == 1)
        {
            fmprb_set_round(y, poly + 0, prec);
        }
        else if (len == 2)
        {
            fmprb_mul(y, x, poly + 1, prec);
            fmprb_add(y, y, poly + 0, prec);
        }
        return;
    }

    m = n_sqrt(len) + 1;
    r = (len + m - 1) / m;

    xs = _fmprb_vec_init(m + 1);
    fmprb_init(s);
    fmprb_init(t);
    fmprb_init(c);

    _fmprb_vec_set_powers(xs, x, m + 1, prec);

    fmprb_set(y, poly + (r - 1) * m);
    for (j = 1; (r - 1) * m + j < len; j++)
        fmprb_addmul(y, xs + j, poly + (r - 1) * m + j, prec);

    for (i = r - 2; i >= 0; i--)
    {
        fmprb_set(s, poly + i * m);
        for (j = 1; j < m; j++)
            fmprb_addmul(s, xs + j, poly + i * m + j, prec);

        fmprb_mul(y, y, xs + m, prec);
        fmprb_add(y, y, s, prec);
    }

    _fmprb_vec_clear(xs, m + 1);
    fmprb_clear(s);
    fmprb_clear(t);
    fmprb_clear(c);
}
Esempio n. 9
0
File: t-rsqrt.c Progetto: isuruf/arb
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

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

        fmprb_init(a);
        fmprb_init(b);
        fmprb_init(c);

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

        fmprb_rsqrt(b, a, prec);

        fmprb_inv(c, b, prec);
        fmprb_mul(c, c, c, prec);

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

        fmprb_rsqrt(a, a, prec);

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

        fmprb_clear(a);
        fmprb_clear(b);
        fmprb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 10
0
File: agm.c Progetto: bluescarni/arb
void
fmprb_agm(fmprb_t z, const fmprb_t x, const fmprb_t y, long prec)
{
    fmprb_t t, u, v, w;

    if (fmprb_contains_negative(x) || fmprb_contains_negative(y))
    {
        fmprb_indeterminate(z);
        return;
    }

    if (fmprb_is_zero(x) || fmprb_is_zero(y))
    {
        fmprb_zero(z);
        return;
    }

    fmprb_init(t);
    fmprb_init(u);
    fmprb_init(v);
    fmprb_init(w);

    fmprb_set(t, x);
    fmprb_set(u, y);

    while (!fmprb_overlaps(t, u) &&
            !fmprb_contains_nonpositive(t) &&
            !fmprb_contains_nonpositive(u))
    {
        fmprb_add(v, t, u, prec);
        fmprb_mul_2exp_si(v, v, -1);

        fmprb_mul(w, t, u, prec);
        fmprb_sqrt(w, w, prec);

        fmprb_swap(v, t);
        fmprb_swap(w, u);
    }

    if (!fmprb_is_finite(t) || !fmprb_is_finite(u))
    {
        fmprb_indeterminate(z);
    }
    else
    {
        fmprb_union(z, t, u, prec);
    }

    fmprb_clear(t);
    fmprb_clear(u);
    fmprb_clear(v);
    fmprb_clear(w);
}
Esempio n. 11
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100; iter++)
    {
        fmprb_t b, radius, ans;
        fmpcb_t x;
        long r, prec, maxdepth;

        fmprb_init(b);
        fmprb_init(radius);
        fmpcb_init(x);

        fmpcb_set_ui(x, 5);

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

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

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

        fmpr_set_d(fmprb_midref(ans), answers[r-1]);
        fmpr_set_d(fmprb_radref(ans), 1e-8);

        if (!fmprb_overlaps(b, ans))
        {
            printf("FAIL\n");
            printf("r = %ld, prec = %ld, maxdepth = %ld\n\n", r, prec, maxdepth);
            fmprb_printd(b, 15); printf("\n\n");
            fmprb_printd(ans, 15); printf("\n\n");
            abort();
        }

        fmprb_clear(b);
        fmprb_clear(radius);
        fmpcb_clear(x);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 12
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000; iter++)
    {
        fmprb_t c1, c2;
        fmpq_t x;
        long prec;

        prec = 2 + n_randint(state, 5000);

        fmprb_init(c1);
        fmprb_init(c2);
        fmpq_init(x);

        fmpq_randtest(x, state, 1 + n_randint(state, 200));

        fmprb_cos_pi_fmpq(c1, x, prec);

        fmprb_const_pi(c2, prec);
        fmprb_mul_fmpz(c2, c2, fmpq_numref(x), prec);
        fmprb_div_fmpz(c2, c2, fmpq_denref(x), prec);
        fmprb_cos(c2, c2, prec);

        if (!fmprb_overlaps(c1, c2))
        {
            printf("FAIL: overlap\n\n");
            printf("x = "); fmpq_print(x); printf("\n\n");
            printf("c1 = "); fmprb_printd(c1, 15); printf("\n\n");
            printf("c2 = "); fmprb_printd(c2, 15); printf("\n\n");
            abort();
        }

        fmprb_clear(c1);
        fmprb_clear(c2);
        fmpq_clear(x);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 13
0
void
bound_I(fmprb_ptr I, const fmprb_t A, const fmprb_t B, const fmprb_t C, long len, long wp)
{
    long k;

    fmprb_t D, Dk, L, T, Bm1;

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

    fmprb_sub_ui(Bm1, B, 1, wp);
    fmprb_one(L);

    /* T = 1 / (A^Bm1 * Bm1) */
    fmprb_inv(T, A, wp);
    fmprb_pow(T, T, Bm1, wp);
    fmprb_div(T, T, Bm1, wp);

    if (len > 1)
    {
        fmprb_log(D, A, wp);
        fmprb_add(D, D, C, wp);
        fmprb_mul(D, D, Bm1, wp);
        fmprb_set(Dk, D);
    }

    for (k = 0; k < len; k++)
    {
        if (k > 0)
        {
            fmprb_mul_ui(L, L, k, wp);
            fmprb_add(L, L, Dk, wp);
            fmprb_mul(Dk, Dk, D, wp);
        }

        fmprb_mul(I + k, L, T, wp);
        fmprb_div(T, T, Bm1, wp);
    }

    fmprb_clear(D);
    fmprb_clear(Dk);
    fmprb_clear(Bm1);
    fmprb_clear(T);
    fmprb_clear(L);
}
Esempio n. 14
0
void
_fmprb_poly_sin_series(fmprb_ptr g, fmprb_srcptr h, long hlen, long n, long prec)
{
    hlen = FLINT_MIN(hlen, n);

    if (hlen == 1)
    {
        fmprb_sin(g, h, prec);
        _fmprb_vec_zero(g + 1, n - 1);
    }
    else if (n == 2)
    {
        fmprb_t t;
        fmprb_init(t);
        fmprb_sin_cos(g, t, h, prec);
        fmprb_mul(g + 1, h + 1, t, prec);  /* safe since hlen >= 2 */
        fmprb_clear(t);
    }
    else
    {
        fmprb_ptr t = _fmprb_vec_init(n);
        _fmprb_poly_sin_cos_series(g, t, h, hlen, n, prec);
        _fmprb_vec_clear(t, n);
    }
}
Esempio n. 15
0
void
fmprb_poly_zeta_series(fmprb_poly_t res, const fmprb_poly_t f, const fmprb_t a, int deflate, long n, long prec)
{
    if (n == 0)
    {
        fmprb_poly_zero(res);
        return;
    }

    fmprb_poly_fit_length(res, n);

    if (f->length == 0)
    {
        fmprb_t t;
        fmprb_init(t);
        _fmprb_poly_zeta_series(res->coeffs, t, 1, a, deflate, n, prec);
        fmprb_clear(t);
    }
    else
    {
        _fmprb_poly_zeta_series(res->coeffs, f->coeffs, f->length, a, deflate, n, prec);
    }

    _fmprb_poly_set_length(res, n);
    _fmprb_poly_normalise(res);
}
Esempio n. 16
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 3000; iter++)
    {
        fmprb_t a, b, c;
        long prec1, prec2;

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

        fmprb_init(a);
        fmprb_init(b);
        fmprb_init(c);

        fmprb_randtest_precise(a, state, 1 + n_randint(state, 1000), 4);

        gamma_taylor_fmprb(b, a, prec1);
        fmprb_gamma(c, a, prec2);

        if (!fmprb_overlaps(b, c))
        {
            printf("FAIL: overlap\n\n");
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("c = "); fmprb_print(c); printf("\n\n");
            abort();
        }

        fmprb_clear(a);
        fmprb_clear(b);
        fmprb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Esempio n. 17
0
void *
_zeta_powsum_evaluator(void * arg_ptr)
{
    powsum_arg_t arg = *((powsum_arg_t *) arg_ptr);
    long i, k;

    fmpcb_t t, u, v;
    fmprb_t f;

    fmpcb_init(t);
    fmpcb_init(u);
    fmpcb_init(v);
    fmprb_init(f);

    _fmpcb_vec_zero(arg.z, arg.len);

    for (k = arg.n0; k < arg.n1; k++)
    {
        /* t = log(a+k) */
        fmpcb_add_ui(t, arg.a, k, arg.prec);
        fmpcb_log(t, t, arg.prec);

        /* u = (a+k)^(-s) */
        fmpcb_mul(u, t, arg.s, arg.prec);
        fmpcb_neg(u, u);
        fmpcb_exp(u, u, arg.prec);

        /* forward: u *= (-1)^d * log(a+k)^d / d! */
        if (arg.d0 != 0)
        {
            fmpcb_pow_ui(v, t, arg.d0, arg.prec);
            fmpcb_mul(u, u, v, arg.prec);
            fmprb_fac_ui(f, arg.d0, arg.prec);
            fmprb_div(fmpcb_realref(u), fmpcb_realref(u), f, arg.prec);
            fmprb_div(fmpcb_imagref(u), fmpcb_imagref(u), f, arg.prec);
            if (arg.d0 % 2)
                fmpcb_neg(u, u);
        }

        fmpcb_add(arg.z, arg.z, u, arg.prec);

        for (i = 1; i < arg.len; i++)
        {
            fmpcb_mul(u, u, t, arg.prec);
            fmpcb_div_si(u, u, -(arg.d0 + i), arg.prec);
            fmpcb_add(arg.z + i, arg.z + i, u, arg.prec);
        }
    }

    fmpcb_clear(t);
    fmpcb_clear(u);
    fmpcb_clear(v);
    fmprb_clear(f);

    flint_cleanup();

    return NULL;
}
Esempio n. 18
0
void
gamma_rising_fmprb_ui_bsplit_eight(fmprb_t y, const fmprb_t x, ulong n, long prec)
{
    if (n == 0)
    {
        fmprb_one(y);
    }
    else if (n == 1)
    {
        fmprb_set_round(y, x, prec);
    }
    else
    {
        ulong k, a;
        long wp;
        fmprb_t t, u;

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

        fmprb_init(t);
        fmprb_init(u);

        if (n >= 8)
        {
            bsplit(t, x, 0, (n / 8) * 8, wp);
            a = (n / 8) * 8;
        }
        else
        {
            fmprb_set(t, x);
            a = 1;
        }

        for (k = a; k < n; k++)
        {
            fmprb_add_ui(u, x, k, wp);
            fmprb_mul(t, t, u, wp);
        }

        fmprb_set_round(y, t, prec);

        fmprb_clear(t);
        fmprb_clear(u);
    }
}
Esempio n. 19
0
File: sub.c Progetto: isuruf/arb
void
fmprb_sub_si(fmprb_t z, const fmprb_t x, slong y, slong prec)
{
    fmprb_t t;
    fmprb_init(t);
    fmprb_set_si(t, y);
    fmprb_sub(z, x, t, prec);
    fmprb_clear(t);
}
Esempio n. 20
0
File: add.c Progetto: isuruf/arb
void
fmprb_add_ui(fmprb_t z, const fmprb_t x, ulong y, slong prec)
{
    fmprb_t t;
    fmprb_init(t);
    fmprb_set_ui(t, y);
    fmprb_add(z, x, t, prec);
    fmprb_clear(t);
}
Esempio n. 21
0
File: add.c Progetto: isuruf/arb
void
fmprb_add_fmpr(fmprb_t z, const fmprb_t x, const fmpr_t y, slong prec)
{
    fmprb_t t;
    fmprb_init(t);
    fmprb_set_fmpr(t, y);
    fmprb_add(z, x, t, prec);
    fmprb_clear(t);
}
Esempio n. 22
0
void
bernoulli_rev_init(bernoulli_rev_t iter, ulong nmax)
{
    long j;
    fmpz_t t;
    fmprb_t x;
    int round1, round2;
    long wp;

    nmax -= (nmax % 2);
    iter->n = nmax;

    iter->alloc = 0;
    if (nmax < BERNOULLI_REV_MIN)
        return;

    iter->prec = wp = global_prec(nmax);

    iter->max_power = zeta_terms(nmax, iter->prec);
    iter->alloc = iter->max_power + 1;
    iter->powers = _fmpz_vec_init(iter->alloc);
    fmpz_init(iter->pow_error);
    fmprb_init(iter->prefactor);
    fmprb_init(iter->two_pi_squared);

    fmprb_init(x);
    fmpz_init(t);

    /* precompute powers */
    for (j = 3; j <= iter->max_power; j += 2)
    {
        fmprb_ui_pow_ui(x, j, nmax, power_prec(j, nmax, wp));
        fmprb_ui_div(x, 1UL, x, power_prec(j, nmax, wp));
        round1 = fmpr_get_fmpz_fixed_si(t, fmprb_midref(x), -wp);
        fmpz_set(iter->powers + j, t);

        /* error: the radius, plus two roundings */
        round2 = fmpr_get_fmpz_fixed_si(t, fmprb_radref(x), -wp);
        fmpz_add_ui(t, t, (round1 != 0) + (round2 != 0));
        if (fmpz_cmp(iter->pow_error, t) < 0)
            fmpz_set(iter->pow_error, t);
    }

    /* precompute (2pi)^2 and 2*(n!)/(2pi)^n */
    fmprb_fac_ui(iter->prefactor, nmax, wp);
    fmprb_mul_2exp_si(iter->prefactor, iter->prefactor, 1);

    fmprb_const_pi(x, wp);
    fmprb_mul_2exp_si(x, x, 1);
    fmprb_mul(iter->two_pi_squared, x, x, wp);

    fmprb_pow_ui(x, iter->two_pi_squared, nmax / 2, wp);
    fmprb_div(iter->prefactor, iter->prefactor, x, wp);

    fmpz_clear(t);
    fmprb_clear(x);
}
Esempio n. 23
0
void
arb_get_rand_fmpq(fmpq_t q, flint_rand_t state, const arb_t x, slong bits)
{
    fmprb_t t;
    fmprb_init(t);
    arb_get_fmprb(t, x);
    fmprb_get_rand_fmpq(q, state, t, bits);
    fmprb_clear(t);
}
Esempio n. 24
0
void
fmprb_si_pow_ui(fmprb_t y, long b, ulong e, long prec)
{
    fmprb_t t;
    fmprb_init(t);
    fmprb_set_si(t, b);
    fmprb_pow_ui(y, t, e, prec);
    fmprb_clear(t);
}
Esempio n. 25
0
File: sqrt.c Progetto: isuruf/arb
void
fmprb_sqrt_fmpz(fmprb_t z, const fmpz_t x, slong prec)
{
    fmprb_t t;
    fmprb_init(t);
    fmprb_set_fmpz(t, x);
    fmprb_sqrt(z, t, prec);
    fmprb_clear(t);
}
Esempio n. 26
0
File: sub.c Progetto: isuruf/arb
void
fmprb_sub_fmpz(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec)
{
    fmprb_t t;
    fmprb_init(t);
    fmprb_set_fmpz(t, y);
    fmprb_sub(z, x, t, prec);
    fmprb_clear(t);
}
Esempio n. 27
0
File: sqrt.c Progetto: isuruf/arb
void
fmprb_sqrt_ui(fmprb_t z, ulong x, slong prec)
{
    fmprb_t t;
    fmprb_init(t);
    fmprb_set_ui(t, x);
    fmprb_sqrt(z, t, prec);
    fmprb_clear(t);
}
Esempio n. 28
0
int
z_function(fmprb_ptr out, const fmprb_t inp, void * params, long order, long prec)
{
    fmprb_struct x[2];

    fmprb_init(x);
    fmprb_init(x + 1);

    fmprb_set(x, inp);
    fmprb_one(x + 1);

    _fmprb_poly_riemann_siegel_z_series(out, x, FLINT_MIN(2, order), order, prec);

    fmprb_clear(x);
    fmprb_clear(x + 1);

    eval_count++;
    return 0;
}
Esempio n. 29
0
File: union.c Progetto: isuruf/arb
void
arb_union(arb_t z, const arb_t x, const arb_t y, slong prec)
{
    fmprb_t t, u, v;

    fmprb_init(t);
    fmprb_init(u);
    fmprb_init(v);

    arb_get_fmprb(t, x);
    arb_get_fmprb(u, y);

    fmprb_union(v, t, u, prec);

    arb_set_fmprb(z, v);

    fmprb_clear(t);
    fmprb_clear(u);
    fmprb_clear(v);
}
Esempio n. 30
0
File: t-mul.c Progetto: isuruf/arb
void
arb_mul_naive(arb_t z, const arb_t x, const arb_t y, slong prec)
{
    fmprb_t c, a, b;

    fmprb_init(a);
    fmprb_init(b);
    fmprb_init(c);

    arb_get_fmprb(a, x);
    arb_get_fmprb(b, y);

    fmprb_mul(c, a, b, prec);

    arb_set_fmprb(z, c);

    fmprb_clear(a);
    fmprb_clear(b);
    fmprb_clear(c);
}