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.
package/dist/pi.js CHANGED
@@ -2,13 +2,13 @@
2
2
  /******/ "use strict";
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
5
- /***/ 519:
5
+ /***/ 607:
6
6
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
7
7
 
8
8
  var __webpack_unused_export__;
9
9
 
10
10
  __webpack_unused_export__ = ({ value: true });
11
- exports.Pi = void 0;
11
+ exports.l = void 0;
12
12
  const numeric_1 = __webpack_require__(956);
13
13
  const numexp_1 = __webpack_require__(735);
14
14
  const shutingyard_1 = __webpack_require__(505);
@@ -28,7 +28,7 @@ const triangle_1 = __webpack_require__(164);
28
28
  const circle_1 = __webpack_require__(699);
29
29
  const point_1 = __webpack_require__(557);
30
30
  // Expose as global
31
- exports.Pi = {
31
+ exports.l = {
32
32
  ShutingYard: shutingyard_1.Shutingyard,
33
33
  Numeric: numeric_1.Numeric,
34
34
  NumExp: numexp_1.NumExp,
@@ -51,7 +51,7 @@ exports.Pi = {
51
51
  Circle: circle_1.Circle
52
52
  }
53
53
  };
54
- window.Pi = exports.Pi;
54
+ window.Pi = exports.l;
55
55
 
56
56
 
57
57
  /***/ }),
@@ -2736,6 +2736,28 @@ class Polynom {
2736
2736
  }
2737
2737
  return M;
2738
2738
  };
