@cortex-js/compute-engine 0.34.0 → 0.35.0

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 (177) hide show
  1. package/dist/compute-engine.esm.js +2337 -695
  2. package/dist/compute-engine.min.esm.js +419 -38
  3. package/dist/compute-engine.min.umd.js +419 -38
  4. package/dist/compute-engine.umd.js +2337 -695
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.min.esm.js +2 -2
  7. package/dist/math-json.min.umd.js +2 -2
  8. package/dist/math-json.umd.js +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +1 -1
  11. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +1 -1
  14. package/dist/types/common/one-of.d.ts +1 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  17. package/dist/types/common/type/boxed-type.d.ts +1 -1
  18. package/dist/types/common/type/lexer.d.ts +1 -1
  19. package/dist/types/common/type/parse.d.ts +1 -1
  20. package/dist/types/common/type/parser.d.ts +1 -1
  21. package/dist/types/common/type/primitive.d.ts +1 -1
  22. package/dist/types/common/type/reduce.d.ts +1 -1
  23. package/dist/types/common/type/serialize.d.ts +1 -1
  24. package/dist/types/common/type/subtype.d.ts +1 -1
  25. package/dist/types/common/type/type-builder.d.ts +1 -1
  26. package/dist/types/common/type/types.d.ts +1 -1
  27. package/dist/types/common/type/utils.d.ts +1 -1
  28. package/dist/types/common/utils.d.ts +1 -1
  29. package/dist/types/compute-engine/assume.d.ts +1 -1
  30. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  34. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  35. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  36. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  38. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  39. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  40. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  41. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  43. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/terms.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  71. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  72. package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
  73. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  74. package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +51 -0
  75. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +93 -0
  76. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  77. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  78. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  79. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  80. package/dist/types/compute-engine/global-types.d.ts +2 -2
  81. package/dist/types/compute-engine/index.d.ts +3 -1
  82. package/dist/types/compute-engine/interval/arithmetic.d.ts +56 -0
  83. package/dist/types/compute-engine/interval/comparison.d.ts +70 -0
  84. package/dist/types/compute-engine/interval/elementary.d.ts +100 -0
  85. package/dist/types/compute-engine/interval/index.d.ts +93 -0
  86. package/dist/types/compute-engine/interval/trigonometric.d.ts +105 -0
  87. package/dist/types/compute-engine/interval/types.d.ts +50 -0
  88. package/dist/types/compute-engine/interval/util.d.ts +99 -0
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  90. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  91. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  92. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  93. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  94. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  95. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  96. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  97. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  98. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  99. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  100. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  101. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  102. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  103. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  104. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  105. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  106. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  107. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  108. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  109. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  110. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  111. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  112. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  113. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  114. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  115. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  116. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  117. package/dist/types/compute-engine/library/core.d.ts +1 -1
  118. package/dist/types/compute-engine/library/invisible-operator.d.ts +1 -1
  119. package/dist/types/compute-engine/library/library.d.ts +1 -1
  120. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  121. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  122. package/dist/types/compute-engine/library/logic-utils.d.ts +1 -1
  123. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  124. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  125. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  126. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  127. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  128. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  129. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  130. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  131. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  132. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  133. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  134. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  135. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  136. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  137. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  138. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  139. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  140. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  141. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  142. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  143. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  144. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  145. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  146. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  147. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  148. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  149. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  150. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  151. package/dist/types/compute-engine/oeis.d.ts +1 -1
  152. package/dist/types/compute-engine/sequence.d.ts +1 -1
  153. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  154. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  155. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  156. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  157. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  158. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  159. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  160. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  161. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  162. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  163. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  164. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  165. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  166. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  167. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  168. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  169. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  170. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  171. package/dist/types/compute-engine/types.d.ts +1 -1
  172. package/dist/types/compute-engine.d.ts +1 -1
  173. package/dist/types/math-json/symbols.d.ts +1 -1
  174. package/dist/types/math-json/types.d.ts +1 -1
  175. package/dist/types/math-json/utils.d.ts +1 -1
  176. package/dist/types/math-json.d.ts +2 -2
  177. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.34.0 */
1
+ /** Compute Engine 0.35.0 */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -18,7 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  }
19
19
  return to;
20
20
  };
21
- var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
21
+ var __toCommonJS = (mod3) => __copyProps(__defProp({}, "__esModule", { value: true }), mod3);
22
22
 
23
23
  // node_modules/complex-esm/dist/src/complex.js
