pimath 0.0.57 → 0.0.60
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 +96 -42
- 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 +3 -0
- package/esm/maths/algebra/rational.js +10 -2
- 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 +16 -2
- package/src/maths/expressions/numexp.ts +1 -1
- package/src/maths/shutingyard.ts +1 -0
- package/tests/algebra/rationnal.test.ts +3 -3
- 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
|
}
|
|
@@ -3334,10 +3380,10 @@ class Rational {
|
|
|
3334
3380
|
this.domain = () => {
|
|
3335
3381
|
let zeroes = this._denominator.getZeroes();
|
|
3336
3382
|
if (zeroes.length === 0 || zeroes[0].tex === equation_1.PARTICULAR_SOLUTION.real) {
|
|
3337
|
-
return equation_1.PARTICULAR_SOLUTION.
|
|
3383
|
+
return equation_1.PARTICULAR_SOLUTION.varnothing;
|
|
3338
3384
|
}
|
|
3339
3385
|
else if (zeroes[0].tex === equation_1.PARTICULAR_SOLUTION.varnothing) {
|
|
3340
|
-
return equation_1.PARTICULAR_SOLUTION.
|
|
3386
|
+
return equation_1.PARTICULAR_SOLUTION.real;
|
|
3341
3387
|
}
|
|
3342
3388
|
else {
|
|
3343
3389
|
return '\\mathbb{R}\\setminus\\left\\{' +
|
|
@@ -3526,6 +3572,11 @@ class Rational {
|
|
|
3526
3572
|
oneLine.push('');
|
|
3527
3573
|
return oneLine;
|
|
3528
3574
|
};
|
|
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
|
+
};
|
|
3529
3580
|
if (numerator instanceof polynom_1.Polynom) {
|
|
3530
3581
|
this._numerator = numerator.clone();
|
|
3531
3582
|
}
|
|
@@ -3557,6 +3608,9 @@ class Rational {
|
|
|
3557
3608
|
get texFactors() {
|
|
3558
3609
|
return `\\frac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
|
|
3559
3610
|
}
|
|
3611
|
+
get plotFunction() {
|
|
3612
|
+
return `(${this._numerator.plotFunction})/(${this._denominator.plotFunction})`;
|
|
3613
|
+
}
|
|
3560
3614
|
}
|
|
3561
3615
|
exports.Rational = Rational;
|
|
3562
3616
|
|
|
@@ -4182,7 +4236,7 @@ exports.NumExp = void 0;
|
|
|
4182
4236
|
const shutingyard_1 = __webpack_require__(505);
|
|
4183
4237
|
const fraction_1 = __webpack_require__(506);
|
|
4184
4238
|
class NumExp {
|
|
4185
|
-
constructor(value) {
|
|
4239
|
+
constructor(value, uniformize) {
|
|
4186
4240
|
this._expression = value;
|
|
4187
4241
|
this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
|
|
4188
4242
|
}
|