@cortex-js/compute-engine 0.50.1 → 0.50.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 (219) hide show
  1. package/dist/compute-engine.esm.js +276 -191
  2. package/dist/compute-engine.min.esm.js +43 -43
  3. package/dist/compute-engine.min.umd.js +44 -44
  4. package/dist/compute-engine.umd.js +276 -191
  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/constants.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  78. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  79. package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
  80. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  81. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  82. package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -1
  83. package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +1 -1
  84. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  85. package/dist/types/compute-engine/compilation/interval-wgsl-target.d.ts +1 -1
  86. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  87. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  88. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  89. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  90. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  91. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  92. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  93. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  94. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  95. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  96. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  97. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  98. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  99. package/dist/types/compute-engine/engine-latex-dictionary-state.d.ts +1 -1
  100. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  101. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  102. package/dist/types/compute-engine/engine-parse-entrypoint.d.ts +1 -1
  103. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  104. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  105. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  106. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  107. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  108. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  109. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  110. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  111. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  112. package/dist/types/compute-engine/global-types.d.ts +1 -1
  113. package/dist/types/compute-engine/index.d.ts +1 -1
  114. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  115. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  116. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  117. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  118. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  119. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  120. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  121. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  122. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  123. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  124. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  125. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  126. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  127. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  128. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  129. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  130. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  131. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  132. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  133. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  134. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  135. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  136. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  137. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  138. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  139. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  140. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  141. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  142. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  143. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  144. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  145. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  146. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  147. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  148. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  149. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  150. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  151. package/dist/types/compute-engine/library/core.d.ts +1 -1
  152. package/dist/types/compute-engine/library/library.d.ts +1 -1
  153. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  154. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  155. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  156. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  157. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  158. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  159. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  160. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  161. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  162. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  163. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  164. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  165. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  166. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  167. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  168. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  169. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  170. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  171. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  172. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  173. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  174. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  175. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  176. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  177. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  178. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  179. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  180. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  181. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  182. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  183. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  184. package/dist/types/compute-engine/oeis.d.ts +1 -1
  185. package/dist/types/compute-engine/sequence.d.ts +1 -1
  186. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  187. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  188. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  189. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  190. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  191. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  192. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  193. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  194. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  195. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  196. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  197. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  198. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  199. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  200. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  201. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  202. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  203. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  204. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  205. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  206. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  207. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  208. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  209. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  210. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  211. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  212. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  213. package/dist/types/compute-engine/types.d.ts +1 -1
  214. package/dist/types/compute-engine.d.ts +1 -1
  215. package/dist/types/math-json/symbols.d.ts +1 -1
  216. package/dist/types/math-json/types.d.ts +1 -1
  217. package/dist/types/math-json/utils.d.ts +1 -1
  218. package/dist/types/math-json.d.ts +2 -2
  219. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.50.1 */
