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[3] 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!

  • $\begingroup$ Incidentally, does anybody know why the indefinite symbolic integration normally takes much less time than the definite? Even when the substitutions needed are straightforward. $\endgroup$
    – BoLe
    Commented Aug 10, 2016 at 19:34
  • $\begingroup$ 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]? $\endgroup$
    – BoLe
    Commented Aug 10, 2016 at 19:39

1 Answer 1


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]}]/(3 Sqrt[3])

enter image description here

numerical check..

% /. x -> 2 // N


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


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


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}];
  If[TrueQ[Head[res] == Integrate], 
   Integrate[expt /. Erf[ a_ t] :> Normal@Series[Erf[a t], {t, 0, 6}],
    {t, 0, x}], res]]
int[Exp[-2 t^2] t^2 Erf[t]]
int[Exp[-2 t^2] t^2 Erf[Sqrt[3] t]]

enter image description here

  • $\begingroup$ Beautiful response! I've plotted the exact result with the series result and there was quite a bit of error (I wasn't sure how to find the exact function until you showed with change of variables)! I think I'll try to use your scheme to do the substitution of variables, otherwise I'll resort to using more terms in the series... Thank you so much! $\endgroup$
    – Buddhapus
    Commented Aug 10, 2016 at 19:41
  • $\begingroup$ the series solution is only good for x<1, about 20 terms gives a good result for x=1 though. $\endgroup$
    – george2079
    Commented Aug 10, 2016 at 19:46
  • $\begingroup$ 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... $\endgroup$
    – Buddhapus
    Commented Aug 10, 2016 at 20:14
  • $\begingroup$ i put the generic integral variable substitution in the answer. $\endgroup$
    – george2079
    Commented Aug 10, 2016 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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