ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 03 Jan 2016 10:13:52 -0600Extract equalities from a list of assumptionshttp://ask.sagemath.org/question/32008/extract-equalities-from-a-list-of-assumptions/Hi,
how can I recognize an equality from an inequality, in a list of assumptions?
thanks, Sun, 03 Jan 2016 07:49:04 -0600http://ask.sagemath.org/question/32008/extract-equalities-from-a-list-of-assumptions/Answer by tmonteil for <p>Hi,
how can I recognize an equality from an inequality, in a list of assumptions?</p>
<p>thanks, </p>
http://ask.sagemath.org/question/32008/extract-equalities-from-a-list-of-assumptions/?answer=32011#post-id-32011To complement @vdelecroix answer, the assumptions is a list of symbolic expressions which you can filter as follows:
sage: var('x,y')
(x, y)
sage: assume(x>0)
sage: assume(x<=1)
sage: assume(y==2)
sage: equalities = [ass for ass in assumptions() if ass.operator() == operator.eq]
sage: inequalities = [ass for ass in assumptions() if ass.operator() in [operator.lt, operator.le, operator.gt, operator.ge]]
sage: equalities
[y == 2]
sage: inequalities
[x > 0, x <= 1]
You might want to put `operator.ne` somewhere.
Sun, 03 Jan 2016 10:13:52 -0600http://ask.sagemath.org/question/32008/extract-equalities-from-a-list-of-assumptions/?answer=32011#post-id-32011Answer by vdelecroix for <p>Hi,
how can I recognize an equality from an inequality, in a list of assumptions?</p>
<p>thanks, </p>
http://ask.sagemath.org/question/32008/extract-equalities-from-a-list-of-assumptions/?answer=32010#post-id-32010Let
sage: var('a,b')
sage: eq1 = a == b
sage: eq2 = a < b
Then
sage: eq1.operator() == operator.eq
True
versus
sage: eq2.operator() == operator.lt
True
operator is a python module and the comparison operators are lt (less than), le (lesser or equal), eq (equal), ne (different), gt (greater than) and ge (greater or equal).Sun, 03 Jan 2016 10:03:53 -0600http://ask.sagemath.org/question/32008/extract-equalities-from-a-list-of-assumptions/?answer=32010#post-id-32010