Zim 2.5 is a TypeScript symbolic-mathematics engine with strict parsing, exact rational arithmetic, deterministic simplification, equation and system solving, symbolic differentiation, conservative limits, verified symbolic integration, arbitrary-precision numerical quadrature, a versioned backend API, and command-line and graphical interfaces.
The former JavaScript implementation is preserved under legacy/ for comparison only. Production code in packages/core does not import it.
- Node.js 20 or newer
- TypeScript 5.9 or newer (
npm installsupplies it after dependencies are installed)
npm install
npm run check
npm run test:browsers
npm run benchmarknpm run check builds both packages, runs all tests, lints the TypeScript source, and checks formatting. Generated dist folders are not committed.
To run the local graphical interface:
npm run start:guiThen open http://127.0.0.1:3210. The interface communicates exclusively through the serialized public API and renders returned AST values with native MathML.
The Scientific Calculator button opens /calculator, a keyboard-friendly calculator powered by Zim's public calculate operation. It supports exact arithmetic, decimal evaluation, radians or degrees, persistent and recallable calculation history, Ans chaining, remainder, factorial, common and arbitrary-base logarithms, pi, e, tau, and Zim's supported scientific functions without dynamically executing user input. Evaluated expressions are presented as native MathML—including roots, powers, fractions, and logarithm bases—while the original source remains available for editing and in history.
The GUI presents API results in a readable format by default. In Settings, enable Show result JSON to display the underlying result data alongside the formatted answer. The separate API developer inspection panel can also be enabled there for full request and response envelopes.
const {
parse,
simplify,
solve,
solveSystem,
format,
toLatex,
execute,
executeV2,
} = require("@zim/core");
const ast = parse("1/3 + 1/6 + x * 0");
const result = simplify(ast, { debug: true });
console.log(format(result.expression)); // 1/2
console.log(result.steps.map((step) => step.rule));
const solution = solve(parse("x^2 = 4"), { variable: "x" });
console.log(solution.kind); // multiple-solutions
console.log(solution.values.map(format)); // ["-2", "2"]
const complex = solve(parse("x^2 + 1 = 0"), { variable: "x", domain: "complex" });
console.log(complex.values.map(format)); // ["-i", "i"]
const system = solveSystem([parse("x + y = 5"), parse("x - y = 1")], ["x", "y"]);
console.log(system.solution); // exact AST values for x = 3 and y = 2
const response = execute({
version: "1.0",
operation: "solve",
expression: "x^2 = 2",
variable: "x",
});
console.log(JSON.stringify(response));
const capabilities = executeV2({ apiVersion: "2.0-beta", operation: "capabilities" });
console.log(capabilities.requestId, capabilities.result);
const roots = executeV2({
apiVersion: "2.0-beta",
operation: "analyzePolynomial",
expression: "x^5 + x + 1",
variable: "x",
});
console.log(roots.result.complexRoots); // approximations include residuals and multiplicities
const nonlinear = executeV2({
apiVersion: "2.0-beta",
operation: "solveNonlinearSystem",
equations: ["x * y = 2", "x + y = 3"],
variables: ["x", "y"],
});
console.log(nonlinear.result.solutions);
const proof = executeV2({
apiVersion: "2.0-beta",
operation: "derive",
expression: "sqrt(x + 1) = x - 1",
variable: "x",
renderMode: "classroom",
});
console.log(proof.result.rendered.text);The public package also exports toLatex(). API v1 remains compatible and converts all bigint fields to decimal strings. The operation-specific v2 beta envelope adds request IDs, timing, diagnostics, and resource-budget outcomes. Machine-readable schemas ship with the core package.
Solve requests can set includeSteps: true to receive a canonical nested derivation graph plus the compatible flat-step view. Stable rule IDs, localized metadata, accepted/rejected evidence, node budgets, and concise/classroom/diagnostic renderers are also available through the v2 derive operation. Simplification requests return their applied rewrite rules through the same option.
| Command | Purpose |
|---|---|
zim parse |
Parse input and inspect the AST |
zim simplify |
Simplify an expression |
zim solve |
Solve an equation or supported relation |
zim relation |
Explicitly solve a relation or inequality |
zim system |
Solve a linear system |
zim nonlinear |
Solve a supported nonlinear system |
zim polynomial |
Analyze polynomial roots |
zim derive |
Generate a derivation/explanation |
zim calculate |
Run an exact or decimal calculation |
zim differentiate |
Compute exact ordered derivatives |
zim limit |
Evaluate supported exact limits |
zim integrate |
Integrate symbolically or numerically |
zim format |
Format an expression |
zim latex |
Generate LaTeX |
zim capabilities |
Inspect engine capabilities |
zim repl |
Start the interactive CLI |
npm run build
node packages/cli/dist/cli.js parse "x^2 = 4"
node packages/cli/dist/cli.js simplify --trace "1 * (2 + 3)"
node packages/cli/dist/cli.js solve --variable x "x^2 = 4"
node packages/cli/dist/cli.js solve --variable x --domain complex "x^2 + 1 = 0"
node packages/cli/dist/cli.js system --variables x,y "x + y = 5; x - y = 1"
node packages/cli/dist/cli.js relation --variable x "x^2 - 4 < 0"
node packages/cli/dist/cli.js polynomial --variable x "x^3 - 2"
node packages/cli/dist/cli.js nonlinear --variables x,y "x * y = 2; x + y = 3"
node packages/cli/dist/cli.js derive --variable x --render-mode classroom "sqrt(x + 1) = x - 1"
node packages/cli/dist/cli.js calculate --result-mode decimal --angle-unit degrees "sin(30) + sqrt(9)"
node packages/cli/dist/cli.js calculate --answer "1/2" "Ans + 1/2"
node packages/cli/dist/cli.js differentiate --variables x "x^3 + sin(x)"
node packages/cli/dist/cli.js limit --variable x --point 0 "sin(x) / x"
node packages/cli/dist/cli.js integrate --variable x "x^2"
node packages/cli/dist/cli.js integrate --variable x --lower 0 --upper 1 --integration-mode numeric --precision-digits 30 "exp(-x^2)"
node packages/cli/dist/cli.js format "(x + 1) * (x - 1)"
node packages/cli/dist/cli.js latex "x^2 = 1/4"
node packages/cli/dist/cli.js capabilities
node packages/cli/dist/cli.js replCommand options:
parse:--jsonsimplify:--trace,--jsonsolve:--variable, -v <name>,--domain <real|complex>,--json,--latexrelation:--variable, -v <name>,--jsonsystem:--variables <name,...>,--jsonpolynomial:--variable, -v <name>,--jsonnonlinear:--variables <name,...>,--mode <exact|numeric>,--initial-guess <x=...,y=...>,--max-iterations <n>,--tolerance <number>,--max-resultant-degree <n>,--jsonderive:--variable, -v <name>,--render-mode <concise|classroom|diagnostic>,--locale <locale>,--max-derivation-nodes <n>,--jsoncalculate:--result-mode <exact|decimal>,--angle-unit <radians|degrees>,--precision-digits <1..15>,--answer <expression>,--json,--latexdifferentiate:--variables <name,...>,--json,--latexlimit:--variable, -v <name>,--point <value|infinity>,--direction <both|left|right>,--json,--latexintegrate:--variable, -v <name>, optional exact--lowerand--upper,--integration-mode <symbolic|numeric>,--precision-digits <n>,--max-iterations <n>,--max-series-terms <n>,--json,--latexcapabilities:--json
Use zim --help or zim <command> --help for terminal help. Human-readable text is the default; --json returns the complete API-v2 envelope. The solve command automatically routes inequalities to the relation solver.
Invalid and unsupported requests also retain the complete API-v2 envelope in --json mode. Plain zim parse continues to print the AST directly for compatibility, while zim parse --json prints the versioned envelope.
Exit code 0 means success, 2 means invalid CLI/input syntax, and 3 means the expression parsed correctly but solving is unsupported.
API v2 (2.0-beta) supports parse, simplify, solve, solveSystem, format, latex, capabilities, analyzePolynomial, solveRelation, solveNonlinearSystem, derive, differentiate, limit, integrate, and calculate. Every operation is available from executeV2, the CLI, and the local GUI. The GUI server accepts the same request envelopes at POST /api/v2; POST /api/v1 remains available.
executeV2({
apiVersion: "2.0-beta",
operation: "solveRelation",
relation: "x^2 - 4 < 0",
variable: "x",
});
executeV2({
apiVersion: "2.0-beta",
operation: "analyzePolynomial",
expression: "x^3 - 2",
variable: "x",
});
executeV2({
apiVersion: "2.0-beta",
operation: "solveNonlinearSystem",
equations: ["x*y=2", "x+y=3"],
variables: ["x", "y"],
});
executeV2({
apiVersion: "2.0-beta",
operation: "derive",
expression: "sqrt(x+1)=x-1",
variable: "x",
renderMode: "classroom",
});
executeV2({ apiVersion: "2.0-beta", operation: "capabilities" });- Integers and finite decimals:
12,.5,12.50(stored exactly) - Identifiers:
x,velocity2,_internal - Unary
+and- - Powers
^(right-associative) - Multiplication
*, division/, modulo%ormod - Addition and subtraction
- Parentheses, function calls, commas, and absolute-value bars
- Equations using
=and first-class relations using!=,<,<=,>, and>=(Unicode forms are normalized)
Implicit multiplication such as 2x is not supported. Use 2 * x.
Domain-changing rules are disabled unless their assumptions are explicit. By default, x/x and x^0 remain unchanged because x might be zero. A caller that knows x != 0 can pass:
simplify(parse("x/x + x^0"), { nonZeroVariables: ["x"] });Rational-equation verification retains restrictions from the original, unsimplified denominators. Relation and nonlinear-system solvers return explicit unsupported or incomplete states when they cannot certify every boundary or solution branch; an unproved empty set is never reported as a successful no-solution result.
- Linear and quadratic equations over the real domain, plus complex quadratic roots when
domain: "complex"is selected - Higher-degree polynomials with exact rational factors, binomial forms, and reducible power-composition forms
- Certified square-free decomposition, multiplicities, exact Sturm real-root isolation, up to 200 significant digits of certified real refinement, and complete complex approximations with residual diagnostics
- Rational equations with polynomial variable denominators and exclusion filtering
- Exponential, natural-logarithmic, standard inverse-pattern trigonometric, radical, and Lambert W forms
- Typed finite, interval, union, empty, universal, conditional, and integer-parameter solution sets
- Polynomial and rational inequalities, absolute-value equations/inequalities, guarded piecewise branches, and bounded/periodic trigonometric cases
- Simultaneous linear systems with exact Gaussian elimination, including unique, infinite, and inconsistent classifications
- Bounded two-variable nonlinear systems using exact substitution, square-resultant elimination, or opt-in Newton iteration with Jacobian and residual diagnostics
General irreducible cubic/quartic radical formulas, arbitrary nonlinear elimination, and arbitrary transcendental rearrangement remain explicit unsupported boundaries. Irreducible polynomials are available through algebraic intervals and numerical approximations rather than potentially explosive radical forms. Nonlinear systems outside the bounded two-variable strategies return explicit unsupported or incomplete results.
- Exact first, higher-order, and ordered partial derivatives with product, quotient, chain, power, and elementary-function rules
- Conservative finite, one-sided, removable-singularity, pole, and infinity limits
- Verified symbolic antiderivatives for polynomial, power, exponential, logarithmic, and basic trigonometric families
- Definite integration with interval-domain checks
- Arbitrary-precision numerical quadrature with requested precision, error evidence, and explicit iteration or series budget outcomes
Unsupported antiderivatives and unproved limits remain explicitly unevaluated or unsupported; Zim does not guess a plausible-looking result.
packages/core/src: new Zim 2 production sourcepackages/core/test: unit, structural, regression, and invariant testspackages/gui: local web GUI, direct/protocol clients, and end-to-end testsdatasets/regression: legacy, polynomial, and linear-equation regression datasetsdatasets/future: advanced solver fixtures and capability-boundary casesdatasets/gui: Week 11-13 GUI workflow and safety fixtureslegacy: isolated pre-overhaul implementation and source datasets