pimath 0.0.64 → 0.0.67
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.
- package/.eslintrc.js +23 -23
- package/dist/pi.js +236 -56
- package/dist/pi.js.map +1 -1
- package/dist/pi.min.js +1 -1
- package/dist/pi.min.js.map +1 -1
- package/docs/assets/highlight.css +78 -78
- package/docs/assets/main.js +52 -52
- package/docs/assets/style.css +1413 -1413
- package/docs/classes/Logicalset.Logicalset-1.html +4 -4
- package/docs/classes/Polynom.Rational.html +3 -3
- package/docs/classes/algebra_equation.Equation.html +25 -25
- package/docs/classes/algebra_monom.Monom.html +113 -113
- package/docs/classes/algebra_polynom.Polynom.html +29 -29
- package/docs/classes/coefficients_fraction.Fraction.html +18 -18
- package/docs/classes/coefficients_nthroot.NthRoot.html +2 -2
- package/docs/classes/geometry_circle.Circle.html +2 -2
- package/docs/classes/geometry_line.Line.html +2 -2
- package/docs/classes/geometry_triangle.Triangle.html +16 -16
- package/docs/classes/numeric.Numeric.html +13 -13
- package/docs/classes/shutingyard.Shutingyard.html +17 -17
- package/docs/index.html +10 -10
- package/docs/interfaces/algebra_equation.ISolution.html +2 -2
- package/docs/modules/Logicalset.html +2 -2
- package/docs/modules/Polynom.html +2 -2
- package/docs/modules/Vector.html +2 -2
- package/esm/maths/algebra/equation.js +2 -2
- package/esm/maths/algebra/equation.js.map +1 -1
- package/esm/maths/algebra/polynom.d.ts +4 -5
- package/esm/maths/algebra/polynom.js +2 -2
- package/esm/maths/algebra/polynom.js.map +1 -1
- package/esm/maths/algebra/rational.d.ts +8 -10
- package/esm/maths/algebra/rational.js +9 -5
- package/esm/maths/algebra/study/rationalStudy.d.ts +1 -2
- package/esm/maths/algebra/study/rationalStudy.js +32 -20
- package/esm/maths/algebra/study/rationalStudy.js.map +1 -1
- package/esm/maths/algebra/study.d.ts +16 -24
- package/esm/maths/algebra/study.js +65 -24
- package/esm/maths/algebra/study.js.map +1 -1
- package/esm/maths/coefficients/fraction.d.ts +8 -6
- package/esm/maths/coefficients/fraction.js +34 -17
- package/esm/maths/coefficients/fraction.js.map +1 -1
- package/esm/maths/expressions/expression.d.ts +21 -0
- package/esm/maths/expressions/expression.js +161 -0
- package/esm/maths/expressions/expression.js.map +1 -0
- package/esm/maths/expressions/expressionFactor.d.ts +29 -0
- package/esm/maths/expressions/expressionFactor.js +109 -0
- package/esm/maths/expressions/expressionFactor.js.map +1 -0
- package/esm/maths/expressions/expressionMember.d.ts +16 -0
- package/esm/maths/expressions/expressionMember.js +90 -0
- package/esm/maths/expressions/expressionMember.js.map +1 -0
- package/esm/maths/expressions/expressionOperators.d.ts +8 -0
- package/esm/maths/expressions/expressionOperators.js +42 -0
- package/esm/maths/expressions/expressionOperators.js.map +1 -0
- package/esm/maths/expressions/expressionParser.d.ts +12 -0
- package/esm/maths/expressions/expressionParser.js +219 -0
- package/esm/maths/expressions/expressionParser.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactor.d.ts +7 -0
- package/esm/maths/expressions/factors/ExpFactor.js +22 -0
- package/esm/maths/expressions/factors/ExpFactor.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorConstant.d.ts +13 -0
- package/esm/maths/expressions/factors/ExpFactorConstant.js +49 -0
- package/esm/maths/expressions/factors/ExpFactorConstant.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorExponential.d.ts +7 -0
- package/esm/maths/expressions/factors/ExpFactorExponential.js +18 -0
- package/esm/maths/expressions/factors/ExpFactorExponential.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorNumber.d.ts +13 -0
- package/esm/maths/expressions/factors/ExpFactorNumber.js +36 -0
- package/esm/maths/expressions/factors/ExpFactorNumber.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorPower.d.ts +9 -0
- package/esm/maths/expressions/factors/ExpFactorPower.js +22 -0
- package/esm/maths/expressions/factors/ExpFactorPower.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorSin.d.ts +7 -0
- package/esm/maths/expressions/factors/ExpFactorSin.js +22 -0
- package/esm/maths/expressions/factors/ExpFactorSin.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorTrigo.d.ts +19 -0
- package/esm/maths/expressions/factors/ExpFactorTrigo.js +40 -0
- package/esm/maths/expressions/factors/ExpFactorTrigo.js.map +1 -0
- package/esm/maths/expressions/factors/ExpFactorVariable.d.ts +12 -0
- package/esm/maths/expressions/factors/ExpFactorVariable.js +33 -0
- package/esm/maths/expressions/factors/ExpFactorVariable.js.map +1 -0
- package/esm/maths/expressions/internals.d.ts +12 -0
- package/esm/maths/expressions/internals.js +29 -0
- package/esm/maths/expressions/internals.js.map +1 -0
- package/esm/maths/shutingyard.d.ts +4 -1
- package/esm/maths/shutingyard.js +137 -21
- package/esm/maths/shutingyard.js.map +1 -1
- package/graph.svg +1033 -0
- package/package.json +1 -1
- package/src/maths/algebra/equation.ts +2 -2
- package/src/maths/algebra/polynom.ts +1 -0
- package/src/maths/algebra/study/rationalStudy.ts +26 -12
- package/src/maths/algebra/study.ts +48 -5
- package/src/maths/coefficients/fraction.ts +111 -86
- package/src/maths/expressions/expression.ts +191 -0
- package/src/maths/expressions/expressionFactor.ts +138 -0
- package/src/maths/expressions/expressionMember.ts +114 -0
- package/src/maths/expressions/expressionOperators.ts +49 -0
- package/src/maths/expressions/expressionParser.ts +249 -0
- package/src/maths/expressions/factors/ExpFactor.ts +26 -0
- package/src/maths/expressions/factors/ExpFactorConstant.ts +56 -0
- package/src/maths/expressions/factors/ExpFactorExponential.ts +19 -0
- package/src/maths/expressions/factors/ExpFactorNumber.ts +44 -0
- package/src/maths/expressions/factors/ExpFactorPower.ts +24 -0
- package/src/maths/expressions/factors/ExpFactorTrigo.ts +44 -0
- package/src/maths/expressions/factors/ExpFactorVariable.ts +40 -0
- package/src/maths/expressions/internals.ts +14 -0
- package/src/maths/shutingyard.ts +156 -26
- package/tests/algebra/study.test.ts +29 -4
- package/tests/coefficients/fraction.test.ts +17 -0
- package/tests/expressions/expressions.test.ts +124 -0
- package/tests/shutingyard.test.ts +22 -0
- package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40_[Changes]/shelved.patch +0 -21
- package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40__Changes_.xml +0 -4
package/src/maths/shutingyard.ts
CHANGED
|
@@ -21,6 +21,7 @@ export enum ShutingyardType {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export enum ShutingyardMode {
|
|
24
|
+
EXPRESSION = 'expression',
|
|
24
25
|
POLYNOM = 'polynom',
|
|
25
26
|
SET = 'set',
|
|
26
27
|
NUMERIC = 'numeric'
|
|
@@ -30,6 +31,7 @@ export type Token = { token: string, tokenType: string }
|
|
|
30
31
|
|
|
31
32
|
export class Shutingyard {
|
|
32
33
|
readonly _mode: ShutingyardMode;
|
|
34
|
+
private _rpn: Token[] = [];
|
|
33
35
|
private _tokenConfig: tokenType;
|
|
34
36
|
private _tokenConstant: { [Key: string]: number }
|
|
35
37
|
private _tokenKeys: string[]
|
|
@@ -40,14 +42,16 @@ export class Shutingyard {
|
|
|
40
42
|
this.tokenConfigInitialization()
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
private _rpn: Token[] = [];
|
|
44
|
-
|
|
45
45
|
// Getter
|
|
46
46
|
get rpn() {
|
|
47
47
|
// console.log(this._rpn)
|
|
48
48
|
return this._rpn;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
get rpnToken() {
|
|
52
|
+
return this._rpn.map(x => x.token)
|
|
53
|
+
}
|
|
54
|
+
|
|
51
55
|
/**
|
|
52
56
|
* Determin if the token is a defined operation
|
|
53
57
|
* Defined operations: + - * / ^ sin cos tan
|
|
@@ -88,6 +92,21 @@ export class Shutingyard {
|
|
|
88
92
|
'sqrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
89
93
|
}
|
|
90
94
|
this._uniformize = false
|
|
95
|
+
} else if (this._mode === ShutingyardMode.EXPRESSION) {
|
|
96
|
+
this._tokenConfig = {
|
|
97
|
+
'^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
|
|
98
|
+
'*': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
99
|
+
'/': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
100
|
+
'+': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
101
|
+
'-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
102
|
+
'%': {precedence: 3, associative: 'right', type: ShutingyardType.OPERATION},
|
|
103
|
+
'sin': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
104
|
+
'cos': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
105
|
+
'tan': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
106
|
+
'sqrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
107
|
+
'nthrt': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
108
|
+
}
|
|
109
|
+
this._uniformize = true
|
|
91
110
|
} else {
|
|
92
111
|
this._tokenConfig = {
|
|
93
112
|
'^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
|
|
@@ -95,10 +114,6 @@ export class Shutingyard {
|
|
|
95
114
|
'/': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
|
|
96
115
|
'+': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
97
116
|
'-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION},
|
|
98
|
-
// '%': {precedence: 3, associative: 'right', type: ShutingyardType.OPERATION},
|
|
99
|
-
// 'sin': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
100
|
-
// 'cos': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
101
|
-
// 'tan': {precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION},
|
|
102
117
|
}
|
|
103
118
|
this._uniformize = true
|
|
104
119
|
}
|
|
@@ -131,10 +146,6 @@ export class Shutingyard {
|
|
|
131
146
|
token = ',';
|
|
132
147
|
tokenType = 'function-argument';
|
|
133
148
|
} else {
|
|
134
|
-
// Order token keys by token characters length (descending)
|
|
135
|
-
// TODO: this is done each time ! SHould be done once !
|
|
136
|
-
// const keys = Object.keys(this._tokenConfig).sort((a,b)=>b.length-a.length)
|
|
137
|
-
|
|
138
149
|
// Extract operation and function tokens
|
|
139
150
|
for (let key of this._tokenKeys) {
|
|
140
151
|
if (expr.substring(start, start + key.length) === key) {
|
|
@@ -159,7 +170,7 @@ export class Shutingyard {
|
|
|
159
170
|
if (this._mode === ShutingyardMode.POLYNOM && false) {
|
|
160
171
|
token = expr.substring(start).match(/^([0-9.,/]+)/)[0]
|
|
161
172
|
} else {
|
|
162
|
-
token = expr.substring(start).match(/^([0-9
|
|
173
|
+
token = expr.substring(start).match(/^([0-9.]+)/)[0]
|
|
163
174
|
}
|
|
164
175
|
tokenType = ShutingyardType.COEFFICIENT
|
|
165
176
|
} else if (expr[start].match(/[a-zA-Z]/)) {
|
|
@@ -177,21 +188,131 @@ export class Shutingyard {
|
|
|
177
188
|
return [token, start + token.length, tokenType];
|
|
178
189
|
}
|
|
179
190
|
|
|
191
|
+
normalize(expr: string): string {
|
|
192
|
+
// Get the list of function token.
|
|
193
|
+
let fnToken: string[] = [],
|
|
194
|
+
kToken: string[] = []
|
|
195
|
+
for (let token in this._tokenConfig) {
|
|
196
|
+
if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
|
|
197
|
+
fnToken.push(token)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// sort if from the lengthy to the smallest function
|
|
201
|
+
fnToken.sort((a, b) => b.length - a.length)
|
|
202
|
+
|
|
203
|
+
for (let token in tokenConstant) {
|
|
204
|
+
kToken.push(token)
|
|
205
|
+
}
|
|
206
|
+
// sort if from the lengthy to the smallest function
|
|
207
|
+
kToken.sort((a, b) => b.length - a.length)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
let normalizedExpr: string = "",
|
|
211
|
+
i = 0,
|
|
212
|
+
crtToken,
|
|
213
|
+
nextToken
|
|
214
|
+
|
|
215
|
+
while (i < expr.length - 1) {
|
|
216
|
+
// Check if we have a function token.
|
|
217
|
+
// The function MUST have an open parentheses
|
|
218
|
+
let tokenIdx = 0
|
|
219
|
+
while (tokenIdx < fnToken.length) {
|
|
220
|
+
let token = fnToken[tokenIdx]
|
|
221
|
+
if (expr.slice(i, i + token.length + 1) === token + '(') {
|
|
222
|
+
normalizedExpr += token + '('
|
|
223
|
+
i += token.length + 1
|
|
224
|
+
|
|
225
|
+
// Restart the scan for the function token
|
|
226
|
+
tokenIdx = 0
|
|
227
|
+
} else {
|
|
228
|
+
// scan for a next function token
|
|
229
|
+
tokenIdx++
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Check for a constant
|
|
234
|
+
tokenIdx = 0
|
|
235
|
+
while (tokenIdx < kToken.length) {
|
|
236
|
+
let token = kToken[tokenIdx]
|
|
237
|
+
if (expr.slice(i, i + token.length) === token) {
|
|
238
|
+
// We have found a constant.
|
|
239
|
+
// add it, but with remove the last letter
|
|
240
|
+
normalizedExpr += token.slice(0, -1)
|
|
241
|
+
i += token.length-1
|
|
242
|
+
|
|
243
|
+
// Exit the loop
|
|
244
|
+
break
|
|
245
|
+
}
|
|
246
|
+
tokenIdx++
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// The function token are solved.
|
|
250
|
+
crtToken = expr[i]
|
|
251
|
+
nextToken = expr[i + 1]
|
|
252
|
+
normalizedExpr += crtToken
|
|
253
|
+
if (crtToken.match(/[a-zA-Z]/g)) {
|
|
254
|
+
// Current element is a letter.
|
|
255
|
+
// if the next element is a letter, a number or an opening parentheses, add the multiplication sign.
|
|
256
|
+
if (nextToken.match(/[a-zA-Z\d(]/)) {
|
|
257
|
+
normalizedExpr += '*'
|
|
258
|
+
}
|
|
259
|
+
} else if (crtToken.match(/\d/)) {
|
|
260
|
+
// Current element is a number.
|
|
261
|
+
// if the next element is a letter or a parentheses, add the multiplication sign.
|
|
262
|
+
if (nextToken.match(/[a-zA-Z(]/)) {
|
|
263
|
+
normalizedExpr += '*'
|
|
264
|
+
}
|
|
265
|
+
} else if (crtToken === ')') {
|
|
266
|
+
// Current element is a closing parentheses.
|
|
267
|
+
// if the next element is a letter, a number or an opening parentheses, add the multiplication sign
|
|
268
|
+
if (nextToken.match(/[a-zA-Z\d(]/)) {
|
|
269
|
+
normalizedExpr += '*'
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Go to next token
|
|
274
|
+
i++
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// add the last token
|
|
278
|
+
return normalizedExpr + nextToken
|
|
279
|
+
}
|
|
280
|
+
|
|
180
281
|
/**
|
|
181
282
|
* Sanitize an expression by adding missing common operation (multiplication between parentheseses)
|
|
182
283
|
* @param expr
|
|
183
284
|
* @constructor
|
|
184
285
|
*/
|
|
185
286
|
Uniformizer(expr: string): string {
|
|
287
|
+
// TODO: Delete this old version
|
|
288
|
+
// Prefere "normalize", much more robust !
|
|
186
289
|
// Determiner if need to be uniformized
|
|
187
290
|
if (!this._uniformize) {
|
|
188
291
|
return expr
|
|
189
292
|
}
|
|
190
293
|
|
|
294
|
+
// Generate the list of function token.
|
|
295
|
+
let fnToken: string[] = []
|
|
296
|
+
for (let token in this._tokenConfig) {
|
|
297
|
+
if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
|
|
298
|
+
fnToken.push(token)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// sort if from the lengthy to the smallest function
|
|
302
|
+
fnToken.sort((a, b) => b.length - a.length)
|
|
303
|
+
let tokenRegExp = new RegExp(`(${fnToken.join('|')})`, 'g')
|
|
304
|
+
let functionTokenOrder = Array.from(expr.matchAll(tokenRegExp))
|
|
305
|
+
|
|
306
|
+
|
|
191
307
|
let expr2;
|
|
192
308
|
|
|
309
|
+
// Replace all function by @
|
|
310
|
+
expr2 = expr.replace(tokenRegExp, '@')
|
|
311
|
+
// Add * before @ (functionn)
|
|
312
|
+
expr2 = expr2.replace(/([\da-zA-Z])(@)/g, "$1*$2");
|
|
313
|
+
|
|
193
314
|
// Replace missing multiplication between two parenthese
|
|
194
|
-
expr2 =
|
|
315
|
+
expr2 = expr2.replace(/\)\(/g, ')*(');
|
|
195
316
|
|
|
196
317
|
// Replace missing multiplication between number or setLetter and parenthese.
|
|
197
318
|
|
|
@@ -206,15 +327,27 @@ export class Shutingyard {
|
|
|
206
327
|
expr2 = expr2.replace(/([0-9])([a-zA-Z])/g, "$1*$2");
|
|
207
328
|
expr2 = expr2.replace(/([a-zA-Z])([0-9])/g, "$1*$2");
|
|
208
329
|
|
|
330
|
+
// Remove letter between function token and it's parenthese.
|
|
331
|
+
// for (let token of fnToken) {
|
|
332
|
+
// // Remove
|
|
333
|
+
// expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
|
|
334
|
+
// }
|
|
209
335
|
// Add multiplication between letters ?
|
|
210
|
-
|
|
211
|
-
expr2 = expr2.replace(/([
|
|
212
|
-
|
|
213
|
-
// Restore operation auto
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
expr2 =
|
|
336
|
+
expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
|
|
337
|
+
expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
|
|
338
|
+
|
|
339
|
+
// Restore operation auto formatting (prevent adding the multiplication star)
|
|
340
|
+
let exprAsArray = expr2.split('@')
|
|
341
|
+
|
|
342
|
+
if (exprAsArray.length > 0) {
|
|
343
|
+
expr2 = ""
|
|
344
|
+
for (let idx in exprAsArray) {
|
|
345
|
+
}
|
|
346
|
+
for (let token of fnToken) {
|
|
347
|
+
// Remove
|
|
348
|
+
|
|
349
|
+
// expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
|
|
350
|
+
}
|
|
218
351
|
}
|
|
219
352
|
|
|
220
353
|
return expr2;
|
|
@@ -234,7 +367,9 @@ export class Shutingyard {
|
|
|
234
367
|
tokenType: string = '',
|
|
235
368
|
previousOpStatckLength = 0
|
|
236
369
|
|
|
237
|
-
|
|
370
|
+
// Normalize the input if required.
|
|
371
|
+
if (this._uniformize) expr = this.normalize(expr)
|
|
372
|
+
|
|
238
373
|
|
|
239
374
|
let securityLoopLvl1 = 50,
|
|
240
375
|
securityLoopLvl2_default = 50,
|
|
@@ -259,10 +394,6 @@ export class Shutingyard {
|
|
|
259
394
|
token,
|
|
260
395
|
tokenType
|
|
261
396
|
});
|
|
262
|
-
// if(previousOpStatckLength == opStack.length && outQueue.length>=2){
|
|
263
|
-
// console.log('opStatckLength', outQueue, opStack.length)
|
|
264
|
-
// outQueue.push('*')
|
|
265
|
-
// }
|
|
266
397
|
break;
|
|
267
398
|
case 'operation':
|
|
268
399
|
previousOpStatckLength = opStack.length;
|
|
@@ -270,7 +401,6 @@ export class Shutingyard {
|
|
|
270
401
|
if (opStack.length > 0) {
|
|
271
402
|
let opTop = opStack[opStack.length - 1];
|
|
272
403
|
|
|
273
|
-
|
|
274
404
|
securityLoopLvl2 = +securityLoopLvl2_default;
|
|
275
405
|
|
|
276
406
|
//while there is an operator token o2, at the top of the operator stack and
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {describe} from "mocha";
|
|
2
2
|
import {Rational} from "../../src/maths/algebra/rational";
|
|
3
3
|
import {RationalStudy} from "../../src/maths/algebra/study/rationalStudy";
|
|
4
|
+
import {expect} from "chai";
|
|
5
|
+
import {ASYMPTOTE} from "../../src/maths/algebra/study";
|
|
4
6
|
|
|
5
7
|
describe('Study tests', () => {
|
|
6
8
|
it('should get the zeroes', function () {
|
|
@@ -9,10 +11,33 @@ describe('Study tests', () => {
|
|
|
9
11
|
new Rational('(3x-2)(x-3)(x+4)', 'x^2-5x+6')
|
|
10
12
|
)
|
|
11
13
|
|
|
12
|
-
console.log(study.texSigns)
|
|
13
|
-
console.log(study.asymptotes)
|
|
14
|
-
console.log(study.derivative.fx.texFactors)
|
|
15
|
-
console.log(study.texGrows)
|
|
14
|
+
// console.log(study.texSigns)
|
|
15
|
+
// console.log(study.asymptotes)
|
|
16
|
+
// console.log(study.derivative.fx.texFactors)
|
|
17
|
+
// console.log(study.texGrows)
|
|
18
|
+
//
|
|
19
|
+
//
|
|
20
|
+
// console.log('----------------')
|
|
16
21
|
|
|
22
|
+
|
|
23
|
+
let AO = study.asymptotes.filter(x => x.type === ASYMPTOTE.SLOPE)[0]
|
|
24
|
+
|
|
25
|
+
console.log(AO.tableOfSign.signs)
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should create draw code block', function () {
|
|
29
|
+
const study = new RationalStudy(
|
|
30
|
+
new Rational("(3x-4)(2x+5)", "(x-4)(x+4)")
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
expect(study.drawCode()).to.be.equal("f(x)=(6*x^(2)+7*x-20)/(x^(2)-16)\n" +
|
|
34
|
+
"av_1=line x=-4->red,dash\n" +
|
|
35
|
+
"av_3=line x=4->red,dash\n" +
|
|
36
|
+
"ah=line y=6->orange,dash\n" +
|
|
37
|
+
"M_6(-20.950583847231826,5.832940216581962)*\n" +
|
|
38
|
+
"M_7(-0.7637018670538883,1.4170597834180383)*\n" +
|
|
39
|
+
"Z_8(-2.5,0)*\n" +
|
|
40
|
+
"Z_9(1.3333333333333333,0)*")
|
|
17
41
|
});
|
|
42
|
+
|
|
18
43
|
})
|
|
@@ -75,4 +75,21 @@ describe("Fraction static functions", ()=>{
|
|
|
75
75
|
|
|
76
76
|
expect(Fraction.average(...list).tex).to.be.equal('\\frac{ 19 }{ 10 }')
|
|
77
77
|
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
describe("Evaluate fraction", () => {
|
|
81
|
+
it('should evaluate and convert to decimal if not exact', function () {
|
|
82
|
+
let F = new Fraction(Math.sqrt(2))
|
|
83
|
+
|
|
84
|
+
expect(F.isApproximative()).to.be.true
|
|
85
|
+
expect(F.isExact()).to.be.false
|
|
86
|
+
|
|
87
|
+
console.log(F.tex, F.value)
|
|
88
|
+
|
|
89
|
+
let G = new Fraction('1/7')
|
|
90
|
+
expect(G.isApproximative()).to.be.false
|
|
91
|
+
expect(G.isExact()).to.be.true
|
|
92
|
+
|
|
93
|
+
console.log(G.tex, G.value)
|
|
94
|
+
});
|
|
78
95
|
})
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {ExpFactorVariable} from "../../src/maths/expressions/factors/ExpFactorVariable";
|
|
2
|
+
import {expect} from "chai";
|
|
3
|
+
import {ExpFactorNumber} from "../../src/maths/expressions/factors/ExpFactorNumber";
|
|
4
|
+
import {Expression} from "../../src/maths/expressions/expression";
|
|
5
|
+
import {ExpFactorTrigo} from "../../src/maths/expressions/factors/ExpFactorTrigo";
|
|
6
|
+
import {ExpFactor} from "../../src/maths/expressions/factors/ExpFactor";
|
|
7
|
+
import {ExpressionMember} from "../../src/maths/expressions/expressionMember";
|
|
8
|
+
import {ExpressionParser} from "../../src/maths/expressions/expressionParser";
|
|
9
|
+
import {expressionOperators} from "../../src/maths/expressions/expressionOperators";
|
|
10
|
+
|
|
11
|
+
describe('Expressions tests', () => { // the tests container
|
|
12
|
+
it('should make some test', () => {
|
|
13
|
+
|
|
14
|
+
// let a = new ExpressionParser('3x').expression
|
|
15
|
+
// let a = new ExpressionParser('3x+5').expression
|
|
16
|
+
// let a = new ExpressionParser('3x^2+5').expression
|
|
17
|
+
// let a = new ExpressionParser('3x^(2/3)+5').expression
|
|
18
|
+
// let a = new ExpressionParser('3x(x+4)').expression
|
|
19
|
+
// let a = new ExpressionParser('sin(cos(3picos(3pi)-5))+sqrt(e-sin(3pi/2))').expression
|
|
20
|
+
let a = new ExpressionParser('3+nthrt(x-3,5)').expression
|
|
21
|
+
console.log('TeX output: ', a.tex)
|
|
22
|
+
console.log(a.structure())
|
|
23
|
+
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should make some operations', ()=>{
|
|
27
|
+
let a = new ExpressionParser('3x').expression,
|
|
28
|
+
b = new ExpressionParser('5x^2').expression,
|
|
29
|
+
c = new ExpressionParser('9x-2').expression
|
|
30
|
+
|
|
31
|
+
console.log(a.tex)
|
|
32
|
+
console.log(b.tex)
|
|
33
|
+
console.log(c.tex)
|
|
34
|
+
|
|
35
|
+
let sum = expressionOperators.add(a, b, c)
|
|
36
|
+
console.log(sum.tex)
|
|
37
|
+
|
|
38
|
+
let diff = expressionOperators.subtract(a, b)
|
|
39
|
+
console.log(diff.tex)
|
|
40
|
+
|
|
41
|
+
let mult = expressionOperators.multiply(a, b, c)
|
|
42
|
+
console.log(mult.tex)
|
|
43
|
+
|
|
44
|
+
let div = expressionOperators.divide(a, c)
|
|
45
|
+
console.log(div.tex)
|
|
46
|
+
})
|
|
47
|
+
it('should work :)', () => {
|
|
48
|
+
|
|
49
|
+
const expVar = new ExpFactorVariable('y', 3, 5)
|
|
50
|
+
expect(expVar.tex).to.be.equal('\\sqrt[5]{ y }^{ 3 }')
|
|
51
|
+
|
|
52
|
+
const expNum = new ExpFactorNumber(17, 3, 5)
|
|
53
|
+
expect(expNum.tex).to.be.equal('\\sqrt[5]{ 17 }^{ 3 }')
|
|
54
|
+
|
|
55
|
+
const expProduct1 = new ExpressionMember(expNum, expVar)
|
|
56
|
+
const expProduct2 = new ExpressionMember(
|
|
57
|
+
new ExpFactorNumber(4),
|
|
58
|
+
new ExpFactorVariable('t', 7, 2)
|
|
59
|
+
)
|
|
60
|
+
expect(expProduct2.tex).to.be.equal("4\\sqrt{ t }^{ 7 }")
|
|
61
|
+
|
|
62
|
+
const expr = new Expression(
|
|
63
|
+
expProduct1,
|
|
64
|
+
expProduct2
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const ExpSin = new ExpFactorTrigo(
|
|
68
|
+
'sin',
|
|
69
|
+
expr,
|
|
70
|
+
3, 7
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const expNum1 = new Expression(
|
|
74
|
+
new ExpressionMember(
|
|
75
|
+
new ExpFactorNumber(3, 2, 7),
|
|
76
|
+
new ExpFactorNumber(4, -3, 2)
|
|
77
|
+
),
|
|
78
|
+
new ExpressionMember(
|
|
79
|
+
new ExpFactorNumber(5),
|
|
80
|
+
new ExpFactor(
|
|
81
|
+
new Expression(
|
|
82
|
+
new ExpressionMember(
|
|
83
|
+
new ExpFactorNumber(3, 2),
|
|
84
|
+
new ExpFactorNumber(2, 1, 3)
|
|
85
|
+
),
|
|
86
|
+
new ExpressionMember(
|
|
87
|
+
new ExpFactorNumber(-4, 3),
|
|
88
|
+
new ExpFactorNumber(7, 2, 6)
|
|
89
|
+
),
|
|
90
|
+
new ExpressionMember(
|
|
91
|
+
new ExpFactorNumber(-3),
|
|
92
|
+
ExpSin
|
|
93
|
+
)
|
|
94
|
+
), 2, 3
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
expect(expNum1.hasVariable()).to.be.false;
|
|
100
|
+
const expNumSin = new Expression(
|
|
101
|
+
new ExpressionMember(
|
|
102
|
+
new ExpFactorTrigo('sin', expNum1)
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
expect(expNumSin.isNumeric()).to.be.true;
|
|
107
|
+
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('should parse an expression', () => {
|
|
111
|
+
|
|
112
|
+
// let E = new Expression().parse('3x')
|
|
113
|
+
// console.log(E.tex)
|
|
114
|
+
//
|
|
115
|
+
// const SY5: Shutingyard = new Shutingyard().parse('3/2*x^(-3)-5*x*y-12');
|
|
116
|
+
//
|
|
117
|
+
// console.log(SY5.rpn.map(x=>x.token))
|
|
118
|
+
// console.log(SY5.rpn)
|
|
119
|
+
//
|
|
120
|
+
// const expr = new Expression()
|
|
121
|
+
// expr.parse('3/2*x^(-3)-5*x*y-12')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
});
|
|
@@ -33,4 +33,26 @@ describe('Shuting yard', () => { // the tests container
|
|
|
33
33
|
expect(SY1.rpn.map(x=>x.token)).to.have.all.members(['A', 'B', '|', 'C', '&'])
|
|
34
34
|
expect(SY2.rpn.map(x=>x.token)).to.have.all.members(['A', 'B', '-', 'C', '!', '&'])
|
|
35
35
|
})
|
|
36
|
+
|
|
37
|
+
it('should uniformize the expression', ()=>{
|
|
38
|
+
// const SY1: Shutingyard = new Shutingyard(ShutingyardMode.POLYNOM).parse('3xx^2(x+5)')
|
|
39
|
+
// expect(SY1.rpn.map(x=>x.token)).to.have.all.members([
|
|
40
|
+
// '3', 'x', '*', 'x',
|
|
41
|
+
// '2', '^', '*', 'x',
|
|
42
|
+
// '5', '+', '*'
|
|
43
|
+
// ])
|
|
44
|
+
//
|
|
45
|
+
// const SY2: Shutingyard = new Shutingyard(ShutingyardMode.EXPRESSION).parse('3xysqrt(x-b)-ab')
|
|
46
|
+
// expect(SY2.rpn.map(x=>x.token)).to.have.all.members([
|
|
47
|
+
// '3', 'x', '*',
|
|
48
|
+
// 'y', 'x', 'b',
|
|
49
|
+
// '-', 'sqrt', '*',
|
|
50
|
+
// 'a', 'b', '*',
|
|
51
|
+
// '-'
|
|
52
|
+
// ])
|
|
53
|
+
|
|
54
|
+
console.log(new Shutingyard(ShutingyardMode.EXPRESSION).normalize('3x(x-5)^(2(x+7))'))
|
|
55
|
+
console.log(new Shutingyard(ShutingyardMode.EXPRESSION).normalize('sin(cos(3pi-5))+sqrt(e-sin(3pi/2))'))
|
|
56
|
+
console.log(new Shutingyard(ShutingyardMode.EXPRESSION).normalize('sin(cos(3picos(3pi)-5))+sqrt(e-sin(3pi/2))'))
|
|
57
|
+
})
|
|
36
58
|
});
|
package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40_[Changes]/shelved.patch
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
Index: .idea/misc.xml
|
|
2
|
-
IDEA additional info:
|
|
3
|
-
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
|
|
4
|
-
<+><?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<project version=\"4\">\r\n <component name=\"JavaScriptSettings\">\r\n <option name=\"languageLevel\" value=\"ES6\" />\r\n </component>\r\n</project>
|
|
5
|
-
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
|
|
6
|
-
<+>UTF-8
|
|
7
|
-
===================================================================
|
|
8
|
-
diff --git a/.idea/misc.xml b/.idea/misc.xml
|
|
9
|
-
--- a/.idea/misc.xml (revision 086de26cdf0bc1b6bbd0062eb9ca7bf11d946bae)
|
|
10
|
-
+++ b/.idea/misc.xml (date 1650192033467)
|
|
11
|
-
@@ -3,4 +3,9 @@
|
|
12
|
-
<component name="JavaScriptSettings">
|
|
13
|
-
<option name="languageLevel" value="ES6" />
|
|
14
|
-
</component>
|
|
15
|
-
+ <component name="SwUserDefinedSpecifications">
|
|
16
|
-
+ <option name="specTypeByUrl">
|
|
17
|
-
+ <map />
|
|
18
|
-
+ </option>
|
|
19
|
-
+ </component>
|
|
20
|
-
</project>
|
|
21
|
-
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
<changelist name="Uncommitted_changes_before_Update_at_17_04_2022_12_40_[Changes]" date="1650192056419" recycled="true" deleted="true">
|
|
2
|
-
<option name="PATH" value="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40_[Changes]/shelved.patch" />
|
|
3
|
-
<option name="DESCRIPTION" value="Uncommitted changes before Update at 17.04.2022 12:40 [Changes]" />
|
|
4
|
-
</changelist>
|