Skip to content

N ​

A numeric value of x -- to d significant digits, every one of them right.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageN!
N(x)x at the engine's working precision.
SageMathenumeratio_n(x)SymPyN(x, 30)Rustnf(x)
N(x, d)x to exactly d significant digits, the last one correctly rounded.
SageMathenumeratio_n(x, d)SymPyN(x, 30)mpmathenumeratio_n(lambda: (x), d)Juliaenumeratio_nshow(x, d)Rustnf(x)
Typed signatures
TypePackageApplies
(any, (integer | list<number>)?) -> unknownanalyticreplaces compute-enginealways
(any, (integer | list<number>)?) -> unknowncompute-enginealways

Domain: Arithmetic

Details
  • N(x,d)\mathrm{N}(x, d) evaluates x at d+20d + 20 digits and again at d+10d + 10, 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 (enclosureOf in @enumeratio/analytic). An argument like 2\sqrt 2 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 1/81/8 -- 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 oracles
Basic #
live ↗
InN(π,30)N(π, 30)Out3.141 592 653 589 793 238 462 643 383 283.141\,592\,653\,589\,793\,238\,462\,643\,383\,28

The last digit correctly rounded: computing at 30 digits alone gives …059

live ↗
InN(sinh⁡(1),30)N(\sinh(1), 30)Out1.175 201 193 643 801 456 882 381 850 61.175\,201\,193\,643\,801\,456\,882\,381\,850\,6

A list, number by number

live ↗
InN([π,e,2],5)N(\bigl\lbrack π, e, \sqrt{2}\bigr\rbrack, 5)Out[3.141 6,2.718 3,1.414 2]\bigl\lbrack3.141\,6, 2.718\,3, 1.414\,2\bigr\rbrack

An exact rational at the default precision

live ↗
InN(17)N(\frac{1}{7})Out0.142 857 142 857 142 857 1430.142\,857\,142\,857\,142\,857\,143

A fifty-digit approximation of 17\frac17

live ↗
InN(17,50)N(\frac{1}{7}, 50)Out0.142 857 142 857 142 857 142 857 142 857 142 857 142 857 142 857 140.142\,857\,142\,857\,142\,857\,142\,857\,142\,857\,142\,857\,142\,857\,142\,857\,14

Γ(3.3)\Gamma(3.3) to 50 digits

live ↗
InN(Γ(3310),50)N(Γ(\frac{33}{10}), 50)Out2.683 437 381 955 768 793 596 327 314 766 711 258 628 187 004 354 82.683\,437\,381\,955\,768\,793\,596\,327\,314\,766\,711\,258\,628\,187\,004\,354\,8
Scope #

π\pi to 50 digits

live ↗
InN(π,50)N(π, 50)Out3.141 592 653 589 793 238 462 643 383 279 502 884 197 169 399 375 13.141\,592\,653\,589\,793\,238\,462\,643\,383\,279\,502\,884\,197\,169\,399\,375\,1

Khinchin's constant to 50 digits

live ↗
InN(Khinchin,50)N(\mathrm{Khinchin}, 50)Out2.685 452 001 065 306 445 309 714 835 481 795 693 820 382 293 994 52.685\,452\,001\,065\,306\,445\,309\,714\,835\,481\,795\,693\,820\,382\,293\,994\,5

Out of the real domain, the result is complex

live ↗
InN(arcsin⁡(3))N(\arcsin(3))Out1.570 796 326 794 896 619 231 321 5−1.762 747 174 039 086 050 47i1.570\,796\,326\,794\,896\,619\,231\,321\,5-1.762\,747\,174\,039\,086\,050\,47i

An undefined symbol stays as it is

live ↗
InN(c)N(c)Outcc

The requested precision does not change a symbol

live ↗
InN(c,47)N(c, 47)Outcc

A plain symbol is unchanged

live ↗
InN(poly)N(\mathrm{poly})Outpoly\mathrm{poly}

Symbolic powers get a float exponent

live ↗
InN(x3)N(\sqrt{x}^{3})Outx1.5x^{1.5}

A float coefficient inside a symbolic expression

live ↗
InN(πx)N(π^{x})Out3.141 592 653 589 793 238 462 643x3.141\,592\,653\,589\,793\,238\,462\,643^{x}

A symbol stays symbolic

live ↗
InN(int)N(\mathrm{int})Outint\mathrm{int}

A numeric constant is turned into a float within a symbolic expression

live ↗
InN(π−2pit,[∞,20])N(π-2\mathrm{pit}, \bigl\lbrack∞, 20\bigr\rbrack)Out3.141 592 653 589 793 238 46−2pit3.141\,592\,653\,589\,793\,238\,46-2\mathrm{pit}

Another symbol is unchanged

live ↗
InN(crt)N(\mathrm{crt})Outcrt\mathrm{crt}

Even with a precision it is left alone

