arb/arb_poly/product_roots.c
2016-04-26 17:20:05 +02:00

55 lines
1.4 KiB
C

/*
Copyright (C) 2011 William Hart
Copyright (C) 2012 Fredrik Johansson
This file is part of Arb.
Arb is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version. See <http://www.gnu.org/licenses/>.
*/
#include "arb_poly.h"
void
_arb_poly_product_roots(arb_ptr poly, arb_srcptr xs, slong n, slong prec)
{
if (n == 0)
{
arb_one(poly);
}
else if (n == 1)
{
arb_neg(poly, xs);
arb_one(poly + 1);
}
else if (n == 2)
{
arb_mul(poly, xs + 0, xs + 1, prec);
arb_add(poly + 1, xs + 0, xs + 1, prec);
arb_neg(poly + 1, poly + 1);
arb_one(poly + 2);
}
else
{
const slong m = (n + 1) / 2;
arb_ptr tmp;
tmp = _arb_vec_init(n + 2);
_arb_poly_product_roots(tmp, xs, m, prec);
_arb_poly_product_roots(tmp + m + 1, xs + m, n - m, prec);
_arb_poly_mul_monic(poly, tmp, m + 1, tmp + m + 1, n - m + 1, prec);
_arb_vec_clear(tmp, n + 2);
}
}
void
arb_poly_product_roots(arb_poly_t poly, arb_srcptr xs, slong n, slong prec)
{
arb_poly_fit_length(poly, n + 1);
_arb_poly_product_roots(poly->coeffs, xs, n, prec);
_arb_poly_set_length(poly, n + 1);
}