# How can I compute Erf of large numbers to more precision?

I would like to compute Erf[80/3] to enough precision to know the order of magnitude of 1 - Erf[80/3]

How can I do that?

I think it's silly every time I type in something like Erf[80/3] and Mathematica just returns the input as the output. I'd rather the output be the string "Cannot evaluate", which would at least be a useful message, although not as useful as one that includes a reason.

I tried N[Erf, WorkingPrecision -> 10], and got the error message:

N::precbd: Requested precision WorkingPrecision->10 is not a machine-sized real number between \$MinPrecision and \$MaxPrecision.

Which I don't understand because $MinPrecision returns 0 and $MaxPrecision returns $$\infty$$, so I'm not sure why 10 is not a machine-sized real number between 0 and $$\infty$$.

• "...to know the order of magnitude of 1 - Erf[80/3]" - use Erfc[] and not Erf[] if you want to spare yourself numerical grief and misery. Jun 3, 2020 at 19:01
• This is closely related: Numerical underflow for a scaled error function Jun 3, 2020 at 20:34

As J.M. mentioned, you can use Erfc directly:

N[Erfc[80/3]]


3.11544 * 10^-311

In general, if that doesn't work, inputting N with an appropriate precision goal is usually sufficient:

N[1-Erf[80/3], 500]


3.1154438... 10^-311

You can also specify $MaxExtraPrecision: Block[{$MaxExtraPrecision=500}, N[1-Erf[80/3], 20]]


If that doesn't work, specifying an infinite precision goal and providing an accuracy goal with a sufficient number of digits should work. This isn't strictly necessary for this problem, but with more poorly behaved functions it can be good to keep in mind.

N[1 - Erf[80/3], {Infinity, 500}]


The first argument of N is the expression to be evaluated, and the second argument are the goals to be met. If the goal is a single number, it is interpreted as a precision goal, otherwise it is a pair of precision goal and accuracy goal in that order. Whichever goal is hit first is the result returned.

With an infinite precision goal, the result will be refined until the accuracy goal is met, even if that requires higher working precision (as the working precision is limited by $MaxExtraPrecision plus the precision goal which is infinite here). 3.11544384... * 10^-311 Looks like the order of 1 - Erf[80/3] is approximately $$10^{-311}$$. The error you received (N::precbd) is because you tried to feed WorkingPrecision -> 10 as the precision goal, which expected a number, not a Rule (specifically, Rule[WorkingPrecision, 10]). • N[Erfc[80/3]] does it with way less fuss. Jun 3, 2020 at 19:02 • Definitely good to note, added it to the answer. Not always applicable though, in my own experience, and given that I only recently learned about N's intricacies for goal specification I think it's good to ensure that that information is explained somewhere too. Jun 3, 2020 at 19:05 • Quite right; it is exactly because people already went through the trouble of inventing the complementary error function that it should be used whenever it could be used.;) But yes, your general advice on N[] remains useful. Jun 4, 2020 at 0:06 If you want 1-Erf, just use Erfc, intended for just this sort of problem. N[Erfc[80/3]] (* 3.11544*10^-311 *)  Also note that exact functions of exact arguments, like Erfc[80/3] are kept in exact, not approximate form, for the excellent reason that Mathematica can often deal with exact numbers exactly, while approximate numbers inflict approximation on a calculation that might otherwise be exact. They may be reduced if an exact reduction is possible: compare Sqrt to Sqrt. When you provide exact numbers, Mathematica will try to provide an exact result. It did evaluate your input, but there is no other way of exactly representing the number you gave it. Try entering 2/6 into Mathematica. You should find it returns 1/3. It evaluated the result and returned the simplest exact representation it could come up with. Similarly, Sqrt returns $$2\sqrt{2}$$. This is why there's no error message: everything worked perfectly. If you provide an exact number without any simpler representation, it appears as though Mathematica did nothing. Try Sin vs. Sin[1.]. If you're okay with an approximate result (like you would get from a calculator), you can use machine precision. Just add a decimal after at least one of the numbers like 1 - Erf[80./3]. Of course, this returns 0 because your computer isn't capable of representing such small numbers in double precision format. If you evaluate $MinMachineNumber, you'll probably get something around $$2.2 \times 10^{-308}$$ and your number is smaller than that.

In this case, you either have to use arbitrary precision, or use N to force an exact number to evaluate into arbitrary precision. Eyorble already shows how to use N. To use arbitrary precision directly, you could do 1 - Erf[80500/3]` which evaluates to $$3 \times 10^{-311}$$ (plus many decimals). This tells Mathematica to represent 80 as an arbitrary precision number with a precision of 500. Since all the other numbers are exact, the answer should have a precision of close to 500.

• To write piece of code with a backtick inside, enclose that code in two backticks from each side, i.e. write ''1 - Erf[80'500/3]'' but changing each of the five apostrophes to a backtick. Jun 3, 2020 at 19:23
• @corey979 Oh god, thank you! I've been wondering how to do this forever, but couldn't seem to find it in the markup help files. Jun 3, 2020 at 21:15