@danielsimonjr/mathts-functions 0.55.0 → 0.57.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
@@ -3918,32 +3918,32 @@ function nextPowerOf2(n) {
3918
3918
  return Math.pow(2, Math.ceil(Math.log2(n)));
3919
3919
  }
3920
3920
  async function fourStepFFT(real, imag, inverse) {
3921
- const N = real.length;
3922
- if (N < 4 || !isPowerOf22(N)) {
3921
+ const N2 = real.length;
3922
+ if (N2 < 4 || !isPowerOf22(N2)) {
3923
3923
  return fftCoreFloat64(real, imag, inverse);
3924
3924
  }
3925
- const bits = Math.round(Math.log2(N));
3925
+ const bits = Math.round(Math.log2(N2));
3926
3926
  const bits1 = bits >> 1;
3927
3927
  const N1 = 1 << bits1;
3928
- const N2 = N / N1;
3928
+ const N22 = N2 / N1;
3929
3929
  const sign3 = inverse ? 1 : -1;
3930
- const aReal = new Float64Array(N2 * N1);
3931
- const aImag = new Float64Array(N2 * N1);
3932
- for (let n26 = 0; n26 < N2; n26++) {
3930
+ const aReal = new Float64Array(N22 * N1);
3931
+ const aImag = new Float64Array(N22 * N1);
3932
+ for (let n26 = 0; n26 < N22; n26++) {
3933
3933
  const base = n26 * N1;
3934
3934
  for (let n16 = 0; n16 < N1; n16++) {
3935
- const src = N2 * n16 + n26;
3935
+ const src = N22 * n16 + n26;
3936
3936
  aReal[base + n16] = real[src];
3937
3937
  aImag[base + n16] = imag[src];
3938
3938
  }
3939
3939
  }
3940
- const stepA = await computePool4.fftBatch(aReal, aImag, N2, N1, inverse);
3940
+ const stepA = await computePool4.fftBatch(aReal, aImag, N22, N1, inverse);
3941
3941
  const aOutReal = stepA.result.real;
3942
3942
  const aOutImag = stepA.result.imag;
3943
- const cReal = new Float64Array(N1 * N2);
3944
- const cImag = new Float64Array(N1 * N2);
3945
- const twN = sign3 * 2 * Math.PI / N;
3946
- for (let n26 = 0; n26 < N2; n26++) {
3943
+ const cReal = new Float64Array(N1 * N22);
3944
+ const cImag = new Float64Array(N1 * N22);
3945
+ const twN = sign3 * 2 * Math.PI / N2;
3946
+ for (let n26 = 0; n26 < N22; n26++) {
3947
3947
  const aBase = n26 * N1;
3948
3948
  for (let k1 = 0; k1 < N1; k1++) {
3949
3949
  const ar = aOutReal[aBase + k1];
@@ -3951,19 +3951,19 @@ async function fourStepFFT(real, imag, inverse) {
3951
3951
  const ang = twN * n26 * k1;
3952
3952
  const wr = Math.cos(ang);
3953
3953
  const wi = Math.sin(ang);
3954
- const dst2 = k1 * N2 + n26;
3954
+ const dst2 = k1 * N22 + n26;
3955
3955
  cReal[dst2] = ar * wr - ai * wi;
3956
3956
  cImag[dst2] = ar * wi + ai * wr;
3957
3957
  }
3958
3958
  }
3959
- const stepC = await computePool4.fftBatch(cReal, cImag, N1, N2, inverse);
3959
+ const stepC = await computePool4.fftBatch(cReal, cImag, N1, N22, inverse);
3960
3960
  const cOutReal = stepC.result.real;
3961
3961
  const cOutImag = stepC.result.imag;
3962
- const outReal = new Float64Array(N);
3963
- const outImag = new Float64Array(N);
3962
+ const outReal = new Float64Array(N2);
3963
+ const outImag = new Float64Array(N2);
3964
3964
  for (let k1 = 0; k1 < N1; k1++) {
3965
- const cBase = k1 * N2;
3966
- for (let k2 = 0; k2 < N2; k2++) {
3965
+ const cBase = k1 * N22;
3966
+ for (let k2 = 0; k2 < N22; k2++) {
3967
3967
  const dst2 = N1 * k2 + k1;
3968
3968
  outReal[dst2] = cOutReal[cBase + k2];
3969
3969
  outImag[dst2] = cOutImag[cBase + k2];
@@ -4189,15 +4189,15 @@ function unwrapPhase(phase) {
4189
4189
  return result;
4190
4190
  }
4191
4191
  function dct(x) {
4192
- const N = x.length;
4193
- if (N >= WASM_THRESHOLD) {
4192
+ const N2 = x.length;
4193
+ if (N2 >= WASM_THRESHOLD) {
4194
4194
  const wasm = wasmLoader.getModule();
4195
4195
  if (wasm) {
4196
4196
  try {
4197
4197
  const inAlloc = wasmLoader.allocateFloat64Array(x);
4198
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
4198
+ const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4199
4199
  try {
4200
- wasm.dct_wasm(inAlloc.ptr, outAlloc.ptr, N);
4200
+ wasm.dct_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4201
4201
  return Array.from(outAlloc.array);
4202
4202
  } finally {
4203
4203
  wasmLoader.free(inAlloc.ptr);
@@ -4207,26 +4207,26 @@ function dct(x) {
4207
4207
  }
4208
4208
  }
4209
4209
  }
4210
- const result = new Array(N);
4211
- for (let k = 0; k < N; k++) {
4210
+ const result = new Array(N2);
4211
+ for (let k = 0; k < N2; k++) {
4212
4212
  let sum3 = 0;
4213
- for (let n = 0; n < N; n++) {
4214
- sum3 += x[n] * Math.cos(Math.PI / N * (n + 0.5) * k);
4213
+ for (let n = 0; n < N2; n++) {
4214
+ sum3 += x[n] * Math.cos(Math.PI / N2 * (n + 0.5) * k);
4215
4215
  }
4216
- result[k] = sum3 * (k === 0 ? Math.sqrt(1 / N) : Math.sqrt(2 / N));
4216
+ result[k] = sum3 * (k === 0 ? Math.sqrt(1 / N2) : Math.sqrt(2 / N2));
4217
4217
  }
4218
4218
  return result;
4219
4219
  }
4220
4220
  function idct(X) {
4221
- const N = X.length;
4222
- if (N >= WASM_THRESHOLD) {
4221
+ const N2 = X.length;
4222
+ if (N2 >= WASM_THRESHOLD) {
4223
4223
  const wasm = wasmLoader.getModule();
4224
4224
  if (wasm) {
4225
4225
  try {
4226
4226
  const inAlloc = wasmLoader.allocateFloat64Array(X);
4227
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
4227
+ const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4228
4228
  try {
4229
- wasm.idct_wasm(inAlloc.ptr, outAlloc.ptr, N);
4229
+ wasm.idct_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4230
4230
  return Array.from(outAlloc.array);
4231
4231
  } finally {
4232
4232
  wasmLoader.free(inAlloc.ptr);
@@ -4236,26 +4236,26 @@ function idct(X) {
4236
4236
  }
4237
4237
  }
4238
4238
  }
4239
- const result = new Array(N);
4240
- for (let n = 0; n < N; n++) {
4241
- let sum3 = X[0] * Math.sqrt(1 / N);
4242
- for (let k = 1; k < N; k++) {
4243
- sum3 += X[k] * Math.sqrt(2 / N) * Math.cos(Math.PI / N * (n + 0.5) * k);
4239
+ const result = new Array(N2);
4240
+ for (let n = 0; n < N2; n++) {
4241
+ let sum3 = X[0] * Math.sqrt(1 / N2);
4242
+ for (let k = 1; k < N2; k++) {
4243
+ sum3 += X[k] * Math.sqrt(2 / N2) * Math.cos(Math.PI / N2 * (n + 0.5) * k);
4244
4244
  }
4245
4245
  result[n] = sum3;
4246
4246
  }
4247
4247
  return result;
4248
4248
  }
4249
4249
  function dst(x) {
4250
- const N = x.length;
4251
- if (N >= WASM_THRESHOLD) {
4250
+ const N2 = x.length;
4251
+ if (N2 >= WASM_THRESHOLD) {
4252
4252
  const wasm = wasmLoader.getModule();
4253
4253
  if (wasm) {
4254
4254
  try {
4255
4255
  const inAlloc = wasmLoader.allocateFloat64Array(x);
4256
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
4256
+ const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4257
4257
  try {
4258
- wasm.dst_wasm(inAlloc.ptr, outAlloc.ptr, N);
4258
+ wasm.dst_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4259
4259
  return Array.from(outAlloc.array);
4260
4260
  } finally {
4261
4261
  wasmLoader.free(inAlloc.ptr);
@@ -4265,26 +4265,26 @@ function dst(x) {
4265
4265
  }
4266
4266
  }
4267
4267
  }
4268
- const result = new Array(N);
4269
- for (let k = 0; k < N; k++) {
4268
+ const result = new Array(N2);
4269
+ for (let k = 0; k < N2; k++) {
4270
4270
  let sum3 = 0;
4271
- for (let n = 0; n < N; n++) {
4272
- sum3 += x[n] * Math.sin(Math.PI / N * (n + 0.5) * (k + 1));
4271
+ for (let n = 0; n < N2; n++) {
4272
+ sum3 += x[n] * Math.sin(Math.PI / N2 * (n + 0.5) * (k + 1));
4273
4273
  }
4274
- result[k] = sum3 * Math.sqrt(2 / N);
4274
+ result[k] = sum3 * Math.sqrt(2 / N2);
4275
4275
  }
4276
4276
  return result;
4277
4277
  }
4278
4278
  function idst(X) {
4279
- const N = X.length;
4280
- if (N >= WASM_THRESHOLD) {
4279
+ const N2 = X.length;
4280
+ if (N2 >= WASM_THRESHOLD) {
4281
4281
  const wasm = wasmLoader.getModule();
4282
4282
  if (wasm) {
4283
4283
  try {
4284
4284
  const inAlloc = wasmLoader.allocateFloat64Array(X);
4285
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
4285
+ const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4286
4286
  try {
4287
- wasm.idst_wasm(inAlloc.ptr, outAlloc.ptr, N);
4287
+ wasm.idst_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4288
4288
  return Array.from(outAlloc.array);
4289
4289
  } finally {
4290
4290
  wasmLoader.free(inAlloc.ptr);
@@ -4294,12 +4294,12 @@ function idst(X) {
4294
4294
  }
4295
4295
  }
4296
4296
  }
4297
- const result = new Array(N);
4298
- for (let n = 0; n < N; n++) {
4297
+ const result = new Array(N2);
4298
+ for (let n = 0; n < N2; n++) {
4299
4299
  let sum3 = 0;
4300
- for (let k = 0; k < N; k++) {
4301
- const factor2 = k === N - 1 ? Math.sqrt(1 / N) : Math.sqrt(2 / N);
4302
- sum3 += X[k] * factor2 * Math.sin(Math.PI / N * (n + 0.5) * (k + 1));
4300
+ for (let k = 0; k < N2; k++) {
4301
+ const factor2 = k === N2 - 1 ? Math.sqrt(1 / N2) : Math.sqrt(2 / N2);
4302
+ sum3 += X[k] * factor2 * Math.sin(Math.PI / N2 * (n + 0.5) * (k + 1));
4303
4303
  }
4304
4304
  result[n] = sum3;
4305
4305
  }
@@ -4446,20 +4446,20 @@ function invFourier(F, omega, t) {
4446
4446
  }
4447
4447
  function hilbertTransform(x) {
4448
4448
  const n = x.length;
4449
- const N = nextPowerOf2(n);
4450
- if (N >= WASM_THRESHOLD) {
4449
+ const N2 = nextPowerOf2(n);
4450
+ if (N2 >= WASM_THRESHOLD) {
4451
4451
  const wasm = wasmLoader.getModule();
4452
4452
  if (wasm) {
4453
4453
  try {
4454
- const paddedInput = new Array(N).fill(0);
4454
+ const paddedInput = new Array(N2).fill(0);
4455
4455
  for (let i = 0; i < n; i++) paddedInput[i] = x[i];
4456
- const zeros4 = new Array(N).fill(0);
4456
+ const zeros4 = new Array(N2).fill(0);
4457
4457
  const inReAlloc = wasmLoader.allocateFloat64Array(paddedInput);
4458
4458
  const inImAlloc = wasmLoader.allocateFloat64Array(zeros4);
4459
- const outReAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
4460
- const outImAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
4459
+ const outReAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4460
+ const outImAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4461
4461
  try {
4462
- wasm.hilbert_wasm(inReAlloc.ptr, inImAlloc.ptr, outReAlloc.ptr, outImAlloc.ptr, N);
4462
+ wasm.hilbert_wasm(inReAlloc.ptr, inImAlloc.ptr, outReAlloc.ptr, outImAlloc.ptr, N2);
4463
4463
  return Array.from(outImAlloc.array.slice(0, n));
4464
4464
  } finally {
4465
4465
  wasmLoader.free(inReAlloc.ptr);
@@ -4471,16 +4471,16 @@ function hilbertTransform(x) {
4471
4471
  }
4472
4472
  }
4473
4473
  }
4474
- const real = new Float64Array(N);
4475
- const imag = new Float64Array(N);
4474
+ const real = new Float64Array(N2);
4475
+ const imag = new Float64Array(N2);
4476
4476
  for (let i = 0; i < n; i++) real[i] = x[i];
4477
4477
  const spectrum = fftCoreFloat64(real, imag, false);
4478
- const hReal = new Float64Array(N);
4479
- const hImag = new Float64Array(N);
4478
+ const hReal = new Float64Array(N2);
4479
+ const hImag = new Float64Array(N2);
4480
4480
  hReal[0] = spectrum.real[0];
4481
4481
  hImag[0] = spectrum.imag[0];
4482
- if (N > 1) {
4483
- const half = N / 2;
4482
+ if (N2 > 1) {
4483
+ const half = N2 / 2;
4484
4484
  for (let i = 1; i < half; i++) {
4485
4485
  hReal[i] = 2 * spectrum.real[i];
4486
4486
  hImag[i] = 2 * spectrum.imag[i];
@@ -10400,10 +10400,10 @@ function cancel(expr) {
10400
10400
  if (dens.length > 0) {
10401
10401
  const numStr = nums.length ? nums.join("*") : "1";
10402
10402
  const denStr = dens.join("*");
10403
- const N = polyToDense(polyFromExpression(numStr, [v]));
10403
+ const N2 = polyToDense(polyFromExpression(numStr, [v]));
10404
10404
  const D = polyToDense(polyFromExpression(denStr, [v]));
10405
- if (N.every(isNearInt) && D.every(isNearInt)) {
10406
- const Nint = N.map((c) => Math.round(c));
10405
+ if (N2.every(isNearInt) && D.every(isNearInt)) {
10406
+ const Nint = N2.map((c) => Math.round(c));
10407
10407
  const Dint = D.map((c) => Math.round(c));
10408
10408
  const g = polynomialGCD(Nint, Dint);
10409
10409
  if (degree(g) >= 1) {
@@ -10501,10 +10501,10 @@ function apart(expr) {
10501
10501
  if (dens.length > 0) {
10502
10502
  const numStr = nums.length ? nums.join("*") : "1";
10503
10503
  const denStr = dens.join("*");
10504
- const N = polyToDense(polyFromExpression(numStr, [v]));
10504
+ const N2 = polyToDense(polyFromExpression(numStr, [v]));
10505
10505
  const D = polyToDense(polyFromExpression(denStr, [v]));
10506
- if (degree(D) >= 1 && N.every(isNearInt) && D.every(isNearInt)) {
10507
- let Nint = N.map((c) => Math.round(c));
10506
+ if (degree(D) >= 1 && N2.every(isNearInt) && D.every(isNearInt)) {
10507
+ let Nint = N2.map((c) => Math.round(c));
10508
10508
  const Dint = D.map((c) => Math.round(c));
10509
10509
  let quotientPrefix = "";
10510
10510
  if (degree(Nint) >= degree(Dint)) {
@@ -13454,8 +13454,8 @@ function solveDAE(f, g, tspan, y0, z0, options = {}) {
13454
13454
  for (let it = 0; it < 12; it++) {
13455
13455
  const R0 = residual(wc);
13456
13456
  const J = newtonMatrix(tNew, wc, c0, residual, R0);
13457
- const solve2 = _factorSolver(J, n);
13458
- const dw = solve2(R0.map((v) => -v));
13457
+ const solve4 = _factorSolver(J, n);
13458
+ const dw = solve4(R0.map((v) => -v));
13459
13459
  if (!dw.every((v) => Number.isFinite(v))) break;
13460
13460
  for (let i = 0; i < n; i++) {
13461
13461
  wc[i] += dw[i];
@@ -17018,13 +17018,13 @@ function hypergeometricDist(population, successes, draws) {
17018
17018
  }
17019
17019
  const M = population;
17020
17020
  const K = successes;
17021
- const N = draws;
17022
- const kMin = Math.max(0, N - (M - K));
17023
- const kMax = Math.min(K, N);
17021
+ const N2 = draws;
17022
+ const kMin = Math.max(0, N2 - (M - K));
17023
+ const kMax = Math.min(K, N2);
17024
17024
  const useExact = M <= 1e3;
17025
17025
  const pmf = (k) => {
17026
17026
  if (!Number.isInteger(k) || k < kMin || k > kMax) return 0;
17027
- return useExact ? _choose(K, k) * _choose(M - K, N - k) / _choose(M, N) : Math.exp(_logChoose(K, k) + _logChoose(M - K, N - k) - _logChoose(M, N));
17027
+ return useExact ? _choose(K, k) * _choose(M - K, N2 - k) / _choose(M, N2) : Math.exp(_logChoose(K, k) + _logChoose(M - K, N2 - k) - _logChoose(M, N2));
17028
17028
  };
17029
17029
  const cdf = (k) => {
17030
17030
  if (k < kMin) return 0;
@@ -17033,8 +17033,8 @@ function hypergeometricDist(population, successes, draws) {
17033
17033
  for (let i = kMin; i <= kk; i++) sum3 += pmf(i);
17034
17034
  return Math.min(1, sum3);
17035
17035
  };
17036
- const mean7 = N * K / M;
17037
- const variance2 = N * (K / M) * ((M - K) / M) * ((M - N) / (M - 1));
17036
+ const mean7 = N2 * K / M;
17037
+ const variance2 = N2 * (K / M) * ((M - K) / M) * ((M - N2) / (M - 1));
17038
17038
  return {
17039
17039
  pdf: pmf,
17040
17040
  cdf,
@@ -17701,19 +17701,19 @@ async function chiSquareTest(observed, expected, opts) {
17701
17701
  function anova(groups) {
17702
17702
  if (groups.length < 2) throw new Error("anova: need at least 2 groups");
17703
17703
  const k = groups.length;
17704
- let N = 0;
17704
+ let N2 = 0;
17705
17705
  let grandSum = 0;
17706
17706
  const groupMeans = [];
17707
17707
  const groupSizes = [];
17708
17708
  for (const group of groups) {
17709
17709
  if (group.length < 1) throw new Error("anova: each group must have at least 1 element");
17710
17710
  groupSizes.push(group.length);
17711
- N += group.length;
17711
+ N2 += group.length;
17712
17712
  const m = _mean(group);
17713
17713
  groupMeans.push(m);
17714
17714
  for (const x of group) grandSum += x;
17715
17715
  }
17716
- const grandMean = grandSum / N;
17716
+ const grandMean = grandSum / N2;
17717
17717
  let ssBetween = 0;
17718
17718
  for (let i = 0; i < k; i++) {
17719
17719
  ssBetween += groupSizes[i] * (groupMeans[i] - grandMean) ** 2;
@@ -17725,7 +17725,7 @@ function anova(groups) {
17725
17725
  }
17726
17726
  }
17727
17727
  const dfBetween = k - 1;
17728
- const dfWithin = N - k;
17728
+ const dfWithin = N2 - k;
17729
17729
  if (dfWithin <= 0) throw new Error("anova: insufficient degrees of freedom");
17730
17730
  const msBetween = ssBetween / dfBetween;
17731
17731
  const msWithin = ssWithin / dfWithin;
@@ -18256,10 +18256,10 @@ function _median(arr10) {
18256
18256
  function leveneTest(groups, center3 = "median") {
18257
18257
  const k = groups.length;
18258
18258
  if (k < 2) throw new Error("leveneTest: need at least 2 groups");
18259
- let N = 0;
18259
+ let N2 = 0;
18260
18260
  for (const g of groups) {
18261
18261
  if (g.length < 1) throw new Error("leveneTest: every group must be non-empty");
18262
- N += g.length;
18262
+ N2 += g.length;
18263
18263
  }
18264
18264
  const z = groups.map((g) => {
18265
18265
  const c = center3 === "median" ? _median(g) : _mean(g);
@@ -18275,16 +18275,16 @@ function leveneTest(groups, center3 = "median") {
18275
18275
  num2 += zi.length * (zBarI - zBarAll) * (zBarI - zBarAll);
18276
18276
  for (const v of zi) den += (v - zBarI) * (v - zBarI);
18277
18277
  }
18278
- const W = (N - k) / (k - 1) * (num2 / den);
18279
- return { statistic: W, pValue: _fPValue(W, k - 1, N - k), degreesOfFreedom: [k - 1, N - k] };
18278
+ const W = (N2 - k) / (k - 1) * (num2 / den);
18279
+ return { statistic: W, pValue: _fPValue(W, k - 1, N2 - k), degreesOfFreedom: [k - 1, N2 - k] };
18280
18280
  }
18281
18281
  function bartlettTest(groups) {
18282
18282
  const k = groups.length;
18283
18283
  if (k < 2) throw new Error("bartlettTest: need at least 2 groups");
18284
- let N = 0;
18284
+ let N2 = 0;
18285
18285
  for (const g of groups) {
18286
18286
  if (g.length < 2) throw new Error("bartlettTest: every group needs \u22652 observations");
18287
- N += g.length;
18287
+ N2 += g.length;
18288
18288
  }
18289
18289
  let pooledNum = 0;
18290
18290
  let sumLnVar = 0;
@@ -18296,9 +18296,9 @@ function bartlettTest(groups) {
18296
18296
  sumLnVar += (ni - 1) * Math.log(si2);
18297
18297
  sumInv += 1 / (ni - 1);
18298
18298
  }
18299
- const sp2 = pooledNum / (N - k);
18300
- const numerator = (N - k) * Math.log(sp2) - sumLnVar;
18301
- const C = 1 + (sumInv - 1 / (N - k)) / (3 * (k - 1));
18299
+ const sp2 = pooledNum / (N2 - k);
18300
+ const numerator = (N2 - k) * Math.log(sp2) - sumLnVar;
18301
+ const C = 1 + (sumInv - 1 / (N2 - k)) / (3 * (k - 1));
18302
18302
  const T = numerator / C;
18303
18303
  return { statistic: T, pValue: _chiSquaredPValue(T, k - 1), degreesOfFreedom: k - 1 };
18304
18304
  }
@@ -21938,8 +21938,8 @@ function nearlyEqual2(a, b, relTol = 1e-9, absTol = 0) {
21938
21938
  }
21939
21939
  const ax = x.abs();
21940
21940
  const ay = y.abs();
21941
- const maxAbs = ax.greaterThanOrEqual(ay) ? ax : ay;
21942
- const relBound = maxAbs.mul(relTol);
21941
+ const maxAbs2 = ax.greaterThanOrEqual(ay) ? ax : ay;
21942
+ const relBound = maxAbs2.mul(relTol);
21943
21943
  const diff2 = x.sub(y).abs();
21944
21944
  return diff2.lessThanOrEqual(relBound) || diff2.lessThanOrEqual(absTol);
21945
21945
  }
@@ -23119,7 +23119,7 @@ var createDot = /* @__PURE__ */ factory(
23119
23119
  return xLen;
23120
23120
  }
23121
23121
  function _denseDot(a, b) {
23122
- const N = _validateDim(a, b);
23122
+ const N2 = _validateDim(a, b);
23123
23123
  const adata = isMatrix(a) ? a._data : a;
23124
23124
  const adt = isMatrix(a) ? a._datatype || a.getDataType() : void 0;
23125
23125
  const bdata = isMatrix(b) ? b._data : b;
@@ -23138,28 +23138,28 @@ var createDot = /* @__PURE__ */ factory(
23138
23138
  }
23139
23139
  if (!aIsColumn && !bIsColumn) {
23140
23140
  let c = mul(conj3(adata[0]), bdata[0]);
23141
- for (let i = 1; i < N; i++) {
23141
+ for (let i = 1; i < N2; i++) {
23142
23142
  c = add4(c, mul(conj3(adata[i]), bdata[i]));
23143
23143
  }
23144
23144
  return c;
23145
23145
  }
23146
23146
  if (!aIsColumn && bIsColumn) {
23147
23147
  let c = mul(conj3(adata[0]), bdata[0][0]);
23148
- for (let i = 1; i < N; i++) {
23148
+ for (let i = 1; i < N2; i++) {
23149
23149
  c = add4(c, mul(conj3(adata[i]), bdata[i][0]));
23150
23150
  }
23151
23151
  return c;
23152
23152
  }
23153
23153
  if (aIsColumn && !bIsColumn) {
23154
23154
  let c = mul(conj3(adata[0][0]), bdata[0]);
23155
- for (let i = 1; i < N; i++) {
23155
+ for (let i = 1; i < N2; i++) {
23156
23156
  c = add4(c, mul(conj3(adata[i][0]), bdata[i]));
23157
23157
  }
23158
23158
  return c;
23159
23159
  }
23160
23160
  {
23161
23161
  let c = mul(conj3(adata[0][0]), bdata[0][0]);
23162
- for (let i = 1; i < N; i++) {
23162
+ for (let i = 1; i < N2; i++) {
23163
23163
  c = add4(c, mul(conj3(adata[i][0]), bdata[i][0]));
23164
23164
  }
23165
23165
  return c;
@@ -24155,20 +24155,20 @@ var createMatrixFromColumns = /* @__PURE__ */ factory(
24155
24155
  function _createArray(arr10) {
24156
24156
  if (arr10.length === 0)
24157
24157
  throw new TypeError("At least one column is needed to construct a matrix.");
24158
- const N = checkVectorTypeAndReturnLength(arr10[0]);
24158
+ const N2 = checkVectorTypeAndReturnLength(arr10[0]);
24159
24159
  const result = [];
24160
- for (let i = 0; i < N; i++) {
24160
+ for (let i = 0; i < N2; i++) {
24161
24161
  result[i] = [];
24162
24162
  }
24163
24163
  for (const col of arr10) {
24164
24164
  const colLength = checkVectorTypeAndReturnLength(col);
24165
- if (colLength !== N) {
24165
+ if (colLength !== N2) {
24166
24166
  throw new TypeError(
24167
- "The vectors had different length: " + (N | 0) + " \u2260 " + (colLength | 0)
24167
+ "The vectors had different length: " + (N2 | 0) + " \u2260 " + (colLength | 0)
24168
24168
  );
24169
24169
  }
24170
24170
  const f = flatten5(col);
24171
- for (let i = 0; i < N; i++) {
24171
+ for (let i = 0; i < N2; i++) {
24172
24172
  result[i].push(f[i]);
24173
24173
  }
24174
24174
  }
@@ -24224,13 +24224,13 @@ var createMatrixFromRows = /* @__PURE__ */ factory(
24224
24224
  function _createArray(arr10) {
24225
24225
  if (arr10.length === 0)
24226
24226
  throw new TypeError("At least one row is needed to construct a matrix.");
24227
- const N = checkVectorTypeAndReturnLength(arr10[0]);
24227
+ const N2 = checkVectorTypeAndReturnLength(arr10[0]);
24228
24228
  const result = [];
24229
24229
  for (const row2 of arr10) {
24230
24230
  const rowLength = checkVectorTypeAndReturnLength(row2);
24231
- if (rowLength !== N) {
24231
+ if (rowLength !== N2) {
24232
24232
  throw new TypeError(
24233
- "The vectors had different length: " + (N | 0) + " \u2260 " + (rowLength | 0)
24233
+ "The vectors had different length: " + (N2 | 0) + " \u2260 " + (rowLength | 0)
24234
24234
  );
24235
24235
  }
24236
24236
  result.push(flatten5(row2));
@@ -38253,20 +38253,20 @@ function createComplexEigs({
38253
38253
  matrixFromColumns: _matrixFromColumns,
38254
38254
  dot: dot9
38255
38255
  }) {
38256
- function complexEigs(arr10, N, prec, type, findVectors = true) {
38257
- if (!findVectors && type === "number" && N * N >= WASM_EIGS_THRESHOLD) {
38256
+ function complexEigs(arr10, N2, prec, type, findVectors = true) {
38257
+ if (!findVectors && type === "number" && N2 * N2 >= WASM_EIGS_THRESHOLD) {
38258
38258
  const wasm = wasmLoader.getModule();
38259
38259
  if (wasm) {
38260
38260
  try {
38261
- const flat = flattenToFloat648(arr10, N, N);
38261
+ const flat = flattenToFloat648(arr10, N2, N2);
38262
38262
  const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
38263
- const eigenvaluesRealAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
38264
- const eigenvaluesImagAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
38265
- const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N * N);
38263
+ const eigenvaluesRealAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
38264
+ const eigenvaluesImagAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
38265
+ const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2 * N2);
38266
38266
  try {
38267
38267
  const iterations = wasm.qrAlgorithm(
38268
38268
  matrixAlloc.ptr,
38269
- N,
38269
+ N2,
38270
38270
  eigenvaluesRealAlloc.ptr,
38271
38271
  eigenvaluesImagAlloc.ptr,
38272
38272
  workAlloc.ptr,
@@ -38276,7 +38276,7 @@ function createComplexEigs({
38276
38276
  );
38277
38277
  if (iterations >= 0) {
38278
38278
  const values2 = [];
38279
- for (let i = 0; i < N; i++) {
38279
+ for (let i = 0; i < N2; i++) {
38280
38280
  const re3 = eigenvaluesRealAlloc.array[i];
38281
38281
  const im3 = eigenvaluesImagAlloc.array[i];
38282
38282
  if (Math.abs(im3) < 1e-14) {
@@ -38302,16 +38302,16 @@ function createComplexEigs({
38302
38302
  }
38303
38303
  }
38304
38304
  }
38305
- const R = balance(arr10, N, prec, type, findVectors);
38306
- reduceToHessenberg(arr10, N, prec, type, findVectors, R);
38307
- const { values, C } = iterateUntilTriangular(arr10, N, prec, type, findVectors);
38305
+ const R = balance(arr10, N2, prec, type, findVectors);
38306
+ reduceToHessenberg(arr10, N2, prec, type, findVectors, R);
38307
+ const { values, C } = iterateUntilTriangular(arr10, N2, prec, type, findVectors);
38308
38308
  if (findVectors) {
38309
- const eigenvectors = findEigenvectors(arr10, N, C, R, values, prec, type);
38309
+ const eigenvectors = findEigenvectors(arr10, N2, C, R, values, prec, type);
38310
38310
  return { values, eigenvectors };
38311
38311
  }
38312
38312
  return { values };
38313
38313
  }
38314
- function balance(arr10, N, _prec, type, findVectors) {
38314
+ function balance(arr10, N2, _prec, type, findVectors) {
38315
38315
  const big = type === "BigNumber";
38316
38316
  const cplx = type === "Complex";
38317
38317
  const realzero = big ? bignumber2(0) : 0;
@@ -38321,24 +38321,24 @@ function createComplexEigs({
38321
38321
  const radixSq = multiplyScalar2(radix, radix);
38322
38322
  let Rdiag;
38323
38323
  if (findVectors) {
38324
- Rdiag = Array(N).fill(one);
38324
+ Rdiag = Array(N2).fill(one);
38325
38325
  }
38326
38326
  let last2 = false;
38327
38327
  while (!last2) {
38328
38328
  last2 = true;
38329
- for (let i = 0; i < N; i++) {
38329
+ for (let i = 0; i < N2; i++) {
38330
38330
  let colNorm = realzero;
38331
- let rowNorm = realzero;
38332
- for (let j = 0; j < N; j++) {
38331
+ let rowNorm2 = realzero;
38332
+ for (let j = 0; j < N2; j++) {
38333
38333
  if (i === j) continue;
38334
38334
  colNorm = addScalar2(colNorm, abs2(arr10[j][i]));
38335
- rowNorm = addScalar2(rowNorm, abs2(arr10[i][j]));
38335
+ rowNorm2 = addScalar2(rowNorm2, abs2(arr10[i][j]));
38336
38336
  }
38337
- if (!equal2(colNorm, 0) && !equal2(rowNorm, 0)) {
38337
+ if (!equal2(colNorm, 0) && !equal2(rowNorm2, 0)) {
38338
38338
  let f = realone;
38339
38339
  let c = colNorm;
38340
- const rowDivRadix = divideScalar2(rowNorm, radix);
38341
- const rowMulRadix = multiplyScalar2(rowNorm, radix);
38340
+ const rowDivRadix = divideScalar2(rowNorm2, radix);
38341
+ const rowMulRadix = multiplyScalar2(rowNorm2, radix);
38342
38342
  while (smaller2(c, rowDivRadix)) {
38343
38343
  c = multiplyScalar2(c, radixSq);
38344
38344
  f = multiplyScalar2(f, radix);
@@ -38348,13 +38348,13 @@ function createComplexEigs({
38348
38348
  f = divideScalar2(f, radix);
38349
38349
  }
38350
38350
  const condition = smaller2(
38351
- divideScalar2(addScalar2(c, rowNorm), f),
38352
- multiplyScalar2(addScalar2(colNorm, rowNorm), 0.95)
38351
+ divideScalar2(addScalar2(c, rowNorm2), f),
38352
+ multiplyScalar2(addScalar2(colNorm, rowNorm2), 0.95)
38353
38353
  );
38354
38354
  if (condition) {
38355
38355
  last2 = false;
38356
38356
  const g = divideScalar2(1, f);
38357
- for (let j = 0; j < N; j++) {
38357
+ for (let j = 0; j < N2; j++) {
38358
38358
  if (i === j) {
38359
38359
  continue;
38360
38360
  }
@@ -38370,17 +38370,17 @@ function createComplexEigs({
38370
38370
  }
38371
38371
  return findVectors ? diag2(Rdiag) : null;
38372
38372
  }
38373
- function reduceToHessenberg(arr10, N, prec, type, findVectors, R) {
38373
+ function reduceToHessenberg(arr10, N2, prec, type, findVectors, R) {
38374
38374
  const big = type === "BigNumber";
38375
38375
  const cplx = type === "Complex";
38376
38376
  const zero = big ? bignumber2(0) : cplx ? complex3(0) : 0;
38377
38377
  if (big) {
38378
38378
  prec = bignumber2(prec);
38379
38379
  }
38380
- for (let i = 0; i < N - 2; i++) {
38380
+ for (let i = 0; i < N2 - 2; i++) {
38381
38381
  let maxIndex = 0;
38382
38382
  let max2 = zero;
38383
- for (let j = i + 1; j < N; j++) {
38383
+ for (let j = i + 1; j < N2; j++) {
38384
38384
  const el = arr10[j][i];
38385
38385
  if (smaller2(abs2(max2), abs2(el))) {
38386
38386
  max2 = el;
@@ -38394,7 +38394,7 @@ function createComplexEigs({
38394
38394
  const tmp1 = arr10[maxIndex];
38395
38395
  arr10[maxIndex] = arr10[i + 1];
38396
38396
  arr10[i + 1] = tmp1;
38397
- for (let j = 0; j < N; j++) {
38397
+ for (let j = 0; j < N2; j++) {
38398
38398
  const tmp2 = arr10[j][maxIndex];
38399
38399
  arr10[j][maxIndex] = arr10[j][i + 1];
38400
38400
  arr10[j][i + 1] = tmp2;
@@ -38405,26 +38405,26 @@ function createComplexEigs({
38405
38405
  R[i + 1] = tmp3;
38406
38406
  }
38407
38407
  }
38408
- for (let j = i + 2; j < N; j++) {
38408
+ for (let j = i + 2; j < N2; j++) {
38409
38409
  const n = divideScalar2(arr10[j][i], max2);
38410
38410
  if (n === 0) {
38411
38411
  continue;
38412
38412
  }
38413
- for (let k = 0; k < N; k++) {
38413
+ for (let k = 0; k < N2; k++) {
38414
38414
  arr10[j][k] = subtract3(arr10[j][k], multiplyScalar2(n, arr10[i + 1][k]));
38415
38415
  }
38416
- for (let k = 0; k < N; k++) {
38416
+ for (let k = 0; k < N2; k++) {
38417
38417
  arr10[k][i + 1] = addScalar2(arr10[k][i + 1], multiplyScalar2(n, arr10[k][j]));
38418
38418
  }
38419
38419
  if (findVectors) {
38420
- for (let k = 0; k < N; k++) {
38420
+ for (let k = 0; k < N2; k++) {
38421
38421
  R[j][k] = subtract3(R[j][k], multiplyScalar2(n, R[i + 1][k]));
38422
38422
  }
38423
38423
  }
38424
38424
  }
38425
38425
  }
38426
38426
  }
38427
- function iterateUntilTriangular(A, N, prec, type, findVectors) {
38427
+ function iterateUntilTriangular(A, N2, prec, type, findVectors) {
38428
38428
  const big = type === "BigNumber";
38429
38429
  const cplx = type === "Complex";
38430
38430
  const one = big ? bignumber2(1) : cplx ? complex3(1) : 1;
@@ -38433,9 +38433,9 @@ function createComplexEigs({
38433
38433
  }
38434
38434
  let arr10 = clone(A);
38435
38435
  const lambdas = [];
38436
- let n = N;
38436
+ let n = N2;
38437
38437
  const Sdiag = [];
38438
- let Qtotal = findVectors ? diag2(Array(N).fill(one)) : void 0;
38438
+ let Qtotal = findVectors ? diag2(Array(N2).fill(one)) : void 0;
38439
38439
  let Qpartial = findVectors ? diag2(Array(n).fill(one)) : void 0;
38440
38440
  let lastConvergenceBefore = 0;
38441
38441
  while (lastConvergenceBefore <= 100) {
@@ -38457,7 +38457,7 @@ function createComplexEigs({
38457
38457
  lambdas.push(arr10[n - 1][n - 1]);
38458
38458
  if (findVectors) {
38459
38459
  Sdiag.unshift([[1]]);
38460
- inflateMatrix(Qpartial, N);
38460
+ inflateMatrix(Qpartial, N2);
38461
38461
  Qtotal = multiply2(Qtotal, Qpartial);
38462
38462
  if (n > 1) {
38463
38463
  Qpartial = diag2(Array(n - 1).fill(one));
@@ -38490,7 +38490,7 @@ function createComplexEigs({
38490
38490
  type
38491
38491
  )
38492
38492
  );
38493
- inflateMatrix(Qpartial, N);
38493
+ inflateMatrix(Qpartial, N2);
38494
38494
  Qtotal = multiply2(Qtotal, Qpartial);
38495
38495
  if (n > 2) {
38496
38496
  Qpartial = diag2(Array(n - 2).fill(one));
@@ -38517,10 +38517,10 @@ function createComplexEigs({
38517
38517
  err.vectors = [];
38518
38518
  throw err;
38519
38519
  }
38520
- const C = findVectors ? multiply2(Qtotal, blockDiag(Sdiag, N)) : void 0;
38520
+ const C = findVectors ? multiply2(Qtotal, blockDiag(Sdiag, N2)) : void 0;
38521
38521
  return { values: lambdas, C };
38522
38522
  }
38523
- function findEigenvectors(A, N, C, R, values, prec, type) {
38523
+ function findEigenvectors(A, N2, C, R, values, prec, type) {
38524
38524
  const Cinv = inv3(C);
38525
38525
  const U = multiply2(multiply2(Cinv, A), C);
38526
38526
  const big = type === "BigNumber";
@@ -38540,8 +38540,8 @@ function createComplexEigs({
38540
38540
  }
38541
38541
  const vectors = [];
38542
38542
  const len = uniqueValues.length;
38543
- const b = Array(N).fill(zero);
38544
- const E = diag2(Array(N).fill(one));
38543
+ const b = Array(N2).fill(zero);
38544
+ const E = diag2(Array(N2).fill(one));
38545
38545
  for (let i = 0; i < len; i++) {
38546
38546
  const lambda = uniqueValues[i];
38547
38547
  const S = subtract3(
@@ -38551,7 +38551,7 @@ function createComplexEigs({
38551
38551
  let solutions = usolveAll2(S, b);
38552
38552
  solutions.shift();
38553
38553
  while (solutions.length < multiplicities[i]) {
38554
- const approxVec = inverseIterate(S, N, solutions, prec, type);
38554
+ const approxVec = inverseIterate(S, N2, solutions, prec, type);
38555
38555
  if (approxVec === null) {
38556
38556
  break;
38557
38557
  }
@@ -38606,20 +38606,20 @@ function createComplexEigs({
38606
38606
  ];
38607
38607
  }
38608
38608
  }
38609
- function inflateMatrix(arr10, N) {
38609
+ function inflateMatrix(arr10, N2) {
38610
38610
  for (let i = 0; i < arr10.length; i++) {
38611
- arr10[i].push(...Array(N - arr10[i].length).fill(0));
38611
+ arr10[i].push(...Array(N2 - arr10[i].length).fill(0));
38612
38612
  }
38613
- for (let i = arr10.length; i < N; i++) {
38614
- arr10.push(Array(N).fill(0));
38613
+ for (let i = arr10.length; i < N2; i++) {
38614
+ arr10.push(Array(N2).fill(0));
38615
38615
  arr10[i][i] = 1;
38616
38616
  }
38617
38617
  return arr10;
38618
38618
  }
38619
- function blockDiag(arr10, N) {
38619
+ function blockDiag(arr10, N2) {
38620
38620
  const M = [];
38621
- for (let i = 0; i < N; i++) {
38622
- M[i] = Array(N).fill(0);
38621
+ for (let i = 0; i < N2; i++) {
38622
+ M[i] = Array(N2).fill(0);
38623
38623
  }
38624
38624
  let I2 = 0;
38625
38625
  for (const sub3 of arr10) {
@@ -38641,12 +38641,12 @@ function createComplexEigs({
38641
38641
  }
38642
38642
  return -1;
38643
38643
  }
38644
- function inverseIterate(A, N, orthog, prec, type) {
38644
+ function inverseIterate(A, N2, orthog, prec, type) {
38645
38645
  const largeNum = type === "BigNumber" ? bignumber2(1e3) : 1e3;
38646
38646
  let b;
38647
38647
  let i = 0;
38648
38648
  for (; i < 5; ++i) {
38649
- b = randomOrthogonalVector(N, orthog, type);
38649
+ b = randomOrthogonalVector(N2, orthog, type);
38650
38650
  try {
38651
38651
  b = usolve2(A, b);
38652
38652
  } catch {
@@ -38672,10 +38672,10 @@ function createComplexEigs({
38672
38672
  }
38673
38673
  return b;
38674
38674
  }
38675
- function randomOrthogonalVector(N, orthog, type) {
38675
+ function randomOrthogonalVector(N2, orthog, type) {
38676
38676
  const big = type === "BigNumber";
38677
38677
  const cplx = type === "Complex";
38678
- let v = Array(N).fill(0).map(() => 2 * Math.random() - 1);
38678
+ let v = Array(N2).fill(0).map(() => 2 * Math.random() - 1);
38679
38679
  if (big) {
38680
38680
  v = v.map((n) => bignumber2(n));
38681
38681
  }
@@ -38758,19 +38758,19 @@ function createRealSymmetric({
38758
38758
  throw TypeError("Unsupported data type: " + type);
38759
38759
  }
38760
38760
  function diag2(x, precision, computeVectors) {
38761
- const N = x.length;
38761
+ const N2 = x.length;
38762
38762
  const wasm = wasmLoader.getModule();
38763
- if (wasm && N * N >= WASM_EIGS_THRESHOLD2) {
38763
+ if (wasm && N2 * N2 >= WASM_EIGS_THRESHOLD2) {
38764
38764
  try {
38765
- const flat = flattenToFloat649(x, N, N);
38765
+ const flat = flattenToFloat649(x, N2, N2);
38766
38766
  const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
38767
- const eigenvaluesAlloc = wasmLoader.allocateFloat64ArrayEmpty(N);
38768
- const eigenvectorsAlloc = computeVectors ? wasmLoader.allocateFloat64ArrayEmpty(N * N) : { ptr: 0, array: new Float64Array(0) };
38769
- const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N * N);
38767
+ const eigenvaluesAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
38768
+ const eigenvectorsAlloc = computeVectors ? wasmLoader.allocateFloat64ArrayEmpty(N2 * N2) : { ptr: 0, array: new Float64Array(0) };
38769
+ const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2 * N2);
38770
38770
  try {
38771
38771
  const iterations = wasm.eigsSymmetric(
38772
38772
  matrixAlloc.ptr,
38773
- N,
38773
+ N2,
38774
38774
  eigenvaluesAlloc.ptr,
38775
38775
  eigenvectorsAlloc.ptr,
38776
38776
  workAlloc.ptr,
@@ -38779,8 +38779,8 @@ function createRealSymmetric({
38779
38779
  precision
38780
38780
  );
38781
38781
  if (iterations >= 0) {
38782
- const values = Array(N);
38783
- for (let i = 0; i < N; i++) {
38782
+ const values = Array(N2);
38783
+ for (let i = 0; i < N2; i++) {
38784
38784
  values[i] = eigenvaluesAlloc.array[i];
38785
38785
  }
38786
38786
  if (!computeVectors) {
@@ -38790,9 +38790,9 @@ function createRealSymmetric({
38790
38790
  const eigenvectors = [];
38791
38791
  const sortedIndices = values.map((v, i) => ({ v, i })).sort((a, b) => Math.abs(a.v) - Math.abs(b.v)).map((x2) => x2.i);
38792
38792
  for (const origIdx of sortedIndices) {
38793
- const vector = Array(N);
38794
- for (let i = 0; i < N; i++) {
38795
- vector[i] = eigenvectorsAlloc.array[i * N + origIdx];
38793
+ const vector = Array(N2);
38794
+ for (let i = 0; i < N2; i++) {
38795
+ vector[i] = eigenvectorsAlloc.array[i * N2 + origIdx];
38796
38796
  }
38797
38797
  eigenvectors.push({
38798
38798
  value: values[origIdx],
@@ -38815,13 +38815,13 @@ function createRealSymmetric({
38815
38815
  } catch {
38816
38816
  }
38817
38817
  }
38818
- const e0 = Math.abs(precision / N);
38818
+ const e0 = Math.abs(precision / N2);
38819
38819
  let psi;
38820
38820
  let Sij;
38821
38821
  if (computeVectors) {
38822
- Sij = new Array(N);
38823
- for (let i = 0; i < N; i++) {
38824
- Sij[i] = Array(N).fill(0);
38822
+ Sij = new Array(N2);
38823
+ for (let i = 0; i < N2; i++) {
38824
+ Sij[i] = Array(N2).fill(0);
38825
38825
  Sij[i][i] = 1;
38826
38826
  }
38827
38827
  }
@@ -38834,21 +38834,21 @@ function createRealSymmetric({
38834
38834
  if (computeVectors) Sij = Sij1(Sij, psi, i, j);
38835
38835
  Vab = getAij(x);
38836
38836
  }
38837
- const Ei = Array(N).fill(0);
38838
- for (let i = 0; i < N; i++) {
38837
+ const Ei = Array(N2).fill(0);
38838
+ for (let i = 0; i < N2; i++) {
38839
38839
  Ei[i] = x[i][i];
38840
38840
  }
38841
38841
  return sorting(clone(Ei), Sij, computeVectors);
38842
38842
  }
38843
38843
  function diagBig(x, precision, computeVectors) {
38844
- const N = x.length;
38845
- const e0 = abs2(multiplyScalar2(precision, bignumber2(1 / N)));
38844
+ const N2 = x.length;
38845
+ const e0 = abs2(multiplyScalar2(precision, bignumber2(1 / N2)));
38846
38846
  let psi;
38847
38847
  let Sij;
38848
38848
  if (computeVectors) {
38849
- Sij = new Array(N);
38850
- for (let i = 0; i < N; i++) {
38851
- Sij[i] = Array(N).fill(bignumber2(0));
38849
+ Sij = new Array(N2);
38850
+ for (let i = 0; i < N2; i++) {
38851
+ Sij[i] = Array(N2).fill(bignumber2(0));
38852
38852
  Sij[i][i] = bignumber2(1);
38853
38853
  }
38854
38854
  }
@@ -38861,8 +38861,8 @@ function createRealSymmetric({
38861
38861
  if (computeVectors) Sij = Sij1Big(Sij, psi, i, j);
38862
38862
  Vab = getAijBig(x);
38863
38863
  }
38864
- const Ei = Array(N).fill(bignumber2(0));
38865
- for (let i = 0; i < N; i++) {
38864
+ const Ei = Array(N2).fill(bignumber2(0));
38865
+ for (let i = 0; i < N2; i++) {
38866
38866
  Ei[i] = x[i][i];
38867
38867
  }
38868
38868
  return sorting(clone(Ei), Sij, computeVectors);
@@ -38887,45 +38887,45 @@ function createRealSymmetric({
38887
38887
  }
38888
38888
  }
38889
38889
  function Sij1(Sij, theta, i, j) {
38890
- const N = Sij.length;
38890
+ const N2 = Sij.length;
38891
38891
  const c = Math.cos(theta);
38892
38892
  const s = Math.sin(theta);
38893
- const Ski = Array(N).fill(0);
38894
- const Skj = Array(N).fill(0);
38895
- for (let k = 0; k < N; k++) {
38893
+ const Ski = Array(N2).fill(0);
38894
+ const Skj = Array(N2).fill(0);
38895
+ for (let k = 0; k < N2; k++) {
38896
38896
  Ski[k] = c * Sij[k][i] - s * Sij[k][j];
38897
38897
  Skj[k] = s * Sij[k][i] + c * Sij[k][j];
38898
38898
  }
38899
- for (let k = 0; k < N; k++) {
38899
+ for (let k = 0; k < N2; k++) {
38900
38900
  Sij[k][i] = Ski[k];
38901
38901
  Sij[k][j] = Skj[k];
38902
38902
  }
38903
38903
  return Sij;
38904
38904
  }
38905
38905
  function Sij1Big(Sij, theta, i, j) {
38906
- const N = Sij.length;
38906
+ const N2 = Sij.length;
38907
38907
  const c = cos2(theta);
38908
38908
  const s = sin2(theta);
38909
- const Ski = Array(N).fill(bignumber2(0));
38910
- const Skj = Array(N).fill(bignumber2(0));
38911
- for (let k = 0; k < N; k++) {
38909
+ const Ski = Array(N2).fill(bignumber2(0));
38910
+ const Skj = Array(N2).fill(bignumber2(0));
38911
+ for (let k = 0; k < N2; k++) {
38912
38912
  Ski[k] = subtract3(multiplyScalar2(c, Sij[k][i]), multiplyScalar2(s, Sij[k][j]));
38913
38913
  Skj[k] = addScalar2(multiplyScalar2(s, Sij[k][i]), multiplyScalar2(c, Sij[k][j]));
38914
38914
  }
38915
- for (let k = 0; k < N; k++) {
38915
+ for (let k = 0; k < N2; k++) {
38916
38916
  Sij[k][i] = Ski[k];
38917
38917
  Sij[k][j] = Skj[k];
38918
38918
  }
38919
38919
  return Sij;
38920
38920
  }
38921
38921
  function x1Big(Hij, theta, i, j) {
38922
- const N = Hij.length;
38922
+ const N2 = Hij.length;
38923
38923
  const c = bignumber2(cos2(theta).toString());
38924
38924
  const s = bignumber2(sin2(theta).toString());
38925
38925
  const c2 = multiplyScalar2(c, c);
38926
38926
  const s2 = multiplyScalar2(s, s);
38927
- const Aki = Array(N).fill(bignumber2(0));
38928
- const Akj = Array(N).fill(bignumber2(0));
38927
+ const Aki = Array(N2).fill(bignumber2(0));
38928
+ const Akj = Array(N2).fill(bignumber2(0));
38929
38929
  const csHij = multiply2(bignumber2(2), c, s, Hij[i][j]);
38930
38930
  const Aii = addScalar2(
38931
38931
  subtract3(multiplyScalar2(c2, Hij[i][i]), csHij),
@@ -38936,7 +38936,7 @@ function createRealSymmetric({
38936
38936
  csHij,
38937
38937
  multiplyScalar2(c2, Hij[j][j])
38938
38938
  );
38939
- for (let k = 0; k < N; k++) {
38939
+ for (let k = 0; k < N2; k++) {
38940
38940
  Aki[k] = subtract3(multiplyScalar2(c, Hij[i][k]), multiplyScalar2(s, Hij[j][k]));
38941
38941
  Akj[k] = addScalar2(multiplyScalar2(s, Hij[i][k]), multiplyScalar2(c, Hij[j][k]));
38942
38942
  }
@@ -38944,7 +38944,7 @@ function createRealSymmetric({
38944
38944
  Hij[j][j] = Ajj;
38945
38945
  Hij[i][j] = bignumber2(0);
38946
38946
  Hij[j][i] = bignumber2(0);
38947
- for (let k = 0; k < N; k++) {
38947
+ for (let k = 0; k < N2; k++) {
38948
38948
  if (k !== i && k !== j) {
38949
38949
  Hij[i][k] = Aki[k];
38950
38950
  Hij[k][i] = Aki[k];
@@ -38955,16 +38955,16 @@ function createRealSymmetric({
38955
38955
  return Hij;
38956
38956
  }
38957
38957
  function x1(Hij, theta, i, j) {
38958
- const N = Hij.length;
38958
+ const N2 = Hij.length;
38959
38959
  const c = Math.cos(theta);
38960
38960
  const s = Math.sin(theta);
38961
38961
  const c2 = c * c;
38962
38962
  const s2 = s * s;
38963
- const Aki = Array(N).fill(0);
38964
- const Akj = Array(N).fill(0);
38963
+ const Aki = Array(N2).fill(0);
38964
+ const Akj = Array(N2).fill(0);
38965
38965
  const Aii = c2 * Hij[i][i] - 2 * c * s * Hij[i][j] + s2 * Hij[j][j];
38966
38966
  const Ajj = s2 * Hij[i][i] + 2 * c * s * Hij[i][j] + c2 * Hij[j][j];
38967
- for (let k = 0; k < N; k++) {
38967
+ for (let k = 0; k < N2; k++) {
38968
38968
  Aki[k] = c * Hij[i][k] - s * Hij[j][k];
38969
38969
  Akj[k] = s * Hij[i][k] + c * Hij[j][k];
38970
38970
  }
@@ -38972,7 +38972,7 @@ function createRealSymmetric({
38972
38972
  Hij[j][j] = Ajj;
38973
38973
  Hij[i][j] = 0;
38974
38974
  Hij[j][i] = 0;
38975
- for (let k = 0; k < N; k++) {
38975
+ for (let k = 0; k < N2; k++) {
38976
38976
  if (k !== i && k !== j) {
38977
38977
  Hij[i][k] = Aki[k];
38978
38978
  Hij[k][i] = Aki[k];
@@ -38983,11 +38983,11 @@ function createRealSymmetric({
38983
38983
  return Hij;
38984
38984
  }
38985
38985
  function getAij(Mij) {
38986
- const N = Mij.length;
38986
+ const N2 = Mij.length;
38987
38987
  let maxMij = 0;
38988
38988
  let maxIJ = [0, 1];
38989
- for (let i = 0; i < N; i++) {
38990
- for (let j = i + 1; j < N; j++) {
38989
+ for (let i = 0; i < N2; i++) {
38990
+ for (let j = i + 1; j < N2; j++) {
38991
38991
  if (Math.abs(maxMij) < Math.abs(Mij[i][j])) {
38992
38992
  maxMij = Math.abs(Mij[i][j]);
38993
38993
  maxIJ = [i, j];
@@ -38997,11 +38997,11 @@ function createRealSymmetric({
38997
38997
  return [maxIJ, maxMij];
38998
38998
  }
38999
38999
  function getAijBig(Mij) {
39000
- const N = Mij.length;
39000
+ const N2 = Mij.length;
39001
39001
  let maxMij = bignumber2(0);
39002
39002
  let maxIJ = [0, 1];
39003
- for (let i = 0; i < N; i++) {
39004
- for (let j = i + 1; j < N; j++) {
39003
+ for (let i = 0; i < N2; i++) {
39004
+ for (let j = i + 1; j < N2; j++) {
39005
39005
  if (bigLt(abs2(maxMij), abs2(Mij[i][j]))) {
39006
39006
  maxMij = abs2(Mij[i][j]);
39007
39007
  maxIJ = [i, j];
@@ -39011,16 +39011,16 @@ function createRealSymmetric({
39011
39011
  return [maxIJ, maxMij];
39012
39012
  }
39013
39013
  function sorting(E, S, computeVectors) {
39014
- const N = E.length;
39015
- const values = Array(N);
39014
+ const N2 = E.length;
39015
+ const values = Array(N2);
39016
39016
  let vecs;
39017
39017
  if (computeVectors) {
39018
- vecs = Array(N);
39019
- for (let k = 0; k < N; k++) {
39020
- vecs[k] = Array(N);
39018
+ vecs = Array(N2);
39019
+ for (let k = 0; k < N2; k++) {
39020
+ vecs[k] = Array(N2);
39021
39021
  }
39022
39022
  }
39023
- for (let i = 0; i < N; i++) {
39023
+ for (let i = 0; i < N2; i++) {
39024
39024
  let minID = 0;
39025
39025
  let minE = E[0];
39026
39026
  for (let j = 0; j < E.length; j++) {
@@ -39031,7 +39031,7 @@ function createRealSymmetric({
39031
39031
  }
39032
39032
  values[i] = E.splice(minID, 1)[0];
39033
39033
  if (computeVectors) {
39034
- for (let k = 0; k < N; k++) {
39034
+ for (let k = 0; k < N2; k++) {
39035
39035
  vecs[i][k] = S[k][minID];
39036
39036
  S[k].splice(minID, 1);
39037
39037
  }
@@ -39220,26 +39220,26 @@ var createEigs = /* @__PURE__ */ factory(
39220
39220
  if (asize.length !== 2 || asize[0] !== asize[1]) {
39221
39221
  throw new RangeError(`Matrix must be square (size: ${formatGeneric(asize, {})})`);
39222
39222
  }
39223
- const N = asize[0];
39224
- if (isReal(arr10, N, prec)) {
39225
- coerceReal(arr10, N);
39226
- if (isSymmetric(arr10, N, prec)) {
39227
- const type2 = coerceTypes(mat, arr10, N);
39223
+ const N2 = asize[0];
39224
+ if (isReal(arr10, N2, prec)) {
39225
+ coerceReal(arr10, N2);
39226
+ if (isSymmetric(arr10, N2, prec)) {
39227
+ const type2 = coerceTypes(mat, arr10, N2);
39228
39228
  return doRealSymmetric(
39229
39229
  arr10,
39230
- N,
39230
+ N2,
39231
39231
  prec,
39232
39232
  type2,
39233
39233
  computeVectors
39234
39234
  );
39235
39235
  }
39236
39236
  }
39237
- const type = coerceTypes(mat, arr10, N);
39238
- return doComplexEigs(arr10, N, prec, type, computeVectors);
39237
+ const type = coerceTypes(mat, arr10, N2);
39238
+ return doComplexEigs(arr10, N2, prec, type, computeVectors);
39239
39239
  }
39240
- function isSymmetric(arr10, N, prec) {
39241
- for (let i = 0; i < N; i++) {
39242
- for (let j = i; j < N; j++) {
39240
+ function isSymmetric(arr10, N2, prec) {
39241
+ for (let i = 0; i < N2; i++) {
39242
+ for (let j = i; j < N2; j++) {
39243
39243
  if (larger2(bignumber2(abs2(subtract3(arr10[i][j], arr10[j][i]))), prec)) {
39244
39244
  return false;
39245
39245
  }
@@ -39247,9 +39247,9 @@ var createEigs = /* @__PURE__ */ factory(
39247
39247
  }
39248
39248
  return true;
39249
39249
  }
39250
- function isReal(arr10, N, prec) {
39251
- for (let i = 0; i < N; i++) {
39252
- for (let j = 0; j < N; j++) {
39250
+ function isReal(arr10, N2, prec) {
39251
+ for (let i = 0; i < N2; i++) {
39252
+ for (let j = 0; j < N2; j++) {
39253
39253
  if (larger2(bignumber2(abs2(im3(arr10[i][j]))), prec)) {
39254
39254
  return false;
39255
39255
  }
@@ -39257,14 +39257,14 @@ var createEigs = /* @__PURE__ */ factory(
39257
39257
  }
39258
39258
  return true;
39259
39259
  }
39260
- function coerceReal(arr10, N) {
39261
- for (let i = 0; i < N; i++) {
39262
- for (let j = 0; j < N; j++) {
39260
+ function coerceReal(arr10, N2) {
39261
+ for (let i = 0; i < N2; i++) {
39262
+ for (let j = 0; j < N2; j++) {
39263
39263
  arr10[i][j] = re3(arr10[i][j]);
39264
39264
  }
39265
39265
  }
39266
39266
  }
39267
- function coerceTypes(mat, arr10, N) {
39267
+ function coerceTypes(mat, arr10, N2) {
39268
39268
  const type = mat.datatype();
39269
39269
  if (type === "number" || type === "BigNumber" || type === "Complex") {
39270
39270
  return type;
@@ -39272,8 +39272,8 @@ var createEigs = /* @__PURE__ */ factory(
39272
39272
  let hasNumber = false;
39273
39273
  let hasBig = false;
39274
39274
  let hasComplex = false;
39275
- for (let i = 0; i < N; i++) {
39276
- for (let j = 0; j < N; j++) {
39275
+ for (let i = 0; i < N2; i++) {
39276
+ for (let j = 0; j < N2; j++) {
39277
39277
  const el = arr10[i][j];
39278
39278
  if (isNumber(el) || isFraction(el)) {
39279
39279
  hasNumber = true;
@@ -39290,24 +39290,24 @@ var createEigs = /* @__PURE__ */ factory(
39290
39290
  console.warn("Complex BigNumbers not supported, this operation will lose precission.");
39291
39291
  }
39292
39292
  if (hasComplex) {
39293
- for (let i = 0; i < N; i++) {
39294
- for (let j = 0; j < N; j++) {
39293
+ for (let i = 0; i < N2; i++) {
39294
+ for (let j = 0; j < N2; j++) {
39295
39295
  arr10[i][j] = complex3(arr10[i][j]);
39296
39296
  }
39297
39297
  }
39298
39298
  return "Complex";
39299
39299
  }
39300
39300
  if (hasBig) {
39301
- for (let i = 0; i < N; i++) {
39302
- for (let j = 0; j < N; j++) {
39301
+ for (let i = 0; i < N2; i++) {
39302
+ for (let j = 0; j < N2; j++) {
39303
39303
  arr10[i][j] = bignumber2(arr10[i][j]);
39304
39304
  }
39305
39305
  }
39306
39306
  return "BigNumber";
39307
39307
  }
39308
39308
  if (hasNumber) {
39309
- for (let i = 0; i < N; i++) {
39310
- for (let j = 0; j < N; j++) {
39309
+ for (let i = 0; i < N2; i++) {
39310
+ for (let j = 0; j < N2; j++) {
39311
39311
  arr10[i][j] = number2(arr10[i][j]);
39312
39312
  }
39313
39313
  }
@@ -43585,12 +43585,12 @@ function numericalDerivative(expr, varName, x0, k, h = 1e-4, scope) {
43585
43585
  return (deriv1 - deriv2) / (2 * h);
43586
43586
  }
43587
43587
  function taylorCoefficients(expr, varName, x0, n) {
43588
- const N = Math.max(1 << Math.ceil(Math.log2(2 * (n + 1))), 16);
43588
+ const N2 = Math.max(1 << Math.ceil(Math.log2(2 * (n + 1))), 16);
43589
43589
  const r = 0.5;
43590
- const fRe = new Array(N);
43591
- const fIm = new Array(N);
43592
- for (let j = 0; j < N; j++) {
43593
- const ang = 2 * Math.PI * j / N;
43590
+ const fRe = new Array(N2);
43591
+ const fIm = new Array(N2);
43592
+ for (let j = 0; j < N2; j++) {
43593
+ const ang = 2 * Math.PI * j / N2;
43594
43594
  const z = new Complex10(x0 + r * Math.cos(ang), r * Math.sin(ang));
43595
43595
  const val = evaluate(expr, { [varName]: z });
43596
43596
  if (typeof val === "number") {
@@ -43604,11 +43604,11 @@ function taylorCoefficients(expr, varName, x0, n) {
43604
43604
  const a = new Array(n + 1);
43605
43605
  for (let k = 0; k <= n; k++) {
43606
43606
  let sRe = 0;
43607
- for (let j = 0; j < N; j++) {
43608
- const ang = -2 * Math.PI * j * k / N;
43607
+ for (let j = 0; j < N2; j++) {
43608
+ const ang = -2 * Math.PI * j * k / N2;
43609
43609
  sRe += fRe[j] * Math.cos(ang) - fIm[j] * Math.sin(ang);
43610
43610
  }
43611
- a[k] = sRe / (N * Math.pow(r, k));
43611
+ a[k] = sRe / (N2 * Math.pow(r, k));
43612
43612
  }
43613
43613
  return a;
43614
43614
  }
@@ -43935,10 +43935,10 @@ function inverseLaplace(expr, s, t) {
43935
43935
  return `L^-1{${trimmed}}(${t})`;
43936
43936
  }
43937
43937
  function fourierSeries(expr, varName, n) {
43938
- const N = 1e3;
43939
- const dx = 2 * Math.PI / N;
43938
+ const N2 = 1e3;
43939
+ const dx = 2 * Math.PI / N2;
43940
43940
  let a0Sum = 0;
43941
- for (let i = 0; i < N; i++) {
43941
+ for (let i = 0; i < N2; i++) {
43942
43942
  const x = -Math.PI + i * dx;
43943
43943
  a0Sum += evalAt(expr, varName, x);
43944
43944
  }
@@ -43948,7 +43948,7 @@ function fourierSeries(expr, varName, n) {
43948
43948
  for (let k = 1; k <= n; k++) {
43949
43949
  let akSum = 0;
43950
43950
  let bkSum = 0;
43951
- for (let i = 0; i < N; i++) {
43951
+ for (let i = 0; i < N2; i++) {
43952
43952
  const x = -Math.PI + i * dx;
43953
43953
  const fx = evalAt(expr, varName, x);
43954
43954
  akSum += fx * Math.cos(k * x);
@@ -45398,18 +45398,18 @@ function kroneckerSymbol(a, n) {
45398
45398
  }
45399
45399
  if (nn === 1) return sign3;
45400
45400
  let aa = (a % nn + nn) % nn;
45401
- let N = nn;
45401
+ let N2 = nn;
45402
45402
  let jac = 1;
45403
45403
  while (aa !== 0) {
45404
45404
  while (aa % 2 === 0) {
45405
45405
  aa /= 2;
45406
- if (N % 8 === 3 || N % 8 === 5) jac = -jac;
45406
+ if (N2 % 8 === 3 || N2 % 8 === 5) jac = -jac;
45407
45407
  }
45408
- [aa, N] = [N, aa];
45409
- if (aa % 4 === 3 && N % 4 === 3) jac = -jac;
45410
- aa = aa % N;
45408
+ [aa, N2] = [N2, aa];
45409
+ if (aa % 4 === 3 && N2 % 4 === 3) jac = -jac;
45410
+ aa = aa % N2;
45411
45411
  }
45412
- return sign3 * (N === 1 ? jac : 0);
45412
+ return sign3 * (N2 === 1 ? jac : 0);
45413
45413
  }
45414
45414
  function combinationsGen(arr10, k) {
45415
45415
  const n = arr10.length;
@@ -45954,7 +45954,7 @@ function kruskalWallis(...groups) {
45954
45954
  const arrs = groups.map(arr2).filter((g) => g.length > 0);
45955
45955
  if (arrs.length < 2) throw new Error("kruskalWallis: need at least 2 non-empty groups");
45956
45956
  const pooled = arrs.flat();
45957
- const N = pooled.length;
45957
+ const N2 = pooled.length;
45958
45958
  const ranks = rankdata(pooled);
45959
45959
  let offset = 0;
45960
45960
  let sumRanksSq = 0;
@@ -45964,8 +45964,8 @@ function kruskalWallis(...groups) {
45964
45964
  sumRanksSq += rsum * rsum / g.length;
45965
45965
  offset += g.length;
45966
45966
  }
45967
- let H = 12 / (N * (N + 1)) * sumRanksSq - 3 * (N + 1);
45968
- const correction = 1 - tieTerm(pooled) / (N * N * N - N);
45967
+ let H = 12 / (N2 * (N2 + 1)) * sumRanksSq - 3 * (N2 + 1);
45968
+ const correction = 1 - tieTerm(pooled) / (N2 * N2 * N2 - N2);
45969
45969
  if (correction !== 0) H /= correction;
45970
45970
  const df = arrs.length - 1;
45971
45971
  return { statistic: H, pValue: 1 - chiSquaredCDF(H, df), df };
@@ -46002,8 +46002,8 @@ function fisherExact(table) {
46002
46002
  const r1 = a + b;
46003
46003
  const r2 = c + d;
46004
46004
  const c1 = a + c;
46005
- const N = a + b + c + d;
46006
- const logHyper = (k) => logChoose(r1, k) + logChoose(r2, c1 - k) - logChoose(N, c1);
46005
+ const N2 = a + b + c + d;
46006
+ const logHyper = (k) => logChoose(r1, k) + logChoose(r2, c1 - k) - logChoose(N2, c1);
46007
46007
  const logPObs = logHyper(a);
46008
46008
  const lo = Math.max(0, c1 - r2);
46009
46009
  const hi = Math.min(r1, c1);
@@ -46053,8 +46053,8 @@ function tukeyHSD(groups, alpha = 0.05) {
46053
46053
  const k = gs.length;
46054
46054
  if (k < 2) throw new Error("tukeyHSD: need at least 2 groups");
46055
46055
  const means = gs.map(mean3);
46056
- const N = gs.reduce((s, g) => s + g.length, 0);
46057
- const dfErr = N - k;
46056
+ const N2 = gs.reduce((s, g) => s + g.length, 0);
46057
+ const dfErr = N2 - k;
46058
46058
  if (dfErr <= 0)
46059
46059
  throw new Error("tukeyHSD: residual df must be > 0 (groups must hold more observations than groups)");
46060
46060
  const sse = gs.reduce((s, g) => s + sampleVar(g) * (g.length - 1), 0);
@@ -46103,9 +46103,9 @@ function triu(A, k = 0) {
46103
46103
  }
46104
46104
  function vander(x, n, increasing = false) {
46105
46105
  const v = arr3(x);
46106
- const N = n ?? v.length;
46106
+ const N2 = n ?? v.length;
46107
46107
  return v.map(
46108
- (xi) => Array.from({ length: N }, (_, j) => Math.pow(xi, increasing ? j : N - 1 - j))
46108
+ (xi) => Array.from({ length: N2 }, (_, j) => Math.pow(xi, increasing ? j : N2 - 1 - j))
46109
46109
  );
46110
46110
  }
46111
46111
  function toeplitz(c, r) {
@@ -47419,8 +47419,8 @@ function funm(A, f, fDerivs) {
47419
47419
  return out;
47420
47420
  }
47421
47421
  const { values } = eig3(A, { computeVectors: false });
47422
- const maxAbs = values.reduce((m, v) => Math.max(m, cAbs(v)), 0);
47423
- const tol = EIGENVALUE_DISTINCT_REL_TOL * Math.max(1, maxAbs);
47422
+ const maxAbs2 = values.reduce((m, v) => Math.max(m, cAbs(v)), 0);
47423
+ const tol = EIGENVALUE_DISTINCT_REL_TOL * Math.max(1, maxAbs2);
47424
47424
  const clusters = clusterEigenvalues(values, tol);
47425
47425
  if (clusters.length === n) {
47426
47426
  const F2 = cZeros(n);
@@ -47584,7 +47584,7 @@ function maxAbsDiff(A, B) {
47584
47584
  for (let j = 0; j < m; j++) d = Math.max(d, Math.abs(A[i][j] - B[i][j]));
47585
47585
  return d;
47586
47586
  }
47587
- function sylvesterOperator(M, N) {
47587
+ function sylvesterOperator(M, N2) {
47588
47588
  const n = M.length;
47589
47589
  const n26 = n * n;
47590
47590
  const L = zeros3(n26, n26);
@@ -47595,7 +47595,7 @@ function sylvesterOperator(M, N) {
47595
47595
  const mip = M[i][p];
47596
47596
  if (mip === 0) continue;
47597
47597
  for (let q = 0; q < n; q++) {
47598
- L[row2][p * n + q] = mip * N[q][j];
47598
+ L[row2][p * n + q] = mip * N2[q][j];
47599
47599
  }
47600
47600
  }
47601
47601
  }
@@ -47870,8 +47870,8 @@ function findSpan(n, p, u, U) {
47870
47870
  return mid;
47871
47871
  }
47872
47872
  function basisFuns(span, u, p, U) {
47873
- const N = new Array(p + 1);
47874
- N[0] = 1;
47873
+ const N2 = new Array(p + 1);
47874
+ N2[0] = 1;
47875
47875
  const left = new Array(p + 1);
47876
47876
  const right = new Array(p + 1);
47877
47877
  for (let j = 1; j <= p; j++) {
@@ -47879,13 +47879,13 @@ function basisFuns(span, u, p, U) {
47879
47879
  right[j] = U[span + j] - u;
47880
47880
  let saved = 0;
47881
47881
  for (let r = 0; r < j; r++) {
47882
- const temp = N[r] / (right[r + 1] + left[j - r]);
47883
- N[r] = saved + right[r + 1] * temp;
47882
+ const temp = N2[r] / (right[r + 1] + left[j - r]);
47883
+ N2[r] = saved + right[r + 1] * temp;
47884
47884
  saved = left[j - r] * temp;
47885
47885
  }
47886
- N[j] = saved;
47886
+ N2[j] = saved;
47887
47887
  }
47888
- return N;
47888
+ return N2;
47889
47889
  }
47890
47890
  function validateXY(x, y) {
47891
47891
  if (x.length !== y.length) throw new Error("bsplineFit: x and y must have the same length");
@@ -47898,8 +47898,8 @@ function buildDesignMatrix(x, t, k, numCoef) {
47898
47898
  const A = Array.from({ length: n }, () => new Array(numCoef).fill(0));
47899
47899
  for (let i = 0; i < n; i++) {
47900
47900
  const span = findSpan(numCoef - 1, k, x[i], t);
47901
- const N = basisFuns(span, x[i], k, t);
47902
- for (let j = 0; j <= k; j++) A[i][span - k + j] = N[j];
47901
+ const N2 = basisFuns(span, x[i], k, t);
47902
+ for (let j = 0; j <= k; j++) A[i][span - k + j] = N2[j];
47903
47903
  }
47904
47904
  return A;
47905
47905
  }
@@ -47948,9 +47948,9 @@ function bsplineEval(spline, xnew) {
47948
47948
  const nLast = c.length - 1;
47949
47949
  const evalOne = (x) => {
47950
47950
  const span = findSpan(nLast, k, x, t);
47951
- const N = basisFuns(span, x, k, t);
47951
+ const N2 = basisFuns(span, x, k, t);
47952
47952
  let val = 0;
47953
- for (let j = 0; j <= k; j++) val += N[j] * c[span - k + j];
47953
+ for (let j = 0; j <= k; j++) val += N2[j] * c[span - k + j];
47954
47954
  return val;
47955
47955
  };
47956
47956
  return Array.isArray(xnew) ? xnew.map(evalOne) : evalOne(xnew);
@@ -49758,18 +49758,18 @@ function analogToDigital(proto, Wn, btype) {
49758
49758
  ({ z, p, k } = bilinearZpk(z, p, k, fs));
49759
49759
  return zpkToTf(z, p, k);
49760
49760
  }
49761
- function buttap(N) {
49761
+ function buttap(N2) {
49762
49762
  const p = [];
49763
- for (let k = 0; k < N; k++) {
49764
- const m = -N + 1 + 2 * k;
49765
- const theta = Math.PI * m / (2 * N);
49763
+ for (let k = 0; k < N2; k++) {
49764
+ const m = -N2 + 1 + 2 * k;
49765
+ const theta = Math.PI * m / (2 * N2);
49766
49766
  p.push(new Complex11(-Math.cos(theta), -Math.sin(theta)));
49767
49767
  }
49768
49768
  return { z: [], p, k: 1 };
49769
49769
  }
49770
- function butter(N, Wn, btype = "low") {
49771
- if (!Number.isInteger(N) || N < 1) throw new Error("butter: order N must be a positive integer");
49772
- return analogToDigital(buttap(N), Wn, btype);
49770
+ function butter(N2, Wn, btype = "low") {
49771
+ if (!Number.isInteger(N2) || N2 < 1) throw new Error("butter: order N must be a positive integer");
49772
+ return analogToDigital(buttap(N2), Wn, btype);
49773
49773
  }
49774
49774
 
49775
49775
  // src/signal/fft.ts
@@ -49981,39 +49981,39 @@ function jacobiDN(u, m) {
49981
49981
 
49982
49982
  // src/signal/iir-design.ts
49983
49983
  var arr8 = (x) => Array.isArray(x) ? x : Array.from(x);
49984
- function cheb1ap(N, rp) {
49984
+ function cheb1ap(N2, rp) {
49985
49985
  const eps = Math.sqrt(Math.pow(10, 0.1 * rp) - 1);
49986
- const mu = 1 / N * Math.asinh(1 / eps);
49986
+ const mu = 1 / N2 * Math.asinh(1 / eps);
49987
49987
  const p = [];
49988
- for (let m = -N + 1; m < N; m += 2) {
49989
- const theta = Math.PI * m / (2 * N);
49988
+ for (let m = -N2 + 1; m < N2; m += 2) {
49989
+ const theta = Math.PI * m / (2 * N2);
49990
49990
  p.push(new Complex12(-Math.sinh(mu) * Math.cos(theta), -Math.cosh(mu) * Math.sin(theta)));
49991
49991
  }
49992
49992
  let prod2 = new Complex12(1, 0);
49993
49993
  for (const pv of p) prod2 = cMul2(prod2, pv.negate());
49994
49994
  let k = prod2.re;
49995
- if (N % 2 === 0) k /= Math.sqrt(1 + eps * eps);
49995
+ if (N2 % 2 === 0) k /= Math.sqrt(1 + eps * eps);
49996
49996
  return { z: [], p, k };
49997
49997
  }
49998
- function cheby1(N, rp, Wn, btype = "low") {
49999
- if (!Number.isInteger(N) || N < 1) throw new Error("cheby1: order N must be a positive integer");
49998
+ function cheby1(N2, rp, Wn, btype = "low") {
49999
+ if (!Number.isInteger(N2) || N2 < 1) throw new Error("cheby1: order N must be a positive integer");
50000
50000
  if (!(rp > 0)) throw new Error("cheby1: rp (passband ripple, dB) must be positive");
50001
- return analogToDigital(cheb1ap(N, rp), Wn, btype);
50001
+ return analogToDigital(cheb1ap(N2, rp), Wn, btype);
50002
50002
  }
50003
- function cheb2ap(N, rs) {
50003
+ function cheb2ap(N2, rs) {
50004
50004
  const de = 1 / Math.sqrt(Math.pow(10, 0.1 * rs) - 1);
50005
- const mu = Math.asinh(1 / de) / N;
50005
+ const mu = Math.asinh(1 / de) / N2;
50006
50006
  const mVals = [];
50007
- if (N % 2) {
50008
- for (let m = -N + 1; m < 0; m += 2) mVals.push(m);
50009
- for (let m = 2; m < N; m += 2) mVals.push(m);
50007
+ if (N2 % 2) {
50008
+ for (let m = -N2 + 1; m < 0; m += 2) mVals.push(m);
50009
+ for (let m = 2; m < N2; m += 2) mVals.push(m);
50010
50010
  } else {
50011
- for (let m = -N + 1; m < N; m += 2) mVals.push(m);
50011
+ for (let m = -N2 + 1; m < N2; m += 2) mVals.push(m);
50012
50012
  }
50013
- const z = mVals.map((m) => new Complex12(0, 1 / Math.sin(m * Math.PI / (2 * N))));
50013
+ const z = mVals.map((m) => new Complex12(0, 1 / Math.sin(m * Math.PI / (2 * N2))));
50014
50014
  const p = [];
50015
- for (let m = -N + 1; m < N; m += 2) {
50016
- const theta = Math.PI * m / (2 * N);
50015
+ for (let m = -N2 + 1; m < N2; m += 2) {
50016
+ const theta = Math.PI * m / (2 * N2);
50017
50017
  const s = new Complex12(Math.sinh(mu) * Math.cos(theta), Math.cosh(mu) * Math.sin(theta));
50018
50018
  p.push(cDiv2(new Complex12(1, 0), s).negate());
50019
50019
  }
@@ -50024,17 +50024,17 @@ function cheb2ap(N, rs) {
50024
50024
  const k = cDiv2(prodP, prodZ).re;
50025
50025
  return { z, p, k };
50026
50026
  }
50027
- function cheby2(N, rs, Wn, btype = "low") {
50028
- if (!Number.isInteger(N) || N < 1) throw new Error("cheby2: order N must be a positive integer");
50027
+ function cheby2(N2, rs, Wn, btype = "low") {
50028
+ if (!Number.isInteger(N2) || N2 < 1) throw new Error("cheby2: order N must be a positive integer");
50029
50029
  if (!(rs > 0)) throw new Error("cheby2: rs (stopband attenuation, dB) must be positive");
50030
- return analogToDigital(cheb2ap(N, rs), Wn, btype);
50030
+ return analogToDigital(cheb2ap(N2, rs), Wn, btype);
50031
50031
  }
50032
50032
  var ELLIPDEG_MMAX = 7;
50033
- function ellipdeg(N, m1) {
50033
+ function ellipdeg(N2, m1) {
50034
50034
  const K1 = ellipticKScalar(m1);
50035
50035
  const K1p = ellipticKScalar(1 - m1);
50036
50036
  const q1 = Math.exp(-Math.PI * K1p / K1);
50037
- const q = Math.pow(q1, 1 / N);
50037
+ const q = Math.pow(q1, 1 / N2);
50038
50038
  let num2 = 0;
50039
50039
  for (let i = 0; i <= ELLIPDEG_MMAX; i++) num2 += Math.pow(q, i * (i + 1));
50040
50040
  let den = 1;
@@ -50085,8 +50085,8 @@ function arcJacSc1(w, m) {
50085
50085
  throw new Error("ellip: elliptic filter design failed to converge (arcJacSc1)");
50086
50086
  return z.im;
50087
50087
  }
50088
- function ellipap(N, rp, rs) {
50089
- if (N === 1) {
50088
+ function ellipap(N2, rp, rs) {
50089
+ if (N2 === 1) {
50090
50090
  const p = -Math.sqrt(1 / (Math.pow(10, 0.1 * rp) - 1));
50091
50091
  return { z: [], p: [new Complex12(p, 0)], k: -p };
50092
50092
  }
@@ -50095,16 +50095,16 @@ function ellipap(N, rp, rs) {
50095
50095
  const ck1Sq = epsSq / (Math.pow(10, 0.1 * rs) - 1);
50096
50096
  if (ck1Sq <= 0) throw new Error("ellip: cannot design a filter with the given rp/rs");
50097
50097
  const val0 = ellipticKScalar(ck1Sq);
50098
- const m = ellipdeg(N, ck1Sq);
50098
+ const m = ellipdeg(N2, ck1Sq);
50099
50099
  const capk = ellipticKScalar(m);
50100
50100
  const j = [];
50101
- for (let v = 1 - N % 2; v < N; v += 2) j.push(v);
50101
+ for (let v = 1 - N2 % 2; v < N2; v += 2) j.push(v);
50102
50102
  const EPSILON = 2e-16;
50103
50103
  const s = [];
50104
50104
  const c = [];
50105
50105
  const d = [];
50106
50106
  for (const jv of j) {
50107
- const u = jv * capk / N;
50107
+ const u = jv * capk / N2;
50108
50108
  s.push(jacobiSN(u, m));
50109
50109
  c.push(jacobiCN(u, m));
50110
50110
  d.push(jacobiDN(u, m));
@@ -50115,7 +50115,7 @@ function ellipap(N, rp, rs) {
50115
50115
  }
50116
50116
  const zFull = zHalf.concat(zHalf.map((zv) => new Complex12(zv.re, -zv.im)));
50117
50117
  const rr = arcJacSc1(1 / eps, ck1Sq);
50118
- const v0 = capk * rr / (N * val0);
50118
+ const v0 = capk * rr / (N2 * val0);
50119
50119
  const sv = jacobiSN(v0, 1 - m);
50120
50120
  const cv = jacobiCN(v0, 1 - m);
50121
50121
  const dv = jacobiDN(v0, 1 - m);
@@ -50126,7 +50126,7 @@ function ellipap(N, rp, rs) {
50126
50126
  pHalf.push(new Complex12(num2.re / den, num2.im / den));
50127
50127
  }
50128
50128
  let pFull;
50129
- if (N % 2) {
50129
+ if (N2 % 2) {
50130
50130
  const sumP2 = pHalf.reduce((acc, pv) => acc + pv.re * pv.re + pv.im * pv.im, 0);
50131
50131
  const thresh = EPSILON * Math.sqrt(sumP2);
50132
50132
  const newp = pHalf.filter((pv) => Math.abs(pv.im) > thresh);
@@ -50139,14 +50139,14 @@ function ellipap(N, rp, rs) {
50139
50139
  let prodZ = new Complex12(1, 0);
50140
50140
  for (const zv of zFull) prodZ = cMul2(prodZ, zv.negate());
50141
50141
  let k = cDiv2(prodP, prodZ).re;
50142
- if (N % 2 === 0) k /= Math.sqrt(1 + epsSq);
50142
+ if (N2 % 2 === 0) k /= Math.sqrt(1 + epsSq);
50143
50143
  return { z: zFull, p: pFull, k };
50144
50144
  }
50145
- function ellip(N, rp, rs, Wn, btype = "low") {
50146
- if (!Number.isInteger(N) || N < 1) throw new Error("ellip: order N must be a positive integer");
50145
+ function ellip(N2, rp, rs, Wn, btype = "low") {
50146
+ if (!Number.isInteger(N2) || N2 < 1) throw new Error("ellip: order N must be a positive integer");
50147
50147
  if (!(rp > 0)) throw new Error("ellip: rp (passband ripple, dB) must be positive");
50148
50148
  if (!(rs > 0)) throw new Error("ellip: rs (stopband attenuation, dB) must be positive");
50149
- return analogToDigital(ellipap(N, rp, rs), Wn, btype);
50149
+ return analogToDigital(ellipap(N2, rp, rs), Wn, btype);
50150
50150
  }
50151
50151
  function polyMul2(p, q) {
50152
50152
  const res = new Array(p.length + q.length - 1).fill(0);
@@ -50174,7 +50174,7 @@ function bilinear(bIn, aIn, fs) {
50174
50174
  const aTrim = trimLeadingZeros(arr8(aIn));
50175
50175
  const Q2 = bTrim.length - 1;
50176
50176
  const P2 = aTrim.length - 1;
50177
- const N = Math.max(P2, Q2);
50177
+ const N2 = Math.max(P2, Q2);
50178
50178
  const kappa = 2 * fs;
50179
50179
  const zp1 = [1, 1];
50180
50180
  const zm1 = [-kappa, kappa];
@@ -50183,7 +50183,7 @@ function bilinear(bIn, aIn, fs) {
50183
50183
  const bq = bTrim[Q2 - q];
50184
50184
  numerator = polyAdd2(
50185
50185
  numerator,
50186
- polyMul2(polyPow2(zp1, N - q), polyPow2(zm1, q)).map((v) => v * bq)
50186
+ polyMul2(polyPow2(zp1, N2 - q), polyPow2(zm1, q)).map((v) => v * bq)
50187
50187
  );
50188
50188
  }
50189
50189
  let denominator = [0];
@@ -50191,7 +50191,7 @@ function bilinear(bIn, aIn, fs) {
50191
50191
  const ap = aTrim[P2 - p];
50192
50192
  denominator = polyAdd2(
50193
50193
  denominator,
50194
- polyMul2(polyPow2(zp1, N - p), polyPow2(zm1, p)).map((v) => v * ap)
50194
+ polyMul2(polyPow2(zp1, N2 - p), polyPow2(zm1, p)).map((v) => v * ap)
50195
50195
  );
50196
50196
  }
50197
50197
  const bDesc = numerator.slice().reverse();
@@ -50332,23 +50332,23 @@ function buttord(wp, ws, gpass, gstop) {
50332
50332
  const nat1 = (stopb[1] * stopb[1] - passb[0] * passb[1]) / (stopb[1] * (passb[0] - passb[1]));
50333
50333
  nat = Math.min(Math.abs(nat0), Math.abs(nat1));
50334
50334
  }
50335
- const N = Math.ceil(Math.log10((GSTOP - 1) / (GPASS - 1)) / (2 * Math.log10(nat)));
50336
- const W0 = Math.pow(GPASS - 1, -1 / (2 * N));
50335
+ const N2 = Math.ceil(Math.log10((GSTOP - 1) / (GPASS - 1)) / (2 * Math.log10(nat)));
50336
+ const W0 = Math.pow(GPASS - 1, -1 / (2 * N2));
50337
50337
  const toDigital = (WN) => Math.atan(WN) * 2 / Math.PI;
50338
- if (filterType === 1) return { N, Wn: toDigital(W0 * passb[0]) };
50339
- if (filterType === 2) return { N, Wn: toDigital(passb[0] / W0) };
50338
+ if (filterType === 1) return { N: N2, Wn: toDigital(W0 * passb[0]) };
50339
+ if (filterType === 2) return { N: N2, Wn: toDigital(passb[0] / W0) };
50340
50340
  if (filterType === 3) {
50341
50341
  const discr = Math.sqrt(Math.pow(passb[1] - passb[0], 2) + 4 * W0 * W0 * passb[0] * passb[1]);
50342
50342
  const wn0 = (passb[1] - passb[0] + discr) / (2 * W0);
50343
50343
  const wn1 = (passb[1] - passb[0] - discr) / (2 * W0);
50344
50344
  const sorted2 = [Math.abs(wn0), Math.abs(wn1)].sort((x, y) => x - y);
50345
- return { N, Wn: [toDigital(sorted2[0]), toDigital(sorted2[1])] };
50345
+ return { N: N2, Wn: [toDigital(sorted2[0]), toDigital(sorted2[1])] };
50346
50346
  }
50347
50347
  const w0s = [-W0, W0].map(
50348
50348
  (s) => -s * ((passb[1] - passb[0]) / 2) + Math.sqrt(s * s / 4 * Math.pow(passb[1] - passb[0], 2) + passb[0] * passb[1])
50349
50349
  );
50350
50350
  const sorted = w0s.map(Math.abs).sort((x, y) => x - y);
50351
- return { N, Wn: [toDigital(sorted[0]), toDigital(sorted[1])] };
50351
+ return { N: N2, Wn: [toDigital(sorted[0]), toDigital(sorted[1])] };
50352
50352
  }
50353
50353
  function toComplex(x) {
50354
50354
  return x instanceof Complex12 ? x : new Complex12(x, 0);
@@ -51091,13 +51091,13 @@ function savgol(x, windowLength, polyorder) {
51091
51091
  function deconvolve(signal, divisor) {
51092
51092
  const s = arr9(signal);
51093
51093
  const d = arr9(divisor);
51094
- const N = s.length;
51094
+ const N2 = s.length;
51095
51095
  const D = d.length;
51096
51096
  if (D === 0) throw new Error("deconvolve: divisor must be non-empty");
51097
51097
  if (d[0] === 0) throw new Error("deconvolve: divisor[0] (leading coefficient) must be nonzero");
51098
- if (D > N) return { quotient: [], remainder: s.slice() };
51098
+ if (D > N2) return { quotient: [], remainder: s.slice() };
51099
51099
  const remainder = s.slice();
51100
- const quotient = new Array(N - D + 1).fill(0);
51100
+ const quotient = new Array(N2 - D + 1).fill(0);
51101
51101
  for (let i = 0; i < quotient.length; i++) {
51102
51102
  const c = remainder[i] / d[0];
51103
51103
  quotient[i] = c;
@@ -52068,6 +52068,177 @@ function sphericalVoronoi(points, radius = 1, center3 = [0, 0, 0]) {
52068
52068
  return { vertices, regions, areas };
52069
52069
  }
52070
52070
 
52071
+ // src/geometry/halfspace-intersection.ts
52072
+ var STRICT_INTERIOR_REL = 1e-12;
52073
+ var BOUNDED_REL = 1e-9;
52074
+ var TIGHT_REL = 1e-9;
52075
+ var DEDUP_SIG = 9;
52076
+ var SINGULAR_REL = 1e-12;
52077
+ function maxAbs(points) {
52078
+ let m = 0;
52079
+ for (const p of points) {
52080
+ for (const x of p) {
52081
+ const a = Math.abs(x);
52082
+ if (a > m) m = a;
52083
+ }
52084
+ }
52085
+ return m;
52086
+ }
52087
+ function rowNorm(row2) {
52088
+ let s = 0;
52089
+ for (const x of row2) s += x * x;
52090
+ return Math.sqrt(s);
52091
+ }
52092
+ function isSingular(det2, a) {
52093
+ let bound = 1;
52094
+ for (const row2 of a) bound *= rowNorm(row2);
52095
+ return bound === 0 || Math.abs(det2) <= SINGULAR_REL * bound;
52096
+ }
52097
+ function solve2(a, c) {
52098
+ const det2 = a[0][0] * a[1][1] - a[0][1] * a[1][0];
52099
+ if (isSingular(det2, a)) return null;
52100
+ return [(c[0] * a[1][1] - c[1] * a[0][1]) / det2, (a[0][0] * c[1] - a[1][0] * c[0]) / det2];
52101
+ }
52102
+ function solve3(a, c) {
52103
+ const det2 = a[0][0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1]) - a[0][1] * (a[1][0] * a[2][2] - a[1][2] * a[2][0]) + a[0][2] * (a[1][0] * a[2][1] - a[1][1] * a[2][0]);
52104
+ if (isSingular(det2, a)) return null;
52105
+ const detFor = (col) => {
52106
+ const m = a.map((row2, i) => row2.map((v, j) => j === col ? c[i] : v));
52107
+ return m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);
52108
+ };
52109
+ return [detFor(0) / det2, detFor(1) / det2, detFor(2) / det2];
52110
+ }
52111
+ function originStrictlyInside(dual, hull, dim) {
52112
+ for (const simplex of hull.simplices) {
52113
+ const p0 = dual[simplex[0]];
52114
+ if (dim === 2) {
52115
+ const p1 = dual[simplex[1]];
52116
+ const ex = p1[0] - p0[0];
52117
+ const ey = p1[1] - p0[1];
52118
+ const edgeLen = Math.hypot(ex, ey);
52119
+ if (edgeLen === 0) continue;
52120
+ const dist = (ex * (0 - p0[1]) - ey * (0 - p0[0])) / edgeLen;
52121
+ if (dist <= BOUNDED_REL) return false;
52122
+ } else {
52123
+ const p1 = dual[simplex[1]];
52124
+ const p2 = dual[simplex[2]];
52125
+ const ux = p1[0] - p0[0];
52126
+ const uy = p1[1] - p0[1];
52127
+ const uz = p1[2] - p0[2];
52128
+ const vx = p2[0] - p0[0];
52129
+ const vy = p2[1] - p0[1];
52130
+ const vz = p2[2] - p0[2];
52131
+ const nx = uy * vz - uz * vy;
52132
+ const ny = uz * vx - ux * vz;
52133
+ const nz = ux * vy - uy * vx;
52134
+ const nLen = Math.hypot(nx, ny, nz);
52135
+ if (nLen === 0) continue;
52136
+ const dist = -(p0[0] * nx + p0[1] * ny + p0[2] * nz) / nLen;
52137
+ if (dist >= -BOUNDED_REL) return false;
52138
+ }
52139
+ }
52140
+ return true;
52141
+ }
52142
+ function halfspaceIntersection(halfspaces, interiorPoint) {
52143
+ if (!Array.isArray(halfspaces) || halfspaces.length === 0) {
52144
+ throw new Error("halfspaceIntersection: requires a non-empty array of halfspaces");
52145
+ }
52146
+ if (!Array.isArray(interiorPoint)) {
52147
+ throw new Error("halfspaceIntersection: interiorPoint must be a coordinate array");
52148
+ }
52149
+ const dim = interiorPoint.length;
52150
+ if (dim !== 2 && dim !== 3) {
52151
+ throw new Error(
52152
+ `halfspaceIntersection: only 2-D and 3-D polytopes are supported (got dimension ${dim}). The general n-D case requires an n-D convex hull or the double-description method, which is not yet implemented.`
52153
+ );
52154
+ }
52155
+ for (const hs of halfspaces) {
52156
+ if (!Array.isArray(hs) || hs.length !== dim + 1) {
52157
+ throw new Error(
52158
+ `halfspaceIntersection: each halfspace must be a row [a_1..a_${dim}, b] of length ${dim + 1}`
52159
+ );
52160
+ }
52161
+ }
52162
+ if (halfspaces.length < dim + 1) {
52163
+ throw new Error(
52164
+ `halfspaceIntersection: the polytope is unbounded \u2014 a bounded ${dim}-D polytope needs at least ${dim + 1} halfspaces (got ${halfspaces.length}); fewer cannot enclose a bounded region`
52165
+ );
52166
+ }
52167
+ const offsets = [];
52168
+ const offsetScales = [];
52169
+ for (const hs of halfspaces) {
52170
+ let s = hs[dim];
52171
+ let mag = Math.abs(hs[dim]);
52172
+ for (let j = 0; j < dim; j++) {
52173
+ const term = hs[j] * interiorPoint[j];
52174
+ s += term;
52175
+ mag += Math.abs(term);
52176
+ }
52177
+ offsets.push(s);
52178
+ offsetScales.push(mag);
52179
+ }
52180
+ for (let i = 0; i < offsets.length; i++) {
52181
+ if (offsets[i] >= -STRICT_INTERIOR_REL * offsetScales[i]) {
52182
+ throw new Error(
52183
+ `halfspaceIntersection: interiorPoint is not strictly interior \u2014 halfspace ${i} gives a\xB7x\u2080 + b = ${offsets[i]} (must be < 0)`
52184
+ );
52185
+ }
52186
+ }
52187
+ const dual = halfspaces.map((hs, i) => {
52188
+ const d = -offsets[i];
52189
+ const y = new Array(dim);
52190
+ for (let j = 0; j < dim; j++) y[j] = hs[j] / d;
52191
+ return y;
52192
+ });
52193
+ const dualScale = maxAbs(dual);
52194
+ const dualN = dualScale > 0 && Number.isFinite(dualScale) ? dual.map((y) => y.map((x) => x / dualScale)) : dual;
52195
+ const hull = convexHull(dualN);
52196
+ if (!originStrictlyInside(dualN, hull, dim)) {
52197
+ throw new Error(
52198
+ "halfspaceIntersection: the polytope is unbounded (the halfspace normals do not positively span the space); vertex enumeration requires a bounded polytope"
52199
+ );
52200
+ }
52201
+ const candidates = [];
52202
+ for (const simplex of hull.simplices) {
52203
+ const aRows = simplex.map((idx) => halfspaces[idx].slice(0, dim));
52204
+ const cVals = simplex.map((idx) => -halfspaces[idx][dim]);
52205
+ const v = dim === 2 ? solve2(aRows, cVals) : solve3(aRows, cVals);
52206
+ if (v === null) continue;
52207
+ if (!v.every((x) => Number.isFinite(x))) continue;
52208
+ candidates.push(v);
52209
+ }
52210
+ const vertScale = maxAbs(candidates);
52211
+ const quantum = vertScale > 0 ? vertScale * Math.pow(10, -DEDUP_SIG) : 0;
52212
+ const vertices = [];
52213
+ const seen = /* @__PURE__ */ new Set();
52214
+ 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);
52218
+ vertices.push(v);
52219
+ }
52220
+ if (dim === 2 && vertices.length > 2) {
52221
+ const cx = vertices.reduce((s, v) => s + v[0], 0) / vertices.length;
52222
+ const cy = vertices.reduce((s, v) => s + v[1], 0) / vertices.length;
52223
+ vertices.sort((p, q) => Math.atan2(p[1] - cy, p[0] - cx) - Math.atan2(q[1] - cy, q[0] - cx));
52224
+ }
52225
+ const incidences = vertices.map((v) => {
52226
+ const tight = [];
52227
+ for (let i = 0; i < halfspaces.length; i++) {
52228
+ let s = halfspaces[i][dim];
52229
+ let mag = Math.abs(halfspaces[i][dim]);
52230
+ for (let j = 0; j < dim; j++) {
52231
+ const term = halfspaces[i][j] * v[j];
52232
+ s += term;
52233
+ mag += Math.abs(term);
52234
+ }
52235
+ if (Math.abs(s) <= TIGHT_REL * mag) tight.push(i);
52236
+ }
52237
+ return tight;
52238
+ });
52239
+ return { vertices, incidences };
52240
+ }
52241
+
52071
52242
  // src/stats/inference-extra2.ts
52072
52243
  var TWO_PI = 2 * Math.PI;
52073
52244
  function noncentralChi2CDF(x, df, nc) {
@@ -52182,7 +52353,7 @@ function cochranQ(data) {
52182
52353
  if (k < 2) throw new Error("cochranQ: need at least 2 treatments (columns)");
52183
52354
  const colSums = new Array(k).fill(0);
52184
52355
  const rowSums = new Array(n).fill(0);
52185
- let N = 0;
52356
+ let N2 = 0;
52186
52357
  for (let i = 0; i < n; i++) {
52187
52358
  if (data[i].length !== k) throw new Error("cochranQ: data must be rectangular");
52188
52359
  let rowSum = 0;
@@ -52191,15 +52362,15 @@ function cochranQ(data) {
52191
52362
  rowSum += data[i][j];
52192
52363
  }
52193
52364
  rowSums[i] = rowSum;
52194
- N += rowSum;
52365
+ N2 += rowSum;
52195
52366
  }
52196
52367
  let sumC2 = 0;
52197
52368
  for (let j = 0; j < k; j++) sumC2 += colSums[j] * colSums[j];
52198
52369
  let sumR2 = 0;
52199
52370
  for (let i = 0; i < n; i++) sumR2 += rowSums[i] * rowSums[i];
52200
52371
  const dof = k - 1;
52201
- const denominator = k * N - sumR2;
52202
- const Q2 = denominator !== 0 ? dof * (k * sumC2 - N * N) / denominator : 0;
52372
+ const denominator = k * N2 - sumR2;
52373
+ const Q2 = denominator !== 0 ? dof * (k * sumC2 - N2 * N2) / denominator : 0;
52203
52374
  const pValue = 1 - chiSquaredCDF(Q2, dof);
52204
52375
  return { Q: Q2, pValue, dof };
52205
52376
  }
@@ -52682,6 +52853,106 @@ function coulombFG(L, eta, rho) {
52682
52853
  return coulombSteed(L, eta, rho);
52683
52854
  }
52684
52855
 
52856
+ // src/special/mathieu.ts
52857
+ import { eig as eig4 } from "@danielsimonjr/mathts-matrix";
52858
+ var N = 50;
52859
+ function harmonicsFor(cls) {
52860
+ const h = new Int32Array(N);
52861
+ for (let k = 0; k < N; k++) {
52862
+ switch (cls) {
52863
+ case "even-cos":
52864
+ h[k] = 2 * k;
52865
+ break;
52866
+ case "odd-cos":
52867
+ case "odd-sin":
52868
+ h[k] = 2 * k + 1;
52869
+ break;
52870
+ case "even-sin":
52871
+ h[k] = 2 * k + 2;
52872
+ break;
52873
+ }
52874
+ }
52875
+ return h;
52876
+ }
52877
+ function buildMatrix(cls, q) {
52878
+ const A = Array.from({ length: N }, () => new Array(N).fill(0));
52879
+ const h = harmonicsFor(cls);
52880
+ for (let k = 0; k < N; k++) A[k][k] = h[k] * h[k];
52881
+ if (cls === "odd-cos") A[0][0] = 1 + q;
52882
+ else if (cls === "odd-sin") A[0][0] = 1 - q;
52883
+ for (let k = 0; k < N - 1; k++) {
52884
+ const off = cls === "even-cos" && k === 0 ? q * Math.SQRT2 : q;
52885
+ A[k][k + 1] = off;
52886
+ A[k + 1][k] = off;
52887
+ }
52888
+ return A;
52889
+ }
52890
+ var modeCache = /* @__PURE__ */ new Map();
52891
+ function solveClass(cls, q) {
52892
+ const key = `${cls}:${q}`;
52893
+ const cached = modeCache.get(key);
52894
+ if (cached) return cached;
52895
+ const harmonics = harmonicsFor(cls);
52896
+ const { values, vectors } = eig4(buildMatrix(cls, q));
52897
+ const order = values.map((_, i) => i).sort((i, j) => values[i].re - values[j].re);
52898
+ const modes = order.map((idx, m) => {
52899
+ const g = vectors[idx];
52900
+ const coeffs = new Float64Array(N);
52901
+ if (cls === "even-cos") {
52902
+ coeffs[0] = g[0];
52903
+ for (let k = 1; k < N; k++) coeffs[k] = Math.SQRT2 * g[k];
52904
+ } else {
52905
+ for (let k = 0; k < N; k++) coeffs[k] = g[k];
52906
+ }
52907
+ let norm28 = 0;
52908
+ for (let k = 0; k < N; k++) {
52909
+ const w = cls === "even-cos" && k === 0 ? 2 : 1;
52910
+ norm28 += w * coeffs[k] * coeffs[k];
52911
+ }
52912
+ const scale4 = 1 / Math.sqrt(norm28);
52913
+ const sign3 = coeffs[m] < 0 ? -scale4 : scale4;
52914
+ for (let k = 0; k < N; k++) coeffs[k] *= sign3;
52915
+ return { a: values[idx].re, coeffs, harmonics };
52916
+ });
52917
+ modeCache.set(key, modes);
52918
+ return modes;
52919
+ }
52920
+ function checkOrder(n, min2, name254) {
52921
+ if (!Number.isInteger(n) || n < min2) {
52922
+ throw new Error(`${name254}: order n must be an integer \u2265 ${min2}, got ${n}`);
52923
+ }
52924
+ }
52925
+ function mathieuA(n, q) {
52926
+ checkOrder(n, 0, "mathieuA");
52927
+ const cls = n % 2 === 0 ? "even-cos" : "odd-cos";
52928
+ const m = Math.floor(n / 2);
52929
+ return solveClass(cls, q)[m].a;
52930
+ }
52931
+ function mathieuB(n, q) {
52932
+ checkOrder(n, 1, "mathieuB");
52933
+ const cls = n % 2 === 0 ? "even-sin" : "odd-sin";
52934
+ const m = Math.floor((n - (n % 2 === 0 ? 2 : 1)) / 2);
52935
+ return solveClass(cls, q)[m].a;
52936
+ }
52937
+ function evalSeries(mode2, x, basis) {
52938
+ let s = 0;
52939
+ const { coeffs, harmonics } = mode2;
52940
+ for (let k = 0; k < N; k++) s += coeffs[k] * basis(harmonics[k] * x);
52941
+ return s;
52942
+ }
52943
+ function mathieuCe(n, q, x) {
52944
+ checkOrder(n, 0, "mathieuCe");
52945
+ const cls = n % 2 === 0 ? "even-cos" : "odd-cos";
52946
+ const m = Math.floor(n / 2);
52947
+ return evalSeries(solveClass(cls, q)[m], x, Math.cos);
52948
+ }
52949
+ function mathieuSe(n, q, x) {
52950
+ checkOrder(n, 1, "mathieuSe");
52951
+ const cls = n % 2 === 0 ? "even-sin" : "odd-sin";
52952
+ const m = Math.floor((n - (n % 2 === 0 ? 2 : 1)) / 2);
52953
+ return evalSeries(solveClass(cls, q)[m], x, Math.sin);
52954
+ }
52955
+
52685
52956
  // src/graph/traversal-centrality.ts
52686
52957
  function bfs(adj, start) {
52687
52958
  const n = adj.length;
@@ -53143,8 +53414,8 @@ var Interval = class {
53143
53414
  if (this.hi <= 0) {
53144
53415
  return outward(this.hi ** n, this.lo ** n);
53145
53416
  }
53146
- const maxAbs = Math.max(Math.abs(this.lo), Math.abs(this.hi));
53147
- return outward(0, maxAbs ** n);
53417
+ const maxAbs2 = Math.max(Math.abs(this.lo), Math.abs(this.hi));
53418
+ return outward(0, maxAbs2 ** n);
53148
53419
  }
53149
53420
  };
53150
53421
  function interval(lo, hi) {
@@ -54346,6 +54617,7 @@ export {
54346
54617
  groebnerBasis,
54347
54618
  groupDelay,
54348
54619
  gumbelDist,
54620
+ halfspaceIntersection,
54349
54621
  halley,
54350
54622
  harmonicCentrality,
54351
54623
  harmonicNumber,
@@ -54512,6 +54784,10 @@ export {
54512
54784
  mannWhitneyTest,
54513
54785
  map2 as map,
54514
54786
  mapSlices,
54787
+ mathieuA,
54788
+ mathieuB,
54789
+ mathieuCe,
54790
+ mathieuSe,
54515
54791
  matmul,
54516
54792
  matrix,
54517
54793
  matrixExpm,