FLINT3.7.0-dev

mp_real_root_ui, mp_real_rroot_ui, _mp_real_root_ui_order

Synopsis#include <flint/mp_real.h>
void mp_real_root_ui(mp_real_t res, const mp_real_t x, ulong k, slong n)source
void mp_real_rroot_ui(mp_real_t res, const mp_real_t x, ulong k, slong n)source
void _mp_real_root_ui_order(mp_real_t res, const mp_real_t x, ulong k, slong n, int r, int recip)source

Set res to x^{1/k} resp. x^{-1/k} for x > 0 and 1 \le k < MP_REAL_ROOT_K_MAX. They throw for k = 0, for x not positive (the third function for k < 2 as well). The third function takes the order r of the iteration (2 \le r \le 15, or 0 for the default) and recip = 1 for the reciprocal root.

For k = 1 the result is x resp. 1/x, and for k = 2 these call mp_real_sqrt and mp_real_rsqrt. Otherwise one step of order r of a binomial-series iteration is taken from an approximation z of x^{-1/k} accurate to about 1/r of the precision, obtained recursively (the recursion starts from a double):

x^{-1/k} = z (1 - u)^{-1/k}, \qquad x^{1/k} = x z^{k-1} (1 - u)^{-(k-1)/k}, \qquad u = 1 - x z^k,

with the series (1 - u)^{-b} = \sum_j c_j u^j truncated after u^{r-1} and its tail, below 2 c_r |u|^r for |u| \le 1/2, added to the radius. The series is summed over a common denominator of the c_j, so that it costs one division by an integer; the coefficient tables are cached per thread. The default order is 3 for k < 8 and 4 otherwise. Only the size of the final u is computed rigorously, so the radius of the recursive approximation is discarded.

Cite this page

The FLINT team, “mp_real_root_ui, mp_real_rroot_ui, _mp_real_root_ui_order (mp_real.h),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/mp_real/mp_real_root_ui.html (generated 2026-10-20).