24
24
  function logHypot(a, b) {
@@ -172,8 +172,8 @@ var init_complex = __esm({
172
172
  * @returns {Complex}
173
173
  */
174
174
  sign() {
175
- var abs2 = this["abs"]();
176
- return new _Complex(this["re"] / abs2, this["im"] / abs2);
175
+ var abs3 = this["abs"]();
176
+ return new _Complex(this["re"] / abs3, this["im"] / abs3);
177
177
  }
178
178
  /**
179
179
  * Adds two complex numbers
@@ -892,8 +892,8 @@ function digitsToString(d) {
892
892
  for (; w % 10 === 0; ) w /= 10;
893
893
  return str + w;
894
894
  }
895
- function checkInt32(i, min2, max2) {
896
- if (i !== ~~i || i < min2 || i > max2) {
895
+ function checkInt32(i, min3, max3) {
896
+ if (i !== ~~i || i < min3 || i > max3) {
897
897
  throw Error(invalidArgument + i);
898
898
  }
899
899
  }
@@ -1147,7 +1147,7 @@ function maxOrMin(Ctor, args, n) {
1147
1147
  return x;
1148
1148
  }
1149
1149
  function naturalExponential(x, sd) {
1150
- var denominator, guard, j, pow3, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1150
+ var denominator, guard, j, pow4, sum2, t, wpr, rep = 0, i = 0, k = 0, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
1151
1151
  if (!x.d || !x.d[0] || x.e > 17) {
1152
1152
  return new Ctor(x.d ? !x.d[0] ? 1 : x.s < 0 ? 0 : 1 / 0 : x.s ? x.s < 0 ? 0 : x : 0 / 0);
1153
1153
  }
@@ -1164,19 +1164,19 @@ function naturalExponential(x, sd) {
1164
1164
  }
1165
1165
  guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
1166
1166
  wpr += guard;
1167
- denominator = pow3 = sum2 = new Ctor(1);
1167
+ denominator = pow4 = sum2 = new Ctor(1);
1168
1168
  Ctor.precision = wpr;
1169
1169
  for (; ; ) {
1170
- pow3 = finalise(pow3.times(x), wpr, 1);
1170
+ pow4 = finalise(pow4.times(x), wpr, 1);
1171
1171
  denominator = denominator.times(++i);
1172
- t = sum2.plus(divide(pow3, denominator, wpr, 1));
1172
+ t = sum2.plus(divide(pow4, denominator, wpr, 1));
1173
1173
  if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum2.d).slice(0, wpr)) {
1174
1174
  j = k;
1175
1175
  while (j--) sum2 = finalise(sum2.times(sum2), wpr, 1);
1176
1176
  if (sd == null) {
1177
1177
  if (rep < 3 && checkRoundingDigits(sum2.d, wpr - guard, rm, rep)) {
1178
1178
  Ctor.precision = wpr += 10;
1179
- denominator = pow3 = t = new Ctor(1);
1179
+ denominator = pow4 = t = new Ctor(1);
1180
1180
  i = 0;
1181
1181
  rep++;
1182
1182
  } else {
@@ -1568,8 +1568,8 @@ function cbrt(x) {
1568
1568
  function ceil(x) {
1569
1569
  return finalise(x = new this(x), x.e + 1, 2);
1570
1570
  }
1571
- function clamp(x, min2, max2) {
1572
- return new this(x).clamp(min2, max2);
1571
+ function clamp(x, min3, max3) {
1572
+ return new this(x).clamp(min3, max3);
1573
1573
  }
1574
1574
  function config(obj) {
1575
1575
  if (!obj || typeof obj !== "object") throw Error(decimalError + "Object expected");
@@ -2013,14 +2013,14 @@ var init_decimal = __esm({
2013
2013
  P.ceil = function() {
2014
2014
  return finalise(new this.constructor(this), this.e + 1, 2);
2015
2015
  };
2016
- P.clampedTo = P.clamp = function(min2, max2) {
2016
+ P.clampedTo = P.clamp = function(min3, max3) {
2017
2017
  var k, x = this, Ctor = x.constructor;
2018
- min2 = new Ctor(min2);
2019
- max2 = new Ctor(max2);
2020
- if (!min2.s || !max2.s) return new Ctor(NaN);
2021
- if (min2.gt(max2)) throw Error(invalidArgument + max2);
2022
- k = x.cmp(min2);
2023
- return k < 0 ? min2 : x.cmp(max2) > 0 ? max2 : new Ctor(x);
2018
+ min3 = new Ctor(min3);
2019
+ max3 = new Ctor(max3);
2020
+ if (!min3.s || !max3.s) return new Ctor(NaN);
2021
+ if (min3.gt(max3)) throw Error(invalidArgument + max3);
2022
+ k = x.cmp(min3);
2023
+ return k < 0 ? min3 : x.cmp(max3) > 0 ? max3 : new Ctor(x);
2024
2024
  };
2025
2025
  P.comparedTo = P.cmp = function(y) {
2026
2026
  var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
@@ -2918,13 +2918,13 @@ var init_decimal = __esm({
2918
2918
  for (; !a[0] && a.length > 1; ) a.shift();
2919
2919
  }
2920
2920
  return function(x, y, pr, rm, dp, base) {
2921
- var cmp2, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign2 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
2921
+ var cmp2, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign3 = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
2922
2922
  if (!xd || !xd[0] || !yd || !yd[0]) {
2923
2923
  return new Ctor(
2924
2924
  // Return NaN if either NaN, or both Infinity or 0.
2925
2925
  !x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : (
2926
2926
  // Return ±0 if x is 0 or y is ±Infinity, or return ±Infinity as y is 0.
2927
- xd && xd[0] == 0 || !yd ? sign2 * 0 : sign2 / 0
2927
+ xd && xd[0] == 0 || !yd ? sign3 * 0 : sign3 / 0
2928
2928
  )
2929
2929
  );
2930
2930
  }
@@ -2938,7 +2938,7 @@ var init_decimal = __esm({
2938
2938
  }
2939
2939
  yL = yd.length;
2940
2940
  xL = xd.length;
2941
- q = new Ctor(sign2);
2941
+ q = new Ctor(sign3);
2942
2942
  qd = q.d = [];
2943
2943
  for (i = 0; yd[i] == (xd[i] || 0); i++) ;
2944
2944
  if (yd[i] > (xd[i] || 0)) e--;
@@ -5446,8 +5446,8 @@ function bigint(a) {
5446
5446
  let s = a.toLowerCase();
5447
5447
  const m = s.match(/([+-]?[0-9]*)(?:\.([0-9]+))?e([+-]?[0-9]+)$/);
5448
5448
  if (m) {
5449
- const exp2 = parseInt(m[3]);
5450
- const pad = exp2 - (m[2] ? m[2].length : 0);
5449
+ const exp3 = parseInt(m[3]);
5450
+ const pad = exp3 - (m[2] ? m[2].length : 0);
5451
5451
  if (pad < 0) return null;
5452
5452
  s = (m[1] ?? "") + (m[2] ?? "") + "0".repeat(pad);
5453
5453
  }
@@ -6940,8 +6940,8 @@ function rationalValue(expr) {
6940
6940
  denom = machineValue(d) ?? NaN;
6941
6941
  }
6942
6942
  if (h === "Power") {
6943
- const [base, exp2] = operands(expr);
6944
- const exponent = machineValue(exp2);
6943
+ const [base, exp3] = operands(expr);
6944
+ const exponent = machineValue(exp3);
6945
6945
  if (exponent === 1) {
6946
6946
  numer = machineValue(base);
6947
6947
  denom = 1;
@@ -8323,11 +8323,11 @@ function parseAssign(parser, lhs) {
8323
8323
  if (!fn2) return null;
8324
8324
  const rhs2 = parser.parseExpression({ minPrec: 0 });
8325
8325
  if (rhs2 === null) return null;
8326
- const sub2 = operand(lhs, 2);
8327
- if (stringValue(sub2) !== null) {
8326
+ const sub3 = operand(lhs, 2);
8327
+ if (stringValue(sub3) !== null) {
8328
8328
  return ["Assign", lhs, rhs2];
8329
8329
  }
8330
- if (symbol(sub2)) {
8330
+ if (symbol(sub3)) {
8331
8331
  return ["Assign", lhs, rhs2];
8332
8332
  }
8333
8333
  return ["Assign", lhs, rhs2];
@@ -9643,12 +9643,12 @@ function formatFractionalPart(digits, wholeDigitsCount, options) {
9643
9643
  if (extraDigits) digits += options.truncationMarker;
9644
9644
  return digits;
9645
9645
  }
9646
- function formatExponent(exp2, options) {
9647
- if (!exp2 || exp2 === "0") return "";
9646
+ function formatExponent(exp3, options) {
9647
+ if (!exp3 || exp3 === "0") return "";
9648
9648
  if (options.beginExponentMarker) {
9649
- return options.beginExponentMarker + exp2 + (options.endExponentMarker ?? "");
9649
+ return options.beginExponentMarker + exp3 + (options.endExponentMarker ?? "");
9650
9650
  }
9651
- return `10^{${exp2}}`;
9651
+ return `10^{${exp3}}`;
9652
9652
  }
9653
9653
  function serializeNumber(expr, options) {
9654
9654
  if (expr === null) return "";
@@ -9692,9 +9692,9 @@ function serializeNumber(expr, options) {
9692
9692
  const [_, body, repeat2, trail] = num.match(/(.+)\(([0-9]+)\)(.*)$/) ?? [];
9693
9693
  num = body + repeat2.repeat(6) + trail;
9694
9694
  }
9695
- let sign2 = "";
9695
+ let sign3 = "";
9696
9696
  if (num[0] === "-") {
9697
- sign2 = "-";
9697
+ sign3 = "-";
9698
9698
  num = num.substring(1);
9699
9699
  } else if (num[0] === "+") {
9700
9700
  num = num.substring(1);
@@ -9710,25 +9710,25 @@ function serializeNumber(expr, options) {
9710
9710
  } else if (options.notation === "adaptiveScientific") {
9711
9711
  result = serializeScientificNotationNumber(num, options);
9712
9712
  }
9713
- return sign2 + (result ?? serializeAutoNotationNumber(num, {
9713
+ return sign3 + (result ?? serializeAutoNotationNumber(num, {
9714
9714
  ...options
9715
9715
  }));
9716
9716
  }
9717
9717
  function serializeScientificNotationNumber(valString, options, expMultiple = 1) {
9718
9718
  let m = valString.match(/^(.*)[e|E]([-+]?[0-9]+)$/);
9719
9719
  if (!m) {
9720
- let sign2 = "";
9720
+ let sign3 = "";
9721
9721
  if (valString[0] === "-") {
9722
- sign2 = "-";
9722
+ sign3 = "-";
9723
9723
  valString = valString.substring(1);
9724
9724
  } else if (valString[0] === "+") {
9725
9725
  valString = valString.substring(1);
9726
9726
  }
9727
9727
  if (valString.indexOf(".") < 0) {
9728
9728
  if (valString.length === 1) {
9729
- valString = sign2 + valString + "e+0";
9729
+ valString = sign3 + valString + "e+0";
9730
9730
  } else {
9731
- valString = sign2 + valString[0] + "." + valString.slice(1) + "e+" + (valString.length - 1).toString();
9731
+ valString = sign3 + valString[0] + "." + valString.slice(1) + "e+" + (valString.length - 1).toString();
9732
9732
  }
9733
9733
  } else {
9734
9734
  let [_, whole, fraction] = valString.match(/^(.*)\.(.*)$/);
@@ -9738,20 +9738,20 @@ function serializeScientificNotationNumber(valString, options, expMultiple = 1)
9738
9738
  let leadingZeros = 0;
9739
9739
  while (fraction[leadingZeros] === "0") leadingZeros++;
9740
9740
  if (leadingZeros === fraction.length) {
9741
- valString = sign2 + "0e+0";
9741
+ valString = sign3 + "0e+0";
9742
9742
  } else {
9743
9743
  const significand = fraction.slice(leadingZeros);
9744
9744
  const firstDigit = significand[0];
9745
9745
  const restDigits = significand.slice(1);
9746
9746
  const exponent2 = -(leadingZeros + 1);
9747
9747
  if (restDigits) {
9748
- valString = sign2 + firstDigit + "." + restDigits + "e" + exponent2;
9748
+ valString = sign3 + firstDigit + "." + restDigits + "e" + exponent2;
9749
9749
  } else {
9750
- valString = sign2 + firstDigit + "e" + exponent2;
9750
+ valString = sign3 + firstDigit + "e" + exponent2;
9751
9751
  }
9752
9752
  }
9753
9753
  } else {
9754
- valString = sign2 + whole[0] + "." + whole.slice(1) + fraction + "e+" + (whole.length - 1).toString();
9754
+ valString = sign3 + whole[0] + "." + whole.slice(1) + fraction + "e+" + (whole.length - 1).toString();
9755
9755
  }
9756
9756
  }
9757
9757
  m = valString.match(/^(.*)[e|E]([-+]?[0-9]+)$/);
@@ -9793,11 +9793,11 @@ function serializeScientificNotationNumber(valString, options, expMultiple = 1)
9793
9793
  }
9794
9794
  function serializeAutoNotationNumber(valString, options) {
9795
9795
  let m = valString.match(/^(.*)[e|E]([-+]?[0-9]+)$/i);
9796
- let exp2 = 0;
9796
+ let exp3 = 0;
9797
9797
  let originalExp = 0;
9798
9798
  if (m?.[1] && m[2]) {
9799
- exp2 = parseInt(m[2]);
9800
- originalExp = exp2;
9799
+ exp3 = parseInt(m[2]);
9800
+ originalExp = exp3;
9801
9801
  valString = m[1];
9802
9802
  }
9803
9803
  let wholePart = m?.[1] ?? valString;
@@ -9807,23 +9807,23 @@ function serializeAutoNotationNumber(valString, options) {
9807
9807
  wholePart = m[1];
9808
9808
  fractionalPart = m[2];
9809
9809
  }
9810
- if (exp2 !== 0 && fractionalPart) {
9810
+ if (exp3 !== 0 && fractionalPart) {
9811
9811
  wholePart += fractionalPart;
9812
- exp2 -= fractionalPart.length;
9812
+ exp3 -= fractionalPart.length;
9813
9813
  fractionalPart = "";
9814
9814
  }
9815
9815
  const avoid = options.avoidExponentsInRange;
9816
- if (exp2 !== 0 && avoid) {
9816
+ if (exp3 !== 0 && avoid) {
9817
9817
  if (originalExp >= avoid[0] && originalExp <= avoid[1]) {
9818
9818
  [wholePart, fractionalPart] = toDecimalNumber(
9819
9819
  wholePart,
9820
9820
  fractionalPart,
9821
- exp2
9821
+ exp3
9822
9822
  );
9823
- exp2 = 0;
9823
+ exp3 = 0;
9824
9824
  }
9825
9825
  }
9826
- const exponent = formatExponent(exp2.toString(), options);
9826
+ const exponent = formatExponent(exp3.toString(), options);
9827
9827
  if (fractionalPart)
9828
9828
  fractionalPart = options.decimalSeparator + formatFractionalPart(fractionalPart, wholePart.length, options);
9829
9829
  wholePart = insertWholeGroupSeparator(wholePart, options);
@@ -9876,10 +9876,10 @@ function insertFractionalGroupSeparator(numberString, options) {
9876
9876
  function insertWholeGroupSeparator(numberString, options) {
9877
9877
  return insertGroupSeparator(numberString, options, 0);
9878
9878
  }
9879
- function toDecimalNumber(wholePart, fractionalPart, exp2) {
9879
+ function toDecimalNumber(wholePart, fractionalPart, exp3) {
9880
9880
  let combinedNumber = wholePart + fractionalPart;
9881
9881
  const wholeLength = wholePart.length;
9882
- const newDecimalPosition = wholeLength + exp2;
9882
+ const newDecimalPosition = wholeLength + exp3;
9883
9883
  let newWholePart;
9884
9884
  let newFractionalPart;
9885
9885
  if (newDecimalPosition > 0) {
@@ -9991,8 +9991,8 @@ function parseSymbolBody2(s, topLevel = true, style = "auto") {
9991
9991
  sups.push(sup);
9992
9992
  rest = rest2;
9993
9993
  } else if (rest.startsWith("_")) {
9994
- const [sub2, rest2] = parseSymbolBody2(rest.substring(1), false, "none");
9995
- subs.push(sub2);
9994
+ const [sub3, rest2] = parseSymbolBody2(rest.substring(1), false, "none");
9995
+ subs.push(sub3);
9996
9996
  rest = rest2;
9997
9997
  } else {
9998
9998
  break;
@@ -11540,13 +11540,13 @@ var init_exact_numeric_value = __esm({
11540
11540
  return this.factory(this.bignumRe).pow(exponent);
11541
11541
  if (this.sign < 0) {
11542
11542
  if (Number.isInteger(exponent)) {
11543
- const sign2 = exponent % 2 === 0 ? 1 : -1;
11543
+ const sign3 = exponent % 2 === 0 ? 1 : -1;
11544
11544
  return this.clone({
11545
11545
  rational: isMachineRational(this.rational) ? [
11546
- sign2 * (-this.rational[0]) ** exponent,
11546
+ sign3 * (-this.rational[0]) ** exponent,
11547
11547
  this.rational[1] ** exponent
11548
11548
  ] : [
11549
- BigInt(sign2) * (-this.rational[0]) ** BigInt(exponent),
11549
+ BigInt(sign3) * (-this.rational[0]) ** BigInt(exponent),
11550
11550
  this.rational[1] ** BigInt(exponent)
11551
11551
  ],
11552
11552
  radical: this.radical ** exponent
@@ -11912,34 +11912,34 @@ function multinomialCoefficient(k) {
11912
11912
  }
11913
11913
  return prod;
11914
11914
  }
11915
- function* powers(n, exp2) {
11915
+ function* powers(n, exp3) {
11916
11916
  if (n === 1) {
11917
- yield [exp2];
11917
+ yield [exp3];
11918
11918
  return;
11919
11919
  }
11920
- for (let i = 0; i <= exp2; i += 1)
11921
- for (const p of powers(n - 1, exp2 - i)) yield [i, ...p];
11920
+ for (let i = 0; i <= exp3; i += 1)
11921
+ for (const p of powers(n - 1, exp3 - i)) yield [i, ...p];
11922
11922
  }
11923
- function expandPower(base, exp2) {
11923
+ function expandPower(base, exp3) {
11924
11924
  const ce = base.engine;
11925
- if (exp2 < 0) {
11926
- const expr = expandPower(base, -exp2);
11925
+ if (exp3 < 0) {
11926
+ const expr = expandPower(base, -exp3);
11927
11927
  return expr ? expr.inv() : null;
11928
11928
  }
11929
- if (exp2 === 0) return ce.One;
11930
- if (exp2 === 1) return expand2(base);
11929
+ if (exp3 === 0) return ce.One;
11930
+ if (exp3 === 1) return expand2(base);
11931
11931
  if (base.operator === "Negate") {
11932
- if (Number.isInteger(exp2)) {
11933
- const sign2 = exp2 % 2 === 0 ? 1 : -1;
11934
- const result2 = expandPower(base.op1, exp2);
11932
+ if (Number.isInteger(exp3)) {
11933
+ const sign3 = exp3 % 2 === 0 ? 1 : -1;
11934
+ const result2 = expandPower(base.op1, exp3);
11935
11935
  if (result2 === null) return null;
11936
- return sign2 > 0 ? result2 : result2.neg();
11936
+ return sign3 > 0 ? result2 : result2.neg();
11937
11937
  }
11938
11938
  }
11939
11939
  console.assert(base.operator !== "Subtract");
11940
11940
  if (base.operator !== "Add") return null;
11941
11941
  const terms = base.ops;
11942
- const it = powers(terms.length, exp2);
11942
+ const it = powers(terms.length, exp3);
11943
11943
  const result = [];
11944
11944
  for (const val of it) {
11945
11945
  const product = [ce.number(multinomialCoefficient(val))];
@@ -11966,8 +11966,8 @@ function expandFunction(ce, h, ops) {
11966
11966
  if (h === "Negate") return expand2(ops[0])?.neg() ?? null;
11967
11967
  if (h === "Add") return add3(...ops.map((x) => expand2(x) ?? x));
11968
11968
  if (h === "Power") {
11969
- const exp2 = asSmallInteger(ops[1]);
11970
- result = exp2 !== null ? expandPower(ops[0], exp2) : null;
11969
+ const exp3 = asSmallInteger(ops[1]);
11970
+ result = exp3 !== null ? expandPower(ops[0], exp3) : null;
11971
11971
  }
11972
11972
  return result;
11973
11973
  }
@@ -12012,22 +12012,22 @@ var init_expand = __esm({
12012
12012
 
12013
12013
  // src/compute-engine/boxed-expression/negate.ts
12014
12014
  function canonicalNegate(expr) {
12015
- let sign2 = -1;
12015
+ let sign3 = -1;
12016
12016
  while (expr.operator === "Negate") {
12017
12017
  expr = expr.op1;
12018
- sign2 = -sign2;
12018
+ sign3 = -sign3;
12019
12019
  }
12020
- if (sign2 === 1) return expr;
12020
+ if (sign3 === 1) return expr;
12021
12021
  if (expr.isNumberLiteral) return expr.neg();
12022
12022
  return expr.engine._fn("Negate", [expr]);
12023
12023
  }
12024
12024
  function negate(expr) {
12025
- let sign2 = -1;
12025
+ let sign3 = -1;
12026
12026
  while (expr.operator === "Negate") {
12027
12027
  expr = expr.op1;
12028
- sign2 = -sign2;
12028
+ sign3 = -sign3;
12029
12029
  }
12030
- if (sign2 === 1) return expr;
12030
+ if (sign3 === 1) return expr;
12031
12031
  if (expr.numericValue !== null) return expr.neg();
12032
12032
  const ce = expr.engine;
12033
12033
  if (expr.operator === "Subtract") return expr.op2.sub(expr.op1);
@@ -12233,11 +12233,11 @@ function div2(num, denom) {
12233
12233
  return result.asRationalExpression();
12234
12234
  }
12235
12235
  function canonicalMultiply(ce, ops) {
12236
- let sign2 = 1;
12236
+ let sign3 = 1;
12237
12237
  let xs = [];
12238
12238
  for (const op of ops) {
12239
12239
  const [o, s] = unnegate(op);
12240
- sign2 *= s;
12240
+ sign3 *= s;
12241
12241
  xs.push(o);
12242
12242
  }
12243
12243
  xs = xs.filter((x) => !x.is(1));
@@ -12301,7 +12301,7 @@ function canonicalMultiply(ce, ops) {
12301
12301
  }
12302
12302
  ys.push(x);
12303
12303
  }
12304
- if (sign2 < 0) {
12304
+ if (sign3 < 0) {
12305
12305
  if (ys.length === 0) return ce.number(-1);
12306
12306
  if (ys.length === 1) return ys[0].neg();
12307
12307
  return negateProduct(ce, ys);
@@ -12311,25 +12311,25 @@ function canonicalMultiply(ce, ops) {
12311
12311
  return ce._fn("Multiply", [...ys].sort(order));
12312
12312
  }
12313
12313
  function unnegate(op) {
12314
- let sign2 = 1;
12314
+ let sign3 = 1;
12315
12315
  while (op.operator === "Negate") {
12316
- sign2 = -sign2;
12316
+ sign3 = -sign3;
12317
12317
  op = op.op1;
12318
12318
  }
12319
12319
  if (op.isNumberLiteral && op.isNegative) {
12320
- sign2 = -sign2;
12320
+ sign3 = -sign3;
12321
12321
  op = op.neg();
12322
12322
  }
12323
- return [op, sign2];
12323
+ return [op, sign3];
12324
12324
  }
12325
12325
  function mul3(...xs) {
12326
12326
  console.assert(xs.length > 0);
12327
12327
  if (xs.length === 1) return xs[0];
12328
12328
  const ce = xs[0].engine;
12329
- const exp2 = expandProducts(ce, xs);
12330
- if (exp2) {
12331
- if (exp2.operator !== "Multiply") return exp2;
12332
- xs = exp2.ops;
12329
+ const exp3 = expandProducts(ce, xs);
12330
+ if (exp3) {
12331
+ if (exp3.operator !== "Multiply") return exp3;
12332
+ xs = exp3.ops;
12333
12333
  }
12334
12334
  return new Product(ce, xs).asRationalExpression();
12335
12335
  }
@@ -12337,10 +12337,10 @@ function mulN(...xs) {
12337
12337
  console.assert(xs.length > 0);
12338
12338
  const ce = xs[0].engine;
12339
12339
  xs = xs.map((x) => x.N());
12340
- const exp2 = expandProducts(ce, xs);
12341
- if (exp2) {
12342
- if (exp2.operator !== "Multiply") return exp2;
12343
- xs = exp2.ops;
12340
+ const exp3 = expandProducts(ce, xs);
12341
+ if (exp3) {
12342
+ if (exp3.operator !== "Multiply") return exp3;
12343
+ xs = exp3.ops;
12344
12344
  }
12345
12345
  return new Product(ce, xs).asExpression({ numericApproximation: true });
12346
12346
  }
@@ -12668,25 +12668,25 @@ var init_big_numeric_value = __esm({
12668
12668
  im: chop2(newModulus.mul(newArgument.sin()).toNumber())
12669
12669
  });
12670
12670
  }
12671
- root(exp2) {
12672
- if (!Number.isInteger(exp2)) return this._makeExact(NaN);
12673
- if (exp2 === 0) return this._makeExact(NaN);
12674
- if (exp2 === 1) return this;
12671
+ root(exp3) {
12672
+ if (!Number.isInteger(exp3)) return this._makeExact(NaN);
12673
+ if (exp3 === 0) return this._makeExact(NaN);
12674
+ if (exp3 === 1) return this;
12675
12675
  if (this.isZero) return this;
12676
12676
  if (this.isOne) return this;
12677
12677
  if (this.isNegativeOne) return this;
12678
12678
  if (this.im === 0) {
12679
12679
  if (this.decimal.isNegative()) return this._makeExact(NaN);
12680
- if (exp2 === 2) return this.clone(this.decimal.sqrt());
12681
- if (exp2 === 3) return this.clone(this.decimal.cbrt());
12682
- return this.clone(this.decimal.pow(1 / exp2));
12680
+ if (exp3 === 2) return this.clone(this.decimal.sqrt());
12681
+ if (exp3 === 3) return this.clone(this.decimal.cbrt());
12682
+ return this.clone(this.decimal.pow(1 / exp3));
12683
12683
  }
12684
12684
  const a = this.decimal;
12685
12685
  const b = this.im;
12686
12686
  const modulus = a.mul(a).add(b * b).sqrt();
12687
12687
  const argument = Decimal.atan2(b, a);
12688
- const newModulus = modulus.pow(1 / exp2);
12689
- const newArgument = argument.div(exp2);
12688
+ const newModulus = modulus.pow(1 / exp3);
12689
+ const newArgument = argument.div(exp3);
12690
12690
  return this.clone({
12691
12691
  re: newModulus.mul(newArgument.cos()),
12692
12692
  im: chop2(newModulus.mul(newArgument.sin()).toNumber())
@@ -14101,12 +14101,12 @@ var init_tensors = __esm({
14101
14101
  const [m, n] = this.shape;
14102
14102
  if (m !== n) return void 0;
14103
14103
  if (m === 1) return this.data[0];
14104
- const add4 = this.field.add.bind(this.field);
14105
- const mul4 = this.field.mul.bind(this.field);
14104
+ const add5 = this.field.add.bind(this.field);
14105
+ const mul5 = this.field.mul.bind(this.field);
14106
14106
  const neg2 = this.field.neg.bind(this.field);
14107
14107
  if (m === 2) {
14108
14108
  const [a, b, c, d] = this.data;
14109
- return add4(mul4(a, d), neg2(mul4(b, c)));
14109
+ return add5(mul5(a, d), neg2(mul5(b, c)));
14110
14110
  }
14111
14111
  const addn = this.field.addn.bind(this.field);
14112
14112
  const muln = this.field.muln.bind(this.field);
@@ -14123,8 +14123,8 @@ var init_tensors = __esm({
14123
14123
  }
14124
14124
  const rows = this.shape[0];
14125
14125
  let negated = false;
14126
- const div3 = this.field.div.bind(this.field);
14127
- const sub2 = this.field.sub.bind(this.field);
14126
+ const div4 = this.field.div.bind(this.field);
14127
+ const sub3 = this.field.sub.bind(this.field);
14128
14128
  const rowIndices = new Array(rows).fill(0).map((_, i) => i);
14129
14129
  const matrix = [...this.data];
14130
14130
  for (let k = 0; k < rows; k++) {
@@ -14147,8 +14147,8 @@ var init_tensors = __esm({
14147
14147
  for (let i = k + 1; i < rows; i++) {
14148
14148
  const i_ = rowIndices[i - 1];
14149
14149
  for (let j = k + 1; j < rows; j++) {
14150
- matrix[i_][j] = div3(
14151
- sub2(mul4(matrix[i_][j], piv), mul4(matrix[i_][k], matrix[k_][j])),
14150
+ matrix[i_][j] = div4(
14151
+ sub3(mul5(matrix[i_][j], piv), mul5(matrix[i_][k], matrix[k_][j])),
14152
14152
  piv_
14153
14153
  );
14154
14154
  }
@@ -14165,13 +14165,13 @@ var init_tensors = __esm({
14165
14165
  const [a, b, c, d] = this.data;
14166
14166
  const det = this.determinant();
14167
14167
  if (det === void 0 || this.field.isZero(det)) return void 0;
14168
- const div4 = this.field.div.bind(this.field);
14168
+ const div5 = this.field.div.bind(this.field);
14169
14169
  const neg2 = this.field.neg.bind(this.field);
14170
14170
  const inverseData2 = [
14171
- div4(d, det),
14172
- neg2(div4(b, det)),
14173
- neg2(div4(c, det)),
14174
- div4(a, det)
14171
+ div5(d, det),
14172
+ neg2(div5(b, det)),
14173
+ neg2(div5(c, det)),
14174
+ div5(a, det)
14175
14175
  ];
14176
14176
  return makeTensor(this.ce, {
14177
14177
  dtype: this.dtype,
@@ -14180,9 +14180,9 @@ var init_tensors = __esm({
14180
14180
  });
14181
14181
  }
14182
14182
  const rows = this.shape[0];
14183
- const div3 = this.field.div.bind(this.field);
14184
- const sub2 = this.field.sub.bind(this.field);
14185
- const mul4 = this.field.mul.bind(this.field);
14183
+ const div4 = this.field.div.bind(this.field);
14184
+ const sub3 = this.field.sub.bind(this.field);
14185
+ const mul5 = this.field.mul.bind(this.field);
14186
14186
  const matrix = this.array;
14187
14187
  const identity = new Array(rows).fill(0).map((_, i) => {
14188
14188
  const row = new Array(rows).fill(0);
@@ -14210,9 +14210,9 @@ var init_tensors = __esm({
14210
14210
  for (let i = k + 1; i < rows; i++) {
14211
14211
  const i_ = rowIndices[i - 1];
14212
14212
  for (let j = k + 1; j < rows * 2; j++) {
14213
- augmented[i_][j] = sub2(
14213
+ augmented[i_][j] = sub3(
14214
14214
  augmented[i_][j],
14215
- mul4(div3(mul4(augmented[i_][k], augmented[k_][j]), piv), piv_)
14215
+ mul5(div4(mul5(augmented[i_][k], augmented[k_][j]), piv), piv_)
14216
14216
  );
14217
14217
  }
14218
14218
  }
@@ -14222,14 +14222,14 @@ var init_tensors = __esm({
14222
14222
  for (let i = 0; i < k; i++) {
14223
14223
  const i_ = rowIndices[i];
14224
14224
  for (let j = rows; j < rows * 2; j++) {
14225
- augmented[i_][j] = sub2(
14225
+ augmented[i_][j] = sub3(
14226
14226
  augmented[i_][j],
14227
- mul4(div3(mul4(augmented[i_][k], augmented[k][j]), piv), piv)
14227
+ mul5(div4(mul5(augmented[i_][k], augmented[k][j]), piv), piv)
14228
14228
  );
14229
14229
  }
14230
14230
  }
14231
14231
  for (let j = rows; j < rows * 2; j++) {
14232
- augmented[k][j] = div3(augmented[k][j], piv);
14232
+ augmented[k][j] = div4(augmented[k][j], piv);
14233
14233
  }
14234
14234
  }
14235
14235
  const inverseData = augmented.map(
@@ -14595,11 +14595,11 @@ var init_boxed_tensor = __esm({
14595
14595
  div(rhs) {
14596
14596
  return this.structural.div(rhs);
14597
14597
  }
14598
- pow(exp2) {
14599
- return this.structural.pow(exp2);
14598
+ pow(exp3) {
14599
+ return this.structural.pow(exp3);
14600
14600
  }
14601
- root(exp2) {
14602
- return this.structural.root(exp2);
14601
+ root(exp3) {
14602
+ return this.structural.root(exp3);
14603
14603
  }
14604
14604
  sqrt() {
14605
14605
  return this.structural.sqrt();
@@ -14934,9 +14934,9 @@ function polynomialDegree(expr, variable) {
14934
14934
  if (expr.op2.has(variable)) return -1;
14935
14935
  return 0;
14936
14936
  }
14937
- const exp2 = asSmallInteger(expr.op2);
14938
- if (exp2 === null || exp2 < 0) return -1;
14939
- return baseDeg * exp2;
14937
+ const exp3 = asSmallInteger(expr.op2);
14938
+ if (exp3 === null || exp3 < 0) return -1;
14939
+ return baseDeg * exp3;
14940
14940
  }
14941
14941
  if (expr.has(variable)) return -1;
14942
14942
  return 0;
@@ -14977,9 +14977,9 @@ function getPolynomialCoefficients(expr, variable) {
14977
14977
  }
14978
14978
  if (term.operator === "Power") {
14979
14979
  if (term.op1.symbol === variable) {
14980
- const exp2 = asSmallInteger(term.op2);
14981
- if (exp2 !== null && exp2 >= 0) {
14982
- return addCoefficient(ce.One, exp2);
14980
+ const exp3 = asSmallInteger(term.op2);
14981
+ if (exp3 !== null && exp3 >= 0) {
14982
+ return addCoefficient(ce.One, exp3);
14983
14983
  }
14984
14984
  }
14985
14985
  if (!term.op1.has(variable)) {
@@ -14997,9 +14997,9 @@ function getPolynomialCoefficients(expr, variable) {
14997
14997
  } else if (factor3.symbol === variable) {
14998
14998
  varDeg += 1;
14999
14999
  } else if (factor3.operator === "Power" && factor3.op1.symbol === variable) {
15000
- const exp2 = asSmallInteger(factor3.op2);
15001
- if (exp2 !== null && exp2 >= 0) {
15002
- varDeg += exp2;
15000
+ const exp3 = asSmallInteger(factor3.op2);
15001
+ if (exp3 !== null && exp3 >= 0) {
15002
+ varDeg += exp3;
15003
15003
  } else {
15004
15004
  return false;
15005
15005
  }
@@ -15358,13 +15358,13 @@ function canonicalPower(a, b) {
15358
15358
  }
15359
15359
  function canonicalRoot(a, b) {
15360
15360
  const ce = a.engine;
15361
- let exp2 = void 0;
15362
- if (typeof b === "number") exp2 = b;
15361
+ let exp3 = void 0;
15362
+ if (typeof b === "number") exp3 = b;
15363
15363
  else {
15364
- if (b.isNumberLiteral && b.im === 0) exp2 = b.re;
15364
+ if (b.isNumberLiteral && b.im === 0) exp3 = b.re;
15365
15365
  }
15366
- if (exp2 === 1) return a;
15367
- if (exp2 === 2) {
15366
+ if (exp3 === 1) return a;
15367
+ if (exp3 === 2) {
15368
15368
  if (a.isNumberLiteral && a.type.matches("rational")) {
15369
15369
  if (a.re < SMALL_INTEGER) {
15370
15370
  const v = a.sqrt();
@@ -15378,86 +15378,86 @@ function canonicalRoot(a, b) {
15378
15378
  canonical: a.isCanonical && (typeof b === "number" || b.isCanonical)
15379
15379
  });
15380
15380
  }
15381
- function pow2(x, exp2, { numericApproximation }) {
15382
- if (!x.isCanonical || typeof exp2 !== "number" && !exp2.isCanonical)
15383
- return x.engine._fn("Power", [x, x.engine.box(exp2)], { canonical: false });
15381
+ function pow2(x, exp3, { numericApproximation }) {
15382
+ if (!x.isCanonical || typeof exp3 !== "number" && !exp3.isCanonical)
15383
+ return x.engine._fn("Power", [x, x.engine.box(exp3)], { canonical: false });
15384
15384
  if (numericApproximation) {
15385
15385
  if (x.isNumberLiteral) {
15386
- if (typeof exp2 === "number") {
15386
+ if (typeof exp3 === "number") {
15387
15387
  return apply(
15388
15388
  x,
15389
- (x2) => Math.pow(x2, exp2),
15390
- (x2) => x2.pow(exp2),
15391
- (x2) => x2.pow(exp2)
15392
- ) ?? pow2(x, exp2, { numericApproximation: false });
15393
- } else if (exp2.isNumberLiteral)
15389
+ (x2) => Math.pow(x2, exp3),
15390
+ (x2) => x2.pow(exp3),
15391
+ (x2) => x2.pow(exp3)
15392
+ ) ?? pow2(x, exp3, { numericApproximation: false });
15393
+ } else if (exp3.isNumberLiteral)
15394
15394
  return apply2(
15395
15395
  x,
15396
- exp2,
15397
- (x2, exp3) => Math.pow(x2, exp3),
15398
- (x2, exp3) => x2.pow(exp3),
15399
- (x2, exp3) => x2.pow(exp3)
15400
- ) ?? pow2(x, exp2, { numericApproximation: false });
15396
+ exp3,
15397
+ (x2, exp4) => Math.pow(x2, exp4),
15398
+ (x2, exp4) => x2.pow(exp4),
15399
+ (x2, exp4) => x2.pow(exp4)
15400
+ ) ?? pow2(x, exp3, { numericApproximation: false });
15401
15401
  }
15402
15402
  }
15403
15403
  const ce = x.engine;
15404
- if (typeof exp2 !== "number") exp2 = exp2.canonical;
15405
- const canonicalResult = canonicalPower(x, ce.box(exp2));
15404
+ if (typeof exp3 !== "number") exp3 = exp3.canonical;
15405
+ const canonicalResult = canonicalPower(x, ce.box(exp3));
15406
15406
  if (canonicalResult.operator !== "Power") return canonicalResult;
15407
- const e = typeof exp2 === "number" ? exp2 : exp2.im === 0 ? exp2.re : void 0;
15407
+ const e = typeof exp3 === "number" ? exp3 : exp3.im === 0 ? exp3.re : void 0;
15408
15408
  if (x.symbol === "ComplexInfinity") return ce.NaN;
15409
15409
  if (x.symbol === "ExponentialE") {
15410
- let theta = getImaginaryFactor(exp2);
15410
+ let theta = getImaginaryFactor(exp3);
15411
15411
  if (theta !== void 0) {
15412
15412
  theta = canonicalAngle(theta);
15413
15413
  if (theta !== void 0) {
15414
15414
  return ce.function("Cos", [theta]).add(ce.function("Sin", [theta]).mul(ce.I)).simplify();
15415
15415
  }
15416
15416
  } else {
15417
- if (typeof exp2 === "number") {
15418
- return ce.number(ce._numericValue(ce.E.N().numericValue).pow(exp2));
15419
- } else if (exp2.isNumberLiteral) {
15417
+ if (typeof exp3 === "number") {
15418
+ return ce.number(ce._numericValue(ce.E.N().numericValue).pow(exp3));
15419
+ } else if (exp3.isNumberLiteral) {
15420
15420
  return ce.number(
15421
- ce._numericValue(ce.E.N().numericValue).pow(exp2.numericValue)
15421
+ ce._numericValue(ce.E.N().numericValue).pow(exp3.numericValue)
15422
15422
  );
15423
15423
  }
15424
15424
  }
15425
15425
  }
15426
15426
  if (x.operator === "Power") {
15427
15427
  const [base, power] = x.ops;
15428
- return pow2(base, power.mul(exp2), { numericApproximation });
15428
+ return pow2(base, power.mul(exp3), { numericApproximation });
15429
15429
  }
15430
15430
  if (x.operator === "Divide") {
15431
15431
  const [num, denom] = x.ops;
15432
- return pow2(num, exp2, { numericApproximation }).div(
15433
- pow2(denom, exp2, { numericApproximation })
15432
+ return pow2(num, exp3, { numericApproximation }).div(
15433
+ pow2(denom, exp3, { numericApproximation })
15434
15434
  );
15435
15435
  }
15436
15436
  if (x.operator === "Negate") {
15437
15437
  if (e !== void 0) {
15438
- if (e % 2 === 0) return pow2(x.op1, exp2, { numericApproximation });
15439
- return pow2(x.op1, exp2, { numericApproximation }).neg();
15438
+ if (e % 2 === 0) return pow2(x.op1, exp3, { numericApproximation });
15439
+ return pow2(x.op1, exp3, { numericApproximation }).neg();
15440
15440
  }
15441
15441
  }
15442
15442
  if (x.operator === "Sqrt") {
15443
15443
  if (e === 2) return x.op1;
15444
15444
  if (e !== void 0 && e % 2 === 0) return x.op1.pow(e / 2);
15445
- return pow2(x.op1, exp2, { numericApproximation }).sqrt();
15445
+ return pow2(x.op1, exp3, { numericApproximation }).sqrt();
15446
15446
  }
15447
15447
  if (x.operator === "Exp")
15448
- return pow2(ce.E, x.op1.mul(exp2), { numericApproximation });
15448
+ return pow2(ce.E, x.op1.mul(exp3), { numericApproximation });
15449
15449
  if (x.operator === "Multiply") {
15450
- const ops = x.ops.map((x2) => pow2(x2, exp2, { numericApproximation }));
15450
+ const ops = x.ops.map((x2) => pow2(x2, exp3, { numericApproximation }));
15451
15451
  return ce._fn("Multiply", ops);
15452
15452
  }
15453
- if (typeof exp2 !== "number" && exp2.isNumberLiteral) {
15454
- const r = asRational(exp2);
15453
+ if (typeof exp3 !== "number" && exp3.isNumberLiteral) {
15454
+ const r = asRational(exp3);
15455
15455
  if (r !== void 0 && r[0] === 1)
15456
15456
  return root(x, ce.number(r[1]), { numericApproximation });
15457
15457
  }
15458
15458
  if (x.operator === "Root") {
15459
15459
  const [base, root2] = x.ops;
15460
- return pow2(base, ce.box(exp2).div(root2), { numericApproximation });
15460
+ return pow2(base, ce.box(exp3).div(root2), { numericApproximation });
15461
15461
  }
15462
15462
  if (x.isNumberLiteral && Number.isInteger(e)) {
15463
15463
  const n = x.numericValue;
@@ -15467,37 +15467,37 @@ function pow2(x, exp2, { numericApproximation }) {
15467
15467
  (x2) => Math.pow(x2, e),
15468
15468
  (x2) => x2.pow(e),
15469
15469
  (x2) => x2.pow(e)
15470
- ) ?? ce._fn("Power", [x, ce.box(exp2)]);
15470
+ ) ?? ce._fn("Power", [x, ce.box(exp3)]);
15471
15471
  } else {
15472
15472
  return ce.number(n.pow(e));
15473
15473
  }
15474
15474
  }
15475
- return ce._fn("Power", [x, ce.box(exp2)]);
15475
+ return ce._fn("Power", [x, ce.box(exp3)]);
15476
15476
  }
15477
15477
  function root(a, b, { numericApproximation }) {
15478
15478
  if (!a.isCanonical || !b.isCanonical)
15479
15479
  return a.engine._fn("Root", [a, b], { canonical: false });
15480
15480
  if (numericApproximation) {
15481
15481
  if (a.isNumberLiteral && b.isNumberLiteral) {
15482
- const isNegative = a.isNegative;
15482
+ const isNegative2 = a.isNegative;
15483
15483
  const isEven = b.isEven;
15484
- if (isNegative) a = a.neg();
15484
+ if (isNegative2) a = a.neg();
15485
15485
  return apply2(
15486
15486
  a,
15487
15487
  b,
15488
15488
  (a2, b2) => {
15489
15489
  const result = Math.pow(a2, 1 / b2);
15490
- if (isNegative && !isEven) return -result;
15490
+ if (isNegative2 && !isEven) return -result;
15491
15491
  return result;
15492
15492
  },
15493
15493
  (a2, b2) => {
15494
15494
  const result = a2.pow(b2.pow(-1));
15495
- if (isNegative && !isEven) return result.neg();
15495
+ if (isNegative2 && !isEven) return result.neg();
15496
15496
  return result;
15497
15497
  },
15498
15498
  (a2, b2) => {
15499
15499
  const result = a2.pow(typeof b2 === "number" ? 1 / b2 : b2.inverse());
15500
- if (isNegative && !isEven) return result.neg();
15500
+ if (isNegative2 && !isEven) return result.neg();
15501
15501
  return result;
15502
15502
  }
15503
15503
  ) ?? root(a, b, { numericApproximation: false });
@@ -15843,7 +15843,7 @@ var init_product = __esm({
15843
15843
  * If `this._isCanonical` a running product of exact terms is kept.
15844
15844
  * Otherwise, terms and their exponent are tallied.
15845
15845
  */
15846
- mul(term, exp2) {
15846
+ mul(term, exp3) {
15847
15847
  console.assert(term.isCanonical || term.isStructural);
15848
15848
  if (this.coefficient.isNaN) return;
15849
15849
  if (term.isNaN) {
@@ -15851,17 +15851,17 @@ var init_product = __esm({
15851
15851
  return;
15852
15852
  }
15853
15853
  if (term.operator === "Multiply") {
15854
- for (const t of term.ops) this.mul(t, exp2);
15854
+ for (const t of term.ops) this.mul(t, exp3);
15855
15855
  return;
15856
15856
  }
15857
15857
  if (term.operator === "Negate") {
15858
- this.mul(term.op1, exp2);
15858
+ this.mul(term.op1, exp3);
15859
15859
  this.coefficient = this.coefficient.neg();
15860
15860
  return;
15861
15861
  }
15862
15862
  if (this._isCanonical) {
15863
15863
  if (term.symbol === "Nothing") return;
15864
- exp2 ??= [1, 1];
15864
+ exp3 ??= [1, 1];
15865
15865
  const num = term.numericValue;
15866
15866
  if (num !== null) {
15867
15867
  if (term.is(1)) return;
@@ -15870,14 +15870,14 @@ var init_product = __esm({
15870
15870
  this.coefficient = this.engine._numericValue(NaN);
15871
15871
  return;
15872
15872
  }
15873
- this.coefficient = this.engine._numericValue(isZero(exp2) ? NaN : 0);
15873
+ this.coefficient = this.engine._numericValue(isZero(exp3) ? NaN : 0);
15874
15874
  return;
15875
15875
  }
15876
15876
  if (term.is(-1)) {
15877
- if (isOne(exp2)) this.coefficient = this.coefficient.neg();
15877
+ if (isOne(exp3)) this.coefficient = this.coefficient.neg();
15878
15878
  else {
15879
15879
  this.coefficient = this.coefficient.mul(
15880
- this.engine._numericValue(-1).pow(this.engine._numericValue(exp2))
15880
+ this.engine._numericValue(-1).pow(this.engine._numericValue(exp3))
15881
15881
  );
15882
15882
  }
15883
15883
  return;
@@ -15887,21 +15887,21 @@ var init_product = __esm({
15887
15887
  this.coefficient = this.engine._numericValue(NaN);
15888
15888
  return;
15889
15889
  }
15890
- if (isOne(exp2)) {
15890
+ if (isOne(exp3)) {
15891
15891
  const coefSign = this.coefficient.sgn();
15892
15892
  const termSign = term.isNegative ? -1 : 1;
15893
15893
  const resultSign = coefSign * termSign;
15894
15894
  this.coefficient = this.engine._numericValue(
15895
15895
  resultSign < 0 ? -Infinity : Infinity
15896
15896
  );
15897
- } else this.terms.push({ term, exponent: exp2 });
15897
+ } else this.terms.push({ term, exponent: exp3 });
15898
15898
  return;
15899
15899
  }
15900
- if (isOne(exp2)) {
15900
+ if (isOne(exp3)) {
15901
15901
  this.coefficient = this.coefficient.mul(num);
15902
15902
  } else
15903
15903
  this.coefficient = this.coefficient.mul(
15904
- this.engine._numericValue(num).pow(this.engine._numericValue(exp2))
15904
+ this.engine._numericValue(num).pow(this.engine._numericValue(exp3))
15905
15905
  );
15906
15906
  return;
15907
15907
  }
@@ -15911,7 +15911,7 @@ var init_product = __esm({
15911
15911
  this.engine._numericValue({
15912
15912
  radical: radical[0] * radical[1],
15913
15913
  rational: [1, Number(radical[1])]
15914
- }).pow(this.engine._numericValue(exp2))
15914
+ }).pow(this.engine._numericValue(exp3))
15915
15915
  );
15916
15916
  return;
15917
15917
  }
@@ -15920,20 +15920,20 @@ var init_product = __esm({
15920
15920
  if (!isSymbolicRadical) {
15921
15921
  let coef;
15922
15922
  [coef, term] = term.toNumericValue();
15923
- if (exp2 && !isOne(exp2))
15924
- coef = coef.pow(this.engine._numericValue(exp2));
15923
+ if (exp3 && !isOne(exp3))
15924
+ coef = coef.pow(this.engine._numericValue(exp3));
15925
15925
  this.coefficient = this.coefficient.mul(coef);
15926
15926
  }
15927
15927
  }
15928
15928
  }
15929
- if (term.is(1) && (!exp2 || isOne(exp2))) return;
15930
- if (term.is(0) === false && exp2 && isZero(exp2)) return;
15929
+ if (term.is(1) && (!exp3 || isOne(exp3))) return;
15930
+ if (term.is(0) === false && exp3 && isZero(exp3)) return;
15931
15931
  if (term.is(0)) {
15932
- if (exp2 && isZero(exp2)) this.coefficient = this.engine._numericValue(NaN);
15932
+ if (exp3 && isZero(exp3)) this.coefficient = this.engine._numericValue(NaN);
15933
15933
  else this.coefficient = this.engine._numericValue(0);
15934
15934
  return;
15935
15935
  }
15936
- const exponent = exp2 ?? [1, 1];
15936
+ const exponent = exp3 ?? [1, 1];
15937
15937
  if (term.operator === "Power") {
15938
15938
  const r = asRational(term.op2);
15939
15939
  if (r) {
@@ -16133,8 +16133,8 @@ function serializeSubtract(ce, a, b, options, metadata) {
16133
16133
  function serializePrettyJsonFunction(ce, name, args, options, metadata) {
16134
16134
  const exclusions = options.exclude;
16135
16135
  if (name === "Add" && args.length === 2 && !exclusions.includes("Subtract")) {
16136
- const sub2 = serializeSubtract(ce, args[0], args[1], options, metadata) ?? serializeSubtract(ce, args[1], args[0], options, metadata);
16137
- if (sub2) return sub2;
16136
+ const sub3 = serializeSubtract(ce, args[0], args[1], options, metadata) ?? serializeSubtract(ce, args[1], args[0], options, metadata);
16137
+ if (sub3) return sub3;
16138
16138
  }
16139
16139
  if (name === "Divide" && args.length === 2 && exclusions.includes("Divide")) {
16140
16140
  return serializeJsonFunction(
@@ -16175,8 +16175,8 @@ function serializePrettyJsonFunction(ce, name, args, options, metadata) {
16175
16175
  if (!exclusions.includes("Exp") && args[0]?.symbol === "ExponentialE")
16176
16176
  return serializeJsonFunction(ce, "Exp", [args[1]], options, metadata);
16177
16177
  if (args[1]?.numericValue !== null) {
16178
- const exp2 = asSmallInteger(args[1]);
16179
- if (exp2 === 2 && !exclusions.includes("Square"))
16178
+ const exp3 = asSmallInteger(args[1]);
16179
+ if (exp3 === 2 && !exclusions.includes("Square"))
16180
16180
  return serializeJsonFunction(
16181
16181
  ce,
16182
16182
  "Square",
@@ -16184,11 +16184,11 @@ function serializePrettyJsonFunction(ce, name, args, options, metadata) {
16184
16184
  options,
16185
16185
  metadata
16186
16186
  );
16187
- if (exp2 !== null && exp2 < 0 && !exclusions.includes("Divide")) {
16187
+ if (exp3 !== null && exp3 < 0 && !exclusions.includes("Divide")) {
16188
16188
  return serializeJsonFunction(
16189
16189
  ce,
16190
16190
  "Divide",
16191
- [ce.One, exp2 === -1 ? args[0] : args[0].pow(-exp2)],
16191
+ [ce.One, exp3 === -1 ? args[0] : args[0].pow(-exp3)],
16192
16192
  options,
16193
16193
  metadata
16194
16194
  );
@@ -20527,10 +20527,10 @@ var init_abstract_boxed_expression = __esm({
20527
20527
  div(rhs) {
20528
20528
  return this.engine.NaN;
20529
20529
  }
20530
- pow(exp2) {
20530
+ pow(exp3) {
20531
20531
  return this.engine.NaN;
20532
20532
  }
20533
- root(exp2) {
20533
+ root(exp3) {
20534
20534
  return this.engine.NaN;
20535
20535
  }
20536
20536
  sqrt() {
@@ -21071,7 +21071,7 @@ function parseRule(ce, rule, options) {
21071
21071
  `Invalid rule "${rule}"
21072
21072
  | The condition expression contains wildcards not present in the match expression`
21073
21073
  );
21074
- condFn = (sub2) => condition.subs(sub2).canonical.evaluate()?.symbol === "True";
21074
+ condFn = (sub3) => condition.subs(sub3).canonical.evaluate()?.symbol === "True";
21075
21075
  }
21076
21076
  return boxRule(ce, { match: match2, replace: replace2, condition: condFn, id: rule }, options);
21077
21077
  }
@@ -21217,19 +21217,19 @@ function applyRule(rule, expr, substitution, options) {
21217
21217
  const useVariations = rule.useVariations ?? options?.useVariations ?? false;
21218
21218
  const matchPermutations = options?.matchPermutations ?? true;
21219
21219
  onBeforeMatch?.(rule, expr);
21220
- const sub2 = match2 ? expr.match(match2, {
21220
+ const sub3 = match2 ? expr.match(match2, {
21221
21221
  substitution,
21222
21222
  useVariations,
21223
21223
  recursive: false,
21224
21224
  matchPermutations
21225
21225
  }) : {};
21226
- if (sub2 === null) return operandsMatched ? { value: expr, because } : null;
21226
+ if (sub3 === null) return operandsMatched ? { value: expr, because } : null;
21227
21227
  if (typeof condition === "function") {
21228
21228
  const conditionSub = {
21229
21229
  ...Object.fromEntries(
21230
- Object.entries(sub2).map(([k, v]) => [k.slice(1), v])
21230
+ Object.entries(sub3).map(([k, v]) => [k.slice(1), v])
21231
21231
  ),
21232
- ...sub2
21232
+ ...sub3
21233
21233
  };
21234
21234
  try {
21235
21235
  if (!condition(conditionSub, expr.engine))
@@ -21246,7 +21246,7 @@ function applyRule(rule, expr, substitution, options) {
21246
21246
  }
21247
21247
  if (!canonical2 && options?.canonical === void 0 && replace2 instanceof _BoxedExpression && replace2.isCanonical)
21248
21248
  canonical2 = true;
21249
- const result = typeof replace2 === "function" ? replace2(expr, sub2) : replace2.subs(sub2, { canonical: canonical2 });
21249
+ const result = typeof replace2 === "function" ? replace2(expr, sub3) : replace2.subs(sub3, { canonical: canonical2 });
21250
21250
  if (!result) return null;
21251
21251
  onMatch?.(rule, expr, result);
21252
21252
  if (isRuleStep(result))
@@ -21291,10 +21291,10 @@ ${e.message}`);
21291
21291
  }
21292
21292
  return steps;
21293
21293
  }
21294
- function matchAnyRules(expr, rules, sub2, options) {
21294
+ function matchAnyRules(expr, rules, sub3, options) {
21295
21295
  const results = [];
21296
21296
  for (const rule of rules.rules) {
21297
- const r = applyRule(rule, expr, sub2, options);
21297
+ const r = applyRule(rule, expr, sub3, options);
21298
21298
  if (r !== null && !results.some((x) => x.isSame(r.value)))
21299
21299
  results.push(r.value);
21300
21300
  }
@@ -21391,8 +21391,8 @@ var init_rules = __esm({
21391
21391
  });
21392
21392
 
21393
21393
  // src/compute-engine/boxed-expression/solve.ts
21394
- function filter(sub2) {
21395
- for (const [k, v] of Object.entries(sub2)) {
21394
+ function filter(sub3) {
21395
+ for (const [k, v] of Object.entries(sub3)) {
21396
21396
  if (k !== "x" && k !== "_x" && v.has("_x")) return false;
21397
21397
  }
21398
21398
  return true;
@@ -21786,7 +21786,7 @@ var init_solve = __esm({
21786
21786
  ["Divide", 1, "_n"]
21787
21787
  ],
21788
21788
  useVariations: true,
21789
- condition: (sub2) => filter(sub2) && !sub2._n.is(0)
21789
+ condition: (sub3) => filter(sub3) && !sub3._n.is(0)
21790
21790
  },
21791
21791
  {
21792
21792
  match: ["Add", ["Multiply", "_a", ["Power", "_x", "_n"]], "__b"],
@@ -21795,7 +21795,7 @@ var init_solve = __esm({
21795
21795
  ["Power", ["Divide", ["Negate", "__b"], "_a"], ["Divide", 1, "_n"]]
21796
21796
  ],
21797
21797
  useVariations: true,
21798
- condition: (sub2) => filter(sub2) && !sub2._n.is(0) && (sub2._n.isEven ?? false)
21798
+ condition: (sub3) => filter(sub3) && !sub3._n.is(0) && (sub3._n.isEven ?? false)
21799
21799
  },
21800
21800
  //
21801
21801
  // Quadratic without constant: ax^2 + bx = 0
@@ -21877,7 +21877,7 @@ var init_solve = __esm({
21877
21877
  useVariations: true,
21878
21878
  onBeforeMatch: () => {
21879
21879
  },
21880
- condition: (sub2) => filter(sub2) && (sub2._a.isPositive ?? false) && (sub2.__b.isNegative ?? false)
21880
+ condition: (sub3) => filter(sub3) && (sub3._a.isPositive ?? false) && (sub3.__b.isNegative ?? false)
21881
21881
  },
21882
21882
  // a * e^(bx) + c = 0
21883
21883
  {
@@ -21888,42 +21888,42 @@ var init_solve = __esm({
21888
21888
  ],
21889
21889
  replace: ["Divide", ["Ln", ["Negate", ["Divide", "__c", "__a"]]], "__b"],
21890
21890
  useVariations: true,
21891
- condition: (sub2) => filter(sub2) && ((!sub2.__a.is(0) && sub2.__c.div(sub2.__a).isNegative) ?? false)
21891
+ condition: (sub3) => filter(sub3) && ((!sub3.__a.is(0) && sub3.__c.div(sub3.__a).isNegative) ?? false)
21892
21892
  },
21893
21893
  // a * e^(x) + c = 0
21894
21894
  {
21895
21895
  match: ["Add", ["Multiply", "__a", ["Exp", "_x"]], "__c"],
21896
21896
  replace: ["Ln", ["Negate", ["Divide", "__c", "__a"]]],
21897
21897
  useVariations: true,
21898
- condition: (sub2) => filter(sub2) && ((!sub2.__a.is(0) && sub2.__c.div(sub2.__a).isNegative) ?? false) && !sub2.__a.has("_x") && !sub2.__c.has("_x")
21898
+ condition: (sub3) => filter(sub3) && ((!sub3.__a.is(0) && sub3.__c.div(sub3.__a).isNegative) ?? false) && !sub3.__a.has("_x") && !sub3.__c.has("_x")
21899
21899
  },
21900
21900
  // e^(x) + c = 0
21901
21901
  {
21902
21902
  match: ["Add", ["Exp", "_x"], "__c"],
21903
21903
  replace: ["Ln", ["Negate", "__c"]],
21904
21904
  useVariations: true,
21905
- condition: (sub2) => filter(sub2) && (sub2.__c.isNegative ?? false)
21905
+ condition: (sub3) => filter(sub3) && (sub3.__c.isNegative ?? false)
21906
21906
  },
21907
21907
  // e^(bx) + c = 0
21908
21908
  {
21909
21909
  match: ["Add", ["Exp", ["Multiply", "__b", "_x"]], "__c"],
21910
21910
  replace: ["Divide", ["Ln", ["Negate", "__c"]], "__b"],
21911
21911
  useVariations: true,
21912
- condition: (sub2) => filter(sub2) && (sub2.__c.isNegative ?? false)
21912
+ condition: (sub3) => filter(sub3) && (sub3.__c.isNegative ?? false)
21913
21913
  },
21914
21914
  // a * log_b(x) + c = 0
21915
21915
  {
21916
21916
  match: ["Add", ["Multiply", "__a", ["Log", "_x", "__b"]], "__c"],
21917
21917
  replace: ["Power", "__b", ["Negate", ["Divide", "__c", "__a"]]],
21918
21918
  useVariations: true,
21919
- condition: (sub2) => (filter(sub2) && !sub2.__a.is(0) && sub2.__b.isPositive) ?? false
21919
+ condition: (sub3) => (filter(sub3) && !sub3.__a.is(0) && sub3.__b.isPositive) ?? false
21920
21920
  },
21921
21921
  // a * log_b(x) = 0
21922
21922
  {
21923
21923
  match: ["Multiply", "__a", ["Log", "_x", "__b"]],
21924
21924
  replace: ["Power", "__b", ["Negate", ["Divide", "__c", "__a"]]],
21925
21925
  useVariations: true,
21926
- condition: (sub2) => (filter(sub2) && !sub2.__a.is(0) && sub2.__b.isPositive) ?? false
21926
+ condition: (sub3) => (filter(sub3) && !sub3.__a.is(0) && sub3.__b.isPositive) ?? false
21927
21927
  },
21928
21928
  // |ax + b| + c = 0
21929
21929
  {
@@ -22053,10 +22053,10 @@ var init_solve = __esm({
22053
22053
  match: ["Add", ["Multiply", "__a", ["Sqrt", "_x"]], "__b"],
22054
22054
  replace: ["Square", ["Divide", ["Negate", "__b"], "__a"]],
22055
22055
  useVariations: true,
22056
- condition: (sub2) => {
22057
- if (!filter(sub2)) return false;
22058
- const a = sub2.__a;
22059
- const b = sub2.__b;
22056
+ condition: (sub3) => {
22057
+ if (!filter(sub3)) return false;
22058
+ const a = sub3.__a;
22059
+ const b = sub3.__b;
22060
22060
  if (!a || !b) return false;
22061
22061
  const ratio = b.div(a);
22062
22062
  return ratio.isNonPositive ?? true;
@@ -22088,10 +22088,10 @@ var init_solve = __esm({
22088
22088
  match: ["Add", ["Multiply", "__a", ["Sin", "_x"]], "__b"],
22089
22089
  replace: ["Arcsin", ["Divide", ["Negate", "__b"], "__a"]],
22090
22090
  useVariations: true,
22091
- condition: (sub2) => {
22092
- if (!filter(sub2)) return false;
22093
- const a = sub2.__a;
22094
- const b = sub2.__b;
22091
+ condition: (sub3) => {
22092
+ if (!filter(sub3)) return false;
22093
+ const a = sub3.__a;
22094
+ const b = sub3.__b;
22095
22095
  if (!a || a.is(0)) return false;
22096
22096
  const ratio = b.div(a).neg();
22097
22097
  const val = ratio.numericValue;
@@ -22109,10 +22109,10 @@ var init_solve = __esm({
22109
22109
  ["Arcsin", ["Divide", ["Negate", "__b"], "__a"]]
22110
22110
  ],
22111
22111
  useVariations: true,
22112
- condition: (sub2) => {
22113
- if (!filter(sub2)) return false;
22114
- const a = sub2.__a;
22115
- const b = sub2.__b;
22112
+ condition: (sub3) => {
22113
+ if (!filter(sub3)) return false;
22114
+ const a = sub3.__a;
22115
+ const b = sub3.__b;
22116
22116
  if (!a || a.is(0)) return false;
22117
22117
  const ratio = b.div(a).neg();
22118
22118
  const val = ratio.numericValue;
@@ -22126,9 +22126,9 @@ var init_solve = __esm({
22126
22126
  match: ["Add", ["Sin", "_x"], "__b"],
22127
22127
  replace: ["Arcsin", ["Negate", "__b"]],
22128
22128
  useVariations: true,
22129
- condition: (sub2) => {
22130
- if (!filter(sub2)) return false;
22131
- const b = sub2.__b;
22129
+ condition: (sub3) => {
22130
+ if (!filter(sub3)) return false;
22131
+ const b = sub3.__b;
22132
22132
  const val = b.numericValue;
22133
22133
  if (val === null) return true;
22134
22134
  if (typeof val === "number") return Math.abs(val) <= 1;
@@ -22140,9 +22140,9 @@ var init_solve = __esm({
22140
22140
  match: ["Add", ["Sin", "_x"], "__b"],
22141
22141
  replace: ["Subtract", "Pi", ["Arcsin", ["Negate", "__b"]]],
22142
22142
  useVariations: true,
22143
- condition: (sub2) => {
22144
- if (!filter(sub2)) return false;
22145
- const b = sub2.__b;
22143
+ condition: (sub3) => {
22144
+ if (!filter(sub3)) return false;
22145
+ const b = sub3.__b;
22146
22146
  const val = b.numericValue;
22147
22147
  if (val === null) return true;
22148
22148
  if (typeof val === "number") return Math.abs(val) <= 1;
@@ -22155,10 +22155,10 @@ var init_solve = __esm({
22155
22155
  match: ["Add", ["Multiply", "__a", ["Cos", "_x"]], "__b"],
22156
22156
  replace: ["Arccos", ["Divide", ["Negate", "__b"], "__a"]],
22157
22157
  useVariations: true,
22158
- condition: (sub2) => {
22159
- if (!filter(sub2)) return false;
22160
- const a = sub2.__a;
22161
- const b = sub2.__b;
22158
+ condition: (sub3) => {
22159
+ if (!filter(sub3)) return false;
22160
+ const a = sub3.__a;
22161
+ const b = sub3.__b;
22162
22162
  if (!a || a.is(0)) return false;
22163
22163
  const ratio = b.div(a).neg();
22164
22164
  const val = ratio.numericValue;
@@ -22172,10 +22172,10 @@ var init_solve = __esm({
22172
22172
  match: ["Add", ["Multiply", "__a", ["Cos", "_x"]], "__b"],
22173
22173
  replace: ["Negate", ["Arccos", ["Divide", ["Negate", "__b"], "__a"]]],
22174
22174
  useVariations: true,
22175
- condition: (sub2) => {
22176
- if (!filter(sub2)) return false;
22177
- const a = sub2.__a;
22178
- const b = sub2.__b;
22175
+ condition: (sub3) => {
22176
+ if (!filter(sub3)) return false;
22177
+ const a = sub3.__a;
22178
+ const b = sub3.__b;
22179
22179
  if (!a || a.is(0)) return false;
22180
22180
  const ratio = b.div(a).neg();
22181
22181
  const val = ratio.numericValue;
@@ -22189,9 +22189,9 @@ var init_solve = __esm({
22189
22189
  match: ["Add", ["Cos", "_x"], "__b"],
22190
22190
  replace: ["Arccos", ["Negate", "__b"]],
22191
22191
  useVariations: true,
22192
- condition: (sub2) => {
22193
- if (!filter(sub2)) return false;
22194
- const b = sub2.__b;
22192
+ condition: (sub3) => {
22193
+ if (!filter(sub3)) return false;
22194
+ const b = sub3.__b;
22195
22195
  const val = b.numericValue;
22196
22196
  if (val === null) return true;
22197
22197
  if (typeof val === "number") return Math.abs(val) <= 1;
@@ -22203,9 +22203,9 @@ var init_solve = __esm({
22203
22203
  match: ["Add", ["Cos", "_x"], "__b"],
22204
22204
  replace: ["Negate", ["Arccos", ["Negate", "__b"]]],
22205
22205
  useVariations: true,
22206
- condition: (sub2) => {
22207
- if (!filter(sub2)) return false;
22208
- const b = sub2.__b;
22206
+ condition: (sub3) => {
22207
+ if (!filter(sub3)) return false;
22208
+ const b = sub3.__b;
22209
22209
  const val = b.numericValue;
22210
22210
  if (val === null) return true;
22211
22211
  if (typeof val === "number") return Math.abs(val) <= 1;
@@ -22218,9 +22218,9 @@ var init_solve = __esm({
22218
22218
  match: ["Add", ["Multiply", "__a", ["Tan", "_x"]], "__b"],
22219
22219
  replace: ["Arctan", ["Divide", ["Negate", "__b"], "__a"]],
22220
22220
  useVariations: true,
22221
- condition: (sub2) => {
22222
- if (!filter(sub2)) return false;
22223
- return !sub2.__a.is(0);
22221
+ condition: (sub3) => {
22222
+ if (!filter(sub3)) return false;
22223
+ return !sub3.__a.is(0);
22224
22224
  }
22225
22225
  },
22226
22226
  // tan(x) + b = 0 => x = arctan(-b) (when a = 1)
@@ -22235,9 +22235,9 @@ var init_solve = __esm({
22235
22235
  match: ["Add", ["Multiply", "__a", ["Cot", "_x"]], "__b"],
22236
22236
  replace: ["Arccot", ["Divide", ["Negate", "__b"], "__a"]],
22237
22237
  useVariations: true,
22238
- condition: (sub2) => {
22239
- if (!filter(sub2)) return false;
22240
- return !sub2.__a.is(0);
22238
+ condition: (sub3) => {
22239
+ if (!filter(sub3)) return false;
22240
+ return !sub3.__a.is(0);
22241
22241
  }
22242
22242
  },
22243
22243
  // cot(x) + b = 0 => x = arccot(-b)
@@ -24165,11 +24165,11 @@ function erf(x) {
24165
24165
  const a4 = -1.453152027;
24166
24166
  const a5 = 1.061405429;
24167
24167
  const p = 0.3275911;
24168
- const sign2 = x < 0 ? -1 : 1;
24168
+ const sign3 = x < 0 ? -1 : 1;
24169
24169
  x = Math.abs(x);
24170
24170
  const t = 1 / (1 + p * x);
24171
24171
  const y = ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t;
24172
- return sign2 * (1 - y * Math.exp(-x * x));
24172
+ return sign3 * (1 - y * Math.exp(-x * x));
24173
24173
  }
24174
24174
  function bigGammaln(ce, z) {
24175
24175
  if (z.isNegative()) return ce._BIGNUM_NAN;
@@ -25005,19 +25005,19 @@ var init_arithmetic = __esm({
25005
25005
  broadcastable: true,
25006
25006
  complexity: 3500,
25007
25007
  signature: "(number, number) -> number",
25008
- type: ([base, exp2]) => {
25009
- if (base.isNaN || exp2.isNaN) return "number";
25010
- if (!exp2.isFinite) return "non_finite_number";
25011
- if (base.isInteger && exp2.isInteger) return "finite_integer";
25012
- if (base.isRational && exp2.isInteger) return "finite_rational";
25013
- if (base.isReal && exp2.isReal) return "finite_real";
25008
+ type: ([base, exp3]) => {
25009
+ if (base.isNaN || exp3.isNaN) return "number";
25010
+ if (!exp3.isFinite) return "non_finite_number";
25011
+ if (base.isInteger && exp3.isInteger) return "finite_integer";
25012
+ if (base.isRational && exp3.isInteger) return "finite_rational";
25013
+ if (base.isReal && exp3.isReal) return "finite_real";
25014
25014
  return "finite_number";
25015
25015
  },
25016
25016
  canonical: (args, { engine }) => {
25017
25017
  args = checkNumericArgs(engine, args, 2);
25018
25018
  if (args.length !== 2) return engine._fn("Power", args);
25019
- const [base, exp2] = args;
25020
- return canonicalPower(base, exp2);
25019
+ const [base, exp3] = args;
25020
+ return canonicalPower(base, exp3);
25021
25021
  },
25022
25022
  sgn: ([a, b]) => {
25023
25023
  const aSgn = a.sgn;
@@ -25090,13 +25090,13 @@ var init_arithmetic = __esm({
25090
25090
  complexity: 3200,
25091
25091
  broadcastable: true,
25092
25092
  signature: "(number, number) -> number",
25093
- type: ([base, exp2]) => {
25094
- if (base.isNaN || exp2.isNaN) return "number";
25095
- if (base.isFinite === false || exp2.isFinite === false)
25093
+ type: ([base, exp3]) => {
25094
+ if (base.isNaN || exp3.isNaN) return "number";
25095
+ if (base.isFinite === false || exp3.isFinite === false)
25096
25096
  return "non_finite_number";
25097
- if (exp2.is(0)) return "finite_integer";
25098
- if (exp2.is(1)) return base.type;
25099
- if (base.isReal && exp2.isReal) {
25097
+ if (exp3.is(0)) return "finite_integer";
25098
+ if (exp3.is(1)) return base.type;
25099
+ if (base.isReal && exp3.isReal) {
25100
25100
  if (base.isPositive === true) return "finite_real";
25101
25101
  return "finite_number";
25102
25102
  }
@@ -25120,8 +25120,8 @@ var init_arithmetic = __esm({
25120
25120
  },
25121
25121
  canonical: (args, { engine }) => {
25122
25122
  args = checkNumericArgs(engine, args, 2);
25123
- const [base, exp2] = args;
25124
- return canonicalRoot(base, exp2);
25123
+ const [base, exp3] = args;
25124
+ return canonicalRoot(base, exp3);
25125
25125
  },
25126
25126
  evaluate: ([x, n], { numericApproximation }) => root(x, n, { numericApproximation })
25127
25127
  },
@@ -25980,9 +25980,9 @@ function serializeAdd(serializer, expr) {
25980
25980
  for (let i = 2; i < last; i++) {
25981
25981
  arg = ops[i - 1];
25982
25982
  if (serializer.options.prettify) {
25983
- const [newArg, sign2] = unsign(arg);
25983
+ const [newArg, sign3] = unsign(arg);
25984
25984
  const term = serializer.wrap(newArg, ADDITION_PRECEDENCE);
25985
- if (sign2 > 0) {
25985
+ if (sign3 > 0) {
25986
25986
  if (term.startsWith("+") || term.startsWith("-")) result += term;
25987
25987
  else result += "+" + term;
25988
25988
  } else {
@@ -26024,7 +26024,7 @@ function serializeMultiply(serializer, expr) {
26024
26024
  serializer.level += 1;
26025
26025
  return result;
26026
26026
  }
26027
- let isNegative = false;
26027
+ let isNegative2 = false;
26028
26028
  let arg = null;
26029
26029
  const count = nops(expr) + 1;
26030
26030
  let xs = operands(expr);
@@ -26044,11 +26044,11 @@ function serializeMultiply(serializer, expr) {
26044
26044
  term = serializer.serialize(arg);
26045
26045
  if (term === "-1" && !result) {
26046
26046
  result = "";
26047
- isNegative = !isNegative;
26047
+ isNegative2 = !isNegative2;
26048
26048
  } else {
26049
26049
  if (term[0] === "-") {
26050
26050
  term = term.slice(1);
26051
- isNegative = !isNegative;
26051
+ isNegative2 = !isNegative2;
26052
26052
  }
26053
26053
  if (!result) result = term;
26054
26054
  else result = latexTemplate(serializer.options.multiply, result, term);
@@ -26081,7 +26081,7 @@ function serializeMultiply(serializer, expr) {
26081
26081
  }
26082
26082
  if (operator(arg) === "Negate") {
26083
26083
  arg = operand(arg, 1);
26084
- isNegative = !isNegative;
26084
+ isNegative2 = !isNegative2;
26085
26085
  }
26086
26086
  term = serializer.wrap(arg, MULTIPLICATION_PRECEDENCE);
26087
26087
  if (!result) {
@@ -26103,7 +26103,7 @@ function serializeMultiply(serializer, expr) {
26103
26103
  prevWasNumber = false;
26104
26104
  }
26105
26105
  serializer.level += 1;
26106
- return isNegative ? "-" + result : result;
26106
+ return isNegative2 ? "-" + result : result;
26107
26107
  }
26108
26108
  function parseFraction(parser) {
26109
26109
  let numer = parser.parseGroup();
@@ -26207,26 +26207,26 @@ function serializePower(serializer, expr) {
26207
26207
  2
26208
26208
  );
26209
26209
  }
26210
- const exp2 = missingIfEmpty(operand(expr, 2));
26210
+ const exp3 = missingIfEmpty(operand(expr, 2));
26211
26211
  if (name === "Root")
26212
26212
  return serializeRoot(
26213
26213
  serializer,
26214
26214
  serializer.rootStyle(expr, serializer.level - 1),
26215
26215
  base,
26216
- exp2
26216
+ exp3
26217
26217
  );
26218
26218
  if (serializer.options.prettify) {
26219
- const val2 = machineValue(exp2) ?? 1;
26219
+ const val2 = machineValue(exp3) ?? 1;
26220
26220
  if (val2 === -1) {
26221
26221
  return serializer.serialize(["Divide", "1", base]);
26222
26222
  } else if (val2 < 0) {
26223
26223
  return serializer.serialize(["Divide", "1", ["Power", base, -val2]]);
26224
- } else if (operator(exp2) === "Divide" || operator(exp2) === "Rational") {
26225
- const num = machineValue(operand(exp2, 1));
26226
- const denom = machineValue(operand(exp2, 2));
26224
+ } else if (operator(exp3) === "Divide" || operator(exp3) === "Rational") {
26225
+ const num = machineValue(operand(exp3, 1));
26226
+ const denom = machineValue(operand(exp3, 2));
26227
26227
  if (num === 1) {
26228
26228
  const style = serializer.rootStyle(expr, serializer.level);
26229
- return serializeRoot(serializer, style, base, operand(exp2, 2));
26229
+ return serializeRoot(serializer, style, base, operand(exp3, 2));
26230
26230
  }
26231
26231
  if (num === -1) {
26232
26232
  if (denom === 2) {
@@ -26235,18 +26235,18 @@ function serializePower(serializer, expr) {
26235
26235
  return serializer.serialize([
26236
26236
  "Divide",
26237
26237
  "1",
26238
- ["Root", base, operand(exp2, 2)]
26238
+ ["Root", base, operand(exp3, 2)]
26239
26239
  ]);
26240
26240
  }
26241
26241
  if (denom === 2) {
26242
26242
  return `${serializer.serialize(["Sqrt", base])}^{${serializer.serialize(
26243
- operand(exp2, 1)
26243
+ operand(exp3, 1)
26244
26244
  )}}`;
26245
26245
  }
26246
- } else if (operator(exp2) === "Power") {
26247
- if (machineValue(operand(exp2, 2)) === -1) {
26246
+ } else if (operator(exp3) === "Power") {
26247
+ if (machineValue(operand(exp3, 2)) === -1) {
26248
26248
  const style = serializer.rootStyle(expr, serializer.level);
26249
- return serializeRoot(serializer, style, base, operand(exp2, 1));
26249
+ return serializeRoot(serializer, style, base, operand(exp3, 1));
26250
26250
  }
26251
26251
  }
26252
26252
  }
@@ -26257,12 +26257,12 @@ function serializePower(serializer, expr) {
26257
26257
  const baseBodyLatex = wrapNegativeBase(serializer.wrapShort(baseBody));
26258
26258
  const baseExponentLatex = serializer.wrapShort(baseExponent);
26259
26259
  return `
26260
- ${baseBodyLatex}^{${supsub("^", baseExponentLatex, serializer.serialize(exp2))}}`;
26260
+ ${baseBodyLatex}^{${supsub("^", baseExponentLatex, serializer.serialize(exp3))}}`;
26261
26261
  }
26262
26262
  return supsub(
26263
26263
  "^",
26264
26264
  wrapNegativeBase(serializer.wrapShort(base)),
26265
- serializer.serialize(exp2)
26265
+ serializer.serialize(exp3)
26266
26266
  );
26267
26267
  }
26268
26268
  var DEFINITIONS_ARITHMETIC = [
@@ -27079,10 +27079,10 @@ function getSequenceOrTuple(expr) {
27079
27079
  }
27080
27080
  return [expr];
27081
27081
  }
27082
- function getIndexes(sub2, sup) {
27083
- if (isEmptySequence(sub2)) sub2 = null;
27082
+ function getIndexes(sub3, sup) {
27083
+ if (isEmptySequence(sub3)) sub3 = null;
27084
27084
  if (isEmptySequence(sup)) sup = null;
27085
- const subs = getSequenceOrTuple(sub2);
27085
+ const subs = getSequenceOrTuple(sub3);
27086
27086
  const sups = getSequenceOrTuple(sup);
27087
27087
  const results = [];
27088
27088
  let i = 0;
@@ -27116,20 +27116,20 @@ function parseBigOp(name, reduceOp, minPrec) {
27116
27116
  parser.skipSpace();
27117
27117
  parser.pushSymbolTable();
27118
27118
  let sup = null;
27119
- let sub2 = null;
27120
- while (!(sub2 && sup) && (parser.peek === "_" || parser.peek === "^")) {
27121
- if (parser.match("_")) sub2 = parser.parseGroup() ?? parser.parseToken();
27119
+ let sub3 = null;
27120
+ while (!(sub3 && sup) && (parser.peek === "_" || parser.peek === "^")) {
27121
+ if (parser.match("_")) sub3 = parser.parseGroup() ?? parser.parseToken();
27122
27122
  else if (parser.match("^"))
27123
27123
  sup = parser.parseGroup() ?? parser.parseToken();
27124
27124
  parser.skipSpace();
27125
27125
  }
27126
- if (!sup && !sub2) {
27126
+ if (!sup && !sub3) {
27127
27127
  const collection = parser.parseExpression({ minPrec });
27128
27128
  parser.popSymbolTable();
27129
27129
  if (collection) return ["Reduce", collection, reduceOp];
27130
27130
  return null;
27131
27131
  }
27132
- const indexes = getIndexes(sub2, sup);
27132
+ const indexes = getIndexes(sub3, sup);
27133
27133
  const fn = parser.parseExpression({ minPrec });
27134
27134
  parser.popSymbolTable();
27135
27135
  if (fn === null) return [name];
@@ -27223,47 +27223,47 @@ function serializeBigOp(command) {
27223
27223
  };
27224
27224
  }
27225
27225
  function parseLog(command, parser) {
27226
- let sub2 = null;
27227
- if (parser.match("_")) sub2 = parser.parseGroup() ?? parser.parseToken();
27226
+ let sub3 = null;
27227
+ if (parser.match("_")) sub3 = parser.parseGroup() ?? parser.parseToken();
27228
27228
  const args = parser.parseArguments("implicit");
27229
- if (args === null && sub2 === null) return [command];
27230
- if (args === null) return [command, sub2];
27231
- if (sub2 === null) return [command, ...args];
27232
- if (sub2 === 10) return ["Log", args[0]];
27233
- if (sub2 === 2) return ["Lb", ...args];
27234
- return ["Log", args[0], sub2];
27229
+ if (args === null && sub3 === null) return [command];
27230
+ if (args === null) return [command, sub3];
27231
+ if (sub3 === null) return [command, ...args];
27232
+ if (sub3 === 10) return ["Log", args[0]];
27233
+ if (sub3 === 2) return ["Lb", ...args];
27234
+ return ["Log", args[0], sub3];
27235
27235
  }
27236
27236
  function unsign(expr) {
27237
- let sign2 = 1;
27237
+ let sign3 = 1;
27238
27238
  let newExpr = expr;
27239
27239
  do {
27240
27240
  expr = newExpr;
27241
27241
  const fnName = operator(expr);
27242
27242
  if (fnName === "Negate") {
27243
- sign2 *= -1;
27243
+ sign3 *= -1;
27244
27244
  newExpr = operand(expr, 1);
27245
27245
  } else if (fnName === "Multiply") {
27246
27246
  const [first, firstSign] = unsign(operand(expr, 1));
27247
27247
  if (firstSign < 0) {
27248
- sign2 *= -1;
27248
+ sign3 *= -1;
27249
27249
  if (first === 1) newExpr = ["Multiply", ...operands(expr).slice(1)];
27250
27250
  else newExpr = ["Multiply", first, ...operands(expr).slice(1)];
27251
27251
  }
27252
27252
  } else if (fnName === "Divide" || fnName === "Rational") {
27253
27253
  const [numer, numerSign] = unsign(operand(expr, 1));
27254
27254
  if (numerSign < 0) {
27255
- sign2 *= -1;
27255
+ sign3 *= -1;
27256
27256
  newExpr = [fnName, numer, operand(expr, 2)];
27257
27257
  }
27258
27258
  } else {
27259
27259
  const val = machineValue(expr);
27260
27260
  if (val !== null && val < 0) {
27261
- sign2 *= -1;
27261
+ sign3 *= -1;
27262
27262
  newExpr = -val;
27263
27263
  }
27264
27264
  }
27265
27265
  } while (newExpr !== expr);
27266
- return [expr, sign2];
27266
+ return [expr, sign3];
27267
27267
  }
27268
27268
 
27269
27269
  // src/compute-engine/latex-syntax/dictionary/definitions.ts
@@ -28087,26 +28087,26 @@ var DEFINITIONS_OTHERS = [
28087
28087
  parse: (parser) => {
28088
28088
  let done = false;
28089
28089
  let sup = "Nothing";
28090
- let sub2 = "Nothing";
28090
+ let sub3 = "Nothing";
28091
28091
  while (!done) {
28092
28092
  parser.skipSpace();
28093
28093
  if (parser.match("_")) {
28094
- sub2 = parser.parseGroup() ?? parser.parseToken();
28094
+ sub3 = parser.parseGroup() ?? parser.parseToken();
28095
28095
  } else if (parser.match("^")) {
28096
28096
  sup = parser.parseGroup() ?? parser.parseToken();
28097
28097
  } else {
28098
28098
  done = true;
28099
28099
  }
28100
28100
  }
28101
- const seq = getSequence(sub2);
28102
- if (seq) sub2 = ["List", ...seq];
28103
- if (sub2 === null || sup === null) return null;
28101
+ const seq = getSequence(sub3);
28102
+ if (seq) sub3 = ["List", ...seq];
28103
+ if (sub3 === null || sup === null) return null;
28104
28104
  let rhs = parser.parseGroup() ?? "Nothing";
28105
28105
  if (!isEmptySequence(rhs)) {
28106
28106
  const args = parser.parseArguments() ?? ["Nothing"];
28107
28107
  rhs = [rhs, ...args];
28108
28108
  }
28109
- return ["PartialDerivative", rhs, sub2, sup];
28109
+ return ["PartialDerivative", rhs, sub3, sup];
28110
28110
  },
28111
28111
  serialize: (serializer, expr) => {
28112
28112
  let result = "\\partial";
@@ -29337,17 +29337,17 @@ function parseIntegral(command) {
29337
29337
  parser.match("\\limits");
29338
29338
  parser.skipSpace();
29339
29339
  let sup = null;
29340
- let sub2 = null;
29341
- while (!(sub2 !== null && sup !== null) && (parser.peek === "_" || parser.peek === "^")) {
29342
- if (parser.match("_")) sub2 = parser.parseGroup() ?? parser.parseToken();
29340
+ let sub3 = null;
29341
+ while (!(sub3 !== null && sup !== null) && (parser.peek === "_" || parser.peek === "^")) {
29342
+ if (parser.match("_")) sub3 = parser.parseGroup() ?? parser.parseToken();
29343
29343
  else if (parser.match("^")) {
29344
29344
  sup = parser.parseGroup() ?? parser.parseToken();
29345
29345
  }
29346
29346
  parser.skipSpace();
29347
29347
  }
29348
- if (isEmptySequence(sub2)) sub2 = null;
29348
+ if (isEmptySequence(sub3)) sub3 = null;
29349
29349
  if (isEmptySequence(sup)) sup = null;
29350
- subs.push(sub2 ?? "Nothing");
29350
+ subs.push(sub3 ?? "Nothing");
29351
29351
  sups.push(sup ?? "Nothing");
29352
29352
  parser.skipVisualSpace();
29353
29353
  done = !parser.match(command);
@@ -29414,9 +29414,9 @@ function makeIntegral(command, fn, limits) {
29414
29414
  }
29415
29415
  const tuples = indexes.map((idx, i) => {
29416
29416
  const sup = limits.sups[i];
29417
- const sub2 = limits.subs[i];
29418
- if (sub2 === "Nothing" && sup === "Nothing") return idx;
29419
- return ["Tuple", idx, sub2, sup];
29417
+ const sub3 = limits.subs[i];
29418
+ if (sub3 === "Nothing" && sup === "Nothing") return idx;
29419
+ return ["Tuple", idx, sub3, sup];
29420
29420
  });
29421
29421
  return [command, fn, ...tuples];
29422
29422
  }
@@ -30451,9 +30451,9 @@ function parseSymbolBody(parser) {
30451
30451
  while (!parser.atEnd) {
30452
30452
  if (parser.match("_")) {
30453
30453
  const hasBrace = parser.match("<{>");
30454
- const sub2 = parseSymbolBody(parser);
30455
- if (hasBrace && !parser.match("<}>") || sub2 === null) return null;
30456
- subs.push(sub2);
30454
+ const sub3 = parseSymbolBody(parser);
30455
+ if (hasBrace && !parser.match("<}>") || sub3 === null) return null;
30456
+ subs.push(sub3);
30457
30457
  } else if (parser.match("^")) {
30458
30458
  const hasBrace = parser.match("<{>");
30459
30459
  const sup = parseSymbolBody(parser);
@@ -30518,14 +30518,14 @@ function parseSymbol(parser) {
30518
30518
  parser.index = underscoreIndex;
30519
30519
  break;
30520
30520
  }
30521
- const sub2 = parseSymbolBody(parser);
30522
- const hasOperators = sub2 !== null && /plus|minus|times|ast/.test(sub2);
30523
- if (sub2 === null || sub2.includes(",") || hasOperators || parser.peek !== "<}>") {
30521
+ const sub3 = parseSymbolBody(parser);
30522
+ const hasOperators = sub3 !== null && /plus|minus|times|ast/.test(sub3);
30523
+ if (sub3 === null || sub3.includes(",") || hasOperators || parser.peek !== "<}>") {
30524
30524
  parser.index = underscoreIndex;
30525
30525
  break;
30526
30526
  }
30527
30527
  parser.match("<}>");
30528
- id2 += "_" + sub2;
30528
+ id2 += "_" + sub3;
30529
30529
  } else {
30530
30530
  const subToken = parser.peek;
30531
30531
  if (/^[a-zA-Z0-9]$/.test(subToken) || /^\p{XIDS}$/u.test(subToken)) {
@@ -31357,10 +31357,10 @@ var _Parser = class {
31357
31357
  *
31358
31358
  */
31359
31359
  parseOptionalSign() {
31360
- let isNegative = !!this.matchAny(["-", "\u2212"]);
31360
+ let isNegative2 = !!this.matchAny(["-", "\u2212"]);
31361
31361
  while (this.matchAny(["+", "\uFE62"]) || this.skipSpace())
31362
- if (this.matchAny(["-", "\u2212"])) isNegative = !isNegative;
31363
- return isNegative ? "-" : "+";
31362
+ if (this.matchAny(["-", "\u2212"])) isNegative2 = !isNegative2;
31363
+ return isNegative2 ? "-" : "+";
31364
31364
  }
31365
31365
  /** Parse a sequence of decimal digits. The part indicates which
31366
31366
  * grouping separator should be expected.
@@ -31392,9 +31392,9 @@ var _Parser = class {
31392
31392
  */
31393
31393
  parseSignedInteger(part) {
31394
31394
  const start = this.index;
31395
- const sign2 = this.parseOptionalSign();
31395
+ const sign3 = this.parseOptionalSign();
31396
31396
  const result = this.parseDecimalDigits(part);
31397
- if (result) return sign2 === "-" ? "-" + result : result;
31397
+ if (result) return sign3 === "-" ? "-" + result : result;
31398
31398
  this.index = start;
31399
31399
  return "";
31400
31400
  }
@@ -31497,9 +31497,9 @@ var _Parser = class {
31497
31497
  return null;
31498
31498
  const start = this.index;
31499
31499
  this.skipVisualSpace();
31500
- let sign2 = 1;
31500
+ let sign3 = 1;
31501
31501
  while (this.peek === "-" || this.peek === "+") {
31502
- if (this.match("-")) sign2 = -sign2;
31502
+ if (this.match("-")) sign3 = -sign3;
31503
31503
  else this.match("+");
31504
31504
  this.skipVisualSpace();
31505
31505
  }
@@ -31536,34 +31536,66 @@ var _Parser = class {
31536
31536
  if (hasFractionalPart && !fractionalPart) {
31537
31537
  this.index = fractionalIndex;
31538
31538
  if (wholePart.length < 10)
31539
- return numberExpression(sign2 * parseInt(wholePart, 10));
31540
- return { num: sign2 < 0 ? "-" + wholePart : wholePart };
31539
+ return numberExpression(sign3 * parseInt(wholePart, 10));
31540
+ return { num: sign3 < 0 ? "-" + wholePart : wholePart };
31541
31541
  }
31542
31542
  const exponent = this.parseExponent();
31543
31543
  if (!hasFractionalPart && !exponent && wholePart.length < 10)
31544
- return numberExpression(sign2 * parseInt(wholePart, 10));
31544
+ return numberExpression(sign3 * parseInt(wholePart, 10));
31545
31545
  if (!hasRepeatingPart && this.options.parseNumbers === "rational") {
31546
- const whole = parseInt(wholePart, 10);
31546
+ const isLargeInteger = wholePart.length > 16 || wholePart.length === 16 && wholePart > "9007199254740991";
31547
31547
  if (!fractionalPart) {
31548
+ if (isLargeInteger) {
31549
+ const numStr = sign3 < 0 ? "-" + wholePart : wholePart;
31550
+ if (exponent)
31551
+ return ["Multiply", { num: numStr }, ["Power", 10, exponent]];
31552
+ return { num: numStr };
31553
+ }
31554
+ const whole2 = parseInt(wholePart, 10);
31548
31555
  if (exponent)
31549
- return ["Multiply", sign2 * whole, ["Power", 10, exponent]];
31550
- return numberExpression(sign2 * whole);
31556
+ return ["Multiply", sign3 * whole2, ["Power", 10, exponent]];
31557
+ return numberExpression(sign3 * whole2);
31551
31558
  }
31552
- const fraction = parseInt(fractionalPart, 10);
31553
31559
  const n = fractionalPart.length;
31560
+ const numeratorDigits = wholePart.length + n;
31561
+ if (numeratorDigits > 15) {
31562
+ const wholeBig = BigInt(wholePart);
31563
+ const fractionBig = BigInt(fractionalPart);
31564
+ const denominatorBig = BigInt(10) ** BigInt(n);
31565
+ const numeratorBig = wholeBig * denominatorBig + fractionBig;
31566
+ const signedNumerator = sign3 < 0 ? -numeratorBig : numeratorBig;
31567
+ if (exponent) {
31568
+ return [
31569
+ "Multiply",
31570
+ [
31571
+ "Rational",
31572
+ { num: signedNumerator.toString() },
31573
+ Number(denominatorBig)
31574
+ ],
31575
+ ["Power", 10, exponent]
31576
+ ];
31577
+ }
31578
+ return [
31579
+ "Rational",
31580
+ { num: signedNumerator.toString() },
31581
+ Number(denominatorBig)
31582
+ ];
31583
+ }
31584
+ const whole = parseInt(wholePart, 10);
31585
+ const fraction = parseInt(fractionalPart, 10);
31554
31586
  const numerator = whole * 10 ** n + fraction;
31555
31587
  const denominator = 10 ** n;
31556
31588
  if (exponent) {
31557
31589
  return [
31558
31590
  "Multiply",
31559
- ["Rational", sign2 * numerator, denominator],
31591
+ ["Rational", sign3 * numerator, denominator],
31560
31592
  ["Power", 10, exponent]
31561
31593
  ];
31562
31594
  }
31563
- return ["Rational", sign2 * numerator, denominator];
31595
+ return ["Rational", sign3 * numerator, denominator];
31564
31596
  }
31565
31597
  return {
31566
- num: (sign2 < 0 ? "-" : "") + wholePart + (hasFractionalPart ? "." + fractionalPart : "") + (exponent ? "e" + exponent : "")
31598
+ num: (sign3 < 0 ? "-" : "") + wholePart + (hasFractionalPart ? "." + fractionalPart : "") + (exponent ? "e" + exponent : "")
31567
31599
  };
31568
31600
  }
31569
31601
  parsePrefixOperator(until) {
@@ -31889,12 +31921,12 @@ var _Parser = class {
31889
31921
  if (this.match("_") || this.match("^"))
31890
31922
  subscripts.push(this.error("syntax-error", subIndex));
31891
31923
  else {
31892
- let sub2 = this.parseGroup() ?? this.parseToken();
31893
- if (sub2 === null && this.options.strict === false && this.peek === "(")
31894
- sub2 = this.parseEnclosure();
31895
- sub2 ??= this.parseStringGroup();
31896
- if (sub2 === null) return this.error("missing", index);
31897
- subscripts.push(sub2);
31924
+ let sub3 = this.parseGroup() ?? this.parseToken();
31925
+ if (sub3 === null && this.options.strict === false && this.peek === "(")
31926
+ sub3 = this.parseEnclosure();
31927
+ sub3 ??= this.parseStringGroup();
31928
+ if (sub3 === null) return this.error("missing", index);
31929
+ subscripts.push(sub3);
31898
31930
  }
31899
31931
  } else if (this.match("^")) {
31900
31932
  subIndex = this.index;
@@ -33005,8 +33037,8 @@ function tryCyclicExpTrigIntegral(factors, index) {
33005
33037
  }
33006
33038
  return null;
33007
33039
  }
33008
- function filter2(sub2) {
33009
- for (const [k, v] of Object.entries(sub2)) {
33040
+ function filter2(sub3) {
33041
+ for (const [k, v] of Object.entries(sub3)) {
33010
33042
  if (k !== "x" && k !== "_x" && v.has("_x")) return false;
33011
33043
  }
33012
33044
  return true;
@@ -33020,7 +33052,7 @@ var INTEGRATION_RULES = [
33020
33052
  ["Power", ["Add", ["Multiply", "_a", "_x"], "__b"], ["Add", "_n", 1]],
33021
33053
  ["Multiply", "_a", ["Add", "_n", 1]]
33022
33054
  ],
33023
- condition: (sub2) => filter2(sub2) && !sub2._n.is(-1)
33055
+ condition: (sub3) => filter2(sub3) && !sub3._n.is(-1)
33024
33056
  },
33025
33057
  // \sqrt{ax + b} -> \frac{2}{3a} (ax + b)^{3/2}
33026
33058
  {
@@ -33030,7 +33062,7 @@ var INTEGRATION_RULES = [
33030
33062
  ["Multiply", 2, ["Power", ["Add", ["Multiply", "_a", "_x"], "__b"], 3]],
33031
33063
  ["Multiply", 3, "_a"]
33032
33064
  ],
33033
- condition: (sub2) => filter2(sub2) && sub2._a.isNumberLiteral
33065
+ condition: (sub3) => filter2(sub3) && sub3._a.isNumberLiteral
33034
33066
  },
33035
33067
  // \sqrt[3]{ax + b} -> \frac{3}{4a} (ax + b)^{4/3}
33036
33068
  {
@@ -33040,13 +33072,13 @@ var INTEGRATION_RULES = [
33040
33072
  ["Multiply", 3, ["Power", ["Add", ["Multiply", "_a", "_x"], "__b"], 4]],
33041
33073
  ["Multiply", 4, "_a"]
33042
33074
  ],
33043
- condition: (sub2) => filter2(sub2) && sub2._a.isNumberLiteral
33075
+ condition: (sub3) => filter2(sub3) && sub3._a.isNumberLiteral
33044
33076
  },
33045
33077
  // a^x -> \frac{a^x}{\ln(a)} where a is a constant (doesn't contain x)
33046
33078
  {
33047
33079
  match: ["Power", "_a", "_x"],
33048
33080
  replace: ["Divide", ["Power", "_a", "_x"], ["Ln", "_a"]],
33049
- condition: (sub2) => filter2(sub2) && !sub2._a.has("_x")
33081
+ condition: (sub3) => filter2(sub3) && !sub3._a.has("_x")
33050
33082
  },
33051
33083
  // (ax+b)^{-1} -> \ln(ax + b) / a
33052
33084
  {
@@ -33062,7 +33094,7 @@ var INTEGRATION_RULES = [
33062
33094
  {
33063
33095
  match: ["Power", ["Add", "_x", "__b"], -1],
33064
33096
  replace: ["Ln", ["Abs", ["Add", "_x", "__b"]]],
33065
- condition: (sub2) => filter2(sub2) && sub2._x.symbol !== null
33097
+ condition: (sub3) => filter2(sub3) && sub3._x.symbol !== null
33066
33098
  },
33067
33099
  // 1/(ax + b) -> \ln(ax + b) / a
33068
33100
  {
@@ -33078,7 +33110,7 @@ var INTEGRATION_RULES = [
33078
33110
  {
33079
33111
  match: ["Divide", 1, ["Add", "_x", "__b"]],
33080
33112
  replace: ["Ln", ["Abs", ["Add", "_x", "__b"]]],
33081
- condition: (sub2) => filter2(sub2) && sub2._x.symbol !== null
33113
+ condition: (sub3) => filter2(sub3) && sub3._x.symbol !== null
33082
33114
  },
33083
33115
  // \ln(ax + b) -> (ax + b) \ln(ax + b) - ax - b
33084
33116
  {
@@ -33677,7 +33709,7 @@ var INTEGRATION_RULES = [
33677
33709
  ["Exp", "_x"],
33678
33710
  ["Subtract", ["Sin", "_x"], ["Cos", "_x"]]
33679
33711
  ],
33680
- condition: (sub2) => filter2(sub2) && sub2._x.symbol !== null
33712
+ condition: (sub3) => filter2(sub3) && sub3._x.symbol !== null
33681
33713
  },
33682
33714
  // e^x * cos(x) -> (e^x/2)(sin(x) + cos(x))
33683
33715
  {
@@ -33688,7 +33720,7 @@ var INTEGRATION_RULES = [
33688
33720
  ["Exp", "_x"],
33689
33721
  ["Add", ["Sin", "_x"], ["Cos", "_x"]]
33690
33722
  ],
33691
- condition: (sub2) => filter2(sub2) && sub2._x.symbol !== null
33723
+ condition: (sub3) => filter2(sub3) && sub3._x.symbol !== null
33692
33724
  },
33693
33725
  // sin(x) * e^x -> (e^x/2)(sin(x) - cos(x)) (commuted order)
33694
33726
  {
@@ -33699,7 +33731,7 @@ var INTEGRATION_RULES = [
33699
33731
  ["Exp", "_x"],
33700
33732
  ["Subtract", ["Sin", "_x"], ["Cos", "_x"]]
33701
33733
  ],
33702
- condition: (sub2) => filter2(sub2) && sub2._x.symbol !== null
33734
+ condition: (sub3) => filter2(sub3) && sub3._x.symbol !== null
33703
33735
  },
33704
33736
  // cos(x) * e^x -> (e^x/2)(sin(x) + cos(x)) (commuted order)
33705
33737
  {
@@ -33710,7 +33742,7 @@ var INTEGRATION_RULES = [
33710
33742
  ["Exp", "_x"],
33711
33743
  ["Add", ["Sin", "_x"], ["Cos", "_x"]]
33712
33744
  ],
33713
- condition: (sub2) => filter2(sub2) && sub2._x.symbol !== null
33745
+ condition: (sub3) => filter2(sub3) && sub3._x.symbol !== null
33714
33746
  },
33715
33747
  // e^x * sin(ax) -> (e^x/(a² + 1))(sin(ax) - a*cos(ax)) (no constant term)
33716
33748
  {
@@ -34101,8 +34133,8 @@ function antiderivative(fn, index) {
34101
34133
  const denom = fn.op2;
34102
34134
  if (denom.operator === "Power") {
34103
34135
  const base = denom.op1;
34104
- const exp2 = denom.op2;
34105
- const n = exp2.re;
34136
+ const exp3 = denom.op2;
34137
+ const n = exp3.re;
34106
34138
  if (n !== null && Number.isInteger(n) && n > 1) {
34107
34139
  const linearCoeffs = getLinearCoefficients(base, index);
34108
34140
  if (linearCoeffs) {
@@ -34142,8 +34174,8 @@ function antiderivative(fn, index) {
34142
34174
  const denom = fn.op2;
34143
34175
  if (denom.operator === "Power") {
34144
34176
  const base = denom.op1;
34145
- const exp2 = denom.op2;
34146
- const n = exp2.re;
34177
+ const exp3 = denom.op2;
34178
+ const n = exp3.re;
34147
34179
  if (n !== null && Number.isInteger(n) && n > 1) {
34148
34180
  const quadCoeffs = getQuadraticCoefficients(base, index);
34149
34181
  if (quadCoeffs && quadCoeffs.b.is(0) && quadCoeffs.a.is(1)) {
@@ -35266,10 +35298,10 @@ var COMPLEX_LIBRARY = [
35266
35298
  const roots = [];
35267
35299
  const im = ops[0].im ?? 0;
35268
35300
  const arg = Math.atan2(im, re);
35269
- const mod2 = Math.sqrt(re * re + im * im);
35301
+ const mod3 = Math.sqrt(re * re + im * im);
35270
35302
  for (let k = 0; k < n; k++) {
35271
35303
  const theta = (arg + 2 * Math.PI * k) / n;
35272
- const r = Math.pow(mod2, 1 / n);
35304
+ const r = Math.pow(mod3, 1 / n);
35273
35305
  roots.push([r * Math.cos(theta), r * Math.sin(theta)]);
35274
35306
  }
35275
35307
  return ce.function(
@@ -36776,8 +36808,8 @@ var CORE_LIBRARY = [
36776
36808
  if (isValueDef(symbolDef) && symbolDef.value.subscriptEvaluate) {
36777
36809
  return "number";
36778
36810
  }
36779
- const sub2 = op2.string ?? op2.symbol ?? asSmallInteger(op2)?.toString();
36780
- if (sub2) return "symbol";
36811
+ const sub3 = op2.string ?? op2.symbol ?? asSmallInteger(op2)?.toString();
36812
+ if (sub3) return "symbol";
36781
36813
  if (op2.operator === "InvisibleOperator" && op2.ops) {
36782
36814
  const parts = op2.ops.map(
36783
36815
  (x) => x.symbol ?? asSmallInteger(x)?.toString()
@@ -36818,8 +36850,8 @@ var CORE_LIBRARY = [
36818
36850
  }
36819
36851
  }
36820
36852
  if (op1.symbol) {
36821
- const sub3 = op2.string ?? op2.symbol ?? asSmallInteger(op2)?.toString();
36822
- if (sub3) return ce.symbol(op1.symbol + "_" + sub3);
36853
+ const sub4 = op2.string ?? op2.symbol ?? asSmallInteger(op2)?.toString();
36854
+ if (sub4) return ce.symbol(op1.symbol + "_" + sub4);
36823
36855
  if (op2.operator === "InvisibleOperator" && op2.ops) {
36824
36856
  const parts = op2.ops.map(
36825
36857
  (x) => x.symbol ?? asSmallInteger(x)?.toString()
@@ -36831,9 +36863,9 @@ var CORE_LIBRARY = [
36831
36863
  }
36832
36864
  if (op2.operator === "Sequence")
36833
36865
  ce._fn("Subscript", [op1, ce._fn("List", op2.ops)]);
36834
- let sub2 = op2;
36835
- if (op2.operator === "Delimiter" && op2.op1) sub2 = op2.op1.canonical;
36836
- return ce._fn("Subscript", [op1, sub2]);
36866
+ let sub3 = op2;
36867
+ if (op2.operator === "Delimiter" && op2.op1) sub3 = op2.op1.canonical;
36868
+ return ce._fn("Subscript", [op1, sub3]);
36837
36869
  },
36838
36870
  evaluate: (ops, { engine: ce, numericApproximation }) => {
36839
36871
  const [base, subscript] = ops;
@@ -36895,11 +36927,11 @@ var CORE_LIBRARY = [
36895
36927
  timings.push(1e3 * (globalThis.performance.now() - start));
36896
36928
  n -= 1;
36897
36929
  }
36898
- const max2 = Math.max(...timings);
36899
- const min2 = Math.min(...timings);
36900
- timings = timings.filter((x) => x > min2 && x < max2);
36930
+ const max3 = Math.max(...timings);
36931
+ const min3 = Math.min(...timings);
36932
+ timings = timings.filter((x) => x > min3 && x < max3);
36901
36933
  const sum2 = timings.reduce((acc, v) => acc + v, 0);
36902
- if (sum2 === 0) return ce.tuple(ce.number(max2), result);
36934
+ if (sum2 === 0) return ce.tuple(ce.number(max3), result);
36903
36935
  return ce.tuple(ce.number(sum2 / timings.length), result);
36904
36936
  }
36905
36937
  }
@@ -38011,8 +38043,8 @@ function computeQR(M, m, n, ce) {
38011
38043
  }
38012
38044
  norm = Math.sqrt(norm);
38013
38045
  if (norm < 1e-10) continue;
38014
- const sign2 = R[k][k] >= 0 ? 1 : -1;
38015
- const u0 = R[k][k] + sign2 * norm;
38046
+ const sign3 = R[k][k] >= 0 ? 1 : -1;
38047
+ const u0 = R[k][k] + sign3 * norm;
38016
38048
  const v = Array(m).fill(0);
38017
38049
  v[k] = 1;
38018
38050
  for (let i = k + 1; i < m; i++) {
@@ -39127,8 +39159,8 @@ var NUMBER_THEORY_LIBRARY = [
39127
39159
  const pent1 = k * (3n * k - 1n) / 2n;
39128
39160
  const pent2 = k * (3n * k + 1n) / 2n;
39129
39161
  if (pent1 > n2 && pent2 > n2) break;
39130
- const sign2 = k % 2n === 0n ? -1n : 1n;
39131
- total += sign2 * (P2(n2 - pent1) + P2(n2 - pent2));
39162
+ const sign3 = k % 2n === 0n ? -1n : 1n;
39163
+ total += sign3 * (P2(n2 - pent1) + P2(n2 - pent2));
39132
39164
  }
39133
39165
  memo.set(n2, total);
39134
39166
  return total;
@@ -39143,9 +39175,9 @@ var NUMBER_THEORY_LIBRARY = [
39143
39175
  const k = toBigint(n);
39144
39176
  if (k === null || k < 1n) return ce.False;
39145
39177
  const D = 8n * k + 1n;
39146
- const sqrt2 = BigInt(decimal_default.sqrt(ce.bignum(D)).toFixed(0));
39178
+ const sqrt3 = BigInt(decimal_default.sqrt(ce.bignum(D)).toFixed(0));
39147
39179
  return ce.symbol(
39148
- sqrt2 * sqrt2 === D && (sqrt2 - 1n) % 2n === 0n ? "True" : "False"
39180
+ sqrt3 * sqrt3 === D && (sqrt3 - 1n) % 2n === 0n ? "True" : "False"
39149
39181
  );
39150
39182
  }
39151
39183
  },
@@ -39155,8 +39187,8 @@ var NUMBER_THEORY_LIBRARY = [
39155
39187
  evaluate: ([n], { engine: ce }) => {
39156
39188
  const k = toBigint(n);
39157
39189
  if (k === null || k < 0n) return ce.False;
39158
- const sqrt2 = BigInt(decimal_default.sqrt(ce.bignum(k)).toFixed(0));
39159
- return ce.symbol(sqrt2 * sqrt2 === k ? "True" : "False");
39190
+ const sqrt3 = BigInt(decimal_default.sqrt(ce.bignum(k)).toFixed(0));
39191
+ return ce.symbol(sqrt3 * sqrt3 === k ? "True" : "False");
39160
39192
  }
39161
39193
  },
39162
39194
  IsOctahedral: {
@@ -39166,8 +39198,8 @@ var NUMBER_THEORY_LIBRARY = [
39166
39198
  const k = toBigint(n);
39167
39199
  if (k === null || k < 1n) return ce.False;
39168
39200
  const discriminant = 3n * k + 1n;
39169
- const sqrt2 = BigInt(decimal_default.sqrt(ce.bignum(discriminant)).toFixed(0));
39170
- return ce.symbol(sqrt2 * sqrt2 === discriminant ? "True" : "False");
39201
+ const sqrt3 = BigInt(decimal_default.sqrt(ce.bignum(discriminant)).toFixed(0));
39202
+ return ce.symbol(sqrt3 * sqrt3 === discriminant ? "True" : "False");
39171
39203
  }
39172
39204
  },
39173
39205
  IsCenteredSquare: {
@@ -39178,8 +39210,8 @@ var NUMBER_THEORY_LIBRARY = [
39178
39210
  if (k === null || k < 1n) return ce.False;
39179
39211
  if ((k - 1n) % 4n !== 0n) return ce.False;
39180
39212
  const t = (k - 1n) / 4n;
39181
- const sqrt2 = BigInt(decimal_default.sqrt(ce.bignum(t)).toFixed(0));
39182
- return ce.symbol(sqrt2 * sqrt2 * 4n + 1n === k ? "True" : "False");
39213
+ const sqrt3 = BigInt(decimal_default.sqrt(ce.bignum(t)).toFixed(0));
39214
+ return ce.symbol(sqrt3 * sqrt3 * 4n + 1n === k ? "True" : "False");
39183
39215
  }
39184
39216
  },
39185
39217
  IsHappy: {
@@ -39261,39 +39293,39 @@ function factorPerfectSquare(expr) {
39261
39293
  const term2 = terms[j];
39262
39294
  const crossTerm = terms[crossIdx];
39263
39295
  const sqrt1 = extractSquareRoot(term1, ce);
39264
- const sqrt2 = extractSquareRoot(term2, ce);
39265
- if (sqrt1 === null || sqrt2 === null) continue;
39266
- const positiveCross = ce.number(2).mul(sqrt1).mul(sqrt2);
39296
+ const sqrt22 = extractSquareRoot(term2, ce);
39297
+ if (sqrt1 === null || sqrt22 === null) continue;
39298
+ const positiveCross = ce.number(2).mul(sqrt1).mul(sqrt22);
39267
39299
  const negativeCross = positiveCross.neg();
39268
39300
  if (crossTerm.isSame(positiveCross)) {
39269
- return ce.box(["Square", sqrt1.add(sqrt2).json]);
39301
+ return ce.box(["Square", sqrt1.add(sqrt22).json]);
39270
39302
  } else if (crossTerm.isSame(negativeCross)) {
39271
- return ce.box(["Square", sqrt1.sub(sqrt2).json]);
39303
+ return ce.box(["Square", sqrt1.sub(sqrt22).json]);
39272
39304
  }
39273
39305
  }
39274
39306
  }
39275
39307
  return null;
39276
39308
  }
39277
39309
  function extractSquareRoot(term, ce) {
39278
- const sqrt2 = term.sqrt().simplify();
39279
- if (sqrt2.operator === "Sqrt") return null;
39280
- if (sqrt2.isNumberLiteral && sqrt2.numericValue) {
39281
- const nv = sqrt2.numericValue;
39310
+ const sqrt3 = term.sqrt().simplify();
39311
+ if (sqrt3.operator === "Sqrt") return null;
39312
+ if (sqrt3.isNumberLiteral && sqrt3.numericValue) {
39313
+ const nv = sqrt3.numericValue;
39282
39314
  if (nv.radical !== void 0 && nv.radical !== 1) return null;
39283
39315
  }
39284
- if (sqrt2.operator === "Abs") {
39285
- return sqrt2.op1;
39316
+ if (sqrt3.operator === "Abs") {
39317
+ return sqrt3.op1;
39286
39318
  }
39287
- if (sqrt2.operator === "Multiply") {
39288
- const absFactors = sqrt2.ops.filter((op) => op.operator === "Abs");
39319
+ if (sqrt3.operator === "Multiply") {
39320
+ const absFactors = sqrt3.ops.filter((op) => op.operator === "Abs");
39289
39321
  if (absFactors.length > 0) {
39290
- const newOps = sqrt2.ops.map(
39322
+ const newOps = sqrt3.ops.map(
39291
39323
  (op) => op.operator === "Abs" ? op.op1 : op
39292
39324
  );
39293
39325
  return ce.box(["Multiply", ...newOps.map((op) => op.json)]);
39294
39326
  }
39295
39327
  }
39296
- return sqrt2;
39328
+ return sqrt3;
39297
39329
  }
39298
39330
  function factorDifferenceOfSquares(expr) {
39299
39331
  const ce = expr.engine;
@@ -39316,9 +39348,9 @@ function factorDifferenceOfSquares(expr) {
39316
39348
  absTerm = ce.box(["Multiply", ...newOps.map((op) => op.json)]);
39317
39349
  }
39318
39350
  }
39319
- const sqrt2 = extractSquareRoot(absTerm, ce);
39320
- if (sqrt2 === null) return null;
39321
- results.push({ sqrt: sqrt2, isNegative: isNeg });
39351
+ const sqrt3 = extractSquareRoot(absTerm, ce);
39352
+ if (sqrt3 === null) return null;
39353
+ results.push({ sqrt: sqrt3, isNegative: isNeg });
39322
39354
  }
39323
39355
  const posSquares = results.filter((r) => !r.isNegative);
39324
39356
  const negSquares = results.filter((r) => r.isNegative);
@@ -39635,10 +39667,10 @@ var RELOP_LIBRARY = {
39635
39667
  let constantRatio = void 0;
39636
39668
  const tolerance = ce.tolerance;
39637
39669
  for (const testVal of testValues) {
39638
- const sub2 = {};
39639
- for (const u of unknowns) sub2[u] = testVal;
39640
- const v1 = expr1.subs(sub2).N();
39641
- const v2 = expr2.subs(sub2).N();
39670
+ const sub3 = {};
39671
+ for (const u of unknowns) sub3[u] = testVal;
39672
+ const v1 = expr1.subs(sub3).N();
39673
+ const v2 = expr2.subs(sub3).N();
39642
39674
  const n1 = v1.re;
39643
39675
  const n2 = v2.re;
39644
39676
  if (!Number.isFinite(n1) || !Number.isFinite(n2)) continue;
@@ -40875,9 +40907,9 @@ function* rationalIterator(self, options) {
40875
40907
  if (signOpt === "+-") {
40876
40908
  yield self.engine.number(value);
40877
40909
  } else {
40878
- const sign2 = signOpt === "-" ? -1 : 1;
40910
+ const sign3 = signOpt === "-" ? -1 : 1;
40879
40911
  const [n, d] = value;
40880
- yield self.engine.number([sign2 * n, d]);
40912
+ yield self.engine.number([sign3 * n, d]);
40881
40913
  }
40882
40914
  }
40883
40915
  }
@@ -41127,12 +41159,12 @@ function mode(values) {
41127
41159
  for (const v of values) {
41128
41160
  counts[v] = (counts[v] ?? 0) + 1;
41129
41161
  }
41130
- let max2 = 0;
41162
+ let max3 = 0;
41131
41163
  let mode2 = NaN;
41132
41164
  for (const v in counts) {
41133
41165
  const c = counts[v];
41134
- if (c > max2) {
41135
- max2 = c;
41166
+ if (c > max3) {
41167
+ max3 = c;
41136
41168
  mode2 = +v;
41137
41169
  }
41138
41170
  }
@@ -41143,12 +41175,12 @@ function bigMode(bignum, values) {
41143
41175
  for (const v of values) {
41144
41176
  counts[v.toString()] = (counts[v.toString()] ?? 0) + 1;
41145
41177
  }
41146
- let max2 = 0;
41178
+ let max3 = 0;
41147
41179
  let mode2 = bignum(NaN);
41148
41180
  for (const v in counts) {
41149
41181
  const c = counts[v];
41150
- if (c > max2) {
41151
- max2 = c;
41182
+ if (c > max3) {
41183
+ max3 = c;
41152
41184
  mode2 = bignum(v);
41153
41185
  }
41154
41186
  }
@@ -41336,18 +41368,18 @@ var STATISTICS_LIBRARY = [
41336
41368
  if (!xs.isFiniteCollection) return void 0;
41337
41369
  const data = Array.from(xs.each()).map((x) => x.re).filter(Number.isFinite);
41338
41370
  if (data.length === 0) return void 0;
41339
- const min2 = Math.min(...data);
41340
- const max2 = Math.max(...data);
41371
+ const min3 = Math.min(...data);
41372
+ const max3 = Math.max(...data);
41341
41373
  let binEdges;
41342
41374
  if (binsArg?.operator === "List") {
41343
41375
  binEdges = binsArg.ops.map((op) => op.re);
41344
41376
  } else {
41345
41377
  const binCount = toInteger(binsArg);
41346
41378
  if (binCount === null || binCount <= 0) return void 0;
41347
- const binWidth = (max2 - min2) / binCount;
41379
+ const binWidth = (max3 - min3) / binCount;
41348
41380
  binEdges = Array.from(
41349
41381
  { length: binCount + 1 },
41350
- (_, i) => min2 + i * binWidth
41382
+ (_, i) => min3 + i * binWidth
41351
41383
  );
41352
41384
  }
41353
41385
  const counts = Array(binEdges.length - 1).fill(0);
@@ -41376,18 +41408,18 @@ var STATISTICS_LIBRARY = [
41376
41408
  if (!xs.isFiniteCollection) return void 0;
41377
41409
  const data = Array.from(xs.each()).map((x) => x.re).filter(Number.isFinite);
41378
41410
  if (data.length === 0) return void 0;
41379
- const min2 = Math.min(...data);
41380
- const max2 = Math.max(...data);
41411
+ const min3 = Math.min(...data);
41412
+ const max3 = Math.max(...data);
41381
41413
  let binEdges;
41382
41414
  if (binsArg.isCollection) {
41383
41415
  binEdges = [...binsArg.each()].map((op) => op.re);
41384
41416
  } else {
41385
41417
  const binCount = toInteger(binsArg);
41386
41418
  if (binCount === null || binCount <= 0) return void 0;
41387
- const binWidth = (max2 - min2) / binCount;
41419
+ const binWidth = (max3 - min3) / binCount;
41388
41420
  binEdges = Array.from(
41389
41421
  { length: binCount + 1 },
41390
- (_, i) => min2 + i * binWidth
41422
+ (_, i) => min3 + i * binWidth
41391
41423
  );
41392
41424
  }
41393
41425
  const counts = Array(binEdges.length - 1).fill(0);
@@ -42037,13 +42069,13 @@ function constructibleValues(operator2, x) {
42037
42069
  theta = Math.abs(theta % (2 * Math.PI));
42038
42070
  const quadrant3 = Math.floor(theta * 2 / Math.PI);
42039
42071
  theta = theta % (Math.PI / 2);
42040
- let sign2;
42041
- [sign2, operator2] = TRIG_IDENTITIES[operator2]?.[quadrant3] ?? [1, operator2];
42072
+ let sign3;
42073
+ [sign3, operator2] = TRIG_IDENTITIES[operator2]?.[quadrant3] ?? [1, operator2];
42042
42074
  for (const [[n, d], value] of specialValues) {
42043
42075
  const r = value[operator2];
42044
42076
  if (r && Math.abs(theta - Math.PI * n / d) <= 1e-12) {
42045
42077
  if (r.symbol === "ComplexInfinity") return r;
42046
- return identitySign * sign2 < 0 ? r.neg() : r;
42078
+ return identitySign * sign3 < 0 ? r.neg() : r;
42047
42079
  }
42048
42080
  }
42049
42081
  return void 0;
@@ -42459,8 +42491,8 @@ function costFunction(expr) {
42459
42491
  return 5 + costFunction(arg) + 6;
42460
42492
  }
42461
42493
  if (arg?.operator === "Power" && arg.op2?.isOdd === true && arg.op2?.isInteger === true) {
42462
- const exp2 = arg.op2;
42463
- const n = exp2.numericValue;
42494
+ const exp3 = arg.op2;
42495
+ const n = exp3.numericValue;
42464
42496
  if (typeof n === "number" && n > 1) {
42465
42497
  return 5 + costFunction(arg) + 10;
42466
42498
  }
@@ -42469,8 +42501,8 @@ function costFunction(expr) {
42469
42501
  } else if (["Square", "Abs"].includes(name)) nameCost = 5;
42470
42502
  else if (name === "Power") {
42471
42503
  const base = expr.ops[0];
42472
- const exp2 = expr.ops[1];
42473
- const expCost = costFunction(exp2);
42504
+ const exp3 = expr.ops[1];
42505
+ const expCost = costFunction(exp3);
42474
42506
  if (base.operator === "Negate") {
42475
42507
  return expCost + 4;
42476
42508
  }
@@ -42478,7 +42510,7 @@ function costFunction(expr) {
42478
42510
  const hasNegativeCoef = base.ops.some(
42479
42511
  (f) => f.isNumberLiteral && f.isNegative === true
42480
42512
  );
42481
- if (hasNegativeCoef && exp2.isRational === true && !exp2.isInteger) {
42513
+ if (hasNegativeCoef && exp3.isRational === true && !exp3.isInteger) {
42482
42514
  return expCost + costFunction(base) + 15;
42483
42515
  }
42484
42516
  return expCost + costFunction(base);
@@ -43390,10 +43422,10 @@ function TR5(expr) {
43390
43422
  const ce = expr.engine;
43391
43423
  if (expr.operator !== "Power") return void 0;
43392
43424
  const base = expr.op1;
43393
- const exp2 = expr.op2;
43394
- if (!base || !exp2) return void 0;
43425
+ const exp3 = expr.op2;
43426
+ if (!base || !exp3) return void 0;
43395
43427
  if (base.operator !== "Sin") return void 0;
43396
- if (!exp2.is(2)) return void 0;
43428
+ if (!exp3.is(2)) return void 0;
43397
43429
  const arg = base.op1;
43398
43430
  if (!arg) return void 0;
43399
43431
  return ce.One.sub(ce._fn("Cos", [arg]).pow(2));
@@ -43405,10 +43437,10 @@ function TR6(expr) {
43405
43437
  const ce = expr.engine;
43406
43438
  if (expr.operator !== "Power") return void 0;
43407
43439
  const base = expr.op1;
43408
- const exp2 = expr.op2;
43409
- if (!base || !exp2) return void 0;
43440
+ const exp3 = expr.op2;
43441
+ if (!base || !exp3) return void 0;
43410
43442
  if (base.operator !== "Cos") return void 0;
43411
- if (!exp2.is(2)) return void 0;
43443
+ if (!exp3.is(2)) return void 0;
43412
43444
  const arg = base.op1;
43413
43445
  if (!arg) return void 0;
43414
43446
  return ce.One.sub(ce._fn("Sin", [arg]).pow(2));
@@ -43420,10 +43452,10 @@ function TR7(expr) {
43420
43452
  const ce = expr.engine;
43421
43453
  if (expr.operator !== "Power") return void 0;
43422
43454
  const base = expr.op1;
43423
- const exp2 = expr.op2;
43424
- if (!base || !exp2) return void 0;
43455
+ const exp3 = expr.op2;
43456
+ if (!base || !exp3) return void 0;
43425
43457
  if (base.operator !== "Cos") return void 0;
43426
- if (!exp2.is(2)) return void 0;
43458
+ if (!exp3.is(2)) return void 0;
43427
43459
  const arg = base.op1;
43428
43460
  if (!arg) return void 0;
43429
43461
  return ce.One.add(ce._fn("Cos", [arg.mul(2)])).div(2);
@@ -44191,9 +44223,9 @@ function TR22(expr) {
44191
44223
  const ce = expr.engine;
44192
44224
  if (expr.operator !== "Power") return void 0;
44193
44225
  const base = expr.op1;
44194
- const exp2 = expr.op2;
44195
- if (!base || !exp2) return void 0;
44196
- if (!exp2.is(2)) return void 0;
44226
+ const exp3 = expr.op2;
44227
+ if (!base || !exp3) return void 0;
44228
+ if (!exp3.is(2)) return void 0;
44197
44229
  const arg = base.op1;
44198
44230
  if (!arg) return void 0;
44199
44231
  if (base.operator === "Tan") {
@@ -45216,9 +45248,9 @@ function matchCommutativeWithAnchors(expr, pattern, substitution, options) {
45216
45248
  (a, b) => anchorSpecificity(b) - anchorSpecificity(a)
45217
45249
  );
45218
45250
  return tryMatchAnchors(0, exprOps, substitution);
45219
- function tryMatchAnchors(anchorIndex, remainingOps, sub2) {
45251
+ function tryMatchAnchors(anchorIndex, remainingOps, sub3) {
45220
45252
  if (anchorIndex >= sortedAnchors.length) {
45221
- return assignWildcards(remainingOps, sub2);
45253
+ return assignWildcards(remainingOps, sub3);
45222
45254
  }
45223
45255
  const anchorsLeft = sortedAnchors.length - anchorIndex;
45224
45256
  const minWildcardNeeds = universalWildcards.length + sequenceWildcards.length;
@@ -45227,7 +45259,7 @@ function matchCommutativeWithAnchors(expr, pattern, substitution, options) {
45227
45259
  }
45228
45260
  const anchor = sortedAnchors[anchorIndex];
45229
45261
  for (let i = 0; i < remainingOps.length; i++) {
45230
- const matchResult = matchOnce(remainingOps[i], anchor, sub2, options);
45262
+ const matchResult = matchOnce(remainingOps[i], anchor, sub3, options);
45231
45263
  if (matchResult !== null) {
45232
45264
  const newRemaining = [...remainingOps];
45233
45265
  newRemaining.splice(i, 1);
@@ -45241,8 +45273,8 @@ function matchCommutativeWithAnchors(expr, pattern, substitution, options) {
45241
45273
  }
45242
45274
  return null;
45243
45275
  }
45244
- function assignWildcards(remainingOps, sub2) {
45245
- const result = sub2;
45276
+ function assignWildcards(remainingOps, sub3) {
45277
+ const result = sub3;
45246
45278
  const neededForUniversal = universalWildcards.length;
45247
45279
  const minNeededForSequence = sequenceWildcards.length;
45248
45280
  const totalNeeded = neededForUniversal + minNeededForSequence;
@@ -45253,16 +45285,16 @@ function matchCommutativeWithAnchors(expr, pattern, substitution, options) {
45253
45285
  result
45254
45286
  );
45255
45287
  }
45256
- function tryAssignWildcards(wildcards, remaining, sub2) {
45288
+ function tryAssignWildcards(wildcards, remaining, sub3) {
45257
45289
  if (wildcards.length === 0) {
45258
- return remaining.length === 0 ? sub2 : null;
45290
+ return remaining.length === 0 ? sub3 : null;
45259
45291
  }
45260
45292
  const [wc, ...restWildcards] = wildcards;
45261
45293
  const wcType = wildcardType(wc);
45262
45294
  const wcName = wildcardName(wc);
45263
45295
  if (wcType === "Wildcard") {
45264
45296
  for (let i = 0; i < remaining.length; i++) {
45265
- const newSub = captureWildcard(wcName, remaining[i], sub2);
45297
+ const newSub = captureWildcard(wcName, remaining[i], sub3);
45266
45298
  if (newSub !== null) {
45267
45299
  const newRemaining = [...remaining];
45268
45300
  newRemaining.splice(i, 1);
@@ -45284,7 +45316,7 @@ function matchCommutativeWithAnchors(expr, pattern, substitution, options) {
45284
45316
  for (const indices of combinations) {
45285
45317
  const captured = indices.map((i) => remaining[i]);
45286
45318
  const capturedExpr = wrapCaptured(captured);
45287
- const newSub = captureWildcard(wcName, capturedExpr, sub2);
45319
+ const newSub = captureWildcard(wcName, capturedExpr, sub3);
45288
45320
  if (newSub !== null) {
45289
45321
  const newRemaining = remaining.filter(
45290
45322
  (_, i) => !indices.includes(i)
@@ -45304,7 +45336,7 @@ function matchCommutativeWithAnchors(expr, pattern, substitution, options) {
45304
45336
  for (let count = maxCapture; count >= 0; count--) {
45305
45337
  if (count === 0) {
45306
45338
  const identity = expr.operator === "Add" ? ce.Zero : expr.operator === "Multiply" ? ce.One : ce.Nothing;
45307
- const newSub = captureWildcard(wcName, identity, sub2);
45339
+ const newSub = captureWildcard(wcName, identity, sub3);
45308
45340
  if (newSub !== null) {
45309
45341
  const result = tryAssignWildcards(restWildcards, remaining, newSub);
45310
45342
  if (result !== null) return result;
@@ -45314,7 +45346,7 @@ function matchCommutativeWithAnchors(expr, pattern, substitution, options) {
45314
45346
  for (const indices of combinations) {
45315
45347
  const captured = indices.map((i) => remaining[i]);
45316
45348
  const capturedExpr = wrapCaptured(captured);
45317
- const newSub = captureWildcard(wcName, capturedExpr, sub2);
45349
+ const newSub = captureWildcard(wcName, capturedExpr, sub3);
45318
45350
  if (newSub !== null) {
45319
45351
  const newRemaining = remaining.filter(
45320
45352
  (_, i) => !indices.includes(i)
@@ -45785,11 +45817,11 @@ var BoxedFunction = class extends _BoxedExpression {
45785
45817
  return [coef.sqrt(), ce.function("Sqrt", [rest])];
45786
45818
  }
45787
45819
  if (expr.operator === "Root") {
45788
- const exp2 = expr.op2.re;
45789
- if (isNaN(exp2) || expr.op2.im !== 0) return [ce._numericValue(1), this];
45820
+ const exp3 = expr.op2.re;
45821
+ if (isNaN(exp3) || expr.op2.im !== 0) return [ce._numericValue(1), this];
45790
45822
  const [coef, rest] = expr.op1.toNumericValue();
45791
- if (exp2 === 2) return [coef.sqrt(), ce.function("Sqrt", [rest])];
45792
- return [coef.root(exp2), ce.function("Root", [rest, expr.op2])];
45823
+ if (exp3 === 2) return [coef.sqrt(), ce.function("Sqrt", [rest])];
45824
+ return [coef.root(exp3), ce.function("Root", [rest, expr.op2])];
45793
45825
  }
45794
45826
  if (expr.operator === "Abs") {
45795
45827
  const [coef, rest] = expr.op1.toNumericValue();
@@ -45806,11 +45838,11 @@ var BoxedFunction = class extends _BoxedExpression {
45806
45838
  * original expression.
45807
45839
  * <!-- This may or may not be desirable -->
45808
45840
  */
45809
- subs(sub2, options) {
45841
+ subs(sub3, options) {
45810
45842
  options ??= { canonical: void 0 };
45811
45843
  if (options.canonical === void 0)
45812
45844
  options = { canonical: this.isCanonical };
45813
- const ops = this._ops.map((x) => x.subs(sub2, options));
45845
+ const ops = this._ops.map((x) => x.subs(sub3, options));
45814
45846
  if (!ops.every((x) => x.isValid))
45815
45847
  return this.engine.function(this._operator, ops, { canonical: false });
45816
45848
  return this.engine.function(this._operator, ops, options);
@@ -45971,13 +46003,13 @@ var BoxedFunction = class extends _BoxedExpression {
45971
46003
  if (!this.isCanonical) throw new Error("Not canonical");
45972
46004
  return div2(this, rhs);
45973
46005
  }
45974
- pow(exp2) {
45975
- return pow2(this, exp2, { numericApproximation: false });
46006
+ pow(exp3) {
46007
+ return pow2(this, exp3, { numericApproximation: false });
45976
46008
  }
45977
- root(exp2) {
45978
- if (!this.isCanonical || typeof exp2 !== "number" && !exp2.isCanonical)
46009
+ root(exp3) {
46010
+ if (!this.isCanonical || typeof exp3 !== "number" && !exp3.isCanonical)
45979
46011
  throw new Error("Not canonical");
45980
- const e = typeof exp2 === "number" ? exp2 : exp2.im === 0 ? exp2.re : void 0;
46012
+ const e = typeof exp3 === "number" ? exp3 : exp3.im === 0 ? exp3.re : void 0;
45981
46013
  if (e === 0) return this.engine.NaN;
45982
46014
  if (e === 1) return this;
45983
46015
  if (e === -1) return this.inv();
@@ -45988,24 +46020,24 @@ var BoxedFunction = class extends _BoxedExpression {
45988
46020
  }
45989
46021
  if (this.operator === "Divide") {
45990
46022
  const [num, denom] = this.ops;
45991
- return num.root(exp2).div(denom.root(exp2));
46023
+ return num.root(exp3).div(denom.root(exp3));
45992
46024
  }
45993
46025
  if (this.operator === "Negate") {
45994
46026
  if (e !== void 0) {
45995
- if (e % 2 === 0) return this.op1.root(exp2);
45996
- return this.op1.root(exp2).neg();
46027
+ if (e % 2 === 0) return this.op1.root(exp3);
46028
+ return this.op1.root(exp3).neg();
45997
46029
  }
45998
46030
  }
45999
46031
  if (this.operator === "Sqrt") {
46000
46032
  if (e !== void 0) return this.op1.root(e * 2);
46001
- if (typeof exp2 !== "number") return this.op1.root(exp2.mul(2));
46033
+ if (typeof exp3 !== "number") return this.op1.root(exp3.mul(2));
46002
46034
  }
46003
46035
  if (this.operator === "Root") {
46004
46036
  const [base, root2] = this.ops;
46005
- return base.root(root2.mul(exp2));
46037
+ return base.root(root2.mul(exp3));
46006
46038
  }
46007
46039
  if (this.operator === "Multiply") {
46008
- const ops = this.ops.map((x) => x.root(exp2));
46040
+ const ops = this.ops.map((x) => x.root(exp3));
46009
46041
  return mul3(...ops);
46010
46042
  }
46011
46043
  if (this.isNumberLiteral) {
@@ -46027,7 +46059,7 @@ var BoxedFunction = class extends _BoxedExpression {
46027
46059
  }
46028
46060
  }
46029
46061
  }
46030
- return this.engine._fn("Root", [this, this.engine.box(exp2)]);
46062
+ return this.engine._fn("Root", [this, this.engine.box(exp3)]);
46031
46063
  }
46032
46064
  sqrt() {
46033
46065
  return this.root(2);
@@ -46046,12 +46078,12 @@ var BoxedFunction = class extends _BoxedExpression {
46046
46078
  return this.engine.One.div(base.ln());
46047
46079
  }
46048
46080
  if (this.operator === "Power") {
46049
- const [b, exp2] = this.ops;
46081
+ const [b, exp3] = this.ops;
46050
46082
  if (b.isSame(this.engine.E)) {
46051
- if (!base) return exp2;
46052
- return exp2.div(base.ln());
46083
+ if (!base) return exp3;
46084
+ return exp3.div(base.ln());
46053
46085
  }
46054
- return exp2.mul(b.ln(base));
46086
+ return exp3.mul(b.ln(base));
46055
46087
  }
46056
46088
  if (this.operator === "Root") {
46057
46089
  const [a, b] = this.ops;
@@ -47389,31 +47421,31 @@ var BoxedNumber = class extends _BoxedExpression {
47389
47421
  div(rhs) {
47390
47422
  return div2(this, rhs);
47391
47423
  }
47392
- pow(exp2) {
47393
- return pow2(this, exp2, { numericApproximation: false });
47424
+ pow(exp3) {
47425
+ return pow2(this, exp3, { numericApproximation: false });
47394
47426
  }
47395
- root(exp2) {
47396
- if (typeof exp2 === "number") {
47397
- if (exp2 === 0) return this.engine.NaN;
47398
- if (exp2 === 1) return this;
47399
- if (exp2 === -1) return this.inv();
47400
- if (exp2 === 2) return this.sqrt();
47427
+ root(exp3) {
47428
+ if (typeof exp3 === "number") {
47429
+ if (exp3 === 0) return this.engine.NaN;
47430
+ if (exp3 === 1) return this;
47431
+ if (exp3 === -1) return this.inv();
47432
+ if (exp3 === 2) return this.sqrt();
47401
47433
  if (this.isNegative) {
47402
- if (exp2 % 2 === 1) return this.neg().root(exp2).neg();
47403
- if (exp2 % 2 === 0) return this.neg().root(exp2);
47434
+ if (exp3 % 2 === 1) return this.neg().root(exp3).neg();
47435
+ if (exp3 % 2 === 0) return this.neg().root(exp3);
47404
47436
  }
47405
47437
  } else {
47406
- exp2 = exp2.canonical;
47407
- if (exp2.is(0)) return this.engine.NaN;
47408
- if (exp2.is(1)) return this;
47409
- if (exp2.is(-1)) return this.inv();
47410
- if (exp2.is(2)) return this.sqrt();
47438
+ exp3 = exp3.canonical;
47439
+ if (exp3.is(0)) return this.engine.NaN;
47440
+ if (exp3.is(1)) return this;
47441
+ if (exp3.is(-1)) return this.inv();
47442
+ if (exp3.is(2)) return this.sqrt();
47411
47443
  if (this.isNegative) {
47412
- if (exp2.isOdd) return this.neg().root(exp2).neg();
47413
- if (exp2.isEven) return this.neg().root(exp2);
47444
+ if (exp3.isOdd) return this.neg().root(exp3).neg();
47445
+ if (exp3.isEven) return this.neg().root(exp3);
47414
47446
  }
47415
47447
  }
47416
- const n = typeof exp2 === "number" ? exp2 : exp2.re;
47448
+ const n = typeof exp3 === "number" ? exp3 : exp3.re;
47417
47449
  if (Number.isInteger(n)) {
47418
47450
  if (typeof this._value === "number") {
47419
47451
  const r = this._value ** (1 / n);
@@ -47423,7 +47455,7 @@ var BoxedNumber = class extends _BoxedExpression {
47423
47455
  if (isSubtype(r.type, "integer")) return this.engine.number(r);
47424
47456
  }
47425
47457
  }
47426
- return this.engine._fn("Root", [this, this.engine.box(exp2)]);
47458
+ return this.engine._fn("Root", [this, this.engine.box(exp3)]);
47427
47459
  }
47428
47460
  sqrt() {
47429
47461
  if (typeof this._value === "number") {
@@ -47504,9 +47536,9 @@ var BoxedNumber = class extends _BoxedExpression {
47504
47536
  ce.number(this._value.denominator)
47505
47537
  ];
47506
47538
  }
47507
- subs(sub2, options) {
47539
+ subs(sub3, options) {
47508
47540
  if (this.isStructural) return this;
47509
- return this.structural.subs(sub2, options);
47541
+ return this.structural.subs(sub3, options);
47510
47542
  }
47511
47543
  replace(rules, options) {
47512
47544
  return replace(this.structural, rules, options).at(-1)?.value ?? null;
@@ -47670,9 +47702,9 @@ function canonicalNumber(ce, value) {
47670
47702
  return 0;
47671
47703
  }
47672
47704
  if (typeof value[0] === "number" && !Number.isFinite(value[0])) {
47673
- const sign2 = value[0] > 0 ? 1 : -1;
47674
- if (value[0] > 0) return sign2 > 0 ? Infinity : -Infinity;
47675
- if (value[0] < 0) return sign2 > 0 ? -Infinity : Infinity;
47705
+ const sign3 = value[0] > 0 ? 1 : -1;
47706
+ if (value[0] > 0) return sign3 > 0 ? Infinity : -Infinity;
47707
+ if (value[0] < 0) return sign3 > 0 ? -Infinity : Infinity;
47676
47708
  return NaN;
47677
47709
  }
47678
47710
  return ce._numericValue(value);
@@ -47816,8 +47848,8 @@ var BoxedSymbol = class extends _BoxedExpression {
47816
47848
  div(rhs) {
47817
47849
  return div2(this, rhs);
47818
47850
  }
47819
- pow(exp2) {
47820
- return pow2(this, exp2, { numericApproximation: false });
47851
+ pow(exp3) {
47852
+ return pow2(this, exp3, { numericApproximation: false });
47821
47853
  }
47822
47854
  root(n) {
47823
47855
  const e = typeof n === "number" ? n : n.im === 0 ? n.re : void 0;
@@ -48143,10 +48175,10 @@ var BoxedSymbol = class extends _BoxedExpression {
48143
48175
  replace(rules, options) {
48144
48176
  return replace(this, rules, options).at(-1)?.value ?? null;
48145
48177
  }
48146
- subs(sub2, options) {
48178
+ subs(sub3, options) {
48147
48179
  const canonical2 = options?.canonical ?? this.isCanonical;
48148
- if (sub2[this._id] === void 0) return canonical2 ? this.canonical : this;
48149
- return this.engine.box(sub2[this._id], { canonical: canonical2 });
48180
+ if (sub3[this._id] === void 0) return canonical2 ? this.canonical : this;
48181
+ return this.engine.box(sub3[this._id], { canonical: canonical2 });
48150
48182
  }
48151
48183
  get _asCollection() {
48152
48184
  if (isValueDef(this._def)) return this._def.value.collection;
@@ -48860,38 +48892,38 @@ function simplifyAbs(x) {
48860
48892
  }
48861
48893
  if (opOperator === "Power") {
48862
48894
  const base = op.op1;
48863
- const exp2 = op.op2;
48864
- if (base && exp2) {
48865
- if (exp2.isEven === true) {
48895
+ const exp3 = op.op2;
48896
+ if (base && exp3) {
48897
+ if (exp3.isEven === true) {
48866
48898
  return {
48867
- value: base.pow(exp2),
48899
+ value: base.pow(exp3),
48868
48900
  because: "|x^n| -> x^n when n is even"
48869
48901
  };
48870
48902
  }
48871
- if (exp2.isOdd === true) {
48903
+ if (exp3.isOdd === true) {
48872
48904
  return {
48873
- value: ce._fn("Abs", [base]).pow(exp2),
48905
+ value: ce._fn("Abs", [base]).pow(exp3),
48874
48906
  because: "|x^n| -> |x|^n when n is odd"
48875
48907
  };
48876
48908
  }
48877
- if (exp2.isRational === false) {
48909
+ if (exp3.isRational === false) {
48878
48910
  return {
48879
- value: ce._fn("Abs", [base]).pow(exp2),
48911
+ value: ce._fn("Abs", [base]).pow(exp3),
48880
48912
  because: "|x^n| -> |x|^n when n is irrational"
48881
48913
  };
48882
48914
  }
48883
- if (exp2.isRational === true && exp2.isInteger === false) {
48884
- const num = exp2.numerator;
48915
+ if (exp3.isRational === true && exp3.isInteger === false) {
48916
+ const num = exp3.numerator;
48885
48917
  if (num) {
48886
48918
  if (num.isEven === true) {
48887
48919
  return {
48888
- value: base.pow(exp2),
48920
+ value: base.pow(exp3),
48889
48921
  because: "|x^(p/q)| -> x^(p/q) when p is even"
48890
48922
  };
48891
48923
  }
48892
48924
  if (num.isOdd === true) {
48893
48925
  return {
48894
- value: ce._fn("Abs", [base]).pow(exp2),
48926
+ value: ce._fn("Abs", [base]).pow(exp3),
48895
48927
  because: "|x^(p/q)| -> |x|^(p/q) when p is odd"
48896
48928
  };
48897
48929
  }
@@ -48913,22 +48945,22 @@ function simplifyAbs(x) {
48913
48945
  function simplifyAbsPower(x) {
48914
48946
  if (x.operator !== "Power") return void 0;
48915
48947
  const base = x.op1;
48916
- const exp2 = x.op2;
48917
- if (!base || !exp2 || base.operator !== "Abs") return void 0;
48948
+ const exp3 = x.op2;
48949
+ if (!base || !exp3 || base.operator !== "Abs") return void 0;
48918
48950
  const innerBase = base.op1;
48919
48951
  if (!innerBase) return void 0;
48920
- if (exp2.isEven === true) {
48952
+ if (exp3.isEven === true) {
48921
48953
  return {
48922
- value: innerBase.pow(exp2),
48954
+ value: innerBase.pow(exp3),
48923
48955
  because: "|x|^n -> x^n when n is even"
48924
48956
  };
48925
48957
  }
48926
- if (exp2.operator === "Divide") {
48927
- const n = exp2.op1;
48928
- const m = exp2.op2;
48958
+ if (exp3.operator === "Divide") {
48959
+ const n = exp3.op1;
48960
+ const m = exp3.op2;
48929
48961
  if (n && m && n.isEven === true && m.isOdd === true) {
48930
48962
  return {
48931
- value: innerBase.pow(exp2),
48963
+ value: innerBase.pow(exp3),
48932
48964
  because: "|x|^(n/m) -> x^(n/m) when n even, m odd"
48933
48965
  };
48934
48966
  }
@@ -49083,27 +49115,27 @@ function simplifyInfinity(x) {
49083
49115
  }
49084
49116
  if (op === "Power") {
49085
49117
  const base = x.op1;
49086
- const exp2 = x.op2;
49087
- if (base && exp2) {
49118
+ const exp3 = x.op2;
49119
+ if (base && exp3) {
49088
49120
  const baseIsInf = base.isInfinity === true;
49089
- const expIsInf = exp2.isInfinity === true;
49121
+ const expIsInf = exp3.isInfinity === true;
49090
49122
  const baseIsPosInf = baseIsInf && base.isPositive === true;
49091
49123
  const baseIsNegInf = baseIsInf && base.isNegative === true;
49092
- const expIsPosInf = expIsInf && exp2.isPositive === true;
49093
- const expIsNegInf = expIsInf && exp2.isNegative === true;
49124
+ const expIsPosInf = expIsInf && exp3.isPositive === true;
49125
+ const expIsNegInf = expIsInf && exp3.isNegative === true;
49094
49126
  if (base.symbol === "ExponentialE" && expIsPosInf) {
49095
49127
  return { value: ce.PositiveInfinity, because: "e^(+inf) -> +inf" };
49096
49128
  }
49097
49129
  if (base.symbol === "ExponentialE" && expIsNegInf) {
49098
49130
  return { value: ce.Zero, because: "e^(-inf) -> 0" };
49099
49131
  }
49100
- if (base.is(1) && exp2.isFinite === true) {
49132
+ if (base.is(1) && exp3.isFinite === true) {
49101
49133
  return { value: ce.One, because: "1^finite -> 1" };
49102
49134
  }
49103
- if (exp2.is(0) && baseIsInf) {
49135
+ if (exp3.is(0) && baseIsInf) {
49104
49136
  return { value: ce.NaN, because: "inf^0 -> NaN" };
49105
49137
  }
49106
- if (exp2.is(0) && base.is(0) === false && base.isFinite === true) {
49138
+ if (exp3.is(0) && base.is(0) === false && base.isFinite === true) {
49107
49139
  return { value: ce.One, because: "x^0 -> 1" };
49108
49140
  }
49109
49141
  if (expIsPosInf) {
@@ -49129,28 +49161,28 @@ function simplifyInfinity(x) {
49129
49161
  }
49130
49162
  }
49131
49163
  if (baseIsPosInf) {
49132
- if (exp2.isNegative === true) {
49164
+ if (exp3.isNegative === true) {
49133
49165
  return { value: ce.Zero, because: "+inf^negative -> 0" };
49134
49166
  }
49135
49167
  }
49136
49168
  if (baseIsNegInf) {
49137
- if (exp2.isNegative === true) {
49169
+ if (exp3.isNegative === true) {
49138
49170
  return { value: ce.Zero, because: "-inf^negative -> 0" };
49139
49171
  }
49140
- if (exp2.isInteger === true && exp2.isEven === true) {
49172
+ if (exp3.isInteger === true && exp3.isEven === true) {
49141
49173
  return {
49142
49174
  value: ce.PositiveInfinity,
49143
49175
  because: "(-inf)^(even integer) -> +inf"
49144
49176
  };
49145
49177
  }
49146
- if (exp2.isInteger === true && exp2.isOdd === true) {
49178
+ if (exp3.isInteger === true && exp3.isOdd === true) {
49147
49179
  return {
49148
49180
  value: ce.NegativeInfinity,
49149
49181
  because: "(-inf)^(odd integer) -> -inf"
49150
49182
  };
49151
49183
  }
49152
- if (exp2.isRational === true) {
49153
- const [numExpr, denomExpr] = exp2.numeratorDenominator;
49184
+ if (exp3.isRational === true) {
49185
+ const [numExpr, denomExpr] = exp3.numeratorDenominator;
49154
49186
  const num = numExpr.re;
49155
49187
  const denom = denomExpr.re;
49156
49188
  if (typeof num === "number" && typeof denom === "number" && Number.isInteger(num) && Number.isInteger(denom)) {
@@ -49192,17 +49224,17 @@ function simplifyLog(x) {
49192
49224
  }
49193
49225
  if (arg.operator === "Power") {
49194
49226
  const base = arg.op1;
49195
- const exp2 = arg.op2;
49196
- if (base && exp2) {
49197
- if (base.isNonNegative === true || exp2.isOdd === true || exp2.isRational === false) {
49227
+ const exp3 = arg.op2;
49228
+ if (base && exp3) {
49229
+ if (base.isNonNegative === true || exp3.isOdd === true || exp3.isRational === false) {
49198
49230
  return {
49199
- value: exp2.mul(ce._fn("Ln", [base])),
49231
+ value: exp3.mul(ce._fn("Ln", [base])),
49200
49232
  because: "ln(x^n) -> n*ln(x)"
49201
49233
  };
49202
49234
  }
49203
- if (exp2.isEven === true) {
49235
+ if (exp3.isEven === true) {
49204
49236
  return {
49205
- value: exp2.mul(ce._fn("Ln", [ce._fn("Abs", [base])])),
49237
+ value: exp3.mul(ce._fn("Ln", [ce._fn("Abs", [base])])),
49206
49238
  because: "ln(x^n) -> n*ln(|x|) when n even"
49207
49239
  };
49208
49240
  }
@@ -49215,11 +49247,11 @@ function simplifyLog(x) {
49215
49247
  for (let i = 0; i < arg.ops.length; i++) {
49216
49248
  const factor3 = arg.ops[i];
49217
49249
  if (factor3.operator === "Power" && factor3.op1?.symbol === "ExponentialE") {
49218
- const exp2 = factor3.op2;
49250
+ const exp3 = factor3.op2;
49219
49251
  const otherFactors = arg.ops.filter((_, idx) => idx !== i);
49220
49252
  const remaining = otherFactors.length === 1 ? otherFactors[0] : ce._fn("Multiply", otherFactors);
49221
49253
  return {
49222
- value: exp2.add(ce._fn("Ln", [remaining])),
49254
+ value: exp3.add(ce._fn("Ln", [remaining])),
49223
49255
  because: "ln(e^x * y) -> x + ln(y)"
49224
49256
  };
49225
49257
  }
@@ -49302,17 +49334,17 @@ function simplifyLog(x) {
49302
49334
  }
49303
49335
  if (arg.operator === "Power") {
49304
49336
  const powerBase = arg.op1;
49305
- const exp2 = arg.op2;
49306
- if (powerBase && exp2) {
49307
- if (powerBase.isNonNegative === true || exp2.isOdd === true || exp2.isRational === false) {
49337
+ const exp3 = arg.op2;
49338
+ if (powerBase && exp3) {
49339
+ if (powerBase.isNonNegative === true || exp3.isOdd === true || exp3.isRational === false) {
49308
49340
  return {
49309
- value: exp2.mul(ce._fn("Log", [powerBase, logBase])),
49341
+ value: exp3.mul(ce._fn("Log", [powerBase, logBase])),
49310
49342
  because: "log_c(x^n) -> n*log_c(x)"
49311
49343
  };
49312
49344
  }
49313
- if (exp2.isEven === true) {
49345
+ if (exp3.isEven === true) {
49314
49346
  return {
49315
- value: exp2.mul(
49347
+ value: exp3.mul(
49316
49348
  ce._fn("Log", [ce._fn("Abs", [powerBase]), logBase])
49317
49349
  ),
49318
49350
  because: "log_c(x^n) -> n*log_c(|x|) when n even"
@@ -49324,11 +49356,11 @@ function simplifyLog(x) {
49324
49356
  for (let i = 0; i < arg.ops.length; i++) {
49325
49357
  const factor3 = arg.ops[i];
49326
49358
  if (factor3.operator === "Power" && factor3.op1?.isSame(logBase)) {
49327
- const exp2 = factor3.op2;
49359
+ const exp3 = factor3.op2;
49328
49360
  const otherFactors = arg.ops.filter((_, idx) => idx !== i);
49329
49361
  const remaining = otherFactors.length === 1 ? otherFactors[0] : ce._fn("Multiply", otherFactors);
49330
49362
  return {
49331
- value: exp2.add(ce._fn("Log", [remaining, logBase])),
49363
+ value: exp3.add(ce._fn("Log", [remaining, logBase])),
49332
49364
  because: "log_c(c^x * y) -> x + log_c(y)"
49333
49365
  };
49334
49366
  }
@@ -49368,32 +49400,32 @@ function simplifyLog(x) {
49368
49400
  }
49369
49401
  if (op === "Power") {
49370
49402
  const base = x.op1;
49371
- const exp2 = x.op2;
49372
- if (!base || !exp2) return void 0;
49373
- if (base.symbol === "ExponentialE" && exp2.operator === "Ln") {
49374
- return { value: exp2.op1, because: "e^ln(x) -> x" };
49403
+ const exp3 = x.op2;
49404
+ if (!base || !exp3) return void 0;
49405
+ if (base.symbol === "ExponentialE" && exp3.operator === "Ln") {
49406
+ return { value: exp3.op1, because: "e^ln(x) -> x" };
49375
49407
  }
49376
- if (base.symbol === "ExponentialE" && exp2.operator === "Log" && exp2.op1) {
49377
- const logBase = exp2.op2;
49408
+ if (base.symbol === "ExponentialE" && exp3.operator === "Log" && exp3.op1) {
49409
+ const logBase = exp3.op2;
49378
49410
  const isDefaultOrBase10 = !logBase || logBase.symbol === "Nothing" || logBase.is(10);
49379
49411
  if (isDefaultOrBase10) {
49380
49412
  return {
49381
- value: exp2.op1.pow(ce.One.div(ce._fn("Ln", [ce.number(10)]))),
49413
+ value: exp3.op1.pow(ce.One.div(ce._fn("Ln", [ce.number(10)]))),
49382
49414
  because: "e^log(x) -> x^{1/ln(10)}"
49383
49415
  };
49384
49416
  }
49385
49417
  if (logBase && logBase.symbol !== "ExponentialE") {
49386
49418
  return {
49387
- value: exp2.op1.pow(ce.One.div(ce._fn("Ln", [logBase]))),
49419
+ value: exp3.op1.pow(ce.One.div(ce._fn("Ln", [logBase]))),
49388
49420
  because: "e^log_c(x) -> x^{1/ln(c)}"
49389
49421
  };
49390
49422
  }
49391
49423
  }
49392
- if (base.symbol === "ExponentialE" && exp2.operator === "Add" && exp2.ops) {
49393
- for (let i = 0; i < exp2.ops.length; i++) {
49394
- const term = exp2.ops[i];
49424
+ if (base.symbol === "ExponentialE" && exp3.operator === "Add" && exp3.ops) {
49425
+ for (let i = 0; i < exp3.ops.length; i++) {
49426
+ const term = exp3.ops[i];
49395
49427
  if (term.operator === "Ln") {
49396
- const otherTerms = exp2.ops.filter((_, idx) => idx !== i);
49428
+ const otherTerms = exp3.ops.filter((_, idx) => idx !== i);
49397
49429
  const remaining = otherTerms.length === 0 ? ce.Zero : otherTerms.length === 1 ? otherTerms[0] : ce._fn("Add", otherTerms);
49398
49430
  return {
49399
49431
  value: term.op1.mul(ce._fn("Exp", [remaining])),
@@ -49401,10 +49433,10 @@ function simplifyLog(x) {
49401
49433
  };
49402
49434
  }
49403
49435
  }
49404
- for (let i = 0; i < exp2.ops.length; i++) {
49405
- const term = exp2.ops[i];
49436
+ for (let i = 0; i < exp3.ops.length; i++) {
49437
+ const term = exp3.ops[i];
49406
49438
  if (term.operator !== "Log" || !term.op1) continue;
49407
- const otherTerms = exp2.ops.filter((_, idx) => idx !== i);
49439
+ const otherTerms = exp3.ops.filter((_, idx) => idx !== i);
49408
49440
  const remaining = otherTerms.length === 0 ? ce.Zero : otherTerms.length === 1 ? otherTerms[0] : ce._fn("Add", otherTerms);
49409
49441
  const logBase = term.op2;
49410
49442
  const isDefaultOrBase10 = !logBase || logBase.symbol === "Nothing" || logBase.is(10);
@@ -49415,11 +49447,11 @@ function simplifyLog(x) {
49415
49447
  };
49416
49448
  }
49417
49449
  }
49418
- if (base.symbol === "ExponentialE" && exp2.operator === "Multiply" && exp2.ops) {
49419
- for (let i = 0; i < exp2.ops.length; i++) {
49420
- const factor3 = exp2.ops[i];
49450
+ if (base.symbol === "ExponentialE" && exp3.operator === "Multiply" && exp3.ops) {
49451
+ for (let i = 0; i < exp3.ops.length; i++) {
49452
+ const factor3 = exp3.ops[i];
49421
49453
  if (factor3.operator === "Ln") {
49422
- const otherFactors = exp2.ops.filter((_, idx) => idx !== i);
49454
+ const otherFactors = exp3.ops.filter((_, idx) => idx !== i);
49423
49455
  const y = otherFactors.length === 1 ? otherFactors[0] : ce._fn("Multiply", otherFactors);
49424
49456
  return {
49425
49457
  value: factor3.op1.pow(y),
@@ -49428,20 +49460,20 @@ function simplifyLog(x) {
49428
49460
  }
49429
49461
  }
49430
49462
  }
49431
- if (base.symbol === "ExponentialE" && exp2.operator === "Divide" && exp2.op1?.operator === "Ln") {
49463
+ if (base.symbol === "ExponentialE" && exp3.operator === "Divide" && exp3.op1?.operator === "Ln") {
49432
49464
  return {
49433
- value: exp2.op1.op1.pow(ce.One.div(exp2.op2)),
49465
+ value: exp3.op1.op1.pow(ce.One.div(exp3.op2)),
49434
49466
  because: "e^(ln(x) / y) -> x^(1/y)"
49435
49467
  };
49436
49468
  }
49437
- if (exp2.operator === "Log" && exp2.op2?.isSame(base)) {
49438
- return { value: exp2.op1, because: "c^log_c(x) -> x" };
49469
+ if (exp3.operator === "Log" && exp3.op2?.isSame(base)) {
49470
+ return { value: exp3.op1, because: "c^log_c(x) -> x" };
49439
49471
  }
49440
- if (exp2.operator === "Add" && exp2.ops) {
49441
- for (let i = 0; i < exp2.ops.length; i++) {
49442
- const term = exp2.ops[i];
49472
+ if (exp3.operator === "Add" && exp3.ops) {
49473
+ for (let i = 0; i < exp3.ops.length; i++) {
49474
+ const term = exp3.ops[i];
49443
49475
  if (term.operator === "Log" && term.op2?.isSame(base)) {
49444
- const otherTerms = exp2.ops.filter((_, idx) => idx !== i);
49476
+ const otherTerms = exp3.ops.filter((_, idx) => idx !== i);
49445
49477
  const remaining = otherTerms.length === 0 ? ce.Zero : otherTerms.length === 1 ? otherTerms[0] : ce._fn("Add", otherTerms);
49446
49478
  return {
49447
49479
  value: term.op1.mul(base.pow(remaining)),
@@ -49450,11 +49482,11 @@ function simplifyLog(x) {
49450
49482
  }
49451
49483
  }
49452
49484
  }
49453
- if (exp2.operator === "Multiply" && exp2.ops) {
49454
- for (let i = 0; i < exp2.ops.length; i++) {
49455
- const factor3 = exp2.ops[i];
49485
+ if (exp3.operator === "Multiply" && exp3.ops) {
49486
+ for (let i = 0; i < exp3.ops.length; i++) {
49487
+ const factor3 = exp3.ops[i];
49456
49488
  if (factor3.operator === "Log" && factor3.op2?.isSame(base)) {
49457
- const otherFactors = exp2.ops.filter((_, idx) => idx !== i);
49489
+ const otherFactors = exp3.ops.filter((_, idx) => idx !== i);
49458
49490
  const y = otherFactors.length === 1 ? otherFactors[0] : ce._fn("Multiply", otherFactors);
49459
49491
  return {
49460
49492
  value: factor3.op1.pow(y),
@@ -49463,9 +49495,9 @@ function simplifyLog(x) {
49463
49495
  }
49464
49496
  }
49465
49497
  }
49466
- if (exp2.operator === "Divide" && exp2.op1?.operator === "Log" && exp2.op1.op2?.isSame(base)) {
49498
+ if (exp3.operator === "Divide" && exp3.op1?.operator === "Log" && exp3.op1.op2?.isSame(base)) {
49467
49499
  return {
49468
- value: exp2.op1.op1.pow(ce.One.div(exp2.op2)),
49500
+ value: exp3.op1.op1.pow(ce.One.div(exp3.op2)),
49469
49501
  because: "c^(log_c(x) / y) -> x^(1/y)"
49470
49502
  };
49471
49503
  }
@@ -49605,8 +49637,8 @@ function simplifyPower(x) {
49605
49637
  }
49606
49638
  if (arg.operator === "Power") {
49607
49639
  const base = arg.op1;
49608
- const exp2 = arg.op2;
49609
- if (base && exp2?.isSame(rootIndex)) {
49640
+ const exp3 = arg.op2;
49641
+ if (base && exp3?.isSame(rootIndex)) {
49610
49642
  if (rootIndex.isEven === true) {
49611
49643
  return {
49612
49644
  value: ce._fn("Abs", [base]),
@@ -49617,8 +49649,8 @@ function simplifyPower(x) {
49617
49649
  return { value: base, because: "root(x^n, n) -> x when n odd" };
49618
49650
  }
49619
49651
  }
49620
- if (base && exp2) {
49621
- const resultExp = exp2.div(rootIndex);
49652
+ if (base && exp3) {
49653
+ const resultExp = exp3.div(rootIndex);
49622
49654
  if (rootIndex.isEven === true) {
49623
49655
  if (resultExp.isInteger === true) {
49624
49656
  return {
@@ -49638,7 +49670,7 @@ function simplifyPower(x) {
49638
49670
  }
49639
49671
  }
49640
49672
  }
49641
- if (rootIndex.isOdd === true && exp2.isInteger === true) {
49673
+ if (rootIndex.isOdd === true && exp3.isInteger === true) {
49642
49674
  return {
49643
49675
  value: base.pow(resultExp),
49644
49676
  because: "root(x^m, n) -> x^{m/n} when n is odd"
@@ -49691,22 +49723,22 @@ function simplifyPower(x) {
49691
49723
  }
49692
49724
  if (arg.operator === "Power") {
49693
49725
  const base = arg.op1;
49694
- const exp2 = arg.op2;
49695
- if (base && exp2) {
49696
- if (exp2.is(2) && base.isNonNegative === true) {
49726
+ const exp3 = arg.op2;
49727
+ if (base && exp3) {
49728
+ if (exp3.is(2) && base.isNonNegative === true) {
49697
49729
  return { value: base, because: "sqrt(x^2) -> x when x >= 0" };
49698
49730
  }
49699
- if (exp2.is(2)) {
49731
+ if (exp3.is(2)) {
49700
49732
  return { value: ce._fn("Abs", [base]), because: "sqrt(x^2) -> |x|" };
49701
49733
  }
49702
- if (exp2.isEven === true && exp2.isPositive === true) {
49734
+ if (exp3.isEven === true && exp3.isPositive === true) {
49703
49735
  return {
49704
- value: ce._fn("Abs", [base]).pow(exp2.div(2)),
49736
+ value: ce._fn("Abs", [base]).pow(exp3.div(2)),
49705
49737
  because: "sqrt(x^{2n}) -> |x|^n"
49706
49738
  };
49707
49739
  }
49708
- if (exp2.isOdd === true && exp2.isInteger === true && exp2.isPositive === true) {
49709
- const n = exp2.sub(ce.One).div(2);
49740
+ if (exp3.isOdd === true && exp3.isInteger === true && exp3.isPositive === true) {
49741
+ const n = exp3.sub(ce.One).div(2);
49710
49742
  if (n.isPositive === true) {
49711
49743
  return {
49712
49744
  value: ce._fn("Abs", [base]).pow(n).mul(ce._fn("Sqrt", [base])),
@@ -49722,13 +49754,13 @@ function simplifyPower(x) {
49722
49754
  for (const factor3 of arg.ops) {
49723
49755
  if (factor3.operator === "Power" && factor3.op1 && factor3.op2) {
49724
49756
  const base = factor3.op1;
49725
- const exp2 = factor3.op2;
49726
- if (exp2.is(2)) {
49757
+ const exp3 = factor3.op2;
49758
+ if (exp3.is(2)) {
49727
49759
  perfectSquares.push(ce._fn("Abs", [base]));
49728
- } else if (exp2.isEven === true && exp2.isPositive === true) {
49729
- perfectSquares.push(ce._fn("Abs", [base]).pow(exp2.div(2)));
49730
- } else if (exp2.isInteger === true && exp2.isPositive === true && exp2.isOdd === true) {
49731
- const n = exp2.sub(ce.One).div(2);
49760
+ } else if (exp3.isEven === true && exp3.isPositive === true) {
49761
+ perfectSquares.push(ce._fn("Abs", [base]).pow(exp3.div(2)));
49762
+ } else if (exp3.isInteger === true && exp3.isPositive === true && exp3.isOdd === true) {
49763
+ const n = exp3.sub(ce.One).div(2);
49732
49764
  if (n.isPositive === true) {
49733
49765
  perfectSquares.push(ce._fn("Abs", [base]).pow(n));
49734
49766
  }
@@ -49758,13 +49790,13 @@ function simplifyPower(x) {
49758
49790
  }
49759
49791
  if (op === "Power") {
49760
49792
  const base = x.op1;
49761
- const exp2 = x.op2;
49762
- if (!base || !exp2) return void 0;
49763
- if (base.is(0) && exp2.isPositive === true) {
49793
+ const exp3 = x.op2;
49794
+ if (!base || !exp3) return void 0;
49795
+ if (base.is(0) && exp3.isPositive === true) {
49764
49796
  return { value: ce.Zero, because: "0^x -> 0 when x > 0" };
49765
49797
  }
49766
49798
  if (base.is(-1)) {
49767
- const rat = asRational(exp2);
49799
+ const rat = asRational(exp3);
49768
49800
  if (rat) {
49769
49801
  const [num, denom] = rat;
49770
49802
  const numN = Number(num);
@@ -49778,7 +49810,7 @@ function simplifyPower(x) {
49778
49810
  }
49779
49811
  }
49780
49812
  if (base.operator === "Multiply" && base.ops) {
49781
- const rat = asRational(exp2);
49813
+ const rat = asRational(exp3);
49782
49814
  if (rat) {
49783
49815
  const [num, denom] = rat;
49784
49816
  const numN = Number(num);
@@ -49802,15 +49834,15 @@ function simplifyPower(x) {
49802
49834
  );
49803
49835
  const posBase = newFactors.length === 1 ? newFactors[0] : ce._fn("Multiply", newFactors);
49804
49836
  return {
49805
- value: posBase.pow(exp2).neg(),
49837
+ value: posBase.pow(exp3).neg(),
49806
49838
  because: "(-a*b)^{p/q} -> -(a*b)^{p/q} when p,q odd"
49807
49839
  };
49808
49840
  }
49809
49841
  }
49810
49842
  }
49811
49843
  }
49812
- if (base.operator === "Multiply" && base.ops && exp2.isInteger === true) {
49813
- const newFactors = base.ops.map((factor3) => factor3.pow(exp2));
49844
+ if (base.operator === "Multiply" && base.ops && exp3.isInteger === true) {
49845
+ const newFactors = base.ops.map((factor3) => factor3.pow(exp3));
49814
49846
  return {
49815
49847
  value: ce._fn("Multiply", newFactors),
49816
49848
  because: "(a*b)^n -> a^n * b^n"
@@ -49818,19 +49850,19 @@ function simplifyPower(x) {
49818
49850
  }
49819
49851
  if (base.operator === "Negate" && base.op1) {
49820
49852
  const innerBase = base.op1;
49821
- if (exp2.isEven === true) {
49853
+ if (exp3.isEven === true) {
49822
49854
  return {
49823
- value: innerBase.pow(exp2),
49855
+ value: innerBase.pow(exp3),
49824
49856
  because: "(-x)^n -> x^n when n is even"
49825
49857
  };
49826
49858
  }
49827
- if (exp2.isOdd === true) {
49859
+ if (exp3.isOdd === true) {
49828
49860
  return {
49829
- value: innerBase.pow(exp2).neg(),
49861
+ value: innerBase.pow(exp3).neg(),
49830
49862
  because: "(-x)^n -> -x^n when n is odd"
49831
49863
  };
49832
49864
  }
49833
- const rat = asRational(exp2);
49865
+ const rat = asRational(exp3);
49834
49866
  if (rat) {
49835
49867
  const [num, denom] = rat;
49836
49868
  const numN = Number(num);
@@ -49840,13 +49872,13 @@ function simplifyPower(x) {
49840
49872
  const denomIsOdd = denomN % 2 !== 0;
49841
49873
  if (numIsEven && denomIsOdd) {
49842
49874
  return {
49843
- value: innerBase.pow(exp2),
49875
+ value: innerBase.pow(exp3),
49844
49876
  because: "(-x)^{n/m} -> x^{n/m} when n is even and m is odd"
49845
49877
  };
49846
49878
  }
49847
49879
  if (numIsOdd && denomIsOdd) {
49848
49880
  return {
49849
- value: innerBase.pow(exp2).neg(),
49881
+ value: innerBase.pow(exp3).neg(),
49850
49882
  because: "(-x)^{n/m} -> -x^{n/m} when n and m are odd"
49851
49883
  };
49852
49884
  }
@@ -49854,15 +49886,15 @@ function simplifyPower(x) {
49854
49886
  }
49855
49887
  if (base.operator === "Sqrt" && base.op1) {
49856
49888
  const innerBase = base.op1;
49857
- if (exp2.isEven === true) {
49889
+ if (exp3.isEven === true) {
49858
49890
  return {
49859
- value: innerBase.pow(exp2.div(2)),
49891
+ value: innerBase.pow(exp3.div(2)),
49860
49892
  because: "sqrt(x)^n -> x^{n/2} when n is even"
49861
49893
  };
49862
49894
  }
49863
49895
  if (innerBase.isNonNegative === true) {
49864
49896
  return {
49865
- value: innerBase.pow(exp2.div(2)),
49897
+ value: innerBase.pow(exp3.div(2)),
49866
49898
  because: "sqrt(x)^n -> x^{n/2} when x >= 0"
49867
49899
  };
49868
49900
  }
@@ -49870,7 +49902,7 @@ function simplifyPower(x) {
49870
49902
  if (base.operator === "Root" && base.op1 && base.op2) {
49871
49903
  const innerBase = base.op1;
49872
49904
  const rootIndex = base.op2;
49873
- const resultExp = exp2.div(rootIndex);
49905
+ const resultExp = exp3.div(rootIndex);
49874
49906
  if (resultExp.isInteger === true || innerBase.isNonNegative === true) {
49875
49907
  return {
49876
49908
  value: innerBase.pow(resultExp),
@@ -49882,13 +49914,13 @@ function simplifyPower(x) {
49882
49914
  const innerBase = base.op1;
49883
49915
  const innerExp = base.op2;
49884
49916
  if (innerBase && innerExp) {
49885
- const bothIntegers = innerExp.isInteger === true && exp2.isInteger === true;
49917
+ const bothIntegers = innerExp.isInteger === true && exp3.isInteger === true;
49886
49918
  const baseNonNeg = innerBase.isNonNegative === true;
49887
- const productIrrational = innerExp.mul(exp2).isRational === false;
49888
- const atLeastOnePositive = innerExp.isPositive === true || exp2.isPositive === true;
49919
+ const productIrrational = innerExp.mul(exp3).isRational === false;
49920
+ const atLeastOnePositive = innerExp.isPositive === true || exp3.isPositive === true;
49889
49921
  if ((bothIntegers || baseNonNeg || productIrrational) && atLeastOnePositive) {
49890
49922
  return {
49891
- value: innerBase.pow(innerExp.mul(exp2)),
49923
+ value: innerBase.pow(innerExp.mul(exp3)),
49892
49924
  because: "(x^n)^m -> x^{n*m}"
49893
49925
  };
49894
49926
  }
@@ -49897,18 +49929,18 @@ function simplifyPower(x) {
49897
49929
  if (base.operator === "Divide" && base.op2?.is(0) === false) {
49898
49930
  const num = base.op1;
49899
49931
  const denom = base.op2;
49900
- if (exp2.operator === "Negate") {
49932
+ if (exp3.operator === "Negate") {
49901
49933
  return {
49902
- value: denom.div(num).pow(exp2.op1),
49934
+ value: denom.div(num).pow(exp3.op1),
49903
49935
  because: "(a/b)^{-n} -> (b/a)^n"
49904
49936
  };
49905
49937
  }
49906
- if (exp2.is(-1)) {
49938
+ if (exp3.is(-1)) {
49907
49939
  return { value: denom.div(num), because: "(a/b)^{-1} -> b/a" };
49908
49940
  }
49909
- if (exp2.isNegative === true && exp2.isNumberLiteral) {
49941
+ if (exp3.isNegative === true && exp3.isNumberLiteral) {
49910
49942
  return {
49911
- value: denom.div(num).pow(exp2.neg()),
49943
+ value: denom.div(num).pow(exp3.neg()),
49912
49944
  because: "(a/b)^{-n} -> (b/a)^n"
49913
49945
  };
49914
49946
  }
@@ -49944,10 +49976,10 @@ function simplifyPower(x) {
49944
49976
  }
49945
49977
  if (denom.operator === "Power" && denom.op1?.is(0) === false) {
49946
49978
  const base = denom.op1;
49947
- const exp2 = denom.op2;
49948
- if (exp2?.operator === "Negate") {
49979
+ const exp3 = denom.op2;
49980
+ if (exp3?.operator === "Negate") {
49949
49981
  return {
49950
- value: num.mul(base.pow(exp2.op1)),
49982
+ value: num.mul(base.pow(exp3.op1)),
49951
49983
  because: "a / b^{-n} -> a * b^n"
49952
49984
  };
49953
49985
  }
@@ -49970,9 +50002,9 @@ function simplifyPower(x) {
49970
50002
  if (denom.operator === "Power" && denom.op1?.operator === "Divide" && denom.op1.op2?.is(0) === false) {
49971
50003
  const fracNum = denom.op1.op1;
49972
50004
  const fracDenom = denom.op1.op2;
49973
- const exp2 = denom.op2;
50005
+ const exp3 = denom.op2;
49974
50006
  return {
49975
- value: num.mul(fracDenom.div(fracNum).pow(exp2)),
50007
+ value: num.mul(fracDenom.div(fracNum).pow(exp3)),
49976
50008
  because: "a / (b/c)^d -> a * (c/b)^d"
49977
50009
  };
49978
50010
  }
@@ -50147,12 +50179,12 @@ function simplifyTrig(x) {
50147
50179
  const left = arg.op1;
50148
50180
  const right = arg.op2;
50149
50181
  if (left?.symbol === "Pi" && right) {
50150
- const sign2 = PI_MINUS_SIGN[op];
50151
- if (sign2 !== void 0) {
50182
+ const sign3 = PI_MINUS_SIGN[op];
50183
+ if (sign3 !== void 0) {
50152
50184
  const result = ce._fn(op, [right]);
50153
50185
  return {
50154
- value: sign2 === 1 ? result : result.neg(),
50155
- because: `${op}(\u03C0 - x) -> ${sign2 === 1 ? "" : "-"}${op}(x)`
50186
+ value: sign3 === 1 ? result : result.neg(),
50187
+ because: `${op}(\u03C0 - x) -> ${sign3 === 1 ? "" : "-"}${op}(x)`
50156
50188
  };
50157
50189
  }
50158
50190
  }
@@ -50163,12 +50195,12 @@ function simplifyTrig(x) {
50163
50195
  const otherTerms = arg.ops.filter((_, idx) => idx !== piIndex);
50164
50196
  if (otherTerms.length === arg.ops.length - 1) {
50165
50197
  const remaining = otherTerms.length === 1 ? otherTerms[0] : ce._fn("Add", otherTerms);
50166
- const sign2 = PI_PLUS_SIGN[op];
50167
- if (sign2 !== void 0) {
50198
+ const sign3 = PI_PLUS_SIGN[op];
50199
+ if (sign3 !== void 0) {
50168
50200
  const result = ce._fn(op, [remaining]);
50169
50201
  return {
50170
- value: sign2 === 1 ? result : result.neg(),
50171
- because: `${op}(\u03C0 + x) -> ${sign2 === 1 ? "" : "-"}${op}(x)`
50202
+ value: sign3 === 1 ? result : result.neg(),
50203
+ because: `${op}(\u03C0 + x) -> ${sign3 === 1 ? "" : "-"}${op}(x)`
50172
50204
  };
50173
50205
  }
50174
50206
  }
@@ -51113,13 +51145,13 @@ var SIMPLIFY_RULES = [
51113
51145
  const otherTerms = [];
51114
51146
  for (const term of x.ops) {
51115
51147
  let base;
51116
- let exp2;
51148
+ let exp3;
51117
51149
  if (term.operator === "Power") {
51118
51150
  base = term.op1;
51119
- exp2 = term.op2;
51151
+ exp3 = term.op2;
51120
51152
  } else if (term.symbol) {
51121
51153
  base = term;
51122
- exp2 = ce.One;
51154
+ exp3 = ce.One;
51123
51155
  } else {
51124
51156
  otherTerms.push(term);
51125
51157
  continue;
@@ -51130,7 +51162,7 @@ var SIMPLIFY_RULES = [
51130
51162
  group = { base, terms: [] };
51131
51163
  baseGroups.set(baseKey, group);
51132
51164
  }
51133
- group.terms.push({ term, exp: exp2 });
51165
+ group.terms.push({ term, exp: exp3 });
51134
51166
  }
51135
51167
  let hasCombinations = false;
51136
51168
  for (const group of baseGroups.values()) {
@@ -51473,12 +51505,12 @@ var JAVASCRIPT_FUNCTIONS = {
51473
51505
  Power: (args, compile) => {
51474
51506
  const arg = args[0];
51475
51507
  if (arg === null) throw new Error("Power: no argument");
51476
- const exp2 = args[1].re;
51477
- if (exp2 === 0.5) return `Math.sqrt(${compile(arg)})`;
51478
- if (exp2 === 1 / 3) return `Math.cbrt(${compile(arg)})`;
51479
- if (exp2 === 1) return compile(arg);
51480
- if (exp2 === -1) return `(1 / (${compile(arg)}))`;
51481
- if (exp2 === -0.5) return `(1 / Math.sqrt(${compile(arg)}))`;
51508
+ const exp3 = args[1].re;
51509
+ if (exp3 === 0.5) return `Math.sqrt(${compile(arg)})`;
51510
+ if (exp3 === 1 / 3) return `Math.cbrt(${compile(arg)})`;
51511
+ if (exp3 === 1) return compile(arg);
51512
+ if (exp3 === -1) return `(1 / (${compile(arg)}))`;
51513
+ if (exp3 === -0.5) return `(1 / Math.sqrt(${compile(arg)}))`;
51482
51514
  return `Math.pow(${compile(arg)}, ${compile(args[1])})`;
51483
51515
  },
51484
51516
  Range: (args, compile) => {
@@ -51512,13 +51544,13 @@ var JAVASCRIPT_FUNCTIONS = {
51512
51544
  }
51513
51545
  return `Array.from({length: Math.floor((${stop} - ${start}) / ${step}) + 1}, (_, i) => ${start} + i * ${step})`;
51514
51546
  },
51515
- Root: ([arg, exp2], compile) => {
51547
+ Root: ([arg, exp3], compile) => {
51516
51548
  if (arg === null) throw new Error("Root: no argument");
51517
- if (exp2 === null) return `Math.sqrt(${compile(arg)})`;
51518
- if (exp2?.re === 2) return `Math.sqrt(${compile(arg)})`;
51519
- if (exp2?.re === 3) return `Math.cbrt(${compile(arg)})`;
51520
- if (!isNaN(exp2?.re)) return `Math.pow(${compile(arg)}, ${1 / exp2.re})`;
51521
- return `Math.pow(${compile(arg)}, 1 / (${compile(exp2)}))`;
51549
+ if (exp3 === null) return `Math.sqrt(${compile(arg)})`;
51550
+ if (exp3?.re === 2) return `Math.sqrt(${compile(arg)})`;
51551
+ if (exp3?.re === 3) return `Math.cbrt(${compile(arg)})`;
51552
+ if (!isNaN(exp3?.re)) return `Math.pow(${compile(arg)}, ${1 / exp3.re})`;
51553
+ return `Math.pow(${compile(arg)}, 1 / (${compile(exp3)}))`;
51522
51554
  },
51523
51555
  Random: "Math.random",
51524
51556
  Round: "Math.round",
@@ -52004,6 +52036,1611 @@ var GLSLTarget = class {
52004
52036
  }
52005
52037
  };
52006
52038
 
52039
+ // src/compute-engine/compilation/interval-javascript-target.ts
52040
+ init_base_compiler();
52041
+
52042
+ // src/compute-engine/interval/util.ts
52043
+ function ok(value) {
52044
+ return { kind: "interval", value };
52045
+ }
52046
+ function point(n) {
52047
+ return { lo: n, hi: n };
52048
+ }
52049
+ function containsExtremum(x, extremum, period) {
52050
+ const n = Math.ceil((x.lo - extremum) / period);
52051
+ const candidate = extremum + n * period;
52052
+ const EPS = 1e-15;
52053
+ return candidate >= x.lo - EPS && candidate <= x.hi + EPS;
52054
+ }
52055
+ function unionResults(a, b) {
52056
+ if (a.kind === "empty") return b;
52057
+ if (b.kind === "empty") return a;
52058
+ if (a.kind === "singular" || b.kind === "singular") {
52059
+ return { kind: "singular" };
52060
+ }
52061
+ if (a.kind === "entire" || b.kind === "entire") {
52062
+ return { kind: "entire" };
52063
+ }
52064
+ const aVal = a.value;
52065
+ const bVal = b.value;
52066
+ const aDomainClip = a.kind === "partial" ? a.domainClipped : null;
52067
+ const bDomainClip = b.kind === "partial" ? b.domainClipped : null;
52068
+ const value = {
52069
+ lo: Math.min(aVal.lo, bVal.lo),
52070
+ hi: Math.max(aVal.hi, bVal.hi)
52071
+ };
52072
+ if (aDomainClip || bDomainClip) {
52073
+ const domainClipped = mergeDomainClip(aDomainClip, bDomainClip);
52074
+ return { kind: "partial", value, domainClipped };
52075
+ }
52076
+ return { kind: "interval", value };
52077
+ }
52078
+ function mergeDomainClip(a, b) {
52079
+ if (a === "both" || b === "both") return "both";
52080
+ if (a === null) return b;
52081
+ if (b === null) return a;
52082
+ if (a === b) return a;
52083
+ return "both";
52084
+ }
52085
+ function isPoint(x) {
52086
+ return x.lo === x.hi;
52087
+ }
52088
+ function containsZero(x) {
52089
+ return x.lo <= 0 && x.hi >= 0;
52090
+ }
52091
+ function isPositive2(x) {
52092
+ return x.lo > 0;
52093
+ }
52094
+ function isNegative(x) {
52095
+ return x.hi < 0;
52096
+ }
52097
+ function isNonNegative(x) {
52098
+ return x.lo >= 0;
52099
+ }
52100
+ function isNonPositive(x) {
52101
+ return x.hi <= 0;
52102
+ }
52103
+ function width(x) {
52104
+ return x.hi - x.lo;
52105
+ }
52106
+ function midpoint(x) {
52107
+ return (x.lo + x.hi) / 2;
52108
+ }
52109
+ function getValue(result) {
52110
+ if (result.kind === "interval" || result.kind === "partial") {
52111
+ return result.value;
52112
+ }
52113
+ return void 0;
52114
+ }
52115
+ function unwrap(input) {
52116
+ if ("kind" in input) {
52117
+ if (input.kind === "interval" || input.kind === "partial") {
52118
+ return input.value;
52119
+ }
52120
+ return void 0;
52121
+ }
52122
+ return input;
52123
+ }
52124
+ function unwrapOrPropagate(...inputs) {
52125
+ const result = [];
52126
+ for (const input of inputs) {
52127
+ if ("kind" in input) {
52128
+ if (input.kind === "empty") return { kind: "empty" };
52129
+ if (input.kind === "entire") return { kind: "entire" };
52130
+ if (input.kind === "singular") return input;
52131
+ result.push(input.value);
52132
+ } else {
52133
+ result.push(input);
52134
+ }
52135
+ }
52136
+ return result;
52137
+ }
52138
+
52139
+ // src/compute-engine/interval/arithmetic.ts
52140
+ function add4(a, b) {
52141
+ const unwrapped = unwrapOrPropagate(a, b);
52142
+ if (!Array.isArray(unwrapped)) return unwrapped;
52143
+ const [aVal, bVal] = unwrapped;
52144
+ return ok({ lo: aVal.lo + bVal.lo, hi: aVal.hi + bVal.hi });
52145
+ }
52146
+ function sub2(a, b) {
52147
+ const unwrapped = unwrapOrPropagate(a, b);
52148
+ if (!Array.isArray(unwrapped)) return unwrapped;
52149
+ const [aVal, bVal] = unwrapped;
52150
+ return ok({ lo: aVal.lo - bVal.hi, hi: aVal.hi - bVal.lo });
52151
+ }
52152
+ function negate2(x) {
52153
+ const unwrapped = unwrapOrPropagate(x);
52154
+ if (!Array.isArray(unwrapped)) return unwrapped;
52155
+ const [xVal] = unwrapped;
52156
+ return ok({ lo: -xVal.hi, hi: -xVal.lo });
52157
+ }
52158
+ function _mul(a, b) {
52159
+ const products = [a.lo * b.lo, a.lo * b.hi, a.hi * b.lo, a.hi * b.hi];
52160
+ return { lo: Math.min(...products), hi: Math.max(...products) };
52161
+ }
52162
+ function mul4(a, b) {
52163
+ const unwrapped = unwrapOrPropagate(a, b);
52164
+ if (!Array.isArray(unwrapped)) return unwrapped;
52165
+ const [aVal, bVal] = unwrapped;
52166
+ return ok(_mul(aVal, bVal));
52167
+ }
52168
+ function div3(a, b) {
52169
+ const unwrapped = unwrapOrPropagate(a, b);
52170
+ if (!Array.isArray(unwrapped)) return unwrapped;
52171
+ const [aVal, bVal] = unwrapped;
52172
+ return _div(aVal, bVal);
52173
+ }
52174
+ function _div(a, b) {
52175
+ if (b.lo > 0 || b.hi < 0) {
52176
+ return ok(_mul(a, { lo: 1 / b.hi, hi: 1 / b.lo }));
52177
+ }
52178
+ if (b.lo < 0 && b.hi > 0) {
52179
+ return { kind: "singular" };
52180
+ }
52181
+ if (b.lo === 0 && b.hi > 0) {
52182
+ if (a.lo >= 0) {
52183
+ return {
52184
+ kind: "partial",
52185
+ value: { lo: a.lo / b.hi, hi: Infinity },
52186
+ domainClipped: "hi"
52187
+ };
52188
+ } else if (a.hi <= 0) {
52189
+ return {
52190
+ kind: "partial",
52191
+ value: { lo: -Infinity, hi: a.hi / b.hi },
52192
+ domainClipped: "lo"
52193
+ };
52194
+ } else {
52195
+ return { kind: "entire" };
52196
+ }
52197
+ }
52198
+ if (b.hi === 0 && b.lo < 0) {
52199
+ if (a.lo >= 0) {
52200
+ return {
52201
+ kind: "partial",
52202
+ value: { lo: -Infinity, hi: a.lo / b.lo },
52203
+ domainClipped: "lo"
52204
+ };
52205
+ } else if (a.hi <= 0) {
52206
+ return {
52207
+ kind: "partial",
52208
+ value: { lo: a.hi / b.lo, hi: Infinity },
52209
+ domainClipped: "hi"
52210
+ };
52211
+ } else {
52212
+ return { kind: "entire" };
52213
+ }
52214
+ }
52215
+ return { kind: "empty" };
52216
+ }
52217
+
52218
+ // src/compute-engine/interval/elementary.ts
52219
+ function sqrt2(x) {
52220
+ const unwrapped = unwrapOrPropagate(x);
52221
+ if (!Array.isArray(unwrapped)) return unwrapped;
52222
+ const [xVal] = unwrapped;
52223
+ return _sqrt(xVal);
52224
+ }
52225
+ function _sqrt(x) {
52226
+ if (x.hi < 0) {
52227
+ return { kind: "empty" };
52228
+ }
52229
+ if (x.lo >= 0) {
52230
+ return ok({ lo: Math.sqrt(x.lo), hi: Math.sqrt(x.hi) });
52231
+ }
52232
+ return {
52233
+ kind: "partial",
52234
+ value: { lo: 0, hi: Math.sqrt(x.hi) },
52235
+ domainClipped: "lo"
52236
+ };
52237
+ }
52238
+ function square(x) {
52239
+ const unwrapped = unwrapOrPropagate(x);
52240
+ if (!Array.isArray(unwrapped)) return unwrapped;
52241
+ const [xVal] = unwrapped;
52242
+ if (xVal.lo >= 0) {
52243
+ return ok({ lo: xVal.lo * xVal.lo, hi: xVal.hi * xVal.hi });
52244
+ } else if (xVal.hi <= 0) {
52245
+ return ok({ lo: xVal.hi * xVal.hi, hi: xVal.lo * xVal.lo });
52246
+ } else {
52247
+ return ok({ lo: 0, hi: Math.max(xVal.lo * xVal.lo, xVal.hi * xVal.hi) });
52248
+ }
52249
+ }
52250
+ function intPow2(base, n) {
52251
+ if (n === 0) return { lo: 1, hi: 1 };
52252
+ if (n === 1) return base;
52253
+ if (n % 2 === 0) {
52254
+ if (base.lo >= 0) {
52255
+ return { lo: Math.pow(base.lo, n), hi: Math.pow(base.hi, n) };
52256
+ } else if (base.hi <= 0) {
52257
+ return { lo: Math.pow(base.hi, n), hi: Math.pow(base.lo, n) };
52258
+ } else {
52259
+ return {
52260
+ lo: 0,
52261
+ hi: Math.max(Math.pow(base.lo, n), Math.pow(base.hi, n))
52262
+ };
52263
+ }
52264
+ }
52265
+ return { lo: Math.pow(base.lo, n), hi: Math.pow(base.hi, n) };
52266
+ }
52267
+ function pow3(base, exp3) {
52268
+ if (Number.isInteger(exp3)) {
52269
+ if (exp3 >= 0) {
52270
+ return ok(intPow2(base, exp3));
52271
+ } else {
52272
+ if (containsZero(base)) {
52273
+ return { kind: "singular" };
52274
+ }
52275
+ const denom = intPow2(base, -exp3);
52276
+ return ok({ lo: 1 / denom.hi, hi: 1 / denom.lo });
52277
+ }
52278
+ } else {
52279
+ if (isNegative(base)) {
52280
+ return { kind: "empty" };
52281
+ }
52282
+ if (base.lo < 0) {
52283
+ const value = exp3 > 0 ? { lo: 0, hi: Math.pow(base.hi, exp3) } : { lo: Math.pow(base.hi, exp3), hi: Infinity };
52284
+ return { kind: "partial", value, domainClipped: "lo" };
52285
+ }
52286
+ if (exp3 > 0) {
52287
+ return ok({ lo: Math.pow(base.lo, exp3), hi: Math.pow(base.hi, exp3) });
52288
+ } else {
52289
+ if (base.lo === 0) {
52290
+ return {
52291
+ kind: "partial",
52292
+ value: { lo: Math.pow(base.hi, exp3), hi: Infinity },
52293
+ domainClipped: "hi"
52294
+ };
52295
+ }
52296
+ return ok({ lo: Math.pow(base.hi, exp3), hi: Math.pow(base.lo, exp3) });
52297
+ }
52298
+ }
52299
+ }
52300
+ function powInterval(base, exp3) {
52301
+ if (base.hi <= 0) {
52302
+ return { kind: "empty" };
52303
+ }
52304
+ if (base.lo <= 0) {
52305
+ const posBase = { lo: Math.max(base.lo, Number.EPSILON), hi: base.hi };
52306
+ const corners2 = [
52307
+ Math.pow(posBase.lo, exp3.lo),
52308
+ Math.pow(posBase.lo, exp3.hi),
52309
+ Math.pow(posBase.hi, exp3.lo),
52310
+ Math.pow(posBase.hi, exp3.hi)
52311
+ ];
52312
+ return {
52313
+ kind: "partial",
52314
+ value: { lo: Math.min(...corners2), hi: Math.max(...corners2) },
52315
+ domainClipped: "lo"
52316
+ };
52317
+ }
52318
+ const corners = [
52319
+ Math.pow(base.lo, exp3.lo),
52320
+ Math.pow(base.lo, exp3.hi),
52321
+ Math.pow(base.hi, exp3.lo),
52322
+ Math.pow(base.hi, exp3.hi)
52323
+ ];
52324
+ return ok({ lo: Math.min(...corners), hi: Math.max(...corners) });
52325
+ }
52326
+ function exp2(x) {
52327
+ const unwrapped = unwrapOrPropagate(x);
52328
+ if (!Array.isArray(unwrapped)) return unwrapped;
52329
+ const [xVal] = unwrapped;
52330
+ return ok({ lo: Math.exp(xVal.lo), hi: Math.exp(xVal.hi) });
52331
+ }
52332
+ function ln2(x) {
52333
+ if (x.hi <= 0) {
52334
+ return { kind: "empty" };
52335
+ }
52336
+ if (x.lo > 0) {
52337
+ return ok({ lo: Math.log(x.lo), hi: Math.log(x.hi) });
52338
+ }
52339
+ return {
52340
+ kind: "partial",
52341
+ value: { lo: -Infinity, hi: Math.log(x.hi) },
52342
+ domainClipped: "lo"
52343
+ };
52344
+ }
52345
+ function log102(x) {
52346
+ if (x.hi <= 0) {
52347
+ return { kind: "empty" };
52348
+ }
52349
+ if (x.lo > 0) {
52350
+ return ok({ lo: Math.log10(x.lo), hi: Math.log10(x.hi) });
52351
+ }
52352
+ return {
52353
+ kind: "partial",
52354
+ value: { lo: -Infinity, hi: Math.log10(x.hi) },
52355
+ domainClipped: "lo"
52356
+ };
52357
+ }
52358
+ function log22(x) {
52359
+ if (x.hi <= 0) {
52360
+ return { kind: "empty" };
52361
+ }
52362
+ if (x.lo > 0) {
52363
+ return ok({ lo: Math.log2(x.lo), hi: Math.log2(x.hi) });
52364
+ }
52365
+ return {
52366
+ kind: "partial",
52367
+ value: { lo: -Infinity, hi: Math.log2(x.hi) },
52368
+ domainClipped: "lo"
52369
+ };
52370
+ }
52371
+ function abs2(x) {
52372
+ if (x.lo >= 0) {
52373
+ return ok(x);
52374
+ }
52375
+ if (x.hi <= 0) {
52376
+ return ok({ lo: -x.hi, hi: -x.lo });
52377
+ }
52378
+ return ok({ lo: 0, hi: Math.max(-x.lo, x.hi) });
52379
+ }
52380
+ function floor2(x) {
52381
+ return ok({ lo: Math.floor(x.lo), hi: Math.floor(x.hi) });
52382
+ }
52383
+ function ceil2(x) {
52384
+ return ok({ lo: Math.ceil(x.lo), hi: Math.ceil(x.hi) });
52385
+ }
52386
+ function round2(x) {
52387
+ return ok({ lo: Math.round(x.lo), hi: Math.round(x.hi) });
52388
+ }
52389
+ function min2(a, b) {
52390
+ return ok({ lo: Math.min(a.lo, b.lo), hi: Math.min(a.hi, b.hi) });
52391
+ }
52392
+ function max2(a, b) {
52393
+ return ok({ lo: Math.max(a.lo, b.lo), hi: Math.max(a.hi, b.hi) });
52394
+ }
52395
+ function mod2(a, b) {
52396
+ if (containsZero(b)) {
52397
+ return { kind: "singular" };
52398
+ }
52399
+ const bAbs = Math.max(Math.abs(b.lo), Math.abs(b.hi));
52400
+ const aWidth = a.hi - a.lo;
52401
+ if (aWidth >= bAbs) {
52402
+ return ok({ lo: 0, hi: bAbs });
52403
+ }
52404
+ const modLo = (a.lo % bAbs + bAbs) % bAbs;
52405
+ const modHi = (a.hi % bAbs + bAbs) % bAbs;
52406
+ if (modLo <= modHi) {
52407
+ return ok({ lo: modLo, hi: modHi });
52408
+ } else {
52409
+ return ok({ lo: 0, hi: bAbs });
52410
+ }
52411
+ }
52412
+ function sign2(x) {
52413
+ if (x.lo > 0) return ok({ lo: 1, hi: 1 });
52414
+ if (x.hi < 0) return ok({ lo: -1, hi: -1 });
52415
+ if (x.lo === 0 && x.hi === 0) return ok({ lo: 0, hi: 0 });
52416
+ if (x.lo < 0 && x.hi > 0) return ok({ lo: -1, hi: 1 });
52417
+ if (x.lo === 0) return ok({ lo: 0, hi: 1 });
52418
+ return ok({ lo: -1, hi: 0 });
52419
+ }
52420
+
52421
+ // src/compute-engine/interval/trigonometric.ts
52422
+ var TWO_PI = 2 * Math.PI;
52423
+ var PI2 = Math.PI;
52424
+ var HALF_PI = Math.PI / 2;
52425
+ var THREE_HALF_PI = 3 * Math.PI / 2;
52426
+ function sin2(x) {
52427
+ if (x.hi - x.lo >= TWO_PI) {
52428
+ return ok({ lo: -1, hi: 1 });
52429
+ }
52430
+ const sinLo = Math.sin(x.lo);
52431
+ const sinHi = Math.sin(x.hi);
52432
+ let lo = Math.min(sinLo, sinHi);
52433
+ let hi = Math.max(sinLo, sinHi);
52434
+ if (containsExtremum(x, HALF_PI, TWO_PI)) {
52435
+ hi = 1;
52436
+ }
52437
+ if (containsExtremum(x, THREE_HALF_PI, TWO_PI)) {
52438
+ lo = -1;
52439
+ }
52440
+ return ok({ lo, hi });
52441
+ }
52442
+ function cos2(x) {
52443
+ if (x.hi - x.lo >= TWO_PI) {
52444
+ return ok({ lo: -1, hi: 1 });
52445
+ }
52446
+ const cosLo = Math.cos(x.lo);
52447
+ const cosHi = Math.cos(x.hi);
52448
+ let lo = Math.min(cosLo, cosHi);
52449
+ let hi = Math.max(cosLo, cosHi);
52450
+ if (containsExtremum(x, 0, TWO_PI)) {
52451
+ hi = 1;
52452
+ }
52453
+ if (containsExtremum(x, PI2, TWO_PI)) {
52454
+ lo = -1;
52455
+ }
52456
+ return ok({ lo, hi });
52457
+ }
52458
+ function tan2(x) {
52459
+ if (x.hi - x.lo >= PI2) {
52460
+ return { kind: "singular" };
52461
+ }
52462
+ if (containsExtremum(x, HALF_PI, PI2)) {
52463
+ const n = Math.ceil((x.lo - HALF_PI) / PI2);
52464
+ const poleAt = HALF_PI + n * PI2;
52465
+ return { kind: "singular", at: poleAt };
52466
+ }
52467
+ const tanLo = Math.tan(x.lo);
52468
+ const tanHi = Math.tan(x.hi);
52469
+ if (tanLo > 1e10 && tanHi < -1e10 || tanLo < -1e10 && tanHi > 1e10) {
52470
+ return { kind: "singular" };
52471
+ }
52472
+ return ok({ lo: tanLo, hi: tanHi });
52473
+ }
52474
+ function cot(x) {
52475
+ if (x.hi - x.lo >= PI2) {
52476
+ return { kind: "singular" };
52477
+ }
52478
+ if (containsExtremum(x, 0, PI2)) {
52479
+ const n = Math.ceil(x.lo / PI2);
52480
+ const poleAt = n * PI2;
52481
+ return { kind: "singular", at: poleAt };
52482
+ }
52483
+ const cotLo = 1 / Math.tan(x.lo);
52484
+ const cotHi = 1 / Math.tan(x.hi);
52485
+ return ok({ lo: Math.min(cotLo, cotHi), hi: Math.max(cotLo, cotHi) });
52486
+ }
52487
+ function sec(x) {
52488
+ if (x.hi - x.lo >= PI2) {
52489
+ return { kind: "singular" };
52490
+ }
52491
+ if (containsExtremum(x, HALF_PI, PI2)) {
52492
+ const n = Math.ceil((x.lo - HALF_PI) / PI2);
52493
+ const poleAt = HALF_PI + n * PI2;
52494
+ return { kind: "singular", at: poleAt };
52495
+ }
52496
+ const secLo = 1 / Math.cos(x.lo);
52497
+ const secHi = 1 / Math.cos(x.hi);
52498
+ let lo = Math.min(secLo, secHi);
52499
+ let hi = Math.max(secLo, secHi);
52500
+ if (containsExtremum(x, 0, TWO_PI)) {
52501
+ lo = Math.min(lo, 1);
52502
+ hi = Math.max(hi, 1);
52503
+ }
52504
+ if (containsExtremum(x, PI2, TWO_PI)) {
52505
+ lo = Math.min(lo, -1);
52506
+ hi = Math.max(hi, -1);
52507
+ }
52508
+ return ok({ lo, hi });
52509
+ }
52510
+ function csc(x) {
52511
+ if (x.hi - x.lo >= PI2) {
52512
+ return { kind: "singular" };
52513
+ }
52514
+ if (containsExtremum(x, 0, PI2)) {
52515
+ const n = Math.ceil(x.lo / PI2);
52516
+ const poleAt = n * PI2;
52517
+ return { kind: "singular", at: poleAt };
52518
+ }
52519
+ const cscLo = 1 / Math.sin(x.lo);
52520
+ const cscHi = 1 / Math.sin(x.hi);
52521
+ let lo = Math.min(cscLo, cscHi);
52522
+ let hi = Math.max(cscLo, cscHi);
52523
+ if (containsExtremum(x, HALF_PI, TWO_PI)) {
52524
+ lo = Math.min(lo, 1);
52525
+ hi = Math.max(hi, 1);
52526
+ }
52527
+ if (containsExtremum(x, THREE_HALF_PI, TWO_PI)) {
52528
+ lo = Math.min(lo, -1);
52529
+ hi = Math.max(hi, -1);
52530
+ }
52531
+ return ok({ lo, hi });
52532
+ }
52533
+ function asin2(x) {
52534
+ if (x.lo > 1 || x.hi < -1) {
52535
+ return { kind: "empty" };
52536
+ }
52537
+ if (x.lo < -1 || x.hi > 1) {
52538
+ const clippedLo = Math.max(x.lo, -1);
52539
+ const clippedHi = Math.min(x.hi, 1);
52540
+ return {
52541
+ kind: "partial",
52542
+ value: { lo: Math.asin(clippedLo), hi: Math.asin(clippedHi) },
52543
+ domainClipped: x.lo < -1 && x.hi > 1 ? "both" : x.lo < -1 ? "lo" : "hi"
52544
+ };
52545
+ }
52546
+ return ok({ lo: Math.asin(x.lo), hi: Math.asin(x.hi) });
52547
+ }
52548
+ function acos2(x) {
52549
+ if (x.lo > 1 || x.hi < -1) {
52550
+ return { kind: "empty" };
52551
+ }
52552
+ if (x.lo < -1 || x.hi > 1) {
52553
+ const clippedLo = Math.max(x.lo, -1);
52554
+ const clippedHi = Math.min(x.hi, 1);
52555
+ return {
52556
+ kind: "partial",
52557
+ value: { lo: Math.acos(clippedHi), hi: Math.acos(clippedLo) },
52558
+ domainClipped: x.lo < -1 && x.hi > 1 ? "both" : x.lo < -1 ? "lo" : "hi"
52559
+ };
52560
+ }
52561
+ return ok({ lo: Math.acos(x.hi), hi: Math.acos(x.lo) });
52562
+ }
52563
+ function atan3(x) {
52564
+ return ok({ lo: Math.atan(x.lo), hi: Math.atan(x.hi) });
52565
+ }
52566
+ function atan22(y, x) {
52567
+ if (y.lo === y.hi && x.lo === x.hi) {
52568
+ const result = Math.atan2(y.lo, x.lo);
52569
+ return ok({ lo: result, hi: result });
52570
+ }
52571
+ const angles = [];
52572
+ angles.push(Math.atan2(y.lo, x.lo));
52573
+ angles.push(Math.atan2(y.lo, x.hi));
52574
+ angles.push(Math.atan2(y.hi, x.lo));
52575
+ angles.push(Math.atan2(y.hi, x.hi));
52576
+ if (x.lo < 0 && y.lo < 0 && y.hi > 0) {
52577
+ return ok({ lo: -PI2, hi: PI2 });
52578
+ }
52579
+ return ok({ lo: Math.min(...angles), hi: Math.max(...angles) });
52580
+ }
52581
+ function sinh3(x) {
52582
+ return ok({ lo: Math.sinh(x.lo), hi: Math.sinh(x.hi) });
52583
+ }
52584
+ function cosh3(x) {
52585
+ if (x.lo >= 0) {
52586
+ return ok({ lo: Math.cosh(x.lo), hi: Math.cosh(x.hi) });
52587
+ } else if (x.hi <= 0) {
52588
+ return ok({ lo: Math.cosh(x.hi), hi: Math.cosh(x.lo) });
52589
+ } else {
52590
+ return ok({ lo: 1, hi: Math.max(Math.cosh(x.lo), Math.cosh(x.hi)) });
52591
+ }
52592
+ }
52593
+ function tanh2(x) {
52594
+ return ok({ lo: Math.tanh(x.lo), hi: Math.tanh(x.hi) });
52595
+ }
52596
+ function asinh2(x) {
52597
+ return ok({ lo: Math.asinh(x.lo), hi: Math.asinh(x.hi) });
52598
+ }
52599
+ function acosh2(x) {
52600
+ if (x.hi < 1) {
52601
+ return { kind: "empty" };
52602
+ }
52603
+ if (x.lo < 1) {
52604
+ return {
52605
+ kind: "partial",
52606
+ value: { lo: 0, hi: Math.acosh(x.hi) },
52607
+ domainClipped: "lo"
52608
+ };
52609
+ }
52610
+ return ok({ lo: Math.acosh(x.lo), hi: Math.acosh(x.hi) });
52611
+ }
52612
+ function atanh2(x) {
52613
+ if (x.lo >= 1 || x.hi <= -1) {
52614
+ return { kind: "empty" };
52615
+ }
52616
+ if (x.lo <= -1 || x.hi >= 1) {
52617
+ const clippedLo = Math.max(x.lo, -1 + Number.EPSILON);
52618
+ const clippedHi = Math.min(x.hi, 1 - Number.EPSILON);
52619
+ return {
52620
+ kind: "partial",
52621
+ value: { lo: Math.atanh(clippedLo), hi: Math.atanh(clippedHi) },
52622
+ domainClipped: x.lo <= -1 && x.hi >= 1 ? "both" : x.lo <= -1 ? "lo" : "hi"
52623
+ };
52624
+ }
52625
+ return ok({ lo: Math.atanh(x.lo), hi: Math.atanh(x.hi) });
52626
+ }
52627
+
52628
+ // src/compute-engine/interval/comparison.ts
52629
+ function less(a, b) {
52630
+ if (a.hi < b.lo) return "true";
52631
+ if (a.lo >= b.hi) return "false";
52632
+ return "maybe";
52633
+ }
52634
+ function lessEqual(a, b) {
52635
+ if (a.hi <= b.lo) return "true";
52636
+ if (a.lo > b.hi) return "false";
52637
+ return "maybe";
52638
+ }
52639
+ function greater(a, b) {
52640
+ if (a.lo > b.hi) return "true";
52641
+ if (a.hi <= b.lo) return "false";
52642
+ return "maybe";
52643
+ }
52644
+ function greaterEqual(a, b) {
52645
+ if (a.lo >= b.hi) return "true";
52646
+ if (a.hi < b.lo) return "false";
52647
+ return "maybe";
52648
+ }
52649
+ function equal(a, b) {
52650
+ if (a.lo === a.hi && b.lo === b.hi && a.lo === b.lo) return "true";
52651
+ if (a.hi < b.lo || b.hi < a.lo) return "false";
52652
+ return "maybe";
52653
+ }
52654
+ function notEqual(a, b) {
52655
+ const eq2 = equal(a, b);
52656
+ if (eq2 === "true") return "false";
52657
+ if (eq2 === "false") return "true";
52658
+ return "maybe";
52659
+ }
52660
+ function and(a, b) {
52661
+ if (a === "false" || b === "false") return "false";
52662
+ if (a === "true" && b === "true") return "true";
52663
+ return "maybe";
52664
+ }
52665
+ function or(a, b) {
52666
+ if (a === "true" || b === "true") return "true";
52667
+ if (a === "false" && b === "false") return "false";
52668
+ return "maybe";
52669
+ }
52670
+ function not(a) {
52671
+ if (a === "true") return "false";
52672
+ if (a === "false") return "true";
52673
+ return "maybe";
52674
+ }
52675
+ function piecewise(x, condition, trueBranch, falseBranch) {
52676
+ const cond = condition(x);
52677
+ switch (cond) {
52678
+ case "true":
52679
+ return trueBranch(x);
52680
+ case "false":
52681
+ return falseBranch(x);
52682
+ case "maybe":
52683
+ const t = trueBranch(x);
52684
+ const f = falseBranch(x);
52685
+ return unionResults(t, f);
52686
+ }
52687
+ }
52688
+ function clamp2(x, lo, hi) {
52689
+ const resultLo = Math.max(x.lo, lo.lo);
52690
+ const resultHi = Math.min(x.hi, hi.hi);
52691
+ if (resultLo > resultHi) {
52692
+ return { kind: "empty" };
52693
+ }
52694
+ return { kind: "interval", value: { lo: resultLo, hi: resultHi } };
52695
+ }
52696
+
52697
+ // src/compute-engine/interval/index.ts
52698
+ var IntervalArithmetic = {
52699
+ // Utilities
52700
+ ok,
52701
+ point,
52702
+ containsExtremum,
52703
+ unionResults,
52704
+ mergeDomainClip,
52705
+ isPoint,
52706
+ containsZero,
52707
+ isPositive: isPositive2,
52708
+ isNegative,
52709
+ isNonNegative,
52710
+ isNonPositive,
52711
+ width,
52712
+ midpoint,
52713
+ getValue,
52714
+ unwrap,
52715
+ unwrapOrPropagate,
52716
+ // Arithmetic
52717
+ add: add4,
52718
+ sub: sub2,
52719
+ mul: mul4,
52720
+ div: div3,
52721
+ negate: negate2,
52722
+ // Elementary
52723
+ sqrt: sqrt2,
52724
+ square,
52725
+ pow: pow3,
52726
+ powInterval,
52727
+ exp: exp2,
52728
+ ln: ln2,
52729
+ log10: log102,
52730
+ log2: log22,
52731
+ abs: abs2,
52732
+ floor: floor2,
52733
+ ceil: ceil2,
52734
+ round: round2,
52735
+ min: min2,
52736
+ max: max2,
52737
+ mod: mod2,
52738
+ sign: sign2,
52739
+ // Trigonometric
52740
+ sin: sin2,
52741
+ cos: cos2,
52742
+ tan: tan2,
52743
+ cot,
52744
+ sec,
52745
+ csc,
52746
+ asin: asin2,
52747
+ acos: acos2,
52748
+ atan: atan3,
52749
+ atan2: atan22,
52750
+ sinh: sinh3,
52751
+ cosh: cosh3,
52752
+ tanh: tanh2,
52753
+ asinh: asinh2,
52754
+ acosh: acosh2,
52755
+ atanh: atanh2,
52756
+ // Comparison
52757
+ less,
52758
+ lessEqual,
52759
+ greater,
52760
+ greaterEqual,
52761
+ equal,
52762
+ notEqual,
52763
+ and,
52764
+ or,
52765
+ not,
52766
+ piecewise,
52767
+ clamp: clamp2
52768
+ };
52769
+
52770
+ // src/compute-engine/compilation/interval-javascript-target.ts
52771
+ var INTERVAL_JAVASCRIPT_OPERATORS = {
52772
+ // We use high precedence since these become function calls
52773
+ Add: ["_IA.add", 20],
52774
+ Negate: ["_IA.negate", 20],
52775
+ Subtract: ["_IA.sub", 20],
52776
+ Multiply: ["_IA.mul", 20],
52777
+ Divide: ["_IA.div", 20],
52778
+ // Comparisons return BoolInterval
52779
+ Equal: ["_IA.equal", 20],
52780
+ NotEqual: ["_IA.notEqual", 20],
52781
+ LessEqual: ["_IA.lessEqual", 20],
52782
+ GreaterEqual: ["_IA.greaterEqual", 20],
52783
+ Less: ["_IA.less", 20],
52784
+ Greater: ["_IA.greater", 20],
52785
+ And: ["_IA.and", 20],
52786
+ Or: ["_IA.or", 20],
52787
+ Not: ["_IA.not", 20]
52788
+ };
52789
+ var INTERVAL_JAVASCRIPT_FUNCTIONS = {
52790
+ // Basic arithmetic - using function call syntax
52791
+ Add: (args, compile) => {
52792
+ if (args.length === 0) return "_IA.point(0)";
52793
+ if (args.length === 1) return compile(args[0]);
52794
+ let result = compile(args[0]);
52795
+ for (let i = 1; i < args.length; i++) {
52796
+ result = `_IA.add(${result}, ${compile(args[i])})`;
52797
+ }
52798
+ return result;
52799
+ },
52800
+ Subtract: (args, compile) => {
52801
+ if (args.length === 0) return "_IA.point(0)";
52802
+ if (args.length === 1) return `_IA.negate(${compile(args[0])})`;
52803
+ if (args.length === 2)
52804
+ return `_IA.sub(${compile(args[0])}, ${compile(args[1])})`;
52805
+ let result = compile(args[0]);
52806
+ for (let i = 1; i < args.length; i++) {
52807
+ result = `_IA.sub(${result}, ${compile(args[i])})`;
52808
+ }
52809
+ return result;
52810
+ },
52811
+ Multiply: (args, compile) => {
52812
+ if (args.length === 0) return "_IA.point(1)";
52813
+ if (args.length === 1) return compile(args[0]);
52814
+ let result = compile(args[0]);
52815
+ for (let i = 1; i < args.length; i++) {
52816
+ result = `_IA.mul(${result}, ${compile(args[i])})`;
52817
+ }
52818
+ return result;
52819
+ },
52820
+ Divide: (args, compile) => {
52821
+ if (args.length === 0) return "_IA.point(1)";
52822
+ if (args.length === 1) return compile(args[0]);
52823
+ if (args.length === 2)
52824
+ return `_IA.div(${compile(args[0])}, ${compile(args[1])})`;
52825
+ let result = compile(args[0]);
52826
+ for (let i = 1; i < args.length; i++) {
52827
+ result = `_IA.div(${result}, ${compile(args[i])})`;
52828
+ }
52829
+ return result;
52830
+ },
52831
+ Negate: (args, compile) => `_IA.negate(${compile(args[0])})`,
52832
+ // Elementary functions
52833
+ Abs: (args, compile) => `_IA.abs(${compile(args[0])})`,
52834
+ Ceiling: (args, compile) => `_IA.ceil(${compile(args[0])})`,
52835
+ Exp: (args, compile) => `_IA.exp(${compile(args[0])})`,
52836
+ Floor: (args, compile) => `_IA.floor(${compile(args[0])})`,
52837
+ Ln: (args, compile) => `_IA.ln(${compile(args[0])})`,
52838
+ Log: (args, compile) => {
52839
+ if (args.length === 1) return `_IA.log10(${compile(args[0])})`;
52840
+ return `_IA.div(_IA.ln(${compile(args[0])}), _IA.ln(${compile(args[1])}))`;
52841
+ },
52842
+ Lb: (args, compile) => `_IA.log2(${compile(args[0])})`,
52843
+ Max: (args, compile) => {
52844
+ if (args.length === 0) return "_IA.point(-Infinity)";
52845
+ if (args.length === 1) return compile(args[0]);
52846
+ let result = compile(args[0]);
52847
+ for (let i = 1; i < args.length; i++) {
52848
+ result = `_IA.max(${result}, ${compile(args[i])})`;
52849
+ }
52850
+ return result;
52851
+ },
52852
+ Min: (args, compile) => {
52853
+ if (args.length === 0) return "_IA.point(Infinity)";
52854
+ if (args.length === 1) return compile(args[0]);
52855
+ let result = compile(args[0]);
52856
+ for (let i = 1; i < args.length; i++) {
52857
+ result = `_IA.min(${result}, ${compile(args[i])})`;
52858
+ }
52859
+ return result;
52860
+ },
52861
+ Power: (args, compile) => {
52862
+ const base = args[0];
52863
+ const exp3 = args[1];
52864
+ if (base === null) throw new Error("Power: no argument");
52865
+ if (base.symbol === "ExponentialE") {
52866
+ return `_IA.exp(${compile(exp3)})`;
52867
+ }
52868
+ if (exp3?.isNumberLiteral && exp3.im === 0) {
52869
+ const expVal = exp3.re;
52870
+ if (expVal === 0.5) return `_IA.sqrt(${compile(base)})`;
52871
+ if (expVal === 2) return `_IA.square(${compile(base)})`;
52872
+ return `_IA.pow(${compile(base)}, ${expVal})`;
52873
+ }
52874
+ return `_IA.powInterval(${compile(base)}, ${compile(exp3)})`;
52875
+ },
52876
+ Root: (args, compile) => {
52877
+ const [arg, exp3] = args;
52878
+ if (arg === null) throw new Error("Root: no argument");
52879
+ if (exp3 === null) return `_IA.sqrt(${compile(arg)})`;
52880
+ if (exp3?.re === 2) return `_IA.sqrt(${compile(arg)})`;
52881
+ if (exp3?.isNumberLiteral && exp3.im === 0) {
52882
+ return `_IA.pow(${compile(arg)}, ${1 / exp3.re})`;
52883
+ }
52884
+ return `_IA.powInterval(${compile(arg)}, _IA.div(_IA.point(1), ${compile(exp3)}))`;
52885
+ },
52886
+ Round: (args, compile) => `_IA.round(${compile(args[0])})`,
52887
+ Sgn: (args, compile) => `_IA.sign(${compile(args[0])})`,
52888
+ Sqrt: (args, compile) => `_IA.sqrt(${compile(args[0])})`,
52889
+ Square: (args, compile) => `_IA.square(${compile(args[0])})`,
52890
+ // Trigonometric functions
52891
+ Sin: (args, compile) => `_IA.sin(${compile(args[0])})`,
52892
+ Cos: (args, compile) => `_IA.cos(${compile(args[0])})`,
52893
+ Tan: (args, compile) => `_IA.tan(${compile(args[0])})`,
52894
+ Cot: (args, compile) => `_IA.cot(${compile(args[0])})`,
52895
+ Sec: (args, compile) => `_IA.sec(${compile(args[0])})`,
52896
+ Csc: (args, compile) => `_IA.csc(${compile(args[0])})`,
52897
+ Arcsin: (args, compile) => `_IA.asin(${compile(args[0])})`,
52898
+ Arccos: (args, compile) => `_IA.acos(${compile(args[0])})`,
52899
+ Arctan: (args, compile) => `_IA.atan(${compile(args[0])})`,
52900
+ // Hyperbolic functions
52901
+ Sinh: (args, compile) => `_IA.sinh(${compile(args[0])})`,
52902
+ Cosh: (args, compile) => `_IA.cosh(${compile(args[0])})`,
52903
+ Tanh: (args, compile) => `_IA.tanh(${compile(args[0])})`,
52904
+ Arsinh: (args, compile) => `_IA.asinh(${compile(args[0])})`,
52905
+ Arcosh: (args, compile) => `_IA.acosh(${compile(args[0])})`,
52906
+ Artanh: (args, compile) => `_IA.atanh(${compile(args[0])})`,
52907
+ // Inverse trig (alternative names)
52908
+ Asin: (args, compile) => `_IA.asin(${compile(args[0])})`,
52909
+ Acos: (args, compile) => `_IA.acos(${compile(args[0])})`,
52910
+ Atan: (args, compile) => `_IA.atan(${compile(args[0])})`,
52911
+ // Mod
52912
+ Mod: (args, compile) => `_IA.mod(${compile(args[0])}, ${compile(args[1])})`,
52913
+ // Conditionals
52914
+ If: (args, compile) => {
52915
+ if (args.length !== 3) throw new Error("If: wrong number of arguments");
52916
+ return `_IA.piecewise(
52917
+ ${compile(args[0])},
52918
+ (_x) => ${compile(args[0])},
52919
+ (_x) => ${compile(args[1])},
52920
+ (_x) => ${compile(args[2])}
52921
+ )`;
52922
+ }
52923
+ };
52924
+ var ComputeEngineIntervalFunction = class extends Function {
52925
+ IA = IntervalArithmetic;
52926
+ constructor(body, preamble = "") {
52927
+ super(
52928
+ "_IA",
52929
+ "_",
52930
+ preamble ? `${preamble};return ${body}` : `return ${body}`
52931
+ );
52932
+ return new Proxy(this, {
52933
+ apply: (target, thisArg, argumentsList) => {
52934
+ const processedArgs = argumentsList.map(processInput);
52935
+ return super.apply(thisArg, [this.IA, ...processedArgs]);
52936
+ },
52937
+ get: (target, prop) => {
52938
+ if (prop === "toString") return () => body;
52939
+ if (prop === "isCompiled") return true;
52940
+ return target[prop];
52941
+ }
52942
+ });
52943
+ }
52944
+ };
52945
+ function processInput(input) {
52946
+ if (input === null || input === void 0) {
52947
+ return input;
52948
+ }
52949
+ if (typeof input === "object" && "lo" in input && "hi" in input) {
52950
+ return input;
52951
+ }
52952
+ if (typeof input === "object") {
52953
+ const result = {};
52954
+ for (const [key, value] of Object.entries(input)) {
52955
+ result[key] = processInput(value);
52956
+ }
52957
+ return result;
52958
+ }
52959
+ if (typeof input === "number") {
52960
+ return { lo: input, hi: input };
52961
+ }
52962
+ return input;
52963
+ }
52964
+ var IntervalJavaScriptTarget = class {
52965
+ getOperators() {
52966
+ return INTERVAL_JAVASCRIPT_OPERATORS;
52967
+ }
52968
+ getFunctions() {
52969
+ return INTERVAL_JAVASCRIPT_FUNCTIONS;
52970
+ }
52971
+ createTarget(options = {}) {
52972
+ return {
52973
+ language: "interval-javascript",
52974
+ // Don't use operators - all arithmetic goes through functions
52975
+ // because interval arithmetic returns IntervalResult, not numbers
52976
+ operators: () => void 0,
52977
+ functions: (id) => INTERVAL_JAVASCRIPT_FUNCTIONS[id],
52978
+ var: (id) => {
52979
+ const result = {
52980
+ Pi: "_IA.point(Math.PI)",
52981
+ ExponentialE: "_IA.point(Math.E)",
52982
+ NaN: "{ lo: NaN, hi: NaN }",
52983
+ ImaginaryUnit: "{ lo: NaN, hi: NaN }",
52984
+ Half: "_IA.point(0.5)",
52985
+ MachineEpsilon: "_IA.point(Number.EPSILON)",
52986
+ GoldenRatio: "_IA.point((1 + Math.sqrt(5)) / 2)",
52987
+ CatalanConstant: "_IA.point(0.91596559417721901)",
52988
+ EulerGamma: "_IA.point(0.57721566490153286)"
52989
+ };
52990
+ return result[id];
52991
+ },
52992
+ string: (str) => JSON.stringify(str),
52993
+ number: (n) => `_IA.point(${n})`,
52994
+ indent: 0,
52995
+ ws: (s) => s ?? "",
52996
+ preamble: "",
52997
+ ...options
52998
+ };
52999
+ }
53000
+ compileToExecutable(expr, options = {}) {
53001
+ const { functions, vars, preamble } = options;
53002
+ const unknowns = expr.unknowns;
53003
+ const namedFunctions = {};
53004
+ let preambleImports = "";
53005
+ if (functions) {
53006
+ for (const [k, v] of Object.entries(functions)) {
53007
+ if (typeof v === "function") {
53008
+ preambleImports += `const ${k} = ${v.toString()};
53009
+ `;
53010
+ namedFunctions[k] = k;
53011
+ } else if (typeof v === "string") {
53012
+ namedFunctions[k] = v;
53013
+ }
53014
+ }
53015
+ }
53016
+ const target = this.createTarget({
53017
+ functions: (id) => namedFunctions?.[id] ? namedFunctions[id] : INTERVAL_JAVASCRIPT_FUNCTIONS[id],
53018
+ var: (id) => {
53019
+ if (vars && id in vars) return vars[id];
53020
+ const constants = {
53021
+ Pi: "_IA.point(Math.PI)",
53022
+ ExponentialE: "_IA.point(Math.E)",
53023
+ NaN: "{ lo: NaN, hi: NaN }",
53024
+ ImaginaryUnit: "{ lo: NaN, hi: NaN }",
53025
+ Half: "_IA.point(0.5)",
53026
+ MachineEpsilon: "_IA.point(Number.EPSILON)",
53027
+ GoldenRatio: "_IA.point((1 + Math.sqrt(5)) / 2)",
53028
+ CatalanConstant: "_IA.point(0.91596559417721901)",
53029
+ EulerGamma: "_IA.point(0.57721566490153286)"
53030
+ };
53031
+ if (id in constants) return constants[id];
53032
+ if (unknowns.includes(id)) return `_.${id}`;
53033
+ return void 0;
53034
+ },
53035
+ preamble: (preamble ?? "") + preambleImports
53036
+ });
53037
+ return compileToIntervalTarget(expr, target);
53038
+ }
53039
+ };
53040
+ function compileToIntervalTarget(expr, target) {
53041
+ const js = BaseCompiler.compile(expr, target);
53042
+ return new ComputeEngineIntervalFunction(
53043
+ js,
53044
+ target.preamble
53045
+ );
53046
+ }
53047
+
53048
+ // src/compute-engine/compilation/interval-glsl-target.ts
53049
+ init_base_compiler();
53050
+ var GLSL_INTERVAL_LIBRARY = `
53051
+ // Interval Arithmetic Library for GLSL
53052
+ // Intervals are represented as vec2(lo, hi)
53053
+ // Results use IntervalResult struct with status flags
53054
+
53055
+ // Status constants
53056
+ const float IA_NORMAL = 0.0;
53057
+ const float IA_EMPTY = 1.0;
53058
+ const float IA_ENTIRE = 2.0;
53059
+ const float IA_SINGULAR = 3.0;
53060
+ const float IA_PARTIAL_LO = 4.0;
53061
+ const float IA_PARTIAL_HI = 5.0;
53062
+ const float IA_PARTIAL_BOTH = 6.0;
53063
+
53064
+ // Interval result struct
53065
+ struct IntervalResult {
53066
+ vec2 value; // (lo, hi)
53067
+ float status; // Status flag
53068
+ };
53069
+
53070
+ // Epsilon for conservative bounds
53071
+ const float IA_EPS = 1e-6;
53072
+ const float IA_HUGE = 1e38;
53073
+
53074
+ // Create a point interval
53075
+ vec2 ia_point(float x) {
53076
+ return vec2(x, x);
53077
+ }
53078
+
53079
+ // Create interval result
53080
+ IntervalResult ia_ok(vec2 v) {
53081
+ return IntervalResult(v, IA_NORMAL);
53082
+ }
53083
+
53084
+ IntervalResult ia_empty() {
53085
+ return IntervalResult(vec2(0.0), IA_EMPTY);
53086
+ }
53087
+
53088
+ IntervalResult ia_entire() {
53089
+ return IntervalResult(vec2(-IA_HUGE, IA_HUGE), IA_ENTIRE);
53090
+ }
53091
+
53092
+ IntervalResult ia_singular(float at) {
53093
+ return IntervalResult(vec2(at, at), IA_SINGULAR);
53094
+ }
53095
+
53096
+ IntervalResult ia_partial(vec2 v, float clip) {
53097
+ return IntervalResult(v, clip);
53098
+ }
53099
+
53100
+ // Addition
53101
+ IntervalResult ia_add(vec2 a, vec2 b) {
53102
+ return ia_ok(vec2(a.x + b.x - IA_EPS, a.y + b.y + IA_EPS));
53103
+ }
53104
+
53105
+ // Subtraction
53106
+ IntervalResult ia_sub(vec2 a, vec2 b) {
53107
+ return ia_ok(vec2(a.x - b.y - IA_EPS, a.y - b.x + IA_EPS));
53108
+ }
53109
+
53110
+ // Negation
53111
+ IntervalResult ia_negate(vec2 x) {
53112
+ return ia_ok(vec2(-x.y, -x.x));
53113
+ }
53114
+
53115
+ // Multiplication helper (returns vec2)
53116
+ vec2 ia_mul_raw(vec2 a, vec2 b) {
53117
+ float p1 = a.x * b.x;
53118
+ float p2 = a.x * b.y;
53119
+ float p3 = a.y * b.x;
53120
+ float p4 = a.y * b.y;
53121
+ return vec2(
53122
+ min(min(p1, p2), min(p3, p4)) - IA_EPS,
53123
+ max(max(p1, p2), max(p3, p4)) + IA_EPS
53124
+ );
53125
+ }
53126
+
53127
+ // Multiplication
53128
+ IntervalResult ia_mul(vec2 a, vec2 b) {
53129
+ return ia_ok(ia_mul_raw(a, b));
53130
+ }
53131
+
53132
+ // Division
53133
+ IntervalResult ia_div(vec2 a, vec2 b) {
53134
+ // Case 1: Divisor entirely positive or negative
53135
+ if (b.x > 0.0 || b.y < 0.0) {
53136
+ return ia_ok(ia_mul_raw(a, vec2(1.0 / b.y, 1.0 / b.x)));
53137
+ }
53138
+
53139
+ // Case 2: Divisor strictly contains zero
53140
+ if (b.x < 0.0 && b.y > 0.0) {
53141
+ return ia_singular(0.0);
53142
+ }
53143
+
53144
+ // Case 3: Divisor touches zero at lower bound [0, c]
53145
+ if (b.x == 0.0 && b.y > 0.0) {
53146
+ if (a.x >= 0.0) {
53147
+ return ia_partial(vec2(a.x / b.y, IA_HUGE), IA_PARTIAL_HI);
53148
+ } else if (a.y <= 0.0) {
53149
+ return ia_partial(vec2(-IA_HUGE, a.y / b.y), IA_PARTIAL_LO);
53150
+ } else {
53151
+ return ia_entire();
53152
+ }
53153
+ }
53154
+
53155
+ // Case 4: Divisor touches zero at upper bound [c, 0]
53156
+ if (b.y == 0.0 && b.x < 0.0) {
53157
+ if (a.x >= 0.0) {
53158
+ return ia_partial(vec2(-IA_HUGE, a.x / b.x), IA_PARTIAL_LO);
53159
+ } else if (a.y <= 0.0) {
53160
+ return ia_partial(vec2(a.y / b.x, IA_HUGE), IA_PARTIAL_HI);
53161
+ } else {
53162
+ return ia_entire();
53163
+ }
53164
+ }
53165
+
53166
+ // Case 5: Divisor is [0, 0]
53167
+ return ia_empty();
53168
+ }
53169
+
53170
+ // Square root
53171
+ IntervalResult ia_sqrt(vec2 x) {
53172
+ if (x.y < 0.0) {
53173
+ return ia_empty();
53174
+ }
53175
+ if (x.x >= 0.0) {
53176
+ return ia_ok(vec2(sqrt(x.x), sqrt(x.y) + IA_EPS));
53177
+ }
53178
+ return ia_partial(vec2(0.0, sqrt(x.y) + IA_EPS), IA_PARTIAL_LO);
53179
+ }
53180
+
53181
+ // Square
53182
+ IntervalResult ia_square(vec2 x) {
53183
+ if (x.x >= 0.0) {
53184
+ return ia_ok(vec2(x.x * x.x - IA_EPS, x.y * x.y + IA_EPS));
53185
+ } else if (x.y <= 0.0) {
53186
+ return ia_ok(vec2(x.y * x.y - IA_EPS, x.x * x.x + IA_EPS));
53187
+ } else {
53188
+ float m = max(-x.x, x.y);
53189
+ return ia_ok(vec2(0.0, m * m + IA_EPS));
53190
+ }
53191
+ }
53192
+
53193
+ // Exponential
53194
+ IntervalResult ia_exp(vec2 x) {
53195
+ return ia_ok(vec2(exp(x.x) - IA_EPS, exp(x.y) + IA_EPS));
53196
+ }
53197
+
53198
+ // Natural logarithm
53199
+ IntervalResult ia_ln(vec2 x) {
53200
+ if (x.y <= 0.0) {
53201
+ return ia_empty();
53202
+ }
53203
+ if (x.x > 0.0) {
53204
+ return ia_ok(vec2(log(x.x) - IA_EPS, log(x.y) + IA_EPS));
53205
+ }
53206
+ return ia_partial(vec2(-IA_HUGE, log(x.y) + IA_EPS), IA_PARTIAL_LO);
53207
+ }
53208
+
53209
+ // Absolute value
53210
+ IntervalResult ia_abs(vec2 x) {
53211
+ if (x.x >= 0.0) {
53212
+ return ia_ok(x);
53213
+ }
53214
+ if (x.y <= 0.0) {
53215
+ return ia_ok(vec2(-x.y, -x.x));
53216
+ }
53217
+ return ia_ok(vec2(0.0, max(-x.x, x.y)));
53218
+ }
53219
+
53220
+ // Sign function
53221
+ IntervalResult ia_sign(vec2 x) {
53222
+ if (x.x > 0.0) return ia_ok(vec2(1.0, 1.0));
53223
+ if (x.y < 0.0) return ia_ok(vec2(-1.0, -1.0));
53224
+ if (x.x == 0.0 && x.y == 0.0) return ia_ok(vec2(0.0, 0.0));
53225
+ if (x.x < 0.0 && x.y > 0.0) return ia_ok(vec2(-1.0, 1.0));
53226
+ if (x.x == 0.0) return ia_ok(vec2(0.0, 1.0));
53227
+ return ia_ok(vec2(-1.0, 0.0));
53228
+ }
53229
+
53230
+ // Floor
53231
+ IntervalResult ia_floor(vec2 x) {
53232
+ return ia_ok(vec2(floor(x.x), floor(x.y)));
53233
+ }
53234
+
53235
+ // Ceiling
53236
+ IntervalResult ia_ceil(vec2 x) {
53237
+ return ia_ok(vec2(ceil(x.x), ceil(x.y)));
53238
+ }
53239
+
53240
+ // Min of two intervals
53241
+ IntervalResult ia_min(vec2 a, vec2 b) {
53242
+ return ia_ok(vec2(min(a.x, b.x), min(a.y, b.y)));
53243
+ }
53244
+
53245
+ // Max of two intervals
53246
+ IntervalResult ia_max(vec2 a, vec2 b) {
53247
+ return ia_ok(vec2(max(a.x, b.x), max(a.y, b.y)));
53248
+ }
53249
+
53250
+ // Power with constant exponent
53251
+ IntervalResult ia_pow(vec2 base, float exp) {
53252
+ if (exp == 0.0) return ia_ok(vec2(1.0, 1.0));
53253
+ if (exp == 1.0) return ia_ok(base);
53254
+ if (exp == 2.0) return ia_square(base);
53255
+ if (exp == 0.5) return ia_sqrt(base);
53256
+
53257
+ // General case - requires positive base for non-integer exponents
53258
+ if (base.y < 0.0) {
53259
+ return ia_empty();
53260
+ }
53261
+ if (base.x < 0.0) {
53262
+ // Partial domain
53263
+ if (exp > 0.0) {
53264
+ return ia_partial(vec2(0.0, pow(base.y, exp) + IA_EPS), IA_PARTIAL_LO);
53265
+ } else {
53266
+ return ia_partial(vec2(pow(base.y, exp) - IA_EPS, IA_HUGE), IA_PARTIAL_LO);
53267
+ }
53268
+ }
53269
+
53270
+ // Entirely non-negative
53271
+ if (exp > 0.0) {
53272
+ return ia_ok(vec2(pow(base.x, exp) - IA_EPS, pow(base.y, exp) + IA_EPS));
53273
+ } else {
53274
+ if (base.x == 0.0) {
53275
+ return ia_partial(vec2(pow(base.y, exp) - IA_EPS, IA_HUGE), IA_PARTIAL_HI);
53276
+ }
53277
+ return ia_ok(vec2(pow(base.y, exp) - IA_EPS, pow(base.x, exp) + IA_EPS));
53278
+ }
53279
+ }
53280
+
53281
+ // Check if interval contains extremum at (extremum + n * period)
53282
+ bool ia_contains_extremum(vec2 x, float extremum, float period) {
53283
+ float n = ceil((x.x - extremum) / period);
53284
+ float candidate = extremum + n * period;
53285
+ return candidate >= x.x - 1e-7 && candidate <= x.y + 1e-7;
53286
+ }
53287
+
53288
+ // Sine
53289
+ IntervalResult ia_sin(vec2 x) {
53290
+ const float TWO_PI = 6.28318530718;
53291
+ const float HALF_PI = 1.57079632679;
53292
+ const float THREE_HALF_PI = 4.71238898038;
53293
+
53294
+ if (x.y - x.x >= TWO_PI) {
53295
+ return ia_ok(vec2(-1.0, 1.0));
53296
+ }
53297
+
53298
+ float sinLo = sin(x.x);
53299
+ float sinHi = sin(x.y);
53300
+ float lo = min(sinLo, sinHi);
53301
+ float hi = max(sinLo, sinHi);
53302
+
53303
+ if (ia_contains_extremum(x, HALF_PI, TWO_PI)) hi = 1.0;
53304
+ if (ia_contains_extremum(x, THREE_HALF_PI, TWO_PI)) lo = -1.0;
53305
+
53306
+ return ia_ok(vec2(lo - IA_EPS, hi + IA_EPS));
53307
+ }
53308
+
53309
+ // Cosine
53310
+ IntervalResult ia_cos(vec2 x) {
53311
+ const float TWO_PI = 6.28318530718;
53312
+ const float PI = 3.14159265359;
53313
+
53314
+ if (x.y - x.x >= TWO_PI) {
53315
+ return ia_ok(vec2(-1.0, 1.0));
53316
+ }
53317
+
53318
+ float cosLo = cos(x.x);
53319
+ float cosHi = cos(x.y);
53320
+ float lo = min(cosLo, cosHi);
53321
+ float hi = max(cosLo, cosHi);
53322
+
53323
+ if (ia_contains_extremum(x, 0.0, TWO_PI)) hi = 1.0;
53324
+ if (ia_contains_extremum(x, PI, TWO_PI)) lo = -1.0;
53325
+
53326
+ return ia_ok(vec2(lo - IA_EPS, hi + IA_EPS));
53327
+ }
53328
+
53329
+ // Tangent
53330
+ IntervalResult ia_tan(vec2 x) {
53331
+ const float PI = 3.14159265359;
53332
+ const float HALF_PI = 1.57079632679;
53333
+
53334
+ if (x.y - x.x >= PI) {
53335
+ return ia_singular(0.0);
53336
+ }
53337
+
53338
+ if (ia_contains_extremum(x, HALF_PI, PI)) {
53339
+ float n = ceil((x.x - HALF_PI) / PI);
53340
+ float poleAt = HALF_PI + n * PI;
53341
+ return ia_singular(poleAt);
53342
+ }
53343
+
53344
+ float tanLo = tan(x.x);
53345
+ float tanHi = tan(x.y);
53346
+
53347
+ if ((tanLo > 1e10 && tanHi < -1e10) || (tanLo < -1e10 && tanHi > 1e10)) {
53348
+ return ia_singular(0.0);
53349
+ }
53350
+
53351
+ return ia_ok(vec2(tanLo - IA_EPS, tanHi + IA_EPS));
53352
+ }
53353
+
53354
+ // Arc sine
53355
+ IntervalResult ia_asin(vec2 x) {
53356
+ if (x.x > 1.0 || x.y < -1.0) {
53357
+ return ia_empty();
53358
+ }
53359
+
53360
+ vec2 clipped = vec2(max(x.x, -1.0), min(x.y, 1.0));
53361
+
53362
+ if (x.x < -1.0 || x.y > 1.0) {
53363
+ float clip = (x.x < -1.0 && x.y > 1.0) ? IA_PARTIAL_BOTH :
53364
+ (x.x < -1.0) ? IA_PARTIAL_LO : IA_PARTIAL_HI;
53365
+ return ia_partial(vec2(asin(clipped.x) - IA_EPS, asin(clipped.y) + IA_EPS), clip);
53366
+ }
53367
+
53368
+ return ia_ok(vec2(asin(x.x) - IA_EPS, asin(x.y) + IA_EPS));
53369
+ }
53370
+
53371
+ // Arc cosine
53372
+ IntervalResult ia_acos(vec2 x) {
53373
+ if (x.x > 1.0 || x.y < -1.0) {
53374
+ return ia_empty();
53375
+ }
53376
+
53377
+ vec2 clipped = vec2(max(x.x, -1.0), min(x.y, 1.0));
53378
+
53379
+ if (x.x < -1.0 || x.y > 1.0) {
53380
+ float clip = (x.x < -1.0 && x.y > 1.0) ? IA_PARTIAL_BOTH :
53381
+ (x.x < -1.0) ? IA_PARTIAL_LO : IA_PARTIAL_HI;
53382
+ // acos is decreasing, so bounds swap
53383
+ return ia_partial(vec2(acos(clipped.y) - IA_EPS, acos(clipped.x) + IA_EPS), clip);
53384
+ }
53385
+
53386
+ // acos is decreasing
53387
+ return ia_ok(vec2(acos(x.y) - IA_EPS, acos(x.x) + IA_EPS));
53388
+ }
53389
+
53390
+ // Arc tangent
53391
+ IntervalResult ia_atan(vec2 x) {
53392
+ return ia_ok(vec2(atan(x.x) - IA_EPS, atan(x.y) + IA_EPS));
53393
+ }
53394
+
53395
+ // Hyperbolic sine
53396
+ IntervalResult ia_sinh(vec2 x) {
53397
+ return ia_ok(vec2(sinh(x.x) - IA_EPS, sinh(x.y) + IA_EPS));
53398
+ }
53399
+
53400
+ // Hyperbolic cosine
53401
+ IntervalResult ia_cosh(vec2 x) {
53402
+ if (x.x >= 0.0) {
53403
+ return ia_ok(vec2(cosh(x.x) - IA_EPS, cosh(x.y) + IA_EPS));
53404
+ } else if (x.y <= 0.0) {
53405
+ return ia_ok(vec2(cosh(x.y) - IA_EPS, cosh(x.x) + IA_EPS));
53406
+ } else {
53407
+ return ia_ok(vec2(1.0 - IA_EPS, max(cosh(x.x), cosh(x.y)) + IA_EPS));
53408
+ }
53409
+ }
53410
+
53411
+ // Hyperbolic tangent
53412
+ IntervalResult ia_tanh(vec2 x) {
53413
+ return ia_ok(vec2(tanh(x.x) - IA_EPS, tanh(x.y) + IA_EPS));
53414
+ }
53415
+ `;
53416
+ var INTERVAL_GLSL_OPERATORS = {
53417
+ Add: ["ia_add", 20],
53418
+ Negate: ["ia_negate", 20],
53419
+ Subtract: ["ia_sub", 20],
53420
+ Multiply: ["ia_mul", 20],
53421
+ Divide: ["ia_div", 20]
53422
+ };
53423
+ var INTERVAL_GLSL_FUNCTIONS = {
53424
+ Add: (args, compile) => {
53425
+ if (args.length === 0) return "ia_point(0.0)";
53426
+ if (args.length === 1) return compile(args[0]);
53427
+ let result = compile(args[0]);
53428
+ for (let i = 1; i < args.length; i++) {
53429
+ result = `ia_add(${result}, ${compile(args[i])})`;
53430
+ }
53431
+ return result;
53432
+ },
53433
+ Subtract: (args, compile) => {
53434
+ if (args.length === 0) return "ia_point(0.0)";
53435
+ if (args.length === 1) return `ia_negate(${compile(args[0])})`;
53436
+ let result = compile(args[0]);
53437
+ for (let i = 1; i < args.length; i++) {
53438
+ result = `ia_sub(${result}, ${compile(args[i])})`;
53439
+ }
53440
+ return result;
53441
+ },
53442
+ Multiply: (args, compile) => {
53443
+ if (args.length === 0) return "ia_point(1.0)";
53444
+ if (args.length === 1) return compile(args[0]);
53445
+ let result = compile(args[0]);
53446
+ for (let i = 1; i < args.length; i++) {
53447
+ result = `ia_mul(${result}, ${compile(args[i])})`;
53448
+ }
53449
+ return result;
53450
+ },
53451
+ Divide: (args, compile) => {
53452
+ if (args.length === 0) return "ia_point(1.0)";
53453
+ if (args.length === 1) return compile(args[0]);
53454
+ let result = compile(args[0]);
53455
+ for (let i = 1; i < args.length; i++) {
53456
+ result = `ia_div(${result}, ${compile(args[i])})`;
53457
+ }
53458
+ return result;
53459
+ },
53460
+ Negate: (args, compile) => `ia_negate(${compile(args[0])})`,
53461
+ // Elementary functions
53462
+ Abs: (args, compile) => `ia_abs(${compile(args[0])})`,
53463
+ Ceiling: (args, compile) => `ia_ceil(${compile(args[0])})`,
53464
+ Exp: (args, compile) => `ia_exp(${compile(args[0])})`,
53465
+ Floor: (args, compile) => `ia_floor(${compile(args[0])})`,
53466
+ Ln: (args, compile) => `ia_ln(${compile(args[0])})`,
53467
+ Max: (args, compile) => {
53468
+ if (args.length === 0) return "ia_point(-1e38)";
53469
+ if (args.length === 1) return compile(args[0]);
53470
+ let result = compile(args[0]);
53471
+ for (let i = 1; i < args.length; i++) {
53472
+ result = `ia_max(${result}, ${compile(args[i])})`;
53473
+ }
53474
+ return result;
53475
+ },
53476
+ Min: (args, compile) => {
53477
+ if (args.length === 0) return "ia_point(1e38)";
53478
+ if (args.length === 1) return compile(args[0]);
53479
+ let result = compile(args[0]);
53480
+ for (let i = 1; i < args.length; i++) {
53481
+ result = `ia_min(${result}, ${compile(args[i])})`;
53482
+ }
53483
+ return result;
53484
+ },
53485
+ Power: (args, compile) => {
53486
+ const base = args[0];
53487
+ const exp3 = args[1];
53488
+ if (base === null) throw new Error("Power: no argument");
53489
+ if (base.symbol === "ExponentialE") {
53490
+ return `ia_exp(${compile(exp3)})`;
53491
+ }
53492
+ if (exp3?.isNumberLiteral && exp3.im === 0) {
53493
+ const expVal = exp3.re;
53494
+ if (expVal === 2) return `ia_square(${compile(base)})`;
53495
+ return `ia_pow(${compile(base)}, ${expVal})`;
53496
+ }
53497
+ throw new Error("Interval GLSL does not support variable exponents");
53498
+ },
53499
+ Sgn: (args, compile) => `ia_sign(${compile(args[0])})`,
53500
+ Sqrt: (args, compile) => `ia_sqrt(${compile(args[0])})`,
53501
+ Square: (args, compile) => `ia_square(${compile(args[0])})`,
53502
+ // Trigonometric functions
53503
+ Sin: (args, compile) => `ia_sin(${compile(args[0])})`,
53504
+ Cos: (args, compile) => `ia_cos(${compile(args[0])})`,
53505
+ Tan: (args, compile) => `ia_tan(${compile(args[0])})`,
53506
+ Arcsin: (args, compile) => `ia_asin(${compile(args[0])})`,
53507
+ Arccos: (args, compile) => `ia_acos(${compile(args[0])})`,
53508
+ Arctan: (args, compile) => `ia_atan(${compile(args[0])})`,
53509
+ // Hyperbolic functions
53510
+ Sinh: (args, compile) => `ia_sinh(${compile(args[0])})`,
53511
+ Cosh: (args, compile) => `ia_cosh(${compile(args[0])})`,
53512
+ Tanh: (args, compile) => `ia_tanh(${compile(args[0])})`
53513
+ };
53514
+ var IntervalGLSLTarget = class {
53515
+ getOperators() {
53516
+ return INTERVAL_GLSL_OPERATORS;
53517
+ }
53518
+ getFunctions() {
53519
+ return INTERVAL_GLSL_FUNCTIONS;
53520
+ }
53521
+ /**
53522
+ * Get the GLSL interval library code.
53523
+ *
53524
+ * This should be included in shaders that use interval arithmetic.
53525
+ */
53526
+ getLibrary() {
53527
+ return GLSL_INTERVAL_LIBRARY;
53528
+ }
53529
+ createTarget(options = {}) {
53530
+ return {
53531
+ language: "interval-glsl",
53532
+ // Don't use operators - all arithmetic goes through functions
53533
+ // because interval arithmetic returns IntervalResult, not numbers
53534
+ operators: () => void 0,
53535
+ functions: (id) => INTERVAL_GLSL_FUNCTIONS[id],
53536
+ var: (id) => {
53537
+ const constants = {
53538
+ Pi: "ia_point(3.14159265359)",
53539
+ ExponentialE: "ia_point(2.71828182846)",
53540
+ GoldenRatio: "ia_point(1.61803398875)",
53541
+ CatalanConstant: "ia_point(0.91596559417)",
53542
+ EulerGamma: "ia_point(0.57721566490)"
53543
+ };
53544
+ if (id in constants) return constants[id];
53545
+ return id;
53546
+ },
53547
+ string: (str) => JSON.stringify(str),
53548
+ number: (n) => {
53549
+ const str = n.toString();
53550
+ const numStr = !str.includes(".") && !str.includes("e") && !str.includes("E") ? `${str}.0` : str;
53551
+ return `ia_point(${numStr})`;
53552
+ },
53553
+ indent: 0,
53554
+ ws: (s) => s ?? "",
53555
+ preamble: "",
53556
+ ...options
53557
+ };
53558
+ }
53559
+ compileToExecutable(expr, options = {}) {
53560
+ const { functions, vars } = options;
53561
+ const target = this.createTarget({
53562
+ functions: (id) => {
53563
+ if (functions && id in functions) {
53564
+ const fn = functions[id];
53565
+ if (typeof fn === "string") return fn;
53566
+ if (typeof fn === "function") return fn.name || id;
53567
+ }
53568
+ return INTERVAL_GLSL_FUNCTIONS[id];
53569
+ },
53570
+ var: (id) => {
53571
+ if (vars && id in vars) return vars[id];
53572
+ const constants = {
53573
+ Pi: "ia_point(3.14159265359)",
53574
+ ExponentialE: "ia_point(2.71828182846)",
53575
+ GoldenRatio: "ia_point(1.61803398875)",
53576
+ CatalanConstant: "ia_point(0.91596559417)",
53577
+ EulerGamma: "ia_point(0.57721566490)"
53578
+ };
53579
+ if (id in constants) return constants[id];
53580
+ return id;
53581
+ }
53582
+ });
53583
+ const glslCode = BaseCompiler.compile(expr, target);
53584
+ const result = function() {
53585
+ return glslCode;
53586
+ };
53587
+ Object.defineProperty(result, "toString", {
53588
+ value: () => glslCode
53589
+ });
53590
+ Object.defineProperty(result, "isCompiled", {
53591
+ value: true
53592
+ });
53593
+ return result;
53594
+ }
53595
+ /**
53596
+ * Compile an expression to GLSL interval code.
53597
+ */
53598
+ compile(expr, options = {}) {
53599
+ const target = this.createTarget();
53600
+ return BaseCompiler.compile(expr, target);
53601
+ }
53602
+ /**
53603
+ * Create a complete GLSL interval function from an expression.
53604
+ *
53605
+ * @param expr - The expression to compile
53606
+ * @param functionName - Name of the GLSL function
53607
+ * @param parameters - Parameter names (each becomes a vec2 interval input)
53608
+ */
53609
+ compileFunction(expr, functionName, parameters) {
53610
+ const target = this.createTarget();
53611
+ const body = BaseCompiler.compile(expr, target);
53612
+ const params = parameters.map((name) => `vec2 ${name}`).join(", ");
53613
+ return `IntervalResult ${functionName}(${params}) {
53614
+ return ${body};
53615
+ }`;
53616
+ }
53617
+ /**
53618
+ * Create a complete GLSL fragment shader for interval function plotting.
53619
+ *
53620
+ * @param expr - The expression to compile
53621
+ * @param options - Shader options
53622
+ */
53623
+ compileShaderFunction(expr, options = {}) {
53624
+ const {
53625
+ functionName = "evaluateInterval",
53626
+ version: version2 = "300 es",
53627
+ parameters = ["x"]
53628
+ } = options;
53629
+ const target = this.createTarget();
53630
+ const body = BaseCompiler.compile(expr, target);
53631
+ const params = parameters.map((name) => `vec2 ${name}`).join(", ");
53632
+ return `#version ${version2}
53633
+ precision highp float;
53634
+
53635
+ ${GLSL_INTERVAL_LIBRARY}
53636
+
53637
+ IntervalResult ${functionName}(${params}) {
53638
+ return ${body};
53639
+ }
53640
+ `;
53641
+ }
53642
+ };
53643
+
52007
53644
  // src/compute-engine/index.ts
52008
53645
  init_base_compiler();
52009
53646
  var ComputeEngine = class _ComputeEngine {
@@ -52309,6 +53946,11 @@ var ComputeEngine = class _ComputeEngine {
52309
53946
  this.pushScope(void 0, "global");
52310
53947
  this._compilationTargets.set("javascript", new JavaScriptTarget());
52311
53948
  this._compilationTargets.set("glsl", new GLSLTarget());
53949
+ this._compilationTargets.set(
53950
+ "interval-js",
53951
+ new IntervalJavaScriptTarget()
53952
+ );
53953
+ this._compilationTargets.set("interval-glsl", new IntervalGLSLTarget());
52312
53954
  hidePrivateProperties(this);
52313
53955
  }
52314
53956
  toJSON() {
@@ -53766,10 +55408,10 @@ function defToString(name, def, v) {
53766
55408
  // src/compute-engine.ts
53767
55409
  init_types6();
53768
55410
  init_base_compiler();
53769
- var version = "0.34.0";
55411
+ var version = "0.35.0";
53770
55412
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
53771
55413
  ComputeEngine: ComputeEngine.prototype.constructor,
53772
- version: "0.34.0"
55414
+ version: "0.35.0"
53773
55415
  };
53774
55416
  export {
53775
55417
  BaseCompiler,