@cortex-js/compute-engine 0.51.0 → 0.51.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 (236) hide show
  1. package/dist/compute-engine.esm.js +1447 -250
  2. package/dist/compute-engine.min.esm.js +66 -58
  3. package/dist/compute-engine.min.umd.js +66 -58
  4. package/dist/compute-engine.umd.js +1447 -250
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.min.esm.js +2 -2
  7. package/dist/math-json.min.umd.js +2 -2
  8. package/dist/math-json.umd.js +2 -2
  9. package/dist/types/color/categorical.d.ts +10 -3
  10. package/dist/types/color/contrast.d.ts +1 -1
  11. package/dist/types/color/conversion.d.ts +1 -1
  12. package/dist/types/color/diverging-palettes.d.ts +1 -1
  13. package/dist/types/color/index.d.ts +1 -1
  14. package/dist/types/color/manipulation.d.ts +3 -3
  15. package/dist/types/color/palette.d.ts +47 -17
  16. package/dist/types/color/sequential.d.ts +1 -1
  17. package/dist/types/color/types.d.ts +1 -1
  18. package/dist/types/common/ansi-codes.d.ts +1 -1
  19. package/dist/types/common/configuration-change.d.ts +1 -1
  20. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  21. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  22. package/dist/types/common/interruptible.d.ts +1 -1
  23. package/dist/types/common/one-of.d.ts +1 -1
  24. package/dist/types/common/signals.d.ts +1 -1
  25. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  26. package/dist/types/common/type/boxed-type.d.ts +1 -1
  27. package/dist/types/common/type/lexer.d.ts +1 -1
  28. package/dist/types/common/type/parse.d.ts +1 -1
  29. package/dist/types/common/type/parser.d.ts +1 -1
  30. package/dist/types/common/type/primitive.d.ts +1 -1
  31. package/dist/types/common/type/reduce.d.ts +1 -1
  32. package/dist/types/common/type/serialize.d.ts +1 -1
  33. package/dist/types/common/type/subtype.d.ts +1 -1
  34. package/dist/types/common/type/type-builder.d.ts +1 -1
  35. package/dist/types/common/type/types.d.ts +1 -1
  36. package/dist/types/common/type/utils.d.ts +1 -1
  37. package/dist/types/common/utils.d.ts +1 -1
  38. package/dist/types/compute-engine/assume.d.ts +1 -1
  39. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  40. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  41. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  43. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/product.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  82. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  87. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  88. package/dist/types/compute-engine/compilation/base-compiler.d.ts +26 -1
  89. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  90. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  91. package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -1
  92. package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +1 -1
  93. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +7 -1
  94. package/dist/types/compute-engine/compilation/interval-wgsl-target.d.ts +1 -1
  95. package/dist/types/compute-engine/compilation/javascript-target.d.ts +10 -2
  96. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  97. package/dist/types/compute-engine/compilation/types.d.ts +24 -6
  98. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  99. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  100. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  101. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  102. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  103. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  104. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  105. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  106. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  107. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  108. package/dist/types/compute-engine/engine-latex-dictionary-state.d.ts +1 -1
  109. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  110. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  111. package/dist/types/compute-engine/engine-parse-entrypoint.d.ts +1 -1
  112. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  113. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  114. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  115. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  116. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  117. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  118. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  119. package/dist/types/compute-engine/free-functions.d.ts +2 -1
  120. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  121. package/dist/types/compute-engine/global-types.d.ts +1 -1
  122. package/dist/types/compute-engine/index.d.ts +2 -2
  123. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  124. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  125. package/dist/types/compute-engine/interval/elementary.d.ts +18 -1
  126. package/dist/types/compute-engine/interval/index.d.ts +11 -5
  127. package/dist/types/compute-engine/interval/trigonometric.d.ts +16 -1
  128. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  129. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  130. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  131. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  132. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  133. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  134. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  135. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  136. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  137. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  138. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  139. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  140. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  141. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  142. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  143. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  144. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  145. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  146. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  147. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  148. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  149. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +22 -0
  150. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  151. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  152. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -2
  153. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  154. package/dist/types/compute-engine/latex-syntax/types.d.ts +58 -1
  155. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  156. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  157. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  158. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  159. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  160. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  161. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  162. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  163. package/dist/types/compute-engine/library/core.d.ts +1 -1
  164. package/dist/types/compute-engine/library/library.d.ts +1 -1
  165. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  166. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  167. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  168. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  169. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  170. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  171. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  172. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  173. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  174. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  175. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  176. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  177. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  178. package/dist/types/compute-engine/library/units.d.ts +1 -1
  179. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  180. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  181. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  182. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  183. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  184. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  185. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  186. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  187. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  188. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  189. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  190. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  191. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  192. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  193. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  194. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  195. package/dist/types/compute-engine/numerics/special-functions.d.ts +15 -1
  196. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  197. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  198. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  199. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  200. package/dist/types/compute-engine/oeis.d.ts +1 -1
  201. package/dist/types/compute-engine/sequence.d.ts +1 -1
  202. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  203. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  204. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  205. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  206. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  207. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  208. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  209. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  210. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  211. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  212. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  213. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  214. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  215. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  216. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  217. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  218. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  219. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  220. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  221. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  222. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  223. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  224. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  225. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  226. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  227. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  228. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  229. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  230. package/dist/types/compute-engine/types.d.ts +1 -1
  231. package/dist/types/compute-engine.d.ts +1 -1
  232. package/dist/types/math-json/symbols.d.ts +1 -1
  233. package/dist/types/math-json/types.d.ts +1 -1
  234. package/dist/types/math-json/utils.d.ts +1 -1
  235. package/dist/types/math-json.d.ts +2 -2
  236. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.51.0 */
