So i want to calculate integral of exp(-ax^2-bx-c) assuming that a>0, b>0, c>0 using sympy.
So i done this:
from sympy import *
x = symbols('x')
a, b, c = symbols('a, b, c')
assumptions = Q.real(a), Q.positive(a), \
Q.real(b), Q.positive(b), \
Q.real(c), Q.positive(c)
with assuming(*assumptions):
expression = exp(-a*x**2 - b*x - c)
ans = integrate(expression, (x, -oo, oo))
ans = simplify(ans)
print(str(ans).replace(',', ',\n\n'))
And i get this:
Piecewise((sqrt(pi)*(erf(b/(2*sqrt(a))) + erfc(b/(2*sqrt(a))) + 1)*exp(-c + b**2/(4*a))/(2*sqrt(a)),
(Abs(arg(a)) < pi/2) | ((Abs(arg(a)) <= pi/2) & (2*Abs(arg(b)) < pi) & (Abs(2*arg(b) + 2*pi) < pi))),
(Integral(exp(-a*x**2 - b*x - c),
(x,
-oo,
oo)),
True))
But i know, that answer must be:
sqrt(pi/a) * exp(b**2/(4*a) - c)
As i think, assuming isnt working, so i tried this:
from sympy import *
a = symbols('a')
assumptions = [ Q.positive(a) ]
with assuming(*assumptions):
print(ask(Q.is_true(a > 0)))
And the answer is:
None
And this is very strange. What am i doing wrong?