pimath 0.0.22 → 0.0.26

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.
Files changed (110) hide show
  1. package/dev/demo.css +3 -0
  2. package/dev/index.html +216 -53
  3. package/dev/pi.js +356 -126
  4. package/dev/pi.js.map +1 -1
  5. package/dist/pi.js +1 -1
  6. package/dist/pi.js.map +1 -1
  7. package/docs/assets/search.js +1 -1
  8. package/docs/classes/algebra.Equation.html +11 -13
  9. package/docs/classes/algebra.LinearSystem.html +1 -1
  10. package/docs/classes/algebra.Logicalset.html +3 -3
  11. package/docs/classes/algebra.Monom.html +42 -42
  12. package/docs/classes/algebra.Polynom.html +12 -25
  13. package/docs/classes/algebra.Rational.html +3 -3
  14. package/docs/classes/coefficients.Fraction.html +10 -6
  15. package/docs/classes/coefficients.Nthroot.html +3 -1
  16. package/docs/classes/geometry.Circle.html +3 -1
  17. package/docs/classes/geometry.Line.html +3 -1
  18. package/docs/classes/geometry.Point.html +1 -1
  19. package/docs/classes/geometry.Triangle.html +6 -6
  20. package/docs/classes/geometry.Vector.html +1 -1
  21. package/docs/classes/numeric.Numeric.html +5 -5
  22. package/docs/classes/shutingyard.Shutingyard.html +5 -5
  23. package/docs/index.html +1 -1
  24. package/docs/interfaces/geometry.remarquableLines.html +1 -1
  25. package/docs/modules/algebra.html +1 -1
  26. package/docs/modules/coefficients.html +1 -1
  27. package/docs/modules/geometry.html +1 -1
  28. package/docs/modules/numeric.html +1 -1
  29. package/docs/modules/random.Random.html +1 -1
  30. package/docs/modules/random.html +1 -1
  31. package/docs/modules/shutingyard.html +1 -1
  32. package/docs/modules.html +1 -1
  33. package/esm/maths/algebra/equation.d.ts +11 -5
  34. package/esm/maths/algebra/equation.js +159 -52
  35. package/esm/maths/algebra/equation.js.map +1 -1
  36. package/esm/maths/algebra/linearSystem.d.ts +3 -4
  37. package/esm/maths/algebra/linearSystem.js +2 -5
  38. package/esm/maths/algebra/linearSystem.js.map +1 -1
  39. package/esm/maths/algebra/logicalset.d.ts +2 -2
  40. package/esm/maths/algebra/logicalset.js.map +1 -1
  41. package/esm/maths/algebra/monom.d.ts +3 -2
  42. package/esm/maths/algebra/monom.js +22 -1
  43. package/esm/maths/algebra/monom.js.map +1 -1
  44. package/esm/maths/algebra/polynom.d.ts +6 -6
  45. package/esm/maths/algebra/polynom.js +4 -4
  46. package/esm/maths/algebra/polynom.js.map +1 -1
  47. package/esm/maths/coefficients/fraction.d.ts +2 -2
  48. package/esm/maths/coefficients/fraction.js +1 -1
  49. package/esm/maths/coefficients/fraction.js.map +1 -1
  50. package/esm/maths/coefficients/nthroot.d.ts +1 -1
  51. package/esm/maths/coefficients/nthroot.js +4 -1
  52. package/esm/maths/coefficients/nthroot.js.map +1 -1
  53. package/esm/maths/geometry/circle.d.ts +12 -3
  54. package/esm/maths/geometry/circle.js +125 -39
  55. package/esm/maths/geometry/circle.js.map +1 -1
  56. package/esm/maths/geometry/line.d.ts +1 -2
  57. package/esm/maths/geometry/line.js +3 -5
  58. package/esm/maths/geometry/line.js.map +1 -1
  59. package/esm/maths/geometry/point.d.ts +3 -4
  60. package/esm/maths/geometry/point.js +18 -15
  61. package/esm/maths/geometry/point.js.map +1 -1
  62. package/esm/maths/geometry/triangle.d.ts +0 -1
  63. package/esm/maths/geometry/triangle.js +3 -4
  64. package/esm/maths/geometry/triangle.js.map +1 -1
  65. package/esm/maths/geometry/vector.js +2 -1
  66. package/esm/maths/geometry/vector.js.map +1 -1
  67. package/esm/maths/random/rndFraction.js +4 -3
  68. package/esm/maths/random/rndFraction.js.map +1 -1
  69. package/esm/maths/random/rndMonom.d.ts +1 -1
  70. package/esm/maths/random/rndMonom.js +12 -7
  71. package/esm/maths/random/rndMonom.js.map +1 -1
  72. package/esm/maths/random/rndPolynom.js +8 -2
  73. package/esm/maths/random/rndPolynom.js.map +1 -1
  74. package/esm/maths/random/rndTypes.d.ts +3 -1
  75. package/package.json +3 -5
  76. package/src/maths/algebra/equation.ts +183 -73
  77. package/src/maths/algebra/linearSystem.ts +262 -265
  78. package/src/maths/algebra/logicalset.ts +1 -1
  79. package/src/maths/algebra/monom.ts +24 -18
  80. package/src/maths/algebra/polynom.ts +10 -10
  81. package/src/maths/coefficients/fraction.ts +11 -7
  82. package/src/maths/coefficients/nthroot.ts +8 -1
  83. package/src/maths/geometry/circle.ts +160 -45
  84. package/src/maths/geometry/line.ts +8 -10
  85. package/src/maths/geometry/point.ts +25 -18
  86. package/src/maths/geometry/triangle.ts +3 -5
  87. package/src/maths/geometry/vector.ts +4 -3
  88. package/src/maths/random/rndFraction.ts +4 -3
  89. package/src/maths/random/rndMonom.ts +39 -35
  90. package/src/maths/random/rndPolynom.ts +13 -3
  91. package/src/maths/random/rndTypes.ts +4 -2
  92. package/tests/algebra/monom.test.ts +18 -4
  93. package/tests/algebra/polynom.test.ts +19 -4
  94. package/tests/geometry/circle.test.ts +28 -0
  95. package/tsconfig.json +4 -1
  96. package/typedoc.katex.js +11 -0
  97. package/docs/classes/algebra.Algebra.Equation.html +0 -26
  98. package/docs/classes/algebra.Algebra.LinearSystem.html +0 -1
  99. package/docs/classes/algebra.Algebra.LogicalSet.html +0 -3
  100. package/docs/classes/algebra.Algebra.Monom.html +0 -111
  101. package/docs/classes/algebra.Algebra.Polynom.html +0 -36
  102. package/docs/classes/algebra.Algebra.Rational.html +0 -2
  103. package/docs/classes/geometry.Geometry.Circle.html +0 -1
  104. package/docs/classes/geometry.Geometry.Line.html +0 -1
  105. package/docs/classes/geometry.Geometry.Point.html +0 -1
  106. package/docs/classes/geometry.Geometry.Triangle.html +0 -9
  107. package/docs/classes/geometry.Geometry.Vector.html +0 -1
  108. package/docs/modules/algebra.Algebra.html +0 -1
  109. package/docs/modules/geometry.Geometry.html +0 -1
  110. package/src/maths/algebra/monom_bck.backup +0 -746
@@ -4,334 +4,331 @@ import {Polynom} from "./polynom";
4
4
  import {Monom} from "./monom";
5
5
  import {Random} from "../random";
6
6
 
7
- export class LinearSystem {
8
- private _solutions: { [letter: string]: { value: Fraction, isReal: boolean, isVarnothing: boolean } };
9
- private _resolutionSteps: LinearSystem[];
10
- private _equations: Equation[];
11
- private _letters: string[];
12
-
13
- constructor(...equationStrings: string[]) {
14
- this._equations = [];
15
- this._letters = 'xy'.split('');
16
-
17
- if (equationStrings !== undefined && equationStrings.length > 0) {
18
- this.parse(...equationStrings);
19
- }
20
-
21
- return this;
7
+ // TODO: Must check and rework
8
+ export class LinearSystem {
9
+ private _solutions: { [letter: string]: { value: Fraction, isReal: boolean, isVarnothing: boolean } };
10
+ private _resolutionSteps: LinearSystem[];
11
+ private _equations: Equation[];
12
+ private _letters: string[];
13
+
14
+ constructor(...equationStrings: string[]) {
15
+ this._equations = [];
16
+ this._letters = 'xy'.split('');
17
+
18
+ if (equationStrings !== undefined && equationStrings.length > 0) {
19
+ this.parse(...equationStrings);
22
20
  }
23
21
 
24
- get isLinearSystem() {
25
- return true;
26
- }
22
+ return this;
23
+ }
27
24
 
28
- // ------------------------------------------
29
- // Getter and setter
30
- // ------------------------------------------
31
- get equations(): Equation[] {
32
- return this._equations;
33
- }
25
+ // ------------------------------------------
26
+ // Getter and setter
27
+ // ------------------------------------------
28
+ get equations(): Equation[] {
29
+ return this._equations;
30
+ }
34
31
 
35
- set equations(value) {
36
- this._equations = value;
37
- }
32
+ set equations(value) {
33
+ this._equations = value;
34
+ }
38
35
 
39
- get letters(): string {
40
- return this._letters.join('')
41
- }
36
+ get letters(): string {
37
+ return this._letters.join('')
38
+ }
42
39
 
43
- set letters(value: string) {
44
- this._letters = value.split('');
45
- }
40
+ set letters(value: string) {
41
+ this._letters = value.split('');
42
+ }
46
43
 
47
- get isSolvable(): boolean {
48
- let V = this.variables;
44
+ get isSolvable(): boolean {
45
+ let V = this.variables;
49
46
 
50
- // TODO: in some case, it is possible to resolve systems if there isn't the isSame number of vars and equations
51
- if (V.length !== this._equations.length) {
52
- return false;
53
- }
47
+ // TODO: in some case, it is possible to resolve systems if there isn't the isSame number of vars and equations
48
+ if (V.length !== this._equations.length) {
49
+ return false;
50
+ }
54
51
 
55
- //TODO: Must check if two equations isn't a linear combination of the others ?
52
+ //TODO: Must check if two equations isn't a linear combination of the others ?
56
53
 
57
- return true;
58
- }
54
+ return true;
55
+ }
59
56
 
60
- get variables(): string[] {
61
- let V: string[] = [];
62
- for (let E of this._equations) {
63
- V = V.concat(E.variables);
64
- }
65
- return [...new Set(V)].sort();
57
+ get variables(): string[] {
58
+ let V: string[] = [];
59
+ for (let E of this._equations) {
60
+ V = V.concat(E.variables);
66
61
  }
62
+ return [...new Set(V)].sort();
63
+ }
67
64
 
68
- get tex(): string {
69
- // Build the array of values.
70
- // Reorder
71
- // This clone the system :!!!
72
- //TODO: Avoid cloning this linear system
73
- let LS = this.clone().reorder(),
74
- letters = LS.variables,
75
- equStr: string[],
76
- equArray: string[] = [],
77
- m: Monom;
78
-
79
- // TODO: Manage tex output of linear equations
80
- for (let equ of LS.equations) {
81
- equStr = [];
82
- for (let L of letters) {
83
- m = equ.left.monomByLetter(L);
84
-
85
- if (equStr.length === 0) {
86
- equStr.push(m.isZero() ? '' : m.tex);
87
- } else {
88
- equStr.push(m.isZero() ? '' : ((m.coefficient.sign() === 1) ? '+' : '') + m.tex);
89
- }
65
+ get tex(): string {
66
+ // Build the array of values.
67
+ // Reorder
68
+ // This clone the system :!!!
69
+ //TODO: Avoid cloning this linear system
70
+ let LS = this.clone().reorder(),
71
+ letters = LS.variables,
72
+ equStr: string[],
73
+ equArray: string[] = [],
74
+ m: Monom;
75
+
76
+ // TODO: Manage tex output of linear equations
77
+ for (let equ of LS.equations) {
78
+ equStr = [];
79
+ for (let L of letters) {
80
+ m = equ.left.monomByLetter(L);
81
+
82
+ if (equStr.length === 0) {
83
+ equStr.push(m.isZero() ? '' : m.tex);
84
+ } else {
85
+ equStr.push(m.isZero() ? '' : ((m.coefficient.sign() === 1) ? '+' : '') + m.tex);
90
86
  }
91
-
92
- // Add the equal sign
93
- equStr.push('=');
94
-
95
- // Add the right hand part of the equation (should be only a number, because it has been reordered)
96
- equStr.push(equ.right.tex);
97
-
98
- // Add to the list.
99
- equArray.push(equStr.join('&'));
100
87
  }
101
88
 
89
+ // Add the equal sign
90
+ equStr.push('=');
91
+
92
+ // Add the right hand part of the equation (should be only a number, because it has been reordered)
93
+ equStr.push(equ.right.tex);
102
94
 
103
- return `\\left\\{\\begin{array}{${"r".repeat(letters.length)}cl}${equArray.join('\\\\\ ')}\\end{array}\\right.`;
104
- //return `\\left\\{\\begin{array}{rrrcl}${this._equations.map(equ => `${equ.tex}`).join('\\\\\ \n')}\\end{array}\\right.`;
95
+ // Add to the list.
96
+ equArray.push(equStr.join('&'));
105
97
  }
106
98
 
107
- get texSolution(): string {
108
- let tex: string[] = [];
109
99
 
110
- if (this._solutions === undefined) {
111
- this.solve();
112
- }
100
+ return `\\left\\{\\begin{array}{${"r".repeat(letters.length)}cl}${equArray.join('\\\\\ ')}\\end{array}\\right.`;
101
+ //return `\\left\\{\\begin{array}{rrrcl}${this._equations.map(equ => `${equ.tex}`).join('\\\\\ \n')}\\end{array}\\right.`;
102
+ }
113
103
 
114
- for (let letter in this._solutions) {
115
- if (this._solutions[letter].isReal) {
116
- console.log(`Undetermined (letter ${letter})`);
117
- return;
118
- }
119
- if (this._solutions[letter].isVarnothing) {
120
- console.log(`Undefined (letter ${letter})`);
121
- return;
122
- }
104
+ get solution(): string {
105
+ let tex: string[] = [];
123
106
 
124
- tex.push(this._solutions[letter].value.dfrac);
125
- }
126
- return `(${tex.join(';')})`;
107
+ if (this._solutions === undefined) {
108
+ this.solve();
127
109
  }
128
110
 
129
- // ------------------------------------------
130
- // Creation / parsing functions
131
- // ------------------------------------------
132
- parse = (...equations: any[]): LinearSystem => {
133
- this._equations = equations.map(value => new Equation(value));
134
- this._findLetters();
135
- return this;
136
- };
137
-
138
- setCoefficient = (...coefficients: string[]): LinearSystem => {
139
- // Reset the equations list
140
- this._equations = [];
141
-
142
- let i = 0;
143
- while (i < coefficients.length - this._letters.length) {
144
- let left = new Polynom().parse(this._letters.join(''), ...coefficients.slice(i, i + this._letters.length)),
145
- right = new Polynom(coefficients[i + this._letters.length].toString()),
146
- equ = new Equation().create(left, right);
147
- this._equations.push(equ.clone());
148
-
149
- i = i + this._letters.length + 1;
111
+ for (let letter in this._solutions) {
112
+ if (this._solutions[letter].isReal) {
113
+ console.log(`Undetermined (letter ${letter})`);
114
+ return;
115
+ }
116
+ if (this._solutions[letter].isVarnothing) {
117
+ console.log(`Undefined (letter ${letter})`);
118
+ return;
150
119
  }
151
- return this;
152
- };
153
-
154
- clone = (): LinearSystem => {
155
- return new LinearSystem().parse(...this._equations.map(equ => equ.clone()));
156
- };
157
120
 
158
- setLetters = (...letters: string[]): LinearSystem => {
159
- this._letters = letters;
160
- return this
121
+ tex.push(this._solutions[letter].value.dfrac);
161
122
  }
162
- private _findLetters = (): LinearSystem => {
163
- // Find all letters used.
164
- let variables = new Set();
165
-
166
- for (let equ of this._equations) {
167
- variables = new Set([...variables, ...equ.variables]);
168
- }
123
+ return `(${tex.join(';')})`;
124
+ }
169
125
 
170
- // TODO: How to transform (Set of string) to string[]
171
- // @ts-ignore
172
- this._letters = [...variables];
173
- return this;
126
+ // ------------------------------------------
127
+ // Creation / parsing functions
128
+ // ------------------------------------------
129
+ parse = (...equations: unknown[]): LinearSystem => {
130
+ this._equations = equations.map(value => new Equation(value));
131
+ this._findLetters();
132
+ return this;
133
+ };
134
+
135
+ setCoefficient = (...coefficients: string[]): LinearSystem => {
136
+ // Reset the equations list
137
+ this._equations = [];
138
+
139
+ let i = 0;
140
+ while (i < coefficients.length - this._letters.length) {
141
+ let left = new Polynom().parse(this._letters.join(''), ...coefficients.slice(i, i + this._letters.length)),
142
+ right = new Polynom(coefficients[i + this._letters.length].toString()),
143
+ equ = new Equation().create(left, right);
144
+ this._equations.push(equ.clone());
145
+
146
+ i = i + this._letters.length + 1;
174
147
  }
148
+ return this;
149
+ };
175
150
 
176
- // -----------------------------------------------
177
- // Equations generators and randomizers
178
- // -----------------------------------------------
179
- generate = (...solutions: Fraction[] | number[]): LinearSystem => {
180
- let solutionsF: Fraction[] = [];
151
+ clone = (): LinearSystem => {
152
+ return new LinearSystem().parse(...this._equations.map(equ => equ.clone()));
153
+ };
181
154
 
182
- // Convert the numbers to fractions if necessary
183
- for (let s of solutions) {
184
- if (typeof s === "number") {
185
- solutionsF.push(new Fraction(s.toString()));
186
- } else {
187
- solutionsF.push(s.clone());
188
- }
189
- }
155
+ setLetters = (...letters: string[]): LinearSystem => {
156
+ this._letters = letters;
157
+ return this
158
+ }
159
+ private _findLetters = (): LinearSystem => {
160
+ // Find all letters used.
161
+ let variables = new Set();
190
162
 
191
- // Create the equations and make sure they are not linear combined.
192
- this._equations = [];
193
- for (let i = 0; i < solutions.length; i++) {
194
- this._equations.push(this._generateOneEquation(...solutionsF));
195
- }
196
- return this;
197
- };
198
- private _generateOneEquation = (...solutions: Fraction[]): Equation => {
199
- let coeff: number[] = [], leftValue: Fraction = new Fraction().zero(),
200
- letters: string[] = ['x', 'y', 'z', 't', 'u', 'v', 'w', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'],
201
- equString: string = '', equ: Equation;
202
- for (let i = 0; i < solutions.length; i++) {
203
- coeff.push(Random.numberSym(5));
204
- leftValue.add(solutions[i].clone().multiply(coeff[i]));
205
- equString += `${(coeff[i] < 0) ? coeff[i] : '+' + coeff[i]}${letters[i]}`
206
- }
163
+ for (let equ of this._equations) {
164
+ variables = new Set([...variables, ...equ.variables]);
165
+ }
207
166
 
208
- // LeftValue contains the left part oof the equation - and is then the isSame as the right part.
209
- // It might be a Fraction.
167
+ // TODO: How to transform (Set of string) to string[]
168
+ // @ts-ignore
169
+ this._letters = [...variables];
170
+ return this;
171
+ }
210
172
 
211
- // Must check if it's not a linear combination
212
- equ = new Equation(`${equString}=${leftValue.display}`);
213
- if (equ.right.monoms[0].coefficient.denominator != 1) {
214
- equ.multiply(new Fraction(equ.right.monoms[0].coefficient.denominator, 1));
215
- }
216
- if (this._checkIfLinerCombination(equ)) {
217
- return equ;
173
+ // -----------------------------------------------
174
+ // Equations generators and randomizers
175
+ // -----------------------------------------------
176
+ generate = (...solutions: Fraction[] | number[]): LinearSystem => {
177
+ let solutionsF: Fraction[] = [];
178
+
179
+ // Convert the numbers to fractions if necessary
180
+ for (let s of solutions) {
181
+ if (typeof s === "number") {
182
+ solutionsF.push(new Fraction(s.toString()));
218
183
  } else {
219
- return this._generateOneEquation(...solutions);
184
+ solutionsF.push(s.clone());
220
185
  }
221
- };
186
+ }
222
187
 
188
+ // Create the equations and make sure they are not linear combined.
189
+ this._equations = [];
190
+ for (let i = 0; i < solutions.length; i++) {
191
+ this._equations.push(this._generateOneEquation(...solutionsF));
192
+ }
193
+ return this;
194
+ };
195
+ private _generateOneEquation = (...solutions: Fraction[]): Equation => {
196
+ let coeff: number[] = [], leftValue: Fraction = new Fraction().zero(),
197
+ letters: string[] = ['x', 'y', 'z', 't', 'u', 'v', 'w', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'],
198
+ equString: string = '', equ: Equation;
199
+ for (let i = 0; i < solutions.length; i++) {
200
+ coeff.push(Random.numberSym(5));
201
+ leftValue.add(solutions[i].clone().multiply(coeff[i]));
202
+ equString += `${(coeff[i] < 0) ? coeff[i] : '+' + coeff[i]}${letters[i]}`
203
+ }
223
204
 
224
- // ------------------------------------------
225
- // Mathematical operations
226
- // ------------------------------------------
227
- private _linearReduction(eq1: Equation, eq2: Equation, letter: string): Equation {
228
- // TODO: handle other signs for equations ?
229
- // Get the monom for the particular letter.
230
- let c1 = eq1.left.monomByDegree(1, letter).coefficient.clone(),
231
- c2 = eq2.left.monomByDegree(1, letter).coefficient.clone().opposed();
205
+ // LeftValue contains the left part oof the equation - and is then the isSame as the right part.
206
+ // It might be a Fraction.
232
207
 
233
- return this.mergeEquations(eq1, eq2, c2, c1);
208
+ // Must check if it's not a linear combination
209
+ equ = new Equation(`${equString}=${leftValue.display}`);
210
+ if (equ.right.monoms[0].coefficient.denominator != 1) {
211
+ equ.multiply(new Fraction(equ.right.monoms[0].coefficient.denominator, 1));
234
212
  }
213
+ if (this._checkIfLinerCombination(equ)) {
214
+ return equ;
215
+ } else {
216
+ return this._generateOneEquation(...solutions);
217
+ }
218
+ };
235
219
 
236
- mergeEquations = (eq1: Equation, eq2: Equation, factor1: any, factor2: any): Equation => {
237
- // Set and clone the equations.
238
220
 
239
- let eq1multiplied = eq1.clone().multiply(new Fraction(factor1)),
240
- eq2multiplied = eq2.clone().multiply(new Fraction(factor2));
221
+ // ------------------------------------------
222
+ // Mathematical operations
223
+ // ------------------------------------------
224
+ private _linearReduction(eq1: Equation, eq2: Equation, letter: string): Equation {
225
+ // TODO: handle other signs for equations ?
226
+ // Get the monom for the particular letter.
227
+ let c1 = eq1.left.monomByDegree(1, letter).coefficient.clone(),
228
+ c2 = eq2.left.monomByDegree(1, letter).coefficient.clone().opposed();
241
229
 
242
- // Add both equations together.
243
- eq1multiplied.left.add(eq2multiplied.left);
244
- eq1multiplied.right.add(eq2multiplied.right);
230
+ return this.mergeEquations(eq1, eq2, c2, c1);
231
+ }
245
232
 
246
- return eq1multiplied;
247
- }
233
+ mergeEquations = (eq1: Equation, eq2: Equation, factor1: unknown, factor2: unknown): Equation => {
234
+ // Set and clone the equations.
248
235
 
236
+ let eq1multiplied = eq1.clone().multiply(new Fraction(factor1)),
237
+ eq2multiplied = eq2.clone().multiply(new Fraction(factor2));
249
238
 
250
- // ------------------------------------------
251
- // Solvers algorithm
252
- // ------------------------------------------
253
- reorder = (): LinearSystem => {
254
- for (let E of this._equations) {
255
- E.reorder();
256
- }
257
- return this;
258
- };
239
+ // Add both equations together.
240
+ eq1multiplied.left.add(eq2multiplied.left);
241
+ eq1multiplied.right.add(eq2multiplied.right);
259
242
 
260
- solve = (): LinearSystem => {
261
- // Solve it by linear
262
- this._solutions = {};
263
- this._resolutionSteps = [];
243
+ return eq1multiplied;
244
+ }
264
245
 
265
- // Reorder all equations.
266
- this.reorder();
267
246
 
268
- // Get all variables in the linear system
269
- let V = this.variables.sort();
247
+ // ------------------------------------------
248
+ // Solvers algorithm
249
+ // ------------------------------------------
250
+ reorder = (): LinearSystem => {
251
+ for (let E of this._equations) {
252
+ E.reorder();
253
+ }
254
+ return this;
255
+ };
270
256
 
271
- for (let letter of V) {
272
- this._solutions[letter] = this._solveOneLetter(letter, V)
273
- }
257
+ solve = (): LinearSystem => {
258
+ // Solve it by linear
259
+ this._solutions = {};
260
+ this._resolutionSteps = [];
274
261
 
275
- // TODO: LinearSystem - solve: optimization and handle undetermined and undefined systems.
276
- return this;
277
- };
262
+ // Reorder all equations.
263
+ this.reorder();
278
264
 
279
- private _checkIfLinerCombination = (equ: Equation): boolean => {
265
+ // Get all variables in the linear system
266
+ let V = this.variables.sort();
280
267
 
281
- return true;
282
- };
268
+ for (let letter of V) {
269
+ this._solutions[letter] = this._solveOneLetter(letter, V)
270
+ }
283
271
 
284
- private _solveOneLetter(letter: string, V: string[]): { value: Fraction, isReal: boolean, isVarnothing: boolean } {
285
- // list of equations.
286
- let LE: Equation[] = this.clone().equations,
287
- reducedEquations: Equation[] = [];
272
+ // TODO: LinearSystem - solve: optimization and handle undetermined and undefined systems.
273
+ return this;
274
+ };
288
275
 
289
- // Reduce the equations.
290
- // Do it as long as there is more than one step, but no more than the number of equations.
291
- for (let L of V) {
292
- // remove the setLetter from all equations using linear combinations
293
- if (L === letter) {
294
- continue;
295
- }
276
+ private _checkIfLinerCombination = (equ: Equation): boolean => {
296
277
 
297
- // Linear reduction.
298
- // TODO: Search for better association
299
- for (let i = 0; i < LE.length - 1; i++) {
300
- reducedEquations.push(this._linearReduction(LE[i], LE[i + 1], L));
301
- }
278
+ return true;
279
+ };
302
280
 
303
- // Keep track of each steps.
304
- this._resolutionSteps.push(new LinearSystem().parse(...reducedEquations));
281
+ private _solveOneLetter(letter: string, V: string[]): { value: Fraction, isReal: boolean, isVarnothing: boolean } {
282
+ // list of equations.
283
+ let LE: Equation[] = this.clone().equations,
284
+ reducedEquations: Equation[] = [];
305
285
 
306
- // Set the list of equations to the new version.
307
- LE = this._resolutionSteps[this._resolutionSteps.length - 1].clone().equations;
286
+ // Reduce the equations.
287
+ // Do it as long as there is more than one step, but no more than the number of equations.
288
+ for (let L of V) {
289
+ // remove the setLetter from all equations using linear combinations
290
+ if (L === letter) {
291
+ continue;
292
+ }
308
293
 
309
- // Reset the stack
310
- reducedEquations = [];
294
+ // Linear reduction.
295
+ // TODO: Search for better association
296
+ for (let i = 0; i < LE.length - 1; i++) {
297
+ reducedEquations.push(this._linearReduction(LE[i], LE[i + 1], L));
311
298
  }
312
299
 
313
- // Solve the equations
314
- let E = this._resolutionSteps[this._resolutionSteps.length - 1].equations[0];
315
- E.solve();
300
+ // Keep track of each steps.
301
+ this._resolutionSteps.push(new LinearSystem().parse(...reducedEquations));
316
302
 
317
- return {
318
- value: new Fraction(E.solutions[0]),
319
- isReal: E.isReal,
320
- isVarnothing: E.isVarnothing
321
- }
322
- }
303
+ // Set the list of equations to the new version.
304
+ LE = this._resolutionSteps[this._resolutionSteps.length - 1].clone().equations;
323
305
 
324
- // ------------------------------------------
325
- // Helpers
326
- // ------------------------------------------
327
- log = (): string => {
328
- let str: string = '';
306
+ // Reset the stack
307
+ reducedEquations = [];
308
+ }
329
309
 
330
- for (let E of this._equations) {
331
- console.log(E.tex);
332
- str += `${E.tex}\\n}`;
333
- }
310
+ // Solve the equations
311
+ let E = this._resolutionSteps[this._resolutionSteps.length - 1].equations[0];
312
+ E.solve();
334
313
 
335
- return str;
336
- };
314
+ return {
315
+ value: new Fraction(E.solutions[0].value),
316
+ isReal: E.isReal,
317
+ isVarnothing: E.isVarnothing
318
+ }
337
319
  }
320
+
321
+ // ------------------------------------------
322
+ // Helpers
323
+ // ------------------------------------------
324
+ log = (): string => {
325
+ let str: string = '';
326
+
327
+ for (let E of this._equations) {
328
+ console.log(E.tex);
329
+ str += `${E.tex}\\n}`;
330
+ }
331
+
332
+ return str;
333
+ };
334
+ }
@@ -35,7 +35,7 @@ import {Shutingyard} from '../shutingyard';
35
35
  return this;
36
36
  }
37
37
 
38
- evaluate(tokenSets: { [key: string]: any[] }, reference?: any[]): any[] {
38
+ evaluate(tokenSets: { [key: string]: unknown[] }, reference?: unknown[]): unknown[] {
39
39
  let varStack: (Set<unknown>)[] = []
40
40
 
41
41
  let referenceSet: Set<unknown>