polynomium
Library for symbolically representing and working with polynomials.
Package Installation and Usage
The package is available on npm:
npm install polynomium
The library can be imported in the usual ways:
var polynomium = ;
The library also supports standalone usage in browsers:
Examples
The library supports the creation of objects that represent polynomials of zero or more variables:
var x = polynomium;var y = polynomium;var a = polynomium;var b = polynomium;var c = polynomium;var p = y;var q = y;var r = y;
Given the polynomials above, it is possible to display them in a human-readable way:
> x'x'> b'3'> y'y + x + 3'> p'x*y + 3y'> q'2x*y + 6y'> q'2x*y + 6y'> r'x^2*y^2 + 6x*y^2 + 9y^2'
When possible, the operator functions will convert arguments that are numeric constants and valid variable names into polynomium objects:
> y'y + x + 5'> y'y + x'
By default, the terms in the outer sum are in order of descending significance (where a term's significance is the sum of its exponents across its factors). The individual variables within factors are in ascending alphabetical order.
It is also possible to evaluate a polynomial by supplying an object that binds explicit values to each variable:
> r625> 625
In some cases, function objects cannot be used within data structures (such as when converting to JSON). A method is included for such scenarios:
> var o = r> o polynomium: true terms: 'y': '2': 9 'x,y': '1,2': 6 '2,2': 1 > polynomium polynomium: true terms: 'y': '2': 18 'x,y': '1,2': 12 '2,2': 2
Testing
Unit tests are included in test/test.js
. They can be run using Mocha:
npm test