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