Skip to content

even roots of negative numbers evaluate incorrectly #2675

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

Open
mdavis7168 opened this issue Apr 4, 2025 · 1 comment
Open

even roots of negative numbers evaluate incorrectly #2675

mdavis7168 opened this issue Apr 4, 2025 · 1 comment
Assignees
Labels

Comments

@mdavis7168
Copy link

Square roots of negative reals correctly evaluate, e.g. sqrt(-1) = i, sqrt(-4) = 2i, etc. For larger even nth roots, e.g. 4, 6, 8 etc, nth roots of negative numbers evaluate as though the argument were positive. E.g.
["Root", -1, 4] -> 1
["Root", -16, 4] -> 2
(-64)^{1/6} -> 2

These were evaluated on the CE demo site, https://cortexjs.io/compute-engine/demo/, using code like

const expr = ce.parse("(-64)^{1/6}");
console.info(expr.N());

or

const expr = ce.box(["Root", -1, 4])
console.info(expr.N());
@arnog
Copy link
Owner

arnog commented Apr 6, 2025

The Root function should give the same results as the Surd function in Mathematica.
Specifically, it should return:

  • the real-valued nth root of real-valued x for odd n
  • the principal nth root for non-negative real-valued x and even n

In other cases, it should return NaN.

Note that the ComplexRoots function will return complex-valued roots.

The ["Power", x, ["Divide", 1, n]] expression should return the principal complex root of $$\sqrt[n]{x}$$.

@arnog arnog self-assigned this Apr 6, 2025
@arnog arnog added the bug label Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants