@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
  (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngine = {}));})(this, (function (exports) { 'use strict';
3
3
  var ComputeEngine = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -5443,15 +5443,14 @@ var ComputeEngine = (() => {
5443
5443
  }
5444
5444
  if (a instanceof Decimal) {
5445
5445
  if (!a.isInteger()) return null;
5446
- return bigint(a.toString());
5446
+ return BigInt(a.toFixed(0));
5447
5447
  }
5448
5448
  let s = a.toLowerCase();
5449
- const m = s.match(/([+-]?[0-9]*)(?:\.([0-9]+))?e([+-]?[0-9]+)$/);
5449
+ const m = s.match(/^([+-]?[0-9]+)e([+-]?[0-9]+)$/);
5450
5450
  if (m) {
5451
- const exp3 = parseInt(m[3]);
5452
- const pad = exp3 - (m[2] ? m[2].length : 0);
5453
- if (pad < 0) return null;
5454
- s = (m[1] ?? "") + (m[2] ?? "") + "0".repeat(pad);
5451
+ const exp3 = parseInt(m[2]);
5452
+ if (exp3 < 0) return null;
5453
+ s = m[1] + "0".repeat(exp3);
5455
5454
  }
5456
5455
  const i = s.indexOf(".");
5457
5456
  if (i >= 0) return null;
@@ -9762,6 +9761,23 @@ var ComputeEngine = (() => {
9762
9761
  if (!m) return serializeAutoNotationNumber(valString, options);
9763
9762
  let exponent = parseInt(m[2]);
9764
9763
  let mantissa = m[1];
9764
+ {
9765
+ const signMatch = mantissa.match(/^(-?)/);
9766
+ const sign3 = signMatch ? signMatch[1] : "";
9767
+ const unsigned = sign3 ? mantissa.substring(1) : mantissa;
9768
+ const parts = unsigned.match(/^(\d+)(?:\.(\d*))?$/);
9769
+ if (parts) {
9770
+ let whole = parts[1];
9771
+ let fraction = parts[2] ?? "";
9772
+ if (whole.length > 1) {
9773
+ fraction = whole.slice(1) + fraction;
9774
+ exponent += whole.length - 1;
9775
+ whole = whole[0];
9776
+ }
9777
+ mantissa = sign3 + whole;
9778
+ if (fraction) mantissa += "." + fraction;
9779
+ }
9780
+ }
9765
9781
  if (Math.abs(exponent) % expMultiple !== 0) {
9766
9782
  const adjust = exponent > 0 ? exponent % expMultiple : -((expMultiple + exponent) % expMultiple);
9767
9783
  exponent = exponent >= 0 ? exponent - adjust : exponent + adjust;
@@ -11720,7 +11736,8 @@ var ComputeEngine = (() => {
11720
11736
  }
11721
11737
  } else {
11722
11738
  console.assert(isSubtype(value.type, "integer"));
11723
- rationalSum = add2(rationalSum, [value.re, 1]);
11739
+ const intValue = BigInt(value.bignumRe.toFixed(0));
11740
+ rationalSum = add2(rationalSum, [intValue, BigInt(1)]);
11724
11741
  }
11725
11742
  }
11726
11743
  if (isZero(rationalSum) && radicals.length === 0) {
@@ -12086,11 +12103,14 @@ var ComputeEngine = (() => {
12086
12103
  const ce = op1.engine;
12087
12104
  if (!op1.isValid || !op2.isValid) return ce._fn("Divide", [op1, op2]);
12088
12105
  if (op1.isNaN || op2.isNaN) return ce.NaN;
12089
- const op2IsConstantExpression = op2.symbols.length === 0 && !op2.isNumberLiteral;
12106
+ const op2IsConstantExpression = op2.unknowns.length === 0 && !op2.isNumberLiteral;
12090
12107
  if (op2.is(0)) return op1.is(0) ? ce.NaN : ce.ComplexInfinity;
12091
12108
  if (op1.is(0) && op2.isFinite !== false) {
12092
12109
  if (op2IsConstantExpression)
12093
- return ce._fn("Divide", [op1, op2], { canonical: false });
12110
+ return ce.function("Divide", [op1, op2], {
12111
+ canonical: false,
12112
+ structural: true
12113
+ });
12094
12114
  return ce.Zero;
12095
12115
  }
12096
12116
  if (op2.isInfinity) return op1.isInfinity ? ce.NaN : ce.Zero;
@@ -12099,7 +12119,10 @@ var ComputeEngine = (() => {
12099
12119
  return ce.One;
12100
12120
  if (op1.isSame(op2)) {
12101
12121
  if (op2IsConstantExpression)
12102
- return ce._fn("Divide", [op1, op2], { canonical: false });
12122
+ return ce.function("Divide", [op1, op2], {
12123
+ canonical: false,
12124
+ structural: true
12125
+ });
12103
12126
  return ce.One;
12104
12127
  }
12105
12128
  }
@@ -15250,7 +15273,7 @@ var ComputeEngine = (() => {
15250
15273
  }
15251
15274
  function canonicalPower(a, b) {
15252
15275
  const ce = a.engine;
15253
- const fullyCanonical = a.isCanonical && b.isCanonical;
15276
+ const fullyCanonical = (a.isCanonical || a.isStructural) && (b.isCanonical || b.isStructural);
15254
15277
  const unchanged = () => ce._fn("Power", [a, b], { canonical: fullyCanonical });
15255
15278
  if (a.operator === "Power") {
15256
15279
  const [base, aPow] = a.ops;
@@ -15296,7 +15319,7 @@ var ComputeEngine = (() => {
15296
15319
  if (a.is(-1)) return ce.NegativeOne;
15297
15320
  if (a.is(1)) return ce.One;
15298
15321
  }
15299
- if (!a.isCanonical)
15322
+ if (!(a.isCanonical || a.isStructural))
15300
15323
  return ce._fn("Power", [a, ce.number(-1)], { canonical: false });
15301
15324
  return a.inv();
15302
15325
  }
@@ -15352,10 +15375,10 @@ var ComputeEngine = (() => {
15352
15375
  }
15353
15376
  }
15354
15377
  if (b.is(0.5))
15355
- return a.isCanonical ? canonicalRoot(a, 2) : ce._fn("Sqrt", [a], { canonical: false });
15378
+ return a.isCanonical || a.isStructural ? canonicalRoot(a, 2) : ce._fn("Sqrt", [a], { canonical: false });
15356
15379
  const r = asRational(b);
15357
15380
  if (r !== void 0 && r[0] === 1 && r[1] !== 1)
15358
- return a.isCanonical ? canonicalRoot(a, ce.number(r[1])) : ce._fn("Root", [a, ce.number(r[1])], { canonical: false });
15381
+ return a.isCanonical || a.isStructural ? canonicalRoot(a, ce.number(r[1])) : ce._fn("Root", [a, ce.number(r[1])], { canonical: false });
15359
15382
  return unchanged();
15360
15383
  }
15361
15384
  function canonicalRoot(a, b) {
@@ -15374,14 +15397,14 @@ var ComputeEngine = (() => {
15374
15397
  if (v.numericValue.isExact) return v;
15375
15398
  }
15376
15399
  }
15377
- return ce._fn("Sqrt", [a], { canonical: a.isCanonical });
15400
+ return ce._fn("Sqrt", [a], { canonical: a.isCanonical || a.isStructural });
15378
15401
  }
15379
15402
  return ce._fn("Root", [a, typeof b === "number" ? ce.number(b) : b], {
15380
- canonical: a.isCanonical && (typeof b === "number" || b.isCanonical)
15403
+ canonical: (a.isCanonical || a.isStructural) && (typeof b === "number" || b.isCanonical || b.isStructural)
15381
15404
  });
15382
15405
  }
15383
15406
  function pow2(x, exp3, { numericApproximation }) {
15384
- if (!x.isCanonical || typeof exp3 !== "number" && !exp3.isCanonical)
15407
+ if (!(x.isCanonical || x.isStructural) || typeof exp3 !== "number" && !(exp3.isCanonical || exp3.isStructural))
15385
15408
  return x.engine._fn("Power", [x, x.engine.box(exp3)], { canonical: false });
15386
15409
  if (numericApproximation) {
15387
15410
  if (x.isNumberLiteral) {
@@ -15477,7 +15500,7 @@ var ComputeEngine = (() => {
15477
15500
  return ce._fn("Power", [x, ce.box(exp3)]);
15478
15501
  }
15479
15502
  function root(a, b, { numericApproximation }) {
15480
- if (!a.isCanonical || !b.isCanonical)
15503
+ if (!(a.isCanonical || a.isStructural) || !(b.isCanonical || b.isStructural))
15481
15504
  return a.engine._fn("Root", [a, b], { canonical: false });
15482
15505
  if (numericApproximation) {
15483
15506
  if (a.isNumberLiteral && b.isNumberLiteral) {
@@ -15683,7 +15706,7 @@ var ComputeEngine = (() => {
15683
15706
  return (a.complexity ?? DEFAULT_COMPLEXITY) - (b.complexity ?? DEFAULT_COMPLEXITY);
15684
15707
  }
15685
15708
  function canonicalOrder(expr, { recursive = false }) {
15686
- if (expr.isCanonical || !expr.ops) return expr;
15709
+ if (expr.isCanonical || expr.isStructural || !expr.ops) return expr;
15687
15710
  let ops = expr.ops;
15688
15711
  if (recursive) ops = ops.map((x) => canonicalOrder(x, { recursive }));
15689
15712
  ops = sortOperands(expr.operator, ops);
@@ -20107,6 +20130,14 @@ var ComputeEngine = (() => {
20107
20130
  return `return ${_BaseCompiler.compile(args[0], target)}`;
20108
20131
  if (h === "If") {
20109
20132
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
20133
+ const fn2 = target.functions?.(h);
20134
+ if (fn2) {
20135
+ if (typeof fn2 === "function") {
20136
+ return fn2(args, (expr) => _BaseCompiler.compile(expr, target), target);
20137
+ }
20138
+ if (args === null) return `${fn2}()`;
20139
+ return `${fn2}(${args.map((x) => _BaseCompiler.compile(x, target)).join(", ")})`;
20140
+ }
20110
20141
  return `((${_BaseCompiler.compile(args[0], target)}) ? (${_BaseCompiler.compile(
20111
20142
  args[1],
20112
20143
  target
@@ -23789,6 +23820,24 @@ ${e.message}`);
23789
23820
  });
23790
23821
 
23791
23822
  // src/compute-engine/boxed-expression/validate.ts
23823
+ function typeCouldBeCollection(type2) {
23824
+ if (typeof type2 === "string") {
23825
+ return type2 === "collection" || type2 === "indexed_collection" || type2 === "list" || type2 === "set" || type2 === "tuple" || type2 === "any";
23826
+ }
23827
+ if (type2.kind === "list" || type2.kind === "set" || type2.kind === "tuple")
23828
+ return true;
23829
+ if (type2.kind === "union") return type2.types.some((t) => typeCouldBeCollection(t));
23830
+ return false;
23831
+ }
23832
+ function typeCouldBeNumericCollection(type2) {
23833
+ if (typeof type2 === "string") {
23834
+ return type2 === "list" || type2 === "set" || type2 === "collection" || type2 === "indexed_collection";
23835
+ }
23836
+ if (type2.kind === "list" || type2.kind === "set") return true;
23837
+ if (type2.kind === "union")
23838
+ return type2.types.some((t) => typeCouldBeNumericCollection(t));
23839
+ return false;
23840
+ }
23792
23841
  function checkArity(ce, ops, count) {
23793
23842
  ops = flatten(ops);
23794
23843
  if (!ce.strict) return ops;
@@ -23838,7 +23887,9 @@ ${e.message}`);
23838
23887
  xs.push(op);
23839
23888
  } else if (op.symbol && !ce.lookupDefinition(op.symbol)) {
23840
23889
  xs.push(op);
23841
- } else if (op.type.isUnknown) {
23890
+ } else if (op.type.isUnknown || op.type.type === "any") {
23891
+ xs.push(op);
23892
+ } else if (typeCouldBeNumericCollection(op.type.type)) {
23842
23893
  xs.push(op);
23843
23894
  } else if (isBoxedTensor(op)) {
23844
23895
  xs.push(op);
@@ -23922,11 +23973,11 @@ ${e.message}`);
23922
23973
  isValid = false;
23923
23974
  continue;
23924
23975
  }
23925
- if (op.type.isUnknown) {
23976
+ if (op.type.isUnknown || op.type.type === "any") {
23926
23977
  result.push(op);
23927
23978
  continue;
23928
23979
  }
23929
- if (threadable && isFiniteIndexedCollection(op)) {
23980
+ if (threadable && (isFiniteIndexedCollection(op) || typeCouldBeCollection(op.type.type))) {
23930
23981
  result.push(op);
23931
23982
  continue;
23932
23983
  }
@@ -23961,12 +24012,12 @@ ${e.message}`);
23961
24012
  i += 1;
23962
24013
  continue;
23963
24014
  }
23964
- if (op.type.isUnknown) {
24015
+ if (op.type.isUnknown || op.type.type === "any") {
23965
24016
  result.push(op);
23966
24017
  i += 1;
23967
24018
  continue;
23968
24019
  }
23969
- if (threadable && isFiniteIndexedCollection(op)) {
24020
+ if (threadable && (isFiniteIndexedCollection(op) || typeCouldBeCollection(op.type.type))) {
23970
24021
  result.push(op);
23971
24022
  i += 1;
23972
24023
  continue;
@@ -23999,11 +24050,11 @@ ${e.message}`);
23999
24050
  isValid = false;
24000
24051
  continue;
24001
24052
  }
24002
- if (op.type.isUnknown) {
24053
+ if (op.type.isUnknown || op.type.type === "any") {
24003
24054
  result.push(op);
24004
24055
  continue;
24005
24056
  }
24006
- if (threadable && isFiniteIndexedCollection(op)) {
24057
+ if (threadable && (isFiniteIndexedCollection(op) || typeCouldBeCollection(op.type.type))) {
24007
24058
  result.push(op);
24008
24059
  continue;
24009
24060
  }
@@ -24033,20 +24084,22 @@ ${e.message}`);
24033
24084
  i = 0;
24034
24085
  for (const param of params) {
24035
24086
  if (!lazy) {
24036
- if (!threadable || !isFiniteIndexedCollection(ops[i]))
24087
+ if (!threadable || !isFiniteIndexedCollection(ops[i]) && !typeCouldBeCollection(ops[i].type.type))
24037
24088
  ops[i].infer(param);
24038
24089
  }
24039
24090
  i += 1;
24040
24091
  }
24041
24092
  for (const param of optParams) {
24042
24093
  if (!ops[i]) break;
24043
- if (!threadable || !isFiniteIndexedCollection(ops[i])) ops[i]?.infer(param);
24094
+ if (!threadable || !isFiniteIndexedCollection(ops[i]) && !typeCouldBeCollection(ops[i].type.type))
24095
+ ops[i]?.infer(param);
24044
24096
  i += 1;
24045
24097
  }
24046
24098
  if (varParam) {
24047
24099
  for (const op of ops.slice(i)) {
24048
24100
  if (!lazy) {
24049
- if (!threadable || !isFiniteIndexedCollection(op)) op.infer(varParam);
24101
+ if (!threadable || !isFiniteIndexedCollection(op) && !typeCouldBeCollection(op.type.type))
24102
+ op.infer(varParam);
24050
24103
  }
24051
24104
  i += 1;
24052
24105
  }
@@ -35470,6 +35523,12 @@ ${lines.join("\n")}`;
35470
35523
  throw Error("Invalid canonical form");
35471
35524
  }
35472
35525
  }
35526
+ if (expr.isFunctionExpression && expr.isCanonical) {
35527
+ expr = expr.engine.function(expr.operator, [...expr.ops], {
35528
+ canonical: false,
35529
+ structural: true
35530
+ });
35531
+ }
35473
35532
  return expr;
35474
35533
  }
35475
35534
  function flattenForm(expr) {
@@ -35551,10 +35610,7 @@ ${lines.join("\n")}`;
35551
35610
  if (!expr.ops) return expr;
35552
35611
  const ops = expr.ops.map(multiplyForm);
35553
35612
  if (expr.operator === "Multiply")
35554
- return canonicalMultiply(
35555
- expr.engine,
35556
- ops.map((x) => x.canonical)
35557
- );
35613
+ return canonicalMultiply(expr.engine, ops);
35558
35614
  if (expr.operator === "Negate")
35559
35615
  return canonicalMultiply(expr.engine, [ops[0], expr.engine.NegativeOne]);
35560
35616
  return expr;
@@ -45688,7 +45744,7 @@ Error in definition of "${name}"`,
45688
45744
  return void 0;
45689
45745
  }
45690
45746
  get isCanonical() {
45691
- return this._def !== void 0 && this._def !== null;
45747
+ return this._def !== void 0 && this._def !== null && !this._isStructural;
45692
45748
  }
45693
45749
  get isPure() {
45694
45750
  if (this._isPure !== void 0) return this._isPure;
@@ -45855,7 +45911,7 @@ Error in definition of "${name}"`,
45855
45911
  subs(sub3, options) {
45856
45912
  options ??= { canonical: void 0 };
45857
45913
  if (options.canonical === void 0)
45858
- options = { canonical: this.isCanonical };
45914
+ options = { canonical: this.isCanonical || this.isStructural };
45859
45915
  const ops = this._ops.map((x) => x.subs(sub3, options));
45860
45916
  if (!ops.every((x) => x.isValid))
45861
45917
  return this.engine.function(this._operator, ops, { canonical: false });
@@ -45927,7 +45983,7 @@ Error in definition of "${name}"`,
45927
45983
  return this.numeratorDenominator[1];
45928
45984
  }
45929
45985
  get numeratorDenominator() {
45930
- if (!this.isCanonical) return [this, this.engine.One];
45986
+ if (!(this.isCanonical || this.isStructural)) return [this, this.engine.One];
45931
45987
  if (this.isNumber !== true)
45932
45988
  return [this.engine.Nothing, this.engine.Nothing];
45933
45989
  const operator2 = this.operator;
@@ -45965,11 +46021,11 @@ Error in definition of "${name}"`,
45965
46021
  // ALGEBRAIC OPERATIONS
45966
46022
  //
45967
46023
  neg() {
45968
- if (!this.isCanonical) throw new Error("Not canonical");
46024
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45969
46025
  return negate(this);
45970
46026
  }
45971
46027
  inv() {
45972
- if (!this.isCanonical) throw new Error("Not canonical");
46028
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45973
46029
  if (this.isOne) return this;
45974
46030
  if (this.isNegativeOne) return this;
45975
46031
  if (this.operator === "Sqrt") return this.op1.inv().sqrt();
@@ -45990,7 +46046,7 @@ Error in definition of "${name}"`,
45990
46046
  return this.engine._fn("Divide", [this.engine.One, this]);
45991
46047
  }
45992
46048
  abs() {
45993
- if (!this.isCanonical) throw new Error("Not canonical");
46049
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
45994
46050
  if (this.operator === "Abs" || this.operator === "Negate") return this;
45995
46051
  if (this.isNonNegative) return this;
45996
46052
  if (this.isNonPositive) return this.neg();
@@ -45998,11 +46054,11 @@ Error in definition of "${name}"`,
45998
46054
  }
45999
46055
  add(rhs) {
46000
46056
  if (rhs === 0) return this;
46001
- if (!this.isCanonical) throw new Error("Not canonical");
46057
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
46002
46058
  return add3(this, this.engine.box(rhs));
46003
46059
  }
46004
46060
  mul(rhs) {
46005
- if (!this.isCanonical) throw new Error("Not canonical");
46061
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
46006
46062
  if (rhs === 0) return this.engine.Zero;
46007
46063
  if (rhs === 1) return this;
46008
46064
  if (rhs === -1) return this.neg();
@@ -46014,14 +46070,14 @@ Error in definition of "${name}"`,
46014
46070
  return mul3(this, this.engine.box(rhs));
46015
46071
  }
46016
46072
  div(rhs) {
46017
- if (!this.isCanonical) throw new Error("Not canonical");
46073
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
46018
46074
  return div2(this, rhs);
46019
46075
  }
46020
46076
  pow(exp3) {
46021
46077
  return pow2(this, exp3, { numericApproximation: false });
46022
46078
  }
46023
46079
  root(exp3) {
46024
- if (!this.isCanonical || typeof exp3 !== "number" && !exp3.isCanonical)
46080
+ if (!(this.isCanonical || this.isStructural) || typeof exp3 !== "number" && !(exp3.isCanonical || exp3.isStructural))
46025
46081
  throw new Error("Not canonical");
46026
46082
  const e = typeof exp3 === "number" ? exp3 : exp3.im === 0 ? exp3.re : void 0;
46027
46083
  if (e === 0) return this.engine.NaN;
@@ -46080,7 +46136,7 @@ Error in definition of "${name}"`,
46080
46136
  }
46081
46137
  ln(semiBase) {
46082
46138
  const base = semiBase ? this.engine.box(semiBase) : void 0;
46083
- if (!this.isCanonical) throw new Error("Not canonical");
46139
+ if (!(this.isCanonical || this.isStructural)) throw new Error("Not canonical");
46084
46140
  if (this.is(0)) return this.engine.NegativeInfinity;
46085
46141
  if (this.operator === "Exp") {
46086
46142
  if (!base) return this.op1;
@@ -46113,7 +46169,7 @@ Error in definition of "${name}"`,
46113
46169
  return this.engine._fn("Ln", [this]);
46114
46170
  }
46115
46171
  get complexity() {
46116
- if (!this.isCanonical) return void 0;
46172
+ if (!(this.isCanonical || this.isStructural)) return void 0;
46117
46173
  return this.operatorDefinition?.complexity ?? DEFAULT_COMPLEXITY;
46118
46174
  }
46119
46175
  get baseDefinition() {
@@ -52279,49 +52335,64 @@ Error in definition of "${name}"`,
52279
52335
  return { lo: Math.pow(base.lo, n), hi: Math.pow(base.hi, n) };
52280
52336
  }
52281
52337
  function pow3(base, exp3) {
52338
+ const unwrapped = unwrapOrPropagate(base);
52339
+ if (!Array.isArray(unwrapped)) return unwrapped;
52340
+ const [baseVal] = unwrapped;
52282
52341
  if (Number.isInteger(exp3)) {
52283
52342
  if (exp3 >= 0) {
52284
- return ok(intPow2(base, exp3));
52343
+ return ok(intPow2(baseVal, exp3));
52285
52344
  } else {
52286
- if (containsZero(base)) {
52345
+ if (containsZero(baseVal)) {
52287
52346
  return { kind: "singular" };
52288
52347
  }
52289
- const denom = intPow2(base, -exp3);
52348
+ const denom = intPow2(baseVal, -exp3);
52290
52349
  return ok({ lo: 1 / denom.hi, hi: 1 / denom.lo });
52291
52350
  }
52292
52351
  } else {
52293
- if (isNegative(base)) {
52352
+ if (isNegative(baseVal)) {
52294
52353
  return { kind: "empty" };
52295
52354
  }
52296
- if (base.lo < 0) {
52297
- const value = exp3 > 0 ? { lo: 0, hi: Math.pow(base.hi, exp3) } : { lo: Math.pow(base.hi, exp3), hi: Infinity };
52355
+ if (baseVal.lo < 0) {
52356
+ const value = exp3 > 0 ? { lo: 0, hi: Math.pow(baseVal.hi, exp3) } : { lo: Math.pow(baseVal.hi, exp3), hi: Infinity };
52298
52357
  return { kind: "partial", value, domainClipped: "lo" };
52299
52358
  }
52300
52359
  if (exp3 > 0) {
52301
- return ok({ lo: Math.pow(base.lo, exp3), hi: Math.pow(base.hi, exp3) });
52360
+ return ok({
52361
+ lo: Math.pow(baseVal.lo, exp3),
52362
+ hi: Math.pow(baseVal.hi, exp3)
52363
+ });
52302
52364
  } else {
52303
- if (base.lo === 0) {
52365
+ if (baseVal.lo === 0) {
52304
52366
  return {
52305
52367
  kind: "partial",
52306
- value: { lo: Math.pow(base.hi, exp3), hi: Infinity },
52368
+ value: { lo: Math.pow(baseVal.hi, exp3), hi: Infinity },
52307
52369
  domainClipped: "hi"
52308
52370
  };
52309
52371
  }
52310
- return ok({ lo: Math.pow(base.hi, exp3), hi: Math.pow(base.lo, exp3) });
52372
+ return ok({
52373
+ lo: Math.pow(baseVal.hi, exp3),
52374
+ hi: Math.pow(baseVal.lo, exp3)
52375
+ });
52311
52376
  }
52312
52377
  }
52313
52378
  }
52314
52379
  function powInterval(base, exp3) {
52315
- if (base.hi <= 0) {
52380
+ const unwrapped = unwrapOrPropagate(base, exp3);
52381
+ if (!Array.isArray(unwrapped)) return unwrapped;
52382
+ const [baseVal, expVal] = unwrapped;
52383
+ if (baseVal.hi <= 0) {
52316
52384
  return { kind: "empty" };
52317
52385
  }
52318
- if (base.lo <= 0) {
52319
- const posBase = { lo: Math.max(base.lo, Number.EPSILON), hi: base.hi };
52386
+ if (baseVal.lo <= 0) {
52387
+ const posBase = {
52388
+ lo: Math.max(baseVal.lo, Number.EPSILON),
52389
+ hi: baseVal.hi
52390
+ };
52320
52391
  const corners2 = [
52321
- Math.pow(posBase.lo, exp3.lo),
52322
- Math.pow(posBase.lo, exp3.hi),
52323
- Math.pow(posBase.hi, exp3.lo),
52324
- Math.pow(posBase.hi, exp3.hi)
52392
+ Math.pow(posBase.lo, expVal.lo),
52393
+ Math.pow(posBase.lo, expVal.hi),
52394
+ Math.pow(posBase.hi, expVal.lo),
52395
+ Math.pow(posBase.hi, expVal.hi)
52325
52396
  ];
52326
52397
  return {
52327
52398
  kind: "partial",
@@ -52330,10 +52401,10 @@ Error in definition of "${name}"`,
52330
52401
  };
52331
52402
  }
52332
52403
  const corners = [
52333
- Math.pow(base.lo, exp3.lo),
52334
- Math.pow(base.lo, exp3.hi),
52335
- Math.pow(base.hi, exp3.lo),
52336
- Math.pow(base.hi, exp3.hi)
52404
+ Math.pow(baseVal.lo, expVal.lo),
52405
+ Math.pow(baseVal.lo, expVal.hi),
52406
+ Math.pow(baseVal.hi, expVal.lo),
52407
+ Math.pow(baseVal.hi, expVal.hi)
52337
52408
  ];
52338
52409
  return ok({ lo: Math.min(...corners), hi: Math.max(...corners) });
52339
52410
  }
@@ -52344,79 +52415,115 @@ Error in definition of "${name}"`,
52344
52415
  return ok({ lo: Math.exp(xVal.lo), hi: Math.exp(xVal.hi) });
52345
52416
  }
52346
52417
  function ln2(x) {
52347
- if (x.hi <= 0) {
52418
+ const unwrapped = unwrapOrPropagate(x);
52419
+ if (!Array.isArray(unwrapped)) return unwrapped;
52420
+ const [xVal] = unwrapped;
52421
+ if (xVal.hi <= 0) {
52348
52422
  return { kind: "empty" };
52349
52423
  }
52350
- if (x.lo > 0) {
52351
- return ok({ lo: Math.log(x.lo), hi: Math.log(x.hi) });
52424
+ if (xVal.lo > 0) {
52425
+ return ok({ lo: Math.log(xVal.lo), hi: Math.log(xVal.hi) });
52352
52426
  }
52353
52427
  return {
52354
52428
  kind: "partial",
52355
- value: { lo: -Infinity, hi: Math.log(x.hi) },
52429
+ value: { lo: -Infinity, hi: Math.log(xVal.hi) },
52356
52430
  domainClipped: "lo"
52357
52431
  };
52358
52432
  }
52359
52433
  function log102(x) {
52360
- if (x.hi <= 0) {
52434
+ const unwrapped = unwrapOrPropagate(x);
52435
+ if (!Array.isArray(unwrapped)) return unwrapped;
52436
+ const [xVal] = unwrapped;
52437
+ if (xVal.hi <= 0) {
52361
52438
  return { kind: "empty" };
52362
52439
  }
52363
- if (x.lo > 0) {
52364
- return ok({ lo: Math.log10(x.lo), hi: Math.log10(x.hi) });
52440
+ if (xVal.lo > 0) {
52441
+ return ok({ lo: Math.log10(xVal.lo), hi: Math.log10(xVal.hi) });
52365
52442
  }
52366
52443
  return {
52367
52444
  kind: "partial",
52368
- value: { lo: -Infinity, hi: Math.log10(x.hi) },
52445
+ value: { lo: -Infinity, hi: Math.log10(xVal.hi) },
52369
52446
  domainClipped: "lo"
52370
52447
  };
52371
52448
  }
52372
52449
  function log22(x) {
52373
- if (x.hi <= 0) {
52450
+ const unwrapped = unwrapOrPropagate(x);
52451
+ if (!Array.isArray(unwrapped)) return unwrapped;
52452
+ const [xVal] = unwrapped;
52453
+ if (xVal.hi <= 0) {
52374
52454
  return { kind: "empty" };
52375
52455
  }
52376
- if (x.lo > 0) {
52377
- return ok({ lo: Math.log2(x.lo), hi: Math.log2(x.hi) });
52456
+ if (xVal.lo > 0) {
52457
+ return ok({ lo: Math.log2(xVal.lo), hi: Math.log2(xVal.hi) });
52378
52458
  }
52379
52459
  return {
52380
52460
  kind: "partial",
52381
- value: { lo: -Infinity, hi: Math.log2(x.hi) },
52461
+ value: { lo: -Infinity, hi: Math.log2(xVal.hi) },
52382
52462
  domainClipped: "lo"
52383
52463
  };
52384
52464
  }
52385
52465
  function abs2(x) {
52386
- if (x.lo >= 0) {
52387
- return ok(x);
52466
+ const unwrapped = unwrapOrPropagate(x);
52467
+ if (!Array.isArray(unwrapped)) return unwrapped;
52468
+ const [xVal] = unwrapped;
52469
+ if (xVal.lo >= 0) {
52470
+ return ok(xVal);
52388
52471
  }
52389
- if (x.hi <= 0) {
52390
- return ok({ lo: -x.hi, hi: -x.lo });
52472
+ if (xVal.hi <= 0) {
52473
+ return ok({ lo: -xVal.hi, hi: -xVal.lo });
52391
52474
  }
52392
- return ok({ lo: 0, hi: Math.max(-x.lo, x.hi) });
52475
+ return ok({ lo: 0, hi: Math.max(-xVal.lo, xVal.hi) });
52393
52476
  }
52394
52477
  function floor2(x) {
52395
- return ok({ lo: Math.floor(x.lo), hi: Math.floor(x.hi) });
52478
+ const unwrapped = unwrapOrPropagate(x);
52479
+ if (!Array.isArray(unwrapped)) return unwrapped;
52480
+ const [xVal] = unwrapped;
52481
+ return ok({ lo: Math.floor(xVal.lo), hi: Math.floor(xVal.hi) });
52396
52482
  }
52397
52483
  function ceil2(x) {
52398
- return ok({ lo: Math.ceil(x.lo), hi: Math.ceil(x.hi) });
52484
+ const unwrapped = unwrapOrPropagate(x);
52485
+ if (!Array.isArray(unwrapped)) return unwrapped;
52486
+ const [xVal] = unwrapped;
52487
+ return ok({ lo: Math.ceil(xVal.lo), hi: Math.ceil(xVal.hi) });
52399
52488
  }
52400
52489
  function round2(x) {
52401
- return ok({ lo: Math.round(x.lo), hi: Math.round(x.hi) });
52490
+ const unwrapped = unwrapOrPropagate(x);
52491
+ if (!Array.isArray(unwrapped)) return unwrapped;
52492
+ const [xVal] = unwrapped;
52493
+ return ok({ lo: Math.round(xVal.lo), hi: Math.round(xVal.hi) });
52402
52494
  }
52403
52495
  function min2(a, b) {
52404
- return ok({ lo: Math.min(a.lo, b.lo), hi: Math.min(a.hi, b.hi) });
52496
+ const unwrapped = unwrapOrPropagate(a, b);
52497
+ if (!Array.isArray(unwrapped)) return unwrapped;
52498
+ const [aVal, bVal] = unwrapped;
52499
+ return ok({
52500
+ lo: Math.min(aVal.lo, bVal.lo),
52501
+ hi: Math.min(aVal.hi, bVal.hi)
52502
+ });
52405
52503
  }
52406
52504
  function max2(a, b) {
52407
- return ok({ lo: Math.max(a.lo, b.lo), hi: Math.max(a.hi, b.hi) });
52505
+ const unwrapped = unwrapOrPropagate(a, b);
52506
+ if (!Array.isArray(unwrapped)) return unwrapped;
52507
+ const [aVal, bVal] = unwrapped;
52508
+ return ok({
52509
+ lo: Math.max(aVal.lo, bVal.lo),
52510
+ hi: Math.max(aVal.hi, bVal.hi)
52511
+ });
52408
52512
  }
52409
52513
  function mod2(a, b) {
52410
- if (containsZero(b)) {
52514
+ const unwrapped = unwrapOrPropagate(a, b);
52515
+ if (!Array.isArray(unwrapped)) return unwrapped;
52516
+ const [aVal, bVal] = unwrapped;
52517
+ if (containsZero(bVal)) {
52411
52518
  return { kind: "singular" };
52412
52519
  }
52413
- const bAbs = Math.max(Math.abs(b.lo), Math.abs(b.hi));
52414
- const aWidth = a.hi - a.lo;
52520
+ const bAbs = Math.max(Math.abs(bVal.lo), Math.abs(bVal.hi));
52521
+ const aWidth = aVal.hi - aVal.lo;
52415
52522
  if (aWidth >= bAbs) {
52416
52523
  return ok({ lo: 0, hi: bAbs });
52417
52524
  }
52418
- const modLo = (a.lo % bAbs + bAbs) % bAbs;
52419
- const modHi = (a.hi % bAbs + bAbs) % bAbs;
52525
+ const modLo = (aVal.lo % bAbs + bAbs) % bAbs;
52526
+ const modHi = (aVal.hi % bAbs + bAbs) % bAbs;
52420
52527
  if (modLo <= modHi) {
52421
52528
  return ok({ lo: modLo, hi: modHi });
52422
52529
  } else {
@@ -52424,11 +52531,14 @@ Error in definition of "${name}"`,
52424
52531
  }
52425
52532
  }
52426
52533
  function sign2(x) {
52427
- if (x.lo > 0) return ok({ lo: 1, hi: 1 });
52428
- if (x.hi < 0) return ok({ lo: -1, hi: -1 });
52429
- if (x.lo === 0 && x.hi === 0) return ok({ lo: 0, hi: 0 });
52430
- if (x.lo < 0 && x.hi > 0) return ok({ lo: -1, hi: 1 });
52431
- if (x.lo === 0) return ok({ lo: 0, hi: 1 });
52534
+ const unwrapped = unwrapOrPropagate(x);
52535
+ if (!Array.isArray(unwrapped)) return unwrapped;
52536
+ const [xVal] = unwrapped;
52537
+ if (xVal.lo > 0) return ok({ lo: 1, hi: 1 });
52538
+ if (xVal.hi < 0) return ok({ lo: -1, hi: -1 });
52539
+ if (xVal.lo === 0 && xVal.hi === 0) return ok({ lo: 0, hi: 0 });
52540
+ if (xVal.lo < 0 && xVal.hi > 0) return ok({ lo: -1, hi: 1 });
52541
+ if (xVal.lo === 0) return ok({ lo: 0, hi: 1 });
52432
52542
  return ok({ lo: -1, hi: 0 });
52433
52543
  }
52434
52544
 
@@ -52438,231 +52548,298 @@ Error in definition of "${name}"`,
52438
52548
  var HALF_PI = Math.PI / 2;
52439
52549
  var THREE_HALF_PI = 3 * Math.PI / 2;
52440
52550
  function sin2(x) {
52441
- if (x.hi - x.lo >= TWO_PI) {
52551
+ const unwrapped = unwrapOrPropagate(x);
52552
+ if (!Array.isArray(unwrapped)) return unwrapped;
52553
+ const [xVal] = unwrapped;
52554
+ if (xVal.hi - xVal.lo >= TWO_PI) {
52442
52555
  return ok({ lo: -1, hi: 1 });
52443
52556
  }
52444
- const sinLo = Math.sin(x.lo);
52445
- const sinHi = Math.sin(x.hi);
52557
+ const sinLo = Math.sin(xVal.lo);
52558
+ const sinHi = Math.sin(xVal.hi);
52446
52559
  let lo = Math.min(sinLo, sinHi);
52447
52560
  let hi = Math.max(sinLo, sinHi);
52448
- if (containsExtremum(x, HALF_PI, TWO_PI)) {
52561
+ if (containsExtremum(xVal, HALF_PI, TWO_PI)) {
52449
52562
  hi = 1;
52450
52563
  }
52451
- if (containsExtremum(x, THREE_HALF_PI, TWO_PI)) {
52564
+ if (containsExtremum(xVal, THREE_HALF_PI, TWO_PI)) {
52452
52565
  lo = -1;
52453
52566
  }
52454
52567
  return ok({ lo, hi });
52455
52568
  }
52456
52569
  function cos2(x) {
52457
- if (x.hi - x.lo >= TWO_PI) {
52570
+ const unwrapped = unwrapOrPropagate(x);
52571
+ if (!Array.isArray(unwrapped)) return unwrapped;
52572
+ const [xVal] = unwrapped;
52573
+ if (xVal.hi - xVal.lo >= TWO_PI) {
52458
52574
  return ok({ lo: -1, hi: 1 });
52459
52575
  }
52460
- const cosLo = Math.cos(x.lo);
52461
- const cosHi = Math.cos(x.hi);
52576
+ const cosLo = Math.cos(xVal.lo);
52577
+ const cosHi = Math.cos(xVal.hi);
52462
52578
  let lo = Math.min(cosLo, cosHi);
52463
52579
  let hi = Math.max(cosLo, cosHi);
52464
- if (containsExtremum(x, 0, TWO_PI)) {
52580
+ if (containsExtremum(xVal, 0, TWO_PI)) {
52465
52581
  hi = 1;
52466
52582
  }
52467
- if (containsExtremum(x, PI2, TWO_PI)) {
52583
+ if (containsExtremum(xVal, PI2, TWO_PI)) {
52468
52584
  lo = -1;
52469
52585
  }
52470
52586
  return ok({ lo, hi });
52471
52587
  }
52472
52588
  function tan2(x) {
52473
- if (x.hi - x.lo >= PI2) {
52589
+ const unwrapped = unwrapOrPropagate(x);
52590
+ if (!Array.isArray(unwrapped)) return unwrapped;
52591
+ const [xVal] = unwrapped;
52592
+ if (xVal.hi - xVal.lo >= PI2) {
52474
52593
  return { kind: "singular" };
52475
52594
  }
52476
- if (containsExtremum(x, HALF_PI, PI2)) {
52477
- const n = Math.ceil((x.lo - HALF_PI) / PI2);
52595
+ if (containsExtremum(xVal, HALF_PI, PI2)) {
52596
+ const n = Math.ceil((xVal.lo - HALF_PI) / PI2);
52478
52597
  const poleAt = HALF_PI + n * PI2;
52479
52598
  return { kind: "singular", at: poleAt };
52480
52599
  }
52481
- const tanLo = Math.tan(x.lo);
52482
- const tanHi = Math.tan(x.hi);
52600
+ const tanLo = Math.tan(xVal.lo);
52601
+ const tanHi = Math.tan(xVal.hi);
52483
52602
  if (tanLo > 1e10 && tanHi < -1e10 || tanLo < -1e10 && tanHi > 1e10) {
52484
52603
  return { kind: "singular" };
52485
52604
  }
52486
52605
  return ok({ lo: tanLo, hi: tanHi });
52487
52606
  }
52488
52607
  function cot(x) {
52489
- if (x.hi - x.lo >= PI2) {
52608
+ const unwrapped = unwrapOrPropagate(x);
52609
+ if (!Array.isArray(unwrapped)) return unwrapped;
52610
+ const [xVal] = unwrapped;
52611
+ if (xVal.hi - xVal.lo >= PI2) {
52490
52612
  return { kind: "singular" };
52491
52613
  }
52492
- if (containsExtremum(x, 0, PI2)) {
52493
- const n = Math.ceil(x.lo / PI2);
52614
+ if (containsExtremum(xVal, 0, PI2)) {
52615
+ const n = Math.ceil(xVal.lo / PI2);
52494
52616
  const poleAt = n * PI2;
52495
52617
  return { kind: "singular", at: poleAt };
52496
52618
  }
52497
- const cotLo = 1 / Math.tan(x.lo);
52498
- const cotHi = 1 / Math.tan(x.hi);
52619
+ const cotLo = 1 / Math.tan(xVal.lo);
52620
+ const cotHi = 1 / Math.tan(xVal.hi);
52499
52621
  return ok({ lo: Math.min(cotLo, cotHi), hi: Math.max(cotLo, cotHi) });
52500
52622
  }
52501
52623
  function sec(x) {
52502
- if (x.hi - x.lo >= PI2) {
52624
+ const unwrapped = unwrapOrPropagate(x);
52625
+ if (!Array.isArray(unwrapped)) return unwrapped;
52626
+ const [xVal] = unwrapped;
52627
+ if (xVal.hi - xVal.lo >= PI2) {
52503
52628
  return { kind: "singular" };
52504
52629
  }
52505
- if (containsExtremum(x, HALF_PI, PI2)) {
52506
- const n = Math.ceil((x.lo - HALF_PI) / PI2);
52630
+ if (containsExtremum(xVal, HALF_PI, PI2)) {
52631
+ const n = Math.ceil((xVal.lo - HALF_PI) / PI2);
52507
52632
  const poleAt = HALF_PI + n * PI2;
52508
52633
  return { kind: "singular", at: poleAt };
52509
52634
  }
52510
- const secLo = 1 / Math.cos(x.lo);
52511
- const secHi = 1 / Math.cos(x.hi);
52635
+ const secLo = 1 / Math.cos(xVal.lo);
52636
+ const secHi = 1 / Math.cos(xVal.hi);
52512
52637
  let lo = Math.min(secLo, secHi);
52513
52638
  let hi = Math.max(secLo, secHi);
52514
- if (containsExtremum(x, 0, TWO_PI)) {
52639
+ if (containsExtremum(xVal, 0, TWO_PI)) {
52515
52640
  lo = Math.min(lo, 1);
52516
52641
  hi = Math.max(hi, 1);
52517
52642
  }
52518
- if (containsExtremum(x, PI2, TWO_PI)) {
52643
+ if (containsExtremum(xVal, PI2, TWO_PI)) {
52519
52644
  lo = Math.min(lo, -1);
52520
52645
  hi = Math.max(hi, -1);
52521
52646
  }
52522
52647
  return ok({ lo, hi });
52523
52648
  }
52524
52649
  function csc(x) {
52525
- if (x.hi - x.lo >= PI2) {
52650
+ const unwrapped = unwrapOrPropagate(x);
52651
+ if (!Array.isArray(unwrapped)) return unwrapped;
52652
+ const [xVal] = unwrapped;
52653
+ if (xVal.hi - xVal.lo >= PI2) {
52526
52654
  return { kind: "singular" };
52527
52655
  }
52528
- if (containsExtremum(x, 0, PI2)) {
52529
- const n = Math.ceil(x.lo / PI2);
52656
+ if (containsExtremum(xVal, 0, PI2)) {
52657
+ const n = Math.ceil(xVal.lo / PI2);
52530
52658
  const poleAt = n * PI2;
52531
52659
  return { kind: "singular", at: poleAt };
52532
52660
  }
52533
- const cscLo = 1 / Math.sin(x.lo);
52534
- const cscHi = 1 / Math.sin(x.hi);
52661
+ const cscLo = 1 / Math.sin(xVal.lo);
52662
+ const cscHi = 1 / Math.sin(xVal.hi);
52535
52663
  let lo = Math.min(cscLo, cscHi);
52536
52664
  let hi = Math.max(cscLo, cscHi);
52537
- if (containsExtremum(x, HALF_PI, TWO_PI)) {
52665
+ if (containsExtremum(xVal, HALF_PI, TWO_PI)) {
52538
52666
  lo = Math.min(lo, 1);
52539
52667
  hi = Math.max(hi, 1);
52540
52668
  }
52541
- if (containsExtremum(x, THREE_HALF_PI, TWO_PI)) {
52669
+ if (containsExtremum(xVal, THREE_HALF_PI, TWO_PI)) {
52542
52670
  lo = Math.min(lo, -1);
52543
52671
  hi = Math.max(hi, -1);
52544
52672
  }
52545
52673
  return ok({ lo, hi });
52546
52674
  }
52547
52675
  function asin2(x) {
52548
- if (x.lo > 1 || x.hi < -1) {
52676
+ const unwrapped = unwrapOrPropagate(x);
52677
+ if (!Array.isArray(unwrapped)) return unwrapped;
52678
+ const [xVal] = unwrapped;
52679
+ if (xVal.lo > 1 || xVal.hi < -1) {
52549
52680
  return { kind: "empty" };
52550
52681
  }
52551
- if (x.lo < -1 || x.hi > 1) {
52552
- const clippedLo = Math.max(x.lo, -1);
52553
- const clippedHi = Math.min(x.hi, 1);
52682
+ if (xVal.lo < -1 || xVal.hi > 1) {
52683
+ const clippedLo = Math.max(xVal.lo, -1);
52684
+ const clippedHi = Math.min(xVal.hi, 1);
52554
52685
  return {
52555
52686
  kind: "partial",
52556
52687
  value: { lo: Math.asin(clippedLo), hi: Math.asin(clippedHi) },
52557
- domainClipped: x.lo < -1 && x.hi > 1 ? "both" : x.lo < -1 ? "lo" : "hi"
52688
+ domainClipped: xVal.lo < -1 && xVal.hi > 1 ? "both" : xVal.lo < -1 ? "lo" : "hi"
52558
52689
  };
52559
52690
  }
52560
- return ok({ lo: Math.asin(x.lo), hi: Math.asin(x.hi) });
52691
+ return ok({ lo: Math.asin(xVal.lo), hi: Math.asin(xVal.hi) });
52561
52692
  }
52562
52693
  function acos2(x) {
52563
- if (x.lo > 1 || x.hi < -1) {
52694
+ const unwrapped = unwrapOrPropagate(x);
52695
+ if (!Array.isArray(unwrapped)) return unwrapped;
52696
+ const [xVal] = unwrapped;
52697
+ if (xVal.lo > 1 || xVal.hi < -1) {
52564
52698
  return { kind: "empty" };
52565
52699
  }
52566
- if (x.lo < -1 || x.hi > 1) {
52567
- const clippedLo = Math.max(x.lo, -1);
52568
- const clippedHi = Math.min(x.hi, 1);
52700
+ if (xVal.lo < -1 || xVal.hi > 1) {
52701
+ const clippedLo = Math.max(xVal.lo, -1);
52702
+ const clippedHi = Math.min(xVal.hi, 1);
52569
52703
  return {
52570
52704
  kind: "partial",
52571
52705
  value: { lo: Math.acos(clippedHi), hi: Math.acos(clippedLo) },
52572
- domainClipped: x.lo < -1 && x.hi > 1 ? "both" : x.lo < -1 ? "lo" : "hi"
52706
+ domainClipped: xVal.lo < -1 && xVal.hi > 1 ? "both" : xVal.lo < -1 ? "lo" : "hi"
52573
52707
  };
52574
52708
  }
52575
- return ok({ lo: Math.acos(x.hi), hi: Math.acos(x.lo) });
52709
+ return ok({ lo: Math.acos(xVal.hi), hi: Math.acos(xVal.lo) });
52576
52710
  }
52577
52711
  function atan3(x) {
52578
- return ok({ lo: Math.atan(x.lo), hi: Math.atan(x.hi) });
52712
+ const unwrapped = unwrapOrPropagate(x);
52713
+ if (!Array.isArray(unwrapped)) return unwrapped;
52714
+ const [xVal] = unwrapped;
52715
+ return ok({ lo: Math.atan(xVal.lo), hi: Math.atan(xVal.hi) });
52579
52716
  }
52580
52717
  function atan22(y, x) {
52581
- if (y.lo === y.hi && x.lo === x.hi) {
52582
- const result = Math.atan2(y.lo, x.lo);
52718
+ const unwrapped = unwrapOrPropagate(y, x);
52719
+ if (!Array.isArray(unwrapped)) return unwrapped;
52720
+ const [yVal, xVal] = unwrapped;
52721
+ if (yVal.lo === yVal.hi && xVal.lo === xVal.hi) {
52722
+ const result = Math.atan2(yVal.lo, xVal.lo);
52583
52723
  return ok({ lo: result, hi: result });
52584
52724
  }
52585
52725
  const angles = [];
52586
- angles.push(Math.atan2(y.lo, x.lo));
52587
- angles.push(Math.atan2(y.lo, x.hi));
52588
- angles.push(Math.atan2(y.hi, x.lo));
52589
- angles.push(Math.atan2(y.hi, x.hi));
52590
- if (x.lo < 0 && y.lo < 0 && y.hi > 0) {
52726
+ angles.push(Math.atan2(yVal.lo, xVal.lo));
52727
+ angles.push(Math.atan2(yVal.lo, xVal.hi));
52728
+ angles.push(Math.atan2(yVal.hi, xVal.lo));
52729
+ angles.push(Math.atan2(yVal.hi, xVal.hi));
52730
+ if (xVal.lo < 0 && yVal.lo < 0 && yVal.hi > 0) {
52591
52731
  return ok({ lo: -PI2, hi: PI2 });
52592
52732
  }
52593
52733
  return ok({ lo: Math.min(...angles), hi: Math.max(...angles) });
52594
52734
  }
52595
52735
  function sinh3(x) {
52596
- return ok({ lo: Math.sinh(x.lo), hi: Math.sinh(x.hi) });
52736
+ const unwrapped = unwrapOrPropagate(x);
52737
+ if (!Array.isArray(unwrapped)) return unwrapped;
52738
+ const [xVal] = unwrapped;
52739
+ return ok({ lo: Math.sinh(xVal.lo), hi: Math.sinh(xVal.hi) });
52597
52740
  }
52598
52741
  function cosh3(x) {
52599
- if (x.lo >= 0) {
52600
- return ok({ lo: Math.cosh(x.lo), hi: Math.cosh(x.hi) });
52601
- } else if (x.hi <= 0) {
52602
- return ok({ lo: Math.cosh(x.hi), hi: Math.cosh(x.lo) });
52742
+ const unwrapped = unwrapOrPropagate(x);
52743
+ if (!Array.isArray(unwrapped)) return unwrapped;
52744
+ const [xVal] = unwrapped;
52745
+ if (xVal.lo >= 0) {
52746
+ return ok({ lo: Math.cosh(xVal.lo), hi: Math.cosh(xVal.hi) });
52747
+ } else if (xVal.hi <= 0) {
52748
+ return ok({ lo: Math.cosh(xVal.hi), hi: Math.cosh(xVal.lo) });
52603
52749
  } else {
52604
- return ok({ lo: 1, hi: Math.max(Math.cosh(x.lo), Math.cosh(x.hi)) });
52750
+ return ok({
52751
+ lo: 1,
52752
+ hi: Math.max(Math.cosh(xVal.lo), Math.cosh(xVal.hi))
52753
+ });
52605
52754
  }
52606
52755
  }
52607
52756
  function tanh2(x) {
52608
- return ok({ lo: Math.tanh(x.lo), hi: Math.tanh(x.hi) });
52757
+ const unwrapped = unwrapOrPropagate(x);
52758
+ if (!Array.isArray(unwrapped)) return unwrapped;
52759
+ const [xVal] = unwrapped;
52760
+ return ok({ lo: Math.tanh(xVal.lo), hi: Math.tanh(xVal.hi) });
52609
52761
  }
52610
52762
  function asinh2(x) {
52611
- return ok({ lo: Math.asinh(x.lo), hi: Math.asinh(x.hi) });
52763
+ const unwrapped = unwrapOrPropagate(x);
52764
+ if (!Array.isArray(unwrapped)) return unwrapped;
52765
+ const [xVal] = unwrapped;
52766
+ return ok({ lo: Math.asinh(xVal.lo), hi: Math.asinh(xVal.hi) });
52612
52767
  }
52613
52768
  function acosh2(x) {
52614
- if (x.hi < 1) {
52769
+ const unwrapped = unwrapOrPropagate(x);
52770
+ if (!Array.isArray(unwrapped)) return unwrapped;
52771
+ const [xVal] = unwrapped;
52772
+ if (xVal.hi < 1) {
52615
52773
  return { kind: "empty" };
52616
52774
  }
52617
- if (x.lo < 1) {
52775
+ if (xVal.lo < 1) {
52618
52776
  return {
52619
52777
  kind: "partial",
52620
- value: { lo: 0, hi: Math.acosh(x.hi) },
52778
+ value: { lo: 0, hi: Math.acosh(xVal.hi) },
52621
52779
  domainClipped: "lo"
52622
52780
  };
52623
52781
  }
52624
- return ok({ lo: Math.acosh(x.lo), hi: Math.acosh(x.hi) });
52782
+ return ok({ lo: Math.acosh(xVal.lo), hi: Math.acosh(xVal.hi) });
52625
52783
  }
52626
52784
  function atanh2(x) {
52627
- if (x.lo >= 1 || x.hi <= -1) {
52785
+ const unwrapped = unwrapOrPropagate(x);
52786
+ if (!Array.isArray(unwrapped)) return unwrapped;
52787
+ const [xVal] = unwrapped;
52788
+ if (xVal.lo >= 1 || xVal.hi <= -1) {
52628
52789
  return { kind: "empty" };
52629
52790
  }
52630
- if (x.lo <= -1 || x.hi >= 1) {
52631
- const clippedLo = Math.max(x.lo, -1 + Number.EPSILON);
52632
- const clippedHi = Math.min(x.hi, 1 - Number.EPSILON);
52791
+ if (xVal.lo <= -1 || xVal.hi >= 1) {
52792
+ const clippedLo = Math.max(xVal.lo, -1 + Number.EPSILON);
52793
+ const clippedHi = Math.min(xVal.hi, 1 - Number.EPSILON);
52633
52794
  return {
52634
52795
  kind: "partial",
52635
52796
  value: { lo: Math.atanh(clippedLo), hi: Math.atanh(clippedHi) },
52636
- domainClipped: x.lo <= -1 && x.hi >= 1 ? "both" : x.lo <= -1 ? "lo" : "hi"
52797
+ domainClipped: xVal.lo <= -1 && xVal.hi >= 1 ? "both" : xVal.lo <= -1 ? "lo" : "hi"
52637
52798
  };
52638
52799
  }
52639
- return ok({ lo: Math.atanh(x.lo), hi: Math.atanh(x.hi) });
52800
+ return ok({ lo: Math.atanh(xVal.lo), hi: Math.atanh(xVal.hi) });
52640
52801
  }
52641
52802
 
52642
52803
  // src/compute-engine/interval/comparison.ts
52643
52804
  function less(a, b) {
52644
- if (a.hi < b.lo) return "true";
52645
- if (a.lo >= b.hi) return "false";
52805
+ const unwrapped = unwrapOrPropagate(a, b);
52806
+ if (!Array.isArray(unwrapped)) return "maybe";
52807
+ const [aVal, bVal] = unwrapped;
52808
+ if (aVal.hi < bVal.lo) return "true";
52809
+ if (aVal.lo >= bVal.hi) return "false";
52646
52810
  return "maybe";
52647
52811
  }
52648
52812
  function lessEqual(a, b) {
52649
- if (a.hi <= b.lo) return "true";
52650
- if (a.lo > b.hi) return "false";
52813
+ const unwrapped = unwrapOrPropagate(a, b);
52814
+ if (!Array.isArray(unwrapped)) return "maybe";
52815
+ const [aVal, bVal] = unwrapped;
52816
+ if (aVal.hi <= bVal.lo) return "true";
52817
+ if (aVal.lo > bVal.hi) return "false";
52651
52818
  return "maybe";
52652
52819
  }
52653
52820
  function greater(a, b) {
52654
- if (a.lo > b.hi) return "true";
52655
- if (a.hi <= b.lo) return "false";
52821
+ const unwrapped = unwrapOrPropagate(a, b);
52822
+ if (!Array.isArray(unwrapped)) return "maybe";
52823
+ const [aVal, bVal] = unwrapped;
52824
+ if (aVal.lo > bVal.hi) return "true";
52825
+ if (aVal.hi <= bVal.lo) return "false";
52656
52826
  return "maybe";
52657
52827
  }
52658
52828
  function greaterEqual(a, b) {
52659
- if (a.lo >= b.hi) return "true";
52660
- if (a.hi < b.lo) return "false";
52829
+ const unwrapped = unwrapOrPropagate(a, b);
52830
+ if (!Array.isArray(unwrapped)) return "maybe";
52831
+ const [aVal, bVal] = unwrapped;
52832
+ if (aVal.lo >= bVal.hi) return "true";
52833
+ if (aVal.hi < bVal.lo) return "false";
52661
52834
  return "maybe";
52662
52835
  }
52663
52836
  function equal(a, b) {
52664
- if (a.lo === a.hi && b.lo === b.hi && a.lo === b.lo) return "true";
52665
- if (a.hi < b.lo || b.hi < a.lo) return "false";
52837
+ const unwrapped = unwrapOrPropagate(a, b);
52838
+ if (!Array.isArray(unwrapped)) return "maybe";
52839
+ const [aVal, bVal] = unwrapped;
52840
+ if (aVal.lo === aVal.hi && bVal.lo === bVal.hi && aVal.lo === bVal.lo)
52841
+ return "true";
52842
+ if (aVal.hi < bVal.lo || bVal.hi < aVal.lo) return "false";
52666
52843
  return "maybe";
52667
52844
  }
52668
52845
  function notEqual(a, b) {
@@ -52686,22 +52863,45 @@ Error in definition of "${name}"`,
52686
52863
  if (a === "false") return "true";
52687
52864
  return "maybe";
52688
52865
  }
52689
- function piecewise(x, condition, trueBranch, falseBranch) {
52690
- const cond = condition(x);
52866
+ function piecewise(xOrCond, conditionOrTrue, trueOrFalse, falseBranch) {
52867
+ if (xOrCond === "true" || xOrCond === "false" || xOrCond === "maybe") {
52868
+ const cond2 = xOrCond;
52869
+ const trueBranch2 = conditionOrTrue;
52870
+ const falseBranchFn2 = trueOrFalse;
52871
+ switch (cond2) {
52872
+ case "true":
52873
+ return trueBranch2();
52874
+ case "false":
52875
+ return falseBranchFn2();
52876
+ case "maybe":
52877
+ return unionResults(trueBranch2(), falseBranchFn2());
52878
+ }
52879
+ }
52880
+ const x = xOrCond;
52881
+ const condition = conditionOrTrue;
52882
+ const trueBranch = trueOrFalse;
52883
+ const falseBranchFn = falseBranch;
52884
+ const unwrapped = unwrapOrPropagate(x);
52885
+ if (!Array.isArray(unwrapped)) return unwrapped;
52886
+ const [xVal] = unwrapped;
52887
+ const cond = condition(xVal);
52691
52888
  switch (cond) {
52692
52889
  case "true":
52693
- return trueBranch(x);
52890
+ return trueBranch(xVal);
52694
52891
  case "false":
52695
- return falseBranch(x);
52892
+ return falseBranchFn(xVal);
52696
52893
  case "maybe":
52697
- const t = trueBranch(x);
52698
- const f = falseBranch(x);
52894
+ const t = trueBranch(xVal);
52895
+ const f = falseBranchFn(xVal);
52699
52896
  return unionResults(t, f);
52700
52897
  }
52701
52898
  }
52702
52899
  function clamp2(x, lo, hi) {
52703
- const resultLo = Math.max(x.lo, lo.lo);
52704
- const resultHi = Math.min(x.hi, hi.hi);
52900
+ const unwrapped = unwrapOrPropagate(x, lo, hi);
52901
+ if (!Array.isArray(unwrapped)) return unwrapped;
52902
+ const [xVal, loVal, hiVal] = unwrapped;
52903
+ const resultLo = Math.max(xVal.lo, loVal.lo);
52904
+ const resultHi = Math.min(xVal.hi, hiVal.hi);
52705
52905
  if (resultLo > resultHi) {
52706
52906
  return { kind: "empty" };
52707
52907
  }
@@ -52929,11 +53129,20 @@ Error in definition of "${name}"`,
52929
53129
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
52930
53130
  return `_IA.piecewise(
52931
53131
  ${compile(args[0])},
52932
- (_x) => ${compile(args[0])},
52933
- (_x) => ${compile(args[1])},
52934
- (_x) => ${compile(args[2])}
53132
+ () => ${compile(args[1])},
53133
+ () => ${compile(args[2])}
52935
53134
  )`;
52936
- }
53135
+ },
53136
+ // Comparisons
53137
+ Equal: (args, compile) => `_IA.equal(${compile(args[0])}, ${compile(args[1])})`,
53138
+ NotEqual: (args, compile) => `_IA.notEqual(${compile(args[0])}, ${compile(args[1])})`,
53139
+ LessEqual: (args, compile) => `_IA.lessEqual(${compile(args[0])}, ${compile(args[1])})`,
53140
+ GreaterEqual: (args, compile) => `_IA.greaterEqual(${compile(args[0])}, ${compile(args[1])})`,
53141
+ Less: (args, compile) => `_IA.less(${compile(args[0])}, ${compile(args[1])})`,
53142
+ Greater: (args, compile) => `_IA.greater(${compile(args[0])}, ${compile(args[1])})`,
53143
+ And: (args, compile) => `_IA.and(${compile(args[0])}, ${compile(args[1])})`,
53144
+ Or: (args, compile) => `_IA.or(${compile(args[0])}, ${compile(args[1])})`,
53145
+ Not: (args, compile) => `_IA.not(${compile(args[0])})`
52937
53146
  };
52938
53147
  var ComputeEngineIntervalFunction = class extends Function {
52939
53148
  IA = IntervalArithmetic;
@@ -53111,6 +53320,10 @@ IntervalResult ia_partial(vec2 v, float clip) {
53111
53320
  return IntervalResult(v, clip);
53112
53321
  }
53113
53322
 
53323
+ bool ia_is_error(float status) {
53324
+ return status == IA_EMPTY || status == IA_ENTIRE || status == IA_SINGULAR;
53325
+ }
53326
+
53114
53327
  // Addition
53115
53328
  IntervalResult ia_add(vec2 a, vec2 b) {
53116
53329
  return ia_ok(vec2(a.x + b.x - IA_EPS, a.y + b.y + IA_EPS));
@@ -53426,6 +53639,198 @@ IntervalResult ia_cosh(vec2 x) {
53426
53639
  IntervalResult ia_tanh(vec2 x) {
53427
53640
  return ia_ok(vec2(tanh(x.x) - IA_EPS, tanh(x.y) + IA_EPS));
53428
53641
  }
53642
+
53643
+ // IntervalResult overloads for propagation
53644
+ IntervalResult ia_add(IntervalResult a, IntervalResult b) {
53645
+ if (ia_is_error(a.status)) return a;
53646
+ if (ia_is_error(b.status)) return b;
53647
+ return ia_add(a.value, b.value);
53648
+ }
53649
+
53650
+ IntervalResult ia_add(IntervalResult a, vec2 b) {
53651
+ if (ia_is_error(a.status)) return a;
53652
+ return ia_add(a.value, b);
53653
+ }
53654
+
53655
+ IntervalResult ia_add(vec2 a, IntervalResult b) {
53656
+ if (ia_is_error(b.status)) return b;
53657
+ return ia_add(a, b.value);
53658
+ }
53659
+
53660
+ IntervalResult ia_sub(IntervalResult a, IntervalResult b) {
53661
+ if (ia_is_error(a.status)) return a;
53662
+ if (ia_is_error(b.status)) return b;
53663
+ return ia_sub(a.value, b.value);
53664
+ }
53665
+
53666
+ IntervalResult ia_sub(IntervalResult a, vec2 b) {
53667
+ if (ia_is_error(a.status)) return a;
53668
+ return ia_sub(a.value, b);
53669
+ }
53670
+
53671
+ IntervalResult ia_sub(vec2 a, IntervalResult b) {
53672
+ if (ia_is_error(b.status)) return b;
53673
+ return ia_sub(a, b.value);
53674
+ }
53675
+
53676
+ IntervalResult ia_mul(IntervalResult a, IntervalResult b) {
53677
+ if (ia_is_error(a.status)) return a;
53678
+ if (ia_is_error(b.status)) return b;
53679
+ return ia_mul(a.value, b.value);
53680
+ }
53681
+
53682
+ IntervalResult ia_mul(IntervalResult a, vec2 b) {
53683
+ if (ia_is_error(a.status)) return a;
53684
+ return ia_mul(a.value, b);
53685
+ }
53686
+
53687
+ IntervalResult ia_mul(vec2 a, IntervalResult b) {
53688
+ if (ia_is_error(b.status)) return b;
53689
+ return ia_mul(a, b.value);
53690
+ }
53691
+
53692
+ IntervalResult ia_div(IntervalResult a, IntervalResult b) {
53693
+ if (ia_is_error(a.status)) return a;
53694
+ if (ia_is_error(b.status)) return b;
53695
+ return ia_div(a.value, b.value);
53696
+ }
53697
+
53698
+ IntervalResult ia_div(IntervalResult a, vec2 b) {
53699
+ if (ia_is_error(a.status)) return a;
53700
+ return ia_div(a.value, b);
53701
+ }
53702
+
53703
+ IntervalResult ia_div(vec2 a, IntervalResult b) {
53704
+ if (ia_is_error(b.status)) return b;
53705
+ return ia_div(a, b.value);
53706
+ }
53707
+
53708
+ IntervalResult ia_negate(IntervalResult x) {
53709
+ if (ia_is_error(x.status)) return x;
53710
+ return ia_negate(x.value);
53711
+ }
53712
+
53713
+ IntervalResult ia_sqrt(IntervalResult x) {
53714
+ if (ia_is_error(x.status)) return x;
53715
+ return ia_sqrt(x.value);
53716
+ }
53717
+
53718
+ IntervalResult ia_square(IntervalResult x) {
53719
+ if (ia_is_error(x.status)) return x;
53720
+ return ia_square(x.value);
53721
+ }
53722
+
53723
+ IntervalResult ia_exp(IntervalResult x) {
53724
+ if (ia_is_error(x.status)) return x;
53725
+ return ia_exp(x.value);
53726
+ }
53727
+
53728
+ IntervalResult ia_ln(IntervalResult x) {
53729
+ if (ia_is_error(x.status)) return x;
53730
+ return ia_ln(x.value);
53731
+ }
53732
+
53733
+ IntervalResult ia_abs(IntervalResult x) {
53734
+ if (ia_is_error(x.status)) return x;
53735
+ return ia_abs(x.value);
53736
+ }
53737
+
53738
+ IntervalResult ia_sign(IntervalResult x) {
53739
+ if (ia_is_error(x.status)) return x;
53740
+ return ia_sign(x.value);
53741
+ }
53742
+
53743
+ IntervalResult ia_floor(IntervalResult x) {
53744
+ if (ia_is_error(x.status)) return x;
53745
+ return ia_floor(x.value);
53746
+ }
53747
+
53748
+ IntervalResult ia_ceil(IntervalResult x) {
53749
+ if (ia_is_error(x.status)) return x;
53750
+ return ia_ceil(x.value);
53751
+ }
53752
+
53753
+ IntervalResult ia_min(IntervalResult a, IntervalResult b) {
53754
+ if (ia_is_error(a.status)) return a;
53755
+ if (ia_is_error(b.status)) return b;
53756
+ return ia_min(a.value, b.value);
53757
+ }
53758
+
53759
+ IntervalResult ia_min(IntervalResult a, vec2 b) {
53760
+ if (ia_is_error(a.status)) return a;
53761
+ return ia_min(a.value, b);
53762
+ }
53763
+
53764
+ IntervalResult ia_min(vec2 a, IntervalResult b) {
53765
+ if (ia_is_error(b.status)) return b;
53766
+ return ia_min(a, b.value);
53767
+ }
53768
+
53769
+ IntervalResult ia_max(IntervalResult a, IntervalResult b) {
53770
+ if (ia_is_error(a.status)) return a;
53771
+ if (ia_is_error(b.status)) return b;
53772
+ return ia_max(a.value, b.value);
53773
+ }
53774
+
53775
+ IntervalResult ia_max(IntervalResult a, vec2 b) {
53776
+ if (ia_is_error(a.status)) return a;
53777
+ return ia_max(a.value, b);
53778
+ }
53779
+
53780
+ IntervalResult ia_max(vec2 a, IntervalResult b) {
53781
+ if (ia_is_error(b.status)) return b;
53782
+ return ia_max(a, b.value);
53783
+ }
53784
+
53785
+ IntervalResult ia_pow(IntervalResult base, float exp) {
53786
+ if (ia_is_error(base.status)) return base;
53787
+ return ia_pow(base.value, exp);
53788
+ }
53789
+
53790
+ IntervalResult ia_sin(IntervalResult x) {
53791
+ if (ia_is_error(x.status)) return x;
53792
+ return ia_sin(x.value);
53793
+ }
53794
+
53795
+ IntervalResult ia_cos(IntervalResult x) {
53796
+ if (ia_is_error(x.status)) return x;
53797
+ return ia_cos(x.value);
53798
+ }
53799
+
53800
+ IntervalResult ia_tan(IntervalResult x) {
53801
+ if (ia_is_error(x.status)) return x;
53802
+ return ia_tan(x.value);
53803
+ }
53804
+
53805
+ IntervalResult ia_asin(IntervalResult x) {
53806
+ if (ia_is_error(x.status)) return x;
53807
+ return ia_asin(x.value);
53808
+ }
53809
+
53810
+ IntervalResult ia_acos(IntervalResult x) {
53811
+ if (ia_is_error(x.status)) return x;
53812
+ return ia_acos(x.value);
53813
+ }
53814
+
53815
+ IntervalResult ia_atan(IntervalResult x) {
53816
+ if (ia_is_error(x.status)) return x;
53817
+ return ia_atan(x.value);
53818
+ }
53819
+
53820
+ IntervalResult ia_sinh(IntervalResult x) {
53821
+ if (ia_is_error(x.status)) return x;
53822
+ return ia_sinh(x.value);
53823
+ }
53824
+
53825
+ IntervalResult ia_cosh(IntervalResult x) {
53826
+ if (ia_is_error(x.status)) return x;
53827
+ return ia_cosh(x.value);
53828
+ }
53829
+
53830
+ IntervalResult ia_tanh(IntervalResult x) {
53831
+ if (ia_is_error(x.status)) return x;
53832
+ return ia_tanh(x.value);
53833
+ }
53429
53834
  `;
53430
53835
  var INTERVAL_GLSL_OPERATORS = {
53431
53836
  Add: ["ia_add", 20],
@@ -54351,12 +54756,11 @@ IntervalResult ${functionName}(${params}) {
54351
54756
  bignum
54352
54757
  );
54353
54758
  if (value instanceof Decimal) {
54354
- if (value.isInteger() && value.e <= MAX_BIGINT_DIGITS)
54355
- return new ExactNumericValue(
54356
- bigint(value.toString()),
54357
- makeNumericValue,
54358
- bignum
54359
- );
54759
+ if (value.isInteger() && value.e <= MAX_BIGINT_DIGITS) {
54760
+ const n = bigint(value.toString());
54761
+ if (n !== null)
54762
+ return new ExactNumericValue(n, makeNumericValue, bignum);
54763
+ }
54360
54764
  return makeNumericValue(value);
54361
54765
  }
54362
54766
  if (value instanceof Complex) {
@@ -55422,10 +55826,10 @@ IntervalResult ${functionName}(${params}) {
55422
55826
  // src/compute-engine.ts
55423
55827
  init_types6();
55424
55828
  init_base_compiler();
55425
- var version = "0.35.0";
55829
+ var version = "0.35.2";
55426
55830
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
55427
55831
  ComputeEngine: ComputeEngine.prototype.constructor,
55428
- version: "0.35.0"
55832
+ version: "0.35.2"
55429
55833
  };
55430
55834
  return __toCommonJS(compute_engine_exports);
55431
55835
  })();