1
+ /** Compute Engine 0.51.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;
@@ -9860,13 +9860,175 @@ var ComputeEngine = (() => {
9860
9860
  parse: (parser, lhs, terminator) => {
9861
9861
  const seq = parseSequence(parser, terminator, lhs, 19, ";");
9862
9862
  if (seq === null) return null;
9863
+ if (seq.some((e) => operator(e) === "Assign"))
9864
+ return buildBlockFromSequence(seq);
9863
9865
  return ["Delimiter", ["Sequence", ...seq], "';'"];
9864
9866
  }
9865
9867
  },
9868
+ // \text{where} — variable binding infix
9869
+ {
9870
+ latexTrigger: ["\\text"],
9871
+ kind: "infix",
9872
+ associativity: "none",
9873
+ precedence: 21,
9874
+ // Above ; (19) and , (20), very low binding
9875
+ parse: (parser, lhs, until) => {
9876
+ const start = parser.index;
9877
+ if (!matchTextKeyword(parser, "where")) {
9878
+ parser.index = start;
9879
+ return null;
9880
+ }
9881
+ return parseWhereExpression(parser, lhs, until);
9882
+ }
9883
+ },
9884
+ // \operatorname{where}
9885
+ {
9886
+ symbolTrigger: "where",
9887
+ kind: "infix",
9888
+ associativity: "none",
9889
+ precedence: 21,
9890
+ parse: (parser, lhs, until) => parseWhereExpression(parser, lhs, until)
9891
+ },
9892
+ // Block serializer — used by both `where` and semicolon blocks
9893
+ {
9894
+ name: "Block",
9895
+ serialize: (serializer, expr) => {
9896
+ const args = operands(expr);
9897
+ if (!args || args.length === 0) return "";
9898
+ const parts = args.filter((a) => operator(a) !== "Declare").map((a) => serializer.serialize(a));
9899
+ return parts.join(";\\; ");
9900
+ }
9901
+ },
9902
+ // Serializer for If expressions (separate from the parser entry
9903
+ // because name-based entries affect kind-based indexing)
9904
+ {
9905
+ name: "If",
9906
+ serialize: (serializer, expr) => {
9907
+ const args = operands(expr);
9908
+ if (!args || args.length < 3) return "";
9909
+ return joinLatex([
9910
+ "\\text{if }",
9911
+ serializer.serialize(args[0]),
9912
+ "\\text{ then }",
9913
+ serializer.serialize(args[1]),
9914
+ "\\text{ else }",
9915
+ serializer.serialize(args[2])
9916
+ ]);
9917
+ }
9918
+ },
9919
+ // Serializer for Loop expressions
9920
+ {
9921
+ name: "Loop",
9922
+ serialize: (serializer, expr) => {
9923
+ const args = operands(expr);
9924
+ if (!args || args.length < 2) return "";
9925
+ const body = args[0];
9926
+ const indexing = args[1];
9927
+ if (operator(indexing) === "Element") {
9928
+ const index = operand(indexing, 1);
9929
+ const range2 = operand(indexing, 2);
9930
+ if (operator(range2) === "Range") {
9931
+ const lo = operand(range2, 1);
9932
+ const hi = operand(range2, 2);
9933
+ return joinLatex([
9934
+ "\\text{for }",
9935
+ serializer.serialize(index),
9936
+ "\\text{ from }",
9937
+ serializer.serialize(lo),
9938
+ "\\text{ to }",
9939
+ serializer.serialize(hi),
9940
+ "\\text{ do }",
9941
+ serializer.serialize(body)
9942
+ ]);
9943
+ }
9944
+ }
9945
+ return joinLatex([
9946
+ "\\operatorname{Loop}(",
9947
+ serializer.serialize(body),
9948
+ ", ",
9949
+ serializer.serialize(indexing),
9950
+ ")"
9951
+ ]);
9952
+ }
9953
+ },
9954
+ // Serializer for Break
9955
+ { name: "Break", serialize: () => "\\text{break}" },
9956
+ // Serializer for Continue
9957
+ { name: "Continue", serialize: () => "\\text{continue}" },
9958
+ // Serializer for Return
9959
+ {
9960
+ name: "Return",
9961
+ serialize: (serializer, expr) => {
9962
+ const arg = operand(expr, 1);
9963
+ if (!arg || symbol(arg) === "Nothing") return "\\text{return}";
9964
+ return joinLatex(["\\text{return }", serializer.serialize(arg)]);
9965
+ }
9966
+ },
9967
+ // Also match `\operatorname{if}` / `\mathrm{if}`
9968
+ {
9969
+ symbolTrigger: "if",
9970
+ kind: "prefix",
9971
+ precedence: 245,
9972
+ parse: (parser, until) => {
9973
+ return parseIfExpression(parser, until);
9974
+ }
9975
+ },
9976
+ // \operatorname{for}
9977
+ {
9978
+ symbolTrigger: "for",
9979
+ kind: "prefix",
9980
+ precedence: 245,
9981
+ parse: (parser, until) => parseForExpression(parser, until)
9982
+ },
9983
+ // \operatorname{break}
9984
+ {
9985
+ symbolTrigger: "break",
9986
+ kind: "prefix",
9987
+ precedence: 245,
9988
+ parse: () => ["Break"]
9989
+ },
9990
+ // \operatorname{continue}
9991
+ {
9992
+ symbolTrigger: "continue",
9993
+ kind: "prefix",
9994
+ precedence: 245,
9995
+ parse: () => ["Continue"]
9996
+ },
9997
+ // \operatorname{return}
9998
+ {
9999
+ symbolTrigger: "return",
10000
+ kind: "prefix",
10001
+ precedence: 245,
10002
+ parse: (parser, until) => [
10003
+ "Return",
10004
+ parser.parseExpression(until) ?? "Nothing"
10005
+ ]
10006
+ },
9866
10007
  {
9867
10008
  name: "String",
9868
10009
  latexTrigger: ["\\text"],
9869
- parse: (scanner) => parseTextRun(scanner),
10010
+ parse: (parser, until) => {
10011
+ const start = parser.index;
10012
+ if (matchTextKeyword(parser, "if"))
10013
+ return parseIfExpression(parser, until);
10014
+ parser.index = start;
10015
+ if (matchTextKeyword(parser, "for"))
10016
+ return parseForExpression(parser, until);
10017
+ parser.index = start;
10018
+ if (matchTextKeyword(parser, "break"))
10019
+ return ["Break"];
10020
+ parser.index = start;
10021
+ if (matchTextKeyword(parser, "continue"))
10022
+ return ["Continue"];
10023
+ parser.index = start;
10024
+ if (matchTextKeyword(parser, "return"))
10025
+ return [
10026
+ "Return",
10027
+ parser.parseExpression(until) ?? "Nothing"
10028
+ ];
10029
+ parser.index = start;
10030
+ return parseTextRun(parser);
10031
+ },
9870
10032
  serialize: (serializer, expr) => {
9871
10033
  const args = operands(expr);
9872
10034
  if (args.length === 0) return "\\text{}";
@@ -10520,7 +10682,7 @@ var ComputeEngine = (() => {
10520
10682
  // '⎾': '', // U+23BE RIGHT PARENTHESIS UPPER HOOK
10521
10683
  // '⎿': '', // U+23BF RIGHT PARENTHESIS LOWER HOOK
10522
10684
  };
10523
- function parseAssign(parser, lhs) {
10685
+ function parseAssign(parser, lhs, until) {
10524
10686
  const lhsSymbol = symbol(lhs);
10525
10687
  if (lhsSymbol && lhsSymbol.includes("_")) {
10526
10688
  const underscoreIndex = lhsSymbol.indexOf("_");
@@ -10533,7 +10695,7 @@ var ComputeEngine = (() => {
10533
10695
  if (operator(lhs) === "InvisibleOperator" && nops(lhs) === 2 && operator(operand(lhs, 2)) === "Delimiter") {
10534
10696
  const fn2 = symbol(operand(lhs, 1));
10535
10697
  if (!fn2) return null;
10536
- const rhs2 = parser.parseExpression({ minPrec: 0 });
10698
+ const rhs2 = parser.parseExpression({ ...until ?? {}, minPrec: 20 });
10537
10699
  if (rhs2 === null) return null;
10538
10700
  const delimBody = operand(operand(lhs, 2), 1);
10539
10701
  let args = [];
@@ -10544,7 +10706,7 @@ var ComputeEngine = (() => {
10544
10706
  if (operator(lhs) === "Subscript" && symbol(operand(lhs, 1))) {
10545
10707
  const fn2 = symbol(operand(lhs, 1));
10546
10708
  if (!fn2) return null;
10547
- const rhs2 = parser.parseExpression({ minPrec: 0 });
10709
+ const rhs2 = parser.parseExpression({ ...until ?? {}, minPrec: 20 });
10548
10710
  if (rhs2 === null) return null;
10549
10711
  const sub3 = operand(lhs, 2);
10550
10712
  if (stringValue(sub3) !== null) {
@@ -10560,12 +10722,12 @@ var ComputeEngine = (() => {
10560
10722
  if (fn === "Subscript" || fn === "Superscript") {
10561
10723
  }
10562
10724
  const args = operands(lhs);
10563
- const rhs2 = parser.parseExpression({ minPrec: 0 });
10725
+ const rhs2 = parser.parseExpression({ ...until ?? {}, minPrec: 20 });
10564
10726
  if (rhs2 === null) return null;
10565
10727
  return ["Assign", fn, ["Function", rhs2, ...args]];
10566
10728
  }
10567
10729
  if (!symbol(lhs)) return null;
10568
- const rhs = parser.parseExpression({ minPrec: 0 });
10730
+ const rhs = parser.parseExpression({ ...until ?? {}, minPrec: 20 });
10569
10731
  if (rhs === null) return null;
10570
10732
  return ["Assign", lhs, rhs];
10571
10733
  }
@@ -10592,6 +10754,141 @@ var ComputeEngine = (() => {
10592
10754
  }
10593
10755
  return ["Which", ...result];
10594
10756
  }
10757
+ function matchTextKeyword(parser, keyword) {
10758
+ const start = parser.index;
10759
+ if (!parser.match("<{>")) {
10760
+ parser.index = start;
10761
+ return false;
10762
+ }
10763
+ while (parser.match("<space>")) {
10764
+ }
10765
+ let text = "";
10766
+ while (!parser.atEnd && parser.peek !== "<}>" && parser.peek !== "<space>") {
10767
+ const tok = parser.peek;
10768
+ if (/^[a-zA-Z]$/.test(tok)) {
10769
+ text += tok;
10770
+ parser.nextToken();
10771
+ } else {
10772
+ break;
10773
+ }
10774
+ }
10775
+ while (parser.match("<space>")) {
10776
+ }
10777
+ if (!parser.match("<}>")) {
10778
+ parser.index = start;
10779
+ return false;
10780
+ }
10781
+ if (text !== keyword) {
10782
+ parser.index = start;
10783
+ return false;
10784
+ }
10785
+ return true;
10786
+ }
10787
+ function matchKeyword(parser, keyword) {
10788
+ const start = parser.index;
10789
+ if (parser.match("\\text")) {
10790
+ if (matchTextKeyword(parser, keyword)) return true;
10791
+ parser.index = start;
10792
+ }
10793
+ const saved = parser.index;
10794
+ const sym2 = parser.parseSymbol();
10795
+ if (sym2 !== null && symbol(sym2) === keyword) return true;
10796
+ parser.index = saved;
10797
+ return false;
10798
+ }
10799
+ function peekKeyword(parser, keyword) {
10800
+ const start = parser.index;
10801
+ const result = matchKeyword(parser, keyword);
10802
+ parser.index = start;
10803
+ return result;
10804
+ }
10805
+ function parseIfExpression(parser, until) {
10806
+ const condition = parser.parseExpression({
10807
+ minPrec: 0,
10808
+ condition: (p) => peekKeyword(p, "then")
10809
+ });
10810
+ if (condition === null) return null;
10811
+ if (!matchKeyword(parser, "then")) return null;
10812
+ const trueBranch = parser.parseExpression({
10813
+ minPrec: 0,
10814
+ condition: (p) => peekKeyword(p, "else")
10815
+ });
10816
+ if (trueBranch === null) return null;
10817
+ if (!matchKeyword(parser, "else")) return null;
10818
+ const falseBranch = parser.parseExpression(until) ?? "Nothing";
10819
+ return ["If", condition, trueBranch, falseBranch];
10820
+ }
10821
+ function parseForExpression(parser, until) {
10822
+ const indexExpr = parser.parseExpression({
10823
+ minPrec: 0,
10824
+ condition: (p) => peekKeyword(p, "from")
10825
+ });
10826
+ const index = indexExpr ? symbol(indexExpr) : null;
10827
+ if (!index) return null;
10828
+ if (!matchKeyword(parser, "from")) return null;
10829
+ const lower = parser.parseExpression({
10830
+ minPrec: 0,
10831
+ condition: (p) => peekKeyword(p, "to")
10832
+ });
10833
+ if (lower === null) return null;
10834
+ if (!matchKeyword(parser, "to")) return null;
10835
+ const upper = parser.parseExpression({
10836
+ minPrec: 0,
10837
+ condition: (p) => peekKeyword(p, "do")
10838
+ });
10839
+ if (upper === null) return null;
10840
+ if (!matchKeyword(parser, "do")) return null;
10841
+ const body = parser.parseExpression(until) ?? "Nothing";
10842
+ return [
10843
+ "Loop",
10844
+ body,
10845
+ ["Element", index, ["Range", lower, upper]]
10846
+ ];
10847
+ }
10848
+ function parseWhereExpression(parser, lhs, until) {
10849
+ const bindingTerminator = {
10850
+ minPrec: 21,
10851
+ // Above comma (20) and ; (19)
10852
+ condition: (p) => {
10853
+ if (until?.condition?.(p)) return true;
10854
+ const saved = p.index;
10855
+ p.skipSpace();
10856
+ const isComma = p.peek === ",";
10857
+ p.index = saved;
10858
+ return isComma;
10859
+ }
10860
+ };
10861
+ const bindings = [];
10862
+ do {
10863
+ parser.skipSpace();
10864
+ const binding = parser.parseExpression(bindingTerminator);
10865
+ if (!binding) break;
10866
+ bindings.push(binding);
10867
+ parser.skipSpace();
10868
+ } while (parser.match(","));
10869
+ if (bindings.length === 0) return null;
10870
+ const block = [];
10871
+ for (const b of bindings) {
10872
+ if (operator(b) === "Assign") {
10873
+ block.push(["Declare", operand(b, 1)]);
10874
+ block.push(b);
10875
+ } else {
10876
+ block.push(b);
10877
+ }
10878
+ }
10879
+ block.push(lhs);
10880
+ return ["Block", ...block];
10881
+ }
10882
+ function buildBlockFromSequence(seq) {
10883
+ const block = [];
10884
+ for (const s of seq) {
10885
+ if (operator(s) === "Assign") {
10886
+ block.push(["Declare", operand(s, 1)]);
10887
+ }
10888
+ block.push(s);
10889
+ }
10890
+ return ["Block", ...block];
10891
+ }
10595
10892
  function parseAt(...close) {
10596
10893
  return (parser, lhs) => {
10597
10894
  if (!symbol(lhs) && operator(lhs) !== "List") return null;
@@ -10726,7 +11023,11 @@ var ComputeEngine = (() => {
10726
11023
  level = -1;
10727
11024
  constructor(dictionary, options) {
10728
11025
  this.dictionary = dictionary;
10729
- this.options = options;
11026
+ this.options = {
11027
+ dmsFormat: false,
11028
+ angleNormalization: "none",
11029
+ ...options
11030
+ };
10730
11031
  }
10731
11032
  /**
10732
11033
  * Serialize the expression, and if the expression is an operator
@@ -11848,6 +12149,8 @@ var ComputeEngine = (() => {
11848
12149
  // invisibleApply: '',
11849
12150
  multiply: "\\times",
11850
12151
  missingSymbol: "\\blacksquare",
12152
+ dmsFormat: false,
12153
+ angleNormalization: "none",
11851
12154
  // openGroup: '(',
11852
12155
  // closeGroup: ')',
11853
12156
  // divide: '\\frac{#1}{#2}',
@@ -16903,6 +17206,150 @@ ${lines.join("\n")}`;
16903
17206
  const x14 = Math.pow(absX, 0.25);
16904
17207
  return Math.cos(xi + Math.PI / 4) / (Math.sqrt(Math.PI) * x14);
16905
17208
  }
17209
+ var SN = [
17210
+ -2991.8191940101983,
17211
+ 708840.0452577386,
17212
+ -6297414862058625e-8,
17213
+ 25489088057337637e-7,
17214
+ -4429795180596978e-5,
17215
+ 3180162978765678e-4
17216
+ ];
17217
+ var SD = [
17218
+ 1,
17219
+ 281.3762688899943,
17220
+ 45584.78108065326,
17221
+ 5173438887700964e-9,
17222
+ 4193202458981112e-7,
17223
+ 22441179564534092e-6,
17224
+ 607366389490085e-3
17225
+ ];
17226
+ var CN = [
17227
+ -49884311457357354e-24,
17228
+ 9504280628298596e-21,
17229
+ -6451914356839651e-19,
17230
+ 0.018884331939670384,
17231
+ -0.20552590095501388,
17232
+ 1
17233
+ ];
17234
+ var CD = [
17235
+ 399982968972496e-26,
17236
+ 9154392157746574e-25,
17237
+ 12500186247959882e-23,
17238
+ 12226278902417902e-21,
17239
+ 8680295429417843e-19,
17240
+ 0.04121420907221998,
17241
+ 1
17242
+ ];
17243
+ var FN = [
17244
+ 0.4215435550436775,
17245
+ 0.1434079197807589,
17246
+ 0.011522095507358577,
17247
+ 345017939782574e-18,
17248
+ 46361374928786735e-22,
17249
+ 3055689837902576e-23,
17250
+ 10230451416490724e-26,
17251
+ 17201074326816183e-29,
17252
+ 13428327623306275e-32,
17253
+ 3763297112699879e-35
17254
+ ];
17255
+ var FD = [
17256
+ 1,
17257
+ 0.7515863983533789,
17258
+ 0.11688892585919138,
17259
+ 0.0064405152650885865,
17260
+ 15593440916415301e-20,
17261
+ 18462756734893055e-22,
17262
+ 11269922476399903e-24,
17263
+ 36014002958937136e-27,
17264
+ 5887545336215784e-29,
17265
+ 45200143407412973e-33,
17266
+ 12544323709001127e-36
17267
+ ];
17268
+ var GN = [
17269
+ 0.5044420736433832,
17270
+ 0.1971028335255234,
17271
+ 0.018764858409257526,
17272
+ 6840793809153931e-19,
17273
+ 11513882611188428e-21,
17274
+ 9828524436884223e-23,
17275
+ 44534441586175015e-26,
17276
+ 10826804113902088e-28,
17277
+ 1375554606332618e-30,
17278
+ 8363544356306774e-34,
17279
+ 18695871016278324e-38
17280
+ ];
17281
+ var GD = [
17282
+ 1,
17283
+ 1.4749575992512833,
17284
+ 0.33774898912002,
17285
+ 0.02536037414203388,
17286
+ 8146791071843061e-19,
17287
+ 12754507566772912e-21,
17288
+ 10431458965757199e-23,
17289
+ 46068072851523205e-26,
17290
+ 11027321506624028e-28,
17291
+ 13879653125957886e-31,
17292
+ 8391588162831187e-34,
17293
+ 18695871016278324e-38
17294
+ ];
17295
+ function polevl(x, coef) {
17296
+ let ans = coef[0];
17297
+ for (let i = 1; i < coef.length; i++) ans = ans * x + coef[i];
17298
+ return ans;
17299
+ }
17300
+ function fresnelS(x) {
17301
+ if (!isFinite(x)) {
17302
+ if (x !== x) return NaN;
17303
+ return x > 0 ? 0.5 : -0.5;
17304
+ }
17305
+ const sign3 = x < 0 ? -1 : 1;
17306
+ x = Math.abs(x);
17307
+ if (x < 1.6) {
17308
+ const x2 = x * x;
17309
+ const t = x2 * x2;
17310
+ return sign3 * x * x2 * polevl(t, SN) / polevl(t, SD);
17311
+ }
17312
+ if (x < 36) {
17313
+ const x2 = x * x;
17314
+ const t = Math.PI * x2;
17315
+ const u = 1 / (t * t);
17316
+ const f = 1 - u * polevl(u, FN) / polevl(u, FD);
17317
+ const g = 1 / t * polevl(u, GN) / polevl(u, GD);
17318
+ const z = Math.PI / 2 * x2;
17319
+ const c = Math.cos(z);
17320
+ const s = Math.sin(z);
17321
+ return sign3 * (0.5 - (f * c + g * s) / (Math.PI * x));
17322
+ }
17323
+ return sign3 * 0.5;
17324
+ }
17325
+ function fresnelC(x) {
17326
+ if (!isFinite(x)) {
17327
+ if (x !== x) return NaN;
17328
+ return x > 0 ? 0.5 : -0.5;
17329
+ }
17330
+ const sign3 = x < 0 ? -1 : 1;
17331
+ x = Math.abs(x);
17332
+ if (x < 1.6) {
17333
+ const x2 = x * x;
17334
+ const t = x2 * x2;
17335
+ return sign3 * x * polevl(t, CN) / polevl(t, CD);
17336
+ }
17337
+ if (x < 36) {
17338
+ const x2 = x * x;
17339
+ const t = Math.PI * x2;
17340
+ const u = 1 / (t * t);
17341
+ const f = 1 - u * polevl(u, FN) / polevl(u, FD);
17342
+ const g = 1 / t * polevl(u, GN) / polevl(u, GD);
17343
+ const z = Math.PI / 2 * x2;
17344
+ const c = Math.cos(z);
17345
+ const s = Math.sin(z);
17346
+ return sign3 * (0.5 + (f * s - g * c) / (Math.PI * x));
17347
+ }
17348
+ return sign3 * 0.5;
17349
+ }
17350
+ function sinc(x) {
17351
+ return x === 0 ? 1 : Math.sin(x) / x;
17352
+ }
16906
17353
 
16907
17354
  // src/compute-engine/boxed-expression/predicates.ts
16908
17355
  function isPrime2(expr) {
@@ -23554,7 +24001,7 @@ ${lines.join("\n")}`;
23554
24001
  wikidata: "Q715358",
23555
24002
  complexity: 2e3,
23556
24003
  broadcastable: true,
23557
- signature: "(number) -> number",
24004
+ signature: "(value) -> value",
23558
24005
  type: ([x]) => x.type,
23559
24006
  sgn: ([x]) => oppositeSgn(x.sgn),
23560
24007
  canonical: (args, { engine }) => {
@@ -23767,6 +24214,20 @@ ${lines.join("\n")}`;
23767
24214
  (x2) => x2.round(0)
23768
24215
  )
23769
24216
  },
24217
+ /** Heaviside step function: H(x) = 0 for x < 0, 1/2 for x = 0, 1 for x > 0 */
24218
+ Heaviside: {
24219
+ complexity: 1200,
24220
+ broadcastable: true,
24221
+ signature: "(number) -> real",
24222
+ type: () => "finite_real",
24223
+ sgn: () => "non-negative",
24224
+ evaluate: ([x], { engine }) => {
24225
+ if (x.is(0)) return engine.Half;
24226
+ if (x.isPositive) return engine.One;
24227
+ if (x.isNegative) return engine.Zero;
24228
+ return void 0;
24229
+ }
24230
+ },
23770
24231
  Sign: {
23771
24232
  complexity: 1200,
23772
24233
  broadcastable: true,
@@ -28837,7 +29298,7 @@ ${e.message}
28837
29298
  ];
