pimath 0.0.127 → 0.0.129

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 (212) hide show
  1. package/dist/main.d.ts +39 -0
  2. package/{esm → dist}/maths/algebra/equation.d.ts +11 -10
  3. package/{esm → dist}/maths/algebra/linearSystem.d.ts +5 -4
  4. package/{esm → dist}/maths/algebra/monom.d.ts +5 -4
  5. package/{esm → dist}/maths/algebra/polynom.d.ts +11 -13
  6. package/{esm → dist}/maths/algebra/rational.d.ts +7 -9
  7. package/dist/maths/algebra/study/rationalStudy.d.ts +14 -0
  8. package/{esm → dist}/maths/algebra/study.d.ts +4 -7
  9. package/{esm → dist}/maths/geometry/circle.d.ts +9 -8
  10. package/{esm → dist}/maths/geometry/line.d.ts +17 -14
  11. package/{esm → dist}/maths/geometry/point.d.ts +11 -9
  12. package/{esm → dist}/maths/geometry/triangle.d.ts +4 -3
  13. package/{esm → dist}/maths/geometry/vector.d.ts +7 -10
  14. package/{esm → dist}/maths/randomization/random.d.ts +10 -7
  15. package/{esm → dist}/maths/randomization/rndFraction.d.ts +4 -3
  16. package/dist/maths/randomization/rndGeometryCircle.d.ts +13 -0
  17. package/{esm → dist}/maths/randomization/rndGeometryLine.d.ts +4 -3
  18. package/{esm → dist}/maths/randomization/rndGeometryPoint.d.ts +4 -3
  19. package/{esm → dist}/maths/randomization/rndMonom.d.ts +5 -4
  20. package/{esm → dist}/maths/randomization/rndPolynom.d.ts +5 -4
  21. package/{esm → dist}/maths/randomization/rndTypes.d.ts +7 -1
  22. package/dist/pimath.js +4239 -7819
  23. package/package.json +13 -7
  24. package/.eslintrc.js +0 -24
  25. package/.idea/$CACHE_FILE$ +0 -6
  26. package/.idea/PI.iml +0 -14
  27. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  28. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  29. package/.idea/misc.xml +0 -6
  30. package/.idea/modules.xml +0 -8
  31. package/.idea/php.xml +0 -19
  32. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]/shelved.patch +0 -192
  33. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30_[Default_Changelist]1/shelved.patch +0 -0
  34. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_07_11_2023_08_30__Default_Changelist_.xml +0 -4
  35. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43_[Default_Changelist]/shelved.patch +0 -2404
  36. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_10_43__Default_Changelist_.xml +0 -4
  37. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01_[Default_Changelist]/shelved.patch +0 -1362
  38. package/.idea/shelf/Uncommitted_changes_before_Checkout_at_09_11_2023_11_01__Default_Changelist_.xml +0 -4
  39. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31_[Default_Changelist]/shelved.patch +0 -90
  40. package/.idea/shelf/Uncommitted_changes_before_Update_at_24_07_2023_15_31__Default_Changelist_.xml +0 -4
  41. package/.idea/vcs.xml +0 -6
  42. package/dev/pimath.js +0 -7945
  43. package/dev/pimath.js.map +0 -1
  44. package/dist/pimath.js.map +0 -1
  45. package/dist/pimath.min.js +0 -2
  46. package/dist/pimath.min.js.map +0 -1
  47. package/docs/.nojekyll +0 -1
  48. package/docs/assets/highlight.css +0 -78
  49. package/docs/assets/main.js +0 -59
  50. package/docs/assets/navigation.js +0 -1
  51. package/docs/assets/search.js +0 -1
  52. package/docs/assets/style.css +0 -1383
  53. package/docs/classes/Logicalset.Logicalset.html +0 -217
  54. package/docs/classes/Polynom.Rational.html +0 -397
  55. package/docs/classes/Vector-1.Vector.html +0 -490
  56. package/docs/classes/Vector.Point.html +0 -337
  57. package/docs/classes/algebra_equation.Equation.html +0 -790
  58. package/docs/classes/algebra_linearSystem.LinearSystem.html +0 -404
  59. package/docs/classes/algebra_monom.Monom.html +0 -962
  60. package/docs/classes/algebra_polynom.Polynom.html +0 -1275
  61. package/docs/classes/coefficients_fraction.Fraction.html +0 -934
  62. package/docs/classes/geometry_circle.Circle.html +0 -472
  63. package/docs/classes/geometry_line.Line.html +0 -774
  64. package/docs/classes/geometry_triangle.Triangle.html +0 -429
  65. package/docs/classes/numeric.Numeric.html +0 -265
  66. package/docs/classes/shutingyard.Shutingyard.html +0 -250
  67. package/docs/enums/algebra_equation.PARTICULAR_SOLUTION.html +0 -83
  68. package/docs/enums/geometry_line.LinePropriety.html +0 -97
  69. package/docs/enums/shutingyard.ShutingyardMode.html +0 -97
  70. package/docs/enums/shutingyard.ShutingyardType.html +0 -111
  71. package/docs/index.html +0 -63
  72. package/docs/interfaces/algebra_equation.ISolution.html +0 -105
  73. package/docs/interfaces/algebra_polynom.IEuclidian.html +0 -87
  74. package/docs/interfaces/geometry_triangle.remarquableLines.html +0 -163
  75. package/docs/modules/Logicalset.html +0 -65
  76. package/docs/modules/Polynom.html +0 -65
  77. package/docs/modules/Vector-1.html +0 -65
  78. package/docs/modules/Vector.html +0 -65
  79. package/docs/modules/algebra_equation.html +0 -69
  80. package/docs/modules/algebra_linearSystem.html +0 -61
  81. package/docs/modules/algebra_monom.html +0 -65
  82. package/docs/modules/algebra_polynom.html +0 -69
  83. package/docs/modules/coefficients_fraction.html +0 -65
  84. package/docs/modules/geometry_circle.html +0 -61
  85. package/docs/modules/geometry_line.html +0 -65
  86. package/docs/modules/geometry_triangle.html +0 -65
  87. package/docs/modules/numeric.html +0 -61
  88. package/docs/modules/shutingyard.html +0 -75
  89. package/docs/types/algebra_monom.literalType.html +0 -61
  90. package/docs/types/algebra_polynom.PolynomParsingType.html +0 -56
  91. package/docs/types/coefficients_fraction.FractionParsingType.html +0 -56
  92. package/docs/types/shutingyard.Token.html +0 -63
  93. package/docs/types/shutingyard.tokenType.html +0 -68
  94. package/docs/variables/shutingyard.tokenConstant.html +0 -61
  95. package/esm/index.d.ts +0 -38
  96. package/esm/index.js +0 -44
  97. package/esm/index.js.map +0 -1
  98. package/esm/maths/algebra/equation.js +0 -797
  99. package/esm/maths/algebra/equation.js.map +0 -1
  100. package/esm/maths/algebra/linearSystem.js +0 -279
  101. package/esm/maths/algebra/linearSystem.js.map +0 -1
  102. package/esm/maths/algebra/logicalset.js +0 -158
  103. package/esm/maths/algebra/logicalset.js.map +0 -1
  104. package/esm/maths/algebra/monom.js +0 -909
  105. package/esm/maths/algebra/monom.js.map +0 -1
  106. package/esm/maths/algebra/polynom.js +0 -1305
  107. package/esm/maths/algebra/polynom.js.map +0 -1
  108. package/esm/maths/algebra/rational.js +0 -195
  109. package/esm/maths/algebra/rational.js.map +0 -1
  110. package/esm/maths/algebra/study/rationalStudy.d.ts +0 -28
  111. package/esm/maths/algebra/study/rationalStudy.js +0 -244
  112. package/esm/maths/algebra/study/rationalStudy.js.map +0 -1
  113. package/esm/maths/algebra/study.js +0 -380
  114. package/esm/maths/algebra/study.js.map +0 -1
  115. package/esm/maths/coefficients/fraction.js +0 -517
  116. package/esm/maths/coefficients/fraction.js.map +0 -1
  117. package/esm/maths/coefficients/nthRoot.js +0 -137
  118. package/esm/maths/coefficients/nthRoot.js.map +0 -1
  119. package/esm/maths/geometry/circle.js +0 -324
  120. package/esm/maths/geometry/circle.js.map +0 -1
  121. package/esm/maths/geometry/line.js +0 -485
  122. package/esm/maths/geometry/line.js.map +0 -1
  123. package/esm/maths/geometry/point.js +0 -167
  124. package/esm/maths/geometry/point.js.map +0 -1
  125. package/esm/maths/geometry/triangle.js +0 -276
  126. package/esm/maths/geometry/triangle.js.map +0 -1
  127. package/esm/maths/geometry/vector.js +0 -198
  128. package/esm/maths/geometry/vector.js.map +0 -1
  129. package/esm/maths/numeric.js +0 -136
  130. package/esm/maths/numeric.js.map +0 -1
  131. package/esm/maths/numexp.js +0 -186
  132. package/esm/maths/numexp.js.map +0 -1
  133. package/esm/maths/randomization/random.js +0 -79
  134. package/esm/maths/randomization/random.js.map +0 -1
  135. package/esm/maths/randomization/randomCore.js +0 -22
  136. package/esm/maths/randomization/randomCore.js.map +0 -1
  137. package/esm/maths/randomization/rndFraction.js +0 -44
  138. package/esm/maths/randomization/rndFraction.js.map +0 -1
  139. package/esm/maths/randomization/rndGeometryLine.js +0 -46
  140. package/esm/maths/randomization/rndGeometryLine.js.map +0 -1
  141. package/esm/maths/randomization/rndGeometryPoint.js +0 -61
  142. package/esm/maths/randomization/rndGeometryPoint.js.map +0 -1
  143. package/esm/maths/randomization/rndHelpers.js +0 -98
  144. package/esm/maths/randomization/rndHelpers.js.map +0 -1
  145. package/esm/maths/randomization/rndMonom.js +0 -53
  146. package/esm/maths/randomization/rndMonom.js.map +0 -1
  147. package/esm/maths/randomization/rndPolynom.js +0 -75
  148. package/esm/maths/randomization/rndPolynom.js.map +0 -1
  149. package/esm/maths/randomization/rndTypes.js +0 -3
  150. package/esm/maths/randomization/rndTypes.js.map +0 -1
  151. package/esm/maths/shutingyard.js +0 -443
  152. package/esm/maths/shutingyard.js.map +0 -1
  153. package/public/demo.css +0 -3
  154. package/public/index.html +0 -283
  155. package/public/matrices.html +0 -100
  156. package/public/playground.html +0 -168
  157. package/src/index.ts +0 -42
  158. package/src/maths/algebra/equation.ts +0 -897
  159. package/src/maths/algebra/linearSystem.ts +0 -370
  160. package/src/maths/algebra/logicalset.ts +0 -183
  161. package/src/maths/algebra/monom.ts +0 -1028
  162. package/src/maths/algebra/polynom.ts +0 -1537
  163. package/src/maths/algebra/rational.ts +0 -240
  164. package/src/maths/algebra/study/rationalStudy.ts +0 -287
  165. package/src/maths/algebra/study.ts +0 -506
  166. package/src/maths/coefficients/fraction.ts +0 -593
  167. package/src/maths/coefficients/nthRoot.ts +0 -148
  168. package/src/maths/geometry/circle.ts +0 -382
  169. package/src/maths/geometry/line.ts +0 -604
  170. package/src/maths/geometry/point.ts +0 -215
  171. package/src/maths/geometry/triangle.ts +0 -368
  172. package/src/maths/geometry/vector.ts +0 -242
  173. package/src/maths/numeric.ts +0 -162
  174. package/src/maths/numexp.ts +0 -184
  175. package/src/maths/randomization/random.ts +0 -80
  176. package/src/maths/randomization/randomCore.ts +0 -19
  177. package/src/maths/randomization/rndFraction.ts +0 -47
  178. package/src/maths/randomization/rndGeometryCircle.ts +0 -50
  179. package/src/maths/randomization/rndGeometryLine.ts +0 -53
  180. package/src/maths/randomization/rndGeometryPoint.ts +0 -69
  181. package/src/maths/randomization/rndHelpers.ts +0 -107
  182. package/src/maths/randomization/rndMonom.ts +0 -57
  183. package/src/maths/randomization/rndPolynom.ts +0 -90
  184. package/src/maths/randomization/rndTypes.ts +0 -43
  185. package/src/maths/shutingyard.ts +0 -496
  186. package/tests/algebra/equation.test.ts +0 -64
  187. package/tests/algebra/linear.test.ts +0 -58
  188. package/tests/algebra/monom.test.ts +0 -78
  189. package/tests/algebra/polynom.test.ts +0 -343
  190. package/tests/algebra/rationnal.test.ts +0 -64
  191. package/tests/algebra/study.test.ts +0 -48
  192. package/tests/coefficients/fraction.test.ts +0 -131
  193. package/tests/custom.test.ts +0 -33
  194. package/tests/geometry/circle.test.ts +0 -404
  195. package/tests/geometry/line.test.ts +0 -36
  196. package/tests/numeric.test.ts +0 -43
  197. package/tests/numexp.test.ts +0 -89
  198. package/tests/shutingyard.test.ts +0 -58
  199. package/tsconfig.json +0 -41
  200. package/tsconfig.testing.json +0 -28
  201. package/typedoc.katex.js +0 -11
  202. package/webpack-production-min.config.js +0 -26
  203. package/webpack-production.config.js +0 -26
  204. package/webpack.config.js +0 -26
  205. package/{esm → dist}/maths/algebra/logicalset.d.ts +6 -6
  206. package/{esm → dist}/maths/coefficients/fraction.d.ts +0 -0
  207. package/{esm → dist}/maths/coefficients/nthRoot.d.ts +0 -0
  208. package/{esm → dist}/maths/numeric.d.ts +0 -0
  209. package/{esm → dist}/maths/numexp.d.ts +3 -3
  210. /package/{esm → dist}/maths/randomization/randomCore.d.ts +0 -0
  211. /package/{esm → dist}/maths/randomization/rndHelpers.d.ts +0 -0
  212. /package/{esm → dist}/maths/shutingyard.d.ts +0 -0
@@ -1,797 +0,0 @@
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;
797
- //# sourceMappingURL=equation.js.map