pimath 0.0.72 → 0.0.75

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
@@ -3139,18 +3139,40 @@ class Polynom {
3139
3139
  }
3140
3140
  get texFactors() {
3141
3141
  this.factorize();
3142
- if (this.factors.length === 0) {
3142
+ if (this.factors.length <= 1) {
3143
3143
  return this.tex;
3144
3144
  }
3145
3145
  let tex = '';
3146
+ // Build an array of texFactors with the number of similar items.
3147
+ let factorsCount = {};
3146
3148
  for (let f of this.factors) {
3147
- if (f.monoms.length > 1) {
3148
- tex += `(${f.tex})`;
3149
+ if (factorsCount[f.tex] !== undefined) {
3150
+ factorsCount[f.tex].degree++;
3149
3151
  }
3150
3152
  else {
3151
- tex = f.tex + tex;
3153
+ factorsCount[f.tex] = {
3154
+ degree: 1,
3155
+ factor: f
3156
+ };
3157
+ }
3158
+ }
3159
+ for (let item of Object.values(factorsCount)) {
3160
+ if (item.factor.length > 1) {
3161
+ tex += `\\left( ${item.factor.tex} \\right)${item.degree > 1 ? '^{ ' + item.degree + ' }' : ''}`;
3162
+ }
3163
+ else {
3164
+ tex += item.degree === 1 ? item.factor.tex : `\\left( ${item.factor} \\right^{ ${item.degree} }`;
3152
3165
  }
3153
3166
  }
3167
+ //
3168
+ // // Actual system
3169
+ // for (let f of this.factors) {
3170
+ // if (f.monoms.length > 1) {
3171
+ // tex += `(${f.tex})`
3172
+ // } else {
3173
+ // tex = f.tex + tex;
3174
+ // }
3175
+ // }
3154
3176
  return tex;
3155
3177
  }
3156
3178
  get length() {
@@ -3303,6 +3325,11 @@ class Rational {
3303
3325
  this._denominator = D.clone().pow(2);
3304
3326
  return this;
3305
3327
  };
3328
+ this.factorize = (letter) => {
3329
+ this._numerator.factorize(letter);
3330
+ this._denominator.factorize(letter);
3331
+ return this;
3332
+ };
3306
3333
  this.simplify = (P) => {
3307
3334
  let NumeratorEuclidien = this._numerator.euclidian(P);
3308
3335
  if (!NumeratorEuclidien.reminder.isZero()) {
@@ -4744,6 +4771,16 @@ class NumExp {
4744
4771
  else if (element.token === 'sqrt') {
4745
4772
  this._addToStack(stack, Math.sqrt(a));
4746
4773
  }
4774
+ else if (element.token === 'nthrt') {
4775
+ // TODO: support nthrt in num. exp.
4776
+ // this._addToStack(stack, Math.pow(a, 1/b))
4777
+ }
4778
+ else if (element.token === 'ln') {
4779
+ this._addToStack(stack, Math.log(a));
4780
+ }
4781
+ else if (element.token === 'log') {
4782
+ this._addToStack(stack, Math.log10(a));
4783
+ }
4747
4784
  }
4748
4785
  }
4749
4786
  if (stack.length === 1) {
@@ -5199,9 +5236,26 @@ class Circle {
5199
5236
  get developed() {
5200
5237
  return this._cartesian.tex;
5201
5238
  }
5202
- // TODO: reformat code for better display.
5203
5239
  get display() {
5204
- return this._cartesian.display;
5240
+ if (this._exists) {
5241
+ let cx, cy;
5242
+ if (this._center.x.isZero()) {
5243
+ cx = 'x^2';
5244
+ }
5245
+ else {
5246
+ cx = `(x${this._center.x.isNegative() ? '+' : '-'}${this._center.x.clone().abs().tex})^2`;
5247
+ }
5248
+ if (this._center.y.isZero()) {
5249
+ cy = 'y^2';
5250
+ }
5251
+ else {
5252
+ cy = `(y${this._center.y.isNegative() ? '+' : '-'}${this._center.y.clone().abs().tex})^2`;
5253
+ }
5254
+ return `${cx}+${cy}=${this._squareRadius.display}`;
5255
+ }
5256
+ else {
5257
+ return `\\text{le cercle n'existe pas.}`;
5258
+ }
5205
5259
  }
5206
5260
  clone() {
5207
5261
  this._center = this._center.clone();
@@ -6920,6 +6974,9 @@ class Shutingyard {
6920
6974
  'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
6921
6975
  'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
6922
6976
  'sqrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
6977
+ 'nthrt': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
6978
+ 'ln': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
6979
+ 'log': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
6923
6980
  };
6924
6981
  this._uniformize = false;
6925
6982
  }