live ↗
InN(crt,47)N(\mathrm{crt}, 47)Outcrt\mathrm{crt}
live ↗
InN(21 000 000)N(2^{1\,000\,000})Out9.900 656 229 295 898 250 7⋅103010299.900\,656\,229\,295\,898\,250\,7\cdot10^{301029}
live ↗
InN(π10,[∞,5])N(π^{10}, \bigl\lbrack∞, 5\bigr\rbrack)Out93 648.047 4893\,648.047\,48
live ↗
InN(π10,[∞,1])N(π^{10}, \bigl\lbrack∞, 1\bigr\rbrack)Out93 64893\,648
live ↗
InN(2x+πe−x,20)N(\frac{2x+π}{e-x}, 20)Out2x+3.141 592 653 589 793 238 52.718 281 828 459 045 235 4−x\frac{2x+3.141\,592\,653\,589\,793\,238\,5}{2.718\,281\,828\,459\,045\,235\,4-x}
live ↗
InN(1−1−1/e1 000,20)N(1-\sqrt{1-1/e^{1\,000}}, 20)Out0.00.0
live ↗
InN(k,25)N(k, 25)Outkk
live ↗
InN(ex+π)N(e^{x+π})Out2.718 281 828 459 045 235 36x+3.141 592 653 589 793 238 462 6432.718\,281\,828\,459\,045\,235\,36^{x+3.141\,592\,653\,589\,793\,238\,462\,643}
live ↗
InN(k)N(k)Outkk
live ↗
InN(1 000!)N(1\,000!)Out4.023 872 600 770 937 735 44⋅1025674.023\,872\,600\,770\,937\,735\,44\cdot10^{2567}
Properties #
live ↗
InN(1−φ+1φ,20)N(1-\varphi+\frac{1}{\varphi}, 20)Out−2.0⋅10−340-2.0\cdot10^{-340}
live ↗
InN(1−φ+1φ,[∞,20])N(1-\varphi+\frac{1}{\varphi}, \bigl\lbrack∞, 20\bigr\rbrack)Out0.00.0
live ↗
InN(e100,[∞,−10])N(e^{100}, \bigl\lbrack∞, -10\bigr\rbrack)Out2.688 117 141 816 135 448 412 625 551 580 014⋅10432.688\,117\,141\,816\,135\,448\,412\,625\,551\,580\,014\cdot10^{43}
live ↗
InN(10 000 000 000(e100−e999 999 999 999/10 000 000 000),[∞,20])N(10\,000\,000\,000(e^{100}-e^{999\,999\,999\,999/10\,000\,000\,000}), \bigl\lbrack∞, 20\bigr\rbrack)Out2.688 117 141 681 729 591 326 298 974 395 630 530 648 558 808 379 370 953 675 983 977⋅10432.688\,117\,141\,681\,729\,591\,326\,298\,974\,395\,630\,530\,648\,558\,808\,379\,370\,953\,675\,983\,977\cdot10^{43}
live ↗
InN(esin⁡(1 000))N(e^{\sin(1\,000)})Out2.286 173 685 812 171 102 232.286\,173\,685\,812\,171\,102\,23
live ↗
InN(esin⁡(1 000),47)N(e^{\sin(1\,000)}, 47)Out2.286 173 685 812 171 102 225 890 854 533 061 221 871 278 5122.286\,173\,685\,812\,171\,102\,225\,890\,854\,533\,061\,221\,871\,278\,512
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 ↗
InN(1−1−1/e1 000,[20,∞])N(1-\sqrt{1-1/e^{1\,000}}, \bigl\lbrack20, ∞\bigr\rbrack)Out2.537 979 448 774 728 382 6⋅10−4352.537\,979\,448\,774\,728\,382\,6\cdot10^{-435}

An exact tie rounds to the even digit: 0.125 to 0.12

live ↗
InN(18,2)N(\frac{1}{8}, 2)Out0.120.12

...and 0.375 to 0.38

live ↗
InN(38,2)N(\frac{3}{8}, 2)Out0.380.38
About
Examples38
Checked againstWolfram Language 34 agree4 differSageMath 36 agree1 unevaluatedSymPy 31 agree4 differ1 errormpmath 20 agree3 differJulia 20 agree2 differ1 errorRust 9 agree4 differ4 errorOscar 2 differ
CrosswalkWolfram LanguageSageMath ×2SymPy ×2mpmathJuliaRust ×2

Implementation

mappedsympypackages/oracle/src/mappings.ts

mpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.

mappedmpmathpackages/oracle/src/mappings.ts

mpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.

mappedsagepackages/oracle/src/mappings.ts

mpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.

mappedoscarpackages/oracle/src/mappings.ts

mpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.

mappedjuliapackages/oracle/src/mappings.ts

mpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.

mappedrustpackages/oracle/src/mappings.ts

mpmath and the Julia libraries are numeric already; SymPy and Sage evaluate exactly unless asked.

mappedsympypackages/oracle/src/mappings.ts

The digit count is dropped: lanes compare numbers to a relative tolerance, so the full-precision value is the better witness.

mappedmpmathpackages/oracle/src/mappings.ts

Past 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.

mappedsagepackages/oracle/src/mappings.ts

The 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.

mappedoscarpackages/oracle/src/mappings.ts

The digit count is dropped: lanes compare numbers to a relative tolerance, so the full-precision value is the better witness.

mappedjuliapackages/oracle/src/mappings.ts

N(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.

mappedrustpackages/oracle/src/mappings.ts

The digit count is dropped: lanes compare numbers to a relative tolerance, so the full-precision value is the better witness.

See also: Round, Interval