mathlive icon indicating copy to clipboard operation
mathlive copied to clipboard

even roots of negative numbers evaluate incorrectly

Open mdavis7168 opened this issue 9 months ago • 1 comments

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());

mdavis7168 avatar Apr 04 '25 18:04 mdavis7168

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 avatar Apr 06 '25 14:04 arnog