nsimplify(e) replaces a number, or the floating point numbers in an
expression, by a simple exact form, as SymPy's nsimplify(): the value
is evaluated to 30 digits and identified (with mpmath's identify()) as
a rational, a quadratic irrational, or a simple formula in the given
constants; otherwise its Floats become rationals.
Usage
nsimplify(
e,
constants = list(),
tolerance = NULL,
full = FALSE,
rational = NULL,
rational_conversion = "base10"
)Arguments
- e
A number or expression.
- constants
A list of constants (such as
sym_pi) to try.- tolerance
The tolerance of the identification, or
NULLfor10^-dwithdthe smallest precision (at most 15 digits) of the Floats ine; withrational = TRUE, the tolerance of the rational approximation.- full
Try harder, returning the shortest formula found.
- rational
TRUEconverts the Floats to rationals only;FALSEreturns the identified value oreitself;NULLfalls back to rationals when no formula is found.- rational_conversion
"base10"converts a Float through its decimal digits,"exact"through its exact binary value.
Examples
nsimplify(0.333333333333)
#> 1/3
nsimplify(1.414213562373095)
#> sqrt(2)
nsimplify(6.283185307179586, constants = list(sym_pi))
#> 2*pi
nsimplify(sym_pi, tolerance = 0.01)
#> 22/7