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 🙏

© 2026 – Pkg Stats / Ryan Hefner

math-extensive

v1.0.3

Published

An npm package with non-common math functions: Pascal's triangle/pyramid (binomial expansion), linear programming (simplex method), and extended trigonometry.

Downloads

170

Readme

math-extensive

An npm package with non-common math functions:

  • Pascal's triangle & pyramid – binomial expansion coefficients and trinomial (Pascal pyramid) coefficients
  • Linear Programming – simplex method for maximisation (simplex) and two-phase simplex for minimisation (minimise)
  • Trigonometry – reciprocal, inverse, hyperbolic, versed/haversine functions, triangle laws, and angle utilities

Installation

npm install math-extensive

Usage

const math = require('math-extensive');

// Or import individual modules:
const { pascalRow, pascalTriangle, pascalPyramid, binomialCoefficient } = require('math-extensive/src/pascal');
const { simplex, minimise } = require('math-extensive/src/linearProgramming');
const trig = require('math-extensive/src/trigonometry');

Pascal's Triangle & Pyramid

pascalRow(rowIndex)

Returns a single row of Pascal's triangle (zero-based).

math.pascalRow(5); // [1, 5, 10, 10, 5, 1]

pascalTriangle(numRows)

Returns the full triangle as a 2-D array.

math.pascalTriangle(4);
// [[1], [1,1], [1,2,1], [1,3,3,1]]

binomialCoefficient(n, k)

Computes C(n, k).

math.binomialCoefficient(10, 3); // 120

binomialExpansionCoefficients(n)

Returns all coefficients of (a + b)^n.

math.binomialExpansionCoefficients(4); // [1, 4, 6, 4, 1]

pascalPyramid(depth)

Generates Pascal's pyramid (trinomial coefficients) up to the given depth.
Layer d contains all coefficients of (a + b + c)^d.

const pyramid = math.pascalPyramid(2);
// pyramid[2] = [[1,2,1],[2,2],[1]]  (coefficients of (a+b+c)^2)

Linear Programming

simplex(c, A, b) – Maximisation

Maximises c · x subject to A · x ≤ b, x ≥ 0, b ≥ 0.

// max 3x + 5y  s.t.  x <= 4, 2y <= 12, 3x + 5y <= 25
const { status, value, solution } = math.simplex(
  [3, 5],
  [[1, 0], [0, 2], [3, 5]],
  [4, 12, 25]
);
// status: 'optimal', value: 25, solution: [x, y]

Returns { status, value, solution } where status is one of:

  • 'optimal' – optimal solution found
  • 'unbounded' – objective is unbounded
  • 'infeasible' – no feasible solution (via phase-1 check)

minimise(c, A, b) – Minimisation

Minimises c · x subject to A · x ≥ b, x ≥ 0, b ≥ 0.
Uses two-phase simplex internally.

// min x1 + x2  s.t. x1 + x2 >= 2, x1 >= 1
const { status, value, solution } = math.minimise(
  [1, 1],
  [[1, 1], [1, 0]],
  [2, 1]
);
// status: 'optimal', value: 2

Trigonometry

Conversion

math.toRadians(180); // Math.PI
math.toDegrees(Math.PI); // 180

Standard (degree variants)

math.sinDeg(90);  // 1
math.cosDeg(0);   // 1
math.tanDeg(45);  // 1

Reciprocal functions

| Function | Description | |----------|-------------| | csc(rad) / cscDeg(deg) | Cosecant | | sec(rad) / secDeg(deg) | Secant | | cot(rad) / cotDeg(deg) | Cotangent |

Inverse reciprocal functions

math.acsc(1);  // π/2
math.asec(1);  // 0
math.acot(1);  // π/4

Hyperbolic reciprocal & inverse hyperbolic

math.sech(0);   // 1
math.csch(1);   // 1/sinh(1)
math.coth(2);   // cosh(2)/sinh(2)

math.asech(0.5);  // inverse hyperbolic secant
math.acsch(2);    // inverse hyperbolic cosecant
math.acoth(2);    // inverse hyperbolic cotangent

Versed / haversine

math.versin(Math.PI);   // 2
math.haversin(Math.PI); // 1

// Great-circle distance between London and Paris (km)
math.haversineDistance(51.5074, -0.1278, 48.8566, 2.3522); // ~340 km

Triangle helpers

// Law of cosines – find side c given sides a, b and angle C (degrees)
math.lawOfCosinesSide(3, 4, 90); // 5 (Pythagoras)

// Law of cosines – find angle C given all three sides
math.lawOfCosinesAngle(1, 1, 1); // 60° (equilateral)

// Law of sines – find side b given side a, angle A, angle B
math.lawOfSinesSide(1, 60, 60); // 1

Angle normalisation

math.normalizeAngleDeg(370);  // 10
math.normalizeAngleDeg(-90);  // 270
math.normalizeAngle(-Math.PI); // Math.PI

Testing

npm test