Bug in parse expression

67 views
Skip to first unread message

Paul Royik

unread,
Feb 19, 2015, 2:44:37 AM2/19/15
to sy...@googlegroups.com
Just noticed, that official example works:
from sympy.parsing.sympy_parser import (parse_expr, standard_transformations, implicit_multiplication_application) parse_expr("10sin**2 x**2 + 3xyz + tan theta",transformations=(standard_transformations +(implicit_multiplication_application,)))

But 
parse_expr("10sin**(120*x) x**2 + 3xyz + tan theta",transformations=(standard_transformations +(implicit_multiplication_application,)))
raises exception (see sine exponent):

TypeError: unbound method could_extract_minus_sign() must be called with Symbol instance as first argument (got nothing instead)

Aaron Meurer

unread,
Feb 19, 2015, 10:35:21 PM2/19/15
to sy...@googlegroups.com
A simpler example is sin**(2*x) x.

Aaron Meurer
> --
> 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/b88049b4-502a-4f00-9796-506188245ebe%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

David Li

unread,
Feb 23, 2015, 9:34:22 AM2/23/15
to sy...@googlegroups.com
For Aaron's case the expression is turned into

sin (Symbol )**(Integer (2 )('x' ))*Symbol ('x' )

For the original case the expression is turned into

Integer (10 )*sin (Symbol )**(Integer (120 )('x' ))*Symbol ('x' )**Integer (2 )+Integer (3 )*Symbol ('x' )*Symbol ('y' )*Symbol ('z' )+tan (Symbol ('theta' ))

so the exponent/argument is not being properly captured. IIRC because this works at the token level it only handles the case where the exponent is something simple like just a symbol or integer, and not a product of symbols and integers. This might make sense to reimplement as an AST transformation instead, or otherwise the transformation would have to do some actual parsing of the tokens.

David
Reply all
Reply to author
Forward
0 new messages