You might want to look at the compare_ode_sol() (and the key equivalent rewrite 
I have at 
http://github.com/asmeurer/sympy/commit/2c5167990473ca4079f334214ffe0c898b18cbda).
  It is specifically for solutions given from dsolve(), but the heuristic 
involves seeing if the expression contains unevaluated Integral's, is or isn't 
solved for f(x), and finally, the length of str(expr).  

len(str(expr)) is probably the simplest way to check this.  I never considered 
looking at the depth of the expression, though.  

By the way, you can probably make that operation faster first, by using the 
Poly class, and second, by somehow making det() do intermediate simplifications 
(things should actually already be better in this respect with the new polys).  

Aaron Meurer
On May 4, 2010, at 3:28 PM, Bastian Weber wrote:

> Hi,
> 
> is there any (easy) way to get an idea of how complex a given expression is?
> 
> I saw that "implementing complexity measures" was among the ideas for
> the GSoC2009. I dont know how sophisticated this was planned to be.
> 
> My naive approach is the following:
> 
> def depth(expr):
>    if expr.is_Atom:
>        return 0
>    else:
>        return max(map(depth, expr.args))+1
> 
> 
> (I have a tree with many levels of subbranches in mind.)
> 
> Any comments?
> 
> The background is: I am trying to investigate why expand() hangs or
> needs very long time if applied to determinants of polynomial matrices
> (just 4-by-4).
> 
> 
> Regards,
> Bastian
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to