One night, I discovered an integration relationship. That relationship allows to quickly integrate squares of functions (and even more, but I will talk about this at the end).

I was wondering if anyone has found a formula like this before. So I researched on the internet, but couldn't find anything like this.

The formula:

$$\int f(x)^2\,dx\;=\;xf(x)^2\;-\;2f(x)\cdot F^{-1}_{(1)}(f(x))\;+\;2\,\cdot F^{-1}_{(2)}(f(x))\;+\;C$$

Where $F^{-1}_{(n)}$ denotes the $n$th anti-derivative of the inverse function of $f$.

The formula looks rather complicated, but it's really not, on further inspection. Note: the formula doesn't work on the function $f(x)=x$ for a reason that I wasn't able to determine yet. Edit: it actually works.

An example in action:

Let's compute $\int \ln^2x\,dx$. We have then:

$f(x)=\ln x$




Applying the formula, the integral becomes:

$$\int\ln^2x\,dx=x\ln^2x-2\ln x\cdot e^{\ln x}+2\cdot e^{\ln x}+C$$ $$=x\ln^2x-2x\ln x+2x+C$$

Derivation (for the curious):

I derived this formula by substituting for inverse functions and doing repeated integration by parts.

First, substitute $x=f^{-1}(u)$. Then, we have $dx=df^{-1}(u)$. This changes the original integral to:

$$\int f(x)^2\,dx=\int f(f^{-1}(u))^2\,df^{-1}(u)=\int u^2\,df^{-1}(u)$$

At this point, I did integration by parts (probably the funkiest integration by parts you have ever seen). Note, that I am using the "DI table" trick for integration by parts, where in one column, derivatives of one function are specified, and integrals of another are put into the other column. Terms are multiplied diagonally left-down.

$$\begin{array}{ l | c | r } \pm & D & I \\ \hline + & u^2 & df^{-1}(u) \\ - & 2u & f^{-1}(u) \\ + & 2 & F^{-1}_{(1)}(u) \\ - & 0 & F^{-1}_{(2)}(u) \\ \end{array}$$

$$\int u^2\,df^{-1}(u)\;=\;u^2f^{-1}(u)-2uF^{-1}_{(1)}(u)+2F^{-1}_{(2)}(u)+C$$

Now, simply subsitute back $u=f(x)$ and we arrive at the formula.

Generalization to composition of functions:

It didn't take long for me to realize that this method can be extended to compositions of functions. Just for the curious folks, this is my integral of composition formula:

$$\int f(g(x))\,dx\;=\;\sum^{\infty}_{k=0}(-1)^k\cdot D_k(g(x))\cdot A_k(g(x)) + C$$

Where $D_k={d^k f\over dx^k}$ and $A_k={d^{-k}g^{-1}\over dx^{-k}}$.

Interesting, isn't it?

Back to the question:

Have I discovered this formula? If I didn't can someone point me to a further reading on this topic? I really can't find anything myself, probably because I don't know how to search.

  • 3
    $\begingroup$ at a first glance it seems correct. However I doubt that nobody had written a similar formula in the previous centuries :) $\endgroup$ – Masacroso Dec 9 '18 at 4:24
  • 4
    $\begingroup$ I'm pretty sure this does work for $f(x)=x$ $\endgroup$ – WW1 Dec 9 '18 at 5:20
  • $\begingroup$ @WW1 oh yeah, it does :) I don't know how it didn't work for me before $\endgroup$ – KKZiomek Dec 9 '18 at 7:14

Maybe I'm missing something, but it seems you're just making the substitution $u = f(x)$ in the $f(x)^2$ case and $u = g(x)$ in the $f(g(x))$ case and then integrating by parts (multiple times). This can certainly be useful depending on the functional forms of $f$ and $g$.

  • 1
    $\begingroup$ Yes, it's just a u=f(x) substitution. Pretty simple, but allows for turning a composition of general functions into a product of a specific function and a differential. This simplicty raises more probability that someone discovered it before just in some obscure paper or in a way that is hard to search online. So I'll just assume I rediscovered it. $\endgroup$ – KKZiomek Dec 9 '18 at 15:32

My first thought was that if this were true, I'd have seen it already in conjunction with the tables of integrals in one of the standard reference books. But it seems it is true.

The reason the formula isn't more prominent may be because it requires $f(x)$ to have an inverse, and then it requires that inverse to be integrated twice. Those requirements put a lot of functions out of reach of this formula. For example, consider $f(x) = xe^{x^2/2},$ which is sometimes given as an example of why there (supposedly) is no general formula to integrate $f(x).$ (For example, see how to calculate integral of square of a function and Integral of Derivative squared). Then $f^{-1}(x) = \sqrt{\mathrm W(x^2)},$ where W is the Lambert W function, but (according to Wolfram Alpha) $\sqrt{\mathrm W(x^2)}$ has no integral expressible in elementary functions.

Out of curiosity, I worked this out for a few examples. All of these are confirmed by other methods (which in these examples are easier than the formula).

\begin{align} f(x) &= x \\ f^{-1}(x) &= x \\ F^{-1}_{(1)}(x) &= \tfrac12 x^2 \\ F^{-1}_{(2)}(x) &= \tfrac16 x^3 \\ F^{-1}_{(1)}(f(x)) &= \tfrac12 x^2 \\ F^{-1}_{(2)}(f(x)) &= \tfrac16 x^3 \end{align}

