2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2014-06-19 15:43:48 +02:00
|
|
|
Copyright (C) 2013 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-06-19 15:43:48 +02:00
|
|
|
|
|
|
|
#include "arb_calc.h"
|
|
|
|
|
|
|
|
int arb_calc_refine_root_newton(arb_t r, arb_calc_func_t func,
|
|
|
|
void * param, const arb_t start, const arb_t conv_region,
|
2015-11-05 17:56:52 +00:00
|
|
|
const arf_t conv_factor, slong eval_extra_prec, slong prec)
|
2014-06-19 15:43:48 +02:00
|
|
|
{
|
2015-11-05 17:56:52 +00:00
|
|
|
slong precs[FLINT_BITS];
|
|
|
|
slong i, iters, wp, padding, start_prec;
|
2014-06-19 15:43:48 +02:00
|
|
|
int result;
|
|
|
|
|
|
|
|
start_prec = arb_rel_accuracy_bits(start);
|
|
|
|
|
|
|
|
if (arb_calc_verbose)
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("newton initial accuracy: %wd\n", start_prec);
|
2014-06-19 15:43:48 +02:00
|
|
|
|
|
|
|
padding = arf_abs_bound_lt_2exp_si(conv_factor);
|
|
|
|
padding = FLINT_MIN(padding, prec) + 5;
|
|
|
|
padding = FLINT_MAX(0, padding);
|
|
|
|
|
|
|
|
precs[0] = prec + padding;
|
|
|
|
iters = 1;
|
|
|
|
while ((iters < FLINT_BITS) && (precs[iters-1] + padding > 2*start_prec))
|
|
|
|
{
|
|
|
|
precs[iters] = (precs[iters-1] / 2) + padding;
|
|
|
|
iters++;
|
|
|
|
|
|
|
|
if (iters == FLINT_BITS)
|
|
|
|
{
|
|
|
|
return ARB_CALC_IMPRECISE_INPUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
arb_set(r, start);
|
|
|
|
|
|
|
|
for (i = iters - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
wp = precs[i] + eval_extra_prec;
|
|
|
|
|
|
|
|
if (arb_calc_verbose)
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("newton step: wp = %wd + %wd = %wd\n",
|
2014-06-19 15:43:48 +02:00
|
|
|
precs[i], eval_extra_prec, wp);
|
|
|
|
|
|
|
|
if ((result = arb_calc_newton_step(r, func, param,
|
|
|
|
r, conv_region, conv_factor, wp)) != ARB_CALC_SUCCESS)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ARB_CALC_SUCCESS;
|
|
|
|
}
|
|
|
|
|