pimath 0.0.65 → 0.0.68

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 (113) hide show
  1. package/.eslintrc.js +23 -23
  2. package/dist/pi.js +191 -50
  3. package/dist/pi.js.map +1 -1
  4. package/dist/pi.min.js +1 -1
  5. package/dist/pi.min.js.map +1 -1
  6. package/docs/assets/highlight.css +78 -78
  7. package/docs/assets/main.js +52 -52
  8. package/docs/assets/style.css +1413 -1413
  9. package/docs/classes/Logicalset.Logicalset-1.html +4 -4
  10. package/docs/classes/Polynom.Rational.html +3 -3
  11. package/docs/classes/algebra_equation.Equation.html +25 -25
  12. package/docs/classes/algebra_monom.Monom.html +113 -113
  13. package/docs/classes/algebra_polynom.Polynom.html +29 -29
  14. package/docs/classes/coefficients_fraction.Fraction.html +18 -18
  15. package/docs/classes/coefficients_nthroot.NthRoot.html +2 -2
  16. package/docs/classes/geometry_circle.Circle.html +2 -2
  17. package/docs/classes/geometry_line.Line.html +2 -2
  18. package/docs/classes/geometry_triangle.Triangle.html +16 -16
  19. package/docs/classes/numeric.Numeric.html +13 -13
  20. package/docs/classes/shutingyard.Shutingyard.html +17 -17
  21. package/docs/index.html +10 -10
  22. package/docs/interfaces/algebra_equation.ISolution.html +2 -2
  23. package/docs/modules/Logicalset.html +2 -2
  24. package/docs/modules/Polynom.html +2 -2
  25. package/docs/modules/Vector.html +2 -2
  26. package/esm/maths/algebra/equation.js +2 -2
  27. package/esm/maths/algebra/equation.js.map +1 -1
  28. package/esm/maths/algebra/polynom.d.ts +4 -5
  29. package/esm/maths/algebra/polynom.js +2 -2
  30. package/esm/maths/algebra/polynom.js.map +1 -1
  31. package/esm/maths/algebra/rational.d.ts +8 -10
  32. package/esm/maths/algebra/rational.js +11 -6
  33. package/esm/maths/algebra/study/rationalStudy.d.ts +1 -2
  34. package/esm/maths/algebra/study/rationalStudy.js +25 -17
  35. package/esm/maths/algebra/study/rationalStudy.js.map +1 -1
  36. package/esm/maths/algebra/study.d.ts +13 -30
  37. package/esm/maths/algebra/study.js +33 -23
  38. package/esm/maths/algebra/study.js.map +1 -1
  39. package/esm/maths/coefficients/fraction.d.ts +8 -6
  40. package/esm/maths/coefficients/fraction.js +34 -17
  41. package/esm/maths/coefficients/fraction.js.map +1 -1
  42. package/esm/maths/expressions/expression.d.ts +21 -0
  43. package/esm/maths/expressions/expression.js +161 -0
  44. package/esm/maths/expressions/expression.js.map +1 -0
  45. package/esm/maths/expressions/expressionFactor.d.ts +29 -0
  46. package/esm/maths/expressions/expressionFactor.js +109 -0
  47. package/esm/maths/expressions/expressionFactor.js.map +1 -0
  48. package/esm/maths/expressions/expressionMember.d.ts +16 -0
  49. package/esm/maths/expressions/expressionMember.js +90 -0
  50. package/esm/maths/expressions/expressionMember.js.map +1 -0
  51. package/esm/maths/expressions/expressionOperators.d.ts +8 -0
  52. package/esm/maths/expressions/expressionOperators.js +42 -0
  53. package/esm/maths/expressions/expressionOperators.js.map +1 -0
  54. package/esm/maths/expressions/expressionParser.d.ts +12 -0
  55. package/esm/maths/expressions/expressionParser.js +219 -0
  56. package/esm/maths/expressions/expressionParser.js.map +1 -0
  57. package/esm/maths/expressions/factors/ExpFactor.d.ts +7 -0
  58. package/esm/maths/expressions/factors/ExpFactor.js +22 -0
  59. package/esm/maths/expressions/factors/ExpFactor.js.map +1 -0
  60. package/esm/maths/expressions/factors/ExpFactorConstant.d.ts +13 -0
  61. package/esm/maths/expressions/factors/ExpFactorConstant.js +49 -0
  62. package/esm/maths/expressions/factors/ExpFactorConstant.js.map +1 -0
  63. package/esm/maths/expressions/factors/ExpFactorExponential.d.ts +7 -0
  64. package/esm/maths/expressions/factors/ExpFactorExponential.js +18 -0
  65. package/esm/maths/expressions/factors/ExpFactorExponential.js.map +1 -0
  66. package/esm/maths/expressions/factors/ExpFactorNumber.d.ts +13 -0
  67. package/esm/maths/expressions/factors/ExpFactorNumber.js +36 -0
  68. package/esm/maths/expressions/factors/ExpFactorNumber.js.map +1 -0
  69. package/esm/maths/expressions/factors/ExpFactorPower.d.ts +9 -0
  70. package/esm/maths/expressions/factors/ExpFactorPower.js +22 -0
  71. package/esm/maths/expressions/factors/ExpFactorPower.js.map +1 -0
  72. package/esm/maths/expressions/factors/ExpFactorSin.d.ts +7 -0
  73. package/esm/maths/expressions/factors/ExpFactorSin.js +22 -0
  74. package/esm/maths/expressions/factors/ExpFactorSin.js.map +1 -0
  75. package/esm/maths/expressions/factors/ExpFactorTrigo.d.ts +19 -0
  76. package/esm/maths/expressions/factors/ExpFactorTrigo.js +40 -0
  77. package/esm/maths/expressions/factors/ExpFactorTrigo.js.map +1 -0
  78. package/esm/maths/expressions/factors/ExpFactorVariable.d.ts +12 -0
  79. package/esm/maths/expressions/factors/ExpFactorVariable.js +33 -0
  80. package/esm/maths/expressions/factors/ExpFactorVariable.js.map +1 -0
  81. package/esm/maths/expressions/internals.d.ts +12 -0
  82. package/esm/maths/expressions/internals.js +29 -0
  83. package/esm/maths/expressions/internals.js.map +1 -0
  84. package/esm/maths/shutingyard.d.ts +4 -1
  85. package/esm/maths/shutingyard.js +137 -21
  86. package/esm/maths/shutingyard.js.map +1 -1
  87. package/graph.svg +1033 -0
  88. package/package.json +1 -1
  89. package/src/maths/algebra/equation.ts +2 -2
  90. package/src/maths/algebra/polynom.ts +1 -0
  91. package/src/maths/algebra/study/rationalStudy.ts +18 -7
  92. package/src/maths/algebra/study.ts +5 -4
  93. package/src/maths/coefficients/fraction.ts +111 -86
  94. package/src/maths/expressions/expression.ts +191 -0
  95. package/src/maths/expressions/expressionFactor.ts +138 -0
  96. package/src/maths/expressions/expressionMember.ts +114 -0
  97. package/src/maths/expressions/expressionOperators.ts +49 -0
  98. package/src/maths/expressions/expressionParser.ts +249 -0
  99. package/src/maths/expressions/factors/ExpFactor.ts +26 -0
  100. package/src/maths/expressions/factors/ExpFactorConstant.ts +56 -0
  101. package/src/maths/expressions/factors/ExpFactorExponential.ts +19 -0
  102. package/src/maths/expressions/factors/ExpFactorNumber.ts +44 -0
  103. package/src/maths/expressions/factors/ExpFactorPower.ts +24 -0
  104. package/src/maths/expressions/factors/ExpFactorTrigo.ts +44 -0
  105. package/src/maths/expressions/factors/ExpFactorVariable.ts +40 -0
  106. package/src/maths/expressions/internals.ts +14 -0
  107. package/src/maths/shutingyard.ts +156 -26
  108. package/tests/algebra/study.test.ts +11 -5
  109. package/tests/coefficients/fraction.test.ts +17 -0
  110. package/tests/expressions/expressions.test.ts +124 -0
  111. package/tests/shutingyard.test.ts +22 -0
  112. package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40_[Changes]/shelved.patch +0 -21
  113. package/.idea/shelf/Uncommitted_changes_before_Update_at_17_04_2022_12_40__Changes_.xml +0 -4
