mathfuse 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -29
- package/README.md +267 -239
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
All notable changes to mathfuse will be documented
|
|
3
|
+
All notable changes to **mathfuse** will be documented here.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
---
|
|
7
6
|
|
|
8
|
-
## [
|
|
9
|
-
|
|
10
|
-
### Added
|
|
7
|
+
## [Unreleased]
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- `skewness`, `kurtosis`
|
|
17
|
-
- `pearsonCorrelation`, `spearmanCorrelation`, `covariance`
|
|
18
|
-
- `zScore`, `minMaxNormalize`
|
|
19
|
-
- `linearRegression` with R², slope, intercept, and predict function
|
|
9
|
+
### Planned
|
|
10
|
+
- Matrix operations
|
|
11
|
+
- Complex number support
|
|
12
|
+
- Symbolic differentiation
|
|
20
13
|
|
|
21
|
-
|
|
22
|
-
- Vector: `vadd`, `vsub`, `vscale`, `vdot`, `vnorm`, `vnormalize`, `vdistance`, `cosineSimilarity`, `cross3d`, `vhadamard`
|
|
23
|
-
- Matrix: `mzeros`, `midentity`, `mtranspose`, `madd`, `mscale`, `mmul`, `mvmul`, `mdet`, `minverse`, `mtrace`, `mrank`, `msolve`
|
|
14
|
+
---
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
- Primes: `isPrime` (Miller-Rabin), `primesUpTo` (sieve), `nextPrime`, `primeFactors`
|
|
27
|
-
- GCD/LCM: `gcd`, `gcdMany`, `lcm`, `lcmMany`
|
|
28
|
-
- Combinatorics: `factorial`, `binomial`, `permutations`
|
|
29
|
-
- Modular: `modPow`, `eulerTotient`
|
|
30
|
-
- Sequences: `fibonacci`, `nthFibonacci` (fast doubling), `collatz`, `digitalRoot`
|
|
16
|
+
## [1.0.0] - 2026-03-30
|
|
31
17
|
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
18
|
+
### Added
|
|
19
|
+
- Initial release
|
|
20
|
+
- Statistics module
|
|
21
|
+
- Algebra module
|
|
22
|
+
- Number theory module
|
|
23
|
+
- Numerical methods
|
|
24
|
+
- 124 tests, ESM + CJS dual build
|
|
25
|
+
- Zero dependencies
|
package/README.md
CHANGED
|
@@ -1,239 +1,267 @@
|
|
|
1
|
-
# mathfuse
|
|
2
|
-
|
|
3
|
-
[](https://github.com/Avinashvelu03/mathfuse/actions)
|
|
4
|
-
[](https://www.npmjs.com/package/mathfuse)
|
|
5
|
-
[](https://www.npmjs.com/package/mathfuse)
|
|
6
|
-
[](https://codecov.io/gh/Avinashvelu03/mathfuse)
|
|
7
|
-
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
[](https://bundlephobia.com/package/mathfuse)
|
|
9
|
-
[](https://www.typescriptlang.org/)
|
|
10
|
-
|
|
11
|
-
**A modern, zero-dependency TypeScript math utility library.**
|
|
12
|
-
Tree-shakeable · ESM + CJS · Browser & Node.js · Fully typed
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Features
|
|
17
|
-
|
|
18
|
-
| Module | What's included |
|
|
19
|
-
|--------|----------------|
|
|
20
|
-
| **`stats`** | Mean, median, mode, std dev, variance, percentiles, IQR, MAD, skewness, kurtosis, Pearson/Spearman correlation, covariance, z-score, min-max normalization, linear regression |
|
|
21
|
-
| **`algebra`** | Vector ops (add, dot, norm, normalize, cosine similarity, cross product), matrix ops (multiply, determinant, inverse, rank, transpose, solve) |
|
|
22
|
-
| **`number-theory`** | Miller-Rabin primality, Sieve of Eratosthenes, GCD/LCM, factorial, binomial, permutations, modular exponentiation, Euler's totient, Fibonacci, Collatz |
|
|
23
|
-
| **`numerical`** | Bisection, Newton-Raphson, Brent's method, numerical derivative/gradient, adaptive Simpson integration, Gauss-Legendre quadrature, Lagrange interpolation, Kahan summation |
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Install
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm install mathfuse
|
|
31
|
-
# or
|
|
32
|
-
yarn add mathfuse
|
|
33
|
-
# or
|
|
34
|
-
pnpm add mathfuse
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## Quick Start
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
import { mean, stdDev, linearRegression } from 'mathfuse';
|
|
43
|
-
// or tree-shake specific modules:
|
|
44
|
-
import { mean, stdDev } from 'mathfuse/stats';
|
|
45
|
-
import { isPrime, fibonacci } from 'mathfuse/number-theory';
|
|
46
|
-
import { newtonRaphson, integrate } from 'mathfuse/numerical';
|
|
47
|
-
import { mmul, mdet, msolve } from 'mathfuse/algebra';
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
## API Reference
|
|
53
|
-
|
|
54
|
-
### 📊 Statistics (`mathfuse/stats`)
|
|
55
|
-
|
|
56
|
-
#### Central Tendency
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { mean, median, mode, geometricMean, harmonicMean, weightedMean } from 'mathfuse/stats';
|
|
60
|
-
|
|
61
|
-
mean([1, 2, 3, 4, 5]) // 3
|
|
62
|
-
median([3, 1, 4, 1, 5]) // 3
|
|
63
|
-
mode([1, 2, 2, 3, 3]) // [2, 3]
|
|
64
|
-
geometricMean([1, 2, 4, 8]) // 2.828...
|
|
65
|
-
harmonicMean([1, 2, 4]) // 1.714...
|
|
66
|
-
weightedMean([1, 2, 3], [1, 2, 3]) // 2.333...
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
#### Spread & Dispersion
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
import { variance, stdDev, range, iqr, mad } from 'mathfuse/stats';
|
|
73
|
-
|
|
74
|
-
variance([2, 4, 4, 4, 5, 5, 7, 9]) // 4.571 (sample)
|
|
75
|
-
variance([2, 4, 4, 4, 5, 5, 7, 9], true) // 4.0 (population)
|
|
76
|
-
stdDev([2, 4, 4, 4, 5, 5, 7, 9], true) // 2.0
|
|
77
|
-
iqr([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) // 4.5
|
|
78
|
-
mad([1, 1, 2, 2, 4, 6, 9]) // 1.0
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
#### Percentiles
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
import { percentile, fiveNumberSummary } from 'mathfuse/stats';
|
|
85
|
-
|
|
86
|
-
percentile([1,2,3,4,5,6,7,8,9,10], 90) // 9.1
|
|
87
|
-
fiveNumberSummary([1,2,3,4,5]) // [1, 1.5, 3, 4.5, 5]
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
#### Correlation & Regression
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
import { pearsonCorrelation, spearmanCorrelation, linearRegression } from 'mathfuse/stats';
|
|
94
|
-
|
|
95
|
-
const x = [1, 2, 3, 4, 5];
|
|
96
|
-
const y = [2, 4, 5, 4, 5];
|
|
97
|
-
|
|
98
|
-
pearsonCorrelation(x, y) // 0.8320...
|
|
99
|
-
spearmanCorrelation(x, y) // 0.8207...
|
|
100
|
-
|
|
101
|
-
const reg = linearRegression(x, y);
|
|
102
|
-
reg.slope // 0.7
|
|
103
|
-
reg.intercept // 1.7
|
|
104
|
-
reg.r2 // 0.6923
|
|
105
|
-
reg.predict(6) // 5.9
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
#### Normalization
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
import { zScore, minMaxNormalize } from 'mathfuse/stats';
|
|
112
|
-
|
|
113
|
-
zScore([1, 2, 3, 4, 5]) // [-1.41, -0.71, 0, 0.71, 1.41]
|
|
114
|
-
minMaxNormalize([1, 2, 3, 4, 5]) // [0, 0.25, 0.5, 0.75, 1]
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
### 🔢 Number Theory (`mathfuse/number-theory`)
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
import { isPrime, primesUpTo, nextPrime, primeFactors } from 'mathfuse/number-theory';
|
|
123
|
-
|
|
124
|
-
isPrime(999_983) // true (Miller-Rabin)
|
|
125
|
-
primesUpTo(20) // [2, 3, 5, 7, 11, 13, 17, 19]
|
|
126
|
-
nextPrime(100) // 101
|
|
127
|
-
primeFactors(360) // [2, 2, 2, 3, 3, 5]
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
import { gcd, lcm, factorial, binomial, fibonacci } from 'mathfuse/number-theory';
|
|
132
|
-
|
|
133
|
-
gcd(48, 18) // 6
|
|
134
|
-
lcm(4, 6) // 12
|
|
135
|
-
factorial(10) // 3_628_800
|
|
136
|
-
binomial(10, 3) // 120
|
|
137
|
-
fibonacci(8) // [0, 1, 1, 2, 3, 5, 8, 13]
|
|
138
|
-
nthFibonacci(50) // 12586269025
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
### 🧮 Linear Algebra (`mathfuse/algebra`)
|
|
144
|
-
|
|
145
|
-
#### Vectors
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
import { vadd, vdot, vnorm, cosineSimilarity, cross3d } from 'mathfuse/algebra';
|
|
149
|
-
|
|
150
|
-
vadd([1,2,3], [4,5,6]) // [5, 7, 9]
|
|
151
|
-
vdot([1,2,3], [4,5,6]) // 32
|
|
152
|
-
vnorm([3, 4]) // 5
|
|
153
|
-
cosineSimilarity([1,0], [1,1]) // 0.7071...
|
|
154
|
-
cross3d([1,0,0], [0,1,0]) // [0, 0, 1]
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
#### Matrices
|
|
158
|
-
|
|
159
|
-
```typescript
|
|
160
|
-
import { mmul, mdet, minverse, msolve } from 'mathfuse/algebra';
|
|
161
|
-
|
|
162
|
-
const A = [[2,1], [-1,3]];
|
|
163
|
-
mdet(A) // 7
|
|
164
|
-
minverse(A) // [[0.428, -0.142], [0.142, 0.285]]
|
|
165
|
-
msolve(A, [5,0]) // [3, 1] (solves Ax = b)
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
---
|
|
169
|
-
|
|
170
|
-
### 📐 Numerical Methods (`mathfuse/numerical`)
|
|
171
|
-
|
|
172
|
-
#### Root Finding
|
|
173
|
-
|
|
174
|
-
```typescript
|
|
175
|
-
import { bisection, newtonRaphson, brent } from 'mathfuse/numerical';
|
|
176
|
-
|
|
177
|
-
const f = (x: number) => x ** 2 - 2; // root at √2
|
|
178
|
-
|
|
179
|
-
bisection(f, 1, 2).root // 1.4142135623...
|
|
180
|
-
newtonRaphson(f, 1.5).root // 1.4142135623...
|
|
181
|
-
brent(f, 1, 2).root // 1.4142135623...
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
#### Calculus
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
import { derivative, integrate } from 'mathfuse/numerical';
|
|
188
|
-
|
|
189
|
-
derivative(Math.sin, Math.PI / 4) // ≈ cos(π/4) ≈ 0.7071
|
|
190
|
-
integrate(Math.sin, 0, Math.PI) // ≈ 2.0 (exact: 2)
|
|
191
|
-
integrate(x => x ** 2, 0, 1) // ≈ 0.333 (exact: 1/3)
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
#### Interpolation
|
|
195
|
-
|
|
196
|
-
```typescript
|
|
197
|
-
import { lerp, tableInterpolate, lagrange } from 'mathfuse/numerical';
|
|
198
|
-
|
|
199
|
-
lerp(0, 100, 0.3) // 30
|
|
200
|
-
tableInterpolate([0,1,2,3], [0,1,4,9], 1.5) // 2.5
|
|
201
|
-
lagrange([0, 1, 2], [0, 1, 4], 1.5) // 2.25
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
---
|
|
205
|
-
|
|
206
|
-
## Tree Shaking
|
|
207
|
-
|
|
208
|
-
mathfuse is fully tree-shakeable. Import only what you need:
|
|
209
|
-
|
|
210
|
-
```typescript
|
|
211
|
-
// ✅ Only the functions you import will be bundled
|
|
212
|
-
import { mean, stdDev } from 'mathfuse/stats';
|
|
213
|
-
import { isPrime } from 'mathfuse/number-theory';
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
## Browser Support
|
|
219
|
-
|
|
220
|
-
mathfuse targets ES2020 and works in all modern browsers and Node.js ≥ 16.
|
|
221
|
-
|
|
222
|
-
---
|
|
223
|
-
|
|
224
|
-
## Contributing
|
|
225
|
-
|
|
226
|
-
Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) and open an issue before submitting a PR for large changes.
|
|
227
|
-
|
|
228
|
-
```bash
|
|
229
|
-
git clone https://github.com/Avinashvelu03/mathfuse.git
|
|
230
|
-
cd mathfuse
|
|
231
|
-
npm install
|
|
232
|
-
npm test
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
---
|
|
236
|
-
|
|
237
|
-
## License
|
|
238
|
-
|
|
239
|
-
[MIT](LICENSE) © Scientist Maths
|
|
1
|
+
# mathfuse
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Avinashvelu03/mathfuse/actions)
|
|
4
|
+
[](https://www.npmjs.com/package/mathfuse)
|
|
5
|
+
[](https://www.npmjs.com/package/mathfuse)
|
|
6
|
+
[](https://codecov.io/gh/Avinashvelu03/mathfuse)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://bundlephobia.com/package/mathfuse)
|
|
9
|
+
[](https://www.typescriptlang.org/)
|
|
10
|
+
|
|
11
|
+
**A modern, zero-dependency TypeScript math utility library.**
|
|
12
|
+
Tree-shakeable · ESM + CJS · Browser & Node.js · Fully typed
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
| Module | What's included |
|
|
19
|
+
|--------|----------------|
|
|
20
|
+
| **`stats`** | Mean, median, mode, std dev, variance, percentiles, IQR, MAD, skewness, kurtosis, Pearson/Spearman correlation, covariance, z-score, min-max normalization, linear regression |
|
|
21
|
+
| **`algebra`** | Vector ops (add, dot, norm, normalize, cosine similarity, cross product), matrix ops (multiply, determinant, inverse, rank, transpose, solve) |
|
|
22
|
+
| **`number-theory`** | Miller-Rabin primality, Sieve of Eratosthenes, GCD/LCM, factorial, binomial, permutations, modular exponentiation, Euler's totient, Fibonacci, Collatz |
|
|
23
|
+
| **`numerical`** | Bisection, Newton-Raphson, Brent's method, numerical derivative/gradient, adaptive Simpson integration, Gauss-Legendre quadrature, Lagrange interpolation, Kahan summation |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install mathfuse
|
|
31
|
+
# or
|
|
32
|
+
yarn add mathfuse
|
|
33
|
+
# or
|
|
34
|
+
pnpm add mathfuse
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { mean, stdDev, linearRegression } from 'mathfuse';
|
|
43
|
+
// or tree-shake specific modules:
|
|
44
|
+
import { mean, stdDev } from 'mathfuse/stats';
|
|
45
|
+
import { isPrime, fibonacci } from 'mathfuse/number-theory';
|
|
46
|
+
import { newtonRaphson, integrate } from 'mathfuse/numerical';
|
|
47
|
+
import { mmul, mdet, msolve } from 'mathfuse/algebra';
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## API Reference
|
|
53
|
+
|
|
54
|
+
### 📊 Statistics (`mathfuse/stats`)
|
|
55
|
+
|
|
56
|
+
#### Central Tendency
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { mean, median, mode, geometricMean, harmonicMean, weightedMean } from 'mathfuse/stats';
|
|
60
|
+
|
|
61
|
+
mean([1, 2, 3, 4, 5]) // 3
|
|
62
|
+
median([3, 1, 4, 1, 5]) // 3
|
|
63
|
+
mode([1, 2, 2, 3, 3]) // [2, 3]
|
|
64
|
+
geometricMean([1, 2, 4, 8]) // 2.828...
|
|
65
|
+
harmonicMean([1, 2, 4]) // 1.714...
|
|
66
|
+
weightedMean([1, 2, 3], [1, 2, 3]) // 2.333...
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Spread & Dispersion
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { variance, stdDev, range, iqr, mad } from 'mathfuse/stats';
|
|
73
|
+
|
|
74
|
+
variance([2, 4, 4, 4, 5, 5, 7, 9]) // 4.571 (sample)
|
|
75
|
+
variance([2, 4, 4, 4, 5, 5, 7, 9], true) // 4.0 (population)
|
|
76
|
+
stdDev([2, 4, 4, 4, 5, 5, 7, 9], true) // 2.0
|
|
77
|
+
iqr([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) // 4.5
|
|
78
|
+
mad([1, 1, 2, 2, 4, 6, 9]) // 1.0
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### Percentiles
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { percentile, fiveNumberSummary } from 'mathfuse/stats';
|
|
85
|
+
|
|
86
|
+
percentile([1,2,3,4,5,6,7,8,9,10], 90) // 9.1
|
|
87
|
+
fiveNumberSummary([1,2,3,4,5]) // [1, 1.5, 3, 4.5, 5]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Correlation & Regression
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { pearsonCorrelation, spearmanCorrelation, linearRegression } from 'mathfuse/stats';
|
|
94
|
+
|
|
95
|
+
const x = [1, 2, 3, 4, 5];
|
|
96
|
+
const y = [2, 4, 5, 4, 5];
|
|
97
|
+
|
|
98
|
+
pearsonCorrelation(x, y) // 0.8320...
|
|
99
|
+
spearmanCorrelation(x, y) // 0.8207...
|
|
100
|
+
|
|
101
|
+
const reg = linearRegression(x, y);
|
|
102
|
+
reg.slope // 0.7
|
|
103
|
+
reg.intercept // 1.7
|
|
104
|
+
reg.r2 // 0.6923
|
|
105
|
+
reg.predict(6) // 5.9
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Normalization
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { zScore, minMaxNormalize } from 'mathfuse/stats';
|
|
112
|
+
|
|
113
|
+
zScore([1, 2, 3, 4, 5]) // [-1.41, -0.71, 0, 0.71, 1.41]
|
|
114
|
+
minMaxNormalize([1, 2, 3, 4, 5]) // [0, 0.25, 0.5, 0.75, 1]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### 🔢 Number Theory (`mathfuse/number-theory`)
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { isPrime, primesUpTo, nextPrime, primeFactors } from 'mathfuse/number-theory';
|
|
123
|
+
|
|
124
|
+
isPrime(999_983) // true (Miller-Rabin)
|
|
125
|
+
primesUpTo(20) // [2, 3, 5, 7, 11, 13, 17, 19]
|
|
126
|
+
nextPrime(100) // 101
|
|
127
|
+
primeFactors(360) // [2, 2, 2, 3, 3, 5]
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { gcd, lcm, factorial, binomial, fibonacci } from 'mathfuse/number-theory';
|
|
132
|
+
|
|
133
|
+
gcd(48, 18) // 6
|
|
134
|
+
lcm(4, 6) // 12
|
|
135
|
+
factorial(10) // 3_628_800
|
|
136
|
+
binomial(10, 3) // 120
|
|
137
|
+
fibonacci(8) // [0, 1, 1, 2, 3, 5, 8, 13]
|
|
138
|
+
nthFibonacci(50) // 12586269025
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### 🧮 Linear Algebra (`mathfuse/algebra`)
|
|
144
|
+
|
|
145
|
+
#### Vectors
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
import { vadd, vdot, vnorm, cosineSimilarity, cross3d } from 'mathfuse/algebra';
|
|
149
|
+
|
|
150
|
+
vadd([1,2,3], [4,5,6]) // [5, 7, 9]
|
|
151
|
+
vdot([1,2,3], [4,5,6]) // 32
|
|
152
|
+
vnorm([3, 4]) // 5
|
|
153
|
+
cosineSimilarity([1,0], [1,1]) // 0.7071...
|
|
154
|
+
cross3d([1,0,0], [0,1,0]) // [0, 0, 1]
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### Matrices
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { mmul, mdet, minverse, msolve } from 'mathfuse/algebra';
|
|
161
|
+
|
|
162
|
+
const A = [[2,1], [-1,3]];
|
|
163
|
+
mdet(A) // 7
|
|
164
|
+
minverse(A) // [[0.428, -0.142], [0.142, 0.285]]
|
|
165
|
+
msolve(A, [5,0]) // [3, 1] (solves Ax = b)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
### 📐 Numerical Methods (`mathfuse/numerical`)
|
|
171
|
+
|
|
172
|
+
#### Root Finding
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { bisection, newtonRaphson, brent } from 'mathfuse/numerical';
|
|
176
|
+
|
|
177
|
+
const f = (x: number) => x ** 2 - 2; // root at √2
|
|
178
|
+
|
|
179
|
+
bisection(f, 1, 2).root // 1.4142135623...
|
|
180
|
+
newtonRaphson(f, 1.5).root // 1.4142135623...
|
|
181
|
+
brent(f, 1, 2).root // 1.4142135623...
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Calculus
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { derivative, integrate } from 'mathfuse/numerical';
|
|
188
|
+
|
|
189
|
+
derivative(Math.sin, Math.PI / 4) // ≈ cos(π/4) ≈ 0.7071
|
|
190
|
+
integrate(Math.sin, 0, Math.PI) // ≈ 2.0 (exact: 2)
|
|
191
|
+
integrate(x => x ** 2, 0, 1) // ≈ 0.333 (exact: 1/3)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### Interpolation
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { lerp, tableInterpolate, lagrange } from 'mathfuse/numerical';
|
|
198
|
+
|
|
199
|
+
lerp(0, 100, 0.3) // 30
|
|
200
|
+
tableInterpolate([0,1,2,3], [0,1,4,9], 1.5) // 2.5
|
|
201
|
+
lagrange([0, 1, 2], [0, 1, 4], 1.5) // 2.25
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Tree Shaking
|
|
207
|
+
|
|
208
|
+
mathfuse is fully tree-shakeable. Import only what you need:
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
// ✅ Only the functions you import will be bundled
|
|
212
|
+
import { mean, stdDev } from 'mathfuse/stats';
|
|
213
|
+
import { isPrime } from 'mathfuse/number-theory';
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Browser Support
|
|
219
|
+
|
|
220
|
+
mathfuse targets ES2020 and works in all modern browsers and Node.js ≥ 16.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Contributing
|
|
225
|
+
|
|
226
|
+
Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) and open an issue before submitting a PR for large changes.
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
git clone https://github.com/Avinashvelu03/mathfuse.git
|
|
230
|
+
cd mathfuse
|
|
231
|
+
npm install
|
|
232
|
+
npm test
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
[MIT](LICENSE) © Scientist Maths
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## ➕ Back MathFuse
|
|
244
|
+
|
|
245
|
+
MathFuse is a one-person project — no VC funding, no corporate backing. Just clean math primitives built for TypeScript developers.
|
|
246
|
+
|
|
247
|
+
If it's saved you from writing `sum` or `mean` for the hundredth time, or handled edge cases you never thought of:
|
|
248
|
+
|
|
249
|
+
<div align="center">
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
┌─────────────────────────────────────────────────────┐
|
|
253
|
+
│ Open source math deserves open source support. │
|
|
254
|
+
│ │
|
|
255
|
+
│ ☕ Ko-fi · GitHub Sponsors │
|
|
256
|
+
└─────────────────────────────────────────────────────┘
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
[](https://ko-fi.com/avinashvelu)
|
|
260
|
+
[](https://github.com/sponsors/Avinashvelu03)
|
|
261
|
+
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
**Zero cost, high impact:**
|
|
265
|
+
- ⭐ [Drop a star](https://github.com/Avinashvelu03/mathfuse) — it's free and it helps more than you think
|
|
266
|
+
- 📣 Mention MathFuse in your next tech post or talk
|
|
267
|
+
- 🛠️ [Open an issue](https://github.com/Avinashvelu03/mathfuse/issues) with missing math functions you need
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mathfuse",
|
|
3
|
-
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A modern, zero-dependency TypeScript math utility library — statistics, linear algebra, number theory & numerical methods.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"math", "mathematics", "statistics", "linear-algebra", "matrix",
|