1
+ /** Compute Engine 0.50.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;
@@ -6619,14 +6619,15 @@ var ComputeEngine = (() => {
6619
6619
  if (result) return result;
6620
6620
  }
6621
6621
  const factors = primeFactors(n);
6622
- let f = 1;
6623
- let r = 1;
6622
+ let f = BigInt(1);
6623
+ let r = BigInt(1);
6624
6624
  for (const k of Object.keys(factors)) {
6625
- const v = parseInt(k);
6626
- f = f * Math.pow(v, Math.floor(factors[k] / exponent));
6627
- r = r * Math.pow(v, factors[k] % exponent);
6625
+ const v = BigInt(parseInt(k));
6626
+ const exponentBase = BigInt(exponent);
6627
+ f = f * v ** (BigInt(factors[k]) / exponentBase);
6628
+ r = r * v ** (BigInt(factors[k]) % exponentBase);
6628
6629
  }
6629
- return [f, r];
6630
+ return [Number(f), Number(r)];
6630
6631
  }
6631
6632
  function gcd(a, b) {
6632
6633
  if (a === 0) return b;
@@ -6637,7 +6638,9 @@ var ComputeEngine = (() => {
6637
6638
  return a < 0 ? -a : a;
6638
6639
  }
6639
6640
  function lcm(a, b) {
6640
- return a * b / gcd(a, b);
6641
+ if (a === 0 || b === 0) return 0;
6642
+ const res = BigInt(a) * BigInt(b) / BigInt(gcd(a, b));
6643
+ return Number(res);
6641
6644
  }
6642
6645
  function factorial2(n) {
6643
6646
  if (!Number.isInteger(n) || n < 0) return NaN;
@@ -11104,11 +11107,25 @@ var ComputeEngine = (() => {
11104
11107
  const bigRhs = [BigInt(rhsNum[0]), BigInt(rhsNum[1])];
11105
11108
  return [bigRhs[1] * lhs[0] + bigRhs[0] * lhs[1], bigRhs[1] * lhs[1]];
11106
11109
  }
11107
- return [rhsNum[1] * lhs[0] + rhsNum[0] * lhs[1], rhsNum[1] * lhs[1]];
11110
+ const n = rhsNum[1] * lhs[0] + rhsNum[0] * lhs[1];
11111
+ const d = rhsNum[1] * lhs[1];
11112
+ if (n <= 9007199254740991 && n >= -9007199254740991 && d <= 9007199254740991)
11113
+ return [n, d];
11114
+ if (!Number.isFinite(n) || !Number.isFinite(d)) return [NaN, 1];
11115
+ return [
11116
+ BigInt(rhsNum[1]) * BigInt(lhs[0]) + BigInt(rhsNum[0]) * BigInt(lhs[1]),
11117
+ BigInt(rhsNum[1]) * BigInt(lhs[1])
11118
+ ];
11108
11119
  }
11109
11120
  function mul2(lhs, rhs) {
11110
- if (isMachineRational(lhs) && isMachineRational(rhs))
11111
- return [lhs[0] * rhs[0], lhs[1] * rhs[1]];
11121
+ if (isMachineRational(lhs) && isMachineRational(rhs)) {
11122
+ const n = lhs[0] * rhs[0];
11123
+ const d = lhs[1] * rhs[1];
11124
+ if (n <= 9007199254740991 && n >= -9007199254740991 && d <= 9007199254740991)
11125
+ return [n, d];
11126
+ if (!Number.isFinite(n) || !Number.isFinite(d)) return [NaN, 1];
11127
+ return [BigInt(lhs[0]) * BigInt(rhs[0]), BigInt(lhs[1]) * BigInt(rhs[1])];
11128
+ }
11112
11129
  if (isMachineRational(lhs))
11113
11130
  return [
11114
11131
  BigInt(lhs[0]) * rhs[0],
@@ -14789,8 +14806,7 @@ ${lines.join("\n")}`;
14789
14806
  }
14790
14807
  if (this.radical >= 4) {
14791
14808
  const [factor3, root2] = canonicalInteger(this.radical, 2);
14792
- if (typeof this.rational[0] === "number") this.rational[0] *= factor3;
14793
- else this.rational = mul2(this.rational, [factor3, 1]);
14809
+ if (factor3 !== 1) this.rational = mul2(this.rational, [factor3, 1]);
14794
14810
  this.radical = root2;
14795
14811
  }
14796
14812
  this.rational = reducedRational(this.rational);
@@ -14841,7 +14857,10 @@ ${lines.join("\n")}`;
14841
14857
  if (this.isOne) return this;
14842
14858
  if (this.isNegativeOne) return this;
14843
14859
  return this.clone({
14844
- rational: isMachineRational(this.rational) ? [this.rational[1], this.rational[0] * this.radical] : [this.rational[1], this.rational[0] * BigInt(this.radical)],
14860
+ rational: mul2(
14861
+ [BigInt(this.rational[1]), BigInt(1)],
14862
+ inverse([BigInt(this.rational[0]) * BigInt(this.radical), BigInt(1)])
14863
+ ),
14845
14864
  radical: this.radical
14846
14865
  });
14847
14866
  }
@@ -14850,10 +14869,7 @@ ${lines.join("\n")}`;
14850
14869
  if (other === 0) return this;
14851
14870
  if (Number.isInteger(other) && this.radical === 1)
14852
14871
  return this.clone({
14853
- rational: isMachineRational(this.rational) ? [this.rational[0] + other * this.rational[1], this.rational[1]] : [
14854
- this.rational[0] + BigInt(other) * this.rational[1],
14855
- this.rational[1]
14856
- ]
14872
+ rational: add2(this.rational, [other, 1])
14857
14873
  });
14858
14874
  return this.factory(this.bignumRe).add(other);
14859
14875
  }
@@ -14882,7 +14898,7 @@ ${lines.join("\n")}`;
14882
14898
  if (typeof other === "number") {
14883
14899
  if (Number.isInteger(other))
14884
14900
  return this.clone({
14885
- rational: isMachineRational(this.rational) ? [this.rational[0] * other, this.rational[1]] : [this.rational[0] * BigInt(other), this.rational[1]],
14901
+ rational: mul2(this.rational, [other, 1]),
14886
14902
  radical: this.radical
14887
14903
  });
14888
14904
  return this.factory(this.bignumRe).mul(other);
@@ -14905,9 +14921,12 @@ ${lines.join("\n")}`;
14905
14921
  if (this.isOne) return other;
14906
14922
  if (this.isNegativeOne) return other.neg();
14907
14923
  if (!(other instanceof _ExactNumericValue)) return other.mul(this);
14924
+ const radical = BigInt(this.radical) * BigInt(other.radical);
14925
+ if (radical > BigInt(SMALL_INTEGER))
14926
+ return this.factory(this.bignumRe).mul(other);
14908
14927
  return this.clone({
14909
14928
  rational: mul2(this.rational, other.rational),
14910
- radical: this.radical * other.radical
14929
+ radical: Number(radical)
14911
14930
  });
14912
14931
  }
14913
14932
  div(other) {
@@ -14916,7 +14935,7 @@ ${lines.join("\n")}`;
14916
14935
  if (other === -1) return this.neg();
14917
14936
  if (other === 0) return this.clone(NaN);
14918
14937
  return this.clone({
14919
- rational: isMachineRational(this.rational) ? [this.rational[0], this.rational[1] * other] : [this.rational[0], this.rational[1] * BigInt(other)],
14938
+ rational: mul2(this.rational, [1, other]),
14920
14939
  radical: this.radical
14921
14940
  });
14922
14941
  }
@@ -14931,18 +14950,14 @@ ${lines.join("\n")}`;
14931
14950
  if (!(other instanceof _ExactNumericValue))
14932
14951
  return this.factory(this.bignumRe).div(other);
14933
14952
  if (other.im !== 0) return this.factory(this.bignumRe).div(other);
14934
- let rational;
14935
- if (isMachineRational(this.rational) && isMachineRational(other.rational)) {
14936
- const [a, b] = this.rational;
14937
- const [d, e] = other.rational;
14938
- rational = [a * e, b * d * other.radical];
14939
- } else {
14940
- rational = mul2(this.rational, [
14941
- BigInt(other.rational[1]),
14942
- BigInt(other.rational[0]) * BigInt(other.radical)
14943
- ]);
14944
- }
14945
- return this.clone({ rational, radical: this.radical * other.radical });
14953
+ const rational = mul2(this.rational, [
14954
+ BigInt(other.rational[1]),
14955
+ BigInt(other.rational[0]) * BigInt(other.radical)
14956
+ ]);
14957
+ const radical = BigInt(this.radical) * BigInt(other.radical);
14958
+ if (radical > BigInt(SMALL_INTEGER))
14959
+ return this.factory(this.bignumRe).div(other);
14960
+ return this.clone({ rational, radical: Number(radical) });
14946
14961
  }
14947
14962
  pow(exponent) {
14948
14963
  console.assert(!Array.isArray(exponent));
@@ -14988,26 +15003,31 @@ ${lines.join("\n")}`;
14988
15003
  if (this.sign < 0) {
14989
15004
  if (Number.isInteger(exponent)) {
14990
15005
  const sign3 = exponent % 2 === 0 ? 1 : -1;
15006
+ const bigExp = BigInt(exponent);
15007
+ const radical = BigInt(this.radical) ** bigExp;
15008
+ if (radical > BigInt(SMALL_INTEGER))
15009
+ return this.factory(this.bignumRe).pow(exponent);
14991
15010
  return this.clone({
14992
- rational: isMachineRational(this.rational) ? [
14993
- sign3 * (-this.rational[0]) ** exponent,
14994
- this.rational[1] ** exponent
14995
- ] : [
14996
- BigInt(sign3) * (-this.rational[0]) ** BigInt(exponent),
14997
- this.rational[1] ** BigInt(exponent)
15011
+ rational: [
15012
+ BigInt(sign3) * (-BigInt(this.rational[0])) ** bigExp,
15013
+ BigInt(this.rational[1]) ** bigExp
14998
15014
  ],
14999
- radical: this.radical ** exponent
15015
+ radical: Number(radical)
15000
15016
  });
15001
15017
  }
15002
15018
  return this.factory({ im: (-this.re) ** exponent });
15003
15019
  } else {
15004
15020
  if (Number.isInteger(exponent)) {
15021
+ const bigExp = BigInt(exponent);
15022
+ const radical = BigInt(this.radical) ** bigExp;
15023
+ if (radical > BigInt(SMALL_INTEGER))
15024
+ return this.factory(this.bignumRe).pow(exponent);
15005
15025
  return this.clone({
15006
- rational: isMachineRational(this.rational) ? [this.rational[0] ** exponent, this.rational[1] ** exponent] : [
15007
- BigInt(this.rational[0]) ** BigInt(exponent),
15008
- this.rational[1] ** BigInt(exponent)
15026
+ rational: [
15027
+ BigInt(this.rational[0]) ** bigExp,
15028
+ BigInt(this.rational[1]) ** bigExp
15009
15029
  ],
15010
- radical: this.radical ** exponent
15030
+ radical: Number(radical)
15011
15031
  });
15012
15032
  }
15013
15033
  }
@@ -21985,11 +22005,15 @@ ${lines.join("\n")}`;
21985
22005
  function canonicalBigop(bigOp2, body, indexingSets, scope) {
21986
22006
  const ce = body.engine;
21987
22007
  ce.pushScope(scope);
21988
- const indexes = indexingSets.map(
21989
- (x) => canonicalIndexingSet(x) ?? ce.error("missing")
21990
- );
21991
- body = body?.canonical ?? ce.error("missing");
21992
- ce.popScope();
22008
+ let indexes;
22009
+ try {
22010
+ indexes = indexingSets.map(
22011
+ (x) => canonicalIndexingSet(x) ?? ce.error("missing")
22012
+ );
22013
+ body = body?.canonical ?? ce.error("missing");
22014
+ } finally {
22015
+ ce.popScope();
22016
+ }
21993
22017
  if (body.isCollection) {
21994
22018
  if (bigOp2 === "Sum") return ce.box(["Reduce", body, "Add", 0]);
21995
22019
  return ce.box(["Reduce", body, "Multiply", 1]);
@@ -22291,7 +22315,11 @@ ${lines.join("\n")}`;
22291
22315
  for (const x of rest) result = canonicalDivide(result, x);
22292
22316
  return result;
22293
22317
  },
22294
- evaluate: ([num, den]) => num.div(den)
22318
+ evaluate: ([num, den], { numericApproximation: numericApproximation2 }) => {
22319
+ const res = num.div(den);
22320
+ if (numericApproximation2 && res.operator !== "Divide") return res.N();
22321
+ return res;
22322
+ }
22295
22323
  },
22296
22324
  Exp: {
22297
22325
  wikidata: "Q168698",
@@ -23474,11 +23502,12 @@ ${lines.join("\n")}`;
23474
23502
  canonical: ([body, ...bounds], { scope }) => canonicalBigop("Product", body, bounds, scope),
23475
23503
  evaluate: (ops, options) => {
23476
23504
  const ce = options.engine;
23505
+ const numericApproximation2 = options.numericApproximation;
23477
23506
  const result = run(
23478
23507
  reduceBigOp(
23479
23508
  ops[0],
23480
23509
  ops.slice(1),
23481
- (acc, x) => acc.mul(x.evaluate(options)),
23510
+ (acc, x) => acc.mul(x.evaluate({ numericApproximation: numericApproximation2 })),
23482
23511
  ce.One
23483
23512
  ),
23484
23513
  ce._timeRemaining
@@ -23486,15 +23515,16 @@ ${lines.join("\n")}`;
23486
23515
  if (result === NON_ENUMERABLE_DOMAIN) {
23487
23516
  return void 0;
23488
23517
  }
23489
- return result?.evaluate() ?? ce.NaN;
23518
+ return result?.evaluate({ numericApproximation: numericApproximation2 }) ?? ce.NaN;
23490
23519
  },
23491
23520
  evaluateAsync: async (ops, options) => {
23492
23521
  const ce = options.engine;
23522
+ const numericApproximation2 = options.numericApproximation;
23493
23523
  const result = await runAsync(
23494
23524
  reduceBigOp(
23495
23525
  ops[0],
23496
23526
  ops.slice(1),
23497
- (acc, x) => acc.mul(x.evaluate(options)),
23527
+ (acc, x) => acc.mul(x.evaluate({ numericApproximation: numericApproximation2 })),
23498
23528
  ce.One
23499
23529
  ),
23500
23530
  ce._timeRemaining,
@@ -23503,7 +23533,7 @@ ${lines.join("\n")}`;
23503
23533
  if (result === NON_ENUMERABLE_DOMAIN) {
23504
23534
  return void 0;
23505
23535
  }
23506
- return result?.evaluate() ?? ce.NaN;
23536
+ return result?.evaluate({ numericApproximation: numericApproximation2 }) ?? ce.NaN;
23507
23537
  }
23508
23538
  },
23509
23539
  Sum: {
@@ -23515,12 +23545,12 @@ ${lines.join("\n")}`;
23515
23545
  lazy: true,
23516
23546
  signature: "((number) -> number, bounds:tuple+) -> number",
23517
23547
  canonical: ([body, ...bounds], { scope }) => canonicalBigop("Sum", body, bounds, scope),
23518
- evaluate: ([body, ...indexes], { engine }) => {
23548
+ evaluate: ([body, ...indexes], { engine, numericApproximation: numericApproximation2 }) => {
23519
23549
  const result = run(
23520
23550
  reduceBigOp(
23521
23551
  body,
23522
23552
  indexes,
23523
- (acc, x) => acc.add(x.evaluate()),
23553
+ (acc, x) => acc.add(x.evaluate({ numericApproximation: numericApproximation2 })),
23524
23554
  engine.Zero
23525
23555
  ),
23526
23556
  engine._timeRemaining
@@ -23528,14 +23558,14 @@ ${lines.join("\n")}`;
23528
23558
  if (result === NON_ENUMERABLE_DOMAIN) {
23529
23559
  return void 0;
23530
23560
  }
23531
- return result?.evaluate() ?? engine.NaN;
23561
+ return result?.evaluate({ numericApproximation: numericApproximation2 }) ?? engine.NaN;
23532
23562
  },
23533
- evaluateAsync: async (xs, { engine, signal }) => {
23563
+ evaluateAsync: async (xs, { engine, signal, numericApproximation: numericApproximation2 }) => {
23534
23564
  const result = await runAsync(
23535
23565
  reduceBigOp(
23536
23566
  xs[0],
23537
23567
  xs.slice(1),
23538
- (acc, x) => acc.add(x.evaluate()),
23568
+ (acc, x) => acc.add(x.evaluate({ numericApproximation: numericApproximation2 })),
23539
23569
  engine.Zero
23540
23570
  ),
23541
23571
  engine._timeRemaining,
@@ -23544,7 +23574,7 @@ ${lines.join("\n")}`;
23544
23574
  if (result === NON_ENUMERABLE_DOMAIN) {
23545
23575
  return void 0;
23546
23576
  }
23547
- return result?.evaluate() ?? engine.NaN;
23577
+ return result?.evaluate({ numericApproximation: numericApproximation2 }) ?? engine.NaN;
23548
23578
  }
23549
23579
  }
23550
23580
  }
@@ -24254,60 +24284,62 @@ ${lines.join("\n")}`;
24254
24284
  if (systemScope) {
24255
24285
  ce.pushScope({ parent: systemScope, bindings: /* @__PURE__ */ new Map() });
