Hi Lee, On Sat, Nov 22, 2014 at 4:04 AM, Lee Philip <redstone-c...@163.com> wrote: > is 'x sin(1/x)+abs(x)' or 'x sin(1/x)+|x|' or 'x Sin[1/x] + Abs[x]' sympy > acceptable? > > I got exceptions by these expressions ,wonder is this a bug or not ?
You seem to found a bug in the Mathematica parser, i.e. this works: In [7]: M("x*Sin[x]") Out[7]: x⋅sin(x) In [9]: M("Sin[1/x]") Out[9]: ⎛1⎞ sin⎜─⎟ ⎝x⎠ But this fails: In [10]: M("x*Sin[1/x]") --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-10-e58ebb4f8e06> in <module>() ----> 1 M("x*Sin[1/x]") /home/ondrej/repos/sympy/sympy/parsing/mathematica.py in mathematica(s) 6 7 def mathematica(s): ----> 8 return sympify(parse(s)) 9 10 /home/ondrej/repos/sympy/sympy/core/sympify.pyc in sympify(a, locals, convert_xor, strict, rational, evaluate) 315 try: 316 a = a.replace('\n', '') --> 317 expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate) 318 except (TokenError, SyntaxError) as exc: 319 raise SympifyError('could not parse %r' % a, exc) /home/ondrej/repos/sympy/sympy/parsing/sympy_parser.pyc in parse_expr(s, local_dict, transformations, global_dict, evaluate) 818 code = compile(evaluateFalse(code), '<string>', 'eval') 819 --> 820 return eval_expr(code, local_dict, global_dict) 821 822 /home/ondrej/repos/sympy/sympy/parsing/sympy_parser.pyc in eval_expr(code, local_dict, global_dict) 731 """ 732 expr = eval( --> 733 code, global_dict, local_dict) # take local objects in preference 734 735 return expr <string> in <module>() TypeError: 'Symbol' object has no attribute '__getitem__' I reported it here: https://github.com/sympy/sympy/issues/8501 However, if you just want to use sympy, don't use the Mathematica parser, but rather sympy directly, like this: In [11]: var("x") Out[11]: x In [12]: x*sin(1/x)+abs(x) Out[12]: ⎛1⎞ x⋅sin⎜─⎟ + │x│ ⎝x⎠ In [13]: _.diff(x) Out[13]: d d ⎛1⎞ re(x)⋅──(re(x)) + im(x)⋅──(im(x)) cos⎜─⎟ dx dx ⎛1⎞ ⎝x⎠ ───────────────────────────────── + sin⎜─⎟ - ────── │x│ ⎝x⎠ x Ondrej > > > > test code here > > http://codepad.org/NyO5tj1I > > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@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/988b0ad3-bb8d-4ba6-9509-ad395f4353d2%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 sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@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/CADDwiVBjW3%3DM3Gfh4auR_-RepnWK2KqQio%3DMb68hLOnMhxHRgQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.