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,496 +0,0 @@
1
- export type tokenType = {
2
- [key: string]: {
3
- precedence: number,
4
- associative: string,
5
- type: string
6
- }
7
- }
8
-
9
- export const tokenConstant: { [Key: string]: number } = {
10
- pi: Math.PI,
11
- e: Math.exp(1)
12
- }
13
-
14
- export enum ShutingyardType {
15
- VARIABLE = 'variable',
16
- COEFFICIENT = 'coefficient',
17
- OPERATION = 'operation',
18
- CONSTANT = 'constant',
19
- FUNCTION = 'function',
20
- MONOM = 'monom'
21
- }
22
-
23
- export enum ShutingyardMode {
24
- EXPRESSION = 'expression',
25
- POLYNOM = 'polynom',
26
- SET = 'set',
27
- NUMERIC = 'numeric'
28
- }
29
-
30
- export type Token = { token: string, tokenType: string }
31
-
32
- export class Shutingyard {
33
- readonly _mode: ShutingyardMode;
34
- private _rpn: Token[] = [];
35
- private _tokenConfig: tokenType;
36
- private _tokenConstant: { [Key: string]: number }
37
- private _tokenKeys: string[]
38
- private _uniformize: boolean;
39
-
40
- constructor(mode?: ShutingyardMode) {
41
- this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
42
- this.tokenConfigInitialization()
43
- }
44
-
45
- // Getter
46
- get rpn() {
47
- // console.log(this._rpn)
48
- return this._rpn;
49
- }
50
-
51
- get rpnToken() {
52
- return this._rpn.map(x => x.token)
53
- }
54
-
55
- /**
56
- * Determin if the token is a defined operation
57
- * Defined operations: + - * / ^ sin cos tan
58
- * @param token
59
- */
60
- // isOperation(token: string): boolean {
61
- // if (token[0].match(/[+\-*/^]/g)) {
62
- // return true;
63
- // }
64
- // //
65
- // // if (token.match(/^sin|cos|tan/g)) {
66
- // // return true;
67
- // // }
68
- //
69
- // return false;
70
- // }
71
-
72
- tokenConfigInitialization(): tokenType {
73
- if (this._mode === ShutingyardMode.SET) {
74
- this._tokenConfig = {
75
- '&': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
76
- '|': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
77
- '!': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
78
- '-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION}
79
- }
80
- this._uniformize = false;
81
- } else if (this._mode === ShutingyardMode.NUMERIC) {
82
- this._tokenConfig = {
83
- '^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
84
- '*': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
85
- '/': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
86
- '+': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
87
- '-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
88
- '%': {precedence: 3, associative: 'right', type: ShutingyardType.OPERATION},
89
- 'sin': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
90
- 'cos': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
91
- 'tan': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
92
- 'sqrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
93
- 'nthrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
94
- 'ln': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
95
- 'log': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
96
- }
97
- this._uniformize = false
98
- } else if (this._mode === ShutingyardMode.EXPRESSION) {
99
- this._tokenConfig = {
100
- '^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
101
- '*': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
102
- '/': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
103
- '+': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
104
- '-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
105
- '%': {precedence: 3, associative: 'right', type: ShutingyardType.OPERATION},
106
- 'sin': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
107
- 'cos': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
108
- 'tan': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
109
- 'sqrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
110
- 'nthrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
111
- }
112
- this._uniformize = true
113
- } else {
114
- this._tokenConfig = {
115
- '^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
116
- '*': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
117
- '/': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
118
- '+': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
119
- '-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
120
- }
121
- this._uniformize = true
122
- }
123
-
124
- this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length)
125
- return this._tokenConfig
126
- }
127
-
128
- /**
129
- * Get the next token to analyse.
130
- * @param expr (string) Expression to analyse
131
- * @param start (number) CUrrent position in the expr string.
132
- */
133
- NextToken(expr: string, start: number): [string, number, string] {
134
- let token: string, tokenType: string;
135
- token = '';
136
- tokenType = '';
137
- // Case of parenthesis or comma (generic items)
138
- if (expr[start] === '(') {
139
- token = '(';
140
- tokenType = '(';
141
- }
142
- // It's a closing parenthese
143
- else if (expr[start] === ')') {
144
- token = ')';
145
- tokenType = ')';
146
- }
147
- // It's an argument separator for a function
148
- else if (expr[start] === ',') {
149
- token = ',';
150
- tokenType = 'function-argument';
151
- } else {
152
- // Extract operation and function tokens
153
- for (let key of this._tokenKeys) {
154
- if (expr.substring(start, start + key.length) === key) {
155
- token += key;
156
- tokenType = this._tokenConfig[key].type
157
- break
158
- }
159
- }
160
-
161
- // Extract constant
162
- for (let key in tokenConstant) {
163
- if (expr.substring(start, start + key.length) === key) {
164
- token += key;
165
- tokenType = ShutingyardType.CONSTANT
166
- break
167
- }
168
- }
169
-
170
- if (token === '') {
171
- // No function found ! Might be a coefficient !
172
- if (expr[start].match(/[0-9]/)) {
173
- if (this._mode === ShutingyardMode.POLYNOM && false) {
174
- token = expr.substring(start).match(/^([0-9.,/]+)/)[0]
175
- } else {
176
- token = expr.substring(start).match(/^([0-9.]+)/)[0]
177
- }
178
- tokenType = ShutingyardType.COEFFICIENT
179
- } else if (expr[start].match(/[a-zA-Z]/)) {
180
- token = expr.substring(start).match(/^([a-zA-Z])/)[0]
181
- tokenType = ShutingyardType.VARIABLE
182
- } else {
183
- console.log('Unidentified token', expr[start], expr, start)
184
- token = expr[start]
185
- tokenType = ShutingyardType.MONOM
186
- }
187
-
188
- }
189
- }
190
-
191
- return [token, start + token.length, tokenType];
192
- }
193
-
194
- normalize(expr: string): string {
195
- if(expr.length===1){return expr}
196
-
197
- // Get the list of function token.
198
- let fnToken: string[] = [],
199
- kToken: string[] = []
200
- for (let token in this._tokenConfig) {
201
- if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
202
- fnToken.push(token)
203
- }
204
- }
205
- // sort if from the lengthy to the smallest function
206
- fnToken.sort((a, b) => b.length - a.length)
207
-
208
- for (let token in tokenConstant) {
209
- kToken.push(token)
210
- }
211
- // sort if from the lengthy to the smallest function
212
- kToken.sort((a, b) => b.length - a.length)
213
-
214
- let normalizedExpr: string = "",
215
- i = 0,
216
- crtToken,
217
- nextToken
218
-
219
- while (i < expr.length - 1) {
220
- // Check if we have a function token.
221
- // The function MUST have an open parentheses
222
- let tokenIdx = 0
223
- while (tokenIdx < fnToken.length) {
224
- let token = fnToken[tokenIdx]
225
- if (expr.slice(i, i + token.length + 1) === token + '(') {
226
- normalizedExpr += token + '('
227
- i += token.length + 1
228
-
229
- // Restart the scan for the function token
230
- tokenIdx = 0
231
- } else {
232
- // scan for a next function token
233
- tokenIdx++
234
- }
235
- }
236
-
237
- // Check for a constant
238
- tokenIdx = 0
239
- while (tokenIdx < kToken.length) {
240
- let token = kToken[tokenIdx]
241
- if (expr.slice(i, i + token.length) === token) {
242
- // We have found a constant.
243
- // add it, but with remove the last letter
244
- normalizedExpr += token.slice(0, -1)
245
- i += token.length-1
246
-
247
- // Exit the loop
248
- break
249
- }
250
- tokenIdx++
251
- }
252
-
253
- // The function token are solved.
254
- crtToken = expr[i]
255
- nextToken = expr[i + 1]
256
- normalizedExpr += crtToken
257
-
258
- if (crtToken.match(/[a-zA-Z]/g)) {
259
- // Current element is a letter.
260
- // if the next element is a letter, a number or an opening parentheses, add the multiplication sign.
261
- if (nextToken?.match(/[a-zA-Z\d(]/)) {
262
- normalizedExpr += '*'
263
- }
264
- } else if (crtToken.match(/\d/)) {
265
- // Current element is a number.
266
- // if the next element is a letter or a parentheses, add the multiplication sign.
267
- if (nextToken?.match(/[a-zA-Z(]/)) {
268
- normalizedExpr += '*'
269
- }
270
- } else if (crtToken === ')') {
271
- // Current element is a closing parentheses.
272
- // if the next element is a letter, a number or an opening parentheses, add the multiplication sign
273
- if (nextToken?.match(/[a-zA-Z\d(]/)) {
274
- normalizedExpr += '*'
275
- }
276
- }
277
-
278
- // Go to next token
279
- i++
280
- }
281
-
282
- // add the last token
283
- return normalizedExpr + (nextToken===undefined?'':nextToken)
284
- }
285
-
286
- // /**
287
- // * Sanitize an expression by adding missing common operation (multiplication between parentheseses)
288
- // * @param expr
289
- // * @constructor
290
- // */
291
- // Uniformizer(expr: string): string {
292
- // // TODO: Delete this old version
293
- // // Prefere "normalize", much more robust !
294
- // // Determiner if need to be uniformized
295
- // if (!this._uniformize) {
296
- // return expr
297
- // }
298
- //
299
- // // Generate the list of function token.
300
- // let fnToken: string[] = []
301
- // for (let token in this._tokenConfig) {
302
- // if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
303
- // fnToken.push(token)
304
- // }
305
- // }
306
- // // sort if from the lengthy to the smallest function
307
- // fnToken.sort((a, b) => b.length - a.length)
308
- // let tokenRegExp = new RegExp(`(${fnToken.join('|')})`, 'g')
309
- // let functionTokenOrder = Array.from(expr.matchAll(tokenRegExp))
310
- //
311
- //
312
- // let expr2;
313
- //
314
- // // Replace all function by @
315
- // expr2 = expr.replace(tokenRegExp, '@')
316
- // // Add * before @ (functionn)
317
- // expr2 = expr2.replace(/([\da-zA-Z])(@)/g, "$1*$2");
318
- //
319
- // // Replace missing multiplication between two parenthese
320
- // expr2 = expr2.replace(/\)\(/g, ')*(');
321
- //
322
- // // Replace missing multiplication between number or setLetter and parenthese.
323
- //
324
- // // 3x(x-4) => 3x*(x-4)
325
- // expr2 = expr2.replace(/([\da-zA-Z])(\()/g, "$1*$2");
326
- //
327
- // // (x-4)3x => (x-4)*3x
328
- // expr2 = expr2.replace(/(\))([\da-zA-Z])/g, "$1*$2");
329
- //
330
- // // Add multiplication between number and letters.
331
- // // 3x => 3*x
332
- // expr2 = expr2.replace(/([0-9])([a-zA-Z])/g, "$1*$2");
333
- // expr2 = expr2.replace(/([a-zA-Z])([0-9])/g, "$1*$2");
334
- //
335
- // // Remove letter between function token and it's parenthese.
336
- // // for (let token of fnToken) {
337
- // // // Remove
338
- // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
339
- // // }
340
- // // Add multiplication between letters ?
341
- // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
342
- // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
343
- //
344
- // // Restore operation auto formatting (prevent adding the multiplication star)
345
- // let exprAsArray = expr2.split('@')
346
- //
347
- // if (exprAsArray.length > 0) {
348
- // expr2 = ""
349
- // for (let idx in exprAsArray) {
350
- // }
351
- // for (let token of fnToken) {
352
- // // Remove
353
- //
354
- // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
355
- // }
356
- // }
357
- //
358
- // return expr2;
359
- // }
360
-
361
- /**
362
- * Parse an expression using the shutting yard tree algorithms
363
- * @param expr (string) Expression to analyse
364
- * Returns a RPN list of items.
365
- * @param uniformize
366
- */
367
- parse(expr: string, uniformize?: boolean): Shutingyard {
368
- let outQueue: { token: string, tokenType: string }[] = [], // Output queue
369
- opStack: { token: string, tokenType: string }[] = [], // Operation queue
370
- token: string = '',
371
- tokenPos: number = 0,
372
- tokenType: string = '',
373
- previousOpStatckLength = 0
374
-
375
- // Normalize the input if required.
376
- if (uniformize || this._uniformize) expr = this.normalize(expr)
377
-
378
-
379
- let securityLoopLvl1 = 50,
380
- securityLoopLvl2_default = 50,
381
- securityLoopLvl2;
382
-
383
- while (tokenPos < expr.length) {
384
- securityLoopLvl1--;
385
- if (securityLoopLvl1 === 0) {
386
- console.log('SECURITY LEVEL 1 EXIT');
387
- break;
388
- }
389
-
390
- // Get the next token and the corresponding new (ending) position
391
- [token, tokenPos, tokenType] = this.NextToken(expr, tokenPos);
392
-
393
- switch (tokenType) {
394
- case 'monom':
395
- case 'coefficient':
396
- case 'variable':
397
- case 'constant':
398
- outQueue.push({
399
- token,
400
- tokenType
401
- });
402
- break;
403
- case 'operation':
404
- previousOpStatckLength = opStack.length;
405
- //If the token is an operator, o1, then:
406
- if (opStack.length > 0) {
407
- let opTop = opStack[opStack.length - 1];
408
-
409
- securityLoopLvl2 = +securityLoopLvl2_default;
410
-
411
- //while there is an operator token o2, at the top of the operator stack and
412
- while (opTop.token in this._tokenConfig && (
413
- //either o1 is left-associative and its precedence is less than or equal to that of o2,
414
- (this._tokenConfig[token].associative === 'left' && this._tokenConfig[token].precedence <= this._tokenConfig[opTop.token].precedence)
415
- ||
416
- //or o1 is right associative, and has precedence less than that of o2,
417
- (this._tokenConfig[token].associative === 'right' && this._tokenConfig[token].precedence < this._tokenConfig[opTop.token].precedence)
418
- )
419
- ) {
420
-
421
- /* Security exit ! */
422
- securityLoopLvl2--;
423
- if (securityLoopLvl2 === 0) {
424
- console.log('SECURITY LEVEL 2 OPERATION EXIT');
425
- break;
426
- }
427
-
428
- // Add the operation to the queue
429
- outQueue.push((opStack.pop()) || {token: '', tokenType: 'operation'});
430
-
431
- // Get the next operation on top of the Stack.
432
- if (opStack.length === 0) {
433
- break;
434
- }
435
- opTop = opStack[opStack.length - 1];
436
- }
437
- }
438
- //at the end of iteration push o1 onto the operator stack
439
- opStack.push({token, tokenType});
440
- break;
441
- case 'function-argument':
442
- // TODO: check if the opStack exist.
443
- securityLoopLvl2 = +securityLoopLvl2_default;
444
- while (opStack[opStack.length - 1].token !== '(' && opStack.length > 0) {
445
- securityLoopLvl2--;
446
- if (securityLoopLvl2 === 0) {
447
- console.log('SECURITY LEVEL 2 FUNCTION ARGUMENT EXIT');
448
- break;
449
- }
450
-
451
- outQueue.push((opStack.pop()) || {token, tokenType});
452
- }
453
- break;
454
- case '(':
455
- opStack.push({token, tokenType});
456
- // Add an empty value if next element is negative.
457
- if (expr[tokenPos] === '-') {
458
- outQueue.push({token: '0', tokenType: 'coefficient'});
459
- }
460
- break;
461
- case ')':
462
- securityLoopLvl2 = +securityLoopLvl2_default;
463
- //Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output queue.
464
- while (opStack[opStack.length - 1].token !== '(' && opStack.length > 1 /*Maybe zero !? */) {
465
- securityLoopLvl2--;
466
- if (securityLoopLvl2 === 0) {
467
- console.log('SECURITY LEVEL 2 CLOSING PARENTHESE EXIT');
468
- break;
469
- }
470
-
471
- outQueue.push((opStack.pop()) || {token, tokenType});
472
- }
473
-
474
- //Pop the left parenthesis from the stack, but not onto the output queue.
475
- opStack.pop();
476
- break;
477
- case 'function':
478
- opStack.push({token, tokenType});
479
- break;
480
- default:
481
- // In theory, everything should be handled.
482
- console.log(`SHUTING YARD: ${tokenType} : ${token} `);
483
- }
484
-
485
- // Output
486
- // console.log(outQueue.concat(opStack.reverse()).join(" "));
487
- }
488
-
489
- // console.log(outQueue.concat(opStack.reverse()));
490
- this._rpn = outQueue.concat(opStack.reverse());
491
-
492
- return this;
493
- }
494
-
495
-
496
- }
@@ -1,64 +0,0 @@
1
- import {describe} from "mocha";
2
- import {expect} from "chai";
3
- import {Equation} from "../../src/maths/algebra/equation";
4
-
5
-
6
- describe('Equations tests', () => {
7
- it('should get the solutions', () => {
8
-
9
- let E1 = new Equation('3x+8', '0')
10
- E1.solve()
11
- expect(E1.solutions[0].tex).to.be.equal('-\\frac{ 8 }{ 3 }')
12
-
13
- let E2 = new Equation('x^2+5x+6', '0')
14
- E2.solve()
15
- expect(E2.solutions.map(x=>x.tex)).to.have.all.members(['-3', '-2'])
16
-
17
- let E3 = new Equation('(x-3)(x+2)(3x-5)', '0')
18
- E3.solve()
19
- expect(E3.solutions.map(x=>x.tex)).to.have.all.members([ '-2', '3', '\\frac{ 5 }{ 3 }' ])
20
-
21
- let E4 = new Equation('x^2+x+10', '0')
22
- E4.solve()
23
- expect(E4.solutions.map(x=>x.tex)).to.have.all.members([ '\\varnothing' ])
24
-
25
- let E5 = new Equation('(x-3)(x+2)(x-5)(x-7)(x+2)', 0)
26
- E5.solve()
27
- expect(E5.solutions.map(x=>x.tex)).to.have.all.members([ '-2', '3', '5', '7' ] )
28
-
29
-
30
- let E6 = new Equation('5x^2+7x-31', 0)
31
- E6.solve()
32
- expect(E6.solutions.map(x=>x.tex)).to.have.all.members([
33
- '\\frac{ -7 - \\sqrt{669} }{ 10 }',
34
- '\\frac{ -7 + \\sqrt{669} }{ 10 }'
35
- ] )
36
- })
37
-
38
- it('should resolve an equation of second degree', ()=>{
39
- let P = new Equation('-10x^2-8x+8=0')
40
- P.solve()
41
- expect(P.solutions[0].tex).to.have.oneOf(['\\frac{ -2 - 2\\sqrt{6} }{ 5 }', '\\frac{ -2 + 2\\sqrt{6} }{ 5 }'])
42
- })
43
-
44
- it('should solve this equation please', function () {
45
- let P = new Equation("2/7(3x+5)=9-(3-x)/7")
46
- P.solve()
47
-
48
- const sols = P.solutions.map(x => x.display)
49
- expect(sols).to.be.length(1)
50
- expect(sols[0]).to.be.equal('10')
51
- });
52
-
53
- it('should detect if two equations are equal or linear', function () {
54
- let P = new Equation('3x+2y=5'),
55
- Q = new Equation('5-3x=2y'),
56
- R = new Equation('6x+4y-10=0')
57
-
58
- expect(P.isSameAs(P)).to.be.true
59
- expect(P.isSameAs(Q)).to.be.true
60
- expect(P.isSameAs(R)).to.be.false
61
- expect(P.isLinearTo(Q)).to.be.true
62
- expect(P.isLinearTo(R)).to.be.true
63
- })
64
- })
@@ -1,58 +0,0 @@
1
- import {describe} from "mocha";
2
- import {expect} from "chai";
3
- import {LinearSystem} from "../../src/maths/algebra/linearSystem";
4
- import {Polynom} from "../../src/maths/algebra/polynom";
5
-
6
-
7
- describe('Linear systems tests', () => {
8
- it('should solve a 2x2 equations', () => {
9
- let LS = new LinearSystem(
10
- '4x+5y=11',
11
- '7y-24=3x'
12
- )
13
- LS.solve(true)
14
-
15
- expect(LS.solution).to.be.equal('\\left(-1;3\\right)')
16
- })
17
- it('should solve a 3x3 equations', () => {
18
- let LS = new LinearSystem(
19
- '2x+7y-z=-3',
20
- '-3x+2y+3z=12',
21
- '-5x-3y+2z=5'
22
- )
23
-
24
- LS.solve()
25
- expect(LS.solutionAsDisplay).to.be.equal("(1;0;5)")
26
- })
27
-
28
- it('should solve a 3x3 equations II ', () => {
29
- let LS = new LinearSystem(
30
- '-x+y-z=-6',
31
- '3x+2y+z=14',
32
- '5x+y+3z=7'
33
- )
34
-
35
- LS.solve()
36
- })
37
-
38
- it('should calculate the reduction', function () {
39
- let E1 = new Polynom('6x+21y-3z'),
40
- E2 = new Polynom('-6x+21y-3z')
41
-
42
- E1.add(E2);
43
- expect(E1.reduce().display).to.be.equal('42y-6z')
44
- });
45
-
46
- it('should use a reduced linear reducation', function () {
47
- let LS = new LinearSystem(
48
- '3x-6y+3=0',
49
- 'x+12y-6=0'
50
- )
51
- LS.solve(true)
52
-
53
- const tex = LS.stepTex('x')
54
-
55
- expect(+LS.resolutionSteps['x'][0].operations[0][0]).to.be.equal(2)
56
- expect(+LS.resolutionSteps['x'][0].operations[1][0]).to.be.equal(1)
57
- });
58
- })