Пример #1
0
void
gamma_taylor_bound_remainder(fmpr_t err, const fmpr_t z, long n)
{
    fmpr_t t, u;

    gamma_taylor_bound_extend_cache(n + 1);

    fmpr_init(t);
    fmpr_init(u);

    /* denominator: 1 - r(n+1) * z, rounded down */
    fmpr_mul(t, gamma_taylor_bound_ratio_cache + n + 1,
        z, FMPRB_RAD_PREC, FMPR_RND_UP);
    fmpr_one(u);
    fmpr_sub(u, u, t, FMPRB_RAD_PREC, FMPR_RND_DOWN);

    if (fmpr_sgn(u) <= 0)
    {
        fmpr_pos_inf(err);
    }
    else
    {
        fmpr_pow_sloppy_ui(t, z, n, FMPRB_RAD_PREC, FMPR_RND_UP);
        fmpr_mul_2exp_si(t, t, gamma_taylor_bound_mag_cache[n + 1]);
        fmpr_div(err, t, u, FMPRB_RAD_PREC, FMPR_RND_UP);
    }

    fmpr_clear(t);
    fmpr_clear(u);
}
Пример #2
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 2000 * arb_test_multiplier(); iter++)
    {
        fmpr_t x, y;
        fmpz_t f;
        mag_t xb;
        ulong n;

        fmpr_init(x);
        fmpr_init(y);
        fmpz_init(f);
        mag_init(xb);

        mag_randtest_special(xb, state, 80);
        n = n_randtest(state) % 2000;

        mag_rfac_ui(xb, n);
        fmpz_fac_ui(f, n);
        fmpr_one(x);
        fmpr_div_fmpz(x, x, f, 2 * MAG_BITS, FMPR_RND_UP);
        mag_get_fmpr(y, xb);

        MAG_CHECK_BITS(xb)

        if (!(fmpr_cmpabs(y, x) >= 0))
        {
            flint_printf("FAIL\n\n");
            flint_printf("n = %wu\n\n", n);
            flint_printf("x = "); fmpr_print(x); flint_printf("\n\n");
            flint_printf("y = "); fmpr_print(y); flint_printf("\n\n");
            abort();
        }

        fmpr_clear(x);
        fmpr_clear(y);
        fmpz_clear(f);
        mag_clear(xb);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #3
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        fmpr_t x, y;
        mag_t b;
        ulong m, n;

        fmpr_init(x);
        fmpr_init(y);
        mag_init(b);

        m = n_randtest(state);
        n = n_randtest(state);

        fmpr_one(x);
        fmpr_div_ui(x, x, m, 128, FMPR_RND_UP);
        fmpr_add_ui(x, x, 1, 128, FMPR_RND_UP);
        fmpr_pow_sloppy_ui(x, x, n, 128, FMPR_RND_UP);

        mag_binpow_uiui(b, m, n);
        mag_get_fmpr(y, b);

        MAG_CHECK_BITS(b)

        if (!(fmpr_cmpabs(x, y) <= 0))
        {
            flint_printf("FAIL\n\n");
            flint_printf("m = %wu\n\n", m);
            flint_printf("n = %wu\n\n", n);
            flint_printf("x = "); fmpr_printd(x, 10); flint_printf("\n\n");
            flint_printf("y = "); fmpr_printd(y, 10); flint_printf("\n\n");
            flint_abort();
        }

        fmpr_clear(x);
        fmpr_clear(y);
        mag_clear(b);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Пример #4
0
/* Absolute value of rising factorial (could speed up once complex gamma is available). */
void
fmpcb_rfac_abs_ubound2(fmpr_t bound, const fmpcb_t s, ulong n, long prec)
{
    fmpr_t term, t;
    ulong k;

    /* M(k) = (a+k)^2 + b^2
       M(0) = a^2 + b^2
       M(k+1) = M(k) + 2*a + (2*k+1)
    */
    fmpr_init(t);
    fmpr_init(term);

    fmpr_one(bound);

    /* M(0) = a^2 + b^2 */
    fmprb_get_abs_ubound_fmpr(t, fmpcb_realref(s), prec);
    fmpr_mul(term, t, t, prec, FMPR_RND_UP);
    fmprb_get_abs_ubound_fmpr(t, fmpcb_imagref(s), prec);
    fmpr_mul(t, t, t, prec, FMPR_RND_UP);
    fmpr_add(term, term, t, prec, FMPR_RND_UP);

    /* we add t = 2*a to each term. note that this can be signed;
       we always want the most positive value */
    fmpr_add(t, fmprb_midref(fmpcb_realref(s)),
        fmprb_radref(fmpcb_realref(s)), prec, FMPR_RND_CEIL);
    fmpr_mul_2exp_si(t, t, 1);

    for (k = 0; k < n; k++)
    {
        fmpr_mul(bound, bound, term, prec, FMPR_RND_UP);
        fmpr_add_ui(term, term, 2 * k + 1, prec, FMPR_RND_UP);
        fmpr_add(term, term, t, prec, FMPR_RND_UP);
    }

    fmpr_sqrt(bound, bound, prec, FMPR_RND_UP);

    fmpr_clear(t);
    fmpr_clear(term);
}
Пример #5
0
Файл: det.c Проект: certik/arb
void
fmprb_mat_det_inplace(fmprb_t det, fmprb_mat_t A, long prec)
{
    long i, n, sign, rank;

    n = fmprb_mat_nrows(A);
    rank = fmprb_mat_gauss_partial(A, prec);
    sign = (rank < 0) ? -1 : 1;
    rank = FLINT_ABS(rank);

    fmprb_set_si(det, sign);
    for (i = 0; i < rank; i++)
        fmprb_mul(det, det, fmprb_mat_entry(A, i, i), prec);

    /* bound unreduced part using Hadamard's inequality */
    if (rank < n)
    {
        fmpr_t t;
        fmprb_t d;

        fmpr_init(t);
        fmprb_init(d);

        fmpr_one(fmprb_radref(d));

        for (i = rank; i < n; i++)
        {
            fmprb_vec_get_fmpr_2norm_squared_bound(t, A->rows[i] + rank, 
                n - rank, FMPRB_RAD_PREC);
            fmpr_mul(fmprb_radref(d), fmprb_radref(d), t, FMPRB_RAD_PREC, FMPR_RND_UP);
        }

        fmpr_sqrt(fmprb_radref(d), fmprb_radref(d), FMPRB_RAD_PREC, FMPR_RND_UP);
        fmprb_mul(det, det, d, prec);

        fmprb_clear(d);
        fmpr_clear(t);
    }
}