@@ -0,0 +1,24 @@
1
+ import {Expression} from "../internals";
2
+ import {ExpressionFactor} from "../internals";
3
+
4
+ export class ExpFactorPower extends ExpressionFactor {
5
+ private powerArgument: Expression
6
+ constructor(radical: Expression, power: Expression, power2?: number, root?:number) {
7
+ super(radical, power2, root);
8
+
9
+ this.powerArgument = power
10
+ }
11
+ derivative(variable: string): Expression {
12
+ return undefined
13
+ }
14
+
15
+ integrate(variable: string): Expression {
16
+ return undefined
17
+ }
18
+
19
+ makeTeX(): string {
20
+ let tex: string = `{ ${ this.argument.tex } }^{ ${this.powerArgument.tex } }`
21
+
22
+ return this.texPowerAndRoot(this.wrapWithParentheses(tex))
23
+ }
24
+ }
@@ -0,0 +1,44 @@
1
+ import {Expression} from "../internals";
2
+ import {ExpressionFactor} from "../internals";
3
+
4
+ export enum TRIGONOMETRIC {
5
+ sin='sin',
6
+ cos='cos',
7
+ tan='tan',
8
+ cot='cot',
9
+ asin='asin',
10
+ atan='atan',
11
+ acos='acos',
12
+ acot='acot'
13
+ }
14
+ export class ExpFactorTrigo extends ExpressionFactor {
15
+
16
+ private _trigo: string
17
+ constructor(trigo: string, argument: Expression, power?: number, root?: number) {
18
+
19
+ super(argument, power, root);
20
+
21
+ if(! (trigo in TRIGONOMETRIC)){
22
+ throw `The ${ trigo } is not a valid trigonometric function.`
23
+ }
24
+
25
+ this._trigo = trigo
26
+ }
27
+ derivative(variable: string): Expression {
28
+ return undefined
29
+ }
30
+
31
+ integrate(variable: string): Expression {
32
+ return undefined
33
+ }
34
+
35
+ makeTeX(): string {
36
+ let tex = `\\${this._trigo}`
37
+ if(this.root>1){
38
+ tex += `^{ ${this.root} }`
39
+ }
40
+
41
+ tex+= `\\left( ${this.argument.tex} \\right)`
42
+ return this.texRoot(tex);
43
+ }
44
+ }
@@ -0,0 +1,40 @@
1
+ import {Expression} from "../internals";
2
+ import {ExpressionFactor} from "../internals";
3
+
4
+ export class ExpFactorVariable extends ExpressionFactor {
5
+ private _variable: string
6
+ constructor(value: string, power?: number, root?: number) {
7
+ super(null, power, root);
8
+
9
+ if (typeof value !== "string") {
10
+ throw `The variable ${value} is not a valid value.`
11
+ }
12
+
13
+ this._variable = value
14
+ }
15
+
16
+
17
+ get variable(): string {
18
+ return this._variable;
19
+ }
20
+
21
+ set variable(value: string) {
22
+ this._variable = value;
23
+ }
24
+
25
+ makeTeX(): string {
26
+ return this.texPower(this.texRoot(this._variable))
27
+ }
28
+
29
+ derivative(variable: string): Expression {
30
+ return undefined;
31
+ }
32
+
33
+ integrate(variable: string): Expression {
34
+ return undefined;
35
+ }
36
+
37
+ hasVariable(variable?: string): boolean {
38
+ return this._variable === variable
39
+ }
40
+ }
@@ -0,0 +1,14 @@
1
+ export * from "./expression"
2
+ export * from "./expressionParser"
3
+ export * from "./expressionMember"
4
+
5
+ export * from "./expressionFactor"
6
+ export * from "./factors/ExpFactor"
7
+ export * from "./factors/ExpFactorConstant"
8
+ export * from "./factors/ExpFactorExponential"
9
+ export * from "./factors/ExpFactorNumber"
10
+ export * from "./factors/ExpFactorPower"
11
+ export * from "./factors/ExpFactorTrigo"
12
+ export * from "./factors/ExpFactorVariable"
13
+
14
+ export * from "../shutingyard"
@@ -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.,]+)/)[0]
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 = expr.replace(/\)\(/g, ')*(');
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
- // TODO: More robust solution to handle all letters ?
211
- expr2 = expr2.replace(/([abcxyz])([abcxyz])/g, "$1*$2");
212
-
213
- // Restore operation auto formating (prevent adding the mutliplcation star)
214
- // TODO: Accept list of functions
215
- let fnToken = ['sin', 'cos', 'tan']
216
- for (let token of fnToken) {
217
- expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
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
- expr = this.Uniformizer(expr);
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
@@ -2,6 +2,7 @@ import {describe} from "mocha";
2
2
  import {Rational} from "../../src/maths/algebra/rational";
3
3
  import {RationalStudy} from "../../src/maths/algebra/study/rationalStudy";
4
4
  import {expect} from "chai";
5
+ import {ASYMPTOTE} from "../../src/maths/algebra/study";
5
6
 
6
7
  describe('Study tests', () => {
7
8
  it('should get the zeroes', function () {
@@ -10,14 +11,18 @@ describe('Study tests', () => {
10
11
  new Rational('(3x-2)(x-3)(x+4)', 'x^2-5x+6')
11
12
  )
12
13
 
13
- console.log(study.texSigns)
14
- console.log(study.asymptotes)
15
- console.log(study.derivative.fx.texFactors)
16
- 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('----------------')
17
21
 
18
22
 
19
- console.log('----------------')
23
+ let AO = study.asymptotes.filter(x => x.type === ASYMPTOTE.SLOPE)[0]
20
24
 
25
+ console.log(AO.tableOfSign.signs)
21
26
  });
22
27
 
23
28
  it('should create draw code block', function () {
@@ -34,4 +39,5 @@ describe('Study tests', () => {
34
39
  "Z_8(-2.5,0)*\n" +
35
40
  "Z_9(1.3333333333333333,0)*")
36
41
  });
42
+
37
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
  });
@@ -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>