@cortex-js/compute-engine 0.35.0 → 0.35.2

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 +605 -201
  2. package/dist/compute-engine.min.esm.js +238 -43
  3. package/dist/compute-engine.min.umd.js +238 -43
  4. package/dist/compute-engine.umd.js +605 -201
  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 +1 -1
  75. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  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 +1 -1
  81. package/dist/types/compute-engine/index.d.ts +1 -1
  82. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  83. package/dist/types/compute-engine/interval/comparison.d.ts +9 -9
  84. package/dist/types/compute-engine/interval/elementary.d.ts +14 -14
  85. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  86. package/dist/types/compute-engine/interval/trigonometric.d.ts +17 -17
  87. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  88. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  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.35.0 */
1
+ /** Compute Engine 0.35.2 */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -5441,15 +5441,14 @@ function bigint(a) {
5441
5441
  }
5442
5442
  if (a instanceof Decimal) {
5443
5443
  if (!a.isInteger()) return null;
5444
- return bigint(a.toString());
5444
+ return BigInt(a.toFixed(0));
5445
5445
  }
5446
5446
  let s = a.toLowerCase();
5447
- const m = s.match(/([+-]?[0-9]*)(?:\.([0-9]+))?e([+-]?[0-9]+)$/);
5447
+ const m = s.match(/^([+-]?[0-9]+)e([+-]?[0-9]+)$/);
5448
5448
  if (m) {
5449
- const exp3 = parseInt(m[3]);
5450
- const pad = exp3 - (m[2] ? m[2].length : 0);
5451
- if (pad < 0) return null;
5452
- s = (m[1] ?? "") + (m[2] ?? "") + "0".repeat(pad);
5449
+ const exp3 = parseInt(m[2]);
5450
+ if (exp3 < 0) return null;
5451
+ s = m[1] + "0".repeat(exp3);
5453
5452
  }
5454
5453
  const i = s.indexOf(".");
5455
5454
  if (i >= 0) return null;
@@ -9760,6 +9759,23 @@ function serializeScientificNotationNumber(valString, options, expMultiple = 1)
9760
9759
  if (!m) return serializeAutoNotationNumber(valString, options);
9761
9760
  let exponent = parseInt(m[2]);
9762
9761
  let mantissa = m[1];
9762
+ {
9763
+ const signMatch = mantissa.match(/^(-?)/);
9764
+ const sign3 = signMatch ? signMatch[1] : "";
9765
+ const unsigned = sign3 ? mantissa.substring(1) : mantissa;
9766
+ const parts = unsigned.match(/^(\d+)(?:\.(\d*))?$/);
9767
+ if (parts) {
9768
+ let whole = parts[1];
9769
+ let fraction = parts[2] ?? "";
9770
+ if (whole.length > 1) {
9771
+ fraction = whole.slice(1) + fraction;
9772
+ exponent += whole.length - 1;
9773
+ whole = whole[0];
9774
+ }
9775
+ mantissa = sign3 + whole;
9776
+ if (fraction) mantissa += "." + fraction;
9777
+ }
9778
+ }
9763
9779
  if (Math.abs(exponent) % expMultiple !== 0) {
9764
9780
  const adjust = exponent > 0 ? exponent % expMultiple : -((expMultiple + exponent) % expMultiple);
9765
9781
  exponent = exponent >= 0 ? exponent - adjust : exponent + adjust;
@@ -11718,7 +11734,8 @@ var init_exact_numeric_value = __esm({
11718
11734
  }
11719
11735
  } else {
11720
11736
  console.assert(isSubtype(value.type, "integer"));
11721
- rationalSum = add2(rationalSum, [value.re, 1]);
11737
+ const intValue = BigInt(value.bignumRe.toFixed(0));
11738
+ rationalSum = add2(rationalSum, [intValue, BigInt(1)]);
11722
11739
  }
11723
11740
  }
11724
11741
  if (isZero(rationalSum) && radicals.length === 0) {
@@ -12084,11 +12101,14 @@ function canonicalDivide(op1, op2) {
12084
12101
  const ce = op1.engine;
12085
12102
  if (!op1.isValid || !op2.isValid) return ce._fn("Divide", [op1, op2]);
12086
12103
  if (op1.isNaN || op2.isNaN) return ce.NaN;
12087
- const op2IsConstantExpression = op2.symbols.length === 0 && !op2.isNumberLiteral;
12104
+ const op2IsConstantExpression = op2.unknowns.length === 0 && !op2.isNumberLiteral;
12088
12105
  if (op2.is(0)) return op1.is(0) ? ce.NaN : ce.ComplexInfinity;
12089
12106
  if (op1.is(0) && op2.isFinite !== false) {
12090
12107
  if (op2IsConstantExpression)
12091
- return ce._fn("Divide", [op1, op2], { canonical: false });
12108
+ return ce.function("Divide", [op1, op2], {
12109
+ canonical: false,
12110
+ structural: true
12111
+ });
12092
12112
  return ce.Zero;
12093
12113
  }
12094
12114
  if (op2.isInfinity) return op1.isInfinity ? ce.NaN : ce.Zero;
@@ -12097,7 +12117,10 @@ function canonicalDivide(op1, op2) {
12097
12117
  return ce.One;
12098
12118
  if (op1.isSame(op2)) {
12099
12119
  if (op2IsConstantExpression)
12100
- return ce._fn("Divide", [op1, op2], { canonical: false });
12120
+ return ce.function("Divide", [op1, op2], {
12121
+ canonical: false,
12122
+ structural: true
12123
+ });
12101
12124
  return ce.One;
12102
12125
  }
12103
12126
  }
@@ -15248,7 +15271,7 @@ function asRadical(expr) {
15248
15271
  }
15249
15272
  function canonicalPower(a, b) {
15250
15273
  const ce = a.engine;
15251
- const fullyCanonical = a.isCanonical && b.isCanonical;
15274
+ const fullyCanonical = (a.isCanonical || a.isStructural) && (b.isCanonical || b.isStructural);
15252
15275
  const unchanged = () => ce._fn("Power", [a, b], { canonical: fullyCanonical });
15253
15276
  if (a.operator === "Power") {
15254
15277
  const [base, aPow] = a.ops;
@@ -15294,7 +15317,7 @@ function canonicalPower(a, b) {
15294
15317
  if (a.is(-1)) return ce.NegativeOne;
15295
15318
  if (a.is(1)) return ce.One;
15296
15319
  }
15297
- if (!a.isCanonical)
15320
+ if (!(a.isCanonical || a.isStructural))
15298
15321
  return ce._fn("Power", [a, ce.number(-1)], { canonical: false });
15299
15322
  return a.inv();
15300
15323
  }
@@ -15350,10 +15373,10 @@ function canonicalPower(a, b) {
15350
15373
  }
15351
15374
  }
15352
15375
  if (b.is(0.5))
15353
- return a.isCanonical ? canonicalRoot(a, 2) : ce._fn("Sqrt", [a], { canonical: false });
15376
+ return a.isCanonical || a.isStructural ? canonicalRoot(a, 2) : ce._fn("Sqrt", [a], { canonical: false });
15354
15377
  const r = asRational(b);
15355
15378
  if (r !== void 0 && r[0] === 1 && r[1] !== 1)
15356
- return a.isCanonical ? canonicalRoot(a, ce.number(r[1])) : ce._fn("Root", [a, ce.number(r[1])], { canonical: false });
15379
+ return a.isCanonical || a.isStructural ? canonicalRoot(a, ce.number(r[1])) : ce._fn("Root", [a, ce.number(r[1])], { canonical: false });
15357
15380
  return unchanged();
15358
15381
  }
15359
15382
  function canonicalRoot(a, b) {
@@ -15372,14 +15395,14 @@ function canonicalRoot(a, b) {
15372
15395
  if (v.numericValue.isExact) return v;
15373
15396
  }
15374
15397
  }
15375
- return ce._fn("Sqrt", [a], { canonical: a.isCanonical });
15398
+ return ce._fn("Sqrt", [a], { canonical: a.isCanonical || a.isStructural });
15376
15399
  }
15377
15400
  return ce._fn("Root", [a, typeof b === "number" ? ce.number(b) : b], {
15378
- canonical: a.isCanonical && (typeof b === "number" || b.isCanonical)
15401
+ canonical: (a.isCanonical || a.isStructural) && (typeof b === "number" || b.isCanonical || b.isStructural)
15379
15402
  });
15380
15403
  }