28838
29299
 
28839
29300
  // src/color/palette.ts
28840
- var FOREGROUND_COLORS = {
29301
+ var NAMED_COLORS = {
28841
29302
  "red": "#d7170b",
28842
29303
  //<- 700, 500 ->'#f21c0d'
28843
29304
  "orange": "#fe8a2b",
@@ -28851,11 +29312,31 @@ ${e.message}
28851
29312
  "indigo": "#63c",
28852
29313
  "purple": "#a219e6",
28853
29314
  "magenta": "#eb4799",
29315
+ "brown": "#8c564b",
29316
+ "olive": "#8a8f2a",
29317
+ "midnight": "#2c4670",
29318
+ "sky": "#d2dce9",
28854
29319
  "black": "#000",
29320
+ "white": "#ffffff",
29321
+ "carbon": "#111111",
29322
+ // near-black, high-contrast text
29323
+ "charcoal": "#333333",
29324
+ // primary axis / label color
29325
+ "slate": "#555555",
29326
+ // secondary text, major gridlines
28855
29327
  "dark-grey": "#666",
29328
+ "graphite": "#777777",
29329
+ // minor gridlines
29330
+ "stone": "#999999",
29331
+ // de-emphasized strokes
28856
29332
  "grey": "#A6A6A6",
28857
29333
  "light-grey": "#d4d5d2",
28858
- "white": "#ffffff"
29334
+ "ash": "#E6E6E6",
29335
+ // subtle fills, light strokes
29336
+ "mist": "#F3F3F3",
29337
+ // light background tint
29338
+ "snow": "#FFFFFF"
29339
+ // pure white
28859
29340
  };
28860
29341
 
28861
29342
  // src/color/manipulation.ts
@@ -29065,9 +29546,9 @@ ${e.message}
29065
29546
  }
29066
29547
  const lms = lmsFromLab(l, labA, labB);
29067
29548
  const lin = linSRGBFromLMS(lms);
29068
- let r = Math.max(0, Math.min(1, gammaCorrect(lin.r)));
29069
- let g = Math.max(0, Math.min(1, gammaCorrect(lin.g)));
29070
- let b = Math.max(0, Math.min(1, gammaCorrect(lin.b)));
29549
+ const r = Math.max(0, Math.min(1, gammaCorrect(lin.r)));
29550
+ const g = Math.max(0, Math.min(1, gammaCorrect(lin.g)));
29551
+ const b = Math.max(0, Math.min(1, gammaCorrect(lin.b)));
29071
29552
  const rByte = Math.round(r * 255);
29072
29553
  const gByte = Math.round(g * 255);
29073
29554
  const bByte = Math.round(b * 255);
@@ -29103,8 +29584,8 @@ ${e.message}
29103
29584
  return (r << 24 | g << 16 | b << 8 | a) >>> 0;
29104
29585
  }
29105
29586
  if (str === "transparent") return 0;
29106
- if (str in FOREGROUND_COLORS)
29107
- return parseColor(FOREGROUND_COLORS[str]);
29587
+ if (str in NAMED_COLORS)
29588
+ return parseColor(NAMED_COLORS[str]);
29108
29589
  console.warn(`parseColor: unrecognized color "${s}"`);
29109
29590
  return 0;
29110
29591
  }
@@ -31424,50 +31905,188 @@ ${e.message}
31424
31905
 
31425
31906
  // src/color/categorical.ts
31426
31907
  var TYCHO_11 = [
31427
- "#0d80f2",
31428
- // blue
31429
- "#d7170b",
31430
- // red
31431
- "#21ba3a",
31432
- // green
31433
- "#eb4799",
31434
- // magenta
31435
- "#13a7ec",
31436
- // cyan
31437
- "#fe8a2b",
31438
- // orange
31439
- "#17cfcf",
31440
- // teal
31441
- "#a219e6",
31442
- // purple
31443
- "#ffc02b",
31444
- // yellow
31445
- "#63b215",
31446
- // lime
31447
- "#663399"
31448
- // indigo
31449
- ];
31450
- var TABLEAU_10 = [
31451
31908
  "#4e79a7",
31452
31909
  // Blue
31453
31910
  "#f28e2b",
31454
31911
  // Orange
31912
+ "#59a14f",
31913
+ // Green
31455
31914
  "#e15759",
31456
31915
  // Red
31916
+ "#b07aa1",
31917
+ // Purple
31918
+ "#9c755f",
31919
+ // Brown
31920
+ "#ff9da7",
31921
+ // Pink
31922
+ "#edc948",
31923
+ // Yellow
31457
31924
  "#76b7b2",
31458
31925
  // Teal
31459
- "#59a14f",
31926
+ "#6b8fd6",
31927
+ // Steel Blue
31928
+ "#c07bc4"
31929
+ // Magenta
31930
+ ];
31931
+ var TYCHO_DARK_11 = [
31932
+ "#78a6d9",
31933
+ // Blue
31934
+ "#ffae54",
31935
+ // Orange
31936
+ "#7ddc7a",
31460
31937
  // Green
31461
- "#edc948",
31938
+ "#ff7a7a",
31939
+ // Red
31940
+ "#d29be0",
31941
+ // Purple
31942
+ "#c49a84",
31943
+ // Brown
31944
+ "#ffb3bf",
31945
+ // Pink
31946
+ "#ffe066",
31462
31947
  // Yellow
31948
+ "#7fd6d0",
31949
+ // Teal
31950
+ "#8fb4ff",
31951
+ // Steel Blue
31952
+ "#e199eb"
31953
+ // Magenta
31954
+ ];
31955
+ var TYCHO_ROBUST_11 = [
31956
+ "#4e79a7",
31957
+ // Blue
31958
+ "#f28e2b",
31959
+ // Orange
31960
+ "#2ca58d",
31961
+ // Teal-shifted green (more CB-safe)
31962
+ "#d13a3c",
31963
+ // Stronger red
31463
31964
  "#b07aa1",
31464
31965
  // Purple
31966
+ "#9c755f",
31967
+ // Brown
31465
31968
  "#ff9da7",
31466
31969
  // Pink
31467
- "#9c755f",
31970
+ "#e3c13b",
31971
+ // Darker yellow for contrast
31972
+ "#5fb8b2",
31973
+ // Teal
31974
+ "#6b8fd6",
31975
+ // Steel Blue
31976
+ "#c07bc4"
31977
+ // Magenta
31978
+ ];
31979
+ var TYCHO_SOFT_11 = [
31980
+ "#8fb1d4",
31981
+ "#f6b878",
31982
+ "#8ecf86",
31983
+ "#f08a8b",
31984
+ "#d3a9cc",
31985
+ "#c3a492",
31986
+ "#ffc6cc",
31987
+ "#f3e08a",
31988
+ "#a8d8d4",
31989
+ "#a9c0ea",
31990
+ "#e0b4e4"
31991
+ ];
31992
+ var TYCHO_SOFT_DARK_11 = [
31993
+ "#78a6d9",
31994
+ "#ffae54",
31995
+ "#7ddc7a",
31996
+ "#ff7a7a",
31997
+ "#d29be0",
31998
+ "#c49a84",
31999
+ "#ffb3bf",
32000
+ "#ffe066",
32001
+ "#7fd6d0",
32002
+ "#8fb4ff",
32003
+ "#e199eb"
32004
+ ];
32005
+ var TYCHO_BOLD_11 = [
32006
+ "#2f6fb0",
32007
+ "#ff7a00",
32008
+ "#2fa23a",
32009
+ "#e02f2f",
32010
+ "#9b4db5",
32011
+ "#7f4f38",
32012
+ "#ff6f86",
32013
+ "#f2c200",
32014
+ "#2daaa3",
32015
+ "#4c79e0",
32016
+ "#b84ac6"
32017
+ ];
32018
+ var TYCHO_BOLD_DARK_11 = [
32019
+ "#4f93ff",
32020
+ "#ff8c1a",
32021
+ "#33c94a",
32022
+ "#ff4f4f",
32023
+ "#b86bff",
32024
+ "#a86a4a",
32025
+ "#ff7f9e",
32026
+ "#ffd400",
32027
+ "#2ec9c1",
32028
+ "#6f9bff",
32029
+ "#cc5bd9"
32030
+ ];
32031
+ var MATHEMATICA_10 = [
32032
+ "#5E81B5",
32033
+ "#E19C24",
32034
+ "#8FB131",
32035
+ "#EB6235",
32036
+ "#8778B3",
32037
+ "#C56E1A",
32038
+ "#5E9EC9",
32039
+ "#B23A3A",
32040
+ "#4C9F70",
32041
+ "#C979B7"
32042
+ ];
32043
+ var TABLEAU_10 = [
32044
+ "#1f77b4",
32045
+ // Blue
32046
+ "#ff7f0e",
32047
+ // Orange
32048
+ "#2ca02c",
32049
+ // Green
32050
+ "#d62728",
32051
+ // Red
32052
+ "#9467bd",
32053
+ // Purple
32054
+ "#8c564b",
31468
32055
  // Brown
31469
- "#bab0ac"
32056
+ "#e377c2",
32057
+ // Pink
32058
+ "#7f7f7f",
31470
32059
  // Gray
32060
+ "#bcbd22",
32061
+ // Olive
32062
+ "#17becf"
32063
+ // Cyan
32064
+ ];
32065
+ var CUPERTINO_10 = [
32066
+ "#007AFF",
32067
+ "#FF9500",
32068
+ "#34C759",
32069
+ "#FF3B30",
32070
+ "#AF52DE",
32071
+ "#FF2D55",
32072
+ "#30B0C7",
32073
+ "#5856D6",
32074
+ "#A2845E",
32075
+ "#32ADE6",
32076
+ "#00C7BE"
32077
+ ];
32078
+ var CUPERTINO_DARK_10 = [
32079
+ "#0A84FF",
32080
+ "#FF9F0A",
32081
+ "#30D158",
32082
+ "#FF453A",
32083
+ "#BF5AF2",
32084
+ "#FF375F",
32085
+ "#40C8E0",
32086
+ "#5E5CE6",
32087
+ "#AC8E68",
32088
+ "#64D2FF",
32089
+ "#00D1C1"
31471
32090
  ];
31472
32091
  var KELLY_22 = [
31473
32092
  "#fdfdfd",
@@ -31515,28 +32134,6 @@ ${e.message}
31515
32134
  "#2b3514"
31516
32135
  // Olive green
31517
32136
  ];
31518
- var GRAPH_6 = [
31519
- "#2d6fb4",
31520
- // Blue
31521
- "#c84442",
31522
- // Red
31523
- "#398c46",
31524
- // Green
31525
- "#fa7d19",
31526
- // Orange
31527
- "#00beff",
31528
- // Light Blue
31529
- "#6042a6"
31530
- // Purple
31531
- ];
31532
- var SPECTRUM_6 = [
31533
- "#4148cc",
31534
- "#db3c80",
31535
- "#12b5b0",
31536
- "#ff8c14",
31537
- "#848aff",
31538
- "#78e16e"
31539
- ];
31540
32137
  var SPECTRUM_12 = [
31541
32138
  "#4148cc",
31542
32139
  "#db3c80",
@@ -31552,12 +32149,19 @@ ${e.message}
31552
32149
  "#00915f"
31553
32150
  ];
