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