@cortex-js/compute-engine 0.55.5 → 0.55.6

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 (258) hide show
  1. package/dist/compile.esm.js +138 -633
  2. package/dist/compile.min.esm.js +71 -493
  3. package/dist/compile.min.umd.cjs +71 -493
  4. package/dist/compile.umd.cjs +138 -633
  5. package/dist/compute-engine.esm.js +227 -651
  6. package/dist/compute-engine.min.esm.js +68 -489
  7. package/dist/compute-engine.min.umd.cjs +68 -489
  8. package/dist/compute-engine.umd.cjs +227 -651
  9. package/dist/core.esm.js +226 -650
  10. package/dist/core.min.esm.js +66 -487
  11. package/dist/core.min.umd.cjs +67 -488
  12. package/dist/core.umd.cjs +226 -650
  13. package/dist/interval.esm.js +136 -60
  14. package/dist/interval.min.esm.js +7 -7
  15. package/dist/interval.min.umd.cjs +7 -7
  16. package/dist/interval.umd.cjs +136 -60
  17. package/dist/latex-syntax.esm.js +219 -74
  18. package/dist/latex-syntax.min.esm.js +7 -6
  19. package/dist/latex-syntax.min.umd.cjs +7 -6
  20. package/dist/latex-syntax.umd.cjs +219 -74
  21. package/dist/math-json.esm.js +2 -2
  22. package/dist/math-json.min.esm.js +2 -2
  23. package/dist/math-json.min.umd.cjs +2 -2
  24. package/dist/math-json.umd.cjs +2 -2
  25. package/dist/numerics.esm.js +2 -2
  26. package/dist/numerics.min.esm.js +2 -2
  27. package/dist/numerics.min.umd.cjs +2 -2
  28. package/dist/numerics.umd.cjs +2 -2
  29. package/dist/types/big-decimal/big-decimal.d.ts +1 -1
  30. package/dist/types/big-decimal/index.d.ts +1 -1
  31. package/dist/types/big-decimal/transcendentals.d.ts +1 -1
  32. package/dist/types/big-decimal/utils.d.ts +1 -1
  33. package/dist/types/common/ansi-codes.d.ts +1 -1
  34. package/dist/types/common/configuration-change.d.ts +1 -1
  35. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  36. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  37. package/dist/types/common/interruptible.d.ts +1 -1
  38. package/dist/types/common/one-of.d.ts +1 -1
  39. package/dist/types/common/signals.d.ts +1 -1
  40. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  41. package/dist/types/common/type/boxed-type.d.ts +1 -1
  42. package/dist/types/common/type/lexer.d.ts +1 -1
  43. package/dist/types/common/type/parse.d.ts +1 -1
  44. package/dist/types/common/type/parser.d.ts +1 -1
  45. package/dist/types/common/type/primitive.d.ts +1 -1
  46. package/dist/types/common/type/reduce.d.ts +1 -1
  47. package/dist/types/common/type/serialize.d.ts +1 -1
  48. package/dist/types/common/type/subtype.d.ts +1 -1
  49. package/dist/types/common/type/type-builder.d.ts +1 -1
  50. package/dist/types/common/type/types.d.ts +1 -1
  51. package/dist/types/common/type/utils.d.ts +1 -1
  52. package/dist/types/common/utils.d.ts +1 -1
  53. package/dist/types/compile.d.ts +1 -1
  54. package/dist/types/compute-engine/assume.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  82. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  87. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  88. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  89. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  90. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  91. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  92. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  93. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  94. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  95. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  96. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  97. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  98. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  99. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  100. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  101. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  102. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  103. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  104. package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
  105. package/dist/types/compute-engine/compilation/compile-expression.d.ts +2 -3
  106. package/dist/types/compute-engine/compilation/constant-folding.d.ts +1 -1
  107. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  108. package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -54
  109. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  110. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  111. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  112. package/dist/types/compute-engine/compilation/types.d.ts +1 -67
  113. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  114. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  115. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  116. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  117. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  118. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  119. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  120. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  121. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  122. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  123. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  124. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  125. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  126. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  127. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  128. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  129. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  130. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  131. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  132. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  133. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  134. package/dist/types/compute-engine/global-types.d.ts +1 -1
  135. package/dist/types/compute-engine/index.d.ts +2 -2
  136. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  137. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  138. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  139. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  140. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  141. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  142. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  143. package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
  144. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  145. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  146. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  147. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  148. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  149. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  150. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  151. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  152. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  153. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  154. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  155. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  156. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  157. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  158. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  159. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  160. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  161. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  162. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  163. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  164. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
  165. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  166. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  167. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +4 -2
  168. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  169. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  170. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  171. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  172. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  173. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  174. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  175. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  176. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  177. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  178. package/dist/types/compute-engine/library/core.d.ts +1 -1
  179. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  180. package/dist/types/compute-engine/library/library.d.ts +1 -1
  181. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  182. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  183. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  184. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  185. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  186. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  187. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  188. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  189. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  190. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  191. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  192. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  193. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  194. package/dist/types/compute-engine/library/units.d.ts +1 -1
  195. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  196. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  197. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  198. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  199. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  200. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  201. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  202. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  203. package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
  204. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  205. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  206. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  207. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  208. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  209. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  210. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  211. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  212. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  213. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  214. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  215. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  216. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  217. package/dist/types/compute-engine/oeis.d.ts +1 -1
  218. package/dist/types/compute-engine/sequence.d.ts +1 -1
  219. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  220. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  221. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  222. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  223. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  224. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  225. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  226. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  227. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  228. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  229. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  230. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  231. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  232. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  233. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  234. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  235. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  236. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  237. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  238. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  239. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  240. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  241. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  242. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  243. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  244. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  245. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  246. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  247. package/dist/types/compute-engine/types.d.ts +1 -1
  248. package/dist/types/compute-engine.d.ts +2 -2
  249. package/dist/types/core.d.ts +1 -1
  250. package/dist/types/interval.d.ts +1 -1
  251. package/dist/types/latex-syntax.d.ts +2 -2
  252. package/dist/types/math-json/symbols.d.ts +1 -1
  253. package/dist/types/math-json/types.d.ts +1 -1
  254. package/dist/types/math-json/utils.d.ts +1 -1
  255. package/dist/types/math-json.d.ts +2 -2
  256. package/dist/types/numerics.d.ts +1 -1
  257. package/package.json +1 -1
  258. package/dist/types/compute-engine/compilation/fractal-orbit.d.ts +0 -19
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.55.5 */
1
+ /** Compute Engine 0.55.6 */
2
2
 
3
3
  // src/compute-engine/numerics/richardson.ts
