pimath 0.0.103 → 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 +46 -9
- 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/equation.js +4 -3
- package/esm/maths/algebra/equation.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/equation.ts +4 -3
- package/src/maths/algebra/polynom.ts +79 -33
- package/tests/algebra/polynom.test.ts +25 -6
- package/tests/geometry/line.test.ts +16 -0
- package/dev/pi.js +0 -7865
- package/dev/pi.js.map +0 -1
package/dist/pi.js
CHANGED
|
@@ -179,11 +179,12 @@ class Equation {
|
|
|
179
179
|
// Start by moving everything to the left.
|
|
180
180
|
this._left.subtract(this._right);
|
|
181
181
|
this._right.zero();
|
|
182
|
-
|
|
182
|
+
let values = [...this._left.monoms];
|
|
183
|
+
for (let m of values) {
|
|
183
184
|
if (!m.hasLetter(letter)) {
|
|
184
185
|
mMove = m.clone();
|
|
185
|
-
this._left.
|
|
186
|
-
this._right.
|
|
186
|
+
this._left.subtract(mMove);
|
|
187
|
+
this._right.subtract(mMove);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
// In theory, we should have only one item on the left.
|
|
@@ -2494,10 +2495,23 @@ class Polynom {
|
|
|
2494
2495
|
else if (typeof value === 'number' && Number.isSafeInteger(value)) {
|
|
2495
2496
|
return this.divideByInteger(value);
|
|
2496
2497
|
}
|
|
2498
|
+
else if (value instanceof monom_1.Monom) {
|
|
2499
|
+
return this.divide(new Polynom(value));
|
|
2500
|
+
}
|
|
2497
2501
|
else if (value instanceof Polynom) {
|
|
2498
2502
|
if (value.monoms.length === 1 && value.variables.length === 0) {
|
|
2499
2503
|
return this.divideByFraction(value.monoms[0].coefficient);
|
|
2500
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
|
+
}
|
|
2501
2515
|
}
|
|
2502
2516
|
};
|
|
2503
2517
|
this.pow = (nb) => {
|
|
@@ -2567,7 +2581,7 @@ class Polynom {
|
|
|
2567
2581
|
this.isOpposedAt = (P) => {
|
|
2568
2582
|
return this.compare(P.clone().opposed(), '=');
|
|
2569
2583
|
};
|
|
2570
|
-
this.isFactorized = (polynomString) => {
|
|
2584
|
+
this.isFactorized = (polynomString, soft) => {
|
|
2571
2585
|
let P;
|
|
2572
2586
|
// Check if polynom is complete...
|
|
2573
2587
|
if (polynomString.split('(').length !== polynomString.split(')').length) {
|
|
@@ -2589,44 +2603,67 @@ class Polynom {
|
|
|
2589
2603
|
let polynomStringNormalized = polynomString.replaceAll('*', ''), polynomStringReduced = '' + polynomStringNormalized, factors = [];
|
|
2590
2604
|
for (let x of polynomStringNormalized.matchAll(/\(([a-z0-9+\-]+)\)(\^[0-9]*)?/g)) {
|
|
2591
2605
|
if (x[2] !== undefined) {
|
|
2606
|
+
// if there is an exponential value, add it multiple times
|
|
2592
2607
|
for (let i = 0; i < +x[2].substring(1); i++) {
|
|
2593
2608
|
factors.push(x[1]);
|
|
2594
2609
|
}
|
|
2595
2610
|
}
|
|
2596
2611
|
else {
|
|
2612
|
+
// no power - add it once.
|
|
2597
2613
|
factors.push(x[1]);
|
|
2598
2614
|
}
|
|
2615
|
+
// Remove the current polynom
|
|
2599
2616
|
polynomStringReduced = polynomStringReduced.replaceAll(x[0], '');
|
|
2600
2617
|
}
|
|
2601
2618
|
if (polynomStringReduced !== '') {
|
|
2602
2619
|
factors.push(polynomStringReduced);
|
|
2603
2620
|
}
|
|
2604
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
|
+
}
|
|
2605
2639
|
// Factorize the current polynom.
|
|
2606
2640
|
this.factorize();
|
|
2607
|
-
// console.log('RESULT BEFORE COMPARE')
|
|
2608
|
-
// console.log(polynomString, polynomStringNormalized)
|
|
2609
|
-
// console.log(factors)
|
|
2610
|
-
// console.log(this.factors.map(x=>x.display))
|
|
2611
2641
|
// Compare the given factors with the generated factors
|
|
2612
|
-
let sign = 1;
|
|
2642
|
+
let sign = 1, notFoundedFactors = [];
|
|
2613
2643
|
for (let f of this.factors) {
|
|
2644
|
+
// The factor is just a coefficient. Might be opposed
|
|
2614
2645
|
if (f.degree().isZero()) {
|
|
2615
2646
|
if (f.monoms[0].coefficient.isNegativeOne()) {
|
|
2616
2647
|
sign = -sign;
|
|
2617
2648
|
}
|
|
2618
2649
|
}
|
|
2650
|
+
let factorFound = false;
|
|
2619
2651
|
for (let i = 0; i < polyFactors.length; i++) {
|
|
2620
2652
|
if (f.isEqual(polyFactors[i])) {
|
|
2621
2653
|
polyFactors.splice(i, 1);
|
|
2654
|
+
factorFound = true;
|
|
2622
2655
|
break;
|
|
2623
2656
|
}
|
|
2624
2657
|
else if (f.isOpposedAt(polyFactors[i])) {
|
|
2625
2658
|
polyFactors.splice(i, 1);
|
|
2626
2659
|
sign = -sign;
|
|
2660
|
+
factorFound = true;
|
|
2627
2661
|
break;
|
|
2628
2662
|
}
|
|
2629
2663
|
}
|
|
2664
|
+
if (!factorFound) {
|
|
2665
|
+
notFoundedFactors.push(f.clone());
|
|
2666
|
+
}
|
|
2630
2667
|
}
|
|
2631
2668
|
// The polyfactors must be empty and the cumulative opposite factors must be 1.
|
|
2632
2669
|
return (polyFactors.length === 0 && sign === 1);
|