24256
24286
  }
24257
- const expr = ce.parse(rule);
24258
- ce.latexDictionary = previousDictionary;
24259
- if (!expr.isValid || expr.operator !== "Rule") {
24260
- if (systemScope) {
24261
- ce.popScope();
24262
- }
24263
- throw new Error(
24264
- `Invalid rule "${rule}"
24287
+ let expr;
24288
+ try {
24289
+ expr = ce.parse(rule);
24290
+ ce.latexDictionary = previousDictionary;
24291
+ if (!expr.isValid || expr.operator !== "Rule") {
24292
+ throw new Error(
24293
+ `Invalid rule "${rule}"
24265
24294
  | ${dewildcard(expr).toString()}
24266
24295
  | A rule should be of the form:
24267
24296
  | <match> -> <replace>; <condition>`
24268
- );
24269
- }
24270
- if (!isFunction2(expr)) {
24271
- if (systemScope) {
24272
- ce.popScope();
24297
+ );
24273
24298
  }
24274
- throw new Error(`Invalid rule "${rule}"`);
24275
- }
24276
- const [match_, replace_, condition] = expr.ops;
24277
- let match2 = match_;
24278
- let replace2 = replace_;
24279
- if (canonical2) {
24280
- match2 = match2.canonical;
24281
- replace2 = replace2.canonical;
24282
- }
24283
- if (systemScope) {
24284
- ce.popScope();
24285
- }
24286
- if (!includesWildcards(replace2, match2))
24287
- throw new Error(
24288
- `Invalid rule "${rule}"
24299
+ if (!isFunction2(expr)) {
24300
+ throw new Error(`Invalid rule "${rule}"`);
24301
+ }
24302
+ const [match_, replace_, condition] = expr.ops;
24303
+ let match2 = match_;
24304
+ let replace2 = replace_;
24305
+ if (canonical2) {
24306
+ match2 = match2.canonical;
24307
+ replace2 = replace2.canonical;
24308
+ }
24309
+ if (!includesWildcards(replace2, match2))
24310
+ throw new Error(
24311
+ `Invalid rule "${rule}"
24289
24312
  | The replace expression contains wildcards not present in the match expression`
24290
- );
24291
- if (match2.isSame(replace2)) {
24292
- throw new Error(
24293
- `Invalid rule "${rule}"
24294
- | The match and replace expressions are the same.
24295
- | This may be because the rule is not necessary due to canonical simplification`
24296
- );
24297
- }
24298
- let condFn = void 0;
24299
- if (condition !== void 0) {
24300
- if (!includesWildcards(condition, match2))
24313
+ );
24314
+ if (match2.isSame(replace2)) {
24301
24315
  throw new Error(
24302
24316
  `Invalid rule "${rule}"
24303
- | The condition expression contains wildcards not present in the match expression`
24317
+ | The match and replace expressions are the same.
24318
+ | This may be because the rule is not necessary due to canonical simplification`
24304
24319
  );
24305
- condFn = (sub3) => {
24306
- const evaluated = condition.subs(sub3).canonical.evaluate();
24307
- return isSymbol2(evaluated) && evaluated.symbol === "True";
24308
- };
24320
+ }
24321
+ let condFn = void 0;
24322
+ if (condition !== void 0) {
24323
+ if (!includesWildcards(condition, match2))
24324
+ throw new Error(
24325
+ `Invalid rule "${rule}"
24326
+ | The condition expression contains wildcards not present in the match expression`
24327
+ );
24328
+ condFn = (sub3) => {
24329
+ const evaluated = condition.subs(sub3).canonical.evaluate();
24330
+ return isSymbol2(evaluated) && evaluated.symbol === "True";
24331
+ };
24332
+ }
24333
+ return boxRule(
24334
+ ce,
24335
+ { match: match2, replace: replace2, condition: condFn, id: rule },
24336
+ options
24337
+ );
24338
+ } finally {
24339
+ if (systemScope) {
24340
+ ce.popScope();
24341
+ }
24309
24342
  }
24310
- return boxRule(ce, { match: match2, replace: replace2, condition: condFn, id: rule }, options);
24311
24343
  }
24312
24344
  function boxRule(ce, rule, options) {
24313
24345
  if (rule === void 0 || rule === null)
@@ -24361,12 +24393,17 @@ ${lines.join("\n")}`;
24361
24393
  } else {
24362
24394
  ce.pushScope();
24363
24395
  }
24364
- const matchExpr = parseRulePart(ce, match2, {
24365
- canonical: false,
24366
- autoWildcard: false
24367
- });
24368
- const replaceExpr = parseRulePart(ce, replace2, options);
24369
- ce.popScope();
24396
+ let matchExpr;
24397
+ let replaceExpr;
24398
+ try {
24399
+ matchExpr = parseRulePart(ce, match2, {
24400
+ canonical: false,
24401
+ autoWildcard: false
24402
+ });
24403
+ replaceExpr = typeof replace2 === "function" ? replace2 : parseRulePart(ce, replace2, options);
24404
+ } finally {
24405
+ ce.popScope();
24406
+ }
24370
24407
  if (!id) {
24371
24408
  if (typeof match2 === "string") id = match2;
24372
24409
  else id = JSON.stringify(match2, void 0, 4);
@@ -24387,7 +24424,7 @@ ${lines.join("\n")}`;
24387
24424
  | the match expression is not valid: ${matchExpr.toString()}`
24388
24425
  );
24389
24426
  }
24390
- if (replaceExpr && !replaceExpr.isValid) {
24427
+ if (replaceExpr && typeof replaceExpr !== "function" && !replaceExpr.isValid) {
24391
24428
  throw new Error(
24392
24429
  `Invalid rule ${id ?? JSON.stringify(rule, void 0, 4)}
24393
24430
  | The replace expression is not valid: ${replaceExpr?.toString()}`
@@ -24430,6 +24467,7 @@ ${e.message}
24430
24467
  return { rules };
24431
24468
  }
24432
24469
  function applyRule(rule, expr, substitution, options) {
24470
+ if (!rule) return null;
24433
24471
  let canonical2 = options?.canonical ?? (expr.isCanonical || expr.isStructural);
24434
24472
  let operandsMatched = false;
24435
24473
  if (isFunction2(expr) && options?.recursive) {
@@ -25453,8 +25491,12 @@ ${e.message}`);
25453
25491
  const uEquation = substitutedArg.sub(aSquared).simplify();
25454
25492
  ce.pushScope();
25455
25493
  ce.declare(uSymbolName, { type: "real" });
25456
- const uSolutions = findUnivariateRoots(uEquation, uSymbolName);
25457
- ce.popScope();
25494
+ let uSolutions;
25495
+ try {
25496
+ uSolutions = findUnivariateRoots(uEquation, uSymbolName);
25497
+ } finally {
25498
+ ce.popScope();
25499
+ }
25458
25500
  if (uSolutions.length === 0) return null;
25459
25501
  const xSolutions = [];
25460
25502
  for (const uVal of uSolutions) {
@@ -25491,40 +25533,44 @@ ${e.message}`);
25491
25533
  const rules = ce.getRuleSet("solve-univariate");
25492
25534
  let exprs = [expr.subs({ [x]: "_x" }, { canonical: false })];
25493
25535
  ce.pushScope();
25494
- const varType = ce.symbol(x).type.type;
25495
- ce.declare("_x", typeof varType === "string" ? varType : "number");
25496
- let result = exprs.flatMap(
25497
- (expr2) => matchAnyRules(
25498
- expr2,
25499
- rules,
25500
- { _x: ce.symbol("_x") },
25501
- { useVariations: true, canonical: true }
25502
- )
25503
- );
25504
- if (result.length === 0) {
25505
- exprs = exprs.flatMap((expr2) => harmonize(expr2));
25506
- result = exprs.flatMap(
25507
- (expr2) => matchAnyRules(
25508
- expr2,
25509
- rules,
25510
- { _x: ce.symbol(x) },
25511
- { useVariations: true, canonical: true }
25512
- )
25513
- );
25514
- }
25515
- if (result.length === 0) {
25516
- exprs = exprs.flatMap((expr2) => expand2(expr2.canonical)).filter((x2) => x2 !== null);
25517
- exprs = exprs.flatMap((expr2) => harmonize(expr2));
25536
+ let result = [];
25537
+ try {
25538
+ const varType = ce.symbol(x).type.type;
25539
+ ce.declare("_x", typeof varType === "string" ? varType : "number");
25518
25540
  result = exprs.flatMap(
25519
25541
  (expr2) => matchAnyRules(
25520
25542
  expr2,
25521
25543
  rules,
25522
- { _x: ce.symbol(x) },
25544
+ { _x: ce.symbol("_x") },
25523
25545
  { useVariations: true, canonical: true }
25524
25546
  )
25525
25547
  );
25548
+ if (result.length === 0) {
25549
+ exprs = exprs.flatMap((expr2) => harmonize(expr2));
25550
+ result = exprs.flatMap(
25551
+ (expr2) => matchAnyRules(
25552
+ expr2,
25553
+ rules,
25554
+ { _x: ce.symbol(x) },
25555
+ { useVariations: true, canonical: true }
25556
+ )
25557
+ );
25558
+ }
25559
+ if (result.length === 0) {
25560
+ exprs = exprs.flatMap((expr2) => expand2(expr2.canonical)).filter((x2) => x2 !== null);
25561
+ exprs = exprs.flatMap((expr2) => harmonize(expr2));
25562
+ result = exprs.flatMap(
25563
+ (expr2) => matchAnyRules(
25564
+ expr2,
25565
+ rules,
25566
+ { _x: ce.symbol(x) },
25567
+ { useVariations: true, canonical: true }
25568
+ )
25569
+ );
25570
+ }
25571
+ } finally {
25572
+ ce.popScope();
25526
25573
  }
25527
- ce.popScope();
25528
25574
  const validatedRoots = validateRoots(
25529
25575
  originalExpr,
25530
25576
  x,
@@ -34649,9 +34695,12 @@ ${e.message}`);
34649
34695
  signature: "((collection|number)+) -> number",
34650
34696
  type: () => "finite_real",
34651
34697
  description: "The most frequently occurring value in the collection.",
34652
- evaluate: (ops, { engine }) => engine.number(
34653
- bignumPreferred(engine) ? bigMean(engine.bignum.bind(engine), flattenBigScalars(ops)) : mean(flattenScalars(ops))
34654
- )
34698
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34699
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34700
+ return engine.number(
34701
+ bignumPreferred(engine) ? bigMean(engine.bignum.bind(engine), flattenBigScalars(xs)) : mean(flattenScalars(xs))
34702
+ );
34703
+ }
34655
34704
  },
34656
34705
  Median: {
34657
34706
  complexity: 1200,
@@ -34660,30 +34709,39 @@ ${e.message}`);
34660
34709
  type: () => "finite_real",
34661
34710
  description: "The most frequently occurring value in the collection.",
34662
34711
  examples: ["Mode([1, 2, 2, 3]) // Returns 2"],
34663
- evaluate: (ops, { engine }) => engine.number(
34664
- bignumPreferred(engine) ? bigMedian(flattenBigScalars(ops)) : median(flattenScalars(ops))
34665
- )
34712
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34713
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34714
+ return engine.number(
34715
+ bignumPreferred(engine) ? bigMedian(flattenBigScalars(xs)) : median(flattenScalars(xs))
34716
+ );
34717
+ }
34666
34718
  },
34667
34719
  Variance: {
34668
34720
  complexity: 1200,
34669
34721
  broadcastable: false,
34670
34722
  signature: "((collection|number)+) -> number",
34671
34723
  type: () => "finite_real",
34672
- evaluate: (ops, { engine }) => engine.number(
34673
- bignumPreferred(engine) ? bigVariance(engine.bignum.bind(engine), flattenBigScalars(ops)) : variance(flattenScalars(ops))
34674
- )
34724
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34725
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34726
+ return engine.number(
34727
+ bignumPreferred(engine) ? bigVariance(engine.bignum.bind(engine), flattenBigScalars(xs)) : variance(flattenScalars(xs))
34728
+ );
34729
+ }
34675
34730
  },
34676
34731
  PopulationVariance: {
34677
34732
  complexity: 1200,
34678
34733
  broadcastable: false,
34679
34734
  signature: "((collection|number)+) -> number",
34680
34735
  type: () => "finite_real",
34681
- evaluate: (ops, { engine }) => engine.number(
34682
- bignumPreferred(engine) ? bigPopulationVariance(
34683
- engine.bignum.bind(engine),
34684
- flattenBigScalars(ops)
34685
- ) : populationVariance(flattenScalars(ops))
34686
- )
34736
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34737
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34738
+ return engine.number(
34739
+ bignumPreferred(engine) ? bigPopulationVariance(
34740
+ engine.bignum.bind(engine),
34741
+ flattenBigScalars(xs)
34742
+ ) : populationVariance(flattenScalars(xs))
34743
+ );
34744
+ }
34687
34745
  },
34688
34746
  StandardDeviation: {
34689
34747
  complexity: 1200,
@@ -34691,12 +34749,15 @@ ${e.message}`);
34691
34749
  description: "Sample Standard Deviation of a collection of numbers.",
34692
34750
  signature: "((collection|number)+) -> number",
34693
34751
  type: () => "finite_real",
34694
- evaluate: (ops, { engine }) => engine.number(
34695
- bignumPreferred(engine) ? bigVariance(
34696
- engine.bignum.bind(engine),
34697
- flattenBigScalars(ops)
34698
- ).sqrt() : Math.sqrt(variance(flattenScalars(ops)))
34699
- )
34752
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34753
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34754
+ return engine.number(
34755
+ bignumPreferred(engine) ? bigVariance(
34756
+ engine.bignum.bind(engine),
34757
+ flattenBigScalars(xs)
34758
+ ).sqrt() : Math.sqrt(variance(flattenScalars(xs)))
34759
+ );
34760
+ }
34700
34761
  },
34701
34762
  PopulationStandardDeviation: {
34702
34763
  complexity: 1200,
@@ -34704,47 +34765,60 @@ ${e.message}`);
34704
34765
  description: "Population Standard Deviation of a collection of numbers.",
34705
34766
  signature: "((collection|number)+) -> number",
34706
34767
  type: () => "finite_real",
34707
- evaluate: (ops, { engine }) => engine.number(
34708
- bignumPreferred(engine) ? bigPopulationVariance(
34709
- engine.bignum.bind(engine),
34710
- flattenBigScalars(ops)
34711
- ).sqrt() : Math.sqrt(populationVariance(flattenScalars(ops)))
34712
- )
34768
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34769
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34770
+ return engine.number(
34771
+ bignumPreferred(engine) ? bigPopulationVariance(
34772
+ engine.bignum.bind(engine),
34773
+ flattenBigScalars(xs)
34774
+ ).sqrt() : Math.sqrt(populationVariance(flattenScalars(xs)))
34775
+ );
34776
+ }
34713
34777
  },
