0

The function erfcx(x) = exp(x^2)erfc(x) is sometimes provided in numerical packages to avoid numerical underflow for large values of x. But Mathematica does not provide a native implementation of this function.

Any suggestions as to what can I use to compute $\exp(x^2)\mathrm{erfc}(x)$ accurately for large values of $x$?

Edit: I just realized this is a duplicate of Numerical underflow for a scaled error function, which contains very detailed answers. So I'm closing this one.

a06e
  • 11,327
  • 4
  • 48
  • 108
  • Underflow rather than Overflow? – mikado Jul 18 '19 at 18:01
  • 1
    What do you consider large values of $x$? N[Exp[x^2] Erfc[x] /. x -> 1000000, 500] works fine. – JimB Jul 18 '19 at 18:01
  • 1
    you can also use 2 HermiteH[-1, x]/Sqrt[Pi]. – AccidentalFourierTransform Jul 18 '19 at 18:07
  • @JimB - extreme precision isn't necessary. Even low arbitrary-precision works fine, e.g., N[Exp[x^2] Erfc[x] /. x -> 1000000, 15] – Bob Hanlon Jul 18 '19 at 18:18
  • Do those numerical packages just use the approximation $\frac{1}{\sqrt{\pi } x}$ for $x>10^6$ ? – JimB Jul 18 '19 at 18:18
  • @BobHanlon I was being extreme in an attempt to get the necessary information to answer the question. I was recently told by a number theorist that numbers aren't large until they reach 10^100 (which is way out of my price range). – JimB Jul 18 '19 at 18:19
  • That's arbitrary precision, which works but is very slow. Try machine precision, e.g., x = 50.0; Exp[x^2] Erfc[x] underflows. @BobHanlon. This shows up (for example) if you try to plot the function. – a06e Jul 18 '19 at 19:01
  • @JimB I don't know if that's the approximation used in other libraries, but I could use it. – a06e Jul 18 '19 at 19:02
  • x = 50.0\20; Exp[x^2] Erfc[x] // AbsoluteTimingevaluates to{0.00035, 0.011281536265323773}`. Doesn't seem very slow. – Bob Hanlon Jul 18 '19 at 19:18
  • LogLinearPlot[Exp[x^2] Erfc[x], {x, 1, 1000}, WorkingPrecision -> 20] plots fine. – Bob Hanlon Jul 18 '19 at 19:21
  • @AccidentalFourierTransform Thanks! That's exact and works perfectly. – a06e May 22 '20 at 15:23
  • @AccidentalFourierTransform If you post an answer with that I'll accept it. Just for future reference, since I foget this often and have to come back here to find it. – a06e Jun 09 '20 at 20:34

1 Answers1

2

Using the approximation $\frac{1}{\sqrt{\pi } x}$ when $x>5*10^6$:

erfcx[x_] := If[x > 5*10^7, 1/(x Sqrt[π]), Exp[x^2] Erfc[x]]
erfcx[10^50] // N
(* 5.6419*10^-51 *)

One potential reference is Closed‐form approximations to the error and complementary error functions and their applications in atmospheric science.

JimB
  • 41,653
  • 3
  • 48
  • 106