Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eq: giving TypeError: cannot determine truth value of Relational #1055

Closed
cbm755 opened this issue Oct 17, 2021 · 3 comments
Closed

eq: giving TypeError: cannot determine truth value of Relational #1055

cbm755 opened this issue Oct 17, 2021 · 3 comments
Milestone

Comments

@cbm755
Copy link
Collaborator

cbm755 commented Oct 17, 2021

On SymPy 1.9:

>> eqn = 2*x + 7 == 17
error: Python exception: TypeError: cannot determine truth value of Relational
    occurred at line 16 of the Python code block:
    q[i] = _op(*[k[i] if isinstance(k, MatrixBase) else k for k in _ins])
error: called from
    pycall_sympy__ at line 178 column 7
    elementwise_op at line 99 column 5
    ineq_helper at line 35 column 5
    eq at line 91 column 5

Same for eq(2*x+7, 17). This is leading to a lot of test failures.

Might be useful to determine the behaviour on 1.6, 1.7, 1.8 as well

@cbm755
Copy link
Collaborator Author

cbm755 commented Oct 17, 2021

Works on 1.8

@cbm755
Copy link
Collaborator Author

cbm755 commented Oct 17, 2021

MWE in SymPy

x = Symbol('x')
e = Eq(2*x, 7)
A = Matrix([[e]])      # you are no longer allowed to keep an Eq inside a Matrix

We get the warning from #1052.

/home/cbm/work/octsympy/octsympy.git/inst/sympy/matrices/repmatrix.py:98: SymPyDeprecationWarning: 

non-Expr objects in a Matrix has been deprecated since SymPy 1.9. Use
list of lists, TableForm or some other data structure instead. See
https://github.com/sympy/sympy/issues/21497 for more info.

  SymPyDeprecationWarning(

But A is still valid (its "just" a warning):

>>> A
Matrix([[Eq(2*x, 7)]])

But if you assign e to a existing Matrix its an error:

>>> B = Matrix([[42]])                                                                                             
>>> B[0]        # good
42
>>> B[0] = 7    # fine
>>> B[0] = e      # <--  our elementwise_op does this

...inst/sympy/matrices/repmatrix.py:85: SymPyDeprecationWarning: 

non-Expr objects in a Matrix has been deprecated since SymPy 1.9. Use
list of lists, TableForm or some other data structure instead. See
https://github.com/sympy/sympy/issues/21497 for more info.

  SymPyDeprecationWarning(
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-33-c093b1f7650a> in <module>
----> 1 B[0] = e

~/work/octsympy/octsympy.git/inst/sympy/matrices/repmatrix.py in __setitem__(self, key, value)
    390             i, j, value = rv
    391             self._rep, value = self._unify_element_sympy(self._rep, value)
--> 392             self._rep.rep.setitem(i, j, value)
    393 
    394     def _eval_col_del(self, col):

~/work/octsympy/octsympy.git/inst/sympy/polys/matrices/sdm.py in setitem(self, i, j, value)
     94             raise IndexError("index out of range")
     95         i, j = i % m, j % n
---> 96         if value:
     97             try:
     98                 self[i][j] = value

~/work/octsympy/octsympy.git/inst/sympy/core/relational.py in __bool__(self)
    396 
    397     def __bool__(self):
--> 398         raise TypeError("cannot determine truth value of Relational")
    399 
    400     def _eval_as_set(self):

TypeError: cannot determine truth value of Relational

I'm not sure if this is a bug upstream but its certainly clear we are not supposed to be storing Eq inside matrices any more...

@cbm755
Copy link
Collaborator Author

cbm755 commented Jun 24, 2022

Most (all?) of these have been worked around, closing in favour of #1124 where we look for a more permanent solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant