@danielsimonjr/mathts-functions 0.57.0 → 0.58.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 +1144 -300
- package/dist/typed/algebra.d.ts +8 -5
- package/dist/typed/algebra.d.ts.map +1 -1
- package/dist/typed/factorization/finite-field.d.ts +84 -0
- package/dist/typed/factorization/finite-field.d.ts.map +1 -0
- package/dist/typed/factorization/hensel.d.ts +38 -0
- package/dist/typed/factorization/hensel.d.ts.map +1 -0
- package/dist/typed/factorization/index.d.ts +47 -0
- package/dist/typed/factorization/index.d.ts.map +1 -0
- package/dist/typed/factorization/integer-poly.d.ts +82 -0
- package/dist/typed/factorization/integer-poly.d.ts.map +1 -0
- package/dist/typed/factorization/square-free.d.ts +37 -0
- package/dist/typed/factorization/square-free.d.ts.map +1 -0
- package/dist/typed/factorization/zassenhaus.d.ts +36 -0
- package/dist/typed/factorization/zassenhaus.d.ts.map +1 -0
- package/package.json +1 -1
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: () =>
|
|
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: () =>
|
|
134
|
+
degree: () => degree2,
|
|
135
135
|
delaunayTriangulation: () => delaunayTriangulation,
|
|
136
136
|
differences: () => differences,
|
|
137
137
|
digamma: () => digamma,
|
|
@@ -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,
|
|
9447
|
+
function polyFitJS(xs, ys, degree3, buildRow) {
|
|
9448
9448
|
const n = xs.length;
|
|
9449
|
-
const k =
|
|
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,
|
|
9527
|
-
const result = polyFitJS(xs, ys,
|
|
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,
|
|
9532
|
-
const result = polyFitJS(xs, ys,
|
|
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,
|
|
9537
|
-
const result = polyFitJS(xs, ys,
|
|
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,
|
|
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,
|
|
9552
|
+
mod3[asName](hx, hy, degree3)
|
|
9553
9553
|
)
|
|
9554
9554
|
);
|
|
9555
|
-
if (out && out.length ===
|
|
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,
|
|
9562
|
+
return jsFallback(xs, ys, degree3);
|
|
9563
9563
|
}
|
|
9564
|
-
function polyFitDispatch(xs, ys,
|
|
9565
|
-
return fitDispatch(xs, ys,
|
|
9564
|
+
function polyFitDispatch(xs, ys, degree3) {
|
|
9565
|
+
return fitDispatch(xs, ys, degree3, "poly_fit_f64", polyFitJSFallback);
|
|
9566
9566
|
}
|
|
9567
|
-
function chebFitDispatch(xs, ys,
|
|
9568
|
-
return fitDispatch(xs, ys,
|
|
9567
|
+
function chebFitDispatch(xs, ys, degree3) {
|
|
9568
|
+
return fitDispatch(xs, ys, degree3, "cheb_fit_f64", chebFitJSFallback);
|
|
9569
9569
|
}
|
|
9570
|
-
function legendreFitDispatch(xs, ys,
|
|
9571
|
-
return fitDispatch(xs, ys,
|
|
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
|
|
@@ -9824,6 +9824,842 @@ 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/index.ts
|
|
10577
|
+
var INT_TOLERANCE = 1e-7;
|
|
10578
|
+
function polyToDense(p) {
|
|
10579
|
+
let maxPow = 0;
|
|
10580
|
+
for (const t of p) maxPow = Math.max(maxPow, t.powers[0] ?? 0);
|
|
10581
|
+
const dense = new Array(maxPow + 1).fill(0);
|
|
10582
|
+
for (const t of p) dense[t.powers[0]] += t.coeff;
|
|
10583
|
+
let n = dense.length;
|
|
10584
|
+
while (n > 0 && Math.abs(dense[n - 1]) < 1e-9) n -= 1;
|
|
10585
|
+
return dense.slice(0, n);
|
|
10586
|
+
}
|
|
10587
|
+
function cleanUnivariatePoly(coeffs, v) {
|
|
10588
|
+
const parts = [];
|
|
10589
|
+
for (let i = coeffs.length - 1; i >= 0; i -= 1) {
|
|
10590
|
+
const c = Math.round(coeffs[i]);
|
|
10591
|
+
if (c === 0) continue;
|
|
10592
|
+
const abs2 = Math.abs(c);
|
|
10593
|
+
let term;
|
|
10594
|
+
if (i === 0) {
|
|
10595
|
+
term = String(abs2);
|
|
10596
|
+
} else {
|
|
10597
|
+
const varPart = i === 1 ? v : `${v}^${i}`;
|
|
10598
|
+
term = abs2 === 1 ? varPart : `${abs2}*${varPart}`;
|
|
10599
|
+
}
|
|
10600
|
+
if (parts.length === 0) {
|
|
10601
|
+
parts.push(c < 0 ? `-${term}` : term);
|
|
10602
|
+
} else {
|
|
10603
|
+
parts.push(c < 0 ? "-" : "+", term);
|
|
10604
|
+
}
|
|
10605
|
+
}
|
|
10606
|
+
return parts.length === 0 ? "0" : parts.join(" ");
|
|
10607
|
+
}
|
|
10608
|
+
function renderLinearFactor(poly, v) {
|
|
10609
|
+
const b = poly[0];
|
|
10610
|
+
const a = poly[1];
|
|
10611
|
+
const base = a === 1n ? v : `${a}*${v}`;
|
|
10612
|
+
if (b === 0n) return `(${base})`;
|
|
10613
|
+
return b < 0n ? `(${base} - ${-b})` : `(${base} + ${b})`;
|
|
10614
|
+
}
|
|
10615
|
+
function renderIntPoly(coeffs, v) {
|
|
10616
|
+
const parts = [];
|
|
10617
|
+
for (let i = coeffs.length - 1; i >= 0; i -= 1) {
|
|
10618
|
+
const c = coeffs[i];
|
|
10619
|
+
if (c === 0n) continue;
|
|
10620
|
+
const abs2 = c < 0n ? -c : c;
|
|
10621
|
+
let term;
|
|
10622
|
+
if (i === 0) {
|
|
10623
|
+
term = abs2.toString();
|
|
10624
|
+
} else {
|
|
10625
|
+
const varPart = i === 1 ? v : `${v}^${i}`;
|
|
10626
|
+
term = abs2 === 1n ? varPart : `${abs2}*${varPart}`;
|
|
10627
|
+
}
|
|
10628
|
+
if (parts.length === 0) {
|
|
10629
|
+
parts.push(c < 0n ? `-${term}` : term);
|
|
10630
|
+
} else {
|
|
10631
|
+
parts.push(c < 0n ? "-" : "+", term);
|
|
10632
|
+
}
|
|
10633
|
+
}
|
|
10634
|
+
return parts.length === 0 ? "0" : parts.join(" ");
|
|
10635
|
+
}
|
|
10636
|
+
function renderFactor(poly, v) {
|
|
10637
|
+
if (degree(poly) === 1) return renderLinearFactor(poly, v);
|
|
10638
|
+
return `(${renderIntPoly(poly, v)})`;
|
|
10639
|
+
}
|
|
10640
|
+
function factorPolynomialUnivariate(expr, v) {
|
|
10641
|
+
let dense;
|
|
10642
|
+
try {
|
|
10643
|
+
dense = polyToDense(polyFromExpression(expr, [v]));
|
|
10644
|
+
} catch {
|
|
10645
|
+
return null;
|
|
10646
|
+
}
|
|
10647
|
+
if (dense.length < 2) return null;
|
|
10648
|
+
for (const c of dense) {
|
|
10649
|
+
if (!Number.isFinite(c) || Math.abs(c - Math.round(c)) > INT_TOLERANCE) return null;
|
|
10650
|
+
}
|
|
10651
|
+
const intPoly = dense.map((c) => BigInt(Math.round(c)));
|
|
10652
|
+
const fact = factorUnivariateZ(intPoly);
|
|
10653
|
+
if (fact.factors.length === 1 && fact.factors[0].mult === 1) return null;
|
|
10654
|
+
const parts = [];
|
|
10655
|
+
if (fact.constant !== 1n) parts.push(String(fact.constant));
|
|
10656
|
+
for (const { poly, mult } of fact.factors) {
|
|
10657
|
+
const term = renderFactor(poly, v);
|
|
10658
|
+
for (let i = 0; i < mult; i += 1) parts.push(term);
|
|
10659
|
+
}
|
|
10660
|
+
return parts.join("*");
|
|
10661
|
+
}
|
|
10662
|
+
|
|
9827
10663
|
// src/typed/algebra.ts
|
|
9828
10664
|
var MATH_KEYWORDS = /* @__PURE__ */ new Set([
|
|
9829
10665
|
"sin",
|
|
@@ -10002,7 +10838,7 @@ function polynomialRemainder(a, b) {
|
|
|
10002
10838
|
const [, remainder] = polyDivMod(a, b);
|
|
10003
10839
|
return remainder.length === 0 ? [0] : remainder;
|
|
10004
10840
|
}
|
|
10005
|
-
function
|
|
10841
|
+
function degree2(coeffs) {
|
|
10006
10842
|
const trimmed = trimPoly(coeffs);
|
|
10007
10843
|
if (trimmed.length === 1 && trimmed[0] === 0) return 0;
|
|
10008
10844
|
return trimmed.length - 1;
|
|
@@ -10075,7 +10911,7 @@ function substitute(expr, vars) {
|
|
|
10075
10911
|
function isNearInt(c) {
|
|
10076
10912
|
return Math.abs(c - Math.round(c)) < 1e-7;
|
|
10077
10913
|
}
|
|
10078
|
-
function
|
|
10914
|
+
function polyToDense2(p) {
|
|
10079
10915
|
let maxPow = 0;
|
|
10080
10916
|
for (const t of p) maxPow = Math.max(maxPow, t.powers[0] ?? 0);
|
|
10081
10917
|
const dense = new Array(maxPow + 1).fill(0);
|
|
@@ -10241,11 +11077,11 @@ function tryMonomialDiffOfSquares(poly, vars) {
|
|
|
10241
11077
|
const [t1, t2] = poly;
|
|
10242
11078
|
if (Math.sign(t1.coeff) === Math.sign(t2.coeff)) return null;
|
|
10243
11079
|
const pos = t1.coeff > 0 ? t1 : t2;
|
|
10244
|
-
const
|
|
11080
|
+
const neg2 = t1.coeff > 0 ? t2 : t1;
|
|
10245
11081
|
const cp = perfectIntSqrt(Math.round(pos.coeff));
|
|
10246
|
-
const cn = perfectIntSqrt(Math.round(-
|
|
11082
|
+
const cn = perfectIntSqrt(Math.round(-neg2.coeff));
|
|
10247
11083
|
if (cp === null || cn === null) return null;
|
|
10248
|
-
if (!pos.powers.every((e) => e % 2 === 0) || !
|
|
11084
|
+
if (!pos.powers.every((e) => e % 2 === 0) || !neg2.powers.every((e) => e % 2 === 0)) return null;
|
|
10249
11085
|
const half = (t) => t.powers.map((e) => e / 2);
|
|
10250
11086
|
const term = (c, powers) => {
|
|
10251
11087
|
const mon = monomialString(powers, vars);
|
|
@@ -10253,7 +11089,7 @@ function tryMonomialDiffOfSquares(poly, vars) {
|
|
|
10253
11089
|
return c === 1 ? mon : `${c}*${mon}`;
|
|
10254
11090
|
};
|
|
10255
11091
|
const A = term(cp, half(pos));
|
|
10256
|
-
const B = term(cn, half(
|
|
11092
|
+
const B = term(cn, half(neg2));
|
|
10257
11093
|
return [`(${A} - ${B})`, `(${A} + ${B})`];
|
|
10258
11094
|
}
|
|
10259
11095
|
function factorMultivariate(expr, vars) {
|
|
@@ -10264,9 +11100,9 @@ function factorMultivariate(expr, vars) {
|
|
|
10264
11100
|
return null;
|
|
10265
11101
|
}
|
|
10266
11102
|
if (poly.length < 2 || !poly.every((t) => isNearInt(t.coeff))) return null;
|
|
10267
|
-
let
|
|
10268
|
-
for (const t of poly)
|
|
10269
|
-
if (
|
|
11103
|
+
let content2 = 0;
|
|
11104
|
+
for (const t of poly) content2 = gcdNum(content2, Math.abs(Math.round(t.coeff)));
|
|
11105
|
+
if (content2 === 0) return null;
|
|
10270
11106
|
const nVars = vars.length;
|
|
10271
11107
|
const monPow = new Array(nVars).fill(Infinity);
|
|
10272
11108
|
for (const t of poly)
|
|
@@ -10274,14 +11110,14 @@ function factorMultivariate(expr, vars) {
|
|
|
10274
11110
|
const hasMonomial = monPow.some((e) => e > 0);
|
|
10275
11111
|
const cofactor = normalize(
|
|
10276
11112
|
poly.map((t) => ({
|
|
10277
|
-
coeff: Math.round(t.coeff) /
|
|
11113
|
+
coeff: Math.round(t.coeff) / content2,
|
|
10278
11114
|
powers: t.powers.map((e, i) => e - monPow[i])
|
|
10279
11115
|
}))
|
|
10280
11116
|
);
|
|
10281
11117
|
const dsq = tryMonomialDiffOfSquares(cofactor, vars);
|
|
10282
11118
|
if (!hasMonomial && !dsq) return null;
|
|
10283
11119
|
const parts = [];
|
|
10284
|
-
if (
|
|
11120
|
+
if (content2 > 1) parts.push(String(content2));
|
|
10285
11121
|
if (hasMonomial) parts.push(monomialString(monPow, vars));
|
|
10286
11122
|
if (dsq) parts.push(dsq[0], dsq[1]);
|
|
10287
11123
|
else parts.push(`(${polyToString(cofactor, vars)})`);
|
|
@@ -10296,21 +11132,29 @@ function factor(expr) {
|
|
|
10296
11132
|
if (univariateVars.length === 1) {
|
|
10297
11133
|
try {
|
|
10298
11134
|
const v = univariateVars[0];
|
|
10299
|
-
const dense =
|
|
10300
|
-
if (
|
|
11135
|
+
const dense = polyToDense2(polyFromExpression(expr, [v]));
|
|
11136
|
+
if (degree2(dense) >= 2 && dense.every(isNearInt)) {
|
|
10301
11137
|
const intDense = dense.map((c) => Math.round(c));
|
|
10302
11138
|
const { roots, remainder } = findRationalLinearFactors(intDense);
|
|
10303
11139
|
if (roots.length > 0) {
|
|
10304
11140
|
const factors = roots.map((r) => formatLinearFactor(r, v));
|
|
10305
|
-
if (
|
|
11141
|
+
if (degree2(remainder) >= 2) {
|
|
11142
|
+
const remExpr = cleanUnivariatePoly(remainder, v);
|
|
11143
|
+
const routed2 = factorPolynomialUnivariate(remExpr, v);
|
|
11144
|
+
factors.push(routed2 ?? `(${remExpr})`);
|
|
11145
|
+
} else if (degree2(remainder) >= 1) {
|
|
10306
11146
|
factors.push(`(${polyToString(denseToPoly(remainder), [v])})`);
|
|
10307
11147
|
} else if (remainder[0] !== 1) {
|
|
10308
11148
|
factors.unshift(String(remainder[0]));
|
|
10309
11149
|
}
|
|
10310
11150
|
return factors.join("*");
|
|
10311
11151
|
}
|
|
11152
|
+
const routed = factorPolynomialUnivariate(expr, v);
|
|
11153
|
+
if (routed !== null) return routed;
|
|
10312
11154
|
}
|
|
10313
|
-
} catch {
|
|
11155
|
+
} catch (err) {
|
|
11156
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
11157
|
+
console.warn("factor: univariate engine path failed, falling back: " + message);
|
|
10314
11158
|
}
|
|
10315
11159
|
}
|
|
10316
11160
|
const normalized = expr.replace(/\s*-\s*/g, " + -");
|
|
@@ -10400,13 +11244,13 @@ function cancel(expr) {
|
|
|
10400
11244
|
if (dens.length > 0) {
|
|
10401
11245
|
const numStr = nums.length ? nums.join("*") : "1";
|
|
10402
11246
|
const denStr = dens.join("*");
|
|
10403
|
-
const N2 =
|
|
10404
|
-
const D =
|
|
11247
|
+
const N2 = polyToDense2(polyFromExpression(numStr, [v]));
|
|
11248
|
+
const D = polyToDense2(polyFromExpression(denStr, [v]));
|
|
10405
11249
|
if (N2.every(isNearInt) && D.every(isNearInt)) {
|
|
10406
11250
|
const Nint = N2.map((c) => Math.round(c));
|
|
10407
11251
|
const Dint = D.map((c) => Math.round(c));
|
|
10408
11252
|
const g = polynomialGCD(Nint, Dint);
|
|
10409
|
-
if (
|
|
11253
|
+
if (degree2(g) >= 1) {
|
|
10410
11254
|
let Nq = polynomialQuotient(Nint, g).map((c) => Math.round(c * 1e6) / 1e6);
|
|
10411
11255
|
let Dq = polynomialQuotient(Dint, g).map((c) => Math.round(c * 1e6) / 1e6);
|
|
10412
11256
|
let contentGcd = 0;
|
|
@@ -10419,7 +11263,7 @@ function cancel(expr) {
|
|
|
10419
11263
|
Nq = Nq.map((c) => -c);
|
|
10420
11264
|
Dq = Dq.map((c) => -c);
|
|
10421
11265
|
}
|
|
10422
|
-
if (
|
|
11266
|
+
if (degree2(Dq) === 0) {
|
|
10423
11267
|
const c = Dq[0];
|
|
10424
11268
|
if (c !== 1) Nq = Nq.map((x) => x / c);
|
|
10425
11269
|
return polyToString(denseToPoly(Nq), [v]);
|
|
@@ -10501,23 +11345,23 @@ function apart(expr) {
|
|
|
10501
11345
|
if (dens.length > 0) {
|
|
10502
11346
|
const numStr = nums.length ? nums.join("*") : "1";
|
|
10503
11347
|
const denStr = dens.join("*");
|
|
10504
|
-
const N2 =
|
|
10505
|
-
const D =
|
|
10506
|
-
if (
|
|
11348
|
+
const N2 = polyToDense2(polyFromExpression(numStr, [v]));
|
|
11349
|
+
const D = polyToDense2(polyFromExpression(denStr, [v]));
|
|
11350
|
+
if (degree2(D) >= 1 && N2.every(isNearInt) && D.every(isNearInt)) {
|
|
10507
11351
|
let Nint = N2.map((c) => Math.round(c));
|
|
10508
11352
|
const Dint = D.map((c) => Math.round(c));
|
|
10509
11353
|
let quotientPrefix = "";
|
|
10510
|
-
if (
|
|
11354
|
+
if (degree2(Nint) >= degree2(Dint)) {
|
|
10511
11355
|
const q = polynomialQuotient(Nint, Dint);
|
|
10512
11356
|
const r = polynomialRemainder(Nint, Dint);
|
|
10513
|
-
if (
|
|
11357
|
+
if (degree2(r) === 0 && r[0] === 0) {
|
|
10514
11358
|
return polyToString(denseToPoly(q), [v]);
|
|
10515
11359
|
}
|
|
10516
11360
|
quotientPrefix = `${polyToString(denseToPoly(q), [v])} + `;
|
|
10517
11361
|
Nint = r.map((c) => Math.round(c));
|
|
10518
11362
|
}
|
|
10519
11363
|
const { roots, remainder, repeated } = findRationalLinearFactors(Dint);
|
|
10520
|
-
if (!repeated &&
|
|
11364
|
+
if (!repeated && degree2(remainder) === 0 && roots.length === degree2(Dint)) {
|
|
10521
11365
|
const Dprime = polyder(Dint);
|
|
10522
11366
|
const termStrs = roots.map((root2) => {
|
|
10523
11367
|
const nAtRoot = ratPolyval(Nint, root2);
|
|
@@ -10766,7 +11610,7 @@ var typedAlgebra = {
|
|
|
10766
11610
|
polynomialLCM,
|
|
10767
11611
|
polynomialQuotient,
|
|
10768
11612
|
polynomialRemainder,
|
|
10769
|
-
degree,
|
|
11613
|
+
degree: degree2,
|
|
10770
11614
|
coefficientList,
|
|
10771
11615
|
discriminant,
|
|
10772
11616
|
differences,
|
|
@@ -11420,19 +12264,19 @@ function pchipEndSlope(x0, x1, _x2, _y0, _y1, _y2, d0, d1) {
|
|
|
11420
12264
|
}
|
|
11421
12265
|
return slope;
|
|
11422
12266
|
}
|
|
11423
|
-
function polyFit(xs, ys,
|
|
11424
|
-
if (xs.length !== ys.length || xs.length <
|
|
12267
|
+
function polyFit(xs, ys, degree3) {
|
|
12268
|
+
if (xs.length !== ys.length || xs.length < degree3 + 1) {
|
|
11425
12269
|
throw new Error("polyFit requires more data points than polynomial degree");
|
|
11426
12270
|
}
|
|
11427
12271
|
if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
|
|
11428
12272
|
try {
|
|
11429
|
-
const result = polyFitDispatch(new Float64Array(xs), new Float64Array(ys),
|
|
12273
|
+
const result = polyFitDispatch(new Float64Array(xs), new Float64Array(ys), degree3);
|
|
11430
12274
|
return Array.from(result);
|
|
11431
12275
|
} catch {
|
|
11432
12276
|
}
|
|
11433
12277
|
}
|
|
11434
12278
|
const n = xs.length;
|
|
11435
|
-
const m =
|
|
12279
|
+
const m = degree3 + 1;
|
|
11436
12280
|
const VtV = Array.from({ length: m }, () => new Array(m).fill(0));
|
|
11437
12281
|
const Vty = new Array(m).fill(0);
|
|
11438
12282
|
for (let i = 0; i < n; i++) {
|
|
@@ -11481,19 +12325,19 @@ function polyFit(xs, ys, degree2) {
|
|
|
11481
12325
|
}
|
|
11482
12326
|
return coeffs;
|
|
11483
12327
|
}
|
|
11484
|
-
function chebyshevFit(xs, ys,
|
|
11485
|
-
if (xs.length !== ys.length || xs.length <
|
|
12328
|
+
function chebyshevFit(xs, ys, degree3) {
|
|
12329
|
+
if (xs.length !== ys.length || xs.length < degree3 + 1) {
|
|
11486
12330
|
throw new Error("chebyshevFit requires more data points than polynomial degree");
|
|
11487
12331
|
}
|
|
11488
12332
|
if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
|
|
11489
12333
|
try {
|
|
11490
|
-
const result = chebFitDispatch(new Float64Array(xs), new Float64Array(ys),
|
|
12334
|
+
const result = chebFitDispatch(new Float64Array(xs), new Float64Array(ys), degree3);
|
|
11491
12335
|
return Array.from(result);
|
|
11492
12336
|
} catch {
|
|
11493
12337
|
}
|
|
11494
12338
|
}
|
|
11495
12339
|
const n = xs.length;
|
|
11496
|
-
const k =
|
|
12340
|
+
const k = degree3 + 1;
|
|
11497
12341
|
function chebRow(x) {
|
|
11498
12342
|
const row2 = new Array(k);
|
|
11499
12343
|
let tPrev = 1, tCurr = x;
|
|
@@ -11541,19 +12385,19 @@ function chebyshevFit(xs, ys, degree2) {
|
|
|
11541
12385
|
}
|
|
11542
12386
|
return coeffs;
|
|
11543
12387
|
}
|
|
11544
|
-
function legendreFit(xs, ys,
|
|
11545
|
-
if (xs.length !== ys.length || xs.length <
|
|
12388
|
+
function legendreFit(xs, ys, degree3) {
|
|
12389
|
+
if (xs.length !== ys.length || xs.length < degree3 + 1) {
|
|
11546
12390
|
throw new Error("legendreFit requires more data points than polynomial degree");
|
|
11547
12391
|
}
|
|
11548
12392
|
if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
|
|
11549
12393
|
try {
|
|
11550
|
-
const result = legendreFitDispatch(new Float64Array(xs), new Float64Array(ys),
|
|
12394
|
+
const result = legendreFitDispatch(new Float64Array(xs), new Float64Array(ys), degree3);
|
|
11551
12395
|
return Array.from(result);
|
|
11552
12396
|
} catch {
|
|
11553
12397
|
}
|
|
11554
12398
|
}
|
|
11555
12399
|
const n = xs.length;
|
|
11556
|
-
const k =
|
|
12400
|
+
const k = degree3 + 1;
|
|
11557
12401
|
function legRow(x) {
|
|
11558
12402
|
const row2 = new Array(k);
|
|
11559
12403
|
let pPrev = 1, pCurr = x;
|
|
@@ -12647,7 +13491,7 @@ var createSolveODE = /* @__PURE__ */ factory(
|
|
|
12647
13491
|
dependencies,
|
|
12648
13492
|
({
|
|
12649
13493
|
typed: typed3,
|
|
12650
|
-
add:
|
|
13494
|
+
add: add5,
|
|
12651
13495
|
subtract: subtract3,
|
|
12652
13496
|
multiply: multiply2,
|
|
12653
13497
|
divide: divide2,
|
|
@@ -12866,7 +13710,7 @@ var createSolveODE = /* @__PURE__ */ factory(
|
|
|
12866
13710
|
const m = Math.min(coeffs.length, stages.length);
|
|
12867
13711
|
let acc = multiply2(coeffs[0], stages[0]);
|
|
12868
13712
|
for (let j = 1; j < m; j++) {
|
|
12869
|
-
acc =
|
|
13713
|
+
acc = add5(acc, multiply2(coeffs[j], stages[j]));
|
|
12870
13714
|
}
|
|
12871
13715
|
return acc;
|
|
12872
13716
|
}
|
|
@@ -12879,14 +13723,14 @@ var createSolveODE = /* @__PURE__ */ factory(
|
|
|
12879
13723
|
h = trimStep(t[n], tf, h);
|
|
12880
13724
|
k.push(f(t[n], y[n]));
|
|
12881
13725
|
for (let i = 1; i < c.length; ++i) {
|
|
12882
|
-
k.push(f(
|
|
13726
|
+
k.push(f(add5(t[n], multiply2(c[i], h)), add5(y[n], multiply2(h, stageCombo(a[i], k)))));
|
|
12883
13727
|
}
|
|
12884
13728
|
const errComb = stageCombo(deltaB, k);
|
|
12885
13729
|
const errArr = Array.isArray(errComb) ? errComb : [errComb];
|
|
12886
13730
|
const TE = max2(abs2(map3(errArr, (X) => isUnit(X) ? X.value : X)));
|
|
12887
13731
|
if (TE < tol && tol / TE > 1 / 4) {
|
|
12888
|
-
t.push(
|
|
12889
|
-
y.push(
|
|
13732
|
+
t.push(add5(t[n], h));
|
|
13733
|
+
y.push(add5(y[n], multiply2(h, stageCombo(b, k))));
|
|
12890
13734
|
n++;
|
|
12891
13735
|
}
|
|
12892
13736
|
let delta = 0.84 * (tol / TE) ** (1 / 5);
|
|
@@ -12980,7 +13824,7 @@ var createSolveODE = /* @__PURE__ */ factory(
|
|
|
12980
13824
|
function _createTrimStep(isForwards) {
|
|
12981
13825
|
const outOfBounds = isForwards ? larger2 : smaller2;
|
|
12982
13826
|
return function(t, tf, h) {
|
|
12983
|
-
const next =
|
|
13827
|
+
const next = add5(t, h);
|
|
12984
13828
|
return outOfBounds(next, tf) ? subtract3(tf, t) : h;
|
|
12985
13829
|
};
|
|
12986
13830
|
}
|
|
@@ -14065,9 +14909,9 @@ function bezierCurve(controlPoints, t) {
|
|
|
14065
14909
|
}
|
|
14066
14910
|
return points[0];
|
|
14067
14911
|
}
|
|
14068
|
-
function bspline(controlPoints,
|
|
14912
|
+
function bspline(controlPoints, degree3, t) {
|
|
14069
14913
|
const n = controlPoints.length;
|
|
14070
|
-
const p =
|
|
14914
|
+
const p = degree3;
|
|
14071
14915
|
if (n <= p) throw new Error("bspline: need more control points than degree");
|
|
14072
14916
|
const m = n + p + 1;
|
|
14073
14917
|
const knots = new Array(m);
|
|
@@ -14811,8 +15655,8 @@ function residue(p, q) {
|
|
|
14811
15655
|
function polyRoots(coeffs) {
|
|
14812
15656
|
const n = coeffs.length - 1;
|
|
14813
15657
|
if (n <= 0) return [];
|
|
14814
|
-
const
|
|
14815
|
-
const c = coeffs.map((v) => v /
|
|
15658
|
+
const lc2 = coeffs[n];
|
|
15659
|
+
const c = coeffs.map((v) => v / lc2);
|
|
14816
15660
|
const roots = [];
|
|
14817
15661
|
for (let i = 0; i < n; i++) {
|
|
14818
15662
|
const angle = 2 * Math.PI * i / n + 0.4;
|
|
@@ -19704,7 +20548,7 @@ function combinationsExact(n, k) {
|
|
|
19704
20548
|
var bernoulli = mathTyped16("bernoulli", {
|
|
19705
20549
|
number: (n) => bernoulliNumber(n)
|
|
19706
20550
|
});
|
|
19707
|
-
var
|
|
20551
|
+
var combinations2 = mathTyped16("combinations", {
|
|
19708
20552
|
"number, number": (n, k) => combinationsExact(n, k)
|
|
19709
20553
|
});
|
|
19710
20554
|
var combinationsWithRep = mathTyped16("combinationsWithRep", {
|
|
@@ -19834,7 +20678,7 @@ function _pick(arr10, n, weights) {
|
|
|
19834
20678
|
}
|
|
19835
20679
|
var typedProbability = {
|
|
19836
20680
|
bernoulli,
|
|
19837
|
-
combinations,
|
|
20681
|
+
combinations: combinations2,
|
|
19838
20682
|
combinationsWithRep,
|
|
19839
20683
|
multinomial,
|
|
19840
20684
|
permutations,
|
|
@@ -20090,7 +20934,7 @@ __export(factories_exports, {
|
|
|
20090
20934
|
csch: () => csch,
|
|
20091
20935
|
ctranspose: () => ctranspose,
|
|
20092
20936
|
cumsum: () => cumsum,
|
|
20093
|
-
derivative: () =>
|
|
20937
|
+
derivative: () => derivative2,
|
|
20094
20938
|
det: () => det,
|
|
20095
20939
|
deuteronMass: () => deuteronMass,
|
|
20096
20940
|
diag: () => diag,
|
|
@@ -20204,8 +21048,8 @@ __export(factories_exports, {
|
|
|
20204
21048
|
isNegative: () => isNegative,
|
|
20205
21049
|
isNumeric: () => isNumeric,
|
|
20206
21050
|
isPositive: () => isPositive,
|
|
20207
|
-
isPrime: () =>
|
|
20208
|
-
isZero: () =>
|
|
21051
|
+
isPrime: () => isPrime2,
|
|
21052
|
+
isZero: () => isZero2,
|
|
20209
21053
|
josephson: () => josephson,
|
|
20210
21054
|
kldivergence: () => kldivergence,
|
|
20211
21055
|
klitzing: () => klitzing,
|
|
@@ -23126,41 +23970,41 @@ var createDot = /* @__PURE__ */ factory(
|
|
|
23126
23970
|
const bdt = isMatrix(b) ? b._datatype || b.getDataType() : void 0;
|
|
23127
23971
|
const aIsColumn = _size(a).length === 2;
|
|
23128
23972
|
const bIsColumn = _size(b).length === 2;
|
|
23129
|
-
let
|
|
23130
|
-
let
|
|
23973
|
+
let add5 = addScalar2;
|
|
23974
|
+
let mul2 = multiplyScalar2;
|
|
23131
23975
|
if (adt && bdt && adt === bdt && typeof adt === "string" && adt !== "mixed") {
|
|
23132
23976
|
const dt = adt;
|
|
23133
|
-
|
|
23134
|
-
|
|
23977
|
+
add5 = typed3.find(addScalar2, [dt, dt]);
|
|
23978
|
+
mul2 = typed3.find(multiplyScalar2, [dt, dt]);
|
|
23135
23979
|
}
|
|
23136
|
-
if (!aIsColumn && !bIsColumn &&
|
|
23980
|
+
if (!aIsColumn && !bIsColumn && add5 === addScalar2 && mul2 === multiplyScalar2 && _isFlatNumbers(adata) && _isFlatNumbers(bdata)) {
|
|
23137
23981
|
return pairwiseDot2(adata, bdata);
|
|
23138
23982
|
}
|
|
23139
23983
|
if (!aIsColumn && !bIsColumn) {
|
|
23140
|
-
let c =
|
|
23984
|
+
let c = mul2(conj3(adata[0]), bdata[0]);
|
|
23141
23985
|
for (let i = 1; i < N2; i++) {
|
|
23142
|
-
c =
|
|
23986
|
+
c = add5(c, mul2(conj3(adata[i]), bdata[i]));
|
|
23143
23987
|
}
|
|
23144
23988
|
return c;
|
|
23145
23989
|
}
|
|
23146
23990
|
if (!aIsColumn && bIsColumn) {
|
|
23147
|
-
let c =
|
|
23991
|
+
let c = mul2(conj3(adata[0]), bdata[0][0]);
|
|
23148
23992
|
for (let i = 1; i < N2; i++) {
|
|
23149
|
-
c =
|
|
23993
|
+
c = add5(c, mul2(conj3(adata[i]), bdata[i][0]));
|
|
23150
23994
|
}
|
|
23151
23995
|
return c;
|
|
23152
23996
|
}
|
|
23153
23997
|
if (aIsColumn && !bIsColumn) {
|
|
23154
|
-
let c =
|
|
23998
|
+
let c = mul2(conj3(adata[0][0]), bdata[0]);
|
|
23155
23999
|
for (let i = 1; i < N2; i++) {
|
|
23156
|
-
c =
|
|
24000
|
+
c = add5(c, mul2(conj3(adata[i][0]), bdata[i]));
|
|
23157
24001
|
}
|
|
23158
24002
|
return c;
|
|
23159
24003
|
}
|
|
23160
24004
|
{
|
|
23161
|
-
let c =
|
|
24005
|
+
let c = mul2(conj3(adata[0][0]), bdata[0][0]);
|
|
23162
24006
|
for (let i = 1; i < N2; i++) {
|
|
23163
|
-
c =
|
|
24007
|
+
c = add5(c, mul2(conj3(adata[i][0]), bdata[i][0]));
|
|
23164
24008
|
}
|
|
23165
24009
|
return c;
|
|
23166
24010
|
}
|
|
@@ -23172,8 +24016,8 @@ var createDot = /* @__PURE__ */ factory(
|
|
|
23172
24016
|
const yindex = y._index;
|
|
23173
24017
|
const yvalues = y._values;
|
|
23174
24018
|
let c = 0;
|
|
23175
|
-
const
|
|
23176
|
-
const
|
|
24019
|
+
const add5 = addScalar2;
|
|
24020
|
+
const mul2 = multiplyScalar2;
|
|
23177
24021
|
let i = 0;
|
|
23178
24022
|
let j = 0;
|
|
23179
24023
|
while (i < xindex.length && j < yindex.length) {
|
|
@@ -23188,7 +24032,7 @@ var createDot = /* @__PURE__ */ factory(
|
|
|
23188
24032
|
continue;
|
|
23189
24033
|
}
|
|
23190
24034
|
if (I2 === J) {
|
|
23191
|
-
c =
|
|
24035
|
+
c = add5(c, mul2(xvalues[i], yvalues[j]));
|
|
23192
24036
|
i++;
|
|
23193
24037
|
j++;
|
|
23194
24038
|
}
|
|
@@ -24084,7 +24928,7 @@ var createMatrixFromFunction = /* @__PURE__ */ factory(
|
|
|
24084
24928
|
({
|
|
24085
24929
|
typed: typed3,
|
|
24086
24930
|
matrix: matrix2,
|
|
24087
|
-
isZero:
|
|
24931
|
+
isZero: isZero3
|
|
24088
24932
|
}) => {
|
|
24089
24933
|
return typed3(name91, {
|
|
24090
24934
|
"Array | Matrix, function, string, string": function(size2, fn, format4, datatype) {
|
|
@@ -24116,7 +24960,7 @@ var createMatrixFromFunction = /* @__PURE__ */ factory(
|
|
|
24116
24960
|
m.resize(size2);
|
|
24117
24961
|
m.forEach(function(_, index) {
|
|
24118
24962
|
const val = fn(index);
|
|
24119
|
-
if (
|
|
24963
|
+
if (isZero3(val)) return;
|
|
24120
24964
|
m.set(index, val);
|
|
24121
24965
|
});
|
|
24122
24966
|
return m;
|
|
@@ -24280,7 +25124,7 @@ var dependencies95 = ["typed", "matrix", "add"];
|
|
|
24280
25124
|
var createTrace = /* @__PURE__ */ factory(
|
|
24281
25125
|
name95,
|
|
24282
25126
|
dependencies95,
|
|
24283
|
-
({ typed: typed3, matrix: matrix2, add:
|
|
25127
|
+
({ typed: typed3, matrix: matrix2, add: add5 }) => {
|
|
24284
25128
|
return typed3("trace", {
|
|
24285
25129
|
Array: function _arrayTrace(x) {
|
|
24286
25130
|
return _denseTrace(matrix2(x));
|
|
@@ -24304,7 +25148,7 @@ var createTrace = /* @__PURE__ */ factory(
|
|
|
24304
25148
|
if (rows === cols) {
|
|
24305
25149
|
let sum3 = 0;
|
|
24306
25150
|
for (let i = 0; i < rows; i++) {
|
|
24307
|
-
sum3 =
|
|
25151
|
+
sum3 = add5(sum3, data[i][i]);
|
|
24308
25152
|
}
|
|
24309
25153
|
return sum3;
|
|
24310
25154
|
} else {
|
|
@@ -24331,7 +25175,7 @@ var createTrace = /* @__PURE__ */ factory(
|
|
|
24331
25175
|
for (let k = k0; k < k1; k++) {
|
|
24332
25176
|
const i = index[k];
|
|
24333
25177
|
if (i === j) {
|
|
24334
|
-
sum3 =
|
|
25178
|
+
sum3 = add5(sum3, values[k]);
|
|
24335
25179
|
break;
|
|
24336
25180
|
}
|
|
24337
25181
|
if (i > j) {
|
|
@@ -24382,7 +25226,7 @@ var dependencies96 = [
|
|
|
24382
25226
|
var createDet = /* @__PURE__ */ factory(
|
|
24383
25227
|
name96,
|
|
24384
25228
|
dependencies96,
|
|
24385
|
-
({ typed: typed3, matrix: matrix2, subtractScalar: subtractScalar2, multiply: multiply2, divideScalar: divideScalar2, isZero:
|
|
25229
|
+
({ typed: typed3, matrix: matrix2, subtractScalar: subtractScalar2, multiply: multiply2, divideScalar: divideScalar2, isZero: isZero3, unaryMinus: unaryMinus2 }) => {
|
|
24386
25230
|
return typed3(name96, {
|
|
24387
25231
|
any: function(x) {
|
|
24388
25232
|
return clone(x);
|
|
@@ -24477,10 +25321,10 @@ var createDet = /* @__PURE__ */ factory(
|
|
|
24477
25321
|
}
|
|
24478
25322
|
for (let k = 0; k < rows; k++) {
|
|
24479
25323
|
let k_ = rowIndices[k];
|
|
24480
|
-
if (
|
|
25324
|
+
if (isZero3(matrix3[k_][k])) {
|
|
24481
25325
|
let _k;
|
|
24482
25326
|
for (_k = k + 1; _k < rows; _k++) {
|
|
24483
|
-
if (!
|
|
25327
|
+
if (!isZero3(matrix3[rowIndices[_k]][k])) {
|
|
24484
25328
|
k_ = rowIndices[_k];
|
|
24485
25329
|
rowIndices[_k] = rowIndices[k];
|
|
24486
25330
|
rowIndices[k] = k_;
|
|
@@ -24698,7 +25542,7 @@ var dependencies98 = ["add", "multiply", "transpose"];
|
|
|
24698
25542
|
var createCsAmd = /* @__PURE__ */ factory(
|
|
24699
25543
|
name98,
|
|
24700
25544
|
dependencies98,
|
|
24701
|
-
({ add:
|
|
25545
|
+
({ add: add5, multiply: multiply2, transpose: transpose5 }) => {
|
|
24702
25546
|
function _tryWasmAmd(a, n) {
|
|
24703
25547
|
const wasm = wasmLoader.getModule();
|
|
24704
25548
|
if (!wasm || !a._ptr || !a._index) return null;
|
|
@@ -24752,7 +25596,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24752
25596
|
const next = 2 * (n + 1);
|
|
24753
25597
|
const head = 3 * (n + 1);
|
|
24754
25598
|
const elen = 4 * (n + 1);
|
|
24755
|
-
const
|
|
25599
|
+
const degree3 = 5 * (n + 1);
|
|
24756
25600
|
const w = 6 * (n + 1);
|
|
24757
25601
|
const hhead = 7 * (n + 1);
|
|
24758
25602
|
const last2 = P2;
|
|
@@ -24768,9 +25612,9 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24768
25612
|
nv,
|
|
24769
25613
|
w,
|
|
24770
25614
|
elen,
|
|
24771
|
-
|
|
25615
|
+
degree3
|
|
24772
25616
|
);
|
|
24773
|
-
let nel = _initializeDegreeLists(n, cptr, W,
|
|
25617
|
+
let nel = _initializeDegreeLists(n, cptr, W, degree3, elen, w, dense, nv, head, last2, next);
|
|
24774
25618
|
let mindeg = 0;
|
|
24775
25619
|
let i, j, k, k1, k2, e, pj, ln, nvi, pk, eln, p1, p2, pn, h, d;
|
|
24776
25620
|
while (nel < n) {
|
|
@@ -24811,7 +25655,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24811
25655
|
if (last2[i] !== -1) {
|
|
24812
25656
|
W[next + last2[i]] = W[next + i];
|
|
24813
25657
|
} else {
|
|
24814
|
-
W[head + W[
|
|
25658
|
+
W[head + W[degree3 + i]] = W[next + i];
|
|
24815
25659
|
}
|
|
24816
25660
|
}
|
|
24817
25661
|
if (e !== k) {
|
|
@@ -24822,7 +25666,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24822
25666
|
if (elenk !== 0) {
|
|
24823
25667
|
cnz = pk2;
|
|
24824
25668
|
}
|
|
24825
|
-
W[
|
|
25669
|
+
W[degree3 + k] = dk;
|
|
24826
25670
|
cptr[k] = pk1;
|
|
24827
25671
|
W[len + k] = pk2 - pk1;
|
|
24828
25672
|
W[elen + k] = -2;
|
|
@@ -24839,7 +25683,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24839
25683
|
if (W[w + e] >= mark) {
|
|
24840
25684
|
W[w + e] -= nvi;
|
|
24841
25685
|
} else if (W[w + e] !== 0) {
|
|
24842
|
-
W[w + e] = W[
|
|
25686
|
+
W[w + e] = W[degree3 + e] + wnvi;
|
|
24843
25687
|
}
|
|
24844
25688
|
}
|
|
24845
25689
|
}
|
|
@@ -24884,7 +25728,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24884
25728
|
W[nv + i] = 0;
|
|
24885
25729
|
W[elen + i] = -1;
|
|
24886
25730
|
} else {
|
|
24887
|
-
W[
|
|
25731
|
+
W[degree3 + i] = Math.min(W[degree3 + i], d);
|
|
24888
25732
|
cindex[pn] = cindex[p3];
|
|
24889
25733
|
cindex[p3] = cindex[p1];
|
|
24890
25734
|
cindex[p1] = k;
|
|
@@ -24895,7 +25739,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24895
25739
|
last2[i] = h;
|
|
24896
25740
|
}
|
|
24897
25741
|
}
|
|
24898
|
-
W[
|
|
25742
|
+
W[degree3 + k] = dk;
|
|
24899
25743
|
lemax = Math.max(lemax, dk);
|
|
24900
25744
|
mark = _wclear(mark + lemax, lemax, W, w, n);
|
|
24901
25745
|
for (pk = pk1; pk < pk2; pk++) {
|
|
@@ -24940,7 +25784,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24940
25784
|
continue;
|
|
24941
25785
|
}
|
|
24942
25786
|
W[nv + i] = nvi;
|
|
24943
|
-
d = W[
|
|
25787
|
+
d = W[degree3 + i] + dk - nvi;
|
|
24944
25788
|
d = Math.min(d, n - nel - nvi);
|
|
24945
25789
|
if (W[head + d] !== -1) {
|
|
24946
25790
|
last2[W[head + d]] = i;
|
|
@@ -24949,7 +25793,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24949
25793
|
last2[i] = -1;
|
|
24950
25794
|
W[head + d] = i;
|
|
24951
25795
|
mindeg = Math.min(mindeg, d);
|
|
24952
|
-
W[
|
|
25796
|
+
W[degree3 + i] = d;
|
|
24953
25797
|
cindex[p++] = i;
|
|
24954
25798
|
}
|
|
24955
25799
|
W[nv + k] = nvk;
|
|
@@ -24994,7 +25838,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
24994
25838
|
function _createTargetMatrix(order, a, m, n, dense) {
|
|
24995
25839
|
const at = transpose5(a);
|
|
24996
25840
|
if (order === 1 && n === m) {
|
|
24997
|
-
return
|
|
25841
|
+
return add5(a, at);
|
|
24998
25842
|
}
|
|
24999
25843
|
if (order === 2) {
|
|
25000
25844
|
const tindex = at._index;
|
|
@@ -25016,7 +25860,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
25016
25860
|
}
|
|
25017
25861
|
return multiply2(at, a);
|
|
25018
25862
|
}
|
|
25019
|
-
function _initializeQuotientGraph(n, cptr, W, len, head, last2, next, hhead, nv, w, elen,
|
|
25863
|
+
function _initializeQuotientGraph(n, cptr, W, len, head, last2, next, hhead, nv, w, elen, degree3) {
|
|
25020
25864
|
for (let k = 0; k < n; k++) {
|
|
25021
25865
|
W[len + k] = cptr[k + 1] - cptr[k];
|
|
25022
25866
|
}
|
|
@@ -25029,7 +25873,7 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
25029
25873
|
W[nv + i] = 1;
|
|
25030
25874
|
W[w + i] = 1;
|
|
25031
25875
|
W[elen + i] = 0;
|
|
25032
|
-
W[
|
|
25876
|
+
W[degree3 + i] = W[len + i];
|
|
25033
25877
|
}
|
|
25034
25878
|
const mark = _wclear(0, 0, W, w, n);
|
|
25035
25879
|
W[elen + n] = -2;
|
|
@@ -25037,10 +25881,10 @@ var createCsAmd = /* @__PURE__ */ factory(
|
|
|
25037
25881
|
W[w + n] = 0;
|
|
25038
25882
|
return mark;
|
|
25039
25883
|
}
|
|
25040
|
-
function _initializeDegreeLists(n, cptr, W,
|
|
25884
|
+
function _initializeDegreeLists(n, cptr, W, degree3, elen, w, dense, nv, head, last2, next) {
|
|
25041
25885
|
let nel = 0;
|
|
25042
25886
|
for (let i = 0; i < n; i++) {
|
|
25043
|
-
const d = W[
|
|
25887
|
+
const d = W[degree3 + i];
|
|
25044
25888
|
if (d === 0) {
|
|
25045
25889
|
W[elen + i] = -2;
|
|
25046
25890
|
nel++;
|
|
@@ -25343,8 +26187,8 @@ var dependencies100 = ["add", "multiply", "transpose"];
|
|
|
25343
26187
|
var createCsSqr = /* @__PURE__ */ factory(
|
|
25344
26188
|
name100,
|
|
25345
26189
|
dependencies100,
|
|
25346
|
-
({ add:
|
|
25347
|
-
const csAmd2 = createCsAmd({ add:
|
|
26190
|
+
({ add: add5, multiply: multiply2, transpose: transpose5 }) => {
|
|
26191
|
+
const csAmd2 = createCsAmd({ add: add5, multiply: multiply2, transpose: transpose5 });
|
|
25348
26192
|
const csCounts2 = createCsCounts({ transpose: transpose5 });
|
|
25349
26193
|
return function csSqr2(order, a, qr2) {
|
|
25350
26194
|
const aptr = a._ptr;
|
|
@@ -26860,7 +27704,7 @@ var createCatalan = /* @__PURE__ */ factory(
|
|
|
26860
27704
|
addScalar: addScalar2,
|
|
26861
27705
|
divideScalar: divideScalar2,
|
|
26862
27706
|
multiplyScalar: multiplyScalar2,
|
|
26863
|
-
combinations:
|
|
27707
|
+
combinations: combinations4,
|
|
26864
27708
|
isNegative: isNegative2,
|
|
26865
27709
|
isInteger: isInteger3
|
|
26866
27710
|
}) => {
|
|
@@ -26869,7 +27713,7 @@ var createCatalan = /* @__PURE__ */ factory(
|
|
|
26869
27713
|
if (!isInteger3(n) || isNegative2(n)) {
|
|
26870
27714
|
throw new TypeError("Non-negative integer value expected in function catalan");
|
|
26871
27715
|
}
|
|
26872
|
-
return divideScalar2(
|
|
27716
|
+
return divideScalar2(combinations4(multiplyScalar2(n, 2), n), addScalar2(n, 1));
|
|
26873
27717
|
}
|
|
26874
27718
|
});
|
|
26875
27719
|
}
|
|
@@ -27356,7 +28200,7 @@ var createSubset = /* @__PURE__ */ factory(
|
|
|
27356
28200
|
typed: typed3,
|
|
27357
28201
|
matrix: matrix2,
|
|
27358
28202
|
zeros: zeros4,
|
|
27359
|
-
add:
|
|
28203
|
+
add: add5
|
|
27360
28204
|
}) => {
|
|
27361
28205
|
const referTo = typed3.referTo;
|
|
27362
28206
|
return typed3(name119, {
|
|
@@ -27415,7 +28259,7 @@ var createSubset = /* @__PURE__ */ factory(
|
|
|
27415
28259
|
const indexSize = index.size();
|
|
27416
28260
|
if (indexSize.every((d) => d > 0)) {
|
|
27417
28261
|
try {
|
|
27418
|
-
return
|
|
28262
|
+
return add5(replacement, zeros4(indexSize));
|
|
27419
28263
|
} catch {
|
|
27420
28264
|
return replacement;
|
|
27421
28265
|
}
|
|
@@ -28088,7 +28932,7 @@ var dependencies127 = ["typed", "add", "multiply", "Complex", "number"];
|
|
|
28088
28932
|
var createZpk2tf = /* @__PURE__ */ factory(
|
|
28089
28933
|
name127,
|
|
28090
28934
|
dependencies127,
|
|
28091
|
-
({ typed: typed3, add:
|
|
28935
|
+
({ typed: typed3, add: add5, multiply: multiply2, Complex: Complex13, number: number2 }) => {
|
|
28092
28936
|
return typed3(name127, {
|
|
28093
28937
|
"Array,Array,number": function(z, p, k) {
|
|
28094
28938
|
return _zpk2tf(z, p, k);
|
|
@@ -28133,7 +28977,7 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
28133
28977
|
c[i] = Complex13(0, 0);
|
|
28134
28978
|
for (let j = 0; j < a.length; j++) {
|
|
28135
28979
|
if (i - j >= 0 && i - j < b.length) {
|
|
28136
|
-
c[i] =
|
|
28980
|
+
c[i] = add5(c[i], multiply2(a[j], b[i - j]));
|
|
28137
28981
|
}
|
|
28138
28982
|
}
|
|
28139
28983
|
}
|
|
@@ -28160,7 +29004,7 @@ var dependencies128 = ["typed", "add", "unaryPlus"];
|
|
|
28160
29004
|
var createCumSum = /* @__PURE__ */ factory(
|
|
28161
29005
|
name128,
|
|
28162
29006
|
dependencies128,
|
|
28163
|
-
({ typed: typed3, add:
|
|
29007
|
+
({ typed: typed3, add: add5, unaryPlus: unaryPlus2 }) => {
|
|
28164
29008
|
return typed3(name128, {
|
|
28165
29009
|
// sum([a, b, c, d, ...])
|
|
28166
29010
|
Array: _cumsum,
|
|
@@ -28201,7 +29045,7 @@ var createCumSum = /* @__PURE__ */ factory(
|
|
|
28201
29045
|
}
|
|
28202
29046
|
const sums = [unaryPlus2(array[0])];
|
|
28203
29047
|
for (let i = 1; i < array.length; ++i) {
|
|
28204
|
-
sums.push(
|
|
29048
|
+
sums.push(add5(sums[i - 1], array[i]));
|
|
28205
29049
|
}
|
|
28206
29050
|
return sums;
|
|
28207
29051
|
}
|
|
@@ -28259,7 +29103,7 @@ var dependencies129 = ["typed", "config", "add", "numeric", "parseNumberWithConf
|
|
|
28259
29103
|
var createSum = /* @__PURE__ */ factory(
|
|
28260
29104
|
name129,
|
|
28261
29105
|
dependencies129,
|
|
28262
|
-
({ typed: typed3, config: config2, add:
|
|
29106
|
+
({ typed: typed3, config: config2, add: add5, numeric: numeric2, parseNumberWithConfig: parseNumberWithConfig2 }) => {
|
|
28263
29107
|
return typed3(name129, {
|
|
28264
29108
|
// sum(string) - single string input
|
|
28265
29109
|
string: function(x) {
|
|
@@ -28285,7 +29129,7 @@ var createSum = /* @__PURE__ */ factory(
|
|
|
28285
29129
|
deepForEach(array, function(value) {
|
|
28286
29130
|
try {
|
|
28287
29131
|
const converted = typeof value === "string" ? parseNumberWithConfig2(value) : value;
|
|
28288
|
-
sum3 = sum3 === void 0 ? converted :
|
|
29132
|
+
sum3 = sum3 === void 0 ? converted : add5(sum3, converted);
|
|
28289
29133
|
} catch (err) {
|
|
28290
29134
|
throw improveErrorMessage(err, "sum", value);
|
|
28291
29135
|
}
|
|
@@ -28298,7 +29142,7 @@ var createSum = /* @__PURE__ */ factory(
|
|
|
28298
29142
|
function _nsumDim(array, dim) {
|
|
28299
29143
|
try {
|
|
28300
29144
|
const dimValue = typeof dim === "number" ? dim : dim.valueOf();
|
|
28301
|
-
const sum3 = reduce2(array, dimValue,
|
|
29145
|
+
const sum3 = reduce2(array, dimValue, add5);
|
|
28302
29146
|
return sum3;
|
|
28303
29147
|
} catch (err) {
|
|
28304
29148
|
throw improveErrorMessage(err, "sum", void 0);
|
|
@@ -29349,7 +30193,7 @@ var dependencies143 = ["typed", "config", "divideScalar", "log", "Complex"];
|
|
|
29349
30193
|
var createLog1p = /* @__PURE__ */ factory(
|
|
29350
30194
|
name143,
|
|
29351
30195
|
dependencies143,
|
|
29352
|
-
({ typed: typed3, config: config2, divideScalar: divideScalar2, log:
|
|
30196
|
+
({ typed: typed3, config: config2, divideScalar: divideScalar2, log: log4, Complex: Complex13 }) => {
|
|
29353
30197
|
return typed3(name143, {
|
|
29354
30198
|
number: function(x) {
|
|
29355
30199
|
if (x >= -1 || config2.predictable) {
|
|
@@ -29372,7 +30216,7 @@ var createLog1p = /* @__PURE__ */ factory(
|
|
|
29372
30216
|
),
|
|
29373
30217
|
"any, any": typed3.referToSelf(
|
|
29374
30218
|
(self) => (x, base) => {
|
|
29375
|
-
return divideScalar2(self(x),
|
|
30219
|
+
return divideScalar2(self(x), log4(base));
|
|
29376
30220
|
}
|
|
29377
30221
|
)
|
|
29378
30222
|
});
|
|
@@ -30960,7 +31804,7 @@ var createInvmod = /* @__PURE__ */ factory(
|
|
|
30960
31804
|
equal: equal2,
|
|
30961
31805
|
smaller: smaller2,
|
|
30962
31806
|
mod: mod3,
|
|
30963
|
-
add:
|
|
31807
|
+
add: add5,
|
|
30964
31808
|
isInteger: isInteger3
|
|
30965
31809
|
}) => {
|
|
30966
31810
|
return typed3(name168, {
|
|
@@ -30977,7 +31821,7 @@ var createInvmod = /* @__PURE__ */ factory(
|
|
|
30977
31821
|
const [gcd2, invValue] = resVal;
|
|
30978
31822
|
if (!equal2(gcd2, 1)) return NaN;
|
|
30979
31823
|
let inv3 = mod3(invValue, b);
|
|
30980
|
-
if (smaller2(inv3, 0)) inv3 =
|
|
31824
|
+
if (smaller2(inv3, 0)) inv3 = add5(inv3, b);
|
|
30981
31825
|
return inv3;
|
|
30982
31826
|
}
|
|
30983
31827
|
}
|
|
@@ -31081,7 +31925,7 @@ var createComposition = /* @__PURE__ */ factory(
|
|
|
31081
31925
|
({
|
|
31082
31926
|
typed: typed3,
|
|
31083
31927
|
addScalar: addScalar2,
|
|
31084
|
-
combinations:
|
|
31928
|
+
combinations: combinations4,
|
|
31085
31929
|
isPositive: isPositive2,
|
|
31086
31930
|
isNegative: _isNegative,
|
|
31087
31931
|
isInteger: isInteger3,
|
|
@@ -31094,7 +31938,7 @@ var createComposition = /* @__PURE__ */ factory(
|
|
|
31094
31938
|
} else if (larger2(k, n)) {
|
|
31095
31939
|
throw new TypeError("k must be less than or equal to n in function composition");
|
|
31096
31940
|
}
|
|
31097
|
-
return
|
|
31941
|
+
return combinations4(addScalar2(n, -1), addScalar2(k, -1));
|
|
31098
31942
|
}
|
|
31099
31943
|
});
|
|
31100
31944
|
}
|
|
@@ -31238,7 +32082,7 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
31238
32082
|
ctranspose: ctranspose2,
|
|
31239
32083
|
divideScalar: divideScalar2,
|
|
31240
32084
|
multiply: multiply2,
|
|
31241
|
-
add:
|
|
32085
|
+
add: add5,
|
|
31242
32086
|
Complex: Complex13
|
|
31243
32087
|
}) => {
|
|
31244
32088
|
return typed3(name172, {
|
|
@@ -31320,7 +32164,7 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
31320
32164
|
if (i2 === r) continue;
|
|
31321
32165
|
val = M[i2][lead];
|
|
31322
32166
|
for (let j = 0; j < cols; j++) {
|
|
31323
|
-
M[i2][j] =
|
|
32167
|
+
M[i2][j] = add5(M[i2][j], multiply2(-1, multiply2(val, M[r][j])));
|
|
31324
32168
|
}
|
|
31325
32169
|
}
|
|
31326
32170
|
lead++;
|
|
@@ -31334,12 +32178,12 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
31334
32178
|
return { C, F };
|
|
31335
32179
|
}
|
|
31336
32180
|
function _isZero(x) {
|
|
31337
|
-
return equal2(
|
|
32181
|
+
return equal2(add5(x, Complex13(1, 1)), add5(0, Complex13(1, 1)));
|
|
31338
32182
|
}
|
|
31339
32183
|
function _isZeros(arr10) {
|
|
31340
32184
|
return deepEqual3(
|
|
31341
|
-
|
|
31342
|
-
|
|
32185
|
+
add5(arr10, Complex13(1, 1)),
|
|
32186
|
+
add5(multiply2(arr10, 0), Complex13(1, 1))
|
|
31343
32187
|
);
|
|
31344
32188
|
}
|
|
31345
32189
|
}
|
|
@@ -31393,7 +32237,7 @@ var createQr = /* @__PURE__ */ factory(
|
|
|
31393
32237
|
matrix: matrix2,
|
|
31394
32238
|
zeros: zeros4,
|
|
31395
32239
|
identity: identity2,
|
|
31396
|
-
isZero:
|
|
32240
|
+
isZero: isZero3,
|
|
31397
32241
|
equal: equal2,
|
|
31398
32242
|
sign: sign3,
|
|
31399
32243
|
sqrt: sqrt2,
|
|
@@ -31479,7 +32323,7 @@ var createQr = /* @__PURE__ */ factory(
|
|
|
31479
32323
|
alphaSquared = addScalar2(alphaSquared, multiplyScalar2(Rdata[i][k], conj3(Rdata[i][k])));
|
|
31480
32324
|
}
|
|
31481
32325
|
const alpha = multiplyScalar2(sgn, sqrt2(alphaSquared));
|
|
31482
|
-
if (!
|
|
32326
|
+
if (!isZero3(alpha)) {
|
|
31483
32327
|
const u1 = subtractScalar2(pivot, alpha);
|
|
31484
32328
|
w[k] = 1;
|
|
31485
32329
|
for (i = k + 1; i < rows; i++) {
|
|
@@ -31570,8 +32414,8 @@ var createRange = /* @__PURE__ */ factory(
|
|
|
31570
32414
|
smallerEq: smallerEq2,
|
|
31571
32415
|
larger: larger2,
|
|
31572
32416
|
largerEq: largerEq2,
|
|
31573
|
-
add:
|
|
31574
|
-
isZero:
|
|
32417
|
+
add: add5,
|
|
32418
|
+
isZero: isZero3,
|
|
31575
32419
|
isPositive: isPositive2
|
|
31576
32420
|
}) => {
|
|
31577
32421
|
return typed3(name174, {
|
|
@@ -31678,12 +32522,12 @@ var createRange = /* @__PURE__ */ factory(
|
|
|
31678
32522
|
}
|
|
31679
32523
|
function _range(start, end, step, includeEnd) {
|
|
31680
32524
|
const array = [];
|
|
31681
|
-
if (
|
|
32525
|
+
if (isZero3(step)) throw new Error("Step must be non-zero");
|
|
31682
32526
|
const ongoing = isPositive2(step) ? includeEnd ? smallerEq2 : smaller2 : includeEnd ? largerEq2 : larger2;
|
|
31683
32527
|
let x = start;
|
|
31684
32528
|
while (ongoing(x, end)) {
|
|
31685
32529
|
array.push(x);
|
|
31686
|
-
x =
|
|
32530
|
+
x = add5(x, step);
|
|
31687
32531
|
}
|
|
31688
32532
|
return array;
|
|
31689
32533
|
}
|
|
@@ -31946,10 +32790,10 @@ var dependencies177 = ["typed", "compareText", "isZero"];
|
|
|
31946
32790
|
var createEqualText = /* @__PURE__ */ factory(
|
|
31947
32791
|
name177,
|
|
31948
32792
|
dependencies177,
|
|
31949
|
-
({ typed: typed3, compareText: compareText4, isZero:
|
|
32793
|
+
({ typed: typed3, compareText: compareText4, isZero: isZero3 }) => {
|
|
31950
32794
|
return typed3(name177, {
|
|
31951
32795
|
"any, any": function(x, y) {
|
|
31952
|
-
return
|
|
32796
|
+
return isZero3(compareText4(x, y));
|
|
31953
32797
|
}
|
|
31954
32798
|
});
|
|
31955
32799
|
}
|
|
@@ -35277,7 +36121,7 @@ var dependencies211 = [
|
|
|
35277
36121
|
var createSqrtm = /* @__PURE__ */ factory(
|
|
35278
36122
|
name211,
|
|
35279
36123
|
dependencies211,
|
|
35280
|
-
({ typed: typed3, abs: abs2, add:
|
|
36124
|
+
({ typed: typed3, abs: abs2, add: add5, multiply: multiply2, map: map3, sqrt: sqrt2, subtract: subtract3, inv: inv3, size: size2, max: max2, identity: identity2 }) => {
|
|
35281
36125
|
const _maxIterations = 1e3;
|
|
35282
36126
|
const _tolerance = 1e-6;
|
|
35283
36127
|
function _tryWasmSqrtm(A, n) {
|
|
@@ -35343,8 +36187,8 @@ var createSqrtm = /* @__PURE__ */ factory(
|
|
|
35343
36187
|
let Z = identity2(size2(A));
|
|
35344
36188
|
do {
|
|
35345
36189
|
const Yk = Y;
|
|
35346
|
-
Y = multiply2(0.5,
|
|
35347
|
-
Z = multiply2(0.5,
|
|
36190
|
+
Y = multiply2(0.5, add5(Yk, inv3(Z)));
|
|
36191
|
+
Z = multiply2(0.5, add5(Z, inv3(Yk)));
|
|
35348
36192
|
error = max2(abs2(subtract3(Y, Yk)));
|
|
35349
36193
|
if (error > _tolerance && ++iterations > _maxIterations) {
|
|
35350
36194
|
throw new Error("computing square root of matrix: iterative method could not converge");
|
|
@@ -35982,7 +36826,7 @@ var createSlu = /* @__PURE__ */ factory(
|
|
|
35982
36826
|
({
|
|
35983
36827
|
typed: typed3,
|
|
35984
36828
|
abs: abs2,
|
|
35985
|
-
add:
|
|
36829
|
+
add: add5,
|
|
35986
36830
|
multiply: multiply2,
|
|
35987
36831
|
transpose: transpose5,
|
|
35988
36832
|
divideScalar: divideScalar2,
|
|
@@ -35991,7 +36835,7 @@ var createSlu = /* @__PURE__ */ factory(
|
|
|
35991
36835
|
largerEq: largerEq2,
|
|
35992
36836
|
SparseMatrix
|
|
35993
36837
|
}) => {
|
|
35994
|
-
const csSqr2 = createCsSqr({ add:
|
|
36838
|
+
const csSqr2 = createCsSqr({ add: add5, multiply: multiply2, transpose: transpose5 });
|
|
35995
36839
|
const csLu2 = createCsLu({
|
|
35996
36840
|
abs: abs2,
|
|
35997
36841
|
divideScalar: divideScalar2,
|
|
@@ -36296,7 +37140,7 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
36296
37140
|
typed: typed3,
|
|
36297
37141
|
config: config2,
|
|
36298
37142
|
abs: abs2,
|
|
36299
|
-
add:
|
|
37143
|
+
add: add5,
|
|
36300
37144
|
addScalar: addScalar2,
|
|
36301
37145
|
matrix: matrix2,
|
|
36302
37146
|
multiply: multiply2,
|
|
@@ -36306,7 +37150,7 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
36306
37150
|
smaller: smaller2,
|
|
36307
37151
|
equalScalar: equalScalar3,
|
|
36308
37152
|
flatten: flatten5,
|
|
36309
|
-
isZero:
|
|
37153
|
+
isZero: isZero3,
|
|
36310
37154
|
isNumeric: isNumeric2
|
|
36311
37155
|
}) => {
|
|
36312
37156
|
return typed3("intersect", {
|
|
@@ -36421,7 +37265,7 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
36421
37265
|
multiplyScalar2(d1[0], d2[1]),
|
|
36422
37266
|
multiplyScalar2(d2[0], d1[1])
|
|
36423
37267
|
);
|
|
36424
|
-
if (
|
|
37268
|
+
if (isZero3(det2)) return null;
|
|
36425
37269
|
if (smaller2(abs2(det2), config2.relTol)) {
|
|
36426
37270
|
return null;
|
|
36427
37271
|
}
|
|
@@ -36436,7 +37280,7 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
36436
37280
|
),
|
|
36437
37281
|
det2
|
|
36438
37282
|
);
|
|
36439
|
-
return
|
|
37283
|
+
return add5(multiply2(d1, t), o1);
|
|
36440
37284
|
}
|
|
36441
37285
|
function _tryWasmIntersect2d(p1a, p1b, p2a, p2b) {
|
|
36442
37286
|
const wasm = wasmLoader.getModule();
|
|
@@ -36495,7 +37339,7 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
36495
37339
|
multiplyScalar2(d2121, d4343),
|
|
36496
37340
|
multiplyScalar2(d4321, d4321)
|
|
36497
37341
|
);
|
|
36498
|
-
if (
|
|
37342
|
+
if (isZero3(denominator)) return null;
|
|
36499
37343
|
const ta = divideScalar2(numerator, denominator);
|
|
36500
37344
|
const tb = divideScalar2(addScalar2(d1343, multiplyScalar2(ta, d4321)), d4343);
|
|
36501
37345
|
const pax = addScalar2(x1, multiplyScalar2(ta, subtract3(x2, x1)));
|
|
@@ -36552,7 +37396,7 @@ var dependencies219 = ["typed", "add", "divide"];
|
|
|
36552
37396
|
var createMean = /* @__PURE__ */ factory(
|
|
36553
37397
|
name219,
|
|
36554
37398
|
dependencies219,
|
|
36555
|
-
({ typed: typed3, add:
|
|
37399
|
+
({ typed: typed3, add: add5, divide: divide2 }) => {
|
|
36556
37400
|
return typed3(name219, {
|
|
36557
37401
|
// mean([a, b, c, d, ...])
|
|
36558
37402
|
"Array | Matrix": _mean2,
|
|
@@ -36569,7 +37413,7 @@ var createMean = /* @__PURE__ */ factory(
|
|
|
36569
37413
|
function _nmeanDim(array, dim) {
|
|
36570
37414
|
try {
|
|
36571
37415
|
const dimValue = typeof dim === "number" ? dim : dim.valueOf();
|
|
36572
|
-
const sum3 = reduce2(array, dimValue,
|
|
37416
|
+
const sum3 = reduce2(array, dimValue, add5);
|
|
36573
37417
|
const s = Array.isArray(array) ? arraySize(array) : array.size();
|
|
36574
37418
|
return divide2(sum3, s[dimValue]);
|
|
36575
37419
|
} catch (err) {
|
|
@@ -36597,7 +37441,7 @@ var createMean = /* @__PURE__ */ factory(
|
|
|
36597
37441
|
let num2 = 0;
|
|
36598
37442
|
deepForEach(array, function(value) {
|
|
36599
37443
|
try {
|
|
36600
|
-
sum3 = sum3 === void 0 ? value :
|
|
37444
|
+
sum3 = sum3 === void 0 ? value : add5(sum3, value);
|
|
36601
37445
|
num2++;
|
|
36602
37446
|
} catch (err) {
|
|
36603
37447
|
throw improveErrorMessage(err, "mean", value);
|
|
@@ -36617,7 +37461,7 @@ var dependencies220 = ["typed", "add", "divide", "compare", "partitionSelect"];
|
|
|
36617
37461
|
var createMedian = /* @__PURE__ */ factory(
|
|
36618
37462
|
name220,
|
|
36619
37463
|
dependencies220,
|
|
36620
|
-
({ typed: typed3, add:
|
|
37464
|
+
({ typed: typed3, add: add5, divide: divide2, compare: compare2, partitionSelect: partitionSelect2 }) => {
|
|
36621
37465
|
function _median2(array) {
|
|
36622
37466
|
try {
|
|
36623
37467
|
const flat = flatten2(array.valueOf());
|
|
@@ -36650,7 +37494,7 @@ var createMedian = /* @__PURE__ */ factory(
|
|
|
36650
37494
|
});
|
|
36651
37495
|
const middle2 = typed3({
|
|
36652
37496
|
"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit": function(left, right) {
|
|
36653
|
-
return divide2(
|
|
37497
|
+
return divide2(add5(left, right), 2);
|
|
36654
37498
|
}
|
|
36655
37499
|
});
|
|
36656
37500
|
return typed3(name220, {
|
|
@@ -36689,7 +37533,7 @@ var createVariance = /* @__PURE__ */ factory(
|
|
|
36689
37533
|
dependencies221,
|
|
36690
37534
|
({
|
|
36691
37535
|
typed: typed3,
|
|
36692
|
-
add:
|
|
37536
|
+
add: add5,
|
|
36693
37537
|
subtract: subtract3,
|
|
36694
37538
|
multiply: multiply2,
|
|
36695
37539
|
divide: divide2,
|
|
@@ -36738,7 +37582,7 @@ var createVariance = /* @__PURE__ */ factory(
|
|
|
36738
37582
|
let num2 = 0;
|
|
36739
37583
|
deepForEach(array, function(value) {
|
|
36740
37584
|
try {
|
|
36741
|
-
sum3 = sum3 === void 0 ? value :
|
|
37585
|
+
sum3 = sum3 === void 0 ? value : add5(sum3, value);
|
|
36742
37586
|
num2++;
|
|
36743
37587
|
} catch (err) {
|
|
36744
37588
|
throw improveErrorMessage(err, "variance", value);
|
|
@@ -36749,7 +37593,7 @@ var createVariance = /* @__PURE__ */ factory(
|
|
|
36749
37593
|
sum3 = void 0;
|
|
36750
37594
|
deepForEach(array, function(value) {
|
|
36751
37595
|
const diff2 = subtract3(value, mean7);
|
|
36752
|
-
sum3 = sum3 === void 0 ? multiply2(diff2, diff2) :
|
|
37596
|
+
sum3 = sum3 === void 0 ? multiply2(diff2, diff2) : add5(sum3, multiply2(diff2, diff2));
|
|
36753
37597
|
});
|
|
36754
37598
|
if (mathIsNaN(sum3)) {
|
|
36755
37599
|
return sum3;
|
|
@@ -36824,7 +37668,7 @@ var createQuantileSeq = /* @__PURE__ */ factory(
|
|
|
36824
37668
|
({
|
|
36825
37669
|
typed: typed3,
|
|
36826
37670
|
bignumber: bignumber2,
|
|
36827
|
-
add:
|
|
37671
|
+
add: add5,
|
|
36828
37672
|
subtract: subtract3,
|
|
36829
37673
|
divide: divide2,
|
|
36830
37674
|
multiply: multiply2,
|
|
@@ -36872,7 +37716,7 @@ var createQuantileSeq = /* @__PURE__ */ factory(
|
|
|
36872
37716
|
"N must be less than or equal to 2^32-1, as that is the maximum length of an Array"
|
|
36873
37717
|
);
|
|
36874
37718
|
}
|
|
36875
|
-
const nPlusOne =
|
|
37719
|
+
const nPlusOne = add5(probOrN, 1);
|
|
36876
37720
|
probArr = [];
|
|
36877
37721
|
for (let i = 0; smaller2(i, probOrN); i++) {
|
|
36878
37722
|
const prob = divide2(i + 1, nPlusOne);
|
|
@@ -36929,11 +37773,11 @@ var createQuantileSeq = /* @__PURE__ */ factory(
|
|
|
36929
37773
|
return integerPart % 2 === 0 ? left : right;
|
|
36930
37774
|
}
|
|
36931
37775
|
case "midpoint":
|
|
36932
|
-
return divide2(
|
|
37776
|
+
return divide2(add5(left, right), 2);
|
|
36933
37777
|
case "linear":
|
|
36934
37778
|
default: {
|
|
36935
37779
|
const fracPartConverted = isBigNumber(left) && isNumber(fracPart) ? bignumber2(fracPart) : fracPart;
|
|
36936
|
-
return
|
|
37780
|
+
return add5(
|
|
36937
37781
|
multiply2(left, subtract3(1, fracPartConverted)),
|
|
36938
37782
|
multiply2(right, fracPartConverted)
|
|
36939
37783
|
);
|
|
@@ -36967,7 +37811,7 @@ var createKldivergence = /* @__PURE__ */ factory(
|
|
|
36967
37811
|
multiply: multiply2,
|
|
36968
37812
|
map: map3,
|
|
36969
37813
|
dotDivide: dotDivide2,
|
|
36970
|
-
log:
|
|
37814
|
+
log: log4,
|
|
36971
37815
|
isNumeric: isNumeric2
|
|
36972
37816
|
}) => {
|
|
36973
37817
|
return typed3(name223, {
|
|
@@ -37009,7 +37853,7 @@ var createKldivergence = /* @__PURE__ */ factory(
|
|
|
37009
37853
|
const result = sum3(
|
|
37010
37854
|
multiply2(
|
|
37011
37855
|
qnorm,
|
|
37012
|
-
map3(dotDivide2(qnorm, pnorm), (x) =>
|
|
37856
|
+
map3(dotDivide2(qnorm, pnorm), (x) => log4(x))
|
|
37013
37857
|
)
|
|
37014
37858
|
);
|
|
37015
37859
|
if (isNumeric2(result)) {
|
|
@@ -37027,7 +37871,7 @@ var dependencies224 = ["typed", "add", "divide", "multiply", "factorial", "isInt
|
|
|
37027
37871
|
var createMultinomial = /* @__PURE__ */ factory(
|
|
37028
37872
|
name224,
|
|
37029
37873
|
dependencies224,
|
|
37030
|
-
({ typed: typed3, add:
|
|
37874
|
+
({ typed: typed3, add: add5, divide: divide2, multiply: multiply2, factorial: factorial6, isInteger: isInteger3, isPositive: isPositive2 }) => {
|
|
37031
37875
|
return typed3(name224, {
|
|
37032
37876
|
"Array | Matrix": function(a) {
|
|
37033
37877
|
let sum3 = 0;
|
|
@@ -37036,7 +37880,7 @@ var createMultinomial = /* @__PURE__ */ factory(
|
|
|
37036
37880
|
if (!isInteger3(ai) || !isPositive2(ai)) {
|
|
37037
37881
|
throw new TypeError("Positive integer value expected in function multinomial");
|
|
37038
37882
|
}
|
|
37039
|
-
sum3 =
|
|
37883
|
+
sum3 = add5(sum3, ai);
|
|
37040
37884
|
denom = multiply2(denom, factorial6(ai));
|
|
37041
37885
|
});
|
|
37042
37886
|
return divide2(factorial6(sum3), denom);
|
|
@@ -37052,7 +37896,7 @@ var dependencies225 = ["typed", "add", "multiply", "Complex", "divide", "matrix"
|
|
|
37052
37896
|
var createFreqz = /* @__PURE__ */ factory(
|
|
37053
37897
|
name225,
|
|
37054
37898
|
dependencies225,
|
|
37055
|
-
({ typed: typed3, add:
|
|
37899
|
+
({ typed: typed3, add: add5, multiply: multiply2, Complex: Complex13, divide: divide2, matrix: matrix2 }) => {
|
|
37056
37900
|
return typed3(name225, {
|
|
37057
37901
|
"Array, Array": function(b, a) {
|
|
37058
37902
|
const w = createBins(512);
|
|
@@ -37146,13 +37990,13 @@ var createFreqz = /* @__PURE__ */ factory(
|
|
|
37146
37990
|
let sumNum = Complex13(0, 0);
|
|
37147
37991
|
let sumDen = Complex13(0, 0);
|
|
37148
37992
|
for (let j = 0; j < b.length; j++) {
|
|
37149
|
-
sumNum =
|
|
37993
|
+
sumNum = add5(
|
|
37150
37994
|
sumNum,
|
|
37151
37995
|
multiply2(b[j], Complex13(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
37152
37996
|
);
|
|
37153
37997
|
}
|
|
37154
37998
|
for (let j = 0; j < a.length; j++) {
|
|
37155
|
-
sumDen =
|
|
37999
|
+
sumDen = add5(
|
|
37156
38000
|
sumDen,
|
|
37157
38001
|
multiply2(a[j], Complex13(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
37158
38002
|
);
|
|
@@ -37717,7 +38561,7 @@ var createSimplifyCore = /* @__PURE__ */ factory(
|
|
|
37717
38561
|
typed: typed3,
|
|
37718
38562
|
parse: _parse2,
|
|
37719
38563
|
equal: equal2,
|
|
37720
|
-
isZero:
|
|
38564
|
+
isZero: isZero3,
|
|
37721
38565
|
add: _add,
|
|
37722
38566
|
subtract: _subtract,
|
|
37723
38567
|
multiply: _multiply2,
|
|
@@ -37815,10 +38659,10 @@ var createSimplifyCore = /* @__PURE__ */ factory(
|
|
|
37815
38659
|
const a0 = _simplifyCore(node.args[0], options);
|
|
37816
38660
|
let a1 = _simplifyCore(node.args[1], options);
|
|
37817
38661
|
if (node.op === "+") {
|
|
37818
|
-
if (isConstantNode(a0) &&
|
|
38662
|
+
if (isConstantNode(a0) && isZero3(a0.value)) {
|
|
37819
38663
|
return a1;
|
|
37820
38664
|
}
|
|
37821
|
-
if (isConstantNode(a1) &&
|
|
38665
|
+
if (isConstantNode(a1) && isZero3(a1.value)) {
|
|
37822
38666
|
return a0;
|
|
37823
38667
|
}
|
|
37824
38668
|
if (isOperatorNode(a1) && a1.isUnary() && a1.op === "-") {
|
|
@@ -37830,24 +38674,24 @@ var createSimplifyCore = /* @__PURE__ */ factory(
|
|
|
37830
38674
|
if (isOperatorNode(a1) && a1.isUnary() && a1.op === "-") {
|
|
37831
38675
|
return _simplifyCore(new OperatorNode("+", "add", [a0, a1.args[0]]), options);
|
|
37832
38676
|
}
|
|
37833
|
-
if (isConstantNode(a0) &&
|
|
38677
|
+
if (isConstantNode(a0) && isZero3(a0.value)) {
|
|
37834
38678
|
return _simplifyCore(new OperatorNode("-", "unaryMinus", [a1]));
|
|
37835
38679
|
}
|
|
37836
|
-
if (isConstantNode(a1) &&
|
|
38680
|
+
if (isConstantNode(a1) && isZero3(a1.value)) {
|
|
37837
38681
|
return a0;
|
|
37838
38682
|
}
|
|
37839
38683
|
return new OperatorNode(node.op, node.fn, [a0, a1]);
|
|
37840
38684
|
}
|
|
37841
38685
|
if (node.op === "*") {
|
|
37842
38686
|
if (isConstantNode(a0)) {
|
|
37843
|
-
if (
|
|
38687
|
+
if (isZero3(a0.value)) {
|
|
37844
38688
|
return node0;
|
|
37845
38689
|
} else if (equal2(a0.value, 1)) {
|
|
37846
38690
|
return a1;
|
|
37847
38691
|
}
|
|
37848
38692
|
}
|
|
37849
38693
|
if (isConstantNode(a1)) {
|
|
37850
|
-
if (
|
|
38694
|
+
if (isZero3(a1.value)) {
|
|
37851
38695
|
return node0;
|
|
37852
38696
|
} else if (equal2(a1.value, 1)) {
|
|
37853
38697
|
return a0;
|
|
@@ -37859,7 +38703,7 @@ var createSimplifyCore = /* @__PURE__ */ factory(
|
|
|
37859
38703
|
return new OperatorNode(node.op, node.fn, [a0, a1], node.implicit);
|
|
37860
38704
|
}
|
|
37861
38705
|
if (node.op === "/") {
|
|
37862
|
-
if (isConstantNode(a0) &&
|
|
38706
|
+
if (isConstantNode(a0) && isZero3(a0.value)) {
|
|
37863
38707
|
return node0;
|
|
37864
38708
|
}
|
|
37865
38709
|
if (isConstantNode(a1) && equal2(a1.value, 1)) {
|
|
@@ -37869,7 +38713,7 @@ var createSimplifyCore = /* @__PURE__ */ factory(
|
|
|
37869
38713
|
}
|
|
37870
38714
|
if (node.op === "^") {
|
|
37871
38715
|
if (isConstantNode(a1)) {
|
|
37872
|
-
if (
|
|
38716
|
+
if (isZero3(a1.value)) {
|
|
37873
38717
|
return node1;
|
|
37874
38718
|
} else if (equal2(a1.value, 1)) {
|
|
37875
38719
|
return a0;
|
|
@@ -37967,9 +38811,9 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
|
|
|
37967
38811
|
dependencies234,
|
|
37968
38812
|
({
|
|
37969
38813
|
typed: typed3,
|
|
37970
|
-
isZero:
|
|
38814
|
+
isZero: isZero3,
|
|
37971
38815
|
equalScalar: equalScalar3,
|
|
37972
|
-
add:
|
|
38816
|
+
add: add5,
|
|
37973
38817
|
subtract: subtract3,
|
|
37974
38818
|
multiply: multiply2,
|
|
37975
38819
|
divide: divide2,
|
|
@@ -37983,7 +38827,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
|
|
|
37983
38827
|
return typed3(name234, {
|
|
37984
38828
|
"number|Complex, ...number|Complex": (constant, restCoeffs) => {
|
|
37985
38829
|
const coeffs = [constant, ...restCoeffs];
|
|
37986
|
-
while (coeffs.length > 0 &&
|
|
38830
|
+
while (coeffs.length > 0 && isZero3(coeffs[coeffs.length - 1])) {
|
|
37987
38831
|
coeffs.pop();
|
|
37988
38832
|
}
|
|
37989
38833
|
if (coeffs.length < 2) {
|
|
@@ -38011,15 +38855,15 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
|
|
|
38011
38855
|
const denom = unaryMinus2(multiply2(3, a));
|
|
38012
38856
|
const D0_1 = multiply2(b, b);
|
|
38013
38857
|
const D0_2 = multiply2(3, a, c);
|
|
38014
|
-
const D1_1 =
|
|
38858
|
+
const D1_1 = add5(multiply2(2, b, b, b), multiply2(27, a, a, d));
|
|
38015
38859
|
const D1_2 = multiply2(9, a, b, c);
|
|
38016
38860
|
if (equalScalar3(D0_1, D0_2) && equalScalar3(D1_1, D1_2)) {
|
|
38017
38861
|
return [divide2(b, denom)];
|
|
38018
38862
|
}
|
|
38019
38863
|
const Delta0 = subtract3(D0_1, D0_2);
|
|
38020
38864
|
const Delta1 = subtract3(D1_1, D1_2);
|
|
38021
|
-
const discriminant1 =
|
|
38022
|
-
const discriminant2 =
|
|
38865
|
+
const discriminant1 = add5(multiply2(18, a, b, c, d), multiply2(b, b, c, c));
|
|
38866
|
+
const discriminant2 = add5(
|
|
38023
38867
|
multiply2(4, b, b, b, d),
|
|
38024
38868
|
multiply2(4, a, c, c, c),
|
|
38025
38869
|
multiply2(27, a, a, d, d)
|
|
@@ -38027,7 +38871,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
|
|
|
38027
38871
|
if (equalScalar3(discriminant1, discriminant2)) {
|
|
38028
38872
|
return [
|
|
38029
38873
|
divide2(
|
|
38030
|
-
subtract3(multiply2(4, a, b, c),
|
|
38874
|
+
subtract3(multiply2(4, a, b, c), add5(multiply2(9, a, a, d), multiply2(b, b, b))),
|
|
38031
38875
|
multiply2(a, Delta0)
|
|
38032
38876
|
),
|
|
38033
38877
|
// simple root
|
|
@@ -38040,7 +38884,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
|
|
|
38040
38884
|
Ccubed = Delta1;
|
|
38041
38885
|
} else {
|
|
38042
38886
|
Ccubed = divide2(
|
|
38043
|
-
|
|
38887
|
+
add5(
|
|
38044
38888
|
Delta1,
|
|
38045
38889
|
sqrt2(subtract3(multiply2(Delta1, Delta1), multiply2(4, Delta0, Delta0, Delta0)))
|
|
38046
38890
|
),
|
|
@@ -38048,7 +38892,7 @@ var createPolynomialRoot = /* @__PURE__ */ factory(
|
|
|
38048
38892
|
);
|
|
38049
38893
|
}
|
|
38050
38894
|
const allRoots = true;
|
|
38051
|
-
const rawRoots = cbrt3(Ccubed, allRoots).toArray().map((C) => divide2(
|
|
38895
|
+
const rawRoots = cbrt3(Ccubed, allRoots).toArray().map((C) => divide2(add5(b, C, divide2(Delta0, C)), denom));
|
|
38052
38896
|
return rawRoots.map((r) => {
|
|
38053
38897
|
if (typeOf3(r) === "Complex" && equalScalar3(re3(r), re3(r) + im3(r))) {
|
|
38054
38898
|
return re3(r);
|
|
@@ -38104,7 +38948,7 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
38104
38948
|
gamma: gamma2,
|
|
38105
38949
|
sin: sin2,
|
|
38106
38950
|
subtract: subtract3,
|
|
38107
|
-
add:
|
|
38951
|
+
add: add5,
|
|
38108
38952
|
Complex: Complex13,
|
|
38109
38953
|
BigNumber: BigNumber9,
|
|
38110
38954
|
pi
|
|
@@ -38172,20 +39016,20 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
38172
39016
|
}
|
|
38173
39017
|
function d(k, n) {
|
|
38174
39018
|
let S = k;
|
|
38175
|
-
for (let j = k; smallerEq2(j, n); j =
|
|
39019
|
+
for (let j = k; smallerEq2(j, n); j = add5(j, 1)) {
|
|
38176
39020
|
const factor2 = divide2(
|
|
38177
|
-
multiply2(factorial6(
|
|
39021
|
+
multiply2(factorial6(add5(n, subtract3(j, 1))), pow2(4, j)),
|
|
38178
39022
|
multiply2(factorial6(subtract3(n, j)), factorial6(multiply2(2, j)))
|
|
38179
39023
|
);
|
|
38180
|
-
S =
|
|
39024
|
+
S = add5(S, factor2);
|
|
38181
39025
|
}
|
|
38182
39026
|
return multiply2(n, S);
|
|
38183
39027
|
}
|
|
38184
39028
|
function f(s, n, createValue) {
|
|
38185
39029
|
const c = divide2(1, multiply2(d(createValue(0), n), subtract3(1, pow2(2, subtract3(1, s)))));
|
|
38186
39030
|
let S = createValue(0);
|
|
38187
|
-
for (let k = createValue(1); smallerEq2(k, n); k =
|
|
38188
|
-
S =
|
|
39031
|
+
for (let k = createValue(1); smallerEq2(k, n); k = add5(k, 1)) {
|
|
39032
|
+
S = add5(S, divide2(multiply2((-1) ** (k - 1), d(k, n)), pow2(k, s)));
|
|
38189
39033
|
}
|
|
38190
39034
|
return multiply2(c, S);
|
|
38191
39035
|
}
|
|
@@ -38622,11 +39466,11 @@ function createComplexEigs({
|
|
|
38622
39466
|
M[i] = Array(N2).fill(0);
|
|
38623
39467
|
}
|
|
38624
39468
|
let I2 = 0;
|
|
38625
|
-
for (const
|
|
38626
|
-
const n =
|
|
39469
|
+
for (const sub4 of arr10) {
|
|
39470
|
+
const n = sub4.length;
|
|
38627
39471
|
for (let i = 0; i < n; i++) {
|
|
38628
39472
|
for (let j = 0; j < n; j++) {
|
|
38629
|
-
M[I2 + i][I2 + j] =
|
|
39473
|
+
M[I2 + i][I2 + j] = sub4[i][j];
|
|
38630
39474
|
}
|
|
38631
39475
|
}
|
|
38632
39476
|
I2 += n;
|
|
@@ -38734,7 +39578,7 @@ function createRealSymmetric({
|
|
|
38734
39578
|
inv: inv3,
|
|
38735
39579
|
bignumber: bignumber2,
|
|
38736
39580
|
multiply: multiply2,
|
|
38737
|
-
add:
|
|
39581
|
+
add: add5
|
|
38738
39582
|
}) {
|
|
38739
39583
|
function bigGte(a, b) {
|
|
38740
39584
|
if (typeof a === "number" && typeof b === "number") return a >= b;
|
|
@@ -38931,7 +39775,7 @@ function createRealSymmetric({
|
|
|
38931
39775
|
subtract3(multiplyScalar2(c2, Hij[i][i]), csHij),
|
|
38932
39776
|
multiplyScalar2(s2, Hij[j][j])
|
|
38933
39777
|
);
|
|
38934
|
-
const Ajj =
|
|
39778
|
+
const Ajj = add5(
|
|
38935
39779
|
multiplyScalar2(s2, Hij[i][i]),
|
|
38936
39780
|
csHij,
|
|
38937
39781
|
multiplyScalar2(c2, Hij[j][j])
|
|
@@ -39103,7 +39947,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
39103
39947
|
inv: inv3,
|
|
39104
39948
|
bignumber: bignumber2,
|
|
39105
39949
|
multiply: multiply2,
|
|
39106
|
-
add:
|
|
39950
|
+
add: add5,
|
|
39107
39951
|
larger: larger2,
|
|
39108
39952
|
column: _column,
|
|
39109
39953
|
flatten: flatten5,
|
|
@@ -39135,7 +39979,7 @@ var createEigs = /* @__PURE__ */ factory(
|
|
|
39135
39979
|
bignumber: bignumber2,
|
|
39136
39980
|
complex: complex3,
|
|
39137
39981
|
multiply: multiply2,
|
|
39138
|
-
add:
|
|
39982
|
+
add: add5
|
|
39139
39983
|
});
|
|
39140
39984
|
const doComplexEigs = createComplexEigs({
|
|
39141
39985
|
addScalar: addScalar2,
|
|
@@ -40605,7 +41449,7 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
40605
41449
|
parse: parse3,
|
|
40606
41450
|
simplify: simplify2,
|
|
40607
41451
|
equal: equal2,
|
|
40608
|
-
isZero:
|
|
41452
|
+
isZero: isZero3,
|
|
40609
41453
|
numeric: numeric2,
|
|
40610
41454
|
ConstantNode,
|
|
40611
41455
|
FunctionNode,
|
|
@@ -40637,7 +41481,7 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
40637
41481
|
}
|
|
40638
41482
|
return symbol;
|
|
40639
41483
|
}
|
|
40640
|
-
const
|
|
41484
|
+
const derivative3 = typed3(name244, {
|
|
40641
41485
|
"Node, SymbolNode": plainDerivative,
|
|
40642
41486
|
"Node, SymbolNode, Object": plainDerivative,
|
|
40643
41487
|
"Node, string": (node, symbol) => plainDerivative(node, parseIdentifier(symbol)),
|
|
@@ -40653,8 +41497,8 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
40653
41497
|
}
|
|
40654
41498
|
*/
|
|
40655
41499
|
});
|
|
40656
|
-
|
|
40657
|
-
|
|
41500
|
+
derivative3._simplify = true;
|
|
41501
|
+
derivative3.toTex = function(deriv) {
|
|
40658
41502
|
return _derivTex(...deriv.args);
|
|
40659
41503
|
};
|
|
40660
41504
|
const _derivTex = typed3("_derivTex", {
|
|
@@ -41081,7 +41925,7 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
41081
41925
|
const arg0 = node.args[0];
|
|
41082
41926
|
const arg1 = node.args[1];
|
|
41083
41927
|
if (isConst2(arg0)) {
|
|
41084
|
-
if (isConstantNode(arg0) && (
|
|
41928
|
+
if (isConstantNode(arg0) && (isZero3(arg0.value) || equal2(arg0.value, 1))) {
|
|
41085
41929
|
return createConstantNode2(0);
|
|
41086
41930
|
}
|
|
41087
41931
|
return new OperatorNode("*", "multiply", [
|
|
@@ -41094,7 +41938,7 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
41094
41938
|
}
|
|
41095
41939
|
if (isConst2(arg1)) {
|
|
41096
41940
|
if (isConstantNode(arg1)) {
|
|
41097
|
-
if (
|
|
41941
|
+
if (isZero3(arg1.value)) {
|
|
41098
41942
|
return createConstantNode2(0);
|
|
41099
41943
|
}
|
|
41100
41944
|
if (equal2(arg1.value, 1)) {
|
|
@@ -41132,7 +41976,7 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
41132
41976
|
function createConstantNode2(value, valueType) {
|
|
41133
41977
|
return new ConstantNode(numeric2(value, valueType || safeNumberType(String(value), config2)));
|
|
41134
41978
|
}
|
|
41135
|
-
return
|
|
41979
|
+
return derivative3;
|
|
41136
41980
|
}
|
|
41137
41981
|
);
|
|
41138
41982
|
|
|
@@ -41161,7 +42005,7 @@ var createNorm = /* @__PURE__ */ factory(
|
|
|
41161
42005
|
({
|
|
41162
42006
|
typed: typed3,
|
|
41163
42007
|
abs: abs2,
|
|
41164
|
-
add:
|
|
42008
|
+
add: add5,
|
|
41165
42009
|
pow: pow2,
|
|
41166
42010
|
conj: conj3,
|
|
41167
42011
|
sqrt: sqrt2,
|
|
@@ -41266,7 +42110,7 @@ var createNorm = /* @__PURE__ */ factory(
|
|
|
41266
42110
|
if (!equalScalar3(p, 0)) {
|
|
41267
42111
|
let n = 0;
|
|
41268
42112
|
x.forEach(function(value) {
|
|
41269
|
-
n =
|
|
42113
|
+
n = add5(pow2(abs2(value), p), n);
|
|
41270
42114
|
}, true);
|
|
41271
42115
|
return pow2(n, 1 / p);
|
|
41272
42116
|
}
|
|
@@ -41277,7 +42121,7 @@ var createNorm = /* @__PURE__ */ factory(
|
|
|
41277
42121
|
function _matrixNormFrobenius(x) {
|
|
41278
42122
|
let fro = 0;
|
|
41279
42123
|
x.forEach(function(value) {
|
|
41280
|
-
fro =
|
|
42124
|
+
fro = add5(fro, multiply2(value, conj3(value)));
|
|
41281
42125
|
});
|
|
41282
42126
|
return abs2(sqrt2(fro));
|
|
41283
42127
|
}
|
|
@@ -41286,7 +42130,7 @@ var createNorm = /* @__PURE__ */ factory(
|
|
|
41286
42130
|
let maxc = 0;
|
|
41287
42131
|
x.forEach(function(value, index) {
|
|
41288
42132
|
const j = index[1];
|
|
41289
|
-
const cj =
|
|
42133
|
+
const cj = add5(c[j] || 0, abs2(value));
|
|
41290
42134
|
if (larger2(cj, maxc)) {
|
|
41291
42135
|
maxc = cj;
|
|
41292
42136
|
}
|
|
@@ -41310,7 +42154,7 @@ var createNorm = /* @__PURE__ */ factory(
|
|
|
41310
42154
|
let maxr = 0;
|
|
41311
42155
|
x.forEach(function(value, index) {
|
|
41312
42156
|
const i = index[0];
|
|
41313
|
-
const ri =
|
|
42157
|
+
const ri = add5(r[i] || 0, abs2(value));
|
|
41314
42158
|
if (larger2(ri, maxr)) {
|
|
41315
42159
|
maxr = ri;
|
|
41316
42160
|
}
|
|
@@ -42144,7 +42988,7 @@ var createSylvester = /* @__PURE__ */ factory(
|
|
|
42144
42988
|
transpose: transpose5,
|
|
42145
42989
|
index,
|
|
42146
42990
|
subset: subset2,
|
|
42147
|
-
add:
|
|
42991
|
+
add: add5,
|
|
42148
42992
|
subtract: subtract3,
|
|
42149
42993
|
identity: identity2,
|
|
42150
42994
|
lusolve: lusolve2,
|
|
@@ -42192,7 +43036,7 @@ var createSylvester = /* @__PURE__ */ factory(
|
|
|
42192
43036
|
if (k < n - 1 && abs2(subset2(G, index(k + 1, k))) > 1e-5) {
|
|
42193
43037
|
let RHS = vc(subset2(D, index(all, [k])), subset2(D, index(all, [k + 1])));
|
|
42194
43038
|
for (let j = 0; j < k; j++) {
|
|
42195
|
-
RHS =
|
|
43039
|
+
RHS = add5(
|
|
42196
43040
|
RHS,
|
|
42197
43041
|
vc(multiply2(y[j], subset2(G, index(j, k))), multiply2(y[j], subset2(G, index(j, k + 1))))
|
|
42198
43042
|
);
|
|
@@ -42201,7 +43045,7 @@ var createSylvester = /* @__PURE__ */ factory(
|
|
|
42201
43045
|
const gmk = multiply2(identity2(m), multiply2(-1, subset2(G, index(k + 1, k))));
|
|
42202
43046
|
const gkm = multiply2(identity2(m), multiply2(-1, subset2(G, index(k, k + 1))));
|
|
42203
43047
|
const gmm = multiply2(identity2(m), multiply2(-1, subset2(G, index(k + 1, k + 1))));
|
|
42204
|
-
const LHS = vc(hc(
|
|
43048
|
+
const LHS = vc(hc(add5(F, gkk), gmk), hc(gkm, add5(F, gmm)));
|
|
42205
43049
|
const yAux = lusolve2(LHS, RHS);
|
|
42206
43050
|
y[k] = yAux.subset(index(range2(0, m), [0]));
|
|
42207
43051
|
y[k + 1] = yAux.subset(index(range2(m, 2 * m), [0]));
|
|
@@ -42209,7 +43053,7 @@ var createSylvester = /* @__PURE__ */ factory(
|
|
|
42209
43053
|
} else {
|
|
42210
43054
|
let RHS = subset2(D, index(all, [k]));
|
|
42211
43055
|
for (let j = 0; j < k; j++) {
|
|
42212
|
-
RHS =
|
|
43056
|
+
RHS = add5(RHS, multiply2(y[j], subset2(G, index(j, k))));
|
|
42213
43057
|
}
|
|
42214
43058
|
const gkk = subset2(G, index(k, k));
|
|
42215
43059
|
const LHS = subtract3(F, multiply2(gkk, identity2(m)));
|
|
@@ -42534,7 +43378,7 @@ var getMatrixDataType = createGetMatrixDataType(
|
|
|
42534
43378
|
var map2 = createMap(factoryScope);
|
|
42535
43379
|
var size = createSize(factoryScope);
|
|
42536
43380
|
var squeeze2 = createSqueeze(factoryScope);
|
|
42537
|
-
var
|
|
43381
|
+
var combinations3 = createCombinations(factoryScope);
|
|
42538
43382
|
var combinationsWithRep2 = createCombinationsWithRep(
|
|
42539
43383
|
factoryScope
|
|
42540
43384
|
);
|
|
@@ -42558,7 +43402,7 @@ var isNaN2 = createIsNaN(factoryScope);
|
|
|
42558
43402
|
var isNegative = createIsNegative(factoryScope);
|
|
42559
43403
|
var isNumeric = createIsNumeric(factoryScope);
|
|
42560
43404
|
var isPositive = createIsPositive(factoryScope);
|
|
42561
|
-
var
|
|
43405
|
+
var isPrime2 = createIsPrime(factoryScope);
|
|
42562
43406
|
var numeric = createNumeric(factoryScope);
|
|
42563
43407
|
var typeOf2 = createTypeOf(factoryScope);
|
|
42564
43408
|
var factory_abs = createAbs(factoryScope);
|
|
@@ -42605,7 +43449,7 @@ factoryScope.atan = factory_atan;
|
|
|
42605
43449
|
factoryScope.atanh = factory_atanh;
|
|
42606
43450
|
factoryScope.bitNot = bitNot2;
|
|
42607
43451
|
factoryScope.clone = clone2;
|
|
42608
|
-
factoryScope.combinations =
|
|
43452
|
+
factoryScope.combinations = combinations3;
|
|
42609
43453
|
factoryScope.combinationsWithRep = combinationsWithRep2;
|
|
42610
43454
|
factoryScope.conj = conj2;
|
|
42611
43455
|
factoryScope.cos = factory_cos;
|
|
@@ -42624,7 +43468,7 @@ factoryScope.isNaN = isNaN2;
|
|
|
42624
43468
|
factoryScope.isNegative = isNegative;
|
|
42625
43469
|
factoryScope.isNumeric = isNumeric;
|
|
42626
43470
|
factoryScope.isPositive = isPositive;
|
|
42627
|
-
factoryScope.isPrime =
|
|
43471
|
+
factoryScope.isPrime = isPrime2;
|
|
42628
43472
|
factoryScope.lgamma = lgamma2;
|
|
42629
43473
|
factoryScope.log2 = factory_log2;
|
|
42630
43474
|
factoryScope.log10 = factory_log10;
|
|
@@ -42671,7 +43515,7 @@ var hasNumericValue = createHasNumericValue(
|
|
|
42671
43515
|
factoryScope
|
|
42672
43516
|
);
|
|
42673
43517
|
var isFinite2 = createIsFinite(factoryScope);
|
|
42674
|
-
var
|
|
43518
|
+
var isZero2 = createIsZero(factoryScope);
|
|
42675
43519
|
var factory_unaryPlus = createUnaryPlus(
|
|
42676
43520
|
factoryScope
|
|
42677
43521
|
);
|
|
@@ -42683,7 +43527,7 @@ factoryScope.unaryPlus = factory_unaryPlus;
|
|
|
42683
43527
|
factoryScope.flatten = flatten3;
|
|
42684
43528
|
factoryScope.hasNumericValue = hasNumericValue;
|
|
42685
43529
|
factoryScope.isFinite = isFinite2;
|
|
42686
|
-
factoryScope.isZero =
|
|
43530
|
+
factoryScope.isZero = isZero2;
|
|
42687
43531
|
factoryScope.prod = prod;
|
|
42688
43532
|
factoryScope.dot = factory_dot;
|
|
42689
43533
|
factoryScope.squeeze = squeeze2;
|
|
@@ -43150,8 +43994,8 @@ var setSymDifference2 = createSetSymDifference(
|
|
|
43150
43994
|
factoryScope.setSymDifference = setSymDifference2;
|
|
43151
43995
|
var simplify = createSimplify(factoryScope);
|
|
43152
43996
|
factoryScope.simplify = simplify;
|
|
43153
|
-
var
|
|
43154
|
-
factoryScope.derivative =
|
|
43997
|
+
var derivative2 = createDerivative(factoryScope);
|
|
43998
|
+
factoryScope.derivative = derivative2;
|
|
43155
43999
|
var factory_norm = createNorm(factoryScope);
|
|
43156
44000
|
factoryScope.norm = factory_norm;
|
|
43157
44001
|
var rationalize = createRationalize(
|
|
@@ -44152,16 +44996,16 @@ function solve(equation, varName) {
|
|
|
44152
44996
|
var cleanComponent = cleanComponent2, pushReal = pushReal2;
|
|
44153
44997
|
const [c0, c1, c2, c3] = coeffs;
|
|
44154
44998
|
const eps = 1e-9;
|
|
44155
|
-
let
|
|
44156
|
-
if (Math.abs(c3) > eps)
|
|
44157
|
-
else if (Math.abs(c2) > eps)
|
|
44158
|
-
else if (Math.abs(c1) > eps)
|
|
44159
|
-
if (
|
|
44999
|
+
let degree3 = 0;
|
|
45000
|
+
if (Math.abs(c3) > eps) degree3 = 3;
|
|
45001
|
+
else if (Math.abs(c2) > eps) degree3 = 2;
|
|
45002
|
+
else if (Math.abs(c1) > eps) degree3 = 1;
|
|
45003
|
+
if (degree3 === 0) {
|
|
44160
45004
|
return [];
|
|
44161
45005
|
}
|
|
44162
45006
|
let raw;
|
|
44163
45007
|
try {
|
|
44164
|
-
const args = [c0, c1, c2, c3].slice(0,
|
|
45008
|
+
const args = [c0, c1, c2, c3].slice(0, degree3 + 1);
|
|
44165
45009
|
raw = polynomialRoot(...args);
|
|
44166
45010
|
} catch {
|
|
44167
45011
|
return numericRealRoots(expr, varName);
|
|
@@ -46415,7 +47259,7 @@ function scale(alpha, x) {
|
|
|
46415
47259
|
function subtract2(a, b) {
|
|
46416
47260
|
return a.map((v, i) => v - b[i]);
|
|
46417
47261
|
}
|
|
46418
|
-
function
|
|
47262
|
+
function add3(a, b) {
|
|
46419
47263
|
return a.map((v, i) => v + b[i]);
|
|
46420
47264
|
}
|
|
46421
47265
|
function zeros2(n) {
|
|
@@ -46584,7 +47428,7 @@ function cg(a, b, opts) {
|
|
|
46584
47428
|
z = applyM(r);
|
|
46585
47429
|
const rzNew = dot2(r, z);
|
|
46586
47430
|
const beta2 = rzNew / rzOld;
|
|
46587
|
-
p =
|
|
47431
|
+
p = add3(z, scale(beta2, p));
|
|
46588
47432
|
rzOld = rzNew;
|
|
46589
47433
|
}
|
|
46590
47434
|
return { x, iterations, converged: residual < tol, residual };
|
|
@@ -46751,7 +47595,7 @@ function bicgstab(a, b, opts) {
|
|
|
46751
47595
|
p = r.slice();
|
|
46752
47596
|
} else {
|
|
46753
47597
|
const beta2 = rhoNew / rho * (alpha / omega);
|
|
46754
|
-
p =
|
|
47598
|
+
p = add3(r, scale(beta2, subtract2(p, scale(omega, v))));
|
|
46755
47599
|
}
|
|
46756
47600
|
rho = rhoNew;
|
|
46757
47601
|
const pHat = applyM(p);
|
|
@@ -47004,12 +47848,12 @@ function svds(A, k = 1, opts) {
|
|
|
47004
47848
|
}
|
|
47005
47849
|
|
|
47006
47850
|
// src/numeric/structured-solvers.ts
|
|
47007
|
-
function thomasSolve(
|
|
47851
|
+
function thomasSolve(sub4, diag2, sup, d) {
|
|
47008
47852
|
const n = diag2.length;
|
|
47009
47853
|
if (n === 0) return [];
|
|
47010
|
-
if (
|
|
47854
|
+
if (sub4.length !== n - 1 || sup.length !== n - 1 || d.length !== n) {
|
|
47011
47855
|
throw new Error(
|
|
47012
|
-
`thomasSolve: expected sub/sup of length ${n - 1} and d of length ${n}, got sub=${
|
|
47856
|
+
`thomasSolve: expected sub/sup of length ${n - 1} and d of length ${n}, got sub=${sub4.length}, sup=${sup.length}, d=${d.length}`
|
|
47013
47857
|
);
|
|
47014
47858
|
}
|
|
47015
47859
|
const cp = new Array(n).fill(0);
|
|
@@ -47018,12 +47862,12 @@ function thomasSolve(sub3, diag2, sup, d) {
|
|
|
47018
47862
|
cp[0] = n > 1 ? sup[0] / diag2[0] : 0;
|
|
47019
47863
|
dp[0] = d[0] / diag2[0];
|
|
47020
47864
|
for (let i = 1; i < n; i++) {
|
|
47021
|
-
const m = diag2[i] -
|
|
47865
|
+
const m = diag2[i] - sub4[i - 1] * cp[i - 1];
|
|
47022
47866
|
if (m === 0) {
|
|
47023
47867
|
throw new Error(`thomasSolve: zero pivot at row ${i} (no pivoting is performed)`);
|
|
47024
47868
|
}
|
|
47025
47869
|
cp[i] = i < n - 1 ? sup[i] / m : 0;
|
|
47026
|
-
dp[i] = (d[i] -
|
|
47870
|
+
dp[i] = (d[i] - sub4[i - 1] * dp[i - 1]) / m;
|
|
47027
47871
|
}
|
|
47028
47872
|
const x = new Array(n);
|
|
47029
47873
|
x[n - 1] = dp[n - 1];
|
|
@@ -47957,7 +48801,7 @@ function bsplineEval(spline, xnew) {
|
|
|
47957
48801
|
}
|
|
47958
48802
|
|
|
47959
48803
|
// src/numeric/monte-carlo.ts
|
|
47960
|
-
function
|
|
48804
|
+
function isPrime3(x) {
|
|
47961
48805
|
if (x < 2) return false;
|
|
47962
48806
|
for (let i = 2; i * i <= x; i++) {
|
|
47963
48807
|
if (x % i === 0) return false;
|
|
@@ -47969,7 +48813,7 @@ function nthPrime(k) {
|
|
|
47969
48813
|
let candidate = 1;
|
|
47970
48814
|
while (count2 < k) {
|
|
47971
48815
|
candidate++;
|
|
47972
|
-
if (
|
|
48816
|
+
if (isPrime3(candidate)) count2++;
|
|
47973
48817
|
}
|
|
47974
48818
|
return candidate;
|
|
47975
48819
|
}
|
|
@@ -48607,18 +49451,18 @@ function nelderMead(f, x0, opts = {}) {
|
|
|
48607
49451
|
for (let i = 0; i < n; i++) for (let j = 0; j < n; j++) c[j] += pts[i][j] / n;
|
|
48608
49452
|
return c;
|
|
48609
49453
|
};
|
|
48610
|
-
const
|
|
48611
|
-
const
|
|
49454
|
+
const add5 = (a, b, s) => a.map((v, i) => v + s * b[i]);
|
|
49455
|
+
const sub4 = (a, b) => a.map((v, i) => v - b[i]);
|
|
48612
49456
|
for (; iter < maxIter; iter++) {
|
|
48613
49457
|
const order = fv.map((_, i) => i).sort((i, j) => fv[i] - fv[j]);
|
|
48614
49458
|
simplex = order.map((i) => simplex[i]);
|
|
48615
49459
|
fv = order.map((i) => fv[i]);
|
|
48616
49460
|
if (Math.abs(fv[n] - fv[0]) <= tol * (Math.abs(fv[0]) + tol)) break;
|
|
48617
49461
|
const c = centroid2(simplex.slice(0, n));
|
|
48618
|
-
const xr =
|
|
49462
|
+
const xr = add5(c, sub4(c, simplex[n]), alpha);
|
|
48619
49463
|
const fr = f(xr);
|
|
48620
49464
|
if (fr < fv[0]) {
|
|
48621
|
-
const xe =
|
|
49465
|
+
const xe = add5(c, sub4(c, simplex[n]), gamma2);
|
|
48622
49466
|
const fe = f(xe);
|
|
48623
49467
|
if (fe < fr) {
|
|
48624
49468
|
simplex[n] = xe;
|
|
@@ -48631,14 +49475,14 @@ function nelderMead(f, x0, opts = {}) {
|
|
|
48631
49475
|
simplex[n] = xr;
|
|
48632
49476
|
fv[n] = fr;
|
|
48633
49477
|
} else {
|
|
48634
|
-
const xc =
|
|
49478
|
+
const xc = add5(c, sub4(simplex[n], c), rho);
|
|
48635
49479
|
const fc = f(xc);
|
|
48636
49480
|
if (fc < fv[n]) {
|
|
48637
49481
|
simplex[n] = xc;
|
|
48638
49482
|
fv[n] = fc;
|
|
48639
49483
|
} else {
|
|
48640
49484
|
for (let i = 1; i <= n; i++) {
|
|
48641
|
-
simplex[i] =
|
|
49485
|
+
simplex[i] = add5(simplex[0], sub4(simplex[i], simplex[0]), sigma);
|
|
48642
49486
|
fv[i] = f(simplex[i]);
|
|
48643
49487
|
}
|
|
48644
49488
|
}
|
|
@@ -49655,23 +50499,23 @@ function polyFromRoots(roots) {
|
|
|
49655
50499
|
return c.map((z) => z.re);
|
|
49656
50500
|
}
|
|
49657
50501
|
function relativeDegree(z, p) {
|
|
49658
|
-
const
|
|
49659
|
-
if (
|
|
49660
|
-
return
|
|
50502
|
+
const degree3 = p.length - z.length;
|
|
50503
|
+
if (degree3 < 0) throw new Error("Improper transfer function: fewer poles than zeros");
|
|
50504
|
+
return degree3;
|
|
49661
50505
|
}
|
|
49662
50506
|
function lp2lpZpk(z, p, k, wo) {
|
|
49663
|
-
const
|
|
50507
|
+
const degree3 = relativeDegree(z, p);
|
|
49664
50508
|
return {
|
|
49665
50509
|
z: z.map((zv) => cScale2(zv, wo)),
|
|
49666
50510
|
p: p.map((pv) => cScale2(pv, wo)),
|
|
49667
|
-
k: k * Math.pow(wo,
|
|
50511
|
+
k: k * Math.pow(wo, degree3)
|
|
49668
50512
|
};
|
|
49669
50513
|
}
|
|
49670
50514
|
function lp2hpZpk(z, p, k, wo) {
|
|
49671
|
-
const
|
|
50515
|
+
const degree3 = relativeDegree(z, p);
|
|
49672
50516
|
const woC = new Complex11(wo, 0);
|
|
49673
50517
|
const zHp = z.map((zv) => cDiv2(woC, zv));
|
|
49674
|
-
for (let i = 0; i <
|
|
50518
|
+
for (let i = 0; i < degree3; i++) zHp.push(new Complex11(0, 0));
|
|
49675
50519
|
let prodZ = new Complex11(1, 0);
|
|
49676
50520
|
for (const zv of z) prodZ = cMul2(prodZ, zv.negate());
|
|
49677
50521
|
let prodP = new Complex11(1, 0);
|
|
@@ -49679,7 +50523,7 @@ function lp2hpZpk(z, p, k, wo) {
|
|
|
49679
50523
|
return { z: zHp, p: p.map((pv) => cDiv2(woC, pv)), k: k * cDiv2(prodZ, prodP).re };
|
|
49680
50524
|
}
|
|
49681
50525
|
function lp2bpZpk(z, p, k, wo, bw) {
|
|
49682
|
-
const
|
|
50526
|
+
const degree3 = relativeDegree(z, p);
|
|
49683
50527
|
const wo2 = new Complex11(wo * wo, 0);
|
|
49684
50528
|
const shift = (roots) => {
|
|
49685
50529
|
const lp = roots.map((r) => cScale2(r, bw / 2));
|
|
@@ -49688,11 +50532,11 @@ function lp2bpZpk(z, p, k, wo, bw) {
|
|
|
49688
50532
|
return plus.concat(minus);
|
|
49689
50533
|
};
|
|
49690
50534
|
const zBp = shift(z);
|
|
49691
|
-
for (let i = 0; i <
|
|
49692
|
-
return { z: zBp, p: shift(p), k: k * Math.pow(bw,
|
|
50535
|
+
for (let i = 0; i < degree3; i++) zBp.push(new Complex11(0, 0));
|
|
50536
|
+
return { z: zBp, p: shift(p), k: k * Math.pow(bw, degree3) };
|
|
49693
50537
|
}
|
|
49694
50538
|
function lp2bsZpk(z, p, k, wo, bw) {
|
|
49695
|
-
const
|
|
50539
|
+
const degree3 = relativeDegree(z, p);
|
|
49696
50540
|
const wo2 = new Complex11(wo * wo, 0);
|
|
49697
50541
|
const bw2 = new Complex11(bw / 2, 0);
|
|
49698
50542
|
const shift = (roots) => {
|
|
@@ -49702,8 +50546,8 @@ function lp2bsZpk(z, p, k, wo, bw) {
|
|
|
49702
50546
|
return plus.concat(minus);
|
|
49703
50547
|
};
|
|
49704
50548
|
const zBs = shift(z);
|
|
49705
|
-
for (let i = 0; i <
|
|
49706
|
-
for (let i = 0; i <
|
|
50549
|
+
for (let i = 0; i < degree3; i++) zBs.push(new Complex11(0, wo));
|
|
50550
|
+
for (let i = 0; i < degree3; i++) zBs.push(new Complex11(0, -wo));
|
|
49707
50551
|
let prodZ = new Complex11(1, 0);
|
|
49708
50552
|
for (const zv of z) prodZ = cMul2(prodZ, zv.negate());
|
|
49709
50553
|
let prodP = new Complex11(1, 0);
|
|
@@ -49711,10 +50555,10 @@ function lp2bsZpk(z, p, k, wo, bw) {
|
|
|
49711
50555
|
return { z: zBs, p: shift(p), k: k * cDiv2(prodZ, prodP).re };
|
|
49712
50556
|
}
|
|
49713
50557
|
function bilinearZpk(z, p, k, fs) {
|
|
49714
|
-
const
|
|
50558
|
+
const degree3 = relativeDegree(z, p);
|
|
49715
50559
|
const fs2 = new Complex11(2 * fs, 0);
|
|
49716
50560
|
const zZ = z.map((zv) => cDiv2(cAdd2(fs2, zv), cSub2(fs2, zv)));
|
|
49717
|
-
for (let i = 0; i <
|
|
50561
|
+
for (let i = 0; i < degree3; i++) zZ.push(new Complex11(-1, 0));
|
|
49718
50562
|
let prodZ = new Complex11(1, 0);
|
|
49719
50563
|
for (const zv of z) prodZ = cMul2(prodZ, cSub2(fs2, zv));
|
|
49720
50564
|
let prodP = new Complex11(1, 0);
|
|
@@ -50899,10 +51743,10 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
|
|
|
50899
51743
|
const wtx = [0, ...w];
|
|
50900
51744
|
const dimsize = Math.ceil(numtaps / 2 + 2);
|
|
50901
51745
|
const wrksize = gridDensity * dimsize;
|
|
50902
|
-
const
|
|
51746
|
+
const neg2 = jtype === 1 ? 0 : 1;
|
|
50903
51747
|
const nodd = numtaps % 2;
|
|
50904
51748
|
let nfcns = Math.floor(numtaps / 2);
|
|
50905
|
-
if (nodd === 1 &&
|
|
51749
|
+
if (nodd === 1 && neg2 === 0) nfcns += 1;
|
|
50906
51750
|
const des = new Array(wrksize + 2).fill(0);
|
|
50907
51751
|
const grid = new Array(wrksize + 2).fill(0);
|
|
50908
51752
|
const wt = new Array(wrksize + 2).fill(0);
|
|
@@ -50911,7 +51755,7 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
|
|
|
50911
51755
|
let delf = gridDensity * nfcns;
|
|
50912
51756
|
delf = 0.5 / delf;
|
|
50913
51757
|
grid[1] = edge[1];
|
|
50914
|
-
if (
|
|
51758
|
+
if (neg2 !== 0 && edge[1] < delf) grid[1] = delf;
|
|
50915
51759
|
let j = 1;
|
|
50916
51760
|
let l = 1;
|
|
50917
51761
|
let lband = 1;
|
|
@@ -50934,10 +51778,10 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
|
|
|
50934
51778
|
grid[j] = edge[l];
|
|
50935
51779
|
}
|
|
50936
51780
|
let ngrid = j - 1;
|
|
50937
|
-
if (
|
|
51781
|
+
if (neg2 === nodd && grid[ngrid] > 0.5 - delf) --ngrid;
|
|
50938
51782
|
if (ngrid < nfcns + 1)
|
|
50939
51783
|
throw new Error("remez: band too narrow for the requested numtaps (grid underflow)");
|
|
50940
|
-
if (
|
|
51784
|
+
if (neg2 <= 0) {
|
|
50941
51785
|
if (nodd !== 1) {
|
|
50942
51786
|
for (j = 1; j <= ngrid; j++) {
|
|
50943
51787
|
const change = Math.cos(PI * grid[j]);
|
|
@@ -50968,7 +51812,7 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
|
|
|
50968
51812
|
const h = new Array(numtaps + 1).fill(0);
|
|
50969
51813
|
const nz = nfcns + 1;
|
|
50970
51814
|
const nm1 = nfcns - 1;
|
|
50971
|
-
if (
|
|
51815
|
+
if (neg2 <= 0) {
|
|
50972
51816
|
if (nodd !== 0) {
|
|
50973
51817
|
for (j = 1; j <= nm1; j++) h[j] = 0.5 * alpha[nz - j];
|
|
50974
51818
|
h[nfcns] = alpha[1];
|
|
@@ -50992,9 +51836,9 @@ function remezExchange(numtaps, bands, desired, weight, type = "bandpass", maxit
|
|
|
50992
51836
|
}
|
|
50993
51837
|
for (j = 1; j <= nfcns; j++) {
|
|
50994
51838
|
const k = numtaps + 1 - j;
|
|
50995
|
-
h[k] =
|
|
51839
|
+
h[k] = neg2 === 0 ? h[j] : -h[j];
|
|
50996
51840
|
}
|
|
50997
|
-
if (
|
|
51841
|
+
if (neg2 === 1 && nodd === 1) h[nz] = 0;
|
|
50998
51842
|
return h.slice(1);
|
|
50999
51843
|
}
|
|
51000
51844
|
|
|
@@ -51729,10 +52573,10 @@ function setDisjoint(a, b) {
|
|
|
51729
52573
|
|
|
51730
52574
|
// src/geometry/intersect3d.ts
|
|
51731
52575
|
var EPS3 = 1e-12;
|
|
51732
|
-
function
|
|
52576
|
+
function sub2(a, b) {
|
|
51733
52577
|
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
51734
52578
|
}
|
|
51735
|
-
function
|
|
52579
|
+
function add4(a, b) {
|
|
51736
52580
|
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
51737
52581
|
}
|
|
51738
52582
|
function scale3(a, s) {
|
|
@@ -51745,13 +52589,13 @@ function cross2(a, b) {
|
|
|
51745
52589
|
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
52590
|
}
|
|
51747
52591
|
function rayTriangleIntersect(origin, dir, v0, v1, v2) {
|
|
51748
|
-
const e1 =
|
|
51749
|
-
const e2 =
|
|
52592
|
+
const e1 = sub2(v1, v0);
|
|
52593
|
+
const e2 = sub2(v2, v0);
|
|
51750
52594
|
const pvec = cross2(dir, e2);
|
|
51751
52595
|
const det2 = dot7(e1, pvec);
|
|
51752
52596
|
if (Math.abs(det2) < EPS3) return null;
|
|
51753
52597
|
const invDet = 1 / det2;
|
|
51754
|
-
const tvec =
|
|
52598
|
+
const tvec = sub2(origin, v0);
|
|
51755
52599
|
const u = dot7(tvec, pvec) * invDet;
|
|
51756
52600
|
if (u < 0 || u > 1) return null;
|
|
51757
52601
|
const qvec = cross2(tvec, e1);
|
|
@@ -51759,21 +52603,21 @@ function rayTriangleIntersect(origin, dir, v0, v1, v2) {
|
|
|
51759
52603
|
if (v < 0 || u + v > 1) return null;
|
|
51760
52604
|
const t = dot7(e2, qvec) * invDet;
|
|
51761
52605
|
if (t < 0) return null;
|
|
51762
|
-
return { point:
|
|
52606
|
+
return { point: add4(origin, scale3(dir, t)), t };
|
|
51763
52607
|
}
|
|
51764
52608
|
function rayPlaneIntersect(origin, dir, planePoint, planeNormal) {
|
|
51765
52609
|
const denom = dot7(dir, planeNormal);
|
|
51766
52610
|
if (Math.abs(denom) < EPS3) return null;
|
|
51767
|
-
const t = dot7(
|
|
51768
|
-
return { point:
|
|
52611
|
+
const t = dot7(sub2(planePoint, origin), planeNormal) / denom;
|
|
52612
|
+
return { point: add4(origin, scale3(dir, t)), t };
|
|
51769
52613
|
}
|
|
51770
52614
|
function clamp01(x) {
|
|
51771
52615
|
return x < 0 ? 0 : x > 1 ? 1 : x;
|
|
51772
52616
|
}
|
|
51773
52617
|
function segmentSegmentClosest(p1, p2, q1, q2) {
|
|
51774
|
-
const d1 =
|
|
51775
|
-
const d2 =
|
|
51776
|
-
const r =
|
|
52618
|
+
const d1 = sub2(p2, p1);
|
|
52619
|
+
const d2 = sub2(q2, q1);
|
|
52620
|
+
const r = sub2(p1, q1);
|
|
51777
52621
|
const a = dot7(d1, d1);
|
|
51778
52622
|
const e = dot7(d2, d2);
|
|
51779
52623
|
const f = dot7(d2, r);
|
|
@@ -51804,9 +52648,9 @@ function segmentSegmentClosest(p1, p2, q1, q2) {
|
|
|
51804
52648
|
}
|
|
51805
52649
|
}
|
|
51806
52650
|
}
|
|
51807
|
-
const point1 =
|
|
51808
|
-
const point2 =
|
|
51809
|
-
const distance2 = Math.sqrt(dot7(
|
|
52651
|
+
const point1 = add4(p1, scale3(d1, s));
|
|
52652
|
+
const point2 = add4(q1, scale3(d2, t));
|
|
52653
|
+
const distance2 = Math.sqrt(dot7(sub2(point1, point2), sub2(point1, point2)));
|
|
51810
52654
|
return { point1, point2, distance: distance2 };
|
|
51811
52655
|
}
|
|
51812
52656
|
|
|
@@ -51979,7 +52823,7 @@ function alphaShape(points, alpha) {
|
|
|
51979
52823
|
}
|
|
51980
52824
|
|
|
51981
52825
|
// src/geometry/spherical-voronoi.ts
|
|
51982
|
-
function
|
|
52826
|
+
function sub3(a, b) {
|
|
51983
52827
|
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
51984
52828
|
}
|
|
51985
52829
|
function cross3(a, b) {
|
|
@@ -52013,7 +52857,7 @@ function sphericalVoronoi(points, radius = 1, center3 = [0, 0, 0]) {
|
|
|
52013
52857
|
if (points[0].length !== 3) {
|
|
52014
52858
|
throw new Error("sphericalVoronoi: only 3-D point sets are supported");
|
|
52015
52859
|
}
|
|
52016
|
-
const gen = points.map((p) => normalize2(
|
|
52860
|
+
const gen = points.map((p) => normalize2(sub3(p, center3)));
|
|
52017
52861
|
const faces = convexHull3D(points);
|
|
52018
52862
|
const vertices = [];
|
|
52019
52863
|
const vertDir = [];
|
|
@@ -52022,7 +52866,7 @@ function sphericalVoronoi(points, radius = 1, center3 = [0, 0, 0]) {
|
|
|
52022
52866
|
const a = gen[f[0]];
|
|
52023
52867
|
const b = gen[f[1]];
|
|
52024
52868
|
const c = gen[f[2]];
|
|
52025
|
-
let nrm = cross3(
|
|
52869
|
+
let nrm = cross3(sub3(b, a), sub3(c, a));
|
|
52026
52870
|
if (dot8(nrm, a) < 0) nrm = [-nrm[0], -nrm[1], -nrm[2]];
|
|
52027
52871
|
const dir = normalize2(nrm);
|
|
52028
52872
|
vertDir.push(dir);
|
|
@@ -52042,7 +52886,7 @@ function sphericalVoronoi(points, radius = 1, center3 = [0, 0, 0]) {
|
|
|
52042
52886
|
const withAngle = facs.map((fi) => {
|
|
52043
52887
|
const d = vertDir[fi];
|
|
52044
52888
|
const tang = normalize2(
|
|
52045
|
-
|
|
52889
|
+
sub3(d, [gdir[0] * dot8(d, gdir), gdir[1] * dot8(d, gdir), gdir[2] * dot8(d, gdir)])
|
|
52046
52890
|
);
|
|
52047
52891
|
if (ref === null) {
|
|
52048
52892
|
ref = tang;
|
|
@@ -53434,14 +54278,14 @@ function graphColoring(adj) {
|
|
|
53434
54278
|
const n = adj.length;
|
|
53435
54279
|
const colors = new Array(n).fill(-1);
|
|
53436
54280
|
if (n === 0) return colors;
|
|
53437
|
-
const
|
|
54281
|
+
const degree3 = new Array(n).fill(0);
|
|
53438
54282
|
for (let i = 0; i < n; i++) {
|
|
53439
54283
|
for (let j = 0; j < n; j++) {
|
|
53440
|
-
if (i !== j && _undirectedEdgeExists(adj, i, j))
|
|
54284
|
+
if (i !== j && _undirectedEdgeExists(adj, i, j)) degree3[i]++;
|
|
53441
54285
|
}
|
|
53442
54286
|
}
|
|
53443
54287
|
const order = Array.from({ length: n }, (_, i) => i).sort(
|
|
53444
|
-
(a, b) =>
|
|
54288
|
+
(a, b) => degree3[b] - degree3[a] || a - b
|
|
53445
54289
|
);
|
|
53446
54290
|
for (const v of order) {
|
|
53447
54291
|
const usedByNeighbor = /* @__PURE__ */ new Set();
|
|
@@ -54305,7 +55149,7 @@ export {
|
|
|
54305
55149
|
coherence,
|
|
54306
55150
|
collect,
|
|
54307
55151
|
column,
|
|
54308
|
-
combinations,
|
|
55152
|
+
combinations2 as combinations,
|
|
54309
55153
|
combinationsGen,
|
|
54310
55154
|
combinationsWithRep,
|
|
54311
55155
|
combine,
|
|
@@ -54381,10 +55225,10 @@ export {
|
|
|
54381
55225
|
decimate,
|
|
54382
55226
|
deconvolve,
|
|
54383
55227
|
deepEqual,
|
|
54384
|
-
degree,
|
|
55228
|
+
degree2 as degree,
|
|
54385
55229
|
delaunay,
|
|
54386
55230
|
delaunayTriangulation,
|
|
54387
|
-
derivative,
|
|
55231
|
+
derivative2 as derivative,
|
|
54388
55232
|
derivativeAt,
|
|
54389
55233
|
describe,
|
|
54390
55234
|
det,
|
|
@@ -54684,8 +55528,8 @@ export {
|
|
|
54684
55528
|
isNegative,
|
|
54685
55529
|
isNumeric,
|
|
54686
55530
|
isPositive,
|
|
54687
|
-
isPrime,
|
|
54688
|
-
isZero,
|
|
55531
|
+
isPrime2 as isPrime,
|
|
55532
|
+
isZero2 as isZero,
|
|
54689
55533
|
istft,
|
|
54690
55534
|
jacobiCN,
|
|
54691
55535
|
jacobiDN,
|