-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
power returns invalid complex number for negative base and Infinity as exponent #804
Comments
Thanks for reporting Paal. That |
I had a look into this: the Therefore with I feel that the behaviour should not change in this way regarding |
@harrysarson would you like to pick this issue up? |
Sure I can have a go :) |
👍 thanks |
What are your views on the best result for
I feel like (c) is the most elegant solution but would require either a new type or and extension of complex.js. (a) and (b) are much easier to do. Additionally the behaviour of complex.js is currently to return |
I think returning complex infinity for |
For complex numbers NaN can make sense, since the the power function is defined via sin/cos and sin(inf)=nan. However, if we think about it, pow(c∈C, inf) is an infinite rotation of an arrow. With this interpretation, Infinity would make sense too. However, I would go with a new "symbol" - "complex infinity" as well. I made some minor changes on complex.js regarding the infinity behavior. I'd be glad if you guys could have a look: rawify/Complex.js#5 |
Ah, and about the printing error, I catch NaN's in complex.js's |
I've fixed the wrong formatting of Sounds good @infusion . It may make sense to create a special constant complex infinity rather than using |
@josdejong for "NaN + NaNi", I decided for complex.js to make the whole complex-number NaN as soon as one component becomes NaN. So, the output is "NaN". I think this lacks some information in the output, but at the end it's just a feedback, that an operation failed, other than for infinity, where the individual dimensions can become infinity with a certain meaning. Mapping
What do you guys think? |
I think complex infinity is a great idea. Complex infinity is different from "real" infinities Complex infinity (denoted by
Edge cases:
|
ComplexNaN, on the other hand, maybe should be avoided. I do not see justification for a "separate" NaN value. (for the record: I do not see justification for NaN in the first place). But accepting the fact that we do have NaN, for whatever reason, then creating another one seems awkward to me. So if any operation could/should return "complex NaN", I would vote for returning simply 'NaN' instead. |
http://reference.wolfram.com/language/ref/ComplexInfinity.html This page is also useful, it has some return values in Wolfram of standard functions on ComplexInfinity. (under "Neat Examples") |
If the complex infinity is in the exponent, I would say:
update: these may be (are probably) wrong, someone should check it who has better knowledge of complex analysis than me... I have studied this type of stuff more than 2 decades ago. |
The discussion about ComplexInfinity may be better placed at rawify/Complex.js#5 as the implementation of complex pow is handed there.
Apart from that I agree :) |
Makes sense. So to summarize: we want The latter may be tricky since that means that after every operations with complex numbers we have to check whether the resulting complex number contains NaN for one or both |
Complex.js now has infinity support in I think it should "just work" but some tests might fail and even if they don't we should add some new tests. I will make a PR when the new version is published. :) |
I thik the concept of complex infinity must be introduced for math.js as well. (with a special symbol or sth) |
Great if you can pick this up coming time Harry ! |
Hi Team - just picking up this issue to see if I can help. First, I've confirmed via the Math notepad that the following two cases work as expected.
Just to clarify from reading previous comments - I need to use complex.js (https://github.com/infusion/Complex.js/#complexinfinity) for cases that don't converge to a limit, e.g. (-1)^{+-inf}, so instead of returning NaN + NaNi I simply return complex.INFINITY and update the unit tests accordingly? Let me know what you think. Best regards |
Thanks for picking this up @georgemarklow ! Math Notepad is a little bit behind (still at mathjs v7.5.1). To know for sure what the output is it may be best to try out directly in the developer console of https://mathjs.org or checkout the project and use the repl locally. Also, be careful not to look at the output of It would be nice if you can get a clear list with the edge cases we're talking about, the desired outcome, and the current outcome. (At least I myself do not have the edge cases and desired outcome clear at this moment, and we may want to discuss some of them). Indeed the calculations are done by Complex.js, in mathjs we want to do as little as possible, though when the output of Complex.js for those edgecases differs from what we want/expect, we have to write code for it in mathjs to cover the edge case. |
There is a stalled PR rawify/Complex.js#25. @georgemarklow having a look at this might be a good place to start. It might be that we can patch the Complex infinity handling from within mathjs somehow although I suspect better infinity support from Complex.js will really be needed to make progress. |
Hi guys, following infusion/Complex.js#25, I created a branch off develop, wrote unit tests to handle the cases, and refactored the code to understand the problem and get feedback. Could I have permission to create a new remote branch (see below)? Thanks |
@georgemarklow what we normally do is start with forking the mathjs project to your own github account, create a feature branch there to work on something new, and then create a PR to |
Following inputs return
NaN - aNi
in Notepad. Seems like all negative bases yield the same:(-0.5)^Infinity
(-1)^Infinity
(-2)^Infinty
probably the underlying function
pow()
returns aComplex
with both Real and Imaginary part set toNaN
. (haven't checked).Definitely,
NaN + aNi
is wrong. But whether this is simply an issue with the rendering, or the underlying logic, is to be analyzed. Some thoughts:Whether the result should be a
Complex
with both Real and Imaginary parts set toNaN
, is questionable (after all there is aNaN
already, no need to introduce a "second, complexNaN
" value maybe).for
-1 < a < 0
, the result should probably be zero, as in javascript, this one converges:Math.pow(-0.5,Infinity) // 0
for
a < -1
the result should not be Infinity (so, unlike javascript), because this is clearly divergent. (I don't understand javascript behavior:Math.pow(-2,Infinity) // Infinity
-Infinity
as exponent should also be considered (currently these cases also return incorrectNaN + aNi
, but convergence / divergence should also be considered separately for-Infinity
)The text was updated successfully, but these errors were encountered: