@danielsimonjr/mathts-functions 0.61.0 → 0.63.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/algebra/derivative.d.ts.map +1 -1
- package/dist/algebra/rationalize.d.ts.map +1 -1
- package/dist/arithmetic/divide.d.ts +1 -1
- package/dist/arithmetic/divide.d.ts.map +1 -1
- package/dist/arithmetic/unaryMinus.d.ts +1 -0
- package/dist/arithmetic/unaryMinus.d.ts.map +1 -1
- package/dist/arithmetic/xgcd.d.ts +15 -0
- package/dist/arithmetic/xgcd.d.ts.map +1 -1
- package/dist/bitwise/rightLogShift.d.ts.map +1 -1
- package/dist/complex/arg.d.ts.map +1 -1
- package/dist/core/create.d.ts.map +1 -1
- package/dist/core/function/import.d.ts.map +1 -1
- package/dist/core/function/typed.d.ts.map +1 -1
- package/dist/factories/index.d.ts +5 -5
- package/dist/factories/index.d.ts.map +1 -1
- package/dist/geometry/intersect.d.ts +0 -4
- package/dist/geometry/intersect.d.ts.map +1 -1
- package/dist/index.js +579 -345
- package/dist/matrix/concat.d.ts.map +1 -1
- package/dist/matrix/matrixFromColumns.d.ts +7 -1
- package/dist/matrix/matrixFromColumns.d.ts.map +1 -1
- package/dist/matrix/matrixFromRows.d.ts +7 -1
- package/dist/matrix/matrixFromRows.d.ts.map +1 -1
- package/dist/probability/permutations.d.ts.map +1 -1
- package/dist/probability/random.d.ts.map +1 -1
- package/dist/statistics/cumsum.d.ts.map +1 -1
- package/dist/statistics/median.d.ts +1 -0
- package/dist/statistics/median.d.ts.map +1 -1
- package/dist/statistics/prod.d.ts.map +1 -1
- package/dist/type/matrix/utils/matAlgo03xDSf.d.ts.map +1 -1
- package/dist/type/matrix/utils/matAlgo11xS0s.d.ts.map +1 -1
- package/dist/typed/arithmetic.d.ts.map +1 -1
- package/dist/typed/cas.d.ts +7 -28
- package/dist/typed/cas.d.ts.map +1 -1
- package/dist/typed/factorization/multi-poly.d.ts +0 -6
- package/dist/typed/factorization/multi-poly.d.ts.map +1 -1
- package/dist/typed/graph.d.ts.map +1 -1
- package/dist/typed/polynomial-ideal.d.ts +12 -1
- package/dist/typed/polynomial-ideal.d.ts.map +1 -1
- package/dist/utils/bignumber/bitwise.d.ts +22 -0
- package/dist/utils/bignumber/bitwise.d.ts.map +1 -1
- package/dist/utils/parseNumber.d.ts +2 -2
- package/dist/utils/parseNumber.d.ts.map +1 -1
- package/package.json +76 -76
package/dist/index.js
CHANGED
|
@@ -2039,6 +2039,28 @@ var xgcd = mathTyped2("xgcd", {
|
|
|
2039
2039
|
[y, lastY] = [lastY - q * y, y];
|
|
2040
2040
|
}
|
|
2041
2041
|
return a < 0n ? [-a, -lastX, -lastY] : [a, lastX, lastY];
|
|
2042
|
+
},
|
|
2043
|
+
"Fraction, Fraction": (a, b) => {
|
|
2044
|
+
if (!a.isInteger() || !b.isInteger()) {
|
|
2045
|
+
throw new Error("Parameters in function xgcd must be integer numbers");
|
|
2046
|
+
}
|
|
2047
|
+
const zero = new Fraction(0n, 1n);
|
|
2048
|
+
const one = new Fraction(1n, 1n);
|
|
2049
|
+
let x = zero, lastX = one;
|
|
2050
|
+
let y = one, lastY = zero;
|
|
2051
|
+
while (!b.isZero()) {
|
|
2052
|
+
const q = a.divide(b).floor();
|
|
2053
|
+
const r = a.mod(b);
|
|
2054
|
+
const nextX = lastX.subtract(q.multiply(x));
|
|
2055
|
+
const nextY = lastY.subtract(q.multiply(y));
|
|
2056
|
+
lastX = x;
|
|
2057
|
+
x = nextX;
|
|
2058
|
+
lastY = y;
|
|
2059
|
+
y = nextY;
|
|
2060
|
+
a = b;
|
|
2061
|
+
b = r;
|
|
2062
|
+
}
|
|
2063
|
+
return a.lessThan(zero) ? [a.negate(), lastX.negate(), lastY.negate()] : [a, !a.isZero() ? lastX : zero, lastY];
|
|
2042
2064
|
}
|
|
2043
2065
|
});
|
|
2044
2066
|
function is2DArray(arr10) {
|
|
@@ -9587,13 +9609,23 @@ function normalize(p) {
|
|
|
9587
9609
|
if (existing) existing.coeff += t.coeff;
|
|
9588
9610
|
else byKey.set(key2, { coeff: t.coeff, powers: [...t.powers] });
|
|
9589
9611
|
}
|
|
9590
|
-
|
|
9612
|
+
const out = [];
|
|
9613
|
+
for (const t of byKey.values()) {
|
|
9614
|
+
if (Math.abs(t.coeff) > EPS) {
|
|
9615
|
+
out.push(t);
|
|
9616
|
+
}
|
|
9617
|
+
}
|
|
9618
|
+
return out.sort((a, b) => cmpPowers(b.powers, a.powers));
|
|
9591
9619
|
}
|
|
9592
9620
|
function polyAdd(a, b) {
|
|
9593
9621
|
return normalize([...a, ...b]);
|
|
9594
9622
|
}
|
|
9595
9623
|
function polyNeg(a) {
|
|
9596
|
-
|
|
9624
|
+
const out = [];
|
|
9625
|
+
for (let i = 0; i < a.length; i++) {
|
|
9626
|
+
out.push({ coeff: -a[i].coeff, powers: [...a[i].powers] });
|
|
9627
|
+
}
|
|
9628
|
+
return out;
|
|
9597
9629
|
}
|
|
9598
9630
|
function polySub(a, b) {
|
|
9599
9631
|
return polyAdd(a, polyNeg(b));
|
|
@@ -9602,9 +9634,13 @@ function polyMul(a, b) {
|
|
|
9602
9634
|
const out = [];
|
|
9603
9635
|
for (const ta of a) {
|
|
9604
9636
|
for (const tb of b) {
|
|
9637
|
+
const powers = new Array(ta.powers.length);
|
|
9638
|
+
for (let i = 0; i < ta.powers.length; i++) {
|
|
9639
|
+
powers[i] = ta.powers[i] + tb.powers[i];
|
|
9640
|
+
}
|
|
9605
9641
|
out.push({
|
|
9606
9642
|
coeff: ta.coeff * tb.coeff,
|
|
9607
|
-
powers
|
|
9643
|
+
powers
|
|
9608
9644
|
});
|
|
9609
9645
|
}
|
|
9610
9646
|
}
|
|
@@ -9617,12 +9653,24 @@ function polyPow(a, n, nVars) {
|
|
|
9617
9653
|
}
|
|
9618
9654
|
function polyFromExpression(expr, vars) {
|
|
9619
9655
|
const nVars = vars.length;
|
|
9620
|
-
const varIndex = new Map(
|
|
9656
|
+
const varIndex = /* @__PURE__ */ new Map();
|
|
9657
|
+
for (let i = 0; i < vars.length; i++) {
|
|
9658
|
+
varIndex.set(vars[i], i);
|
|
9659
|
+
}
|
|
9621
9660
|
let pos = 0;
|
|
9622
9661
|
const constPoly = (v) => normalize([{ coeff: v, powers: new Array(nVars).fill(0) }]);
|
|
9623
9662
|
function constOf(p) {
|
|
9624
9663
|
if (p.length === 0) return 0;
|
|
9625
|
-
if (p.length === 1
|
|
9664
|
+
if (p.length === 1) {
|
|
9665
|
+
let isConst2 = true;
|
|
9666
|
+
for (let i = 0; i < p[0].powers.length; i++) {
|
|
9667
|
+
if (p[0].powers[i] !== 0) {
|
|
9668
|
+
isConst2 = false;
|
|
9669
|
+
break;
|
|
9670
|
+
}
|
|
9671
|
+
}
|
|
9672
|
+
if (isConst2) return p[0].coeff;
|
|
9673
|
+
}
|
|
9626
9674
|
return null;
|
|
9627
9675
|
}
|
|
9628
9676
|
const skipWs = () => {
|
|
@@ -9705,7 +9753,11 @@ function polyFromExpression(expr, vars) {
|
|
|
9705
9753
|
if (denom === null || Math.abs(denom) <= EPS) {
|
|
9706
9754
|
return fail("division only by a nonzero numeric constant");
|
|
9707
9755
|
}
|
|
9708
|
-
|
|
9756
|
+
const nextP = [];
|
|
9757
|
+
for (let i = 0; i < p.length; i++) {
|
|
9758
|
+
nextP.push({ coeff: p[i].coeff / denom, powers: p[i].powers });
|
|
9759
|
+
}
|
|
9760
|
+
p = normalize(nextP);
|
|
9709
9761
|
} else {
|
|
9710
9762
|
break;
|
|
9711
9763
|
}
|
|
@@ -9734,23 +9786,64 @@ function polyFromExpression(expr, vars) {
|
|
|
9734
9786
|
return result;
|
|
9735
9787
|
}
|
|
9736
9788
|
function divides(a, b) {
|
|
9737
|
-
|
|
9789
|
+
for (let i = 0; i < a.length; i++) {
|
|
9790
|
+
if (a[i] > b[i]) return false;
|
|
9791
|
+
}
|
|
9792
|
+
return true;
|
|
9738
9793
|
}
|
|
9794
|
+
function totalDegree(powers) {
|
|
9795
|
+
let sum3 = 0;
|
|
9796
|
+
for (let i = 0; i < powers.length; i++) sum3 += powers[i];
|
|
9797
|
+
return sum3;
|
|
9798
|
+
}
|
|
9799
|
+
var DivisorGeobucket = class {
|
|
9800
|
+
buckets = [];
|
|
9801
|
+
maxDeg = 0;
|
|
9802
|
+
constructor(polys) {
|
|
9803
|
+
for (const p of polys) this.insert(p);
|
|
9804
|
+
}
|
|
9805
|
+
insert(poly) {
|
|
9806
|
+
if (poly.length === 0) return;
|
|
9807
|
+
const d = totalDegree(poly[0].powers);
|
|
9808
|
+
if (!this.buckets[d]) this.buckets[d] = [];
|
|
9809
|
+
this.buckets[d].push(poly);
|
|
9810
|
+
if (d > this.maxDeg) this.maxDeg = d;
|
|
9811
|
+
}
|
|
9812
|
+
find(target) {
|
|
9813
|
+
const d = totalDegree(target);
|
|
9814
|
+
const limit2 = d < this.maxDeg ? d : this.maxDeg;
|
|
9815
|
+
for (let i = 0; i <= limit2; i++) {
|
|
9816
|
+
const bucket = this.buckets[i];
|
|
9817
|
+
if (!bucket) continue;
|
|
9818
|
+
for (let j = 0; j < bucket.length; j++) {
|
|
9819
|
+
if (divides(bucket[j][0].powers, target)) {
|
|
9820
|
+
return bucket[j];
|
|
9821
|
+
}
|
|
9822
|
+
}
|
|
9823
|
+
}
|
|
9824
|
+
return void 0;
|
|
9825
|
+
}
|
|
9826
|
+
};
|
|
9739
9827
|
function polyReduce(p, G) {
|
|
9740
9828
|
const rem = [];
|
|
9741
9829
|
let work = normalize(p);
|
|
9742
9830
|
let guard = 0;
|
|
9831
|
+
const index = Array.isArray(G) ? new DivisorGeobucket(G) : G;
|
|
9743
9832
|
while (work.length > 0) {
|
|
9744
9833
|
if (++guard > 2e4) {
|
|
9745
9834
|
throw new Error("polyReduce: iteration cap exceeded (system too large for this CAS)");
|
|
9746
9835
|
}
|
|
9747
9836
|
const lt = work[0];
|
|
9748
|
-
const g =
|
|
9837
|
+
const g = index.find(lt.powers);
|
|
9749
9838
|
if (g) {
|
|
9839
|
+
const powers = new Array(lt.powers.length);
|
|
9840
|
+
for (let i = 0; i < lt.powers.length; i++) {
|
|
9841
|
+
powers[i] = lt.powers[i] - g[0].powers[i];
|
|
9842
|
+
}
|
|
9750
9843
|
const factor2 = [
|
|
9751
9844
|
{
|
|
9752
9845
|
coeff: lt.coeff / g[0].coeff,
|
|
9753
|
-
powers
|
|
9846
|
+
powers
|
|
9754
9847
|
}
|
|
9755
9848
|
];
|
|
9756
9849
|
work = polySub(work, polyMul(factor2, g));
|
|
@@ -9762,52 +9855,88 @@ function polyReduce(p, G) {
|
|
|
9762
9855
|
return normalize(rem);
|
|
9763
9856
|
}
|
|
9764
9857
|
function lcmPowers(a, b) {
|
|
9765
|
-
|
|
9858
|
+
const len = a.length;
|
|
9859
|
+
const out = new Array(len);
|
|
9860
|
+
for (let i = 0; i < len; i++) {
|
|
9861
|
+
out[i] = Math.max(a[i], b[i]);
|
|
9862
|
+
}
|
|
9863
|
+
return out;
|
|
9766
9864
|
}
|
|
9767
9865
|
function sPoly(f, g) {
|
|
9768
9866
|
const l = lcmPowers(f[0].powers, g[0].powers);
|
|
9769
|
-
const
|
|
9770
|
-
const
|
|
9867
|
+
const mfPowers = new Array(l.length);
|
|
9868
|
+
const mgPowers = new Array(l.length);
|
|
9869
|
+
for (let i = 0; i < l.length; i++) {
|
|
9870
|
+
mfPowers[i] = l[i] - f[0].powers[i];
|
|
9871
|
+
mgPowers[i] = l[i] - g[0].powers[i];
|
|
9872
|
+
}
|
|
9873
|
+
const mf = [{ coeff: 1 / f[0].coeff, powers: mfPowers }];
|
|
9874
|
+
const mg = [{ coeff: 1 / g[0].coeff, powers: mgPowers }];
|
|
9771
9875
|
return polySub(polyMul(mf, f), polyMul(mg, g));
|
|
9772
9876
|
}
|
|
9773
9877
|
function monic(p) {
|
|
9774
9878
|
if (p.length === 0) return p;
|
|
9775
9879
|
const c = p[0].coeff;
|
|
9776
|
-
|
|
9880
|
+
const out = [];
|
|
9881
|
+
for (let i = 0; i < p.length; i++) {
|
|
9882
|
+
out.push({ coeff: p[i].coeff / c, powers: [...p[i].powers] });
|
|
9883
|
+
}
|
|
9884
|
+
return out;
|
|
9777
9885
|
}
|
|
9778
9886
|
function buchberger(input) {
|
|
9779
|
-
let G =
|
|
9887
|
+
let G = [];
|
|
9888
|
+
for (let i = 0; i < input.length; i++) {
|
|
9889
|
+
const p = normalize(input[i]);
|
|
9890
|
+
if (p.length > 0) {
|
|
9891
|
+
G.push(monic(p));
|
|
9892
|
+
}
|
|
9893
|
+
}
|
|
9780
9894
|
if (G.length === 0) return [];
|
|
9781
9895
|
const pairs = [];
|
|
9782
9896
|
for (let i = 0; i < G.length; i++) {
|
|
9783
9897
|
for (let j = i + 1; j < G.length; j++) pairs.push([i, j]);
|
|
9784
9898
|
}
|
|
9785
9899
|
let iter = 0;
|
|
9900
|
+
const index = new DivisorGeobucket(G);
|
|
9786
9901
|
while (pairs.length > 0) {
|
|
9787
9902
|
if (++iter > 2e3 || G.length > 64) {
|
|
9788
9903
|
throw new Error("groebnerBasis: system too large (iteration/basis cap exceeded)");
|
|
9789
9904
|
}
|
|
9790
9905
|
const [i, j] = pairs.shift();
|
|
9791
|
-
const s = polyReduce(sPoly(G[i], G[j]),
|
|
9906
|
+
const s = polyReduce(sPoly(G[i], G[j]), index);
|
|
9792
9907
|
if (s.length > 0) {
|
|
9793
9908
|
const k = G.length;
|
|
9794
|
-
|
|
9909
|
+
const newPoly = monic(s);
|
|
9910
|
+
G.push(newPoly);
|
|
9911
|
+
index.insert(newPoly);
|
|
9795
9912
|
for (let t = 0; t < k; t++) pairs.push([t, k]);
|
|
9796
9913
|
}
|
|
9797
9914
|
}
|
|
9798
|
-
|
|
9799
|
-
|
|
9800
|
-
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9915
|
+
const minimalG = [];
|
|
9916
|
+
for (let i = 0; i < G.length; i++) {
|
|
9917
|
+
const g = G[i];
|
|
9918
|
+
let isDivisible = false;
|
|
9919
|
+
for (let j = 0; j < G.length; j++) {
|
|
9920
|
+
if (i === j) continue;
|
|
9921
|
+
const h = G[j];
|
|
9922
|
+
if (h.length > 0 && divides(h[0].powers, g[0].powers) && (cmpPowers(h[0].powers, g[0].powers) !== 0 || j < i)) {
|
|
9923
|
+
isDivisible = true;
|
|
9924
|
+
break;
|
|
9925
|
+
}
|
|
9926
|
+
}
|
|
9927
|
+
if (!isDivisible) minimalG.push(g);
|
|
9928
|
+
}
|
|
9929
|
+
G = minimalG;
|
|
9930
|
+
const reducedG = [];
|
|
9931
|
+
for (let i = 0; i < G.length; i++) {
|
|
9932
|
+
const others = [];
|
|
9933
|
+
for (let j = 0; j < G.length; j++) {
|
|
9934
|
+
if (i !== j) others.push(G[j]);
|
|
9935
|
+
}
|
|
9936
|
+
const reduced = monic(polyReduce(G[i], others));
|
|
9937
|
+
if (reduced.length > 0) reducedG.push(reduced);
|
|
9938
|
+
}
|
|
9939
|
+
G = reducedG;
|
|
9811
9940
|
G.sort((a, b) => cmpPowers(b[0].powers, a[0].powers));
|
|
9812
9941
|
return G;
|
|
9813
9942
|
}
|
|
@@ -9817,10 +9946,18 @@ function polyToString(p, vars) {
|
|
|
9817
9946
|
const r = Math.round(c);
|
|
9818
9947
|
return Math.abs(c - r) < 1e-9 ? String(r) : String(Number(c.toPrecision(12)));
|
|
9819
9948
|
};
|
|
9820
|
-
const terms = [
|
|
9821
|
-
|
|
9822
|
-
|
|
9823
|
-
|
|
9949
|
+
const terms = [];
|
|
9950
|
+
for (let i = p.length - 1; i >= 0; i--) {
|
|
9951
|
+
const t = p[i];
|
|
9952
|
+
const parts = [];
|
|
9953
|
+
for (let j = 0; j < t.powers.length; j++) {
|
|
9954
|
+
const e = t.powers[j];
|
|
9955
|
+
if (e === 1) parts.push(vars[j]);
|
|
9956
|
+
else if (e > 1) parts.push(`${vars[j]}^${e}`);
|
|
9957
|
+
}
|
|
9958
|
+
const varPart = parts.join("*");
|
|
9959
|
+
terms.push(varPart ? `${fmt(t.coeff)}*${varPart}` : fmt(t.coeff));
|
|
9960
|
+
}
|
|
9824
9961
|
return terms.join(" + ").replace(/\+ -/g, "- ");
|
|
9825
9962
|
}
|
|
9826
9963
|
|
|
@@ -10614,7 +10751,7 @@ function degreeIn(p, varIndex) {
|
|
|
10614
10751
|
}
|
|
10615
10752
|
return d;
|
|
10616
10753
|
}
|
|
10617
|
-
function
|
|
10754
|
+
function totalDegree2(p) {
|
|
10618
10755
|
let d = -1;
|
|
10619
10756
|
for (const k of p.terms.keys()) {
|
|
10620
10757
|
const exps = unkey(k);
|
|
@@ -10900,7 +11037,7 @@ function candidateFor(pool, indices, bases, degBounds, vars) {
|
|
|
10900
11037
|
return null;
|
|
10901
11038
|
}
|
|
10902
11039
|
const cand = primitivePartMP(back);
|
|
10903
|
-
if (
|
|
11040
|
+
if (totalDegree2(cand) < 1) {
|
|
10904
11041
|
return null;
|
|
10905
11042
|
}
|
|
10906
11043
|
return cand;
|
|
@@ -10918,7 +11055,7 @@ function factorMultivariateKronecker(p) {
|
|
|
10918
11055
|
if (p.vars.length < 2) {
|
|
10919
11056
|
return null;
|
|
10920
11057
|
}
|
|
10921
|
-
if (isZero2(p) ||
|
|
11058
|
+
if (isZero2(p) || totalDegree2(p) < 1) {
|
|
10922
11059
|
return null;
|
|
10923
11060
|
}
|
|
10924
11061
|
const cont = integerContentMP(p);
|
|
@@ -10997,7 +11134,7 @@ function factorMultivariateKronecker(p) {
|
|
|
10997
11134
|
const l = leadingTerm(gCur);
|
|
10998
11135
|
const sgn = l !== null && l.coeff < 0n ? -1n : 1n;
|
|
10999
11136
|
constant *= c * sgn;
|
|
11000
|
-
if (
|
|
11137
|
+
if (totalDegree2(gCur) >= 1) {
|
|
11001
11138
|
found.push({ poly: primitivePartMP(gCur), mult: 1 });
|
|
11002
11139
|
}
|
|
11003
11140
|
}
|
|
@@ -17449,6 +17586,8 @@ function _betweennessOnce(adj, directed, normalise, seed) {
|
|
|
17449
17586
|
if (denom > 0) {
|
|
17450
17587
|
for (let i = 0; i < n; i++) cb[i] /= denom;
|
|
17451
17588
|
}
|
|
17589
|
+
} else if (!directed) {
|
|
17590
|
+
for (let i = 0; i < n; i++) cb[i] /= 2;
|
|
17452
17591
|
}
|
|
17453
17592
|
return cb;
|
|
17454
17593
|
}
|
|
@@ -22008,11 +22147,11 @@ var createSubtractScalar = /* @__PURE__ */ factory(
|
|
|
22008
22147
|
|
|
22009
22148
|
// src/arithmetic/unaryMinus.ts
|
|
22010
22149
|
var name14 = "unaryMinus";
|
|
22011
|
-
var dependencies14 = ["typed", "config", "?bignumber"];
|
|
22150
|
+
var dependencies14 = ["typed", "config", "?bignumber", "?fraction"];
|
|
22012
22151
|
var createUnaryMinus = /* @__PURE__ */ factory(
|
|
22013
22152
|
name14,
|
|
22014
22153
|
dependencies14,
|
|
22015
|
-
({ typed: typed3, config: config2, bignumber: bignumber2 }) => {
|
|
22154
|
+
({ typed: typed3, config: config2, bignumber: bignumber2, fraction: fraction2 }) => {
|
|
22016
22155
|
return typed3(name14, {
|
|
22017
22156
|
number: unaryMinusNumber,
|
|
22018
22157
|
"Complex | BigNumber | Fraction": (x) => x.neg(),
|
|
@@ -22035,7 +22174,10 @@ var createUnaryMinus = /* @__PURE__ */ factory(
|
|
|
22035
22174
|
case "bigint":
|
|
22036
22175
|
return BigInt(negValue);
|
|
22037
22176
|
case "Fraction":
|
|
22038
|
-
|
|
22177
|
+
if (!fraction2) {
|
|
22178
|
+
throw new Error("Fraction not available. Configure mathjs with Fraction support.");
|
|
22179
|
+
}
|
|
22180
|
+
return fraction2(negValue);
|
|
22039
22181
|
case "number":
|
|
22040
22182
|
default:
|
|
22041
22183
|
return negValue;
|
|
@@ -22316,6 +22458,36 @@ function rightArithShiftBigNumber(x, y) {
|
|
|
22316
22458
|
}
|
|
22317
22459
|
return x.div(new BigNumber9(2).pow(y)).floor();
|
|
22318
22460
|
}
|
|
22461
|
+
function rightLogShiftBigNumber(x, y) {
|
|
22462
|
+
if (x.isFinite() && !x.isInteger() || y.isFinite() && !y.isInteger()) {
|
|
22463
|
+
throw new Error("Integers expected in function rightLogShift");
|
|
22464
|
+
}
|
|
22465
|
+
const BigNumber9 = x.constructor;
|
|
22466
|
+
if (x.isNaN() || y.isNaN() || y.isNegative() && !y.isZero()) {
|
|
22467
|
+
return new BigNumber9(NaN);
|
|
22468
|
+
}
|
|
22469
|
+
if (x.isZero() || y.isZero()) {
|
|
22470
|
+
return x;
|
|
22471
|
+
}
|
|
22472
|
+
if (!y.isFinite()) {
|
|
22473
|
+
if (x.isNegative() || !x.isFinite()) {
|
|
22474
|
+
return new BigNumber9(NaN);
|
|
22475
|
+
}
|
|
22476
|
+
return new BigNumber9(0);
|
|
22477
|
+
}
|
|
22478
|
+
let val = x;
|
|
22479
|
+
if (val.isNegative()) {
|
|
22480
|
+
const MASK = new BigNumber9(4294967296);
|
|
22481
|
+
val = val.mod(MASK);
|
|
22482
|
+
if (val.isNegative()) {
|
|
22483
|
+
val = val.plus(MASK);
|
|
22484
|
+
}
|
|
22485
|
+
}
|
|
22486
|
+
if (y.lt(55)) {
|
|
22487
|
+
return val.div(Math.pow(2, y.toNumber()) + "").floor();
|
|
22488
|
+
}
|
|
22489
|
+
return val.div(new BigNumber9(2).pow(y)).floor();
|
|
22490
|
+
}
|
|
22319
22491
|
|
|
22320
22492
|
// src/bitwise/bitNot.ts
|
|
22321
22493
|
var name15 = "bitNot";
|
|
@@ -22352,7 +22524,6 @@ var createArg = /* @__PURE__ */ factory(
|
|
|
22352
22524
|
Complex: function(x) {
|
|
22353
22525
|
return x.arg();
|
|
22354
22526
|
},
|
|
22355
|
-
// TODO: implement BigNumber support for function arg
|
|
22356
22527
|
"Array | Matrix": typed3.referToSelf(
|
|
22357
22528
|
(self) => (x) => deepMap(x, self)
|
|
22358
22529
|
)
|
|
@@ -23194,26 +23365,36 @@ function randomMatrix(size2, random3) {
|
|
|
23194
23365
|
// src/probability/random.ts
|
|
23195
23366
|
var name32 = "random";
|
|
23196
23367
|
var dependencies32 = ["typed", "config", "?on"];
|
|
23368
|
+
function _createRng(config2, on) {
|
|
23369
|
+
let rng = createRng(config2.randomSeed);
|
|
23370
|
+
if (on) {
|
|
23371
|
+
on("config", function(curr, prev) {
|
|
23372
|
+
if (curr.randomSeed !== prev.randomSeed) {
|
|
23373
|
+
rng = createRng(curr.randomSeed);
|
|
23374
|
+
}
|
|
23375
|
+
});
|
|
23376
|
+
}
|
|
23377
|
+
return () => rng();
|
|
23378
|
+
}
|
|
23379
|
+
function _createRandomSignatures(rng) {
|
|
23380
|
+
function _random(min2, max2) {
|
|
23381
|
+
return min2 + rng() * (max2 - min2);
|
|
23382
|
+
}
|
|
23383
|
+
return {
|
|
23384
|
+
_random,
|
|
23385
|
+
signatures: {
|
|
23386
|
+
"": () => _random(0, 1),
|
|
23387
|
+
number: (max2) => _random(0, max2),
|
|
23388
|
+
"number, number": (min2, max2) => _random(min2, max2)
|
|
23389
|
+
}
|
|
23390
|
+
};
|
|
23391
|
+
}
|
|
23197
23392
|
var createRandom = /* @__PURE__ */ factory(
|
|
23198
23393
|
name32,
|
|
23199
23394
|
dependencies32,
|
|
23200
23395
|
({ typed: typed3, config: config2, on }) => {
|
|
23201
|
-
|
|
23202
|
-
|
|
23203
|
-
on("config", function(curr, prev) {
|
|
23204
|
-
if (curr.randomSeed !== prev.randomSeed) {
|
|
23205
|
-
rng = createRng(curr.randomSeed);
|
|
23206
|
-
}
|
|
23207
|
-
});
|
|
23208
|
-
}
|
|
23209
|
-
return typed3(name32, {
|
|
23210
|
-
"": () => _random(0, 1),
|
|
23211
|
-
number: (max2) => _random(0, max2),
|
|
23212
|
-
"number, number": (min2, max2) => _random(min2, max2),
|
|
23213
|
-
"Array | Matrix": (size2) => _randomMatrix(size2, 0, 1),
|
|
23214
|
-
"Array | Matrix, number": (size2, max2) => _randomMatrix(size2, 0, max2),
|
|
23215
|
-
"Array | Matrix, number, number": (size2, min2, max2) => _randomMatrix(size2, min2, max2)
|
|
23216
|
-
});
|
|
23396
|
+
const rng = _createRng(config2, on);
|
|
23397
|
+
const { _random, signatures } = _createRandomSignatures(rng);
|
|
23217
23398
|
function _randomMatrix(size2, min2, max2) {
|
|
23218
23399
|
const res = randomMatrix(
|
|
23219
23400
|
size2.valueOf(),
|
|
@@ -23221,9 +23402,12 @@ var createRandom = /* @__PURE__ */ factory(
|
|
|
23221
23402
|
);
|
|
23222
23403
|
return isMatrix(size2) ? size2.create(res, "number") : res;
|
|
23223
23404
|
}
|
|
23224
|
-
|
|
23225
|
-
|
|
23226
|
-
|
|
23405
|
+
return typed3(name32, {
|
|
23406
|
+
...signatures,
|
|
23407
|
+
"Array | Matrix": (size2) => _randomMatrix(size2, 0, 1),
|
|
23408
|
+
"Array | Matrix, number": (size2, max2) => _randomMatrix(size2, 0, max2),
|
|
23409
|
+
"Array | Matrix, number, number": (size2, min2, max2) => _randomMatrix(size2, min2, max2)
|
|
23410
|
+
});
|
|
23227
23411
|
}
|
|
23228
23412
|
);
|
|
23229
23413
|
|
|
@@ -24655,9 +24839,7 @@ var createProd = /* @__PURE__ */ factory(
|
|
|
24655
24839
|
// prod([a, b, c, d, ...])
|
|
24656
24840
|
"Array | Matrix": _prod,
|
|
24657
24841
|
// prod([a, b, c, d, ...], dim)
|
|
24658
|
-
"Array | Matrix, number | BigNumber":
|
|
24659
|
-
throw new Error("prod(A, dim) is not yet supported");
|
|
24660
|
-
},
|
|
24842
|
+
"Array | Matrix, number | BigNumber": _nprodDim,
|
|
24661
24843
|
// prod(a, b, c, d, ...)
|
|
24662
24844
|
"...": function(args) {
|
|
24663
24845
|
return _prod(args);
|
|
@@ -24694,6 +24876,15 @@ var createProd = /* @__PURE__ */ factory(
|
|
|
24694
24876
|
}
|
|
24695
24877
|
return prod2;
|
|
24696
24878
|
}
|
|
24879
|
+
function _nprodDim(array, dim) {
|
|
24880
|
+
try {
|
|
24881
|
+
const dimValue = typeof dim === "number" ? dim : dim.valueOf();
|
|
24882
|
+
const prod2 = reduce2(array, dimValue, multiplyScalar2);
|
|
24883
|
+
return prod2;
|
|
24884
|
+
} catch (err) {
|
|
24885
|
+
throw improveErrorMessage(err, "prod", void 0);
|
|
24886
|
+
}
|
|
24887
|
+
}
|
|
24697
24888
|
}
|
|
24698
24889
|
);
|
|
24699
24890
|
|
|
@@ -24806,11 +24997,11 @@ var createIsZero = /* @__PURE__ */ factory(
|
|
|
24806
24997
|
|
|
24807
24998
|
// src/utils/parseNumber.ts
|
|
24808
24999
|
var name83 = "parseNumberWithConfig";
|
|
24809
|
-
var dependencies83 = ["config", "?bignumber"];
|
|
25000
|
+
var dependencies83 = ["config", "?bignumber", "?fraction"];
|
|
24810
25001
|
var createParseNumberWithConfig = /* @__PURE__ */ factory(
|
|
24811
25002
|
name83,
|
|
24812
25003
|
dependencies83,
|
|
24813
|
-
({ config: config2, bignumber: bignumber2 }) => {
|
|
25004
|
+
({ config: config2, bignumber: bignumber2, fraction: fraction2 }) => {
|
|
24814
25005
|
function parseNumberWithConfig2(str) {
|
|
24815
25006
|
if (typeof str !== "string") {
|
|
24816
25007
|
throw new TypeError(`parseNumberWithConfig expects string, got ${typeof str}`);
|
|
@@ -24836,11 +25027,10 @@ var createParseNumberWithConfig = /* @__PURE__ */ factory(
|
|
|
24836
25027
|
throw new SyntaxError(`String "${str}" is not a valid number`);
|
|
24837
25028
|
}
|
|
24838
25029
|
case "Fraction": {
|
|
24839
|
-
|
|
24840
|
-
|
|
24841
|
-
throw new SyntaxError(`String "${str}" is not a valid number`);
|
|
25030
|
+
if (!fraction2) {
|
|
25031
|
+
throw new Error("Fraction not available. Configure mathjs with Fraction support.");
|
|
24842
25032
|
}
|
|
24843
|
-
return
|
|
25033
|
+
return fraction2(str);
|
|
24844
25034
|
}
|
|
24845
25035
|
case "number":
|
|
24846
25036
|
default: {
|
|
@@ -25451,17 +25641,79 @@ var createMatrixFromColumns = /* @__PURE__ */ factory(
|
|
|
25451
25641
|
(item) => typeof item.toArray === "function"
|
|
25452
25642
|
);
|
|
25453
25643
|
const hasArray = arr10.some((item) => Array.isArray(item));
|
|
25644
|
+
const isSparse = allMatrix && !hasArray && arr10.some(
|
|
25645
|
+
(item) => typeof item.storage === "function" && item.storage() === "sparse"
|
|
25646
|
+
);
|
|
25647
|
+
if (isSparse) {
|
|
25648
|
+
return _createSparseMatrixFromColumns(arr10);
|
|
25649
|
+
}
|
|
25454
25650
|
const arrays = arr10.map(
|
|
25455
25651
|
(item) => typeof item.toArray === "function" ? item.toArray() : item
|
|
25456
25652
|
);
|
|
25457
25653
|
const result = _createArray(arrays);
|
|
25458
25654
|
if (allMatrix && !hasArray) {
|
|
25459
|
-
return matrix2(result);
|
|
25655
|
+
return matrix2(result, "dense");
|
|
25460
25656
|
}
|
|
25461
25657
|
return result;
|
|
25462
25658
|
}
|
|
25463
|
-
// TODO implement this properly for SparseMatrix
|
|
25464
25659
|
});
|
|
25660
|
+
function _createSparseMatrixFromColumns(arr10) {
|
|
25661
|
+
const M = arr10.length;
|
|
25662
|
+
const N2 = checkVectorTypeAndReturnLength(arr10[0]);
|
|
25663
|
+
const entries = [];
|
|
25664
|
+
for (let j = 0; j < M; j++) {
|
|
25665
|
+
const colVec = arr10[j];
|
|
25666
|
+
const colLength = checkVectorTypeAndReturnLength(colVec);
|
|
25667
|
+
if (colLength !== N2) {
|
|
25668
|
+
throw new TypeError(
|
|
25669
|
+
"The vectors had different length: " + (N2 | 0) + " \u2260 " + (colLength | 0)
|
|
25670
|
+
);
|
|
25671
|
+
}
|
|
25672
|
+
if (typeof colVec.forEach === "function") {
|
|
25673
|
+
const s = size2(colVec);
|
|
25674
|
+
const is1D = s.length === 1;
|
|
25675
|
+
const isCol = s.length === 2 && s[1] === 1;
|
|
25676
|
+
colVec.forEach((val, idx) => {
|
|
25677
|
+
let row2;
|
|
25678
|
+
if (is1D) {
|
|
25679
|
+
row2 = idx[0];
|
|
25680
|
+
} else if (isCol) {
|
|
25681
|
+
row2 = idx[0];
|
|
25682
|
+
} else {
|
|
25683
|
+
row2 = idx[1];
|
|
25684
|
+
}
|
|
25685
|
+
if (val !== 0) {
|
|
25686
|
+
entries.push({ row: row2, col: j, value: val });
|
|
25687
|
+
}
|
|
25688
|
+
});
|
|
25689
|
+
} else {
|
|
25690
|
+
const f = flatten5(colVec);
|
|
25691
|
+
for (let i = 0; i < N2; i++) {
|
|
25692
|
+
if (f[i] !== 0) {
|
|
25693
|
+
entries.push({ row: i, col: j, value: f[i] });
|
|
25694
|
+
}
|
|
25695
|
+
}
|
|
25696
|
+
}
|
|
25697
|
+
}
|
|
25698
|
+
entries.sort((a, b) => {
|
|
25699
|
+
if (a.col !== b.col) return a.col - b.col;
|
|
25700
|
+
return a.row - b.row;
|
|
25701
|
+
});
|
|
25702
|
+
const values = [];
|
|
25703
|
+
const index = [];
|
|
25704
|
+
const ptr = new Array(M + 1).fill(0);
|
|
25705
|
+
for (let i = 0; i < entries.length; i++) {
|
|
25706
|
+
ptr[entries[i].col + 1]++;
|
|
25707
|
+
}
|
|
25708
|
+
for (let j = 1; j <= M; j++) {
|
|
25709
|
+
ptr[j] += ptr[j - 1];
|
|
25710
|
+
}
|
|
25711
|
+
for (let i = 0; i < entries.length; i++) {
|
|
25712
|
+
values.push(entries[i].value);
|
|
25713
|
+
index.push(entries[i].row);
|
|
25714
|
+
}
|
|
25715
|
+
return matrix2({ values, index, ptr, size: [N2, M] }, "sparse");
|
|
25716
|
+
}
|
|
25465
25717
|
function _createArray(arr10) {
|
|
25466
25718
|
if (arr10.length === 0)
|
|
25467
25719
|
throw new TypeError("At least one column is needed to construct a matrix.");
|
|
@@ -25520,17 +25772,79 @@ var createMatrixFromRows = /* @__PURE__ */ factory(
|
|
|
25520
25772
|
(item) => typeof item.toArray === "function"
|
|
25521
25773
|
);
|
|
25522
25774
|
const hasArray = arr10.some((item) => Array.isArray(item));
|
|
25775
|
+
const isSparse = allMatrix && !hasArray && arr10.some(
|
|
25776
|
+
(item) => typeof item.storage === "function" && item.storage() === "sparse"
|
|
25777
|
+
);
|
|
25778
|
+
if (isSparse) {
|
|
25779
|
+
return _createSparseMatrixFromRows(arr10);
|
|
25780
|
+
}
|
|
25523
25781
|
const arrays = arr10.map(
|
|
25524
25782
|
(item) => typeof item.toArray === "function" ? item.toArray() : item
|
|
25525
25783
|
);
|
|
25526
25784
|
const result = _createArray(arrays);
|
|
25527
25785
|
if (allMatrix && !hasArray) {
|
|
25528
|
-
return matrix2(result);
|
|
25786
|
+
return matrix2(result, "dense");
|
|
25529
25787
|
}
|
|
25530
25788
|
return result;
|
|
25531
25789
|
}
|
|
25532
|
-
// TODO implement this properly for SparseMatrix
|
|
25533
25790
|
});
|
|
25791
|
+
function _createSparseMatrixFromRows(arr10) {
|
|
25792
|
+
const N2 = arr10.length;
|
|
25793
|
+
const M = checkVectorTypeAndReturnLength(arr10[0]);
|
|
25794
|
+
const entries = [];
|
|
25795
|
+
for (let i = 0; i < N2; i++) {
|
|
25796
|
+
const rowVec = arr10[i];
|
|
25797
|
+
const rowLength = checkVectorTypeAndReturnLength(rowVec);
|
|
25798
|
+
if (rowLength !== M) {
|
|
25799
|
+
throw new TypeError(
|
|
25800
|
+
"The vectors had different length: " + (M | 0) + " \u2260 " + (rowLength | 0)
|
|
25801
|
+
);
|
|
25802
|
+
}
|
|
25803
|
+
if (typeof rowVec.forEach === "function") {
|
|
25804
|
+
const s = size2(rowVec);
|
|
25805
|
+
const is1D = s.length === 1;
|
|
25806
|
+
const isCol = s.length === 2 && s[1] === 1;
|
|
25807
|
+
rowVec.forEach((val, idx) => {
|
|
25808
|
+
let col;
|
|
25809
|
+
if (is1D) {
|
|
25810
|
+
col = idx[0];
|
|
25811
|
+
} else if (isCol) {
|
|
25812
|
+
col = idx[0];
|
|
25813
|
+
} else {
|
|
25814
|
+
col = idx[1];
|
|
25815
|
+
}
|
|
25816
|
+
if (val !== 0) {
|
|
25817
|
+
entries.push({ row: i, col, value: val });
|
|
25818
|
+
}
|
|
25819
|
+
});
|
|
25820
|
+
} else {
|
|
25821
|
+
const f = flatten5(rowVec);
|
|
25822
|
+
for (let j = 0; j < M; j++) {
|
|
25823
|
+
if (f[j] !== 0) {
|
|
25824
|
+
entries.push({ row: i, col: j, value: f[j] });
|
|
25825
|
+
}
|
|
25826
|
+
}
|
|
25827
|
+
}
|
|
25828
|
+
}
|
|
25829
|
+
entries.sort((a, b) => {
|
|
25830
|
+
if (a.col !== b.col) return a.col - b.col;
|
|
25831
|
+
return a.row - b.row;
|
|
25832
|
+
});
|
|
25833
|
+
const values = [];
|
|
25834
|
+
const index = [];
|
|
25835
|
+
const ptr = new Array(M + 1).fill(0);
|
|
25836
|
+
for (let i = 0; i < entries.length; i++) {
|
|
25837
|
+
ptr[entries[i].col + 1]++;
|
|
25838
|
+
}
|
|
25839
|
+
for (let j = 1; j <= M; j++) {
|
|
25840
|
+
ptr[j] += ptr[j - 1];
|
|
25841
|
+
}
|
|
25842
|
+
for (let i = 0; i < entries.length; i++) {
|
|
25843
|
+
values.push(entries[i].value);
|
|
25844
|
+
index.push(entries[i].row);
|
|
25845
|
+
}
|
|
25846
|
+
return matrix2({ values, index, ptr, size: [N2, M] }, "sparse");
|
|
25847
|
+
}
|
|
25534
25848
|
function _createArray(arr10) {
|
|
25535
25849
|
if (arr10.length === 0)
|
|
25536
25850
|
throw new TypeError("At least one row is needed to construct a matrix.");
|
|
@@ -27745,6 +28059,10 @@ var createMatAlgo11xS0s = /* @__PURE__ */ factory(
|
|
|
27745
28059
|
name108,
|
|
27746
28060
|
dependencies108,
|
|
27747
28061
|
({ typed: typed3, equalScalar: equalScalar3 }) => {
|
|
28062
|
+
let _dtCache;
|
|
28063
|
+
let _cbCache;
|
|
28064
|
+
let _eqCache;
|
|
28065
|
+
let _cfCache;
|
|
27748
28066
|
return function matAlgo11xS0s(s, b, callback, inverse) {
|
|
27749
28067
|
const avalues = s._values;
|
|
27750
28068
|
const aindex = s._index;
|
|
@@ -27762,10 +28080,19 @@ var createMatAlgo11xS0s = /* @__PURE__ */ factory(
|
|
|
27762
28080
|
let cf = callback;
|
|
27763
28081
|
if (typeof adt === "string") {
|
|
27764
28082
|
dt = adt;
|
|
27765
|
-
|
|
28083
|
+
if (dt === _dtCache && callback === _cbCache) {
|
|
28084
|
+
eq = _eqCache;
|
|
28085
|
+
cf = _cfCache;
|
|
28086
|
+
} else {
|
|
28087
|
+
eq = typed3.find(equalScalar3, [dt, dt]) || equalScalar3;
|
|
28088
|
+
cf = typed3.find(callback, [dt, dt]) || callback;
|
|
28089
|
+
_dtCache = dt;
|
|
28090
|
+
_cbCache = callback;
|
|
28091
|
+
_eqCache = eq;
|
|
28092
|
+
_cfCache = cf;
|
|
28093
|
+
}
|
|
27766
28094
|
zero = typed3.convert(0, dt);
|
|
27767
28095
|
b = typed3.convert(b, dt);
|
|
27768
|
-
cf = typed3.find(callback, [dt, dt]);
|
|
27769
28096
|
}
|
|
27770
28097
|
const cvalues = [];
|
|
27771
28098
|
const cindex = [];
|
|
@@ -28056,19 +28383,22 @@ var createRound = /* @__PURE__ */ factory(
|
|
|
28056
28383
|
|
|
28057
28384
|
// src/arithmetic/xgcd.ts
|
|
28058
28385
|
var name112 = "xgcd";
|
|
28059
|
-
var dependencies112 = ["typed", "config", "matrix", "BigNumber"];
|
|
28386
|
+
var dependencies112 = ["typed", "config", "matrix", "BigNumber", "?Fraction"];
|
|
28060
28387
|
var createXgcd = /* @__PURE__ */ factory(
|
|
28061
28388
|
name112,
|
|
28062
28389
|
dependencies112,
|
|
28063
|
-
({ typed: typed3, config: config2, matrix: matrix2, BigNumber: BigNumber9 }) => {
|
|
28064
|
-
|
|
28390
|
+
({ typed: typed3, config: config2, matrix: matrix2, BigNumber: BigNumber9, Fraction: Fraction5 }) => {
|
|
28391
|
+
const typedSignatures = {
|
|
28065
28392
|
"number, number": function(a, b) {
|
|
28066
28393
|
const res = xgcdNumber(a, b);
|
|
28067
28394
|
return config2.matrix === "Array" ? res : matrix2(res);
|
|
28068
28395
|
},
|
|
28069
28396
|
"BigNumber, BigNumber": _xgcdBigNumber
|
|
28070
|
-
|
|
28071
|
-
|
|
28397
|
+
};
|
|
28398
|
+
if (Fraction5) {
|
|
28399
|
+
typedSignatures["Fraction, Fraction"] = _xgcdFraction;
|
|
28400
|
+
}
|
|
28401
|
+
return typed3(name112, typedSignatures);
|
|
28072
28402
|
function _xgcdBigNumber(a, b) {
|
|
28073
28403
|
let t;
|
|
28074
28404
|
let q;
|
|
@@ -28102,6 +28432,42 @@ var createXgcd = /* @__PURE__ */ factory(
|
|
|
28102
28432
|
}
|
|
28103
28433
|
return config2.matrix === "Array" ? res : matrix2(res);
|
|
28104
28434
|
}
|
|
28435
|
+
function _xgcdFraction(a, b) {
|
|
28436
|
+
if (!Fraction5) {
|
|
28437
|
+
throw new Error("Fraction is not available");
|
|
28438
|
+
}
|
|
28439
|
+
let t;
|
|
28440
|
+
let q;
|
|
28441
|
+
let r;
|
|
28442
|
+
const zero = new Fraction5(0);
|
|
28443
|
+
const one = new Fraction5(1);
|
|
28444
|
+
let x = zero;
|
|
28445
|
+
let lastx = one;
|
|
28446
|
+
let y = one;
|
|
28447
|
+
let lasty = zero;
|
|
28448
|
+
if (!a.isInteger() || !b.isInteger()) {
|
|
28449
|
+
throw new Error("Parameters in function xgcd must be integer numbers");
|
|
28450
|
+
}
|
|
28451
|
+
while (!b.isZero()) {
|
|
28452
|
+
q = a.divide(b).floor();
|
|
28453
|
+
r = a.mod(b);
|
|
28454
|
+
t = x;
|
|
28455
|
+
x = lastx.subtract(q.multiply(x));
|
|
28456
|
+
lastx = t;
|
|
28457
|
+
t = y;
|
|
28458
|
+
y = lasty.subtract(q.multiply(y));
|
|
28459
|
+
lasty = t;
|
|
28460
|
+
a = b;
|
|
28461
|
+
b = r;
|
|
28462
|
+
}
|
|
28463
|
+
let res;
|
|
28464
|
+
if (a.lessThan(zero)) {
|
|
28465
|
+
res = [a.negate(), lastx.negate(), lasty.negate()];
|
|
28466
|
+
} else {
|
|
28467
|
+
res = [a, !a.isZero() ? lastx : 0, lasty];
|
|
28468
|
+
}
|
|
28469
|
+
return config2.matrix === "Array" ? res : matrix2(res);
|
|
28470
|
+
}
|
|
28105
28471
|
}
|
|
28106
28472
|
);
|
|
28107
28473
|
|
|
@@ -28185,9 +28551,6 @@ var createCatalan = /* @__PURE__ */ factory(
|
|
|
28185
28551
|
}
|
|
28186
28552
|
);
|
|
28187
28553
|
|
|
28188
|
-
// src/error/IndexError.ts
|
|
28189
|
-
import { IndexError, createIndexError } from "@danielsimonjr/mathts-core/internal";
|
|
28190
|
-
|
|
28191
28554
|
// src/error/DimensionError.ts
|
|
28192
28555
|
import { DimensionError } from "@danielsimonjr/mathts-core/internal";
|
|
28193
28556
|
|
|
@@ -28199,45 +28562,52 @@ var createConcat = /* @__PURE__ */ factory(
|
|
|
28199
28562
|
dependencies115,
|
|
28200
28563
|
({ typed: typed3, matrix: matrix2, isInteger: isInteger3 }) => {
|
|
28201
28564
|
return typed3(name115, {
|
|
28202
|
-
// TODO: change signature to '...Array | Matrix, dim?' when supported
|
|
28203
28565
|
"...Array | Matrix | number | BigNumber": function(args) {
|
|
28204
|
-
let i;
|
|
28205
28566
|
const len = args.length;
|
|
28567
|
+
if (len === 0) {
|
|
28568
|
+
throw new SyntaxError("At least one matrix expected");
|
|
28569
|
+
}
|
|
28570
|
+
const lastArg = args[len - 1];
|
|
28571
|
+
const hasDim = isNumber(lastArg) || isBigNumber(lastArg);
|
|
28572
|
+
const dimIndex = hasDim ? len - 1 : len;
|
|
28206
28573
|
let dim = -1;
|
|
28207
|
-
|
|
28574
|
+
if (hasDim) {
|
|
28575
|
+
dim = lastArg.valueOf();
|
|
28576
|
+
if (!isInteger3(dim)) {
|
|
28577
|
+
throw new TypeError("Integer number expected for dimension");
|
|
28578
|
+
}
|
|
28579
|
+
}
|
|
28208
28580
|
let asMatrix = false;
|
|
28581
|
+
let prevDim = -1;
|
|
28209
28582
|
const matrices = [];
|
|
28210
|
-
for (i = 0; i <
|
|
28583
|
+
for (let i = 0; i < dimIndex; i++) {
|
|
28211
28584
|
const arg3 = args[i];
|
|
28585
|
+
if (isNumber(arg3) || isBigNumber(arg3)) {
|
|
28586
|
+
throw new Error("Dimension must be specified as last argument");
|
|
28587
|
+
}
|
|
28212
28588
|
if (isMatrix(arg3)) {
|
|
28213
28589
|
asMatrix = true;
|
|
28214
28590
|
}
|
|
28215
|
-
|
|
28216
|
-
|
|
28217
|
-
|
|
28218
|
-
|
|
28219
|
-
|
|
28220
|
-
|
|
28221
|
-
|
|
28222
|
-
|
|
28223
|
-
}
|
|
28224
|
-
if (dim < 0 || i > 0 && dim > prevDim) {
|
|
28225
|
-
throw new IndexError(dim, prevDim + 1);
|
|
28226
|
-
}
|
|
28227
|
-
} else {
|
|
28228
|
-
const m = clone(arg3).valueOf();
|
|
28229
|
-
const size2 = arraySize(m);
|
|
28230
|
-
matrices[i] = m;
|
|
28231
|
-
prevDim = dim;
|
|
28232
|
-
dim = size2.length - 1;
|
|
28233
|
-
if (i > 0 && dim !== prevDim) {
|
|
28234
|
-
throw new DimensionError(prevDim + 1, dim + 1);
|
|
28235
|
-
}
|
|
28591
|
+
const m = clone(arg3).valueOf();
|
|
28592
|
+
const size2 = arraySize(m);
|
|
28593
|
+
matrices.push(m);
|
|
28594
|
+
const currentDim = size2.length - 1;
|
|
28595
|
+
if (i === 0) {
|
|
28596
|
+
prevDim = currentDim;
|
|
28597
|
+
} else if (currentDim !== prevDim) {
|
|
28598
|
+
throw new DimensionError(prevDim + 1, currentDim + 1);
|
|
28236
28599
|
}
|
|
28237
28600
|
}
|
|
28238
28601
|
if (matrices.length === 0) {
|
|
28239
28602
|
throw new SyntaxError("At least one matrix expected");
|
|
28240
28603
|
}
|
|
28604
|
+
if (hasDim) {
|
|
28605
|
+
if (dim < 0 || dim > prevDim) {
|
|
28606
|
+
throw new DimensionError(dim, dim < 0 ? 0 : prevDim, dim < 0 ? "<" : ">");
|
|
28607
|
+
}
|
|
28608
|
+
} else {
|
|
28609
|
+
dim = prevDim;
|
|
28610
|
+
}
|
|
28241
28611
|
let res = matrices.shift();
|
|
28242
28612
|
while (matrices.length) {
|
|
28243
28613
|
res = concat(res, matrices.shift(), dim);
|
|
@@ -28449,6 +28819,9 @@ var createInv = /* @__PURE__ */ factory(
|
|
|
28449
28819
|
}
|
|
28450
28820
|
);
|
|
28451
28821
|
|
|
28822
|
+
// src/error/IndexError.ts
|
|
28823
|
+
import { IndexError, createIndexError } from "@danielsimonjr/mathts-core/internal";
|
|
28824
|
+
|
|
28452
28825
|
// src/matrix/mapSlices.ts
|
|
28453
28826
|
var name117 = "mapSlices";
|
|
28454
28827
|
var dependencies117 = ["typed", "isInteger"];
|
|
@@ -28737,7 +29110,7 @@ var createSubset = /* @__PURE__ */ factory(
|
|
|
28737
29110
|
);
|
|
28738
29111
|
function _getSubstring(str, index) {
|
|
28739
29112
|
if (!isIndex(index)) {
|
|
28740
|
-
throw new TypeError("Index
|
|
29113
|
+
throw new TypeError("Invalid index: must be an Index or Index-like object");
|
|
28741
29114
|
}
|
|
28742
29115
|
if (isEmptyIndex(index)) {
|
|
28743
29116
|
return "";
|
|
@@ -28763,7 +29136,7 @@ function _getSubstring(str, index) {
|
|
|
28763
29136
|
}
|
|
28764
29137
|
function _setSubstring(str, index, replacement, defaultValue) {
|
|
28765
29138
|
if (!index || index.isIndex !== true) {
|
|
28766
|
-
throw new TypeError("Index
|
|
29139
|
+
throw new TypeError("Invalid index: must be an Index or Index-like object");
|
|
28767
29140
|
}
|
|
28768
29141
|
if (isEmptyIndex(index)) {
|
|
28769
29142
|
return str;
|
|
@@ -28933,6 +29306,7 @@ var createMatAlgo03xDSf = /* @__PURE__ */ factory(
|
|
|
28933
29306
|
name121,
|
|
28934
29307
|
dependencies121,
|
|
28935
29308
|
({ typed: typed3 }) => {
|
|
29309
|
+
const signaturesCache = /* @__PURE__ */ new WeakMap();
|
|
28936
29310
|
return function matAlgo03xDSf(denseMatrix, sparseMatrix, callback, inverse) {
|
|
28937
29311
|
const adata = denseMatrix._data;
|
|
28938
29312
|
const asize = denseMatrix._size;
|
|
@@ -28961,7 +29335,17 @@ var createMatAlgo03xDSf = /* @__PURE__ */ factory(
|
|
|
28961
29335
|
if (typeof adt === "string" && adt === bdt && adt !== "mixed") {
|
|
28962
29336
|
dt = adt;
|
|
28963
29337
|
zero = typed3.convert(0, dt);
|
|
28964
|
-
|
|
29338
|
+
let callbacksForDt = signaturesCache.get(callback);
|
|
29339
|
+
if (!callbacksForDt) {
|
|
29340
|
+
callbacksForDt = /* @__PURE__ */ new Map();
|
|
29341
|
+
signaturesCache.set(callback, callbacksForDt);
|
|
29342
|
+
}
|
|
29343
|
+
let cachedCf = callbacksForDt.get(dt);
|
|
29344
|
+
if (!cachedCf) {
|
|
29345
|
+
cachedCf = typed3.find(callback, [dt, dt]);
|
|
29346
|
+
callbacksForDt.set(dt, cachedCf);
|
|
29347
|
+
}
|
|
29348
|
+
cf = cachedCf;
|
|
28965
29349
|
}
|
|
28966
29350
|
const cdata = [];
|
|
28967
29351
|
for (let z = 0; z < rows; z++) {
|
|
@@ -29519,7 +29903,7 @@ var createCumSum = /* @__PURE__ */ factory(
|
|
|
29519
29903
|
const size2 = arraySize(array);
|
|
29520
29904
|
const dimValue = typeof dim === "number" ? dim : dim.valueOf();
|
|
29521
29905
|
if (dimValue < 0 || dimValue >= size2.length) {
|
|
29522
|
-
throw new
|
|
29906
|
+
throw new DimensionError(dimValue, size2.length, "<");
|
|
29523
29907
|
}
|
|
29524
29908
|
try {
|
|
29525
29909
|
return _cumsumDimensional(array, dimValue);
|
|
@@ -31452,7 +31836,7 @@ var createRightLogShift = /* @__PURE__ */ factory(
|
|
|
31452
31836
|
name153,
|
|
31453
31837
|
{
|
|
31454
31838
|
"number, number": rightLogShiftNumber,
|
|
31455
|
-
|
|
31839
|
+
"BigNumber, BigNumber": rightLogShiftBigNumber,
|
|
31456
31840
|
"SparseMatrix, number | BigNumber": typed3.referToSelf(
|
|
31457
31841
|
(self) => (x, y) => {
|
|
31458
31842
|
if (equalScalar3(y, 0)) {
|
|
@@ -34141,8 +34525,16 @@ var createPermutations = /* @__PURE__ */ factory(
|
|
|
34141
34525
|
result = result.times(i);
|
|
34142
34526
|
}
|
|
34143
34527
|
return result;
|
|
34144
|
-
}
|
|
34145
|
-
|
|
34528
|
+
},
|
|
34529
|
+
"Array | Matrix": typed3.referToSelf(
|
|
34530
|
+
(self) => (n) => deepMap(n, self)
|
|
34531
|
+
),
|
|
34532
|
+
"Array | Matrix, number | BigNumber": typed3.referToSelf(
|
|
34533
|
+
(self) => (n, k) => deepMap(n, (n_val) => self(n_val, k))
|
|
34534
|
+
),
|
|
34535
|
+
"number | BigNumber, Array | Matrix": typed3.referToSelf(
|
|
34536
|
+
(self) => (n, k) => deepMap(k, (k_val) => self(n, k_val))
|
|
34537
|
+
)
|
|
34146
34538
|
});
|
|
34147
34539
|
}
|
|
34148
34540
|
);
|
|
@@ -35393,13 +35785,21 @@ var dependencies199 = [
|
|
|
35393
35785
|
"multiply",
|
|
35394
35786
|
"equalScalar",
|
|
35395
35787
|
"divideScalar",
|
|
35396
|
-
"
|
|
35788
|
+
"pinv",
|
|
35397
35789
|
"nodeOperations"
|
|
35398
35790
|
];
|
|
35399
35791
|
var createDivide = /* @__PURE__ */ factory(
|
|
35400
35792
|
name199,
|
|
35401
35793
|
dependencies199,
|
|
35402
|
-
({
|
|
35794
|
+
({
|
|
35795
|
+
typed: typed3,
|
|
35796
|
+
matrix: matrix2,
|
|
35797
|
+
multiply: multiply2,
|
|
35798
|
+
equalScalar: equalScalar3,
|
|
35799
|
+
divideScalar: divideScalar2,
|
|
35800
|
+
pinv: pinv2,
|
|
35801
|
+
nodeOperations: nodeOperations2
|
|
35802
|
+
}) => {
|
|
35403
35803
|
const matAlgo11xS0s = createMatAlgo11xS0s({ typed: typed3, equalScalar: equalScalar3 });
|
|
35404
35804
|
const matAlgo14xDs = createMatAlgo14xDs({ typed: typed3 });
|
|
35405
35805
|
return typed3(
|
|
@@ -35427,7 +35827,7 @@ var createDivide = /* @__PURE__ */ factory(
|
|
|
35427
35827
|
// MATRIX SIGNATURES - Deal with matrices
|
|
35428
35828
|
// =========================================================================
|
|
35429
35829
|
"Array | Matrix, Array | Matrix": function(x, y) {
|
|
35430
|
-
return multiply2(x,
|
|
35830
|
+
return multiply2(x, pinv2(y));
|
|
35431
35831
|
},
|
|
35432
35832
|
"DenseMatrix, any": function(x, y) {
|
|
35433
35833
|
return matAlgo14xDs(
|
|
@@ -35454,7 +35854,7 @@ var createDivide = /* @__PURE__ */ factory(
|
|
|
35454
35854
|
).valueOf();
|
|
35455
35855
|
},
|
|
35456
35856
|
"any, Array | Matrix": function(x, y) {
|
|
35457
|
-
return multiply2(x,
|
|
35857
|
+
return multiply2(x, pinv2(y));
|
|
35458
35858
|
}
|
|
35459
35859
|
},
|
|
35460
35860
|
divideScalar2.signatures
|
|
@@ -37588,7 +37988,6 @@ var dependencies218 = [
|
|
|
37588
37988
|
"abs",
|
|
37589
37989
|
"add",
|
|
37590
37990
|
"addScalar",
|
|
37591
|
-
"matrix",
|
|
37592
37991
|
"multiply",
|
|
37593
37992
|
"multiplyScalar",
|
|
37594
37993
|
"divideScalar",
|
|
@@ -37608,7 +38007,6 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
37608
38007
|
abs: abs2,
|
|
37609
38008
|
add: add5,
|
|
37610
38009
|
addScalar: addScalar2,
|
|
37611
|
-
matrix: matrix2,
|
|
37612
38010
|
multiply: multiply2,
|
|
37613
38011
|
multiplyScalar: multiplyScalar2,
|
|
37614
38012
|
divideScalar: divideScalar2,
|
|
@@ -37628,7 +38026,7 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
37628
38026
|
y.valueOf(),
|
|
37629
38027
|
plane.valueOf()
|
|
37630
38028
|
);
|
|
37631
|
-
return arr10 === null ? null :
|
|
38029
|
+
return arr10 === null ? null : x.create(arr10, x.datatype());
|
|
37632
38030
|
},
|
|
37633
38031
|
"Matrix, Matrix, Matrix, Matrix": function(w, x, y, z) {
|
|
37634
38032
|
const arr10 = _AAAA(
|
|
@@ -37637,7 +38035,7 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
37637
38035
|
y.valueOf(),
|
|
37638
38036
|
z.valueOf()
|
|
37639
38037
|
);
|
|
37640
|
-
return arr10 === null ? null :
|
|
38038
|
+
return arr10 === null ? null : w.create(arr10, w.datatype());
|
|
37641
38039
|
}
|
|
37642
38040
|
});
|
|
37643
38041
|
function _AAA(x, y, plane) {
|
|
@@ -37838,6 +38236,15 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
37838
38236
|
),
|
|
37839
38237
|
z1z
|
|
37840
38238
|
);
|
|
38239
|
+
if (isZero4(denominator) || smaller2(abs2(denominator), config2.relTol)) {
|
|
38240
|
+
if (isZero4(numerator) || smaller2(abs2(numerator), config2.relTol)) {
|
|
38241
|
+
return [
|
|
38242
|
+
[x1, y1, z1],
|
|
38243
|
+
[x2, y2, z2]
|
|
38244
|
+
];
|
|
38245
|
+
}
|
|
38246
|
+
return null;
|
|
38247
|
+
}
|
|
37841
38248
|
const t = divideScalar2(numerator, denominator);
|
|
37842
38249
|
const px = addScalar2(x1, multiplyScalar2(t, subtract3(x2, x1)));
|
|
37843
38250
|
const py = addScalar2(y1, multiplyScalar2(t, subtract3(y2, y1)));
|
|
@@ -37923,11 +38330,11 @@ var createMean = /* @__PURE__ */ factory(
|
|
|
37923
38330
|
|
|
37924
38331
|
// src/statistics/median.ts
|
|
37925
38332
|
var name220 = "median";
|
|
37926
|
-
var dependencies220 = ["typed", "add", "divide", "compare", "partitionSelect"];
|
|
38333
|
+
var dependencies220 = ["typed", "add", "divide", "compare", "partitionSelect", "mapSlices"];
|
|
37927
38334
|
var createMedian = /* @__PURE__ */ factory(
|
|
37928
38335
|
name220,
|
|
37929
38336
|
dependencies220,
|
|
37930
|
-
({ typed: typed3, add: add5, divide: divide2, compare: compare2, partitionSelect: partitionSelect2 }) => {
|
|
38337
|
+
({ typed: typed3, add: add5, divide: divide2, compare: compare2, partitionSelect: partitionSelect2, mapSlices: mapSlices2 }) => {
|
|
37931
38338
|
function _median2(array) {
|
|
37932
38339
|
try {
|
|
37933
38340
|
const flat = flatten2(array.valueOf());
|
|
@@ -37968,7 +38375,11 @@ var createMedian = /* @__PURE__ */ factory(
|
|
|
37968
38375
|
"Array | Matrix": _median2,
|
|
37969
38376
|
// median([a, b, c, d, ...], dim)
|
|
37970
38377
|
"Array | Matrix, number | BigNumber": function(_array, _dim) {
|
|
37971
|
-
|
|
38378
|
+
try {
|
|
38379
|
+
return mapSlices2(_array, _dim, (x) => _median2(x));
|
|
38380
|
+
} catch (err) {
|
|
38381
|
+
throw improveErrorMessage(err, "median", void 0);
|
|
38382
|
+
}
|
|
37972
38383
|
},
|
|
37973
38384
|
// median(a, b, c, d, ...)
|
|
37974
38385
|
"...": function(args) {
|
|
@@ -41924,19 +42335,30 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
41924
42335
|
SymbolNode
|
|
41925
42336
|
}) => {
|
|
41926
42337
|
function plainDerivative(expr, variable, options = { simplify: true }) {
|
|
41927
|
-
const
|
|
42338
|
+
const order = options.order !== void 0 ? options.order : 1;
|
|
42339
|
+
if (!Number.isInteger(order) || order < 0) {
|
|
42340
|
+
throw new TypeError('Option "order" must be a non-negative integer');
|
|
42341
|
+
}
|
|
41928
42342
|
const variableName = variable.name;
|
|
41929
|
-
|
|
41930
|
-
|
|
41931
|
-
|
|
41932
|
-
|
|
42343
|
+
let res = expr;
|
|
42344
|
+
for (let i = 0; i < order; i++) {
|
|
42345
|
+
let isConstCached2 = function(node) {
|
|
42346
|
+
const cached = cache.get(node);
|
|
42347
|
+
if (cached !== void 0) {
|
|
42348
|
+
return cached;
|
|
42349
|
+
}
|
|
42350
|
+
const r = _isConst(isConstCached2, node, variableName);
|
|
42351
|
+
cache.set(node, r);
|
|
42352
|
+
return r;
|
|
42353
|
+
};
|
|
42354
|
+
var isConstCached = isConstCached2;
|
|
42355
|
+
const cache = /* @__PURE__ */ new Map();
|
|
42356
|
+
res = _derivative(res, isConstCached2);
|
|
42357
|
+
if (options.simplify !== false && i < order - 1) {
|
|
42358
|
+
res = simplify2(res);
|
|
41933
42359
|
}
|
|
41934
|
-
const res2 = _isConst(isConstCached, node, variableName);
|
|
41935
|
-
cache.set(node, res2);
|
|
41936
|
-
return res2;
|
|
41937
42360
|
}
|
|
41938
|
-
|
|
41939
|
-
return options.simplify ? simplify2(res) : res;
|
|
42361
|
+
return options.simplify !== false ? simplify2(res) : res;
|
|
41940
42362
|
}
|
|
41941
42363
|
function parseIdentifier(string2) {
|
|
41942
42364
|
const symbol = parse3(string2);
|
|
@@ -41952,16 +42374,6 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
41952
42374
|
"Node, SymbolNode, Object": plainDerivative,
|
|
41953
42375
|
"Node, string": (node, symbol) => plainDerivative(node, parseIdentifier(symbol)),
|
|
41954
42376
|
"Node, string, Object": (node, symbol, options) => plainDerivative(node, parseIdentifier(symbol), options)
|
|
41955
|
-
/* TODO: implement and test syntax with order of derivatives -> implement as an option {order: number}
|
|
41956
|
-
'Node, SymbolNode, ConstantNode': function (expr, variable, {order}) {
|
|
41957
|
-
let res = expr
|
|
41958
|
-
for (let i = 0; i < order; i++) {
|
|
41959
|
-
<create caching isConst>
|
|
41960
|
-
res = _derivative(res, isConst)
|
|
41961
|
-
}
|
|
41962
|
-
return res
|
|
41963
|
-
}
|
|
41964
|
-
*/
|
|
41965
42377
|
});
|
|
41966
42378
|
derivative3._simplify = true;
|
|
41967
42379
|
derivative3.toTex = function(deriv) {
|
|
@@ -41970,7 +42382,11 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
41970
42382
|
const _derivTex = typed3("_derivTex", {
|
|
41971
42383
|
"Node, SymbolNode": function(expr, x) {
|
|
41972
42384
|
if (isConstantNode(expr) && typeOf(expr.value) === "string") {
|
|
41973
|
-
return _derivTex(
|
|
42385
|
+
return _derivTex(
|
|
42386
|
+
parse3(expr.value).toString(),
|
|
42387
|
+
x.toString(),
|
|
42388
|
+
1
|
|
42389
|
+
);
|
|
41974
42390
|
} else {
|
|
41975
42391
|
return _derivTex(expr.toTex(), x.toString(), 1);
|
|
41976
42392
|
}
|
|
@@ -42026,7 +42442,9 @@ var createDerivative = /* @__PURE__ */ factory(
|
|
|
42026
42442
|
return createConstantNode2(1);
|
|
42027
42443
|
},
|
|
42028
42444
|
"ParenthesisNode, function": function(node, isConst2) {
|
|
42029
|
-
return new ParenthesisNode(
|
|
42445
|
+
return new ParenthesisNode(
|
|
42446
|
+
_derivative(node.content, isConst2)
|
|
42447
|
+
);
|
|
42030
42448
|
},
|
|
42031
42449
|
"FunctionAssignmentNode, function": function(node, isConst2) {
|
|
42032
42450
|
if (isConst2(node)) {
|
|
@@ -42797,7 +43215,6 @@ var createRationalize = /* @__PURE__ */ factory(
|
|
|
42797
43215
|
const variables2 = [];
|
|
42798
43216
|
const node = simplify2(expr, rules, scope, { exactFractions: false });
|
|
42799
43217
|
extended = !!extended;
|
|
42800
|
-
const oper = "+-*" + (extended ? "/" : "");
|
|
42801
43218
|
recPoly(node);
|
|
42802
43219
|
const retFunc = {};
|
|
42803
43220
|
retFunc.expression = node;
|
|
@@ -42815,9 +43232,10 @@ var createRationalize = /* @__PURE__ */ factory(
|
|
|
42815
43232
|
recPoly(node2.args[0]);
|
|
42816
43233
|
}
|
|
42817
43234
|
} else {
|
|
42818
|
-
|
|
43235
|
+
const op = node2.op;
|
|
43236
|
+
if (op !== "+" && op !== "-" && op !== "*" && op !== "^" && (!extended || op !== "/")) {
|
|
42819
43237
|
throw new Error(
|
|
42820
|
-
"Operator " +
|
|
43238
|
+
"Operator " + op + " invalid in polynomial expression"
|
|
42821
43239
|
);
|
|
42822
43240
|
}
|
|
42823
43241
|
for (let i = 0; i < node2.args.length; i++) {
|
|
@@ -43057,8 +43475,9 @@ var createRationalize = /* @__PURE__ */ factory(
|
|
|
43057
43475
|
if (tp === "FunctionNode") {
|
|
43058
43476
|
throw new Error("There is an unsolved function call");
|
|
43059
43477
|
} else if (tp === "OperatorNode") {
|
|
43060
|
-
|
|
43061
|
-
|
|
43478
|
+
const op = node2.op;
|
|
43479
|
+
if (op !== "+" && op !== "-" && op !== "*" && op !== "^")
|
|
43480
|
+
throw new Error("Operator " + op + " invalid");
|
|
43062
43481
|
if (noPai !== null) {
|
|
43063
43482
|
if ((node2.fn === "unaryMinus" || node2.fn === "pow") && noPai.fn !== "add" && noPai.fn !== "subtract" && noPai.fn !== "multiply") {
|
|
43064
43483
|
throw new Error("Invalid " + node2.op + " placing");
|
|
@@ -43640,7 +44059,7 @@ var createNuclearMagneton = /* @__PURE__ */ unitFactory(
|
|
|
43640
44059
|
var createKlitzing = /* @__PURE__ */ unitFactory("klitzing", "25812.807459304513", "ohm");
|
|
43641
44060
|
var createJosephson = /* @__PURE__ */ unitFactory(
|
|
43642
44061
|
"josephson",
|
|
43643
|
-
"4.835978484169836e14
|
|
44062
|
+
"4.835978484169836e14",
|
|
43644
44063
|
"Hz V^-1"
|
|
43645
44064
|
);
|
|
43646
44065
|
var createBohrRadius = /* @__PURE__ */ unitFactory("bohrRadius", "5.29177210544e-11", "m");
|
|
@@ -44775,7 +45194,6 @@ function reviver(_key, value) {
|
|
|
44775
45194
|
}
|
|
44776
45195
|
|
|
44777
45196
|
// src/typed/cas.ts
|
|
44778
|
-
import { computePool as computePool12 } from "@danielsimonjr/mathts-parallel";
|
|
44779
45197
|
import { Complex as Complex10 } from "@danielsimonjr/mathts-core";
|
|
44780
45198
|
|
|
44781
45199
|
// src/numeric/numeric-jacobian.ts
|
|
@@ -46212,15 +46630,17 @@ function _combineLikeTerms(expr) {
|
|
|
46212
46630
|
return parts.join(" + ").replace(/\+\s*-/g, "- ");
|
|
46213
46631
|
}
|
|
46214
46632
|
function _casDerivativeOne(expr, variable) {
|
|
46633
|
+
if (expr.indexOf(variable) === -1) return "0";
|
|
46215
46634
|
const terms = expr.split(/\s*\+\s*/);
|
|
46216
46635
|
const derivedTerms = [];
|
|
46636
|
+
const powerRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "\\^(\\d+)$");
|
|
46637
|
+
const linearRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "$");
|
|
46217
46638
|
for (const term of terms) {
|
|
46218
46639
|
const t = term.trim();
|
|
46219
|
-
if (
|
|
46640
|
+
if (t.indexOf(variable) === -1) {
|
|
46220
46641
|
derivedTerms.push("0");
|
|
46221
46642
|
continue;
|
|
46222
46643
|
}
|
|
46223
|
-
const powerRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "\\^(\\d+)$");
|
|
46224
46644
|
const powerMatch = t.match(powerRe);
|
|
46225
46645
|
if (powerMatch) {
|
|
46226
46646
|
const coeff = powerMatch[1] === "" || powerMatch[1] === void 0 ? 1 : parseFloat(powerMatch[1]);
|
|
@@ -46234,7 +46654,6 @@ function _casDerivativeOne(expr, variable) {
|
|
|
46234
46654
|
}
|
|
46235
46655
|
continue;
|
|
46236
46656
|
}
|
|
46237
|
-
const linearRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "$");
|
|
46238
46657
|
const linearMatch = t.match(linearRe);
|
|
46239
46658
|
if (linearMatch) {
|
|
46240
46659
|
const coeff = linearMatch[1] === "" ? 1 : parseFloat(linearMatch[1]);
|
|
@@ -46273,199 +46692,14 @@ function casSimplify(input) {
|
|
|
46273
46692
|
return _casSimplifyOne(_nodeToStr(input));
|
|
46274
46693
|
}
|
|
46275
46694
|
const strs = input.map(_nodeToStr);
|
|
46276
|
-
|
|
46277
|
-
return Promise.resolve(strs.map(_casSimplifyOne));
|
|
46278
|
-
}
|
|
46279
|
-
return computePool12.map(strs, (exprStr) => {
|
|
46280
|
-
function _evalNumeric2(exprStr2) {
|
|
46281
|
-
let pos = 0;
|
|
46282
|
-
const s = exprStr2.replace(/\s+/g, "");
|
|
46283
|
-
const parseExpr = () => {
|
|
46284
|
-
let val = parseTerm();
|
|
46285
|
-
while (pos < s.length) {
|
|
46286
|
-
if (s[pos] === "+") {
|
|
46287
|
-
pos++;
|
|
46288
|
-
val += parseTerm();
|
|
46289
|
-
} else if (s[pos] === "-") {
|
|
46290
|
-
pos++;
|
|
46291
|
-
val -= parseTerm();
|
|
46292
|
-
} else break;
|
|
46293
|
-
}
|
|
46294
|
-
return val;
|
|
46295
|
-
};
|
|
46296
|
-
const parseTerm = () => {
|
|
46297
|
-
let val = parseFactor();
|
|
46298
|
-
while (pos < s.length) {
|
|
46299
|
-
if (s[pos] === "*") {
|
|
46300
|
-
pos++;
|
|
46301
|
-
val *= parseFactor();
|
|
46302
|
-
} else if (s[pos] === "/") {
|
|
46303
|
-
pos++;
|
|
46304
|
-
val /= parseFactor();
|
|
46305
|
-
} else break;
|
|
46306
|
-
}
|
|
46307
|
-
return val;
|
|
46308
|
-
};
|
|
46309
|
-
const parseFactor = () => {
|
|
46310
|
-
let val = parseBase();
|
|
46311
|
-
if (pos < s.length && s[pos] === "^") {
|
|
46312
|
-
pos++;
|
|
46313
|
-
val = Math.pow(val, parseFactor());
|
|
46314
|
-
}
|
|
46315
|
-
return val;
|
|
46316
|
-
};
|
|
46317
|
-
const parseBase = () => {
|
|
46318
|
-
if (s[pos] === "+") {
|
|
46319
|
-
pos++;
|
|
46320
|
-
return parseBase();
|
|
46321
|
-
}
|
|
46322
|
-
if (s[pos] === "-") {
|
|
46323
|
-
pos++;
|
|
46324
|
-
return -parseBase();
|
|
46325
|
-
}
|
|
46326
|
-
if (s[pos] === "(") {
|
|
46327
|
-
pos++;
|
|
46328
|
-
const val = parseExpr();
|
|
46329
|
-
if (s[pos] === ")") pos++;
|
|
46330
|
-
return val;
|
|
46331
|
-
}
|
|
46332
|
-
const start = pos;
|
|
46333
|
-
while (pos < s.length && /[\d.]/.test(s[pos])) pos++;
|
|
46334
|
-
if (start === pos) throw new Error();
|
|
46335
|
-
return parseFloat(s.substring(start, pos));
|
|
46336
|
-
};
|
|
46337
|
-
try {
|
|
46338
|
-
const val = parseExpr();
|
|
46339
|
-
if (pos === s.length && typeof val === "number" && isFinite(val)) {
|
|
46340
|
-
return String(val);
|
|
46341
|
-
}
|
|
46342
|
-
} catch {
|
|
46343
|
-
}
|
|
46344
|
-
return void 0;
|
|
46345
|
-
}
|
|
46346
|
-
function _combineLikeTermsW(expr) {
|
|
46347
|
-
const normalised = expr.replace(/\s*-\s*/g, " + -");
|
|
46348
|
-
const rawTerms = normalised.split(/\s*\+\s*/);
|
|
46349
|
-
const termMap = /* @__PURE__ */ new Map();
|
|
46350
|
-
const otherTerms = [];
|
|
46351
|
-
for (const raw of rawTerms) {
|
|
46352
|
-
const t = raw.trim();
|
|
46353
|
-
if (!t) continue;
|
|
46354
|
-
if (/^-?\d+(\.\d+)?$/.test(t)) {
|
|
46355
|
-
termMap.set("__const__", (termMap.get("__const__") ?? 0) + Number(t));
|
|
46356
|
-
continue;
|
|
46357
|
-
}
|
|
46358
|
-
const cvpMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)\^(\d+)$/);
|
|
46359
|
-
if (cvpMatch) {
|
|
46360
|
-
const c = cvpMatch[1] === "" || cvpMatch[1] === "+" ? 1 : cvpMatch[1] === "-" ? -1 : Number(cvpMatch[1]);
|
|
46361
|
-
const key2 = cvpMatch[2] + "^" + cvpMatch[3];
|
|
46362
|
-
termMap.set(key2, (termMap.get(key2) ?? 0) + c);
|
|
46363
|
-
continue;
|
|
46364
|
-
}
|
|
46365
|
-
const cvMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)$/);
|
|
46366
|
-
if (cvMatch && !/^\d+$/.test(cvMatch[2])) {
|
|
46367
|
-
const c = cvMatch[1] === "" || cvMatch[1] === "+" ? 1 : cvMatch[1] === "-" ? -1 : Number(cvMatch[1]);
|
|
46368
|
-
termMap.set(cvMatch[2], (termMap.get(cvMatch[2]) ?? 0) + c);
|
|
46369
|
-
continue;
|
|
46370
|
-
}
|
|
46371
|
-
otherTerms.push(t);
|
|
46372
|
-
}
|
|
46373
|
-
const parts = [];
|
|
46374
|
-
for (const [key2, c] of termMap) {
|
|
46375
|
-
if (Math.abs(c) < 1e-12) continue;
|
|
46376
|
-
if (key2 === "__const__") {
|
|
46377
|
-
parts.push(String(c));
|
|
46378
|
-
} else if (Math.abs(c - 1) < 1e-12) {
|
|
46379
|
-
parts.push(key2);
|
|
46380
|
-
} else if (Math.abs(c + 1) < 1e-12) {
|
|
46381
|
-
parts.push("-" + key2);
|
|
46382
|
-
} else {
|
|
46383
|
-
parts.push(c + "*" + key2);
|
|
46384
|
-
}
|
|
46385
|
-
}
|
|
46386
|
-
parts.push(...otherTerms);
|
|
46387
|
-
if (parts.length === 0) return "0";
|
|
46388
|
-
return parts.join(" + ").replace(/\+\s*-/g, "- ");
|
|
46389
|
-
}
|
|
46390
|
-
let r = exprStr.trim();
|
|
46391
|
-
r = r.replace(/\b(\w+)\^0\b/g, "1");
|
|
46392
|
-
r = r.replace(/\b(\w+)\^1\b/g, "$1");
|
|
46393
|
-
r = r.replace(/\b1\s*\*\s*/g, "");
|
|
46394
|
-
r = r.replace(/\s*\*\s*1\b/g, "");
|
|
46395
|
-
r = r.replace(/\b0\s*\+\s*/g, "");
|
|
46396
|
-
r = r.replace(/\s*\+\s*0\b/g, "");
|
|
46397
|
-
r = r.replace(/\b0\s*\*\s*[^+-]*/g, "0");
|
|
46398
|
-
if (/^[\d\s+\-*/().^]+$/.test(r)) {
|
|
46399
|
-
const val = _evalNumeric2(r);
|
|
46400
|
-
if (val !== void 0) return val;
|
|
46401
|
-
}
|
|
46402
|
-
return _combineLikeTermsW(r) || "0";
|
|
46403
|
-
}).then((r) => r.result);
|
|
46695
|
+
return Promise.resolve(strs.map(_casSimplifyOne));
|
|
46404
46696
|
}
|
|
46405
46697
|
function casDerivative(input, variable) {
|
|
46406
46698
|
if (!Array.isArray(input)) {
|
|
46407
46699
|
return _casDerivativeOne(_nodeToStr(input), variable);
|
|
46408
46700
|
}
|
|
46409
46701
|
const strs = input.map(_nodeToStr);
|
|
46410
|
-
|
|
46411
|
-
return Promise.resolve(strs.map((s) => _casDerivativeOne(s, variable)));
|
|
46412
|
-
}
|
|
46413
|
-
const varName = variable;
|
|
46414
|
-
return computePool12.map(strs, (exprStr) => {
|
|
46415
|
-
const _variable = varName;
|
|
46416
|
-
const terms = exprStr.split(/\s*\+\s*/);
|
|
46417
|
-
const derivedTerms = [];
|
|
46418
|
-
for (const term of terms) {
|
|
46419
|
-
const t = term.trim();
|
|
46420
|
-
if (!t.includes(_variable)) {
|
|
46421
|
-
derivedTerms.push("0");
|
|
46422
|
-
continue;
|
|
46423
|
-
}
|
|
46424
|
-
const powerRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + _variable + "\\^(\\d+)$");
|
|
46425
|
-
const powerMatch = t.match(powerRe);
|
|
46426
|
-
if (powerMatch) {
|
|
46427
|
-
const coeff = powerMatch[1] === "" || powerMatch[1] === void 0 ? 1 : parseFloat(powerMatch[1]);
|
|
46428
|
-
const n = parseInt(powerMatch[2], 10);
|
|
46429
|
-
if (n === 0) {
|
|
46430
|
-
derivedTerms.push("0");
|
|
46431
|
-
} else if (n === 1) {
|
|
46432
|
-
derivedTerms.push(String(coeff));
|
|
46433
|
-
} else {
|
|
46434
|
-
derivedTerms.push(coeff * n + "*" + _variable + "^" + (n - 1));
|
|
46435
|
-
}
|
|
46436
|
-
continue;
|
|
46437
|
-
}
|
|
46438
|
-
const linearRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + _variable + "$");
|
|
46439
|
-
const linearMatch = t.match(linearRe);
|
|
46440
|
-
if (linearMatch) {
|
|
46441
|
-
const coeff = linearMatch[1] === "" ? 1 : parseFloat(linearMatch[1]);
|
|
46442
|
-
derivedTerms.push(String(coeff));
|
|
46443
|
-
continue;
|
|
46444
|
-
}
|
|
46445
|
-
if (t === _variable) {
|
|
46446
|
-
derivedTerms.push("1");
|
|
46447
|
-
continue;
|
|
46448
|
-
}
|
|
46449
|
-
if (t === "sin(" + _variable + ")") {
|
|
46450
|
-
derivedTerms.push("cos(" + _variable + ")");
|
|
46451
|
-
continue;
|
|
46452
|
-
}
|
|
46453
|
-
if (t === "cos(" + _variable + ")") {
|
|
46454
|
-
derivedTerms.push("-sin(" + _variable + ")");
|
|
46455
|
-
continue;
|
|
46456
|
-
}
|
|
46457
|
-
if (t === "exp(" + _variable + ")") {
|
|
46458
|
-
derivedTerms.push("exp(" + _variable + ")");
|
|
46459
|
-
continue;
|
|
46460
|
-
}
|
|
46461
|
-
if (t === "ln(" + _variable + ")") {
|
|
46462
|
-
derivedTerms.push("1/" + _variable);
|
|
46463
|
-
continue;
|
|
46464
|
-
}
|
|
46465
|
-
derivedTerms.push("d/d" + _variable + "(" + t + ")");
|
|
46466
|
-
}
|
|
46467
|
-
return derivedTerms.join(" + ");
|
|
46468
|
-
}).then((r) => r.result);
|
|
46702
|
+
return Promise.resolve(strs.map((s) => _casDerivativeOne(s, variable)));
|
|
46469
46703
|
}
|
|
46470
46704
|
function casExpand(input) {
|
|
46471
46705
|
if (!Array.isArray(input)) {
|