On Tue, May 4, 2010 at 4:15 PM, Bastian Weber <bastian.we...@gmx-topmail.de> wrote: > >> >> 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 > > > > Thats very cool. > Its what I was looking for. > > >> >> 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. > > cout_ops(False) does almost exactly the same as my count_branches from > my last mail. (I should check for new mail before sending a mail to the > list...) > > > The main difference is that count_ops seems to be faster. > > I dont see any useful possibility to integrate the depth function with > count_ops and I doubt that anybody might want to use the former. > > Concerning the docs / doctests for count_ops I do not understand the > current situation: > > > in ipython > > Symbol.count_ops.__doc__ == None > > evaluates to True > > but on the other hand, if I go to the source file, I can read the following: > > """ Return the number of operations in expressions. > > Examples: > >>> from sympy.abc import a, b, x > >>> from sympy import sin > >>> (1+a+b**2).count_ops() > POW + 2*ADD > >>> (sin(x)*x+sin(x)**2).count_ops() > 2 + ADD + MUL + POW > > """ > > > __version__ = '0.7.0-git' > > I am confused about this.
Ah, I see. It's because it's only documented in Basic, but you use it for Symbol. The count_ops in all classes except Basic should be renamed to _count_ops. The docstring in Basic should also include the symbolic=False option (that should probably be the default). 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.