pimath 0.0.36 → 0.0.39

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.
@@ -51,6 +51,10 @@ export class Fraction {
51
51
 
52
52
  // Display getter
53
53
  get tex(): string {
54
+ if(this.isInfinity()){
55
+ return `${this.sign()===1?'+':'-'}\\infty`
56
+ }
57
+
54
58
  if (this._denominator === 1) {
55
59
  return `${this._numerator}`;
56
60
  } else if (this._numerator < 0) {
@@ -195,6 +195,12 @@ export class Line {
195
195
  }else if (values[2] === LinePropriety.Parallel){
196
196
  return this.parseByPointAndVector(values[0], values[1])
197
197
  }
198
+ }else if (values[0] instanceof Point && values[1] instanceof Line ) {
199
+ if(values[2]===LinePropriety.Parallel || values[2]===null) {
200
+ return this.parseByPointAndLine(values[0], values[1], LinePropriety.Parallel)
201
+ }else{
202
+ return this.parseByPointAndLine(values[0], values[1], LinePropriety.Perpendicular)
203
+ }
198
204
  }
199
205
  }
200
206
 
@@ -10,8 +10,8 @@ import {Fraction} from "../coefficients/fraction";
10
10
  * Helper class - a way to identify an object {x: number, y: number}
11
11
  */
12
12
  class PointXY {
13
- public x: number
14
- public y: number
13
+ x: number
14
+ y: number
15
15
  }
16
16
 
17
17
  export class Point {
@@ -1,6 +1,3 @@
1
- import {loadHighlighter} from "typedoc/dist/lib/utils/highlighter";
2
- import exp = require("constants");
3
-
4
1
  export type tokenType = {
5
2
  [key: string]: {
6
3
  precedence: number,
@@ -9,14 +6,14 @@ export type tokenType = {
9
6
  }
10
7
  }
11
8
 
12
- export const tokenConstant:{[Key:string]:number} = {
9
+ export const tokenConstant: { [Key: string]: number } = {
13
10
  pi: Math.PI,
14
11
  e: Math.exp(1)
15
12
  }
16
13
 
17
14
  export enum ShutingyardType {
18
- VARIABLE='variable',
19
- COEFFICIENT='coefficient',
15
+ VARIABLE = 'variable',
16
+ COEFFICIENT = 'coefficient',
20
17
  OPERATION = 'operation',
21
18
  CONSTANT = 'constant',
22
19
  FUNCTION = 'function',
@@ -24,7 +21,7 @@ export enum ShutingyardType {
24
21
  }
25
22
 
26
23
  export enum ShutingyardMode {
27
- POLYNOM= 'polynom',
24
+ POLYNOM = 'polynom',
28
25
  SET = 'set',
29
26
  NUMERIC = 'numeric'
30
27
  }
@@ -32,18 +29,25 @@ export enum ShutingyardMode {
32
29
  export type Token = { token: string, tokenType: string }
33
30
 
34
31
  export class Shutingyard {
35
- private _rpn: Token[] = [];
36
32
  readonly _mode: ShutingyardMode;
37
33
  private _tokenConfig: tokenType;
38
- private _tokenConstant: {[Key:string]: number}
39
- private _uniformize: boolean;
34
+ private _tokenConstant: { [Key: string]: number }
40
35
  private _tokenKeys: string[]
36
+ private _uniformize: boolean;
41
37
 
42
- constructor(mode?: ShutingyardMode ) {
38
+ constructor(mode?: ShutingyardMode) {
43
39
  this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
44
40
  this.tokenConfigInitialization()
45
41
  }
46
42
 
43
+ private _rpn: Token[] = [];
44
+
45
+ // Getter
46
+ get rpn() {
47
+ // console.log(this._rpn)
48
+ return this._rpn;
49
+ }
50
+
47
51
  /**
48
52
  * Determin if the token is a defined operation
49
53
  * Defined operations: + - * / ^ sin cos tan
@@ -70,7 +74,7 @@ export class Shutingyard {
70
74
  '-': {precedence: 2, associative: 'left', type: ShutingyardType.OPERATION}
71
75
  }
72
76
  this._uniformize = false;
73
- }else if (this._mode === ShutingyardMode.NUMERIC){
77
+ } else if (this._mode === ShutingyardMode.NUMERIC) {
74
78
  this._tokenConfig = {
75
79
  '^': {precedence: 4, associative: 'right', type: ShutingyardType.OPERATION},
76
80
  '*': {precedence: 3, associative: 'left', type: ShutingyardType.OPERATION},
@@ -99,7 +103,7 @@ export class Shutingyard {
99
103
  this._uniformize = true
100
104
  }
101
105
 
102
- this._tokenKeys = Object.keys(this._tokenConfig).sort((a,b)=>b.length-a.length)
106
+ this._tokenKeys = Object.keys(this._tokenConfig).sort((a, b) => b.length - a.length)
103
107
  return this._tokenConfig
104
108
  }
105
109
 
@@ -126,14 +130,14 @@ export class Shutingyard {
126
130
  else if (expr[start] === ',') {
127
131
  token = ',';
128
132
  tokenType = 'function-argument';
129
- } else{
133
+ } else {
130
134
  // Order token keys by token characters length (descending)
131
135
  // TODO: this is done each time ! SHould be done once !
132
136
  // const keys = Object.keys(this._tokenConfig).sort((a,b)=>b.length-a.length)
133
137
 
134
138
  // Extract operation and function tokens
135
- for(let key of this._tokenKeys){
136
- if(expr.substring(start, start+key.length) === key){
139
+ for (let key of this._tokenKeys) {
140
+ if (expr.substring(start, start + key.length) === key) {
137
141
  token += key;
138
142
  tokenType = this._tokenConfig[key].type
139
143
  break
@@ -141,27 +145,27 @@ export class Shutingyard {
141
145
  }
142
146
 
143
147
  // Extract constant
144
- for(let key in tokenConstant){
145
- if(expr.substring(start, start+key.length) === key){
148
+ for (let key in tokenConstant) {
149
+ if (expr.substring(start, start + key.length) === key) {
146
150
  token += key;
147
151
  tokenType = ShutingyardType.CONSTANT
148
152
  break
149
153
  }
150
154
  }
151
155
 
152
- if(token===''){
156
+ if (token === '') {
153
157
  // No function found ! Might be a coefficient !
154
- if( expr[start].match(/[0-9]/) ) {
155
- if(this._mode === ShutingyardMode.POLYNOM && false) {
158
+ if (expr[start].match(/[0-9]/)) {
159
+ if (this._mode === ShutingyardMode.POLYNOM && false) {
156
160
  token = expr.substring(start).match(/^([0-9.,/]+)/)[0]
157
- }else{
161
+ } else {
158
162
  token = expr.substring(start).match(/^([0-9.,]+)/)[0]
159
163
  }
160
164
  tokenType = ShutingyardType.COEFFICIENT
161
- }else if (expr[start].match(/[a-zA-Z]/)) {
165
+ } else if (expr[start].match(/[a-zA-Z]/)) {
162
166
  token = expr.substring(start).match(/^([a-zA-Z])/)[0]
163
167
  tokenType = ShutingyardType.VARIABLE
164
- }else{
168
+ } else {
165
169
  console.log('Unidentified token', expr[start], expr, start)
166
170
  token = expr[start]
167
171
  tokenType = ShutingyardType.MONOM
@@ -180,7 +184,9 @@ export class Shutingyard {
180
184
  */
181
185
  Uniformizer(expr: string): string {
182
186
  // Determiner if need to be uniformized
183
- if(!this._uniformize){return expr}
187
+ if (!this._uniformize) {
188
+ return expr
189
+ }
184
190
 
185
191
  let expr2;
186
192
  // Replace missing multiplication between two parenthese
@@ -220,8 +226,8 @@ export class Shutingyard {
220
226
  * @param operators
221
227
  */
222
228
  parse(expr: string, operators?: string[]): Shutingyard {
223
- let outQueue: {token:string, tokenType: string}[] = [], // Output queue
224
- opStack: {token:string, tokenType: string}[] = [], // Operation queue
229
+ let outQueue: { token: string, tokenType: string }[] = [], // Output queue
230
+ opStack: { token: string, tokenType: string }[] = [], // Operation queue
225
231
  token: string = '',
226
232
  tokenPos: number = 0,
227
233
  tokenType: string = '',
@@ -287,12 +293,14 @@ export class Shutingyard {
287
293
  outQueue.push((opStack.pop()) || {token: '', tokenType: 'operation'});
288
294
 
289
295
  // Get the next operation on top of the Stack.
290
- if(opStack.length===0){break;}
296
+ if (opStack.length === 0) {
297
+ break;
298
+ }
291
299
  opTop = opStack[opStack.length - 1];
292
300
  }
293
301
  }
294
302
  //at the end of iteration push o1 onto the operator stack
295
- opStack.push({token,tokenType});
303
+ opStack.push({token, tokenType});
296
304
  break;
297
305
  case 'function-argument':
298
306
  // TODO: check if the opStack exist.
@@ -304,11 +312,11 @@ export class Shutingyard {
304
312
  break;
305
313
  }
306
314
 
307
- outQueue.push((opStack.pop()) || {token,tokenType});
315
+ outQueue.push((opStack.pop()) || {token, tokenType});
308
316
  }
309
317
  break;
310
318
  case '(':
311
- opStack.push({token,tokenType});
319
+ opStack.push({token, tokenType});
312
320
  // Add an empty value if next element is negative.
313
321
  if (expr[tokenPos] === '-') {
314
322
  outQueue.push({token: '0', tokenType: 'coefficient'});
@@ -324,7 +332,7 @@ export class Shutingyard {
324
332
  break;
325
333
  }
326
334
 
327
- outQueue.push((opStack.pop()) || {token,tokenType});
335
+ outQueue.push((opStack.pop()) || {token, tokenType});
328
336
  }
329
337
 
330
338
  //Pop the left parenthesis from the stack, but not onto the output queue.
@@ -349,11 +357,4 @@ export class Shutingyard {
349
357
  }
350
358
 
351
359
 
352
- // Getter
353
- get rpn() {
354
- // console.log(this._rpn)
355
- return this._rpn;
356
- }
357
-
358
-
359
360
  }
@@ -0,0 +1,44 @@
1
+ import {describe} from "mocha";
2
+ import {Rational} from "../../src/maths/algebra/rational";
3
+ import {Polynom} from "../../src/maths/algebra/polynom";
4
+ import {Fraction} from "../../src/maths/coefficients/fraction";
5
+ import {expect} from "chai";
6
+
7
+ describe('Rational tests', () => {
8
+ it('should calculate correctly the limits to a value', () => {
9
+
10
+ const FR = new Rational(
11
+ new Polynom('(x+2)'),
12
+ new Polynom('(x-4)(x+2)')
13
+ )
14
+
15
+ expect(FR.limits(4).tex).to.be.equal("Infinity")
16
+ expect(FR.limits(4, 'below').tex).to.be.equal("-Infinity")
17
+ expect(FR.limits(4, 'above').tex).to.be.equal("Infinity")
18
+ expect(FR.limits(-2).tex).to.be.equal("-\\frac{ 1 }{ 6 }")
19
+ })
20
+ it('should calculate the limits to Infinity', ()=>{
21
+ const FR0 = new Rational(
22
+ new Polynom('3'),
23
+ new Polynom('x-5')
24
+ )
25
+ const FR2 = new Rational(
26
+ new Polynom('2x+5'),
27
+ new Polynom('x-5')
28
+ )
29
+
30
+ const FR3 = new Rational(
31
+ new Polynom('2x^2+5'),
32
+ new Polynom('x-5')
33
+ )
34
+
35
+ expect(FR0.limits(Infinity).value).to.be.equal(0)
36
+ expect(FR0.limits(-Infinity).value).to.be.equal(0)
37
+
38
+ expect(FR2.limits(Infinity).value).to.be.equal(2)
39
+ expect(FR2.limits(-Infinity).value).to.be.equal(2)
40
+
41
+ expect(FR3.limits(Infinity).value).to.be.equal(Infinity)
42
+ expect(FR3.limits(-Infinity).value).to.be.equal(-Infinity)
43
+ })
44
+ })
@@ -2,7 +2,7 @@ const path = require('path');
2
2
 
3
3
  module.exports = {
4
4
  mode: 'production',
5
- entry: './src/main.ts',
5
+ entry: './src/index.ts',
6
6
  devtool: 'source-map',
7
7
  module: {
8
8
  rules: [
@@ -2,7 +2,7 @@ const path = require('path');
2
2
 
3
3
  module.exports = {
4
4
  mode: 'production',
5
- entry: './src/main.ts',
5
+ entry: './src/index.ts',
6
6
  devtool: 'source-map',
7
7
  module: {
8
8
  rules: [
package/webpack.config.js CHANGED
@@ -2,7 +2,7 @@ const path = require('path');
2
2
 
3
3
  module.exports = {
4
4
  mode: 'development',
5
- entry: './src/main.ts',
5
+ entry: './src/index.ts',
6
6
  devtool: 'source-map',
7
7
  module: {
8
8
  rules: [
package/esm/main.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,uDAAkD;AAClD,qDAAgD;AAChD,yDAAoD;AACpD,4DAAuD;AACvD,0DAAqD;AACrD,iDAA4C;AAC5C,qDAAgD;AAChD,uDAAkD;AAClD,+DAA0D;AAC1D,uDAAkD;AAClD,2DAAsD;AACtD,+DAAmF;AACnF,oDAA+C;AAC/C,gDAA2C;AAC3C,wDAAmD;AACnD,oDAA+C;AAC/C,kDAA6C;AAE7C,mBAAmB;AACN,QAAA,EAAE,GAAG;IACd,WAAW,EAAE,yBAAW;IACxB,OAAO,EAAE,iBAAO;IAChB,MAAM,EAAE,eAAM;IACd,QAAQ,EAAE,mBAAQ;IAClB,IAAI,EAAE,iBAAO;IACb,KAAK,EAAE,aAAK;IACZ,OAAO,EAAE,iBAAO;IAChB,QAAQ,EAAE,mBAAQ;IAClB,YAAY,EAAE,2BAAY;IAC1B,QAAQ,EAAE,mBAAQ;IAClB,UAAU,EAAE,uBAAU;IACtB,MAAM,EAAE,eAAM;IACd,gBAAgB,EAAE,6BAAgB;IAClC,iBAAiB,EAAE,8BAAiB;IACpC,QAAQ,EAAE;QACN,MAAM,EAAE,eAAM;QACd,KAAK,EAAE,aAAK;QACZ,IAAI,EAAE,WAAI;QACV,QAAQ,EAAE,mBAAQ;QAClB,MAAM,EAAE,eAAM;KACjB;CACJ,CAAC;AACI,MAAO,CAAC,EAAE,GAAG,UAAE,CAAA"}