31554
32151
  var CATEGORICAL_PALETTES = {
31555
- tycho11: TYCHO_11,
31556
- tableau10: TABLEAU_10,
31557
- kelly22: KELLY_22,
31558
- graph6: GRAPH_6,
31559
- spectrum6: SPECTRUM_6,
31560
- spectrum12: SPECTRUM_12
32152
+ "tycho11": TYCHO_11,
32153
+ "tycho-dark11": TYCHO_DARK_11,
32154
+ "tycho-robust11": TYCHO_ROBUST_11,
32155
+ "tycho-soft11": TYCHO_SOFT_11,
32156
+ "tycho-soft-dark11": TYCHO_SOFT_DARK_11,
32157
+ "tycho-bold11": TYCHO_BOLD_11,
32158
+ "tycho-bold-dark11": TYCHO_BOLD_DARK_11,
32159
+ "tableau10": TABLEAU_10,
32160
+ "kelly22": KELLY_22,
32161
+ "mathematica10": MATHEMATICA_10,
32162
+ "cupertino10": CUPERTINO_10,
32163
+ "cupertino-dark10": CUPERTINO_DARK_10,
32164
+ "spectrum12": SPECTRUM_12
31561
32165
  };
31562
32166
 
31563
32167
  // src/color/diverging-palettes.ts
@@ -39854,6 +40458,29 @@ ${e.message}
39854
40458
  return ops[0].mul(options.engine.Pi.div(180)).evaluate(options);
39855
40459
  }
39856
40460
  },
40461
+ // DMS(degrees, minutes?, seconds?) — programmatic angle construction
40462
+ DMS: {
40463
+ signature: "(real, real?, real?) -> real",
40464
+ type: () => "finite_real",
40465
+ canonical: (ops, { engine: ce }) => {
40466
+ const deg = ops[0]?.re ?? NaN;
40467
+ const min3 = ops[1]?.re ?? 0;
40468
+ const sec2 = ops[2]?.re ?? 0;
40469
+ if (Number.isNaN(deg)) return ce._fn("DMS", ops);
40470
+ const total = deg + min3 / 60 + sec2 / 3600;
40471
+ return ce.function("Degrees", [ce.number(total)]);
40472
+ },
40473
+ evaluate: (ops, options) => {
40474
+ const ce = options.engine;
40475
+ const deg = ops[0]?.re ?? NaN;
40476
+ const min3 = ops[1]?.re ?? 0;
40477
+ const sec2 = ops[2]?.re ?? 0;
40478
+ if (Number.isNaN(deg)) return ce._fn("DMS", ops);
40479
+ const total = deg + min3 / 60 + sec2 / 3600;
40480
+ if (ce.angularUnit === "deg") return ce.number(total);
40481
+ return ce.number(total).div(180).mul(ce.Pi).evaluate(options);
40482
+ }
40483
+ },
39857
40484
  // Hypot: sqrt(x*x + y*y)
39858
40485
  Hypot: {
39859
40486
  broadcastable: true,
@@ -39955,6 +40582,39 @@ ${e.message}
39955
40582
  Arsech: trigFunction("Arsech", 6250),
39956
40583
  Arccsc: trigFunction("Arccsc", 5650),
39957
40584
  Coth: trigFunction("Coth", 6300),
40585
+ /** sinc(x) = sin(x)/x with sinc(0) = 1 (unnormalized cardinal sine) */
40586
+ Sinc: {
40587
+ complexity: 5100,
40588
+ broadcastable: true,
40589
+ signature: "(number) -> real",
40590
+ type: () => "finite_real",
40591
+ evaluate: ([x], { engine: ce }) => {
40592
+ if (!x || !isNumber(x)) return void 0;
40593
+ return ce.number(sinc(x.re));
40594
+ }
40595
+ },
40596
+ /** FresnelS(x) = ∫₀ˣ sin(πt²/2) dt — odd function, S(∞) = 1/2 */
40597
+ FresnelS: {
40598
+ complexity: 5200,
40599
+ broadcastable: true,
40600
+ signature: "(number) -> real",
40601
+ type: () => "finite_real",
40602
+ evaluate: ([x], { engine: ce }) => {
40603
+ if (!x || !isNumber(x)) return void 0;
40604
+ return ce.number(fresnelS(x.re));
40605
+ }
40606
+ },
40607
+ /** FresnelC(x) = ∫₀ˣ cos(πt²/2) dt — odd function, C(∞) = 1/2 */
40608
+ FresnelC: {
40609
+ complexity: 5200,
40610
+ broadcastable: true,
40611
+ signature: "(number) -> real",
40612
+ type: () => "finite_real",
40613
+ evaluate: ([x], { engine: ce }) => {
40614
+ if (!x || !isNumber(x)) return void 0;
40615
+ return ce.number(fresnelC(x.re));
40616
+ }
40617
+ },
39958
40618
  /* converts (radius, angle) -> (x, y) */
39959
40619
  // FromPolarCoordinates: {
39960
40620
  // domain: 'Function',
@@ -40038,6 +40698,61 @@ ${e.message}
40038
40698
  }
40039
40699
  ];
40040
40700
 
40701
+ // src/compute-engine/latex-syntax/serialize-dms.ts
40702
+ function normalizeAngle(degrees, mode2) {
40703
+ if (mode2 === "none") return degrees;
40704
+ if (mode2 === "0...360") {
40705
+ const normalized = degrees % 360;
40706
+ return (normalized < 0 ? normalized + 360 : normalized) || 0;
40707
+ }
40708
+ if (mode2 === "-180...180") {
40709
+ let normalized = degrees % 360;
40710
+ if (normalized > 180) normalized -= 360;
40711
+ if (normalized < -180) normalized += 360;
40712
+ return normalized || 0;
40713
+ }
40714
+ return degrees;
40715
+ }
40716
+ function degreesToDMS(totalDegrees) {
40717
+ const sign3 = totalDegrees < 0 ? -1 : 1;
40718
+ const absDegrees = Math.abs(totalDegrees);
40719
+ const deg = Math.floor(absDegrees);
40720
+ const minDecimal = (absDegrees - deg) * 60;
40721
+ const min3 = Math.floor(minDecimal);
40722
+ const secDecimal = (minDecimal - min3) * 60;
40723
+ let sec2 = Math.round(secDecimal * 1e3) / 1e3;
40724
+ let finalMin = min3;
40725
+ let finalDeg = deg;
40726
+ if (sec2 >= 60) {
40727
+ sec2 = 0;
40728
+ finalMin++;
40729
+ }
40730
+ if (finalMin >= 60) {
40731
+ finalMin = 0;
40732
+ finalDeg++;
40733
+ }
40734
+ return {
40735
+ deg: sign3 * finalDeg || 0,
40736
+ // Avoid -0
40737
+ min: sign3 * finalMin || 0,
40738
+ // Avoid -0
40739
+ sec: sec2 === 0 ? 0 : sign3 * sec2
40740
+ };
40741
+ }
40742
+ function formatDMS(degrees) {
40743
+ const { deg, min: min3, sec: sec2 } = degreesToDMS(degrees);
40744
+ let result = `${deg}\xB0`;
40745
+ if (Math.abs(sec2) > 1e-3) {
40746
+ const secStr = sec2 % 1 === 0 ? sec2.toString() : sec2.toFixed(2);
40747
+ result += `${Math.abs(min3)}'${Math.abs(Number(secStr))}"`;
40748
+ } else if (Math.abs(min3) > 0) {
40749
+ result += `${Math.abs(min3)}'`;
40750
+ } else {
40751
+ result += `0'0"`;
40752
+ }
40753
+ return result;
40754
+ }
40755
+
40041
40756
  // src/compute-engine/latex-syntax/dictionary/definitions-units.ts
40042
40757
  function readBracedText(parser) {
40043
40758
  if (!parser.match("<{>")) return null;
@@ -40205,6 +40920,29 @@ ${e.message}
40205
40920
  const magnitude = operand(expr, 1);
40206
40921
  const unit = operand(expr, 2);
40207
40922
  if (magnitude === null || unit === null) return "";
40923
+ const unitSymbol2 = symbol(unit);
40924
+ const isAngleUnit = unitSymbol2 === "deg" || unitSymbol2 === "rad" || unitSymbol2 === "arcmin" || unitSymbol2 === "arcsec";
40925
+ const options = serializer.options;
40926
+ if (isAngleUnit && (options.dmsFormat || options.angleNormalization && options.angleNormalization !== "none")) {
40927
+ const magnitudeValue = machineValue(magnitude);
40928
+ if (magnitudeValue === null) {
40929
+ const magLatex2 = serializer.serialize(magnitude);
40930
+ const unitStr2 = unitToMathrm(unit);
40931
+ return joinLatex([magLatex2, "\\,", `\\mathrm{${unitStr2}}`]);
40932
+ }
40933
+ let degrees = magnitudeValue;
40934
+ if (unitSymbol2 === "rad") {
40935
+ degrees = degrees * 180 / Math.PI;
40936
+ } else if (unitSymbol2 === "arcmin") {
40937
+ degrees = degrees / 60;
40938
+ } else if (unitSymbol2 === "arcsec") {
40939
+ degrees = degrees / 3600;
40940
+ }
40941
+ if (options.angleNormalization && options.angleNormalization !== "none")
40942
+ degrees = normalizeAngle(degrees, options.angleNormalization);
40943
+ if (options.dmsFormat) return formatDMS(degrees);
40944
+ return `${degrees}\xB0`;
40945
+ }
40208
40946
  const magLatex = serializer.serialize(magnitude);
40209
40947
  const unitStr = unitToMathrm(unit);
40210
40948
  return joinLatex([magLatex, "\\,", `\\mathrm{${unitStr}}`]);
@@ -40610,6 +41348,37 @@ ${e.message}
40610
41348
  serializer.serialize(exp3)
40611
41349
  );
40612
41350
  }
41351
+ function parseDMS(parser, lhs) {
41352
+ parser.skipSpace();
41353
+ const savepoint = parser.index;
41354
+ const minExpr = parser.parseNumber();
41355
+ let minNum = null;
41356
+ let secNum = null;
41357
+ if (minExpr !== null && (parser.match("'") || parser.match("\\prime"))) {
41358
+ minNum = machineValue(minExpr);
41359
+ parser.skipSpace();
41360
+ const secSavepoint = parser.index;
41361
+ const secExpr = parser.parseNumber();
41362
+ if (secExpr !== null && (parser.match('"') || parser.match("\\doubleprime"))) {
41363
+ secNum = machineValue(secExpr);
41364
+ } else {
41365
+ parser.index = secSavepoint;
41366
+ }
41367
+ } else {
41368
+ parser.index = savepoint;
41369
+ return ["Degrees", lhs];
41370
+ }
41371
+ const degNum = machineValue(lhs);
41372
+ if (degNum !== null && minNum !== null) {
41373
+ let total = degNum + minNum / 60;
41374
+ if (secNum !== null) total += secNum / 3600;
41375
+ return ["Degrees", total];
41376
+ }
41377
+ const parts = [["Quantity", lhs, "deg"]];
41378
+ parts.push(["Quantity", minExpr, "arcmin"]);
41379
+ if (secNum !== null) parts.push(["Quantity", secNum, "arcsec"]);
41380
+ return ["Add", ...parts];
41381
+ }
40613
41382
  var DEFINITIONS_ARITHMETIC = [
40614
41383
  // Constants
40615
41384
  { name: "CatalanConstant", symbolTrigger: "G" },
@@ -40620,32 +41389,48 @@ ${e.message}
40620
41389
  latexTrigger: ["\\degree"],
40621
41390
  kind: "postfix",
40622
41391
  precedence: 880,
40623
- parse: (_parser, lhs) => ["Degrees", lhs],
41392
+ parse: (parser, lhs) => parseDMS(parser, lhs),
40624
41393
  serialize: (serializer, expr) => {
40625
- return joinLatex([serializer.serialize(operand(expr, 1)), "\\degree"]);
41394
+ const options = serializer.options;
41395
+ const arg = operand(expr, 1);
41396
+ if (options.dmsFormat || options.angleNormalization && options.angleNormalization !== "none") {
41397
+ const argValue = machineValue(arg);
41398
+ if (argValue !== null) {
41399
+ let degrees = argValue;
41400
+ if (options.angleNormalization && options.angleNormalization !== "none")
41401
+ degrees = normalizeAngle(degrees, options.angleNormalization);
41402
+ if (options.dmsFormat) return formatDMS(degrees);
41403
+ return `${degrees}\xB0`;
41404
+ }
41405
+ }
41406
+ return joinLatex([serializer.serialize(arg), "\\degree"]);
40626
41407
  }
40627
41408
  },
40628
41409
  {
40629
41410
  latexTrigger: ["\\degree"],
40630
41411
  kind: "postfix",
40631
41412
  precedence: 880,
40632
- parse: (_parser, lhs) => ["Degrees", lhs]
41413
+ parse: (parser, lhs) => parseDMS(parser, lhs)
40633
41414
  },
41415
+ // No `precedence` on these entries: the dictionary validator
41416
+ // (definitions.ts:947-968) rejects `precedence` on entries whose
41417
+ // `latexTrigger` starts with `^` or `_`, since their binding is
41418
+ // governed by LaTeX grouping rules, not operator precedence.
40634
41419
  {
40635
41420
  latexTrigger: ["^", "<{>", "\\circ", "<}>"],
40636
41421
  kind: "postfix",
40637
- parse: (_parser, lhs) => ["Degrees", lhs]
41422
+ parse: (parser, lhs) => parseDMS(parser, lhs)
40638
41423
  },
