These are chat archives for symengine/symengine

2nd
Aug 2017
Shikhar Jaiswal
@ShikharJ
Aug 02 2017 09:43
@isuruf '0' sympifies just fine in SymEngine.py and I'm unable to find out why the current scenario gives an output similar to passing '0' to _sympify.
Isuru Fernando
@isuruf
Aug 02 2017 09:43
>>> from symengine import *
>>> sympify("0")
0
>>> sympify("'0'")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "symengine/lib/symengine_wrapper.pyx", line 273, in symengine.lib.symengine_wrapper.sympify (/home/isuru/projects/symengine.py/build/lib.linux-x86_64-2.7/symengine/lib/symengine_wrapper.cpp:10245)
RuntimeError: '0' is not a symbol or numeric
Shikhar Jaiswal
@ShikharJ
Aug 02 2017 09:49
That I think is an error thrown up in SymEngine. Should this be fixed there or in SymEngine.py?
Isuru Fernando
@isuruf
Aug 02 2017 10:07
That's not an error in symengine. It's a user error
>>> _sympify("'0'")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "symengine/lib/symengine_wrapper.pyx", line 322, in symengine.lib.symengine_wrapper._sympify (/home/isuru/projects/symengine.py/build/lib.linux-x86_64-2.7/symengine/lib/symengine_wrapper.cpp:11155)
  File "symengine/lib/symengine_wrapper.pyx", line 251, in symengine.lib.symengine_wrapper.sympy2symengine (/home/isuru/projects/symengine.py/build/lib.linux-x86_64-2.7/symengine/lib/symengine_wrapper.cpp:10127)
symengine.lib.symengine_wrapper.SympifyError: sympy2symengine: Cannot convert '"'0'"' to a symengine type.
Wait, if you want to sympify a string you have to use sympify instead of _sympify
Shikhar Jaiswal
@ShikharJ
Aug 02 2017 10:09
Yes, and I am using sympify only.
Isuru Fernando
@isuruf
Aug 02 2017 10:09
Then check which line of code is calling _sympify
Shikhar Jaiswal
@ShikharJ
Aug 02 2017 10:14
Ah, I think I found the error. In qubit, at times there are tuples like ('0', '0') which are passed as arguments in sympify. In case of tuples, this code is used:
elif isinstance(a, tuple):
        v = []
        for e in a:
            v.append(_sympify(e, True))
        return tuple(v)

Can I just change this to:

elif isinstance(a, tuple):
        v = []
        for e in a:
            v.append(sympify(e))
        return tuple(v)

?

Isuru Fernando
@isuruf
Aug 02 2017 10:18
_sympify shouldn't call sympify. Instead you can check in sympify for tuples first
Shikhar Jaiswal
@ShikharJ
Aug 02 2017 10:20
Ok. Thanks!