Debian Codegraph @

src/libmps/unisolve/solve.c

raw
1 /*
2 * This file is part of MPSolve 3.2.2
3 *
4 * Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa.
5 * License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher
6 *
7 * Authors:
8 * Dario Andrea Bini <[email protected]>
9 * Giuseppe Fiorentino <[email protected]>
10 * Leonardo Robol <[email protected]>
11 */
12
13
14 #include <math.h>
15 #include <mps/mps.h>
16 #include <float.h>
17
18 /**
19 * @brief Set <code>again[i]</code> to <code>true</code> or to <code>false</code>
20 * according to the values of <code>status</code> and <code>inclusion</code>
21 * in the mps_approximation and the current <code>goal</code>.
22 *
23 * More precisely:
24 *
25 * - If goal is <code>MPS_OUTPUT_GOAL_COUNT</code>: <code>true</code> only
26 * if inclusion is <code>MPS_ROOT_INCLUSION_UNKNOWN</code> and status is not
27 * <code>MPS_ROOT_STATUS_APPROXIMATED</code>, <code>MPS_ROOT_STATUS_APPROXIMATED_IN_CLUSTER</code>
28 * or <code>MPS_ROOT_STATUS_NOT_FLOAT</code>.
29 *
30 * - If goal is <code>MPS_OUTPUT_GOAL_ISOLATE</code> or <code>MPS_OUTPUT_GOAL_APPROXIMATE</code>:
31 * <code>true</code> if <code>status</code> is <code>MPS_ROOT_STATUS_CLUSTERED</code> or <code>inclusion</code>
32 * is <code>MPS_ROOT_INCLUSION_UNKNOWN</code>.
33 */
34 MPS_PRIVATE void
35 mps_update (mps_context * s)
36 {
37 int i;
38
39 for (i = 0; i < s->n; i++)
40 s->root[i]->again = false;
41 switch (s->output_config->goal)
42 {
43 case MPS_OUTPUT_GOAL_COUNT: /* count */
44 for (i = 0; i < s->n; i++)
45 {
46 if (s->root[i]->inclusion == MPS_ROOT_INCLUSION_UNKNOWN)
47 if (!MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status) &&
48 s->root[i]->status != MPS_ROOT_STATUS_NOT_DPE)
49 s->root[i]->again = true;
50
51 if (s->output_config->multiplicity &&
52 s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED &&
53 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT)
54 s->root[i]->again = true;
55
56 if (s->output_config->root_properties &&
57 (s->root[i]->attrs == MPS_ROOT_ATTRS_NONE &&
58 (s->root[i]->inclusion != MPS_ROOT_INCLUSION_UNKNOWN ||
59 (!MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status) &&
60 s->root[i]->status != MPS_ROOT_STATUS_NOT_DPE))))
61 s->root[i]->again = true;
62 }
63 break;
64
65 case MPS_OUTPUT_GOAL_ISOLATE: /* isolate */
66 for (i = 0; i < s->n; i++)
67 {
68 if (s->root[i]->inclusion == MPS_ROOT_INCLUSION_UNKNOWN ||
69 (s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED &&
70 s->root[i]->inclusion == MPS_ROOT_INCLUSION_IN))
71 if (!MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status) &&
72 (s->root[i]->status != MPS_ROOT_STATUS_ISOLATED ||
73 s->root[i]->inclusion != MPS_ROOT_INCLUSION_IN))
74 s->root[i]->again = true;
75
76 if (s->output_config->multiplicity &&
77 s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED &&
78 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT)
79 s->root[i]->again = true;
80
81 if (s->output_config->root_properties)
82 {
83 if (s->root[i]->attrs == MPS_ROOT_ATTRS_NONE &&
84 (!MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status) &&
85 s->root[i]->status != MPS_ROOT_STATUS_NOT_DPE))
86 s->root[i]->again = true;
87 }
88 }
89
90 break;
91
92 case MPS_OUTPUT_GOAL_APPROXIMATE: /* approximate (the same as isolate) */
93 for (i = 0; i < s->n; i++)
94 {
95 if (s->root[i]->inclusion == MPS_ROOT_INCLUSION_UNKNOWN ||
96 (s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED &&
97 s->root[i]->inclusion == MPS_ROOT_INCLUSION_IN))
98 if (!MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status))
99 s->root[i]->again = true;
100
101 if (s->output_config->multiplicity &&
102 s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED &&
103 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT)
104 s->root[i]->again = true;
105
106 if (s->output_config->root_properties)
107 {
108 if (s->root[i]->attrs == MPS_ROOT_ATTRS_NONE &&
109 MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status))
110 s->root[i]->again = true;
111 }
112 }
113 break;
114 }
115 }
116
117 /**
118 * @brief Compute super center and super radius
119 *
120 * This routines the super radius of the <code>i</code>-th cluster,
121 * i.e. the radius of the inclusion disc for the whole cluster
122 *
123 * @param s The <code>mps_context</code> associated with the current computation.
124 * @param cluster cluster of which the super center and radius should be computed.
125 * @param sc Center of the cluster;
126 * @param sr Double that will be set to the super radius of the cluster;
127 */
128 MPS_PRIVATE void
129 mps_fsrad (mps_context * s, mps_cluster * cluster, cplx_t sc, double *sr)
130 {
131 cplx_t ctmp;
132 double sum;
133 int l;
134
135 mps_root * root;
136
137 sum = 0.0;
138 for (root = cluster->first; root != NULL; root = root->next)
139 {
140 l = root->k;
141 sum += s->root[l]->frad;
142 }
143 cplx_set (sc, cplx_zero);
144 for (root = cluster->first; root != NULL; root = root->next)
145 {
146 l = root->k;
147 cplx_mul_d (ctmp, s->root[l]->fvalue, s->root[l]->frad);
148 cplx_add_eq (sc, ctmp);
149 }
150 cplx_div_eq_d (sc, sum);
151 *sr = 0.0;
152 for (root = cluster->first; root != NULL; root = root->next)
153 {
154 l = root->k;
155 cplx_sub (ctmp, sc, s->root[l]->fvalue);
156 *sr = MAX (*sr, s->root[l]->frad + cplx_mod (ctmp));
157 }
158 }
159
160 /**
161 * @brief <code>dpe</code> version of <code>fsrad()</code>
162 */
163 MPS_PRIVATE void
164 mps_dsrad (mps_context * s, mps_cluster * cluster, cdpe_t sc, rdpe_t sr)
165 {
166 cdpe_t ctmp;
167 rdpe_t sum, rtmp;
168 int l;
169 mps_root * root;
170
171 rdpe_set (sum, rdpe_zero);
172 for (root = cluster->first; root != NULL; root = root->next)
173 {
174 l = root->k;
175 rdpe_add_eq (sum, s->root[l]->drad);
176 }
177 cdpe_set (sc, cdpe_zero);
178 for (root = cluster->first; root != NULL; root = root->next)
179 {
180 l = root->k;
181 cdpe_mul_e (ctmp, s->root[l]->dvalue, s->root[l]->drad);
182 cdpe_add_eq (sc, ctmp);
183 }
184 cdpe_div_eq_e (sc, sum);
185 rdpe_set (sr, rdpe_zero);
186 for (root = cluster->first; root != NULL; root = root->next)
187 {
188 l = root->k;
189 cdpe_sub (ctmp, sc, s->root[l]->dvalue);
190 cdpe_mod (rtmp, ctmp);
191 rdpe_add_eq (rtmp, s->root[l]->drad);
192 if (rdpe_lt (sr, rtmp))
193 rdpe_set (sr, rtmp);
194 }
195 }
196
197 /**
198 * @brief Multiprecision versione of <code>fsrad()</code>
199 */
200 MPS_PRIVATE void
201 mps_msrad (mps_context * s, mps_cluster * cluster, mpc_t sc, rdpe_t sr)
202 {
203 int l;
204 rdpe_t rtmp;
205 cdpe_t cdtmp;
206 mpf_t ftmp, sum;
207 mpc_t ctmp;
208 mps_root * root;
209
210 mpc_init2 (ctmp, s->mpwp);
211 mpf_init2 (ftmp, s->mpwp);
212 mpf_init2 (sum, s->mpwp);
213
214 mpf_set_ui (sum, 0);
215 for (root = cluster->first; root != NULL; root = root->next)
216 {
217 l = root->k;
218 mpf_set_rdpe (ftmp, s->root[l]->drad);
219 mpf_add (sum, sum, ftmp);
220 }
221
222 mpc_set_ui (sc, 0, 0);
223 for (root = cluster->first; root != NULL; root = root->next)
224 {
225 l = root->k;
226 mpf_set_rdpe (ftmp, s->root[l]->drad);
227 mpc_mul_f (ctmp, s->root[l]->mvalue, ftmp);
228 mpc_add_eq (sc, ctmp);
229 }
230
231 mpc_div_eq_f (sc, sum);
232 rdpe_set (sr, rdpe_zero);
233 for (root = cluster->first; root != NULL; root = root->next)
234 {
235 l = root->k;
236 mpc_sub (ctmp, sc, s->root[l]->mvalue);
237 mpc_get_cdpe (cdtmp, ctmp);
238 cdpe_mod (rtmp, cdtmp);
239 rdpe_add_eq (rtmp, s->root[l]->drad);
240 if (rdpe_lt (sr, rtmp))
241 rdpe_set (sr, rtmp);
242 else
243 {
244 if (s->debug_level & MPS_DEBUG_CLUSTER)
245 {
246 MPS_DEBUG_RDPE (s, sr, "Super radius of the cluster");
247 }
248 }
249 }
250
251 mpf_clear (sum);
252 mpf_clear (ftmp);
253 mpc_clear (ctmp);
254 }
255
256
257
258 /**
259 * @brief Check if the roots are computed with the required
260 * precision.
261 *
262 * Set <code>computed</code> to <code>true</code>
263 * if the stop condition is satisfied,
264 * otherwise set <code>computed</code> to <code>false</code>.
265 *
266 * The stop condition is obtained from the vector <code>status</code>
267 * as follows:
268 *
269 * If the <code>goal</code> is count stop if
270 * - <code>**u</code> does not exist, except for
271 * <code>a*u</code>, <code>o*u</code>, <code>f*u</code>
272 * - Mult. and does not exist <code>c**</code>
273 * - Real. and does not exist <code>*u*</code>, except for <code>au*</code>,
274 * <code>ou*</code>;
275 * - Imag and does not exist <code>*v*</code>, except for
276 * <code>av*</code>, <code>ov*</code>;
277 *
278 * If the <code>goal</code> is isolate or approximate stop if:
279 * - <code>**u</code> does not exist, except for <code>a*u</code>,
280 * <code>o*u</code>, <code>f*u</code>
281 * and if <code>c*i</code> does not exist;
282 * - Mult. and does not exist <code>c*i</code>, <code>o*i</code>
283 * - Real. and does not exist <code>*ui</code>, except for <code>aui</code>,
284 * <code>oui</code>;
285 * - Imag and does not exist <code>*vi</code>,
286 * except for <code>avi</code>, <code>ovi</code>;
287 *
288 * @see status
289 */
290 MPS_PRIVATE mps_boolean
291 mps_check_stop (mps_context * s)
292 {
293 MPS_DEBUG_THIS_CALL (s);
294
295 int i;
296 mps_boolean computed;
297
298 computed = false;
299 /* count */
300 if (s->output_config->goal == MPS_OUTPUT_GOAL_COUNT)
301 {
302 for (i = 0; i < s->n; i++)
303 {
304 if (!MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status) &&
305 s->root[i]->inclusion == MPS_ROOT_INCLUSION_UNKNOWN)
306 return computed;
307
308 if (s->output_config->multiplicity &&
309 s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED &&
310 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT)
311 return computed;
312
313 if (s->output_config->root_properties &&
314 s->root[i]->attrs == MPS_ROOT_ATTRS_NONE &&
315 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT &&
316 !MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status) &&
317 s->root[i]->status != MPS_ROOT_STATUS_MULTIPLE)
318 return computed;
319 }
320 computed = true;
321 }
322
323 /* isolate or approximate */
324 if (s->output_config->goal == MPS_OUTPUT_GOAL_ISOLATE ||
325 s->output_config->goal == MPS_OUTPUT_GOAL_APPROXIMATE)
326 {
327 for (i = 0; i < s->n; i++)
328 {
329 if ((s->root[i]->inclusion == MPS_ROOT_INCLUSION_UNKNOWN || s->root[i]->inclusion == MPS_ROOT_INCLUSION_IN) &&
330 !MPS_ROOT_STATUS_IS_COMPUTED (s->root[i]->status))
331 {
332 if (s->debug_level & MPS_DEBUG_PACKETS)
333 MPS_DEBUG (s, "Cannot stop because root %d is not approximated, and its inclusion is not certain", i);
334 return computed;
335 }
336
337 if (s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED &&
338 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT)
339 {
340 if (s->debug_level & MPS_DEBUG_PACKETS)
341 MPS_DEBUG (s, "Cannot stop because root %d is clustered and not certainly out of the target set", i);
342 return computed;
343 }
344
345 if (s->output_config->multiplicity &&
346 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT &&
347 s->root[i]->status == MPS_ROOT_STATUS_CLUSTERED)
348 {
349 if (s->debug_level & MPS_DEBUG_PACKETS)
350 MPS_DEBUG (s, "Cannot stop because root %d is not out of the target set and is clustered", i);
351 return computed;
352 }
353
354 if (s->output_config->root_properties &&
355 s->root[i]->attrs == MPS_ROOT_ATTRS_NONE &&
356 s->root[i]->inclusion != MPS_ROOT_INCLUSION_OUT &&
357 !MPS_ROOT_STATUS_IS_APPROXIMATED (s->root[i]->status) &&
358 s->root[i]->status != MPS_ROOT_STATUS_MULTIPLE)
359 {
360 if (s->debug_level & MPS_DEBUG_PACKETS)
361 MPS_DEBUG (s, "Cannot stop because properties of root %d have not been detected, it's not out of the target set, nor approximated or multiple", i);
362 return computed;
363 }
364 }
365
366 MPS_DEBUG (s, "All roots are computed, stopping Aberth");
367 computed = true;
368 }
369
370 return computed;
371 }
372
373 /**
374 * @brief Actually solve the polynomial
375 *
376 * This routine performs the following computations:
377 * -# Select starting approximations and check if some of them need dpe.
378 * Initialize the vector again which is true if the corresponding
379 * approximation is out of the root neighbourhood.
380 * -# Performs max_pack packets of Aberth iterations on all the
381 * components out of the root neighbourhood belonging to the set S
382 * and on which it is possible to iterate with float.
383 * More precisely, each packet performs max_it iterations on all the
384 * components where again is true. At each iteration check if the
385 * current approximation is in the root neighbourhood; in this case
386 * set 'again' to false.
387 * -# If at the end of the general packet all the approximations
388 * are inside the root neighbourhood, i.e., 'again' is false in all
389 * the components then return.
390 * else, perform cluster analysis, select new starting approximations
391 * update the vector 'statu', update the vector 'again' that selects
392 * the components on which to iterate, according to the goal, and
393 * repeat until the max number of allowed packets is reached.
394 * In the latter case output FAILURE.
395 *
396 * The local variable <code>again</code> controls the iteration: i.e.,
397 * <code>again[i]=true</code> means iterate on the <code>i</code>-th
398 * component
399 *
400 * @param s The <code>mps_context</code> associated with the current computation.
401 * @param d_after_f this variable is <code>true</code> if dpe
402 * are needed after the floating point pass.
403 */
404 MPS_PRIVATE void
405 mps_fsolve (mps_context * s, mps_boolean * d_after_f)
406 {
407 mps_boolean excep;
408 int it_pack, iter, nit, oldnclust, i, j, required_zeros = s->n;
409 mps_polynomial *p = s->active_poly;
410 double * frad = double_valloc (s->n);
411
412 /* == 1 == Initialize variables */
413 it_pack = 0;
414 mps_cluster_reset (s);
415 for (i = 0; i < s->n; i++)
416 {
417 s->root[i]->again = true;
418 cplx_set (s->root[i]->fvalue, cplx_zero);
419 s->root[i]->frad = DBL_MAX;
420 }
421
422 /* choose starting approximations */
423 if (s->DOLOG)
424 fprintf (s->logstr, "FSOLVE: call fstart");
425
426 mps_polynomial_fstart (s, p, s->root);
427
428 /***************
429 this part of code performs shift in the gravity center of the roots
430 In order to use it, uncomment the part below and comment the
431 instruction above. Dangerous for overflow.
432 ************/
433 /*
434 {
435 cplx_t ft;
436 cplx_mul_d(ft, fpc[n], -n);
437 cplx_div(ft, fpc[n-1], ft);
438 fshift(n, 0, 100, ft, eps_out);
439 }
440 *//* till here */
441
442 if (s->debug_level & MPS_DEBUG_APPROXIMATIONS)
443 mps_dump (s);
444
445 /* Check if there are too large or too small approximations */
446 *d_after_f = false;
447 for (i = 0; i < s->n; i++)
448 if (s->root[i]->status == MPS_ROOT_STATUS_NOT_FLOAT)
449 {
450 s->root[i]->again = false;
451 *d_after_f = true;
452 }
453
454 /* == 2 == Perform max_pack packets of Aberth's iterations */
455 if (s->DOLOG)
456 fprintf (s->logstr, " FSOLVE: call fpolzer\n");
457 for (iter = 0; iter < s->max_pack; iter++)
458 { /* floop: */
459 /* mps_fpolzer(s, &nit, &excep); */
460 mps_thread_fpolzer (s, &nit, &excep, required_zeros--);
461 it_pack += nit;
462
463 /* This flag will be set in case any floating point
464 * exception happens during this phase. In this case, we are
465 * required to switch to the DPE phase. */
466 if (s->skip_float)
467 {
468 *d_after_f = true;
469 s->skip_float = false;
470
471 /* Fake that all the roots are not representable in floating point.
472 * In this way the following routines will take care of reinitializing the
473 * itearation completely. */
474 for (i = 0; i < s->n; i++)
475 {
476 s->root[i]->status = MPS_ROOT_STATUS_NOT_FLOAT;
477 }
478
479 goto fsolve_final_cleanup;
480 }
481
482 if (s->DOLOG)
483 fprintf (s->logstr, "Packet %d iterations= %d\n", iter, nit);
484
485 /* perform cluster analysis, shift, restart, update 'statu', and
486 * update 'again'
487 */
488 if (excep)
489 {
490 oldnclust = s->clusterization->n;
491
492 if (s->DOLOG)
493 fprintf (s->logstr, " FSOLVE: call fcluster\n");
494 /* cluster analysis */
495
496 /* Compute the inclusion radii with Gerschgorin so we can compute
497 * clusterizations for the roots. */
498 mps_fradii (s, s->active_poly, frad);
499 mps_fcluster (s, frad, 2 * s->n); /* Isolation factor */
500
501 MPS_DEBUG (s, "oldncluster = %d, ncluster = %ld", oldnclust, s->clusterization->n);
502
503 if (oldnclust == s->clusterization->n)
504 {
505 if (s->DOLOG)
506 fprintf (s->logstr, " FSOLVE: cycle\n");
507 continue;
508 }
509 else
510 {
511 /* modify the vector status and mark also the old
512 * clusters with 'C'
513 */
514 if (s->DOLOG)
515 fprintf (s->logstr, " FSOLVE: call modify\n");
516 mps_fmodify (s, true);
517
518 if (iter == 0)
519 for (i = 0; i < s->n; i++)
520 if (s->root[i]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
521 s->root[i]->status = MPS_ROOT_STATUS_CLUSTERED;
522
523 /* If the polynomial is not given in terms of its coeff. then
524 * skip the restart stage */
525 if (MPS_IS_MONOMIAL_POLY (s->active_poly))
526 {
527 /* choose new starting approximations only for new clusters */
528 if (s->DOLOG)
529 fprintf (s->logstr, " FSOLVE: call frestart\n");
530 mps_frestart (s);
531 }
532 /* reset the status vector */
533 for (j = 0; j < s->n; j++)
534 {
535 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
536 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
537 s->again_old[j] = s->root[j]->again;
538 }
539
540 /* update 'again' */
541 if (s->DOLOG)
542 fprintf (s->logstr, " FSOLVE: call update\n");
543 mps_update (s);
544
545 /* adjust 'again' This is needed since we are
546 * between two packets */
547 for (i = 0; i < s->n; i++)
548 if (!s->again_old[i])
549 s->root[i]->again = false;
550 if (s->DOLOG)
551 fprintf (s->logstr, " FSOLVE: call checkstop\n");
552 /* Check the stop condition */
553 if (mps_check_stop (s))
554 goto fsolve_final_cleanup;
555 }
556 }
557 else
558 break;
559 }
560
561 /* The 'floop' has been completed:
562 * If the max number of iteration has been reached then output FAILURE */
563 if (iter == s->max_pack)
564 {
565 mps_dump (s);
566 mps_error (s,
567 "Float: reached the maximum number of packet iterations");
568 }
569 /* Otherwise exit since all the approximations are
570 * in the root neighbourhood, except for the ones that cannot be
571 * represented as double. */
572
573 if (s->DOLOG)
574 fprintf (s->logstr, "FLOAT: nit= %d\n", it_pack);
575
576 /* Update */
577 if (s->DOLOG)
578 fprintf (s->logstr, " FSOLVE: call fcluster\n");
579 oldnclust = s->clusterization->n;
580
581 /* Compute the inclusion radii with Gerschgorin so we can compute
582 * clusterizations for the roots. */
583 mps_fradii (s, s->active_poly, frad);
584 mps_fcluster (s, frad, 2 * s->n); /* Isolation factor */
585
586 if (s->DOLOG)
587 fprintf (s->logstr, " FSOLVE: call modify\n");
588 mps_fmodify (s, true);
589
590 /* reset the status vector */
591 for (j = 0; j < s->n; j++)
592 {
593 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
594 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
595 if (s->root[j]->status == MPS_ROOT_STATUS_NOT_FLOAT)
596 *d_after_f = true;
597 }
598
599
600 fsolve_final_cleanup:
601 double_vfree (frad);
602 }
603
604 /**
605 * @brief This routine applies <code>nit</code> iterations of
606 * Aberth's method.
607 *
608 * The method is applied to
609 * the <code>i</code>-th component of the approximations for which
610 * <code>again[i]</code>
611 * is <code>true</code>. Set <code>again[i]=false</code> if the <code>i</code>-th
612 * approximation is in
613 * the root neighbourhood. Stop if <code>again[i]=false</code> for any <code>i</code>.
614 *
615 * @param s The <code>mps_context</code> associated with the current computation.
616 * @param it Index of the component on which the iteration is needed.
617 * @param excep This variable is set to <code>true</code> if after <code>nit</code>
618 * iterations some approximation is still out of the root neighbourhood.
619 */
620 MPS_PRIVATE void
621 mps_fpolzer (mps_context * s, int *it, mps_boolean * excep)
622 {
623 int i, iter, nzeros;
624 cplx_t corr, abcorr;
625 double rad1, modcorr;
626 mps_polynomial *p = s->active_poly;
627
628 /* initialize the iteration counter */
629 *it = 0;
630 *excep = false;
631
632 /* count the number of approximations in the root neighbourhood */
633 nzeros = 0;
634 for (i = 0; i < s->n; i++)
635 if (!s->root[i]->again)
636 nzeros++;
637 if (nzeros == s->n)
638 return;
639
640 /* Start Aberth's iterations */
641 if (s->DOLOG)
642 fprintf (s->logstr, "FPOLZER: starts aberth it\n");
643
644 for (iter = 0; iter < s->max_it; iter++)
645 { /* do_iter : DO iter=1,nit */
646 if (s->DOLOG)
647 {
648 fprintf (s->logstr, "FPOLZER: iteration %d\n", iter);
649 mps_dump (s);
650 }
651
652 for (i = 0; i < s->n; i++)
653 { /* do_index */
654 if (s->root[i]->again)
655 {
656 (*it)++;
657 rad1 = s->root[i]->frad;
658 mps_polynomial_fnewton (s, p, s->root[i], corr);
659 if (iter == 0 && !s->root[i]->again && s->root[i]->frad > rad1 && rad1
660 != 0)
661 s->root[i]->frad = rad1;
662 /***************************************
663 The above condition is needed to cope with the case
664 where at the first iteration the starting point
665 is already in the root neighbourhood and the actually
666 computed radius is too big since the value of the first
667 derivative is too small.
668 In this case the previous radius bound, obtained by
669 means of Rouche' is more reliable and strict
670 **************************************/
671
672 if (s->root[i]->again ||
673 /* the correction is performed only if iter!=1 or rad(i)!=rad1 */
674 iter != 0 || s->root[i]->frad != rad1)
675 {
676 mps_faberth (s, s->root[i], abcorr);
677 cplx_mul_eq (abcorr, corr);
678 cplx_sub (abcorr, cplx_one, abcorr);
679 cplx_div (abcorr, corr, abcorr);
680 cplx_sub_eq (s->root[i]->fvalue, abcorr);
681 modcorr = cplx_mod (abcorr);
682 s->root[i]->frad += modcorr;
683 }
684
685 /* check for new approximated roots */
686 if (!s->root[i]->again)
687 {
688 nzeros++;
689 if (nzeros == s->n)
690 return;
691 }
692 }
693 }
694 }
695 *excep = true;
696 }
697
698 /**
699 * @brief <code>dpe</code> version of <code>fpolzer()</code>.
700 */
701 MPS_PRIVATE void
702 mps_dpolzer (mps_context * s, int *it, mps_boolean * excep)
703 {
704 int iter, i, nzeros;
705 rdpe_t rad1, rtmp;
706 cdpe_t corr, abcorr;
707 mps_polynomial *p = s->active_poly;
708
709 /* initialize the iteration counter */
710 *it = 0;
711 *excep = false;
712
713 /* count the number of approximations in the root neighbourhood */
714 nzeros = 0;
715 for (i = 0; i < s->n; i++)
716 if (!s->root[i]->again)
717 nzeros++;
718 if (nzeros == s->n)
719 return;
720
721 /* Start Aberth's iterations */
722 if (s->DOLOG)
723 fprintf (s->logstr, "DPOLZER: starts aberth\n");
724 for (iter = 0; iter < s->max_it; iter++)
725 { /* do_iter: */
726 for (i = 0; i < s->n; i++)
727 { /* do_index: */
728 if (s->root[i]->again)
729 {
730 (*it)++;
731 rdpe_set (rad1, s->root[i]->drad);
732 mps_polynomial_dnewton (s, p, s->root[i], corr);
733 if (iter == 0 && !s->root[i]->again && rdpe_gt (s->root[i]->drad, rad1)
734 && rdpe_ne (rad1, rdpe_zero))
735 rdpe_set (s->root[i]->drad, rad1);
736 /************************************************
737 The above condition is needed to manage with the case where
738 at the first iteration the starting point is already in the
739 root neighbourhood and the actually computed radius is too
740 big since the value of the first derivative is too small.
741 In this case the previous radius bound, obtained by means of
742 Rouche' is more reliable and strict
743 **********************************************/
744
745 if (s->root[i]->again ||
746 /* the correction is performed only if iter!=1 or rad(i)!=rad1 */
747 iter != 0
748 || rdpe_ne (s->root[i]->drad, rad1))
749 {
750 mps_daberth (s, s->root[i], abcorr);
751 cdpe_mul_eq (abcorr, corr);
752 cdpe_sub (abcorr, cdpe_one, abcorr);
753 cdpe_div (abcorr, corr, abcorr);
754 cdpe_sub_eq (s->root[i]->dvalue, abcorr);
755 cdpe_mod (rtmp, abcorr);
756 rdpe_add_eq (s->root[i]->drad, rtmp);
757 }
758
759 /* check for new approximated roots */
760 if (!s->root[i]->again)
761 {
762 nzeros++;
763 if (nzeros == s->n)
764 return;
765 }
766 }
767 }
768 }
769 *excep = true;
770 }
771
772 /**
773 * @brief <code>dpe</code> version of <code>fsolve()</code>.
774 */
775 MPS_PRIVATE void
776 mps_dsolve (mps_context * s, mps_boolean d_after_f)
777 {
778 int it_pack, iter, nit, oldnclust, i, j, required_zeros = s->n;
779 mps_boolean excep;
780 mps_polynomial *p = s->active_poly;
781 rdpe_t * drad = rdpe_valloc (s->n);
782
783 if (s->DOLOG)
784 {
785 fprintf (s->logstr, " DSOLVE: d_after_f= %d\n", d_after_f);
786 }
787
788 /* == 1 == Initialize variables */
789 it_pack = 0;
790
791 if (d_after_f)
792 for (i = 0; i < s->n; i++)
793 if (s->root[i]->status == MPS_ROOT_STATUS_NOT_FLOAT)
794 {
795 s->root[i]->again = true;
796 rdpe_set_d (s->root[i]->drad, DBL_MAX);
797 }
798 else
799 s->root[i]->again = false;
800 else
801 {
802 mps_cluster_reset (s);
803 for (i = 0; i < s->n; i++)
804 {
805 s->root[i]->again = true;
806 rdpe_set_d (s->root[i]->drad, DBL_MAX);
807 cdpe_set (s->root[i]->dvalue, cdpe_zero);
808 }
809 }
810
811 /* Choose starting approximations */
812 if (s->DOLOG)
813 fprintf (s->logstr, " DSOLVE: call dstart with again=\n");
814
815 mps_polynomial_dstart (s, p, s->root);
816
817 /* Now adjust the status vector */
818 if (d_after_f)
819 for (i = 0; i < s->n; i++)
820 if (s->root[i]->status == MPS_ROOT_STATUS_NOT_FLOAT)
821 s->root[i]->status = MPS_ROOT_STATUS_CLUSTERED;
822
823 if (s->debug_level & MPS_DEBUG_APPROXIMATIONS)
824 mps_dump (s);
825
826 /* == 2 == Perform s->max_pack packets of Aberth's iterations */
827 if (s->DOLOG)
828 fprintf (s->logstr, " DSOLVE: call dpolzero\n");
829
830 for (iter = 0; iter < s->max_pack; iter++)
831 { /* dloop : DO iter=1,s->max_pack */
832 /* mps_dpolzer(s, &nit, &excep); */
833 mps_thread_dpolzer (s, &nit, &excep, required_zeros--);
834 it_pack += nit;
835
836 MPS_DEBUG (s, "DPE packet completed in %d iterations", nit);
837
838 if (s->DOLOG)
839 fprintf (s->logstr, "Packet %d iterations= %d\n", iter, nit);
840
841 if (excep)
842 {
843 oldnclust = s->clusterization->n;
844
845 /* cluster analysis */
846 if (s->DOLOG)
847 fprintf (s->logstr, " DSOLVE: call dcluster\n");
848
849 mps_dradii (s, s->active_poly, drad);
850 mps_dcluster (s, drad, 2 * s->n); /* Isolation factor */
851 if (oldnclust == s->clusterization->n)
852 {
853 if (s->DOLOG)
854 fprintf (s->logstr, " DSOLVE: CYCLE\n");
855 continue;
856 }
857 else
858 {
859 if (s->DOLOG)
860 fprintf (s->logstr, " DSOLVE: call dmodify\n");
861 mps_dmodify (s, true);
862
863 if (iter == 0 && !d_after_f)
864 for (i = 0; i < s->n; i++)
865 if (s->root[i]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
866 s->root[i]->status = MPS_ROOT_STATUS_CLUSTERED;
867
868 /* If the polynomial is not given in terms of its
869 * coeff. then skip the restart stage */
870 if (MPS_IS_MONOMIAL_POLY (s->active_poly))
871 {
872 /* choose new starting approximations only for new clusters */
873 if (s->DOLOG)
874 fprintf (s->logstr, " DSOLVE: call drestart\n");
875 mps_drestart (s);
876 }
877 /* reset the status vector */
878 for (j = 0; j < s->n; j++)
879 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
880 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
881 for (j = 0; j < s->n; j++)
882 s->again_old[j] = s->root[j]->again;
883
884 /* update 'again' */
885 if (s->DOLOG)
886 fprintf (s->logstr, " DSOLVE: call update\n");
887 mps_update (s);
888 /* adjust 'again'
889 * This is needed since we are between two packets
890 */
891 for (i = 0; i < s->n; i++)
892 if (!s->again_old[i])
893 s->root[i]->again = false;
894 if (s->DOLOG)
895 fprintf (s->logstr, " DSOLVE: call checkstop\n");
896 if (mps_check_stop (s))
897 goto dsolve_final_cleanup;
898 }
899 }
900 else
901 break;
902 }
903 if (iter == s->max_pack)
904 {
905 mps_dump (s);
906 mps_error (s,
907 "DPE: reached the maximum number of packet iterations");
908 }
909 /* Otherwise exit since all the approximations are
910 * in the root neighbourhood, except for the ones that cannot be
911 * represented as double.
912 */
913
914 if (s->DOLOG)
915 fprintf (s->logstr, "DPE: nit=%d\n", nit);
916
917 /* Update */
918 if (s->DOLOG)
919 fprintf (s->logstr, " DSOLVE: now update: call dcluster\n");
920 oldnclust = s->clusterization->n;
921
922 mps_dradii (s, s->active_poly, drad);
923 mps_dcluster (s, drad, 2 * s->n); /* Isolation factor */
924
925 if (s->DOLOG)
926 fprintf (s->logstr, " DSOLVE: now call dmodify\n");
927 mps_dmodify (s, true);
928
929 /* reset the status vector */
930 for (j = 0; j < s->n; j++)
931 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
932 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
933
934 dsolve_final_cleanup:
935 rdpe_vfree (drad);
936 }
937
938 /**
939 * @brief Multiprecision version of <code>fsolve()</code>.
940 */
941 MPS_PRIVATE void
942 mps_msolve (mps_context * s)
943 {
944 int iter, nit, oldnclust, i, j, it_pack, required_zeros = s->n;
945 mps_boolean excep;
946 int nzc;
947 rdpe_t * drad = rdpe_valloc (s->n);
948
949 /* == 1 == Initialize variables */
950 it_pack = 0;
951
952 if (s->DOLOG)
953 fprintf (s->logstr, " MSOLVE: call restart\n");
954 if (MPS_IS_MONOMIAL_POLY (s->active_poly))
955 mps_mrestart (s);
956 if (s->DOLOG)
957 fprintf (s->logstr, " MSOLVE: call update1\n");
958 mps_update (s);
959 if (s->DOLOG)
960 {
961 fprintf (s->logstr, " MSOLVE: again after update = ");
962 for (i = 0; i < s->n; i++)
963 fprintf (s->logstr, "%d", s->root[i]->again);
964 fprintf (s->logstr, "\n");
965 }
966
967 for (i = 0; i < s->n; i++)
968 if (s->root[i]->again)
969 s->root[i]->wp = s->mpwp;
970
971 if (s->DOLOG)
972 fprintf (s->logstr, " MSOLVE: call checkstop\n");
973 if (mps_check_stop (s))
974 {
975 oldnclust = s->clusterization->n;
976
977 mps_mmodify (s, true);
978
979 /* reset the status vector */
980 for (j = 0; j < s->n; j++)
981 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
982 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
983
984 goto msolve_final_cleanup;
985 }
986 nzc = 0;
987 if (s->output_config->search_set == MPS_SEARCH_SET_COMPLEX_PLANE &&
988 !s->output_config->multiplicity &&
989 !s->output_config->root_properties)
990 for (i = 0; i < s->n; i++)
991 if (MPS_ROOT_STATUS_IS_COMPUTED (s->root[i]->status))
992 nzc++;
993 if (s->DOLOG)
994 fprintf (s->logstr, " MSOLVE: nzc=%d\n", nzc);
995
996 if (nzc == s->n)
997 {
998 if (s->DOLOG)
999 fprintf (s->logstr, " MSOLVE: call mmodify and return\n");
1000 mps_mmodify (s, true);
1001
1002 /* reset the status vector */
1003 for (j = 0; j < s->n; j++)
1004 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
1005 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
1006
1007 goto msolve_final_cleanup;
1008 }
1009
1010 /* Perform s->max_pack packets of Aberth's iterations */
1011 if (s->DOLOG)
1012 fprintf (s->logstr, " MSOLVE: Perform packets of Aberth\n");
1013
1014 for (iter = 0; iter < s->max_pack; iter++)
1015 { /* mloop : DO iter=1,s->max_pack */
1016 if (s->DOLOG)
1017 {
1018 fprintf (s->logstr, " MSOLVE: packet= %d\n", iter);
1019 fprintf (s->logstr, " MSOLVE: again before mpolzer =");
1020 for (i = 0; i < s->n; i++)
1021 fprintf (s->logstr, "%d", s->root[i]->again);
1022 fprintf (s->logstr, "\n");
1023 fprintf (s->logstr, " MSOLVE: call mpolzer\n");
1024 }
1025 /* mps_mpolzer(s, &nit, &excep); */
1026 mps_thread_mpolzer (s, &nit, &excep, required_zeros--);
1027
1028 if (s->debug_level & MPS_DEBUG_APPROXIMATIONS)
1029 mps_dump (s);
1030
1031 if (s->DOLOG)
1032 fprintf (s->logstr, " MSOLVE: Packet %d: iterations= %d\n", iter, nit);
1033
1034 it_pack += nit;
1035 nzc = 0;
1036 if (s->output_config->search_set == MPS_SEARCH_SET_COMPLEX_PLANE &&
1037 !s->output_config->multiplicity &&
1038 !s->output_config->root_properties) /* DARIO APRILE 98 */
1039 for (i = 0; i < s->n; i++)
1040 if (MPS_ROOT_STATUS_IS_COMPUTED (s->root[i]->status))
1041 nzc++;
1042 if (s->DOLOG)
1043 fprintf (s->logstr, " MSOLVE: check again nzc=%d\n", nzc);
1044 if (nzc == s->n)
1045 {
1046 if (s->DOLOG)
1047 fprintf (s->logstr, " MSOLVE: call mmodify and return\n");
1048 mps_mmodify (s, true);
1049
1050 /* reset the status vector */
1051 for (j = 0; j < s->n; j++)
1052 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
1053 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
1054 if (s->DOLOG)
1055 {
1056 MPS_DEBUG (s, "Dumping status");
1057 for (j = 0; j < s->n; j++)
1058 MPS_DEBUG (s, " %4d: %s", j,
1059 MPS_ROOT_STATUS_TO_STRING (s->root[j]->status));
1060 }
1061
1062 goto msolve_final_cleanup;
1063 }
1064
1065 if (s->DOLOG)
1066 fprintf (s->logstr, " MSOLVE: isolated %d roots excep=%d\n", nzc,
1067 excep);
1068
1069 if (excep)
1070 {
1071 oldnclust = s->clusterization->n;
1072
1073 /* cluster analysis */
1074 if (s->DOLOG)
1075 fprintf (s->logstr, " MSOLVE: call mcluster\n");
1076
1077 mps_mradii (s, s->active_poly, drad);
1078 mps_mcluster (s, drad, 2 * s->n); /* Isolation factor */
1079
1080 s->newtis_old = s->newtis;
1081 if (s->newtis == 0)
1082 mps_mnewtis (s);
1083 if (s->DOLOG)
1084 fprintf (s->logstr,
1085 " MSOLVE: newtis_old=%d, newtis=%d, oldncl=%d, s->nclust=%ld\n",
1086 s->newtis_old, s->newtis, oldnclust, s->clusterization->n);
1087
1088 if (oldnclust == s->clusterization->n && !(s->newtis == 1 && s->newtis_old == 0))
1089 /*# if(&& iter != 0) AGO99 */
1090 {
1091 /*#D !newtis */
1092 if (s->DOLOG)
1093 fprintf (s->logstr, " MSOLVE: CYCLE\n");
1094 continue;
1095 }
1096 else
1097 {
1098 if (s->DOLOG)
1099 fprintf (s->logstr, " MSOLVE: call modify\n");
1100 mps_mmodify (s, true);
1101 if (iter == 0)
1102 /* if first packet: reset the status vector */
1103 for (j = 0; j < s->n; j++)
1104 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
1105 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
1106 if (s->DOLOG)
1107 {
1108 MPS_DEBUG (s, "Dumping status");
1109 for (j = 0; j < s->n; j++)
1110 MPS_DEBUG (s, " %4d: %s", j,
1111 MPS_ROOT_STATUS_TO_STRING (s->root[j]->status));
1112 }
1113 /* If the polynomial is not given in terms of its coeff. then
1114 * skip the restart stage */
1115 if (MPS_IS_MONOMIAL_POLY (s->active_poly))
1116 {
1117 /* choose new starting approximations only for new clusters */
1118 if (s->DOLOG)
1119 fprintf (s->logstr,
1120 " MSOLVE: call mrestart for new clusters\n");
1121 mps_mrestart (s);
1122 }
1123 /* reset the s->status vector */
1124 for (j = 0; j < s->n; j++)
1125 {
1126 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
1127 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
1128 s->again_old[j] = s->root[j]->again;
1129 }
1130 /* update 'again' */
1131 if (s->DOLOG)
1132 fprintf (s->logstr, " MSOLVE: call update2 : ");
1133 mps_update (s);
1134 if (s->DOLOG)
1135 {
1136 fprintf (s->logstr, " MSOLVE: again = ");
1137 for (j = 0; j < s->n; j++)
1138 fprintf (s->logstr, "%d", s->root[j]->again);
1139 fprintf (s->logstr, "\n");
1140 }
1141 /* adjust 'again' This is needed since we are between two packets */
1142 for (i = 0; i < s->n; i++)
1143 if (!s->again_old[i])
1144 s->root[i]->again = false;
1145 if (s->DOLOG)
1146 {
1147 fprintf (s->logstr, " MSOLVE: adjusted again = ");
1148 for (j = 0; j < s->n; j++)
1149 fprintf (s->logstr, "%d", s->root[j]->again);
1150 fprintf (s->logstr, "\n");
1151 }
1152 if (s->DOLOG)
1153 fprintf (s->logstr, " MSOLVE: call checkstop\n");
1154 if (mps_check_stop (s))
1155 {
1156 mps_mmodify (s, true);
1157
1158 /* reset the s->status vector */
1159 for (j = 0; j < s->n; j++)
1160 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
1161 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
1162
1163 goto msolve_final_cleanup;
1164 }
1165
1166 nzc = 0;
1167 if (s->output_config->search_set == MPS_SEARCH_SET_COMPLEX_PLANE &&
1168 s->output_config->multiplicity &&
1169 !s->output_config->root_properties)
1170 for (i = 0; i < s->n; i++)
1171 if (MPS_ROOT_STATUS_IS_COMPUTED (s->root[i]->status))
1172 nzc++;
1173 if (s->DOLOG)
1174 fprintf (s->logstr, " MSOLVE: check again nzc=%d\n", nzc);
1175 if (nzc == s->n)
1176 {
1177 if (s->DOLOG)
1178 fprintf (s->logstr, " MSOLVE: call mmodify and return");
1179 mps_mmodify (s, true);
1180
1181 /* reset the s->status vector */
1182 for (j = 0; j < s->n; j++)
1183 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
1184 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
1185
1186 goto msolve_final_cleanup;
1187 }
1188 }
1189 }
1190 else
1191 break;
1192 }
1193
1194 if (iter == s->max_pack)
1195 {
1196 mps_error (s, "MP: reached the maximum number of packet iteration");
1197 }
1198
1199 if (s->DOLOG)
1200 {
1201 fprintf (s->logstr, " MSOLVE: MP: nit= %d\n", nit);
1202 fprintf (s->logstr, " MSOLVE: call mcluster\n");
1203 }
1204
1205 mps_mradii (s, s->active_poly, drad);
1206 mps_mcluster (s, drad, 2 * s->n); /* Isolation factor */
1207
1208 if (s->DOLOG)
1209 fprintf (s->logstr, " MSOLVE: call mmodify\n");
1210
1211 oldnclust = s->clusterization->n;
1212
1213 mps_mmodify (s, true);
1214
1215 for (j = 0; j < s->n; j++)
1216 if (s->root[j]->status == MPS_ROOT_STATUS_NEW_CLUSTERED)
1217 s->root[j]->status = MPS_ROOT_STATUS_CLUSTERED;
1218
1219 if (s->DOLOG)
1220 {
1221 MPS_DEBUG (s, "Dumping status: ");
1222 for (j = 0; j < s->n; j++)
1223 MPS_DEBUG (s, " %4d: %s", j,
1224 MPS_ROOT_STATUS_TO_STRING (s->root[j]->status));
1225 }
1226 mps_update (s);
1227
1228 if (s->DOLOG)
1229 {
1230 for (j = 0; j < s->n; j++)
1231 fprintf (s->logstr, "%d", s->root[j]->again);
1232 fprintf (s->logstr, "\n");
1233 }
1234
1235 msolve_final_cleanup:
1236 rdpe_vfree (drad);
1237 }
1238
1239 /**
1240 * @brief Multiprecision versione of <code>fpolzer()</code>.
1241 */
1242 MPS_PRIVATE void
1243 mps_mpolzer (mps_context * s, int *it, mps_boolean * excep)
1244 {
1245 int nzeros, i, iter, l;
1246 mpc_t corr, abcorr;
1247 rdpe_t eps, rad1, rtmp;
1248 cdpe_t ctmp;
1249 mps_polynomial *p = s->active_poly;
1250
1251 mpc_init2 (abcorr, s->mpwp);
1252 mpc_init2 (corr, s->mpwp);
1253
1254 rdpe_mul_d (eps, s->mp_epsilon, (double)4 * s->n);
1255
1256 /* initialize the iteration counter */
1257 *it = 0;
1258 *excep = false;
1259
1260 /* count the number of approximations in the root neighbourhood */
1261 nzeros = 0;
1262 for (i = 0; i < s->n; i++)
1263 if (!s->root[i]->again)
1264 nzeros++;
1265 if (nzeros == s->n)
1266 goto endfun;
1267
1268 mps_cluster_item * c_item;
1269 mps_cluster * cluster;
1270 mps_root * root;
1271
1272 /* Start Aberth's iterations */
1273 for (iter = 0; iter < s->max_it; iter++)
1274 { /* do_iter: */
1275 for (c_item = s->clusterization->first; c_item != NULL; c_item = c_item->next)
1276 { /* do_clust: */
1277 cluster = c_item->cluster;
1278 for (root = cluster->first; root != NULL; root = root->next)
1279 { /* do_indice: */
1280 l = root->k;
1281
1282 MPS_DEBUG (s, "Iterating on root %d, iter %d", l, iter);
1283
1284 if (s->root[l]->again)
1285 {
1286 (*it)++;
1287 /* sparse/dense polynomial */
1288 rdpe_set (rad1, s->root[l]->drad);
1289 mps_polynomial_mnewton (s, p, s->root[l], corr, s->mpwp);
1290 if (iter == 0 && !s->root[l]->again && rdpe_gt (s->root[l]->drad,
1291 rad1)
1292 && rdpe_ne (rad1, rdpe_zero))
1293 rdpe_set (s->root[l]->drad, rad1);
1294
1295 /************************************************
1296 The above condition is needed to cope with the case
1297 where at the first iteration the starting point is
1298 already in the root neighbourhood and the actually
1299 computed radius is too big since the value of the
1300 first derivative is too small.
1301 In this case the previous radius bound, obtained by
1302 means of Rouche' is more reliable and strict
1303 ***********************************************/
1304
1305 if (s->root[l]->again ||
1306 /* the correction is performed only if iter!=1 or rad[l]!=rad1 */
1307 iter != 0
1308 || rdpe_ne (s->root[l]->drad, rad1))
1309 {
1310 mps_maberth_s (s, s->root[l], cluster, abcorr);
1311 mpc_mul_eq (abcorr, corr);
1312 mpc_neg_eq (abcorr);
1313 mpc_add_eq_ui (abcorr, 1, 0);
1314 mpc_div (abcorr, corr, abcorr);
1315 mpc_sub_eq (s->root[l]->mvalue, abcorr);
1316 mpc_get_cdpe (ctmp, abcorr);
1317 cdpe_mod (rtmp, ctmp);
1318 rdpe_add_eq (s->root[l]->drad, rtmp);
1319 }
1320
1321 /* check for new approximated roots */
1322 if (!s->root[l]->again)
1323 {
1324 nzeros++;
1325 if (nzeros == s->n)
1326 goto endfun;
1327 }
1328
1329 MPS_DEBUG_MPC (s, 15, s->root[l]->mvalue, "s->mroot[%d]", l);
1330 MPS_DEBUG_RDPE (s, s->root[l]->drad, "s->drad[%d]", l);
1331 }
1332 }
1333 }
1334 if (nzeros == s->n)
1335 goto endfun;
1336 }
1337 *excep = true;
1338
1339 endfun: /* free local MP variables */
1340 mpc_clear (corr);
1341 mpc_clear (abcorr);
1342 }