@cortex-js/compute-engine 0.53.0 → 0.53.1

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 (226) hide show
  1. package/dist/compute-engine.esm.js +719 -59
  2. package/dist/compute-engine.min.esm.js +519 -47
  3. package/dist/{compute-engine.min.umd.js → compute-engine.min.umd.cjs} +525 -53
  4. package/dist/{compute-engine.umd.js → compute-engine.umd.cjs} +719 -59
  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 → math-json.min.umd.cjs} +2 -2
  8. package/dist/{math-json.umd.js → math-json.umd.cjs} +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/rules.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/stochastic-equal.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 +68 -1
  83. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  84. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  85. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  86. package/dist/types/compute-engine/compilation/types.d.ts +9 -1
  87. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  88. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  89. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  90. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  91. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  92. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  93. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  94. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  95. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  96. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  97. package/dist/types/compute-engine/engine-latex-dictionary-state.d.ts +1 -1
  98. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  99. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  100. package/dist/types/compute-engine/engine-parse-entrypoint.d.ts +1 -1
  101. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  102. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  103. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  104. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  105. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  106. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  107. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  108. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  109. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  110. package/dist/types/compute-engine/global-types.d.ts +1 -1
  111. package/dist/types/compute-engine/index.d.ts +1 -1
  112. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  113. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  114. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  115. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  116. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  117. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  118. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  119. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  120. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  121. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  122. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  124. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  125. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  126. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  127. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  128. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  129. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  130. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  131. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  132. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  133. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  134. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  135. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  136. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  137. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  138. package/dist/types/compute-engine/latex-syntax/serialize-dms.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/colors.d.ts +1 -1
  149. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  150. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  151. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  152. package/dist/types/compute-engine/library/core.d.ts +1 -1
  153. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  154. package/dist/types/compute-engine/library/library.d.ts +1 -1
  155. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  156. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  157. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  158. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  159. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  160. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  161. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  162. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  163. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  164. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  165. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  166. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  167. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  168. package/dist/types/compute-engine/library/units.d.ts +1 -1
  169. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  170. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  171. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  172. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  173. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  174. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  175. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  176. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  177. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  178. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  179. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +2 -2
  180. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  181. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  182. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  183. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  184. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  185. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  186. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  187. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  188. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  189. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  190. package/dist/types/compute-engine/oeis.d.ts +1 -1
  191. package/dist/types/compute-engine/sequence.d.ts +1 -1
  192. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  193. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  194. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  195. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  196. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  197. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  198. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  199. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  200. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  201. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  202. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  203. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  204. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  205. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  206. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  207. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  208. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  209. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  210. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  211. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  212. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  213. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  214. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  215. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  216. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  217. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  218. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  219. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  220. package/dist/types/compute-engine/types.d.ts +1 -1
  221. package/dist/types/compute-engine.d.ts +1 -1
  222. package/dist/types/math-json/symbols.d.ts +1 -1
  223. package/dist/types/math-json/types.d.ts +1 -1
  224. package/dist/types/math-json/utils.d.ts +1 -1
  225. package/dist/types/math-json.d.ts +2 -2
  226. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.53.0 */
