Is it possible to simplify x == 1 or x == 2 or x ==3 to x in [ 1, 2, 3 ] ?

53 views
Skip to first unread message

Simon

unread,
Dec 6, 2015, 12:53:29 PM12/6/15
to sympy
Hello,

I'm newcomer  to sympy and just read some document from sympy website, sympy does a very good job on simplify Boolean expression. I would greatly appreciate it if someone could let me know whether I can customer sympy to support below cases

simplify( x == 1 or x == 2 or x ==3 ) 
                                                             get result  x in [ 1, 2, 3 ] 

simplify( x != 1 and x != 2 and x !=3 ) 
                                                            get result x not in [1, 2, 3]

Simon.

Aaron Meurer

unread,
Dec 8, 2015, 12:57:42 PM12/8/15
to sy...@googlegroups.com
SymPy can represent each, but as far as I know, no functions exist to
simplify one to the other.

The representation of each would be like

Or(Eq(x, 1), Eq(x, 2), Eq(x, 3))
Contains(x, FiniteSet(1, 2, 3))

And(Neq(x, 1), Neq(x, 2), Neq(x, 3))
Not(Contains(x, FiniteSet(1, 2, 3)))

Contains is relatively new in SymPy, so not much exists yet to
manipulate it, but it shouldn't be hard to add functions to go from
Contains to a boolean or visa-versa.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/8d68708e-a94d-4b89-b5ed-db5cd00b2217%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Simon

unread,
Dec 8, 2015, 9:19:19 PM12/8/15
to sympy
Aaron Meurer , thanks for help.

在 2015年12月9日星期三 UTC+8上午1:57:42,Aaron Meurer写道:
Reply all
Reply to author
Forward
0 new messages