# Automatically Substituting In A Series Into An Integral

I'm working on an algorithm that includes some difficult integration, dealing with $\mathrm{erf}(t)$ functions, for example. One term in the algorithm is this:

Integrate[Exp[-2 t^2] t^2 Erf[t], {t, 0, x}]


which integrates just fine. Next, we have another term:

Integrate[Exp[-2 t^2] t^2 Erf[Sqrt t], {t, 0, x}],


where we have added the $\sqrt{3}$ in the argument of the $\mathrm{erf}(t)$. Mathematica will integrate this if we approximate either $\exp(-2 t^2)$ or $\mathrm{erf}(\sqrt{3}t)$ as Maclaurin series, for example.

What I want Mathematica to do is if it can't do an integral that includes an $\mathrm{erf}(t)$ function, then it would sub in Maclaurin series for the function and try again. I don't want to sub in the series prematurely (for all instances of $\mathrm{erf}(t)$) because the series are not that great and I'm using them more as a crutch. Since these integrations are automated (they are part of a Do loop), I can't do this substitution manually.

If there is an option that already exists, or that could be created that would accomplish this, I would be over the moon.

Thank you!

• Incidentally, does anybody know why the indefinite symbolic integration normally takes much less time than the definite? Even when the substitutions needed are straightforward. – BoLe Aug 10 '16 at 19:34
• What if approach by @george2079 below isn't successful, because the integrand is that complex for example; should the procedure call itself again, this time approximating Exp[t^2]? – BoLe Aug 10 '16 at 19:39

That can be done with a straightforward change of variable..

Integrate[Exp[-2/3 (t)^2] t^2 Erf[ t], {t, 0, x Sqrt}]/(3 Sqrt) numerical check..

% /. x -> 2 // N


0.137056

NIntegrate[Exp[-2 t^2] t^2 Erf[Sqrt t], {t, 0, 2}]


0.137056

a bit puzzling that Integrate cant do that on its own.

generically

Integrate[Exp[b t^2] t^2 Erf[a t], {t, 0, x}]


transforms to:

Integrate[ Exp[b (tp/a)^2] (tp/a)^2 Erf[tp]/a, {tp, 0, a x}]


which evaluates successfully (just a bit unwieldy to post though)

The auto substitution you wanted can be done something like this:

int[expt_] := Module[{res},
res = Integrate[expt, {t, 0, x}]; • the series solution is only good for x<1, about 20 terms gives a good result for x=1 though. – george2079 Aug 10 '16 at 19:46
• It looks like for the change of variables to work we would substitute $t \rightarrow t/a$ where $a$ is the parameter in $Erf(a t)$, and then do another substitution for the upper $x$ bound. In your code you used a pattern to track what $a$ is, but that's when you were directly substituting it with the series. Can I track this $a$ without a direct substitution? Otherwise Mathematica doesn't know what it is... – Buddhapus Aug 10 '16 at 20:14