Skip to content

Add differential equation solvers#315

Merged
arnog merged 2 commits into
cortex-js:mainfrom
KingArth0r:dsolve
Jun 27, 2026
Merged

Add differential equation solvers#315
arnog merged 2 commits into
cortex-js:mainfrom
KingArth0r:dsolve

Conversation

@KingArth0r

Copy link
Copy Markdown
Contributor

Summary

Adds an initial, modular differential-equation solving slice for the compute engine:

  • registers symbolic DSolve in the calculus library
  • implements symbolic first-order linear scalar ODE solving in src/compute-engine/symbolic/differential-equations.ts
  • registers numeric NDSolve in the calculus library
  • implements fixed-step scalar RK4 support in src/compute-engine/numerics/differential-equations.ts
  • adds focused tests for symbolic solutions, unsupported inert cases, RK4 sample accuracy, and a Gaussian IVP with a non-elementary antiderivative checked against Erf

Scope / Limitations

This is intentionally narrow so the API and result shape can get feedback before broader ODE support is added.

Current symbolic support handles first-order linear equations of the form y'(x) + p(x)y(x) = q(x) and leaves unsupported/nonlinear/higher-order equations inert.

Current numeric support handles explicit scalar first-order IVPs with fixed-step RK4 and returns sample data as a List of [x, y] pairs. It does not yet implement adaptive RK45, systems, interpolation objects, stiff solvers, implicit equations, or higher-order reductions.

Validation

  • node_modules/.bin/jest.cmd --config ./config/jest.config.cjs test/compute-engine/differential-equations.test.ts --runInBand --reporters default
  • node_modules/.bin/jest.cmd --config ./config/jest.config.cjs test/compute-engine/calculus.test.ts --runInBand --reporters default --testNamePattern DERIVATION
  • node_modules/.bin/madge.cmd --circular --extensions ts src/compute-engine
  • node_modules/.bin/tsc.cmd --target es2022 --module es2022 --moduleResolution bundler --types node --skipLibCheck -d --allowImportingTsExtensions true --emitDeclarationOnly --ignoreConfig --outDir .typecheck ./src/compute-engine.ts

@arnog

arnog commented Jun 27, 2026

Copy link
Copy Markdown
Member

Excellent work!

This looks good overall and fits well with the conventions of the Compute Engine.

A few small things:

  1. For the integration constant, use a generated constant name (avoiding freeVariables in the expression) instead of hardcoding C, or alternatively start with C if it is not an already defined identifier in scope, and fallback to a constructed constant name if it is.

  2. For NDSolve, use canonicalLimits() to parse the operand, to handle cases like a simple Tuple/Tripe (forms which are also supported by the Integrate/Sum operators).

  3. I'd suggest that DSolve should return a List, so that it can represent solution families in the future without changing the API shape.

  4. You have a few functions (isDependentFunction(), isDerivativeOfDependent() and the symbolArg closure) that should be promoted to shared helpers to avoid duplication.

  5. In NDSolve you can use compiled.success for a quick bypass.

@KingArth0r KingArth0r marked this pull request as ready for review June 27, 2026 21:52
@arnog arnog merged commit 7f8f117 into cortex-js:main Jun 27, 2026
@KingArth0r KingArth0r deleted the dsolve branch June 28, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants