Exemplo n.º 1
0
void
arb_hypgeom_legendre_q(arb_t res, const arb_t n, const arb_t m, const arb_t z, int type, slong prec)
{
    acb_t t, u, v;
    acb_init(t);
    acb_init(u);
    acb_init(v);
    arb_set(acb_realref(t), n);
    arb_set(acb_realref(u), m);
    arb_set(acb_realref(v), z);
    acb_hypgeom_legendre_q(t, t, u, v, type, prec);
    if (acb_is_finite(t) && acb_is_real(t))
        arb_swap(res, acb_realref(t));
    else
        arb_indeterminate(res);
    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    int function, i, numtests;
    slong prec, goal;
    double t, total, logtotal;

    acb_t a, b, c, z, r, s;

    acb_init(a);
    acb_init(b);
    acb_init(c);
    acb_init(z);
    acb_init(r);
    acb_init(s);

    /*    J(0,pi x)   I(0,pi x)   K(0,pi x)          */

    for (function = 0; function < 3; function++)
    {
        total = 0.0;
        logtotal = 0.0;

        if (function < 2)
            numtests = 40;
        else
            numtests = 30;

        for (i = 0; i < numtests; i++)
        {
//            printf("%2d ", i + 1); fflush(stdout);

            TIMEIT_START
            prec = 96;

            for (;;)
            {
                if (function == 0)
                {
                    acb_set_d_d(a, input_1f1[i][0], input_1f1[i][1]);
                    acb_set_d_d(b, input_1f1[i][2], input_1f1[i][3]);
                    acb_set_d_d(z, input_1f1[i][4], input_1f1[i][5]);
                    acb_hypgeom_m(r, a, b, z, 0, prec);
                }
                else if (function == 1)
                {
                    acb_set_d_d(a, input_1f1[i][0], input_1f1[i][1]);
                    acb_set_d_d(b, input_1f1[i][2], input_1f1[i][3]);
                    acb_set_d_d(z, input_1f1[i][4], input_1f1[i][5]);
                    acb_hypgeom_u(r, a, b, z, prec);
                }
                else if (function == 2)
                {
                    acb_set_d_d(a, input_2f1[i][0], input_2f1[i][1]);
                    acb_set_d_d(b, input_2f1[i][2], input_2f1[i][3]);
                    acb_set_d_d(c, input_2f1[i][4], input_2f1[i][5]);
                    acb_set_d_d(z, input_2f1[i][6], input_2f1[i][7]);
                    acb_hypgeom_2f1(r, a, b, c, z, 0, prec);
                }
                else
                {
                    acb_set_d_d(a, input_2f1[i][0], input_2f1[i][1]);
                    acb_set_d_d(b, input_2f1[i][2], input_2f1[i][3]);
                    acb_set_d_d(c, input_2f1[i][4], input_2f1[i][5]);
                    acb_set_d_d(z, input_2f1[i][6], input_2f1[i][7]);
                    acb_mul_2exp_si(z, z, 1);
                    acb_sub_ui(z, z, 1, prec);
                    acb_neg(z, z);
                    acb_hypgeom_legendre_q(r, a, c, z, 0, prec);
                }

                if (function == 3)
                {
                    if (acb_rel_accuracy_bits(r) >= goal)
                        break;
                }
                else
                {
                    if (arb_can_round_arf(acb_realref(r), goal, ARF_RND_NEAR) &&
                        arb_can_round_arf(acb_imagref(r), goal, ARF_RND_NEAR))
                        break;
                }

                prec *= 2;
            }

            TIMEIT_STOP_VAL(t)

            total += t;
            logtotal += log(t);

#if 1
            printf("%8g, ", t);
#else
            printf("%8ld    %8g    ", prec, t);
            _acb_print(r, 25);
            printf("\n");
#endif
        }

        printf("---------------------------------------------------------------\n");
        printf("Mean %g s; geometric mean %g\n", total, exp(logtotal / numtests));
        printf("---------------------------------------------------------------\n");
    }

    acb_clear(a);
    acb_clear(b);
    acb_clear(c);
    acb_clear(z);
    acb_clear(r);
    acb_clear(s);
}
Exemplo n.º 3
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000; iter++)
    {
        acb_t n, m, z, res1, res2;
        long prec1, prec2, ebits;

        acb_init(n);
        acb_init(m);
        acb_init(z);
        acb_init(res1);
        acb_init(res2);

        prec1 = 2 + n_randint(state, 300);
        prec2 = 2 + n_randint(state, 300);
        ebits = 1 + n_randint(state, 10);

        if (n_randint(state, 2))
        {
            acb_set_si(m, n_randint(state, 20) - 10);
            acb_set_si(n, n_randint(state, 20) - 10);
        }
        else
        {
            acb_randtest_param(n, state, 1 + n_randint(state, 400), ebits);
            acb_randtest_param(m, state, 1 + n_randint(state, 400), ebits);
        }

        acb_randtest_param(z, state, 1 + n_randint(state, 400), ebits);

        _acb_hypgeom_legendre_q_single(res1, n, m, z, prec1);
        _acb_hypgeom_legendre_q_double(res2, n, m, z, prec2);

        if (!acb_overlaps(res1, res2))
        {
            printf("FAIL: consistency 1\n\n");
            printf("iter = %ld, prec1 = %ld, prec2 = %ld\n\n", iter, prec1, prec2);
            printf("m = "); acb_printd(m, 30); printf("\n\n");
            printf("n = "); acb_printd(n, 30); printf("\n\n");
            printf("z = "); acb_printd(z, 30); printf("\n\n");
            printf("res1 = "); acb_printd(res1, 30); printf("\n\n");
            printf("res2 = "); acb_printd(res2, 30); printf("\n\n");
            abort();
        }

        acb_clear(n);
        acb_clear(m);
        acb_clear(z);
        acb_clear(res1);
        acb_clear(res2);
    }

    for (iter = 0; iter < 2000; iter++)
    {
        acb_t n, m, z, res1, res2, t, u;
        long prec1, prec2, ebits;
        int type;

        acb_init(n);
        acb_init(m);
        acb_init(z);
        acb_init(res1);
        acb_init(res2);
        acb_init(t);
        acb_init(u);

        prec1 = 2 + n_randint(state, 300);
        prec2 = 2 + n_randint(state, 300);
        ebits = 1 + n_randint(state, 10);

        if (n_randint(state, 2))
        {
            acb_set_si(m, n_randint(state, 20) - 10);
            acb_set_si(n, n_randint(state, 20) - 10);
        }
        else
        {
            acb_randtest_param(n, state, 1 + n_randint(state, 400), ebits);
            acb_randtest_param(m, state, 1 + n_randint(state, 400), ebits);
        }

        acb_randtest_param(z, state, 1 + n_randint(state, 400), ebits);

        type = n_randint(state, 2);

        acb_hypgeom_legendre_q(res1, n, m, z, type, prec1);

        acb_neg(t, m);
        acb_hypgeom_legendre_p(res2, n, t, z, type, prec2);
        acb_add(u, m, n, prec2);
        acb_add_ui(u, u, 1, prec2);
        acb_gamma(u, u, prec2);
        acb_mul(res2, res2, u, prec2);
        acb_sub(u, n, m, prec2);
        acb_add_ui(u, u, 1, prec2);
        acb_rgamma(u, u, prec2);
        acb_mul(res2, res2, u, prec2);

        acb_hypgeom_legendre_p(t, n, m, z, type, prec2);

        if (type == 0)
        {
            acb_cos_pi(u, m, prec2);
            acb_mul(t, t, u, prec2);
        }
        acb_sub(res2, t, res2, prec2);

        if (type == 1)
        {
            acb_exp_pi_i(t, m, prec2);
            acb_mul(res2, res2, t, prec2);
        }

        acb_sin_pi(t, m, prec2);

        if (acb_contains_zero(t))
            acb_indeterminate(res2);
        else
            acb_div(res2, res2, t, prec2);

        acb_const_pi(t, prec2);
        acb_mul(res2, res2, t, prec2);
        acb_mul_2exp_si(res2, res2, -1);

        if (!acb_overlaps(res1, res2))
        {
            printf("FAIL: consistency 2\n\n");
            printf("iter = %ld, prec1 = %ld, prec2 = %ld\n\n", iter, prec1, prec2);
            printf("type = %d\n\n", type);
            printf("m = "); acb_printd(m, 30); printf("\n\n");
            printf("n = "); acb_printd(n, 30); printf("\n\n");
            printf("z = "); acb_printd(z, 30); printf("\n\n");
            printf("res1 = "); acb_printd(res1, 30); printf("\n\n");
            printf("res2 = "); acb_printd(res2, 30); printf("\n\n");
            abort();
        }

        acb_clear(n);
        acb_clear(m);
        acb_clear(z);
        acb_clear(res1);
        acb_clear(res2);
        acb_clear(t);
        acb_clear(u);
    }

    flint_randclear(state);
    flint_cleanup();
    printf("PASS\n");
    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
