Cortex Compute Engine
Symbolic manipulation and numeric evaluation of MathJSON expressions
MathJSON is a lightweight mathematical notation interchange format based on JSON.
The Cortex Compute Engine can parse LaTeX to MathJSON, serialize MathJSON to
LaTeX, format, simplify and evaluate MathJSON expressions.
Reference documentation and guides at
cortexjs.io/compute-engine.
Using Compute Engine
$ npm install --save @cortex-js/compute-engine
import { parse, evaluate } from '@cortex-js/compute-engine';
const expr = parse('2^{11}-1 \\in \\P');
console.log(expr);
console.log(evaluate(expr));
More
Related Projects
- MathJSON
- A lightweight mathematical notation interchange format
- MathLive (on GitHub)
- A Web Component for math input.
- Cortex (on GitHub)
- A programming language for scientific computing
Support the Project
License
This project is licensed under the MIT License.
0.7.0 2022-09-30
Breaking Changes
- The
ce.latexOptions.preserveLatex
default value is now false
- The first argument of the
["Error"]
expression (default value) has been
dropped. The first argument is now an error code, either as a string or an
["ErrorCode"]
expression.
Features
- Much improved LaTeX parser, in particular when parsing invalid LaTeX. The
parser now avoids throwing, but will return a partial expression with
["Error"]
subexpressions indicating where the problems were.
- Implemented new domain computation system (similar to type systems in
programming languages)
- Added support for multiple signatures per function (ad-hoc polymorphism)
- Added
FixedPoint
, Loop
, Product
, Sum
, Break
, Continue
, Block
,
If
, Let
, Set
, Function
, Apply
, Return
- Added
Min
, Max
, Clamp
- Parsing of
\sum
, \prod
, \int
.
- Added parsing of log functions,
\lb
, \ln
, \ln_{10}
, \ln_2
, etc...
- Added
expr.
subexpressions,
expr.getSubexpressions(),
expr.errors,
expr.symbols,
expr.isValid`.
- Symbols can now be used to represent functions, i.e.
ce.box('Sin').domain
correctly returns ["Domain", "Function"]
.
- Correctly handle rational numbers with a numerator or denominator outside the
range of a 64-bit float.
- Instead of a
Missing
symbol an ["Error", "'missing'"]
expression is used.
- Name binding is now done lazily
- Correctly handle MathJSON numbers with repeating decimals, e.g.
1.(3)
.
- Correctly evaluate inverse functions, e.g.
ce.parse('\\sin^{-1}(.5)).N()
- Fixed some LaTeX serialization issues
Read more at
Core Reference and
[Arithmetic Reference]
(https://cortexjs.io/compute-engine/reference/arithmetic/)
Bugs Fixed
- #43 If the input of
ce.parse()
is an empty string, return an empty
string for expr.latex
or expr.json.latex
: that is, ensure verbatim LaTeX
round-tripping
- Evaluating some functions, such as
\arccos
would result in a crash
- Correctly handle parsing of multi-token decimal markers, e.g.
{,}