1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
Copyright (C) 2012 Fredrik Johansson
This file is part of FLINT.
FLINT 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 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/
#include "acb_poly.h"
slong
_acb_poly_validate_roots(acb_ptr roots,
acb_srcptr poly, slong len, slong prec)
{
slong i, j, deg;
slong isolated, nonisolated, total_isolated;
acb_ptr deriv;
acb_ptr tmp;
int *overlap;
deg = len - 1;
deriv = _acb_vec_init(deg);
overlap = flint_calloc(deg, sizeof(int));
tmp = flint_malloc(sizeof(acb_struct) * deg);
_acb_poly_derivative(deriv, poly, len, prec);
/* compute an inclusion interval for each point */
for (i = 0; i < deg; i++)
{
_acb_poly_root_inclusion(roots + i, roots + i,
poly, deriv, len, prec);
}
/* find which points do not overlap with any other points */
for (i = 0; i < deg; i++)
{
for (j = i + 1; j < deg; j++)
{
if (acb_overlaps(roots + i, roots + j))
{
overlap[i] = overlap[j] = 1;
}
}
}
/* count and move all isolated roots to the front of the array */
total_isolated = 0;
for (i = 0; i < deg; i++)
total_isolated += (overlap[i] == 0);
for (i = 0; i < deg; i++)
tmp[i] = roots[i];
isolated = 0;
nonisolated = 0;
for (i = 0; i < deg; i++)
{
if (overlap[i] == 0)
{
roots[isolated] = tmp[i];
isolated++;
}
else
{
roots[total_isolated + nonisolated] = tmp[i];
nonisolated++;
}
}
_acb_vec_clear(deriv, deg);
flint_free(tmp);
flint_free(overlap);
return isolated;
}