Algebra.js Symbolic Equation Solver

0.2.6 · maintenance · verified Tue Apr 21

Algebra.js is a JavaScript library designed for building, displaying, and solving algebraic equations. As of version 0.2.6, it provides core functionalities for creating `Fraction` objects for precise arithmetic, `Expression` objects to represent algebraic expressions, and `Equation` objects to encapsulate equalities. A key differentiator is its ability to parse string representations of expressions and equations, enabling convenient construction from human-readable input. The library also includes methods for symbolic simplification, evaluation, and solving linear, quadratic, cubic, and quartic equations, along with a `toTex()` method for LaTeX output. It primarily targets Node.js and browser environments using CommonJS module syntax. The release cadence is infrequent, with recent updates focusing on bug fixes and stability within the 0.2.x series.

Warnings

Install

Imports

Quickstart

Demonstrates creating expressions, equations, displaying them, solving for a variable, and using the string parser.

const algebra = require('algebra.js');

// Create an expression
let expr = new algebra.Expression("x");
expr = expr.subtract(3);
expr = expr.add("x");

console.log(expr.toString()); // Expected: 2x - 3

// Create an equation from the expression
const eq = new algebra.Equation(expr, 4);

console.log(eq.toString()); // Expected: 2x - 3 = 4

// Solve the equation for 'x'
const x = eq.solveFor("x");

console.log("x = " + x.toString()); // Expected: x = 7/2

// Use the parser to create an equation directly from a string
const quadraticEq = algebra.parse("x^2 + 4 * x + 4 = 0");
console.log(quadraticEq.toString()); // Expected: x^2 + 4x + 4 = 0

view raw JSON →