npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

polynomium

v0.1.9

Published

Library for symbolically representing and working with polynomials.

Downloads

387

Readme

polynomium

Library for symbolically representing and working with polynomials.

npm version

Package Installation and Usage

The package is available on npm:

npm install polynomium

The library can be imported in the usual ways:

var polynomium = require('polynomium');

The library also supports standalone usage in browsers:

<script src="https://lapets.github.io/polynomium/lib/polynomium.js"></script>

Examples

The library supports the creation of objects that represent polynomials of zero or more variables:

var x = polynomium.v('x');
var y = polynomium.v('y');
var a = polynomium.c(2);
var b = polynomium.c(3);
var c = polynomium.c(5);
var p = (y.mul(x.add(b)));
var q = (y.mul(x.add(b))).mul(a);
var r = (y.mul(x.add(b))).mul((y.mul(x.add(b))));

Given the polynomials above, it is possible to display them in a human-readable way:

> x.toString()
'x'
> b.toString()
'3'
> (y.add(x.add(b))).toString()
'y + x + 3'
> p.toString()
'x*y + 3y'
> q.toString()
'2x*y + 6y'
> q.maxCoefficients(p).toString()
'2x*y + 6y'
> r.toString()
'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.add(x.add(5))).toString()
'y + x + 5'
> (y.add('x')).toString()
'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:

> r.evaluate({"x":2, "y":5})
625
> r({"x":2, "y":5})
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.toObject()
> o
{ polynomium: true,
  terms: 
   { 'y': { '2': 9 }, 
     'x,y': { '1,2': 6, '2,2': 1 } } }
> polynomium.add(o, o).toObject()
{ 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