pimath 0.0.102 → 0.0.104

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
@@ -179,11 +179,12 @@ class Equation {
179
179
  // Start by moving everything to the left.
180
180
  this._left.subtract(this._right);
181
181
  this._right.zero();
182
- for (let m of this._left.monoms) {
182
+ let values = [...this._left.monoms];
183
+ for (let m of values) {
183
184
  if (!m.hasLetter(letter)) {
184
185
  mMove = m.clone();
185
- this._left.add(mMove.clone().opposed());
186
- this._right.add(mMove.clone().opposed());
186
+ this._left.subtract(mMove);
187
+ this._right.subtract(mMove);
187
188
  }
188
189
  }
189
190
  // In theory, we should have only one item on the left.
@@ -214,7 +215,7 @@ class Equation {
214
215
  if (this._sign !== '=' && F.sign() === -1) {
215
216
  this._reverseSign();
216
217
  }
217
- return this;
218
+ return this.reorder();
218
219
  };
219
220
  /**
220
221
  * divide an equation by a given value (transformed as a fraction)
@@ -2717,8 +2718,23 @@ class Polynom {
2717
2718
  };
2718
2719
  this.reorder = (letter = 'x') => {
2719
2720
  // TODO: Must handle multiple setLetter reorder system
2721
+ let otherLetters = this.variables.filter(x => x !== letter);
2720
2722
  this._monoms.sort(function (a, b) {
2721
- return b.degree(letter).clone().subtract(a.degree(letter)).value;
2723
+ let da = a.degree(letter).value, db = b.degree(letter).value;
2724
+ // Values are different
2725
+ if (da !== db)
2726
+ return db - da;
2727
+ // if values are equals, check other letters.
2728
+ if (otherLetters.length > 0) {
2729
+ for (let L of otherLetters) {
2730
+ let da = a.degree(L).value, db = b.degree(L).value;
2731
+ // Values are different
2732
+ if (da !== db)
2733
+ return db - da;
2734
+ }
2735
+ }
2736
+ return 0;
2737
+ // return b.degree(letter).clone().subtract(a.degree(letter)).value
2722
2738
  });
2723
2739
  return this;
2724
2740
  };
@@ -3365,6 +3381,7 @@ class Polynom {
3365
3381
  }
3366
3382
  // Remove duplicates.
3367
3383
  V = [...new Set(V)];
3384
+ V.sort();
3368
3385
  return V;
3369
3386
  }
3370
3387
  get numberOfVars() {
@@ -6901,6 +6918,15 @@ class Numeric {
6901
6918
  }
6902
6919
  // Find the periodic if it exists.
6903
6920
  }
6921
+ static decompose(value) {
6922
+ let dividers = Numeric.dividers(value), limit = Math.sqrt(value), arr = [], u, v;
6923
+ while (dividers.length > 0) {
6924
+ u = dividers.shift();
6925
+ v = dividers.length > 0 ? dividers.pop() : +u;
6926
+ arr.push([u, v]);
6927
+ }
6928
+ return arr;
6929
+ }
6904
6930
  }
6905
6931
  exports.Numeric = Numeric;
6906
6932