'How to integrate with relational operators in SymPy?

I want to integrate sin((a-b)*x) along x from 0 to pi/4 in sympy. It gives me a piecewise answer for when (a-b)!=0 and (a-b)=0. How do I integrate only for the condition that (a-b)!=0?

I tried the following code with the relational operator but it didn't help.

from sympy import *
a, b, x = symbols("a b x")
Rel(a, b, "ne")
integrate(sin((a-b)*x),(x,pi/4))


Solution 1:[1]

You can use conds="none" inside the integrate command:

integrate(sin((a-b)*x),(x,pi/4), conds="none")

Alternatively, you can extract the piece you are interested in from a piecewise result, by exploring its arguments:

res = integrate(sin((a-b)*x),(x,pi/4), conds="none")
final = res.args[0][0]

Edit: Note that the command Rel(a, b, "ne") does nothing. It just creates an unequality that is never being used.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Davide_sd