-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Fix to how eps() works on complex values and types #2651
Conversation
I'm pretty dubious about |
I agree, it wasn't clear to me what was the proper definition in the complex case. Since it was already implemented, however, I just wanted to make it consistent with the definition for real Floats and Integers. The only use case I have in mind is checking for approximate equality. Thinking of complex values are pairs of real values leads to a natural approach to comparison: if both the real and imag parts are approximately equal, then so are the complex values (this is somewhat analogous to the infinity norm for vectors). |
It seems to me the distance between complex numbers is |
Cc: @alanedelman |
I think It all goes back to @StefanKarpinski's point, I suppose, and what kind of distance is more reasonable to use (if any, in the complex case). |
Also, there's an inconsistency in the current implementation, where
I am not even sure what |
As mentioned already, it really depends on how you want to define distance between complex numbers.
The Euclidean norm is the most useful for complex operations, but there are other norms (Wikipedia) one could take such as the Lp norms. These range in absolute value between the L∞-norm where So perhaps the correct thing to do is to have |
@marcusps "the precision of complex numbers is worse than the precision of real numbers." It is not necessarily that surprising considering the number of operations on real-valued quantities one has to perform to do complex arithmetic, since there are twice as many real-valued numbers to work with in the latter. |
This seems to be getting into murky territory. Here are what appear to be the clear issues, suggested fixed
I think this meshes well with the reservations that @StefanKarpinski haves, addresses some of the issues @ViralBShah and I have pointed out, and avoids the murkier questions brought up by myself, @jiahao and @JeffBezanson about how Thoughts? |
Getting into norm stuff feels like the wrong direction to me – I feel like one of the classic use cases is to make an epsilon-ball around one value to compare it with another, to check for containment in the epsilon ball. I guess that's where the norm stuff comes in, since you typically use a norm like |
@marcusps (2) makes sense. I did a cursory search of the numerical analysis literature and didn't turn up anything particularly definitive on complex machine epsilon. It's not too surprising, since any sensible definition of @StefanKarpinski I think the discussion about norm is entirely relevant, since the whole point of
Personally I only care about machine epsilon to the extent that I need to test for approximate equalities, and secondarily in error propagation to make sure that roundoff error isn't washing out all my calculations. Both of these cases are handled by epsilon-ball. |
A quick inspection of LAPACK also shows that |
Removing |
The current implementation of
eps
on complex values relies onabs
. This leads to a problem for complex integer types, asabs
returns a float, and thuseps(1im)
does not fail likeeps(1)
(and it should). Similarly,eps(Complex{Float64})
and related expressions simply fail (not being defined).The changes in this request fix both of these issues, which become important when trying to compare complex floating point values. The docs (
doc/stdlib/base.rst
specifically) mentions only eps of real Float values & types is sensible, but it strikes me as natural to support complex Floats.