Computer Algebra System in TypeScript
npm install jsxmath
JsxMath is a Javascript (Typescript) library for symbolic mathematics.
``typescript
import { assert } from "chai";
import { is_rat } from "math-expression-atoms";
import { create_engine, ExprEngine } from "../src/api/index";
import { State, Stepper } from '../src/clojurescript/runtime/Interpreter';
import { Stack } from "../src/env/Stack";
describe("example", function () {
it("program", function () {
const lines: string[] = [
(+ 1 2 3 4 5),(+ 10 (* 5 2))
,(* (+ 10 5) 2)
``
];
const sourceText = lines.join('\n');
const engine: ExprEngine = create_engine({ syntaxKind: ... });
const { program, errors } = engine.parseModule(sourceText, {});
assert.strictEqual(errors.length, 0);
const runner = new Stepper(program);
runner.run();
const stack: Stack
assert.strictEqual(stack.length, 1);
const values = stack.top.values;
assert.strictEqual(values.length, 3);
assert.strictEqual(engine.renderAsString(values[0], { format: 'Infix' }), "15");
assert.strictEqual(is_rat(values[0]), true);
assert.strictEqual(engine.renderAsString(values[1], { format: 'Infix' }), "20");
assert.strictEqual(is_rat(values[1]), true);
assert.strictEqual(engine.renderAsString(values[2], { format: 'Infix' }), "30");
assert.strictEqual(is_rat(values[2]), true);
engine.release();
});
});
* arbitrary-precision arithmetic
* complex quantities
* geometric algebra
* trigonometric functions
* special functions
* simplification
* expansion
* substitution
* factoring
* symbolic and numeric roots
* units of measure
* hyperreal numbers
* matrices
* derivatives and gradients
* tensors
* booleans
* integrals
* multi-integrals
* open for extension
Please take a look at the tutorial file.
Please take a look at the contributing file.
jsxmath is a fork of Algebrite by Davide Della Casa.
The fork adds Geometric Algebra, S.I. Units of Measure, and changes the way that expressions are matched and transformed.
Algebrite started as a port of the EigenMath CAS by George Weigt to TypeScript.
Another fork of EigenMath: SMIB by Philippe Billet.
Another CAS of similar nature is SymPy made in Python.
Three other Javascript CAS are
* javascript-cas by Anthony Foster supporting "differentiation, complex numbers, sums, vectors (dot products, cross products, gradient/curl etc)"
* Coffeequate by Matthew Alger supporting "quadratic and linear equations, simplification of most algebraic expressions, uncertainties propagation, substitutions, variables, constants, and symbolic constants".
* Algebra.js by Nicole White which among other things can build and solve equations via a "chainable" API.