N
A numeric value of x -- to d significant digits, every one of them right.
N!N(x)x at the engine's working precision.enumeratio_n(x)SymPyN(x, 30)Rustnf(x)N(x, d)x to exactly d significant digits, the last one correctly rounded.enumeratio_n(x, d)SymPyN(x, 30)mpmathenumeratio_n(lambda: (x), d)Juliaenumeratio_nshow(x, d)Rustnf(x)Typed signatures
| Type | Package | Applies |
|---|---|---|
(any, (integer | list<number>)?) -> unknown | analyticreplaces compute-engine | always |
(any, (integer | list<number>)?) -> unknown | compute-engine | always |
Details
- evaluates x at digits and again at , rounds both to d, and answers when they agree; when they don't, the value lies near a rounding boundary, and the guard doubles until they do (Ziv's loop). Agreement across precisions is strong evidence rather than a proof.
- Some heads prove their digits instead: Zeta, HurwitzZeta, LerchPhi, PolyLog and StieltjesGamma, on exact real arguments (integers, rationals, decimals). Their kernels bound their own error and return an enclosure, a ball that provably holds the value. When both ends of it round to the same d digits, those digits are certain; when they don't, the working precision rises, with no appeal to agreement. The enclosure travels with the answer (
enclosureOfin@enumeratio/analytic). An argument like arrives already rounded, by an evaluation that bounds nothing, so such a call takes the agreement path. - The answer carries exactly d significant digits, never more, and the working precision is left as it was: a later evaluation runs at the precision it would have anyway.
- A value exactly halfway between two d-digit answers -- only a terminating decimal, like -- rounds to the even one.
- A list, or a symbolic result, is rounded number by number; integers in it are left alone.
- A head that computes in machine doubles, whatever precision is asked of it, can't be measured more finely: up to 15 digits its double is rounded like any other value; past that it comes back as that double, with the digits it has rather than the d asked for.
Examples
2 more kept as data, checked against the oraclesScope #
Possible issues #
The accuracy-goal form N(x, [20, PositiveInfinity]) keeps the digits that plain N(x, 20) cancels to 0.0, in the row above
live ↗About
| Examples | 38 |
|---|---|
| Checked against | Wolfram Language 34 agree4 differSageMath 36 agree1 unevaluatedSymPy 31 agree4 differ1 errormpmath 20 agree3 differJulia 20 agree2 differ1 errorRust 9 agree4 differ4 errorOscar 2 differ |
| Crosswalk | Wolfram LanguageSageMath ×2SymPy ×2mpmathJuliaRust ×2 |
Implementation
sympypackages/oracle/src/mappings.tsmpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.
mpmathpackages/oracle/src/mappings.tsmpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.
sagepackages/oracle/src/mappings.tsmpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.
oscarpackages/oracle/src/mappings.tsmpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.
juliapackages/oracle/src/mappings.tsmpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.
rustpackages/oracle/src/mappings.tsmpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.
sympypackages/oracle/src/mappings.tsThe digit count is dropped: lanes compare numbers to a relative tolerance, so the full-precision value is the better witness.
mpmathpackages/oracle/src/mappings.tsPast a double's 15 digits the operand runs at the requested precision (plus 20 guard digits) and the answer is rounded to it; below, the digit count is dropped.
sagepackages/oracle/src/mappings.tsThe digit count only sets the starting precision, and the value is evaluated until stable: lanes compare numbers to a relative tolerance, so the full-precision value is the better witness.
oscarpackages/oracle/src/mappings.tsThe digit count is dropped: lanes compare numbers to a relative tolerance, so the full-precision value is the better witness.
juliapackages/oracle/src/mappings.tsN(x, d) as the answer is written out to d significant digits, ties to the even digit (Wolfram shows N[1/8, 2] as 0.12), so the scan compares digit for digit; below another call it is the rounded number.
rustpackages/oracle/src/mappings.tsThe digit count is dropped: lanes compare numbers to a relative tolerance, so the full-precision value is the better witness.