-
-
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
cbrt(::Complex) #36534
Comments
Hmm, one issue with the implementation above is that it is inconsistent with the julia> Base.cbrt(z::Complex) = cbrt(abs(z)) * cis(angle(z)/3)
julia> cbrt(-3)
-1.4422495703074083
julia> cbrt(-3+0im)
0.7211247851537043 + 1.2490247664834064im
julia> (-3+0im)^(1//3)
0.7211247851537042 + 1.2490247664834064im It's not obvious to me what definition we would want for |
Having this consistent with real input will necessarily put a branch cut at a non-standard place (different than R- used for the other usual functions). If you compute the cube root of a complex number you will most likely want to specify your branch cut explicitly, so I don't think this function should be defined at all. |
In Mathematica, cbrt is only defined to return the real value of cuberoot. I don't think it is a good idea to define cbrt for complex value because it would cause discontinuity (depending on whether the arguement is Real or Complex). But certainly the documentation for crbt should be updated to mention that cbrt(-27) == -3 while (-27+0im)^(1/3) == 1.5 + 2.598076211353316im so cbrt will only return a real result (and never a complex result) |
I'd say the most sensible definition of Here's an implementation based on this definition.
Tests, imitating the tests for
|
Any chance this will get approved if I turn the above into a PR? |
I think that we should be cautious about implementing this, since the "correct" choice is non-obvious and the difference from |
I've been thinking about this some more in the context of #47565, and it seems like there is some value in defining a cbrt(z::Complex) = signbit(real(z)) ? -(-z)^(1//3) : z^(1//3) For example, this would allow one to define a real cube root of a diagonalizable real matrix |
Actually there would be three answers (3 cube roots in the complex domain) in this case one of which would lie along the real axis. |
@stevengj Please check my Draft PR (#47860). I think to make |
…ented for complex and real numbers.
@theWiseAman, we don't want an array of roots. The whole point of |
Ping on this. Ran into this today |
@MilesCranmer, what behavior did you want |
I won’t need a particular branch cut for my work as it would be for SymbolicRegression.jl where the search could learn an additional rotation in the complex plane if needed. (i.e., any branch cut would do) I suppose my vote would be for matching the same branch cut as |
That choice seems out of the question for me, since it would be inconsistent with But then, having |
Yeah it actually looks like this – a lack of any implementation – seems to be the standard:
|
As noted on discourse, this method is missing.
An obvious (but inconsistent, see below) implementation would be:
but maybe there is a faster way?
Might also be worth having a fallback method too:(this is inconsistent too)The text was updated successfully, but these errors were encountered: