Wrong values from scipy.special.erf (erf(x) != -erf(-x))
See original GitHub issueWe are seeing incorrect values returned from scipy.special.erf
We have some equations that depend on the symmetry of the erf function, but scipy violates this assumption.
Mathematically, for reals, erf(x) == -erf(-x), but scipy.special.erf does not seem to honor this property.
The difference from expectation seems to be beyond a simple floating point representation problem.
Reproducing code example:
# succeeds
import math
difference = math.erf(5.905732037710919)+math.erf(-5.905732037710919)
assert abs(difference) == 0.0
# fails, difference should be 0.0, difference is actually -1.1102230246251565e-16
import scipy.special
difference = scipy.special.erf(5.905732037710919)+scipy.special.erf(-5.905732037710919)
assert abs(difference) == 0.0
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
Scipy/Numpy/Python version information:
1.1.0 1.14.0 sys.version_info(major=3, minor=6, micro=3, releaselevel='final', serial=0)
(Older versions of scipy affected as well)
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
scipy.special.erf — SciPy v1.9.3 Manual
Returns the error function of complex argument. It is defined as 2/sqrt(pi)*integral(exp(-t**2), t=0.. z) .
Read more >Is there an easily available implementation of erf() for Python?
FWIW, how are you using scipy's erf function? With the following setup: from scipy.special import erf; import numpy as np; data = np.random....
Read more >Behavior of np.erf for complex arguments #12515 - GitHub
When np. erf is given a complex number, it returns the number itself instead of the value of the error function. For example,...
Read more >Error function - Wikipedia
In mathematics, the error function often denoted by erf, is a complex function of a complex variable defined as: ... Two closely related...
Read more >scipy.special.erf — SciPy v0.14.0 Reference Guide
scipy.special.erf¶ ... Returns the error function of complex argument. It is defined as 2/sqrt(pi)*integral(exp(-t**2), t=0..z). ... The cumulative of the unit ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

We use Cephes
erf, not cdflib.(just had an open environment and a bit of time to spare) It seems easiest to throw gh-9351 over the wall and forget.