@danielsimonjr/mathts-functions 0.60.0 → 0.62.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/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/cas/rational-integrate.d.ts +72 -17
- package/dist/cas/rational-integrate.d.ts.map +1 -1
- package/dist/complex/arg.d.ts.map +1 -1
- package/dist/core/function/import.d.ts.map +1 -1
- package/dist/factories/index.d.ts +1 -1
- package/dist/factories/index.d.ts.map +1 -1
- package/dist/geometry/intersect.d.ts.map +1 -1
- package/dist/index.js +313 -260
- package/dist/matrix/concat.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/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/integer-poly.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/polynomial-ideal.d.ts +12 -1
- package/dist/typed/polynomial-ideal.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 +6 -6
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) {
|
|
@@ -9734,18 +9756,55 @@ function polyFromExpression(expr, vars) {
|
|
|
9734
9756
|
return result;
|
|
9735
9757
|
}
|
|
9736
9758
|
function divides(a, b) {
|
|
9737
|
-
|
|
9759
|
+
for (let i = 0; i < a.length; i++) {
|
|
9760
|
+
if (a[i] > b[i]) return false;
|
|
9761
|
+
}
|
|
9762
|
+
return true;
|
|
9763
|
+
}
|
|
9764
|
+
function totalDegree(powers) {
|
|
9765
|
+
let sum3 = 0;
|
|
9766
|
+
for (let i = 0; i < powers.length; i++) sum3 += powers[i];
|
|
9767
|
+
return sum3;
|
|
9738
9768
|
}
|
|
9769
|
+
var DivisorGeobucket = class {
|
|
9770
|
+
buckets = [];
|
|
9771
|
+
maxDeg = 0;
|
|
9772
|
+
constructor(polys) {
|
|
9773
|
+
for (const p of polys) this.insert(p);
|
|
9774
|
+
}
|
|
9775
|
+
insert(poly) {
|
|
9776
|
+
if (poly.length === 0) return;
|
|
9777
|
+
const d = totalDegree(poly[0].powers);
|
|
9778
|
+
if (!this.buckets[d]) this.buckets[d] = [];
|
|
9779
|
+
this.buckets[d].push(poly);
|
|
9780
|
+
if (d > this.maxDeg) this.maxDeg = d;
|
|
9781
|
+
}
|
|
9782
|
+
find(target) {
|
|
9783
|
+
const d = totalDegree(target);
|
|
9784
|
+
const limit2 = d < this.maxDeg ? d : this.maxDeg;
|
|
9785
|
+
for (let i = 0; i <= limit2; i++) {
|
|
9786
|
+
const bucket = this.buckets[i];
|
|
9787
|
+
if (!bucket) continue;
|
|
9788
|
+
for (let j = 0; j < bucket.length; j++) {
|
|
9789
|
+
if (divides(bucket[j][0].powers, target)) {
|
|
9790
|
+
return bucket[j];
|
|
9791
|
+
}
|
|
9792
|
+
}
|
|
9793
|
+
}
|
|
9794
|
+
return void 0;
|
|
9795
|
+
}
|
|
9796
|
+
};
|
|
9739
9797
|
function polyReduce(p, G) {
|
|
9740
9798
|
const rem = [];
|
|
9741
9799
|
let work = normalize(p);
|
|
9742
9800
|
let guard = 0;
|
|
9801
|
+
const index = Array.isArray(G) ? new DivisorGeobucket(G) : G;
|
|
9743
9802
|
while (work.length > 0) {
|
|
9744
9803
|
if (++guard > 2e4) {
|
|
9745
9804
|
throw new Error("polyReduce: iteration cap exceeded (system too large for this CAS)");
|
|
9746
9805
|
}
|
|
9747
9806
|
const lt = work[0];
|
|
9748
|
-
const g =
|
|
9807
|
+
const g = index.find(lt.powers);
|
|
9749
9808
|
if (g) {
|
|
9750
9809
|
const factor2 = [
|
|
9751
9810
|
{
|
|
@@ -9783,15 +9842,18 @@ function buchberger(input) {
|
|
|
9783
9842
|
for (let j = i + 1; j < G.length; j++) pairs.push([i, j]);
|
|
9784
9843
|
}
|
|
9785
9844
|
let iter = 0;
|
|
9845
|
+
const index = new DivisorGeobucket(G);
|
|
9786
9846
|
while (pairs.length > 0) {
|
|
9787
9847
|
if (++iter > 2e3 || G.length > 64) {
|
|
9788
9848
|
throw new Error("groebnerBasis: system too large (iteration/basis cap exceeded)");
|
|
9789
9849
|
}
|
|
9790
9850
|
const [i, j] = pairs.shift();
|
|
9791
|
-
const s = polyReduce(sPoly(G[i], G[j]),
|
|
9851
|
+
const s = polyReduce(sPoly(G[i], G[j]), index);
|
|
9792
9852
|
if (s.length > 0) {
|
|
9793
9853
|
const k = G.length;
|
|
9794
|
-
|
|
9854
|
+
const newPoly = monic(s);
|
|
9855
|
+
G.push(newPoly);
|
|
9856
|
+
index.insert(newPoly);
|
|
9795
9857
|
for (let t = 0; t < k; t++) pairs.push([t, k]);
|
|
9796
9858
|
}
|
|
9797
9859
|
}
|
|
@@ -10019,11 +10081,15 @@ function landauMignotte(p) {
|
|
|
10019
10081
|
return 1n;
|
|
10020
10082
|
}
|
|
10021
10083
|
const n = BigInt(d + 1);
|
|
10022
|
-
const lcAbs = t[d] < 0n ? -t[d] : t[d];
|
|
10023
10084
|
const powerOfTwo = 1n << BigInt(d);
|
|
10085
|
+
let normSq = 0n;
|
|
10086
|
+
for (const c of t) {
|
|
10087
|
+
normSq += c * c;
|
|
10088
|
+
}
|
|
10089
|
+
const norm2Ceil = isqrt(normSq) + 1n;
|
|
10024
10090
|
const sq = isqrt(n);
|
|
10025
10091
|
const sqrtCeil = sq * sq === n ? sq : sq + 1n;
|
|
10026
|
-
const bound = sqrtCeil * powerOfTwo *
|
|
10092
|
+
const bound = sqrtCeil * powerOfTwo * norm2Ceil;
|
|
10027
10093
|
return bound > 0n ? bound : 1n;
|
|
10028
10094
|
}
|
|
10029
10095
|
function modSymmetric(p, m) {
|
|
@@ -10610,7 +10676,7 @@ function degreeIn(p, varIndex) {
|
|
|
10610
10676
|
}
|
|
10611
10677
|
return d;
|
|
10612
10678
|
}
|
|
10613
|
-
function
|
|
10679
|
+
function totalDegree2(p) {
|
|
10614
10680
|
let d = -1;
|
|
10615
10681
|
for (const k of p.terms.keys()) {
|
|
10616
10682
|
const exps = unkey(k);
|
|
@@ -10896,7 +10962,7 @@ function candidateFor(pool, indices, bases, degBounds, vars) {
|
|
|
10896
10962
|
return null;
|
|
10897
10963
|
}
|
|
10898
10964
|
const cand = primitivePartMP(back);
|
|
10899
|
-
if (
|
|
10965
|
+
if (totalDegree2(cand) < 1) {
|
|
10900
10966
|
return null;
|
|
10901
10967
|
}
|
|
10902
10968
|
return cand;
|
|
@@ -10914,7 +10980,7 @@ function factorMultivariateKronecker(p) {
|
|
|
10914
10980
|
if (p.vars.length < 2) {
|
|
10915
10981
|
return null;
|
|
10916
10982
|
}
|
|
10917
|
-
if (isZero2(p) ||
|
|
10983
|
+
if (isZero2(p) || totalDegree2(p) < 1) {
|
|
10918
10984
|
return null;
|
|
10919
10985
|
}
|
|
10920
10986
|
const cont = integerContentMP(p);
|
|
@@ -10993,7 +11059,7 @@ function factorMultivariateKronecker(p) {
|
|
|
10993
11059
|
const l = leadingTerm(gCur);
|
|
10994
11060
|
const sgn = l !== null && l.coeff < 0n ? -1n : 1n;
|
|
10995
11061
|
constant *= c * sgn;
|
|
10996
|
-
if (
|
|
11062
|
+
if (totalDegree2(gCur) >= 1) {
|
|
10997
11063
|
found.push({ poly: primitivePartMP(gCur), mult: 1 });
|
|
10998
11064
|
}
|
|
10999
11065
|
}
|
|
@@ -22004,11 +22070,11 @@ var createSubtractScalar = /* @__PURE__ */ factory(
|
|
|
22004
22070
|
|
|
22005
22071
|
// src/arithmetic/unaryMinus.ts
|
|
22006
22072
|
var name14 = "unaryMinus";
|
|
22007
|
-
var dependencies14 = ["typed", "config", "?bignumber"];
|
|
22073
|
+
var dependencies14 = ["typed", "config", "?bignumber", "?fraction"];
|
|
22008
22074
|
var createUnaryMinus = /* @__PURE__ */ factory(
|
|
22009
22075
|
name14,
|
|
22010
22076
|
dependencies14,
|
|
22011
|
-
({ typed: typed3, config: config2, bignumber: bignumber2 }) => {
|
|
22077
|
+
({ typed: typed3, config: config2, bignumber: bignumber2, fraction: fraction2 }) => {
|
|
22012
22078
|
return typed3(name14, {
|
|
22013
22079
|
number: unaryMinusNumber,
|
|
22014
22080
|
"Complex | BigNumber | Fraction": (x) => x.neg(),
|
|
@@ -22031,7 +22097,10 @@ var createUnaryMinus = /* @__PURE__ */ factory(
|
|
|
22031
22097
|
case "bigint":
|
|
22032
22098
|
return BigInt(negValue);
|
|
22033
22099
|
case "Fraction":
|
|
22034
|
-
|
|
22100
|
+
if (!fraction2) {
|
|
22101
|
+
throw new Error("Fraction not available. Configure mathjs with Fraction support.");
|
|
22102
|
+
}
|
|
22103
|
+
return fraction2(negValue);
|
|
22035
22104
|
case "number":
|
|
22036
22105
|
default:
|
|
22037
22106
|
return negValue;
|
|
@@ -22348,7 +22417,6 @@ var createArg = /* @__PURE__ */ factory(
|
|
|
22348
22417
|
Complex: function(x) {
|
|
22349
22418
|
return x.arg();
|
|
22350
22419
|
},
|
|
22351
|
-
// TODO: implement BigNumber support for function arg
|
|
22352
22420
|
"Array | Matrix": typed3.referToSelf(
|
|
22353
22421
|
(self) => (x) => deepMap(x, self)
|
|
22354
22422
|
)
|
|
@@ -23190,26 +23258,36 @@ function randomMatrix(size2, random3) {
|
|
|
23190
23258
|
// src/probability/random.ts
|
|
23191
23259
|
var name32 = "random";
|
|
23192
23260
|
var dependencies32 = ["typed", "config", "?on"];
|
|
23261
|
+
function _createRng(config2, on) {
|
|
23262
|
+
let rng = createRng(config2.randomSeed);
|
|
23263
|
+
if (on) {
|
|
23264
|
+
on("config", function(curr, prev) {
|
|
23265
|
+
if (curr.randomSeed !== prev.randomSeed) {
|
|
23266
|
+
rng = createRng(curr.randomSeed);
|
|
23267
|
+
}
|
|
23268
|
+
});
|
|
23269
|
+
}
|
|
23270
|
+
return () => rng();
|
|
23271
|
+
}
|
|
23272
|
+
function _createRandomSignatures(rng) {
|
|
23273
|
+
function _random(min2, max2) {
|
|
23274
|
+
return min2 + rng() * (max2 - min2);
|
|
23275
|
+
}
|
|
23276
|
+
return {
|
|
23277
|
+
_random,
|
|
23278
|
+
signatures: {
|
|
23279
|
+
"": () => _random(0, 1),
|
|
23280
|
+
number: (max2) => _random(0, max2),
|
|
23281
|
+
"number, number": (min2, max2) => _random(min2, max2)
|
|
23282
|
+
}
|
|
23283
|
+
};
|
|
23284
|
+
}
|
|
23193
23285
|
var createRandom = /* @__PURE__ */ factory(
|
|
23194
23286
|
name32,
|
|
23195
23287
|
dependencies32,
|
|
23196
23288
|
({ typed: typed3, config: config2, on }) => {
|
|
23197
|
-
|
|
23198
|
-
|
|
23199
|
-
on("config", function(curr, prev) {
|
|
23200
|
-
if (curr.randomSeed !== prev.randomSeed) {
|
|
23201
|
-
rng = createRng(curr.randomSeed);
|
|
23202
|
-
}
|
|
23203
|
-
});
|
|
23204
|
-
}
|
|
23205
|
-
return typed3(name32, {
|
|
23206
|
-
"": () => _random(0, 1),
|
|
23207
|
-
number: (max2) => _random(0, max2),
|
|
23208
|
-
"number, number": (min2, max2) => _random(min2, max2),
|
|
23209
|
-
"Array | Matrix": (size2) => _randomMatrix(size2, 0, 1),
|
|
23210
|
-
"Array | Matrix, number": (size2, max2) => _randomMatrix(size2, 0, max2),
|
|
23211
|
-
"Array | Matrix, number, number": (size2, min2, max2) => _randomMatrix(size2, min2, max2)
|
|
23212
|
-
});
|
|
23289
|
+
const rng = _createRng(config2, on);
|
|
23290
|
+
const { _random, signatures } = _createRandomSignatures(rng);
|
|
23213
23291
|
function _randomMatrix(size2, min2, max2) {
|
|
23214
23292
|
const res = randomMatrix(
|
|
23215
23293
|
size2.valueOf(),
|
|
@@ -23217,9 +23295,12 @@ var createRandom = /* @__PURE__ */ factory(
|
|
|
23217
23295
|
);
|
|
23218
23296
|
return isMatrix(size2) ? size2.create(res, "number") : res;
|
|
23219
23297
|
}
|
|
23220
|
-
|
|
23221
|
-
|
|
23222
|
-
|
|
23298
|
+
return typed3(name32, {
|
|
23299
|
+
...signatures,
|
|
23300
|
+
"Array | Matrix": (size2) => _randomMatrix(size2, 0, 1),
|
|
23301
|
+
"Array | Matrix, number": (size2, max2) => _randomMatrix(size2, 0, max2),
|
|
23302
|
+
"Array | Matrix, number, number": (size2, min2, max2) => _randomMatrix(size2, min2, max2)
|
|
23303
|
+
});
|
|
23223
23304
|
}
|
|
23224
23305
|
);
|
|
23225
23306
|
|
|
@@ -24651,9 +24732,7 @@ var createProd = /* @__PURE__ */ factory(
|
|
|
24651
24732
|
// prod([a, b, c, d, ...])
|
|
24652
24733
|
"Array | Matrix": _prod,
|
|
24653
24734
|
// prod([a, b, c, d, ...], dim)
|
|
24654
|
-
"Array | Matrix, number | BigNumber":
|
|
24655
|
-
throw new Error("prod(A, dim) is not yet supported");
|
|
24656
|
-
},
|
|
24735
|
+
"Array | Matrix, number | BigNumber": _nprodDim,
|
|
24657
24736
|
// prod(a, b, c, d, ...)
|
|
24658
24737
|
"...": function(args) {
|
|
24659
24738
|
return _prod(args);
|
|
@@ -24690,6 +24769,15 @@ var createProd = /* @__PURE__ */ factory(
|
|
|
24690
24769
|
}
|
|
24691
24770
|
return prod2;
|
|
24692
24771
|
}
|
|
24772
|
+
function _nprodDim(array, dim) {
|
|
24773
|
+
try {
|
|
24774
|
+
const dimValue = typeof dim === "number" ? dim : dim.valueOf();
|
|
24775
|
+
const prod2 = reduce2(array, dimValue, multiplyScalar2);
|
|
24776
|
+
return prod2;
|
|
24777
|
+
} catch (err) {
|
|
24778
|
+
throw improveErrorMessage(err, "prod", void 0);
|
|
24779
|
+
}
|
|
24780
|
+
}
|
|
24693
24781
|
}
|
|
24694
24782
|
);
|
|
24695
24783
|
|
|
@@ -24802,11 +24890,11 @@ var createIsZero = /* @__PURE__ */ factory(
|
|
|
24802
24890
|
|
|
24803
24891
|
// src/utils/parseNumber.ts
|
|
24804
24892
|
var name83 = "parseNumberWithConfig";
|
|
24805
|
-
var dependencies83 = ["config", "?bignumber"];
|
|
24893
|
+
var dependencies83 = ["config", "?bignumber", "?fraction"];
|
|
24806
24894
|
var createParseNumberWithConfig = /* @__PURE__ */ factory(
|
|
24807
24895
|
name83,
|
|
24808
24896
|
dependencies83,
|
|
24809
|
-
({ config: config2, bignumber: bignumber2 }) => {
|
|
24897
|
+
({ config: config2, bignumber: bignumber2, fraction: fraction2 }) => {
|
|
24810
24898
|
function parseNumberWithConfig2(str) {
|
|
24811
24899
|
if (typeof str !== "string") {
|
|
24812
24900
|
throw new TypeError(`parseNumberWithConfig expects string, got ${typeof str}`);
|
|
@@ -24832,11 +24920,10 @@ var createParseNumberWithConfig = /* @__PURE__ */ factory(
|
|
|
24832
24920
|
throw new SyntaxError(`String "${str}" is not a valid number`);
|
|
24833
24921
|
}
|
|
24834
24922
|
case "Fraction": {
|
|
24835
|
-
|
|
24836
|
-
|
|
24837
|
-
throw new SyntaxError(`String "${str}" is not a valid number`);
|
|
24923
|
+
if (!fraction2) {
|
|
24924
|
+
throw new Error("Fraction not available. Configure mathjs with Fraction support.");
|
|
24838
24925
|
}
|
|
24839
|
-
return
|
|
24926
|
+
return fraction2(str);
|
|
24840
24927
|
}
|
|
24841
24928
|
case "number":
|
|
24842
24929
|
default: {
|
|
@@ -28052,19 +28139,22 @@ var createRound = /* @__PURE__ */ factory(
|
|
|
28052
28139
|
|
|
28053
28140
|
// src/arithmetic/xgcd.ts
|
|
28054
28141
|
var name112 = "xgcd";
|
|
28055
|
-
var dependencies112 = ["typed", "config", "matrix", "BigNumber"];
|
|
28142
|
+
var dependencies112 = ["typed", "config", "matrix", "BigNumber", "?Fraction"];
|
|
28056
28143
|
var createXgcd = /* @__PURE__ */ factory(
|
|
28057
28144
|
name112,
|
|
28058
28145
|
dependencies112,
|
|
28059
|
-
({ typed: typed3, config: config2, matrix: matrix2, BigNumber: BigNumber9 }) => {
|
|
28060
|
-
|
|
28146
|
+
({ typed: typed3, config: config2, matrix: matrix2, BigNumber: BigNumber9, Fraction: Fraction5 }) => {
|
|
28147
|
+
const typedSignatures = {
|
|
28061
28148
|
"number, number": function(a, b) {
|
|
28062
28149
|
const res = xgcdNumber(a, b);
|
|
28063
28150
|
return config2.matrix === "Array" ? res : matrix2(res);
|
|
28064
28151
|
},
|
|
28065
28152
|
"BigNumber, BigNumber": _xgcdBigNumber
|
|
28066
|
-
|
|
28067
|
-
|
|
28153
|
+
};
|
|
28154
|
+
if (Fraction5) {
|
|
28155
|
+
typedSignatures["Fraction, Fraction"] = _xgcdFraction;
|
|
28156
|
+
}
|
|
28157
|
+
return typed3(name112, typedSignatures);
|
|
28068
28158
|
function _xgcdBigNumber(a, b) {
|
|
28069
28159
|
let t;
|
|
28070
28160
|
let q;
|
|
@@ -28098,6 +28188,42 @@ var createXgcd = /* @__PURE__ */ factory(
|
|
|
28098
28188
|
}
|
|
28099
28189
|
return config2.matrix === "Array" ? res : matrix2(res);
|
|
28100
28190
|
}
|
|
28191
|
+
function _xgcdFraction(a, b) {
|
|
28192
|
+
if (!Fraction5) {
|
|
28193
|
+
throw new Error("Fraction is not available");
|
|
28194
|
+
}
|
|
28195
|
+
let t;
|
|
28196
|
+
let q;
|
|
28197
|
+
let r;
|
|
28198
|
+
const zero = new Fraction5(0);
|
|
28199
|
+
const one = new Fraction5(1);
|
|
28200
|
+
let x = zero;
|
|
28201
|
+
let lastx = one;
|
|
28202
|
+
let y = one;
|
|
28203
|
+
let lasty = zero;
|
|
28204
|
+
if (!a.isInteger() || !b.isInteger()) {
|
|
28205
|
+
throw new Error("Parameters in function xgcd must be integer numbers");
|
|
28206
|
+
}
|
|
28207
|
+
while (!b.isZero()) {
|
|
28208
|
+
q = a.divide(b).floor();
|
|
28209
|
+
r = a.mod(b);
|
|
28210
|
+
t = x;
|
|
28211
|
+
x = lastx.subtract(q.multiply(x));
|
|
28212
|
+
lastx = t;
|
|
28213
|
+
t = y;
|
|
28214
|
+
y = lasty.subtract(q.multiply(y));
|
|
28215
|
+
lasty = t;
|
|
28216
|
+
a = b;
|
|
28217
|
+
b = r;
|
|
28218
|
+
}
|
|
28219
|
+
let res;
|
|
28220
|
+
if (a.lessThan(zero)) {
|
|
28221
|
+
res = [a.negate(), lastx.negate(), lasty.negate()];
|
|
28222
|
+
} else {
|
|
28223
|
+
res = [a, !a.isZero() ? lastx : 0, lasty];
|
|
28224
|
+
}
|
|
28225
|
+
return config2.matrix === "Array" ? res : matrix2(res);
|
|
28226
|
+
}
|
|
28101
28227
|
}
|
|
28102
28228
|
);
|
|
28103
28229
|
|
|
@@ -28181,9 +28307,6 @@ var createCatalan = /* @__PURE__ */ factory(
|
|
|
28181
28307
|
}
|
|
28182
28308
|
);
|
|
28183
28309
|
|
|
28184
|
-
// src/error/IndexError.ts
|
|
28185
|
-
import { IndexError, createIndexError } from "@danielsimonjr/mathts-core/internal";
|
|
28186
|
-
|
|
28187
28310
|
// src/error/DimensionError.ts
|
|
28188
28311
|
import { DimensionError } from "@danielsimonjr/mathts-core/internal";
|
|
28189
28312
|
|
|
@@ -28218,7 +28341,7 @@ var createConcat = /* @__PURE__ */ factory(
|
|
|
28218
28341
|
throw new TypeError("Integer number expected for dimension");
|
|
28219
28342
|
}
|
|
28220
28343
|
if (dim < 0 || i > 0 && dim > prevDim) {
|
|
28221
|
-
throw new
|
|
28344
|
+
throw new DimensionError(dim, dim < 0 ? 0 : prevDim, dim < 0 ? "<" : ">");
|
|
28222
28345
|
}
|
|
28223
28346
|
} else {
|
|
28224
28347
|
const m = clone(arg3).valueOf();
|
|
@@ -28445,6 +28568,9 @@ var createInv = /* @__PURE__ */ factory(
|
|
|
28445
28568
|
}
|
|
28446
28569
|
);
|
|
28447
28570
|
|
|
28571
|
+
// src/error/IndexError.ts
|
|
28572
|
+
import { IndexError, createIndexError } from "@danielsimonjr/mathts-core/internal";
|
|
28573
|
+
|
|
28448
28574
|
// src/matrix/mapSlices.ts
|
|
28449
28575
|
var name117 = "mapSlices";
|
|
28450
28576
|
var dependencies117 = ["typed", "isInteger"];
|
|
@@ -28733,7 +28859,7 @@ var createSubset = /* @__PURE__ */ factory(
|
|
|
28733
28859
|
);
|
|
28734
28860
|
function _getSubstring(str, index) {
|
|
28735
28861
|
if (!isIndex(index)) {
|
|
28736
|
-
throw new TypeError("Index
|
|
28862
|
+
throw new TypeError("Invalid index: must be an Index or Index-like object");
|
|
28737
28863
|
}
|
|
28738
28864
|
if (isEmptyIndex(index)) {
|
|
28739
28865
|
return "";
|
|
@@ -28759,7 +28885,7 @@ function _getSubstring(str, index) {
|
|
|
28759
28885
|
}
|
|
28760
28886
|
function _setSubstring(str, index, replacement, defaultValue) {
|
|
28761
28887
|
if (!index || index.isIndex !== true) {
|
|
28762
|
-
throw new TypeError("Index
|
|
28888
|
+
throw new TypeError("Invalid index: must be an Index or Index-like object");
|
|
28763
28889
|
}
|
|
28764
28890
|
if (isEmptyIndex(index)) {
|
|
28765
28891
|
return str;
|
|
@@ -29515,7 +29641,7 @@ var createCumSum = /* @__PURE__ */ factory(
|
|
|
29515
29641
|
const size2 = arraySize(array);
|
|
29516
29642
|
const dimValue = typeof dim === "number" ? dim : dim.valueOf();
|
|
29517
29643
|
if (dimValue < 0 || dimValue >= size2.length) {
|
|
29518
|
-
throw new
|
|
29644
|
+
throw new DimensionError(dimValue, size2.length, "<");
|
|
29519
29645
|
}
|
|
29520
29646
|
try {
|
|
29521
29647
|
return _cumsumDimensional(array, dimValue);
|
|
@@ -35389,13 +35515,21 @@ var dependencies199 = [
|
|
|
35389
35515
|
"multiply",
|
|
35390
35516
|
"equalScalar",
|
|
35391
35517
|
"divideScalar",
|
|
35392
|
-
"
|
|
35518
|
+
"pinv",
|
|
35393
35519
|
"nodeOperations"
|
|
35394
35520
|
];
|
|
35395
35521
|
var createDivide = /* @__PURE__ */ factory(
|
|
35396
35522
|
name199,
|
|
35397
35523
|
dependencies199,
|
|
35398
|
-
({
|
|
35524
|
+
({
|
|
35525
|
+
typed: typed3,
|
|
35526
|
+
matrix: matrix2,
|
|
35527
|
+
multiply: multiply2,
|
|
35528
|
+
equalScalar: equalScalar3,
|
|
35529
|
+
divideScalar: divideScalar2,
|
|
35530
|
+
pinv: pinv2,
|
|
35531
|
+
nodeOperations: nodeOperations2
|
|
35532
|
+
}) => {
|
|
35399
35533
|
const matAlgo11xS0s = createMatAlgo11xS0s({ typed: typed3, equalScalar: equalScalar3 });
|
|
35400
35534
|
const matAlgo14xDs = createMatAlgo14xDs({ typed: typed3 });
|
|
35401
35535
|
return typed3(
|
|
@@ -35423,7 +35557,7 @@ var createDivide = /* @__PURE__ */ factory(
|
|
|
35423
35557
|
// MATRIX SIGNATURES - Deal with matrices
|
|
35424
35558
|
// =========================================================================
|
|
35425
35559
|
"Array | Matrix, Array | Matrix": function(x, y) {
|
|
35426
|
-
return multiply2(x,
|
|
35560
|
+
return multiply2(x, pinv2(y));
|
|
35427
35561
|
},
|
|
35428
35562
|
"DenseMatrix, any": function(x, y) {
|
|
35429
35563
|
return matAlgo14xDs(
|
|
@@ -35450,7 +35584,7 @@ var createDivide = /* @__PURE__ */ factory(
|
|
|
35450
35584
|
).valueOf();
|
|
35451
35585
|
},
|
|
35452
35586
|
"any, Array | Matrix": function(x, y) {
|
|
35453
|
-
return multiply2(x,
|
|
35587
|
+
return multiply2(x, pinv2(y));
|
|
35454
35588
|
}
|
|
35455
35589
|
},
|
|
35456
35590
|
divideScalar2.signatures
|
|
@@ -37834,6 +37968,15 @@ var createIntersect = /* @__PURE__ */ factory(
|
|
|
37834
37968
|
),
|
|
37835
37969
|
z1z
|
|
37836
37970
|
);
|
|
37971
|
+
if (isZero4(denominator) || smaller2(abs2(denominator), config2.relTol)) {
|
|
37972
|
+
if (isZero4(numerator) || smaller2(abs2(numerator), config2.relTol)) {
|
|
37973
|
+
return [
|
|
37974
|
+
[x1, y1, z1],
|
|
37975
|
+
[x2, y2, z2]
|
|
37976
|
+
];
|
|
37977
|
+
}
|
|
37978
|
+
return null;
|
|
37979
|
+
}
|
|
37837
37980
|
const t = divideScalar2(numerator, denominator);
|
|
37838
37981
|
const px = addScalar2(x1, multiplyScalar2(t, subtract3(x2, x1)));
|
|
37839
37982
|
const py = addScalar2(y1, multiplyScalar2(t, subtract3(y2, y1)));
|
|
@@ -37919,11 +38062,11 @@ var createMean = /* @__PURE__ */ factory(
|
|
|
37919
38062
|
|
|
37920
38063
|
// src/statistics/median.ts
|
|
37921
38064
|
var name220 = "median";
|
|
37922
|
-
var dependencies220 = ["typed", "add", "divide", "compare", "partitionSelect"];
|
|
38065
|
+
var dependencies220 = ["typed", "add", "divide", "compare", "partitionSelect", "mapSlices"];
|
|
37923
38066
|
var createMedian = /* @__PURE__ */ factory(
|
|
37924
38067
|
name220,
|
|
37925
38068
|
dependencies220,
|
|
37926
|
-
({ typed: typed3, add: add5, divide: divide2, compare: compare2, partitionSelect: partitionSelect2 }) => {
|
|
38069
|
+
({ typed: typed3, add: add5, divide: divide2, compare: compare2, partitionSelect: partitionSelect2, mapSlices: mapSlices2 }) => {
|
|
37927
38070
|
function _median2(array) {
|
|
37928
38071
|
try {
|
|
37929
38072
|
const flat = flatten2(array.valueOf());
|
|
@@ -37964,7 +38107,11 @@ var createMedian = /* @__PURE__ */ factory(
|
|
|
37964
38107
|
"Array | Matrix": _median2,
|
|
37965
38108
|
// median([a, b, c, d, ...], dim)
|
|
37966
38109
|
"Array | Matrix, number | BigNumber": function(_array, _dim) {
|
|
37967
|
-
|
|
38110
|
+
try {
|
|
38111
|
+
return mapSlices2(_array, _dim, (x) => _median2(x));
|
|
38112
|
+
} catch (err) {
|
|
38113
|
+
throw improveErrorMessage(err, "median", void 0);
|
|
38114
|
+
}
|
|
37968
38115
|
},
|
|
37969
38116
|
// median(a, b, c, d, ...)
|
|
37970
38117
|
"...": function(args) {
|
|
@@ -42793,7 +42940,6 @@ var createRationalize = /* @__PURE__ */ factory(
|
|
|
42793
42940
|
const variables2 = [];
|
|
42794
42941
|
const node = simplify2(expr, rules, scope, { exactFractions: false });
|
|
42795
42942
|
extended = !!extended;
|
|
42796
|
-
const oper = "+-*" + (extended ? "/" : "");
|
|
42797
42943
|
recPoly(node);
|
|
42798
42944
|
const retFunc = {};
|
|
42799
42945
|
retFunc.expression = node;
|
|
@@ -42811,9 +42957,10 @@ var createRationalize = /* @__PURE__ */ factory(
|
|
|
42811
42957
|
recPoly(node2.args[0]);
|
|
42812
42958
|
}
|
|
42813
42959
|
} else {
|
|
42814
|
-
|
|
42960
|
+
const op = node2.op;
|
|
42961
|
+
if (op !== "+" && op !== "-" && op !== "*" && op !== "^" && (!extended || op !== "/")) {
|
|
42815
42962
|
throw new Error(
|
|
42816
|
-
"Operator " +
|
|
42963
|
+
"Operator " + op + " invalid in polynomial expression"
|
|
42817
42964
|
);
|
|
42818
42965
|
}
|
|
42819
42966
|
for (let i = 0; i < node2.args.length; i++) {
|
|
@@ -43053,8 +43200,9 @@ var createRationalize = /* @__PURE__ */ factory(
|
|
|
43053
43200
|
if (tp === "FunctionNode") {
|
|
43054
43201
|
throw new Error("There is an unsolved function call");
|
|
43055
43202
|
} else if (tp === "OperatorNode") {
|
|
43056
|
-
|
|
43057
|
-
|
|
43203
|
+
const op = node2.op;
|
|
43204
|
+
if (op !== "+" && op !== "-" && op !== "*" && op !== "^")
|
|
43205
|
+
throw new Error("Operator " + op + " invalid");
|
|
43058
43206
|
if (noPai !== null) {
|
|
43059
43207
|
if ((node2.fn === "unaryMinus" || node2.fn === "pow") && noPai.fn !== "add" && noPai.fn !== "subtract" && noPai.fn !== "multiply") {
|
|
43060
43208
|
throw new Error("Invalid " + node2.op + " placing");
|
|
@@ -44771,7 +44919,6 @@ function reviver(_key, value) {
|
|
|
44771
44919
|
}
|
|
44772
44920
|
|
|
44773
44921
|
// src/typed/cas.ts
|
|
44774
|
-
import { computePool as computePool12 } from "@danielsimonjr/mathts-parallel";
|
|
44775
44922
|
import { Complex as Complex10 } from "@danielsimonjr/mathts-core";
|
|
44776
44923
|
|
|
44777
44924
|
// src/numeric/numeric-jacobian.ts
|
|
@@ -46208,15 +46355,17 @@ function _combineLikeTerms(expr) {
|
|
|
46208
46355
|
return parts.join(" + ").replace(/\+\s*-/g, "- ");
|
|
46209
46356
|
}
|
|
46210
46357
|
function _casDerivativeOne(expr, variable) {
|
|
46358
|
+
if (expr.indexOf(variable) === -1) return "0";
|
|
46211
46359
|
const terms = expr.split(/\s*\+\s*/);
|
|
46212
46360
|
const derivedTerms = [];
|
|
46361
|
+
const powerRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "\\^(\\d+)$");
|
|
46362
|
+
const linearRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "$");
|
|
46213
46363
|
for (const term of terms) {
|
|
46214
46364
|
const t = term.trim();
|
|
46215
|
-
if (
|
|
46365
|
+
if (t.indexOf(variable) === -1) {
|
|
46216
46366
|
derivedTerms.push("0");
|
|
46217
46367
|
continue;
|
|
46218
46368
|
}
|
|
46219
|
-
const powerRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "\\^(\\d+)$");
|
|
46220
46369
|
const powerMatch = t.match(powerRe);
|
|
46221
46370
|
if (powerMatch) {
|
|
46222
46371
|
const coeff = powerMatch[1] === "" || powerMatch[1] === void 0 ? 1 : parseFloat(powerMatch[1]);
|
|
@@ -46230,7 +46379,6 @@ function _casDerivativeOne(expr, variable) {
|
|
|
46230
46379
|
}
|
|
46231
46380
|
continue;
|
|
46232
46381
|
}
|
|
46233
|
-
const linearRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + variable + "$");
|
|
46234
46382
|
const linearMatch = t.match(linearRe);
|
|
46235
46383
|
if (linearMatch) {
|
|
46236
46384
|
const coeff = linearMatch[1] === "" ? 1 : parseFloat(linearMatch[1]);
|
|
@@ -46269,199 +46417,14 @@ function casSimplify(input) {
|
|
|
46269
46417
|
return _casSimplifyOne(_nodeToStr(input));
|
|
46270
46418
|
}
|
|
46271
46419
|
const strs = input.map(_nodeToStr);
|
|
46272
|
-
|
|
46273
|
-
return Promise.resolve(strs.map(_casSimplifyOne));
|
|
46274
|
-
}
|
|
46275
|
-
return computePool12.map(strs, (exprStr) => {
|
|
46276
|
-
function _evalNumeric2(exprStr2) {
|
|
46277
|
-
let pos = 0;
|
|
46278
|
-
const s = exprStr2.replace(/\s+/g, "");
|
|
46279
|
-
const parseExpr = () => {
|
|
46280
|
-
let val = parseTerm();
|
|
46281
|
-
while (pos < s.length) {
|
|
46282
|
-
if (s[pos] === "+") {
|
|
46283
|
-
pos++;
|
|
46284
|
-
val += parseTerm();
|
|
46285
|
-
} else if (s[pos] === "-") {
|
|
46286
|
-
pos++;
|
|
46287
|
-
val -= parseTerm();
|
|
46288
|
-
} else break;
|
|
46289
|
-
}
|
|
46290
|
-
return val;
|
|
46291
|
-
};
|
|
46292
|
-
const parseTerm = () => {
|
|
46293
|
-
let val = parseFactor();
|
|
46294
|
-
while (pos < s.length) {
|
|
46295
|
-
if (s[pos] === "*") {
|
|
46296
|
-
pos++;
|
|
46297
|
-
val *= parseFactor();
|
|
46298
|
-
} else if (s[pos] === "/") {
|
|
46299
|
-
pos++;
|
|
46300
|
-
val /= parseFactor();
|
|
46301
|
-
} else break;
|
|
46302
|
-
}
|
|
46303
|
-
return val;
|
|
46304
|
-
};
|
|
46305
|
-
const parseFactor = () => {
|
|
46306
|
-
let val = parseBase();
|
|
46307
|
-
if (pos < s.length && s[pos] === "^") {
|
|
46308
|
-
pos++;
|
|
46309
|
-
val = Math.pow(val, parseFactor());
|
|
46310
|
-
}
|
|
46311
|
-
return val;
|
|
46312
|
-
};
|
|
46313
|
-
const parseBase = () => {
|
|
46314
|
-
if (s[pos] === "+") {
|
|
46315
|
-
pos++;
|
|
46316
|
-
return parseBase();
|
|
46317
|
-
}
|
|
46318
|
-
if (s[pos] === "-") {
|
|
46319
|
-
pos++;
|
|
46320
|
-
return -parseBase();
|
|
46321
|
-
}
|
|
46322
|
-
if (s[pos] === "(") {
|
|
46323
|
-
pos++;
|
|
46324
|
-
const val = parseExpr();
|
|
46325
|
-
if (s[pos] === ")") pos++;
|
|
46326
|
-
return val;
|
|
46327
|
-
}
|
|
46328
|
-
const start = pos;
|
|
46329
|
-
while (pos < s.length && /[\d.]/.test(s[pos])) pos++;
|
|
46330
|
-
if (start === pos) throw new Error();
|
|
46331
|
-
return parseFloat(s.substring(start, pos));
|
|
46332
|
-
};
|
|
46333
|
-
try {
|
|
46334
|
-
const val = parseExpr();
|
|
46335
|
-
if (pos === s.length && typeof val === "number" && isFinite(val)) {
|
|
46336
|
-
return String(val);
|
|
46337
|
-
}
|
|
46338
|
-
} catch {
|
|
46339
|
-
}
|
|
46340
|
-
return void 0;
|
|
46341
|
-
}
|
|
46342
|
-
function _combineLikeTermsW(expr) {
|
|
46343
|
-
const normalised = expr.replace(/\s*-\s*/g, " + -");
|
|
46344
|
-
const rawTerms = normalised.split(/\s*\+\s*/);
|
|
46345
|
-
const termMap = /* @__PURE__ */ new Map();
|
|
46346
|
-
const otherTerms = [];
|
|
46347
|
-
for (const raw of rawTerms) {
|
|
46348
|
-
const t = raw.trim();
|
|
46349
|
-
if (!t) continue;
|
|
46350
|
-
if (/^-?\d+(\.\d+)?$/.test(t)) {
|
|
46351
|
-
termMap.set("__const__", (termMap.get("__const__") ?? 0) + Number(t));
|
|
46352
|
-
continue;
|
|
46353
|
-
}
|
|
46354
|
-
const cvpMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)\^(\d+)$/);
|
|
46355
|
-
if (cvpMatch) {
|
|
46356
|
-
const c = cvpMatch[1] === "" || cvpMatch[1] === "+" ? 1 : cvpMatch[1] === "-" ? -1 : Number(cvpMatch[1]);
|
|
46357
|
-
const key2 = cvpMatch[2] + "^" + cvpMatch[3];
|
|
46358
|
-
termMap.set(key2, (termMap.get(key2) ?? 0) + c);
|
|
46359
|
-
continue;
|
|
46360
|
-
}
|
|
46361
|
-
const cvMatch = t.match(/^(-?\d*\.?\d*)\s*\*?\s*(\w+)$/);
|
|
46362
|
-
if (cvMatch && !/^\d+$/.test(cvMatch[2])) {
|
|
46363
|
-
const c = cvMatch[1] === "" || cvMatch[1] === "+" ? 1 : cvMatch[1] === "-" ? -1 : Number(cvMatch[1]);
|
|
46364
|
-
termMap.set(cvMatch[2], (termMap.get(cvMatch[2]) ?? 0) + c);
|
|
46365
|
-
continue;
|
|
46366
|
-
}
|
|
46367
|
-
otherTerms.push(t);
|
|
46368
|
-
}
|
|
46369
|
-
const parts = [];
|
|
46370
|
-
for (const [key2, c] of termMap) {
|
|
46371
|
-
if (Math.abs(c) < 1e-12) continue;
|
|
46372
|
-
if (key2 === "__const__") {
|
|
46373
|
-
parts.push(String(c));
|
|
46374
|
-
} else if (Math.abs(c - 1) < 1e-12) {
|
|
46375
|
-
parts.push(key2);
|
|
46376
|
-
} else if (Math.abs(c + 1) < 1e-12) {
|
|
46377
|
-
parts.push("-" + key2);
|
|
46378
|
-
} else {
|
|
46379
|
-
parts.push(c + "*" + key2);
|
|
46380
|
-
}
|
|
46381
|
-
}
|
|
46382
|
-
parts.push(...otherTerms);
|
|
46383
|
-
if (parts.length === 0) return "0";
|
|
46384
|
-
return parts.join(" + ").replace(/\+\s*-/g, "- ");
|
|
46385
|
-
}
|
|
46386
|
-
let r = exprStr.trim();
|
|
46387
|
-
r = r.replace(/\b(\w+)\^0\b/g, "1");
|
|
46388
|
-
r = r.replace(/\b(\w+)\^1\b/g, "$1");
|
|
46389
|
-
r = r.replace(/\b1\s*\*\s*/g, "");
|
|
46390
|
-
r = r.replace(/\s*\*\s*1\b/g, "");
|
|
46391
|
-
r = r.replace(/\b0\s*\+\s*/g, "");
|
|
46392
|
-
r = r.replace(/\s*\+\s*0\b/g, "");
|
|
46393
|
-
r = r.replace(/\b0\s*\*\s*[^+-]*/g, "0");
|
|
46394
|
-
if (/^[\d\s+\-*/().^]+$/.test(r)) {
|
|
46395
|
-
const val = _evalNumeric2(r);
|
|
46396
|
-
if (val !== void 0) return val;
|
|
46397
|
-
}
|
|
46398
|
-
return _combineLikeTermsW(r) || "0";
|
|
46399
|
-
}).then((r) => r.result);
|
|
46420
|
+
return Promise.resolve(strs.map(_casSimplifyOne));
|
|
46400
46421
|
}
|
|
46401
46422
|
function casDerivative(input, variable) {
|
|
46402
46423
|
if (!Array.isArray(input)) {
|
|
46403
46424
|
return _casDerivativeOne(_nodeToStr(input), variable);
|
|
46404
46425
|
}
|
|
46405
46426
|
const strs = input.map(_nodeToStr);
|
|
46406
|
-
|
|
46407
|
-
return Promise.resolve(strs.map((s) => _casDerivativeOne(s, variable)));
|
|
46408
|
-
}
|
|
46409
|
-
const varName = variable;
|
|
46410
|
-
return computePool12.map(strs, (exprStr) => {
|
|
46411
|
-
const _variable = varName;
|
|
46412
|
-
const terms = exprStr.split(/\s*\+\s*/);
|
|
46413
|
-
const derivedTerms = [];
|
|
46414
|
-
for (const term of terms) {
|
|
46415
|
-
const t = term.trim();
|
|
46416
|
-
if (!t.includes(_variable)) {
|
|
46417
|
-
derivedTerms.push("0");
|
|
46418
|
-
continue;
|
|
46419
|
-
}
|
|
46420
|
-
const powerRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + _variable + "\\^(\\d+)$");
|
|
46421
|
-
const powerMatch = t.match(powerRe);
|
|
46422
|
-
if (powerMatch) {
|
|
46423
|
-
const coeff = powerMatch[1] === "" || powerMatch[1] === void 0 ? 1 : parseFloat(powerMatch[1]);
|
|
46424
|
-
const n = parseInt(powerMatch[2], 10);
|
|
46425
|
-
if (n === 0) {
|
|
46426
|
-
derivedTerms.push("0");
|
|
46427
|
-
} else if (n === 1) {
|
|
46428
|
-
derivedTerms.push(String(coeff));
|
|
46429
|
-
} else {
|
|
46430
|
-
derivedTerms.push(coeff * n + "*" + _variable + "^" + (n - 1));
|
|
46431
|
-
}
|
|
46432
|
-
continue;
|
|
46433
|
-
}
|
|
46434
|
-
const linearRe = new RegExp("^(-?\\d*\\.?\\d*)\\s*\\*?\\s*" + _variable + "$");
|
|
46435
|
-
const linearMatch = t.match(linearRe);
|
|
46436
|
-
if (linearMatch) {
|
|
46437
|
-
const coeff = linearMatch[1] === "" ? 1 : parseFloat(linearMatch[1]);
|
|
46438
|
-
derivedTerms.push(String(coeff));
|
|
46439
|
-
continue;
|
|
46440
|
-
}
|
|
46441
|
-
if (t === _variable) {
|
|
46442
|
-
derivedTerms.push("1");
|
|
46443
|
-
continue;
|
|
46444
|
-
}
|
|
46445
|
-
if (t === "sin(" + _variable + ")") {
|
|
46446
|
-
derivedTerms.push("cos(" + _variable + ")");
|
|
46447
|
-
continue;
|
|
46448
|
-
}
|
|
46449
|
-
if (t === "cos(" + _variable + ")") {
|
|
46450
|
-
derivedTerms.push("-sin(" + _variable + ")");
|
|
46451
|
-
continue;
|
|
46452
|
-
}
|
|
46453
|
-
if (t === "exp(" + _variable + ")") {
|
|
46454
|
-
derivedTerms.push("exp(" + _variable + ")");
|
|
46455
|
-
continue;
|
|
46456
|
-
}
|
|
46457
|
-
if (t === "ln(" + _variable + ")") {
|
|
46458
|
-
derivedTerms.push("1/" + _variable);
|
|
46459
|
-
continue;
|
|
46460
|
-
}
|
|
46461
|
-
derivedTerms.push("d/d" + _variable + "(" + t + ")");
|
|
46462
|
-
}
|
|
46463
|
-
return derivedTerms.join(" + ");
|
|
46464
|
-
}).then((r) => r.result);
|
|
46427
|
+
return Promise.resolve(strs.map((s) => _casDerivativeOne(s, variable)));
|
|
46465
46428
|
}
|
|
46466
46429
|
function casExpand(input) {
|
|
46467
46430
|
if (!Array.isArray(input)) {
|
|
@@ -50626,6 +50589,9 @@ function ratNormalize(num2, den) {
|
|
|
50626
50589
|
const g = bigintGcd(n, d);
|
|
50627
50590
|
return { num: n / g, den: d / g };
|
|
50628
50591
|
}
|
|
50592
|
+
function ratAdd(a, b) {
|
|
50593
|
+
return ratNormalize(a.num * b.den + b.num * a.den, a.den * b.den);
|
|
50594
|
+
}
|
|
50629
50595
|
function ratSub(a, b) {
|
|
50630
50596
|
return ratNormalize(a.num * b.den - b.num * a.den, a.den * b.den);
|
|
50631
50597
|
}
|
|
@@ -50642,6 +50608,53 @@ function ratFromBigint(n) {
|
|
|
50642
50608
|
return { num: n, den: 1n };
|
|
50643
50609
|
}
|
|
50644
50610
|
var RAT_ZERO = { num: 0n, den: 1n };
|
|
50611
|
+
function surdFromRat(r) {
|
|
50612
|
+
return { a: r, b: RAT_ZERO };
|
|
50613
|
+
}
|
|
50614
|
+
function surdNeg(s) {
|
|
50615
|
+
return { a: ratNeg(s.a), b: ratNeg(s.b) };
|
|
50616
|
+
}
|
|
50617
|
+
function surdAdd(x, y) {
|
|
50618
|
+
return { a: ratAdd(x.a, y.a), b: ratAdd(x.b, y.b) };
|
|
50619
|
+
}
|
|
50620
|
+
function surdMul(x, y, delta) {
|
|
50621
|
+
const d = ratFromBigint(delta);
|
|
50622
|
+
return {
|
|
50623
|
+
a: ratAdd(ratMul(x.a, y.a), ratMul(ratMul(x.b, y.b), d)),
|
|
50624
|
+
b: ratAdd(ratMul(x.a, y.b), ratMul(x.b, y.a))
|
|
50625
|
+
};
|
|
50626
|
+
}
|
|
50627
|
+
function surdDiv(x, y, delta) {
|
|
50628
|
+
if (y.a.num === 0n && y.b.num === 0n) {
|
|
50629
|
+
throw new Error("surdDiv: division by zero surd");
|
|
50630
|
+
}
|
|
50631
|
+
const d = ratFromBigint(delta);
|
|
50632
|
+
const scale4 = ratSub(ratMul(y.a, y.a), ratMul(ratMul(y.b, y.b), d));
|
|
50633
|
+
const conj3 = { a: y.a, b: ratNeg(y.b) };
|
|
50634
|
+
const numer = surdMul(x, conj3, delta);
|
|
50635
|
+
return { a: ratDiv(numer.a, scale4), b: ratDiv(numer.b, scale4) };
|
|
50636
|
+
}
|
|
50637
|
+
function surdRender(s, delta) {
|
|
50638
|
+
const parts = [];
|
|
50639
|
+
if (s.a.num !== 0n) {
|
|
50640
|
+
parts.push(ratToStr(s.a));
|
|
50641
|
+
}
|
|
50642
|
+
if (s.b.num !== 0n) {
|
|
50643
|
+
const neg2 = s.b.num < 0n;
|
|
50644
|
+
const absB = neg2 ? ratNeg(s.b) : s.b;
|
|
50645
|
+
const sqrtPart = `sqrt(${delta})`;
|
|
50646
|
+
const term = absB.num === absB.den ? sqrtPart : `${ratToStr(absB)}*${sqrtPart}`;
|
|
50647
|
+
if (parts.length === 0) {
|
|
50648
|
+
parts.push(neg2 ? `- ${term}` : term);
|
|
50649
|
+
} else {
|
|
50650
|
+
parts.push(neg2 ? `- ${term}` : `+ ${term}`);
|
|
50651
|
+
}
|
|
50652
|
+
}
|
|
50653
|
+
if (parts.length === 0) {
|
|
50654
|
+
return "0";
|
|
50655
|
+
}
|
|
50656
|
+
return parts.join(" ");
|
|
50657
|
+
}
|
|
50645
50658
|
function splitTopLevelDivision(expr) {
|
|
50646
50659
|
let depth = 0;
|
|
50647
50660
|
for (let i = 0; i < expr.length; i += 1) {
|
|
@@ -50793,10 +50806,13 @@ function factorDenominator(denom) {
|
|
|
50793
50806
|
} else if (deg === 2) {
|
|
50794
50807
|
const q = trim(poly);
|
|
50795
50808
|
const disc = q[1] * q[1] - 4n * q[2] * q[0];
|
|
50796
|
-
if (disc
|
|
50809
|
+
if (disc < 0n) {
|
|
50810
|
+
out.push({ poly, mult, kind: "quadratic-neg" });
|
|
50811
|
+
} else if (mult === 1) {
|
|
50812
|
+
out.push({ poly, mult, kind: "quadratic-pos" });
|
|
50813
|
+
} else {
|
|
50797
50814
|
return null;
|
|
50798
50815
|
}
|
|
50799
|
-
out.push({ poly, mult, kind: "quadratic" });
|
|
50800
50816
|
} else {
|
|
50801
50817
|
return null;
|
|
50802
50818
|
}
|
|
@@ -51020,6 +51036,36 @@ function integrateQuadraticTerm(factor2, k, numer, v) {
|
|
|
51020
51036
|
}
|
|
51021
51037
|
return joinTerms(parts);
|
|
51022
51038
|
}
|
|
51039
|
+
function integrateQuadraticPosTerm(factor2, numer, v) {
|
|
51040
|
+
const c = factor2[0];
|
|
51041
|
+
const b = factor2[1];
|
|
51042
|
+
const a = factor2[2];
|
|
51043
|
+
const R = b * b - 4n * a * c;
|
|
51044
|
+
const D = numer[1] ?? RAT_ZERO;
|
|
51045
|
+
const E = numer[0] ?? RAT_ZERO;
|
|
51046
|
+
const twoA = ratFromBigint(2n * a);
|
|
51047
|
+
const negBOver2A = ratDiv(ratFromBigint(-b), twoA);
|
|
51048
|
+
const inv2A = ratDiv(ratFromBigint(1n), twoA);
|
|
51049
|
+
const r1 = { a: negBOver2A, b: inv2A };
|
|
51050
|
+
const r2 = { a: negBOver2A, b: ratNeg(inv2A) };
|
|
51051
|
+
const sqrtR = { a: RAT_ZERO, b: ratFromBigint(1n) };
|
|
51052
|
+
const Dsurd = surdFromRat(D);
|
|
51053
|
+
const Esurd = surdFromRat(E);
|
|
51054
|
+
const numA = surdAdd(surdMul(Dsurd, r1, R), Esurd);
|
|
51055
|
+
const numB = surdAdd(surdMul(Dsurd, r2, R), Esurd);
|
|
51056
|
+
const A = surdDiv(numA, sqrtR, R);
|
|
51057
|
+
const B = surdDiv(numB, surdNeg(sqrtR), R);
|
|
51058
|
+
const parts = [];
|
|
51059
|
+
const emit = (coeff, root2) => {
|
|
51060
|
+
if (coeff.a.num === 0n && coeff.b.num === 0n) {
|
|
51061
|
+
return;
|
|
51062
|
+
}
|
|
51063
|
+
parts.push(`(${surdRender(coeff, R)})*log(abs(${v} - (${surdRender(root2, R)})))`);
|
|
51064
|
+
};
|
|
51065
|
+
emit(A, r1);
|
|
51066
|
+
emit(B, r2);
|
|
51067
|
+
return joinTerms(parts);
|
|
51068
|
+
}
|
|
51023
51069
|
function integratePFTerm(term, v) {
|
|
51024
51070
|
const factor2 = trim(term.factor);
|
|
51025
51071
|
const deg = factor2.length - 1;
|
|
@@ -51027,7 +51073,14 @@ function integratePFTerm(term, v) {
|
|
|
51027
51073
|
return integrateLinearTerm(factor2, term.power, term.numer, v);
|
|
51028
51074
|
}
|
|
51029
51075
|
if (deg === 2) {
|
|
51030
|
-
|
|
51076
|
+
const disc = factor2[1] * factor2[1] - 4n * factor2[2] * factor2[0];
|
|
51077
|
+
if (disc < 0n) {
|
|
51078
|
+
return integrateQuadraticTerm(factor2, term.power, term.numer, v);
|
|
51079
|
+
}
|
|
51080
|
+
if (term.power !== 1) {
|
|
51081
|
+
throw new Error("integratePFTerm: repeated positive-discriminant quadratic is out of scope");
|
|
51082
|
+
}
|
|
51083
|
+
return integrateQuadraticPosTerm(factor2, term.numer, v);
|
|
51031
51084
|
}
|
|
51032
51085
|
throw new Error(`integratePFTerm: unsupported factor degree ${deg}`);
|
|
51033
51086
|
}
|