首页 文章

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

提问于
浏览
1

我在python或python lib中寻找相当于Mathematicas RootApproximant函数:https://reference.wolfram.com/language/ref/RootApproximant.html

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

RootApproximant[1.414213] -> sqrt(2)

谢谢!

2 回答

  • 3

    sympy.nsimplify(内部使用 mpmath.identify

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

    您可能正在寻找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)'
    

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

相关问题