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,370 +0,0 @@
1
- import {Equation, ISolution} from "./equation";
2
- import {Monom} from "./monom";
3
- import {Fraction} from "../coefficients/fraction";
4
- import {Polynom} from "./polynom";
5
- import {Numeric} from "../numeric";
6
-
7
- // TODO: Must check and rework
8
- export class LinearSystem {
9
- // Stores the original equations
10
- private _equations: Equation[];
11
- // Determine the letters in the linear system, usually ['x', 'y']
12
- private _letters: string[];
13
- // Resolution steps contains each steps
14
- // letter : target letter
15
- // steps: {system: current LinearSystem, operations: [*3,/5] or [[*3,*2], [,*5], [*2,]]}
16
- private _resolutionSteps: {
17
- [key: string]: {
18
- equations: Equation[],
19
- operations: (string[])[]
20
- }[]
21
- };
22
- // Get the solution of the equation
23
- private _solutions: { [letter: string]: ISolution };
24
-
25
- constructor(...equationStrings: (string | Equation)[]) {
26
- // TODO: allow construction to accept an array of values (like a matrix) to build the equations
27
- this._equations = [];
28
- this._letters = 'xyz'.split('');
29
-
30
- if (equationStrings !== undefined && equationStrings.length > 0) {
31
- this.parse(...equationStrings);
32
- }
33
-
34
- return this;
35
- }
36
-
37
- // ------------------------------------------
38
- // Getter and setter
39
- // ------------------------------------------
40
- get equations(): Equation[] {
41
- return this._equations;
42
- }
43
-
44
- set equations(value) {
45
- this._equations = value;
46
- }
47
-
48
- get letters(): string {
49
- return this._letters.join('')
50
- }
51
-
52
- set letters(value: string) {
53
- this._letters = value.split('');
54
- }
55
-
56
- get isSolvable(): boolean {
57
- let V = this.variables;
58
-
59
- // TODO: in some case, it is possible to resolve systems if there isn't the isSame number of vars and equations
60
- if (V.length !== this._equations.length) {
61
- return false;
62
- }
63
-
64
- //TODO: Must check if two equations isn't a linear combination of the others ?
65
-
66
- return true;
67
- }
68
-
69
- get variables(): string[] {
70
- return this._letters
71
- }
72
-
73
- get tex(): string {
74
- // Build the array of values.
75
- // Reorder
76
- // This clone the system :!!!
77
- //TODO: Avoid cloning this linear system
78
- let LS = this.clone().reorder(),
79
- letters = LS.variables
80
-
81
- return this.buildTex(LS.equations)
82
- }
83
-
84
- get solution(): string {
85
- let tex: string[] = [];
86
-
87
- if (this._solutions === undefined) {
88
- this.solve();
89
- }
90
-
91
- for (let letter in this._solutions) {
92
- if (this._solutions[letter].display === "RR") {
93
- return `\\left\\{ \\left(${this._letters.join(';')}\\right) \\big\\vert ${this.equations[0].tex} \\right\\}`;
94
- }
95
- if (this._solutions[letter].display === "O/") {
96
- return `\\varnothing`
97
- }
98
-
99
- tex.push(this._solutions[letter].tex);
100
- }
101
- return `\\left(${tex.join(';')}\\right)`;
102
- }
103
-
104
- get solutionAsDisplay(): string {
105
- let display: string[] = [];
106
-
107
- if (this._solutions === undefined) {
108
- this.solve();
109
- }
110
-
111
- for (let letter in this._solutions) {
112
- if (this._solutions[letter].display === "RR") {
113
- return `{(${this._letters.join(';')}) | ${this.equations[0].display} }`;
114
- }
115
- if (this._solutions[letter].display === "O/") {
116
- return "O/"
117
- }
118
-
119
- display.push(this._solutions[letter].display);
120
- }
121
- return `(${display.join(';')})`;
122
- }
123
-
124
- buildTex = (equations: Equation[], operators?: (string[])[]): string => {
125
- let equStr: string[],
126
- equArray: string[] = [],
127
- m: Monom,
128
- letters: string[] = []
129
-
130
- // Get the letters from the linear system
131
- for (let equ of equations) {
132
- letters = letters.concat(equ.letters())
133
- }
134
- letters = [...new Set(letters)]
135
- letters.sort()
136
-
137
- for (let i = 0; i < equations.length; i++) {
138
- let equ = equations[i]
139
-
140
- equStr = [];
141
- for (let L of letters) {
142
- m = equ.left.monomByLetter(L);
143
-
144
- if (equStr.length === 0) {
145
- equStr.push(m.isZero() ? '' : m.tex);
146
- } else {
147
- equStr.push(m.isZero() ? '' : ((m.coefficient.sign() === 1) ? '+' : '') + m.tex);
148
- }
149
- }
150
-
151
- // Add the equal sign
152
- equStr.push('=');
153
-
154
- // Add the right hand part of the equation (should be only a number, because it has been reordered)
155
- equStr.push(equ.right.tex);
156
-
157
- // Add the operations if existing
158
- if (operators !== undefined && operators[i] !== undefined) {
159
- // add extra space at the end of the equation
160
- equStr[equStr.length - 1] = equStr[equStr.length - 1] + ' \\phantom{\\quad}'
161
- for (let o of operators[i]) {
162
- equStr.push(`\\ \\cdot\\ ${o.startsWith('-') ? "\\left(" + o + "\\right)" : o}`)
163
- }
164
- }
165
-
166
- // Add to the list.
167
- equArray.push(equStr.join('&'));
168
- }
169
-
170
- let operatorsColumns = 0
171
- if (operators !== undefined && operators.length > 0) {
172
- operatorsColumns = operators[0].length
173
- }
174
- return `\\left\\{\\begin{array}{${"r".repeat(letters.length)}cl ${"|l".repeat(operatorsColumns)}}${equArray.join('\\\\\ ')}\\end{array}\\right.`;
175
- }
176
-
177
- stepTex = (letter: string): string => {
178
- const steps = this._resolutionSteps[letter]
179
-
180
- if (steps === undefined) {
181
- return ''
182
- }
183
-
184
- // steps = { equations[], operations: [[],[]]
185
- let tex: string[] = []
186
- for (let i = 0; i < steps.length; i++) {
187
- tex.push(this.buildTex(steps[i].equations, steps[i].operations))
188
- }
189
-
190
- return `\\begin{aligned}&${tex.join('\\\\&')}\\end{aligned}`
191
-
192
- }
193
-
194
-
195
- get resolutionSteps(): { [p: string]: { equations: Equation[]; operations: string[][] }[] } {
196
- return this._resolutionSteps;
197
- }
198
-
199
- // ------------------------------------------
200
- // Creation / parsing functions
201
-
202
- // ------------------------------------------
203
- parse = (...equations: (string | Equation)[]): LinearSystem => {
204
- // make the original equations
205
- this._equations = equations.map(value => new Equation(value));
206
- // get the letters.
207
- this._findLetters();
208
- return this;
209
- };
210
-
211
- clone = (): LinearSystem => {
212
- return new LinearSystem().parse(...this._equations.map(equ => equ.clone()));
213
- };
214
-
215
- // ------------------------------------------
216
- reorder = (): LinearSystem => {
217
- for (let E of this._equations) {
218
- E.reorder();
219
- }
220
- return this;
221
- };
222
-
223
-
224
- // -----------------------------------------------
225
- // Equations solving algorithms
226
-
227
- solve = (withResolution?: boolean): LinearSystem => {
228
- // Solve it by linear
229
- this._solutions = {};
230
- this._resolutionSteps = {};
231
-
232
- // Reorder all equations.
233
- this.reorder();
234
-
235
- if (withResolution === undefined) {
236
- withResolution = false
237
- }
238
-
239
- for (let letter of this.variables) {
240
- this._solutions[letter] = this._solveOneLetter(letter, withResolution)
241
- }
242
-
243
- // TODO: LinearSystem - solve: optimization and handle undetermined and undefined systems.
244
- return this;
245
- };
246
-
247
- mergeEquations = (eq1: Equation, eq2: Equation, factor1: Fraction, factor2: Fraction): Equation => {
248
- // Set and clone the equations.
249
-
250
- let eq1multiplied = eq1.clone().multiply(new Fraction(factor1)),
251
- eq2multiplied = eq2.clone().multiply(new Fraction(factor2));
252
-
253
- // Add both equations together.
254
- eq1multiplied.left.add(eq2multiplied.left);
255
- eq1multiplied.right.add(eq2multiplied.right);
256
-
257
- return eq1multiplied;
258
- }
259
-
260
- private _findLetters = (): LinearSystem => {
261
- // Find all letters used.
262
- let variables: Set<string> = new Set();
263
-
264
- for (let equ of this._equations) {
265
- variables = new Set([...variables, ...equ.variables]);
266
- }
267
-
268
- this._letters = [...variables];
269
- this._letters.sort()
270
- return this;
271
- }
272
-
273
- private _linearReduction(eq1: Equation, eq2: Equation, letter: string): { merged: Equation, factors: Fraction[] } {
274
- // Get the monom for the particular letter.
275
- let c1 = eq1.left.monomByDegree(1, letter).coefficient.clone(),
276
- c2 = eq2.left.monomByDegree(1, letter).coefficient.clone().opposed();
277
-
278
- // Reduce c1 and c2 by the gcd
279
- const gcdN = Numeric.gcd(c1.numerator, c2.numerator),
280
- gcdD = Numeric.gcd(c1.denominator, c2.denominator)
281
- c1.divide(gcdN).multiply(gcdD)
282
- c2.divide(gcdN).multiply(gcdD)
283
-
284
- // if one value is -1, use 1 and make the other one opposed
285
- if (c2.isNegativeOne()) {
286
- c1.opposed()
287
- c2.opposed()
288
- } else if (c1.isNegativeOne()) {
289
- c1.opposed()
290
- c2.opposed()
291
- }
292
-
293
- return {
294
- merged: this.mergeEquations(eq1, eq2, c2, c1),
295
- factors: [c2, c1]
296
- }
297
- }
298
-
299
- /**
300
- * Linear reduction of the equations to have only one letter
301
- * @param letter letter to isolate
302
- * @private
303
- */
304
- private _solveOneLetter(letter: string, withResolution: boolean): ISolution {
305
- // list of equations.
306
- let LE: Equation[] = this.clone().equations,
307
- reducedEquations: Equation[] = [],
308
- lastIndex
309
-
310
- this._resolutionSteps[letter] = []
311
-
312
- // Reduce the equations.
313
- // Do it as long as there is more than one step, but no more than the number of equations.
314
- for (let L of this.variables) {
315
- // Reset the stack
316
- reducedEquations = [];
317
-
318
- // remove the setLetter from all equations using linear combinations
319
- if (L === letter) continue;
320
-
321
- if (withResolution) {
322
- this._resolutionSteps[letter].push({
323
- equations: LE.map(x => x.clone()),
324
- operations: [...new Array(LE.length)].map(x => [...new Array(LE.length - 1)].map(x => ""))
325
- })
326
- lastIndex = this._resolutionSteps[letter].length - 1
327
- }
328
-
329
- // Linear reduction.
330
- for (let i = 0; i < LE.length - 1; i++) {
331
- const result = this._linearReduction(LE[i], LE[i + 1], L)
332
- reducedEquations.push(result.merged)
333
-
334
- if (withResolution) {
335
- this._resolutionSteps[letter][lastIndex].operations[i][i] = result.factors[0].tex
336
- this._resolutionSteps[letter][lastIndex].operations[i + 1][i] = result.factors[1].tex
337
- }
338
- }
339
-
340
- LE = [...reducedEquations]
341
- }
342
-
343
- // Solve the equations
344
- // let E = this._resolutionSteps[this._resolutionSteps.length - 1].equations[0];
345
- let E = LE[0];
346
- E.solve()
347
- const solution = E.solutions[0]
348
-
349
- if (withResolution) {
350
- this._resolutionSteps[letter].push({
351
- equations: [LE[0]],
352
- operations: [[LE[0].left.monoms[0].coefficient.tex]]
353
- })
354
-
355
- let P: Polynom
356
- if (solution.exact instanceof Fraction || typeof solution.exact === "string") {
357
- P = new Polynom(solution.exact)
358
- } else {
359
- P = new Polynom(solution.value)
360
- }
361
- this._resolutionSteps[letter].push({
362
- equations: [new Equation(new Polynom(letter), P)],
363
- operations: []
364
- })
365
-
366
- }
367
- return E.solutions[0]
368
- }
369
-
370
- }
@@ -1,183 +0,0 @@
1
- /**
2
- * Polynom module contains everything necessary to handle polynoms.
3
- * @module Logicalset
4
- */
5
-
6
- import {Shutingyard, ShutingyardMode} from '../shutingyard';
7
-
8
- /**
9
- * Polynom class can handle polynoms, reorder, resolve, ...
10
- */
11
- export class Logicalset {
12
- private _rawString: string;
13
- private _rpn: { token: string, tokenType: string }[]
14
-
15
- /**
16
- *
17
- * @param {string} value (optional) Default polynom to parse on class creation
18
- */
19
- constructor(value: string) {
20
- this._rawString = value
21
- this.parse(value)
22
- return this;
23
- }
24
-
25
- get isLogicalset() {
26
- return true;
27
- };
28
-
29
- private parse = (value: string): Logicalset => {
30
- // TODO: Must format the value string to convert some items...
31
-
32
- // Parse the updated value to the shutingyard algorithm
33
- this._rpn = new Shutingyard(ShutingyardMode.SET).parse(value).rpn;
34
-
35
- return this;
36
- }
37
-
38
- evaluate(tokenSets: { [key: string]: unknown[] }, reference?: unknown[]): unknown[] {
39
- let varStack: (Set<unknown>)[] = []
40
-
41
- let referenceSet: Set<unknown>
42
- if (reference === undefined) {
43
- referenceSet = new Set()
44
- for (let key in tokenSets) {
45
- referenceSet = new Set([...referenceSet, ...tokenSets[key]])
46
- }
47
- } else {
48
- referenceSet = new Set(reference)
49
- }
50
-
51
- for (let token of this._rpn) {
52
- if (token.tokenType === 'variable') {
53
- // The variable has no token - assume it's empty.
54
- if (tokenSets[token.token] === undefined) {
55
- varStack.push(new Set())
56
- } else {
57
- varStack.push(new Set(tokenSets[token.token]));
58
- }
59
-
60
- } else {
61
- switch (token.token) {
62
- case '&':
63
- if (varStack.length >= 2) {
64
- let second = varStack.pop(),
65
- first = varStack.pop()
66
-
67
- varStack.push(new Set([...first].filter(x => second.has(x))))
68
- }
69
- break
70
- case '|':
71
- if (varStack.length >= 2) {
72
- let second = varStack.pop(),
73
- first = varStack.pop()
74
- varStack.push(new Set([...first, ...second]))
75
- }
76
- break
77
- case '-':
78
- if (varStack.length >= 2) {
79
- let second = varStack.pop(),
80
- first = varStack.pop()
81
- varStack.push(new Set([...first].filter(x => !second.has(x))))
82
- }
83
- break
84
- case '!':
85
- if (varStack.length >= 1) {
86
- let first = varStack.pop()
87
-
88
- varStack.push(new Set([...referenceSet].filter(x => !first.has(x))))
89
- }
90
- break
91
- }
92
- }
93
- }
94
-
95
- return [...varStack[0]].sort();
96
- }
97
-
98
- vennAB(): any[] {
99
- return this.evaluate({
100
- A: ['A', 'AB'],
101
- B: ['B', 'AB']
102
- },
103
- ['A', 'B', 'AB', 'E']
104
- )
105
- }
106
-
107
- vennABC(): any[] {
108
- return this.evaluate({
109
- A: ['A', 'AB', 'AC', 'ABC'],
110
- B: ['B', 'AB', 'BC', 'ABC'],
111
- C: ['C', 'AC', 'BC', 'ABC']
112
- },
113
- ['A', 'B', 'C', 'AB', 'AC', 'BC', 'E']
114
- )
115
- }
116
-
117
- get rpn(): { token: string, tokenType: string }[] {
118
- return this._rpn
119
- }
120
-
121
- get tex(): string {
122
- let varStack: { token: string, tokenType: string } [] = []
123
-
124
- for (let token of this._rpn) {
125
- if (token.tokenType === 'variable') {
126
- varStack.push(token);
127
- } else {
128
- switch (token.token) {
129
- case '&':
130
- if (varStack.length >= 2) {
131
- let second = varStack.pop(),
132
- first = varStack.pop()
133
-
134
- if (first.tokenType === 'mix') {
135
- first.token = `( ${first.token} )`
136
- }
137
- if (second.tokenType === 'mix') {
138
- second.token = `( ${second.token} )`
139
- }
140
- varStack.push({token: `${first.token} \\cap ${second.token}`, tokenType: 'mix'})
141
- }
142
- break
143
- case '|':
144
- if (varStack.length >= 2) {
145
- let second = varStack.pop(),
146
- first = varStack.pop()
147
-
148
- if (first.tokenType === 'mix') {
149
- first.token = `( ${first.token} )`
150
- }
151
- if (second.tokenType === 'mix') {
152
- second.token = `( ${second.token} )`
153
- }
154
- varStack.push({token: `${first.token} \\cup ${second.token}`, tokenType: 'mix'})
155
- }
156
- break
157
- case '-':
158
- if (varStack.length >= 2) {
159
- let second = varStack.pop(),
160
- first = varStack.pop()
161
-
162
- if (first.tokenType === 'mix') {
163
- first.token = `( ${first.token} )`
164
- }
165
- if (second.tokenType === 'mix') {
166
- second.token = `( ${second.token} )`
167
- }
168
- varStack.push({token: `${first.token} \\setminus ${second.token}`, tokenType: 'mix'})
169
- }
170
- break
171
- case '!':
172
- if (varStack.length >= 1) {
173
- let first = varStack.pop()
174
- varStack.push({token: `\\overline{ ${first.token} }`, tokenType: 'variable'})
175
- }
176
- break
177
- }
178
- }
179
- }
180
-
181
- return varStack[0].token
182
- }
183
- }