1
+ /** Compute Engine 0.53.1 */
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;
@@ -11144,7 +11144,7 @@ var ComputeEngine = (() => {
11144
11144
  condition: (p) => {
11145
11145
  if (until?.condition?.(p)) return true;
11146
11146
  const saved = p.index;
11147
- p.skipSpace();
11147
+ p.skipVisualSpace();
11148
11148
  const isComma = p.peek === ",";
11149
11149
  p.index = saved;
11150
11150
  return isComma;
@@ -11152,11 +11152,11 @@ var ComputeEngine = (() => {
11152
11152
  };
11153
11153
  const bindings = [];
11154
11154
  do {
11155
- parser.skipSpace();
11155
+ parser.skipVisualSpace();
11156
11156
  const binding = parser.parseExpression(bindingTerminator);
11157
11157
  if (!binding) break;
11158
11158
  bindings.push(binding);
11159
- parser.skipSpace();
11159
+ parser.skipVisualSpace();
11160
11160
  } while (parser.match(","));
11161
11161
  if (bindings.length === 0) return null;
11162
11162
  const block = [];
@@ -11655,14 +11655,11 @@ var ComputeEngine = (() => {
11655
11655
  let loop = n;
11656
11656
  let sum2 = n;
11657
11657
  let val = n;
11658
- let counter = 0;
11659
11658
  while (loop > 2) {
11660
11659
  loop -= BigInt(2);
11661
11660
  sum2 += loop;
11662
11661
  val *= sum2;
11663
- counter += 1;
11664
- if (counter % 5e4 === 0 || counter > 1e4 && counter % 500 === 0)
11665
- yield val;
11662
+ yield val;
11666
11663
  }
11667
11664
  return val;
11668
11665
  }
@@ -16731,13 +16728,14 @@ ${lines.join("\n")}`;
16731
16728
  function lcm3(a, b) {
16732
16729
  return a.mul(b).div(gcd3(a, b));
16733
16730
  }
16734
- function factorial23(ce, n) {
16731
+ function* factorial23(ce, n) {
16735
16732
  if (!n.isInteger() || n.isNegative()) return ce._BIGNUM_NAN;
16736
16733
  if (n.lessThan(1)) return ce._BIGNUM_ONE;
16737
16734
  let result = n;
16738
16735
  while (n.greaterThan(2)) {
16739
16736
  n = n.minus(2);
16740
16737
  result = result.mul(n);
16738
+ yield result;
16741
16739
  }
16742
16740
  return result;
16743
16741
  }
@@ -20254,24 +20252,30 @@ ${lines.join("\n")}`;
20254
20252
  if (initial.type.matches("real") && collection.type.matches(ce.type("collection<real>"))) {
20255
20253
  const compiled = ce._compile(fn);
20256
20254
  if (compiled.calling !== "lambda" || !compiled.run) return void 0;
20257
- let accumulator2 = initial.re;
20258
- let first2 = true;
20259
- for (const item of collection.each()) {
20260
- if (first2) accumulator2 = item.re;
20261
- else accumulator2 = compiled.run(accumulator2, item.re);
20262
- first2 = false;
20263
- }
20264
- return ce.box(accumulator2);
20255
+ return run(
20256
+ (function* () {
20257
+ let accumulator = initial.re;
20258
+ let first = true;
20259
+ for (const item of collection.each()) {
20260
+ if (first) accumulator = item.re;
20261
+ else accumulator = compiled.run(accumulator, item.re);
20262
+ first = false;
20263
+ yield;
20264
+ }
20265
+ return ce.box(accumulator);
20266
+ })(),
20267
+ ce._timeRemaining
20268
+ );
20265
20269
  }
20266
20270
  const f = applicable(fn);
20267
- let accumulator = initial;
20268
- let first = true;
20269
- for (const item of collection.each()) {
20270
- if (first) accumulator = item;
20271
- else accumulator = f([accumulator, item]) ?? ce.Nothing;
20272
- first = false;
20273
- }
20274
- return accumulator;
20271
+ return run(
20272
+ reduceCollection(
20273
+ collection,
20274
+ (acc, x) => f([acc, x]) ?? ce.Nothing,
20275
+ initial
20276
+ ),
20277
+ ce._timeRemaining
20278
+ );
20275
20279
  }
20276
20280
  },
20277
20281
  Join: {
@@ -21496,12 +21500,10 @@ ${lines.join("\n")}`;
21496
21500
  }
21497
21501
  function* reduceCollection(collection, fn, initial) {
21498
21502
  let acc = initial;
21499
- let counter = 0;
21500
21503
  for (const x of collection.each()) {
21501
21504
  const result = fn(acc, x);
21502
21505
  if (result === null) return void 0;
21503
- counter += 1;
21504
- if (counter % 1e3 === 0) yield acc;
21506
+ yield acc;
21505
21507
  acc = result;
21506
21508
  }
21507
21509
  return acc;
@@ -22920,12 +22922,10 @@ ${lines.join("\n")}`;
22920
22922
  const indexingSets = normalizeIndexingSets(indexes);
22921
22923
  const cartesianArray = indexingSetCartesianProduct(indexingSets);
22922
22924
  let result = initial;
22923
- let counter = 0;
22924
22925
  for (const element of cartesianArray) {
22925
22926
  indexingSets.forEach((x, i) => ce.assign(x.index, element[i]));
22926
22927
  result = fn(result, body) ?? void 0;
22927
- counter += 1;
22928
- if (counter % 1e3 === 0) yield result;
22928
+ yield result;
22929
22929
  if (result === void 0) break;
22930
22930
  }
22931
22931
  return result ?? void 0;
@@ -22992,7 +22992,6 @@ ${lines.join("\n")}`;
22992
22992
  return initial;
22993
22993
  }
22994
22994
  let result = initial;
22995
- let counter = 0;
22996
22995
  while (true) {
22997
22996
  for (let i = 0; i < elementDomains.length; i++) {
22998
22997
  ce.assign(
@@ -23001,8 +23000,7 @@ ${lines.join("\n")}`;
23001
23000
  );
23002
23001
  }
23003
23002
  result = fn(result, body) ?? void 0;
23004
- counter++;
23005
- if (counter % 1e3 === 0) yield result;
23003
+ yield result;
23006
23004
  if (result === void 0) break;
23007
23005
  let dim = elementDomains.length - 1;
23008
23006
  while (dim >= 0) {
@@ -23972,7 +23970,8 @@ ${lines.join("\n")}`;
23972
23970
  ce._timeRemaining
23973
23971
  )
23974
23972
  );
23975
- } catch {
23973
+ } catch (e) {
23974
+ if (e instanceof CancellationError) throw e;
23976
23975
  return void 0;
23977
23976
  }
23978
23977
  },
@@ -23991,7 +23990,8 @@ ${lines.join("\n")}`;
23991
23990
  signal
23992
23991
  )
23993
23992
  );
23994
- } catch {
23993
+ } catch (e) {
23994
+ if (e instanceof CancellationError) throw e;
23995
23995
  return void 0;
23996
23996
  }
23997
23997
  }
@@ -24009,7 +24009,7 @@ ${lines.join("\n")}`;
24009
24009
  if (n === null) return void 0;
24010
24010
  const ce = x.engine;
24011
24011
  if (bignumPreferred(ce))
24012
- return ce.number(factorial23(ce, ce.bignum(n)));
24012
+ return ce.number(run(factorial23(ce, ce.bignum(n)), ce._timeRemaining));
24013
24013
  return ce.number(factorial22(n));
24014
24014
  }
24015
24015
  },
@@ -33600,7 +33600,7 @@ ${e.message}
33600
33600
  if (isFunction2(result, "Break")) return result.op1;
33601
33601
  if (result.operator === "Return") return result;
33602
33602
  i2 += 1;
33603
- if (i2 % 1e3 === 0) yield result;
33603
+ yield result;
33604
33604
  if (i2 > ce.iterationLimit)
33605
33605
  throw new CancellationError({ cause: "iteration-limit-exceeded" });
33606
33606
  }
@@ -33612,7 +33612,7 @@ ${e.message}
33612
33612
  if (isFunction2(result, "Break")) return result.op1;
33613
33613
  if (result.operator === "Return") return result;
33614
33614
  i += 1;
33615
- if (i % 1e3 === 0) yield result;
33615
+ yield result;
33616
33616
  if (i > ce.iterationLimit)
33617
33617
  throw new CancellationError({ cause: "iteration-limit-exceeded" });
33618
33618
  }
@@ -48972,9 +48972,11 @@ Error in definition of "${name}"`,
48972
48972
  return () => {
48973
48973
  if (engine._deadline === void 0) {
48974
48974
  engine._deadline = Date.now() + engine.timeLimit;
48975
- const result = fn();
48976
- engine._deadline = void 0;
48977
- return result;
48975
+ try {
48976
+ return fn();
48977
+ } finally {
48978
+ engine._deadline = void 0;
48979
+ }
48978
48980
  }
48979
48981
  return fn();
48980
48982
  };
@@ -48983,9 +48985,11 @@ Error in definition of "${name}"`,
48983
48985
  return async () => {
48984
48986
  if (engine._deadline === void 0) {
48985
48987
  engine._deadline = Date.now() + engine.timeLimit;
48986
- const result = await fn();
48987
- engine._deadline = void 0;
48988
- return result;
48988
+ try {
48989
+ return await fn();
48990
+ } finally {
48991
+ engine._deadline = void 0;
48992
+ }
48989
48993
  }
48990
48994
  return fn();
48991
48995
  };
@@ -50483,6 +50487,13 @@ Error in definition of "${name}"`,
50483
50487
  }
