Real integrals by residues
Some integrals over the real line are easiest in the complex plane: close the path with a large semicircle, show the semicircle contributes nothing, and add up residues. Two families are done here from start to finish, with each step of the argument written out and the value proved.
import { realLineIntegral, trigIntegral } from "@ratmath/complex";
const r = realLineIntegral("1/(x^2 + 1)^2");
r.real; // an interval around π/2 = 1.5707963267948966, 2.7e-20 wide
r.steps; // the argument, as { title, detail }
realLineIntegral("x/(x^2 + 1)", { fourier: 2 }).sin; // ∫ x sin 2x/(x² + 1) dx = π/e²
trigIntegral("1/(2 + cos(t))").real; // 2π/√3 = 3.62759872847
Rational functions over the whole line
Let with and no real root of . Integrate round the segment and the semicircle above it. On the semicircle , so that part is at most and vanishes as grows. What is left is
The steps the function takes:
- The formula is turned into exact polynomials and and common factors are cancelled, so a removable singularity on the real axis does no harm.
- The degrees are compared; if the integral does not converge the call is refused and says why.
- Every root of is found by
zerosin a square that Cauchy's bound proves large enough, and the count is checked against the degree. - Each root must be provably above or below the real axis. One that is on it, or too close to tell, is refused: the integral does not exist as it stands.
- At a simple pole the residue is , evaluated on the root's enclosure. At a multiple pole it is a contour integral round a small circle.
Fourier integrals
With { fourier: a } the integrand is . For the factor decays in the upper half-plane, and Jordan's lemma makes the semicircle vanish as soon as . For the path closes below instead. When is real on the real axis the real and imaginary parts of the result are the cosine and sine integrals, returned as cos and sin.
Trigonometric integrals over a period
For a rational function of and , put . Then , , , and as runs from 0 to the point runs once round the unit circle:
trigIntegral makes the substitution, reduces to a quotient of polynomials, and sums the residues at the poles proved to be inside the circle. cos(2t) and the like are understood. A pole on the circle means the integrand is unbounded, and is refused.
| call | returns |
|---|---|
| realLineIntegral(f, { fourier, bits, variable }) | { value, real, cos, sin, poles, steps }. value is a Rect; real the interval for a real integrand; cos and sin with fourier. |
| trigIntegral(f, { bits, variable }) | { value, real, poles, steps } |
| poles | Every pole: { enclosure, order, taken, residue } |
| steps | The argument: [{ title, detail }] |
The formula's variable is x (or z) for the line and t (or theta, or x) for the circle; name another with variable. Coefficients must be exact, which here means rational numbers and i.
@ratmath/complex and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.