parse_expr with implicit_multiplication and member functions

20 views
Skip to first unread message

Duane Nykamp

unread,
Oct 19, 2014, 1:34:59 AM10/19/14
to sy...@googlegroups.com
Given changes with booleans as discussed in https://groups.google.com/forum/#!topic/sympy/82ls0doW6Nk, I'm trying to develop a new approach to testing the number of True's in Tuple. 

With earlier versions of sympy, if
   thelist=Tuple(False, True, False)
the following worked
   sum(thelist)==1
Now, I'm trying to use the condition
   thelist.count(True)==1
with parse_expr.

The following works as expected

In [25]: parse_expr("(True,False,False).count(True)==1", transformations=(auto_symbol, auto_number, split_symbols))
Out[25]: True

but, if I add implicit_multiplication, it breaks.

In [26]: parse_expr("(True,False,False).count(True)==1", transformations=(auto_symbol, auto_number, split_symbols, implicit_multiplication))
---------------------------------------------------------------------------
[snip]
TypeError: unsupported operand type(s) for *: 'builtin_function_or_method' and 'bool'

I don't suppose there is a way to get implicit_multiplication to realize that .count() is a function and it shouldn't replace the function application with a multiplication.

Or are there better ways of determining the number of True's in the Tuple using parse_expr?

Thanks,
Duane

Aaron Meurer

unread,
Oct 20, 2014, 7:07:22 PM10/20/14
to sy...@googlegroups.com
I'd consider this to be a bug.

Aaron Meurer

>
> Or are there better ways of determining the number of True's in the Tuple
> using parse_expr?
>
> Thanks,
> Duane
>
> --
> 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 sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/fbd3ae7a-1033-4d15-981b-d2b9799cb8be%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages