On Tue, May 4, 2010 at 2:28 PM, Bastian Weber <bastian.we...@gmx-topmail.de> 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?
One undocumented function is count_ops: In [1]: e = x**2+y+z In [2]: e.count_ops(False) Out[2]: 3 In [3]: e = x**2+y+z+sin(z) In [4]: e.count_ops(False) Out[4]: 5 In [5]: e = x**2+y+z+sin(z)**2 In [6]: e.count_ops(False) Out[6]: 6 See also the tests in sympy/core/tests/test_count_ops.py I think it's similar to your function too. It'd be cool to maybe write some documentation and example doctests for this, and/or integrate it with your depth() function. Ondrej -- 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.