pimath 0.0.74 → 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()) {