pimath 0.0.74 → 0.0.77
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 +139 -73
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/docs/assets/highlight.css +78 -78
- package/docs/assets/main.js +52 -52
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1413 -1413
- package/docs/classes/Logicalset.Logicalset-1.html +5 -5
- package/docs/classes/Polynom.Rational.html +4 -4
- package/docs/classes/Vector.Point.html +1 -1
- package/docs/classes/Vector.Vector-1.html +1 -1
- package/docs/classes/algebra_equation.Equation.html +26 -26
- package/docs/classes/algebra_linearSystem.LinearSystem.html +1 -1
- package/docs/classes/algebra_monom.Monom.html +114 -114
- package/docs/classes/algebra_polynom.Polynom.html +30 -30
- package/docs/classes/coefficients_fraction.Fraction.html +19 -19
- package/docs/classes/coefficients_nthroot.NthRoot.html +3 -3
- package/docs/classes/expressions_numexp.NumExp.html +1 -1
- package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +1 -1
- package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +1 -1
- package/docs/classes/geometry_circle.Circle.html +3 -3
- package/docs/classes/geometry_line.Line.html +3 -3
- package/docs/classes/geometry_triangle.Triangle.html +16 -16
- package/docs/classes/numeric.Numeric.html +14 -14
- package/docs/classes/shutingyard.Shutingyard.html +18 -18
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +1 -1
- package/docs/enums/geometry_line.LinePropriety.html +1 -1
- package/docs/enums/shutingyard.ShutingyardMode.html +1 -1
- package/docs/enums/shutingyard.ShutingyardType.html +1 -1
- package/docs/index.html +10 -10
- package/docs/interfaces/algebra_equation.ISolution.html +3 -3
- package/docs/interfaces/algebra_polynom.IEuclidian.html +1 -0
- package/docs/interfaces/geometry_triangle.remarquableLines.html +1 -1
- package/docs/modules/Logicalset.html +2 -2
- package/docs/modules/Polynom.html +2 -2
- package/docs/modules/Vector.html +2 -2
- package/docs/modules/algebra_monom.html +1 -1
- package/docs/modules/algebra_polynom.html +1 -1
- package/docs/modules/coefficients_fraction.html +1 -1
- package/docs/modules/shutingyard.html +1 -1
- package/esm/maths/algebra/polynom.js +94 -73
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +1 -0
- package/esm/maths/algebra/rational.js +5 -0
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/expressions/ExpressionTree.d.ts +17 -0
- package/esm/maths/expressions/ExpressionTree.js +150 -0
- package/esm/maths/expressions/ExpressionTree.js.map +1 -0
- package/esm/maths/numeric.d.ts +1 -0
- package/esm/maths/numeric.js +40 -0
- package/esm/maths/numeric.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/polynom.ts +107 -78
- package/src/maths/algebra/rational.ts +6 -0
- package/src/maths/expressions/ExpressionTree.ts +172 -0
- package/src/maths/numeric.ts +55 -0
- package/tests/algebra/polynom.test.ts +12 -2
- package/tests/expressions/expressiontree.test.ts +11 -0
- package/tests/numexp.test.ts +5 -4
package/dist/pi.js
CHANGED
|
@@ -2680,81 +2680,86 @@ class Polynom {
|
|
|
2680
2680
|
* @param maxValue Defines the greatest value to search to (default is 20).
|
|
2681
2681
|
*/
|
|
2682
2682
|
this.factorize = (letter) => {
|
|
2683
|
-
if (this.dirty_factors) {
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
// The polynom is a first degree polynom => 3x-5
|
|
2709
|
-
// No need to continue
|
|
2683
|
+
if (!this.dirty_factors) {
|
|
2684
|
+
return this._factors;
|
|
2685
|
+
}
|
|
2686
|
+
let factors = [];
|
|
2687
|
+
let P = this.clone().reorder();
|
|
2688
|
+
// Extract the common monom
|
|
2689
|
+
// 2x^3+6x^2 => 2x^2
|
|
2690
|
+
let M = P.commonMonom();
|
|
2691
|
+
// If the polynom starts with a negative monom, factorize it.
|
|
2692
|
+
if (P.monomByDegree().coefficient.isStrictlyNegative() && M.coefficient.isStrictlyPositive()) {
|
|
2693
|
+
M.opposed();
|
|
2694
|
+
}
|
|
2695
|
+
if (!M.isOne()) {
|
|
2696
|
+
let tempPolynom = new Polynom(M);
|
|
2697
|
+
factors = [tempPolynom.clone()];
|
|
2698
|
+
P = P.euclidian(tempPolynom).quotient;
|
|
2699
|
+
}
|
|
2700
|
+
// Main loop
|
|
2701
|
+
let securityLoop = P.degree().clone().multiply(2).value, maxDegree = 1;
|
|
2702
|
+
while (securityLoop >= 0) {
|
|
2703
|
+
securityLoop--;
|
|
2704
|
+
if (P.monoms.length < 2) {
|
|
2705
|
+
// The polynom has only one monom => 7x^2
|
|
2706
|
+
// No need to continue.
|
|
2707
|
+
if (!P.isOne()) {
|
|
2710
2708
|
factors.push(P.clone());
|
|
2711
2709
|
P.one();
|
|
2712
|
-
break;
|
|
2713
|
-
}
|
|
2714
|
-
else {
|
|
2715
|
-
// Create the list of all "potential" polynom dividers.
|
|
2716
|
-
let allDividers = this._getAllPotentialFactors(P, maxDegree, letter);
|
|
2717
|
-
maxDegree = P.degree(letter).value;
|
|
2718
|
-
// Actually: 100ms
|
|
2719
|
-
while (allDividers.length > 0) {
|
|
2720
|
-
let div = allDividers[0];
|
|
2721
|
-
if (!P.isDividableBy(div)) {
|
|
2722
|
-
// Not dividable. Remove it from the list
|
|
2723
|
-
allDividers.shift();
|
|
2724
|
-
}
|
|
2725
|
-
else {
|
|
2726
|
-
// It's dividable - so make the division
|
|
2727
|
-
let result = P.euclidian(div);
|
|
2728
|
-
// Add the factor
|
|
2729
|
-
factors.push(div);
|
|
2730
|
-
// As it's dividable, get the quotient.
|
|
2731
|
-
P = result.quotient.clone();
|
|
2732
|
-
// filter all dividers that are no more suitable.
|
|
2733
|
-
allDividers = allDividers.filter(x => {
|
|
2734
|
-
let pX = P.monoms[0], pC = P.monoms[P.monoms.length - 1], dX = x.monoms[0], dC = x.monoms[x.monoms.length - 1];
|
|
2735
|
-
// Check last item (degree zero)
|
|
2736
|
-
if (!pC.isDivisible(dC)) {
|
|
2737
|
-
return false;
|
|
2738
|
-
}
|
|
2739
|
-
// Check the first item (degree max)
|
|
2740
|
-
if (!pX.isDivisible(dX)) {
|
|
2741
|
-
return false;
|
|
2742
|
-
}
|
|
2743
|
-
return true;
|
|
2744
|
-
});
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
2710
|
}
|
|
2711
|
+
break;
|
|
2748
2712
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2713
|
+
else if (P.degree(letter).isOne()) {
|
|
2714
|
+
// The polynom is a first degree polynom => 3x-5
|
|
2715
|
+
// No need to continue
|
|
2751
2716
|
factors.push(P.clone());
|
|
2717
|
+
P.one();
|
|
2718
|
+
break;
|
|
2719
|
+
}
|
|
2720
|
+
else {
|
|
2721
|
+
// Create the list of all "potential" polynom dividers.
|
|
2722
|
+
let allDividers = this._getAllPotentialFactors(P, maxDegree, letter);
|
|
2723
|
+
maxDegree = P.degree(letter).value;
|
|
2724
|
+
// Actually: 100ms
|
|
2725
|
+
while (allDividers.length > 0) {
|
|
2726
|
+
let div = allDividers[0];
|
|
2727
|
+
if (!P.isDividableBy(div)) {
|
|
2728
|
+
// Not dividable. Remove it from the list
|
|
2729
|
+
allDividers.shift();
|
|
2730
|
+
}
|
|
2731
|
+
else {
|
|
2732
|
+
// It's dividable - so make the division
|
|
2733
|
+
let result = P.euclidian(div);
|
|
2734
|
+
// Add the factor
|
|
2735
|
+
factors.push(div);
|
|
2736
|
+
// As it's dividable, get the quotient.
|
|
2737
|
+
P = result.quotient.clone();
|
|
2738
|
+
// filter all dividers that are no more suitable.
|
|
2739
|
+
allDividers = allDividers.filter(x => {
|
|
2740
|
+
let pX = P.monoms[0], pC = P.monoms[P.monoms.length - 1], dX = x.monoms[0], dC = x.monoms[x.monoms.length - 1];
|
|
2741
|
+
// Check last item (degree zero)
|
|
2742
|
+
if (!pC.isDivisible(dC)) {
|
|
2743
|
+
return false;
|
|
2744
|
+
}
|
|
2745
|
+
// Check the first item (degree max)
|
|
2746
|
+
if (!pX.isDivisible(dX)) {
|
|
2747
|
+
return false;
|
|
2748
|
+
}
|
|
2749
|
+
return true;
|
|
2750
|
+
});
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2752
2753
|
}
|
|
2753
|
-
// Save the factors
|
|
2754
|
-
this._factors = factors;
|
|
2755
|
-
// The factors list is no more dirty
|
|
2756
|
-
this.dirty_factors = false;
|
|
2757
2754
|
}
|
|
2755
|
+
// Maybe there is still something in the Polynom (not everything was possible to factorize)
|
|
2756
|
+
if (!P.isOne()) {
|
|
2757
|
+
factors.push(P.clone());
|
|
2758
|
+
}
|
|
2759
|
+
// Save the factors
|
|
2760
|
+
this._factors = factors;
|
|
2761
|
+
// The factors list is no more dirty
|
|
2762
|
+
this.dirty_factors = false;
|
|
2758
2763
|
return this._factors;
|
|
2759
2764
|
};
|
|
2760
2765
|
this.isDividableBy = (div) => {
|
|
@@ -3139,16 +3144,32 @@ class Polynom {
|
|
|
3139
3144
|
}
|
|
3140
3145
|
get texFactors() {
|
|
3141
3146
|
this.factorize();
|
|
3142
|
-
if (this.factors.length
|
|
3147
|
+
if (this.factors.length <= 1) {
|
|
3143
3148
|
return this.tex;
|
|
3144
3149
|
}
|
|
3145
|
-
|
|
3150
|
+
// Build an array of texFactors with the number of similar items.
|
|
3151
|
+
let factorsCount = {};
|
|
3146
3152
|
for (let f of this.factors) {
|
|
3147
|
-
if (f.
|
|
3148
|
-
|
|
3153
|
+
if (factorsCount[f.tex] !== undefined) {
|
|
3154
|
+
factorsCount[f.tex].degree++;
|
|
3149
3155
|
}
|
|
3150
3156
|
else {
|
|
3151
|
-
|
|
3157
|
+
factorsCount[f.tex] = {
|
|
3158
|
+
degree: 1,
|
|
3159
|
+
factor: f
|
|
3160
|
+
};
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
// First round to put the 'monom' first
|
|
3164
|
+
let simpleFactor = new Polynom().one();
|
|
3165
|
+
for (let item of Object.values(factorsCount).filter(item => item.factor.monoms.length === 1)) {
|
|
3166
|
+
simpleFactor.multiply(item.factor);
|
|
3167
|
+
}
|
|
3168
|
+
let tex = simpleFactor.isOne() ? '' : simpleFactor.tex;
|
|
3169
|
+
// Loop through all factors that contains at least 2 monoms.
|
|
3170
|
+
for (let item of Object.values(factorsCount).filter(item => item.factor.monoms.length > 1)) {
|
|
3171
|
+
if (item.factor.length > 1) {
|
|
3172
|
+
tex += `\\left( ${item.factor.tex} \\right)${item.degree > 1 ? '^{ ' + item.degree + ' }' : ''}`;
|
|
3152
3173
|
}
|
|
3153
3174
|
}
|
|
3154
3175
|
return tex;
|
|
@@ -3303,6 +3324,11 @@ class Rational {
|
|
|
3303
3324
|
this._denominator = D.clone().pow(2);
|
|
3304
3325
|
return this;
|
|
3305
3326
|
};
|
|
3327
|
+
this.factorize = (letter) => {
|
|
3328
|
+
this._numerator.factorize(letter);
|
|
3329
|
+
this._denominator.factorize(letter);
|
|
3330
|
+
return this;
|
|
3331
|
+
};
|
|
3306
3332
|
this.simplify = (P) => {
|
|
3307
3333
|
let NumeratorEuclidien = this._numerator.euclidian(P);
|
|
3308
3334
|
if (!NumeratorEuclidien.reminder.isZero()) {
|
|
@@ -6497,6 +6523,46 @@ class Numeric {
|
|
|
6497
6523
|
}
|
|
6498
6524
|
return triplets;
|
|
6499
6525
|
}
|
|
6526
|
+
static numberCorrection(value) {
|
|
6527
|
+
// Must modify the number if it's like:
|
|
6528
|
+
// a: 3.0000000000000003
|
|
6529
|
+
// b: 3.9999999999999994
|
|
6530
|
+
// remove the last character
|
|
6531
|
+
// check if around n last characters are either 0 or 9
|
|
6532
|
+
// if it is, 'round' the number.
|
|
6533
|
+
function extractDecimalPart(valueToExtract) {
|
|
6534
|
+
let decimal = valueToExtract.toString();
|
|
6535
|
+
if (!decimal.includes('.')) {
|
|
6536
|
+
return '';
|
|
6537
|
+
}
|
|
6538
|
+
decimal = decimal.split('.')[1];
|
|
6539
|
+
return decimal.substring(0, decimal.length - 2);
|
|
6540
|
+
}
|
|
6541
|
+
const epsilon = 0.00000000000001, number_of_digits = 6;
|
|
6542
|
+
const decimal = extractDecimalPart(value);
|
|
6543
|
+
if (decimal === '') {
|
|
6544
|
+
return value;
|
|
6545
|
+
}
|
|
6546
|
+
const n9 = decimal.match(/9+$/g);
|
|
6547
|
+
const n0 = decimal.match(/0+$/g);
|
|
6548
|
+
if (n9 && n9[0].length >= number_of_digits) {
|
|
6549
|
+
// New tested values.
|
|
6550
|
+
const mod = extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
|
|
6551
|
+
if (mod0 && mod0[0].length >= number_of_digits) {
|
|
6552
|
+
// The value can be changed. Remove all zeros!
|
|
6553
|
+
return +((value + epsilon).toString().split(mod0[0])[0]);
|
|
6554
|
+
}
|
|
6555
|
+
}
|
|
6556
|
+
if (n0 && n0[0].length >= number_of_digits) {
|
|
6557
|
+
// New tested values.
|
|
6558
|
+
const mod = extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
|
|
6559
|
+
if (mod9 && mod9[0].length >= number_of_digits) {
|
|
6560
|
+
// The value can be changed. Remove all nines!
|
|
6561
|
+
return +(value.toString().split(n0[0])[0]);
|
|
6562
|
+
}
|
|
6563
|
+
}
|
|
6564
|
+
return value;
|
|
6565
|
+
}
|
|
6500
6566
|
}
|
|
6501
6567
|
exports.Numeric = Numeric;
|
|
6502
6568
|
|