估计 SymPy 函数的进度 [英] Estimating progress of SymPy functions

查看:26
本文介绍了估计 SymPy 函数的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发出了一个 sympy 命令来求解某个方程或其他方程.现在已经过去几天了,我不知道什么时候才能完成.

I have issued a sympy command to solve some equation or another. It's been a couple of days now, and I have no idea when to expect it to be finished.

我可以让 sympy 记录对 .solvers.solve 的调用进度吗?如果不是,我如何估计 sympy 求解一组方程所需的最坏情况时间?

Can I get sympy to log the progress of a call to, say, .solvers.solve? If not, how can I estimate the worst-case time that sympy will need to solve some set of equations?

例如

import sympy, sympy.solvers
from sympy import sqrt

a,c,d,e,f,x = tuple(map(sympy.Symbol, 'acdefx'))

# when will this finish?
print(sympy.solvers.solve(
    3*sqrt((16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2 + (-8*a**2*c*x - 2*a*e + 2*a*x + 2*a*sqrt(16*a**2*c**2*
x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) + d)**2)**3/(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2)**3)*(a*(2*c
*(8*a**2*c*x + 2*a*e - 2*a*x - d) - (4*a*c - 1)*sqrt(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2))*(-8*a**2*c*x - 2*a*e + 2*a
*x + 2*a*sqrt(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) + d) + c*(8*a**2*c*x + 2*a*e - 2*a*x - d)*sqrt(16*a**2*c**2*x**2 +
 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2))*(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2)/((a*(4*a*c - 1)*(16*a**2*c**
2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) - c*(8*a**2*c*x + 2*a*e - 2*a*x - d)**2)*(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*
d*x - 4*c*f + e**2 + (-8*a**2*c*x - 2*a*e + 2*a*x + 2*a*sqrt(16*a**2*c**2*x**2 + 8*a*c*e*x - 4*a*c*x**2 - 4*c*d*x - 4*c*f + e**2) + d)**2))
,x))

推荐答案

SymPy 不提供任何完成时间估计.它的一些算法依赖于以各种方式重写表达式;如果结果表达式变得更复杂而不是更复杂,则此过程可能永远不会终止.

SymPy does not provide any time estimate for completion. Some of its algorithms rely on rewriting an expression in various ways; it is possible for this procedure to never terminate if the resulting expressions become more complex instead of less.

在具体示例中,分解表达式和求解单个因子会有所帮助.

In the specific example, factoring the expression and solving individual factors helps.

factors = expr.factor().args
solve(factors[4], x)   # "4" by trial and error

返回

[(c*(-2*a*e + d) - sqrt(c*(16*a**2*c**2*f - 4*a*c*d*e - 4*a*c*f + a*e**2 + c*d**2)))/(2*a*c*(4*a*c - 1)),
 (c*(-2*a*e + d) + sqrt(c*(16*a**2*c**2*f - 4*a*c*d*e - 4*a*c*f + a*e**2 + c*d**2)))/(2*a*c*(4*a*c - 1))]

这篇关于估计 SymPy 函数的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