Skip to content

The Gaussian, its even moments and the error functions are integrated - #1512

Merged
Rafael-SOWNet merged 3 commits into
masterfrom
erf-integration
Sep 27, 2026
Merged

Rafael-SOWNet merged 3 commits into
masterfrom
erf-integration

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Part of #1501, step 3.

These are the first integration rules that answer in the error functions. Each is a closed form that names the identity it uses, and none of them is a fallback for an elementary search that failed.

  • The Gaussian. int F^(a x^2 + b x + c) dx is an error function of the completed square. The square is a (x + b/(2a))^2 + c - b^2/(4a), so with A = a ln F and u = x + b/(2a) the integral is F^(c - b^2/(4a)) times int e^(A u^2) du, and int e^(A u^2) du = sqrt(pi)/(2 sqrt(-A)) erf(sqrt(-A) u). That differentiates back for every non-zero A, whichever root is taken. Where A is decidably positive the answer uses erfi and the real root instead. So e^(-x^2) gives sqrt(pi)/2 erf(x), and e^(x^2) gives sqrt(pi)/2 erfi(x).

  • The Gaussian beside an even power of x. int x^m F^(a x^2 + c) dx, for an even m on either side of 0, reduces two powers at a time to the Gaussian:

    • I_m = x^(m - 1) e^(A x^2)/(2A) - (m - 1)/(2A) I_(m - 2);
    • read the other way for a negative m.

    An odd m ends at an elementary integral, which is answered elsewhere, or at the exponential integral, so it isn't taken here.

  • The error functions themselves, by parts against 1: int erf(u) = u erf(u) + e^(-u^2)/sqrt(pi), and likewise for erfc and erfi.

A symbolic exponent is answered for the generic case, as F^(a x)/(a ln F) already is. f^(a + b x^2) gives f^a sqrt(pi)/(2 sqrt(-b ln f)) erf(sqrt(-b ln f) x) with no condition attached.

Together with the error functions' values at ±oo (#1506), the whole-line integrals come out exactly: e^(-x^2) over the line is sqrt(pi), and e^(-x^2/2) is sqrt(2 pi).

Two implementation notes

  • The sign test that picks erfi reads Evaled, as the integrator's other sign tests do. It is in one place, and all of them move together to the interval evaluation of The integrator's sampled-point checks evaluate in intervals, which read no setting #1497.
  • The moment rule is asked of every integrand that reaches the table of standard integrals. So it starts with a type test and captures no local, since a closure would be allocated on entry, before any early return.

Measured

The corpus runs and the gate were taken at f6f747e3, the change before its rebase onto #1509 and #1510, neither of which changes an indefinite integral.

Rubi's problems whose answer uses erf, erfc or erfi: 811 across families 0 to 7, graded by differentiating the answer back, at a 3 s budget.

solved unevaluated wrong timeout
master c42ec55e 0 762 0 49
this PR 473 324 0 14

By Rubi section:

section problems master this PR
textbook 4 0 4
2.1 19 0 19
2.2 3 0 3
2.3 110 0 33
3.1.2 36 0 0
3.1.4 3 0 0
3.3 57 0 7
3.5 7 0 4
4.7.6 64 0 0
5.1.5 8 0 0
6.1.1 27 0 27
6.1.3 19 0 9
6.1.4 24 0 14
6.1.5 29 0 5
6.2.1 27 0 27
6.2.3 16 0 11
6.2.4 24 0 14
6.2.5 29 0 5
7.1.2 56 0 56
7.1.4 37 0 37
7.1.5 60 0 60
7.2.2 56 0 56
7.2.4 37 0 37
7.2.5 56 0 42
7.3.4 3 0 3

Every problem in 2.1, 2.2, 6.1.1, 6.2.1, 7.1.2, 7.1.4, 7.1.5, 7.2.2, 7.2.4 and 7.3.4 is now solved, and so are the four textbook problems. Most reach the Gaussian through a substitution the integrator already makes. The sections still at 0 are the next seams: 3.1.2 (a power of a logarithm beside a power of x), 4.7.6 (an exponential of a quadratic times a trigonometric function of one) and 5.1.5.

The textbook suites (family 0): all 1892 problems at a 5 s budget. Counting erf, erfc and erfi as functions the library has makes four more problems fair, 1778 from 1774. Hearn 337 and 338 have erf in the integrand. Hearn 191 and Moses 74, both e^(x^2), need it in the answer.

solved unevaluated wrong timeout
master c42ec55e 1719 56 0 0
this PR 1723 52 0 0

The four gained are those four, and no problem master solves is lost.

The unit suite passes on net10.0: 12874 passed, 14 skipped, none failed, of 12888, at 30662d38. Its first run failed seven tests. Each used e^(x^2) as the example of an integral with no answer: the documented example of Integrate(string), three transformation tests, the exponential ansatz's declined row, and the ODE solver's declined row. Those now use x^x, which has no antiderivative in any function the library will have, and e^(x^3) where the row is about the ansatz's shape. y' + y = e^(x^2) moves to what the ODE solver solves.

The allocation gate passes on all 19 gated benchmarks.

With #1509 on master, the half line comes out too: e^(-x^2), x^2 e^(-x^2) and x^4 e^(-x^2) over [0, +oo) are sqrt(pi)/2, sqrt(pi)/4 and 3 sqrt(pi)/8.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Rafael-SOWNet and others added 3 commits September 27, 2026 17:16
int F^(a x^2 + b x + c) dx is F^(c - b^2/(4a)) times the Gaussian of
A = a ln F in u = x + b/(2a), and int e^(A u^2) du is
sqrt(pi)/(2 sqrt(-A)) erf(sqrt(-A) u), written with erfi and the real
root where A is decidably positive. Beside an even power of x, on either
side of 0, parts reduce it two powers at a time to the Gaussian; an odd
power ends at an elementary integral or at the exponential integral and
is not taken. erf, erfc and erfi are integrated by parts against 1.

Part of #1501.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
…x and e^(x^3)

The documented example of Integrate(string), the transformation tests and
the exponential ansatz's declined row used e^(x^2) as the integral with no
answer; it is sqrt(pi)/2 erfi(x) now. They use x^x, which has no
antiderivative in any function the library will have, and e^(x^3) where the
row is about the ansatz's shape. y' + y = e^(x^2) moves from what the ODE
solver declines to what it solves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
With #1509, a definite integral takes the limit where its antiderivative is
undefined at a bound, so the moments' x^k e^(-x^2) at +oo is 0 and the half
line gives sqrt(pi)/2, sqrt(pi)/4 and 3 sqrt(pi)/8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant