Did I just discover this integration formula?

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$.


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.$