2739
+ this.limitToInfinity = (letter) => {
2740
+ const M = this.monomByDegree(undefined, letter), sign = M.coefficient.sign(), degree = M.degree(letter);
2741
+ if (degree.isStrictlyPositive()) {
2742
+ return sign === 1 ? (new fraction_1.Fraction()).infinite() : (new fraction_1.Fraction()).infinite().opposed();
2743
+ }
2744
+ else if (degree.isZero()) {
2745
+ return M.coefficient;
2746
+ }
2747
+ // Any other cases
2748
+ return (new fraction_1.Fraction()).zero();
2749
+ };
2750
+ this.limitToNegativeInfinity = (letter) => {
2751
+ const M = this.monomByDegree(undefined, letter), sign = M.coefficient.sign(), degree = M.degree(letter);
2752
+ if (degree.isStrictlyPositive()) {
2753
+ return sign === -1 ? (new fraction_1.Fraction()).infinite() : (new fraction_1.Fraction()).infinite().opposed();
2754
+ }
2755
+ else if (degree.isZero()) {
2756
+ return M.coefficient;
2757
+ }
2758
+ // Any other cases
2759
+ return (new fraction_1.Fraction()).zero();
2760
+ };
2739
2761
  this.genDisplay = (output, forceSign, wrapParentheses) => {
2740
2762
  let P = '';
2741
2763
  for (const k of this._monoms) {
@@ -3238,9 +3260,7 @@ class Rational {
3238
3260
  return this;
3239
3261
  };
3240
3262
  this.reduce = () => {
3241
- console.log(this._numerator.tex);
3242
3263
  this._numerator.factorize();
3243
- console.log(this._numerator.factors.map(x => x.tex));
3244
3264
  for (let f of this._numerator.factors) {
3245
3265
  this.simplify(f);
3246
3266
  }
@@ -3265,27 +3285,55 @@ class Rational {
3265
3285
  this.subtract = (R) => {
3266
3286
  return this.add(R.clone().opposed());
3267
3287
  };
3268
- this.limits = (value, letter) => {
3288
+ this.limits = (value, offset, letter) => {
3269
3289
  if (value === Infinity || value === -Infinity) {
3270
- let N = this._numerator.monomByDegree(this._numerator.degree(letter), letter), D = this._denominator.monomByDegree(this._denominator.degree(letter), letter);
3271
- N.divide(D);
3272
- if (N.degree(letter).isStrictlyPositive()) {
3273
- return N.coefficient.sign() * (Math.pow((value > 0 ? 1 : -1), N.degree(letter).value % 2)) === 1 ? Infinity : -Infinity;
3290
+ let { quotient, reminder } = this._numerator.clone().euclidian(this._denominator);
3291
+ // quotient is positive => it will be infinite.
3292
+ if (quotient.degree(letter).isStrictlyPositive()) {
3293
+ return value === Infinity ? quotient.limitToInfinity(letter) : quotient.limitToNegativeInfinity(letter);
3294
+ // return quotient.monomByDegree(undefined, letter).coefficient.sign()===1?(new Fraction()).infinite():(new Fraction()).infinite().opposed()
3274
3295
  }
3275
- if (N.degree(letter).isZero()) {
3276
- return N.coefficient;
3277
- }
3278
- if (N.degree(letter).isStrictlyPositive()) {
3279
- return N.coefficient.sign() * (Math.pow(-1, N.degree(letter).value % 2)) === 1 ? 0 : -0;
3296
+ else {
3297
+ return quotient.monomByDegree(undefined, letter).coefficient;
3280
3298
  }
3281
3299
  }
3282
3300
  else {
3283
- return this._numerator.evaluate({ letter: new fraction_1.Fraction(value) }).divide(this._denominator.evaluate({ letter: new fraction_1.Fraction(value) }));
3301
+ let evalValues = {}, evalValuesOffset = {}, theLimit, theSign, FR = this.clone().reduce();
3302
+ evalValues[letter === undefined ? 'x' : letter] = new fraction_1.Fraction(value);
3303
+ if (offset !== 'above' && offset !== 'below') {
3304
+ theLimit = FR._numerator.evaluate(evalValues)
3305
+ .divide(FR._denominator.evaluate(evalValues));
3306
+ return theLimit.isInfinity() ? theLimit.abs() : theLimit;
3307
+ }
3308
+ else {
3309
+ if (offset === 'above') {
3310
+ evalValuesOffset[letter === undefined ? 'x' : letter] = (new fraction_1.Fraction(value)).add(0.000001);
3311
+ }
3312
+ else if (offset === 'below') {
3313
+ evalValuesOffset[letter === undefined ? 'x' : letter] = (new fraction_1.Fraction(value)).subtract(0.000001);
3314
+ }
3315
+ theLimit = FR._numerator.evaluate(evalValues)
3316
+ .divide(FR._denominator.evaluate(evalValues));
3317
+ theSign = FR._numerator.evaluate(evalValuesOffset)
3318
+ .divide(FR._denominator.evaluate(evalValuesOffset)).sign();
3319
+ if (theLimit.isInfinity()) {
3320
+ return theSign === 1 ? theLimit.abs() : theLimit.abs().opposed();
3321
+ }
3322
+ else {
3323
+ return theLimit;
3324
+ }
3325
+ }
3284
3326
  }
3285
3327
  };
3286
3328
  this._numerator = numerator ? numerator.clone() : new polynom_1.Polynom();
3287
3329
  this._denominator = denominator ? denominator.clone() : new polynom_1.Polynom();
3288
3330
  }
3331
+ get numerator() {
3332
+ return this._numerator;
3333
+ }
3334
+ get denominator() {
3335
+ return this._denominator;
3336
+ }
3289
3337
  get tex() {
3290
3338
  return `\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`;
3291
3339
  }
@@ -3294,12 +3342,6 @@ class Rational {
3294
3342
  this._denominator.factorize();
3295
3343
  return `\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
3296
3344
  }
3297
- get numerator() {
3298
- return this._numerator;
3299
- }
3300
- get denominator() {
3301
- return this._denominator;
3302
- }
3303
3345
  }
3304
3346
  exports.Rational = Rational;
3305
3347
 
@@ -3710,6 +3752,9 @@ class Fraction {
3710
3752
  }
3711
3753
  // Display getter
3712
3754
  get tex() {
3755
+ if (this.isInfinity()) {
3756
+ return `${this.sign() === 1 ? '+' : '-'}\\infty`;
3757
+ }
3713
3758
  if (this._denominator === 1) {
3714
3759
  return `${this._numerator}`;
3715
3760
  }
@@ -4696,6 +4741,14 @@ class Line {
4696
4741
  return this.parseByPointAndVector(values[0], values[1]);
4697
4742
  }
4698
4743
  }
4744
+ else if (values[0] instanceof point_1.Point && values[1] instanceof Line) {
4745
+ if (values[2] === LinePropriety.Parallel || values[2] === null) {
4746
+ return this.parseByPointAndLine(values[0], values[1], LinePropriety.Parallel);
4747
+ }
4748
+ else {
4749
+ return this.parseByPointAndLine(values[0], values[1], LinePropriety.Perpendicular);
4750
+ }
4751
+ }
4699
4752
  }
4700
4753
  // TODO: Add the ability to create line from a normal vector
4701
4754
  console.log('Someting wrong happend while creating the line');
@@ -6151,6 +6204,11 @@ class Shutingyard {
6151
6204
  this._mode = typeof mode === 'undefined' ? ShutingyardMode.POLYNOM : mode;
6152
6205
  this.tokenConfigInitialization();
6153
6206
  }
6207
+ // Getter
6208
+ get rpn() {
6209
+ // console.log(this._rpn)
6210
+ return this._rpn;
6211
+ }
6154
6212
  /**
6155
6213
  * Determin if the token is a defined operation
6156
6214
  * Defined operations: + - * / ^ sin cos tan
@@ -6420,11 +6478,6 @@ class Shutingyard {
6420
6478
  this._rpn = outQueue.concat(opStack.reverse());
6421
6479
  return this;
6422
6480
  }
6423
- // Getter
6424
- get rpn() {
6425
- // console.log(this._rpn)
6426
- return this._rpn;
6427
- }
6428
6481
  }
6429
6482
  exports.Shutingyard = Shutingyard;
6430
6483
 
@@ -6462,7 +6515,7 @@ exports.Shutingyard = Shutingyard;
6462
6515
  /******/ // startup
6463
6516
  /******/ // Load entry module and return exports
6464
6517
  /******/ // This entry module is referenced by other modules so it can't be inlined
6465
- /******/ var __webpack_exports__ = __webpack_require__(519);
6518
+ /******/ var __webpack_exports__ = __webpack_require__(607);
6466
6519
  /******/
6467
6520
  /******/ })()
6468
6521
  ;