Search code examples
pythondistributionsympysymbolic-math

How to hint Sympy an integration for Inverse Gaussian equation


Symbolic integration of the Inverse Gaussian PDF works on Wolfram Alpha https://www.wolframalpha.com/input/?i=x%5E(-3%2F2)*exp(-Bx-A%2Fx)

but I cannot reproduce it using Sympy (It takes forever with no response):

from __future__ import division
from sympy import *
A, B, x = symbols('A B x')
ig_pdf = (sqrt(x)**(-3))*exp(-B*x-A/x)
pprint(ig_pdf, use_unicode=True)
ig_cdf = integrate(ig_pdf, x, conds='none')
pprint(ig_cdf, use_unicode=True)

Is there a way to make it work and produce a closed form integration? How can I hint Sympy to use a certain integration rule such as the "integration by parts"?


Solution

  • As requested here my comment as an answer.

    I assume sympy is not (yet) able to solve this integral. Assigning A, B, x = symbols('A B x', real=True) as real variables does not do the trick. sympy calculates for about 40 minutes before simply returning the integral, not the solution. The same output can be achieved much faster by using ig_cdf = sym.integrals.Integral(ig_pdf, x) instead of the integration. Tested with sympy version 1.1.1, python 3.6.2