Exemplo n.º 1
0
void
acb_modular_elliptic_e(acb_t res, const acb_t m, long prec)
{
    if (acb_is_zero(m))
    {
        acb_const_pi(res, prec);
        acb_mul_2exp_si(res, res, -1);
    }
    else if (acb_is_one(m))
    {
        acb_one(res);
    }
    else
    {
        acb_struct t[2];

        acb_init(t + 0);
        acb_init(t + 1);

        acb_modular_elliptic_k_cpx(t, m, 2, prec);
        acb_mul(t + 1, t + 1, m, prec);
        acb_mul_2exp_si(t + 1, t + 1, 1);
        acb_add(t, t, t + 1, prec);
        acb_sub_ui(t + 1, m, 1, prec);
        acb_mul(res, t, t + 1, prec);
        acb_neg(res, res);

        acb_clear(t + 0);
        acb_clear(t + 1);
    }
}
Exemplo n.º 2
0
/* REAL: erf(x) = 2x/sqrt(pi) * exp(-x^2) 1F1(1, 3/2, x^2) */
void
acb_hypgeom_erf_1f1b(acb_t res, const acb_t z, slong prec)
{
    acb_t a, b, t, w;

    acb_init(a);
    acb_init(b);
    acb_init(t);
    acb_init(w);

    acb_set_ui(b, 3);
    acb_mul_2exp_si(b, b, -1);

    acb_mul(w, z, z, prec);

    acb_hypgeom_pfq_direct(t, a, 0, b, 1, w, -1, prec);

    acb_neg(w, w);
    acb_exp(w, w, prec);
    acb_mul(t, t, w, prec);

    acb_mul(t, t, z, prec);
    arb_const_sqrt_pi(acb_realref(w), prec);
    acb_div_arb(t, t, acb_realref(w), prec);

    acb_mul_2exp_si(res, t, 1);

    acb_clear(a);
    acb_clear(b);
    acb_clear(t);
    acb_clear(w);
}
Exemplo n.º 3
0
void
acb_lambertw_initial_asymp(acb_t w, const acb_t z, const fmpz_t k, slong prec)
{
    acb_t L1, L2, t;

    acb_init(L1);
    acb_init(L2);
    acb_init(t);

    acb_const_pi(L2, prec);
    acb_mul_2exp_si(L2, L2, 1);
    acb_mul_fmpz(L2, L2, k, prec);
    acb_mul_onei(L2, L2);
    acb_log(L1, z, prec);
    acb_add(L1, L1, L2, prec);
    acb_log(L2, L1, prec);

    /* L1 - L2 + L2/L1 + L2(L2-2)/(2 L1^2) */
    acb_inv(t, L1, prec);
    acb_mul_2exp_si(w, L2, 1);
    acb_submul(w, L2, L2, prec);
    acb_neg(w, w);
    acb_mul(w, w, t, prec);
    acb_mul_2exp_si(w, w, -1);
    acb_add(w, w, L2, prec);
    acb_mul(w, w, t, prec);
    acb_sub(w, w, L2, prec);
    acb_add(w, w, L1, prec);

    acb_clear(L1);
    acb_clear(L2);
    acb_clear(t);
}
Exemplo n.º 4
0
void
acb_hypgeom_bessel_j_asymp_prefactors(acb_t Ap, acb_t Am, acb_t C,
    const acb_t nu, const acb_t z, long prec)
{
    if (arb_is_positive(acb_realref(z)))
    {
        acb_t t, u;

        acb_init(t);
        acb_init(u);

        /* -(2nu+1)/4 * pi + z */
        acb_mul_2exp_si(t, nu, 1);
        acb_add_ui(t, t, 1, prec);
        acb_mul_2exp_si(t, t, -2);
        acb_neg(t, t);
        acb_const_pi(u, prec);
        acb_mul(t, t, u, prec);
        acb_add(t, t, z, prec);
        acb_mul_onei(t, t);
        acb_exp_invexp(Ap, Am, t, prec);

        /* (2 pi z)^(-1/2) */
        acb_const_pi(C, prec);
        acb_mul_2exp_si(C, C, 1);
        acb_mul(C, C, z, prec);
        acb_rsqrt(C, C, prec);

        acb_clear(t);
        acb_clear(u);
        return;
    }

    acb_hypgeom_bessel_j_asymp_prefactors_fallback(Ap, Am, C, nu, z, prec);
}
Exemplo n.º 5
0
void
acb_hypgeom_fresnel(acb_t res1, acb_t res2, const acb_t z, int normalized, slong prec)
{
    slong wp;
    acb_t w;
    arb_t c;

    if (!acb_is_finite(z))
    {
        if (res1 != NULL) acb_indeterminate(res1);
        if (res2 != NULL) acb_indeterminate(res2);
        return;
    }

    acb_init(w);
    arb_init(c);

    wp = prec + 8;

    if (normalized)
    {
        arb_const_pi(c, wp);
        arb_sqrt(c, c, wp);
        arb_mul_2exp_si(c, c, -1);
        acb_mul_arb(w, z, c, wp);
        acb_hypgeom_fresnel_erf_error(res1, res2, w, wp);
    }
    else
    {
        arb_sqrt_ui(c, 2, wp);
        arb_mul_2exp_si(c, c, -1);
        acb_mul_arb(w, z, c, wp);
        acb_hypgeom_fresnel_erf_error(res1, res2, w, wp);
        arb_const_pi(c, wp);
        arb_mul_2exp_si(c, c, -1);
        arb_sqrt(c, c, wp);

        if (res1 != NULL) acb_mul_arb(res1, res1, c, wp);
        if (res2 != NULL) acb_mul_arb(res2, res2, c, wp);
    }

    if (res1 != NULL)
    {
        acb_mul_2exp_si(res1, res1, -2);
        acb_set_round(res1, res1, prec);
    }

    if (res2 != NULL)
    {
        acb_mul_2exp_si(res2, res2, -2);
        acb_set_round(res2, res2, prec);
    }

    acb_clear(w);
    arb_clear(c);
}
Exemplo n.º 6
0
Arquivo: tan_pi.c Projeto: isuruf/arb
void
acb_tan_pi(acb_t r, const acb_t z, slong prec)
{
    if (arb_is_zero(acb_imagref(z)))
    {
        arb_tan_pi(acb_realref(r), acb_realref(z), prec);
        arb_zero(acb_imagref(r));
    }
    else if (arb_is_zero(acb_realref(z)))
    {
        arb_t t;
        arb_init(t);
        arb_const_pi(t, prec + 4);
        arb_mul(t, acb_imagref(z), t, prec + 4);
        arb_tanh(acb_imagref(r), t, prec);
        arb_zero(acb_realref(r));
        arb_clear(t);
    }
    else
    {
        acb_t t;
        acb_init(t);

        if (arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), 0) < 0)
        {
            acb_sin_cos_pi(r, t, z, prec + 4);
            acb_div(r, r, t, prec);
        }
        else
        {
            acb_mul_2exp_si(t, z, 1);

            if (arf_sgn(arb_midref(acb_imagref(z))) > 0)
            {
                acb_exp_pi_i(t, t, prec + 4);
                acb_add_ui(r, t, 1, prec + 4);
                acb_div(r, t, r, prec + 4);
                acb_mul_2exp_si(r, r, 1);
                acb_sub_ui(r, r, 1, prec);
                acb_div_onei(r, r);
            }
            else
            {
                acb_neg(t, t);
                acb_exp_pi_i(t, t, prec + 4);
                acb_add_ui(r, t, 1, prec + 4);
                acb_div(r, t, r, prec + 4);
                acb_mul_2exp_si(r, r, 1);
                acb_sub_ui(r, r, 1, prec);
                acb_mul_onei(r, r);
            }
        }

        acb_clear(t);
    }
}
Exemplo n.º 7
0
void
acb_hypgeom_bessel_j_0f1(acb_t res, const acb_t nu, const acb_t z, long prec)
{
    acb_struct b[2];
    acb_t w, c, t;

    if (acb_is_int(nu) && arb_is_negative(acb_realref(nu)))
    {
        acb_init(t);
        acb_neg(t, nu);

        acb_hypgeom_bessel_j_0f1(res, t, z, prec);

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

        acb_clear(t);
        return;
    }

    acb_init(b + 0);
    acb_init(b + 1);
    acb_init(w);
    acb_init(c);
    acb_init(t);

    acb_add_ui(b + 0, nu, 1, prec);
    acb_one(b + 1);

    /* (z/2)^nu / gamma(nu+1) */
    acb_mul_2exp_si(c, z, -1);
    acb_pow(c, c, nu, prec);
    acb_rgamma(t, b + 0, prec);
    acb_mul(c, t, c, prec);

    /* -z^2/4 */
    acb_mul(w, z, z, prec);
    acb_mul_2exp_si(w, w, -2);
    acb_neg(w, w);

    acb_hypgeom_pfq_direct(t, NULL, 0, b, 2, w, -1, prec);

    acb_mul(res, t, c, prec);

    acb_clear(b + 0);
    acb_clear(b + 1);
    acb_clear(w);
    acb_clear(c);
    acb_clear(t);
}
Exemplo n.º 8
0
void
acb_dirichlet_theta_arb(acb_t res, const dirichlet_group_t G, const dirichlet_char_t chi, const arb_t t, slong prec)
{
    slong len;
    ulong order;
    arb_t xt;
    mag_t e;

    len = acb_dirichlet_theta_length(G->q, t, prec);

    arb_init(xt);
    _acb_dirichlet_theta_argument_at_arb(xt, G->q, t, prec);

    mag_init(e);
    mag_tail_kexpk2_arb(e, xt, len);

    arb_neg(xt, xt);
    arb_exp(xt, xt, prec);

    /* TODO: tune this limit */
    order = dirichlet_order_char(G, chi);
    if (order < 30)
        _acb_dirichlet_theta_arb_smallorder(res, G, chi, xt, len, prec);
    else
        _acb_dirichlet_theta_arb_naive(res, G, chi, xt, len, prec);

    arb_add_error_mag(acb_realref(res), e);
    arb_add_error_mag(acb_imagref(res), e);

    mag_clear(e);

    acb_mul_2exp_si(res, res, 1);
    arb_clear(xt);
}
Exemplo n.º 9
0
/* Extremely close to the branch point at -1/e, use the series expansion directly. */
int
acb_lambertw_try_near_branch_point(acb_t res, const acb_t z,
    const acb_t ez1, const fmpz_t k, int flags, slong prec)
{
    if (fmpz_is_zero(k) || (fmpz_is_one(k) && arb_is_negative(acb_imagref(z)))
                        || (fmpz_equal_si(k, -1) && arb_is_nonnegative(acb_imagref(z))))
    {
        if (acb_contains_zero(ez1) ||
            (arf_cmpabs_2exp_si(arb_midref(acb_realref(ez1)), -prec / 4.5 - 6) < 0 &&
             arf_cmpabs_2exp_si(arb_midref(acb_imagref(ez1)), -prec / 4.5 - 6) < 0))
        {
            acb_t t;
            acb_init(t);
            acb_mul_2exp_si(t, ez1, 1);
            acb_sqrt(t, t, prec);
            if (!fmpz_is_zero(k))
                acb_neg(t, t);
            acb_lambertw_branchpoint_series(res, t, 1, prec);
            acb_clear(t);
            return 1;
        }
    }

    return 0;
}
Exemplo n.º 10
0
/* todo: remove radii */
void
acb_lambertw_halley_step(acb_t res, acb_t ew, const acb_t z, const acb_t w, slong prec)
{
    acb_t t, u, v;

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

    acb_exp(ew, w, prec);
    acb_add_ui(u, w, 2, prec);
    acb_add_ui(v, w, 1, prec);
    acb_mul_2exp_si(v, v, 1);
    acb_div(v, u, v, prec);
    acb_mul(t, ew, w, prec);
    acb_sub(u, t, z, prec);
    acb_mul(v, v, u, prec);
    acb_neg(v, v);
    acb_add(v, v, t, prec);
    acb_add(v, v, ew, prec);
    acb_div(t, u, v, prec);

    acb_sub(t, w, t, prec);

    acb_swap(res, t);

    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
}
Exemplo n.º 11
0
Arquivo: log1p.c Projeto: isuruf/arb
static void
acb_log1p_tiny(acb_t r, const acb_t z, slong prec)
{
    mag_t b, c;
    acb_t t;
    int real;

    mag_init(b);
    mag_init(c);
    acb_init(t);

    real = acb_is_real(z);

    /* if |z| < 1, then |log(1+z) - [z - z^2/2]| <= |z|^3/(1-|z|) */
    acb_get_mag(b, z);
    mag_one(c);
    mag_sub_lower(c, c, b);
    mag_pow_ui(b, b, 3);
    mag_div(b, b, c);

    acb_mul(t, z, z, prec);
    acb_mul_2exp_si(t, t, -1);
    acb_sub(r, z, t, prec);

    if (real && mag_is_finite(b))
        arb_add_error_mag(acb_realref(r), b);
    else
        acb_add_error_mag(r, b);

    mag_clear(b);
    mag_clear(c);
    acb_clear(t);
}
Exemplo n.º 12
0
/* (+/- iz)^(-1/2-v) * z^v * exp(+/- iz) */
void
acb_hypgeom_bessel_j_asymp_prefactors_fallback(acb_t Ap, acb_t Am, acb_t C,
    const acb_t nu, const acb_t z, long prec)
{
    acb_t t, u, v;

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

    /* v = -1/2-nu */
    acb_one(v);
    acb_mul_2exp_si(v, v, -1);
    acb_add(v, v, nu, prec);
    acb_neg(v, v);

    acb_mul_onei(t, z);  /* t = iz */
    acb_neg(u, t);       /* u = -iz */

    /* Ap, Am = (+/- iz)^(-1/2-nu) */
    acb_pow(Ap, t, v, prec);
    acb_pow(Am, u, v, prec);

    /* Ap, Am *= exp(+/- iz) */
    acb_exp_invexp(u, v, t, prec);
    acb_mul(Ap, Ap, u, prec);
    acb_mul(Am, Am, v, prec);

    /* z^nu */
    acb_pow(t, z, nu, prec);
    acb_mul(Ap, Ap, t, prec);
    acb_mul(Am, Am, t, prec);

    /* (2 pi)^(-1/2) */
    acb_const_pi(C, prec);
    acb_mul_2exp_si(C, C, 1);
    acb_rsqrt(C, C, prec);

    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
}
Exemplo n.º 13
0
void
acb_hypgeom_bessel_jy(acb_t res1, acb_t res2, const acb_t nu, const acb_t z, slong prec)
{
    acb_t jnu, t, u, v;

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

    acb_hypgeom_bessel_j(jnu, nu, z, prec);

    if (acb_is_int(nu))
    {
        int is_real = acb_is_real(nu) && acb_is_real(z)
            && arb_is_positive(acb_realref(z));

        acb_mul_onei(t, z);
        acb_hypgeom_bessel_k(t, nu, t, prec);
        acb_onei(u);
        acb_pow(u, u, nu, prec);
        acb_mul(t, t, u, prec);
        acb_const_pi(u, prec);
        acb_div(t, t, u, prec);
        acb_mul_2exp_si(t, t, 1);
        acb_neg(t, t);

        phase(v, acb_realref(z), acb_imagref(z));
        acb_mul(u, jnu, v, prec);
        acb_mul_onei(u, u);

        acb_sub(res2, t, u, prec);

        if (is_real)
            arb_zero(acb_imagref(res2));
    }
    else
    {
        acb_sin_cos_pi(t, u, nu, prec);
        acb_mul(v, jnu, u, prec);
        acb_neg(u, nu);
        acb_hypgeom_bessel_j(u, u, z, prec);
        acb_sub(v, v, u, prec);
        acb_div(res2, v, t, prec);
    }

    if (res1 != NULL)
        acb_set(res1, jnu);

    acb_clear(jnu);
    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
}
Exemplo n.º 14
0
Arquivo: ci.c Projeto: isuruf/arb
void
acb_hypgeom_ci_2f3(acb_t res, const acb_t z, slong prec)
{
    acb_t a, t, u;
    acb_struct b[3];

    acb_init(a);
    acb_init(b);
    acb_init(b + 1);
    acb_init(b + 2);
    acb_init(t);
    acb_init(u);

    acb_one(a);
    acb_set_ui(b, 2);
    acb_set(b + 1, b);
    acb_set_ui(b + 2, 3);
    acb_mul_2exp_si(b + 2, b + 2, -1);

    acb_mul(t, z, z, prec);
    acb_mul_2exp_si(t, t, -2);
    acb_neg(t, t);
    acb_hypgeom_pfq_direct(u, a, 1, b, 3, t, -1, prec);
    acb_mul(u, u, t, prec);

    acb_log(t, z, prec);
    acb_add(u, u, t, prec);

    arb_const_euler(acb_realref(t), prec);
    arb_add(acb_realref(u), acb_realref(u), acb_realref(t), prec);

    acb_swap(res, u);

    acb_clear(a);
    acb_clear(b);
    acb_clear(b + 1);
    acb_clear(b + 2);
    acb_clear(t);
    acb_clear(u);
}
Exemplo n.º 15
0
Arquivo: delta.c Projeto: thofma/arb
void
acb_modular_delta(acb_t z, const acb_t tau, long prec)
{
    psl2z_t g;
    arf_t one_minus_eps;
    acb_t tau_prime, t1, t2, t3, t4, q;

    psl2z_init(g);
    arf_init(one_minus_eps);
    acb_init(tau_prime);
    acb_init(t1);
    acb_init(t2);
    acb_init(t3);
    acb_init(t4);
    acb_init(q);

    arf_set_ui_2exp_si(one_minus_eps, 63, -6);
    acb_modular_fundamental_domain_approx(tau_prime, g, tau,
        one_minus_eps, prec);

    acb_exp_pi_i(q, tau_prime, prec);
    acb_modular_theta_const_sum(t2, t3, t4, q, prec);

    /* (t2 t3 t4) ^ 8 * q^2 */
    acb_mul(t1, t2, t3, prec);
    acb_mul(t1, t1, t4, prec);
    acb_mul(t1, t1, t1, prec);
    acb_mul(t1, t1, t1, prec);
    acb_mul(t1, t1, q, prec);
    acb_mul(t1, t1, t1, prec);
    acb_mul_2exp_si(t1, t1, -8);

    if (!fmpz_is_zero(&g->c))
    {
        acb_mul_fmpz(t2, tau, &g->c, prec);
        acb_add_fmpz(t2, t2, &g->d, prec);
        acb_pow_ui(t2, t2, 12, prec);
        acb_div(t1, t1, t2, prec);
    }

    acb_set(z, t1);

    psl2z_clear(g);
    arf_clear(one_minus_eps);
    acb_clear(tau_prime);
    acb_clear(t1);
    acb_clear(t2);
    acb_clear(t3);
    acb_clear(t4);
    acb_clear(q);
}
Exemplo n.º 16
0
/* u[0..l1[ contains roots re(ui)<=0
   u[l1..d-2[ roots with re(ui) > 0
   the last two components are set to
   (b-a)/2 and (a+b)/(b-a)
   returns l1
*/
slong
ab_points(acb_ptr u, acb_srcptr x, edge_t e, slong d, slong prec)
{
    slong k, l;
    acb_t ab, ba; /* a + b and b - a */

    acb_init(ab);
    acb_init(ba);

    acb_set(ba, x + e.b);
    acb_sub(ba, ba, x + e.a, prec);
    acb_set(ab, x + e.a);
    acb_add(ab, ba, x + e.b, prec);

    for (k = 0, l = 0; k < d; k++)
    {
        if (k == e.a || k == e.b)
            continue;
        acb_mul_2exp_si(u + l, x + k, 1);
        acb_sub(u + l, u + l, ab, prec);
        acb_div(u + l, u + l, ba, prec);
        l++;
    }

    /* now l = d - 2, set last two */

    acb_mul_2exp_si(u + l, ba, -1);
    acb_div(u + l + 1, ab, ba, prec);

    /* reorder */
    for (k = 0; k < l; k++)
        if (arb_is_positive(acb_realref(u + k)))
            acb_swap(u + k--, u + l--);
    acb_clear(ab);
    acb_clear(ba);

    return l;
}
Exemplo n.º 17
0
void
acb_modular_elliptic_k(acb_t k, const acb_t m, slong prec)
{
    acb_t t;
    acb_init(t);
    acb_sub_ui(t, m, 1, prec);
    acb_neg(t, t);
    acb_sqrt(t, t, prec);
    acb_agm1(k, t, prec);
    acb_const_pi(t, prec);
    acb_div(k, t, k, prec);
    acb_mul_2exp_si(k, k, -1);
    acb_clear(t);
}
Exemplo n.º 18
0
Arquivo: erf.c Projeto: isuruf/arb
void
acb_hypgeom_erf_asymp(acb_t res, const acb_t z, slong prec, slong prec2)
{
    acb_t a, t, u;

    acb_init(a);
    acb_init(t);
    acb_init(u);

    acb_one(a);
    acb_mul_2exp_si(a, a, -1);
    acb_mul(t, z, z, prec2);

    acb_hypgeom_u_asymp(u, a, a, t, -1, prec2);

    acb_neg(t, t);
    acb_exp(t, t, prec2);
    acb_mul(u, u, t, prec2);

    acb_const_pi(t, prec2);
    acb_sqrt(t, t, prec2);
    acb_mul(t, t, z, prec2);

    acb_div(u, u, t, prec2);

    /* branch cut term: -1 or 1 */
    if (arb_contains_zero(acb_realref(z)))
    {
        arb_zero(acb_imagref(t));
        arf_zero(arb_midref(acb_realref(t)));
        mag_one(arb_radref(acb_realref(t)));
    }
    else
    {
        acb_set_si(t, arf_sgn(arb_midref(acb_realref(z))));
    }

    acb_sub(t, t, u, prec);

    if (arb_is_zero(acb_imagref(z)))
        arb_zero(acb_imagref(t));
    else if (arb_is_zero(acb_realref(z)))
        arb_zero(acb_realref(t));

    acb_set(res, t);

    acb_clear(a);
    acb_clear(t);
    acb_clear(u);
}
Exemplo n.º 19
0
void
acb_hypgeom_bessel_k_asymp(acb_t res, const acb_t nu, const acb_t z, slong prec)
{
    acb_t t, a, b, w;

    acb_init(t);
    acb_init(a);
    acb_init(b);
    acb_init(w);

    acb_one(a);
    acb_mul_2exp_si(a, a, -1);
    acb_add(a, a, nu, prec);

    acb_mul_2exp_si(b, nu, 1);
    acb_add_ui(b, b, 1, prec);

    acb_mul_2exp_si(w, z, 1);

    acb_hypgeom_u_asymp(t, a, b, w, -1, prec);

    acb_neg(w, z);
    acb_exp(w, w, prec);    
    acb_mul(t, t, w, prec);

    acb_mul_2exp_si(w, z, 1);
    acb_rsqrt(w, w, prec);
    acb_mul(res, t, w, prec);

    arb_const_sqrt_pi(acb_realref(w), prec);
    acb_mul_arb(res, res, acb_realref(w), prec);

    acb_clear(t);
    acb_clear(a);
    acb_clear(b);
    acb_clear(w);
}
Exemplo n.º 20
0
/* assumes no aliasing */
slong
acb_lambertw_initial(acb_t res, const acb_t z, const acb_t ez1, const fmpz_t k, slong prec)
{
    /* Handle z very close to 0 on the principal branch. */
    if (fmpz_is_zero(k) && 
            (arf_cmpabs_2exp_si(arb_midref(acb_realref(z)), -20) <= 0 &&
             arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), -20) <= 0))
    {
        acb_set(res, z);
        acb_submul(res, res, res, prec);
        return 40;  /* could be tightened... */
    }

    /* For moderate input not close to the branch point, compute a double
       approximation as the initial value. */
    if (fmpz_is_zero(k) &&
        arf_cmpabs_2exp_si(arb_midref(acb_realref(z)), 400) < 0 &&
        arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), 400) < 0 &&
          (arf_cmp_d(arb_midref(acb_realref(z)), -0.37) < 0 ||
           arf_cmp_d(arb_midref(acb_realref(z)), -0.36) > 0 ||
           arf_cmpabs_d(arb_midref(acb_imagref(z)), 0.01) > 0))
    {
        acb_lambertw_principal_d(res, z);
        return 48;
    }

    /* Check if we are close to the branch point at -1/e. */
    if ((fmpz_is_zero(k) || (fmpz_is_one(k) && arb_is_negative(acb_imagref(z)))
                         || (fmpz_equal_si(k, -1) && arb_is_nonnegative(acb_imagref(z))))
        && ((arf_cmpabs_2exp_si(arb_midref(acb_realref(ez1)), -2) <= 0 &&
             arf_cmpabs_2exp_si(arb_midref(acb_imagref(ez1)), -2) <= 0)))
    {
        acb_t t;
        acb_init(t);
        acb_mul_2exp_si(t, ez1, 1);
        mag_zero(arb_radref(acb_realref(t)));
        mag_zero(arb_radref(acb_imagref(t)));
        acb_mul_ui(t, t, 3, prec);
        acb_sqrt(t, t, prec);
        if (!fmpz_is_zero(k))
            acb_neg(t, t);
        acb_lambertw_branchpoint_series(res, t, 0, prec);
        acb_clear(t);
        return 1;  /* todo: estimate */
    }

    acb_lambertw_initial_asymp(res, z, k, prec);
    return 1;  /* todo: estimate */
}
Exemplo n.º 21
0
Arquivo: erf.c Projeto: isuruf/arb
/* IMAG: erf(z) = 2z/sqrt(pi) * 1F1(1/2, 3/2, -z^2) */
void
acb_hypgeom_erf_1f1a(acb_t res, const acb_t z, slong prec)
{
    acb_t a, t, w;
    acb_struct b[2];

    acb_init(a);
    acb_init(b);
    acb_init(b + 1);
    acb_init(t);
    acb_init(w);

    acb_one(a);
    acb_mul_2exp_si(a, a, -1);
    acb_set_ui(b, 3);
    acb_mul_2exp_si(b, b, -1);
    acb_one(b + 1);

    acb_mul(w, z, z, prec);
    acb_neg(w, w);

    acb_hypgeom_pfq_direct(t, a, 1, b, 2, w, -1, prec);

    acb_const_pi(w, prec);
    acb_rsqrt(w, w, prec);
    acb_mul(t, t, w, prec);
    acb_mul(t, t, z, prec);

    acb_mul_2exp_si(res, t, 1);

    acb_clear(a);
    acb_clear(b);
    acb_clear(b + 1);
    acb_clear(t);
    acb_clear(w);
}
Exemplo n.º 22
0
void
acb_hypgeom_bessel_i_asymp_prefactors(acb_t A, acb_t B, acb_t C,
    const acb_t nu, const acb_t z, long prec)
{
    acb_t t, u;

    acb_init(t);
    acb_init(u);

    /* C = (2 pi z)^(-1/2) */
    acb_const_pi(C, prec);
    acb_mul_2exp_si(C, C, 1);
    acb_mul(C, C, z, prec);
    acb_rsqrt(C, C, prec);

    if (arb_is_positive(acb_imagref(z)) ||
        (arb_is_zero(acb_imagref(z)) && arb_is_negative(acb_realref(z))))
    {
        acb_exp_pi_i(t, nu, prec);
        acb_mul_onei(t, t);
    }
    else if (arb_is_negative(acb_imagref(z)) ||
        (arb_is_zero(acb_imagref(z)) && arb_is_positive(acb_realref(z))))
    {
        acb_neg(t, nu);
        acb_exp_pi_i(t, t, prec);
        acb_mul_onei(t, t);
        acb_neg(t, t);
    }
    else
    {
        acb_exp_pi_i(t, nu, prec);
        acb_mul_onei(t, t);
        acb_neg(u, nu);
        acb_exp_pi_i(u, u, prec);
        acb_mul_onei(u, u);
        acb_neg(u, u);

        arb_union(acb_realref(t), acb_realref(t), acb_realref(u), prec);
        arb_union(acb_imagref(t), acb_imagref(t), acb_imagref(u), prec);
    }

    acb_exp_invexp(B, A, z, prec);
    acb_mul(A, A, t, prec);

    acb_clear(t);
    acb_clear(u);
}
Exemplo n.º 23
0
void
_acb_poly_mullow_classical(acb_ptr res,
    acb_srcptr poly1, slong len1,
    acb_srcptr poly2, slong len2, slong n, slong prec)
{
    len1 = FLINT_MIN(len1, n);
    len2 = FLINT_MIN(len2, n);

    if (n == 1)
    {
        acb_mul(res, poly1, poly2, prec);
    }
    else if (poly1 == poly2 && len1 == len2)
    {
        slong i;

        _acb_vec_scalar_mul(res, poly1, FLINT_MIN(len1, n), poly1, prec);
        _acb_vec_scalar_mul(res + len1, poly1 + 1, n - len1, poly1 + len1 - 1, prec);

        for (i = 1; i < len1 - 1; i++)
            _acb_vec_scalar_addmul(res + i + 1, poly1 + 1,
                FLINT_MIN(i - 1, n - (i + 1)), poly1 + i, prec);

        for (i = 1; i < FLINT_MIN(2 * len1 - 2, n); i++)
            acb_mul_2exp_si(res + i, res + i, 1);

        for (i = 1; i < FLINT_MIN(len1 - 1, (n + 1) / 2); i++)
            acb_addmul(res + 2 * i, poly1 + i, poly1 + i, prec);
    }
    else
    {
        slong i;

        _acb_vec_scalar_mul(res, poly1, FLINT_MIN(len1, n), poly2, prec);

        if (n > len1)
            _acb_vec_scalar_mul(res + len1, poly2 + 1, n - len1,
                                      poly1 + len1 - 1, prec);

        for (i = 0; i < FLINT_MIN(len1, n) - 1; i++)
            _acb_vec_scalar_addmul(res + i + 1, poly2 + 1,
                                         FLINT_MIN(len2, n - i) - 1,
                                         poly1 + i, prec);
    }
}
Exemplo n.º 24
0
void
acb_randtest_maybe_half_int(acb_t x, flint_rand_t state, long prec, long size)
{
    if (n_randint(state, 8) == 0)
    {
        fmpz_t t;
        fmpz_init(t);
        fmpz_randtest(t, state, 1 + n_randint(state, prec));
        arb_set_fmpz(acb_realref(x), t);
        arb_zero(acb_imagref(x));
        acb_mul_2exp_si(x, x, -1);
        fmpz_clear(t);
    }
    else
    {
        acb_randtest(x, state, prec, size);
    }
}
Exemplo n.º 25
0
Arquivo: acos.c Projeto: isuruf/arb
void
acb_acos(acb_t res, const acb_t z, slong prec)
{
    if (acb_is_one(z))
    {
        acb_zero(res);
    }
    else
    {
        acb_t t;
        acb_init(t);
        acb_asin(res, z, prec);
        acb_const_pi(t, prec);
        acb_mul_2exp_si(t, t, -1);
        acb_sub(res, t, res, prec);
        acb_clear(t);
    }
}
Exemplo n.º 26
0
void
acb_hypgeom_jacobi_p(acb_t res, const acb_t n, const acb_t a, const acb_t b,
    const acb_t z, slong prec)
{
    acb_t t, u, v, w;

    if (use_recurrence(n, a, b, prec))
    {
        acb_hypgeom_jacobi_p_ui_direct(res,
            arf_get_si(arb_midref(acb_realref(n)), ARF_RND_DOWN), a, b, z, prec);
        return;
    }

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

    acb_neg(t, n);
    acb_add_ui(v, a, 1, prec);
    acb_add(u, n, v, prec);
    acb_add(u, u, b, prec);
    acb_sub_ui(w, z, 1, prec);
    acb_mul_2exp_si(w, w, -1);
    acb_neg(w, w);

    acb_hypgeom_2f1(w, t, u, v, w, 0, prec);

    acb_rising(t, v, n, prec);
    acb_mul(w, w, t, prec);

    acb_add_ui(t, n, 1, prec);
    acb_rgamma(t, t, prec);
    acb_mul(w, w, t, prec);

    acb_set(res, w);

    acb_clear(t);
    acb_clear(u);
    acb_clear(v);
    acb_clear(w);
}
Exemplo n.º 27
0
void
integrals_edge_factors_gc(acb_ptr res, const acb_t cab, const acb_t ba2, sec_t c, slong prec)
{
    slong i;
    acb_t cj, ci;

    acb_init(cj);
    acb_init(ci);

    /* polynomial shift */
    acb_vec_polynomial_shift(res, cab, c.g, prec);

    /* constants cj, j = 1 */
    /* c_1 = (1-zeta^-1) ba2^(-d/2) (-I)^i
     *     = 2 / ba2^(d/2) */

    acb_pow_ui(cj, ba2, c.d / 2, prec);
    if (c.d % 2)
    {
        acb_t t;
        acb_init(t);
        acb_sqrt(t, ba2, prec);
        acb_mul(cj, cj, t, prec);
        acb_clear(t);
    }
    acb_inv(cj, cj, prec);
    acb_mul_2exp_si(cj, cj, 1);

    _acb_vec_scalar_mul(res, res, c.g, cj, prec);

    /* constant ci = -I * ba2*/
    acb_one(ci);
    for (i = 1; i < c.g; i++)
    {
        acb_mul(ci, ci, ba2, prec);
        acb_div_onei(ci, ci);
        acb_mul(res + i, res + i, ci, prec);
    }

    acb_clear(ci);
    acb_clear(cj);
}
Exemplo n.º 28
0
void
_acb_poly_sqrt_series(acb_ptr g,
    acb_srcptr h, slong hlen, slong len, slong prec)
{
    hlen = FLINT_MIN(hlen, len);

    while (hlen > 0 && acb_is_zero(h + hlen - 1))
        hlen--;

    if (hlen <= 1)
    {
        acb_sqrt(g, h, prec);
        _acb_vec_zero(g + 1, len - 1);
    }
    else if (len == 2)
    {
        acb_sqrt(g, h, prec);
        acb_div(g + 1, h + 1, h, prec);
        acb_mul(g + 1, g + 1, g, prec);
        acb_mul_2exp_si(g + 1, g + 1, -1);
    }
    else if (_acb_vec_is_zero(h + 1, hlen - 2))
    {
        acb_t t;
        acb_init(t);
        arf_set_si_2exp_si(arb_midref(acb_realref(t)), 1, -1);
        _acb_poly_binomial_pow_acb_series(g, h, hlen, t, len, prec);
        acb_clear(t);
    }
    else
    {
        acb_ptr t;
        t = _acb_vec_init(len);
        _acb_poly_rsqrt_series(t, h, hlen, len, prec);
        _acb_poly_mullow(g, t, len, h, hlen, len, prec);
        _acb_vec_clear(t, len);
    }
}
Exemplo n.º 29
0
/* todo: use euler product for complex s, and check efficiency
   for large negative integers */
void
acb_dirichlet_zeta(acb_t res, const acb_t s, slong prec)
{
    acb_t a;
    double cutoff;

    if (acb_is_int(s) &&
        arf_cmpabs_2exp_si(arb_midref(acb_realref(s)), FLINT_BITS - 1) < 0)
    {
        acb_zeta_si(res, arf_get_si(arb_midref(acb_realref(s)), ARF_RND_DOWN), prec);
        return;
    }

    cutoff = 24.0 * prec * sqrt(prec);

    if (arf_cmpabs_d(arb_midref(acb_imagref(s)), cutoff) >= 0 &&
        arf_cmpabs_d(arb_midref(acb_realref(s)), 10 + prec * 0.1) <= 0)
    {
        acb_dirichlet_zeta_rs(res, s, 0, prec);
        return;
    }

    acb_init(a);
    acb_one(a);

    if (arf_sgn(arb_midref(acb_realref(s))) < 0)
    {
        acb_t t, u, v;
        slong wp = prec + 6;

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

        acb_sub_ui(t, s, 1, wp);

        /* 2 * (2pi)^(s-1) */
        arb_const_pi(acb_realref(u), wp);
        acb_mul_2exp_si(u, u, 1);
        acb_pow(u, u, t, wp);
        acb_mul_2exp_si(u, u, 1);

        /* sin(pi*s/2) */
        acb_mul_2exp_si(v, s, -1);
        acb_sin_pi(v, v, wp);
        acb_mul(u, u, v, wp);

        /* gamma(1-s) zeta(1-s) */
        acb_neg(t, t);
        acb_gamma(v, t, wp);
        acb_mul(u, u, v, wp);
        acb_hurwitz_zeta(v, t, a, wp);
        acb_mul(res, u, v, prec);

        acb_clear(t);
        acb_clear(u);
        acb_clear(v);
    }
    else
    {
        acb_hurwitz_zeta(res, s, a, prec);
    }

    acb_clear(a);
}
Exemplo n.º 30
0
int main()
{
    long iter;
    flint_rand_t state;

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

    flint_randinit(state);

    for (iter = 0; iter < 2000; iter++)
    {
        acb_t a0, a1, a2, b, z, w0, w1, w2, t, u;
        long prec0, prec1, prec2;

        acb_init(a0);
        acb_init(a1);
        acb_init(a2);
        acb_init(b);
        acb_init(z);
        acb_init(w0);
        acb_init(w1);
        acb_init(w2);
        acb_init(t);
        acb_init(u);

        prec0 = 2 + n_randint(state, 700);
        prec1 = 2 + n_randint(state, 700);
        prec2 = 2 + n_randint(state, 700);

        acb_randtest_maybe_half_int(a0, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest_maybe_half_int(b, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest(z, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest(w0, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest(w1, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));
        acb_randtest(w2, state, 1 + n_randint(state, 1000), 1 + n_randint(state, 100));

        acb_add_ui(a1, a0, 1, prec0);
        acb_add_ui(a2, a0, 2, prec0);

        switch (n_randint(state, 3))
        {
            case 0:
                acb_hypgeom_u_asymp_proper(w0, a0, b, z, prec0);
                break;
            case 1:
                acb_hypgeom_u_1f1(w0, a0, b, z, prec0);
                break;
            default:
                acb_hypgeom_u(w0, a0, b, z, prec0);
        }

        switch (n_randint(state, 3))
        {
            case 0:
                acb_hypgeom_u_asymp_proper(w1, a0, b, z, prec1);
                break;
            case 1:
                acb_hypgeom_u_1f1(w1, a0, b, z, prec1);
                break;
            default:
                acb_hypgeom_u(w1, a0, b, z, prec1);
        }

        if (!acb_overlaps(w0, w1))
        {
            printf("FAIL: consistency\n\n");
            printf("a = "); acb_printd(a0, 30); printf("\n\n");
            printf("b = "); acb_printd(b, 30); printf("\n\n");
            printf("z = "); acb_printd(z, 30); printf("\n\n");
            printf("w0 = "); acb_printd(w0, 30); printf("\n\n");
            printf("w1 = "); acb_printd(w1, 30); printf("\n\n");
            abort();
        }

        switch (n_randint(state, 3))
        {
            case 0:
                acb_hypgeom_u_asymp_proper(w1, a1, b, z, prec1);
                break;
            case 1:
                acb_hypgeom_u_1f1(w1, a1, b, z, prec1);
                break;
            default:
                acb_hypgeom_u(w1, a1, b, z, prec1);
        }

        switch (n_randint(state, 3))
        {
            case 0:
                acb_hypgeom_u_asymp_proper(w2, a2, b, z, prec2);
                break;
            case 1:
                acb_hypgeom_u_1f1(w2, a2, b, z, prec2);
                break;
            default:
                acb_hypgeom_u(w2, a2, b, z, prec2);
        }

        acb_set(t, w0);

        acb_mul_2exp_si(u, a0, 1);
        acb_sub(u, u, b, prec0);
        acb_add(u, u, z, prec0);
        acb_add_ui(u, u, 2, prec0);

        acb_submul(t, w1, u, prec0);

        acb_sub(u, a2, b, prec0);
        acb_mul(u, u, a1, prec0);
        acb_addmul(t, w2, u, prec0);

        if (!acb_contains_zero(t))
        {
            printf("FAIL: contiguous relation\n\n");
            printf("a = "); acb_printd(a0, 30); printf("\n\n");
            printf("b = "); acb_printd(b, 30); printf("\n\n");
            printf("z = ");  acb_printd(z, 30); printf("\n\n");
            printf("w0 = "); acb_printd(w0, 30); printf("\n\n");
            printf("w1 = "); acb_printd(w1, 30); printf("\n\n");
            printf("w2 = "); acb_printd(w2, 30); printf("\n\n");
            printf("t = "); acb_printd(t, 30); printf("\n\n");
            abort();
        }

        acb_clear(a0);
        acb_clear(a1);
        acb_clear(a2);
        acb_clear(b);
        acb_clear(z);
        acb_clear(w0);
        acb_clear(w1);
        acb_clear(w2);
        acb_clear(t);
        acb_clear(u);
    }

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