An open API service indexing awesome lists of open source software.

https://github.com/clumsycomputer/clumsy-math

a little library of helpful math utensils 🙂
https://github.com/clumsycomputer/clumsy-math

math typescript

Last synced: 12 months ago
JSON representation

a little library of helpful math utensils 🙂

Awesome Lists containing this project

README

          

# clumsy-math

a math library for the clumsy and curious 🙂

## installation

```bash
yarn add clumsy-math
```

## documentation

- **[spacer _(concepts)_](#spacer-concepts)**

- **[spacer _(encodings)_](#spacer-encodings)**

- **[spacer _(functions)_](#spacer-functions)**

- **[prime _(concepts)_](#prime-concepts)**

- **[prime _(functions)_](#prime-functions)**

- **[prime _(encodings)_](#prime-encodings)**

- **[loop _(functions)_](#loop-functions)**

## spacer _(concepts)_

###### aligned recursive euclid spacer

> a recursive euclid spacer where each layer has a point at the zero slot

```typescript
const baseEuclidMap = [true, true, false, true, false]
const terminalEuclidMap = [true, false, true]
const resultEuclidMap = [true, false, false, true, false]
```

###### basic euclid spacer

> a euclid spacer that has an orientation and phase of zero (default layout) (most left dense)

```typescript
const euclidMapA = [true, true, false, true, false] // basic
const euclidMapB = [true, false, true, false, true] // not basic
const euclidMapC = [true, false, true, true, false] // not basic
```

###### component spacer

> a recursive euclidean spacer of a recursive euclidean spacer

```typescript
const baseComponentMap = [true, true, false, true, false]
const interposedComponentMap = [true, false, false, true, false]
const terminalComponentMap = [true, false, false, false, false]
```

###### core euclid spacer

> a basic euclid spacer that is reduced to its simplest form

```typescript
const fullEuclidMap = [true, false, true, false]
const coreEuclidMap = [true, false]
```

###### euclid spacer

> a spacer whose points are as evenly distributed as possible throughout a discrete space

```typescript
const euclidMapA = [true, true, false, true, false]
const euclidMapB = [true, false, true, false, true]
const euclidMapC = [true, false, true, true, false]
```

###### phased recursive euclid spacer

> a recursive euclid spacer where all of the individual layers are phaseable

```typescript
const baseEuclidMap = [true, true, false, true, false]
const terminalEuclidMap = [false, true, true]
const resultEuclidMap = [false, true, false, true, false]
```

###### recursive euclid spacer

> a spacer where euclid spacers are stacked on top of one another such that the base spacer's density / points determines the next spacer's resolution / space

```typescript
const baseEuclidMap = [true, true, false, true, false]
const terminalEuclidMap = [true, true, flase]
const resultEuclidMap = [true, true, false, false, false]
```

###### spacer

> a discrete sequence / cycle of binary values (slots)

```typescript
const spacerString = "1010"
const spacerMap = [true, false, true, false];
const spacer = {
resolution: 4,
points: [0, 2]
}
```

###### spacer density

> the number of points in a spacer

```typescript
const spacerMap = [true, true, false, true, false]
const spacerPoints = [0, 1, 3]
const spacerDensity = 3 // spacerPoints.length
```

###### spacer group

> a set of aligned recursive euclidean spacers that share a static base structure and a dynamic member structure where the density structure is the same but orientations are different

```typescript
const groupBase = [true, true, false, true, false]
const groupMapsA = [
[true, true, false, true, false],
[true, false, false, true, false],
]
```

###### spacer interval

> starting at a base point, the distance upto the next point

```typescript
const spacerMap = [true, true, false, true, false]
const spacerPoints = [0, 1, 3]
const spacerIntervals = [1, 2, 2]
```

###### spacer lineage

> all spacer groups an aligned recursive euclidean spacer belongs to

```typescript
const spacerMapA = [true, false, false, true, false]
const lineageMapsA = [
[
[true, true, false, false, false],
[true, false, false, true, false],
[true, false, true, false, false],
[true, false, false, false, true],
[true, false, true, false, false],
[true, false, false, true, false],
],
[
[true, true, false, false, false],
[true, false, false, true, false],
],
];
```

###### spacer orientation

> the offset of an aligned spacer, measured in points, relative to a base spacer

```typescript
const baseSpacerMap = [true, true, false, true, false]
const spacerOrientation = 2
const reorientedSpacerMap = [true, false, true, true, false]
```

###### spacer phase

> the offset of a spacer, measured in slots, relative to a base spacer

```typescript
const baseSpacerMap = [true, true, false, true, false]
const spacerPhase = -1; // spacerMap.length
const phasedSpacerMap = [false, true, true, false, true]
```

###### spacer point

> the index of a slot whose value is true (1)

```typescript
const spacerMap = [true, true, false, true, false]
const spacerPoints = [0, 1, 3]
```

###### spacer point weight

> a point's corresponding slot weight

```typescript
const spacerMapA = [true, true, false, true, false]; // 1, 1, 0, 1, 0
const spacerMapB = [true, false, true, false, true]; // 1, 0, 1, 0, 1
const spacerMapC = [true, false, true, true, false]; // 1, 0, 1, 1, 0
const groupSlotWeights = [3, 1, 2, 2, 1];
const spacerPointsA = [0, 1, 3]
const spacerPointWeightsA = [3, 1, 2]
```

###### spacer relative point

> a point whose value is normalized within the range of [0, 1)

```typescript
const spacerMap = [true, true, false, true, false]
const spacerPoints = [0, 1, 3]
const relativeSpacerPoints = [0.0, 0.2, 0.6]
```

###### spacer resolution

> the number of slots constituting a spacer

```typescript
const spacerMap = [true, true, false, true, false]
const spacerResolution = 5; // spacerMap.length
```

###### spacer slot

> the building block of spacer

```typescript
const spacerMap = [true, true, false, true, false]
const spacerSlotZero = spacerMap[0] // true
const spacerSlotTwo = spacerMap[2] // false
```

###### spacer slot weight

> the sum of points at a slot across a set of spacers with the same resolution

```typescript
const spacerMapA = [true, true, false, true, false]; // 1, 1, 0, 1, 0
const spacerMapB = [true, false, true, false, true]; // 1, 0, 1, 0, 1
const spacerMapC = [true, false, true, true, false]; // 1, 0, 1, 1, 0
const groupSlotWeights = [3, 1, 2, 2, 1];
const slotWeightZero = 3; // groupSlotWeights[0]
```

###### spacer weight

> the sum of a spacer's point weight

```typescript
const spacerMapA = [true, true, false, true, false]; // 1, 1, 0, 1, 0
const spacerMapB = [true, false, true, false, true]; // 1, 0, 1, 0, 1
const spacerMapC = [true, false, true, true, false]; // 1, 0, 1, 1, 0
const groupSlotWeights = [3, 1, 2, 2, 1];
const spacerPointsA = [0, 1, 3]
const spacerPointWeightsA = [3, 1, 2]
const spacerWeightA = 6 // 3 + 1 + 2
```

## spacer _(encodings)_

###### AlignedEuclidSpacerLayer

> encoding for defining a [AlignedRecursiveEuclidSpacerStructure](#alignedrecursiveeuclidspacerstructure) layer's components

###### AlignedRecursiveEuclidSpacer

> [aligned recursive euclid spacer](#aligned-recursive-euclid-spacer) as [Spacer](#spacer-1)

###### AlignedRecursiveEuclidSpacerStructure

> ergonomic encoding for defining [aligned recursive euclid spacer](#aligned-recursive-euclid-spacer)

###### AlignedSpacerStructure

> compressed alias for [AlignedRecursiveEuclidSpacerStructure](#alignedrecursiveeuclidspacerstructure)

###### BasicEuclidSpacer

> [basic euclid spacer](#basic-euclid-spacer) as [Spacer](#spacer-1)

###### CoreEuclidSpacer

> [core euclid spacer](#core-euclid-spacer) as [Spacer](#spacer-1)

###### EuclidSpacer

> [euclid spacer](#euclid-spacer) as [Spacer](#spacer-1)

###### EuclidSpacerMap

> [euclid spacer](#euclid-spacer) as [SpacerMap](#spacermap)

###### PhasedEuclidSpacerLayer

> encoding for defining a [PhasedRecursiveEuclidSpacerStructure](#phasedrecursiveeuclidspacerstructure) layer's components

###### PhasedRecursiveEuclidSpacer

> [phased recursive euclid spacer](#phased-recursive-euclid-spacer) as [Spacer](#spacer-1)

###### PhasedRecursiveEuclidSpacerStructure

> ergonomic encoding for defining [phased recursive euclid spacer](#phased-recursive-euclid-spacer)

###### PhasedSpacerStructure

> compressed alias for [PhasedRecursiveEuclidSpacerStructure](#phasedrecursiveeuclidspacerstructure)

###### RecursiveEuclidSpacer

> [recursive euclid spacer](#recursive-euclid-spacer) as [Spacer](#spacer-1)

###### RecursiveEuclidSpacerStructure

> useful encoding for either [AlignedRecursiveEuclidSpacerStructure](#alignedrecursiveeuclidspacerstructure) or [PhasedRecursiveEuclidSpacerStructure](#phasedrecursiveeuclidspacerstructure)

###### RelativeSpacerPoint

> a real number in the range of [0, 1)

###### Spacer

> defacto encoding for working with [spacer](#spacer)

###### SpacerDensity

> an integer in the range of [0, spacerResolution]

###### SpacerGroupBaseStructure

> encoding for defining the base structure of a [SpacerGroupStructure](#spacergroupstructure)

###### SpacerGroupMemberStructure

> encoding for defining the member structure of a [SpacerGroupStructure](#spacergroupstructure)

###### SpacerGroupStructure

> ergonomic encoding for defining [spacer group](#spacer-group)

###### SpacerInterval

> an integer in the range of [1, spacerResolution]

###### SpacerMap

> [spacer](#spacer) as Array\

###### SpacerOrientation

> an integer in the range of [0, spacerDensity)

###### SpacerPhase

> an integer in the range of (-spacerResolution, spacerResolution)

###### SpacerPoint

> an integer in the range of [0, spacerResolution)

###### SpacerPointWeight

> an integer in the range of [0, ∞)

###### SpacerResolution

> an integer in the range of [1, ∞)

###### SpacerSlot

> a boolean that's either true or false

###### SpacerSlotWeight

> an integer in the range of [0, ∞)

###### SpacerString

> [spacer](#spacer) as a string of 1's and 0's

###### SpacerWeight

> an integer in the range of [0, ∞)

## spacer _(functions)_

###### basicEuclidSpacer

> great for working with euclid spacers where orientation and phase are not needed

```typescript
const basicSpacerA = basicEuclidSpacer(5, 3)
// basicSpacerA === [5, [0, 1, 3]]
```

###### componentSpacers

> great for destructuring a spacer structure into its constituent spacers

```typescript
const componentsA = spacerComponents([5, [3, 1, 0], [2, 0, 0]])
// const componentsA === [
// [5, [3, 1, 0]], // baseSpacerStructure
// [5, [3, 1, 0], [2, 0, 0]]
// ]
```

###### coreEuclidMap

> most important spacer function, but rarely invoked by itself

```typescript
const coreSpacerMapA = coreEuclidMap(5, 3)
// coreSpacerMapA === [true, true, false, true, false]
```

###### coreEuclidSpacer

> great for working with simplified euclid spacers

```typescript
const coreSpacerA = coreEuclidSpacer(8, 4)
// coreSpacerA === [2, [0]]
```

###### euclidSpacer

> great for working with unlayered euclid spacers

```typescript
const spacerA = euclidSpacer(5, 3, 1, 0)
// spacerA === [5, [0, 2, 4]]
```

###### orientatedSpacer

> great for reorienting an aligned spacer after it's been created

```typescript
const spacerA = spacer(5, [3, 1])
const spacerB = orientatedSpacer(spacerA, 1)
// spacerB === [5, [0, 2, 3]]
```

###### phasedSpacer

> great for phasing a spacer after it's been created

```typescript
const spacerA = spacer([5, [3, 1]]),
const spacerB = phasedSpacer(spacerA, 1)
// spacerB === [5, [1, 3, 4]]
```

###### relativeSpacerPoints

> great for normalizing spacers across different resolutions

```typescript
const relativePointsA = relativeSpacerPoints(
spacer([5, [3, 1]])
)
// relativePointsA === [0, 0.4, 0.8]
```

###### spacer

> primary function for working with spacer

```typescript
const spacerA = spacer([5, [3, 1, 0]])
// const spacerA === [5, [0, 2, 4]]
```

###### spacerFullSlotWeights

> great for normalizing a spacer and it's orientations against itself

```typescript
spacerFullSlotWeights(
spacer([5, [3, 0]]),
) // [3, 1, 2, 2, 1]
```

###### spacerGroup

> great for defining a set of related spacers at a desired altitude / scope

```typescript
const groupA = spacerGroup([[5], [3]])
// groupA === [
// [5, [3, 0]],
// [5, [3, 1]],
// [5, [3, 2]]
// ]
```

###### spacerGroupId

> great for logging and working with datasets of spacer groups

```typescript
const groupIdA = spacerGroupId([[5, [3, 1]], [2]])
// groupIdA === "group___5__3_1___2"
```

###### spacerId

> great for logging and working with datasets of spacer structures

```typescript
const idA = spacerId([5, [3, 1, 0]])
// const idA === "phased__5__3_1_0"
```

###### spacerIntervals

> great for making calculations between spacer points

```typescript
const intervalsA = spacerIntervals(
spacer([5, [3, 1]])
)
// intervalsA === [2, 2, 1]
```

###### spacerLineage

> great for getting related spacers at a given altitude / scope / lineageIndex

```typescript
const lineageA = spacerLineage([5, [3, 1], [2, 0]])
// lineageA === [
// [[5], [3, 2]], // high-altitude or zoomed-out
// [[5, [3, 1]], [2]] // low-altitude or zoomed-in
// ]
```

###### spacerPointWeights

> great for working with a spacer's points in the context of a set of spacers

```typescript
const pointWeightsA = spacerPointWeights(
spacerSlotWeights([
spacer([5, [3, 0]]),
spacer([5, [3, 1]]),
spacer([5, [3, 2]])
]),
spacer([5, [3, 2]])
)
// const pointWeightsA === [3, 2, 2]
```

###### spacerSlotWeights

> great for understanding point distribution across a set of spacers

```typescript
const slotWeightsA = spacerSlotWeights([
spacer([5, [3, 0]]),
spacer([5, [3, 1]]),
spacer([5, [3, 2]])
])
// slotWeightsA === [3, 1, 2, 2, 1]
```

###### spacerString

> great for logging and visualizing short spacers

```typescript
const stringA = spacerString(
spacer([5, [3, 1]])
)
// stringA === "10101"
```

###### spacerWeight

> great for differentiating a spacer against a set of spacers

```typescript
const weightA = spacerWeight(
spacerSlotWeights([
spacer([5, [3, 0]]),
spacer([5, [3, 1]]),
spacer([5, [3, 2]])
]),
spacer([5, [3, 2]])
)
// const weightA === 7
```

## prime _(concepts)_

###### prime

> a natural number greater than one whose factors are one and itself

```typescript
const prime = 5 // 5 * 1
const notPrime = 4 // 2 * 2, 4 * 1
```

###### prime container

> a natural number where both it's immediate neighbors are prime

```typescript
const containerA = 6 // 5 & 7
const containerB = 12 // 11 & 13
```

###### prime tribe

> the set of primes bounded by adjacent prime containers

## prime _(functions)_

###### isPrime

> use for checking if some number is prime

```typescript
isPrime(4) // false
isPrime(5) // true
```

###### isPrimeContainer

> use for checking if some number is a prime container

```typescript
isPrimeContainer(4) // true
isPrimeContainer(5) // false
```

###### nearestPrimes

> great for rounding some number to nearest prime

```typescript
nearestPrimes(1) // [null, 2]
nearestPrimes(3) // [3, 3]
nearestPrimes(8) // [7, 11]
```

###### prime

> use for getting prime by index

```typescript
prime(0) // 2
prime(1) // 3
prime(2) // 5
```

###### primeContainer

> great for organizing primes and who knows what else

```typescript
primeContainer(0) // 4
primeContainer(1) // 6
primeContainer(2) // 12
```

###### primeContainerSequence

> use for working with the first n prime containers

```typescript
primeContainerSequence(2) // [4, 6, 12]
```

###### primeSequence

> use for working with the first n primes

```typescript
primeSeqeunce(2) // [2, 3, 5]
```

###### primeSequenceInclusive

> use for getting all primes less than some number

```typescript
primeSequenceInclusive(6) // [2, 3, 5]
```

###### primeSequenceInRange

> great for working with primes between containers

```typescript
primeSequenceInRange(12, 18) // [13, 17]
```

###### primeTribe

> great for working with primes that share bounds and analyzing prime distribution

```typescript
primeTribe(0) // [5]
primeTribe(1) // [7, 11]
primeTribe(2) // [13, 17]
```

###### tribeSpacer

> great for analyzing the layout of a prime tribe

```typescript
tribeSpacer(2) // [6, [0, 4]]
tribeSpacer(3) // [12, [0, 4, 10]]
tribeSpacer(4) // [12, [0, 6, 10]]
```

## prime _(encodings)_

###### Prime

> [prime](#prime) as number

###### PrimeContainer

> [prime container](#prime-container) as number

## loop _(functions)_

###### loopCosine

> great for generating cosine waves of a loop

###### loopPendulum

> great for generating pendulum waves of a loop

###### loopPoint

> great for rendering geometry and synthesizing waves

###### loopSine

> great for generating sine waves of a loop