pimath 0.0.120 → 0.0.122
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/PI.iml +7 -1
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +90 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]1/shelved.patch +107 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +4 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_1.xml +4 -0
- package/LICENSE.md +1 -1
- package/dev/pimath.js +7929 -0
- package/dev/pimath.js.map +1 -0
- package/dist/{pi.js → pimath.js} +7613 -7840
- package/dist/pimath.js.map +1 -0
- package/dist/pimath.min.js +2 -0
- package/dist/pimath.min.js.map +1 -0
- package/docs/assets/main.js +58 -58
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +1367 -1280
- package/docs/classes/Logicalset.Logicalset.html +221 -212
- package/docs/classes/Polynom.Rational.html +391 -388
- package/docs/classes/Vector-1.Vector.html +494 -448
- package/docs/classes/Vector.Point.html +341 -342
- package/docs/classes/algebra_equation.Equation.html +796 -753
- package/docs/classes/algebra_linearSystem.LinearSystem.html +408 -397
- package/docs/classes/algebra_monom.Monom.html +967 -910
- package/docs/classes/algebra_polynom.Polynom.html +1281 -1260
- package/docs/classes/coefficients_fraction.Fraction.html +939 -931
- package/docs/classes/geometry_circle.Circle.html +476 -476
- package/docs/classes/geometry_line.Line.html +779 -719
- package/docs/classes/geometry_triangle.Triangle.html +429 -420
- package/docs/classes/numeric.Numeric.html +269 -263
- package/docs/classes/shutingyard.Shutingyard.html +259 -248
- package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +89 -88
- package/docs/enums/geometry_line.LinePropriety.html +102 -102
- package/docs/enums/shutingyard.ShutingyardMode.html +106 -102
- package/docs/enums/shutingyard.ShutingyardType.html +120 -116
- package/docs/index.html +63 -65
- package/docs/interfaces/algebra_equation.ISolution.html +111 -109
- package/docs/interfaces/algebra_polynom.IEuclidian.html +93 -92
- package/docs/interfaces/geometry_triangle.remarquableLines.html +150 -150
- package/docs/modules/Logicalset.html +69 -74
- package/docs/modules/Polynom.html +69 -74
- package/docs/modules/Vector-1.html +69 -74
- package/docs/modules/Vector.html +69 -74
- package/docs/modules/algebra_equation.html +75 -81
- package/docs/modules/algebra_linearSystem.html +65 -71
- package/docs/modules/algebra_monom.html +70 -76
- package/docs/modules/algebra_polynom.html +75 -81
- package/docs/modules/coefficients_fraction.html +70 -76
- package/docs/modules/geometry_circle.html +65 -71
- package/docs/modules/geometry_line.html +70 -76
- package/docs/modules/geometry_triangle.html +70 -76
- package/docs/modules/numeric.html +65 -71
- package/docs/modules/shutingyard.html +84 -90
- package/docs/types/algebra_monom.literalType.html +66 -70
- package/docs/types/algebra_polynom.PolynomParsingType.html +62 -66
- package/docs/types/coefficients_fraction.FractionParsingType.html +61 -65
- package/docs/types/shutingyard.Token.html +72 -76
- package/docs/types/shutingyard.tokenType.html +77 -81
- package/docs/variables/shutingyard.tokenConstant.html +70 -74
- package/esm/index.d.ts +38 -41
- package/esm/index.js +43 -46
- package/esm/index.js.map +1 -1
- package/esm/maths/algebra/equation.d.ts +119 -117
- package/esm/maths/algebra/equation.js +796 -785
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/linearSystem.d.ts +39 -38
- package/esm/maths/algebra/linearSystem.js +278 -262
- package/esm/maths/algebra/linearSystem.js.map +1 -1
- package/esm/maths/algebra/logicalset.d.ts +28 -28
- package/esm/maths/algebra/logicalset.js +157 -157
- package/esm/maths/algebra/monom.d.ts +206 -206
- package/esm/maths/algebra/monom.js +908 -908
- package/esm/maths/algebra/monom.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +157 -157
- package/esm/maths/algebra/polynom.js +1277 -1277
- package/esm/maths/algebra/rational.d.ts +45 -45
- package/esm/maths/algebra/rational.js +183 -183
- package/esm/maths/algebra/study/rationalStudy.d.ts +28 -28
- package/esm/maths/algebra/study/rationalStudy.js +243 -243
- package/esm/maths/algebra/study.d.ts +143 -142
- package/esm/maths/algebra/study.js +378 -377
- package/esm/maths/algebra/study.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +90 -90
- package/esm/maths/coefficients/fraction.js +516 -516
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/coefficients/nthRoot.d.ts +23 -23
- package/esm/maths/coefficients/nthRoot.js +136 -136
- package/esm/maths/geometry/circle.d.ts +45 -45
- package/esm/maths/geometry/circle.js +323 -323
- package/esm/maths/geometry/line.d.ts +99 -99
- package/esm/maths/geometry/line.js +481 -481
- package/esm/maths/geometry/line.js.map +1 -1
- package/esm/maths/geometry/point.d.ts +34 -34
- package/esm/maths/geometry/point.js +166 -166
- package/esm/maths/geometry/point.js.map +1 -1
- package/esm/maths/geometry/triangle.d.ts +85 -85
- package/esm/maths/geometry/triangle.js +268 -268
- package/esm/maths/geometry/vector.d.ts +41 -41
- package/esm/maths/geometry/vector.js +197 -197
- package/esm/maths/geometry/vector.js.map +1 -1
- package/esm/maths/numeric.d.ts +28 -28
- package/esm/maths/numeric.js +180 -180
- package/esm/maths/numexp.d.ts +19 -0
- package/esm/maths/numexp.js +186 -0
- package/esm/maths/numexp.js.map +1 -0
- package/esm/maths/randomization/random.d.ts +23 -23
- package/esm/maths/randomization/random.js +78 -78
- package/esm/maths/randomization/random.js.map +1 -1
- package/esm/maths/randomization/randomCore.d.ts +7 -7
- package/esm/maths/randomization/randomCore.js +21 -21
- package/esm/maths/randomization/rndFraction.d.ts +12 -12
- package/esm/maths/randomization/rndFraction.js +43 -43
- package/esm/maths/randomization/rndGeometryLine.d.ts +12 -12
- package/esm/maths/randomization/rndGeometryLine.js +45 -45
- package/esm/maths/randomization/rndGeometryPoint.d.ts +12 -12
- package/esm/maths/randomization/rndGeometryPoint.js +60 -60
- package/esm/maths/randomization/rndHelpers.d.ts +23 -23
- package/esm/maths/randomization/rndHelpers.js +76 -76
- package/esm/maths/randomization/rndMonom.d.ts +12 -12
- package/esm/maths/randomization/rndMonom.js +52 -52
- package/esm/maths/randomization/rndPolynom.d.ts +13 -13
- package/esm/maths/randomization/rndPolynom.js +74 -74
- package/esm/maths/randomization/rndTypes.d.ts +34 -34
- package/esm/maths/randomization/rndTypes.js +2 -2
- package/esm/maths/shutingyard.d.ts +59 -59
- package/esm/maths/shutingyard.js +442 -442
- package/esm/maths/shutingyard.js.map +1 -1
- package/package.json +11 -11
- package/public/index.html +50 -81
- package/public/playground.html +7 -8
- package/src/index.ts +1 -4
- package/src/maths/algebra/equation.ts +16 -0
- package/src/maths/algebra/linearSystem.ts +20 -0
- package/src/maths/algebra/study.ts +12 -10
- package/src/maths/{expressions/numexp.ts → numexp.ts} +2 -2
- package/tests/algebra/equation.test.ts +19 -5
- package/tests/algebra/linear.test.ts +3 -11
- package/tests/algebra/polynom.test.ts +7 -8
- package/tests/algebra/rationnal.test.ts +1 -1
- package/tests/algebra/study.test.ts +2 -9
- package/tests/coefficients/fraction.test.ts +8 -8
- package/tests/custom.test.ts +33 -37
- package/tests/numeric.test.ts +1 -2
- package/tests/numexp.test.ts +13 -5
- package/tests/shutingyard.test.ts +3 -3
- package/webpack-production-min.config.js +1 -1
- package/webpack-production.config.js +1 -1
- package/webpack.config.js +1 -1
- package/dist/pi.js.map +0 -1
- package/dist/pi.min.js +0 -2
- package/dist/pi.min.js.map +0 -1
- package/docs/classes/expressions_numexp.NumExp.html +0 -236
- package/docs/classes/expressions_polynomexp.PolynomExpFactor.html +0 -317
- package/docs/classes/expressions_polynomexp.PolynomExpProduct.html +0 -285
- package/docs/modules/expressions_numexp.html +0 -71
- package/docs/modules/expressions_polynomexp.html +0 -73
- package/docs/modules.html +0 -76
- package/graph.svg +0 -1033
- package/src/maths/expressions/ExpressionTree.ts +0 -172
- package/src/maths/expressions/expression.ts +0 -286
- package/src/maths/expressions/expressionFactor.ts +0 -190
- package/src/maths/expressions/expressionMember.ts +0 -233
- package/src/maths/expressions/expressionOperators.ts +0 -49
- package/src/maths/expressions/expressionParser.ts +0 -295
- package/src/maths/expressions/factors/ExpFactor.ts +0 -39
- package/src/maths/expressions/factors/ExpFactorConstant.ts +0 -60
- package/src/maths/expressions/factors/ExpFactorExponential.ts +0 -26
- package/src/maths/expressions/factors/ExpFactorNumber.ts +0 -72
- package/src/maths/expressions/factors/ExpFactorPower.ts +0 -42
- package/src/maths/expressions/factors/ExpFactorTrigo.ts +0 -53
- package/src/maths/expressions/factors/ExpFactorVariable.ts +0 -45
- package/src/maths/expressions/internals.ts +0 -14
- package/src/maths/expressions/polynomexp.bkp.ts +0 -221
- package/src/maths/expressions/polynomexp.ts +0 -310
- package/tests/expressions/expressions.test.ts +0 -145
- package/tests/expressions/expressiontree.test.ts +0 -11
- package/tests/polynomexp.test.ts +0 -12
|
@@ -1,786 +1,797 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Equation = exports.PARTICULAR_SOLUTION = void 0;
|
|
4
|
-
const polynom_1 = require("./polynom");
|
|
5
|
-
const numeric_1 = require("../numeric");
|
|
6
|
-
const fraction_1 = require("../coefficients/fraction");
|
|
7
|
-
const nthRoot_1 = require("../coefficients/nthRoot");
|
|
8
|
-
var PARTICULAR_SOLUTION;
|
|
9
|
-
(function (PARTICULAR_SOLUTION) {
|
|
10
|
-
PARTICULAR_SOLUTION["real"] = "\\mathbb{R}";
|
|
11
|
-
PARTICULAR_SOLUTION["varnothing"] = "\\varnothing";
|
|
12
|
-
})(PARTICULAR_SOLUTION
|
|
13
|
-
class Equation {
|
|
14
|
-
/**
|
|
15
|
-
* Create an Equation using two polynoms.
|
|
16
|
-
* Markdown *support* is cool
|
|
17
|
-
* @param equations
|
|
18
|
-
*/
|
|
19
|
-
constructor(...equations) {
|
|
20
|
-
// Undetermined texSolutions.
|
|
21
|
-
this._varnothing = PARTICULAR_SOLUTION.varnothing;
|
|
22
|
-
this._real = PARTICULAR_SOLUTION.real;
|
|
23
|
-
this.hasVariable = (letter) => {
|
|
24
|
-
return this.variables.includes(letter);
|
|
25
|
-
};
|
|
26
|
-
// ------------------------------------------
|
|
27
|
-
// Creation / parsing functions
|
|
28
|
-
// -----------------------------------------------
|
|
29
|
-
this._randomizeDefaults = {
|
|
30
|
-
degree: 2
|
|
31
|
-
};
|
|
32
|
-
// ------------------------------------------
|
|
33
|
-
this.parse = (equationString) => {
|
|
34
|
-
let pStr, strSign;
|
|
35
|
-
// Find the string separator
|
|
36
|
-
strSign = this._findSign(equationString);
|
|
37
|
-
if (strSign === false) {
|
|
38
|
-
console.error('The equation is not valid (no sign found)');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
// The StrSign is found
|
|
42
|
-
pStr = equationString.split(strSign);
|
|
43
|
-
return this.create(new polynom_1.Polynom(pStr[0]), new polynom_1.Polynom(pStr[1]), this._formatSign(strSign));
|
|
44
|
-
};
|
|
45
|
-
this.create = (left, right, sign) => {
|
|
46
|
-
this._left = left;
|
|
47
|
-
this._right = right;
|
|
48
|
-
this._sign = this._formatSign(sign);
|
|
49
|
-
return this;
|
|
50
|
-
};
|
|
51
|
-
this.clone = () => {
|
|
52
|
-
return new Equation().create(this._left.clone(), this._right.clone(), this._sign + '');
|
|
53
|
-
};
|
|
54
|
-
// -----------------------------------------------
|
|
55
|
-
// Equations generators and randomizers
|
|
56
|
-
this.randomize = (opts, sign) => {
|
|
57
|
-
// TODO: Generate equations randomly, using config.
|
|
58
|
-
return new Equation().create(new polynom_1.Polynom(), new polynom_1.Polynom(), sign);
|
|
59
|
-
};
|
|
60
|
-
// -----------------------------------------------
|
|
61
|
-
/**
|
|
62
|
-
* Reorder will move all monoms containing a letter on the left, all the other on the right.
|
|
63
|
-
*/
|
|
64
|
-
this.moveLeft = () => {
|
|
65
|
-
this._left = this._left.clone().subtract(this._right);
|
|
66
|
-
this._right.zero();
|
|
67
|
-
return this;
|
|
68
|
-
};
|
|
69
|
-
this.reorder = (allLeft) => {
|
|
70
|
-
// Move all monoms of degree greater than 0 to the left.
|
|
71
|
-
// and all zero degree monoms to the right.
|
|
72
|
-
this._left.subtract(this._right);
|
|
73
|
-
this._right.zero();
|
|
74
|
-
this._left.reorder();
|
|
75
|
-
// we eant all left (so equal zero) : it's done !
|
|
76
|
-
if (allLeft)
|
|
77
|
-
return this;
|
|
78
|
-
// Fetch all zero degree monoms.
|
|
79
|
-
this._left.monoms
|
|
80
|
-
.filter(m => m.degree().isZero())
|
|
81
|
-
.forEach(m => {
|
|
82
|
-
const move = m.clone();
|
|
83
|
-
this._left.subtract(move);
|
|
84
|
-
this._right.subtract(move);
|
|
85
|
-
});
|
|
86
|
-
// Reorder the left and right polynoms
|
|
87
|
-
this._left.reorder();
|
|
88
|
-
this._right.reorder();
|
|
89
|
-
return this;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
93
|
-
*/
|
|
94
|
-
this.simplify = () => {
|
|
95
|
-
this.multiply(numeric_1.Numeric.lcm(...this._left.getDenominators(), ...this._right.getDenominators()));
|
|
96
|
-
this.divide(numeric_1.Numeric.gcd(...this._left.getNumerators(), ...this._right.getNumerators()));
|
|
97
|
-
return this;
|
|
98
|
-
};
|
|
99
|
-
// -----------------------------------------------
|
|
100
|
-
// Equations operations
|
|
101
|
-
/**
|
|
102
|
-
* Reorder the polynom to have only one letter on the left, the rest on the right.
|
|
103
|
-
* @param letter
|
|
104
|
-
*/
|
|
105
|
-
this.isolate = (letter) => {
|
|
106
|
-
// Determine if we can isolate the variables.
|
|
107
|
-
// Both part of the equations must be of the first degree.
|
|
108
|
-
//TODO: handle equations of degree two or more ?
|
|
109
|
-
if (!this.degree(letter).isOne()) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
// Modify the equation to isolate the asked variable.
|
|
113
|
-
// TODO: must handle equations like 3xy+5y=4 => y = 4/(3x-5)
|
|
114
|
-
if (this.isMultiVariable()) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
// Isolate the letter.
|
|
118
|
-
let mMove, cMove;
|
|
119
|
-
// Start by moving everything to the left.
|
|
120
|
-
this._left.subtract(this._right);
|
|
121
|
-
this._right.zero();
|
|
122
|
-
let values = [...this._left.monoms];
|
|
123
|
-
for (let m of values) {
|
|
124
|
-
if (!m.hasLetter(letter)) {
|
|
125
|
-
mMove = m.clone();
|
|
126
|
-
this._left.subtract(mMove);
|
|
127
|
-
this._right.subtract(mMove);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
// In theory, we should have only one item on the left.
|
|
131
|
-
if (this._left.length !== 1) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
cMove = this._left.monoms[0].coefficient.clone();
|
|
135
|
-
this._left.divide(cMove);
|
|
136
|
-
this._right.divide(cMove);
|
|
137
|
-
return this;
|
|
138
|
-
};
|
|
139
|
-
this.replaceBy = (letter, P) => {
|
|
140
|
-
this._left.replaceBy(letter, P);
|
|
141
|
-
this._right.replaceBy(letter, P);
|
|
142
|
-
return this;
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Multiple an equation by a fraction value.
|
|
146
|
-
* @param value
|
|
147
|
-
*/
|
|
148
|
-
this.multiply = (value) => {
|
|
149
|
-
// Make sure we have a fraction.
|
|
150
|
-
let F = new fraction_1.Fraction(value);
|
|
151
|
-
// Multiply each part of the equation by the fraction
|
|
152
|
-
this._left.multiply(F);
|
|
153
|
-
this._right.multiply(F);
|
|
154
|
-
// The sign of the inequation must be changed.
|
|
155
|
-
if (this._sign !== '=' && F.sign() === -1) {
|
|
156
|
-
this._reverseSign();
|
|
157
|
-
}
|
|
158
|
-
return this;
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* divide an equation by a given value (transformed as a fraction)
|
|
162
|
-
*
|
|
163
|
-
* ```
|
|
164
|
-
* 8x+10=6x \vert 2
|
|
165
|
-
* 4x+5=3x
|
|
166
|
-
* ```
|
|
167
|
-
*
|
|
168
|
-
* |>Alternatively with $3x-4$ maybe it's working ?
|
|
169
|
-
* $$\frac{3x}{5}$$
|
|
170
|
-
*
|
|
171
|
-
* @param value
|
|
172
|
-
* @returns {Equation}
|
|
173
|
-
*/
|
|
174
|
-
this.divide = (value) => {
|
|
175
|
-
// Make sure we have a fraction.
|
|
176
|
-
let F = new fraction_1.Fraction(value);
|
|
177
|
-
if (F.isZero()) {
|
|
178
|
-
return this;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
return this.multiply(F.invert());
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* Get the degree of the equation
|
|
186
|
-
* @param letter
|
|
187
|
-
*/
|
|
188
|
-
this.degree = (letter) => {
|
|
189
|
-
return fraction_1.Fraction.max(this._left.degree(letter), this._right.degree(letter));
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Determine if the equation contains more than one letter/variable.
|
|
193
|
-
*/
|
|
194
|
-
this.isMultiVariable = () => {
|
|
195
|
-
return this._left.isMultiVariable || this._right.isMultiVariable;
|
|
196
|
-
};
|
|
197
|
-
this.letters = () => {
|
|
198
|
-
// @ts-ignore
|
|
199
|
-
return [...new Set([...this._left.letters(), ...this._right.letters()])];
|
|
200
|
-
};
|
|
201
|
-
// -----------------------------------------------
|
|
202
|
-
// Equations helpers
|
|
203
|
-
// -----------------------------------------------
|
|
204
|
-
// -----------------------------------------------
|
|
205
|
-
this.solve = () => {
|
|
206
|
-
// Initialise the variables:
|
|
207
|
-
this._solutions = [];
|
|
208
|
-
// TODO: consolidate solving equations (inequations vs equations)
|
|
209
|
-
// TODO: work with not natural degrees ?
|
|
210
|
-
this._polynom = this._left.clone().subtract(this._right);
|
|
211
|
-
switch (this._polynom.degree().value) {
|
|
212
|
-
case 0:
|
|
213
|
-
case 1:
|
|
214
|
-
this._solveDegree1();
|
|
215
|
-
break;
|
|
216
|
-
case 2:
|
|
217
|
-
this._solveDegree2();
|
|
218
|
-
break;
|
|
219
|
-
default:
|
|
220
|
-
this._solveDegree3plus();
|
|
221
|
-
}
|
|
222
|
-
// cleanup the solutions.
|
|
223
|
-
this._solutions = Equation.makeSolutionsUnique(this._solutions);
|
|
224
|
-
return this;
|
|
225
|
-
};
|
|
226
|
-
this.test = (values) => {
|
|
227
|
-
return this.left.evaluate(values).isEqual(this.right.evaluate(values));
|
|
228
|
-
};
|
|
229
|
-
this.
|
|
230
|
-
let
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
return '=';
|
|
268
|
-
}
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (
|
|
299
|
-
return
|
|
300
|
-
}
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (this._sign.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
};
|
|
331
|
-
this.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
//
|
|
472
|
-
//
|
|
473
|
-
//
|
|
474
|
-
//
|
|
475
|
-
//
|
|
476
|
-
//
|
|
477
|
-
//
|
|
478
|
-
//
|
|
479
|
-
//
|
|
480
|
-
//
|
|
481
|
-
//
|
|
482
|
-
//
|
|
483
|
-
//
|
|
484
|
-
//
|
|
485
|
-
//
|
|
486
|
-
//
|
|
487
|
-
//
|
|
488
|
-
//
|
|
489
|
-
// }
|
|
490
|
-
//
|
|
491
|
-
//
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
//
|
|
497
|
-
//
|
|
498
|
-
//
|
|
499
|
-
//
|
|
500
|
-
//
|
|
501
|
-
//
|
|
502
|
-
//
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
//
|
|
507
|
-
//
|
|
508
|
-
//
|
|
509
|
-
//
|
|
510
|
-
//
|
|
511
|
-
//
|
|
512
|
-
//
|
|
513
|
-
//
|
|
514
|
-
//
|
|
515
|
-
//
|
|
516
|
-
//
|
|
517
|
-
// }
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
//
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
if (equations[
|
|
677
|
-
this.
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
this.
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
//
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}
|
|
714
|
-
get
|
|
715
|
-
return
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Equation = exports.PARTICULAR_SOLUTION = void 0;
|
|
4
|
+
const polynom_1 = require("./polynom");
|
|
5
|
+
const numeric_1 = require("../numeric");
|
|
6
|
+
const fraction_1 = require("../coefficients/fraction");
|
|
7
|
+
const nthRoot_1 = require("../coefficients/nthRoot");
|
|
8
|
+
var PARTICULAR_SOLUTION;
|
|
9
|
+
(function (PARTICULAR_SOLUTION) {
|
|
10
|
+
PARTICULAR_SOLUTION["real"] = "\\mathbb{R}";
|
|
11
|
+
PARTICULAR_SOLUTION["varnothing"] = "\\varnothing";
|
|
12
|
+
})(PARTICULAR_SOLUTION || (exports.PARTICULAR_SOLUTION = PARTICULAR_SOLUTION = {}));
|
|
13
|
+
class Equation {
|
|
14
|
+
/**
|
|
15
|
+
* Create an Equation using two polynoms.
|
|
16
|
+
* Markdown *support* is cool
|
|
17
|
+
* @param equations
|
|
18
|
+
*/
|
|
19
|
+
constructor(...equations) {
|
|
20
|
+
// Undetermined texSolutions.
|
|
21
|
+
this._varnothing = PARTICULAR_SOLUTION.varnothing;
|
|
22
|
+
this._real = PARTICULAR_SOLUTION.real;
|
|
23
|
+
this.hasVariable = (letter) => {
|
|
24
|
+
return this.variables.includes(letter);
|
|
25
|
+
};
|
|
26
|
+
// ------------------------------------------
|
|
27
|
+
// Creation / parsing functions
|
|
28
|
+
// -----------------------------------------------
|
|
29
|
+
this._randomizeDefaults = {
|
|
30
|
+
degree: 2
|
|
31
|
+
};
|
|
32
|
+
// ------------------------------------------
|
|
33
|
+
this.parse = (equationString) => {
|
|
34
|
+
let pStr, strSign;
|
|
35
|
+
// Find the string separator
|
|
36
|
+
strSign = this._findSign(equationString);
|
|
37
|
+
if (strSign === false) {
|
|
38
|
+
console.error('The equation is not valid (no sign found)');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// The StrSign is found
|
|
42
|
+
pStr = equationString.split(strSign);
|
|
43
|
+
return this.create(new polynom_1.Polynom(pStr[0]), new polynom_1.Polynom(pStr[1]), this._formatSign(strSign));
|
|
44
|
+
};
|
|
45
|
+
this.create = (left, right, sign) => {
|
|
46
|
+
this._left = left;
|
|
47
|
+
this._right = right;
|
|
48
|
+
this._sign = this._formatSign(sign);
|
|
49
|
+
return this;
|
|
50
|
+
};
|
|
51
|
+
this.clone = () => {
|
|
52
|
+
return new Equation().create(this._left.clone(), this._right.clone(), this._sign + '');
|
|
53
|
+
};
|
|
54
|
+
// -----------------------------------------------
|
|
55
|
+
// Equations generators and randomizers
|
|
56
|
+
this.randomize = (opts, sign) => {
|
|
57
|
+
// TODO: Generate equations randomly, using config.
|
|
58
|
+
return new Equation().create(new polynom_1.Polynom(), new polynom_1.Polynom(), sign);
|
|
59
|
+
};
|
|
60
|
+
// -----------------------------------------------
|
|
61
|
+
/**
|
|
62
|
+
* Reorder will move all monoms containing a letter on the left, all the other on the right.
|
|
63
|
+
*/
|
|
64
|
+
this.moveLeft = () => {
|
|
65
|
+
this._left = this._left.clone().subtract(this._right);
|
|
66
|
+
this._right.zero();
|
|
67
|
+
return this;
|
|
68
|
+
};
|
|
69
|
+
this.reorder = (allLeft) => {
|
|
70
|
+
// Move all monoms of degree greater than 0 to the left.
|
|
71
|
+
// and all zero degree monoms to the right.
|
|
72
|
+
this._left.subtract(this._right);
|
|
73
|
+
this._right.zero();
|
|
74
|
+
this._left.reorder();
|
|
75
|
+
// we eant all left (so equal zero) : it's done !
|
|
76
|
+
if (allLeft)
|
|
77
|
+
return this;
|
|
78
|
+
// Fetch all zero degree monoms.
|
|
79
|
+
this._left.monoms
|
|
80
|
+
.filter(m => m.degree().isZero())
|
|
81
|
+
.forEach(m => {
|
|
82
|
+
const move = m.clone();
|
|
83
|
+
this._left.subtract(move);
|
|
84
|
+
this._right.subtract(move);
|
|
85
|
+
});
|
|
86
|
+
// Reorder the left and right polynoms
|
|
87
|
+
this._left.reorder();
|
|
88
|
+
this._right.reorder();
|
|
89
|
+
return this;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Multiply by the lcm denominator and divide by the gcm numerators.
|
|
93
|
+
*/
|
|
94
|
+
this.simplify = () => {
|
|
95
|
+
this.multiply(numeric_1.Numeric.lcm(...this._left.getDenominators(), ...this._right.getDenominators()));
|
|
96
|
+
this.divide(numeric_1.Numeric.gcd(...this._left.getNumerators(), ...this._right.getNumerators()));
|
|
97
|
+
return this;
|
|
98
|
+
};
|
|
99
|
+
// -----------------------------------------------
|
|
100
|
+
// Equations operations
|
|
101
|
+
/**
|
|
102
|
+
* Reorder the polynom to have only one letter on the left, the rest on the right.
|
|
103
|
+
* @param letter
|
|
104
|
+
*/
|
|
105
|
+
this.isolate = (letter) => {
|
|
106
|
+
// Determine if we can isolate the variables.
|
|
107
|
+
// Both part of the equations must be of the first degree.
|
|
108
|
+
//TODO: handle equations of degree two or more ?
|
|
109
|
+
if (!this.degree(letter).isOne()) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
// Modify the equation to isolate the asked variable.
|
|
113
|
+
// TODO: must handle equations like 3xy+5y=4 => y = 4/(3x-5)
|
|
114
|
+
if (this.isMultiVariable()) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
// Isolate the letter.
|
|
118
|
+
let mMove, cMove;
|
|
119
|
+
// Start by moving everything to the left.
|
|
120
|
+
this._left.subtract(this._right);
|
|
121
|
+
this._right.zero();
|
|
122
|
+
let values = [...this._left.monoms];
|
|
123
|
+
for (let m of values) {
|
|
124
|
+
if (!m.hasLetter(letter)) {
|
|
125
|
+
mMove = m.clone();
|
|
126
|
+
this._left.subtract(mMove);
|
|
127
|
+
this._right.subtract(mMove);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// In theory, we should have only one item on the left.
|
|
131
|
+
if (this._left.length !== 1) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
cMove = this._left.monoms[0].coefficient.clone();
|
|
135
|
+
this._left.divide(cMove);
|
|
136
|
+
this._right.divide(cMove);
|
|
137
|
+
return this;
|
|
138
|
+
};
|
|
139
|
+
this.replaceBy = (letter, P) => {
|
|
140
|
+
this._left.replaceBy(letter, P);
|
|
141
|
+
this._right.replaceBy(letter, P);
|
|
142
|
+
return this;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Multiple an equation by a fraction value.
|
|
146
|
+
* @param value
|
|
147
|
+
*/
|
|
148
|
+
this.multiply = (value) => {
|
|
149
|
+
// Make sure we have a fraction.
|
|
150
|
+
let F = new fraction_1.Fraction(value);
|
|
151
|
+
// Multiply each part of the equation by the fraction
|
|
152
|
+
this._left.multiply(F);
|
|
153
|
+
this._right.multiply(F);
|
|
154
|
+
// The sign of the inequation must be changed.
|
|
155
|
+
if (this._sign !== '=' && F.sign() === -1) {
|
|
156
|
+
this._reverseSign();
|
|
157
|
+
}
|
|
158
|
+
return this;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* divide an equation by a given value (transformed as a fraction)
|
|
162
|
+
*
|
|
163
|
+
* ```
|
|
164
|
+
* 8x+10=6x \vert 2
|
|
165
|
+
* 4x+5=3x
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* |>Alternatively with $3x-4$ maybe it's working ?
|
|
169
|
+
* $$\frac{3x}{5}$$
|
|
170
|
+
*
|
|
171
|
+
* @param value
|
|
172
|
+
* @returns {Equation}
|
|
173
|
+
*/
|
|
174
|
+
this.divide = (value) => {
|
|
175
|
+
// Make sure we have a fraction.
|
|
176
|
+
let F = new fraction_1.Fraction(value);
|
|
177
|
+
if (F.isZero()) {
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return this.multiply(F.invert());
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Get the degree of the equation
|
|
186
|
+
* @param letter
|
|
187
|
+
*/
|
|
188
|
+
this.degree = (letter) => {
|
|
189
|
+
return fraction_1.Fraction.max(this._left.degree(letter), this._right.degree(letter));
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Determine if the equation contains more than one letter/variable.
|
|
193
|
+
*/
|
|
194
|
+
this.isMultiVariable = () => {
|
|
195
|
+
return this._left.isMultiVariable || this._right.isMultiVariable;
|
|
196
|
+
};
|
|
197
|
+
this.letters = () => {
|
|
198
|
+
// @ts-ignore
|
|
199
|
+
return [...new Set([...this._left.letters(), ...this._right.letters()])];
|
|
200
|
+
};
|
|
201
|
+
// -----------------------------------------------
|
|
202
|
+
// Equations helpers
|
|
203
|
+
// -----------------------------------------------
|
|
204
|
+
// -----------------------------------------------
|
|
205
|
+
this.solve = () => {
|
|
206
|
+
// Initialise the variables:
|
|
207
|
+
this._solutions = [];
|
|
208
|
+
// TODO: consolidate solving equations (inequations vs equations)
|
|
209
|
+
// TODO: work with not natural degrees ?
|
|
210
|
+
this._polynom = this._left.clone().subtract(this._right);
|
|
211
|
+
switch (this._polynom.degree().value) {
|
|
212
|
+
case 0:
|
|
213
|
+
case 1:
|
|
214
|
+
this._solveDegree1();
|
|
215
|
+
break;
|
|
216
|
+
case 2:
|
|
217
|
+
this._solveDegree2();
|
|
218
|
+
break;
|
|
219
|
+
default:
|
|
220
|
+
this._solveDegree3plus();
|
|
221
|
+
}
|
|
222
|
+
// cleanup the solutions.
|
|
223
|
+
this._solutions = Equation.makeSolutionsUnique(this._solutions);
|
|
224
|
+
return this;
|
|
225
|
+
};
|
|
226
|
+
this.test = (values) => {
|
|
227
|
+
return this.left.evaluate(values).isEqual(this.right.evaluate(values));
|
|
228
|
+
};
|
|
229
|
+
this.isSameAs = (equ) => {
|
|
230
|
+
let p1 = equ.clone().moveLeft().left, p2 = this.clone().moveLeft().left;
|
|
231
|
+
// They are the same.
|
|
232
|
+
return p1.isEqual(p2) || p1.isOpposedAt(p2);
|
|
233
|
+
};
|
|
234
|
+
this.isLinearTo = (equ) => {
|
|
235
|
+
// Move all left.
|
|
236
|
+
let p1 = equ.clone().moveLeft().simplify().left, p2 = this.clone().moveLeft().simplify().left;
|
|
237
|
+
// They are the same.
|
|
238
|
+
return p1.isEqual(p2) || p1.isOpposedAt(p2);
|
|
239
|
+
};
|
|
240
|
+
this._findSign = (equationString) => {
|
|
241
|
+
let strSign = '';
|
|
242
|
+
if (equationString.includes('geq')) {
|
|
243
|
+
return (equationString.includes('\\geq')) ? '\\geq' : 'geq';
|
|
244
|
+
}
|
|
245
|
+
else if (equationString.includes('leq')) {
|
|
246
|
+
return (equationString.includes('\\leq')) ? '\\leq' : 'leq';
|
|
247
|
+
}
|
|
248
|
+
else if (equationString.includes('>=')) {
|
|
249
|
+
return '>=';
|
|
250
|
+
}
|
|
251
|
+
else if (equationString.includes('=>')) {
|
|
252
|
+
return '=>';
|
|
253
|
+
}
|
|
254
|
+
else if (equationString.includes('>')) {
|
|
255
|
+
return '>';
|
|
256
|
+
}
|
|
257
|
+
else if (equationString.includes('<=')) {
|
|
258
|
+
return '<=';
|
|
259
|
+
}
|
|
260
|
+
else if (equationString.includes('=<')) {
|
|
261
|
+
return '=<';
|
|
262
|
+
}
|
|
263
|
+
else if (equationString.includes('<')) {
|
|
264
|
+
return '<';
|
|
265
|
+
}
|
|
266
|
+
else if (equationString.includes('=')) {
|
|
267
|
+
return '=';
|
|
268
|
+
}
|
|
269
|
+
if (strSign === '') {
|
|
270
|
+
console.log('Equation: parse string : sign not found');
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
// -----------------------------------------------
|
|
275
|
+
// Equations solving algorithms
|
|
276
|
+
this._formatSign = (signStr) => {
|
|
277
|
+
if (signStr === undefined) {
|
|
278
|
+
return '=';
|
|
279
|
+
}
|
|
280
|
+
if (signStr.includes('geq')) {
|
|
281
|
+
return '>=';
|
|
282
|
+
}
|
|
283
|
+
else if (signStr.includes('>=')) {
|
|
284
|
+
return '>=';
|
|
285
|
+
}
|
|
286
|
+
else if (signStr.includes('=>')) {
|
|
287
|
+
return '>=';
|
|
288
|
+
}
|
|
289
|
+
else if (signStr.includes('>')) {
|
|
290
|
+
return '>';
|
|
291
|
+
}
|
|
292
|
+
else if (signStr.includes('leq')) {
|
|
293
|
+
return '<=';
|
|
294
|
+
}
|
|
295
|
+
else if (signStr.includes('<=')) {
|
|
296
|
+
return '<=';
|
|
297
|
+
}
|
|
298
|
+
else if (signStr.includes('=<')) {
|
|
299
|
+
return '<=';
|
|
300
|
+
}
|
|
301
|
+
else if (signStr.includes('<')) {
|
|
302
|
+
return '<';
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return '=';
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
this._reverseSign = () => {
|
|
309
|
+
if (this._sign === '=') {
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
if (this._sign.includes('<')) {
|
|
313
|
+
this._sign.replace('<', '>');
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
if (this._sign.includes('>')) {
|
|
317
|
+
this._sign.replace('>', '<');
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
return this;
|
|
321
|
+
};
|
|
322
|
+
this.isGreater = () => {
|
|
323
|
+
if (this._sign.indexOf('>') !== -1) {
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
return this._sign.indexOf('geq') !== -1;
|
|
327
|
+
};
|
|
328
|
+
this.isStrictEqual = () => {
|
|
329
|
+
return this._sign === '=';
|
|
330
|
+
};
|
|
331
|
+
this.isAlsoEqual = () => {
|
|
332
|
+
if (this._sign.indexOf('=') !== -1) {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
if (this._sign.indexOf('geq') !== -1) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
if (this._sign.indexOf('leq') !== -1) {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
this._solveDegree1 = (letter) => {
|
|
343
|
+
const m1 = this._polynom.monomByDegree(1, letter).coefficient, m0 = this._polynom.monomByDegree(0, letter).coefficient, v = m0.clone().opposed().divide(m1);
|
|
344
|
+
let s, d;
|
|
345
|
+
if (this.isStrictEqual()) {
|
|
346
|
+
if (m1.value === 0) {
|
|
347
|
+
// In this case, the coefficient of the x variable is zero.
|
|
348
|
+
if (m0.value === 0) {
|
|
349
|
+
this._solutions = [{
|
|
350
|
+
tex: this._real,
|
|
351
|
+
display: "RR",
|
|
352
|
+
value: NaN,
|
|
353
|
+
exact: false
|
|
354
|
+
}];
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
this._solutions = [{
|
|
358
|
+
tex: this._varnothing,
|
|
359
|
+
display: "O/",
|
|
360
|
+
value: NaN,
|
|
361
|
+
exact: false
|
|
362
|
+
}];
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
this._solutions = [{
|
|
367
|
+
tex: v.tex,
|
|
368
|
+
display: v.display,
|
|
369
|
+
value: v.value,
|
|
370
|
+
exact: v
|
|
371
|
+
}];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
if (m1.value === 0) {
|
|
376
|
+
// In this case, the coefficient of the x variable is zero.
|
|
377
|
+
if (m0.value === 0 && this.isAlsoEqual()) {
|
|
378
|
+
s = '\\mathbb{R}';
|
|
379
|
+
d = "RR";
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
if (m0.value > 0) {
|
|
383
|
+
s = this.isGreater() ? this._real : this._varnothing;
|
|
384
|
+
s = this.isGreater() ? "RR" : "O/";
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
s = !this.isGreater() ? this._real : this._varnothing;
|
|
388
|
+
s = !this.isGreater() ? "RR" : "O/";
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
// Must handle the case if the m1 monom is negative.
|
|
394
|
+
if ((this.isGreater() && m1.sign() === 1) || (!this.isGreater() && m1.sign() === -1)) {
|
|
395
|
+
s = `\\left${this.isAlsoEqual() ? '[' : ']'}${v.tex};+\\infty\\right[`;
|
|
396
|
+
d = `${this.isAlsoEqual() ? '[' : ']'}${v.tex};+oo[`;
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
s = `\\left]-\\infty;${v.tex} \\right${this.isAlsoEqual() ? ']' : '['}`;
|
|
400
|
+
d = `]-oo;${v.tex}${this.isAlsoEqual() ? ']' : '['}`;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
this._solutions = [{
|
|
404
|
+
tex: s,
|
|
405
|
+
display: d,
|
|
406
|
+
value: NaN,
|
|
407
|
+
exact: false
|
|
408
|
+
}];
|
|
409
|
+
}
|
|
410
|
+
return this._solutions;
|
|
411
|
+
};
|
|
412
|
+
this._solveDegree2 = (letter) => {
|
|
413
|
+
let aF = this._polynom.monomByDegree(2, letter).coefficient, bF = this._polynom.monomByDegree(1, letter).coefficient, cF = this._polynom.monomByDegree(0, letter).coefficient, delta, nthDelta, lcm = numeric_1.Numeric.lcm(aF.denominator, bF.denominator, cF.denominator), a = aF.multiply(lcm).value, b = bF.multiply(lcm).value, c = cF.multiply(lcm).value, realX1, realX2, sX1, sX2;
|
|
414
|
+
delta = b * b - 4 * a * c;
|
|
415
|
+
if (delta > 0) {
|
|
416
|
+
realX1 = (-b - Math.sqrt(delta)) / (2 * a);
|
|
417
|
+
realX2 = (-b + Math.sqrt(delta)) / (2 * a);
|
|
418
|
+
if (delta > 1.0e5) {
|
|
419
|
+
// The delta is too big to be parsed !
|
|
420
|
+
let v1 = ((-b - Math.sqrt(delta)) / (2 * a)).toFixed(5), v2 = ((-b + Math.sqrt(delta)) / (2 * a)).toFixed(5);
|
|
421
|
+
this._solutions = [
|
|
422
|
+
{
|
|
423
|
+
tex: v1,
|
|
424
|
+
display: v1,
|
|
425
|
+
value: realX1,
|
|
426
|
+
exact: false
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
tex: v2,
|
|
430
|
+
display: v2,
|
|
431
|
+
value: realX2,
|
|
432
|
+
exact: false
|
|
433
|
+
}
|
|
434
|
+
];
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
nthDelta = new nthRoot_1.NthRoot(delta).reduce();
|
|
438
|
+
if (nthDelta.hasRadical()) {
|
|
439
|
+
// -b +- coeff\sqrt{radical}
|
|
440
|
+
// -------------------------
|
|
441
|
+
// 2a
|
|
442
|
+
let gcd = numeric_1.Numeric.gcd(b, 2 * a, nthDelta.coefficient), am = a / gcd, bm = b / gcd;
|
|
443
|
+
nthDelta.coefficient = nthDelta.coefficient / gcd;
|
|
444
|
+
if (a < 0) {
|
|
445
|
+
am = -am;
|
|
446
|
+
bm = -bm;
|
|
447
|
+
}
|
|
448
|
+
let tex1 = "", tex2 = "", display1 = "", display2 = "";
|
|
449
|
+
tex1 = `${bm !== 0 ? ((-bm) + ' - ') : ''}${nthDelta.tex}`;
|
|
450
|
+
tex2 = `${bm !== 0 ? ((-bm) + ' + ') : ''}${nthDelta.tex}`;
|
|
451
|
+
display1 = `${bm !== 0 ? ((-bm) + ' - ') : ''}${nthDelta.display}`;
|
|
452
|
+
display2 = `${bm !== 0 ? ((-bm) + ' + ') : ''}${nthDelta.display}`;
|
|
453
|
+
if (am !== 1) {
|
|
454
|
+
tex1 = `\\frac{ ${tex1} }{ ${2 * am} }`;
|
|
455
|
+
tex2 = `\\frac{ ${tex2} }{ ${2 * am} }`;
|
|
456
|
+
}
|
|
457
|
+
this._solutions = [
|
|
458
|
+
{
|
|
459
|
+
tex: tex1,
|
|
460
|
+
display: tex1,
|
|
461
|
+
value: realX1,
|
|
462
|
+
exact: false
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
tex: tex2,
|
|
466
|
+
display: tex2,
|
|
467
|
+
value: realX2,
|
|
468
|
+
exact: false
|
|
469
|
+
},
|
|
470
|
+
];
|
|
471
|
+
// if (b !== 0) {
|
|
472
|
+
// if (2 * a / gcd === 1) {
|
|
473
|
+
// this._solutions = [
|
|
474
|
+
// {
|
|
475
|
+
// tex: `${-b / gcd} - ${nthDelta.tex}`,
|
|
476
|
+
// value: realX1,
|
|
477
|
+
// exact: false // TODO: implement exact value with nthroot
|
|
478
|
+
// },
|
|
479
|
+
// {
|
|
480
|
+
// tex: `${-b / gcd} + ${nthDelta.tex}`,
|
|
481
|
+
// value: realX2,
|
|
482
|
+
// exact: false
|
|
483
|
+
// },
|
|
484
|
+
//
|
|
485
|
+
// ]
|
|
486
|
+
// } else {
|
|
487
|
+
// this._solutions = [
|
|
488
|
+
// {
|
|
489
|
+
// tex: `\\frac{${-b / gcd} - ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
490
|
+
// value: realX1,
|
|
491
|
+
// exact: false
|
|
492
|
+
// },
|
|
493
|
+
// {
|
|
494
|
+
// tex: `\\frac{${-b / gcd} + ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
495
|
+
// value: realX2,
|
|
496
|
+
// exact: false
|
|
497
|
+
// },
|
|
498
|
+
// ]
|
|
499
|
+
// }
|
|
500
|
+
// } else {
|
|
501
|
+
// if (2 * a / gcd === 1) {
|
|
502
|
+
// this._solutions = [
|
|
503
|
+
// {
|
|
504
|
+
// tex: `- ${nthDelta.tex}`,
|
|
505
|
+
// value: realX1,
|
|
506
|
+
// exact: false
|
|
507
|
+
// },
|
|
508
|
+
// {
|
|
509
|
+
// tex: `${nthDelta.tex}`,
|
|
510
|
+
// value: realX2,
|
|
511
|
+
// exact: false
|
|
512
|
+
// },
|
|
513
|
+
// ]
|
|
514
|
+
// } else {
|
|
515
|
+
// this._solutions = [
|
|
516
|
+
// {
|
|
517
|
+
// tex: `\\frac{- ${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
518
|
+
// value: realX1,
|
|
519
|
+
// exact: false
|
|
520
|
+
// },
|
|
521
|
+
// {
|
|
522
|
+
// tex: `\\frac{${nthDelta.tex} }{ ${2 * a / gcd} }`,
|
|
523
|
+
// value: realX2,
|
|
524
|
+
// exact: false
|
|
525
|
+
// },
|
|
526
|
+
// ]
|
|
527
|
+
// }
|
|
528
|
+
// }
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
// -b +- d / 2a
|
|
532
|
+
const S1 = new fraction_1.Fraction(-b - nthDelta.coefficient, 2 * a).reduce(), S2 = new fraction_1.Fraction(-b + nthDelta.coefficient, 2 * a).reduce();
|
|
533
|
+
this._solutions = [
|
|
534
|
+
{
|
|
535
|
+
tex: S1.frac,
|
|
536
|
+
display: S1.display,
|
|
537
|
+
value: realX1,
|
|
538
|
+
exact: S1
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
tex: S2.frac,
|
|
542
|
+
display: S2.display,
|
|
543
|
+
value: realX2,
|
|
544
|
+
exact: S2
|
|
545
|
+
}
|
|
546
|
+
];
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
else if (delta === 0) {
|
|
551
|
+
const sol = new fraction_1.Fraction(-b, 2 * a).reduce();
|
|
552
|
+
this._solutions = [{
|
|
553
|
+
tex: sol.frac,
|
|
554
|
+
display: sol.display,
|
|
555
|
+
value: sol.value,
|
|
556
|
+
exact: sol
|
|
557
|
+
}];
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
this._solutions = [{
|
|
561
|
+
tex: this._varnothing,
|
|
562
|
+
display: "O/",
|
|
563
|
+
value: NaN,
|
|
564
|
+
exact: false
|
|
565
|
+
}];
|
|
566
|
+
}
|
|
567
|
+
// Handle now the inequations.
|
|
568
|
+
if (!this.isStrictEqual()) {
|
|
569
|
+
if (this._solutions.length === 2) {
|
|
570
|
+
sX1 = (realX1 < realX2) ? this._solutions[0].tex : this._solutions[1].tex;
|
|
571
|
+
sX2 = (realX1 < realX2) ? this._solutions[1].tex : this._solutions[0].tex;
|
|
572
|
+
if ((this.isGreater() && aF.sign() === 1) || (!this.isGreater() && aF.sign() === -1)) {
|
|
573
|
+
this._solutions = [{
|
|
574
|
+
tex: `\\left]-\\infty ; ${sX1}\\right${this.isAlsoEqual() ? ']' : '['} \\cup \\left${this.isAlsoEqual() ? '[' : ']'}${sX2};+\\infty\\right[`,
|
|
575
|
+
display: `]-oo;${sX1}${this.isAlsoEqual() ? ']' : '['}uu${this.isAlsoEqual() ? '[' : ']'}${sX2};+oo[`,
|
|
576
|
+
value: NaN,
|
|
577
|
+
exact: false
|
|
578
|
+
}
|
|
579
|
+
];
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
this._solutions = [{
|
|
583
|
+
tex: `\\left${this.isAlsoEqual() ? '[' : ']'}${sX1} ; ${sX2}\\right${this.isAlsoEqual() ? ']' : '['}`,
|
|
584
|
+
display: `${this.isAlsoEqual() ? '[' : ']'}${sX1};${sX2}${this.isAlsoEqual() ? ']' : '['}`,
|
|
585
|
+
value: NaN,
|
|
586
|
+
exact: false
|
|
587
|
+
}];
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else if (this._solutions.length === 1 && this._solutions[0].tex !== this._varnothing) {
|
|
591
|
+
if (!this.isAlsoEqual()) {
|
|
592
|
+
if ((this.isGreater() && aF.sign() === 1) || (!this.isGreater() && aF.sign() === -1)) {
|
|
593
|
+
this._solutions = [{
|
|
594
|
+
tex: `\\left]-\\infty ; ${this._solutions[0].tex}\\right[ \\cup \\left]${this._solutions[0].tex};+\\infty\\right[`,
|
|
595
|
+
display: `]-oo;${this._solutions[0].tex}[uu]${this._solutions[0].tex};+oo[`,
|
|
596
|
+
value: NaN,
|
|
597
|
+
exact: false
|
|
598
|
+
}
|
|
599
|
+
];
|
|
600
|
+
}
|
|
601
|
+
else {
|
|
602
|
+
this._solutions = [{
|
|
603
|
+
tex: this._varnothing,
|
|
604
|
+
display: "O/",
|
|
605
|
+
value: NaN,
|
|
606
|
+
exact: false
|
|
607
|
+
}];
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
if ((this.isGreater() && aF.sign() === 1) || (!this.isGreater() && aF.sign() === -1)) {
|
|
612
|
+
this._solutions = [{
|
|
613
|
+
tex: this._real,
|
|
614
|
+
display: "RR",
|
|
615
|
+
value: NaN,
|
|
616
|
+
exact: false
|
|
617
|
+
}];
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
// this._texSolutions = [ this._texSolutions[0] ];
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
if (this.isGreater()) {
|
|
626
|
+
this._solutions = [{
|
|
627
|
+
tex: aF.sign() === 1 ? this._real : this._varnothing,
|
|
628
|
+
display: aF.sign() === 1 ? "RR" : "O/",
|
|
629
|
+
value: NaN,
|
|
630
|
+
exact: false
|
|
631
|
+
}];
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
this._solutions = [{
|
|
635
|
+
tex: aF.sign() === -1 ? this._real : this._varnothing,
|
|
636
|
+
display: aF.sign() === -1 ? "RR" : "O/",
|
|
637
|
+
value: NaN,
|
|
638
|
+
exact: false
|
|
639
|
+
}];
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return this._solutions;
|
|
644
|
+
};
|
|
645
|
+
this._solveDegree3plus = (letter) => {
|
|
646
|
+
// Push everything to the left
|
|
647
|
+
// factorize
|
|
648
|
+
// solve each factors.
|
|
649
|
+
let equ = this.clone().moveLeft();
|
|
650
|
+
equ.left.factorize();
|
|
651
|
+
this._solutions = [];
|
|
652
|
+
equ.left.factors.forEach(factor => {
|
|
653
|
+
if (factor.degree(letter).leq(2)) {
|
|
654
|
+
let factorAsEquation = new Equation(factor, 0);
|
|
655
|
+
factorAsEquation.solve();
|
|
656
|
+
factorAsEquation.solutions.forEach(solution => {
|
|
657
|
+
this._solutions.push(solution);
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
console.log(factor.tex, ': cannot actually get the solution of this equation');
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
// TODO: check equation resolution for more than degree 2
|
|
665
|
+
// this._solutions = [{tex: 'solve x - not yet handled', value: NaN, exact: false}]; // ESLint remove system :(
|
|
666
|
+
return this._solutions;
|
|
667
|
+
};
|
|
668
|
+
// Default equation
|
|
669
|
+
this._left = new polynom_1.Polynom().zero();
|
|
670
|
+
this._right = new polynom_1.Polynom().zero();
|
|
671
|
+
this._sign = '=';
|
|
672
|
+
if (equations.length === 1) {
|
|
673
|
+
if (equations[0] instanceof Equation) {
|
|
674
|
+
return equations[0].clone();
|
|
675
|
+
}
|
|
676
|
+
else if (typeof equations[0] === 'string') {
|
|
677
|
+
this.parse(equations[0]);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
else if (equations.length === 2) {
|
|
681
|
+
if (equations[0] instanceof polynom_1.Polynom) {
|
|
682
|
+
this.left = equations[0].clone();
|
|
683
|
+
}
|
|
684
|
+
else if (typeof equations[0] === 'string') {
|
|
685
|
+
this.left = new polynom_1.Polynom(equations[0]);
|
|
686
|
+
}
|
|
687
|
+
if (equations[1] instanceof polynom_1.Polynom) {
|
|
688
|
+
this.right = equations[1].clone();
|
|
689
|
+
}
|
|
690
|
+
else if (typeof equations[1] === 'string') {
|
|
691
|
+
this.right = new polynom_1.Polynom(equations[1]);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
// Return default empty equation
|
|
696
|
+
return this;
|
|
697
|
+
}
|
|
698
|
+
return this;
|
|
699
|
+
}
|
|
700
|
+
get left() {
|
|
701
|
+
return this._left;
|
|
702
|
+
}
|
|
703
|
+
set left(value) {
|
|
704
|
+
this._left = value;
|
|
705
|
+
}
|
|
706
|
+
get right() {
|
|
707
|
+
return this._right;
|
|
708
|
+
}
|
|
709
|
+
// ------------------------------------------
|
|
710
|
+
// Getter and setter
|
|
711
|
+
set right(value) {
|
|
712
|
+
this._right = value;
|
|
713
|
+
}
|
|
714
|
+
get sign() {
|
|
715
|
+
return this._sign;
|
|
716
|
+
}
|
|
717
|
+
set sign(value) {
|
|
718
|
+
// Set the sign value as formatted.
|
|
719
|
+
this._sign = this._formatSign(value);
|
|
720
|
+
}
|
|
721
|
+
// ------------------------------------------
|
|
722
|
+
get solutions() {
|
|
723
|
+
return this._solutions;
|
|
724
|
+
}
|
|
725
|
+
get isEquation() {
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
728
|
+
get solution() {
|
|
729
|
+
if (this._solutions.length === 1
|
|
730
|
+
&&
|
|
731
|
+
(this._solutions[0].tex === this._real
|
|
732
|
+
|| this._solutions[0].tex === this._varnothing
|
|
733
|
+
|| this._solutions[0].tex.includes('\\left'))) {
|
|
734
|
+
return `S = ${this._solutions[0]}`;
|
|
735
|
+
}
|
|
736
|
+
return `S = \\left{ ${this._solutions.map(x => x.tex).join(';')} \\right}`;
|
|
737
|
+
}
|
|
738
|
+
get isReal() {
|
|
739
|
+
if (this._solutions === undefined) {
|
|
740
|
+
this.solve();
|
|
741
|
+
}
|
|
742
|
+
return this._solutions[0].tex === this._real;
|
|
743
|
+
}
|
|
744
|
+
get isVarnothing() {
|
|
745
|
+
if (this._solutions === undefined) {
|
|
746
|
+
this.solve();
|
|
747
|
+
}
|
|
748
|
+
return this._solutions[0].tex === this._varnothing;
|
|
749
|
+
}
|
|
750
|
+
get signAsTex() {
|
|
751
|
+
if (this._sign === '>=' || this._sign === '=>' || this._sign === 'geq') {
|
|
752
|
+
return '\\geq';
|
|
753
|
+
}
|
|
754
|
+
if (this._sign === '<=' || this._sign === '=<' || this._sign === 'leq') {
|
|
755
|
+
return '\\leq';
|
|
756
|
+
}
|
|
757
|
+
return this._sign;
|
|
758
|
+
}
|
|
759
|
+
get tex() {
|
|
760
|
+
return `${this._left.tex}${this.signAsTex}${this._right.tex}`;
|
|
761
|
+
}
|
|
762
|
+
get display() {
|
|
763
|
+
return `${this._left.display}${this.signAsTex}${this._right.display}`;
|
|
764
|
+
}
|
|
765
|
+
get raw() {
|
|
766
|
+
return `${this._left.raw}${this.signAsTex}${this._right.raw}`;
|
|
767
|
+
}
|
|
768
|
+
get variables() {
|
|
769
|
+
return [...new Set(this._right.variables.concat(this._left.variables))];
|
|
770
|
+
}
|
|
771
|
+
get numberOfVars() {
|
|
772
|
+
return this.variables.length;
|
|
773
|
+
}
|
|
774
|
+
get randomizeDefaults() {
|
|
775
|
+
return this._randomizeDefaults;
|
|
776
|
+
}
|
|
777
|
+
set randomizeDefaults(value) {
|
|
778
|
+
this._randomizeDefaults = value;
|
|
779
|
+
}
|
|
780
|
+
static makeSolutionsUnique(solutions, sorted) {
|
|
781
|
+
let solutionAsTex = [], uniqueSolutions = solutions.filter(sol => {
|
|
782
|
+
if (!solutionAsTex.includes(sol.tex)) {
|
|
783
|
+
solutionAsTex.push(sol.tex);
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
if (sorted === true) {
|
|
791
|
+
uniqueSolutions.sort((a, b) => a.value - b.value);
|
|
792
|
+
}
|
|
793
|
+
return uniqueSolutions;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
exports.Equation = Equation;
|
|
786
797
|
//# sourceMappingURL=equation.js.map
|