pimath 0.2.10 → 0.2.11

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/pimath.js CHANGED
@@ -1816,7 +1816,7 @@ var v = class e {
1816
1816
  #e;
1817
1817
  #t;
1818
1818
  constructor(e) {
1819
- e instanceof M || e instanceof A ? this.#e = new M(e) : this.#e = new M().fromPolynom(e), this.#t = this.#e.getRoots();
1819
+ this.#e = e instanceof M || e instanceof A ? new M(e) : new M().fromPolynom(e), this.#t = this.#e.getRoots();
1820
1820
  }
1821
1821
  get fx() {
1822
1822
  return this.#e;
@@ -1983,7 +1983,11 @@ var v = class e {
1983
1983
  }, x = {
1984
1984
  pi: Math.PI,
1985
1985
  e: Math.exp(1)
1986
- }, S = /* @__PURE__ */ ((e) => (e.VARIABLE = "variable", e.COEFFICIENT = "coefficient", e.OPERATION = "operation", e.CONSTANT = "constant", e.FUNCTION = "function", e.FUNCTION_ARGUMENT = "function-argument", e.MONOM = "monom", e.LEFT_PARENTHESIS = "(", e.RIGHT_PARENTHESIS = ")", e))(S || {}), C = /* @__PURE__ */ ((e) => (e.EXPRESSION = "expression", e.POLYNOM = "polynom", e.SET = "set", e.NUMERIC = "numeric", e))(C || {});
1986
+ }, S = /* @__PURE__ */ function(e) {
1987
+ return e.VARIABLE = "variable", e.COEFFICIENT = "coefficient", e.OPERATION = "operation", e.CONSTANT = "constant", e.FUNCTION = "function", e.FUNCTION_ARGUMENT = "function-argument", e.MONOM = "monom", e.LEFT_PARENTHESIS = "(", e.RIGHT_PARENTHESIS = ")", e;
1988
+ }({}), C = /* @__PURE__ */ function(e) {
1989
+ return e.EXPRESSION = "expression", e.POLYNOM = "polynom", e.SET = "set", e.NUMERIC = "numeric", e;
1990
+ }({});
1987
1991
  function te(e, t) {
1988
1992
  if (e.length <= 1) return e;
1989
1993
  let n = Object.keys(t).filter((e) => t[e].type === S.FUNCTION).map((e) => e);
@@ -2115,6 +2119,11 @@ var re = {
2115
2119
  associative: "right",
2116
2120
  type: S.FUNCTION
2117
2121
  },
2122
+ logn: {
2123
+ precedence: 4,
2124
+ associative: "right",
2125
+ type: S.FUNCTION
2126
+ },
2118
2127
  ",": {
2119
2128
  precedence: 2,
2120
2129
  associative: "left",
@@ -2181,6 +2190,11 @@ var re = {
2181
2190
  associative: "right",
2182
2191
  type: S.FUNCTION
2183
2192
  },
2193
+ logn: {
2194
+ precedence: 4,
2195
+ associative: "right",
2196
+ type: S.FUNCTION
2197
+ },
2184
2198
  log: {
2185
2199
  precedence: 4,
2186
2200
  associative: "right",
@@ -2214,7 +2228,7 @@ var re = {
2214
2228
  #r = [];
2215
2229
  #i;
2216
2230
  constructor(e) {
2217
- this.#e = typeof e > "u" ? C.POLYNOM : e, this.tokenConfigInitialization();
2231
+ this.#e = e === void 0 ? C.POLYNOM : e, this.tokenConfigInitialization();
2218
2232
  }
2219
2233
  get rpn() {
2220
2234
  return this.#t;
@@ -2347,7 +2361,7 @@ var re = {
2347
2361
  try {
2348
2362
  this._rpn = new w(C.NUMERIC).parse(e, t).rpn;
2349
2363
  } catch (t) {
2350
- throw this._rpn = null, this._isValid = !1, console.warn(t), /* @__PURE__ */ Error(`There was a problem parsing: ${e}`);
2364
+ throw this._rpn = null, this._isValid = !1, console.warn(t), Error(`There was a problem parsing: ${e}`);
2351
2365
  }
2352
2366
  }
2353
2367
  get rpn() {
@@ -2356,8 +2370,8 @@ var re = {
2356
2370
  get isValid() {
2357
2371
  if (this._isValid === void 0) try {
2358
2372
  this.evaluate({ x: 2 });
2359
- } catch {
2360
- this._isValid = !1;
2373
+ } catch (e) {
2374
+ e instanceof Error, this._isValid = !1;
2361
2375
  }
2362
2376
  return this._isValid ?? !1;
2363
2377
  }
@@ -2374,7 +2388,7 @@ var re = {
2374
2388
  for (let n of this._rpn) if (n.tokenType === S.COEFFICIENT) if (!isNaN(+n.token)) t.push(+n.token);
2375
2389
  else {
2376
2390
  let e = n.token.split("/");
2377
- if (e.length !== 2) throw this._isValid = !1, /* @__PURE__ */ Error("This coefficient is not a fraction");
2391
+ if (e.length !== 2) throw this._isValid = !1, Error("This coefficient is not a fraction");
2378
2392
  t.push(e[0] / +e[1]);
2379
2393
  }
2380
2394
  else if (n.tokenType === S.VARIABLE && e !== void 0) Object.hasOwn(e, n.token) && t.push(+e[n.token]);
@@ -2382,37 +2396,43 @@ var re = {
2382
2396
  else if (n.tokenType === S.OPERATION) {
2383
2397
  if (n.token === "*") {
2384
2398
  let e = t.pop(), n = t.pop();
2385
- if (n === void 0 || e === void 0) throw this._isValid = !1, /* @__PURE__ */ Error(`The multiplication factors ${n ?? "a"} or ${e ?? "b"} are not defined`);
2399
+ if (n === void 0 || e === void 0) throw this._isValid = !1, Error(`The multiplication factors ${n ?? "a"} or ${e ?? "b"} are not defined`);
2386
2400
  t.push(n * e);
2387
2401
  } else if (n.token === "/") {
2388
2402
  let e = t.pop(), n = t.pop();
2389
- if (n === void 0 || e === void 0) throw this._isValid = !1, /* @__PURE__ */ Error(`The division values ${n ?? "a"} or ${e ?? "b"} are not defined`);
2403
+ if (n === void 0 || e === void 0) throw this._isValid = !1, Error(`The division values ${n ?? "a"} or ${e ?? "b"} are not defined`);
2390
2404
  t.push(n / e);
2391
2405
  } else if (n.token === "+") {
2392
2406
  let e = t.pop(), n = t.pop();
2393
- if (n === void 0 || e === void 0) throw this._isValid = !1, /* @__PURE__ */ Error(`The addition values ${n ?? "a"} or ${e ?? "b"} are not defined`);
2407
+ if (n === void 0 || e === void 0) throw this._isValid = !1, Error(`The addition values ${n ?? "a"} or ${e ?? "b"} are not defined`);
2394
2408
  t.push(+n + +e);
2395
2409
  } else if (n.token === "-") {
2396
2410
  let e = t.pop(), n = t.pop() ?? 0;
2397
- if (e === void 0) throw this._isValid = !1, /* @__PURE__ */ Error("The subtraction value b is not defined");
2411
+ if (e === void 0) throw this._isValid = !1, Error("The subtraction value b is not defined");
2398
2412
  t.push(n - e);
2399
2413
  } else if (n.token === "^") {
2400
2414
  let e = t.pop(), n = t.pop();
2401
- if (n === void 0 || e === void 0) throw this._isValid = !1, /* @__PURE__ */ Error(`The base value ${n ?? "a"} or exponent ${e ?? "b"} are not defined`);
2415
+ if (n === void 0 || e === void 0) throw this._isValid = !1, Error(`The base value ${n ?? "a"} or exponent ${e ?? "b"} are not defined`);
2402
2416
  t.push(n ** +e);
2403
2417
  }
2404
2418
  } else if (n.tokenType === S.FUNCTION) {
2405
2419
  let e = t.pop();
2406
- if (e === void 0) throw this._isValid = !1, /* @__PURE__ */ Error(`The parameters for ${n.token} is not defined`);
2420
+ if (e === void 0) throw this._isValid = !1, Error(`The parameters for ${n.token} is not defined`);
2407
2421
  if (n.token === "sin") t.push(Math.sin(e));
2408
2422
  else if (n.token === "cos") t.push(Math.cos(e));
2409
2423
  else if (n.token === "tan") t.push(Math.tan(e));
2410
2424
  else if (n.token === "sqrt") t.push(Math.sqrt(e));
2411
2425
  else if (n.token === "nthrt") {
2412
2426
  let n = t.pop();
2413
- if (n === void 0) throw this._isValid = !1, /* @__PURE__ */ Error("The nthrt function requires two parameters");
2427
+ if (n === void 0) throw this._isValid = !1, Error("The nthrt function requires two parameters");
2414
2428
  e % 2 == 0 && n < 0 ? t.push(NaN) : t.push((n < 0 ? -1 : 1) * Math.abs(n) ** (1 / e));
2415
- } else n.token === "ln" ? t.push(Math.log(e)) : n.token === "log" && t.push(Math.log10(e));
2429
+ } else if (n.token === "ln") t.push(Math.log(e));
2430
+ else if (n.token === "log") t.push(Math.log10(e));
2431
+ else if (n.token === "logn") {
2432
+ let n = t.pop();
2433
+ if (n === void 0) throw this._isValid = !1, Error("The logn function requires two parameters");
2434
+ e <= 0 || e === 1 || n <= 0 ? t.push(NaN) : t.push(Math.log(n) / Math.log(e));
2435
+ }
2416
2436
  }
2417
2437
  if (t.length === 1) return this._numberCorrection(t[0]);
2418
2438
  throw Error(`There was a problem parsing: ${this._expression}`);
@@ -2476,7 +2496,8 @@ var re = {
2476
2496
  if (this.hasVariable(t)) {
2477
2497
  let e = this.#t[t].clone(), n = this.clone();
2478
2498
  return n.#t[t].subtract(1), n.#e.multiply(new p(e.clone())), n;
2479
- } else return new e().zero();
2499
+ }
2500
+ return new e().zero();
2480
2501
  };
2481
2502
  divide = (...t) => {
2482
2503
  for (let n of t) {
@@ -2684,9 +2705,7 @@ var re = {
2684
2705
  case "/":
2685
2706
  i = t.pop() ?? new e().one(), r = t.pop() ?? new e().one(), t.push(r.divide(i));
2686
2707
  break;
2687
- case "^":
2688
- s = t.pop()?.coefficient ?? new p().one(), a = t.pop() ?? new e().one(), o = a.variables[0], o && a.setLetter(o, s), t.push(a);
2689
- break;
2708
+ case "^": s = t.pop()?.coefficient ?? new p().one(), a = t.pop() ?? new e().one(), o = a.variables[0], o && a.setLetter(o, s), t.push(a);
2690
2709
  }
2691
2710
  };
2692
2711
  #s = (e) => {
@@ -2695,7 +2714,8 @@ var re = {
2695
2714
  if (t.length === 1) {
2696
2715
  let e = t[0];
2697
2716
  return this.one(), e.tokenType === S.COEFFICIENT ? this.coefficient = new p(e.token) : e.tokenType === S.VARIABLE && this.setLetter(e.token, 1), this;
2698
- } else for (let e of t) this.#o(n, e);
2717
+ }
2718
+ for (let e of t) this.#o(n, e);
2699
2719
  return this.one(), this.multiply(n[0]), this;
2700
2720
  };
2701
2721
  };
@@ -2881,7 +2901,8 @@ var O = class e {
2881
2901
  if (e.degree().isOne()) {
2882
2902
  let t = e.getZeroes()[0];
2883
2903
  return t.exact ? this.evaluate(t.fraction).isZero() : !1;
2884
- } else {
2904
+ }
2905
+ {
2885
2906
  let { reminder: t } = this.euclidean(e);
2886
2907
  return t.isZero();
2887
2908
  }
@@ -3117,7 +3138,8 @@ var O = class e {
3117
3138
  return this.add(t), this;
3118
3139
  }
3119
3140
  return this.#_(e);
3120
- } else if (/^[a-z]+$/.test(e)) {
3141
+ }
3142
+ if (/^[a-z]+$/.test(e)) {
3121
3143
  this.empty();
3122
3144
  let n = t.map((e) => new p(e));
3123
3145
  if (e.length > 1) {
@@ -3136,7 +3158,8 @@ var O = class e {
3136
3158
  }
3137
3159
  }
3138
3160
  return this;
3139
- } else return this.zero();
3161
+ }
3162
+ return this.zero();
3140
3163
  }
3141
3164
  #g(t, n) {
3142
3165
  switch (n.tokenType) {
@@ -3209,7 +3232,7 @@ var O = class e {
3209
3232
  return e.includes("=") || e.includes("<") || e.includes(">") || e.includes("<=") || e.includes(">=");
3210
3233
  }
3211
3234
  static makeSolutionsUnique(e, t) {
3212
- let n = [], r = e.filter((e) => n.includes(e.tex) ? !1 : (n.push(e.tex), !0));
3235
+ let n = [], r = e.filter((e) => !n.includes(e.tex) && (n.push(e.tex), !0));
3213
3236
  return t === !0 && r.sort((e, t) => e.value - t.value), r;
3214
3237
  }
3215
3238
  add(t) {
@@ -3689,15 +3712,13 @@ var O = class e {
3689
3712
  }));
3690
3713
  }
3691
3714
  break;
3692
- case "!":
3693
- if (e.length >= 1) {
3694
- let t = e.pop();
3695
- t && e.push({
3696
- token: `\\overline{ ${t.token} }`,
3697
- tokenType: "variable"
3698
- });
3699
- }
3700
- break;
3715
+ case "!": if (e.length >= 1) {
3716
+ let t = e.pop();
3717
+ t && e.push({
3718
+ token: `\\overline{ ${t.token} }`,
3719
+ tokenType: "variable"
3720
+ });
3721
+ }
3701
3722
  }
3702
3723
  return e[0].token;
3703
3724
  }
@@ -3800,12 +3821,10 @@ var O = class e {
3800
3821
  t && e && n.push(new Set([...t].filter((t) => !e.has(t))));
3801
3822
  }
3802
3823
  break;
3803
- case "!":
3804
- if (n.length >= 1) {
3805
- let e = n.pop();
3806
- e && n.push(new Set([...r].filter((t) => !e.has(t))));
3807
- }
3808
- break;
3824
+ case "!": if (n.length >= 1) {
3825
+ let e = n.pop();
3826
+ e && n.push(new Set([...r].filter((t) => !e.has(t))));
3827
+ }
3809
3828
  }
3810
3829
  return [...n[0]].sort();
3811
3830
  }
