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

@neoncitylights/series

v1.0.1

Published

A TypeScript math library for working with series and progressions

Downloads

7

Readme

@neoncitylights/series

License: MIT npm (scoped) Codecov GitHub Workflow Status (with event)

A TypeScript math library for working with progressions and series.

Install

npm install @neoncitylights/series

Documentation

Auto-generated API documentation is available.

There are 3 types of a progression in math:

  • Arithmetic progression: A sequence of numbers where the consecutive difference between each term is a constant. E.g., an arithmetic progression of 5 numbers, with 2 as the common difference, starting at 1: $$1, 3, 5, 7, 9$$
  • Geometric progression: A sequence of numbers where there is a common ratio between each term. That ratio is found by multiplying the previous term by a non-zero number. E.g., a geometric progression of 6 numbers, with 2 as the common ratio, starting at 5: $$5, 10, 20, 40, 80, 160$$
  • Harmonic progression: A sequence of numbers where each term is the harmonic mean of its previous term and next term. E.g., a harmonic progression of 6 numbers, with 2 as the scaling value, starting at 1: $$1, \frac{1}{2}, \frac{1}{3}, \frac{1}{4}, \frac{1}{5}, \frac{1}{6}$$

API

Generators

  • fn: # generators.newArithmeticProgression(startNumber, length, step): number[]source, docs
  • fn: # generators.newGeometricProgression(startNumber, length, scale): number[]source, docs
  • fn: # generators.newHarmonicProgression(startNumber, length, scale): number[]source, docs

Predicates

  • fn: # predicates.isArithmeticProgression(numbers): ProgressionResultsource, docs
  • fn: # predicates.isGeometricProgression(numbers): ProgressionResultsource, docs
  • fn: # predicates.isHarmonicProgression(numbers): ProgressionResultsource, docs

Totals (sums and products)

  • fn: # total.getProductFromArray(factors, lambda): number • source, docs
  • fn: # total.getProductFromBounds(lower, upper, lambda): number • source, docs
  • fn: # total.getSumFromArray(summands, lambda): number • source, docs
  • fn: # total.getSumFromBounds(lower, upper, lambda): number • source, docs

There are constants for certain music intervals that can be used coincide with the generator functions.

  • C: # MinorSecond
  • C: # MajorSecond
  • C: # MinorThird
  • C: # MajorThird
  • C: # PerfectThird
  • C: # AugmentedFourth
  • C: # PerfectFifth
  • C: # GoldenRatio
  • C: # MajorSixth
  • C: # MajorSeventh
  • C: # EmptySum
  • C: # EmptyProduct

Examples

Convergent series

Given a length of an arbitrarily large number, we can prove, model, and visualize convergent series; that is, the sum of an infinite sequence resulting in a finite number.

We can use newArithmeticProgression to find the sequence of summands, and getSumFromArray() for passing in the summands for the sum; we can also only use getSumFromBounds() to find the sum.

For example:

const ARBITRARILY_LARGE_LIMIT = 500;
getSumFromBounds(1, ARBITRARILY_LARGE_LIMIT, (n) => (Math.pow(-1, n+1)/Math.pow(2, n)));
// absolute alternating convergence
// 1/2 − 1/4 + 1/8 − 1/16 + ⋯ = 0.3333333333333333 (1/3)

getSumFromBounds(1, ARBITRARILY_LARGE_LIMIT, (n) => (1/Math.pow(4,n)));
// 1/4 + 1/16 + 1/64 + 1/256 + ⋯ = 0.3333333333333333 (1/3)

getSumFromBounds(1, ARBITRARILY_LARGE_LIMIT, (n) => Math.pow(1/2, n));
// 1/2 + 1/4 + 1/8 + 1/16 + ⋯ = 1

getSumFromBounds(1, ARBITRARILY_LARGE_LIMIT, (n) => 1/(n * (n-1)));
// 1/2 + 1/4 + 1/6 + 1/12 + 1/20 + 1/30 + ⋯ = 0

const riemannZeta = (s: number, limit: ABSOLUTELY_LARGE_LIMIT) => {
  getSumFromBounds(1, n, (n) => 1/(n ** s));
}

Typographic scales

This library can be used to generate a typography scale for web projects.

For example, to generate a scale on a major second where the base font size is 16px:

newGeometricProgression(16, 6, MajorSecond).map(n => `${n.toFixed(3)}px`);
// ["16.000px", "18.000px", "20.250px", "22.781px", "25.629px", "28.833px"]

These floating points aren't easy to remember, so we have the option to modify this scale by rounding each value:

newGeometricProgression(16, 6, MajorSecond).map(n => `${Math.round(n)}px`);
// ["16px", "18px", "20px", "23px", "26px", "29px"]

License

This library is licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.