python - (-6x^2-x-7)(2x^3+3x^2-2x-5) as input in SymPy -
python - (-6x^2-x-7)(2x^3+3x^2-2x-5) as input in SymPy -
is there function in sympy can take thisexpression input
(-6x^2-x-7)(2x^3+3x^2-2x-5)
to find derivative?
there variety of parsers in parsing
module.
there may improve way, works:
from sympy import * sympy.parsing.sympy_parser import parse_expr sympy.parsing.sympy_parser import standard_transformations, \ implicit_multiplication_application transformations = (standard_transformations + ( implicit_multiplication_application, ) ) >>> var('x') x >>> s = '(-6x^2-x-7)(2x^3+3x^2-2x-5)' >>> parse_expr( s.replace( "^", "**" ), transformations = transformations ) (-6*x**2 - x - 7)*(2*x**3 + 3*x**2 - 2*x - 5) >>> _.diff(x) (-12*x - 1)*(2*x**3 + 3*x**2 - 2*x - 5) + (-6*x**2 - x - 7)*(6*x**2 + 6*x - 2)
but see rule in mathematica
parser needs tweak , can as:
from sympy.parsing.mathematica import mathematica m sympy.abc import x m( '(-6x^2-x-7)(2x^3+3x^2-2x-5)' ).diff(x)
the mathematica
parser gives error
from sympy.parsing.mathematica import mathematica m sympy.abc import x m( '(-6x^2-x-7)(2x^3+3x^2-2x-5)' ).diff(x) traceback (most recent phone call last): file "c:\python34\lib\site-packages\sympy\core\sympify.py", line 313, in sympify expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate) file "c:\python34\lib\site-packages\sympy\parsing\sympy_parser.py", line 757, in parse_expr homecoming 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
during handling of above exception, exception occurred:
traceback (most recent phone call last): file "<pyshell#2>", line 1, in <module> m('(-6x^2-x-7)(2x^3+3x^2-2x-5)').diff(x) file "c:\python34\lib\site-packages\sympy\parsing\mathematica.py", line 8, in mathematica homecoming sympify(parse(s)) file "c:\python34\lib\site-packages\sympy\core\sympify.py", line 315, in sympify raise sympifyerror('could not parse %r' % a, exc) sympy.core.sympify.sympifyerror: sympify of look 'could not parse '(-6x**2-x-7)*(2*x**3+3*x**2-2*x-5)'' failed, because of exception beingness raised: syntaxerror: invalid syntax (<string>, line 1)
python scipy latex sympy tex
Comments
Post a Comment