It is not necessary for all the arguments of ITE to be bool. If x,y and z are all arbitrary variables (but not numbers) this is what it gives. * >>> ITE(x,y,z)* * Or(And(Not(x), z), And(x, y))* And you are getting this error because of the above logical statement *(*you can not add two logical statements but if by "+" you mean "Or" please use " | "*)* But if instead of that like, i said earlier, if "Cond" in your example is either* True *or *False* your statement will return* ( x + y )* * >>> ITE(True,x,y) + ITE(True,y,x)* * x + y*
And about x and y being a number, ITE does not support that . It takes them as being bool. The reason the arbitary variables work but number don't is that ITE is a logical boolean function which converts number into bools whereas you can use variables because they can be specified to be bools like * >>>x = symbols(x,is_Boolean=True)* *I am not sure if we want numbers to be included in ITE or they are just fine. it will be nice if other developers also comment.* *Thanks* On Friday, April 4, 2014 9:55:58 PM UTC+5:30, Mehul Tikekar wrote: > > I am referring to the ITE function defined in sympy here: > http://docs.sympy.org/dev/_modules/sympy/logic/boolalg.html#ITE. But it > requires all three arguments to be boolean. When I try: > > cond, x, y = symbols('cond x y') > ITE(cond, x, y) + ITE(cond, y, x) > > I get a TypeError: unsupported operand type(s) for +: 'Or' and 'Or' > > On Friday, April 4, 2014 12:17:00 PM UTC-4, SAHIL SHEKHAWAT wrote: >> >> I don't understand what you mean by boolean ITE function can you please >> explain that? >> BUT I think ITE work well if "cond" is a bool when "x" and "y" are >> arbitary symbols. for example: >> IN [1]:* ITE**(True, x , y)* >> OUT [1]:* x* >> >> in the second part of your question if "cond" is a bool then yes ,* >> ITE'(cond, a, b) + ITE'(cond, b, a) *will return* (a+b)* >> >> >> On Fri, Apr 4, 2014 at 9:23 PM, Mehul Tikekar <[email protected]>wrote: >> >>> Hi, >>> I am looking for a variant of the boolean ITE(cond, x, y) function. I >>> need only "cond" to be a bool while "x" and "y" are arbitrary symbols (they >>> could be numbers, for example). Does sympy have a function like that? If >>> not, any ideas on how I can go about writing one? Ideally, it should also >>> be able to do simplifications. For example, ITE'(cond, a, b) + ITE'(cond, >>> b, a) should be simplified to (a + b). >>> >>> Mehul >>> >>> -- >>> 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 [email protected]. >>> To post to this group, send email to [email protected]. >>> 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/b5d8f3fc-d413-4ec2-ace0-76e21ac0bae7%40googlegroups.com<https://groups.google.com/d/msgid/sympy/b5d8f3fc-d413-4ec2-ace0-76e21ac0bae7%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- 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 [email protected]. To post to this group, send email to [email protected]. 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/28a8cd01-2ef1-412d-9f37-55f74c8c6c13%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
