pimath 0.0.23 → 0.0.27
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/dev/demo.css +3 -0
- package/dev/index.html +217 -53
- package/dev/pi.js +581 -220
- package/dev/pi.js.map +1 -1
- package/dist/pi.js +1 -1
- package/dist/pi.js.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/algebra.Equation.html +11 -13
- package/docs/classes/algebra.LinearSystem.html +1 -1
- package/docs/classes/algebra.Logicalset.html +3 -3
- package/docs/classes/algebra.Monom.html +50 -49
- package/docs/classes/algebra.Polynom.html +12 -25
- package/docs/classes/algebra.Rational.html +3 -3
- package/docs/classes/coefficients.Fraction.html +10 -6
- package/docs/classes/coefficients.Nthroot.html +3 -1
- package/docs/classes/geometry.Circle.html +3 -1
- package/docs/classes/geometry.Line.html +3 -1
- package/docs/classes/geometry.Point.html +1 -1
- package/docs/classes/geometry.Triangle.html +6 -6
- package/docs/classes/geometry.Vector.html +1 -1
- package/docs/classes/numeric.Numeric.html +5 -5
- package/docs/classes/shutingyard.Shutingyard.html +5 -5
- package/docs/index.html +1 -1
- package/docs/interfaces/geometry.remarquableLines.html +1 -1
- package/docs/modules/algebra.html +1 -1
- package/docs/modules/coefficients.html +1 -1
- package/docs/modules/geometry.html +1 -1
- package/docs/modules/numeric.html +1 -1
- package/docs/modules/random.Random.html +1 -1
- package/docs/modules/random.html +1 -1
- package/docs/modules/shutingyard.html +1 -1
- package/docs/modules.html +1 -1
- package/esm/main.js +2 -0
- package/esm/main.js.map +1 -1
- package/esm/maths/algebra/equation.d.ts +11 -5
- package/esm/maths/algebra/equation.js +159 -52
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/linearSystem.d.ts +3 -4
- package/esm/maths/algebra/linearSystem.js +2 -5
- package/esm/maths/algebra/linearSystem.js.map +1 -1
- package/esm/maths/algebra/logicalset.d.ts +2 -2
- package/esm/maths/algebra/logicalset.js +1 -1
- package/esm/maths/algebra/logicalset.js.map +1 -1
- package/esm/maths/algebra/monom.d.ts +5 -3
- package/esm/maths/algebra/monom.js +29 -2
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +6 -6
- package/esm/maths/algebra/polynom.js +4 -4
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +1 -1
- package/esm/maths/algebra/rational.js +2 -2
- package/esm/maths/algebra/rational.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +2 -2
- package/esm/maths/coefficients/fraction.js +1 -1
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/coefficients/nthroot.d.ts +1 -1
- package/esm/maths/coefficients/nthroot.js +4 -1
- package/esm/maths/coefficients/nthroot.js.map +1 -1
- package/esm/maths/geometry/circle.d.ts +12 -3
- package/esm/maths/geometry/circle.js +125 -39
- package/esm/maths/geometry/circle.js.map +1 -1
- package/esm/maths/geometry/line.d.ts +1 -2
- package/esm/maths/geometry/line.js +1 -4
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.d.ts +3 -4
- package/esm/maths/geometry/point.js +18 -15
- package/esm/maths/geometry/point.js.map +1 -1
- package/esm/maths/geometry/triangle.d.ts +0 -1
- package/esm/maths/geometry/triangle.js +3 -4
- package/esm/maths/geometry/triangle.js.map +1 -1
- package/esm/maths/geometry/vector.js +2 -1
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/numexp.d.ts +11 -0
- package/esm/maths/numexp.js +107 -0
- package/esm/maths/numexp.js.map +1 -0
- package/esm/maths/random/rndFraction.js +4 -3
- package/esm/maths/random/rndFraction.js.map +1 -1
- package/esm/maths/random/rndMonom.d.ts +1 -1
- package/esm/maths/random/rndMonom.js +12 -7
- package/esm/maths/random/rndMonom.js.map +1 -1
- package/esm/maths/random/rndPolynom.js +8 -2
- package/esm/maths/random/rndPolynom.js.map +1 -1
- package/esm/maths/random/rndTypes.d.ts +3 -1
- package/esm/maths/shutingyard.d.ts +21 -4
- package/esm/maths/shutingyard.js +72 -74
- package/esm/maths/shutingyard.js.map +1 -1
- package/package.json +3 -5
- package/src/main.ts +2 -0
- package/src/maths/algebra/equation.ts +183 -73
- package/src/maths/algebra/linearSystem.ts +262 -265
- package/src/maths/algebra/logicalset.ts +3 -3
- package/src/maths/algebra/monom.ts +54 -35
- package/src/maths/algebra/polynom.ts +10 -10
- package/src/maths/algebra/rational.ts +1 -1
- package/src/maths/coefficients/fraction.ts +11 -7
- package/src/maths/coefficients/nthroot.ts +8 -1
- package/src/maths/geometry/circle.ts +160 -45
- package/src/maths/geometry/line.ts +4 -8
- package/src/maths/geometry/point.ts +25 -18
- package/src/maths/geometry/triangle.ts +3 -5
- package/src/maths/geometry/vector.ts +4 -3
- package/src/maths/numexp.ts +127 -0
- package/src/maths/random/rndFraction.ts +4 -3
- package/src/maths/random/rndMonom.ts +39 -35
- package/src/maths/random/rndPolynom.ts +13 -3
- package/src/maths/random/rndTypes.ts +4 -2
- package/src/maths/shutingyard.ts +144 -94
- package/tests/algebra/monom.test.ts +18 -4
- package/tests/algebra/polynom.test.ts +19 -4
- package/tests/geometry/circle.test.ts +28 -0
- package/tests/shutingyard.test.ts +3 -3
- package/tsconfig.json +4 -1
- package/typedoc.katex.js +11 -0
- package/docs/classes/algebra.Algebra.Equation.html +0 -26
- package/docs/classes/algebra.Algebra.LinearSystem.html +0 -1
- package/docs/classes/algebra.Algebra.LogicalSet.html +0 -3
- package/docs/classes/algebra.Algebra.Monom.html +0 -111
- package/docs/classes/algebra.Algebra.Polynom.html +0 -36
- package/docs/classes/algebra.Algebra.Rational.html +0 -2
- package/docs/classes/geometry.Geometry.Circle.html +0 -1
- package/docs/classes/geometry.Geometry.Line.html +0 -1
- package/docs/classes/geometry.Geometry.Point.html +0 -1
- package/docs/classes/geometry.Geometry.Triangle.html +0 -9
- package/docs/classes/geometry.Geometry.Vector.html +0 -1
- package/docs/modules/algebra.Algebra.html +0 -1
- package/docs/modules/geometry.Geometry.html +0 -1
- 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
// ------------------------------------------
|
|
26
|
+
// Getter and setter
|
|
27
|
+
// ------------------------------------------
|
|
28
|
+
get equations(): Equation[] {
|
|
29
|
+
return this._equations;
|
|
30
|
+
}
|
|
34
31
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
set equations(value) {
|
|
33
|
+
this._equations = value;
|
|
34
|
+
}
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
get letters(): string {
|
|
37
|
+
return this._letters.join('')
|
|
38
|
+
}
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
set letters(value: string) {
|
|
41
|
+
this._letters = value.split('');
|
|
42
|
+
}
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
get isSolvable(): boolean {
|
|
45
|
+
let V = this.variables;
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
52
|
+
//TODO: Must check if two equations isn't a linear combination of the others ?
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
104
|
-
|
|
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
|
-
|
|
111
|
-
|
|
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
|
-
|
|
115
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
return `(${tex.join(';')})`;
|
|
107
|
+
if (this._solutions === undefined) {
|
|
108
|
+
this.solve();
|
|
127
109
|
}
|
|
128
110
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.
|
|
135
|
-
|
|
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
|
-
|
|
159
|
-
this._letters = letters;
|
|
160
|
-
return this
|
|
121
|
+
tex.push(this._solutions[letter].value.dfrac);
|
|
161
122
|
}
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
209
|
-
|
|
167
|
+
// TODO: How to transform (Set of string) to string[]
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
this._letters = [...variables];
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
210
172
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
240
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
eq1multiplied.right.add(eq2multiplied.right);
|
|
230
|
+
return this.mergeEquations(eq1, eq2, c2, c1);
|
|
231
|
+
}
|
|
245
232
|
|
|
246
|
-
|
|
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
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
this._solutions = {};
|
|
263
|
-
this._resolutionSteps = [];
|
|
243
|
+
return eq1multiplied;
|
|
244
|
+
}
|
|
264
245
|
|
|
265
|
-
// Reorder all equations.
|
|
266
|
-
this.reorder();
|
|
267
246
|
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
257
|
+
solve = (): LinearSystem => {
|
|
258
|
+
// Solve it by linear
|
|
259
|
+
this._solutions = {};
|
|
260
|
+
this._resolutionSteps = [];
|
|
274
261
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
};
|
|
262
|
+
// Reorder all equations.
|
|
263
|
+
this.reorder();
|
|
278
264
|
|
|
279
|
-
|
|
265
|
+
// Get all variables in the linear system
|
|
266
|
+
let V = this.variables.sort();
|
|
280
267
|
|
|
281
|
-
|
|
282
|
-
|
|
268
|
+
for (let letter of V) {
|
|
269
|
+
this._solutions[letter] = this._solveOneLetter(letter, V)
|
|
270
|
+
}
|
|
283
271
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
reducedEquations: Equation[] = [];
|
|
272
|
+
// TODO: LinearSystem - solve: optimization and handle undetermined and undefined systems.
|
|
273
|
+
return this;
|
|
274
|
+
};
|
|
288
275
|
|
|
289
|
-
|
|
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
|
-
|
|
298
|
-
|
|
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
|
-
|
|
304
|
-
|
|
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
|
-
|
|
307
|
-
|
|
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
|
-
|
|
310
|
-
|
|
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
|
-
//
|
|
314
|
-
|
|
315
|
-
E.solve();
|
|
300
|
+
// Keep track of each steps.
|
|
301
|
+
this._resolutionSteps.push(new LinearSystem().parse(...reducedEquations));
|
|
316
302
|
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
log = (): string => {
|
|
328
|
-
let str: string = '';
|
|
306
|
+
// Reset the stack
|
|
307
|
+
reducedEquations = [];
|
|
308
|
+
}
|
|
329
309
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
310
|
+
// Solve the equations
|
|
311
|
+
let E = this._resolutionSteps[this._resolutionSteps.length - 1].equations[0];
|
|
312
|
+
E.solve();
|
|
334
313
|
|
|
335
|
-
|
|
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
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @module Logicalset
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {Shutingyard} from '../shutingyard';
|
|
6
|
+
import {Shutingyard, ShutingyardMode} from '../shutingyard';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Polynom class can handle polynoms, reorder, resolve, ...
|
|
@@ -30,12 +30,12 @@ import {Shutingyard} from '../shutingyard';
|
|
|
30
30
|
// TODO: Must format the value string to convert some items...
|
|
31
31
|
|
|
32
32
|
// Parse the updated value to the shutingyard algorithm
|
|
33
|
-
this._rpn = new Shutingyard(
|
|
33
|
+
this._rpn = new Shutingyard(ShutingyardMode.SET).parse(value).rpn;
|
|
34
34
|
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
evaluate(tokenSets: { [key: string]:
|
|
38
|
+
evaluate(tokenSets: { [key: string]: unknown[] }, reference?: unknown[]): unknown[] {
|
|
39
39
|
let varStack: (Set<unknown>)[] = []
|
|
40
40
|
|
|
41
41
|
let referenceSet: Set<unknown>
|