Mathematica parser error ,bug ?

55 views
Skip to first unread message

Lee Philip

unread,
Nov 27, 2014, 7:42:53 AM11/27/14
to sy...@googlegroups.com
test code here, error encountered there .


what I want to do here is just convert it to a Python acceptable expression ,is there an easy way ?

Francesco Bonazzi

unread,
Nov 27, 2014, 8:28:11 AM11/27/14
to sy...@googlegroups.com
The regex parser fails to recognize in expressions such as 1/(4x-1), that 4x is 4 times x.

I tried to call M("1/(4x - 1)") and I got the following transformation:

Integer (1 )/(Integer (4 )Symbol ('x' )-Integer (1 ))

Obviously, Integer(4) Symbol('x') is not valid, as an asterisk (*) is missing to represent the multiplication.

A quick makeshift fix:

your_mathematica_expr = '((-2x+5)(4x-1)-4(-x^2+5x+1))/(4x-1)^2'
new_math_expr = re.sub("([0-9])\ *([a-zA-Z])", "\\1 * \\2", your_mathematica_expr)
M
(new_math_expr)

Francesco Bonazzi

unread,
Nov 27, 2014, 8:29:16 AM11/27/14
to sy...@googlegroups.com


On Thursday, November 27, 2014 2:28:11 PM UTC+1, Francesco Bonazzi wrote:

your_mathematica_expr = '((-2x+5)(4x-1)-4(-x^2+5x+1))/(4x-1)^2'
new_math_expr = re.sub("([0-9])\ *([a-zA-Z])", "\\1 * \\2", your_mathematica_expr)
M
(new_math_expr)


Remember import re to use the re module.

Richard Fateman

unread,
Nov 27, 2014, 2:46:39 PM11/27/14
to sy...@googlegroups.com
Does sympy really spell simplify  without the L?

Richard Fateman

unread,
Nov 27, 2014, 2:58:59 PM11/27/14
to sy...@googlegroups.com
answering my own question ... oh
it is creating a sympy object, not simplifying.
Sorry for the noise.
'RJF

redstone-cold

unread,
Nov 27, 2014, 10:02:38 PM11/27/14
to sy...@googlegroups.com
thanks for your kind help ! then it is surely a bug of the parser.
--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/R5r3lWAc2jo/unsubscribe.
To unsubscribe from this group and all its topics, 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/094ec242-37e7-42c4-80c9-497f30e447b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Lee Philip

unread,
Nov 27, 2014, 11:16:02 PM11/27/14
to sy...@googlegroups.com
I reported the bug here https://github.com/sympy/sympy/issues/8535

在 2014年11月27日星期四UTC+8下午8时42分53秒,Lee Philip写道:

Francesco Bonazzi

unread,
Nov 28, 2014, 5:57:12 AM11/28/14
to sy...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages