# @cortex-js/compute-engine

> Symbolic computing and numeric evaluations for JavaScript and Node.js

Latest version **0.139.0** (published 2026-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cortex-js/compute-engine
pnpm add @cortex-js/compute-engine
yarn add @cortex-js/compute-engine
bun add @cortex-js/compute-engine
```

Provides the command `epsil`.

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; large bundle; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.139.0 |
| Published | 2026-09-27 |
| First published | 2021-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.3.0 |
| Dependencies | 2 |
| Unpacked size | 44.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 476 |
| Maintainers | arnog |
| Keywords | math, JSON, mathjs, mathematica, maple, algebra, symbolic computing, scientific computing, sympy |

## Links

- npm: https://www.npmjs.com/package/@cortex-js/compute-engine
- Repository: https://github.com/cortex-js/compute-engine
- Homepage: https://cortexjs.io/compute-engine/
- Issues: https://github.com/cortex-js/compute-engine/issues/
- npm.io page: https://npm.io/package/@cortex-js/compute-engine

## Dependencies (2)

- [complex-esm](https://npm.io/package/complex-esm.md) ^2.1.1-esm1
- [@arnog/colors](https://npm.io/package/@arnog/colors.md) ^0.7.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.139.0 (latest) — 2026-09-27
- 0.138.0 — 2026-09-27
- 0.137.3 — 2026-09-27
- 0.137.2 — 2026-09-27
- 0.137.1 — 2026-09-27
- 0.137.0 — 2026-09-27
- 0.136.2 — 2026-09-26
- 0.136.1 — 2026-09-26
- 0.136.0 — 2026-09-26
- 0.135.0 — 2026-09-25
- 0.134.0 — 2026-09-24
- 0.133.0 — 2026-09-22
- 0.132.3 — 2026-09-21
- 0.132.2 — 2026-09-20
- 0.132.1 — 2026-09-20
- … 215 more at https://npm.io/package/@cortex-js/compute-engine/versions

## README

<div align="center">
    <img alt="math live" src="assets/compute-engine.jpg?raw=true"/>
</div>

<h3><strong>Compute Engine</strong></h3>
<h1>Symbolic manipulation and numeric evaluation of MathJSON expressions</h1>

[MathJSON](https://cortexjs.io/math-json/) is a lightweight mathematical
notation interchange format based on JSON.

The Compute Engine can parse LaTeX to MathJSON, serialize MathJSON to
LaTeX or MathASCII, format, simplify and evaluate MathJSON expressions.

Reference documentation and guides at
[cortexjs.io/compute-engine](https://cortexjs.io/compute-engine/).

[![](https://dcbadge.vercel.app/api/server/yhmvVeJ4Hd)](https://discord.gg/yhmvVeJ4Hd)

## Installation

```bash
$ npm install --save @cortex-js/compute-engine
```

## Quick Start

### Basic Parsing and Evaluation

No setup required:

```js
import { simplify, evaluate, N, assign } from "@cortex-js/compute-engine";

simplify("x + x + 1").print();
// ➔ 2x + 1

evaluate("2^{11} - 1").print();
// ➔ 2047

N("\\sqrt{2}").print();
// ➔ 1.414213562...

assign("x", 3);
evaluate("x + 2").print();
// ➔ 5
```

These functions use a shared `ComputeEngine` instance created on first use. Use
`getDefaultEngine()` to configure it, or create your own instance for isolated
configurations.

### Working with Numbers (Type-Safe)

Use type guards to safely access specialized properties:

```js
import { evaluate, isNumber } from "@cortex-js/compute-engine";

const expr = evaluate("\\frac{5}{2}");

if (isNumber(expr)) {
  console.log(expr.numericValue);  // 2.5 (type-safe access)
  console.log(expr.isInteger);     // false
}
```

### Working with Symbols

```js
import { parse, isSymbol, sym } from "@cortex-js/compute-engine";

const expr = parse("x + 1");

// Check if expression is a specific symbol
if (sym(expr) === "x") {
  console.log("This is the variable x");
}

// Or use full type guard for more access
const variable = parse("y");
if (isSymbol(variable)) {
  console.log(variable.symbol);  // "y"
}
```

### Working with Functions

```js
import { parse, isFunction } from "@cortex-js/compute-engine";

const expr = parse("2x + 3y");

// Access function structure safely
if (isFunction(expr)) {
  console.log(expr.operator);    // "Add"
  console.log(expr.ops.length);  // 2

  // Iterate over operands
  for (const op of expr.ops) {
    console.log(op.toString());
  }
}
```

### Simplification and Manipulation

```js
import { parse, simplify, expand } from "@cortex-js/compute-engine";

// Simplify expressions
simplify("x + x").print();
// ➔ 2x

// Expand from LaTeX or Expression
expand("(x + 1)^2").print();
// ➔ x^2 + 2x + 1

// Substitute values
const expr = parse("x^2 + 2x + 1");
expr.subs({ x: 3 }).evaluate().print();
// ➔ 16
```

### Solving Equations

```js
import { solve, parse } from "@cortex-js/compute-engine";

// Solve from LaTeX
solve("x^2 - 5x + 6 = 0", "x");
// ➔ [2, 3]

// Solve a linear system
const system = parse("\\begin{cases}x+y=5\\\\x-y=1\\end{cases}");
const solution = system.solve(["x", "y"]);

console.log(solution.x.json);  // 3
console.log(solution.y.json);  // 2
```

### Epsil Language (Experimental)

Epsil is a text-syntax programming language for scientific computing whose
intermediate representation is MathJSON, evaluated by the Compute Engine. It
ships as a separate, **experimental** entry point (syntax and semantics may
change between releases):

```js
import { ComputeEngine, executeEpsil } from "@cortex-js/compute-engine/epsil";

const ce = new ComputeEngine();
const { value } = executeEpsil(ce, `
  let x = 1/2
  if (x < 1) { x + 1 } else { 0 }
`);
// value.toString() ➔ "3/2"
```

See the [Epsil language documentation](https://cortexjs.io/epsil/).

#### Epsil CLI and REPL

The package also installs an `epsil` command:

```sh
# Start an interactive session
npx epsil

# Evaluate source text or a file
npx epsil -e 'Simplify(2 + 2x)'
npx epsil program.epsil

# Epsil programs can also be piped over stdin
printf '1/2 + 1' | npx epsil
```

The interactive session preserves declarations between inputs and supports
persistent history, multiline input, `.load`, `.clear`, `.ast`, and `.time`. Run
`epsil --help` for output formats and execution-limit options.

#### MCP Server for AI Assistants

The `epsil` command includes a
[Model Context Protocol](https://modelcontextprotocol.io) server, so an AI
assistant can evaluate Epsil programs — exact arithmetic and symbolic
computation as a tool call. For example, with Claude Code:

```sh
claude mcp add epsil -- npx -y @cortex-js/compute-engine mcp
```

The server exposes `evaluate`, `check`, `doc`, `parse`, and `serialize` tools,
and serves machine-verified cards so the assistant can learn Epsil, and the
Compute Engine JavaScript API, on its own. It also has a native Streamable HTTP transport for ChatGPT and other
URL-based clients:

```sh
npx -y @cortex-js/compute-engine mcp --transport streamable-http
```

See the [MCP server guide](https://cortexjs.io/epsil/mcp/) for ChatGPT setup
and HTTPS deployment options.

**💡 Best Practices:**

- Always use type guards (`isNumber`, `isSymbol`, `isFunction`) before accessing
  specialized properties
- Use the `sym()` helper for quick symbol name checks

**📚 Learn More:**
[Full documentation and guides](https://cortexjs.io/compute-engine/)

## FAQ

**Q** How do I build the project?

[Build](BUILD.md) instructions

**Q** How is the project structured?

See [ARCHITECTURE.md](ARCHITECTURE.md) for an overview of the codebase.

## Related Projects

<dl>
  <dt><a href="https://cortexjs.io/math-json/">MathJSON</a></dt>
  <dd>A lightweight mathematical notation interchange format</dd>  
  <dt><a href="https://cortexjs.io/mathlive">MathLive</a> (on <a href="https://github.com/arnog/mathlive">GitHub</a>)</dt>
  <dd>A Web Component for math input.</dd>  
</dl>

## Support the Project

- <span style='font-size:1.5em'>🌟</span> Star the GitHub repo (it really helps)
- <span style='font-size:1.5em'>💬</span> Ask questions and give feedback on our
  [Discussion Forum](https://cortexjs.io/forum/)
- <span style='font-size:1.5em'>📨</span> Drop a line to arno@arno.org

## License

This project is licensed under the [MIT License](LICENSE).

---
_Source: https://npm.io/package/@cortex-js/compute-engine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
