void _acb_poly_compose_series_brent_kung(acb_ptr res, acb_srcptr poly1, long len1, acb_srcptr poly2, long len2, long n, long prec) { acb_mat_t A, B, C; acb_ptr t, h; long i, m; if (n == 1) { acb_set(res, poly1); return; } m = n_sqrt(n) + 1; acb_mat_init(A, m, n); acb_mat_init(B, m, m); acb_mat_init(C, m, n); h = _acb_vec_init(n); t = _acb_vec_init(n); /* Set rows of B to the segments of poly1 */ for (i = 0; i < len1 / m; i++) _acb_vec_set(B->rows[i], poly1 + i*m, m); _acb_vec_set(B->rows[i], poly1 + i*m, len1 % m); /* Set rows of A to powers of poly2 */ acb_set_ui(A->rows[0] + 0, 1UL); _acb_vec_set(A->rows[1], poly2, len2); for (i = 2; i < m; i++) _acb_poly_mullow(A->rows[i], A->rows[(i + 1) / 2], n, A->rows[i / 2], n, n, prec); acb_mat_mul(C, B, A, prec); /* Evaluate block composition using the Horner scheme */ _acb_vec_set(res, C->rows[m - 1], n); _acb_poly_mullow(h, A->rows[m - 1], n, poly2, len2, n, prec); for (i = m - 2; i >= 0; i--) { _acb_poly_mullow(t, res, n, h, n, n, prec); _acb_poly_add(res, t, n, C->rows[i], n, prec); } _acb_vec_clear(h, n); _acb_vec_clear(t, n); acb_mat_clear(A); acb_mat_clear(B); acb_mat_clear(C); }
void acb_poly_add(acb_poly_t res, const acb_poly_t poly1, const acb_poly_t poly2, long prec) { long max = FLINT_MAX(poly1->length, poly2->length); acb_poly_fit_length(res, max); _acb_poly_add(res->coeffs, poly1->coeffs, poly1->length, poly2->coeffs, poly2->length, prec); _acb_poly_set_length(res, max); _acb_poly_normalise(res); }
void acb_poly_add_series(acb_poly_t res, const acb_poly_t poly1, const acb_poly_t poly2, slong len, slong prec) { slong len1, len2; len1 = poly1->length; len2 = poly2->length; len1 = FLINT_MIN(len1, len); len2 = FLINT_MIN(len2, len); len = FLINT_MAX(len1, len2); acb_poly_fit_length(res, len); _acb_poly_add(res->coeffs, poly1->coeffs, len1, poly2->coeffs, len2, prec); _acb_poly_set_length(res, len); _acb_poly_normalise(res); }
void _acb_poly_compose_series_horner(acb_ptr res, acb_srcptr poly1, slong len1, acb_srcptr poly2, slong len2, slong n, slong prec) { if (n == 1) { acb_set(res, poly1); } else { slong i = len1 - 1; slong lenr; acb_ptr t = _acb_vec_init(n); lenr = len2; _acb_vec_scalar_mul(res, poly2, len2, poly1 + i, prec); i--; acb_add(res, res, poly1 + i, prec); while (i > 0) { i--; if (lenr + len2 - 1 < n) { _acb_poly_mul(t, res, lenr, poly2, len2, prec); lenr = lenr + len2 - 1; } else { _acb_poly_mullow(t, res, lenr, poly2, len2, n, prec); lenr = n; } _acb_poly_add(res, t, lenr, poly1 + i, 1, prec); } _acb_vec_zero(res + lenr, n - lenr); _acb_vec_clear(t, n); } }