是否有相当于python / scipy中的Mathematicas RootApproximant函数,numpy,sympy?

时间:2021-08-12 21:21:10

I am looking for an equivalent to Mathematicas RootApproximant function in python or a python lib: https://reference.wolfram.com/language/ref/RootApproximant.html

我正在寻找与python或python库中的Mathematicas RootApproximant函数相当的函数:https://reference.wolfram.com/language/ref/RootApproximant.html

Basically, this function finds the algebraic root of a numeric, e.g.

基本上,该函数找到数字的代数根,例如,

RootApproximant[1.414213] -> sqrt(2)

Thanks!

谢谢!

2 个解决方案

#1


3  

Look at sympy.nsimplify (which uses mpmath.identify internally)

看看sympy.nsimplify(内部使用mpmath.identify)

>>> nsimplify(1.414213, tolerance=1e-6)
√2

#2


0  

You might be looking for mpmath.identify():

您可能正在寻找mpmath.identify():

In [295]: import mpmath as mpm

In [296]: mpm.identify(1.414213)
Out[296]: 'sqrt(((4-sqrt(0))/2))'

In [297]: mpm.identify(3.141592/2)
Out[297]: '(2**(157/183)*3**(67/183)*5**(152/183))/(7**(59/61))'

In [298]: mpm.identify(3.141592/2,['pi'])
Out[298]: 'pi*((4-sqrt(0))/8)'

It's obviously not as clear-cut as Mathematica's implementation, but I'm sure it beats any manual attempt to do this job. And the features are surely different (and more scarce), so you should check out the manual if it fits your needs.

它显然不像Mathematica的实现那么明确,但我确信它胜过任何手动尝试这项工作。功能肯定不同(而且更加稀缺),因此如果符合您的需要,您应该查看手册。

#1


3  

Look at sympy.nsimplify (which uses mpmath.identify internally)

看看sympy.nsimplify(内部使用mpmath.identify)

>>> nsimplify(1.414213, tolerance=1e-6)
√2

#2


0  

You might be looking for mpmath.identify():

您可能正在寻找mpmath.identify():

In [295]: import mpmath as mpm

In [296]: mpm.identify(1.414213)
Out[296]: 'sqrt(((4-sqrt(0))/2))'

In [297]: mpm.identify(3.141592/2)
Out[297]: '(2**(157/183)*3**(67/183)*5**(152/183))/(7**(59/61))'

In [298]: mpm.identify(3.141592/2,['pi'])
Out[298]: 'pi*((4-sqrt(0))/8)'

It's obviously not as clear-cut as Mathematica's implementation, but I'm sure it beats any manual attempt to do this job. And the features are surely different (and more scarce), so you should check out the manual if it fits your needs.

它显然不像Mathematica的实现那么明确,但我确信它胜过任何手动尝试这项工作。功能肯定不同(而且更加稀缺),因此如果符合您的需要,您应该查看手册。