This page explains the general integration techniques used by Symtegration which work in with direct integration methods. Together, they can integrate functions that the direct methods cannot integrate directly. For example, the Symtegration
See also more implementation notes on Symtegration.
Integrating with constant factors
The Symtegration
Integrating by term
The Symtegration
Integration by substitution
The Symtegration
If \(f' = \frac{df}{dx}\) and \(g' = \frac{dg}{dx}\), then by the chain rule we have
\[\frac{d f(g(x))}{dx} = g'(x) f'(g(x))\]From this, it follows that
\[\int g'(x) f'(g(x)) \, dx = f(g(x))\]If we have a function which is the multiplication of two other functions, we could try differentiating the argument to one of the functions to see if it is the same as the other function, and if so, we can integrate by substitution.
To get this to work, we need to be able to differentiate functions, for which we use AD. We also need to compare whether two separate representations of functions represent equivalent functions. This cannot always be done perfectly for arbitrary functions, but we can rewrite representations to make it more likely that equivalent functions have syntactically equal representations.
The variable multiplied by and added to a constant is a special case of integration by substitution, with \(g = ax+b\).
\[\int a f'(ax + b) \, dx = f(ax+b)\]Integration by parts
The Symtegration
By the product rule, the derivative of the product of two functions \(f\) and \(g\) is as follows.
\[\frac{d(fg)}{dx} = g \frac{df}{dx} + f \frac{dg}{dx}\]A minor rearrangement gives
\[g \frac{df}{dx} = \frac{d(fg)}{dx} - f \frac{dg}{dx}\]If we know how to integrate \(f \frac{dg}{dx} \, dx\), then we can integrate \(g \frac{df}{dx} \, dx\).
\[\begin{align*} \int g \frac{df}{dx} \, dx & = \int \left( \frac{d(fg)}{dx} - f \frac{dg}{dx} \right) \, dx \\ & = \int \frac{d(fg)}{dx} \, dx - \int f \frac{dg}{dx} \, dx \\ & = f g - \int f \frac{dg}{dx} \, dx \end{align*}\]If we are given a function \(F(x) G(x)\), we can try integrating this by guessing an \(f\) such that \(F = \frac{df}{dx}\), and hoping that \(\int f \frac{dG}{dx} \, dx\) is easier to integrate. If this does not work, we could try again with \(G\). Basically, we may be able to derive the integral of the original function from two easier integrals.