| 694 | ce.precision = 'machine'; |
| 695 | try { |
| 696 | const integrand = ce.parse(integrandLatex); |
| 697 | const dAnti = ce.expr(['D', ce.parse(antiderivLatex), 'x']).evaluate(); |
| 698 | for (const xv of sample) { |
| 699 | const a = dAnti.subs({ x: xv }).N().re; |
| 700 | const b = integrand.subs({ x: xv }).N().re; |
| 701 | if (a === null || b === null) continue; |
| 702 | if (!isFinite(a) || !isFinite(b)) continue; |
| 703 | expect(Math.abs(a - b)).toBeLessThan(1e-7 * (1 + Math.abs(b))); |
| 704 | } |
| 705 | } finally { |
| 706 | ce.precision = saved; |
| 707 | } |
| 708 | }; |
| 709 | |
| 710 | // Gaussian → error functions (completing the square selects Erf vs Erfi). |
| 711 | test('∫e^(−x²) dx → (√π/2)·Erf(x)', () => { |
| 712 | expect(evaluate('\\int e^{-x^2} dx')).toMatchInlineSnapshot( |
| 713 | `1/2 * Erf(x) * sqrt(pi)` |
| 714 | ); |
| 715 | checkDeriv('e^{-x^2}', '\\frac{\\sqrt{\\pi}}{2}\\mathrm{Erf}(x)'); |
| 716 | }); |