void acb_poly_inv_series(acb_poly_t Qinv, const acb_poly_t Q, slong n, slong prec) { if (n == 0) { acb_poly_zero(Qinv); return; } if (Q->length == 0) { acb_poly_fit_length(Qinv, n); _acb_vec_indeterminate(Qinv->coeffs, n); _acb_poly_set_length(Qinv, n); return; } if (Qinv == Q) { acb_poly_t t; acb_poly_init(t); acb_poly_inv_series(t, Q, n, prec); acb_poly_swap(Qinv, t); acb_poly_clear(t); return; } acb_poly_fit_length(Qinv, n); _acb_poly_inv_series(Qinv->coeffs, Q->coeffs, Q->length, n, prec); _acb_poly_set_length(Qinv, n); _acb_poly_normalise(Qinv); }
void acb_poly_sin_cos_series_tangent(acb_poly_t s, acb_poly_t c, const acb_poly_t h, slong n, slong prec, int times_pi) { slong hlen = h->length; if (n == 0) { acb_poly_zero(s); acb_poly_zero(c); return; } if (hlen == 0) { acb_poly_zero(s); acb_poly_one(c); return; } acb_poly_fit_length(s, n); acb_poly_fit_length(c, n); _acb_poly_sin_cos_series_tangent(s->coeffs, c->coeffs, h->coeffs, hlen, n, prec, times_pi); _acb_poly_set_length(s, n); _acb_poly_normalise(s); _acb_poly_set_length(c, n); _acb_poly_normalise(c); }
void acb_poly_sin_cos_pi_series(acb_poly_t s, acb_poly_t c, const acb_poly_t h, slong n, slong prec) { slong hlen = h->length; if (n == 0) { acb_poly_zero(s); acb_poly_zero(c); return; } if (hlen == 0) { acb_poly_zero(s); acb_poly_one(c); return; } if (hlen == 1) n = 1; acb_poly_fit_length(s, n); acb_poly_fit_length(c, n); _acb_poly_sin_cos_pi_series(s->coeffs, c->coeffs, h->coeffs, hlen, n, prec); _acb_poly_set_length(s, n); _acb_poly_normalise(s); _acb_poly_set_length(c, n); _acb_poly_normalise(c); }
void acb_hypgeom_coulomb_series(acb_poly_t F, acb_poly_t G, acb_poly_t Hpos, acb_poly_t Hneg, const acb_t l, const acb_t eta, const acb_poly_t z, slong len, slong prec) { acb_srcptr zptr; slong zlen; acb_t t; if (len == 0) { if (F != NULL) acb_poly_zero(F); if (G != NULL) acb_poly_zero(G); if (Hpos != NULL) acb_poly_zero(Hpos); if (Hneg != NULL) acb_poly_zero(Hneg); return; } zlen = z->length; if (zlen <= 1) len = 1; if (F != NULL) acb_poly_fit_length(F, len); if (G != NULL) acb_poly_fit_length(G, len); if (Hpos != NULL) acb_poly_fit_length(Hpos, len); if (Hneg != NULL) acb_poly_fit_length(Hneg, len); if (zlen == 0) { acb_init(t); zptr = t; zlen = 1; } else { zptr = z->coeffs; } _acb_hypgeom_coulomb_series( F ? F->coeffs : NULL, G ? G->coeffs : NULL, Hpos ? Hpos->coeffs : NULL, Hneg ? Hneg->coeffs : NULL, l, eta, zptr, zlen, len, prec); if (F != NULL) _acb_poly_set_length(F, len); if (G != NULL) _acb_poly_set_length(G, len); if (Hpos != NULL) _acb_poly_set_length(Hpos, len); if (Hneg != NULL) _acb_poly_set_length(Hneg, len); if (F != NULL) _acb_poly_normalise(F); if (G != NULL) _acb_poly_normalise(G); if (Hpos != NULL) _acb_poly_normalise(Hpos); if (Hneg != NULL) _acb_poly_normalise(Hneg); }
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); } }
void acb_poly_add_si(acb_poly_t res, const acb_poly_t x, long y, long prec) { long len = x->length; if (len == 0) { acb_poly_set_si(res, y); } else { acb_poly_fit_length(res, len); if (y >= 0) acb_add_ui(res->coeffs, x->coeffs, y, prec); else acb_sub_ui(res->coeffs, x->coeffs, -y, prec); if (res != x) _acb_vec_set(res->coeffs + 1, x->coeffs + 1, len - 1); _acb_poly_set_length(res, len); _acb_poly_normalise(res); } }
void acb_poly_agm1_series(acb_poly_t res, const acb_poly_t z, long n, long prec) { if (n == 0) { acb_poly_zero(res); return; } acb_poly_fit_length(res, n); if (z->length == 0) { acb_t t; acb_init(t); _acb_poly_agm1_series(res->coeffs, t, 1, n, prec); acb_clear(t); } else { _acb_poly_agm1_series(res->coeffs, z->coeffs, z->length, n, prec); } _acb_poly_set_length(res, n); _acb_poly_normalise(res); }
void acb_poly_mul(acb_poly_t res, const acb_poly_t poly1, const acb_poly_t poly2, slong prec) { slong len_out; if ((poly1->length == 0) || (poly2->length == 0)) { acb_poly_zero(res); return; } len_out = poly1->length + poly2->length - 1; if (res == poly1 || res == poly2) { acb_poly_t temp; acb_poly_init2(temp, len_out); _acb_poly_mul(temp->coeffs, poly1->coeffs, poly1->length, poly2->coeffs, poly2->length, prec); acb_poly_swap(res, temp); acb_poly_clear(temp); } else { acb_poly_fit_length(res, len_out); _acb_poly_mul(res->coeffs, poly1->coeffs, poly1->length, poly2->coeffs, poly2->length, prec); } _acb_poly_set_length(res, len_out); _acb_poly_normalise(res); }
void acb_poly_revert_series_lagrange_fast(acb_poly_t Qinv, const acb_poly_t Q, slong n, slong prec) { slong Qlen = Q->length; if (Qlen < 2 || !acb_is_zero(Q->coeffs) || acb_contains_zero(Q->coeffs + 1)) { flint_printf("Exception (acb_poly_revert_series_lagrange_fast). Input \n" "must have zero constant term and nonzero coefficient of x^1.\n"); abort(); } if (Qinv != Q) { acb_poly_fit_length(Qinv, n); _acb_poly_revert_series_lagrange_fast(Qinv->coeffs, Q->coeffs, Qlen, n, prec); } else { acb_poly_t t; acb_poly_init2(t, n); _acb_poly_revert_series_lagrange_fast(t->coeffs, Q->coeffs, Qlen, n, prec); acb_poly_swap(Qinv, t); acb_poly_clear(t); } _acb_poly_set_length(Qinv, n); _acb_poly_normalise(Qinv); }
void acb_dirichlet_hardy_z_series(acb_poly_t res, const acb_poly_t s, const dirichlet_group_t G, const dirichlet_char_t chi, slong len, slong prec) { if (len == 0) { acb_poly_zero(res); return; } acb_poly_fit_length(res, len); if (s->length == 0) { acb_t t; acb_init(t); _acb_dirichlet_hardy_z_series(res->coeffs, t, 1, G, chi, len, prec); acb_clear(t); } else { _acb_dirichlet_hardy_z_series(res->coeffs, s->coeffs, s->length, G, chi, len, prec); } _acb_poly_set_length(res, len); _acb_poly_normalise(res); }
void acb_poly_sqrt_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec) { if (n == 0) { acb_poly_zero(g); return; } if (g == h) { acb_poly_t t; acb_poly_init(t); acb_poly_sqrt_series(t, h, n, prec); acb_poly_swap(g, t); acb_poly_clear(t); return; } acb_poly_fit_length(g, n); if (h->length == 0) _acb_vec_indeterminate(g->coeffs, n); else _acb_poly_sqrt_series(g->coeffs, h->coeffs, h->length, n, prec); _acb_poly_set_length(g, n); _acb_poly_normalise(g); }
void acb_poly_binomial_transform(acb_poly_t b, const acb_poly_t a, slong len, slong prec) { if (len == 0 || a->length == 0) { acb_poly_zero(b); return; } if (b == a) { acb_poly_t c; acb_poly_init2(c, len); _acb_poly_binomial_transform(c->coeffs, a->coeffs, a->length, len, prec); acb_poly_swap(b, c); acb_poly_clear(c); } else { acb_poly_fit_length(b, len); _acb_poly_binomial_transform(b->coeffs, a->coeffs, a->length, len, prec); } _acb_poly_set_length(b, len); _acb_poly_normalise(b); }
void acb_poly_product_roots(acb_poly_t poly, acb_srcptr xs, slong n, slong prec) { acb_poly_fit_length(poly, n + 1); _acb_poly_product_roots(poly->coeffs, xs, n, prec); _acb_poly_set_length(poly, n + 1); }
void acb_poly_zeta_series(acb_poly_t res, const acb_poly_t f, const acb_t a, int deflate, slong n, slong prec) { if (n == 0) { acb_poly_zero(res); return; } acb_poly_fit_length(res, n); if (f->length == 0) { acb_t t; acb_init(t); _acb_poly_zeta_series(res->coeffs, t, 1, a, deflate, n, prec); acb_clear(t); } else { _acb_poly_zeta_series(res->coeffs, f->coeffs, f->length, a, deflate, n, prec); } _acb_poly_set_length(res, n); _acb_poly_normalise(res); }
void acb_poly_pow_ui(acb_poly_t res, const acb_poly_t poly, ulong exp, slong prec) { slong flen, rlen; flen = poly->length; if (exp == 0) { acb_poly_one(res); } else if (flen == 0) { acb_poly_zero(res); } else { rlen = exp * (flen - 1) + 1; if (res != poly) { acb_poly_fit_length(res, rlen); _acb_poly_pow_ui(res->coeffs, poly->coeffs, flen, exp, prec); _acb_poly_set_length(res, rlen); _acb_poly_normalise(res); } else { acb_poly_t t; acb_poly_init2(t, rlen); _acb_poly_pow_ui(t->coeffs, poly->coeffs, flen, exp, prec); _acb_poly_set_length(t, rlen); _acb_poly_normalise(t); acb_poly_swap(res, t); acb_poly_clear(t); } } }
void acb_poly_pow_ui_trunc_binexp(acb_poly_t res, const acb_poly_t poly, ulong exp, long len, long prec) { long flen, rlen; flen = poly->length; if (exp == 0 && len != 0) { acb_poly_one(res); } else if (flen == 0 || len == 0) { acb_poly_zero(res); } else { rlen = poly_pow_length(flen, exp, len); if (res != poly) { acb_poly_fit_length(res, rlen); _acb_poly_pow_ui_trunc_binexp(res->coeffs, poly->coeffs, flen, exp, rlen, prec); _acb_poly_set_length(res, rlen); _acb_poly_normalise(res); } else { acb_poly_t t; acb_poly_init2(t, rlen); _acb_poly_pow_ui_trunc_binexp(t->coeffs, poly->coeffs, flen, exp, rlen, prec); _acb_poly_set_length(t, rlen); _acb_poly_normalise(t); acb_poly_swap(res, t); acb_poly_clear(t); } } }
void acb_poly_lgamma_series(acb_poly_t res, const acb_poly_t f, slong n, slong prec) { acb_poly_fit_length(res, n); if (f->length == 0 || n == 0) _acb_vec_indeterminate(res->coeffs, n); else _acb_poly_lgamma_series(res->coeffs, f->coeffs, f->length, n, prec); _acb_poly_set_length(res, n); _acb_poly_normalise(res); }
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_rgamma_series(acb_poly_t res, const acb_poly_t f, slong n, slong prec) { if (f->length == 0 || n == 0) { acb_poly_zero(res); } else { acb_poly_fit_length(res, n); _acb_poly_rgamma_series(res->coeffs, f->coeffs, f->length, n, prec); _acb_poly_set_length(res, n); _acb_poly_normalise(res); } }
void acb_poly_interpolate_fast(acb_poly_t poly, acb_srcptr xs, acb_srcptr ys, slong n, slong prec) { if (n == 0) { acb_poly_zero(poly); } else { acb_poly_fit_length(poly, n); _acb_poly_set_length(poly, n); _acb_poly_interpolate_fast(poly->coeffs, xs, ys, n, prec); _acb_poly_normalise(poly); } }
void acb_poly_atan_series(acb_poly_t g, const acb_poly_t h, slong n, slong prec) { slong hlen = h->length; if (hlen == 0 || n == 0) { acb_poly_zero(g); return; } acb_poly_fit_length(g, n); _acb_poly_atan_series(g->coeffs, h->coeffs, hlen, n, prec); _acb_poly_set_length(g, n); _acb_poly_normalise(g); }
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_shift_left(acb_poly_t res, const acb_poly_t poly, long n) { if (n == 0) { acb_poly_set(res, poly); return; } if (poly->length == 0) { acb_poly_zero(res); return; } acb_poly_fit_length(res, poly->length + n); _acb_poly_shift_left(res->coeffs, poly->coeffs, poly->length, n); _acb_poly_set_length(res, poly->length + n); }
void acb_poly_mullow(acb_poly_t res, const acb_poly_t poly1, const acb_poly_t poly2, slong n, slong prec) { slong len1, len2; len1 = poly1->length; len2 = poly2->length; if (len1 == 0 || len2 == 0 || n == 0) { acb_poly_zero(res); return; } n = FLINT_MIN((len1 + len2 - 1), n); len1 = FLINT_MIN(len1, n); len2 = FLINT_MIN(len2, n); if (res == poly1 || res == poly2) { acb_poly_t t; acb_poly_init2(t, n); _acb_poly_mullow(t->coeffs, poly1->coeffs, len1, poly2->coeffs, len2, n, prec); acb_poly_swap(res, t); acb_poly_clear(t); } else { acb_poly_fit_length(res, n); _acb_poly_mullow(res->coeffs, poly1->coeffs, len1, poly2->coeffs, len2, n, prec); } _acb_poly_set_length(res, n); _acb_poly_normalise(res); }
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); } }
void acb_poly_mullow_classical(acb_poly_t res, const acb_poly_t poly1, const acb_poly_t poly2, slong n, slong prec) { slong len_out; if (poly1->length == 0 || poly2->length == 0 || n == 0) { acb_poly_zero(res); return; } len_out = poly1->length + poly2->length - 1; if (n > len_out) n = len_out; if (res == poly1 || res == poly2) { acb_poly_t t; acb_poly_init2(t, n); _acb_poly_mullow_classical(t->coeffs, poly1->coeffs, poly1->length, poly2->coeffs, poly2->length, n, prec); acb_poly_swap(res, t); acb_poly_clear(t); } else { acb_poly_fit_length(res, n); _acb_poly_mullow_classical(res->coeffs, poly1->coeffs, poly1->length, poly2->coeffs, poly2->length, n, prec); } _acb_poly_set_length(res, n); _acb_poly_normalise(res); }
int main() { slong iter; flint_rand_t state; flint_printf("find_roots...."); fflush(stdout); flint_randinit(state); for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++) { acb_poly_t A; acb_poly_t B; acb_poly_t C; acb_t t; acb_ptr roots; slong i, deg, isolated; slong prec = 10 + n_randint(state, 400); acb_init(t); acb_poly_init(A); acb_poly_init(B); acb_poly_init(C); do { acb_poly_randtest(A, state, 2 + n_randint(state, 15), prec, 5); } while (A->length == 0); deg = A->length - 1; roots = _acb_vec_init(deg); isolated = acb_poly_find_roots(roots, A, NULL, 0, prec); if (isolated == deg) { acb_poly_fit_length(B, 1); acb_set(B->coeffs, A->coeffs + deg); _acb_poly_set_length(B, 1); for (i = 0; i < deg; i++) { acb_poly_fit_length(C, 2); acb_one(C->coeffs + 1); acb_neg(C->coeffs + 0, roots + i); _acb_poly_set_length(C, 2); acb_poly_mul(B, B, C, prec); } if (!acb_poly_contains(B, A)) { flint_printf("FAIL: product does not equal polynomial\n"); acb_poly_printd(A, 15); flint_printf("\n\n"); acb_poly_printd(B, 15); flint_printf("\n\n"); flint_abort(); } } for (i = 0; i < isolated; i++) { acb_poly_evaluate(t, A, roots + i, prec); if (!acb_contains_zero(t)) { flint_printf("FAIL: poly(root) does not contain zero\n"); acb_poly_printd(A, 15); flint_printf("\n\n"); acb_printd(roots + i, 15); flint_printf("\n\n"); acb_printd(t, 15); flint_printf("\n\n"); flint_abort(); } } _acb_vec_clear(roots, deg); acb_clear(t); acb_poly_clear(A); acb_poly_clear(B); acb_poly_clear(C); } flint_randclear(state); flint_cleanup(); flint_printf("PASS\n"); return EXIT_SUCCESS; }
void acb_hypgeom_pfq_series_direct(acb_poly_t res, const acb_poly_struct * a, long p, const acb_poly_struct * b, long q, const acb_poly_t z, int regularized, long n, long len, long prec) { acb_poly_t s, t, err; arb_poly_t C, T; long i; int is_real; int terminating; /* default algorithm to choose number of terms */ if (n < 0) { n = acb_hypgeom_pfq_series_choose_n(a, p, b, q, z, len, prec); } terminating = 0; /* check if it terminates due to a root of the numerator */ for (i = 0; i < p; i++) { if (acb_poly_length(a + i) == 0 && n > 0) { terminating = 1; } else if (acb_poly_length(a + i) == 1) { acb_srcptr c = acb_poly_get_coeff_ptr(a + i, 0); if (acb_is_int(c) && arb_is_negative(acb_realref(c)) && arf_cmpabs_ui(arb_midref(acb_realref(c)), n) < 0) { terminating = 1; } } } /* check if it terminates (to order n) due to z */ /* the following tests could be made stronger... */ if (z->length == 0 && n >= 1) { terminating = 1; } else if (!terminating && z->length > 0 && acb_is_zero(z->coeffs) && n >= len) { if (regularized) { terminating = 1; } else { terminating = 1; for (i = 0; i < q; i++) { acb_srcptr c = acb_poly_get_coeff_ptr(b + i, 0); if (!arb_is_positive(acb_realref(c)) && acb_contains_int(c)) terminating = 0; } } } acb_poly_init(s); acb_poly_init(t); acb_poly_init(err); arb_poly_init(C); arb_poly_init(T); acb_hypgeom_pfq_series_sum_forward(s, t, a, p, b, q, z, regularized, n, len, prec); if (!terminating) { is_real = acb_poly_is_real(z); for (i = 0; i < p; i++) is_real = is_real && acb_poly_is_real(a + i); for (i = 0; i < q; i++) is_real = is_real && acb_poly_is_real(b + i); acb_poly_majorant(T, t, MAG_BITS); acb_hypgeom_pfq_series_bound_factor(C, a, p, b, q, z, n, len, MAG_BITS); if (!_arb_vec_is_finite(T->coeffs, T->length) || !_arb_vec_is_finite(C->coeffs, C->length)) { arb_poly_fit_length(T, len); _arb_vec_indeterminate(T->coeffs, len); _arb_poly_set_length(T, len); } else { arb_poly_mullow(T, T, C, len, MAG_BITS); } /* create polynomial of errors */ acb_poly_fit_length(err, len); for (i = 0; i < FLINT_MIN(len, T->length); i++) { arb_add_error(acb_realref(err->coeffs + i), T->coeffs + i); if (!is_real) arb_add_error(acb_imagref(err->coeffs + i), T->coeffs + i); } _acb_poly_set_length(err, len); _acb_poly_normalise(err); acb_poly_add(s, s, err, prec); } acb_poly_set(res, s); acb_poly_clear(s); acb_poly_clear(t); acb_poly_clear(err); arb_poly_clear(C); arb_poly_clear(T); }
void acb_hypgeom_pfq_series_direct(acb_poly_t res, const acb_poly_struct * a, long p, const acb_poly_struct * b, long q, const acb_poly_t z, int regularized, long n, long len, long prec) { acb_poly_t s, t, err; arb_poly_t C, T; long i; int is_real; /* default algorithm to choose number of terms */ if (n < 0) { n = acb_hypgeom_pfq_series_choose_n(a, p, b, q, z, len, prec); } acb_poly_init(s); acb_poly_init(t); acb_poly_init(err); arb_poly_init(C); arb_poly_init(T); acb_hypgeom_pfq_series_sum_forward(s, t, a, p, b, q, z, regularized, n, len, prec); if (acb_poly_length(t) != 0) { is_real = acb_poly_is_real(z); for (i = 0; i < p; i++) is_real = is_real && acb_poly_is_real(a + i); for (i = 0; i < q; i++) is_real = is_real && acb_poly_is_real(b + i); acb_poly_majorant(T, t, MAG_BITS); acb_hypgeom_pfq_series_bound_factor(C, a, p, b, q, z, n, len, MAG_BITS); arb_poly_mullow(T, T, C, len, MAG_BITS); /* create polynomial of errors */ acb_poly_fit_length(err, len); for (i = 0; i < FLINT_MIN(len, T->length); i++) { arb_add_error(acb_realref(err->coeffs + i), T->coeffs + i); if (!is_real) arb_add_error(acb_imagref(err->coeffs + i), T->coeffs + i); } _acb_poly_set_length(err, len); _acb_poly_normalise(err); acb_poly_add(s, s, err, prec); } acb_poly_set(res, s); acb_poly_clear(s); acb_poly_clear(t); acb_poly_clear(err); arb_poly_clear(C); arb_poly_clear(T); }
static void evaluate(acb_poly_t A, acb_srcptr a, slong p, const acb_t z, slong n, slong prec) { acb_poly_fit_length(A, p + 1); if (p == 1) { acb_add_ui(A->coeffs, a, n, prec); if (z != NULL) acb_mul(A->coeffs, A->coeffs, z, prec); } else if (p == 2) { acb_add(A->coeffs, a + 0, a + 1, prec); acb_add_ui(A->coeffs + 1, A->coeffs, 2 * n, prec); acb_add_ui(A->coeffs, A->coeffs, n, prec); acb_mul_ui(A->coeffs, A->coeffs, n, prec); acb_addmul(A->coeffs, a + 0, a + 1, prec); if (z != NULL) { acb_mul(A->coeffs, A->coeffs, z, prec); acb_mul(A->coeffs + 1, A->coeffs + 1, z, prec); } } else if (p == 3) { acb_t t, u; acb_init(t); acb_init(u); acb_add(t, a + 0, a + 1, prec); acb_add(t, t, a + 2, prec); acb_mul(u, a + 0, a + 1, prec); acb_mul(A->coeffs, u, a + 2, prec); acb_addmul(u, a + 0, a + 2, prec); acb_addmul(u, a + 1, a + 2, prec); /* (a0 + n)(a1 + n)(a2 + n) = a0 a1 a2 + (a0 a1 + a0 a2 + a1 a2) n + (a0 + a1 + a2) n^2 + n^3 (a0 a1 + a0 a2 + a1 a2) + 2 (a0 + a1 + a2) n + 3 n^2 (a0 + a1 + a2) + 3n 1 */ acb_addmul_ui(A->coeffs, u, n, prec); acb_addmul_ui(A->coeffs, t, n * n, prec); acb_add_ui(A->coeffs, A->coeffs, n * n * n, prec); acb_set(A->coeffs + 1, u); acb_addmul_ui(A->coeffs + 1, t, 2 * n, prec); acb_add_ui(A->coeffs + 1, A->coeffs + 1, 3 * n * n, prec); acb_add_ui(A->coeffs + 2, t, 3 * n, prec); if (z != NULL) { acb_mul(A->coeffs + 0, A->coeffs + 0, z, prec); acb_mul(A->coeffs + 1, A->coeffs + 1, z, prec); acb_mul(A->coeffs + 2, A->coeffs + 2, z, prec); } acb_clear(t); acb_clear(u); } else if (p != 0) { flint_abort(); } if (z != NULL) acb_set(A->coeffs + p, z); else acb_one(A->coeffs + p); _acb_poly_set_length(A, p + 1); _acb_poly_normalise(A); }