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

FiniteSet not Value False #20089

Closed
flavio1974-art opened this issue Sep 16, 2020 · 3 comments · Fixed by #20208
Closed

FiniteSet not Value False #20089

flavio1974-art opened this issue Sep 16, 2020 · 3 comments · Fixed by #20208
Labels

Comments

@flavio1974-art
Copy link

flavio1974-art commented Sep 16, 2020

A=FiniteSet(1,2)
B=(FiniteSet(1,2),FiniteSet(1))

{1} in A
AttributeError Traceback (most recent call last)
in ()
----> 1 {1} in A

/usr/lib/python3/dist-packages/sympy/sets/sets.py in contains(self, other)
577
578 def contains(self, other):
--> 579 symb = sympify(self.contains(other))
580 if not (symb is S.true or symb is S.false):
581 raise TypeError('contains did not evaluate to a bool: %r' % symb)

/usr/lib/python3/dist-packages/sympy/sets/sets.py in contains(self, other)
305 """
306 other = sympify(other, strict=True)
--> 307 ret = sympify(self._contains(other))
308 if ret is None:
309 ret = Contains(other, self, evaluate=False)

/usr/lib/python3/dist-packages/sympy/sets/sets.py in _contains(self, other)
2001 r = false
2002 for e in self._elements:
-> 2003 t = Eq(e, other, evaluate=True)
2004 if isinstance(t, Eq):
2005 t = t.simplify()

/usr/lib/python3/dist-packages/sympy/core/relational.py in new(cls, lhs, rhs, **options)
302 return r
303 if hasattr(rhs, '_eval_Eq'):
--> 304 r = rhs._eval_Eq(lhs)
305 if r is not None:
306 return r

/usr/lib/python3/dist-packages/sympy/sets/sets.py in _eval_Eq(self, other)
1899
1900 def _eval_Eq(self, other):
-> 1901 if not other.is_FiniteSet:
1902 if (other.is_Union or other.is_Complement or
1903 other.is_Intersection or other.is_Produ

@flavio1974-art
Copy link
Author

FiniteSet

@friyaz
Copy link
Member

friyaz commented Sep 18, 2020

Hi! Can you please clarify the issue further?

@friyaz friyaz added the sets label Sep 18, 2020
@oscarbenjamin
Copy link
Contributor

This is what I get with sympy 1.6.2:

In [8]: A = FiniteSet(1, 2)                                                                                                                    

In [9]: B = FiniteSet(FiniteSet(1, 2), FiniteSet(1))                                                                                           

In [10]: A                                                                                                                                     
Out[10]: {1, 2}

In [11]: B                                                                                                                                     
Out[11]: {{1}, {1, 2}}

In [12]: A in B                                                                                                                                
Out[12]: True

In [15]: 1 in A                                                                                                                                
Out[15]: True

In [13]: print(A.issubset(B)) # should be False                                                                                                
None

In [14]: 1 in B           # should be False                                                                                                                     
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-858aaa7d4c4d> in <module>
----> 1 1 in B

~/current/sympy/sympy/sympy/sets/sets.py in __contains__(self, other)
    673             # x in y must evaluate to T or F; to entertain a None
    674             # result with Set use y.contains(x)
--> 675             raise TypeError('did not evaluate to a bool: %r' % c)
    676         return b
    677 

TypeError: did not evaluate to a bool: None

These would evaluate correctly if Eq could recognise that a Set is never equal to an Expr:

In [11]: Eq(1, FiniteSet(1, 2))                                                                                                                
Out[11]: 1 = {1, 2}

In [12]: Eq(1, FiniteSet(1))                                                                                                                   
Out[12]: 1 = {1}

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

Successfully merging a pull request may close this issue.

3 participants