pimath 0.0.59 → 0.0.62
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/.eslintrc.js +23 -23
- package/.idea/misc.xml +5 -0
- package/.idea/php.xml +1 -1
- package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40_[Changes]/shelved.patch +21 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40__Changes_.xml +4 -0
- package/dist/pi.js +169 -357
- 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/style.css +1413 -1413
- package/docs/classes/Logicalset.Logicalset-1.html +4 -4
- package/docs/classes/Polynom.Rational.html +3 -3
- package/docs/classes/algebra_equation.Equation.html +25 -25
- package/docs/classes/algebra_monom.Monom.html +113 -113
- package/docs/classes/algebra_polynom.Polynom.html +29 -29
- package/docs/classes/coefficients_fraction.Fraction.html +18 -18
- package/docs/classes/coefficients_nthroot.NthRoot.html +2 -2
- package/docs/classes/geometry_circle.Circle.html +2 -2
- package/docs/classes/geometry_line.Line.html +2 -2
- package/docs/classes/geometry_triangle.Triangle.html +16 -16
- package/docs/classes/numeric.Numeric.html +13 -13
- package/docs/classes/shutingyard.Shutingyard.html +17 -17
- package/docs/index.html +10 -10
- package/docs/interfaces/algebra_equation.ISolution.html +2 -2
- package/docs/modules/Logicalset.html +2 -2
- package/docs/modules/Polynom.html +2 -2
- package/docs/modules/Vector.html +2 -2
- package/esm/maths/algebra/linearSystem.js +0 -1
- package/esm/maths/algebra/linearSystem.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +1 -0
- package/esm/maths/algebra/monom.js +18 -0
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +36 -11
- package/esm/maths/algebra/polynom.js +144 -258
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +15 -15
- package/esm/maths/algebra/rational.js +10 -101
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/algebra/study/rationalStudy.d.ts +33 -0
- package/esm/maths/algebra/study/rationalStudy.js +183 -0
- package/esm/maths/algebra/study/rationalStudy.js.map +1 -0
- package/esm/maths/algebra/study.d.ts +140 -0
- package/esm/maths/algebra/study.js +290 -0
- package/esm/maths/algebra/study.js.map +1 -0
- package/package.json +1 -1
- package/src/maths/algebra/linearSystem.ts +0 -1
- package/src/maths/algebra/monom.ts +19 -0
- package/src/maths/algebra/polynom.ts +185 -278
- package/src/maths/algebra/rational.ts +23 -134
- package/src/maths/algebra/study/rationalStudy.ts +208 -0
- package/src/maths/algebra/study.ts +384 -0
- package/tests/algebra/monom.test.ts +2 -5
- package/tests/algebra/polynom.test.ts +2 -3
- package/tests/algebra/rationnal.test.ts +0 -43
- package/tests/algebra/study.test.ts +18 -0
- package/tests/numexp.test.ts +1 -1
|
@@ -10,6 +10,11 @@ import {Equation, ISolution} from "./equation";
|
|
|
10
10
|
|
|
11
11
|
export type PolynomParsingType = string | Polynom | number | Fraction | Monom
|
|
12
12
|
|
|
13
|
+
export interface IEuclidian {
|
|
14
|
+
quotient: Polynom,
|
|
15
|
+
reminder: Polynom
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
/**
|
|
14
19
|
* Polynom class can handle polynoms, reorder, resolve, ...
|
|
15
20
|
* ```
|
|
@@ -17,7 +22,14 @@ export type PolynomParsingType = string | Polynom | number | Fraction | Monom
|
|
|
17
22
|
* ```
|
|
18
23
|
*/
|
|
19
24
|
export class Polynom {
|
|
25
|
+
private _dirty_factors: boolean
|
|
26
|
+
private _dirty_zeroes: boolean
|
|
27
|
+
private _euclidianCache: { [Key: string]: IEuclidian }
|
|
28
|
+
private _factors: Polynom[];
|
|
29
|
+
private _monoms: Monom[];
|
|
20
30
|
private _rawString: string;
|
|
31
|
+
private _texString: string;
|
|
32
|
+
private _zeroes: ISolution[]
|
|
21
33
|
|
|
22
34
|
/**
|
|
23
35
|
*
|
|
@@ -27,13 +39,38 @@ export class Polynom {
|
|
|
27
39
|
constructor(polynomString?: PolynomParsingType, ...values: unknown[]) {
|
|
28
40
|
this._monoms = [];
|
|
29
41
|
this._factors = [];
|
|
42
|
+
this.mark_as_dirty()
|
|
43
|
+
|
|
30
44
|
if (polynomString !== undefined) {
|
|
31
45
|
this.parse(polynomString, ...values);
|
|
32
46
|
}
|
|
33
47
|
return this;
|
|
34
48
|
}
|
|
35
49
|
|
|
36
|
-
|
|
50
|
+
get euclidianCache(): { [p: string]: IEuclidian } {
|
|
51
|
+
return this._euclidianCache;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
set euclidianCache(value: { [p: string]: IEuclidian }) {
|
|
55
|
+
this._euclidianCache = value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get dirty_zeroes(): boolean {
|
|
59
|
+
return this._dirty_zeroes;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
set dirty_zeroes(value: boolean) {
|
|
63
|
+
this._dirty_zeroes = value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ------------------------------------------
|
|
67
|
+
get dirty_factors(): boolean {
|
|
68
|
+
return this._dirty_factors;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
set dirty_factors(value: boolean) {
|
|
72
|
+
this._dirty_factors = value;
|
|
73
|
+
}
|
|
37
74
|
|
|
38
75
|
// ------------------------------------------
|
|
39
76
|
get monoms() {
|
|
@@ -44,21 +81,19 @@ export class Polynom {
|
|
|
44
81
|
this._monoms = M;
|
|
45
82
|
}
|
|
46
83
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
private _factors: Polynom[];
|
|
84
|
+
get zeroes(): ISolution[] {
|
|
85
|
+
return this.getZeroes()
|
|
86
|
+
}
|
|
51
87
|
|
|
52
88
|
get factors(): Polynom[] {
|
|
53
|
-
return this.
|
|
89
|
+
return this.factorize()
|
|
54
90
|
}
|
|
55
91
|
|
|
56
92
|
set factors(value: Polynom[]) {
|
|
93
|
+
this.mark_as_dirty()
|
|
57
94
|
this._factors = value;
|
|
58
95
|
}
|
|
59
96
|
|
|
60
|
-
private _texString: string;
|
|
61
|
-
|
|
62
97
|
get texString(): string {
|
|
63
98
|
return this._texString;
|
|
64
99
|
}
|
|
@@ -128,8 +163,13 @@ export class Polynom {
|
|
|
128
163
|
return this.genDisplay('tex', false, false, true)
|
|
129
164
|
}
|
|
130
165
|
|
|
131
|
-
|
|
166
|
+
mark_as_dirty = (): void => {
|
|
167
|
+
this.dirty_factors = true
|
|
168
|
+
this.dirty_zeroes = true
|
|
169
|
+
this.euclidianCache = {}
|
|
170
|
+
}
|
|
132
171
|
|
|
172
|
+
addToken = (stack: Polynom[], element: Token): void => {
|
|
133
173
|
switch (element.tokenType) {
|
|
134
174
|
case ShutingyardType.COEFFICIENT:
|
|
135
175
|
stack.push(new Polynom(element.token))
|
|
@@ -217,6 +257,7 @@ export class Polynom {
|
|
|
217
257
|
// Reset the main variables.
|
|
218
258
|
this._monoms = []
|
|
219
259
|
this._factors = []
|
|
260
|
+
this.mark_as_dirty()
|
|
220
261
|
|
|
221
262
|
if (typeof inputStr === 'string') {
|
|
222
263
|
return this._parseString(inputStr, ...values)
|
|
@@ -251,6 +292,7 @@ export class Polynom {
|
|
|
251
292
|
}
|
|
252
293
|
|
|
253
294
|
P.monoms = M;
|
|
295
|
+
|
|
254
296
|
return P;
|
|
255
297
|
};
|
|
256
298
|
|
|
@@ -262,6 +304,7 @@ export class Polynom {
|
|
|
262
304
|
this._monoms = [];
|
|
263
305
|
this._monoms.push(new Monom().zero());
|
|
264
306
|
this._rawString = '0';
|
|
307
|
+
this.mark_as_dirty()
|
|
265
308
|
return this;
|
|
266
309
|
};
|
|
267
310
|
|
|
@@ -269,87 +312,30 @@ export class Polynom {
|
|
|
269
312
|
this._monoms = [];
|
|
270
313
|
this._monoms.push(new Monom().one());
|
|
271
314
|
this._rawString = '1';
|
|
315
|
+
this.mark_as_dirty()
|
|
272
316
|
return this;
|
|
273
317
|
}
|
|
274
318
|
|
|
275
319
|
empty = (): Polynom => {
|
|
276
320
|
this._monoms = [];
|
|
277
321
|
this._rawString = '';
|
|
322
|
+
this.mark_as_dirty()
|
|
278
323
|
return this;
|
|
279
324
|
};
|
|
280
325
|
|
|
281
326
|
// ------------------------------------------
|
|
282
327
|
opposed = (): Polynom => {
|
|
283
328
|
this._monoms = this._monoms.map(m => m.opposed());
|
|
329
|
+
this.mark_as_dirty()
|
|
284
330
|
return this;
|
|
285
331
|
};
|
|
286
332
|
|
|
287
|
-
// // -----------------------------------------------
|
|
288
|
-
// // Polynom generators and randomizers
|
|
289
|
-
// // -----------------------------------------------
|
|
290
|
-
// random(config?: randomPolynomConfig) {
|
|
291
|
-
// return Random.polynom(config);
|
|
292
|
-
// }
|
|
293
|
-
//
|
|
294
|
-
// private _randomizeDefaults: { [key: string]: number | string | boolean } = {
|
|
295
|
-
// degree: 2,
|
|
296
|
-
// unit: true,
|
|
297
|
-
// fractions: false,
|
|
298
|
-
// factorable: false,
|
|
299
|
-
// letters: 'x',
|
|
300
|
-
// allowNullMonom: false,
|
|
301
|
-
// numberOfMonoms: false
|
|
302
|
-
// };
|
|
303
|
-
// get randomizeDefaults(): { [key: string]: number | string | boolean } {
|
|
304
|
-
// return this._randomizeDefaults;
|
|
305
|
-
// }
|
|
306
|
-
//
|
|
307
|
-
// set randomizeDefaults(value) {
|
|
308
|
-
// this._randomizeDefaults = value;
|
|
309
|
-
// }
|
|
310
|
-
//
|
|
311
|
-
// randomize = (config: { [key: string]: number | string | boolean }): Polynom => {
|
|
312
|
-
// let P = new Polynom();
|
|
313
|
-
//
|
|
314
|
-
// // Check the config file and use the default values.
|
|
315
|
-
// if (config === undefined) {
|
|
316
|
-
// config = {};
|
|
317
|
-
// }
|
|
318
|
-
// for (let k in this._randomizeDefaults) {
|
|
319
|
-
// if (config[k] === undefined) {
|
|
320
|
-
// config[k] = this._randomizeDefaults[k];
|
|
321
|
-
// }
|
|
322
|
-
// }
|
|
323
|
-
//
|
|
324
|
-
// // TODO: Build a more robust randomize function
|
|
325
|
-
// return P;
|
|
326
|
-
// }
|
|
327
|
-
//
|
|
328
|
-
// rndFactorable = (degree: number = 2, unit: boolean | number = false, letters: string = 'x'): Polynom => {
|
|
329
|
-
// // TODO: Make rndFactorable polynom generator more user friendly
|
|
330
|
-
// this._factors = [];
|
|
331
|
-
// for (let i = 0; i < degree; i++) {
|
|
332
|
-
// let factorUnit = unit === true || i >= unit,
|
|
333
|
-
// p = Random.polynom({
|
|
334
|
-
// degree: 1,
|
|
335
|
-
// unit: factorUnit,
|
|
336
|
-
// fraction: false,
|
|
337
|
-
// letters
|
|
338
|
-
// });
|
|
339
|
-
// this._factors.push(p);
|
|
340
|
-
// }
|
|
341
|
-
//
|
|
342
|
-
// this.empty().monoms = this._factors[0].monoms;
|
|
343
|
-
// for (let i = 1; i < this._factors.length; i++) {
|
|
344
|
-
// this.multiply(this._factors[i]);
|
|
345
|
-
// }
|
|
346
|
-
// return this;
|
|
347
|
-
// };
|
|
348
333
|
|
|
349
334
|
// ------------------------------------------
|
|
350
335
|
// Mathematical operations
|
|
351
336
|
|
|
352
337
|
add = (...values: unknown[]): Polynom => {
|
|
338
|
+
this.mark_as_dirty()
|
|
353
339
|
|
|
354
340
|
for (let value of values) {
|
|
355
341
|
if (value instanceof Polynom) {
|
|
@@ -367,6 +353,7 @@ export class Polynom {
|
|
|
367
353
|
};
|
|
368
354
|
|
|
369
355
|
subtract = (...values: unknown[]): Polynom => {
|
|
356
|
+
this.mark_as_dirty()
|
|
370
357
|
|
|
371
358
|
for (let value of values) {
|
|
372
359
|
if (value instanceof Polynom) {
|
|
@@ -384,6 +371,8 @@ export class Polynom {
|
|
|
384
371
|
};
|
|
385
372
|
|
|
386
373
|
multiply = (value: unknown): Polynom => {
|
|
374
|
+
this.mark_as_dirty()
|
|
375
|
+
|
|
387
376
|
if (value instanceof Polynom) {
|
|
388
377
|
return this.multiplyByPolynom(value);
|
|
389
378
|
} else if (value instanceof Fraction) {
|
|
@@ -403,7 +392,12 @@ export class Polynom {
|
|
|
403
392
|
* @param P
|
|
404
393
|
* returns {quotient: Polynom, reminder: Polynom}
|
|
405
394
|
*/
|
|
406
|
-
euclidian = (P: Polynom):
|
|
395
|
+
euclidian = (P: Polynom): IEuclidian => {
|
|
396
|
+
|
|
397
|
+
if (this.euclidianCache[P.tex] !== undefined) {
|
|
398
|
+
return this.euclidianCache[P.tex]
|
|
399
|
+
}
|
|
400
|
+
|
|
407
401
|
const letter: string = P.variables[0];
|
|
408
402
|
const quotient: Polynom = new Polynom().zero();
|
|
409
403
|
const reminder: Polynom = this.clone().reorder(letter);
|
|
@@ -448,6 +442,8 @@ export class Polynom {
|
|
|
448
442
|
};
|
|
449
443
|
|
|
450
444
|
divide = (value: unknown): Polynom => {
|
|
445
|
+
this.mark_as_dirty()
|
|
446
|
+
|
|
451
447
|
if (value instanceof Fraction) {
|
|
452
448
|
return this.divideByFraction(value);
|
|
453
449
|
} else if (typeof value === 'number' && Number.isSafeInteger(value)) {
|
|
@@ -460,6 +456,8 @@ export class Polynom {
|
|
|
460
456
|
}
|
|
461
457
|
|
|
462
458
|
pow = (nb: number): Polynom => {
|
|
459
|
+
this.mark_as_dirty()
|
|
460
|
+
|
|
463
461
|
if (!Number.isSafeInteger(nb)) {
|
|
464
462
|
return this.zero();
|
|
465
463
|
}
|
|
@@ -705,6 +703,8 @@ export class Polynom {
|
|
|
705
703
|
* @param P
|
|
706
704
|
*/
|
|
707
705
|
replaceBy = (letter: string, P: Polynom): Polynom => {
|
|
706
|
+
this.mark_as_dirty()
|
|
707
|
+
|
|
708
708
|
let pow: Fraction;
|
|
709
709
|
const resultPolynom: Polynom = new Polynom().zero();
|
|
710
710
|
|
|
@@ -745,7 +745,6 @@ export class Polynom {
|
|
|
745
745
|
dP.add(m.derivative(letter));
|
|
746
746
|
}
|
|
747
747
|
return dP;
|
|
748
|
-
|
|
749
748
|
}
|
|
750
749
|
// ------------------------------------------
|
|
751
750
|
// Misc polynoms functions
|
|
@@ -780,157 +779,125 @@ export class Polynom {
|
|
|
780
779
|
* @param maxValue Defines the greatest value to search to (default is 20).
|
|
781
780
|
*/
|
|
782
781
|
factorize = (letter?: string): Polynom[] => {
|
|
783
|
-
|
|
782
|
+
if (this.dirty_factors) {
|
|
783
|
+
let factors: Polynom[] = [];
|
|
784
|
+
|
|
785
|
+
let P = this.clone().reorder()
|
|
786
|
+
|
|
787
|
+
// Extract the common monom
|
|
788
|
+
// 2x^3+6x^2 => 2x^2
|
|
789
|
+
let M = P.commonMonom()
|
|
790
|
+
if (!M.isOne()) {
|
|
791
|
+
let tempPolynom: Polynom = new Polynom(M)
|
|
792
|
+
factors = [tempPolynom.clone()]
|
|
793
|
+
P = P.euclidian(tempPolynom).quotient;
|
|
794
|
+
}
|
|
784
795
|
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
796
|
+
// Main loop
|
|
797
|
+
let securityLoop = P.degree().clone().multiply(2).value,
|
|
798
|
+
maxDegree = 1
|
|
799
|
+
while (securityLoop >= 0) {
|
|
800
|
+
securityLoop--
|
|
801
|
+
if (P.monoms.length < 2) {
|
|
802
|
+
// The polynom has only one monom => 7x^2
|
|
803
|
+
// No need to continue.
|
|
804
|
+
if (!P.isOne()) {
|
|
805
|
+
factors.push(P.clone())
|
|
806
|
+
P.one()
|
|
807
|
+
}
|
|
808
|
+
break
|
|
809
|
+
} else if (P.degree(letter).isOne()) {
|
|
810
|
+
// The polynom is a first degree polynom => 3x-5
|
|
811
|
+
// No need to continue
|
|
812
|
+
factors.push(P.clone())
|
|
813
|
+
P.one()
|
|
814
|
+
break
|
|
815
|
+
} else {
|
|
816
|
+
// Create the list of all "potential" polynom dividers.
|
|
817
|
+
let allDividers: Polynom[] = this._getAllPotentialFactors(P, maxDegree, letter)
|
|
818
|
+
maxDegree = P.degree(letter).value
|
|
789
819
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
820
|
+
// Actually: 100ms
|
|
821
|
+
while (allDividers.length > 0) {
|
|
822
|
+
let div = allDividers[0]
|
|
823
|
+
|
|
824
|
+
if (!P.isDividableBy(div)) {
|
|
825
|
+
// Not dividable. Remove it from the list
|
|
826
|
+
allDividers.shift()
|
|
827
|
+
} else {
|
|
828
|
+
// It's dividable - so make the division
|
|
829
|
+
let result = P.euclidian(div)
|
|
796
830
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
// securityLoop = 0
|
|
831
|
+
// Add the factor
|
|
832
|
+
factors.push(div)
|
|
800
833
|
|
|
801
|
-
|
|
802
|
-
|
|
834
|
+
// As it's dividable, get the quotient.
|
|
835
|
+
P = result.quotient.clone()
|
|
803
836
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
837
|
+
// filter all dividers that are no more suitable.
|
|
838
|
+
allDividers = allDividers.filter(x => {
|
|
839
|
+
let pX = P.monoms[0],
|
|
840
|
+
pC = P.monoms[P.monoms.length - 1],
|
|
841
|
+
dX = x.monoms[0],
|
|
842
|
+
dC = x.monoms[x.monoms.length - 1]
|
|
843
|
+
|
|
844
|
+
// Check last item (degree zero)
|
|
845
|
+
if (!pC.isDivisible(dC)) {
|
|
846
|
+
return false
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
// Check the first item (degree max)
|
|
850
|
+
if (!pX.isDivisible(dX)) {
|
|
851
|
+
return false
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
return true
|
|
855
|
+
})
|
|
856
|
+
}
|
|
857
|
+
}
|
|
808
858
|
}
|
|
809
|
-
|
|
810
|
-
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// Maybe there is still something in the Polynom (not everything was possible to factorize)
|
|
862
|
+
if (!P.isOne()) {
|
|
811
863
|
factors.push(P.clone())
|
|
812
|
-
P.one()
|
|
813
|
-
break
|
|
814
|
-
} else {
|
|
815
|
-
// Get the first and last monom and build all their dividers.
|
|
816
|
-
// let m1 = P.monoms[0].dividers,
|
|
817
|
-
// m2 = P.monoms[P.monoms.length - 1].dividers
|
|
818
|
-
|
|
819
|
-
// Create the list of all "potential" polynom dividers.
|
|
820
|
-
let allDividers: Polynom[] = this._getAllPotentialFactors(P, letter)
|
|
821
|
-
|
|
822
|
-
allDividers.every(div => {
|
|
823
|
-
result = P.euclidian(div)
|
|
824
|
-
if (result.reminder.isZero()) {
|
|
825
|
-
P = result.quotient.clone()
|
|
826
|
-
factors.push(div)
|
|
827
|
-
return false
|
|
828
|
-
}
|
|
829
|
-
return true
|
|
830
|
-
})
|
|
831
864
|
}
|
|
832
|
-
}
|
|
833
865
|
|
|
834
|
-
|
|
835
|
-
factors
|
|
866
|
+
// Save the factors
|
|
867
|
+
this._factors = factors
|
|
868
|
+
|
|
869
|
+
// The factors list is no more dirty
|
|
870
|
+
this.dirty_factors = false
|
|
836
871
|
}
|
|
837
872
|
|
|
838
|
-
this.
|
|
839
|
-
return factors;
|
|
873
|
+
return this._factors;
|
|
840
874
|
}
|
|
841
875
|
|
|
876
|
+
isDividableBy = (div: Polynom): boolean => {
|
|
877
|
+
// Quick evaluation.
|
|
878
|
+
if (div.degree().isOne()) {
|
|
879
|
+
let zero = div.getZeroes()[0]
|
|
880
|
+
|
|
881
|
+
if (zero.exact instanceof Fraction) {
|
|
882
|
+
return this.evaluate(zero.exact).isZero()
|
|
883
|
+
} else {
|
|
884
|
+
return false
|
|
885
|
+
}
|
|
886
|
+
} else {
|
|
887
|
+
this.euclidianCache[div.tex] = this.euclidian(div)
|
|
888
|
+
return this.euclidianCache[div.tex].reminder.isZero()
|
|
889
|
+
}
|
|
890
|
+
}
|
|
842
891
|
// TODO: get zeroes for more than first degree and for more than natural degrees
|
|
843
892
|
getZeroes = (): ISolution[] => {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
//
|
|
853
|
-
// switch (this.degree().value) {
|
|
854
|
-
// case 0:
|
|
855
|
-
// if (this._monoms[0].coefficient.value === 0) {
|
|
856
|
-
// return [{
|
|
857
|
-
// tex: '\\mathbb{R}',
|
|
858
|
-
// value: NaN,
|
|
859
|
-
// exact: false
|
|
860
|
-
// }];
|
|
861
|
-
// } else {
|
|
862
|
-
// return [{
|
|
863
|
-
// tex: '\\varnothing',
|
|
864
|
-
// value: NaN,
|
|
865
|
-
// exact: false
|
|
866
|
-
// }];
|
|
867
|
-
// }
|
|
868
|
-
// case 1:
|
|
869
|
-
// // There is only one monoms,
|
|
870
|
-
// if (this._monoms.length === 1) {
|
|
871
|
-
// return [{
|
|
872
|
-
// tex: '0',
|
|
873
|
-
// value: 0,
|
|
874
|
-
// exact: new Fraction().zero()
|
|
875
|
-
// }];
|
|
876
|
-
// } else {
|
|
877
|
-
// const P = this.clone().reduce().reorder();
|
|
878
|
-
// const coeff = P.monoms[1].coefficient.opposed().divide(P.monoms[0].coefficient)
|
|
879
|
-
// return [{
|
|
880
|
-
// tex: coeff.tex,
|
|
881
|
-
// value: coeff.value,
|
|
882
|
-
// exact: coeff
|
|
883
|
-
// }];
|
|
884
|
-
// }
|
|
885
|
-
// // TODO: Determine the zeros of an equation of second degree.
|
|
886
|
-
// //case 2:
|
|
887
|
-
// default:
|
|
888
|
-
// // Make sure the polynom is factorized.
|
|
889
|
-
// if (this._factors.length === 0) {
|
|
890
|
-
// this.factorize()
|
|
891
|
-
// }
|
|
892
|
-
//
|
|
893
|
-
// let zeroes:Fraction[] = [], zeroesAsTex = [];
|
|
894
|
-
// for (let P of this._factors) {
|
|
895
|
-
// if (P.degree().greater(2)) {
|
|
896
|
-
// // TODO: get zeroes of polynom with a degree greater than 2.
|
|
897
|
-
//
|
|
898
|
-
// } else if (P.degree().value === 2) {
|
|
899
|
-
// let A = P.monomByDegree(2).coefficient,
|
|
900
|
-
// B = P.monomByDegree(1).coefficient,
|
|
901
|
-
// C = P.monomByDegree(0).coefficient,
|
|
902
|
-
// D = B.clone().pow(2).subtract(A.clone().multiply(C).multiply(4));
|
|
903
|
-
//
|
|
904
|
-
// if (D.value > 0) {
|
|
905
|
-
// /*console.log('Two zeroes for ', P.tex); */
|
|
906
|
-
// let x1 = (-(B.value) + Math.sqrt(D.value)) / (2 * A.value),
|
|
907
|
-
// x2 = (-(B.value) - Math.sqrt(D.value)) / (2 * A.value);
|
|
908
|
-
//
|
|
909
|
-
// zeroes.push(new Fraction(x1.toFixed(3)).reduce());
|
|
910
|
-
// zeroes.push(new Fraction(x2.toFixed(3)).reduce());
|
|
911
|
-
// } else if (D.value === 0) {
|
|
912
|
-
// /*console.log('One zero for ', P.tex); */
|
|
913
|
-
// } else {
|
|
914
|
-
// console.log('No zero for ', P.tex);
|
|
915
|
-
// }
|
|
916
|
-
// } else {
|
|
917
|
-
// for (let z of P.getZeroes()) {
|
|
918
|
-
// // Check if the zero is already in the list.
|
|
919
|
-
// // if (z === false || z === true) {
|
|
920
|
-
// // continue;
|
|
921
|
-
// // }
|
|
922
|
-
// if (zeroesAsTex.indexOf(z.frac) === -1) {
|
|
923
|
-
// zeroes.push(z);
|
|
924
|
-
// zeroesAsTex.push(z.frac);
|
|
925
|
-
// }
|
|
926
|
-
// }
|
|
927
|
-
// }
|
|
928
|
-
// }
|
|
929
|
-
//
|
|
930
|
-
//
|
|
931
|
-
// return zeroes;
|
|
932
|
-
// }
|
|
933
|
-
// return Z;
|
|
893
|
+
if (this.dirty_zeroes) {
|
|
894
|
+
let equ = new Equation(this.clone(), 0)
|
|
895
|
+
equ.solve()
|
|
896
|
+
this._zeroes = equ.solutions
|
|
897
|
+
this.dirty_zeroes = false
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
return this._zeroes
|
|
934
901
|
};
|
|
935
902
|
|
|
936
903
|
// TODO: analyse the next functions to determine if they are useful or not...
|
|
@@ -1071,18 +1038,21 @@ export class Polynom {
|
|
|
1071
1038
|
return (new Fraction()).zero()
|
|
1072
1039
|
}
|
|
1073
1040
|
|
|
1074
|
-
private _getAllPotentialFactors = (P: Polynom, letter
|
|
1041
|
+
private _getAllPotentialFactors = (P: Polynom, maxDegree: number, letter: string): Polynom[] => {
|
|
1075
1042
|
let m1 = P.monoms[0].dividers,
|
|
1076
1043
|
m2 = P.monoms[P.monoms.length - 1].dividers
|
|
1077
1044
|
|
|
1078
1045
|
let allDividers: Polynom[] = []
|
|
1079
1046
|
m1.forEach(m1d => {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1047
|
+
// Get only polynom that has a degree less than a specific value
|
|
1048
|
+
if (m1d.degree(letter).leq(maxDegree)) {
|
|
1049
|
+
m2.forEach(m2d => {
|
|
1050
|
+
if (m1d.degree(letter).isNotEqual(m2d.degree(letter))) {
|
|
1051
|
+
allDividers.push(new Polynom(m1d, m2d))
|
|
1052
|
+
allDividers.push(new Polynom(m1d, m2d.clone().opposed()))
|
|
1053
|
+
}
|
|
1054
|
+
})
|
|
1055
|
+
}
|
|
1086
1056
|
})
|
|
1087
1057
|
|
|
1088
1058
|
return allDividers
|
|
@@ -1200,41 +1170,6 @@ export class Polynom {
|
|
|
1200
1170
|
}
|
|
1201
1171
|
|
|
1202
1172
|
return this
|
|
1203
|
-
/**
|
|
1204
|
-
let m1: Polynom;
|
|
1205
|
-
let m2: Polynom;
|
|
1206
|
-
|
|
1207
|
-
let stack: Polynom[] = [],
|
|
1208
|
-
previousToken: string = null,
|
|
1209
|
-
tempPolynom
|
|
1210
|
-
|
|
1211
|
-
for (const element of rpn) {
|
|
1212
|
-
if (element.tokenType === 'coefficient' || element.tokenType === 'variable') {
|
|
1213
|
-
tempPolynom = new Polynom().zero();
|
|
1214
|
-
tempPolynom.monoms = [new Monom(element.token)]
|
|
1215
|
-
stack.push(tempPolynom.clone())
|
|
1216
|
-
} else if (element.tokenType === 'operation') {
|
|
1217
|
-
m2 = (stack.pop()) || new Polynom().zero();
|
|
1218
|
-
m1 = (stack.pop()) || new Polynom().zero();
|
|
1219
|
-
switch (element.token) {
|
|
1220
|
-
case '+':
|
|
1221
|
-
stack.push(m1.add(m2))
|
|
1222
|
-
break;
|
|
1223
|
-
case '-':
|
|
1224
|
-
stack.push(m1.subtract(m2))
|
|
1225
|
-
break;
|
|
1226
|
-
case '*':
|
|
1227
|
-
stack.push(m1.multiply(m2))
|
|
1228
|
-
break;
|
|
1229
|
-
case '^':
|
|
1230
|
-
stack.push(m1.pow(+previousToken))
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
previousToken = element.token;
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
this._monoms = stack[0].monoms;
|
|
1237
|
-
return this;*/
|
|
1238
1173
|
}
|
|
1239
1174
|
|
|
1240
1175
|
private multiplyByPolynom = (P: Polynom): Polynom => {
|
|
@@ -1375,34 +1310,6 @@ export class Polynom {
|
|
|
1375
1310
|
}
|
|
1376
1311
|
|
|
1377
1312
|
return [this.clone()]
|
|
1378
|
-
//
|
|
1379
|
-
// console.log(a.tex, b.tex, c.tex)
|
|
1380
|
-
// if (a.isSquare() && c.isSquare()) {
|
|
1381
|
-
// console.log('A C squares')
|
|
1382
|
-
// if (a.clone().sqrt().multiply(c.clone().sqrt()).multiplyByNumber(2).isSameAs(b)) {
|
|
1383
|
-
// console.log('HERE')
|
|
1384
|
-
// if (a.coefficient.sign() === b.coefficient.sign()) {
|
|
1385
|
-
// return []
|
|
1386
|
-
// }else{
|
|
1387
|
-
// return []
|
|
1388
|
-
// }
|
|
1389
|
-
// }
|
|
1390
|
-
// } else if(a.isLiteralSquare() && c.isLiteralSquare()) {
|
|
1391
|
-
// console.log('A C litteral SQUARES')
|
|
1392
|
-
// // Check that the middle element is the product of a and c.
|
|
1393
|
-
//
|
|
1394
|
-
// if(b.clone().pow(2).isSameAs(a.clone().multiply(c))){
|
|
1395
|
-
// console.log('SAME')
|
|
1396
|
-
//
|
|
1397
|
-
// }else{
|
|
1398
|
-
// console.log('NOT SAME')
|
|
1399
|
-
// }
|
|
1400
|
-
//
|
|
1401
|
-
// return [this.clone()]
|
|
1402
|
-
// } else {
|
|
1403
|
-
// console.log('NOT SQUARES AT ALL !!!!')
|
|
1404
|
-
// }
|
|
1405
|
-
|
|
1406
1313
|
}
|
|
1407
1314
|
}
|
|
1408
1315
|
|