pimath 0.0.73 → 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 +112 -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/numexp.js +10 -0
- package/esm/maths/expressions/numexp.js.map +1 -1
- package/esm/maths/shutingyard.js +3 -0
- package/esm/maths/shutingyard.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/numexp.ts +7 -0
- package/src/maths/shutingyard.ts +3 -0
- package/tests/algebra/polynom.test.ts +12 -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;
|
|
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()) {
|
|
@@ -4744,6 +4770,16 @@ class NumExp {
|
|
|
4744
4770
|
else if (element.token === 'sqrt') {
|
|
4745
4771
|
this._addToStack(stack, Math.sqrt(a));
|
|
4746
4772
|
}
|
|
4773
|
+
else if (element.token === 'nthrt') {
|
|
4774
|
+
// TODO: support nthrt in num. exp.
|
|
4775
|
+
// this._addToStack(stack, Math.pow(a, 1/b))
|
|
4776
|
+
}
|
|
4777
|
+
else if (element.token === 'ln') {
|
|
4778
|
+
this._addToStack(stack, Math.log(a));
|
|
4779
|
+
}
|
|
4780
|
+
else if (element.token === 'log') {
|
|
4781
|
+
this._addToStack(stack, Math.log10(a));
|
|
4782
|
+
}
|
|
4747
4783
|
}
|
|
4748
4784
|
}
|
|
4749
4785
|
if (stack.length === 1) {
|
|
@@ -6937,6 +6973,9 @@ class Shutingyard {
|
|
|
6937
6973
|
'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
6938
6974
|
'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
6939
6975
|
'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
6976
|
+
'nthrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
6977
|
+
'ln': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
6978
|
+
'log': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
|
|
6940
6979
|
};
|
|
6941
6980
|
this._uniformize = false;
|
|
6942
6981
|
}
|