Updates:
        Labels: -NeedsBetterPatch NeedsReview

Comment #38 on issue 1923 by smi...@gmail.com: count_ops doesn't return a count (by default)
http://code.google.com/p/sympy/issues/detail?id=1923

How would people feel about making the non-visual count_ops just return a slightly modified tree length? This is much simpler (and about 3X faster) than trying to get something mathematically correct but still serves the purpose of providing a metric for comparing expressions.

The visual option tries to give something that is visually correlated to what you would see when printing an expression:

    >>> count_ops(I-1, visual=1) # I PLUS neg. one TIMES 1
    Add + Mul

The existing non-visual count directly correlates to that:

    >>> count_ops(I-1)
    2

But since such a number would likely be used for comparison purposes, the tree length is quicker to compute

    >>> from sympy.utilities.iterables import preorder_traversal as tree
    >>> list(tree(I-1))
    [-1 + I, -1, I]
    >>> count_ops(I-1, quick=1)
    4

Note the 4 because of the negative 1. If there is a +1 that has a shorter op count:

    >>> count_ops(I+1, quick=1)
    3

And if the 1 is replaced with 1/2 the count goes up:

    >>> count_ops(I-S.Half, quick=1)
    5

These corrections for Rationals are the only correction to the tree length made by the quick calculation.

Right now in [ https://github.com/sympy/sympy/pull/23 ] I've added a `quick` flag to allow the tree length calculation (which is about 3X faster). My preference is to just make the non-visual return the modified tree length.

Does anyone else have a preference?

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

Reply via email to