In this case the problem is that quadgk
and scipy’s quad
use different default tolerances.
Following the documentation, quadgk
uses an absolute tolerance atol = 0
and relative tolerance rtol = sqrt(eps)
, while scipy’s quad
uses the equivalent of atol = sqrt(eps)
and rtol = sqrt(eps)
.
The default choice of quadgk
is not the best in your case, as the analytical value of your integral is exactly zero. This is actually mentioned in the quadgk
docs:
(Note that it is useful to specify a positive
atol
in cases wherenorm(I)
may be zero.)
Choosing atol = sqrt(eps(Float64))
should bring the evaluation time close to the one you see in python.