Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wondering what are the general tips & hints for speeding up symbolic integration. As far as I understand, it solely depends on the form a function is represented before it is processed by Integrate. So, Simplify, ExpandAll, PowerExpand etc. should be used. Are there any other strategies?

My monster function (it looks relatively simple, though) is:

f[r_]:=(A^(2) E^((2 r α)/(3)) α^(3) (A^(8/3) \
(-0.002396-0.001198 r α)+E^((8 r α)/(3)) α^(4) \
(0.00001755-(8.776*10^(-6)) r α)+A^(4/3) E^((4 r \
α)/(3)) α^(2) (-0.0002734+0.0004785 r α)))/(r \
(1.000 A^(4/3)+0.02853 E^((4 r α)/(3)) α^(2))^(4))

or (TeX) $$ \frac{A^2 \alpha ^3 e^{\frac{2 \alpha r}{3}} \left(\alpha ^4 \ e^{\frac{8 \alpha r}{3}} \left(0.00001755-\alpha r \left(8.776 \times 10^{-6}\right)\right)+\alpha ^2 A^{4/3} (0.0004785 \alpha \ r-0.0002734) e^{\frac{4 \alpha r}{3}}+A^{8/3} (-0.001198 \alpha \ r-0.002396)\right)}{r \left(0.02853 \alpha ^2 e^{\frac{4 \alpha \ r}{3}}+1.000 A^{4/3}\right)^4} $$

where $\alpha > 0$ and $A > 0$ are some parameters.

What I am trying to do:


Sure, I could have used NIntegrate for some specific $\alpha$ and $A$ (and belive me, I did it:), but now I am interested in the general result.

Seems like the situation is hopeless, because my laptop can not handle it.

share|improve this question
up vote 8 down vote accepted

Analyze the integrand $f(r)r^2$:

{Expand[Numerator[#]], Denominator[#]} &  @ (Apart[f[r]][[#]] r^2 // FullSimplify) & /@ Range[3]

The result exhibits the integrand as a sum of six fractions whose numerators are in the form $\lambda \exp(2 r \alpha / 3) r^k$ for $k=1,2$ and whose common denominator is in the form $(1 + \mu \exp(4 r \alpha / 3))^2$ (after factoring out the constant $A^{8/3}$, which can be incorporated in $\lambda$).

This is still not easy to integrate symbolically. However, from $\exp(\omega r) = 1 + \omega r + (\omega r)^2/2 + \cdots$ it follows (from the absolute convergence of the integrand when the real part of $\alpha$ is positive) that these integrals can be recovered from the MacLaurin series in $\omega$ for

$$\int_0^\infty \frac{\exp(2 r \alpha / 3) \exp(\omega r)}{(1 + \mu \exp(4 r \alpha / 3))^2} dr.$$

The Mathematica expression for this integral is

u = Integrate[Exp[2 r α] Exp[ω r]/(1 + μ Exp[4 r α])^2, {r, 0, Infinity}]

Within a few seconds it returns a ConditionalExpression equal to

$$\frac{\frac{4 \alpha \mu }{1+\mu }+\left(-\frac{1}{\mu }\right)^{\frac{1}{4} \left(-2+\frac{\omega }{\alpha }\right)} \mu (2 \alpha -\omega ) \text{Beta}\left[-\frac{1}{\mu },\frac{3}{2}-\frac{\omega }{4 \alpha },0\right]}{16 \alpha ^2 \mu ^2}$$

provided $6 \text{Re}[\alpha ]>\text{Re}[\omega ]$ and $\text{Re}[\alpha ]>0$.

Since we only need this to converge for $\omega$ near $0$, this is tantamount to requiring $\text{Re}(\alpha) \gt 0$, which is clearly the case for otherwise the integral diverges.

Now compute the series coefficients of order $1$ and $2$:

SeriesCoefficient[u[[1]], {ω, 0, 1}]

$\frac{\sqrt{-\frac{1}{\mu }} \text{Beta}\left[-\frac{1}{\mu },\frac{3}{2},0\right]}{16 \alpha ^2}-\frac{\text{HypergeometricPFQ}\left[\left\{1,\frac{3}{2},\frac{3}{2}\right\},\left\{\frac{5}{2},\frac{5}{2}\right\},-\frac{1}{\mu }\right]}{72 \alpha ^2 \mu ^2}$

That was only the first coefficient, but the second is found the same way (replacing the last 1 by 2). The second coefficient is messier, involving a linear combination of regularized generalized hypergeometric functions. Don't forget to multiply it by $2!$. Because so much manipulation and re-assembly is involved in obtaining the final answer (it's going to be a linear combination of $30$ such hypergeometric functions before any simplification), it would be a good idea to check your final result against numeric integrations in a range of representative cases.


It often helps to reduce the form of an integrand to the simplest possible--this gives Mathematica better chances to identify good simplifications. In this case, the crux of the matter is to find integrals of the form

$$\int_0^\infty \frac{\exp(x(1 + \tau))}{(1 + \exp(2 x + \sigma))^2}dx,$$

which can be obtained from the change of variable $x = 2 r \alpha / 3$ and letting $\mu = \exp(\sigma)$. So we try

Integrate[Exp[x(1 + τ)] / (1 + Exp[2 x + σ])^2, {x, 0, Infinity}]

It's still a mess, but the series coefficients are a little simpler than before: they are linear combinations of up to five derivatives of a single ordinary (not regularized, not generalized) hypergeometric function. That at least may be better known and easier to understand and perhaps easier for Mathematica to simplify when everything is recombined.

share|improve this answer
+1 When I tried this I got several PolyLogs from the indefinite integral. That made me think I won't learn anything from the analytic solution, as opposed to just doing numerics. You definitely tried harder. – Jens Jan 29 '13 at 18:04
thnx a lot for yr help!!! – molkee Jan 29 '13 at 23:23
+1 this kind of answer certainly cannot be provided from one who doesn't have enough knowledge and experience on general math as well as integration techniques. Well done! – Leo Fang Aug 18 '13 at 20:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.