pimath 0.0.75 → 0.0.78
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 +137 -84
- 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/esm/maths/coefficients/fraction.js +3 -1
- package/esm/maths/coefficients/fraction.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 +2 -0
- package/esm/maths/numeric.js +52 -0
- package/esm/maths/numeric.js.map +1 -1
- package/esm/maths/randomization/random.d.ts +1 -1
- package/esm/maths/randomization/random.js +1 -1
- package/esm/maths/randomization/random.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/polynom.ts +98 -92
- package/src/maths/coefficients/fraction.ts +6 -2
- package/src/maths/expressions/ExpressionTree.ts +172 -0
- package/src/maths/numeric.ts +67 -0
- package/src/maths/randomization/random.ts +2 -2
- package/tests/algebra/polynom.test.ts +6 -2
- package/tests/coefficients/fraction.test.ts +11 -3
- 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) => {
|
|
@@ -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() {
|
|
@@ -4064,7 +4063,9 @@ class Fraction {
|
|
|
4064
4063
|
else {
|
|
4065
4064
|
// The given value is a float number
|
|
4066
4065
|
// Get the number of decimals after the float sign
|
|
4067
|
-
let
|
|
4066
|
+
let [unit, decimal] = (value.toString()).split('.');
|
|
4067
|
+
let p = decimal.length;
|
|
4068
|
+
// Detect if the decimal part is periodic or not...
|
|
4068
4069
|
// Transform the float number in two integer
|
|
4069
4070
|
if (denominatorOrPeriodic === undefined) {
|
|
4070
4071
|
this._numerator = value * Math.pow(10, p);
|
|
@@ -6524,6 +6525,58 @@ class Numeric {
|
|
|
6524
6525
|
}
|
|
6525
6526
|
return triplets;
|
|
6526
6527
|
}
|
|
6528
|
+
static numberCorrection(value) {
|
|
6529
|
+
// Must modify the number if it's like:
|
|
6530
|
+
// a: 3.0000000000000003
|
|
6531
|
+
// b: 3.9999999999999994
|
|
6532
|
+
// remove the last character
|
|
6533
|
+
// check if around n last characters are either 0 or 9
|
|
6534
|
+
// if it is, 'round' the number.
|
|
6535
|
+
function extractDecimalPart(valueToExtract) {
|
|
6536
|
+
let decimal = valueToExtract.toString();
|
|
6537
|
+
if (!decimal.includes('.')) {
|
|
6538
|
+
return '';
|
|
6539
|
+
}
|
|
6540
|
+
decimal = decimal.split('.')[1];
|
|
6541
|
+
return decimal.substring(0, decimal.length - 2);
|
|
6542
|
+
}
|
|
6543
|
+
const epsilon = 0.00000000000001, number_of_digits = 6;
|
|
6544
|
+
const decimal = extractDecimalPart(value);
|
|
6545
|
+
if (decimal === '') {
|
|
6546
|
+
return value;
|
|
6547
|
+
}
|
|
6548
|
+
const n9 = decimal.match(/9+$/g);
|
|
6549
|
+
const n0 = decimal.match(/0+$/g);
|
|
6550
|
+
if (n9 && n9[0].length >= number_of_digits) {
|
|
6551
|
+
// New tested values.
|
|
6552
|
+
const mod = extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
|
|
6553
|
+
if (mod0 && mod0[0].length >= number_of_digits) {
|
|
6554
|
+
// The value can be changed. Remove all zeros!
|
|
6555
|
+
return +((value + epsilon).toString().split(mod0[0])[0]);
|
|
6556
|
+
}
|
|
6557
|
+
}
|
|
6558
|
+
if (n0 && n0[0].length >= number_of_digits) {
|
|
6559
|
+
// New tested values.
|
|
6560
|
+
const mod = extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
|
|
6561
|
+
if (mod9 && mod9[0].length >= number_of_digits) {
|
|
6562
|
+
// The value can be changed. Remove all nines!
|
|
6563
|
+
return +(value.toString().split(n0[0])[0]);
|
|
6564
|
+
}
|
|
6565
|
+
}
|
|
6566
|
+
return value;
|
|
6567
|
+
}
|
|
6568
|
+
static periodic(value) {
|
|
6569
|
+
if (Number.isSafeInteger(value)) {
|
|
6570
|
+
return 0;
|
|
6571
|
+
}
|
|
6572
|
+
// Assume it's with decimal.
|
|
6573
|
+
let decimal = (value.toString()).split('.')[0];
|
|
6574
|
+
// The decimal part is limited
|
|
6575
|
+
if (decimal.length < 10) {
|
|
6576
|
+
return 0;
|
|
6577
|
+
}
|
|
6578
|
+
// Find the periodic if it exists.
|
|
6579
|
+
}
|
|
6527
6580
|
}
|
|
6528
6581
|
exports.Numeric = Numeric;
|
|
6529
6582
|
|
|
@@ -6590,7 +6643,7 @@ var Random;
|
|
|
6590
6643
|
}
|
|
6591
6644
|
Random.item = item;
|
|
6592
6645
|
function shuffle(arr) {
|
|
6593
|
-
rndHelpers_1.rndHelpers.shuffleArray(arr);
|
|
6646
|
+
return rndHelpers_1.rndHelpers.shuffleArray(arr);
|
|
6594
6647
|
}
|
|
6595
6648
|
Random.shuffle = shuffle;
|
|
6596
6649
|
})(Random = exports.Random || (exports.Random = {}));
|