MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / checkDeriv

Function checkDeriv

test/compute-engine/calculus.test.ts:696–713  ·  view source on GitHub ↗
(integrandLatex: string, antiderivLatex: string)

Source from the content-addressed store, hash-verified

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 });

Callers 1

calculus.test.tsFile · 0.85

Calls 7

isFiniteFunction · 0.85
parseMethod · 0.65
evaluateMethod · 0.65
exprMethod · 0.65
NMethod · 0.65
subsMethod · 0.65
absMethod · 0.65

Tested by

no test coverage detected