pimath 0.0.56 → 0.0.59
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/pi.js +119 -44
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +1 -0
- package/esm/maths/algebra/monom.js +36 -1
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +2 -1
- package/esm/maths/algebra/polynom.js +49 -38
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +4 -1
- package/esm/maths/algebra/rational.js +33 -4
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/expressions/numexp.d.ts +1 -1
- package/esm/maths/expressions/numexp.js +1 -1
- package/esm/maths/expressions/numexp.js.map +1 -1
- package/esm/maths/shutingyard.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/monom.ts +36 -1
- package/src/maths/algebra/polynom.ts +63 -50
- package/src/maths/algebra/rational.ts +39 -7
- package/src/maths/expressions/numexp.ts +1 -1
- package/src/maths/shutingyard.ts +1 -0
- package/tests/algebra/rationnal.test.ts +6 -0
- package/tests/numexp.test.ts +8 -0
package/dist/pi.js
CHANGED
|
@@ -1859,7 +1859,7 @@ class Monom {
|
|
|
1859
1859
|
if (this._literal[letter].isNotZero()) {
|
|
1860
1860
|
L += `${letter}`;
|
|
1861
1861
|
if (this._literal[letter].isNotEqual(1)) {
|
|
1862
|
-
L +=
|
|
1862
|
+
L += `^(${this._literal[letter].display})`;
|
|
1863
1863
|
}
|
|
1864
1864
|
}
|
|
1865
1865
|
}
|
|
@@ -1970,6 +1970,41 @@ class Monom {
|
|
|
1970
1970
|
}
|
|
1971
1971
|
return this.tex;
|
|
1972
1972
|
}
|
|
1973
|
+
get plotFunction() {
|
|
1974
|
+
let L = '', letters = Object.keys(this._literal).sort();
|
|
1975
|
+
for (let letter of letters) {
|
|
1976
|
+
if (this._literal[letter].isNotZero()) {
|
|
1977
|
+
L += (L === '' ? "" : "*") + `${letter}`;
|
|
1978
|
+
if (this._literal[letter].isNotEqual(1)) {
|
|
1979
|
+
L += `^(${this._literal[letter].display})`;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
// No literal part
|
|
1984
|
+
if (L === '') {
|
|
1985
|
+
// No setLetter - means it's only a number !
|
|
1986
|
+
if (this._coefficient.value != 0) {
|
|
1987
|
+
return `${this._coefficient.display}`;
|
|
1988
|
+
}
|
|
1989
|
+
else {
|
|
1990
|
+
return '';
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
else {
|
|
1994
|
+
if (this._coefficient.value === 1) {
|
|
1995
|
+
return L;
|
|
1996
|
+
}
|
|
1997
|
+
else if (this._coefficient.value === -1) {
|
|
1998
|
+
return `-${L}`;
|
|
1999
|
+
}
|
|
2000
|
+
else if (this._coefficient.value === 0) {
|
|
2001
|
+
return '0';
|
|
2002
|
+
}
|
|
2003
|
+
else {
|
|
2004
|
+
return `${this._coefficient.display}*${L}`;
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
1973
2008
|
/**
|
|
1974
2009
|
* Get the tex output of the monom
|
|
1975
2010
|
*/
|
|
@@ -2176,6 +2211,8 @@ class Polynom {
|
|
|
2176
2211
|
}
|
|
2177
2212
|
};
|
|
2178
2213
|
// ------------------------------------------
|
|
2214
|
+
// Creation / parsing functions
|
|
2215
|
+
// ------------------------------------------
|
|
2179
2216
|
/**
|
|
2180
2217
|
* Parse a string to a polynom.
|
|
2181
2218
|
* @param inputStr
|
|
@@ -2205,8 +2242,6 @@ class Polynom {
|
|
|
2205
2242
|
}
|
|
2206
2243
|
return this;
|
|
2207
2244
|
};
|
|
2208
|
-
// ------------------------------------------
|
|
2209
|
-
// Creation / parsing functions
|
|
2210
2245
|
/**
|
|
2211
2246
|
* Clone the polynom
|
|
2212
2247
|
*/
|
|
@@ -2245,23 +2280,6 @@ class Polynom {
|
|
|
2245
2280
|
this._monoms = this._monoms.map(m => m.opposed());
|
|
2246
2281
|
return this;
|
|
2247
2282
|
};
|
|
2248
|
-
this.add = (...values) => {
|
|
2249
|
-
for (let value of values) {
|
|
2250
|
-
if (value instanceof Polynom) {
|
|
2251
|
-
this._monoms = this._monoms.concat(value.monoms);
|
|
2252
|
-
}
|
|
2253
|
-
else if (value instanceof monom_1.Monom) {
|
|
2254
|
-
this._monoms.push(value.clone());
|
|
2255
|
-
}
|
|
2256
|
-
else if (Number.isSafeInteger(value)) {
|
|
2257
|
-
this._monoms.push(new monom_1.Monom(value.toString()));
|
|
2258
|
-
}
|
|
2259
|
-
else {
|
|
2260
|
-
this._monoms.push(new monom_1.Monom(value));
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
return this.reduce();
|
|
2264
|
-
};
|
|
2265
2283
|
// // -----------------------------------------------
|
|
2266
2284
|
// // Polynom generators and randomizers
|
|
2267
2285
|
// // -----------------------------------------------
|
|
@@ -2325,6 +2343,23 @@ class Polynom {
|
|
|
2325
2343
|
// };
|
|
2326
2344
|
// ------------------------------------------
|
|
2327
2345
|
// Mathematical operations
|
|
2346
|
+
this.add = (...values) => {
|
|
2347
|
+
for (let value of values) {
|
|
2348
|
+
if (value instanceof Polynom) {
|
|
2349
|
+
this._monoms = this._monoms.concat(value.monoms);
|
|
2350
|
+
}
|
|
2351
|
+
else if (value instanceof monom_1.Monom) {
|
|
2352
|
+
this._monoms.push(value.clone());
|
|
2353
|
+
}
|
|
2354
|
+
else if (Number.isSafeInteger(value)) {
|
|
2355
|
+
this._monoms.push(new monom_1.Monom(value.toString()));
|
|
2356
|
+
}
|
|
2357
|
+
else {
|
|
2358
|
+
this._monoms.push(new monom_1.Monom(value));
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
return this.reduce();
|
|
2362
|
+
};
|
|
2328
2363
|
this.subtract = (...values) => {
|
|
2329
2364
|
for (let value of values) {
|
|
2330
2365
|
if (value instanceof Polynom) {
|
|
@@ -2530,6 +2565,8 @@ class Polynom {
|
|
|
2530
2565
|
// The polyfactors must be empty and the cumulative opposite factors must be 1.
|
|
2531
2566
|
return (polyFactors.length === 0 && sign === 1);
|
|
2532
2567
|
};
|
|
2568
|
+
// ------------------------------------------
|
|
2569
|
+
// Compare functions
|
|
2533
2570
|
this.isDeveloped = (polynomString) => {
|
|
2534
2571
|
let P;
|
|
2535
2572
|
// There is at least one parenthese - it is not developed.
|
|
@@ -2557,8 +2594,6 @@ class Polynom {
|
|
|
2557
2594
|
// TODO: Maybe it's enough to just make this test !
|
|
2558
2595
|
return polynomStringNormalized === P.reduce().reorder().display;
|
|
2559
2596
|
};
|
|
2560
|
-
// ------------------------------------------
|
|
2561
|
-
// Compare functions
|
|
2562
2597
|
// -------------------------------------
|
|
2563
2598
|
this.reduce = () => {
|
|
2564
2599
|
for (let i = 0; i < this._monoms.length; i++) {
|
|
@@ -2644,6 +2679,8 @@ class Polynom {
|
|
|
2644
2679
|
}
|
|
2645
2680
|
return dP;
|
|
2646
2681
|
};
|
|
2682
|
+
// ------------------------------------------
|
|
2683
|
+
// Misc polynoms functions
|
|
2647
2684
|
this.primitive = (letter) => {
|
|
2648
2685
|
let dP = new Polynom();
|
|
2649
2686
|
for (let m of this._monoms) {
|
|
@@ -2651,8 +2688,6 @@ class Polynom {
|
|
|
2651
2688
|
}
|
|
2652
2689
|
return dP;
|
|
2653
2690
|
};
|
|
2654
|
-
// ------------------------------------------
|
|
2655
|
-
// Misc polynoms functions
|
|
2656
2691
|
this.integrate = (a, b, letter) => {
|
|
2657
2692
|
const primitive = this.primitive(letter);
|
|
2658
2693
|
if (letter === undefined) {
|
|
@@ -2718,19 +2753,6 @@ class Polynom {
|
|
|
2718
2753
|
this.factors = factors;
|
|
2719
2754
|
return factors;
|
|
2720
2755
|
};
|
|
2721
|
-
this._getAllPotentialFactors = (P, letter) => {
|
|
2722
|
-
let m1 = P.monoms[0].dividers, m2 = P.monoms[P.monoms.length - 1].dividers;
|
|
2723
|
-
let allDividers = [];
|
|
2724
|
-
m1.forEach(m1d => {
|
|
2725
|
-
m2.forEach(m2d => {
|
|
2726
|
-
if (m1d.degree(letter).isNotEqual(m2d.degree(letter))) {
|
|
2727
|
-
allDividers.push(new Polynom(m1d, m2d));
|
|
2728
|
-
allDividers.push(new Polynom(m1d, m2d.clone().opposed()));
|
|
2729
|
-
}
|
|
2730
|
-
});
|
|
2731
|
-
});
|
|
2732
|
-
return allDividers;
|
|
2733
|
-
};
|
|
2734
2756
|
// TODO: get zeroes for more than first degree and for more than natural degrees
|
|
2735
2757
|
this.getZeroes = () => {
|
|
2736
2758
|
let equ = new equation_1.Equation(this.clone(), 0);
|
|
@@ -2936,13 +2958,34 @@ class Polynom {
|
|
|
2936
2958
|
// Any other cases
|
|
2937
2959
|
return (new fraction_1.Fraction()).zero();
|
|
2938
2960
|
};
|
|
2939
|
-
this.
|
|
2961
|
+
this._getAllPotentialFactors = (P, letter) => {
|
|
2962
|
+
let m1 = P.monoms[0].dividers, m2 = P.monoms[P.monoms.length - 1].dividers;
|
|
2963
|
+
let allDividers = [];
|
|
2964
|
+
m1.forEach(m1d => {
|
|
2965
|
+
m2.forEach(m2d => {
|
|
2966
|
+
if (m1d.degree(letter).isNotEqual(m2d.degree(letter))) {
|
|
2967
|
+
allDividers.push(new Polynom(m1d, m2d));
|
|
2968
|
+
allDividers.push(new Polynom(m1d, m2d.clone().opposed()));
|
|
2969
|
+
}
|
|
2970
|
+
});
|
|
2971
|
+
});
|
|
2972
|
+
return allDividers;
|
|
2973
|
+
};
|
|
2974
|
+
this.genDisplay = (output, forceSign, wrapParentheses, withAllMultSign) => {
|
|
2940
2975
|
let P = '';
|
|
2941
2976
|
for (const k of this._monoms) {
|
|
2942
2977
|
if (k.coefficient.value === 0) {
|
|
2943
2978
|
continue;
|
|
2944
2979
|
}
|
|
2945
|
-
|
|
2980
|
+
// The monom to be displayed
|
|
2981
|
+
let m;
|
|
2982
|
+
if (withAllMultSign) {
|
|
2983
|
+
m = k.plotFunction;
|
|
2984
|
+
}
|
|
2985
|
+
else {
|
|
2986
|
+
m = (output === 'tex') ? k.tex : k.display;
|
|
2987
|
+
}
|
|
2988
|
+
P += `${(k.coefficient.sign() === 1 && (P !== '' || forceSign === true)) ? '+' : ''}${m}`;
|
|
2946
2989
|
}
|
|
2947
2990
|
if (wrapParentheses === true && this.length > 1) {
|
|
2948
2991
|
if (output === 'tex') {
|
|
@@ -3241,6 +3284,9 @@ class Polynom {
|
|
|
3241
3284
|
get numberOfVars() {
|
|
3242
3285
|
return this.variables.length;
|
|
3243
3286
|
}
|
|
3287
|
+
get plotFunction() {
|
|
3288
|
+
return this.genDisplay('tex', false, false, true);
|
|
3289
|
+
}
|
|
3244
3290
|
isZero() {
|
|
3245
3291
|
return (this._monoms.length === 1 && this._monoms[0].coefficient.isZero()) || this._monoms.length === 0;
|
|
3246
3292
|
}
|
|
@@ -3438,7 +3484,7 @@ class Rational {
|
|
|
3438
3484
|
// Factorize the numerator and the denominator
|
|
3439
3485
|
this._numerator.factorize();
|
|
3440
3486
|
this._denominator.factorize();
|
|
3441
|
-
let zeroes = equation_1.Equation.makeSolutionsUnique([...this._numerator.getZeroes(), ...this._denominator.getZeroes()], true), NFactors = this._numerator.factors, DFactors = this._denominator.factors;
|
|
3487
|
+
let zeroes = equation_1.Equation.makeSolutionsUnique([...this._numerator.getZeroes(), ...this._denominator.getZeroes()], true).filter(x => !isNaN(x.value)), NFactors = this._numerator.factors, DFactors = this._denominator.factors;
|
|
3442
3488
|
let tableOfSigns = [], result = [];
|
|
3443
3489
|
NFactors.forEach(factor => {
|
|
3444
3490
|
tableOfSigns.push(this._makeOneLineOfTableOfSigns(factor, zeroes, 'z'));
|
|
@@ -3506,7 +3552,12 @@ class Rational {
|
|
|
3506
3552
|
let oneLine = [], currentZero = factor.getZeroes().map(x => x.tex);
|
|
3507
3553
|
// First +/- sign, before the first zero
|
|
3508
3554
|
oneLine.push('');
|
|
3509
|
-
|
|
3555
|
+
if (factor.degree().isZero()) {
|
|
3556
|
+
oneLine.push(factor.monoms[0].coefficient.sign() === 1 ? '+' : '-');
|
|
3557
|
+
}
|
|
3558
|
+
else {
|
|
3559
|
+
oneLine.push(factor.evaluate(zeroes[0].value - 1).sign() === 1 ? '+' : '-');
|
|
3560
|
+
}
|
|
3510
3561
|
for (let i = 0; i < zeroes.length; i++) {
|
|
3511
3562
|
// Add the zero if it's the current one
|
|
3512
3563
|
oneLine.push(currentZero.includes(zeroes[i].tex) ? zeroSign : 't');
|
|
@@ -3521,8 +3572,29 @@ class Rational {
|
|
|
3521
3572
|
oneLine.push('');
|
|
3522
3573
|
return oneLine;
|
|
3523
3574
|
};
|
|
3524
|
-
this.
|
|
3525
|
-
|
|
3575
|
+
this.evaluate = (values) => {
|
|
3576
|
+
const r = new fraction_1.Fraction().zero();
|
|
3577
|
+
let N = this._numerator.evaluate(values), D = this._numerator.evaluate(values);
|
|
3578
|
+
return N.divide(D);
|
|
3579
|
+
};
|
|
3580
|
+
if (numerator instanceof polynom_1.Polynom) {
|
|
3581
|
+
this._numerator = numerator.clone();
|
|
3582
|
+
}
|
|
3583
|
+
else if (typeof numerator === 'string') {
|
|
3584
|
+
this._numerator = new polynom_1.Polynom(numerator);
|
|
3585
|
+
}
|
|
3586
|
+
else {
|
|
3587
|
+
this._numerator = new polynom_1.Polynom();
|
|
3588
|
+
}
|
|
3589
|
+
if (denominator instanceof polynom_1.Polynom) {
|
|
3590
|
+
this._denominator = denominator.clone();
|
|
3591
|
+
}
|
|
3592
|
+
else if (typeof denominator === 'string') {
|
|
3593
|
+
this._denominator = new polynom_1.Polynom(denominator);
|
|
3594
|
+
}
|
|
3595
|
+
else {
|
|
3596
|
+
this._denominator = new polynom_1.Polynom();
|
|
3597
|
+
}
|
|
3526
3598
|
}
|
|
3527
3599
|
get numerator() {
|
|
3528
3600
|
return this._numerator;
|
|
@@ -3536,6 +3608,9 @@ class Rational {
|
|
|
3536
3608
|
get texFactors() {
|
|
3537
3609
|
return `\\frac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
|
|
3538
3610
|
}
|
|
3611
|
+
get plotFunction() {
|
|
3612
|
+
return `(${this._numerator.plotFunction})/(${this._denominator.plotFunction})`;
|
|
3613
|
+
}
|
|
3539
3614
|
}
|
|
3540
3615
|
exports.Rational = Rational;
|
|
3541
3616
|
|
|
@@ -4161,7 +4236,7 @@ exports.NumExp = void 0;
|
|
|
4161
4236
|
const shutingyard_1 = __webpack_require__(505);
|
|
4162
4237
|
const fraction_1 = __webpack_require__(506);
|
|
4163
4238
|
class NumExp {
|
|
4164
|
-
constructor(value) {
|
|
4239
|
+
constructor(value, uniformize) {
|
|
4165
4240
|
this._expression = value;
|
|
4166
4241
|
this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
|
|
4167
4242
|
}
|