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"
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2015-11-05 17:51:23 +00:00
|
|
|
slong iter;
|
2014-05-16 14:04:28 +02:00
|
|
|
flint_rand_t state;
|
|
|
|
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("find_roots....");
|
2014-05-16 14:04:28 +02:00
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
flint_randinit(state);
|
|
|
|
|
2016-04-10 17:24:58 +02:00
|
|
|
for (iter = 0; iter < 1000 * arb_test_multiplier(); iter++)
|
2014-05-16 14:04:28 +02:00
|
|
|
{
|
|
|
|
acb_poly_t A;
|
|
|
|
acb_poly_t B;
|
|
|
|
acb_poly_t C;
|
|
|
|
acb_t t;
|
|
|
|
acb_ptr roots;
|
2015-11-05 17:51:23 +00:00
|
|
|
slong i, deg, isolated;
|
|
|
|
slong prec = 10 + n_randint(state, 400);
|
2014-05-16 14:04:28 +02:00
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
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");
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2014-05-16 14:04:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < isolated; i++)
|
|
|
|
{
|
|
|
|
acb_poly_evaluate(t, A, roots + i, prec);
|
|
|
|
if (!acb_contains_zero(t))
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
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");
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2014-05-16 14:04:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_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();
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("PASS\n");
|
2014-05-16 14:04:28 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|