34714
34778
  Kurtosis: {
34715
34779
  complexity: 1200,
34716
34780
  broadcastable: false,
34717
34781
  signature: "((collection|number)+) -> number",
34718
34782
  type: () => "finite_real",
34719
- evaluate: (ops, { engine }) => engine.number(
34720
- bignumPreferred(engine) ? bigKurtosis(engine.bignum.bind(engine), flattenBigScalars(ops)) : kurtosis(flattenScalars(ops))
34721
- )
34783
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34784
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34785
+ return engine.number(
34786
+ bignumPreferred(engine) ? bigKurtosis(engine.bignum.bind(engine), flattenBigScalars(xs)) : kurtosis(flattenScalars(xs))
34787
+ );
34788
+ }
34722
34789
  },
34723
34790
  Skewness: {
34724
34791
  complexity: 1200,
34725
34792
  broadcastable: false,
34726
34793
  signature: "((collection|number)+) -> number",
34727
34794
  type: () => "finite_real",
34728
- evaluate: (ops, { engine }) => engine.number(
34729
- bignumPreferred(engine) ? bigSkewness(engine.bignum.bind(engine), flattenBigScalars(ops)) : skewness(flattenScalars(ops))
34730
- )
34795
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34796
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34797
+ return engine.number(
34798
+ bignumPreferred(engine) ? bigSkewness(engine.bignum.bind(engine), flattenBigScalars(xs)) : skewness(flattenScalars(xs))
34799
+ );
34800
+ }
34731
34801
  },
