A TypeScript math library for working with progressions and series.
npm install @neoncitylights/series
Auto-generated API documentation is available.
There are 3 types of a progression in math:
fn
: # generators.newArithmeticProgression(startNumber, length, step): number[] • source, docsfn
: # generators.newGeometricProgression(startNumber, length, scale): number[] • source, docsfn
: # generators.newHarmonicProgression(startNumber, length, scale): number[] • source, docsfn
: # predicates.isArithmeticProgression(numbers): ProgressionResult • source, docsfn
: # predicates.isGeometricProgression(numbers): ProgressionResult • source, docsfn
: # predicates.isHarmonicProgression(numbers): ProgressionResult • source, docsfn
: # total.getProductFromArray(factors, lambda): number • source, docsfn
: # total.getProductFromBounds(lower, upper, lambda): number • source, docsfn
: # total.getSumFromArray(summands, lambda): number • source, docsfn
: # total.getSumFromBounds(lower, upper, lambda): number • source, docsThere are constants for certain music intervals that can be used coincide with the generator functions.
C
: # MinorSecondC
: # MajorSecondC
: # MinorThirdC
: # MajorThirdC
: # PerfectThirdC
: # AugmentedFourthC
: # PerfectFifthC
: # GoldenRatioC
: # MajorSixthC
: # MajorSeventhC
: # EmptySumC
: # EmptyProductGiven 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));
}
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"]
This library is licensed under the MIT license (LICENSE-MIT
or http://opensource.org/licenses/MIT).
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.
Generated using TypeDoc