pimath 0.0.104 → 0.0.105
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 +42 -6
- 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/polynom.d.ts +1 -1
- package/esm/maths/algebra/polynom.js +42 -6
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/package.json +1 -1
- package/src/maths/algebra/polynom.ts +79 -33
- package/tests/algebra/polynom.test.ts +25 -6
- package/dev/pi.js +0 -7866
- package/dev/pi.js.map +0 -1
package/dist/pi.js
CHANGED
|
@@ -2495,10 +2495,23 @@ class Polynom {
|
|
|
2495
2495
|
else if (typeof value === 'number' && Number.isSafeInteger(value)) {
|
|
2496
2496
|
return this.divideByInteger(value);
|
|
2497
2497
|
}
|
|
2498
|
+
else if (value instanceof monom_1.Monom) {
|
|
2499
|
+
return this.divide(new Polynom(value));
|
|
2500
|
+
}
|
|
2498
2501
|
else if (value instanceof Polynom) {
|
|
2499
2502
|
if (value.monoms.length === 1 && value.variables.length === 0) {
|
|
2500
2503
|
return this.divideByFraction(value.monoms[0].coefficient);
|
|
2501
2504
|
}
|
|
2505
|
+
else {
|
|
2506
|
+
let { quotient, reminder } = this.euclidian(value);
|
|
2507
|
+
if (reminder.isZero()) {
|
|
2508
|
+
return quotient;
|
|
2509
|
+
}
|
|
2510
|
+
else {
|
|
2511
|
+
console.log(`${this.tex} is not divideable by ${value.tex}`);
|
|
2512
|
+
return new Polynom().zero();
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2502
2515
|
}
|
|
2503
2516
|
};
|
|
2504
2517
|
this.pow = (nb) => {
|
|
@@ -2568,7 +2581,7 @@ class Polynom {
|
|
|
2568
2581
|
this.isOpposedAt = (P) => {
|
|
2569
2582
|
return this.compare(P.clone().opposed(), '=');
|
|
2570
2583
|
};
|
|
2571
|
-
this.isFactorized = (polynomString) => {
|
|
2584
|
+
this.isFactorized = (polynomString, soft) => {
|
|
2572
2585
|
let P;
|
|
2573
2586
|
// Check if polynom is complete...
|
|
2574
2587
|
if (polynomString.split('(').length !== polynomString.split(')').length) {
|
|
@@ -2590,44 +2603,67 @@ class Polynom {
|
|
|
2590
2603
|
let polynomStringNormalized = polynomString.replaceAll('*', ''), polynomStringReduced = '' + polynomStringNormalized, factors = [];
|
|
2591
2604
|
for (let x of polynomStringNormalized.matchAll(/\(([a-z0-9+\-]+)\)(\^[0-9]*)?/g)) {
|
|
2592
2605
|
if (x[2] !== undefined) {
|
|
2606
|
+
// if there is an exponential value, add it multiple times
|
|
2593
2607
|
for (let i = 0; i < +x[2].substring(1); i++) {
|
|
2594
2608
|
factors.push(x[1]);
|
|
2595
2609
|
}
|
|
2596
2610
|
}
|
|
2597
2611
|
else {
|
|
2612
|
+
// no power - add it once.
|
|
2598
2613
|
factors.push(x[1]);
|
|
2599
2614
|
}
|
|
2615
|
+
// Remove the current polynom
|
|
2600
2616
|
polynomStringReduced = polynomStringReduced.replaceAll(x[0], '');
|
|
2601
2617
|
}
|
|
2602
2618
|
if (polynomStringReduced !== '') {
|
|
2603
2619
|
factors.push(polynomStringReduced);
|
|
2604
2620
|
}
|
|
2605
2621
|
let polyFactors = factors.map(x => new Polynom(x));
|
|
2622
|
+
// polyFactors contain all polynoms.
|
|
2623
|
+
let checkPolyFactors = polyFactors.filter(x => x.degree().geq(1) && !x.commonMonom().isOne());
|
|
2624
|
+
// Some polynoms are not completely factorized.
|
|
2625
|
+
if (checkPolyFactors.length > 0 && !soft) {
|
|
2626
|
+
return false;
|
|
2627
|
+
}
|
|
2628
|
+
if (checkPolyFactors.length > 0 && soft) {
|
|
2629
|
+
polyFactors = polyFactors.filter(x => x.commonMonom().isOne());
|
|
2630
|
+
let FactorizedConstant = new fraction_1.Fraction().one();
|
|
2631
|
+
for (let p of checkPolyFactors) {
|
|
2632
|
+
let k = p.commonMonom(), pFactor = p.clone().divide(k);
|
|
2633
|
+
if (k.degree().isZero()) {
|
|
2634
|
+
FactorizedConstant.multiply(k.coefficient);
|
|
2635
|
+
polyFactors.push(pFactor.clone());
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2606
2639
|
// Factorize the current polynom.
|
|
2607
2640
|
this.factorize();
|
|
2608
|
-
// console.log('RESULT BEFORE COMPARE')
|
|
2609
|
-
// console.log(polynomString, polynomStringNormalized)
|
|
2610
|
-
// console.log(factors)
|
|
2611
|
-
// console.log(this.factors.map(x=>x.display))
|
|
2612
2641
|
// Compare the given factors with the generated factors
|
|
2613
|
-
let sign = 1;
|
|
2642
|
+
let sign = 1, notFoundedFactors = [];
|
|
2614
2643
|
for (let f of this.factors) {
|
|
2644
|
+
// The factor is just a coefficient. Might be opposed
|
|
2615
2645
|
if (f.degree().isZero()) {
|
|
2616
2646
|
if (f.monoms[0].coefficient.isNegativeOne()) {
|
|
2617
2647
|
sign = -sign;
|
|
2618
2648
|
}
|
|
2619
2649
|
}
|
|
2650
|
+
let factorFound = false;
|
|
2620
2651
|
for (let i = 0; i < polyFactors.length; i++) {
|
|
2621
2652
|
if (f.isEqual(polyFactors[i])) {
|
|
2622
2653
|
polyFactors.splice(i, 1);
|
|
2654
|
+
factorFound = true;
|
|
2623
2655
|
break;
|
|
2624
2656
|
}
|
|
2625
2657
|
else if (f.isOpposedAt(polyFactors[i])) {
|
|
2626
2658
|
polyFactors.splice(i, 1);
|
|
2627
2659
|
sign = -sign;
|
|
2660
|
+
factorFound = true;
|
|
2628
2661
|
break;
|
|
2629
2662
|
}
|
|
2630
2663
|
}
|
|
2664
|
+
if (!factorFound) {
|
|
2665
|
+
notFoundedFactors.push(f.clone());
|
|
2666
|
+
}
|
|
2631
2667
|
}
|
|
2632
2668
|
// The polyfactors must be empty and the cumulative opposite factors must be 1.
|
|
2633
2669
|
return (polyFactors.length === 0 && sign === 1);
|