34732
34802
  Mode: {
34733
34803
  complexity: 1200,
34734
34804
  broadcastable: false,
34735
34805
  signature: "((collection|number)+) -> number",
34736
34806
  type: () => "finite_real",
34737
- evaluate: (ops, { engine }) => engine.number(
34738
- bignumPreferred(engine) ? bigMode(engine.bignum.bind(engine), flattenBigScalars(ops)) : mode(flattenScalars(ops))
34739
- )
34807
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34808
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34809
+ return engine.number(
34810
+ bignumPreferred(engine) ? bigMode(engine.bignum.bind(engine), flattenBigScalars(xs)) : mode(flattenScalars(xs))
34811
+ );
34812
+ }
34740
34813
  },
34741
34814
  Quartiles: {
34742
34815
  complexity: 1200,
34743
34816
  broadcastable: false,
34744
34817
  signature: "((collection|number)+) -> tuple<mid:number, lower:number, upper:number>",
34745
34818
  examples: ["Quartiles([1, 2, 3, 4, 5]) // Returns (3, 2, 4)"],
34746
- evaluate: (ops, { engine }) => {
34747
- const [mid, lower, upper] = (bignumPreferred(engine) ? bigQuartiles(flattenBigScalars(ops)) : quartiles(flattenScalars(ops))).map((v) => engine.number(v));
34819
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34820
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34821
+ const [mid, lower, upper] = (bignumPreferred(engine) ? bigQuartiles(flattenBigScalars(xs)) : quartiles(flattenScalars(xs))).map((v) => engine.number(v));
34748
34822
  return engine.tuple(mid, lower, upper);
34749
34823
  }
34750
34824
  },