40639
41424
  {
40640
41425
  latexTrigger: ["^", "\\circ"],
40641
41426
  kind: "postfix",
40642
- parse: (_parser, lhs) => ["Degrees", lhs]
41427
+ parse: (parser, lhs) => parseDMS(parser, lhs)
40643
41428
  },
40644
41429
  {
40645
41430
  latexTrigger: ["\xB0"],
40646
41431
  kind: "postfix",
40647
41432
  precedence: 880,
40648
- parse: (_parser, lhs) => ["Degrees", lhs]
41433
+ parse: (parser, lhs) => parseDMS(parser, lhs)
40649
41434
  },
40650
41435
  {
40651
41436
  latexTrigger: ["\\ang"],
@@ -40654,6 +41439,28 @@ ${e.message}
40654
41439
  return arg === null ? ["Degrees"] : ["Degrees", arg];
40655
41440
  }
40656
41441
  },
41442
+ {
41443
+ name: "DMS",
41444
+ serialize: (serializer, expr) => {
41445
+ const deg = machineValue(operand(expr, 1));
41446
+ const min3 = machineValue(operand(expr, 2));
41447
+ const sec2 = machineValue(operand(expr, 3));
41448
+ if (deg !== null) {
41449
+ const m = min3 ?? 0;
41450
+ const s = sec2 ?? 0;
41451
+ let result = `${deg}\xB0`;
41452
+ if (m !== 0 || s !== 0) result += `${m}'`;
41453
+ if (s !== 0) result += `${s}"`;
41454
+ return result;
41455
+ }
41456
+ const args = [];
41457
+ for (const i of [1, 2, 3]) {
41458
+ const op = operand(expr, i);
41459
+ if (op !== void 0) args.push(serializer.serialize(op));
41460
+ }
41461
+ return `\\operatorname{DMS}(${args.join(", ")})`;
41462
+ }
41463
+ },
40657
41464
  {
40658
41465
  latexTrigger: ["\\infty"],
40659
41466
  parse: "PositiveInfinity"
@@ -41389,6 +42196,11 @@ ${e.message}
41389
42196
  parse: parseBigOp("Sum", "Add", MULTIPLICATION_PRECEDENCE),
41390
42197
  serialize: serializeBigOp("\\sum")
41391
42198
  },
42199
+ {
42200
+ name: "Heaviside",
42201
+ symbolTrigger: "Heaviside",
42202
+ kind: "function"
42203
+ },
41392
42204
  {
41393
42205
  name: "Sign",
41394
42206
  // As per ISO 80000-2, "signum" is 'sgn'
@@ -44274,6 +45086,21 @@ ${e.message}
44274
45086
  name: "Sin",
44275
45087
  latexTrigger: ["\\sin"],
44276
45088
  parse: parseTrig("Sin")
45089
+ },
45090
+ {
45091
+ name: "Sinc",
45092
+ symbolTrigger: "sinc",
45093
+ kind: "function"
45094
+ },
45095
+ {
45096
+ name: "FresnelS",
45097
+ symbolTrigger: "FresnelS",
45098
+ kind: "function"
45099
+ },
45100
+ {
45101
+ name: "FresnelC",
45102
+ symbolTrigger: "FresnelC",
45103
+ kind: "function"
44277
45104
  }
44278
45105
  ];
44279
45106
 