50484
50488
  }
50485
50489
  if (h === "Function") {
50490
+ const fnFn = target.functions?.(h);
50491
+ if (typeof fnFn === "function")
50492
+ return fnFn(
50493
+ args,
50494
+ (expr) => _BaseCompiler.compile(expr, target),
50495
+ target
50496
+ );
50486
50497
  const params = args.slice(1).map((x) => isSymbol2(x) ? x.symbol : "_");
50487
50498
  return `((${params.join(", ")}) => ${_BaseCompiler.compile(
50488
50499
  args[0].canonical,
@@ -50492,15 +50503,26 @@ Error in definition of "${name}"`,
50492
50503
  }
50493
50504
  )})`;
50494
50505
  }
50495
- if (h === "Declare")
50496
- return `let ${isSymbol2(args[0]) ? args[0].symbol : "_"}`;
50506
+ if (h === "Declare") {
50507
+ const name = isSymbol2(args[0]) ? args[0].symbol : "_";
50508
+ return target.declare ? target.declare(name) : `let ${name}`;
50509
+ }
50497
50510
  if (h === "Assign")
50498
50511
  return `${isSymbol2(args[0]) ? args[0].symbol : "_"} = ${_BaseCompiler.compile(args[1], target)}`;
50499
50512
  if (h === "Return")
50500
50513
  return `return ${_BaseCompiler.compile(args[0], target)}`;
50501
50514
  if (h === "Break") return "break";
50502
50515
  if (h === "Continue") return "continue";
50503
- if (h === "Loop") return _BaseCompiler.compileForLoop(args, target);
50516
+ if (h === "Loop") {
50517
+ const loopFn = target.functions?.(h);
50518
+ if (typeof loopFn === "function")
50519
+ return loopFn(
50520
+ args,
50521
+ (expr) => _BaseCompiler.compile(expr, target),
50522
+ target
50523
+ );
50524
+ return _BaseCompiler.compileForLoop(args, target);
50525
+ }
50504
50526
  if (h === "If") {
50505
50527
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
50506
50528
  const fn2 = target.functions?.(h);
@@ -50577,16 +50599,35 @@ Error in definition of "${name}"`,
50577
50599
  if (args.length === 1 && locals.length === 0) {
50578
50600
  return _BaseCompiler.compile(args[0], target);
50579
50601
  }
50580
- const result = args.filter((a) => !isSymbol2(a, "Nothing")).map(
50581
- (arg) => _BaseCompiler.compile(arg, {
50582
- ...target,
50583
- var: (id) => {
50584
- if (locals.includes(id)) return id;
50585
- return target.var(id);
50602
+ const typeHints = {};
50603
+ if (target.declare && target.language) {
50604
+ const isWGSL = target.language === "wgsl";
50605
+ for (const local of locals) {
50606
+ for (const arg of args) {
50607
+ if (isFunction2(arg, "Assign") && isSymbol2(arg.ops[0], local)) {
50608
+ if (_BaseCompiler.isComplexValued(arg.ops[1])) {
50609
+ typeHints[local] = isWGSL ? "vec2f" : "vec2";
50610
+ }
50611
+ break;
50612
+ }
50586
50613
  }
50587
- })
50588
- ).filter((s) => s !== "");
50614
+ }
50615
+ }
50616
+ const localTarget = {
50617
+ ...target,
50618
+ var: (id) => {
50619
+ if (locals.includes(id)) return id;
50620
+ return target.var(id);
50621
+ }
50622
+ };
50623
+ const result = args.filter((a) => !isSymbol2(a, "Nothing")).map((arg) => {
50624
+ if (isFunction2(arg, "Declare") && isSymbol2(arg.ops[0]) && target.declare) {
50625
+ return target.declare(arg.ops[0].symbol, typeHints[arg.ops[0].symbol]);
50626
+ }
50627
+ return _BaseCompiler.compile(arg, localTarget);
50628
+ }).filter((s) => s !== "");
50589
50629
  if (result.length === 0) return "";
50630
+ if (target.block) return target.block(result);
50590
50631
  result[result.length - 1] = `return ${result[result.length - 1]}`;
50591
50632
  return `(() => {${target.ws("\n")}${result.join(
50592
50633
  `;${target.ws("\n")}`
@@ -57352,6 +57393,62 @@ Error in definition of "${name}"`,
57352
57393
  function gpuVec2(target) {
57353
57394
  return target?.language === "wgsl" ? "vec2f" : "vec2";
57354
57395
  }
57396
+ var GPU_UNROLL_LIMIT = 100;
57397
+ function compileGPUSumProduct(kind, args, _compile2, target) {
57398
+ if (!args[0]) throw new Error(`${kind}: no body`);
57399
+ if (!args[1]) throw new Error(`${kind}: no indexing set`);
57400
+ if (BaseCompiler.isComplexValued(args[0]))
57401
+ throw new Error(
57402
+ `${kind}: complex-valued body not supported in GPU targets`
57403
+ );
57404
+ const limitsExpr = args[1];
57405
+ if (!isFunction2(limitsExpr, "Limits"))
57406
+ throw new Error(`${kind}: expected Limits indexing set`);
57407
+ const limitsOps = limitsExpr.ops;
57408
+ const index = isSymbol2(limitsOps[0]) ? limitsOps[0].symbol : "_";
57409
+ const lowerRe = limitsOps[1].re;
57410
+ const upperRe = limitsOps[2].re;
57411
+ const lowerNum = !isNaN(lowerRe) && Number.isFinite(lowerRe) ? Math.floor(lowerRe) : void 0;
57412
+ const upperNum = !isNaN(upperRe) && Number.isFinite(upperRe) ? Math.floor(upperRe) : void 0;
57413
+ const isSum = kind === "Sum";
57414
+ const op = isSum ? "+" : "*";
57415
+ const identity = isSum ? "0.0" : "1.0";
57416
+ const isWGSL = target.language === "wgsl";
57417
+ const bothConstant = lowerNum !== void 0 && upperNum !== void 0;
57418
+ if (bothConstant && lowerNum > upperNum) return identity;
57419
+ if (bothConstant && upperNum - lowerNum + 1 <= GPU_UNROLL_LIMIT) {
57420
+ const terms = [];
57421
+ for (let k = lowerNum; k <= upperNum; k++) {
57422
+ const kStr = formatGPUNumber(k);
57423
+ const innerTarget = {
57424
+ ...target,
57425
+ var: (id) => id === index ? kStr : target.var(id)
57426
+ };
57427
+ terms.push(`(${BaseCompiler.compile(args[0], innerTarget)})`);
57428
+ }
57429
+ return `(${terms.join(` ${op} `)})`;
57430
+ }
57431
+ const acc = BaseCompiler.tempVar();
57432
+ const floatType = isWGSL ? "f32" : "float";
57433
+ const intType = isWGSL ? "i32" : "int";
57434
+ const bodyTarget = {
57435
+ ...target,
57436
+ var: (id) => id === index ? isWGSL ? `f32(${index})` : `float(${index})` : target.var(id)
57437
+ };
57438
+ const body = BaseCompiler.compile(args[0], bodyTarget);
57439
+ const lowerStr = lowerNum !== void 0 ? String(lowerNum) : BaseCompiler.compile(limitsOps[1], target);
57440
+ const upperStr = upperNum !== void 0 ? String(upperNum) : BaseCompiler.compile(limitsOps[2], target);
57441
+ const accDecl = isWGSL ? `var ${acc}: ${floatType}` : `${floatType} ${acc}`;
57442
+ const indexDecl = isWGSL ? `var ${index}: ${intType}` : `${intType} ${index}`;
57443
+ const lines = [
57444
+ `${accDecl} = ${identity};`,
57445
+ `for (${indexDecl} = ${lowerStr}; ${index} <= ${upperStr}; ${index}++) {`,
57446
+ ` ${acc} ${op}= ${body};`,
57447
+ `}`,
57448
+ `return ${acc}`
57449
+ ];
57450
+ return lines.join("\n");
57451
+ }
57355
57452
  var GPU_FUNCTIONS = {
57356
57453
  // Variadic arithmetic (for function-call form, e.g., with vectors)
57357
57454
  Add: (args, compile3, target) => {
@@ -57701,6 +57798,27 @@ Error in definition of "${name}"`,
57701
57798
  if (x === null) throw new Error("ErfInv: no argument");
57702
57799
  return `_gpu_erfinv(${compile3(x)})`;
57703
57800
  },
57801
+ Heaviside: ([x], compile3) => {
57802
+ if (x === null) throw new Error("Heaviside: no argument");
57803
+ return `_gpu_heaviside(${compile3(x)})`;
57804
+ },
57805
+ Sinc: ([x], compile3) => {
57806
+ if (x === null) throw new Error("Sinc: no argument");
57807
+ return `_gpu_sinc(${compile3(x)})`;
57808
+ },
57809
+ FresnelC: ([x], compile3) => {
57810
+ if (x === null) throw new Error("FresnelC: no argument");
57811
+ return `_gpu_fresnelC(${compile3(x)})`;
57812
+ },
57813
+ FresnelS: ([x], compile3) => {
57814
+ if (x === null) throw new Error("FresnelS: no argument");
57815
+ return `_gpu_fresnelS(${compile3(x)})`;
57816
+ },
57817
+ BesselJ: ([n, x], compile3, target) => {
57818
+ if (n === null || x === null) throw new Error("BesselJ: need two arguments");
57819
+ const intCast = target?.language === "wgsl" ? "i32" : "int";
57820
+ return `_gpu_besselJ(${intCast}(${compile3(n)}), ${compile3(x)})`;
57821
+ },
57704
57822
  // Additional math functions
57705
57823
  Lb: "log2",
57706
57824
  Log: (args, compile3) => {
@@ -57786,7 +57904,45 @@ Error in definition of "${name}"`,
57786
57904
  Length: "length",
57787
57905
  Normalize: "normalize",
57788
57906
  Reflect: "reflect",
57789
- Refract: "refract"
57907
+ Refract: "refract",
57908
+ // Sum/Product — unrolled or for-loop
57909
+ Sum: (args, compile3, target) => compileGPUSumProduct("Sum", args, compile3, target),
57910
+ Product: (args, compile3, target) => compileGPUSumProduct("Product", args, compile3, target),
57911
+ // Loop — GPU for-loop (no IIFE, no let)
57912
+ Loop: (args, _compile2, target) => {
57913
+ if (!args[0]) throw new Error("Loop: no body");
57914
+ if (!args[1]) throw new Error("Loop: no indexing set");
57915
+ const indexing = args[1];
57916
+ if (!isFunction2(indexing, "Element"))
57917
+ throw new Error("Loop: expected Element(index, Range(lo, hi))");
57918
+ const indexExpr = indexing.ops[0];
57919
+ const rangeExpr = indexing.ops[1];
57920
+ if (!isSymbol2(indexExpr))
57921
+ throw new Error("Loop: index must be a symbol");
57922
+ if (!isFunction2(rangeExpr, "Range"))
57923
+ throw new Error("Loop: expected Range(lo, hi)");
57924
+ const index = indexExpr.symbol;
57925
+ const lower = Math.floor(rangeExpr.ops[0].re);
57926
+ const upper = Math.floor(rangeExpr.ops[1].re);
57927
+ if (!Number.isFinite(lower) || !Number.isFinite(upper))
57928
+ throw new Error("Loop: bounds must be finite numbers");
57929
+ const isWGSL = target.language === "wgsl";
57930
+ const intType = isWGSL ? "i32" : "int";
57931
+ const bodyCode = BaseCompiler.compile(args[0], {
57932
+ ...target,
57933
+ var: (id) => id === index ? index : target.var(id)
57934
+ });
57935
+ const indexDecl = isWGSL ? `var ${index}: ${intType}` : `${intType} ${index}`;
57936
+ return `for (${indexDecl} = ${lower}; ${index} <= ${upper}; ${index}++) {
57937
+ ${bodyCode};
57938
+ }`;
57939
+ },
57940
+ // Function (lambda) — not supported in GPU
57941
+ Function: () => {
57942
+ throw new Error(
57943
+ "Anonymous functions (Function) are not supported in GPU targets"
57944
+ );
57945
+ }
57790
57946
  };
57791
57947
  function compileGPUMatrix(args, compile3, vecFn, matFn, arrayFn) {
57792
57948
  const body = args[0];
@@ -57866,6 +58022,476 @@ float _gpu_erfinv(float x) {
57866
58022
  float x9 = x7 * x2;
57867
58023
  return sqrt(pi) * 0.5 * (x + (pi / 12.0) * x3 + (7.0 * pi * pi / 480.0) * x5 + (127.0 * pi * pi * pi / 40320.0) * x7 + (4369.0 * pi * pi * pi * pi / 5806080.0) * x9);
57868
58024
  }
58025
+ `;
58026
+ var GPU_HEAVISIDE_PREAMBLE_GLSL = `
58027
+ float _gpu_heaviside(float x) {
58028
+ if (x < 0.0) return 0.0;
58029
+ if (x > 0.0) return 1.0;
58030
+ return 0.5;
58031
+ }
58032
+ `;
58033
+ var GPU_HEAVISIDE_PREAMBLE_WGSL = `
58034
+ fn _gpu_heaviside(x: f32) -> f32 {
58035
+ if (x < 0.0) { return 0.0; }
58036
+ if (x > 0.0) { return 1.0; }
58037
+ return 0.5;
58038
+ }
58039
+ `;
58040
+ var GPU_SINC_PREAMBLE_GLSL = `
58041
+ float _gpu_sinc(float x) {
58042
+ if (abs(x) < 1e-10) return 1.0;
58043
+ return sin(x) / x;
58044
+ }
58045
+ `;
58046
+ var GPU_SINC_PREAMBLE_WGSL = `
58047
+ fn _gpu_sinc(x: f32) -> f32 {
58048
+ if (abs(x) < 1e-10) { return 1.0; }
58049
+ return sin(x) / x;
58050
+ }
58051
+ `;
58052
+ var GPU_POLEVL_PREAMBLE_GLSL = `
58053
+ float _gpu_polevl(float x, float c[12], int n) {
58054
+ float ans = c[0];
58055
+ for (int i = 1; i < n; i++) ans = ans * x + c[i];
58056
+ return ans;
58057
+ }
58058
+ `;
58059
+ var GPU_POLEVL_PREAMBLE_WGSL = `
58060
+ fn _gpu_polevl(x: f32, c: array<f32, 12>, n: i32) -> f32 {
58061
+ var ans = c[0];
58062
+ for (var i: i32 = 1; i < n; i++) { ans = ans * x + c[i]; }
58063
+ return ans;
58064
+ }
58065
+ `;
58066
+ var GPU_FRESNELC_PREAMBLE_GLSL = `
58067
+ float _gpu_fresnelC(float x_in) {
58068
+ float sgn = x_in < 0.0 ? -1.0 : 1.0;
58069
+ float x = abs(x_in);
58070
+
58071
+ if (x < 1.6) {
58072
+ float x2 = x * x;
58073
+ float t = x2 * x2;
58074
+ float cn[6] = float[6](
58075
+ -4.98843114573573548651e-8, 9.50428062829859605134e-6,
58076
+ -6.45191435683965050962e-4, 1.88843319396703850064e-2,
58077
+ -2.05525900955013891793e-1, 9.99999999999999998822e-1
58078
+ );
58079
+ float cd[7] = float[7](
58080
+ 3.99982968972495980367e-12, 9.15439215774657478799e-10,
58081
+ 1.25001862479598821474e-7, 1.22262789024179030997e-5,
58082
+ 8.68029542941784300606e-4, 4.12142090722199792936e-2, 1.0
58083
+ );
58084
+ return sgn * x * _gpu_polevl(t, cn, 6) / _gpu_polevl(t, cd, 7);
58085
+ }
58086
+
58087
+ if (x < 36.0) {
58088
+ float x2 = x * x;
58089
+ float t = 3.14159265358979 * x2;
58090
+ float u = 1.0 / (t * t);
58091
+ float fn[10] = float[10](
58092
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58093
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58094
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58095
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58096
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20
58097
+ );
58098
+ float fd[11] = float[11](
58099
+ 1.0, 7.51586398353378947175e-1,
58100
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58101
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58102
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58103
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58104
+ 1.25443237090011264384e-20
58105
+ );
58106
+ float gn[11] = float[11](
58107
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58108
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58109
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58110
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58111
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58112
+ 1.86958710162783235106e-22
58113
+ );
58114
+ float gd[12] = float[12](
58115
+ 1.0, 1.47495759925128324529,
58116
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58117
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58118
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58119
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58120
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58121
+ );
58122
+ float f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58123
+ float g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58124
+ float z = 1.5707963267948966 * x2;
58125
+ float c = cos(z);
58126
+ float s = sin(z);
58127
+ return sgn * (0.5 + (f * s - g * c) / (3.14159265358979 * x));
58128
+ }
58129
+
58130
+ return sgn * 0.5;
58131
+ }
58132
+ `;
58133
+ var GPU_FRESNELC_PREAMBLE_WGSL = `
58134
+ fn _gpu_fresnelC(x_in: f32) -> f32 {
58135
+ let sgn: f32 = select(1.0, -1.0, x_in < 0.0);
58136
+ let x = abs(x_in);
58137
+
58138
+ if (x < 1.6) {
58139
+ let x2 = x * x;
58140
+ let t = x2 * x2;
58141
+ var cn = array<f32, 12>(
58142
+ -4.98843114573573548651e-8, 9.50428062829859605134e-6,
58143
+ -6.45191435683965050962e-4, 1.88843319396703850064e-2,
58144
+ -2.05525900955013891793e-1, 9.99999999999999998822e-1,
58145
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
58146
+ );
58147
+ var cd = array<f32, 12>(
58148
+ 3.99982968972495980367e-12, 9.15439215774657478799e-10,
58149
+ 1.25001862479598821474e-7, 1.22262789024179030997e-5,
58150
+ 8.68029542941784300606e-4, 4.12142090722199792936e-2, 1.0,
58151
+ 0.0, 0.0, 0.0, 0.0, 0.0
58152
+ );
58153
+ return sgn * x * _gpu_polevl(t, cn, 6) / _gpu_polevl(t, cd, 7);
58154
+ }
58155
+
58156
+ if (x < 36.0) {
58157
+ let x2 = x * x;
58158
+ let t = 3.14159265358979 * x2;
58159
+ let u = 1.0 / (t * t);
58160
+ var fn = array<f32, 12>(
58161
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58162
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58163
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58164
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58165
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20,
58166
+ 0.0, 0.0
58167
+ );
58168
+ var fd = array<f32, 12>(
58169
+ 1.0, 7.51586398353378947175e-1,
58170
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58171
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58172
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58173
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58174
+ 1.25443237090011264384e-20, 0.0
58175
+ );
58176
+ var gn = array<f32, 12>(
58177
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58178
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58179
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58180
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58181
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58182
+ 1.86958710162783235106e-22, 0.0
58183
+ );
58184
+ var gd = array<f32, 12>(
58185
+ 1.0, 1.47495759925128324529,
58186
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58187
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58188
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58189
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58190
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58191
+ );
58192
+ let f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58193
+ let g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58194
+ let z = 1.5707963267948966 * x2;
58195
+ let c = cos(z);
58196
+ let s = sin(z);
58197
+ return sgn * (0.5 + (f * s - g * c) / (3.14159265358979 * x));
58198
+ }
58199
+
58200
+ return sgn * 0.5;
58201
+ }
58202
+ `;
58203
+ var GPU_FRESNELS_PREAMBLE_GLSL = `
58204
+ float _gpu_fresnelS(float x_in) {
58205
+ float sgn = x_in < 0.0 ? -1.0 : 1.0;
58206
+ float x = abs(x_in);
58207
+
58208
+ if (x < 1.6) {
58209
+ float x2 = x * x;
58210
+ float t = x2 * x2;
58211
+ float sn[6] = float[6](
58212
+ -2.99181919401019853726e3, 7.08840045257738576863e5,
58213
+ -6.29741486205862506537e7, 2.54890880573376359104e9,
58214
+ -4.42979518059697779103e10, 3.18016297876567817986e11
58215
+ );
58216
+ float sd[7] = float[7](
58217
+ 1.0, 2.81376268889994315696e2, 4.55847810806532581675e4,
58218
+ 5.1734388877009640073e6, 4.19320245898111231129e8, 2.2441179564534092094e10,
58219
+ 6.07366389490084914091e11
58220
+ );
58221
+ return sgn * x * x2 * _gpu_polevl(t, sn, 6) / _gpu_polevl(t, sd, 7);
58222
+ }
58223
+
58224
+ if (x < 36.0) {
58225
+ float x2 = x * x;
58226
+ float t = 3.14159265358979 * x2;
58227
+ float u = 1.0 / (t * t);
58228
+ float fn[10] = float[10](
58229
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58230
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58231
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58232
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58233
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20
58234
+ );
58235
+ float fd[11] = float[11](
58236
+ 1.0, 7.51586398353378947175e-1,
58237
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58238
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58239
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58240
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58241
+ 1.25443237090011264384e-20
58242
+ );
58243
+ float gn[11] = float[11](
58244
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58245
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58246
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58247
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58248
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58249
+ 1.86958710162783235106e-22
58250
+ );
58251
+ float gd[12] = float[12](
58252
+ 1.0, 1.47495759925128324529,
58253
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58254
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58255
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58256
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58257
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58258
+ );
58259
+ float f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58260
+ float g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58261
+ float z = 1.5707963267948966 * x2;
58262
+ float c = cos(z);
58263
+ float s = sin(z);
58264
+ return sgn * (0.5 - (f * c + g * s) / (3.14159265358979 * x));
58265
+ }
58266
+
58267
+ return sgn * 0.5;
58268
+ }
58269
+ `;
58270
+ var GPU_FRESNELS_PREAMBLE_WGSL = `
58271
+ fn _gpu_fresnelS(x_in: f32) -> f32 {
58272
+ let sgn: f32 = select(1.0, -1.0, x_in < 0.0);
58273
+ let x = abs(x_in);
58274
+
58275
+ if (x < 1.6) {
58276
+ let x2 = x * x;
58277
+ let t = x2 * x2;
58278
+ var sn = array<f32, 12>(
58279
+ -2.99181919401019853726e3, 7.08840045257738576863e5,
58280
+ -6.29741486205862506537e7, 2.54890880573376359104e9,
58281
+ -4.42979518059697779103e10, 3.18016297876567817986e11,
58282
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
58283
+ );
58284
+ var sd = array<f32, 12>(
58285
+ 1.0, 2.81376268889994315696e2, 4.55847810806532581675e4,
58286
+ 5.1734388877009640073e6, 4.19320245898111231129e8, 2.2441179564534092094e10,
58287
+ 6.07366389490084914091e11,
58288
+ 0.0, 0.0, 0.0, 0.0, 0.0
58289
+ );
58290
+ return sgn * x * x2 * _gpu_polevl(t, sn, 6) / _gpu_polevl(t, sd, 7);
58291
+ }
58292
+
58293
+ if (x < 36.0) {
58294
+ let x2 = x * x;
58295
+ let t = 3.14159265358979 * x2;
58296
+ let u = 1.0 / (t * t);
58297
+ var fn = array<f32, 12>(
58298
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58299
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58300
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58301
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58302
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20,
58303
+ 0.0, 0.0
58304
+ );
58305
+ var fd = array<f32, 12>(
58306
+ 1.0, 7.51586398353378947175e-1,
58307
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58308
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58309
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58310
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58311
+ 1.25443237090011264384e-20, 0.0
58312
+ );
58313
+ var gn = array<f32, 12>(
58314
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58315
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58316
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58317
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58318
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58319
+ 1.86958710162783235106e-22, 0.0
58320
+ );
58321
+ var gd = array<f32, 12>(
58322
+ 1.0, 1.47495759925128324529,
58323
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58324
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58325
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58326
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58327
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58328
+ );
58329
+ let f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58330
+ let g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58331
+ let z = 1.5707963267948966 * x2;
58332
+ let c = cos(z);
58333
+ let s = sin(z);
58334
+ return sgn * (0.5 - (f * c + g * s) / (3.14159265358979 * x));
58335
+ }
58336
+
58337
+ return sgn * 0.5;
58338
+ }
58339
+ `;
58340
+ var GPU_BESSELJ_PREAMBLE_GLSL = `
58341
+ float _gpu_factorial(int n) {
58342
+ float f = 1.0;
58343
+ for (int i = 2; i <= n; i++) f *= float(i);
58344
+ return f;
58345
+ }
58346
+
58347
+ float _gpu_besselJ_series(int n, float x) {
58348
+ float halfX = x / 2.0;
58349
+ float negQ = -(x * x) / 4.0;
58350
+ float term = 1.0;
58351
+ for (int i = 1; i <= n; i++) term /= float(i);
58352
+ float s = term;
58353
+ for (int k = 1; k <= 60; k++) {
58354
+ term *= negQ / (float(k) * float(n + k));
58355
+ s += term;
58356
+ if (abs(term) < abs(s) * 1e-7) break;
58357
+ }
58358
+ return s * pow(halfX, float(n));
58359
+ }
58360
+
58361
+ float _gpu_besselJ_asymptotic(int n, float x) {
58362
+ float mu = 4.0 * float(n) * float(n);
58363
+ float P = 1.0;
58364
+ float Q = 0.0;
58365
+ float ak = 1.0;
58366
+ float e8x = 8.0 * x;
58367
+ for (int k = 1; k <= 12; k++) {
58368
+ float twokm1 = float(2 * k - 1);
58369
+ ak *= mu - twokm1 * twokm1;
58370
+ float denom = _gpu_factorial(k) * pow(e8x, float(k));
58371
+ float contrib = ak / denom;
58372
+ if (k == 1 || k == 3 || k == 5 || k == 7 || k == 9 || k == 11) {
58373
+ // odd k: contributes to Q
58374
+ if (((k - 1) / 2) % 2 == 0) Q += contrib;
58375
+ else Q -= contrib;
58376
+ } else {
58377
+ // even k: contributes to P
58378
+ if ((k / 2) % 2 == 1) P -= contrib;
58379
+ else P += contrib;
58380
+ }
58381
+ if (abs(contrib) < 1e-7) break;
58382
+ }
58383
+ float chi = x - (float(n) / 2.0 + 0.25) * 3.14159265358979;
58384
+ return sqrt(2.0 / (3.14159265358979 * x)) * (P * cos(chi) - Q * sin(chi));
58385
+ }
58386
+
58387
+ float _gpu_besselJ(int n, float x) {
58388
+ if (x == 0.0) return n == 0 ? 1.0 : 0.0;
58389
+ float sgn = 1.0;
58390
+ if (n < 0) {
58391
+ n = -n;
58392
+ if (n % 2 != 0) sgn = -1.0;
58393
+ }
58394
+ if (x < 0.0) {
58395
+ x = -x;
58396
+ if (n % 2 != 0) sgn *= -1.0;
58397
+ }
58398
+ if (x > 25.0 + float(n * n) / 2.0) return sgn * _gpu_besselJ_asymptotic(n, x);
58399
+ if (x < 5.0 + float(n)) return sgn * _gpu_besselJ_series(n, x);
58400
+ // Miller's backward recurrence
58401
+ int M = max(n + 20, int(ceil(x)) + 30);
58402
+ if (M > 200) return sgn * _gpu_besselJ_series(n, x);
58403
+ float vals[201];
58404
+ float jp1 = 0.0;
58405
+ float jk = 1.0;
58406
+ vals[M] = jk;
58407
+ for (int k = M; k >= 1; k--) {
58408
+ float jm1 = (2.0 * float(k) / x) * jk - jp1;
58409
+ jp1 = jk;
58410
+ jk = jm1;
58411
+ vals[k - 1] = jk;
58412
+ }
58413
+ float norm = vals[0];
58414
+ for (int k = 2; k <= M; k += 2) norm += 2.0 * vals[k];
58415
+ return sgn * vals[n] / norm;
58416
+ }
58417
+ `;
58418
+ var GPU_BESSELJ_PREAMBLE_WGSL = `
58419
+ fn _gpu_factorial(n: i32) -> f32 {
58420
+ var f: f32 = 1.0;
58421
+ for (var i: i32 = 2; i <= n; i++) { f *= f32(i); }
58422
+ return f;
58423
+ }
58424
+
58425
+ fn _gpu_besselJ_series(n_in: i32, x: f32) -> f32 {
58426
+ let halfX = x / 2.0;
58427
+ let negQ = -(x * x) / 4.0;
58428
+ var term: f32 = 1.0;
58429
+ for (var i: i32 = 1; i <= n_in; i++) { term /= f32(i); }
58430
+ var s = term;
58431
+ for (var k: i32 = 1; k <= 60; k++) {
58432
+ term *= negQ / (f32(k) * f32(n_in + k));
58433
+ s += term;
58434
+ if (abs(term) < abs(s) * 1e-7) { break; }
58435
+ }
58436
+ return s * pow(halfX, f32(n_in));
58437
+ }
58438
+
58439
+ fn _gpu_besselJ_asymptotic(n_in: i32, x: f32) -> f32 {
58440
+ let mu = 4.0 * f32(n_in) * f32(n_in);
58441
+ var P: f32 = 1.0;
58442
+ var Q: f32 = 0.0;
58443
+ var ak: f32 = 1.0;
58444
+ let e8x = 8.0 * x;
58445
+ for (var k: i32 = 1; k <= 12; k++) {
58446
+ let twokm1 = f32(2 * k - 1);
58447
+ ak *= mu - twokm1 * twokm1;
58448
+ let denom = _gpu_factorial(k) * pow(e8x, f32(k));
58449
+ let contrib = ak / denom;
58450
+ if (k == 1 || k == 3 || k == 5 || k == 7 || k == 9 || k == 11) {
58451
+ if (((k - 1) / 2) % 2 == 0) { Q += contrib; }
58452
+ else { Q -= contrib; }
58453
+ } else {
58454
+ if ((k / 2) % 2 == 1) { P -= contrib; }
58455
+ else { P += contrib; }
58456
+ }
58457
+ if (abs(contrib) < 1e-7) { break; }
58458
+ }
58459
+ let chi = x - (f32(n_in) / 2.0 + 0.25) * 3.14159265358979;
58460
+ return sqrt(2.0 / (3.14159265358979 * x)) * (P * cos(chi) - Q * sin(chi));
58461
+ }
58462
+
58463
+ fn _gpu_besselJ(n_in: i32, x_in: f32) -> f32 {
58464
+ var n = n_in;
58465
+ var x = x_in;
58466
+ if (x == 0.0) { return select(0.0, 1.0, n == 0); }
58467
+ var sgn: f32 = 1.0;
58468
+ if (n < 0) {
58469
+ n = -n;
58470
+ if (n % 2 != 0) { sgn = -1.0; }
58471
+ }
58472
+ if (x < 0.0) {
58473
+ x = -x;
58474
+ if (n % 2 != 0) { sgn *= -1.0; }
58475
+ }
58476
+ if (x > 25.0 + f32(n * n) / 2.0) { return sgn * _gpu_besselJ_asymptotic(n, x); }
58477
+ if (x < 5.0 + f32(n)) { return sgn * _gpu_besselJ_series(n, x); }
58478
+ // Miller's backward recurrence
58479
+ var M = max(n + 20, i32(ceil(x)) + 30);
58480
+ if (M > 200) { return sgn * _gpu_besselJ_series(n, x); }
58481
+ var vals: array<f32, 201>;
58482
+ var jp1: f32 = 0.0;
58483
+ var jk: f32 = 1.0;
58484
+ vals[M] = jk;
58485
+ for (var k: i32 = M; k >= 1; k--) {
58486
+ let jm1 = (2.0 * f32(k) / x) * jk - jp1;
58487
+ jp1 = jk;
58488
+ jk = jm1;
58489
+ vals[k - 1] = jk;
58490
+ }
58491
+ var norm = vals[0];
58492
+ for (var k2: i32 = 2; k2 <= M; k2 += 2) { norm += 2.0 * vals[k2]; }
58493
+ return sgn * vals[n] / norm;
58494
+ }
57869
58495
  `;
57870
58496
  var GPU_FRACTAL_PREAMBLE_GLSL = `
57871
58497
  float _fractal_mandelbrot(vec2 c, int maxIter) {
@@ -58329,6 +58955,16 @@ fn _gpu_apca(bg: vec3f, fg: vec3f) -> f32 {
58329
58955
  indent: 0,
58330
58956
  ws: (s) => s ?? "",
58331
58957
  preamble: "",
58958
+ declare: (name, typeHint) => {
58959
+ const type2 = typeHint ?? (this.languageId === "wgsl" ? "f32" : "float");
58960
+ return this.languageId === "wgsl" ? `var ${name}: ${type2}` : `${type2} ${name}`;
58961
+ },
58962
+ block: (stmts) => {
58963
+ if (stmts.length === 0) return "";
58964
+ const last = stmts.length - 1;
58965
+ stmts[last] = `return ${stmts[last]}`;
58966
+ return stmts.join(";\n");
58967
+ },
58332
58968
  ...options
58333
58969
  };
58334
58970
  }
@@ -58363,6 +58999,18 @@ fn _gpu_apca(bg: vec3f, fg: vec3f) -> f32 {
58363
58999
  preamble += buildComplexPreamble(code, this.languageId);
58364
59000
  if (code.includes("_gpu_gamma")) preamble += GPU_GAMMA_PREAMBLE;
58365
59001
  if (code.includes("_gpu_erf")) preamble += GPU_ERF_PREAMBLE;
59002
+ if (code.includes("_gpu_heaviside"))
59003
+ preamble += this.languageId === "wgsl" ? GPU_HEAVISIDE_PREAMBLE_WGSL : GPU_HEAVISIDE_PREAMBLE_GLSL;
59004
+ if (code.includes("_gpu_sinc"))
59005
+ preamble += this.languageId === "wgsl" ? GPU_SINC_PREAMBLE_WGSL : GPU_SINC_PREAMBLE_GLSL;
59006
+ if (code.includes("_gpu_fresnel"))
59007
+ preamble += this.languageId === "wgsl" ? GPU_POLEVL_PREAMBLE_WGSL : GPU_POLEVL_PREAMBLE_GLSL;
59008
+ if (code.includes("_gpu_fresnelC"))
59009
+ preamble += this.languageId === "wgsl" ? GPU_FRESNELC_PREAMBLE_WGSL : GPU_FRESNELC_PREAMBLE_GLSL;
59010
+ if (code.includes("_gpu_fresnelS"))
59011
+ preamble += this.languageId === "wgsl" ? GPU_FRESNELS_PREAMBLE_WGSL : GPU_FRESNELS_PREAMBLE_GLSL;
59012
+ if (code.includes("_gpu_besselJ"))
59013
+ preamble += this.languageId === "wgsl" ? GPU_BESSELJ_PREAMBLE_WGSL : GPU_BESSELJ_PREAMBLE_GLSL;
58366
59014
  if (code.includes("_fractal_")) {
58367
59015
  preamble += this.languageId === "wgsl" ? GPU_FRACTAL_PREAMBLE_WGSL : GPU_FRACTAL_PREAMBLE_GLSL;
58368
59016
  }
@@ -58411,6 +59059,12 @@ fn _gpu_apca(bg: vec3f, fg: vec3f) -> f32 {
58411
59059
  const target = this.createTarget();
58412
59060
  const body = BaseCompiler.compile(expr, target);
58413
59061
  const params = parameters.map(([name, type2]) => `${type2} ${name}`).join(", ");
59062
+ if (body.includes("\n")) {
59063
+ const indented = body.split("\n").map((l) => ` ${l}`).join("\n");
59064
+ return `${returnType} ${functionName}(${params}) {
59065
+ ${indented};
59066
+ }`;
59067
+ }
58414
59068
  return `${returnType} ${functionName}(${params}) {
58415
59069
  return ${body};
58416
59070
  }`;
@@ -58514,6 +59168,12 @@ fn _gpu_apca(bg: vec3f, fg: vec3f) -> f32 {
58514
59168
  const target = this.createTarget();
58515
59169
  const body = BaseCompiler.compile(expr, target);
58516
59170
  const params = parameters.map(([name, type2]) => `${name}: ${toWGSLType(type2)}`).join(", ");
59171
+ if (body.includes("\n")) {
59172
+ const indented = body.split("\n").map((l) => ` ${l}`).join("\n");
59173
+ return `fn ${functionName}(${params}) -> ${toWGSLType(returnType)} {
59174
+ ${indented};
59175
+ }`;
59176
+ }
58517
59177
  return `fn ${functionName}(${params}) -> ${toWGSLType(returnType)} {
58518
59178
  return ${body};
58519
59179
  }`;
@@ -67381,10 +68041,10 @@ ${code}`;
67381
68041
  _setComputeEngineClass(ComputeEngine);
67382
68042
 
67383
68043
  // src/compute-engine.ts
67384
- var version = "0.53.0";
68044
+ var version = "0.53.1";
67385
68045
  globalThis[/* @__PURE__ */ Symbol.for("io.cortexjs.compute-engine")] = {
67386
68046
  ComputeEngine: ComputeEngine.prototype.constructor,
67387
- version: "0.53.0"
68047
+ version: "0.53.1"
67388
68048
  };
67389
68049
  return __toCommonJS(compute_engine_exports);
67390
68050
  })();