This module provides functions for operations of calculus over the real numbers (intended to include root-finding, optimization, integration, and so on). It is planned that the module will include two types of algorithms:
Any algorithms of the second kind will be clearly marked as such.
Typedef for a pointer to a function with signature:
int func(fmprb_ptr out, const fmprb_t inp, void * param, long order, long prec)
implementing a univariate real function \(f(x)\). When called, func should write to out the first order coefficients in the Taylor series expansion of \(f(x)\) at the point inp, evaluated at a precision of prec bits. The param argument may be used to pass through additional parameters to the function. The return value is reserved for future use as an error code. It can be assumed that out and inp are not aliased and that order is positive.
Return value indicating that an operation is successful.
Return value indicating that the input to a function probably needs to be computed more accurately.
Return value indicating that an algorithm has failed to convergence, possibly due to the problem not having a solution, the algorithm not being applicable, or the precision being insufficient
If set, enables printing information about the calculation to standard output.
Rigorously isolates single roots of a real analytic function on the interior of an interval.
This routine writes an array of n interesting subintervals of interval to found and corresponding flags to flags, returning the integer n. The output has the following properties:
If no flags other than 1 occur, all roots of the function on interval have been isolated. If there are output subintervals on which the existence or nonexistence of roots could not be determined, the user may attempt further searches on those subintervals (possibly with increased precision and/or increased bounds for the breaking criteria). Note that roots of multiplicity higher than one and roots located exactly at endpoints cannot be isolated by the algorithm.
The following breaking criteria are implemented:
The argument prec denotes the precision used to evaluate the function. It is possibly also used for some other arithmetic operations performed internally by the algorithm. Note that it probably does not make sense for maxdepth to exceed prec.
Warning: it is assumed that subdivision points of interval can be represented exactly as floating-point numbers in memory. Do not pass \(1 \pm 2^{-10^{100}}\) as input.
Given an interval start known to contain a single root of func, refines it using iter bisection steps. The algorithm can return a failure code if the sign of the function at an evaluation point is ambiguous. The output r is set to a valid isolating interval (possibly just start) even if the algorithm fails.
Given an interval \(I\) specified by conv_region, evaluates a bound for \(C = \sup_{t,u \in I} \frac{1}{2} |f''(t)| / |f'(u)|\), where \(f\) is the function specified by func and param. The bound is obtained by evaluating \(f'(I)\) and \(f''(I)\) directly. If \(f\) is ill-conditioned, \(I\) may need to be extremely precise in order to get an effective, finite bound for C.
Performs a single step with an interval version of Newton’s method. The input consists of the function \(f\) specified by func and param, a ball \(x = [m-r, m+r]\) known to contain a single root of \(f\), a ball \(I\) (conv_region) containing \(x\) with an associated bound (conv_factor) for \(C = \sup_{t,u \in I} \frac{1}{2} |f''(t)| / |f'(u)|\), and a working precision prec.
The Newton update consists of setting \(x' = [m'-r', m'+r']\) where \(m' = m - f(m) / f'(m)\) and \(r' = C r^2\). The expression \(m - f(m) / f'(m)\) is evaluated using ball arithmetic at a working precision of prec bits, and the rounding error during this evaluation is accounted for in the output. We now check that \(x' \in I\) and \(r' < r\). If both conditions are satisfied, we set xnew to \(x'\) and return FMPRB_CALC_SUCCESS. If either condition fails, we set xnew to \(x\) and return FMPRB_CALC_NO_CONVERGENCE, indicating that no progress is made.
Refines a precise estimate of a single root of a function to high precision by performing several Newton steps, using nearly optimally chosen doubling precision steps.
The inputs are defined as for fmprb_calc_newton_step, except for the precision parameters: prec is the target accuracy and eval_extra_prec is the estimated number of guard bits that need to be added to evaluate the function accurately close to the root (for example, if the function is a polynomial with large coefficients of alternating signs and Horner’s rule is used to evaluate it, the extra precision should typically be approximately the bit size of the coefficients).
This function returns FMPRB_CALC_SUCCESS if all attempted Newton steps are successful (note that this does not guarantee that the computed root is accurate to prec bits, which has to be verified by the user), only that it is more accurate than the starting ball.
On failure, FMPRB_CALC_IMPRECISE_INPUT or FMPRB_CALC_NO_CONVERGENCE may be returned. In this case, r is set to a ball for the root which is valid but likely does have full accuracy (it can possibly just be equal to the starting ball).