sympify with embedded strings ?

7 views
Skip to first unread message

Roberto Colistete Jr.

unread,
Aug 30, 2011, 3:15:21 PM8/30/11
to sympy
Hi,

I was using SymPy 0.6.7 (on Ubuntu, etc) and now I have installed
version 0.7.1.

Until SymPy v0.6.7, the following was working well :

sympify(u'Limit(sin(x),x,0,dir=\"-\")')

But with SymPy 0.7.0 or 0.7.1, it gives

"SympifyError: SympifyError: 'could not parse u\'Limit(sin(x),x,
0,dir="-")\''

I need this feature to update "Limit" (http://
www.robertocolistete.net/Limit/) to SymPy 0.7.1 and release it.

Thanks in advance, Roberto

Aaron Meurer

unread,
Aug 31, 2011, 11:20:37 AM8/31/11
to sy...@googlegroups.com
Thanks for reporting this. Can you open an issue in our issue tracker
(http://code.google.com/p/sympy/issues/list) for it? I bisected the
regression to the commit

commit d00c8b214520604fb65bde426cbaf4f4b30dbba0
Author: Mateusz Paprocki <mat...@gmail.com>
Date: Tue Jun 7 01:55:11 2011 -0700

Use new parse_expr() in sympify() (#871, #976)

This makes sympify() independent of parsing tools in Python's
standard library and makes it much simpler. parse_expr() uses
modified tokenize module to split an input string into tokens,
then it applies SymPy-specific transformations, untokenizes
transformed token sequence and passes resulting string directly
to eval(). All transformations from old sympify() are supported,
but lambda -> Lambda conversion. It is possible to implement
this in the new parse_expr(), but it would make it a little more
complex, so for now I skipped it, as this kind of transformation
isn't used very often anyway (lambda tests were XFAILed).

This also fixes issue #976 and allows sympify() to handle very
large expressions, e.g.:

In [1]: e = expand((x + y + z)**50)

In [2]: s = str(e)

In [3]: %time sympify(s) == e
CPU times: user 27.13 s, sys: 0.09 s, total: 27.22 s
Wall time: 27.22 s
Out[4]: True

Previously it raised RuntimeError. Speed could be improved, by
improving tokenize module.

Old parsers (ast and ast2.4) are still available and we could
use them in future to make a more advanced version of sympify()
that doesn't care about speed and platform compatibility, but
about generality of transformations, thus we could restore
lambda support this way (e.g. sympify("...", parser="ast")).

Aaron Meurer

> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
>

Roberto Colistete Jr.

unread,
Aug 31, 2011, 5:14:56 PM8/31/11
to sympy
Thanks, Aaron Meurer.

I have opened a new issue :
http://code.google.com/p/sympy/issues/detail?id=2663&q=sympify&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary%20Stars

For my use, I have succeeded with a workaround in "Limit" (passing
some functions as "locals=locals()" argument for "sympify", it is not
elegant but works.
Reply all
Reply to author
Forward
0 new messages