int f_horror(acb_ptr res, const acb_t z, void * param, slong order, slong prec) { acb_t s, t; if (order > 1) flint_abort(); /* Would be needed for Taylor method. */ acb_init(s); acb_init(t); acb_real_floor(res, z, order != 0, prec); if (acb_is_finite(res)) { acb_sub(res, z, res, prec); acb_set_d(t, 0.5); acb_sub(res, res, t, prec); acb_sin_cos(s, t, z, prec); acb_real_max(s, s, t, order != 0, prec); acb_mul(res, res, s, prec); } acb_clear(s); acb_clear(t); return 0; }
void _acb_poly_sin_series(acb_ptr g, acb_srcptr h, slong hlen, slong n, slong prec) { hlen = FLINT_MIN(hlen, n); if (hlen == 1) { acb_sin(g, h, prec); _acb_vec_zero(g + 1, n - 1); } else if (n == 2) { acb_t t; acb_init(t); acb_sin_cos(g, t, h, prec); acb_mul(g + 1, h + 1, t, prec); /* safe since hlen >= 2 */ acb_clear(t); } else { acb_ptr t = _acb_vec_init(n); _acb_poly_sin_cos_series(g, t, h, hlen, n, prec); _acb_vec_clear(t, n); } }
void acb_cot(acb_t r, const acb_t z, slong prec) { if (arb_is_zero(acb_imagref(z))) { arb_cot(acb_realref(r), acb_realref(z), prec); arb_zero(acb_imagref(r)); } else if (arb_is_zero(acb_realref(z))) { arb_coth(acb_imagref(r), acb_imagref(z), prec); arb_neg(acb_imagref(r), acb_imagref(r)); arb_zero(acb_realref(r)); } else { acb_t t; acb_init(t); if (arf_cmpabs_2exp_si(arb_midref(acb_imagref(z)), 0) < 0) { acb_sin_cos(r, t, z, prec + 4); acb_div(r, t, r, prec); } else { acb_mul_2exp_si(t, z, 1); if (arf_sgn(arb_midref(acb_imagref(z))) > 0) { acb_mul_onei(t, t); acb_exp(t, t, prec + 4); acb_sub_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); } else { acb_div_onei(t, t); acb_exp(t, t, prec + 4); acb_sub_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); } } acb_clear(t); } }
/* f(z) = max(sin(z), cos(z)) */ int f_max_sin_cos(acb_ptr res, const acb_t z, void * param, slong order, slong prec) { acb_t s, c; if (order > 1) flint_abort(); /* Would be needed for Taylor method. */ acb_init(s); acb_init(c); acb_sin_cos(s, c, z, prec); acb_real_max(res, s, c, order != 0, prec); acb_clear(s); acb_clear(c); return 0; }
/* f(z) = z sin(z) / (1 + cos(z)^2) */ int f_sin_cos_frac(acb_ptr res, const acb_t z, void * param, slong order, slong prec) { acb_t s, c; if (order > 1) flint_abort(); /* Would be needed for Taylor method. */ acb_init(s); acb_init(c); acb_sin_cos(s, c, z, prec); acb_mul(c, c, c, prec); acb_add_ui(c, c, 1, prec); acb_mul(s, s, z, prec); acb_div(res, s, c, prec); acb_clear(s); acb_clear(c); return 0; }
void _acb_poly_sin_cos_series_tangent(acb_ptr s, acb_ptr c, const acb_srcptr h, slong hlen, slong len, slong prec, int times_pi) { acb_ptr t, u, v; acb_t s0, c0; hlen = FLINT_MIN(hlen, len); if (hlen == 1) { if (times_pi) acb_sin_cos_pi(s, c, h, prec); else acb_sin_cos(s, c, h, prec); _acb_vec_zero(s + 1, len - 1); _acb_vec_zero(c + 1, len - 1); return; } /* sin(x) = 2*tan(x/2)/(1+tan(x/2)^2) cos(x) = (1-tan(x/2)^2)/(1+tan(x/2)^2) */ acb_init(s0); acb_init(c0); t = _acb_vec_init(3 * len); u = t + len; v = u + len; /* sin, cos of h0 */ if (times_pi) acb_sin_cos_pi(s0, c0, h, prec); else acb_sin_cos(s0, c0, h, prec); /* t = tan((h-h0)/2) */ acb_zero(u); _acb_vec_scalar_mul_2exp_si(u + 1, h + 1, hlen - 1, -1); if (times_pi) { acb_const_pi(t, prec); _acb_vec_scalar_mul(u + 1, u + 1, hlen - 1, t, prec); } _acb_poly_tan_series(t, u, hlen, len, prec); /* v = 1 + t^2 */ _acb_poly_mullow(v, t, len, t, len, len, prec); acb_add_ui(v, v, 1, prec); /* u = 1/(1+t^2) */ _acb_poly_inv_series(u, v, len, len, prec); /* sine */ _acb_poly_mullow(s, t, len, u, len, len, prec); _acb_vec_scalar_mul_2exp_si(s, s, len, 1); /* cosine */ acb_sub_ui(v, v, 2, prec); _acb_vec_neg(v, v, len); _acb_poly_mullow(c, v, len, u, len, len, prec); /* sin(h0 + h1) = cos(h0) sin(h1) + sin(h0) cos(h1) cos(h0 + h1) = cos(h0) cos(h1) - sin(h0) sin(h1) */ if (!acb_is_zero(s0)) { _acb_vec_scalar_mul(t, s, len, c0, prec); _acb_vec_scalar_mul(u, c, len, s0, prec); _acb_vec_scalar_mul(v, s, len, s0, prec); _acb_vec_add(s, t, u, len, prec); _acb_vec_scalar_mul(t, c, len, c0, prec); _acb_vec_sub(c, t, v, len, prec); } _acb_vec_clear(t, 3 * len); acb_clear(s0); acb_clear(c0); }