@danielsimonjr/mathts-functions 0.2.8 → 0.2.10
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 +214 -98
- package/dist/typed/arithmetic.d.ts.map +1 -1
- 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
|
@@ -477,10 +477,19 @@ var add = mathTyped("add", {
|
|
|
477
477
|
const result = await computePool.add(a, b);
|
|
478
478
|
return result.result;
|
|
479
479
|
},
|
|
480
|
-
// Variadic addition
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
-
|
|
480
|
+
// Variadic addition over ANY types (mathjs parity). Folds pairwise through the
|
|
481
|
+
// binary `add`, so Complex / Fraction / BigNumber / mixed arguments work — not
|
|
482
|
+
// only number. (Needed e.g. by polynomialRoot's `add(b, C, …)` where C is a
|
|
483
|
+
// complex cube root.) NOTE: this typed-function fork delivers the variadic
|
|
484
|
+
// rest as a single packed array argument, not via JS spread.
|
|
485
|
+
"any, any, ...any": (a, b, rest) => {
|
|
486
|
+
const op = add;
|
|
487
|
+
let result = op(a, b);
|
|
488
|
+
for (let i = 0; i < rest.length; i++) {
|
|
489
|
+
result = op(result, rest[i]);
|
|
490
|
+
}
|
|
491
|
+
return result;
|
|
492
|
+
}
|
|
484
493
|
});
|
|
485
494
|
var subtract = mathTyped("subtract", {
|
|
486
495
|
"number, number": (a, b) => a - b,
|
|
@@ -526,8 +535,17 @@ var multiply = mathTyped("multiply", {
|
|
|
526
535
|
const result = await computePool.scale(a, scalar);
|
|
527
536
|
return result.result;
|
|
528
537
|
},
|
|
529
|
-
// Variadic multiplication
|
|
530
|
-
|
|
538
|
+
// Variadic multiplication over ANY types (mathjs parity); folds pairwise
|
|
539
|
+
// through the binary `multiply`. See the variadic-add note above re: types and
|
|
540
|
+
// the packed-array rest shape.
|
|
541
|
+
"any, any, ...any": (a, b, rest) => {
|
|
542
|
+
const op = multiply;
|
|
543
|
+
let result = op(a, b);
|
|
544
|
+
for (let i = 0; i < rest.length; i++) {
|
|
545
|
+
result = op(result, rest[i]);
|
|
546
|
+
}
|
|
547
|
+
return result;
|
|
548
|
+
}
|
|
531
549
|
});
|
|
532
550
|
var divide = mathTyped("divide", {
|
|
533
551
|
"number, number": (a, b) => a / b,
|
|
@@ -17687,12 +17705,12 @@ var dependencies5 = ["typed", "Complex"];
|
|
|
17687
17705
|
var createExpm1 = /* @__PURE__ */ factory(
|
|
17688
17706
|
name5,
|
|
17689
17707
|
dependencies5,
|
|
17690
|
-
({ typed: typed3, Complex:
|
|
17708
|
+
({ typed: typed3, Complex: Complex9 }) => {
|
|
17691
17709
|
return typed3(name5, {
|
|
17692
17710
|
number: expm1Number,
|
|
17693
17711
|
Complex: function(x) {
|
|
17694
17712
|
const r = Math.exp(x.re);
|
|
17695
|
-
return new
|
|
17713
|
+
return new Complex9(r * Math.cos(x.im) - 1, r * Math.sin(x.im));
|
|
17696
17714
|
},
|
|
17697
17715
|
BigNumber: function(x) {
|
|
17698
17716
|
return x.exp().minus(1);
|
|
@@ -17721,12 +17739,12 @@ var log16 = log10Number(16);
|
|
|
17721
17739
|
var createLog10 = /* @__PURE__ */ factory(
|
|
17722
17740
|
name6,
|
|
17723
17741
|
dependencies6,
|
|
17724
|
-
({ typed: typed3, config, Complex:
|
|
17742
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
17725
17743
|
function complexLog(c) {
|
|
17726
17744
|
return c.log().div(Math.LN10);
|
|
17727
17745
|
}
|
|
17728
17746
|
function complexLogNumber(x) {
|
|
17729
|
-
return complexLog(new
|
|
17747
|
+
return complexLog(new Complex9(x, 0));
|
|
17730
17748
|
}
|
|
17731
17749
|
return typed3(name6, {
|
|
17732
17750
|
number: function(x) {
|
|
@@ -17758,9 +17776,9 @@ var dependencies7 = ["typed", "config", "Complex"];
|
|
|
17758
17776
|
var createLog2 = /* @__PURE__ */ factory(
|
|
17759
17777
|
name7,
|
|
17760
17778
|
dependencies7,
|
|
17761
|
-
({ typed: typed3, config, Complex:
|
|
17779
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
17762
17780
|
function complexLog2Number(x) {
|
|
17763
|
-
return _log2Complex(new
|
|
17781
|
+
return _log2Complex(new Complex9(x, 0));
|
|
17764
17782
|
}
|
|
17765
17783
|
return typed3(name7, {
|
|
17766
17784
|
number: function(x) {
|
|
@@ -17785,7 +17803,7 @@ var createLog2 = /* @__PURE__ */ factory(
|
|
|
17785
17803
|
});
|
|
17786
17804
|
function _log2Complex(x) {
|
|
17787
17805
|
const newX = Math.sqrt(x.re * x.re + x.im * x.im);
|
|
17788
|
-
return new
|
|
17806
|
+
return new Complex9(
|
|
17789
17807
|
Math.log2 ? Math.log2(newX) : Math.log(newX) / Math.LN2,
|
|
17790
17808
|
Math.atan2(x.im, x.re) / Math.LN2
|
|
17791
17809
|
);
|
|
@@ -17861,7 +17879,7 @@ var dependencies10 = ["config", "typed", "Complex"];
|
|
|
17861
17879
|
var createSqrt = /* @__PURE__ */ factory(
|
|
17862
17880
|
name10,
|
|
17863
17881
|
dependencies10,
|
|
17864
|
-
({ config, typed: typed3, Complex:
|
|
17882
|
+
({ config, typed: typed3, Complex: Complex9 }) => {
|
|
17865
17883
|
return typed3("sqrt", {
|
|
17866
17884
|
number: _sqrtNumber,
|
|
17867
17885
|
Complex: function(x) {
|
|
@@ -17884,7 +17902,7 @@ var createSqrt = /* @__PURE__ */ factory(
|
|
|
17884
17902
|
} else if (x >= 0 || config.predictable) {
|
|
17885
17903
|
return Math.sqrt(x);
|
|
17886
17904
|
} else {
|
|
17887
|
-
return new
|
|
17905
|
+
return new Complex9(x, 0).sqrt();
|
|
17888
17906
|
}
|
|
17889
17907
|
}
|
|
17890
17908
|
}
|
|
@@ -18876,7 +18894,7 @@ var dependencies29 = ["Complex", "typed"];
|
|
|
18876
18894
|
var createLgamma = /* @__PURE__ */ factory(
|
|
18877
18895
|
name29,
|
|
18878
18896
|
dependencies29,
|
|
18879
|
-
({ Complex:
|
|
18897
|
+
({ Complex: Complex9, typed: typed3 }) => {
|
|
18880
18898
|
const SMALL_RE = 7;
|
|
18881
18899
|
const SMALL_IM = 7;
|
|
18882
18900
|
const coeffs = [
|
|
@@ -18922,16 +18940,16 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
18922
18940
|
const LOGPI = 1.1447298858494002;
|
|
18923
18941
|
const REFLECTION = 0.1;
|
|
18924
18942
|
if (n.isNaN()) {
|
|
18925
|
-
return new
|
|
18943
|
+
return new Complex9(NaN, NaN);
|
|
18926
18944
|
} else if (n.im === 0) {
|
|
18927
|
-
return new
|
|
18945
|
+
return new Complex9(lgammaNumber(n.re), 0);
|
|
18928
18946
|
} else if (n.re >= SMALL_RE || Math.abs(n.im) >= SMALL_IM) {
|
|
18929
18947
|
return lgammaStirling(n);
|
|
18930
18948
|
} else if (n.re <= REFLECTION) {
|
|
18931
18949
|
const tmp = copysign(TWOPI, n.im) * Math.floor(0.5 * n.re + 0.25);
|
|
18932
18950
|
const a = n.mul(Math.PI).sin().log();
|
|
18933
|
-
const b = lgammaComplex(new
|
|
18934
|
-
return new
|
|
18951
|
+
const b = lgammaComplex(new Complex9(1 - n.re, -n.im));
|
|
18952
|
+
return new Complex9(LOGPI, tmp).sub(a).sub(b);
|
|
18935
18953
|
} else if (n.im >= 0) {
|
|
18936
18954
|
return lgammaRecurrence(n);
|
|
18937
18955
|
} else {
|
|
@@ -18940,7 +18958,7 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
18940
18958
|
}
|
|
18941
18959
|
function lgammaStirling(z) {
|
|
18942
18960
|
const leftPart = z.sub(0.5).mul(z.log()).sub(z).add(lnSqrt2PI);
|
|
18943
|
-
const rz = new
|
|
18961
|
+
const rz = new Complex9(1, 0).div(z);
|
|
18944
18962
|
const rzz = rz.div(z);
|
|
18945
18963
|
let a = coeffs[0];
|
|
18946
18964
|
let b = coeffs[1];
|
|
@@ -18966,7 +18984,7 @@ var createLgamma = /* @__PURE__ */ factory(
|
|
|
18966
18984
|
sb = nsb;
|
|
18967
18985
|
z = z.add(1);
|
|
18968
18986
|
}
|
|
18969
|
-
return lgammaStirling(z).sub(shiftprod.log()).sub(new
|
|
18987
|
+
return lgammaStirling(z).sub(shiftprod.log()).sub(new Complex9(0, signflips * 2 * Math.PI * 1));
|
|
18970
18988
|
}
|
|
18971
18989
|
}
|
|
18972
18990
|
);
|
|
@@ -19408,13 +19426,13 @@ var dependencies36 = ["typed", "config", "Complex"];
|
|
|
19408
19426
|
var createAcos = /* @__PURE__ */ factory(
|
|
19409
19427
|
name36,
|
|
19410
19428
|
dependencies36,
|
|
19411
|
-
({ typed: typed3, config, Complex:
|
|
19429
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19412
19430
|
return typed3(name36, {
|
|
19413
19431
|
number: function(x) {
|
|
19414
19432
|
if (x >= -1 && x <= 1 || config.predictable) {
|
|
19415
19433
|
return Math.acos(x);
|
|
19416
19434
|
} else {
|
|
19417
|
-
return new
|
|
19435
|
+
return new Complex9(x, 0).acos();
|
|
19418
19436
|
}
|
|
19419
19437
|
},
|
|
19420
19438
|
Complex: function(x) {
|
|
@@ -19433,16 +19451,16 @@ var dependencies37 = ["typed", "config", "Complex"];
|
|
|
19433
19451
|
var createAcosh = /* @__PURE__ */ factory(
|
|
19434
19452
|
name37,
|
|
19435
19453
|
dependencies37,
|
|
19436
|
-
({ typed: typed3, config, Complex:
|
|
19454
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19437
19455
|
return typed3(name37, {
|
|
19438
19456
|
number: function(x) {
|
|
19439
19457
|
if (x >= 1 || config.predictable) {
|
|
19440
19458
|
return acoshNumber(x);
|
|
19441
19459
|
}
|
|
19442
19460
|
if (x <= -1) {
|
|
19443
|
-
return new
|
|
19461
|
+
return new Complex9(Math.log(Math.sqrt(x * x - 1) - x), Math.PI);
|
|
19444
19462
|
}
|
|
19445
|
-
return new
|
|
19463
|
+
return new Complex9(x, 0).acosh();
|
|
19446
19464
|
},
|
|
19447
19465
|
Complex: function(x) {
|
|
19448
19466
|
return x.acosh();
|
|
@@ -19479,13 +19497,13 @@ var dependencies39 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19479
19497
|
var createAcoth = /* @__PURE__ */ factory(
|
|
19480
19498
|
name39,
|
|
19481
19499
|
dependencies39,
|
|
19482
|
-
({ typed: typed3, config, Complex:
|
|
19500
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19483
19501
|
return typed3(name39, {
|
|
19484
19502
|
number: function(x) {
|
|
19485
19503
|
if (x >= 1 || x <= -1 || config.predictable) {
|
|
19486
19504
|
return acothNumber(x);
|
|
19487
19505
|
}
|
|
19488
|
-
return new
|
|
19506
|
+
return new Complex9(x, 0).acoth();
|
|
19489
19507
|
},
|
|
19490
19508
|
Complex: function(x) {
|
|
19491
19509
|
return x.acoth();
|
|
@@ -19503,13 +19521,13 @@ var dependencies40 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19503
19521
|
var createAcsc = /* @__PURE__ */ factory(
|
|
19504
19522
|
name40,
|
|
19505
19523
|
dependencies40,
|
|
19506
|
-
({ typed: typed3, config, Complex:
|
|
19524
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19507
19525
|
return typed3(name40, {
|
|
19508
19526
|
number: function(x) {
|
|
19509
19527
|
if (x <= -1 || x >= 1 || config.predictable) {
|
|
19510
19528
|
return acscNumber(x);
|
|
19511
19529
|
}
|
|
19512
|
-
return new
|
|
19530
|
+
return new Complex9(x, 0).acsc();
|
|
19513
19531
|
},
|
|
19514
19532
|
Complex: function(x) {
|
|
19515
19533
|
return x.acsc();
|
|
@@ -19546,13 +19564,13 @@ var dependencies42 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19546
19564
|
var createAsec = /* @__PURE__ */ factory(
|
|
19547
19565
|
name42,
|
|
19548
19566
|
dependencies42,
|
|
19549
|
-
({ typed: typed3, config, Complex:
|
|
19567
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19550
19568
|
return typed3(name42, {
|
|
19551
19569
|
number: function(x) {
|
|
19552
19570
|
if (x <= -1 || x >= 1 || config.predictable) {
|
|
19553
19571
|
return asecNumber(x);
|
|
19554
19572
|
}
|
|
19555
|
-
return new
|
|
19573
|
+
return new Complex9(x, 0).asec();
|
|
19556
19574
|
},
|
|
19557
19575
|
Complex: function(x) {
|
|
19558
19576
|
return x.asec();
|
|
@@ -19570,7 +19588,7 @@ var dependencies43 = ["typed", "config", "Complex", "BigNumber"];
|
|
|
19570
19588
|
var createAsech = /* @__PURE__ */ factory(
|
|
19571
19589
|
name43,
|
|
19572
19590
|
dependencies43,
|
|
19573
|
-
({ typed: typed3, config, Complex:
|
|
19591
|
+
({ typed: typed3, config, Complex: Complex9, BigNumber: BigNumber9 }) => {
|
|
19574
19592
|
return typed3(name43, {
|
|
19575
19593
|
number: function(x) {
|
|
19576
19594
|
if (x <= 1 && x >= -1 || config.predictable) {
|
|
@@ -19579,9 +19597,9 @@ var createAsech = /* @__PURE__ */ factory(
|
|
|
19579
19597
|
return asechNumber(x);
|
|
19580
19598
|
}
|
|
19581
19599
|
const ret = Math.sqrt(xInv * xInv - 1);
|
|
19582
|
-
return new
|
|
19600
|
+
return new Complex9(Math.log(ret - xInv), Math.PI);
|
|
19583
19601
|
}
|
|
19584
|
-
return new
|
|
19602
|
+
return new Complex9(x, 0).asech();
|
|
19585
19603
|
},
|
|
19586
19604
|
Complex: function(x) {
|
|
19587
19605
|
return x.asech();
|
|
@@ -19599,13 +19617,13 @@ var dependencies44 = ["typed", "config", "Complex"];
|
|
|
19599
19617
|
var createAsin = /* @__PURE__ */ factory(
|
|
19600
19618
|
name44,
|
|
19601
19619
|
dependencies44,
|
|
19602
|
-
({ typed: typed3, config, Complex:
|
|
19620
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19603
19621
|
return typed3(name44, {
|
|
19604
19622
|
number: function(x) {
|
|
19605
19623
|
if (x >= -1 && x <= 1 || config.predictable) {
|
|
19606
19624
|
return Math.asin(x);
|
|
19607
19625
|
} else {
|
|
19608
|
-
return new
|
|
19626
|
+
return new Complex9(x, 0).asin();
|
|
19609
19627
|
}
|
|
19610
19628
|
},
|
|
19611
19629
|
Complex: function(x) {
|
|
@@ -19664,13 +19682,13 @@ var dependencies47 = ["typed", "config", "Complex"];
|
|
|
19664
19682
|
var createAtanh = /* @__PURE__ */ factory(
|
|
19665
19683
|
name47,
|
|
19666
19684
|
dependencies47,
|
|
19667
|
-
({ typed: typed3, config, Complex:
|
|
19685
|
+
({ typed: typed3, config, Complex: Complex9 }) => {
|
|
19668
19686
|
return typed3(name47, {
|
|
19669
19687
|
number: function(x) {
|
|
19670
19688
|
if (x <= 1 && x >= -1 || config.predictable) {
|
|
19671
19689
|
return atanhNumber(x);
|
|
19672
19690
|
}
|
|
19673
|
-
return new
|
|
19691
|
+
return new Complex9(x, 0).atanh();
|
|
19674
19692
|
},
|
|
19675
19693
|
Complex: function(x) {
|
|
19676
19694
|
return x.atanh();
|
|
@@ -23394,7 +23412,7 @@ var createCbrt = /* @__PURE__ */ factory(
|
|
|
23394
23412
|
isNegative: isNegative2,
|
|
23395
23413
|
unaryMinus: unaryMinus2,
|
|
23396
23414
|
matrix: matrix2,
|
|
23397
|
-
Complex:
|
|
23415
|
+
Complex: Complex9,
|
|
23398
23416
|
BigNumber: BigNumber9,
|
|
23399
23417
|
Fraction: Fraction5
|
|
23400
23418
|
}) => {
|
|
@@ -23412,12 +23430,12 @@ var createCbrt = /* @__PURE__ */ factory(
|
|
|
23412
23430
|
function _cbrtComplex(x, allRoots) {
|
|
23413
23431
|
const arg3 = x.arg() / 3;
|
|
23414
23432
|
const abs2 = x.abs();
|
|
23415
|
-
const principal = new
|
|
23433
|
+
const principal = new Complex9(cbrtNumber(abs2), 0).mul(new Complex9(0, arg3).exp());
|
|
23416
23434
|
if (allRoots) {
|
|
23417
23435
|
const all = [
|
|
23418
23436
|
principal,
|
|
23419
|
-
new
|
|
23420
|
-
new
|
|
23437
|
+
new Complex9(cbrtNumber(abs2), 0).mul(new Complex9(0, arg3 + Math.PI * 2 / 3).exp()),
|
|
23438
|
+
new Complex9(cbrtNumber(abs2), 0).mul(new Complex9(0, arg3 - Math.PI * 2 / 3).exp())
|
|
23421
23439
|
];
|
|
23422
23440
|
return config.matrix === "Array" ? all : matrix2(all);
|
|
23423
23441
|
} else {
|
|
@@ -23466,27 +23484,27 @@ var createNthRoots = /* @__PURE__ */ factory(
|
|
|
23466
23484
|
typed: typed3,
|
|
23467
23485
|
config: _config,
|
|
23468
23486
|
divideScalar: _divideScalar,
|
|
23469
|
-
Complex:
|
|
23487
|
+
Complex: Complex9
|
|
23470
23488
|
}) => {
|
|
23471
23489
|
const _calculateExactResult = [
|
|
23472
23490
|
function realPos(val) {
|
|
23473
|
-
return new
|
|
23491
|
+
return new Complex9(val, 0);
|
|
23474
23492
|
},
|
|
23475
23493
|
function imagPos(val) {
|
|
23476
|
-
return new
|
|
23494
|
+
return new Complex9(0, val);
|
|
23477
23495
|
},
|
|
23478
23496
|
function realNeg(val) {
|
|
23479
|
-
return new
|
|
23497
|
+
return new Complex9(-val, 0);
|
|
23480
23498
|
},
|
|
23481
23499
|
function imagNeg(val) {
|
|
23482
|
-
return new
|
|
23500
|
+
return new Complex9(0, -val);
|
|
23483
23501
|
}
|
|
23484
23502
|
];
|
|
23485
23503
|
function _nthComplexRoots(a, root) {
|
|
23486
23504
|
if (root < 0) throw new Error("Root must be greater than zero");
|
|
23487
23505
|
if (root === 0) throw new Error("Root must be non-zero");
|
|
23488
23506
|
if (root % 1 !== 0) throw new Error("Root must be an integer");
|
|
23489
|
-
if (a === 0 || a.abs() === 0) return [new
|
|
23507
|
+
if (a === 0 || a.abs() === 0) return [new Complex9(0, 0)];
|
|
23490
23508
|
const aIsNumeric = typeof a === "number";
|
|
23491
23509
|
let offset;
|
|
23492
23510
|
if (aIsNumeric || a.re === 0 || a.im === 0) {
|
|
@@ -23508,7 +23526,7 @@ var createNthRoots = /* @__PURE__ */ factory(
|
|
|
23508
23526
|
roots.push(_calculateExactResult[halfPiFactor % 4](r));
|
|
23509
23527
|
continue;
|
|
23510
23528
|
}
|
|
23511
|
-
roots.push(new
|
|
23529
|
+
roots.push(new Complex9({ r, phi: (arg3 + 2 * Math.PI * k) / root }));
|
|
23512
23530
|
}
|
|
23513
23531
|
return roots;
|
|
23514
23532
|
}
|
|
@@ -23895,12 +23913,12 @@ var nlg16 = Math.log(16);
|
|
|
23895
23913
|
var createLog = /* @__PURE__ */ factory(
|
|
23896
23914
|
name112,
|
|
23897
23915
|
dependencies112,
|
|
23898
|
-
({ typed: typed3, typeOf: typeOf3, config, divideScalar: divideScalar2, Complex:
|
|
23916
|
+
({ typed: typed3, typeOf: typeOf3, config, divideScalar: divideScalar2, Complex: Complex9 }) => {
|
|
23899
23917
|
function complexLog(c) {
|
|
23900
23918
|
return c.log();
|
|
23901
23919
|
}
|
|
23902
23920
|
function complexLogNumber(x) {
|
|
23903
|
-
return complexLog(new
|
|
23921
|
+
return complexLog(new Complex9(x, 0));
|
|
23904
23922
|
}
|
|
23905
23923
|
return typed3(name112, {
|
|
23906
23924
|
number: function(x) {
|
|
@@ -25146,7 +25164,7 @@ var dependencies126 = ["typed", "add", "multiply", "Complex", "number"];
|
|
|
25146
25164
|
var createZpk2tf = /* @__PURE__ */ factory(
|
|
25147
25165
|
name126,
|
|
25148
25166
|
dependencies126,
|
|
25149
|
-
({ typed: typed3, add: add2, multiply: multiply2, Complex:
|
|
25167
|
+
({ typed: typed3, add: add2, multiply: multiply2, Complex: Complex9, number: number2 }) => {
|
|
25150
25168
|
return typed3(name126, {
|
|
25151
25169
|
"Array,Array,number": function(z, p, k) {
|
|
25152
25170
|
return _zpk2tf(z, p, k);
|
|
@@ -25168,17 +25186,17 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
25168
25186
|
if (p.some((el) => el.type === "BigNumber")) {
|
|
25169
25187
|
p = p.map((el) => number2(el));
|
|
25170
25188
|
}
|
|
25171
|
-
let num = [
|
|
25172
|
-
let den = [
|
|
25189
|
+
let num = [Complex9(1, 0)];
|
|
25190
|
+
let den = [Complex9(1, 0)];
|
|
25173
25191
|
for (let i = 0; i < z.length; i++) {
|
|
25174
25192
|
let zero = z[i];
|
|
25175
|
-
if (typeof zero === "number") zero =
|
|
25176
|
-
num = _multiply(num, [
|
|
25193
|
+
if (typeof zero === "number") zero = Complex9(zero, 0);
|
|
25194
|
+
num = _multiply(num, [Complex9(1, 0), Complex9(-zero.re, -zero.im)]);
|
|
25177
25195
|
}
|
|
25178
25196
|
for (let i = 0; i < p.length; i++) {
|
|
25179
25197
|
let pole = p[i];
|
|
25180
|
-
if (typeof pole === "number") pole =
|
|
25181
|
-
den = _multiply(den, [
|
|
25198
|
+
if (typeof pole === "number") pole = Complex9(pole, 0);
|
|
25199
|
+
den = _multiply(den, [Complex9(1, 0), Complex9(-pole.re, -pole.im)]);
|
|
25182
25200
|
}
|
|
25183
25201
|
for (let i = 0; i < num.length; i++) {
|
|
25184
25202
|
num[i] = multiply2(num[i], k);
|
|
@@ -25188,7 +25206,7 @@ var createZpk2tf = /* @__PURE__ */ factory(
|
|
|
25188
25206
|
function _multiply(a, b) {
|
|
25189
25207
|
const c = [];
|
|
25190
25208
|
for (let i = 0; i < a.length + b.length - 1; i++) {
|
|
25191
|
-
c[i] =
|
|
25209
|
+
c[i] = Complex9(0, 0);
|
|
25192
25210
|
for (let j = 0; j < a.length; j++) {
|
|
25193
25211
|
if (i - j >= 0 && i - j < b.length) {
|
|
25194
25212
|
c[i] = add2(c[i], multiply2(a[j], b[i - j]));
|
|
@@ -26431,13 +26449,13 @@ var dependencies142 = ["typed", "config", "divideScalar", "log", "Complex"];
|
|
|
26431
26449
|
var createLog1p = /* @__PURE__ */ factory(
|
|
26432
26450
|
name142,
|
|
26433
26451
|
dependencies142,
|
|
26434
|
-
({ typed: typed3, config, divideScalar: divideScalar2, log: log3, Complex:
|
|
26452
|
+
({ typed: typed3, config, divideScalar: divideScalar2, log: log3, Complex: Complex9 }) => {
|
|
26435
26453
|
return typed3(name142, {
|
|
26436
26454
|
number: function(x) {
|
|
26437
26455
|
if (x >= -1 || config.predictable) {
|
|
26438
26456
|
return log1p2(x);
|
|
26439
26457
|
} else {
|
|
26440
|
-
return _log1pComplex(new
|
|
26458
|
+
return _log1pComplex(new Complex9(x, 0));
|
|
26441
26459
|
}
|
|
26442
26460
|
},
|
|
26443
26461
|
Complex: _log1pComplex,
|
|
@@ -26446,7 +26464,7 @@ var createLog1p = /* @__PURE__ */ factory(
|
|
|
26446
26464
|
if (!y.isNegative() || config.predictable) {
|
|
26447
26465
|
return y.ln();
|
|
26448
26466
|
} else {
|
|
26449
|
-
return _log1pComplex(new
|
|
26467
|
+
return _log1pComplex(new Complex9(x.toNumber(), 0));
|
|
26450
26468
|
}
|
|
26451
26469
|
},
|
|
26452
26470
|
"Array | Matrix": typed3.referToSelf(
|
|
@@ -26460,7 +26478,7 @@ var createLog1p = /* @__PURE__ */ factory(
|
|
|
26460
26478
|
});
|
|
26461
26479
|
function _log1pComplex(x) {
|
|
26462
26480
|
const xRe1p = x.re + 1;
|
|
26463
|
-
return new
|
|
26481
|
+
return new Complex9(Math.log(Math.sqrt(xRe1p * xRe1p + x.im * x.im)), Math.atan2(x.im, xRe1p));
|
|
26464
26482
|
}
|
|
26465
26483
|
}
|
|
26466
26484
|
);
|
|
@@ -26593,7 +26611,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
26593
26611
|
inv: inv2,
|
|
26594
26612
|
number: number2,
|
|
26595
26613
|
fraction: fraction2,
|
|
26596
|
-
Complex:
|
|
26614
|
+
Complex: Complex9
|
|
26597
26615
|
}) => {
|
|
26598
26616
|
return typed3(name144, {
|
|
26599
26617
|
"number, number": _pow,
|
|
@@ -26604,7 +26622,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
26604
26622
|
if (y.isInteger() || x.gte(0) || config.predictable) {
|
|
26605
26623
|
return x.pow(y);
|
|
26606
26624
|
} else {
|
|
26607
|
-
return new
|
|
26625
|
+
return new Complex9(x.toNumber(), 0).pow(y.toNumber(), 0);
|
|
26608
26626
|
}
|
|
26609
26627
|
},
|
|
26610
26628
|
"bigint, bigint": (x, y) => x ** y,
|
|
@@ -26653,7 +26671,7 @@ var createPow = /* @__PURE__ */ factory(
|
|
|
26653
26671
|
if (isPowZeroAtInfinity(x, y)) {
|
|
26654
26672
|
return 0;
|
|
26655
26673
|
}
|
|
26656
|
-
return new
|
|
26674
|
+
return new Complex9(x, 0).pow(y, 0);
|
|
26657
26675
|
}
|
|
26658
26676
|
}
|
|
26659
26677
|
function _powArray(x, y) {
|
|
@@ -28054,7 +28072,7 @@ var createFixNumber = /* @__PURE__ */ factory(
|
|
|
28054
28072
|
var createFix = /* @__PURE__ */ factory(
|
|
28055
28073
|
name167,
|
|
28056
28074
|
dependencies167,
|
|
28057
|
-
({ typed: typed3, Complex:
|
|
28075
|
+
({ typed: typed3, Complex: Complex9, matrix: matrix2, ceil: ceil2, floor: floor2, equalScalar: equalScalar3, zeros: zeros3, DenseMatrix: DenseMatrix3 }) => {
|
|
28058
28076
|
const matAlgo12xSfs = createMatAlgo12xSfs({ typed: typed3, DenseMatrix: DenseMatrix3 });
|
|
28059
28077
|
const matAlgo14xDs = createMatAlgo14xDs({ typed: typed3 });
|
|
28060
28078
|
const fixNumber = createFixNumber({ typed: typed3, ceil: ceil2, floor: floor2 });
|
|
@@ -28062,20 +28080,20 @@ var createFix = /* @__PURE__ */ factory(
|
|
|
28062
28080
|
number: fixNumber.signatures.number,
|
|
28063
28081
|
"number, number | BigNumber": fixNumber.signatures["number,number"],
|
|
28064
28082
|
Complex: function(x) {
|
|
28065
|
-
return new
|
|
28083
|
+
return new Complex9(
|
|
28066
28084
|
x.re > 0 ? Math.floor(x.re) : Math.ceil(x.re),
|
|
28067
28085
|
x.im > 0 ? Math.floor(x.im) : Math.ceil(x.im)
|
|
28068
28086
|
);
|
|
28069
28087
|
},
|
|
28070
28088
|
"Complex, number": function(x, n) {
|
|
28071
|
-
return new
|
|
28089
|
+
return new Complex9(
|
|
28072
28090
|
x.re > 0 ? floor2(x.re, n) : ceil2(x.re, n),
|
|
28073
28091
|
x.im > 0 ? floor2(x.im, n) : ceil2(x.im, n)
|
|
28074
28092
|
);
|
|
28075
28093
|
},
|
|
28076
28094
|
"Complex, BigNumber": function(x, bn) {
|
|
28077
28095
|
const n = bn.toNumber();
|
|
28078
|
-
return new
|
|
28096
|
+
return new Complex9(
|
|
28079
28097
|
x.re > 0 ? floor2(x.re, n) : ceil2(x.re, n),
|
|
28080
28098
|
x.im > 0 ? floor2(x.im, n) : ceil2(x.im, n)
|
|
28081
28099
|
);
|
|
@@ -28445,7 +28463,7 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
28445
28463
|
divideScalar: divideScalar2,
|
|
28446
28464
|
multiply: multiply2,
|
|
28447
28465
|
add: add2,
|
|
28448
|
-
Complex:
|
|
28466
|
+
Complex: Complex9
|
|
28449
28467
|
}) => {
|
|
28450
28468
|
return typed3(name172, {
|
|
28451
28469
|
"Array | Matrix": function(x) {
|
|
@@ -28540,12 +28558,12 @@ var createPinv = /* @__PURE__ */ factory(
|
|
|
28540
28558
|
return { C, F };
|
|
28541
28559
|
}
|
|
28542
28560
|
function _isZero(x) {
|
|
28543
|
-
return equal2(add2(x,
|
|
28561
|
+
return equal2(add2(x, Complex9(1, 1)), add2(0, Complex9(1, 1)));
|
|
28544
28562
|
}
|
|
28545
28563
|
function _isZeros(arr) {
|
|
28546
28564
|
return deepEqual3(
|
|
28547
|
-
add2(arr,
|
|
28548
|
-
add2(multiply2(arr, 0),
|
|
28565
|
+
add2(arr, Complex9(1, 1)),
|
|
28566
|
+
add2(multiply2(arr, 0), Complex9(1, 1))
|
|
28549
28567
|
);
|
|
28550
28568
|
}
|
|
28551
28569
|
}
|
|
@@ -28936,25 +28954,25 @@ var createGamma = /* @__PURE__ */ factory(
|
|
|
28936
28954
|
multiplyScalar: _multiplyScalar,
|
|
28937
28955
|
pow: _pow,
|
|
28938
28956
|
BigNumber: BigNumber9,
|
|
28939
|
-
Complex:
|
|
28957
|
+
Complex: Complex9
|
|
28940
28958
|
}) => {
|
|
28941
28959
|
function gammaComplex(n) {
|
|
28942
28960
|
if (n.im === 0) {
|
|
28943
28961
|
return gammaNumber(n.re);
|
|
28944
28962
|
}
|
|
28945
28963
|
if (n.re < 0.5) {
|
|
28946
|
-
const t2 = new
|
|
28947
|
-
const r = new
|
|
28964
|
+
const t2 = new Complex9(1 - n.re, -n.im);
|
|
28965
|
+
const r = new Complex9(Math.PI * n.re, Math.PI * n.im);
|
|
28948
28966
|
const gammaT = gammaComplex(t2);
|
|
28949
|
-
return new
|
|
28967
|
+
return new Complex9(Math.PI).div(r.sin()).div(gammaT);
|
|
28950
28968
|
}
|
|
28951
|
-
const z = new
|
|
28952
|
-
let x = new
|
|
28969
|
+
const z = new Complex9(n.re - 1, n.im);
|
|
28970
|
+
let x = new Complex9(gammaP[0], 0);
|
|
28953
28971
|
for (let i = 1; i < gammaP.length; ++i) {
|
|
28954
|
-
const gammaPval = new
|
|
28972
|
+
const gammaPval = new Complex9(gammaP[i], 0);
|
|
28955
28973
|
x = x.add(gammaPval.div(z.add(i)));
|
|
28956
28974
|
}
|
|
28957
|
-
const t = new
|
|
28975
|
+
const t = new Complex9(z.re + gammaG + 0.5, z.im);
|
|
28958
28976
|
const twoPiSqrt = Math.sqrt(2 * Math.PI);
|
|
28959
28977
|
const tpow = t.pow(z.add(0.5));
|
|
28960
28978
|
const expt = t.neg().exp();
|
|
@@ -32018,7 +32036,7 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
32018
32036
|
isNumeric: isNumeric2,
|
|
32019
32037
|
format: format6,
|
|
32020
32038
|
number: number2,
|
|
32021
|
-
Complex:
|
|
32039
|
+
Complex: Complex9,
|
|
32022
32040
|
BigNumber: BigNumber9,
|
|
32023
32041
|
Fraction: Fraction5
|
|
32024
32042
|
}) => {
|
|
@@ -34127,7 +34145,7 @@ var createUnitClass = /* @__PURE__ */ factory(
|
|
|
34127
34145
|
name: "VAR",
|
|
34128
34146
|
base: BASE_UNITS.POWER,
|
|
34129
34147
|
prefixes: PREFIXES.SHORT,
|
|
34130
|
-
value:
|
|
34148
|
+
value: Complex9.I,
|
|
34131
34149
|
offset: 0
|
|
34132
34150
|
},
|
|
34133
34151
|
VA: {
|
|
@@ -37203,7 +37221,7 @@ var dependencies226 = ["typed", "add", "multiply", "Complex", "divide", "matrix"
|
|
|
37203
37221
|
var createFreqz = /* @__PURE__ */ factory(
|
|
37204
37222
|
name226,
|
|
37205
37223
|
dependencies226,
|
|
37206
|
-
({ typed: typed3, add: add2, multiply: multiply2, Complex:
|
|
37224
|
+
({ typed: typed3, add: add2, multiply: multiply2, Complex: Complex9, divide: divide2, matrix: matrix2 }) => {
|
|
37207
37225
|
return typed3(name226, {
|
|
37208
37226
|
"Array, Array": function(b, a) {
|
|
37209
37227
|
const w = createBins(512);
|
|
@@ -37272,7 +37290,7 @@ var createFreqz = /* @__PURE__ */ factory(
|
|
|
37272
37290
|
);
|
|
37273
37291
|
const h = [];
|
|
37274
37292
|
for (let i = 0; i < w.length; i++) {
|
|
37275
|
-
h.push(
|
|
37293
|
+
h.push(Complex9(hRealAlloc.array[i], hImagAlloc.array[i]));
|
|
37276
37294
|
}
|
|
37277
37295
|
return { h, w };
|
|
37278
37296
|
} finally {
|
|
@@ -37294,18 +37312,18 @@ var createFreqz = /* @__PURE__ */ factory(
|
|
|
37294
37312
|
const num = [];
|
|
37295
37313
|
const den = [];
|
|
37296
37314
|
for (let i = 0; i < w.length; i++) {
|
|
37297
|
-
let sumNum =
|
|
37298
|
-
let sumDen =
|
|
37315
|
+
let sumNum = Complex9(0, 0);
|
|
37316
|
+
let sumDen = Complex9(0, 0);
|
|
37299
37317
|
for (let j = 0; j < b.length; j++) {
|
|
37300
37318
|
sumNum = add2(
|
|
37301
37319
|
sumNum,
|
|
37302
|
-
multiply2(b[j],
|
|
37320
|
+
multiply2(b[j], Complex9(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
37303
37321
|
);
|
|
37304
37322
|
}
|
|
37305
37323
|
for (let j = 0; j < a.length; j++) {
|
|
37306
37324
|
sumDen = add2(
|
|
37307
37325
|
sumDen,
|
|
37308
|
-
multiply2(a[j],
|
|
37326
|
+
multiply2(a[j], Complex9(Math.cos(-j * w[i]), Math.sin(-j * w[i])))
|
|
37309
37327
|
);
|
|
37310
37328
|
}
|
|
37311
37329
|
num.push(sumNum);
|
|
@@ -38612,7 +38630,7 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
38612
38630
|
sin: sin2,
|
|
38613
38631
|
subtract: subtract2,
|
|
38614
38632
|
add: add2,
|
|
38615
|
-
Complex:
|
|
38633
|
+
Complex: Complex9,
|
|
38616
38634
|
BigNumber: BigNumber9,
|
|
38617
38635
|
pi
|
|
38618
38636
|
}) => {
|
|
@@ -38648,16 +38666,16 @@ var createZeta = /* @__PURE__ */ factory(
|
|
|
38648
38666
|
}
|
|
38649
38667
|
function zetaComplex(s) {
|
|
38650
38668
|
if (s.re === 0 && s.im === 0) {
|
|
38651
|
-
return new
|
|
38669
|
+
return new Complex9(-0.5);
|
|
38652
38670
|
}
|
|
38653
38671
|
if (s.re === 1) {
|
|
38654
|
-
return new
|
|
38672
|
+
return new Complex9(NaN, NaN);
|
|
38655
38673
|
}
|
|
38656
38674
|
if (s.re === Infinity && s.im === 0) {
|
|
38657
|
-
return new
|
|
38675
|
+
return new Complex9(1);
|
|
38658
38676
|
}
|
|
38659
38677
|
if (s.im === Infinity || s.re === -Infinity) {
|
|
38660
|
-
return new
|
|
38678
|
+
return new Complex9(NaN, NaN);
|
|
38661
38679
|
}
|
|
38662
38680
|
return zeta2(
|
|
38663
38681
|
s,
|
|
@@ -43761,6 +43779,7 @@ function reviver(_key, value) {
|
|
|
43761
43779
|
|
|
43762
43780
|
// src/typed/cas.ts
|
|
43763
43781
|
import { computePool as computePool13 } from "@danielsimonjr/mathts-parallel";
|
|
43782
|
+
import { Complex as Complex8 } from "@danielsimonjr/mathts-core";
|
|
43764
43783
|
function evalAt(expr, varName, value) {
|
|
43765
43784
|
return evaluate(expr, { [varName]: value });
|
|
43766
43785
|
}
|
|
@@ -44199,7 +44218,40 @@ function seriesCoefficient(expr, varName, x0, k) {
|
|
|
44199
44218
|
const deriv = numericalDerivative(expr, varName, x0, k);
|
|
44200
44219
|
return deriv / factorial3(k);
|
|
44201
44220
|
}
|
|
44202
|
-
function
|
|
44221
|
+
function isComplexRoot(r) {
|
|
44222
|
+
return typeof r === "object" && r !== null && "re" in r && "im" in r;
|
|
44223
|
+
}
|
|
44224
|
+
function polyCoeffsDeg3(expr, varName) {
|
|
44225
|
+
const at = (x) => {
|
|
44226
|
+
const v = evalAt(expr, varName, x);
|
|
44227
|
+
return typeof v === "number" && Number.isFinite(v) ? v : NaN;
|
|
44228
|
+
};
|
|
44229
|
+
try {
|
|
44230
|
+
const f = [0, 1, 2, 3, 4].map(at);
|
|
44231
|
+
if (f.some((v) => !Number.isFinite(v))) return null;
|
|
44232
|
+
const d1 = f[1] - f[0];
|
|
44233
|
+
const d2 = f[2] - 2 * f[1] + f[0];
|
|
44234
|
+
const d3 = f[3] - 3 * f[2] + 3 * f[1] - f[0];
|
|
44235
|
+
const d4 = f[4] - 4 * f[3] + 6 * f[2] - 4 * f[1] + f[0];
|
|
44236
|
+
const scale = Math.max(1, ...f.map(Math.abs));
|
|
44237
|
+
if (Math.abs(d4) > 1e-7 * scale) return null;
|
|
44238
|
+
const c3 = d3 / 6;
|
|
44239
|
+
const c2 = d2 / 2 - d3 / 2;
|
|
44240
|
+
const c1 = d1 - d2 / 2 + d3 / 3;
|
|
44241
|
+
const c0 = f[0];
|
|
44242
|
+
const coeffs = [c0, c1, c2, c3];
|
|
44243
|
+
for (const x of [-1.5, 0.5, 2.5, 3.5]) {
|
|
44244
|
+
const recon = c0 + c1 * x + c2 * x * x + c3 * x * x * x;
|
|
44245
|
+
const actual = at(x);
|
|
44246
|
+
if (!Number.isFinite(actual)) return null;
|
|
44247
|
+
if (Math.abs(recon - actual) > 1e-6 * (1 + Math.abs(actual))) return null;
|
|
44248
|
+
}
|
|
44249
|
+
return coeffs;
|
|
44250
|
+
} catch {
|
|
44251
|
+
return null;
|
|
44252
|
+
}
|
|
44253
|
+
}
|
|
44254
|
+
function numericRealRoots(expr, varName) {
|
|
44203
44255
|
const roots = [];
|
|
44204
44256
|
const seen = /* @__PURE__ */ new Set();
|
|
44205
44257
|
const addRoot = (r) => {
|
|
@@ -44259,6 +44311,70 @@ function solve(expr, varName) {
|
|
|
44259
44311
|
roots.sort((a, b) => a - b);
|
|
44260
44312
|
return roots;
|
|
44261
44313
|
}
|
|
44314
|
+
function solve(equation, varName) {
|
|
44315
|
+
let expr = equation;
|
|
44316
|
+
if (equation.includes("=")) {
|
|
44317
|
+
const parts = equation.split("=");
|
|
44318
|
+
if (parts.length !== 2) {
|
|
44319
|
+
throw new SyntaxError("solve: equation must contain at most one '=' sign");
|
|
44320
|
+
}
|
|
44321
|
+
expr = `${parts[0].trim()} - (${parts[1].trim()})`;
|
|
44322
|
+
}
|
|
44323
|
+
const coeffs = polyCoeffsDeg3(expr, varName);
|
|
44324
|
+
if (coeffs) {
|
|
44325
|
+
let cleanComponent = function(x) {
|
|
44326
|
+
if (Math.abs(x) < 1e-10) return 0;
|
|
44327
|
+
const rounded = Math.round(x);
|
|
44328
|
+
return Math.abs(x - rounded) < 1e-8 ? rounded : x;
|
|
44329
|
+
}, pushReal = function(x) {
|
|
44330
|
+
const clean = cleanComponent(x);
|
|
44331
|
+
const key = `r${clean.toFixed(8)}`;
|
|
44332
|
+
if (!seen.has(key)) {
|
|
44333
|
+
seen.add(key);
|
|
44334
|
+
reals.push(clean);
|
|
44335
|
+
}
|
|
44336
|
+
};
|
|
44337
|
+
const [c0, c1, c2, c3] = coeffs;
|
|
44338
|
+
const eps = 1e-9;
|
|
44339
|
+
let degree2 = 0;
|
|
44340
|
+
if (Math.abs(c3) > eps) degree2 = 3;
|
|
44341
|
+
else if (Math.abs(c2) > eps) degree2 = 2;
|
|
44342
|
+
else if (Math.abs(c1) > eps) degree2 = 1;
|
|
44343
|
+
if (degree2 === 0) {
|
|
44344
|
+
return [];
|
|
44345
|
+
}
|
|
44346
|
+
let raw;
|
|
44347
|
+
try {
|
|
44348
|
+
const args = [c0, c1, c2, c3].slice(0, degree2 + 1);
|
|
44349
|
+
raw = polynomialRoot(...args);
|
|
44350
|
+
} catch {
|
|
44351
|
+
return numericRealRoots(expr, varName);
|
|
44352
|
+
}
|
|
44353
|
+
const reals = [];
|
|
44354
|
+
const complexRoots = [];
|
|
44355
|
+
const seen = /* @__PURE__ */ new Set();
|
|
44356
|
+
for (const r of raw) {
|
|
44357
|
+
if (isComplexRoot(r)) {
|
|
44358
|
+
if (Math.abs(r.im) < 1e-10) {
|
|
44359
|
+
pushReal(r.re);
|
|
44360
|
+
} else {
|
|
44361
|
+
const re3 = cleanComponent(r.re);
|
|
44362
|
+
const im3 = cleanComponent(r.im);
|
|
44363
|
+
const key = `${re3.toFixed(8)}|${im3.toFixed(8)}`;
|
|
44364
|
+
if (!seen.has(key)) {
|
|
44365
|
+
seen.add(key);
|
|
44366
|
+
complexRoots.push(new Complex8(re3, im3));
|
|
44367
|
+
}
|
|
44368
|
+
}
|
|
44369
|
+
} else {
|
|
44370
|
+
pushReal(r);
|
|
44371
|
+
}
|
|
44372
|
+
}
|
|
44373
|
+
reals.sort((a, b) => a - b);
|
|
44374
|
+
return [...reals, ...complexRoots];
|
|
44375
|
+
}
|
|
44376
|
+
return numericRealRoots(expr, varName);
|
|
44377
|
+
}
|
|
44262
44378
|
function implicitDiff(expr, x, y, scope) {
|
|
44263
44379
|
const dFdx = partialDerivative(expr, x, scope);
|
|
44264
44380
|
const dFdy = partialDerivative(expr, y, scope);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arithmetic.d.ts","sourceRoot":"","sources":["../../src/typed/arithmetic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAe,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAS1E,4BAA4B;AAC5B,KAAK,GAAG,GAAG,MAAM,CAAC;AASlB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"arithmetic.d.ts","sourceRoot":"","sources":["../../src/typed/arithmetic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAe,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAS1E,4BAA4B;AAC5B,KAAK,GAAG,GAAG,MAAM,CAAC;AASlB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,GAAG,wCAwCd,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,QAAQ,wCAyBnB,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,QAAQ,wCAgDnB,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,MAAM,wCAyBjB,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,UAAU,wCAYrB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,SAAS,wCAOpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,GAAG,wCAYd,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,IAAI,wCAgBf,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,GAAG,wCAQd,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,IAAI,wCAef,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,MAAM,wCAYjB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,IAAI,wCAiBf,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,IAAI,wCAef,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,OAAO,wCAIlB,CAAC;AAMH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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+E3B,CAAC"}
|
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;AASrD,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,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,GAAG,CAgEvF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,GAAG,CAkE5F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CA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