Ejemplo n.º 1
0
void
acb_poly_compose_series(acb_poly_t res,
                    const acb_poly_t poly1,
                    const acb_poly_t poly2, slong n, slong prec)
{
    slong len1 = poly1->length;
    slong len2 = poly2->length;
    slong lenr;

    if (len2 != 0 && !acb_is_zero(poly2->coeffs))
    {
        flint_printf("exception: compose_series: inner "
                "polynomial must have zero constant term\n");
        abort();
    }

    if (len1 == 0 || n == 0)
    {
        acb_poly_zero(res);
        return;
    }

    if (len2 == 0 || len1 == 1)
    {
        acb_poly_set_acb(res, poly1->coeffs);
        return;
    }

    lenr = FLINT_MIN((len1 - 1) * (len2 - 1) + 1, n);
    len1 = FLINT_MIN(len1, lenr);
    len2 = FLINT_MIN(len2, lenr);

    if ((res != poly1) && (res != poly2))
    {
        acb_poly_fit_length(res, lenr);
        _acb_poly_compose_series(res->coeffs, poly1->coeffs, len1,
                                        poly2->coeffs, len2, lenr, prec);
        _acb_poly_set_length(res, lenr);
        _acb_poly_normalise(res);
    }
    else
    {
        acb_poly_t t;
        acb_poly_init2(t, lenr);
        _acb_poly_compose_series(t->coeffs, poly1->coeffs, len1,
                                        poly2->coeffs, len2, lenr, prec);
        _acb_poly_set_length(t, lenr);
        _acb_poly_normalise(t);
        acb_poly_swap(res, t);
        acb_poly_clear(t);
    }
}
Ejemplo n.º 2
0
void acb_poly_compose(acb_poly_t res,
              const acb_poly_t poly1, const acb_poly_t poly2, slong prec)
{
    const slong len1 = poly1->length;
    const slong len2 = poly2->length;
    
    if (len1 == 0)
    {
        acb_poly_zero(res);
    }
    else if (len1 == 1 || len2 == 0)
    {
        acb_poly_set_acb(res, poly1->coeffs);
    }
    else
    {
        const slong lenr = (len1 - 1) * (len2 - 1) + 1;
        
        if (res != poly1 && res != poly2)
        {
            acb_poly_fit_length(res, lenr);
            _acb_poly_compose(res->coeffs, poly1->coeffs, len1,
                                                   poly2->coeffs, len2, prec);
        }
        else
        {
            acb_poly_t t;
            acb_poly_init2(t, lenr);
            _acb_poly_compose(t->coeffs, poly1->coeffs, len1,
                                                 poly2->coeffs, len2, prec);
            acb_poly_swap(res, t);
            acb_poly_clear(t);
        }

        _acb_poly_set_length(res, lenr);
        _acb_poly_normalise(res);
    }
}
Ejemplo n.º 3
0
void
acb_hypgeom_bessel_k_0f1(acb_t res, const acb_t nu, const acb_t z, slong prec)
{
    if (acb_is_int(nu))
    {
        acb_poly_t nux, zx, rx;

        acb_poly_init(nux);
        acb_poly_init(zx);
        acb_poly_init(rx);

        acb_poly_set_coeff_acb(nux, 0, nu);
        acb_poly_set_coeff_si(nux, 1, 1);
        acb_poly_set_acb(zx, z);

        acb_hypgeom_bessel_k_0f1_series(rx, nux, zx, 1, prec);

        acb_poly_get_coeff_acb(res, rx, 0);

        acb_poly_clear(nux);
        acb_poly_clear(zx);
        acb_poly_clear(rx);
    }
    else
    {
        acb_t t, u, v, w;
        acb_struct b[2];

        acb_init(t);
        acb_init(u);
        acb_init(v);
        acb_init(w);
        acb_init(b + 0);
        acb_init(b + 1);

        /* u = 0F1(1+nu), v = 0F1(1-nu) */
        acb_mul(t, z, z, prec);
        acb_mul_2exp_si(t, t, -2);
        acb_add_ui(b, nu, 1, prec);
        acb_one(b + 1);
        acb_hypgeom_pfq_direct(u, NULL, 0, b, 2, t, -1, prec);
        acb_sub_ui(b, nu, 1, prec);
        acb_neg(b, b);
        acb_hypgeom_pfq_direct(v, NULL, 0, b, 2, t, -1, prec);

        /* v = v * gamma(nu) / (z/2)^nu */
        acb_mul_2exp_si(t, z, -1);
        acb_pow(t, t, nu, prec);
        acb_gamma(w, nu, prec);
        acb_mul(v, v, w, prec);
        acb_div(v, v, t, prec);

        /* u = u * t * pi / (gamma(nu) * nu * sin(pi nu)) */
        acb_mul(u, u, t, prec);
        acb_const_pi(t, prec);
        acb_mul(u, u, t, prec);
        acb_sin_pi(t, nu, prec);
        acb_mul(t, t, w, prec);
        acb_mul(t, t, nu, prec);
        acb_div(u, u, t, prec);

        acb_sub(res, v, u, prec);
        acb_mul_2exp_si(res, res, -1);

        acb_clear(t);
        acb_clear(u);
        acb_clear(v);
        acb_clear(w);
        acb_clear(b + 0);
        acb_clear(b + 1);
    }
}
Ejemplo n.º 4
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        slong m, n1, n2, bits1, bits2, bits3;
        acb_poly_t S, A, B, C;
        acb_t pi;

        bits1 = 2 + n_randint(state, 200);
        bits2 = 2 + n_randint(state, 200);
        bits3 = 2 + n_randint(state, 200);

        m = 1 + n_randint(state, 30);
        n1 = 1 + n_randint(state, 30);
        n2 = 1 + n_randint(state, 30);

        acb_poly_init(S);
        acb_poly_init(A);
        acb_poly_init(B);
        acb_poly_init(C);
        acb_init(pi);

        acb_poly_randtest(S, state, m, bits1, 3);
        acb_poly_randtest(A, state, m, bits1, 3);
        acb_poly_randtest(B, state, m, bits1, 3);

        acb_poly_cos_pi_series(A, S, n1, bits2);

        acb_const_pi(pi, bits3);
        acb_poly_set_acb(B, pi);
        acb_poly_mul(B, S, B, bits3);
        acb_poly_cos_series(B, B, n2, bits3);

        acb_poly_set(C, A);
        acb_poly_truncate(C, FLINT_MIN(n1, n2));
        acb_poly_truncate(B, FLINT_MIN(n1, n2));

        if (!acb_poly_overlaps(B, C))
        {
            flint_printf("FAIL\n\n");
            flint_printf("S = "); acb_poly_printd(S, 15); flint_printf("\n\n");
            flint_printf("A = "); acb_poly_printd(A, 15); flint_printf("\n\n");
            flint_printf("B = "); acb_poly_printd(B, 15); flint_printf("\n\n");
            abort();
        }

        acb_poly_cos_pi_series(S, S, n1, bits2);

        if (!acb_poly_overlaps(A, S))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        acb_poly_clear(S);
        acb_poly_clear(A);
        acb_poly_clear(B);
        acb_poly_clear(C);
        acb_clear(pi);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
    {
        acb_poly_t ai, aip, bi, bip, ai2, aip2, bi2, bip2, z, w, t;
        acb_t c;
        slong n1, n2, prec1, prec2;
        unsigned int mask;

        acb_poly_init(ai); acb_poly_init(aip);
        acb_poly_init(bi); acb_poly_init(bip);
        acb_poly_init(ai2); acb_poly_init(aip2);
        acb_poly_init(bi2); acb_poly_init(bip2);
        acb_poly_init(z); acb_poly_init(w);
        acb_poly_init(t); acb_init(c);

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

        n1 = n_randint(state, 6);
        n2 = n_randint(state, 6);

        acb_poly_randtest(ai, state, 10, prec1, 10);
        acb_poly_randtest(aip, state, 10, prec1, 10);
        acb_poly_randtest(bi, state, 10, prec1, 10);
        acb_poly_randtest(bip, state, 10, prec1, 10);
        acb_poly_randtest(z, state, 1 + n_randint(state, 10), prec1, 10);

        acb_hypgeom_airy_series(ai, aip, bi, bip, z, n1, prec1);

        acb_poly_mullow(w, ai, bip, n1, prec1);
        acb_poly_mullow(t, bi, aip, n1, prec1);
        acb_poly_sub(w, w, t, prec1);

        acb_const_pi(c, prec1);
        acb_inv(c, c, prec1);
        acb_poly_set_acb(t, c);
        acb_poly_truncate(t, n1);

        if (!acb_poly_overlaps(w, t))
        {
            flint_printf("FAIL: wronskian\n\n");
            flint_printf("z = "); acb_poly_printd(z, 30); flint_printf("\n\n");
            flint_printf("ai = "); acb_poly_printd(ai, 30); flint_printf("\n\n");
            flint_printf("aip = "); acb_poly_printd(aip, 30); flint_printf("\n\n");
            flint_printf("bi = "); acb_poly_printd(bi, 30); flint_printf("\n\n");
            flint_printf("bip = "); acb_poly_printd(bip, 30); flint_printf("\n\n");
            flint_printf("w = "); acb_poly_printd(w, 30); flint_printf("\n\n");
            abort();
        }

        mask = n_randlimb(state);

        acb_hypgeom_airy_series((mask & 1) ? ai2 : NULL,
                                (mask & 2) ? aip2 : NULL,
                                (mask & 4) ? bi2 : NULL,
                                (mask & 8) ? bip2 : NULL, z, n2, prec2);

        acb_poly_truncate(ai, FLINT_MIN(n1, n2));
        acb_poly_truncate(aip, FLINT_MIN(n1, n2));
        acb_poly_truncate(bi, FLINT_MIN(n1, n2));
        acb_poly_truncate(bip, FLINT_MIN(n1, n2));
        acb_poly_truncate(ai2, FLINT_MIN(n1, n2));
        acb_poly_truncate(aip2, FLINT_MIN(n1, n2));
        acb_poly_truncate(bi2, FLINT_MIN(n1, n2));
        acb_poly_truncate(bip2, FLINT_MIN(n1, n2));

        if (((mask & 1) && (!acb_poly_overlaps(ai, ai2))) ||
            ((mask & 2) && (!acb_poly_overlaps(aip, aip2))) ||
            ((mask & 4) && (!acb_poly_overlaps(bi, bi2))) ||
            ((mask & 8) && (!acb_poly_overlaps(bip, bip2))))
        {
            flint_printf("FAIL: consistency (mask)\n\n");
            flint_printf("mask = %u\n\n", mask);
            flint_printf("len1 = %wd, len2 = %wd\n\n", n1, n2);
            flint_printf("z = "); acb_poly_printd(z, 30); flint_printf("\n\n");
            flint_printf("ai = "); acb_poly_printd(ai, 30); flint_printf("\n\n");
            flint_printf("ai2 = "); acb_poly_printd(ai2, 30); flint_printf("\n\n");
            flint_printf("aip = "); acb_poly_printd(aip, 30); flint_printf("\n\n");
            flint_printf("aip2 = "); acb_poly_printd(aip2, 30); flint_printf("\n\n");
            flint_printf("bi = "); acb_poly_printd(bi, 30); flint_printf("\n\n");
            flint_printf("bi2 = "); acb_poly_printd(bi2, 30); flint_printf("\n\n");
            flint_printf("bip = "); acb_poly_printd(bip, 30); flint_printf("\n\n");
            flint_printf("bip2 = "); acb_poly_printd(bip2, 30); flint_printf("\n\n");
            abort();
        }

        acb_poly_clear(ai); acb_poly_clear(aip);
        acb_poly_clear(bi); acb_poly_clear(bip);
        acb_poly_clear(ai2); acb_poly_clear(aip2);
        acb_poly_clear(bi2); acb_poly_clear(bip2);
        acb_poly_clear(z); acb_poly_clear(w);
        acb_poly_clear(t); acb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
int main()
{
    slong iter;
    flint_rand_t state;

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

    flint_randinit(state);

    /* compare with exp/log */
    for (iter = 0; iter < 10000 * arb_test_multiplier(); iter++)
    {
        slong prec, trunc;
        acb_poly_t f, g, h1, h2;
        acb_t c;

        prec = 2 + n_randint(state, 200);
        trunc = n_randint(state, 20);

        acb_poly_init(f);
        acb_poly_init(g);
        acb_poly_init(h1);
        acb_poly_init(h2);
        acb_init(c);

        /* generate binomials */
        if (n_randint(state, 20) == 0)
        {
            acb_randtest(c, state, prec, 10);
            acb_poly_set_coeff_acb(f, 0, c);
            acb_randtest(c, state, prec, 10);
            acb_poly_set_coeff_acb(f, 1 + n_randint(state, 20), c);
        }
        else
        {
            acb_poly_randtest(f, state, 1 + n_randint(state, 20), prec, 10);
        }

        acb_poly_randtest(h1, state, 1 + n_randint(state, 20), prec, 10);

        acb_randtest(c, state, prec, 10);
        acb_poly_set_acb(g, c);

        /* f^c */
        acb_poly_pow_acb_series(h1, f, c, trunc, prec);

        /* f^c = exp(c*log(f)) */
        acb_poly_log_series(h2, f, trunc, prec);
        acb_poly_mullow(h2, h2, g, trunc, prec);
        acb_poly_exp_series(h2, h2, trunc, prec);

        if (!acb_poly_overlaps(h1, h2))
        {
            flint_printf("FAIL\n\n");

            flint_printf("prec = %wd\n", prec);
            flint_printf("trunc = %wd\n", trunc);

            flint_printf("f = "); acb_poly_printd(f, 15); flint_printf("\n\n");
            flint_printf("c = "); acb_printd(c, 15); flint_printf("\n\n");
            flint_printf("h1 = "); acb_poly_printd(h1, 15); flint_printf("\n\n");
            flint_printf("h2 = "); acb_poly_printd(h2, 15); flint_printf("\n\n");

            abort();
        }

        acb_poly_pow_acb_series(f, f, c, trunc, prec);

        if (!acb_poly_overlaps(f, h1))
        {
            flint_printf("FAIL (aliasing)\n\n");
            abort();
        }

        acb_poly_clear(f);
        acb_poly_clear(g);
        acb_poly_clear(h1);
        acb_poly_clear(h2);
        acb_clear(c);
    }

    flint_randclear(state);
    flint_cleanup();
    flint_printf("PASS\n");
    return EXIT_SUCCESS;
}
Ejemplo n.º 7
0
void
acb_hypgeom_2f1_transform_limit(acb_t res, const acb_t a, const acb_t b,
    const acb_t c, const acb_t z, int regularized, int which, slong prec)
{
    acb_poly_t aa, bb, cc, zz;
    acb_t t;

    if (acb_contains_zero(z) || !acb_is_finite(z))
    {
        acb_indeterminate(res);
        return;
    }

    if (arb_contains_si(acb_realref(z), 1) && arb_contains_zero(acb_imagref(z)))
    {
        acb_indeterminate(res);
        return;
    }

    if (!regularized)
    {
        acb_init(t);
        acb_gamma(t, c, prec);
        acb_hypgeom_2f1_transform_limit(res, a, b, c, z, 1, which, prec);
        acb_mul(res, res, t, prec);
        acb_clear(t);
        return;
    }

    acb_poly_init(aa);
    acb_poly_init(bb);
    acb_poly_init(cc);
    acb_poly_init(zz);
    acb_init(t);

    acb_poly_set_acb(aa, a);
    acb_poly_set_acb(bb, b);
    acb_poly_set_acb(cc, c);
    acb_poly_set_acb(zz, z);

    if (which == 2 || which == 3)
    {
        acb_sub(t, b, a, prec);
        acb_poly_set_coeff_si(aa, 1, 1);

        /* prefer b-a nonnegative (either is correct) to avoid
           expensive operations in the hypergeometric series */
        if (arb_is_nonnegative(acb_realref(t)))
            _acb_hypgeom_2f1_transform_limit(res, aa, bb, cc, zz, which, prec);
        else
            _acb_hypgeom_2f1_transform_limit(res, bb, aa, cc, zz, which, prec);
    }
    else
    {
        acb_poly_set_coeff_si(aa, 1, 1);
        _acb_hypgeom_2f1_transform_limit(res, aa, bb, cc, zz, which, prec);
    }

    acb_poly_clear(aa);
    acb_poly_clear(bb);
    acb_poly_clear(cc);
    acb_poly_clear(zz);
    acb_clear(t);
}
Ejemplo n.º 8
0
void
acb_hypgeom_u_1f1(acb_t res, const acb_t a, const acb_t b, const acb_t z, long prec)
{
    if (acb_is_int(b))
    {
        acb_poly_t aa, bb, zz;

        acb_poly_init(aa);
        acb_poly_init(bb);
        acb_poly_init(zz);

        acb_poly_set_acb(aa, a);
        acb_poly_set_coeff_acb(bb, 0, b);
        acb_poly_set_coeff_si(bb, 1, 1);
        acb_poly_set_acb(zz, z);

        acb_hypgeom_u_1f1_series(zz, aa, bb, zz, 1, prec);
        acb_poly_get_coeff_acb(res, zz, 0);

        acb_poly_clear(aa);
        acb_poly_clear(bb);
        acb_poly_clear(zz);
    }
    else
    {
        acb_t t, u, v;
        acb_struct aa[3];

        acb_init(t);
        acb_init(u);
        acb_init(v);
        acb_init(aa + 0);
        acb_init(aa + 1);
        acb_init(aa + 2);

        acb_set(aa, a);
        acb_set(aa + 1, b);
        acb_one(aa + 2);
        acb_hypgeom_pfq_direct(u, aa, 1, aa + 1, 2, z, -1, prec);
        acb_sub(aa, a, b, prec);
        acb_add_ui(aa, aa, 1, prec);
        acb_sub_ui(aa + 1, b, 2, prec);
        acb_neg(aa + 1, aa + 1);
        acb_hypgeom_pfq_direct(v, aa, 1, aa + 1, 2, z, -1, prec);

        acb_sub_ui(aa + 1, b, 1, prec);

        /* rgamma(a-b+1) * gamma(1-b) * u */
        acb_rgamma(t, aa, prec);
        acb_mul(u, u, t, prec);
        acb_neg(t, aa + 1);
        acb_gamma(t, t, prec);
        acb_mul(u, u, t, prec);

        /* rgamma(a) * gamma(b-1) * z^(1-b) * v */
        acb_rgamma(t, a, prec);
        acb_mul(v, v, t, prec);
        acb_gamma(t, aa + 1, prec);
        acb_mul(v, v, t, prec);
        acb_neg(t, aa + 1);
        acb_pow(t, z, t, prec);
        acb_mul(v, v, t, prec);

        acb_add(res, u, v, prec);

        acb_clear(t);
        acb_clear(u);
        acb_clear(v);
        acb_clear(aa + 0);
        acb_clear(aa + 1);
        acb_clear(aa + 2);
    }
}