@@ -34753,9 +34827,12 @@ ${e.message}`);
34753
34827
  broadcastable: false,
34754
34828
  signature: "((collection|number)+) -> number",
34755
34829
  type: () => "finite_real",
34756
- evaluate: (ops, { engine }) => engine.number(
34757
- bignumPreferred(engine) ? bigInterquartileRange(flattenBigScalars(ops)) : interquartileRange(flattenScalars(ops))
34758
- )
34830
+ evaluate: (ops, { engine, numericApproximation: numericApproximation2 }) => {
34831
+ const xs = ops.map((x) => x.evaluate({ numericApproximation: numericApproximation2 }));
34832
+ return engine.number(
34833
+ bignumPreferred(engine) ? bigInterquartileRange(flattenBigScalars(xs)) : interquartileRange(flattenScalars(xs))
34834
+ );
34835
+ }
34759
34836
  },
34760
34837
  Histogram: {
34761
34838
  description: "Compute a histogram of the values in a collection. Returns a list of (bin start, count) tuples.",
@@ -42379,12 +42456,16 @@ Error in definition of "${name}"`,
42379
42456
  this.engine.context.values[k] = v;
42380
42457
  }
42381
42458
  }
42382
- const evalResult = def.evaluate?.(tail, {
42383
- numericApproximation: numericApproximation2,
42384
- engine: this.engine,
42385
- materialization
42386
- });
42387
- if (isScoped) this.engine._popEvalContext();
42459
+ let evalResult;
42460
+ try {
42461
+ evalResult = def.evaluate?.(tail, {
42462
+ numericApproximation: numericApproximation2,
42463
+ engine: this.engine,
42464
+ materialization
42465
+ });
42466
+ } finally {
42467
+ if (isScoped) this.engine._popEvalContext();
42468
+ }
42388
42469
  return evalResult ?? this.engine.function(this._operator, tail);
