@danielsimonjr/mathts-functions 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +221 -94
- package/dist/typed/cas.d.ts +17 -10
- package/dist/typed/cas.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17687,12 +17687,12 @@ var dependencies5 = ["typed", "Complex"];
|
|
|
17687
17687
|
var createExpm1 = /* @__PURE__ */ factory(
|
|
17688
17688
|
name5,
|
|
17689
17689
|
dependencies5,
|
|
17690
|
-
({ typed: typed3, Complex:
|
|
17690
|
+
({ typed: typed3, Complex: Complex9 }) => {
|
|
17691
17691
|
return typed3(name5, {
|
|
17692
17692
|
number: expm1Number,
|
|
17693
17693
|
Complex: function(x) {
|
|
17694
17694
|
const r = Math.exp(x.re);
|
|
17695
|
-
return new
|
|
17695
|
+
return new Complex9(r * Math.cos(x.im) - 1, r * Math.sin(x.im));
|
|
17696
17696
|
},
|
|
17697
17697
|
BigNumber: function(x) {
|
|
17698
17698
|
return x.exp().minus(1);
|
|
@@ -17721,12 +17721,12 @@ var log16 = log10Number(16);
|
|
|
17721
17721
|
var createLog10 = /* @__PURE__ */ factory(
|
|
17722
17722
|
name6,
|
|
17723
17723
|
dependencies6,
|
|
17724
|
-
({ typed: typed3, config, Complex:
|
|
17724
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
17725
17725
|
function complexLog(c) {
|
|
17726
17726
|
return c.log().div(Math.LN10);
|
|
17727
17727
|
}
|
|
17728
17728
|
function complexLogNumber(x) {
|
|
17729
|
-
return complexLog(new
|
|
17729
|
+
return complexLog(new Complex9(x, 0));
|
|
17730
17730
|
}
|
|
17731
17731
|
return typed3(name6, {
|
|
17732
17732
|
number: function(x) {
|
|
@@ -17758,9 +17758,9 @@ var dependencies7 = ["typed", "config", "Complex"];
|
|
|
17758
17758
|
var createLog2 = /* @__PURE__ */ factory(
|
|
17759
17759
|
name7,
|
|
17760
17760
|
dependencies7,
|
|
17761
|
-
({ typed: typed3, config, Complex:
|
|
17761
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
17762
17762
|
function complexLog2Number(x) {
|
|
17763
|
-
return _log2Complex(new
|
|
17763
|
+
return _log2Complex(new Complex9(x, 0));
|
|
17764
17764
|
}
|
|
17765
17765
|
return typed3(name7, {
|
|
17766
17766
|
number: function(x) {
|
|
@@ -17785,7 +17785,7 @@ var createLog2 = /* @__PURE__ */ factory(
|
|
|
17785
17785
|
});
|
|
17786
17786
|
function _log2Complex(x) {
|
|
17787
17787
|
const newX = Math.sqrt(x.re * x.re + x.im * x.im);
|
|
17788
|
-
return new
|
|
17788
|
+
return new Complex9(
|
|
17789
17789
|
Math.log2 ? Math.log2(newX) : Math.log(newX) / Math.LN2,
|
|
17790
17790
|
Math.atan2(x.im, x.re) / Math.LN2
|
|
17791
17791
|
);
|
|
@@ -17861,7 +17861,7 @@ var dependencies10 = ["config", "typed", "Complex"];
|
|
|
17861
17861
|
var createSqrt = /* @__PURE__ */ factory(
|
|
17862
17862
|
name10,
|
|
17863
17863
|
dependencies10,
|
|
17864
|
-
({ config, typed: typed3, Complex:
|
|
17864
|
+
({ config, typed: typed3, Complex: Complex9 }) => {
|
|
17865
17865
|
return typed3("sqrt", {
|
|
17866
17866
|
number: _sqrtNumber,
|
|
17867
17867
|
Complex: function(x) {
|
|
@@ -17884,7 +17884,7 @@ var createSqrt = /* @__PURE__ */ factory(
|
|
|
17884
17884
|
} else if (x >= 0 || config.predictable) {
|
|
17885
17885
|
return Math.sqrt(x);
|
|
17886
17886
|
} else {
|
|
17887
|
-
return new
|
|
17887
|
+
return new Complex9(x, 0).sqrt();
|
|
17888
17888
|
}
|
|
17889
17889
|
}
|
|
17890
17890
|
}
|
|
@@ -18876,7 +18876,7 @@ var dependencies29 = ["Complex", "typed"];
|
|
|
18876
18876
|
var createLgamma = /* @__PURE__ */ factory(
|
|
18877
18877
|
name29,
|
|
18878
18878
|
dependencies29,
|
|
18879
|
-
({ Complex:
|
|
18879
|
+
({ Complex: Complex9, typed: typed3 }) => {
|
|
18880
18880
|
const SMALL_RE = 7;
|
|
18881
18881
|
const SMALL_IM = 7;
|
|
18882
18882
|
const coeffs = [
|
|
@@ -18922,16 +18922,16 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
18922
18922
|
const LOGPI = 1.1447298858494002;
|
|
18923
18923
|
const REFLECTION = 0.1;
|
|
18924
18924
|
if (n.isNaN()) {
|
|
18925
|
-
return new
|
|
18925
|
+
return new Complex9(NaN, NaN);
|
|
18926
18926
|
} else if (n.im === 0) {
|
|
18927
|
-
return new
|
|
18927
|
+
return new Complex9(lgammaNumber(n.re), 0);
|
|
18928
18928
|
} else if (n.re >= SMALL_RE || Math.abs(n.im) >= SMALL_IM) {
|
|
18929
18929
|
return lgammaStirling(n);
|
|
18930
18930
|
} else if (n.re <= REFLECTION) {
|
|
18931
18931
|
const tmp = copysign(TWOPI, n.im) * Math.floor(0.5 * n.re + 0.25);
|
|
18932
18932
|
const a = n.mul(Math.PI).sin().log();
|
|
18933
|
-
const b = lgammaComplex(new
|
|
18934
|
-
return new
|
|
18933
|
+
const b = lgammaComplex(new Complex9(1 - n.re, -n.im));
|
|
18934
|
+
return new Complex9(LOGPI, tmp).sub(a).sub(b);
|
|
18935
18935
|
} else if (n.im >= 0) {
|
|
18936
18936
|
return lgammaRecurrence(n);
|
|
18937
18937
|
} else {
|
|
@@ -18940,7 +18940,7 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
18940
18940
|
}
|
|
18941
18941
|
function lgammaStirling(z) {
|
|
18942
18942
|
const leftPart = z.sub(0.5).mul(z.log()).sub(z).add(lnSqrt2PI);
|
|
18943
|
-
const rz = new
|
|
18943
|
+
const rz = new Complex9(1, 0).div(z);
|
|
18944
18944
|
const rzz = rz.div(z);
|
|
18945
18945
|
let a = coeffs[0];
|
|
18946
18946
|
let b = coeffs[1];
|
|
@@ -18966,7 +18966,7 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
18966
18966
|
sb = nsb;
|
|
18967
18967
|
z = z.add(1);
|
|
18968
18968
|
}
|
|
18969
|
-
return lgammaStirling(z).sub(shiftprod.log()).sub(new
|
|
18969
|
+
return lgammaStirling(z).sub(shiftprod.log()).sub(new Complex9(0, signflips * 2 * Math.PI * 1));
|
|
18970
18970
|
}
|
|
18971
18971
|
}
|
|
18972
18972
|
);
|
|
@@ -19408,13 +19408,13 @@ var dependencies36 = ["typed", "config", "Complex"];
|
|
|
19408
19408
|
var createAcos = /* @__PURE__ */ factory(
|
|
19409
19409
|
name36,
|
|
19410
19410
|
dependencies36,
|
|
19411
|
-
({ typed: typed3, config, Complex:
|
|
19411
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19412
19412
|
return typed3(name36, {
|
|
19413
19413
|
number: function(x) {
|
|
19414
19414
|
if (x >= -1 && x <= 1 || config.predictable) {
|
|
19415
19415
|
return Math.acos(x);
|
|
19416
19416
|
} else {
|
|
19417
|
-
return new
|
|
19417
|
+
return new Complex9(x, 0).acos();
|
|
19418
19418
|
}
|
|
19419
19419
|
},
|
|
19420
19420
|
Complex: function(x) {
|
|
@@ -19433,16 +19433,16 @@ var dependencies37 = ["typed", "config", "Complex"];
|
|
|
19433
19433
|
var createAcosh = /* @__PURE__ */ factory(
|
|
19434
19434
|
name37,
|
|
19435
19435
|
dependencies37,
|
|
19436
|
-
({ typed: typed3, config, Complex:
|
|
19436
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19437
19437
|
return typed3(name37, {
|
|
19438
19438
|
number: function(x) {
|
|
19439
19439
|
if (x >= 1 || config.predictable) {
|
|
19440
19440
|
return acoshNumber(x);
|
|
19441
19441
|
}
|
|
19442
19442
|
if (x <= -1) {
|
|
19443
|
-
return new
|
|
19443
|
+
return new Complex9(Math.log(Math.sqrt(x * x - 1) - x), Math.PI);
|
|
19444
19444
|
}
|
|
19445
|
-
return new
|
|
19445
|
+
return new Complex9(x, 0).acosh();
|
|
19446
19446
|
},
|
|
19447
19447
|
Complex: function(x) {
|
|
19448
19448
|
return x.acosh();
|
|
@@ -19479,13 +19479,13 @@ var dependencies39 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19479
19479
|
var createAcoth = /* @__PURE__ */ factory(
|
|
19480
19480
|
name39,
|
|
19481
19481
|
dependencies39,
|
|
19482
|
-
({ typed: typed3, config, Complex:
|
|
19482
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19483
19483
|
return typed3(name39, {
|
|
19484
19484
|
number: function(x) {
|
|
19485
19485
|
if (x >= 1 || x <= -1 || config.predictable) {
|
|
19486
19486
|
return acothNumber(x);
|
|
19487
19487
|
}
|
|
19488
|
-
return new
|
|
19488
|
+
return new Complex9(x, 0).acoth();
|
|
19489
19489
|
},
|
|
19490
19490
|
Complex: function(x) {
|
|
19491
19491
|
return x.acoth();
|
|
@@ -19503,13 +19503,13 @@ var dependencies40 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19503
19503
|
var createAcsc = /* @__PURE__ */ factory(
|
|
19504
19504
|
name40,
|
|
19505
19505
|
dependencies40,
|
|
19506
|
-
({ typed: typed3, config, Complex:
|
|
19506
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19507
19507
|
return typed3(name40, {
|
|
19508
19508
|
number: function(x) {
|
|
19509
19509
|
if (x <= -1 || x >= 1 || config.predictable) {
|
|
19510
19510
|
return acscNumber(x);
|
|
19511
19511
|
}
|
|
19512
|
-
return new
|
|
19512
|
+
return new Complex9(x, 0).acsc();
|
|
19513
19513
|
},
|
|
19514
19514
|
Complex: function(x) {
|
|
19515
19515
|
return x.acsc();
|
|
@@ -19546,13 +19546,13 @@ var dependencies42 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19546
19546
|
var createAsec = /* @__PURE__ */ factory(
|
|
19547
19547
|
name42,
|
|
19548
19548
|
dependencies42,
|
|
19549
|
-
({ typed: typed3, config, Complex:
|
|
19549
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19550
19550
|
return typed3(name42, {
|
|
19551
19551
|
number: function(x) {
|
|
19552
19552
|
if (x <= -1 || x >= 1 || config.predictable) {
|
|
19553
19553
|
return asecNumber(x);
|
|
19554
19554
|
}
|
|
19555
|
-
return new
|
|
19555
|
+
return new Complex9(x, 0).asec();
|
|
19556
19556
|
},
|
|
19557
19557
|
Complex: function(x) {
|
|
19558
19558
|
return x.asec();
|
|
@@ -19570,7 +19570,7 @@ var dependencies43 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19570
19570
|
var createAsech = /* @__PURE__ */ factory(
|
|
19571
19571
|
name43,
|
|
19572
19572
|
dependencies43,
|
|
19573
|
-
({ typed: typed3, config, Complex:
|
|
19573
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19574
19574
|
return typed3(name43, {
|
|
19575
19575
|
number: function(x) {
|
|
19576
19576
|
if (x <= 1 && x >= -1 || config.predictable) {
|
|
@@ -19579,9 +19579,9 @@ var createAsech = /* @__PURE__ */ factory(
|
|
|
19579
19579
|
return asechNumber(x);
|
|
19580
19580
|
}
|
|
19581
19581
|
const ret = Math.sqrt(xInv * xInv - 1);
|
|
19582
|
-
return new
|
|
19582
|
+
return new Complex9(Math.log(ret - xInv), Math.PI);
|
|
19583
19583
|
}
|
|
19584
|
-
return new
|
|
19584
|
+
return new Complex9(x, 0).asech();
|
|
19585
19585
|
},
|
|
19586
19586
|
Complex: function(x) {
|
|
19587
19587
|
return x.asech();
|
|
@@ -19599,13 +19599,13 @@ var dependencies44 = ["typed", "config", "Complex"];
|
|
|
19599
19599
|
var createAsin = /* @__PURE__ */ factory(
|
|
19600
19600
|
name44,
|
|
19601
19601
|
dependencies44,
|
|
19602
|
-
({ typed: typed3, config, Complex:
|
|
19602
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19603
19603
|
return typed3(name44, {
|
|
19604
19604
|
number: function(x) {
|
|
19605
19605
|
if (x >= -1 && x <= 1 || config.predictable) {
|
|
19606
19606
|
return Math.asin(x);
|
|
19607
19607
|
} else {
|
|
19608
|
-
return new
|
|
19608
|
+
return new Complex9(x, 0).asin();
|
|
19609
19609
|
}
|
|
19610
19610
|
},
|
|
19611
19611
|
Complex: function(x) {
|
|
@@ -19664,13 +19664,13 @@ var dependencies47 = ["typed", "config", "Complex"];
|
|
|
19664
19664
|
var createAtanh = /* @__PURE__ */ factory(
|
|
19665
19665
|
name47,
|
|
19666
19666
|
dependencies47,
|
|
19667
|
-
({ typed: typed3, config, Complex:
|
|
19667
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19668
19668
|
return typed3(name47, {
|
|
19669
19669
|
number: function(x) {
|
|
19670
19670
|
if (x <= 1 && x >= -1 || config.predictable) {
|
|
19671
19671
|
return atanhNumber(x);
|
|
19672
19672
|
}
|
|
19673
|
-
return new
|
|
19673
|
+
return new Complex9(x, 0).atanh();
|
|
19674
19674
|
},
|
|
19675
19675
|
Complex: function(x) {
|
|
19676
19676
|
return x.atanh();
|
|
@@ -23394,7 +23394,7 @@ var createCbrt = /* @__PURE__ */ factory(
|
|
|
23394
23394
|
isNegative: isNegative2,
|
|
23395
23395
|
unaryMinus: unaryMinus2,
|
|
23396
23396
|
matrix: matrix2,
|
|
23397
|
-
Complex:
|
|
23397
|
+
Complex: Complex9,
|
|
23398
23398
|
BigNumber: BigNumber9,
|
|
23399
23399
|
Fraction: Fraction5
|
|
23400
23400
|
}) => {
|
|
@@ -23412,12 +23412,12 @@ var createCbrt = /* @__PURE__ */ factory(
|
|
|
23412
23412
|
function _cbrtComplex(x, allRoots) {
|
|
23413
23413
|
const arg3 = x.arg() / 3;
|
|
23414
23414
|
const abs2 = x.abs();
|
|
23415
|
-
const principal = new
|
|
23415
|
+
const principal = new Complex9(cbrtNumber(abs2), 0).mul(new Complex9(0, arg3).exp());
|
|
23416
23416
|
if (allRoots) {
|
|
23417
23417
|
const all = [
|
|
23418
23418
|
principal,
|
|
23419
|
-
new
|
|
23420
|
-
new
|
|
23419
|
+
new Complex9(cbrtNumber(abs2), 0).mul(new Complex9(0, arg3 + Math.PI * 2 / 3).exp()),
|
|
23420
|
+
new Complex9(cbrtNumber(abs2), 0).mul(new Complex9(0, arg3 - Math.PI * 2 / 3).exp())
|
|
23421
23421
|
];
|
|
23422
23422
|
return config.matrix === "Array" ? all : matrix2(all);
|
|
23423
23423
|
} else {
|
|
@@ -23466,27 +23466,27 @@ var createNthRoots = /* @__PURE__ */ factory(
|
|
|
23466
23466
|
typed: typed3,
|
|
23467
23467
|
config: _config,
|
|
23468
23468
|
divideScalar: _divideScalar,
|
|
23469
|
-
Complex:
|
|
23469
|
+
Complex: Complex9
|
|
23470
23470
|
}) => {
|
|
23471
23471
|
const _calculateExactResult = [
|
|
23472
23472
|
function realPos(val) {
|
|
23473
|
-
return new
|
|
23473
|
+
return new Complex9(val, 0);
|
|
23474
23474
|
},
|
|
23475
23475
|
function imagPos(val) {
|
|
23476
|
-
return new
|
|
23476
|
+
return new Complex9(0, val);
|
|
23477
23477
|
},
|
|
23478
23478
|
function realNeg(val) {
|
|
23479
|
-
return new
|
|
23479
|
+
return new Complex9(-val, 0);
|
|
23480
23480
|
},
|
|
23481
23481
|
function imagNeg(val) {
|
|
23482
|
-
return new
|
|
23482
|
+
return new Complex9(0, -val);
|
|
23483
23483
|
}
|
|
23484
23484
|
];
|
|
23485
23485
|
function _nthComplexRoots(a, root) {
|
|
23486
23486
|
if (root < 0) throw new Error("Root must be greater than zero");
|
|
23487
23487
|
if (root === 0) throw new Error("Root must be non-zero");
|
|
23488
23488
|
if (root % 1 !== 0) throw new Error("Root must be an integer");
|
|
23489
|
-
if (a === 0 || a.abs() === 0) return [new
|
|
23489
|
+
if (a === 0 || a.abs() === 0) return [new Complex9(0, 0)];
|
|
23490
23490
|
const aIsNumeric = typeof a === "number";
|
|
23491
23491
|
let offset;
|
|
23492
23492
|
if (aIsNumeric || a.re === 0 || a.im === 0) {
|
|
@@ -23508,7 +23508,7 @@ var createNthRoots = /* @__PURE__ */ factory(
|
|
|
23508
23508
|
roots.push(_calculateExactResult[halfPiFactor % 4](r));
|
|
23509
23509
|
continue;
|
|
23510
23510
|
}
|
|
23511
|
-
roots.push(new
|
|
23511
|
+
roots.push(new Complex9({ r, phi: (arg3 + 2 * Math.PI * k) / root }));
|
|
23512
23512
|
}
|
|
23513
23513
|
return roots;
|
|
23514
23514
|
}
|
|
@@ -23895,12 +23895,12 @@ var nlg16 = Math.log(16);
|
|
|
23895
23895
|
var createLog = /* @__PURE__ */ factory(
|
|
23896
23896
|
name112,
|
|
23897
23897
|
dependencies112,
|
|
23898
|
-
({ typed: typed3, typeOf: typeOf3, config, divideScalar: divideScalar2, Complex:
|
|
23898
|
+
({ typed: typed3, typeOf: typeOf3, config, divideScalar: divideScalar2, Complex: Complex9 }) => {
|
|
23899
23899
|
function complexLog(c) {
|
|
23900
23900
|
return c.log();
|
|
23901
23901
|
}
|
|
23902
23902
|
function complexLogNumber(x) {
|
|
23903
|
-
return complexLog(new
|
|
23903
|
+
return complexLog(new Complex9(x, 0));
|
|
23904
23904
|
}
|
|
23905
23905
|
return typed3(name112, {
|
|
23906
23906
|
number: function(x) {
|
|
@@ -25146,7 +25146,7 @@ var dependencies126 = ["typed", "add", "multiply", "Complex", "number"];
|
|
|
25146
25146
|
var createZpk2tf = /* @__PURE__ */ factory(
|
|
25147
25147
|
name126,
|
|
25148
25148
|
dependencies126,
|
|
25149
|
-
({ typed: typed3, add: add2, multiply: multiply2, Complex:
|
|
25149
|
+
({ typed: typed3, add: add2, multiply: multiply2, Complex: Complex9, number: number2 }) => {
|
|
25150
25150
|
return typed3(name126, {
|
|
25151
25151
|
"Array,Array,number": function(z, p, k) {
|
|
25152
25152
|
return _zpk2tf(z, p, k);
|
|
@@ -25168,17 +25168,17 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
25168
25168
|
if (p.some((el) => el.type === "BigNumber")) {
|
|
25169
25169
|
p = p.map((el) => number2(el));
|
|
25170
25170
|
}
|
|
25171
|
-
let num = [
|
|
25172
|
-
let den = [
|
|
25171
|
+
let num = [Complex9(1, 0)];
|
|
25172
|
+
let den = [Complex9(1, 0)];
|
|
25173
25173
|
for (let i = 0; i < z.length; i++) {
|
|
25174
25174
|
let zero = z[i];
|
|
25175
|
-
if (typeof zero === "number") zero =
|
|
25176
|
-
num = _multiply(num, [
|
|
25175
|
+
if (typeof zero === "number") zero = Complex9(zero, 0);
|
|
25176
|
+
num = _multiply(num, [Complex9(1, 0), Complex9(-zero.re, -zero.im)]);
|
|
25177
25177
|
}
|
|
25178
25178
|
for (let i = 0; i < p.length; i++) {
|
|
25179
25179
|
let pole = p[i];
|
|
25180
|
-
if (typeof pole === "number") pole =
|
|
25181
|
-
den = _multiply(den, [
|
|
25180
|
+
if (typeof pole === "number") pole = Complex9(pole, 0);
|
|
25181
|
+
den = _multiply(den, [Complex9(1, 0), Complex9(-pole.re, -pole.im)]);
|
|
25182
25182
|
}
|
|
25183
25183
|
for (let i = 0; i < num.length; i++) {
|
|
25184
25184
|
num[i] = multiply2(num[i], k);
|
|
@@ -25188,7 +25188,7 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
25188
25188
|
function _multiply(a, b) {
|
|
25189
25189
|
const c = [];
|
|
25190
25190
|
for (let i = 0; i < a.length + b.length - 1; i++) {
|
|
25191
|
-
c[i] =
|
|
25191
|
+
c[i] = Complex9(0, 0);
|
|
25192
25192
|
for (let j = 0; j < a.length; j++) {
|
|
25193
25193
|
if (i - j >= 0 && i - j < b.length) {
|
|
25194
25194
|
c[i] = add2(c[i], multiply2(a[j], b[i - j]));
|
|
@@ -26431,13 +26431,13 @@ var dependencies142 = ["typed", "config", "divideScalar", "log", "Complex"];
|
|
|
26431
26431
|
var createLog1p = /* @__PURE__ */ factory(
|
|
26432
26432
|
name142,
|
|
26433
26433
|
dependencies142,
|
|
26434
|
-
({ typed: typed3, config, divideScalar: divideScalar2, log: log3, Complex:
|
|
26434
|
+
({ typed: typed3, config, divideScalar: divideScalar2, log: log3, Complex: Complex9 }) => {
|
|
26435
26435
|
return typed3(name142, {
|
|
26436
26436
|
number: function(x) {
|
|
26437
26437
|
if (x >= -1 || config.predictable) {
|
|
26438
26438
|
return log1p2(x);
|
|
26439
26439
|
} else {
|
|
26440
|
-
return _log1pComplex(new
|
|
26440
|
+
return _log1pComplex(new Complex9(x, 0));
|
|
26441
26441
|
}
|
|
26442
26442
|
},
|
|
26443
26443
|
Complex: _log1pComplex,
|
|
@@ -26446,7 +26446,7 @@ var createLog1p = /* @__PURE__ */ factory(
|
|
|
26446
26446
|
if (!y.isNegative() || config.predictable) {
|
|
26447
26447
|
return y.ln();
|
|
26448
26448
|
} else {
|
|
26449
|
-
return _log1pComplex(new
|
|
26449
|
+
return _log1pComplex(new Complex9(x.toNumber(), 0));
|
|
26450
26450
|
}
|
|
26451
26451
|
},
|
|
26452
26452
|
"Array | Matrix": typed3.referToSelf(
|
|
@@ -26460,7 +26460,7 @@ var createLog1p = /* @__PURE__ */ factory(
|
|
|
26460
26460
|
});
|
|
26461
26461
|
function _log1pComplex(x) {
|
|
26462
26462
|
const xRe1p = x.re + 1;
|
|
26463
|
-
return new
|
|
26463
|
+
return new Complex9(Math.log(Math.sqrt(xRe1p * xRe1p + x.im * x.im)), Math.atan2(x.im, xRe1p));
|
|
26464
26464
|
}
|
|
26465
26465
|
}
|
|
26466
26466
|
);
|
|
@@ -26593,7 +26593,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
26593
26593
|
inv: inv2,
|
|
26594
26594
|
number: number2,
|
|
26595
26595
|
fraction: fraction2,
|
|
26596
|
-
Complex:
|
|
26596
|
+
Complex: Complex9
|
|
26597
26597
|
}) => {
|
|
26598
26598
|
return typed3(name144, {
|
|
26599
26599
|
"number, number": _pow,
|
|
@@ -26604,7 +26604,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
26604
26604
|
if (y.isInteger() || x.gte(0) || config.predictable) {
|
|
26605
26605
|
return x.pow(y);
|
|
26606
26606
|
} else {
|
|
26607
|
-
return new
|
|
26607
|
+
return new Complex9(x.toNumber(), 0).pow(y.toNumber(), 0);
|
|
26608
26608
|
}
|
|
26609
26609
|
},
|
|
26610
26610
|
"bigint, bigint": (x, y) => x ** y,
|
|
@@ -26653,7 +26653,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
26653
26653
|
if (isPowZeroAtInfinity(x, y)) {
|
|
26654
26654
|
return 0;
|
|
26655
26655
|
}
|
|
26656
|
-
return new
|
|
26656
|
+
return new Complex9(x, 0).pow(y, 0);
|
|
26657
26657
|
}
|
|
26658
26658
|
}
|
|
26659
26659
|
function _powArray(x, y) {
|
|
@@ -28054,7 +28054,7 @@ var createFixNumber = /* @__PURE__ */ factory(
|
|
|
28054
28054
|
var createFix = /* @__PURE__ */ factory(
|
|
28055
28055
|
name167,
|
|
28056
28056
|
dependencies167,
|
|
28057
|
-
({ typed: typed3, Complex:
|
|
28057
|
+
({ typed: typed3, Complex: Complex9, matrix: matrix2, ceil: ceil2, floor: floor2, equalScalar: equalScalar3, zeros: zeros3, DenseMatrix: DenseMatrix3 }) => {
|
|
28058
28058
|
const matAlgo12xSfs = createMatAlgo12xSfs({ typed: typed3, DenseMatrix: DenseMatrix3 });
|
|
28059
28059
|
const matAlgo14xDs = createMatAlgo14xDs({ typed: typed3 });
|
|
28060
28060
|
const fixNumber = createFixNumber({ typed: typed3, ceil: ceil2, floor: floor2 });
|
|
@@ -28062,20 +28062,20 @@ var createFix = /* @__PURE__ */ factory(
|
|
|
28062
28062
|
number: fixNumber.signatures.number,
|
|
28063
28063
|
"number, number | BigNumber": fixNumber.signatures["number,number"],
|
|
28064
28064
|
Complex: function(x) {
|
|
28065
|
-
return new
|
|
28065
|
+
return new Complex9(
|
|
28066
28066
|
x.re > 0 ? Math.floor(x.re) : Math.ceil(x.re),
|
|
28067
28067
|
x.im > 0 ? Math.floor(x.im) : Math.ceil(x.im)
|
|
28068
28068
|
);
|
|
28069
28069
|
},
|
|
28070
28070
|
"Complex, number": function(x, n) {
|
|
28071
|
-
return new
|
|
28071
|
+
return new Complex9(
|
|
28072
28072
|
x.re > 0 ? floor2(x.re, n) : ceil2(x.re, n),
|
|
28073
28073
|
x.im > 0 ? floor2(x.im, n) : ceil2(x.im, n)
|
|
28074
28074
|
);
|
|
28075
28075
|
},
|
|
28076
28076
|
"Complex, BigNumber": function(x, bn) {
|
|
28077
28077
|
const n = bn.toNumber();
|
|
28078
|
-
return new
|
|
28078
|
+
return new Complex9(
|
|
28079
28079
|
x.re > 0 ? floor2(x.re, n) : ceil2(x.re, n),
|
|
28080
28080
|
x.im > 0 ? floor2(x.im, n) : ceil2(x.im, n)
|
|
28081
28081
|
);
|
|
@@ -28445,7 +28445,7 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
28445
28445
|
divideScalar: divideScalar2,
|
|
28446
28446
|
multiply: multiply2,
|
|
28447
28447
|
add: add2,
|
|
28448
|
-
Complex:
|
|
28448
|
+
Complex: Complex9
|
|
28449
28449
|
}) => {
|
|
28450
28450
|
return typed3(name172, {
|
|
28451
28451
|
"Array | Matrix": function(x) {
|
|
@@ -28540,12 +28540,12 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
28540
28540
|
return { C, F };
|
|
28541
28541
|
}
|
|
28542
28542
|
function _isZero(x) {
|
|
28543
|
-
return equal2(add2(x,
|
|
28543
|
+
return equal2(add2(x, Complex9(1, 1)), add2(0, Complex9(1, 1)));
|
|
28544
28544
|
}
|
|
28545
28545
|
function _isZeros(arr) {
|
|
28546
28546
|
return deepEqual3(
|
|
28547
|
-
add2(arr,
|
|
28548
|
-
add2(multiply2(arr, 0),
|
|
28547
|
+
add2(arr, Complex9(1, 1)),
|
|
28548
|
+
add2(multiply2(arr, 0), Complex9(1, 1))
|
|
28549
28549
|
);
|
|
28550
28550
|
}
|
|
28551
28551
|
}
|
|
@@ -28936,25 +28936,25 @@ var createGamma = /* @__PURE__ */ factory(
|
|
|
28936
28936
|
multiplyScalar: _multiplyScalar,
|
|
28937
28937
|
pow: _pow,
|
|
28938
28938
|
BigNumber: BigNumber9,
|
|
28939
|
-
Complex:
|
|
28939
|
+
Complex: Complex9
|
|
28940
28940
|
}) => {
|
|
28941
28941
|
function gammaComplex(n) {
|
|
28942
28942
|
if (n.im === 0) {
|
|
28943
28943
|
return gammaNumber(n.re);
|
|
28944
28944
|
}
|
|
28945
28945
|
if (n.re < 0.5) {
|
|
28946
|
-
const t2 = new
|
|
28947
|
-
const r = new
|
|
28946
|
+
const t2 = new Complex9(1 - n.re, -n.im);
|
|
28947
|
+
const r = new Complex9(Math.PI * n.re, Math.PI * n.im);
|
|
28948
28948
|
const gammaT = gammaComplex(t2);
|
|
28949
|
-
return new
|
|
28949
|
+
return new Complex9(Math.PI).div(r.sin()).div(gammaT);
|
|
28950
28950
|
}
|
|
28951
|
-
const z = new
|
|
28952
|
-
let x = new
|
|
28951
|
+
const z = new Complex9(n.re - 1, n.im);
|
|
28952
|
+
let x = new Complex9(gammaP[0], 0);
|
|
28953
28953
|
for (let i = 1; i < gammaP.length; ++i) {
|
|
28954
|
-
const gammaPval = new
|
|
28954
|
+
const gammaPval = new Complex9(gammaP[i], 0);
|
|
28955
28955
|
x = x.add(gammaPval.div(z.add(i)));
|
|
28956
28956
|
}
|
|
28957
|
-
const t = new
|
|
28957
|
+
const t = new Complex9(z.re + gammaG + 0.5, z.im);
|
|
28958
28958
|
const twoPiSqrt = Math.sqrt(2 * Math.PI);
|
|
28959
28959
|
const tpow = t.pow(z.add(0.5));
|
|
28960
28960
|
const expt = t.neg().exp();
|
|
@@ -32018,7 +32018,7 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
32018
32018
|
isNumeric: isNumeric2,
|
|
32019
32019
|
format: format6,
|
|
32020
32020
|
number: number2,
|
|
32021
|
-
Complex:
|
|
32021
|
+
Complex: Complex9,
|
|
32022
32022
|
BigNumber: BigNumber9,
|
|
32023
32023
|
Fraction: Fraction5
|
|
32024
32024
|
}) => {
|
|
@@ -34127,7 +34127,7 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
34127
34127
|
name: "VAR",
|
|
34128
34128
|
base: BASE_UNITS.POWER,
|
|
34129
34129
|
prefixes: PREFIXES.SHORT,
|
|
34130
|
-
value:
|
|
34130
|
+
value: Complex9.I,
|
|
34131
34131
|
offset: 0
|
|
34132
34132
|
},
|
|
34133
34133
|
VA: {
|
|
@@ -37203,7 +37203,7 @@ var dependencies226 = ["typed", "add", "multiply", "Complex", "divide", "matrix"
|
|
|
37203
37203
|
var createFreqz = /* @__PURE__ */ factory(
|
|
37204
37204
|
name226,
|
|
37205
37205
|
dependencies226,
|
|
37206
|
-
({ typed: typed3, add: add2, multiply: multiply2, Complex:
|
|
37206
|
+
({ typed: typed3, add: add2, multiply: multiply2, Complex: Complex9, divide: divide2, matrix: matrix2 }) => {
|
|
37207
37207
|
return typed3(name226, {
|
|
37208
37208
|
"Array, Array": function(b, a) {
|
|
37209
37209
|
const w = createBins(512);
|
|
@@ -37272,7 +37272,7 @@ var createFreqz = /* @__PURE__ */ factory(
|
|
|
37272
37272
|
);
|
|
37273
37273
|
const h = [];
|
|
37274
37274
|
for (let i = 0; i < w.length; i++) {
|
|
37275
|
-
h.push(
|
|
37275
|
+
h.push(Complex9(hRealAlloc.array[i], hImagAlloc.array[i]));
|
|
37276
37276
|
}
|
|
37277
37277
|
return { h, w };
|
|
37278
37278
|
} finally {
|
|
@@ -37294,18 +37294,18 @@ var createFreqz = /* @__PURE__ */ factory(
|
|
|
37294
37294
|
const num = [];
|
|
37295
37295
|
const den = [];
|
|
37296
37296
|
for (let i = 0; i < w.length; i++) {
|
|
37297
|
-
let sumNum =
|
|
37298
|
-
let sumDen =
|
|
37297
|
+
let sumNum = Complex9(0, 0);
|
|
37298
|
+
let sumDen = Complex9(0, 0);
|
|
37299
37299
|
for (let j = 0; j < b.length; j++) {
|
|
37300
37300
|
sumNum = add2(
|
|
37301
37301
|
sumNum,
|
|
37302
|
-
multiply2(b[j],
|
|
37302
|
+
multiply2(b[j], Complex9(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
37303
37303
|
);
|
|
37304
37304
|
}
|
|
37305
37305
|
for (let j = 0; j < a.length; j++) {
|
|
37306
37306
|
sumDen = add2(
|
|
37307
37307
|
sumDen,
|
|
37308
|
-
multiply2(a[j],
|
|
37308
|
+
multiply2(a[j], Complex9(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
37309
37309
|
);
|
|
37310
37310
|
}
|
|
37311
37311
|
num.push(sumNum);
|
|
@@ -38612,7 +38612,7 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
38612
38612
|
sin: sin2,
|
|
38613
38613
|
subtract: subtract2,
|
|
38614
38614
|
add: add2,
|
|
38615
|
-
Complex:
|
|
38615
|
+
Complex: Complex9,
|
|
38616
38616
|
BigNumber: BigNumber9,
|
|
38617
38617
|
pi
|
|
38618
38618
|
}) => {
|
|
@@ -38648,16 +38648,16 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
38648
38648
|
}
|
|
38649
38649
|
function zetaComplex(s) {
|
|
38650
38650
|
if (s.re === 0 && s.im === 0) {
|
|
38651
|
-
return new
|
|
38651
|
+
return new Complex9(-0.5);
|
|
38652
38652
|
}
|
|
38653
38653
|
if (s.re === 1) {
|
|
38654
|
-
return new
|
|
38654
|
+
return new Complex9(NaN, NaN);
|
|
38655
38655
|
}
|
|
38656
38656
|
if (s.re === Infinity && s.im === 0) {
|
|
38657
|
-
return new
|
|
38657
|
+
return new Complex9(1);
|
|
38658
38658
|
}
|
|
38659
38659
|
if (s.im === Infinity || s.re === -Infinity) {
|
|
38660
|
-
return new
|
|
38660
|
+
return new Complex9(NaN, NaN);
|
|
38661
38661
|
}
|
|
38662
38662
|
return zeta2(
|
|
38663
38663
|
s,
|
|
@@ -43761,6 +43761,7 @@ function reviver(_key, value) {
|
|
|
43761
43761
|
|
|
43762
43762
|
// src/typed/cas.ts
|
|
43763
43763
|
import { computePool as computePool13 } from "@danielsimonjr/mathts-parallel";
|
|
43764
|
+
import { Complex as Complex8 } from "@danielsimonjr/mathts-core";
|
|
43764
43765
|
function evalAt(expr, varName, value) {
|
|
43765
43766
|
return evaluate(expr, { [varName]: value });
|
|
43766
43767
|
}
|
|
@@ -44199,7 +44200,78 @@ function seriesCoefficient(expr, varName, x0, k) {
|
|
|
44199
44200
|
const deriv = numericalDerivative(expr, varName, x0, k);
|
|
44200
44201
|
return deriv / factorial3(k);
|
|
44201
44202
|
}
|
|
44202
|
-
function
|
|
44203
|
+
function realCbrt(x) {
|
|
44204
|
+
return x < 0 ? -Math.pow(-x, 1 / 3) : Math.pow(x, 1 / 3);
|
|
44205
|
+
}
|
|
44206
|
+
function quadraticRoots(a, b, c) {
|
|
44207
|
+
const disc = b * b - 4 * a * c;
|
|
44208
|
+
if (disc >= 0) {
|
|
44209
|
+
const s2 = Math.sqrt(disc);
|
|
44210
|
+
return [(-b + s2) / (2 * a), (-b - s2) / (2 * a)];
|
|
44211
|
+
}
|
|
44212
|
+
const s = Math.sqrt(-disc);
|
|
44213
|
+
const re3 = -b / (2 * a);
|
|
44214
|
+
const im3 = s / (2 * a);
|
|
44215
|
+
return [new Complex8(re3, im3), new Complex8(re3, -im3)];
|
|
44216
|
+
}
|
|
44217
|
+
function cubicRoots(a, b, c, d) {
|
|
44218
|
+
const B = b / a;
|
|
44219
|
+
const C = c / a;
|
|
44220
|
+
const D = d / a;
|
|
44221
|
+
const p = C - B * B / 3;
|
|
44222
|
+
const q = 2 * B * B * B / 27 - B * C / 3 + D;
|
|
44223
|
+
const shift = -B / 3;
|
|
44224
|
+
const disc = q * q / 4 + p * p * p / 27;
|
|
44225
|
+
if (Math.abs(disc) < 1e-12) {
|
|
44226
|
+
if (Math.abs(p) < 1e-12 && Math.abs(q) < 1e-12) return [shift];
|
|
44227
|
+
const u = realCbrt(-q / 2);
|
|
44228
|
+
return [2 * u + shift, -u + shift];
|
|
44229
|
+
}
|
|
44230
|
+
if (disc > 0) {
|
|
44231
|
+
const sq = Math.sqrt(disc);
|
|
44232
|
+
const u = realCbrt(-q / 2 + sq);
|
|
44233
|
+
const v = realCbrt(-q / 2 - sq);
|
|
44234
|
+
const realPart = -(u + v) / 2 + shift;
|
|
44235
|
+
const imagPart = (u - v) * Math.sqrt(3) / 2;
|
|
44236
|
+
return [u + v + shift, new Complex8(realPart, imagPart), new Complex8(realPart, -imagPart)];
|
|
44237
|
+
}
|
|
44238
|
+
const m = 2 * Math.sqrt(-p / 3);
|
|
44239
|
+
let arg3 = 3 * q / (2 * p) * Math.sqrt(-3 / p);
|
|
44240
|
+
arg3 = Math.max(-1, Math.min(1, arg3));
|
|
44241
|
+
const theta = Math.acos(arg3) / 3;
|
|
44242
|
+
return [0, 1, 2].map((k) => m * Math.cos(theta - 2 * Math.PI * k / 3) + shift);
|
|
44243
|
+
}
|
|
44244
|
+
function polyCoeffsDeg3(expr, varName) {
|
|
44245
|
+
const at = (x) => {
|
|
44246
|
+
const v = evalAt(expr, varName, x);
|
|
44247
|
+
return typeof v === "number" && Number.isFinite(v) ? v : NaN;
|
|
44248
|
+
};
|
|
44249
|
+
try {
|
|
44250
|
+
const f = [0, 1, 2, 3, 4].map(at);
|
|
44251
|
+
if (f.some((v) => !Number.isFinite(v))) return null;
|
|
44252
|
+
const d1 = f[1] - f[0];
|
|
44253
|
+
const d2 = f[2] - 2 * f[1] + f[0];
|
|
44254
|
+
const d3 = f[3] - 3 * f[2] + 3 * f[1] - f[0];
|
|
44255
|
+
const d4 = f[4] - 4 * f[3] + 6 * f[2] - 4 * f[1] + f[0];
|
|
44256
|
+
const scale = Math.max(1, ...f.map(Math.abs));
|
|
44257
|
+
if (Math.abs(d4) > 1e-7 * scale) return null;
|
|
44258
|
+
const c3 = d3 / 6;
|
|
44259
|
+
const c2 = d2 / 2 - d3 / 2;
|
|
44260
|
+
const c1 = d1 - d2 / 2 + d3 / 3;
|
|
44261
|
+
const c0 = f[0];
|
|
44262
|
+
const coeffs = [c0, c1, c2, c3];
|
|
44263
|
+
for (const x of [-1.5, 0.5, 2.5, 3.5]) {
|
|
44264
|
+
const recon = c0 + c1 * x + c2 * x * x + c3 * x * x * x;
|
|
44265
|
+
const actual = at(x);
|
|
44266
|
+
if (!Number.isFinite(actual)) return null;
|
|
44267
|
+
if (Math.abs(recon - actual) > 1e-6 * (1 + Math.abs(actual))) return null;
|
|
44268
|
+
}
|
|
44269
|
+
return coeffs;
|
|
44270
|
+
} catch {
|
|
44271
|
+
return null;
|
|
44272
|
+
}
|
|
44273
|
+
}
|
|
44274
|
+
function numericRealRoots(expr, varName) {
|
|
44203
44275
|
const roots = [];
|
|
44204
44276
|
const seen = /* @__PURE__ */ new Set();
|
|
44205
44277
|
const addRoot = (r) => {
|
|
@@ -44259,6 +44331,61 @@ function solve(expr, varName) {
|
|
|
44259
44331
|
roots.sort((a, b) => a - b);
|
|
44260
44332
|
return roots;
|
|
44261
44333
|
}
|
|
44334
|
+
function solve(equation, varName) {
|
|
44335
|
+
let expr = equation;
|
|
44336
|
+
if (equation.includes("=")) {
|
|
44337
|
+
const parts = equation.split("=");
|
|
44338
|
+
if (parts.length !== 2) {
|
|
44339
|
+
throw new SyntaxError("solve: equation must contain at most one '=' sign");
|
|
44340
|
+
}
|
|
44341
|
+
expr = `${parts[0].trim()} - (${parts[1].trim()})`;
|
|
44342
|
+
}
|
|
44343
|
+
const coeffs = polyCoeffsDeg3(expr, varName);
|
|
44344
|
+
if (coeffs) {
|
|
44345
|
+
let cleanComponent = function(x) {
|
|
44346
|
+
if (Math.abs(x) < 1e-10) return 0;
|
|
44347
|
+
const rounded = Math.round(x);
|
|
44348
|
+
return Math.abs(x - rounded) < 1e-8 ? rounded : x;
|
|
44349
|
+
}, pushReal = function(x) {
|
|
44350
|
+
const clean = cleanComponent(x);
|
|
44351
|
+
const key = `r${clean.toFixed(8)}`;
|
|
44352
|
+
if (!seen.has(key)) {
|
|
44353
|
+
seen.add(key);
|
|
44354
|
+
reals.push(clean);
|
|
44355
|
+
}
|
|
44356
|
+
};
|
|
44357
|
+
const [c0, c1, c2, c3] = coeffs;
|
|
44358
|
+
const eps = 1e-9;
|
|
44359
|
+
let raw = [];
|
|
44360
|
+
if (Math.abs(c3) > eps) raw = cubicRoots(c3, c2, c1, c0);
|
|
44361
|
+
else if (Math.abs(c2) > eps) raw = quadraticRoots(c2, c1, c0);
|
|
44362
|
+
else if (Math.abs(c1) > eps) raw = [-c0 / c1];
|
|
44363
|
+
else raw = [];
|
|
44364
|
+
const reals = [];
|
|
44365
|
+
const complexRoots = [];
|
|
44366
|
+
const seen = /* @__PURE__ */ new Set();
|
|
44367
|
+
for (const r of raw) {
|
|
44368
|
+
if (r instanceof Complex8) {
|
|
44369
|
+
if (Math.abs(r.im) < 1e-10) {
|
|
44370
|
+
pushReal(r.re);
|
|
44371
|
+
} else {
|
|
44372
|
+
const re3 = cleanComponent(r.re);
|
|
44373
|
+
const im3 = cleanComponent(r.im);
|
|
44374
|
+
const key = `${re3.toFixed(8)}|${im3.toFixed(8)}`;
|
|
44375
|
+
if (!seen.has(key)) {
|
|
44376
|
+
seen.add(key);
|
|
44377
|
+
complexRoots.push(new Complex8(re3, im3));
|
|
44378
|
+
}
|
|
44379
|
+
}
|
|
44380
|
+
} else {
|
|
44381
|
+
pushReal(r);
|
|
44382
|
+
}
|
|
44383
|
+
}
|
|
44384
|
+
reals.sort((a, b) => a - b);
|
|
44385
|
+
return [...reals, ...complexRoots];
|
|
44386
|
+
}
|
|
44387
|
+
return numericRealRoots(expr, varName);
|
|
44388
|
+
}
|
|
44262
44389
|
function implicitDiff(expr, x, y, scope) {
|
|
44263
44390
|
const dFdx = partialDerivative(expr, x, scope);
|
|
44264
44391
|
const dFdy = partialDerivative(expr, y, scope);
|
|
@@ -44582,8 +44709,8 @@ function solveQuarticRadicals(A, B, C, D, E, fm2, fm1, f0, f1, f2) {
|
|
|
44582
44709
|
const p2 = c2 / A - c1 * c1 / (3 * A * A);
|
|
44583
44710
|
const q2 = c3 / A - c1 * c2 / (3 * A * A) + 2 * c1 * c1 * c1 / (27 * A * A * A);
|
|
44584
44711
|
const tRoots2 = depressedCubicRoots(p2, q2);
|
|
44585
|
-
const
|
|
44586
|
-
const allRoots = [r, ...
|
|
44712
|
+
const cubicRoots2 = tRoots2.map((t) => t - shift2);
|
|
44713
|
+
const allRoots = [r, ...cubicRoots2];
|
|
44587
44714
|
return allRoots.map(formatCoeff);
|
|
44588
44715
|
}
|
|
44589
44716
|
}
|
package/dist/typed/cas.d.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* @packageDocumentation
|
|
21
21
|
*/
|
|
22
22
|
import { parse } from '../factories/evaluate.js';
|
|
23
|
+
import { Complex } from '@danielsimonjr/mathts-core';
|
|
23
24
|
type f64 = number;
|
|
24
25
|
type MathNode = ReturnType<typeof parse>;
|
|
25
26
|
/**
|
|
@@ -280,21 +281,27 @@ export declare function series(expr: string, varName: string, x0?: f64, n?: numb
|
|
|
280
281
|
*/
|
|
281
282
|
export declare function seriesCoefficient(expr: string, varName: string, x0: f64, k: number): f64;
|
|
282
283
|
/**
|
|
283
|
-
* Solve an equation for a variable.
|
|
284
|
+
* Solve an equation or expression for a variable, returning its distinct roots.
|
|
284
285
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
286
|
+
* Accepts either an expression (treated as `expr = 0`) or a full equation with a
|
|
287
|
+
* single `=` sign. Polynomials of degree ≤ 3 yield exact closed-form roots —
|
|
288
|
+
* including complex conjugates — while higher-degree and transcendental
|
|
289
|
+
* equations fall back to a numeric scan for real roots. Real roots are returned
|
|
290
|
+
* first (cleaned of float noise and sorted ascending), followed by any complex
|
|
291
|
+
* roots.
|
|
291
292
|
*
|
|
292
293
|
* @example
|
|
293
|
-
* solve('x^2 - 4', 'x')
|
|
294
|
-
* solve('x^2 +
|
|
294
|
+
* solve('x^2 - 4', 'x') // => [-2, 2]
|
|
295
|
+
* solve('x^2 + 1 = 0', 'x') // => [Complex(0, 1), Complex(0, -1)]
|
|
295
296
|
* solve('2*x - 6', 'x') // => [3]
|
|
297
|
+
* solve('x^3 - 8', 'x') // => [2, Complex(-1, 1.732…), Complex(-1, -1.732…)]
|
|
298
|
+
* solve('cos(x)', 'x') // => numeric real roots
|
|
299
|
+
*
|
|
300
|
+
* @param equation - Expression (`expr = 0`) or equation with one `=` sign.
|
|
301
|
+
* @param varName - Variable to solve for.
|
|
302
|
+
* @returns Distinct roots: real numbers (sorted) then Complex.
|
|
296
303
|
*/
|
|
297
|
-
export declare function solve(
|
|
304
|
+
export declare function solve(equation: string, varName: string): Array<f64 | Complex>;
|
|
298
305
|
/**
|
|
299
306
|
* Compute dy/dx from an implicit equation F(x, y) = 0.
|
|
300
307
|
*
|
package/dist/typed/cas.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cas.d.ts","sourceRoot":"","sources":["../../src/typed/cas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,EAAY,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"cas.d.ts","sourceRoot":"","sources":["../../src/typed/cas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,EAAY,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAMrD,KAAK,GAAG,GAAG,MAAM,CAAC;AAClB,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AAwGzC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,E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