@danielsimonjr/mathts-functions 0.57.0 → 0.59.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
@@ -101,7 +101,7 @@ __export(typed_exports, {
101
101
  cholesky: () => cholesky,
102
102
  coefficientList: () => coefficientList,
103
103
  collect: () => collect,
104
- combinations: () => combinations,
104
+ combinations: () => combinations2,
105
105
  combinationsWithRep: () => combinationsWithRep,
106
106
  combine: () => combine,
107
107
  compare: () => compare,
@@ -131,7 +131,7 @@ __export(typed_exports, {
131
131
  dagostinoTest: () => dagostinoTest,
132
132
  dct: () => dct,
133
133
  deepEqual: () => deepEqual,
134
- degree: () => degree,
134
+ degree: () => degree2,
135
135
  delaunayTriangulation: () => delaunayTriangulation,
136
136
  differences: () => differences,
137
137
  digamma: () => digamma,
@@ -454,7 +454,7 @@ __export(typed_exports, {
454
454
  studentTTest: () => studentTTest,
455
455
  studentTTestPaired: () => studentTTestPaired,
456
456
  subfactorial: () => subfactorial,
457
- substitute: () => substitute,
457
+ substitute: () => substitute2,
458
458
  subtract: () => subtract,
459
459
  sum: () => sum,
460
460
  symbolicPartialDerivative: () => symbolicPartialDerivative,
@@ -3341,8 +3341,8 @@ function resetGpuFft() {
3341
3341
  resources = null;
3342
3342
  }
3343
3343
  function stageUniformsFor(res, n, inverse) {
3344
- const key = `${n}:${inverse ? 1 : 0}`;
3345
- const cached = res.stageUniforms.get(key);
3344
+ const key2 = `${n}:${inverse ? 1 : 0}`;
3345
+ const cached = res.stageUniforms.get(key2);
3346
3346
  if (cached) return cached;
3347
3347
  const stages = Math.log2(n);
3348
3348
  const bufs = [];
@@ -3355,7 +3355,7 @@ function stageUniformsFor(res, n, inverse) {
3355
3355
  res.device.queue.writeBuffer(u, 0, new Uint32Array([n, ns, inverse ? 1 : 0, 0]));
3356
3356
  bufs.push(u);
3357
3357
  }
3358
- res.stageUniforms.set(key, bufs);
3358
+ res.stageUniforms.set(key2, bufs);
3359
3359
  return bufs;
3360
3360
  }
3361
3361
  var isPowerOf2 = (n) => n > 0 && (n & n - 1) === 0;
@@ -8957,14 +8957,14 @@ function voronoiDiagram(points, bounds) {
8957
8957
  const uy = ((a[0] * a[0] + a[1] * a[1]) * (c[0] - b[0]) + (b[0] * b[0] + b[1] * b[1]) * (a[0] - c[0]) + (c[0] * c[0] + c[1] * c[1]) * (b[0] - a[0])) / D;
8958
8958
  const cx = Math.max(bounds[0], Math.min(bounds[2], ux));
8959
8959
  const cy = Math.max(bounds[1], Math.min(bounds[3], uy));
8960
- const key = tri.slice().sort().join(",");
8961
- triCircumcenters.set(key, vertices.length);
8960
+ const key2 = tri.slice().sort().join(",");
8961
+ triCircumcenters.set(key2, vertices.length);
8962
8962
  vertices.push([cx, cy]);
8963
8963
  }
8964
8964
  const regions = Array.from({ length: points.length }, () => []);
8965
8965
  for (const tri of triangles) {
8966
- const key = tri.slice().sort().join(",");
8967
- const vIdx = triCircumcenters.get(key);
8966
+ const key2 = tri.slice().sort().join(",");
8967
+ const vIdx = triCircumcenters.get(key2);
8968
8968
  if (vIdx !== void 0) {
8969
8969
  for (const pIdx of tri) {
8970
8970
  if (!regions[pIdx].includes(vIdx)) {
@@ -9444,9 +9444,9 @@ function discriminantDispatch(p) {
9444
9444
  return discriminantJS(p);
9445
9445
  }
9446
9446
  var WASM_POLY_FIT_THRESHOLD = 1024;
9447
- function polyFitJS(xs, ys, degree2, buildRow) {
9447
+ function polyFitJS(xs, ys, degree3, buildRow) {
9448
9448
  const n = xs.length;
9449
- const k = degree2 + 1;
9449
+ const k = degree3 + 1;
9450
9450
  if (n < k) return null;
9451
9451
  const A = [];
9452
9452
  for (let i = 0; i < n; i++) {
@@ -9523,22 +9523,22 @@ function legendreBasisRow(x, k) {
9523
9523
  }
9524
9524
  return row2;
9525
9525
  }
9526
- function polyFitJSFallback(xs, ys, degree2) {
9527
- const result = polyFitJS(xs, ys, degree2, powerBasisRow);
9526
+ function polyFitJSFallback(xs, ys, degree3) {
9527
+ const result = polyFitJS(xs, ys, degree3, powerBasisRow);
9528
9528
  if (!result) throw new Error("polyFit: rank-deficient or insufficient data");
9529
9529
  return result;
9530
9530
  }
9531
- function chebFitJSFallback(xs, ys, degree2) {
9532
- const result = polyFitJS(xs, ys, degree2, chebBasisRow);
9531
+ function chebFitJSFallback(xs, ys, degree3) {
9532
+ const result = polyFitJS(xs, ys, degree3, chebBasisRow);
9533
9533
  if (!result) throw new Error("chebyshevFit: rank-deficient or insufficient data");
9534
9534
  return result;
9535
9535
  }
9536
- function legendreFitJSFallback(xs, ys, degree2) {
9537
- const result = polyFitJS(xs, ys, degree2, legendreBasisRow);
9536
+ function legendreFitJSFallback(xs, ys, degree3) {
9537
+ const result = polyFitJS(xs, ys, degree3, legendreBasisRow);
9538
9538
  if (!result) throw new Error("legendreFit: rank-deficient or insufficient data");
9539
9539
  return result;
9540
9540
  }
9541
- function fitDispatch(xs, ys, degree2, asName, jsFallback) {
9541
+ function fitDispatch(xs, ys, degree3, asName, jsFallback) {
9542
9542
  if (xs.length !== ys.length) throw new Error("xs and ys must have the same length");
9543
9543
  if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
9544
9544
  const wasm = getWasm();
@@ -9549,26 +9549,26 @@ function fitDispatch(xs, ys, degree2, asName, jsFallback) {
9549
9549
  [xs, ys],
9550
9550
  (mod3, [hx, hy]) => asReadReturnedF64(
9551
9551
  mod3,
9552
- mod3[asName](hx, hy, degree2)
9552
+ mod3[asName](hx, hy, degree3)
9553
9553
  )
9554
9554
  );
9555
- if (out && out.length === degree2 + 1 && out.every((v) => Number.isFinite(v))) {
9555
+ if (out && out.length === degree3 + 1 && out.every((v) => Number.isFinite(v))) {
9556
9556
  return out;
9557
9557
  }
9558
9558
  } catch {
9559
9559
  }
9560
9560
  }
9561
9561
  }
9562
- return jsFallback(xs, ys, degree2);
9562
+ return jsFallback(xs, ys, degree3);
9563
9563
  }
9564
- function polyFitDispatch(xs, ys, degree2) {
9565
- return fitDispatch(xs, ys, degree2, "poly_fit_f64", polyFitJSFallback);
9564
+ function polyFitDispatch(xs, ys, degree3) {
9565
+ return fitDispatch(xs, ys, degree3, "poly_fit_f64", polyFitJSFallback);
9566
9566
  }
9567
- function chebFitDispatch(xs, ys, degree2) {
9568
- return fitDispatch(xs, ys, degree2, "cheb_fit_f64", chebFitJSFallback);
9567
+ function chebFitDispatch(xs, ys, degree3) {
9568
+ return fitDispatch(xs, ys, degree3, "cheb_fit_f64", chebFitJSFallback);
9569
9569
  }
9570
- function legendreFitDispatch(xs, ys, degree2) {
9571
- return fitDispatch(xs, ys, degree2, "legendre_fit_f64", legendreFitJSFallback);
9570
+ function legendreFitDispatch(xs, ys, degree3) {
9571
+ return fitDispatch(xs, ys, degree3, "legendre_fit_f64", legendreFitJSFallback);
9572
9572
  }
9573
9573
 
9574
9574
  // src/typed/polynomial-ideal.ts
@@ -9582,10 +9582,10 @@ function cmpPowers(a, b) {
9582
9582
  function normalize(p) {
9583
9583
  const byKey = /* @__PURE__ */ new Map();
9584
9584
  for (const t of p) {
9585
- const key = t.powers.join(",");
9586
- const existing = byKey.get(key);
9585
+ const key2 = t.powers.join(",");
9586
+ const existing = byKey.get(key2);
9587
9587
  if (existing) existing.coeff += t.coeff;
9588
- else byKey.set(key, { coeff: t.coeff, powers: [...t.powers] });
9588
+ else byKey.set(key2, { coeff: t.coeff, powers: [...t.powers] });
9589
9589
  }
9590
9590
  return [...byKey.values()].filter((t) => Math.abs(t.coeff) > EPS).sort((a, b) => cmpPowers(b.powers, a.powers));
9591
9591
  }
@@ -9824,6 +9824,1295 @@ function polyToString(p, vars) {
9824
9824
  return terms.join(" + ").replace(/\+ -/g, "- ");
9825
9825
  }
9826
9826
 
9827
+ // src/typed/factorization/integer-poly.ts
9828
+ function trim(p) {
9829
+ let n = p.length;
9830
+ while (n > 0 && p[n - 1] === 0n) {
9831
+ n -= 1;
9832
+ }
9833
+ return p.slice(0, n);
9834
+ }
9835
+ function degree(p) {
9836
+ const t = trim(p);
9837
+ return t.length - 1;
9838
+ }
9839
+ function lc(p) {
9840
+ const t = trim(p);
9841
+ return t.length === 0 ? 0n : t[t.length - 1];
9842
+ }
9843
+ function isZero(p) {
9844
+ return trim(p).length === 0;
9845
+ }
9846
+ function add2(a, b) {
9847
+ const n = Math.max(a.length, b.length);
9848
+ const out = new Array(n);
9849
+ for (let i = 0; i < n; i += 1) {
9850
+ const av = i < a.length ? a[i] : 0n;
9851
+ const bv = i < b.length ? b[i] : 0n;
9852
+ out[i] = av + bv;
9853
+ }
9854
+ return trim(out);
9855
+ }
9856
+ function sub(a, b) {
9857
+ const n = Math.max(a.length, b.length);
9858
+ const out = new Array(n);
9859
+ for (let i = 0; i < n; i += 1) {
9860
+ const av = i < a.length ? a[i] : 0n;
9861
+ const bv = i < b.length ? b[i] : 0n;
9862
+ out[i] = av - bv;
9863
+ }
9864
+ return trim(out);
9865
+ }
9866
+ function neg(a) {
9867
+ return a.map((c) => -c);
9868
+ }
9869
+ function mul(a, b) {
9870
+ const ta = trim(a);
9871
+ const tb = trim(b);
9872
+ if (ta.length === 0 || tb.length === 0) {
9873
+ return [];
9874
+ }
9875
+ const out = new Array(ta.length + tb.length - 1).fill(0n);
9876
+ for (let i = 0; i < ta.length; i += 1) {
9877
+ const ai = ta[i];
9878
+ if (ai === 0n) continue;
9879
+ for (let j = 0; j < tb.length; j += 1) {
9880
+ out[i + j] += ai * tb[j];
9881
+ }
9882
+ }
9883
+ return trim(out);
9884
+ }
9885
+ function scalarMul(p, k) {
9886
+ return trim(p.map((c) => c * k));
9887
+ }
9888
+ function bigintGcd(a, b) {
9889
+ let x = a < 0n ? -a : a;
9890
+ let y = b < 0n ? -b : b;
9891
+ while (y !== 0n) {
9892
+ const t = x % y;
9893
+ x = y;
9894
+ y = t;
9895
+ }
9896
+ return x;
9897
+ }
9898
+ function content(p) {
9899
+ const t = trim(p);
9900
+ let g = 0n;
9901
+ for (const c of t) {
9902
+ g = bigintGcd(g, c);
9903
+ }
9904
+ return g;
9905
+ }
9906
+ function primitivePart(p) {
9907
+ const t = trim(p);
9908
+ if (t.length === 0) {
9909
+ return [];
9910
+ }
9911
+ const g = content(t);
9912
+ const divided = g === 0n ? t.slice() : t.map((c) => c / g);
9913
+ const reduced = trim(divided);
9914
+ if (reduced.length === 0) {
9915
+ return reduced;
9916
+ }
9917
+ return lc(reduced) < 0n ? neg(reduced) : reduced;
9918
+ }
9919
+ function exactDivide(a, b) {
9920
+ const tb = trim(b);
9921
+ if (tb.length === 0) {
9922
+ return null;
9923
+ }
9924
+ let rem = trim(a);
9925
+ if (rem.length === 0) {
9926
+ return [];
9927
+ }
9928
+ const db = tb.length - 1;
9929
+ const lb = tb[db];
9930
+ const dq = rem.length - 1 - db;
9931
+ if (dq < 0) {
9932
+ return null;
9933
+ }
9934
+ const q = new Array(dq + 1).fill(0n);
9935
+ while (!isZero(rem) && degree(rem) >= db) {
9936
+ const dr = degree(rem);
9937
+ const lrRaw = rem[dr];
9938
+ if (lrRaw % lb !== 0n) {
9939
+ return null;
9940
+ }
9941
+ const coeff = lrRaw / lb;
9942
+ const shift = dr - db;
9943
+ q[shift] = coeff;
9944
+ for (let i = 0; i <= db; i += 1) {
9945
+ rem[shift + i] -= coeff * tb[i];
9946
+ }
9947
+ rem = trim(rem);
9948
+ }
9949
+ if (!isZero(rem)) {
9950
+ return null;
9951
+ }
9952
+ return trim(q);
9953
+ }
9954
+ function derivative(p) {
9955
+ const t = trim(p);
9956
+ if (t.length <= 1) {
9957
+ return [];
9958
+ }
9959
+ const out = new Array(t.length - 1);
9960
+ for (let i = 1; i < t.length; i += 1) {
9961
+ out[i - 1] = t[i] * BigInt(i);
9962
+ }
9963
+ return trim(out);
9964
+ }
9965
+ function pseudoRemainder(a, b) {
9966
+ const db = degree(b);
9967
+ const lb = lc(b);
9968
+ let rem = trim(a);
9969
+ while (!isZero(rem) && degree(rem) >= db) {
9970
+ const dr = degree(rem);
9971
+ const lr = rem[dr];
9972
+ const shift = dr - db;
9973
+ const scaled = rem.map((c) => c * lb);
9974
+ for (let i = 0; i <= db; i += 1) {
9975
+ scaled[shift + i] -= lr * b[i];
9976
+ }
9977
+ rem = trim(scaled);
9978
+ }
9979
+ return rem;
9980
+ }
9981
+ function polyGcdZ(a, b) {
9982
+ let x = primitivePart(a);
9983
+ let y = primitivePart(b);
9984
+ if (isZero(x)) {
9985
+ return y;
9986
+ }
9987
+ if (isZero(y)) {
9988
+ return x;
9989
+ }
9990
+ if (degree(x) < degree(y)) {
9991
+ [x, y] = [y, x];
9992
+ }
9993
+ while (!isZero(y)) {
9994
+ const r = pseudoRemainder(x, y);
9995
+ x = y;
9996
+ y = primitivePart(r);
9997
+ }
9998
+ return x;
9999
+ }
10000
+ function isqrt(n) {
10001
+ if (n < 0n) {
10002
+ throw new RangeError("isqrt: negative input");
10003
+ }
10004
+ if (n < 2n) {
10005
+ return n;
10006
+ }
10007
+ let x0 = n;
10008
+ let x1 = (x0 + 1n) / 2n;
10009
+ while (x1 < x0) {
10010
+ x0 = x1;
10011
+ x1 = (x0 + n / x0) / 2n;
10012
+ }
10013
+ return x0;
10014
+ }
10015
+ function landauMignotte(p) {
10016
+ const t = trim(p);
10017
+ const d = t.length - 1;
10018
+ if (d < 0) {
10019
+ return 1n;
10020
+ }
10021
+ const n = BigInt(d + 1);
10022
+ const lcAbs = t[d] < 0n ? -t[d] : t[d];
10023
+ const powerOfTwo = 1n << BigInt(d);
10024
+ const sq = isqrt(n);
10025
+ const sqrtCeil = sq * sq === n ? sq : sq + 1n;
10026
+ const bound = sqrtCeil * powerOfTwo * (lcAbs === 0n ? 1n : lcAbs);
10027
+ return bound > 0n ? bound : 1n;
10028
+ }
10029
+ function modSymmetric(p, m) {
10030
+ const half = m / 2n;
10031
+ return p.map((c) => {
10032
+ let r = c % m;
10033
+ if (r < 0n) {
10034
+ r += m;
10035
+ }
10036
+ if (r > half) {
10037
+ r -= m;
10038
+ }
10039
+ return r;
10040
+ });
10041
+ }
10042
+
10043
+ // src/typed/factorization/finite-field.ts
10044
+ function modP(a, p) {
10045
+ const r = a % p;
10046
+ return r < 0n ? r + p : r;
10047
+ }
10048
+ function reduceModP(a, p) {
10049
+ return trim(a.map((c) => modP(c, p)));
10050
+ }
10051
+ function addP(a, b, p) {
10052
+ const n = Math.max(a.length, b.length);
10053
+ const out = new Array(n);
10054
+ for (let i = 0; i < n; i += 1) {
10055
+ const av = i < a.length ? a[i] : 0n;
10056
+ const bv = i < b.length ? b[i] : 0n;
10057
+ out[i] = modP(av + bv, p);
10058
+ }
10059
+ return trim(out);
10060
+ }
10061
+ function subP(a, b, p) {
10062
+ const n = Math.max(a.length, b.length);
10063
+ const out = new Array(n);
10064
+ for (let i = 0; i < n; i += 1) {
10065
+ const av = i < a.length ? a[i] : 0n;
10066
+ const bv = i < b.length ? b[i] : 0n;
10067
+ out[i] = modP(av - bv, p);
10068
+ }
10069
+ return trim(out);
10070
+ }
10071
+ function mulP(a, b, p) {
10072
+ const ta = trim(a);
10073
+ const tb = trim(b);
10074
+ if (ta.length === 0 || tb.length === 0) {
10075
+ return [];
10076
+ }
10077
+ const out = new Array(ta.length + tb.length - 1).fill(0n);
10078
+ for (let i = 0; i < ta.length; i += 1) {
10079
+ const ai = ta[i];
10080
+ if (ai === 0n) continue;
10081
+ for (let j = 0; j < tb.length; j += 1) {
10082
+ out[i + j] = modP(out[i + j] + ai * tb[j], p);
10083
+ }
10084
+ }
10085
+ return trim(out);
10086
+ }
10087
+ function invModP(a, p) {
10088
+ const ar = modP(a, p);
10089
+ if (ar === 0n) {
10090
+ throw new RangeError("invModP: 0 has no modular inverse");
10091
+ }
10092
+ let oldR = ar;
10093
+ let r = p;
10094
+ let oldS = 1n;
10095
+ let s = 0n;
10096
+ while (r !== 0n) {
10097
+ const q = oldR / r;
10098
+ [oldR, r] = [r, oldR - q * r];
10099
+ [oldS, s] = [s, oldS - q * s];
10100
+ }
10101
+ return modP(oldS, p);
10102
+ }
10103
+ function makeMonicP(a, p) {
10104
+ const t = reduceModP(a, p);
10105
+ if (isZero(t)) {
10106
+ return [];
10107
+ }
10108
+ const inv3 = invModP(lc(t), p);
10109
+ return trim(t.map((c) => modP(c * inv3, p)));
10110
+ }
10111
+ function divmodP(a, b, p) {
10112
+ const tb = reduceModP(b, p);
10113
+ if (isZero(tb)) {
10114
+ throw new RangeError("divmodP: division by the zero polynomial");
10115
+ }
10116
+ const db = degree(tb);
10117
+ const invLb = invModP(lc(tb), p);
10118
+ let rem = reduceModP(a, p);
10119
+ const dq = degree(rem) - db;
10120
+ const q = dq >= 0 ? new Array(dq + 1).fill(0n) : [];
10121
+ while (!isZero(rem) && degree(rem) >= db) {
10122
+ const dr = degree(rem);
10123
+ const shift = dr - db;
10124
+ const coeff = modP(rem[dr] * invLb, p);
10125
+ q[shift] = coeff;
10126
+ for (let i = 0; i <= db; i += 1) {
10127
+ rem[shift + i] = modP(rem[shift + i] - coeff * tb[i], p);
10128
+ }
10129
+ rem = trim(rem);
10130
+ }
10131
+ return { q: trim(q), r: rem };
10132
+ }
10133
+ function gcdP(a, b, p) {
10134
+ let x = reduceModP(a, p);
10135
+ let y = reduceModP(b, p);
10136
+ if (isZero(x)) {
10137
+ return makeMonicP(y, p);
10138
+ }
10139
+ if (isZero(y)) {
10140
+ return makeMonicP(x, p);
10141
+ }
10142
+ while (!isZero(y)) {
10143
+ const { r } = divmodP(x, y, p);
10144
+ x = y;
10145
+ y = r;
10146
+ }
10147
+ return makeMonicP(x, p);
10148
+ }
10149
+ function powModPolyP(base, e, mod3, p) {
10150
+ if (e < 0n) {
10151
+ throw new RangeError("powModPolyP: negative exponent not supported");
10152
+ }
10153
+ let result = [1n];
10154
+ let b = divmodP(base, mod3, p).r;
10155
+ let exp2 = e;
10156
+ while (exp2 > 0n) {
10157
+ if (exp2 & 1n) {
10158
+ result = divmodP(mulP(result, b, p), mod3, p).r;
10159
+ }
10160
+ b = divmodP(mulP(b, b, p), mod3, p).r;
10161
+ exp2 >>= 1n;
10162
+ }
10163
+ return reduceModP(result, p);
10164
+ }
10165
+ var X_POLY = [0n, 1n];
10166
+ function distinctDegreeFactor(f, p) {
10167
+ const result = [];
10168
+ let v = makeMonicP(f, p);
10169
+ if (degree(v) <= 0) {
10170
+ return result;
10171
+ }
10172
+ let w = divmodP(X_POLY, v, p).r;
10173
+ let i = 1;
10174
+ while (degree(v) >= 2 * i) {
10175
+ w = powModPolyP(w, p, v, p);
10176
+ const g = gcdP(v, subP(w, X_POLY, p), p);
10177
+ if (degree(g) > 0) {
10178
+ result.push({ deg: i, prod: g });
10179
+ v = divmodP(v, g, p).q;
10180
+ w = divmodP(w, v, p).r;
10181
+ }
10182
+ i += 1;
10183
+ }
10184
+ if (degree(v) > 0) {
10185
+ result.push({ deg: degree(v), prod: v });
10186
+ }
10187
+ return result;
10188
+ }
10189
+ function* trialPolys(p) {
10190
+ let deg = 1;
10191
+ while (true) {
10192
+ const count2 = p ** BigInt(deg);
10193
+ for (let k = 0n; k < count2; k += 1n) {
10194
+ const poly = new Array(deg + 1);
10195
+ let kk = k;
10196
+ for (let idx = 0; idx < deg; idx += 1) {
10197
+ poly[idx] = kk % p;
10198
+ kk /= p;
10199
+ }
10200
+ poly[deg] = 1n;
10201
+ yield trim(poly);
10202
+ }
10203
+ deg += 1;
10204
+ }
10205
+ }
10206
+ function edSplit(f, d, p, out) {
10207
+ if (degree(f) === d) {
10208
+ out.push(f);
10209
+ return;
10210
+ }
10211
+ const trials = trialPolys(p);
10212
+ while (true) {
10213
+ const next = trials.next();
10214
+ if (next.done) {
10215
+ return;
10216
+ }
10217
+ const t = next.value;
10218
+ let g;
10219
+ if (p === 2n) {
10220
+ let trace3 = [];
10221
+ let cur = divmodP(t, f, p).r;
10222
+ for (let i = 0; i < d; i += 1) {
10223
+ trace3 = addP(trace3, cur, p);
10224
+ cur = divmodP(mulP(cur, cur, p), f, p).r;
10225
+ }
10226
+ g = gcdP(f, trace3, p);
10227
+ } else {
10228
+ const e = (p ** BigInt(d) - 1n) / 2n;
10229
+ const h = powModPolyP(t, e, f, p);
10230
+ g = gcdP(f, subP(h, [1n], p), p);
10231
+ }
10232
+ const dg = degree(g);
10233
+ if (dg > 0 && dg < degree(f)) {
10234
+ edSplit(g, d, p, out);
10235
+ edSplit(divmodP(f, g, p).q, d, p, out);
10236
+ return;
10237
+ }
10238
+ }
10239
+ }
10240
+ function equalDegreeFactor(f, d, p) {
10241
+ const out = [];
10242
+ edSplit(makeMonicP(f, p), d, p, out);
10243
+ return out;
10244
+ }
10245
+ function factorModP(f, p) {
10246
+ const fm = makeMonicP(f, p);
10247
+ const d = degree(fm);
10248
+ if (d <= 0) {
10249
+ return [];
10250
+ }
10251
+ if (d === 1) {
10252
+ return [fm];
10253
+ }
10254
+ const factors = [];
10255
+ for (const { deg, prod: prod2 } of distinctDegreeFactor(fm, p)) {
10256
+ if (degree(prod2) === deg) {
10257
+ factors.push(prod2);
10258
+ } else {
10259
+ for (const g of equalDegreeFactor(prod2, deg, p)) {
10260
+ factors.push(g);
10261
+ }
10262
+ }
10263
+ }
10264
+ return factors;
10265
+ }
10266
+
10267
+ // src/typed/factorization/hensel.ts
10268
+ function reduceIntoRange(poly, m) {
10269
+ const out = poly.map((c) => {
10270
+ const r = c % m;
10271
+ return r < 0n ? r + m : r;
10272
+ });
10273
+ let n = out.length;
10274
+ while (n > 0 && out[n - 1] === 0n) {
10275
+ n -= 1;
10276
+ }
10277
+ return out.slice(0, n);
10278
+ }
10279
+ function scalarExactDiv(poly, m) {
10280
+ return poly.map((c) => c / m);
10281
+ }
10282
+ function productModP(polys, p) {
10283
+ let acc = [1n];
10284
+ for (const g of polys) {
10285
+ acc = mulP(acc, g, p);
10286
+ }
10287
+ return acc;
10288
+ }
10289
+ function bezoutModP(g, h, p) {
10290
+ let oldR = reduceModP(g, p);
10291
+ let r = reduceModP(h, p);
10292
+ let oldS = [1n];
10293
+ let s = [];
10294
+ let oldT = [];
10295
+ let t = [1n];
10296
+ while (!isZero(r)) {
10297
+ const { q } = divmodP(oldR, r, p);
10298
+ const newR = subP(oldR, mulP(q, r, p), p);
10299
+ oldR = r;
10300
+ r = newR;
10301
+ const newS = subP(oldS, mulP(q, s, p), p);
10302
+ oldS = s;
10303
+ s = newS;
10304
+ const newT = subP(oldT, mulP(q, t, p), p);
10305
+ oldT = t;
10306
+ t = newT;
10307
+ }
10308
+ const inv3 = invModP(lc(oldR), p);
10309
+ return {
10310
+ s: mulP(oldS, [inv3], p),
10311
+ t: mulP(oldT, [inv3], p)
10312
+ };
10313
+ }
10314
+ function diophantineModP(c, g, h, s, t, p) {
10315
+ const { q, r: dg } = divmodP(mulP(t, c, p), g, p);
10316
+ const dh = addP(mulP(s, c, p), mulP(q, h, p), p);
10317
+ return { dg, dh };
10318
+ }
10319
+ function henselLiftTwo(f, g, h, p, targetPk) {
10320
+ const gBase = reduceModP(g, p);
10321
+ const hBase = reduceModP(h, p);
10322
+ const { s, t } = bezoutModP(gBase, hBase, p);
10323
+ let bigG = gBase;
10324
+ let bigH = hBase;
10325
+ let mod3 = p;
10326
+ while (mod3 < targetPk) {
10327
+ const nextMod = mod3 * p;
10328
+ const e = sub(f, mul(bigG, bigH));
10329
+ const c = reduceModP(scalarExactDiv(e, mod3), p);
10330
+ const { dg, dh } = diophantineModP(c, gBase, hBase, s, t, p);
10331
+ bigG = reduceIntoRange(add2(bigG, scalarMul(dg, mod3)), nextMod);
10332
+ bigH = reduceIntoRange(add2(bigH, scalarMul(dh, mod3)), nextMod);
10333
+ mod3 = nextMod;
10334
+ }
10335
+ return { g: bigG, h: bigH };
10336
+ }
10337
+ function henselLift(f, factorsModP, p, targetPk) {
10338
+ const n = factorsModP.length;
10339
+ if (n === 0) {
10340
+ return [];
10341
+ }
10342
+ if (n === 1) {
10343
+ return [modSymmetric(f, targetPk)];
10344
+ }
10345
+ const mid = n >> 1;
10346
+ const left = factorsModP.slice(0, mid);
10347
+ const right = factorsModP.slice(mid);
10348
+ const gBase = productModP(left, p);
10349
+ const hBase = productModP(right, p);
10350
+ const { g: bigG, h: bigH } = henselLiftTwo(f, gBase, hBase, p, targetPk);
10351
+ const leftLifted = henselLift(bigG, left, p, targetPk);
10352
+ const rightLifted = henselLift(bigH, right, p, targetPk);
10353
+ return [...leftLifted, ...rightLifted];
10354
+ }
10355
+
10356
+ // src/typed/factorization/square-free.ts
10357
+ function squareFreeDecompose(f) {
10358
+ const p = primitivePart(f);
10359
+ const result = [];
10360
+ const fPrime = derivative(p);
10361
+ const g = polyGcdZ(p, fPrime);
10362
+ const b0 = exactDivide(p, g);
10363
+ const c0 = exactDivide(fPrime, g);
10364
+ if (b0 === null || c0 === null) {
10365
+ throw new Error(
10366
+ "squareFreeDecompose: exact division failed against gcd(f, f'); f/g and f'/g must divide evenly"
10367
+ );
10368
+ }
10369
+ let b = b0;
10370
+ let d = sub(c0, derivative(b));
10371
+ let i = 1;
10372
+ while (degree(b) > 0) {
10373
+ const a = polyGcdZ(b, d);
10374
+ if (degree(a) > 0) {
10375
+ result.push({ factor: primitivePart(a), mult: i });
10376
+ }
10377
+ const nextB = exactDivide(b, a);
10378
+ const nextC = exactDivide(d, a);
10379
+ if (nextB === null || nextC === null) {
10380
+ throw new Error("squareFreeDecompose: exact division b/a or d/a failed");
10381
+ }
10382
+ b = nextB;
10383
+ d = sub(nextC, derivative(b));
10384
+ i += 1;
10385
+ }
10386
+ return result;
10387
+ }
10388
+
10389
+ // src/typed/factorization/zassenhaus.ts
10390
+ var MAX_MODULAR_FACTORS = 24;
10391
+ var PRIME_CANDIDATE_WINDOW = 5;
10392
+ function log3(message) {
10393
+ console.warn(message);
10394
+ }
10395
+ function isPrime(n) {
10396
+ if (n < 2n) return false;
10397
+ if (n < 4n) return true;
10398
+ if (n % 2n === 0n) return false;
10399
+ for (let i = 3n; i * i <= n; i += 2n) {
10400
+ if (n % i === 0n) return false;
10401
+ }
10402
+ return true;
10403
+ }
10404
+ function invMod(a, m) {
10405
+ let oldR = (a % m + m) % m;
10406
+ let r = m;
10407
+ let oldS = 1n;
10408
+ let s = 0n;
10409
+ while (r !== 0n) {
10410
+ const q = oldR / r;
10411
+ [oldR, r] = [r, oldR - q * r];
10412
+ [oldS, s] = [s, oldS - q * s];
10413
+ }
10414
+ if (oldR !== 1n) {
10415
+ throw new RangeError("invMod: arguments are not coprime");
10416
+ }
10417
+ return (oldS % m + m) % m;
10418
+ }
10419
+ function isImageSquareFree(g, p) {
10420
+ const gbar = reduceModP(g, p);
10421
+ const gbarDeriv = reduceModP(derivative(g), p);
10422
+ return degree(gcdP(gbar, gbarDeriv, p)) === 0;
10423
+ }
10424
+ function selectPrime(g, L) {
10425
+ let best = null;
10426
+ let considered = 0;
10427
+ let candidate = 2n;
10428
+ while (considered < PRIME_CANDIDATE_WINDOW) {
10429
+ while (!isPrime(candidate) || L % candidate === 0n || !isImageSquareFree(g, candidate)) {
10430
+ candidate += 1n;
10431
+ }
10432
+ const gp = makeMonicP(reduceModP(g, candidate), candidate);
10433
+ const modFactors = factorModP(gp, candidate);
10434
+ if (best === null || modFactors.length < best.modFactors.length) {
10435
+ best = { p: candidate, modFactors };
10436
+ }
10437
+ considered += 1;
10438
+ candidate += 1n;
10439
+ if (best.modFactors.length === 1) {
10440
+ break;
10441
+ }
10442
+ }
10443
+ return best;
10444
+ }
10445
+ function powAtLeast(p, bound) {
10446
+ let pk = p;
10447
+ while (pk < bound) {
10448
+ pk *= p;
10449
+ }
10450
+ return pk;
10451
+ }
10452
+ function* combinations(n, k) {
10453
+ if (k < 0 || k > n) return;
10454
+ const idx = Array.from({ length: k }, (_, i) => i);
10455
+ while (true) {
10456
+ yield idx.slice();
10457
+ let i = k - 1;
10458
+ while (i >= 0 && idx[i] === n - k + i) {
10459
+ i -= 1;
10460
+ }
10461
+ if (i < 0) return;
10462
+ idx[i] += 1;
10463
+ for (let j = i + 1; j < k; j += 1) {
10464
+ idx[j] = idx[j - 1] + 1;
10465
+ }
10466
+ }
10467
+ }
10468
+ function subsetCandidate(pool, indices, L, Pk) {
10469
+ let prod2 = [1n];
10470
+ for (const i of indices) {
10471
+ prod2 = mul(prod2, pool[i]);
10472
+ }
10473
+ return primitivePart(modSymmetric(scalarMul(prod2, L), Pk));
10474
+ }
10475
+ function factorSquareFree(g) {
10476
+ if (degree(g) <= 0) {
10477
+ return [];
10478
+ }
10479
+ if (degree(g) === 1) {
10480
+ return [primitivePart(g)];
10481
+ }
10482
+ const L = lc(g);
10483
+ const { p, modFactors } = selectPrime(g, L);
10484
+ if (modFactors.length === 1) {
10485
+ return [primitivePart(g)];
10486
+ }
10487
+ if (modFactors.length > MAX_MODULAR_FACTORS) {
10488
+ log3(
10489
+ `factorUnivariateZ: ${modFactors.length} modular factors exceeds cap ${MAX_MODULAR_FACTORS}; returning square-free part of degree ${degree(g)} unfactored`
10490
+ );
10491
+ return [primitivePart(g)];
10492
+ }
10493
+ const n = BigInt(degree(g));
10494
+ const Labs = L < 0n ? -L : L;
10495
+ const bound = 2n * n * Labs * landauMignotte(g) + 1n;
10496
+ const Pk = powAtLeast(p, bound);
10497
+ const Linv = invMod((L % Pk + Pk) % Pk, Pk);
10498
+ const gMonic = modSymmetric(scalarMul(g, Linv), Pk);
10499
+ const u = henselLift(gMonic, modFactors, p, Pk);
10500
+ const found = [];
10501
+ let pool = u.slice();
10502
+ let gCur = g;
10503
+ let Lcur = lc(gCur);
10504
+ let size2 = 1;
10505
+ while (2 * size2 <= pool.length) {
10506
+ let matched = null;
10507
+ for (const indices of combinations(pool.length, size2)) {
10508
+ const cand = subsetCandidate(pool, indices, Lcur, Pk);
10509
+ if (degree(cand) < 1) {
10510
+ continue;
10511
+ }
10512
+ if (exactDivide(gCur, cand) !== null) {
10513
+ matched = { cand, indices };
10514
+ break;
10515
+ }
10516
+ }
10517
+ if (matched === null) {
10518
+ size2 += 1;
10519
+ continue;
10520
+ }
10521
+ const quotient = exactDivide(gCur, matched.cand);
10522
+ if (quotient === null) {
10523
+ throw new Error("factorUnivariateZ: recombination divisor stopped dividing");
10524
+ }
10525
+ found.push(primitivePart(matched.cand));
10526
+ gCur = quotient;
10527
+ Lcur = lc(gCur);
10528
+ const drop = new Set(matched.indices);
10529
+ pool = pool.filter((_, i) => !drop.has(i));
10530
+ }
10531
+ if (degree(gCur) > 0) {
10532
+ found.push(primitivePart(gCur));
10533
+ }
10534
+ return found;
10535
+ }
10536
+ function comparePolys(a, b) {
10537
+ const da = degree(a);
10538
+ const db = degree(b);
10539
+ if (da !== db) {
10540
+ return da - db;
10541
+ }
10542
+ const ta = trim(a);
10543
+ const tb = trim(b);
10544
+ for (let i = 0; i < ta.length; i += 1) {
10545
+ if (ta[i] !== tb[i]) {
10546
+ return ta[i] < tb[i] ? -1 : 1;
10547
+ }
10548
+ }
10549
+ return 0;
10550
+ }
10551
+ function factorUnivariateZ(f) {
10552
+ const tf = trim(f);
10553
+ if (isZero(tf)) {
10554
+ return { constant: 0n, factors: [] };
10555
+ }
10556
+ if (tf.length === 1) {
10557
+ return { constant: tf[0], factors: [] };
10558
+ }
10559
+ const cont = content(tf);
10560
+ const sign3 = lc(tf) < 0n ? -1n : 1n;
10561
+ const constant = cont * sign3;
10562
+ const prim = primitivePart(tf);
10563
+ if (degree(prim) === 1) {
10564
+ return { constant, factors: [{ poly: prim, mult: 1 }] };
10565
+ }
10566
+ const factors = [];
10567
+ for (const { factor: g, mult } of squareFreeDecompose(prim)) {
10568
+ for (const irreducible of factorSquareFree(g)) {
10569
+ factors.push({ poly: irreducible, mult });
10570
+ }
10571
+ }
10572
+ factors.sort((a, b) => comparePolys(a.poly, b.poly));
10573
+ return { constant, factors };
10574
+ }
10575
+
10576
+ // src/typed/factorization/multi-poly.ts
10577
+ function key(exps) {
10578
+ return exps.join(",");
10579
+ }
10580
+ function unkey(k) {
10581
+ if (k === "") {
10582
+ return [];
10583
+ }
10584
+ return k.split(",").map((s) => Number(s));
10585
+ }
10586
+ function fromTerms(vars, entries) {
10587
+ const terms = /* @__PURE__ */ new Map();
10588
+ for (const [exps, coeff] of entries) {
10589
+ if (exps.length !== vars.length) {
10590
+ throw new RangeError("fromTerms: exponent vector length must match vars.length");
10591
+ }
10592
+ const k = key(exps);
10593
+ const prev = terms.get(k) ?? 0n;
10594
+ const next = prev + coeff;
10595
+ if (next === 0n) {
10596
+ terms.delete(k);
10597
+ } else {
10598
+ terms.set(k, next);
10599
+ }
10600
+ }
10601
+ return { vars: vars.slice(), terms };
10602
+ }
10603
+ function degreeIn(p, varIndex) {
10604
+ let d = -1;
10605
+ for (const k of p.terms.keys()) {
10606
+ const exps = unkey(k);
10607
+ if (exps[varIndex] > d) {
10608
+ d = exps[varIndex];
10609
+ }
10610
+ }
10611
+ return d;
10612
+ }
10613
+ function totalDegree(p) {
10614
+ let d = -1;
10615
+ for (const k of p.terms.keys()) {
10616
+ const exps = unkey(k);
10617
+ const s = exps.reduce((a, b) => a + b, 0);
10618
+ if (s > d) {
10619
+ d = s;
10620
+ }
10621
+ }
10622
+ return d;
10623
+ }
10624
+ function isZero2(p) {
10625
+ return p.terms.size === 0;
10626
+ }
10627
+ function equals(a, b) {
10628
+ if (a.vars.length !== b.vars.length) return false;
10629
+ for (let i = 0; i < a.vars.length; i += 1) {
10630
+ if (a.vars[i] !== b.vars[i]) return false;
10631
+ }
10632
+ if (a.terms.size !== b.terms.size) return false;
10633
+ for (const [k, v] of a.terms) {
10634
+ if (b.terms.get(k) !== v) return false;
10635
+ }
10636
+ return true;
10637
+ }
10638
+ function addMP(a, b) {
10639
+ const terms = new Map(a.terms);
10640
+ for (const [k, v] of b.terms) {
10641
+ const next = (terms.get(k) ?? 0n) + v;
10642
+ if (next === 0n) {
10643
+ terms.delete(k);
10644
+ } else {
10645
+ terms.set(k, next);
10646
+ }
10647
+ }
10648
+ return { vars: a.vars.slice(), terms };
10649
+ }
10650
+ function subMP(a, b) {
10651
+ return addMP(a, negMP(b));
10652
+ }
10653
+ function mulMP(a, b) {
10654
+ const n = a.vars.length;
10655
+ const terms = /* @__PURE__ */ new Map();
10656
+ for (const [ka, ca] of a.terms) {
10657
+ const ea = unkey(ka);
10658
+ for (const [kb, cb] of b.terms) {
10659
+ const eb = unkey(kb);
10660
+ const exps = new Array(n);
10661
+ for (let i = 0; i < n; i += 1) {
10662
+ exps[i] = ea[i] + eb[i];
10663
+ }
10664
+ const k = key(exps);
10665
+ const next = (terms.get(k) ?? 0n) + ca * cb;
10666
+ if (next === 0n) {
10667
+ terms.delete(k);
10668
+ } else {
10669
+ terms.set(k, next);
10670
+ }
10671
+ }
10672
+ }
10673
+ return { vars: a.vars.slice(), terms };
10674
+ }
10675
+ function negMP(p) {
10676
+ const terms = /* @__PURE__ */ new Map();
10677
+ for (const [k, v] of p.terms) {
10678
+ terms.set(k, -v);
10679
+ }
10680
+ return { vars: p.vars.slice(), terms };
10681
+ }
10682
+ function canonicalCompare(expsA, expsB) {
10683
+ const da = expsA.reduce((a, b) => a + b, 0);
10684
+ const db = expsB.reduce((a, b) => a + b, 0);
10685
+ if (da !== db) {
10686
+ return db - da;
10687
+ }
10688
+ for (let i = 0; i < expsA.length; i += 1) {
10689
+ if (expsA[i] !== expsB[i]) {
10690
+ return expsB[i] - expsA[i];
10691
+ }
10692
+ }
10693
+ return 0;
10694
+ }
10695
+ function leadingTerm(p) {
10696
+ let best = null;
10697
+ for (const [k, v] of p.terms) {
10698
+ const exps = unkey(k);
10699
+ if (best === null || canonicalCompare(exps, best.exps) < 0) {
10700
+ best = { exps, coeff: v };
10701
+ }
10702
+ }
10703
+ return best;
10704
+ }
10705
+ function integerContentMP(p) {
10706
+ let g = 0n;
10707
+ for (const v of p.terms.values()) {
10708
+ g = bigintGcd(g, v);
10709
+ }
10710
+ return g;
10711
+ }
10712
+ function primitivePartMP(p) {
10713
+ if (isZero2(p)) {
10714
+ return { vars: p.vars.slice(), terms: /* @__PURE__ */ new Map() };
10715
+ }
10716
+ const g = integerContentMP(p);
10717
+ const terms = /* @__PURE__ */ new Map();
10718
+ for (const [k, v] of p.terms) {
10719
+ terms.set(k, g === 0n ? v : v / g);
10720
+ }
10721
+ const divided = { vars: p.vars.slice(), terms };
10722
+ const lead = leadingTerm(divided);
10723
+ if (lead !== null && lead.coeff < 0n) {
10724
+ return negMP(divided);
10725
+ }
10726
+ return divided;
10727
+ }
10728
+ function multiExactDivide(a, b) {
10729
+ const bLead = leadingTerm(b);
10730
+ if (bLead === null) {
10731
+ return null;
10732
+ }
10733
+ const n = a.vars.length;
10734
+ let remainder = a;
10735
+ const quotientEntries = [];
10736
+ while (!isZero2(remainder)) {
10737
+ const rLead = leadingTerm(remainder);
10738
+ if (rLead === null) {
10739
+ break;
10740
+ }
10741
+ const qExps = new Array(n);
10742
+ for (let i = 0; i < n; i += 1) {
10743
+ const diff2 = rLead.exps[i] - bLead.exps[i];
10744
+ if (diff2 < 0) {
10745
+ return null;
10746
+ }
10747
+ qExps[i] = diff2;
10748
+ }
10749
+ if (rLead.coeff % bLead.coeff !== 0n) {
10750
+ return null;
10751
+ }
10752
+ const qCoeff = rLead.coeff / bLead.coeff;
10753
+ quotientEntries.push([qExps, qCoeff]);
10754
+ const qTerm = fromTerms(a.vars, [[qExps, qCoeff]]);
10755
+ remainder = subMP(remainder, mulMP(qTerm, b));
10756
+ }
10757
+ return fromTerms(a.vars, quotientEntries);
10758
+ }
10759
+ function fromAlgebraExpr(expr, vars) {
10760
+ try {
10761
+ const parsed = polyFromExpression(expr, vars);
10762
+ const entries = [];
10763
+ for (const term of parsed) {
10764
+ if (!Number.isInteger(term.coeff)) {
10765
+ return null;
10766
+ }
10767
+ entries.push([term.powers, BigInt(term.coeff)]);
10768
+ }
10769
+ return fromTerms(vars, entries);
10770
+ } catch {
10771
+ return null;
10772
+ }
10773
+ }
10774
+ function toAlgebraString(p) {
10775
+ if (p.terms.size === 0) return "0";
10776
+ const fmt = (c) => c.toString();
10777
+ const terms = [...p.terms].map(([k, v]) => ({ exps: unkey(k), coeff: v })).reverse().map(({ exps, coeff }) => {
10778
+ const varPart = exps.map((e, i) => e === 0 ? "" : e === 1 ? p.vars[i] : `${p.vars[i]}^${e}`).filter(Boolean).join("*");
10779
+ return varPart ? `${fmt(coeff)}*${varPart}` : fmt(coeff);
10780
+ });
10781
+ return terms.join(" + ").replace(/\+ -/g, "- ");
10782
+ }
10783
+
10784
+ // src/typed/factorization/kronecker.ts
10785
+ function substitutionBases(p) {
10786
+ const n = p.vars.length;
10787
+ const bases = new Array(n);
10788
+ let prod2 = 1n;
10789
+ for (let k = 0; k < n; k += 1) {
10790
+ bases[k] = prod2;
10791
+ const d = degreeIn(p, k);
10792
+ const radix = d < 0 ? 1n : BigInt(d) + 1n;
10793
+ prod2 *= radix;
10794
+ }
10795
+ return bases;
10796
+ }
10797
+ function substitutedDegree(p, bases) {
10798
+ let total = 0n;
10799
+ for (let i = 0; i < bases.length; i += 1) {
10800
+ const d = degreeIn(p, i);
10801
+ const dd = d < 0 ? 0n : BigInt(d);
10802
+ total += dd * bases[i];
10803
+ }
10804
+ return total;
10805
+ }
10806
+ function substitute(p, bases) {
10807
+ const maxDeg = substitutedDegree(p, bases);
10808
+ if (maxDeg > BigInt(Number.MAX_SAFE_INTEGER)) {
10809
+ throw new RangeError(
10810
+ `substitute: substituted degree ${maxDeg.toString()} exceeds Number.MAX_SAFE_INTEGER`
10811
+ );
10812
+ }
10813
+ const len = Number(maxDeg) + 1;
10814
+ const out = new Array(len).fill(0n);
10815
+ for (const [k, coeff] of p.terms) {
10816
+ const exps = unkey(k);
10817
+ let deg = 0n;
10818
+ for (let i = 0; i < exps.length; i += 1) {
10819
+ deg += BigInt(exps[i]) * bases[i];
10820
+ }
10821
+ const idx = Number(deg);
10822
+ out[idx] += coeff;
10823
+ }
10824
+ return trim(out);
10825
+ }
10826
+ function backSubstitute(u, bases, degBounds, vars) {
10827
+ const n = bases.length;
10828
+ const trimmed = trim(u);
10829
+ const entries = [];
10830
+ for (let e = 0; e < trimmed.length; e += 1) {
10831
+ const coeff = trimmed[e];
10832
+ if (coeff === 0n) {
10833
+ continue;
10834
+ }
10835
+ let remaining = BigInt(e);
10836
+ const exps = new Array(n);
10837
+ for (let i = 0; i < n; i += 1) {
10838
+ const radix = BigInt(degBounds[i]) + 1n;
10839
+ exps[i] = Number(remaining % radix);
10840
+ remaining = remaining / radix;
10841
+ }
10842
+ if (remaining !== 0n) {
10843
+ return null;
10844
+ }
10845
+ entries.push([exps, coeff]);
10846
+ }
10847
+ return fromTerms(vars, entries);
10848
+ }
10849
+
10850
+ // src/typed/factorization/kronecker-factor.ts
10851
+ var KRONECKER_MAX_DEGREE = 2000n;
10852
+ var MAX_MODULAR_FACTORS2 = 24;
10853
+ function log4(message) {
10854
+ console.warn(message);
10855
+ }
10856
+ function* subsetsOfSize(n, s) {
10857
+ if (s === 0) {
10858
+ yield [];
10859
+ return;
10860
+ }
10861
+ if (s > n) {
10862
+ return;
10863
+ }
10864
+ const idx = Array.from({ length: s }, (_, i) => i);
10865
+ for (; ; ) {
10866
+ yield idx.slice();
10867
+ let i = s - 1;
10868
+ while (i >= 0 && idx[i] === n - s + i) {
10869
+ i -= 1;
10870
+ }
10871
+ if (i < 0) {
10872
+ return;
10873
+ }
10874
+ idx[i] += 1;
10875
+ for (let j = i + 1; j < s; j += 1) {
10876
+ idx[j] = idx[j - 1] + 1;
10877
+ }
10878
+ }
10879
+ }
10880
+ function removeIndices(pool, indices) {
10881
+ const sorted = [...indices].sort((a, b) => b - a);
10882
+ for (const i of sorted) {
10883
+ pool.splice(i, 1);
10884
+ }
10885
+ }
10886
+ function subsetProduct(pool, indices) {
10887
+ let prod2 = [1n];
10888
+ for (const idx of indices) {
10889
+ prod2 = mul(prod2, pool[idx]);
10890
+ }
10891
+ return prod2;
10892
+ }
10893
+ function candidateFor(pool, indices, bases, degBounds, vars) {
10894
+ const back = backSubstitute(subsetProduct(pool, indices), bases, degBounds, vars);
10895
+ if (back === null) {
10896
+ return null;
10897
+ }
10898
+ const cand = primitivePartMP(back);
10899
+ if (totalDegree(cand) < 1) {
10900
+ return null;
10901
+ }
10902
+ return cand;
10903
+ }
10904
+ function findMatchingSubset(pool, s, cand, bases, degBounds, vars) {
10905
+ for (const indices of subsetsOfSize(pool.length, s)) {
10906
+ const c = candidateFor(pool, indices, bases, degBounds, vars);
10907
+ if (c !== null && equals(c, cand)) {
10908
+ return indices;
10909
+ }
10910
+ }
10911
+ return null;
10912
+ }
10913
+ function factorMultivariateKronecker(p) {
10914
+ if (p.vars.length < 2) {
10915
+ return null;
10916
+ }
10917
+ if (isZero2(p) || totalDegree(p) < 1) {
10918
+ return null;
10919
+ }
10920
+ const cont = integerContentMP(p);
10921
+ const pLead = leadingTerm(p);
10922
+ const sign3 = pLead !== null && pLead.coeff < 0n ? -1n : 1n;
10923
+ let constant = cont * sign3;
10924
+ const g = primitivePartMP(p);
10925
+ const bases = substitutionBases(g);
10926
+ if (substitutedDegree(g, bases) > KRONECKER_MAX_DEGREE) {
10927
+ log4(
10928
+ `factorMultivariateKronecker: substituted degree exceeds KRONECKER_MAX_DEGREE=${KRONECKER_MAX_DEGREE.toString()}; declining`
10929
+ );
10930
+ return null;
10931
+ }
10932
+ const image = substitute(g, bases);
10933
+ const uf = factorUnivariateZ(image);
10934
+ const totalCount = uf.factors.reduce((acc, f) => acc + f.mult, 0);
10935
+ if (totalCount <= 1) {
10936
+ return { constant, factors: [{ poly: g, mult: 1 }] };
10937
+ }
10938
+ const pool = [];
10939
+ for (const { poly, mult } of uf.factors) {
10940
+ for (let i = 0; i < mult; i += 1) {
10941
+ pool.push(poly);
10942
+ }
10943
+ }
10944
+ if (pool.length > MAX_MODULAR_FACTORS2) {
10945
+ log4(
10946
+ `factorMultivariateKronecker: ${pool.length} univariate factors exceeds MAX_MODULAR_FACTORS=${MAX_MODULAR_FACTORS2}; returning input whole`
10947
+ );
10948
+ return { constant, factors: [{ poly: g, mult: 1 }] };
10949
+ }
10950
+ const degBounds = g.vars.map((_, i) => degreeIn(g, i));
10951
+ let gCur = g;
10952
+ const found = [];
10953
+ let s = 1;
10954
+ while (pool.length > 0 && 2 * s <= pool.length) {
10955
+ let extracted = false;
10956
+ for (const indices of subsetsOfSize(pool.length, s)) {
10957
+ const cand = candidateFor(pool, indices, bases, degBounds, g.vars);
10958
+ if (cand === null) {
10959
+ continue;
10960
+ }
10961
+ const quotient = multiExactDivide(gCur, cand);
10962
+ if (quotient === null) {
10963
+ continue;
10964
+ }
10965
+ gCur = quotient;
10966
+ removeIndices(pool, indices);
10967
+ let mult = 1;
10968
+ for (; ; ) {
10969
+ const next = multiExactDivide(gCur, cand);
10970
+ if (next === null) {
10971
+ break;
10972
+ }
10973
+ const copy = findMatchingSubset(pool, s, cand, bases, degBounds, g.vars);
10974
+ if (copy === null) {
10975
+ break;
10976
+ }
10977
+ removeIndices(pool, copy);
10978
+ gCur = next;
10979
+ mult += 1;
10980
+ }
10981
+ found.push({ poly: cand, mult });
10982
+ extracted = true;
10983
+ break;
10984
+ }
10985
+ if (extracted) {
10986
+ s = 1;
10987
+ } else {
10988
+ s += 1;
10989
+ }
10990
+ }
10991
+ if (!isZero2(gCur)) {
10992
+ const c = integerContentMP(gCur);
10993
+ const l = leadingTerm(gCur);
10994
+ const sgn = l !== null && l.coeff < 0n ? -1n : 1n;
10995
+ constant *= c * sgn;
10996
+ if (totalDegree(gCur) >= 1) {
10997
+ found.push({ poly: primitivePartMP(gCur), mult: 1 });
10998
+ }
10999
+ }
11000
+ found.sort((a, b) => {
11001
+ const la = leadingTerm(a.poly);
11002
+ const lb = leadingTerm(b.poly);
11003
+ if (la === null || lb === null) {
11004
+ return 0;
11005
+ }
11006
+ return canonicalCompare(la.exps, lb.exps);
11007
+ });
11008
+ return { constant, factors: found };
11009
+ }
11010
+
11011
+ // src/typed/factorization/index.ts
11012
+ var INT_TOLERANCE = 1e-7;
11013
+ function polyToDense(p) {
11014
+ let maxPow = 0;
11015
+ for (const t of p) maxPow = Math.max(maxPow, t.powers[0] ?? 0);
11016
+ const dense = new Array(maxPow + 1).fill(0);
11017
+ for (const t of p) dense[t.powers[0]] += t.coeff;
11018
+ let n = dense.length;
11019
+ while (n > 0 && Math.abs(dense[n - 1]) < 1e-9) n -= 1;
11020
+ return dense.slice(0, n);
11021
+ }
11022
+ function cleanUnivariatePoly(coeffs, v) {
11023
+ const parts = [];
11024
+ for (let i = coeffs.length - 1; i >= 0; i -= 1) {
11025
+ const c = Math.round(coeffs[i]);
11026
+ if (c === 0) continue;
11027
+ const abs2 = Math.abs(c);
11028
+ let term;
11029
+ if (i === 0) {
11030
+ term = String(abs2);
11031
+ } else {
11032
+ const varPart = i === 1 ? v : `${v}^${i}`;
11033
+ term = abs2 === 1 ? varPart : `${abs2}*${varPart}`;
11034
+ }
11035
+ if (parts.length === 0) {
11036
+ parts.push(c < 0 ? `-${term}` : term);
11037
+ } else {
11038
+ parts.push(c < 0 ? "-" : "+", term);
11039
+ }
11040
+ }
11041
+ return parts.length === 0 ? "0" : parts.join(" ");
11042
+ }
11043
+ function renderLinearFactor(poly, v) {
11044
+ const b = poly[0];
11045
+ const a = poly[1];
11046
+ const base = a === 1n ? v : `${a}*${v}`;
11047
+ if (b === 0n) return `(${base})`;
11048
+ return b < 0n ? `(${base} - ${-b})` : `(${base} + ${b})`;
11049
+ }
11050
+ function renderIntPoly(coeffs, v) {
11051
+ const parts = [];
11052
+ for (let i = coeffs.length - 1; i >= 0; i -= 1) {
11053
+ const c = coeffs[i];
11054
+ if (c === 0n) continue;
11055
+ const abs2 = c < 0n ? -c : c;
11056
+ let term;
11057
+ if (i === 0) {
11058
+ term = abs2.toString();
11059
+ } else {
11060
+ const varPart = i === 1 ? v : `${v}^${i}`;
11061
+ term = abs2 === 1n ? varPart : `${abs2}*${varPart}`;
11062
+ }
11063
+ if (parts.length === 0) {
11064
+ parts.push(c < 0n ? `-${term}` : term);
11065
+ } else {
11066
+ parts.push(c < 0n ? "-" : "+", term);
11067
+ }
11068
+ }
11069
+ return parts.length === 0 ? "0" : parts.join(" ");
11070
+ }
11071
+ function renderFactor(poly, v) {
11072
+ if (degree(poly) === 1) return renderLinearFactor(poly, v);
11073
+ return `(${renderIntPoly(poly, v)})`;
11074
+ }
11075
+ function factorPolynomialUnivariate(expr, v) {
11076
+ let dense;
11077
+ try {
11078
+ dense = polyToDense(polyFromExpression(expr, [v]));
11079
+ } catch {
11080
+ return null;
11081
+ }
11082
+ if (dense.length < 2) return null;
11083
+ for (const c of dense) {
11084
+ if (!Number.isFinite(c) || Math.abs(c - Math.round(c)) > INT_TOLERANCE) return null;
11085
+ }
11086
+ const intPoly = dense.map((c) => BigInt(Math.round(c)));
11087
+ const fact = factorUnivariateZ(intPoly);
11088
+ if (fact.factors.length === 1 && fact.factors[0].mult === 1) return null;
11089
+ const parts = [];
11090
+ if (fact.constant !== 1n) parts.push(String(fact.constant));
11091
+ for (const { poly, mult } of fact.factors) {
11092
+ const term = renderFactor(poly, v);
11093
+ for (let i = 0; i < mult; i += 1) parts.push(term);
11094
+ }
11095
+ return parts.join("*");
11096
+ }
11097
+ function renderMultiFactorization(fact) {
11098
+ const parts = [];
11099
+ if (fact.constant !== 1n) parts.push(String(fact.constant));
11100
+ for (const { poly, mult } of fact.factors) {
11101
+ const term = `(${toAlgebraString(poly)})`;
11102
+ parts.push(mult > 1 ? `${term}^${mult}` : term);
11103
+ }
11104
+ return parts.join("*");
11105
+ }
11106
+ function factorMultivariateString(expr, vars, minFactors = 2) {
11107
+ const p = fromAlgebraExpr(expr, vars);
11108
+ if (p === null) return null;
11109
+ const fact = factorMultivariateKronecker(p);
11110
+ if (fact === null) return null;
11111
+ const count2 = fact.factors.reduce((acc, f) => acc + f.mult, 0);
11112
+ if (count2 < minFactors) return null;
11113
+ return renderMultiFactorization(fact);
11114
+ }
11115
+
9827
11116
  // src/typed/algebra.ts
9828
11117
  var MATH_KEYWORDS = /* @__PURE__ */ new Set([
9829
11118
  "sin",
@@ -10002,7 +11291,7 @@ function polynomialRemainder(a, b) {
10002
11291
  const [, remainder] = polyDivMod(a, b);
10003
11292
  return remainder.length === 0 ? [0] : remainder;
10004
11293
  }
10005
- function degree(coeffs) {
11294
+ function degree2(coeffs) {
10006
11295
  const trimmed = trimPoly(coeffs);
10007
11296
  if (trimmed.length === 1 && trimmed[0] === 0) return 0;
10008
11297
  return trimmed.length - 1;
@@ -10062,20 +11351,20 @@ function variables(expr) {
10062
11351
  }
10063
11352
  return [...vars].sort();
10064
11353
  }
10065
- function substitute(expr, vars) {
11354
+ function substitute2(expr, vars) {
10066
11355
  let result = expr;
10067
11356
  const keys = Object.keys(vars).sort((a, b) => b.length - a.length);
10068
- for (const key of keys) {
10069
- const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
11357
+ for (const key2 of keys) {
11358
+ const escaped = key2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10070
11359
  const pattern = new RegExp("\\b" + escaped + "\\b", "g");
10071
- result = result.replace(pattern, vars[key]);
11360
+ result = result.replace(pattern, vars[key2]);
10072
11361
  }
10073
11362
  return result;
10074
11363
  }
10075
11364
  function isNearInt(c) {
10076
11365
  return Math.abs(c - Math.round(c)) < 1e-7;
10077
11366
  }
10078
- function polyToDense(p) {
11367
+ function polyToDense2(p) {
10079
11368
  let maxPow = 0;
10080
11369
  for (const t of p) maxPow = Math.max(maxPow, t.powers[0] ?? 0);
10081
11370
  const dense = new Array(maxPow + 1).fill(0);
@@ -10241,11 +11530,11 @@ function tryMonomialDiffOfSquares(poly, vars) {
10241
11530
  const [t1, t2] = poly;
10242
11531
  if (Math.sign(t1.coeff) === Math.sign(t2.coeff)) return null;
10243
11532
  const pos = t1.coeff > 0 ? t1 : t2;
10244
- const neg = t1.coeff > 0 ? t2 : t1;
11533
+ const neg2 = t1.coeff > 0 ? t2 : t1;
10245
11534
  const cp = perfectIntSqrt(Math.round(pos.coeff));
10246
- const cn = perfectIntSqrt(Math.round(-neg.coeff));
11535
+ const cn = perfectIntSqrt(Math.round(-neg2.coeff));
10247
11536
  if (cp === null || cn === null) return null;
10248
- if (!pos.powers.every((e) => e % 2 === 0) || !neg.powers.every((e) => e % 2 === 0)) return null;
11537
+ if (!pos.powers.every((e) => e % 2 === 0) || !neg2.powers.every((e) => e % 2 === 0)) return null;
10249
11538
  const half = (t) => t.powers.map((e) => e / 2);
10250
11539
  const term = (c, powers) => {
10251
11540
  const mon = monomialString(powers, vars);
@@ -10253,7 +11542,7 @@ function tryMonomialDiffOfSquares(poly, vars) {
10253
11542
  return c === 1 ? mon : `${c}*${mon}`;
10254
11543
  };
10255
11544
  const A = term(cp, half(pos));
10256
- const B = term(cn, half(neg));
11545
+ const B = term(cn, half(neg2));
10257
11546
  return [`(${A} - ${B})`, `(${A} + ${B})`];
10258
11547
  }
10259
11548
  function factorMultivariate(expr, vars) {
@@ -10264,9 +11553,9 @@ function factorMultivariate(expr, vars) {
10264
11553
  return null;
10265
11554
  }
10266
11555
  if (poly.length < 2 || !poly.every((t) => isNearInt(t.coeff))) return null;
10267
- let content = 0;
10268
- for (const t of poly) content = gcdNum(content, Math.abs(Math.round(t.coeff)));
10269
- if (content === 0) return null;
11556
+ let content2 = 0;
11557
+ for (const t of poly) content2 = gcdNum(content2, Math.abs(Math.round(t.coeff)));
11558
+ if (content2 === 0) return null;
10270
11559
  const nVars = vars.length;
10271
11560
  const monPow = new Array(nVars).fill(Infinity);
10272
11561
  for (const t of poly)
@@ -10274,43 +11563,60 @@ function factorMultivariate(expr, vars) {
10274
11563
  const hasMonomial = monPow.some((e) => e > 0);
10275
11564
  const cofactor = normalize(
10276
11565
  poly.map((t) => ({
10277
- coeff: Math.round(t.coeff) / content,
11566
+ coeff: Math.round(t.coeff) / content2,
10278
11567
  powers: t.powers.map((e, i) => e - monPow[i])
10279
11568
  }))
10280
11569
  );
10281
11570
  const dsq = tryMonomialDiffOfSquares(cofactor, vars);
10282
11571
  if (!hasMonomial && !dsq) return null;
10283
11572
  const parts = [];
10284
- if (content > 1) parts.push(String(content));
11573
+ if (content2 > 1) parts.push(String(content2));
10285
11574
  if (hasMonomial) parts.push(monomialString(monPow, vars));
10286
11575
  if (dsq) parts.push(dsq[0], dsq[1]);
10287
11576
  else parts.push(`(${polyToString(cofactor, vars)})`);
10288
- return parts.join("*");
11577
+ const monomialFactors = monPow.reduce((acc, e) => acc + e, 0);
11578
+ const count2 = monomialFactors + (dsq ? 2 : 1);
11579
+ return { text: parts.join("*"), count: count2 };
10289
11580
  }
10290
11581
  function factor(expr) {
10291
11582
  const univariateVars = variables(expr);
10292
11583
  if (univariateVars.length >= 2) {
10293
11584
  const mv = factorMultivariate(expr, univariateVars);
10294
- if (mv !== null) return mv;
11585
+ if (mv === null) {
11586
+ const kron2 = factorMultivariateString(expr, univariateVars);
11587
+ if (kron2 !== null) return kron2;
11588
+ } else {
11589
+ const refined = factorMultivariateString(expr, univariateVars, mv.count + 1);
11590
+ if (refined !== null) return refined;
11591
+ return mv.text;
11592
+ }
10295
11593
  }
10296
11594
  if (univariateVars.length === 1) {
10297
11595
  try {
10298
11596
  const v = univariateVars[0];
10299
- const dense = polyToDense(polyFromExpression(expr, [v]));
10300
- if (degree(dense) >= 2 && dense.every(isNearInt)) {
11597
+ const dense = polyToDense2(polyFromExpression(expr, [v]));
11598
+ if (degree2(dense) >= 2 && dense.every(isNearInt)) {
10301
11599
  const intDense = dense.map((c) => Math.round(c));
10302
11600
  const { roots, remainder } = findRationalLinearFactors(intDense);
10303
11601
  if (roots.length > 0) {
10304
11602
  const factors = roots.map((r) => formatLinearFactor(r, v));
10305
- if (degree(remainder) >= 1) {
11603
+ if (degree2(remainder) >= 2) {
11604
+ const remExpr = cleanUnivariatePoly(remainder, v);
11605
+ const routed2 = factorPolynomialUnivariate(remExpr, v);
11606
+ factors.push(routed2 ?? `(${remExpr})`);
11607
+ } else if (degree2(remainder) >= 1) {
10306
11608
  factors.push(`(${polyToString(denseToPoly(remainder), [v])})`);
10307
11609
  } else if (remainder[0] !== 1) {
10308
11610
  factors.unshift(String(remainder[0]));
10309
11611
  }
10310
11612
  return factors.join("*");
10311
11613
  }
11614
+ const routed = factorPolynomialUnivariate(expr, v);
11615
+ if (routed !== null) return routed;
10312
11616
  }
10313
- } catch {
11617
+ } catch (err) {
11618
+ const message = err instanceof Error ? err.message : String(err);
11619
+ console.warn("factor: univariate engine path failed, falling back: " + message);
10314
11620
  }
10315
11621
  }
10316
11622
  const normalized = expr.replace(/\s*-\s*/g, " + -");
@@ -10400,13 +11706,13 @@ function cancel(expr) {
10400
11706
  if (dens.length > 0) {
10401
11707
  const numStr = nums.length ? nums.join("*") : "1";
10402
11708
  const denStr = dens.join("*");
10403
- const N2 = polyToDense(polyFromExpression(numStr, [v]));
10404
- const D = polyToDense(polyFromExpression(denStr, [v]));
11709
+ const N2 = polyToDense2(polyFromExpression(numStr, [v]));
11710
+ const D = polyToDense2(polyFromExpression(denStr, [v]));
10405
11711
  if (N2.every(isNearInt) && D.every(isNearInt)) {
10406
11712
  const Nint = N2.map((c) => Math.round(c));
10407
11713
  const Dint = D.map((c) => Math.round(c));
10408
11714
  const g = polynomialGCD(Nint, Dint);
10409
- if (degree(g) >= 1) {
11715
+ if (degree2(g) >= 1) {
10410
11716
  let Nq = polynomialQuotient(Nint, g).map((c) => Math.round(c * 1e6) / 1e6);
10411
11717
  let Dq = polynomialQuotient(Dint, g).map((c) => Math.round(c * 1e6) / 1e6);
10412
11718
  let contentGcd = 0;
@@ -10419,7 +11725,7 @@ function cancel(expr) {
10419
11725
  Nq = Nq.map((c) => -c);
10420
11726
  Dq = Dq.map((c) => -c);
10421
11727
  }
10422
- if (degree(Dq) === 0) {
11728
+ if (degree2(Dq) === 0) {
10423
11729
  const c = Dq[0];
10424
11730
  if (c !== 1) Nq = Nq.map((x) => x / c);
10425
11731
  return polyToString(denseToPoly(Nq), [v]);
@@ -10501,23 +11807,23 @@ function apart(expr) {
10501
11807
  if (dens.length > 0) {
10502
11808
  const numStr = nums.length ? nums.join("*") : "1";
10503
11809
  const denStr = dens.join("*");
10504
- const N2 = polyToDense(polyFromExpression(numStr, [v]));
10505
- const D = polyToDense(polyFromExpression(denStr, [v]));
10506
- if (degree(D) >= 1 && N2.every(isNearInt) && D.every(isNearInt)) {
11810
+ const N2 = polyToDense2(polyFromExpression(numStr, [v]));
11811
+ const D = polyToDense2(polyFromExpression(denStr, [v]));
11812
+ if (degree2(D) >= 1 && N2.every(isNearInt) && D.every(isNearInt)) {
10507
11813
  let Nint = N2.map((c) => Math.round(c));
10508
11814
  const Dint = D.map((c) => Math.round(c));
10509
11815
  let quotientPrefix = "";
10510
- if (degree(Nint) >= degree(Dint)) {
11816
+ if (degree2(Nint) >= degree2(Dint)) {
10511
11817
  const q = polynomialQuotient(Nint, Dint);
10512
11818
  const r = polynomialRemainder(Nint, Dint);
10513
- if (degree(r) === 0 && r[0] === 0) {
11819
+ if (degree2(r) === 0 && r[0] === 0) {
10514
11820
  return polyToString(denseToPoly(q), [v]);
10515
11821
  }
10516
11822
  quotientPrefix = `${polyToString(denseToPoly(q), [v])} + `;
10517
11823
  Nint = r.map((c) => Math.round(c));
10518
11824
  }
10519
11825
  const { roots, remainder, repeated } = findRationalLinearFactors(Dint);
10520
- if (!repeated && degree(remainder) === 0 && roots.length === degree(Dint)) {
11826
+ if (!repeated && degree2(remainder) === 0 && roots.length === degree2(Dint)) {
10521
11827
  const Dprime = polyder(Dint);
10522
11828
  const termStrs = roots.map((root2) => {
10523
11829
  const nAtRoot = ratPolyval(Nint, root2);
@@ -10766,7 +12072,7 @@ var typedAlgebra = {
10766
12072
  polynomialLCM,
10767
12073
  polynomialQuotient,
10768
12074
  polynomialRemainder,
10769
- degree,
12075
+ degree: degree2,
10770
12076
  coefficientList,
10771
12077
  discriminant,
10772
12078
  differences,
@@ -10774,7 +12080,7 @@ var typedAlgebra = {
10774
12080
  expand,
10775
12081
  factor,
10776
12082
  collect,
10777
- substitute,
12083
+ substitute: substitute2,
10778
12084
  variables,
10779
12085
  cancel,
10780
12086
  together,
@@ -11420,19 +12726,19 @@ function pchipEndSlope(x0, x1, _x2, _y0, _y1, _y2, d0, d1) {
11420
12726
  }
11421
12727
  return slope;
11422
12728
  }
11423
- function polyFit(xs, ys, degree2) {
11424
- if (xs.length !== ys.length || xs.length < degree2 + 1) {
12729
+ function polyFit(xs, ys, degree3) {
12730
+ if (xs.length !== ys.length || xs.length < degree3 + 1) {
11425
12731
  throw new Error("polyFit requires more data points than polynomial degree");
11426
12732
  }
11427
12733
  if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
11428
12734
  try {
11429
- const result = polyFitDispatch(new Float64Array(xs), new Float64Array(ys), degree2);
12735
+ const result = polyFitDispatch(new Float64Array(xs), new Float64Array(ys), degree3);
11430
12736
  return Array.from(result);
11431
12737
  } catch {
11432
12738
  }
11433
12739
  }
11434
12740
  const n = xs.length;
11435
- const m = degree2 + 1;
12741
+ const m = degree3 + 1;
11436
12742
  const VtV = Array.from({ length: m }, () => new Array(m).fill(0));
11437
12743
  const Vty = new Array(m).fill(0);
11438
12744
  for (let i = 0; i < n; i++) {
@@ -11481,19 +12787,19 @@ function polyFit(xs, ys, degree2) {
11481
12787
  }
11482
12788
  return coeffs;
11483
12789
  }
11484
- function chebyshevFit(xs, ys, degree2) {
11485
- if (xs.length !== ys.length || xs.length < degree2 + 1) {
12790
+ function chebyshevFit(xs, ys, degree3) {
12791
+ if (xs.length !== ys.length || xs.length < degree3 + 1) {
11486
12792
  throw new Error("chebyshevFit requires more data points than polynomial degree");
11487
12793
  }
11488
12794
  if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
11489
12795
  try {
11490
- const result = chebFitDispatch(new Float64Array(xs), new Float64Array(ys), degree2);
12796
+ const result = chebFitDispatch(new Float64Array(xs), new Float64Array(ys), degree3);
11491
12797
  return Array.from(result);
11492
12798
  } catch {
11493
12799
  }
11494
12800
  }
11495
12801
  const n = xs.length;
11496
- const k = degree2 + 1;
12802
+ const k = degree3 + 1;
11497
12803
  function chebRow(x) {
11498
12804
  const row2 = new Array(k);
11499
12805
  let tPrev = 1, tCurr = x;
@@ -11541,19 +12847,19 @@ function chebyshevFit(xs, ys, degree2) {
11541
12847
  }
11542
12848
  return coeffs;
11543
12849
  }
11544
- function legendreFit(xs, ys, degree2) {
11545
- if (xs.length !== ys.length || xs.length < degree2 + 1) {
12850
+ function legendreFit(xs, ys, degree3) {
12851
+ if (xs.length !== ys.length || xs.length < degree3 + 1) {
11546
12852
  throw new Error("legendreFit requires more data points than polynomial degree");
11547
12853
  }
11548
12854
  if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
11549
12855
  try {
11550
- const result = legendreFitDispatch(new Float64Array(xs), new Float64Array(ys), degree2);
12856
+ const result = legendreFitDispatch(new Float64Array(xs), new Float64Array(ys), degree3);
11551
12857
  return Array.from(result);
11552
12858
  } catch {
11553
12859
  }
11554
12860
  }
11555
12861
  const n = xs.length;
11556
- const k = degree2 + 1;
12862
+ const k = degree3 + 1;
11557
12863
  function legRow(x) {
11558
12864
  const row2 = new Array(k);
11559
12865
  let pPrev = 1, pCurr = x;
@@ -12647,7 +13953,7 @@ var createSolveODE = /* @__PURE__ */ factory(
12647
13953
  dependencies,
12648
13954
  ({
12649
13955
  typed: typed3,
12650
- add: add4,
13956
+ add: add5,
12651
13957
  subtract: subtract3,
12652
13958
  multiply: multiply2,
12653
13959
  divide: divide2,
@@ -12866,7 +14172,7 @@ var createSolveODE = /* @__PURE__ */ factory(
12866
14172
  const m = Math.min(coeffs.length, stages.length);
12867
14173
  let acc = multiply2(coeffs[0], stages[0]);
12868
14174
  for (let j = 1; j < m; j++) {
12869
- acc = add4(acc, multiply2(coeffs[j], stages[j]));
14175
+ acc = add5(acc, multiply2(coeffs[j], stages[j]));
12870
14176
  }
12871
14177
  return acc;
12872
14178
  }
@@ -12879,14 +14185,14 @@ var createSolveODE = /* @__PURE__ */ factory(
12879
14185
  h = trimStep(t[n], tf, h);
12880
14186
  k.push(f(t[n], y[n]));
12881
14187
  for (let i = 1; i < c.length; ++i) {
12882
- k.push(f(add4(t[n], multiply2(c[i], h)), add4(y[n], multiply2(h, stageCombo(a[i], k)))));
14188
+ k.push(f(add5(t[n], multiply2(c[i], h)), add5(y[n], multiply2(h, stageCombo(a[i], k)))));
12883
14189
  }
12884
14190
  const errComb = stageCombo(deltaB, k);
12885
14191
  const errArr = Array.isArray(errComb) ? errComb : [errComb];
12886
14192
  const TE = max2(abs2(map3(errArr, (X) => isUnit(X) ? X.value : X)));
12887
14193
  if (TE < tol && tol / TE > 1 / 4) {
12888
- t.push(add4(t[n], h));
12889
- y.push(add4(y[n], multiply2(h, stageCombo(b, k))));
14194
+ t.push(add5(t[n], h));
14195
+ y.push(add5(y[n], multiply2(h, stageCombo(b, k))));
12890
14196
  n++;
12891
14197
  }
12892
14198
  let delta = 0.84 * (tol / TE) ** (1 / 5);
@@ -12980,7 +14286,7 @@ var createSolveODE = /* @__PURE__ */ factory(
12980
14286
  function _createTrimStep(isForwards) {
12981
14287
  const outOfBounds = isForwards ? larger2 : smaller2;
12982
14288
  return function(t, tf, h) {
12983
- const next = add4(t, h);
14289
+ const next = add5(t, h);
12984
14290
  return outOfBounds(next, tf) ? subtract3(tf, t) : h;
12985
14291
  };
12986
14292
  }
@@ -14065,9 +15371,9 @@ function bezierCurve(controlPoints, t) {
14065
15371
  }
14066
15372
  return points[0];
14067
15373
  }
14068
- function bspline(controlPoints, degree2, t) {
15374
+ function bspline(controlPoints, degree3, t) {
14069
15375
  const n = controlPoints.length;
14070
- const p = degree2;
15376
+ const p = degree3;
14071
15377
  if (n <= p) throw new Error("bspline: need more control points than degree");
14072
15378
  const m = n + p + 1;
14073
15379
  const knots = new Array(m);
@@ -14811,8 +16117,8 @@ function residue(p, q) {
14811
16117
  function polyRoots(coeffs) {
14812
16118
  const n = coeffs.length - 1;
14813
16119
  if (n <= 0) return [];
14814
- const lc = coeffs[n];
14815
- const c = coeffs.map((v) => v / lc);
16120
+ const lc2 = coeffs[n];
16121
+ const c = coeffs.map((v) => v / lc2);
14816
16122
  const roots = [];
14817
16123
  for (let i = 0; i < n; i++) {
14818
16124
  const angle = 2 * Math.PI * i / n + 0.4;
@@ -15811,19 +17117,19 @@ function minimumSpanningTree(adj) {
15811
17117
  const n = adj.length;
15812
17118
  if (n === 0) return [];
15813
17119
  const inMST = new Array(n).fill(false);
15814
- const key = new Array(n).fill(Infinity);
17120
+ const key2 = new Array(n).fill(Infinity);
15815
17121
  const parent = new Array(n).fill(-1);
15816
- key[0] = 0;
17122
+ key2[0] = 0;
15817
17123
  for (let count2 = 0; count2 < n; count2++) {
15818
17124
  let u = -1;
15819
17125
  for (let v = 0; v < n; v++) {
15820
- if (!inMST[v] && (u === -1 || key[v] < key[u])) u = v;
17126
+ if (!inMST[v] && (u === -1 || key2[v] < key2[u])) u = v;
15821
17127
  }
15822
- if (u === -1 || key[u] === Infinity) break;
17128
+ if (u === -1 || key2[u] === Infinity) break;
15823
17129
  inMST[u] = true;
15824
17130
  for (let v = 0; v < n; v++) {
15825
- if (adj[u][v] > 0 && !inMST[v] && adj[u][v] < key[v]) {
15826
- key[v] = adj[u][v];
17131
+ if (adj[u][v] > 0 && !inMST[v] && adj[u][v] < key2[v]) {
17132
+ key2[v] = adj[u][v];
15827
17133
  parent[v] = u;
15828
17134
  }
15829
17135
  }
@@ -19557,8 +20863,8 @@ function bigNumberToBase(bn, base, wordSize) {
19557
20863
  return numberToBase(n, base, wordSize);
19558
20864
  }
19559
20865
  function interpolate2(template, values, options) {
19560
- return template.replace(printTemplate, function(original, key) {
19561
- const keys = key.split(".");
20866
+ return template.replace(printTemplate, function(original, key2) {
20867
+ const keys = key2.split(".");
19562
20868
  let value = values[keys.shift()];
19563
20869
  if (value !== void 0 && value.isMatrix) {
19564
20870
  value = value.toArray();
@@ -19704,7 +21010,7 @@ function combinationsExact(n, k) {
19704
21010
  var bernoulli = mathTyped16("bernoulli", {
19705
21011
  number: (n) => bernoulliNumber(n)
19706
21012
  });
19707
- var combinations = mathTyped16("combinations", {
21013
+ var combinations2 = mathTyped16("combinations", {
19708
21014
  "number, number": (n, k) => combinationsExact(n, k)
19709
21015
  });
19710
21016
  var combinationsWithRep = mathTyped16("combinationsWithRep", {
@@ -19834,7 +21140,7 @@ function _pick(arr10, n, weights) {
19834
21140
  }
19835
21141
  var typedProbability = {
19836
21142
  bernoulli,
19837
- combinations,
21143
+ combinations: combinations2,
19838
21144
  combinationsWithRep,
19839
21145
  multinomial,
19840
21146
  permutations,
@@ -20090,7 +21396,7 @@ __export(factories_exports, {
20090
21396
  csch: () => csch,
20091
21397
  ctranspose: () => ctranspose,
20092
21398
  cumsum: () => cumsum,
20093
- derivative: () => derivative,
21399
+ derivative: () => derivative2,
20094
21400
  det: () => det,
20095
21401
  deuteronMass: () => deuteronMass,
20096
21402
  diag: () => diag,
@@ -20204,8 +21510,8 @@ __export(factories_exports, {
20204
21510
  isNegative: () => isNegative,
20205
21511
  isNumeric: () => isNumeric,
20206
21512
  isPositive: () => isPositive,
20207
- isPrime: () => isPrime,
20208
- isZero: () => isZero,
21513
+ isPrime: () => isPrime2,
21514
+ isZero: () => isZero3,
20209
21515
  josephson: () => josephson,
20210
21516
  kldivergence: () => kldivergence,
20211
21517
  klitzing: () => klitzing,
@@ -22171,8 +23477,8 @@ var createPrint = /* @__PURE__ */ factory(
22171
23477
  }
22172
23478
  );
22173
23479
  function _print(template, values, options) {
22174
- return template.replace(printTemplate, function(original, key) {
22175
- const keys = key.split(".");
23480
+ return template.replace(printTemplate, function(original, key2) {
23481
+ const keys = key2.split(".");
22176
23482
  let value = values[keys.shift()];
22177
23483
  if (value !== void 0 && value.isMatrix) {
22178
23484
  value = value.toArray();
@@ -23126,41 +24432,41 @@ var createDot = /* @__PURE__ */ factory(
23126
24432
  const bdt = isMatrix(b) ? b._datatype || b.getDataType() : void 0;
23127
24433
  const aIsColumn = _size(a).length === 2;
23128
24434
  const bIsColumn = _size(b).length === 2;
23129
- let add4 = addScalar2;
23130
- let mul = multiplyScalar2;
24435
+ let add5 = addScalar2;
24436
+ let mul2 = multiplyScalar2;
23131
24437
  if (adt && bdt && adt === bdt && typeof adt === "string" && adt !== "mixed") {
23132
24438
  const dt = adt;
23133
- add4 = typed3.find(addScalar2, [dt, dt]);
23134
- mul = typed3.find(multiplyScalar2, [dt, dt]);
24439
+ add5 = typed3.find(addScalar2, [dt, dt]);
24440
+ mul2 = typed3.find(multiplyScalar2, [dt, dt]);
23135
24441
  }
23136
- if (!aIsColumn && !bIsColumn && add4 === addScalar2 && mul === multiplyScalar2 && _isFlatNumbers(adata) && _isFlatNumbers(bdata)) {
24442
+ if (!aIsColumn && !bIsColumn && add5 === addScalar2 && mul2 === multiplyScalar2 && _isFlatNumbers(adata) && _isFlatNumbers(bdata)) {
23137
24443
  return pairwiseDot2(adata, bdata);
23138
24444
  }
23139
24445
  if (!aIsColumn && !bIsColumn) {
23140
- let c = mul(conj3(adata[0]), bdata[0]);
24446
+ let c = mul2(conj3(adata[0]), bdata[0]);
23141
24447
  for (let i = 1; i < N2; i++) {
23142
- c = add4(c, mul(conj3(adata[i]), bdata[i]));
24448
+ c = add5(c, mul2(conj3(adata[i]), bdata[i]));
23143
24449
  }
23144
24450
  return c;
23145
24451
  }
23146
24452
  if (!aIsColumn && bIsColumn) {
23147
- let c = mul(conj3(adata[0]), bdata[0][0]);
24453
+ let c = mul2(conj3(adata[0]), bdata[0][0]);
23148
24454
  for (let i = 1; i < N2; i++) {
23149
- c = add4(c, mul(conj3(adata[i]), bdata[i][0]));
24455
+ c = add5(c, mul2(conj3(adata[i]), bdata[i][0]));
23150
24456
  }
23151
24457
  return c;
23152
24458
  }
23153
24459
  if (aIsColumn && !bIsColumn) {
23154
- let c = mul(conj3(adata[0][0]), bdata[0]);
24460
+ let c = mul2(conj3(adata[0][0]), bdata[0]);
23155
24461
  for (let i = 1; i < N2; i++) {
23156
- c = add4(c, mul(conj3(adata[i][0]), bdata[i]));
24462
+ c = add5(c, mul2(conj3(adata[i][0]), bdata[i]));
23157
24463
  }
23158
24464
  return c;
23159
24465
  }
23160
24466
  {
23161
- let c = mul(conj3(adata[0][0]), bdata[0][0]);
24467
+ let c = mul2(conj3(adata[0][0]), bdata[0][0]);
23162
24468
  for (let i = 1; i < N2; i++) {
23163
- c = add4(c, mul(conj3(adata[i][0]), bdata[i][0]));
24469
+ c = add5(c, mul2(conj3(adata[i][0]), bdata[i][0]));
23164
24470
  }
23165
24471
  return c;
23166
24472
  }
@@ -23172,8 +24478,8 @@ var createDot = /* @__PURE__ */ factory(
23172
24478
  const yindex = y._index;
23173
24479
  const yvalues = y._values;
23174
24480
  let c = 0;
23175
- const add4 = addScalar2;
23176
- const mul = multiplyScalar2;
24481
+ const add5 = addScalar2;
24482
+ const mul2 = multiplyScalar2;
23177
24483
  let i = 0;
23178
24484
  let j = 0;
23179
24485
  while (i < xindex.length && j < yindex.length) {
@@ -23188,7 +24494,7 @@ var createDot = /* @__PURE__ */ factory(
23188
24494
  continue;
23189
24495
  }
23190
24496
  if (I2 === J) {
23191
- c = add4(c, mul(xvalues[i], yvalues[j]));
24497
+ c = add5(c, mul2(xvalues[i], yvalues[j]));
23192
24498
  i++;
23193
24499
  j++;
23194
24500
  }
@@ -24084,7 +25390,7 @@ var createMatrixFromFunction = /* @__PURE__ */ factory(
24084
25390
  ({
24085
25391
  typed: typed3,
24086
25392
  matrix: matrix2,
24087
- isZero: isZero2
25393
+ isZero: isZero4
24088
25394
  }) => {
24089
25395
  return typed3(name91, {
24090
25396
  "Array | Matrix, function, string, string": function(size2, fn, format4, datatype) {
@@ -24116,7 +25422,7 @@ var createMatrixFromFunction = /* @__PURE__ */ factory(
24116
25422
  m.resize(size2);
24117
25423
  m.forEach(function(_, index) {
24118
25424
  const val = fn(index);
24119
- if (isZero2(val)) return;
25425
+ if (isZero4(val)) return;
24120
25426
  m.set(index, val);
24121
25427
  });
24122
25428
  return m;
@@ -24280,7 +25586,7 @@ var dependencies95 = ["typed", "matrix", "add"];
24280
25586
  var createTrace = /* @__PURE__ */ factory(
24281
25587
  name95,
24282
25588
  dependencies95,
24283
- ({ typed: typed3, matrix: matrix2, add: add4 }) => {
25589
+ ({ typed: typed3, matrix: matrix2, add: add5 }) => {
24284
25590
  return typed3("trace", {
24285
25591
  Array: function _arrayTrace(x) {
24286
25592
  return _denseTrace(matrix2(x));
@@ -24304,7 +25610,7 @@ var createTrace = /* @__PURE__ */ factory(
24304
25610
  if (rows === cols) {
24305
25611
  let sum3 = 0;
24306
25612
  for (let i = 0; i < rows; i++) {
24307
- sum3 = add4(sum3, data[i][i]);
25613
+ sum3 = add5(sum3, data[i][i]);
24308
25614
  }
24309
25615
  return sum3;
24310
25616
  } else {
@@ -24331,7 +25637,7 @@ var createTrace = /* @__PURE__ */ factory(
24331
25637
  for (let k = k0; k < k1; k++) {
24332
25638
  const i = index[k];
24333
25639
  if (i === j) {
24334
- sum3 = add4(sum3, values[k]);
25640
+ sum3 = add5(sum3, values[k]);
24335
25641
  break;
24336
25642
  }
24337
25643
  if (i > j) {
@@ -24382,7 +25688,7 @@ var dependencies96 = [
24382
25688
  var createDet = /* @__PURE__ */ factory(
24383
25689
  name96,
24384
25690
  dependencies96,
24385
- ({ typed: typed3, matrix: matrix2, subtractScalar: subtractScalar2, multiply: multiply2, divideScalar: divideScalar2, isZero: isZero2, unaryMinus: unaryMinus2 }) => {
25691
+ ({ typed: typed3, matrix: matrix2, subtractScalar: subtractScalar2, multiply: multiply2, divideScalar: divideScalar2, isZero: isZero4, unaryMinus: unaryMinus2 }) => {
24386
25692
  return typed3(name96, {
24387
25693
  any: function(x) {
24388
25694
  return clone(x);
@@ -24477,10 +25783,10 @@ var createDet = /* @__PURE__ */ factory(
24477
25783
  }
24478
25784
  for (let k = 0; k < rows; k++) {
24479
25785
  let k_ = rowIndices[k];
24480
- if (isZero2(matrix3[k_][k])) {
25786
+ if (isZero4(matrix3[k_][k])) {
24481
25787
  let _k;
24482
25788
  for (_k = k + 1; _k < rows; _k++) {
24483
- if (!isZero2(matrix3[rowIndices[_k]][k])) {
25789
+ if (!isZero4(matrix3[rowIndices[_k]][k])) {
24484
25790
  k_ = rowIndices[_k];
24485
25791
  rowIndices[_k] = rowIndices[k];
24486
25792
  rowIndices[k] = k_;
@@ -24698,7 +26004,7 @@ var dependencies98 = ["add", "multiply", "transpose"];
24698
26004
  var createCsAmd = /* @__PURE__ */ factory(
24699
26005
  name98,
24700
26006
  dependencies98,
24701
- ({ add: add4, multiply: multiply2, transpose: transpose5 }) => {
26007
+ ({ add: add5, multiply: multiply2, transpose: transpose5 }) => {
24702
26008
  function _tryWasmAmd(a, n) {
24703
26009
  const wasm = wasmLoader.getModule();
24704
26010
  if (!wasm || !a._ptr || !a._index) return null;
@@ -24752,7 +26058,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24752
26058
  const next = 2 * (n + 1);
24753
26059
  const head = 3 * (n + 1);
24754
26060
  const elen = 4 * (n + 1);
24755
- const degree2 = 5 * (n + 1);
26061
+ const degree3 = 5 * (n + 1);
24756
26062
  const w = 6 * (n + 1);
24757
26063
  const hhead = 7 * (n + 1);
24758
26064
  const last2 = P2;
@@ -24768,9 +26074,9 @@ var createCsAmd = /* @__PURE__ */ factory(
24768
26074
  nv,
24769
26075
  w,
24770
26076
  elen,
24771
- degree2
26077
+ degree3
24772
26078
  );
24773
- let nel = _initializeDegreeLists(n, cptr, W, degree2, elen, w, dense, nv, head, last2, next);
26079
+ let nel = _initializeDegreeLists(n, cptr, W, degree3, elen, w, dense, nv, head, last2, next);
24774
26080
  let mindeg = 0;
24775
26081
  let i, j, k, k1, k2, e, pj, ln, nvi, pk, eln, p1, p2, pn, h, d;
24776
26082
  while (nel < n) {
@@ -24811,7 +26117,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24811
26117
  if (last2[i] !== -1) {
24812
26118
  W[next + last2[i]] = W[next + i];
24813
26119
  } else {
24814
- W[head + W[degree2 + i]] = W[next + i];
26120
+ W[head + W[degree3 + i]] = W[next + i];
24815
26121
  }
24816
26122
  }
24817
26123
  if (e !== k) {
@@ -24822,7 +26128,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24822
26128
  if (elenk !== 0) {
24823
26129
  cnz = pk2;
24824
26130
  }
24825
- W[degree2 + k] = dk;
26131
+ W[degree3 + k] = dk;
24826
26132
  cptr[k] = pk1;
24827
26133
  W[len + k] = pk2 - pk1;
24828
26134
  W[elen + k] = -2;
@@ -24839,7 +26145,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24839
26145
  if (W[w + e] >= mark) {
24840
26146
  W[w + e] -= nvi;
24841
26147
  } else if (W[w + e] !== 0) {
24842
- W[w + e] = W[degree2 + e] + wnvi;
26148
+ W[w + e] = W[degree3 + e] + wnvi;
24843
26149
  }
24844
26150
  }
24845
26151
  }
@@ -24884,7 +26190,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24884
26190
  W[nv + i] = 0;
24885
26191
  W[elen + i] = -1;
24886
26192
  } else {
24887
- W[degree2 + i] = Math.min(W[degree2 + i], d);
26193
+ W[degree3 + i] = Math.min(W[degree3 + i], d);
24888
26194
  cindex[pn] = cindex[p3];
24889
26195
  cindex[p3] = cindex[p1];
24890
26196
  cindex[p1] = k;
@@ -24895,7 +26201,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24895
26201
  last2[i] = h;
24896
26202
  }
24897
26203
  }
24898
- W[degree2 + k] = dk;
26204
+ W[degree3 + k] = dk;
24899
26205
  lemax = Math.max(lemax, dk);
24900
26206
  mark = _wclear(mark + lemax, lemax, W, w, n);
24901
26207
  for (pk = pk1; pk < pk2; pk++) {
@@ -24940,7 +26246,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24940
26246
  continue;
24941
26247
  }
24942
26248
  W[nv + i] = nvi;
24943
- d = W[degree2 + i] + dk - nvi;
26249
+ d = W[degree3 + i] + dk - nvi;
24944
26250
  d = Math.min(d, n - nel - nvi);
24945
26251
  if (W[head + d] !== -1) {
24946
26252
  last2[W[head + d]] = i;
@@ -24949,7 +26255,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24949
26255
  last2[i] = -1;
24950
26256
  W[head + d] = i;
24951
26257
  mindeg = Math.min(mindeg, d);
24952
- W[degree2 + i] = d;
26258
+ W[degree3 + i] = d;
24953
26259
  cindex[p++] = i;
24954
26260
  }
24955
26261
  W[nv + k] = nvk;
@@ -24994,7 +26300,7 @@ var createCsAmd = /* @__PURE__ */ factory(
24994
26300
  function _createTargetMatrix(order, a, m, n, dense) {
24995
26301
  const at = transpose5(a);
24996
26302
  if (order === 1 && n === m) {
24997
- return add4(a, at);
26303
+ return add5(a, at);
24998
26304
  }
24999
26305
  if (order === 2) {
25000
26306
  const tindex = at._index;
@@ -25016,7 +26322,7 @@ var createCsAmd = /* @__PURE__ */ factory(
25016
26322
  }
25017
26323
  return multiply2(at, a);
25018
26324
  }
25019
- function _initializeQuotientGraph(n, cptr, W, len, head, last2, next, hhead, nv, w, elen, degree2) {
26325
+ function _initializeQuotientGraph(n, cptr, W, len, head, last2, next, hhead, nv, w, elen, degree3) {
25020
26326
  for (let k = 0; k < n; k++) {
25021
26327
  W[len + k] = cptr[k + 1] - cptr[k];
25022
26328
  }
@@ -25029,7 +26335,7 @@ var createCsAmd = /* @__PURE__ */ factory(
25029
26335
  W[nv + i] = 1;
25030
26336
  W[w + i] = 1;
25031
26337
  W[elen + i] = 0;
25032
- W[degree2 + i] = W[len + i];
26338
+ W[degree3 + i] = W[len + i];
25033
26339
  }
25034
26340
  const mark = _wclear(0, 0, W, w, n);
25035
26341
  W[elen + n] = -2;
@@ -25037,10 +26343,10 @@ var createCsAmd = /* @__PURE__ */ factory(
25037
26343
  W[w + n] = 0;
25038
26344
  return mark;
25039
26345
  }
25040
- function _initializeDegreeLists(n, cptr, W, degree2, elen, w, dense, nv, head, last2, next) {
26346
+ function _initializeDegreeLists(n, cptr, W, degree3, elen, w, dense, nv, head, last2, next) {
25041
26347
  let nel = 0;
25042
26348
  for (let i = 0; i < n; i++) {
25043
- const d = W[degree2 + i];
26349
+ const d = W[degree3 + i];
25044
26350
  if (d === 0) {
25045
26351
  W[elen + i] = -2;
25046
26352
  nel++;
@@ -25343,8 +26649,8 @@ var dependencies100 = ["add", "multiply", "transpose"];
25343
26649
  var createCsSqr = /* @__PURE__ */ factory(
25344
26650
  name100,
25345
26651
  dependencies100,
25346
- ({ add: add4, multiply: multiply2, transpose: transpose5 }) => {
25347
- const csAmd2 = createCsAmd({ add: add4, multiply: multiply2, transpose: transpose5 });
26652
+ ({ add: add5, multiply: multiply2, transpose: transpose5 }) => {
26653
+ const csAmd2 = createCsAmd({ add: add5, multiply: multiply2, transpose: transpose5 });
25348
26654
  const csCounts2 = createCsCounts({ transpose: transpose5 });
25349
26655
  return function csSqr2(order, a, qr2) {
25350
26656
  const aptr = a._ptr;
@@ -26860,7 +28166,7 @@ var createCatalan = /* @__PURE__ */ factory(
26860
28166
  addScalar: addScalar2,
26861
28167
  divideScalar: divideScalar2,
26862
28168
  multiplyScalar: multiplyScalar2,
26863
- combinations: combinations3,
28169
+ combinations: combinations4,
26864
28170
  isNegative: isNegative2,
26865
28171
  isInteger: isInteger3
26866
28172
  }) => {
@@ -26869,7 +28175,7 @@ var createCatalan = /* @__PURE__ */ factory(
26869
28175
  if (!isInteger3(n) || isNegative2(n)) {
26870
28176
  throw new TypeError("Non-negative integer value expected in function catalan");
26871
28177
  }
26872
- return divideScalar2(combinations3(multiplyScalar2(n, 2), n), addScalar2(n, 1));
28178
+ return divideScalar2(combinations4(multiplyScalar2(n, 2), n), addScalar2(n, 1));
26873
28179
  }
26874
28180
  });
26875
28181
  }
@@ -27356,7 +28662,7 @@ var createSubset = /* @__PURE__ */ factory(
27356
28662
  typed: typed3,
27357
28663
  matrix: matrix2,
27358
28664
  zeros: zeros4,
27359
- add: add4
28665
+ add: add5
27360
28666
  }) => {
27361
28667
  const referTo = typed3.referTo;
27362
28668
  return typed3(name119, {
@@ -27415,7 +28721,7 @@ var createSubset = /* @__PURE__ */ factory(
27415
28721
  const indexSize = index.size();
27416
28722
  if (indexSize.every((d) => d > 0)) {
27417
28723
  try {
27418
- return add4(replacement, zeros4(indexSize));
28724
+ return add5(replacement, zeros4(indexSize));
27419
28725
  } catch {
27420
28726
  return replacement;
27421
28727
  }
@@ -27505,11 +28811,11 @@ function _getObjectProperty(object, index) {
27505
28811
  if (index.size().length !== 1) {
27506
28812
  throw new DimensionError(index.size(), 1);
27507
28813
  }
27508
- const key = index.dimension(0);
27509
- if (typeof key !== "string") {
28814
+ const key2 = index.dimension(0);
28815
+ if (typeof key2 !== "string") {
27510
28816
  throw new TypeError("String expected as index to retrieve an object property");
27511
28817
  }
27512
- return getSafeProperty(object, key);
28818
+ return getSafeProperty(object, key2);
27513
28819
  }
27514
28820
  function _setObjectProperty(object, index, replacement) {
27515
28821
  if (isEmptyIndex(index)) {
@@ -27518,12 +28824,12 @@ function _setObjectProperty(object, index, replacement) {
27518
28824
  if (index.size().length !== 1) {
27519
28825
  throw new DimensionError(index.size(), 1);
27520
28826
  }
27521
- const key = index.dimension(0);
27522
- if (typeof key !== "string") {
28827
+ const key2 = index.dimension(0);
28828
+ if (typeof key2 !== "string") {
27523
28829
  throw new TypeError("String expected as index to retrieve an object property");
27524
28830
  }
27525
28831
  const updated = clone(object);
27526
- setSafeProperty(updated, key, replacement);
28832
+ setSafeProperty(updated, key2, replacement);
27527
28833
  return updated;
27528
28834
  }
27529
28835
 
@@ -28088,7 +29394,7 @@ var dependencies127 = ["typed", "add", "multiply", "Complex", "number"];
28088
29394
  var createZpk2tf = /* @__PURE__ */ factory(
28089
29395
  name127,
28090
29396
  dependencies127,
28091
- ({ typed: typed3, add: add4, multiply: multiply2, Complex: Complex13, number: number2 }) => {
29397
+ ({ typed: typed3, add: add5, multiply: multiply2, Complex: Complex13, number: number2 }) => {
28092
29398
  return typed3(name127, {
28093
29399
  "Array,Array,number": function(z, p, k) {
28094
29400
  return _zpk2tf(z, p, k);
@@ -28133,7 +29439,7 @@ var createZpk2tf = /* @__PURE__ */ factory(
28133
29439
  c[i] = Complex13(0, 0);
28134
29440
  for (let j = 0; j < a.length; j++) {
28135
29441
  if (i - j >= 0 && i - j < b.length) {
28136
- c[i] = add4(c[i], multiply2(a[j], b[i - j]));
29442
+ c[i] = add5(c[i], multiply2(a[j], b[i - j]));
28137
29443
  }
28138
29444
  }
28139
29445
  }
@@ -28160,7 +29466,7 @@ var dependencies128 = ["typed", "add", "unaryPlus"];
28160
29466
  var createCumSum = /* @__PURE__ */ factory(
28161
29467
  name128,
28162
29468
  dependencies128,
28163
- ({ typed: typed3, add: add4, unaryPlus: unaryPlus2 }) => {
29469
+ ({ typed: typed3, add: add5, unaryPlus: unaryPlus2 }) => {
28164
29470
  return typed3(name128, {
28165
29471
  // sum([a, b, c, d, ...])
28166
29472
  Array: _cumsum,
@@ -28201,7 +29507,7 @@ var createCumSum = /* @__PURE__ */ factory(
28201
29507
  }
28202
29508
  const sums = [unaryPlus2(array[0])];
28203
29509
  for (let i = 1; i < array.length; ++i) {
28204
- sums.push(add4(sums[i - 1], array[i]));
29510
+ sums.push(add5(sums[i - 1], array[i]));
28205
29511
  }
28206
29512
  return sums;
28207
29513
  }
@@ -28259,7 +29565,7 @@ var dependencies129 = ["typed", "config", "add", "numeric", "parseNumberWithConf
28259
29565
  var createSum = /* @__PURE__ */ factory(
28260
29566
  name129,
28261
29567
  dependencies129,
28262
- ({ typed: typed3, config: config2, add: add4, numeric: numeric2, parseNumberWithConfig: parseNumberWithConfig2 }) => {
29568
+ ({ typed: typed3, config: config2, add: add5, numeric: numeric2, parseNumberWithConfig: parseNumberWithConfig2 }) => {
28263
29569
  return typed3(name129, {
28264
29570
  // sum(string) - single string input
28265
29571
  string: function(x) {
@@ -28285,7 +29591,7 @@ var createSum = /* @__PURE__ */ factory(
28285
29591
  deepForEach(array, function(value) {
28286
29592
  try {
28287
29593
  const converted = typeof value === "string" ? parseNumberWithConfig2(value) : value;
28288
- sum3 = sum3 === void 0 ? converted : add4(sum3, converted);
29594
+ sum3 = sum3 === void 0 ? converted : add5(sum3, converted);
28289
29595
  } catch (err) {
28290
29596
  throw improveErrorMessage(err, "sum", value);
28291
29597
  }
@@ -28298,7 +29604,7 @@ var createSum = /* @__PURE__ */ factory(
28298
29604
  function _nsumDim(array, dim) {
28299
29605
  try {
28300
29606
  const dimValue = typeof dim === "number" ? dim : dim.valueOf();
28301
- const sum3 = reduce2(array, dimValue, add4);
29607
+ const sum3 = reduce2(array, dimValue, add5);
28302
29608
  return sum3;
28303
29609
  } catch (err) {
28304
29610
  throw improveErrorMessage(err, "sum", void 0);
@@ -29349,7 +30655,7 @@ var dependencies143 = ["typed", "config", "divideScalar", "log", "Complex"];
29349
30655
  var createLog1p = /* @__PURE__ */ factory(
29350
30656
  name143,
29351
30657
  dependencies143,
29352
- ({ typed: typed3, config: config2, divideScalar: divideScalar2, log: log3, Complex: Complex13 }) => {
30658
+ ({ typed: typed3, config: config2, divideScalar: divideScalar2, log: log5, Complex: Complex13 }) => {
29353
30659
  return typed3(name143, {
29354
30660
  number: function(x) {
29355
30661
  if (x >= -1 || config2.predictable) {
@@ -29372,7 +30678,7 @@ var createLog1p = /* @__PURE__ */ factory(
29372
30678
  ),
29373
30679
  "any, any": typed3.referToSelf(
29374
30680
  (self) => (x, base) => {
29375
- return divideScalar2(self(x), log3(base));
30681
+ return divideScalar2(self(x), log5(base));
29376
30682
  }
29377
30683
  )
29378
30684
  });
@@ -30960,7 +32266,7 @@ var createInvmod = /* @__PURE__ */ factory(
30960
32266
  equal: equal2,
30961
32267
  smaller: smaller2,
30962
32268
  mod: mod3,
30963
- add: add4,
32269
+ add: add5,
30964
32270
  isInteger: isInteger3
30965
32271
  }) => {
30966
32272
  return typed3(name168, {
@@ -30977,7 +32283,7 @@ var createInvmod = /* @__PURE__ */ factory(
30977
32283
  const [gcd2, invValue] = resVal;
30978
32284
  if (!equal2(gcd2, 1)) return NaN;
30979
32285
  let inv3 = mod3(invValue, b);
30980
- if (smaller2(inv3, 0)) inv3 = add4(inv3, b);
32286
+ if (smaller2(inv3, 0)) inv3 = add5(inv3, b);
30981
32287
  return inv3;
30982
32288
  }
30983
32289
  }
@@ -31081,7 +32387,7 @@ var createComposition = /* @__PURE__ */ factory(
31081
32387
  ({
31082
32388
  typed: typed3,
31083
32389
  addScalar: addScalar2,
31084
- combinations: combinations3,
32390
+ combinations: combinations4,
31085
32391
  isPositive: isPositive2,
31086
32392
  isNegative: _isNegative,
31087
32393
  isInteger: isInteger3,
@@ -31094,7 +32400,7 @@ var createComposition = /* @__PURE__ */ factory(
31094
32400
  } else if (larger2(k, n)) {
31095
32401
  throw new TypeError("k must be less than or equal to n in function composition");
31096
32402
  }
31097
- return combinations3(addScalar2(n, -1), addScalar2(k, -1));
32403
+ return combinations4(addScalar2(n, -1), addScalar2(k, -1));
31098
32404
  }
31099
32405
  });
31100
32406
  }
@@ -31238,7 +32544,7 @@ var createPinv = /* @__PURE__ */ factory(
31238
32544
  ctranspose: ctranspose2,
31239
32545
  divideScalar: divideScalar2,
31240
32546
  multiply: multiply2,
31241
- add: add4,
32547
+ add: add5,
31242
32548
  Complex: Complex13
31243
32549
  }) => {
31244
32550
  return typed3(name172, {
@@ -31320,7 +32626,7 @@ var createPinv = /* @__PURE__ */ factory(
31320
32626
  if (i2 === r) continue;
31321
32627
  val = M[i2][lead];
31322
32628
  for (let j = 0; j < cols; j++) {
31323
- M[i2][j] = add4(M[i2][j], multiply2(-1, multiply2(val, M[r][j])));
32629
+ M[i2][j] = add5(M[i2][j], multiply2(-1, multiply2(val, M[r][j])));
31324
32630
  }
31325
32631
  }
31326
32632
  lead++;
@@ -31334,12 +32640,12 @@ var createPinv = /* @__PURE__ */ factory(
31334
32640
  return { C, F };
31335
32641
  }
31336
32642
  function _isZero(x) {
31337
- return equal2(add4(x, Complex13(1, 1)), add4(0, Complex13(1, 1)));
32643
+ return equal2(add5(x, Complex13(1, 1)), add5(0, Complex13(1, 1)));
31338
32644
  }
31339
32645
  function _isZeros(arr10) {
31340
32646
  return deepEqual3(
31341
- add4(arr10, Complex13(1, 1)),
31342
- add4(multiply2(arr10, 0), Complex13(1, 1))
32647
+ add5(arr10, Complex13(1, 1)),
32648
+ add5(multiply2(arr10, 0), Complex13(1, 1))
31343
32649
  );
31344
32650
  }
31345
32651
  }
@@ -31393,7 +32699,7 @@ var createQr = /* @__PURE__ */ factory(
31393
32699
  matrix: matrix2,
31394
32700
  zeros: zeros4,
31395
32701
  identity: identity2,
31396
- isZero: isZero2,
32702
+ isZero: isZero4,
31397
32703
  equal: equal2,
31398
32704
  sign: sign3,
31399
32705
  sqrt: sqrt2,
@@ -31479,7 +32785,7 @@ var createQr = /* @__PURE__ */ factory(
31479
32785
  alphaSquared = addScalar2(alphaSquared, multiplyScalar2(Rdata[i][k], conj3(Rdata[i][k])));
31480
32786
  }
31481
32787
  const alpha = multiplyScalar2(sgn, sqrt2(alphaSquared));
31482
- if (!isZero2(alpha)) {
32788
+ if (!isZero4(alpha)) {
31483
32789
  const u1 = subtractScalar2(pivot, alpha);
31484
32790
  w[k] = 1;
31485
32791
  for (i = k + 1; i < rows; i++) {
@@ -31570,8 +32876,8 @@ var createRange = /* @__PURE__ */ factory(
31570
32876
  smallerEq: smallerEq2,
31571
32877
  larger: larger2,
31572
32878
  largerEq: largerEq2,
31573
- add: add4,
31574
- isZero: isZero2,
32879
+ add: add5,
32880
+ isZero: isZero4,
31575
32881
  isPositive: isPositive2
31576
32882
  }) => {
31577
32883
  return typed3(name174, {
@@ -31678,12 +32984,12 @@ var createRange = /* @__PURE__ */ factory(
31678
32984
  }
31679
32985
  function _range(start, end, step, includeEnd) {
31680
32986
  const array = [];
31681
- if (isZero2(step)) throw new Error("Step must be non-zero");
32987
+ if (isZero4(step)) throw new Error("Step must be non-zero");
31682
32988
  const ongoing = isPositive2(step) ? includeEnd ? smallerEq2 : smaller2 : includeEnd ? largerEq2 : larger2;
31683
32989
  let x = start;
31684
32990
  while (ongoing(x, end)) {
31685
32991
  array.push(x);
31686
- x = add4(x, step);
32992
+ x = add5(x, step);
31687
32993
  }
31688
32994
  return array;
31689
32995
  }
@@ -31946,10 +33252,10 @@ var dependencies177 = ["typed", "compareText", "isZero"];
31946
33252
  var createEqualText = /* @__PURE__ */ factory(
31947
33253
  name177,
31948
33254
  dependencies177,
31949
- ({ typed: typed3, compareText: compareText4, isZero: isZero2 }) => {
33255
+ ({ typed: typed3, compareText: compareText4, isZero: isZero4 }) => {
31950
33256
  return typed3(name177, {
31951
33257
  "any, any": function(x, y) {
31952
- return isZero2(compareText4(x, y));
33258
+ return isZero4(compareText4(x, y));
31953
33259
  }
31954
33260
  });
31955
33261
  }
@@ -33515,9 +34821,9 @@ var createSimplifyConstant = /* @__PURE__ */ factory(
33515
34821
  return obj;
33516
34822
  }
33517
34823
  if (isObjectNode(obj) && index.dimensions.length === 1 && isConstantNode(index.dimensions[0])) {
33518
- const key = index.dimensions[0].value;
33519
- if (key in obj.properties) {
33520
- return obj.properties[key];
34824
+ const key2 = index.dimensions[0].value;
34825
+ if (key2 in obj.properties) {
34826
+ return obj.properties[key2];
33521
34827
  }
33522
34828
  return new ConstantNode();
33523
34829
  }
@@ -34620,9 +35926,9 @@ var createFibonacciHeapClass = /* @__PURE__ */ factory(
34620
35926
  * list of this heap. Running time: O(1) actual.
34621
35927
  * @memberof FibonacciHeap
34622
35928
  */
34623
- insert(key, value) {
35929
+ insert(key2, value) {
34624
35930
  const node = {
34625
- key,
35931
+ key: key2,
34626
35932
  value,
34627
35933
  degree: 0
34628
35934
  };
@@ -34632,7 +35938,7 @@ var createFibonacciHeapClass = /* @__PURE__ */ factory(
34632
35938
  node.right = minimum.right;
34633
35939
  minimum.right = node;
34634
35940
  node.right.left = node;
34635
- if (smaller2(key, minimum.key)) {
35941
+ if (smaller2(key2, minimum.key)) {
34636
35942
  this._minimum = node;
34637
35943
  }
34638
35944
  } else {
@@ -34714,8 +36020,8 @@ var createFibonacciHeapClass = /* @__PURE__ */ factory(
34714
36020
  this.extractMinimum();
34715
36021
  }
34716
36022
  }
34717
- function _decreaseKey(minimum, node, key) {
34718
- node.key = key;
36023
+ function _decreaseKey(minimum, node, key2) {
36024
+ node.key = key2;
34719
36025
  const parent = node.parent;
34720
36026
  if (parent && smaller2(node.key, parent.key)) {
34721
36027
  _cut(minimum, node, parent);
@@ -35277,7 +36583,7 @@ var dependencies211 = [
35277
36583
  var createSqrtm = /* @__PURE__ */ factory(
35278
36584
  name211,
35279
36585
  dependencies211,
35280
- ({ typed: typed3, abs: abs2, add: add4, multiply: multiply2, map: map3, sqrt: sqrt2, subtract: subtract3, inv: inv3, size: size2, max: max2, identity: identity2 }) => {
36586
+ ({ typed: typed3, abs: abs2, add: add5, multiply: multiply2, map: map3, sqrt: sqrt2, subtract: subtract3, inv: inv3, size: size2, max: max2, identity: identity2 }) => {
35281
36587
  const _maxIterations = 1e3;
35282
36588
  const _tolerance = 1e-6;
35283
36589
  function _tryWasmSqrtm(A, n) {
@@ -35343,8 +36649,8 @@ var createSqrtm = /* @__PURE__ */ factory(
35343
36649
  let Z = identity2(size2(A));
35344
36650
  do {
35345
36651
  const Yk = Y;
35346
- Y = multiply2(0.5, add4(Yk, inv3(Z)));
35347
- Z = multiply2(0.5, add4(Z, inv3(Yk)));
36652
+ Y = multiply2(0.5, add5(Yk, inv3(Z)));
36653
+ Z = multiply2(0.5, add5(Z, inv3(Yk)));
35348
36654
  error = max2(abs2(subtract3(Y, Yk)));
35349
36655
  if (error > _tolerance && ++iterations > _maxIterations) {
35350
36656
  throw new Error("computing square root of matrix: iterative method could not converge");
@@ -35982,7 +37288,7 @@ var createSlu = /* @__PURE__ */ factory(
35982
37288
  ({
35983
37289
  typed: typed3,
35984
37290
  abs: abs2,
35985
- add: add4,
37291
+ add: add5,
35986
37292
  multiply: multiply2,
35987
37293
  transpose: transpose5,
35988
37294
  divideScalar: divideScalar2,
@@ -35991,7 +37297,7 @@ var createSlu = /* @__PURE__ */ factory(
35991
37297
  largerEq: largerEq2,
35992
37298
  SparseMatrix
35993
37299
  }) => {
35994
- const csSqr2 = createCsSqr({ add: add4, multiply: multiply2, transpose: transpose5 });
37300
+ const csSqr2 = createCsSqr({ add: add5, multiply: multiply2, transpose: transpose5 });
35995
37301
  const csLu2 = createCsLu({
35996
37302
  abs: abs2,
35997
37303
  divideScalar: divideScalar2,
@@ -36296,7 +37602,7 @@ var createIntersect = /* @__PURE__ */ factory(
36296
37602
  typed: typed3,
36297
37603
  config: config2,
36298
37604
  abs: abs2,
36299
- add: add4,
37605
+ add: add5,
36300
37606
  addScalar: addScalar2,
36301
37607
  matrix: matrix2,
36302
37608
  multiply: multiply2,
@@ -36306,7 +37612,7 @@ var createIntersect = /* @__PURE__ */ factory(
36306
37612
  smaller: smaller2,
36307
37613
  equalScalar: equalScalar3,
36308
37614
  flatten: flatten5,
36309
- isZero: isZero2,
37615
+ isZero: isZero4,
36310
37616
  isNumeric: isNumeric2
36311
37617
  }) => {
36312
37618
  return typed3("intersect", {
@@ -36421,7 +37727,7 @@ var createIntersect = /* @__PURE__ */ factory(
36421
37727
  multiplyScalar2(d1[0], d2[1]),
36422
37728
  multiplyScalar2(d2[0], d1[1])
36423
37729
  );
36424
- if (isZero2(det2)) return null;
37730
+ if (isZero4(det2)) return null;
36425
37731
  if (smaller2(abs2(det2), config2.relTol)) {
36426
37732
  return null;
36427
37733
  }
@@ -36436,7 +37742,7 @@ var createIntersect = /* @__PURE__ */ factory(
36436
37742
  ),
36437
37743
  det2
36438
37744
  );
36439
- return add4(multiply2(d1, t), o1);
37745
+ return add5(multiply2(d1, t), o1);
36440
37746
  }
36441
37747
  function _tryWasmIntersect2d(p1a, p1b, p2a, p2b) {
36442
37748
  const wasm = wasmLoader.getModule();
@@ -36495,7 +37801,7 @@ var createIntersect = /* @__PURE__ */ factory(
36495
37801
  multiplyScalar2(d2121, d4343),
36496
37802
  multiplyScalar2(d4321, d4321)
36497
37803
  );
36498
- if (isZero2(denominator)) return null;
37804
+ if (isZero4(denominator)) return null;
36499
37805
  const ta = divideScalar2(numerator, denominator);
36500
37806
  const tb = divideScalar2(addScalar2(d1343, multiplyScalar2(ta, d4321)), d4343);
36501
37807
  const pax = addScalar2(x1, multiplyScalar2(ta, subtract3(x2, x1)));
@@ -36552,7 +37858,7 @@ var dependencies219 = ["typed", "add", "divide"];
36552
37858
  var createMean = /* @__PURE__ */ factory(
36553
37859
  name219,
36554
37860
  dependencies219,
36555
- ({ typed: typed3, add: add4, divide: divide2 }) => {
37861
+ ({ typed: typed3, add: add5, divide: divide2 }) => {
36556
37862
  return typed3(name219, {
36557
37863
  // mean([a, b, c, d, ...])
36558
37864
  "Array | Matrix": _mean2,
@@ -36569,7 +37875,7 @@ var createMean = /* @__PURE__ */ factory(
36569
37875
  function _nmeanDim(array, dim) {
36570
37876
  try {
36571
37877
  const dimValue = typeof dim === "number" ? dim : dim.valueOf();
36572
- const sum3 = reduce2(array, dimValue, add4);
37878
+ const sum3 = reduce2(array, dimValue, add5);
36573
37879
  const s = Array.isArray(array) ? arraySize(array) : array.size();
36574
37880
  return divide2(sum3, s[dimValue]);
36575
37881
  } catch (err) {
@@ -36597,7 +37903,7 @@ var createMean = /* @__PURE__ */ factory(
36597
37903
  let num2 = 0;
36598
37904
  deepForEach(array, function(value) {
36599
37905
  try {
36600
- sum3 = sum3 === void 0 ? value : add4(sum3, value);
37906
+ sum3 = sum3 === void 0 ? value : add5(sum3, value);
36601
37907
  num2++;
36602
37908
  } catch (err) {
36603
37909
  throw improveErrorMessage(err, "mean", value);
@@ -36617,7 +37923,7 @@ var dependencies220 = ["typed", "add", "divide", "compare", "partitionSelect"];
36617
37923
  var createMedian = /* @__PURE__ */ factory(
36618
37924
  name220,
36619
37925
  dependencies220,
36620
- ({ typed: typed3, add: add4, divide: divide2, compare: compare2, partitionSelect: partitionSelect2 }) => {
37926
+ ({ typed: typed3, add: add5, divide: divide2, compare: compare2, partitionSelect: partitionSelect2 }) => {
36621
37927
  function _median2(array) {
36622
37928
  try {
36623
37929
  const flat = flatten2(array.valueOf());
@@ -36650,7 +37956,7 @@ var createMedian = /* @__PURE__ */ factory(
36650
37956
  });
36651
37957
  const middle2 = typed3({
36652
37958
  "number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit": function(left, right) {
36653
- return divide2(add4(left, right), 2);
37959
+ return divide2(add5(left, right), 2);
36654
37960
  }
36655
37961
  });
36656
37962
  return typed3(name220, {
@@ -36689,7 +37995,7 @@ var createVariance = /* @__PURE__ */ factory(
36689
37995
  dependencies221,
36690
37996
  ({
36691
37997
  typed: typed3,
36692
- add: add4,
37998
+ add: add5,
36693
37999
  subtract: subtract3,
36694
38000
  multiply: multiply2,
36695
38001
  divide: divide2,
@@ -36738,7 +38044,7 @@ var createVariance = /* @__PURE__ */ factory(
36738
38044
  let num2 = 0;
36739
38045
  deepForEach(array, function(value) {
36740
38046
  try {
36741
- sum3 = sum3 === void 0 ? value : add4(sum3, value);
38047
+ sum3 = sum3 === void 0 ? value : add5(sum3, value);
36742
38048
  num2++;
36743
38049
  } catch (err) {
36744
38050
  throw improveErrorMessage(err, "variance", value);
@@ -36749,7 +38055,7 @@ var createVariance = /* @__PURE__ */ factory(
36749
38055
  sum3 = void 0;
36750
38056
  deepForEach(array, function(value) {
36751
38057
  const diff2 = subtract3(value, mean7);
36752
- sum3 = sum3 === void 0 ? multiply2(diff2, diff2) : add4(sum3, multiply2(diff2, diff2));
38058
+ sum3 = sum3 === void 0 ? multiply2(diff2, diff2) : add5(sum3, multiply2(diff2, diff2));
36753
38059
  });
36754
38060
  if (mathIsNaN(sum3)) {
36755
38061
  return sum3;
@@ -36824,7 +38130,7 @@ var createQuantileSeq = /* @__PURE__ */ factory(
36824
38130
  ({
36825
38131
  typed: typed3,
36826
38132
  bignumber: bignumber2,
36827
- add: add4,
38133
+ add: add5,
36828
38134
  subtract: subtract3,
36829
38135
  divide: divide2,
36830
38136
  multiply: multiply2,
@@ -36872,7 +38178,7 @@ var createQuantileSeq = /* @__PURE__ */ factory(
36872
38178
  "N must be less than or equal to 2^32-1, as that is the maximum length of an Array"
36873
38179
  );
36874
38180
  }
36875
- const nPlusOne = add4(probOrN, 1);
38181
+ const nPlusOne = add5(probOrN, 1);
36876
38182
  probArr = [];
36877
38183
  for (let i = 0; smaller2(i, probOrN); i++) {
36878
38184
  const prob = divide2(i + 1, nPlusOne);
@@ -36929,11 +38235,11 @@ var createQuantileSeq = /* @__PURE__ */ factory(
36929
38235
  return integerPart % 2 === 0 ? left : right;
36930
38236
  }
36931
38237
  case "midpoint":
36932
- return divide2(add4(left, right), 2);
38238
+ return divide2(add5(left, right), 2);
36933
38239
  case "linear":
36934
38240
  default: {
36935
38241
  const fracPartConverted = isBigNumber(left) && isNumber(fracPart) ? bignumber2(fracPart) : fracPart;
36936
- return add4(
38242
+ return add5(
36937
38243
  multiply2(left, subtract3(1, fracPartConverted)),
36938
38244
  multiply2(right, fracPartConverted)
36939
38245
  );
@@ -36967,7 +38273,7 @@ var createKldivergence = /* @__PURE__ */ factory(
36967
38273
  multiply: multiply2,
36968
38274
  map: map3,
36969
38275
  dotDivide: dotDivide2,
36970
- log: log3,
38276
+ log: log5,
36971
38277
  isNumeric: isNumeric2
36972
38278
  }) => {
36973
38279
  return typed3(name223, {
@@ -37009,7 +38315,7 @@ var createKldivergence = /* @__PURE__ */ factory(
37009
38315
  const result = sum3(
37010
38316
  multiply2(
37011
38317
  qnorm,
37012
- map3(dotDivide2(qnorm, pnorm), (x) => log3(x))
38318
+ map3(dotDivide2(qnorm, pnorm), (x) => log5(x))
37013
38319
  )
37014
38320
  );
37015
38321
  if (isNumeric2(result)) {
@@ -37027,7 +38333,7 @@ var dependencies224 = ["typed", "add", "divide", "multiply", "factorial", "isInt
37027
38333
  var createMultinomial = /* @__PURE__ */ factory(
37028
38334
  name224,
37029
38335
  dependencies224,
37030
- ({ typed: typed3, add: add4, divide: divide2, multiply: multiply2, factorial: factorial6, isInteger: isInteger3, isPositive: isPositive2 }) => {
38336
+ ({ typed: typed3, add: add5, divide: divide2, multiply: multiply2, factorial: factorial6, isInteger: isInteger3, isPositive: isPositive2 }) => {
37031
38337
  return typed3(name224, {
37032
38338
  "Array | Matrix": function(a) {
37033
38339
  let sum3 = 0;
@@ -37036,7 +38342,7 @@ var createMultinomial = /* @__PURE__ */ factory(
37036
38342
  if (!isInteger3(ai) || !isPositive2(ai)) {
37037
38343
  throw new TypeError("Positive integer value expected in function multinomial");
37038
38344
  }
37039
- sum3 = add4(sum3, ai);
38345
+ sum3 = add5(sum3, ai);
37040
38346
  denom = multiply2(denom, factorial6(ai));
37041
38347
  });
37042
38348
  return divide2(factorial6(sum3), denom);
@@ -37052,7 +38358,7 @@ var dependencies225 = ["typed", "add", "multiply", "Complex", "divide", "matrix"
37052
38358
  var createFreqz = /* @__PURE__ */ factory(
37053
38359
  name225,
37054
38360
  dependencies225,
37055
- ({ typed: typed3, add: add4, multiply: multiply2, Complex: Complex13, divide: divide2, matrix: matrix2 }) => {
38361
+ ({ typed: typed3, add: add5, multiply: multiply2, Complex: Complex13, divide: divide2, matrix: matrix2 }) => {
37056
38362
  return typed3(name225, {
37057
38363
  "Array, Array": function(b, a) {
37058
38364
  const w = createBins(512);
@@ -37146,13 +38452,13 @@ var createFreqz = /* @__PURE__ */ factory(
37146
38452
  let sumNum = Complex13(0, 0);
37147
38453
  let sumDen = Complex13(0, 0);
37148
38454
  for (let j = 0; j < b.length; j++) {
37149
- sumNum = add4(
38455
+ sumNum = add5(
37150
38456
  sumNum,
37151
38457
  multiply2(b[j], Complex13(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
37152
38458
  );
37153
38459
  }
37154
38460
  for (let j = 0; j < a.length; j++) {
37155
- sumDen = add4(
38461
+ sumDen = add5(
37156
38462
  sumDen,
37157
38463
  multiply2(a[j], Complex13(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
37158
38464
  );
@@ -37717,7 +39023,7 @@ var createSimplifyCore = /* @__PURE__ */ factory(
37717
39023
  typed: typed3,
37718
39024
  parse: _parse2,
37719
39025
  equal: equal2,
37720
- isZero: isZero2,
39026
+ isZero: isZero4,
37721
39027
  add: _add,
37722
39028
  subtract: _subtract,
37723
39029
  multiply: _multiply2,
@@ -37815,10 +39121,10 @@ var createSimplifyCore = /* @__PURE__ */ factory(
37815
39121
  const a0 = _simplifyCore(node.args[0], options);
37816
39122
  let a1 = _simplifyCore(node.args[1], options);
37817
39123
  if (node.op === "+") {
37818
- if (isConstantNode(a0) && isZero2(a0.value)) {
39124
+ if (isConstantNode(a0) && isZero4(a0.value)) {
37819
39125
  return a1;
37820
39126
  }
37821
- if (isConstantNode(a1) && isZero2(a1.value)) {
39127
+ if (isConstantNode(a1) && isZero4(a1.value)) {
37822
39128
  return a0;
37823
39129
  }
37824
39130
  if (isOperatorNode(a1) && a1.isUnary() && a1.op === "-") {
@@ -37830,24 +39136,24 @@ var createSimplifyCore = /* @__PURE__ */ factory(
37830
39136
  if (isOperatorNode(a1) && a1.isUnary() && a1.op === "-") {
37831
39137
  return _simplifyCore(new OperatorNode("+", "add", [a0, a1.args[0]]), options);
37832
39138
  }
37833
- if (isConstantNode(a0) && isZero2(a0.value)) {
39139
+ if (isConstantNode(a0) && isZero4(a0.value)) {
37834
39140
  return _simplifyCore(new OperatorNode("-", "unaryMinus", [a1]));
37835
39141
  }
37836
- if (isConstantNode(a1) && isZero2(a1.value)) {
39142
+ if (isConstantNode(a1) && isZero4(a1.value)) {
37837
39143
  return a0;
37838
39144
  }
37839
39145
  return new OperatorNode(node.op, node.fn, [a0, a1]);
37840
39146
  }
37841
39147
  if (node.op === "*") {
37842
39148
  if (isConstantNode(a0)) {
37843
- if (isZero2(a0.value)) {
39149
+ if (isZero4(a0.value)) {
37844
39150
  return node0;
37845
39151
  } else if (equal2(a0.value, 1)) {
37846
39152
  return a1;
37847
39153
  }
37848
39154
  }
37849
39155
  if (isConstantNode(a1)) {
37850
- if (isZero2(a1.value)) {
39156
+ if (isZero4(a1.value)) {
37851
39157
  return node0;
37852
39158
  } else if (equal2(a1.value, 1)) {
37853
39159
  return a0;
@@ -37859,7 +39165,7 @@ var createSimplifyCore = /* @__PURE__ */ factory(
37859
39165
  return new OperatorNode(node.op, node.fn, [a0, a1], node.implicit);
37860
39166
  }
37861
39167
  if (node.op === "/") {
37862
- if (isConstantNode(a0) && isZero2(a0.value)) {
39168
+ if (isConstantNode(a0) && isZero4(a0.value)) {
37863
39169
  return node0;
37864
39170
  }
37865
39171
  if (isConstantNode(a1) && equal2(a1.value, 1)) {
@@ -37869,7 +39175,7 @@ var createSimplifyCore = /* @__PURE__ */ factory(
37869
39175
  }
37870
39176
  if (node.op === "^") {
37871
39177
  if (isConstantNode(a1)) {
37872
- if (isZero2(a1.value)) {
39178
+ if (isZero4(a1.value)) {
37873
39179
  return node1;
37874
39180
  } else if (equal2(a1.value, 1)) {
37875
39181
  return a0;
@@ -37967,9 +39273,9 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
37967
39273
  dependencies234,
37968
39274
  ({
37969
39275
  typed: typed3,
37970
- isZero: isZero2,
39276
+ isZero: isZero4,
37971
39277
  equalScalar: equalScalar3,
37972
- add: add4,
39278
+ add: add5,
37973
39279
  subtract: subtract3,
37974
39280
  multiply: multiply2,
37975
39281
  divide: divide2,
@@ -37983,7 +39289,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
37983
39289
  return typed3(name234, {
37984
39290
  "number|Complex, ...number|Complex": (constant, restCoeffs) => {
37985
39291
  const coeffs = [constant, ...restCoeffs];
37986
- while (coeffs.length > 0 && isZero2(coeffs[coeffs.length - 1])) {
39292
+ while (coeffs.length > 0 && isZero4(coeffs[coeffs.length - 1])) {
37987
39293
  coeffs.pop();
37988
39294
  }
37989
39295
  if (coeffs.length < 2) {
@@ -38011,15 +39317,15 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
38011
39317
  const denom = unaryMinus2(multiply2(3, a));
38012
39318
  const D0_1 = multiply2(b, b);
38013
39319
  const D0_2 = multiply2(3, a, c);
38014
- const D1_1 = add4(multiply2(2, b, b, b), multiply2(27, a, a, d));
39320
+ const D1_1 = add5(multiply2(2, b, b, b), multiply2(27, a, a, d));
38015
39321
  const D1_2 = multiply2(9, a, b, c);
38016
39322
  if (equalScalar3(D0_1, D0_2) && equalScalar3(D1_1, D1_2)) {
38017
39323
  return [divide2(b, denom)];
38018
39324
  }
38019
39325
  const Delta0 = subtract3(D0_1, D0_2);
38020
39326
  const Delta1 = subtract3(D1_1, D1_2);
38021
- const discriminant1 = add4(multiply2(18, a, b, c, d), multiply2(b, b, c, c));
38022
- const discriminant2 = add4(
39327
+ const discriminant1 = add5(multiply2(18, a, b, c, d), multiply2(b, b, c, c));
39328
+ const discriminant2 = add5(
38023
39329
  multiply2(4, b, b, b, d),
38024
39330
  multiply2(4, a, c, c, c),
38025
39331
  multiply2(27, a, a, d, d)
@@ -38027,7 +39333,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
38027
39333
  if (equalScalar3(discriminant1, discriminant2)) {
38028
39334
  return [
38029
39335
  divide2(
38030
- subtract3(multiply2(4, a, b, c), add4(multiply2(9, a, a, d), multiply2(b, b, b))),
39336
+ subtract3(multiply2(4, a, b, c), add5(multiply2(9, a, a, d), multiply2(b, b, b))),
38031
39337
  multiply2(a, Delta0)
38032
39338
  ),
38033
39339
  // simple root
@@ -38040,7 +39346,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
38040
39346
  Ccubed = Delta1;
38041
39347
  } else {
38042
39348
  Ccubed = divide2(
38043
- add4(
39349
+ add5(
38044
39350
  Delta1,
38045
39351
  sqrt2(subtract3(multiply2(Delta1, Delta1), multiply2(4, Delta0, Delta0, Delta0)))
38046
39352
  ),
@@ -38048,7 +39354,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
38048
39354
  );
38049
39355
  }
38050
39356
  const allRoots = true;
38051
- const rawRoots = cbrt3(Ccubed, allRoots).toArray().map((C) => divide2(add4(b, C, divide2(Delta0, C)), denom));
39357
+ const rawRoots = cbrt3(Ccubed, allRoots).toArray().map((C) => divide2(add5(b, C, divide2(Delta0, C)), denom));
38052
39358
  return rawRoots.map((r) => {
38053
39359
  if (typeOf3(r) === "Complex" && equalScalar3(re3(r), re3(r) + im3(r))) {
38054
39360
  return re3(r);
@@ -38104,7 +39410,7 @@ var createZeta = /* @__PURE__ */ factory(
38104
39410
  gamma: gamma2,
38105
39411
  sin: sin2,
38106
39412
  subtract: subtract3,
38107
- add: add4,
39413
+ add: add5,
38108
39414
  Complex: Complex13,
38109
39415
  BigNumber: BigNumber9,
38110
39416
  pi
@@ -38172,20 +39478,20 @@ var createZeta = /* @__PURE__ */ factory(
38172
39478
  }
38173
39479
  function d(k, n) {
38174
39480
  let S = k;
38175
- for (let j = k; smallerEq2(j, n); j = add4(j, 1)) {
39481
+ for (let j = k; smallerEq2(j, n); j = add5(j, 1)) {
38176
39482
  const factor2 = divide2(
38177
- multiply2(factorial6(add4(n, subtract3(j, 1))), pow2(4, j)),
39483
+ multiply2(factorial6(add5(n, subtract3(j, 1))), pow2(4, j)),
38178
39484
  multiply2(factorial6(subtract3(n, j)), factorial6(multiply2(2, j)))
38179
39485
  );
38180
- S = add4(S, factor2);
39486
+ S = add5(S, factor2);
38181
39487
  }
38182
39488
  return multiply2(n, S);
38183
39489
  }
38184
39490
  function f(s, n, createValue) {
38185
39491
  const c = divide2(1, multiply2(d(createValue(0), n), subtract3(1, pow2(2, subtract3(1, s)))));
38186
39492
  let S = createValue(0);
38187
- for (let k = createValue(1); smallerEq2(k, n); k = add4(k, 1)) {
38188
- S = add4(S, divide2(multiply2((-1) ** (k - 1), d(k, n)), pow2(k, s)));
39493
+ for (let k = createValue(1); smallerEq2(k, n); k = add5(k, 1)) {
39494
+ S = add5(S, divide2(multiply2((-1) ** (k - 1), d(k, n)), pow2(k, s)));
38189
39495
  }
38190
39496
  return multiply2(c, S);
38191
39497
  }
@@ -38622,11 +39928,11 @@ function createComplexEigs({
38622
39928
  M[i] = Array(N2).fill(0);
38623
39929
  }
38624
39930
  let I2 = 0;
38625
- for (const sub3 of arr10) {
38626
- const n = sub3.length;
39931
+ for (const sub4 of arr10) {
39932
+ const n = sub4.length;
38627
39933
  for (let i = 0; i < n; i++) {
38628
39934
  for (let j = 0; j < n; j++) {
38629
- M[I2 + i][I2 + j] = sub3[i][j];
39935
+ M[I2 + i][I2 + j] = sub4[i][j];
38630
39936
  }
38631
39937
  }
38632
39938
  I2 += n;
@@ -38734,7 +40040,7 @@ function createRealSymmetric({
38734
40040
  inv: inv3,
38735
40041
  bignumber: bignumber2,
38736
40042
  multiply: multiply2,
38737
- add: add4
40043
+ add: add5
38738
40044
  }) {
38739
40045
  function bigGte(a, b) {
38740
40046
  if (typeof a === "number" && typeof b === "number") return a >= b;
@@ -38931,7 +40237,7 @@ function createRealSymmetric({
38931
40237
  subtract3(multiplyScalar2(c2, Hij[i][i]), csHij),
38932
40238
  multiplyScalar2(s2, Hij[j][j])
38933
40239
  );
38934
- const Ajj = add4(
40240
+ const Ajj = add5(
38935
40241
  multiplyScalar2(s2, Hij[i][i]),
38936
40242
  csHij,
38937
40243
  multiplyScalar2(c2, Hij[j][j])
@@ -39103,7 +40409,7 @@ var createEigs = /* @__PURE__ */ factory(
39103
40409
  inv: inv3,
39104
40410
  bignumber: bignumber2,
39105
40411
  multiply: multiply2,
39106
- add: add4,
40412
+ add: add5,
39107
40413
  larger: larger2,
39108
40414
  column: _column,
39109
40415
  flatten: flatten5,
@@ -39135,7 +40441,7 @@ var createEigs = /* @__PURE__ */ factory(
39135
40441
  bignumber: bignumber2,
39136
40442
  complex: complex3,
39137
40443
  multiply: multiply2,
39138
- add: add4
40444
+ add: add5
39139
40445
  });
39140
40446
  const doComplexEigs = createComplexEigs({
39141
40447
  addScalar: addScalar2,
@@ -40158,10 +41464,10 @@ var createSimplify = /* @__PURE__ */ factory(
40158
41464
  const native = /* @__PURE__ */ new Map();
40159
41465
  const sm = scope;
40160
41466
  if (typeof sm.forEach === "function") {
40161
- sm.forEach((value, key) => native.set(key, value));
41467
+ sm.forEach((value, key2) => native.set(key2, value));
40162
41468
  } else {
40163
- for (const [key, value] of Object.entries(scope)) {
40164
- native.set(key, value);
41469
+ for (const [key2, value] of Object.entries(scope)) {
41470
+ native.set(key2, value);
40165
41471
  }
40166
41472
  }
40167
41473
  scope = native;
@@ -40351,19 +41657,19 @@ var createSimplify = /* @__PURE__ */ factory(
40351
41657
  } else if (!match2.placeholders) {
40352
41658
  return match1;
40353
41659
  }
40354
- for (const key in match1.placeholders) {
40355
- if (hasOwnProperty(match1.placeholders, key)) {
40356
- res.placeholders[key] = match1.placeholders[key];
40357
- if (hasOwnProperty(match2.placeholders, key)) {
40358
- if (!_exactMatch(match1.placeholders[key], match2.placeholders[key])) {
41660
+ for (const key2 in match1.placeholders) {
41661
+ if (hasOwnProperty(match1.placeholders, key2)) {
41662
+ res.placeholders[key2] = match1.placeholders[key2];
41663
+ if (hasOwnProperty(match2.placeholders, key2)) {
41664
+ if (!_exactMatch(match1.placeholders[key2], match2.placeholders[key2])) {
40359
41665
  return null;
40360
41666
  }
40361
41667
  }
40362
41668
  }
40363
41669
  }
40364
- for (const key in match2.placeholders) {
40365
- if (hasOwnProperty(match2.placeholders, key)) {
40366
- res.placeholders[key] = match2.placeholders[key];
41670
+ for (const key2 in match2.placeholders) {
41671
+ if (hasOwnProperty(match2.placeholders, key2)) {
41672
+ res.placeholders[key2] = match2.placeholders[key2];
40367
41673
  }
40368
41674
  }
40369
41675
  return res;
@@ -40605,7 +41911,7 @@ var createDerivative = /* @__PURE__ */ factory(
40605
41911
  parse: parse3,
40606
41912
  simplify: simplify2,
40607
41913
  equal: equal2,
40608
- isZero: isZero2,
41914
+ isZero: isZero4,
40609
41915
  numeric: numeric2,
40610
41916
  ConstantNode,
40611
41917
  FunctionNode,
@@ -40637,7 +41943,7 @@ var createDerivative = /* @__PURE__ */ factory(
40637
41943
  }
40638
41944
  return symbol;
40639
41945
  }
40640
- const derivative2 = typed3(name244, {
41946
+ const derivative3 = typed3(name244, {
40641
41947
  "Node, SymbolNode": plainDerivative,
40642
41948
  "Node, SymbolNode, Object": plainDerivative,
40643
41949
  "Node, string": (node, symbol) => plainDerivative(node, parseIdentifier(symbol)),
@@ -40653,8 +41959,8 @@ var createDerivative = /* @__PURE__ */ factory(
40653
41959
  }
40654
41960
  */
40655
41961
  });
40656
- derivative2._simplify = true;
40657
- derivative2.toTex = function(deriv) {
41962
+ derivative3._simplify = true;
41963
+ derivative3.toTex = function(deriv) {
40658
41964
  return _derivTex(...deriv.args);
40659
41965
  };
40660
41966
  const _derivTex = typed3("_derivTex", {
@@ -41081,7 +42387,7 @@ var createDerivative = /* @__PURE__ */ factory(
41081
42387
  const arg0 = node.args[0];
41082
42388
  const arg1 = node.args[1];
41083
42389
  if (isConst2(arg0)) {
41084
- if (isConstantNode(arg0) && (isZero2(arg0.value) || equal2(arg0.value, 1))) {
42390
+ if (isConstantNode(arg0) && (isZero4(arg0.value) || equal2(arg0.value, 1))) {
41085
42391
  return createConstantNode2(0);
41086
42392
  }
41087
42393
  return new OperatorNode("*", "multiply", [
@@ -41094,7 +42400,7 @@ var createDerivative = /* @__PURE__ */ factory(
41094
42400
  }
41095
42401
  if (isConst2(arg1)) {
41096
42402
  if (isConstantNode(arg1)) {
41097
- if (isZero2(arg1.value)) {
42403
+ if (isZero4(arg1.value)) {
41098
42404
  return createConstantNode2(0);
41099
42405
  }
41100
42406
  if (equal2(arg1.value, 1)) {
@@ -41132,7 +42438,7 @@ var createDerivative = /* @__PURE__ */ factory(
41132
42438
  function createConstantNode2(value, valueType) {
41133
42439
  return new ConstantNode(numeric2(value, valueType || safeNumberType(String(value), config2)));
41134
42440
  }
41135
- return derivative2;
42441
+ return derivative3;
41136
42442
  }
41137
42443
  );
41138
42444
 
@@ -41161,7 +42467,7 @@ var createNorm = /* @__PURE__ */ factory(
41161
42467
  ({
41162
42468
  typed: typed3,
41163
42469
  abs: abs2,
41164
- add: add4,
42470
+ add: add5,
41165
42471
  pow: pow2,
41166
42472
  conj: conj3,
41167
42473
  sqrt: sqrt2,
@@ -41266,7 +42572,7 @@ var createNorm = /* @__PURE__ */ factory(
41266
42572
  if (!equalScalar3(p, 0)) {
41267
42573
  let n = 0;
41268
42574
  x.forEach(function(value) {
41269
- n = add4(pow2(abs2(value), p), n);
42575
+ n = add5(pow2(abs2(value), p), n);
41270
42576
  }, true);
41271
42577
  return pow2(n, 1 / p);
41272
42578
  }
@@ -41277,7 +42583,7 @@ var createNorm = /* @__PURE__ */ factory(
41277
42583
  function _matrixNormFrobenius(x) {
41278
42584
  let fro = 0;
41279
42585
  x.forEach(function(value) {
41280
- fro = add4(fro, multiply2(value, conj3(value)));
42586
+ fro = add5(fro, multiply2(value, conj3(value)));
41281
42587
  });
41282
42588
  return abs2(sqrt2(fro));
41283
42589
  }
@@ -41286,7 +42592,7 @@ var createNorm = /* @__PURE__ */ factory(
41286
42592
  let maxc = 0;
41287
42593
  x.forEach(function(value, index) {
41288
42594
  const j = index[1];
41289
- const cj = add4(c[j] || 0, abs2(value));
42595
+ const cj = add5(c[j] || 0, abs2(value));
41290
42596
  if (larger2(cj, maxc)) {
41291
42597
  maxc = cj;
41292
42598
  }
@@ -41310,7 +42616,7 @@ var createNorm = /* @__PURE__ */ factory(
41310
42616
  let maxr = 0;
41311
42617
  x.forEach(function(value, index) {
41312
42618
  const i = index[0];
41313
- const ri = add4(r[i] || 0, abs2(value));
42619
+ const ri = add5(r[i] || 0, abs2(value));
41314
42620
  if (larger2(ri, maxr)) {
41315
42621
  maxr = ri;
41316
42622
  }
@@ -42144,7 +43450,7 @@ var createSylvester = /* @__PURE__ */ factory(
42144
43450
  transpose: transpose5,
42145
43451
  index,
42146
43452
  subset: subset2,
42147
- add: add4,
43453
+ add: add5,
42148
43454
  subtract: subtract3,
42149
43455
  identity: identity2,
42150
43456
  lusolve: lusolve2,
@@ -42192,7 +43498,7 @@ var createSylvester = /* @__PURE__ */ factory(
42192
43498
  if (k < n - 1 && abs2(subset2(G, index(k + 1, k))) > 1e-5) {
42193
43499
  let RHS = vc(subset2(D, index(all, [k])), subset2(D, index(all, [k + 1])));
42194
43500
  for (let j = 0; j < k; j++) {
42195
- RHS = add4(
43501
+ RHS = add5(
42196
43502
  RHS,
42197
43503
  vc(multiply2(y[j], subset2(G, index(j, k))), multiply2(y[j], subset2(G, index(j, k + 1))))
42198
43504
  );
@@ -42201,7 +43507,7 @@ var createSylvester = /* @__PURE__ */ factory(
42201
43507
  const gmk = multiply2(identity2(m), multiply2(-1, subset2(G, index(k + 1, k))));
42202
43508
  const gkm = multiply2(identity2(m), multiply2(-1, subset2(G, index(k, k + 1))));
42203
43509
  const gmm = multiply2(identity2(m), multiply2(-1, subset2(G, index(k + 1, k + 1))));
42204
- const LHS = vc(hc(add4(F, gkk), gmk), hc(gkm, add4(F, gmm)));
43510
+ const LHS = vc(hc(add5(F, gkk), gmk), hc(gkm, add5(F, gmm)));
42205
43511
  const yAux = lusolve2(LHS, RHS);
42206
43512
  y[k] = yAux.subset(index(range2(0, m), [0]));
42207
43513
  y[k + 1] = yAux.subset(index(range2(m, 2 * m), [0]));
@@ -42209,7 +43515,7 @@ var createSylvester = /* @__PURE__ */ factory(
42209
43515
  } else {
42210
43516
  let RHS = subset2(D, index(all, [k]));
42211
43517
  for (let j = 0; j < k; j++) {
42212
- RHS = add4(RHS, multiply2(y[j], subset2(G, index(j, k))));
43518
+ RHS = add5(RHS, multiply2(y[j], subset2(G, index(j, k))));
42213
43519
  }
42214
43520
  const gkk = subset2(G, index(k, k));
42215
43521
  const LHS = subtract3(F, multiply2(gkk, identity2(m)));
@@ -42534,7 +43840,7 @@ var getMatrixDataType = createGetMatrixDataType(
42534
43840
  var map2 = createMap(factoryScope);
42535
43841
  var size = createSize(factoryScope);
42536
43842
  var squeeze2 = createSqueeze(factoryScope);
42537
- var combinations2 = createCombinations(factoryScope);
43843
+ var combinations3 = createCombinations(factoryScope);
42538
43844
  var combinationsWithRep2 = createCombinationsWithRep(
42539
43845
  factoryScope
42540
43846
  );
@@ -42558,7 +43864,7 @@ var isNaN2 = createIsNaN(factoryScope);
42558
43864
  var isNegative = createIsNegative(factoryScope);
42559
43865
  var isNumeric = createIsNumeric(factoryScope);
42560
43866
  var isPositive = createIsPositive(factoryScope);
42561
- var isPrime = createIsPrime(factoryScope);
43867
+ var isPrime2 = createIsPrime(factoryScope);
42562
43868
  var numeric = createNumeric(factoryScope);
42563
43869
  var typeOf2 = createTypeOf(factoryScope);
42564
43870
  var factory_abs = createAbs(factoryScope);
@@ -42605,7 +43911,7 @@ factoryScope.atan = factory_atan;
42605
43911
  factoryScope.atanh = factory_atanh;
42606
43912
  factoryScope.bitNot = bitNot2;
42607
43913
  factoryScope.clone = clone2;
42608
- factoryScope.combinations = combinations2;
43914
+ factoryScope.combinations = combinations3;
42609
43915
  factoryScope.combinationsWithRep = combinationsWithRep2;
42610
43916
  factoryScope.conj = conj2;
42611
43917
  factoryScope.cos = factory_cos;
@@ -42624,7 +43930,7 @@ factoryScope.isNaN = isNaN2;
42624
43930
  factoryScope.isNegative = isNegative;
42625
43931
  factoryScope.isNumeric = isNumeric;
42626
43932
  factoryScope.isPositive = isPositive;
42627
- factoryScope.isPrime = isPrime;
43933
+ factoryScope.isPrime = isPrime2;
42628
43934
  factoryScope.lgamma = lgamma2;
42629
43935
  factoryScope.log2 = factory_log2;
42630
43936
  factoryScope.log10 = factory_log10;
@@ -42671,7 +43977,7 @@ var hasNumericValue = createHasNumericValue(
42671
43977
  factoryScope
42672
43978
  );
42673
43979
  var isFinite2 = createIsFinite(factoryScope);
42674
- var isZero = createIsZero(factoryScope);
43980
+ var isZero3 = createIsZero(factoryScope);
42675
43981
  var factory_unaryPlus = createUnaryPlus(
42676
43982
  factoryScope
42677
43983
  );
@@ -42683,7 +43989,7 @@ factoryScope.unaryPlus = factory_unaryPlus;
42683
43989
  factoryScope.flatten = flatten3;
42684
43990
  factoryScope.hasNumericValue = hasNumericValue;
42685
43991
  factoryScope.isFinite = isFinite2;
42686
- factoryScope.isZero = isZero;
43992
+ factoryScope.isZero = isZero3;
42687
43993
  factoryScope.prod = prod;
42688
43994
  factoryScope.dot = factory_dot;
42689
43995
  factoryScope.squeeze = squeeze2;
@@ -43150,8 +44456,8 @@ var setSymDifference2 = createSetSymDifference(
43150
44456
  factoryScope.setSymDifference = setSymDifference2;
43151
44457
  var simplify = createSimplify(factoryScope);
43152
44458
  factoryScope.simplify = simplify;
43153
- var derivative = createDerivative(factoryScope);
43154
- factoryScope.derivative = derivative;
44459
+ var derivative2 = createDerivative(factoryScope);
44460
+ factoryScope.derivative = derivative2;
43155
44461
  var factory_norm = createNorm(factoryScope);
43156
44462
  factoryScope.norm = factory_norm;
43157
44463
  var rationalize = createRationalize(
@@ -43376,7 +44682,7 @@ var mathScope = {
43376
44682
  };
43377
44683
  {
43378
44684
  const mwt = factoryScope.mathWithTransform;
43379
- for (const key of [
44685
+ for (const key2 of [
43380
44686
  "and",
43381
44687
  "bitAnd",
43382
44688
  "bitOr",
@@ -43403,7 +44709,7 @@ var mathScope = {
43403
44709
  "sum",
43404
44710
  "variance"
43405
44711
  ]) {
43406
- if (typeof mwt[key] === "function") mathScope[key] = mwt[key];
44712
+ if (typeof mwt[key2] === "function") mathScope[key2] = mwt[key2];
43407
44713
  }
43408
44714
  }
43409
44715
  var parse = factoryScope.parse;
@@ -43434,7 +44740,7 @@ function parser() {
43434
44740
  },
43435
44741
  /** Clear all retained variables. */
43436
44742
  clear() {
43437
- for (const key of Object.keys(scope)) delete scope[key];
44743
+ for (const key2 of Object.keys(scope)) delete scope[key2];
43438
44744
  }
43439
44745
  };
43440
44746
  }
@@ -44072,9 +45378,9 @@ function numericRealRoots(expr, varName) {
44072
45378
  const addRoot = (r) => {
44073
45379
  const rounded = Math.round(r);
44074
45380
  const clean = Math.abs(r - rounded) < 1e-8 ? rounded : r;
44075
- const key = clean.toFixed(8);
44076
- if (!seen.has(key)) {
44077
- seen.add(key);
45381
+ const key2 = clean.toFixed(8);
45382
+ if (!seen.has(key2)) {
45383
+ seen.add(key2);
44078
45384
  roots.push(clean);
44079
45385
  }
44080
45386
  };
@@ -44143,25 +45449,25 @@ function solve(equation, varName) {
44143
45449
  return Math.abs(x - rounded) < 1e-8 ? rounded : x;
44144
45450
  }, pushReal2 = function(x) {
44145
45451
  const clean = cleanComponent2(x);
44146
- const key = `r${clean.toFixed(8)}`;
44147
- if (!seen.has(key)) {
44148
- seen.add(key);
45452
+ const key2 = `r${clean.toFixed(8)}`;
45453
+ if (!seen.has(key2)) {
45454
+ seen.add(key2);
44149
45455
  reals.push(clean);
44150
45456
  }
44151
45457
  };
44152
45458
  var cleanComponent = cleanComponent2, pushReal = pushReal2;
44153
45459
  const [c0, c1, c2, c3] = coeffs;
44154
45460
  const eps = 1e-9;
44155
- let degree2 = 0;
44156
- if (Math.abs(c3) > eps) degree2 = 3;
44157
- else if (Math.abs(c2) > eps) degree2 = 2;
44158
- else if (Math.abs(c1) > eps) degree2 = 1;
44159
- if (degree2 === 0) {
45461
+ let degree3 = 0;
45462
+ if (Math.abs(c3) > eps) degree3 = 3;
45463
+ else if (Math.abs(c2) > eps) degree3 = 2;
45464
+ else if (Math.abs(c1) > eps) degree3 = 1;
45465
+ if (degree3 === 0) {
44160
45466
  return [];
44161
45467
  }
44162
45468
  let raw;
44163
45469
  try {
44164
- const args = [c0, c1, c2, c3].slice(0, degree2 + 1);
45470
+ const args = [c0, c1, c2, c3].slice(0, degree3 + 1);
44165
45471
  raw = polynomialRoot(...args);
44166
45472
  } catch {
44167
45473
  return numericRealRoots(expr, varName);
@@ -44176,9 +45482,9 @@ function solve(equation, varName) {
44176
45482
  } else {
44177
45483
  const re3 = cleanComponent2(r.re);
44178
45484
  const im3 = cleanComponent2(r.im);
44179
- const key = `${re3.toFixed(8)}|${im3.toFixed(8)}`;
44180
- if (!seen.has(key)) {
44181
- seen.add(key);
45485
+ const key2 = `${re3.toFixed(8)}|${im3.toFixed(8)}`;
45486
+ if (!seen.has(key2)) {
45487
+ seen.add(key2);
44182
45488
  complexRoots.push(new Complex10(re3, im3));
44183
45489
  }
44184
45490
  }
@@ -44259,15 +45565,15 @@ function asymptotic(expr, varName, towards = Infinity) {
44259
45565
  const avgOrder = (logRatio1 + logRatio2) / 2;
44260
45566
  const roundedOrder = Math.round(avgOrder * 2) / 2;
44261
45567
  const coefficient = f3 / Math.pow(x3, roundedOrder);
44262
- let leadingTerm;
45568
+ let leadingTerm2;
44263
45569
  if (roundedOrder === 0) {
44264
- leadingTerm = formatCoeff(coefficient);
45570
+ leadingTerm2 = formatCoeff(coefficient);
44265
45571
  } else if (roundedOrder === 1) {
44266
- leadingTerm = `${formatCoeff(coefficient)}*${varName}`;
45572
+ leadingTerm2 = `${formatCoeff(coefficient)}*${varName}`;
44267
45573
  } else {
44268
- leadingTerm = `${formatCoeff(coefficient)}*${varName}^${roundedOrder}`;
45574
+ leadingTerm2 = `${formatCoeff(coefficient)}*${varName}^${roundedOrder}`;
44269
45575
  }
44270
- return { leadingTerm, order: roundedOrder, coefficient };
45576
+ return { leadingTerm: leadingTerm2, order: roundedOrder, coefficient };
44271
45577
  }
44272
45578
  const lim = limit(expr, varName, towards);
44273
45579
  return { leadingTerm: formatCoeff(lim), order: 0, coefficient: lim };
@@ -44872,8 +46178,8 @@ function _combineLikeTerms(expr) {
44872
46178
  const cvpMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)\^(\d+)$/);
44873
46179
  if (cvpMatch) {
44874
46180
  const c = cvpMatch[1] === "" || cvpMatch[1] === "+" ? 1 : cvpMatch[1] === "-" ? -1 : Number(cvpMatch[1]);
44875
- const key = cvpMatch[2] + "^" + cvpMatch[3];
44876
- termMap.set(key, (termMap.get(key) ?? 0) + c);
46181
+ const key2 = cvpMatch[2] + "^" + cvpMatch[3];
46182
+ termMap.set(key2, (termMap.get(key2) ?? 0) + c);
44877
46183
  continue;
44878
46184
  }
44879
46185
  const cvMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)$/);
@@ -44885,16 +46191,16 @@ function _combineLikeTerms(expr) {
44885
46191
  otherTerms.push(t);
44886
46192
  }
44887
46193
  const parts = [];
44888
- for (const [key, c] of termMap) {
46194
+ for (const [key2, c] of termMap) {
44889
46195
  if (Math.abs(c) < 1e-12) continue;
44890
- if (key === "__const__") {
46196
+ if (key2 === "__const__") {
44891
46197
  parts.push(String(c));
44892
46198
  } else if (Math.abs(c - 1) < 1e-12) {
44893
- parts.push(key);
46199
+ parts.push(key2);
44894
46200
  } else if (Math.abs(c + 1) < 1e-12) {
44895
- parts.push("-" + key);
46201
+ parts.push("-" + key2);
44896
46202
  } else {
44897
- parts.push(c + "*" + key);
46203
+ parts.push(c + "*" + key2);
44898
46204
  }
44899
46205
  }
44900
46206
  parts.push(...otherTerms);
@@ -45048,8 +46354,8 @@ function casSimplify(input) {
45048
46354
  const cvpMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)\^(\d+)$/);
45049
46355
  if (cvpMatch) {
45050
46356
  const c = cvpMatch[1] === "" || cvpMatch[1] === "+" ? 1 : cvpMatch[1] === "-" ? -1 : Number(cvpMatch[1]);
45051
- const key = cvpMatch[2] + "^" + cvpMatch[3];
45052
- termMap.set(key, (termMap.get(key) ?? 0) + c);
46357
+ const key2 = cvpMatch[2] + "^" + cvpMatch[3];
46358
+ termMap.set(key2, (termMap.get(key2) ?? 0) + c);
45053
46359
  continue;
45054
46360
  }
45055
46361
  const cvMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)$/);
@@ -45061,16 +46367,16 @@ function casSimplify(input) {
45061
46367
  otherTerms.push(t);
45062
46368
  }
45063
46369
  const parts = [];
45064
- for (const [key, c] of termMap) {
46370
+ for (const [key2, c] of termMap) {
45065
46371
  if (Math.abs(c) < 1e-12) continue;
45066
- if (key === "__const__") {
46372
+ if (key2 === "__const__") {
45067
46373
  parts.push(String(c));
45068
46374
  } else if (Math.abs(c - 1) < 1e-12) {
45069
- parts.push(key);
46375
+ parts.push(key2);
45070
46376
  } else if (Math.abs(c + 1) < 1e-12) {
45071
- parts.push("-" + key);
46377
+ parts.push("-" + key2);
45072
46378
  } else {
45073
- parts.push(c + "*" + key);
46379
+ parts.push(c + "*" + key2);
45074
46380
  }
45075
46381
  }
45076
46382
  parts.push(...otherTerms);
@@ -45296,16 +46602,16 @@ function discreteLog(g, h, p) {
45296
46602
  const table = /* @__PURE__ */ new Map();
45297
46603
  let cur = 1n;
45298
46604
  for (let j = 0n; j < m; j++) {
45299
- const key = cur.toString();
45300
- if (!table.has(key)) table.set(key, j);
46605
+ const key2 = cur.toString();
46606
+ if (!table.has(key2)) table.set(key2, j);
45301
46607
  cur = cur * G % P2;
45302
46608
  }
45303
46609
  const gm = modPowBig(G, m, P2);
45304
46610
  const gInvM = modInverseBig(gm, P2);
45305
46611
  let gamma2 = H;
45306
46612
  for (let i = 0n; i < m; i++) {
45307
- const key = gamma2.toString();
45308
- const j = table.get(key);
46613
+ const key2 = gamma2.toString();
46614
+ const j = table.get(key2);
45309
46615
  if (j !== void 0) {
45310
46616
  return Number(i * m + j);
45311
46617
  }
@@ -46415,7 +47721,7 @@ function scale(alpha, x) {
46415
47721
  function subtract2(a, b) {
46416
47722
  return a.map((v, i) => v - b[i]);
46417
47723
  }
46418
- function add2(a, b) {
47724
+ function add3(a, b) {
46419
47725
  return a.map((v, i) => v + b[i]);
46420
47726
  }
46421
47727
  function zeros2(n) {
@@ -46584,7 +47890,7 @@ function cg(a, b, opts) {
46584
47890
  z = applyM(r);
46585
47891
  const rzNew = dot2(r, z);
46586
47892
  const beta2 = rzNew / rzOld;
46587
- p = add2(z, scale(beta2, p));
47893
+ p = add3(z, scale(beta2, p));
46588
47894
  rzOld = rzNew;
46589
47895
  }
46590
47896
  return { x, iterations, converged: residual < tol, residual };
@@ -46751,7 +48057,7 @@ function bicgstab(a, b, opts) {
46751
48057
  p = r.slice();
46752
48058
  } else {
46753
48059
  const beta2 = rhoNew / rho * (alpha / omega);
46754
- p = add2(r, scale(beta2, subtract2(p, scale(omega, v))));
48060
+ p = add3(r, scale(beta2, subtract2(p, scale(omega, v))));
46755
48061
  }
46756
48062
  rho = rhoNew;
46757
48063
  const pHat = applyM(p);
@@ -47004,12 +48310,12 @@ function svds(A, k = 1, opts) {
47004
48310
  }
47005
48311
 
47006
48312
  // src/numeric/structured-solvers.ts
47007
- function thomasSolve(sub3, diag2, sup, d) {
48313
+ function thomasSolve(sub4, diag2, sup, d) {
47008
48314
  const n = diag2.length;
47009
48315
  if (n === 0) return [];
47010
- if (sub3.length !== n - 1 || sup.length !== n - 1 || d.length !== n) {
48316
+ if (sub4.length !== n - 1 || sup.length !== n - 1 || d.length !== n) {
47011
48317
  throw new Error(
47012
- `thomasSolve: expected sub/sup of length ${n - 1} and d of length ${n}, got sub=${sub3.length}, sup=${sup.length}, d=${d.length}`
48318
+ `thomasSolve: expected sub/sup of length ${n - 1} and d of length ${n}, got sub=${sub4.length}, sup=${sup.length}, d=${d.length}`
47013
48319
  );
47014
48320
  }
47015
48321
  const cp = new Array(n).fill(0);
@@ -47018,12 +48324,12 @@ function thomasSolve(sub3, diag2, sup, d) {
47018
48324
  cp[0] = n > 1 ? sup[0] / diag2[0] : 0;
47019
48325
  dp[0] = d[0] / diag2[0];
47020
48326
  for (let i = 1; i < n; i++) {
47021
- const m = diag2[i] - sub3[i - 1] * cp[i - 1];
48327
+ const m = diag2[i] - sub4[i - 1] * cp[i - 1];
47022
48328
  if (m === 0) {
47023
48329
  throw new Error(`thomasSolve: zero pivot at row ${i} (no pivoting is performed)`);
47024
48330
  }
47025
48331
  cp[i] = i < n - 1 ? sup[i] / m : 0;
47026
- dp[i] = (d[i] - sub3[i - 1] * dp[i - 1]) / m;
48332
+ dp[i] = (d[i] - sub4[i - 1] * dp[i - 1]) / m;
47027
48333
  }
47028
48334
  const x = new Array(n);
47029
48335
  x[n - 1] = dp[n - 1];
@@ -47957,7 +49263,7 @@ function bsplineEval(spline, xnew) {
47957
49263
  }
47958
49264
 
47959
49265
  // src/numeric/monte-carlo.ts
47960
- function isPrime2(x) {
49266
+ function isPrime3(x) {
47961
49267
  if (x < 2) return false;
47962
49268
  for (let i = 2; i * i <= x; i++) {
47963
49269
  if (x % i === 0) return false;
@@ -47969,7 +49275,7 @@ function nthPrime(k) {
47969
49275
  let candidate = 1;
47970
49276
  while (count2 < k) {
47971
49277
  candidate++;
47972
- if (isPrime2(candidate)) count2++;
49278
+ if (isPrime3(candidate)) count2++;
47973
49279
  }
47974
49280
  return candidate;
47975
49281
  }
@@ -48607,18 +49913,18 @@ function nelderMead(f, x0, opts = {}) {
48607
49913
  for (let i = 0; i < n; i++) for (let j = 0; j < n; j++) c[j] += pts[i][j] / n;
48608
49914
  return c;
48609
49915
  };
48610
- const add4 = (a, b, s) => a.map((v, i) => v + s * b[i]);
48611
- const sub3 = (a, b) => a.map((v, i) => v - b[i]);
49916
+ const add5 = (a, b, s) => a.map((v, i) => v + s * b[i]);
49917
+ const sub4 = (a, b) => a.map((v, i) => v - b[i]);
48612
49918
  for (; iter < maxIter; iter++) {
48613
49919
  const order = fv.map((_, i) => i).sort((i, j) => fv[i] - fv[j]);
48614
49920
  simplex = order.map((i) => simplex[i]);
48615
49921
  fv = order.map((i) => fv[i]);
48616
49922
  if (Math.abs(fv[n] - fv[0]) <= tol * (Math.abs(fv[0]) + tol)) break;
48617
49923
  const c = centroid2(simplex.slice(0, n));
48618
- const xr = add4(c, sub3(c, simplex[n]), alpha);
49924
+ const xr = add5(c, sub4(c, simplex[n]), alpha);
48619
49925
  const fr = f(xr);
48620
49926
  if (fr < fv[0]) {
48621
- const xe = add4(c, sub3(c, simplex[n]), gamma2);
49927
+ const xe = add5(c, sub4(c, simplex[n]), gamma2);
48622
49928
  const fe = f(xe);
48623
49929
  if (fe < fr) {
48624
49930
  simplex[n] = xe;
@@ -48631,14 +49937,14 @@ function nelderMead(f, x0, opts = {}) {
48631
49937
  simplex[n] = xr;
48632
49938
  fv[n] = fr;
48633
49939
  } else {
48634
- const xc = add4(c, sub3(simplex[n], c), rho);
49940
+ const xc = add5(c, sub4(simplex[n], c), rho);
48635
49941
  const fc = f(xc);
48636
49942
  if (fc < fv[n]) {
48637
49943
  simplex[n] = xc;
48638
49944
  fv[n] = fc;
48639
49945
  } else {
48640
49946
  for (let i = 1; i <= n; i++) {
48641
- simplex[i] = add4(simplex[0], sub3(simplex[i], simplex[0]), sigma);
49947
+ simplex[i] = add5(simplex[0], sub4(simplex[i], simplex[0]), sigma);
48642
49948
  fv[i] = f(simplex[i]);
48643
49949
  }
48644
49950
  }
@@ -49655,23 +50961,23 @@ function polyFromRoots(roots) {
49655
50961
  return c.map((z) => z.re);
49656
50962
  }
49657
50963
  function relativeDegree(z, p) {
49658
- const degree2 = p.length - z.length;
49659
- if (degree2 < 0) throw new Error("Improper transfer function: fewer poles than zeros");
49660
- return degree2;
50964
+ const degree3 = p.length - z.length;
50965
+ if (degree3 < 0) throw new Error("Improper transfer function: fewer poles than zeros");
50966
+ return degree3;
49661
50967
  }
49662
50968
  function lp2lpZpk(z, p, k, wo) {
49663
- const degree2 = relativeDegree(z, p);
50969
+ const degree3 = relativeDegree(z, p);
49664
50970
  return {
49665
50971
  z: z.map((zv) => cScale2(zv, wo)),
49666
50972
  p: p.map((pv) => cScale2(pv, wo)),
49667
- k: k * Math.pow(wo, degree2)
50973
+ k: k * Math.pow(wo, degree3)
49668
50974
  };
49669
50975
  }
49670
50976
  function lp2hpZpk(z, p, k, wo) {
49671
- const degree2 = relativeDegree(z, p);
50977
+ const degree3 = relativeDegree(z, p);
49672
50978
  const woC = new Complex11(wo, 0);
49673
50979
  const zHp = z.map((zv) => cDiv2(woC, zv));
49674
- for (let i = 0; i < degree2; i++) zHp.push(new Complex11(0, 0));
50980
+ for (let i = 0; i < degree3; i++) zHp.push(new Complex11(0, 0));
49675
50981
  let prodZ = new Complex11(1, 0);
49676
50982
  for (const zv of z) prodZ = cMul2(prodZ, zv.negate());
49677
50983
  let prodP = new Complex11(1, 0);
@@ -49679,7 +50985,7 @@ function lp2hpZpk(z, p, k, wo) {
49679
50985
  return { z: zHp, p: p.map((pv) => cDiv2(woC, pv)), k: k * cDiv2(prodZ, prodP).re };
49680
50986
  }
49681
50987
  function lp2bpZpk(z, p, k, wo, bw) {
49682
- const degree2 = relativeDegree(z, p);
50988
+ const degree3 = relativeDegree(z, p);
49683
50989
  const wo2 = new Complex11(wo * wo, 0);
49684
50990
  const shift = (roots) => {
49685
50991
  const lp = roots.map((r) => cScale2(r, bw / 2));
@@ -49688,11 +50994,11 @@ function lp2bpZpk(z, p, k, wo, bw) {
49688
50994
  return plus.concat(minus);
49689
50995
  };
49690
50996
  const zBp = shift(z);
49691
- for (let i = 0; i < degree2; i++) zBp.push(new Complex11(0, 0));
49692
- return { z: zBp, p: shift(p), k: k * Math.pow(bw, degree2) };
50997
+ for (let i = 0; i < degree3; i++) zBp.push(new Complex11(0, 0));
50998
+ return { z: zBp, p: shift(p), k: k * Math.pow(bw, degree3) };
49693
50999
  }
49694
51000
  function lp2bsZpk(z, p, k, wo, bw) {
49695
- const degree2 = relativeDegree(z, p);
51001
+ const degree3 = relativeDegree(z, p);
49696
51002
  const wo2 = new Complex11(wo * wo, 0);
49697
51003
  const bw2 = new Complex11(bw / 2, 0);
49698
51004
  const shift = (roots) => {
@@ -49702,8 +51008,8 @@ function lp2bsZpk(z, p, k, wo, bw) {
49702
51008
  return plus.concat(minus);
49703
51009
  };
49704
51010
  const zBs = shift(z);
49705
- for (let i = 0; i < degree2; i++) zBs.push(new Complex11(0, wo));
49706
- for (let i = 0; i < degree2; i++) zBs.push(new Complex11(0, -wo));
51011
+ for (let i = 0; i < degree3; i++) zBs.push(new Complex11(0, wo));
51012
+ for (let i = 0; i < degree3; i++) zBs.push(new Complex11(0, -wo));
49707
51013
  let prodZ = new Complex11(1, 0);
49708
51014
  for (const zv of z) prodZ = cMul2(prodZ, zv.negate());
49709
51015
  let prodP = new Complex11(1, 0);
@@ -49711,10 +51017,10 @@ function lp2bsZpk(z, p, k, wo, bw) {
49711
51017
  return { z: zBs, p: shift(p), k: k * cDiv2(prodZ, prodP).re };
49712
51018
  }
49713
51019
  function bilinearZpk(z, p, k, fs) {
49714
- const degree2 = relativeDegree(z, p);
51020
+ const degree3 = relativeDegree(z, p);
49715
51021
  const fs2 = new Complex11(2 * fs, 0);
49716
51022
  const zZ = z.map((zv) => cDiv2(cAdd2(fs2, zv), cSub2(fs2, zv)));
49717
- for (let i = 0; i < degree2; i++) zZ.push(new Complex11(-1, 0));
51023
+ for (let i = 0; i < degree3; i++) zZ.push(new Complex11(-1, 0));
49718
51024
  let prodZ = new Complex11(1, 0);
49719
51025
  for (const zv of z) prodZ = cMul2(prodZ, cSub2(fs2, zv));
49720
51026
  let prodP = new Complex11(1, 0);
@@ -50899,10 +52205,10 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
50899
52205
  const wtx = [0, ...w];
50900
52206
  const dimsize = Math.ceil(numtaps / 2 + 2);
50901
52207
  const wrksize = gridDensity * dimsize;
50902
- const neg = jtype === 1 ? 0 : 1;
52208
+ const neg2 = jtype === 1 ? 0 : 1;
50903
52209
  const nodd = numtaps % 2;
50904
52210
  let nfcns = Math.floor(numtaps / 2);
50905
- if (nodd === 1 && neg === 0) nfcns += 1;
52211
+ if (nodd === 1 && neg2 === 0) nfcns += 1;
50906
52212
  const des = new Array(wrksize + 2).fill(0);
50907
52213
  const grid = new Array(wrksize + 2).fill(0);
50908
52214
  const wt = new Array(wrksize + 2).fill(0);
@@ -50911,7 +52217,7 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
50911
52217
  let delf = gridDensity * nfcns;
50912
52218
  delf = 0.5 / delf;
50913
52219
  grid[1] = edge[1];
50914
- if (neg !== 0 && edge[1] < delf) grid[1] = delf;
52220
+ if (neg2 !== 0 && edge[1] < delf) grid[1] = delf;
50915
52221
  let j = 1;
50916
52222
  let l = 1;
50917
52223
  let lband = 1;
@@ -50934,10 +52240,10 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
50934
52240
  grid[j] = edge[l];
50935
52241
  }
50936
52242
  let ngrid = j - 1;
50937
- if (neg === nodd && grid[ngrid] > 0.5 - delf) --ngrid;
52243
+ if (neg2 === nodd && grid[ngrid] > 0.5 - delf) --ngrid;
50938
52244
  if (ngrid < nfcns + 1)
50939
52245
  throw new Error("remez: band too narrow for the requested numtaps (grid underflow)");
50940
- if (neg <= 0) {
52246
+ if (neg2 <= 0) {
50941
52247
  if (nodd !== 1) {
50942
52248
  for (j = 1; j <= ngrid; j++) {
50943
52249
  const change = Math.cos(PI * grid[j]);
@@ -50968,7 +52274,7 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
50968
52274
  const h = new Array(numtaps + 1).fill(0);
50969
52275
  const nz = nfcns + 1;
50970
52276
  const nm1 = nfcns - 1;
50971
- if (neg <= 0) {
52277
+ if (neg2 <= 0) {
50972
52278
  if (nodd !== 0) {
50973
52279
  for (j = 1; j <= nm1; j++) h[j] = 0.5 * alpha[nz - j];
50974
52280
  h[nfcns] = alpha[1];
@@ -50992,9 +52298,9 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
50992
52298
  }
50993
52299
  for (j = 1; j <= nfcns; j++) {
50994
52300
  const k = numtaps + 1 - j;
50995
- h[k] = neg === 0 ? h[j] : -h[j];
52301
+ h[k] = neg2 === 0 ? h[j] : -h[j];
50996
52302
  }
50997
- if (neg === 1 && nodd === 1) h[nz] = 0;
52303
+ if (neg2 === 1 && nodd === 1) h[nz] = 0;
50998
52304
  return h.slice(1);
50999
52305
  }
51000
52306
 
@@ -51729,10 +53035,10 @@ function setDisjoint(a, b) {
51729
53035
 
51730
53036
  // src/geometry/intersect3d.ts
51731
53037
  var EPS3 = 1e-12;
51732
- function sub(a, b) {
53038
+ function sub2(a, b) {
51733
53039
  return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
51734
53040
  }
51735
- function add3(a, b) {
53041
+ function add4(a, b) {
51736
53042
  return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
51737
53043
  }
51738
53044
  function scale3(a, s) {
@@ -51745,13 +53051,13 @@ function cross2(a, b) {
51745
53051
  return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
51746
53052
  }
51747
53053
  function rayTriangleIntersect(origin, dir, v0, v1, v2) {
51748
- const e1 = sub(v1, v0);
51749
- const e2 = sub(v2, v0);
53054
+ const e1 = sub2(v1, v0);
53055
+ const e2 = sub2(v2, v0);
51750
53056
  const pvec = cross2(dir, e2);
51751
53057
  const det2 = dot7(e1, pvec);
51752
53058
  if (Math.abs(det2) < EPS3) return null;
51753
53059
  const invDet = 1 / det2;
51754
- const tvec = sub(origin, v0);
53060
+ const tvec = sub2(origin, v0);
51755
53061
  const u = dot7(tvec, pvec) * invDet;
51756
53062
  if (u < 0 || u > 1) return null;
51757
53063
  const qvec = cross2(tvec, e1);
@@ -51759,21 +53065,21 @@ function rayTriangleIntersect(origin, dir, v0, v1, v2) {
51759
53065
  if (v < 0 || u + v > 1) return null;
51760
53066
  const t = dot7(e2, qvec) * invDet;
51761
53067
  if (t < 0) return null;
51762
- return { point: add3(origin, scale3(dir, t)), t };
53068
+ return { point: add4(origin, scale3(dir, t)), t };
51763
53069
  }
51764
53070
  function rayPlaneIntersect(origin, dir, planePoint, planeNormal) {
51765
53071
  const denom = dot7(dir, planeNormal);
51766
53072
  if (Math.abs(denom) < EPS3) return null;
51767
- const t = dot7(sub(planePoint, origin), planeNormal) / denom;
51768
- return { point: add3(origin, scale3(dir, t)), t };
53073
+ const t = dot7(sub2(planePoint, origin), planeNormal) / denom;
53074
+ return { point: add4(origin, scale3(dir, t)), t };
51769
53075
  }
51770
53076
  function clamp01(x) {
51771
53077
  return x < 0 ? 0 : x > 1 ? 1 : x;
51772
53078
  }
51773
53079
  function segmentSegmentClosest(p1, p2, q1, q2) {
51774
- const d1 = sub(p2, p1);
51775
- const d2 = sub(q2, q1);
51776
- const r = sub(p1, q1);
53080
+ const d1 = sub2(p2, p1);
53081
+ const d2 = sub2(q2, q1);
53082
+ const r = sub2(p1, q1);
51777
53083
  const a = dot7(d1, d1);
51778
53084
  const e = dot7(d2, d2);
51779
53085
  const f = dot7(d2, r);
@@ -51804,9 +53110,9 @@ function segmentSegmentClosest(p1, p2, q1, q2) {
51804
53110
  }
51805
53111
  }
51806
53112
  }
51807
- const point1 = add3(p1, scale3(d1, s));
51808
- const point2 = add3(q1, scale3(d2, t));
51809
- const distance2 = Math.sqrt(dot7(sub(point1, point2), sub(point1, point2)));
53113
+ const point1 = add4(p1, scale3(d1, s));
53114
+ const point2 = add4(q1, scale3(d2, t));
53115
+ const distance2 = Math.sqrt(dot7(sub2(point1, point2), sub2(point1, point2)));
51810
53116
  return { point1, point2, distance: distance2 };
51811
53117
  }
51812
53118
 
@@ -51964,14 +53270,14 @@ function alphaShape(points, alpha) {
51964
53270
  [t[2], t[0]]
51965
53271
  ];
51966
53272
  for (const [u, v] of es) {
51967
- const key = `${Math.min(u, v)},${Math.max(u, v)}`;
51968
- edgeCount.set(key, (edgeCount.get(key) ?? 0) + 1);
53273
+ const key2 = `${Math.min(u, v)},${Math.max(u, v)}`;
53274
+ edgeCount.set(key2, (edgeCount.get(key2) ?? 0) + 1);
51969
53275
  }
51970
53276
  }
51971
53277
  const edges = [];
51972
- for (const [key, count2] of edgeCount) {
53278
+ for (const [key2, count2] of edgeCount) {
51973
53279
  if (count2 === 1) {
51974
- const [lo, hi] = key.split(",").map(Number);
53280
+ const [lo, hi] = key2.split(",").map(Number);
51975
53281
  edges.push([lo, hi]);
51976
53282
  }
51977
53283
  }
@@ -51979,7 +53285,7 @@ function alphaShape(points, alpha) {
51979
53285
  }
51980
53286
 
51981
53287
  // src/geometry/spherical-voronoi.ts
51982
- function sub2(a, b) {
53288
+ function sub3(a, b) {
51983
53289
  return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
51984
53290
  }
51985
53291
  function cross3(a, b) {
@@ -52013,7 +53319,7 @@ function sphericalVoronoi(points, radius = 1, center3 = [0, 0, 0]) {
52013
53319
  if (points[0].length !== 3) {
52014
53320
  throw new Error("sphericalVoronoi: only 3-D point sets are supported");
52015
53321
  }
52016
- const gen = points.map((p) => normalize2(sub2(p, center3)));
53322
+ const gen = points.map((p) => normalize2(sub3(p, center3)));
52017
53323
  const faces = convexHull3D(points);
52018
53324
  const vertices = [];
52019
53325
  const vertDir = [];
@@ -52022,7 +53328,7 @@ function sphericalVoronoi(points, radius = 1, center3 = [0, 0, 0]) {
52022
53328
  const a = gen[f[0]];
52023
53329
  const b = gen[f[1]];
52024
53330
  const c = gen[f[2]];
52025
- let nrm = cross3(sub2(b, a), sub2(c, a));
53331
+ let nrm = cross3(sub3(b, a), sub3(c, a));
52026
53332
  if (dot8(nrm, a) < 0) nrm = [-nrm[0], -nrm[1], -nrm[2]];
52027
53333
  const dir = normalize2(nrm);
52028
53334
  vertDir.push(dir);
@@ -52042,7 +53348,7 @@ function sphericalVoronoi(points, radius = 1, center3 = [0, 0, 0]) {
52042
53348
  const withAngle = facs.map((fi) => {
52043
53349
  const d = vertDir[fi];
52044
53350
  const tang = normalize2(
52045
- sub2(d, [gdir[0] * dot8(d, gdir), gdir[1] * dot8(d, gdir), gdir[2] * dot8(d, gdir)])
53351
+ sub3(d, [gdir[0] * dot8(d, gdir), gdir[1] * dot8(d, gdir), gdir[2] * dot8(d, gdir)])
52046
53352
  );
52047
53353
  if (ref === null) {
52048
53354
  ref = tang;
@@ -52212,9 +53518,9 @@ function halfspaceIntersection(halfspaces, interiorPoint) {
52212
53518
  const vertices = [];
52213
53519
  const seen = /* @__PURE__ */ new Set();
52214
53520
  for (const v of candidates) {
52215
- const key = quantum > 0 ? v.map((x) => Math.round(x / quantum)).join(",") : v.join(",");
52216
- if (seen.has(key)) continue;
52217
- seen.add(key);
53521
+ const key2 = quantum > 0 ? v.map((x) => Math.round(x / quantum)).join(",") : v.join(",");
53522
+ if (seen.has(key2)) continue;
53523
+ seen.add(key2);
52218
53524
  vertices.push(v);
52219
53525
  }
52220
53526
  if (dim === 2 && vertices.length > 2) {
@@ -52889,8 +54195,8 @@ function buildMatrix(cls, q) {
52889
54195
  }
52890
54196
  var modeCache = /* @__PURE__ */ new Map();
52891
54197
  function solveClass(cls, q) {
52892
- const key = `${cls}:${q}`;
52893
- const cached = modeCache.get(key);
54198
+ const key2 = `${cls}:${q}`;
54199
+ const cached = modeCache.get(key2);
52894
54200
  if (cached) return cached;
52895
54201
  const harmonics = harmonicsFor(cls);
52896
54202
  const { values, vectors } = eig4(buildMatrix(cls, q));
@@ -52914,7 +54220,7 @@ function solveClass(cls, q) {
52914
54220
  for (let k = 0; k < N; k++) coeffs[k] *= sign3;
52915
54221
  return { a: values[idx].re, coeffs, harmonics };
52916
54222
  });
52917
- modeCache.set(key, modes);
54223
+ modeCache.set(key2, modes);
52918
54224
  return modes;
52919
54225
  }
52920
54226
  function checkOrder(n, min2, name254) {
@@ -53434,14 +54740,14 @@ function graphColoring(adj) {
53434
54740
  const n = adj.length;
53435
54741
  const colors = new Array(n).fill(-1);
53436
54742
  if (n === 0) return colors;
53437
- const degree2 = new Array(n).fill(0);
54743
+ const degree3 = new Array(n).fill(0);
53438
54744
  for (let i = 0; i < n; i++) {
53439
54745
  for (let j = 0; j < n; j++) {
53440
- if (i !== j && _undirectedEdgeExists(adj, i, j)) degree2[i]++;
54746
+ if (i !== j && _undirectedEdgeExists(adj, i, j)) degree3[i]++;
53441
54747
  }
53442
54748
  }
53443
54749
  const order = Array.from({ length: n }, (_, i) => i).sort(
53444
- (a, b) => degree2[b] - degree2[a] || a - b
54750
+ (a, b) => degree3[b] - degree3[a] || a - b
53445
54751
  );
53446
54752
  for (const v of order) {
53447
54753
  const usedByNeighbor = /* @__PURE__ */ new Set();
@@ -54305,7 +55611,7 @@ export {
54305
55611
  coherence,
54306
55612
  collect,
54307
55613
  column,
54308
- combinations,
55614
+ combinations2 as combinations,
54309
55615
  combinationsGen,
54310
55616
  combinationsWithRep,
54311
55617
  combine,
@@ -54381,10 +55687,10 @@ export {
54381
55687
  decimate,
54382
55688
  deconvolve,
54383
55689
  deepEqual,
54384
- degree,
55690
+ degree2 as degree,
54385
55691
  delaunay,
54386
55692
  delaunayTriangulation,
54387
- derivative,
55693
+ derivative2 as derivative,
54388
55694
  derivativeAt,
54389
55695
  describe,
54390
55696
  det,
@@ -54684,8 +55990,8 @@ export {
54684
55990
  isNegative,
54685
55991
  isNumeric,
54686
55992
  isPositive,
54687
- isPrime,
54688
- isZero,
55993
+ isPrime2 as isPrime,
55994
+ isZero3 as isZero,
54689
55995
  istft,
54690
55996
  jacobiCN,
54691
55997
  jacobiDN,
@@ -55122,7 +56428,7 @@ export {
55122
56428
  studentizedRangeQuantile,
55123
56429
  subfactorial,
55124
56430
  subset,
55125
- substitute,
56431
+ substitute2 as substitute,
55126
56432
  subtract,
55127
56433
  subtractScalar,
55128
56434
  sum,