I did the following bottom_up traversal and got an unexpected result:

>>> e
y*(x + 3) - y
>>> bottom_up(condition(lambda x:x.is_Add, lambda x:S.One))(e)
1

I confirmed with the debugger that Add(-y, y) is created but apparently in 
an unevaluated manner. If it were evaluated, that should have collapsed to 
0 and then there would be no Add to be identified as 1. If I try to slip a 
recalculation of the x I get an error:

>>> cond = lambda x:Add(*Add.make_args(x)).is_Add
>>> bottom_up(condition(cond, lambda x:S.One))(e)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy\rules\traverse.py", line 19, in bottom_up_rl
    return rule(new(type(expr), *map(bottom_up_rl, expr.args)))
  File "sympy\rules\strat_pure.py", line 27, in conditioned_rl
    if cond(expr):
  File "<stdin>", line 1, in <lambda>
  File "sympy\core\cache.py", line 92, in wrapper
    func_cache_it_cache[k] = r = func(*args, **kw_args)
  File "sympy\core\operations.py", line 38, in __new__
    c_part, nc_part, order_symbols = cls.flatten(args)
  File "sympy\core\add.py", line 179, in flatten
    noncommutative = noncommutative or not s.is_commutative
AttributeError: is_commutative

/c

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to