15381
15404
  function pow2(x, exp3, { numericApproximation }) {
15382
- if (!x.isCanonical || typeof exp3 !== "number" && !exp3.isCanonical)
15405
+ if (!(x.isCanonical || x.isStructural) || typeof exp3 !== "number" && !(exp3.isCanonical || exp3.isStructural))
15383
15406
  return x.engine._fn("Power", [x, x.engine.box(exp3)], { canonical: false });
15384
15407
  if (numericApproximation) {
15385
15408
  if (x.isNumberLiteral) {
@@ -15475,7 +15498,7 @@ function pow2(x, exp3, { numericApproximation }) {
15475
15498
  return ce._fn("Power", [x, ce.box(exp3)]);
15476
15499
  }
15477
15500
  function root(a, b, { numericApproximation }) {
15478
- if (!a.isCanonical || !b.isCanonical)
15501
+ if (!(a.isCanonical || a.isStructural) || !(b.isCanonical || b.isStructural))
15479
15502
  return a.engine._fn("Root", [a, b], { canonical: false });
15480
15503
  if (numericApproximation) {
15481
15504
  if (a.isNumberLiteral && b.isNumberLiteral) {
@@ -15681,7 +15704,7 @@ function order(a, b) {
15681
15704
  return (a.complexity ?? DEFAULT_COMPLEXITY) - (b.complexity ?? DEFAULT_COMPLEXITY);
15682
15705
  }
15683
15706
  function canonicalOrder(expr, { recursive = false }) {
15684
- if (expr.isCanonical || !expr.ops) return expr;
15707
+ if (expr.isCanonical || expr.isStructural || !expr.ops) return expr;
15685
15708
  let ops = expr.ops;
15686
15709
  if (recursive) ops = ops.map((x) => canonicalOrder(x, { recursive }));
15687
15710
  ops = sortOperands(expr.operator, ops);
@@ -20105,6 +20128,14 @@ var init_base_compiler = __esm({
20105
20128
  return `return ${_BaseCompiler.compile(args[0], target)}`;
20106
20129
  if (h === "If") {
20107
20130
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
20131
+ const fn2 = target.functions?.(h);
20132
+ if (fn2) {
20133
+ if (typeof fn2 === "function") {
20134
+ return fn2(args, (expr) => _BaseCompiler.compile(expr, target), target);
20135
+ }
20136
+ if (args === null) return `${fn2}()`;
20137
+ return `${fn2}(${args.map((x) => _BaseCompiler.compile(x, target)).join(", ")})`;
20138
+ }
20108
20139
  return `((${_BaseCompiler.compile(args[0], target)}) ? (${_BaseCompiler.compile(
20109
20140
  args[1],
20110
20141
  target
@@ -23787,6 +23818,24 @@ var init_utils5 = __esm({
23787
23818
  });
23788
23819
 
23789
23820
  // src/compute-engine/boxed-expression/validate.ts
23821
+ function typeCouldBeCollection(type2) {
23822
+ if (typeof type2 === "string") {
23823
+ return type2 === "collection" || type2 === "indexed_collection" || type2 === "list" || type2 === "set" || type2 === "tuple" || type2 === "any";
23824
+ }
23825
+ if (type2.kind === "list" || type2.kind === "set" || type2.kind === "tuple")
23826
+ return true;
23827
+ if (type2.kind === "union") return type2.types.some((t) => typeCouldBeCollection(t));
23828
+ return false;
23829
+ }
23830
+ function typeCouldBeNumericCollection(type2) {
23831
+ if (typeof type2 === "string") {
23832
+ return type2 === "list" || type2 === "set" || type2 === "collection" || type2 === "indexed_collection";
23833
+ }
23834
+ if (type2.kind === "list" || type2.kind === "set") return true;
23835
+ if (type2.kind === "union")
23836
+ return type2.types.some((t) => typeCouldBeNumericCollection(t));
23837
+ return false;
23838
+ }
23790
23839
  function checkArity(ce, ops, count) {
23791
23840
  ops = flatten(ops);
23792
23841
  if (!ce.strict) return ops;
@@ -23836,7 +23885,9 @@ function checkNumericArgs(ce, ops, options) {
23836
23885
  xs.push(op);
23837
23886
  } else if (op.symbol && !ce.lookupDefinition(op.symbol)) {
23838
23887
  xs.push(op);
23839
- } else if (op.type.isUnknown) {
23888
+ } else if (op.type.isUnknown || op.type.type === "any") {
23889
+ xs.push(op);
23890
+ } else if (typeCouldBeNumericCollection(op.type.type)) {
23840
23891
  xs.push(op);
23841
23892
  } else if (isBoxedTensor(op)) {
23842
23893
  xs.push(op);
@@ -23920,11 +23971,11 @@ function validateArguments(ce, ops, signature, lazy, threadable) {
23920
23971
  isValid = false;
23921
23972
  continue;
23922
23973
  }
23923
- if (op.type.isUnknown) {
23974
+ if (op.type.isUnknown || op.type.type === "any") {
23924
23975
  result.push(op);
23925
23976
  continue;
23926
23977
  }
23927
- if (threadable && isFiniteIndexedCollection(op)) {
23978
+ if (threadable && (isFiniteIndexedCollection(op) || typeCouldBeCollection(op.type.type))) {
23928
23979
  result.push(op);
23929
23980
  continue;
23930
23981
  }
@@ -23959,12 +24010,12 @@ function validateArguments(ce, ops, signature, lazy, threadable) {
23959
24010
  i += 1;
23960
24011
  continue;
23961
24012
  }
23962
- if (op.type.isUnknown) {
24013
+ if (op.type.isUnknown || op.type.type === "any") {
23963
24014
  result.push(op);
23964
24015
  i += 1;
23965
24016
  continue;
23966
24017
  }
23967
- if (threadable && isFiniteIndexedCollection(op)) {
24018
+ if (threadable && (isFiniteIndexedCollection(op) || typeCouldBeCollection(op.type.type))) {
23968
24019
  result.push(op);
23969
24020
  i += 1;
23970
24021
  continue;
@@ -23997,11 +24048,11 @@ function validateArguments(ce, ops, signature, lazy, threadable) {
23997
24048
  isValid = false;
23998
24049
  continue;
23999
24050
  }
24000
- if (op.type.isUnknown) {
24051
+ if (op.type.isUnknown || op.type.type === "any") {
24001
24052
  result.push(op);
24002
24053
  continue;
24003
24054
  }
24004
- if (threadable && isFiniteIndexedCollection(op)) {
24055
+ if (threadable && (isFiniteIndexedCollection(op) || typeCouldBeCollection(op.type.type))) {
24005
24056
  result.push(op);
24006
24057
  continue;
24007
24058
  }
@@ -24031,20 +24082,22 @@ function validateArguments(ce, ops, signature, lazy, threadable) {
24031
24082
  i = 0;
24032
24083
  for (const param of params) {
24033
24084
  if (!lazy) {
24034
- if (!threadable || !isFiniteIndexedCollection(ops[i]))
24085
+ if (!threadable || !isFiniteIndexedCollection(ops[i]) && !typeCouldBeCollection(ops[i].type.type))
24035
24086
  ops[i].infer(param);
24036
24087
  }
24037
24088
  i += 1;
24038
24089
  }
24039
24090
  for (const param of optParams) {
24040
24091
  if (!ops[i]) break;
24041
- if (!threadable || !isFiniteIndexedCollection(ops[i])) ops[i]?.infer(param);
24092
+ if (!threadable || !isFiniteIndexedCollection(ops[i]) && !typeCouldBeCollection(ops[i].type.type))
24093
+ ops[i]?.infer(param);
24042
24094
  i += 1;
24043
24095
  }
24044
24096
  if (varParam) {
24045
24097
  for (const op of ops.slice(i)) {
24046
24098
  if (!lazy) {
24047
- if (!threadable || !isFiniteIndexedCollection(op)) op.infer(varParam);
24099
+ if (!threadable || !isFiniteIndexedCollection(op) && !typeCouldBeCollection(op.type.type))
24100
+ op.infer(varParam);
24048
24101
  }
24049
24102
  i += 1;
24050
24103
  }
@@ -35456,6 +35509,12 @@ function canonicalForm(expr, forms, scope) {
35456
35509
  throw Error("Invalid canonical form");
35457
35510
  }
35458
35511
  }
35512
+ if (expr.isFunctionExpression && expr.isCanonical) {
35513
+ expr = expr.engine.function(expr.operator, [...expr.ops], {
35514
+ canonical: false,
35515
+ structural: true
35516
+ });
35517
+ }
35459
35518
  return expr;
35460
35519
  }
35461
35520
  function flattenForm(expr) {
@@ -35537,10 +35596,7 @@ function multiplyForm(expr) {
35537
35596
  if (!expr.ops) return expr;
35538
35597
  const ops = expr.ops.map(multiplyForm);
35539
35598
  if (expr.operator === "Multiply")
35540
- return canonicalMultiply(
35541
- expr.engine,
35542
- ops.map((x) => x.canonical)
35543
- );
35599
+ return canonicalMultiply(expr.engine, ops);
35544
35600
  if (expr.operator === "Negate")
35545
35601
  return canonicalMultiply(expr.engine, [ops[0], expr.engine.NegativeOne]);
35546
35602
  return expr;
@@ -45674,7 +45730,7 @@ var BoxedFunction = class extends _BoxedExpression {
45674
45730
  return void 0;
45675
45731
  }
45676
45732
  get isCanonical() {
45677
- return this._def !== void 0 && this._def !== null;
45733
+ return this._def !== void 0 && this._def !== null && !this._isStructural;
45678
45734
  }
45679
45735
  get isPure() {
45680
45736
  if (this._isPure !== void 0) return this._isPure;
@@ -45841,7 +45897,7 @@ var BoxedFunction = class extends _BoxedExpression {
45841
45897
  subs(sub3, options) {
45842
45898
  options ??= { canonical: void 0 };
45843
45899
  if (options.canonical === void 0)
45844
- options = { canonical: this.isCanonical };
45900
+ options = { canonical: this.isCanonical || this.isStructural };
45845
45901
  const ops = this._ops.map((x) => x.subs(sub3, options));
45846
45902
  if (!ops.every((x) => x.isValid))
45847
45903
  return this.engine.function(this._operator, ops, { canonical: false });
@@ -45913,7 +45969,7 @@ var BoxedFunction = class extends _BoxedExpression {
45913
45969
  return this.numeratorDenominator[1];
45914
45970
  }
45915
45971
  get numeratorDenominator() {
45916
- if (!this.isCanonical) return [this, this.engine.One];
45972
+ if (!(this.isCanonical || this.isStructural)) return [this, this.engine.One];
45917
45973
  if (this.isNumber !== true)
45918
45974
  return [this.engine.Nothing, this.engine.Nothing];
45919
45975
  const operator2 = this.operator;
@@ -45951,11 +46007,11 @@ var BoxedFunction = class extends _BoxedExpression {
45951
46007
  // ALGEBRAIC OPERATIONS
45952
46008
  //
45953
46009
  neg() {
45954
- if (!this.isCanonical) throw new Error("Not canonical");
46010
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45955
46011
  return negate(this);
45956
46012
  }
45957
46013
  inv() {
45958
- if (!this.isCanonical) throw new Error("Not canonical");
46014
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45959
46015
  if (this.isOne) return this;
45960
46016
  if (this.isNegativeOne) return this;
45961
46017
  if (this.operator === "Sqrt") return this.op1.inv().sqrt();
@@ -45976,7 +46032,7 @@ var BoxedFunction = class extends _BoxedExpression {
45976
46032
  return this.engine._fn("Divide", [this.engine.One, this]);
45977
46033
  }
45978
46034
  abs() {
45979
- if (!this.isCanonical) throw new Error("Not canonical");
46035
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45980
46036
  if (this.operator === "Abs" || this.operator === "Negate") return this;
45981
46037
  if (this.isNonNegative) return this;
45982
46038
  if (this.isNonPositive) return this.neg();
@@ -45984,11 +46040,11 @@ var BoxedFunction = class extends _BoxedExpression {
45984
46040
  }
45985
46041
  add(rhs) {
45986
46042
  if (rhs === 0) return this;
45987
- if (!this.isCanonical) throw new Error("Not canonical");
46043
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45988
46044
  return add3(this, this.engine.box(rhs));
45989
46045
  }
45990
46046
  mul(rhs) {
45991
- if (!this.isCanonical) throw new Error("Not canonical");
46047
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45992
46048
  if (rhs === 0) return this.engine.Zero;
45993
46049
  if (rhs === 1) return this;
45994
46050
  if (rhs === -1) return this.neg();
@@ -46000,14 +46056,14 @@ var BoxedFunction = class extends _BoxedExpression {
46000
46056
  return mul3(this, this.engine.box(rhs));
46001
46057
  }
46002
46058
  div(rhs) {
46003
- if (!this.isCanonical) throw new Error("Not canonical");
46059
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
46004
46060
  return div2(this, rhs);
46005
46061
  }
46006
46062
  pow(exp3) {
46007
46063
  return pow2(this, exp3, { numericApproximation: false });
46008
46064
  }
46009
46065
  root(exp3) {
46010
- if (!this.isCanonical || typeof exp3 !== "number" && !exp3.isCanonical)
46066
+ if (!(this.isCanonical || this.isStructural) || typeof exp3 !== "number" && !(exp3.isCanonical || exp3.isStructural))
46011
46067
  throw new Error("Not canonical");
46012
46068
  const e = typeof exp3 === "number" ? exp3 : exp3.im === 0 ? exp3.re : void 0;
46013
46069
  if (e === 0) return this.engine.NaN;
@@ -46066,7 +46122,7 @@ var BoxedFunction = class extends _BoxedExpression {
46066
46122
  }
46067
46123
  ln(semiBase) {
46068
46124
  const base = semiBase ? this.engine.box(semiBase) : void 0;
46069
- if (!this.isCanonical) throw new Error("Not canonical");
46125
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
46070
46126
  if (this.is(0)) return this.engine.NegativeInfinity;
46071
46127
  if (this.operator === "Exp") {
46072
46128
  if (!base) return this.op1;
@@ -46099,7 +46155,7 @@ var BoxedFunction = class extends _BoxedExpression {
46099
46155
  return this.engine._fn("Ln", [this]);
46100
46156
  }
46101
46157
  get complexity() {
46102
- if (!this.isCanonical) return void 0;
46158
+ if (!(this.isCanonical || this.isStructural)) return void 0;
46103
46159
  return this.operatorDefinition?.complexity ?? DEFAULT_COMPLEXITY;
46104
46160
  }
46105
46161
  get baseDefinition() {
@@ -52265,49 +52321,64 @@ function intPow2(base, n) {
52265
52321
  return { lo: Math.pow(base.lo, n), hi: Math.pow(base.hi, n) };
52266
52322
  }
52267
52323
  function pow3(base, exp3) {
52324
+ const unwrapped = unwrapOrPropagate(base);
52325
+ if (!Array.isArray(unwrapped)) return unwrapped;
52326
+ const [baseVal] = unwrapped;
52268
52327
  if (Number.isInteger(exp3)) {
52269
52328
  if (exp3 >= 0) {
52270
- return ok(intPow2(base, exp3));
52329
+ return ok(intPow2(baseVal, exp3));
52271
52330
  } else {
52272
- if (containsZero(base)) {
52331
+ if (containsZero(baseVal)) {
52273
52332
  return { kind: "singular" };
52274
52333
  }
52275
- const denom = intPow2(base, -exp3);
52334
+ const denom = intPow2(baseVal, -exp3);
52276
52335
  return ok({ lo: 1 / denom.hi, hi: 1 / denom.lo });
52277
52336
  }
52278
52337
  } else {
52279
- if (isNegative(base)) {
52338
+ if (isNegative(baseVal)) {
52280
52339
  return { kind: "empty" };
52281
52340
  }
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 };
52341
+ if (baseVal.lo < 0) {
52342
+ const value = exp3 > 0 ? { lo: 0, hi: Math.pow(baseVal.hi, exp3) } : { lo: Math.pow(baseVal.hi, exp3), hi: Infinity };
52284
52343
  return { kind: "partial", value, domainClipped: "lo" };
52285
52344
  }
52286
52345
  if (exp3 > 0) {
52287
- return ok({ lo: Math.pow(base.lo, exp3), hi: Math.pow(base.hi, exp3) });
52346
+ return ok({
52347
+ lo: Math.pow(baseVal.lo, exp3),
52348
+ hi: Math.pow(baseVal.hi, exp3)
52349
+ });
52288
52350
  } else {
52289
- if (base.lo === 0) {
52351
+ if (baseVal.lo === 0) {
52290
52352
  return {
52291
52353
  kind: "partial",
52292
- value: { lo: Math.pow(base.hi, exp3), hi: Infinity },
52354
+ value: { lo: Math.pow(baseVal.hi, exp3), hi: Infinity },
52293
52355
  domainClipped: "hi"
52294
52356
  };
52295
52357
  }
52296
- return ok({ lo: Math.pow(base.hi, exp3), hi: Math.pow(base.lo, exp3) });
52358
+ return ok({
52359
+ lo: Math.pow(baseVal.hi, exp3),
52360
+ hi: Math.pow(baseVal.lo, exp3)
52361
+ });
52297
52362
  }
52298
52363
  }
52299
52364
  }
52300
52365
  function powInterval(base, exp3) {
52301
- if (base.hi <= 0) {
52366
+ const unwrapped = unwrapOrPropagate(base, exp3);
52367
+ if (!Array.isArray(unwrapped)) return unwrapped;
52368
+ const [baseVal, expVal] = unwrapped;
52369
+ if (baseVal.hi <= 0) {
52302
52370
  return { kind: "empty" };
52303
52371
  }
52304
- if (base.lo <= 0) {
52305
- const posBase = { lo: Math.max(base.lo, Number.EPSILON), hi: base.hi };
52372
+ if (baseVal.lo <= 0) {
52373
+ const posBase = {
52374
+ lo: Math.max(baseVal.lo, Number.EPSILON),
52375
+ hi: baseVal.hi
52376
+ };
52306
52377
  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)
52378
+ Math.pow(posBase.lo, expVal.lo),
52379
+ Math.pow(posBase.lo, expVal.hi),
52380
+ Math.pow(posBase.hi, expVal.lo),
52381
+ Math.pow(posBase.hi, expVal.hi)
52311
52382
  ];
52312
52383
  return {
52313
52384
  kind: "partial",
@@ -52316,10 +52387,10 @@ function powInterval(base, exp3) {
52316
52387
  };
52317
52388
  }
52318
52389
  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)
52390
+ Math.pow(baseVal.lo, expVal.lo),
52391
+ Math.pow(baseVal.lo, expVal.hi),
52392
+ Math.pow(baseVal.hi, expVal.lo),
52393
+ Math.pow(baseVal.hi, expVal.hi)
52323
52394
  ];
52324
52395
  return ok({ lo: Math.min(...corners), hi: Math.max(...corners) });
52325
52396
  }
@@ -52330,79 +52401,115 @@ function exp2(x) {
52330
52401
  return ok({ lo: Math.exp(xVal.lo), hi: Math.exp(xVal.hi) });
52331
52402
  }
52332
52403
  function ln2(x) {
52333
- if (x.hi <= 0) {
52404
+ const unwrapped = unwrapOrPropagate(x);
52405
+ if (!Array.isArray(unwrapped)) return unwrapped;
52406
+ const [xVal] = unwrapped;
52407
+ if (xVal.hi <= 0) {
52334
52408
  return { kind: "empty" };
52335
52409
  }
52336
- if (x.lo > 0) {
52337
- return ok({ lo: Math.log(x.lo), hi: Math.log(x.hi) });
52410
+ if (xVal.lo > 0) {
52411
+ return ok({ lo: Math.log(xVal.lo), hi: Math.log(xVal.hi) });
52338
52412
  }
52339
52413
  return {
52340
52414
  kind: "partial",
52341
- value: { lo: -Infinity, hi: Math.log(x.hi) },
52415
+ value: { lo: -Infinity, hi: Math.log(xVal.hi) },
52342
52416
  domainClipped: "lo"
52343
52417
  };
52344
52418
  }
52345
52419
  function log102(x) {
52346
- if (x.hi <= 0) {
52420
+ const unwrapped = unwrapOrPropagate(x);
52421
+ if (!Array.isArray(unwrapped)) return unwrapped;
52422
+ const [xVal] = unwrapped;
52423
+ if (xVal.hi <= 0) {
52347
52424
  return { kind: "empty" };
52348
52425
  }
52349
- if (x.lo > 0) {
52350
- return ok({ lo: Math.log10(x.lo), hi: Math.log10(x.hi) });
52426
+ if (xVal.lo > 0) {
52427
+ return ok({ lo: Math.log10(xVal.lo), hi: Math.log10(xVal.hi) });
52351
52428
  }
52352
52429
  return {
52353
52430
  kind: "partial",
52354
- value: { lo: -Infinity, hi: Math.log10(x.hi) },
52431
+ value: { lo: -Infinity, hi: Math.log10(xVal.hi) },
52355
52432
  domainClipped: "lo"
52356
52433
  };
52357
52434
  }
52358
52435
  function log22(x) {
52359
- if (x.hi <= 0) {
52436
+ const unwrapped = unwrapOrPropagate(x);
52437
+ if (!Array.isArray(unwrapped)) return unwrapped;
52438
+ const [xVal] = unwrapped;
52439
+ if (xVal.hi <= 0) {
52360
52440
  return { kind: "empty" };
52361
52441
  }
52362
- if (x.lo > 0) {
52363
- return ok({ lo: Math.log2(x.lo), hi: Math.log2(x.hi) });
52442
+ if (xVal.lo > 0) {
52443
+ return ok({ lo: Math.log2(xVal.lo), hi: Math.log2(xVal.hi) });
52364
52444
  }
52365
52445
  return {
52366
52446
  kind: "partial",
52367
- value: { lo: -Infinity, hi: Math.log2(x.hi) },
52447
+ value: { lo: -Infinity, hi: Math.log2(xVal.hi) },
52368
52448
  domainClipped: "lo"
52369
52449
  };
52370
52450
  }
52371
52451
  function abs2(x) {
52372
- if (x.lo >= 0) {
52373
- return ok(x);
52452
+ const unwrapped = unwrapOrPropagate(x);
52453
+ if (!Array.isArray(unwrapped)) return unwrapped;
52454
+ const [xVal] = unwrapped;
52455
+ if (xVal.lo >= 0) {
52456
+ return ok(xVal);
52374
52457
  }
52375
- if (x.hi <= 0) {
52376
- return ok({ lo: -x.hi, hi: -x.lo });
52458
+ if (xVal.hi <= 0) {
52459
+ return ok({ lo: -xVal.hi, hi: -xVal.lo });
52377
52460
  }
52378
- return ok({ lo: 0, hi: Math.max(-x.lo, x.hi) });
52461
+ return ok({ lo: 0, hi: Math.max(-xVal.lo, xVal.hi) });
52379
52462
  }
52380
52463
  function floor2(x) {
52381
- return ok({ lo: Math.floor(x.lo), hi: Math.floor(x.hi) });
52464
+ const unwrapped = unwrapOrPropagate(x);
52465
+ if (!Array.isArray(unwrapped)) return unwrapped;
52466
+ const [xVal] = unwrapped;
52467
+ return ok({ lo: Math.floor(xVal.lo), hi: Math.floor(xVal.hi) });
52382
52468
  }
52383
52469
  function ceil2(x) {
52384
- return ok({ lo: Math.ceil(x.lo), hi: Math.ceil(x.hi) });
52470
+ const unwrapped = unwrapOrPropagate(x);
52471
+ if (!Array.isArray(unwrapped)) return unwrapped;
52472
+ const [xVal] = unwrapped;
52473
+ return ok({ lo: Math.ceil(xVal.lo), hi: Math.ceil(xVal.hi) });
52385
52474
  }
52386
52475
  function round2(x) {
52387
- return ok({ lo: Math.round(x.lo), hi: Math.round(x.hi) });
52476
+ const unwrapped = unwrapOrPropagate(x);
52477
+ if (!Array.isArray(unwrapped)) return unwrapped;
52478
+ const [xVal] = unwrapped;
52479
+ return ok({ lo: Math.round(xVal.lo), hi: Math.round(xVal.hi) });
52388
52480
  }
52389
52481
  function min2(a, b) {
52390
- return ok({ lo: Math.min(a.lo, b.lo), hi: Math.min(a.hi, b.hi) });
52482
+ const unwrapped = unwrapOrPropagate(a, b);
52483
+ if (!Array.isArray(unwrapped)) return unwrapped;
52484
+ const [aVal, bVal] = unwrapped;
52485
+ return ok({
52486
+ lo: Math.min(aVal.lo, bVal.lo),
52487
+ hi: Math.min(aVal.hi, bVal.hi)
52488
+ });
52391
52489
  }
52392
52490
  function max2(a, b) {
52393
- return ok({ lo: Math.max(a.lo, b.lo), hi: Math.max(a.hi, b.hi) });
52491
+ const unwrapped = unwrapOrPropagate(a, b);
52492
+ if (!Array.isArray(unwrapped)) return unwrapped;
52493
+ const [aVal, bVal] = unwrapped;
52494
+ return ok({
52495
+ lo: Math.max(aVal.lo, bVal.lo),
52496
+ hi: Math.max(aVal.hi, bVal.hi)
52497
+ });
52394
52498
  }
52395
52499
  function mod2(a, b) {
52396
- if (containsZero(b)) {
52500
+ const unwrapped = unwrapOrPropagate(a, b);
52501
+ if (!Array.isArray(unwrapped)) return unwrapped;
52502
+ const [aVal, bVal] = unwrapped;
52503
+ if (containsZero(bVal)) {
52397
52504
  return { kind: "singular" };
52398
52505
  }
52399
- const bAbs = Math.max(Math.abs(b.lo), Math.abs(b.hi));
52400
- const aWidth = a.hi - a.lo;
52506
+ const bAbs = Math.max(Math.abs(bVal.lo), Math.abs(bVal.hi));
52507
+ const aWidth = aVal.hi - aVal.lo;
52401
52508
  if (aWidth >= bAbs) {
52402
52509
  return ok({ lo: 0, hi: bAbs });
52403
52510
  }
52404
- const modLo = (a.lo % bAbs + bAbs) % bAbs;
52405
- const modHi = (a.hi % bAbs + bAbs) % bAbs;
52511
+ const modLo = (aVal.lo % bAbs + bAbs) % bAbs;
52512
+ const modHi = (aVal.hi % bAbs + bAbs) % bAbs;
52406
52513
  if (modLo <= modHi) {
52407
52514
  return ok({ lo: modLo, hi: modHi });
52408
52515
  } else {
@@ -52410,11 +52517,14 @@ function mod2(a, b) {
52410
52517
  }
52411
52518
  }
52412
52519
  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 });
52520
+ const unwrapped = unwrapOrPropagate(x);
52521
+ if (!Array.isArray(unwrapped)) return unwrapped;
52522
+ const [xVal] = unwrapped;
52523
+ if (xVal.lo > 0) return ok({ lo: 1, hi: 1 });
52524
+ if (xVal.hi < 0) return ok({ lo: -1, hi: -1 });
52525
+ if (xVal.lo === 0 && xVal.hi === 0) return ok({ lo: 0, hi: 0 });
52526
+ if (xVal.lo < 0 && xVal.hi > 0) return ok({ lo: -1, hi: 1 });
52527
+ if (xVal.lo === 0) return ok({ lo: 0, hi: 1 });
52418
52528
  return ok({ lo: -1, hi: 0 });
52419
52529
  }
52420
52530
 
@@ -52424,231 +52534,298 @@ var PI2 = Math.PI;
52424
52534
  var HALF_PI = Math.PI / 2;
52425
52535
  var THREE_HALF_PI = 3 * Math.PI / 2;
52426
52536
  function sin2(x) {
52427
- if (x.hi - x.lo >= TWO_PI) {
52537
+ const unwrapped = unwrapOrPropagate(x);
52538
+ if (!Array.isArray(unwrapped)) return unwrapped;
52539
+ const [xVal] = unwrapped;
52540
+ if (xVal.hi - xVal.lo >= TWO_PI) {
52428
52541
  return ok({ lo: -1, hi: 1 });
52429
52542
  }
52430
- const sinLo = Math.sin(x.lo);
52431
- const sinHi = Math.sin(x.hi);
52543
+ const sinLo = Math.sin(xVal.lo);
52544
+ const sinHi = Math.sin(xVal.hi);
52432
52545
  let lo = Math.min(sinLo, sinHi);
52433
52546
  let hi = Math.max(sinLo, sinHi);
52434
- if (containsExtremum(x, HALF_PI, TWO_PI)) {
52547
+ if (containsExtremum(xVal, HALF_PI, TWO_PI)) {
52435
52548
  hi = 1;
52436
52549
  }
52437
- if (containsExtremum(x, THREE_HALF_PI, TWO_PI)) {
52550
+ if (containsExtremum(xVal, THREE_HALF_PI, TWO_PI)) {
52438
52551
  lo = -1;
52439
52552
  }
52440
52553
  return ok({ lo, hi });
52441
52554
  }
52442
52555
  function cos2(x) {
52443
- if (x.hi - x.lo >= TWO_PI) {
52556
+ const unwrapped = unwrapOrPropagate(x);
52557
+ if (!Array.isArray(unwrapped)) return unwrapped;
52558
+ const [xVal] = unwrapped;
52559
+ if (xVal.hi - xVal.lo >= TWO_PI) {
52444
52560
  return ok({ lo: -1, hi: 1 });
52445
52561
  }
52446
- const cosLo = Math.cos(x.lo);
52447
- const cosHi = Math.cos(x.hi);
52562
+ const cosLo = Math.cos(xVal.lo);
52563
+ const cosHi = Math.cos(xVal.hi);
52448
52564
  let lo = Math.min(cosLo, cosHi);
52449
52565
  let hi = Math.max(cosLo, cosHi);
52450
- if (containsExtremum(x, 0, TWO_PI)) {
52566
+ if (containsExtremum(xVal, 0, TWO_PI)) {
52451
52567
  hi = 1;
52452
52568
  }
52453
- if (containsExtremum(x, PI2, TWO_PI)) {
52569
+ if (containsExtremum(xVal, PI2, TWO_PI)) {
52454
52570
  lo = -1;
52455
52571
  }
52456
52572
  return ok({ lo, hi });
52457
52573
  }
52458
52574
  function tan2(x) {
52459
- if (x.hi - x.lo >= PI2) {
52575
+ const unwrapped = unwrapOrPropagate(x);
52576
+ if (!Array.isArray(unwrapped)) return unwrapped;
52577
+ const [xVal] = unwrapped;
52578
+ if (xVal.hi - xVal.lo >= PI2) {
52460
52579
  return { kind: "singular" };
52461
52580
  }
52462
- if (containsExtremum(x, HALF_PI, PI2)) {
52463
- const n = Math.ceil((x.lo - HALF_PI) / PI2);
52581
+ if (containsExtremum(xVal, HALF_PI, PI2)) {
52582
+ const n = Math.ceil((xVal.lo - HALF_PI) / PI2);
52464
52583
  const poleAt = HALF_PI + n * PI2;
52465
52584
  return { kind: "singular", at: poleAt };
52466
52585
  }
52467
- const tanLo = Math.tan(x.lo);
52468
- const tanHi = Math.tan(x.hi);
52586
+ const tanLo = Math.tan(xVal.lo);
52587
+ const tanHi = Math.tan(xVal.hi);
52469
52588
  if (tanLo > 1e10 && tanHi < -1e10 || tanLo < -1e10 && tanHi > 1e10) {
52470
52589
  return { kind: "singular" };
52471
52590
  }
52472
52591
  return ok({ lo: tanLo, hi: tanHi });
52473
52592
  }
52474
52593
  function cot(x) {
52475
- if (x.hi - x.lo >= PI2) {
52594
+ const unwrapped = unwrapOrPropagate(x);
52595
+ if (!Array.isArray(unwrapped)) return unwrapped;
52596
+ const [xVal] = unwrapped;
52597
+ if (xVal.hi - xVal.lo >= PI2) {
52476
52598
  return { kind: "singular" };
52477
52599
  }
52478
- if (containsExtremum(x, 0, PI2)) {
52479
- const n = Math.ceil(x.lo / PI2);
52600
+ if (containsExtremum(xVal, 0, PI2)) {
52601
+ const n = Math.ceil(xVal.lo / PI2);
52480
52602
  const poleAt = n * PI2;
52481
52603
  return { kind: "singular", at: poleAt };
52482
52604
  }
52483
- const cotLo = 1 / Math.tan(x.lo);
52484
- const cotHi = 1 / Math.tan(x.hi);
52605
+ const cotLo = 1 / Math.tan(xVal.lo);
52606
+ const cotHi = 1 / Math.tan(xVal.hi);
52485
52607
  return ok({ lo: Math.min(cotLo, cotHi), hi: Math.max(cotLo, cotHi) });
52486
52608
  }
52487
52609
  function sec(x) {
52488
- if (x.hi - x.lo >= PI2) {
52610
+ const unwrapped = unwrapOrPropagate(x);
52611
+ if (!Array.isArray(unwrapped)) return unwrapped;
52612
+ const [xVal] = unwrapped;
52613
+ if (xVal.hi - xVal.lo >= PI2) {
52489
52614
  return { kind: "singular" };
52490
52615
  }
52491
- if (containsExtremum(x, HALF_PI, PI2)) {
52492
- const n = Math.ceil((x.lo - HALF_PI) / PI2);
52616
+ if (containsExtremum(xVal, HALF_PI, PI2)) {
52617
+ const n = Math.ceil((xVal.lo - HALF_PI) / PI2);
52493
52618
  const poleAt = HALF_PI + n * PI2;
52494
52619
  return { kind: "singular", at: poleAt };
52495
52620
  }
52496
- const secLo = 1 / Math.cos(x.lo);
52497
- const secHi = 1 / Math.cos(x.hi);
52621
+ const secLo = 1 / Math.cos(xVal.lo);
52622
+ const secHi = 1 / Math.cos(xVal.hi);
52498
52623
  let lo = Math.min(secLo, secHi);
52499
52624
  let hi = Math.max(secLo, secHi);
52500
- if (containsExtremum(x, 0, TWO_PI)) {
52625
+ if (containsExtremum(xVal, 0, TWO_PI)) {
52501
52626
  lo = Math.min(lo, 1);
52502
52627
  hi = Math.max(hi, 1);
52503
52628
  }
52504
- if (containsExtremum(x, PI2, TWO_PI)) {
52629
+ if (containsExtremum(xVal, PI2, TWO_PI)) {
52505
52630
  lo = Math.min(lo, -1);
52506
52631
  hi = Math.max(hi, -1);
52507
52632
  }
52508
52633
  return ok({ lo, hi });
52509
52634
  }
52510
52635
  function csc(x) {
52511
- if (x.hi - x.lo >= PI2) {
52636
+ const unwrapped = unwrapOrPropagate(x);
52637
+ if (!Array.isArray(unwrapped)) return unwrapped;
52638
+ const [xVal] = unwrapped;
52639
+ if (xVal.hi - xVal.lo >= PI2) {
52512
52640
  return { kind: "singular" };
52513
52641
  }
52514
- if (containsExtremum(x, 0, PI2)) {
52515
- const n = Math.ceil(x.lo / PI2);
52642
+ if (containsExtremum(xVal, 0, PI2)) {
52643
+ const n = Math.ceil(xVal.lo / PI2);
52516
52644
  const poleAt = n * PI2;
52517
52645
  return { kind: "singular", at: poleAt };
52518
52646
  }
52519
- const cscLo = 1 / Math.sin(x.lo);
52520
- const cscHi = 1 / Math.sin(x.hi);
52647
+ const cscLo = 1 / Math.sin(xVal.lo);
52648
+ const cscHi = 1 / Math.sin(xVal.hi);
52521
52649
  let lo = Math.min(cscLo, cscHi);
52522
52650
  let hi = Math.max(cscLo, cscHi);
52523
- if (containsExtremum(x, HALF_PI, TWO_PI)) {
52651
+ if (containsExtremum(xVal, HALF_PI, TWO_PI)) {
52524
52652
  lo = Math.min(lo, 1);
52525
52653
  hi = Math.max(hi, 1);
52526
52654
  }
52527
- if (containsExtremum(x, THREE_HALF_PI, TWO_PI)) {
52655
+ if (containsExtremum(xVal, THREE_HALF_PI, TWO_PI)) {
52528
52656
  lo = Math.min(lo, -1);
52529
52657
  hi = Math.max(hi, -1);
52530
52658
  }
52531
52659
  return ok({ lo, hi });
52532
52660
  }
52533
52661
  function asin2(x) {
52534
- if (x.lo > 1 || x.hi < -1) {
52662
+ const unwrapped = unwrapOrPropagate(x);
52663
+ if (!Array.isArray(unwrapped)) return unwrapped;
52664
+ const [xVal] = unwrapped;
52665
+ if (xVal.lo > 1 || xVal.hi < -1) {
52535
52666
  return { kind: "empty" };
52536
52667
  }
52537
- if (x.lo < -1 || x.hi > 1) {
52538
- const clippedLo = Math.max(x.lo, -1);
52539
- const clippedHi = Math.min(x.hi, 1);
52668
+ if (xVal.lo < -1 || xVal.hi > 1) {
52669
+ const clippedLo = Math.max(xVal.lo, -1);
52670
+ const clippedHi = Math.min(xVal.hi, 1);
52540
52671
  return {
52541
52672
  kind: "partial",
52542
52673
  value: { lo: Math.asin(clippedLo), hi: Math.asin(clippedHi) },
52543
- domainClipped: x.lo < -1 && x.hi > 1 ? "both" : x.lo < -1 ? "lo" : "hi"
52674
+ domainClipped: xVal.lo < -1 && xVal.hi > 1 ? "both" : xVal.lo < -1 ? "lo" : "hi"
52544
52675
  };
52545
52676
  }
52546
- return ok({ lo: Math.asin(x.lo), hi: Math.asin(x.hi) });
52677
+ return ok({ lo: Math.asin(xVal.lo), hi: Math.asin(xVal.hi) });
52547
52678
  }
52548
52679
  function acos2(x) {
52549
- if (x.lo > 1 || x.hi < -1) {
52680
+ const unwrapped = unwrapOrPropagate(x);
52681
+ if (!Array.isArray(unwrapped)) return unwrapped;
52682
+ const [xVal] = unwrapped;
52683
+ if (xVal.lo > 1 || xVal.hi < -1) {
52550
52684
  return { kind: "empty" };
52551
52685
  }
52552
- if (x.lo < -1 || x.hi > 1) {
52553
- const clippedLo = Math.max(x.lo, -1);
52554
- const clippedHi = Math.min(x.hi, 1);
52686
+ if (xVal.lo < -1 || xVal.hi > 1) {
52687
+ const clippedLo = Math.max(xVal.lo, -1);
52688
+ const clippedHi = Math.min(xVal.hi, 1);
52555
52689
  return {
52556
52690
  kind: "partial",
52557
52691
  value: { lo: Math.acos(clippedHi), hi: Math.acos(clippedLo) },
52558
- domainClipped: x.lo < -1 && x.hi > 1 ? "both" : x.lo < -1 ? "lo" : "hi"
52692
+ domainClipped: xVal.lo < -1 && xVal.hi > 1 ? "both" : xVal.lo < -1 ? "lo" : "hi"
52559
52693
  };
52560
52694
  }
52561
- return ok({ lo: Math.acos(x.hi), hi: Math.acos(x.lo) });
52695
+ return ok({ lo: Math.acos(xVal.hi), hi: Math.acos(xVal.lo) });
52562
52696
  }
52563
52697
  function atan3(x) {
52564
- return ok({ lo: Math.atan(x.lo), hi: Math.atan(x.hi) });
52698
+ const unwrapped = unwrapOrPropagate(x);
52699
+ if (!Array.isArray(unwrapped)) return unwrapped;
52700
+ const [xVal] = unwrapped;
52701
+ return ok({ lo: Math.atan(xVal.lo), hi: Math.atan(xVal.hi) });
52565
52702
  }
52566
52703
  function atan22(y, x) {
52567
- if (y.lo === y.hi && x.lo === x.hi) {
52568
- const result = Math.atan2(y.lo, x.lo);
52704
+ const unwrapped = unwrapOrPropagate(y, x);
52705
+ if (!Array.isArray(unwrapped)) return unwrapped;
52706
+ const [yVal, xVal] = unwrapped;
52707
+ if (yVal.lo === yVal.hi && xVal.lo === xVal.hi) {
52708
+ const result = Math.atan2(yVal.lo, xVal.lo);
52569
52709
  return ok({ lo: result, hi: result });
52570
52710
  }
52571
52711
  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) {
52712
+ angles.push(Math.atan2(yVal.lo, xVal.lo));
52713
+ angles.push(Math.atan2(yVal.lo, xVal.hi));
52714
+ angles.push(Math.atan2(yVal.hi, xVal.lo));
52715
+ angles.push(Math.atan2(yVal.hi, xVal.hi));
52716
+ if (xVal.lo < 0 && yVal.lo < 0 && yVal.hi > 0) {
52577
52717
  return ok({ lo: -PI2, hi: PI2 });
52578
52718
  }
52579
52719
  return ok({ lo: Math.min(...angles), hi: Math.max(...angles) });
52580
52720
  }
52581
52721
  function sinh3(x) {
52582
- return ok({ lo: Math.sinh(x.lo), hi: Math.sinh(x.hi) });
52722
+ const unwrapped = unwrapOrPropagate(x);
52723
+ if (!Array.isArray(unwrapped)) return unwrapped;
52724
+ const [xVal] = unwrapped;
52725
+ return ok({ lo: Math.sinh(xVal.lo), hi: Math.sinh(xVal.hi) });
52583
52726
  }
52584
52727
  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) });
52728
+ const unwrapped = unwrapOrPropagate(x);
52729
+ if (!Array.isArray(unwrapped)) return unwrapped;
52730
+ const [xVal] = unwrapped;
52731
+ if (xVal.lo >= 0) {
52732
+ return ok({ lo: Math.cosh(xVal.lo), hi: Math.cosh(xVal.hi) });
52733
+ } else if (xVal.hi <= 0) {
52734
+ return ok({ lo: Math.cosh(xVal.hi), hi: Math.cosh(xVal.lo) });
52589
52735
  } else {
52590
- return ok({ lo: 1, hi: Math.max(Math.cosh(x.lo), Math.cosh(x.hi)) });
52736
+ return ok({
52737
+ lo: 1,
52738
+ hi: Math.max(Math.cosh(xVal.lo), Math.cosh(xVal.hi))
52739
+ });
52591
52740
  }
52592
52741
  }
52593
52742
  function tanh2(x) {
52594
- return ok({ lo: Math.tanh(x.lo), hi: Math.tanh(x.hi) });
52743
+ const unwrapped = unwrapOrPropagate(x);
52744
+ if (!Array.isArray(unwrapped)) return unwrapped;
52745
+ const [xVal] = unwrapped;
52746
+ return ok({ lo: Math.tanh(xVal.lo), hi: Math.tanh(xVal.hi) });
52595
52747
  }
52596
52748
  function asinh2(x) {
52597
- return ok({ lo: Math.asinh(x.lo), hi: Math.asinh(x.hi) });
52749
+ const unwrapped = unwrapOrPropagate(x);
52750
+ if (!Array.isArray(unwrapped)) return unwrapped;
52751
+ const [xVal] = unwrapped;
52752
+ return ok({ lo: Math.asinh(xVal.lo), hi: Math.asinh(xVal.hi) });
52598
52753
  }
52599
52754
  function acosh2(x) {
52600
- if (x.hi < 1) {
52755
+ const unwrapped = unwrapOrPropagate(x);
52756
+ if (!Array.isArray(unwrapped)) return unwrapped;
52757
+ const [xVal] = unwrapped;
52758
+ if (xVal.hi < 1) {
52601
52759
  return { kind: "empty" };
52602
52760
  }
52603
- if (x.lo < 1) {
52761
+ if (xVal.lo < 1) {
52604
52762
  return {
52605
52763
  kind: "partial",
52606
- value: { lo: 0, hi: Math.acosh(x.hi) },
52764
+ value: { lo: 0, hi: Math.acosh(xVal.hi) },
52607
52765
  domainClipped: "lo"
52608
52766
  };
52609
52767
  }
52610
- return ok({ lo: Math.acosh(x.lo), hi: Math.acosh(x.hi) });
52768
+ return ok({ lo: Math.acosh(xVal.lo), hi: Math.acosh(xVal.hi) });
52611
52769
  }
52612
52770
  function atanh2(x) {
52613
- if (x.lo >= 1 || x.hi <= -1) {
52771
+ const unwrapped = unwrapOrPropagate(x);
52772
+ if (!Array.isArray(unwrapped)) return unwrapped;
52773
+ const [xVal] = unwrapped;
52774
+ if (xVal.lo >= 1 || xVal.hi <= -1) {
52614
52775
  return { kind: "empty" };
52615
52776
  }
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);
52777
+ if (xVal.lo <= -1 || xVal.hi >= 1) {
52778
+ const clippedLo = Math.max(xVal.lo, -1 + Number.EPSILON);
52779
+ const clippedHi = Math.min(xVal.hi, 1 - Number.EPSILON);
52619
52780
  return {
52620
52781
  kind: "partial",
52621
52782
  value: { lo: Math.atanh(clippedLo), hi: Math.atanh(clippedHi) },
52622
- domainClipped: x.lo <= -1 && x.hi >= 1 ? "both" : x.lo <= -1 ? "lo" : "hi"
52783
+ domainClipped: xVal.lo <= -1 && xVal.hi >= 1 ? "both" : xVal.lo <= -1 ? "lo" : "hi"
52623
52784
  };
52624
52785
  }
52625
- return ok({ lo: Math.atanh(x.lo), hi: Math.atanh(x.hi) });
52786
+ return ok({ lo: Math.atanh(xVal.lo), hi: Math.atanh(xVal.hi) });
52626
52787
  }
52627
52788
 
52628
52789
  // src/compute-engine/interval/comparison.ts
52629
52790
  function less(a, b) {
52630
- if (a.hi < b.lo) return "true";
52631
- if (a.lo >= b.hi) return "false";
52791
+ const unwrapped = unwrapOrPropagate(a, b);
52792
+ if (!Array.isArray(unwrapped)) return "maybe";
52793
+ const [aVal, bVal] = unwrapped;
52794
+ if (aVal.hi < bVal.lo) return "true";
52795
+ if (aVal.lo >= bVal.hi) return "false";
52632
52796
  return "maybe";
52633
52797
  }
52634
52798
  function lessEqual(a, b) {
52635
- if (a.hi <= b.lo) return "true";
52636
- if (a.lo > b.hi) return "false";
52799
+ const unwrapped = unwrapOrPropagate(a, b);
52800
+ if (!Array.isArray(unwrapped)) return "maybe";
52801
+ const [aVal, bVal] = unwrapped;
52802
+ if (aVal.hi <= bVal.lo) return "true";
52803
+ if (aVal.lo > bVal.hi) return "false";
52637
52804
  return "maybe";
52638
52805
  }
52639
52806
  function greater(a, b) {
52640
- if (a.lo > b.hi) return "true";
52641
- if (a.hi <= b.lo) return "false";
52807
+ const unwrapped = unwrapOrPropagate(a, b);
52808
+ if (!Array.isArray(unwrapped)) return "maybe";
52809
+ const [aVal, bVal] = unwrapped;
52810
+ if (aVal.lo > bVal.hi) return "true";
52811
+ if (aVal.hi <= bVal.lo) return "false";
52642
52812
  return "maybe";
52643
52813
  }
52644
52814
  function greaterEqual(a, b) {
52645
- if (a.lo >= b.hi) return "true";
52646
- if (a.hi < b.lo) return "false";
52815
+ const unwrapped = unwrapOrPropagate(a, b);
52816
+ if (!Array.isArray(unwrapped)) return "maybe";
52817
+ const [aVal, bVal] = unwrapped;
52818
+ if (aVal.lo >= bVal.hi) return "true";
52819
+ if (aVal.hi < bVal.lo) return "false";
52647
52820
  return "maybe";
52648
52821
  }
52649
52822
  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";
52823
+ const unwrapped = unwrapOrPropagate(a, b);
52824
+ if (!Array.isArray(unwrapped)) return "maybe";
52825
+ const [aVal, bVal] = unwrapped;
52826
+ if (aVal.lo === aVal.hi && bVal.lo === bVal.hi && aVal.lo === bVal.lo)
52827
+ return "true";
52828
+ if (aVal.hi < bVal.lo || bVal.hi < aVal.lo) return "false";
52652
52829
  return "maybe";
52653
52830
  }
52654
52831
  function notEqual(a, b) {
@@ -52672,22 +52849,45 @@ function not(a) {
52672
52849
  if (a === "false") return "true";
52673
52850
  return "maybe";
52674
52851
  }
52675
- function piecewise(x, condition, trueBranch, falseBranch) {
52676
- const cond = condition(x);
52852
+ function piecewise(xOrCond, conditionOrTrue, trueOrFalse, falseBranch) {
52853
+ if (xOrCond === "true" || xOrCond === "false" || xOrCond === "maybe") {
52854
+ const cond2 = xOrCond;
52855
+ const trueBranch2 = conditionOrTrue;
52856
+ const falseBranchFn2 = trueOrFalse;
52857
+ switch (cond2) {
52858
+ case "true":
52859
+ return trueBranch2();
52860
+ case "false":
52861
+ return falseBranchFn2();
52862
+ case "maybe":
52863
+ return unionResults(trueBranch2(), falseBranchFn2());
52864
+ }
52865
+ }
52866
+ const x = xOrCond;
52867
+ const condition = conditionOrTrue;
52868
+ const trueBranch = trueOrFalse;
52869
+ const falseBranchFn = falseBranch;
52870
+ const unwrapped = unwrapOrPropagate(x);
52871
+ if (!Array.isArray(unwrapped)) return unwrapped;
52872
+ const [xVal] = unwrapped;
52873
+ const cond = condition(xVal);
52677
52874
  switch (cond) {
52678
52875
  case "true":
52679
- return trueBranch(x);
52876
+ return trueBranch(xVal);
52680
52877
  case "false":
52681
- return falseBranch(x);
52878
+ return falseBranchFn(xVal);
52682
52879
  case "maybe":
52683
- const t = trueBranch(x);
52684
- const f = falseBranch(x);
52880
+ const t = trueBranch(xVal);
52881
+ const f = falseBranchFn(xVal);
52685
52882
  return unionResults(t, f);
52686
52883
  }
52687
52884
  }
52688
52885
  function clamp2(x, lo, hi) {
52689
- const resultLo = Math.max(x.lo, lo.lo);
52690
- const resultHi = Math.min(x.hi, hi.hi);
52886
+ const unwrapped = unwrapOrPropagate(x, lo, hi);
52887
+ if (!Array.isArray(unwrapped)) return unwrapped;
52888
+ const [xVal, loVal, hiVal] = unwrapped;
52889
+ const resultLo = Math.max(xVal.lo, loVal.lo);
52890
+ const resultHi = Math.min(xVal.hi, hiVal.hi);
52691
52891
  if (resultLo > resultHi) {
52692
52892
  return { kind: "empty" };
52693
52893
  }
@@ -52915,11 +53115,20 @@ var INTERVAL_JAVASCRIPT_FUNCTIONS = {
52915
53115
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
52916
53116
  return `_IA.piecewise(
52917
53117
  ${compile(args[0])},
52918
- (_x) => ${compile(args[0])},
52919
- (_x) => ${compile(args[1])},
52920
- (_x) => ${compile(args[2])}
53118
+ () => ${compile(args[1])},
53119
+ () => ${compile(args[2])}
52921
53120
  )`;
52922
- }
53121
+ },
53122
+ // Comparisons
53123
+ Equal: (args, compile) => `_IA.equal(${compile(args[0])}, ${compile(args[1])})`,
53124
+ NotEqual: (args, compile) => `_IA.notEqual(${compile(args[0])}, ${compile(args[1])})`,
53125
+ LessEqual: (args, compile) => `_IA.lessEqual(${compile(args[0])}, ${compile(args[1])})`,
53126
+ GreaterEqual: (args, compile) => `_IA.greaterEqual(${compile(args[0])}, ${compile(args[1])})`,
53127
+ Less: (args, compile) => `_IA.less(${compile(args[0])}, ${compile(args[1])})`,
53128
+ Greater: (args, compile) => `_IA.greater(${compile(args[0])}, ${compile(args[1])})`,
53129
+ And: (args, compile) => `_IA.and(${compile(args[0])}, ${compile(args[1])})`,
53130
+ Or: (args, compile) => `_IA.or(${compile(args[0])}, ${compile(args[1])})`,
53131
+ Not: (args, compile) => `_IA.not(${compile(args[0])})`
52923
53132
  };
52924
53133
  var ComputeEngineIntervalFunction = class extends Function {
52925
53134
  IA = IntervalArithmetic;
@@ -53097,6 +53306,10 @@ IntervalResult ia_partial(vec2 v, float clip) {
53097
53306
  return IntervalResult(v, clip);
53098
53307
  }
53099
53308
 
53309
+ bool ia_is_error(float status) {
53310
+ return status == IA_EMPTY || status == IA_ENTIRE || status == IA_SINGULAR;
53311
+ }
53312
+
53100
53313
  // Addition
53101
53314
  IntervalResult ia_add(vec2 a, vec2 b) {
53102
53315
  return ia_ok(vec2(a.x + b.x - IA_EPS, a.y + b.y + IA_EPS));
@@ -53412,6 +53625,198 @@ IntervalResult ia_cosh(vec2 x) {
53412
53625
  IntervalResult ia_tanh(vec2 x) {
53413
53626
  return ia_ok(vec2(tanh(x.x) - IA_EPS, tanh(x.y) + IA_EPS));
53414
53627
  }
53628
+
53629
+ // IntervalResult overloads for propagation
53630
+ IntervalResult ia_add(IntervalResult a, IntervalResult b) {
53631
+ if (ia_is_error(a.status)) return a;
53632
+ if (ia_is_error(b.status)) return b;
53633
+ return ia_add(a.value, b.value);
53634
+ }
53635
+
53636
+ IntervalResult ia_add(IntervalResult a, vec2 b) {
53637
+ if (ia_is_error(a.status)) return a;
53638
+ return ia_add(a.value, b);
53639
+ }
53640
+
53641
+ IntervalResult ia_add(vec2 a, IntervalResult b) {
53642
+ if (ia_is_error(b.status)) return b;
53643
+ return ia_add(a, b.value);
53644
+ }
53645
+
53646
+ IntervalResult ia_sub(IntervalResult a, IntervalResult b) {
53647
+ if (ia_is_error(a.status)) return a;
53648
+ if (ia_is_error(b.status)) return b;
53649
+ return ia_sub(a.value, b.value);
53650
+ }
53651
+
53652
+ IntervalResult ia_sub(IntervalResult a, vec2 b) {
53653
+ if (ia_is_error(a.status)) return a;
53654
+ return ia_sub(a.value, b);
53655
+ }
53656
+
53657
+ IntervalResult ia_sub(vec2 a, IntervalResult b) {
53658
+ if (ia_is_error(b.status)) return b;
53659
+ return ia_sub(a, b.value);
53660
+ }
53661
+
53662
+ IntervalResult ia_mul(IntervalResult a, IntervalResult b) {
53663
+ if (ia_is_error(a.status)) return a;
53664
+ if (ia_is_error(b.status)) return b;
53665
+ return ia_mul(a.value, b.value);
53666
+ }
53667
+
53668
+ IntervalResult ia_mul(IntervalResult a, vec2 b) {
53669
+ if (ia_is_error(a.status)) return a;
53670
+ return ia_mul(a.value, b);
53671
+ }
53672
+
53673
+ IntervalResult ia_mul(vec2 a, IntervalResult b) {
53674
+ if (ia_is_error(b.status)) return b;
53675
+ return ia_mul(a, b.value);
53676
+ }
53677
+
53678
+ IntervalResult ia_div(IntervalResult a, IntervalResult b) {
53679
+ if (ia_is_error(a.status)) return a;
53680
+ if (ia_is_error(b.status)) return b;
53681
+ return ia_div(a.value, b.value);
53682
+ }
53683
+
53684
+ IntervalResult ia_div(IntervalResult a, vec2 b) {
53685
+ if (ia_is_error(a.status)) return a;
53686
+ return ia_div(a.value, b);
53687
+ }
53688
+
53689
+ IntervalResult ia_div(vec2 a, IntervalResult b) {
53690
+ if (ia_is_error(b.status)) return b;
53691
+ return ia_div(a, b.value);
53692
+ }
53693
+
53694
+ IntervalResult ia_negate(IntervalResult x) {
53695
+ if (ia_is_error(x.status)) return x;
53696
+ return ia_negate(x.value);
53697
+ }
53698
+
53699
+ IntervalResult ia_sqrt(IntervalResult x) {
53700
+ if (ia_is_error(x.status)) return x;
53701
+ return ia_sqrt(x.value);
53702
+ }
53703
+
53704
+ IntervalResult ia_square(IntervalResult x) {
53705
+ if (ia_is_error(x.status)) return x;
53706
+ return ia_square(x.value);
53707
+ }
53708
+
53709
+ IntervalResult ia_exp(IntervalResult x) {
53710
+ if (ia_is_error(x.status)) return x;
53711
+ return ia_exp(x.value);
53712
+ }
53713
+
53714
+ IntervalResult ia_ln(IntervalResult x) {
53715
+ if (ia_is_error(x.status)) return x;
53716
+ return ia_ln(x.value);
53717
+ }
53718
+
53719
+ IntervalResult ia_abs(IntervalResult x) {
53720
+ if (ia_is_error(x.status)) return x;
53721
+ return ia_abs(x.value);
53722
+ }
53723
+
53724
+ IntervalResult ia_sign(IntervalResult x) {
53725
+ if (ia_is_error(x.status)) return x;
53726
+ return ia_sign(x.value);
53727
+ }
53728
+
53729
+ IntervalResult ia_floor(IntervalResult x) {
53730
+ if (ia_is_error(x.status)) return x;
53731
+ return ia_floor(x.value);
53732
+ }
53733
+
53734
+ IntervalResult ia_ceil(IntervalResult x) {
53735
+ if (ia_is_error(x.status)) return x;
53736
+ return ia_ceil(x.value);
53737
+ }
53738
+
53739
+ IntervalResult ia_min(IntervalResult a, IntervalResult b) {
53740
+ if (ia_is_error(a.status)) return a;
53741
+ if (ia_is_error(b.status)) return b;
53742
+ return ia_min(a.value, b.value);
53743
+ }
53744
+
53745
+ IntervalResult ia_min(IntervalResult a, vec2 b) {
53746
+ if (ia_is_error(a.status)) return a;
53747
+ return ia_min(a.value, b);
53748
+ }
53749
+
53750
+ IntervalResult ia_min(vec2 a, IntervalResult b) {
53751
+ if (ia_is_error(b.status)) return b;
53752
+ return ia_min(a, b.value);
53753
+ }
53754
+
53755
+ IntervalResult ia_max(IntervalResult a, IntervalResult b) {
53756
+ if (ia_is_error(a.status)) return a;
53757
+ if (ia_is_error(b.status)) return b;
53758
+ return ia_max(a.value, b.value);
53759
+ }
53760
+
53761
+ IntervalResult ia_max(IntervalResult a, vec2 b) {
53762
+ if (ia_is_error(a.status)) return a;
53763
+ return ia_max(a.value, b);
53764
+ }
53765
+
53766
+ IntervalResult ia_max(vec2 a, IntervalResult b) {
53767
+ if (ia_is_error(b.status)) return b;
53768
+ return ia_max(a, b.value);
53769
+ }
53770
+
53771
+ IntervalResult ia_pow(IntervalResult base, float exp) {
53772
+ if (ia_is_error(base.status)) return base;
53773
+ return ia_pow(base.value, exp);
53774
+ }
53775
+
53776
+ IntervalResult ia_sin(IntervalResult x) {
53777
+ if (ia_is_error(x.status)) return x;
53778
+ return ia_sin(x.value);
53779
+ }
53780
+
53781
+ IntervalResult ia_cos(IntervalResult x) {
53782
+ if (ia_is_error(x.status)) return x;
53783
+ return ia_cos(x.value);
53784
+ }
53785
+
53786
+ IntervalResult ia_tan(IntervalResult x) {
53787
+ if (ia_is_error(x.status)) return x;
53788
+ return ia_tan(x.value);
53789
+ }
53790
+
53791
+ IntervalResult ia_asin(IntervalResult x) {
53792
+ if (ia_is_error(x.status)) return x;
53793
+ return ia_asin(x.value);
53794
+ }
53795
+
53796
+ IntervalResult ia_acos(IntervalResult x) {
53797
+ if (ia_is_error(x.status)) return x;
53798
+ return ia_acos(x.value);
53799
+ }
53800
+
53801
+ IntervalResult ia_atan(IntervalResult x) {
53802
+ if (ia_is_error(x.status)) return x;
53803
+ return ia_atan(x.value);
53804
+ }
53805
+
53806
+ IntervalResult ia_sinh(IntervalResult x) {
53807
+ if (ia_is_error(x.status)) return x;
53808
+ return ia_sinh(x.value);
53809
+ }
53810
+
53811
+ IntervalResult ia_cosh(IntervalResult x) {
53812
+ if (ia_is_error(x.status)) return x;
53813
+ return ia_cosh(x.value);
53814
+ }
53815
+
53816
+ IntervalResult ia_tanh(IntervalResult x) {
53817
+ if (ia_is_error(x.status)) return x;
53818
+ return ia_tanh(x.value);
53819
+ }
53415
53820
  `;
53416
53821
  var INTERVAL_GLSL_OPERATORS = {
53417
53822
  Add: ["ia_add", 20],
@@ -54337,12 +54742,11 @@ var ComputeEngine = class _ComputeEngine {
54337
54742
  bignum
54338
54743
  );
54339
54744
  if (value instanceof Decimal) {
54340
- if (value.isInteger() && value.e <= MAX_BIGINT_DIGITS)
54341
- return new ExactNumericValue(
54342
- bigint(value.toString()),
54343
- makeNumericValue,
54344
- bignum
54345
- );
54745
+ if (value.isInteger() && value.e <= MAX_BIGINT_DIGITS) {
54746
+ const n = bigint(value.toString());
54747
+ if (n !== null)
54748
+ return new ExactNumericValue(n, makeNumericValue, bignum);
54749
+ }
54346
54750
  return makeNumericValue(value);
54347
54751
  }
54348
54752
  if (value instanceof Complex) {
@@ -55408,10 +55812,10 @@ function defToString(name, def, v) {
55408
55812
  // src/compute-engine.ts
55409
55813
  init_types6();
55410
55814
  init_base_compiler();
55411
- var version = "0.35.0";
55815
+ var version = "0.35.2";
55412
55816
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
55413
55817
  ComputeEngine: ComputeEngine.prototype.constructor,
55414
- version: "0.35.0"
55818
+ version: "0.35.2"
55415
55819
  };
55416
55820
  export {
55417
55821
  BaseCompiler,