pimath 0.0.29 → 0.0.33

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.
Files changed (86) hide show
  1. package/dev/pi.js +852 -488
  2. package/dev/pi.js.map +1 -1
  3. package/dist/pi.js +1 -1
  4. package/dist/pi.js.map +1 -1
  5. package/docs/assets/search.js +1 -1
  6. package/docs/classes/algebra.Equation.html +9 -9
  7. package/docs/classes/algebra.LinearSystem.html +1 -1
  8. package/docs/classes/algebra.Logicalset.html +2 -2
  9. package/docs/classes/algebra.Monom.html +42 -40
  10. package/docs/classes/algebra.Polynom.html +10 -10
  11. package/docs/classes/algebra.PolynomExpFactor.html +1 -0
  12. package/docs/classes/algebra.PolynomExpProduct.html +1 -0
  13. package/docs/classes/algebra.Rational.html +2 -2
  14. package/docs/classes/coefficients.Fraction.html +4 -4
  15. package/docs/classes/coefficients.Nthroot.html +1 -1
  16. package/docs/classes/geometry.Circle.html +2 -2
  17. package/docs/classes/geometry.Line.html +2 -2
  18. package/docs/classes/geometry.Point.html +1 -1
  19. package/docs/classes/geometry.Triangle.html +6 -6
  20. package/docs/classes/geometry.Vector.html +1 -1
  21. package/docs/classes/numeric.Numeric.html +5 -5
  22. package/docs/classes/shutingyard.Shutingyard.html +7 -8
  23. package/docs/enums/shutingyard.ShutingyardMode.html +1 -0
  24. package/docs/enums/shutingyard.ShutingyardType.html +1 -0
  25. package/docs/index.html +1 -1
  26. package/docs/interfaces/geometry.remarquableLines.html +1 -1
  27. package/docs/modules/algebra.html +1 -1
  28. package/docs/modules/coefficients.html +1 -1
  29. package/docs/modules/geometry.html +1 -1
  30. package/docs/modules/numeric.html +1 -1
  31. package/docs/modules/random.Random.html +1 -1
  32. package/docs/modules/random.html +1 -1
  33. package/docs/modules/shutingyard.html +1 -1
  34. package/docs/modules.html +1 -1
  35. package/esm/main.js +3 -1
  36. package/esm/main.js.map +1 -1
  37. package/esm/maths/algebra/equation.js +1 -1
  38. package/esm/maths/algebra/equation.js.map +1 -1
  39. package/esm/maths/algebra/index.d.ts +1 -0
  40. package/esm/maths/algebra/index.js +1 -0
  41. package/esm/maths/algebra/index.js.map +1 -1
  42. package/esm/maths/algebra/monom.d.ts +4 -1
  43. package/esm/maths/algebra/monom.js +54 -39
  44. package/esm/maths/algebra/monom.js.map +1 -1
  45. package/esm/maths/algebra/polynom.d.ts +19 -15
  46. package/esm/maths/algebra/polynom.js +242 -174
  47. package/esm/maths/algebra/polynom.js.map +1 -1
  48. package/esm/maths/coefficients/fraction.d.ts +3 -0
  49. package/esm/maths/coefficients/fraction.js +21 -8
  50. package/esm/maths/coefficients/fraction.js.map +1 -1
  51. package/esm/maths/{numexp.d.ts → expressions/numexp.d.ts} +3 -0
  52. package/esm/maths/{numexp.js → expressions/numexp.js} +43 -15
  53. package/esm/maths/expressions/numexp.js.map +1 -0
  54. package/esm/maths/expressions/polynomexp.bkp.d.ts +33 -0
  55. package/esm/maths/expressions/polynomexp.bkp.js +186 -0
  56. package/esm/maths/expressions/polynomexp.bkp.js.map +1 -0
  57. package/esm/maths/expressions/polynomexp.d.ts +52 -0
  58. package/esm/maths/expressions/polynomexp.js +233 -0
  59. package/esm/maths/expressions/polynomexp.js.map +1 -0
  60. package/esm/maths/geometry/line.d.ts +3 -2
  61. package/esm/maths/geometry/line.js +3 -2
  62. package/esm/maths/geometry/line.js.map +1 -1
  63. package/esm/maths/shutingyard.d.ts +6 -6
  64. package/esm/maths/shutingyard.js +1 -5
  65. package/esm/maths/shutingyard.js.map +1 -1
  66. package/package.json +1 -1
  67. package/{dev → public}/demo.css +0 -0
  68. package/{dev → public}/index.html +48 -13
  69. package/{dev → public}/playground.html +1 -1
  70. package/src/main.ts +13 -2
  71. package/src/maths/algebra/equation.ts +1 -1
  72. package/src/maths/algebra/index.ts +2 -1
  73. package/src/maths/algebra/monom.ts +77 -51
  74. package/src/maths/algebra/polynom.ts +445 -327
  75. package/src/maths/coefficients/fraction.ts +28 -11
  76. package/src/maths/{numexp.ts → expressions/numexp.ts} +40 -20
  77. package/src/maths/expressions/polynomexp.bkp.ts +223 -0
  78. package/src/maths/expressions/polynomexp.ts +309 -0
  79. package/src/maths/geometry/line.ts +4 -2
  80. package/src/maths/shutingyard.ts +11 -7
  81. package/tests/algebra/monom.test.ts +12 -8
  82. package/tests/algebra/polynom.test.ts +35 -2
  83. package/tests/numexp.test.ts +21 -1
  84. package/tests/polynomexp.test.ts +15 -0
  85. package/tests/shutingyard.test.ts +4 -4
  86. package/esm/maths/numexp.js.map +0 -1
package/dev/pi.js CHANGED
@@ -127,7 +127,7 @@ class Equation {
127
127
  let pStr, strSign;
128
128
  strSign = this._findSign(equationString);
129
129
  if (strSign === false) {
130
- console.log('The equation is not valid (no sign found)');
130
+ console.error('The equation is not valid (no sign found)');
131
131
  return;
132
132
  }
133
133
  pStr = equationString.split(strSign);
@@ -634,6 +634,7 @@ __exportStar(__webpack_require__(/*! ./logicalset */ "./src/maths/algebra/logica
634
634
  __exportStar(__webpack_require__(/*! ./monom */ "./src/maths/algebra/monom.ts"), exports);
635
635
  __exportStar(__webpack_require__(/*! ./polynom */ "./src/maths/algebra/polynom.ts"), exports);
636
636
  __exportStar(__webpack_require__(/*! ./rational */ "./src/maths/algebra/rational.ts"), exports);
637
+ __exportStar(__webpack_require__(/*! ./../expressions/polynomexp */ "./src/maths/expressions/polynomexp.ts"), exports);
637
638
 
638
639
 
639
640
  /***/ }),
@@ -1071,8 +1072,8 @@ class Monom {
1071
1072
  }
1072
1073
  }
1073
1074
  get variables() {
1074
- this.clone().clean();
1075
- return Object.keys(this._literal);
1075
+ let M = this.clone().clean();
1076
+ return Object.keys(M.literal);
1076
1077
  }
1077
1078
  get display() {
1078
1079
  let L = '', letters = Object.keys(this._literal).sort();
@@ -1108,10 +1109,10 @@ class Monom {
1108
1109
  }
1109
1110
  }
