Ask Your Question
2

Extract equalities from a list of assumptions

asked 9 years ago

daniele gravatar image

Hi, how can I recognize an equality from an inequality, in a list of assumptions?

thanks,

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 9 years ago

vdelecroix gravatar image

Let

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).

Preview: (hide)
link
3

answered 9 years ago

tmonteil gravatar image

To 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.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 472 times

Last updated: Jan 03 '16