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/dev/pi.js CHANGED
@@ -184,11 +184,12 @@ class Equation {
184
184
  // Start by moving everything to the left.
185
185
  this._left.subtract(this._right);
186
186
  this._right.zero();
187
- for (let m of this._left.monoms) {
187
+ let values = [...this._left.monoms];
188
+ for (let m of values) {
188
189
  if (!m.hasLetter(letter)) {
189
190
  mMove = m.clone();
190
- this._left.add(mMove.clone().opposed());
191
- this._right.add(mMove.clone().opposed());
191
+ this._left.subtract(mMove);
192
+ this._right.subtract(mMove);
192
193
  }
193
194
  }
194
195
  // In theory, we should have only one item on the left.
@@ -219,7 +220,7 @@ class Equation {
219
220
  if (this._sign !== '=' && F.sign() === -1) {
220
221
  this._reverseSign();
221
222
  }
222
- return this;
223
+ return this.reorder();
223
224
  };
224
225
  /**
225
226
  * divide an equation by a given value (transformed as a fraction)
@@ -2734,8 +2735,23 @@ class Polynom {
2734
2735
  };
2735
2736
  this.reorder = (letter = 'x') => {
2736
2737
  // TODO: Must handle multiple setLetter reorder system
2738
+ let otherLetters = this.variables.filter(x => x !== letter);
2737
2739
  this._monoms.sort(function (a, b) {
2738
- return b.degree(letter).clone().subtract(a.degree(letter)).value;
2740
+ let da = a.degree(letter).value, db = b.degree(letter).value;
2741
+ // Values are different
2742
+ if (da !== db)
2743
+ return db - da;
2744
+ // if values are equals, check other letters.
2745
+ if (otherLetters.length > 0) {
2746
+ for (let L of otherLetters) {
2747
+ let da = a.degree(L).value, db = b.degree(L).value;
2748
+ // Values are different
2749
+ if (da !== db)
2750
+ return db - da;
2751
+ }
2752
+ }
2753
+ return 0;
2754
+ // return b.degree(letter).clone().subtract(a.degree(letter)).value
2739
2755
  });
2740
2756
  return this;
2741
2757
  };
@@ -3382,6 +3398,7 @@ class Polynom {
3382
3398
  }
3383
3399
  // Remove duplicates.
3384
3400
  V = [...new Set(V)];
3401
+ V.sort();
3385
3402
  return V;
3386
3403
  }
3387
3404
  get numberOfVars() {
@@ -6957,6 +6974,15 @@ class Numeric {
6957
6974
  }
6958
6975
  // Find the periodic if it exists.
6959
6976
  }
6977
+ static decompose(value) {
6978
+ let dividers = Numeric.dividers(value), limit = Math.sqrt(value), arr = [], u, v;
6979
+ while (dividers.length > 0) {
6980
+ u = dividers.shift();
6981
+ v = dividers.length > 0 ? dividers.pop() : +u;
6982
+ arr.push([u, v]);
6983
+ }
6984
+ return arr;
6985
+ }
6960
6986
  }
6961
6987
  exports.Numeric = Numeric;
6962
6988