pimath 0.0.49 → 0.0.53
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/README.md +1 -1
- package/dist/pi.js +626 -358
- 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/icons.css +1043 -1043
- package/docs/assets/main.js +52 -52
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1413 -1388
- package/docs/classes/Logicalset.Logicalset-1.html +5 -0
- package/docs/classes/Polynom.Rational.html +4 -0
- package/docs/classes/Vector.Point.html +1 -0
- package/docs/classes/Vector.Vector-1.html +1 -0
- package/docs/classes/algebra_equation.Equation.html +26 -0
- package/docs/classes/algebra_linearSystem.LinearSystem.html +1 -0
- package/docs/classes/algebra_monom.Monom.html +114 -0
- package/docs/classes/algebra_polynom.Polynom.html +30 -0
- package/docs/classes/coefficients_fraction.Fraction.html +19 -0
- package/docs/classes/coefficients_nthroot.NthRoot.html +3 -0
- package/docs/classes/expressions_numexp.NumExp.html +1 -0
- package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +1 -0
- package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +1 -0
- package/docs/classes/geometry_circle.Circle.html +3 -0
- package/docs/classes/geometry_line.Line.html +3 -0
- package/docs/classes/geometry_triangle.Triangle.html +17 -0
- 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 -0
- package/docs/enums/geometry_line.LinePropriety.html +1 -0
- package/docs/enums/shutingyard.ShutingyardMode.html +1 -1
- package/docs/enums/shutingyard.ShutingyardType.html +1 -1
- package/docs/index.html +11 -11
- package/docs/interfaces/algebra_equation.ISolution.html +3 -0
- package/docs/interfaces/geometry_triangle.remarquableLines.html +1 -0
- package/docs/modules/Logicalset.html +3 -0
- package/docs/modules/Polynom.html +3 -0
- package/docs/modules/Vector.html +3 -0
- package/docs/modules/algebra_equation.html +1 -0
- package/docs/modules/algebra_linearSystem.html +1 -0
- package/docs/modules/algebra_monom.html +1 -0
- package/docs/modules/algebra_polynom.html +1 -0
- package/docs/modules/coefficients_fraction.html +1 -0
- package/docs/modules/coefficients_nthroot.html +1 -0
- package/docs/modules/expressions_numexp.html +1 -0
- package/docs/modules/expressions_polynomexp.html +1 -0
- package/docs/modules/geometry_circle.html +1 -0
- package/docs/modules/geometry_line.html +1 -0
- package/docs/modules/geometry_triangle.html +1 -0
- package/docs/modules/numeric.html +1 -1
- package/docs/modules/shutingyard.html +1 -1
- package/docs/modules.html +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/maths/algebra/equation.d.ts +7 -2
- package/esm/maths/algebra/equation.js +62 -19
- package/esm/maths/algebra/equation.js.map +10 -1
- package/esm/maths/algebra/linearSystem.js +1 -1
- package/esm/maths/algebra/linearSystem.js.map +10 -1
- package/esm/maths/algebra/monom.js +2 -2
- package/esm/maths/algebra/monom.js.map +10 -1
- package/esm/maths/algebra/polynom.d.ts +5 -1
- package/esm/maths/algebra/polynom.js +157 -81
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +16 -6
- package/esm/maths/algebra/rational.js +139 -30
- package/esm/maths/algebra/rational.js.map +10 -1
- package/esm/maths/coefficients/fraction.d.ts +3 -1
- package/esm/maths/coefficients/fraction.js +37 -5
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/coefficients/{nthroot.d.ts → nthRoot.d.ts} +5 -5
- package/esm/maths/coefficients/{nthroot.js → nthRoot.js} +5 -5
- package/esm/maths/coefficients/{nthroot.js.map → nthRoot.js.map} +1 -1
- package/esm/maths/expressions/polynomexp.bkp.js +2 -3
- package/esm/maths/expressions/polynomexp.bkp.js.map +10 -1
- package/esm/maths/expressions/polynomexp.js +3 -3
- package/esm/maths/expressions/polynomexp.js.map +10 -1
- package/esm/maths/geometry/line.js +8 -0
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.js +1 -1
- package/esm/maths/geometry/point.js.map +10 -1
- package/esm/maths/randomization/random.js +5 -1
- package/esm/maths/randomization/random.js.map +10 -1
- package/package.json +11 -11
- package/public/index.html +234 -235
- package/src/index.ts +2 -2
- package/src/maths/algebra/equation.ts +68 -19
- package/src/maths/algebra/linearSystem.ts +1 -1
- package/src/maths/algebra/monom.ts +3 -4
- package/src/maths/algebra/polynom.ts +170 -87
- package/src/maths/algebra/rational.ts +243 -98
- package/src/maths/coefficients/fraction.ts +44 -6
- package/src/maths/coefficients/{nthroot.ts → nthRoot.ts} +5 -5
- package/src/maths/expressions/polynomexp.bkp.ts +1 -2
- package/src/maths/expressions/polynomexp.ts +2 -1
- package/src/maths/geometry/line.ts +0 -1
- package/src/maths/geometry/point.ts +1 -1
- package/tests/algebra/equation.test.ts +36 -0
- package/tests/algebra/monom.test.ts +2 -5
- package/tests/algebra/polynom.test.ts +7 -3
- package/tests/algebra/rationnal.test.ts +96 -0
- package/tests/coefficients/fraction.test.ts +43 -1
- package/tests/geometry/circle.test.ts +4 -2
- package/tests/polynomexp.test.ts +0 -3
- package/tsconfig.json +16 -5
- package/docs/classes/Algebra.Equation.html +0 -26
- package/docs/classes/algebra.LinearSystem.html +0 -1
- package/docs/classes/algebra.Logicalset.html +0 -5
- package/docs/classes/algebra.Monom.html +0 -114
- package/docs/classes/algebra.Polynom.html +0 -30
- package/docs/classes/algebra.PolynomExpFactor.html +0 -1
- package/docs/classes/algebra.PolynomExpProduct.html +0 -1
- package/docs/classes/algebra.Rational.html +0 -4
- package/docs/classes/coefficients.Fraction.html +0 -19
- package/docs/classes/coefficients.Nthroot.html +0 -3
- package/docs/classes/geometry.Circle.html +0 -3
- package/docs/classes/geometry.Line.html +0 -3
- package/docs/classes/geometry.Point.html +0 -1
- package/docs/classes/geometry.Triangle.html +0 -17
- package/docs/classes/geometry.Vector.html +0 -1
- package/docs/enums/geometry.LinePropriety.html +0 -1
- package/docs/interfaces/geometry.remarquableLines.html +0 -1
- package/docs/modules/Algebra.html +0 -1
- package/docs/modules/Random.html +0 -1
- package/docs/modules/coefficients.html +0 -1
- package/docs/modules/geometry.html +0 -1
- package/docs/modules/random.Random.html +0 -1
|
@@ -2,22 +2,28 @@ import {Polynom} from "./polynom";
|
|
|
2
2
|
import {literalType, Monom} from "./monom";
|
|
3
3
|
import {Numeric} from "../numeric";
|
|
4
4
|
import {Fraction} from "../coefficients/fraction";
|
|
5
|
-
import {
|
|
5
|
+
import {NthRoot} from "../coefficients/nthRoot";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Equation is a class to manage equations...
|
|
9
9
|
*/
|
|
10
|
-
interface ISolution {
|
|
10
|
+
export interface ISolution {
|
|
11
11
|
tex: string,
|
|
12
12
|
value: number,
|
|
13
13
|
exact: unknown
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export enum PARTICULAR_SOLUTION {
|
|
17
|
+
real="\\mathbb{R}",
|
|
18
|
+
varnothing="\\varnothing"
|
|
19
|
+
}
|
|
20
|
+
|
|
16
21
|
export class Equation {
|
|
17
22
|
private _polynom: Polynom; // Used to solve the equation // TODO: remove the private value ?
|
|
23
|
+
|
|
18
24
|
// Undetermined texSolutions.
|
|
19
|
-
private _varnothing: string =
|
|
20
|
-
private _real: string =
|
|
25
|
+
private _varnothing: string = PARTICULAR_SOLUTION.varnothing;
|
|
26
|
+
private _real: string = PARTICULAR_SOLUTION.real;
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* Create an Equation using two polynoms.
|
|
@@ -159,6 +165,9 @@ export class Equation {
|
|
|
159
165
|
return this.variables.length;
|
|
160
166
|
}
|
|
161
167
|
|
|
168
|
+
hasVariable = (letter: string): boolean => {
|
|
169
|
+
return this.variables.includes(letter)
|
|
170
|
+
}
|
|
162
171
|
|
|
163
172
|
// ------------------------------------------
|
|
164
173
|
// Creation / parsing functions
|
|
@@ -397,9 +406,29 @@ export class Equation {
|
|
|
397
406
|
default:
|
|
398
407
|
this._solveDegree3plus();
|
|
399
408
|
}
|
|
409
|
+
|
|
410
|
+
// cleanup the solutions.
|
|
411
|
+
this._solutions = Equation.makeSolutionsUnique(this._solutions)
|
|
400
412
|
return this;
|
|
401
413
|
};
|
|
402
414
|
|
|
415
|
+
static makeSolutionsUnique(solutions: ISolution[], sorted?: boolean):ISolution[] {
|
|
416
|
+
let solutionAsTex:string[] = [],
|
|
417
|
+
uniqueSolutions = solutions.filter(sol=>{
|
|
418
|
+
if(!solutionAsTex.includes(sol.tex)){
|
|
419
|
+
solutionAsTex.push(sol.tex)
|
|
420
|
+
return true
|
|
421
|
+
}else{
|
|
422
|
+
return false
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
if(sorted===true){
|
|
427
|
+
uniqueSolutions.sort((a, b)=>a.value-b.value)
|
|
428
|
+
}
|
|
429
|
+
return uniqueSolutions
|
|
430
|
+
}
|
|
431
|
+
|
|
403
432
|
test = (values: literalType): Boolean => {
|
|
404
433
|
return this.left.evaluate(values).isEqual(this.right.evaluate(values))
|
|
405
434
|
}
|
|
@@ -526,12 +555,13 @@ export class Equation {
|
|
|
526
555
|
}
|
|
527
556
|
} else {
|
|
528
557
|
this._solutions = [{
|
|
529
|
-
tex: v.
|
|
558
|
+
tex: v.tex,
|
|
530
559
|
value: v.value,
|
|
531
560
|
exact: v
|
|
532
561
|
}]
|
|
533
562
|
}
|
|
534
|
-
}
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
535
565
|
if (m1.value === 0) {
|
|
536
566
|
// In this case, the coefficient of the x variable is zero.
|
|
537
567
|
if (m0.value === 0 && this.isAlsoEqual()) {
|
|
@@ -565,7 +595,7 @@ export class Equation {
|
|
|
565
595
|
let aF = this._polynom.monomByDegree(2, letter).coefficient,
|
|
566
596
|
bF = this._polynom.monomByDegree(1, letter).coefficient,
|
|
567
597
|
cF = this._polynom.monomByDegree(0, letter).coefficient,
|
|
568
|
-
delta: number, nthDelta:
|
|
598
|
+
delta: number, nthDelta: NthRoot,
|
|
569
599
|
lcm = Numeric.lcm(aF.denominator, bF.denominator, cF.denominator),
|
|
570
600
|
a = aF.multiply(lcm).value,
|
|
571
601
|
b = bF.multiply(lcm).value,
|
|
@@ -594,7 +624,7 @@ export class Equation {
|
|
|
594
624
|
}
|
|
595
625
|
]
|
|
596
626
|
} else {
|
|
597
|
-
nthDelta = new
|
|
627
|
+
nthDelta = new NthRoot(delta).reduce();
|
|
598
628
|
if (nthDelta.hasRadical()) {
|
|
599
629
|
// -b +- coeff\sqrt{radical}
|
|
600
630
|
// -------------------------
|
|
@@ -622,12 +652,12 @@ export class Equation {
|
|
|
622
652
|
} else {
|
|
623
653
|
this._solutions = [
|
|
624
654
|
{
|
|
625
|
-
tex: `\\
|
|
655
|
+
tex: `\\frac{${-b / gcd} - ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
626
656
|
value: realX1,
|
|
627
657
|
exact: false
|
|
628
658
|
},
|
|
629
659
|
{
|
|
630
|
-
tex: `\\
|
|
660
|
+
tex: `\\frac{${-b / gcd} + ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
631
661
|
value: realX2,
|
|
632
662
|
exact: false
|
|
633
663
|
},
|
|
@@ -650,12 +680,12 @@ export class Equation {
|
|
|
650
680
|
} else {
|
|
651
681
|
this._solutions = [
|
|
652
682
|
{
|
|
653
|
-
tex: `\\
|
|
683
|
+
tex: `\\frac{- ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
654
684
|
value: realX1,
|
|
655
685
|
exact: false
|
|
656
686
|
},
|
|
657
687
|
{
|
|
658
|
-
tex: `\\
|
|
688
|
+
tex: `\\frac{${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
659
689
|
value: realX2,
|
|
660
690
|
exact: false
|
|
661
691
|
},
|
|
@@ -668,12 +698,12 @@ export class Equation {
|
|
|
668
698
|
S2 = new Fraction(-b + nthDelta.coefficient, 2 * a).reduce()
|
|
669
699
|
this._solutions = [
|
|
670
700
|
{
|
|
671
|
-
tex: S1.
|
|
701
|
+
tex: S1.frac,
|
|
672
702
|
value: realX1,
|
|
673
703
|
exact: S1
|
|
674
704
|
},
|
|
675
705
|
{
|
|
676
|
-
tex: S2.
|
|
706
|
+
tex: S2.frac,
|
|
677
707
|
value: realX2,
|
|
678
708
|
exact: S2
|
|
679
709
|
}
|
|
@@ -684,7 +714,7 @@ export class Equation {
|
|
|
684
714
|
} else if (delta === 0) {
|
|
685
715
|
const sol = new Fraction(-b, 2 * a).reduce()
|
|
686
716
|
this._solutions = [{
|
|
687
|
-
tex: sol.
|
|
717
|
+
tex: sol.frac,
|
|
688
718
|
value: sol.value,
|
|
689
719
|
exact: sol
|
|
690
720
|
}];
|
|
@@ -696,7 +726,6 @@ export class Equation {
|
|
|
696
726
|
}];
|
|
697
727
|
}
|
|
698
728
|
|
|
699
|
-
|
|
700
729
|
// Handle now the inequations.
|
|
701
730
|
if (!this.isStrictEqual()) {
|
|
702
731
|
if (this._solutions.length === 2) {
|
|
@@ -763,9 +792,29 @@ export class Equation {
|
|
|
763
792
|
return this._solutions;
|
|
764
793
|
};
|
|
765
794
|
|
|
766
|
-
private _solveDegree3plus = (): ISolution[] => {
|
|
767
|
-
//
|
|
768
|
-
|
|
795
|
+
private _solveDegree3plus = (letter?: string): ISolution[] => {
|
|
796
|
+
// Push everything to the left
|
|
797
|
+
// factorize
|
|
798
|
+
// solve each factors.
|
|
799
|
+
let equ = this.clone().moveLeft()
|
|
800
|
+
equ.left.factorize()
|
|
801
|
+
|
|
802
|
+
this._solutions = []
|
|
803
|
+
|
|
804
|
+
equ.left.factors.forEach(factor=>{
|
|
805
|
+
if(factor.degree(letter).leq(2)) {
|
|
806
|
+
let factorAsEquation = new Equation(factor, 0)
|
|
807
|
+
factorAsEquation.solve()
|
|
808
|
+
factorAsEquation.solutions.forEach(solution => {
|
|
809
|
+
this._solutions.push(solution)
|
|
810
|
+
})
|
|
811
|
+
}else{
|
|
812
|
+
console.log(factor.tex, ': cannot actually get the solution of this equation')
|
|
813
|
+
}
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
// TODO: check equation resolution for more than degree 2
|
|
817
|
+
// this._solutions = [{tex: 'solve x - not yet handled', value: NaN, exact: false}]; // ESLint remove system :(
|
|
769
818
|
return this._solutions;
|
|
770
819
|
};
|
|
771
820
|
}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* Monom class
|
|
3
3
|
*/
|
|
4
4
|
import {Numeric} from "../numeric";
|
|
5
|
-
import {Shutingyard, ShutingyardType, Token
|
|
6
|
-
import {log} from "util";
|
|
5
|
+
import {Shutingyard, ShutingyardType, Token} from "../shutingyard";
|
|
7
6
|
import {Fraction} from "../coefficients/fraction";
|
|
8
7
|
|
|
9
8
|
export type literalType = {
|
|
@@ -273,7 +272,7 @@ export class Monom {
|
|
|
273
272
|
if (L === '') {
|
|
274
273
|
// No setLetter - means it's only a number !
|
|
275
274
|
if (this._coefficient.value != 0) {
|
|
276
|
-
return `${this._coefficient.
|
|
275
|
+
return `${this._coefficient.frac}`;
|
|
277
276
|
} else {
|
|
278
277
|
return '0';
|
|
279
278
|
}
|
|
@@ -285,7 +284,7 @@ export class Monom {
|
|
|
285
284
|
} else if (this._coefficient.value === 0) {
|
|
286
285
|
return '0';
|
|
287
286
|
} else {
|
|
288
|
-
return `${this._coefficient.
|
|
287
|
+
return `${this._coefficient.frac}${L}`;
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
290
|
}
|
|
@@ -6,6 +6,7 @@ import {literalType, Monom} from './monom';
|
|
|
6
6
|
import {Shutingyard, ShutingyardType, Token} from '../shutingyard';
|
|
7
7
|
import {Numeric} from '../numeric';
|
|
8
8
|
import {Fraction} from "../coefficients/fraction";
|
|
9
|
+
import {Equation, ISolution} from "./equation";
|
|
9
10
|
|
|
10
11
|
export type PolynomParsingType = string | Polynom | number | Fraction | Monom
|
|
11
12
|
|
|
@@ -65,6 +66,9 @@ export class Polynom {
|
|
|
65
66
|
get texFactors(): string {
|
|
66
67
|
this.factorize()
|
|
67
68
|
|
|
69
|
+
if (this.factors.length === 0) {
|
|
70
|
+
return this.tex
|
|
71
|
+
}
|
|
68
72
|
let tex = ''
|
|
69
73
|
for (let f of this.factors) {
|
|
70
74
|
if (f.monoms.length > 1) {
|
|
@@ -209,8 +213,16 @@ export class Polynom {
|
|
|
209
213
|
|
|
210
214
|
if (typeof inputStr === 'string') {
|
|
211
215
|
return this._parseString(inputStr, ...values)
|
|
212
|
-
} else if (
|
|
216
|
+
} else if (
|
|
217
|
+
(typeof inputStr === 'number' || inputStr instanceof Fraction || inputStr instanceof Monom)
|
|
218
|
+
&& (values === undefined || values.length===0)
|
|
219
|
+
) {
|
|
220
|
+
this._monoms.push(new Monom(inputStr))
|
|
221
|
+
} else if (inputStr instanceof Monom && values.length > 0) {
|
|
213
222
|
this._monoms.push(new Monom(inputStr))
|
|
223
|
+
values.forEach(m => {
|
|
224
|
+
this._monoms.push(new Monom(m))
|
|
225
|
+
})
|
|
214
226
|
} else if (inputStr instanceof Polynom) {
|
|
215
227
|
for (const m of inputStr.monoms) {
|
|
216
228
|
this._monoms.push(m.clone())
|
|
@@ -773,6 +785,7 @@ export class Polynom {
|
|
|
773
785
|
}
|
|
774
786
|
|
|
775
787
|
let securityLoop = P.degree().clone().multiply(2).value
|
|
788
|
+
let result
|
|
776
789
|
// securityLoop = 0
|
|
777
790
|
|
|
778
791
|
while (securityLoop >= 0) {
|
|
@@ -780,110 +793,151 @@ export class Polynom {
|
|
|
780
793
|
|
|
781
794
|
if (P.monoms.length < 2) {
|
|
782
795
|
if (!P.isOne()) {
|
|
783
|
-
factors.push(P.clone())
|
|
796
|
+
factors.push(P.clone())
|
|
797
|
+
P.one()
|
|
784
798
|
}
|
|
785
|
-
break
|
|
799
|
+
break
|
|
800
|
+
} else if (P.degree(letter).isOne()){
|
|
801
|
+
factors.push(P.clone())
|
|
802
|
+
P.one()
|
|
803
|
+
break
|
|
786
804
|
} else {
|
|
787
|
-
// Get the first and last monom.
|
|
805
|
+
// Get the first and last monom and build all their dividers.
|
|
788
806
|
let m1 = P.monoms[0].dividers,
|
|
789
807
|
m2 = P.monoms[P.monoms.length - 1].dividers
|
|
790
808
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
// if(m1d.degree()===m2d.degree()){continue}
|
|
794
|
-
let dividerPolynom = new Polynom(),
|
|
795
|
-
result
|
|
796
|
-
dividerPolynom.monoms = [m1d.clone(), m2d.clone()]
|
|
797
|
-
result = P.euclidian(dividerPolynom)
|
|
798
|
-
|
|
799
|
-
if (result.reminder.isZero()) {
|
|
800
|
-
P = result.quotient.clone();
|
|
801
|
-
factors.push(dividerPolynom)
|
|
802
|
-
continue;
|
|
803
|
-
}
|
|
809
|
+
// Create the list of all "potential" polynom dividers.
|
|
810
|
+
let allDividers:Polynom[] = this._getAllPotentialFactors(P,letter)
|
|
804
811
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
812
|
+
allDividers.every(div => {
|
|
813
|
+
result = P.euclidian(div)
|
|
814
|
+
if(result.reminder.isZero()){
|
|
815
|
+
P = result.quotient.clone()
|
|
816
|
+
factors.push(div)
|
|
817
|
+
return false
|
|
811
818
|
}
|
|
812
|
-
|
|
819
|
+
return true
|
|
820
|
+
})
|
|
813
821
|
}
|
|
814
822
|
}
|
|
815
823
|
|
|
824
|
+
if (!P.isOne()) {
|
|
825
|
+
factors.push(P.clone())
|
|
826
|
+
}
|
|
827
|
+
|
|
816
828
|
this.factors = factors
|
|
817
829
|
return factors;
|
|
818
830
|
}
|
|
819
831
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
832
|
+
private _getAllPotentialFactors = (P: Polynom, letter?: string): Polynom[] => {
|
|
833
|
+
let m1 = P.monoms[0].dividers,
|
|
834
|
+
m2 = P.monoms[P.monoms.length - 1].dividers
|
|
823
835
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
836
|
+
let allDividers: Polynom[] = []
|
|
837
|
+
m1.forEach(m1d => {
|
|
838
|
+
m2.forEach(m2d => {
|
|
839
|
+
if (m1d.degree(letter).isNotEqual(m2d.degree(letter))) {
|
|
840
|
+
allDividers.push(new Polynom(m1d, m2d))
|
|
841
|
+
allDividers.push(new Polynom(m1d, m2d.clone().opposed()))
|
|
830
842
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
if (this._monoms.length === 1) {
|
|
834
|
-
return [new Fraction().zero()];
|
|
835
|
-
} else {
|
|
836
|
-
const P = this.clone().reduce().reorder();
|
|
837
|
-
return [P.monoms[1].coefficient.opposed().divide(P.monoms[0].coefficient)];
|
|
838
|
-
}
|
|
839
|
-
// TODO: Determine the zeros of an equation of second degree.
|
|
840
|
-
//case 2:
|
|
841
|
-
default:
|
|
842
|
-
// Make sure the polynom is factorized.
|
|
843
|
-
if (this._factors.length === 0) {
|
|
844
|
-
this.factorize()
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
let zeroes = [], zeroesAsTex = [];
|
|
848
|
-
for (let P of this._factors) {
|
|
849
|
-
if (P.degree().greater(2)) {
|
|
850
|
-
// TODO: Handle other polynom.
|
|
851
|
-
|
|
852
|
-
} else if (P.degree().value === 2) {
|
|
853
|
-
let A = P.monomByDegree(2).coefficient,
|
|
854
|
-
B = P.monomByDegree(1).coefficient,
|
|
855
|
-
C = P.monomByDegree(0).coefficient,
|
|
856
|
-
D = B.clone().pow(2).subtract(A.clone().multiply(C).multiply(4));
|
|
857
|
-
|
|
858
|
-
if (D.value > 0) {
|
|
859
|
-
/*console.log('Two zeroes for ', P.tex); */
|
|
860
|
-
let x1 = (-(B.value) + Math.sqrt(D.value)) / (2 * A.value),
|
|
861
|
-
x2 = (-(B.value) - Math.sqrt(D.value)) / (2 * A.value);
|
|
843
|
+
})
|
|
844
|
+
})
|
|
862
845
|
|
|
863
|
-
|
|
864
|
-
zeroes.push(new Fraction(x2.toFixed(3)).reduce());
|
|
865
|
-
} else if (D.value === 0) {
|
|
866
|
-
/*console.log('One zero for ', P.tex); */
|
|
846
|
+
return allDividers
|
|
867
847
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
848
|
+
}
|
|
849
|
+
// TODO: get zeroes for more than first degree and for more than natural degrees
|
|
850
|
+
getZeroes = (): ISolution[] => {
|
|
851
|
+
let equ = new Equation(this.clone(), 0)
|
|
852
|
+
equ.solve()
|
|
853
|
+
return equ.solutions
|
|
854
|
+
|
|
855
|
+
//
|
|
856
|
+
// const Z: Fraction[] = [];
|
|
857
|
+
//
|
|
858
|
+
// // ISolution: {tex: string, value: number, exact: boolean|Fraction|...}
|
|
859
|
+
//
|
|
860
|
+
// switch (this.degree().value) {
|
|
861
|
+
// case 0:
|
|
862
|
+
// if (this._monoms[0].coefficient.value === 0) {
|
|
863
|
+
// return [{
|
|
864
|
+
// tex: '\\mathbb{R}',
|
|
865
|
+
// value: NaN,
|
|
866
|
+
// exact: false
|
|
867
|
+
// }];
|
|
868
|
+
// } else {
|
|
869
|
+
// return [{
|
|
870
|
+
// tex: '\\varnothing',
|
|
871
|
+
// value: NaN,
|
|
872
|
+
// exact: false
|
|
873
|
+
// }];
|
|
874
|
+
// }
|
|
875
|
+
// case 1:
|
|
876
|
+
// // There is only one monoms,
|
|
877
|
+
// if (this._monoms.length === 1) {
|
|
878
|
+
// return [{
|
|
879
|
+
// tex: '0',
|
|
880
|
+
// value: 0,
|
|
881
|
+
// exact: new Fraction().zero()
|
|
882
|
+
// }];
|
|
883
|
+
// } else {
|
|
884
|
+
// const P = this.clone().reduce().reorder();
|
|
885
|
+
// const coeff = P.monoms[1].coefficient.opposed().divide(P.monoms[0].coefficient)
|
|
886
|
+
// return [{
|
|
887
|
+
// tex: coeff.tex,
|
|
888
|
+
// value: coeff.value,
|
|
889
|
+
// exact: coeff
|
|
890
|
+
// }];
|
|
891
|
+
// }
|
|
892
|
+
// // TODO: Determine the zeros of an equation of second degree.
|
|
893
|
+
// //case 2:
|
|
894
|
+
// default:
|
|
895
|
+
// // Make sure the polynom is factorized.
|
|
896
|
+
// if (this._factors.length === 0) {
|
|
897
|
+
// this.factorize()
|
|
898
|
+
// }
|
|
899
|
+
//
|
|
900
|
+
// let zeroes:Fraction[] = [], zeroesAsTex = [];
|
|
901
|
+
// for (let P of this._factors) {
|
|
902
|
+
// if (P.degree().greater(2)) {
|
|
903
|
+
// // TODO: get zeroes of polynom with a degree greater than 2.
|
|
904
|
+
//
|
|
905
|
+
// } else if (P.degree().value === 2) {
|
|
906
|
+
// let A = P.monomByDegree(2).coefficient,
|
|
907
|
+
// B = P.monomByDegree(1).coefficient,
|
|
908
|
+
// C = P.monomByDegree(0).coefficient,
|
|
909
|
+
// D = B.clone().pow(2).subtract(A.clone().multiply(C).multiply(4));
|
|
910
|
+
//
|
|
911
|
+
// if (D.value > 0) {
|
|
912
|
+
// /*console.log('Two zeroes for ', P.tex); */
|
|
913
|
+
// let x1 = (-(B.value) + Math.sqrt(D.value)) / (2 * A.value),
|
|
914
|
+
// x2 = (-(B.value) - Math.sqrt(D.value)) / (2 * A.value);
|
|
915
|
+
//
|
|
916
|
+
// zeroes.push(new Fraction(x1.toFixed(3)).reduce());
|
|
917
|
+
// zeroes.push(new Fraction(x2.toFixed(3)).reduce());
|
|
918
|
+
// } else if (D.value === 0) {
|
|
919
|
+
// /*console.log('One zero for ', P.tex); */
|
|
920
|
+
// } else {
|
|
921
|
+
// console.log('No zero for ', P.tex);
|
|
922
|
+
// }
|
|
923
|
+
// } else {
|
|
924
|
+
// for (let z of P.getZeroes()) {
|
|
925
|
+
// // Check if the zero is already in the list.
|
|
926
|
+
// // if (z === false || z === true) {
|
|
927
|
+
// // continue;
|
|
928
|
+
// // }
|
|
929
|
+
// if (zeroesAsTex.indexOf(z.frac) === -1) {
|
|
930
|
+
// zeroes.push(z);
|
|
931
|
+
// zeroesAsTex.push(z.frac);
|
|
932
|
+
// }
|
|
933
|
+
// }
|
|
934
|
+
// }
|
|
935
|
+
// }
|
|
936
|
+
//
|
|
937
|
+
//
|
|
938
|
+
// return zeroes;
|
|
939
|
+
// }
|
|
940
|
+
// return Z;
|
|
887
941
|
};
|
|
888
942
|
|
|
889
943
|
// TODO: analyse the next functions to determine if they are useful or not...
|
|
@@ -995,6 +1049,35 @@ export class Polynom {
|
|
|
995
1049
|
return M;
|
|
996
1050
|
}
|
|
997
1051
|
|
|
1052
|
+
limitToInfinity = (letter?: string): Fraction => {
|
|
1053
|
+
const M = this.monomByDegree(undefined, letter),
|
|
1054
|
+
sign = M.coefficient.sign(),
|
|
1055
|
+
degree = M.degree(letter)
|
|
1056
|
+
|
|
1057
|
+
if (degree.isStrictlyPositive()) {
|
|
1058
|
+
return sign === 1 ? (new Fraction()).infinite() : (new Fraction()).infinite().opposed()
|
|
1059
|
+
} else if (degree.isZero()) {
|
|
1060
|
+
return M.coefficient
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
// Any other cases
|
|
1064
|
+
return (new Fraction()).zero()
|
|
1065
|
+
}
|
|
1066
|
+
limitToNegativeInfinity = (letter?: string): Fraction => {
|
|
1067
|
+
const M = this.monomByDegree(undefined, letter),
|
|
1068
|
+
sign = M.coefficient.sign(),
|
|
1069
|
+
degree = M.degree(letter)
|
|
1070
|
+
|
|
1071
|
+
if (degree.isStrictlyPositive()) {
|
|
1072
|
+
return sign === -1 ? (new Fraction()).infinite() : (new Fraction()).infinite().opposed()
|
|
1073
|
+
} else if (degree.isZero()) {
|
|
1074
|
+
return M.coefficient
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// Any other cases
|
|
1078
|
+
return (new Fraction()).zero()
|
|
1079
|
+
}
|
|
1080
|
+
|
|
998
1081
|
private _parseString(inputStr: string, ...values: unknown[]): Polynom {
|
|
999
1082
|
if (values === undefined || values.length === 0) {
|
|
1000
1083
|
inputStr = '' + inputStr;
|