void _nmod_poly_exp_series(mp_ptr f, mp_srcptr h, long n, nmod_t mod) { mp_ptr g, T, U, hprime; if (n < NMOD_NEWTON_EXP_CUTOFF2) { _nmod_poly_exp_series_basecase(f, h, n, n, mod); return; } g = _nmod_vec_init((n + 1) / 2); T = _nmod_vec_init(n); U = _nmod_vec_init(n); hprime = _nmod_vec_init(n); _nmod_poly_derivative(hprime, h, n, mod); hprime[n-1] = 0UL; __nmod_poly_exp_series_prealloc(f, g, h, hprime, T, U, n, mod, 0); _nmod_vec_free(hprime); _nmod_vec_free(g); _nmod_vec_free(T); _nmod_vec_free(U); }
void __nmod_poly_exp_series_prealloc(mp_ptr f, mp_ptr g, mp_srcptr h, mp_srcptr hprime, mp_ptr T, mp_ptr U, long n, nmod_t mod, int extend) { long m, m2, l; if (n < NMOD_NEWTON_EXP_CUTOFF) { _nmod_poly_exp_series_basecase(f, h, n, n, mod); _nmod_poly_inv_series_basecase(g, f, extend ? n : (n + 1) / 2, mod); return; } m = (n + 1) / 2; m2 = (m + 1) / 2; l = m - 1; /* shifted for derivative */ /* f := exp(h) + O(x^m), g := exp(-h) + O(x^m2) */ __nmod_poly_exp_series_prealloc(f, g, h, hprime, T, U, m, mod, 0); /* g := exp(-h) + O(x^m) */ _nmod_poly_mullow(T, f, m, g, m2, m, mod); _nmod_poly_mullow(g + m2, g, m2, T + m2, m - m2, m - m2, mod); _nmod_vec_neg(g + m2, g + m2, m - m2, mod); /* U := h' + g (f' - f h') + O(x^(n-1)) Note: should replace h' by h' mod x^(m-1) */ _nmod_vec_zero(f + m, n - m); _nmod_poly_mullow(T, f, n, hprime, n, n, mod); /* should be mulmid */ _nmod_poly_derivative(U, f, n, mod); /* should skip low terms */ _nmod_vec_sub(U + l, U + l, T + l, n - l, mod); _nmod_poly_mullow(T + l, g, n - m, U + l, n - m, n - m, mod); _nmod_vec_add(U + l, hprime + l, T + l, n - m, mod); /* f := f + f * (h - int U) + O(x^n) = exp(h) + O(x^n) */ _nmod_poly_integral(U, U, n, mod); /* should skip low terms */ _nmod_vec_sub(U + m, h + m, U + m, n - m, mod); _nmod_poly_mullow(f + m, f, n - m, U + m, n - m, n - m, mod); /* g := exp(-h) + O(x^n) */ if (extend) { _nmod_poly_mullow(T, f, n, g, m, n, mod); _nmod_poly_mullow(g + m, g, m, T + m, n - m, n - m, mod); _nmod_vec_neg(g + m, g + m, n - m, mod); } }
void _nmod_poly_atan_series(mp_ptr g, mp_srcptr h, long n, nmod_t mod) { mp_ptr t, u; t = _nmod_vec_init(n); u = _nmod_vec_init(n); /* atan(h(x)) = integral(h'(x)/(1+h(x)^2)) */ _nmod_poly_mullow(u, h, n, h, n, n, mod); u[0] = 1UL; _nmod_poly_derivative(t, h, n, mod); t[n-1] = 0UL; _nmod_poly_div_series(g, t, u, n, mod); _nmod_poly_integral(g, g, n, mod); _nmod_vec_free(t); _nmod_vec_free(u); }
void _nmod_poly_asinh_series(mp_ptr g, mp_srcptr h, slong n, nmod_t mod) { mp_ptr t, u; t = _nmod_vec_init(n); u = _nmod_vec_init(n); /* asinh(h(x)) = integral(h'(x)/sqrt(1+h(x)^2)) */ _nmod_poly_mullow(u, h, n, h, n, n, mod); u[0] = UWORD(1); _nmod_poly_invsqrt_series(t, u, n, mod); _nmod_poly_derivative(u, h, n, mod); u[n-1] = UWORD(0); _nmod_poly_mullow(g, t, n, u, n, n, mod); _nmod_poly_integral(g, g, n, mod); _nmod_vec_clear(t); _nmod_vec_clear(u); }
void _nmod_poly_cosh_series(mp_ptr f, mp_srcptr h, long n, nmod_t mod) { mp_ptr g, T, U, hprime; g = _nmod_vec_init(n); T = _nmod_vec_init(n); U = _nmod_vec_init(n); hprime = _nmod_vec_init(n); _nmod_poly_derivative(hprime, h, n, mod); hprime[n-1] = 0UL; __nmod_poly_exp_series_prealloc(f, g, h, hprime, T, U, n, mod, 1); _nmod_vec_add(f, f, g, n, mod); _nmod_vec_scalar_mul_nmod(f, f, n, n_invmod(2UL, mod.n), mod); _nmod_vec_free(hprime); _nmod_vec_free(g); _nmod_vec_free(T); _nmod_vec_free(U); }