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

lex-polynomial

v1.0.0

Published

This library provides classes to work with polynomials, monomials, and terms. The main classes included are `Polynomial`, `Monomial`, and `Term`.

Downloads

3

Readme

Lex-Polynomial Library

This library provides classes to work with polynomials, monomials, and terms. The main classes included are Polynomial, Monomial, and Term.

Installation

You can install this library by cloning the repository and importing the classes as needed.

npm install lex-polynoimal

Usage

Importing the Classes

import { Monomial, Term, Polynomial } from 'lex-polynomial'

Creating Monomials

A Monomial represents a single term in a polynomial with variables and their respective powers.

const monomial = new Monomial({ x: 2, y: 1 });
console.log(monomial.toString()); // Outputs: x^2y

Creating Terms

A Term consists of a coefficient and a Monomial.

const monomial = new Monomial({ x: 2, y: 1 });
const term = new Term(3, monomial);
console.log(term.toString()); // Outputs: 3x^2y

Creating Polynomials

A Polynomial is a collection of Term objects.

const term1 = new Term(3, new Monomial({ x: 2, y: 1 }));
const term2 = new Term(-1, new Monomial({ y: 1 }));
const polynomial = new Polynomial([term1, term2]);
console.log(polynomial.toString()); // Outputs: 3x^2y-y

You can also create a Polynomial from a string representation:

const polynomial = new Polynomial("3x^2y - y");
console.log(polynomial.toString()); // Outputs: 3x^2y-y

Operations on Polynomials

Addition

const poly1 = new Polynomial("3x^2y - y");
const poly2 = new Polynomial("x^2y + 2");
const sum = poly1.add(poly2);
console.log(sum.toString()); // Outputs: 4x^2y-y+2

Subtraction

const poly1 = new Polynomial("3x^2y - y");
const poly2 = new Polynomial("x^2y + 2");
const difference = poly1.sub(poly2);
console.log(difference.toString()); // Outputs: 2x^2y-y-2

Multiplication

const poly1 = new Polynomial("3x^2y - y");
const poly2 = new Polynomial("x + 1");
const product = poly1.multiplyPolynomial(poly2);
console.log(product.toString()); // Outputs: 3x^3y+3x^2y-yx-y

Division

const poly1 = new Polynomial("3x^2y - y");
const term = new Term(3, new Monomial({ x: 2 }));
const quotient = poly1.divideByTerm(term);
console.log(quotient.toString()); // Outputs: y - y/(3x^2)

Class Methods

Monomial

  • getVarNames(): Returns the sorted variable names.
  • getVariables(): Returns the variables with their powers.
  • toString(): Returns the string representation.
  • dividableByMonomial(mono): Checks if the monomial is divisible by another monomial.
  • compare(mono): Compares two monomials.
  • equal(mono): Checks if two monomials are equal.
  • static isSame(mono1, mono2): Static method to check if two monomials are the same.
  • static compare(mono1, mono2): Static method to compare two monomials.
  • static getGCD(mono1, mono2): Static method to get the GCD of two monomials.
  • static getLCM(mono1, mono2): Static method to get the LCM of two monomials.

Term

  • getCoefficient(): Returns the coefficient.
  • getMonomial(): Returns the monomial part.
  • getVarNames(): Returns the variable names.
  • getVariables(): Returns the variables.
  • toString(): Returns the string representation.
  • getNonCoefficientPart(): Returns the non-coefficient part as a monomial.
  • multiplyPolynomial(poly): Multiplies the term with a polynomial.
  • divideByMonomial(divisor): Divides the term by a monomial.
  • divideByTerm(divisor): Divides the term by another term.
  • static compare(term1, term2): Static method to compare two terms.

Polynomial

  • getLeadingTerm(): Returns the leading term.
  • getLeadingCofficient(): Returns the leading coefficient.
  • getLeadingMonomial(): Returns the leading monomial.
  • getTerms(): Returns the terms.
  • removeTerm(removeTerm): Removes a term.
  • negative(): Returns the negation of the polynomial.
  • multiplyTerm(term): Multiplies the polynomial by a term.
  • divideByTerm(term): Divides the polynomial by a term.
  • multiplyPolynomial(poly): Multiplies the polynomial by another polynomial.
  • quotient(divisor): Returns the quotient of the polynomial division.
  • reminder(divisor): Returns the remainder of the polynomial division.
  • divideByPolynomial(divisor): Divides the polynomial by another polynomial.
  • clone(): Clones the polynomial.
  • toString(): Returns the string representation.
  • add(poly): Adds another polynomial.
  • sub(poly): Subtracts another polynomial.
  • static sum(poly1, poly2): Static method to sum two polynomials.
  • static createTermsFromString(polyString): Static method to create terms from a string.