4
4
  function extrapolate(f, x0, options = {}) {
@@ -6240,10 +6240,6 @@ var DEFINITIONS_CORE = [
6240
6240
  // Lagrange notation
6241
6241
  {
6242
6242
  name: "Derivative",
6243
- // @todo: Leibniz notation: {% latex " \\frac{d^n}{dx^n} f(x)" %}
6244
- // @todo: Euler modified notation: This notation is used by Mathematica. The Euler notation uses `D` instead of
6245
- // `\partial`: `\partial_{x} f`, `\partial_{x,y} f`
6246
- // Newton notation (\dot{v}, \ddot{v}) is implemented below
6247
6243
  serialize: (serializer, expr) => {
6248
6244
  const degree = machineValue(operand(expr, 2)) ?? 1;
6249
6245
  const base = serializer.serialize(operand(expr, 1));
@@ -7281,14 +7277,18 @@ var DEFINITIONS_SETS = [
7281
7277
  return ["Complement", lhs];
7282
7278
  }
7283
7279
  // precedence: 240,
7284
- // @todo: serialize for the multiple argument case
7285
7280
  },
7286
7281
  {
7287
7282
  name: "Complement",
7288
7283
  latexTrigger: ["^", "<{>", "\\complement", "<}>"],
7289
- kind: "postfix"
7284
+ kind: "postfix",
7290
7285
  // precedence: 240,
7291
- // @todo: serialize for the multiple argument case
7286
+ serialize: (serializer, expr) => {
7287
+ return joinLatex([
7288
+ serializer.serialize(operand(expr, 1)),
7289
+ "^\\complement"
7290
+ ]);
7291
+ }
7292
7292
  },
7293
7293
  {
7294
7294
  name: "Intersection",
@@ -7375,7 +7375,6 @@ var DEFINITIONS_SETS = [
7375
7375
  // commands like \rbrack a, b \rbrack which are unambiguous.
7376
7376
  {
7377
7377
  name: "Multiple",
7378
- // @todo: parse
7379
7378
  serialize: serializeSet
7380
7379
  },
7381
7380
  {
@@ -7384,14 +7383,28 @@ var DEFINITIONS_SETS = [
7384
7383
  kind: "infix",
7385
7384
  precedence: 350
7386
7385
  },
7386
+ // \mid as a separator/operator (used in set-builder notation: {x \mid x > 0})
7387
+ // Low precedence so it binds loosely — everything on each side is parsed first
7388
+ {
7389
+ name: "Divides",
7390
+ latexTrigger: ["\\mid"],
7391
+ kind: "infix",
7392
+ precedence: 160
7393
+ },
7387
7394
  {
7388
7395
  name: "Set",
7389
7396
  kind: "matchfix",
7390
7397
  openTrigger: "{",
7391
7398
  closeTrigger: "}",
7392
- // @todo: the set syntax can also include conditions...
7393
7399
  parse: (_parser, body) => {
7394
7400
  if (isEmptySequence(body)) return "EmptySet";
7401
+ const h = operator(body);
7402
+ if (h === "Divides" || h === "Colon") {
7403
+ const expr = operand(body, 1);
7404
+ const condition = operand(body, 2);
7405
+ if (expr !== null && condition !== null)
7406
+ return ["Set", expr, ["Condition", condition]];
7407
+ }
7395
7408
  if (operator(body) == "Delimiter" && stringValue(operand(body, 2)) === ",") {
7396
7409
  body = operand(body, 1);
7397
7410
  }
@@ -7399,6 +7412,17 @@ var DEFINITIONS_SETS = [
7399
7412
  return ["Set", ...operands(body)];
7400
7413
  },
7401
7414
  serialize: (serializer, expr) => {
7415
+ if (nops(expr) === 2 && operator(operand(expr, 2)) === "Condition") {
7416
+ const condition = operand(expr, 2);
7417
+ return joinLatex([
7418
+ "\\lbrace",
7419
+ serializer.serialize(operand(expr, 1)),
7420
+ "\\mid",
7421
+ // Serialize the inner expression of the Condition wrapper
7422
+ serializer.serialize(operand(condition, 1)),
7423
+ "\\rbrace"
7424
+ ]);
7425
+ }
7402
7426
  return joinLatex([
7403
7427
  "\\lbrace",
7404
7428
  operands(expr).map((x) => serializer.serialize(x)).join(", "),
@@ -7565,23 +7589,6 @@ function serializeSet(serializer, expr) {
7565
7589
  if (expr === null) return "";
7566
7590
  const h = operator(expr);
7567
7591
  if (!h) return "";
7568
- if (h === "Set") {
7569
- if (nops(expr) === 0) return "\\emptyset";
7570
- if (nops(expr) === 2 && operator(operand(expr, 2)) === "Condition") {
7571
- return joinLatex([
7572
- "\\left\\lbrace",
7573
- serializer.serialize(operand(expr, 1)),
7574
- "\\middle\\mid",
7575
- serializer.serialize(operand(expr, 2)),
7576
- "\\right\\rbrace"
7577
- ]);
7578
- }
7579
- return joinLatex([
7580
- "\\left\\lbrace",
7581
- ...operands(expr).map((x) => serializer.serialize(x) + " ,"),
7582
- "\\right\\rbrace"
7583
- ]);
7584
- }
7585
7592
  if (h === "Multiple") {
7586
7593
  }
7587
7594
  if (h === "Range") {
@@ -8699,11 +8706,13 @@ var DEFINITIONS_ARITHMETIC = [
8699
8706
  if (!parser.match("_")) return null;
8700
8707
  const base = parser.parseGroup();
8701
8708
  if (operator(base) !== "To") return null;
8702
- const expr = parser.parseArguments("implicit");
8709
+ const expr = parser.parseExpression({
8710
+ minPrec: MULTIPLICATION_PRECEDENCE
8711
+ });
8703
8712
  if (!expr) return null;
8704
8713
  return [
8705
8714
  "Limit",
8706
- ["Function", expr[0], operand(base, 1)],
8715
+ ["Function", expr, operand(base, 1)],
8707
8716
  operand(base, 2)
8708
8717
  ];
8709
8718
  },
@@ -10907,12 +10916,52 @@ var DEFINITIONS_UNITS = [
10907
10916
  ];
10908
10917
 
10909
10918
  // src/compute-engine/latex-syntax/dictionary/definitions-other.ts
10919
+ var TEX_UNITS = [
10920
+ "pt",
10921
+ "em",
10922
+ "mu",
10923
+ "ex",
10924
+ "mm",
10925
+ "cm",
10926
+ "in",
10927
+ "bp",
10928
+ "sp",
10929
+ "dd",
10930
+ "cc",
10931
+ "pc",
10932
+ "nc",
10933
+ "nd"
10934
+ ];
10935
+ function skipTexDimension(parser) {
10936
+ parser.skipSpace();
10937
+ if (parser.peek === "-" || parser.peek === "+") parser.nextToken();
10938
+ while (/^[\d.]$/.test(parser.peek)) parser.nextToken();
10939
+ for (const unit of TEX_UNITS) {
10940
+ if (parser.matchAll([...unit])) return;
10941
+ }
10942
+ }
10910
10943
  function parseSingleArg(cmd) {
10911
10944
  return (parser) => {
10912
10945
  const arg = parser.parseGroup();
10913
10946
  return arg === null ? [cmd] : [cmd, arg];
10914
10947
  };
10915
10948
  }
10949
+ function parseMathStyleSwitch(mathStyle) {
10950
+ return (parser) => {
10951
+ const body = parser.parseExpression();
10952
+ if (body !== null && !isEmptySequence(body))
10953
+ return ["Annotated", body, { dict: { mathStyle } }];
10954
+ return "Nothing";
10955
+ };
10956
+ }
10957
+ function parseSizeSwitch(size) {
10958
+ return (parser) => {
10959
+ const body = parser.parseExpression();
10960
+ if (body !== null && !isEmptySequence(body))
10961
+ return ["Annotated", body, { dict: { size } }];
10962
+ return "Nothing";
10963
+ };
10964
+ }
10916
10965
  var DEFINITIONS_OTHERS = [
10917
10966
  {
10918
10967
  name: "Overscript",
@@ -11152,80 +11201,71 @@ var DEFINITIONS_OTHERS = [
11152
11201
  },
11153
11202
  {
11154
11203
  latexTrigger: ["\\displaystyle"],
11155
- parse: () => "Nothing"
11156
- // @todo: parse as ['Annotated'...]
11204
+ parse: parseMathStyleSwitch("normal")
11157
11205
  },
11158
11206
  {
11159
11207
  latexTrigger: ["\\textstyle"],
11160
- parse: () => "Nothing"
11161
- // @todo: parse as ['Annotated'...]
11208
+ parse: parseMathStyleSwitch("compact")
11162
11209
  },
11163
11210
  {
11164
11211
  latexTrigger: ["\\scriptstyle"],
11165
- parse: () => "Nothing"
11166
- // @todo: parse as ['Annotated'...]
11212
+ parse: parseMathStyleSwitch("script")
11167
11213
  },
11168
11214
  {
11169
11215
  latexTrigger: ["\\scriptscriptstyle"],
11170
- parse: () => "Nothing"
11171
- // @todo: parse as ['Annotated'...]
11216
+ parse: parseMathStyleSwitch("scriptscript")
11172
11217
  },
11173
11218
  {
11174
11219
  latexTrigger: ["\\color"],
11175
11220
  parse: (parser) => {
11176
- parser.parseGroup();
11221
+ const color = parser.parseStringGroup();
11222
+ if (color !== null) {
11223
+ const body = parser.parseExpression();
11224
+ if (body !== null && !isEmptySequence(body))
11225
+ return ["Annotated", body, { dict: { color } }];
11226
+ }
11177
11227
  return "Nothing";
11178
11228
  }
11179
11229
  },
11180
11230
  {
11181
11231
  latexTrigger: ["\\tiny"],
11182
- parse: () => "Nothing"
11183
- // @todo: parse as ['Annotated'...]
11232
+ parse: parseSizeSwitch(1)
11184
11233
  },
11185
11234
  {
11186
11235
  latexTrigger: ["\\scriptsize"],
11187
- parse: () => "Nothing"
11188
- // @todo: parse as ['Annotated'...]
11236
+ parse: parseSizeSwitch(2)
11189
11237
  },
11190
11238
  {
11191
11239
  latexTrigger: ["\\footnotesize"],
11192
- parse: () => "Nothing"
11193
- // @todo: parse as ['Annotated'...]
11240
+ parse: parseSizeSwitch(3)
11194
11241
  },
11195
11242
  {
11196
11243
  latexTrigger: ["\\small"],
11197
- parse: () => "Nothing"
11198
- // @todo: parse as ['Annotated'...]
11244
+ parse: parseSizeSwitch(4)
11199
11245
  },
11200
11246
  {
11201
11247
  latexTrigger: ["\\normalsize"],
11202
- parse: () => "Nothing"
11203
- // @todo: parse as ['Annotated'...]
11248
+ parse: parseSizeSwitch(5)
11204
11249
  },
11205
11250
  {
11206
11251
  latexTrigger: ["\\large"],
11207
- parse: () => "Nothing"
11208
- // @todo: parse as ['Annotated'...]
11252
+ parse: parseSizeSwitch(6)
11209
11253
  },
11210
11254
  {
11211
11255
  latexTrigger: ["\\Large"],
11212
- parse: () => "Nothing"
11213
- // @todo: parse as ['Annotated'...]
11256
+ parse: parseSizeSwitch(7)
11214
11257
  },
11215
11258
  {
11216
11259
  latexTrigger: ["\\LARGE"],
11217
- parse: () => "Nothing"
11218
- // @todo: parse as ['Annotated'...]
11260
+ parse: parseSizeSwitch(8)
11219
11261
  },
11220
11262
  {
11221
11263
  latexTrigger: ["\\huge"],
11222
- parse: () => "Nothing"
11223
- // @todo: parse as ['Annotated'...]
11264
+ parse: parseSizeSwitch(9)
11224
11265
  },
11225
11266
  {
11226
11267
  latexTrigger: ["\\Huge"],
11227
- parse: () => "Nothing"
11228
- // @todo: parse as ['Annotated'...]
11268
+ parse: parseSizeSwitch(10)
11229
11269
  },
11230
11270
  {
11231
11271
  name: "Annotated",
@@ -11237,6 +11277,10 @@ var DEFINITIONS_OTHERS = [
11237
11277
  result = joinLatex(["{\\displaystyle", result, "}"]);
11238
11278
  else if (dict.dict.mathStyle === "compact")
11239
11279
  result = joinLatex(["{\\textstyle", result, "}"]);
11280
+ else if (dict.dict.mathStyle === "script")
11281
+ result = joinLatex(["{\\scriptstyle", result, "}"]);
11282
+ else if (dict.dict.mathStyle === "scriptscript")
11283
+ result = joinLatex(["{\\scriptscriptstyle", result, "}"]);
11240
11284
  const v = dict.dict.size;
11241
11285
  if (v !== null && v >= 1 && v <= 10) {
11242
11286
  result = joinLatex([
@@ -11324,6 +11368,28 @@ var DEFINITIONS_OTHERS = [
11324
11368
  latexTrigger: ["\\enspace"],
11325
11369
  parse: () => ["HorizontalSpacing", 9]
11326
11370
  },
11371
+ {
11372
+ latexTrigger: ["\\hspace"],
11373
+ parse: (parser) => {
11374
+ if (parser.peek === "*") parser.nextToken();
11375
+ parser.parseStringGroup();
11376
+ return ["HorizontalSpacing", 0];
11377
+ }
11378
+ },
11379
+ {
11380
+ latexTrigger: ["\\hskip"],
11381
+ parse: (parser) => {
11382
+ skipTexDimension(parser);
11383
+ return ["HorizontalSpacing", 0];
11384
+ }
11385
+ },
11386
+ {
11387
+ latexTrigger: ["\\kern"],
11388
+ parse: (parser) => {
11389
+ skipTexDimension(parser);
11390
+ return ["HorizontalSpacing", 0];
11391
+ }
11392
+ },
11327
11393
  {
11328
11394
  latexTrigger: ["\\phantom"],
11329
11395
  parse: (parser) => {
@@ -11374,7 +11440,17 @@ var DEFINITIONS_OTHERS = [
11374
11440
  // `["HorizontalSpacing", expr, 'op'|'bin'|rel]` -> indicate a spacing around and expression, i.e. `\mathbin{x}`, etc...
11375
11441
  serialize: (serializer, expr) => {
11376
11442
  if (operand(expr, 2) !== null) {
11377
- return serializer.serialize(operand(expr, 1));
11443
+ const cls = stringValue(operand(expr, 2));
11444
+ const inner = serializer.serialize(operand(expr, 1));
11445
+ if (cls === "bin") return `\\mathbin{${inner}}`;
11446
+ if (cls === "op") return `\\mathop{${inner}}`;
11447
+ if (cls === "rel") return `\\mathrel{${inner}}`;
11448
+ if (cls === "ord") return `\\mathord{${inner}}`;
11449
+ if (cls === "open") return `\\mathopen{${inner}}`;
11450
+ if (cls === "close") return `\\mathclose{${inner}}`;
11451
+ if (cls === "punct") return `\\mathpunct{${inner}}`;
11452
+ if (cls === "inner") return `\\mathinner{${inner}}`;
11453
+ return inner;
11378
11454
  }
11379
11455
  const v = machineValue(operand(expr, 1));
11380
11456
  if (v === null) return "";
@@ -15066,8 +15142,7 @@ function compile(expr, options) {
15066
15142
  vars: options?.vars,
15067
15143
  imports: options?.imports,
15068
15144
  preamble: options?.preamble,
15069
- realOnly: options?.realOnly,
15070
- hints: options?.hints
15145
+ realOnly: options?.realOnly
15071
15146
  });
15072
15147
  } catch (e) {
15073
15148
  if (options?.fallback ?? true) {
@@ -20749,43 +20824,6 @@ function fibonacci(n) {
20749
20824
  return b;
20750
20825
  }
20751
20826
 
20752
- // src/compute-engine/compilation/fractal-orbit.ts
20753
- function toBigDecimal(v) {
20754
- if (typeof v === "object" && "hi" in v)
20755
- return new BigDecimal(v.hi).add(new BigDecimal(v.lo));
20756
- return new BigDecimal(v);
20757
- }
20758
- function hpToNumber(v) {
20759
- if (typeof v === "number") return v;
20760
- if (typeof v === "string") return Number(v);
20761
- return v.hi + v.lo;
20762
- }
20763
- function computeReferenceOrbit(center, maxIter, precision) {
20764
- const prevPrecision = BigDecimal.precision;
20765
- BigDecimal.precision = precision;
20766
- try {
20767
- const cr = toBigDecimal(center[0]);
20768
- const ci = toBigDecimal(center[1]);
20769
- let zr = BigDecimal.ZERO;
20770
- let zi = BigDecimal.ZERO;
20771
- const ESCAPE = new BigDecimal(256);
20772
- const points = [];
20773
- for (let i = 0; i < maxIter; i++) {
20774
- points.push(zr.toNumber(), zi.toNumber());
20775
- const zr2 = zr.mul(zr).toPrecision(precision);
20776
- const zi2 = zi.mul(zi).toPrecision(precision);
20777
- const mag2 = zr2.add(zi2);
20778
- if (mag2.cmp(ESCAPE) > 0) break;
20779
- const new_zi = zr.mul(zi).toPrecision(precision).mul(2).add(ci);
20780
- zr = zr2.sub(zi2).add(cr);
20781
- zi = new_zi;
20782
- }
20783
- return new Float32Array(points);
20784
- } finally {
20785
- BigDecimal.precision = prevPrecision;
20786
- }
20787
- }
20788
-
20789
20827
  // src/compute-engine/compilation/gpu-target.ts
20790
20828
  var GPU_OPERATORS = {
20791
20829
  Add: ["+", 11],
@@ -20869,13 +20907,6 @@ function compileGPUSumProduct(kind, args, _compile, target) {
20869
20907
  ];
20870
20908
  return lines.join("\n");
20871
20909
  }
20872
- function selectFractalStrategy(target) {
20873
- const radius = target.hints?.viewport?.radius;
20874
- if (radius === void 0) return "single";
20875
- if (radius > 1e-6) return "single";
20876
- if (radius > 1e-14) return "double";
20877
- return "perturbation";
20878
- }
20879
20910
  var GPU_FUNCTIONS = {
20880
20911
  // Variadic arithmetic (for function-call form, e.g., with vectors)
20881
20912
  Add: (args, compile2, target) => {
@@ -21371,32 +21402,12 @@ var GPU_FUNCTIONS = {
21371
21402
  if (c === null || maxIter === null)
21372
21403
  throw new Error("Mandelbrot: missing arguments");
21373
21404
  const iterCode = compileIntArg(maxIter, compile2, target);
21374
- const strategy = selectFractalStrategy(target);
21375
- if (strategy === "double") {
21376
- const dpCoord = target?.language === "wgsl" ? "_dp_coord(v_uv)" : "_dp_coord()";
21377
- return `_fractal_mandelbrot_dp(${dpCoord}, ${iterCode})`;
21378
- }
21379
- if (strategy === "perturbation") {
21380
- const ptDelta = target?.language === "wgsl" ? "_pt_delta(v_uv)" : "_pt_delta()";
21381
- return `_fractal_mandelbrot_pt(${ptDelta}, ${iterCode})`;
21382
- }
21383
21405
  return `_fractal_mandelbrot(${compile2(c)}, ${iterCode})`;
21384
21406
  },
21385
21407
  Julia: ([z, c, maxIter], compile2, target) => {
21386
21408
  if (z === null || c === null || maxIter === null)
21387
21409
  throw new Error("Julia: missing arguments");
21388
21410
  const iterCode = compileIntArg(maxIter, compile2, target);
21389
- const strategy = selectFractalStrategy(target);
21390
- if (strategy === "double") {
21391
- const dpCoord = target?.language === "wgsl" ? "_dp_coord(v_uv)" : "_dp_coord()";
21392
- const cCode = compile2(c);
21393
- return `_fractal_julia_dp(${dpCoord}, vec4(${cCode}, vec2(0.0)), ${iterCode})`;
21394
- }
21395
- if (strategy === "perturbation") {
21396
- const ptDelta = target?.language === "wgsl" ? "_pt_delta(v_uv)" : "_pt_delta()";
21397
- const cCode = compile2(c);
21398
- return `_fractal_julia_pt(${ptDelta}, ${cCode}, ${iterCode})`;
21399
- }
21400
21411
  return `_fractal_julia(${compile2(z)}, ${compile2(c)}, ${iterCode})`;
21401
21412
  },
21402
21413
  // Vector/Matrix operations
@@ -21994,232 +22005,6 @@ fn _gpu_besselJ(n_in: i32, x_in: f32) -> f32 {
21994
22005
  return sgn * vals[n] / norm;
21995
22006
  }
21996
22007
  `;
21997
- var GPU_DS_ARITHMETIC_PREAMBLE_GLSL = `
21998
- // Split a float into high and low parts for exact multiplication
21999
- vec2 ds_split(float a) {
22000
- const float SPLIT = 4097.0; // 2^12 + 1
22001
- float t = SPLIT * a;
22002
- float hi = t - (t - a);
22003
- float lo = a - hi;
22004
- return vec2(hi, lo);
22005
- }
22006
-
22007
- // Create a double-single from a single float
22008
- vec2 ds_from(float a) {
22009
- return vec2(a, 0.0);
22010
- }
22011
-
22012
- // Error-free addition (Knuth TwoSum)
22013
- vec2 ds_add(vec2 a, vec2 b) {
22014
- float s = a.x + b.x;
22015
- float v = s - a.x;
22016
- float e = (a.x - (s - v)) + (b.x - v);
22017
- float lo = (a.y + b.y) + e;
22018
- float hi = s + lo;
22019
- lo = lo - (hi - s);
22020
- return vec2(hi, lo);
22021
- }
22022
-
22023
- // Double-single subtraction
22024
- vec2 ds_sub(vec2 a, vec2 b) {
22025
- return ds_add(a, vec2(-b.x, -b.y));
22026
- }
22027
-
22028
- // Error-free multiplication (Dekker TwoProduct)
22029
- vec2 ds_mul(vec2 a, vec2 b) {
22030
- float p = a.x * b.x;
22031
- vec2 sa = ds_split(a.x);
22032
- vec2 sb = ds_split(b.x);
22033
- float err = ((sa.x * sb.x - p) + sa.x * sb.y + sa.y * sb.x) + sa.y * sb.y;
22034
- err += a.x * b.y + a.y * b.x;
22035
- float hi = p + err;
22036
- float lo = err - (hi - p);
22037
- return vec2(hi, lo);
22038
- }
22039
-
22040
- // Optimized self-multiply
22041
- vec2 ds_sqr(vec2 a) {
22042
- float p = a.x * a.x;
22043
- vec2 sa = ds_split(a.x);
22044
- float err = ((sa.x * sa.x - p) + 2.0 * sa.x * sa.y) + sa.y * sa.y;
22045
- err += 2.0 * a.x * a.y;
22046
- float hi = p + err;
22047
- float lo = err - (hi - p);
22048
- return vec2(hi, lo);
22049
- }
22050
-
22051
- // Compare magnitude: returns -1, 0, or 1
22052
- float ds_cmp(vec2 a, vec2 b) {
22053
- float d = a.x - b.x;
22054
- if (d != 0.0) return sign(d);
22055
- return sign(a.y - b.y);
22056
- }
22057
- `;
22058
- var GPU_DS_ARITHMETIC_PREAMBLE_WGSL = `
22059
- fn ds_split(a: f32) -> vec2f {
22060
- const SPLIT: f32 = 4097.0;
22061
- let t = SPLIT * a;
22062
- let hi = t - (t - a);
22063
- let lo = a - hi;
22064
- return vec2f(hi, lo);
22065
- }
22066
-
22067
- fn ds_from(a: f32) -> vec2f {
22068
- return vec2f(a, 0.0);
22069
- }
22070
-
22071
- fn ds_add(a: vec2f, b: vec2f) -> vec2f {
22072
- let s = a.x + b.x;
22073
- let v = s - a.x;
22074
- let e = (a.x - (s - v)) + (b.x - v);
22075
- let lo_t = (a.y + b.y) + e;
22076
- let hi = s + lo_t;
22077
- let lo = lo_t - (hi - s);
22078
- return vec2f(hi, lo);
22079
- }
22080
-
22081
- fn ds_sub(a: vec2f, b: vec2f) -> vec2f {
22082
- return ds_add(a, vec2f(-b.x, -b.y));
22083
- }
22084
-
22085
- fn ds_mul(a: vec2f, b: vec2f) -> vec2f {
22086
- let p = a.x * b.x;
22087
- let sa = ds_split(a.x);
22088
- let sb = ds_split(b.x);
22089
- var err = ((sa.x * sb.x - p) + sa.x * sb.y + sa.y * sb.x) + sa.y * sb.y;
22090
- err += a.x * b.y + a.y * b.x;
22091
- let hi = p + err;
22092
- let lo = err - (hi - p);
22093
- return vec2f(hi, lo);
22094
- }
22095
-
22096
- fn ds_sqr(a: vec2f) -> vec2f {
22097
- let p = a.x * a.x;
22098
- let sa = ds_split(a.x);
22099
- var err = ((sa.x * sa.x - p) + 2.0 * sa.x * sa.y) + sa.y * sa.y;
22100
- err += 2.0 * a.x * a.y;
22101
- let hi = p + err;
22102
- let lo = err - (hi - p);
22103
- return vec2f(hi, lo);
22104
- }
22105
-
22106
- fn ds_cmp(a: vec2f, b: vec2f) -> f32 {
22107
- let d = a.x - b.x;
22108
- if (d != 0.0) { return sign(d); }
22109
- return sign(a.y - b.y);
22110
- }
22111
- `;
22112
- var GPU_FRACTAL_DP_PREAMBLE_GLSL = `
22113
- uniform float _dp_cx_hi;
22114
- uniform float _dp_cx_lo;
22115
- uniform float _dp_cy_hi;
22116
- uniform float _dp_cy_lo;
22117
- uniform float _dp_w;
22118
- uniform float _dp_h;
22119
-
22120
- vec4 _dp_coord() {
22121
- // Per-pixel offset from center \u2014 small, so float-precise
22122
- float dx = (v_uv.x - 0.5) * _dp_w;
22123
- float dy = (v_uv.y - 0.5) * _dp_h;
22124
- // Combine center (hi+lo) + delta with emulated double precision
22125
- vec2 cre = ds_add(vec2(_dp_cx_hi, _dp_cx_lo), ds_from(dx));
22126
- vec2 cim = ds_add(vec2(_dp_cy_hi, _dp_cy_lo), ds_from(dy));
22127
- return vec4(cre.x, cim.x, cre.y, cim.y);
22128
- }
22129
-
22130
- float _fractal_mandelbrot_dp(vec4 c, int maxIter) {
22131
- // c = (re_hi, im_hi, re_lo, im_lo)
22132
- vec2 cr = vec2(c.x, c.z); // real part as ds
22133
- vec2 ci = vec2(c.y, c.w); // imag part as ds
22134
- vec2 zr = vec2(0.0, 0.0);
22135
- vec2 zi = vec2(0.0, 0.0);
22136
- for (int i = 0; i < maxIter; i++) {
22137
- vec2 zr2 = ds_sqr(zr);
22138
- vec2 zi2 = ds_sqr(zi);
22139
- // |z|^2 > 4.0 ?
22140
- vec2 mag2 = ds_add(zr2, zi2);
22141
- if (mag2.x > 4.0)
22142
- return clamp((float(i) - log2(log2(mag2.x)) + 4.0) / float(maxIter), 0.0, 1.0);
22143
- // z = z^2 + c
22144
- vec2 new_zi = ds_add(ds_mul(ds_add(zr, zr), zi), ci); // 2*zr*zi + ci
22145
- zr = ds_add(ds_sub(zr2, zi2), cr); // zr^2 - zi^2 + cr
22146
- zi = new_zi;
22147
- }
22148
- return 1.0;
22149
- }
22150
-
22151
- float _fractal_julia_dp(vec4 z_in, vec4 c, int maxIter) {
22152
- vec2 zr = vec2(z_in.x, z_in.z);
22153
- vec2 zi = vec2(z_in.y, z_in.w);
22154
- vec2 cr = vec2(c.x, c.z);
22155
- vec2 ci = vec2(c.y, c.w);
22156
- for (int i = 0; i < maxIter; i++) {
22157
- vec2 zr2 = ds_sqr(zr);
22158
- vec2 zi2 = ds_sqr(zi);
22159
- vec2 mag2 = ds_add(zr2, zi2);
22160
- if (mag2.x > 4.0)
22161
- return clamp((float(i) - log2(log2(mag2.x)) + 4.0) / float(maxIter), 0.0, 1.0);
22162
- vec2 new_zi = ds_add(ds_mul(ds_add(zr, zr), zi), ci);
22163
- zr = ds_add(ds_sub(zr2, zi2), cr);
22164
- zi = new_zi;
22165
- }
22166
- return 1.0;
22167
- }
22168
- `;
22169
- var GPU_FRACTAL_DP_PREAMBLE_WGSL = `
22170
- @group(0) @binding(10) var<uniform> _dp_cx_hi: f32;
22171
- @group(0) @binding(11) var<uniform> _dp_cx_lo: f32;
22172
- @group(0) @binding(12) var<uniform> _dp_cy_hi: f32;
22173
- @group(0) @binding(13) var<uniform> _dp_cy_lo: f32;
22174
- @group(0) @binding(14) var<uniform> _dp_w: f32;
22175
- @group(0) @binding(15) var<uniform> _dp_h: f32;
22176
-
22177
- fn _dp_coord(uv: vec2f) -> vec4f {
22178
- let dx = (uv.x - 0.5) * _dp_w;
22179
- let dy = (uv.y - 0.5) * _dp_h;
22180
- let cre = ds_add(vec2f(_dp_cx_hi, _dp_cx_lo), ds_from(dx));
22181
- let cim = ds_add(vec2f(_dp_cy_hi, _dp_cy_lo), ds_from(dy));
22182
- return vec4f(cre.x, cim.x, cre.y, cim.y);
22183
- }
22184
-
22185
- fn _fractal_mandelbrot_dp(c: vec4f, maxIter: i32) -> f32 {
22186
- let cr = vec2f(c.x, c.z);
22187
- let ci = vec2f(c.y, c.w);
22188
- var zr = vec2f(0.0, 0.0);
22189
- var zi = vec2f(0.0, 0.0);
22190
- for (var i: i32 = 0; i < maxIter; i++) {
22191
- let zr2 = ds_sqr(zr);
22192
- let zi2 = ds_sqr(zi);
22193
- let mag2 = ds_add(zr2, zi2);
22194
- if (mag2.x > 4.0) {
22195
- return clamp((f32(i) - log2(log2(mag2.x)) + 4.0) / f32(maxIter), 0.0, 1.0);
22196
- }
22197
- let new_zi = ds_add(ds_mul(ds_add(zr, zr), zi), ci);
22198
- zr = ds_add(ds_sub(zr2, zi2), cr);
22199
- zi = new_zi;
22200
- }
22201
- return 1.0;
22202
- }
22203
-
22204
- fn _fractal_julia_dp(z_in: vec4f, c: vec4f, maxIter: i32) -> f32 {
22205
- var zr = vec2f(z_in.x, z_in.z);
22206
- var zi = vec2f(z_in.y, z_in.w);
22207
- let cr = vec2f(c.x, c.z);
22208
- let ci = vec2f(c.y, c.w);
22209
- for (var i: i32 = 0; i < maxIter; i++) {
22210
- let zr2 = ds_sqr(zr);
22211
- let zi2 = ds_sqr(zi);
22212
- let mag2 = ds_add(zr2, zi2);
22213
- if (mag2.x > 4.0) {
22214
- return clamp((f32(i) - log2(log2(mag2.x)) + 4.0) / f32(maxIter), 0.0, 1.0);
22215
- }
22216
- let new_zi = ds_add(ds_mul(ds_add(zr, zr), zi), ci);
22217
- zr = ds_add(ds_sub(zr2, zi2), cr);
22218
- zi = new_zi;
22219
- }
22220
- return 1.0;
22221
- }
22222
- `;
22223
22008
  var GPU_FRACTAL_PREAMBLE_GLSL = `
22224
22009
  float _fractal_mandelbrot(vec2 c, int maxIter) {
22225
22010
  vec2 z = vec2(0.0, 0.0);
@@ -22263,208 +22048,6 @@ fn _fractal_julia(z_in: vec2f, c: vec2f, maxIter: i32) -> f32 {
22263
22048
  return 1.0;
22264
22049
  }
22265
22050
  `;
22266
- var GPU_FRACTAL_PT_PREAMBLE_GLSL = `
22267
- uniform sampler2D _refOrbit;
22268
- uniform int _refOrbitLen;
22269
- uniform int _refOrbitTexWidth;
22270
- uniform float _pt_offset_x;
22271
- uniform float _pt_offset_y;
22272
- uniform float _pt_w;
22273
- uniform float _pt_h;
22274
-
22275
- vec2 _pt_delta() {
22276
- float dx = _pt_offset_x + (v_uv.x - 0.5) * _pt_w;
22277
- float dy = _pt_offset_y + (v_uv.y - 0.5) * _pt_h;
22278
- return vec2(dx, dy);
22279
- }
22280
-
22281
- vec2 _pt_fetch_orbit(int i) {
22282
- int y = i / _refOrbitTexWidth;
22283
- int x = i - y * _refOrbitTexWidth;
22284
- return texelFetch(_refOrbit, ivec2(x, y), 0).rg;
22285
- }
22286
-
22287
- float _fractal_mandelbrot_pt(vec2 delta_c, int maxIter) {
22288
- float dr = 0.0;
22289
- float di = 0.0;
22290
- int orbitLen = min(maxIter, _refOrbitLen);
22291
- for (int i = 0; i < orbitLen; i++) {
22292
- vec2 Zn = _pt_fetch_orbit(i);
22293
- // delta_{n+1} = 2*Z_n*delta_n + delta_n^2 + delta_c
22294
- float new_dr = 2.0 * (Zn.x * dr - Zn.y * di) + dr * dr - di * di + delta_c.x;
22295
- float new_di = 2.0 * (Zn.x * di + Zn.y * dr) + 2.0 * dr * di + delta_c.y;
22296
- dr = new_dr;
22297
- di = new_di;
22298
- // Full z = Z_{n+1} + delta for escape check
22299
- vec2 Zn1 = (i + 1 < orbitLen) ? _pt_fetch_orbit(i + 1) : vec2(0.0);
22300
- float zr = Zn1.x + dr;
22301
- float zi = Zn1.y + di;
22302
- float mag2 = zr * zr + zi * zi;
22303
- if (mag2 > 4.0)
22304
- return clamp((float(i) - log2(log2(mag2)) + 4.0) / float(maxIter), 0.0, 1.0);
22305
- // Glitch detection: |delta|^2 > |Z|^2
22306
- float dmag2 = dr * dr + di * di;
22307
- float Zmag2 = Zn.x * Zn.x + Zn.y * Zn.y;
22308
- if (dmag2 > Zmag2 && Zmag2 > 0.0) {
22309
- // Rebase to absolute coordinates and continue with single-float
22310
- float abs_zr = Zn1.x + dr;
22311
- float abs_zi = Zn1.y + di;
22312
- // Reconstruct absolute c from reference + delta
22313
- // (Use ds_from for the concept, but single-float suffices for fallback)
22314
- float cx = abs_zr - dr + delta_c.x;
22315
- float cy = abs_zi - di + delta_c.y;
22316
- for (int j = i + 1; j < maxIter; j++) {
22317
- float new_zr = abs_zr * abs_zr - abs_zi * abs_zi + cx;
22318
- abs_zi = 2.0 * abs_zr * abs_zi + cy;
22319
- abs_zr = new_zr;
22320
- mag2 = abs_zr * abs_zr + abs_zi * abs_zi;
22321
- if (mag2 > 4.0)
22322
- return clamp((float(j) - log2(log2(mag2)) + 4.0) / float(maxIter), 0.0, 1.0);
22323
- }
22324
- return 1.0;
22325
- }
22326
- }
22327
- return 1.0;
22328
- }
22329
-
22330
- float _fractal_julia_pt(vec2 z_delta, vec2 delta_c, int maxIter) {
22331
- float dr = z_delta.x;
22332
- float di = z_delta.y;
22333
- int orbitLen = min(maxIter, _refOrbitLen);
22334
- for (int i = 0; i < orbitLen; i++) {
22335
- vec2 Zn = _pt_fetch_orbit(i);
22336
- float new_dr = 2.0 * (Zn.x * dr - Zn.y * di) + dr * dr - di * di + delta_c.x;
22337
- float new_di = 2.0 * (Zn.x * di + Zn.y * dr) + 2.0 * dr * di + delta_c.y;
22338
- dr = new_dr;
22339
- di = new_di;
22340
- vec2 Zn1 = (i + 1 < orbitLen) ? _pt_fetch_orbit(i + 1) : vec2(0.0);
22341
- float zr = Zn1.x + dr;
22342
- float zi = Zn1.y + di;
22343
- float mag2 = zr * zr + zi * zi;
22344
- if (mag2 > 4.0)
22345
- return clamp((float(i) - log2(log2(mag2)) + 4.0) / float(maxIter), 0.0, 1.0);
22346
- float dmag2 = dr * dr + di * di;
22347
- float Zmag2 = Zn.x * Zn.x + Zn.y * Zn.y;
22348
- if (dmag2 > Zmag2 && Zmag2 > 0.0) {
22349
- float abs_zr = Zn1.x + dr;
22350
- float abs_zi = Zn1.y + di;
22351
- float cx = delta_c.x;
22352
- float cy = delta_c.y;
22353
- for (int j = i + 1; j < maxIter; j++) {
22354
- float new_zr = abs_zr * abs_zr - abs_zi * abs_zi + cx;
22355
- abs_zi = 2.0 * abs_zr * abs_zi + cy;
22356
- abs_zr = new_zr;
22357
- mag2 = abs_zr * abs_zr + abs_zi * abs_zi;
22358
- if (mag2 > 4.0)
22359
- return clamp((float(j) - log2(log2(mag2)) + 4.0) / float(maxIter), 0.0, 1.0);
22360
- }
22361
- return 1.0;
22362
- }
22363
- }
22364
- return 1.0;
22365
- }
22366
- `;
22367
- var GPU_FRACTAL_PT_PREAMBLE_WGSL = `
22368
- @group(0) @binding(1) var _refOrbit: texture_2d<f32>;
22369
- var<uniform> _refOrbitLen: i32;
22370
- var<uniform> _refOrbitTexWidth: i32;
22371
- var<uniform> _pt_offset_x: f32;
22372
- var<uniform> _pt_offset_y: f32;
22373
- var<uniform> _pt_w: f32;
22374
- var<uniform> _pt_h: f32;
22375
-
22376
- fn _pt_delta(uv: vec2f) -> vec2f {
22377
- let dx = _pt_offset_x + (uv.x - 0.5) * _pt_w;
22378
- let dy = _pt_offset_y + (uv.y - 0.5) * _pt_h;
22379
- return vec2f(dx, dy);
22380
- }
22381
-
22382
- fn _pt_fetch_orbit(i: i32) -> vec2f {
22383
- let y = i / _refOrbitTexWidth;
22384
- let x = i - y * _refOrbitTexWidth;
22385
- return textureLoad(_refOrbit, vec2i(x, y), 0).rg;
22386
- }
22387
-
22388
- fn _fractal_mandelbrot_pt(delta_c: vec2f, maxIter: i32) -> f32 {
22389
- var dr: f32 = 0.0;
22390
- var di: f32 = 0.0;
22391
- let orbitLen = min(maxIter, _refOrbitLen);
22392
- for (var i: i32 = 0; i < orbitLen; i++) {
22393
- let Zn = _pt_fetch_orbit(i);
22394
- let new_dr = 2.0 * (Zn.x * dr - Zn.y * di) + dr * dr - di * di + delta_c.x;
22395
- let new_di = 2.0 * (Zn.x * di + Zn.y * dr) + 2.0 * dr * di + delta_c.y;
22396
- dr = new_dr;
22397
- di = new_di;
22398
- var Zn1 = vec2f(0.0);
22399
- if (i + 1 < orbitLen) { Zn1 = _pt_fetch_orbit(i + 1); }
22400
- let zr = Zn1.x + dr;
22401
- let zi = Zn1.y + di;
22402
- var mag2 = zr * zr + zi * zi;
22403
- if (mag2 > 4.0) {
22404
- return clamp((f32(i) - log2(log2(mag2)) + 4.0) / f32(maxIter), 0.0, 1.0);
22405
- }
22406
- let dmag2 = dr * dr + di * di;
22407
- let Zmag2 = Zn.x * Zn.x + Zn.y * Zn.y;
22408
- if (dmag2 > Zmag2 && Zmag2 > 0.0) {
22409
- var f_zr = Zn1.x + dr;
22410
- var f_zi = Zn1.y + di;
22411
- let cx = delta_c.x;
22412
- let cy = delta_c.y;
22413
- for (var j: i32 = i + 1; j < maxIter; j++) {
22414
- let t_zr = f_zr * f_zr - f_zi * f_zi + cx;
22415
- f_zi = 2.0 * f_zr * f_zi + cy;
22416
- f_zr = t_zr;
22417
- mag2 = f_zr * f_zr + f_zi * f_zi;
22418
- if (mag2 > 4.0) {
22419
- return clamp((f32(j) - log2(log2(mag2)) + 4.0) / f32(maxIter), 0.0, 1.0);
22420
- }
22421
- }
22422
- return 1.0;
22423
- }
22424
- }
22425
- return 1.0;
22426
- }
22427
-
22428
- fn _fractal_julia_pt(z_delta: vec2f, delta_c: vec2f, maxIter: i32) -> f32 {
22429
- var dr = z_delta.x;
22430
- var di = z_delta.y;
22431
- let orbitLen = min(maxIter, _refOrbitLen);
22432
- for (var i: i32 = 0; i < orbitLen; i++) {
22433
- let Zn = _pt_fetch_orbit(i);
22434
- let new_dr = 2.0 * (Zn.x * dr - Zn.y * di) + dr * dr - di * di + delta_c.x;
22435
- let new_di = 2.0 * (Zn.x * di + Zn.y * dr) + 2.0 * dr * di + delta_c.y;
22436
- dr = new_dr;
22437
- di = new_di;
22438
- var Zn1 = vec2f(0.0);
22439
- if (i + 1 < orbitLen) { Zn1 = _pt_fetch_orbit(i + 1); }
22440
- let zr = Zn1.x + dr;
22441
- let zi = Zn1.y + di;
22442
- var mag2 = zr * zr + zi * zi;
22443
- if (mag2 > 4.0) {
22444
- return clamp((f32(i) - log2(log2(mag2)) + 4.0) / f32(maxIter), 0.0, 1.0);
22445
- }
22446
- let dmag2 = dr * dr + di * di;
22447
- let Zmag2 = Zn.x * Zn.x + Zn.y * Zn.y;
22448
- if (dmag2 > Zmag2 && Zmag2 > 0.0) {
22449
- var f_zr = Zn1.x + dr;
22450
- var f_zi = Zn1.y + di;
22451
- let cx = delta_c.x;
22452
- let cy = delta_c.y;
22453
- for (var j: i32 = i + 1; j < maxIter; j++) {
22454
- let t_zr = f_zr * f_zr - f_zi * f_zi + cx;
22455
- f_zi = 2.0 * f_zr * f_zi + cy;
22456
- f_zr = t_zr;
22457
- mag2 = f_zr * f_zr + f_zi * f_zi;
22458
- if (mag2 > 4.0) {
22459
- return clamp((f32(j) - log2(log2(mag2)) + 4.0) / f32(maxIter), 0.0, 1.0);
22460
- }
22461
- }
22462
- return 1.0;
22463
- }
22464
- }
22465
- return 1.0;
22466
- }
22467
- `;
22468
22051
  var GPU_COLOR_PREAMBLE_GLSL = `
22469
22052
  float _gpu_srgb_to_linear(float c) {
22470
22053
  if (c <= 0.04045) return c / 12.92;
@@ -22903,7 +22486,6 @@ var GPUShaderTarget = class {
22903
22486
  const constants = this.getConstants();
22904
22487
  const v2 = this.languageId === "wgsl" ? "vec2f" : "vec2";
22905
22488
  const target = this.createTarget({
22906
- hints: options.hints,
22907
22489
  functions: (id) => {
22908
22490
  if (userFunctions && id in userFunctions) {
22909
22491
  const fn = userFunctions[id];
@@ -22942,89 +22524,12 @@ var GPUShaderTarget = class {
22942
22524
  if (code.includes("_gpu_besselJ"))
22943
22525
  preamble += this.languageId === "wgsl" ? GPU_BESSELJ_PREAMBLE_WGSL : GPU_BESSELJ_PREAMBLE_GLSL;
22944
22526
  if (code.includes("_fractal_")) {
22945
- if (code.includes("_fractal_mandelbrot_pt") || code.includes("_fractal_julia_pt")) {
22946
- preamble += this.languageId === "wgsl" ? GPU_DS_ARITHMETIC_PREAMBLE_WGSL : GPU_DS_ARITHMETIC_PREAMBLE_GLSL;
22947
- preamble += this.languageId === "wgsl" ? GPU_FRACTAL_PT_PREAMBLE_WGSL : GPU_FRACTAL_PT_PREAMBLE_GLSL;
22948
- } else if (code.includes("_fractal_mandelbrot_dp") || code.includes("_fractal_julia_dp")) {
22949
- preamble += this.languageId === "wgsl" ? GPU_DS_ARITHMETIC_PREAMBLE_WGSL : GPU_DS_ARITHMETIC_PREAMBLE_GLSL;
22950
- preamble += this.languageId === "wgsl" ? GPU_FRACTAL_DP_PREAMBLE_WGSL : GPU_FRACTAL_DP_PREAMBLE_GLSL;
22951
- } else {
22952
- preamble += this.languageId === "wgsl" ? GPU_FRACTAL_PREAMBLE_WGSL : GPU_FRACTAL_PREAMBLE_GLSL;
22953
- }
22527
+ preamble += this.languageId === "wgsl" ? GPU_FRACTAL_PREAMBLE_WGSL : GPU_FRACTAL_PREAMBLE_GLSL;
22954
22528
  }
22955
22529
  if (code.includes("_gpu_srgb_to") || code.includes("_gpu_oklab") || code.includes("_gpu_oklch") || code.includes("_gpu_color_mix") || code.includes("_gpu_apca")) {
22956
22530
  preamble += this.languageId === "wgsl" ? GPU_COLOR_PREAMBLE_WGSL : GPU_COLOR_PREAMBLE_GLSL;
22957
22531
  }
22958
22532
  if (preamble) result.preamble = preamble;
22959
- if (code.includes("_fractal_") && options.hints?.viewport) {
22960
- const strategy = selectFractalStrategy(target);
22961
- const radius = options.hints.viewport.radius;
22962
- switch (strategy) {
22963
- case "single":
22964
- result.staleWhen = { radiusBelow: 1e-6 };
22965
- break;
22966
- case "double":
22967
- result.staleWhen = { radiusBelow: 1e-14, radiusAbove: 1e-5 };
22968
- break;
22969
- case "perturbation":
22970
- result.staleWhen = {
22971
- radiusAbove: 1e-5,
22972
- radiusBelow: radius * 0.01,
22973
- centerDistance: radius * 2
22974
- };
22975
- break;
22976
- }
22977
- }
22978
- if ((code.includes("_fractal_mandelbrot_dp") || code.includes("_fractal_julia_dp")) && options.hints?.viewport) {
22979
- const cx = hpToNumber(options.hints.viewport.center[0]);
22980
- const cy = hpToNumber(options.hints.viewport.center[1]);
22981
- const size = options.hints.viewport.radius * 2;
22982
- const cx_hi = Math.fround(cx);
22983
- const cy_hi = Math.fround(cy);
22984
- result.uniforms = {
22985
- ...result.uniforms,
22986
- _dp_cx_hi: cx_hi,
22987
- _dp_cx_lo: cx - cx_hi,
22988
- _dp_cy_hi: cy_hi,
22989
- _dp_cy_lo: cy - cy_hi,
22990
- _dp_w: size,
22991
- _dp_h: size
22992
- };
22993
- }
22994
- if ((code.includes("_fractal_mandelbrot_pt") || code.includes("_fractal_julia_pt")) && options.hints?.viewport) {
22995
- const viewport = options.hints.viewport;
22996
- const size = viewport.radius * 2;
22997
- result.uniforms = {
22998
- ...result.uniforms,
22999
- _pt_offset_x: 0,
23000
- _pt_offset_y: 0,
23001
- _pt_w: size,
23002
- _pt_h: size
23003
- };
23004
- const digits = Math.max(50, Math.ceil(-Math.log10(viewport.radius)) + 10);
23005
- const maxIter = 1e3;
23006
- const orbit = computeReferenceOrbit(
23007
- viewport.center,
23008
- maxIter,
23009
- digits
23010
- );
23011
- const orbitLen = orbit.length / 2;
23012
- const texWidth = Math.min(orbitLen, 4096);
23013
- const texHeight = Math.ceil(orbitLen / texWidth);
23014
- result.textures = {
23015
- _refOrbit: {
23016
- data: orbit,
23017
- width: texWidth,
23018
- height: texHeight,
23019
- format: "rg32f"
23020
- }
23021
- };
23022
- result.uniforms = {
23023
- ...result.uniforms,
23024
- _refOrbitLen: orbitLen,
23025
- _refOrbitTexWidth: texWidth
23026
- };
23027
- }
23028
22533
  return result;
23029
22534
  }
23030
22535
  compileToSource(expr, _options = {}) {
@@ -25359,7 +24864,7 @@ function compileToIntervalTarget(expr, target) {
25359
24864
  }
25360
24865
 
25361
24866
  // src/compile.ts
25362
- var version = "0.55.5";
24867
+ var version = "0.55.6";
25363
24868
  export {
25364
24869
  BaseCompiler,
25365
24870
  GLSLTarget,