Does sympify has an upper limit of number of variables?

58 views
Skip to first unread message

Hong Xu

unread,
Jul 21, 2015, 11:25:26 PM7/21/15
to sympy
Hi,

When I tried to run

    print(sympify('a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N'))

I got the error:


Traceback (most recent call last):
  File "test.py", line 6, in <module>
    print(sympify('a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N'))
  File "/home/user/.local/lib/python3.4/site-packages/sympy/core/sympify.py", line 317, in sympify
    expr = parse_expr(a, local_dict=locals, transformations=transformations, evaluate=evaluate)
  File "/home/user/.local/lib/python3.4/site-packages/sympy/parsing/sympy_parser.py", line 820, in parse_expr
    return eval_expr(code, local_dict, global_dict)
  File "/home/user/.local/lib/python3.4/site-packages/sympy/parsing/sympy_parser.py", line 733, in eval_expr
    code, global_dict, local_dict)  # take local objects in preference
  File "<string>", line 1, in <module>
  File "/home/user/.local/lib/python3.4/site-packages/sympy/logic/boolalg.py", line 34, in __or__
    return Or(self, other)
  File "/home/user/.local/lib/python3.4/site-packages/sympy/core/operations.py", line 404, in __new__
    _args = frozenset(cls._new_args_filter(args))
  File "/home/user/.local/lib/python3.4/site-packages/sympy/logic/boolalg.py", line 374, in _new_args_filter
    for x in args:
  File "/home/user/.local/lib/python3.4/site-packages/sympy/core/operations.py", line 402, in <genexpr>
    args = (_sympify(arg) for arg in args)
  File "/home/user/.local/lib/python3.4/site-packages/sympy/core/sympify.py", line 350, in _sympify
    return sympify(a, strict=True)
  File "/home/user/.local/lib/python3.4/site-packages/sympy/core/sympify.py", line 272, in sympify
    raise SympifyError(a)
sympy.core.sympify.SympifyError: SympifyError: <function N at 0x7f3e5c913620>

Is there a hard coded number of variables sympify can handle, or a different reason?

Thanks!

Hong

Amit Saha

unread,
Jul 21, 2015, 11:33:25 PM7/21/15
to sy...@googlegroups.com
The error you see seem to be coming from the last symbol you have,
"N". If I replace it by "K" (say):

>>> print(sympify('a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|K'))
Or(A, B, C, D, E, F, G, H, I, J, K, L, M, a, b, c, d, e, f, g, h, i,
j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)

sympy has a function, "N":
>>> sympy.N
<function N at 0x7f2437adfb70>
>>> sympy.N.__module__
'sympy.core.evalf'


Best,
Amit.

Jason Moore

unread,
Jul 21, 2015, 11:33:51 PM7/21/15
to sy...@googlegroups.com
"N" is a function in SymPy, so is "S". So sympify is trying to transform those into a function. You can avoid the variables that clash with top level sympy functions as work around.

--
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+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/239d6ad7-f46a-422e-b3f6-f32ca85a5f81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Meurer

unread,
Jul 22, 2015, 1:42:18 PM7/22/15
to sy...@googlegroups.com
The docstring of sympify() explains this issue in more detail and how to work around it. http://docs.sympy.org/latest/modules/core.html#sympy.core.sympify.sympify

Aaron Meurer

Reply all
Reply to author
Forward
0 new messages