-
Notifications
You must be signed in to change notification settings - Fork 34
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
Behaviour of non-finite complex numbers. #5
Comments
Oh, that are good findings! Thanks a lot for the ticket and notifying me about #804! I'll look into this. About the last point, it's a mere philosophical question if infinity should equal infinity, or more specifically is 1/0 == 2/0? JavaScript simply compares the infintiy bit, but other languages treat this case differently. |
Yeah that's fair re the equality - an Is full support for infinite values (eg in the |
Okay, I added a new branch "infinity": f06449f I added a new symbol Complex.Infinity, which sets real and imaginary part to infinity. This symbol is returned for inv(0), div(z, 0) and if the angle for cos/sin in The actual code changes don't change the size of the library dramatically, so I would say it's worthwhile to add the feature. I would say we keep |
I noticed that currently Additionally currently Finally |
Hm, yep I thought the same way and I think a real infinity should stay real. However, wolframalpha decided (maybe for the same reason) to print complex infinity for any case, the complex and real: http://www.wolframalpha.com/input/?i=1%2F0 0/0 Should be fixed, right. NaN is an approproate value for that. The different behavior of div and inverse must be fixed as well. About the last one, the multiplication, it happens to become NaN since 0Infinity=NaN. I see your point that the multiplicative neutral element should return the same value after multiplication (which would be the case, if we treat 0Infinity as 0. I must have a look, if this can be generalized this way.) |
Okay, there is an update in infinity branch.
|
|
Hi What is the purpose of these lines in the divide function? return new Complex(
(a !== 0) ? (a / 0) : Infinity,
(b !== 0) ? (b / 0) : Infinity); If a is not zero then the expression evaluates to Infinity anyway. https://github.com/infusion/Complex.js/blob/infinity/complex.js#L387-l388. I believe that the whole of the |
The purpose is to keep the sign of each Infinity. |
But as both the real and imaginary parts will be infinite the return value will get converted to complex infinity anyway. I am also reasonably convinced that |
Hi! |
Unfortunately I currently (and for quite a while) do not have the time to understand the code and test it. What I can do is write down what I consider the mathematically correct behavior. Below Construction and equality
Addition, subtraction, negation
Real and imaginary part, argument and absolute value
Multiplication
Division Division has multiple cases. both the dividend and the divisor must be examined and three cases separated: zero, non-zero (but finite), infinity. This yields 9 possible combinations (here I use more traditional notation and Multiplicative inverse
This is the basic stuff, other functions require some more thinking but I will come back when I have some time |
Ah thanks, I'll have a look through these :) |
Yeah, I back everything except the following which I have questions about. 0. How about 2. See #5 (comment), I would be happy for 4. Yeah we have 8. Hmm, need to think more about this. Possibly worthy of a separate issue. 22. Also requires thought. |
I see what you mean. Unfortunately, it is impossible to extend the complex plane with a single complex infinity in such a way that it is mathematically reasonable ("correct") and operations for real numbers behave exactly as on the (extended) real number line at the same time. The closest thing is using "directed infinities". The real infinity (javascript: This is possible, and indeed, Wolfram uses this approach. It has a For complex infinity, wolfram uses a symbol similar to this: ⧝ (U+29DD). But then This becomes even more problematic, because you then have to define all operations for all of these new infinities, and some of the operations are again undefined. To my knowledge there is little, if any, practical use for these directed infinities. But I may be mistaken. https://en.wikipedia.org/wiki/Directed_infinity |
btw javascript has some mathematically incorrect behavior as well, so maybe it is not a great idea to follow it. example: |
This does not mean of course that the javascript behavior for |
I see. Looks kind of silly, based on these it seems MATLAB models 8 selected directions on the complex plane (i∞, (1+i)∞, 1∞, (1-i)∞, (-i)∞, (-1-i)∞, (-1)∞, (-1+i)∞ ) which is very arbitrary. I do not know MATLAB, but I remember vaguely that I came across some other case where it had questionable behavior. The real question is: what is the practical use of all these infinities? I see the following use cases generally:
These are the cases I have ever came across. The first one is the most common (at least for me), but does not apply to complexes (no ordering on complex plane). The second one can be achieved by any infinity construct (whether a single complex infinity, or several directed infinities, or the MATLAB version with 8 selected directed infinities - I still think this is silly). The more different kinds of infinities you have, the less useful this becomes because it will be difficult and error prone how you check the return value for these infinities. The third one is a piece of cake, provided that the underlying logic is mathematically sound. It does not occur frequently, but when it does, it can greatly simplify code (no need to separate a lot of different edge cases). However, if some arbitrary rules are used, like in MATLAB, then most probably the result will not be what you expect in a particular scenario, so you end up checking those edge cases despite the built in infinity constructs / computation rules, hence no improvement / simplification in your code and the infinities become useless like Of course this is by no means a detailed analysis, rather just my personal opinion based on (my particular) experience and intuition. Which still tells me that the best / most elegant version would be a single complex infinity. It would be great, however, to hear opinions from others as well. |
Nevertheless I have to give credit to the argument that it is a nice feature to have that things like |
Sorry about the delay. :) Having these 8 infinities is easy to implement with each complex object containing two fields (
I propose adding an Therefore options:
I vote for |
see #14 as well. |
I vote for option 1 (Riemann Sphere) that @balagge recommended. It is both mathematically and programmatically elegant and shouldn't add much if any to the size of the library. I have been looking for a complex library that implemented it for a while now... |
Issue resolved by #17, we can close this issue as soon as a new version is pushed to npm. I think these changes are semver major just incase anyone was previously doing |
@infusion could you release a version to npm? |
I was looking into issue josdejong/mathjs#804 regarding the behaviour of negative numbers raised to infinite powers.
Support for non-finite complex numbers seems to be incomplete in complex.js and I was wondering if it was something that you are planning to support more comprehensively. For example:
new Complex(-0.5).pow(Infinity)
currently givesNaN
which is inconsistant with the behaviour ofMath.pow(-0.5, Infinity)
which (correctly) gives0
.Additionally I found a couple of bug which need fixing regardless of whether the library is extended to add proper support for complex numbers.
new Complex(0).inverse()
currently gives0
.new Complex(Infinity).equals(Infinity)
currently returnsfalse
.The text was updated successfully, but these errors were encountered: