Registry / ai-ml / algebra.js

algebra.js

JSON →
library0.2.6jsnpmunverified

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.

npm install algebra.js
INSTALL
IMPORT
SIG · ALGEBRA.JS
A
algebra.js
ai-mljavascriptv0.2.6
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

algebra
✓ const algebra = require('algebra.js');
✗ import algebra from 'algebra.js';
This library is a CommonJS module. The `algebra` object is the main export, containing all constructors and utility methods.
Expression
✓ const algebra = require('algebra.js'); const expr = new algebra.Expression('x');
✗ const { Expression } = require('algebra.js'); // or import { Expression } from 'algebra.js';
`Expression` is a constructor exposed as a property of the main `algebra` export, not a named export itself.
Equation
✓ const algebra = require('algebra.js'); const eq = new algebra.Equation(expr, 4);
✗ const { Equation } = require('algebra.js'); // or import { Equation } from 'algebra.js';
`Equation` is a constructor exposed as a property of the main `algebra` export, not a named export itself.
Fraction
✓ const algebra = require('algebra.js'); const frac = new algebra.Fraction(1, 2);
✗ const { Fraction } = require('algebra.js'); // or import { Fraction } from 'algebra.js';
`Fraction` is a constructor exposed as a property of the main `algebra` export, used for precise fractional arithmetic.
parse
✓ const algebra = require('algebra.js'); const exp = algebra.parse("x^2 + 4 * x + 4");
✗ const { parse } = require('algebra.js'); // or import { parse } from 'algebra.js';
The `parse` utility method is directly available on the main `algebra` object for parsing strings into expressions or equations.

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
Debug
Known issues
gotchaIn versions prior to 0.2.0, solving single-variable equations with an infinite number of solutions would return `undefined`. This behavior changed in 0.2.0 to return `Fraction(1, 1)`.
fix
Update to version 0.2.0 or later and adjust logic to handle `Fraction(1, 1)` instead of `undefined` for infinite solutions.
affects: <0.2.0
gotchaVersions prior to 0.2.4 contained a bug where solving quadratic equations with irrational solutions when the 'a' coefficient was greater than 1 yielded incorrect results. Relying on such solutions in older versions would have produced wrong output.
fix
Upgrade to version 0.2.4 or newer to ensure correct solving of quadratic equations under these conditions.
affects: <0.2.4
gotchaThe parser in versions prior to 0.2.2 incorrectly handled negative numbers (throwing an error) and misinterpreted adjacent parentheses. Code relying on previous buggy parser behavior or error handling for these cases will need adjustment.
fix
Upgrade to version 0.2.2 or newer to benefit from improved parser robustness and correct interpretation of negative numbers and adjacent parentheses.
affects: <0.2.2
gotcha`Expression.simplify()` in versions prior to 0.2.1 would sometimes fail to fully simplify expressions consisting only of unsimplified constants, reducing them to two constants instead of a single one. This could lead to unexpected unsimplified numerical results.
fix
Update to version 0.2.1 or later to ensure `Expression.simplify()` consistently reduces expressions to their single simplest constant form.
affects: <0.2.1
Upgrade
Version history
0.2.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
14
OpenAI (training)
2
Perplexity
1
Resources
algebra.js — npm install algebra.js · libregistry