- Sponsor
-
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
Complex bundling, ComplexInfinity and floor #2114
Comments
Glad to know! After looking at #2097 I have a crazy idea: use (r,phi) instead of (re,im) to internally represent complex numbers. This way we can realize all these good stuff by having I wrote a corresponding pow function here. Is that a world we like? |
(1) there is no ready-made solution for that but all the building blocks are there. It will require some work though. It boils down to:
(2) see comment of Harry. Feel free to weigh in in the discussion there! (3) the mathjs version of (4) about storing complex numbers as (r, phi): that may be interesting, though I'm not sure if it will really improve things in the end: will most calculations become easier or faster? Do most calculations get more round-off errors? Or less? |
Thanks for the detailed answers. I will try to understand the custom bundling more when I can, but I already found About (4): compared to the rectangular form, the polar form is (much) simpler and faster and more precise with |
That sounds interesting! It would be a huge breaking change of course, so it may to be easy to pull this off. I suppose besides understanding the upsides, we also need to have a clear overview of the downsides. It may be handiest to open a discussion at https://github.com/infusion/Complex.js/ (the library that is powering complex number calculations in mathjs). |
Thanks! I opened an issue there. |
Closing this issue now, the concerns are addressed in separate issues if I'm not mistaken. |
Hi! While using the library, I had a few questions/comments:
(1) Is there a way to only load the parts about numbers and complex numbers? Basically I only need functions from ℂ to ℂ (complex abs, sqrt, log etc, maybe also logicals), never need things like matrices and units. I'm not aiming to reduce the bundle size, but mainly for performance, and I hope to get rid of the unnecessary branchings (and also prevent some risks like #2088). Do you have suggestions about what I can do?
(2) It threw me off today that
math.evaluate("i/0").toString()
andmath.evaluate("-(i/0)").toString()
are both "Infinity"---the same "Infinity" as the actually-negatable Infinity. Can we call it something else like ComplexInfinity?(3) Just a sidenote (I already fixed it in my code :)): I think the performance of
math.floor
has some potential to improve:Looking at the code, I think the main bottleneck---when the input is a number---is the two(!) calls of
math.round
(which is understandably pretty slow). I'll suggest the following workaround: when x has type number, we know (hopefully) thatmath.round(x)
is equal to eitherMath.floor(x)
orMath.ceil(x)
, so just try both of them! In the worst case, we callMath.floor
andMath.ceil
once andnearlyEqual
twice, which still seems to be much faster than callingmath.round
.Also, to me it makes more sense if this nearlyEqual business is off by default in
math.floor
. Currently it's off for complex numbers anyway (math.floor(math.Complex(-1e-16, -1e-16)) == Complex(-1, -1)
, as compared withmath.floor(-1e-16) == 0
). I'm leaning towards letting floor be consistent with js, and call the one with nearlyEqualmath.toleratingFloor
or something similar. That's just my personal preference though.Pardon me for the wall of text! Many thanks for this awesome library.
The text was updated successfully, but these errors were encountered: