>>> from sympy.parsing.sympy_parser import parse_expr
>>> parse_expr("(-6x^2-x-7)(2x^3+3x^2-2x-5)")
Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    parse_expr("(-6x^2-x-7)(2x^3+3x^2-2x-5)")
  File "C:\Python34\lib\site-packages\sympy\parsing\sympy_parser.py", line 
757, in parse_expr
    return eval_expr(code, local_dict, global_dict)
  File "C:\Python34\lib\site-packages\sympy\parsing\sympy_parser.py", line 
691, in eval_expr
    code, global_dict, local_dict)  # take local objects in preference
  File "<string>", line 1
    (-Integer (6 )Symbol ('x' )^Integer (2 )-Symbol ('x' )-Integer (7 
))(Integer (2 )Symbol ('x' )^Integer (3 )+Integer (3 )Symbol ('x' )^Integer 
(2 )-Integer (2 )Symbol ('x' )-Integer (5 ))
                       ^
SyntaxError: invalid syntax
>>> 

在 2014年10月9日星期四UTC+8上午3时37分07秒,Aaron Meurer写道:
>
> Have a look at parse_expr() in sympy.parsing.sympy_parser. 
>
> Aaron Meurer 
>
> On Wed, Oct 8, 2014 at 8:42 AM, Mateusz Paprocki <[email protected] 
> <javascript:>> wrote: 
> > Hi, 
> > 
> > On 8 October 2014 12:05,  <[email protected] <javascript:>> wrote: 
> >> Is there any function in SymPy can take this TEX command as an input 
> >> 
> >> (-6x^2-x-7)(2x^3+3x^2-2x-5) 
> >> 
> >> to find the derivative? 
> > 
> > I wanted to suggest a mathematica parser for this: 
> > 
> > In [1]: import sympy.parsing.mathematica as m 
> > 
> > In [2]: m.parse("(-6x^2-x-7)(2x^3+3x^2-2x-5)") 
> > Out[2]: '(-6*x**2-x-7)*(2*x**3+3*x**2-2*x-5)' 
> > 
> > In [3]: eval(_) 
> > Out[3]: 
> > ⎛     2        ⎞ ⎛   3      2          ⎞ 
> > ⎝- 6⋅x  - x - 7⎠⋅⎝2⋅x  + 3⋅x  - 2⋅x - 5⎠ 
> > 
> > But there is bug there and the above output requires the following 
> patch: 
> > 
> > diff --git a/sympy/parsing/mathematica.py b/sympy/parsing/mathematica.py 
> > index f86d59a..eeb12f7 100644 
> > --- a/sympy/parsing/mathematica.py 
> > +++ b/sympy/parsing/mathematica.py 
> > @@ -39,7 +39,7 @@ def parse(s): 
> >          (r"\A\((.+)\)([\w\.].*)\Z",  # Implied multiplication - (a)b 
> >          lambda m: "(" + parse(m.group(1)) + ")*" + parse(m.group(2))), 
> > 
> > -        (r"\A([\d\.]+)([a-zA-Z].*)\Z",  # Implied multiplicatin - 2a 
> > +        (r"\A([+-]?[\d\.]+)([a-zA-Z].*)\Z",  # Implied multiplicatin - 
> 2a 
> >          lambda m: parse(m.group(1)) + "*" + parse(m.group(2))), 
> > 
> >          (r"\A([^=]+)([\^\-\*/\+=]=?)(.+)\Z",  # Infix operator 
> > 
> > Mateusz 
> > 
> >> -- 
> >> 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] <javascript:>. 
> >> To post to this group, send email to [email protected] 
> <javascript:>. 
> >> 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/04e0cbd4-5b6b-4418-8166-024a0729aff8%40googlegroups.com.
>  
>
> >> For more options, visit https://groups.google.com/d/optout. 
> > 
> > -- 
> > 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] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > 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/CAGBZUCZfJVXw27Rh0U31ST9tU%3DwZbkuqUS792ff364JYvdG%2BHg%40mail.gmail.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/041204f1-5a4d-4b1a-ac0e-fecf690a037a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to