void
_acb_hypgeom_legendre_q_double(acb_t res, const acb_t n, const acb_t m,
    const acb_t z, slong prec)
{
    acb_t t, u, v;

    acb_init(t);
    acb_init(u);
    acb_init(v);

    if (acb_is_int(m))
    {
        acb_sub_ui(t, z, 1, prec);
        acb_mul_2exp_si(u, m, -1);
        acb_pow(v, t, u, prec);
        acb_neg(t, t);
        acb_neg(u, u);
        acb_pow(t, t, u, prec);
        acb_mul(t, t, v, prec);

        acb_hypgeom_legendre_q(u, n, m, z, 0, prec);
        acb_mul(t, t, u, prec);

        acb_mul_2exp_si(u, m, -1);
        if (!acb_is_int(u))
            acb_neg(t, t);

        acb_sub_ui(u, z, 1, prec);
        acb_sqrt(u, u, prec);
        acb_sub_ui(v, z, 1, prec);
        acb_neg(v, v);
        acb_rsqrt(v, v, prec);
        acb_mul(u, u, v, prec);
        acb_hypgeom_legendre_p(v, n, m, z, 1, prec);
        acb_mul(u, u, v, prec);
        acb_const_pi(v, prec);
        acb_mul(u, u, v, prec);
        acb_mul_2exp_si(u, u, -1);

        acb_sub(res, t, u, prec);
    }
    else
    {
        acb_sub(t, n, m, prec);
        acb_add_ui(t, t, 1, prec);
        acb_mul_2exp_si(u, m, 1);
        acb_rising(t, t, u, prec);
        acb_neg(u, m);
        acb_hypgeom_legendre_p(u, n, u, z, 1, prec);
        acb_mul(t, t, u, prec);

        acb_hypgeom_legendre_p(u, n, m, z, 1, prec);
        acb_sub(t, u, t, prec);

        acb_exp_pi_i(u, m, prec);
        acb_mul(t, t, u, prec);

        acb_sin_pi(u, m, prec);
        acb_div(t, t, u, prec);
        acb_const_pi(u, prec);
        acb_mul(t, t, u, prec);
        acb_mul_2exp_si(t, t, -1);

        acb_set(res, t);
    }

    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
}