\begin{align} \int x^2\,dx &= x \cdot x^2 - 2x \cdot \tfrac12 x^2 + 2 \cdot \tfrac16 x^3 + C \\ &= x^3 - x^3 + \tfrac13 x^3 + C \\ &= \tfrac13 x^3 + C. \end{align}

\begin{align} f(x) &= \sin x \\ f^{-1}(x) &= \arcsin x \\ F^{-1}_{(1)}(x) &= \sqrt{1 - x^2} + x \arcsin x \\ F^{-1}_{(2)}(x) &= \tfrac14 (3x \sqrt{1 - x^2} + 2 x^2 \arcsin x + \arcsin x) \\ F^{-1}_{(1)}(f(x)) &= \cos x + x\sin x \\ F^{-1}_{(2)}(f(x)) &= \tfrac14 (3\sin x \cos x + 2 x\sin^2 x + x) \end{align}

\begin{align} \int \sin^2 x\,dx &= x \sin^2 x - 2\sin x (\cos x + x\sin x) + 2 \cdot \tfrac14 (3\sin x \cos x + 2 x\sin^2 x + x) + C \\ &= x \sin^2 x - 2\sin x \cos x - 2x\sin^2 x + \tfrac32\sin x \cos x + x\sin^2 x + \tfrac12x + C \\ &= (x - 2x +x)\sin^2 x + \left(- 2 + \tfrac32\right)\sin x \cos x + \tfrac12x + C \\ &= -\tfrac12 \sin x \cos x + \tfrac12x + C. \\ \end{align}

\begin{align} f(x) &= e^x \\ f^{-1}(x) &= \ln x \\ F^{-1}_{(1)}(x) &= x (\ln x - 1) \\ F^{-1}_{(2)}(x) &= \tfrac14 x^2 (2 \ln x - 3) \\ F^{-1}_{(1)}(f(x)) &= e^x (x - 1) \\ F^{-1}_{(2)}(f(x)) &= \tfrac14 e^{2x} (2 x - 3) \end{align}

\begin{align} \int (e^x)^2\,dx &= x e^{2x} - 2e^x \cdot e^x (x - 1) + 2 \cdot \tfrac14 e^{2x} (2 x - 3) + C \\ &= x e^{2x} - 2(x - 1)e^{2x} + \left(x - \tfrac32\right) e^{2x} + C \\ &= \left(x - 2x + 2 + x - \tfrac32\right)e^{2x} + C \\ &= \tfrac12 e^{2x} + C. \\ \end{align}

\begin{align} f(x) &= e^{x^2} \\ f^{-1}(x) &= \sqrt{\ln x} \\ F^{-1}_{(1)}(x) &= x\sqrt{\ln x} - \tfrac12\sqrt\pi\,\mathrm{erfi}(\sqrt{\ln x}) \\ F^{-1}_{(2)}(x) &= -\tfrac12 \sqrt\pi x \, \mathrm{erfi}(\sqrt{\ln x}) + \tfrac18\sqrt{2\pi}\,\mathrm{erfi}(\sqrt{2\ln x}) + \tfrac12 x^2 \sqrt{\ln x} \\ x f(x)^2 &= x e^{2x^2}, \\ F^{-1}_{(1)}(f(x)) &= x e^{x^2} - \tfrac12\sqrt\pi\,\mathrm{erfi}(x) \\ 2f(x)F^{-1}_{(1)}(f(x)) &= 2x e^{2x^2} - \sqrt\pi\,e^{x^2}\mathrm{erfi}(x),\\ 2F^{-1}_{(2)}(f(x)) &= -\sqrt\pi e^{x^2} \mathrm{erfi}(x) + \tfrac14\sqrt{2\pi}\, \mathrm{erfi}(\sqrt2 x) + xe^{2x^2} \\ \end{align}

\begin{align} \int \left(e^{x^2}\right)^2\,dx &= x e^{2x^2} - \left(2x e^{2x^2} - \sqrt\pi\,e^{x^2}\mathrm{erfi}(x)\right) - \sqrt\pi e^{x^2} \mathrm{erfi}(x) + \tfrac14\sqrt{2\pi}\, \mathrm{erfi}(\sqrt2 x) + xe^{2x^2} + C\\ &= \tfrac14\sqrt{2\pi}\, \mathrm{erfi}(\sqrt2 x) + C. \end{align}

This agrees with $\int e^{u^2}\,du = \tfrac12\sqrt\pi\,\mathrm{erfi}(u) + C$ with the substitution $u = \sqrt2 x.$

  • 1
    $\begingroup$ Thank you for that analysis. So it seems that this formula works nicely only for certain functions, for others it is unnecessarily complicating. It seems that the best functions to integrate this method are powers of logarithms $\endgroup$ – KKZiomek Dec 9 '18 at 18:04
  • 1
    $\begingroup$ It did work out very nicely for $(\ln x)^2$; no cancellation of unnecessary terms. I would not be surprised if there were some other functions it worked nicely for. $\endgroup$ – David K Dec 10 '18 at 0:35
  • 1
    $\begingroup$ True, but arguably $\ln x $ is the *nicest* of all, as its inverse is $e^x$ whose antiderivtives are all $e^x$. Though, like you said, there may be functions that are nice enough for this method besides logarithms $\endgroup$ – KKZiomek Dec 10 '18 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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