pimath 0.0.75 → 0.0.76
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 +81 -82
- 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 +81 -82
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/polynom.ts +98 -92
- package/tests/algebra/polynom.test.ts +6 -2
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;
|
|
2752
2719
|
}
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
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
|
+
}
|
|
2753
|
+
}
|
|
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());
|
|
2757
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) => {
|
|
@@ -3142,7 +3147,6 @@ class Polynom {
|
|
|
3142
3147
|
if (this.factors.length <= 1) {
|
|
3143
3148
|
return this.tex;
|
|
3144
3149
|
}
|
|
3145
|
-
let tex = '';
|
|
3146
3150
|
// Build an array of texFactors with the number of similar items.
|
|
3147
3151
|
let factorsCount = {};
|
|
3148
3152
|
for (let f of this.factors) {
|
|
@@ -3156,23 +3160,18 @@ class Polynom {
|
|
|
3156
3160
|
};
|
|
3157
3161
|
}
|
|
3158
3162
|
}
|
|
3159
|
-
|
|
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)) {
|
|
3160
3171
|
if (item.factor.length > 1) {
|
|
3161
3172
|
tex += `\\left( ${item.factor.tex} \\right)${item.degree > 1 ? '^{ ' + item.degree + ' }' : ''}`;
|
|
3162
3173
|
}
|
|
3163
|
-
else {
|
|
3164
|
-
tex += item.degree === 1 ? item.factor.tex : `\\left( ${item.factor} \\right^{ ${item.degree} }`;
|
|
3165
|
-
}
|
|
3166
3174
|
}
|
|
3167
|
-
//
|
|
3168
|
-
// // Actual system
|
|
3169
|
-
// for (let f of this.factors) {
|
|
3170
|
-
// if (f.monoms.length > 1) {
|
|
3171
|
-
// tex += `(${f.tex})`
|
|
3172
|
-
// } else {
|
|
3173
|
-
// tex = f.tex + tex;
|
|
3174
|
-
// }
|
|
3175
|
-
// }
|
|
3176
3175
|
return tex;
|
|
3177
3176
|
}
|
|
3178
3177
|
get length() {
|