예제 #1
0
파일: get_rand_fmpq.c 프로젝트: isuruf/arb
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);
}
예제 #2
0
int main()
{
    slong iter;
    flint_rand_t state;

    flint_printf("get_rand_fmpq....");
    fflush(stdout);
    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        fmprb_t x;
        fmpq_t q;

        fmprb_init(x);
        fmpq_init(q);

        fmprb_randtest(x, state, 1 + n_randint(state, 200), 10);
        fmprb_get_rand_fmpq(q, state, x, 1 + n_randint(state, 200));

        if (!fmprb_contains_fmpq(x, q) || !fmpq_is_canonical(q))
        {
            flint_printf("FAIL:\n\n");
            flint_printf("x = "); fmprb_print(x); flint_printf("\n\n");
            flint_printf("q = "); fmpq_print(q); flint_printf("\n\n");
            abort();
        }

        fmprb_clear(x);
        fmpq_clear(q);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
예제 #3
0
파일: t-exp.c 프로젝트: bluescarni/arb
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        fmprb_t a, b;
        fmpq_t q;
        mpfr_t t;
        long prec = 2 + n_randint(state, 200);

        fmprb_init(a);
        fmprb_init(b);
        fmpq_init(q);
        mpfr_init2(t, prec + 100);

        fmprb_randtest(a, state, 1 + n_randint(state, 200), 3);
        fmprb_randtest(b, state, 1 + n_randint(state, 200), 3);
        fmprb_get_rand_fmpq(q, state, a, 1 + n_randint(state, 200));

        fmpq_get_mpfr(t, q, MPFR_RNDN);
        mpfr_exp(t, t, MPFR_RNDN);

        fmprb_exp(b, a, prec);

        if (!fmprb_contains_mpfr(b, t))
        {
            printf("FAIL: containment\n\n");
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            abort();
        }

        fmprb_exp(a, a, prec);

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

        fmprb_clear(a);
        fmprb_clear(b);
        fmpq_clear(q);
        mpfr_clear(t);
    }

    /* check large arguments */
    for (iter = 0; iter < 100000; iter++)
    {
        fmprb_t a, b, c, d;
        long prec1, prec2;

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

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

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

        fmprb_exp(b, a, prec1);
        fmprb_exp(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_randtest_precise(b, state, 1 + n_randint(state, 1000), 100);

        /* check exp(a)*exp(b) = exp(a+b) */
        fmprb_exp(c, a, prec1);
        fmprb_exp(d, b, prec1);
        fmprb_mul(c, c, d, prec1);

        fmprb_add(d, a, b, prec1);
        fmprb_exp(d, d, prec1);

        if (!fmprb_overlaps(c, d))
        {
            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");
            printf("d = "); fmprb_print(d); printf("\n\n");
            abort();
        }

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

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
예제 #4
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* compare with fmpq */
    for (iter = 0; iter < 1000; iter++)
    {
        fmprb_t a, b;
        fmpq_t x, y, z;
        ulong n;
        long i;

        fmprb_init(a);
        fmprb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

        fmprb_randtest(a, state, 1 + n_randint(state, 1000), 10);
        fmprb_randtest(b, state, 1 + n_randint(state, 1000), 10);
        n = n_randint(state, 40);

        fmprb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 1000));

        gamma_rising_fmprb_ui_bsplit_simple(b, a, n, 2 + n_randint(state, 1000));

        fmpq_one(y);
        for (i = 0; i < n; i++)
        {
            fmpq_set_si(z, i, 1);
            fmpq_add(z, x, z);
            fmpq_mul(y, y, z);
        }

        if (!fmprb_contains_fmpq(b, y))
        {
            printf("FAIL: containment\n\n");
            printf("n = %lu\n", n);
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("x = "); fmpq_print(x); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("y = "); fmpq_print(y); printf("\n\n");
            abort();
        }

        fmprb_clear(a);
        fmprb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of y and x */
    for (iter = 0; iter < 1000; iter++)
    {
        fmprb_t x, y;
        ulong n;
        long prec;

        fmprb_init(x);
        fmprb_init(y);

        fmprb_randtest(x, state, 1 + n_randint(state, 200), 10);
        fmprb_randtest(y, state, 1 + n_randint(state, 200), 10);
        n = n_randint(state, 100);

        prec = 2 + n_randint(state, 200);
        gamma_rising_fmprb_ui_bsplit_simple(y, x, n, prec);
        gamma_rising_fmprb_ui_bsplit_simple(x, x, n, prec);

        if (!fmprb_equal(x, y))
        {
            printf("FAIL: aliasing\n\n");
            printf("x = "); fmprb_print(x); printf("\n\n");
            printf("y = "); fmprb_print(y); printf("\n\n");
            printf("n = %lu\n", n);
            abort();
        }

        fmprb_clear(x);
        fmprb_clear(y);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
예제 #5
0
파일: t-agm.c 프로젝트: isuruf/arb
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        fmprb_t a, b, c;
        fmpq_t q, r;
        mpfr_t t, u;
        slong prec = 2 + n_randint(state, 200);

        fmprb_init(a);
        fmprb_init(b);
        fmprb_init(c);
        fmpq_init(q);
        fmpq_init(r);
        mpfr_init2(t, prec + 100);
        mpfr_init2(u, prec + 100);

        fmprb_randtest(a, state, 1 + n_randint(state, 200), 3);
        fmprb_randtest(b, state, 1 + n_randint(state, 200), 3);
        fmprb_randtest(c, state, 1 + n_randint(state, 200), 3);

        fmprb_agm(c, a, b, prec);

        if (fmprb_equal(a, b))
        {
            if (!fmprb_contains(c, a))
            {
                flint_printf("FAIL: containment (identity)\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();
            }
        }
        else
        {
            fmprb_get_rand_fmpq(q, state, a, 1 + n_randint(state, 200));
            fmprb_get_rand_fmpq(r, state, b, 1 + n_randint(state, 200));
            fmpq_get_mpfr(t, q, MPFR_RNDN);
            fmpq_get_mpfr(u, r, MPFR_RNDN);
            mpfr_agm(t, t, u, MPFR_RNDN);

            if (!fmprb_contains_mpfr(c, t))
            {
                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_clear(a);
        fmprb_clear(b);
        fmprb_clear(c);
        fmpq_clear(q);
        fmpq_clear(r);
        mpfr_clear(t);
        mpfr_clear(u);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
예제 #6
0
파일: t-cosh.c 프로젝트: jwbober/arb
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        fmprb_t a, b;
        fmpq_t q;
        mpfr_t t;
        long prec = 2 + n_randint(state, 200);

        fmprb_init(a);
        fmprb_init(b);
        fmpq_init(q);
        mpfr_init2(t, prec + 100);

        fmprb_randtest(a, state, 1 + n_randint(state, 200), 3);
        fmprb_randtest(b, state, 1 + n_randint(state, 200), 3);
        fmprb_get_rand_fmpq(q, state, a, 1 + n_randint(state, 200));

        fmpq_get_mpfr(t, q, MPFR_RNDN);
        mpfr_cosh(t, t, MPFR_RNDN);

        fmprb_cosh(b, a, prec);

        if (!fmprb_contains_mpfr(b, t))
        {
            printf("FAIL: containment\n\n");
            printf("a = ");
            fmprb_print(a);
            printf("\n\n");
            printf("b = ");
            fmprb_print(b);
            printf("\n\n");
            abort();
        }

        fmprb_cosh(a, a, prec);

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

        fmprb_clear(a);
        fmprb_clear(b);
        fmpq_clear(q);
        mpfr_clear(t);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
예제 #7
0
파일: t-addmul.c 프로젝트: bluescarni/arb
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 100000; iter++)
    {
        fmprb_t a, b, c;
        fmpq_t x, y, z;

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

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        fmprb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        fmprb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));
        fmprb_get_rand_fmpq(z, state, c, 1 + n_randint(state, 200));

        fmprb_addmul(c, a, b, 2 + n_randint(state, 200));
        fmpq_addmul(z, x, y);

        if (!fmprb_contains_fmpq(c, z))
        {
            printf("FAIL: containment\n\n");
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("x = "); fmpq_print(x); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("y = "); fmpq_print(y); printf("\n\n");
            printf("c = "); fmprb_print(c); printf("\n\n");
            printf("z = "); fmpq_print(z); printf("\n\n");
            abort();
        }

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

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of c and a */
    for (iter = 0; iter < 10000; iter++)
    {
        fmprb_t a, b;
        fmpq_t x, y, z;

        fmprb_init(a);
        fmprb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        fmprb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        fmprb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));
        fmpq_set(z, x);

        fmprb_addmul(a, a, b, 2 + n_randint(state, 200));
        fmpq_addmul(z, x, y);

        if (!fmprb_contains_fmpq(a, z))
        {
            printf("FAIL: aliasing (c, a)\n\n");
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("x = "); fmpq_print(x); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("y = "); fmpq_print(y); printf("\n\n");
            printf("z = "); fmpq_print(z); printf("\n\n");
            abort();
        }

        fmprb_clear(a);
        fmprb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    /* aliasing of c and b */
    for (iter = 0; iter < 10000; iter++)
    {
        fmprb_t a, b;
        fmpq_t x, y, z;

        fmprb_init(a);
        fmprb_init(b);

        fmpq_init(x);
        fmpq_init(y);
        fmpq_init(z);

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

        fmprb_get_rand_fmpq(x, state, a, 1 + n_randint(state, 200));
        fmprb_get_rand_fmpq(y, state, b, 1 + n_randint(state, 200));
        fmpq_set(z, y);

        fmprb_addmul(b, a, b, 2 + n_randint(state, 200));
        fmpq_addmul(z, x, y);

        if (!fmprb_contains_fmpq(b, z))
        {
            printf("FAIL: aliasing (c, b)\n\n");
            printf("a = "); fmprb_print(a); printf("\n\n");
            printf("x = "); fmpq_print(x); printf("\n\n");
            printf("b = "); fmprb_print(b); printf("\n\n");
            printf("y = "); fmpq_print(y); printf("\n\n");
            printf("z = "); fmpq_print(z); printf("\n\n");
            abort();
        }

        fmprb_clear(a);
        fmprb_clear(b);

        fmpq_clear(x);
        fmpq_clear(y);
        fmpq_clear(z);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}