fmprb.h – real numbers represented as floating-point balls¶
This type is now obsolete: use arb_t
instead.
An fmprb_t
represents a ball over the real numbers.
Types, macros and constants¶
-
fmprb_struct
¶
-
fmprb_t
¶ An fmprb_struct consists of a pair of fmpr_struct:s. An fmprb_t is defined as an array of length one of type fmprb_struct, permitting an fmprb_t to be passed by reference.
-
fmprb_ptr
¶ Alias for
fmprb_struct *
, used for vectors of numbers.
-
fmprb_srcptr
¶ Alias for
const fmprb_struct *
, used for vectors of numbers when passed as constant input to functions.
-
FMPRB_RAD_PREC
¶ The precision used for operations on the radius. This is small enough to fit in a single word, currently 30 bits.
-
fmprb_midref
(x)¶ Macro returning a pointer to the midpoint of x as an fmpr_t.
-
fmprb_radref
(x)¶ Macro returning a pointer to the radius of x as an fmpr_t.
Memory management¶
Assignment and rounding¶
-
void
fmprb_set_round
(fmprb_t y, const fmprb_t x, slong prec)¶ Sets y to a copy of x, rounded to prec bits.
-
void
fmprb_set_fmpq
(fmprb_t y, const fmpq_t x, slong prec)¶ Sets y to the rational number x, rounded to prec bits.
Assignment of special values¶
Input and output¶
Random number generation¶
-
void
fmprb_randtest
(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits)¶ Generates a random ball. The midpoint and radius will both be finite.
-
void
fmprb_randtest_exact
(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits)¶ Generates a random number with zero radius.
-
void
fmprb_randtest_precise
(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits)¶ Generates a random number with radius at most \(2^{-\mathrm{prec}}\) the magnitude of the midpoint.
-
void
fmprb_randtest_wide
(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits)¶ Generates a random number with midpoint and radius chosen independently, possibly giving a very large interval.
-
void
fmprb_randtest_special
(fmprb_t x, flint_rand_t state, slong prec, slong mag_bits)¶ Generates a random interval, possibly having NaN or an infinity as the midpoint and possibly having an infinite radius.
-
void
fmprb_get_rand_fmpq
(fmpq_t q, flint_rand_t state, const fmprb_t x, slong bits)¶ Sets q to a random rational number from the interval represented by x. A denominator is chosen by multiplying the binary denominator of x by a random integer up to bits bits.
The outcome is undefined if the midpoint or radius of x is non-finite, or if the exponent of the midpoint or radius is so large or small that representing the endpoints as exact rational numbers would cause overflows.
Radius and interval operations¶
-
void
fmprb_add_error_fmpr
(fmprb_t x, const fmpr_t err)¶ Adds err, which is assumed to be nonnegative, to the radius of x.
-
void
fmprb_add_error
(fmprb_t x, const fmprb_t err)¶ Adds the supremum of err, which is assumed to be nonnegative, to the radius of x.
-
void
fmprb_union
(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec)¶ Sets z to a ball containing both x and y.
-
void
fmprb_get_abs_ubound_fmpr
(fmpr_t u, const fmprb_t x, slong prec)¶ Sets u to the upper bound of the absolute value of x, rounded up to prec bits. If x contains NaN, the result is NaN.
-
void
fmprb_get_abs_lbound_fmpr
(fmpr_t u, const fmprb_t x, slong prec)¶ Sets u to the lower bound of the absolute value of x, rounded down to prec bits. If x contains NaN, the result is NaN.
-
void
fmprb_get_interval_fmpz_2exp
(fmpz_t a, fmpz_t b, fmpz_t exp, const fmprb_t x)¶ Computes the exact interval represented by x, in the form of an integer interval multiplied by a power of two, i.e. \(x = [a, b] \times 2^{\mathrm{exp}}\).
The outcome is undefined if the midpoint or radius of x is non-finite, or if the difference in magnitude between the midpoint and radius is so large that representing the endpoints exactly would cause overflows.
-
void
fmprb_set_interval_fmpr
(fmprb_t x, const fmpr_t a, const fmpr_t b, slong prec)¶ Sets x to a ball containing the interval \([a, b]\). We require that \(a \le b\).
-
slong
fmprb_rel_error_bits
(const fmprb_t x)¶ Returns the effective relative error of x measured in bits, defined as the difference between the position of the top bit in the radius and the top bit in the midpoint, plus one. The result is clamped between plus/minus FMPR_PREC_EXACT.
-
slong
fmprb_rel_accuracy_bits
(const fmprb_t x)¶ Returns the effective relative accuracy of x measured in bits, equal to the negative of the return value from fmprb_rel_error_bits.
-
slong
fmprb_bits
(const fmprb_t x)¶ Returns the number of bits needed to represent the absolute value of the mantissa of the midpoint of x, i.e. the minimum precision sufficient to represent x exactly. Returns 0 if the midpoint of x is a special value.
Comparisons¶
-
int
fmprb_is_nonzero
(const fmprb_t x)¶ Returns nonzero iff zero is not contained in the interval represented by x.
-
int
fmprb_is_finite
(fmprb_t x)¶ Returns nonzero iff the midpoint and radius of x are both finite floating-point numbers, i.e. not infinities or NaN.
-
int
fmprb_equal
(const fmprb_t x, const fmprb_t y)¶ Returns nonzero iff x and y are equal as balls, i.e. have both the same midpoint and radius.
Note that this is not the same thing as testing whether both x and y certainly represent the same real number, unless either x or y is exact (and neither contains NaN). To test whether both operands might represent the same mathematical quantity, use
fmprb_overlaps()
orfmprb_contains()
, depending on the circumstance.
-
int
fmprb_is_nonpositive
(const fmprb_t x)¶ Returns nonzero iff all points p in the interval represented by x satisfy, respectively, \(p > 0\), \(p \ge 0\), \(p < 0\), \(p \le 0\). If x contains NaN, returns zero.
-
int
fmprb_overlaps
(const fmprb_t x, const fmprb_t y)¶ Returns nonzero iff x and y have some point in common. If either x or y contains NaN, this function always returns nonzero (as a NaN could be anything, it could in particular contain any number that is included in the other operand).
-
int
fmprb_contains
(const fmprb_t x, const fmprb_t y)¶ Returns nonzero iff the given number (or ball) y is contained in the interval represented by x.
If x is contains NaN, this function always returns nonzero (as it could represent anything, and in particular could represent all the points included in y). If y contains NaN and x does not, it always returns zero.
Arithmetic¶
-
void
fmprb_abs
(fmprb_t y, const fmprb_t x)¶ Sets y to the absolute value of x. No attempt is made to improve the interval represented by x if it contains zero.
-
void
fmprb_add_fmpr
(fmprb_t z, const fmprb_t x, const fmpr_t y, slong prec)¶ Sets \(z = x + y\), rounded to prec bits. The precision can be FMPR_PREC_EXACT provided that the result fits in memory.
-
void
fmprb_sub_fmpz
(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec)¶ Sets \(z = x - y\), rounded to prec bits. The precision can be FMPR_PREC_EXACT provided that the result fits in memory.
-
void
fmprb_mul_fmpz
(fmprb_t z, const fmprb_t x, const fmpz_t y, slong prec)¶ Sets \(z = x \times y\), rounded to prec bits. The precision can be FMPR_PREC_EXACT provided that the result fits in memory.
-
void
fmprb_mul_2exp_fmpz
(fmprb_t y, const fmprb_t x, const fmpz_t e)¶ Sets y to x multiplied by \(2^e\).
-
void
fmprb_ui_div
(fmprb_t z, ulong x, const fmprb_t y, slong prec)¶ Sets \(z = x / y\), rounded to prec bits. If y contains zero, z is set to \(0 \pm \infty\). Otherwise, error propagation uses the rule
\[\left| \frac{x}{y} - \frac{x+\xi_1 a}{y+\xi_2 b} \right| = \left|\frac{x \xi_2 b - y \xi_1 a}{y (y+\xi_2 b)}\right| \le \frac{|xb|+|ya|}{|y| (|y|-b)}\]where \(-1 \le \xi_1, \xi_2 \le 1\), and where the triangle inequality has been applied to the numerator and the reverse triangle inequality has been applied to the denominator.
Powers and roots¶
-
void
fmprb_sqrt_fmpz
(fmprb_t z, const fmpz_t x, slong prec)¶ Sets z to the square root of x, rounded to prec bits. Error propagation is done using the following rule: assuming \(m > r \ge 0\), the error is largest at \(m - r\), and we have \(\sqrt{m} - \sqrt{m-r} \le r / (2 \sqrt{m-r})\).
-
void
fmprb_sqrtpos
(fmprb_t z, const fmprb_t x, slong prec)¶ Sets z to the square root of x, assuming that x represents a nonnegative number (i.e. discarding any negative numbers in the input interval), and producing an output interval not containing any negative numbers (unless the radius is infinite).
-
void
fmprb_hypot
(fmprb_t z, const fmprb_t x, const fmprb_t y, slong prec)¶ Sets z to \(\sqrt{x^2 + y^2}\).
-
void
fmprb_rsqrt_ui
(fmprb_t z, ulong x, slong prec)¶ Sets z to the reciprocal square root of x, rounded to prec bits. At high precision, this is faster than computing a square root.