2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2014-05-16 14:04:28 +02:00
|
|
|
Copyright (C) 2012 Fredrik Johansson
|
|
|
|
|
2016-04-26 17:20:05 +02:00
|
|
|
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/>.
|
|
|
|
*/
|
2014-05-16 14:04:28 +02:00
|
|
|
|
|
|
|
#include "acb_poly.h"
|
|
|
|
|
2015-11-05 17:51:23 +00:00
|
|
|
acb_ptr * _acb_poly_tree_alloc(slong len)
|
2014-05-16 14:04:28 +02:00
|
|
|
{
|
|
|
|
acb_ptr * tree = NULL;
|
|
|
|
|
|
|
|
if (len)
|
|
|
|
{
|
2015-11-05 17:51:23 +00:00
|
|
|
slong i, height = FLINT_CLOG2(len);
|
2014-05-16 14:04:28 +02:00
|
|
|
|
|
|
|
tree = flint_malloc(sizeof(acb_ptr) * (height + 1));
|
|
|
|
for (i = 0; i <= height; i++)
|
|
|
|
tree[i] = _acb_vec_init(len + (len >> i) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
2015-11-05 17:51:23 +00:00
|
|
|
void _acb_poly_tree_free(acb_ptr * tree, slong len)
|
2014-05-16 14:04:28 +02:00
|
|
|
{
|
|
|
|
if (len)
|
|
|
|
{
|
2015-11-05 17:51:23 +00:00
|
|
|
slong i, height = FLINT_CLOG2(len);
|
2014-05-16 14:04:28 +02:00
|
|
|
|
|
|
|
for (i = 0; i <= height; i++)
|
|
|
|
_acb_vec_clear(tree[i], len + (len >> i) + 1);
|
|
|
|
|
|
|
|
flint_free(tree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-11-05 17:51:23 +00:00
|
|
|
_acb_poly_tree_build(acb_ptr * tree, acb_srcptr roots, slong len, slong prec)
|
2014-05-16 14:04:28 +02:00
|
|
|
{
|
2015-11-05 17:51:23 +00:00
|
|
|
slong height, pow, left, i;
|
2014-05-16 14:04:28 +02:00
|
|
|
acb_ptr pa, pb;
|
|
|
|
acb_srcptr a, b;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
height = FLINT_CLOG2(len);
|
|
|
|
|
|
|
|
/* zeroth level, (x-a) */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
acb_one(tree[0] + (2 * i + 1));
|
|
|
|
acb_neg(tree[0] + (2 * i), roots + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first level, (x-a)(x-b) = x^2 + (-a-b)*x + a*b */
|
|
|
|
if (height > 1)
|
|
|
|
{
|
|
|
|
pa = tree[1];
|
|
|
|
|
|
|
|
for (i = 0; i < len / 2; i++)
|
|
|
|
{
|
|
|
|
a = (acb_srcptr) (roots + (2 * i));
|
|
|
|
b = (acb_srcptr) (roots + (2 * i + 1));
|
|
|
|
|
|
|
|
acb_mul(pa + (3 * i), a, b, prec);
|
|
|
|
acb_add(pa + (3 * i + 1), a, b, prec);
|
|
|
|
acb_neg(pa + (3 * i + 1), pa + (3 * i + 1));
|
|
|
|
acb_one(pa + (3 * i + 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len & 1)
|
|
|
|
{
|
|
|
|
acb_neg(pa + (3 * (len / 2)), roots + len - 1);
|
|
|
|
acb_one(pa + (3 * (len / 2) + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i < height - 1; i++)
|
|
|
|
{
|
|
|
|
left = len;
|
2015-11-06 15:34:19 +00:00
|
|
|
pow = WORD(1) << i;
|
2014-05-16 14:04:28 +02:00
|
|
|
pa = tree[i];
|
|
|
|
pb = tree[i + 1];
|
|
|
|
|
|
|
|
while (left >= 2 * pow)
|
|
|
|
{
|
|
|
|
_acb_poly_mul_monic(pb, pa, pow + 1, pa + pow + 1, pow + 1, prec);
|
|
|
|
left -= 2 * pow;
|
|
|
|
pa += 2 * pow + 2;
|
|
|
|
pb += 2 * pow + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left > pow)
|
|
|
|
{
|
|
|
|
_acb_poly_mul_monic(pb, pa, pow + 1, pa + pow + 1, left - pow + 1, prec);
|
|
|
|
}
|
|
|
|
else if (left > 0)
|
|
|
|
_acb_vec_set(pb, pa, left + 1);
|
|
|
|
}
|
|
|
|
}
|