mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

bugfix/804: Added handling of complex numbers negative bases and positive infinity exponent

Open georgemarklow opened this issue 5 years ago • 15 comments

Implementation of following requirements in https://github.com/infusion/Complex.js/pull/25:

  • z ^ Infinity === NaN
  • Infinity ^ z === Infinity if Im(z) === 0 and Re(z) > 0
  • Infinity ^ z === 0 if Re(z) < 0
  • Infinity ^ 0 === 1
  • Infinity ^ z === NaN otherwise

georgemarklow avatar Jan 31 '21 14:01 georgemarklow

Could give me some feedback on the custom implementation of the logic described in infusion/Complex.js#25, before I commit more work to deal with negative base cases x < -1, x == -1 and -1 < x < 0. Thanks.

georgemarklow avatar Jan 31 '21 14:01 georgemarklow

Looks good and well tested @georgemarklow , thanks 👍

I remember we had some discussions long time ago on whether we should return number Infinity, or complex Infinity, it may be this discussion: #1277. Do you have any thoughts in that regard George?

josdejong avatar Jan 31 '21 16:01 josdejong

Thanks @josdejong for your feedback.

I agree with what you said at the bottom of that thread that ComplexInfinity covers a number of edge cases, and it's also consistent with Wolfram's view and therefore ideal for users consuming mathjs that have come from that background. If you agree - I'll create a ComplexInfinity type and I'll make the changes needed.

Let me know what you feel is the best choice.

Thanks! George

georgemarklow avatar Jan 31 '21 17:01 georgemarklow

Re ComplexInfinity I think there are upto XXX different infinities we could have:

  1. ±∞ + 0i
  2. 0 ± ∞i
  3. ∞̃ (ComplexInfinity: infintite magnitude and unknown/unspecified/undefined argument)

Currently this PR only covers postive real infinity --- so the first half of (1.). The change looks good to me but it might be nice to extend it to correctly handle the other infinities. Probably the best way to do that is to add an isFinite function to mathjs (or update the implementation if there is already one) rather than checking x.re == Infininity.

Thanks for picking this up @georgemarklow it would be really cool to see this fixed finally!

harrysarson avatar Feb 01 '21 14:02 harrysarson

I agree with what you said at the bottom of that thread that ComplexInfinity covers a number of edge cases, and it's also consistent with Wolfram's view and therefore ideal for users consuming mathjs that have come from that background. If you agree - I'll create a ComplexInfinity type and I'll make the changes needed.

Yes it makes sense to me 👍 . I guess Harry is right though that this may open up new edge cases that we need to be aware of.

Probably the best way to do that is to add an isFinite

Good idea! Or make an isInfinite ;) . Similar to isNaN.

josdejong avatar Feb 03 '21 16:02 josdejong

Thanks @harrysarson and @josdejong , I agree with your comments. I'll push changes to this PR in the next few days for review.

georgemarklow avatar Feb 07 '21 20:02 georgemarklow

Hi - I've checked in my progress so far. I'll come back to this PR later in the week to resolve some commented unit tests and check test coverage. In the meantime, if there's anything in the PR you would like changed at this stage, just let me know. Thanks.

georgemarklow avatar Feb 14 '21 19:02 georgemarklow

Hey sorry for the slowness, I have been thinking about this issue though. I think this is the behaviour we want. Does this agree with your thinking so far @georgemarklow?

harrysarson avatar Mar 04 '21 17:03 harrysarson

@harrysarson George let me know that unfortunately he isn't able to work on this any further. Is this something you like to pick up instead?

josdejong avatar Mar 08 '21 19:03 josdejong

I will definitely keep this in on my radar but I cannot promise I will make much progress anytime soon

harrysarson avatar Mar 08 '21 21:03 harrysarson

👍 take it easy

josdejong avatar Mar 10 '21 08:03 josdejong

I must admit I am confused about the current handling of complex infinities/NaNs both in mathjs and complex.js, as there seem to be lots of open issues and PRs on this topic in both projects, but I'd rate this as fairly high priority to iron out in some consistent way and implement and move on from... if that requires some effort, I'm happy to help but can't guarantee I will be able to do this entirely on my own.

gwhitney avatar Aug 17 '22 08:08 gwhitney

Thanks Glen! Yes this could involve quite some edge cases. We can possibly address issues in multiple small PR's that each improve some part to keep it manageable.

josdejong avatar Aug 17 '22 14:08 josdejong

I have so many assigned to me now, and I tried to make it clear above that I do not see myself as being able to handle this one on my own, so is it OK if I unassign myself?

gwhitney avatar Aug 18 '22 02:08 gwhitney

Yes of course, sorry! Thanks for the offer to at least assist getting this straightened out.

josdejong avatar Aug 18 '22 07:08 josdejong