@@ -54158,6 +54985,17 @@ Error in definition of "${name}"`,
54158
54985
  return `(${args.map((arg) => _BaseCompiler.compile(arg, target, prec)).join(", ")})`;
54159
54986
  }
54160
54987
  if (h === "Sum" || h === "Product") {
54988
+ const sumProdFn = target.functions?.(h);
54989
+ if (typeof sumProdFn === "function") {
54990
+ return sumProdFn(
54991
+ args,
54992
+ (expr) => _BaseCompiler.compile(expr, target),
54993
+ target
54994
+ );
54995
+ }
54996
+ if (typeof sumProdFn === "string") {
54997
+ return `${sumProdFn}(${args.map((x) => _BaseCompiler.compile(x, target)).join(", ")})`;
54998
+ }
54161
54999
  return _BaseCompiler.compileLoop(h, args, target);
54162
55000
  }
54163
55001
  const op = target.operators?.(h);
@@ -54166,7 +55004,6 @@ Error in definition of "${name}"`,
54166
55004
  if (!hasComplex) {
54167
55005
  const isFunction4 = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(op[0]);
54168
55006
  if (isFunction4) {
54169
- if (args === null) return `${op[0]}()`;
54170
55007
  return `${op[0]}(${args.map((arg) => _BaseCompiler.compile(arg, target)).join(", ")})`;
54171
55008
  } else {
54172
55009
  if (args.every((x) => !x.isCollection)) {
@@ -54185,7 +55022,6 @@ Error in definition of "${name}"`,
54185
55022
  }
54186
55023
  return `(${result.join(") && (")})`;
54187
55024
  }
54188
- if (args === null) return "";
54189
55025
  let resultStr;
54190
55026
  if (args.length === 1) {
54191
55027
  resultStr = `${op[0]}${_BaseCompiler.compile(args[0], target, op[1])}`;
@@ -54213,6 +55049,9 @@ Error in definition of "${name}"`,
54213
55049
  return `${isSymbol2(args[0]) ? args[0].symbol : "_"} = ${_BaseCompiler.compile(args[1], target)}`;
54214
55050
  if (h === "Return")
54215
55051
  return `return ${_BaseCompiler.compile(args[0], target)}`;
55052
+ if (h === "Break") return "break";
55053
+ if (h === "Continue") return "continue";
55054
+ if (h === "Loop") return _BaseCompiler.compileForLoop(args, target);
54216
55055
  if (h === "If") {
54217
55056
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
54218
55057
  const fn2 = target.functions?.(h);
@@ -54220,7 +55059,6 @@ Error in definition of "${name}"`,
54220
55059
  if (typeof fn2 === "function") {
54221
55060
  return fn2(args, (expr) => _BaseCompiler.compile(expr, target), target);
54222
55061
  }
54223
- if (args === null) return `${fn2}()`;
54224
55062
  return `${fn2}(${args.map((x) => _BaseCompiler.compile(x, target)).join(", ")})`;
54225
55063
  }
54226
55064
  return `((${_BaseCompiler.compile(args[0], target)}) ? (${_BaseCompiler.compile(
@@ -54228,6 +55066,29 @@ Error in definition of "${name}"`,
54228
55066
  target
54229
55067
  )}) : (${_BaseCompiler.compile(args[2], target)}))`;
54230
55068
  }
55069
+ if (h === "Which") {
55070
+ if (args.length < 2 || args.length % 2 !== 0)
55071
+ throw new Error(
55072
+ "Which: expected even number of arguments (condition/value pairs)"
55073
+ );
55074
+ const fn2 = target.functions?.(h);
55075
+ if (fn2) {
55076
+ if (typeof fn2 === "function") {
55077
+ return fn2(args, (expr) => _BaseCompiler.compile(expr, target), target);
55078
+ }
55079
+ return `${fn2}(${args.map((x) => _BaseCompiler.compile(x, target)).join(", ")})`;
55080
+ }
55081
+ const compilePair = (i) => {
55082
+ if (i >= args.length) return "NaN";
55083
+ const cond = args[i];
55084
+ const val = args[i + 1];
55085
+ if (isSymbol2(cond) && cond.symbol === "True") {
55086
+ return `(${_BaseCompiler.compile(val, target)})`;
55087
+ }
55088
+ return `((${_BaseCompiler.compile(cond, target)}) ? (${_BaseCompiler.compile(val, target)}) : ${compilePair(i + 2)})`;
55089
+ };
55090
+ return compilePair(0);
55091
+ }
54231
55092
  if (h === "Block") {
54232
55093
  return _BaseCompiler.compileBlock(args, target);
54233
55094
  }
@@ -54245,7 +55106,6 @@ Error in definition of "${name}"`,
54245
55106
  }
54246
55107
  return fn(args, (expr) => _BaseCompiler.compile(expr, target), target);
54247
55108
  }
54248
- if (args === null) return `${fn}()`;
54249
55109
  return `${fn}(${args.map((x) => _BaseCompiler.compile(x, target)).join(", ")})`;
54250
55110
  }
54251
55111
  /**
@@ -54276,11 +55136,109 @@ Error in definition of "${name}"`,
54276
55136
  `;${target.ws("\n")}`
54277
55137
  )}${target.ws("\n")}})()`;
54278
55138
  }
55139
+ /**
55140
+ * Compile a Loop expression with Element(index, Range(lo, hi)) indexing.
55141
+ * Generates: (() => { for (let i = lo; i <= hi; i++) { body } })()
55142
+ *
55143
+ * The loop counter is always a raw number. For targets that wrap numeric
55144
+ * values (e.g. interval-js wraps with `_IA.point()`), references to the
55145
+ * loop index inside the body are wrapped via `target.number`.
55146
+ */
55147
+ static compileForLoop(args, target) {
55148
+ if (!args[0]) throw new Error("Loop: no body");
55149
+ if (!args[1]) throw new Error("Loop: no indexing set");
55150
+ const indexing = args[1];
55151
+ if (indexing.operator !== "Element" || !isFunction2(indexing))
55152
+ throw new Error("Loop: expected Element(index, Range(lo, hi))");
55153
+ const indexExpr = indexing.ops[0];
55154
+ const rangeExpr = indexing.ops[1];
55155
+ if (!isSymbol2(indexExpr)) throw new Error("Loop: index must be a symbol");
55156
+ if (rangeExpr.operator !== "Range" || !isFunction2(rangeExpr))
55157
+ throw new Error("Loop: expected Range(lo, hi)");
55158
+ const index = indexExpr.symbol;
55159
+ const lower = Math.floor(rangeExpr.ops[0].re);
55160
+ const upper = Math.floor(rangeExpr.ops[1].re);
55161
+ if (!Number.isFinite(lower) || !Number.isFinite(upper))
55162
+ throw new Error("Loop: bounds must be finite numbers");
55163
+ const needsWrap = target.number(0) !== "0";
55164
+ const bodyTarget = {
55165
+ ...target,
55166
+ var: (id) => id === index ? needsWrap ? target.number(0).replace("0", index) : index : target.var(id)
55167
+ };
55168
+ const bodyStmts = _BaseCompiler.compileLoopBody(args[0], bodyTarget);
55169
+ return `(() => {${target.ws("\n")}for (let ${index} = ${lower}; ${index} <= ${upper}; ${index}++) {${target.ws("\n")}${bodyStmts}${target.ws("\n")}}${target.ws("\n")}})()`;
55170
+ }
55171
+ /**
55172
+ * Compile a loop body expression as statements (not wrapped in IIFE).
55173
+ * Handles Break, Continue, Return as statements, and If as if-else when
55174
+ * branches contain control flow.
55175
+ */
55176
+ static compileLoopBody(expr, target) {
55177
+ if (isSymbol2(expr) && expr.symbol === "Nothing") return "";
55178
+ if (!isFunction2(expr)) return _BaseCompiler.compile(expr, target);
55179
+ const h = expr.operator;
55180
+ if (h === "Break") return "break";
55181
+ if (h === "Continue") return "continue";
55182
+ if (h === "Return")
55183
+ return `return ${_BaseCompiler.compile(expr.ops[0], target)}`;
55184
+ if (h === "If") {
55185
+ const condTarget = _BaseCompiler.scalarConditionTarget(target);
55186
+ const cond = _BaseCompiler.compile(expr.ops[0], condTarget);
55187
+ const thenBranch = _BaseCompiler.compileLoopBody(expr.ops[1], target);
55188
+ if (expr.ops.length > 2) {
55189
+ const elseBranch = _BaseCompiler.compileLoopBody(expr.ops[2], target);
55190
+ if (elseBranch)
55191
+ return `if (${cond}) { ${thenBranch} } else { ${elseBranch} }`;
55192
+ }
55193
+ return `if (${cond}) { ${thenBranch} }`;
55194
+ }
55195
+ if (h === "Block") {
55196
+ return expr.ops.map((s) => _BaseCompiler.compileLoopBody(s, target)).join("; ");
55197
+ }
55198
+ return _BaseCompiler.compile(expr, target);
55199
+ }
55200
+ /**
55201
+ * Create a target that compiles conditions as plain JS booleans.
55202
+ * Used inside `compileLoopBody` so that `if (cond)` gets a real boolean,
55203
+ * not an interval result object (which would always be truthy).
55204
+ *
55205
+ * Overrides comparison and logical operators to use plain JS, and
55206
+ * numeric values/variables to use raw numbers (the loop counter is
55207
+ * already a plain number).
55208
+ */
55209
+ static scalarConditionTarget(target) {
55210
+ const SCALAR_OPS = {
55211
+ Less: ["<", 20],
55212
+ Greater: [">", 20],
55213
+ LessEqual: ["<=", 20],
55214
+ GreaterEqual: [">=", 20],
55215
+ Equal: ["===", 20],
55216
+ NotEqual: ["!==", 20],
55217
+ And: ["&&", 6],
55218
+ Or: ["||", 5],
55219
+ Not: ["!", 16]
55220
+ };
55221
+ if (target.number(0) === "0") return target;
55222
+ return {
55223
+ ...target,
55224
+ number: (n) => String(n),
55225
+ var: (id) => {
55226
+ const resolved = target.var(id);
55227
+ if (!resolved) return void 0;
55228
+ const match2 = resolved.match(/^_IA\.point\((.+)\)$/);
55229
+ return match2 ? match2[1] : resolved;
55230
+ },
55231
+ operators: (op) => SCALAR_OPS[op] ?? target.operators?.(op),
55232
+ functions: (id) => {
55233
+ if (id in SCALAR_OPS) return void 0;
55234
+ return target.functions?.(id);
55235
+ }
55236
+ };
55237
+ }
54279
55238
  /**
54280
55239
  * Compile loop constructs (Sum/Product)
54281
55240
  */
54282
55241
  static compileLoop(h, args, target) {
54283
- if (args === null) throw new Error("Sum/Product: no arguments");
54284
55242
  if (!args[0]) throw new Error("Sum/Product: no body");
54285
55243
  const {
54286
55244
  index,
@@ -54532,6 +55490,8 @@ Error in definition of "${name}"`,
54532
55490
  GCD: "_SYS.gcd",
54533
55491
  Integrate: (args, compile3, target) => compileIntegrate(args, compile3, target),
54534
55492
  LCM: "_SYS.lcm",
55493
+ Product: (args, compile3, target) => compileSumProduct("Product", args, compile3, target),
55494
+ Sum: (args, compile3, target) => compileSumProduct("Sum", args, compile3, target),
54535
55495
  Limit: (args, compile3) => `_SYS.limit(${compile3(args[0])}, ${compile3(args[1])})`,
54536
55496
  Ln: (args, compile3) => {
54537
55497
  if (BaseCompiler.isComplexValued(args[0]))
@@ -54683,7 +55643,11 @@ Error in definition of "${name}"`,
54683
55643
  if (BaseCompiler.isComplexValued(arg)) return `_SYS.csech(${compile3(arg)})`;
54684
55644
  return `1 / Math.cosh(${compile3(arg)})`;
54685
55645
  },
55646
+ Heaviside: "_SYS.heaviside",
54686
55647
  Sign: "Math.sign",
55648
+ Sinc: "_SYS.sinc",
55649
+ FresnelS: "_SYS.fresnelS",
55650
+ FresnelC: "_SYS.fresnelC",
54687
55651
  Sin: (args, compile3) => {
54688
55652
  if (BaseCompiler.isComplexValued(args[0]))
54689
55653
  return `_SYS.csin(${compile3(args[0])})`;
@@ -55085,9 +56049,18 @@ Error in definition of "${name}"`,
55085
56049
  const pos = t * (colors.length - 1);
55086
56050
  const i = Math.floor(pos);
55087
56051
  const frac = pos - i;
55088
- if (frac === 0 || i >= colors.length - 1) return [...colors[Math.min(i, colors.length - 1)]];
55089
- const rgb1 = { r: colors[i][0] * 255, g: colors[i][1] * 255, b: colors[i][2] * 255 };
55090
- const rgb2 = { r: colors[i + 1][0] * 255, g: colors[i + 1][1] * 255, b: colors[i + 1][2] * 255 };
56052
+ if (frac === 0 || i >= colors.length - 1)
56053
+ return [...colors[Math.min(i, colors.length - 1)]];
56054
+ const rgb1 = {
56055
+ r: colors[i][0] * 255,
56056
+ g: colors[i][1] * 255,
56057
+ b: colors[i][2] * 255
56058
+ };
56059
+ const rgb2 = {
56060
+ r: colors[i + 1][0] * 255,
56061
+ g: colors[i + 1][1] * 255,
56062
+ b: colors[i + 1][2] * 255
56063
+ };
55091
56064
  const c1 = rgbToOklch(rgb1);
55092
56065
  const c2 = rgbToOklch(rgb2);
55093
56066
  let dh = c2.H - c1.H;
@@ -55136,82 +56109,87 @@ Error in definition of "${name}"`,
55136
56109
  return result;
55137
56110
  }
55138
56111
  };
56112
+ var SYS_HELPERS = {
56113
+ chop,
56114
+ factorial: factorial2,
56115
+ factorial2: factorial22,
56116
+ gamma: gamma2,
56117
+ gcd,
56118
+ heaviside: (x) => x < 0 ? 0 : x === 0 ? 0.5 : 1,
56119
+ integrate: (f, a, b) => monteCarloEstimate(f, a, b, 1e7).estimate,
56120
+ lcm,
56121
+ lngamma: gammaln2,
56122
+ limit,
56123
+ mean,
56124
+ median,
56125
+ variance,
56126
+ populationVariance,
56127
+ standardDeviation,
56128
+ populationStandardDeviation,
56129
+ kurtosis,
56130
+ skewness,
56131
+ mode,
56132
+ quartiles,
56133
+ interquartileRange,
56134
+ erf,
56135
+ erfc,
56136
+ erfInv,
56137
+ beta,
56138
+ digamma,
56139
+ trigamma,
56140
+ polygamma,
56141
+ zeta,
56142
+ lambertW,
56143
+ besselJ,
56144
+ besselY,
56145
+ besselI,
56146
+ besselK,
56147
+ airyAi,
56148
+ airyBi,
56149
+ sinc,
56150
+ fresnelS,
56151
+ fresnelC,
56152
+ binomial: choose,
56153
+ fibonacci,
56154
+ // Complex helpers
56155
+ csin: (z) => toRI(new Complex(z.re, z.im).sin()),
56156
+ ccos: (z) => toRI(new Complex(z.re, z.im).cos()),
56157
+ ctan: (z) => toRI(new Complex(z.re, z.im).tan()),
56158
+ casin: (z) => toRI(new Complex(z.re, z.im).asin()),
56159
+ cacos: (z) => toRI(new Complex(z.re, z.im).acos()),
56160
+ catan: (z) => toRI(new Complex(z.re, z.im).atan()),
56161
+ csinh: (z) => toRI(new Complex(z.re, z.im).sinh()),
56162
+ ccosh: (z) => toRI(new Complex(z.re, z.im).cosh()),
56163
+ ctanh: (z) => toRI(new Complex(z.re, z.im).tanh()),
56164
+ csqrt: (z) => toRI(new Complex(z.re, z.im).sqrt()),
56165
+ cexp: (z) => toRI(new Complex(z.re, z.im).exp()),
56166
+ cln: (z) => toRI(new Complex(z.re, z.im).log()),
56167
+ cpow: (z, w) => {
56168
+ const zz = typeof z === "number" ? new Complex(z, 0) : new Complex(z.re, z.im);
56169
+ const ww = typeof w === "number" ? new Complex(w, 0) : new Complex(w.re, w.im);
56170
+ return toRI(zz.pow(ww));
56171
+ },
56172
+ ccot: (z) => toRI(new Complex(z.re, z.im).cot()),
56173
+ csec: (z) => toRI(new Complex(z.re, z.im).sec()),
56174
+ ccsc: (z) => toRI(new Complex(z.re, z.im).csc()),
56175
+ ccoth: (z) => toRI(new Complex(z.re, z.im).coth()),
56176
+ csech: (z) => toRI(new Complex(z.re, z.im).sech()),
56177
+ ccsch: (z) => toRI(new Complex(z.re, z.im).csch()),
56178
+ cacot: (z) => toRI(new Complex(z.re, z.im).acot()),
56179
+ casec: (z) => toRI(new Complex(z.re, z.im).asec()),
56180
+ cacsc: (z) => toRI(new Complex(z.re, z.im).acsc()),
56181
+ cacoth: (z) => toRI(new Complex(z.re, z.im).acoth()),
56182
+ casech: (z) => toRI(new Complex(z.re, z.im).asech()),
56183
+ cacsch: (z) => toRI(new Complex(z.re, z.im).acsch()),
56184
+ cabs: (z) => new Complex(z.re, z.im).abs(),
56185
+ carg: (z) => new Complex(z.re, z.im).arg(),
56186
+ cconj: (z) => toRI(new Complex(z.re, z.im).conjugate()),
56187
+ cneg: (z) => ({ re: -z.re, im: -z.im }),
56188
+ // Color helpers
56189
+ ...colorHelpers
56190
+ };
55139
56191
  var ComputeEngineFunction = class extends Function {
55140
- SYS = {
55141
- chop,
55142
- factorial: factorial2,
55143
- factorial2: factorial22,
55144
- gamma: gamma2,
55145
- gcd,
55146
- integrate: (f, a, b) => monteCarloEstimate(f, a, b, 1e7).estimate,
55147
- lcm,
55148
- lngamma: gammaln2,
55149
- limit,
55150
- mean,
55151
- median,
55152
- variance,
55153
- populationVariance,
55154
- standardDeviation,
55155
- populationStandardDeviation,
55156
- kurtosis,
55157
- skewness,
55158
- mode,
55159
- quartiles,
55160
- interquartileRange,
55161
- erf,
55162
- erfc,
55163
- erfInv,
55164
- beta,
55165
- digamma,
55166
- trigamma,
55167
- polygamma,
55168
- zeta,
55169
- lambertW,
55170
- besselJ,
55171
- besselY,
55172
- besselI,
55173
- besselK,
55174
- airyAi,
55175
- airyBi,
55176
- binomial: choose,
55177
- fibonacci,
55178
- // Complex helpers
55179
- csin: (z) => toRI(new Complex(z.re, z.im).sin()),
55180
- ccos: (z) => toRI(new Complex(z.re, z.im).cos()),
55181
- ctan: (z) => toRI(new Complex(z.re, z.im).tan()),
55182
- casin: (z) => toRI(new Complex(z.re, z.im).asin()),
55183
- cacos: (z) => toRI(new Complex(z.re, z.im).acos()),
55184
- catan: (z) => toRI(new Complex(z.re, z.im).atan()),
55185
- csinh: (z) => toRI(new Complex(z.re, z.im).sinh()),
55186
- ccosh: (z) => toRI(new Complex(z.re, z.im).cosh()),
55187
- ctanh: (z) => toRI(new Complex(z.re, z.im).tanh()),
55188
- csqrt: (z) => toRI(new Complex(z.re, z.im).sqrt()),
55189
- cexp: (z) => toRI(new Complex(z.re, z.im).exp()),
55190
- cln: (z) => toRI(new Complex(z.re, z.im).log()),
55191
- cpow: (z, w) => {
55192
- const zz = typeof z === "number" ? new Complex(z, 0) : new Complex(z.re, z.im);
55193
- const ww = typeof w === "number" ? new Complex(w, 0) : new Complex(w.re, w.im);
55194
- return toRI(zz.pow(ww));
55195
- },
55196
- ccot: (z) => toRI(new Complex(z.re, z.im).cot()),
55197
- csec: (z) => toRI(new Complex(z.re, z.im).sec()),
55198
- ccsc: (z) => toRI(new Complex(z.re, z.im).csc()),
55199
- ccoth: (z) => toRI(new Complex(z.re, z.im).coth()),
55200
- csech: (z) => toRI(new Complex(z.re, z.im).sech()),
55201
- ccsch: (z) => toRI(new Complex(z.re, z.im).csch()),
55202
- cacot: (z) => toRI(new Complex(z.re, z.im).acot()),
55203
- casec: (z) => toRI(new Complex(z.re, z.im).asec()),
55204
- cacsc: (z) => toRI(new Complex(z.re, z.im).acsc()),
55205
- cacoth: (z) => toRI(new Complex(z.re, z.im).acoth()),
55206
- casech: (z) => toRI(new Complex(z.re, z.im).asech()),
55207
- cacsch: (z) => toRI(new Complex(z.re, z.im).acsch()),
55208
- cabs: (z) => new Complex(z.re, z.im).abs(),
55209
- carg: (z) => new Complex(z.re, z.im).arg(),
55210
- cconj: (z) => toRI(new Complex(z.re, z.im).conjugate()),
55211
- cneg: (z) => ({ re: -z.re, im: -z.im }),
55212
- // Color helpers
55213
- ...colorHelpers
55214
- };
56192
+ SYS = SYS_HELPERS;
55215
56193
  constructor(body, preamble = "") {
55216
56194
  super(
55217
56195
  "_SYS",
@@ -55229,81 +56207,7 @@ Error in definition of "${name}"`,
55229
56207
  }
55230
56208
  };
55231
56209
  var ComputeEngineFunctionLiteral = class extends Function {
55232
- SYS = {
55233
- chop,
55234
- factorial: factorial2,
55235
- factorial2: factorial22,
55236
- gamma: gamma2,
55237
- gcd,
55238
- integrate: (f, a, b) => monteCarloEstimate(f, a, b, 1e7).estimate,
55239
- lcm,
55240
- lngamma: gammaln2,
55241
- limit,
55242
- mean,
55243
- median,
55244
- variance,
55245
- populationVariance,
55246
- standardDeviation,
55247
- populationStandardDeviation,
55248
- kurtosis,
55249
- skewness,
55250
- mode,
55251
- quartiles,
55252
- interquartileRange,
55253
- erf,
55254
- erfc,
55255
- erfInv,
55256
- beta,
55257
- digamma,
55258
- trigamma,
55259
- polygamma,
55260
- zeta,
55261
- lambertW,
55262
- besselJ,
55263
- besselY,
55264
- besselI,
55265
- besselK,
55266
- airyAi,
55267
- airyBi,
55268
- binomial: choose,
55269
- fibonacci,
55270
- // Complex helpers
55271
- csin: (z) => toRI(new Complex(z.re, z.im).sin()),
55272
- ccos: (z) => toRI(new Complex(z.re, z.im).cos()),
55273
- ctan: (z) => toRI(new Complex(z.re, z.im).tan()),
55274
- casin: (z) => toRI(new Complex(z.re, z.im).asin()),
55275
- cacos: (z) => toRI(new Complex(z.re, z.im).acos()),
55276
- catan: (z) => toRI(new Complex(z.re, z.im).atan()),
55277
- csinh: (z) => toRI(new Complex(z.re, z.im).sinh()),
55278
- ccosh: (z) => toRI(new Complex(z.re, z.im).cosh()),
55279
- ctanh: (z) => toRI(new Complex(z.re, z.im).tanh()),
55280
- csqrt: (z) => toRI(new Complex(z.re, z.im).sqrt()),
55281
- cexp: (z) => toRI(new Complex(z.re, z.im).exp()),
55282
- cln: (z) => toRI(new Complex(z.re, z.im).log()),
55283
- cpow: (z, w) => {
55284
- const zz = typeof z === "number" ? new Complex(z, 0) : new Complex(z.re, z.im);
55285
- const ww = typeof w === "number" ? new Complex(w, 0) : new Complex(w.re, w.im);
55286
- return toRI(zz.pow(ww));
55287
- },
55288
- ccot: (z) => toRI(new Complex(z.re, z.im).cot()),
55289
- csec: (z) => toRI(new Complex(z.re, z.im).sec()),
55290
- ccsc: (z) => toRI(new Complex(z.re, z.im).csc()),
55291
- ccoth: (z) => toRI(new Complex(z.re, z.im).coth()),
55292
- csech: (z) => toRI(new Complex(z.re, z.im).sech()),
55293
- ccsch: (z) => toRI(new Complex(z.re, z.im).csch()),
55294
- cacot: (z) => toRI(new Complex(z.re, z.im).acot()),
55295
- casec: (z) => toRI(new Complex(z.re, z.im).asec()),
55296
- cacsc: (z) => toRI(new Complex(z.re, z.im).acsc()),
55297
- cacoth: (z) => toRI(new Complex(z.re, z.im).acoth()),
55298
- casech: (z) => toRI(new Complex(z.re, z.im).asech()),
55299
- cacsch: (z) => toRI(new Complex(z.re, z.im).acsch()),
55300
- cabs: (z) => new Complex(z.re, z.im).abs(),
55301
- carg: (z) => new Complex(z.re, z.im).arg(),
55302
- cconj: (z) => toRI(new Complex(z.re, z.im).conjugate()),
55303
- cneg: (z) => ({ re: -z.re, im: -z.im }),
55304
- // Color helpers
55305
- ...colorHelpers
55306
- };
56210
+ SYS = SYS_HELPERS;
55307
56211
  constructor(body, args) {
55308
56212
  super("_SYS", ...args, `return ${body}`);
55309
56213
  return new Proxy(this, {
@@ -55353,7 +56257,14 @@ Error in definition of "${name}"`,
55353
56257
  };
55354
56258
  }
55355
56259
  compile(expr, options = {}) {
55356
- const { operators, functions, vars, imports = [], preamble } = options;
56260
+ const {
56261
+ operators,
56262
+ functions,
56263
+ vars,
56264
+ imports = [],
56265
+ preamble,
56266
+ realOnly
56267
+ } = options;
55357
56268
  const unknowns = expr.unknowns;
55358
56269
  let preambleImports = imports.map((x) => {
55359
56270
  if (typeof x === "function") return x.toString();
@@ -55406,10 +56317,21 @@ Error in definition of "${name}"`,
55406
56317
  },
55407
56318
  preamble: (preamble ?? "") + preambleImports
55408
56319
  });
55409
- return compileToTarget(expr, target);
56320
+ return compileToTarget(expr, target, realOnly);
55410
56321
  }
55411
56322
  };
55412
- function compileToTarget(expr, target) {
56323
+ function wrapRealOnly(result) {
56324
+ if (!result.run) return result;
56325
+ const origRun = result.run;
56326
+ result.run = ((...args) => {
56327
+ const r = origRun(...args);
56328
+ if (typeof r === "object" && r !== null && "im" in r)
56329
+ return r.im === 0 ? r.re : NaN;
56330
+ return r;
56331
+ });
56332
+ return result;
56333
+ }
56334
+ function compileToTarget(expr, target, realOnly) {
55413
56335
  if (expr.operator === "Function" && isFunction2(expr)) {
55414
56336
  const args = expr.ops;
55415
56337
  const params = args.slice(1).map((x) => isSymbol2(x) ? x.symbol : "_");
@@ -55439,12 +56361,68 @@ Error in definition of "${name}"`,
55439
56361
  }
55440
56362
  const js = BaseCompiler.compile(expr, target);
55441
56363
  const fn = new ComputeEngineFunction(js, target.preamble);
55442
- return {
56364
+ const result = {
55443
56365
  target: "javascript",
55444
56366
  success: true,
55445
56367
  code: js,
55446
56368
  run: fn
55447
56369
  };
56370
+ return realOnly ? wrapRealOnly(result) : result;
56371
+ }
56372
+ var UNROLL_LIMIT = 100;
56373
+ function compileSumProduct(kind, args, _compile, target) {
56374
+ if (!args[0]) throw new Error(`${kind}: no body`);
56375
+ if (!args[1]) throw new Error(`${kind}: no indexing set`);
56376
+ const { index, lower, upper } = normalizeIndexingSet(args[1]);
56377
+ const isSum = kind === "Sum";
56378
+ const op = isSum ? "+" : "*";
56379
+ const identity = isSum ? "0" : "1";
56380
+ if (lower > upper) return identity;
56381
+ const termCount = upper - lower + 1;
56382
+ const bodyIsComplex = BaseCompiler.isComplexValued(args[0]);
56383
+ if (termCount <= UNROLL_LIMIT) {
56384
+ const terms = [];
56385
+ for (let k = lower; k <= upper; k++) {
56386
+ const innerTarget = {
56387
+ ...target,
56388
+ var: (id) => id === index ? String(k) : target.var(id)
56389
+ };
56390
+ terms.push(`(${BaseCompiler.compile(args[0], innerTarget)})`);
56391
+ }
56392
+ if (!bodyIsComplex) {
56393
+ return `(${terms.join(` ${op} `)})`;
56394
+ }
56395
+ const temps = terms.map((_, i) => `_t${i}`);
56396
+ const assignments = terms.map((t, i) => `const ${temps[i]} = ${t}`).join("; ");
56397
+ if (isSum) {
56398
+ const reSum = temps.map((t) => `${t}.re`).join(" + ");
56399
+ const imSum = temps.map((t) => `${t}.im`).join(" + ");
56400
+ return `(() => { ${assignments}; return { re: ${reSum}, im: ${imSum} }; })()`;
56401
+ }
56402
+ let acc2 = temps[0];
56403
+ const parts = [assignments];
56404
+ for (let i = 1; i < temps.length; i++) {
56405
+ const prev = acc2;
56406
+ acc2 = `_p${i}`;
56407
+ parts.push(
56408
+ `const ${acc2} = { re: ${prev}.re * ${temps[i]}.re - ${prev}.im * ${temps[i]}.im, im: ${prev}.re * ${temps[i]}.im + ${prev}.im * ${temps[i]}.re }`
56409
+ );
56410
+ }
56411
+ return `(() => { ${parts.join("; ")}; return ${acc2}; })()`;
56412
+ }
56413
+ const bodyCode = BaseCompiler.compile(args[0], {
56414
+ ...target,
56415
+ var: (id) => id === index ? index : target.var(id)
56416
+ });
56417
+ const acc = BaseCompiler.tempVar();
56418
+ if (bodyIsComplex) {
56419
+ const val = BaseCompiler.tempVar();
56420
+ if (isSum) {
56421
+ return `(() => { let ${acc} = { re: 0, im: 0 }; let ${index} = ${lower}; while (${index} <= ${upper}) { const ${val} = ${bodyCode}; ${acc} = { re: ${acc}.re + ${val}.re, im: ${acc}.im + ${val}.im }; ${index}++; } return ${acc}; })()`;
56422
+ }
56423
+ return `(() => { let ${acc} = { re: 1, im: 0 }; let ${index} = ${lower}; while (${index} <= ${upper}) { const ${val} = ${bodyCode}; ${acc} = { re: ${acc}.re * ${val}.re - ${acc}.im * ${val}.im, im: ${acc}.re * ${val}.im + ${acc}.im * ${val}.re }; ${index}++; } return ${acc}; })()`;
56424
+ }
56425
+ return `(() => { let ${acc} = ${identity}; let ${index} = ${lower}; while (${index} <= ${upper}) { ${acc} ${op}= ${bodyCode}; ${index}++; } return ${acc}; })()`;
55448
56426
  }
55449
56427
  function compileIntegrate(args, _, target) {
55450
56428
  const { index, lower, upper } = normalizeIndexingSet(args[1]);
@@ -55660,13 +56638,11 @@ Error in definition of "${name}"`,
55660
56638
  Truncate: "trunc",
55661
56639
  // Complex-specific functions
55662
56640
  Re: (args, compile3) => {
55663
- if (BaseCompiler.isComplexValued(args[0]))
55664
- return `(${compile3(args[0])}).x`;
56641
+ if (BaseCompiler.isComplexValued(args[0])) return `(${compile3(args[0])}).x`;
55665
56642
  return compile3(args[0]);
55666
56643
  },
55667
56644
  Im: (args, compile3) => {
55668
- if (BaseCompiler.isComplexValued(args[0]))
55669
- return `(${compile3(args[0])}).y`;
56645
+ if (BaseCompiler.isComplexValued(args[0])) return `(${compile3(args[0])}).y`;
55670
56646
  return "0.0";
55671
56647
  },
55672
56648
  Arg: (args, compile3) => {
@@ -57119,6 +58095,15 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57119
58095
  function remainder(a, b) {
57120
58096
  return sub2(a, mul4(b, round2(div3(a, b))));
57121
58097
  }
58098
+ function heaviside(x) {
58099
+ const unwrapped = unwrapOrPropagate(x);
58100
+ if (!Array.isArray(unwrapped)) return unwrapped;
58101
+ const [xVal] = unwrapped;
58102
+ if (xVal.lo > 0) return ok({ lo: 1, hi: 1 });
58103
+ if (xVal.hi < 0) return ok({ lo: 0, hi: 0 });
58104
+ if (xVal.lo === 0 && xVal.hi === 0) return ok({ lo: 0.5, hi: 0.5 });
58105
+ return { kind: "singular", at: 0 };
58106
+ }
57122
58107
  function sign2(x) {
57123
58108
  const unwrapped = unwrapOrPropagate(x);
57124
58109
  if (!Array.isArray(unwrapped)) return unwrapped;
@@ -57128,6 +58113,61 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57128
58113
  if (xVal.lo === 0 && xVal.hi === 0) return ok({ lo: 0, hi: 0 });
57129
58114
  return { kind: "singular", at: 0 };
57130
58115
  }
58116
+ var GAMMA_MIN_X = 1.4616321449683622;
58117
+ var GAMMA_MIN_Y = 0.8856031944108887;
58118
+ function gamma3(x) {
58119
+ const unwrapped = unwrapOrPropagate(x);
58120
+ if (!Array.isArray(unwrapped)) return unwrapped;
58121
+ const [xVal] = unwrapped;
58122
+ return _gamma(xVal);
58123
+ }
58124
+ function _gamma(x) {
58125
+ if (x.hi >= 0 && x.lo <= 0) {
58126
+ return { kind: "singular", at: 0 };
58127
+ }
58128
+ if (x.lo < 0) {
58129
+ const ceilLo = Math.ceil(x.lo);
58130
+ const floorHi = Math.floor(x.hi);
58131
+ if (ceilLo <= floorHi) {
58132
+ return { kind: "singular", at: ceilLo };
58133
+ }
58134
+ const gLo = gamma2(x.lo);
58135
+ const gHi = gamma2(x.hi);
58136
+ return ok({ lo: Math.min(gLo, gHi), hi: Math.max(gLo, gHi) });
58137
+ }
58138
+ if (x.lo >= GAMMA_MIN_X) {
58139
+ return ok({ lo: gamma2(x.lo), hi: gamma2(x.hi) });
58140
+ }
58141
+ if (x.hi <= GAMMA_MIN_X) {
58142
+ return ok({ lo: gamma2(x.hi), hi: gamma2(x.lo) });
58143
+ }
58144
+ return ok({
58145
+ lo: GAMMA_MIN_Y,
58146
+ hi: Math.max(gamma2(x.lo), gamma2(x.hi))
58147
+ });
58148
+ }
58149
+ function gammaln3(x) {
58150
+ const unwrapped = unwrapOrPropagate(x);
58151
+ if (!Array.isArray(unwrapped)) return unwrapped;
58152
+ const [xVal] = unwrapped;
58153
+ return _gammaln(xVal);
58154
+ }
58155
+ function _gammaln(x) {
58156
+ if (x.hi >= 0 && x.lo <= 0) {
58157
+ return { kind: "singular", at: 0 };
58158
+ }
58159
+ if (x.lo < 0) {
58160
+ const ceilLo = Math.ceil(x.lo);
58161
+ const floorHi = Math.floor(x.hi);
58162
+ if (ceilLo <= floorHi) {
58163
+ return { kind: "singular", at: ceilLo };
58164
+ }
58165
+ const gLo = gammaln2(x.lo);
58166
+ const gHi = gammaln2(x.hi);
58167
+ return ok({ lo: Math.min(gLo, gHi), hi: Math.max(gLo, gHi) });
58168
+ }
58169
+ return ok({ lo: gammaln2(x.lo), hi: gammaln2(x.hi) });
58170
+ }
57131
58171
 
57132
58172
  // src/compute-engine/interval/trigonometric.ts
57133
58173
  var TWO_PI = 2 * Math.PI;
@@ -57461,6 +58501,86 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57461
58501
  }
57462
58502
  return acosh2(div3(ok({ lo: 1, hi: 1 }), ok(xVal)));
57463
58503
  }
58504
+ var SINC_EXTREMA = [
58505
+ 4.49341,
58506
+ 7.72525,
58507
+ 10.90412,
58508
+ 14.06619,
58509
+ 17.22076,
58510
+ 20.3713,
58511
+ 23.51945,
58512
+ 26.66605,
58513
+ 29.8116,
58514
+ 32.95639
58515
+ ];
58516
+ var SINC_GLOBAL_LO = -0.21724;
58517
+ function sinc2(x) {
58518
+ const unwrapped = unwrapOrPropagate(x);
58519
+ if (!Array.isArray(unwrapped)) return unwrapped;
58520
+ const [xVal] = unwrapped;
58521
+ const sincVal = (t) => t === 0 ? 1 : Math.sin(t) / t;
58522
+ let lo = sincVal(xVal.lo);
58523
+ let hi = lo;
58524
+ const update = (v) => {
58525
+ if (v < lo) lo = v;
58526
+ if (v > hi) hi = v;
58527
+ };
58528
+ update(sincVal(xVal.hi));
58529
+ if (xVal.lo <= 0 && xVal.hi >= 0) {
58530
+ update(1);
58531
+ }
58532
+ const lastExtremum = SINC_EXTREMA[SINC_EXTREMA.length - 1];
58533
+ for (const e of SINC_EXTREMA) {
58534
+ if (e >= xVal.lo && e <= xVal.hi) update(sincVal(e));
58535
+ if (-e >= xVal.lo && -e <= xVal.hi) update(sincVal(-e));
58536
+ }
58537
+ if (Math.abs(xVal.lo) > lastExtremum || Math.abs(xVal.hi) > lastExtremum) {
58538
+ update(SINC_GLOBAL_LO);
58539
+ }
58540
+ return ok({ lo, hi });
58541
+ }
58542
+ var FRESNEL_S_EXTREMA = [];
58543
+ var FRESNEL_C_EXTREMA = [];
58544
+ for (let n = 1; n <= 20; n++) {
58545
+ FRESNEL_S_EXTREMA.push(Math.sqrt(2 * n));
58546
+ FRESNEL_C_EXTREMA.push(Math.sqrt(2 * n - 1));
58547
+ }
58548
+ function fresnelS2(x) {
58549
+ const unwrapped = unwrapOrPropagate(x);
58550
+ if (!Array.isArray(unwrapped)) return unwrapped;
58551
+ const [xVal] = unwrapped;
58552
+ let lo = fresnelS(xVal.lo);
58553
+ let hi = lo;
58554
+ const update = (v) => {
58555
+ if (v < lo) lo = v;
58556
+ if (v > hi) hi = v;
58557
+ };
58558
+ update(fresnelS(xVal.hi));
58559
+ if (xVal.lo <= 0 && xVal.hi >= 0) update(0);
58560
+ for (const e of FRESNEL_S_EXTREMA) {
58561
+ if (e >= xVal.lo && e <= xVal.hi) update(fresnelS(e));
58562
+ if (-e >= xVal.lo && -e <= xVal.hi) update(fresnelS(-e));
58563
+ }
58564
+ return ok({ lo, hi });
58565
+ }
58566
+ function fresnelC2(x) {
58567
+ const unwrapped = unwrapOrPropagate(x);
58568
+ if (!Array.isArray(unwrapped)) return unwrapped;
58569
+ const [xVal] = unwrapped;
58570
+ let lo = fresnelC(xVal.lo);
58571
+ let hi = lo;
58572
+ const update = (v) => {
58573
+ if (v < lo) lo = v;
58574
+ if (v > hi) hi = v;
58575
+ };
58576
+ update(fresnelC(xVal.hi));
58577
+ if (xVal.lo <= 0 && xVal.hi >= 0) update(0);
58578
+ for (const e of FRESNEL_C_EXTREMA) {
58579
+ if (e >= xVal.lo && e <= xVal.hi) update(fresnelC(e));
58580
+ if (-e >= xVal.lo && -e <= xVal.hi) update(fresnelC(-e));
58581
+ }
58582
+ return ok({ lo, hi });
58583
+ }
57464
58584
 
57465
58585
  // src/compute-engine/interval/comparison.ts
57466
58586
  function less(a, b) {
@@ -57614,7 +58734,10 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57614
58734
  max: max2,
57615
58735
  mod: mod2,
57616
58736
  remainder,
58737
+ heaviside,
57617
58738
  sign: sign2,
58739
+ gamma: gamma3,
58740
+ gammaln: gammaln3,
57618
58741
  // Trigonometric
57619
58742
  sin: sin2,
57620
58743
  cos: cos2,
@@ -57641,6 +58764,9 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57641
58764
  acoth,
57642
58765
  acsch,
57643
58766
  asech,
58767
+ sinc: sinc2,
58768
+ fresnelS: fresnelS2,
58769
+ fresnelC: fresnelC2,
57644
58770
  // Comparison
57645
58771
  less,
57646
58772
  lessEqual,
@@ -57772,6 +58898,7 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57772
58898
  return `_IA.powInterval(${compile3(arg)}, _IA.div(_IA.point(1), ${compile3(exp3)}))`;
57773
58899
  },
57774
58900
  Round: (args, compile3) => `_IA.round(${compile3(args[0])})`,
58901
+ Heaviside: (args, compile3) => `_IA.heaviside(${compile3(args[0])})`,
57775
58902
  Sign: (args, compile3) => `_IA.sign(${compile3(args[0])})`,
57776
58903
  Sqrt: (args, compile3) => `_IA.sqrt(${compile3(args[0])})`,
57777
58904
  Square: (args, compile3) => `_IA.square(${compile3(args[0])})`,
@@ -57801,6 +58928,11 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57801
58928
  Arcoth: (args, compile3) => `_IA.acoth(${compile3(args[0])})`,
57802
58929
  Arcsch: (args, compile3) => `_IA.acsch(${compile3(args[0])})`,
57803
58930
  Arsech: (args, compile3) => `_IA.asech(${compile3(args[0])})`,
58931
+ // Cardinal sine
58932
+ Sinc: (args, compile3) => `_IA.sinc(${compile3(args[0])})`,
58933
+ // Fresnel integrals
58934
+ FresnelS: (args, compile3) => `_IA.fresnelS(${compile3(args[0])})`,
58935
+ FresnelC: (args, compile3) => `_IA.fresnelC(${compile3(args[0])})`,
57804
58936
  // Special functions
57805
58937
  Gamma: (args, compile3) => `_IA.gamma(${compile3(args[0])})`,
57806
58938
  GammaLn: (args, compile3) => `_IA.gammaln(${compile3(args[0])})`,
@@ -57810,6 +58942,9 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57810
58942
  // Mod / Remainder
57811
58943
  Mod: (args, compile3) => `_IA.mod(${compile3(args[0])}, ${compile3(args[1])})`,
57812
58944
  Remainder: (args, compile3) => `_IA.remainder(${compile3(args[0])}, ${compile3(args[1])})`,
58945
+ // Sum / Product
58946
+ Sum: (args, compile3, target) => compileIntervalSumProduct("Sum", args, compile3, target),
58947
+ Product: (args, compile3, target) => compileIntervalSumProduct("Product", args, compile3, target),
57813
58948
  // Conditionals
57814
58949
  If: (args, compile3) => {
57815
58950
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
@@ -57819,6 +58954,26 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57819
58954
  () => ${compile3(args[2])}
57820
58955
  )`;
57821
58956
  },
58957
+ Which: (args, compile3) => {
58958
+ if (args.length < 2 || args.length % 2 !== 0)
58959
+ throw new Error(
58960
+ "Which: expected even number of arguments (condition/value pairs)"
58961
+ );
58962
+ const buildPiecewise = (i) => {
58963
+ if (i >= args.length) return `{ kind: 'empty' }`;
58964
+ const cond = args[i];
58965
+ const val = args[i + 1];
58966
+ if (isSymbol2(cond) && cond.symbol === "True") {
58967
+ return compile3(val);
58968
+ }
58969
+ return `_IA.piecewise(
58970
+ ${compile3(cond)},
58971
+ () => ${compile3(val)},
58972
+ () => ${buildPiecewise(i + 2)}
58973
+ )`;
58974
+ };
58975
+ return buildPiecewise(0);
58976
+ },
57822
58977
  // Comparisons
57823
58978
  Equal: (args, compile3) => `_IA.equal(${compile3(args[0])}, ${compile3(args[1])})`,
57824
58979
  NotEqual: (args, compile3) => `_IA.notEqual(${compile3(args[0])}, ${compile3(args[1])})`,
@@ -57830,6 +58985,38 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57830
58985
  Or: (args, compile3) => `_IA.or(${compile3(args[0])}, ${compile3(args[1])})`,
57831
58986
  Not: (args, compile3) => `_IA.not(${compile3(args[0])})`
57832
58987
  };
58988
+ var INTERVAL_UNROLL_LIMIT = 100;
58989
+ function compileIntervalSumProduct(kind, args, _compile, target) {
58990
+ if (!args[0]) throw new Error(`${kind}: no body`);
58991
+ if (!args[1]) throw new Error(`${kind}: no indexing set`);
58992
+ const { index, lower, upper } = normalizeIndexingSet(args[1]);
58993
+ const isSum = kind === "Sum";
58994
+ const iaOp = isSum ? "_IA.add" : "_IA.mul";
58995
+ const identity = isSum ? "_IA.point(0)" : "_IA.point(1)";
58996
+ if (lower > upper) return identity;
58997
+ const termCount = upper - lower + 1;
58998
+ if (termCount <= INTERVAL_UNROLL_LIMIT) {
58999
+ const terms = [];
59000
+ for (let k = lower; k <= upper; k++) {
59001
+ const innerTarget = {
59002
+ ...target,
59003
+ var: (id) => id === index ? `_IA.point(${k})` : target.var(id)
59004
+ };
59005
+ terms.push(BaseCompiler.compile(args[0], innerTarget));
59006
+ }
59007
+ let result = terms[terms.length - 1];
59008
+ for (let i = terms.length - 2; i >= 0; i--) {
59009
+ result = `${iaOp}(${terms[i]}, ${result})`;
59010
+ }
59011
+ return result;
59012
+ }
59013
+ const acc = BaseCompiler.tempVar();
59014
+ const bodyCode = BaseCompiler.compile(args[0], {
59015
+ ...target,
59016
+ var: (id) => id === index ? `_IA.point(${index})` : target.var(id)
59017
+ });
59018
+ return `(() => { let ${acc} = ${identity}; for (let ${index} = ${lower}; ${index} <= ${upper}; ${index}++) { ${acc} = ${iaOp}(${acc}, ${bodyCode}); } return ${acc}; })()`;
59019
+ }
57833
59020
  var ComputeEngineIntervalFunction = class extends Function {
57834
59021
  IA = IntervalArithmetic;
57835
59022
  constructor(body, preamble = "") {
@@ -57840,8 +59027,12 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57840
59027
  );
57841
59028
  return new Proxy(this, {
57842
59029
  apply: (target, thisArg, argumentsList) => {
57843
- const processedArgs = argumentsList.map(processInput);
57844
- return super.apply(thisArg, [this.IA, ...processedArgs]);
59030
+ try {
59031
+ const processedArgs = argumentsList.map(processInput);
59032
+ return super.apply(thisArg, [this.IA, ...processedArgs]);
59033
+ } catch {
59034
+ return { kind: "entire" };
59035
+ }
57845
59036
  },
57846
59037
  get: (target, prop) => {
57847
59038
  if (prop === "toString") return () => body;
@@ -57953,7 +59144,12 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
57953
59144
  }
57954
59145
  };
57955
59146
  function compileToIntervalTarget(expr, target) {
57956
- const js = BaseCompiler.compile(expr, target);
59147
+ let js;
59148
+ try {
59149
+ js = BaseCompiler.compile(expr, target);
59150
+ } catch {
59151
+ return { target: "interval-js", success: false, code: "" };
59152
+ }
57957
59153
  const fn = new ComputeEngineIntervalFunction(js, target.preamble);
57958
59154
  return {
57959
59155
  target: "interval-js",
@@ -64080,7 +65276,8 @@ fn ${functionName}(${params}) -> IntervalResult {
64080
65276
  this.skipSpace();
64081
65277
  let result = this.parseInfixOperator(lhs, until);
64082
65278
  if (result === null && until.minPrec <= INVISIBLE_OP_PRECEDENCE) {
64083
- if (this.peekDefinitions("operator").length === 0) {
65279
+ const opDefs = this.peekDefinitions("operator");
65280
+ if (opDefs.length === 0 || opDefs.every(([def]) => def.latexTrigger === "\\text")) {
64084
65281
  const rhs = this.parseExpression({
64085
65282
  ...until,
64086
65283
  minPrec: INVISIBLE_OP_PRECEDENCE + 1
@@ -67615,10 +68812,10 @@ ${code}`;
67615
68812
  _setComputeEngineClass(ComputeEngine);
67616
68813
 
67617
68814
  // src/compute-engine.ts
67618
- var version = "0.51.0";
68815
+ var version = "0.51.1";
67619
68816
  globalThis[Symbol.for("io.cortexjs.compute-engine")] = {
67620
68817
  ComputeEngine: ComputeEngine.prototype.constructor,
67621
- version: "0.51.0"
68818
+ version: "0.51.1"
67622
68819
  };
67623
68820
  return __toCommonJS(compute_engine_exports);
67624
68821
  })();