[SciPy-User] error function with complex argument

"Claas H. Köhler" claas.koehler@dlr...
Wed Oct 10 03:39:10 CDT 2012

On 09/10/12 19:12, Pauli Virtanen wrote:
> 09.10.2012 19:28, "Claas H. Köhler" kirjoitti:
>> I have a question regarding the error function scipy.special.erf:
>> Is it intended, that the erf of an imaginary argument yields a non-vanishing real-part?
>> I get e.g.
>> erf(1j)= 1.6504257587975431j
>> erf(5j)= (1+8298273879.8992386j)
>> The first result is what I would expect in accordance with Wolfram alpha. The second result, however,
>> has a real part of unity. As far as I know, the real part of erf should always vanish for purely
>> imaginary numbers.
>> Any support would be appreciated.
> The reason here is that the ye olde complex erf Fortran implementation
> that Scipy has uses the asymptotic expansion (Abramowitz & Stegun
> 7.1.23) to compute large-argument values. The asymptotic series is for
> erfc, and one always gets Re erf = 1 along the imaginary axis.
> Of course, this is somewhat naive. While it does produce reasonable
> relative accuracy as a complex number, the accuracy of the real and
> imaginary parts separately is not necessarily OK near the imaginary axis.
> The issue with Scipy here is twofold -- first, there are no better
> existing special function libraries we could use, or at least I'm not
> aware of them. Second, writing these from scratch takes time and
> expertise and nobody has so far volunteered to do any work in this
> direction.
Thanks for the quick response!

The bottom line is that erf is actually not (correctly) implemented for complex arguments, if I
understand you correctly.

I suspect there are good reasons to provide a function which is known to yield incorrect results, so
that throwing a type error is not an option? (This is what erfc does on my machine)

However, adding a warning when called with complex arguments could be helpful to prevent naiive use
as in my case. Adding this important piece of information to the docs would not harm either, from my
point of view.

In any case, thanks for the quick support.


More information about the SciPy-User mailing list