42389
42470
  };
42390
42471
  }
@@ -47507,9 +47588,13 @@ Error in definition of "${name}"`,
47507
47588
  const def = ce.lookupDefinition(id);
47508
47589
  if (isOperatorDef(def)) {
47509
47590
  const value2 = assignValueAsValue(ce, arg2);
47510
- if (value2) throw Error(`Cannot change the operator "${id}" to a value`);
47591
+ if (value2 !== void 0) {
47592
+ updateDef(ce, id, def, { value: value2 });
47593
+ ce._setSymbolValue(id, value2);
47594
+ return ce;
47595
+ }
47511
47596
  const fnDef2 = assignValueAsOperatorDef(ce, arg2);
47512
- if (!fnDef2) throw Error(`Cannot change the operator "${id}" to a value`);
47597
+ if (!fnDef2) throw Error(`Invalid definition for symbol "${id}"`);
47513
47598
  updateDef(ce, id, def, fnDef2);
47514
47599
  return ce;
47515
47600
  }
@@ -61094,10 +61179,10 @@ ${code}`;
61094
61179
  _setComputeEngineClass(ComputeEngine);
61095
61180
 
61096
61181
  // src/compute-engine.ts
61097
- var version = "0.50.1";
61182
+ var version = "0.50.2";
61098
61183
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
61099
61184
  ComputeEngine: ComputeEngine.prototype.constructor,
61100
- version: "0.50.1"
61185
+ version: "0.50.2"
61101
61186
  };
61102
61187
  return __toCommonJS(compute_engine_exports);
61103
61188
  })();