@danielsimonjr/mathts-core 0.18.1 → 0.19.0

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/dist/index.js CHANGED
@@ -1,1598 +1,1308 @@
1
- import {
2
- BIGNUMBER_E,
3
- BIGNUMBER_LN10,
4
- BIGNUMBER_LN2,
5
- BIGNUMBER_NEG_ONE,
6
- BIGNUMBER_ONE,
7
- BIGNUMBER_PI,
8
- BIGNUMBER_TEN,
9
- BIGNUMBER_ZERO,
10
- BigNumber,
11
- COMPLEX_NEG_ONE,
12
- COMPLEX_ONE,
13
- COMPLEX_ZERO,
14
- Complex,
15
- DimensionMismatchError,
16
- FRACTION_HALF,
17
- FRACTION_NEG_ONE,
18
- FRACTION_ONE,
19
- FRACTION_QUARTER,
20
- FRACTION_THIRD,
21
- FRACTION_ZERO,
22
- Fraction,
23
- I,
24
- LN2_EXACT_SCALE,
25
- NAMED_IRRATIONALS,
26
- NAMED_SCALES,
27
- PI_EXACT_SCALE,
28
- UNIT_EXACT_SCALE,
29
- UNIT_PREFIX_SETS,
30
- UNIT_ROWS,
31
- UNIT_ROW_ALIASES,
32
- Unit,
33
- UnitParseError,
34
- abs,
35
- addExactScales,
36
- addScalar,
37
- binaryExactScale,
38
- clearExactScaleNumberCache,
39
- decimalExactScale,
40
- divideExactScales,
41
- divideScalar,
42
- equal,
43
- exactScaleNumberCacheSize,
44
- exactScaleOf,
45
- exactScaleToNumber,
46
- exactScalesEqual,
47
- factory,
48
- fix,
49
- format,
50
- formatExactScale,
51
- getUnitPrefix,
52
- getUnitRow,
53
- irrationalPower,
54
- isBigInt,
55
- isBigNumber,
56
- isBigNumber2,
57
- isComplex2 as isComplex,
58
- isFraction2 as isFraction,
59
- isNumeric,
60
- isRationalScale,
61
- isUnit,
62
- multiplyExactScales,
63
- multiplyScalar,
64
- namedExactScale,
65
- namedIrrationalScale,
66
- nearlyEqual,
67
- number,
68
- pow,
69
- powerExactScale,
70
- ratioExactScale,
71
- readScaleExpression,
72
- readUnitScale,
73
- round,
74
- sign,
75
- subtractScalar,
76
- unitPrefixExactScale,
77
- unitRowExactOffset,
78
- unitRowExactScale,
79
- unitRowValue
80
- } from "./chunk-36FOYJAP.js";
81
-
82
- // src/types/matrix/Range.ts
83
- var name = "Range";
84
- var dependencies = [];
85
- var createRangeClass = /* @__PURE__ */ factory(
86
- name,
87
- dependencies,
88
- () => {
89
- class Range2 {
90
- /**
91
- * Type identifier
92
- */
93
- type = "Range";
94
- /**
95
- * Range type flag
96
- */
97
- isRange = true;
98
- /**
99
- * Start value of the range (inclusive)
100
- */
101
- start;
102
- /**
103
- * End value of the range (exclusive)
104
- */
105
- end;
106
- /**
107
- * Step size for the range
108
- */
109
- step;
110
- /**
111
- * Cached primitive array representation.
112
- *
113
- * @internal Not part of the public API.
114
- *
115
- * These four were ES-private (`#cache`) until TypeScript 7. This class is
116
- * returned from a `factory()` call, so declaration emit describes it as an
117
- * ANONYMOUS class type -- and TS4094 forbids private or protected members
118
- * there, because an anonymous type has no name to refer them to. The
119
- * underscore prefix keeps the "do not touch" signal without the emit
120
- * failure. Restore `#` if the class is ever hoisted out of the factory.
121
- */
122
- _cache = null;
123
- _cacheStart;
124
- _cacheEnd;
125
- _cacheStep;
126
- /**
127
- * Create a range from start to end with a step.
128
- *
129
- * @param start - Included lower bound. Default is 0.
130
- * @param end - Excluded upper bound. Default is 0.
131
- * @param step - Optional step size. Default is 1.
132
- * @throws TypeError when start, end or step is not a number, bigint or BigNumber.
133
- * @throws Error when step is zero.
134
- */
135
- constructor(start, end, step) {
136
- if (!(this instanceof Range2)) {
137
- throw new SyntaxError("Constructor must be called with the new operator");
138
- }
139
- const hasStart = start !== null && start !== void 0;
140
- const hasEnd = end !== null && end !== void 0;
141
- const hasStep = step !== null && step !== void 0;
142
- let startValue = 0;
143
- let endValue = 0;
144
- let stepValue = 1;
145
- if (hasStart) {
146
- if (isBigNumber(start)) {
147
- startValue = start.toNumber();
148
- } else if (typeof start !== "number" && !isBigInt(start)) {
149
- throw new TypeError("Parameter start must be a number or bigint");
150
- } else {
151
- startValue = start;
152
- }
153
- }
154
- if (hasEnd) {
155
- if (isBigNumber(end)) {
156
- endValue = end.toNumber();
157
- } else if (typeof end !== "number" && !isBigInt(end)) {
158
- throw new TypeError("Parameter end must be a number or bigint");
159
- } else {
160
- endValue = end;
161
- }
162
- }
163
- if (hasStep) {
164
- if (isBigNumber(step)) {
165
- stepValue = step.toNumber();
166
- } else if (typeof step !== "number" && !isBigInt(step)) {
167
- throw new TypeError("Parameter step must be a number or bigint");
168
- } else {
169
- stepValue = step;
170
- }
171
- }
172
- this.start = hasStart ? parseFloat(startValue.toString()) : 0;
173
- this.end = hasEnd ? parseFloat(endValue.toString()) : 0;
174
- this.step = hasStep ? parseFloat(stepValue.toString()) : 1;
175
- if (hasStep && nearlyEqual(this.step, 0)) {
176
- throw new Error("Step must not be zero");
177
- }
178
- }
179
- /**
180
- * Parse a string into a range,
181
- * The string contains the start, optional step, and end, separated by a colon.
182
- * If the string does not contain a valid range, null is returned.
183
- * For example str='0:2:11'.
184
- * @memberof Range
185
- * @param str
186
- * @return range
187
- */
188
- static parse(str) {
189
- if (typeof str !== "string") {
190
- return null;
191
- }
192
- const args = str.split(":");
193
- const nums = args.map(function(arg) {
194
- return parseFloat(arg);
195
- });
196
- const invalid = nums.some(function(num) {
197
- return isNaN(num);
198
- });
199
- if (invalid) {
200
- return null;
201
- }
202
- switch (nums.length) {
203
- case 2:
204
- return new Range2(nums[0], nums[1]);
205
- case 3:
206
- return new Range2(nums[0], nums[2], nums[1]);
207
- default:
208
- return null;
209
- }
210
- }
211
- /**
212
- * Create a clone of the range
213
- * @return clone
214
- */
215
- clone() {
216
- return new Range2(this.start, this.end, this.step);
217
- }
218
- /**
219
- * Retrieve the size of the range.
220
- * Returns an array containing one number, the number of elements in the range.
221
- * @memberof Range
222
- * @returns size
223
- */
224
- size() {
225
- let len = 0;
226
- const start = this.start;
227
- const step = this.step;
228
- const end = this.end;
229
- const diff = end - start;
230
- if (sign(step) === sign(diff)) {
231
- len = Math.ceil(diff / step);
232
- } else if (diff === 0) {
233
- len = 0;
234
- }
235
- if (isNaN(len)) {
236
- len = 0;
237
- }
238
- return [len];
239
- }
240
- /**
241
- * Calculate the minimum value in the range
242
- * @memberof Range
243
- * @return min
244
- */
245
- min() {
246
- const size = this.size()[0];
247
- if (size > 0) {
248
- if (this.step > 0) {
249
- return this.start;
250
- } else {
251
- return this.start + (size - 1) * this.step;
252
- }
253
- } else {
254
- return void 0;
255
- }
256
- }
257
- /**
258
- * Calculate the maximum value in the range
259
- * @memberof Range
260
- * @return max
261
- */
262
- max() {
263
- const size = this.size()[0];
264
- if (size > 0) {
265
- if (this.step > 0) {
266
- return this.start + (size - 1) * this.step;
267
- } else {
268
- return this.start;
269
- }
270
- } else {
271
- return void 0;
272
- }
273
- }
274
- /**
275
- * Execute a callback function for each value in the range.
276
- * @memberof Range
277
- * @param callback - The callback method is invoked with three
278
- * parameters: the value of the element, the index
279
- * of the element, and the Range being traversed.
280
- */
281
- forEach(callback) {
282
- let x = this.start;
283
- const step = this.step;
284
- const end = this.end;
285
- let i = 0;
286
- if (step > 0) {
287
- while (x < end) {
288
- callback(x, [i], this);
289
- x += step;
290
- i++;
291
- }
292
- } else if (step < 0) {
293
- while (x > end) {
294
- callback(x, [i], this);
295
- x += step;
296
- i++;
297
- }
298
- }
299
- }
300
- /**
301
- * Execute a callback function for each value in the Range, and return the
302
- * results as an array
303
- * @memberof Range
304
- * @param callback - The callback method is invoked with three
305
- * parameters: the value of the element, the index
306
- * of the element, and the Matrix being traversed.
307
- * @returns array
308
- */
309
- map(callback) {
310
- const array = [];
311
- this.forEach((value, index) => {
312
- array[index[0]] = callback(value, index, this);
313
- });
314
- return array;
315
- }
316
- /**
317
- * Create an Array with a copy of the Ranges data
318
- * @memberof Range
319
- * @returns array
320
- */
321
- toArray() {
322
- const array = [];
323
- this.forEach(function(value, index) {
324
- array[index[0]] = value;
325
- });
326
- return array;
327
- }
328
- /**
329
- * Get the primitive value of the Range, a one dimensional array
330
- * @memberof Range
331
- * @returns array
332
- */
333
- valueOf() {
334
- if (this._cache !== null && this.start === this._cacheStart && this.end === this._cacheEnd && this.step === this._cacheStep) {
335
- return this._cache;
336
- }
337
- this._cache = this.toArray();
338
- this._cacheStart = this.start;
339
- this._cacheEnd = this.end;
340
- this._cacheStep = this.step;
341
- return this._cache;
342
- }
343
- /**
344
- * Get a string representation of the range, with optional formatting options.
345
- * Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
346
- * @memberof Range
347
- * @param options - Optional. Formatting options. See
348
- * lib/utils/number:format for a
349
- * description of the available
350
- * options.
351
- * @returns str
352
- */
353
- format(options) {
354
- let str = format(this.start, options);
355
- if (this.step !== 1) {
356
- str += ":" + format(this.step, options);
357
- }
358
- str += ":" + format(this.end, options);
359
- return str;
360
- }
361
- /**
362
- * Get a string representation of the range.
363
- * @memberof Range
364
- * @returns
365
- */
366
- toString() {
367
- return this.format();
368
- }
369
- /**
370
- * Get a JSON representation of the range
371
- * @memberof Range
372
- * @returns Returns a JSON object structured as:
373
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
374
- */
375
- toJSON() {
376
- return {
377
- mathjs: "Range",
378
- start: this.start,
379
- end: this.end,
380
- step: this.step
381
- };
382
- }
383
- /**
384
- * Instantiate a Range from a JSON object
385
- * @memberof Range
386
- * @param json - A JSON object structured as:
387
- * `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
388
- * @return
389
- */
390
- static fromJSON(json) {
391
- return new Range2(json.start, json.end, json.step);
392
- }
393
- }
394
- return Range2;
395
- },
396
- { isClass: true }
397
- );
398
- var Range = createRangeClass({});
399
-
400
- // src/types/dual-rules.ts
401
- var DUAL_UNARY_RULES = {
402
- exp: { primal: Math.exp, deriv: (_x, y) => y },
403
- expm1: { primal: Math.expm1, deriv: (_x, y) => y + 1 },
404
- log: { primal: Math.log, deriv: (x) => 1 / x },
405
- log2: { primal: Math.log2, deriv: (x) => 1 / (x * Math.LN2) },
406
- log10: { primal: Math.log10, deriv: (x) => 1 / (x * Math.LN10) },
407
- log1p: { primal: Math.log1p, deriv: (x) => 1 / (1 + x) },
408
- sin: { primal: Math.sin, deriv: (x) => Math.cos(x) },
409
- cos: { primal: Math.cos, deriv: (x) => -Math.sin(x) },
410
- tan: { primal: Math.tan, deriv: (x) => 1 / (Math.cos(x) * Math.cos(x)) },
411
- asin: { primal: Math.asin, deriv: (x) => 1 / Math.sqrt(1 - x * x) },
412
- acos: { primal: Math.acos, deriv: (x) => -1 / Math.sqrt(1 - x * x) },
413
- atan: { primal: Math.atan, deriv: (x) => 1 / (1 + x * x) },
414
- sinh: { primal: Math.sinh, deriv: (x) => Math.cosh(x) },
415
- cosh: { primal: Math.cosh, deriv: (x) => Math.sinh(x) },
416
- tanh: { primal: Math.tanh, deriv: (_x, y) => 1 - y * y },
417
- asinh: { primal: Math.asinh, deriv: (x) => 1 / Math.sqrt(x * x + 1) },
418
- acosh: { primal: Math.acosh, deriv: (x) => 1 / Math.sqrt(x * x - 1) },
419
- atanh: { primal: Math.atanh, deriv: (x) => 1 / (1 - x * x) },
420
- sqrt: { primal: Math.sqrt, deriv: (_x, y) => 1 / (2 * y) },
421
- cbrt: { primal: Math.cbrt, deriv: (_x, y) => 1 / (3 * y * y) },
422
- square: { primal: (x) => x * x, deriv: (x) => 2 * x },
423
- reciprocal: { primal: (x) => 1 / x, deriv: (x) => -1 / (x * x) },
424
- abs: { primal: Math.abs, deriv: (x) => Math.sign(x) },
425
- sign: { primal: Math.sign, deriv: () => 0 }
1
+ import { $ as BIGNUMBER_LN2, A as irrationalPower, B as addScalar, Bn as I, C as decimalExactScale, D as exactScaleToNumber, E as exactScaleOf, F as ratioExactScale, G as multiplyScalar, H as equal, I as readScaleExpression, In as COMPLEX_NEG_ONE, J as round, K as number, L as DimensionMismatchError, Ln as COMPLEX_ONE, M as multiplyExactScales, N as namedIrrationalScale, O as exactScalesEqual, P as powerExactScale, Pn as isUnit$1, Q as BIGNUMBER_LN10, R as UnitParseError, Rn as COMPLEX_ZERO, S as clearExactScaleNumberCache, T as exactScaleNumberCacheSize, U as fix, V as divideScalar, Vn as isComplex, W as isNumeric, Y as subtractScalar, Yt as format, Z as BIGNUMBER_E, _ as NAMED_IRRATIONALS, _t as factory, a as UNIT_PREFIX_SETS, an as sign, at as BigNumber, b as addExactScales, c as getUnitPrefix, ct as FRACTION_NEG_ONE, d as readUnitScale, dt as FRACTION_THIRD, et as BIGNUMBER_NEG_ONE, f as unitPrefixExactScale, ft as FRACTION_ZERO, g as LN2_EXACT_SCALE, h as unitRowValue, hn as isBigNumber$2, i as NAMED_SCALES, it as BIGNUMBER_ZERO, j as isRationalScale, k as formatExactScale, l as getUnitRow, lt as FRACTION_ONE, m as unitRowExactScale, mn as isBigInt$1, mt as isFraction, nt as BIGNUMBER_PI, o as UNIT_ROWS, ot as isBigNumber, p as unitRowExactOffset, pt as Fraction, q as pow, rt as BIGNUMBER_TEN, s as UNIT_ROW_ALIASES, st as FRACTION_HALF, t as Unit, tn as nearlyEqual, tt as BIGNUMBER_ONE, u as namedExactScale, ut as FRACTION_QUARTER, v as PI_EXACT_SCALE, w as divideExactScales, x as binaryExactScale, y as UNIT_EXACT_SCALE, z as abs, zn as Complex } from "./unit-l_r8z5Fv.js";
2
+ import typed, { create } from "typed-function";
3
+ const createRangeClass = /* #__PURE__ */ factory("Range", [], () => {
4
+ class Range {
5
+ type = "Range";
6
+ isRange = true;
7
+ start;
8
+ end;
9
+ step;
10
+ _cache = null;
11
+ _cacheStart;
12
+ _cacheEnd;
13
+ _cacheStep;
14
+ constructor(start, end, step) {
15
+ if (!(this instanceof Range)) throw new SyntaxError("Constructor must be called with the new operator");
16
+ const hasStart = start !== null && start !== void 0;
17
+ const hasEnd = end !== null && end !== void 0;
18
+ const hasStep = step !== null && step !== void 0;
19
+ let startValue = 0;
20
+ let endValue = 0;
21
+ let stepValue = 1;
22
+ if (hasStart) {
23
+ if (isBigNumber$2(start)) startValue = start.toNumber();
24
+ else if (typeof start !== "number" && !isBigInt$1(start)) throw new TypeError("Parameter start must be a number or bigint");
25
+ else startValue = start;
26
+ }
27
+ if (hasEnd) {
28
+ if (isBigNumber$2(end)) endValue = end.toNumber();
29
+ else if (typeof end !== "number" && !isBigInt$1(end)) throw new TypeError("Parameter end must be a number or bigint");
30
+ else endValue = end;
31
+ }
32
+ if (hasStep) {
33
+ if (isBigNumber$2(step)) stepValue = step.toNumber();
34
+ else if (typeof step !== "number" && !isBigInt$1(step)) throw new TypeError("Parameter step must be a number or bigint");
35
+ else stepValue = step;
36
+ }
37
+ this.start = hasStart ? parseFloat(startValue.toString()) : 0;
38
+ this.end = hasEnd ? parseFloat(endValue.toString()) : 0;
39
+ this.step = hasStep ? parseFloat(stepValue.toString()) : 1;
40
+ if (hasStep && nearlyEqual(this.step, 0)) throw new Error("Step must not be zero");
41
+ }
42
+ static parse(str) {
43
+ if (typeof str !== "string") return null;
44
+ const nums = str.split(":").map(function(arg) {
45
+ return parseFloat(arg);
46
+ });
47
+ if (nums.some(function(num) {
48
+ return isNaN(num);
49
+ })) return null;
50
+ switch (nums.length) {
51
+ case 2: return new Range(nums[0], nums[1]);
52
+ case 3: return new Range(nums[0], nums[2], nums[1]);
53
+ default: return null;
54
+ }
55
+ }
56
+ clone() {
57
+ return new Range(this.start, this.end, this.step);
58
+ }
59
+ size() {
60
+ let len = 0;
61
+ const start = this.start;
62
+ const step = this.step;
63
+ const diff = this.end - start;
64
+ if (sign(step) === sign(diff)) len = Math.ceil(diff / step);
65
+ else if (diff === 0) len = 0;
66
+ if (isNaN(len)) len = 0;
67
+ return [len];
68
+ }
69
+ min() {
70
+ const size = this.size()[0];
71
+ if (size > 0) {
72
+ if (this.step > 0) return this.start;
73
+ else return this.start + (size - 1) * this.step;
74
+ } else return;
75
+ }
76
+ max() {
77
+ const size = this.size()[0];
78
+ if (size > 0) {
79
+ if (this.step > 0) return this.start + (size - 1) * this.step;
80
+ else return this.start;
81
+ } else return;
82
+ }
83
+ forEach(callback) {
84
+ let x = this.start;
85
+ const step = this.step;
86
+ const end = this.end;
87
+ let i = 0;
88
+ if (step > 0) while (x < end) {
89
+ callback(x, [i], this);
90
+ x += step;
91
+ i++;
92
+ }
93
+ else if (step < 0) while (x > end) {
94
+ callback(x, [i], this);
95
+ x += step;
96
+ i++;
97
+ }
98
+ }
99
+ map(callback) {
100
+ const array = [];
101
+ this.forEach((value, index) => {
102
+ array[index[0]] = callback(value, index, this);
103
+ });
104
+ return array;
105
+ }
106
+ toArray() {
107
+ const array = [];
108
+ this.forEach(function(value, index) {
109
+ array[index[0]] = value;
110
+ });
111
+ return array;
112
+ }
113
+ valueOf() {
114
+ if (this._cache !== null && this.start === this._cacheStart && this.end === this._cacheEnd && this.step === this._cacheStep) return this._cache;
115
+ this._cache = this.toArray();
116
+ this._cacheStart = this.start;
117
+ this._cacheEnd = this.end;
118
+ this._cacheStep = this.step;
119
+ return this._cache;
120
+ }
121
+ format(options) {
122
+ let str = format(this.start, options);
123
+ if (this.step !== 1) str += ":" + format(this.step, options);
124
+ str += ":" + format(this.end, options);
125
+ return str;
126
+ }
127
+ toString() {
128
+ return this.format();
129
+ }
130
+ toJSON() {
131
+ return {
132
+ mathjs: "Range",
133
+ start: this.start,
134
+ end: this.end,
135
+ step: this.step
136
+ };
137
+ }
138
+ static fromJSON(json) {
139
+ return new Range(json.start, json.end, json.step);
140
+ }
141
+ }
142
+ return Range;
143
+ }, { isClass: true });
144
+ const Range = createRangeClass({});
145
+ //#endregion
146
+ //#region src/types/dual-rules.ts
147
+ const DUAL_UNARY_RULES = {
148
+ exp: {
149
+ primal: Math.exp,
150
+ deriv: (_x, y) => y
151
+ },
152
+ expm1: {
153
+ primal: Math.expm1,
154
+ deriv: (_x, y) => y + 1
155
+ },
156
+ log: {
157
+ primal: Math.log,
158
+ deriv: (x) => 1 / x
159
+ },
160
+ log2: {
161
+ primal: Math.log2,
162
+ deriv: (x) => 1 / (x * Math.LN2)
163
+ },
164
+ log10: {
165
+ primal: Math.log10,
166
+ deriv: (x) => 1 / (x * Math.LN10)
167
+ },
168
+ log1p: {
169
+ primal: Math.log1p,
170
+ deriv: (x) => 1 / (1 + x)
171
+ },
172
+ sin: {
173
+ primal: Math.sin,
174
+ deriv: (x) => Math.cos(x)
175
+ },
176
+ cos: {
177
+ primal: Math.cos,
178
+ deriv: (x) => -Math.sin(x)
179
+ },
180
+ tan: {
181
+ primal: Math.tan,
182
+ deriv: (x) => 1 / (Math.cos(x) * Math.cos(x))
183
+ },
184
+ asin: {
185
+ primal: Math.asin,
186
+ deriv: (x) => 1 / Math.sqrt(1 - x * x)
187
+ },
188
+ acos: {
189
+ primal: Math.acos,
190
+ deriv: (x) => -1 / Math.sqrt(1 - x * x)
191
+ },
192
+ atan: {
193
+ primal: Math.atan,
194
+ deriv: (x) => 1 / (1 + x * x)
195
+ },
196
+ sinh: {
197
+ primal: Math.sinh,
198
+ deriv: (x) => Math.cosh(x)
199
+ },
200
+ cosh: {
201
+ primal: Math.cosh,
202
+ deriv: (x) => Math.sinh(x)
203
+ },
204
+ tanh: {
205
+ primal: Math.tanh,
206
+ deriv: (_x, y) => 1 - y * y
207
+ },
208
+ asinh: {
209
+ primal: Math.asinh,
210
+ deriv: (x) => 1 / Math.sqrt(x * x + 1)
211
+ },
212
+ acosh: {
213
+ primal: Math.acosh,
214
+ deriv: (x) => 1 / Math.sqrt(x * x - 1)
215
+ },
216
+ atanh: {
217
+ primal: Math.atanh,
218
+ deriv: (x) => 1 / (1 - x * x)
219
+ },
220
+ sqrt: {
221
+ primal: Math.sqrt,
222
+ deriv: (_x, y) => 1 / (2 * y)
223
+ },
224
+ cbrt: {
225
+ primal: Math.cbrt,
226
+ deriv: (_x, y) => 1 / (3 * y * y)
227
+ },
228
+ square: {
229
+ primal: (x) => x * x,
230
+ deriv: (x) => 2 * x
231
+ },
232
+ reciprocal: {
233
+ primal: (x) => 1 / x,
234
+ deriv: (x) => -1 / (x * x)
235
+ },
236
+ abs: {
237
+ primal: Math.abs,
238
+ deriv: (x) => Math.sign(x)
239
+ },
240
+ sign: {
241
+ primal: Math.sign,
242
+ deriv: () => 0
243
+ }
426
244
  };
427
-
428
- // src/types/dual.ts
429
- var Dual = class _Dual {
430
- /** Function value (the real part). */
431
- value;
432
- /** First derivative (the ε coefficient). */
433
- deriv;
434
- constructor(value, deriv = 0) {
435
- this.value = value;
436
- this.deriv = deriv;
437
- }
438
- /** A constant (derivative 0). */
439
- static constant(v) {
440
- return new _Dual(v, 0);
441
- }
442
- /** A seed variable (derivative 1) — the point of differentiation. */
443
- static variable(v) {
444
- return new _Dual(v, 1);
445
- }
446
- // --- arithmetic ----------------------------------------------------------
447
- add(o) {
448
- return new _Dual(this.value + o.value, this.deriv + o.deriv);
449
- }
450
- sub(o) {
451
- return new _Dual(this.value - o.value, this.deriv - o.deriv);
452
- }
453
- mul(o) {
454
- return new _Dual(this.value * o.value, this.deriv * o.value + this.value * o.deriv);
455
- }
456
- div(o) {
457
- const d = (this.deriv * o.value - this.value * o.deriv) / (o.value * o.value);
458
- return new _Dual(this.value / o.value, d);
459
- }
460
- neg() {
461
- return new _Dual(-this.value, -this.deriv);
462
- }
463
- /** Power with a constant real exponent: d(xᵏ) = k·xᵏ⁻¹·dx. */
464
- powConst(k) {
465
- return new _Dual(Math.pow(this.value, k), this.deriv * k * Math.pow(this.value, k - 1));
466
- }
467
- /** General power a^b: d = a^b·(b'·ln a + b·a'/a). */
468
- pow(o) {
469
- const v = Math.pow(this.value, o.value);
470
- const d = v * (o.deriv * Math.log(this.value) + o.value * this.deriv / this.value);
471
- return new _Dual(v, d);
472
- }
473
- // --- elementary functions ------------------------------------------------
474
- // Each applies the shared chain rule (value, deriv) ↦ (f(v), deriv·f′(v))
475
- // using the canonical rule from `DUAL_UNARY_RULES`, so the scalar and tensor
476
- // AD paths can never drift apart.
477
- unary(rule) {
478
- const y = rule.primal(this.value);
479
- return new _Dual(y, this.deriv * rule.deriv(this.value, y));
480
- }
481
- sin() {
482
- return this.unary(DUAL_UNARY_RULES.sin);
483
- }
484
- cos() {
485
- return this.unary(DUAL_UNARY_RULES.cos);
486
- }
487
- tan() {
488
- return this.unary(DUAL_UNARY_RULES.tan);
489
- }
490
- exp() {
491
- return this.unary(DUAL_UNARY_RULES.exp);
492
- }
493
- log() {
494
- return this.unary(DUAL_UNARY_RULES.log);
495
- }
496
- sqrt() {
497
- return this.unary(DUAL_UNARY_RULES.sqrt);
498
- }
499
- square() {
500
- return this.unary(DUAL_UNARY_RULES.square);
501
- }
502
- abs() {
503
- return this.unary(DUAL_UNARY_RULES.abs);
504
- }
505
- sinh() {
506
- return this.unary(DUAL_UNARY_RULES.sinh);
507
- }
508
- cosh() {
509
- return this.unary(DUAL_UNARY_RULES.cosh);
510
- }
511
- tanh() {
512
- return this.unary(DUAL_UNARY_RULES.tanh);
513
- }
514
- toString() {
515
- return `Dual(${this.value}, ${this.deriv})`;
516
- }
245
+ //#endregion
246
+ //#region src/types/dual.ts
247
+ var Dual = class Dual {
248
+ value;
249
+ deriv;
250
+ constructor(value, deriv = 0) {
251
+ this.value = value;
252
+ this.deriv = deriv;
253
+ }
254
+ static constant(v) {
255
+ return new Dual(v, 0);
256
+ }
257
+ static variable(v) {
258
+ return new Dual(v, 1);
259
+ }
260
+ add(o) {
261
+ return new Dual(this.value + o.value, this.deriv + o.deriv);
262
+ }
263
+ sub(o) {
264
+ return new Dual(this.value - o.value, this.deriv - o.deriv);
265
+ }
266
+ mul(o) {
267
+ return new Dual(this.value * o.value, this.deriv * o.value + this.value * o.deriv);
268
+ }
269
+ div(o) {
270
+ const d = (this.deriv * o.value - this.value * o.deriv) / (o.value * o.value);
271
+ return new Dual(this.value / o.value, d);
272
+ }
273
+ neg() {
274
+ return new Dual(-this.value, -this.deriv);
275
+ }
276
+ powConst(k) {
277
+ return new Dual(Math.pow(this.value, k), this.deriv * k * Math.pow(this.value, k - 1));
278
+ }
279
+ pow(o) {
280
+ const v = Math.pow(this.value, o.value);
281
+ const d = v * (o.deriv * Math.log(this.value) + o.value * this.deriv / this.value);
282
+ return new Dual(v, d);
283
+ }
284
+ unary(rule) {
285
+ const y = rule.primal(this.value);
286
+ return new Dual(y, this.deriv * rule.deriv(this.value, y));
287
+ }
288
+ sin() {
289
+ return this.unary(DUAL_UNARY_RULES.sin);
290
+ }
291
+ cos() {
292
+ return this.unary(DUAL_UNARY_RULES.cos);
293
+ }
294
+ tan() {
295
+ return this.unary(DUAL_UNARY_RULES.tan);
296
+ }
297
+ exp() {
298
+ return this.unary(DUAL_UNARY_RULES.exp);
299
+ }
300
+ log() {
301
+ return this.unary(DUAL_UNARY_RULES.log);
302
+ }
303
+ sqrt() {
304
+ return this.unary(DUAL_UNARY_RULES.sqrt);
305
+ }
306
+ square() {
307
+ return this.unary(DUAL_UNARY_RULES.square);
308
+ }
309
+ abs() {
310
+ return this.unary(DUAL_UNARY_RULES.abs);
311
+ }
312
+ sinh() {
313
+ return this.unary(DUAL_UNARY_RULES.sinh);
314
+ }
315
+ cosh() {
316
+ return this.unary(DUAL_UNARY_RULES.cosh);
317
+ }
318
+ tanh() {
319
+ return this.unary(DUAL_UNARY_RULES.tanh);
320
+ }
321
+ toString() {
322
+ return `Dual(${this.value}, ${this.deriv})`;
323
+ }
517
324
  };
518
325
  function isDual(x) {
519
- return x instanceof Dual;
326
+ return x instanceof Dual;
520
327
  }
521
-
522
- // src/constants.ts
523
- var PI = Math.PI;
524
- var E = Math.E;
525
- var TAU = 2 * Math.PI;
526
- var PHI = (1 + Math.sqrt(5)) / 2;
527
- var SQRT2 = Math.SQRT2;
528
- var SQRT1_2 = Math.SQRT1_2;
529
- var LN2 = Math.LN2;
530
- var LN10 = Math.LN10;
531
- var LOG2E = Math.LOG2E;
532
- var LOG10E = Math.LOG10E;
533
-
534
- // src/types/unit-definitions.ts
535
- var DIMENSIONLESS = Object.freeze({
536
- length: 0,
537
- mass: 0,
538
- time: 0,
539
- current: 0,
540
- temperature: 0,
541
- amount: 0,
542
- luminosity: 0
328
+ //#endregion
329
+ //#region src/constants.ts
330
+ const PI = Math.PI;
331
+ const E = Math.E;
332
+ const TAU = 2 * Math.PI;
333
+ const PHI = (1 + Math.sqrt(5)) / 2;
334
+ const SQRT2 = Math.SQRT2;
335
+ const SQRT1_2 = Math.SQRT1_2;
336
+ const LN2 = Math.LN2;
337
+ const LN10 = Math.LN10;
338
+ const LOG2E = Math.LOG2E;
339
+ const LOG10E = Math.LOG10E;
340
+ //#endregion
341
+ //#region src/types/unit-definitions.ts
342
+ const DIMENSIONLESS = Object.freeze({
343
+ length: 0,
344
+ mass: 0,
345
+ time: 0,
346
+ current: 0,
347
+ temperature: 0,
348
+ amount: 0,
349
+ luminosity: 0
543
350
  });
544
351
  function dim(partial) {
545
- return {
546
- length: partial.length ?? 0,
547
- mass: partial.mass ?? 0,
548
- time: partial.time ?? 0,
549
- current: partial.current ?? 0,
550
- temperature: partial.temperature ?? 0,
551
- amount: partial.amount ?? 0,
552
- luminosity: partial.luminosity ?? 0
553
- };
352
+ return {
353
+ length: partial.length ?? 0,
354
+ mass: partial.mass ?? 0,
355
+ time: partial.time ?? 0,
356
+ current: partial.current ?? 0,
357
+ temperature: partial.temperature ?? 0,
358
+ amount: partial.amount ?? 0,
359
+ luminosity: partial.luminosity ?? 0
360
+ };
554
361
  }
555
- var BASE_UNITS = {
556
- m: { multiplier: 1, dimensions: dim({ length: 1 }), prefixable: true },
557
- // The base unit of mass is *kilogram*, but the prefix-able symbol is "g".
558
- // Internally we treat 1 kg as the canonical value, so "g" -> 0.001 kg.
559
- kg: { multiplier: 1, dimensions: dim({ mass: 1 }) },
560
- s: { multiplier: 1, dimensions: dim({ time: 1 }), prefixable: true },
561
- A: { multiplier: 1, dimensions: dim({ current: 1 }), prefixable: true },
562
- K: { multiplier: 1, dimensions: dim({ temperature: 1 }), prefixable: true },
563
- mol: { multiplier: 1, dimensions: dim({ amount: 1 }), prefixable: true },
564
- cd: { multiplier: 1, dimensions: dim({ luminosity: 1 }), prefixable: true }
362
+ const BASE_UNITS = {
363
+ m: {
364
+ multiplier: 1,
365
+ dimensions: dim({ length: 1 }),
366
+ prefixable: true
367
+ },
368
+ kg: {
369
+ multiplier: 1,
370
+ dimensions: dim({ mass: 1 })
371
+ },
372
+ s: {
373
+ multiplier: 1,
374
+ dimensions: dim({ time: 1 }),
375
+ prefixable: true
376
+ },
377
+ A: {
378
+ multiplier: 1,
379
+ dimensions: dim({ current: 1 }),
380
+ prefixable: true
381
+ },
382
+ K: {
383
+ multiplier: 1,
384
+ dimensions: dim({ temperature: 1 }),
385
+ prefixable: true
386
+ },
387
+ mol: {
388
+ multiplier: 1,
389
+ dimensions: dim({ amount: 1 }),
390
+ prefixable: true
391
+ },
392
+ cd: {
393
+ multiplier: 1,
394
+ dimensions: dim({ luminosity: 1 }),
395
+ prefixable: true
396
+ }
565
397
  };
566
- function tableUnit(name2, dimensions, prefixable) {
567
- const row = getUnitRow(name2);
568
- if (row === void 0) throw new Error(`unit-definitions: '${name2}' is not in the unit table`);
569
- const scale = readUnitScale(row.scale);
570
- const def = { multiplier: exactScaleToNumber(scale), dimensions };
571
- if (row.offset !== void 0) {
572
- def.offset = exactScaleToNumber(multiplyExactScales(scale, readUnitScale(row.offset)));
573
- }
574
- if (prefixable) def.prefixable = true;
575
- return def;
398
+ function tableUnit(name, dimensions, prefixable) {
399
+ const row = getUnitRow(name);
400
+ if (row === void 0) throw new Error(`unit-definitions: '${name}' is not in the unit table`);
401
+ const scale = readUnitScale(row.scale);
402
+ const def = {
403
+ multiplier: exactScaleToNumber(scale),
404
+ dimensions
405
+ };
406
+ if (row.offset !== void 0) def.offset = exactScaleToNumber(multiplyExactScales(scale, readUnitScale(row.offset)));
407
+ if (prefixable) def.prefixable = true;
408
+ return def;
576
409
  }
577
- var DERIVED_UNITS = {
578
- // --- Length ---------------------------------------------------------------
579
- // Note: 'm' is a base unit (above), already prefixable.
580
- ft: tableUnit("ft", dim({ length: 1 })),
581
- foot: tableUnit("foot", dim({ length: 1 })),
582
- in: tableUnit("in", dim({ length: 1 })),
583
- inch: tableUnit("inch", dim({ length: 1 })),
584
- yd: tableUnit("yd", dim({ length: 1 })),
585
- yard: tableUnit("yard", dim({ length: 1 })),
586
- mi: tableUnit("mi", dim({ length: 1 })),
587
- mile: tableUnit("mile", dim({ length: 1 })),
588
- // --- Mass -----------------------------------------------------------------
589
- // The "g" entry is gram (0.001 kg). It is prefixable, so kg/mg/µg work via
590
- // prefix application on this entry rather than the base "kg".
591
- g: tableUnit("g", dim({ mass: 1 }), true),
592
- lb: tableUnit("lb", dim({ mass: 1 })),
593
- lbm: tableUnit("lbm", dim({ mass: 1 })),
594
- oz: tableUnit("oz", dim({ mass: 1 })),
595
- ton: tableUnit("ton", dim({ mass: 1 })),
596
- // US short ton
597
- tonne: tableUnit("tonne", dim({ mass: 1 })),
598
- // metric ton
599
- // --- Time -----------------------------------------------------------------
600
- min: tableUnit("min", dim({ time: 1 })),
601
- h: tableUnit("h", dim({ time: 1 })),
602
- hr: tableUnit("hr", dim({ time: 1 })),
603
- day: tableUnit("day", dim({ time: 1 })),
604
- week: tableUnit("week", dim({ time: 1 })),
605
- year: tableUnit("year", dim({ time: 1 })),
606
- // Julian year
607
- // --- Temperature ----------------------------------------------------------
608
- // K is the base.
609
- // °C → K is offset by 273.15 (no multiplicative factor change).
610
- // °F → K is more complex (offset & scale).
611
- degC: tableUnit("degC", dim({ temperature: 1 })),
612
- degF: tableUnit("degF", dim({ temperature: 1 })),
613
- degR: tableUnit("degR", dim({ temperature: 1 })),
614
- // Rankine
615
- // --- Plane angle (dimensionless, but often treated as units) --------------
616
- rad: tableUnit("rad", dim({}), true),
617
- deg: tableUnit("deg", dim({})),
618
- grad: tableUnit("grad", dim({})),
619
- // --- Force ----------------------------------------------------------------
620
- // N = kg·m·s^-2 = 1 kg·m·s^-2; in our base-units representation that's
621
- // value=1, dim {length: 1, mass: 1, time: -2}.
622
- N: tableUnit("N", dim({ length: 1, mass: 1, time: -2 }), true),
623
- dyn: tableUnit("dyn", dim({ length: 1, mass: 1, time: -2 })),
624
- lbf: tableUnit("lbf", dim({ length: 1, mass: 1, time: -2 })),
625
- // --- Energy ---------------------------------------------------------------
626
- J: tableUnit("J", dim({ length: 2, mass: 1, time: -2 }), true),
627
- erg: tableUnit("erg", dim({ length: 2, mass: 1, time: -2 })),
628
- cal: tableUnit("cal", dim({ length: 2, mass: 1, time: -2 })),
629
- eV: tableUnit("eV", dim({ length: 2, mass: 1, time: -2 }), true),
630
- BTU: tableUnit("BTU", dim({ length: 2, mass: 1, time: -2 })),
631
- // --- Power ----------------------------------------------------------------
632
- W: tableUnit("W", dim({ length: 2, mass: 1, time: -3 }), true),
633
- hp: tableUnit("hp", dim({ length: 2, mass: 1, time: -3 })),
634
- // --- Pressure -------------------------------------------------------------
635
- Pa: tableUnit("Pa", dim({ length: -1, mass: 1, time: -2 }), true),
636
- bar: tableUnit("bar", dim({ length: -1, mass: 1, time: -2 }), true),
637
- atm: tableUnit("atm", dim({ length: -1, mass: 1, time: -2 })),
638
- psi: tableUnit("psi", dim({ length: -1, mass: 1, time: -2 })),
639
- torr: tableUnit("torr", dim({ length: -1, mass: 1, time: -2 })),
640
- mmHg: tableUnit("mmHg", dim({ length: -1, mass: 1, time: -2 })),
641
- // --- Electric -------------------------------------------------------------
642
- C: tableUnit("C", dim({ time: 1, current: 1 }), true),
643
- V: tableUnit("V", dim({ length: 2, mass: 1, time: -3, current: -1 }), true),
644
- ohm: tableUnit("ohm", dim({ length: 2, mass: 1, time: -3, current: -2 }), true),
645
- \u03A9: tableUnit("ohm", dim({ length: 2, mass: 1, time: -3, current: -2 }), true),
646
- F: tableUnit("F", dim({ length: -2, mass: -1, time: 4, current: 2 }), true),
647
- H: tableUnit("H", dim({ length: 2, mass: 1, time: -2, current: -2 }), true),
648
- // --- Frequency ------------------------------------------------------------
649
- Hz: tableUnit("Hz", dim({ time: -1 }), true),
650
- // --- Volume ---------------------------------------------------------------
651
- L: tableUnit("L", dim({ length: 3 }), true),
652
- l: tableUnit("l", dim({ length: 3 }), true),
653
- gal: tableUnit("gal", dim({ length: 3 })),
654
- // US gallon
655
- // --- Area -----------------------------------------------------------------
656
- ha: tableUnit("hectare", dim({ length: 2 })),
657
- // hectare
658
- acre: tableUnit("acre", dim({ length: 2 }))
410
+ const DERIVED_UNITS = {
411
+ ft: tableUnit("ft", dim({ length: 1 })),
412
+ foot: tableUnit("foot", dim({ length: 1 })),
413
+ in: tableUnit("in", dim({ length: 1 })),
414
+ inch: tableUnit("inch", dim({ length: 1 })),
415
+ yd: tableUnit("yd", dim({ length: 1 })),
416
+ yard: tableUnit("yard", dim({ length: 1 })),
417
+ mi: tableUnit("mi", dim({ length: 1 })),
418
+ mile: tableUnit("mile", dim({ length: 1 })),
419
+ g: tableUnit("g", dim({ mass: 1 }), true),
420
+ lb: tableUnit("lb", dim({ mass: 1 })),
421
+ lbm: tableUnit("lbm", dim({ mass: 1 })),
422
+ oz: tableUnit("oz", dim({ mass: 1 })),
423
+ ton: tableUnit("ton", dim({ mass: 1 })),
424
+ tonne: tableUnit("tonne", dim({ mass: 1 })),
425
+ min: tableUnit("min", dim({ time: 1 })),
426
+ h: tableUnit("h", dim({ time: 1 })),
427
+ hr: tableUnit("hr", dim({ time: 1 })),
428
+ day: tableUnit("day", dim({ time: 1 })),
429
+ week: tableUnit("week", dim({ time: 1 })),
430
+ year: tableUnit("year", dim({ time: 1 })),
431
+ degC: tableUnit("degC", dim({ temperature: 1 })),
432
+ degF: tableUnit("degF", dim({ temperature: 1 })),
433
+ degR: tableUnit("degR", dim({ temperature: 1 })),
434
+ rad: tableUnit("rad", dim({}), true),
435
+ deg: tableUnit("deg", dim({})),
436
+ grad: tableUnit("grad", dim({})),
437
+ N: tableUnit("N", dim({
438
+ length: 1,
439
+ mass: 1,
440
+ time: -2
441
+ }), true),
442
+ dyn: tableUnit("dyn", dim({
443
+ length: 1,
444
+ mass: 1,
445
+ time: -2
446
+ })),
447
+ lbf: tableUnit("lbf", dim({
448
+ length: 1,
449
+ mass: 1,
450
+ time: -2
451
+ })),
452
+ J: tableUnit("J", dim({
453
+ length: 2,
454
+ mass: 1,
455
+ time: -2
456
+ }), true),
457
+ erg: tableUnit("erg", dim({
458
+ length: 2,
459
+ mass: 1,
460
+ time: -2
461
+ })),
462
+ cal: tableUnit("cal", dim({
463
+ length: 2,
464
+ mass: 1,
465
+ time: -2
466
+ })),
467
+ eV: tableUnit("eV", dim({
468
+ length: 2,
469
+ mass: 1,
470
+ time: -2
471
+ }), true),
472
+ BTU: tableUnit("BTU", dim({
473
+ length: 2,
474
+ mass: 1,
475
+ time: -2
476
+ })),
477
+ W: tableUnit("W", dim({
478
+ length: 2,
479
+ mass: 1,
480
+ time: -3
481
+ }), true),
482
+ hp: tableUnit("hp", dim({
483
+ length: 2,
484
+ mass: 1,
485
+ time: -3
486
+ })),
487
+ Pa: tableUnit("Pa", dim({
488
+ length: -1,
489
+ mass: 1,
490
+ time: -2
491
+ }), true),
492
+ bar: tableUnit("bar", dim({
493
+ length: -1,
494
+ mass: 1,
495
+ time: -2
496
+ }), true),
497
+ atm: tableUnit("atm", dim({
498
+ length: -1,
499
+ mass: 1,
500
+ time: -2
501
+ })),
502
+ psi: tableUnit("psi", dim({
503
+ length: -1,
504
+ mass: 1,
505
+ time: -2
506
+ })),
507
+ torr: tableUnit("torr", dim({
508
+ length: -1,
509
+ mass: 1,
510
+ time: -2
511
+ })),
512
+ mmHg: tableUnit("mmHg", dim({
513
+ length: -1,
514
+ mass: 1,
515
+ time: -2
516
+ })),
517
+ C: tableUnit("C", dim({
518
+ time: 1,
519
+ current: 1
520
+ }), true),
521
+ V: tableUnit("V", dim({
522
+ length: 2,
523
+ mass: 1,
524
+ time: -3,
525
+ current: -1
526
+ }), true),
527
+ ohm: tableUnit("ohm", dim({
528
+ length: 2,
529
+ mass: 1,
530
+ time: -3,
531
+ current: -2
532
+ }), true),
533
+ Ω: tableUnit("ohm", dim({
534
+ length: 2,
535
+ mass: 1,
536
+ time: -3,
537
+ current: -2
538
+ }), true),
539
+ F: tableUnit("F", dim({
540
+ length: -2,
541
+ mass: -1,
542
+ time: 4,
543
+ current: 2
544
+ }), true),
545
+ H: tableUnit("H", dim({
546
+ length: 2,
547
+ mass: 1,
548
+ time: -2,
549
+ current: -2
550
+ }), true),
551
+ Hz: tableUnit("Hz", dim({ time: -1 }), true),
552
+ L: tableUnit("L", dim({ length: 3 }), true),
553
+ l: tableUnit("l", dim({ length: 3 }), true),
554
+ gal: tableUnit("gal", dim({ length: 3 })),
555
+ ha: tableUnit("hectare", dim({ length: 2 })),
556
+ acre: tableUnit("acre", dim({ length: 2 }))
557
+ };
558
+ const ALL_UNITS = {
559
+ ...BASE_UNITS,
560
+ ...DERIVED_UNITS
659
561
  };
660
- var ALL_UNITS = { ...BASE_UNITS, ...DERIVED_UNITS };
661
- var UNIT_ALIASES = {
662
- "\xB0C": "degC",
663
- "\xB0F": "degF",
664
- "\xB0R": "degR",
665
- "\xB0": "deg"
666
- // The Unicode micro sign is handled in prefixes; °K is non-standard.
562
+ const UNIT_ALIASES = {
563
+ "°C": "degC",
564
+ "°F": "degF",
565
+ "°R": "degR",
566
+ "°": "deg"
667
567
  };
668
- function getUnitDef(name2) {
669
- return ALL_UNITS[name2];
568
+ function getUnitDef(name) {
569
+ return ALL_UNITS[name];
670
570
  }
671
-
672
- // src/types/si-dimension-vector.ts
673
- var UNIT_DIMENSION_LENGTH = 10;
674
- var SI_DIMENSION_LENGTH = 7;
675
- var EXTRA_INDEXES = [7, 8, 9];
571
+ //#endregion
572
+ //#region src/types/si-dimension-vector.ts
573
+ const UNIT_DIMENSION_LENGTH = 10;
574
+ const SI_DIMENSION_LENGTH = 7;
575
+ const EXTRA_INDEXES = [
576
+ 7,
577
+ 8,
578
+ 9
579
+ ];
676
580
  function assertFinite(label, value) {
677
- if (typeof value !== "number" || !Number.isFinite(value)) {
678
- throw new TypeError(`${label} must be a finite number`);
679
- }
581
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new TypeError(`${label} must be a finite number`);
680
582
  }
681
583
  function assertUnitVector(vector) {
682
- if (vector.length !== UNIT_DIMENSION_LENGTH) {
683
- throw new TypeError(`dimension vector must have length ${UNIT_DIMENSION_LENGTH}`);
684
- }
685
- for (let i = 0; i < vector.length; i++) {
686
- assertFinite(`dimension vector[${i}]`, vector[i]);
687
- }
584
+ if (vector.length !== 10) throw new TypeError(`dimension vector must have length 10`);
585
+ for (let i = 0; i < vector.length; i++) assertFinite(`dimension vector[${i}]`, vector[i]);
688
586
  }
689
587
  function rejectExtra(vector, options) {
690
- if (options?.ignoreExtra) return;
691
- for (const index of EXTRA_INDEXES) {
692
- if (vector[index] !== 0) {
693
- throw new RangeError(
694
- `dimension vector has a nonzero angle, bit, or solid-angle exponent at index ${index}; pass { ignoreExtra: true } to drop it`
695
- );
696
- }
697
- }
588
+ if (options?.ignoreExtra) return;
589
+ for (const index of EXTRA_INDEXES) if (vector[index] !== 0) throw new RangeError(`dimension vector has a nonzero angle, bit, or solid-angle exponent at index ${index}; pass { ignoreExtra: true } to drop it`);
698
590
  }
699
591
  function toSiDimensions(vector, options) {
700
- assertUnitVector(vector);
701
- rejectExtra(vector, options);
702
- return {
703
- length: vector[1],
704
- mass: vector[0],
705
- time: vector[2],
706
- current: vector[3],
707
- temperature: vector[4],
708
- amount: vector[6],
709
- luminosity: vector[5]
710
- };
592
+ assertUnitVector(vector);
593
+ rejectExtra(vector, options);
594
+ return {
595
+ length: vector[1],
596
+ mass: vector[0],
597
+ time: vector[2],
598
+ current: vector[3],
599
+ temperature: vector[4],
600
+ amount: vector[6],
601
+ luminosity: vector[5]
602
+ };
711
603
  }
712
604
  function toSiDimensionVector(vector, options) {
713
- const d = toSiDimensions(vector, options);
714
- return [d.length, d.mass, d.time, d.current, d.temperature, d.amount, d.luminosity];
605
+ const d = toSiDimensions(vector, options);
606
+ return [
607
+ d.length,
608
+ d.mass,
609
+ d.time,
610
+ d.current,
611
+ d.temperature,
612
+ d.amount,
613
+ d.luminosity
614
+ ];
715
615
  }
716
616
  function fromSiDimensions(dimensions) {
717
- const fields = [
718
- ["mass", dimensions.mass],
719
- ["length", dimensions.length],
720
- ["time", dimensions.time],
721
- ["current", dimensions.current],
722
- ["temperature", dimensions.temperature],
723
- ["luminosity", dimensions.luminosity],
724
- ["amount", dimensions.amount]
725
- ];
726
- for (const [name2, value] of fields) {
727
- assertFinite(`dimensions.${name2}`, value);
728
- }
729
- return [
730
- dimensions.mass,
731
- dimensions.length,
732
- dimensions.time,
733
- dimensions.current,
734
- dimensions.temperature,
735
- dimensions.luminosity,
736
- dimensions.amount,
737
- 0,
738
- 0,
739
- 0
740
- ];
617
+ const fields = [
618
+ ["mass", dimensions.mass],
619
+ ["length", dimensions.length],
620
+ ["time", dimensions.time],
621
+ ["current", dimensions.current],
622
+ ["temperature", dimensions.temperature],
623
+ ["luminosity", dimensions.luminosity],
624
+ ["amount", dimensions.amount]
625
+ ];
626
+ for (const [name, value] of fields) assertFinite(`dimensions.${name}`, value);
627
+ return [
628
+ dimensions.mass,
629
+ dimensions.length,
630
+ dimensions.time,
631
+ dimensions.current,
632
+ dimensions.temperature,
633
+ dimensions.luminosity,
634
+ dimensions.amount,
635
+ 0,
636
+ 0,
637
+ 0
638
+ ];
741
639
  }
742
640
  function fromSiDimensionVector(vector) {
743
- if (vector.length !== SI_DIMENSION_LENGTH) {
744
- throw new TypeError(
745
- `SI dimension vector must have length ${SI_DIMENSION_LENGTH} [L, M, T, I, \u0398, N, J]`
746
- );
747
- }
748
- return fromSiDimensions({
749
- length: vector[0],
750
- mass: vector[1],
751
- time: vector[2],
752
- current: vector[3],
753
- temperature: vector[4],
754
- amount: vector[5],
755
- luminosity: vector[6]
756
- });
641
+ if (vector.length !== 7) throw new TypeError(`SI dimension vector must have length 7 [L, M, T, I, Θ, N, J]`);
642
+ return fromSiDimensions({
643
+ length: vector[0],
644
+ mass: vector[1],
645
+ time: vector[2],
646
+ current: vector[3],
647
+ temperature: vector[4],
648
+ amount: vector[5],
649
+ luminosity: vector[6]
650
+ });
757
651
  }
758
-
759
- // src/types/unit-prefixes.ts
760
- var SI_PREFIXES = (() => {
761
- const prefixes = {};
762
- const short = UNIT_PREFIX_SETS.SHORT;
763
- for (const name2 of Object.keys(short)) {
764
- if (name2 === "") continue;
765
- prefixes[name2] = exactScaleToNumber(unitPrefixExactScale(short[name2]));
766
- }
767
- prefixes["\xB5"] = prefixes.u;
768
- return prefixes;
652
+ //#endregion
653
+ //#region src/types/unit-prefixes.ts
654
+ const SI_PREFIXES = (() => {
655
+ const prefixes = {};
656
+ const short = UNIT_PREFIX_SETS.SHORT;
657
+ for (const name of Object.keys(short)) {
658
+ if (name === "") continue;
659
+ prefixes[name] = exactScaleToNumber(unitPrefixExactScale(short[name]));
660
+ }
661
+ prefixes["µ"] = prefixes.u;
662
+ return prefixes;
769
663
  })();
770
- var BEST_PREFIXES = [
771
- "Y",
772
- "Z",
773
- "E",
774
- "P",
775
- "T",
776
- "G",
777
- "M",
778
- "k",
779
- "",
780
- "m",
781
- "u",
782
- "n",
783
- "p",
784
- "f",
785
- "a",
786
- "z",
787
- "y"
664
+ const BEST_PREFIXES = [
665
+ "Y",
666
+ "Z",
667
+ "E",
668
+ "P",
669
+ "T",
670
+ "G",
671
+ "M",
672
+ "k",
673
+ "",
674
+ "m",
675
+ "u",
676
+ "n",
677
+ "p",
678
+ "f",
679
+ "a",
680
+ "z",
681
+ "y"
788
682
  ];
789
- function getPrefix(name2) {
790
- return SI_PREFIXES[name2];
683
+ function getPrefix(name) {
684
+ return SI_PREFIXES[name];
791
685
  }
792
-
793
- // src/typed/mathts-typed.ts
794
- import typed, { create } from "typed-function";
795
- var wasmInitialized = false;
796
- var wasmAvailable = false;
686
+ //#endregion
687
+ //#region src/typed/mathts-typed.ts
688
+ let wasmInitialized = false;
689
+ let wasmAvailable = false;
797
690
  async function initTypedWasm(options = {}) {
798
- if (wasmInitialized) return wasmAvailable;
799
- try {
800
- if (typeof typed.init === "function") {
801
- await typed.init({ preferWasm: options.preferWasm ?? true });
802
- wasmAvailable = typed.isWasmEnabled?.() ?? false;
803
- }
804
- } catch {
805
- wasmAvailable = false;
806
- }
807
- wasmInitialized = true;
808
- return wasmAvailable;
691
+ if (wasmInitialized) return wasmAvailable;
692
+ try {
693
+ if (typeof typed.init === "function") {
694
+ await typed.init({ preferWasm: options.preferWasm ?? true });
695
+ wasmAvailable = typed.isWasmEnabled?.() ?? false;
696
+ }
697
+ } catch {
698
+ wasmAvailable = false;
699
+ }
700
+ wasmInitialized = true;
701
+ return wasmAvailable;
809
702
  }
810
703
  function isTypedWasmAvailable() {
811
- return typed.isWasmEnabled?.() ?? wasmAvailable;
704
+ return typed.isWasmEnabled?.() ?? wasmAvailable;
812
705
  }
813
- var isNumber = (x) => typeof x === "number";
814
- var isBoolean = (x) => typeof x === "boolean";
815
- var isString = (x) => typeof x === "string";
816
- var isBigInt2 = (x) => typeof x === "bigint";
817
- var isArray = (x) => Array.isArray(x);
818
- var isFunction = (x) => typeof x === "function";
819
- var isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
820
- var isNull = (x) => x === null;
821
- var isUndefined = (x) => x === void 0;
822
- var isFloat64Array = (x) => x instanceof Float64Array;
823
- var isFloat32Array = (x) => x instanceof Float32Array;
824
- var isInt32Array = (x) => x instanceof Int32Array;
825
- var isUint32Array = (x) => x instanceof Uint32Array;
826
- var isUint8Array = (x) => x instanceof Uint8Array;
827
- var isComplex2 = (x) => isComplex(x);
828
- var isFraction2 = (x) => isFraction(x);
829
- var isBigNumber3 = (x) => isBigNumber2(x);
830
- var isMatrix = (x) => isObject(x) && "rows" in x && "cols" in x && "get" in x && typeof x.type === "string";
831
- var isDenseMatrix = (x) => isMatrix(x) && x.type === "DenseMatrix";
832
- var isSparseMatrix = (x) => isMatrix(x) && x.type === "SparseMatrix";
833
- var isUnit2 = (x) => {
834
- if (!isObject(x)) return false;
835
- const o = x;
836
- if (typeof o.type !== "string") return false;
837
- if (o.type === "Unit" && "value" in o && "dimensions" in o) return true;
838
- if ("value" in o && "unit" in o) return true;
839
- return false;
706
+ const isNumber = (x) => typeof x === "number";
707
+ const isBoolean = (x) => typeof x === "boolean";
708
+ const isString = (x) => typeof x === "string";
709
+ const isBigInt = (x) => typeof x === "bigint";
710
+ const isArray = (x) => Array.isArray(x);
711
+ const isFunction = (x) => typeof x === "function";
712
+ const isObject = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
713
+ const isNull = (x) => x === null;
714
+ const isUndefined = (x) => x === void 0;
715
+ const isFloat64Array = (x) => x instanceof Float64Array;
716
+ const isFloat32Array = (x) => x instanceof Float32Array;
717
+ const isInt32Array = (x) => x instanceof Int32Array;
718
+ const isUint32Array = (x) => x instanceof Uint32Array;
719
+ const isUint8Array = (x) => x instanceof Uint8Array;
720
+ const isComplex$1 = (x) => isComplex(x);
721
+ const isFraction$1 = (x) => isFraction(x);
722
+ const isBigNumber$1 = (x) => isBigNumber(x);
723
+ const isMatrix = (x) => isObject(x) && "rows" in x && "cols" in x && "get" in x && typeof x.type === "string";
724
+ const isDenseMatrix = (x) => isMatrix(x) && x.type === "DenseMatrix";
725
+ const isSparseMatrix = (x) => isMatrix(x) && x.type === "SparseMatrix";
726
+ const isUnit = (x) => {
727
+ if (!isObject(x)) return false;
728
+ const o = x;
729
+ if (typeof o.type !== "string") return false;
730
+ if (o.type === "Unit" && "value" in o && "dimensions" in o) return true;
731
+ if ("value" in o && "unit" in o) return true;
732
+ return false;
840
733
  };
841
- var MATHTS_TYPES = [
842
- // bigint is not built into typed-function
843
- { name: "bigint", test: isBigInt2 },
844
- // MathTS numeric types (ordered by specificity for conversion priority)
845
- // WASM masks use typed.masks.OBJECT | typed.masks.custom(N) pattern
846
- { name: "Complex", test: isComplex2 },
847
- { name: "Fraction", test: isFraction2 },
848
- { name: "BigNumber", test: isBigNumber3 },
849
- // TypedArrays (for parallel-first WASM operations)
850
- { name: "Float64Array", test: isFloat64Array },
851
- { name: "Float32Array", test: isFloat32Array },
852
- { name: "Int32Array", test: isInt32Array },
853
- { name: "Uint32Array", test: isUint32Array },
854
- { name: "Uint8Array", test: isUint8Array },
855
- // Matrix types
856
- { name: "DenseMatrix", test: isDenseMatrix },
857
- { name: "SparseMatrix", test: isSparseMatrix },
858
- { name: "Matrix", test: isMatrix },
859
- // Other types
860
- { name: "Unit", test: isUnit2 },
861
- { name: "Dual", test: isDual }
734
+ const MATHTS_TYPES = [
735
+ {
736
+ name: "bigint",
737
+ test: isBigInt
738
+ },
739
+ {
740
+ name: "Complex",
741
+ test: isComplex$1
742
+ },
743
+ {
744
+ name: "Fraction",
745
+ test: isFraction$1
746
+ },
747
+ {
748
+ name: "BigNumber",
749
+ test: isBigNumber$1
750
+ },
751
+ {
752
+ name: "Float64Array",
753
+ test: isFloat64Array
754
+ },
755
+ {
756
+ name: "Float32Array",
757
+ test: isFloat32Array
758
+ },
759
+ {
760
+ name: "Int32Array",
761
+ test: isInt32Array
762
+ },
763
+ {
764
+ name: "Uint32Array",
765
+ test: isUint32Array
766
+ },
767
+ {
768
+ name: "Uint8Array",
769
+ test: isUint8Array
770
+ },
771
+ {
772
+ name: "DenseMatrix",
773
+ test: isDenseMatrix
774
+ },
775
+ {
776
+ name: "SparseMatrix",
777
+ test: isSparseMatrix
778
+ },
779
+ {
780
+ name: "Matrix",
781
+ test: isMatrix
782
+ },
783
+ {
784
+ name: "Unit",
785
+ test: isUnit
786
+ },
787
+ {
788
+ name: "Dual",
789
+ test: isDual
790
+ }
862
791
  ];
863
- var MATHTS_CONVERSIONS = [
864
- // -------------------------------------------------------------------------
865
- // To Complex conversions
866
- // -------------------------------------------------------------------------
867
- {
868
- from: "number",
869
- to: "Complex",
870
- convert: (n) => Complex.fromNumber(n)
871
- },
872
- {
873
- from: "Fraction",
874
- to: "Complex",
875
- convert: (f) => Complex.fromNumber(f.toNumber())
876
- },
877
- {
878
- from: "BigNumber",
879
- to: "Complex",
880
- convert: (bn) => Complex.fromNumber(bn.valueOf())
881
- },
882
- {
883
- from: "string",
884
- to: "Complex",
885
- convert: (s) => Complex.parse(s)
886
- },
887
- // -------------------------------------------------------------------------
888
- // To Fraction conversions
889
- // -------------------------------------------------------------------------
890
- {
891
- from: "number",
892
- to: "Fraction",
893
- convert: (n) => Fraction.fromNumber(n)
894
- },
895
- {
896
- from: "bigint",
897
- to: "Fraction",
898
- convert: (n) => new Fraction(n, 1n)
899
- },
900
- {
901
- from: "string",
902
- to: "Fraction",
903
- convert: (s) => Fraction.parse(s)
904
- },
905
- // -------------------------------------------------------------------------
906
- // To BigNumber conversions
907
- // -------------------------------------------------------------------------
908
- {
909
- from: "number",
910
- to: "BigNumber",
911
- convert: (n) => BigNumber.fromNumber(n)
912
- },
913
- {
914
- from: "bigint",
915
- to: "BigNumber",
916
- convert: (n) => BigNumber.fromBigInt(n)
917
- },
918
- {
919
- from: "Fraction",
920
- to: "BigNumber",
921
- convert: (f) => BigNumber.fromNumber(f.toNumber())
922
- },
923
- {
924
- from: "string",
925
- to: "BigNumber",
926
- convert: (s) => BigNumber.parse(s)
927
- },
928
- // -------------------------------------------------------------------------
929
- // To number conversions
930
- // -------------------------------------------------------------------------
931
- {
932
- from: "boolean",
933
- to: "number",
934
- convert: (b) => b ? 1 : 0
935
- },
936
- {
937
- from: "string",
938
- to: "number",
939
- convert: (s) => {
940
- const n = parseFloat(s);
941
- if (isNaN(n)) throw new Error(`Cannot convert "${s}" to number`);
942
- return n;
943
- }
944
- },
945
- {
946
- from: "bigint",
947
- to: "number",
948
- convert: (n) => Number(n)
949
- },
950
- {
951
- from: "Fraction",
952
- to: "number",
953
- convert: (f) => f.toNumber()
954
- },
955
- {
956
- from: "BigNumber",
957
- to: "number",
958
- convert: (bn) => bn.valueOf()
959
- },
960
- // -------------------------------------------------------------------------
961
- // To bigint conversions
962
- // -------------------------------------------------------------------------
963
- {
964
- from: "number",
965
- to: "bigint",
966
- convert: (n) => BigInt(Math.trunc(n))
967
- },
968
- {
969
- from: "Fraction",
970
- to: "bigint",
971
- convert: (f) => f.trunc().numerator
972
- },
973
- {
974
- from: "BigNumber",
975
- to: "bigint",
976
- convert: (bn) => bn.toBigInt()
977
- },
978
- {
979
- from: "string",
980
- to: "bigint",
981
- convert: (s) => BigInt(s)
982
- },
983
- // -------------------------------------------------------------------------
984
- // Matrix conversions (placeholder until Matrix is implemented)
985
- // -------------------------------------------------------------------------
986
- {
987
- from: "Array",
988
- to: "Matrix",
989
- convert: (a) => {
990
- const arr = a;
991
- return {
992
- rows: arr.length,
993
- cols: arr[0]?.length ?? 0,
994
- data: arr.flat(),
995
- type: "DenseMatrix",
996
- get: (r, c) => arr[r]?.[c]
997
- };
998
- }
999
- },
1000
- {
1001
- from: "Matrix",
1002
- to: "Array",
1003
- convert: (m) => {
1004
- const matrix = m;
1005
- const result = [];
1006
- for (let i = 0; i < matrix.rows; i++) {
1007
- result[i] = [];
1008
- for (let j = 0; j < matrix.cols; j++) {
1009
- result[i][j] = matrix.get(i, j);
1010
- }
1011
- }
1012
- return result;
1013
- }
1014
- },
1015
- {
1016
- from: "DenseMatrix",
1017
- to: "SparseMatrix",
1018
- convert: (m) => {
1019
- return { ...m, type: "SparseMatrix" };
1020
- }
1021
- }
792
+ const MATHTS_CONVERSIONS = [
793
+ {
794
+ from: "number",
795
+ to: "Complex",
796
+ convert: (n) => Complex.fromNumber(n)
797
+ },
798
+ {
799
+ from: "Fraction",
800
+ to: "Complex",
801
+ convert: (f) => Complex.fromNumber(f.toNumber())
802
+ },
803
+ {
804
+ from: "BigNumber",
805
+ to: "Complex",
806
+ convert: (bn) => Complex.fromNumber(bn.valueOf())
807
+ },
808
+ {
809
+ from: "string",
810
+ to: "Complex",
811
+ convert: (s) => Complex.parse(s)
812
+ },
813
+ {
814
+ from: "number",
815
+ to: "Fraction",
816
+ convert: (n) => Fraction.fromNumber(n)
817
+ },
818
+ {
819
+ from: "bigint",
820
+ to: "Fraction",
821
+ convert: (n) => new Fraction(n, 1n)
822
+ },
823
+ {
824
+ from: "string",
825
+ to: "Fraction",
826
+ convert: (s) => Fraction.parse(s)
827
+ },
828
+ {
829
+ from: "number",
830
+ to: "BigNumber",
831
+ convert: (n) => BigNumber.fromNumber(n)
832
+ },
833
+ {
834
+ from: "bigint",
835
+ to: "BigNumber",
836
+ convert: (n) => BigNumber.fromBigInt(n)
837
+ },
838
+ {
839
+ from: "Fraction",
840
+ to: "BigNumber",
841
+ convert: (f) => BigNumber.fromNumber(f.toNumber())
842
+ },
843
+ {
844
+ from: "string",
845
+ to: "BigNumber",
846
+ convert: (s) => BigNumber.parse(s)
847
+ },
848
+ {
849
+ from: "boolean",
850
+ to: "number",
851
+ convert: (b) => b ? 1 : 0
852
+ },
853
+ {
854
+ from: "string",
855
+ to: "number",
856
+ convert: (s) => {
857
+ const n = parseFloat(s);
858
+ if (isNaN(n)) throw new Error(`Cannot convert "${s}" to number`);
859
+ return n;
860
+ }
861
+ },
862
+ {
863
+ from: "bigint",
864
+ to: "number",
865
+ convert: (n) => Number(n)
866
+ },
867
+ {
868
+ from: "Fraction",
869
+ to: "number",
870
+ convert: (f) => f.toNumber()
871
+ },
872
+ {
873
+ from: "BigNumber",
874
+ to: "number",
875
+ convert: (bn) => bn.valueOf()
876
+ },
877
+ {
878
+ from: "number",
879
+ to: "bigint",
880
+ convert: (n) => BigInt(Math.trunc(n))
881
+ },
882
+ {
883
+ from: "Fraction",
884
+ to: "bigint",
885
+ convert: (f) => f.trunc().numerator
886
+ },
887
+ {
888
+ from: "BigNumber",
889
+ to: "bigint",
890
+ convert: (bn) => bn.toBigInt()
891
+ },
892
+ {
893
+ from: "string",
894
+ to: "bigint",
895
+ convert: (s) => BigInt(s)
896
+ },
897
+ {
898
+ from: "Array",
899
+ to: "Matrix",
900
+ convert: (a) => {
901
+ const arr = a;
902
+ return {
903
+ rows: arr.length,
904
+ cols: arr[0]?.length ?? 0,
905
+ data: arr.flat(),
906
+ type: "DenseMatrix",
907
+ get: (r, c) => arr[r]?.[c]
908
+ };
909
+ }
910
+ },
911
+ {
912
+ from: "Matrix",
913
+ to: "Array",
914
+ convert: (m) => {
915
+ const matrix = m;
916
+ const result = [];
917
+ for (let i = 0; i < matrix.rows; i++) {
918
+ result[i] = [];
919
+ for (let j = 0; j < matrix.cols; j++) result[i][j] = matrix.get(i, j);
920
+ }
921
+ return result;
922
+ }
923
+ },
924
+ {
925
+ from: "DenseMatrix",
926
+ to: "SparseMatrix",
927
+ convert: (m) => {
928
+ return {
929
+ ...m,
930
+ type: "SparseMatrix"
931
+ };
932
+ }
933
+ }
1022
934
  ];
1023
935
  function createMathTSTyped() {
1024
- const instance = create();
1025
- if (typeof instance.addType === "function") {
1026
- for (const typeDef of MATHTS_TYPES) {
1027
- instance.addType(typeDef);
1028
- }
1029
- } else {
1030
- instance.addTypes(MATHTS_TYPES, "any");
1031
- }
1032
- instance.addConversions(MATHTS_CONVERSIONS);
1033
- return instance;
936
+ const instance = create();
937
+ if (typeof instance.addType === "function") for (const typeDef of MATHTS_TYPES) instance.addType(typeDef);
938
+ else instance.addTypes(MATHTS_TYPES, "any");
939
+ instance.addConversions(MATHTS_CONVERSIONS);
940
+ return instance;
1034
941
  }
1035
- var mathTyped = createMathTSTyped();
942
+ const mathTyped = createMathTSTyped();
1036
943
  var TypeRegistry = class {
1037
- types = /* @__PURE__ */ new Map();
1038
- conversions = /* @__PURE__ */ new Map();
1039
- instance = null;
1040
- /**
1041
- * Register a new type
1042
- */
1043
- registerType(name2, test) {
1044
- this.types.set(name2, { name: name2, test });
1045
- this.instance = null;
1046
- return this;
1047
- }
1048
- /**
1049
- * Register a type conversion
1050
- */
1051
- registerConversion(from, to, convert) {
1052
- const key = `${from}->${to}`;
1053
- this.conversions.set(key, {
1054
- from,
1055
- to,
1056
- convert
1057
- });
1058
- this.instance = null;
1059
- return this;
1060
- }
1061
- /**
1062
- * Check if a type is registered
1063
- */
1064
- hasType(name2) {
1065
- return this.types.has(name2);
1066
- }
1067
- /**
1068
- * Check if a conversion is registered
1069
- */
1070
- hasConversion(from, to) {
1071
- return this.conversions.has(`${from}->${to}`);
1072
- }
1073
- /**
1074
- * Get all registered type names
1075
- */
1076
- getTypeNames() {
1077
- return Array.from(this.types.keys());
1078
- }
1079
- /**
1080
- * Build a typed-function instance from the registry
1081
- */
1082
- build() {
1083
- if (!this.instance) {
1084
- const inst = create();
1085
- inst.addTypes(Array.from(this.types.values()), "any");
1086
- inst.addConversions(Array.from(this.conversions.values()));
1087
- this.instance = inst;
1088
- }
1089
- return this.instance;
1090
- }
1091
- /**
1092
- * Clear all registered types and conversions
1093
- */
1094
- clear() {
1095
- this.types.clear();
1096
- this.conversions.clear();
1097
- this.instance = null;
1098
- }
944
+ types = /* @__PURE__ */ new Map();
945
+ conversions = /* @__PURE__ */ new Map();
946
+ instance = null;
947
+ registerType(name, test) {
948
+ this.types.set(name, {
949
+ name,
950
+ test
951
+ });
952
+ this.instance = null;
953
+ return this;
954
+ }
955
+ registerConversion(from, to, convert) {
956
+ const key = `${from}->${to}`;
957
+ this.conversions.set(key, {
958
+ from,
959
+ to,
960
+ convert
961
+ });
962
+ this.instance = null;
963
+ return this;
964
+ }
965
+ hasType(name) {
966
+ return this.types.has(name);
967
+ }
968
+ hasConversion(from, to) {
969
+ return this.conversions.has(`${from}->${to}`);
970
+ }
971
+ getTypeNames() {
972
+ return Array.from(this.types.keys());
973
+ }
974
+ build() {
975
+ if (!this.instance) {
976
+ const inst = create();
977
+ inst.addTypes(Array.from(this.types.values()), "any");
978
+ inst.addConversions(Array.from(this.conversions.values()));
979
+ this.instance = inst;
980
+ }
981
+ return this.instance;
982
+ }
983
+ clear() {
984
+ this.types.clear();
985
+ this.conversions.clear();
986
+ this.instance = null;
987
+ }
1099
988
  };
1100
- function createTypedFunction(name2, signatures, typedInstance = mathTyped) {
1101
- return typedInstance(name2, signatures);
989
+ function createTypedFunction(name, signatures, typedInstance = mathTyped) {
990
+ return typedInstance(name, signatures);
1102
991
  }
1103
-
1104
- // src/typed/type-bridge.ts
1105
- var registered = false;
992
+ //#endregion
993
+ //#region src/typed/type-bridge.ts
994
+ let registered = false;
1106
995
  function registerNativeTypes() {
1107
- if (registered) return;
1108
- registered = true;
1109
- if (!("isComplex" in Complex.prototype)) {
1110
- Object.defineProperty(Complex.prototype, "isComplex", {
1111
- value: true,
1112
- writable: false,
1113
- enumerable: false,
1114
- configurable: false
1115
- });
1116
- }
1117
- if (!("type" in Complex.prototype)) {
1118
- Object.defineProperty(Complex.prototype, "type", {
1119
- value: "Complex",
1120
- writable: false,
1121
- enumerable: false,
1122
- configurable: false
1123
- });
1124
- }
1125
- if (!("isFraction" in Fraction.prototype)) {
1126
- Object.defineProperty(Fraction.prototype, "isFraction", {
1127
- value: true,
1128
- writable: false,
1129
- enumerable: false,
1130
- configurable: false
1131
- });
1132
- }
1133
- if (!("type" in Fraction.prototype)) {
1134
- Object.defineProperty(Fraction.prototype, "type", {
1135
- value: "Fraction",
1136
- writable: false,
1137
- enumerable: false,
1138
- configurable: false
1139
- });
1140
- }
1141
- if (!("isBigNumber" in BigNumber.prototype)) {
1142
- Object.defineProperty(BigNumber.prototype, "isBigNumber", {
1143
- value: true,
1144
- writable: false,
1145
- enumerable: false,
1146
- configurable: false
1147
- });
1148
- }
1149
- if (!("type" in BigNumber.prototype)) {
1150
- Object.defineProperty(BigNumber.prototype, "type", {
1151
- value: "BigNumber",
1152
- writable: false,
1153
- enumerable: false,
1154
- configurable: false
1155
- });
1156
- }
996
+ if (registered) return;
997
+ registered = true;
998
+ if (!("isComplex" in Complex.prototype)) Object.defineProperty(Complex.prototype, "isComplex", {
999
+ value: true,
1000
+ writable: false,
1001
+ enumerable: false,
1002
+ configurable: false
1003
+ });
1004
+ if (!("type" in Complex.prototype)) Object.defineProperty(Complex.prototype, "type", {
1005
+ value: "Complex",
1006
+ writable: false,
1007
+ enumerable: false,
1008
+ configurable: false
1009
+ });
1010
+ if (!("isFraction" in Fraction.prototype)) Object.defineProperty(Fraction.prototype, "isFraction", {
1011
+ value: true,
1012
+ writable: false,
1013
+ enumerable: false,
1014
+ configurable: false
1015
+ });
1016
+ if (!("type" in Fraction.prototype)) Object.defineProperty(Fraction.prototype, "type", {
1017
+ value: "Fraction",
1018
+ writable: false,
1019
+ enumerable: false,
1020
+ configurable: false
1021
+ });
1022
+ if (!("isBigNumber" in BigNumber.prototype)) Object.defineProperty(BigNumber.prototype, "isBigNumber", {
1023
+ value: true,
1024
+ writable: false,
1025
+ enumerable: false,
1026
+ configurable: false
1027
+ });
1028
+ if (!("type" in BigNumber.prototype)) Object.defineProperty(BigNumber.prototype, "type", {
1029
+ value: "BigNumber",
1030
+ writable: false,
1031
+ enumerable: false,
1032
+ configurable: false
1033
+ });
1157
1034
  }
1158
-
1159
- // src/factory/factory.ts
1160
- var DEFAULT_CONFIG = {
1161
- precision: 64,
1162
- matrix: "Matrix",
1163
- number: "number",
1164
- randomSeed: null,
1165
- epsilon: 1e-12,
1166
- preferredBackend: "auto",
1167
- wasmThreshold: 1e3,
1168
- gpuThreshold: 1e5,
1169
- parallelEnabled: true,
1170
- parallelThreshold: 5e4
1035
+ //#endregion
1036
+ //#region src/factory/factory.ts
1037
+ const DEFAULT_CONFIG = {
1038
+ precision: 64,
1039
+ matrix: "Matrix",
1040
+ number: "number",
1041
+ randomSeed: null,
1042
+ epsilon: 1e-12,
1043
+ preferredBackend: "auto",
1044
+ wasmThreshold: 1e3,
1045
+ gpuThreshold: 1e5,
1046
+ parallelEnabled: true,
1047
+ parallelThreshold: 5e4
1171
1048
  };
1172
1049
  var FunctionRegistry = class {
1173
- factories = /* @__PURE__ */ new Map();
1174
- instances = /* @__PURE__ */ new Map();
1175
- dependencies;
1176
- creating = /* @__PURE__ */ new Set();
1177
- constructor(config = {}, typed2 = mathTyped) {
1178
- this.dependencies = {
1179
- config: { ...DEFAULT_CONFIG, ...config },
1180
- typed: typed2
1181
- };
1182
- }
1183
- /**
1184
- * Register a factory function
1185
- */
1186
- register(factory2) {
1187
- this.factories.set(factory2.name, factory2);
1188
- }
1189
- /**
1190
- * Register multiple factory functions
1191
- */
1192
- registerAll(factories) {
1193
- for (const factory2 of factories) {
1194
- this.register(factory2);
1195
- }
1196
- }
1197
- /**
1198
- * Get or create a function by name
1199
- */
1200
- get(name2) {
1201
- const existing = this.instances.get(name2);
1202
- if (existing) return existing;
1203
- if (this.creating.has(name2)) {
1204
- throw new Error(`Circular dependency detected: ${name2}`);
1205
- }
1206
- const factory2 = this.factories.get(name2);
1207
- if (!factory2) {
1208
- throw new Error(`Unknown function: ${name2}`);
1209
- }
1210
- this.creating.add(name2);
1211
- try {
1212
- const deps = { ...this.dependencies };
1213
- for (const depName of factory2.dependencies) {
1214
- if (depName === "config" || depName === "typed") continue;
1215
- deps[depName] = this.get(depName);
1216
- }
1217
- const fn = factory2.factory(deps);
1218
- this.instances.set(name2, fn);
1219
- this.dependencies[name2] = fn;
1220
- return fn;
1221
- } finally {
1222
- this.creating.delete(name2);
1223
- }
1224
- }
1225
- /**
1226
- * Check if a function is registered
1227
- */
1228
- has(name2) {
1229
- return this.factories.has(name2);
1230
- }
1231
- /**
1232
- * Get all registered function names
1233
- */
1234
- names() {
1235
- return Array.from(this.factories.keys());
1236
- }
1237
- /**
1238
- * Update configuration
1239
- */
1240
- updateConfig(config) {
1241
- this.dependencies.config = { ...this.dependencies.config, ...config };
1242
- this.instances.clear();
1243
- }
1244
- /**
1245
- * Get current configuration
1246
- */
1247
- getConfig() {
1248
- return { ...this.dependencies.config };
1249
- }
1050
+ factories = /* @__PURE__ */ new Map();
1051
+ instances = /* @__PURE__ */ new Map();
1052
+ dependencies;
1053
+ creating = /* @__PURE__ */ new Set();
1054
+ constructor(config = {}, typed = mathTyped) {
1055
+ this.dependencies = {
1056
+ config: {
1057
+ ...DEFAULT_CONFIG,
1058
+ ...config
1059
+ },
1060
+ typed
1061
+ };
1062
+ }
1063
+ register(factory) {
1064
+ this.factories.set(factory.name, factory);
1065
+ }
1066
+ registerAll(factories) {
1067
+ for (const factory of factories) this.register(factory);
1068
+ }
1069
+ get(name) {
1070
+ const existing = this.instances.get(name);
1071
+ if (existing) return existing;
1072
+ if (this.creating.has(name)) throw new Error(`Circular dependency detected: ${name}`);
1073
+ const factory = this.factories.get(name);
1074
+ if (!factory) throw new Error(`Unknown function: ${name}`);
1075
+ this.creating.add(name);
1076
+ try {
1077
+ const deps = { ...this.dependencies };
1078
+ for (const depName of factory.dependencies) {
1079
+ if (depName === "config" || depName === "typed") continue;
1080
+ deps[depName] = this.get(depName);
1081
+ }
1082
+ const fn = factory.factory(deps);
1083
+ this.instances.set(name, fn);
1084
+ this.dependencies[name] = fn;
1085
+ return fn;
1086
+ } finally {
1087
+ this.creating.delete(name);
1088
+ }
1089
+ }
1090
+ has(name) {
1091
+ return this.factories.has(name);
1092
+ }
1093
+ names() {
1094
+ return Array.from(this.factories.keys());
1095
+ }
1096
+ updateConfig(config) {
1097
+ this.dependencies.config = {
1098
+ ...this.dependencies.config,
1099
+ ...config
1100
+ };
1101
+ this.instances.clear();
1102
+ }
1103
+ getConfig() {
1104
+ return { ...this.dependencies.config };
1105
+ }
1250
1106
  };
1251
- function createFactory(name2, dependencies2, factory2) {
1252
- return { name: name2, dependencies: dependencies2, factory: factory2 };
1107
+ function createFactory(name, dependencies, factory) {
1108
+ return {
1109
+ name,
1110
+ dependencies,
1111
+ factory
1112
+ };
1253
1113
  }
1254
- var registry = new FunctionRegistry();
1255
- var math = {
1256
- /**
1257
- * Get a registered function
1258
- */
1259
- get: (name2) => registry.get(name2),
1260
- /**
1261
- * Register a factory function
1262
- */
1263
- register: (factory2) => registry.register(factory2),
1264
- /**
1265
- * Get configuration
1266
- */
1267
- config: () => registry.getConfig(),
1268
- /**
1269
- * Update configuration
1270
- */
1271
- configure: (config) => registry.updateConfig(config)
1114
+ const registry = new FunctionRegistry();
1115
+ const math = {
1116
+ get: (name) => registry.get(name),
1117
+ register: (factory) => registry.register(factory),
1118
+ config: () => registry.getConfig(),
1119
+ configure: (config) => registry.updateConfig(config)
1272
1120
  };
1273
-
1274
- // src/numeric/stable.ts
1275
- var PAIRWISE_BLOCK = 128;
1121
+ //#endregion
1122
+ //#region src/numeric/stable.ts
1123
+ const PAIRWISE_BLOCK = 128;
1276
1124
  function pairwiseSum(xs, start = 0, end = xs.length) {
1277
- const n = end - start;
1278
- if (n <= PAIRWISE_BLOCK) {
1279
- let s0 = 0;
1280
- let s1 = 0;
1281
- let s2 = 0;
1282
- let s3 = 0;
1283
- let s4 = 0;
1284
- let s5 = 0;
1285
- let s6 = 0;
1286
- let s7 = 0;
1287
- let i = start;
1288
- const limit = start + (n - n % 8);
1289
- for (; i < limit; i += 8) {
1290
- s0 += xs[i];
1291
- s1 += xs[i + 1];
1292
- s2 += xs[i + 2];
1293
- s3 += xs[i + 3];
1294
- s4 += xs[i + 4];
1295
- s5 += xs[i + 5];
1296
- s6 += xs[i + 6];
1297
- s7 += xs[i + 7];
1298
- }
1299
- let tail = 0;
1300
- for (; i < end; i++) tail += xs[i];
1301
- return s0 + s1 + (s2 + s3) + (s4 + s5 + (s6 + s7)) + tail;
1302
- }
1303
- const half = (n >> 1) - (n >> 1) % 8;
1304
- return pairwiseSum(xs, start, start + half) + pairwiseSum(xs, start + half, end);
1125
+ const n = end - start;
1126
+ if (n <= PAIRWISE_BLOCK) {
1127
+ let s0 = 0;
1128
+ let s1 = 0;
1129
+ let s2 = 0;
1130
+ let s3 = 0;
1131
+ let s4 = 0;
1132
+ let s5 = 0;
1133
+ let s6 = 0;
1134
+ let s7 = 0;
1135
+ let i = start;
1136
+ const limit = start + (n - n % 8);
1137
+ for (; i < limit; i += 8) {
1138
+ s0 += xs[i];
1139
+ s1 += xs[i + 1];
1140
+ s2 += xs[i + 2];
1141
+ s3 += xs[i + 3];
1142
+ s4 += xs[i + 4];
1143
+ s5 += xs[i + 5];
1144
+ s6 += xs[i + 6];
1145
+ s7 += xs[i + 7];
1146
+ }
1147
+ let tail = 0;
1148
+ for (; i < end; i++) tail += xs[i];
1149
+ return s0 + s1 + (s2 + s3) + (s4 + s5 + (s6 + s7)) + tail;
1150
+ }
1151
+ const half = (n >> 1) - (n >> 1) % 8;
1152
+ return pairwiseSum(xs, start, start + half) + pairwiseSum(xs, start + half, end);
1305
1153
  }
1306
1154
  function neumaierSum(xs) {
1307
- let sum = 0;
1308
- let c = 0;
1309
- for (let i = 0; i < xs.length; i++) {
1310
- const x = xs[i];
1311
- const t = sum + x;
1312
- c += Math.abs(sum) >= Math.abs(x) ? sum - t + x : x - t + sum;
1313
- sum = t;
1314
- }
1315
- return sum + c;
1155
+ let sum = 0;
1156
+ let c = 0;
1157
+ for (let i = 0; i < xs.length; i++) {
1158
+ const x = xs[i];
1159
+ const t = sum + x;
1160
+ c += Math.abs(sum) >= Math.abs(x) ? sum - t + x : x - t + sum;
1161
+ sum = t;
1162
+ }
1163
+ return sum + c;
1316
1164
  }
1317
1165
  function norm2(xs) {
1318
- let scale = 0;
1319
- let ssq = 1;
1320
- for (let i = 0; i < xs.length; i++) {
1321
- const x = xs[i];
1322
- if (x === 0) continue;
1323
- if (Number.isNaN(x)) return NaN;
1324
- const ax = Math.abs(x);
1325
- if (scale < ax) {
1326
- const r = scale / ax;
1327
- ssq = 1 + ssq * r * r;
1328
- scale = ax;
1329
- } else {
1330
- const r = ax / scale;
1331
- ssq += r * r;
1332
- }
1333
- }
1334
- return scale === 0 ? 0 : scale * Math.sqrt(ssq);
1166
+ let scale = 0;
1167
+ let ssq = 1;
1168
+ for (let i = 0; i < xs.length; i++) {
1169
+ const x = xs[i];
1170
+ if (x === 0) continue;
1171
+ if (Number.isNaN(x)) return NaN;
1172
+ const ax = Math.abs(x);
1173
+ if (scale < ax) {
1174
+ const r = scale / ax;
1175
+ ssq = 1 + ssq * r * r;
1176
+ scale = ax;
1177
+ } else {
1178
+ const r = ax / scale;
1179
+ ssq += r * r;
1180
+ }
1181
+ }
1182
+ return scale === 0 ? 0 : scale * Math.sqrt(ssq);
1335
1183
  }
1336
1184
  function pairwiseDot(a, b, start = 0, end = a.length) {
1337
- const n = end - start;
1338
- if (n <= PAIRWISE_BLOCK) {
1339
- let s0 = 0;
1340
- let s1 = 0;
1341
- let s2 = 0;
1342
- let s3 = 0;
1343
- let s4 = 0;
1344
- let s5 = 0;
1345
- let s6 = 0;
1346
- let s7 = 0;
1347
- let i = start;
1348
- const limit = start + (n - n % 8);
1349
- for (; i < limit; i += 8) {
1350
- s0 += a[i] * b[i];
1351
- s1 += a[i + 1] * b[i + 1];
1352
- s2 += a[i + 2] * b[i + 2];
1353
- s3 += a[i + 3] * b[i + 3];
1354
- s4 += a[i + 4] * b[i + 4];
1355
- s5 += a[i + 5] * b[i + 5];
1356
- s6 += a[i + 6] * b[i + 6];
1357
- s7 += a[i + 7] * b[i + 7];
1358
- }
1359
- let tail = 0;
1360
- for (; i < end; i++) tail += a[i] * b[i];
1361
- return s0 + s1 + (s2 + s3) + (s4 + s5 + (s6 + s7)) + tail;
1362
- }
1363
- const half = (n >> 1) - (n >> 1) % 8;
1364
- return pairwiseDot(a, b, start, start + half) + pairwiseDot(a, b, start + half, end);
1185
+ const n = end - start;
1186
+ if (n <= PAIRWISE_BLOCK) {
1187
+ let s0 = 0;
1188
+ let s1 = 0;
1189
+ let s2 = 0;
1190
+ let s3 = 0;
1191
+ let s4 = 0;
1192
+ let s5 = 0;
1193
+ let s6 = 0;
1194
+ let s7 = 0;
1195
+ let i = start;
1196
+ const limit = start + (n - n % 8);
1197
+ for (; i < limit; i += 8) {
1198
+ s0 += a[i] * b[i];
1199
+ s1 += a[i + 1] * b[i + 1];
1200
+ s2 += a[i + 2] * b[i + 2];
1201
+ s3 += a[i + 3] * b[i + 3];
1202
+ s4 += a[i + 4] * b[i + 4];
1203
+ s5 += a[i + 5] * b[i + 5];
1204
+ s6 += a[i + 6] * b[i + 6];
1205
+ s7 += a[i + 7] * b[i + 7];
1206
+ }
1207
+ let tail = 0;
1208
+ for (; i < end; i++) tail += a[i] * b[i];
1209
+ return s0 + s1 + (s2 + s3) + (s4 + s5 + (s6 + s7)) + tail;
1210
+ }
1211
+ const half = (n >> 1) - (n >> 1) % 8;
1212
+ return pairwiseDot(a, b, start, start + half) + pairwiseDot(a, b, start + half, end);
1365
1213
  }
1366
1214
  function scaledDistance(a, b) {
1367
- let scale = 0;
1368
- let ssq = 1;
1369
- for (let i = 0; i < a.length; i++) {
1370
- const d = a[i] - b[i];
1371
- if (d === 0) continue;
1372
- if (Number.isNaN(d)) return NaN;
1373
- const ad = Math.abs(d);
1374
- if (scale < ad) {
1375
- const r = scale / ad;
1376
- ssq = 1 + ssq * r * r;
1377
- scale = ad;
1378
- } else {
1379
- const r = ad / scale;
1380
- ssq += r * r;
1381
- }
1382
- }
1383
- return scale === 0 ? 0 : scale * Math.sqrt(ssq);
1215
+ let scale = 0;
1216
+ let ssq = 1;
1217
+ for (let i = 0; i < a.length; i++) {
1218
+ const d = a[i] - b[i];
1219
+ if (d === 0) continue;
1220
+ if (Number.isNaN(d)) return NaN;
1221
+ const ad = Math.abs(d);
1222
+ if (scale < ad) {
1223
+ const r = scale / ad;
1224
+ ssq = 1 + ssq * r * r;
1225
+ scale = ad;
1226
+ } else {
1227
+ const r = ad / scale;
1228
+ ssq += r * r;
1229
+ }
1230
+ }
1231
+ return scale === 0 ? 0 : scale * Math.sqrt(ssq);
1384
1232
  }
1385
1233
  function sumSquaredDeviations(xs) {
1386
- const n = xs.length;
1387
- if (n < 2) return 0;
1388
- const mean = pairwiseSum(xs) / n;
1389
- const { sumD, sumDD } = pairwiseDeviationSums(xs, mean, 0, n);
1390
- const corrected = sumDD - sumD * sumD / n;
1391
- return corrected < 0 ? 0 : corrected;
1234
+ const n = xs.length;
1235
+ if (n < 2) return 0;
1236
+ const { sumD, sumDD } = pairwiseDeviationSums(xs, pairwiseSum(xs) / n, 0, n);
1237
+ const corrected = sumDD - sumD * sumD / n;
1238
+ return corrected < 0 ? 0 : corrected;
1392
1239
  }
1393
1240
  function pairwiseDeviationSums(xs, mean, start, end) {
1394
- const n = end - start;
1395
- if (n <= PAIRWISE_BLOCK) {
1396
- let d0 = 0, d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0, d7 = 0;
1397
- let q0 = 0, q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0, q6 = 0, q7 = 0;
1398
- let i = start;
1399
- const limit = start + (n - n % 8);
1400
- for (; i < limit; i += 8) {
1401
- const a0 = xs[i] - mean;
1402
- const a1 = xs[i + 1] - mean;
1403
- const a2 = xs[i + 2] - mean;
1404
- const a3 = xs[i + 3] - mean;
1405
- const a4 = xs[i + 4] - mean;
1406
- const a5 = xs[i + 5] - mean;
1407
- const a6 = xs[i + 6] - mean;
1408
- const a7 = xs[i + 7] - mean;
1409
- d0 += a0;
1410
- q0 += a0 * a0;
1411
- d1 += a1;
1412
- q1 += a1 * a1;
1413
- d2 += a2;
1414
- q2 += a2 * a2;
1415
- d3 += a3;
1416
- q3 += a3 * a3;
1417
- d4 += a4;
1418
- q4 += a4 * a4;
1419
- d5 += a5;
1420
- q5 += a5 * a5;
1421
- d6 += a6;
1422
- q6 += a6 * a6;
1423
- d7 += a7;
1424
- q7 += a7 * a7;
1425
- }
1426
- let tailD = 0;
1427
- let tailDD = 0;
1428
- for (; i < end; i++) {
1429
- const a = xs[i] - mean;
1430
- tailD += a;
1431
- tailDD += a * a;
1432
- }
1433
- return {
1434
- sumD: d0 + d1 + (d2 + d3) + (d4 + d5 + (d6 + d7)) + tailD,
1435
- sumDD: q0 + q1 + (q2 + q3) + (q4 + q5 + (q6 + q7)) + tailDD
1436
- };
1437
- }
1438
- const half = (n >> 1) - (n >> 1) % 8;
1439
- const left = pairwiseDeviationSums(xs, mean, start, start + half);
1440
- const right = pairwiseDeviationSums(xs, mean, start + half, end);
1441
- return { sumD: left.sumD + right.sumD, sumDD: left.sumDD + right.sumDD };
1241
+ const n = end - start;
1242
+ if (n <= PAIRWISE_BLOCK) {
1243
+ let d0 = 0, d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0, d7 = 0;
1244
+ let q0 = 0, q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0, q6 = 0, q7 = 0;
1245
+ let i = start;
1246
+ const limit = start + (n - n % 8);
1247
+ for (; i < limit; i += 8) {
1248
+ const a0 = xs[i] - mean;
1249
+ const a1 = xs[i + 1] - mean;
1250
+ const a2 = xs[i + 2] - mean;
1251
+ const a3 = xs[i + 3] - mean;
1252
+ const a4 = xs[i + 4] - mean;
1253
+ const a5 = xs[i + 5] - mean;
1254
+ const a6 = xs[i + 6] - mean;
1255
+ const a7 = xs[i + 7] - mean;
1256
+ d0 += a0;
1257
+ q0 += a0 * a0;
1258
+ d1 += a1;
1259
+ q1 += a1 * a1;
1260
+ d2 += a2;
1261
+ q2 += a2 * a2;
1262
+ d3 += a3;
1263
+ q3 += a3 * a3;
1264
+ d4 += a4;
1265
+ q4 += a4 * a4;
1266
+ d5 += a5;
1267
+ q5 += a5 * a5;
1268
+ d6 += a6;
1269
+ q6 += a6 * a6;
1270
+ d7 += a7;
1271
+ q7 += a7 * a7;
1272
+ }
1273
+ let tailD = 0;
1274
+ let tailDD = 0;
1275
+ for (; i < end; i++) {
1276
+ const a = xs[i] - mean;
1277
+ tailD += a;
1278
+ tailDD += a * a;
1279
+ }
1280
+ return {
1281
+ sumD: d0 + d1 + (d2 + d3) + (d4 + d5 + (d6 + d7)) + tailD,
1282
+ sumDD: q0 + q1 + (q2 + q3) + (q4 + q5 + (q6 + q7)) + tailDD
1283
+ };
1284
+ }
1285
+ const half = (n >> 1) - (n >> 1) % 8;
1286
+ const left = pairwiseDeviationSums(xs, mean, start, start + half);
1287
+ const right = pairwiseDeviationSums(xs, mean, start + half, end);
1288
+ return {
1289
+ sumD: left.sumD + right.sumD,
1290
+ sumDD: left.sumDD + right.sumDD
1291
+ };
1442
1292
  }
1443
1293
  function neumaierCumsum(xs, out) {
1444
- let sum = 0;
1445
- let c = 0;
1446
- for (let i = 0; i < xs.length; i++) {
1447
- const x = xs[i];
1448
- const t = sum + x;
1449
- c += Math.abs(sum) >= Math.abs(x) ? sum - t + x : x - t + sum;
1450
- sum = t;
1451
- out[i] = sum + c;
1452
- }
1294
+ let sum = 0;
1295
+ let c = 0;
1296
+ for (let i = 0; i < xs.length; i++) {
1297
+ const x = xs[i];
1298
+ const t = sum + x;
1299
+ c += Math.abs(sum) >= Math.abs(x) ? sum - t + x : x - t + sum;
1300
+ sum = t;
1301
+ out[i] = sum + c;
1302
+ }
1453
1303
  }
1454
-
1455
- // src/index.ts
1456
- var VERSION = "0.18.1";
1457
- export {
1458
- ALL_UNITS,
1459
- BASE_UNITS,
1460
- BEST_PREFIXES,
1461
- BIGNUMBER_E,
1462
- BIGNUMBER_LN10,
1463
- BIGNUMBER_LN2,
1464
- BIGNUMBER_NEG_ONE,
1465
- BIGNUMBER_ONE,
1466
- BIGNUMBER_PI,
1467
- BIGNUMBER_TEN,
1468
- BIGNUMBER_ZERO,
1469
- BigNumber,
1470
- COMPLEX_NEG_ONE,
1471
- COMPLEX_ONE,
1472
- COMPLEX_ZERO,
1473
- Complex,
1474
- DEFAULT_CONFIG,
1475
- DERIVED_UNITS,
1476
- DIMENSIONLESS,
1477
- DUAL_UNARY_RULES,
1478
- DimensionMismatchError,
1479
- Dual,
1480
- E,
1481
- FRACTION_HALF,
1482
- FRACTION_NEG_ONE,
1483
- FRACTION_ONE,
1484
- FRACTION_QUARTER,
1485
- FRACTION_THIRD,
1486
- FRACTION_ZERO,
1487
- Fraction,
1488
- FunctionRegistry,
1489
- I,
1490
- LN10,
1491
- LN2,
1492
- LN2_EXACT_SCALE,
1493
- LOG10E,
1494
- LOG2E,
1495
- MATHTS_CONVERSIONS,
1496
- MATHTS_TYPES,
1497
- NAMED_IRRATIONALS,
1498
- NAMED_SCALES,
1499
- PHI,
1500
- PI,
1501
- PI_EXACT_SCALE,
1502
- Range,
1503
- SI_DIMENSION_LENGTH,
1504
- SI_PREFIXES,
1505
- SQRT1_2,
1506
- SQRT2,
1507
- TAU,
1508
- TypeRegistry,
1509
- UNIT_ALIASES,
1510
- UNIT_DIMENSION_LENGTH,
1511
- UNIT_EXACT_SCALE,
1512
- UNIT_PREFIX_SETS,
1513
- UNIT_ROWS,
1514
- UNIT_ROW_ALIASES,
1515
- Unit,
1516
- UnitParseError,
1517
- VERSION,
1518
- abs,
1519
- addExactScales,
1520
- addScalar,
1521
- binaryExactScale,
1522
- clearExactScaleNumberCache,
1523
- create,
1524
- createFactory,
1525
- createMathTSTyped,
1526
- createRangeClass,
1527
- createTypedFunction,
1528
- decimalExactScale,
1529
- dim,
1530
- divideExactScales,
1531
- divideScalar,
1532
- equal,
1533
- exactScaleNumberCacheSize,
1534
- exactScaleOf,
1535
- exactScaleToNumber,
1536
- exactScalesEqual,
1537
- fix,
1538
- formatExactScale,
1539
- fromSiDimensionVector,
1540
- fromSiDimensions,
1541
- getPrefix,
1542
- getUnitDef,
1543
- getUnitPrefix,
1544
- getUnitRow,
1545
- initTypedWasm,
1546
- irrationalPower,
1547
- isArray,
1548
- isBigInt2 as isBigInt,
1549
- isBigNumber2 as isBigNumber,
1550
- isBoolean,
1551
- isComplex,
1552
- isDenseMatrix,
1553
- isDual,
1554
- isFraction,
1555
- isFunction,
1556
- isMatrix,
1557
- isNull,
1558
- isNumber,
1559
- isNumeric,
1560
- isObject,
1561
- isRationalScale,
1562
- isSparseMatrix,
1563
- isString,
1564
- isTypedWasmAvailable,
1565
- isUndefined,
1566
- isUnit2 as isUnit,
1567
- isUnit as isUnitValue,
1568
- math,
1569
- mathTyped,
1570
- multiplyExactScales,
1571
- multiplyScalar,
1572
- namedExactScale,
1573
- namedIrrationalScale,
1574
- neumaierCumsum,
1575
- neumaierSum,
1576
- norm2,
1577
- number,
1578
- pairwiseDot,
1579
- pairwiseSum,
1580
- pow,
1581
- powerExactScale,
1582
- ratioExactScale,
1583
- readScaleExpression,
1584
- readUnitScale,
1585
- registerNativeTypes,
1586
- registry,
1587
- round,
1588
- scaledDistance,
1589
- subtractScalar,
1590
- sumSquaredDeviations,
1591
- toSiDimensionVector,
1592
- toSiDimensions,
1593
- typed,
1594
- unitPrefixExactScale,
1595
- unitRowExactOffset,
1596
- unitRowExactScale,
1597
- unitRowValue
1598
- };
1304
+ //#endregion
1305
+ //#region src/index.ts
1306
+ const VERSION = "0.19.0";
1307
+ //#endregion
1308
+ export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, BigNumber, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, Dual, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, Fraction, FunctionRegistry, I, LN10, LN2, LN2_EXACT_SCALE, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, NAMED_IRRATIONALS, NAMED_SCALES, PHI, PI, PI_EXACT_SCALE, Range, SI_DIMENSION_LENGTH, SI_PREFIXES, SQRT1_2, SQRT2, TAU, TypeRegistry, UNIT_ALIASES, UNIT_DIMENSION_LENGTH, UNIT_EXACT_SCALE, UNIT_PREFIX_SETS, UNIT_ROWS, UNIT_ROW_ALIASES, Unit, UnitParseError, VERSION, abs, addExactScales, addScalar, binaryExactScale, clearExactScaleNumberCache, create, createFactory, createMathTSTyped, createRangeClass, createTypedFunction, decimalExactScale, dim, divideExactScales, divideScalar, equal, exactScaleNumberCacheSize, exactScaleOf, exactScaleToNumber, exactScalesEqual, fix, formatExactScale, fromSiDimensionVector, fromSiDimensions, getPrefix, getUnitDef, getUnitPrefix, getUnitRow, initTypedWasm, irrationalPower, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isRationalScale, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, isUnit$1 as isUnitValue, math, mathTyped, multiplyExactScales, multiplyScalar, namedExactScale, namedIrrationalScale, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, powerExactScale, ratioExactScale, readScaleExpression, readUnitScale, registerNativeTypes, registry, round, scaledDistance, subtractScalar, sumSquaredDeviations, toSiDimensionVector, toSiDimensions, typed, unitPrefixExactScale, unitRowExactOffset, unitRowExactScale, unitRowValue };