@@ -3817,6 +3836,7 @@ var O = class e {
3817
3836
  }
3818
3837
  parse(...t) {
3819
3838
  return this.#t = [], t.length === 0 || t.forEach((t) => {
3839
+ if (typeof t == "string") return this.fromString(t);
3820
3840
  t instanceof e ? this.#t.push(...t.factors.map((e) => e.clone())) : this.#t.push(new A(t));
3821
3841
  }), this;
3822
3842
  }
@@ -3937,7 +3957,7 @@ var O = class e {
3937
3957
  let [t, ...n] = _(e, "/");
3938
3958
  if (t === "") throw Error("Parsing a PolyFactor from a string requires a numerator");
3939
3959
  if (n.length > 1) throw Error("Parsing a PolyFactor from a string only allows max one signe \"/\"");
3940
- return n.length === 0 ? this.#t = A.factorsFromString(h(t), !0) : this.#t = [...A.factorsFromString(h(t), !0), ...A.factorsFromString(h(n[0]), !1)], this;
3960
+ return this.#t = n.length === 0 ? A.factorsFromString(h(t), !0) : [...A.factorsFromString(h(t), !0), ...A.factorsFromString(h(n[0]), !1)], this;
3941
3961
  }
3942
3962
  getRoots() {
3943
3963
  return [];
@@ -3962,9 +3982,10 @@ var O = class e {
3962
3982
  isZero() {
3963
3983
  return this.#t.every((e) => e.isZero());
3964
3984
  }
3965
- multiply(...e) {
3966
- return e.forEach((e) => {
3967
- this.#t = this.#t.concat(e.clone().factors);
3985
+ multiply(...t) {
3986
+ return t.forEach((t) => {
3987
+ let n = new e(t);
3988
+ this.#t = this.#t.concat(n.factors);
3968
3989
  }), this;
3969
3990
  }
3970
3991
  get numerator() {
@@ -4038,9 +4059,7 @@ var O = class e {
4038
4059
  case "h":
4039
4060
  e[n] = "h";
4040
4061
  break;
4041
- case "-":
4042
- e[n] = e[n] === "h" ? "h" : e[n] === "-" ? "+" : "-";
4043
- break;
4062
+ case "-": e[n] = e[n] === "h" ? "h" : e[n] === "-" ? "+" : "-";
4044
4063
  }
4045
4064
  }), e), []),
4046
4065
  roots: e,
@@ -5075,7 +5094,7 @@ var G = class e {
5075
5094
  return this.#e = e.clone(), this.#r = new L(this.#e, t).normSquare, this.#i(), this;
5076
5095
  }
5077
5096
  fromCenterRadius(e, t, n) {
5078
- return this.#e = e.clone(), n ? this.#r = new p(t) : this.#r = new p(t).pow(2), this.#i(), this;
5097
+ return this.#e = e.clone(), this.#r = n ? new p(t) : new p(t).pow(2), this.#i(), this;
5079
5098
  }
5080
5099
  fromEquation(e) {
5081
5100
  if (e.moveLeft(), e.degree("x").value === 2 && e.degree("y").value === 2) {
@@ -5135,7 +5154,7 @@ var G = class e {
5135
5154
  return t - n > 1e-10 ? 0 : Math.abs(t - n) < 1e-10 ? 1 : 2;
5136
5155
  }
5137
5156
  setRadius(e, t) {
5138
- return t ? this.#r = new p(e) : this.#r = new p(e).pow(2), this.#i(), this;
5157
+ return this.#r = t ? new p(e) : new p(e).pow(2), this.#i(), this;
5139
5158
  }
5140
5159
  get squareRadius() {
5141
5160
  return this.#r?.clone() ?? new p(-1);
@@ -5262,7 +5281,7 @@ var G = class e {
5262
5281
  }
5263
5282
  if (e.equation) {
5264
5283
  let t = e.equation.moveLeft().reduce().left, n = t.monomByLetter("x").coefficient, r = t.monomByLetter("y").coefficient, i = t.monomByLetter("z").coefficient, a = t.monomByDegree(0).coefficient;
5265
- this.normal = new L(n, r, i), n.isNotZero() ? this.point = new I(a.clone().divide(n).opposite(), 0, 0) : r.isNotZero() ? this.point = new I(0, a.clone().divide(r).opposite(), 0) : this.point = new I(0, 0, a.clone().divide(i).opposite());
5284
+ this.normal = new L(n, r, i), this.point = n.isNotZero() ? new I(a.clone().divide(n).opposite(), 0, 0) : r.isNotZero() ? new I(0, a.clone().divide(r).opposite(), 0) : new I(0, 0, a.clone().divide(i).opposite());
5266
5285
  return;
5267
5286
  }
5268
5287
  if (e.points?.length === 3 && e.points.every((e) => e instanceof L)) {
@@ -5427,7 +5446,7 @@ function Y(e) {
5427
5446
  zero: !0,
5428
5447
  natural: !1
5429
5448
  }, e), n = new p();
5430
- if (t.negative ? n.numerator = H(t.max, t.zero) : n.numerator = V(+!t.zero, t.max), t.natural) n.denominator = 1;
5449
+ if (n.numerator = t.negative ? H(t.max, t.zero) : V(+!t.zero, t.max), t.natural) n.denominator = 1;
5431
5450
  else {
5432
5451
  let e = 0;
5433
5452
  for (; n.isRelative() && e < 10;) n.denominator = V(1, t.max), e++;