当我在 Python 和 NumPy 中取第 n 个根时,我实际上得到了 n 个现有根中的哪一个?

When I take an nth root in Python and NumPy, which of the n existing roots do I actually get?

fundamental theorem of algebra得出的公式z^n=a存在n个复根,其中a为实数,n为正整数,z为复数。除了复数之外,一些根也将是实数(即 a+bi,其中 b=0)。

一个有多个实根的例子是 z^2=1,我们得到 z = ±sqrt(1) = ± 1。解 z = 1 是立竿见影的。解z = -1由z = sqrt(1) = sqrt(-1 * -1) = I * I = -1得到,I为虚数单位

在 Python/NumPy(以及许多其他编程语言和程序包)中,只有一个值被 returned。下面是 5^{1/3} 的两个例子,它有 3 个根。

>>> 5 ** (1 / 3)
1.7099759466766968
>>> import numpy as np
>>> np.power(5, 1/3)
1.7099759466766968

对于我的用例来说,只有一个可能的根被 returned 不是问题,但是知道“哪个”根会提供信息在 Python 和 NumPy 的上下文中系统地计算。也许有一个 (ISO) 标准说明应该 returned 哪个根,或者可能有一个常用的算法恰好 return 一个特定的根。我想象过一个等价物class,例如“实值解的最大值”,但我不知道。

问题:当我在 Python 和 NumPy 中取第 n 个根时,我实际上得到了 n 个现有根中的哪一个?

由于恒等式 xᵃ = exp(a⋅log(x)) 通常用于定义一般幂,因此您将获得与所选 branch cut of the complex logarithm.

相对应的根

关于这个,numpy documentation 说:

For real-valued input data types, log always returns real output. For each value that cannot be expressed as a real number or infinity, it yields nan and sets the invalid floating point error flag.

For complex-valued input, log is a complex analytical function that has a branch cut [-inf, 0] and is continuous from above on it. log handles the floating-point negative zero as an infinitesimal negative number, conforming to the C99 standard.

例如,np.power(-1 +0j, 1/3) = 0.5 + 0.866j = np.exp(np.log(-1+0j)/3)