pimath 0.0.124 → 0.0.126
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/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +192 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +4 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +2404 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +4 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +1362 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +4 -0
- package/dev/pimath.js +7940 -7930
- package/dev/pimath.js.map +1 -1
- package/dist/pimath.js +219 -227
- package/dist/pimath.js.map +1 -1
- package/dist/pimath.min.js +1 -1
- package/dist/pimath.min.js.map +1 -1
- package/docs/assets/main.js +59 -58
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1383 -1367
- package/docs/classes/Logicalset.Logicalset.html +217 -221
- package/docs/classes/Polynom.Rational.html +397 -391
- package/docs/classes/Vector-1.Vector.html +490 -494
- package/docs/classes/Vector.Point.html +337 -341
- package/docs/classes/algebra_equation.Equation.html +790 -796
- package/docs/classes/algebra_linearSystem.LinearSystem.html +404 -408
- package/docs/classes/algebra_monom.Monom.html +962 -967
- package/docs/classes/algebra_polynom.Polynom.html +1275 -1281
- package/docs/classes/coefficients_fraction.Fraction.html +934 -939
- package/docs/classes/geometry_circle.Circle.html +472 -476
- package/docs/classes/geometry_line.Line.html +774 -779
- package/docs/classes/geometry_triangle.Triangle.html +429 -429
- package/docs/classes/numeric.Numeric.html +265 -269
- package/docs/classes/shutingyard.Shutingyard.html +250 -259
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +83 -89
- package/docs/enums/geometry_line.LinePropriety.html +97 -102
- package/docs/enums/shutingyard.ShutingyardMode.html +97 -106
- package/docs/enums/shutingyard.ShutingyardType.html +111 -120
- package/docs/index.html +63 -63
- package/docs/interfaces/algebra_equation.ISolution.html +105 -111
- package/docs/interfaces/algebra_polynom.IEuclidian.html +87 -93
- package/docs/interfaces/geometry_triangle.remarquableLines.html +163 -150
- package/docs/modules/Logicalset.html +65 -69
- package/docs/modules/Polynom.html +65 -69
- package/docs/modules/Vector-1.html +65 -69
- package/docs/modules/Vector.html +65 -69
- package/docs/modules/algebra_equation.html +69 -75
- package/docs/modules/algebra_linearSystem.html +61 -65
- package/docs/modules/algebra_monom.html +65 -70
- package/docs/modules/algebra_polynom.html +69 -75
- package/docs/modules/coefficients_fraction.html +65 -70
- package/docs/modules/geometry_circle.html +61 -65
- package/docs/modules/geometry_line.html +65 -70
- package/docs/modules/geometry_triangle.html +65 -70
- package/docs/modules/numeric.html +61 -65
- package/docs/modules/shutingyard.html +75 -84
- package/docs/types/algebra_monom.literalType.html +61 -66
- package/docs/types/algebra_polynom.PolynomParsingType.html +56 -62
- package/docs/types/coefficients_fraction.FractionParsingType.html +56 -61
- package/docs/types/shutingyard.Token.html +63 -72
- package/docs/types/shutingyard.tokenType.html +68 -77
- package/docs/variables/shutingyard.tokenConstant.html +61 -70
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +19 -19
- package/esm/maths/algebra/monom.js +66 -66
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +14 -14
- package/esm/maths/algebra/polynom.js +72 -50
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/numeric.js +3 -48
- package/esm/maths/numeric.js.map +1 -1
- package/esm/maths/randomization/random.d.ts +1 -1
- package/esm/maths/randomization/random.js +2 -2
- package/esm/maths/randomization/random.js.map +1 -1
- package/esm/maths/randomization/rndHelpers.d.ts +1 -1
- package/esm/maths/randomization/rndHelpers.js +25 -4
- package/esm/maths/randomization/rndHelpers.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/maths/algebra/monom.ts +138 -130
- package/src/maths/algebra/polynom.ts +107 -85
- package/src/maths/numeric.ts +61 -90
- package/src/maths/randomization/random.ts +2 -2
- package/src/maths/randomization/rndHelpers.ts +49 -18
- package/tests/algebra/linear.test.ts +1 -1
- package/tests/algebra/polynom.test.ts +152 -1
- package/tests/algebra/study.test.ts +1 -0
- package/tests/geometry/circle.test.ts +124 -25
- package/tests/geometry/line.test.ts +8 -17
- package/tests/numexp.test.ts +10 -2
- package/esm/maths/expressions/ExpressionTree.d.ts +0 -17
- package/esm/maths/expressions/ExpressionTree.js +0 -150
- package/esm/maths/expressions/ExpressionTree.js.map +0 -1
- package/esm/maths/expressions/expression.d.ts +0 -27
- package/esm/maths/expressions/expression.js +0 -239
- package/esm/maths/expressions/expression.js.map +0 -1
- package/esm/maths/expressions/expressionFactor.d.ts +0 -36
- package/esm/maths/expressions/expressionFactor.js +0 -156
- package/esm/maths/expressions/expressionFactor.js.map +0 -1
- package/esm/maths/expressions/expressionMember.d.ts +0 -27
- package/esm/maths/expressions/expressionMember.js +0 -199
- package/esm/maths/expressions/expressionMember.js.map +0 -1
- package/esm/maths/expressions/expressionOperators.d.ts +0 -8
- package/esm/maths/expressions/expressionOperators.js +0 -42
- package/esm/maths/expressions/expressionOperators.js.map +0 -1
- package/esm/maths/expressions/expressionParser.d.ts +0 -14
- package/esm/maths/expressions/expressionParser.js +0 -259
- package/esm/maths/expressions/expressionParser.js.map +0 -1
- package/esm/maths/expressions/factors/ExpFactor.d.ts +0 -7
- package/esm/maths/expressions/factors/ExpFactor.js +0 -34
- package/esm/maths/expressions/factors/ExpFactor.js.map +0 -1
- package/esm/maths/expressions/factors/ExpFactorConstant.d.ts +0 -14
- package/esm/maths/expressions/factors/ExpFactorConstant.js +0 -52
- package/esm/maths/expressions/factors/ExpFactorConstant.js.map +0 -1
- package/esm/maths/expressions/factors/ExpFactorExponential.d.ts +0 -8
- package/esm/maths/expressions/factors/ExpFactorExponential.js +0 -22
- package/esm/maths/expressions/factors/ExpFactorExponential.js.map +0 -1
- package/esm/maths/expressions/factors/ExpFactorNumber.d.ts +0 -14
- package/esm/maths/expressions/factors/ExpFactorNumber.js +0 -59
- package/esm/maths/expressions/factors/ExpFactorNumber.js.map +0 -1
- package/esm/maths/expressions/factors/ExpFactorPower.d.ts +0 -13
- package/esm/maths/expressions/factors/ExpFactorPower.js +0 -35
- package/esm/maths/expressions/factors/ExpFactorPower.js.map +0 -1
- package/esm/maths/expressions/factors/ExpFactorTrigo.d.ts +0 -20
- package/esm/maths/expressions/factors/ExpFactorTrigo.js +0 -48
- package/esm/maths/expressions/factors/ExpFactorTrigo.js.map +0 -1
- package/esm/maths/expressions/factors/ExpFactorVariable.d.ts +0 -13
- package/esm/maths/expressions/factors/ExpFactorVariable.js +0 -36
- package/esm/maths/expressions/factors/ExpFactorVariable.js.map +0 -1
- package/esm/maths/expressions/internals.d.ts +0 -12
- package/esm/maths/expressions/internals.js +0 -29
- package/esm/maths/expressions/internals.js.map +0 -1
- package/esm/maths/expressions/numexp.d.ts +0 -19
- package/esm/maths/expressions/numexp.js +0 -186
- package/esm/maths/expressions/numexp.js.map +0 -1
- package/esm/maths/expressions/polynomexp.bkp.d.ts +0 -33
- package/esm/maths/expressions/polynomexp.bkp.js +0 -184
- package/esm/maths/expressions/polynomexp.bkp.js.map +0 -1
- package/esm/maths/expressions/polynomexp.d.ts +0 -52
- package/esm/maths/expressions/polynomexp.js +0 -246
- package/esm/maths/expressions/polynomexp.js.map +0 -1
|
@@ -10,9 +10,6 @@ export type literalType = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class Monom {
|
|
13
|
-
private _coefficient: Fraction;
|
|
14
|
-
private _literal: literalType;
|
|
15
|
-
|
|
16
13
|
/**
|
|
17
14
|
* Create a Monom
|
|
18
15
|
* Defined as \\(k \\cdot x^{n}\\), where \\( k,n \in \\mathbb{Q}\\).
|
|
@@ -30,8 +27,8 @@ export class Monom {
|
|
|
30
27
|
return this;
|
|
31
28
|
}
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
private _coefficient: Fraction;
|
|
31
|
+
|
|
35
32
|
// ------------------------------------------
|
|
36
33
|
/**
|
|
37
34
|
* Get the coefficient \\(k\\) of the Monom \\(k\\cdot x^{n}\\)
|
|
@@ -41,6 +38,9 @@ export class Monom {
|
|
|
41
38
|
return this._coefficient;
|
|
42
39
|
}
|
|
43
40
|
|
|
41
|
+
// ------------------------------------------
|
|
42
|
+
// Getter and setter
|
|
43
|
+
|
|
44
44
|
/**
|
|
45
45
|
* Set the coefficient \\(k\\) value of the monom
|
|
46
46
|
* @param {Fraction | number | string} F
|
|
@@ -49,6 +49,8 @@ export class Monom {
|
|
|
49
49
|
this._coefficient = new Fraction(F);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
private _literal: literalType;
|
|
53
|
+
|
|
52
54
|
/**
|
|
53
55
|
* Get the literal part of \\(x^{n_1}y^{n_2}\\) as dictionary \\[\\begin{array}{ll}x&=n_1\\\\y&=n_2\\end{array}\\]
|
|
54
56
|
* @returns {literalType}
|
|
@@ -57,6 +59,14 @@ export class Monom {
|
|
|
57
59
|
return this._literal;
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Set the literal part of the monom. Must be a dictionary {x: Fraction, y: Fraction, ...}
|
|
64
|
+
* @param {literalType} L
|
|
65
|
+
*/
|
|
66
|
+
set literal(L: literalType) {
|
|
67
|
+
this._literal = L;
|
|
68
|
+
}
|
|
69
|
+
|
|
60
70
|
/**
|
|
61
71
|
* Get the literal square roots of the Monom.
|
|
62
72
|
* TODO: remove this getter ? Is it used and is it correct ?
|
|
@@ -74,14 +84,6 @@ export class Monom {
|
|
|
74
84
|
}
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
/**
|
|
78
|
-
* Set the literal part of the monom. Must be a dictionary {x: Fraction, y: Fraction, ...}
|
|
79
|
-
* @param {literalType} L
|
|
80
|
-
*/
|
|
81
|
-
set literal(L: literalType) {
|
|
82
|
-
this._literal = L;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
87
|
/**
|
|
86
88
|
* Set the literal part of the monom from a string
|
|
87
89
|
* @param inputStr String like x^2y^3
|
|
@@ -212,29 +214,6 @@ export class Monom {
|
|
|
212
214
|
return monomDividers.length === 0 ? [new Monom().one()] : monomDividers;
|
|
213
215
|
}
|
|
214
216
|
|
|
215
|
-
private _getLiteralDividers(arr: literalType[], letter: string): literalType[] {
|
|
216
|
-
let tmpList: { [key: string]: Fraction }[] = [];
|
|
217
|
-
|
|
218
|
-
// Be default, this.literal[letter] should be a rational number.
|
|
219
|
-
for (let d = 0; d <= this.literal[letter].value; d++) {
|
|
220
|
-
if (arr.length === 0) {
|
|
221
|
-
let litt: literalType = {}
|
|
222
|
-
litt[letter] = new Fraction(d)
|
|
223
|
-
tmpList.push(litt)
|
|
224
|
-
} else {
|
|
225
|
-
for (let item of arr) {
|
|
226
|
-
let litt: literalType = {}
|
|
227
|
-
for (let currentLetter in item) {
|
|
228
|
-
litt[currentLetter] = item[currentLetter]
|
|
229
|
-
}
|
|
230
|
-
litt[letter] = new Fraction(d)
|
|
231
|
-
tmpList.push(litt)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return tmpList;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
217
|
/**
|
|
239
218
|
* Display the monom, forcing the '+' sign to appear
|
|
240
219
|
*/
|
|
@@ -258,7 +237,7 @@ export class Monom {
|
|
|
258
237
|
|
|
259
238
|
for (let letter of letters) {
|
|
260
239
|
if (this._literal[letter].isNotZero()) {
|
|
261
|
-
L += (L===''?"":"*") + `${letter}`
|
|
240
|
+
L += (L === '' ? "" : "*") + `${letter}`
|
|
262
241
|
if (this._literal[letter].isNotEqual(1)) {
|
|
263
242
|
L += `^(${this._literal[letter].display})`;
|
|
264
243
|
}
|
|
@@ -323,8 +302,65 @@ export class Monom {
|
|
|
323
302
|
}
|
|
324
303
|
}
|
|
325
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Get the least common multiple of monoms
|
|
307
|
+
* @param monoms Array of monoms
|
|
308
|
+
*/
|
|
309
|
+
static lcm = (...monoms: Monom[]): Monom => {
|
|
310
|
+
// All the monoms must be with natural powers...
|
|
311
|
+
for (let m of monoms) {
|
|
312
|
+
if (m.hasFractionCoefficient()) {
|
|
313
|
+
return new Monom().zero()
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
let M = new Monom(),
|
|
319
|
+
coeffN: number[] = monoms.map(value => value.coefficient.numerator),
|
|
320
|
+
coeffD: number[] = monoms.map(value => value.coefficient.denominator),
|
|
321
|
+
n = Numeric.gcd(...coeffN),
|
|
322
|
+
d = Numeric.lcm(...coeffD);
|
|
323
|
+
|
|
324
|
+
// Get the coefficient.
|
|
325
|
+
M.coefficient = new Fraction(n, d).reduce();
|
|
326
|
+
|
|
327
|
+
// Set the literal parts - go through each monoms literal parts and get only the lowest degree of each letters.
|
|
328
|
+
for (let m of monoms) {
|
|
329
|
+
// Remove the inexistant letters from the resulting monom
|
|
330
|
+
for (let letter in M.literal) {
|
|
331
|
+
if (!(letter in m.literal)) {
|
|
332
|
+
M.literal[letter].zero();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (let letter in m.literal) {
|
|
336
|
+
if (M.literal[letter] === undefined && m.literal[letter].isStrictlyPositive()) {
|
|
337
|
+
M.literal[letter] = m.literal[letter].clone();
|
|
338
|
+
} else {
|
|
339
|
+
M.literal[letter] = new Fraction(Math.min(m.literal[letter].value, M.literal[letter].value))
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return M;
|
|
345
|
+
};
|
|
346
|
+
|
|
326
347
|
// ------------------------------------------
|
|
327
348
|
// Creation / parsing functions
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Multiply two monoms and return a NEW monom.
|
|
352
|
+
* @param monoms
|
|
353
|
+
*/
|
|
354
|
+
static xmultiply = (...monoms: Monom[]): Monom => {
|
|
355
|
+
let M = new Monom().one();
|
|
356
|
+
|
|
357
|
+
for (let m of monoms) {
|
|
358
|
+
M.multiply(m);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return M;
|
|
362
|
+
};
|
|
363
|
+
|
|
328
364
|
// -----------------------------------------
|
|
329
365
|
/**
|
|
330
366
|
* Parse a string to a monom. The string may include fraction.
|
|
@@ -401,37 +437,7 @@ export class Monom {
|
|
|
401
437
|
}
|
|
402
438
|
}
|
|
403
439
|
}
|
|
404
|
-
private _shutingYardToReducedMonom = (inputStr: string): Monom => {
|
|
405
|
-
// Get the RPN array of the current expression
|
|
406
|
-
const SY: Shutingyard = new Shutingyard().parse(inputStr);
|
|
407
|
-
const rpn: { token: string, tokenType: string }[] = SY.rpn;
|
|
408
440
|
|
|
409
|
-
let stack: Monom[] = [], m, pow, letter, q1, q2
|
|
410
|
-
|
|
411
|
-
if (rpn.length === 0) {
|
|
412
|
-
this.zero()
|
|
413
|
-
return this
|
|
414
|
-
} else if (rpn.length === 1) {
|
|
415
|
-
const element = rpn[0]
|
|
416
|
-
|
|
417
|
-
this.one()
|
|
418
|
-
if (element.tokenType === 'coefficient') {
|
|
419
|
-
this.coefficient = new Fraction(element.token)
|
|
420
|
-
} else if (element.tokenType === 'variable') {
|
|
421
|
-
this.setLetter(element.token, 1)
|
|
422
|
-
}
|
|
423
|
-
return this
|
|
424
|
-
} else {
|
|
425
|
-
// Reset the monom
|
|
426
|
-
for (const element of rpn) {
|
|
427
|
-
this.addToken(stack, element)
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
this.one()
|
|
432
|
-
this.multiply(stack[0])
|
|
433
|
-
return this
|
|
434
|
-
}
|
|
435
441
|
/**
|
|
436
442
|
* Clone the current Monom.
|
|
437
443
|
*/
|
|
@@ -603,7 +609,7 @@ export class Monom {
|
|
|
603
609
|
* Get the pow of a monom.
|
|
604
610
|
* @param nb (number) : Mathematical pow
|
|
605
611
|
*/
|
|
606
|
-
pow = (nb: number|Fraction): Monom => {
|
|
612
|
+
pow = (nb: number | Fraction): Monom => {
|
|
607
613
|
this._coefficient.pow(nb);
|
|
608
614
|
for (let letter in this._literal) {
|
|
609
615
|
this._literal[letter].multiply(nb)
|
|
@@ -658,7 +664,9 @@ export class Monom {
|
|
|
658
664
|
M2: string[] = M.variables,
|
|
659
665
|
K: string[] = M1.concat(M2.filter((item) => M1.indexOf(item) < 0));
|
|
660
666
|
|
|
661
|
-
if(M1.length===0 && M2.length===0){
|
|
667
|
+
if (M1.length === 0 && M2.length === 0) {
|
|
668
|
+
return true
|
|
669
|
+
}
|
|
662
670
|
// To compare, both must be different than zero.
|
|
663
671
|
if (!this.isZero() && !M.isZero()) {
|
|
664
672
|
for (let key of K) {
|
|
@@ -808,7 +816,7 @@ export class Monom {
|
|
|
808
816
|
}
|
|
809
817
|
|
|
810
818
|
if (typeof values === 'object') {
|
|
811
|
-
if(this.variables.length===0){
|
|
819
|
+
if (this.variables.length === 0) {
|
|
812
820
|
return this.coefficient
|
|
813
821
|
}
|
|
814
822
|
for (let L in this._literal) {
|
|
@@ -904,63 +912,6 @@ export class Monom {
|
|
|
904
912
|
// Static functions
|
|
905
913
|
// ----------------------------------------
|
|
906
914
|
|
|
907
|
-
/**
|
|
908
|
-
* Get the least common multiple of monoms
|
|
909
|
-
* @param monoms Array of monoms
|
|
910
|
-
*/
|
|
911
|
-
static lcm = (...monoms: Monom[]): Monom => {
|
|
912
|
-
// All the monoms must be with natural powers...
|
|
913
|
-
for (let m of monoms) {
|
|
914
|
-
if (m.hasFractionCoefficient()) {
|
|
915
|
-
return new Monom().zero()
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
let M = new Monom(),
|
|
921
|
-
coeffN: number[] = monoms.map(value => value.coefficient.numerator),
|
|
922
|
-
coeffD: number[] = monoms.map(value => value.coefficient.denominator),
|
|
923
|
-
n = Numeric.gcd(...coeffN),
|
|
924
|
-
d = Numeric.lcm(...coeffD);
|
|
925
|
-
|
|
926
|
-
// Get the coefficient.
|
|
927
|
-
M.coefficient = new Fraction(n, d).reduce();
|
|
928
|
-
|
|
929
|
-
// Set the literal parts - go through each monoms literal parts and get only the lowest degree of each letters.
|
|
930
|
-
for (let m of monoms) {
|
|
931
|
-
// Remove the inexistant letters from the resulting monom
|
|
932
|
-
for (let letter in M.literal) {
|
|
933
|
-
if (!(letter in m.literal)) {
|
|
934
|
-
M.literal[letter].zero();
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
for (let letter in m.literal) {
|
|
938
|
-
if (M.literal[letter] === undefined && m.literal[letter].isStrictlyPositive()) {
|
|
939
|
-
M.literal[letter] = m.literal[letter].clone();
|
|
940
|
-
} else {
|
|
941
|
-
M.literal[letter] = new Fraction(Math.min(m.literal[letter].value, M.literal[letter].value))
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
return M;
|
|
947
|
-
};
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* Multiply two monoms and return a NEW monom.
|
|
951
|
-
* @param monoms
|
|
952
|
-
*/
|
|
953
|
-
static xmultiply = (...monoms: Monom[]): Monom => {
|
|
954
|
-
let M = new Monom().one();
|
|
955
|
-
|
|
956
|
-
for (let m of monoms) {
|
|
957
|
-
M.multiply(m);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
return M;
|
|
961
|
-
};
|
|
962
|
-
|
|
963
|
-
|
|
964
915
|
// TODO: The rest of the functions are not used or unnecessary ?
|
|
965
916
|
/**
|
|
966
917
|
* Determine if multiple monoms are similar
|
|
@@ -1001,9 +952,9 @@ export class Monom {
|
|
|
1001
952
|
return true;
|
|
1002
953
|
};
|
|
1003
954
|
|
|
1004
|
-
isDivisible = (div:Monom):boolean => {
|
|
955
|
+
isDivisible = (div: Monom): boolean => {
|
|
1005
956
|
// For all variables (letters), the current monom must have a degree higher than the divider
|
|
1006
|
-
if(div.degree().isStrictlyPositive()) {
|
|
957
|
+
if (div.degree().isStrictlyPositive()) {
|
|
1007
958
|
for (let letter of div.variables) {
|
|
1008
959
|
if (!this.degree(letter).geq(div.degree(letter))) {
|
|
1009
960
|
return false
|
|
@@ -1012,9 +963,66 @@ export class Monom {
|
|
|
1012
963
|
}
|
|
1013
964
|
|
|
1014
965
|
// If the coefficient is rational, we suppose we don't need to check the division by the coefficient.
|
|
1015
|
-
if(this.coefficient.isRational() || div.coefficient.isRational()){
|
|
966
|
+
if (this.coefficient.isRational() || div.coefficient.isRational()) {
|
|
967
|
+
return true
|
|
968
|
+
}
|
|
1016
969
|
|
|
1017
970
|
return this.coefficient.clone().divide(div.coefficient).isRelative()
|
|
1018
971
|
}
|
|
1019
972
|
|
|
973
|
+
private _getLiteralDividers(arr: literalType[], letter: string): literalType[] {
|
|
974
|
+
let tmpList: { [key: string]: Fraction }[] = [];
|
|
975
|
+
|
|
976
|
+
// Be default, this.literal[letter] should be a rational number.
|
|
977
|
+
for (let d = 0; d <= this.literal[letter].value; d++) {
|
|
978
|
+
if (arr.length === 0) {
|
|
979
|
+
let litt: literalType = {}
|
|
980
|
+
litt[letter] = new Fraction(d)
|
|
981
|
+
tmpList.push(litt)
|
|
982
|
+
} else {
|
|
983
|
+
for (let item of arr) {
|
|
984
|
+
let litt: literalType = {}
|
|
985
|
+
for (let currentLetter in item) {
|
|
986
|
+
litt[currentLetter] = item[currentLetter]
|
|
987
|
+
}
|
|
988
|
+
litt[letter] = new Fraction(d)
|
|
989
|
+
tmpList.push(litt)
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return tmpList;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
private _shutingYardToReducedMonom = (inputStr: string): Monom => {
|
|
997
|
+
// Get the RPN array of the current expression
|
|
998
|
+
const SY: Shutingyard = new Shutingyard().parse(inputStr);
|
|
999
|
+
const rpn: { token: string, tokenType: string }[] = SY.rpn;
|
|
1000
|
+
|
|
1001
|
+
let stack: Monom[] = [], m, pow, letter, q1, q2
|
|
1002
|
+
|
|
1003
|
+
if (rpn.length === 0) {
|
|
1004
|
+
this.zero()
|
|
1005
|
+
return this
|
|
1006
|
+
} else if (rpn.length === 1) {
|
|
1007
|
+
const element = rpn[0]
|
|
1008
|
+
|
|
1009
|
+
this.one()
|
|
1010
|
+
if (element.tokenType === 'coefficient') {
|
|
1011
|
+
this.coefficient = new Fraction(element.token)
|
|
1012
|
+
} else if (element.tokenType === 'variable') {
|
|
1013
|
+
this.setLetter(element.token, 1)
|
|
1014
|
+
}
|
|
1015
|
+
return this
|
|
1016
|
+
} else {
|
|
1017
|
+
// Reset the monom
|
|
1018
|
+
for (const element of rpn) {
|
|
1019
|
+
this.addToken(stack, element)
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
this.one()
|
|
1024
|
+
this.multiply(stack[0])
|
|
1025
|
+
return this
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1020
1028
|
}
|