Basically I'm trying to run the following code.
import sympy as sp
alpha = sp.Symbol(r'\alpha')
x = sp.Symbol('x')
sp.Q.is_true(alpha != -1)
sp.integrate(x**alpha, x)
This results in the following Piecewise
function.
Since I specify global assumptions that alpha != -1
, I expected it will simply give me the first expression. So two questions I have:
sp.integrate
does not ignore them;Piecewise
function?Thanks in advance!
PS. Defining conds='separate'
in the sp.integrate
only returns the first expression for some reason. So if I needed the second part of the piecewise function, I wouldn't be able to get it.
PPS. In case this matters, I have python 3.8.0
and sympy 1.4
.
There is no way to give a specific value as an assumption for a symbol so it can be used in the integration. The best you can do is specify positive, negative, etc... But as for extracting the desired expression from the Piecewise, you can either get it as the particular argument or else feed in a dummy value for x that would extract it. Like the following:
>> from sympy.abc import x
>> from sympy import Piecewise, Dummy
>> eq = Piecewise((x + 1, x < 0), (1/x, True))
>> eq.args[0]
(x + 1, x < 0)
>> _.args[0]
x + 1
>> d = Dummy(negative=True)
>> eq.subs(x, d)
d + 1
>> _.subs(d, x)
x + 1