1110
1111
  get dividers() {
1111
- if (this.coefficient.denominator !== 1) {
1112
+ if (!this.coefficient.isRelative()) {
1112
1113
  return [this.clone()];
1113
1114
  }
1114
- if (this.hasFractionCoefficient) {
1115
+ if (this.hasFractionCoefficient()) {
1115
1116
  return [this.clone()];
1116
1117
  }
1117
1118
  if (this.coefficient.numerator > 10000) {
@@ -1187,7 +1188,7 @@ class Monom {
1187
1188
  if (this._literal[letter].isNotZero()) {
1188
1189
  L += `${letter}`;
1189
1190
  if (this._literal[letter].isNotEqual(1)) {
1190
- L += `^{${this._literal[letter].display}}`;
1191
+ L += `^{${this._literal[letter].tfrac}}`;
1191
1192
  }
1192
1193
  }
1193
1194
  }
@@ -1232,6 +1233,45 @@ class Monom {
1232
1233
  }
1233
1234
  return this;
1234
1235
  };
1236
+ static addToken = (stack, element) => {
1237
+ let q1, q2, m, letter, pow;
1238
+ if (element.tokenType === shutingyard_1.ShutingyardType.COEFFICIENT) {
1239
+ stack.push(new Monom(new coefficients_1.Fraction(element.token)));
1240
+ }
1241
+ else if (element.tokenType === shutingyard_1.ShutingyardType.VARIABLE) {
1242
+ let M = new Monom().one();
1243
+ M.setLetter(element.token, 1);
1244
+ stack.push(M.clone());
1245
+ }
1246
+ else if (element.tokenType === shutingyard_1.ShutingyardType.OPERATION) {
1247
+ switch (element.token) {
1248
+ case '-':
1249
+ q2 = (stack.pop()) || new Monom().zero();
1250
+ q1 = (stack.pop()) || new Monom().zero();
1251
+ stack.push(q1.subtract(q2));
1252
+ break;
1253
+ case '*':
1254
+ q2 = (stack.pop()) || new Monom().one();
1255
+ q1 = (stack.pop()) || new Monom().one();
1256
+ stack.push(q1.multiply(q2));
1257
+ break;
1258
+ case '/':
1259
+ q2 = (stack.pop()) || new Monom().one();
1260
+ q1 = (stack.pop()) || new Monom().one();
1261
+ stack.push(q1.divide(q2));
1262
+ break;
1263
+ case '^':
1264
+ pow = (stack.pop().coefficient) || new coefficients_1.Fraction().one();
1265
+ m = (stack.pop()) || new Monom().one();
1266
+ letter = m.variables[0];
1267
+ if (letter !== undefined) {
1268
+ m.setLetter(letter, pow);
1269
+ }
1270
+ stack.push(m);
1271
+ break;
1272
+ }
1273
+ }
1274
+ };
1235
1275
  _shutingYardToReducedMonom = (inputStr) => {
1236
1276
  const SY = new shutingyard_1.Shutingyard().parse(inputStr);
1237
1277
  const rpn = SY.rpn;
@@ -1253,39 +1293,7 @@ class Monom {
1253
1293
  }
1254
1294
  else {
1255
1295
  for (const element of rpn) {
1256
- if (element.tokenType === 'coefficient') {
1257
- let M = new Monom().one();
1258
- M.coefficient = new coefficients_1.Fraction(element.token);
1259
- stack.push(M.clone());
1260
- }
1261
- else if (element.tokenType === 'variable') {
1262
- let M = new Monom().one();
1263
- M.setLetter(element.token, 1);
1264
- stack.push(M.clone());
1265
- }
1266
- else if (element.tokenType === 'operation') {
1267
- switch (element.token) {
1268
- case '-':
1269
- q2 = (stack.pop()) || new Monom().zero();
1270
- q1 = (stack.pop()) || new Monom().zero();
1271
- stack.push(q1.subtract(q2));
1272
- break;
1273
- case '*':
1274
- q2 = (stack.pop()) || new Monom().one();
1275
- q1 = (stack.pop()) || new Monom().one();
1276
- stack.push(q1.multiply(q2));
1277
- break;
1278
- case '^':
1279
- pow = (stack.pop().coefficient) || new coefficients_1.Fraction().one();
1280
- m = (stack.pop()) || new Monom().one();
1281
- letter = m.variables[0];
1282
- if (letter !== undefined) {
1283
- m.setLetter(letter, pow);
1284
- }
1285
- stack.push(m);
1286
- break;
1287
- }
1288
- }
1296
+ Monom.addToken(stack, element);
1289
1297
  }
1290
1298
  }
1291
1299
  this.one();
@@ -1331,6 +1339,11 @@ class Monom {
1331
1339
  }
1332
1340
  return this;
1333
1341
  };
1342
+ reduce = () => {
1343
+ this.clean();
1344
+ this.coefficient.reduce();
1345
+ return this;
1346
+ };
1334
1347
  opposed = () => {
1335
1348
  this._coefficient.opposed();
1336
1349
  return this;
@@ -1396,7 +1409,7 @@ class Monom {
1396
1409
  pow = (nb) => {
1397
1410
  this._coefficient.pow(nb);
1398
1411
  for (let letter in this._literal) {
1399
- this._literal[letter].pow(nb);
1412
+ this._literal[letter].multiply(nb);
1400
1413
  }
1401
1414
  return this;
1402
1415
  };
@@ -1424,6 +1437,9 @@ class Monom {
1424
1437
  return this._coefficient.isEqual(M.coefficient);
1425
1438
  case 'same':
1426
1439
  let M1 = this.variables, M2 = M.variables, K = M1.concat(M2.filter((item) => M1.indexOf(item) < 0));
1440
+ if (M1.length === 0 && M2.length === 0) {
1441
+ return true;
1442
+ }
1427
1443
  if (!this.isZero() && !M.isZero()) {
1428
1444
  for (let key of K) {
1429
1445
  if (this._literal[key] === undefined || M.literal[key] === undefined) {
@@ -1627,9 +1643,6 @@ const numeric_1 = __webpack_require__(/*! ../numeric */ "./src/maths/numeric.ts"
1627
1643
  const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
1628
1644
  class Polynom {
1629
1645
  _rawString;
1630
- _monoms;
1631
- _factors;
1632
- _texString;
1633
1646
  constructor(polynomString, ...values) {
1634
1647
  this._monoms = [];
1635
1648
  this._factors = [];
@@ -1638,18 +1651,24 @@ class Polynom {
1638
1651
  }
1639
1652
  return this;
1640
1653
  }
1654
+ _monoms;
1641
1655
  get monoms() {
1642
1656
  return this._monoms;
1643
1657
  }
1644
1658
  set monoms(M) {
1645
1659
  this._monoms = M;
1646
1660
  }
1661
+ _factors;
1647
1662
  get factors() {
1648
1663
  return this._factors;
1649
1664
  }
1650
1665
  set factors(value) {
1651
1666
  this._factors = value;
1652
1667
  }
1668
+ _texString;
1669
+ get texString() {
1670
+ return this._texString;
1671
+ }
1653
1672
  get texFactors() {
1654
1673
  this.factorize();
1655
1674
  let tex = '';
@@ -1663,9 +1682,6 @@ class Polynom {
1663
1682
  }
1664
1683
  return tex;
1665
1684
  }
1666
- get texString() {
1667
- return this._texString;
1668
- }
1669
1685
  get length() {
1670
1686
  return this._monoms.length;
1671
1687
  }
@@ -1698,28 +1714,23 @@ class Polynom {
1698
1714
  get numberOfVars() {
1699
1715
  return this.variables.length;
1700
1716
  }
1701
- genDisplay = (output, forceSign, wrapParentheses) => {
1702
- let P = '';
1703
- for (const k of this._monoms) {
1704
- if (k.coefficient.value === 0) {
1705
- continue;
1706
- }
1707
- P += `${(k.coefficient.sign() === 1 && (P !== '' || forceSign === true)) ? '+' : ''}${(output === 'tex') ? k.tex : k.display}`;
1717
+ parse = (inputStr, ...values) => {
1718
+ this._monoms = [];
1719
+ this._factors = [];
1720
+ if (typeof inputStr === 'string') {
1721
+ return this._parseString(inputStr, ...values);
1708
1722
  }
1709
- if (wrapParentheses === true && this.length > 1) {
1710
- if (output === 'tex') {
1711
- P = `\\left( ${P} \\right)`;
1712
- }
1713
- else {
1714
- P = `(${P})`;
1715
- }
1723
+ else if (typeof inputStr === 'number' || inputStr instanceof coefficients_1.Fraction || inputStr instanceof monom_1.Monom) {
1724
+ this._monoms.push(new monom_1.Monom(inputStr));
1716
1725
  }
1717
- if (P === '') {
1718
- P = '0';
1726
+ else if (inputStr instanceof Polynom) {
1727
+ for (const m of inputStr.monoms) {
1728
+ this._monoms.push(m.clone());
1729
+ }
1719
1730
  }
1720
- return P;
1731
+ return this;
1721
1732
  };
1722
- parse = (inputStr, ...values) => {
1733
+ _parseString(inputStr, ...values) {
1723
1734
  if (values === undefined || values.length === 0) {
1724
1735
  inputStr = '' + inputStr;
1725
1736
  this._rawString = inputStr;
@@ -1759,41 +1770,7 @@ class Polynom {
1759
1770
  else {
1760
1771
  return this.zero();
1761
1772
  }
1762
- };
1763
- shutingYardToReducedPolynom = (inputStr) => {
1764
- const SY = new shutingyard_1.Shutingyard().parse(inputStr);
1765
- const rpn = SY.rpn;
1766
- let m1;
1767
- let m2;
1768
- let stack = [], previousToken = null, tempPolynom;
1769
- for (const element of rpn) {
1770
- if (element.tokenType === 'coefficient' || element.tokenType === 'variable') {
1771
- tempPolynom = new Polynom().zero();
1772
- tempPolynom.monoms = [new monom_1.Monom(element.token)];
1773
- stack.push(tempPolynom.clone());
1774
- }
1775
- else if (element.tokenType === 'operation') {
1776
- m2 = (stack.pop()) || new Polynom().zero();
1777
- m1 = (stack.pop()) || new Polynom().zero();
1778
- switch (element.token) {
1779
- case '+':
1780
- stack.push(m1.add(m2));
1781
- break;
1782
- case '-':
1783
- stack.push(m1.subtract(m2));
1784
- break;
1785
- case '*':
1786
- stack.push(m1.multiply(m2));
1787
- break;
1788
- case '^':
1789
- stack.push(m1.pow(+previousToken));
1790
- }
1791
- }
1792
- previousToken = element.token;
1793
- }
1794
- this._monoms = stack[0].monoms;
1795
- return this;
1796
- };
1773
+ }
1797
1774
  clone = () => {
1798
1775
  const P = new Polynom();
1799
1776
  const M = [];
@@ -1873,31 +1850,6 @@ class Polynom {
1873
1850
  }
1874
1851
  return this;
1875
1852
  };
1876
- multiplyByPolynom = (P) => {
1877
- const M = [];
1878
- for (const m1 of this._monoms) {
1879
- for (const m2 of P.monoms) {
1880
- M.push(monom_1.Monom.xmultiply(m1, m2));
1881
- }
1882
- }
1883
- this._monoms = M;
1884
- return this.reduce();
1885
- };
1886
- multiplyByFraction = (F) => {
1887
- for (const m of this._monoms) {
1888
- m.coefficient.multiply(F);
1889
- }
1890
- return this.reduce();
1891
- };
1892
- multiplyByInteger = (nb) => {
1893
- return this.multiplyByFraction(new coefficients_1.Fraction(nb));
1894
- };
1895
- multiplyByMonom = (M) => {
1896
- for (const m of this._monoms) {
1897
- m.multiply(M);
1898
- }
1899
- return this.reduce();
1900
- };
1901
1853
  euclidian = (P) => {
1902
1854
  const letter = P.variables[0];
1903
1855
  const quotient = new Polynom().zero();
@@ -1918,29 +1870,18 @@ class Polynom {
1918
1870
  quotient.add(newM);
1919
1871
  reminder.subtract(P.clone().multiply(newM));
1920
1872
  }
1873
+ quotient.reduce();
1874
+ reminder.reduce();
1921
1875
  return { quotient, reminder };
1922
1876
  };
1923
1877
  divide = (value) => {
1924
1878
  if (value instanceof coefficients_1.Fraction) {
1925
- this.divideByFraction(value);
1879
+ return this.divideByFraction(value);
1926
1880
  }
1927
1881
  else if (typeof value === 'number' && Number.isSafeInteger(value)) {
1928
1882
  return this.divideByInteger(value);
1929
1883
  }
1930
1884
  };
1931
- divideByInteger = (nb) => {
1932
- const nbF = new coefficients_1.Fraction(nb);
1933
- for (const m of this._monoms) {
1934
- m.coefficient.divide(nbF);
1935
- }
1936
- return this;
1937
- };
1938
- divideByFraction = (F) => {
1939
- for (const m of this._monoms) {
1940
- m.coefficient.divide(F);
1941
- }
1942
- return this;
1943
- };
1944
1885
  pow = (nb) => {
1945
1886
  if (!Number.isSafeInteger(nb)) {
1946
1887
  return this.zero();
@@ -2197,82 +2138,6 @@ class Polynom {
2197
2138
  this.factors = factors;
2198
2139
  return factors;
2199
2140
  };
2200
- _factorize2ndDegree = (letter) => {
2201
- let P1, P2, a, b, c, delta, x1, x2, factor;
2202
- if (this.numberOfVars === 1) {
2203
- a = this.monomByDegree(2, letter).coefficient;
2204
- b = this.monomByDegree(1, letter).coefficient;
2205
- c = this.monomByDegree(0, letter).coefficient;
2206
- delta = b.clone().pow(2).subtract(a.clone().multiply(c).multiply(4));
2207
- if (delta.isZero()) {
2208
- x1 = b.clone().opposed().divide(a.clone().multiply(2));
2209
- P1 = new Polynom(letter).subtract(x1.display).multiply(x1.denominator);
2210
- P2 = new Polynom(letter).subtract(x1.display).multiply(x1.denominator);
2211
- factor = a.divide(x1.denominator).divide(x1.denominator);
2212
- if (!factor.isOne()) {
2213
- return [new Polynom(factor.display), P1, P2];
2214
- }
2215
- else {
2216
- return [P1, P2];
2217
- }
2218
- }
2219
- else if (delta.isPositive() && delta.isSquare()) {
2220
- x1 = b.clone().opposed()
2221
- .add(delta.clone().sqrt())
2222
- .divide(a.clone().multiply(2));
2223
- x2 = b.clone().opposed()
2224
- .subtract(delta.clone().sqrt())
2225
- .divide(a.clone().multiply(2));
2226
- factor = a.divide(x1.denominator).divide(x2.denominator);
2227
- if (factor.isOne()) {
2228
- return [
2229
- new Polynom(letter).subtract(x1.display).multiply(x1.denominator),
2230
- new Polynom(letter).subtract(x2.display).multiply(x2.denominator),
2231
- ];
2232
- }
2233
- else {
2234
- return [
2235
- new Polynom(factor.display),
2236
- new Polynom(letter).subtract(x1.display).multiply(x1.denominator),
2237
- new Polynom(letter).subtract(x2.display).multiply(x2.denominator),
2238
- ];
2239
- }
2240
- }
2241
- else {
2242
- return [this.clone()];
2243
- }
2244
- }
2245
- else {
2246
- a = this.monomByDegree(2, letter);
2247
- b = this.monomByDegree(1, letter);
2248
- c = this.monomByDegree(0, letter);
2249
- if (a.isLiteralSquare() && c.isLiteralSquare()) {
2250
- if (b.clone().pow(2).isSameAs(a.clone().multiply(c))) {
2251
- let xPolynom = new Polynom('x', a.coefficient, b.coefficient, c.coefficient);
2252
- let xFactors = xPolynom._factorize2ndDegree('x');
2253
- let factors = [], xyzPolynom;
2254
- if (xFactors.length >= 2) {
2255
- for (let p of xFactors) {
2256
- if (p.degree().isZero()) {
2257
- factors.push(p.clone());
2258
- }
2259
- else {
2260
- xyzPolynom = p.clone();
2261
- xyzPolynom.monoms[0].literal = a.literalSqrt;
2262
- xyzPolynom.monoms[1].literal = c.literalSqrt;
2263
- factors.push(xyzPolynom.clone());
2264
- }
2265
- }
2266
- return factors;
2267
- }
2268
- }
2269
- }
2270
- return [this.clone()];
2271
- }
2272
- };
2273
- _factorizeByGroups = () => {
2274
- return [];
2275
- };
2276
2141
  getZeroes = () => {
2277
2142
  const Z = [];
2278
2143
  switch (this.degree().value) {
@@ -2404,64 +2269,283 @@ class Polynom {
2404
2269
  }
2405
2270
  return M;
2406
2271
  };
2407
- }
2408
- exports.Polynom = Polynom;
2409
-
2410
-
2411
- /***/ }),
2412
-
2413
- /***/ "./src/maths/algebra/rational.ts":
2414
- /*!***************************************!*\
2415
- !*** ./src/maths/algebra/rational.ts ***!
2416
- \***************************************/
2417
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2418
-
2419
-
2420
- Object.defineProperty(exports, "__esModule", ({ value: true }));
2421
- exports.Rational = void 0;
2422
- const polynom_1 = __webpack_require__(/*! ./polynom */ "./src/maths/algebra/polynom.ts");
2423
- const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
2424
- class Rational {
2425
- _rawString;
2426
- _numerator;
2427
- _denominator;
2428
- constructor(numerator, denominator) {
2429
- this._numerator = numerator ? numerator.clone() : new polynom_1.Polynom();
2430
- this._denominator = denominator ? denominator.clone() : new polynom_1.Polynom();
2431
- }
2432
- clone = () => {
2433
- this._numerator = this._numerator.clone();
2434
- this._denominator = this._denominator.clone();
2435
- return this;
2436
- };
2437
- get tex() {
2438
- return `\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`;
2439
- }
2440
- get texFactors() {
2441
- this._numerator.factorize();
2442
- this._denominator.factorize();
2443
- return `\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
2444
- }
2445
- get numerator() {
2446
- return this._numerator;
2447
- }
2448
- get denominator() {
2449
- return this._denominator;
2450
- }
2451
- domain = () => {
2452
- let zeroes = this._denominator.getZeroes();
2453
- if (zeroes.length === 0 || zeroes[0] === false) {
2454
- return '\\mathbb{R}';
2455
- }
2456
- else if (zeroes[0] === true) {
2457
- return '\\varnothing';
2272
+ genDisplay = (output, forceSign, wrapParentheses) => {
2273
+ let P = '';
2274
+ for (const k of this._monoms) {
2275
+ if (k.coefficient.value === 0) {
2276
+ continue;
2277
+ }
2278
+ P += `${(k.coefficient.sign() === 1 && (P !== '' || forceSign === true)) ? '+' : ''}${(output === 'tex') ? k.tex : k.display}`;
2458
2279
  }
2459
- else {
2460
- return '\\mathbb{R}\\setminus\\left{' +
2461
- zeroes.map(x => {
2462
- return (typeof x === 'boolean') ? '' : x.frac;
2463
- })
2464
- .join(';') + '\\right}';
2280
+ if (wrapParentheses === true && this.length > 1) {
2281
+ if (output === 'tex') {
2282
+ P = `\\left( ${P} \\right)`;
2283
+ }
2284
+ else {
2285
+ P = `(${P})`;
2286
+ }
2287
+ }
2288
+ if (P === '') {
2289
+ P = '0';
2290
+ }
2291
+ return P;
2292
+ };
2293
+ static addToken = (stack, element) => {
2294
+ switch (element.tokenType) {
2295
+ case shutingyard_1.ShutingyardType.COEFFICIENT:
2296
+ stack.push(new Polynom(element.token));
2297
+ break;
2298
+ case shutingyard_1.ShutingyardType.VARIABLE:
2299
+ stack.push(new Polynom().add(new monom_1.Monom(element.token)));
2300
+ break;
2301
+ case shutingyard_1.ShutingyardType.CONSTANT:
2302
+ console.log('Actually, not supported - will be added later !');
2303
+ break;
2304
+ case shutingyard_1.ShutingyardType.OPERATION:
2305
+ if (stack.length >= 2) {
2306
+ const b = stack.pop(), a = stack.pop();
2307
+ if (element.token === '+') {
2308
+ stack.push(a.add(b));
2309
+ }
2310
+ else if (element.token === '-') {
2311
+ stack.push(a.subtract(b));
2312
+ }
2313
+ else if (element.token === '*') {
2314
+ stack.push(a.multiply(b));
2315
+ }
2316
+ else if (element.token === '/') {
2317
+ if (b.degree().isStrictlyPositive()) {
2318
+ console.log('divide by a polynom -> should create a rational polynom !');
2319
+ }
2320
+ else {
2321
+ stack.push(a.divide(b.monoms[0].coefficient));
2322
+ }
2323
+ }
2324
+ else if (element.token === '^') {
2325
+ if (b.degree().isStrictlyPositive()) {
2326
+ console.error('Cannot elevate a polynom with another polynom !');
2327
+ }
2328
+ else {
2329
+ if (b.monoms[0].coefficient.isRelative()) {
2330
+ stack.push(a.pow(b.monoms[0].coefficient.value));
2331
+ }
2332
+ else {
2333
+ if (a.monoms.length === 1 && a.monoms[0].coefficient.isOne()) {
2334
+ for (let letter in a.monoms[0].literal) {
2335
+ a.monoms[0].literal[letter].multiply(b.monoms[0].coefficient);
2336
+ }
2337
+ stack.push(a);
2338
+ }
2339
+ else {
2340
+ console.error('Cannot have power with fraction');
2341
+ }
2342
+ }
2343
+ }
2344
+ }
2345
+ }
2346
+ else {
2347
+ console.log('Stack size: ', stack.length);
2348
+ if (element.token === '-') {
2349
+ stack.push(stack.pop().opposed());
2350
+ }
2351
+ else {
2352
+ console.log('While parsing, cannot apply ', element.token, 'to', stack[0].tex);
2353
+ }
2354
+ }
2355
+ break;
2356
+ case shutingyard_1.ShutingyardType.MONOM:
2357
+ console.error('The monom token should not appear here');
2358
+ break;
2359
+ case shutingyard_1.ShutingyardType.FUNCTION:
2360
+ console.log('The function token should not appear here - might be introduced later.');
2361
+ break;
2362
+ }
2363
+ };
2364
+ shutingYardToReducedPolynom = (inputStr) => {
2365
+ const SY = new shutingyard_1.Shutingyard().parse(inputStr);
2366
+ const rpn = SY.rpn;
2367
+ this.zero();
2368
+ let stack = [], monom = new monom_1.Monom();
2369
+ for (const element of rpn) {
2370
+ Polynom.addToken(stack, element);
2371
+ }
2372
+ if (stack.length === 1) {
2373
+ this.add(stack[0]);
2374
+ }
2375
+ return this;
2376
+ };
2377
+ multiplyByPolynom = (P) => {
2378
+ const M = [];
2379
+ for (const m1 of this._monoms) {
2380
+ for (const m2 of P.monoms) {
2381
+ M.push(monom_1.Monom.xmultiply(m1, m2));
2382
+ }
2383
+ }
2384
+ this._monoms = M;
2385
+ return this.reduce();
2386
+ };
2387
+ multiplyByFraction = (F) => {
2388
+ for (const m of this._monoms) {
2389
+ m.coefficient.multiply(F);
2390
+ }
2391
+ return this.reduce();
2392
+ };
2393
+ multiplyByInteger = (nb) => {
2394
+ return this.multiplyByFraction(new coefficients_1.Fraction(nb));
2395
+ };
2396
+ multiplyByMonom = (M) => {
2397
+ for (const m of this._monoms) {
2398
+ m.multiply(M);
2399
+ }
2400
+ return this.reduce();
2401
+ };
2402
+ divideByInteger = (nb) => {
2403
+ const nbF = new coefficients_1.Fraction(nb);
2404
+ for (const m of this._monoms) {
2405
+ m.coefficient.divide(nbF);
2406
+ }
2407
+ return this;
2408
+ };
2409
+ divideByFraction = (F) => {
2410
+ for (const m of this._monoms) {
2411
+ m.coefficient.divide(F);
2412
+ }
2413
+ return this;
2414
+ };
2415
+ _factorize2ndDegree = (letter) => {
2416
+ let P1, P2, a, b, c, delta, x1, x2, factor;
2417
+ if (this.numberOfVars === 1) {
2418
+ a = this.monomByDegree(2, letter).coefficient;
2419
+ b = this.monomByDegree(1, letter).coefficient;
2420
+ c = this.monomByDegree(0, letter).coefficient;
2421
+ delta = b.clone().pow(2).subtract(a.clone().multiply(c).multiply(4));
2422
+ if (delta.isZero()) {
2423
+ x1 = b.clone().opposed().divide(a.clone().multiply(2));
2424
+ P1 = new Polynom(letter).subtract(x1.display).multiply(x1.denominator);
2425
+ P2 = new Polynom(letter).subtract(x1.display).multiply(x1.denominator);
2426
+ factor = a.divide(x1.denominator).divide(x1.denominator);
2427
+ if (!factor.isOne()) {
2428
+ return [new Polynom(factor.display), P1, P2];
2429
+ }
2430
+ else {
2431
+ return [P1, P2];
2432
+ }
2433
+ }
2434
+ else if (delta.isPositive() && delta.isSquare()) {
2435
+ x1 = b.clone().opposed()
2436
+ .add(delta.clone().sqrt())
2437
+ .divide(a.clone().multiply(2));
2438
+ x2 = b.clone().opposed()
2439
+ .subtract(delta.clone().sqrt())
2440
+ .divide(a.clone().multiply(2));
2441
+ factor = a.divide(x1.denominator).divide(x2.denominator);
2442
+ if (factor.isOne()) {
2443
+ return [
2444
+ new Polynom(letter).subtract(x1.display).multiply(x1.denominator),
2445
+ new Polynom(letter).subtract(x2.display).multiply(x2.denominator),
2446
+ ];
2447
+ }
2448
+ else {
2449
+ return [
2450
+ new Polynom(factor.display),
2451
+ new Polynom(letter).subtract(x1.display).multiply(x1.denominator),
2452
+ new Polynom(letter).subtract(x2.display).multiply(x2.denominator),
2453
+ ];
2454
+ }
2455
+ }
2456
+ else {
2457
+ return [this.clone()];
2458
+ }
2459
+ }
2460
+ else {
2461
+ a = this.monomByDegree(2, letter);
2462
+ b = this.monomByDegree(1, letter);
2463
+ c = this.monomByDegree(0, letter);
2464
+ if (a.isLiteralSquare() && c.isLiteralSquare()) {
2465
+ if (b.clone().pow(2).isSameAs(a.clone().multiply(c))) {
2466
+ let xPolynom = new Polynom('x', a.coefficient, b.coefficient, c.coefficient);
2467
+ let xFactors = xPolynom._factorize2ndDegree('x');
2468
+ let factors = [], xyzPolynom;
2469
+ if (xFactors.length >= 2) {
2470
+ for (let p of xFactors) {
2471
+ if (p.degree().isZero()) {
2472
+ factors.push(p.clone());
2473
+ }
2474
+ else {
2475
+ xyzPolynom = p.clone();
2476
+ xyzPolynom.monoms[0].literal = a.literalSqrt;
2477
+ xyzPolynom.monoms[1].literal = c.literalSqrt;
2478
+ factors.push(xyzPolynom.clone());
2479
+ }
2480
+ }
2481
+ return factors;
2482
+ }
2483
+ }
2484
+ }
2485
+ return [this.clone()];
2486
+ }
2487
+ };
2488
+ _factorizeByGroups = () => {
2489
+ return [];
2490
+ };
2491
+ }
2492
+ exports.Polynom = Polynom;
2493
+
2494
+
2495
+ /***/ }),
2496
+
2497
+ /***/ "./src/maths/algebra/rational.ts":
2498
+ /*!***************************************!*\
2499
+ !*** ./src/maths/algebra/rational.ts ***!
2500
+ \***************************************/
2501
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
2502
+
2503
+
2504
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2505
+ exports.Rational = void 0;
2506
+ const polynom_1 = __webpack_require__(/*! ./polynom */ "./src/maths/algebra/polynom.ts");
2507
+ const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
2508
+ class Rational {
2509
+ _rawString;
2510
+ _numerator;
2511
+ _denominator;
2512
+ constructor(numerator, denominator) {
2513
+ this._numerator = numerator ? numerator.clone() : new polynom_1.Polynom();
2514
+ this._denominator = denominator ? denominator.clone() : new polynom_1.Polynom();
2515
+ }
2516
+ clone = () => {
2517
+ this._numerator = this._numerator.clone();
2518
+ this._denominator = this._denominator.clone();
2519
+ return this;
2520
+ };
2521
+ get tex() {
2522
+ return `\\dfrac{ ${this._numerator.tex} }{ ${this._denominator.tex} }`;
2523
+ }
2524
+ get texFactors() {
2525
+ this._numerator.factorize();
2526
+ this._denominator.factorize();
2527
+ return `\\dfrac{ ${this._numerator.texFactors} }{ ${this._denominator.texFactors} }`;
2528
+ }
2529
+ get numerator() {
2530
+ return this._numerator;
2531
+ }
2532
+ get denominator() {
2533
+ return this._denominator;
2534
+ }
2535
+ domain = () => {
2536
+ let zeroes = this._denominator.getZeroes();
2537
+ if (zeroes.length === 0 || zeroes[0] === false) {
2538
+ return '\\mathbb{R}';
2539
+ }
2540
+ else if (zeroes[0] === true) {
2541
+ return '\\varnothing';
2542
+ }
2543
+ else {
2544
+ return '\\mathbb{R}\\setminus\\left{' +
2545
+ zeroes.map(x => {
2546
+ return (typeof x === 'boolean') ? '' : x.frac;
2547
+ })
2548
+ .join(';') + '\\right}';
2465
2549
  }
2466
2550
  };
2467
2551
  amplify = (P) => {
@@ -2592,6 +2676,9 @@ class Fraction {
2592
2676
  get dfrac() {
2593
2677
  return this.tex.replace('\\frac', '\\dfrac');
2594
2678
  }
2679
+ get tfrac() {
2680
+ return this.tex.replace('\\frac', '\\tfrac');
2681
+ }
2595
2682
  parse = (value, denominatorOrPeriodic) => {
2596
2683
  let S;
2597
2684
  if (value === null || value === "") {
@@ -2644,6 +2731,7 @@ class Fraction {
2644
2731
  this._numerator = value * Math.pow(10, p) - Math.floor(value * Math.pow(10, p - denominatorOrPeriodic));
2645
2732
  this.denominator = Math.pow(10, p) - Math.pow(10, p - denominatorOrPeriodic);
2646
2733
  }
2734
+ this.reduce();
2647
2735
  }
2648
2736
  break;
2649
2737
  case "object":
@@ -2730,15 +2818,21 @@ class Fraction {
2730
2818
  if (p instanceof Fraction) {
2731
2819
  return this.pow(p.value);
2732
2820
  }
2733
- if (!Number.isSafeInteger(p)) {
2734
- return this.invalid();
2735
- }
2736
2821
  this.reduce();
2737
2822
  if (p < 0) {
2738
2823
  this.invert();
2739
2824
  }
2740
- this._numerator = this._numerator ** Math.abs(p);
2741
- this._denominator = this._denominator ** Math.abs(p);
2825
+ let controlNumerator = Math.floor(Math.pow(this._numerator, Math.abs(p))), controlDenominator = Math.floor(Math.pow(this._denominator, Math.abs(p)));
2826
+ if (controlNumerator ** Math.abs(p) === this._numerator
2827
+ &&
2828
+ controlDenominator ** Math.abs(p) === this._denominator) {
2829
+ this._numerator = this._numerator ** Math.abs(p);
2830
+ this._denominator = this._denominator ** Math.abs(p);
2831
+ }
2832
+ else {
2833
+ this._numerator = this._numerator ** Math.abs(p);
2834
+ this._denominator = this._denominator ** Math.abs(p);
2835
+ }
2742
2836
  return this;
2743
2837
  };
2744
2838
  root = (p) => {
@@ -2890,16 +2984,19 @@ class Fraction {
2890
2984
  return Math.abs(numeric_1.Numeric.gcd(this._numerator, this._denominator)) === 1;
2891
2985
  };
2892
2986
  isNatural = () => {
2987
+ return this.isRelative() && this.isPositive();
2988
+ };
2989
+ isRelative = () => {
2893
2990
  return this.clone().reduce().denominator === 1;
2894
2991
  };
2895
2992
  isRational = () => {
2896
- return !this.isNatural();
2993
+ return !this.isRelative();
2897
2994
  };
2898
2995
  isEven = () => {
2899
- return this.isNatural() && this.value % 2 === 0;
2996
+ return this.isRelative() && this.value % 2 === 0;
2900
2997
  };
2901
2998
  isOdd = () => {
2902
- return this.isNatural() && this.value % 2 === 1;
2999
+ return this.isRelative() && this.value % 2 === 1;
2903
3000
  };
2904
3001
  sign = () => {
2905
3002
  return (this._numerator * this._denominator >= 0) ? 1 : -1;
@@ -2950,102 +3047,500 @@ __exportStar(__webpack_require__(/*! ./nthroot */ "./src/maths/coefficients/nthr
2950
3047
 
2951
3048
 
2952
3049
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2953
- exports.Nthroot = void 0;
2954
- class Nthroot {
2955
- _radical;
2956
- _nth;
2957
- _coefficient;
2958
- _isValid;
2959
- constructor(...values) {
2960
- this._radical = 1;
2961
- this._coefficient = 1;
2962
- this._nth = 2;
2963
- this._isValid = true;
2964
- if (values !== undefined) {
2965
- this.parse(values[0], values[1], values[2]);
3050
+ exports.Nthroot = void 0;
3051
+ class Nthroot {
3052
+ _radical;
3053
+ _nth;
3054
+ _coefficient;
3055
+ _isValid;
3056
+ constructor(...values) {
3057
+ this._radical = 1;
3058
+ this._coefficient = 1;
3059
+ this._nth = 2;
3060
+ this._isValid = true;
3061
+ if (values !== undefined) {
3062
+ this.parse(values[0], values[1], values[2]);
3063
+ }
3064
+ }
3065
+ get radical() {
3066
+ return this._radical;
3067
+ }
3068
+ set radical(value) {
3069
+ this._radical = value;
3070
+ }
3071
+ get nth() {
3072
+ return this._nth;
3073
+ }
3074
+ set nth(value) {
3075
+ if (Number.isSafeInteger(value) && value >= 2) {
3076
+ this._nth = value;
3077
+ }
3078
+ else {
3079
+ console.log('Error setting the nth root');
3080
+ this._nth = 2;
3081
+ }
3082
+ }
3083
+ get coefficient() {
3084
+ return this._coefficient;
3085
+ }
3086
+ set coefficient(value) {
3087
+ this._coefficient = value;
3088
+ }
3089
+ get tex() {
3090
+ let C;
3091
+ if (this._coefficient === 1) {
3092
+ C = '';
3093
+ }
3094
+ else if (this._coefficient === -1) {
3095
+ C = '-';
3096
+ }
3097
+ else {
3098
+ C = this._coefficient.toString();
3099
+ }
3100
+ if (this._radical === 1) {
3101
+ return `${this._coefficient}`;
3102
+ }
3103
+ else {
3104
+ if (this._nth === 2) {
3105
+ return `${C}\\sqrt{${this._radical}}`;
3106
+ }
3107
+ else {
3108
+ return `${C}\\sqrt[${this._nth}]{${this._radical}}`;
3109
+ }
3110
+ }
3111
+ }
3112
+ get value() {
3113
+ return this._coefficient * Math.pow(this._radical, 1 / this._nth);
3114
+ }
3115
+ parse = (radical, nthroot, coefficient) => {
3116
+ this._coefficient = (coefficient === undefined) ? 1 : coefficient;
3117
+ this._nth = (nthroot === undefined) ? 2 : nthroot;
3118
+ this._radical = (radical === undefined) ? 1 : radical;
3119
+ if (this._nth % 2 === 0 && this._radical < 0) {
3120
+ this._isValid = false;
3121
+ }
3122
+ return this;
3123
+ };
3124
+ reduce = () => {
3125
+ let V = Math.floor(Math.pow(this._radical, 1 / this._nth));
3126
+ while (V > 1) {
3127
+ if (this._radical % Math.pow(V, this._nth) === 0) {
3128
+ this._coefficient *= V;
3129
+ this._radical = this._radical / Math.pow(V, this._nth);
3130
+ V = Math.floor(Math.pow(this._radical, 1 / this._nth));
3131
+ continue;
3132
+ }
3133
+ V--;
3134
+ }
3135
+ return this;
3136
+ };
3137
+ multiply = (N) => {
3138
+ this._radical *= N.radical;
3139
+ return this.reduce();
3140
+ };
3141
+ hasRadical = () => {
3142
+ return !(this._radical === 1 || this._radical === 0 || this._isValid === false);
3143
+ };
3144
+ }
3145
+ exports.Nthroot = Nthroot;
3146
+
3147
+
3148
+ /***/ }),
3149
+
3150
+ /***/ "./src/maths/expressions/numexp.ts":
3151
+ /*!*****************************************!*\
3152
+ !*** ./src/maths/expressions/numexp.ts ***!
3153
+ \*****************************************/
3154
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3155
+
3156
+
3157
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3158
+ exports.NumExp = void 0;
3159
+ const shutingyard_1 = __webpack_require__(/*! ../shutingyard */ "./src/maths/shutingyard.ts");
3160
+ const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
3161
+ class NumExp {
3162
+ _rpn;
3163
+ _expression;
3164
+ _isValid;
3165
+ constructor(value) {
3166
+ this._expression = value;
3167
+ this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
3168
+ }
3169
+ get rpn() {
3170
+ return this._rpn;
3171
+ }
3172
+ get isValid() {
3173
+ if (this._isValid === undefined) {
3174
+ this.evaluate({ x: 0 });
3175
+ }
3176
+ return this._isValid;
3177
+ }
3178
+ set isValid(value) {
3179
+ this._isValid = value;
3180
+ }
3181
+ get expression() {
3182
+ return this._expression;
3183
+ }
3184
+ _extractDecimalPart(value) {
3185
+ let decimal = value.toString();
3186
+ if (!decimal.includes('.')) {
3187
+ return '';
3188
+ }
3189
+ decimal = decimal.split('.')[1];
3190
+ return decimal.substring(0, decimal.length - 2);
3191
+ }
3192
+ _numberCorrection(value) {
3193
+ const epsilon = 0.00000000000001, number_of_digits = 6;
3194
+ const decimal = this._extractDecimalPart(value);
3195
+ if (decimal === '') {
3196
+ return value;
3197
+ }
3198
+ const n9 = decimal.match(/9+$/g);
3199
+ const n0 = decimal.match(/0+$/g);
3200
+ if (n9 && n9[0].length >= number_of_digits) {
3201
+ const mod = this._extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
3202
+ if (mod0 && mod0[0].length >= number_of_digits) {
3203
+ return +((value + epsilon).toString().split(mod0[0])[0]);
3204
+ }
3205
+ }
3206
+ if (n0 && n0[0].length >= number_of_digits) {
3207
+ const mod = this._extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
3208
+ if (mod9 && mod9[0].length >= number_of_digits) {
3209
+ return +(value.toString().split(n0[0])[0]);
3210
+ }
3211
+ }
3212
+ return value;
3213
+ }
3214
+ _addToStack(stack, value) {
3215
+ stack.push(this._numberCorrection(value));
3216
+ }
3217
+ evaluate(values) {
3218
+ const stack = [];
3219
+ this.isValid = true;
3220
+ for (const element of this._rpn) {
3221
+ if (element.tokenType === shutingyard_1.ShutingyardType.COEFFICIENT) {
3222
+ if (!isNaN(+element.token)) {
3223
+ this._addToStack(stack, +element.token);
3224
+ }
3225
+ else {
3226
+ this._addToStack(stack, new coefficients_1.Fraction(element.token).value);
3227
+ }
3228
+ }
3229
+ else if (element.tokenType === shutingyard_1.ShutingyardType.VARIABLE) {
3230
+ if (values[element.token] !== undefined) {
3231
+ this._addToStack(stack, +values[element.token]);
3232
+ }
3233
+ }
3234
+ else if (element.tokenType === shutingyard_1.ShutingyardType.CONSTANT) {
3235
+ this._addToStack(stack, shutingyard_1.tokenConstant[element.token]);
3236
+ }
3237
+ else if (element.tokenType === shutingyard_1.ShutingyardType.OPERATION) {
3238
+ if (element.token === '*') {
3239
+ const b = stack.pop(), a = stack.pop();
3240
+ if (a === undefined || b === undefined) {
3241
+ this.isValid = false;
3242
+ }
3243
+ this._addToStack(stack, a * b);
3244
+ }
3245
+ else if (element.token === '/') {
3246
+ const b = stack.pop(), a = stack.pop();
3247
+ if (a === undefined || b === undefined) {
3248
+ this.isValid = false;
3249
+ }
3250
+ this._addToStack(stack, a / b);
3251
+ }
3252
+ else if (element.token === '+') {
3253
+ const b = stack.pop(), a = stack.pop();
3254
+ if (a === undefined || b === undefined) {
3255
+ this.isValid = false;
3256
+ }
3257
+ this._addToStack(stack, (+a) + (+b));
3258
+ }
3259
+ else if (element.token === '-') {
3260
+ const b = stack.pop(), a = stack.pop() || 0;
3261
+ if (b === undefined) {
3262
+ this.isValid = false;
3263
+ }
3264
+ this._addToStack(stack, a - b);
3265
+ }
3266
+ else if (element.token === '^') {
3267
+ const b = stack.pop(), a = stack.pop();
3268
+ if (a === undefined || b === undefined) {
3269
+ this.isValid = false;
3270
+ }
3271
+ this._addToStack(stack, Math.pow(a, b));
3272
+ }
3273
+ }
3274
+ else if (element.tokenType === shutingyard_1.ShutingyardType.FUNCTION) {
3275
+ const a = stack.pop();
3276
+ if (a === undefined) {
3277
+ this.isValid = false;
3278
+ }
3279
+ if (element.token === 'sin') {
3280
+ this._addToStack(stack, Math.sin(a));
3281
+ }
3282
+ else if (element.token === 'cos') {
3283
+ this._addToStack(stack, Math.cos(a));
3284
+ }
3285
+ else if (element.token === 'tan') {
3286
+ this._addToStack(stack, Math.tan(a));
3287
+ }
3288
+ else if (element.token === 'sqrt') {
3289
+ this._addToStack(stack, Math.sqrt(a));
3290
+ }
3291
+ }
3292
+ }
3293
+ if (stack.length === 1) {
3294
+ return stack[0];
3295
+ }
3296
+ else {
3297
+ throw `There was a problem parsing: ${this._expression}`;
3298
+ }
3299
+ }
3300
+ }
3301
+ exports.NumExp = NumExp;
3302
+
3303
+
3304
+ /***/ }),
3305
+
3306
+ /***/ "./src/maths/expressions/polynomexp.ts":
3307
+ /*!*********************************************!*\
3308
+ !*** ./src/maths/expressions/polynomexp.ts ***!
3309
+ \*********************************************/
3310
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3311
+
3312
+
3313
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3314
+ exports.PolynomExpProduct = exports.PolynomExpFactor = void 0;
3315
+ const algebra_1 = __webpack_require__(/*! ../algebra */ "./src/maths/algebra/index.ts");
3316
+ const coefficients_1 = __webpack_require__(/*! ../coefficients */ "./src/maths/coefficients/index.ts");
3317
+ class PolynomExpFactor {
3318
+ constructor(polynom, degree, mathFunction) {
3319
+ this._polynom = new algebra_1.Polynom(polynom);
3320
+ this._degree = new coefficients_1.Fraction(degree === undefined ? 1 : degree);
3321
+ this._fn = mathFunction;
3322
+ this._powerAsInteger = true;
3323
+ this._forceParenthesis = true;
3324
+ }
3325
+ _forceParenthesis;
3326
+ get forceParenthesis() {
3327
+ return this._forceParenthesis;
3328
+ }
3329
+ set forceParenthesis(value) {
3330
+ this._forceParenthesis = value;
3331
+ }
3332
+ _fn;
3333
+ get fn() {
3334
+ return this._fn;
3335
+ }
3336
+ set fn(value) {
3337
+ this._fn = value;
3338
+ }
3339
+ _powerAsInteger;
3340
+ get powerAsInteger() {
3341
+ return this._powerAsInteger;
3342
+ }
3343
+ set powerAsInteger(value) {
3344
+ this._powerAsInteger = value;
3345
+ }
3346
+ _polynom;
3347
+ get polynom() {
3348
+ return this._polynom;
3349
+ }
3350
+ set polynom(value) {
3351
+ this._polynom = value;
3352
+ }
3353
+ _degree;
3354
+ get degree() {
3355
+ return this._degree;
3356
+ }
3357
+ set degree(value) {
3358
+ this._degree = value;
3359
+ }
3360
+ get tex() {
3361
+ let tex;
3362
+ if (this._degree.isOne() && (this._fn !== undefined || !this._forceParenthesis)) {
3363
+ tex = this._polynom.tex;
3364
+ }
3365
+ else {
3366
+ if (this._powerAsInteger && !this._degree.isRelative()) {
3367
+ tex = `\\sqrt${this._degree.denominator !== 2 ? `[ ${this._degree.denominator} ]` : ''}{ ${this._polynom.tex} }^{ ${this._degree.numerator} }`;
3368
+ }
3369
+ else if (this.isCoefficient && this.firstCoefficient.isNatural()) {
3370
+ tex = this._polynom.tex + this._texDegree;
3371
+ }
3372
+ else {
3373
+ tex = `\\left( ${this._polynom.tex} \\right)${this._texDegree}`;
3374
+ }
2966
3375
  }
3376
+ if (this._fn !== undefined && this._fn.tex !== undefined) {
3377
+ tex = `${this._fn.tex}\\left( ${tex} \\right)`;
3378
+ }
3379
+ return tex;
2967
3380
  }
2968
- get radical() {
2969
- return this._radical;
3381
+ get isCoefficient() {
3382
+ return this._polynom.degree().isZero();
2970
3383
  }
2971
- set radical(value) {
2972
- this._radical = value;
3384
+ get firstCoefficient() {
3385
+ return this._polynom.monomByDegree().coefficient;
2973
3386
  }
2974
- get nth() {
2975
- return this._nth;
3387
+ get _texDegree() {
3388
+ if (this._degree.isOne()) {
3389
+ return '';
3390
+ }
3391
+ else {
3392
+ return `^{ ${this._degree.tfrac} }`;
3393
+ }
2976
3394
  }
2977
- set nth(value) {
2978
- if (Number.isSafeInteger(value) && value >= 2) {
2979
- this._nth = value;
3395
+ setForceParenthesis(value) {
3396
+ this._forceParenthesis = value === undefined || value;
3397
+ return this;
3398
+ }
3399
+ derivative(letter) {
3400
+ if (this._degree.isOne()) {
3401
+ return new PolynomExpProduct(new PolynomExpFactor(this._polynom.clone().derivative(letter)));
2980
3402
  }
2981
3403
  else {
2982
- console.log('Error setting the nth root');
2983
- this._nth = 2;
3404
+ return new PolynomExpProduct(new PolynomExpFactor(this._degree.clone()), new PolynomExpFactor(this._polynom.clone().derivative(letter)), new PolynomExpFactor(this._polynom.clone(), this._degree.clone().subtract(1)));
2984
3405
  }
2985
3406
  }
2986
- get coefficient() {
2987
- return this._coefficient;
3407
+ }
3408
+ exports.PolynomExpFactor = PolynomExpFactor;
3409
+ class PolynomExpProduct {
3410
+ constructor(...values) {
3411
+ this._factors = values || [];
3412
+ this._positive = true;
3413
+ this._asPositiveDegree = true;
2988
3414
  }
2989
- set coefficient(value) {
2990
- this._coefficient = value;
3415
+ _fn;
3416
+ get fn() {
3417
+ return this._fn;
3418
+ }
3419
+ set fn(value) {
3420
+ this._fn = value;
3421
+ }
3422
+ _factors;
3423
+ get factors() {
3424
+ return this._factors;
3425
+ }
3426
+ set factors(value) {
3427
+ this._factors = value;
3428
+ }
3429
+ _positive;
3430
+ get positive() {
3431
+ return this._positive;
3432
+ }
3433
+ set positive(value) {
3434
+ this._positive = value;
3435
+ }
3436
+ _asPositiveDegree;
3437
+ get asPositiveDegree() {
3438
+ return this._asPositiveDegree;
3439
+ }
3440
+ set asPositiveDegree(value) {
3441
+ this._asPositiveDegree = value;
2991
3442
  }
2992
3443
  get tex() {
2993
- let C;
2994
- if (this._coefficient === 1) {
2995
- C = '';
3444
+ let parenthesis = this._factors.length > 1;
3445
+ let tex = this._factors.map(factor => factor.setForceParenthesis(parenthesis).tex).join(' \\cdot ');
3446
+ if (this._asPositiveDegree) {
3447
+ const numerators = this._factors.filter(x => x.degree.isPositive()), denominators = this._factors.filter(x => x.degree.isNegative());
3448
+ let numeratorsAsTex, denominatorsAsTex;
3449
+ if (denominators.length > 0) {
3450
+ if (numerators.length === 0) {
3451
+ numeratorsAsTex = [1];
3452
+ }
3453
+ else if (numerators.length === 1) {
3454
+ numeratorsAsTex = [numerators[0].setForceParenthesis(false).tex];
3455
+ }
3456
+ else {
3457
+ parenthesis = numerators.length > 1;
3458
+ numeratorsAsTex = numerators.map(factor => factor.setForceParenthesis(parenthesis).tex);
3459
+ }
3460
+ denominators.map(x => x.degree.opposed());
3461
+ if (denominators.length === 1) {
3462
+ denominatorsAsTex = [denominators[0].setForceParenthesis(false).tex];
3463
+ }
3464
+ else {
3465
+ parenthesis = denominators.length > 1;
3466
+ denominatorsAsTex = denominators.map(factor => factor.setForceParenthesis(parenthesis).tex);
3467
+ }
3468
+ denominators.map(x => x.degree.opposed());
3469
+ tex = `\\dfrac{ ${numeratorsAsTex.join(' \\cdot ')} }{ ${denominatorsAsTex.join(' \\cdot ')} }`;
3470
+ }
2996
3471
  }
2997
- else if (this._coefficient === -1) {
2998
- C = '-';
3472
+ if (this._fn !== undefined && this._fn.name !== undefined && this._fn.name !== '') {
3473
+ tex = `${this._fn.tex}\\left( ${tex} \\right)`;
2999
3474
  }
3000
- else {
3001
- C = this._coefficient.toString();
3475
+ return tex;
3476
+ }
3477
+ reduce() {
3478
+ let coefficients = this._factors.filter(factor => factor.isCoefficient), polynoms = this._factors.filter(factor => !factor.isCoefficient);
3479
+ let result = new coefficients_1.Fraction().one();
3480
+ if (coefficients.length > 1) {
3481
+ for (const factor of coefficients) {
3482
+ if (factor.degree.isPositive()) {
3483
+ result.multiply(factor.polynom.monoms[0].coefficient.pow(factor.degree));
3484
+ }
3485
+ else {
3486
+ result.divide(factor.polynom.monoms[0].coefficient.pow(factor.degree.clone().abs()));
3487
+ }
3488
+ }
3002
3489
  }
3003
- if (this._radical === 1) {
3004
- return `${this._coefficient}`;
3490
+ else if (coefficients.length === 1) {
3491
+ result = coefficients[0].polynom.monoms[0].coefficient;
3492
+ }
3493
+ if (result.isOne()) {
3494
+ this._factors = [...polynoms];
3495
+ }
3496
+ else if (!result.isRelative()) {
3497
+ this._factors = [
3498
+ new PolynomExpFactor(result.numerator),
3499
+ new PolynomExpFactor(result.denominator, -1),
3500
+ ...polynoms
3501
+ ];
3005
3502
  }
3006
3503
  else {
3007
- if (this._nth === 2) {
3008
- return `${C}\\sqrt{${this._radical}}`;
3504
+ this._factors = [
3505
+ new PolynomExpFactor(result),
3506
+ ...polynoms
3507
+ ];
3508
+ }
3509
+ return this;
3510
+ }
3511
+ integrate(letter) {
3512
+ if (this._factors.length === 2) {
3513
+ let d1 = this._factors[0].polynom.degree(letter).value, d2 = this._factors[1].polynom.degree(letter).value;
3514
+ if (d1 === d2 + 1) {
3515
+ return this._integrateWithInternalDerivative(this._factors[0], this._factors[1], letter);
3009
3516
  }
3010
- else {
3011
- return `${C}\\sqrt[${this._nth}]{${this._radical}}`;
3517
+ else if (d1 + 1 === d2) {
3518
+ return this._integrateWithInternalDerivative(this._factors[1], this._factors[0], letter);
3012
3519
  }
3013
3520
  }
3521
+ return;
3014
3522
  }
3015
- get value() {
3016
- return this._coefficient * Math.pow(this._radical, 1 / this._nth);
3017
- }
3018
- parse = (radical, nthroot, coefficient) => {
3019
- this._coefficient = (coefficient === undefined) ? 1 : coefficient;
3020
- this._nth = (nthroot === undefined) ? 2 : nthroot;
3021
- this._radical = (radical === undefined) ? 1 : radical;
3022
- if (this._nth % 2 === 0 && this._radical < 0) {
3023
- this._isValid = false;
3024
- }
3523
+ applyMathFunction(mathFn) {
3524
+ this._fn = mathFn;
3025
3525
  return this;
3026
- };
3027
- reduce = () => {
3028
- let V = Math.floor(Math.pow(this._radical, 1 / this._nth));
3029
- while (V > 1) {
3030
- if (this._radical % Math.pow(V, this._nth) === 0) {
3031
- this._coefficient *= V;
3032
- this._radical = this._radical / Math.pow(V, this._nth);
3033
- V = Math.floor(Math.pow(this._radical, 1 / this._nth));
3034
- continue;
3526
+ }
3527
+ _integrateWithInternalDerivative(P, Pinternal, letter) {
3528
+ let internalDerivative = P.polynom.clone().derivative(letter);
3529
+ let { quotient, reminder } = Pinternal.polynom.clone().euclidian(internalDerivative);
3530
+ if (reminder.isZero() && quotient.degree(letter).isZero()) {
3531
+ if (P.degree.isEqual(-1)) {
3532
+ return (new PolynomExpProduct(new PolynomExpFactor(quotient, 1), new PolynomExpFactor(P.polynom.clone(), 1, {
3533
+ name: 'ln', tex: '\\ln', fn: (x) => Math.log(x)
3534
+ })));
3535
+ }
3536
+ else {
3537
+ return new PolynomExpProduct(new PolynomExpFactor(P.degree.clone().add(1).invert(), 1), new PolynomExpFactor(quotient, 1), new PolynomExpFactor(P.polynom.clone(), P.degree.clone().add(1)));
3035
3538
  }
3036
- V--;
3037
3539
  }
3038
- return this;
3039
- };
3040
- multiply = (N) => {
3041
- this._radical *= N.radical;
3042
- return this.reduce();
3043
- };
3044
- hasRadical = () => {
3045
- return !(this._radical === 1 || this._radical === 0 || this._isValid === false);
3046
- };
3540
+ return;
3541
+ }
3047
3542
  }
3048
- exports.Nthroot = Nthroot;
3543
+ exports.PolynomExpProduct = PolynomExpProduct;
3049
3544
 
3050
3545
 
3051
3546
  /***/ }),
@@ -3312,8 +3807,9 @@ const numeric_1 = __webpack_require__(/*! ../numeric */ "./src/maths/numeric.ts"
3312
3807
  var LinePropriety;
3313
3808
  (function (LinePropriety) {
3314
3809
  LinePropriety[LinePropriety["None"] = 0] = "None";
3315
- LinePropriety[LinePropriety["Parallel"] = 1] = "Parallel";
3316
- LinePropriety[LinePropriety["Perpendicular"] = 2] = "Perpendicular";
3810
+ LinePropriety["Parallel"] = "parallel";
3811
+ LinePropriety["Perpendicular"] = "perpendicular";
3812
+ LinePropriety["Tangent"] = "tangent";
3317
3813
  })(LinePropriety || (LinePropriety = {}));
3318
3814
  class Line {
3319
3815
  _a;
@@ -4242,134 +4738,6 @@ class Numeric {
4242
4738
  exports.Numeric = Numeric;
4243
4739
 
4244
4740
 
4245
- /***/ }),
4246
-
4247
- /***/ "./src/maths/numexp.ts":
4248
- /*!*****************************!*\
4249
- !*** ./src/maths/numexp.ts ***!
4250
- \*****************************/
4251
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
4252
-
4253
-
4254
- Object.defineProperty(exports, "__esModule", ({ value: true }));
4255
- exports.NumExp = void 0;
4256
- const shutingyard_1 = __webpack_require__(/*! ./shutingyard */ "./src/maths/shutingyard.ts");
4257
- const coefficients_1 = __webpack_require__(/*! ./coefficients */ "./src/maths/coefficients/index.ts");
4258
- class NumExp {
4259
- _rpn;
4260
- _expression;
4261
- constructor(value) {
4262
- this._expression = value;
4263
- this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
4264
- }
4265
- get rpn() {
4266
- return this._rpn;
4267
- }
4268
- get expression() {
4269
- return this._expression;
4270
- }
4271
- _extractDecimalPart(value) {
4272
- let decimal = value.toString();
4273
- if (!decimal.includes('.')) {
4274
- return '';
4275
- }
4276
- decimal = decimal.split('.')[1];
4277
- return decimal.substring(0, decimal.length - 2);
4278
- }
4279
- _numberCorrection(value) {
4280
- const epsilon = 0.00000000000001, number_of_digits = 6;
4281
- let decimal = this._extractDecimalPart(value);
4282
- if (decimal === '') {
4283
- return value;
4284
- }
4285
- const n9 = decimal.match(/9+$/g);
4286
- const n0 = decimal.match(/0+$/g);
4287
- if (n9 && n9[0].length >= number_of_digits) {
4288
- let mod = this._extractDecimalPart(value + epsilon), mod0 = mod.match(/0+$/g);
4289
- if (mod0 && mod0[0].length >= number_of_digits) {
4290
- return +((value + epsilon).toString().split(mod0[0])[0]);
4291
- }
4292
- }
4293
- if (n0 && n0[0].length >= number_of_digits) {
4294
- let mod = this._extractDecimalPart(value - epsilon), mod9 = mod.match(/9+$/g);
4295
- if (mod9 && mod9[0].length >= number_of_digits) {
4296
- return +(value.toString().split(n0[0])[0]);
4297
- }
4298
- }
4299
- return value;
4300
- }
4301
- _addToStack(stack, value) {
4302
- stack.push(this._numberCorrection(value));
4303
- }
4304
- evaluate(values) {
4305
- let stack = [];
4306
- for (const element of this._rpn) {
4307
- if (element.tokenType === shutingyard_1.ShutingyardType.COEFFICIENT) {
4308
- if (!isNaN(+element.token)) {
4309
- this._addToStack(stack, +element.token);
4310
- }
4311
- else {
4312
- this._addToStack(stack, new coefficients_1.Fraction(element.token).value);
4313
- }
4314
- }
4315
- else if (element.tokenType === shutingyard_1.ShutingyardType.VARIABLE) {
4316
- if (values[element.token] !== undefined) {
4317
- this._addToStack(stack, +values[element.token]);
4318
- }
4319
- }
4320
- else if (element.tokenType === shutingyard_1.ShutingyardType.CONSTANT) {
4321
- this._addToStack(stack, shutingyard_1.tokenConstant[element.token]);
4322
- }
4323
- else if (element.tokenType === shutingyard_1.ShutingyardType.OPERATION) {
4324
- if (element.token === '*') {
4325
- const b = +stack.pop(), a = +stack.pop();
4326
- this._addToStack(stack, a * b);
4327
- }
4328
- else if (element.token === '/') {
4329
- const b = +stack.pop(), a = +stack.pop();
4330
- this._addToStack(stack, a / b);
4331
- }
4332
- else if (element.token === '+') {
4333
- const b = +stack.pop(), a = +stack.pop();
4334
- this._addToStack(stack, a + b);
4335
- }
4336
- else if (element.token === '-') {
4337
- const b = +stack.pop(), a = +stack.pop();
4338
- this._addToStack(stack, a - b);
4339
- }
4340
- else if (element.token === '^') {
4341
- const b = +stack.pop(), a = +stack.pop();
4342
- this._addToStack(stack, Math.pow(a, b));
4343
- }
4344
- }
4345
- else if (element.tokenType === shutingyard_1.ShutingyardType.FUNCTION) {
4346
- const a = +stack.pop();
4347
- if (element.token === 'sin') {
4348
- this._addToStack(stack, Math.sin(a));
4349
- }
4350
- else if (element.token === 'cos') {
4351
- this._addToStack(stack, Math.cos(a));
4352
- }
4353
- else if (element.token === 'tan') {
4354
- this._addToStack(stack, Math.tan(a));
4355
- }
4356
- else if (element.token === 'sqrt') {
4357
- this._addToStack(stack, Math.sqrt(a));
4358
- }
4359
- }
4360
- }
4361
- if (stack.length === 1) {
4362
- return stack[0];
4363
- }
4364
- else {
4365
- console.error('There was a problem parsing', this._expression, '. The RPN array is', this._rpn);
4366
- return 0;
4367
- }
4368
- }
4369
- }
4370
- exports.NumExp = NumExp;
4371
-
4372
-
4373
4741
  /***/ }),
4374
4742
 
4375
4743
  /***/ "./src/maths/random/index.ts":
@@ -4784,10 +5152,6 @@ class Shutingyard {
4784
5152
  '/': { precedence: 3, associative: 'left', type: ShutingyardType.OPERATION },
4785
5153
  '+': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
4786
5154
  '-': { precedence: 2, associative: 'left', type: ShutingyardType.OPERATION },
4787
- '%': { precedence: 3, associative: 'right', type: ShutingyardType.OPERATION },
4788
- 'sin': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4789
- 'cos': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4790
- 'tan': { precedence: 4, associative: 'right', type: ShutingyardType.FUNCTION },
4791
5155
  };
4792
5156
  this._uniformize = true;
4793
5157
  }
@@ -4827,9 +5191,7 @@ class Shutingyard {
4827
5191
  }
4828
5192
  if (token === '') {
4829
5193
  if (expr[start].match(/[0-9]/)) {
4830
- if (this._mode === ShutingyardMode.POLYNOM) {
4831
- token = expr.substring(start).match(/^([0-9.,/]+)/)[0];
4832
- }
5194
+ if (this._mode === ShutingyardMode.POLYNOM && false) {}
4833
5195
  else {
4834
5196
  token = expr.substring(start).match(/^([0-9.,]+)/)[0];
4835
5197
  }
@@ -4993,7 +5355,7 @@ var exports = __webpack_exports__;
4993
5355
 
4994
5356
  Object.defineProperty(exports, "__esModule", ({ value: true }));
4995
5357
  const numeric_1 = __webpack_require__(/*! ./maths/numeric */ "./src/maths/numeric.ts");
4996
- const numexp_1 = __webpack_require__(/*! ./maths/numexp */ "./src/maths/numexp.ts");
5358
+ const numexp_1 = __webpack_require__(/*! ./maths/expressions/numexp */ "./src/maths/expressions/numexp.ts");
4997
5359
  const shutingyard_1 = __webpack_require__(/*! ./maths/shutingyard */ "./src/maths/shutingyard.ts");
4998
5360
  const random_1 = __webpack_require__(/*! ./maths/random */ "./src/maths/random/index.ts");
4999
5361
  const coefficients_1 = __webpack_require__(/*! ./maths/coefficients */ "./src/maths/coefficients/index.ts");
@@ -5012,6 +5374,8 @@ window.Pi = {
5012
5374
  Rational: algebra_1.Rational,
5013
5375
  Logicalset: algebra_1.Logicalset,
5014
5376
  Random: random_1.Random,
5377
+ PolynomExpFactor: algebra_1.PolynomExpFactor,
5378
+ PolynomExpProduct: algebra_1.PolynomExpProduct,
5015
5379
  Geometry: {
5016
5380
  Vector: geometry_1.Vector,
5017
5381
  Point: geometry_1.Point,