@cortex-js/compute-engine 0.58.0 → 0.59.0

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 (270) hide show
  1. package/README.md +4 -0
  2. package/dist/compile.esm.js +1721 -483
  3. package/dist/compile.min.esm.js +122 -74
  4. package/dist/compile.min.umd.cjs +122 -74
  5. package/dist/compile.umd.cjs +1721 -483
  6. package/dist/compute-engine.esm.js +25209 -22883
  7. package/dist/compute-engine.min.esm.js +135 -87
  8. package/dist/compute-engine.min.umd.cjs +135 -87
  9. package/dist/compute-engine.umd.cjs +24952 -22626
  10. package/dist/core.esm.js +25208 -22882
  11. package/dist/core.min.esm.js +134 -86
  12. package/dist/core.min.umd.cjs +134 -86
  13. package/dist/core.umd.cjs +24951 -22625
  14. package/dist/identities.esm.js +1921 -0
  15. package/dist/identities.min.esm.js +2 -0
  16. package/dist/identities.min.umd.cjs +4 -0
  17. package/dist/identities.umd.cjs +1946 -0
  18. package/dist/interval.esm.js +653 -330
  19. package/dist/interval.min.esm.js +8 -8
  20. package/dist/interval.min.umd.cjs +8 -8
  21. package/dist/interval.umd.cjs +653 -330
  22. package/dist/latex-syntax.esm.js +758 -512
  23. package/dist/latex-syntax.min.esm.js +7 -7
  24. package/dist/latex-syntax.min.umd.cjs +7 -7
  25. package/dist/latex-syntax.umd.cjs +758 -512
  26. package/dist/math-json.esm.js +8 -12
  27. package/dist/math-json.min.esm.js +2 -2
  28. package/dist/math-json.min.umd.cjs +2 -2
  29. package/dist/math-json.umd.cjs +8 -12
  30. package/dist/numerics.esm.js +1349 -228
  31. package/dist/numerics.min.esm.js +16 -5
  32. package/dist/numerics.min.umd.cjs +16 -5
  33. package/dist/numerics.umd.cjs +1349 -228
  34. package/dist/types/big-decimal/big-decimal.d.ts +1 -1
  35. package/dist/types/big-decimal/index.d.ts +1 -1
  36. package/dist/types/big-decimal/transcendentals.d.ts +1 -1
  37. package/dist/types/big-decimal/utils.d.ts +1 -1
  38. package/dist/types/common/ansi-codes.d.ts +1 -1
  39. package/dist/types/common/configuration-change.d.ts +1 -1
  40. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  41. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  42. package/dist/types/common/interruptible.d.ts +1 -1
  43. package/dist/types/common/one-of.d.ts +1 -1
  44. package/dist/types/common/signals.d.ts +1 -1
  45. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  46. package/dist/types/common/type/boxed-type.d.ts +1 -1
  47. package/dist/types/common/type/lexer.d.ts +1 -1
  48. package/dist/types/common/type/parse.d.ts +1 -208
  49. package/dist/types/common/type/parser.d.ts +124 -2
  50. package/dist/types/common/type/primitive.d.ts +5 -1
  51. package/dist/types/common/type/reduce.d.ts +1 -1
  52. package/dist/types/common/type/serialize.d.ts +1 -1
  53. package/dist/types/common/type/subtype.d.ts +18 -1
  54. package/dist/types/common/type/type-builder.d.ts +1 -1
  55. package/dist/types/common/type/types.d.ts +1 -1
  56. package/dist/types/common/type/utils.d.ts +1 -1
  57. package/dist/types/common/utils.d.ts +1 -1
  58. package/dist/types/compile.d.ts +1 -1
  59. package/dist/types/compute-engine/assume.d.ts +13 -6
  60. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -3
  74. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +140 -0
  82. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  87. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +14 -4
  88. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  89. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  90. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  91. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  92. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  93. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  94. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  95. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  96. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  97. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  98. package/dist/types/compute-engine/boxed-expression/rule-index.d.ts +112 -0
  99. package/dist/types/compute-engine/boxed-expression/rules.d.ts +2 -1
  100. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  101. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  102. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  103. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  104. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  105. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  106. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  107. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  108. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  109. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  110. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  111. package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
  112. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  113. package/dist/types/compute-engine/compilation/constant-folding.d.ts +16 -1
  114. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  115. package/dist/types/compute-engine/compilation/gpu-target.d.ts +15 -5
  116. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +4 -4
  117. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  118. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  119. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  120. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  121. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  122. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  123. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  124. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  125. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  126. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  127. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  128. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  129. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  130. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  131. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  132. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  133. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  134. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  135. package/dist/types/compute-engine/engine-simplification-rules.d.ts +10 -2
  136. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  137. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  138. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  139. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  140. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  141. package/dist/types/compute-engine/fungrim/loader.d.ts +13 -0
  142. package/dist/types/compute-engine/fungrim/types.d.ts +160 -0
  143. package/dist/types/compute-engine/global-types.d.ts +1 -1
  144. package/dist/types/compute-engine/index.d.ts +48 -2
  145. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  146. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  147. package/dist/types/compute-engine/interval/elementary.d.ts +10 -2
  148. package/dist/types/compute-engine/interval/index.d.ts +2 -2
  149. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  150. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  151. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  152. package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
  153. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  154. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  155. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  156. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-colors.d.ts +1 -1
  157. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  158. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  159. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  160. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  161. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  162. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  163. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  164. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  165. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  166. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  167. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  168. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  169. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +4 -1
  170. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  171. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  172. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  173. package/dist/types/compute-engine/latex-syntax/parse.d.ts +3 -2
  174. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
  175. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -11
  176. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  177. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  178. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  179. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  180. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  181. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  182. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  183. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  184. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  185. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  186. package/dist/types/compute-engine/library/complex.d.ts +13 -1
  187. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  188. package/dist/types/compute-engine/library/core.d.ts +1 -1
  189. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  190. package/dist/types/compute-engine/library/library.d.ts +1 -1
  191. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  192. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  193. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  194. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  195. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  196. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  197. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  198. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  199. package/dist/types/compute-engine/library/sets.d.ts +27 -1
  200. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  201. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  202. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  203. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  204. package/dist/types/compute-engine/library/units.d.ts +1 -1
  205. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  206. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  207. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +7 -1
  208. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  209. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  210. package/dist/types/compute-engine/numerics/bernoulli.d.ts +39 -0
  211. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  212. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  213. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  214. package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
  215. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  216. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  217. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  218. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +12 -1
  219. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  220. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  221. package/dist/types/compute-engine/numerics/random.d.ts +1 -1
  222. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  223. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  224. package/dist/types/compute-engine/numerics/special-functions.d.ts +78 -10
  225. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  226. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  227. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  228. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  229. package/dist/types/compute-engine/oeis.d.ts +1 -1
  230. package/dist/types/compute-engine/sequence.d.ts +1 -1
  231. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  232. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  233. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  234. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  235. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  236. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  237. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  238. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  239. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  240. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  241. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  242. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  243. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  244. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  245. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  246. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  247. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  248. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  249. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  250. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  251. package/dist/types/compute-engine/tensor/tensors.d.ts +3 -3
  252. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  253. package/dist/types/compute-engine/types-engine.d.ts +19 -3
  254. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  255. package/dist/types/compute-engine/types-expression.d.ts +17 -14
  256. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +32 -1
  257. package/dist/types/compute-engine/types-kernel-serialization.d.ts +45 -3
  258. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  259. package/dist/types/compute-engine/types.d.ts +1 -1
  260. package/dist/types/compute-engine.d.ts +1 -1
  261. package/dist/types/core.d.ts +1 -1
  262. package/dist/types/identities.d.ts +3 -0
  263. package/dist/types/interval.d.ts +1 -1
  264. package/dist/types/latex-syntax.d.ts +2 -2
  265. package/dist/types/math-json/symbols.d.ts +1 -1
  266. package/dist/types/math-json/types.d.ts +1 -1
  267. package/dist/types/math-json/utils.d.ts +1 -1
  268. package/dist/types/math-json.d.ts +2 -2
  269. package/dist/types/numerics.d.ts +1 -1
  270. package/package.json +9 -3
@@ -1,55 +1,55 @@
1
- /** Compile 0.58.0 */
1
+ /** Compile 0.59.0 */
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.Compile = {}));})(this, (function (exports) { 'use strict';
3
- var Compile=(()=>{var Ii=Object.defineProperty;var il=Object.getOwnPropertyDescriptor;var rl=Object.getOwnPropertyNames;var sl=Object.prototype.hasOwnProperty;var ol=(e,n)=>{for(var t in n)Ii(e,t,{get:n[t],enumerable:!0})},al=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of rl(n))!sl.call(e,r)&&r!==t&&Ii(e,r,{get:()=>n[r],enumerable:!(i=il(n,r))||i.enumerable});return e};var ul=e=>al(Ii({},"__esModule",{value:!0}),e);var Op={};ol(Op,{BaseCompiler:()=>g,GLSLTarget:()=>ci,GPUShaderTarget:()=>sn,IntervalJavaScriptTarget:()=>Ti,JavaScriptTarget:()=>ui,PythonTarget:()=>pi,WGSLTarget:()=>fi,compile:()=>Ca,version:()=>Lp});function _i(e,n,t={}){let{contract:i=.125,step:r=1,power:s=2,atol:o=1e-16,rtol:a=o>0?0:Math.sqrt(Number.EPSILON),maxeval:u=1e6,breaktol:l=2}=t;if(!isFinite(n))return _i(T=>e(1/T),1/n,{rtol:a,atol:o,maxeval:u,contract:Math.abs(i)>1?1/i:i,step:1/r,power:s});let c=r,f=Math.pow(1/i,s),m=e(n+c),d=[m],b=1/0,v=1;for(;v<u;){v+=1,c*=i,d.push(e(n+c));let T=f,M=1/0;for(let C=d.length-2;C>=0;C--){let F=d[C];d[C]=d[C+1]+(d[C+1]-d[C])/(T-1);let V=Math.abs(d[C]-F);M=Math.min(M,V),V<b&&(m=d[C],b=V),T*=f}if(M>l*b||!isFinite(M)||b<=Math.max(a*Math.abs(m),o))break}return[m,b]}var zs=new Map;function O(e){if(e<=100){let n=zs.get(e);return n===void 0&&(n=10n**BigInt(e),zs.set(e,n)),n}return 10n**BigInt(e)}function js(e,n,t){return e*n/t}function Us(e,n,t){return e*t/n}function Gn(e,n){if(e===0n)return 0n;if(e<0n)throw new RangeError("fpsqrt: negative input");let t,i=Number(e),r=Number(n);if(Number.isFinite(i)&&Number.isFinite(r)&&i>0&&r>0){let c=Math.sqrt(i/r)*r;Number.isFinite(c)&&c>0?(t=BigInt(Math.floor(c)),t===0n&&(t=1n)):t=Gs(e,n)}else t=Gs(e,n);let s=e*n,o;do o=t,t=(t+s/t)/2n;while(_e(t-o)>1n);let a=(t+s/t)/2n,u=_e(t*t-s);return _e(a*a-s)<u?a:t}function Gs(e,n){let i=K(e),r=Math.max(0,i-15),s=Number(r>0?e/O(r):e),o=K(n),a=Math.max(0,o-15),u=Number(a>0?n/O(a):n),l=r+a,c=Math.floor(l/2),f=Math.sqrt(s*u);l%2!==0&&(f*=3.1622776601683795);let m=BigInt(Math.round(f))*O(c);return m>0n?m:1n}function _e(e){return e<0n?-e:e}function K(e){if(e===0n)return 1;if(e<0n&&(e=-e),e<0x20000000000000n)return Math.floor(Math.log10(Number(e)))+1;let n=0,t=e,i=1;for(;t>>BigInt(i)>0n;)i*=2;for(let s=i>>1;s>=1;s>>=1)t>>BigInt(s)>0n&&(n+=s,t>>=BigInt(s));n+=1;let r=Math.ceil(n*.30102999566398);return e<O(r-1)?r-1:e>=O(r)?r+1:r}function Mi(e,n){if(e===0n)return n;let t=0,i=e,r=n/2n;for(;_e(i)>r;)i=i/2n,t++;let s=n,o=i;s+=o;for(let a=2;o=o*i/(BigInt(a)*n),_e(o)!==0n;a++)s+=o;for(let a=0;a<t;a++)s=s*s/n;return s}function Hs(e,n){if(e===n)return 0n;let t=Number(e),i=Number(n),r,s=e,o=0;if(Number.isFinite(t)&&Number.isFinite(i)&&t>0&&i>0){let u=t/i;if(Number.isFinite(u)&&u>0){let l=Math.log(u);Number.isFinite(l)?r=BigInt(Math.round(l*i)):r=ki(e,n)}else r=ki(e,n)}else{s=e;let u=2n*n,l=n/2n;for(;s>u||s<l;)s=Gn(s,n),o++;r=ki(s,n)}let a=0n;for(let u=0;u<100;u++){let l=Mi(r,n);if(l===0n){r=r/2n;continue}let c=r+s*n/l-n,f=_e(c-r);if(f<=1n||f<100000n&&a>0n&&a<100000n&&f*4n>=a)break;a=f,r=c}for(let u=0;u<o;u++)r=2n*r;return r}function ki(e,n){let t=K(e),i=K(n);return BigInt(t-i)*2302585n*n/1000000n}var vt="314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635",xt=null;function Si(e){if(xt!==null&&xt.scale===e)return xt.value;let t=K(e)-1+10,i=vt.slice(0,t+1),r=BigInt(i),s=i.length-1,o=r*e/O(s);return xt={scale:e,value:o},o}function Et(e,n){if(e===0n)return[0n,n];let t=Si(n),i=2n*t,r=t/2n,s,o=_e(e);if(o>n*(1n<<30n)){let F=K(o)-K(n)+20,V=n*O(F),U=e*O(F),ue=2n*Si(V),H=U%ue;H<0n&&(H+=ue),s=H/O(F)}else s=e%i;s<0n&&(s+=i);let a=1n,u=1n;s>3n*r?(s=i-s,a=-1n):s>t?(s=s-t,a=-1n,u=-1n):s>r&&(s=t-s,u=-1n);let l=K(n)-1,c=Math.min(18,Math.max(2,Math.ceil(.87*Math.sqrt(l)))),f=0,m=n>>BigInt(c);for(;s>m;)s=s/2n,f++;let d=s,b=n,v=s,T=n,M=s*s,C=n*n;for(let F=2;;F+=2){if(T=T*M/(BigInt(F)*BigInt(F-1)*C),T===0n){v=v*M/(BigInt(F+1)*BigInt(F)*C),v!==0n&&(F%4===2?(b-=T,d-=v):(b+=T,d+=v));break}if(v=v*M/(BigInt(F+1)*BigInt(F)*C),F%4===2?(b-=T,d-=v):(b+=T,d+=v),v===0n)break}for(let F=0;F<f;F++){let V=2n*d*b/n,U=2n*b*b/n-n;d=V,b=U}return[a*d,u*b]}function zn(e,n){if(e===0n)return 0n;if(e<0n)return-zn(-e,n);let i=Si(n)/2n;if(e>n){let f=n*n/e;return i-zn(f,n)}let r=4n*n/10n,s=0,o=e;for(;o>r;){let f=o*o,m=(n*n+f)/n,d=Gn(m,n);o=o*n/(n+d),s++}let a=o,u=o,l=o*o,c=n*n;for(let f=3;u=u*l/c,u!==0n;f+=2)f%4===3?a-=u/BigInt(f):a+=u/BigInt(f);for(let f=0;f<s;f++)a=2n*a;return a}var wi=NaN,x=class e{static precision=50;static ZERO=Object.freeze(Object.assign(Object.create(e.prototype),{significand:0n,exponent:0}));static ONE=Object.freeze(Object.assign(Object.create(e.prototype),{significand:1n,exponent:0}));static TWO=Object.freeze(Object.assign(Object.create(e.prototype),{significand:2n,exponent:0}));static NEGATIVE_ONE=Object.freeze(Object.assign(Object.create(e.prototype),{significand:-1n,exponent:0}));static HALF=Object.freeze(Object.assign(Object.create(e.prototype),{significand:5n,exponent:-1}));static NAN=Object.freeze(Object.assign(Object.create(e.prototype),{significand:0n,exponent:NaN}));static POSITIVE_INFINITY=Object.freeze(Object.assign(Object.create(e.prototype),{significand:1n,exponent:1/0}));static NEGATIVE_INFINITY=Object.freeze(Object.assign(Object.create(e.prototype),{significand:-1n,exponent:1/0}));static _piFullPrecision=null;static _piCache=null;static _piCachePrecision=0;static get PI(){e._piFullPrecision===null&&(e._piFullPrecision=new e(vt[0]+"."+vt.slice(1)));let n=e.precision;return(e._piCache===null||e._piCachePrecision!==n)&&(e._piCache=e._piFullPrecision.toPrecision(n+4),e._piCachePrecision=n),e._piCache}significand;exponent;constructor(n){if(n instanceof e){this.significand=n.significand,this.exponent=n.exponent;return}if(typeof n=="bigint"){[this.significand,this.exponent]=Nt(n,0);return}if(typeof n=="number"){[this.significand,this.exponent]=ll(n);return}[this.significand,this.exponent]=Ws(n)}isNaN(){return Number.isNaN(this.exponent)}isZero(){return this.exponent===0&&this.significand===0n}isFinite(){return Number.isFinite(this.exponent)}isInteger(){return this.isFinite()&&this.exponent>=0}isPositive(){return this.significand>0n}isNegative(){return this.significand<0n}cmp(n){if(typeof n=="number"){if(Number.isNaN(n))return wi;let d=this.exponent;if(Number.isNaN(d))return wi;if(n===0)return this.significand===0n?0:this.significand>0n?1:-1;if(!Number.isFinite(d))return n===1/0?this.significand>0n?0:-1:n===-1/0?this.significand<0n?0:1:this.significand>0n?1:-1;if(this.significand===0n)return n>0?-1:1;if(n===1/0)return-1;if(n===-1/0)return 1;if(this.significand>0n!=n>0)return this.significand>0n?1:-1;if(Number.isInteger(n)&&d>=0&&d<=15){let b=this.significand*O(d),v=BigInt(n);return b<v?-1:b>v?1:0}n=new e(n)}let t=this.exponent,i=n.exponent,r=this.significand,s=n.significand;if(t!==t||i!==i)return wi;if(!Number.isFinite(t)||!Number.isFinite(i))return!Number.isFinite(t)&&!Number.isFinite(i)?r===s?0:r>s?1:-1:Number.isFinite(t)?s>0n?-1:1:r>0n?1:-1;if(r===0n)return s===0n?0:s>0n?-1:1;if(s===0n)return r>0n?1:-1;if(r>0n&&s<0n)return 1;if(r<0n&&s>0n)return-1;if(t===i)return r<s?-1:r>s?1:0;let o=K(r),a=K(s),u=o+t,l=a+i;if(u!==l){let d=r>0n?1:-1;return u>l?d:-d}let c=r,f=s,m=Math.abs(t-i);if(m>1e3){let d=o,b=a,v=Math.max(d,b)+1;d<v&&(c=c*O(v-d)),b<v&&(f=f*O(v-b))}else t<i?f=f*O(m):c=c*O(m);return c<f?-1:c>f?1:0}eq(n){return typeof n=="number"?n===0?this.significand===0n&&this.exponent===0:n===1?this.significand===1n&&this.exponent===0:n===-1?this.significand===-1n&&this.exponent===0:Number.isInteger(n)&&Number.isFinite(this.exponent)&&this.exponent>=0&&this.exponent<=15?this.significand*O(this.exponent)===BigInt(n):this.cmp(n)===0:this.significand===n.significand&&this.exponent===n.exponent}lt(n){return this.cmp(n)===-1}lte(n){let t=this.cmp(n);return t===-1||t===0}gt(n){return this.cmp(n)===1}gte(n){let t=this.cmp(n);return t===1||t===0}add(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;if(Number.isFinite(t)&&Number.isFinite(i)){if(t===i)return G(this.significand+n.significand,t);let o=t-i;return o>0?G(this.significand*O(o)+n.significand,i):G(this.significand+n.significand*O(-o),t)}if(t!==t||i!==i)return e.NAN;let r=!Number.isFinite(t),s=!Number.isFinite(i);return r&&s?this.significand!==n.significand?e.NAN:this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:r?this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:n.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}sub(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;if(Number.isFinite(t)&&Number.isFinite(i)){if(t===i)return G(this.significand-n.significand,t);let o=t-i;return o>0?G(this.significand*O(o)-n.significand,i):G(this.significand-n.significand*O(-o),t)}if(t!==t||i!==i)return e.NAN;let r=!Number.isFinite(t),s=!Number.isFinite(i);return r&&s?this.significand===n.significand?e.NAN:this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:r?this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:n.significand>0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY}mul(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;if(Number.isFinite(t)&&Number.isFinite(i))return G(this.significand*n.significand,t+i);if(t!==t||i!==i||this.significand===0n||n.significand===0n)return e.NAN;let r=this.significand>0n?1n:-1n,s=n.significand>0n?1n:-1n;return r*s>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}neg(){let n=this.significand;return n===0n?this:Number.isFinite(this.exponent)?G(-n,this.exponent):n>0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY}abs(){return this.significand>=0n?this:Number.isFinite(this.exponent)?G(-this.significand,this.exponent):e.POSITIVE_INFINITY}floor(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=this.trunc();return this.significand<0n?t.sub(G(1n,0)):t}return this}ceil(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=this.trunc();return this.significand>0n?t.add(G(1n,0)):t}return this}round(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=G(5n,-1);return this.significand>0n?this.add(t).trunc():this.sub(t).trunc()}return this}trunc(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=this.significand/O(-n);return G(t===0n?0n:t,0)}return this}div(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent,r=this.significand,s=n.significand;if(Number.isFinite(t)&&Number.isFinite(i)){if(s===0n)return r===0n?e.NAN:r>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY;if(r===0n)return G(0n,0);let u=e.precision,l=10,c=r<0n?-r:r,f=s<0n?-s:s,m=K(c),d=K(f),b=u+l+Math.max(0,d-m),v=O(b),T=r*v/s,M=t-i-b;return G(T,M).toPrecision(u)}if(t!==t||i!==i)return e.NAN;let o=!Number.isFinite(t),a=!Number.isFinite(i);if(o&&a)return e.NAN;if(o){let u=r>0n?1n:-1n,l=s>0n?1n:s<0n?-1n:1n;return u*l>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}return G(0n,0)}inv(){return G(1n,0).div(this)}mod(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;return Number.isFinite(t)&&Number.isFinite(i)?n.significand===0n?e.NAN:this.significand===0n?G(0n,0):this.sub(this.div(n).trunc().mul(n)).toPrecision(e.precision):t!==t||i!==i||!Number.isFinite(t)?e.NAN:new e(this)}pow(n){if(typeof n=="number"&&(n=new e(n)),this.isNaN()||n.isNaN()||!n.isFinite())return e.NAN;if(n.isInteger()){let t=n.toBigInt();if(t===0n)return G(1n,0);if(!this.isFinite())return t>0n?this.significand<0n&&t%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY:G(0n,0);if(this.isZero())return t>0n?G(0n,0):e.POSITIVE_INFINITY;if(t<0n)return this.pow(n.neg()).inv();let i=this.significand<0n?-this.significand:this.significand,r=K(i)+this.exponent,s=Number(t)*r;if(s>9e15)return this.significand<0n&&t%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY;if(s<-9e15)return G(0n,0);let o=e.precision,a=G(1n,0),u=this,l=t;for(;l>0n;)l&1n&&(a=a.mul(u).toPrecision(o)),l>>=1n,l>0n&&(u=u.mul(u).toPrecision(o));return a}return this.isFinite()?this.isZero()?n.significand>0n?e.ZERO:e.POSITIVE_INFINITY:this.significand<0n?e.NAN:n.mul(this.ln()).exp():this.significand<0n?e.NAN:n.significand>0n?e.POSITIVE_INFINITY:e.ZERO}toNumber(){return Number.isFinite(this.exponent)?this.significand===0n?0:this.exponent===0?Number(this.significand):Number(this.toString()):this.exponent!==this.exponent?NaN:this.significand>0n?1/0:-1/0}toString(){if(!Number.isFinite(this.exponent))return this.exponent!==this.exponent?"NaN":this.significand>0n?"Infinity":"-Infinity";if(this.significand===0n)return"0";let n=this.significand<0n,t=(n?-this.significand:this.significand).toString(),i=t.length,r=i+this.exponent-1,s=n?"-":"";if(r>20||r<-6){let u=i===1?t:t[0]+"."+t.slice(1),l=r>=0?"+":"";return`${s}${u}e${l}${r}`}if(this.exponent>=0)return s+t+"0".repeat(this.exponent);let o=-this.exponent;if(o<i){let u=t.slice(0,i-o),l=t.slice(i-o);return`${s}${u}.${l}`}let a=o-i;return`${s}0.${"0".repeat(a)}${t}`}toFixed(n){let t=n??0;if(!Number.isFinite(this.exponent))return this.exponent!==this.exponent?"NaN":this.significand>0n?"Infinity":"-Infinity";let i=this.significand<0n,r=i?-this.significand:this.significand,s=this.exponent+t,o;if(s>=0)o=r*O(s);else{let f=O(-s),m=r/f,d=r%f,b=f/2n;d>b?o=m+1n:d<b||f%2n!==0n||m%2n===0n?o=m:o=m+1n}let a=i&&o!==0n?"-":"",u=o.toString();if(t===0)return`${a}${u}`;if(u.length<=t){let f=u.padStart(t,"0");return`${a}0.${f}`}let l=u.slice(0,u.length-t),c=u.slice(u.length-t);return`${a}${l}.${c}`}toPrecision(n){if(this.significand===0n||!Number.isFinite(this.exponent))return this;let t=this.significand<0n?-this.significand:this.significand,i=K(t);if(i<=n)return this;let r=i-n,s=O(r),o=t/s,a=t%s,u=s/2n;(a>u||a===u&&o%2n!==0n)&&(o+=1n);let l=this.significand<0n?-o:o;return G(l,this.exponent+r)}toBigInt(){if(!Number.isFinite(this.exponent))throw this.exponent!==this.exponent?new RangeError("Cannot convert NaN to BigInt"):new RangeError("Cannot convert Infinity to BigInt");if(this.exponent>=0)return this.significand*O(this.exponent);let n=O(-this.exponent);return this.significand/n}};function G(e,n){let[t,i]=Nt(e,n),r=Object.create(x.prototype);return r.significand=t,r.exponent=i,r}var Zs=1000000000n,Ys=1000n;function Nt(e,n){if(e===0n)return[0n,0];for(;e%Zs===0n;)e/=Zs,n+=9;for(;e%Ys===0n;)e/=Ys,n+=3;for(;e%10n===0n;)e/=10n,n+=1;return[e,n]}function ll(e){return Number.isNaN(e)?[0n,NaN]:e===1/0?[1n,1/0]:e===-1/0?[-1n,1/0]:Number.isInteger(e)?Nt(BigInt(e),0):Ws(e.toString())}function Ws(e){if(e=e.trim(),e===""||e==="NaN")return[0n,NaN];if(e==="Infinity"||e==="+Infinity")return[1n,1/0];if(e==="-Infinity")return[-1n,1/0];let n,t=0,i=e.search(/[eE]/);if(i!==-1){if(n=e.slice(0,i),t=Number(e.slice(i+1)),!Number.isFinite(t))return[0n,NaN]}else n=e;let r=!1;n.startsWith("-")?(r=!0,n=n.slice(1)):n.startsWith("+")&&(n=n.slice(1));let s=n.indexOf("."),o,a;s===-1?(o=n,a=""):(o=n.slice(0,s),a=n.slice(s+1)),o=o.replace(/^0+/,"")||"0";let u=o+a;if(u.length===0||!/^\d+$/.test(u))return[0n,NaN];let l=BigInt(u);r&&(l=-l);let c=-a.length;return Nt(l,c+t)}function Ve(e,n){let t=O(n),i=e.exponent+n;return i>=0?[e.significand*O(i),t]:[e.significand/O(-i),t]}function Je(e,n,t){if(e===0n)return x.ZERO;let i=e<0n,r=i?-e:e,s=K(r);if(s>t){let l=s-t,c=O(l),f=c/2n,m=r%c;r=r/c,m>=f&&(r+=1n);let d=K(n)-1,b=l-d,v=i?-r:r;return G(v,b)}let a=-(K(n)-1),u=i?-r:r;return G(u,a)}x.prototype.sqrt=function(){if(this.isNaN())return x.NAN;if(this.isZero())return x.ZERO;if(!this.isFinite())return this.significand>0n?x.POSITIVE_INFINITY:x.NAN;if(this.significand<0n)return x.NAN;let e=x.precision,n=e+10,[t,i]=Ve(this,n),r=Gn(t,i);return Je(r,i,e)};x.prototype.cbrt=function(){if(this.isNaN())return x.NAN;if(this.isZero())return x.ZERO;if(!this.isFinite())return this.significand>0n?x.POSITIVE_INFINITY:x.NEGATIVE_INFINITY;if(this.significand<0n)return this.neg().cbrt().neg();let e=x.precision,n=e+10,[t,i]=Ve(this,n),r=t*i*i,s,o=this.toNumber(),a=Number(i);if(Number.isFinite(o)&&o>0&&Number.isFinite(a)){let l=Math.cbrt(o);Number.isFinite(l)&&l>0?(s=BigInt(Math.floor(l*a)),s===0n&&(s=1n)):s=Xs(t,i)}else s=Xs(t,i);let u;do{u=s;let l=s*s;if(l===0n){s=1n;break}s=(2n*s+r/l)/3n}while(_e(s-u)>1n);{let l=(2n*s+r/(s*s))/3n,c=_e(s*s*s-r);_e(l*l*l-r)<c&&(s=l)}return Je(s,i,e)};x.sqrt=function(e){return e.sqrt()};x.cbrt=function(e){return e.cbrt()};x.prototype.exp=function(){if(this.isNaN())return x.NAN;if(!this.isFinite())return this.significand>0n?x.POSITIVE_INFINITY:x.ZERO;if(this.isZero())return x.ONE;let e=x.precision,n=e+15,[t,i]=Ve(this,n),r=Mi(t,i);return Je(r,i,e)};x.prototype.ln=function(){if(this.isNaN())return x.NAN;if(!this.isFinite())return this.significand>0n?x.POSITIVE_INFINITY:x.NAN;if(this.isZero())return x.NEGATIVE_INFINITY;if(this.significand<0n)return x.NAN;if(this.eq(1))return x.ZERO;let e=x.precision,n=e+15,[t,i]=Ve(this,n),r=Hs(t,i);return Je(r,i,e)};x.prototype.log=function(e){let n=e instanceof x?e:new x(e);return this.ln().div(n.ln())};x.exp=function(e){return e.exp()};x.ln=function(e){return e.ln()};x.log10=function(e){return e.log(10)};x.prototype.sin=function(){if(this.isNaN())return x.NAN;if(!this.isFinite())return x.NAN;if(this.isZero())return x.ZERO;let e=x.precision,n=e+15,[t,i]=Ve(this,n),[r]=Et(t,i);return Je(r,i,e)};x.prototype.cos=function(){if(this.isNaN())return x.NAN;if(!this.isFinite())return x.NAN;if(this.isZero())return x.ONE;let e=x.precision,n=e+15,[t,i]=Ve(this,n),[,r]=Et(t,i);return Je(r,i,e)};x.prototype.tan=function(){if(this.isNaN())return x.NAN;if(!this.isFinite())return x.NAN;if(this.isZero())return x.ZERO;let e=x.precision,n=e+15,[t,i]=Ve(this,n),[r,s]=Et(t,i);if(s===0n)return r>0n?x.POSITIVE_INFINITY:x.NEGATIVE_INFINITY;let o=r*i/s;return Je(o,i,e)};x.prototype.atan=function(){if(this.isNaN())return x.NAN;if(this.isZero())return x.ZERO;if(!this.isFinite()){let s=x.PI.div(x.TWO);return this.significand>0n?s:s.neg()}let e=x.precision,n=e+15,[t,i]=Ve(this,n),r=zn(t,i);return Je(r,i,e)};x.prototype.asin=function(){if(this.isNaN())return x.NAN;if(!this.isFinite())return x.NAN;if(this.isZero())return x.ZERO;let e=this.abs(),n=x.ONE;if(e.gt(n))return x.NAN;if(e.eq(n)){let f=x.PI.div(x.TWO);return this.significand>0n?f:f.neg()}let t=x.precision,i=t+20,[r,s]=Ve(this,i),o=js(r,r,s),a=s-o,u=Gn(a,s),l=Us(r,u,s),c=zn(l,s);return Je(c,s,t)};x.prototype.acos=function(){return this.isNaN()?x.NAN:this.isFinite()?this.abs().gt(x.ONE)?x.NAN:this.eq(1)?x.ZERO:this.eq(-1)?x.PI:x.PI.div(x.TWO).sub(this.asin()):x.NAN};x.sin=function(e){return e.sin()};x.cos=function(e){return e.cos()};x.tan=function(e){return e.tan()};x.asin=function(e){return e.asin()};x.acos=function(e){return e.acos()};x.atan=function(e){return e.atan()};x.atan2=function(e,n){let t=e instanceof x?e:new x(e);if(t.isNaN()||n.isNaN())return x.NAN;let i=x.PI,r=i.div(x.TWO);if(n.isZero())return t.isZero()?x.ZERO:t.significand>0n?r:r.neg();let s=t.div(n);return n.significand>0n?s.atan():t.significand>=0n?s.atan().add(i):s.atan().sub(i)};x.prototype.sinh=function(){if(this.isNaN())return x.NAN;if(this.isZero())return x.ZERO;if(!this.isFinite())return this.significand>0n?x.POSITIVE_INFINITY:x.NEGATIVE_INFINITY;let e=this.exp(),n=e.inv();return e.sub(n).div(x.TWO)};x.prototype.cosh=function(){if(this.isNaN())return x.NAN;if(this.isZero())return x.ONE;if(!this.isFinite())return x.POSITIVE_INFINITY;let e=this.exp(),n=e.inv();return e.add(n).div(x.TWO)};x.prototype.tanh=function(){if(this.isNaN())return x.NAN;if(this.isZero())return x.ZERO;if(!this.isFinite())return this.significand>0n?x.ONE:x.NEGATIVE_ONE;let e=this.mul(x.TWO).exp();return e.sub(x.ONE).div(e.add(x.ONE))};x.sinh=function(e){return e.sinh()};x.cosh=function(e){return e.cosh()};x.tanh=function(e){return e.tanh()};function Xs(e,n){let i=K(e),r=Math.max(0,i-15),s=Number(r>0?e/O(r):e),o=K(n),a=Math.max(0,o-15),u=Number(a>0?n/O(a):n),l=r+2*a,c=Math.floor(l/3),f=l%3,m=Math.cbrt(s*u*u);f===1&&(m*=2.154434690031882),f===2&&(m*=4.641588833612779);let d=BigInt(Math.round(m))*O(c);return d>0n?d:1n}var Qp=[BigInt(4),BigInt(2),BigInt(4),BigInt(2),BigInt(4),BigInt(6),BigInt(2),BigInt(6)];var cl=53,Qs=Math.floor(Math.log10(Math.pow(2,cl))),fl=1e-10;var Ai=1e4;function Me(e,n){if(e===0)return n;if(n===0||e===n)return e;if(!Number.isInteger(e)||!Number.isInteger(n))return NaN;for(;n!==0;)[e,n]=[n,e%n];return e<0?-e:e}function Xe(e,n){if(e===0||n===0)return 0;let t=BigInt(e)*BigInt(n)/BigInt(Me(e,n));return Number(t)}function Un(e){if(!Number.isInteger(e)||e<0)return NaN;if(e>=170)return 1/0;let n=1;for(let t=2;t<=e;t++)n=n*t;return n}function Hn(e){if(!Number.isInteger(e)||e<0)return NaN;if(e<0)return NaN;if(e<=1)return 1;let n=e;for(;e>2;)e-=2,n*=e;return n}function Zn(e,n=fl){return typeof e=="number"&&Math.abs(e)<=n?0:e}function Tt(e,n,t=1){if(t===0){let s=Tt(e,n,-1),o=Tt(e,n,1);return s===void 0||o===void 0?NaN:Math.abs(s-o)>1e-5?NaN:(s+o)/2}let[i,r]=_i(e,n,{step:t>0?1:-1});return i}var En=["number","finite_number","complex","finite_complex","imaginary","real","finite_real","rational","finite_rational","integer","finite_integer","non_finite_number"],$i=["indexed_collection","list","tuple"],It=[...$i,"collection","set","record","dictionary"],_t=["scalar",...En,"boolean","string"],Ci=["value","color",...It,..._t],Ri=["expression","symbol","function",...Ci],Qe=["any","unknown","nothing","never","error",...Ri];function kt(e){return typeof e=="string"?Qe.includes(e):typeof e!="object"||!("kind"in e)?!1:e.kind==="signature"||e.kind==="union"||e.kind==="intersection"||e.kind==="negation"||e.kind==="tuple"||e.kind==="list"||e.kind==="record"||e.kind==="dictionary"||e.kind==="set"||e.kind==="function"||e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="reference"}var eo=3,no=1,to=2,pl=4,ml=5,dl=6,hl=7,gl=8,bl=9,yl=10,xl=11;function J(e,n=0){if(typeof e=="string")return e;let t="";switch(e.kind){case"value":typeof e.value=="string"?t=`"${e.value}"`:typeof e.value=="boolean"?t=e.value?"true":"false":t=e.value.toString();break;case"reference":t=e.name;break;case"negation":t=`!${J(e.type,eo)}`;break;case"union":t=e.types.map(u=>J(u,no)).join(" | ");break;case"intersection":t=e.types.map(u=>J(u,to)).join(" & ");break;case"expression":t=`expression<${Ks(e.operator)}>`;break;case"symbol":t=`symbol<${Ks(e.name)}>`;break;case"numeric":Number.isFinite(e.lower)&&Number.isFinite(e.upper)?t=`${e.type}<${e.lower}..${e.upper}>`:Number.isFinite(e.lower)?t=`${e.type}<${e.lower}..>`:Number.isFinite(e.upper)?t=`${e.type}<..${e.upper}>`:t=`${e.type}`;break;case"list":if(e.dimensions&&typeof e.elements=="string"&&En.includes(e.elements)){if(e.dimensions===void 0)e.elements==="number"&&(t="tensor");else if(e.dimensions.length===1)e.elements==="number"?e.dimensions[0]<0?t="vector":t=`vector<${e.dimensions[0]}>`:e.dimensions[0]<0?t=`vector<${J(e.elements)}>`:t=`vector<${J(e.elements)}^${e.dimensions[0]}>`;else if(e.dimensions.length===2){let u=e.dimensions;e.elements==="number"?u[0]<0&&u[1]<0?t="matrix":t=`matrix<${u[0]}x${u[1]}>`:u[0]<0&&u[1]<0?t=`matrix<${J(e.elements)}>`:t=`matrix<${J(e.elements)}^(${u[0]}x${u[1]})>`}}if(!t){let u=e.dimensions?e.dimensions.length===1?`^${e.dimensions[0].toString()}`:`^(${e.dimensions.join("x")})`:"";t=`list<${J(e.elements)}${u}>`}break;case"record":t=`record<${Object.entries(e.elements).map(([u,l])=>`${u}: ${J(l)}`).join(", ")}>`;break;case"dictionary":t=`dictionary<${J(e.values)}>`;break;case"set":t=`set<${J(e.elements)}>`;break;case"collection":t=`collection<${J(e.elements)}>`;break;case"indexed_collection":t=`indexed_collection<${J(e.elements)}>`;break;case"tuple":if(e.elements.length===0)t="tuple";else if(e.elements.length===1){let[u]=e.elements;t=`tuple<${Nn(u)}>`}else t="tuple<"+e.elements.map(u=>Nn(u)).join(", ")+">";break;case"signature":let r=e.args?e.args.map(u=>Nn(u)).join(", "):"",s=e.optArgs?e.optArgs.map(u=>Nn(u)+"?").join(", "):"",o=e.variadicArg?e.variadicMin===0?`${Nn(e.variadicArg)}*`:`${Nn(e.variadicArg)}+`:"";t=`(${[r,s,o].filter(u=>u).join(", ")}) -> ${J(e.result)}`;break;default:t="error"}return n>0&&n>vl(e.kind)?`(${t})`:t}function Nn(e){return e.name?`${e.name}: ${J(e.type)}`:J(e.type)}function Ks(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)?e:`\`${e}\``}function vl(e){switch(e){case"negation":return eo;case"union":return no;case"intersection":return to;case"list":return pl;case"record":return ml;case"dictionary":return dl;case"set":return hl;case"collection":case"indexed_collection":return gl;case"tuple":return bl;case"signature":return yl;case"value":return xl;default:return 0}}function El(e,n){if(e===n)return 0;if(e.length===0)return n.length;if(n.length===0)return e.length;let t=Array.from({length:e.length+1},(r,s)=>s),i=new Array(e.length+1);for(let r=1;r<=n.length;r++){i[0]=r;for(let s=1;s<=e.length;s++){let o=e[s-1]===n[r-1]?0:1;i[s]=Math.min(t[s]+1,i[s-1]+1,t[s-1]+o)}[t,i]=[i,t]}return t[e.length]}function St(e,n){let i=null,r=1/0,s=e.length;for(let o of n){if(Math.abs(s-o.length)>7)continue;let a=El(e,o);if(a===0)return o;a<=7&&a<r&&(r=a,i=o)}return i}var Mt=class{input;pos=0;line=1;column=1;tokens=[];constructor(n){this.input=n}saveState(){return{pos:this.pos,line:this.line,column:this.column,tokens:[...this.tokens]}}restoreState(n){this.pos=n.pos,this.line=n.line,this.column=n.column,this.tokens=n.tokens}error(n){throw new Error(`Lexer error at line ${this.line}, column ${this.column}: ${n}`)}peek(n=0){let t=this.pos+n;return t<this.input.length?this.input[t]:""}advance(){let n=this.input[this.pos++];return n===`
4
- `?(this.line++,this.column=1):this.column++,n}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){for(let t=0;t<n.length;t++)this.advance();return!0}return!1}isEOF(){return this.pos>=this.input.length}skipWhitespace(){for(;!this.isEOF()&&/\s/.test(this.peek());)this.advance()}readIdentifier(){let n="";for(;!this.isEOF()&&/[a-zA-Z0-9_]/.test(this.peek());)n+=this.advance();return n}readVerbatimString(){if(!this.match("`"))return"";let n="";for(;!this.isEOF()&&this.peek()!=="`";)this.match("\\`")?n+="`":this.match("\\\\")?n+="\\":n+=this.advance();return this.isEOF()&&this.error("Unterminated verbatim string"),this.advance(),n}readStringLiteral(){let n=this.advance(),t="";for(;!this.isEOF()&&this.peek()!==n;)this.match("\\"+n)?t+=n:this.match("\\\\")?t+="\\":t+=this.advance();return this.isEOF()&&this.error("Unterminated string literal"),this.advance(),t}readNumber(){let n="";if((this.peek()==="-"||this.peek()==="+")&&(n+=this.advance()),this.match("0x")||this.match("0X")){for(n+="x";!this.isEOF()&&/[0-9a-fA-F]/.test(this.peek());)n+=this.advance();return"0"+n}if(this.match("0b")||this.match("0B")){for(n+="b";!this.isEOF()&&/[01]/.test(this.peek());)n+=this.advance();return"0"+n}for(;!this.isEOF()&&/[0-9]/.test(this.peek());)n+=this.advance();if(this.peek()==="."&&/[0-9]/.test(this.peek(1)))for(n+=this.advance();!this.isEOF()&&/[0-9]/.test(this.peek());)n+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(n+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(n+=this.advance());!this.isEOF()&&/[0-9]/.test(this.peek());)n+=this.advance();return n}createToken(n,t){return{type:n,value:t,position:this.pos-t.length,line:this.line,column:this.column-t.length}}nextToken(){if(this.skipWhitespace(),this.isEOF())return this.createToken("EOF","");let n=this.pos,t=this.peek();if(this.match("->"))return this.createToken("->","->");if(this.match(".."))return this.createToken("..","..");if(this.match("+\u221E")||this.match("+oo"))return this.createToken("PLUS_INFINITY",this.input.slice(n,this.pos));if(this.match("-\u221E")||this.match("-oo"))return this.createToken("MINUS_INFINITY",this.input.slice(n,this.pos));if(this.match("+infinity"))return this.createToken("PLUS_INFINITY","+infinity");if(this.match("-infinity"))return this.createToken("MINUS_INFINITY","-infinity");if(/[a-zA-Z_]/.test(t)){let i=this.readIdentifier();switch(i){case"true":return this.createToken("TRUE",i);case"false":return this.createToken("FALSE",i);case"nan":return this.createToken("NAN",i);case"infinity":return this.createToken("INFINITY",i);case"oo":return this.createToken("INFINITY",i);default:return this.createToken("IDENTIFIER",i)}}switch(t){case"|":return this.advance(),this.createToken("|","|");case"&":return this.advance(),this.createToken("&","&");case"!":return this.advance(),this.createToken("!","!");case"^":return this.advance(),this.createToken("^","^");case"(":return this.advance(),this.createToken("(","(");case")":return this.advance(),this.createToken(")",")");case"<":return this.advance(),this.createToken("<","<");case">":return this.advance(),this.createToken(">",">");case"[":return this.advance(),this.createToken("[","[");case"]":return this.advance(),this.createToken("]","]");case",":return this.advance(),this.createToken(",",",");case":":return this.advance(),this.createToken(":",":");case"?":return this.advance(),this.createToken("?","?");case"*":return this.advance(),this.createToken("*","*");case"+":return/[0-9]/.test(this.peek(1))?this.createToken("NUMBER_LITERAL",this.readNumber()):(this.advance(),this.createToken("+","+"));case"x":return/[0-9]/.test(this.peek(1))?(this.advance(),this.createToken("x","x")):(this.advance(),this.createToken("x","x"))}if(t==='"'||t==="'")return this.createToken("STRING_LITERAL",this.readStringLiteral());if(t==="`")return this.createToken("VERBATIM_STRING",this.readVerbatimString());if(/[0-9]/.test(t)||t==="-"&&/[0-9]/.test(this.peek(1))){let i=this.readNumber();return this.peek()==="x"&&/[0-9]/.test(this.peek(1)),this.createToken("NUMBER_LITERAL",i)}if(t==="\u221E")return this.advance(),this.createToken("INFINITY","\u221E");this.error(`Unexpected character: ${t}`)}tokenize(){let n=[];for(;!this.isEOF();){let t=this.nextToken();if(t&&(n.push(t),t.type==="EOF"))break}return n}peekToken(){if(this.tokens.length===0){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens[0]||this.createToken("EOF","")}consumeToken(){if(this.tokens.length===0){let n=this.nextToken();if(n)return n}return this.tokens.shift()||this.createToken("EOF","")}matchToken(n){return this.peekToken().type===n?(this.consumeToken(),!0):!1}expectToken(n){let t=this.consumeToken();return t.type!==n&&this.error(`Expected ${n}, got ${t.type}`),t}};var wt=class{lexer;typeResolver;current;constructor(n,t){this.lexer=new Mt(n),this.typeResolver=t?.typeResolver??{forward:()=>{},resolve:()=>{},get names(){return[]}},this.current=this.lexer.consumeToken()}error(n,t){this.errorAtToken(this.current,n,t)}errorAtToken(n,t,i){let r=this.lexer.input,o=r.split(`
3
+ var Compile=(()=>{var Fi=Object.defineProperty;var Gl=Object.getOwnPropertyDescriptor;var jl=Object.getOwnPropertyNames;var Ul=Object.prototype.hasOwnProperty;var Hl=(e,n)=>{for(var t in n)Fi(e,t,{get:n[t],enumerable:!0})},Zl=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of jl(n))!Ul.call(e,r)&&r!==t&&Fi(e,r,{get:()=>n[r],enumerable:!(i=Gl(n,r))||i.enumerable});return e};var Yl=e=>Zl(Fi({},"__esModule",{value:!0}),e);var qm={};Hl(qm,{BaseCompiler:()=>b,GLSLTarget:()=>Ei,GPUShaderTarget:()=>cn,IntervalJavaScriptTarget:()=>Pi,JavaScriptTarget:()=>xi,PythonTarget:()=>Ti,WGSLTarget:()=>Ni,compile:()=>Eu,version:()=>Vm});function Oi(e,n,t={}){let{contract:i=.125,step:r=1,power:s=2,atol:o=1e-16,rtol:a=o>0?0:Math.sqrt(Number.EPSILON),maxeval:u=1e6,breaktol:l=2}=t;if(!isFinite(n))return Oi(N=>e(1/N),1/n,{rtol:a,atol:o,maxeval:u,contract:Math.abs(i)>1?1/i:i,step:1/r,power:s});let c=r,f=Math.pow(1/i,s),d=e(n+c),m=[d],g=1/0,v=1;for(;v<u;){v+=1,c*=i,m.push(e(n+c));let N=f,M=1/0;for(let $=m.length-2;$>=0;$--){let P=m[$];m[$]=m[$+1]+(m[$+1]-m[$])/(N-1);let J=Math.abs(m[$]-P);M=Math.min(M,J),J<g&&(d=m[$],g=J),N*=f}if(M>l*g||!isFinite(M)||g<=Math.max(a*Math.abs(d),o))break}return[d,g]}var ho=new Map;function L(e){if(e<=100){let n=ho.get(e);return n===void 0&&(n=10n**BigInt(e),ho.set(e,n)),n}return 10n**BigInt(e)}function bo(e,n,t){return e*n/t}function yo(e,n,t){return e*t/n}function Zn(e,n){if(e===0n)return 0n;if(e<0n)throw new RangeError("fpsqrt: negative input");let t,i=Number(e),r=Number(n);if(Number.isFinite(i)&&Number.isFinite(r)&&i>0&&r>0){let c=Math.sqrt(i/r)*r;Number.isFinite(c)&&c>0?(t=BigInt(Math.floor(c)),t===0n&&(t=1n)):t=go(e,n)}else t=go(e,n);let s=e*n,o;do o=t,t=(t+s/t)/2n;while(ke(t-o)>1n);let a=(t+s/t)/2n,u=ke(t*t-s);return ke(a*a-s)<u?a:t}function go(e,n){let i=Y(e),r=Math.max(0,i-15),s=Number(r>0?e/L(r):e),o=Y(n),a=Math.max(0,o-15),u=Number(a>0?n/L(a):n),l=r+a,c=Math.floor(l/2),f=Math.sqrt(s*u);l%2!==0&&(f*=3.1622776601683795);let d=BigInt(Math.round(f))*L(c);return d>0n?d:1n}function ke(e){return e<0n?-e:e}function Y(e){if(e===0n)return 1;if(e<0n&&(e=-e),e<0x20000000000000n)return Math.floor(Math.log10(Number(e)))+1;let n=0,t=e,i=1;for(;t>>BigInt(i)>0n;)i*=2;for(let s=i>>1;s>=1;s>>=1)t>>BigInt(s)>0n&&(n+=s,t>>=BigInt(s));n+=1;let r=Math.ceil(n*.30102999566398);return e<L(r-1)?r-1:e>=L(r)?r+1:r}function Vi(e,n){if(e===0n)return n;let t=0,i=e,r=n/2n;for(;ke(i)>r;)i=i/2n,t++;let s=n,o=i;s+=o;for(let a=2;o=o*i/(BigInt(a)*n),ke(o)!==0n;a++)s+=o;for(let a=0;a<t;a++)s=s*s/n;return s}function qi(e,n){if(e<=0n)throw new RangeError("fpln: input must be positive");if(e===n)return 0n;let t=Number(e),i=Number(n),r,s=e,o=0;if(Number.isFinite(t)&&Number.isFinite(i)&&t>0&&i>0){let u=t/i;if(Number.isFinite(u)&&u>0){let l=Math.log(u);Number.isFinite(l)?r=BigInt(Math.round(l*i)):r=Li(e,n)}else r=Li(e,n)}else{s=e;let u=2n*n,l=n/2n;for(;s>u||s<l;)s=Zn(s,n),o++;r=Li(s,n)}let a=0n;for(let u=0;u<100;u++){let l=Vi(r,n);if(l===0n){r=r/2n;continue}let c=r+s*n/l-n,f=ke(c-r);if(f<=1n||f<100000n&&a>0n&&a<100000n&&f*4n>=a)break;a=f,r=c}for(let u=0;u<o;u++)r=2n*r;return r}function Li(e,n){let t=Y(e),i=Y(n);return BigInt(t-i)*2302585n*n/1000000n}var nn="314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635",kt=null;function Bi(e){if(kt!==null&&kt.scale===e)return kt.value;let t=Y(e)-1+10,i=nn.slice(0,t+1),r=BigInt(i),s=i.length-1,o=r*e/L(s);return kt={scale:e,value:o},o}function Mt(e,n){if(e===0n)return[0n,n];let t=Bi(n),i=2n*t,r=t/2n,s,o=ke(e);if(o>n*(1n<<30n)){let P=Y(o)-Y(n)+20,J=n*L(P),H=e*L(P),ue=2n*Bi(J),Z=H%ue;Z<0n&&(Z+=ue),s=Z/L(P)}else s=e%i;s<0n&&(s+=i);let a=1n,u=1n;s>3n*r?(s=i-s,a=-1n):s>t?(s=s-t,a=-1n,u=-1n):s>r&&(s=t-s,u=-1n);let l=Y(n)-1,c=Math.min(18,Math.max(2,Math.ceil(.87*Math.sqrt(l)))),f=0,d=n>>BigInt(c);for(;s>d;)s=s/2n,f++;let m=s,g=n,v=s,N=n,M=s*s,$=n*n;for(let P=2;;P+=2){if(N=N*M/(BigInt(P)*BigInt(P-1)*$),N===0n){v=v*M/(BigInt(P+1)*BigInt(P)*$),v!==0n&&(P%4===2?(g-=N,m-=v):(g+=N,m+=v));break}if(v=v*M/(BigInt(P+1)*BigInt(P)*$),P%4===2?(g-=N,m-=v):(g+=N,m+=v),v===0n)break}for(let P=0;P<f;P++){let J=2n*m*g/n,H=2n*g*g/n-n;m=J,g=H}return[a*m,u*g]}function Hn(e,n){if(e===0n)return 0n;if(e<0n)return-Hn(-e,n);let i=Bi(n)/2n;if(e>n){let f=n*n/e;return i-Hn(f,n)}let r=4n*n/10n,s=0,o=e;for(;o>r;){let f=o*o,d=(n*n+f)/n,m=Zn(d,n);o=o*n/(n+m),s++}let a=o,u=o,l=o*o,c=n*n;for(let f=3;u=u*l/c,u!==0n;f+=2)f%4===3?a-=u/BigInt(f):a+=u/BigInt(f);for(let f=0;f<s;f++)a=2n*a;return a}var Ji=NaN,y=class e{static precision=50;static ZERO=Object.freeze(Object.assign(Object.create(e.prototype),{significand:0n,exponent:0}));static ONE=Object.freeze(Object.assign(Object.create(e.prototype),{significand:1n,exponent:0}));static TWO=Object.freeze(Object.assign(Object.create(e.prototype),{significand:2n,exponent:0}));static NEGATIVE_ONE=Object.freeze(Object.assign(Object.create(e.prototype),{significand:-1n,exponent:0}));static HALF=Object.freeze(Object.assign(Object.create(e.prototype),{significand:5n,exponent:-1}));static NAN=Object.freeze(Object.assign(Object.create(e.prototype),{significand:0n,exponent:NaN}));static POSITIVE_INFINITY=Object.freeze(Object.assign(Object.create(e.prototype),{significand:1n,exponent:1/0}));static NEGATIVE_INFINITY=Object.freeze(Object.assign(Object.create(e.prototype),{significand:-1n,exponent:1/0}));static _piFullPrecision=null;static _piCache=null;static _piCachePrecision=0;static get PI(){e._piFullPrecision===null&&(e._piFullPrecision=new e(nn[0]+"."+nn.slice(1)));let n=e.precision;return(e._piCache===null||e._piCachePrecision!==n)&&(e._piCache=e._piFullPrecision.toPrecision(n+4),e._piCachePrecision=n),e._piCache}significand;exponent;constructor(n){if(n instanceof e){this.significand=n.significand,this.exponent=n.exponent;return}if(typeof n=="bigint"){[this.significand,this.exponent]=wt(n,0);return}if(typeof n=="number"){[this.significand,this.exponent]=Wl(n);return}[this.significand,this.exponent]=Eo(n)}isNaN(){return Number.isNaN(this.exponent)}isZero(){return this.exponent===0&&this.significand===0n}isFinite(){return Number.isFinite(this.exponent)}isInteger(){return this.isFinite()&&this.exponent>=0}isPositive(){return this.significand>0n}isNegative(){return this.significand<0n}cmp(n){if(typeof n=="number"){if(Number.isNaN(n))return Ji;let m=this.exponent;if(Number.isNaN(m))return Ji;if(n===0)return this.significand===0n?0:this.significand>0n?1:-1;if(!Number.isFinite(m))return n===1/0?this.significand>0n?0:-1:n===-1/0?this.significand<0n?0:1:this.significand>0n?1:-1;if(this.significand===0n)return n>0?-1:1;if(n===1/0)return-1;if(n===-1/0)return 1;if(this.significand>0n!=n>0)return this.significand>0n?1:-1;if(Number.isInteger(n)&&m>=0&&m<=15){let g=this.significand*L(m),v=BigInt(n);return g<v?-1:g>v?1:0}n=new e(n)}let t=this.exponent,i=n.exponent,r=this.significand,s=n.significand;if(t!==t||i!==i)return Ji;if(!Number.isFinite(t)||!Number.isFinite(i))return!Number.isFinite(t)&&!Number.isFinite(i)?r===s?0:r>s?1:-1:Number.isFinite(t)?s>0n?-1:1:r>0n?1:-1;if(r===0n)return s===0n?0:s>0n?-1:1;if(s===0n)return r>0n?1:-1;if(r>0n&&s<0n)return 1;if(r<0n&&s>0n)return-1;if(t===i)return r<s?-1:r>s?1:0;let o=Y(r),a=Y(s),u=o+t,l=a+i;if(u!==l){let m=r>0n?1:-1;return u>l?m:-m}let c=r,f=s,d=Math.abs(t-i);if(d>1e3){let m=o,g=a,v=Math.max(m,g)+1;m<v&&(c=c*L(v-m)),g<v&&(f=f*L(v-g))}else t<i?f=f*L(d):c=c*L(d);return c<f?-1:c>f?1:0}eq(n){return typeof n=="number"?n===0?this.significand===0n&&this.exponent===0:n===1?this.significand===1n&&this.exponent===0:n===-1?this.significand===-1n&&this.exponent===0:Number.isInteger(n)&&Number.isFinite(this.exponent)&&this.exponent>=0&&this.exponent<=15?this.significand*L(this.exponent)===BigInt(n):this.cmp(n)===0:this.significand===n.significand&&this.exponent===n.exponent}lt(n){return this.cmp(n)===-1}lte(n){let t=this.cmp(n);return t===-1||t===0}gt(n){return this.cmp(n)===1}gte(n){let t=this.cmp(n);return t===1||t===0}add(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;if(Number.isFinite(t)&&Number.isFinite(i)){if(t===i)return B(this.significand+n.significand,t);let o=t-i;return o>0?B(this.significand*L(o)+n.significand,i):B(this.significand+n.significand*L(-o),t)}if(t!==t||i!==i)return e.NAN;let r=!Number.isFinite(t),s=!Number.isFinite(i);return r&&s?this.significand!==n.significand?e.NAN:this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:r?this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:n.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}sub(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;if(Number.isFinite(t)&&Number.isFinite(i)){if(t===i)return B(this.significand-n.significand,t);let o=t-i;return o>0?B(this.significand*L(o)-n.significand,i):B(this.significand-n.significand*L(-o),t)}if(t!==t||i!==i)return e.NAN;let r=!Number.isFinite(t),s=!Number.isFinite(i);return r&&s?this.significand===n.significand?e.NAN:this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:r?this.significand>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY:n.significand>0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY}mul(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;if(Number.isFinite(t)&&Number.isFinite(i))return B(this.significand*n.significand,t+i);if(t!==t||i!==i||this.significand===0n||n.significand===0n)return e.NAN;let r=this.significand>0n?1n:-1n,s=n.significand>0n?1n:-1n;return r*s>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}neg(){let n=this.significand;return n===0n?this:Number.isFinite(this.exponent)?B(-n,this.exponent):n>0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY}abs(){return this.significand>=0n?this:Number.isFinite(this.exponent)?B(-this.significand,this.exponent):e.POSITIVE_INFINITY}floor(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=this.trunc();return this.significand<0n?t.sub(B(1n,0)):t}return this}ceil(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=this.trunc();return this.significand>0n?t.add(B(1n,0)):t}return this}round(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=B(5n,-1);return this.significand>0n?this.add(t).trunc():this.sub(t).trunc()}return this}trunc(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=this.significand/L(-n);return B(t===0n?0n:t,0)}return this}div(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent,r=this.significand,s=n.significand;if(Number.isFinite(t)&&Number.isFinite(i)){if(s===0n)return r===0n?e.NAN:r>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY;if(r===0n)return B(0n,0);let u=e.precision,l=10,c=r<0n?-r:r,f=s<0n?-s:s,d=Y(c),m=Y(f),g=u+l+Math.max(0,m-d),v=L(g),N=r*v/s,M=t-i-g;return B(N,M).toPrecision(u)}if(t!==t||i!==i)return e.NAN;let o=!Number.isFinite(t),a=!Number.isFinite(i);if(o&&a)return e.NAN;if(o){let u=r>0n?1n:-1n,l=s>0n?1n:s<0n?-1n:1n;return u*l>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}return B(0n,0)}inv(){return B(1n,0).div(this)}mod(n){typeof n=="number"&&(n=new e(n));let t=this.exponent,i=n.exponent;if(Number.isFinite(t)&&Number.isFinite(i)){if(n.significand===0n)return e.NAN;if(this.significand===0n)return B(0n,0);let r=t-i,s=r>=0?this.significand*L(r):this.significand,o=r>=0?n.significand:n.significand*L(-r),a=s/o;return this.sub(B(a,0).mul(n))}return t!==t||i!==i||!Number.isFinite(t)?e.NAN:new e(this)}pow(n){if(typeof n=="number"&&(n=new e(n)),this.isNaN()||n.isNaN()||!n.isFinite())return e.NAN;if(n.isInteger()){let l=n.toBigInt();if(l===0n)return B(1n,0);if(!this.isFinite())return l>0n?this.significand<0n&&l%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY:B(0n,0);if(this.isZero())return l>0n?B(0n,0):e.POSITIVE_INFINITY;if(l<0n)return this.pow(n.neg()).inv();let c=this.significand<0n?-this.significand:this.significand,f=Y(c),d=f>15?f-15:0,m=d>0?Number(c/10n**BigInt(d)):Number(c),g=Math.log10(m)+d+this.exponent,v=Number(l)*g;if(v>9e15)return this.significand<0n&&l%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY;if(v<-9e15)return B(0n,0);let N=e.precision,M=B(1n,0),$=this,P=l;for(;P>0n;)P&1n&&(M=M.mul($).toPrecision(N)),P>>=1n,P>0n&&($=$.mul($).toPrecision(N));return M}if(!this.isFinite())return this.significand<0n?e.NAN:n.significand>0n?e.POSITIVE_INFINITY:e.ZERO;if(this.isZero())return n.significand>0n?e.ZERO:e.POSITIVE_INFINITY;if(this.significand<0n)return e.NAN;let t=this.significand,i=this.exponent+Y(t)-1,r=n.significand<0n?-n.significand:n.significand,o=n.exponent+Y(r)-1+Math.log10(Math.abs(i)*2.303+3)+1,a=Math.min(20,Math.max(2,Math.ceil(o)+2)),u=e.precision;e.precision=u+a;try{return n.mul(this.ln()).exp().toPrecision(u)}finally{e.precision=u}}toNumber(){return Number.isFinite(this.exponent)?this.significand===0n?0:this.exponent===0?Number(this.significand):Number(this.toString()):this.exponent!==this.exponent?NaN:this.significand>0n?1/0:-1/0}toString(){if(!Number.isFinite(this.exponent))return this.exponent!==this.exponent?"NaN":this.significand>0n?"Infinity":"-Infinity";if(this.significand===0n)return"0";let n=this.significand<0n,t=(n?-this.significand:this.significand).toString(),i=t.length,r=i+this.exponent-1,s=n?"-":"";if(r>20||r<-6){let u=i===1?t:t[0]+"."+t.slice(1),l=r>=0?"+":"";return`${s}${u}e${l}${r}`}if(this.exponent>=0)return s+t+"0".repeat(this.exponent);let o=-this.exponent;if(o<i){let u=t.slice(0,i-o),l=t.slice(i-o);return`${s}${u}.${l}`}let a=o-i;return`${s}0.${"0".repeat(a)}${t}`}toFixed(n){let t=n??0;if(!Number.isFinite(this.exponent))return this.exponent!==this.exponent?"NaN":this.significand>0n?"Infinity":"-Infinity";let i=this.significand<0n,r=i?-this.significand:this.significand,s=this.exponent+t,o;if(s>=0)o=r*L(s);else{let f=L(-s),d=r/f,m=r%f,g=f/2n;m>g?o=d+1n:m<g||f%2n!==0n||d%2n===0n?o=d:o=d+1n}let a=i&&o!==0n?"-":"",u=o.toString();if(t===0)return`${a}${u}`;if(u.length<=t){let f=u.padStart(t,"0");return`${a}0.${f}`}let l=u.slice(0,u.length-t),c=u.slice(u.length-t);return`${a}${l}.${c}`}toPrecision(n){if(this.significand===0n||!Number.isFinite(this.exponent))return this;let t=this.significand<0n?-this.significand:this.significand,i=Y(t);if(i<=n)return this;let r=i-n,s=L(r),o=t/s,a=t%s,u=s/2n;(a>u||a===u&&o%2n!==0n)&&(o+=1n);let l=this.significand<0n?-o:o;return B(l,this.exponent+r)}toBigInt(){if(!Number.isFinite(this.exponent))throw this.exponent!==this.exponent?new RangeError("Cannot convert NaN to BigInt"):new RangeError("Cannot convert Infinity to BigInt");if(this.exponent>=0)return this.significand*L(this.exponent);let n=L(-this.exponent);return this.significand/n}};function B(e,n){let[t,i]=wt(e,n),r=Object.create(y.prototype);return r.significand=t,r.exponent=i,r}var xo=1000000000n,vo=1000n;function wt(e,n){if(e===0n)return[0n,0];for(;e%xo===0n;)e/=xo,n+=9;for(;e%vo===0n;)e/=vo,n+=3;for(;e%10n===0n;)e/=10n,n+=1;return[e,n]}function Wl(e){return Number.isNaN(e)?[0n,NaN]:e===1/0?[1n,1/0]:e===-1/0?[-1n,1/0]:Number.isInteger(e)?wt(BigInt(e),0):Eo(e.toString())}function Eo(e){if(e=e.trim(),e===""||e==="NaN")return[0n,NaN];if(e==="Infinity"||e==="+Infinity")return[1n,1/0];if(e==="-Infinity")return[-1n,1/0];let n,t=0,i=e.search(/[eE]/);if(i!==-1){if(n=e.slice(0,i),t=Number(e.slice(i+1)),!Number.isFinite(t))return[0n,NaN]}else n=e;let r=!1;n.startsWith("-")?(r=!0,n=n.slice(1)):n.startsWith("+")&&(n=n.slice(1));let s=n.indexOf("."),o,a;s===-1?(o=n,a=""):(o=n.slice(0,s),a=n.slice(s+1)),o=o.replace(/^0+/,"")||"0";let u=o+a;if(u.length===0||!/^\d+$/.test(u))return[0n,NaN];let l=BigInt(u);r&&(l=-l);let c=-a.length;return wt(l,c+t)}function Ge(e,n){let t=L(n),i=e.exponent+n;return i>=0?[e.significand*L(i),t]:[e.significand/L(-i),t]}function je(e,n,t){if(e===0n)return y.ZERO;let i=e<0n,r=i?-e:e,s=Y(r);if(s>t){let l=s-t,c=L(l),f=c/2n,d=r%c;r=r/c,d>=f&&(r+=1n);let m=Y(n)-1,g=l-m,v=i?-r:r;return B(v,g)}let a=-(Y(n)-1),u=i?-r:r;return B(u,a)}function $e(e){let n=e.significand<0n?-e.significand:e.significand;return e.exponent+Y(n)-1}var No=BigInt(Number.MAX_SAFE_INTEGER),To=null,Io=null;function So(e){return Io!==e&&(To=qi(10n*e,e),Io=e),To}y.prototype.sqrt=function(){if(this.isNaN())return y.NAN;if(this.isZero())return y.ZERO;if(!this.isFinite())return this.significand>0n?y.POSITIVE_INFINITY:y.NAN;if(this.significand<0n)return y.NAN;let e=y.precision,n=e+10,t=$e(this),i=Math.floor(t/2),r=B(this.significand,this.exponent-2*i),[s,o]=Ge(r,n),a=Zn(s,o),u=je(a,o,e);return B(u.significand,u.exponent+i)};y.prototype.cbrt=function(){if(this.isNaN())return y.NAN;if(this.isZero())return y.ZERO;if(!this.isFinite())return this.significand>0n?y.POSITIVE_INFINITY:y.NEGATIVE_INFINITY;if(this.significand<0n)return this.neg().cbrt().neg();let e=y.precision,n=e+10,t=$e(this),i=Math.floor(t/3),r=B(this.significand,this.exponent-3*i),[s,o]=Ge(r,n),a=s*o*o,u,l=r.toNumber(),c=Number(o);if(Number.isFinite(l)&&l>0&&Number.isFinite(c)){let m=Math.cbrt(l);Number.isFinite(m)&&m>0?(u=BigInt(Math.floor(m*c)),u===0n&&(u=1n)):u=_o(s,o)}else u=_o(s,o);let f;do{f=u;let m=u*u;if(m===0n){u=1n;break}u=(2n*u+a/m)/3n}while(ke(u-f)>1n);{let m=(2n*u+a/(u*u))/3n,g=ke(u*u*u-a);ke(m*m*m-a)<g&&(u=m)}let d=je(u,o,e);return B(d.significand,d.exponent+i)};y.sqrt=function(e){return e.sqrt()};y.cbrt=function(e){return e.cbrt()};y.prototype.exp=function(){if(this.isNaN())return y.NAN;if(!this.isFinite())return this.significand>0n?y.POSITIVE_INFINITY:y.ZERO;if(this.isZero())return y.ONE;if($e(this)>=17)return this.significand>0n?y.POSITIVE_INFINITY:y.ZERO;let e=y.precision,n=this.significand<0n?-this.significand:this.significand,t=Math.max(0,this.exponent+Y(n)),i=e+20+t,[r,s]=Ge(this,i),o=So(s),a=r/o,u=r-a*o;if(u<0n&&(a-=1n,u+=o),a>No||a<-No)return a>0n?y.POSITIVE_INFINITY:y.ZERO;let l=je(Vi(u,s),s,e),c=l.exponent+Number(a);return Number.isSafeInteger(c)?B(l.significand,c):a>0n?y.POSITIVE_INFINITY:y.ZERO};y.prototype.ln=function(){if(this.isNaN())return y.NAN;if(!this.isFinite())return this.significand>0n?y.POSITIVE_INFINITY:y.NAN;if(this.isZero())return y.NEGATIVE_INFINITY;if(this.significand<0n)return y.NAN;if(this.eq(1))return y.ZERO;let e=y.precision,n=this.significand,t=Y(n),i=this.exponent+t-1,r=B(n,-(t-1)),s=Math.abs(i).toString().length,o=e+20+s,[a,u]=Ge(r,o),l=So(u),c=qi(a,u)+BigInt(i)*l;return je(c,u,e)};y.prototype.log=function(e){let n=e instanceof y?e:new y(e);return this.ln().div(n.ln())};y.exp=function(e){return e.exp()};y.ln=function(e){return e.ln()};y.log10=function(e){return e.log(10)};y.prototype.sin=function(){if(this.isNaN())return y.NAN;if(!this.isFinite())return y.NAN;if(this.isZero())return y.ZERO;let e=y.precision,n=$e(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=e+15+(n<0?-n:0);if(n>nn.length-t-30)return y.NAN;let[i,r]=Ge(this,t),[s]=Mt(i,r);return je(s,r,e)};y.prototype.cos=function(){if(this.isNaN())return y.NAN;if(!this.isFinite())return y.NAN;if(this.isZero())return y.ONE;let e=y.precision,n=e+15;if($e(this)>nn.length-n-30)return y.NAN;let[i,r]=Ge(this,n),[,s]=Mt(i,r);return je(s,r,e)};y.prototype.tan=function(){if(this.isNaN())return y.NAN;if(!this.isFinite())return y.NAN;if(this.isZero())return y.ZERO;let e=y.precision,n=$e(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=e+15+(n<0?-n:0);if(n>nn.length-t-30)return y.NAN;let[i,r]=Ge(this,t),[s,o]=Mt(i,r);if(o===0n)return s>0n?y.POSITIVE_INFINITY:y.NEGATIVE_INFINITY;let a=s*r/o;return je(a,r,e)};y.prototype.atan=function(){if(this.isNaN())return y.NAN;if(this.isZero())return y.ZERO;if(!this.isFinite()){let o=y.PI.div(y.TWO);return this.significand>0n?o:o.neg()}let e=y.precision,n=$e(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=e+15+(n<0?-n:0),[i,r]=Ge(this,t),s=Hn(i,r);return je(s,r,e)};y.prototype.asin=function(){if(this.isNaN())return y.NAN;if(!this.isFinite())return y.NAN;if(this.isZero())return y.ZERO;let e=this.abs(),n=y.ONE;if(e.gt(n))return y.NAN;if(e.eq(n)){let d=y.PI.div(y.TWO);return this.significand>0n?d:d.neg()}let t=y.precision,i=$e(this);if(i<0&&-2*i>=t+4)return this.toPrecision(t);let r=t+20+(i<0?-i:0),[s,o]=Ge(this,r),a=bo(s,s,o),u=o-a,l=Zn(u,o),c=yo(s,l,o),f=Hn(c,o);return je(f,o,t)};y.prototype.acos=function(){return this.isNaN()?y.NAN:this.isFinite()?this.abs().gt(y.ONE)?y.NAN:this.eq(1)?y.ZERO:this.eq(-1)?y.PI:y.PI.div(y.TWO).sub(this.asin()):y.NAN};y.sin=function(e){return e.sin()};y.cos=function(e){return e.cos()};y.tan=function(e){return e.tan()};y.asin=function(e){return e.asin()};y.acos=function(e){return e.acos()};y.atan=function(e){return e.atan()};y.atan2=function(e,n){let t=e instanceof y?e:new y(e);if(t.isNaN()||n.isNaN())return y.NAN;let i=y.PI,r=i.div(y.TWO);if(n.isZero())return t.isZero()?y.ZERO:t.significand>0n?r:r.neg();let s=t.div(n);return n.significand>0n?s.atan():t.significand>=0n?s.atan().add(i):s.atan().sub(i)};y.prototype.sinh=function(){if(this.isNaN())return y.NAN;if(this.isZero())return y.ZERO;if(!this.isFinite())return this.significand>0n?y.POSITIVE_INFINITY:y.NEGATIVE_INFINITY;let e=y.precision,n=$e(this);if(n<0){if(-2*n>=e+4)return this.toPrecision(e);let r=y.precision;y.precision=e-n+5;try{let s=this.exp();return s.sub(s.inv()).div(y.TWO).toPrecision(e)}finally{y.precision=r}}if(Math.abs(this.toNumber())>1.16*(e+3)){let r=this.abs().exp().div(y.TWO);return this.significand>0n?r:r.neg()}let t=this.exp(),i=t.inv();return t.sub(i).div(y.TWO)};y.prototype.cosh=function(){if(this.isNaN())return y.NAN;if(this.isZero())return y.ONE;if(!this.isFinite())return y.POSITIVE_INFINITY;let e=y.precision;if(Math.abs(this.toNumber())>1.16*(e+3))return this.abs().exp().div(y.TWO);let n=this.exp(),t=n.inv();return n.add(t).div(y.TWO)};y.prototype.tanh=function(){if(this.isNaN())return y.NAN;if(this.isZero())return y.ZERO;if(!this.isFinite())return this.significand>0n?y.ONE:y.NEGATIVE_ONE;let e=y.precision,n=$e(this);if(n<0){if(-2*n>=e+4)return this.toPrecision(e);let i=y.precision;y.precision=e-n+5;try{let r=this.mul(y.TWO).exp();return r.sub(y.ONE).div(r.add(y.ONE)).toPrecision(e)}finally{y.precision=i}}if(Math.abs(this.toNumber())>1.16*(e+3))return this.significand>0n?y.ONE:y.NEGATIVE_ONE;let t=this.mul(y.TWO).exp();return t.sub(y.ONE).div(t.add(y.ONE))};y.sinh=function(e){return e.sinh()};y.cosh=function(e){return e.cosh()};y.tanh=function(e){return e.tanh()};function _o(e,n){let i=Y(e),r=Math.max(0,i-15),s=Number(r>0?e/L(r):e),o=Y(n),a=Math.max(0,o-15),u=Number(a>0?n/L(a):n),l=r+2*a,c=Math.floor(l/3),f=l%3,d=Math.cbrt(s*u*u);f===1&&(d*=2.154434690031882),f===2&&(d*=4.641588833612779);let m=BigInt(Math.round(d))*L(c);return m>0n?m:1n}var nd=[BigInt(4),BigInt(2),BigInt(4),BigInt(2),BigInt(4),BigInt(6),BigInt(2),BigInt(6)];var Xl=53,ko=Math.floor(Math.log10(Math.pow(2,Xl))),Ql=1e-10,Me=1e6;var zi=1e4;function mn(e,n){if(e===0)return n;if(n===0||e===n)return e;if(!Number.isInteger(e)||!Number.isInteger(n))return NaN;for(;n!==0;)[e,n]=[n,e%n];return e<0?-e:e}function Wn(e,n){if(e===0||n===0)return 0;let t=BigInt(e)*BigInt(n)/BigInt(mn(e,n));return t<0n&&(t=-t),Number(t)}function Xn(e){if(!Number.isInteger(e)||e<0)return NaN;if(e>=170)return 1/0;let n=1;for(let t=2;t<=e;t++)n=n*t;return n}function Qn(e){if(!Number.isInteger(e)||e<0)return NaN;if(e<0)return NaN;if(e<=1)return 1;let n=e;for(;e>2;)e-=2,n*=e;return n}function Kn(e,n=Ql){return typeof e=="number"&&Math.abs(e)<=n?0:e}function At(e,n,t=1){if(t===0){let s=At(e,n,-1),o=At(e,n,1);return s===void 0||o===void 0?NaN:Math.abs(s-o)>1e-5?NaN:(s+o)/2}let[i,r]=Oi(e,n,{step:t>0?1:-1});return i}var $t=["number","finite_number","complex","finite_complex","imaginary","real","finite_real","rational","finite_rational","integer","finite_integer","non_finite_number"],Gi=["indexed_collection","list","tuple"],Ct=[...Gi,"collection","set","record","dictionary"],Rt=["scalar",...$t,"boolean","string"],ji=["value","color",...Ct,...Rt],Ui=["expression","symbol","function",...ji],Hi=["any","unknown","nothing","never","error",...Ui],Dt=new Set($t),Mo=new Set(Ct),wo=new Set(Rt),dn=new Set(Hi);function Ao(e){return typeof e!="string"?!1:dn.has(e)}function Pt(e){return typeof e=="string"?dn.has(e):typeof e!="object"||!("kind"in e)?!1:e.kind==="signature"||e.kind==="union"||e.kind==="intersection"||e.kind==="negation"||e.kind==="value"||e.kind==="tuple"||e.kind==="list"||e.kind==="record"||e.kind==="dictionary"||e.kind==="set"||e.kind==="symbol"||e.kind==="expression"||e.kind==="numeric"||e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="reference"}var Ft=class{input;pos=0;line=1;column=1;tokens=[];constructor(n){this.input=n}saveState(){return{pos:this.pos,line:this.line,column:this.column,tokens:[...this.tokens]}}restoreState(n){this.pos=n.pos,this.line=n.line,this.column=n.column,this.tokens=n.tokens}error(n){throw new Error(`Lexer error at line ${this.line}, column ${this.column}: ${n}`)}peek(n=0){let t=this.pos+n;return t<this.input.length?this.input[t]:""}advance(){let n=this.input[this.pos++];return n===`
4
+ `?(this.line++,this.column=1):this.column++,n}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){for(let t=0;t<n.length;t++)this.advance();return!0}return!1}isEOF(){return this.pos>=this.input.length}skipWhitespace(){for(;!this.isEOF()&&/\s/.test(this.peek());)this.advance()}readIdentifier(){let n="";for(;!this.isEOF()&&/[a-zA-Z0-9_]/.test(this.peek());)n+=this.advance();return n}readVerbatimString(){if(!this.match("`"))return"";let n="";for(;!this.isEOF()&&this.peek()!=="`";)this.match("\\`")?n+="`":this.match("\\\\")?n+="\\":n+=this.advance();return this.isEOF()&&this.error("Unterminated verbatim string"),this.advance(),n}readStringLiteral(){let n=this.advance(),t="";for(;!this.isEOF()&&this.peek()!==n;)this.match("\\"+n)?t+=n:this.match("\\\\")?t+="\\":t+=this.advance();return this.isEOF()&&this.error("Unterminated string literal"),this.advance(),t}readNumber(){let n="";if((this.peek()==="-"||this.peek()==="+")&&(n+=this.advance()),this.match("0x")||this.match("0X")){for(n+="x";!this.isEOF()&&/[0-9a-fA-F]/.test(this.peek());)n+=this.advance();return"0"+n}if(this.match("0b")||this.match("0B")){for(n+="b";!this.isEOF()&&/[01]/.test(this.peek());)n+=this.advance();return"0"+n}for(;!this.isEOF()&&/[0-9]/.test(this.peek());)n+=this.advance();if(this.peek()==="."&&/[0-9]/.test(this.peek(1)))for(n+=this.advance();!this.isEOF()&&/[0-9]/.test(this.peek());)n+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(n+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(n+=this.advance());!this.isEOF()&&/[0-9]/.test(this.peek());)n+=this.advance();return n}createToken(n,t){return{type:n,value:t,position:this.pos-t.length,line:this.line,column:this.column-t.length}}nextToken(){if(this.skipWhitespace(),this.isEOF())return this.createToken("EOF","");let n=this.pos,t=this.peek();if(this.match("->"))return this.createToken("->","->");if(this.match(".."))return this.createToken("..","..");if(this.match("+\u221E")||this.match("+oo"))return this.createToken("PLUS_INFINITY",this.input.slice(n,this.pos));if(this.match("-\u221E")||this.match("-oo"))return this.createToken("MINUS_INFINITY",this.input.slice(n,this.pos));if(this.match("+infinity"))return this.createToken("PLUS_INFINITY","+infinity");if(this.match("-infinity"))return this.createToken("MINUS_INFINITY","-infinity");if(/[a-zA-Z_]/.test(t)){let i=this.readIdentifier();switch(i){case"true":return this.createToken("TRUE",i);case"false":return this.createToken("FALSE",i);case"nan":return this.createToken("NAN",i);case"infinity":return this.createToken("INFINITY",i);case"oo":return this.createToken("INFINITY",i);default:return this.createToken("IDENTIFIER",i)}}switch(t){case"|":return this.advance(),this.createToken("|","|");case"&":return this.advance(),this.createToken("&","&");case"!":return this.advance(),this.createToken("!","!");case"^":return this.advance(),this.createToken("^","^");case"(":return this.advance(),this.createToken("(","(");case")":return this.advance(),this.createToken(")",")");case"<":return this.advance(),this.createToken("<","<");case">":return this.advance(),this.createToken(">",">");case"[":return this.advance(),this.createToken("[","[");case"]":return this.advance(),this.createToken("]","]");case",":return this.advance(),this.createToken(",",",");case":":return this.advance(),this.createToken(":",":");case"?":return this.advance(),this.createToken("?","?");case"*":return this.advance(),this.createToken("*","*");case"+":return/[0-9]/.test(this.peek(1))?this.createToken("NUMBER_LITERAL",this.readNumber()):(this.advance(),this.createToken("+","+"));case"x":return/[0-9]/.test(this.peek(1))?(this.advance(),this.createToken("x","x")):(this.advance(),this.createToken("x","x"))}if(t==='"'||t==="'")return this.createToken("STRING_LITERAL",this.readStringLiteral());if(t==="`")return this.createToken("VERBATIM_STRING",this.readVerbatimString());if(/[0-9]/.test(t)||t==="-"&&/[0-9]/.test(this.peek(1))){let i=this.readNumber();return this.peek()==="x"&&/[0-9]/.test(this.peek(1)),this.createToken("NUMBER_LITERAL",i)}if(t==="\u221E")return this.advance(),this.createToken("INFINITY","\u221E");this.error(`Unexpected character: ${t}`)}tokenize(){let n=[];for(;!this.isEOF();){let t=this.nextToken();if(t&&(n.push(t),t.type==="EOF"))break}return n}peekToken(){if(this.tokens.length===0){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens[0]||this.createToken("EOF","")}consumeToken(){if(this.tokens.length===0){let n=this.nextToken();if(n)return n}return this.tokens.shift()||this.createToken("EOF","")}matchToken(n){return this.peekToken().type===n?(this.consumeToken(),!0):!1}expectToken(n){let t=this.consumeToken();return t.type!==n&&this.error(`Expected ${n}, got ${t.type}`),t}};var Ot=class{lexer;typeResolver;current;constructor(n,t){this.lexer=new Ft(n),this.typeResolver=t?.typeResolver??{forward:()=>{},resolve:()=>{},get names(){return[]}},this.current=this.lexer.consumeToken()}error(n,t){this.errorAtToken(this.current,n,t)}errorAtToken(n,t,i){let r=this.lexer.input,o=r.split(`
5
5
  `)[n.line-1]||r,a=n.column,u=" ".repeat(Math.max(0,a-1))+"^",l=["","Invalid type",`| ${o}`,`| ${u}`,"|",`| ${t}`];throw i&&l.push(`| ${i}`),l.push(""),new Error(l.join(`
6
- `))}advance(){let n=this.current;return this.current=this.lexer.consumeToken(),n}match(n){return this.current.type===n?(this.advance(),!0):!1}expect(n){return this.current.type!==n&&this.error(`Expected ${n}, got ${this.current.type}`),this.advance()}createNode(n,t={}){return{kind:n,position:this.current.position,line:this.current.line,column:this.current.column,...t}}parseType(){this.checkForNakedFunctionSignature();let n=this.parseUnionType();if(n||this.error("Expected a type"),this.current.type!=="EOF")if(this.current.type==="->"||this.current.type==="+"||this.current.type==="*"||this.current.type==="?")this.error("Function signatures must be enclosed in parentheses","For example `(x: number) -> number`");else if(this.current.type==="("){let t=this.lexer.input;t.includes("set(")||t.includes("collection(")||t.includes("list(")||t.includes("tuple(")?t.includes("set(")?this.error("Use `set<integer>` instead of `set(integer)`."):t.includes("collection(")?this.error("Use `collection<type>` instead of `collection(type)`.","For example `collection<number>`"):t.includes("list(")?this.error("Use `list<type>` instead of `list(type)`.","For example `list<number>`"):t.includes("tuple(")&&this.error("Use `tuple<type1, type2>` instead of `tuple(type1, type2)`.","For example `tuple<string, number>`"):this.error("Unexpected token after type")}else this.error("Unexpected token after type");return n}checkForNakedFunctionSignature(){if(this.current.type==="IDENTIFIER"){let n=this.lexer.saveState(),t=this.current;try{let i=this.current;if(this.advance(),this.current.type===":"){this.advance();let r=!1,s=0,o=10;for(;this.current.type!=="EOF"&&s<o;){if(this.current.type==="->"){r=!0;break}if(this.current.type==="+"||this.current.type==="*"||this.current.type==="?"){if(this.advance(),this.current.type==="->"){r=!0;break}s++}this.advance(),s++}r&&(this.lexer.restoreState(n),this.current=t,this.errorAtToken(i,"Function signatures must be enclosed in parentheses","For example `(z: string*) -> boolean`"))}this.lexer.restoreState(n),this.current=t}catch(i){if(this.lexer.restoreState(n),this.current=t,i instanceof Error&&i.message.includes("Function signatures must be enclosed"))throw i}}}parseUnionType(){let n=this.parseIntersectionType();if(!n)return;let t=[n];for(;this.match("|");){let i=this.parseIntersectionType();i||this.error("Expected type after |"),t.push(i)}return t.length===1?t[0]:this.createNode("union",{types:t})}parseIntersectionType(){let n=this.parsePrimaryType();if(!n)return;let t=[n];for(;this.match("&");){let i=this.parsePrimaryType();i||this.error("Expected type after &"),t.push(i)}return t.length===1?t[0]:this.createNode("intersection",{types:t})}parsePrimaryType(){if(this.match("!")){let n=this.parsePrimaryType();return n||this.error("Expected type after !"),this.createNode("negation",{type:n})}if(this.current.type==="("){let n=this.parseFunctionSignature();if(n)return n;if(this.match("(")){let t=this.parseUnionType();if(t||this.error("Expected type after ("),this.current.type===","){let i=[this.createNode("named_element",{name:void 0,type:t})];for(;this.match(",");){let r=this.parseUnionType();r||this.error("Expected type after ,"),i.push(this.createNode("named_element",{name:void 0,type:r}))}return this.expect(")"),this.createNode("tuple",{elements:i})}return this.expect(")"),this.createNode("group",{type:t})}}return this.parseListType()||this.parseTupleType()||this.parseRecordType()||this.parseDictionaryType()||this.parseSetType()||this.parseCollectionType()||this.parseExpressionType()||this.parseSymbolType()||this.parseNumericType()||this.parsePrimitiveType()||this.parseValue()||this.parseTypeReference()}isFunctionSignature(){let n=this.lexer.saveState(),t=this.current;this.advance();let i=1;for(;i>0&&this.current.type!=="EOF";)this.current.type==="("?i++:this.current.type===")"&&i--,this.advance();let r=this.current.type==="->";return this.lexer.restoreState(n),this.current=t,r}parseFunctionSignature(){if(this.current.type!=="("||!this.isFunctionSignature())return;let n=[];if(this.advance(),!this.match(")")){do{let o=this.parseArgument();o||this.error("Expected argument"),n.push(o)}while(this.match(","));this.expect(")")}this.expect("->");let t=this.parseUnionType();t||this.error("Expected return type after ->");let i=n.some(o=>o.modifier==="optional"),r=n.some(o=>o.modifier==="variadic_zero"||o.modifier==="variadic_one"),s=n.filter(o=>o.modifier==="variadic_zero"||o.modifier==="variadic_one").length;return i&&r&&this.error("Variadic arguments cannot be used with optional arguments"),s>1&&this.error("There can be only one variadic argument"),this.createNode("function_signature",{arguments:n,returnType:t})}parseArgument(){let n=this.parseNamedElement();if(!n)return;let t;return this.match("?")?t="optional":this.match("*")?t="variadic_zero":this.match("+")&&(t="variadic_one"),this.createNode("argument",{element:n,modifier:t})}parseNamedElement(){let n;if(this.current.type==="IDENTIFIER"||this.current.type==="VERBATIM_STRING"){let i=this.current;if(this.lexer.peekToken().type===":"){n=i.value,this.advance(),this.advance();let s=this.parseUnionType();return s?this.createNode("named_element",{name:n,type:s}):void 0}}let t=this.parseUnionType();if(t)return this.createNode("named_element",{name:void 0,type:t})}parseListType(){if(this.current.type==="IDENTIFIER"){let n=this.current,i=this.lexer.peekToken().type==="<";switch(n.value){case"list":return i?(this.advance(),this.parseListTypeImpl()):void 0;case"vector":return i?(this.advance(),this.parseVectorType()):(this.advance(),this.createNode("list",{elementType:this.createNode("primitive",{name:"number"}),dimensions:void 0}));case"matrix":return i?(this.advance(),this.parseMatrixType()):(this.advance(),this.createNode("matrix",{elementType:this.createNode("primitive",{name:"number"}),dimensions:[this.createNode("dimension",{size:-1}),this.createNode("dimension",{size:-1})]}));case"tensor":return i?(this.advance(),this.parseTensorType()):(this.advance(),this.createNode("list",{elementType:this.createNode("primitive",{name:"number"}),dimensions:void 0}));default:return}}}parseListTypeImpl(){let n=this.createNode("primitive",{name:"any"}),t;if(this.match("<")){if(t=this.parseDimensionWithX(),t||(t=this.parseDimensions()),!t){let i=this.parseUnionType();i&&(n=i,this.match("^")&&(t=this.parseDimensionWithX(),t||(t=this.parseDimensions())))}this.expect(">")}return this.createNode("list",{elementType:n,dimensions:t})}parseVectorType(){let n=this.createNode("primitive",{name:"number"}),t;if(this.match("<")){if(this.current.type==="NUMBER_LITERAL")t=parseInt(this.advance().value);else{let i=this.parseUnionType();i&&(n=i,this.match("^")&&(this.current.type==="NUMBER_LITERAL"?t=parseInt(this.advance().value):this.error("Expected number after ^")))}this.expect(">")}return this.createNode("vector",{elementType:n,size:t})}parseMatrixType(){let n=this.createNode("primitive",{name:"number"}),t;if(this.match("<")){if(t=this.parseDimensionWithX(),t||(t=this.parseDimensions()),!t){let i=this.parseUnionType();i&&(n=i,this.match("^")&&(t=this.parseDimensionWithX(),t||(t=this.parseDimensions())))}this.expect(">")}else t=[this.createNode("dimension",{size:null}),this.createNode("dimension",{size:null})];return this.createNode("matrix",{elementType:n,dimensions:t})}parseTensorType(){let n=this.createNode("primitive",{name:"number"});if(this.match("<")){let t=this.parseUnionType();t&&(n=t),this.expect(">")}return this.createNode("tensor",{elementType:n})}parseDimensions(){let n=[],t=this.parseDimension();if(t){for(n.push(t);this.match("x");){let i=this.parseDimension();i||this.error("Expected dimension after x"),n.push(i)}return n}}parseDimension(){if(this.match("?"))return this.createNode("dimension",{size:null});if(this.current.type==="NUMBER_LITERAL"){let n=parseInt(this.advance().value);return this.createNode("dimension",{size:n})}}parseDimensionWithX(){if(this.current.type==="NUMBER_LITERAL"){let n=[],t=parseInt(this.advance().value);if(n.push(this.createNode("dimension",{size:t})),this.current.type==="IDENTIFIER"&&this.current.value.startsWith("x")){let i=this.current.value,r=i.match(/x(\d+)/g);if(r&&r.join("")===i){this.advance();for(let s of r){let o=parseInt(s.substring(1));n.push(this.createNode("dimension",{size:o}))}}else(i==="x"||i.startsWith("x"))&&this.error("Expected a positive integer literal or `?` after x. For example: `2x3` or `2x?`")}if(n.length>1)return n}}parseTupleType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="tuple"){if(this.lexer.peekToken().type!=="<")return;this.advance(),this.expect("<");let t=[];if(this.current.type!==">"){let i=this.parseNamedElement();i||this.error("Expected tuple element"),t.push(i);let r=i.name!==void 0;for(;this.match(",");){let s=this.parseNamedElement();s||this.error("Expected tuple element"),r&&!s.name&&this.error("All tuple elements should be named, or none. Previous elements were named, but this one isn't."),!r&&s.name&&this.error("All tuple elements should be named, or none. Previous elements were not named, but this one is."),t.push(s)}}return this.expect(">"),this.createNode("tuple",{elements:t})}}parseRecordType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="record"){this.advance();let n=[];if(this.match("<")){if(this.current.type!==">")do{let t=this.parseRecordEntry();t||this.error("Expected record entry"),n.push(t)}while(this.match(","));this.expect(">")}return this.createNode("record",{entries:n})}}parseRecordEntry(){let n;if(this.current.type==="IDENTIFIER")n=this.advance().value;else if(this.current.type==="VERBATIM_STRING")n=this.advance().value;else return;this.expect(":");let t=this.parseUnionType();return t||this.error("Expected value type"),this.createNode("record_entry",{key:n,valueType:t})}parseDictionaryType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="dictionary"){this.advance();let n=this.createNode("primitive",{name:"any"});if(this.match("<")){let t=this.parseUnionType();t&&(n=t),this.expect(">")}return this.createNode("dictionary",{valueType:n})}}parseSetType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="set"){this.advance();let n=this.createNode("primitive",{name:"any"});if(this.match("<")){let t=this.parseUnionType();t&&(n=t),this.expect(">")}return this.createNode("set",{elementType:n})}}parseCollectionType(){if(this.current.type==="IDENTIFIER"){let n=this.current.value==="indexed_collection",t=this.current.value==="collection";if(n||t){this.advance();let i=this.createNode("primitive",{name:"any"});if(this.match("<")){let r=this.parseUnionType();r&&(i=r),this.expect(">")}return this.createNode("collection",{elementType:i,indexed:n})}}}parseExpressionType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="expression"){if(this.lexer.peekToken().type!=="<")return;this.advance(),this.expect("<");let i=this.expect("IDENTIFIER").value;return this.expect(">"),this.createNode("expression",{operator:i})}}parseSymbolType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="symbol"){if(this.lexer.peekToken().type!=="<")return;this.advance(),this.expect("<");let i=this.expect("IDENTIFIER").value;return this.expect(">"),this.createNode("symbol",{name:i})}}parseNumericType(){if(this.current.type==="IDENTIFIER"&&["real","finite_real","rational","finite_rational","integer","finite_integer"].includes(this.current.value)){let t=this.advance().value;if(this.match("<")){let i=this.parseValue();this.expect("..");let r=this.parseValue();return this.expect(">"),this.createNode("numeric",{baseType:t,lowerBound:i,upperBound:r})}return this.createNode("numeric",{baseType:t})}}parsePrimitiveType(){if(this.current.type==="IDENTIFIER"){let n=this.current.value;if(Qe.includes(n))return this.advance(),this.createNode("primitive",{name:n})}}parseValue(){let n,t;switch(this.current.type){case"STRING_LITERAL":n=this.advance().value,t="string";break;case"NUMBER_LITERAL":n=parseFloat(this.advance().value),t="number";break;case"TRUE":this.advance(),n=!0,t="boolean";break;case"FALSE":this.advance(),n=!1,t="boolean";break;case"NAN":this.advance(),n=NaN,t="nan";break;case"INFINITY":case"PLUS_INFINITY":this.advance(),n=1/0,t="infinity";break;case"MINUS_INFINITY":this.advance(),n=-1/0,t="infinity";break;default:return}return this.createNode("value",{value:n,valueType:t})}parseTypeReference(){let n=this.current.type==="IDENTIFIER"&&this.current.value==="type";if(n&&this.advance(),this.current.type==="IDENTIFIER"){let t=this.current,i=this.advance().value;return this.typeResolver.resolve(i)?this.createNode("type_reference",{name:i,isForward:n}):n&&this.typeResolver.forward(i)?this.createNode("type_reference",{name:i,isForward:!0}):(n||this.errorAtToken(t,`Unknown type "${i}"`,"Syntax error. The type was not recognized."),this.createNode("type_reference",{name:i,isForward:n}))}}};function io(e,n){switch(e.kind){case"function_signature":return n.visitFunctionSignature(e);case"union":return n.visitUnionType(e);case"intersection":return n.visitIntersectionType(e);case"negation":return n.visitNegationType(e);case"group":return n.visitGroupType(e);case"list":return n.visitListType(e);case"vector":return n.visitVectorType(e);case"matrix":return n.visitMatrixType(e);case"tensor":return n.visitTensorType(e);case"tuple":return n.visitTupleType(e);case"record":return n.visitRecordType(e);case"dictionary":return n.visitDictionaryType(e);case"set":return n.visitSetType(e);case"collection":return n.visitCollectionType(e);case"expression":return n.visitExpressionType(e);case"symbol":return n.visitSymbolType(e);case"numeric":return n.visitNumericType(e);case"primitive":return n.visitPrimitiveType(e);case"type_reference":return n.visitTypeReference(e);case"value":return n.visitValue(e);default:throw new Error(`Unknown node kind: ${e.kind}`)}}var Di=class{typeResolver;constructor(n){this.typeResolver=n??{forward:()=>{},resolve:()=>{},get names(){return[]}}}buildType(n){return io(n,this)}visitFunctionSignature(n){let t=[],i=[],r,s;for(let u of n.arguments){let l=this.buildNamedElement(u.element);switch(u.modifier){case"optional":i.push(l);break;case"variadic_zero":r=l,s=0;break;case"variadic_one":r=l,s=1;break;default:t.push(l);break}}let o=this.buildType(n.returnType),a={kind:"signature",args:t.length>0?t:void 0,result:o};return i.length>0&&(a.optArgs=i),r&&(a.variadicArg=r,a.variadicMin=s),a}visitUnionType(n){return{kind:"union",types:n.types.map(i=>this.buildType(i))}}visitIntersectionType(n){return{kind:"intersection",types:n.types.map(i=>this.buildType(i))}}visitNegationType(n){return{kind:"negation",type:this.buildType(n.type)}}visitGroupType(n){return this.buildType(n.type)}visitListType(n){let t=this.buildType(n.elementType),i=n.dimensions?.map(r=>this.buildDimension(r));return{kind:"list",elements:t,dimensions:i}}visitVectorType(n){let t=this.buildType(n.elementType);return n.size!==void 0?{kind:"list",elements:t,dimensions:[n.size]}:{kind:"list",elements:t}}visitMatrixType(n){let t=this.buildType(n.elementType);if(n.dimensions){let i=n.dimensions.map(r=>this.buildDimension(r));return{kind:"list",elements:t,dimensions:i}}return{kind:"list",elements:t,dimensions:[-1,-1]}}visitTensorType(n){return{kind:"list",elements:this.buildType(n.elementType)}}visitTupleType(n){return{kind:"tuple",elements:n.elements.map(i=>this.buildNamedElement(i))}}visitRecordType(n){if(n.entries.length===0)return"record";let t={};for(let i of n.entries)t[i.key]=this.buildType(i.valueType);return{kind:"record",elements:t}}visitDictionaryType(n){let t=this.buildType(n.valueType);return this.isAnyType(t)?"dictionary":{kind:"dictionary",values:t}}visitSetType(n){let t=this.buildType(n.elementType);return this.isAnyType(t)?"set":{kind:"set",elements:t}}visitCollectionType(n){let t=this.buildType(n.elementType);return n.indexed?this.isAnyType(t)?"indexed_collection":{kind:"indexed_collection",elements:t}:this.isAnyType(t)?"collection":{kind:"collection",elements:t}}visitExpressionType(n){return{kind:"expression",operator:n.operator}}visitSymbolType(n){return{kind:"symbol",name:n.name}}visitNumericType(n){if(!n.lowerBound&&!n.upperBound)return n.baseType;let t=n.lowerBound?this.buildValue(n.lowerBound):-1/0,i=n.upperBound?this.buildValue(n.upperBound):1/0;return t===-1/0&&i===1/0?n.baseType:{kind:"numeric",type:n.baseType,lower:t,upper:i}}visitPrimitiveType(n){return n.name}visitTypeReference(n){let t=this.typeResolver.resolve(n.name);if(t)return t;if(n.isForward){let i=this.typeResolver.forward(n.name);if(i)return i}return n.name}visitValue(n){return{kind:"value",value:n.value}}buildNamedElement(n){let t=this.buildType(n.type);return n.name?{name:n.name,type:t}:{type:t}}buildDimension(n){return n.size??-1}buildValue(n){return n.value}isAnyType(n){return n==="any"||typeof n=="object"&&"kind"in n&&n.kind==="primitive"&&"name"in n&&n.name==="any"}};function ro(e,n){return new Di(n).buildType(e)}function W(e,n){if(e!==void 0){if(kt(e))return e;if(typeof e=="string")try{let i=new wt(e,{typeResolver:n}).parseType();return ro(i,n)}catch(t){throw new Error(`Failed to parse type "${e}": ${t instanceof Error?t.message:String(t)}`)}}}var Nl={number:En,non_finite_number:[],finite_number:["finite_complex","finite_real","finite_integer","finite_rational"],complex:["finite_complex","imaginary","finite_real","finite_rational","finite_integer","non_finite_number"],finite_complex:["imaginary","finite_real","finite_rational","finite_integer"],imaginary:[],real:["rational","integer","finite_real","finite_rational","finite_integer","non_finite_number"],finite_real:["finite_rational","finite_integer"],rational:["finite_rational","finite_integer","integer","non_finite_number"],finite_rational:["finite_integer"],integer:["finite_integer","non_finite_number"],finite_integer:[],any:Qe,unknown:[],nothing:[],never:[],error:[],value:Ci,scalar:_t,collection:It,indexed_collection:$i,list:[],set:[],tuple:[],record:[],dictionary:[],function:[],symbol:[],boolean:[],string:[],color:[],expression:Ri};function Yn(e,n){return n==="any"||e==="never"?!0:e==="unknown"||n==="unknown"?!1:e===n?!0:Nl[n].includes(e)}function A(e,n){if(typeof e=="string"&&!Qe.includes(e)&&(e=W(e)),typeof n=="string"&&!Qe.includes(n)&&(n=W(n)),n==="any")return!0;if(n==="never")return!1;if(n==="error")return e==="error";if(n==="nothing")return e==="nothing";if(e==="nothing")return!1;if(n==="unknown")return!0;if(e==="unknown")return!1;if(typeof n=="string")return typeof e=="string"?Yn(e,n):e.kind==="value"?typeof e.value=="boolean"?n==="boolean":typeof e.value=="number"?Number.isInteger(e.value)?Yn("integer",n):Yn("number",n):typeof e.value=="boolean"?Yn("boolean",n):typeof e.value=="string"?Yn("string",n):!1:e.kind==="union"?e.types.every(t=>A(t,n)):e.kind==="intersection"?e.types.some(t=>A(t,n)):e.kind==="negation"?!A(e.type,n):e.kind==="numeric"?!!A(e.type,n):n==="number"?so(e):n==="symbol"?Pi(e):n==="expression"?Tl(e):n==="function"?co(e):n==="scalar"?oo(e):n==="value"?lo(e):n==="indexed_collection"?uo(e):n==="collection"?ao(e):n==="tuple"?e.kind==="tuple":n==="list"?e.kind==="list":n==="set"?e.kind==="set":n==="record"?e.kind==="record":n==="dictionary"?e.kind==="dictionary":!1;if(n.kind==="union")return typeof e!="string"&&e.kind==="union"?e.types.every(t=>n.types.some(i=>A(t,i))):n.types.some(t=>A(e,t));if(n.kind==="expression"){if(e==="symbol")return!0;if(typeof e=="string")return!1;if(e.kind==="expression")return n.operator==="Symbol"?Pi(e):e.operator===n.operator;if(e.kind==="symbol")return!0}if(typeof e=="string")return!1;if(n.kind==="reference"){if(e.kind==="reference")return e.name===n.name;if(n.alias===!0&&n.def)return A(e,n.def)}if(e.kind==="union")return e.types.some(t=>A(t,n));if(e.kind==="intersection"&&n.kind==="intersection")return n.types.every(t=>e.types.some(i=>A(i,t)));if(e.kind==="intersection")return e.types.every(t=>A(t,n));if(n.kind==="intersection")return n.types.every(t=>A(e,t));if(e.kind==="signature"&&n.kind==="signature"){if(!A(e.result,n.result))return!1;if(e.optArgs||e.variadicArg){if(n.args){if(!e.args||e.args.length!==n.args.length)return!1;for(let t=0;t<n.args.length;t++)if(!A(n.args[t].type,e.args[t].type))return!1}else if(e.args)return!1;if(n.optArgs){if(!e.optArgs||e.optArgs.length!==n.optArgs.length)return!1;for(let t=0;t<e.optArgs.length;t++)if(!A(n.optArgs[t].type,e.optArgs[t].type))return!1}else if(e.optArgs)return!1;if(n.variadicArg){if(!e.variadicArg||e.variadicMin!=n.variadicMin||!A(n.variadicArg.type,e.variadicArg.type))return!1}else if(e.variadicArg)return!1}else{if(n.args&&!e.args)return!1;let t=0;if(n.args){if(e.args.length<n.args.length)return!1;for(;t<n.args.length;){if(!A(n.args[t].type,e.args[t].type))return!1;t+=1}}if(n.optArgs){if(t>=e.args.length)return!0;for(let i=0;i<n.optArgs.length;i++){if(!A(n.optArgs[i].type,e.args[t].type))return!1;if(t+=1,t>=e.args.length)return!0}}if(n.variadicArg){if(t>=e.args.length&&n.variadicMin===0)return!0;if(n.variadicMin>0&&t+n.variadicMin>e.args.length)return!1;for(;t<e.args.length;){if(!A(n.variadicArg.type,e.args[t].type))return!1;t+=1}}}return!0}if(e.kind==="record"&&n.kind==="record"){for(let t of Object.keys(n.elements))if(!(t in e.elements)||!A(e.elements[t],n.elements[t]))return!1;return!0}if(e.kind==="dictionary"&&n.kind==="dictionary")return A(e.values,n.values);if(n.kind==="indexed_collection")return e.kind==="indexed_collection"||e.kind==="list"?A(e.elements,n.elements):e.kind==="tuple"?e.elements.every(t=>A(t.type,n.elements)):!1;if(n.kind==="collection"){if(e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="list")return A(e.elements,n.elements);if(e.kind==="tuple")return e.elements.every(t=>A(t.type,n.elements));if(e.kind==="set")return A(e.elements,n.elements);if(e.kind==="dictionary")return A({kind:"tuple",elements:[{type:"string"},{type:e.values}]},n.elements);if(e.kind==="record")return A({kind:"tuple",elements:[{type:"string"},{type:xe(...Object.values(e.elements))}]},n.elements)}if(e.kind==="tuple"&&n.kind==="tuple"){if(e.elements.length!==n.elements.length)return!1;for(let t=0;t<e.elements.length;t++){let i=e.elements[t],r=n.elements[t];if(!A(i.type,r.type)||i.name!==r.name)return!1}return!0}if(n.kind==="list"&&e.kind==="list"){if(!A(e.elements,n.elements))return!1;if(n.dimensions){if(!e.dimensions||e.dimensions.length!==n.dimensions.length)return!1;for(let t=0;t<e.dimensions.length;t++)if(n.dimensions[t]!==-1&&e.dimensions[t]!==n.dimensions[t])return!1}return!0}if(e.kind==="symbol"&&n.kind==="symbol")return e.name===n.name;if(e.kind==="numeric"&&n.kind==="numeric")return!(!A(e.type,n.type)||(e.lower??-1/0)<(n.lower??-1/0)||(e.upper??1/0)>(n.upper??1/0));if(n.kind==="set"&&e.kind==="set")return!!A(e.elements,n.elements);if(e.kind==="negation"&&n.kind==="negation")return A(e.type,n.type);if(n.kind==="negation")return!A(e,n.type);if(n.kind==="value"&&e.kind==="value")return n.value===e.value;if(e.kind==="value"){if(typeof e.value=="boolean")return A("boolean",n);if(typeof e.value=="number")return Number.isInteger(e.value)?A("integer",n):A("real",n);if(typeof e.value=="string")return A("string",n)}return!1}function so(e){return typeof e=="string"?En.includes(e):e.kind==="value"?typeof e.value=="number":e.kind==="numeric"}function oo(e){return so(e)?!0:typeof e=="string"?_t.includes(e):e.kind==="value"?["string","boolean","number"].includes(typeof e.value):!1}function ao(e){return uo(e)?!0:typeof e=="string"?It.includes(e):["collection","set","record","dictionary"].includes(e.kind)}function uo(e){return typeof e=="string"?!1:["indexed_collection","list","tuple"].includes(e.kind)}function lo(e){return oo(e)||ao(e)}function co(e){return e==="function"||typeof e!="string"&&e.kind==="signature"}function Tl(e){return typeof e=="string"&&["expression","symbol","function"].includes(e)||lo(e)||co(e)||Pi(e)?!0:typeof e=="string"?!1:e.kind==="expression"}function Pi(e){return e==="symbol"?!0:typeof e=="string"?!1:e.kind==="symbol"?!0:e.kind==="expression"?e.operator==="Symbol":!1}function Il(e,n){return e===n?e:e==="nothing"||n==="nothing"?"nothing":e==="any"?n:n==="any"?e:e==="never"?n:n==="never"?e:e==="unknown"?n:n==="unknown"||A(e,n)?e:A(n,e)?n:fo(e,n)}function _l(e,n){if(e===n)return e;if(e==="any"||n==="any")return"any";if(e==="never")return n;if(n==="never")return e;if(e==="unknown")return n;if(n==="unknown")return e;if(e==="nothing")return n;if(n==="nothing")return e;if(A(e,n))return n;if(A(n,e))return e;let t=fo(e,n);return kl.has(t)?Sl(e,n):t}var kl=new Set(["scalar","value","function","expression","collection","indexed_collection","list","set","tuple","record","dictionary","map","any"]);function Sl(e,n){let t=[],i=r=>{if(typeof r=="object"&&r.kind==="union"){for(let o of r.types)i(o);return}let s=typeof r=="string"?r:JSON.stringify(r);t.some(o=>(typeof o=="string"?o:JSON.stringify(o))===s)||t.push(r)};return i(e),i(n),t.length===1?t[0]:{kind:"union",types:t}}function Fi(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce((n,t)=>Il(n,t))}function xe(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce((n,t)=>_l(n,t))}function fo(e,n){return e===n?e:e==="any"||n==="any"?"any":e==="never"?n:n==="never"?e:e==="unknown"?n:n==="unknown"?e:e==="nothing"?n:n==="nothing"?e:Q(e,n,"non_finite_number")?"non_finite_number":Q(e,n,"finite_integer")?"finite_integer":Q(e,n,"integer")?"integer":Q(e,n,"finite_rational")?"finite_rational":Q(e,n,"rational")?"rational":Q(e,n,"finite_real")?"finite_real":Q(e,n,"real")?"real":Q(e,n,"imaginary")?"imaginary":Q(e,n,"finite_complex")?"finite_complex":Q(e,n,"complex")?"complex":Q(e,n,"finite_number")?"finite_number":Q(e,n,"number")?"number":Q(e,n,"list")?"list":Q(e,n,"record")?"record":Q(e,n,"dictionary")?"dictionary":Q(e,n,"set")?"set":Q(e,n,"tuple")?"tuple":Q(e,n,"indexed_collection")?"indexed_collection":Q(e,n,"collection")?"collection":Q(e,n,"scalar")?"scalar":Q(e,n,"value")?"value":Q(e,n,"function")?"function":Q(e,n,"expression")?"expression":"any"}function Q(e,n,t){return!!(A(e,t)&&A(n,t))}function Li(e){if(e){if(e==="function")return"any";if(typeof e!="string"&&e.kind==="signature")return e.result}}function we(e){if(e==="collection"||e==="indexed_collection"||e==="list"||e==="set"||e==="tuple"||e==="dictionary"||e==="record")return"any";if(typeof e!="string"){if(e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="list"||e.kind==="set")return e.elements;if(e.kind==="tuple")return xe(...e.elements.map(n=>n.type));if(e.kind==="dictionary")return W(`tuple<string, ${J(e.values)}>`);if(e.kind==="record")return W(`tuple<string, ${J(xe(...Object.values(e.elements)))}>`)}}var he=class e{static unknown=new e("unknown");static number=new e("number");static non_finite_number=new e("non_finite_number");static finite_number=new e("finite_number");static finite_integer=new e("finite_integer");static finite_real=new e("finite_real");static string=new e("string");static dictionary=new e("dictionary");static setNumber=new e("set<number>");static setComplex=new e("set<complex>");static setImaginary=new e("set<imaginary>");static setReal=new e("set<real>");static setRational=new e("set<rational>");static setFiniteInteger=new e("set<finite_integer>");static setInteger=new e("set<integer>");type;static widen(...n){return new e(xe(...n.map(t=>t instanceof e?t.type:t)))}static narrow(...n){return new e(Fi(...n.map(t=>t instanceof e?t.type:t)))}constructor(n,t){typeof n=="string"?this.type=W(n,t):this.type=n}matches(n){return n instanceof e?A(this.type,n.type):A(this.type,n)}is(n){return A(this.type,n)&&A(n,this.type)}get isUnknown(){return this.type==="unknown"}toString(){return J(this.type)}toJSON(){return J(this.type)}[Symbol.toPrimitive](n){return n==="string"?this.toString():null}valueOf(){return J(this.type)}};function D(e){return e?._kind==="number"}function k(e,n){return e?._kind==="symbol"&&(n===void 0||e.symbol===n)}function h(e,n){return(e?._kind==="function"||e?._kind==="tensor")&&(n===void 0||e.operator===n)}function fe(e){return e?._kind==="string"}function pe(e){return e?._kind==="symbol"?e.symbol:void 0}var cd=[0,-1,1,Math.PI,Math.E,-Math.PI,-Math.E,.5,-.5];function qe(e){if(!e)return;if(e.operator==="Function"&&e.isCanonical||k(e))return e;if(h(e,"BuiltinFunction"))return e.op1;if(h(e,"Delimiter")){let s=e.op1;if(h(s,"Sequence"))if(s.nops===1)e=s;else return qe(e.engine._fn("Block",s.ops,{canonical:!1}));return qe(h(e)?e.op1:void 0)}if(h(e,"Function"))return po(e.engine,e.ops);e.operator;let n=e.engine,t=e.subs({_:"_1"}),i=1,r=[];for(;i<10;)t.has(`_${i}`)&&r.push(t.engine.symbol(`_${i}`,{canonical:!1})),i++;if(r.length===0){t.operator!=="Block"?t=n.function("Block",[t]):t=t.canonical;let s=t.unknowns;s.length>0&&(r=s.map(o=>n.symbol(o,{canonical:!1})))}return po(n,[t,...r])}function po(e,n){if(n.length===0)return;let t=n[0].operator==="Block"?n[0].canonical:e.function("Block",[n[0]]),i=n.slice(1).map(r=>k(r)?r:e.error("expected-a-symbol",r.toString()));t.isScoped;for(let r of i)k(r)&&!t.localScope.bindings.has(r.symbol)&&e.declare(r.symbol,{inferred:!0,type:"unknown"},t.localScope);return e._fn("Function",[t,...i])}function mo(e,n){let t=e.Nothing;for(let i of n){let r=i.operator;if(r==="Return"&&h(i)){t=i.op1.evaluate();break}if((r==="Break"||r==="Continue")&&h(i)){t=e.expr([r,i.op1.evaluate()]);break}t=i.evaluate()}return t}function ho(e,n){let t=[];for(let i of n){if(!i)continue;let r=e.bindings.get(i);r&&(t.push([i,r]),e.bindings.delete(i))}return t}function go(e,n){for(let[t,i]of n)e.bindings.set(t,i)}function bo(e,n,t){if(n.operator==="Function"&&h(n)){let i=n.op1;if(i&&h(i)&&i.localScope){let r=new Set(n.ops.slice(1).map(u=>k(u)?u.symbol:"").filter(u=>u)),s=new Map;for(let[u,l]of i.localScope.bindings)r.has(u)&&s.set(u,l);let o={parent:t,bindings:s},a=e._fn("Block",i.ops,{scope:o});return e._fn("Function",[a,...n.ops.slice(1)])}return n}if(h(n)&&n.ops.length>0){let i=!1,r=n.ops.map(s=>{let o=bo(e,s,t);return o!==s&&(i=!0),o});if(i)return e._fn(n.operator,r)}return n}function wl(e){let n=e.engine;if(k(e)){let a=e.symbol;return u=>n.function(a,u).evaluate()}let t=qe(e);if(!t)throw new Error("Invalid function literal");e=t,e.operator,e.isCanonical;let i=e;if(i.ops.length===1)return i.ops[0],()=>i.ops[0].evaluate();let[r,...s]=i.ops;if(r.isScoped,!r.localScope)throw new Error("Function body must be a scoped Block expression");let o=r;return a=>{if(a.length>s.length)throw new Error(`Too many arguments for function "${e.toString()}": expected ${s.length}, got ${a.length}`);if(n.strict&&!a.every(T=>T.isValid))return;if(a.length<s.length){let T=new Set([...r.symbols,...s.map(ne=>k(ne)?ne.symbol:"")]),M=s.slice(a.length).map((ne,Oe)=>{let Be=`_${Oe+1}`,yt=0;for(;T.has(Be);)Be=`_${Oe+1}_${yt++}`;return T.add(Be),n.symbol(Be,{canonical:!1})}),C=Object.fromEntries(s.slice(a.length).map((ne,Oe)=>[k(ne)?ne.symbol:"",M[Oe]])),F=a.map(ne=>ne.evaluate()),U={parent:o.localScope.parent??n.context.lexicalScope,bindings:new Map};for(let ne=0;ne<a.length;ne++){let Oe=s[ne],Be=k(Oe)?Oe.symbol:"";Be&&n.declare(Be,{value:F[ne],inferred:!0},U)}let L=o.localScope,ue=L.parent;L.parent=U;let H=s.slice(0,a.length).map(ne=>k(ne)?ne.symbol:""),se=ho(L,H);n.pushScope(U);let oe;try{oe=mo(n,o.ops)}finally{n.popScope(),L.parent=ue,go(L,se)}return n.function("Function",[oe.subs(C),...M])}let u=a.map(T=>T.evaluate()),c={parent:o.localScope.parent??n.context.lexicalScope,bindings:new Map},f=s.map(T=>k(T)?T.symbol:"");for(let T=0;T<s.length;T++)f[T]&&n.declare(f[T],{value:u[T],inferred:!0},c);let m=o.localScope,d=m.parent;m.parent=c;let b=ho(m,f);n.pushScope(c);let v;try{v=mo(n,o.ops),v=bo(n,v,c)}finally{n.popScope(),m.parent=d,go(m,b)}return v.isValid?v:void 0}}function te(e){return wl(e)??(n=>e.engine.function("Apply",[e,...n]).evaluate())}function Oi(e){return(e.isFiniteCollection??!1)&&e.isIndexedCollection}function Al(e,n,t){if(!(e.isFiniteCollection!==!0||n.isFiniteCollection!==!0)){for(let i of e.each())if(n.contains(i)!==!0)return!1;if(t){let i=e.count;if(i===void 0)return!1;let r=n.count;if(r===void 0||i===r)return!1}return!0}}function $l(e,n){if(h(e)){for(let t=0;t!==e.nops;t+=1)if(n(e.ops[t]))return t+1}}function At(){return{isLazy:e=>!1,count:e=>h(e)?e.nops:0,isEmpty:e=>!h(e)||e.nops===0,isFinite:e=>!0,contains:(e,n)=>h(e)?e.ops.some(t=>t.isSame(n)):!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=1,t=e.nops;return{next:()=>n===t+1?{value:void 0,done:!0}:(n+=1,{value:e.ops[n-1-1],done:!1})}},subsetOf:Al,at:(e,n)=>{if(!(typeof n!="number"||!h(e))&&(n<0&&(n=e.nops+n+1),!(n<1||n>e.nops)))return e.ops[n-1]},indexWhere:$l,eltsgn:e=>{},elttype:e=>!h(e)||e.nops===0?"unknown":e.nops===1?e.ops[0].type.type:xe(...e.ops.map(n=>n.type.type))}}var Tn=class extends Error{cause;value;constructor({message:n,value:t,cause:i}={}){super(n??"Operation canceled"),t&&(this.value=t),this.cause=i,this.name="CancellationError"}};function Bi(e,n){let t=Date.now();for(;;){let{done:i,value:r}=e.next();if(i)return r;if(Date.now()-t>=n)throw new Tn({value:r,cause:"timeout",message:`Timeout exceeded (${n}ms)`})}}function N(e){let n="",t="";for(let i of e)i!=null&&(typeof i=="string"&&(/[a-zA-Z]/.test(i[0])&&(t+=n),/\\[a-zA-Z]+\*?$/.test(i)?n=" ":n=""),t+=i.toString());return t}function In(e,n,t){return n.includes(e)&&(n=`{${n}}`),/^[0-9]$/.test(t)?`${n}${e}${t}`:`${n}${e}{${t}}`}var P=245,Wn=260,ze=270,ee=275,ge=390,Ee=600;var Xn=700,Vi=810;var un=[{latexTrigger:["\\not","<"],kind:"infix",associativity:"any",precedence:246,parse:"NotLess"},{name:"NotLess",latexTrigger:["\\nless"],kind:"infix",associativity:"any",precedence:246},{latexTrigger:["<"],kind:"infix",associativity:"any",precedence:245,parse:"Less"},{name:"Less",latexTrigger:["\\lt"],kind:"infix",associativity:"any",precedence:245},{latexTrigger:["<","="],kind:"infix",associativity:"any",precedence:241,parse:"LessEqual"},{name:"LessEqual",latexTrigger:["\\le"],kind:"infix",associativity:"any",precedence:241},{latexTrigger:["\\leq"],kind:"infix",associativity:"any",precedence:241,parse:"LessEqual"},{latexTrigger:["\\leqslant"],kind:"infix",associativity:"any",precedence:P+5,parse:"LessEqual"},{name:"LessNotEqual",latexTrigger:["\\lneqq"],kind:"infix",associativity:"any",precedence:P},{name:"NotLessNotEqual",latexTrigger:["\\nleqq"],kind:"infix",associativity:"any",precedence:P},{name:"LessOverEqual",latexTrigger:["\\leqq"],kind:"infix",associativity:"any",precedence:P+5},{name:"GreaterOverEqual",latexTrigger:["\\geqq"],kind:"infix",associativity:"any",precedence:P+5,parse:"GreaterEqual"},{name:"Equal",latexTrigger:["="],kind:"infix",associativity:"right",precedence:P},{latexTrigger:["*","="],kind:"infix",associativity:"right",precedence:P,parse:"StarEqual"},{name:"StarEqual",latexTrigger:["\\star","="],kind:"infix",associativity:"right",precedence:P},{name:"PlusEqual",latexTrigger:["+","="],kind:"infix",associativity:"right",precedence:P},{name:"MinusEqual",latexTrigger:["-","="],kind:"infix",associativity:"right",precedence:P},{name:"SlashEqual",latexTrigger:["/","="],kind:"infix",associativity:"right",precedence:P},{name:"EqualEqual",latexTrigger:["=","="],kind:"infix",associativity:"right",precedence:P},{name:"EqualEqualEqual",latexTrigger:["=","=","="],kind:"infix",associativity:"right",precedence:P+5},{name:"TildeFullEqual",latexTrigger:["\\cong"],kind:"infix",associativity:"right",precedence:P},{name:"NotTildeFullEqual",latexTrigger:["\\ncong"],kind:"infix",associativity:"right",precedence:P},{name:"Approx",latexTrigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"NotApprox",latexTrigger:["\\not","\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"ApproxEqual",latexTrigger:["\\approxeq"],kind:"infix",associativity:"right",precedence:P},{name:"NotApproxEqual",latexTrigger:["\\not","\\approxeq"],kind:"infix",associativity:"right",precedence:250},{name:"NotEqual",latexTrigger:["\\ne"],kind:"infix",associativity:"right",precedence:255},{name:"Unequal",latexTrigger:["!","="],kind:"infix",associativity:"right",precedence:P},{name:"GreaterEqual",latexTrigger:["\\ge"],kind:"infix",associativity:"right",precedence:242},{latexTrigger:["\\geq"],kind:"infix",associativity:"right",precedence:242,parse:"GreaterEqual"},{latexTrigger:[">","="],kind:"infix",associativity:"right",precedence:243,parse:"GreaterEqual"},{latexTrigger:["\\geqslant"],kind:"infix",associativity:"right",precedence:P+5,parse:"GreaterEqual"},{name:"GreaterNotEqual",latexTrigger:["\\gneqq"],kind:"infix",associativity:"right",precedence:P},{name:"NotGreaterNotEqual",latexTrigger:["\\ngeqq"],kind:"infix",associativity:"right",precedence:P},{latexTrigger:[">"],kind:"infix",associativity:"right",precedence:245,parse:"Greater"},{name:"Greater",latexTrigger:["\\gt"],kind:"infix",associativity:"right",precedence:245},{name:"NotGreater",latexTrigger:["\\ngtr"],kind:"infix",associativity:"right",precedence:244},{latexTrigger:["\\not",">"],kind:"infix",associativity:"right",precedence:244,parse:"NotGreater"},{name:"RingEqual",latexTrigger:["\\circeq"],kind:"infix",associativity:"right",precedence:P},{name:"TriangleEqual",latexTrigger:["\\triangleq"],kind:"infix",associativity:"right",precedence:P},{name:"DotEqual",latexTrigger:["\\doteq"],kind:"infix",associativity:"right",precedence:P+5},{name:"DotEqualDot",latexTrigger:["\\doteqdot"],kind:"infix",associativity:"right",precedence:P+5},{name:"FallingDotEqual",latexTrigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:P+5},{name:"RisingDotEqual",latexTrigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:P+5},{name:"QuestionEqual",latexTrigger:["\\questeq"],kind:"infix",associativity:"right",precedence:P},{name:"MuchLess",latexTrigger:["\\ll"],kind:"infix",associativity:"right",precedence:P},{name:"MuchGreater",latexTrigger:["\\gg"],kind:"infix",associativity:"right",precedence:P},{name:"Precedes",latexTrigger:["\\prec"],kind:"infix",associativity:"right",precedence:P},{name:"Succeeds",latexTrigger:["\\succ"],kind:"infix",associativity:"right",precedence:P},{name:"PrecedesEqual",latexTrigger:["\\preccurlyeq"],kind:"infix",associativity:"right",precedence:P},{name:"SucceedsEqual",latexTrigger:["\\curlyeqprec"],kind:"infix",associativity:"right",precedence:P},{name:"NotPrecedes",latexTrigger:["\\nprec"],kind:"infix",associativity:"right",precedence:P},{name:"NotSucceeds",latexTrigger:["\\nsucc"],kind:"infix",associativity:"right",precedence:P},{name:"Between",latexTrigger:["\\between"],kind:"infix",associativity:"right",precedence:P+5}];function Ji(e){return typeof e!="string"?!1:un.some(n=>n.name===e)}function qi(e){return typeof e!="string"?!1:["Less","LessEqual","Greater","GreaterEqual"].includes(e)}function zi(e){return typeof e!="string"?!1:["Equal","NotEqual"].includes(e)}var _n=["Error","'missing'"];function ln(e){return!!(typeof e=="number"||kn(e)||typeof e=="string"&&Dt(e))}function kn(e){return e!==null&&typeof e=="object"&&"num"in e}function $t(e){return e!==null&&typeof e=="object"&&"sym"in e}function xo(e){return e!==null&&typeof e=="object"&&"str"in e}function vo(e){return e!==null&&typeof e=="object"&&"dict"in e&&typeof e.dict=="object"&&!Array.isArray(e.dict)&&e.dict!==null}function Sn(e){return e!==null&&typeof e=="object"&&"fn"in e&&Array.isArray(e.fn)&&e.fn.length>0&&typeof e.fn[0]=="string"}function B(e){return e==null?null:typeof e=="object"&&"str"in e?e.str:typeof e!="string"?null:e.length>=2&&e.at(0)==="'"&&e.at(-1)==="'"?e.substring(1,e.length-1):Dt(e)||Hi(e)?null:e}function ji(e){if(e==null||B(e)!==null)return null;let n=y(e);return n?[n,...I(e).map(t=>ji(t)).filter(t=>t!==null)]:e}function y(e){return Array.isArray(e)?e[0]:e==null?"":Sn(e)?e.fn[0]:""}function I(e){return Array.isArray(e)?e.slice(1):e!==void 0&&Sn(e)?e.fn.slice(1):[]}function p(e,n){return Array.isArray(e)?e[n]??null:e===null||!Sn(e)?null:e.fn[n]??null}function Z(e){return e==null?0:Array.isArray(e)?Math.max(0,e.length-1):Sn(e)?Math.max(0,e.fn.length-1):0}function Ui(e){return e==null?null:y(e)==="Hold"?p(e,1):e}function S(e){return typeof e=="string"&&Hi(e)?e.length>=2&&e.at(0)==="`"&&e.at(-1)==="`"?e.slice(1,-1):e:e==null?null:$t(e)?e.sym:null}function yo(e){let n=y(e);if(n==="KeyValuePair"||n==="Tuple"||n==="Pair"){let[t,i]=I(e),r=B(t);return r?[r,i??"Nothing"]:null}return null}function Eo(e){if(e===null)return null;if(vo(e))return e;let n=yo(e);if(n)return{[n[0]]:n[1]};if(y(e)==="Dictionary"){let t={},i=I(e);for(let r=1;r<Z(e);r++){let s=yo(i[r]);s&&(t[s[0]]=Fl(s[1])??"Nothing")}return{dict:t}}return null}function Ct(e){return{dict:Object.fromEntries(Object.entries(e).map(([t,i])=>[t,Gi(i)??"Nothing"]))}}function Pl(e){if(e=e.toLowerCase().replace(/[nd]$/,"").replace(/[\u0009-\u000d\u0020\u00a0]/g,""),e==="nan")return NaN;if(/^(infinity|\+infinity|oo|\+oo)$/i.test(e))return 1/0;if(/^(-infinity|-oo)$/.test(e))return-1/0;if(/\([0-9]+\)/.test(e)){let[n,t,i,r]=e.match(/(.+)\(([0-9]+)\)(.*)$/)??[];e=t+i.repeat(Math.ceil(16/i.length))+(r??"")}return parseFloat(e)}function R(e){return typeof e=="number"?e:typeof e=="string"&&Dt(e)?Pl(e):e!==void 0&&kn(e)?R(e.num):null}function Mn(e){if(e==null)return null;if(S(e)==="Half")return[1,2];let n=y(e);if(!n)return null;let t=null,i=null;if(n==="Negate"){let r=Mn(I(e)[0]);if(r)return[-r[0],r[1]]}if(n==="Rational"||n==="Divide"){let[r,s]=I(e);t=R(r)??NaN,i=R(s)??NaN}if(n==="Power"){let[r,s]=I(e),o=R(s);o===1?(t=R(r),i=1):o===-1&&(t=1,i=R(r))}if(n==="Multiply"){let[r,s]=I(e);if(y(s)==="Power"){let[o,a]=I(s);R(a)===-1&&(t=R(r),i=R(o))}}return t===null||i===null?null:Number.isInteger(t)&&Number.isInteger(i)?[t,i]:null}function Rt(e,n){let t=null;if(Array.isArray(e)&&(t=e),Sn(e)&&(t=e.fn),t===null)return[];let i=1,r=[];for(;i<t.length;)r.push(n(t[i])),i+=1;return r}function wn(e,n,t){let i=y(n),r=y(t);return i===e&&r===e?[e,...I(n),...I(t)]:i===e?[e,...I(n),t]:r===e?[e,n,...I(t)]:[e,n,t]}function cn(e){if(e==null)return null;let n=y(e);if(n==="Delimiter"){if(e=p(e,1),e===null)return[];if(n=y(e),n!=="Sequence")return[e]}return n!=="Sequence"?null:I(e)}function z(e){return e==null||e==="Nothing"?!0:y(e)==="Sequence"&&Z(e)===0}function j(e){return z(e)?_n:e}function Dt(e){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(e)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(e)}function Hi(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)||e.length>=2&&e[0]==="`"&&e[e.length-1]==="`"}function Gi(e){if(typeof e=="string")return{str:e};if(typeof e=="number")return{num:e.toString()};if(typeof e=="boolean")return e?"True":"False";if(Array.isArray(e))return["List",...e.map(n=>Gi(n)??"Nothing")];if(e===null)return null;if(typeof e=="object"){let n={};for(let t in e)n[t]=Gi(e[t])??"Nothing";return{dict:n}}return Sn(e)||$t(e)||kn(e)||xo(e)||vo(e)?e:null}function Fl(e){return e==null?null:xo(e)?e.str:kn(e)?parseFloat(e.num):$t(e)?e.sym:typeof e=="string"||typeof e=="number"?e:Array.isArray(e)?{fn:e}:e}var To=[{name:"True",kind:"symbol",latexTrigger:["\\top"]},{kind:"symbol",latexTrigger:"\\mathrm{True}",parse:"True"},{kind:"symbol",latexTrigger:"\\operatorname{True}",parse:"True"},{kind:"symbol",latexTrigger:"\\mathsf{T}",parse:"True"},{name:"False",kind:"symbol",latexTrigger:["\\bot"]},{kind:"symbol",latexTrigger:"\\operatorname{False}",parse:"False"},{kind:"symbol",latexTrigger:"\\mathsf{F}",parse:"False"},{name:"And",kind:"infix",latexTrigger:["\\land"],precedence:235},{kind:"infix",latexTrigger:["\\wedge"],parse:"And",precedence:235},{kind:"infix",latexTrigger:"\\&",parse:"And",precedence:235},{kind:"infix",latexTrigger:"\\operatorname{and}",parse:"And",precedence:235},{name:"Or",kind:"infix",latexTrigger:["\\lor"],precedence:230},{kind:"infix",latexTrigger:["\\vee"],parse:"Or",precedence:230},{kind:"infix",latexTrigger:"\\parallel",parse:"Or",precedence:230},{kind:"infix",latexTrigger:"\\operatorname{or}",parse:"Or",precedence:230},{name:"Xor",kind:"infix",latexTrigger:["\\veebar"],precedence:232},{name:"Not",kind:"prefix",latexTrigger:["\\lnot"],precedence:880},{kind:"prefix",latexTrigger:["\\neg"],parse:"Not",precedence:880},{name:"Nand",kind:"infix",latexTrigger:["\\barwedge"],precedence:232},{name:"Nor",kind:"infix",latexTrigger:["\u22BD"],precedence:232},{kind:"function",symbolTrigger:"and",parse:"And"},{kind:"function",symbolTrigger:"or",parse:"Or"},{kind:"function",symbolTrigger:"not",parse:"Not"},{name:"Implies",kind:"infix",precedence:220,associativity:"right",latexTrigger:["\\implies"],serialize:"\\implies"},{latexTrigger:["\\Rightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["\\rightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["\\Longrightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["\\longrightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["=",">"],kind:"infix",precedence:220,associativity:"right",parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:220});return i===null?null:["Implies",n,i]}},{name:"Equivalent",latexTrigger:["\\iff"],kind:"infix",associativity:"right",precedence:219},{latexTrigger:["\\Leftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["\\leftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["\\Longleftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["\\longleftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["<","=",">"],kind:"infix",precedence:219,associativity:"right",parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:219});return i===null?null:["Equivalent",n,i]}},{latexTrigger:["\\equiv"],kind:"infix",associativity:"right",precedence:219,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:219}),r=e.index,s=e.parseExpression({...t,minPrec:219});return s!==null&&y(s)==="Mod"?["Congruent",n,i,j(p(s,1))]:(e.index=r,["Equivalent",n,j(i)])}},{name:"Proves",kind:"infix",latexTrigger:["\\vdash"],precedence:220,associativity:"right",serialize:"\\vdash"},{name:"Entails",kind:"infix",latexTrigger:["\\vDash"],precedence:220,associativity:"right",serialize:"\\vDash"},{name:"Satisfies",kind:"infix",latexTrigger:["\\models"],precedence:220,associativity:"right",serialize:"\\models"},{name:"ForAll",kind:"prefix",latexTrigger:["\\forall"],precedence:200,serialize:Qn("\\forall"),parse:Ke("ForAll")},{name:"Exists",kind:"prefix",latexTrigger:["\\exists"],precedence:200,serialize:Qn("\\exists"),parse:Ke("Exists")},{name:"ExistsUnique",kind:"prefix",latexTrigger:["\\exists","!"],precedence:200,serialize:Qn("\\exists!"),parse:Ke("ExistsUnique")},{name:"NotForAll",kind:"prefix",latexTrigger:["\\lnot","\\forall"],precedence:200,serialize:Qn("\\lnot\\forall"),parse:Ke("NotForAll")},{name:"NotExists",kind:"prefix",latexTrigger:["\\lnot","\\exists"],precedence:200,serialize:Qn("\\lnot\\exists"),parse:Ke("NotExists")},{name:"KroneckerDelta",kind:"prefix",latexTrigger:["\\delta","_"],precedence:200,serialize:(e,n)=>{let t=I(n);return t.length===0?"\\delta":t.every(i=>S(i))?`\\delta_{${t.map(i=>e.serialize(i)).join("")}}`:`\\delta_{${t.map(i=>e.serialize(i)).join(", ")}}`},parse:e=>{let n=e.parseGroup();if(n===null){let i=e.parseToken();return i?["KroneckerDelta",i]:null}let t=cn(n);return t&&t.length<=2?["KroneckerDelta",...t]:y(n)==="InvisibleOperator"?["KroneckerDelta",...I(n)]:n!==null?["KroneckerDelta",n]:null}},{name:"Boole",kind:"matchfix",openTrigger:"[",closeTrigger:"]",parse:(e,n)=>{let t=y(n);return!t||!un.some(i=>i.name===t)?null:["Boole",n]}},{kind:"matchfix",openTrigger:"\\llbracket",closeTrigger:"\\rrbracket",parse:(e,n)=>{let t=y(n);return!t||!un.some(i=>i.name===t)?null:["Boole",n]}},{name:"Predicate",serialize:(e,n)=>{let t=I(n);if(t.length===0)return"";let i=t[0],r=typeof i=="string"?i:e.serialize(i);if(t.length===1)return r;let s=t.slice(1).map(o=>e.serialize(o));return`${r}(${s.join(", ")})`}}];function Qn(e){return(n,t)=>{let i=I(t);if(i.length===0)return e;if(i.length===1)return`${e} ${n.serialize(i[0])}`;let r=n.serialize(i[0]),s=n.serialize(i[1]);return`${e} ${r}, ${s}`}}function No(e,n){return e.peek==="\\to"||e.peek==="\\rightarrow"||e.peek==="\\implies"||e.peek==="\\Rightarrow"||e.peek==="\\iff"||e.peek==="\\Leftrightarrow"||e.peek==="\\land"||e.peek==="\\wedge"||e.peek==="\\lor"||e.peek==="\\vee"||(n.condition?.(e)??!1)}function Ke(e){return(n,t)=>{let i=n.index,r=n.options.quantifierScope!=="loose",s=n.parseSymbol(t);if(s){if(n.skipSpace(),n.match(",")||n.match("\\mid")||n.match(".")||n.match(":")||n.match("\\colon")){let l=r?{...t,condition:f=>No(f,t)}:t;n.enterQuantifierScope();let c=n.parseExpression(l);return n.exitQuantifierScope(),[e,s,j(c)]}n.enterQuantifierScope();let u=n.parseEnclosure();if(n.exitQuantifierScope(),u)return[e,s,j(u)]}n.index=i;let o={...t,condition:u=>u.peek===":"||u.peek==="\\colon"||(t.condition?.(u)??!1)},a=n.parseExpression(o);if(a===null)return null;if(n.skipSpace(),n.matchAny([",","\\mid",":","\\colon"])){let u=r?{...t,condition:c=>No(c,t)}:t;n.enterQuantifierScope();let l=n.parseExpression(u);return n.exitQuantifierScope(),[e,a,j(l)]}if(n.match("(")){n.enterQuantifierScope();let u=n.parseExpression(t);return n.exitQuantifierScope(),n.match(")")?[e,a,j(u)]:null}return null}}var Ll={x:"First",y:"Second",z:"Third",real:"Real",re:"Real",imag:"Imaginary",im:"Imaginary",count:"Length",total:"Sum",max:"Max",min:"Min"};function Zi(e){return Ll[e]??null}function Ol(e,n){if(e.skipVisualSpace(),e.match("\\operatorname")){let i=e.parseStringGroup();if(i===null)return null;let r=Zi(i.trim());return r===null?null:[r,n]}let t=e.peek;if(typeof t=="string"&&t.startsWith("\\")){let i=t.slice(1),r=Zi(i);return r!==null?(e.nextToken(),[r,n]):null}if(typeof t=="string"&&/^[a-zA-Z]$/.test(t)){let i=Zi(t);return i===null?null:(e.nextToken(),[i,n])}return null}function Io(e,n,t){e.addBoundary(t),e.skipVisualSpace();let i=e.parseExpression({minPrec:0});return i===null||(e.skipVisualSpace(),!e.matchBoundary())?(e.removeBoundary(),null):["When",n,i]}function Yi(e,n,t,i,r){if(n&&n.minPrec>=i)return null;let s=t?[t]:["Nothing"],o=!1;for(;!o;){for(o=!0,e.skipSpace();e.match(r);)s.push("Nothing"),e.skipSpace();if(e.skipVisualSpace(),e.atTerminator(n))s.push("Nothing");else{let a=e.parseExpression({...n,minPrec:i});s.push(a??"Nothing"),o=a===null}o||(e.skipSpace(),o=!e.match(r),o||e.skipVisualSpace())}return s}function $e(e=""){return(n,t)=>{if(!t)return"";let i=I(t);if(i.length===0)return"";if(i.length===1)return n.serialize(i[0]);e={"&":"\\&",":":"\\colon","|":"\\mvert","-":"-","\xB7":"\\cdot","\u2012":"-","\u2013":"--","\u2014":"---","\u2015":"-","\u2022":"\\bullet","\u2026":"\\ldots"}[e]??e;let r=i.reduce((s,o)=>(s.push(n.serialize(o),e),s),[]);return r.pop(),N(r)}}var Ao=[{latexTrigger:["\\placeholder"],kind:"symbol",parse:e=>{for(;e.match("<space>"););if(e.match("["))for(;!e.match("]")&&!e.atBoundary;)e.nextToken();for(;e.match("<space>"););if(e.match("<{>"))for(;!e.match("<}>")&&!e.atBoundary;)e.nextToken();return"Nothing"}},{name:"ContinuationPlaceholder",latexTrigger:["\\dots"]},{latexTrigger:["\\ldots"],parse:"ContinuationPlaceholder"},{latexTrigger:[".",".","."],parse:"ContinuationPlaceholder"},{name:"Function",latexTrigger:["\\mapsto"],kind:"infix",precedence:ze,parse:(e,n,t)=>{let i=[];if(y(n)==="Delimiter"&&(n=p(n,1)??"Nothing"),y(n)==="Sequence")for(let s of I(n)){if(!S(s))return null;i.push(S(s))}else{if(!S(n))return null;i=[S(n)]}let r=e.parseExpression({minPrec:ze})??"Nothing";return y(r)==="Delimiter"&&(r=p(r,1)??"Nothing"),y(r)==="Sequence"&&(r=["Block",...I(r)]),["Function",r,...i]},serialize:(e,n)=>{let t=I(n);return t.length<1?"()\\mapsto()":t.length===1?N(["()","\\mapsto",e.serialize(p(n,1))]):t.length===2?N([e.serialize(p(n,2)),"\\mapsto",e.serialize(p(n,1))]):N([e.wrapString(I(n)?.slice(1).map(i=>e.serialize(i)).join(", "),"normal"),"\\mapsto",e.serialize(p(n,1))])}},{name:"Apply",kind:"function",symbolTrigger:"apply",serialize:(e,n)=>{let t=p(n,1),i=y(t);if(i==="InverseFunction"||i==="Derivative"){let o=e.options.applyFunctionStyle(n,e.level),a=I(n).slice(1);return e.serializeFunction(t,e.dictionary.ids.get(i))+e.wrapString(a.map(u=>e.serialize(u)).join(", "),o)}let r=p(n,2);if(typeof t=="string"||!r){let o=I(n).slice(1);return e.serialize(o)}if(Z(n)===2)return N([e.wrap(t,20),"\\lhd",e.wrap(r,20)]);let s=e.options.applyFunctionStyle(n,e.level);return N(["\\operatorname{apply}",e.wrapString(e.serialize(i)+", "+e.serialize(["List",...I(n)]),s)])}},{latexTrigger:"\\lhd",kind:"infix",precedence:20,parse:"Apply"},{latexTrigger:"\\rhd",kind:"infix",precedence:20,parse:(e,n,t)=>["Apply",e.parseExpression({minPrec:21})??"Nothing",n]},{name:"EvaluateAt",openTrigger:".",closeTrigger:"|",kind:"matchfix",serialize:(e,n)=>{let t=p(n,1);if(!t)return"";let i=I(n).slice(1);if(y(t)==="Function"){let r=I(t).slice(1),s=p(t,1);if(y(s)==="Block"&&Z(s)===1&&(s=p(s,1)),r.length>0)return`\\left.\\left(${e.serialize(s)}\\right)\\right|_{${r.map((o,a)=>`${e.serialize(o)}=${e.serialize(i[a])}`).join(", ")}}`}return`\\left.\\left(${e.serialize(t)}\\right)\\right|_{${i.map(r=>e.serialize(r)).join(", ")}}`}},{name:"Assign",latexTrigger:"\\coloneq",kind:"infix",associativity:"right",precedence:Wn,serialize:(e,n)=>{let t=Ui(p(n,1));if(y(p(n,2))==="Function"){let i=p(n,2),r=Ui(p(i,1)),s=I(i).slice(1);return N([e.serialize(t),e.wrapString(s.map(o=>e.serialize(o)).join(", "),e.options.applyFunctionStyle(n,e.level)),"\\coloneq",e.serialize(r)])}return N([e.serialize(t),"\\coloneq",e.serialize(p(n,2))])},parse:Ft},{latexTrigger:"\\coloneqq",kind:"infix",associativity:"right",precedence:Wn,parse:Ft},{latexTrigger:"\\colonequals",kind:"infix",associativity:"right",precedence:Wn,parse:Ft},{latexTrigger:[":","="],kind:"infix",associativity:"right",precedence:Wn,parse:Ft},{name:"Colon",latexTrigger:":",kind:"infix",associativity:"right",precedence:240,serialize:(e,n)=>N([e.serialize(p(n,1)),"\\colon",e.serialize(p(n,2))])},{latexTrigger:"\\colon",kind:"infix",associativity:"right",precedence:240,parse:"Colon"},{name:"BaseForm",serialize:(e,n)=>{let t=R(p(n,2))??NaN;if(isFinite(t)&&t>=2&&t<=36){let i=R(p(n,1))??NaN;if(isFinite(i)&&Number.isInteger(i)){let r=Number(i).toString(t),s=0;if(t===2||t===10?s=4:t===16?s=2:t>16&&(s=4),s>0){let o=r;r="";for(let a=0;a<o.length;a++)a>0&&a%s===0&&(r="\\, "+r),r=o[o.length-a-1]+r}return`(\\text{${r}}_{${t}}`}}return"\\operatorname{BaseForm}("+e.serialize(p(n,1))+", "+e.serialize(p(n,2))+")"}},{name:"Sequence",serialize:$e(" ")},{name:"InvisibleOperator",serialize:$e("")},{name:"Delimiter",serialize:(e,n)=>{let t=e.options.groupStyle(n,e.level+1),i=p(n,1),r={Set:"{,}",List:"[,]",Tuple:"(,)",Single:"(,)",Pair:"(,)",Triple:"(,)",Sequence:"(,)",String:'""'}[y(i)],s=r?i:["Sequence",i];if(r??="(,)",Z(n)>1){let c=B(p(n,2));typeof c=="string"&&c.length<=3&&(r=c)}let[o,a,u]=["","",""];r.length===3?[o,a,u]=r:r.length===2?[o,u]=r:r.length===1&&(a=r);let l=i?s?$e(a)(e,s):e.serialize(i):"";return e.wrapString(l,t,o+u)}},{name:"Tuple",serialize:(e,n)=>N(["(",$e(",")(e,n),")"])},{name:"Pair",serialize:(e,n)=>N(["(",$e(",")(e,n),")"])},{name:"Triple",serialize:(e,n)=>N(["(",$e(",")(e,n),")"])},{name:"Single",serialize:(e,n)=>N(["(",$e(",")(e,n),")"])},{name:"Domain",serialize:(e,n)=>y(n)==="Error"?e.serialize(n):`\\mathbf{${e.serialize(p(n,1))}}`},{latexTrigger:["\\mathtip"],parse:e=>{let n=e.parseGroup();return e.parseGroup(),n}},{latexTrigger:["\\texttip"],parse:e=>{let n=e.parseGroup();return e.parseGroup(),n}},{latexTrigger:["\\error"],parse:e=>["Error",e.parseGroup()]},{name:"Error",serialize:(e,n)=>{let t=p(n,1);if(B(t)==="missing")return`\\error{${e.options.missingSymbol??"\\placeholder{}"}}`;let i=Vl(e,n)||"\\blacksquare",r=y(t)==="ErrorCode"?B(p(t,1)):B(t);return r==="incompatible-type"?S(p(t,3))==="Undefined"?`\\mathtip{\\error{${i}}}{\\notin ${e.serialize(p(t,2))}}`:`\\mathtip{\\error{${i}}}{\\in ${e.serialize(p(t,3))}\\notin ${e.serialize(p(t,2))}}`:typeof r=="string"?`\\error{${i}}`:`\\error{${i}}`}},{name:"ErrorCode",serialize:(e,n)=>{let t=B(p(n,1));return t==="missing"?e.options.missingSymbol??"\\placeholder{}":t==="unexpected-command"||t==="unexpected-operator"||t==="unexpected-token"||t==="invalid-symbol"||t==="unknown-environment"||t==="unexpected-base"||t==="incompatible-type"?"":`\\texttip{\\error{\\blacksquare}}{\\mathtt{${t}}}`}},{name:"FromLatex",serialize:(e,n)=>`\\texttt{${_o(B(p(n,1)))}}`},{name:"Latex",serialize:(e,n)=>n===null?"":N(Rt(n,t=>B(t)??e.serialize(t)))},{name:"LatexString",serialize:(e,n)=>n===null?"":N(Rt(n,t=>e.serialize(t)))},{name:"LatexTokens",serialize:Bl},{kind:"postfix",precedence:850,latexTrigger:["."],parse:Ol},{name:"At",kind:"postfix",precedence:810,latexTrigger:["["],parse:Xi("]"),serialize:(e,n)=>N(["\\lbrack",$e(", ")(e,n),"\\rbrack"])},{kind:"postfix",precedence:810,latexTrigger:["\\lbrack"],parse:Xi("\\rbrack")},{kind:"postfix",precedence:810,latexTrigger:["\\left","\\lbrack"],parse:Xi("\\right","\\rbrack")},{name:"When",kind:"postfix",precedence:800,latexTrigger:["\\left","\\{"],parse:(e,n)=>Io(e,n,["\\right","\\}"]),serialize:(e,n)=>{let t=p(n,1),i=p(n,2);if(!t||!i)return"";let s=(y(i)==="And"?I(i)??[]:[i]).map(o=>`\\left\\{${e.serialize(o)}\\right\\}`).join("");return`${e.serialize(t)}${s}`}},{kind:"postfix",precedence:800,latexTrigger:["\\{"],parse:(e,n)=>Io(e,n,["\\}"])},{kind:"postfix",latexTrigger:["_"],parse:(e,n,t)=>{let i=e.parseGroup()??e.parseToken();i===null&&e.options.strict===!1&&e.peek==="("&&(i=e.parseEnclosure());let r=S(n);return i!==null&&(r&&e.getSymbolType(r).matches("indexed_collection")||y(n)==="List")?(y(i)==="Delimiter"&&(i=p(i,1)??"Nothing"),y(i)==="Sequence"?["At",n,...I(i)]:["At",n,i]):["Subscript",n,i]}},{name:"List",kind:"matchfix",openTrigger:"[",closeTrigger:"]",parse:$o,serialize:ql},{kind:"matchfix",openTrigger:"(",closeTrigger:")",parse:Jl},{latexTrigger:[","],kind:"infix",precedence:20,parse:(e,n,t)=>{let i=Yi(e,t,n,20,",");return i===null?null:["Delimiter",["Sequence",...i],{str:","}]}},{latexTrigger:[","],kind:"prefix",precedence:20,parse:(e,n)=>{let t=Yi(e,n,null,20,",");return t===null?null:["Delimiter",["Sequence",...t],{str:","}]}},{name:"Range",latexTrigger:[".","."],kind:"infix",precedence:800,parse:Pt,serialize:(e,n)=>{let t=I(n);if(t.length===0)return"";if(t.length===1)return"1.."+e.serialize(p(n,1));if(t.length===2)return e.wrap(p(n,1),10)+".."+e.wrap(p(n,2),10);if(t.length===3){let i=R(p(n,3)),r=R(p(n,1));return i!==null&&r!==null?e.wrap(p(n,1),10)+".."+e.wrap(r+i,10)+".."+e.wrap(p(n,2),10):e.wrap(p(n,1),10)+"..("+(e.wrap(p(n,1),ee)+"+"+e.wrap(p(n,3),ee))+").."+e.wrap(p(n,2),10)}return""}},{latexTrigger:[".",".","."],kind:"infix",precedence:800,parse:Pt},{latexTrigger:["\\ldots"],kind:"infix",precedence:800,parse:Pt},{latexTrigger:["\\dots"],kind:"infix",precedence:800,parse:Pt},{latexTrigger:[";"],kind:"infix",precedence:19,parse:(e,n,t)=>{let i=Yi(e,t,n,19,";");return i===null?null:i.some(r=>y(r)==="Assign")?zl(i):["Delimiter",["Sequence",...i],"';'"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"none",precedence:21,parse:(e,n,t)=>{let i=e.index;return be(e,"where")?wo(e,n,t):(e.index=i,null)}},{symbolTrigger:"where",kind:"infix",associativity:"none",precedence:21,parse:(e,n,t)=>wo(e,n,t)},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:235,parse:(e,n,t)=>{let i=e.index;if(!be(e,"and"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:235});return["And",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:230,parse:(e,n,t)=>{let i=e.index;if(!be(e,"or"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:230});return["Or",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:219,parse:(e,n,t)=>{let i=e.index;if(!be(e,"iff"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:219});return["Equivalent",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:219,parse:(e,n,t)=>{let i=e.index;if(!be(e,"if and only if"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:219});return["Equivalent",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:21,parse:(e,n,t)=>{let i=e.index;if(!be(e,"such that"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:21});return["Colon",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"prefix",precedence:200,parse:(e,n)=>{let t=e.index;return be(e,"for all")?Ke("ForAll")(e,n):(e.index=t,null)}},{latexTrigger:["\\text"],kind:"prefix",precedence:200,parse:(e,n)=>{let t=e.index;return be(e,"there exists")?Ke("Exists")(e,n):(e.index=t,null)}},{name:"Block",serialize:(e,n)=>{let t=I(n);return!t||t.length===0?"":t.filter(r=>y(r)!=="Declare").map(r=>e.serialize(r)).join("; ")}},{name:"If",serialize:(e,n)=>{let t=I(n);return!t||t.length<3?"":N(["\\text{if }",e.serialize(t[0]),"\\text{ then }",e.serialize(t[1]),"\\text{ else }",e.serialize(t[2])])}},{name:"Loop",serialize:(e,n)=>{let t=I(n);if(!t||t.length<2)return"";let i=t[0],r=t.slice(1);if(!r.every(a=>y(a)==="Element"))return N(["\\operatorname{Loop}(",e.serialize(i),", ",e.serialize(r[0]),")"]);if(r.length===1){let a=r[0],u=p(a,1),l=p(a,2);if(y(l)==="Range"){let c=p(l,1),f=p(l,2);return N(["\\text{for }",e.serialize(u),"\\text{ from }",e.serialize(c),"\\text{ to }",e.serialize(f),"\\text{ do }",e.serialize(i)])}return N([e.serialize(i)," \\operatorname{for} ",e.serialize(u)," = ",e.serialize(l)])}let o=r.map(a=>{let u=p(a,1),l=p(a,2);return N([e.serialize(u)," = ",e.serialize(l)])}).join(", ");return N([e.serialize(i)," \\operatorname{for} ",o])}},{name:"Break",serialize:()=>"\\text{break}"},{name:"Continue",serialize:()=>"\\text{continue}"},{name:"Return",serialize:(e,n)=>{let t=p(n,1);return!t||S(t)==="Nothing"?"\\text{return}":N(["\\text{return }",e.serialize(t)])}},{symbolTrigger:"if",kind:"prefix",precedence:245,parse:(e,n)=>So(e,n)},{symbolTrigger:"for",kind:"prefix",precedence:245,parse:(e,n)=>Mo(e,n)},{symbolTrigger:"for",kind:"infix",associativity:"none",precedence:19,parse:(e,n,t)=>Co(e,n,t)},{symbolTrigger:"break",kind:"prefix",precedence:245,parse:()=>["Break"]},{symbolTrigger:"continue",kind:"prefix",precedence:245,parse:()=>["Continue"]},{symbolTrigger:"return",kind:"prefix",precedence:245,parse:(e,n)=>["Return",e.parseExpression(n)??"Nothing"]},{name:"Text",serialize:(e,n)=>{let t=I(n);if(t.length===0)return"";let i=-1,r=-1;for(let a=0;a<t.length;a++)B(t[a])!==null&&(i<0&&(i=a),r=a);if(i<0)return N(t.map(a=>e.serialize(a)));let s=[];for(let a=0;a<i;a++)s.push(e.serialize(t[a]));let o="";for(let a=i;a<=r;a++){let u=B(t[a]);u!==null?o+=_o(u):y(t[a])==="Annotated"||y(t[a])==="Text"?o+=e.serialize(t[a]):o+="$"+e.serialize(t[a])+"$"}s.push("\\text{"+o+"}");for(let a=r+1;a<t.length;a++)s.push(e.serialize(t[a]));return N(s)}},{name:"String",latexTrigger:["\\text"],parse:(e,n)=>{let t=e.index;return be(e,"if")?So(e,n):(e.index=t,be(e,"for")?Mo(e,n):(e.index=t,be(e,"break")?["Break"]:(e.index=t,be(e,"continue")?["Continue"]:(e.index=t,be(e,"return")?["Return",e.parseExpression(n)??"Nothing"]:(e.index=t,Ae(e))))))},serialize:(e,n)=>{let t=I(n);return t.length===0?"\\text{}":N(["\\text{",t.map(i=>e.serialize(i)).join(""),"}"])}},{name:"Subscript",latexTrigger:["_"],kind:"infix",serialize:(e,n)=>Z(n)===2?e.serialize(p(n,1))+"_{"+e.serialize(p(n,2))+"}":"_{"+e.serialize(p(n,1))+"}"},{name:"Superplus",latexTrigger:["^","+"],kind:"postfix"},{name:"Subplus",latexTrigger:["_","+"],kind:"postfix"},{name:"Superminus",latexTrigger:["^","-"],kind:"postfix",parse:(e,n)=>e.options.strict===!1&&/^[0-9]$/.test(e.peek)?null:["Superminus",n]},{name:"Subminus",latexTrigger:["_","-"],kind:"postfix"},{latexTrigger:["^","*"],kind:"postfix",parse:(e,n)=>["Superstar",n]},{latexTrigger:["_","*"],kind:"postfix",parse:(e,n)=>["Substar",n]},{name:"Substar",latexTrigger:["_","\\star"],kind:"postfix"},{name:"Superdagger",latexTrigger:["^","\\dagger"],kind:"postfix"},{latexTrigger:["^","\\dag"],kind:"postfix",parse:(e,n)=>["Superdagger",n]},{name:"Prime",latexTrigger:["^","\\prime"],kind:"postfix",parse:(e,n)=>Ge(e,n,1),serialize:(e,n)=>{let t=R(p(n,2))??1,i=e.serialize(p(n,1));return t===1?i+"^\\prime":t===2?i+"^\\doubleprime":t===3?i+"^\\tripleprime":i+"^{("+e.serialize(p(n,2))+")}"}},{latexTrigger:"^{\\prime\\prime}",kind:"postfix",parse:(e,n)=>Ge(e,n,2)},{latexTrigger:"^{\\prime\\prime\\prime}",kind:"postfix",parse:(e,n)=>Ge(e,n,3)},{latexTrigger:["^","\\doubleprime"],kind:"postfix",parse:(e,n)=>Ge(e,n,2)},{latexTrigger:["^","\\tripleprime"],kind:"postfix",parse:(e,n)=>Ge(e,n,3)},{latexTrigger:"'",kind:"postfix",precedence:810,parse:(e,n)=>Ge(e,n,1)},{latexTrigger:"\\prime",kind:"postfix",precedence:810,parse:(e,n)=>Ge(e,n,1)},{latexTrigger:"\\doubleprime",kind:"postfix",precedence:810,parse:(e,n)=>Ge(e,n,2)},{latexTrigger:"\\tripleprime",kind:"postfix",precedence:810,parse:(e,n)=>Ge(e,n,3)},{latexTrigger:["^","<{>","("],kind:"postfix",parse:(e,n,t)=>{let i=S(n);if(!i||!e.getSymbolType(i).matches("function"))return null;e.addBoundary([")"]);let r=e.parseExpression(t);return e.matchBoundary()?e.match("<}>")?["Derivative",n,r]:null:(e.removeBoundary(),null)}},{name:"InverseFunction",latexTrigger:"^{-1",kind:"postfix",parse:(e,n)=>{if(y(n)==="Matrix")return e.match("<}>"),["Inverse",n];let t=S(n);if(!t)return null;let i=e.getSymbolType(t);if(i.matches(new he("matrix")))return e.match("<}>"),["Inverse",n];if(!i.matches("function"))return null;let r=0;for(;!e.atEnd&&!e.match("<}>");)if(e.match("'"))r++;else if(e.match("\\prime"))r++;else if(e.match("\\doubleprime"))r+=2;else if(e.match("\\tripleprime"))r+=3;else return null;return r===1?["Derivative",["InverseFunction",n]]:r>0?["Derivative",["InverseFunction",n],r]:["InverseFunction",n]},serialize:(e,n)=>e.serialize(p(n,1))+"^{-1}"},{name:"Derivative",serialize:(e,n)=>{let t=R(p(n,2))??1,i=e.serialize(p(n,1));return t===1?i+"^{\\prime}":t===2?i+"^{\\doubleprime}":t===3?i+"^{\\tripleprime}":i+"^{("+e.serialize(p(n,2))+")}"}},{name:"D",serialize:(e,n)=>{if(y(n)!=="D")return"D";let t=p(n,1),i=p(n,2);if(!t||!i)return"D";let r=1,s=t;for(;y(s)==="D";){let l=p(s,2);if(S(l)===S(i))r++,s=p(s,1);else break}let o=s;y(s)==="Function"&&(o=p(s,1)??s);let a=e.serialize(o),u=e.serialize(i);return r===1?`\\frac{\\mathrm{d}}{\\mathrm{d}${u}}${a}`:`\\frac{\\mathrm{d}^{${r}}}{\\mathrm{d}${u}^{${r}}}${a}`}},{name:"NewtonDerivative1",latexTrigger:["\\dot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",n,t]}},{name:"NewtonDerivative2",latexTrigger:["\\ddot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",["D",n,t],t]}},{name:"NewtonDerivative3",latexTrigger:["\\dddot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",["D",["D",n,t],t],t]}},{name:"NewtonDerivative4",latexTrigger:["\\ddddot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",["D",["D",["D",n,t],t],t],t]}},{name:"EulerDerivative",latexTrigger:["D"],kind:"expression",parse:e=>{let n=1,t=null,i=!1;for(;!i;)if(e.match("_")){if(t=e.parseGroup()??e.parseToken(),!t)return null}else if(e.match("^")){let o=e.parseGroup()??e.parseToken();n=R(o)??1}else i=!0;if(!t)return null;e.skipSpace();let r=e.parseExpression({minPrec:740});if(!r)return null;let s=r;for(let o=0;o<n;o++)s=["D",s,t];return s}},{kind:"environment",name:"Which",symbolTrigger:"cases",parse:Wi,serialize:(e,n)=>{let t=[],i=I(n);if(i.length>0)for(let r=0;r<=i.length-2;r+=2){let s=[];s.push(e.serialize(i[r+1])),s.push(e.serialize(i[r])),t.push(s.join("&"))}return N(["\\begin{cases}",t.join("\\\\"),"\\end{cases}"])}},{kind:"environment",symbolTrigger:"dcases",parse:Wi},{kind:"environment",symbolTrigger:"rcases",parse:Wi}];function Ae(e,n){if(!e.match("<{>"))return"''";let t=[],i="",r=null,s=()=>{r!==null&&i?t.push(["Annotated",`'${i}'`,Ct(r)]):i&&t.push(`'${i}'`),i="",r=null};for(;!e.atEnd&&!e.match("<}>");)if(e.peek==="<{>")s(),t.push(Ae(e));else if(e.match("\\textbf"))s(),t.push(Ae(e,{fontWeight:"bold"}));else if(e.match("\\textmd"))s(),t.push(Ae(e,{fontStyle:"normal"}));else if(e.match("\\textup"))s(),t.push(Ae(e,{fontStyle:"normal"}));else if(e.match("\\textsl"))s(),t.push(Ae(e,{fontStyle:"italic"}));else if(e.match("\\textit"))s(),t.push(Ae(e,{fontStyle:"italic"}));else if(e.match("\\texttt"))s(),t.push(Ae(e,{fontFamily:"monospace"}));else if(e.match("\\textsf"))s(),t.push(Ae(e,{fontFamily:"sans-serif"}));else if(e.match("\\textcolor")){let a=e.index,u=e.parseStringGroup();if(u!==null){s();let l=Ae(e);t.push(["Annotated",l,Ct({color:u})])}else e.index=a,i+="\\textcolor"}else if(e.match("\\color")){let a=e.parseStringGroup();a!==null&&(s(),r={color:a})}else if(e.match("<space>"))i+=" ";else if(e.match("<$>")){let a=e.index,u=e.parseExpression()??"Nothing";e.skipSpace(),e.match("<$>")?(s(),t.push(u)):(i+="$",e.index=a)}else if(e.match("<$$>")){let a=e.index,u=e.parseExpression()??"Nothing";e.skipSpace(),e.match("<$$>")?(s(),t.push(u)):(i+="$$",e.index=a)}else{let a=e.parseChar()??e.nextToken();i+={"\\enskip":"\u2002","\\enspace":"\u2002","\\quad":"\u2003","\\qquad":"\u2003\u2003","\\space":"\u2003","\\ ":"\u2003","\\;":"\u2004","\\,":"\u2009","\\:":"\u205F","\\!":"","\\{":"{","\\}":"}","\\$":"$","\\&":"&","\\#":"#","\\%":"%","\\_":"_","\\textbackslash":"\\","\\textasciitilde":"~","\\textasciicircum":"^","\\textless":"<","\\textgreater":">","\\textbar":"|","\\textunderscore":"_","\\textbraceleft":"{","\\textbraceright":"}","\\textasciigrave":"`","\\textquotesingle":"'","\\textquotedblleft":"\u201C","\\textquotedblright":"\u201D","\\textquotedbl":'"',"\\textquoteleft":"\u2018","\\textquoteright":"\u2019","\\textbullet":"\u2022","\\textdagger":"\u2020","\\textdaggerdbl":"\u2021","\\textsection":"\xA7","\\textparagraph":"\xB6","\\textperiodcentered":"\xB7","\\textellipsis":"\u2026","\\textemdash":"\u2014","\\textendash":"\u2013","\\textregistered":"\xAE","\\texttrademark":"\u2122","\\textdegree":"\xB0"}[a]??a}s();let o;return t.length===1?o=t[0]:t.every(a=>B(a)!==null)?o="'"+t.map(a=>B(a)).join()+"'":o=["Text",...t],n?["Annotated",o,Ct(n)]:o}function Bl(e,n){return n===null?"":N(Rt(n,t=>{let i=B(t);return i===null?e.serialize(t):i==="<{>"?"{":i==="<}>"?"}":i==="<$>"?"$":i==="<$$>"?"$$":i==="<space>"?" ":i}))}function _o(e){return e===null?"":e.replace(/[{}\[\]\\:\-\$%]/g,n=>({"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "})[n]??"\\"+n)}function Vl(e,n){let t=p(n,2);return t?y(t)==="LatexString"?B(p(t,1))??"":y(t)==="Hold"?e.serialize(p(t,1)):e.serialize(t):""}function Ge(e,n,t){for(;!e.atEnd;)if(e.match("'")||e.match("\\prime"))t++;else if(e.match("\\doubleprime"))t+=2;else if(e.match("\\tripleprime"))t+=3;else break;let i=y(n);if(i==="Derivative"||i==="Prime"){let a=R(p(n,2))??1;return[i,j(p(n,1)),a+t]}let r=S(n),s=r&&e.getSymbolType(r).matches("function")||y(n);e.skipSpace();let o=e.parseArguments("enclosure");if(o&&o.length>0){let a=o[0],u=S(a)??"x",c=typeof n=="string"?[n,...o]:["Apply",n,...o];for(let f=0;f<t;f++)c=["D",c,u];return c}return s?t===1?["Derivative",n]:["Derivative",n,t]:t===1?["Prime",j(n)]:["Prime",j(n),t]}function Jl(e,n){if(z(n))return["Delimiter"];let t=y(n);if(t==="Delimiter"&&p(n,2)!==null){let i=B(p(n,2));if(i?.length===1)return["Delimiter",p(n,1)??"Nothing",{str:`(${i})`}]}return t==="Matrix"&&(B(p(n,2))??"..")===".."?["Matrix",p(n,1)]:["Delimiter",n]}function $o(e,n){if(z(n))return["List"];let t=y(n);if(t==="Range"||t==="Linspace")return n;if(t==="Sequence"){let i=I(n),r=ko(i,e);return r||["List",...i]}if(t==="Delimiter"){let i=B(p(n,2))??"...";if(i===";"||i===".;.")return["List",...(I(p(n,1))??[]).map(r=>$o(e,r))];if(i===","||i===".,."){if(n=p(n,1),y(n)==="Sequence"){let r=I(n),s=ko(r,e);return s||["List",...r]}return["List",n??"Nothing"]}}return["List",n]}function ko(e,n){if(e.length<4)return null;let t=e[e.length-2];if(S(t)!=="ContinuationPlaceholder")return null;let i=e.slice(0,-2),r=e[e.length-1];if(i.length<2)return null;let s=i.map(R);if(s.some(l=>l===null))return null;let o=s,a=o[o.length-1]-o[o.length-2],u=n.options.tolerance;if(Math.abs(a)<u)return n.error("degenerate-range-step",n.index);for(let l=1;l<o.length;l++)if(Math.abs(o[l]-o[l-1]-a)>u)return n.error("inconsistent-range-samples",n.index);return["Range",o[0],r,a]}function ql(e,n){return Z(n)>1&&I(n).every(t=>{let i=y(t);return zi(i)||qi(i)})?N(["\\begin{cases}",$e("\\\\")(e,n),"\\end{cases}"]):N(["\\bigl\\lbrack",$e(", ")(e,n),"\\bigr\\rbrack"])}function Pt(e,n){if(n===null)return null;let t=e.parseExpression({minPrec:270});if(t===null)return null;if(y(t)==="Range"){let i=p(t,1),r=p(t,2);return i&&r?["Range",n,r,["Subtract",i,n]]:null}return["Range",n,t]}var Lt={"(":"(",")":")","[":"\\lbrack","]":"\\rbrack","\u27E6":"\\llbrack","\u27E7":"\\rrbrack","{":"\\lbrace","}":"\\rbrace","<":"\\langle",">":"\\rangle","\u2016":"\\Vert","\\":"\\backslash","\u2308":"\\lceil","\u2309":"\\rceil","\u230A":"\\lfloor","\u230B":"\\rfloor","\u231C":"\\ulcorner","\u231D":"\\urcorner","\u231E":"\\llcorner","\u231F":"\\lrcorner","\u23B0":"\\lmoustache","\u23B1":"\\rmoustache"};function Ft(e,n,t){let i=(t?.minPrec??0)>=19,r=S(n);if(r&&r.includes("_")){let a=r.indexOf("_"),u=r.substring(0,a),l=r.substring(a+1),c=parseInt(l,10),f=!isNaN(c)&&String(c)===l?c:l,m=f!==""&&(typeof f=="number"||typeof f=="string"&&f.length===1);(e.getSymbolType(u).matches("indexed_collection")||!i&&m)&&(n=["Subscript",u,f])}if(y(n)==="InvisibleOperator"&&Z(n)===2&&y(p(n,2))==="Delimiter"){let a=S(p(n,1));if(!a)return null;let u=e.parseExpression({...t??{},minPrec:20});if(u===null)return null;let l=p(p(n,2),1),c=[];return y(l)==="Sequence"?c=[...I(l)]:l&&(c=[l]),["Assign",a,["Function",u,...c??[]]]}if(y(n)==="Subscript"&&S(p(n,1))){let a=S(p(n,1));if(!e.getSymbolType(a).matches("indexed_collection")){let c=p(n,2),f=(c!==null&&typeof c=="string"?c:void 0)??(c!==null&&typeof c=="number"?String(c):void 0);if(f&&i){let m=e.parseExpression({...t??{},minPrec:20});return m===null?null:["Assign",a+"_"+f,m]}}let u=e.parseExpression({...t??{},minPrec:20});if(u===null)return null;let l=p(n,2);return B(l)!==null?["Assign",n,u]:S(l)?["Assign",n,u]:["Assign",n,u]}let s=y(n);if(s){let a=I(n),u=e.parseExpression({...t??{},minPrec:20});return u===null?null:["Assign",s,["Function",u,...a]]}if(!S(n))return null;let o=e.parseExpression({...t??{},minPrec:20});return o===null?null:["Assign",n,o]}function Wi(e){let n=e.parseTabular();if(!n)return["List"];if(n.every(i=>{if(i.length!==1)return!1;let r=y(i[0]);return qi(r)||zi(r)}))return["List",...n.map(i=>i[0])];let t=[];for(let i of n)if(i.length===1)t.push("True"),t.push(i[0]);else if(i.length===2){let r=B(i[1]);t.push(r?"True":ji(i[1])??"True"),t.push(i[0])}return["Which",...t]}function be(e,n){let t=e.index;if(!e.match("<{>"))return e.index=t,!1;for(;e.match("<space>"););for(let i=0;i<n.length;i++)if(n[i]===" "){if(!e.match("<space>"))return e.index=t,!1;for(;e.match("<space>"););}else{if(e.peek!==n[i])return e.index=t,!1;e.nextToken()}for(;e.match("<space>"););return e.match("<}>")?!0:(e.index=t,!1)}function fn(e,n){let t=e.index;if(e.skipVisualSpace(),e.match("\\text")){if(be(e,n))return!0;e.index=t}let i=e.index,r=e.parseSymbol();return r!==null&&S(r)===n?!0:(e.index=i,!1)}function pn(e,n){let t=e.index,i=fn(e,n);return e.index=t,i}function So(e,n){e.skipVisualSpace();let t=e.parseExpression({minPrec:0,condition:s=>pn(s,"then")});if(t===null||!fn(e,"then"))return null;e.skipVisualSpace();let i=e.parseExpression({minPrec:0,condition:s=>pn(s,"else")});if(i===null||!fn(e,"else"))return null;e.skipVisualSpace();let r=e.parseExpression(n)??"Nothing";return["If",t,i,r]}function Mo(e,n){let t=e.parseExpression({minPrec:0,condition:a=>pn(a,"from")}),i=t?S(t):null;if(!i||!fn(e,"from"))return null;let r=e.parseExpression({minPrec:0,condition:a=>pn(a,"to")});if(r===null||!fn(e,"to"))return null;let s=e.parseExpression({minPrec:0,condition:a=>pn(a,"do")});return s===null||!fn(e,"do")?null:["Loop",e.parseExpression(n)??"Nothing",["Element",i,["Range",r,s]]]}function Co(e,n,t){let i={minPrec:21,condition:s=>{if(t?.condition?.(s))return!0;let o=s.index;s.skipVisualSpace();let a=s.peek===",";return s.index=o,!!(a||pn(s,"where")||pn(s,"with"))}},r=[];do{e.skipVisualSpace();let s=e.parseExpression(i);if(s===null)break;let o=y(s);if(o!=="Equal"&&o!=="Assign")return null;let a=p(s,1),u=p(s,2);if(!a||!u)return null;r.push(["Element",a,u]),e.skipVisualSpace()}while(e.match(","));return r.length===0?null:["Loop",n,...r]}function wo(e,n,t){let i={minPrec:21,condition:a=>{if(t?.condition?.(a))return!0;let u=a.index;a.skipVisualSpace();let l=a.peek===",";return a.index=u,l}},r=[];do{e.skipVisualSpace();let a=e.parseExpression(i);if(!a)break;r.push(a),e.skipVisualSpace()}while(e.match(","));if(r.length===0)return null;let s=e.index;if(fn(e,"for")){let a=Co(e,n,t);if(a){let u=[];for(let l of r){let c=Qi(l);y(c)==="Assign"&&u.push(["Declare",p(c,1)]),u.push(c)}return u.push(a),["Block",...u]}e.index=s}let o=[];for(let a of r){let u=Qi(a);y(u)==="Assign"&&o.push(["Declare",p(u,1)]),o.push(u)}return o.push(n),["Block",...o]}function zl(e){let n=[];for(let t of e){let i=Qi(t);y(i)==="Assign"&&n.push(["Declare",p(i,1)]),n.push(i)}return["Block",...n]}function Qi(e){if(y(e)!=="Assign")return e;let n=p(e,1);if(y(n)!=="Subscript")return e;let t=S(p(n,1));if(!t)return e;let i=p(n,2),r=(typeof i=="string"?i:void 0)??(typeof i=="number"?String(i):void 0);return r?["Assign",`${t}_${r}`,p(e,2)??"Nothing"]:e}function Xi(...e){return(n,t)=>{if(!S(t)&&y(t)!=="List")return null;let i=null;return e.length===0&&(i=n.parseGroup()),i??=n.parseExpression({minPrec:0}),i===null||e.length>0&&!n.matchAll(e)||B(i)!==null?null:(y(i)==="Delimiter"&&(i=p(i,1)??"Nothing"),y(i)==="Sequence"?["At",t,...I(i)]:["At",t,i])}}var Kn=[["alpha","\\alpha",945],["beta","\\beta",946],["gamma","\\gamma",947],["delta","\\delta",948],["epsilon","\\epsilon",949],["epsilonSymbol","\\varepsilon",1013],["zeta","\\zeta",950],["eta","\\eta",951],["theta","\\theta",952],["thetaSymbol","\\vartheta",977],["iota","\\iota",953],["kappa","\\kappa",954],["kappaSymbol","\\varkappa",1008],["lambda","\\lambda",955],["mu","\\mu",956],["nu","\\nu",957],["xi","\\xi",958],["omicron","\\omicron",959],["pi","\\pi",960],["piSymbol","\\varpi",982],["rho","\\rho",961],["rhoSymbol","\\varrho",1009],["sigma","\\sigma",963],["finalSigma","\\varsigma",962],["tau","\\tau",964],["phi","\\phi",981],["phiLetter","\\varphi",966],["upsilon","\\upsilon",965],["chi","\\chi",967],["psi","\\psi",968],["omega","\\omega",969],["Alpha","\\Alpha",913],["Beta","\\Beta",914],["Gamma","\\Gamma",915],["Delta","\\Delta",916],["Epsilon","\\Epsilon",917],["Zeta","\\Zeta",918],["Eta","\\Eta",919],["Theta","\\Theta",920],["Iota","\\Iota",921],["Kappa","\\Kappa",922],["Lambda","\\Lambda",923],["Mu","\\Mu",924],["Nu","\\Nu",925],["Xi","\\Xi",926],["Omicron","\\Omicron",927],["Rho","\\Rho",929],["Sigma","\\Sigma",931],["Tau","\\Tau",932],["Phi","\\Phi",934],["Upsilon","\\Upsilon",933],["Chi","\\Chi",935],["Psi","\\Psi",936],["Omega","\\Omega",937],["digamma","\\digamma",989],["aleph","\\aleph",8501],["bet","\\beth",8502],["gimel","\\gimel",8503],["dalet","\\daleth",8504],["ell","\\ell",8499],["turnedCapitalF","\\Finv",8498],["turnedCapitalG","\\Game",8513],["weierstrass","\\wp",8472],["eth","\\eth",240],["invertedOhm","\\mho",8487],["hBar","\\hbar",295],["hSlash","\\hslash",8463],["blackClubSuit","\\clubsuit",9827],["whiteHeartSuit","\\heartsuit",9825],["blackSpadeSuit","\\spadesuit",9824],["whiteDiamondSuit","\\diamondsuit",9826],["sharp","\\sharp",9839],["flat","\\flat",9837],["natural","\\natural",9838]],Ro=[...Kn.map(([e,n,t])=>({kind:"symbol",name:e,latexTrigger:[n],parse:e})),...Kn.map(([e,n,t])=>({kind:"symbol",latexTrigger:[String.fromCodePoint(t)],parse:e}))];var Do=[{name:"To",latexTrigger:["\\to"],kind:"infix",precedence:270},{latexTrigger:["-",">"],kind:"infix",precedence:270,parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:270});return i===null?null:["To",n,i]}}];function Ce(e,n,t){if(z(e))return null;let i,r=y(e);if(r==="Delimiter"){let l=B(p(e,2));if(l!==","&&l!=="(,)"&&l!=="[,]")return null;let c=p(e,1);y(c)==="Sequence"?i=[...I(c)]:i=c?[c]:[]}else if(r==="Sequence")i=[...I(e)];else return null;if(i.length!==2)return null;let[s,o]=i;return["Interval",n?["Open",s]:s,t?["Open",o]:o]}var Po=new Set(["Less","LessEqual","Greater","GreaterEqual","Equal","NotEqual","And","Or","Not"]),Lo=[{name:"AlgebraicNumbers",latexTrigger:"\\overline\\Q"},{latexTrigger:"\\bar\\Q",parse:"AlgebraicNumbers"},{name:"ComplexNumbers",latexTrigger:["\\C"]},{latexTrigger:"\\mathbb{C}",parse:"ComplexNumbers"},{name:"ImaginaryNumbers",latexTrigger:["\\imaginaryI","\\R"]},{name:"EmptySet",latexTrigger:["\\emptyset"]},{latexTrigger:["\\varnothing"],parse:"EmptySet"},{name:"Integers",latexTrigger:["\\Z"]},{latexTrigger:"\\mathbb{Z}",parse:"Integers"},{name:"RationalNumbers",latexTrigger:["\\Q"]},{latexTrigger:"\\mathbb{Q}",parse:"RationalNumbers"},{name:"RealNumbers",latexTrigger:["\\R"]},{latexTrigger:"\\mathbb{R}",parse:"RealNumbers"},{name:"TranscendentalNumbers",latexTrigger:"\\R-\\bar\\Q"},{latexTrigger:"\\R\\backslash\\bar\\Q",parse:"TranscendentalNumbers"},{name:"NegativeNumbers",latexTrigger:"\\R_{<0}"},{latexTrigger:"\\R^-",parse:"NegativeNumbers"},{latexTrigger:"\\R^{-}",parse:"NegativeNumbers"},{latexTrigger:"\\R^-",parse:"NegativeNumbers"},{latexTrigger:"\\R_-",parse:"NegativeNumbers"},{latexTrigger:"\\R_{-}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{\\lt}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{<}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{\\lt0}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{<0}",parse:"NegativeNumbers"},{name:"NonPositiveNumbers",latexTrigger:"\\R_{\\le0}"},{latexTrigger:"\\R^{\\leq0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{-0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{\\leq}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{0-}",parse:"NonPositiveNumbers"},{name:"PositiveNumbers",latexTrigger:"\\R_{>0}"},{latexTrigger:"\\R^+",parse:"PositiveNumbers"},{latexTrigger:"\\R^{+}",parse:"PositiveNumbers"},{latexTrigger:"\\R_+",parse:"PositiveNumbers"},{latexTrigger:"\\R_{+}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{\\gt}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{\\gt 0}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{>}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{>0}",parse:"PositiveNumbers"},{name:"NonNegativeNumbers",latexTrigger:"\\R_{\\geq0}"},{latexTrigger:"\\R^{0+}",parse:"NonNegativeNumbers"},{latexTrigger:"\\R^{\\geq}",parse:"NonNegativeNumbers"},{name:"ExtendedRealNumbers",latexTrigger:"\\overline\\R"},{latexTrigger:"\\bar\\R",parse:"ExtendedRealNumbers"},{name:"NegativeIntegers",latexTrigger:"\\Z_{<0}"},{latexTrigger:"\\Z_{\\lt0}",parse:"NegativeIntegers"},{latexTrigger:"\\Z^-",parse:"NegativeIntegers"},{latexTrigger:"\\Z^{-}",parse:"NegativeIntegers"},{latexTrigger:"\\Z_-",parse:"NegativeIntegers"},{latexTrigger:"\\Z_{-}",parse:"NegativeIntegers"},{latexTrigger:"\\Z^{\\lt}",parse:"NegativeIntegers"},{name:"NonPositiveIntegers",latexTrigger:"\\Z_{\\le0}"},{latexTrigger:"\\Z_{\\leq0}",parse:"NonPositiveIntegers"},{latexTrigger:"\\Z_{<0}",parse:"NonPositiveIntegers"},{name:"PositiveIntegers",latexTrigger:"\\N^*"},{latexTrigger:"\\Z_{>0}",parse:"PositiveIntegers"},{latexTrigger:"\\Z_{\\gt0}",parse:"PositiveIntegers"},{latexTrigger:"\\Z^{+}",parse:"PositiveIntegers"},{latexTrigger:"\\Z_+",parse:"PositiveIntegers"},{latexTrigger:"\\Z_{+}",parse:"PositiveIntegers"},{latexTrigger:"\\Z^{\\gt}",parse:"PositiveIntegers"},{latexTrigger:"\\Z^{\\gt0}",parse:"PositiveIntegers"},{latexTrigger:"\\N^+",parse:"PositiveIntegers"},{latexTrigger:"\\N^{+}",parse:"PositiveIntegers"},{latexTrigger:"\\N^*",parse:"PositiveIntegers"},{latexTrigger:"\\N^{*}",parse:"PositiveIntegers"},{latexTrigger:"\\N^\\star",parse:"PositiveIntegers"},{latexTrigger:"\\N^{\\star}",parse:"PositiveIntegers"},{latexTrigger:"\\N_1",parse:"PositiveIntegers"},{latexTrigger:"\\N_{1}",parse:"PositiveIntegers"},{name:"NonNegativeIntegers",latexTrigger:["\\N"]},{latexTrigger:"\\Z^{+0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{\\geq}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{\\geq0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{0+}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{N}",parse:"NonNegativeIntegers"},{latexTrigger:"\\N_0",parse:"NonNegativeIntegers"},{latexTrigger:"\\N_{0}",parse:"NonNegativeIntegers"},{name:"ExtendedIntegers",latexTrigger:"\\overline\\Z"},{latexTrigger:"\\bar\\Z",parse:"ExtendedIntegers"},{name:"ExtendedRationalNumbers",latexTrigger:"\\overline\\Q"},{latexTrigger:"\\bar\\Q",parse:"ExtendedRationalNumbers"},{name:"ExtendedComplexNumbers",latexTrigger:"\\overline\\C"},{latexTrigger:"\\bar\\C",parse:"ExtendedComplexNumbers"},{latexTrigger:["^","\\complement"],kind:"postfix",parse:(e,n)=>["Complement",n]},{name:"Complement",latexTrigger:["^","<{>","\\complement","<}>"],kind:"postfix",serialize:(e,n)=>N([e.serialize(p(n,1)),"^\\complement"])},{name:"Intersection",latexTrigger:["\\cap"],kind:"infix",precedence:350},{name:"Interval",serialize:Fo},{kind:"matchfix",openTrigger:["["],closeTrigger:[")"],parse:(e,n)=>Ce(n,!1,!0)},{kind:"matchfix",openTrigger:["\\lbrack"],closeTrigger:["\\rparen"],parse:(e,n)=>Ce(n,!1,!0)},{kind:"matchfix",openTrigger:["\\lbrack"],closeTrigger:[")"],parse:(e,n)=>Ce(n,!1,!0)},{kind:"matchfix",openTrigger:["["],closeTrigger:["\\rparen"],parse:(e,n)=>Ce(n,!1,!0)},{kind:"matchfix",openTrigger:["("],closeTrigger:["]"],parse:(e,n)=>Ce(n,!0,!1)},{kind:"matchfix",openTrigger:["\\lparen"],closeTrigger:["\\rbrack"],parse:(e,n)=>Ce(n,!0,!1)},{kind:"matchfix",openTrigger:["\\lparen"],closeTrigger:["]"],parse:(e,n)=>Ce(n,!0,!1)},{kind:"matchfix",openTrigger:["("],closeTrigger:["\\rbrack"],parse:(e,n)=>Ce(n,!0,!1)},{kind:"matchfix",openTrigger:["]"],closeTrigger:["["],parse:(e,n)=>Ce(n,!0,!0)},{kind:"matchfix",openTrigger:["\\rbrack"],closeTrigger:["\\lbrack"],parse:(e,n)=>Ce(n,!0,!0)},{name:"Multiple",serialize:Fo},{name:"Union",latexTrigger:["\\cup"],kind:"infix",precedence:350},{name:"Divides",latexTrigger:["\\mid"],kind:"infix",precedence:160},{name:"Set",kind:"matchfix",openTrigger:"{",closeTrigger:"}",parse:(e,n)=>{if(z(n))return"EmptySet";y(n)=="Delimiter"&&B(p(n,2))===","&&(n=p(n,1));let t=y(n);if(t==="Divides"){let i=p(n,1),r=p(n,2);if(i!==null&&r!==null)return["Set",i,["Condition",r]]}if(t==="Colon"){let i=p(n,1),r=p(n,2);if(i!==null&&r!==null){let s=y(i);return s!==null&&Po.has(s)?["Which",i,r]:["Set",i,["Condition",r]]}}if(t==="Sequence"){let i=I(n),r=i.filter(o=>y(o)==="Colon");if(r.length>0&&r.every(o=>{let a=p(o,1),u=a!==null?y(a):null;return u!==null&&Po.has(u)})){let o=[];for(let a=0;a<i.length;a++){let u=i[a];if(y(u)==="Colon"){let l=p(u,1),c=p(u,2);if(l===null||c===null)return["Set",...i];o.push(l,c)}else{if(a!==i.length-1)return["Set",...i];o.push("True",u)}}return["Which",...o]}return["Set",...i]}return["Set",n]},serialize:(e,n)=>{if(Z(n)===2&&y(p(n,2))==="Condition"){let t=p(n,2);return N(["\\lbrace",e.serialize(p(n,1)),"\\mid",e.serialize(p(t,1)),"\\rbrace"])}return N(["\\lbrace",I(n).map(t=>e.serialize(t)).join(", "),"\\rbrace"])}},{name:"SetMinus",latexTrigger:["\\setminus"],kind:"infix",precedence:650},{name:"SymmetricDifference",latexTrigger:["\\triangle"],kind:"infix",precedence:P},{latexTrigger:["\\ni"],kind:"infix",associativity:"none",precedence:160,parse:(e,n,t)=>{let i=e.parseExpression(t);return i===null?null:["Element",i,n]}},{name:"Element",latexTrigger:["\\in"],kind:"infix",precedence:240},{name:"NotElement",latexTrigger:["\\notin"],kind:"infix",precedence:240},{name:"NotSubset",latexTrigger:["\\nsubset"],kind:"infix",associativity:"none",precedence:240},{name:"NotSuperset",latexTrigger:["\\nsupset"],kind:"infix",associativity:"none",precedence:240},{name:"NotSubsetNotEqual",latexTrigger:["\\nsubseteq"],kind:"infix",associativity:"none",precedence:240},{name:"NotSupersetNotEqual",latexTrigger:["\\nsupseteq"],kind:"infix",associativity:"none",precedence:240},{name:"SquareSubset",latexTrigger:["\\sqsubset"],kind:"infix",associativity:"none",precedence:265},{name:"SquareSubsetEqual",latexTrigger:["\\sqsubseteq"],kind:"infix",associativity:"none",precedence:265},{name:"SquareSuperset",latexTrigger:["\\sqsupset"],kind:"infix",associativity:"none",precedence:265},{name:"SquareSupersetEqual",latexTrigger:["\\sqsupseteq"],kind:"infix",associativity:"none",precedence:265},{name:"Subset",latexTrigger:["\\subset"],kind:"infix",associativity:"none",precedence:240},{latexTrigger:["\\subsetneq"],kind:"infix",associativity:"none",precedence:240,parse:"Subset"},{latexTrigger:["\\varsubsetneqq"],kind:"infix",associativity:"none",precedence:240,parse:"Subset"},{name:"SubsetEqual",latexTrigger:["\\subseteq"],kind:"infix",associativity:"none",precedence:240},{name:"Superset",latexTrigger:["\\supset"],kind:"infix",associativity:"none",precedence:240},{latexTrigger:["\\supsetneq"],kind:"infix",associativity:"none",precedence:240,parse:"Superset"},{latexTrigger:["\\varsupsetneq"],kind:"infix",associativity:"none",precedence:240,parse:"Superset"},{name:"SupersetEqual",latexTrigger:["\\supseteq"],kind:"infix",associativity:"none",precedence:240}];function Fo(e,n){if(n===null)return"";let t=y(n);if(!t)return"";if(t==="Range")return N(["\\mathopen\\lbrack",e.serialize(p(n,1)),", ",e.serialize(p(n,2)),"\\mathclose\\rbrack"]);if(t==="Interval"){let r=p(n,1),s=p(n,2),o=!1,a=!1;return y(r)==="Open"&&(r=p(r,1),o=!0),y(s)==="Open"&&(s=p(s,1),a=!0),N([o?"\\lparen":"\\lbrack",e.serialize(r),", ",e.serialize(s),a?"\\rparen":"\\rbrack"])}let i=e.numericSetStyle(n,e.level);return""}function An(e,n,t){e.indexOf("#1")<0&&e.indexOf("#2")<0&&(e=`#1 ${e} #2`);let i=e.split(/(#\d+)/).filter(r=>r.trim()!=="").map(r=>r.trim());return N(i.map(r=>{switch(r){case"#1":return n;case"#2":return t;default:return r}}))}function Ot(e,n){if(n==="none")return e;if(n==="0...360"){let t=e%360;return(t<0?t+360:t)||0}if(n==="-180...180"){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t||0}return e}function Gl(e){let n=e<0?-1:1,t=Math.abs(e),i=Math.floor(t),r=(t-i)*60,s=Math.floor(r),o=(r-s)*60,a=Math.round(o*1e3)/1e3,u=s,l=i;return a>=60&&(a=0,u++),u>=60&&(u=0,l++),{deg:n*l||0,min:n*u||0,sec:a===0?0:n*a}}function Bt(e){let{deg:n,min:t,sec:i}=Gl(e),r=`${n}\xB0`;if(Math.abs(i)>.001){let s=i%1===0?i.toString():i.toFixed(2);r+=`${Math.abs(t)}'${Math.abs(Number(s))}"`}else Math.abs(t)>0?r+=`${Math.abs(t)}'`:r+=`0'0"`;return r}function jl(e){if(y(e)!=="Multiply")return[[],[]];let n=[],t=[];for(let i of I(e))if(y(i)==="Power"){let r=p(i,1),s=p(i,2);if(y(s)==="Negate"){let o=p(s,1);r&&o&&t.push(["Power",r,o])}else{let o=R(s)??NaN;o===-1?r&&t.push(r):o<0?r&&t.push(["Power",r,-o]):n.push(i)}}else if(y(i)==="Rational"&&Z(i)===2||y(i)==="Divide"){let r=p(i,1),s=p(i,2);R(r)!==1&&n.push(r),R(s)!==1&&t.push(s)}else{let r=Mn(i);r!==null?(r[0]!==1&&n.push(r[0]),t.push(r[1])):n.push(i)}return[n,t]}function Ul(e){let n=e.parseOptionalGroup(),t=e.parseGroup()??e.parseToken();return z(t)?n!==null?["Root",_n,j(n)]:["Sqrt",_n]:n!==null?["Root",t,n]:["Sqrt",t]}function Hl(e){if(typeof e=="number")return-e;if(typeof e=="string")return e.startsWith("-")?e.slice(1):e.startsWith("+")?"-"+e.slice(1):"-"+e;let n=e.num;return n.startsWith("-")?{num:n.slice(1)}:n.startsWith("+")?{num:"-"+n.slice(1)}:{num:"-"+n}}function nt(e,n,t,i){return t==null?"\\sqrt{}":(i=i??2,n==="solidus"?e.wrapShort(t)+"^{1/"+e.serialize(i)+"}":n==="quotient"?e.wrapShort(t)+"^{\\frac{1}{"+e.serialize(i)+"}}":R(i)===2?"\\sqrt{"+e.serialize(t)+"}":"\\sqrt["+e.serialize(i)+"]{"+e.serialize(t)+"}")}function Zl(e,n){e.level-=1;let t=y(n),i="",r=p(n,1);if(t==="Negate")i="-"+e.wrap(r,ee+1);else if(t==="Subtract"){i=e.wrap(r,ee);let s=p(n,2);if(s!==null){let o=e.wrap(s,ee);o[0]==="-"?i+="+"+o.slice(1):o[0]==="+"?i+="-"+o.slice(1):i=i+"-"+o}}else if(t==="Add"){if(e.options.prettify&&Z(n)===2&&e.options.invisiblePlus!=="+"){let[a,u]=[p(n,1),p(n,2)],[l,c]=[a,u],f=R(l),m=Mn(c);if((f===null||m===null)&&([l,c]=[u,a],f=R(l),m=Mn(c)),f!==null&&m!==null&&isFinite(f)&&Number.isInteger(f)&&f>=0&&f<=1e3&&isFinite(m[0])&&isFinite(m[1])&&m[0]>0&&m[0]<=100&&m[1]<=100)return i=An(e.options.invisiblePlus,e.serialize(l),e.serialize(c)),e.level+=1,i}if(e.options.prettify&&Z(n)===2){let[a,u]=tt(r),[l,c]=tt(p(n,2));if(u<0&&c>0)return i=e.wrap(l,ee)+"-"+e.wrap(a,ee),e.level+=1,i}i=e.serialize(r);let s=Z(n)+1,o=I(n);for(let a=2;a<s;a++)if(r=o[a-1],e.options.prettify){let[u,l]=tt(r),c=e.wrap(u,ee);l>0?c.startsWith("+")||c.startsWith("-")?i+=c:i+="+"+c:c.startsWith("+")?i+="-"+c.slice(1):c.startsWith("-")?i+="+"+c.slice(1):i+="-"+c}else{let u=e.wrap(r,ee);u[0]==="-"||u[0]==="+"?i+=u:i+="+"+u}}return e.level+=1,i}function Go(e,n){if(n===null)return"";e.level-=1;let t="";if(e.options.prettify===!0){let[u,l]=jl(n);l.length>0&&(l.length===1&&l[0]===1?u.length===0?t="1":u.length===1?t=e.serialize(u[0]):t=Go(e,["Multiply",...u]):t=e.serialize(["Divide",u.length===1?u[0]:["Multiply",...u],l.length===1?l[0]:["Multiply",...l]]))}if(t)return e.level+=1,t;let i=!1,r=null,s=Z(n)+1,o=I(n);e.options.prettify===!0&&o.length===2&&ln(o[1])&&!ln(o[0])&&(o=[o[1],o[0]]);let a=!1;for(let u=1;u<s;u++){if(r=o[u-1],r===null)continue;let l;if(ln(r)){l=e.serialize(r),l==="-1"&&!t?(t="",i=!i):(l[0]==="-"&&(l=l.slice(1),i=!i),t?t=An(e.options.multiply,t,l):t=l),a=!0;continue}if(y(r)==="Power"){let c=Mn(p(r,2));if(c!=null){let[f,m]=c;if(f===1&&m!==null){t+=nt(e,e.rootStyle(r,e.level),p(r,1),m),a=!1;continue}}}if(y(r)==="Power"&&!isNaN(R(p(r,1))??NaN)){l=e.serialize(r),t?t=An(e.options.multiply,t,l):t=l,a=!0;continue}if(y(r)==="Negate"&&(r=p(r,1),i=!i),l=e.wrap(r,ge),!t)t=l;else{let c=y(r);a&&(c==="Divide"||c==="Rational")?t=An(e.options.multiply,t,l):e.options.invisibleMultiply?t=An(e.options.invisibleMultiply,t,l):t=N([t,l])}a=!1}return e.level+=1,i?"-"+t:t}function Vt(e){let n=e.parseGroup(),t=null;if(n===null?(n=e.parseToken(),t=e.parseToken()):t=e.parseGroup(),n=j(n),t=j(t),y(n)==="PartialDerivative"&&(y(t)==="PartialDerivative"||y(t)==="Multiply"&&y(p(t,1))==="PartialDerivative")){let s=p(n,3)??null,o=p(n,1);o==null&&(o=j(e.parseExpression()));let a=[];if(y(t)==="Multiply"){for(let u of I(t))if(y(u)==="PartialDerivative"){let l=p(u,2);l&&a.push(l)}}else{let u=p(t,2);u&&a.push(u)}return a.length>1&&(a=["List",...a]),["PartialDerivative",o,...a,s===null?1:s]}let i=S(n);if(i==="d"||i==="d_upright"||i==="differentialD"){let s=[],o=a=>{if(!a)return;let u=S(a);if(u&&u!=="d"&&u!=="d_upright"&&u!=="differentialD"){s.push(a);return}let l=y(a);if(l==="Sequence"||l==="Multiply"||l==="InvisibleOperator")for(let c of I(a))o(c)};if(o(t),s.length===0){let a=S(t);a&&a.length>1&&a[0]==="d"&&s.push(a.slice(1))}if(s.length>0)return["D",j(e.parseExpression()),...s]}return["Divide",n,t]}function Oo(e,n){if(n===null)return"";let t=j(p(n,1)),i=j(p(n,2)),r=e.options.prettify?e.fractionStyle(n,e.level):"quotient";if(r==="inline-solidus"||r==="nice-solidus"){let u=e.wrapShort(t),l=e.wrapShort(i);return r==="inline-solidus"?`${u}/${l}`:`{}^{${u}}\\!\\!/\\!{}_{${l}}`}else{if(r==="reciprocal")return R(t)===1?e.wrap(i)+"^{-1}":e.wrap(t)+e.wrap(i)+"^{-1}";if(r==="factor")return R(i)===1?e.wrap(t):"\\frac{1}{"+e.serialize(i)+"}"+e.wrapString(e.serialize(t),e.groupStyle(n,1))}let s="\\frac";r==="block-quotient"?s="\\dfrac":r==="inline-quotient"&&(s="\\tfrac");let o=e.serialize(t),a=e.serialize(i);return`${s}{${o}}{${a}}`}function Ki(e,n){if(!n)return"";let t=y(n),i=j(p(n,1));if(t==="Sqrt")return nt(e,e.rootStyle(n,e.level-1),i,2);let r=j(p(n,2));if(t==="Root")return nt(e,e.rootStyle(n,e.level-1),i,r);if(e.options.prettify){let o=R(r)??1;if(o===-1)return e.serialize(["Divide","1",i]);if(o<0)return e.serialize(["Divide","1",["Power",i,-o]]);if(y(r)==="Divide"||y(r)==="Rational"){let a=R(p(r,1)),u=R(p(r,2));if(a===1){let l=e.rootStyle(n,e.level);return nt(e,l,i,p(r,2))}if(a===-1)return u===2?e.serialize(["Divide","1",["Sqrt",i]]):e.serialize(["Divide","1",["Root",i,p(r,2)??_n]]);if(u===2)return`${e.serialize(["Sqrt",i])}^{${e.serialize(p(r,1))}}`}else if(y(r)==="Power"&&R(p(r,2))===-1){let a=e.rootStyle(n,e.level);return nt(e,a,i,p(r,1))}}let s=o=>o.startsWith("-")?e.wrapString(o,"normal"):o;if(y(i)==="Power"){let o=p(i,1),a=p(i,2),u=s(e.wrapShort(o)),l=e.wrapShort(a);return`
7
- ${u}^{${In("^",l,e.serialize(r))}}`}return In("^",s(e.wrapShort(i)),e.serialize(r))}function et(e,n){e.skipSpace();let t=e.index,i=e.parseNumber(),r=null,s=null;if(i!==null&&(e.match("'")||e.match("\\prime"))){r=R(i),e.skipSpace();let u=e.index,l=e.parseNumber();l!==null&&(e.match('"')||e.match("\\doubleprime"))?s=R(l):e.index=u}else return e.index=t,["Degrees",n];let o=R(n);if(o!==null&&r!==null){let u=o+r/60;return s!==null&&(u+=s/3600),["Degrees",u]}let a=[["Quantity",n,"deg"]];return a.push(["Quantity",i,"arcmin"]),s!==null&&a.push(["Quantity",s,"arcsec"]),["Add",...a]}var jo=[{name:"CatalanConstant",symbolTrigger:"G"},{name:"GoldenRatio",latexTrigger:"\\varphi"},{name:"EulerGamma",latexTrigger:"\\gamma"},{name:"Degrees",latexTrigger:["\\degree"],kind:"postfix",precedence:880,parse:(e,n)=>et(e,n),serialize:(e,n)=>{let t=e.options,i=p(n,1);if(t.dmsFormat||t.angleNormalization&&t.angleNormalization!=="none"){let r=R(i);if(r!==null){let s=r;return t.angleNormalization&&t.angleNormalization!=="none"&&(s=Ot(s,t.angleNormalization)),t.dmsFormat?Bt(s):`${s}\xB0`}}return N([e.serialize(i),"\\degree"])}},{latexTrigger:["\\degree"],kind:"postfix",precedence:880,parse:(e,n)=>et(e,n)},{latexTrigger:["^","<{>","\\circ","<}>"],kind:"postfix",parse:(e,n)=>et(e,n)},{latexTrigger:["^","\\circ"],kind:"postfix",parse:(e,n)=>et(e,n)},{latexTrigger:["\xB0"],kind:"postfix",precedence:880,parse:(e,n)=>et(e,n)},{latexTrigger:["\\ang"],parse:e=>{let n=e.parseGroup();return n===null?["Degrees"]:["Degrees",n]}},{name:"DMS",serialize:(e,n)=>{let t=R(p(n,1)),i=R(p(n,2)),r=R(p(n,3));if(t!==null){let o=i??0,a=r??0,u=`${t}\xB0`;return(o!==0||a!==0)&&(u+=`${o}'`),a!==0&&(u+=`${a}"`),u}let s=[];for(let o of[1,2,3]){let a=p(n,o);a!==null&&s.push(e.serialize(a))}return`\\operatorname{DMS}(${s.join(", ")})`}},{latexTrigger:["\\infty"],parse:"PositiveInfinity"},{latexTrigger:["\\infin"],parse:"PositiveInfinity"},{name:"PositiveInfinity",serialize:e=>e.options.positiveInfinity},{name:"NegativeInfinity",serialize:e=>e.options.negativeInfinity},{name:"ComplexInfinity",latexTrigger:["\\tilde","\\infty"],serialize:"\\tilde\\infty"},{latexTrigger:["\\tilde","<{>","\\infty","<}>"],parse:"ComplexInfinity"},{name:"Pi",kind:"symbol",latexTrigger:["\\pi"]},{latexTrigger:["\u03C0"],parse:"Pi"},{name:"ExponentialE",latexTrigger:["\\exponentialE"],parse:"ExponentialE",serialize:"\\exponentialE"},{latexTrigger:"\\operatorname{e}",parse:"ExponentialE"},{latexTrigger:"\\mathrm{e}",parse:"ExponentialE"},{kind:"function",symbolTrigger:"exp",parse:e=>{let n=e.parseArguments("implicit");return n===null?"Exp":["Exp",...n]}},{latexTrigger:"\\exp",parse:e=>{let n=e.parseArguments("implicit");return n===null?"Exp":["Exp",...n]}},{name:"ImaginaryUnit",latexTrigger:["\\imaginaryI"]},{latexTrigger:"\\operatorname{i}",parse:"ImaginaryUnit"},{latexTrigger:"\\mathrm{i}",parse:"ImaginaryUnit"},{name:"Abs",kind:"matchfix",openTrigger:"|",closeTrigger:"|",parse:(e,n)=>z(n)?null:["Abs",n]},{kind:"matchfix",openTrigger:["\\vert"],closeTrigger:["\\vert"],parse:(e,n)=>z(n)?null:["Abs",n]},{symbolTrigger:"abs",kind:"function",parse:"Abs"},{name:"Add",latexTrigger:["+"],kind:"infix",associativity:"any",precedence:ee,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:ee});if(i===null)return null;if(y(i)==="Negate"){let r=p(i,1);if(ln(r))return wn("Add",n,Hl(r))}return wn("Add",n,i)},serialize:Zl},{kind:"prefix",latexTrigger:["+"],precedence:ee,parse:(e,n)=>e.parseExpression({...n,minPrec:400})},{name:"Ceil",kind:"matchfix",openTrigger:"\\lceil",closeTrigger:"\\rceil",parse:(e,n)=>z(n)?null:["Ceil",n]},{kind:"matchfix",openTrigger:["\u2308"],closeTrigger:["\u2309"],parse:(e,n)=>z(n)?null:["Ceil",n]},{symbolTrigger:"ceil",kind:"function",parse:"Ceil"},{name:"Chop",symbolTrigger:"chop",kind:"function",parse:"Chop"},{name:"Complex",precedence:ee-1,serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=R(p(n,2));if(i===0)return t;let r=i===1?"\\imaginaryI":i===-1?"-\\imaginaryI":N([e.serialize(p(n,2)),"\\imaginaryI"]);return R(p(n,1))===0?r:i!==null&&i<0?N([t,r]):N([t,"+",r])}},{name:"Divide",latexTrigger:"\\frac",precedence:Ee,parse:Vt,serialize:Oo},{latexTrigger:"\\dfrac",precedence:Ee,parse:Vt},{latexTrigger:"\\tfrac",precedence:Ee,parse:Vt},{latexTrigger:"\\cfrac",precedence:Ee,parse:Vt},{kind:"infix",latexTrigger:"\\over",associativity:"none",precedence:Ee,parse:"Divide"},{latexTrigger:["\\/"],kind:"infix",associativity:"left",precedence:Ee,parse:"Divide"},{latexTrigger:["/"],kind:"infix",associativity:"left",precedence:Ee,parse:"Divide"},{latexTrigger:["\\div"],kind:"infix",associativity:"left",precedence:Ee,parse:"Divide"},{name:"Exp",serialize:(e,n)=>{let t=p(n,1);return S(t)||R(t)!==null?N(["\\exponentialE^{",e.serialize(t),"}"]):N(["\\exp",e.wrap(j(t))])}},{name:"Factorial",latexTrigger:["!"],kind:"postfix",precedence:Vi},{name:"Factorial2",latexTrigger:["!","!"],kind:"postfix",precedence:Vi},{name:"Floor",kind:"matchfix",openTrigger:"\\lfloor",closeTrigger:"\\rfloor",parse:(e,n)=>z(n)?null:["Floor",n]},{kind:"matchfix",openTrigger:["\u230A"],closeTrigger:["\u230B"],parse:(e,n)=>z(n)?null:["Floor",n]},{symbolTrigger:"floor",kind:"function",parse:"Floor"},{latexTrigger:["\\Gamma"],parse:"Gamma"},{latexTrigger:["\\zeta"],kind:"function",parse:"Zeta"},{latexTrigger:["\\Beta"],kind:"function",parse:"Beta"},{name:"LambertW",latexTrigger:["\\operatorname{W}"],kind:"function",serialize:(e,n)=>"\\operatorname{W}"+e.wrapArguments(n)},{name:"BesselJ",latexTrigger:["\\operatorname{J}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{J}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselJ",i]):"\\operatorname{J}"+e.wrapArguments(n)}},{name:"BesselY",latexTrigger:["\\operatorname{Y}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{Y}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselY",i]):"\\operatorname{Y}"+e.wrapArguments(n)}},{name:"BesselI",latexTrigger:["\\operatorname{I}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{I}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselI",i]):"\\operatorname{I}"+e.wrapArguments(n)}},{name:"BesselK",latexTrigger:["\\operatorname{K}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{K}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselK",i]):"\\operatorname{K}"+e.wrapArguments(n)}},{name:"AiryAi",latexTrigger:["\\operatorname{Ai}"],kind:"function",serialize:(e,n)=>"\\operatorname{Ai}"+e.wrapArguments(n)},{name:"AiryBi",latexTrigger:["\\operatorname{Bi}"],kind:"function",serialize:(e,n)=>"\\operatorname{Bi}"+e.wrapArguments(n)},{name:"GCD",latexTrigger:["\\gcd"],kind:"function"},{symbolTrigger:"gcd",kind:"function",parse:"GCD"},{symbolTrigger:"GCD",kind:"function",parse:"GCD"},{name:"Half",serialize:"\\frac12"},{name:"Lg",latexTrigger:["\\lg"],serialize:(e,n)=>"\\log_{10}"+e.wrapArguments(n),parse:e=>{let n=e.parseArguments("implicit");return n===null?"Lg":["Log",...n,10]}},{name:"Lb",latexTrigger:"\\lb",parse:e=>{let n=e.parseArguments("implicit");return n===null?"Log":["Log",n[0],2]}},{name:"Ln",latexTrigger:["\\ln"],parse:e=>zo("Ln",e),serialize:(e,n)=>"\\ln"+e.wrapArguments(n)},{name:"Log",latexTrigger:["\\log"],parse:e=>zo("Log",e),serialize:(e,n)=>{let[t,i]=I(n);return i?N(["\\log_{",e.serialize(i),"}",e.wrap(t)]):"\\log"+e.wrapArguments(n)}},{name:"LCM",latexTrigger:["\\lcm"],kind:"function"},{symbolTrigger:"lcm",kind:"function",parse:"LCM"},{symbolTrigger:"LCM",kind:"function",parse:"LCM"},{symbolTrigger:"max",kind:"function",parse:"Max",arguments:"implicit"},{symbolTrigger:"min",kind:"function",parse:"Min",arguments:"implicit"},{name:"Max",latexTrigger:"\\max",kind:"function",arguments:"implicit"},{name:"Min",latexTrigger:"\\min",kind:"function",arguments:"implicit"},{name:"Supremum",latexTrigger:"\\sup",kind:"function",arguments:"implicit"},{name:"Infimum",latexTrigger:"\\inf",kind:"function",arguments:"implicit"},{name:"Limit",latexTrigger:"\\lim",kind:"expression",parse:e=>{if(!e.match("_"))return null;let n=e.parseGroup();if(y(n)!=="To")return null;let t=e.parseExpression({minPrec:ge});return t?["Limit",["Function",t,p(n,1)],p(n,2)]:null},serialize:(e,n)=>{let t=p(n,1),i=p(t,2),r=p(n,2);return N(["\\lim_{",e.serialize(i),"\\to",e.serialize(r),"}",e.serialize(p(t,1))])}},{name:"MinusPlus",latexTrigger:["\\mp"],kind:"infix",associativity:"any",precedence:ze},{name:"Multiply",latexTrigger:["\\times"],kind:"infix",associativity:"any",precedence:ge,serialize:Go},{latexTrigger:["\\cdot"],kind:"infix",associativity:"any",precedence:ge,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:ge+2});return i===null?null:wn("Multiply",n,i)}},{latexTrigger:["*"],kind:"infix",associativity:"any",precedence:ge,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:ge+2});return i===null?["Multiply",n,_n]:wn("Multiply",n,i)}},{name:"Mod",latexTrigger:"\\bmod",kind:"infix",precedence:Ee,serialize:(e,n)=>{if(Z(n)!==2)return"";let t=e.serialize(p(n,1)),i=e.serialize(p(n,2));return N([t,"\\bmod",i])}},{latexTrigger:"\\mod",kind:"infix",precedence:Ee,parse:"Mod"},{latexTrigger:"\\operatorname{mod}",parse:"Mod"},{latexTrigger:"\\pmod",kind:"prefix",precedence:P,parse:e=>{let n=e.parseGroup()??e.parseToken();return["Mod",j(n)]}},{name:"Congruent",serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=e.serialize(p(n,2));if(p(n,3)===null)return N([t,"\\equiv",i]);let r=e.serialize(p(n,3));return N([t,"\\equiv",i,"\\pmod{",r,"}"])}},{name:"Negate",latexTrigger:["-"],kind:"prefix",precedence:Xn+1,parse:(e,n)=>{e.skipSpace();let t=e.parseExpression({...n,minPrec:Xn+3});return t===null?null:["Negate",t]}},{kind:"matchfix",openTrigger:"||",closeTrigger:"||",parse:(e,n)=>z(n)?null:["Norm",n]},{name:"Norm",kind:"matchfix",openTrigger:["\\left","\\Vert"],closeTrigger:["\\right","\\Vert"],parse:(e,n)=>z(n)?null:["Norm",n],serialize:(e,n)=>{let t=p(n,1);if(y(t)==="Matrix"){let i=p(t,1),r=p(t,2),s=r?["Matrix",i,{str:"\u2016\u2016"},r]:["Matrix",i,{str:"\u2016\u2016"}];return e.serialize(s)}return`\\left\\Vert ${e.serialize(t)}\\right\\Vert`}},{name:"PlusMinus",latexTrigger:["\\pm"],kind:"infix",associativity:"any",precedence:ze,serialize:(e,n)=>{let t=p(n,1);if(t===null)return"\\pm";if(Z(n)===1)return N(["\\pm",e.serialize(t)]);let i=p(n,2);return N([e.serialize(t),"\\pm",e.serialize(i)])}},{latexTrigger:["\\pm"],kind:"prefix",precedence:ze,parse:(e,n)=>{let t=e.parseExpression({...n,minPrec:400});return["PlusMinus",0,j(t)]}},{latexTrigger:["\\plusmn"],kind:"infix",associativity:"any",precedence:ze,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:400});return["PlusMinus",n,j(i)]}},{latexTrigger:["\\plusmn"],kind:"prefix",precedence:ze,parse:(e,n)=>{let t=e.parseExpression({...n,minPrec:400});return["PlusMinus",j(t)]}},{name:"Power",latexTrigger:["^"],kind:"infix",serialize:Ki},{latexTrigger:"\\prod",precedence:ge,name:"Product",parse:Vo("Product","Multiply",ge),serialize:qo("\\prod")},{latexTrigger:["*","*"],kind:"infix",associativity:"right",precedence:Xn,parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:Xn});return i===null?null:["Power",n,i]}},{name:"Rational",precedence:Ee,serialize:(e,n)=>n&&Z(n)===1?"\\operatorname{Rational}"+e.wrapArguments(n):Oo(e,n)},{name:"Reduce",serialize:(e,n)=>{let t=p(n,1);if(!t)return"";let i=p(n,2);return S(i)==="Add"?`\\sum ${e.serialize(t)}`:S(i)==="Multiply"?`\\prod ${e.serialize(t)}`:`\\operatorname{Reduce}\\left(${e.serialize(t)}, ${e.serialize(p(n,2))}\\right)`}},{name:"Root",serialize:Ki},{name:"Round",symbolTrigger:"round",kind:"function"},{name:"Square",precedence:720,serialize:(e,n)=>{let t=e.wrapShort(p(n,1));return(t.startsWith("-")?e.wrapString(t,"normal"):t)+"^2"}},{latexTrigger:["\\sum"],precedence:ee,name:"Sum",parse:Vo("Sum","Add",ge),serialize:qo("\\sum")},{name:"Heaviside",symbolTrigger:"Heaviside",kind:"function"},{name:"Sign",symbolTrigger:"sgn",kind:"function"},{name:"Sqrt",latexTrigger:["\\sqrt"],parse:Ul,serialize:Ki},{name:"Subtract",latexTrigger:["-"],kind:"infix",associativity:"left",precedence:ee+2,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:ee+3});return i===null?null:["Subtract",n,i]},serialize:(e,n)=>{let t=e.wrap(p(n,1),ee+2),i=e.wrap(p(n,2),ee+3);return N([t,"-",i])}},{name:"Distance",latexTrigger:["\\operatorname{distance}"],kind:"function",serialize:(e,n)=>"\\operatorname{distance}"+e.wrapArguments(n)}];function Yl(e,n){if(e!==null){if(S(e))return{index:S(e)??"Nothing",upper:n};if(y(e)==="GreaterEqual"){let t=S(p(e,1))??"Nothing",i=p(e,2)??1;return{index:t,lower:i,upper:n}}if(y(e)==="Equal"){let t=S(p(e,1))??"Nothing",i=p(e,2);if(y(i)==="Range"){let s=p(i,1)??1,o=p(i,2)??void 0;return{index:t,lower:s,upper:o}}return{index:t,lower:i??1,upper:n}}if(y(e)==="Element")return{index:S(p(e,1))??"Nothing",element:e}}}function Wl(e){let n=y(e);return n?new Set(["Less","LessEqual","Greater","GreaterEqual","NotEqual","And","Or","Not"]).has(n):!1}function Bo(e){if(e===null)return[];let n=cn(e);if(n)return[...n];if(y(e)==="Tuple"){let t=I(e);return t?[...t]:[e]}return[e]}function Xl(e,n){z(e)&&(e=null),z(n)&&(n=null);let t=Bo(e),i=Bo(n),r=[],s=0;for(;s<t.length;){let o=t[s],a=Yl(o,i[s]);if(a){if(a.element&&s+1<t.length){let u=t[s+1];if(Wl(u)&&y(u)!=="Element"&&y(u)!=="Equal"){let l=a.element;if(Array.isArray(l)&&l.length>=3){let c=[l[0],...l.slice(1),u];a.element=c}s++}}r.push(a)}s++}return r}function Vo(e,n,t){return i=>{i.skipSpace(),i.pushSymbolTable();let r=null,s=null;for(;!(s&&r)&&(i.peek==="_"||i.peek==="^");)i.match("_")?s=i.parseGroup()??i.parseToken():i.match("^")&&(r=i.parseGroup()??i.parseToken()),i.skipSpace();if(!r&&!s){let l=i.parseExpression({minPrec:t});return i.popSymbolTable(),l?["Reduce",l,n]:null}let o=Xl(s,r),a=i.parseExpression({minPrec:t});if(i.popSymbolTable(),a===null)return[e];let u=[];for(let l of o){if(l.element){u.push(l.element);continue}let c=l.lower,f=l.upper,m=l.index??"Nothing";f!=null?u.push(["Tuple",m,c??1,f]):c!=null?u.push(["Tuple",m,c]):u.push(["Tuple",m])}return[e,a,...u]}}var Ql=new Set(["Tuple","Triple","Pair","Single","Limits","Element"]);function Jo(e){return e==null||S(e)==="Nothing"?null:e}function Kl(e){let n=[],t=I(e);if(t.length<=1)return n;for(let i of t.slice(1)){let r=y(i);if(r&&Ql.has(r)){n.push(i);continue}break}return n}function ec(e,n){if(y(n)==="Element"){let l=e.serialize(p(n,1)),c=e.serialize(p(n,2));return{sub:`${l}\\in ${c}`}}let t=p(n,1);t!==null&&y(t)==="Hold"&&(t=p(t,1));let i=Jo(p(n,2)),r=Jo(p(n,3)),s={},o=t?S(t):null,a=o!==null&&o!=="Nothing",u=a&&t?e.serialize(t):void 0;return a&&i!==null&&u?s.sub=`${u}=${e.serialize(i)}`:a&&u?s.sub=u:i!==null&&(s.sub=e.serialize(i)),r!==null&&(s.sup=e.serialize(r)),s}function qo(e){return(n,t)=>{let i=p(t,1);if(!i)return e;let r=Kl(t),s=e;if(r.length>0){let o=[],a=[];for(let u of r){let l=ec(n,u);l.sub&&o.push(l.sub),l.sup&&a.push(l.sup)}o.length>0&&(s=In("_",s,o.join(", "))),a.length>0&&(s=In("^",s,a.join(", ")))}return N([s,n.serialize(i)])}}function zo(e,n){let t=null;n.match("_")&&(t=n.parseGroup()??n.parseToken());let i=n.parseArguments("implicit");return i===null&&t===null?[e]:i===null?[e,t]:t===null?[e,...i]:t===10?["Log",i[0]]:t===2?["Lb",...i]:["Log",i[0],t]}function tt(e){let n=1,t=e;do{e=t;let i=y(e);if(i==="Negate")n*=-1,t=p(e,1);else if(i==="Multiply"){let[r,s]=tt(p(e,1));s<0&&(n*=-1,r===1?t=["Multiply",...I(e).slice(1)]:t=["Multiply",r,...I(e).slice(1)])}else if(i==="Divide"||i==="Rational"){let[r,s]=tt(p(e,1));s<0&&(n*=-1,t=[i,r,p(e,2)])}else{let r=R(e);r!==null&&r<0&&(n*=-1,t=-r)}}while(t!==e);return[e,n]}var Uo=[{name:"Real",kind:"function",latexTrigger:["\\Re"],arguments:"implicit"},{name:"Imaginary",kind:"function",latexTrigger:["\\Im"],arguments:"implicit"},{name:"Argument",kind:"function",latexTrigger:["\\arg"],arguments:"implicit"},{name:"Conjugate",latexTrigger:["^","\\star"],kind:"postfix"}];function w(e){return(n,t)=>{let i={"\\arcsin":"Arcsin","\\arccos":"Arccos","\\arctan":"Arctan","\\arctg":"Arctan","\\arcctg":"Arccot","\\arcsec":"Arcsec","\\arccsc":"Arccsc","\\arsinh":"Arsinh","\\arcsinh":"Arsinh","\\arcosh":"Arcosh","\\arccosh":"Arcosh","\\artanh":"Artanh","\\arctanh":"Artanh","\\arsech":"Arsech","\\arcsech":"Arsech","\\arcsch":"Arcsch","\\arccsch":"Arcsch","\\arcoth":"Arcoth","\\arccoth":"Arcoth","\\ch":"Cosh","\\cos":"Cos","\\cosh":"Cosh","\\cosec":"Csc","\\cot":"Cot","\\cotg":"Cot","\\ctg":"Cot","\\csc":"Csc","\\csch":"Csch","\\coth":"Coth","\\cth":"Coth","\\sec":"Sec","\\sech":"Sech","\\sin":"Sin","\\sinh":"Sinh","\\sh":"Sinh","\\tan":"Tan","\\tg":"Tan","\\tanh":"Tanh","\\th":"Tanh"},r=i[e??""]??e??"";if(n.atTerminator(t))return r;let s=r;do{let c=n.parsePostfixOperator(s,t);if(c===null)break;s=c}while(!0);n.skipSpace();let o=null;n.match("^")&&(o=n.parseGroup()??n.parseToken()),n.skipSpace();let a=n.parseArguments("implicit",{minPrec:ge,condition:c=>i[c.peek]||(t?.condition?.(c)??!1)}),u=s==="Arctan"&&a?.length===2?"Arctan2":s,l=a===null?s:typeof u=="string"?[u,...a]:["Apply",u,...a];return o===null?l:["Power",l,o]}}var Ho=[{name:"Arcsin",latexTrigger:["\\arcsin"],parse:w("Arcsin")},{name:"Arccos",latexTrigger:["\\arccos"],parse:w("Arccos")},{name:"Arctan",latexTrigger:["\\arctan"],parse:w("Arctan")},{latexTrigger:["\\arctg"],parse:w("Arctan")},{symbolTrigger:"arctg",parse:w("Arctan")},{name:"Arccot",symbolTrigger:"arcctg",parse:w("Arccot")},{latexTrigger:["\\arcctg"],parse:w("Arccot")},{name:"Arcoth",symbolTrigger:"arcoth",parse:w("Arcoth")},{symbolTrigger:"arccoth",parse:w("Arcoth")},{latexTrigger:["\\arcoth"],parse:w("Arcoth")},{latexTrigger:["\\arccoth"],parse:w("Arcoth")},{name:"Arcsec",symbolTrigger:"arcsec",parse:w("Arcsec")},{latexTrigger:["\\arcsec"],parse:w("Arcsec")},{name:"Arccsc",symbolTrigger:"arccsc",parse:w("Arccsc")},{latexTrigger:["\\arccsc"],parse:w("Arccsc")},{name:"Arsinh",symbolTrigger:"arsinh",parse:w("Arsinh")},{symbolTrigger:"arcsinh",parse:w("Arsinh")},{latexTrigger:["\\arsinh"],parse:w("Arsinh")},{latexTrigger:["\\arcsinh"],parse:w("Arsinh")},{name:"Arcosh",symbolTrigger:"arcosh",parse:w("Arcosh")},{symbolTrigger:"arccosh",parse:w("Arcosh")},{latexTrigger:"\\arcosh",parse:w("Arcosh")},{latexTrigger:"\\arccosh",parse:w("Arcosh")},{name:"Artanh",symbolTrigger:"artanh",parse:w("Artanh")},{symbolTrigger:"arctanh",parse:w("Artanh")},{latexTrigger:"\\artanh",parse:w("Artanh")},{latexTrigger:["\\arctanh"],parse:w("Artanh")},{name:"Arsech",symbolTrigger:"arsech",parse:w("Arsech")},{symbolTrigger:"arcsech",parse:w("Arsech")},{latexTrigger:["\\arsech"],parse:w("Arsech")},{latexTrigger:["\\arcsech"],parse:w("Arsech")},{name:"Arcsch",symbolTrigger:"arcsch",parse:w("Arcsch")},{symbolTrigger:"arccsch",parse:w("Arcsch")},{latexTrigger:["\\arcsch"],parse:w("Arcsch")},{latexTrigger:["\\arccsch"],parse:w("Arcsch")},{name:"Cosec",symbolTrigger:"cosec",parse:w("Cosec")},{latexTrigger:["\\cosec"],parse:w("Cosec")},{name:"Cosh",latexTrigger:["\\cosh"],parse:w("Cosh")},{latexTrigger:["\\ch"],parse:w("Cosh")},{name:"Cot",latexTrigger:["\\cot"],parse:w("Cot")},{latexTrigger:["\\cotg"],parse:w("Cot")},{latexTrigger:["\\ctg"],parse:w("Cot")},{name:"Csc",latexTrigger:["\\csc"],parse:w("Csc")},{name:"Csch",latexTrigger:["\\csch"],parse:w("Csch")},{name:"Coth",latexTrigger:["\\coth"],parse:w("Coth")},{latexTrigger:["\\cth"],parse:w("Coth")},{symbolTrigger:"cth",parse:w("Coth")},{latexTrigger:["\\coth"],parse:w("Coth")},{name:"Sec",latexTrigger:["\\sec"],parse:w("Sec")},{name:"Sech",symbolTrigger:"sech",parse:w("Sech")},{latexTrigger:["\\sech"],parse:w("Sech")},{name:"Sinh",latexTrigger:["\\sinh"],parse:w("Sinh")},{latexTrigger:["\\sh"],parse:w("Sinh")},{name:"Tan",latexTrigger:["\\tan"],parse:w("Tan")},{latexTrigger:["\\tg"],parse:w("Tan")},{name:"Tanh",latexTrigger:["\\tanh"],parse:w("Tanh")},{latexTrigger:["\\th"],parse:w("Tanh")},{name:"Cos",latexTrigger:["\\cos"],parse:w("Cos")},{name:"Sin",latexTrigger:["\\sin"],parse:w("Sin")},{name:"Sinc",symbolTrigger:"sinc",kind:"function"},{name:"FresnelS",symbolTrigger:"FresnelS",kind:"function"},{name:"FresnelC",symbolTrigger:"FresnelC",kind:"function"}];function $n(e){return n=>{let t=!1,i=[],r=[];for(;!t;){n.skipVisualSpace(),n.match("\\limits"),n.skipSpace();let a=null,u=null;for(;!(u!==null&&a!==null)&&(n.peek==="_"||n.peek==="^");)n.match("_")?u=n.parseGroup()??n.parseToken():n.match("^")&&(a=n.parseGroup()??n.parseToken()),n.skipSpace();z(u)&&(u=null),z(a)&&(a=null),i.push(u??"Nothing"),r.push(a??"Nothing"),n.skipVisualSpace(),t=!n.match(e)}let[s,o]=nc(n);if(s&&o.length===0){if(y(s)==="Add"||y(s)==="Subtract"){let a=[],u=[];for(let l of I(s))if(o)u.push(l);else{let c;[c,o]=je(l),a.push(c??l)}if(o!==null&&u.length>0)return["Add",Zo(e,["Add",...a],{indexes:o,subs:i,sups:r})??"Nothing",...u]}else if(y(s)==="Divide"){let a;[a,o]=je(p(s,1)),a!==null&&o!==null&&(s=["Divide",a,p(s,2)])}}return Zo(e,s,{indexes:o,subs:i,sups:r})}}function Zo(e,n,t){if(!n)return null;if(t.sups.length===0&&t.subs.length===0)return[e,n,...t.indexes];let i=t.indexes.length===0?y(n)==="Function"?I(n).slice(1):[]:t.indexes,r=Math.max(t.sups.length,t.subs.length,i.length);if(i.length===0)for(let o=0;o<r;o++)i.push("Nothing");else if(i.length!==r)for(let o=i.length;o<r;o++)i.push(["Error","'missing'"]);if(t.subs.length!==r)for(let o=t.subs.length;o<r;o++)t.subs.push("Nothing");if(t.sups.length!==r)for(let o=t.sups.length;o<r;o++)t.sups.push("Nothing");let s=i.map((o,a)=>{let u=t.sups[a],l=t.subs[a];return l==="Nothing"&&u==="Nothing"?o:["Tuple",o,l,u]});return[e,n,...s]}function nc(e){let n=!1,t=e.parseExpression({minPrec:266,condition:()=>{let i=e.index;return n=Xo(e),e.index=i,n}});return t!==null&&!n?je(t):[t,tc(e)]}function tc(e){let n=[];for(;Xo(e);){e.skipVisualSpace();let t=S(e.parseSymbol());if(t===null)return n;n.push(t)}return n}function je(e){let n=y(e),t=p(e,1);if(!t)return[e,[]];if(n==="Sequence"&&Z(e)===1)return je(t);if(n==="Multiply"||n==="InvisibleOperator"){let i=I(e);if(i){let[r,s]=ic(i);return r.length>0?[[n,...r],s]:[null,s]}}else if(n==="Delimiter"){let[i,r]=je(t);if(r)return i?[["Delimiter",["Sequence",i],...I(e).slice(1)],r]:[null,r]}else if(n==="Add"){let i=I(e);if(i.length>0){let[r,s]=je(i[i.length-1]);if(s.length>0){if(r)return[["Add",...i.slice(0,-1),r],s];if(i.length>2)return[["Add",...i.slice(0,-1)],s];if(i.length>2)return[i[0],s]}}}else if(n==="Negate"){let[i,r]=je(t);if(r.length>0)return[i?["Negate",i]:null,r]}else if(n==="Divide"){let[i,r]=je(t);if(r.length>0)return[["Divide",i??1,p(e,2)],r]}else{let i=I(e);if(i.length===1){let[r,s]=je(i[0]);if(s.length>0)return[[y(e),r],s]}}return[e,[]]}function Yo(e){return(n,t)=>{if(!p(t,1))return e;let i=p(t,1),r=[];y(i)==="BuiltInFunction"?(r=["x"],i=[p(i,1),"x"]):y(i)==="Function"?(r=I(i).slice(1),i=p(i,1)):S(i)?r=[]:r=[];let s=I(t).slice(1),o=[],a=s.map((l,c)=>{if(S(l)==="Nothing")return o.push(S(r[c])??"Nothing"),"";if(S(l))return o.push(S(l)??"Nothing"),"";let f=y(l);if(f==="Tuple"||f==="Pair"||f==="Limits"||f==="Range"){if(Z(l)===3){let m=p(l,1);o.push(S(m)??"Nothing");let d=p(l,2),b=p(l,3);return S(d)==="Nothing"&&(d=null),S(b)==="Nothing"&&(b=null),d!==null&&b!==null?`_{${n.serialize(d)}}^{${n.serialize(b)}}`:d!==null?`_{${n.serialize(d)}}`:b!==null?`^{${n.serialize(b)}}`:""}return`_{${n.serialize(l)}}`}if(Z(l)===2){if(S(p(l,1))){o.push(S(p(l,1))??"Nothing");let b=p(l,2);return S(b)==="Nothing"?"":`_{${n.serialize(b)}}`}o.push(S(r[c])??"Nothing");let m=p(l,1),d=p(l,2);if(S(m)==="Nothing"&&(m=null),S(d)==="Nothing"&&(d=null),m!==null&&d!==null)return`_{${n.serialize(m)}}^{${n.serialize(d)}}`;if(m!==null)return`_{${n.serialize(m)}}`;if(d!==null)return`^{${n.serialize(d)}}`}else o.push(S(r[c])??"Nothing")}),u=o.filter(l=>S(l)!=="Nothing").map(l=>`\\mathrm{d}${n.serialize(S(l)??"x")}`);return u.length>0&&(u=["\\,",...u]),a.length===0?`${e}\\,${n.serialize(i)}\\!${u.join(" ")}`:a.reverse().map(l=>`${e}${l}`).join("")+"\\!"+n.serialize(i)+u.join(" ")}}var Wo=[{kind:"expression",name:"Integrate",latexTrigger:["\\int"],parse:$n("Integrate"),serialize:Yo("\\int")},{kind:"expression",latexTrigger:["\\iint"],parse:$n("Integrate")},{kind:"expression",latexTrigger:["\\iiint"],parse:$n("Integrate")},{kind:"expression",name:"CircularIntegrate",latexTrigger:["\\oint"],parse:$n("CircularIntegrate"),serialize:Yo("\\oint")},{kind:"expression",latexTrigger:["\\oiint"],parse:$n("CircularIntegrate")},{kind:"expression",latexTrigger:["\\oiiint"],parse:$n("CircularIntegrate")}];function Xo(e){let n=e.index;for(;e.match("\\cdot")||e.skipVisualSpace(););return e.matchAll(["\\mathrm","<{>","d","<}>"])||e.matchAll(["\\operatorname","<{>","d","<}>"])||e.match("d")||e.match("\\differentialD")?!0:(e.index=n,!1)}function ic(e){let n=[...e],t=[];for(;n.length>0;){let i;if([n,i]=rc(n),!i)break;t.push(i)}return[n,t]}function rc(e){if(e.length<2)return[e,""];let n=e[e.length-2];if(n==="d"||n==="d_upright"){let t=S(e[e.length-1]);if(t)return[e.slice(0,-2),t]}return[e,""]}var Qo=[{name:"Matrix",serialize:(e,n)=>{let t=I(p(n,1));return er(e,t,B(p(n,2)),B(p(n,3)))}},{name:"Vector",serialize:(e,n)=>{let t=I(n);return er(e,t.map(i=>["List",i]),B(p(n,2)),B(p(n,3)))}},{kind:"environment",symbolTrigger:"pmatrix",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?[t,i,{str:"()"},{str:n}]:[t,i]}},{kind:"environment",symbolTrigger:"bmatrix",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?[t,i,{str:"[]"},{str:n}]:[t,i,{str:"[]"}]}},{kind:"environment",symbolTrigger:"Bmatrix",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?[t,i,{str:"{}"},{str:n}]:[t,i,{str:"{}"}]}},{kind:"environment",symbolTrigger:"vmatrix",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?["Determinant",[t,i,{str:n}]]:["Determinant",[t,i]]}},{kind:"environment",symbolTrigger:"Vmatrix",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?["Norm",[t,i,{str:n}]]:["Norm",[t,i]]}},{kind:"environment",symbolTrigger:"smallmatrix",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?[t,i,{str:"()"},{str:n}]:[t,i]}},{kind:"environment",symbolTrigger:"array",parse:e=>{let n=He(e,!1),[t,i]=Ue(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{kind:"environment",symbolTrigger:"matrix",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{kind:"environment",symbolTrigger:"matrix*",parse:e=>{let n=He(e),[t,i]=Ue(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{name:"ConjugateTranspose",kind:"postfix",latexTrigger:["^","\\star"]},{kind:"postfix",latexTrigger:["^","\\H"],parse:"ConjugateTranspose"},{kind:"postfix",latexTrigger:["^","\\dagger"],parse:(e,n)=>["ConjugateTranspose",n]},{kind:"postfix",latexTrigger:["^","\\ast"],parse:(e,n)=>["ConjugateTranspose",n]},{kind:"postfix",latexTrigger:["^","\\top"],parse:(e,n)=>["Transpose",n]},{kind:"postfix",latexTrigger:["^","\\intercal"],parse:(e,n)=>["Transpose",n]},{name:"Transpose",kind:"postfix",latexTrigger:["^","T"]},{name:"PseudoInverse",kind:"postfix",latexTrigger:["^","+"]},{name:"Inverse",serialize:(e,n)=>e.serialize(p(n,1))+"^{-1}"},{name:"Trace",kind:"function",latexTrigger:"\\tr",arguments:"implicit",serialize:(e,n)=>Cn(e,n,"\\tr")},{symbolTrigger:"tr",kind:"function",parse:"Trace",arguments:"implicit"},{name:"Kernel",kind:"function",latexTrigger:"\\ker",arguments:"implicit",serialize:(e,n)=>Cn(e,n,"\\ker")},{symbolTrigger:"ker",kind:"function",parse:"Kernel",arguments:"implicit"},{name:"Dimension",kind:"function",latexTrigger:"\\dim",arguments:"implicit",serialize:(e,n)=>Cn(e,n,"\\dim")},{symbolTrigger:"dim",kind:"function",parse:"Dimension",arguments:"implicit"},{name:"Degree",kind:"function",latexTrigger:"\\deg",arguments:"implicit",serialize:(e,n)=>Cn(e,n,"\\deg")},{symbolTrigger:"deg",kind:"function",parse:"Degree",arguments:"implicit"},{name:"Hom",kind:"function",latexTrigger:"\\hom",arguments:"implicit",serialize:(e,n)=>Cn(e,n,"\\hom")},{symbolTrigger:"hom",kind:"function",parse:"Hom",arguments:"implicit"},{name:"Determinant",kind:"function",latexTrigger:"\\det",arguments:"implicit",serialize:(e,n)=>{let t=p(n,1);if(y(t)==="Matrix"){let i=I(p(t,1));return er(e,i,"||",B(p(t,2)))}return Cn(e,n,"\\det")}},{symbolTrigger:"det",kind:"function",parse:"Determinant",arguments:"implicit"},{name:"MatrixMultiply",serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=e.serialize(p(n,2));return`${t} \\cdot ${i}`}}];function Ue(e){let n=e.parseTabular();return n?["Matrix",["List",...n.map(t=>["List",...t])]]:["",null]}function He(e,n=!0){let t=e.parseStringGroup(n)?.trim();if(!t)return"";let i="";for(let r of t)r==="c"&&(i+="="),r==="l"&&(i+="<"),r==="r"&&(i+=">"),r==="|"&&(i+="|"),r===":"&&(i+=":");return i}function Cn(e,n,t){if(I(n).length!==1)return`${t}${e.wrapArguments(n)}`;let r=p(n,1),s=e.serialize(r);return typeof r=="string"||typeof r=="number"?`${t} ${s}`:`${t}\\left(${s}\\right)`}function er(e,n,t,i){t??="()";let[r,s]=["",""];typeof t=="string"&&t.length===2&&([r,s]=t);let o="";if(i)for(let c of i)c==="<"?o+="l":c===">"?o+="r":c==="="?o+="c":c==="|"?o+="|":c===":"&&(o+=":");let a=[];for(let c of n??[]){let f=[];for(let m of I(c))f.push(e.serialize(m));a.push(f.join(" & "))}let u=a.join(`\\\\
8
- `),l=o.length>0?`[${o}]`:"";return r==="("&&s===")"?N(["\\begin{pmatrix}",l,u,"\\end{pmatrix}"]):r==="["&&s==="]"?N(["\\begin{bmatrix}",l,u,"\\end{bmatrix}"]):r==="{"&&s==="}"?N(["\\begin{Bmatrix}",l,u,"\\end{Bmatrix}"]):r==="|"&&s==="|"?N(["\\begin{vmatrix}",l,u,"\\end{vmatrix}"]):r==="\u2016"&&s==="\u2016"?N(["\\begin{Vmatrix}",l,u,"\\end{Vmatrix}"]):r==="{"&&s==="."?N(["\\begin{dcases}",l,u,"\\end{dcases}"]):r==="."&&s==="}"?N(["\\begin{rcases}",l,u,"\\end{rcases}"]):o||r!=="."||s!=="."?N(["\\left",Lt[r]??r,"\\begin{array}",`{${o}}`,u,"\\end{array}","\\right",Lt[s]??s]):N(["\\begin{matrix}",u,"\\end{matrix}"])}var Ko=[{name:"Mean",kind:"function",symbolTrigger:"mean"},{name:"Median",kind:"function",symbolTrigger:"median"},{name:"StandarDeviation",kind:"function",symbolTrigger:"stddev"},{latexTrigger:["\\bar"],kind:"expression",parse:(e,n)=>{let t=e.parseGroup()??e.parseToken();return!t||!S(t)?null:["Mean",t]}},{latexTrigger:"\\operatorname{var}",parse:"Variance"}];var Jt={Q:1e30,R:1e27,Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,h:100,da:10,d:.1,c:.01,m:.001,\u00B5:1e-6,\u03BC:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24,r:1e-27,q:1e-30},ea=new Set(["m","g","s","A","K","mol","cd","Hz","N","Pa","J","W","C","V","F","ohm","S","Wb","T","H","lm","lx","Bq","Gy","Sv","kat","eV","L","bar"]),qt={m:{dimension:[1,0,0,0,0,0,0],scale:1},kg:{dimension:[0,1,0,0,0,0,0],scale:1},g:{dimension:[0,1,0,0,0,0,0],scale:.001},s:{dimension:[0,0,1,0,0,0,0],scale:1},A:{dimension:[0,0,0,1,0,0,0],scale:1},K:{dimension:[0,0,0,0,1,0,0],scale:1},mol:{dimension:[0,0,0,0,0,1,0],scale:1},cd:{dimension:[0,0,0,0,0,0,1],scale:1},Hz:{dimension:[0,0,-1,0,0,0,0],scale:1},N:{dimension:[1,1,-2,0,0,0,0],scale:1},Pa:{dimension:[-1,1,-2,0,0,0,0],scale:1},J:{dimension:[2,1,-2,0,0,0,0],scale:1},W:{dimension:[2,1,-3,0,0,0,0],scale:1},C:{dimension:[0,0,1,1,0,0,0],scale:1},V:{dimension:[2,1,-3,-1,0,0,0],scale:1},F:{dimension:[-2,-1,4,2,0,0,0],scale:1},ohm:{dimension:[2,1,-3,-2,0,0,0],scale:1},S:{dimension:[-2,-1,3,2,0,0,0],scale:1},Wb:{dimension:[2,1,-2,-1,0,0,0],scale:1},T:{dimension:[0,1,-2,-1,0,0,0],scale:1},H:{dimension:[2,1,-2,-2,0,0,0],scale:1},lm:{dimension:[0,0,0,0,0,0,1],scale:1},lx:{dimension:[-2,0,0,0,0,0,1],scale:1},Bq:{dimension:[0,0,-1,0,0,0,0],scale:1},Gy:{dimension:[2,0,-2,0,0,0,0],scale:1},Sv:{dimension:[2,0,-2,0,0,0,0],scale:1},kat:{dimension:[0,0,-1,0,0,1,0],scale:1},degC:{dimension:[0,0,0,0,1,0,0],scale:1,offset:273.15},degF:{dimension:[0,0,0,0,1,0,0],scale:5/9,offset:459.67},min:{dimension:[0,0,1,0,0,0,0],scale:60},h:{dimension:[0,0,1,0,0,0,0],scale:3600},d:{dimension:[0,0,1,0,0,0,0],scale:86400},ha:{dimension:[2,0,0,0,0,0,0],scale:1e4},L:{dimension:[3,0,0,0,0,0,0],scale:.001},t:{dimension:[0,1,0,0,0,0,0],scale:1e3},eV:{dimension:[2,1,-2,0,0,0,0],scale:1602176634e-28},Da:{dimension:[0,1,0,0,0,0,0],scale:16605390666e-37},au:{dimension:[1,0,0,0,0,0,0],scale:149597870700},deg:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/180},rad:{dimension:[0,0,0,0,0,0,0],scale:1},grad:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/200},turn:{dimension:[0,0,0,0,0,0,0],scale:2*Math.PI},arcmin:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/10800},arcsec:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/648e3},percent:{dimension:[0,0,0,0,0,0,0],scale:.01},ppm:{dimension:[0,0,0,0,0,0,0],scale:1e-6},dB:{dimension:[0,0,0,0,0,0,0],scale:1},Np:{dimension:[0,0,0,0,0,0,0],scale:1},in:{dimension:[1,0,0,0,0,0,0],scale:.0254},ft:{dimension:[1,0,0,0,0,0,0],scale:.3048},mi:{dimension:[1,0,0,0,0,0,0],scale:1609.344},lb:{dimension:[0,1,0,0,0,0,0],scale:.45359237},oz:{dimension:[0,1,0,0,0,0,0],scale:.028349523125},gal:{dimension:[3,0,0,0,0,0,0],scale:.003785411784},atm:{dimension:[-1,1,-2,0,0,0,0],scale:101325},bar:{dimension:[-1,1,-2,0,0,0,0],scale:1e5},cal:{dimension:[2,1,-2,0,0,0,0],scale:4.184},kWh:{dimension:[2,1,-2,0,0,0,0],scale:36e5},\u00C5:{dimension:[1,0,0,0,0,0,0],scale:1e-10}};function sc(e){if(e.length>2){let n=e.slice(0,2),t=e.slice(2);if(Jt[n]!==void 0&&ea.has(t)){let i=qt[t];if(i)return{prefixScale:Jt[n],baseEntry:i}}}if(e.length>1){let n=e.slice(0,1),t=e.slice(1);if(Jt[n]!==void 0&&ea.has(t)){let i=qt[t];if(i)return{prefixScale:Jt[n],baseEntry:i}}}return null}function oc(e){let n=qt[e];if(n)return n;let t=sc(e);return t?{dimension:t.baseEntry.dimension,scale:t.prefixScale*t.baseEntry.scale}:null}function nr(e){let n=oc(e);return n?n.dimension:null}var yg=new Map(["N","J","W","Pa","Hz","C","V","F","ohm","S","Wb","T","H","lm","lx","Gy","kat"].map(e=>[qt[e].dimension.join(","),e]));function ac(e){let n=e.indexOf("^");if(n===-1)return e;let t=e.slice(0,n),i=e.slice(n+1),r=parseInt(i,10);return isNaN(r)?e:["Power",t,r]}function it(e){if(e=e.trim(),e.length===0)return null;if(e[0]==="("&&e[e.length-1]===")"){let r=0,s=!0;for(let o=0;o<e.length-1;o++)if(e[o]==="("?r++:e[o]===")"&&r--,r===0&&o<e.length-1){s=!1;break}if(s)return it(e.slice(1,-1))}let n=-1,t=[],i=0;for(let r=0;r<e.length;r++)e[r]==="("?i++:e[r]===")"?i--:i===0&&(e[r]==="/"&&n===-1?n=r:e[r]==="*"&&t.push(r));if(n!==-1){let r=e.slice(0,n).trim(),s=e.slice(n+1).trim(),o=it(r),a=it(s);return!o||!a?null:["Divide",o,a]}if(t.length>0){let r=[],s=0;for(let a of t)r.push(e.slice(s,a).trim()),s=a+1;r.push(e.slice(s).trim());let o=r.filter(a=>a.length>0).map(a=>it(a));return o.some(a=>a===null)?null:o.length===1?o[0]:["Multiply",...o]}return e[0]==="("?null:ac(e)}function na(e){return e=e.trim(),e.length===0?null:/[/*^()]/.test(e)?it(e):e}function sa(e){if(!e.match("<{>"))return null;let n="",t=0;for(;!e.atEnd;){let i=e.peek;if(i==="<}>"&&t===0)return e.nextToken(),n;if(i==="<}>"){t--,e.nextToken();continue}if(i==="<{>"){t++,e.nextToken();continue}if(i==="<space>"){e.nextToken();continue}if(i==="\\cdot"){n+="*",e.nextToken();continue}if(i==="^"){n+="^",e.nextToken();continue}n+=i,e.nextToken()}return null}var uc=new Set(["d"]);function oa(e){if(!e||e.length===0||uc.has(e))return null;if(nr(e)!==null)return e;if(/[/*^]/.test(e))try{let n=na(e);if(n!==null&&tr(n))return n}catch{return null}return null}function tr(e){if(typeof e=="string")return nr(e)!==null;if(!Array.isArray(e))return!1;let n=e[0];return n==="Multiply"||n==="Divide"?e.slice(1).every(t=>tr(t)):n==="Power"?tr(e[1]):!1}var ta=e=>{let n=e.index,t=sa(e);if(t===null)return e.index=n,null;let i=oa(t);return i===null?(e.index=n,null):["__unit__",i]};function mn(e){let n=S(e);if(n!==null)return n;if(typeof e=="number")return String(e);let t=y(e);if(!t)return"";if(t==="Divide"){let i=p(e,1),r=p(e,2);return`${mn(i)}/${mn(r)}`}if(t==="Multiply"){let i=[];if(Array.isArray(e))for(let r=1;r<e.length;r++)i.push(mn(e[r]));return i.join("\\cdot ")}if(t==="Power"){let i=p(e,1),r=p(e,2),s=typeof r=="number"?String(r):S(r)??String(r);return`${mn(i)}^{${s}}`}if(t==="Square"){let i=p(e,1);return`${mn(i)}^{2}`}return""}function ia(e){let n=e.parseGroup();if(n===null)return null;let t=aa(e);return t===null?null:["Quantity",n,t]}function ra(e){return aa(e)}function aa(e){let n=e.index,t=sa(e);if(t===null)return e.index=n,null;let i=oa(t);return i===null?(e.index=n,null):i}var ua=[{latexTrigger:"\\mathrm",kind:"expression",parse:ta},{latexTrigger:"\\text",kind:"expression",parse:ta},{latexTrigger:"\\qty",parse:ia},{latexTrigger:"\\SI",parse:ia},{latexTrigger:"\\unit",parse:ra},{latexTrigger:"\\si",parse:ra},{name:"Quantity",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);if(t===null||i===null)return"";let r=S(i),s=r==="deg"||r==="rad"||r==="arcmin"||r==="arcsec",o=e.options;if(s&&(o.dmsFormat||o.angleNormalization&&o.angleNormalization!=="none")){let l=R(t);if(l===null){let f=e.serialize(t),m=mn(i);return N([f,"\\,",`\\mathrm{${m}}`])}let c=l;return r==="rad"?c=c*180/Math.PI:r==="arcmin"?c=c/60:r==="arcsec"&&(c=c/3600),o.angleNormalization&&o.angleNormalization!=="none"&&(c=Ot(c,o.angleNormalization)),o.dmsFormat?Bt(c):`${c}\xB0`}let a=e.serialize(t),u=mn(i);return N([a,"\\,",`\\mathrm{${u}}`])}}];var lc=["pt","em","mu","ex","mm","cm","in","bp","sp","dd","cc","pc","nc","nd"];function la(e){for(e.skipSpace(),(e.peek==="-"||e.peek==="+")&&e.nextToken();/^[\d.]$/.test(e.peek);)e.nextToken();for(let n of lc)if(e.matchAll([...n]))return}function ye(e){return n=>{let t=n.parseGroup();return t===null?[e]:[e,t]}}function zt(e){return n=>{let t=n.parseExpression();return t!==null&&!z(t)?["Annotated",t,{dict:{mathStyle:e}}]:"Nothing"}}function Re(e){return n=>{let t=n.parseExpression();return t!==null&&!z(t)?["Annotated",t,{dict:{size:e}}]:"Nothing"}}var ca=[{name:"Overscript",latexTrigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",latexTrigger:["\\underset"],kind:"infix",precedence:700},{name:"Increment",latexTrigger:["+","+"],kind:"postfix",precedence:880,parse:(e,n)=>S(n)===null?null:["Increment",n]},{name:"Decrement",latexTrigger:["-","-"],kind:"postfix",precedence:880,parse:(e,n)=>S(n)===null?null:["Decrement",n]},{name:"PreIncrement",latexTrigger:["+","+"],kind:"prefix",precedence:880,parse:(e,n)=>{let t=e.parseExpression(n);return S(t)===null?null:["PreIncrement",t]}},{name:"PreDecrement",latexTrigger:["-","-"],kind:"prefix",precedence:880,parse:(e,n)=>{let t=e.parseExpression(n);return S(t)===null?null:["PreDecrement",t]}},{name:"Ring",latexTrigger:["\\circ"],kind:"infix",precedence:265},{name:"StringJoin",latexTrigger:["\\lt","\\gt"],kind:"infix",precedence:780},{name:"Starstar",latexTrigger:["\\star","\\star"],kind:"infix",precedence:780},{name:"PartialDerivative",latexTrigger:["\\partial"],kind:"prefix",parse:e=>{let n=!1,t="Nothing",i="Nothing";for(;!n;)e.skipSpace(),e.match("_")?i=e.parseGroup()??e.parseToken():e.match("^")?t=e.parseGroup()??e.parseToken():n=!0;let r=cn(i);if(r&&(i=["List",...r]),i===null||t===null)return null;let s=e.parseGroup()??"Nothing";if(!z(s)){let o=e.parseArguments()??["Nothing"];s=[s,...o]}return["PartialDerivative",s,i,t]},serialize:(e,n)=>{let t="\\partial",i=p(n,1),r=p(n,2),s=p(n,3);return r!==null&&r!=="Nothing"&&(y(r)==="List"?t+="_{"+e.serialize(["Sequence",...I(r)])+"}":t+="_{"+e.serialize(r)+"}"),s!==null&&s!=="Nothing"&&(t+="^{"+e.serialize(s)+"}"),i!==null&&i!=="Nothing"&&(t+=e.serialize(i)),t},precedence:740},{name:"OverBar",latexTrigger:["\\overline"],parse:ye("OverBar")},{name:"UnderBar",latexTrigger:["\\underline"],parse:ye("UnderBar")},{name:"OverVector",latexTrigger:["\\vec"],parse:ye("OverVector")},{name:"OverTilde",latexTrigger:["\\tilde"],parse:ye("OverTilde")},{name:"OverHat",latexTrigger:["\\hat"],parse:ye("OverHat")},{name:"OverRightArrow",latexTrigger:["\\overrightarrow"],parse:ye("OverRightArrow")},{name:"OverLeftArrow",latexTrigger:["\\overleftarrow"],parse:ye("OverLeftArrow")},{name:"OverRightDoubleArrow",latexTrigger:["\\Overrightarrow"],parse:ye("OverRightDoubleArrow")},{name:"OverLeftHarpoon",latexTrigger:["\\overleftharpoon"],parse:ye("OverLeftHarpoon")},{name:"OverRightHarpoon",latexTrigger:["\\overrightharpoon"],parse:ye("OverRightHarpoon")},{name:"OverLeftRightArrow",latexTrigger:["\\overleftrightarrow"],parse:ye("OverLeftRightArrow")},{name:"OverBrace",latexTrigger:["\\overbrace"],parse:ye("OverBrace")},{name:"OverLineSegment",latexTrigger:["\\overlinesegment"],parse:ye("OverLineSegment")},{name:"OverGroup",latexTrigger:["\\overgroup"],parse:ye("OverGroup")},{latexTrigger:["\\textcolor"],parse:e=>{let n=e.index,t=e.parseStringGroup(),i=e.parseGroup();return t!==null?i!==null?["Annotated",i,{dict:{color:t}}]:"Nothing":(e.index=n,"Nothing")}},{latexTrigger:["\\colorbox"],parse:e=>{let n=e.index,t=e.parseStringGroup(),i=e.parseGroup();return t!==null?i!==null?["Annotated",i,{dict:{backgroundColor:t}}]:"Nothing":(e.index=n,"Nothing")}},{latexTrigger:["\\boxed"],parse:e=>{let n=e.parseGroup();return n!==null?["Annotated",n,{dict:{border:!0}}]:"Nothing"}},{latexTrigger:["\\displaystyle"],parse:zt("normal")},{latexTrigger:["\\textstyle"],parse:zt("compact")},{latexTrigger:["\\scriptstyle"],parse:zt("script")},{latexTrigger:["\\scriptscriptstyle"],parse:zt("scriptscript")},{latexTrigger:["\\color"],parse:e=>{let n=e.parseStringGroup();if(n!==null){let t=e.parseExpression();if(t!==null&&!z(t))return["Annotated",t,{dict:{color:n}}]}return"Nothing"}},{latexTrigger:["\\tiny"],parse:Re(1)},{latexTrigger:["\\scriptsize"],parse:Re(2)},{latexTrigger:["\\footnotesize"],parse:Re(3)},{latexTrigger:["\\small"],parse:Re(4)},{latexTrigger:["\\normalsize"],parse:Re(5)},{latexTrigger:["\\large"],parse:Re(6)},{latexTrigger:["\\Large"],parse:Re(7)},{latexTrigger:["\\LARGE"],parse:Re(8)},{latexTrigger:["\\huge"],parse:Re(9)},{latexTrigger:["\\Huge"],parse:Re(10)},{name:"Annotated",serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=Eo(p(n,2));if(i==null)return t;i.dict.mathStyle==="normal"?t=N(["{\\displaystyle",t,"}"]):i.dict.mathStyle==="compact"?t=N(["{\\textstyle",t,"}"]):i.dict.mathStyle==="script"?t=N(["{\\scriptstyle",t,"}"]):i.dict.mathStyle==="scriptscript"&&(t=N(["{\\scriptscriptstyle",t,"}"]));let r=i.dict.size;return r!==null&&r>=1&&r<=10&&(t=N(["{",{1:"\\tiny",2:"\\scriptsize",3:"\\footnotesize",4:"\\small",5:"\\normalsize",6:"\\large",7:"\\Large",8:"\\LARGE",9:"\\huge",10:"\\Huge"}[r],t,"}"])),i.dict.fontFamily==="monospace"?t=N(["\\texttt{",t,"}"]):i.dict.fontFamily==="sans-serif"&&(t=N(["\\textsf{",t,"}"])),i.dict.fontWeight==="bold"&&(t=N(["\\textbf{",t,"}"])),i.dict.fontStyle==="italic"?t=N(["\\textit{",t,"}"]):i.dict.fontStyle==="normal"&&(t=N(["\\textup{",t,"}"])),i.dict.color&&(t=N(["\\textcolor{",i.dict.color,"}{",t,"}"])),i.dict.backgroundColor&&(t=N(["\\colorbox{",i.dict.backgroundColor,"}{",t,"}"])),i.dict.border===!0&&(t=N(["\\boxed{",t,"}"])),t}},{latexTrigger:["\\!"],parse:()=>["HorizontalSpacing",-3]},{latexTrigger:["\\ "],parse:()=>["HorizontalSpacing",6]},{latexTrigger:["\\:"],parse:()=>["HorizontalSpacing",4]},{latexTrigger:["\\enskip"],parse:()=>["HorizontalSpacing",9]},{latexTrigger:["\\quad"],parse:()=>["HorizontalSpacing",18]},{latexTrigger:["\\qquad"],parse:()=>["HorizontalSpacing",36]},{latexTrigger:["\\,"],parse:()=>["HorizontalSpacing",3]},{latexTrigger:["\\;"],parse:()=>["HorizontalSpacing",5]},{latexTrigger:["\\enspace"],parse:()=>["HorizontalSpacing",9]},{latexTrigger:["\\hspace"],parse:e=>(e.peek==="*"&&e.nextToken(),e.parseStringGroup(),["HorizontalSpacing",0])},{latexTrigger:["\\hskip"],parse:e=>(la(e),["HorizontalSpacing",0])},{latexTrigger:["\\kern"],parse:e=>(la(e),["HorizontalSpacing",0])},{latexTrigger:["\\phantom"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\vphantom"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\hphantom"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\placeholder"],parse:e=>(e.parseOptionalGroup(),e.parseGroup()??"Nothing")},{latexTrigger:["\\smash"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\strut"],parse:e=>"Nothing"},{latexTrigger:["\\mathstrut"],parse:e=>"Nothing"},{name:"HorizontalSpacing",serialize:(e,n)=>{if(p(n,2)!==null){let i=B(p(n,2)),r=e.serialize(p(n,1));return i==="bin"?`\\mathbin{${r}}`:i==="op"?`\\mathop{${r}}`:i==="rel"?`\\mathrel{${r}}`:i==="ord"?`\\mathord{${r}}`:i==="open"?`\\mathopen{${r}}`:i==="close"?`\\mathclose{${r}}`:i==="punct"?`\\mathpunct{${r}}`:i==="inner"?`\\mathinner{${r}}`:r}let t=R(p(n,1));return t===null?"":{"-3":"\\!",6:"\\ ",3:"\\,",4:"\\:",5:"\\;",9:"\\enspace",18:"\\quad",36:"\\qquad"}[t]??""}},{latexTrigger:"\\operatorname{count}",parse:"Length"},{latexTrigger:"\\operatorname{random}",parse:"Random"},{latexTrigger:"\\operatorname{shuffle}",parse:"Shuffle"},{latexTrigger:"\\operatorname{repeat}",parse:"Repeat"},{latexTrigger:"\\operatorname{join}",parse:"Join"},{latexTrigger:"\\operatorname{range}",parse:"Range"},{name:"Triangle",latexTrigger:["\\operatorname{triangle}"],kind:"function",serialize:(e,n)=>"\\operatorname{triangle}"+e.wrapArguments(n)},{name:"GeometricVector",latexTrigger:["\\operatorname{vector}"],kind:"function",serialize:(e,n)=>"\\operatorname{vector}"+e.wrapArguments(n)},{name:"Sphere",latexTrigger:["\\operatorname{sphere}"],kind:"function",serialize:(e,n)=>"\\operatorname{sphere}"+e.wrapArguments(n)},{name:"Segment",latexTrigger:["\\operatorname{segment}"],kind:"function",serialize:(e,n)=>"\\operatorname{segment}"+e.wrapArguments(n)}];var fa=[{name:"Rgb",latexTrigger:["\\operatorname{rgb}"],kind:"function",serialize:(e,n)=>"\\operatorname{rgb}"+e.wrapArguments(n)},{name:"Hsv",latexTrigger:["\\operatorname{hsv}"],kind:"function",serialize:(e,n)=>"\\operatorname{hsv}"+e.wrapArguments(n)},{name:"Hsl",latexTrigger:["\\operatorname{hsl}"],kind:"function",serialize:(e,n)=>"\\operatorname{hsl}"+e.wrapArguments(n)},{name:"Oklab",latexTrigger:["\\operatorname{oklab}"],kind:"function",serialize:(e,n)=>"\\operatorname{oklab}"+e.wrapArguments(n)},{name:"Oklch",latexTrigger:["\\operatorname{oklch}"],kind:"function",serialize:(e,n)=>"\\operatorname{oklch}"+e.wrapArguments(n)},{name:"AsRgb",latexTrigger:["\\operatorname{asRgb}"],kind:"function",serialize:(e,n)=>"\\operatorname{asRgb}"+e.wrapArguments(n)},{name:"AsHsv",latexTrigger:["\\operatorname{asHsv}"],kind:"function",serialize:(e,n)=>"\\operatorname{asHsv}"+e.wrapArguments(n)},{name:"AsHsl",latexTrigger:["\\operatorname{asHsl}"],kind:"function",serialize:(e,n)=>"\\operatorname{asHsl}"+e.wrapArguments(n)},{name:"AsOklab",latexTrigger:["\\operatorname{asOklab}"],kind:"function",serialize:(e,n)=>"\\operatorname{asOklab}"+e.wrapArguments(n)},{name:"AsOklch",latexTrigger:["\\operatorname{asOklch}"],kind:"function",serialize:(e,n)=>"\\operatorname{asOklch}"+e.wrapArguments(n)},{name:"ColorDelta",latexTrigger:["\\operatorname{colorDelta}"],kind:"function",serialize:(e,n)=>"\\operatorname{colorDelta}"+e.wrapArguments(n)}];var cc=[{name:"Mu0",kind:"symbol",latexTrigger:"\\mu_0"},{name:"VacuumPermittivity",kind:"symbol",latexTrigger:"\\varepsilon_0"}];var fc=[...Ao,...Ro,...Do,...To,...Lo,...un,...jo,...Uo,...Ho,...Wo,...Qo,...Ko,...ua,...ca,...cc,...fa];var pc="\\u{FE0F}",mc="\\u{20E3}",dc="\\u{200D}",hc="\\p{RI}\\p{RI}",gc="(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})",pa=`(?:\\p{EMod}|${pc}${mc}?|${gc})`,bc="(?:(?=\\P{XIDC})(?=[^\\x23\\x2a\\x30-\\x39])\\p{Emoji})",ma=`(?:${bc}${pa}*|\\p{Emoji}${pa}+|${hc})`,da=`(?:${ma})(${dc}${ma})*`,jg=new RegExp(`(?:${da})+`,"u"),ha=new RegExp(`^(?:${da})+$`,"u");function ba(e){return e!==void 0&&"value"in e}function rt(e){return e!==void 0&&"operator"in e}function Rn(e,n,t=!0){let i=!t||e.every(s=>s.isCanonical)?e:e.map(s=>s.canonical);if(n){let s=a=>k(a,"Nothing")||a.operator===n||a.operator==="Sequence";if(i.every(a=>!s(a)))return i;let o=[];for(let a of i)k(a,"Nothing")||(h(a)&&(a.operator===n||a.operator==="Sequence")?o.push(...Rn(a.ops,n,t)):o.push(a));return o}if(i.every(s=>!(k(s,"Nothing")||s.operator==="Sequence")))return i;let r=[];for(let s of i)k(s,"Nothing")||(h(s,"Sequence")?r.push(...Rn(s.ops,n,t)):r.push(s));return r}function jt(e,n,t){if(n=Rn(n),!e.strict||n.length===t)return n;let i=[...n.slice(0,t)],r=Math.min(t,n.length);for(;r<t;)i.push(e.error("missing")),r+=1;for(;r<n.length;)i.push(e.error("unexpected-argument",n[r].toString())),r+=1;return i}function en(e,n,t){return n==null?e.error("missing"):t===void 0?e.error("unexpected-argument",n.toString()):(n=n.canonical,!n.isValid||n.type.matches(t)?n:e.typeError(t,n.type,n))}function rr(e,n,t){if(n.length===t.length&&n.every((r,s)=>r.type.matches(t[s])))return n;let i=[];for(let r=0;r<=t.length-1;r++)i.push(en(e,n[r],t[r]));for(let r=t.length;r<=n.length-1;r++)i.push(e.error("unexpected-argument",n[r].toString()));return i}function ya(e){let n={},t=Sc(e.engine),i=kc(e.engine);if(k(e)&&!n[e.symbol]&&!e.symbol.startsWith("_")){if(!t.includes(e.symbol)){let r=St(e.symbol,t);r&&(n[e.symbol]=r)}}else if(h(e)&&!n[e.operator]&&!e.operator.startsWith("_")){let r=e.operator;if(!i.includes(r)){let s=St(r,i);s&&(n[r]=s)}for(let s of e.ops)n={...n,...ya(s)}}return n}function kc(e){let n=[],t=e.context.lexicalScope;for(;t;){for(let i of t.bindings.keys()){let r=t.bindings.get(i);rt(r)&&n.push(i)}t=t.parent}return n}function Sc(e){let n=[],t=e.context.lexicalScope;for(;t;){for(let i of t.bindings.keys()){let r=t.bindings.get(i);ba(r)&&n.push(i)}t=t.parent}return n}function Ze(e){let n=ya(e);if(Object.keys(n).length===0)return"";if(Object.keys(n).length===1){let[i,r]=Object.entries(n)[0];return`Unknown symbol "${i}". Did you mean "${r}"?`}let t=[];for(let[i,r]of Object.entries(n))t.push(`- "${i}" -> "${r}"?`);return`Unknown symbols found:
6
+ `))}advance(){let n=this.current;return this.current=this.lexer.consumeToken(),n}match(n){return this.current.type===n?(this.advance(),!0):!1}expect(n){return this.current.type!==n&&this.error(`Expected ${n}, got ${this.current.type}`),this.advance()}createNode(n,t={}){return{kind:n,position:this.current.position,line:this.current.line,column:this.current.column,...t}}parseType(){this.checkForNakedFunctionSignature();let n=this.parseUnionType();if(n||this.error("Expected a type"),this.current.type!=="EOF")if(this.current.type==="->"||this.current.type==="+"||this.current.type==="*"||this.current.type==="?")this.error("Function signatures must be enclosed in parentheses","For example `(x: number) -> number`");else if(this.current.type==="("){let t=this.lexer.input;t.includes("set(")||t.includes("collection(")||t.includes("list(")||t.includes("tuple(")?t.includes("set(")?this.error("Use `set<integer>` instead of `set(integer)`."):t.includes("collection(")?this.error("Use `collection<type>` instead of `collection(type)`.","For example `collection<number>`"):t.includes("list(")?this.error("Use `list<type>` instead of `list(type)`.","For example `list<number>`"):t.includes("tuple(")&&this.error("Use `tuple<type1, type2>` instead of `tuple(type1, type2)`.","For example `tuple<string, number>`"):this.error("Unexpected token after type")}else this.error("Unexpected token after type");return n}checkForNakedFunctionSignature(){if(this.current.type==="IDENTIFIER"){let n=this.lexer.saveState(),t=this.current;try{let i=this.current;if(this.advance(),this.current.type===":"){this.advance();let r=!1,s=0,o=10;for(;this.current.type!=="EOF"&&s<o;){if(this.current.type==="->"){r=!0;break}if(this.current.type==="+"||this.current.type==="*"||this.current.type==="?"){if(this.advance(),this.current.type==="->"){r=!0;break}s++}this.advance(),s++}r&&(this.lexer.restoreState(n),this.current=t,this.errorAtToken(i,"Function signatures must be enclosed in parentheses","For example `(z: string*) -> boolean`"))}this.lexer.restoreState(n),this.current=t}catch(i){if(this.lexer.restoreState(n),this.current=t,i instanceof Error&&i.message.includes("Function signatures must be enclosed"))throw i}}}parseUnionType(){let n=this.parseIntersectionType();if(!n)return;let t=[n];for(;this.match("|");){let i=this.parseIntersectionType();i||this.error("Expected type after |"),t.push(i)}return t.length===1?t[0]:this.createNode("union",{types:t})}parseIntersectionType(){let n=this.parsePrimaryType();if(!n)return;let t=[n];for(;this.match("&");){let i=this.parsePrimaryType();i||this.error("Expected type after &"),t.push(i)}return t.length===1?t[0]:this.createNode("intersection",{types:t})}parsePrimaryType(){if(this.match("!")){let n=this.parsePrimaryType();return n||this.error("Expected type after !"),this.createNode("negation",{type:n})}if(this.current.type==="("){let n=this.parseFunctionSignature();if(n)return n;if(this.match("(")){let t=this.parseUnionType();if(t||this.error("Expected type after ("),this.current.type===","){let i=[this.createNode("named_element",{name:void 0,type:t})];for(;this.match(",");){let r=this.parseUnionType();r||this.error("Expected type after ,"),i.push(this.createNode("named_element",{name:void 0,type:r}))}return this.expect(")"),this.createNode("tuple",{elements:i})}return this.expect(")"),this.createNode("group",{type:t})}}return this.parseListType()||this.parseTupleType()||this.parseRecordType()||this.parseDictionaryType()||this.parseSetType()||this.parseCollectionType()||this.parseExpressionType()||this.parseSymbolType()||this.parseNumericType()||this.parsePrimitiveType()||this.parseValue()||this.parseTypeReference()}isFunctionSignature(){let n=this.lexer.saveState(),t=this.current;this.advance();let i=1;for(;i>0&&this.current.type!=="EOF";)this.current.type==="("?i++:this.current.type===")"&&i--,this.advance();let r=this.current.type==="->";return this.lexer.restoreState(n),this.current=t,r}parseFunctionSignature(){if(this.current.type!=="("||!this.isFunctionSignature())return;let n=[];if(this.advance(),!this.match(")")){do{let o=this.parseArgument();o||this.error("Expected argument"),n.push(o)}while(this.match(","));this.expect(")")}this.expect("->");let t=this.parseUnionType();t||this.error("Expected return type after ->");let i=n.some(o=>o.modifier==="optional"),r=n.some(o=>o.modifier==="variadic_zero"||o.modifier==="variadic_one"),s=n.filter(o=>o.modifier==="variadic_zero"||o.modifier==="variadic_one").length;return i&&r&&this.error("Variadic arguments cannot be used with optional arguments"),s>1&&this.error("There can be only one variadic argument"),this.createNode("function_signature",{arguments:n,returnType:t})}parseArgument(){let n=this.parseNamedElement();if(!n)return;let t;return this.match("?")?t="optional":this.match("*")?t="variadic_zero":this.match("+")&&(t="variadic_one"),this.createNode("argument",{element:n,modifier:t})}parseNamedElement(){let n;if(this.current.type==="IDENTIFIER"||this.current.type==="VERBATIM_STRING"){let i=this.current;if(this.lexer.peekToken().type===":"){n=i.value,this.advance(),this.advance();let s=this.parseUnionType();return s?this.createNode("named_element",{name:n,type:s}):void 0}}let t=this.parseUnionType();if(t)return this.createNode("named_element",{name:void 0,type:t})}parseListType(){if(this.current.type==="IDENTIFIER"){let n=this.current,i=this.lexer.peekToken().type==="<";switch(n.value){case"list":return i?(this.advance(),this.parseListTypeImpl()):void 0;case"vector":return i?(this.advance(),this.parseVectorType()):(this.advance(),this.createNode("list",{elementType:this.createNode("primitive",{name:"number"}),dimensions:void 0}));case"matrix":return i?(this.advance(),this.parseMatrixType()):(this.advance(),this.createNode("matrix",{elementType:this.createNode("primitive",{name:"number"}),dimensions:[this.createNode("dimension",{size:-1}),this.createNode("dimension",{size:-1})]}));case"tensor":return i?(this.advance(),this.parseTensorType()):(this.advance(),this.createNode("list",{elementType:this.createNode("primitive",{name:"number"}),dimensions:void 0}));default:return}}}parseListTypeImpl(){let n=this.createNode("primitive",{name:"any"}),t;if(this.match("<")){if(t=this.parseDimensions(),!t){let i=this.parseUnionType();i&&(n=i,this.match("^")&&(t=this.parseCaretDimensions()))}this.expect(">")}return this.createNode("list",{elementType:n,dimensions:t})}parseVectorType(){let n=this.createNode("primitive",{name:"number"}),t;if(this.match("<")){if(this.current.type==="NUMBER_LITERAL")t=parseInt(this.advance().value);else{let i=this.parseUnionType();i&&(n=i,this.match("^")&&(this.current.type==="NUMBER_LITERAL"?t=parseInt(this.advance().value):this.error("Expected number after ^")))}this.expect(">")}return this.createNode("vector",{elementType:n,size:t})}parseMatrixType(){let n=this.createNode("primitive",{name:"number"}),t;if(this.match("<")){if(t=this.parseDimensions(),!t){let i=this.parseUnionType();i&&(n=i,this.match("^")&&(t=this.parseCaretDimensions()))}this.expect(">")}else t=[this.createNode("dimension",{size:null}),this.createNode("dimension",{size:null})];return this.createNode("matrix",{elementType:n,dimensions:t})}parseTensorType(){let n=this.createNode("primitive",{name:"number"});if(this.match("<")){let t=this.parseUnionType();t&&(n=t),this.expect(">")}return this.createNode("tensor",{elementType:n})}parseDimensions(){let n=this.parseDimension();if(!n)return;let t=[n];for(;;){let i=this.current;if(i.type==="IDENTIFIER"&&/^(x\d+)+$/.test(i.value)){this.advance();for(let r of i.value.match(/x(\d+)/g))t.push(this.createNode("dimension",{size:parseInt(r.slice(1))}))}else if(i.type==="IDENTIFIER"&&i.value==="x"){let r=this.lexer.peekToken();r.type!=="NUMBER_LITERAL"&&r.type!=="?"&&this.error("Expected a positive integer literal or `?` after x. For example: `2x3` or `2x?`"),this.advance(),t.push(this.parseDimension())}else break}return t}parseDimension(){if(this.match("?"))return this.createNode("dimension",{size:null});if(this.current.type==="NUMBER_LITERAL"){let n=parseInt(this.advance().value);return this.createNode("dimension",{size:n})}}parseCaretDimensions(){let n=this.match("("),t=this.parseDimensions();return n&&this.expect(")"),t}parseTupleType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="tuple"){if(this.lexer.peekToken().type!=="<")return;this.advance(),this.expect("<");let t=[];if(this.current.type!==">"){let i=this.parseNamedElement();i||this.error("Expected tuple element"),t.push(i);let r=i.name!==void 0;for(;this.match(",");){let s=this.parseNamedElement();s||this.error("Expected tuple element"),r&&!s.name&&this.error("All tuple elements should be named, or none. Previous elements were named, but this one isn't."),!r&&s.name&&this.error("All tuple elements should be named, or none. Previous elements were not named, but this one is."),t.push(s)}}return this.expect(">"),this.createNode("tuple",{elements:t})}}parseRecordType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="record"){this.advance();let n=[];if(this.match("<")){if(this.current.type!==">")do{let t=this.parseRecordEntry();t||this.error("Expected record entry"),n.push(t)}while(this.match(","));this.expect(">")}return this.createNode("record",{entries:n})}}parseRecordEntry(){let n;if(this.current.type==="IDENTIFIER")n=this.advance().value;else if(this.current.type==="VERBATIM_STRING")n=this.advance().value;else return;this.expect(":");let t=this.parseUnionType();return t||this.error("Expected value type"),this.createNode("record_entry",{key:n,valueType:t})}parseDictionaryType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="dictionary"){this.advance();let n=this.createNode("primitive",{name:"any"});if(this.match("<")){let t=this.parseUnionType();t&&(n=t),this.expect(">")}return this.createNode("dictionary",{valueType:n})}}parseSetType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="set"){this.advance();let n=this.createNode("primitive",{name:"any"});if(this.match("<")){let t=this.parseUnionType();t&&(n=t),this.expect(">")}return this.createNode("set",{elementType:n})}}parseCollectionType(){if(this.current.type==="IDENTIFIER"){let n=this.current.value==="indexed_collection",t=this.current.value==="collection";if(n||t){this.advance();let i=this.createNode("primitive",{name:"any"});if(this.match("<")){let r=this.parseUnionType();r&&(i=r),this.expect(">")}return this.createNode("collection",{elementType:i,indexed:n})}}}parseExpressionType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="expression"){if(this.lexer.peekToken().type!=="<")return;this.advance(),this.expect("<");let i=this.expect("IDENTIFIER").value;return this.expect(">"),this.createNode("expression",{operator:i})}}parseSymbolType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="symbol"){if(this.lexer.peekToken().type!=="<")return;this.advance(),this.expect("<");let i=this.expect("IDENTIFIER").value;return this.expect(">"),this.createNode("symbol",{name:i})}}parseNumericType(){if(this.current.type==="IDENTIFIER"&&["real","finite_real","rational","finite_rational","integer","finite_integer"].includes(this.current.value)){let t=this.advance().value;if(this.match("<")){let i=this.parseValue();this.expect("..");let r=this.parseValue();this.expect(">");let s=i?.value??-1/0,o=r?.value??1/0;return(Number.isNaN(s)||Number.isNaN(o))&&this.error("Invalid numeric type","Lower and upper bounds must be valid numbers"),s>o&&this.error(`Invalid range: ${s}..${o}`,"The lower bound must be less than the upper bound"),this.createNode("numeric",{baseType:t,lowerBound:i,upperBound:r})}return this.createNode("numeric",{baseType:t})}}parsePrimitiveType(){if(this.current.type==="IDENTIFIER"){let n=this.current.value;if(dn.has(n))return this.advance(),this.createNode("primitive",{name:n})}}parseValue(){let n,t;switch(this.current.type){case"STRING_LITERAL":n=this.advance().value,t="string";break;case"NUMBER_LITERAL":n=parseFloat(this.advance().value),t="number";break;case"TRUE":this.advance(),n=!0,t="boolean";break;case"FALSE":this.advance(),n=!1,t="boolean";break;case"NAN":this.advance(),n=NaN,t="nan";break;case"INFINITY":case"PLUS_INFINITY":this.advance(),n=1/0,t="infinity";break;case"MINUS_INFINITY":this.advance(),n=-1/0,t="infinity";break;default:return}return this.createNode("value",{value:n,valueType:t})}parseTypeReference(){let n=this.current.type==="IDENTIFIER"&&this.current.value==="type";if(n&&this.advance(),this.current.type==="IDENTIFIER"){let t=this.current,i=this.advance().value;return this.typeResolver.resolve(i)?this.createNode("type_reference",{name:i,isForward:n}):n&&this.typeResolver.forward(i)?this.createNode("type_reference",{name:i,isForward:!0}):(n||this.errorAtToken(t,`Unknown type "${i}"`,"Syntax error. The type was not recognized."),this.createNode("type_reference",{name:i,isForward:n}))}}};function $o(e,n){switch(e.kind){case"function_signature":return n.visitFunctionSignature(e);case"union":return n.visitUnionType(e);case"intersection":return n.visitIntersectionType(e);case"negation":return n.visitNegationType(e);case"group":return n.visitGroupType(e);case"list":return n.visitListType(e);case"vector":return n.visitVectorType(e);case"matrix":return n.visitMatrixType(e);case"tensor":return n.visitTensorType(e);case"tuple":return n.visitTupleType(e);case"record":return n.visitRecordType(e);case"dictionary":return n.visitDictionaryType(e);case"set":return n.visitSetType(e);case"collection":return n.visitCollectionType(e);case"expression":return n.visitExpressionType(e);case"symbol":return n.visitSymbolType(e);case"numeric":return n.visitNumericType(e);case"primitive":return n.visitPrimitiveType(e);case"type_reference":return n.visitTypeReference(e);case"value":return n.visitValue(e);default:throw new Error(`Unknown node kind: ${e.kind}`)}}var Zi=class{typeResolver;constructor(n){this.typeResolver=n??{forward:()=>{},resolve:()=>{},get names(){return[]}}}buildType(n){return $o(n,this)}visitFunctionSignature(n){let t=[],i=[],r,s;for(let u of n.arguments){let l=this.buildNamedElement(u.element);switch(u.modifier){case"optional":i.push(l);break;case"variadic_zero":r=l,s=0;break;case"variadic_one":r=l,s=1;break;default:t.push(l);break}}let o=this.buildType(n.returnType),a={kind:"signature",args:t.length>0?t:void 0,result:o};return i.length>0&&(a.optArgs=i),r&&(a.variadicArg=r,a.variadicMin=s),a}visitUnionType(n){return{kind:"union",types:n.types.map(i=>this.buildType(i))}}visitIntersectionType(n){return{kind:"intersection",types:n.types.map(i=>this.buildType(i))}}visitNegationType(n){return{kind:"negation",type:this.buildType(n.type)}}visitGroupType(n){return this.buildType(n.type)}visitListType(n){let t=this.buildType(n.elementType),i=n.dimensions?.map(r=>this.buildDimension(r));return{kind:"list",elements:t,dimensions:i}}visitVectorType(n){let t=this.buildType(n.elementType);return n.size!==void 0?{kind:"list",elements:t,dimensions:[n.size]}:{kind:"list",elements:t}}visitMatrixType(n){let t=this.buildType(n.elementType);if(n.dimensions){let i=n.dimensions.map(r=>this.buildDimension(r));return{kind:"list",elements:t,dimensions:i}}return{kind:"list",elements:t,dimensions:[-1,-1]}}visitTensorType(n){return{kind:"list",elements:this.buildType(n.elementType)}}visitTupleType(n){return{kind:"tuple",elements:n.elements.map(i=>this.buildNamedElement(i))}}visitRecordType(n){if(n.entries.length===0)return"record";let t={};for(let i of n.entries)t[i.key]=this.buildType(i.valueType);return{kind:"record",elements:t}}visitDictionaryType(n){let t=this.buildType(n.valueType);return this.isAnyType(t)?"dictionary":{kind:"dictionary",values:t}}visitSetType(n){let t=this.buildType(n.elementType);return this.isAnyType(t)?"set":{kind:"set",elements:t}}visitCollectionType(n){let t=this.buildType(n.elementType);return n.indexed?this.isAnyType(t)?"indexed_collection":{kind:"indexed_collection",elements:t}:this.isAnyType(t)?"collection":{kind:"collection",elements:t}}visitExpressionType(n){return{kind:"expression",operator:n.operator}}visitSymbolType(n){return{kind:"symbol",name:n.name}}visitNumericType(n){if(!n.lowerBound&&!n.upperBound)return n.baseType;let t=n.lowerBound?this.buildValue(n.lowerBound):-1/0,i=n.upperBound?this.buildValue(n.upperBound):1/0;return t===-1/0&&i===1/0?n.baseType:{kind:"numeric",type:n.baseType,lower:t,upper:i}}visitPrimitiveType(n){return n.name}visitTypeReference(n){let t=this.typeResolver.resolve(n.name);if(t)return t;if(n.isForward){let i=this.typeResolver.forward(n.name);if(i)return i}return n.name}visitValue(n){return{kind:"value",value:n.value}}buildNamedElement(n){let t=this.buildType(n.type);return n.name?{name:n.name,type:t}:{type:t}}buildDimension(n){return n.size??-1}buildValue(n){return n.value}isAnyType(n){return n==="any"||typeof n=="object"&&"kind"in n&&n.kind==="primitive"&&"name"in n&&n.name==="any"}};function Co(e,n){return new Zi(n).buildType(e)}var Lt=new Map,Kl=2048;function Ro(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;Object.freeze(e);for(let n of Object.values(e))Ro(n);return e}function U(e,n){if(e===void 0)return;if(Pt(e))return e;if(typeof e!="string")return;let t=n===void 0;if(t){let i=Lt.get(e);if(i!==void 0)return i}try{let r=new Ot(e,{typeResolver:n}).parseType(),s=Co(r,n);return t&&(Lt.size>=Kl&&Lt.clear(),Lt.set(e,Ro(s))),s}catch(i){throw new Error(`Failed to parse type "${e}": ${i instanceof Error?i.message:String(i)}`)}}var Do={number:$t,non_finite_number:[],finite_number:["finite_complex","finite_real","finite_integer","finite_rational"],complex:["finite_complex","imaginary","finite_real","finite_rational","finite_integer","non_finite_number"],finite_complex:["imaginary","finite_real","finite_rational","finite_integer"],imaginary:[],real:["rational","integer","finite_real","finite_rational","finite_integer","non_finite_number"],finite_real:["finite_rational","finite_integer"],rational:["finite_rational","finite_integer","integer","non_finite_number"],finite_rational:["finite_integer"],integer:["finite_integer","non_finite_number"],finite_integer:[],any:Hi,unknown:[],nothing:[],never:[],error:[],value:ji,scalar:Rt,collection:Ct,indexed_collection:Gi,list:[],set:[],tuple:[],record:[],dictionary:[],function:[],symbol:[],boolean:[],string:[],color:[],expression:Ui},nt=(()=>{let e={},n=t=>{if(e[t])return e[t];let i=new Set([t]);e[t]=i;for(let r of Do[t])if(r!==t)for(let s of n(r))i.add(s);return i};for(let t of Object.keys(Do))n(t);return e})();function et(e,n){return n==="any"||e==="never"?!0:e==="unknown"||n==="unknown"?!1:e===n?!0:nt[n].has(e)}function Lo(e,n){if(e===n)return[e];let t=nt[e],i=nt[n];if(t.has(n))return[n];if(i.has(e))return[e];let r=e<n?`${e}|${n}`:`${n}|${e}`,s=Po.get(r);if(s)return s;let o=[];for(let u of t)i.has(u)&&o.push(u);let a=o.filter(u=>!o.some(l=>l!==u&&nt[l].has(u)));return Po.set(r,a),a}var Po=new Map;function w(e,n){if(typeof e=="string"&&!dn.has(e)&&(e=U(e)),typeof n=="string"&&!dn.has(n)&&(n=U(n)),n==="any"||e==="never")return!0;if(n==="never")return!1;if(n==="error")return e==="error";if(n==="nothing")return e==="nothing";if(e==="nothing")return!1;if(n==="unknown")return!0;if(e==="unknown")return!1;if(typeof n=="string")return typeof e=="string"?et(e,n):e.kind==="value"?typeof e.value=="boolean"?n==="boolean":typeof e.value=="number"?Number.isInteger(e.value)?et("integer",n):et("real",n):typeof e.value=="boolean"?et("boolean",n):typeof e.value=="string"?et("string",n):!1:e.kind==="union"?e.types.every(t=>w(t,n)):e.kind==="intersection"?e.types.some(t=>w(t,n)):e.kind==="negation"?!w(e.type,n):e.kind==="numeric"?!!w(e.type,n):n==="number"?Bo(e):n==="symbol"?Yi(e):n==="expression"?ec(e):n==="function"?Go(e):n==="scalar"?Vo(e):n==="value"?zo(e):n==="indexed_collection"?Jo(e):n==="collection"?qo(e):n==="tuple"?e.kind==="tuple":n==="list"?e.kind==="list":n==="set"?e.kind==="set":n==="record"?e.kind==="record":n==="dictionary"?e.kind==="dictionary":!1;if(n.kind==="union")return typeof e!="string"&&e.kind==="union"?e.types.every(t=>n.types.some(i=>w(t,i))):n.types.some(t=>w(e,t));if(n.kind==="expression"){if(e==="symbol")return!0;if(typeof e=="string")return!1;if(e.kind==="expression")return n.operator==="Symbol"?Yi(e):e.operator===n.operator;if(e.kind==="symbol")return!0}if(typeof e=="string")return!1;if(n.kind==="reference"){if(e.kind==="reference")return e.name===n.name;if(n.alias===!0&&n.def)return w(e,n.def)}if(e.kind==="union")return e.types.some(t=>w(t,n));if(e.kind==="intersection"&&n.kind==="intersection")return n.types.every(t=>e.types.some(i=>w(i,t)));if(e.kind==="intersection")return e.types.every(t=>w(t,n));if(n.kind==="intersection")return n.types.every(t=>w(e,t));if(e.kind==="signature"&&n.kind==="signature"){if(!w(e.result,n.result))return!1;if(e.optArgs||e.variadicArg){if(n.args){if(!e.args||e.args.length!==n.args.length)return!1;for(let t=0;t<n.args.length;t++)if(!w(n.args[t].type,e.args[t].type))return!1}else if(e.args)return!1;if(n.optArgs){if(!e.optArgs||e.optArgs.length!==n.optArgs.length)return!1;for(let t=0;t<e.optArgs.length;t++)if(!w(n.optArgs[t].type,e.optArgs[t].type))return!1}else if(e.optArgs)return!1;if(n.variadicArg){if(!e.variadicArg||e.variadicMin!=n.variadicMin||!w(n.variadicArg.type,e.variadicArg.type))return!1}else if(e.variadicArg)return!1}else{if(n.args&&!e.args)return!1;let t=0;if(n.args){if(e.args.length<n.args.length)return!1;for(;t<n.args.length;){if(!w(n.args[t].type,e.args[t].type))return!1;t+=1}}if(n.optArgs){if(t>=e.args.length)return!0;for(let i=0;i<n.optArgs.length;i++){if(!w(n.optArgs[i].type,e.args[t].type))return!1;if(t+=1,t>=e.args.length)return!0}}if(n.variadicArg){if(t>=e.args.length&&n.variadicMin===0)return!0;if(n.variadicMin>0&&t+n.variadicMin>e.args.length)return!1;for(;t<e.args.length;){if(!w(n.variadicArg.type,e.args[t].type))return!1;t+=1}}}return!0}if(e.kind==="record"&&n.kind==="record"){for(let t of Object.keys(n.elements))if(!(t in e.elements)||!w(e.elements[t],n.elements[t]))return!1;return!0}if(e.kind==="dictionary"&&n.kind==="dictionary")return w(e.values,n.values);if(n.kind==="indexed_collection")return e.kind==="indexed_collection"||e.kind==="list"?w(e.elements,n.elements):e.kind==="tuple"?e.elements.every(t=>w(t.type,n.elements)):!1;if(n.kind==="collection"){if(e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="list")return w(e.elements,n.elements);if(e.kind==="tuple")return e.elements.every(t=>w(t.type,n.elements));if(e.kind==="set")return w(e.elements,n.elements);if(e.kind==="dictionary")return w({kind:"tuple",elements:[{type:"string"},{type:e.values}]},n.elements);if(e.kind==="record")return w({kind:"tuple",elements:[{type:"string"},{type:ge(...Object.values(e.elements))}]},n.elements)}if(e.kind==="tuple"&&n.kind==="tuple"){if(e.elements.length!==n.elements.length)return!1;for(let t=0;t<e.elements.length;t++){let i=e.elements[t],r=n.elements[t];if(!w(i.type,r.type)||i.name!==r.name)return!1}return!0}if(n.kind==="list"&&e.kind==="list"){if(!w(e.elements,n.elements))return!1;if(n.dimensions){if(!e.dimensions||e.dimensions.length!==n.dimensions.length)return!1;for(let t=0;t<e.dimensions.length;t++)if(n.dimensions[t]!==-1&&e.dimensions[t]!==n.dimensions[t])return!1}return!0}if(e.kind==="symbol"&&n.kind==="symbol")return e.name===n.name;if(e.kind==="numeric"&&n.kind==="numeric")return!(!w(e.type,n.type)||(e.lower??-1/0)<(n.lower??-1/0)||(e.upper??1/0)>(n.upper??1/0));if(n.kind==="set"&&e.kind==="set")return!!w(e.elements,n.elements);if(e.kind==="negation"&&n.kind==="negation")return w(e.type,n.type);if(n.kind==="negation")return!w(e,n.type);if(n.kind==="value"&&e.kind==="value")return n.value===e.value;if(e.kind==="value"){if(typeof e.value=="boolean")return w("boolean",n);if(typeof e.value=="number")return Number.isInteger(e.value)?w("integer",n):w("real",n);if(typeof e.value=="string")return w("string",n)}return!1}function Bo(e){return typeof e=="string"?Dt.has(e):e.kind==="value"?typeof e.value=="number":e.kind==="numeric"}function Vo(e){return Bo(e)?!0:typeof e=="string"?wo.has(e):e.kind==="value"?["string","boolean","number"].includes(typeof e.value):!1}function qo(e){return Jo(e)?!0:typeof e=="string"?Mo.has(e):["collection","set","record","dictionary"].includes(e.kind)}function Jo(e){return typeof e=="string"?!1:["indexed_collection","list","tuple"].includes(e.kind)}function zo(e){return Vo(e)||qo(e)}function Go(e){return e==="function"||typeof e!="string"&&e.kind==="signature"}function ec(e){return typeof e=="string"&&["expression","symbol","function"].includes(e)||zo(e)||Go(e)||Yi(e)?!0:typeof e=="string"?!1:e.kind==="expression"}function Yi(e){return e==="symbol"?!0:typeof e=="string"?!1:e.kind==="symbol"?!0:e.kind==="expression"?e.operator==="Symbol":!1}function nc(e,n){return e===n?e:e==="nothing"||n==="nothing"?"nothing":e==="any"?n:n==="any"?e:e==="never"?n:n==="never"?e:e==="unknown"?n:n==="unknown"||w(e,n)?e:w(n,e)?n:"never"}function tc(e,n){if(e===n)return e;if(e==="any"||n==="any")return"any";if(e==="never")return n;if(n==="never")return e;if(e==="unknown")return n;if(n==="unknown")return e;if(e==="nothing")return n;if(n==="nothing")return e;if(w(e,n))return n;if(w(n,e))return e;let t=sc(e,n);return ic.has(t)?rc(e,n):t}var ic=new Set(["scalar","value","function","expression","collection","indexed_collection","list","set","tuple","record","dictionary","map","any"]);function rc(e,n){let t=[],i=new Set,r=s=>{if(typeof s=="object"&&s.kind==="union"){for(let a of s.types)r(a);return}let o=typeof s=="string"?s:JSON.stringify(s);i.has(o)||(i.add(o),t.push(s))};return r(e),r(n),t.length===1?t[0]:{kind:"union",types:t}}function Wi(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce((n,t)=>nc(n,t))}function ge(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce((n,t)=>tc(n,t))}var Fo=["non_finite_number","finite_integer","integer","finite_rational","rational","finite_real","real","imaginary","finite_complex","complex","finite_number","number","list","record","dictionary","set","tuple","indexed_collection","collection","scalar","value","function","expression"],Oo=new Map;function sc(e,n){if(e===n)return e;if(e==="any"||n==="any")return"any";if(e==="never")return n;if(n==="never")return e;if(e==="unknown")return n;if(n==="unknown")return e;if(e==="nothing")return n;if(n==="nothing")return e;if(typeof e=="string"&&typeof n=="string"){let t=e<n?`${e}|${n}`:`${n}|${e}`,i=Oo.get(t);if(i===void 0){i="any";for(let r of Fo){let s=nt[r];if(s.has(e)&&s.has(n)){i=r;break}}Oo.set(t,i)}return i}for(let t of Fo)if(w(e,t)&&w(n,t))return t;return"any"}var Uo=3,Ho=1,Zo=2,oc=4,ac=5,uc=6,lc=7,cc=8,fc=9,pc=10,mc=11;function V(e,n=0){if(typeof e=="string")return e;let t="";switch(e.kind){case"value":typeof e.value=="string"?t=`"${e.value}"`:typeof e.value=="boolean"?t=e.value?"true":"false":t=e.value.toString();break;case"reference":t=e.name;break;case"negation":t=`!${V(e.type,Uo)}`;break;case"union":t=e.types.map(u=>V(u,Ho)).join(" | ");break;case"intersection":t=e.types.map(u=>V(u,Zo)).join(" & ");break;case"expression":t=`expression<${jo(e.operator)}>`;break;case"symbol":t=`symbol<${jo(e.name)}>`;break;case"numeric":Number.isFinite(e.lower)&&Number.isFinite(e.upper)?t=`${e.type}<${e.lower}..${e.upper}>`:Number.isFinite(e.lower)?t=`${e.type}<${e.lower}..>`:Number.isFinite(e.upper)?t=`${e.type}<..${e.upper}>`:t=`${e.type}`;break;case"list":if(e.dimensions&&typeof e.elements=="string"&&Dt.has(e.elements)){if(e.dimensions===void 0)e.elements==="number"&&(t="tensor");else if(e.dimensions.length===1)e.elements==="number"?e.dimensions[0]<0?t="vector":t=`vector<${e.dimensions[0]}>`:e.dimensions[0]<0?t=`vector<${V(e.elements)}>`:t=`vector<${V(e.elements)}^${e.dimensions[0]}>`;else if(e.dimensions.length===2){let u=e.dimensions;e.elements==="number"?u[0]<0&&u[1]<0?t="matrix":t=`matrix<${u[0]}x${u[1]}>`:u[0]<0&&u[1]<0?t=`matrix<${V(e.elements)}>`:t=`matrix<${V(e.elements)}^(${u[0]}x${u[1]})>`}}if(!t){let u=e.dimensions?e.dimensions.length===1?`^${e.dimensions[0].toString()}`:`^(${e.dimensions.join("x")})`:"";t=`list<${V(e.elements)}${u}>`}break;case"record":t=`record<${Object.entries(e.elements).map(([u,l])=>`${u}: ${V(l)}`).join(", ")}>`;break;case"dictionary":t=`dictionary<${V(e.values)}>`;break;case"set":t=`set<${V(e.elements)}>`;break;case"collection":t=`collection<${V(e.elements)}>`;break;case"indexed_collection":t=`indexed_collection<${V(e.elements)}>`;break;case"tuple":if(e.elements.length===0)t="tuple";else if(e.elements.length===1){let[u]=e.elements;t=`tuple<${Mn(u)}>`}else t="tuple<"+e.elements.map(u=>Mn(u)).join(", ")+">";break;case"signature":let r=e.args?e.args.map(u=>Mn(u)).join(", "):"",s=e.optArgs?e.optArgs.map(u=>Mn(u)+"?").join(", "):"",o=e.variadicArg?e.variadicMin===0?`${Mn(e.variadicArg)}*`:`${Mn(e.variadicArg)}+`:"";t=`(${[r,s,o].filter(u=>u).join(", ")}) -> ${V(e.result)}`;break;default:t="error"}return n>0&&n>dc(e.kind)?`(${t})`:t}function Mn(e){return e.name?`${e.name}: ${V(e.type)}`:V(e.type)}function jo(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)?e:`\`${e}\``}function dc(e){switch(e){case"negation":return Uo;case"union":return Ho;case"intersection":return Zo;case"list":return oc;case"record":return ac;case"dictionary":return uc;case"set":return lc;case"collection":case"indexed_collection":return cc;case"tuple":return fc;case"signature":return pc;case"value":return mc;default:return 0}}function Xi(e){if(e){if(e==="function")return"any";if(typeof e!="string"&&e.kind==="signature")return e.result}}function Ce(e){if(e==="collection"||e==="indexed_collection"||e==="list"||e==="set"||e==="tuple"||e==="dictionary"||e==="record")return"any";if(typeof e!="string"){if(e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="list"||e.kind==="set")return e.elements;if(e.kind==="tuple")return ge(...e.elements.map(n=>n.type));if(e.kind==="dictionary")return U(`tuple<string, ${V(e.values)}>`);if(e.kind==="record")return U(`tuple<string, ${V(ge(...Object.values(e.elements)))}>`)}}var pe=class e{static unknown=new e("unknown");static number=new e("number");static non_finite_number=new e("non_finite_number");static finite_number=new e("finite_number");static finite_integer=new e("finite_integer");static finite_real=new e("finite_real");static string=new e("string");static dictionary=new e("dictionary");static setNumber=new e("set<number>");static setComplex=new e("set<complex>");static setImaginary=new e("set<imaginary>");static setReal=new e("set<real>");static setRational=new e("set<rational>");static setFiniteInteger=new e("set<finite_integer>");static setInteger=new e("set<integer>");type;static widen(...n){return new e(ge(...n.map(t=>t instanceof e?t.type:t)))}static narrow(...n){return new e(Wi(...n.map(t=>t instanceof e?t.type:t)))}constructor(n,t){typeof n=="string"?this.type=U(n,t):this.type=n}matches(n){return n instanceof e?w(this.type,n.type):w(this.type,n)}is(n){return w(this.type,n)&&w(n,this.type)}get isUnknown(){return this.type==="unknown"}toString(){return V(this.type)}toJSON(){return V(this.type)}[Symbol.toPrimitive](n){return n==="string"?this.toString():null}valueOf(){return V(this.type)}};function R(e){return e?._kind==="number"}function T(e,n){return e?._kind==="symbol"&&(n===void 0||e.symbol===n)}function h(e,n){return(e?._kind==="function"||e?._kind==="tensor")&&(n===void 0||e.operator===n)}function le(e){return e?._kind==="string"}function K(e){return e?._kind==="symbol"?e.symbol:void 0}var lh=Object.freeze({bySubject:new Map,membership:new Map});var hh=[0,-1,1,Math.PI,Math.E,-Math.PI,-Math.E,.5,-.5];function Ue(e){if(!e)return;if(e.operator==="Function"&&e.isCanonical||T(e))return e;if(h(e,"BuiltinFunction"))return e.op1;if(h(e,"Delimiter")){let s=e.op1;if(h(s,"Sequence"))if(s.nops===1)e=s;else return Ue(e.engine._fn("Block",s.ops,{canonical:!1}));return Ue(h(e)?e.op1:void 0)}if(h(e,"Function"))return Yo(e.engine,e.ops);e.operator;let n=e.engine,t=e.subs({_:"_1"}),i=1,r=[];for(;i<10;)t.has(`_${i}`)&&r.push(t.engine.symbol(`_${i}`,{canonical:!1})),i++;if(r.length===0){t.operator!=="Block"?t=n.function("Block",[t]):t=t.canonical;let s=t.unknowns;s.length>0&&(r=s.map(o=>n.symbol(o,{canonical:!1})))}return Yo(n,[t,...r])}function Yo(e,n){if(n.length===0)return;let t=n[0].operator==="Block"?n[0].canonical:e.function("Block",[n[0]]),i=n.slice(1).map(r=>T(r)?r:e.error("expected-a-symbol",r.toString()));t.isScoped;for(let r of i)T(r)&&!t.localScope.bindings.has(r.symbol)&&e.declare(r.symbol,{inferred:!0,type:"unknown"},t.localScope);return e._fn("Function",[t,...i])}function Wo(e,n){let t=e.Nothing;for(let i of n){let r=i.operator;if(r==="Return"&&h(i)){t=i.op1.evaluate();break}if((r==="Break"||r==="Continue")&&h(i)){t=e.expr([r,i.op1.evaluate()]);break}t=i.evaluate()}return t}function Xo(e,n){let t=[];for(let i of n){if(!i)continue;let r=e.bindings.get(i);r&&(t.push([i,r]),e.bindings.delete(i))}return t}function Qo(e,n){for(let[t,i]of n)e.bindings.set(t,i)}function Ko(e,n,t){if(n.operator==="Function"&&h(n)){let i=n.op1;if(i&&h(i)&&i.localScope){let r=new Set(n.ops.slice(1).map(u=>T(u)?u.symbol:"").filter(u=>u)),s=new Map;for(let[u,l]of i.localScope.bindings)r.has(u)&&s.set(u,l);let o={parent:t,bindings:s},a=e._fn("Block",i.ops,{scope:o});return e._fn("Function",[a,...n.ops.slice(1)])}return n}if(h(n)&&n.ops.length>0){let i=!1,r=n.ops.map(s=>{let o=Ko(e,s,t);return o!==s&&(i=!0),o});if(i)return e._fn(n.operator,r)}return n}function yc(e){let n=e.engine;if(T(e)){let a=e.symbol;return u=>n.function(a,u).evaluate()}let t=Ue(e);if(!t)throw new Error("Invalid function literal");e=t,e.operator,e.isCanonical;let i=e;if(i.ops.length===1)return i.ops[0],()=>i.ops[0].evaluate();let[r,...s]=i.ops;if(r.isScoped,!r.localScope)throw new Error("Function body must be a scoped Block expression");let o=r;return a=>{if(a.length>s.length)throw new Error(`Too many arguments for function "${e.toString()}": expected ${s.length}, got ${a.length}`);if(n.strict&&!a.every(N=>N.isValid))return;if(a.length<s.length){let N=new Set([...r.symbols,...s.map(te=>T(te)?te.symbol:"")]),M=s.slice(a.length).map((te,Je)=>{let ze=`_${Je+1}`,St=0;for(;N.has(ze);)ze=`_${Je+1}_${St++}`;return N.add(ze),n.symbol(ze,{canonical:!1})}),$=Object.fromEntries(s.slice(a.length).map((te,Je)=>[T(te)?te.symbol:"",M[Je]])),P=a.map(te=>te.evaluate()),H={parent:o.localScope.parent??n.context.lexicalScope,bindings:new Map};for(let te=0;te<a.length;te++){let Je=s[te],ze=T(Je)?Je.symbol:"";ze&&n.declare(ze,{value:P[te],inferred:!0},H)}let O=o.localScope,ue=O.parent;O.parent=H;let Z=s.slice(0,a.length).map(te=>T(te)?te.symbol:""),se=Xo(O,Z);n.pushScope(H);let oe;try{oe=Wo(n,o.ops)}finally{n.popScope(),O.parent=ue,Qo(O,se)}return n.function("Function",[oe.subs($),...M])}let u=a.map(N=>N.evaluate()),c={parent:o.localScope.parent??n.context.lexicalScope,bindings:new Map},f=s.map(N=>T(N)?N.symbol:"");for(let N=0;N<s.length;N++)f[N]&&n.declare(f[N],{value:u[N],inferred:!0},c);let d=o.localScope,m=d.parent;d.parent=c;let g=Xo(d,f);n.pushScope(c);let v;try{v=Wo(n,o.ops),v=Ko(n,v,c)}finally{n.popScope(),d.parent=m,Qo(d,g)}return v.isValid?v:void 0}}function ie(e){return yc(e)??(n=>e.engine.function("Apply",[e,...n]).evaluate())}var Qi=100;function Bt(e){return(e.isFiniteCollection??!1)&&e.isIndexedCollection}function xc(e,n,t){if(!(e.isFiniteCollection!==!0||n.isFiniteCollection!==!0)){for(let i of e.each())if(n.contains(i)!==!0)return!1;if(t){let i=e.count;if(i===void 0)return!1;let r=n.count;if(r===void 0||i===r)return!1}return!0}}function vc(e,n){if(h(e)){for(let t=0;t!==e.nops;t+=1)if(n(e.ops[t]))return t+1}}function Vt(){return{isLazy:e=>!1,count:e=>h(e)?e.nops:0,isEmpty:e=>!h(e)||e.nops===0,isFinite:e=>!0,contains:(e,n)=>h(e)?e.ops.some(t=>t.isSame(n)):!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=1,t=e.nops;return{next:()=>n===t+1?{value:void 0,done:!0}:(n+=1,{value:e.ops[n-1-1],done:!1})}},subsetOf:xc,at:(e,n)=>{if(!(typeof n!="number"||!h(e))&&(n<0&&(n=e.nops+n+1),!(n<1||n>e.nops)))return e.ops[n-1]},indexWhere:vc,eltsgn:e=>{},elttype:e=>!h(e)||e.nops===0?"unknown":e.nops===1?e.ops[0].type.type:ge(...e.ops.map(n=>n.type.type))}}var wn=class extends Error{cause;value;constructor({message:n,value:t,cause:i}={}){super(n??"Operation canceled"),t&&(this.value=t),this.cause=i,this.name="CancellationError"}};function Ki(e,n){let t=Date.now();for(;;){let{done:i,value:r}=e.next();if(i)return r;if(Date.now()-t>=n)throw new wn({value:r,cause:"timeout",message:`Timeout exceeded (${n}ms)`})}}function I(e){let n="",t="";for(let i of e)i!=null&&(typeof i=="string"&&(/[a-zA-Z]/.test(i[0])&&(t+=n),/\\[a-zA-Z]+\*?$/.test(i)?n=" ":n=""),t+=i.toString());return t}function An(e,n,t){return n.includes(e)&&(n=`{${n}}`),/^[0-9]$/.test(t)?`${n}${e}${t}`:`${n}${e}{${t}}`}var F=245,tt=260,He=270,ee=275,be=390,Ne=600;var it=700,er=810;var hn=[{latexTrigger:["\\not","<"],kind:"infix",associativity:"any",precedence:246,parse:"NotLess"},{name:"NotLess",latexTrigger:["\\nless"],kind:"infix",associativity:"any",precedence:246},{latexTrigger:["<"],kind:"infix",associativity:"any",precedence:245,parse:"Less"},{name:"Less",latexTrigger:["\\lt"],kind:"infix",associativity:"any",precedence:245},{latexTrigger:["<","="],kind:"infix",associativity:"any",precedence:241,parse:"LessEqual"},{name:"LessEqual",latexTrigger:["\\le"],kind:"infix",associativity:"any",precedence:241},{latexTrigger:["\\leq"],kind:"infix",associativity:"any",precedence:241,parse:"LessEqual"},{latexTrigger:["\\leqslant"],kind:"infix",associativity:"any",precedence:F+5,parse:"LessEqual"},{name:"LessNotEqual",latexTrigger:["\\lneqq"],kind:"infix",associativity:"any",precedence:F},{name:"NotLessNotEqual",latexTrigger:["\\nleqq"],kind:"infix",associativity:"any",precedence:F},{name:"LessOverEqual",latexTrigger:["\\leqq"],kind:"infix",associativity:"any",precedence:F+5},{name:"GreaterOverEqual",latexTrigger:["\\geqq"],kind:"infix",associativity:"any",precedence:F+5,parse:"GreaterEqual"},{name:"Equal",latexTrigger:["="],kind:"infix",associativity:"right",precedence:F},{latexTrigger:["*","="],kind:"infix",associativity:"right",precedence:F,parse:"StarEqual"},{name:"StarEqual",latexTrigger:["\\star","="],kind:"infix",associativity:"right",precedence:F},{name:"PlusEqual",latexTrigger:["+","="],kind:"infix",associativity:"right",precedence:F},{name:"MinusEqual",latexTrigger:["-","="],kind:"infix",associativity:"right",precedence:F},{name:"SlashEqual",latexTrigger:["/","="],kind:"infix",associativity:"right",precedence:F},{name:"EqualEqual",latexTrigger:["=","="],kind:"infix",associativity:"right",precedence:F},{name:"EqualEqualEqual",latexTrigger:["=","=","="],kind:"infix",associativity:"right",precedence:F+5},{name:"TildeFullEqual",latexTrigger:["\\cong"],kind:"infix",associativity:"right",precedence:F},{name:"NotTildeFullEqual",latexTrigger:["\\ncong"],kind:"infix",associativity:"right",precedence:F},{name:"Approx",latexTrigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"NotApprox",latexTrigger:["\\not","\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"ApproxEqual",latexTrigger:["\\approxeq"],kind:"infix",associativity:"right",precedence:F},{name:"NotApproxEqual",latexTrigger:["\\not","\\approxeq"],kind:"infix",associativity:"right",precedence:250},{name:"NotEqual",latexTrigger:["\\ne"],kind:"infix",associativity:"right",precedence:255},{name:"Unequal",latexTrigger:["!","="],kind:"infix",associativity:"right",precedence:F},{name:"GreaterEqual",latexTrigger:["\\ge"],kind:"infix",associativity:"right",precedence:242},{latexTrigger:["\\geq"],kind:"infix",associativity:"right",precedence:242,parse:"GreaterEqual"},{latexTrigger:[">","="],kind:"infix",associativity:"right",precedence:243,parse:"GreaterEqual"},{latexTrigger:["\\geqslant"],kind:"infix",associativity:"right",precedence:F+5,parse:"GreaterEqual"},{name:"GreaterNotEqual",latexTrigger:["\\gneqq"],kind:"infix",associativity:"right",precedence:F},{name:"NotGreaterNotEqual",latexTrigger:["\\ngeqq"],kind:"infix",associativity:"right",precedence:F},{latexTrigger:[">"],kind:"infix",associativity:"right",precedence:245,parse:"Greater"},{name:"Greater",latexTrigger:["\\gt"],kind:"infix",associativity:"right",precedence:245},{name:"NotGreater",latexTrigger:["\\ngtr"],kind:"infix",associativity:"right",precedence:244},{latexTrigger:["\\not",">"],kind:"infix",associativity:"right",precedence:244,parse:"NotGreater"},{name:"RingEqual",latexTrigger:["\\circeq"],kind:"infix",associativity:"right",precedence:F},{name:"TriangleEqual",latexTrigger:["\\triangleq"],kind:"infix",associativity:"right",precedence:F},{name:"DotEqual",latexTrigger:["\\doteq"],kind:"infix",associativity:"right",precedence:F+5},{name:"DotEqualDot",latexTrigger:["\\doteqdot"],kind:"infix",associativity:"right",precedence:F+5},{name:"FallingDotEqual",latexTrigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:F+5},{name:"RisingDotEqual",latexTrigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:F+5},{name:"QuestionEqual",latexTrigger:["\\questeq"],kind:"infix",associativity:"right",precedence:F},{name:"MuchLess",latexTrigger:["\\ll"],kind:"infix",associativity:"right",precedence:F},{name:"MuchGreater",latexTrigger:["\\gg"],kind:"infix",associativity:"right",precedence:F},{name:"Precedes",latexTrigger:["\\prec"],kind:"infix",associativity:"right",precedence:F},{name:"Succeeds",latexTrigger:["\\succ"],kind:"infix",associativity:"right",precedence:F},{name:"PrecedesEqual",latexTrigger:["\\preccurlyeq"],kind:"infix",associativity:"right",precedence:F},{name:"SucceedsEqual",latexTrigger:["\\curlyeqprec"],kind:"infix",associativity:"right",precedence:F},{name:"NotPrecedes",latexTrigger:["\\nprec"],kind:"infix",associativity:"right",precedence:F},{name:"NotSucceeds",latexTrigger:["\\nsucc"],kind:"infix",associativity:"right",precedence:F},{name:"Between",latexTrigger:["\\between"],kind:"infix",associativity:"right",precedence:F+5}];function nr(e){return typeof e!="string"?!1:hn.some(n=>n.name===e)}function tr(e){return typeof e!="string"?!1:["Less","LessEqual","Greater","GreaterEqual"].includes(e)}function ir(e){return typeof e!="string"?!1:["Equal","NotEqual"].includes(e)}var $n=["Error","'missing'"];function gn(e){return!!(typeof e=="number"||Cn(e)||typeof e=="string"&&Gt(e))}function Cn(e){return e!==null&&typeof e=="object"&&"num"in e}function qt(e){return e!==null&&typeof e=="object"&&"sym"in e}function ta(e){return e!==null&&typeof e=="object"&&"str"in e}function ia(e){return e!==null&&typeof e=="object"&&"dict"in e&&typeof e.dict=="object"&&!Array.isArray(e.dict)&&e.dict!==null}function Rn(e){return e!==null&&typeof e=="object"&&"fn"in e&&Array.isArray(e.fn)&&e.fn.length>0&&typeof e.fn[0]=="string"}function q(e){return e==null?null:typeof e=="object"&&"str"in e?e.str:typeof e!="string"?null:e.length>=2&&e.at(0)==="'"&&e.at(-1)==="'"?e.substring(1,e.length-1):Gt(e)||ar(e)?null:e}function sr(e){if(e==null||q(e)!==null)return null;let n=x(e);return n?[n,..._(e).map(t=>sr(t)).filter(t=>t!==null)]:e}function x(e){return Array.isArray(e)?e[0]:e==null?"":Rn(e)?e.fn[0]:""}function _(e){return Array.isArray(e)?e.slice(1):e!==void 0&&Rn(e)?e.fn.slice(1):[]}function p(e,n){return Array.isArray(e)?e[n]??null:e===null||!Rn(e)?null:e.fn[n]??null}function X(e){return e==null?0:Array.isArray(e)?Math.max(0,e.length-1):Rn(e)?Math.max(0,e.fn.length-1):0}function or(e){return e==null?null:x(e)==="Hold"?p(e,1):e}function k(e){return typeof e=="string"&&ar(e)?e.length>=2&&e.at(0)==="`"&&e.at(-1)==="`"?e.slice(1,-1):e:e==null?null:qt(e)?e.sym:null}function ea(e){let n=x(e);if(n==="KeyValuePair"||n==="Tuple"||n==="Pair"){let[t,i]=_(e),r=q(t);return r?[r,i??"Nothing"]:null}return null}function ra(e){if(e===null)return null;if(ia(e))return e;let n=ea(e);if(n)return{dict:{[n[0]]:na(n[1])??"Nothing"}};if(x(e)==="Dictionary"){let t={};for(let i of _(e)){let r=ea(i);r&&(t[r[0]]=na(r[1])??"Nothing")}return{dict:t}}return null}function Jt(e){return{dict:Object.fromEntries(Object.entries(e).map(([t,i])=>[t,rr(i)??"Nothing"]))}}function Ic(e){if(e=e.toLowerCase().replace(/[nd]$/,"").replace(/[\u0009-\u000d\u0020\u00a0]/g,""),e==="nan")return NaN;if(/^(infinity|\+infinity|oo|\+oo)$/i.test(e))return 1/0;if(/^(-infinity|-oo)$/.test(e))return-1/0;if(/\([0-9]+\)/.test(e)){let[n,t,i,r]=e.match(/(.+)\(([0-9]+)\)(.*)$/)??[];e=t+i.repeat(Math.ceil(16/i.length))+(r??"")}return parseFloat(e)}function D(e){return typeof e=="number"?e:typeof e=="string"&&Gt(e)?Ic(e):e!==void 0&&Cn(e)?D(e.num):null}function Dn(e){if(e==null)return null;if(k(e)==="Half")return[1,2];let n=x(e);if(!n)return null;let t=null,i=null;if(n==="Negate"){let r=Dn(_(e)[0]);if(r)return[-r[0],r[1]]}if(n==="Rational"||n==="Divide"){let[r,s]=_(e);t=D(r)??NaN,i=D(s)??NaN}if(n==="Power"){let[r,s]=_(e),o=D(s);o===1?(t=D(r),i=1):o===-1&&(t=1,i=D(r))}if(n==="Multiply"){let[r,s]=_(e);if(x(s)==="Power"){let[o,a]=_(s);D(a)===-1&&(t=D(r),i=D(o))}}return t===null||i===null?null:Number.isInteger(t)&&Number.isInteger(i)?[t,i]:null}function zt(e,n){let t=null;if(Array.isArray(e)&&(t=e),Rn(e)&&(t=e.fn),t===null)return[];let i=1,r=[];for(;i<t.length;)r.push(n(t[i])),i+=1;return r}function Pn(e,n,t){let i=x(n),r=x(t);return i===e&&r===e?[e,..._(n),..._(t)]:i===e?[e,..._(n),t]:r===e?[e,n,..._(t)]:[e,n,t]}function bn(e){if(e==null)return null;let n=x(e);if(n==="Delimiter"){if(e=p(e,1),e===null)return[];if(n=x(e),n!=="Sequence")return[e]}return n!=="Sequence"?null:_(e)}function G(e){return e==null||e==="Nothing"?!0:x(e)==="Sequence"&&X(e)===0}function j(e){return G(e)?$n:e}function Gt(e){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(e)||/^[+-]?(0|[1-9][0-9]*)(\.[0-9]+)?(\([0-9]+\))?([eE][+-]?[0-9]+)?$/.test(e)}function ar(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)||e.length>=2&&e[0]==="`"&&e[e.length-1]==="`"}function rr(e){if(typeof e=="string")return{str:e};if(typeof e=="number")return{num:e.toString()};if(typeof e=="boolean")return e?"True":"False";if(Array.isArray(e))return["List",...e.map(n=>rr(n)??"Nothing")];if(e===null)return null;if(typeof e=="object"){let n={};for(let t in e)n[t]=rr(e[t])??"Nothing";return{dict:n}}return Rn(e)||qt(e)||Cn(e)||ta(e)||ia(e)?e:null}function na(e){return e==null?null:ta(e)?e.str:Cn(e)?parseFloat(e.num):qt(e)?e.sym:typeof e=="string"||typeof e=="number"?e:Array.isArray(e)?{fn:e}:e}var oa=[{name:"True",kind:"symbol",latexTrigger:["\\top"]},{kind:"symbol",latexTrigger:"\\mathrm{True}",parse:"True"},{kind:"symbol",latexTrigger:"\\operatorname{True}",parse:"True"},{kind:"symbol",latexTrigger:"\\mathsf{T}",parse:"True"},{name:"False",kind:"symbol",latexTrigger:["\\bot"]},{kind:"symbol",latexTrigger:"\\operatorname{False}",parse:"False"},{kind:"symbol",latexTrigger:"\\mathsf{F}",parse:"False"},{name:"And",kind:"infix",latexTrigger:["\\land"],precedence:235},{kind:"infix",latexTrigger:["\\wedge"],parse:"And",precedence:235},{kind:"infix",latexTrigger:"\\&",parse:"And",precedence:235},{kind:"infix",latexTrigger:"\\operatorname{and}",parse:"And",precedence:235},{name:"Or",kind:"infix",latexTrigger:["\\lor"],precedence:230},{kind:"infix",latexTrigger:["\\vee"],parse:"Or",precedence:230},{kind:"infix",latexTrigger:"\\parallel",parse:"Or",precedence:230},{kind:"infix",latexTrigger:"\\operatorname{or}",parse:"Or",precedence:230},{name:"Xor",kind:"infix",latexTrigger:["\\veebar"],precedence:232},{name:"Not",kind:"prefix",latexTrigger:["\\lnot"],precedence:880},{kind:"prefix",latexTrigger:["\\neg"],parse:"Not",precedence:880},{name:"Nand",kind:"infix",latexTrigger:["\\barwedge"],precedence:232},{name:"Nor",kind:"infix",latexTrigger:["\u22BD"],precedence:232},{kind:"function",symbolTrigger:"and",parse:"And"},{kind:"function",symbolTrigger:"or",parse:"Or"},{kind:"function",symbolTrigger:"not",parse:"Not"},{name:"Implies",kind:"infix",precedence:220,associativity:"right",latexTrigger:["\\implies"],serialize:"\\implies"},{latexTrigger:["\\Rightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["\\rightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["\\Longrightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["\\longrightarrow"],kind:"infix",precedence:220,associativity:"right",parse:"Implies"},{latexTrigger:["=",">"],kind:"infix",precedence:220,associativity:"right",parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:220});return i===null?null:["Implies",n,i]}},{name:"Equivalent",latexTrigger:["\\iff"],kind:"infix",associativity:"right",precedence:219},{latexTrigger:["\\Leftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["\\leftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["\\Longleftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["\\longleftrightarrow"],kind:"infix",associativity:"right",precedence:219,parse:"Equivalent"},{latexTrigger:["<","=",">"],kind:"infix",precedence:219,associativity:"right",parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:219});return i===null?null:["Equivalent",n,i]}},{latexTrigger:["\\equiv"],kind:"infix",associativity:"right",precedence:219,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:219}),r=e.index,s=e.parseExpression({...t,minPrec:219});return s!==null&&x(s)==="Mod"?["Congruent",n,i,j(p(s,1))]:(e.index=r,["Equivalent",n,j(i)])}},{name:"Proves",kind:"infix",latexTrigger:["\\vdash"],precedence:220,associativity:"right",serialize:"\\vdash"},{name:"Entails",kind:"infix",latexTrigger:["\\vDash"],precedence:220,associativity:"right",serialize:"\\vDash"},{name:"Satisfies",kind:"infix",latexTrigger:["\\models"],precedence:220,associativity:"right",serialize:"\\models"},{name:"ForAll",kind:"prefix",latexTrigger:["\\forall"],precedence:200,serialize:rt("\\forall"),parse:tn("ForAll")},{name:"Exists",kind:"prefix",latexTrigger:["\\exists"],precedence:200,serialize:rt("\\exists"),parse:tn("Exists")},{name:"ExistsUnique",kind:"prefix",latexTrigger:["\\exists","!"],precedence:200,serialize:rt("\\exists!"),parse:tn("ExistsUnique")},{name:"NotForAll",kind:"prefix",latexTrigger:["\\lnot","\\forall"],precedence:200,serialize:rt("\\lnot\\forall"),parse:tn("NotForAll")},{name:"NotExists",kind:"prefix",latexTrigger:["\\lnot","\\exists"],precedence:200,serialize:rt("\\lnot\\exists"),parse:tn("NotExists")},{name:"KroneckerDelta",kind:"prefix",latexTrigger:["\\delta","_"],precedence:200,serialize:(e,n)=>{let t=_(n);return t.length===0?"\\delta":t.every(i=>k(i))?`\\delta_{${t.map(i=>e.serialize(i)).join("")}}`:`\\delta_{${t.map(i=>e.serialize(i)).join(", ")}}`},parse:e=>{let n=e.parseGroup();if(n===null){let i=e.parseToken();return i?["KroneckerDelta",i]:null}let t=bn(n);return t&&t.length<=2?["KroneckerDelta",...t]:x(n)==="InvisibleOperator"?["KroneckerDelta",..._(n)]:n!==null?["KroneckerDelta",n]:null}},{name:"Boole",kind:"matchfix",openTrigger:"[",closeTrigger:"]",parse:(e,n)=>{let t=x(n);return!t||!hn.some(i=>i.name===t)?null:["Boole",n]}},{kind:"matchfix",openTrigger:"\\llbracket",closeTrigger:"\\rrbracket",parse:(e,n)=>{let t=x(n);return!t||!hn.some(i=>i.name===t)?null:["Boole",n]}},{name:"Predicate",serialize:(e,n)=>{let t=_(n);if(t.length===0)return"";let i=t[0],r=typeof i=="string"?i:e.serialize(i);if(t.length===1)return r;let s=t.slice(1).map(o=>e.serialize(o));return`${r}(${s.join(", ")})`}}];function rt(e){return(n,t)=>{let i=_(t);if(i.length===0)return e;if(i.length===1)return`${e} ${n.serialize(i[0])}`;let r=n.serialize(i[0]),s=n.serialize(i[1]);return`${e} ${r}, ${s}`}}function sa(e,n){return e.peek==="\\to"||e.peek==="\\rightarrow"||e.peek==="\\implies"||e.peek==="\\Rightarrow"||e.peek==="\\iff"||e.peek==="\\Leftrightarrow"||e.peek==="\\land"||e.peek==="\\wedge"||e.peek==="\\lor"||e.peek==="\\vee"||(n.condition?.(e)??!1)}function tn(e){return(n,t)=>{let i=n.index,r=n.options.quantifierScope!=="loose",s=n.parseSymbol(t);if(s){if(n.skipSpace(),n.match(",")||n.match("\\mid")||n.match(".")||n.match(":")||n.match("\\colon")){let l=r?{...t,condition:f=>sa(f,t)}:t;n.enterQuantifierScope();let c=n.parseExpression(l);return n.exitQuantifierScope(),[e,s,j(c)]}n.enterQuantifierScope();let u=n.parseEnclosure();if(n.exitQuantifierScope(),u)return[e,s,j(u)]}n.index=i;let o={...t,condition:u=>u.peek===":"||u.peek==="\\colon"||(t.condition?.(u)??!1)},a=n.parseExpression(o);if(a===null)return null;if(n.skipSpace(),n.matchAny([",","\\mid",":","\\colon"])){let u=r?{...t,condition:c=>sa(c,t)}:t;n.enterQuantifierScope();let l=n.parseExpression(u);return n.exitQuantifierScope(),[e,a,j(l)]}if(n.match("(")){n.enterQuantifierScope();let u=n.parseExpression(t);return n.exitQuantifierScope(),n.match(")")?[e,a,j(u)]:null}return null}}var _c={x:"First",y:"Second",z:"Third",real:"Real",re:"Real",imag:"Imaginary",im:"Imaginary",count:"Length",total:"Sum",max:"Max",min:"Min"};function ur(e){return _c[e]??null}function Sc(e,n){if(e.skipVisualSpace(),e.match("\\operatorname")){let i=e.parseStringGroup();if(i===null)return null;let r=ur(i.trim());return r===null?null:[r,n]}let t=e.peek;if(typeof t=="string"&&t.startsWith("\\")){let i=t.slice(1),r=ur(i);return r!==null?(e.nextToken(),[r,n]):null}if(typeof t=="string"&&/^[a-zA-Z]$/.test(t)){let i=ur(t);return i===null?null:(e.nextToken(),[i,n])}return null}function aa(e,n,t){e.addBoundary(t),e.skipVisualSpace();let i=e.parseExpression({minPrec:0});return i===null||(e.skipVisualSpace(),!e.matchBoundary())?(e.removeBoundary(),null):["When",n,i]}function lr(e,n,t,i,r){if(n&&n.minPrec>=i)return null;let s=t?[t]:["Nothing"],o=!1;for(;!o;){for(o=!0,e.skipSpace();e.match(r);)s.push("Nothing"),e.skipSpace();if(e.skipVisualSpace(),e.atTerminator(n))s.push("Nothing");else{let a=e.parseExpression({...n,minPrec:i});s.push(a??"Nothing"),o=a===null}o||(e.skipSpace(),o=!e.match(r),o||e.skipVisualSpace())}return s}function De(e=""){return(n,t)=>{if(!t)return"";let i=_(t);if(i.length===0)return"";if(i.length===1)return n.serialize(i[0]);e={"&":"\\&",":":"\\colon","|":"\\mvert","-":"-","\xB7":"\\cdot","\u2012":"-","\u2013":"--","\u2014":"---","\u2015":"-","\u2022":"\\bullet","\u2026":"\\ldots"}[e]??e;let r=i.reduce((s,o)=>(s.push(n.serialize(o),e),s),[]);return r.pop(),I(r)}}var ma=[{latexTrigger:["\\placeholder"],kind:"symbol",parse:e=>{for(;e.match("<space>"););if(e.match("["))for(;!e.match("]")&&!e.atBoundary;)e.nextToken();for(;e.match("<space>"););if(e.match("<{>"))for(;!e.match("<}>")&&!e.atBoundary;)e.nextToken();return"Nothing"}},{name:"ContinuationPlaceholder",latexTrigger:["\\dots"]},{latexTrigger:["\\ldots"],parse:"ContinuationPlaceholder"},{latexTrigger:[".",".","."],parse:"ContinuationPlaceholder"},{name:"Function",latexTrigger:["\\mapsto"],kind:"infix",precedence:He,parse:(e,n,t)=>{let i=[];if(x(n)==="Delimiter"&&(n=p(n,1)??"Nothing"),x(n)==="Sequence")for(let s of _(n)){if(!k(s))return null;i.push(k(s))}else{if(!k(n))return null;i=[k(n)]}let r=e.parseExpression({minPrec:He})??"Nothing";return x(r)==="Delimiter"&&(r=p(r,1)??"Nothing"),x(r)==="Sequence"&&(r=["Block",..._(r)]),["Function",r,...i]},serialize:(e,n)=>{let t=_(n);return t.length<1?"()\\mapsto()":t.length===1?I(["()","\\mapsto",e.serialize(p(n,1))]):t.length===2?I([e.serialize(p(n,2)),"\\mapsto",e.serialize(p(n,1))]):I([e.wrapString(_(n)?.slice(1).map(i=>e.serialize(i)).join(", "),"normal"),"\\mapsto",e.serialize(p(n,1))])}},{name:"Apply",kind:"function",symbolTrigger:"apply",serialize:(e,n)=>{let t=p(n,1),i=x(t);if(i==="InverseFunction"||i==="Derivative"){let o=e.options.applyFunctionStyle(n,e.level),a=_(n).slice(1);return e.serializeFunction(t,e.dictionary.ids.get(i))+e.wrapString(a.map(u=>e.serialize(u)).join(", "),o)}let r=p(n,2);if(typeof t=="string"||!r){let o=_(n).slice(1);return e.serialize(o)}if(X(n)===2)return I([e.wrap(t,20),"\\lhd",e.wrap(r,20)]);let s=e.options.applyFunctionStyle(n,e.level);return I(["\\operatorname{apply}",e.wrapString(e.serialize(i)+", "+e.serialize(["List",..._(n)]),s)])}},{latexTrigger:"\\lhd",kind:"infix",precedence:20,parse:"Apply"},{latexTrigger:"\\rhd",kind:"infix",precedence:20,parse:(e,n,t)=>["Apply",e.parseExpression({minPrec:21})??"Nothing",n]},{name:"EvaluateAt",openTrigger:".",closeTrigger:"|",kind:"matchfix",serialize:(e,n)=>{let t=p(n,1);if(!t)return"";let i=_(n).slice(1);if(x(t)==="Function"){let r=_(t).slice(1),s=p(t,1);if(x(s)==="Block"&&X(s)===1&&(s=p(s,1)),r.length>0)return`\\left.\\left(${e.serialize(s)}\\right)\\right|_{${r.map((o,a)=>`${e.serialize(o)}=${e.serialize(i[a])}`).join(", ")}}`}return`\\left.\\left(${e.serialize(t)}\\right)\\right|_{${i.map(r=>e.serialize(r)).join(", ")}}`}},{name:"Assign",latexTrigger:"\\coloneq",kind:"infix",associativity:"right",precedence:tt,serialize:(e,n)=>{let t=or(p(n,1));if(x(p(n,2))==="Function"){let i=p(n,2),r=or(p(i,1)),s=_(i).slice(1);return I([e.serialize(t),e.wrapString(s.map(o=>e.serialize(o)).join(", "),e.options.applyFunctionStyle(n,e.level)),"\\coloneq",e.serialize(r)])}return I([e.serialize(t),"\\coloneq",e.serialize(p(n,2))])},parse:Ut},{latexTrigger:"\\coloneqq",kind:"infix",associativity:"right",precedence:tt,parse:Ut},{latexTrigger:"\\colonequals",kind:"infix",associativity:"right",precedence:tt,parse:Ut},{latexTrigger:[":","="],kind:"infix",associativity:"right",precedence:tt,parse:Ut},{name:"Colon",latexTrigger:":",kind:"infix",associativity:"right",precedence:240,serialize:(e,n)=>I([e.serialize(p(n,1)),"\\colon",e.serialize(p(n,2))])},{latexTrigger:"\\colon",kind:"infix",associativity:"right",precedence:240,parse:"Colon"},{name:"BaseForm",serialize:(e,n)=>{let t=D(p(n,2))??NaN;if(isFinite(t)&&t>=2&&t<=36){let i=D(p(n,1))??NaN;if(isFinite(i)&&Number.isInteger(i)){let r=Number(i).toString(t),s=0;if(t===2||t===10?s=4:t===16?s=2:t>16&&(s=4),s>0){let o=r;r="";for(let a=0;a<o.length;a++)a>0&&a%s===0&&(r="\\, "+r),r=o[o.length-a-1]+r}return`(\\text{${r}}_{${t}}`}}return"\\operatorname{BaseForm}("+e.serialize(p(n,1))+", "+e.serialize(p(n,2))+")"}},{name:"Sequence",serialize:De(" ")},{name:"InvisibleOperator",serialize:De("")},{name:"Delimiter",serialize:(e,n)=>{let t=e.options.groupStyle(n,e.level+1),i=p(n,1),r={Set:"{,}",List:"[,]",Tuple:"(,)",Single:"(,)",Pair:"(,)",Triple:"(,)",Sequence:"(,)",String:'""'}[x(i)],s=r?i:["Sequence",i];if(r??="(,)",X(n)>1){let c=q(p(n,2));typeof c=="string"&&c.length<=3&&(r=c)}let[o,a,u]=["","",""];r.length===3?[o,a,u]=r:r.length===2?[o,u]=r:r.length===1&&(a=r);let l=i?s?De(a)(e,s):e.serialize(i):"";return e.wrapString(l,t,o+u)}},{name:"Tuple",serialize:(e,n)=>I(["(",De(",")(e,n),")"])},{name:"Pair",serialize:(e,n)=>I(["(",De(",")(e,n),")"])},{name:"Triple",serialize:(e,n)=>I(["(",De(",")(e,n),")"])},{name:"Single",serialize:(e,n)=>I(["(",De(",")(e,n),")"])},{name:"Domain",serialize:(e,n)=>x(n)==="Error"?e.serialize(n):`\\mathbf{${e.serialize(p(n,1))}}`},{latexTrigger:["\\mathtip"],parse:e=>{let n=e.parseGroup();return e.parseGroup(),n}},{latexTrigger:["\\texttip"],parse:e=>{let n=e.parseGroup();return e.parseGroup(),n}},{latexTrigger:["\\error"],parse:e=>["Error",e.parseGroup()]},{name:"Error",serialize:(e,n)=>{let t=p(n,1);if(q(t)==="missing")return`\\error{${e.options.missingSymbol??"\\placeholder{}"}}`;let i=Mc(e,n)||"\\blacksquare",r=x(t)==="ErrorCode"?q(p(t,1)):q(t);return r==="incompatible-type"?k(p(t,3))==="Undefined"?`\\mathtip{\\error{${i}}}{\\notin ${e.serialize(p(t,2))}}`:`\\mathtip{\\error{${i}}}{\\in ${e.serialize(p(t,3))}\\notin ${e.serialize(p(t,2))}}`:typeof r=="string"?`\\error{${i}}`:`\\error{${i}}`}},{name:"ErrorCode",serialize:(e,n)=>{let t=q(p(n,1));return t==="missing"?e.options.missingSymbol??"\\placeholder{}":t==="unexpected-command"||t==="unexpected-operator"||t==="unexpected-token"||t==="invalid-symbol"||t==="unknown-environment"||t==="unexpected-base"||t==="incompatible-type"?"":`\\texttip{\\error{\\blacksquare}}{\\mathtt{${t}}}`}},{name:"FromLatex",serialize:(e,n)=>`\\texttt{${ua(q(p(n,1)))}}`},{name:"Latex",serialize:(e,n)=>n===null?"":I(zt(n,t=>q(t)??e.serialize(t)))},{name:"LatexString",serialize:(e,n)=>n===null?"":I(zt(n,t=>e.serialize(t)))},{name:"LatexTokens",serialize:kc},{kind:"postfix",precedence:850,latexTrigger:["."],parse:Sc},{name:"At",kind:"postfix",precedence:810,latexTrigger:["["],parse:fr("]"),serialize:(e,n)=>I(["\\lbrack",De(", ")(e,n),"\\rbrack"])},{kind:"postfix",precedence:810,latexTrigger:["\\lbrack"],parse:fr("\\rbrack")},{kind:"postfix",precedence:810,latexTrigger:["\\left","\\lbrack"],parse:fr("\\right","\\rbrack")},{name:"When",kind:"postfix",precedence:800,latexTrigger:["\\left","\\{"],parse:(e,n)=>aa(e,n,["\\right","\\}"]),serialize:(e,n)=>{let t=p(n,1),i=p(n,2);if(!t||!i)return"";let s=(x(i)==="And"?_(i)??[]:[i]).map(o=>`\\left\\{${e.serialize(o)}\\right\\}`).join("");return`${e.serialize(t)}${s}`}},{kind:"postfix",precedence:800,latexTrigger:["\\{"],parse:(e,n)=>aa(e,n,["\\}"])},{kind:"postfix",latexTrigger:["_"],parse:(e,n,t)=>{let i=e.parseGroup()??e.parseToken();i===null&&e.options.strict===!1&&e.peek==="("&&(i=e.parseEnclosure());let r=k(n);return i!==null&&(r&&e.getSymbolType(r).matches("indexed_collection")||x(n)==="List")?(x(i)==="Delimiter"&&(i=p(i,1)??"Nothing"),x(i)==="Sequence"?["At",n,..._(i)]:["At",n,i]):["Subscript",n,i]}},{name:"List",kind:"matchfix",openTrigger:"[",closeTrigger:"]",parse:da,serialize:Ac},{kind:"matchfix",openTrigger:"(",closeTrigger:")",parse:wc},{latexTrigger:[","],kind:"infix",precedence:20,parse:(e,n,t)=>{let i=lr(e,t,n,20,",");return i===null?null:["Delimiter",["Sequence",...i],{str:","}]}},{latexTrigger:[","],kind:"prefix",precedence:20,parse:(e,n)=>{let t=lr(e,n,null,20,",");return t===null?null:["Delimiter",["Sequence",...t],{str:","}]}},{name:"Range",latexTrigger:[".","."],kind:"infix",precedence:800,parse:jt,serialize:(e,n)=>{let t=_(n);if(t.length===0)return"";if(t.length===1)return"1.."+e.serialize(p(n,1));if(t.length===2)return e.wrap(p(n,1),10)+".."+e.wrap(p(n,2),10);if(t.length===3){let i=D(p(n,3)),r=D(p(n,1));return i!==null&&r!==null?e.wrap(p(n,1),10)+".."+e.wrap(r+i,10)+".."+e.wrap(p(n,2),10):e.wrap(p(n,1),10)+"..("+(e.wrap(p(n,1),ee)+"+"+e.wrap(p(n,3),ee))+").."+e.wrap(p(n,2),10)}return""}},{latexTrigger:[".",".","."],kind:"infix",precedence:800,parse:jt},{latexTrigger:["\\ldots"],kind:"infix",precedence:800,parse:jt},{latexTrigger:["\\dots"],kind:"infix",precedence:800,parse:jt},{latexTrigger:[";"],kind:"infix",precedence:19,parse:(e,n,t)=>{let i=lr(e,t,n,19,";");return i===null?null:i.some(r=>x(r)==="Assign")?$c(i):["Delimiter",["Sequence",...i],"';'"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"none",precedence:21,parse:(e,n,t)=>{let i=e.index;return ye(e,"where")?pa(e,n,t):(e.index=i,null)}},{symbolTrigger:"where",kind:"infix",associativity:"none",precedence:21,parse:(e,n,t)=>pa(e,n,t)},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:235,parse:(e,n,t)=>{let i=e.index;if(!ye(e,"and"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:235});return["And",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:230,parse:(e,n,t)=>{let i=e.index;if(!ye(e,"or"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:230});return["Or",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:219,parse:(e,n,t)=>{let i=e.index;if(!ye(e,"iff"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:219});return["Equivalent",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:219,parse:(e,n,t)=>{let i=e.index;if(!ye(e,"if and only if"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:219});return["Equivalent",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"infix",associativity:"right",precedence:21,parse:(e,n,t)=>{let i=e.index;if(!ye(e,"such that"))return e.index=i,null;let r=e.parseExpression({...t,minPrec:21});return["Colon",n,r??"Nothing"]}},{latexTrigger:["\\text"],kind:"prefix",precedence:200,parse:(e,n)=>{let t=e.index;return ye(e,"for all")?tn("ForAll")(e,n):(e.index=t,null)}},{latexTrigger:["\\text"],kind:"prefix",precedence:200,parse:(e,n)=>{let t=e.index;return ye(e,"there exists")?tn("Exists")(e,n):(e.index=t,null)}},{name:"Block",serialize:(e,n)=>{let t=_(n);return!t||t.length===0?"":t.filter(r=>x(r)!=="Declare").map(r=>e.serialize(r)).join("; ")}},{name:"If",serialize:(e,n)=>{let t=_(n);return!t||t.length<3?"":I(["\\text{if }",e.serialize(t[0]),"\\text{ then }",e.serialize(t[1]),"\\text{ else }",e.serialize(t[2])])}},{name:"Loop",serialize:(e,n)=>{let t=_(n);if(!t||t.length<2)return"";let i=t[0],r=t.slice(1);if(!r.every(a=>x(a)==="Element"))return I(["\\operatorname{Loop}(",e.serialize(i),", ",e.serialize(r[0]),")"]);if(r.length===1){let a=r[0],u=p(a,1),l=p(a,2);if(x(l)==="Range"){let c=p(l,1),f=p(l,2);return I(["\\text{for }",e.serialize(u),"\\text{ from }",e.serialize(c),"\\text{ to }",e.serialize(f),"\\text{ do }",e.serialize(i)])}return I([e.serialize(i)," \\operatorname{for} ",e.serialize(u)," = ",e.serialize(l)])}let o=r.map(a=>{let u=p(a,1),l=p(a,2);return I([e.serialize(u)," = ",e.serialize(l)])}).join(", ");return I([e.serialize(i)," \\operatorname{for} ",o])}},{name:"Break",serialize:()=>"\\text{break}"},{name:"Continue",serialize:()=>"\\text{continue}"},{name:"Return",serialize:(e,n)=>{let t=p(n,1);return!t||k(t)==="Nothing"?"\\text{return}":I(["\\text{return }",e.serialize(t)])}},{symbolTrigger:"if",kind:"prefix",precedence:245,parse:(e,n)=>ca(e,n)},{symbolTrigger:"for",kind:"prefix",precedence:245,parse:(e,n)=>fa(e,n)},{symbolTrigger:"for",kind:"infix",associativity:"none",precedence:19,parse:(e,n,t)=>ha(e,n,t)},{symbolTrigger:"break",kind:"prefix",precedence:245,parse:()=>["Break"]},{symbolTrigger:"continue",kind:"prefix",precedence:245,parse:()=>["Continue"]},{symbolTrigger:"return",kind:"prefix",precedence:245,parse:(e,n)=>["Return",e.parseExpression(n)??"Nothing"]},{name:"Text",serialize:(e,n)=>{let t=_(n);if(t.length===0)return"";let i=-1,r=-1;for(let a=0;a<t.length;a++)q(t[a])!==null&&(i<0&&(i=a),r=a);if(i<0)return I(t.map(a=>e.serialize(a)));let s=[];for(let a=0;a<i;a++)s.push(e.serialize(t[a]));let o="";for(let a=i;a<=r;a++){let u=q(t[a]);u!==null?o+=ua(u):x(t[a])==="Annotated"||x(t[a])==="Text"?o+=e.serialize(t[a]):o+="$"+e.serialize(t[a])+"$"}s.push("\\text{"+o+"}");for(let a=r+1;a<t.length;a++)s.push(e.serialize(t[a]));return I(s)}},{name:"String",latexTrigger:["\\text"],parse:(e,n)=>{let t=e.index;return ye(e,"if")?ca(e,n):(e.index=t,ye(e,"for")?fa(e,n):(e.index=t,ye(e,"break")?["Break"]:(e.index=t,ye(e,"continue")?["Continue"]:(e.index=t,ye(e,"return")?["Return",e.parseExpression(n)??"Nothing"]:(e.index=t,Re(e))))))},serialize:(e,n)=>{let t=_(n);return t.length===0?"\\text{}":I(["\\text{",t.map(i=>e.serialize(i)).join(""),"}"])}},{name:"Subscript",latexTrigger:["_"],kind:"infix",serialize:(e,n)=>X(n)===2?e.serialize(p(n,1))+"_{"+e.serialize(p(n,2))+"}":"_{"+e.serialize(p(n,1))+"}"},{name:"Superplus",latexTrigger:["^","+"],kind:"postfix"},{name:"Subplus",latexTrigger:["_","+"],kind:"postfix"},{name:"Superminus",latexTrigger:["^","-"],kind:"postfix",parse:(e,n)=>e.options.strict===!1&&/^[0-9]$/.test(e.peek)?null:["Superminus",n]},{name:"Subminus",latexTrigger:["_","-"],kind:"postfix"},{latexTrigger:["^","*"],kind:"postfix",parse:(e,n)=>["Superstar",n]},{latexTrigger:["_","*"],kind:"postfix",parse:(e,n)=>["Substar",n]},{name:"Substar",latexTrigger:["_","\\star"],kind:"postfix"},{name:"Superdagger",latexTrigger:["^","\\dagger"],kind:"postfix"},{latexTrigger:["^","\\dag"],kind:"postfix",parse:(e,n)=>["Superdagger",n]},{name:"Prime",latexTrigger:["^","\\prime"],kind:"postfix",parse:(e,n)=>Ze(e,n,1),serialize:(e,n)=>{let t=D(p(n,2))??1,i=e.serialize(p(n,1));return t===1?i+"^\\prime":t===2?i+"^\\doubleprime":t===3?i+"^\\tripleprime":i+"^{("+e.serialize(p(n,2))+")}"}},{latexTrigger:"^{\\prime\\prime}",kind:"postfix",parse:(e,n)=>Ze(e,n,2)},{latexTrigger:"^{\\prime\\prime\\prime}",kind:"postfix",parse:(e,n)=>Ze(e,n,3)},{latexTrigger:["^","\\doubleprime"],kind:"postfix",parse:(e,n)=>Ze(e,n,2)},{latexTrigger:["^","\\tripleprime"],kind:"postfix",parse:(e,n)=>Ze(e,n,3)},{latexTrigger:"'",kind:"postfix",precedence:810,parse:(e,n)=>Ze(e,n,1)},{latexTrigger:"\\prime",kind:"postfix",precedence:810,parse:(e,n)=>Ze(e,n,1)},{latexTrigger:"\\doubleprime",kind:"postfix",precedence:810,parse:(e,n)=>Ze(e,n,2)},{latexTrigger:"\\tripleprime",kind:"postfix",precedence:810,parse:(e,n)=>Ze(e,n,3)},{latexTrigger:["^","<{>","("],kind:"postfix",parse:(e,n,t)=>{let i=k(n);if(!i||!e.getSymbolType(i).matches("function"))return null;e.addBoundary([")"]);let r=e.parseExpression(t);return e.matchBoundary()?e.match("<}>")?["Derivative",n,r]:null:(e.removeBoundary(),null)}},{name:"InverseFunction",latexTrigger:"^{-1",kind:"postfix",parse:(e,n)=>{if(x(n)==="Matrix")return e.match("<}>"),["Inverse",n];let t=k(n);if(!t)return null;let i=e.getSymbolType(t);if(i.matches(new pe("matrix")))return e.match("<}>"),["Inverse",n];if(!i.matches("function"))return null;let r=0;for(;!e.atEnd&&!e.match("<}>");)if(e.match("'"))r++;else if(e.match("\\prime"))r++;else if(e.match("\\doubleprime"))r+=2;else if(e.match("\\tripleprime"))r+=3;else return null;return r===1?["Derivative",["InverseFunction",n]]:r>0?["Derivative",["InverseFunction",n],r]:["InverseFunction",n]},serialize:(e,n)=>e.serialize(p(n,1))+"^{-1}"},{name:"Derivative",serialize:(e,n)=>{let t=D(p(n,2))??1,i=e.serialize(p(n,1));return t===1?i+"^{\\prime}":t===2?i+"^{\\doubleprime}":t===3?i+"^{\\tripleprime}":i+"^{("+e.serialize(p(n,2))+")}"}},{name:"D",serialize:(e,n)=>{if(x(n)!=="D")return"D";let t=p(n,1),i=p(n,2);if(!t||!i)return"D";let r=1,s=t;for(;x(s)==="D";){let l=p(s,2);if(k(l)===k(i))r++,s=p(s,1);else break}let o=s;x(s)==="Function"&&(o=p(s,1)??s);let a=e.serialize(o),u=e.serialize(i);return r===1?`\\frac{\\mathrm{d}}{\\mathrm{d}${u}}${a}`:`\\frac{\\mathrm{d}^{${r}}}{\\mathrm{d}${u}^{${r}}}${a}`}},{name:"NewtonDerivative1",latexTrigger:["\\dot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",n,t]}},{name:"NewtonDerivative2",latexTrigger:["\\ddot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",["D",n,t],t]}},{name:"NewtonDerivative3",latexTrigger:["\\dddot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",["D",["D",n,t],t],t]}},{name:"NewtonDerivative4",latexTrigger:["\\ddddot"],kind:"prefix",precedence:740,parse:e=>{let n=e.parseGroup();if(n===null)return null;let t=e.options.timeDerivativeVariable;return["D",["D",["D",["D",n,t],t],t],t]}},{name:"EulerDerivative",latexTrigger:["D"],kind:"expression",parse:e=>{let n=1,t=null,i=!1;for(;!i;)if(e.match("_")){if(t=e.parseGroup()??e.parseToken(),!t)return null}else if(e.match("^")){let o=e.parseGroup()??e.parseToken();n=D(o)??1}else i=!0;if(!t||k(t)===null)return null;e.skipSpace();let r=e.parseExpression({minPrec:740});if(!r)return null;let s=r;for(let o=0;o<n;o++)s=["D",s,t];return s}},{kind:"environment",name:"Which",symbolTrigger:"cases",parse:cr,serialize:(e,n)=>{let t=[],i=_(n);if(i.length>0)for(let r=0;r<=i.length-2;r+=2){let s=[];s.push(e.serialize(i[r+1])),s.push(e.serialize(i[r])),t.push(s.join("&"))}return I(["\\begin{cases}",t.join("\\\\"),"\\end{cases}"])}},{kind:"environment",symbolTrigger:"dcases",parse:cr},{kind:"environment",symbolTrigger:"rcases",parse:cr}];function Re(e,n){if(!e.match("<{>"))return"''";let t=[],i="",r=null,s=()=>{r!==null&&i?t.push(["Annotated",`'${i}'`,Jt(r)]):i&&t.push(`'${i}'`),i="",r=null};for(;!e.atEnd&&!e.match("<}>");)if(e.peek==="<{>")s(),t.push(Re(e));else if(e.match("\\textbf"))s(),t.push(Re(e,{fontWeight:"bold"}));else if(e.match("\\textmd"))s(),t.push(Re(e,{fontStyle:"normal"}));else if(e.match("\\textup"))s(),t.push(Re(e,{fontStyle:"normal"}));else if(e.match("\\textsl"))s(),t.push(Re(e,{fontStyle:"italic"}));else if(e.match("\\textit"))s(),t.push(Re(e,{fontStyle:"italic"}));else if(e.match("\\texttt"))s(),t.push(Re(e,{fontFamily:"monospace"}));else if(e.match("\\textsf"))s(),t.push(Re(e,{fontFamily:"sans-serif"}));else if(e.match("\\textcolor")){let a=e.index,u=e.parseStringGroup();if(u!==null){s();let l=Re(e);t.push(["Annotated",l,Jt({color:u})])}else e.index=a,i+="\\textcolor"}else if(e.match("\\color")){let a=e.parseStringGroup();a!==null&&(s(),r={color:a})}else if(e.match("<space>"))i+=" ";else if(e.match("<$>")){let a=e.index,u=e.parseExpression()??"Nothing";e.skipSpace(),e.match("<$>")?(s(),t.push(u)):(i+="$",e.index=a)}else if(e.match("<$$>")){let a=e.index,u=e.parseExpression()??"Nothing";e.skipSpace(),e.match("<$$>")?(s(),t.push(u)):(i+="$$",e.index=a)}else{let a=e.parseChar()??e.nextToken();i+={"\\enskip":"\u2002","\\enspace":"\u2002","\\quad":"\u2003","\\qquad":"\u2003\u2003","\\space":"\u2003","\\ ":"\u2003","\\;":"\u2004","\\,":"\u2009","\\:":"\u205F","\\!":"","\\{":"{","\\}":"}","\\$":"$","\\&":"&","\\#":"#","\\%":"%","\\_":"_","\\textbackslash":"\\","\\textasciitilde":"~","\\textasciicircum":"^","\\textless":"<","\\textgreater":">","\\textbar":"|","\\textunderscore":"_","\\textbraceleft":"{","\\textbraceright":"}","\\textasciigrave":"`","\\textquotesingle":"'","\\textquotedblleft":"\u201C","\\textquotedblright":"\u201D","\\textquotedbl":'"',"\\textquoteleft":"\u2018","\\textquoteright":"\u2019","\\textbullet":"\u2022","\\textdagger":"\u2020","\\textdaggerdbl":"\u2021","\\textsection":"\xA7","\\textparagraph":"\xB6","\\textperiodcentered":"\xB7","\\textellipsis":"\u2026","\\textemdash":"\u2014","\\textendash":"\u2013","\\textregistered":"\xAE","\\texttrademark":"\u2122","\\textdegree":"\xB0"}[a]??a}s();let o;return t.length===1?o=t[0]:t.every(a=>q(a)!==null)?o="'"+t.map(a=>q(a)).join("")+"'":o=["Text",...t],n?["Annotated",o,Jt(n)]:o}function kc(e,n){return n===null?"":I(zt(n,t=>{let i=q(t);return i===null?e.serialize(t):i==="<{>"?"{":i==="<}>"?"}":i==="<$>"?"$":i==="<$$>"?"$$":i==="<space>"?" ":i}))}function ua(e){return e===null?"":e.replace(/[{}\[\]\\:\-\$%]/g,n=>({"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "})[n]??"\\"+n)}function Mc(e,n){let t=p(n,2);return t?x(t)==="LatexString"?q(p(t,1))??"":x(t)==="Hold"?e.serialize(p(t,1)):e.serialize(t):""}function Ze(e,n,t){for(;!e.atEnd;)if(e.match("'")||e.match("\\prime"))t++;else if(e.match("\\doubleprime"))t+=2;else if(e.match("\\tripleprime"))t+=3;else break;let i=x(n);if(i==="Derivative"||i==="Prime"){let a=D(p(n,2))??1;return[i,j(p(n,1)),a+t]}let r=k(n),s=r&&e.getSymbolType(r).matches("function")||x(n);e.skipSpace();let o=e.parseArguments("enclosure");if(o&&o.length>0){let a=o[0],u=k(a)??"x",c=typeof n=="string"?[n,...o]:["Apply",n,...o];for(let f=0;f<t;f++)c=["D",c,u];return c}return s?t===1?["Derivative",n]:["Derivative",n,t]:t===1?["Prime",j(n)]:["Prime",j(n),t]}function wc(e,n){if(G(n))return["Delimiter"];let t=x(n);if(t==="Delimiter"&&p(n,2)!==null){let i=q(p(n,2));if(i?.length===1)return["Delimiter",p(n,1)??"Nothing",{str:`(${i})`}]}return t==="Matrix"&&(q(p(n,2))??"..")===".."?["Matrix",p(n,1)]:["Delimiter",n]}function da(e,n){if(G(n))return["List"];let t=x(n);if(t==="Range"||t==="Linspace")return n;if(t==="Sequence"){let i=_(n),r=la(i,e);return r||["List",...i]}if(t==="Delimiter"){let i=q(p(n,2))??"...";if(i===";"||i===".;.")return["List",...(_(p(n,1))??[]).map(r=>da(e,r))];if(i===","||i===".,."){if(n=p(n,1),x(n)==="Sequence"){let r=_(n),s=la(r,e);return s||["List",...r]}return["List",n??"Nothing"]}}return["List",n]}function la(e,n){if(e.length<4)return null;let t=e[e.length-2];if(k(t)!=="ContinuationPlaceholder")return null;let i=e.slice(0,-2),r=e[e.length-1];if(i.length<2)return null;let s=i.map(D);if(s.some(l=>l===null))return null;let o=s,a=o[o.length-1]-o[o.length-2],u=n.options.tolerance;if(Math.abs(a)<u)return n.error("degenerate-range-step",n.index);for(let l=1;l<o.length;l++)if(Math.abs(o[l]-o[l-1]-a)>u)return n.error("inconsistent-range-samples",n.index);return["Range",o[0],r,a]}function Ac(e,n){return X(n)>1&&_(n).every(t=>{let i=x(t);return ir(i)||tr(i)})?I(["\\begin{cases}",De("\\\\")(e,n),"\\end{cases}"]):I(["\\bigl\\lbrack",De(", ")(e,n),"\\bigr\\rbrack"])}function jt(e,n){if(n===null)return null;let t=e.parseExpression({minPrec:270});if(t===null)return null;if(x(t)==="Range"){let i=p(t,1),r=p(t,2);return i&&r?["Range",n,r,["Subtract",i,n]]:null}return["Range",n,t]}var Ht={"(":"(",")":")","[":"\\lbrack","]":"\\rbrack","\u27E6":"\\llbrack","\u27E7":"\\rrbrack","{":"\\lbrace","}":"\\rbrace","<":"\\langle",">":"\\rangle","\u2016":"\\Vert","\\":"\\backslash","\u2308":"\\lceil","\u2309":"\\rceil","\u230A":"\\lfloor","\u230B":"\\rfloor","\u231C":"\\ulcorner","\u231D":"\\urcorner","\u231E":"\\llcorner","\u231F":"\\lrcorner","\u23B0":"\\lmoustache","\u23B1":"\\rmoustache"};function Ut(e,n,t){let i=(t?.minPrec??0)>=19,r=k(n);if(r&&r.includes("_")){let a=r.indexOf("_"),u=r.substring(0,a),l=r.substring(a+1),c=parseInt(l,10),f=!isNaN(c)&&String(c)===l?c:l,d=f!==""&&(typeof f=="number"||typeof f=="string"&&f.length===1);(e.getSymbolType(u).matches("indexed_collection")||!i&&d)&&(n=["Subscript",u,f])}if(x(n)==="InvisibleOperator"&&X(n)===2&&x(p(n,2))==="Delimiter"){let a=k(p(n,1));if(!a)return null;let u=e.parseExpression({...t??{},minPrec:20});if(u===null)return null;let l=p(p(n,2),1),c=[];return x(l)==="Sequence"?c=[..._(l)]:l&&(c=[l]),["Assign",a,["Function",u,...c??[]]]}if(x(n)==="Subscript"&&k(p(n,1))){let a=k(p(n,1));if(!e.getSymbolType(a).matches("indexed_collection")){let c=p(n,2),f=(c!==null&&typeof c=="string"?c:void 0)??(c!==null&&typeof c=="number"?String(c):void 0);if(f&&i){let d=e.parseExpression({...t??{},minPrec:20});return d===null?null:["Assign",a+"_"+f,d]}}let u=e.parseExpression({...t??{},minPrec:20});if(u===null)return null;let l=p(n,2);return q(l)!==null?["Assign",n,u]:k(l)?["Assign",n,u]:["Assign",n,u]}let s=x(n);if(s){let a=_(n),u=e.parseExpression({...t??{},minPrec:20});return u===null?null:["Assign",s,["Function",u,...a]]}if(!k(n))return null;let o=e.parseExpression({...t??{},minPrec:20});return o===null?null:["Assign",n,o]}function cr(e){let n=e.parseTabular();if(!n)return["List"];if(n.every(i=>{if(i.length!==1)return!1;let r=x(i[0]);return tr(r)||ir(r)}))return["List",...n.map(i=>i[0])];let t=[];for(let i of n)if(i.length===1)t.push("True"),t.push(i[0]);else if(i.length===2){let r=q(i[1]);t.push(r?"True":sr(i[1])??"True"),t.push(i[0])}return["Which",...t]}function ye(e,n){let t=e.index;if(!e.match("<{>"))return e.index=t,!1;for(;e.match("<space>"););for(let i=0;i<n.length;i++)if(n[i]===" "){if(!e.match("<space>"))return e.index=t,!1;for(;e.match("<space>"););}else{if(e.peek!==n[i])return e.index=t,!1;e.nextToken()}for(;e.match("<space>"););return e.match("<}>")?!0:(e.index=t,!1)}function yn(e,n){let t=e.index;if(e.skipVisualSpace(),e.match("\\text")){if(ye(e,n))return!0;e.index=t}let i=e.index,r=e.parseSymbol();return r!==null&&k(r)===n?!0:(e.index=i,!1)}function xn(e,n){let t=e.index,i=yn(e,n);return e.index=t,i}function ca(e,n){e.skipVisualSpace();let t=e.parseExpression({minPrec:0,condition:s=>xn(s,"then")});if(t===null||!yn(e,"then"))return null;e.skipVisualSpace();let i=e.parseExpression({minPrec:0,condition:s=>xn(s,"else")});if(i===null||!yn(e,"else"))return null;e.skipVisualSpace();let r=e.parseExpression(n)??"Nothing";return["If",t,i,r]}function fa(e,n){let t=e.parseExpression({minPrec:0,condition:a=>xn(a,"from")}),i=t?k(t):null;if(!i||!yn(e,"from"))return null;let r=e.parseExpression({minPrec:0,condition:a=>xn(a,"to")});if(r===null||!yn(e,"to"))return null;let s=e.parseExpression({minPrec:0,condition:a=>xn(a,"do")});return s===null||!yn(e,"do")?null:["Loop",e.parseExpression(n)??"Nothing",["Element",i,["Range",r,s]]]}function ha(e,n,t){let i={minPrec:21,condition:s=>{if(t?.condition?.(s))return!0;let o=s.index;s.skipVisualSpace();let a=s.peek===",";return s.index=o,!!(a||xn(s,"where")||xn(s,"with"))}},r=[];do{e.skipVisualSpace();let s=e.parseExpression(i);if(s===null)break;let o=x(s);if(o!=="Equal"&&o!=="Assign")return null;let a=p(s,1),u=p(s,2);if(!a||!u)return null;r.push(["Element",a,u]),e.skipVisualSpace()}while(e.match(","));return r.length===0?null:["Loop",n,...r]}function pa(e,n,t){let i={minPrec:21,condition:a=>{if(t?.condition?.(a))return!0;let u=a.index;a.skipVisualSpace();let l=a.peek===",";return a.index=u,l}},r=[];do{e.skipVisualSpace();let a=e.parseExpression(i);if(!a)break;r.push(a),e.skipVisualSpace()}while(e.match(","));if(r.length===0)return null;let s=e.index;if(yn(e,"for")){let a=ha(e,n,t);if(a){let u=[];for(let l of r){let c=pr(l);x(c)==="Assign"&&u.push(["Declare",p(c,1)]),u.push(c)}return u.push(a),["Block",...u]}e.index=s}let o=[];for(let a of r){let u=pr(a);x(u)==="Assign"&&o.push(["Declare",p(u,1)]),o.push(u)}return o.push(n),["Block",...o]}function $c(e){let n=[];for(let t of e){let i=pr(t);x(i)==="Assign"&&n.push(["Declare",p(i,1)]),n.push(i)}return["Block",...n]}function pr(e){if(x(e)!=="Assign")return e;let n=p(e,1);if(x(n)!=="Subscript")return e;let t=k(p(n,1));if(!t)return e;let i=p(n,2),r=(typeof i=="string"?i:void 0)??(typeof i=="number"?String(i):void 0);return r?["Assign",`${t}_${r}`,p(e,2)??"Nothing"]:e}function fr(...e){return(n,t)=>{if(!k(t)&&x(t)!=="List")return null;let i=null;return e.length===0&&(i=n.parseGroup()),i??=n.parseExpression({minPrec:0}),i===null||e.length>0&&!n.matchAll(e)||q(i)!==null?null:(x(i)==="Delimiter"&&(i=p(i,1)??"Nothing"),x(i)==="Sequence"?["At",t,..._(i)]:["At",t,i])}}var st=[["alpha","\\alpha",945],["beta","\\beta",946],["gamma","\\gamma",947],["delta","\\delta",948],["epsilon","\\epsilon",949],["epsilonSymbol","\\varepsilon",1013],["zeta","\\zeta",950],["eta","\\eta",951],["theta","\\theta",952],["thetaSymbol","\\vartheta",977],["iota","\\iota",953],["kappa","\\kappa",954],["kappaSymbol","\\varkappa",1008],["lambda","\\lambda",955],["mu","\\mu",956],["nu","\\nu",957],["xi","\\xi",958],["omicron","\\omicron",959],["pi","\\pi",960],["piSymbol","\\varpi",982],["rho","\\rho",961],["rhoSymbol","\\varrho",1009],["sigma","\\sigma",963],["finalSigma","\\varsigma",962],["tau","\\tau",964],["phi","\\phi",981],["phiLetter","\\varphi",966],["upsilon","\\upsilon",965],["chi","\\chi",967],["psi","\\psi",968],["omega","\\omega",969],["Alpha","\\Alpha",913],["Beta","\\Beta",914],["Gamma","\\Gamma",915],["Delta","\\Delta",916],["Epsilon","\\Epsilon",917],["Zeta","\\Zeta",918],["Eta","\\Eta",919],["Theta","\\Theta",920],["Iota","\\Iota",921],["Kappa","\\Kappa",922],["Lambda","\\Lambda",923],["Mu","\\Mu",924],["Nu","\\Nu",925],["Xi","\\Xi",926],["Omicron","\\Omicron",927],["Rho","\\Rho",929],["Sigma","\\Sigma",931],["Tau","\\Tau",932],["Phi","\\Phi",934],["Upsilon","\\Upsilon",933],["Chi","\\Chi",935],["Psi","\\Psi",936],["Omega","\\Omega",937],["digamma","\\digamma",989],["aleph","\\aleph",8501],["bet","\\beth",8502],["gimel","\\gimel",8503],["dalet","\\daleth",8504],["ell","\\ell",8499],["turnedCapitalF","\\Finv",8498],["turnedCapitalG","\\Game",8513],["weierstrass","\\wp",8472],["eth","\\eth",240],["invertedOhm","\\mho",8487],["hBar","\\hbar",295],["hSlash","\\hslash",8463],["blackClubSuit","\\clubsuit",9827],["whiteHeartSuit","\\heartsuit",9825],["blackSpadeSuit","\\spadesuit",9824],["whiteDiamondSuit","\\diamondsuit",9826],["sharp","\\sharp",9839],["flat","\\flat",9837],["natural","\\natural",9838]],ga=[...st.map(([e,n,t])=>({kind:"symbol",name:e,latexTrigger:[n],parse:e})),...st.map(([e,n,t])=>({kind:"symbol",latexTrigger:[String.fromCodePoint(t)],parse:e}))];var ba=[{name:"To",latexTrigger:["\\to"],kind:"infix",precedence:270},{latexTrigger:["-",">"],kind:"infix",precedence:270,parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:270});return i===null?null:["To",n,i]}}];function Pe(e,n,t){if(G(e))return null;let i,r=x(e);if(r==="Delimiter"){let l=q(p(e,2));if(l!==","&&l!=="(,)"&&l!=="[,]")return null;let c=p(e,1);x(c)==="Sequence"?i=[..._(c)]:i=c?[c]:[]}else if(r==="Sequence")i=[..._(e)];else return null;if(i.length!==2)return null;let[s,o]=i;return["Interval",n?["Open",s]:s,t?["Open",o]:o]}var ya=new Set(["Less","LessEqual","Greater","GreaterEqual","Equal","NotEqual","And","Or","Not"]),va=[{name:"AlgebraicNumbers",latexTrigger:"\\overline\\Q"},{latexTrigger:"\\bar\\Q",parse:"AlgebraicNumbers"},{name:"ComplexNumbers",latexTrigger:["\\C"]},{latexTrigger:"\\mathbb{C}",parse:"ComplexNumbers"},{name:"ImaginaryNumbers",latexTrigger:["\\imaginaryI","\\R"]},{name:"EmptySet",latexTrigger:["\\emptyset"]},{latexTrigger:["\\varnothing"],parse:"EmptySet"},{name:"Integers",latexTrigger:["\\Z"]},{latexTrigger:"\\mathbb{Z}",parse:"Integers"},{name:"RationalNumbers",latexTrigger:["\\Q"]},{latexTrigger:"\\mathbb{Q}",parse:"RationalNumbers"},{name:"RealNumbers",latexTrigger:["\\R"]},{latexTrigger:"\\mathbb{R}",parse:"RealNumbers"},{name:"TranscendentalNumbers",latexTrigger:"\\R-\\bar\\Q"},{latexTrigger:"\\R\\backslash\\bar\\Q",parse:"TranscendentalNumbers"},{name:"NegativeNumbers",latexTrigger:"\\R_{<0}"},{latexTrigger:"\\R^-",parse:"NegativeNumbers"},{latexTrigger:"\\R^{-}",parse:"NegativeNumbers"},{latexTrigger:"\\R^-",parse:"NegativeNumbers"},{latexTrigger:"\\R_-",parse:"NegativeNumbers"},{latexTrigger:"\\R_{-}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{\\lt}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{<}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{\\lt0}",parse:"NegativeNumbers"},{latexTrigger:"\\R^{<0}",parse:"NegativeNumbers"},{name:"NonPositiveNumbers",latexTrigger:"\\R_{\\le0}"},{latexTrigger:"\\R^{\\leq0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{-0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{\\leq}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{0-}",parse:"NonPositiveNumbers"},{name:"PositiveNumbers",latexTrigger:"\\R_{>0}"},{latexTrigger:"\\R^+",parse:"PositiveNumbers"},{latexTrigger:"\\R^{+}",parse:"PositiveNumbers"},{latexTrigger:"\\R_+",parse:"PositiveNumbers"},{latexTrigger:"\\R_{+}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{\\gt}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{\\gt 0}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{>}",parse:"PositiveNumbers"},{latexTrigger:"\\R^{>0}",parse:"PositiveNumbers"},{name:"NonNegativeNumbers",latexTrigger:"\\R_{\\geq0}"},{latexTrigger:"\\R^{0+}",parse:"NonNegativeNumbers"},{latexTrigger:"\\R^{\\geq}",parse:"NonNegativeNumbers"},{name:"ExtendedRealNumbers",latexTrigger:"\\overline\\R"},{latexTrigger:"\\bar\\R",parse:"ExtendedRealNumbers"},{name:"NegativeIntegers",latexTrigger:"\\Z_{<0}"},{latexTrigger:"\\Z_{\\lt0}",parse:"NegativeIntegers"},{latexTrigger:"\\Z^-",parse:"NegativeIntegers"},{latexTrigger:"\\Z^{-}",parse:"NegativeIntegers"},{latexTrigger:"\\Z_-",parse:"NegativeIntegers"},{latexTrigger:"\\Z_{-}",parse:"NegativeIntegers"},{latexTrigger:"\\Z^{\\lt}",parse:"NegativeIntegers"},{name:"NonPositiveIntegers",latexTrigger:"\\Z_{\\le0}"},{latexTrigger:"\\Z_{\\leq0}",parse:"NonPositiveIntegers"},{latexTrigger:"\\Z_{<0}",parse:"NonPositiveIntegers"},{name:"PositiveIntegers",latexTrigger:"\\N^*"},{latexTrigger:"\\Z_{>0}",parse:"PositiveIntegers"},{latexTrigger:"\\Z_{\\gt0}",parse:"PositiveIntegers"},{latexTrigger:"\\Z^{+}",parse:"PositiveIntegers"},{latexTrigger:"\\Z_+",parse:"PositiveIntegers"},{latexTrigger:"\\Z_{+}",parse:"PositiveIntegers"},{latexTrigger:"\\Z^{\\gt}",parse:"PositiveIntegers"},{latexTrigger:"\\Z^{\\gt0}",parse:"PositiveIntegers"},{latexTrigger:"\\N^+",parse:"PositiveIntegers"},{latexTrigger:"\\N^{+}",parse:"PositiveIntegers"},{latexTrigger:"\\N^*",parse:"PositiveIntegers"},{latexTrigger:"\\N^{*}",parse:"PositiveIntegers"},{latexTrigger:"\\N^\\star",parse:"PositiveIntegers"},{latexTrigger:"\\N^{\\star}",parse:"PositiveIntegers"},{latexTrigger:"\\N_1",parse:"PositiveIntegers"},{latexTrigger:"\\N_{1}",parse:"PositiveIntegers"},{name:"NonNegativeIntegers",latexTrigger:["\\N"]},{latexTrigger:"\\Z^{+0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{\\geq}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{\\geq0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{0+}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{N}",parse:"NonNegativeIntegers"},{latexTrigger:"\\N_0",parse:"NonNegativeIntegers"},{latexTrigger:"\\N_{0}",parse:"NonNegativeIntegers"},{name:"ExtendedIntegers",latexTrigger:"\\overline\\Z"},{latexTrigger:"\\bar\\Z",parse:"ExtendedIntegers"},{name:"ExtendedRationalNumbers",latexTrigger:"\\overline\\Q"},{latexTrigger:"\\bar\\Q",parse:"ExtendedRationalNumbers"},{name:"ExtendedComplexNumbers",latexTrigger:"\\overline\\C"},{latexTrigger:"\\bar\\C",parse:"ExtendedComplexNumbers"},{latexTrigger:["^","\\complement"],kind:"postfix",parse:(e,n)=>["Complement",n]},{name:"Complement",latexTrigger:["^","<{>","\\complement","<}>"],kind:"postfix",serialize:(e,n)=>I([e.serialize(p(n,1)),"^\\complement"])},{name:"Intersection",latexTrigger:["\\cap"],kind:"infix",precedence:350},{name:"Interval",serialize:xa},{kind:"matchfix",openTrigger:["["],closeTrigger:[")"],parse:(e,n)=>Pe(n,!1,!0)},{kind:"matchfix",openTrigger:["\\lbrack"],closeTrigger:["\\rparen"],parse:(e,n)=>Pe(n,!1,!0)},{kind:"matchfix",openTrigger:["\\lbrack"],closeTrigger:[")"],parse:(e,n)=>Pe(n,!1,!0)},{kind:"matchfix",openTrigger:["["],closeTrigger:["\\rparen"],parse:(e,n)=>Pe(n,!1,!0)},{kind:"matchfix",openTrigger:["("],closeTrigger:["]"],parse:(e,n)=>Pe(n,!0,!1)},{kind:"matchfix",openTrigger:["\\lparen"],closeTrigger:["\\rbrack"],parse:(e,n)=>Pe(n,!0,!1)},{kind:"matchfix",openTrigger:["\\lparen"],closeTrigger:["]"],parse:(e,n)=>Pe(n,!0,!1)},{kind:"matchfix",openTrigger:["("],closeTrigger:["\\rbrack"],parse:(e,n)=>Pe(n,!0,!1)},{kind:"matchfix",openTrigger:["]"],closeTrigger:["["],parse:(e,n)=>Pe(n,!0,!0)},{kind:"matchfix",openTrigger:["\\rbrack"],closeTrigger:["\\lbrack"],parse:(e,n)=>Pe(n,!0,!0)},{name:"Multiple",serialize:xa},{name:"Union",latexTrigger:["\\cup"],kind:"infix",precedence:350},{name:"Divides",latexTrigger:["\\mid"],kind:"infix",precedence:160},{name:"Set",kind:"matchfix",openTrigger:"{",closeTrigger:"}",parse:(e,n)=>{if(G(n))return"EmptySet";x(n)=="Delimiter"&&q(p(n,2))===","&&(n=p(n,1));let t=x(n);if(t==="Divides"){let i=p(n,1),r=p(n,2);if(i!==null&&r!==null)return["Set",i,["Condition",r]]}if(t==="Colon"){let i=p(n,1),r=p(n,2);if(i!==null&&r!==null){let s=x(i);return s!==null&&ya.has(s)?["Which",i,r]:["Set",i,["Condition",r]]}}if(t==="Sequence"){let i=_(n),r=i.filter(o=>x(o)==="Colon");if(r.length>0&&r.every(o=>{let a=p(o,1),u=a!==null?x(a):null;return u!==null&&ya.has(u)})){let o=[];for(let a=0;a<i.length;a++){let u=i[a];if(x(u)==="Colon"){let l=p(u,1),c=p(u,2);if(l===null||c===null)return["Set",...i];o.push(l,c)}else{if(a!==i.length-1)return["Set",...i];o.push("True",u)}}return["Which",...o]}return["Set",...i]}return["Set",n]},serialize:(e,n)=>{if(X(n)===2&&x(p(n,2))==="Condition"){let t=p(n,2);return I(["\\lbrace",e.serialize(p(n,1)),"\\mid",e.serialize(p(t,1)),"\\rbrace"])}return I(["\\lbrace",_(n).map(t=>e.serialize(t)).join(", "),"\\rbrace"])}},{name:"SetMinus",latexTrigger:["\\setminus"],kind:"infix",precedence:650},{name:"SymmetricDifference",latexTrigger:["\\triangle"],kind:"infix",precedence:F},{latexTrigger:["\\ni"],kind:"infix",associativity:"none",precedence:160,parse:(e,n,t)=>{let i=e.parseExpression(t);return i===null?null:["Element",i,n]}},{name:"Element",latexTrigger:["\\in"],kind:"infix",precedence:240},{name:"NotElement",latexTrigger:["\\notin"],kind:"infix",precedence:240},{name:"NotSubset",latexTrigger:["\\nsubset"],kind:"infix",associativity:"none",precedence:240},{name:"NotSuperset",latexTrigger:["\\nsupset"],kind:"infix",associativity:"none",precedence:240},{name:"NotSubsetNotEqual",latexTrigger:["\\nsubseteq"],kind:"infix",associativity:"none",precedence:240},{name:"NotSupersetNotEqual",latexTrigger:["\\nsupseteq"],kind:"infix",associativity:"none",precedence:240},{name:"SquareSubset",latexTrigger:["\\sqsubset"],kind:"infix",associativity:"none",precedence:265},{name:"SquareSubsetEqual",latexTrigger:["\\sqsubseteq"],kind:"infix",associativity:"none",precedence:265},{name:"SquareSuperset",latexTrigger:["\\sqsupset"],kind:"infix",associativity:"none",precedence:265},{name:"SquareSupersetEqual",latexTrigger:["\\sqsupseteq"],kind:"infix",associativity:"none",precedence:265},{name:"Subset",latexTrigger:["\\subset"],kind:"infix",associativity:"none",precedence:240},{latexTrigger:["\\subsetneq"],kind:"infix",associativity:"none",precedence:240,parse:"Subset"},{latexTrigger:["\\varsubsetneqq"],kind:"infix",associativity:"none",precedence:240,parse:"Subset"},{name:"SubsetEqual",latexTrigger:["\\subseteq"],kind:"infix",associativity:"none",precedence:240},{name:"Superset",latexTrigger:["\\supset"],kind:"infix",associativity:"none",precedence:240},{latexTrigger:["\\supsetneq"],kind:"infix",associativity:"none",precedence:240,parse:"Superset"},{latexTrigger:["\\varsupsetneq"],kind:"infix",associativity:"none",precedence:240,parse:"Superset"},{name:"SupersetEqual",latexTrigger:["\\supseteq"],kind:"infix",associativity:"none",precedence:240}];function xa(e,n){if(n===null)return"";let t=x(n);if(!t)return"";if(t==="Range")return I(["\\mathopen\\lbrack",e.serialize(p(n,1)),", ",e.serialize(p(n,2)),"\\mathclose\\rbrack"]);if(t==="Interval"){let r=p(n,1),s=p(n,2),o=!1,a=!1;return x(r)==="Open"&&(r=p(r,1),o=!0),x(s)==="Open"&&(s=p(s,1),a=!0),I([o?"\\lparen":"\\lbrack",e.serialize(r),", ",e.serialize(s),a?"\\rparen":"\\rbrack"])}let i=e.numericSetStyle(n,e.level);return""}function vn(e,n,t){e.indexOf("#1")<0&&e.indexOf("#2")<0&&(e=`#1 ${e} #2`);let i=e.split(/(#\d+)/).filter(r=>r.trim()!=="").map(r=>r.trim());return I(i.map(r=>{switch(r){case"#1":return n;case"#2":return t;default:return r}}))}function Zt(e,n){if(n==="none")return e;if(n==="0...360"){let t=e%360;return(t<0?t+360:t)||0}if(n==="-180...180"){let t=e%360;return t>180&&(t-=360),t<-180&&(t+=360),t||0}return e}function Cc(e){let n=e<0?-1:1,t=Math.abs(e),i=Math.floor(t),r=(t-i)*60,s=Math.floor(r),o=(r-s)*60,a=Math.round(o*1e3)/1e3,u=s,l=i;return a>=60&&(a=0,u++),u>=60&&(u=0,l++),{deg:n*l||0,min:n*u||0,sec:a===0?0:n*a}}function Yt(e){let{deg:n,min:t,sec:i}=Cc(e),r=`${n}\xB0`;if(Math.abs(i)>.001){let s=i%1===0?i.toString():i.toFixed(2);r+=`${Math.abs(t)}'${Math.abs(Number(s))}"`}else Math.abs(t)>0?r+=`${Math.abs(t)}'`:r+=`0'0"`;return r}function Rc(e){if(x(e)!=="Multiply")return[[],[]];let n=[],t=[];for(let i of _(e))if(x(i)==="Power"){let r=p(i,1),s=p(i,2);if(x(s)==="Negate"){let o=p(s,1);r&&o&&t.push(["Power",r,o])}else{let o=D(s)??NaN;o===-1?r&&t.push(r):o<0?r&&t.push(["Power",r,-o]):n.push(i)}}else if(x(i)==="Rational"&&X(i)===2||x(i)==="Divide"){let r=p(i,1),s=p(i,2);D(r)!==1&&n.push(r),D(s)!==1&&t.push(s)}else{let r=Dn(i);r!==null?(r[0]!==1&&n.push(r[0]),t.push(r[1])):n.push(i)}return[n,t]}function Dc(e){let n=e.parseOptionalGroup(),t=e.parseGroup()??e.parseToken();return G(t)?n!==null?["Root",$n,j(n)]:["Sqrt",$n]:n!==null?["Root",t,n]:["Sqrt",t]}function Pc(e){if(typeof e=="number")return-e;if(typeof e=="string")return e.startsWith("-")?e.slice(1):e.startsWith("+")?"-"+e.slice(1):"-"+e;let n=e.num;return n.startsWith("-")?{num:n.slice(1)}:n.startsWith("+")?{num:"-"+n.slice(1)}:{num:"-"+n}}function at(e,n,t,i){return t==null?"\\sqrt{}":(i=i??2,n==="solidus"?e.wrapShort(t)+"^{1/"+e.serialize(i)+"}":n==="quotient"?e.wrapShort(t)+"^{\\frac{1}{"+e.serialize(i)+"}}":D(i)===2?"\\sqrt{"+e.serialize(t)+"}":"\\sqrt["+e.serialize(i)+"]{"+e.serialize(t)+"}")}function Fc(e,n){e.level-=1;let t=x(n),i="",r=p(n,1);if(t==="Negate")i="-"+e.wrap(r,ee+1);else if(t==="Subtract"){i=e.wrap(r,ee);let s=p(n,2);if(s!==null){let o=e.wrap(s,ee);o[0]==="-"?i+="+"+o.slice(1):o[0]==="+"?i+="-"+o.slice(1):i=i+"-"+o}}else if(t==="Add"){if(e.options.prettify&&X(n)===2&&e.options.invisiblePlus!=="+"){let[a,u]=[p(n,1),p(n,2)],[l,c]=[a,u],f=D(l),d=Dn(c);if((f===null||d===null)&&([l,c]=[u,a],f=D(l),d=Dn(c)),f!==null&&d!==null&&isFinite(f)&&Number.isInteger(f)&&f>=0&&f<=1e3&&isFinite(d[0])&&isFinite(d[1])&&d[0]>0&&d[0]<=100&&d[1]<=100)return i=vn(e.options.invisiblePlus,e.serialize(l),e.serialize(c)),e.level+=1,i}if(e.options.prettify&&X(n)===2){let[a,u]=ut(r),[l,c]=ut(p(n,2));if(u<0&&c>0)return i=e.wrap(l,ee)+"-"+e.wrap(a,ee),e.level+=1,i}i=e.serialize(r);let s=X(n)+1,o=_(n);for(let a=2;a<s;a++)if(r=o[a-1],e.options.prettify){let[u,l]=ut(r),c=e.wrap(u,ee);l>0?c.startsWith("+")||c.startsWith("-")?i+=c:i+="+"+c:c.startsWith("+")?i+="-"+c.slice(1):c.startsWith("-")?i+="+"+c.slice(1):i+="-"+c}else{let u=e.wrap(r,ee);u[0]==="-"||u[0]==="+"?i+=u:i+="+"+u}}return e.level+=1,i}function ka(e,n){if(n===null)return"";e.level-=1;let t="";if(e.options.prettify===!0){let[u,l]=Rc(n);l.length>0&&(l.length===1&&l[0]===1?u.length===0?t="1":u.length===1?t=e.serialize(u[0]):t=ka(e,["Multiply",...u]):t=e.serialize(["Divide",u.length===1?u[0]:["Multiply",...u],l.length===1?l[0]:["Multiply",...l]]))}if(t)return e.level+=1,t;let i=!1,r=null,s=X(n)+1,o=_(n);e.options.prettify===!0&&o.length===2&&gn(o[1])&&!gn(o[0])&&(o=[o[1],o[0]]);let a=!1;for(let u=1;u<s;u++){if(r=o[u-1],r===null)continue;let l;if(gn(r)){l=e.serialize(r),l==="-1"&&!t?(t="",i=!i):(l[0]==="-"&&(l=l.slice(1),i=!i),t?t=vn(e.options.multiply,t,l):t=l),a=!0;continue}if(x(r)==="Power"){let c=Dn(p(r,2));if(c!=null){let[f,d]=c;if(f===1&&d!==null){t+=at(e,e.rootStyle(r,e.level),p(r,1),d),a=!1;continue}}}if(x(r)==="Power"&&!isNaN(D(p(r,1))??NaN)){l=e.serialize(r),t?t=vn(e.options.multiply,t,l):t=l,a=!0;continue}if(x(r)==="Negate"&&(r=p(r,1),i=!i),l=e.wrap(r,be),!t)t=l;else{let c=x(r);a&&(c==="Divide"||c==="Rational")?t=vn(e.options.multiply,t,l):/^\d/.test(l)?t=vn(e.options.multiply,t,l):e.options.invisibleMultiply?t=vn(e.options.invisibleMultiply,t,l):t=I([t,l])}a=!1}return e.level+=1,i?"-"+t:t}function Wt(e){let n=e.parseGroup(),t=null;if(n===null?(n=e.parseToken(),t=e.parseToken()):t=e.parseGroup(),n=j(n),t=j(t),x(n)==="PartialDerivative"&&(x(t)==="PartialDerivative"||x(t)==="Multiply"&&x(p(t,1))==="PartialDerivative")){let s=p(n,3)??null,o=p(n,1);o==null&&(o=j(e.parseExpression()));let a=[];if(x(t)==="Multiply"){for(let u of _(t))if(x(u)==="PartialDerivative"){let l=p(u,2);l&&a.push(l)}}else{let u=p(t,2);u&&a.push(u)}return a.length>1&&(a=["List",...a]),["PartialDerivative",o,...a,s===null?1:s]}let i=k(n);if(i==="d"||i==="d_upright"||i==="differentialD"){let s=[],o=a=>{if(!a)return;let u=k(a);if(u&&u!=="d"&&u!=="d_upright"&&u!=="differentialD"){s.push(a);return}let l=x(a);if(l==="Sequence"||l==="Multiply"||l==="InvisibleOperator")for(let c of _(a))o(c)};if(o(t),s.length===0){let a=k(t);a&&a.length>1&&a[0]==="d"&&s.push(a.slice(1))}if(s.length>0)return["D",j(e.parseExpression()),...s]}return["Divide",n,t]}function Ea(e,n){if(n===null)return"";let t=j(p(n,1)),i=j(p(n,2)),r=e.options.prettify?e.fractionStyle(n,e.level):"quotient";if(r==="inline-solidus"||r==="nice-solidus"){let u=e.wrapShort(t),l=e.wrapShort(i);return r==="inline-solidus"?`${u}/${l}`:`{}^{${u}}\\!\\!/\\!{}_{${l}}`}else{if(r==="reciprocal")return D(t)===1?e.wrap(i)+"^{-1}":e.wrap(t)+e.wrap(i)+"^{-1}";if(r==="factor")return D(i)===1?e.wrap(t):"\\frac{1}{"+e.serialize(i)+"}"+e.wrapString(e.serialize(t),e.groupStyle(n,1))}let s="\\frac";r==="block-quotient"?s="\\dfrac":r==="inline-quotient"&&(s="\\tfrac");let o=e.serialize(t),a=e.serialize(i);return`${s}{${o}}{${a}}`}function mr(e,n){if(!n)return"";let t=x(n),i=j(p(n,1));if(t==="Sqrt")return at(e,e.rootStyle(n,e.level-1),i,2);let r=j(p(n,2));if(t==="Root")return at(e,e.rootStyle(n,e.level-1),i,r);if(e.options.prettify){let o=D(r)??1;if(o===-1)return e.serialize(["Divide","1",i]);if(o<0)return e.serialize(["Divide","1",["Power",i,-o]]);if(x(r)==="Divide"||x(r)==="Rational"){let a=D(p(r,1)),u=D(p(r,2));if(a===1){let l=e.rootStyle(n,e.level);return at(e,l,i,p(r,2))}if(a===-1)return u===2?e.serialize(["Divide","1",["Sqrt",i]]):e.serialize(["Divide","1",["Root",i,p(r,2)??$n]]);if(u===2)return`${e.serialize(["Sqrt",i])}^{${e.serialize(p(r,1))}}`}else if(x(r)==="Power"&&D(p(r,2))===-1){let a=e.rootStyle(n,e.level);return at(e,a,i,p(r,1))}}let s=o=>o.startsWith("-")?e.wrapString(o,"normal"):o;if(x(i)==="Power"){let o=p(i,1),a=p(i,2),u=s(e.wrapShort(o)),l=e.wrapShort(a);return`
7
+ ${u}^{${An("^",l,e.serialize(r))}}`}return An("^",s(e.wrapShort(i)),e.serialize(r))}function ot(e,n){e.skipSpace();let t=e.index,i=e.parseNumber(),r=null,s=null;if(i!==null&&(e.match("'")||e.match("\\prime"))){r=D(i),e.skipSpace();let u=e.index,l=e.parseNumber();l!==null&&(e.match('"')||e.match("\\doubleprime"))?s=D(l):e.index=u}else return e.index=t,["Degrees",n];let o=D(n);if(o!==null&&r!==null){let u=o+r/60;return s!==null&&(u+=s/3600),["Degrees",u]}let a=[["Quantity",n,"deg"]];return a.push(["Quantity",i,"arcmin"]),s!==null&&a.push(["Quantity",s,"arcsec"]),["Add",...a]}var Ma=[{name:"CatalanConstant",symbolTrigger:"G"},{name:"GoldenRatio",latexTrigger:"\\varphi"},{name:"EulerGamma",latexTrigger:"\\gamma"},{name:"Degrees",latexTrigger:["\\degree"],kind:"postfix",precedence:880,parse:(e,n)=>ot(e,n),serialize:(e,n)=>{let t=e.options,i=p(n,1);if(t.dmsFormat||t.angleNormalization&&t.angleNormalization!=="none"){let r=D(i);if(r!==null){let s=r;return t.angleNormalization&&t.angleNormalization!=="none"&&(s=Zt(s,t.angleNormalization)),t.dmsFormat?Yt(s):`${s}\xB0`}}return I([e.serialize(i),"\\degree"])}},{latexTrigger:["\\degree"],kind:"postfix",precedence:880,parse:(e,n)=>ot(e,n)},{latexTrigger:["^","<{>","\\circ","<}>"],kind:"postfix",parse:(e,n)=>ot(e,n)},{latexTrigger:["^","\\circ"],kind:"postfix",parse:(e,n)=>ot(e,n)},{latexTrigger:["\xB0"],kind:"postfix",precedence:880,parse:(e,n)=>ot(e,n)},{latexTrigger:["\\ang"],parse:e=>{let n=e.parseGroup();return n===null?["Degrees"]:["Degrees",n]}},{name:"DMS",serialize:(e,n)=>{let t=D(p(n,1)),i=D(p(n,2)),r=D(p(n,3));if(t!==null){let o=i??0,a=r??0,u=`${t}\xB0`;return(o!==0||a!==0)&&(u+=`${o}'`),a!==0&&(u+=`${a}"`),u}let s=[];for(let o of[1,2,3]){let a=p(n,o);a!==null&&s.push(e.serialize(a))}return`\\operatorname{DMS}(${s.join(", ")})`}},{latexTrigger:["\\infty"],parse:"PositiveInfinity"},{latexTrigger:["\\infin"],parse:"PositiveInfinity"},{name:"PositiveInfinity",serialize:e=>e.options.positiveInfinity},{name:"NegativeInfinity",serialize:e=>e.options.negativeInfinity},{name:"ComplexInfinity",latexTrigger:["\\tilde","\\infty"],serialize:"\\tilde\\infty"},{latexTrigger:["\\tilde","<{>","\\infty","<}>"],parse:"ComplexInfinity"},{name:"Pi",kind:"symbol",latexTrigger:["\\pi"]},{latexTrigger:["\u03C0"],parse:"Pi"},{name:"ExponentialE",latexTrigger:["\\exponentialE"],parse:"ExponentialE",serialize:"\\exponentialE"},{latexTrigger:"\\operatorname{e}",parse:"ExponentialE"},{latexTrigger:"\\mathrm{e}",parse:"ExponentialE"},{kind:"function",symbolTrigger:"exp",parse:e=>{let n=e.parseArguments("implicit");return n===null?"Exp":["Exp",...n]}},{latexTrigger:"\\exp",parse:e=>{let n=e.parseArguments("implicit");return n===null?"Exp":["Exp",...n]}},{name:"ImaginaryUnit",latexTrigger:["\\imaginaryI"]},{latexTrigger:"\\operatorname{i}",parse:"ImaginaryUnit"},{latexTrigger:"\\mathrm{i}",parse:"ImaginaryUnit"},{name:"Abs",kind:"matchfix",openTrigger:"|",closeTrigger:"|",parse:(e,n)=>G(n)?null:["Abs",n]},{kind:"matchfix",openTrigger:["\\vert"],closeTrigger:["\\vert"],parse:(e,n)=>G(n)?null:["Abs",n]},{symbolTrigger:"abs",kind:"function",parse:"Abs"},{name:"Add",latexTrigger:["+"],kind:"infix",associativity:"any",precedence:ee,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:ee});if(i===null)return null;if(x(i)==="Negate"){let r=p(i,1);if(gn(r))return Pn("Add",n,Pc(r))}return Pn("Add",n,i)},serialize:Fc},{kind:"prefix",latexTrigger:["+"],precedence:ee,parse:(e,n)=>e.parseExpression({...n,minPrec:400})},{name:"Ceil",kind:"matchfix",openTrigger:"\\lceil",closeTrigger:"\\rceil",parse:(e,n)=>G(n)?null:["Ceil",n]},{kind:"matchfix",openTrigger:["\u2308"],closeTrigger:["\u2309"],parse:(e,n)=>G(n)?null:["Ceil",n]},{symbolTrigger:"ceil",kind:"function",parse:"Ceil"},{name:"Chop",symbolTrigger:"chop",kind:"function",parse:"Chop"},{name:"Complex",precedence:ee-1,serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=D(p(n,2));if(i===0)return t;let r=i===1?"\\imaginaryI":i===-1?"-\\imaginaryI":I([e.serialize(p(n,2)),"\\imaginaryI"]);return D(p(n,1))===0?r:i!==null&&i<0?I([t,r]):I([t,"+",r])}},{name:"Divide",latexTrigger:"\\frac",precedence:Ne,parse:Wt,serialize:Ea},{latexTrigger:"\\dfrac",precedence:Ne,parse:Wt},{latexTrigger:"\\tfrac",precedence:Ne,parse:Wt},{latexTrigger:"\\cfrac",precedence:Ne,parse:Wt},{kind:"infix",latexTrigger:"\\over",associativity:"none",precedence:Ne,parse:"Divide"},{latexTrigger:["\\/"],kind:"infix",associativity:"left",precedence:Ne,parse:"Divide"},{latexTrigger:["/"],kind:"infix",associativity:"left",precedence:Ne,parse:"Divide"},{latexTrigger:["\\div"],kind:"infix",associativity:"left",precedence:Ne,parse:"Divide"},{name:"Exp",serialize:(e,n)=>{let t=p(n,1);return k(t)||D(t)!==null?I(["\\exponentialE^{",e.serialize(t),"}"]):I(["\\exp",e.wrap(j(t))])}},{name:"Factorial",latexTrigger:["!"],kind:"postfix",precedence:er},{name:"Factorial2",latexTrigger:["!","!"],kind:"postfix",precedence:er},{name:"Floor",kind:"matchfix",openTrigger:"\\lfloor",closeTrigger:"\\rfloor",parse:(e,n)=>G(n)?null:["Floor",n]},{kind:"matchfix",openTrigger:["\u230A"],closeTrigger:["\u230B"],parse:(e,n)=>G(n)?null:["Floor",n]},{symbolTrigger:"floor",kind:"function",parse:"Floor"},{latexTrigger:["\\Gamma"],parse:"Gamma"},{latexTrigger:["\\zeta"],kind:"function",parse:"Zeta"},{latexTrigger:["\\Beta"],kind:"function",parse:"Beta"},{name:"LambertW",latexTrigger:["\\operatorname{W}"],kind:"function",serialize:(e,n)=>"\\operatorname{W}"+e.wrapArguments(n)},{name:"BesselJ",latexTrigger:["\\operatorname{J}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{J}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselJ",i]):"\\operatorname{J}"+e.wrapArguments(n)}},{name:"BesselY",latexTrigger:["\\operatorname{Y}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{Y}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselY",i]):"\\operatorname{Y}"+e.wrapArguments(n)}},{name:"BesselI",latexTrigger:["\\operatorname{I}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{I}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselI",i]):"\\operatorname{I}"+e.wrapArguments(n)}},{name:"BesselK",latexTrigger:["\\operatorname{K}"],kind:"function",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);return t!==null&&i!==null?"\\operatorname{K}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselK",i]):"\\operatorname{K}"+e.wrapArguments(n)}},{name:"AiryAi",latexTrigger:["\\operatorname{Ai}"],kind:"function",serialize:(e,n)=>"\\operatorname{Ai}"+e.wrapArguments(n)},{name:"AiryBi",latexTrigger:["\\operatorname{Bi}"],kind:"function",serialize:(e,n)=>"\\operatorname{Bi}"+e.wrapArguments(n)},{name:"GCD",latexTrigger:["\\gcd"],kind:"function"},{symbolTrigger:"gcd",kind:"function",parse:"GCD"},{symbolTrigger:"GCD",kind:"function",parse:"GCD"},{name:"Half",serialize:"\\frac12"},{name:"Lg",latexTrigger:["\\lg"],serialize:(e,n)=>"\\log_{10}"+e.wrapArguments(n),parse:e=>{let n=e.parseArguments("implicit");return n===null?"Lg":["Log",...n,10]}},{name:"Lb",latexTrigger:"\\lb",parse:e=>{let n=e.parseArguments("implicit");return n===null?"Log":["Log",n[0],2]}},{name:"Ln",latexTrigger:["\\ln"],parse:e=>Sa("Ln",e),serialize:(e,n)=>"\\ln"+e.wrapArguments(n)},{name:"Log",latexTrigger:["\\log"],parse:e=>Sa("Log",e),serialize:(e,n)=>{let[t,i]=_(n);return i?I(["\\log_{",e.serialize(i),"}",e.wrap(t)]):"\\log"+e.wrapArguments(n)}},{name:"LCM",latexTrigger:["\\lcm"],kind:"function"},{symbolTrigger:"lcm",kind:"function",parse:"LCM"},{symbolTrigger:"LCM",kind:"function",parse:"LCM"},{symbolTrigger:"max",kind:"function",parse:"Max",arguments:"implicit"},{symbolTrigger:"min",kind:"function",parse:"Min",arguments:"implicit"},{name:"Max",latexTrigger:"\\max",kind:"function",arguments:"implicit"},{name:"Min",latexTrigger:"\\min",kind:"function",arguments:"implicit"},{name:"Supremum",latexTrigger:"\\sup",kind:"function",arguments:"implicit"},{name:"Infimum",latexTrigger:"\\inf",kind:"function",arguments:"implicit"},{name:"Limit",latexTrigger:"\\lim",kind:"expression",parse:e=>{if(!e.match("_"))return null;let n=e.parseGroup();if(x(n)!=="To")return null;let t=e.parseExpression({minPrec:be});return t?["Limit",["Function",t,p(n,1)],p(n,2)]:null},serialize:(e,n)=>{let t=p(n,1),i=p(t,2),r=p(n,2);return I(["\\lim_{",e.serialize(i),"\\to",e.serialize(r),"}",e.serialize(p(t,1))])}},{name:"MinusPlus",latexTrigger:["\\mp"],kind:"infix",associativity:"any",precedence:He},{name:"Multiply",latexTrigger:["\\times"],kind:"infix",associativity:"any",precedence:be,serialize:ka},{latexTrigger:["\\cdot"],kind:"infix",associativity:"any",precedence:be,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:be+2});return i===null?null:Pn("Multiply",n,i)}},{latexTrigger:["*"],kind:"infix",associativity:"any",precedence:be,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:be+2});return i===null?["Multiply",n,$n]:Pn("Multiply",n,i)}},{name:"Mod",latexTrigger:"\\bmod",kind:"infix",precedence:Ne,serialize:(e,n)=>{if(X(n)!==2)return"";let t=e.serialize(p(n,1)),i=e.serialize(p(n,2));return I([t,"\\bmod",i])}},{latexTrigger:"\\mod",kind:"infix",precedence:Ne,parse:"Mod"},{latexTrigger:"\\operatorname{mod}",parse:"Mod"},{latexTrigger:"\\pmod",kind:"prefix",precedence:F,parse:e=>{let n=e.parseGroup()??e.parseToken();return["Mod",j(n)]}},{name:"Congruent",serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=e.serialize(p(n,2));if(p(n,3)===null)return I([t,"\\equiv",i]);let r=e.serialize(p(n,3));return I([t,"\\equiv",i,"\\pmod{",r,"}"])}},{name:"Negate",latexTrigger:["-"],kind:"prefix",precedence:it+1,parse:(e,n)=>{e.skipSpace();let t=e.parseExpression({...n,minPrec:it+3});return t===null?null:["Negate",t]}},{kind:"matchfix",openTrigger:"||",closeTrigger:"||",parse:(e,n)=>G(n)?null:["Norm",n]},{name:"Norm",kind:"matchfix",openTrigger:["\\left","\\Vert"],closeTrigger:["\\right","\\Vert"],parse:(e,n)=>G(n)?null:["Norm",n],serialize:(e,n)=>{let t=p(n,1);if(x(t)==="Matrix"){let i=p(t,1),r=p(t,2),s=r?["Matrix",i,{str:"\u2016\u2016"},r]:["Matrix",i,{str:"\u2016\u2016"}];return e.serialize(s)}return`\\left\\Vert ${e.serialize(t)}\\right\\Vert`}},{name:"PlusMinus",latexTrigger:["\\pm"],kind:"infix",associativity:"any",precedence:He,serialize:(e,n)=>{let t=p(n,1);if(t===null)return"\\pm";if(X(n)===1)return I(["\\pm",e.serialize(t)]);let i=p(n,2);return I([e.serialize(t),"\\pm",e.serialize(i)])}},{latexTrigger:["\\pm"],kind:"prefix",precedence:He,parse:(e,n)=>{let t=e.parseExpression({...n,minPrec:400});return["PlusMinus",0,j(t)]}},{latexTrigger:["\\plusmn"],kind:"infix",associativity:"any",precedence:He,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:400});return["PlusMinus",n,j(i)]}},{latexTrigger:["\\plusmn"],kind:"prefix",precedence:He,parse:(e,n)=>{let t=e.parseExpression({...n,minPrec:400});return["PlusMinus",j(t)]}},{name:"Power",latexTrigger:["^"],kind:"infix",serialize:mr},{latexTrigger:"\\prod",precedence:be,name:"Product",parse:Ta("Product","Multiply",be),serialize:_a("\\prod")},{latexTrigger:["*","*"],kind:"infix",associativity:"right",precedence:it,parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:it});return i===null?null:["Power",n,i]}},{name:"Rational",precedence:Ne,serialize:(e,n)=>n&&X(n)===1?"\\operatorname{Rational}"+e.wrapArguments(n):Ea(e,n)},{name:"Reduce",serialize:(e,n)=>{let t=p(n,1);if(!t)return"";let i=p(n,2);return k(i)==="Add"?`\\sum ${e.serialize(t)}`:k(i)==="Multiply"?`\\prod ${e.serialize(t)}`:`\\operatorname{Reduce}\\left(${e.serialize(t)}, ${e.serialize(p(n,2))}\\right)`}},{name:"Root",serialize:mr},{name:"Round",symbolTrigger:"round",kind:"function"},{name:"Square",precedence:720,serialize:(e,n)=>{let t=e.wrapShort(p(n,1));return(t.startsWith("-")?e.wrapString(t,"normal"):t)+"^2"}},{latexTrigger:["\\sum"],precedence:ee,name:"Sum",parse:Ta("Sum","Add",be),serialize:_a("\\sum")},{name:"Heaviside",symbolTrigger:"Heaviside",kind:"function"},{name:"Sign",symbolTrigger:"sgn",kind:"function"},{name:"Sqrt",latexTrigger:["\\sqrt"],parse:Dc,serialize:mr},{name:"Subtract",latexTrigger:["-"],kind:"infix",associativity:"left",precedence:ee+2,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:ee+3});return i===null?null:["Subtract",n,i]},serialize:(e,n)=>{let t=e.wrap(p(n,1),ee+2),i=e.wrap(p(n,2),ee+3);return I([t,"-",i])}},{name:"Distance",latexTrigger:["\\operatorname{distance}"],kind:"function",serialize:(e,n)=>"\\operatorname{distance}"+e.wrapArguments(n)}];function Oc(e,n){if(e!==null){if(k(e))return{index:k(e)??"Nothing",upper:n};if(x(e)==="GreaterEqual"){let t=k(p(e,1))??"Nothing",i=p(e,2)??1;return{index:t,lower:i,upper:n}}if(x(e)==="Equal"){let t=k(p(e,1))??"Nothing",i=p(e,2);if(x(i)==="Range"){let s=p(i,1)??1,o=p(i,2)??void 0;return{index:t,lower:s,upper:o}}return{index:t,lower:i??1,upper:n}}if(x(e)==="Element")return{index:k(p(e,1))??"Nothing",element:e}}}function Lc(e){let n=x(e);return n?new Set(["Less","LessEqual","Greater","GreaterEqual","NotEqual","And","Or","Not"]).has(n):!1}function Na(e){if(e===null)return[];let n=bn(e);if(n)return[...n];if(x(e)==="Tuple"){let t=_(e);return t?[...t]:[e]}return[e]}function Bc(e,n){G(e)&&(e=null),G(n)&&(n=null);let t=Na(e),i=Na(n),r=[],s=0;for(;s<t.length;){let o=t[s],a=Oc(o,i[s]);if(a){if(a.element&&s+1<t.length){let u=t[s+1];if(Lc(u)&&x(u)!=="Element"&&x(u)!=="Equal"){let l=a.element;if(Array.isArray(l)&&l.length>=3){let c=[l[0],...l.slice(1),u];a.element=c}s++}}r.push(a)}s++}return r}function Ta(e,n,t){return i=>{i.skipSpace(),i.pushSymbolTable();let r=null,s=null;for(;!(s&&r)&&(i.peek==="_"||i.peek==="^");)i.match("_")?s=i.parseGroup()??i.parseToken():i.match("^")&&(r=i.parseGroup()??i.parseToken()),i.skipSpace();if(!r&&!s){let l=i.parseExpression({minPrec:t});return i.popSymbolTable(),l?["Reduce",l,n]:null}let o=Bc(s,r),a=i.parseExpression({minPrec:t});if(i.popSymbolTable(),a===null)return[e];let u=[];for(let l of o){if(l.element){u.push(l.element);continue}let c=l.lower,f=l.upper,d=l.index??"Nothing";f!=null?u.push(["Tuple",d,c??1,f]):c!=null?u.push(["Tuple",d,c]):u.push(["Tuple",d])}return[e,a,...u]}}var Vc=new Set(["Tuple","Triple","Pair","Single","Limits","Element"]);function Ia(e){return e==null||k(e)==="Nothing"?null:e}function qc(e){let n=[],t=_(e);if(t.length<=1)return n;for(let i of t.slice(1)){let r=x(i);if(r&&Vc.has(r)){n.push(i);continue}break}return n}function Jc(e,n){if(x(n)==="Element"){let l=e.serialize(p(n,1)),c=e.serialize(p(n,2));return{sub:`${l}\\in ${c}`}}let t=p(n,1);t!==null&&x(t)==="Hold"&&(t=p(t,1));let i=Ia(p(n,2)),r=Ia(p(n,3)),s={},o=t?k(t):null,a=o!==null&&o!=="Nothing",u=a&&t?e.serialize(t):void 0;return a&&i!==null&&u?s.sub=`${u}=${e.serialize(i)}`:a&&u?s.sub=u:i!==null&&(s.sub=e.serialize(i)),r!==null&&(s.sup=e.serialize(r)),s}function _a(e){return(n,t)=>{let i=p(t,1);if(!i)return e;let r=qc(t),s=e;if(r.length>0){let o=[],a=[];for(let u of r){let l=Jc(n,u);l.sub&&o.push(l.sub),l.sup&&a.push(l.sup)}o.length>0&&(s=An("_",s,o.join(", "))),a.length>0&&(s=An("^",s,a.join(", ")))}return I([s,n.serialize(i)])}}function Sa(e,n){let t=null;n.match("_")&&(t=n.parseGroup()??n.parseToken());let i=n.parseArguments("implicit");return i===null&&t===null?[e]:i===null?[e,t]:t===null?[e,...i]:t===10?["Log",i[0]]:t===2?["Lb",...i]:["Log",i[0],t]}function ut(e){let n=1,t=e;do{e=t;let i=x(e);if(i==="Negate")n*=-1,t=p(e,1);else if(i==="Multiply"){let[r,s]=ut(p(e,1));s<0&&(n*=-1,r===1?t=["Multiply",..._(e).slice(1)]:t=["Multiply",r,..._(e).slice(1)])}else if(i==="Divide"||i==="Rational"){let[r,s]=ut(p(e,1));s<0&&(n*=-1,t=[i,r,p(e,2)])}else{let r=D(e);r!==null&&r<0&&(n*=-1,t=-r)}}while(t!==e);return[e,n]}var wa=[{name:"Real",kind:"function",latexTrigger:["\\Re"],arguments:"implicit"},{name:"Imaginary",kind:"function",latexTrigger:["\\Im"],arguments:"implicit"},{name:"Argument",kind:"function",latexTrigger:["\\arg"],arguments:"implicit"},{name:"Conjugate",latexTrigger:["^","\\star"],kind:"postfix"}];function A(e){return(n,t)=>{let i={"\\arcsin":"Arcsin","\\arccos":"Arccos","\\arctan":"Arctan","\\arctg":"Arctan","\\arcctg":"Arccot","\\arcsec":"Arcsec","\\arccsc":"Arccsc","\\arsinh":"Arsinh","\\arcsinh":"Arsinh","\\arcosh":"Arcosh","\\arccosh":"Arcosh","\\artanh":"Artanh","\\arctanh":"Artanh","\\arsech":"Arsech","\\arcsech":"Arsech","\\arcsch":"Arcsch","\\arccsch":"Arcsch","\\arcoth":"Arcoth","\\arccoth":"Arcoth","\\ch":"Cosh","\\cos":"Cos","\\cosh":"Cosh","\\cosec":"Csc","\\cot":"Cot","\\cotg":"Cot","\\ctg":"Cot","\\csc":"Csc","\\csch":"Csch","\\coth":"Coth","\\cth":"Coth","\\sec":"Sec","\\sech":"Sech","\\sin":"Sin","\\sinh":"Sinh","\\sh":"Sinh","\\tan":"Tan","\\tg":"Tan","\\tanh":"Tanh","\\th":"Tanh"},r=i[e??""]??e??"";if(n.atTerminator(t))return r;let s=r;do{let f=n.parsePostfixOperator(s,t);if(f===null)break;s=f}while(!0);n.skipSpace();let o=null;n.match("^")&&(o=n.parseGroup()??n.parseToken()),n.skipSpace();let a=n.parseArguments("implicit",{minPrec:be,condition:f=>i[f.peek]||(t?.condition?.(f)??!1)}),l=a?.length===2&&(s==="Arctan"||Array.isArray(s)&&s[0]==="InverseFunction"&&s[1]==="Tan")?"Arctan2":s,c=a===null?s:typeof l=="string"?[l,...a]:["Apply",l,...a];return o===null?c:["Power",c,o]}}var Aa=[{name:"Arcsin",latexTrigger:["\\arcsin"],parse:A("Arcsin")},{name:"Arccos",latexTrigger:["\\arccos"],parse:A("Arccos")},{name:"Arctan",latexTrigger:["\\arctan"],parse:A("Arctan")},{latexTrigger:["\\arctg"],parse:A("Arctan")},{symbolTrigger:"arctg",parse:A("Arctan")},{name:"Arccot",symbolTrigger:"arcctg",parse:A("Arccot")},{latexTrigger:["\\arcctg"],parse:A("Arccot")},{name:"Arcoth",symbolTrigger:"arcoth",parse:A("Arcoth")},{symbolTrigger:"arccoth",parse:A("Arcoth")},{latexTrigger:["\\arcoth"],parse:A("Arcoth")},{latexTrigger:["\\arccoth"],parse:A("Arcoth")},{name:"Arcsec",symbolTrigger:"arcsec",parse:A("Arcsec")},{latexTrigger:["\\arcsec"],parse:A("Arcsec")},{name:"Arccsc",symbolTrigger:"arccsc",parse:A("Arccsc")},{latexTrigger:["\\arccsc"],parse:A("Arccsc")},{name:"Arsinh",symbolTrigger:"arsinh",parse:A("Arsinh")},{symbolTrigger:"arcsinh",parse:A("Arsinh")},{latexTrigger:["\\arsinh"],parse:A("Arsinh")},{latexTrigger:["\\arcsinh"],parse:A("Arsinh")},{name:"Arcosh",symbolTrigger:"arcosh",parse:A("Arcosh")},{symbolTrigger:"arccosh",parse:A("Arcosh")},{latexTrigger:"\\arcosh",parse:A("Arcosh")},{latexTrigger:"\\arccosh",parse:A("Arcosh")},{name:"Artanh",symbolTrigger:"artanh",parse:A("Artanh")},{symbolTrigger:"arctanh",parse:A("Artanh")},{latexTrigger:"\\artanh",parse:A("Artanh")},{latexTrigger:["\\arctanh"],parse:A("Artanh")},{name:"Arsech",symbolTrigger:"arsech",parse:A("Arsech")},{symbolTrigger:"arcsech",parse:A("Arsech")},{latexTrigger:["\\arsech"],parse:A("Arsech")},{latexTrigger:["\\arcsech"],parse:A("Arsech")},{name:"Arcsch",symbolTrigger:"arcsch",parse:A("Arcsch")},{symbolTrigger:"arccsch",parse:A("Arcsch")},{latexTrigger:["\\arcsch"],parse:A("Arcsch")},{latexTrigger:["\\arccsch"],parse:A("Arcsch")},{name:"Cosec",symbolTrigger:"cosec",parse:A("Cosec")},{latexTrigger:["\\cosec"],parse:A("Cosec")},{name:"Cosh",latexTrigger:["\\cosh"],parse:A("Cosh")},{latexTrigger:["\\ch"],parse:A("Cosh")},{name:"Cot",latexTrigger:["\\cot"],parse:A("Cot")},{latexTrigger:["\\cotg"],parse:A("Cot")},{latexTrigger:["\\ctg"],parse:A("Cot")},{name:"Csc",latexTrigger:["\\csc"],parse:A("Csc")},{name:"Csch",latexTrigger:["\\csch"],parse:A("Csch")},{name:"Coth",latexTrigger:["\\coth"],parse:A("Coth")},{latexTrigger:["\\cth"],parse:A("Coth")},{symbolTrigger:"cth",parse:A("Coth")},{latexTrigger:["\\coth"],parse:A("Coth")},{name:"Sec",latexTrigger:["\\sec"],parse:A("Sec")},{name:"Sech",symbolTrigger:"sech",parse:A("Sech")},{latexTrigger:["\\sech"],parse:A("Sech")},{name:"Sinh",latexTrigger:["\\sinh"],parse:A("Sinh")},{latexTrigger:["\\sh"],parse:A("Sinh")},{name:"Tan",latexTrigger:["\\tan"],parse:A("Tan")},{latexTrigger:["\\tg"],parse:A("Tan")},{name:"Tanh",latexTrigger:["\\tanh"],parse:A("Tanh")},{latexTrigger:["\\th"],parse:A("Tanh")},{name:"Cos",latexTrigger:["\\cos"],parse:A("Cos")},{name:"Sin",latexTrigger:["\\sin"],parse:A("Sin")},{name:"Sinc",symbolTrigger:"sinc",kind:"function"},{name:"FresnelS",symbolTrigger:"FresnelS",kind:"function"},{name:"FresnelC",symbolTrigger:"FresnelC",kind:"function"}];function Fn(e){return n=>{let t=!1,i=[],r=[];for(;!t;){n.skipVisualSpace(),n.match("\\limits"),n.skipSpace();let a=null,u=null;for(;!(u!==null&&a!==null)&&(n.peek==="_"||n.peek==="^");)n.match("_")?u=n.parseGroup()??n.parseToken():n.match("^")&&(a=n.parseGroup()??n.parseToken()),n.skipSpace();G(u)&&(u=null),G(a)&&(a=null),i.push(u??"Nothing"),r.push(a??"Nothing"),n.skipVisualSpace(),t=!n.match(e)}let[s,o]=zc(n);if(s&&o.length===0){if(x(s)==="Add"||x(s)==="Subtract"){let a=[],u=[];for(let l of _(s))if(o)u.push(l);else{let c;[c,o]=Ye(l),a.push(c??l)}if(o!==null&&u.length>0)return["Add",$a(e,["Add",...a],{indexes:o,subs:i,sups:r})??"Nothing",...u]}else if(x(s)==="Divide"){let a;[a,o]=Ye(p(s,1)),a!==null&&o!==null&&(s=["Divide",a,p(s,2)])}}return $a(e,s,{indexes:o,subs:i,sups:r})}}function $a(e,n,t){if(!n)return null;if(t.sups.length===0&&t.subs.length===0)return[e,n,...t.indexes];let i=t.indexes.length===0?x(n)==="Function"?_(n).slice(1):[]:t.indexes,r=Math.max(t.sups.length,t.subs.length,i.length);if(i.length===0)for(let o=0;o<r;o++)i.push("Nothing");else if(i.length!==r)for(let o=i.length;o<r;o++)i.push(["Error","'missing'"]);if(t.subs.length!==r)for(let o=t.subs.length;o<r;o++)t.subs.push("Nothing");if(t.sups.length!==r)for(let o=t.sups.length;o<r;o++)t.sups.push("Nothing");let s=i.map((o,a)=>{let u=t.sups[a],l=t.subs[a];return l==="Nothing"&&u==="Nothing"?o:["Tuple",o,l,u]});return[e,n,...s]}function zc(e){let n=!1,t=e.parseExpression({minPrec:266,condition:()=>{let i=e.index;return n=Da(e),e.index=i,n}});return t!==null&&!n?Ye(t):[t,Gc(e)]}function Gc(e){let n=[];for(;Da(e);){e.skipVisualSpace();let t=k(e.parseSymbol());if(t===null)return n;n.push(t)}return n}function Ye(e){let n=x(e),t=p(e,1);if(!t)return[e,[]];if(n==="Sequence"&&X(e)===1)return Ye(t);if(n==="Multiply"||n==="InvisibleOperator"){let i=_(e);if(i){let[r,s]=jc(i);return r.length>0?[[n,...r],s]:[null,s]}}else if(n==="Delimiter"){let[i,r]=Ye(t);if(r)return i?[["Delimiter",["Sequence",i],..._(e).slice(1)],r]:[null,r]}else if(n==="Add"){let i=_(e);if(i.length>0){let[r,s]=Ye(i[i.length-1]);if(s.length>0){if(r)return[["Add",...i.slice(0,-1),r],s];if(i.length>2)return[["Add",...i.slice(0,-1)],s];if(i.length>2)return[i[0],s]}}}else if(n==="Negate"){let[i,r]=Ye(t);if(r.length>0)return[i?["Negate",i]:null,r]}else if(n==="Divide"){let[i,r]=Ye(t);if(r.length>0)return[["Divide",i??1,p(e,2)],r]}else{let i=_(e);if(i.length===1){let[r,s]=Ye(i[0]);if(s.length>0)return[[x(e),r],s]}}return[e,[]]}function Ca(e){return(n,t)=>{if(!p(t,1))return e;let i=p(t,1),r=[];x(i)==="BuiltInFunction"?(r=["x"],i=[p(i,1),"x"]):x(i)==="Function"?(r=_(i).slice(1),i=p(i,1)):k(i)?r=[]:r=[];let s=_(t).slice(1),o=[],a=s.map((l,c)=>{if(k(l)==="Nothing")return o.push(k(r[c])??"Nothing"),"";if(k(l))return o.push(k(l)??"Nothing"),"";let f=x(l);if(f==="Tuple"||f==="Pair"||f==="Limits"||f==="Range"){if(X(l)===3){let d=p(l,1);o.push(k(d)??"Nothing");let m=p(l,2),g=p(l,3);return k(m)==="Nothing"&&(m=null),k(g)==="Nothing"&&(g=null),m!==null&&g!==null?`_{${n.serialize(m)}}^{${n.serialize(g)}}`:m!==null?`_{${n.serialize(m)}}`:g!==null?`^{${n.serialize(g)}}`:""}return`_{${n.serialize(l)}}`}if(X(l)===2){if(k(p(l,1))){o.push(k(p(l,1))??"Nothing");let g=p(l,2);return k(g)==="Nothing"?"":`_{${n.serialize(g)}}`}o.push(k(r[c])??"Nothing");let d=p(l,1),m=p(l,2);if(k(d)==="Nothing"&&(d=null),k(m)==="Nothing"&&(m=null),d!==null&&m!==null)return`_{${n.serialize(d)}}^{${n.serialize(m)}}`;if(d!==null)return`_{${n.serialize(d)}}`;if(m!==null)return`^{${n.serialize(m)}}`}else o.push(k(r[c])??"Nothing")}),u=o.filter(l=>k(l)!=="Nothing").map(l=>`\\mathrm{d}${n.serialize(k(l)??"x")}`);return u.length>0&&(u=["\\,",...u]),a.length===0?`${e}\\,${n.serialize(i)}\\!${u.join(" ")}`:a.reverse().map(l=>`${e}${l}`).join("")+"\\!"+n.serialize(i)+u.join(" ")}}var Ra=[{kind:"expression",name:"Integrate",latexTrigger:["\\int"],parse:Fn("Integrate"),serialize:Ca("\\int")},{kind:"expression",latexTrigger:["\\iint"],parse:Fn("Integrate")},{kind:"expression",latexTrigger:["\\iiint"],parse:Fn("Integrate")},{kind:"expression",name:"CircularIntegrate",latexTrigger:["\\oint"],parse:Fn("CircularIntegrate"),serialize:Ca("\\oint")},{kind:"expression",latexTrigger:["\\oiint"],parse:Fn("CircularIntegrate")},{kind:"expression",latexTrigger:["\\oiiint"],parse:Fn("CircularIntegrate")}];function Da(e){let n=e.index;for(;e.match("\\cdot")||e.skipVisualSpace(););return e.matchAll(["\\mathrm","<{>","d","<}>"])||e.matchAll(["\\operatorname","<{>","d","<}>"])||e.match("d")||e.match("\\differentialD")?!0:(e.index=n,!1)}function jc(e){let n=[...e],t=[];for(;n.length>0;){let i;if([n,i]=Uc(n),!i)break;t.push(i)}return[n,t]}function Uc(e){if(e.length<2)return[e,""];let n=e[e.length-2];if(n==="d"||n==="d_upright"){let t=k(e[e.length-1]);if(t)return[e.slice(0,-2),t]}return[e,""]}var Pa=[{name:"Matrix",serialize:(e,n)=>{let t=_(p(n,1));return dr(e,t,q(p(n,2)),q(p(n,3)))}},{name:"Vector",serialize:(e,n)=>{let t=_(n);return dr(e,t.map(i=>["List",i]),q(p(n,2)),q(p(n,3)))}},{kind:"environment",symbolTrigger:"pmatrix",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?[t,i,{str:"()"},{str:n}]:[t,i]}},{kind:"environment",symbolTrigger:"bmatrix",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?[t,i,{str:"[]"},{str:n}]:[t,i,{str:"[]"}]}},{kind:"environment",symbolTrigger:"Bmatrix",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?[t,i,{str:"{}"},{str:n}]:[t,i,{str:"{}"}]}},{kind:"environment",symbolTrigger:"vmatrix",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?["Determinant",[t,i,{str:n}]]:["Determinant",[t,i]]}},{kind:"environment",symbolTrigger:"Vmatrix",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?["Norm",[t,i,{str:n}]]:["Norm",[t,i]]}},{kind:"environment",symbolTrigger:"smallmatrix",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?[t,i,{str:"()"},{str:n}]:[t,i]}},{kind:"environment",symbolTrigger:"array",parse:e=>{let n=Xe(e,!1),[t,i]=We(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{kind:"environment",symbolTrigger:"matrix",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{kind:"environment",symbolTrigger:"matrix*",parse:e=>{let n=Xe(e),[t,i]=We(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{name:"ConjugateTranspose",kind:"postfix",latexTrigger:["^","\\star"]},{kind:"postfix",latexTrigger:["^","\\H"],parse:"ConjugateTranspose"},{kind:"postfix",latexTrigger:["^","\\dagger"],parse:(e,n)=>["ConjugateTranspose",n]},{kind:"postfix",latexTrigger:["^","\\ast"],parse:(e,n)=>["ConjugateTranspose",n]},{kind:"postfix",latexTrigger:["^","\\top"],parse:(e,n)=>["Transpose",n]},{kind:"postfix",latexTrigger:["^","\\intercal"],parse:(e,n)=>["Transpose",n]},{name:"Transpose",kind:"postfix",latexTrigger:["^","T"]},{name:"PseudoInverse",kind:"postfix",latexTrigger:["^","+"]},{name:"Inverse",serialize:(e,n)=>e.serialize(p(n,1))+"^{-1}"},{name:"Trace",kind:"function",latexTrigger:"\\tr",arguments:"implicit",serialize:(e,n)=>On(e,n,"\\tr")},{symbolTrigger:"tr",kind:"function",parse:"Trace",arguments:"implicit"},{name:"Kernel",kind:"function",latexTrigger:"\\ker",arguments:"implicit",serialize:(e,n)=>On(e,n,"\\ker")},{symbolTrigger:"ker",kind:"function",parse:"Kernel",arguments:"implicit"},{name:"Dimension",kind:"function",latexTrigger:"\\dim",arguments:"implicit",serialize:(e,n)=>On(e,n,"\\dim")},{symbolTrigger:"dim",kind:"function",parse:"Dimension",arguments:"implicit"},{name:"Degree",kind:"function",latexTrigger:"\\deg",arguments:"implicit",serialize:(e,n)=>On(e,n,"\\deg")},{symbolTrigger:"deg",kind:"function",parse:"Degree",arguments:"implicit"},{name:"Hom",kind:"function",latexTrigger:"\\hom",arguments:"implicit",serialize:(e,n)=>On(e,n,"\\hom")},{symbolTrigger:"hom",kind:"function",parse:"Hom",arguments:"implicit"},{name:"Determinant",kind:"function",latexTrigger:"\\det",arguments:"implicit",serialize:(e,n)=>{let t=p(n,1);if(x(t)==="Matrix"){let i=_(p(t,1));return dr(e,i,"||",q(p(t,2)))}return On(e,n,"\\det")}},{symbolTrigger:"det",kind:"function",parse:"Determinant",arguments:"implicit"},{name:"MatrixMultiply",serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=e.serialize(p(n,2));return`${t} \\cdot ${i}`}}];function We(e){let n=e.parseTabular();return n?["Matrix",["List",...n.map(t=>["List",...t])]]:["",null]}function Xe(e,n=!0){let t=e.parseStringGroup(n)?.trim();if(!t)return"";let i="";for(let r of t)r==="c"&&(i+="="),r==="l"&&(i+="<"),r==="r"&&(i+=">"),r==="|"&&(i+="|"),r===":"&&(i+=":");return i}function On(e,n,t){if(_(n).length!==1)return`${t}${e.wrapArguments(n)}`;let r=p(n,1),s=e.serialize(r);return typeof r=="string"||typeof r=="number"?`${t} ${s}`:`${t}\\left(${s}\\right)`}function dr(e,n,t,i){t??="()";let[r,s]=["",""];typeof t=="string"&&t.length===2&&([r,s]=t);let o="";if(i)for(let c of i)c==="<"?o+="l":c===">"?o+="r":c==="="?o+="c":c==="|"?o+="|":c===":"&&(o+=":");let a=[];for(let c of n??[]){let f=[];for(let d of _(c))f.push(e.serialize(d));a.push(f.join(" & "))}let u=a.join(`\\\\
8
+ `),l=o.length>0?`[${o}]`:"";return r==="("&&s===")"?I(["\\begin{pmatrix}",l,u,"\\end{pmatrix}"]):r==="["&&s==="]"?I(["\\begin{bmatrix}",l,u,"\\end{bmatrix}"]):r==="{"&&s==="}"?I(["\\begin{Bmatrix}",l,u,"\\end{Bmatrix}"]):r==="|"&&s==="|"?I(["\\begin{vmatrix}",l,u,"\\end{vmatrix}"]):r==="\u2016"&&s==="\u2016"?I(["\\begin{Vmatrix}",l,u,"\\end{Vmatrix}"]):r==="{"&&s==="."?I(["\\begin{dcases}",l,u,"\\end{dcases}"]):r==="."&&s==="}"?I(["\\begin{rcases}",l,u,"\\end{rcases}"]):o||r!=="."||s!=="."?I(["\\left",Ht[r]??r,"\\begin{array}",`{${o}}`,u,"\\end{array}","\\right",Ht[s]??s]):I(["\\begin{matrix}",u,"\\end{matrix}"])}var Fa=[{name:"Mean",kind:"function",symbolTrigger:"mean"},{name:"Median",kind:"function",symbolTrigger:"median"},{name:"StandarDeviation",kind:"function",symbolTrigger:"stddev"},{latexTrigger:["\\bar"],kind:"expression",parse:(e,n)=>{let t=e.parseGroup()??e.parseToken();return!t||!k(t)?null:["Mean",t]}},{latexTrigger:"\\operatorname{var}",parse:"Variance"}];var Xt={Q:1e30,R:1e27,Y:1e24,Z:1e21,E:1e18,P:1e15,T:1e12,G:1e9,M:1e6,k:1e3,h:100,da:10,d:.1,c:.01,m:.001,\u00B5:1e-6,\u03BC:1e-6,n:1e-9,p:1e-12,f:1e-15,a:1e-18,z:1e-21,y:1e-24,r:1e-27,q:1e-30},Oa=new Set(["m","g","s","A","K","mol","cd","Hz","N","Pa","J","W","C","V","F","ohm","S","Wb","T","H","lm","lx","Bq","Gy","Sv","kat","eV","L","bar"]),Qt={m:{dimension:[1,0,0,0,0,0,0],scale:1},kg:{dimension:[0,1,0,0,0,0,0],scale:1},g:{dimension:[0,1,0,0,0,0,0],scale:.001},s:{dimension:[0,0,1,0,0,0,0],scale:1},A:{dimension:[0,0,0,1,0,0,0],scale:1},K:{dimension:[0,0,0,0,1,0,0],scale:1},mol:{dimension:[0,0,0,0,0,1,0],scale:1},cd:{dimension:[0,0,0,0,0,0,1],scale:1},Hz:{dimension:[0,0,-1,0,0,0,0],scale:1},N:{dimension:[1,1,-2,0,0,0,0],scale:1},Pa:{dimension:[-1,1,-2,0,0,0,0],scale:1},J:{dimension:[2,1,-2,0,0,0,0],scale:1},W:{dimension:[2,1,-3,0,0,0,0],scale:1},C:{dimension:[0,0,1,1,0,0,0],scale:1},V:{dimension:[2,1,-3,-1,0,0,0],scale:1},F:{dimension:[-2,-1,4,2,0,0,0],scale:1},ohm:{dimension:[2,1,-3,-2,0,0,0],scale:1},S:{dimension:[-2,-1,3,2,0,0,0],scale:1},Wb:{dimension:[2,1,-2,-1,0,0,0],scale:1},T:{dimension:[0,1,-2,-1,0,0,0],scale:1},H:{dimension:[2,1,-2,-2,0,0,0],scale:1},lm:{dimension:[0,0,0,0,0,0,1],scale:1},lx:{dimension:[-2,0,0,0,0,0,1],scale:1},Bq:{dimension:[0,0,-1,0,0,0,0],scale:1},Gy:{dimension:[2,0,-2,0,0,0,0],scale:1},Sv:{dimension:[2,0,-2,0,0,0,0],scale:1},kat:{dimension:[0,0,-1,0,0,1,0],scale:1},degC:{dimension:[0,0,0,0,1,0,0],scale:1,offset:273.15},degF:{dimension:[0,0,0,0,1,0,0],scale:5/9,offset:459.67},min:{dimension:[0,0,1,0,0,0,0],scale:60},h:{dimension:[0,0,1,0,0,0,0],scale:3600},d:{dimension:[0,0,1,0,0,0,0],scale:86400},ha:{dimension:[2,0,0,0,0,0,0],scale:1e4},L:{dimension:[3,0,0,0,0,0,0],scale:.001},t:{dimension:[0,1,0,0,0,0,0],scale:1e3},eV:{dimension:[2,1,-2,0,0,0,0],scale:1602176634e-28},Da:{dimension:[0,1,0,0,0,0,0],scale:16605390666e-37},au:{dimension:[1,0,0,0,0,0,0],scale:149597870700},deg:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/180},rad:{dimension:[0,0,0,0,0,0,0],scale:1},grad:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/200},turn:{dimension:[0,0,0,0,0,0,0],scale:2*Math.PI},arcmin:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/10800},arcsec:{dimension:[0,0,0,0,0,0,0],scale:Math.PI/648e3},percent:{dimension:[0,0,0,0,0,0,0],scale:.01},ppm:{dimension:[0,0,0,0,0,0,0],scale:1e-6},dB:{dimension:[0,0,0,0,0,0,0],scale:1},Np:{dimension:[0,0,0,0,0,0,0],scale:1},in:{dimension:[1,0,0,0,0,0,0],scale:.0254},ft:{dimension:[1,0,0,0,0,0,0],scale:.3048},mi:{dimension:[1,0,0,0,0,0,0],scale:1609.344},lb:{dimension:[0,1,0,0,0,0,0],scale:.45359237},oz:{dimension:[0,1,0,0,0,0,0],scale:.028349523125},gal:{dimension:[3,0,0,0,0,0,0],scale:.003785411784},atm:{dimension:[-1,1,-2,0,0,0,0],scale:101325},bar:{dimension:[-1,1,-2,0,0,0,0],scale:1e5},cal:{dimension:[2,1,-2,0,0,0,0],scale:4.184},kWh:{dimension:[2,1,-2,0,0,0,0],scale:36e5},\u00C5:{dimension:[1,0,0,0,0,0,0],scale:1e-10}};function Hc(e){if(e.length>2){let n=e.slice(0,2),t=e.slice(2);if(Xt[n]!==void 0&&Oa.has(t)){let i=Qt[t];if(i)return{prefixScale:Xt[n],baseEntry:i}}}if(e.length>1){let n=e.slice(0,1),t=e.slice(1);if(Xt[n]!==void 0&&Oa.has(t)){let i=Qt[t];if(i)return{prefixScale:Xt[n],baseEntry:i}}}return null}function Zc(e){let n=Qt[e];if(n)return n;let t=Hc(e);return t?{dimension:t.baseEntry.dimension,scale:t.prefixScale*t.baseEntry.scale}:null}function hr(e){let n=Zc(e);return n?n.dimension:null}var T0=new Map(["N","J","W","Pa","Hz","C","V","F","ohm","S","Wb","T","H","lm","lx","Gy","kat"].map(e=>[Qt[e].dimension.join(","),e]));function Yc(e){let n=e.indexOf("^");if(n===-1)return e;let t=e.slice(0,n),i=e.slice(n+1),r=parseInt(i,10);return isNaN(r)?e:["Power",t,r]}function lt(e){if(e=e.trim(),e.length===0)return null;if(e[0]==="("&&e[e.length-1]===")"){let r=0,s=!0;for(let o=0;o<e.length-1;o++)if(e[o]==="("?r++:e[o]===")"&&r--,r===0&&o<e.length-1){s=!1;break}if(s)return lt(e.slice(1,-1))}let n=-1,t=[],i=0;for(let r=0;r<e.length;r++)e[r]==="("?i++:e[r]===")"?i--:i===0&&(e[r]==="/"&&n===-1?n=r:e[r]==="*"&&t.push(r));if(n!==-1){let r=e.slice(0,n).trim(),s=e.slice(n+1).trim(),o=lt(r),a=lt(s);return!o||!a?null:["Divide",o,a]}if(t.length>0){let r=[],s=0;for(let a of t)r.push(e.slice(s,a).trim()),s=a+1;r.push(e.slice(s).trim());let o=r.filter(a=>a.length>0).map(a=>lt(a));return o.some(a=>a===null)?null:o.length===1?o[0]:["Multiply",...o]}return e[0]==="("?null:Yc(e)}function La(e){return e=e.trim(),e.length===0?null:/[/*^()]/.test(e)?lt(e):e}function Ja(e){if(!e.match("<{>"))return null;let n="",t=0;for(;!e.atEnd;){let i=e.peek;if(i==="<}>"&&t===0)return e.nextToken(),n;if(i==="<}>"){t--,e.nextToken();continue}if(i==="<{>"){t++,e.nextToken();continue}if(i==="<space>"){e.nextToken();continue}if(i==="\\cdot"){n+="*",e.nextToken();continue}if(i==="^"){n+="^",e.nextToken();continue}n+=i,e.nextToken()}return null}var Wc=new Set(["d"]);function za(e){if(!e||e.length===0||Wc.has(e))return null;if(hr(e)!==null)return e;if(/[/*^]/.test(e))try{let n=La(e);if(n!==null&&gr(n))return n}catch{return null}return null}function gr(e){if(typeof e=="string")return hr(e)!==null;if(!Array.isArray(e))return!1;let n=e[0];return n==="Multiply"||n==="Divide"?e.slice(1).every(t=>gr(t)):n==="Power"?gr(e[1]):!1}var Ba=e=>{let n=e.index,t=Ja(e);if(t===null)return e.index=n,null;let i=za(t);return i===null?(e.index=n,null):["__unit__",i]};function En(e){let n=k(e);if(n!==null)return n;if(typeof e=="number")return String(e);let t=x(e);if(!t)return"";if(t==="Divide"){let i=p(e,1),r=p(e,2);return`${En(i)}/${En(r)}`}if(t==="Multiply"){let i=[];if(Array.isArray(e))for(let r=1;r<e.length;r++)i.push(En(e[r]));return i.join("\\cdot ")}if(t==="Power"){let i=p(e,1),r=p(e,2),s=typeof r=="number"?String(r):k(r)??String(r);return`${En(i)}^{${s}}`}if(t==="Square"){let i=p(e,1);return`${En(i)}^{2}`}return""}function Va(e){let n=e.parseGroup();if(n===null)return null;let t=Ga(e);return t===null?null:["Quantity",n,t]}function qa(e){return Ga(e)}function Ga(e){let n=e.index,t=Ja(e);if(t===null)return e.index=n,null;let i=za(t);return i===null?(e.index=n,null):i}var ja=[{latexTrigger:"\\mathrm",kind:"expression",parse:Ba},{latexTrigger:"\\text",kind:"expression",parse:Ba},{latexTrigger:"\\qty",parse:Va},{latexTrigger:"\\SI",parse:Va},{latexTrigger:"\\unit",parse:qa},{latexTrigger:"\\si",parse:qa},{name:"Quantity",serialize:(e,n)=>{let t=p(n,1),i=p(n,2);if(t===null||i===null)return"";let r=k(i),s=r==="deg"||r==="rad"||r==="arcmin"||r==="arcsec",o=e.options;if(s&&(o.dmsFormat||o.angleNormalization&&o.angleNormalization!=="none")){let l=D(t);if(l===null){let f=e.serialize(t),d=En(i);return I([f,"\\,",`\\mathrm{${d}}`])}let c=l;return r==="rad"?c=c*180/Math.PI:r==="arcmin"?c=c/60:r==="arcsec"&&(c=c/3600),o.angleNormalization&&o.angleNormalization!=="none"&&(c=Zt(c,o.angleNormalization)),o.dmsFormat?Yt(c):`${c}\xB0`}let a=e.serialize(t),u=En(i);return I([a,"\\,",`\\mathrm{${u}}`])}}];var Xc=["pt","em","mu","ex","mm","cm","in","bp","sp","dd","cc","pc","nc","nd"];function Ua(e){for(e.skipSpace(),(e.peek==="-"||e.peek==="+")&&e.nextToken();/^[\d.]$/.test(e.peek);)e.nextToken();for(let n of Xc)if(e.matchAll([...n]))return}function xe(e){return n=>{let t=n.parseGroup();return t===null?[e]:[e,t]}}function Kt(e){return n=>{let t=n.parseExpression();return t!==null&&!G(t)?["Annotated",t,{dict:{mathStyle:e}}]:"Nothing"}}function Fe(e){return n=>{let t=n.parseExpression();return t!==null&&!G(t)?["Annotated",t,{dict:{size:e}}]:"Nothing"}}var Ha=[{name:"Overscript",latexTrigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",latexTrigger:["\\underset"],kind:"infix",precedence:700},{name:"Increment",latexTrigger:["+","+"],kind:"postfix",precedence:880,parse:(e,n)=>k(n)===null?null:["Increment",n]},{name:"Decrement",latexTrigger:["-","-"],kind:"postfix",precedence:880,parse:(e,n)=>k(n)===null?null:["Decrement",n]},{name:"PreIncrement",latexTrigger:["+","+"],kind:"prefix",precedence:880,parse:(e,n)=>{let t=e.parseExpression(n);return k(t)===null?null:["PreIncrement",t]}},{name:"PreDecrement",latexTrigger:["-","-"],kind:"prefix",precedence:880,parse:(e,n)=>{let t=e.parseExpression(n);return k(t)===null?null:["PreDecrement",t]}},{name:"Ring",latexTrigger:["\\circ"],kind:"infix",precedence:265},{name:"StringJoin",latexTrigger:["\\lt","\\gt"],kind:"infix",precedence:780},{name:"Starstar",latexTrigger:["\\star","\\star"],kind:"infix",precedence:780},{name:"PartialDerivative",latexTrigger:["\\partial"],kind:"prefix",parse:e=>{let n=!1,t="Nothing",i="Nothing";for(;!n;)e.skipSpace(),e.match("_")?i=e.parseGroup()??e.parseToken():e.match("^")?t=e.parseGroup()??e.parseToken():n=!0;let r=bn(i);if(r&&(i=["List",...r]),i===null||t===null)return null;let s=e.parseGroup()??"Nothing";if(!G(s)){let o=e.parseArguments()??["Nothing"];s=[s,...o]}return["PartialDerivative",s,i,t]},serialize:(e,n)=>{let t="\\partial",i=p(n,1),r=p(n,2),s=p(n,3);return r!==null&&r!=="Nothing"&&(x(r)==="List"?t+="_{"+e.serialize(["Sequence",..._(r)])+"}":t+="_{"+e.serialize(r)+"}"),s!==null&&s!=="Nothing"&&(t+="^{"+e.serialize(s)+"}"),i!==null&&i!=="Nothing"&&(t+=e.serialize(i)),t},precedence:740},{name:"OverBar",latexTrigger:["\\overline"],parse:xe("OverBar")},{name:"UnderBar",latexTrigger:["\\underline"],parse:xe("UnderBar")},{name:"OverVector",latexTrigger:["\\vec"],parse:xe("OverVector")},{name:"OverTilde",latexTrigger:["\\tilde"],parse:xe("OverTilde")},{name:"OverHat",latexTrigger:["\\hat"],parse:xe("OverHat")},{name:"OverRightArrow",latexTrigger:["\\overrightarrow"],parse:xe("OverRightArrow")},{name:"OverLeftArrow",latexTrigger:["\\overleftarrow"],parse:xe("OverLeftArrow")},{name:"OverRightDoubleArrow",latexTrigger:["\\Overrightarrow"],parse:xe("OverRightDoubleArrow")},{name:"OverLeftHarpoon",latexTrigger:["\\overleftharpoon"],parse:xe("OverLeftHarpoon")},{name:"OverRightHarpoon",latexTrigger:["\\overrightharpoon"],parse:xe("OverRightHarpoon")},{name:"OverLeftRightArrow",latexTrigger:["\\overleftrightarrow"],parse:xe("OverLeftRightArrow")},{name:"OverBrace",latexTrigger:["\\overbrace"],parse:xe("OverBrace")},{name:"OverLineSegment",latexTrigger:["\\overlinesegment"],parse:xe("OverLineSegment")},{name:"OverGroup",latexTrigger:["\\overgroup"],parse:xe("OverGroup")},{latexTrigger:["\\textcolor"],parse:e=>{let n=e.index,t=e.parseStringGroup(),i=e.parseGroup();return t!==null?i!==null?["Annotated",i,{dict:{color:t}}]:"Nothing":(e.index=n,"Nothing")}},{latexTrigger:["\\colorbox"],parse:e=>{let n=e.index,t=e.parseStringGroup(),i=e.parseGroup();return t!==null?i!==null?["Annotated",i,{dict:{backgroundColor:t}}]:"Nothing":(e.index=n,"Nothing")}},{latexTrigger:["\\boxed"],parse:e=>{let n=e.parseGroup();return n!==null?["Annotated",n,{dict:{border:!0}}]:"Nothing"}},{latexTrigger:["\\displaystyle"],parse:Kt("normal")},{latexTrigger:["\\textstyle"],parse:Kt("compact")},{latexTrigger:["\\scriptstyle"],parse:Kt("script")},{latexTrigger:["\\scriptscriptstyle"],parse:Kt("scriptscript")},{latexTrigger:["\\color"],parse:e=>{let n=e.parseStringGroup();if(n!==null){let t=e.parseExpression();if(t!==null&&!G(t))return["Annotated",t,{dict:{color:n}}]}return"Nothing"}},{latexTrigger:["\\tiny"],parse:Fe(1)},{latexTrigger:["\\scriptsize"],parse:Fe(2)},{latexTrigger:["\\footnotesize"],parse:Fe(3)},{latexTrigger:["\\small"],parse:Fe(4)},{latexTrigger:["\\normalsize"],parse:Fe(5)},{latexTrigger:["\\large"],parse:Fe(6)},{latexTrigger:["\\Large"],parse:Fe(7)},{latexTrigger:["\\LARGE"],parse:Fe(8)},{latexTrigger:["\\huge"],parse:Fe(9)},{latexTrigger:["\\Huge"],parse:Fe(10)},{name:"Annotated",serialize:(e,n)=>{let t=e.serialize(p(n,1)),i=ra(p(n,2));if(i==null)return t;i.dict.mathStyle==="normal"?t=I(["{\\displaystyle",t,"}"]):i.dict.mathStyle==="compact"?t=I(["{\\textstyle",t,"}"]):i.dict.mathStyle==="script"?t=I(["{\\scriptstyle",t,"}"]):i.dict.mathStyle==="scriptscript"&&(t=I(["{\\scriptscriptstyle",t,"}"]));let r=i.dict.size;return r!==null&&r>=1&&r<=10&&(t=I(["{",{1:"\\tiny",2:"\\scriptsize",3:"\\footnotesize",4:"\\small",5:"\\normalsize",6:"\\large",7:"\\Large",8:"\\LARGE",9:"\\huge",10:"\\Huge"}[r],t,"}"])),i.dict.fontFamily==="monospace"?t=I(["\\texttt{",t,"}"]):i.dict.fontFamily==="sans-serif"&&(t=I(["\\textsf{",t,"}"])),i.dict.fontWeight==="bold"&&(t=I(["\\textbf{",t,"}"])),i.dict.fontStyle==="italic"?t=I(["\\textit{",t,"}"]):i.dict.fontStyle==="normal"&&(t=I(["\\textup{",t,"}"])),i.dict.color&&(t=I(["\\textcolor{",i.dict.color,"}{",t,"}"])),i.dict.backgroundColor&&(t=I(["\\colorbox{",i.dict.backgroundColor,"}{",t,"}"])),i.dict.border===!0&&(t=I(["\\boxed{",t,"}"])),t}},{latexTrigger:["\\!"],parse:()=>["HorizontalSpacing",-3]},{latexTrigger:["\\ "],parse:()=>["HorizontalSpacing",6]},{latexTrigger:["\\:"],parse:()=>["HorizontalSpacing",4]},{latexTrigger:["\\enskip"],parse:()=>["HorizontalSpacing",9]},{latexTrigger:["\\quad"],parse:()=>["HorizontalSpacing",18]},{latexTrigger:["\\qquad"],parse:()=>["HorizontalSpacing",36]},{latexTrigger:["\\,"],parse:()=>["HorizontalSpacing",3]},{latexTrigger:["\\;"],parse:()=>["HorizontalSpacing",5]},{latexTrigger:["\\enspace"],parse:()=>["HorizontalSpacing",9]},{latexTrigger:["\\hspace"],parse:e=>(e.peek==="*"&&e.nextToken(),e.parseStringGroup(),["HorizontalSpacing",0])},{latexTrigger:["\\hskip"],parse:e=>(Ua(e),["HorizontalSpacing",0])},{latexTrigger:["\\kern"],parse:e=>(Ua(e),["HorizontalSpacing",0])},{latexTrigger:["\\phantom"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\vphantom"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\hphantom"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\placeholder"],parse:e=>(e.parseOptionalGroup(),e.parseGroup()??"Nothing")},{latexTrigger:["\\smash"],parse:e=>(e.parseGroup(),"Nothing")},{latexTrigger:["\\strut"],parse:e=>"Nothing"},{latexTrigger:["\\mathstrut"],parse:e=>"Nothing"},{name:"HorizontalSpacing",serialize:(e,n)=>{if(p(n,2)!==null){let i=q(p(n,2)),r=e.serialize(p(n,1));return i==="bin"?`\\mathbin{${r}}`:i==="op"?`\\mathop{${r}}`:i==="rel"?`\\mathrel{${r}}`:i==="ord"?`\\mathord{${r}}`:i==="open"?`\\mathopen{${r}}`:i==="close"?`\\mathclose{${r}}`:i==="punct"?`\\mathpunct{${r}}`:i==="inner"?`\\mathinner{${r}}`:r}let t=D(p(n,1));return t===null?"":{"-3":"\\!",6:"\\ ",3:"\\,",4:"\\:",5:"\\;",9:"\\enspace",18:"\\quad",36:"\\qquad"}[t]??""}},{latexTrigger:"\\operatorname{count}",parse:"Length"},{latexTrigger:"\\operatorname{random}",parse:"Random"},{latexTrigger:"\\operatorname{shuffle}",parse:"Shuffle"},{latexTrigger:"\\operatorname{repeat}",parse:"Repeat"},{latexTrigger:"\\operatorname{join}",parse:"Join"},{latexTrigger:"\\operatorname{range}",parse:"Range"},{name:"Triangle",latexTrigger:["\\operatorname{triangle}"],kind:"function",serialize:(e,n)=>"\\operatorname{triangle}"+e.wrapArguments(n)},{name:"GeometricVector",latexTrigger:["\\operatorname{vector}"],kind:"function",serialize:(e,n)=>"\\operatorname{vector}"+e.wrapArguments(n)},{name:"Sphere",latexTrigger:["\\operatorname{sphere}"],kind:"function",serialize:(e,n)=>"\\operatorname{sphere}"+e.wrapArguments(n)},{name:"Segment",latexTrigger:["\\operatorname{segment}"],kind:"function",serialize:(e,n)=>"\\operatorname{segment}"+e.wrapArguments(n)}];var Za=[{name:"Rgb",latexTrigger:["\\operatorname{rgb}"],kind:"function",serialize:(e,n)=>"\\operatorname{rgb}"+e.wrapArguments(n)},{name:"Hsv",latexTrigger:["\\operatorname{hsv}"],kind:"function",serialize:(e,n)=>"\\operatorname{hsv}"+e.wrapArguments(n)},{name:"Hsl",latexTrigger:["\\operatorname{hsl}"],kind:"function",serialize:(e,n)=>"\\operatorname{hsl}"+e.wrapArguments(n)},{name:"Oklab",latexTrigger:["\\operatorname{oklab}"],kind:"function",serialize:(e,n)=>"\\operatorname{oklab}"+e.wrapArguments(n)},{name:"Oklch",latexTrigger:["\\operatorname{oklch}"],kind:"function",serialize:(e,n)=>"\\operatorname{oklch}"+e.wrapArguments(n)},{name:"AsRgb",latexTrigger:["\\operatorname{asRgb}"],kind:"function",serialize:(e,n)=>"\\operatorname{asRgb}"+e.wrapArguments(n)},{name:"AsHsv",latexTrigger:["\\operatorname{asHsv}"],kind:"function",serialize:(e,n)=>"\\operatorname{asHsv}"+e.wrapArguments(n)},{name:"AsHsl",latexTrigger:["\\operatorname{asHsl}"],kind:"function",serialize:(e,n)=>"\\operatorname{asHsl}"+e.wrapArguments(n)},{name:"AsOklab",latexTrigger:["\\operatorname{asOklab}"],kind:"function",serialize:(e,n)=>"\\operatorname{asOklab}"+e.wrapArguments(n)},{name:"AsOklch",latexTrigger:["\\operatorname{asOklch}"],kind:"function",serialize:(e,n)=>"\\operatorname{asOklch}"+e.wrapArguments(n)},{name:"ColorDelta",latexTrigger:["\\operatorname{colorDelta}"],kind:"function",serialize:(e,n)=>"\\operatorname{colorDelta}"+e.wrapArguments(n)}];var Qc=[{name:"Mu0",kind:"symbol",latexTrigger:"\\mu_0"},{name:"VacuumPermittivity",kind:"symbol",latexTrigger:"\\varepsilon_0"}];var Kc=[...ma,...ga,...ba,...oa,...va,...hn,...Ma,...wa,...Aa,...Ra,...Pa,...Fa,...ja,...Ha,...Qc,...Za];var ef="\\u{FE0F}",nf="\\u{20E3}",tf="\\u{200D}",rf="\\p{RI}\\p{RI}",sf="(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})",Ya=`(?:\\p{EMod}|${ef}${nf}?|${sf})`,of="(?:(?=\\P{XIDC})(?=[^\\x23\\x2a\\x30-\\x39])\\p{Emoji})",Wa=`(?:${of}${Ya}*|\\p{Emoji}${Ya}+|${rf})`,Xa=`(?:${Wa})(${tf}${Wa})*`,W0=new RegExp(`(?:${Xa})+`,"u"),Qa=new RegExp(`^(?:${Xa})+$`,"u");var J1=new Set([...'!"#$%&(),/;:?@[]\\`|~'.split(""),"\\left","\\bigl","\\mleft"]);var z1=["pt","em","mu","ex","mm","cm","in","bp","sp","dd","cc","pc","nc","nd"].map(e=>[...e]);function eu(e){return e!==void 0&&"value"in e}function ct(e){return e!==void 0&&"operator"in e}function Nn(e,n,t=!0){let i=!t||e.every(s=>s.isCanonical)?e:e.map(s=>s.canonical);if(n){let s=a=>T(a,"Nothing")||a.operator===n||a.operator==="Sequence";if(i.every(a=>!s(a)))return i;let o=[];for(let a of i)T(a,"Nothing")||(h(a)&&(a.operator===n||a.operator==="Sequence")?o.push(...Nn(a.ops,n,t)):o.push(a));return o}if(i.every(s=>!(T(s,"Nothing")||s.operator==="Sequence")))return i;let r=[];for(let s of i)T(s,"Nothing")||(h(s,"Sequence")?r.push(...Nn(s.ops,n,t)):r.push(s));return r}function ff(e,n){if(e===n)return 0;if(e.length===0)return n.length;if(n.length===0)return e.length;let t=Array.from({length:e.length+1},(r,s)=>s),i=new Array(e.length+1);for(let r=1;r<=n.length;r++){i[0]=r;for(let s=1;s<=e.length;s++){let o=e[s-1]===n[r-1]?0:1;i[s]=Math.min(t[s]+1,i[s-1]+1,t[s-1]+o)}[t,i]=[i,t]}return t[e.length]}function yr(e,n){let i=null,r=1/0,s=e.length;for(let o of n){if(Math.abs(s-o.length)>7)continue;let a=ff(e,o);if(a===0)return o;a<=7&&a<r&&(r=a,i=o)}return i}function ei(e,n,t){if(n=Nn(n),!e.strict||n.length===t)return n;let i=[...n.slice(0,t)],r=Math.min(t,n.length);for(;r<t;)i.push(e.error("missing")),r+=1;for(;r<n.length;)i.push(e.error("unexpected-argument",n[r].toString())),r+=1;return i}function rn(e,n,t){return n==null?e.error("missing"):t===void 0?e.error("unexpected-argument",n.toString()):(n=n.canonical,!n.isValid||n.type.matches(t)?n:e.typeError(t,n.type,n))}function xr(e,n,t){if(n.length===t.length&&n.every((r,s)=>r.type.matches(t[s])))return n;let i=[];for(let r=0;r<=t.length-1;r++)i.push(rn(e,n[r],t[r]));for(let r=t.length;r<=n.length-1;r++)i.push(e.error("unexpected-argument",n[r].toString()));return i}function nu(e){let n={},t=bf(e.engine),i=gf(e.engine);if(T(e)&&!n[e.symbol]&&!e.symbol.startsWith("_")){if(!t.includes(e.symbol)){let r=yr(e.symbol,t);r&&(n[e.symbol]=r)}}else if(h(e)&&!n[e.operator]&&!e.operator.startsWith("_")){let r=e.operator;if(!i.includes(r)){let s=yr(r,i);s&&(n[r]=s)}for(let s of e.ops)n={...n,...nu(s)}}return n}function gf(e){let n=[],t=e.context.lexicalScope;for(;t;){for(let i of t.bindings.keys()){let r=t.bindings.get(i);ct(r)&&n.push(i)}t=t.parent}return n}function bf(e){let n=[],t=e.context.lexicalScope;for(;t;){for(let i of t.bindings.keys()){let r=t.bindings.get(i);eu(r)&&n.push(i)}t=t.parent}return n}function Qe(e){let n=nu(e);if(Object.keys(n).length===0)return"";if(Object.keys(n).length===1){let[i,r]=Object.entries(n)[0];return`Unknown symbol "${i}". Did you mean "${r}"?`}let t=[];for(let[i,r]of Object.entries(n))t.push(`- "${i}" -> "${r}"?`);return`Unknown symbols found:
9
9
  ${t.join(`
10
- `)}`}var le=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Ne=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},Mc=function(e){var n=Math.PI/4;if(-n>e||e>n)return Math.cos(e)-1;var t=e*e;return t*(t*(t*(t*(t*(t*(t*(t/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-1/2)},wc=function(e,n){var t=Math.abs(e),i=Math.abs(n);return t<3e3&&i<3e3?Math.sqrt(t*t+i*i):(t<i?(t=i,i=e/n):i=n/e,t*Math.sqrt(1+i*i))},Dn=function(){throw SyntaxError("Invalid Param")};function sr(e,n){var t=Math.abs(e),i=Math.abs(n);return e===0?Math.log(i):n===0?Math.log(t):t<3e3&&i<3e3?Math.log(e*e+n*n)*.5:(e=e/2,n=n/2,.5*Math.log(e*e+n*n)+Math.LN2)}var Ac=function(e,n){var t={re:0,im:0};if(e==null)t.re=t.im=0;else if(n!==void 0)t.re=e,t.im=n;else switch(typeof e){case"object":if("im"in e&&"re"in e)t.re=e.re,t.im=e.im;else if("abs"in e&&"arg"in e){if(!Number.isFinite(e.abs)&&Number.isFinite(e.arg))return $.INFINITY;t.re=e.abs*Math.cos(e.arg),t.im=e.abs*Math.sin(e.arg)}else if("r"in e&&"phi"in e){if(!Number.isFinite(e.r)&&Number.isFinite(e.phi))return $.INFINITY;t.re=e.r*Math.cos(e.phi),t.im=e.r*Math.sin(e.phi)}else e.length===2?(t.re=e[0],t.im=e[1]):Dn();break;case"string":t.im=t.re=0;var i=e.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,s=0;i===null&&Dn();for(var o=0;o<i.length;o++){var a=i[o];a===" "||a===" "||a===`
11
- `||(a==="+"?r++:a==="-"?s++:a==="i"||a==="I"?(r+s===0&&Dn(),i[o+1]!==" "&&!isNaN(Number(i[o+1]))?(t.im+=parseFloat((s%2?"-":"")+i[o+1]),o++):t.im+=parseFloat((s%2?"-":"")+"1"),r=s=0):((r+s===0||isNaN(Number(a)))&&Dn(),i[o+1]==="i"||i[o+1]==="I"?(t.im+=parseFloat((s%2?"-":"")+a),o++):t.re+=parseFloat((s%2?"-":"")+a),r=s=0))}r+s>0&&Dn();break;case"number":t.im=0,t.re=e;break;default:Dn()}return isNaN(t.re)||isNaN(t.im),t},$=class e{constructor(n,t){this.re=0,this.im=0;var i=Ac(n,t);this.re=i.re,this.im=i.im}sign(){var n=this.abs();return new e(this.re/n,this.im/n)}add(n,t){var i=new e(n,t);return this.isInfinite()&&i.isInfinite()?e.NAN:this.isInfinite()||i.isInfinite()?e.INFINITY:new e(this.re+i.re,this.im+i.im)}sub(n,t){var i=new e(n,t);return this.isInfinite()&&i.isInfinite()?e.NAN:this.isInfinite()||i.isInfinite()?e.INFINITY:new e(this.re-i.re,this.im-i.im)}mul(n,t){var i=new e(n,t);return this.isInfinite()&&i.isZero()||this.isZero()&&i.isInfinite()?e.NAN:this.isInfinite()||i.isInfinite()?e.INFINITY:i.im===0&&this.im===0?new e(this.re*i.re,0):new e(this.re*i.re-this.im*i.im,this.re*i.im+this.im*i.re)}div(n,t){var i=new e(n,t);if(this.isZero()&&i.isZero()||this.isInfinite()&&i.isInfinite())return e.NAN;if(this.isInfinite()||i.isZero())return e.INFINITY;if(this.isZero()||i.isInfinite())return e.ZERO;n=this.re,t=this.im;var r=i.re,s=i.im,o,a;return s===0?new e(n/r,t/r):Math.abs(r)<Math.abs(s)?(a=r/s,o=r*a+s,new e((n*a+t)/o,(t*a-n)/o)):(a=s/r,o=s*a+r,new e((n+t*a)/o,(t-n*a)/o))}pow(n,t){var i=new e(n,t);if(n=this.re,t=this.im,i.isZero())return e.ONE;if(i.im===0){if(t===0&&n>0)return new e(Math.pow(n,i.re),0);if(n===0)switch((i.re%4+4)%4){case 0:return new e(Math.pow(t,i.re),0);case 1:return new e(0,Math.pow(t,i.re));case 2:return new e(-Math.pow(t,i.re),0);case 3:return new e(0,-Math.pow(t,i.re))}}if(n===0&&t===0&&i.re>0&&i.im>=0)return e.ZERO;var r=Math.atan2(t,n),s=sr(n,t);return n=Math.exp(i.re*s-i.im*r),t=i.im*s+i.re*r,new e(n*Math.cos(t),n*Math.sin(t))}sqrt(){var n=this.re,t=this.im,i=this.abs(),r,s;if(n>=0){if(t===0)return new e(Math.sqrt(n),0);r=.5*Math.sqrt(2*(i+n))}else r=Math.abs(t)/Math.sqrt(2*(i-n));return n<=0?s=.5*Math.sqrt(2*(i-n)):s=Math.abs(t)/Math.sqrt(2*(i+n)),new e(r,t<0?-s:s)}exp(){var n=Math.exp(this.re);return this.im,new e(n*Math.cos(this.im),n*Math.sin(this.im))}expm1(){var n=this.re,t=this.im;return new e(Math.expm1(n)*Math.cos(t)+Mc(t),Math.exp(n)*Math.sin(t))}log(){var n=this.re,t=this.im;return t===0&&n>0,new e(sr(n,t),Math.atan2(t,n))}abs(){return wc(this.re,this.im)}arg(){return Math.atan2(this.im,this.re)}sin(){var n=this.re,t=this.im;return new e(Math.sin(n)*le(t),Math.cos(n)*Ne(t))}cos(){var n=this.re,t=this.im;return new e(Math.cos(n)*le(t),-Math.sin(n)*Ne(t))}tan(){var n=2*this.re,t=2*this.im,i=Math.cos(n)+le(t);return new e(Math.sin(n)/i,Ne(t)/i)}cot(){var n=2*this.re,t=2*this.im,i=Math.cos(n)-le(t);return new e(-Math.sin(n)/i,Ne(t)/i)}sec(){var n=this.re,t=this.im,i=.5*le(2*t)+.5*Math.cos(2*n);return new e(Math.cos(n)*le(t)/i,Math.sin(n)*Ne(t)/i)}csc(){var n=this.re,t=this.im,i=.5*le(2*t)-.5*Math.cos(2*n);return new e(Math.sin(n)*le(t)/i,-Math.cos(n)*Ne(t)/i)}asin(){var n=this.re,t=this.im,i=new e(t*t-n*n+1,-2*n*t).sqrt(),r=new e(i.re-t,i.im+n).log();return new e(r.im,-r.re)}acos(){var n=this.re,t=this.im,i=new e(t*t-n*n+1,-2*n*t).sqrt(),r=new e(i.re-t,i.im+n).log();return new e(Math.PI/2-r.im,r.re)}atan(){var n=this.re,t=this.im;if(n===0){if(t===1)return new e(0,1/0);if(t===-1)return new e(0,-1/0)}var i=n*n+(1-t)*(1-t),r=new e((1-t*t-n*n)/i,-2*n/i).log();return new e(-.5*r.im,.5*r.re)}acot(){var n=this.re,t=this.im;if(t===0)return new e(Math.atan2(1,n),0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).atan():new e(n!==0?n/0:0,t!==0?-t/0:0).atan()}asec(){var n=this.re,t=this.im;if(n===0&&t===0)return new e(0,1/0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).acos():new e(n!==0?n/0:0,t!==0?-t/0:0).acos()}acsc(){var n=this.re,t=this.im;if(n===0&&t===0)return new e(Math.PI/2,1/0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).asin():new e(n!==0?n/0:0,t!==0?-t/0:0).asin()}sinh(){var n=this.re,t=this.im;return new e(Ne(n)*Math.cos(t),le(n)*Math.sin(t))}cosh(){var n=this.re,t=this.im;return new e(le(n)*Math.cos(t),Ne(n)*Math.sin(t))}tanh(){var n=2*this.re,t=2*this.im,i=le(n)+Math.cos(t);return new e(Ne(n)/i,Math.sin(t)/i)}coth(){var n=2*this.re,t=2*this.im,i=le(n)-Math.cos(t);return new e(Ne(n)/i,-Math.sin(t)/i)}csch(){var n=this.re,t=this.im,i=Math.cos(2*t)-le(2*n);return new e(-2*Ne(n)*Math.cos(t)/i,2*le(n)*Math.sin(t)/i)}sech(){var n=this.re,t=this.im,i=Math.cos(2*t)+le(2*n);return new e(2*le(n)*Math.cos(t)/i,-2*Ne(n)*Math.sin(t)/i)}asinh(){var n=this.im;this.im=-this.re,this.re=n;var t=this.asin();return this.re=-this.im,this.im=n,n=t.re,t.re=-t.im,t.im=n,t}acosh(){var n=this.acos();if(n.im<=0){var t=n.re;n.re=-n.im,n.im=t}else{var t=n.im;n.im=-n.re,n.re=t}return n}atanh(){var n=this.re,t=this.im,i=n>1&&t===0,r=1-n,s=1+n,o=r*r+t*t,a=o!==0?new e((s*r-t*t)/o,(t*r+s*t)/o):new e(n!==-1?n/0:0,t!==0?t/0:0),u=a.re;return a.re=sr(a.re,a.im)/2,a.im=Math.atan2(a.im,u)/2,i&&(a.im=-a.im),a}acoth(){var n=this.re,t=this.im;if(n===0&&t===0)return new e(0,Math.PI/2);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).atanh():new e(n!==0?n/0:0,t!==0?-t/0:0).atanh()}acsch(){var n=this.re,t=this.im;if(t===0)return new e(n!==0?Math.log(n+Math.sqrt(n*n+1)):1/0,0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).asinh():new e(n!==0?n/0:0,t!==0?-t/0:0).asinh()}asech(){var n=this.re,t=this.im;if(this.isZero())return e.INFINITY;var i=n*n+t*t;return i!==0?new e(n/i,-t/i).acosh():new e(n!==0?n/0:0,t!==0?-t/0:0).acosh()}inverse(){if(this.isZero())return e.INFINITY;if(this.isInfinite())return e.ZERO;var n=this.re,t=this.im,i=n*n+t*t;return new e(n/i,-t/i)}conjugate(){return new e(this.re,-this.im)}neg(){return new e(-this.re,-this.im)}ceil(n){return n=Math.pow(10,n||0),new e(Math.ceil(this.re*n)/n,Math.ceil(this.im*n)/n)}floor(n){return n=Math.pow(10,n||0),new e(Math.floor(this.re*n)/n,Math.floor(this.im*n)/n)}round(n){return n=Math.pow(10,n||0),new e(Math.round(this.re*n)/n,Math.round(this.im*n)/n)}equals(n,t){var i=new e(n,t);return Math.abs(i.re-this.re)<=e.EPSILON&&Math.abs(i.im-this.im)<=e.EPSILON}clone(){return new e(this.re,this.im)}toString(){var n=this.re,t=this.im,i="";return this.isNaN()?"NaN":this.isInfinite()?"Infinity":(Math.abs(n)<e.EPSILON&&(n=0),Math.abs(t)<e.EPSILON&&(t=0),t===0?i+n:(n!==0?(i+=n,i+=" ",t<0?(t=-t,i+="-"):i+="+",i+=" "):t<0&&(t=-t,i+="-"),t!==1&&(i+=t),i+"i"))}toVector(){return[this.re,this.im]}valueOf(){return this.im===0?this.re:null}isNaN(){return isNaN(this.re)||isNaN(this.im)}isZero(){return this.im===0&&this.re===0}isFinite(){return isFinite(this.re)&&isFinite(this.im)}isInfinite(){return!(this.isNaN()||this.isFinite())}};$.ZERO=new $(0,0);$.ONE=new $(1,0);$.I=new $(0,1);$.PI=new $(Math.PI,0);$.E=new $(Math.E,0);$.INFINITY=new $(1/0,1/0);$.NAN=new $(NaN,NaN);$.EPSILON=1e-15;function q(e){if(!D(e))return null;let n=e.numericValue;return Math.round(typeof n=="number"?n:n.re)}function va(e){return e?._kind==="number"}function Bc(e){return e?._kind==="symbol"}function st(e,n){return(e?._kind==="function"||e?._kind==="tensor")&&(n===void 0||e.operator===n)}function nn(e){if(st(e,"Interval")){let n=e.op1,t=e.op2,i=!1,r=!1;st(n,"Open")?(i=!0,n=n.op1):st(n,"Closed")&&(n=n.op1),st(t,"Open")?(r=!0,t=t.op1):st(t,"Closed")&&(t=t.op1);let s=n.N(),o=t.N();return!va(s)||!va(o)?void 0:{start:s.re,openStart:i,end:o.re,openEnd:r}}if(Bc(e)){if(e.symbol==="EmptySet")return{start:0,openStart:!0,end:0,openEnd:!0};if(e.symbol==="RealNumbers")return{start:-1/0,openStart:!1,end:1/0,openEnd:!1};if(e.symbol==="NegativeNumbers")return{start:-1/0,openStart:!1,end:0,openEnd:!0};if(e.symbol==="NonPositiveNumbers")return{start:-1/0,openStart:!1,end:0,openEnd:!1};if(e.symbol==="PositiveNumbers")return{start:0,openStart:!0,end:1/0,openEnd:!1};if(e.symbol==="NonNegativeNumbers")return{start:0,openStart:!1,end:1/0,openEnd:!1}}}function Ea(e){let n=Math.sin(e*12.9898)*43758.5453;return n-Math.floor(n)}function Na(e){return e+.6180339887498949}function Ta(e,n,t){return n.every(i=>i.isCanonical)?n:n.map(i=>e.expr(i,{scope:t}))}var ot=50,ly={List:{complexity:8200,signature:"(any*) -> list",type:(e,{engine:n})=>W(`list<${he.widen(...e.map(t=>t.type))}>`),canonical:Vc,lazy:!0,evaluate:(e,{engine:n,materialization:t})=>{if(t)return n._fn("List",ur(e).map(i=>i.evaluate({materialization:t})))},eq:_a,collection:At()},Set:{complexity:8200,signature:"(any*) -> set",type:(e,{engine:n})=>W(`set<${he.widen(...e.map(t=>t.type))}>`),canonical:Jc,eq:(e,n)=>{if(e.operator!==n.operator||!h(e)||!h(n)||e.nops!==n.nops)return!1;let t=i=>n.ops.some(r=>i.isSame(r));return e.ops.every(t)},collection:{...At(),at:void 0,indexWhere:void 0}},Length:{description:"Number of elements in a collection. Returns undefined for non-collections and for infinite collections.",complexity:4e3,signature:"(any) -> integer",type:()=>"integer",evaluate:([e],{engine:n})=>{if(!e.isCollection)return;if(e.isEmptyCollection)return n.Zero;let t=e.count;if(!(t===void 0||!isFinite(t)))return n.number(t)}},Tuple:{description:"A fixed number of heterogeneous elements",complexity:8200,signature:"(any*) -> tuple",type:e=>W(`tuple<${e.map(n=>n.type).join(", ")}>`),canonical:(e,{engine:n})=>n.tuple(...e),eq:_a,collection:{...At(),keys:e=>["first","second","last"]}},KeyValuePair:{description:"A key/value pair",complexity:8200,signature:"(key: string, value: any) -> tuple<string, unknown>",type:([e,n])=>W(`tuple<string, ${n.type}>`),canonical:(e,{engine:n})=>{let[t,i]=rr(n,e,["string","any"]);return!t.isValid||!i.isValid?n._fn("KeyValuePair",[t,i]):n.tuple(t,i)}},Single:{description:"A tuple with a single element",complexity:8200,signature:"(value: any) -> tuple<any>",type:([e])=>W(`tuple<${e.type}>`),canonical:(e,{engine:n})=>n.tuple(...jt(n,e,1))},Pair:{description:"A tuple of two elements",complexity:8200,signature:"(first: any, second: any) -> tuple<any, any>",type:([e,n])=>W(`tuple<${e.type}, ${n.type}>`),canonical:(e,{engine:n})=>n.tuple(...jt(n,e,2))},Triple:{description:"A tuple of three elements",complexity:8200,signature:"(first: any, second: any, third: any) -> tuple<any, any, any>",type:([e,n,t])=>W(`tuple<${e.type}, ${n.type}, ${t.type}>`),canonical:(e,{engine:n})=>n.tuple(...jt(n,e,3))},Range:{complexity:8200,signature:"(number, number?, step: number?) -> indexed_collection<number>",type:e=>e.every(t=>t.isInteger)?W("indexed_collection<integer>"):W("indexed_collection<number>"),canonical:(e,{engine:n})=>e.length===0?null:e.length===1?n._fn("Range",[n.One,e[0].canonical]):e.length===2?n._fn("Range",[e[0].canonical,e[1].canonical]):n._fn("Range",[e[0].canonical,e[1].canonical,e[2].canonical.evaluate()]),eq:(e,n)=>{if(e.operator!==n.operator)return!1;let[t,i,r]=Ye(e),[s,o,a]=Ye(n);return t===s&&i===o&&r===a},collection:{isLazy:e=>!0,count:e=>{let[n,t,i]=Ye(e);return i===0?0:!isFinite(n)||!isFinite(t)?1/0:Math.max(0,Math.floor((t-n)/i)+1)},contains:(e,n)=>{let t=n.re;if(!isFinite(t))return!1;let[i,r,s]=Ye(e);if(s===0)return!1;if(s>0){if(t<i||t>r)return!1}else if(t>i||t<r)return!1;let o=(t-i)/s,a=e.engine.tolerance,u=Math.round(o);return u>=0&&Math.abs(o-u)<a},iterator:e=>{let[n,t,i]=Ye(e),r=i===0?0:Math.max(0,Math.floor((t-n)/i)+1),s=1;return{next:()=>s===r+1?{value:void 0,done:!0}:(s+=1,{value:e.engine.number(n+i*(s-1-1)),done:!1})}},at:(e,n)=>{if(typeof n!="number")return;let[t,i,r]=Ye(e);if(r===0)return;let s=Math.max(0,Math.floor((i-t)/r)+1);if(!(n<1||n>s))return e.engine.number(t+r*(n-1))},indexWhere:void 0,subsetOf:(e,n)=>{if(n.operator==="Range"){let[i,r,s]=Ye(e),[o,a,u]=Ye(n);return i>=o&&r<=a&&s%u===0}if(!n.isCollection)return!1;let t=1;for(let i of n.each()){if(!e.contains(i)||!e.at(t)?.isSame(i))return!1;t++}return!0},eltsgn:e=>{let[n,t,i]=Ye(e);return i===0?"zero":i>0?n<=t?"positive":"negative":n>=t?"positive":"negative"},elttype:e=>{if(!h(e))return"finite_integer";for(let n=1;n<=e.nops;n++)if(!e[`op${n}`].isInteger)return"finite_real";return"finite_integer"}}},Interval:{description:"A set of real numbers between two endpoints. The endpoints may or may not be included.",complexity:8200,lazy:!0,signature:"(number, number) -> set<real>",canonical:([e,n],{engine:t})=>{if(!e||!n)return null;let[i,r]=rr(t,[e.canonical,n.canonical],["number","number"]);return!i.isValid||!r.isValid?null:t._fn("Interval",[i,r])},eq:(e,n)=>{let t=nn(e),i=nn(n);return!t||!i?!1:t.start===i.start&&t.end===i.end&&t.openStart===i.openStart&&t.openEnd===i.openEnd},collection:{count:e=>1/0,iterator:e=>{let n=nn(e);if(!n)return{next:()=>({value:void 0,done:!0})};if(n.start>=n.end)return{next:()=>({value:void 0,done:!0})};let t=e.engine,i=0,r=0;return{next:()=>{let s=Math.pow(2,i);r>=s&&(i++,r=0);let o=(2*r+1)/Math.pow(2,i+1),a=n.start+o*(n.end-n.start);return r++,{value:t.number(a),done:!1}}}},isEmpty:e=>{let n=nn(e);return n?n.openStart&&n.start===n.end||n.openEnd&&n.start===n.end?!0:n.openStart&&n.openEnd?!1:n.start>=n.end:!1},isFinite:e=>!1,contains:(e,n)=>{let t=nn(e);return!t||t.openStart&&n.isLessEqual(t.start)||t.openEnd&&n.isGreaterEqual(t.end)?!1:n.isGreaterEqual(t.start)&&n.isLessEqual(t.end)},eltsgn:e=>{let n=nn(e);if(!n||n.start===n.end)return"unsigned";if(n.start>=0&&!n.openStart)return"non-negative";if(n.end<=0&&!n.openEnd)return"non-positive";if(n.start>0&&n.end>0)return"positive";if(n.start<0&&n.end<0)return"negative"},elttype:e=>{let n=nn(e);return n?isFinite(n.start)&&isFinite(n.end)?"finite_real":"real":"never"}}},Linspace:{complexity:8200,signature:"(start: number, end: number?, count: number?) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=e.op3.re;return isFinite(n)||(n=ot),Math.max(0,Math.floor(n))},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.re,i=e.op2.re,r=e.op3.re;if(isFinite(r)||(r=ot),r=Math.floor(r),!(!isFinite(t)||!isFinite(i))&&!(n<1||n>r))return r===1?e.engine.number(t):e.engine.number(t+(i-t)*(n-1)/(r-1))},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.re,t=e.op2.re,i;isFinite(t)?i=Math.max(0,isFinite(e.op3.re)?e.op3.re:ot):(t=n,n=1,i=ot),i=Math.floor(i);let r=i>1?i-1:1,s=1;return{next:()=>s===i+1?{value:void 0,done:!0}:(s+=1,{value:e.engine.number(n+(t-n)*(s-1-1)/r),done:!1})}},contains:(e,n)=>{if(!n.type.matches("finite_real")||!h(e))return!1;let t=n.re,i=e.op1.re,r=e.op2.re;if(t<i||t>r)return!1;let s=e.op3.re;if(isFinite(s)||(s=ot),s=Math.floor(s),s===0)return!1;if(s===1)return t===i;let o=(r-i)/(s-1),a=(t-i)/o,u=e.engine.tolerance,l=Math.round(a);return l>=0&&l<=s-1&&Math.abs(a-l)<u}}},Contains:{description:"Return True if the collection contains the given element, False otherwise.",complexity:8200,signature:"(collection, element: any) -> boolean",evaluate:([e,n],{engine:t})=>e.contains(n)?t.True:t.False},Count:{description:["Return the number of elements in the collection."],complexity:8200,signature:"(collection) -> integer",evaluate:([e],{engine:n})=>e.isEmptyCollection?n.Zero:n.number(e.count),sgn:([e])=>e.isEmptyCollection?"zero":"positive"},IsEmpty:{description:["Return True if the collection is empty, False otherwise."],complexity:8200,signature:"(collection) -> boolean",evaluate:([e],{engine:n})=>e.isEmptyCollection?n.True:n.False},Map:{description:["Return the collection where each element has been transformed by the mapping function.","Equivalent to `[f(x) for x in xs]`."],complexity:8200,lazy:!0,signature:"(collection, function) -> collection",type:e=>e[0].type,canonical:(e,{engine:n})=>{let t=en(n,e[0]?.canonical,"collection"),i=qe(e[1]);return!t.isValid||!i?null:n._fn("Map",[t,i])},collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},isEmpty:e=>{if(h(e))return e.op1.isEmptyCollection},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=te(e.op2);if(!n)return{next:()=>({value:void 0,done:!0})};let t=e.op1.each();return{next:()=>{for(;;){let{value:i,done:r}=t.next();return r?{value:void 0,done:!0}:{value:n([i])??e.engine.Nothing,done:!1}}}}},at:(e,n)=>{if(!h(e)||!e.isIndexedCollection||typeof n!="number"||!Number.isFinite(n)||n===0)return;let t=e.op1.at(n);if(t)return te(e.op2)?.([t])}}},Filter:{description:["Return the elements of the collection for which the predicate function returns True.","Equivalent to `[x for x in xs if p(x)]`."],complexity:8200,lazy:!0,signature:"(collection, predicate: function) -> collection",type:e=>e[0].type,canonical:(e,{engine:n})=>{let t=en(n,e[0]?.canonical,"collection"),i=qe(e[1]);return!t.isValid||!i?null:n._fn("Filter",[t,i])},collection:{isLazy:e=>!0,count:e=>1/0,contains:(e,n)=>{if(!h(e)||!e.contains(n))return!1;let t=te(e.op2);return pe(t([n]))==="True"},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=te(e.op2);if(!n)return{next:()=>({value:void 0,done:!0})};let t=e.op1.each(),i=0,r=e.engine.iterationLimit;return{next:()=>{for(;;){let{value:s,done:o}=t.next();if(i+=1,i>r)throw new Tn({cause:"iteration-limit-exceeded",message:`Iteration limit of ${r} exceeded while evaluating Filter()`});if(o)return{value:void 0,done:!0};let a=n([s]);if(!a)throw new Error(`Invalid filter predicate. ${Ze(e.op2)}`);if(pe(a)==="True")return{value:s,done:!1};if(pe(a)!=="False")throw new Error(`Filter predicate must return "True" or "False". ${Ze(e.op2)}`)}}}},at:(e,n)=>{if(typeof n!="number"||!Number.isFinite(n)||n===0||!h(e))return;let t=te(e.op2);if(!t)return;if(n<0){if(!e.op1.isFiniteCollection)return;let r=Array.from(e.each()),s=r.length+n+1;return s<1||s>r.length?void 0:r[s-1]}let i=0;for(let r of e.op1.each()){let s=pe(t([r]));if(s==="True"){if(i+=1,i===n)return r}else if(s!=="False")throw new Error(`Filter predicate must return "True" or "False". ${Ze(e.op2)}`)}}}},Reduce:{complexity:8200,lazy:!0,signature:"(collection, function, initial:value?) -> value",canonical:(e,{engine:n})=>{let t=en(n,e[0],"collection"),i=qe(e[1]);if(!t.isValid||!i)return null;let r=e[2]?.canonical;return r?.isValid?n._fn("Reduce",[t,i,r]):n._fn("Reduce",[t,i])},type:e=>W(Li(e[1].type.type)??"unknown"),evaluate:([e,n,t],{engine:i})=>{if(!e.isFiniteCollection)return;if(t??=i.Nothing,t.type.matches("real")&&e.type.matches(i.type("collection<real>"))){let s=i._compile(n);return s.calling!=="lambda"||!s.run?void 0:Bi((function*(){let o=t.re,a=!0;for(let u of e.each())a?o=u.re:o=s.run(o,u.re),a=!1,yield;return i.expr(o)})(),i._timeRemaining)}let r=te(n);return Bi(Ma(e,(s,o)=>r([s,o])??i.Nothing,t),i._timeRemaining)}},Join:{description:["Join the elements of some collections into a flat collection."],complexity:8200,signature:"(collection*) -> collection",type:qc,collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=0;for(let t of e.ops){let i=t.count;if(i===void 0)return;if(!Number.isFinite(i))return 1/0;n+=i}return n},contains:(e,n)=>h(e)?e.ops.some(t=>t.contains(n)):!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.ops.map(i=>i.each()),t=0;return{next:()=>{for(;;){let{value:i,done:r}=n[t].next();if(!r)return{value:i,done:!1};if(t+=1,t>=n.length)return{value:void 0,done:!0}}}}}}},At:{description:["Access an element of an indexed collection.","If the index is negative, it is counted from the end.","Multiple indices can be provided to access nested collections (e.g., matrices).","If the index is a finite collection of booleans, returns the elements where the mask is True.","If the index is a finite collection of integers, returns the elements at those indices."],complexity:8200,signature:"(value: indexed_collection, index: (number|string|indexed_collection)+) -> unknown",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??we(e.type.type)??"any",evaluate:(e,{engine:n})=>{let t=e[0],i=1;for(;e[i];){let s=t.baseDefinition?.collection?.at;if(!s)return;let o=e[i],a=fe(o)?o.string:void 0;if(a!==void 0){t=s(t,a)??n.Nothing,i+=1;continue}if(o.isCollection&&o.isFiniteCollection){let l=Array.from(o.each()),c=l.every(m=>{let d=pe(m);return d==="True"||d==="False"}),f=[];if(c)l.forEach((m,d)=>{if(pe(m)!=="True")return;let b=s(t,d+1);b!==void 0&&f.push(b)});else for(let m of l){let d=m.re;if(!Number.isInteger(d))return;let b=s(t,d);b!==void 0&&f.push(b)}t=n._fn("List",f),i+=1;continue}let u=o.re;if(!Number.isInteger(u))return;t=s(t,u)??n.Nothing,i+=1}return t}},Take:{description:["Return `n` elements from a collection."],complexity:8200,signature:"(xs: indexed_collection, count: number) -> indexed_collection",type:([e])=>`list<${J(we(e.type.type)??"any")}>`,evaluate:(e,{engine:n,materialization:t})=>{if(!t)return;let i=n._fn("Take",e),r=Array.from(i.each());return n._fn("List",r)},collection:{isLazy:e=>!0,count:Sa,isEmpty:e=>{if(!h(e))return;let[n,t]=e.ops;if(n.isEmptyCollection)return!0;if(n.isFiniteCollection===!1)return!1;let i=Math.max(0,q(t)??0),r=n.count;if(r!==void 0)return Number.isFinite(i)?Math.min(r,i)===0:!1},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:zc,at:(e,n)=>{if(typeof n!="number"||n===0||!h(e))return;let t=Math.max(0,q(e.op2)??0);if(t===0)return;if(n>0)return n>t?void 0:e.op1.at(n);let i=Sa(e);if(!(i===void 0||i===0)&&!(n<-i))return e.op1.at(i+n)}}},Drop:{description:["Return the collection without the first n elements."],complexity:8200,signature:"(xs: indexed_collection, count: number) -> indexed_collection",type:([e])=>`list<${J(we(e.type.type)??"any")}>`,collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let[n,t]=e.ops,i=n.count;if(i===void 0)return;if(!Number.isFinite(i))return 1/0;if(n.isEmptyCollection)return 0;let r=q(t)??0;return r>=i?0:Math.max(0,i-r)},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let[n,t]=e.ops,i=q(t)??0;if(i<=0)return n.each();let r=i+1;return{next:()=>{let s=e.op1.at(r++);return s===void 0?{value:void 0,done:!0}:{value:s,done:!1}}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let[t,i]=e.ops,r=q(i)??0;if(!(r<=0))return t.at(n+r)}}},First:{complexity:8200,signature:"(any) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.isCollection?e.at(1)??n.Nothing:n.error(["incompatible-type","'collection'",e.type.toString()])},Second:{complexity:8200,signature:"(any) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.isCollection?e.at(2)??n.Nothing:n.error(["incompatible-type","'collection'",e.type.toString()])},Third:{complexity:8200,signature:"(any) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.isCollection?e.at(3)??n.Nothing:n.error(["incompatible-type","'collection'",e.type.toString()])},Last:{complexity:8200,signature:"(collection) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.at(-1)??n.Nothing},Rest:{description:["Return the collection without the first element.","If the collection has only one element, return an empty collection."],complexity:8200,signature:"(indexed_collection) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=e.op1.count;if(n!==void 0)return Math.max(0,n-1)},isEmpty:e=>{if(!h(e))return;if(e.op1.isEmptyCollection)return!0;let n=e.op1.count;if(n!==void 0)return n<=1},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:e=>h(e)?{next:()=>{let n=1,t=e.op1.at(n>0?n+1:n);return t?(n+=1,{value:t,done:!1}):{value:void 0,done:!0}}}:{next:()=>({value:void 0,done:!0})},at:(e,n)=>{if(typeof n=="number"&&h(e))return e.op1.at(n>0?n+1:n)}}},Most:{complexity:8200,description:["Return the collection without the last element.","If the collection has only one element, return an empty collection."],signature:"(indexed_collection) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=e.op1.count;if(n!==void 0)return Math.max(0,n-1)},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},isEmpty:e=>{if(!h(e))return;let n=e.op1.count;if(n!==void 0)return n<=1},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.count;if(n===void 0||n<=1)return{next:()=>({value:void 0,done:!0})};let t=1,i=n-1;return{next:()=>t>i?{value:void 0,done:!0}:{value:e.op1.at(t++),done:!1}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t!==void 0&&(n<1&&(n=t+1+n),!(n<1||n>t-1)))return e.op1.at(n)}}},Slice:{description:["Return a range of elements from an indexed collection.","If the index is negative, it is counted from the end."],complexity:8200,signature:"(value: indexed_collection, start: number, end: number) -> list",type:([e])=>W(`list<${J(we(e.type.type)??"any")}>`),collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=q(e.op2)??1,t=e.op1.count;if(t===void 0)return;let i=q(e.op3)??t;return n<1?Math.max(0,i+n-1):Math.max(0,Math.min(i,t)-n+1)},isFinite:e=>!0,at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t===void 0)return;let i=q(e.op2)??1;if(i<1&&(i=t+1+i),i<1&&(i=1),i>t)return;let r=q(e.op3)??t;r<1&&(r=t+1+r),r<1&&(r=1),r>t&&(r=t)},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=q(e.op2)??1,t=e.op1.count;if(t===void 0)return{next:()=>({value:void 0,done:!0})};if(n<1&&(n=t+1+n),n<1&&(n=1),n>t)return{next:()=>({value:void 0,done:!0})};let i=q(e.op3)??t;i<1&&(i=t+1+i),i<1&&(i=1),i>t&&(i=t);let r=n,s=i;return{next:()=>{if(r>s)return{value:void 0,done:!0};let o=e.op1.at(r);return r+=1,{value:o,done:!1}}}}}},Reverse:{complexity:8200,signature:"(indexed_collection) -> indexed_collection",type:([e])=>e.type,collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},isEmpty:e=>{if(h(e))return e.op1.isEmptyCollection},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=-1;return{next:()=>{if(n===0)return{value:void 0,done:!0};let t=e.op1.at(n);return n-=1,{value:t,done:!1}}}},at:(e,n)=>{if(typeof n=="number"&&h(e))return e.op1.at(-n)}}},RotateLeft:{description:"Rotate the elements of the collection to the left by n positions.",complexity:8200,signature:"(indexed_collection, integer?) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},isEmpty:e=>{if(h(e))return e.op1.isEmptyCollection},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.count;if(n===void 0||n<=0)return{next:()=>({value:void 0,done:!0})};let t=q(e.op2)??1;t=(t%n+n)%n;let i=1,r=n;return{next:()=>{if(i===r+1)return{value:void 0,done:!0};i+=1;let s=e.op1.at((i-1-1+t)%n+1);return s===void 0?{value:void 0,done:!0}:{value:s,done:!1}}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t===void 0||t<=0||(n<1&&(n=t+1+n),n<1||n>t))return;let i=q(e.op2)??1;return i=(i%t+t)%t,e.op1.at((n-1+i)%t+1)}}},RotateRight:{description:"Rotate the elements of the collection to the right by n positions.",complexity:8200,signature:"(indexed_collection, integer?) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.count;if(n===void 0||n<=0)return{next:()=>({value:void 0,done:!0})};let t=q(e.op2)??1;t=(t%n+n)%n;let i=1;return{next:()=>{if(i===n+1)return{value:void 0,done:!0};i+=1;let r=(i-1-1+(n-t))%n+1,s=e.op1.at(r);return s===void 0?{value:void 0,done:!0}:{value:s,done:!1}}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t===void 0||t<=0||(n<1&&(n=t+1+n),n<1||n>t))return;let i=q(e.op2)??1;i=(i%t+t)%t;let r=(n-1+(t-i))%t+1;return e.op1.at(r)}}},IndexOf:{description:"Return the 1-based index of the first occurrence of value in collection, or 0 if not found.",complexity:8200,signature:"(collection, any) -> integer",evaluate:([e,n],{engine:t})=>{let i=e.indexWhere(r=>r.isSame(n))??void 0;return t.number(i??0)}},IndexWhere:{description:"Return the 1-based index of the first element satisfying the predicate, or 0 if not found.",complexity:8200,signature:"(collection, function) -> integer",evaluate:([e,n],{engine:t})=>{let i=te(n);if(!i)return t.Zero;let r=e.indexWhere(s=>{let o=pe(i([s]));if(o==="True")return!0;if(o==="False")return!1;throw new Error(`Filter predicate must return "True" or "False". ${Ze(n)}`)})??void 0;return t.number(r??0)}},Find:{description:"Return the first element of the collection satisfying the predicate, or Nothing if none found.",complexity:8200,signature:"(collection, function) -> any",type:e=>e[0].type,evaluate:([e,n],{engine:t})=>{let i=te(n);if(!i)return t.Nothing;for(let r of e.each()){let s=pe(i([r]));if(s!=="False"){if(s==="True")return r;throw new Error(`Filter predicate must return "True" or "False". ${Ze(n)}`)}}return t.Nothing}},CountIf:{description:"Return the number of elements in the collection satisfying the predicate.",complexity:8200,signature:"(collection, function) -> integer",evaluate:([e,n],{engine:t})=>{let i=te(n);if(!i)return t.Zero;let r=0;for(let s of e.each()){let o=pe(i([s]));if(o!=="False")if(o==="True")r++;else throw new Error(`Filter predicate must return "True" or "False". ${Ze(n)}`)}return t.number(r)}},Position:{description:"Return a list of indexes of elements in the collection satisfying the predicate.",complexity:8200,signature:"(collection, function) -> list<integer>",type:()=>"list<integer>",evaluate:([e,n],{engine:t})=>{let i=te(n);if(!i)return t.function("List",[]);let r=[],s=1;for(let o of e.each()){let a=pe(i([o]));if(a==="True"&&r.push(t.number(s)),a!=="False")throw new Error(`Filter predicate must return "True" or "False". ${Ze(n)}`);s++}return t.function("List",r)}},Ordering:{description:"Return the indexes that would sort the collection.",complexity:8200,signature:"(indexed_collection, function?) -> list<integer>",evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return t.function("List",[]);let i=ka(e,n);return i?t.function("List",i):t.function("List",[])}},Sort:{description:"Return the elements of the collection sorted according to the given comparison function.",complexity:8200,signature:"(indexed_collection, function?) -> indexed_collection",type:e=>e[0].type,evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return t.function(e.operator,[]);let i=ka(e,n);if(i)return t.function(e.operator,i.map(r=>e.at(r)))}},Shuffle:{description:"Randomize the order of the elements in the collection. With an optional `seed` argument, the shuffle is deterministic.",complexity:8200,signature:"(indexed_collection, real?) -> indexed_collection",type:e=>e[0].type,evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return;let i=Array.from(e.each()),r=n?.re;if(r!==void 0&&!Number.isNaN(r)){let s=r;for(let o=i.length-1;o>0;o--){let a=Math.floor(Ea(s)*(o+1));[i[o],i[a]]=[i[a],i[o]],s=Na(s)}}else for(let s=i.length-1;s>0;s--){let o=Math.floor(Math.random()*(s+1));[i[s],i[o]]=[i[o],i[s]]}return t.function(e.operator,i)}},Tabulate:{description:"Create a collection by applying a function to each index in the specified dimensions.",complexity:8200,lazy:!0,signature:"(function, integer, integer?) -> collection",canonical:(e,{engine:n})=>{let t=qe(e[0]);return t?e[2]?n._fn("Tabulate",[t,en(n,e[1]?.canonical,"integer"),en(n,e[2]?.canonical,"integer")]):n._fn("Tabulate",[t,en(n,e[1]?.canonical,"integer")]):null},evaluate:(e,{engine:n})=>{let t=te(e[0]);if(!t)return;if(e.length===1)return n._fn("List",[]);let i=e.slice(1).map(s=>q(s));if(i.some(s=>s===null||s<=0))return;if(i.length===1)return n._fn("List",Array.from({length:i[0]??0},(s,o)=>t([n.number(o+1)])??n.Nothing));let r=(s,o,a=0)=>{if(a===s.length){let l=o.map(c=>n.number(c));return t(l)??n.Nothing}let u=["List"];for(let l=1;l<=s[a];l++)o[a]=l,u.push(r(s,o,a+1));return u};return n.expr(r(i,Array(i.length).fill(0)))}},Tally:{description:"Return a tuple with the unique elements of the collection and their respective counts.",complexity:8200,signature:"(collection) -> tuple<list, list<integer>>",type:([e],{engine:n})=>{let t=e.type.type;return t==="string"?W("tuple<list<string>, list<integer>>"):W(`tuple<list<${J(we(t)??"any")}>, list<integer>>`)},evaluate:(e,{engine:n})=>{if(!e[0].isFiniteCollection)return;let[t,i]=Ia(e[0]);return n.tuple(n.function("List",t),n.function("List",i))}},Unique:{description:"Return a list of the unique elements of the collection.",complexity:8200,signature:"(collection) -> list",type:([e])=>`list<${J(we(e.type.type)??"any")}>`,evaluate:(e,{engine:n})=>{if(!e[0].isFiniteCollection)return;let[t,i]=Ia(e[0]);return n.function("List",t)}},Partition:{wikidata:"Q381060",complexity:8200,signature:"(collection, integer | function) -> list",type:([e])=>`list<${J(we(e.type.type)??"any")}>`,evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return;let i=q(n);if(i!==null&&i>0){let a=Array.from(e.each()),u=[],l=Math.ceil(a.length/i);for(let c=0;c<i;c++){let f=a.slice(c*l,(c+1)*l);u.push(t.function("List",f))}return t.function("List",u)}let r=te(n);if(!r)return;let s=[],o=[];for(let a of e.each()){let u=pe(r([a]));if(u==="True")s.push(a);else if(u==="False")o.push(a);else throw new Error(`Partition predicate must return "True" or "False". ${Ze(n)}`)}return t.function("List",[t.function("List",s),t.function("List",o)])}},Chunk:{description:"Split the collection into `k` nearly equal-sized chunks.",complexity:8200,signature:"(collection, integer) -> list<list>",evaluate:([e,n],{engine:t})=>{let i=q(n);if(!e.isFiniteCollection||i===null||i<=0)return;let r=Array.from(e.each()),s=[],o=Math.ceil(r.length/i);for(let a=0;a<i;a++){let u=r.slice(a*o,(a+1)*o);s.push(t.function("List",u))}return t.function("List",s)}},GroupBy:{description:["Partition the collection into a dictionary of lists based on the key returned by the function."],complexity:8200,signature:"(collection, function) -> dictionary<list>",evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return;let i=te(n);if(!i)return;let r={};for(let s of e.each()){let o=i([s])??t.Nothing,a=(k(o)?o.symbol:void 0)??(fe(o)?o.string:void 0)??o.toString();a in r||(r[a]=[]),r[a].push(s)}return t.function("Dictionary",Object.entries(r).map(([s,o])=>t._fn("Tuple",[t.string(s),t.function("List",o)])))}},Zip:{description:"Combine multiple collections element-wise into a list of tuples. The result has the length of the shortest input.",complexity:8200,signature:"(indexed_collection+) -> list",collection:{isLazy:e=>!0,count:ar,isFinite:e=>{if(h(e))return e.ops.every(n=>n.isFiniteCollection)},isEmpty:e=>{if(h(e))return e.nops===0||e.ops.every(n=>n.isEmptyCollection)},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=ar(e);if(n===void 0||n<=0)return{next:()=>({value:void 0,done:!0})};let t=1;return{next:()=>{if(t===n+1)return{value:void 0,done:!0};t+=1;let i=e.ops.map(r=>r.at(t-1));return i.some(r=>r===void 0)?{value:void 0,done:!0}:{value:e.engine.tuple(...i),done:!1}}}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=ar(e);if(t===void 0||n<1||n>t)return;let i=e.ops.map(r=>r.at(n));if(!i.some(r=>r===void 0))return e.engine.tuple(...i)}}},Iterate:{description:"Produce an infinite sequence by repeatedly applying a function to the previous value, starting with an initial value.",complexity:8200,signature:"((index: integer, acc:any) -> any, initial: any?) -> list",canonical:([e,n],{engine:t})=>{let i=qe(e);if(!i)return null;let r=n?.canonical;return r?t._fn("Iterate",[i,r]):t._fn("Iterate",[i])},collection:{isLazy:e=>!0,count:()=>1/0,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=te(e.op1);if(!n)return{next:()=>({value:void 0,done:!0})};let t=e.op2??e.engine.Nothing,i=0;return{next:()=>(i+=1,t=n([e.engine.number(i),t])??e.engine.Nothing,{value:t,done:!1})}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=te(e.op1);if(!t)return;let i=e.op2??e.engine.Nothing;for(let r=1;r<n;r++)i=t([e.engine.number(r),i])??e.engine.Nothing;return i}}},Repeat:{description:"Produce a sequence by repeating a single value. With 1 argument, returns an infinite sequence; with 2 arguments (value, count), returns a finite list of `count` copies.",complexity:8200,signature:"(value: any, count: integer?) -> list",evaluate:(e,{engine:n})=>{if(e.length!==2)return;let t=q(e[1]);if(t===null)return;let i=Math.max(0,t);if(!(i>n.maxCollectionSize))return n._fn("List",Array(i).fill(e[0]))},collection:{isLazy:e=>h(e)&&e.ops?.length===1,count:e=>{if(h(e)){if(e.ops?.length===2){let n=q(e.op2);return n!==null?Math.max(0,n):void 0}return 1/0}},isEmpty:e=>{if(h(e)){if(e.ops?.length===2){let n=q(e.op2);return n!==null?n<=0:void 0}return!1}},isFinite:e=>h(e)&&e.ops?.length===2,contains:(e,n)=>{if(!h(e))return!1;if(e.ops?.length===2){let t=q(e.op2);if(t!==null&&t<=0)return!1}return e.op1.isSame(n)},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};if(e.ops?.length===2){let n=q(e.op2);if(n===null)return{next:()=>({value:void 0,done:!0})};let t=Math.max(0,n),i=0;return{next:()=>i++<t?{value:e.op1,done:!1}:{value:void 0,done:!0}}}return{next:()=>({value:e.op1,done:!1})}},at:(e,n)=>{if(h(e)&&typeof n=="number"){if(e.ops?.length===2){let t=q(e.op2),i=t!==null?Math.max(0,t):0;if(n<1||n>i)return}else if(n<1)return;return e.op1}}}},Cycle:{description:"Produce an infinite sequence by cycling through the elements of a finite collection.",complexity:8200,signature:"(list) -> list",collection:{isLazy:e=>!0,count:()=>1/0,isEmpty:e=>e.isEmptyCollection,isFinite:e=>!e.isEmptyCollection,contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=1,t=e.op1.count;return t===void 0||t===0?{next:()=>({value:void 0,done:!0})}:{next:()=>{let i=(n-1-1)%t+1,r=e.op1.at(i);return r===void 0?{value:void 0,done:!0}:(n+=1,{value:r,done:!1})}}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=e.op1.count;if(t===void 0||t===0)return;let i=(n-1)%t+1;return e.op1.at(i)}}},Fill:{description:"Produce a 2D list (matrix) by applying a function to each pair of row and column indexes.",complexity:8200,signature:"(function, tuple) -> list",collection:{isLazy:e=>!0,count:e=>!h(e)||!h(e.op2)?void 0:e.op2.ops.map(t=>q(t)??0)[0]??0,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=te(e.op1);if(!n)return{next:()=>({value:void 0,done:!0})};if(!h(e.op2))return{next:()=>({value:void 0,done:!0})};let t=e.op2.ops.map(a=>q(a)??0),i=t[0]??0,r=t[1]??0,s=i,o=1;return{next:()=>{if(o===s+1)return{value:void 0,done:!0};o+=1;let a=[];for(let u=1;u<=r;u++)a.push(n([e.engine.number(o-1),e.engine.number(u)])??e.engine.Nothing);return{value:e.engine.function("List",a),done:!1}}}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=te(e.op1);if(!t||!h(e.op2))return;let i=e.op2.ops.map(u=>q(u)??0),r=i[0]??0,s=i[1]??0;if(n>r*s)return;let o=Math.ceil(n/s),a=(n-1)%s+1;return t([e.engine.number(o),e.engine.number(a)])??e.engine.Nothing}}},ListFrom:{description:"Create a list from the elements of a collection.",complexity:8200,signature:"(value*) -> list",type:e=>{if(e.length===0)return"list";let n="unknown";for(let t of e){if(t.isCollection&&!t.isFiniteCollection)return"list";n=xe(n,we(t.type.type)??n)}return W(`list<${J(n)}>`)},evaluate:(e,{engine:n})=>{let t=[];for(let i of e)if(!i.isCollection)t.push(i);else{if(!i.isFiniteCollection)return;t.push(...Array.from(i.each()))}return n.function("List",t)}},SetFrom:{description:"Create a set from the elements of a collection.",complexity:8200,signature:"(value*) -> set",type:e=>{if(e.length===0)return"set";let n="unknown";for(let t of e){if(t.isCollection&&!t.isFiniteCollection)return"set";n=xe(n,we(t.type.type)??n)}return W(`set<${J(n)}>`)},evaluate:(e,{engine:n})=>{let t=[];for(let i of e)if(i.isCollection)t.push(i);else{if(!i.isFiniteCollection)return;t.push(...Array.from(i.each()))}return n.function("Set",t)}},TupleFrom:{description:"Create a tuple from the elements of a collection.",complexity:8200,signature:"(value*) -> tuple",evaluate:(e,{engine:n})=>{let t=[];for(let i of e)if(i.isCollection)t.push(i);else{if(!i.isFiniteCollection)return;t.push(...Array.from(i.each()))}return n.tuple(...t)}},DictionaryFrom:{description:"Create a dictionary from the elements of a collection of (key, value) pairs.",complexity:8200,signature:"(collection) -> dictionary",evaluate:([e],{engine:n})=>{if(!e.isCollection)return;if(h(e,"Record"))return n.function("Dictionary",[...e.ops]);let t=[];for(let i of e.each()){if(!h(i)||i.nops!==2)throw new Error(`Expected a collection of pairs, got ${i.type}`);let r=i.op1,s=i.op2;if(!fe(r))throw new Error(`Expected a string key, got ${r.type}`);t.push(n.tuple(r,s))}return n.function("Dictionary",t)}},RecordFrom:{description:"Create a record from the elements of a collection of (key, value) pairs.",complexity:8200,signature:"(collection) -> record",evaluate:([e],{engine:n})=>{if(!e.isCollection)return;if(h(e,"Dictionary"))return n.function("Record",[...e.ops]);let t=[];for(let i of e.each()){if(!h(i)||i.nops!==2)throw new Error(`Expected a collection of pairs, got ${i.type}`);let r=i.op1,s=i.op2;if(!fe(r))throw new Error(`Expected a string key, got ${r.type}`);t.push(n.tuple(r,s))}return n.function("Record",t)}}};function Ye(e){if(!h(e))return[1,0,0];if(e.nops===0)return[1,0,0];let n=e.op1.re;if(!isFinite(n)&&!n&&(n=1),e.nops===1)return[1,n,1];let t=e.op2.re;if(!isFinite(t)&&!t&&(t=1),e.nops===2)return[n,t,t>=n?1:-1];let i=e.op3.re;return!isFinite(i)&&!i&&(i=1),[n,t,i]}function Vc(e,{engine:n}){let t=e[0];if(e.length===1&&h(t,"Matrix")){let[i,r,s]=t.ops;if(!r||fe(r)&&r.string==="..")return s?n._fn("Matrix",[i,n.string("[]"),s]):n._fn("Matrix",[i,r])}return e=e.map(i=>h(i,"Delimiter")?h(i.op1,"Sequence")?n._fn("List",Ta(n,i.op1.ops)):n._fn("List",[i.op1?.canonical??n.Nothing]):i.canonical),n._fn("List",e)}function Jc(e,{engine:n}){let t=[],i=r=>t.some(s=>s.isSame(r));for(let r of e)i(r)||t.push(r);return n._fn("Set",t)}function Ia(e){let n=[],t=[],i=r=>{for(let s=0;s<n.length;s++)if(n[s].isSame(r))return s;return-1};for(let r of e.each()){let s=i(r);s>=0?t[s]++:(n.push(r),t.push(1))}return[n,t]}function*Ma(e,n,t){let i=t;for(let r of e.each()){let s=n(i,r);if(s===null)return;yield i,i=s}return i}function qc(e){return e.some(n=>n.type.matches("record"))?"record":e.some(n=>n.type.matches("dictionary"))?"dictionary":e.some(n=>n.type.matches("set"))?"set":"list"}function _a(e,n){return e.operator!==n.operator||!h(e)||!h(n)||e.nops!==n.nops?!1:e.ops.every((t,i)=>t.isSame(n.ops[i]))}function ka(e,n=void 0){let t=n?te(n):void 0,i=t?(o,a)=>{let u=t([o,a]);return u?.isNegative?-1:u?.isSame(0)?0:1}:(o,a)=>o.isLess(a)?-1:o.isEqual(a)?0:1,r=e.count;if(r===void 0||!Number.isFinite(r)||r<1)return;let s=Array.from({length:r},(o,a)=>a+1);return s.sort((o,a)=>{let u=e.at(o),l=e.at(a);return i(u,l)}),s}function ur(e){if(e.length===0)return[];let n=[];for(let t of e)pe(t)!=="Nothing"&&(h(t,"Sequence")?n.push(...ur([...t.ops])):fe(t)?n.push(t):t.isCollection?n.push(...ur([...t.each()])):n.push(t));return n}function zc(e){if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=Math.max(0,q(e.op2)??0);if(n===0)return{next:()=>({value:void 0,done:!0})};let t=1,i=0;return{next:()=>{if(i>=Math.abs(n))return{value:void 0,done:!0};let r=e.op1.at(t);return r?(t+=1,i+=1,{value:r,done:!1}):{value:void 0,done:!0}}}}function Sa(e){if(!h(e))return;let[n,t]=e.ops,i=n.count;if(i===void 0)return;let r=Math.max(0,q(t)??0);return Number.isFinite(r)?Math.min(i,r):1/0}function ar(e){if(!h(e))return;let n=e.ops.map(t=>t.count);if(!n.some(t=>t===void 0))return n.some(t=>!Number.isFinite(t))?1/0:n.length===0?0:Math.min(...n)}function wa(e){e?.operator,h(e);let n=1,t=n+Ai,i,r=!0,s=e,o=s.op1;i=k(o)?o.symbol:void 0,n=Math.floor(s.op2.re),isNaN(n)&&(n=1),Number.isFinite(n)||(r=!1);let a=s.op3;return(k(a)?a.symbol:void 0)==="Nothing"||a.isInfinity?r=!1:(isNaN(a.re)||(t=Math.floor(a.re??t)),Number.isFinite(t)||(r=!1)),!r&&Number.isFinite(n)&&(t=n+Ai),{index:i,lower:n,upper:t,isFinite:r}}var g=class e{static compile(n,t,i=0){if(n===void 0)return"";if(!n.isValid)throw new Error(`Cannot compile invalid expression: "${n.toString()}"`);if(k(n)){let r=n.symbol,s=t.operators?.(r);return s!==void 0?`(a,b) => a ${s[0]} b`:t.var?.(r)??r}if(D(n)){if(n.im!==0){if(!t.complex)throw new Error("Complex numbers are not supported by this target");return t.complex(n.re,n.im)}return t.number(n.re)}if(fe(n))return t.string(n.string);if(!h(n))throw new Error(`Cannot compile expression: "${n.toString()}"`);return e.compileExpr(n.engine,n.operator,n.ops,i,t)}static compileExpr(n,t,i,r,s){if(t==="Error")throw new Error("Error");if(t==="Sequence")return i.length===0?"":`(${i.map(u=>e.compile(u,s,r)).join(", ")})`;if(t==="Sum"||t==="Product"){let u=s.functions?.(t);return typeof u=="function"?u(i,l=>e.compile(l,s),s):typeof u=="string"?`${u}(${i.map(l=>e.compile(l,s)).join(", ")})`:e.compileLoop(t,i,s)}let o=s.operators?.(t);if(o!==void 0&&!i.some(l=>e.isComplexValued(l))){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o[0]))return`${o[0]}(${i.map(c=>e.compile(c,s)).join(", ")})`;if(i.every(c=>!c.isCollection)){if(Ji(t)&&i.length>2){let f=[];for(let m=0;m<i.length-1;m++)f.push(e.compileExpr(n,t,[i[m],i[m+1]],o[1],s));return`(${f.join(") && (")})`}let c;return i.length===1?c=`${o[0]}${e.compile(i[0],s,o[1])}`:c=i.map(f=>e.compile(f,s,o[1])).join(` ${o[0]} `),o[1]<r?`(${c})`:c}}if(t==="Function"){let u=s.functions?.(t);if(typeof u=="function")return u(i,c=>e.compile(c,s),s);let l=i.slice(1).map(c=>k(c)?c.symbol:"_");return`((${l.join(", ")}) => ${e.compile(i[0].canonical,{...s,var:c=>l.includes(c)?c:s.var(c)})})`}if(t==="Declare"){let u=k(i[0])?i[0].symbol:"_";return s.declare?s.declare(u):`let ${u}`}if(t==="Assign")return`${k(i[0])?i[0].symbol:"_"} = ${e.compile(i[1],s)}`;if(t==="Return")return`return ${e.compile(i[0],s)}`;if(t==="Break")return"break";if(t==="Continue")return"continue";if(t==="Loop"){let u=s.functions?.(t);return typeof u=="function"?u(i,l=>e.compile(l,s),s):e.compileForLoop(i,s)}if(t==="If"){if(i.length!==3)throw new Error("If: wrong number of arguments");let u=s.functions?.(t);return u?typeof u=="function"?u(i,l=>e.compile(l,s),s):`${u}(${i.map(l=>e.compile(l,s)).join(", ")})`:`((${e.compile(i[0],s)}) ? (${e.compile(i[1],s)}) : (${e.compile(i[2],s)}))`}if(t==="Which"){if(i.length<2||i.length%2!==0)throw new Error("Which: expected even number of arguments (condition/value pairs)");let u=s.functions?.(t);if(u)return typeof u=="function"?u(i,c=>e.compile(c,s),s):`${u}(${i.map(c=>e.compile(c,s)).join(", ")})`;let l=c=>{if(c>=i.length)return"NaN";let f=i[c],m=i[c+1];return k(f,"True")?`(${e.compile(m,s)})`:`((${e.compile(f,s)}) ? (${e.compile(m,s)}) : ${l(c+2)})`};return l(0)}if(t==="When"){if(i.length!==2)throw new Error("When: expected exactly 2 arguments (expr, cond)");let u=s.functions?.(t);if(u)return typeof u=="function"?u(i,f=>e.compile(f,s),s):`${u}(${i.map(f=>e.compile(f,s)).join(", ")})`;if(k(i[1],"True"))return`(${e.compile(i[0],s)})`;if(k(i[1],"False"))return"NaN";let l=e.compile(i[0],s);return`((${e.compile(i[1],s)}) ? (${l}) : NaN)`}if(t==="Block")return e.compileBlock(i,s);let a=s.functions?.(t);if(!a)throw new Error(`Unknown operator \`${t}\``);if(typeof a=="function"){let u=n.lookupDefinition(t);if(rt(u)&&u.operator.broadcastable&&i.length===1&&Oi(i[0])){let l=e.tempVar();return`(${e.compile(i[0],s)}).map((${l}) => ${a([i[0].engine.expr(l)],c=>e.compile(c,s),s)})`}return a(i,l=>e.compile(l,s),s)}return`${a}(${i.map(u=>e.compile(u,s)).join(", ")})`}static compileBlock(n,t){let i=[];for(let a of n)if(h(a,"Declare")){let u=a.ops[0];k(u)&&i.push(u.symbol)}if(n.length===1&&i.length===0)return e.compile(n[0],t);let r={};if(t.declare&&t.language){let a=t.language==="wgsl";for(let u of i)for(let l of n)if(h(l,"Assign")&&k(l.ops[0],u)){let c=l.ops[1];e.isComplexValued(c)?r[u]=a?"vec2f":"vec2":e.isIntegerValued(c)&&(r[u]=a?"i32":"int");break}}let s={...t,var:a=>i.includes(a)?a:t.var(a)},o=n.filter(a=>!k(a,"Nothing")).map(a=>h(a,"Declare")&&k(a.ops[0])&&t.declare?t.declare(a.ops[0].symbol,r[a.ops[0].symbol]):e.compile(a,s)).filter(a=>a!=="");return o.length===0?"":t.block?t.block(o):(o[o.length-1]=`return ${o[o.length-1]}`,`(() => {${t.ws(`
10
+ `)}`}var ce=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},Te=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},yf=function(e){var n=Math.PI/4;if(-n>e||e>n)return Math.cos(e)-1;var t=e*e;return t*(t*(t*(t*(t*(t*(t*(t/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-1/2)},xf=function(e,n){var t=Math.abs(e),i=Math.abs(n);return t<3e3&&i<3e3?Math.sqrt(t*t+i*i):(t<i?(t=i,i=e/n):i=n/e,t*Math.sqrt(1+i*i))},Ln=function(){throw SyntaxError("Invalid Param")};function vr(e,n){var t=Math.abs(e),i=Math.abs(n);return e===0?Math.log(i):n===0?Math.log(t):t<3e3&&i<3e3?Math.log(e*e+n*n)*.5:(e=e/2,n=n/2,.5*Math.log(e*e+n*n)+Math.LN2)}var vf=function(e,n){var t={re:0,im:0};if(e==null)t.re=t.im=0;else if(n!==void 0)t.re=e,t.im=n;else switch(typeof e){case"object":if("im"in e&&"re"in e)t.re=e.re,t.im=e.im;else if("abs"in e&&"arg"in e){if(!Number.isFinite(e.abs)&&Number.isFinite(e.arg))return C.INFINITY;t.re=e.abs*Math.cos(e.arg),t.im=e.abs*Math.sin(e.arg)}else if("r"in e&&"phi"in e){if(!Number.isFinite(e.r)&&Number.isFinite(e.phi))return C.INFINITY;t.re=e.r*Math.cos(e.phi),t.im=e.r*Math.sin(e.phi)}else e.length===2?(t.re=e[0],t.im=e[1]):Ln();break;case"string":t.im=t.re=0;var i=e.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,s=0;i===null&&Ln();for(var o=0;o<i.length;o++){var a=i[o];a===" "||a===" "||a===`
11
+ `||(a==="+"?r++:a==="-"?s++:a==="i"||a==="I"?(r+s===0&&Ln(),i[o+1]!==" "&&!isNaN(Number(i[o+1]))?(t.im+=parseFloat((s%2?"-":"")+i[o+1]),o++):t.im+=parseFloat((s%2?"-":"")+"1"),r=s=0):((r+s===0||isNaN(Number(a)))&&Ln(),i[o+1]==="i"||i[o+1]==="I"?(t.im+=parseFloat((s%2?"-":"")+a),o++):t.re+=parseFloat((s%2?"-":"")+a),r=s=0))}r+s>0&&Ln();break;case"number":t.im=0,t.re=e;break;default:Ln()}return isNaN(t.re)||isNaN(t.im),t},C=class e{constructor(n,t){this.re=0,this.im=0;var i=vf(n,t);this.re=i.re,this.im=i.im}sign(){var n=this.abs();return new e(this.re/n,this.im/n)}add(n,t){var i=new e(n,t);return this.isInfinite()&&i.isInfinite()?e.NAN:this.isInfinite()||i.isInfinite()?e.INFINITY:new e(this.re+i.re,this.im+i.im)}sub(n,t){var i=new e(n,t);return this.isInfinite()&&i.isInfinite()?e.NAN:this.isInfinite()||i.isInfinite()?e.INFINITY:new e(this.re-i.re,this.im-i.im)}mul(n,t){var i=new e(n,t);return this.isInfinite()&&i.isZero()||this.isZero()&&i.isInfinite()?e.NAN:this.isInfinite()||i.isInfinite()?e.INFINITY:i.im===0&&this.im===0?new e(this.re*i.re,0):new e(this.re*i.re-this.im*i.im,this.re*i.im+this.im*i.re)}div(n,t){var i=new e(n,t);if(this.isZero()&&i.isZero()||this.isInfinite()&&i.isInfinite())return e.NAN;if(this.isInfinite()||i.isZero())return e.INFINITY;if(this.isZero()||i.isInfinite())return e.ZERO;n=this.re,t=this.im;var r=i.re,s=i.im,o,a;return s===0?new e(n/r,t/r):Math.abs(r)<Math.abs(s)?(a=r/s,o=r*a+s,new e((n*a+t)/o,(t*a-n)/o)):(a=s/r,o=s*a+r,new e((n+t*a)/o,(t-n*a)/o))}pow(n,t){var i=new e(n,t);if(n=this.re,t=this.im,i.isZero())return e.ONE;if(i.im===0){if(t===0&&n>0)return new e(Math.pow(n,i.re),0);if(n===0)switch((i.re%4+4)%4){case 0:return new e(Math.pow(t,i.re),0);case 1:return new e(0,Math.pow(t,i.re));case 2:return new e(-Math.pow(t,i.re),0);case 3:return new e(0,-Math.pow(t,i.re))}}if(n===0&&t===0&&i.re>0&&i.im>=0)return e.ZERO;var r=Math.atan2(t,n),s=vr(n,t);return n=Math.exp(i.re*s-i.im*r),t=i.im*s+i.re*r,new e(n*Math.cos(t),n*Math.sin(t))}sqrt(){var n=this.re,t=this.im,i=this.abs(),r,s;if(n>=0){if(t===0)return new e(Math.sqrt(n),0);r=.5*Math.sqrt(2*(i+n))}else r=Math.abs(t)/Math.sqrt(2*(i-n));return n<=0?s=.5*Math.sqrt(2*(i-n)):s=Math.abs(t)/Math.sqrt(2*(i+n)),new e(r,t<0?-s:s)}exp(){var n=Math.exp(this.re);return this.im,new e(n*Math.cos(this.im),n*Math.sin(this.im))}expm1(){var n=this.re,t=this.im;return new e(Math.expm1(n)*Math.cos(t)+yf(t),Math.exp(n)*Math.sin(t))}log(){var n=this.re,t=this.im;return t===0&&n>0,new e(vr(n,t),Math.atan2(t,n))}abs(){return xf(this.re,this.im)}arg(){return Math.atan2(this.im,this.re)}sin(){var n=this.re,t=this.im;return new e(Math.sin(n)*ce(t),Math.cos(n)*Te(t))}cos(){var n=this.re,t=this.im;return new e(Math.cos(n)*ce(t),-Math.sin(n)*Te(t))}tan(){var n=2*this.re,t=2*this.im,i=Math.cos(n)+ce(t);return new e(Math.sin(n)/i,Te(t)/i)}cot(){var n=2*this.re,t=2*this.im,i=Math.cos(n)-ce(t);return new e(-Math.sin(n)/i,Te(t)/i)}sec(){var n=this.re,t=this.im,i=.5*ce(2*t)+.5*Math.cos(2*n);return new e(Math.cos(n)*ce(t)/i,Math.sin(n)*Te(t)/i)}csc(){var n=this.re,t=this.im,i=.5*ce(2*t)-.5*Math.cos(2*n);return new e(Math.sin(n)*ce(t)/i,-Math.cos(n)*Te(t)/i)}asin(){var n=this.re,t=this.im,i=new e(t*t-n*n+1,-2*n*t).sqrt(),r=new e(i.re-t,i.im+n).log();return new e(r.im,-r.re)}acos(){var n=this.re,t=this.im,i=new e(t*t-n*n+1,-2*n*t).sqrt(),r=new e(i.re-t,i.im+n).log();return new e(Math.PI/2-r.im,r.re)}atan(){var n=this.re,t=this.im;if(n===0){if(t===1)return new e(0,1/0);if(t===-1)return new e(0,-1/0)}var i=n*n+(1-t)*(1-t),r=new e((1-t*t-n*n)/i,-2*n/i).log();return new e(-.5*r.im,.5*r.re)}acot(){var n=this.re,t=this.im;if(t===0)return new e(Math.atan2(1,n),0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).atan():new e(n!==0?n/0:0,t!==0?-t/0:0).atan()}asec(){var n=this.re,t=this.im;if(n===0&&t===0)return new e(0,1/0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).acos():new e(n!==0?n/0:0,t!==0?-t/0:0).acos()}acsc(){var n=this.re,t=this.im;if(n===0&&t===0)return new e(Math.PI/2,1/0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).asin():new e(n!==0?n/0:0,t!==0?-t/0:0).asin()}sinh(){var n=this.re,t=this.im;return new e(Te(n)*Math.cos(t),ce(n)*Math.sin(t))}cosh(){var n=this.re,t=this.im;return new e(ce(n)*Math.cos(t),Te(n)*Math.sin(t))}tanh(){var n=2*this.re,t=2*this.im,i=ce(n)+Math.cos(t);return new e(Te(n)/i,Math.sin(t)/i)}coth(){var n=2*this.re,t=2*this.im,i=ce(n)-Math.cos(t);return new e(Te(n)/i,-Math.sin(t)/i)}csch(){var n=this.re,t=this.im,i=Math.cos(2*t)-ce(2*n);return new e(-2*Te(n)*Math.cos(t)/i,2*ce(n)*Math.sin(t)/i)}sech(){var n=this.re,t=this.im,i=Math.cos(2*t)+ce(2*n);return new e(2*ce(n)*Math.cos(t)/i,-2*Te(n)*Math.sin(t)/i)}asinh(){var n=this.im;this.im=-this.re,this.re=n;var t=this.asin();return this.re=-this.im,this.im=n,n=t.re,t.re=-t.im,t.im=n,t}acosh(){var n=this.acos();if(n.im<=0){var t=n.re;n.re=-n.im,n.im=t}else{var t=n.im;n.im=-n.re,n.re=t}return n}atanh(){var n=this.re,t=this.im,i=n>1&&t===0,r=1-n,s=1+n,o=r*r+t*t,a=o!==0?new e((s*r-t*t)/o,(t*r+s*t)/o):new e(n!==-1?n/0:0,t!==0?t/0:0),u=a.re;return a.re=vr(a.re,a.im)/2,a.im=Math.atan2(a.im,u)/2,i&&(a.im=-a.im),a}acoth(){var n=this.re,t=this.im;if(n===0&&t===0)return new e(0,Math.PI/2);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).atanh():new e(n!==0?n/0:0,t!==0?-t/0:0).atanh()}acsch(){var n=this.re,t=this.im;if(t===0)return new e(n!==0?Math.log(n+Math.sqrt(n*n+1)):1/0,0);var i=n*n+t*t;return i!==0?new e(n/i,-t/i).asinh():new e(n!==0?n/0:0,t!==0?-t/0:0).asinh()}asech(){var n=this.re,t=this.im;if(this.isZero())return e.INFINITY;var i=n*n+t*t;return i!==0?new e(n/i,-t/i).acosh():new e(n!==0?n/0:0,t!==0?-t/0:0).acosh()}inverse(){if(this.isZero())return e.INFINITY;if(this.isInfinite())return e.ZERO;var n=this.re,t=this.im,i=n*n+t*t;return new e(n/i,-t/i)}conjugate(){return new e(this.re,-this.im)}neg(){return new e(-this.re,-this.im)}ceil(n){return n=Math.pow(10,n||0),new e(Math.ceil(this.re*n)/n,Math.ceil(this.im*n)/n)}floor(n){return n=Math.pow(10,n||0),new e(Math.floor(this.re*n)/n,Math.floor(this.im*n)/n)}round(n){return n=Math.pow(10,n||0),new e(Math.round(this.re*n)/n,Math.round(this.im*n)/n)}equals(n,t){var i=new e(n,t);return Math.abs(i.re-this.re)<=e.EPSILON&&Math.abs(i.im-this.im)<=e.EPSILON}clone(){return new e(this.re,this.im)}toString(){var n=this.re,t=this.im,i="";return this.isNaN()?"NaN":this.isInfinite()?"Infinity":(Math.abs(n)<e.EPSILON&&(n=0),Math.abs(t)<e.EPSILON&&(t=0),t===0?i+n:(n!==0?(i+=n,i+=" ",t<0?(t=-t,i+="-"):i+="+",i+=" "):t<0&&(t=-t,i+="-"),t!==1&&(i+=t),i+"i"))}toVector(){return[this.re,this.im]}valueOf(){return this.im===0?this.re:null}isNaN(){return isNaN(this.re)||isNaN(this.im)}isZero(){return this.im===0&&this.re===0}isFinite(){return isFinite(this.re)&&isFinite(this.im)}isInfinite(){return!(this.isNaN()||this.isFinite())}};C.ZERO=new C(0,0);C.ONE=new C(1,0);C.I=new C(0,1);C.PI=new C(Math.PI,0);C.E=new C(Math.E,0);C.INFINITY=new C(1/0,1/0);C.NAN=new C(NaN,NaN);C.EPSILON=1e-15;function we(e){if(e==null)return null;if(typeof e=="number")return Number.isInteger(e)&&e>=-Me&&e<=Me?e:null;if(!R(e))return null;let n=e.numericValue;if(typeof n=="number")return Number.isInteger(n)&&n>=-Me&&n<=Me?n:null;if(n.im!==0)return null;let t=n.re;return Number.isInteger(t)&&t>=-Me&&t<=Me?Number(t):null}function z(e){if(!R(e))return null;let n=e.numericValue;return Math.round(typeof n=="number"?n:n.re)}function wf(e,n,t,i){return e.filter(r=>{let o=t.subs({[n]:r}).evaluate();return K(o)==="True"})}function Nr(e,n){if(e.operator!=="Element")return{status:"error",reason:"expected-element-expression"};if(!h(e))return{status:"error",reason:"expected-element-expression"};let t=T(e.op1)?e.op1.symbol:void 0;if(!t)return{status:"error",reason:"expected-index-variable"};let i=e.op2;if(!i)return{status:"error",reason:"expected-domain"};let r=e.op3,s=e.nops>=3&&r&&K(r)!=="Nothing"?r:null,o=u=>{if(s){let l=wf(u,t,s,n);return{status:"success",variable:t,values:l}}return{status:"success",variable:t,values:u}};if(i.operator==="Set"||i.operator==="List"){let u=h(i)?i.ops:void 0;if(u&&u.length<=1e3){if(i.operator==="List"&&u.length===2){let l=we(u[0]),c=we(u[1]);if(l!==null&&c!==null){let f=c-l+1;if(f>0&&f<=1e3){let d=[];for(let m=l;m<=c;m++)d.push(n.number(m));return o(d)}if(f>1e3)return{status:"non-enumerable",variable:t,domain:i,reason:"domain-too-large"}}}return o([...u])}return u&&u.length>1e3?{status:"non-enumerable",variable:t,domain:i,reason:"domain-too-large"}:{status:"error",reason:"empty-domain"}}if(h(i,"Range")){let u=we(i.op1),l=we(i.op2),c=i.ops.length>=3?we(i.op3):1;if(u!==null&&l!==null&&c!==null&&c!==0){let f=Math.floor((l-u)/c)+1;if(f>0&&f<=1e3){let d=[];for(let m=u;c>0?m<=l:m>=l;m+=c)d.push(n.number(m));return o(d)}if(f>1e3)return{status:"non-enumerable",variable:t,domain:i,reason:"domain-too-large"}}return{status:"non-enumerable",variable:t,domain:i,reason:"non-integer-bounds"}}if(h(i,"Interval")){let u=i.op1,l=i.op2,c=!1,f=!1;h(u,"Open")?(c=!0,u=u.op1):h(u,"Closed")&&(u=u.op1),h(l,"Open")?(f=!0,l=l.op1):h(l,"Closed")&&(l=l.op1);let d=we(u),m=we(l);if(d!==null&&m!==null){c&&(d+=1),f&&(m-=1);let g=m-d+1;if(g>0&&g<=1e3){let v=[];for(let N=d;N<=m;N++)v.push(n.number(N));return o(v)}if(g>1e3)return{status:"non-enumerable",variable:t,domain:i,reason:"domain-too-large"}}return{status:"non-enumerable",variable:t,domain:i,reason:"non-integer-bounds"}}let a=K(i);if(a){if(["Integers","NonNegativeIntegers","PositiveIntegers","NegativeIntegers","Rationals","Reals","PositiveReals","NonNegativeReals","NegativeReals","NonPositiveReals","ExtendedReals","Complexes","ImaginaryNumbers","Numbers","ExtendedComplexes","AlgebraicNumbers","TranscendentalNumbers"].includes(a))return{status:"non-enumerable",variable:t,domain:i,reason:"infinite-domain"};let l=i.value;if(l&&l.operator==="Set"&&h(l)){let c=l.ops;if(c&&c.length<=1e3)return o([...c]);if(c&&c.length>1e3)return{status:"non-enumerable",variable:t,domain:i,reason:"domain-too-large"}}return{status:"non-enumerable",variable:t,domain:i,reason:"unknown-domain"}}return{status:"non-enumerable",variable:t,domain:i,reason:"unrecognized-domain-type"}}function iu(e){return e?._kind==="number"}function Af(e){return e?._kind==="symbol"}function ft(e,n){return(e?._kind==="function"||e?._kind==="tensor")&&(n===void 0||e.operator===n)}function sn(e){if(ft(e,"Interval")){let n=e.op1,t=e.op2,i=!1,r=!1;ft(n,"Open")?(i=!0,n=n.op1):ft(n,"Closed")&&(n=n.op1),ft(t,"Open")?(r=!0,t=t.op1):ft(t,"Closed")&&(t=t.op1);let s=n.N(),o=t.N();return!iu(s)||!iu(o)?void 0:{start:s.re,openStart:i,end:o.re,openEnd:r}}if(Af(e)){if(e.symbol==="EmptySet")return{start:0,openStart:!0,end:0,openEnd:!0};if(e.symbol==="RealNumbers")return{start:-1/0,openStart:!1,end:1/0,openEnd:!1};if(e.symbol==="NegativeNumbers")return{start:-1/0,openStart:!1,end:0,openEnd:!0};if(e.symbol==="NonPositiveNumbers")return{start:-1/0,openStart:!1,end:0,openEnd:!1};if(e.symbol==="PositiveNumbers")return{start:0,openStart:!0,end:1/0,openEnd:!1};if(e.symbol==="NonNegativeNumbers")return{start:0,openStart:!1,end:1/0,openEnd:!1}}}function ru(e,n){return!((e.openStart?n<=e.start:n<e.start)||(e.openEnd?n>=e.end:n>e.end))}function su(e){let n=Math.sin(e*12.9898)*43758.5453;return n-Math.floor(n)}function ou(e){return e+.6180339887498949}function au(e,n,t){return n.every(i=>i.isCanonical)?n:n.map(i=>e.expr(i,{scope:t}))}function ve(e){if(typeof e=="string")return Ao(e)?e:"error";switch(e.kind){case"union":return cu(e);case"intersection":return Cf(e);case"negation":return $f(e);case"collection":case"indexed_collection":return Rf(e.kind,e);case"list":return Df(e);case"set":return Pf(e);case"tuple":return Ff(e);case"record":return Of(e);case"dictionary":return Lf(e);case"signature":return Bf(e);case"value":return e;case"reference":return e;default:throw new Error(`Unknown type kind: ${e}`)}}function me(e){return typeof e!="object"||Object.isFrozen(e)||Object.prototype.hasOwnProperty.call(e,"toString")||Object.defineProperty(e,"toString",{value:()=>V(e)}),e}function lu(e){let n=[],t=new Set;for(let i of e){let r=ve(i),s=typeof r=="string"?r:V(r);t.has(s)||(t.add(s),n.push(r))}return n}function $f(e){let n=ve(e.type);return n==="nothing"?"any":n==="any"?"nothing":me({kind:"negation",type:n})}function cu(e){let n=lu(e.types);if(n.length===0)return"never";if(n.some(i=>i==="error"))return"error";if(n.length===1)return me(n[0]);let t=[];for(let i of n)if(!t.some(r=>w(i,r))){for(let r=t.length-1;r>=0;r--)w(t[r],i)&&t.splice(r,1);t.push(i)}return t.length===1?me(t[0]):me({kind:"union",types:t})}function fu(e,n){if(w(e,n))return e;if(w(n,e))return n;if(typeof e=="object"&&e.kind==="union")return uu(e.types,n);if(typeof n=="object"&&n.kind==="union")return uu(n.types,e);if(typeof e=="string"&&typeof n=="string"){let t=Lo(e,n);return t.length===0?"nothing":t.length===1?t[0]:{kind:"union",types:t}}return"nothing"}function uu(e,n){let t=e.map(i=>fu(i,n)).filter(i=>i!=="nothing");return t.length===0?"nothing":t.length===1?t[0]:cu({kind:"union",types:t})}function Cf(e){let n=lu(e.types);if(n.length===0)return"nothing";if(n.some(i=>i==="error"))return"error";let t=n[0];for(let i=1;i<n.length;i++)if(t=fu(t,n[i]),t==="nothing")return"nothing";return me(t)}function Rf(e,n){let t=ve(n.elements);return t==="error"?"error":t==="nothing"?me({kind:e,elements:"nothing"}):t==="any"?e:me({...n,elements:t})}function Df(e){let n=ve(e.elements);if(n==="error")return"error";if(n==="nothing")return me({kind:"list",elements:"nothing"});if(n==="any")return"list";let t=e.dimensions;return t&&(t=t.filter(i=>i>=1||i===-1),t.length===0)?"nothing":me({...e,dimensions:t,elements:n})}function Pf(e){let n=ve(e.elements);return n==="error"?"error":n==="nothing"?me({kind:"set",elements:"nothing"}):n==="any"?"set":me({...e,elements:n})}function Ff(e){let n=e.elements.map(t=>({...t,type:ve(t.type)}));return n.length===0?"nothing":n.some(t=>t.type==="error")?"error":(n=n.filter(t=>t.type!=="nothing"),me({...e,elements:n}))}function Of(e){let n={};for(let[t,i]of Object.entries(e.elements))n[t]=ve(i);return Object.values(n).some(t=>t==="error")?"error":(n=Object.fromEntries(Object.entries(n).filter(([t,i])=>i!=="nothing")),Object.keys(n).length===0?"record":me({...e,elements:n}))}function Lf(e){let n=ve(e.values);return n==="error"||n==="nothing"?"error":n==="any"||n==="unknown"?"any":me({kind:"dictionary",values:n})}function Bf(e){let n=e.args?.map(s=>({...s,type:ve(s.type)})),t=e.optArgs?.map(s=>({...s,type:ve(s.type)})),i=e.variadicArg?{...e.variadicArg,type:ve(e.variadicArg.type)}:void 0,r=ve(e.result);return n?.some(s=>s.type==="error")||t?.some(s=>s.type==="error")||i?.type==="error"||r==="error"?"error":(t=t?.filter(s=>s.type!=="nothing"),n?.length===0&&(t=void 0),t?.length===0&&(t=void 0),i?.type==="nothing"&&(i=void 0),me({...e,args:n,optArgs:t,variadicArg:i,variadicMin:i?e.variadicMin:void 0,result:r}))}function Vf(e,n){return ve({kind:"intersection",types:[e,n]})}function ii(e,n){let t=e.type;if(t.matches(n))return!0;if(Vf(t.type,n)==="nothing"||R(e))return!1}var pt=50,mt=Vt(),Xx={List:{complexity:8200,signature:"(any*) -> list",type:(e,{engine:n})=>U(`list<${pe.widen(...e.map(t=>t.type))}>`),canonical:qf,lazy:!0,evaluate:(e,{engine:n,materialization:t})=>{if(t)return n._fn("List",Ir(e).map(i=>i.evaluate({materialization:t})))},eq:mu,collection:Vt()},Set:{complexity:8200,signature:"(any*) -> set",type:(e,{engine:n})=>Oe(e)!==null?U("set"):U(`set<${pe.widen(...e.map(t=>t.type))}>`),canonical:Jf,lazy:!0,evaluate:(e,{engine:n,numericApproximation:t,materialization:i})=>{let r=Oe(e);if(r!==null){let s=Tn(r);return s===void 0||s.length>Qi?void 0:n.function("Set",s)}return n.function("Set",e.map(s=>s.evaluate({numericApproximation:t,materialization:i})))},eq:(e,n)=>{if(e.operator!==n.operator||!h(e)||!h(n)||e.nops!==n.nops)return!1;let t=i=>n.ops.some(r=>i.isSame(r));return e.ops.every(t)},collection:{...mt,at:void 0,indexWhere:void 0,isLazy:e=>h(e)&&Oe(e.ops)!==null,count:e=>{if(!h(e))return 0;let n=Oe(e.ops);return n===null?e.nops:Tn(n)?.length},isEmpty:e=>{if(!h(e))return!0;let n=Oe(e.ops);if(n===null)return e.nops===0;let t=Tn(n);return t===void 0?void 0:t.length===0},isFinite:e=>{if(!h(e))return!0;let n=Oe(e.ops);if(n===null||Tn(n)!==void 0||n.domain?.isFiniteCollection===!0)return!0},iterator:e=>{if(!h(e))return mt.iterator(e);let n=Oe(e.ops);if(n===null)return mt.iterator(e);let t=Tn(n);if(t===void 0)return;let i=0;return{next:()=>i>=t.length?{value:void 0,done:!0}:{value:t[i++],done:!1}}},contains:(e,n)=>{if(!h(e))return;let t=Oe(e.ops);return t!==null?zf(t,n):gu(e.ops,n)},elttype:e=>{if(!h(e))return mt.elttype(e);let n=Oe(e.ops);if(n===null)return mt.elttype(e);let t=Tn(n);return t===void 0||t.length===0?"unknown":ge(...t.map(i=>i.type.type))}}},Length:{description:"Number of elements in a collection. Returns undefined for non-collections and for infinite collections.",complexity:4e3,signature:"(any) -> integer",type:()=>"integer",evaluate:([e],{engine:n})=>{if(!e.isCollection)return;if(e.isEmptyCollection)return n.Zero;let t=e.count;if(!(t===void 0||!isFinite(t)))return n.number(t)}},Tuple:{description:"A fixed number of heterogeneous elements",complexity:8200,signature:"(any*) -> tuple",type:e=>U(`tuple<${e.map(n=>n.type).join(", ")}>`),canonical:(e,{engine:n})=>n.tuple(...e),eq:mu,collection:{...Vt(),keys:e=>["first","second","last"]}},KeyValuePair:{description:"A key/value pair",complexity:8200,signature:"(key: string, value: any) -> tuple<string, unknown>",type:([e,n])=>U(`tuple<string, ${n.type}>`),canonical:(e,{engine:n})=>{let[t,i]=xr(n,e,["string","any"]);return!t.isValid||!i.isValid?n._fn("KeyValuePair",[t,i]):n.tuple(t,i)}},Single:{description:"A tuple with a single element",complexity:8200,signature:"(value: any) -> tuple<any>",type:([e])=>U(`tuple<${e.type}>`),canonical:(e,{engine:n})=>n.tuple(...ei(n,e,1))},Pair:{description:"A tuple of two elements",complexity:8200,signature:"(first: any, second: any) -> tuple<any, any>",type:([e,n])=>U(`tuple<${e.type}, ${n.type}>`),canonical:(e,{engine:n})=>n.tuple(...ei(n,e,2))},Triple:{description:"A tuple of three elements",complexity:8200,signature:"(first: any, second: any, third: any) -> tuple<any, any, any>",type:([e,n,t])=>U(`tuple<${e.type}, ${n.type}, ${t.type}>`),canonical:(e,{engine:n})=>n.tuple(...ei(n,e,3))},Range:{complexity:8200,signature:"(number, number?, step: number?) -> indexed_collection<number>",type:e=>e.every(t=>t.isInteger)?U("indexed_collection<integer>"):U("indexed_collection<number>"),canonical:(e,{engine:n})=>e.length===0?null:e.length===1?n._fn("Range",[n.One,e[0].canonical]):e.length===2?n._fn("Range",[e[0].canonical,e[1].canonical]):n._fn("Range",[e[0].canonical,e[1].canonical,e[2].canonical.evaluate()]),eq:(e,n)=>{if(e.operator!==n.operator)return!1;let[t,i,r]=Ke(e),[s,o,a]=Ke(n);return t===s&&i===o&&r===a},collection:{isLazy:e=>!0,count:e=>{let[n,t,i]=Ke(e);return i===0?0:!isFinite(n)||!isFinite(t)?1/0:Math.max(0,Math.floor((t-n)/i)+1)},contains:(e,n)=>{let t=n.re;if(Number.isNaN(t))return ii(n,"number")===!1?!1:void 0;if(n.im!==0||!isFinite(t))return!1;if(h(e)&&e.ops.some(l=>Number.isNaN(l.re)))return;let[i,r,s]=Ke(e);if(s===0)return!1;if(s>0){if(t<i||t>r)return!1}else if(t>i||t<r)return!1;let o=(t-i)/s,a=e.engine.tolerance,u=Math.round(o);return u>=0&&Math.abs(o-u)<a},iterator:e=>{let[n,t,i]=Ke(e),r=i===0?0:Math.max(0,Math.floor((t-n)/i)+1),s=1;return{next:()=>s===r+1?{value:void 0,done:!0}:(s+=1,{value:e.engine.number(n+i*(s-1-1)),done:!1})}},at:(e,n)=>{if(typeof n!="number")return;let[t,i,r]=Ke(e);if(r===0)return;let s=Math.max(0,Math.floor((i-t)/r)+1);if(!(n<1||n>s))return e.engine.number(t+r*(n-1))},indexWhere:void 0,subsetOf:(e,n)=>{if(n.operator==="Range"){let[i,r,s]=Ke(e),[o,a,u]=Ke(n);return i>=o&&r<=a&&s%u===0}if(!n.isCollection)return!1;let t=1;for(let i of n.each()){if(!e.contains(i)||!e.at(t)?.isSame(i))return!1;t++}return!0},eltsgn:e=>{let[n,t,i]=Ke(e);return i===0?"zero":i>0?n<=t?"positive":"negative":n>=t?"positive":"negative"},elttype:e=>{if(!h(e))return"finite_integer";for(let n=1;n<=e.nops;n++)if(!e[`op${n}`].isInteger)return"finite_real";return"finite_integer"}}},Interval:{description:"A set of real numbers between two endpoints. The endpoints may or may not be included.",complexity:8200,lazy:!0,signature:"(number, number) -> set<real>",canonical:([e,n],{engine:t})=>{if(!e||!n)return null;let i=c=>h(c,"Open")?[c.op1,!0]:h(c,"Closed")?[c.op1,!1]:[c,!1],[r,s]=i(e),[o,a]=i(n),[u,l]=xr(t,[r.canonical,o.canonical],["number","number"]);return!u.isValid||!l.isValid?null:t._fn("Interval",[s?t._fn("Open",[u]):u,a?t._fn("Open",[l]):l])},eq:(e,n)=>{let t=sn(e),i=sn(n);return!t||!i?!1:t.start===i.start&&t.end===i.end&&t.openStart===i.openStart&&t.openEnd===i.openEnd},collection:{count:e=>1/0,iterator:e=>{let n=sn(e);if(!n)return{next:()=>({value:void 0,done:!0})};if(n.start>=n.end)return{next:()=>({value:void 0,done:!0})};let t=e.engine,i=0,r=0;return{next:()=>{let s=Math.pow(2,i);r>=s&&(i++,r=0);let o=(2*r+1)/Math.pow(2,i+1),a=n.start+o*(n.end-n.start);return r++,{value:t.number(a),done:!1}}}},isEmpty:e=>{let n=sn(e);if(n)return n.openStart&&n.start===n.end||n.openEnd&&n.start===n.end?!0:n.openStart&&n.openEnd?!1:n.start>=n.end},isFinite:e=>!1,contains:(e,n)=>{let t=sn(e);if(!t)return;if(ii(n,"number")===!1)return!1;let i=n.re;if(!Number.isNaN(i))return n.im!==0?!1:ru(t,i);let r=t.openStart?n.isGreater(t.start):n.isGreaterEqual(t.start);if(r===!1)return!1;let s=t.openEnd?n.isLess(t.end):n.isLessEqual(t.end);if(s===!1)return!1;if(r===!0&&s===!0)return!0},eltsgn:e=>{let n=sn(e);if(!n||n.start===n.end)return"unsigned";if(n.start>=0&&!n.openStart)return"non-negative";if(n.end<=0&&!n.openEnd)return"non-positive";if(n.start>0&&n.end>0)return"positive";if(n.start<0&&n.end<0)return"negative"},elttype:e=>{let n=sn(e);return n?isFinite(n.start)&&isFinite(n.end)?"finite_real":"real":"never"}}},Linspace:{complexity:8200,signature:"(start: number, end: number?, count: number?) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=e.op3.re;return isFinite(n)||(n=pt),Math.max(0,Math.floor(n))},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.re,i=e.op2.re,r=e.op3.re;if(isFinite(r)||(r=pt),r=Math.floor(r),!(!isFinite(t)||!isFinite(i))&&!(n<1||n>r))return r===1?e.engine.number(t):e.engine.number(t+(i-t)*(n-1)/(r-1))},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.re,t=e.op2.re,i;isFinite(t)?i=Math.max(0,isFinite(e.op3.re)?e.op3.re:pt):(t=n,n=1,i=pt),i=Math.floor(i);let r=i>1?i-1:1,s=1;return{next:()=>s===i+1?{value:void 0,done:!0}:(s+=1,{value:e.engine.number(n+(t-n)*(s-1-1)/r),done:!1})}},contains:(e,n)=>{let t=n.re;if(Number.isNaN(t))return ii(n,"number")===!1?!1:void 0;if(n.im!==0||!isFinite(t))return!1;if(!h(e))return;let i=e.op1.re,r=e.op2.re;if(Number.isNaN(i)||Number.isNaN(r))return;if(t<i||t>r)return!1;let s=e.op3.re;if(isFinite(s)||(s=pt),s=Math.floor(s),s===0)return!1;if(s===1)return t===i;let o=(r-i)/(s-1),a=(t-i)/o,u=e.engine.tolerance,l=Math.round(a);return l>=0&&l<=s-1&&Math.abs(a-l)<u}}},Contains:{description:"Return True if the collection contains the given element, False otherwise.",complexity:8200,signature:"(collection, element: any) -> boolean",evaluate:([e,n],{engine:t})=>e.contains(n)?t.True:t.False},Count:{description:["Return the number of elements in the collection."],complexity:8200,signature:"(collection) -> integer",evaluate:([e],{engine:n})=>{if(e.isEmptyCollection)return n.Zero;let t=e.count;if(t!==void 0)return n.number(t)},sgn:([e])=>{let n=e.isEmptyCollection;if(n===!0)return"zero";if(n===!1)return"positive"}},IsEmpty:{description:["Return True if the collection is empty, False otherwise."],complexity:8200,signature:"(collection) -> boolean",evaluate:([e],{engine:n})=>e.isEmptyCollection?n.True:n.False},Map:{description:["Return the collection where each element has been transformed by the mapping function.","Equivalent to `[f(x) for x in xs]`."],complexity:8200,lazy:!0,signature:"(collection, function) -> collection",type:e=>e[0].type,canonical:(e,{engine:n})=>{let t=rn(n,e[0]?.canonical,"collection"),i=Ue(e[1]);return!t.isValid||!i?null:n._fn("Map",[t,i])},collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},isEmpty:e=>{if(h(e))return e.op1.isEmptyCollection},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=ie(e.op2);if(!n)return{next:()=>({value:void 0,done:!0})};let t=e.op1.each();return{next:()=>{for(;;){let{value:i,done:r}=t.next();return r?{value:void 0,done:!0}:{value:n([i])??e.engine.Nothing,done:!1}}}}},at:(e,n)=>{if(!h(e)||!e.isIndexedCollection||typeof n!="number"||!Number.isFinite(n)||n===0)return;let t=e.op1.at(n);if(t)return ie(e.op2)?.([t])}}},Filter:{description:["Return the elements of the collection for which the predicate function returns True.","Equivalent to `[x for x in xs if p(x)]`."],complexity:8200,lazy:!0,signature:"(collection, predicate: function) -> collection",type:e=>e[0].type,canonical:(e,{engine:n})=>{let t=rn(n,e[0]?.canonical,"collection"),i=Ue(e[1]);return!t.isValid||!i?null:n._fn("Filter",[t,i])},collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;if(!e.op1.isFiniteCollection)return 1/0;let n=0;for(let t of e.each())n++;return n},contains:(e,n)=>{if(!h(e)||!e.contains(n))return!1;let t=ie(e.op2);return K(t([n]))==="True"},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=ie(e.op2);if(!n)return{next:()=>({value:void 0,done:!0})};let t=e.op1.each(),i=0,r=e.engine.iterationLimit;return{next:()=>{for(;;){let{value:s,done:o}=t.next();if(i+=1,i>r)throw new wn({cause:"iteration-limit-exceeded",message:`Iteration limit of ${r} exceeded while evaluating Filter()`});if(o)return{value:void 0,done:!0};let a=n([s]);if(!a)throw new Error(`Invalid filter predicate. ${Qe(e.op2)}`);if(K(a)==="True")return{value:s,done:!1};if(K(a)!=="False")throw new Error(`Filter predicate must return "True" or "False". ${Qe(e.op2)}`)}}}},at:(e,n)=>{if(typeof n!="number"||!Number.isFinite(n)||n===0||!h(e))return;let t=ie(e.op2);if(!t)return;if(n<0){if(!e.op1.isFiniteCollection)return;let r=Array.from(e.each()),s=r.length+n+1;return s<1||s>r.length?void 0:r[s-1]}let i=0;for(let r of e.op1.each()){let s=K(t([r]));if(s==="True"){if(i+=1,i===n)return r}else if(s!=="False")throw new Error(`Filter predicate must return "True" or "False". ${Qe(e.op2)}`)}}}},Reduce:{complexity:8200,lazy:!0,signature:"(collection, function, initial:value?) -> value",canonical:(e,{engine:n})=>{let t=rn(n,e[0],"collection"),i=Ue(e[1]);if(!t.isValid||!i)return null;let r=e[2]?.canonical;return r?.isValid?n._fn("Reduce",[t,i,r]):n._fn("Reduce",[t,i])},type:e=>U(Xi(e[1].type.type)??"unknown"),evaluate:([e,n,t],{engine:i})=>{if(!e.isFiniteCollection)return;let r=t!==void 0;if(t??=i.Nothing,t.type.matches("real")&&e.type.matches(i.type("collection<real>"))){let o=i._compile(n);if(o.calling==="lambda"&&o.run)return Ki((function*(){let a=r?t.re:NaN,u=!0;for(let l of e.each())u&&!r?a=l.re:a=o.run(a,l.re),u=!1,yield;return i.expr(a)})(),i._timeRemaining)}let s=ie(n);return Ki(bu(e,(o,a)=>s([o,a])??i.Nothing,t),i._timeRemaining)}},Join:{description:["Join the elements of some collections into a flat collection."],complexity:8200,signature:"(collection*) -> collection",type:Gf,collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=0;for(let t of e.ops){let i=t.count;if(i===void 0)return;if(!Number.isFinite(i))return 1/0;n+=i}return n},contains:(e,n)=>h(e)?e.ops.some(t=>t.contains(n)):!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.ops.map(i=>i.each()),t=0;return{next:()=>{for(;;){let{value:i,done:r}=n[t].next();if(!r)return{value:i,done:!1};if(t+=1,t>=n.length)return{value:void 0,done:!0}}}}}}},At:{description:["Access an element of an indexed collection.","If the index is negative, it is counted from the end.","Multiple indices can be provided to access nested collections (e.g., matrices).","If the index is a finite collection of booleans, returns the elements where the mask is True.","If the index is a finite collection of integers, returns the elements at those indices."],complexity:8200,signature:"(value: indexed_collection, index: (number|string|indexed_collection)+) -> unknown",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??Ce(e.type.type)??"any",evaluate:(e,{engine:n})=>{let t=e[0],i=1;for(;e[i];){let s=t.baseDefinition?.collection?.at;if(!s)return;let o=e[i],a=le(o)?o.string:void 0;if(a!==void 0){t=s(t,a)??n.Nothing,i+=1;continue}if(o.isCollection&&o.isFiniteCollection){let l=Array.from(o.each()),c=l.every(d=>{let m=K(d);return m==="True"||m==="False"}),f=[];if(c)l.forEach((d,m)=>{if(K(d)!=="True")return;let g=s(t,m+1);g!==void 0&&f.push(g)});else for(let d of l){let m=d.re;if(!Number.isInteger(m))return;let g=s(t,m);g!==void 0&&f.push(g)}t=n._fn("List",f),i+=1;continue}let u=o.re;if(!Number.isInteger(u))return;t=s(t,u)??n.Nothing,i+=1}return t}},Take:{description:["Return `n` elements from a collection."],complexity:8200,signature:"(xs: indexed_collection, count: number) -> indexed_collection",type:([e])=>`list<${V(Ce(e.type.type)??"any")}>`,evaluate:(e,{engine:n,materialization:t})=>{if(!t)return;let i=n._fn("Take",e),r=Array.from(i.each());return n._fn("List",r)},collection:{isLazy:e=>!0,count:hu,isEmpty:e=>{if(!h(e))return;let[n,t]=e.ops;if(n.isEmptyCollection)return!0;if(n.isFiniteCollection===!1)return!1;let i=Math.max(0,z(t)??0),r=n.count;if(r!==void 0)return Number.isFinite(i)?Math.min(r,i)===0:!1},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:jf,at:(e,n)=>{if(typeof n!="number"||n===0||!h(e))return;let t=Math.max(0,z(e.op2)??0);if(t===0)return;if(n>0)return n>t?void 0:e.op1.at(n);let i=hu(e);if(!(i===void 0||i===0)&&!(n<-i))return e.op1.at(i+n)}}},Drop:{description:["Return the collection without the first n elements."],complexity:8200,signature:"(xs: indexed_collection, count: number) -> indexed_collection",type:([e])=>`list<${V(Ce(e.type.type)??"any")}>`,collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let[n,t]=e.ops,i=n.count;if(i===void 0)return;if(!Number.isFinite(i))return 1/0;if(n.isEmptyCollection)return 0;let r=z(t)??0;return r>=i?0:Math.max(0,i-r)},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let[n,t]=e.ops,i=z(t)??0;if(i<=0)return n.each();let r=n.count,s=i+1;return{next:()=>{if(r!==void 0&&s>r)return{value:void 0,done:!0};let o=n.at(s++);return o===void 0?{value:void 0,done:!0}:{value:o,done:!1}}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let[t,i]=e.ops,r=z(i)??0;if(r<=0)return t.at(n);if(n<0){let s=t.count;return s!==void 0&&-n>s-r?void 0:t.at(n)}if(!(n<1))return t.at(n+r)}}},First:{complexity:8200,signature:"(any) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.isCollection?e.at(1)??n.Nothing:n.error(["incompatible-type","'collection'",e.type.toString()])},Second:{complexity:8200,signature:"(any) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.isCollection?e.at(2)??n.Nothing:n.error(["incompatible-type","'collection'",e.type.toString()])},Third:{complexity:8200,signature:"(any) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.isCollection?e.at(3)??n.Nothing:n.error(["incompatible-type","'collection'",e.type.toString()])},Last:{complexity:8200,signature:"(collection) -> any",type:([e])=>e.operatorDefinition?.collection?.elttype?.(e)??"any",evaluate:([e],{engine:n})=>e.at(-1)??n.Nothing},Rest:{description:["Return the collection without the first element.","If the collection has only one element, return an empty collection."],complexity:8200,signature:"(indexed_collection) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=e.op1.count;if(n!==void 0)return Math.max(0,n-1)},isEmpty:e=>{if(!h(e))return;if(e.op1.isEmptyCollection)return!0;let n=e.op1.count;if(n!==void 0)return n<=1},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1,t=n.count,i=2;return{next:()=>{if(t!==void 0&&i>t)return{value:void 0,done:!0};let r=n.at(i);return r===void 0?{value:void 0,done:!0}:(i+=1,{value:r,done:!1})}}},at:(e,n)=>{if(typeof n=="number"&&h(e))return e.op1.at(n>0?n+1:n)}}},Most:{complexity:8200,description:["Return the collection without the last element.","If the collection has only one element, return an empty collection."],signature:"(indexed_collection) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=e.op1.count;if(n!==void 0)return Math.max(0,n-1)},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},isEmpty:e=>{if(!h(e))return;let n=e.op1.count;if(n!==void 0)return n<=1},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.count;if(n===void 0||n<=1)return{next:()=>({value:void 0,done:!0})};let t=1,i=n-1;return{next:()=>t>i?{value:void 0,done:!0}:{value:e.op1.at(t++),done:!1}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t!==void 0&&(n<1&&(n=t+1+n),!(n<1||n>t-1)))return e.op1.at(n)}}},Slice:{description:["Return a range of elements from an indexed collection.","If the index is negative, it is counted from the end."],complexity:8200,signature:"(value: indexed_collection, start: number, end: number) -> list",type:([e])=>U(`list<${V(Ce(e.type.type)??"any")}>`),collection:{isLazy:e=>!0,count:e=>{if(!h(e))return;let n=e.op1.count;if(n===void 0)return;let t=z(e.op2)??1;if(t<1&&(t=n+1+t),t<1&&(t=1),t>n)return 0;let i=z(e.op3)??n;return i<1&&(i=n+1+i),i<1&&(i=1),i>n&&(i=n),Math.max(0,i-t+1)},isFinite:e=>!0,at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t===void 0)return;let i=z(e.op2)??1;if(i<1&&(i=t+1+i),i<1&&(i=1),i>t)return;let r=z(e.op3)??t;r<1&&(r=t+1+r),r<1&&(r=1),r>t&&(r=t);let s=r-i+1;if(!(s<=0)&&(n<0&&(n=s+1+n),!(n<1||n>s)))return e.op1.at(i+n-1)},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=z(e.op2)??1,t=e.op1.count;if(t===void 0)return{next:()=>({value:void 0,done:!0})};if(n<1&&(n=t+1+n),n<1&&(n=1),n>t)return{next:()=>({value:void 0,done:!0})};let i=z(e.op3)??t;i<1&&(i=t+1+i),i<1&&(i=1),i>t&&(i=t);let r=n,s=i;return{next:()=>{if(r>s)return{value:void 0,done:!0};let o=e.op1.at(r);return r+=1,{value:o,done:!1}}}}}},Reverse:{complexity:8200,signature:"(indexed_collection) -> indexed_collection",type:([e])=>e.type,collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},isEmpty:e=>{if(h(e))return e.op1.isEmptyCollection},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=-1;return{next:()=>{if(n===0)return{value:void 0,done:!0};let t=e.op1.at(n);return n-=1,{value:t,done:!1}}}},at:(e,n)=>{if(typeof n=="number"&&h(e))return e.op1.at(-n)}}},RotateLeft:{description:"Rotate the elements of the collection to the left by n positions.",complexity:8200,signature:"(indexed_collection, integer?) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},isEmpty:e=>{if(h(e))return e.op1.isEmptyCollection},isFinite:e=>{if(h(e))return e.op1.isFiniteCollection},contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.count;if(n===void 0||n<=0)return{next:()=>({value:void 0,done:!0})};let t=z(e.op2)??1;t=(t%n+n)%n;let i=1,r=n;return{next:()=>{if(i===r+1)return{value:void 0,done:!0};i+=1;let s=e.op1.at((i-1-1+t)%n+1);return s===void 0?{value:void 0,done:!0}:{value:s,done:!1}}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t===void 0||t<=0||(n<1&&(n=t+1+n),n<1||n>t))return;let i=z(e.op2)??1;return i=(i%t+t)%t,e.op1.at((n-1+i)%t+1)}}},RotateRight:{description:"Rotate the elements of the collection to the right by n positions.",complexity:8200,signature:"(indexed_collection, integer?) -> indexed_collection",collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.count},contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=e.op1.count;if(n===void 0||n<=0)return{next:()=>({value:void 0,done:!0})};let t=z(e.op2)??1;t=(t%n+n)%n;let i=1;return{next:()=>{if(i===n+1)return{value:void 0,done:!0};i+=1;let r=(i-1-1+(n-t))%n+1,s=e.op1.at(r);return s===void 0?{value:void 0,done:!0}:{value:s,done:!1}}}},at:(e,n)=>{if(typeof n!="number"||!h(e))return;let t=e.op1.count;if(t===void 0||t<=0||(n<1&&(n=t+1+n),n<1||n>t))return;let i=z(e.op2)??1;i=(i%t+t)%t;let r=(n-1+(t-i))%t+1;return e.op1.at(r)}}},IndexOf:{description:"Return the 1-based index of the first occurrence of value in collection, or 0 if not found.",complexity:8200,signature:"(collection, any) -> integer",evaluate:([e,n],{engine:t})=>{let i=e.indexWhere(r=>r.isSame(n))??void 0;return t.number(i??0)}},IndexWhere:{description:"Return the 1-based index of the first element satisfying the predicate, or 0 if not found.",complexity:8200,signature:"(collection, function) -> integer",evaluate:([e,n],{engine:t})=>{let i=ie(n);if(!i)return t.Zero;let r=e.indexWhere(s=>{let o=K(i([s]));if(o==="True")return!0;if(o==="False")return!1;throw new Error(`Filter predicate must return "True" or "False". ${Qe(n)}`)})??void 0;return t.number(r??0)}},Find:{description:"Return the first element of the collection satisfying the predicate, or Nothing if none found.",complexity:8200,signature:"(collection, function) -> any",type:e=>e[0].type,evaluate:([e,n],{engine:t})=>{let i=ie(n);if(!i)return t.Nothing;for(let r of e.each()){let s=K(i([r]));if(s!=="False"){if(s==="True")return r;throw new Error(`Filter predicate must return "True" or "False". ${Qe(n)}`)}}return t.Nothing}},CountIf:{description:"Return the number of elements in the collection satisfying the predicate.",complexity:8200,signature:"(collection, function) -> integer",evaluate:([e,n],{engine:t})=>{let i=ie(n);if(!i)return t.Zero;let r=0;for(let s of e.each()){let o=K(i([s]));if(o!=="False")if(o==="True")r++;else throw new Error(`Filter predicate must return "True" or "False". ${Qe(n)}`)}return t.number(r)}},Position:{description:"Return a list of indexes of elements in the collection satisfying the predicate.",complexity:8200,signature:"(collection, function) -> list<integer>",type:()=>"list<integer>",evaluate:([e,n],{engine:t})=>{let i=ie(n);if(!i)return t.function("List",[]);let r=[],s=1;for(let o of e.each()){let a=K(i([o]));if(a==="True")r.push(t.number(s));else if(a!=="False")throw new Error(`Filter predicate must return "True" or "False". ${Qe(n)}`);s++}return t.function("List",r)}},Ordering:{description:"Return the indexes that would sort the collection.",complexity:8200,signature:"(indexed_collection, function?) -> list<integer>",evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return t.function("List",[]);let i=du(e,n);return i?t.function("List",i):t.function("List",[])}},Sort:{description:"Return the elements of the collection sorted according to the given comparison function.",complexity:8200,signature:"(indexed_collection, function?) -> indexed_collection",type:e=>e[0].type,evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return t.function(e.operator,[]);let i=du(e,n);if(i)return t.function(e.operator,i.map(r=>e.at(r)))}},Shuffle:{description:"Randomize the order of the elements in the collection. With an optional `seed` argument, the shuffle is deterministic.",complexity:8200,signature:"(indexed_collection, real?) -> indexed_collection",type:e=>e[0].type,evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return;let i=Array.from(e.each()),r=n?.re;if(r!==void 0&&!Number.isNaN(r)){let s=r;for(let o=i.length-1;o>0;o--){let a=Math.floor(su(s)*(o+1));[i[o],i[a]]=[i[a],i[o]],s=ou(s)}}else for(let s=i.length-1;s>0;s--){let o=Math.floor(Math.random()*(s+1));[i[s],i[o]]=[i[o],i[s]]}return t.function(e.operator,i)}},Tabulate:{description:"Create a collection by applying a function to each index in the specified dimensions.",complexity:8200,lazy:!0,signature:"(function, integer, integer?) -> collection",canonical:(e,{engine:n})=>{let t=Ue(e[0]);return t?e[2]?n._fn("Tabulate",[t,rn(n,e[1]?.canonical,"integer"),rn(n,e[2]?.canonical,"integer")]):n._fn("Tabulate",[t,rn(n,e[1]?.canonical,"integer")]):null},evaluate:(e,{engine:n})=>{let t=ie(e[0]);if(!t)return;if(e.length===1)return n._fn("List",[]);let i=e.slice(1).map(s=>z(s));if(i.some(s=>s===null||s<=0))return;if(i.length===1)return n._fn("List",Array.from({length:i[0]??0},(s,o)=>t([n.number(o+1)])??n.Nothing));let r=(s,o,a=0)=>{if(a===s.length){let l=o.map(c=>n.number(c));return t(l)??n.Nothing}let u=["List"];for(let l=1;l<=s[a];l++)o[a]=l,u.push(r(s,o,a+1));return u};return n.expr(r(i,Array(i.length).fill(0)))}},Tally:{description:"Return a tuple with the unique elements of the collection and their respective counts.",complexity:8200,signature:"(collection) -> tuple<list, list<integer>>",type:([e],{engine:n})=>{let t=e.type.type;return t==="string"?U("tuple<list<string>, list<integer>>"):U(`tuple<list<${V(Ce(t)??"any")}>, list<integer>>`)},evaluate:(e,{engine:n})=>{if(!e[0].isFiniteCollection)return;let[t,i]=pu(e[0]);return n.tuple(n.function("List",t),n.function("List",i))}},Unique:{description:"Return a list of the unique elements of the collection.",complexity:8200,signature:"(collection) -> list",type:([e])=>`list<${V(Ce(e.type.type)??"any")}>`,evaluate:(e,{engine:n})=>{if(!e[0].isFiniteCollection)return;let[t,i]=pu(e[0]);return n.function("List",t)}},Partition:{wikidata:"Q381060",complexity:8200,signature:"(collection, integer | function) -> list",type:([e])=>`list<${V(Ce(e.type.type)??"any")}>`,evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return;let i=z(n);if(i!==null&&i>0){let a=Array.from(e.each()),u=[],l=Math.ceil(a.length/i);for(let c=0;c<i;c++){let f=a.slice(c*l,(c+1)*l);u.push(t.function("List",f))}return t.function("List",u)}let r=ie(n);if(!r)return;let s=[],o=[];for(let a of e.each()){let u=K(r([a]));if(u==="True")s.push(a);else if(u==="False")o.push(a);else throw new Error(`Partition predicate must return "True" or "False". ${Qe(n)}`)}return t.function("List",[t.function("List",s),t.function("List",o)])}},Chunk:{description:"Split the collection into `k` nearly equal-sized chunks.",complexity:8200,signature:"(collection, integer) -> list<list>",evaluate:([e,n],{engine:t})=>{let i=z(n);if(!e.isFiniteCollection||i===null||i<=0)return;let r=Array.from(e.each()),s=[],o=Math.ceil(r.length/i);for(let a=0;a<i;a++){let u=r.slice(a*o,(a+1)*o);s.push(t.function("List",u))}return t.function("List",s)}},GroupBy:{description:["Partition the collection into a dictionary of lists based on the key returned by the function."],complexity:8200,signature:"(collection, function) -> dictionary<list>",evaluate:([e,n],{engine:t})=>{if(!e.isFiniteCollection)return;let i=ie(n);if(!i)return;let r={};for(let s of e.each()){let o=i([s])??t.Nothing,a=(T(o)?o.symbol:void 0)??(le(o)?o.string:void 0)??o.toString();a in r||(r[a]=[]),r[a].push(s)}return t.function("Dictionary",Object.entries(r).map(([s,o])=>t._fn("Tuple",[t.string(s),t.function("List",o)])))}},Zip:{description:"Combine multiple collections element-wise into a list of tuples. The result has the length of the shortest input.",complexity:8200,signature:"(indexed_collection+) -> list",collection:{isLazy:e=>!0,count:Tr,isFinite:e=>{if(!h(e))return;if(e.nops===0)return!0;let n=!1;for(let t of e.ops){let i=t.isFiniteCollection;if(i===!0)return!0;i===void 0&&(n=!0)}return n?void 0:!1},isEmpty:e=>{if(!h(e))return;if(e.nops===0)return!0;let n=!1;for(let t of e.ops){let i=t.isEmptyCollection;if(i===!0)return!0;i===void 0&&(n=!0)}return n?void 0:!1},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=Tr(e);if(n===void 0||n<=0)return{next:()=>({value:void 0,done:!0})};let t=1;return{next:()=>{if(t===n+1)return{value:void 0,done:!0};t+=1;let i=e.ops.map(r=>r.at(t-1));return i.some(r=>r===void 0)?{value:void 0,done:!0}:{value:e.engine.tuple(...i),done:!1}}}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=Tr(e);if(t===void 0||n<1||n>t)return;let i=e.ops.map(r=>r.at(n));if(!i.some(r=>r===void 0))return e.engine.tuple(...i)}}},Iterate:{description:"Produce an infinite sequence by repeatedly applying a function to the previous value, starting with an initial value.",complexity:8200,signature:"((index: integer, acc:any) -> any, initial: any?) -> list",canonical:([e,n],{engine:t})=>{let i=Ue(e);if(!i)return null;let r=n?.canonical;return r?t._fn("Iterate",[i,r]):t._fn("Iterate",[i])},collection:{isLazy:e=>!0,count:()=>1/0,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=ie(e.op1);if(!n)return{next:()=>({value:void 0,done:!0})};let t=e.op2??e.engine.Nothing,i=0;return{next:()=>(i+=1,t=n([e.engine.number(i),t])??e.engine.Nothing,{value:t,done:!1})}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=ie(e.op1);if(!t)return;let i=e.op2??e.engine.Nothing;for(let r=1;r<n;r++)i=t([e.engine.number(r),i])??e.engine.Nothing;return i}}},Repeat:{description:"Produce a sequence by repeating a single value. With 1 argument, returns an infinite sequence; with 2 arguments (value, count), returns a finite list of `count` copies.",complexity:8200,signature:"(value: any, count: integer?) -> list",evaluate:(e,{engine:n})=>{if(e.length!==2)return;let t=z(e[1]);if(t===null)return;let i=Math.max(0,t);if(!(i>n.maxCollectionSize))return n._fn("List",Array(i).fill(e[0]))},collection:{isLazy:e=>h(e)&&e.ops?.length===1,count:e=>{if(h(e)){if(e.ops?.length===2){let n=z(e.op2);return n!==null?Math.max(0,n):void 0}return 1/0}},isEmpty:e=>{if(h(e)){if(e.ops?.length===2){let n=z(e.op2);return n!==null?n<=0:void 0}return!1}},isFinite:e=>h(e)&&e.ops?.length===2,contains:(e,n)=>{if(!h(e))return!1;if(e.ops?.length===2){let t=z(e.op2);if(t!==null&&t<=0)return!1}return e.op1.isSame(n)},iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};if(e.ops?.length===2){let n=z(e.op2);if(n===null)return{next:()=>({value:void 0,done:!0})};let t=Math.max(0,n),i=0;return{next:()=>i++<t?{value:e.op1,done:!1}:{value:void 0,done:!0}}}return{next:()=>({value:e.op1,done:!1})}},at:(e,n)=>{if(h(e)&&typeof n=="number"){if(e.ops?.length===2){let t=z(e.op2),i=t!==null?Math.max(0,t):0;if(n<1||n>i)return}else if(n<1)return;return e.op1}}}},Cycle:{description:"Produce an infinite sequence by cycling through the elements of a finite collection.",complexity:8200,signature:"(list) -> list",collection:{isLazy:e=>!0,count:e=>{if(h(e))return e.op1.isEmptyCollection?0:1/0},isEmpty:e=>{if(h(e))return e.op1.isEmptyCollection},isFinite:e=>{if(h(e))return e.op1.isEmptyCollection},contains:(e,n)=>h(e)?e.op1.contains(n)??!1:!1,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=1,t=e.op1.count;return t===void 0||t===0?{next:()=>({value:void 0,done:!0})}:{next:()=>{let i=(n-1)%t+1,r=e.op1.at(i);return r===void 0?{value:void 0,done:!0}:(n+=1,{value:r,done:!1})}}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=e.op1.count;if(t===void 0||t===0)return;let i=(n-1)%t+1;return e.op1.at(i)}}},Fill:{description:"Produce a 2D list (matrix) by applying a function to each pair of row and column indexes.",complexity:8200,signature:"(function, tuple) -> list",collection:{isLazy:e=>!0,count:e=>!h(e)||!h(e.op2)?void 0:e.op2.ops.map(t=>z(t)??0)[0]??0,iterator:e=>{if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=ie(e.op1);if(!n)return{next:()=>({value:void 0,done:!0})};if(!h(e.op2))return{next:()=>({value:void 0,done:!0})};let t=e.op2.ops.map(a=>z(a)??0),i=t[0]??0,r=t[1]??0,s=i,o=1;return{next:()=>{if(o===s+1)return{value:void 0,done:!0};o+=1;let a=[];for(let u=1;u<=r;u++)a.push(n([e.engine.number(o-1),e.engine.number(u)])??e.engine.Nothing);return{value:e.engine.function("List",a),done:!1}}}},at:(e,n)=>{if(typeof n!="number"||n<1||!h(e))return;let t=ie(e.op1);if(!t||!h(e.op2))return;let i=e.op2.ops.map(u=>z(u)??0),r=i[0]??0,s=i[1]??0;if(n>r*s)return;let o=Math.ceil(n/s),a=(n-1)%s+1;return t([e.engine.number(o),e.engine.number(a)])??e.engine.Nothing}}},ListFrom:{description:"Create a list from the elements of a collection.",complexity:8200,signature:"(value*) -> list",type:e=>{if(e.length===0)return"list";let n="unknown";for(let t of e){if(t.isCollection&&!t.isFiniteCollection)return"list";n=ge(n,Ce(t.type.type)??n)}return U(`list<${V(n)}>`)},evaluate:(e,{engine:n})=>{let t=[];for(let i of e)if(!i.isCollection)t.push(i);else{if(!i.isFiniteCollection)return;t.push(...Array.from(i.each()))}return n.function("List",t)}},SetFrom:{description:"Create a set from the elements of a collection.",complexity:8200,signature:"(value*) -> set",type:e=>{if(e.length===0)return"set";let n="unknown";for(let t of e){if(t.isCollection&&!t.isFiniteCollection)return"set";n=ge(n,Ce(t.type.type)??n)}return U(`set<${V(n)}>`)},evaluate:(e,{engine:n})=>{let t=[];for(let i of e)if(!i.isCollection)t.push(i);else{if(!i.isFiniteCollection)return;t.push(...Array.from(i.each()))}return n.function("Set",t)}},TupleFrom:{description:"Create a tuple from the elements of a collection.",complexity:8200,signature:"(value*) -> tuple",evaluate:(e,{engine:n})=>{let t=[];for(let i of e)if(!i.isCollection)t.push(i);else{if(!i.isFiniteCollection)return;t.push(...Array.from(i.each()))}return n.tuple(...t)}},DictionaryFrom:{description:"Create a dictionary from the elements of a collection of (key, value) pairs.",complexity:8200,signature:"(collection) -> dictionary",evaluate:([e],{engine:n})=>{if(!e.isCollection)return;if(h(e,"Record"))return n.function("Dictionary",[...e.ops]);let t=[];for(let i of e.each()){if(!h(i)||i.nops!==2)throw new Error(`Expected a collection of pairs, got ${i.type}`);let r=i.op1,s=i.op2;if(!le(r))throw new Error(`Expected a string key, got ${r.type}`);t.push(n.tuple(r,s))}return n.function("Dictionary",t)}},RecordFrom:{description:"Create a record from the elements of a collection of (key, value) pairs.",complexity:8200,signature:"(collection) -> record",evaluate:([e],{engine:n})=>{if(!e.isCollection)return;if(h(e,"Dictionary"))return n.function("Record",[...e.ops]);let t=[];for(let i of e.each()){if(!h(i)||i.nops!==2)throw new Error(`Expected a collection of pairs, got ${i.type}`);let r=i.op1,s=i.op2;if(!le(r))throw new Error(`Expected a string key, got ${r.type}`);t.push(n.tuple(r,s))}return n.function("Record",t)}}};function Ke(e){if(!h(e))return[1,0,0];if(e.nops===0)return[1,0,0];let n=e.op1.re;if(!isFinite(n)&&!n&&(n=1),e.nops===1)return[1,n,1];let t=e.op2.re;if(!isFinite(t)&&!t&&(t=1),e.nops===2)return[n,t,t>=n?1:-1];let i=e.op3.re;return!isFinite(i)&&!i&&(i=1),[n,t,i]}function qf(e,{engine:n}){let t=e[0];if(e.length===1&&h(t,"Matrix")){let[i,r,s]=t.ops;if(!r||le(r)&&r.string==="..")return s?n._fn("Matrix",[i,n.string("[]"),s]):n._fn("Matrix",[i,r])}return e=e.map(i=>h(i,"Delimiter")?h(i.op1,"Sequence")?n._fn("List",au(n,i.op1.ops)):n._fn("List",[i.op1?.canonical??n.Nothing]):i.canonical),n._fn("List",e)}function Jf(e,{engine:n}){if(e=e.map(r=>r.canonical),Oe(e)!==null)return n._fn("Set",[...e]);let t=[],i=r=>t.some(s=>s.isSame(r));for(let r of e)i(r)||t.push(r);return n._fn("Set",t)}function Oe(e){if(e.length!==2)return null;let[n,t]=e,i=r=>r.isCanonical?r:r.canonical;if(h(t,"Element")&&t.nops>=2){if(!T(t.op1))return null;let r=t.op1.symbol;if(!n.has(r))return null;let s=t.nops>=3&&K(t.op3)!=="Nothing"?t.op3:void 0;return{body:n,variable:r,domain:t.op2,condition:s}}if(h(t,"Condition")&&t.nops>=1){let r=t.op1;if(h(n,"Element")&&n.nops===2&&T(n.op1))return{body:n.op1,variable:n.op1.symbol,domain:i(n.op2),condition:i(r)};if(h(r,"Element")&&r.nops===2&&T(r.op1)){let s=r.op1.symbol;if(n.has(s))return{body:n,variable:s,domain:i(r.op2),condition:void 0}}if(h(r,"And")){let s=r.ops.filter(a=>h(a,"Element")&&a.nops===2&&T(a.op1)&&n.has(a.op1.symbol)),o=s.length===1?s[0]:void 0;if(o&&h(o,"Element")&&T(o.op1)){let a=r.ops.filter(c=>c!==o).map(i),u=n.engine,l=a.length===0?void 0:a.length===1?a[0]:u._fn("And",a);return{body:n,variable:o.op1.symbol,domain:i(o.op2),condition:l}}}return{body:n,variable:T(n)?n.symbol:void 0,domain:void 0,condition:r}}return null}function Tn(e){let{body:n,variable:t,domain:i,condition:r}=e;if(t===void 0||i===void 0)return;let s=n.engine,o=c=>Nr(s._fn("Element",[s.symbol(t),c,...r?[r]:[]]),s),a=o(i);if(a.status!=="success"){let c=i.evaluate();c.isSame(i)||(a=o(c))}if(a.status!=="success")return;let u=T(n)&&n.symbol===t,l=[];for(let c of a.values){let f=u?c:n.subs({[t]:c}).evaluate();l.some(d=>d.isSame(f))||l.push(f)}return l}function gu(e,n){let t=!1;for(let i of e){if(n.isSame(i))return!0;if(R(n)&&R(i)){let r=n.isEqual(i);if(r===!0)return!0;r!==!1&&(t=!0)}else le(n)&&le(i)||(t=!0)}return t?void 0:!1}function zf(e,n){let t=Tn(e);if(t!==void 0)return gu(t,n);if(e.domain!==void 0&&e.variable!==void 0&&T(e.body)&&e.body.symbol===e.variable){let i=e.domain.contains(n);if(i===!1)return!1;let r=!0;if(e.condition!==void 0)if(R(n)||le(n)){let s=e.condition.subs({[e.variable]:n}).evaluate();r=K(s)==="True"?!0:K(s)==="False"?!1:void 0}else r=void 0;if(r===!1)return!1;if(i===!0&&r===!0)return!0}}function pu(e){let n=[],t=[],i=r=>{for(let s=0;s<n.length;s++)if(n[s].isSame(r))return s;return-1};for(let r of e.each()){let s=i(r);s>=0?t[s]++:(n.push(r),t.push(1))}return[n,t]}function*bu(e,n,t){let i=t;for(let r of e.each()){let s=n(i,r);if(s===null)return;yield i,i=s}return i}function Gf(e){return e.some(n=>n.type.matches("record"))?"record":e.some(n=>n.type.matches("dictionary"))?"dictionary":e.some(n=>n.type.matches("set"))?"set":"list"}function mu(e,n){return e.operator!==n.operator||!h(e)||!h(n)||e.nops!==n.nops?!1:e.ops.every((t,i)=>t.isSame(n.ops[i]))}function du(e,n=void 0){let t=n?ie(n):void 0,i=t?(o,a)=>{let u=t([o,a]);return u?.isNegative?-1:u?.isSame(0)?0:1}:(o,a)=>o.isLess(a)?-1:o.isEqual(a)?0:1,r=e.count;if(r===void 0||!Number.isFinite(r)||r<1)return;let s=Array.from({length:r},(o,a)=>a+1);return s.sort((o,a)=>{let u=e.at(o),l=e.at(a);return i(u,l)}),s}function Ir(e){if(e.length===0)return[];let n=[];for(let t of e)K(t)!=="Nothing"&&(h(t,"Sequence")?n.push(...Ir([...t.ops])):le(t)?n.push(t):t.isCollection?n.push(...Ir([...t.each()])):n.push(t));return n}function jf(e){if(!h(e))return{next:()=>({value:void 0,done:!0})};let n=Math.max(0,z(e.op2)??0);if(n===0)return{next:()=>({value:void 0,done:!0})};let t=1,i=0;return{next:()=>{if(i>=Math.abs(n))return{value:void 0,done:!0};let r=e.op1.at(t);return r?(t+=1,i+=1,{value:r,done:!1}):{value:void 0,done:!0}}}}function hu(e){if(!h(e))return;let[n,t]=e.ops,i=n.count;if(i===void 0)return;let r=Math.max(0,z(t)??0);return Number.isFinite(r)?Math.min(i,r):1/0}function Tr(e){if(!h(e))return;let n=e.ops.map(t=>t.count);if(!n.some(t=>t===void 0))return n.some(t=>!Number.isFinite(t))?1/0:n.length===0?0:Math.min(...n)}function yu(e){e?.operator,h(e);let n=1,t=n+zi,i,r=!0,s=e,o=s.op1;i=T(o)?o.symbol:void 0,n=Math.floor(s.op2.re),isNaN(n)&&(n=1),Number.isFinite(n)||(r=!1);let a=s.op3;return(T(a)?a.symbol:void 0)==="Nothing"||a.isInfinity?r=!1:(isNaN(a.re)||(t=Math.floor(a.re??t)),Number.isFinite(t)||(r=!1)),!r&&Number.isFinite(n)&&(t=n+zi),{index:i,lower:n,upper:t,isFinite:r}}var b=class e{static compile(n,t,i=0){if(n===void 0)return"";if(!n.isValid)throw new Error(`Cannot compile invalid expression: "${n.toString()}"`);if(T(n)){let r=n.symbol,s=t.operators?.(r);return s!==void 0?`(a,b) => a ${s[0]} b`:t.var?.(r)??r}if(R(n)){if(n.im!==0){if(!t.complex)throw new Error("Complex numbers are not supported by this target");return t.complex(n.re,n.im)}return t.number(n.re)}if(le(n))return t.string(n.string);if(!h(n))throw new Error(`Cannot compile expression: "${n.toString()}"`);return e.compileExpr(n.engine,n.operator,n.ops,i,t)}static compileExpr(n,t,i,r,s){if(t==="Error")throw new Error("Error");if(t==="Sequence")return i.length===0?"":`(${i.map(u=>e.compile(u,s,r)).join(", ")})`;if(t==="Sum"||t==="Product"){let u=s.functions?.(t);return typeof u=="function"?u(i,l=>e.compile(l,s),s):typeof u=="string"?`${u}(${i.map(l=>e.compile(l,s)).join(", ")})`:e.compileLoop(t,i,s)}let o=s.operators?.(t);if(o!==void 0&&!i.some(l=>e.isComplexValued(l))){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o[0]))return`${o[0]}(${i.map(c=>e.compile(c,s)).join(", ")})`;if(i.every(c=>!c.isCollection)){if(nr(t)&&i.length>2){let f=[];for(let d=0;d<i.length-1;d++)f.push(e.compileExpr(n,t,[i[d],i[d+1]],o[1],s));return`(${f.join(") && (")})`}let c;if(i.length===1)c=`${o[0]}${e.compile(i[0],s,o[1])}`;else{let f=t==="Power";c=i.map((d,m)=>{let g=f&&m<i.length-1?o[1]+1:o[1];return e.compile(d,s,g)}).join(` ${o[0]} `)}return o[1]<r?`(${c})`:c}}if(t==="Function"){let u=s.functions?.(t);if(typeof u=="function")return u(i,c=>e.compile(c,s),s);let l=i.slice(1).map(c=>T(c)?c.symbol:"_");return`((${l.join(", ")}) => ${e.compile(i[0].canonical,{...s,var:c=>l.includes(c)?c:s.var(c)})})`}if(t==="Declare"){let u=T(i[0])?i[0].symbol:"_";return s.declare?s.declare(u):`let ${u}`}if(t==="Assign")return`${T(i[0])?i[0].symbol:"_"} = ${e.compile(i[1],s)}`;if(t==="Return")return`return ${e.compile(i[0],s)}`;if(t==="Break")return"break";if(t==="Continue")return"continue";if(t==="Loop"){let u=s.functions?.(t);return typeof u=="function"?u(i,l=>e.compile(l,s),s):e.compileForLoop(i,s)}if(t==="If"){if(i.length!==3)throw new Error("If: wrong number of arguments");let u=s.functions?.(t);return u?typeof u=="function"?u(i,l=>e.compile(l,s),s):`${u}(${i.map(l=>e.compile(l,s)).join(", ")})`:`((${e.compile(i[0],s)}) ? (${e.compile(i[1],s)}) : (${e.compile(i[2],s)}))`}if(t==="Which"){if(i.length<2||i.length%2!==0)throw new Error("Which: expected even number of arguments (condition/value pairs)");let u=s.functions?.(t);if(u)return typeof u=="function"?u(i,c=>e.compile(c,s),s):`${u}(${i.map(c=>e.compile(c,s)).join(", ")})`;let l=c=>{if(c>=i.length)return"NaN";let f=i[c],d=i[c+1];return T(f,"True")?`(${e.compile(d,s)})`:`((${e.compile(f,s)}) ? (${e.compile(d,s)}) : ${l(c+2)})`};return l(0)}if(t==="When"){if(i.length!==2)throw new Error("When: expected exactly 2 arguments (expr, cond)");let u=s.functions?.(t);if(u)return typeof u=="function"?u(i,f=>e.compile(f,s),s):`${u}(${i.map(f=>e.compile(f,s)).join(", ")})`;if(T(i[1],"True"))return`(${e.compile(i[0],s)})`;if(T(i[1],"False"))return"NaN";let l=e.compile(i[0],s);return`((${e.compile(i[1],s)}) ? (${l}) : NaN)`}if(t==="Block")return e.compileBlock(i,s);let a=s.functions?.(t);if(!a)throw new Error(`Unknown operator \`${t}\``);if(typeof a=="function"){let u=n.lookupDefinition(t);if(ct(u)&&u.operator.broadcastable&&i.length===1&&Bt(i[0])){let l=e.tempVar();return`(${e.compile(i[0],s)}).map((${l}) => ${a([i[0].engine.expr(l)],c=>e.compile(c,s),s)})`}return a(i,l=>e.compile(l,s),s)}return`${a}(${i.map(u=>e.compile(u,s)).join(", ")})`}static compileBlock(n,t){let i=[];for(let a of n)if(h(a,"Declare")){let u=a.ops[0];T(u)&&i.push(u.symbol)}if(n.length===1&&i.length===0)return e.compile(n[0],t);let r={};if(t.declare&&t.language){let a=t.language==="wgsl";for(let u of i)for(let l of n)if(h(l,"Assign")&&T(l.ops[0],u)){let c=l.ops[1];e.isComplexValued(c)?r[u]=a?"vec2f":"vec2":e.isIntegerValued(c)&&(r[u]=a?"i32":"int");break}}let s={...t,var:a=>i.includes(a)?a:t.var(a)},o=n.filter(a=>!T(a,"Nothing")).map(a=>h(a,"Declare")&&T(a.ops[0])&&t.declare?t.declare(a.ops[0].symbol,r[a.ops[0].symbol]):e.compile(a,s)).filter(a=>a!=="");return o.length===0?"":t.block?t.block(o):(o[o.length-1]=`return ${o[o.length-1]}`,`(() => {${t.ws(`
12
12
  `)}${o.join(`;${t.ws(`
13
13
  `)}`)}${t.ws(`
14
- `)}})()`)}static compileForLoop(n,t){if(!n[0])throw new Error("Loop: no body");if(!n[1])throw new Error("Loop: no indexing set");let i=n[0],r=n.slice(1);if(r.length>1||r.length===1&&h(r[0],"Element")&&!e.isLegacyCompatibleRange(r[0].ops[1])){let v=t.language??"";if(v==="glsl"||v==="wgsl")throw new Error(`${v.toUpperCase()}: multi-Element Loop comprehension is not yet supported. TODO(E3-GLSL): unroll or use a fixed-size array.`);let T=[];for(let L=0;L<r.length;L++){let ue=r[L];if(!h(ue,"Element"))throw new Error(`Loop: argument ${L+1} must be an Element clause, got ${ue.operator??"?"}`);if(!k(ue.ops[0]))throw new Error(`Loop: Element index (argument ${L+1}) must be a symbol`);T.push(ue)}let M=new Set(T.map(L=>L.ops[0].symbol)),F=t.number(0)!=="0"?{...t,var:L=>M.has(L)?t.number(0).replace("0",L):t.var(L)}:t,U=`result.push(${e.compile(i,F)});`;for(let L=T.length-1;L>=0;L--){let ue=T[L],H=ue.ops[0].symbol,se=ue.ops[1],oe;h(se,"Range")?oe=e.compileRangeIterable(se,F):oe=e.compile(se,F),U=`for (const ${H} of ${oe}) { ${U} }`}return`(() => { const result = []; ${U} return result; })()`}let o=r[0];if(!h(o,"Element"))throw new Error("Loop: expected Element(index, Range(lo, hi))");let a=o.ops[0],u=o.ops[1];if(!k(a))throw new Error("Loop: index must be a symbol");if(!h(u,"Range"))throw new Error("Loop: expected Range(lo, hi)");let l=a.symbol,c=Math.floor(u.ops[0].re),f=Math.floor(u.ops[1].re);if(!Number.isFinite(c)||!Number.isFinite(f))throw new Error("Loop: bounds must be finite numbers");let m=t.number(0)!=="0",d={...t,var:v=>v===l?m?t.number(0).replace("0",l):l:t.var(v)},b=e.compileLoopBody(i,d);return`(() => {${t.ws(`
14
+ `)}})()`)}static compileForLoop(n,t){if(!n[0])throw new Error("Loop: no body");if(!n[1])throw new Error("Loop: no indexing set");let i=n[0],r=n.slice(1);if(r.length>1||r.length===1&&h(r[0],"Element")&&!e.isLegacyCompatibleRange(r[0].ops[1])){let v=t.language??"";if(v==="glsl"||v==="wgsl")throw new Error(`${v.toUpperCase()}: multi-Element Loop comprehension is not yet supported. TODO(E3-GLSL): unroll or use a fixed-size array.`);let N=[];for(let O=0;O<r.length;O++){let ue=r[O];if(!h(ue,"Element"))throw new Error(`Loop: argument ${O+1} must be an Element clause, got ${ue.operator??"?"}`);if(!T(ue.ops[0]))throw new Error(`Loop: Element index (argument ${O+1}) must be a symbol`);N.push(ue)}let M=new Set(N.map(O=>O.ops[0].symbol)),P=t.number(0)!=="0"?{...t,var:O=>M.has(O)?t.number(0).replace("0",O):t.var(O)}:t,H=`result.push(${e.compile(i,P)});`;for(let O=N.length-1;O>=0;O--){let ue=N[O],Z=ue.ops[0].symbol,se=ue.ops[1],oe;h(se,"Range")?oe=e.compileRangeIterable(se,P):oe=e.compile(se,P),H=`for (const ${Z} of ${oe}) { ${H} }`}return`(() => { const result = []; ${H} return result; })()`}let o=r[0];if(!h(o,"Element"))throw new Error("Loop: expected Element(index, Range(lo, hi))");let a=o.ops[0],u=o.ops[1];if(!T(a))throw new Error("Loop: index must be a symbol");if(!h(u,"Range"))throw new Error("Loop: expected Range(lo, hi)");let l=a.symbol,c=Math.floor(u.ops[0].re),f=Math.floor(u.ops[1].re);if(!Number.isFinite(c)||!Number.isFinite(f))throw new Error("Loop: bounds must be finite numbers");let d=t.number(0)!=="0",m={...t,var:v=>v===l?d?t.number(0).replace("0",l):l:t.var(v)},g=e.compileLoopBody(i,m);return`(() => {${t.ws(`
15
15
  `)}for (let ${l} = ${c}; ${l} <= ${f}; ${l}++) {${t.ws(`
16
- `)}${b}${t.ws(`
16
+ `)}${g}${t.ws(`
17
17
  `)}}${t.ws(`
18
- `)}})()`}static isLegacyCompatibleRange(n){if(!h(n,"Range"))return!1;if(n.ops.length>=3){let r=n.ops[2];if(!D(r)||r.re!==1)return!1}let t=n.ops[0],i=n.ops[1];return!(D(t)&&!Number.isInteger(t.re)||D(i)&&!Number.isInteger(i.re)||D(t)&&D(i)&&t.re>i.re)}static compileRangeIterable(n,t){let i=n.ops[0],r=n.ops[1],s=n.ops[2];if(D(i)&&D(r)&&(s===void 0||D(s))){let l=i.re,c=r.re,f=s===void 0?c>=l?1:-1:s.re;if(f===0)return"[]";let m=Math.max(0,Math.floor((c-l)/f)+1);return f===1?l===0?`Array.from({length:${m}},(_,k)=>k)`:`Array.from({length:${m}},(_,k)=>${l}+k)`:`Array.from({length:${m}},(_,k)=>${l}+(${f})*k)`}let o=e.compile(i,t),a=e.compile(r,t);if(s===void 0)return`((_lo,_hi)=>{const _st=_hi>=_lo?1:-1;return Array.from({length:Math.max(0,Math.floor((_hi-_lo)/_st)+1)},(_,k)=>_lo+_st*k);})(${o},${a})`;let u=e.compile(s,t);return`((_lo,_hi,_st)=>_st===0?[]:Array.from({length:Math.max(0,Math.floor((_hi-_lo)/_st)+1)},(_,k)=>_lo+_st*k))(${o},${a},${u})`}static compileLoopBody(n,t){if(k(n,"Nothing"))return"";if(!h(n))return e.compile(n,t);let i=n.operator;if(i==="Break")return"break";if(i==="Continue")return"continue";if(i==="Return")return`return ${e.compile(n.ops[0],t)}`;if(i==="If"){let r=e.scalarConditionTarget(t),s=e.compile(n.ops[0],r),o=e.compileLoopBody(n.ops[1],t);if(n.ops.length>2){let a=e.compileLoopBody(n.ops[2],t);if(a)return`if (${s}) { ${o} } else { ${a} }`}return`if (${s}) { ${o} }`}return i==="Block"?n.ops.map(r=>e.compileLoopBody(r,t)).join("; "):e.compile(n,t)}static scalarConditionTarget(n){let t={Less:["<",20],Greater:[">",20],LessEqual:["<=",20],GreaterEqual:[">=",20],Equal:["===",20],NotEqual:["!==",20],And:["&&",6],Or:["||",5],Not:["!",16]};return n.number(0)==="0"?n:{...n,number:i=>String(i),var:i=>{let r=n.var(i);if(!r)return;let s=r.match(/^_IA\.point\((.+)\)$/);return s?s[1]:r},operators:i=>t[i]??n.operators?.(i),functions:i=>{if(!(i in t))return n.functions?.(i)}}}static compileLoop(n,t,i){if(!t[0])throw new Error("Sum/Product: no body");let{index:r,lower:s,upper:o,isFinite:a}=wa(t[1]),u=n==="Sum",l=u?"+":"*",c=e.isComplexValued(t[0]);if(!r){let d=e.tempVar(),b=e.tempVar(),v=e.compile(t[0],i);return c?u?`${v}.reduce((${b}, ${d}) => ({ re: ${b}.re + ${d}.re, im: ${b}.im + ${d}.im }), { re: 0, im: 0 })`:`${v}.reduce((${b}, ${d}) => ({ re: ${b}.re * ${d}.re - ${b}.im * ${d}.im, im: ${b}.re * ${d}.im + ${b}.im * ${d}.re }), { re: 1, im: 0 })`:`${v}.reduce((${b}, ${d}) => ${b} ${l} ${d}, ${u?"0":"1"})`}let f=e.compile(t[0],{...i,var:d=>d===r?r:i.var(d)}),m=e.tempVar();if(c){let d=e.tempVar();return u?`(() => {
19
- let ${m} = { re: 0, im: 0 };
18
+ `)}})()`}static isLegacyCompatibleRange(n){if(!h(n,"Range"))return!1;if(n.ops.length>=3){let r=n.ops[2];if(!R(r)||r.re!==1)return!1}let t=n.ops[0],i=n.ops[1];return!(R(t)&&!Number.isInteger(t.re)||R(i)&&!Number.isInteger(i.re)||R(t)&&R(i)&&t.re>i.re)}static compileRangeIterable(n,t){let i=n.ops[0],r=n.ops[1],s=n.ops[2];if(R(i)&&R(r)&&(s===void 0||R(s))){let l=i.re,c=r.re,f=s===void 0?c>=l?1:-1:s.re;if(f===0)return"[]";let d=Math.max(0,Math.floor((c-l)/f)+1);return f===1?l===0?`Array.from({length:${d}},(_,k)=>k)`:`Array.from({length:${d}},(_,k)=>${l}+k)`:`Array.from({length:${d}},(_,k)=>${l}+(${f})*k)`}let o=e.compile(i,t),a=e.compile(r,t);if(s===void 0)return`((_lo,_hi)=>{const _st=_hi>=_lo?1:-1;return Array.from({length:Math.max(0,Math.floor((_hi-_lo)/_st)+1)},(_,k)=>_lo+_st*k);})(${o},${a})`;let u=e.compile(s,t);return`((_lo,_hi,_st)=>_st===0?[]:Array.from({length:Math.max(0,Math.floor((_hi-_lo)/_st)+1)},(_,k)=>_lo+_st*k))(${o},${a},${u})`}static compileLoopBody(n,t){if(T(n,"Nothing"))return"";if(!h(n))return e.compile(n,t);let i=n.operator;if(i==="Break")return"break";if(i==="Continue")return"continue";if(i==="Return")return`return ${e.compile(n.ops[0],t)}`;if(i==="If"){let r=e.scalarConditionTarget(t),s=e.compile(n.ops[0],r),o=e.compileLoopBody(n.ops[1],t);if(n.ops.length>2){let a=e.compileLoopBody(n.ops[2],t);if(a)return`if (${s}) { ${o} } else { ${a} }`}return`if (${s}) { ${o} }`}return i==="Block"?n.ops.map(r=>e.compileLoopBody(r,t)).join("; "):e.compile(n,t)}static scalarConditionTarget(n){let t={Less:["<",20],Greater:[">",20],LessEqual:["<=",20],GreaterEqual:[">=",20],Equal:["===",20],NotEqual:["!==",20],And:["&&",6],Or:["||",5],Not:["!",16]};return n.number(0)==="0"?n:{...n,number:i=>String(i),var:i=>{let r=n.var(i);if(!r)return;let s=r.match(/^_IA\.point\((.+)\)$/);return s?s[1]:r},operators:i=>t[i]??n.operators?.(i),functions:i=>{if(!(i in t))return n.functions?.(i)}}}static compileLoop(n,t,i){if(!t[0])throw new Error("Sum/Product: no body");let{index:r,lower:s,upper:o,isFinite:a}=yu(t[1]),u=n==="Sum",l=u?"+":"*",c=e.isComplexValued(t[0]);if(!r){let m=e.tempVar(),g=e.tempVar(),v=e.compile(t[0],i);return c?u?`${v}.reduce((${g}, ${m}) => ({ re: ${g}.re + ${m}.re, im: ${g}.im + ${m}.im }), { re: 0, im: 0 })`:`${v}.reduce((${g}, ${m}) => ({ re: ${g}.re * ${m}.re - ${g}.im * ${m}.im, im: ${g}.re * ${m}.im + ${g}.im * ${m}.re }), { re: 1, im: 0 })`:`${v}.reduce((${g}, ${m}) => ${g} ${l} ${m}, ${u?"0":"1"})`}let f=e.compile(t[0],{...i,var:m=>m===r?r:i.var(m)}),d=e.tempVar();if(c){let m=e.tempVar();return u?`(() => {
19
+ let ${d} = { re: 0, im: 0 };
20
20
  let ${r} = ${s};
21
21
  while (${r} <= ${o}) {
22
- const ${d} = ${f};
23
- ${m} = { re: ${m}.re + ${d}.re, im: ${m}.im + ${d}.im };
22
+ const ${m} = ${f};
23
+ ${d} = { re: ${d}.re + ${m}.re, im: ${d}.im + ${m}.im };
24
24
  ${r}++;
25
25
  }
26
- return ${m};
26
+ return ${d};
27
27
  })()`:`(() => {
28
- let ${m} = { re: 1, im: 0 };
28
+ let ${d} = { re: 1, im: 0 };
29
29
  let ${r} = ${s};
30
30
  while (${r} <= ${o}) {
31
- const ${d} = ${f};
32
- ${m} = { re: ${m}.re * ${d}.re - ${m}.im * ${d}.im, im: ${m}.re * ${d}.im + ${m}.im * ${d}.re };
31
+ const ${m} = ${f};
32
+ ${d} = { re: ${d}.re * ${m}.re - ${d}.im * ${m}.im, im: ${d}.re * ${m}.im + ${d}.im * ${m}.re };
33
33
  ${r}++;
34
34
  }
35
- return ${m};
35
+ return ${d};
36
36
  })()`}return`(() => {
37
- let ${m} = ${u?"0":"1"};
37
+ let ${d} = ${u?"0":"1"};
38
38
  let ${r} = ${s};
39
39
  while (${r} <= ${o}) {
40
- ${m} ${l}= ${f};
40
+ ${d} ${l}= ${f};
41
41
  ${r}++;
42
42
  }
43
- return ${m};
44
- })()`}static isComplexValued(n){if(D(n))return n.im!==0;if(k(n)){if(n.symbol==="ImaginaryUnit")return!0;let t=n.type;return t?t.matches("complex")&&!t.matches("real"):!1}if(h(n)){let t=n.type;return t.matches("complex")&&!t.matches("real")?!0:t.matches("real")?!1:n.ops.some(i=>e.isComplexValued(i))}return!1}static isIntegerValued(n){if(D(n))return n.im===0&&Number.isInteger(n.re);let t=n.type;return t?t.matches("integer"):!1}static isNonNegative(n){return D(n)?n.im===0&&n.re>=0:n.isNonNegative===!0}static tempVar(){return`_${Math.random().toString(36).substring(4)}`}static inlineExpression(n,t){if(/^[\p{L}_][\p{L}\p{N}_]*$/u.test(t)||/^[0-9]+$/.test(t))return new Function("x",`return \`${n}\`;`)(t);{let r=e.tempVar();return new Function("x",`return \`(() => { const ${r} = \${x}; return ${n.replace(/\\\${x}/g,r)}; })()\`;`)(t)}}};function at(e){return typeof e=="object"&&e!==null}function Aa(e){return typeof e=="number"&&Number.isFinite(e)}function Gc(e){if(!at(e))throw new Error("Invalid compile target: expected an object");if(typeof e.var!="function")throw new Error('Invalid compile target: missing required method "var()"');if(typeof e.string!="function")throw new Error('Invalid compile target: missing required method "string()"');if(typeof e.number!="function")throw new Error('Invalid compile target: missing required method "number()"');if(typeof e.ws!="function")throw new Error('Invalid compile target: missing required method "ws()"');if(typeof e.preamble!="string")throw new Error('Invalid compile target: "preamble" must be a string');if(!Aa(e.indent))throw new Error('Invalid compile target: "indent" must be a finite number');if(e.operators!==void 0&&typeof e.operators!="function")throw new Error('Invalid compile target: "operators" must be a function');if(e.functions!==void 0&&typeof e.functions!="function")throw new Error('Invalid compile target: "functions" must be a function');if(e.language!==void 0&&typeof e.language!="string")throw new Error('Invalid compile target: "language" must be a string')}function jc(e,n){if(n!==void 0&&(!Array.isArray(n)||n.length!==2||typeof n[0]!="string"||!Aa(n[1])))throw new Error(`Invalid compilation option "operators.${e}": expected [string, number]`)}function Uc(e){if(e!==void 0&&typeof e!="function"){if(!at(e)||Array.isArray(e))throw new Error('Invalid compilation option "operators": expected a function or a record');for(let[n,t]of Object.entries(e))jc(n,t)}}function Hc(e){if(e!==void 0){if(!at(e)||Array.isArray(e))throw new Error('Invalid compilation option "functions": expected a record');for(let[n,t]of Object.entries(e))if(typeof t!="string"&&typeof t!="function")throw new Error(`Invalid compilation option "functions.${n}": expected a string or function`)}}function Zc(e){if(e!==void 0){if(!at(e)||Array.isArray(e))throw new Error('Invalid compilation option "vars": expected a record');for(let[n,t]of Object.entries(e))if(typeof t!="string")throw new Error(`Invalid compilation option "vars.${n}": expected a string`)}}function Yc(e){if(e!==void 0&&!Array.isArray(e))throw new Error('Invalid compilation option "imports": expected an array')}function $a(e){if(e!==void 0){if(!at(e)||Array.isArray(e))throw new Error("Invalid compilation options: expected an object");if(e.to!==void 0&&typeof e.to!="string")throw new Error('Invalid compilation option "to": expected a string');if(e.target!==void 0&&Gc(e.target),Uc(e.operators),Hc(e.functions),Zc(e.vars),Yc(e.imports),e.preamble!==void 0&&typeof e.preamble!="string")throw new Error('Invalid compilation option "preamble": expected a string');if(e.fallback!==void 0&&typeof e.fallback!="boolean")throw new Error('Invalid compilation option "fallback": expected a boolean')}}function Ca(e,n){$a(n);try{if(n?.target){let r=g.compile(e,n.target);return{target:n.target.language??"custom",success:!0,code:r}}let t=n?.to??"javascript",i=e.engine.getCompilationTarget(t);if(!i)throw new Error(`Compilation target "${t}" is not registered. Available targets: ${e.engine.listCompilationTargets().join(", ")}`);return i.compile(e,{operators:n?.operators,functions:n?.functions,vars:n?.vars,imports:n?.imports,preamble:n?.preamble,realOnly:n?.realOnly})}catch(t){if(n?.fallback??!0){console.warn(`Compilation fallback for "${e.operator}" (target: ${n?.to??"javascript"}): ${t.message}`);let i=e.engine,r=(s=>{i.pushScope();try{if(s&&typeof s=="object")for(let[o,a]of Object.entries(s))i.assign(o,a);return e.evaluate().re}finally{i.popScope()}});return{target:n?.to??"javascript",success:!1,code:"",calling:"expression",run:r}}throw t}}function ae(e){let n=e.toString();return!n.includes(".")&&!n.includes("e")&&!n.includes("E")?`${n}.0`:n}function X(e){if(!D(e)||e.im!==0)return;let n=e.re;if(isFinite(n))return n}var Wc=/^-?\d+(\.\d+)?$/;function tn(e,n,t){let i=t==="+"?0:1,r=null,s=[];for(let o of e)if(Wc.test(o)){let a=parseFloat(o);if(t==="*"&&a===0)return"0.0";r===null?r=a:r=t==="+"?r+a:r*a}else s.push(o);return r!==null&&r!==i&&s.unshift(ae(r)),s.length===0?r!==null?ae(r):n:s.length===1?s[0]:s.join(t==="+"?" + ":" * ")}function Ra(e,n){if(k(e,"ImaginaryUnit"))return{re:null,im:"1.0"};if(D(e)&&e.im!==0){let t=e.re,i=e.im;return{re:t!==0?ae(t):null,im:ae(i)}}if(h(e,"Multiply")){let t=e.ops,i=t.findIndex(r=>k(r,"ImaginaryUnit")||D(r)&&r.re===0&&r.im!==0);if(i>=0){let r=t[i],s=k(r,"ImaginaryUnit")?1:r.im,o=t.filter((l,c)=>c!==i);if(o.length===0)return{re:null,im:ae(s)};let a=o.map(l=>n(l));return s!==1&&a.unshift(ae(s)),{re:null,im:tn(a,"1.0","*")}}}return g.isComplexValued(e)?null:{re:n(e),im:null}}function cr(e){let n=Math.abs(e);return n<=.0031308?12.92*e:(Math.sign(e)||1)*(1.055*Math.pow(n,1/2.4)-.055)}function fr(e){let n=Math.abs(e);return n<=.04045?e/12.92:(Math.sign(e)||1)*Math.pow((n+.055)/1.055,2.4)}function Kt(e,n,t){e=e/360;let i,r,s;if(n===0)i=r=s=t;else{let o=(l,c,f)=>(f<0&&(f+=1),f>1&&(f-=1),f<.16666666666666666?l+(c-l)*6*f:f<.5?c:f<.6666666666666666?l+(c-l)*(.6666666666666666-f)*6:l),a=t<.5?t*(1+n):t+n-t*n,u=2*t-a;i=o(u,a,e+1/3),r=o(u,a,e),s=o(u,a,e-1/3)}return{r:Math.round(i*255),g:Math.round(r*255),b:Math.round(s*255)}}function ei(e,n,t){e/=255,n/=255,t/=255;let i=Math.max(e,n,t),r=Math.min(e,n,t),s=(i+r)/2;if(i===r)return{h:0,s:0,l:s};let o=i-r,a=s>.5?o/(2-i-r):o/(i+r),u;return i===e?u=((n-t)/o+(n<t?6:0))/6:i===n?u=((t-e)/o+2)/6:u=((e-n)/o+4)/6,{h:u*360,s:a,l:s}}function Xa(e,n,t){e=(e%360+360)%360,n=Math.max(0,Math.min(1,n)),t=Math.max(0,Math.min(1,t));let i=t*n,r=i*(1-Math.abs(e/60%2-1)),s=t-i,o=0,a=0,u=0;return e<60?[o,a,u]=[i,r,0]:e<120?[o,a,u]=[r,i,0]:e<180?[o,a,u]=[0,i,r]:e<240?[o,a,u]=[0,r,i]:e<300?[o,a,u]=[r,0,i]:[o,a,u]=[i,0,r],{r:(o+s)*255,g:(a+s)*255,b:(u+s)*255}}function Qa(e,n,t){e/=255,n/=255,t/=255;let i=Math.max(e,n,t),r=Math.min(e,n,t),s=i-r,o=0;s>0&&(i===e?o=(n-t)/s%6:i===n?o=(t-e)/s+2:o=(e-n)/s+4,o*=60,o<0&&(o+=360));let a=i===0?0:s/i;return{h:o,s:a,v:i}}function Xc(e){let n=e.startsWith("#")?e.substring(1):e,t,i,r,s;if(n.length===3)t=parseInt(n[0]+n[0],16),i=parseInt(n[1]+n[1],16),r=parseInt(n[2]+n[2],16);else if(n.length===6)t=parseInt(n.substring(0,2),16),i=parseInt(n.substring(2,4),16),r=parseInt(n.substring(4,6),16);else if(n.length===8)t=parseInt(n.substring(0,2),16),i=parseInt(n.substring(2,4),16),r=parseInt(n.substring(4,6),16),s=parseInt(n.substring(6,8),16)/255;else return{r:0,g:0,b:0};let o={r:t,g:i,b:r};return s!==void 0&&(o.alpha=s),o}function Wt(e){return typeof e=="number"?{r:e>>>24&255,g:e>>>16&255,b:e>>>8&255,alpha:(e&255)/255}:typeof e=="string"?Xc(e):"C"in e?ni(e):"a"in e&&"b"in e?gr(e):e}function Da(e){let n=Wt(e),t=n.alpha!==void 0?Pe(n.alpha*255):255;return(Pe(n.r)<<24|Pe(n.g)<<16|Pe(n.b)<<8|t)>>>0}function Pe(e){return e<0?0:e>255?255:Math.round(e)}function dn(e){let[n,t,i]=[e.L,e.C,e.H],r=i*Math.PI/180,s={L:n,a:t*Math.cos(r),b:t*Math.sin(r)};return e.alpha!==void 0&&(s.alpha=e.alpha),s}function lt(e){let[n,t,i]=[e.L,e.a,e.b],r=Math.sqrt(t*t+i*i),o=Math.atan2(i,t)*180/Math.PI,a={L:n,C:r,H:o};return e.alpha!==void 0&&(a.alpha=e.alpha),a}function Yt(e){let[n,t,i]=[e.L,e.a,e.b],r=Math.pow(.9999999984505198*n+.39633779217376786*t+.2158037580607588*i,3),s=Math.pow(1.00000000888176*n-.10556134232365635*t-.0638541747717059*i,3),o=Math.pow(n*1.000000054672411-.0894841820949657*t-1.2914855378640917*i,3),a=4.076741661347994*r-3.307711590408193*s+.230969928729428*o,u=-1.2684380040921763*r+2.6097574006633715*s-.3413193963102197*o,l=-.004196086541837188*r-.7034186144594493*s+1.7076147009309444*o;return[cr(a),cr(u),cr(l)]}function pr(e){let[n,t,i]=e;return n>=0&&n<=1&&t>=0&&t<=1&&i>=0&&i<=1}function mr(e,n){let[t,i,r]=e;return t=Pe(t*255),i=Pe(i*255),r=Pe(r*255),n!==void 0?{r:t,g:i,b:r,alpha:n}:{r:t,g:i,b:r}}function gr(e){let[n,t,i]=Yt(e);if(pr([n,t,i]))return mr([n,t,i],e.alpha);let r=lt(e);if(r.C=0,[n,t,i]=Yt(dn(r)),!pr([n,t,i]))return mr([n,t,i],e.alpha);let s=0,o=e.L,a=(s+o)/2;r.C=a;let u=.36/Math.pow(2,12);for(;o-s>u;)a=(s+o)/2,r.C=a,[n,t,i]=Yt(dn(r)),pr([n,t,i])?s=a:o=a;return mr([n,t,i],e.alpha)}function ni(e){return gr(dn(e))}function br(e){let[n,t,i]=[e.r,e.g,e.b],r=fr(n/255),s=fr(t/255),o=fr(i/255),a=.41222147079999993*r+.5363325363*s+.0514459929*o,u=.2119034981999999*r+.6806995450999999*s+.1073969566*o,l=.08830246189999998*r+.2817188376*s+.6299787005000002*o,c=Math.cbrt(a),f=Math.cbrt(u),m=Math.cbrt(l),d={L:.2104542553*c+.793617785*f-.0040720468*m,a:1.9779984951*c-2.428592205*f+.4505937099*m,b:.0259040371*c+.7827717662*f-.808675766*m};return e.alpha!==void 0&&(d.alpha=e.alpha),d}function ve(e){return lt(br(e))}function dr(e,n){let t=n*Math.PI/180,i=0,r=1.5;for(let s=0;s<32;s++){let o=(i+r)/2,[a,u,l]=Yt({L:e,a:o*Math.cos(t),b:o*Math.sin(t)});a>=0&&a<=1&&u>=0&&u<=1&&l>=0&&l<=1?i=o:r=o}return i}function Fn(e,n,t){let i=e/100;if(i<=0)return 255;let r=ni({L:i,C:n,H:t});return(Pe(r.r)<<24|Pe(r.g)<<16|Pe(r.b)<<8|255)>>>0}function Qc(e){let{l:n,c:t,h:i}=Xt(e);return Fn(n+2.8,t+.002,i+.46)}function Xt(e){let n=e>>>24&255,t=e>>>16&255,i=e>>>8&255,r=ve({r:n,g:t,b:i});return{l:r.L*100,c:r.C,h:r.H<0?r.H+360:r.H}}function hr(e,n,t){let{l:i,c:r,h:s}=Xt(e),{l:o,c:a,h:u}=Xt(n),l=i+(o-i)*t,c=r+(a-r)*t,f=u-s;f>180&&(f-=360),f<-180&&(f+=360);let m=s+f*t,d=e&255,b=n&255,v=Math.round(d+(b-d)*t);return Fn(l,c,m<0?m+360:m>360?m-360:m)&4294967040|v}function Kc(e,n=.1){let a=.45,u=0;for(let b=.45;b>=.35;b-=.01){let v=dr(b,e);if(v>=.15){a=b,u=.15;break}else v>u&&(a=b,u=v)}if(u<.15*.8)for(let b=.45+.01;b<=.5;b+=.01){let v=dr(b,e);if(v>=.15||v>u*1.2){a=b,u=Math.min(.15,v);break}}let l=.96,c=.02,f=dr(.96,e);f<.02&&(c=f*(1-n)),c=Math.max(.015,Math.min(.02,c));let m=Fn(a*100,u,e),d=Fn(l*100,c,e);return{darkest:m,lightest:d}}function ef(e,n){let t=Math.max(0,Math.min(1e3,n)),i,r,s;if(typeof e=="object")i=e.darkest,s=e.lightest,r=e.mid??0;else{r=e;let{h:u}=Xt(r),l=r&255,{darkest:c,lightest:f}=Kc(u);i=c&4294967040|l,s=f&4294967040|l}if(!r&&typeof e=="object"&&!e.mid&&(r=hr(i,s,.5)),t<=500){let u=t/500,l=u*u*(3-2*u);return hr(s,r,l)}let o=(t-500)/500,a=o*o*(3-2*o);return hr(r,i,a)}var nf=[{id:"pink",name:"Pink",colors:{mid:{lightness:69,chroma:.202,hue:7.4}}},{id:"red",name:"Red",colors:{lightest:{lightness:95,chroma:.2,hue:30},mid:{lightness:62,chroma:.25,hue:30},darkest:{lightness:36,chroma:.16,hue:25}}},{id:"brown",name:"Brown",colors:{lightest:{lightness:94.5,chroma:.021,hue:72.1},mid:{lightness:59,chroma:.2,hue:73},darkest:{lightness:20,chroma:.061,hue:72.7}}},{id:"orange",name:"Orange",colors:{lightest:{lightness:95,chroma:.06,hue:82},mid:{lightness:73,chroma:.21,hue:56},darkest:{lightness:46,chroma:.2,hue:35}}},{id:"yellow",name:"Yellow",colors:{lightest:{lightness:97,chroma:.02,hue:106},mid:{lightness:89,chroma:.21,hue:99},darkest:{lightness:67,chroma:.43,hue:59}}},{id:"lime",name:"Lime",colors:{mid:{lightness:65,chroma:.192,hue:134.3}}},{id:"green",name:"Green",colors:{mid:{lightness:64,chroma:.21,hue:144}}},{id:"teal",name:"Teal",colors:{mid:{lightness:65,chroma:.116,hue:192.6}}},{id:"cyan",name:"Cyan",colors:{lightest:{lightness:97,chroma:.11,hue:195},mid:{lightness:61,chroma:.11,hue:210},darkest:{lightness:42,chroma:.11,hue:210}}},{id:"blue",name:"Blue",colors:{lightest:{lightness:91,chroma:.22,hue:240},mid:{lightness:63,chroma:.22,hue:255},darkest:{lightness:38,chroma:.22,hue:252}}},{id:"indigo",name:"Indigo",colors:{lightest:{lightness:92.7,chroma:.036,hue:291},mid:{lightness:67,chroma:.285,hue:296},darkest:{lightness:28,chroma:.23,hue:278}}},{id:"purple",name:"Purple",colors:{mid:{lightness:67,chroma:.21,hue:299}}}];function Pn({lightness:e,chroma:n,hue:t}){return Fn(e,n,t)}function tf(e){let{mid:n,lightest:t,darkest:i}=e.colors;if(t&&i&&n)return{lightest:Pn(t),mid:Pn(n),darkest:Pn(i)};if(t&&i)return{lightest:Pn(t),darkest:Pn(i)};if(n)return Pn(n);throw new Error(`Color scale preset "${e.id}" is missing required anchors.`)}var Zt=null;function rf(){if(!Zt){Zt=Object.create(null);for(let e of nf)Zt[e.id]=tf(e)}return Zt}var Pa={red:"#d7170b",orange:"#fe8a2b",yellow:"#ffc02b",lime:"#63b215",green:"#21ba3a",teal:"#17cfcf",cyan:"#13a7ec",blue:"#0d80f2",indigo:"#63c",purple:"#a219e6",magenta:"#eb4799",brown:"#8c564b",olive:"#8a8f2a",midnight:"#2c4670",sky:"#d2dce9",black:"#000",white:"#ffffff",carbon:"#111111",charcoal:"#333333",slate:"#555555","dark-grey":"#666",graphite:"#777777",stone:"#999999",grey:"#A6A6A6","light-grey":"#d4d5d2",ash:"#E6E6E6",mist:"#F3F3F3",snow:"#FFFFFF"};function We(e,n){let t=e.trim().toLowerCase(),i=t.match(/^(.+?)\s*\/\s*(\d+(?:\.\d+)?)%?\s*$/);if(i){let l=We(i[1].trim(),n),c=Math.max(0,Math.min(100,parseFloat(i[2]))),f=Math.round(c/100*255);return l&4294967040|f}if(t.startsWith("#")){let l=t.substring(1),c,f,m,d=255;if(l.length===3)c=parseInt(l[0]+l[0],16),f=parseInt(l[1]+l[1],16),m=parseInt(l[2]+l[2],16);else if(l.length===6)c=parseInt(l.substring(0,2),16),f=parseInt(l.substring(2,4),16),m=parseInt(l.substring(4,6),16);else if(l.length===8)c=parseInt(l.substring(0,2),16),f=parseInt(l.substring(2,4),16),m=parseInt(l.substring(4,6),16),d=parseInt(l.substring(6,8),16);else return 0;return(c<<24|f<<16|m<<8|d)>>>0}let r=t.match(/^rgba?\s*\(\s*([^)]+)\s*\)$/);if(r){let l=r[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0])||0,f=parseFloat(l[1])||0,m=parseFloat(l[2])||0;l[0].includes("%")||l[1].includes("%")||l[2].includes("%")?(l[0].includes("%")&&(c=c/100*255),l[1].includes("%")&&(f=f/100*255),l[2].includes("%")&&(m=m/100*255)):c<=1&&f<=1&&m<=1&&(c=c*255,f=f*255,m=m*255),c=Math.round(Math.max(0,Math.min(255,c))),f=Math.round(Math.max(0,Math.min(255,f))),m=Math.round(Math.max(0,Math.min(255,m)));let d=255;if(l.length>=4){let b=parseFloat(l[3]);l[3].includes("%")?b=b/100:b>1&&(b=b/255),d=Math.round(Math.max(0,Math.min(255,b*255)))}return(c<<24|f<<16|m<<8|d)>>>0}let s=t.match(/^oklch\s*\(\s*([^)]+)\s*\)$/);if(s){let l=s[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0]);l[0].includes("%")?c=c/100:c<=1||(c=c/100);let f=parseFloat(l[1])||0,m=parseFloat(l[2])||0,d=1;l.length>=4&&(d=parseFloat(l[3]),l[3].includes("%")?d=d/100:d>1&&(d=d/255));let b=Fn(c*100,f,m),v=Math.round(d*255);return b&4294967040|v}let o=t.match(/^oklab\s*\(\s*([^)]+)\s*\)$/);if(o){let l=o[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0]);(l[0].includes("%")||c>1)&&(c=c/100);let f=parseFloat(l[1])||0,m=parseFloat(l[2])||0,d=1;l.length>=4&&(d=parseFloat(l[3]),l[3].includes("%")?d=d/100:d>1&&(d=d/255));let b=gr({L:c,a:f,b:m}),v=b.r,T=b.g,M=b.b,C=Math.round(d*255);return(v<<24|T<<16|M<<8|C)>>>0}let a=t.match(/^hsl\s*\(\s*([^)]+)\s*\)$/);if(a){let l=a[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0])||0,f=parseFloat(l[1])||0;l[1].includes("%")?f=f/100:f<=1||(f=f/100);let m=parseFloat(l[2])||0;l[2].includes("%")?m=m/100:m<=1||(m=m/100);let d=1;l.length>=4&&(d=parseFloat(l[3]),l[3].includes("%")?d=d/100:d>1&&(d=d/255));let{r:b,g:v,b:T}=Kt(c,f,m),M=Math.round(d*255);return(b<<24|v<<16|T<<8|M)>>>0}if(t==="transparent")return 0;let u=t.match(/^([a-z]+)-(\d+)$/);if(u){let l=rf()[u[1]];if(l){let c=ef(l,parseInt(u[2],10));return n?Qc(c):c}}return t in Pa?We(Pa[t]):(console.warn(`parseColor: unrecognized color "${e}"`),0)}function Qt(e,n){let t=Wt(e),i=Wt(n),r=.56,s=.57,o=.62,a=.65,u=.022,l=1.414,c=.1,f=5e-4,m=1.14,d=.027,b=1.14,v=.027;function T(L){return L>=u?L:L+(u-L)**l}function M(L){return(L<0?-1:1)*Math.pow(Math.abs(L),2.4)}let C=T(M(i.r/255)*.2126729+M(i.g/255)*.7151522+M(i.b/255)*.072175),F=T(M(t.r/255)*.2126729+M(t.g/255)*.7151522+M(t.b/255)*.072175),V,U;return Math.abs(F-C)<f?U=0:F>C?(V=F**r-C**s,U=V*m):(V=F**a-C**o,U=V*b),Math.abs(U)<c?0:U>0?U-v:U+d}function yr(e){let n,t,i;typeof e!="object"||!("bg"in e)?(n=Wt(e),t="#ffffff",i="#000000"):(n=e.bg,t=e.fg1,i=e.fg2);let r=Math.abs(Qt(t,n)),s=Math.abs(Qt(i,n));return r>=s?Da(t):Da(i)}function Ka(e,n){let t=e.L-n.L,i=e.a-n.a,r=e.b-n.b;return Math.sqrt(t*t+i*i+r*r)}var sf=["#4e79a7","#f28e2b","#59a14f","#e15759","#b07aa1","#9c755f","#ff9da7","#edc948","#76b7b2","#6b8fd6","#c07bc4"],of=["#78a6d9","#ffae54","#7ddc7a","#ff7a7a","#d29be0","#c49a84","#ffb3bf","#ffe066","#7fd6d0","#8fb4ff","#e199eb"],af=["#4e79a7","#f28e2b","#2ca58d","#d13a3c","#b07aa1","#9c755f","#ff9da7","#e3c13b","#5fb8b2","#6b8fd6","#c07bc4"],uf=["#8fb1d4","#f6b878","#8ecf86","#f08a8b","#d3a9cc","#c3a492","#ffc6cc","#f3e08a","#a8d8d4","#a9c0ea","#e0b4e4"],lf=["#78a6d9","#ffae54","#7ddc7a","#ff7a7a","#d29be0","#c49a84","#ffb3bf","#ffe066","#7fd6d0","#8fb4ff","#e199eb"],cf=["#2f6fb0","#ff7a00","#2fa23a","#e02f2f","#9b4db5","#7f4f38","#ff6f86","#f2c200","#2daaa3","#4c79e0","#b84ac6"],ff=["#4f93ff","#ff8c1a","#33c94a","#ff4f4f","#b86bff","#a86a4a","#ff7f9e","#ffd400","#2ec9c1","#6f9bff","#cc5bd9"],pf=["#5E81B5","#E19C24","#8FB131","#EB6235","#8778B3","#C56E1A","#5E9EC9","#B23A3A","#4C9F70","#C979B7"],mf=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],df=["#007AFF","#FF9500","#34C759","#FF3B30","#AF52DE","#FF2D55","#30B0C7","#5856D6","#A2845E","#32ADE6","#00C7BE"],hf=["#0A84FF","#FF9F0A","#30D158","#FF453A","#BF5AF2","#FF375F","#40C8E0","#5E5CE6","#AC8E68","#64D2FF","#00D1C1"],gf=["#fdfdfd","#1d1d1d","#ebce2b","#702c8c","#db6917","#96cde6","#ba1c30","#c0bd7f","#7f7e80","#5fa641","#d485b2","#4277b6","#df8461","#463397","#e1a11a","#91218c","#e8e948","#7e1510","#92ae31","#6f340d","#d32b1e","#2b3514"],bf=["#4148cc","#db3c80","#12b5b0","#ff8c14","#848aff","#78e16e","#1e78f0","#ebcd00","#beeb3c","#7828d2","#cd5f00","#00915f"],eu={tycho11:sf,"tycho-dark11":of,"tycho-robust11":af,"tycho-soft11":uf,"tycho-soft-dark11":lf,"tycho-bold11":cf,"tycho-bold-dark11":ff,tableau10:mf,kelly22:gf,mathematica10:pf,cupertino10:df,"cupertino-dark10":hf,spectrum12:bf},Fa=["#033198","#053399","#07359a","#09379b","#0b399c","#0c3b9c","#0e3d9d","#0f3f9e","#11409f","#1242a0","#1344a0","#1446a1","#1548a2","#164aa3","#174ca4","#184da4","#194fa5","#1951a6","#1a53a7","#1b54a8","#1b56a8","#1c58a9","#1d5aaa","#1d5bab","#1e5dab","#1e5fac","#1f60ad","#2062ae","#2064ae","#2166af","#2167b0","#2269b0","#226ab1","#236cb2","#236eb3","#246fb3","#2471b4","#2573b5","#2574b5","#2676b6","#2677b7","#2779b7","#287ab8","#287cb9","#297eb9","#297fba","#2a81bb","#2b82bb","#2b84bc","#2c85bd","#2d87bd","#2d88be","#2e8abf","#2f8cbf","#308dc0","#308fc1","#3190c1","#3292c2","#3394c3","#3495c3","#3597c4","#3698c5","#379ac5","#389cc6","#399dc7","#3a9fc7","#3ca1c8","#3da2c9","#3ea4c9","#40a6ca","#41a7cb","#43a9cb","#44abcc","#46accc","#47aecd","#49b0ce","#4bb2ce","#4db3cf","#4fb5d0","#51b7d0","#53b8d1","#55bad1","#57bcd2","#59bdd2","#5bbfd3","#5dc1d3","#60c3d4","#62c4d4","#64c6d5","#67c7d5","#69c9d5","#6ccbd6","#6eccd6","#71ced6","#74cfd6","#76d1d7","#79d2d7","#7bd4d7","#7ed5d7","#81d7d7","#83d8d7","#86d9d7","#89dad7","#8bdcd7","#8eddd7","#90ded7","#93dfd6","#95e0d6","#98e1d6","#9be2d5","#9de3d5","#9fe4d4","#a2e5d4","#a4e5d3","#a6e6d2","#a9e7d2","#abe7d1","#ade8d0","#afe8cf","#b1e9ce","#b3e9cd","#b5eacc","#b7eaca","#b9eac9","#bbeac8","#bdeac6","#beeac5","#c0eac3","#c1eac2","#c3eac0","#c4eabe","#c6eabc","#c7e9ba","#c8e9b8","#c9e9b6","#cbe8b4","#cce7b2","#cce7b0","#cde6ad","#cee5ab","#cfe5a8","#d0e4a6","#d0e3a3","#d1e2a1","#d1e19e","#d1df9b","#d2de98","#d2dd96","#d2dc93","#d2da90","#d2d98d","#d2d78a","#d2d687","#d2d484","#d2d381","#d2d17e","#d1cf7b","#d1cd78","#d0cc75","#d0ca72","#cfc86f","#cfc66d","#cec46a","#cec267","#cdc064","#ccbe62","#cbbc5f","#cbba5d","#cab85a","#c9b658","#c8b455","#c7b253","#c7b051","#c6ae4f","#c5ac4c","#c4aa4a","#c3a848","#c2a647","#c1a545","#c1a343","#c0a141","#bf9f40","#be9d3e","#bd9b3c","#bc993b","#bb9739","#ba9538","#ba9437","#b99235","#b89034","#b78e33","#b68c32","#b58b31","#b58930","#b4872f","#b3862e","#b2842d","#b1822c","#b0802b","#b07f2a","#af7d29","#ae7c28","#ad7a27","#ad7826","#ac7726","#ab7525","#aa7324","#a97223","#a97023","#a86f22","#a76d21","#a66c20","#a66a20","#a5681f","#a4671e","#a3651e","#a2641d","#a2621c","#a1611c","#a05f1b","#9f5d1a","#9e5c19","#9e5a19","#9d5818","#9c5717","#9b5517","#9a5316","#995215","#995014","#984e14","#974d13","#964b12","#954912","#944711","#934610","#92440f","#91420f","#90400e","#903e0d","#8f3c0c","#8e3a0b","#8d380b","#8c360a","#8b3409","#8a3208","#883008","#872e07","#862c06","#852a06","#842705","#832504","#822204","#812003","#801d02","#7f1a01","#7e1700"],La=["#0b3c78","#2366a8","#4f97cf","#9bc7e4","#f7f7f7","#e88fa0","#c23c6f","#8e1d4d","#5a0c2e"],Oa=["#2c557f","#4a7fa8","#7aa8c9","#b5cfe3","#f7f7f7","#e4b0b0","#c96c72","#9b3d4f","#6b1a2b"],Ba=["#053061","#11458c","#1f5fa5","#337ab7","#4f94c6","#6baed6","#8bbdd9","#a6cce3","#c1dbec","#dceaf4","#f7f7f7","#fbe3d6","#f9c8b2","#f5a993","#ee8a75","#e36b58","#d64b41","#c72c33","#af212d","#971628","#7f0b23","#67001f"],Va=["#3b4cc0","#465ecf","#5070de","#5c82ea","#6f96f5","#86aafc","#9dbdff","#b6d0f3","#cfe1e8","#e6efe1","#f1f1f1","#f7f7f7","#f6e1d3","#f4cbb3","#f1b594","#ee9f76","#ea8960","#e06b53","#d24f49","#c1363f","#ae2036","#b40426"],ut=e=>e.slice().reverse(),nu={roma:Fa,"roma-reversed":ut(Fa),vik:La,"vik-reversed":ut(La),broc:Oa,"broc-reversed":ut(Oa),rdbu:Ba,"rdbu-reversed":ut(Ba),coolwarm:Va,"coolwarm-reversed":ut(Va)},Ja=["#30123b","#321543","#33184a","#341b51","#351e58","#36215f","#372466","#38276d","#392a73","#3a2d79","#3b2f80","#3c3286","#3d358b","#3e3891","#3f3b97","#3f3e9c","#4040a2","#4143a7","#4146ac","#4249b1","#424bb5","#434eba","#4451bf","#4454c3","#4456c7","#4559cb","#455ccf","#455ed3","#4661d6","#4664da","#4666dd","#4669e0","#466be3","#476ee6","#4771e9","#4773eb","#4776ee","#4778f0","#477bf2","#467df4","#4680f6","#4682f8","#4685fa","#4687fb","#458afc","#458cfd","#448ffe","#4391fe","#4294ff","#4196ff","#4099ff","#3e9bfe","#3d9efe","#3ba0fd","#3aa3fc","#38a5fb","#37a8fa","#35abf8","#33adf7","#31aff5","#2fb2f4","#2eb4f2","#2cb7f0","#2ab9ee","#28bceb","#27bee9","#25c0e7","#23c3e4","#22c5e2","#20c7df","#1fc9dd","#1ecbda","#1ccdd8","#1bd0d5","#1ad2d2","#1ad4d0","#19d5cd","#18d7ca","#18d9c8","#18dbc5","#18ddc2","#18dec0","#18e0bd","#19e2bb","#19e3b9","#1ae4b6","#1ce6b4","#1de7b2","#1fe9af","#20eaac","#22ebaa","#25eca7","#27eea4","#2aefa1","#2cf09e","#2ff19b","#32f298","#35f394","#38f491","#3cf58e","#3ff68a","#43f787","#46f884","#4af880","#4ef97d","#52fa7a","#55fa76","#59fb73","#5dfc6f","#61fc6c","#65fd69","#69fd66","#6dfe62","#71fe5f","#75fe5c","#79fe59","#7dff56","#80ff53","#84ff51","#88ff4e","#8bff4b","#8fff49","#92ff47","#96fe44","#99fe42","#9cfe40","#9ffd3f","#a1fd3d","#a4fc3c","#a7fc3a","#a9fb39","#acfb38","#affa37","#b1f936","#b4f836","#b7f735","#b9f635","#bcf534","#bef434","#c1f334","#c3f134","#c6f034","#c8ef34","#cbed34","#cdec34","#d0ea34","#d2e935","#d4e735","#d7e535","#d9e436","#dbe236","#dde037","#dfdf37","#e1dd37","#e3db38","#e5d938","#e7d739","#e9d539","#ebd339","#ecd13a","#eecf3a","#efcd3a","#f1cb3a","#f2c93a","#f4c73a","#f5c53a","#f6c33a","#f7c13a","#f8be39","#f9bc39","#faba39","#fbb838","#fbb637","#fcb336","#fcb136","#fdae35","#fdac34","#fea933","#fea732","#fea431","#fea130","#fe9e2f","#fe9b2d","#fe992c","#fe962b","#fe932a","#fe9029","#fd8d27","#fd8a26","#fc8725","#fc8423","#fb8122","#fb7e21","#fa7b1f","#f9781e","#f9751d","#f8721c","#f76f1a","#f66c19","#f56918","#f46617","#f36315","#f26014","#f15d13","#f05b12","#ef5811","#ed5510","#ec530f","#eb500e","#ea4e0d","#e84b0c","#e7490c","#e5470b","#e4450a","#e2430a","#e14109","#df3f08","#dd3d08","#dc3b07","#da3907","#d83706","#d63506","#d43305","#d23105","#d02f05","#ce2d04","#cc2b04","#ca2a04","#c82803","#c52603","#c32503","#c12302","#be2102","#bc2002","#b91e02","#b71d02","#b41b01","#b21a01","#af1801","#ac1701","#a91601","#a71401","#a41301","#a11201","#9e1001","#9b0f01","#980e01","#950d01","#920b01","#8e0a01","#8b0902","#880802","#850702","#810602","#7e0502","#7a0403"],qa=["#000004","#010005","#010106","#010108","#020109","#02020b","#02020d","#03030f","#030312","#040414","#050416","#060518","#06051a","#07061c","#08071e","#090720","#0a0822","#0b0924","#0c0926","#0d0a29","#0e0b2b","#100b2d","#110c2f","#120d31","#130d34","#140e36","#150e38","#160f3b","#180f3d","#19103f","#1a1042","#1c1044","#1d1147","#1e1149","#20114b","#21114e","#221150","#241253","#251255","#271258","#29115a","#2a115c","#2c115f","#2d1161","#2f1163","#311165","#331067","#341069","#36106b","#38106c","#390f6e","#3b0f70","#3d0f71","#3f0f72","#400f74","#420f75","#440f76","#451077","#471078","#491078","#4a1079","#4c117a","#4e117b","#4f127b","#51127c","#52137c","#54137d","#56147d","#57157e","#59157e","#5a167e","#5c167f","#5d177f","#5f187f","#601880","#621980","#641a80","#651a80","#671b80","#681c81","#6a1c81","#6b1d81","#6d1d81","#6e1e81","#701f81","#721f81","#732081","#752181","#762181","#782281","#792282","#7b2382","#7c2382","#7e2482","#802582","#812581","#832681","#842681","#862781","#882781","#892881","#8b2981","#8c2981","#8e2a81","#902a81","#912b81","#932b80","#942c80","#962c80","#982d80","#992d80","#9b2e7f","#9c2e7f","#9e2f7f","#a02f7f","#a1307e","#a3307e","#a5317e","#a6317d","#a8327d","#aa337d","#ab337c","#ad347c","#ae347b","#b0357b","#b2357b","#b3367a","#b5367a","#b73779","#b83779","#ba3878","#bc3978","#bd3977","#bf3a77","#c03a76","#c23b75","#c43c75","#c53c74","#c73d73","#c83e73","#ca3e72","#cc3f71","#cd4071","#cf4070","#d0416f","#d2426f","#d3436e","#d5446d","#d6456c","#d8456c","#d9466b","#db476a","#dc4869","#de4968","#df4a68","#e04c67","#e24d66","#e34e65","#e44f64","#e55064","#e75263","#e85362","#e95462","#ea5661","#eb5760","#ec5860","#ed5a5f","#ee5b5e","#ef5d5e","#f05f5e","#f1605d","#f2625d","#f2645c","#f3655c","#f4675c","#f4695c","#f56b5c","#f66c5c","#f66e5c","#f7705c","#f7725c","#f8745c","#f8765c","#f9785d","#f9795d","#f97b5d","#fa7d5e","#fa7f5e","#fa815f","#fb835f","#fb8560","#fb8761","#fc8961","#fc8a62","#fc8c63","#fc8e64","#fc9065","#fd9266","#fd9467","#fd9668","#fd9869","#fd9a6a","#fd9b6b","#fe9d6c","#fe9f6d","#fea16e","#fea36f","#fea571","#fea772","#fea973","#feaa74","#feac76","#feae77","#feb078","#feb27a","#feb47b","#feb67c","#feb77e","#feb97f","#febb81","#febd82","#febf84","#fec185","#fec287","#fec488","#fec68a","#fec88c","#feca8d","#fecc8f","#fecd90","#fecf92","#fed194","#fed395","#fed597","#fed799","#fed89a","#fdda9c","#fddc9e","#fddea0","#fde0a1","#fde2a3","#fde3a5","#fde5a7","#fde7a9","#fde9aa","#fdebac","#fcecae","#fceeb0","#fcf0b2","#fcf2b4","#fcf4b6","#fcf6b8","#fcf7b9","#fcf9bb","#fcfbbd","#fcfdbf"],za=["#000004","#010005","#010106","#010108","#02010a","#02020c","#02020e","#030210","#040312","#040314","#050417","#060419","#07051b","#08051d","#09061f","#0a0722","#0b0724","#0c0826","#0d0829","#0e092b","#10092d","#110a30","#120a32","#140b34","#150b37","#160b39","#180c3c","#190c3e","#1b0c41","#1c0c43","#1e0c45","#1f0c48","#210c4a","#230c4c","#240c4f","#260c51","#280b53","#290b55","#2b0b57","#2d0b59","#2f0a5b","#310a5c","#320a5e","#340a5f","#360961","#380962","#390963","#3b0964","#3d0965","#3e0966","#400a67","#420a68","#440a68","#450a69","#470b6a","#490b6a","#4a0c6b","#4c0c6b","#4d0d6c","#4f0d6c","#510e6c","#520e6d","#540f6d","#550f6d","#57106e","#59106e","#5a116e","#5c126e","#5d126e","#5f136e","#61136e","#62146e","#64156e","#65156e","#67166e","#69166e","#6a176e","#6c186e","#6d186e","#6f196e","#71196e","#721a6e","#741a6e","#751b6e","#771c6d","#781c6d","#7a1d6d","#7c1d6d","#7d1e6d","#7f1e6c","#801f6c","#82206c","#84206b","#85216b","#87216b","#88226a","#8a226a","#8c2369","#8d2369","#8f2469","#902568","#922568","#932667","#952667","#972766","#982766","#9a2865","#9b2964","#9d2964","#9f2a63","#a02a63","#a22b62","#a32c61","#a52c60","#a62d60","#a82e5f","#a92e5e","#ab2f5e","#ad305d","#ae305c","#b0315b","#b1325a","#b3325a","#b43359","#b63458","#b73557","#b93556","#ba3655","#bc3754","#bd3853","#bf3952","#c03a51","#c13a50","#c33b4f","#c43c4e","#c63d4d","#c73e4c","#c83f4b","#ca404a","#cb4149","#cc4248","#ce4347","#cf4446","#d04545","#d24644","#d34743","#d44842","#d54a41","#d74b3f","#d84c3e","#d94d3d","#da4e3c","#db503b","#dd513a","#de5238","#df5337","#e05536","#e15635","#e25734","#e35933","#e45a31","#e55c30","#e65d2f","#e75e2e","#e8602d","#e9612b","#ea632a","#eb6429","#eb6628","#ec6726","#ed6925","#ee6a24","#ef6c23","#ef6e21","#f06f20","#f1711f","#f1731d","#f2741c","#f3761b","#f37819","#f47918","#f57b17","#f57d15","#f67e14","#f68013","#f78212","#f78410","#f8850f","#f8870e","#f8890c","#f98b0b","#f98c0a","#f98e09","#fa9008","#fa9207","#fa9407","#fb9606","#fb9706","#fb9906","#fb9b06","#fb9d07","#fc9f07","#fca108","#fca309","#fca50a","#fca60c","#fca80d","#fcaa0f","#fcac11","#fcae12","#fcb014","#fcb216","#fcb418","#fbb61a","#fbb81d","#fbba1f","#fbbc21","#fbbe23","#fac026","#fac228","#fac42a","#fac62d","#f9c72f","#f9c932","#f9cb35","#f8cd37","#f8cf3a","#f7d13d","#f7d340","#f6d543","#f6d746","#f5d949","#f5db4c","#f4dd4f","#f4df53","#f4e156","#f3e35a","#f3e55d","#f2e661","#f2e865","#f2ea69","#f1ec6d","#f1ed71","#f1ef75","#f1f179","#f2f27d","#f2f482","#f3f586","#f3f68a","#f4f88e","#f5f992","#f6fa96","#f8fb9a","#f9fc9d","#fafda1","#fcffa4"],Ga=["#0d0887","#100788","#130789","#16078a","#19068c","#1b068d","#1d068e","#20068f","#220690","#240691","#260591","#280592","#2a0593","#2c0594","#2e0595","#2f0596","#310597","#330597","#350498","#370499","#38049a","#3a049a","#3c049b","#3e049c","#3f049c","#41049d","#43039e","#44039e","#46039f","#48039f","#4903a0","#4b03a1","#4c02a1","#4e02a2","#5002a2","#5102a3","#5302a3","#5502a4","#5601a4","#5801a4","#5901a5","#5b01a5","#5c01a6","#5e01a6","#6001a6","#6100a7","#6300a7","#6400a7","#6600a7","#6700a8","#6900a8","#6a00a8","#6c00a8","#6e00a8","#6f00a8","#7100a8","#7201a8","#7401a8","#7501a8","#7701a8","#7801a8","#7a02a8","#7b02a8","#7d03a8","#7e03a8","#8004a8","#8104a7","#8305a7","#8405a7","#8606a6","#8707a6","#8808a6","#8a09a5","#8b0aa5","#8d0ba5","#8e0ca4","#8f0da4","#910ea3","#920fa3","#9410a2","#9511a1","#9613a1","#9814a0","#99159f","#9a169f","#9c179e","#9d189d","#9e199d","#a01a9c","#a11b9b","#a21d9a","#a31e9a","#a51f99","#a62098","#a72197","#a82296","#aa2395","#ab2494","#ac2694","#ad2793","#ae2892","#b02991","#b12a90","#b22b8f","#b32c8e","#b42e8d","#b52f8c","#b6308b","#b7318a","#b83289","#ba3388","#bb3488","#bc3587","#bd3786","#be3885","#bf3984","#c03a83","#c13b82","#c23c81","#c33d80","#c43e7f","#c5407e","#c6417d","#c7427c","#c8437b","#c9447a","#ca457a","#cb4679","#cc4778","#cc4977","#cd4a76","#ce4b75","#cf4c74","#d04d73","#d14e72","#d24f71","#d35171","#d45270","#d5536f","#d5546e","#d6556d","#d7566c","#d8576b","#d9586a","#da5a6a","#da5b69","#db5c68","#dc5d67","#dd5e66","#de5f65","#de6164","#df6263","#e06363","#e16462","#e26561","#e26660","#e3685f","#e4695e","#e56a5d","#e56b5d","#e66c5c","#e76e5b","#e76f5a","#e87059","#e97158","#e97257","#ea7457","#eb7556","#eb7655","#ec7754","#ed7953","#ed7a52","#ee7b51","#ef7c51","#ef7e50","#f07f4f","#f0804e","#f1814d","#f1834c","#f2844b","#f3854b","#f3874a","#f48849","#f48948","#f58b47","#f58c46","#f68d45","#f68f44","#f79044","#f79143","#f79342","#f89441","#f89540","#f9973f","#f9983e","#f99a3e","#fa9b3d","#fa9c3c","#fa9e3b","#fb9f3a","#fba139","#fba238","#fca338","#fca537","#fca636","#fca835","#fca934","#fdab33","#fdac33","#fdae32","#fdaf31","#fdb130","#fdb22f","#fdb42f","#fdb52e","#feb72d","#feb82c","#feba2c","#febb2b","#febd2a","#febe2a","#fec029","#fdc229","#fdc328","#fdc527","#fdc627","#fdc827","#fdca26","#fdcb26","#fccd25","#fcce25","#fcd025","#fcd225","#fbd324","#fbd524","#fbd724","#fad824","#fada24","#f9dc24","#f9dd25","#f8df25","#f8e125","#f7e225","#f7e425","#f6e626","#f6e826","#f5e926","#f5eb27","#f4ed27","#f3ee27","#f3f027","#f2f227","#f1f426","#f1f525","#f0f724","#f0f921"],ja=["#440154","#440256","#450457","#450559","#46075a","#46085c","#460a5d","#460b5e","#470d60","#470e61","#471063","#471164","#471365","#481467","#481668","#481769","#48186a","#481a6c","#481b6d","#481c6e","#481d6f","#481f70","#482071","#482173","#482374","#482475","#482576","#482677","#482878","#482979","#472a7a","#472c7a","#472d7b","#472e7c","#472f7d","#46307e","#46327e","#46337f","#463480","#453581","#453781","#453882","#443983","#443a83","#443b84","#433d84","#433e85","#423f85","#424086","#424186","#414287","#414487","#404588","#404688","#3f4788","#3f4889","#3e4989","#3e4a89","#3e4c8a","#3d4d8a","#3d4e8a","#3c4f8a","#3c508b","#3b518b","#3b528b","#3a538b","#3a548c","#39558c","#39568c","#38588c","#38598c","#375a8c","#375b8d","#365c8d","#365d8d","#355e8d","#355f8d","#34608d","#34618d","#33628d","#33638d","#32648e","#32658e","#31668e","#31678e","#31688e","#30698e","#306a8e","#2f6b8e","#2f6c8e","#2e6d8e","#2e6e8e","#2e6f8e","#2d708e","#2d718e","#2c718e","#2c728e","#2c738e","#2b748e","#2b758e","#2a768e","#2a778e","#2a788e","#29798e","#297a8e","#297b8e","#287c8e","#287d8e","#277e8e","#277f8e","#27808e","#26818e","#26828e","#26828e","#25838e","#25848e","#25858e","#24868e","#24878e","#23888e","#23898e","#238a8d","#228b8d","#228c8d","#228d8d","#218e8d","#218f8d","#21908d","#21918c","#20928c","#20928c","#20938c","#1f948c","#1f958b","#1f968b","#1f978b","#1f988b","#1f998a","#1f9a8a","#1e9b8a","#1e9c89","#1e9d89","#1f9e89","#1f9f88","#1fa088","#1fa188","#1fa187","#1fa287","#20a386","#20a486","#21a585","#21a685","#22a785","#22a884","#23a983","#24aa83","#25ab82","#25ac82","#26ad81","#27ad81","#28ae80","#29af7f","#2ab07f","#2cb17e","#2db27d","#2eb37c","#2fb47c","#31b57b","#32b67a","#34b679","#35b779","#37b878","#38b977","#3aba76","#3bbb75","#3dbc74","#3fbc73","#40bd72","#42be71","#44bf70","#46c06f","#48c16e","#4ac16d","#4cc26c","#4ec36b","#50c46a","#52c569","#54c568","#56c667","#58c765","#5ac864","#5cc863","#5ec962","#60ca60","#63cb5f","#65cb5e","#67cc5c","#69cd5b","#6ccd5a","#6ece58","#70cf57","#73d056","#75d054","#77d153","#7ad151","#7cd250","#7fd34e","#81d34d","#84d44b","#86d549","#89d548","#8bd646","#8ed645","#90d743","#93d741","#95d840","#98d83e","#9bd93c","#9dd93b","#a0da39","#a2da37","#a5db36","#a8db34","#aadc32","#addc30","#b0dd2f","#b2dd2d","#b5de2b","#b8de29","#bade28","#bddf26","#c0df25","#c2df23","#c5e021","#c8e020","#cae11f","#cde11d","#d0e11c","#d2e21b","#d5e21a","#d8e219","#dae319","#dde318","#dfe318","#e2e418","#e5e419","#e7e419","#eae51a","#ece51b","#efe51c","#f1e51d","#f4e61e","#f6e620","#f8e621","#fbe723","#fde725"],Ua=["#00204d","#00214e","#002250","#002252","#002353","#002455","#002557","#002558","#00265a","#00275c","#00275e","#002860","#002961","#002a63","#002a65","#002b67","#002c69","#002c6a","#002d6c","#002e6e","#002e6f","#002f6f","#002f6f","#00306f","#00306f","#00316f","#00326f","#00336f","#00336f","#00346f","#00356e","#01366e","#06366e","#0b376e","#0f386e","#12386d","#15396d","#183a6d","#1a3b6d","#1d3b6d","#1f3c6d","#213d6d","#233e6c","#243e6c","#263f6c","#28406c","#2a406c","#2b416c","#2d426c","#2e436c","#30436c","#31446b","#32456b","#34456b","#35466b","#36476b","#38486b","#39486b","#3a496b","#3b4a6b","#3d4a6b","#3e4b6b","#3f4c6b","#404d6b","#414d6b","#424e6b","#434f6b","#444f6b","#46506b","#47516b","#48526b","#49526b","#4a536b","#4b546c","#4c546c","#4d556c","#4e566c","#4f576c","#50576c","#51586c","#52596c","#53596c","#545a6c","#555b6d","#565c6d","#575c6d","#585d6d","#595e6d","#595f6d","#5a5f6d","#5b606e","#5c616e","#5d616e","#5e626e","#5f636e","#60646f","#61646f","#62656f","#63666f","#64666f","#646770","#656870","#666970","#676970","#686a71","#696b71","#6a6c71","#6b6c71","#6c6d72","#6c6e72","#6d6e72","#6e6f73","#6f7073","#707173","#717174","#727274","#727374","#737475","#747475","#757575","#767676","#777776","#787777","#787877","#797977","#7a7a78","#7b7a78","#7c7b78","#7d7c78","#7e7d78","#7f7d78","#807e79","#817f79","#828079","#838079","#848179","#848279","#858379","#868379","#878479","#888579","#898679","#8a8779","#8b8779","#8c8879","#8d8979","#8e8a79","#8f8a79","#908b79","#918c78","#928d78","#938e78","#948e78","#958f78","#969078","#979178","#989278","#999278","#9a9377","#9b9477","#9c9577","#9d9677","#9e9677","#9f9777","#a09877","#a19976","#a29a76","#a39a76","#a49b76","#a59c76","#a69d75","#a89e75","#a99f75","#aa9f75","#aba074","#aca174","#ada274","#aea374","#afa473","#b0a473","#b1a573","#b2a672","#b3a772","#b4a872","#b5a971","#b6a971","#b7aa71","#b8ab70","#b9ac70","#baad70","#bbae6f","#bcaf6f","#beaf6f","#bfb06e","#c0b16e","#c1b26d","#c2b36d","#c3b46d","#c4b56c","#c5b56c","#c6b66b","#c7b76b","#c8b86a","#c9b96a","#cbba69","#ccbb69","#cdbc68","#cebc68","#cfbd67","#d0be67","#d1bf66","#d2c066","#d3c165","#d4c264","#d6c364","#d7c463","#d8c563","#d9c562","#dac661","#dbc761","#dcc860","#ddc95f","#deca5f","#e0cb5e","#e1cc5d","#e2cd5c","#e3ce5c","#e4cf5b","#e5d05a","#e6d159","#e8d259","#e9d358","#ead357","#ebd456","#ecd555","#edd654","#efd753","#f0d852","#f1d951","#f2da50","#f3db4f","#f4dc4e","#f6dd4d","#f7de4c","#f8df4b","#f9e04a","#fae149","#fbe248","#fde346","#fee445","#ffe544","#ffe642","#ffe742","#ffe843","#ffe944","#ffea46"],Ha=["#03051a","#04051a","#05061b","#06071c","#07071d","#08081e","#0a091f","#0b0920","#0d0a21","#0e0b22","#100b23","#110c24","#130d25","#140e26","#160e27","#170f28","#180f29","#1a102a","#1b112b","#1d112c","#1e122d","#20122e","#211330","#221331","#241432","#251433","#271534","#281535","#2a1636","#2b1637","#2d1738","#2e1739","#30173a","#31183b","#33183c","#34193d","#35193e","#37193f","#381a40","#3a1a41","#3c1a42","#3d1a42","#3f1b43","#401b44","#421b45","#431c46","#451c47","#461c48","#481c48","#491d49","#4b1d4a","#4c1d4b","#4e1d4b","#501d4c","#511e4d","#531e4d","#541e4e","#561e4f","#581e4f","#591e50","#5b1e51","#5c1e51","#5e1f52","#601f52","#611f53","#631f53","#641f54","#661f54","#681f55","#691f55","#6b1f56","#6d1f56","#6e1f57","#701f57","#711f57","#731f58","#751f58","#761f58","#781f59","#7a1f59","#7b1f59","#7d1f5a","#7f1e5a","#811e5a","#821e5a","#841e5a","#861e5b","#871e5b","#891e5b","#8b1d5b","#8c1d5b","#8e1d5b","#901d5b","#921c5b","#931c5b","#951c5b","#971c5b","#981b5b","#9a1b5b","#9c1b5b","#9e1a5b","#9f1a5b","#a11a5b","#a3195b","#a4195b","#a6195a","#a8185a","#aa185a","#ab185a","#ad1759","#af1759","#b01759","#b21758","#b41658","#b51657","#b71657","#b91657","#ba1656","#bc1656","#bd1655","#bf1654","#c11754","#c21753","#c41753","#c51852","#c71951","#c81951","#ca1a50","#cb1b4f","#cd1c4e","#ce1d4e","#cf1e4d","#d11f4c","#d2204c","#d3214b","#d5224a","#d62449","#d72549","#d82748","#d92847","#db2946","#dc2b46","#dd2c45","#de2e44","#df2f44","#e03143","#e13342","#e23442","#e33641","#e43841","#e53940","#e63b40","#e73d3f","#e83f3f","#e8403e","#e9423e","#ea443e","#eb463e","#eb483e","#ec4a3e","#ec4c3e","#ed4e3e","#ed503e","#ee523f","#ee543f","#ef5640","#ef5840","#ef5a41","#f05c42","#f05e42","#f06043","#f16244","#f16445","#f16646","#f26747","#f26948","#f26b49","#f26d4b","#f26f4c","#f3714d","#f3734e","#f37450","#f37651","#f37852","#f47a54","#f47c55","#f47d57","#f47f58","#f4815a","#f4835b","#f4845d","#f4865e","#f58860","#f58a61","#f58b63","#f58d64","#f58f66","#f59067","#f59269","#f5946b","#f5966c","#f5976e","#f59970","#f69b71","#f69c73","#f69e75","#f6a077","#f6a178","#f6a37a","#f6a47c","#f6a67e","#f6a880","#f6a981","#f6ab83","#f6ad85","#f6ae87","#f6b089","#f6b18b","#f6b38d","#f6b48f","#f6b691","#f6b893","#f6b995","#f6bb97","#f6bc99","#f6be9b","#f6bf9d","#f6c19f","#f7c2a2","#f7c4a4","#f7c6a6","#f7c7a8","#f7c9aa","#f7caac","#f7ccaf","#f7cdb1","#f7cfb3","#f7d0b5","#f8d1b8","#f8d3ba","#f8d4bc","#f8d6be","#f8d7c0","#f8d9c3","#f8dac5","#f8dcc7","#f9ddc9","#f9dfcb","#f9e0cd","#f9e2d0","#f9e3d2","#f9e5d4","#fae6d6","#fae8d8","#fae9da","#faebdd"],Za=["#0b0405","#0d0406","#0e0508","#0f0609","#10060a","#11070c","#12080d","#13090f","#140910","#150a12","#160b13","#170c15","#180d16","#190e18","#1a0e19","#1b0f1a","#1c101c","#1d111d","#1e111f","#1f1220","#201322","#211423","#221425","#231526","#241628","#251729","#26172b","#27182d","#28192e","#291930","#291a31","#2a1b33","#2b1c35","#2c1c36","#2d1d38","#2e1e39","#2e1e3b","#2f1f3d","#30203e","#312140","#312142","#322243","#332345","#342447","#342548","#35254a","#35264c","#36274d","#37284f","#372851","#382953","#382a54","#392b56","#3a2c58","#3a2c59","#3b2d5b","#3b2e5d","#3b2f5f","#3c3060","#3c3162","#3d3164","#3d3266","#3e3367","#3e3469","#3e356b","#3f366d","#3f366f","#3f3770","#403872","#403974","#403a76","#403b78","#403c79","#413d7b","#413e7d","#413e7f","#413f80","#414082","#414184","#414285","#414387","#414488","#40468a","#40478b","#40488d","#40498e","#3f4a8f","#3f4b90","#3f4c92","#3e4d93","#3e4f94","#3e5095","#3d5195","#3d5296","#3c5397","#3c5598","#3b5698","#3b5799","#3b589a","#3a599a","#3a5b9b","#3a5c9b","#395d9c","#395e9c","#385f9c","#38619d","#38629d","#38639d","#37649e","#37659e","#37669e","#37689f","#36699f","#366a9f","#366b9f","#366ca0","#366da0","#366fa0","#3670a0","#3671a0","#3572a1","#3573a1","#3574a1","#3575a1","#3576a2","#3578a2","#3579a2","#357aa2","#357ba3","#357ca3","#357da3","#357ea4","#347fa4","#3480a4","#3482a4","#3483a5","#3484a5","#3485a5","#3486a5","#3487a6","#3488a6","#3489a6","#348ba6","#348ca7","#348da7","#348ea7","#348fa7","#3490a8","#3491a8","#3492a8","#3493a8","#3495a9","#3496a9","#3497a9","#3498a9","#3499aa","#349aaa","#359baa","#359caa","#359eaa","#359fab","#35a0ab","#35a1ab","#36a2ab","#36a3ab","#36a4ab","#37a5ac","#37a6ac","#37a8ac","#38a9ac","#38aaac","#39abac","#39acac","#3aadac","#3aaead","#3bafad","#3cb1ad","#3cb2ad","#3db3ad","#3eb4ad","#3fb5ad","#3fb6ad","#40b7ad","#41b8ad","#42b9ad","#43baad","#44bcad","#45bdad","#46bead","#47bfad","#48c0ad","#49c1ad","#4bc2ad","#4cc3ad","#4dc4ad","#4fc5ad","#50c6ad","#52c7ad","#53c9ad","#55caad","#57cbad","#59ccad","#5bcdad","#5ecdad","#60ceac","#62cfac","#65d0ad","#68d1ad","#6ad2ad","#6dd3ad","#70d4ad","#73d4ad","#76d5ae","#79d6ae","#7cd6af","#7fd7af","#82d8b0","#85d9b1","#88d9b1","#8bdab2","#8edbb3","#91dbb4","#94dcb5","#96ddb5","#99ddb6","#9cdeb7","#9edfb8","#a1dfb9","#a4e0bb","#a6e1bc","#a9e1bd","#abe2be","#aee3c0","#b0e4c1","#b2e4c2","#b5e5c4","#b7e6c5","#b9e6c7","#bbe7c8","#bee8ca","#c0e9cc","#c2e9cd","#c4eacf","#c6ebd1","#c8ecd2","#caedd4","#ccedd6","#ceeed7","#d0efd9","#d2f0db","#d4f1dc","#d6f1de","#d8f2e0","#daf3e1","#dcf4e3","#def5e5"],Ya=["#000000","#111111","#222222","#333333","#444444","#555555","#666666","#777777","#888888","#999999","#aaaaaa","#bbbbbb","#cccccc","#dddddd","#eeeeee","#ffffff"],Wa=["#a8780d","#b3701b","#be6828","#c75f35","#cf5643","#d54b53","#db4066","#de357b","#df2a93","#dc25ad","#d529c4","#cc34d7","#c041e5","#b24fef","#a25cf3","#9168f4","#7d73f0","#687ce8","#5285dc","#3d8bcd","#2c90bc","#2093ac","#19959c","#12978c","#0c987c","#119a69","#249a52","#409839","#5e9420","#778d12","#8b860d","#9b7f0d"],De=e=>e.slice().reverse(),tu={turbo:Ja,"turbo-reversed":De(Ja),grey:Ya,"grey-reversed":De(Ya),magma:qa,"magma-reversed":De(qa),inferno:za,"inferno-reversed":De(za),plasma:Ga,"plasma-reversed":De(Ga),viridis:ja,"viridis-reversed":De(ja),cividis:Ua,"cividis-reversed":De(Ua),rocket:Ha,"rocket-reversed":De(Ha),mako:Za,"mako-reversed":De(Za),"cmocean-phase":Wa,"cmocean-phase-reversed":De(Wa)};var iu=7,ru=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23];function ke(e){if(e<0)return NaN;let n=Math.PI,t=e*e*e;return e*Math.log(e)-e-.5*Math.log(e)+.5*Math.log(2*n)+1/(12*e)-1/(360*t)+1/(1260*t*e*e)}function ie(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*ie(1-e));if(e>100)return Math.exp(ke(e));e-=1;let n=ru[0];for(let i=1;i<iu+2;i++)n+=ru[i]/(e+i);let t=e+iu+.5;return Math.sqrt(2*Math.PI)*Math.pow(t,e+.5)*Math.exp(-t)*n}function su(e){let n=Math.PI,t=n*n,i=t*n,r=e*e,s=e*r,o=s*r,a=o*r;return Math.sqrt(n)/2*(e+n/12*s+7*t/480*o+127*i/40320*a+4369*t*t/5806080*a*r+34807*i*t/182476800*a*r*r)}function ct(e){return 1-Bn(e)}function Bn(e){let n=.254829592,t=-.284496736,i=1.421413741,r=-1.453152027,s=1.061405429,o=.3275911,a=e<0?-1:1;e=Math.abs(e);let u=1/(1+o*e),l=((((s*u+r)*u+i)*u+t)*u+n)*u;return a*(1-l*Math.exp(-e*e))}var ti=.5772156649015329,On=[1/6,-1/30,1/42,-1/30,5/66,-691/2730,7/6,-3617/510,43867/798,-174611/330];function ri(e){if(!isFinite(e))return NaN;if(e<0)return Number.isInteger(e)?NaN:ri(1-e)-Math.PI/Math.tan(Math.PI*e);if(e===0)return NaN;let n=0,t=e;for(;t<7;)n-=1/t,t+=1;n+=Math.log(t)-1/(2*t);let i=t*t;for(let r=0;r<On.length;r++)n-=On[r]/(2*(r+1)*i),i*=t*t;return n}function si(e){if(!isFinite(e))return NaN;if(e<0){if(Number.isInteger(e))return NaN;let r=Math.sin(Math.PI*e);return Math.PI*Math.PI/(r*r)-si(1-e)}if(e===0)return NaN;let n=0,t=e;for(;t<7;)n+=1/(t*t),t+=1;n+=1/t+1/(2*t*t);let i=t*t*t;for(let r=0;r<On.length;r++)n+=On[r]/i,i*=t*t;return n}function xr(e,n){if(!Number.isInteger(e)||e<0)return NaN;if(e===0)return ri(n);if(e===1)return si(n);if(!isFinite(n)||n===0)return NaN;if(n<0){if(Number.isInteger(n))return NaN;let a=0,u=n,l=e%2===0?1:-1;for(;u<1;)a+=l*Ln(e)/Math.pow(u,e+1),u+=1;return a+xr(e,u)}let t=0,i=n,r=e%2===0?-1:1;for(;i<7;)t+=r*Ln(e)/Math.pow(i,e+1),i+=1;let s=e%2===0?-1:1;t+=s*Ln(e-1)/Math.pow(i,e),t+=s*Ln(e)/(2*Math.pow(i,e+1));let o=Math.pow(i,e+2);for(let a=0;a<Math.min(On.length,6);a++){let u=2*(a+1),l=1;for(let c=0;c<u;c++)l*=e+c;t+=s*On[a]*l/(Ln(u)*o),o*=i*i}return t}function Ln(e){if(e<=1)return 1;let n=1;for(let t=2;t<=e;t++)n*=t;return n}function ou(e,n){return e>100||n>100||e+n>100?Math.exp(ke(e)+ke(n)-ke(e+n)):ie(e)*ie(n)/ie(e+n)}function vr(e){if(!isFinite(e))return NaN;if(e===1)return 1/0;if(e===0)return-.5;if(e===2)return Math.PI*Math.PI/6;if(e===4)return Math.PI**4/90;if(e===6)return Math.PI**6/945;if(e===8)return Math.PI**8/9450;if(e<0)return Math.pow(2,e)*Math.pow(Math.PI,e-1)*Math.sin(Math.PI*e/2)*ie(1-e)*vr(1-e);let n=22,t=yf(n),i=t[n],r=0;for(let s=0;s<=n;s++)r+=(s%2===0?1:-1)*(t[s]-i)/Math.pow(s+1,e);return-1/(i*(1-Math.pow(2,1-e)))*r}function yf(e){let n=new Array(e+1);n[0]=1;for(let t=1;t<=e;t++)n[t]=n[t-1]+xf(e,t);return n}function xf(e,n){n>e-n&&(n=e-n);let t=1;for(let i=0;i<n;i++)t=t*(e-i)/(i+1);return t}function au(e){if(!isFinite(e))return e;if(e===0)return 0;let n=1/Math.E;if(e<-n)return NaN;if(Math.abs(e+n)<1e-15)return-1;let t;if(e<0){let i=Math.sqrt(2*(Math.E*e+1));t=-1+i-i*i/3+11/72*i*i*i}else if(e<=1)t=e*(1-e*(1-1.5*e));else if(e<100){let i=Math.log(e);t=i-Math.log(i)}else{let i=Math.log(e),r=Math.log(i);t=i-r+r/i}for(let i=0;i<30;i++){let r=Math.exp(t),o=t*r-e,a=r*(t+1),u=r*(t+2),l=o/(a-o*u/(2*a));if(t-=l,Math.abs(l)<1e-15*(1+Math.abs(t)))break}return t}function rn(e,n){return!isFinite(n)||!Number.isInteger(e)?NaN:n===0?e===0?1:0:e<0?(e=-e,e%2===0?rn(e,n):-rn(e,n)):n<0?e%2===0?rn(e,-n):-rn(e,-n):n>25+e*e/2?Ef(e,n):n<5+e?vf(e,n):Nf(e,n)}function vf(e,n){let t=n/2,i=-(n*n)/4,r=1;for(let o=1;o<=e;o++)r/=o;let s=r;for(let o=1;o<=60&&(r*=i/(o*(e+o)),s+=r,!(Math.abs(r)<Math.abs(s)*1e-16));o++);return s*Math.pow(t,e)}function uu(e,n){let t=4*e*e,i=1,r=0,s=1,o=8*n;for(let a=1;a<=20;a++){s*=t-(2*a-1)*(2*a-1);let u=Ln(a)*Math.pow(o,a),l=s/u;if(a%2===1?r+=(a%4===1?1:-1)*l:i+=(a%4===2?-1:1)*l,Math.abs(l)<1e-15)break}return[i,r]}function Ef(e,n){let t=n-(e/2+.25)*Math.PI,[i,r]=uu(e,n);return Math.sqrt(2/(Math.PI*n))*(i*Math.cos(t)-r*Math.sin(t))}function Nf(e,n){let t=Math.max(e+20,Math.ceil(n)+30),i=0,r=1,s=new Array(t+1);s[t]=r;for(let u=t;u>=1;u--){let l=2*u/n*r-i;i=r,r=l,s[u-1]=r}let o=s[0];for(let u=2;u<=t;u+=2)o+=2*s[u];let a=1/o;return s[e]*a}function ii(e,n){if(!isFinite(n)||!Number.isInteger(e))return NaN;if(n<=0)return NaN;if(e<0)return e=-e,e%2===0?ii(e,n):-ii(e,n);if(n>12+e*e/4)return _f(e,n);let t=Tf(n);if(e===0)return t;let i=If(n);if(e===1)return i;let r=t,s=i;for(let o=1;o<e;o++){let a=2*o/n*s-r;r=s,s=a}return s}function Tf(e){let n=e/2,t=n*n,i=rn(0,e),r=0,s=1,o=0;for(let a=1;a<=60&&(o+=1/a,s*=-t/(a*a),r-=s*o,!(Math.abs(s*o)<Math.abs(r)*1e-16));a++);return 2/Math.PI*(i*(Math.log(n)+ti)+r)}function If(e){let n=e/2,t=n*n,i=rn(1,e),r=0,s=1,o=1;for(let a=0;a<=60;a++){a>0&&(o*=a,s*=t);let u=o*(a+1),l=0;for(let v=1;v<=a;v++)l+=1/v;let c=l+1/(a+1),f=-ti+l,m=-ti+c,b=(a%2===0?1:-1)*(f+m)*s/(o*u);if(r+=b,a>3&&Math.abs(b)<1e-16*Math.abs(r))break}return-2/(Math.PI*e)+2/Math.PI*Math.log(n)*i-n/Math.PI*r}function _f(e,n){let t=n-(e/2+.25)*Math.PI,[i,r]=uu(e,n);return Math.sqrt(2/(Math.PI*n))*(i*Math.sin(t)+r*Math.cos(t))}function hn(e,n){return!isFinite(n)||!Number.isInteger(e)?NaN:n===0?e===0?1:0:(e<0&&(e=-e),n<0?e%2===0?hn(e,-n):-hn(e,-n):n>40?Sf(e,n):kf(e,n))}function kf(e,n){let t=n/2,i=n*n/4,r=1;for(let o=1;o<=e;o++)r/=o;let s=r;for(let o=1;o<=80&&(r*=i/(o*(e+o)),s+=r,!(Math.abs(r)<Math.abs(s)*1e-16));o++);return s*Math.pow(t,e)}function Sf(e,n){let t=4*e*e,i=1,r=1;for(let s=1;s<=12;s++){let o=t-(2*s-1)*(2*s-1);if(i*=o/(s*8*n),r+=i,Math.abs(i)<1e-15)break}return Math.exp(n)/Math.sqrt(2*Math.PI*n)*r}function lu(e,n){if(!isFinite(n)||!Number.isInteger(e))return NaN;if(n<=0)return NaN;if(e<0&&(e=-e),n>40)return wf(e,n);let t=cu(n);if(e===0)return t;let i=Mf(n);if(e===1)return i;let r=t,s=i;for(let o=1;o<e;o++){let a=2*o/n*s+r;r=s,s=a}return s}function cu(e){let n=e/2,t=n*n,i=hn(0,e),r=0,s=1,o=0;for(let a=1;a<=60&&(o+=1/a,s*=t/(a*a),r+=s*o,!(Math.abs(s*o)<Math.abs(r)*1e-16&&a>3));a++);return-(Math.log(n)+ti)*i+r}function Mf(e){let n=hn(0,e),t=hn(1,e),i=cu(e);return(1/e-t*i)/n}function wf(e,n){let t=4*e*e,i=1,r=1;for(let s=1;s<=12;s++){let o=t-(2*s-1)*(2*s-1);if(i*=o/(s*8*n),r+=i,Math.abs(i)<1e-15)break}return Math.sqrt(Math.PI/(2*n))*Math.exp(-n)*r}function fu(e){if(!isFinite(e))return NaN;if(e>5){let a=.6666666666666666*Math.pow(e,1.5);return Af(e,a)}if(e<-5){let a=-e,u=2/3*Math.pow(a,1.5);return $f(a,u)}let n=1/(Math.pow(3,2/3)*ie(2/3)),t=1/(Math.pow(3,1/3)*ie(1/3)),i=1,r=e,s=1,o=e;for(let a=1;a<=80;a++){let u=3*a;if(s*=e*e*e/((u-1)*u),o*=e*e*e/(u*(u+1)),i+=s,r+=o,Math.abs(s)+Math.abs(o)<1e-16*(Math.abs(i)+Math.abs(r)))break}return n*i-t*r}function Af(e,n){let t=Math.pow(e,.25),i=1,r=1,s=[1,5/72,385/10368,85085/2239488,37182145/644972544];for(let o=1;o<s.length;o++)r=s[o]/Math.pow(n,o),i+=(o%2===0?1:-1)*r;return Math.exp(-n)/(2*Math.sqrt(Math.PI)*t)*i}function $f(e,n){let t=Math.pow(e,.25);return Math.sin(n+Math.PI/4)/(Math.sqrt(Math.PI)*t)}function pu(e){if(!isFinite(e))return NaN;if(e>5){let a=.6666666666666666*Math.pow(e,1.5);return Cf(e,a)}if(e<-5){let a=-e,u=2/3*Math.pow(a,1.5);return Rf(a,u)}let n=1/(Math.pow(3,2/3)*ie(2/3)),t=1/(Math.pow(3,1/3)*ie(1/3)),i=1,r=e,s=1,o=e;for(let a=1;a<=80;a++){let u=3*a;if(s*=e*e*e/((u-1)*u),o*=e*e*e/(u*(u+1)),i+=s,r+=o,Math.abs(s)+Math.abs(o)<1e-16*(Math.abs(i)+Math.abs(r)))break}return Math.sqrt(3)*(n*i+t*r)}function Cf(e,n){let t=Math.pow(e,.25),i=1,r=1,s=[1,5/72,385/10368,85085/2239488,37182145/644972544];for(let o=1;o<s.length;o++)r=s[o]/Math.pow(n,o),i+=r;return Math.exp(n)/(Math.sqrt(Math.PI)*t)*i}function Rf(e,n){let t=Math.pow(e,.25);return Math.cos(n+Math.PI/4)/(Math.sqrt(Math.PI)*t)}var Df=[-2991.8191940101983,708840.0452577386,-6297414862058625e-8,25489088057337637e-7,-4429795180596978e-5,3180162978765678e-4],Pf=[1,281.3762688899943,45584.78108065326,5173438887700964e-9,4193202458981112e-7,22441179564534092e-6,607366389490085e-3],Ff=[-49884311457357354e-24,9504280628298596e-21,-.0006451914356839651,.018884331939670384,-.20552590095501388,1],Lf=[399982968972496e-26,9154392157746574e-25,12500186247959882e-23,12226278902417902e-21,.0008680295429417843,.04121420907221998,1],mu=[.4215435550436775,.1434079197807589,.011522095507358577,.000345017939782574,46361374928786735e-22,3055689837902576e-23,10230451416490724e-26,17201074326816183e-29,13428327623306275e-32,3763297112699879e-35],du=[1,.7515863983533789,.11688892585919138,.0064405152650885865,.00015593440916415301,18462756734893055e-22,11269922476399903e-24,36014002958937136e-27,5887545336215784e-29,45200143407412973e-33,12544323709001127e-36],hu=[.5044420736433832,.1971028335255234,.018764858409257526,.0006840793809153931,11513882611188428e-21,9828524436884223e-23,44534441586175015e-26,10826804113902088e-28,1375554606332618e-30,8363544356306774e-34,18695871016278324e-38],gu=[1,1.4749575992512833,.33774898912002,.02536037414203388,.0008146791071843061,12754507566772912e-21,10431458965757199e-23,46068072851523205e-26,11027321506624028e-28,13879653125957886e-31,8391588162831187e-34,18695871016278324e-38];function Te(e,n){let t=n[0];for(let i=1;i<n.length;i++)t=t*e+n[i];return t}function gn(e){if(!isFinite(e))return e!==e?NaN:e>0?.5:-.5;let n=e<0?-1:1;if(e=Math.abs(e),e<1.6){let t=e*e,i=t*t;return n*e*t*Te(i,Df)/Te(i,Pf)}if(e<36){let t=e*e,i=Math.PI*t,r=1/(i*i),s=1-r*Te(r,mu)/Te(r,du),o=1/i*Te(r,hu)/Te(r,gu),a=Math.PI/2*t,u=Math.cos(a),l=Math.sin(a);return n*(.5-(s*u+o*l)/(Math.PI*e))}return n*.5}function bn(e){if(!isFinite(e))return e!==e?NaN:e>0?.5:-.5;let n=e<0?-1:1;if(e=Math.abs(e),e<1.6){let t=e*e,i=t*t;return n*e*Te(i,Ff)/Te(i,Lf)}if(e<36){let t=e*e,i=Math.PI*t,r=1/(i*i),s=1-r*Te(r,mu)/Te(r,du),o=1/i*Te(r,hu)/Te(r,gu),a=Math.PI/2*t,u=Math.cos(a),l=Math.sin(a);return n*(.5+(s*l-o*u)/(Math.PI*e))}return n*.5}function bu(e){return e===0?1:Math.sin(e)/e}var ft=[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1],[1,6,15,20,15,6,1],[1,7,21,35,35,21,7,1],[1,8,28,56,70,56,28,8,1]];function yn(e,n){for(;e>=ft.length;){let t=ft.length,i=[1],r=ft[t-1];for(let s=1;s<t;s++)i[s]=r[s-1]+r[s];i[t]=1,ft.push(i)}return ft[e][n]}function xu(e){let n=0,t=0;for(let i of e)n+=i,t++;return t===0?NaN:n/t}function xn(e){let n=[...e].sort((i,r)=>i-r),t=Math.floor(n.length/2);return n.length%2===0?(n[t-1]+n[t])/2:n[t]}function Er(e){let n=0,t=0,i=0;for(let r of e)n+=r,t+=r*r,i++;return i===0?NaN:(t-n*n/i)/(i-1)}function Nr(e){let n=0,t=0,i=0;for(let r of e)n+=r,t+=r*r,i++;return i===0?NaN:(t-n*n/i)/i}function vu(e){return Math.sqrt(Er(e))}function Eu(e){return Math.sqrt(Nr(e))}function Nu(e){let n=0,t=0,i=0,r=0;for(let o of e){let a=o;if(!Number.isFinite(a))return NaN;n+=a,t+=a*a,i+=a*a*a*a,r++}if(r===0)return NaN;let s=(t-n*n/r)/(r-1);return(i-4*n*t/r+6*n*n*n/r/r-3*n*n*n*n/r/r/r)/(s*s)}function Tu(e){let n=0,t=0,i=0,r=0;for(let a of e){let u=a;if(!Number.isFinite(u))return NaN;n+=u,t+=u*u,i+=u*u*u,r++}if(r===0)return NaN;let s=(t-n*n/r)/(r-1);return(i-t*n/r)/(r-1)/Math.pow(s,3/2)*Math.sqrt(r*1)}function Iu(e){let n={};for(let r of e)n[r]=(n[r]??0)+1;let t=0,i=NaN;for(let r in n){let s=n[r];s>t&&(t=s,i=+r)}return i}function _u(e){let n=[...e].sort((o,a)=>o-a),t=Math.floor(n.length/2),i=xn(n.slice(0,t)),r=xn(n),s=xn(n.slice(t));return[i,r,s]}function ku(e){let n=[...e].sort((s,o)=>s-o),t=Math.floor(n.length/2),i=n.slice(0,t),r=n.slice(t+1);return xn(r)-xn(i)}function zf(e,n){if(n===0)return{estimate:e,error:n};let t=Math.abs(n),i=Math.floor(Math.log10(t)),r=2,s=Math.pow(10,i-(r-1)),o=Math.round(n/s)*s,a=Math.max(0,-(i-(r-1)));return{estimate:Number(e.toFixed(a)),error:o}}function Su(e,n,t,i=1e5){let r=0,s=0;if(n===-1/0&&t===1/0)for(let d=0;d<i;d++){let b=Math.random(),v=Math.tan(Math.PI*(b-.5)),T=e(v)*Math.PI*(1+v*v);r+=T,s+=T*T}else if(n===-1/0)for(let d=0;d<i;d++){let b=Math.random(),v=t+Math.log(b),T=e(v)/b;r+=T,s+=T*T}else if(t===1/0)for(let d=0;d<i;d++){let b=Math.random(),v=n-Math.log(b),T=e(v)/b;r+=T,s+=T*T}else for(let d=0;d<i;d++){let b=e(n+Math.random()*(t-n));r+=b,s+=b*b}let o=r/i,a=(s-i*o*o)/(i-1),u=Math.sqrt(a/i),l=isFinite(n)&&isFinite(t)?t-n:1,c=o*l,f=u*l;return zf(c,f)}var Tr={Add:["+",11],Negate:["-",14],Subtract:["-",11],Multiply:["*",12],Divide:["/",13],Equal:["===",8],NotEqual:["!==",8],LessEqual:["<=",9],GreaterEqual:[">=",9],Less:["<",9],Greater:[">",9],And:["&&",4],Or:["||",3],Not:["!",14]},Ir={Abs:(e,n)=>g.isComplexValued(e[0])?`_SYS.cabs(${n(e[0])})`:g.isNonNegative(e[0])?n(e[0]):`Math.abs(${n(e[0])})`,Add:(e,n)=>{if(e.length===1)return n(e[0]);if(!e.some(o=>g.isComplexValued(o))){let o=e.map(X);if(o.every(u=>u!==void 0))return String(o.reduce((u,l)=>u+l,0));let a=e.filter(u=>X(u)!==0);return a.length===0?"0":a.length===1?n(a[0]):`(${a.map(u=>n(u)).join(" + ")})`}let i=e.map(o=>({code:n(o),isComplex:g.isComplexValued(o)})),r=i.map(o=>o.isComplex?`(${o.code}).re`:o.code),s=i.filter(o=>o.isComplex).map(o=>`(${o.code}).im`);return`({ re: ${r.join(" + ")}, im: ${s.join(" + ")} })`},Arccos:(e,n)=>g.isComplexValued(e[0])?`_SYS.cacos(${n(e[0])})`:`Math.acos(${n(e[0])})`,Arcosh:"Math.acosh",Arccot:([e],n)=>{if(e===null)throw new Error("Arccot: no argument");return g.isComplexValued(e)?`_SYS.cacot(${n(e)})`:`Math.atan(1 / (${n(e)}))`},Arcoth:([e],n)=>{if(e===null)throw new Error("Arcoth: no argument");return g.isComplexValued(e)?`_SYS.cacoth(${n(e)})`:`Math.atanh(1 / (${n(e)}))`},Arccsc:([e],n)=>{if(e===null)throw new Error("Arccsc: no argument");return g.isComplexValued(e)?`_SYS.cacsc(${n(e)})`:`Math.asin(1 / (${n(e)}))`},Arcsch:([e],n)=>{if(e===null)throw new Error("Arcsch: no argument");return g.isComplexValued(e)?`_SYS.cacsch(${n(e)})`:`Math.asinh(1 / (${n(e)}))`},Arcsec:([e],n)=>{if(e===null)throw new Error("Arcsec: no argument");return g.isComplexValued(e)?`_SYS.casec(${n(e)})`:`Math.acos(1 / (${n(e)}))`},Arsech:([e],n)=>{if(e===null)throw new Error("Arsech: no argument");return g.isComplexValued(e)?`_SYS.casech(${n(e)})`:`Math.acosh(1 / (${n(e)}))`},Arcsin:(e,n)=>g.isComplexValued(e[0])?`_SYS.casin(${n(e[0])})`:`Math.asin(${n(e[0])})`,Arsinh:"Math.asinh",Arctan:(e,n)=>g.isComplexValued(e[0])?`_SYS.catan(${n(e[0])})`:`Math.atan(${n(e[0])})`,Artanh:"Math.atanh",Ceil:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`Math.ceil(${n(e[0])})`,Chop:"_SYS.chop",Cos:(e,n)=>g.isComplexValued(e[0])?`_SYS.ccos(${n(e[0])})`:`Math.cos(${n(e[0])})`,Cosh:(e,n)=>g.isComplexValued(e[0])?`_SYS.ccosh(${n(e[0])})`:`Math.cosh(${n(e[0])})`,Cot:([e],n)=>{if(e===null)throw new Error("Cot: no argument");return g.isComplexValued(e)?`_SYS.ccot(${n(e)})`:g.inlineExpression("Math.cos(${x}) / Math.sin(${x})",n(e))},Coth:([e],n)=>{if(e===null)throw new Error("Coth: no argument");return g.isComplexValued(e)?`_SYS.ccoth(${n(e)})`:g.inlineExpression("(Math.cosh(${x}) / Math.sinh(${x}))",n(e))},Csc:([e],n)=>{if(e===null)throw new Error("Csc: no argument");return g.isComplexValued(e)?`_SYS.ccsc(${n(e)})`:`1 / Math.sin(${n(e)})`},Csch:([e],n)=>{if(e===null)throw new Error("Csch: no argument");return g.isComplexValued(e)?`_SYS.ccsch(${n(e)})`:`1 / Math.sinh(${n(e)})`},Exp:(e,n)=>g.isComplexValued(e[0])?`_SYS.cexp(${n(e[0])})`:`Math.exp(${n(e[0])})`,First:(e,n)=>`${n(e[0])}[0]`,Floor:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`Math.floor(${n(e[0])})`,Fract:([e],n)=>{if(e===null)throw new Error("Fract: no argument");return g.inlineExpression("${x} - Math.floor(${x})",n(e))},Gamma:"_SYS.gamma",GCD:"_SYS.gcd",Integrate:(e,n,t)=>Hf(e,n,t),LCM:"_SYS.lcm",Product:(e,n,t)=>wu("Product",e,n,t),Sum:(e,n,t)=>wu("Sum",e,n,t),Limit:(e,n)=>`_SYS.limit(${n(e[0])}, ${n(e[1])})`,Ln:(e,n)=>g.isComplexValued(e[0])?`_SYS.cln(${n(e[0])})`:`Math.log(${n(e[0])})`,List:(e,n)=>`[${e.map(t=>n(t)).join(", ")}]`,Matrix:(e,n)=>n(e[0]),Tuple:(e,n)=>`[${e.map(t=>n(t)).join(", ")}]`,Log:(e,n)=>e.length===1?`Math.log10(${n(e[0])})`:`(Math.log(${n(e[0])}) / Math.log(${n(e[1])}))`,GammaLn:"_SYS.lngamma",Lb:"Math.log2",Max:"Math.max",Mean:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.mean(${n(e[0])})`:`_SYS.mean([${e.map(t=>n(t)).join(", ")}])`,Median:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.median(${n(e[0])})`:`_SYS.median([${e.map(t=>n(t)).join(", ")}])`,Variance:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.variance(${n(e[0])})`:`_SYS.variance([${e.map(t=>n(t)).join(", ")}])`,PopulationVariance:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.populationVariance(${n(e[0])})`:`_SYS.populationVariance([${e.map(t=>n(t)).join(", ")}])`,StandardDeviation:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.standardDeviation(${n(e[0])})`:`_SYS.standardDeviation([${e.map(t=>n(t)).join(", ")}])`,PopulationStandardDeviation:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.populationStandardDeviation(${n(e[0])})`:`_SYS.populationStandardDeviation([${e.map(t=>n(t)).join(", ")}])`,Kurtosis:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.kurtosis(${n(e[0])})`:`_SYS.kurtosis([${e.map(t=>n(t)).join(", ")}])`,Skewness:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.skewness(${n(e[0])})`:`_SYS.skewness([${e.map(t=>n(t)).join(", ")}])`,Mode:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.mode(${n(e[0])})`:`_SYS.mode([${e.map(t=>n(t)).join(", ")}])`,Quartiles:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.quartiles(${n(e[0])})`:`_SYS.quartiles([${e.map(t=>n(t)).join(", ")}])`,InterquartileRange:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.interquartileRange(${n(e[0])})`:`_SYS.interquartileRange([${e.map(t=>n(t)).join(", ")}])`,Min:"Math.min",Power:(e,n)=>{let t=e[0],i=e[1];if(t===null)throw new Error("Power: no argument");if(g.isComplexValued(t)||g.isComplexValued(i))return`_SYS.cpow(${n(t)}, ${n(i)})`;let r=X(t),s=X(i);if(r!==void 0&&s!==void 0)return String(Math.pow(r,s));if(s===0)return"1";if(s===1)return n(t);if(s===2&&(k(t)||D(t))){let o=n(t);return`(${o} * ${o})`}return s===-1?`(1 / (${n(t)}))`:s===.5?`Math.sqrt(${n(t)})`:s===1/3?`Math.cbrt(${n(t)})`:s===-.5?`(1 / Math.sqrt(${n(t)}))`:`Math.pow(${n(t)}, ${n(i)})`},Range:(e,n)=>{if(e.length===0)return"[]";if(e.length===1)return`Array.from({length: ${n(e[0])}}, (_, i) => i)`;let t=n(e[0]),i=n(e[1]),r=e[2]?n(e[2]):"1";if(t===null)throw new Error("Range: no start");if(i===null&&(i=t,t="1"),r==="0")throw new Error("Range: step cannot be zero");if(parseFloat(r)===1){let s=parseFloat(i),o=parseFloat(t);return s!==null&&o!==null?s-o<50?`[${Array.from({length:s-o+1},(a,u)=>o+u).join(", ")}]`:`Array.from({length: ${s-o+1}
43
+ return ${d};
44
+ })()`}static isComplexValued(n){if(R(n))return n.im!==0;if(T(n)){if(n.symbol==="ImaginaryUnit")return!0;let t=n.type;return t?t.matches("complex")&&!t.matches("real"):!1}if(h(n)){let t=n.type;return t.matches("complex")&&!t.matches("real")?!0:t.matches("real")?!1:n.ops.some(i=>e.isComplexValued(i))}return!1}static isIntegerValued(n){if(R(n))return n.im===0&&Number.isInteger(n.re);let t=n.type;return t?t.matches("integer"):!1}static isNonNegative(n){return R(n)?n.im===0&&n.re>=0:n.isNonNegative===!0}static tempVar(){return`_${Math.random().toString(36).substring(4)}`}static inlineExpression(n,t){if(/^[\p{L}_][\p{L}\p{N}_]*$/u.test(t)||/^[0-9]+$/.test(t))return new Function("x",`return \`${n}\`;`)(t);{let r=e.tempVar();return new Function("x",`return \`(() => { const ${r} = \${x}; return ${n.replace(/\\\${x}/g,r)}; })()\`;`)(t)}}};function dt(e){return typeof e=="object"&&e!==null}function xu(e){return typeof e=="number"&&Number.isFinite(e)}function Uf(e){if(!dt(e))throw new Error("Invalid compile target: expected an object");if(typeof e.var!="function")throw new Error('Invalid compile target: missing required method "var()"');if(typeof e.string!="function")throw new Error('Invalid compile target: missing required method "string()"');if(typeof e.number!="function")throw new Error('Invalid compile target: missing required method "number()"');if(typeof e.ws!="function")throw new Error('Invalid compile target: missing required method "ws()"');if(typeof e.preamble!="string")throw new Error('Invalid compile target: "preamble" must be a string');if(!xu(e.indent))throw new Error('Invalid compile target: "indent" must be a finite number');if(e.operators!==void 0&&typeof e.operators!="function")throw new Error('Invalid compile target: "operators" must be a function');if(e.functions!==void 0&&typeof e.functions!="function")throw new Error('Invalid compile target: "functions" must be a function');if(e.language!==void 0&&typeof e.language!="string")throw new Error('Invalid compile target: "language" must be a string')}function Hf(e,n){if(n!==void 0&&(!Array.isArray(n)||n.length!==2||typeof n[0]!="string"||!xu(n[1])))throw new Error(`Invalid compilation option "operators.${e}": expected [string, number]`)}function Zf(e){if(e!==void 0&&typeof e!="function"){if(!dt(e)||Array.isArray(e))throw new Error('Invalid compilation option "operators": expected a function or a record');for(let[n,t]of Object.entries(e))Hf(n,t)}}function Yf(e){if(e!==void 0){if(!dt(e)||Array.isArray(e))throw new Error('Invalid compilation option "functions": expected a record');for(let[n,t]of Object.entries(e))if(typeof t!="string"&&typeof t!="function")throw new Error(`Invalid compilation option "functions.${n}": expected a string or function`)}}function Wf(e){if(e!==void 0){if(!dt(e)||Array.isArray(e))throw new Error('Invalid compilation option "vars": expected a record');for(let[n,t]of Object.entries(e))if(typeof t!="string")throw new Error(`Invalid compilation option "vars.${n}": expected a string`)}}function Xf(e){if(e!==void 0&&!Array.isArray(e))throw new Error('Invalid compilation option "imports": expected an array')}function vu(e){if(e!==void 0){if(!dt(e)||Array.isArray(e))throw new Error("Invalid compilation options: expected an object");if(e.to!==void 0&&typeof e.to!="string")throw new Error('Invalid compilation option "to": expected a string');if(e.target!==void 0&&Uf(e.target),Zf(e.operators),Yf(e.functions),Wf(e.vars),Xf(e.imports),e.preamble!==void 0&&typeof e.preamble!="string")throw new Error('Invalid compilation option "preamble": expected a string');if(e.fallback!==void 0&&typeof e.fallback!="boolean")throw new Error('Invalid compilation option "fallback": expected a boolean')}}function Eu(e,n){vu(n);try{if(n?.target){let r=b.compile(e,n.target);return{target:n.target.language??"custom",success:!0,code:r}}let t=n?.to??"javascript",i=e.engine.getCompilationTarget(t);if(!i)throw new Error(`Compilation target "${t}" is not registered. Available targets: ${e.engine.listCompilationTargets().join(", ")}`);return i.compile(e,{operators:n?.operators,functions:n?.functions,vars:n?.vars,imports:n?.imports,preamble:n?.preamble,realOnly:n?.realOnly})}catch(t){if(n?.fallback??!0){console.warn(`Compilation fallback for "${e.operator}" (target: ${n?.to??"javascript"}): ${t.message}`);let i=e.engine,r=n?.to??"javascript";return h(e,"Function")?{target:r,success:!1,code:"",calling:"lambda",run:((...a)=>i.function("Apply",[e,...a.map(u=>i.box(u))]).evaluate().re)}:{target:r,success:!1,code:"",calling:"expression",run:(o=>{i.pushScope();try{if(o&&typeof o=="object")for(let[a,u]of Object.entries(o))i.assign(a,u);return e.evaluate().re}finally{i.popScope()}})}}throw t}}function ae(e){let n=e.toString();return!n.includes(".")&&!n.includes("e")&&!n.includes("E")?`${n}.0`:n}function Q(e){if(!R(e)||e.im!==0)return;let n=e.re;if(isFinite(n))return n}var Qf=/^-?\d+(\.\d+)?$/;function on(e,n,t){let i=t==="+"?0:1,r=null,s=[];for(let o of e)if(Qf.test(o)){let a=parseFloat(o);if(t==="*"&&a===0)return"0.0";r===null?r=a:r=t==="+"?r+a:r*a}else s.push(o);return r!==null&&r!==i&&s.unshift(ae(r)),s.length===0?r!==null?ae(r):n:s.length===1?s[0]:s.join(t==="+"?" + ":" * ")}function ri(e,n){return h(e,"Add")||h(e,"Subtract")?`(${n})`:n}function Nu(e,n){if(T(e,"ImaginaryUnit"))return{re:null,im:"1.0"};if(R(e)&&e.im!==0){let t=e.re,i=e.im;return{re:t!==0?ae(t):null,im:ae(i)}}if(h(e,"Multiply")){let t=e.ops,i=t.findIndex(r=>T(r,"ImaginaryUnit")||R(r)&&r.re===0&&r.im!==0);if(i>=0){let r=t[i],s=T(r,"ImaginaryUnit")?1:r.im,o=t.filter((l,c)=>c!==i);if(o.length===0)return{re:null,im:ae(s)};let a=o.map(l=>ri(l,n(l)));return s!==1&&a.unshift(ae(s)),{re:null,im:on(a,"1.0","*")}}}return b.isComplexValued(e)?null:{re:n(e),im:null}}function _r(e){let n=Math.abs(e);return n<=.0031308?12.92*e:(Math.sign(e)||1)*(1.055*Math.pow(n,1/2.4)-.055)}function Sr(e){let n=Math.abs(e);return n<=.04045?e/12.92:(Math.sign(e)||1)*Math.pow((n+.055)/1.055,2.4)}function ci(e,n,t){e=e/360;let i,r,s;if(n===0)i=r=s=t;else{let o=(l,c,f)=>(f<0&&(f+=1),f>1&&(f-=1),f<.16666666666666666?l+(c-l)*6*f:f<.5?c:f<.6666666666666666?l+(c-l)*(.6666666666666666-f)*6:l),a=t<.5?t*(1+n):t+n-t*n,u=2*t-a;i=o(u,a,e+1/3),r=o(u,a,e),s=o(u,a,e-1/3)}return{r:Math.round(i*255),g:Math.round(r*255),b:Math.round(s*255)}}function fi(e,n,t){e/=255,n/=255,t/=255;let i=Math.max(e,n,t),r=Math.min(e,n,t),s=(i+r)/2;if(i===r)return{h:0,s:0,l:s};let o=i-r,a=s>.5?o/(2-i-r):o/(i+r),u;return i===e?u=((n-t)/o+(n<t?6:0))/6:i===n?u=((t-e)/o+2)/6:u=((e-n)/o+4)/6,{h:u*360,s:a,l:s}}function Vu(e,n,t){e=(e%360+360)%360,n=Math.max(0,Math.min(1,n)),t=Math.max(0,Math.min(1,t));let i=t*n,r=i*(1-Math.abs(e/60%2-1)),s=t-i,o=0,a=0,u=0;return e<60?[o,a,u]=[i,r,0]:e<120?[o,a,u]=[r,i,0]:e<180?[o,a,u]=[0,i,r]:e<240?[o,a,u]=[0,r,i]:e<300?[o,a,u]=[r,0,i]:[o,a,u]=[i,0,r],{r:(o+s)*255,g:(a+s)*255,b:(u+s)*255}}function qu(e,n,t){e/=255,n/=255,t/=255;let i=Math.max(e,n,t),r=Math.min(e,n,t),s=i-r,o=0;s>0&&(i===e?o=(n-t)/s%6:i===n?o=(t-e)/s+2:o=(e-n)/s+4,o*=60,o<0&&(o+=360));let a=i===0?0:s/i;return{h:o,s:a,v:i}}function Kf(e){let n=e.startsWith("#")?e.substring(1):e,t,i,r,s;if(n.length===3)t=parseInt(n[0]+n[0],16),i=parseInt(n[1]+n[1],16),r=parseInt(n[2]+n[2],16);else if(n.length===6)t=parseInt(n.substring(0,2),16),i=parseInt(n.substring(2,4),16),r=parseInt(n.substring(4,6),16);else if(n.length===8)t=parseInt(n.substring(0,2),16),i=parseInt(n.substring(2,4),16),r=parseInt(n.substring(4,6),16),s=parseInt(n.substring(6,8),16)/255;else return{r:0,g:0,b:0};let o={r:t,g:i,b:r};return s!==void 0&&(o.alpha=s),o}function ai(e){return typeof e=="number"?{r:e>>>24&255,g:e>>>16&255,b:e>>>8&255,alpha:(e&255)/255}:typeof e=="string"?Kf(e):"C"in e?pi(e):"a"in e&&"b"in e?$r(e):e}function Tu(e){let n=ai(e),t=n.alpha!==void 0?Be(n.alpha*255):255;return(Be(n.r)<<24|Be(n.g)<<16|Be(n.b)<<8|t)>>>0}function Be(e){return e<0?0:e>255?255:Math.round(e)}function In(e){let[n,t,i]=[e.L,e.C,e.H],r=i*Math.PI/180,s={L:n,a:t*Math.cos(r),b:t*Math.sin(r)};return e.alpha!==void 0&&(s.alpha=e.alpha),s}function gt(e){let[n,t,i]=[e.L,e.a,e.b],r=Math.sqrt(t*t+i*i),o=Math.atan2(i,t)*180/Math.PI,a={L:n,C:r,H:o};return e.alpha!==void 0&&(a.alpha=e.alpha),a}function oi(e){let[n,t,i]=[e.L,e.a,e.b],r=Math.pow(.9999999984505198*n+.39633779217376786*t+.2158037580607588*i,3),s=Math.pow(1.00000000888176*n-.10556134232365635*t-.0638541747717059*i,3),o=Math.pow(n*1.000000054672411-.0894841820949657*t-1.2914855378640917*i,3),a=4.076741661347994*r-3.307711590408193*s+.230969928729428*o,u=-1.2684380040921763*r+2.6097574006633715*s-.3413193963102197*o,l=-.004196086541837188*r-.7034186144594493*s+1.7076147009309444*o;return[_r(a),_r(u),_r(l)]}function kr(e){let[n,t,i]=e;return n>=0&&n<=1&&t>=0&&t<=1&&i>=0&&i<=1}function Mr(e,n){let[t,i,r]=e;return t=Be(t*255),i=Be(i*255),r=Be(r*255),n!==void 0?{r:t,g:i,b:r,alpha:n}:{r:t,g:i,b:r}}function $r(e){let[n,t,i]=oi(e);if(kr([n,t,i]))return Mr([n,t,i],e.alpha);let r=gt(e);if(r.C=0,[n,t,i]=oi(In(r)),!kr([n,t,i]))return Mr([n,t,i],e.alpha);let s=0,o=e.L,a=(s+o)/2;r.C=a;let u=.36/Math.pow(2,12);for(;o-s>u;)a=(s+o)/2,r.C=a,[n,t,i]=oi(In(r)),kr([n,t,i])?s=a:o=a;return Mr([n,t,i],e.alpha)}function pi(e){return $r(In(e))}function Cr(e){let[n,t,i]=[e.r,e.g,e.b],r=Sr(n/255),s=Sr(t/255),o=Sr(i/255),a=.41222147079999993*r+.5363325363*s+.0514459929*o,u=.2119034981999999*r+.6806995450999999*s+.1073969566*o,l=.08830246189999998*r+.2817188376*s+.6299787005000002*o,c=Math.cbrt(a),f=Math.cbrt(u),d=Math.cbrt(l),m={L:.2104542553*c+.793617785*f-.0040720468*d,a:1.9779984951*c-2.428592205*f+.4505937099*d,b:.0259040371*c+.7827717662*f-.808675766*d};return e.alpha!==void 0&&(m.alpha=e.alpha),m}function Ee(e){return gt(Cr(e))}function wr(e,n){let t=n*Math.PI/180,i=0,r=1.5;for(let s=0;s<32;s++){let o=(i+r)/2,[a,u,l]=oi({L:e,a:o*Math.cos(t),b:o*Math.sin(t)});a>=0&&a<=1&&u>=0&&u<=1&&l>=0&&l<=1?i=o:r=o}return i}function Vn(e,n,t){let i=e/100;if(i<=0)return 255;let r=pi({L:i,C:n,H:t});return(Be(r.r)<<24|Be(r.g)<<16|Be(r.b)<<8|255)>>>0}function ep(e){let{l:n,c:t,h:i}=ui(e);return Vn(n+2.8,t+.002,i+.46)}function ui(e){let n=e>>>24&255,t=e>>>16&255,i=e>>>8&255,r=Ee({r:n,g:t,b:i});return{l:r.L*100,c:r.C,h:r.H<0?r.H+360:r.H}}function Ar(e,n,t){let{l:i,c:r,h:s}=ui(e),{l:o,c:a,h:u}=ui(n),l=i+(o-i)*t,c=r+(a-r)*t,f=u-s;f>180&&(f-=360),f<-180&&(f+=360);let d=s+f*t,m=e&255,g=n&255,v=Math.round(m+(g-m)*t);return Vn(l,c,d<0?d+360:d>360?d-360:d)&4294967040|v}function np(e,n=.1){let a=.45,u=0;for(let g=.45;g>=.35;g-=.01){let v=wr(g,e);if(v>=.15){a=g,u=.15;break}else v>u&&(a=g,u=v)}if(u<.15*.8)for(let g=.45+.01;g<=.5;g+=.01){let v=wr(g,e);if(v>=.15||v>u*1.2){a=g,u=Math.min(.15,v);break}}let l=.96,c=.02,f=wr(.96,e);f<.02&&(c=f*(1-n)),c=Math.max(.015,Math.min(.02,c));let d=Vn(a*100,u,e),m=Vn(l*100,c,e);return{darkest:d,lightest:m}}function tp(e,n){let t=Math.max(0,Math.min(1e3,n)),i,r,s;if(typeof e=="object")i=e.darkest,s=e.lightest,r=e.mid??0;else{r=e;let{h:u}=ui(r),l=r&255,{darkest:c,lightest:f}=np(u);i=c&4294967040|l,s=f&4294967040|l}if(!r&&typeof e=="object"&&!e.mid&&(r=Ar(i,s,.5)),t<=500){let u=t/500,l=u*u*(3-2*u);return Ar(s,r,l)}let o=(t-500)/500,a=o*o*(3-2*o);return Ar(r,i,a)}var ip=[{id:"pink",name:"Pink",colors:{mid:{lightness:69,chroma:.202,hue:7.4}}},{id:"red",name:"Red",colors:{lightest:{lightness:95,chroma:.2,hue:30},mid:{lightness:62,chroma:.25,hue:30},darkest:{lightness:36,chroma:.16,hue:25}}},{id:"brown",name:"Brown",colors:{lightest:{lightness:94.5,chroma:.021,hue:72.1},mid:{lightness:59,chroma:.2,hue:73},darkest:{lightness:20,chroma:.061,hue:72.7}}},{id:"orange",name:"Orange",colors:{lightest:{lightness:95,chroma:.06,hue:82},mid:{lightness:73,chroma:.21,hue:56},darkest:{lightness:46,chroma:.2,hue:35}}},{id:"yellow",name:"Yellow",colors:{lightest:{lightness:97,chroma:.02,hue:106},mid:{lightness:89,chroma:.21,hue:99},darkest:{lightness:67,chroma:.43,hue:59}}},{id:"lime",name:"Lime",colors:{mid:{lightness:65,chroma:.192,hue:134.3}}},{id:"green",name:"Green",colors:{mid:{lightness:64,chroma:.21,hue:144}}},{id:"teal",name:"Teal",colors:{mid:{lightness:65,chroma:.116,hue:192.6}}},{id:"cyan",name:"Cyan",colors:{lightest:{lightness:97,chroma:.11,hue:195},mid:{lightness:61,chroma:.11,hue:210},darkest:{lightness:42,chroma:.11,hue:210}}},{id:"blue",name:"Blue",colors:{lightest:{lightness:91,chroma:.22,hue:240},mid:{lightness:63,chroma:.22,hue:255},darkest:{lightness:38,chroma:.22,hue:252}}},{id:"indigo",name:"Indigo",colors:{lightest:{lightness:92.7,chroma:.036,hue:291},mid:{lightness:67,chroma:.285,hue:296},darkest:{lightness:28,chroma:.23,hue:278}}},{id:"purple",name:"Purple",colors:{mid:{lightness:67,chroma:.21,hue:299}}}];function Bn({lightness:e,chroma:n,hue:t}){return Vn(e,n,t)}function rp(e){let{mid:n,lightest:t,darkest:i}=e.colors;if(t&&i&&n)return{lightest:Bn(t),mid:Bn(n),darkest:Bn(i)};if(t&&i)return{lightest:Bn(t),darkest:Bn(i)};if(n)return Bn(n);throw new Error(`Color scale preset "${e.id}" is missing required anchors.`)}var si=null;function sp(){if(!si){si=Object.create(null);for(let e of ip)si[e.id]=rp(e)}return si}var Iu={red:"#d7170b",orange:"#fe8a2b",yellow:"#ffc02b",lime:"#63b215",green:"#21ba3a",teal:"#17cfcf",cyan:"#13a7ec",blue:"#0d80f2",indigo:"#63c",purple:"#a219e6",magenta:"#eb4799",brown:"#8c564b",olive:"#8a8f2a",midnight:"#2c4670",sky:"#d2dce9",black:"#000",white:"#ffffff",carbon:"#111111",charcoal:"#333333",slate:"#555555","dark-grey":"#666",graphite:"#777777",stone:"#999999",grey:"#A6A6A6","light-grey":"#d4d5d2",ash:"#E6E6E6",mist:"#F3F3F3",snow:"#FFFFFF"};function en(e,n){let t=e.trim().toLowerCase(),i=t.match(/^(.+?)\s*\/\s*(\d+(?:\.\d+)?)%?\s*$/);if(i){let l=en(i[1].trim(),n),c=Math.max(0,Math.min(100,parseFloat(i[2]))),f=Math.round(c/100*255);return l&4294967040|f}if(t.startsWith("#")){let l=t.substring(1),c,f,d,m=255;if(l.length===3)c=parseInt(l[0]+l[0],16),f=parseInt(l[1]+l[1],16),d=parseInt(l[2]+l[2],16);else if(l.length===6)c=parseInt(l.substring(0,2),16),f=parseInt(l.substring(2,4),16),d=parseInt(l.substring(4,6),16);else if(l.length===8)c=parseInt(l.substring(0,2),16),f=parseInt(l.substring(2,4),16),d=parseInt(l.substring(4,6),16),m=parseInt(l.substring(6,8),16);else return 0;return(c<<24|f<<16|d<<8|m)>>>0}let r=t.match(/^rgba?\s*\(\s*([^)]+)\s*\)$/);if(r){let l=r[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0])||0,f=parseFloat(l[1])||0,d=parseFloat(l[2])||0;l[0].includes("%")||l[1].includes("%")||l[2].includes("%")?(l[0].includes("%")&&(c=c/100*255),l[1].includes("%")&&(f=f/100*255),l[2].includes("%")&&(d=d/100*255)):c<=1&&f<=1&&d<=1&&(c=c*255,f=f*255,d=d*255),c=Math.round(Math.max(0,Math.min(255,c))),f=Math.round(Math.max(0,Math.min(255,f))),d=Math.round(Math.max(0,Math.min(255,d)));let m=255;if(l.length>=4){let g=parseFloat(l[3]);l[3].includes("%")?g=g/100:g>1&&(g=g/255),m=Math.round(Math.max(0,Math.min(255,g*255)))}return(c<<24|f<<16|d<<8|m)>>>0}let s=t.match(/^oklch\s*\(\s*([^)]+)\s*\)$/);if(s){let l=s[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0]);l[0].includes("%")?c=c/100:c<=1||(c=c/100);let f=parseFloat(l[1])||0,d=parseFloat(l[2])||0,m=1;l.length>=4&&(m=parseFloat(l[3]),l[3].includes("%")?m=m/100:m>1&&(m=m/255));let g=Vn(c*100,f,d),v=Math.round(m*255);return g&4294967040|v}let o=t.match(/^oklab\s*\(\s*([^)]+)\s*\)$/);if(o){let l=o[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0]);(l[0].includes("%")||c>1)&&(c=c/100);let f=parseFloat(l[1])||0,d=parseFloat(l[2])||0,m=1;l.length>=4&&(m=parseFloat(l[3]),l[3].includes("%")?m=m/100:m>1&&(m=m/255));let g=$r({L:c,a:f,b:d}),v=g.r,N=g.g,M=g.b,$=Math.round(m*255);return(v<<24|N<<16|M<<8|$)>>>0}let a=t.match(/^hsl\s*\(\s*([^)]+)\s*\)$/);if(a){let l=a[1].replace(/[,/]/g," ").trim().split(/\s+/),c=parseFloat(l[0])||0,f=parseFloat(l[1])||0;l[1].includes("%")?f=f/100:f<=1||(f=f/100);let d=parseFloat(l[2])||0;l[2].includes("%")?d=d/100:d<=1||(d=d/100);let m=1;l.length>=4&&(m=parseFloat(l[3]),l[3].includes("%")?m=m/100:m>1&&(m=m/255));let{r:g,g:v,b:N}=ci(c,f,d),M=Math.round(m*255);return(g<<24|v<<16|N<<8|M)>>>0}if(t==="transparent")return 0;let u=t.match(/^([a-z]+)-(\d+)$/);if(u){let l=sp()[u[1]];if(l){let c=tp(l,parseInt(u[2],10));return n?ep(c):c}}return t in Iu?en(Iu[t]):(console.warn(`parseColor: unrecognized color "${e}"`),0)}function li(e,n){let t=ai(e),i=ai(n),r=.56,s=.57,o=.62,a=.65,u=.022,l=1.414,c=.1,f=5e-4,d=1.14,m=.027,g=1.14,v=.027;function N(O){return O>=u?O:O+(u-O)**l}function M(O){return(O<0?-1:1)*Math.pow(Math.abs(O),2.4)}let $=N(M(i.r/255)*.2126729+M(i.g/255)*.7151522+M(i.b/255)*.072175),P=N(M(t.r/255)*.2126729+M(t.g/255)*.7151522+M(t.b/255)*.072175),J,H;return Math.abs(P-$)<f?H=0:P>$?(J=P**r-$**s,H=J*d):(J=P**a-$**o,H=J*g),Math.abs(H)<c?0:H>0?H-v:H+m}function Rr(e){let n,t,i;typeof e!="object"||!("bg"in e)?(n=ai(e),t="#ffffff",i="#000000"):(n=e.bg,t=e.fg1,i=e.fg2);let r=Math.abs(li(t,n)),s=Math.abs(li(i,n));return r>=s?Tu(t):Tu(i)}function Ju(e,n){let t=e.L-n.L,i=e.a-n.a,r=e.b-n.b;return Math.sqrt(t*t+i*i+r*r)}var op=["#4e79a7","#f28e2b","#59a14f","#e15759","#b07aa1","#9c755f","#ff9da7","#edc948","#76b7b2","#6b8fd6","#c07bc4"],ap=["#78a6d9","#ffae54","#7ddc7a","#ff7a7a","#d29be0","#c49a84","#ffb3bf","#ffe066","#7fd6d0","#8fb4ff","#e199eb"],up=["#4e79a7","#f28e2b","#2ca58d","#d13a3c","#b07aa1","#9c755f","#ff9da7","#e3c13b","#5fb8b2","#6b8fd6","#c07bc4"],lp=["#8fb1d4","#f6b878","#8ecf86","#f08a8b","#d3a9cc","#c3a492","#ffc6cc","#f3e08a","#a8d8d4","#a9c0ea","#e0b4e4"],cp=["#78a6d9","#ffae54","#7ddc7a","#ff7a7a","#d29be0","#c49a84","#ffb3bf","#ffe066","#7fd6d0","#8fb4ff","#e199eb"],fp=["#2f6fb0","#ff7a00","#2fa23a","#e02f2f","#9b4db5","#7f4f38","#ff6f86","#f2c200","#2daaa3","#4c79e0","#b84ac6"],pp=["#4f93ff","#ff8c1a","#33c94a","#ff4f4f","#b86bff","#a86a4a","#ff7f9e","#ffd400","#2ec9c1","#6f9bff","#cc5bd9"],mp=["#5E81B5","#E19C24","#8FB131","#EB6235","#8778B3","#C56E1A","#5E9EC9","#B23A3A","#4C9F70","#C979B7"],dp=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],hp=["#007AFF","#FF9500","#34C759","#FF3B30","#AF52DE","#FF2D55","#30B0C7","#5856D6","#A2845E","#32ADE6","#00C7BE"],gp=["#0A84FF","#FF9F0A","#30D158","#FF453A","#BF5AF2","#FF375F","#40C8E0","#5E5CE6","#AC8E68","#64D2FF","#00D1C1"],bp=["#fdfdfd","#1d1d1d","#ebce2b","#702c8c","#db6917","#96cde6","#ba1c30","#c0bd7f","#7f7e80","#5fa641","#d485b2","#4277b6","#df8461","#463397","#e1a11a","#91218c","#e8e948","#7e1510","#92ae31","#6f340d","#d32b1e","#2b3514"],yp=["#4148cc","#db3c80","#12b5b0","#ff8c14","#848aff","#78e16e","#1e78f0","#ebcd00","#beeb3c","#7828d2","#cd5f00","#00915f"],zu={tycho11:op,"tycho-dark11":ap,"tycho-robust11":up,"tycho-soft11":lp,"tycho-soft-dark11":cp,"tycho-bold11":fp,"tycho-bold-dark11":pp,tableau10:dp,kelly22:bp,mathematica10:mp,cupertino10:hp,"cupertino-dark10":gp,spectrum12:yp},_u=["#033198","#053399","#07359a","#09379b","#0b399c","#0c3b9c","#0e3d9d","#0f3f9e","#11409f","#1242a0","#1344a0","#1446a1","#1548a2","#164aa3","#174ca4","#184da4","#194fa5","#1951a6","#1a53a7","#1b54a8","#1b56a8","#1c58a9","#1d5aaa","#1d5bab","#1e5dab","#1e5fac","#1f60ad","#2062ae","#2064ae","#2166af","#2167b0","#2269b0","#226ab1","#236cb2","#236eb3","#246fb3","#2471b4","#2573b5","#2574b5","#2676b6","#2677b7","#2779b7","#287ab8","#287cb9","#297eb9","#297fba","#2a81bb","#2b82bb","#2b84bc","#2c85bd","#2d87bd","#2d88be","#2e8abf","#2f8cbf","#308dc0","#308fc1","#3190c1","#3292c2","#3394c3","#3495c3","#3597c4","#3698c5","#379ac5","#389cc6","#399dc7","#3a9fc7","#3ca1c8","#3da2c9","#3ea4c9","#40a6ca","#41a7cb","#43a9cb","#44abcc","#46accc","#47aecd","#49b0ce","#4bb2ce","#4db3cf","#4fb5d0","#51b7d0","#53b8d1","#55bad1","#57bcd2","#59bdd2","#5bbfd3","#5dc1d3","#60c3d4","#62c4d4","#64c6d5","#67c7d5","#69c9d5","#6ccbd6","#6eccd6","#71ced6","#74cfd6","#76d1d7","#79d2d7","#7bd4d7","#7ed5d7","#81d7d7","#83d8d7","#86d9d7","#89dad7","#8bdcd7","#8eddd7","#90ded7","#93dfd6","#95e0d6","#98e1d6","#9be2d5","#9de3d5","#9fe4d4","#a2e5d4","#a4e5d3","#a6e6d2","#a9e7d2","#abe7d1","#ade8d0","#afe8cf","#b1e9ce","#b3e9cd","#b5eacc","#b7eaca","#b9eac9","#bbeac8","#bdeac6","#beeac5","#c0eac3","#c1eac2","#c3eac0","#c4eabe","#c6eabc","#c7e9ba","#c8e9b8","#c9e9b6","#cbe8b4","#cce7b2","#cce7b0","#cde6ad","#cee5ab","#cfe5a8","#d0e4a6","#d0e3a3","#d1e2a1","#d1e19e","#d1df9b","#d2de98","#d2dd96","#d2dc93","#d2da90","#d2d98d","#d2d78a","#d2d687","#d2d484","#d2d381","#d2d17e","#d1cf7b","#d1cd78","#d0cc75","#d0ca72","#cfc86f","#cfc66d","#cec46a","#cec267","#cdc064","#ccbe62","#cbbc5f","#cbba5d","#cab85a","#c9b658","#c8b455","#c7b253","#c7b051","#c6ae4f","#c5ac4c","#c4aa4a","#c3a848","#c2a647","#c1a545","#c1a343","#c0a141","#bf9f40","#be9d3e","#bd9b3c","#bc993b","#bb9739","#ba9538","#ba9437","#b99235","#b89034","#b78e33","#b68c32","#b58b31","#b58930","#b4872f","#b3862e","#b2842d","#b1822c","#b0802b","#b07f2a","#af7d29","#ae7c28","#ad7a27","#ad7826","#ac7726","#ab7525","#aa7324","#a97223","#a97023","#a86f22","#a76d21","#a66c20","#a66a20","#a5681f","#a4671e","#a3651e","#a2641d","#a2621c","#a1611c","#a05f1b","#9f5d1a","#9e5c19","#9e5a19","#9d5818","#9c5717","#9b5517","#9a5316","#995215","#995014","#984e14","#974d13","#964b12","#954912","#944711","#934610","#92440f","#91420f","#90400e","#903e0d","#8f3c0c","#8e3a0b","#8d380b","#8c360a","#8b3409","#8a3208","#883008","#872e07","#862c06","#852a06","#842705","#832504","#822204","#812003","#801d02","#7f1a01","#7e1700"],Su=["#0b3c78","#2366a8","#4f97cf","#9bc7e4","#f7f7f7","#e88fa0","#c23c6f","#8e1d4d","#5a0c2e"],ku=["#2c557f","#4a7fa8","#7aa8c9","#b5cfe3","#f7f7f7","#e4b0b0","#c96c72","#9b3d4f","#6b1a2b"],Mu=["#053061","#11458c","#1f5fa5","#337ab7","#4f94c6","#6baed6","#8bbdd9","#a6cce3","#c1dbec","#dceaf4","#f7f7f7","#fbe3d6","#f9c8b2","#f5a993","#ee8a75","#e36b58","#d64b41","#c72c33","#af212d","#971628","#7f0b23","#67001f"],wu=["#3b4cc0","#465ecf","#5070de","#5c82ea","#6f96f5","#86aafc","#9dbdff","#b6d0f3","#cfe1e8","#e6efe1","#f1f1f1","#f7f7f7","#f6e1d3","#f4cbb3","#f1b594","#ee9f76","#ea8960","#e06b53","#d24f49","#c1363f","#ae2036","#b40426"],ht=e=>e.slice().reverse(),Gu={roma:_u,"roma-reversed":ht(_u),vik:Su,"vik-reversed":ht(Su),broc:ku,"broc-reversed":ht(ku),rdbu:Mu,"rdbu-reversed":ht(Mu),coolwarm:wu,"coolwarm-reversed":ht(wu)},Au=["#30123b","#321543","#33184a","#341b51","#351e58","#36215f","#372466","#38276d","#392a73","#3a2d79","#3b2f80","#3c3286","#3d358b","#3e3891","#3f3b97","#3f3e9c","#4040a2","#4143a7","#4146ac","#4249b1","#424bb5","#434eba","#4451bf","#4454c3","#4456c7","#4559cb","#455ccf","#455ed3","#4661d6","#4664da","#4666dd","#4669e0","#466be3","#476ee6","#4771e9","#4773eb","#4776ee","#4778f0","#477bf2","#467df4","#4680f6","#4682f8","#4685fa","#4687fb","#458afc","#458cfd","#448ffe","#4391fe","#4294ff","#4196ff","#4099ff","#3e9bfe","#3d9efe","#3ba0fd","#3aa3fc","#38a5fb","#37a8fa","#35abf8","#33adf7","#31aff5","#2fb2f4","#2eb4f2","#2cb7f0","#2ab9ee","#28bceb","#27bee9","#25c0e7","#23c3e4","#22c5e2","#20c7df","#1fc9dd","#1ecbda","#1ccdd8","#1bd0d5","#1ad2d2","#1ad4d0","#19d5cd","#18d7ca","#18d9c8","#18dbc5","#18ddc2","#18dec0","#18e0bd","#19e2bb","#19e3b9","#1ae4b6","#1ce6b4","#1de7b2","#1fe9af","#20eaac","#22ebaa","#25eca7","#27eea4","#2aefa1","#2cf09e","#2ff19b","#32f298","#35f394","#38f491","#3cf58e","#3ff68a","#43f787","#46f884","#4af880","#4ef97d","#52fa7a","#55fa76","#59fb73","#5dfc6f","#61fc6c","#65fd69","#69fd66","#6dfe62","#71fe5f","#75fe5c","#79fe59","#7dff56","#80ff53","#84ff51","#88ff4e","#8bff4b","#8fff49","#92ff47","#96fe44","#99fe42","#9cfe40","#9ffd3f","#a1fd3d","#a4fc3c","#a7fc3a","#a9fb39","#acfb38","#affa37","#b1f936","#b4f836","#b7f735","#b9f635","#bcf534","#bef434","#c1f334","#c3f134","#c6f034","#c8ef34","#cbed34","#cdec34","#d0ea34","#d2e935","#d4e735","#d7e535","#d9e436","#dbe236","#dde037","#dfdf37","#e1dd37","#e3db38","#e5d938","#e7d739","#e9d539","#ebd339","#ecd13a","#eecf3a","#efcd3a","#f1cb3a","#f2c93a","#f4c73a","#f5c53a","#f6c33a","#f7c13a","#f8be39","#f9bc39","#faba39","#fbb838","#fbb637","#fcb336","#fcb136","#fdae35","#fdac34","#fea933","#fea732","#fea431","#fea130","#fe9e2f","#fe9b2d","#fe992c","#fe962b","#fe932a","#fe9029","#fd8d27","#fd8a26","#fc8725","#fc8423","#fb8122","#fb7e21","#fa7b1f","#f9781e","#f9751d","#f8721c","#f76f1a","#f66c19","#f56918","#f46617","#f36315","#f26014","#f15d13","#f05b12","#ef5811","#ed5510","#ec530f","#eb500e","#ea4e0d","#e84b0c","#e7490c","#e5470b","#e4450a","#e2430a","#e14109","#df3f08","#dd3d08","#dc3b07","#da3907","#d83706","#d63506","#d43305","#d23105","#d02f05","#ce2d04","#cc2b04","#ca2a04","#c82803","#c52603","#c32503","#c12302","#be2102","#bc2002","#b91e02","#b71d02","#b41b01","#b21a01","#af1801","#ac1701","#a91601","#a71401","#a41301","#a11201","#9e1001","#9b0f01","#980e01","#950d01","#920b01","#8e0a01","#8b0902","#880802","#850702","#810602","#7e0502","#7a0403"],$u=["#000004","#010005","#010106","#010108","#020109","#02020b","#02020d","#03030f","#030312","#040414","#050416","#060518","#06051a","#07061c","#08071e","#090720","#0a0822","#0b0924","#0c0926","#0d0a29","#0e0b2b","#100b2d","#110c2f","#120d31","#130d34","#140e36","#150e38","#160f3b","#180f3d","#19103f","#1a1042","#1c1044","#1d1147","#1e1149","#20114b","#21114e","#221150","#241253","#251255","#271258","#29115a","#2a115c","#2c115f","#2d1161","#2f1163","#311165","#331067","#341069","#36106b","#38106c","#390f6e","#3b0f70","#3d0f71","#3f0f72","#400f74","#420f75","#440f76","#451077","#471078","#491078","#4a1079","#4c117a","#4e117b","#4f127b","#51127c","#52137c","#54137d","#56147d","#57157e","#59157e","#5a167e","#5c167f","#5d177f","#5f187f","#601880","#621980","#641a80","#651a80","#671b80","#681c81","#6a1c81","#6b1d81","#6d1d81","#6e1e81","#701f81","#721f81","#732081","#752181","#762181","#782281","#792282","#7b2382","#7c2382","#7e2482","#802582","#812581","#832681","#842681","#862781","#882781","#892881","#8b2981","#8c2981","#8e2a81","#902a81","#912b81","#932b80","#942c80","#962c80","#982d80","#992d80","#9b2e7f","#9c2e7f","#9e2f7f","#a02f7f","#a1307e","#a3307e","#a5317e","#a6317d","#a8327d","#aa337d","#ab337c","#ad347c","#ae347b","#b0357b","#b2357b","#b3367a","#b5367a","#b73779","#b83779","#ba3878","#bc3978","#bd3977","#bf3a77","#c03a76","#c23b75","#c43c75","#c53c74","#c73d73","#c83e73","#ca3e72","#cc3f71","#cd4071","#cf4070","#d0416f","#d2426f","#d3436e","#d5446d","#d6456c","#d8456c","#d9466b","#db476a","#dc4869","#de4968","#df4a68","#e04c67","#e24d66","#e34e65","#e44f64","#e55064","#e75263","#e85362","#e95462","#ea5661","#eb5760","#ec5860","#ed5a5f","#ee5b5e","#ef5d5e","#f05f5e","#f1605d","#f2625d","#f2645c","#f3655c","#f4675c","#f4695c","#f56b5c","#f66c5c","#f66e5c","#f7705c","#f7725c","#f8745c","#f8765c","#f9785d","#f9795d","#f97b5d","#fa7d5e","#fa7f5e","#fa815f","#fb835f","#fb8560","#fb8761","#fc8961","#fc8a62","#fc8c63","#fc8e64","#fc9065","#fd9266","#fd9467","#fd9668","#fd9869","#fd9a6a","#fd9b6b","#fe9d6c","#fe9f6d","#fea16e","#fea36f","#fea571","#fea772","#fea973","#feaa74","#feac76","#feae77","#feb078","#feb27a","#feb47b","#feb67c","#feb77e","#feb97f","#febb81","#febd82","#febf84","#fec185","#fec287","#fec488","#fec68a","#fec88c","#feca8d","#fecc8f","#fecd90","#fecf92","#fed194","#fed395","#fed597","#fed799","#fed89a","#fdda9c","#fddc9e","#fddea0","#fde0a1","#fde2a3","#fde3a5","#fde5a7","#fde7a9","#fde9aa","#fdebac","#fcecae","#fceeb0","#fcf0b2","#fcf2b4","#fcf4b6","#fcf6b8","#fcf7b9","#fcf9bb","#fcfbbd","#fcfdbf"],Cu=["#000004","#010005","#010106","#010108","#02010a","#02020c","#02020e","#030210","#040312","#040314","#050417","#060419","#07051b","#08051d","#09061f","#0a0722","#0b0724","#0c0826","#0d0829","#0e092b","#10092d","#110a30","#120a32","#140b34","#150b37","#160b39","#180c3c","#190c3e","#1b0c41","#1c0c43","#1e0c45","#1f0c48","#210c4a","#230c4c","#240c4f","#260c51","#280b53","#290b55","#2b0b57","#2d0b59","#2f0a5b","#310a5c","#320a5e","#340a5f","#360961","#380962","#390963","#3b0964","#3d0965","#3e0966","#400a67","#420a68","#440a68","#450a69","#470b6a","#490b6a","#4a0c6b","#4c0c6b","#4d0d6c","#4f0d6c","#510e6c","#520e6d","#540f6d","#550f6d","#57106e","#59106e","#5a116e","#5c126e","#5d126e","#5f136e","#61136e","#62146e","#64156e","#65156e","#67166e","#69166e","#6a176e","#6c186e","#6d186e","#6f196e","#71196e","#721a6e","#741a6e","#751b6e","#771c6d","#781c6d","#7a1d6d","#7c1d6d","#7d1e6d","#7f1e6c","#801f6c","#82206c","#84206b","#85216b","#87216b","#88226a","#8a226a","#8c2369","#8d2369","#8f2469","#902568","#922568","#932667","#952667","#972766","#982766","#9a2865","#9b2964","#9d2964","#9f2a63","#a02a63","#a22b62","#a32c61","#a52c60","#a62d60","#a82e5f","#a92e5e","#ab2f5e","#ad305d","#ae305c","#b0315b","#b1325a","#b3325a","#b43359","#b63458","#b73557","#b93556","#ba3655","#bc3754","#bd3853","#bf3952","#c03a51","#c13a50","#c33b4f","#c43c4e","#c63d4d","#c73e4c","#c83f4b","#ca404a","#cb4149","#cc4248","#ce4347","#cf4446","#d04545","#d24644","#d34743","#d44842","#d54a41","#d74b3f","#d84c3e","#d94d3d","#da4e3c","#db503b","#dd513a","#de5238","#df5337","#e05536","#e15635","#e25734","#e35933","#e45a31","#e55c30","#e65d2f","#e75e2e","#e8602d","#e9612b","#ea632a","#eb6429","#eb6628","#ec6726","#ed6925","#ee6a24","#ef6c23","#ef6e21","#f06f20","#f1711f","#f1731d","#f2741c","#f3761b","#f37819","#f47918","#f57b17","#f57d15","#f67e14","#f68013","#f78212","#f78410","#f8850f","#f8870e","#f8890c","#f98b0b","#f98c0a","#f98e09","#fa9008","#fa9207","#fa9407","#fb9606","#fb9706","#fb9906","#fb9b06","#fb9d07","#fc9f07","#fca108","#fca309","#fca50a","#fca60c","#fca80d","#fcaa0f","#fcac11","#fcae12","#fcb014","#fcb216","#fcb418","#fbb61a","#fbb81d","#fbba1f","#fbbc21","#fbbe23","#fac026","#fac228","#fac42a","#fac62d","#f9c72f","#f9c932","#f9cb35","#f8cd37","#f8cf3a","#f7d13d","#f7d340","#f6d543","#f6d746","#f5d949","#f5db4c","#f4dd4f","#f4df53","#f4e156","#f3e35a","#f3e55d","#f2e661","#f2e865","#f2ea69","#f1ec6d","#f1ed71","#f1ef75","#f1f179","#f2f27d","#f2f482","#f3f586","#f3f68a","#f4f88e","#f5f992","#f6fa96","#f8fb9a","#f9fc9d","#fafda1","#fcffa4"],Ru=["#0d0887","#100788","#130789","#16078a","#19068c","#1b068d","#1d068e","#20068f","#220690","#240691","#260591","#280592","#2a0593","#2c0594","#2e0595","#2f0596","#310597","#330597","#350498","#370499","#38049a","#3a049a","#3c049b","#3e049c","#3f049c","#41049d","#43039e","#44039e","#46039f","#48039f","#4903a0","#4b03a1","#4c02a1","#4e02a2","#5002a2","#5102a3","#5302a3","#5502a4","#5601a4","#5801a4","#5901a5","#5b01a5","#5c01a6","#5e01a6","#6001a6","#6100a7","#6300a7","#6400a7","#6600a7","#6700a8","#6900a8","#6a00a8","#6c00a8","#6e00a8","#6f00a8","#7100a8","#7201a8","#7401a8","#7501a8","#7701a8","#7801a8","#7a02a8","#7b02a8","#7d03a8","#7e03a8","#8004a8","#8104a7","#8305a7","#8405a7","#8606a6","#8707a6","#8808a6","#8a09a5","#8b0aa5","#8d0ba5","#8e0ca4","#8f0da4","#910ea3","#920fa3","#9410a2","#9511a1","#9613a1","#9814a0","#99159f","#9a169f","#9c179e","#9d189d","#9e199d","#a01a9c","#a11b9b","#a21d9a","#a31e9a","#a51f99","#a62098","#a72197","#a82296","#aa2395","#ab2494","#ac2694","#ad2793","#ae2892","#b02991","#b12a90","#b22b8f","#b32c8e","#b42e8d","#b52f8c","#b6308b","#b7318a","#b83289","#ba3388","#bb3488","#bc3587","#bd3786","#be3885","#bf3984","#c03a83","#c13b82","#c23c81","#c33d80","#c43e7f","#c5407e","#c6417d","#c7427c","#c8437b","#c9447a","#ca457a","#cb4679","#cc4778","#cc4977","#cd4a76","#ce4b75","#cf4c74","#d04d73","#d14e72","#d24f71","#d35171","#d45270","#d5536f","#d5546e","#d6556d","#d7566c","#d8576b","#d9586a","#da5a6a","#da5b69","#db5c68","#dc5d67","#dd5e66","#de5f65","#de6164","#df6263","#e06363","#e16462","#e26561","#e26660","#e3685f","#e4695e","#e56a5d","#e56b5d","#e66c5c","#e76e5b","#e76f5a","#e87059","#e97158","#e97257","#ea7457","#eb7556","#eb7655","#ec7754","#ed7953","#ed7a52","#ee7b51","#ef7c51","#ef7e50","#f07f4f","#f0804e","#f1814d","#f1834c","#f2844b","#f3854b","#f3874a","#f48849","#f48948","#f58b47","#f58c46","#f68d45","#f68f44","#f79044","#f79143","#f79342","#f89441","#f89540","#f9973f","#f9983e","#f99a3e","#fa9b3d","#fa9c3c","#fa9e3b","#fb9f3a","#fba139","#fba238","#fca338","#fca537","#fca636","#fca835","#fca934","#fdab33","#fdac33","#fdae32","#fdaf31","#fdb130","#fdb22f","#fdb42f","#fdb52e","#feb72d","#feb82c","#feba2c","#febb2b","#febd2a","#febe2a","#fec029","#fdc229","#fdc328","#fdc527","#fdc627","#fdc827","#fdca26","#fdcb26","#fccd25","#fcce25","#fcd025","#fcd225","#fbd324","#fbd524","#fbd724","#fad824","#fada24","#f9dc24","#f9dd25","#f8df25","#f8e125","#f7e225","#f7e425","#f6e626","#f6e826","#f5e926","#f5eb27","#f4ed27","#f3ee27","#f3f027","#f2f227","#f1f426","#f1f525","#f0f724","#f0f921"],Du=["#440154","#440256","#450457","#450559","#46075a","#46085c","#460a5d","#460b5e","#470d60","#470e61","#471063","#471164","#471365","#481467","#481668","#481769","#48186a","#481a6c","#481b6d","#481c6e","#481d6f","#481f70","#482071","#482173","#482374","#482475","#482576","#482677","#482878","#482979","#472a7a","#472c7a","#472d7b","#472e7c","#472f7d","#46307e","#46327e","#46337f","#463480","#453581","#453781","#453882","#443983","#443a83","#443b84","#433d84","#433e85","#423f85","#424086","#424186","#414287","#414487","#404588","#404688","#3f4788","#3f4889","#3e4989","#3e4a89","#3e4c8a","#3d4d8a","#3d4e8a","#3c4f8a","#3c508b","#3b518b","#3b528b","#3a538b","#3a548c","#39558c","#39568c","#38588c","#38598c","#375a8c","#375b8d","#365c8d","#365d8d","#355e8d","#355f8d","#34608d","#34618d","#33628d","#33638d","#32648e","#32658e","#31668e","#31678e","#31688e","#30698e","#306a8e","#2f6b8e","#2f6c8e","#2e6d8e","#2e6e8e","#2e6f8e","#2d708e","#2d718e","#2c718e","#2c728e","#2c738e","#2b748e","#2b758e","#2a768e","#2a778e","#2a788e","#29798e","#297a8e","#297b8e","#287c8e","#287d8e","#277e8e","#277f8e","#27808e","#26818e","#26828e","#26828e","#25838e","#25848e","#25858e","#24868e","#24878e","#23888e","#23898e","#238a8d","#228b8d","#228c8d","#228d8d","#218e8d","#218f8d","#21908d","#21918c","#20928c","#20928c","#20938c","#1f948c","#1f958b","#1f968b","#1f978b","#1f988b","#1f998a","#1f9a8a","#1e9b8a","#1e9c89","#1e9d89","#1f9e89","#1f9f88","#1fa088","#1fa188","#1fa187","#1fa287","#20a386","#20a486","#21a585","#21a685","#22a785","#22a884","#23a983","#24aa83","#25ab82","#25ac82","#26ad81","#27ad81","#28ae80","#29af7f","#2ab07f","#2cb17e","#2db27d","#2eb37c","#2fb47c","#31b57b","#32b67a","#34b679","#35b779","#37b878","#38b977","#3aba76","#3bbb75","#3dbc74","#3fbc73","#40bd72","#42be71","#44bf70","#46c06f","#48c16e","#4ac16d","#4cc26c","#4ec36b","#50c46a","#52c569","#54c568","#56c667","#58c765","#5ac864","#5cc863","#5ec962","#60ca60","#63cb5f","#65cb5e","#67cc5c","#69cd5b","#6ccd5a","#6ece58","#70cf57","#73d056","#75d054","#77d153","#7ad151","#7cd250","#7fd34e","#81d34d","#84d44b","#86d549","#89d548","#8bd646","#8ed645","#90d743","#93d741","#95d840","#98d83e","#9bd93c","#9dd93b","#a0da39","#a2da37","#a5db36","#a8db34","#aadc32","#addc30","#b0dd2f","#b2dd2d","#b5de2b","#b8de29","#bade28","#bddf26","#c0df25","#c2df23","#c5e021","#c8e020","#cae11f","#cde11d","#d0e11c","#d2e21b","#d5e21a","#d8e219","#dae319","#dde318","#dfe318","#e2e418","#e5e419","#e7e419","#eae51a","#ece51b","#efe51c","#f1e51d","#f4e61e","#f6e620","#f8e621","#fbe723","#fde725"],Pu=["#00204d","#00214e","#002250","#002252","#002353","#002455","#002557","#002558","#00265a","#00275c","#00275e","#002860","#002961","#002a63","#002a65","#002b67","#002c69","#002c6a","#002d6c","#002e6e","#002e6f","#002f6f","#002f6f","#00306f","#00306f","#00316f","#00326f","#00336f","#00336f","#00346f","#00356e","#01366e","#06366e","#0b376e","#0f386e","#12386d","#15396d","#183a6d","#1a3b6d","#1d3b6d","#1f3c6d","#213d6d","#233e6c","#243e6c","#263f6c","#28406c","#2a406c","#2b416c","#2d426c","#2e436c","#30436c","#31446b","#32456b","#34456b","#35466b","#36476b","#38486b","#39486b","#3a496b","#3b4a6b","#3d4a6b","#3e4b6b","#3f4c6b","#404d6b","#414d6b","#424e6b","#434f6b","#444f6b","#46506b","#47516b","#48526b","#49526b","#4a536b","#4b546c","#4c546c","#4d556c","#4e566c","#4f576c","#50576c","#51586c","#52596c","#53596c","#545a6c","#555b6d","#565c6d","#575c6d","#585d6d","#595e6d","#595f6d","#5a5f6d","#5b606e","#5c616e","#5d616e","#5e626e","#5f636e","#60646f","#61646f","#62656f","#63666f","#64666f","#646770","#656870","#666970","#676970","#686a71","#696b71","#6a6c71","#6b6c71","#6c6d72","#6c6e72","#6d6e72","#6e6f73","#6f7073","#707173","#717174","#727274","#727374","#737475","#747475","#757575","#767676","#777776","#787777","#787877","#797977","#7a7a78","#7b7a78","#7c7b78","#7d7c78","#7e7d78","#7f7d78","#807e79","#817f79","#828079","#838079","#848179","#848279","#858379","#868379","#878479","#888579","#898679","#8a8779","#8b8779","#8c8879","#8d8979","#8e8a79","#8f8a79","#908b79","#918c78","#928d78","#938e78","#948e78","#958f78","#969078","#979178","#989278","#999278","#9a9377","#9b9477","#9c9577","#9d9677","#9e9677","#9f9777","#a09877","#a19976","#a29a76","#a39a76","#a49b76","#a59c76","#a69d75","#a89e75","#a99f75","#aa9f75","#aba074","#aca174","#ada274","#aea374","#afa473","#b0a473","#b1a573","#b2a672","#b3a772","#b4a872","#b5a971","#b6a971","#b7aa71","#b8ab70","#b9ac70","#baad70","#bbae6f","#bcaf6f","#beaf6f","#bfb06e","#c0b16e","#c1b26d","#c2b36d","#c3b46d","#c4b56c","#c5b56c","#c6b66b","#c7b76b","#c8b86a","#c9b96a","#cbba69","#ccbb69","#cdbc68","#cebc68","#cfbd67","#d0be67","#d1bf66","#d2c066","#d3c165","#d4c264","#d6c364","#d7c463","#d8c563","#d9c562","#dac661","#dbc761","#dcc860","#ddc95f","#deca5f","#e0cb5e","#e1cc5d","#e2cd5c","#e3ce5c","#e4cf5b","#e5d05a","#e6d159","#e8d259","#e9d358","#ead357","#ebd456","#ecd555","#edd654","#efd753","#f0d852","#f1d951","#f2da50","#f3db4f","#f4dc4e","#f6dd4d","#f7de4c","#f8df4b","#f9e04a","#fae149","#fbe248","#fde346","#fee445","#ffe544","#ffe642","#ffe742","#ffe843","#ffe944","#ffea46"],Fu=["#03051a","#04051a","#05061b","#06071c","#07071d","#08081e","#0a091f","#0b0920","#0d0a21","#0e0b22","#100b23","#110c24","#130d25","#140e26","#160e27","#170f28","#180f29","#1a102a","#1b112b","#1d112c","#1e122d","#20122e","#211330","#221331","#241432","#251433","#271534","#281535","#2a1636","#2b1637","#2d1738","#2e1739","#30173a","#31183b","#33183c","#34193d","#35193e","#37193f","#381a40","#3a1a41","#3c1a42","#3d1a42","#3f1b43","#401b44","#421b45","#431c46","#451c47","#461c48","#481c48","#491d49","#4b1d4a","#4c1d4b","#4e1d4b","#501d4c","#511e4d","#531e4d","#541e4e","#561e4f","#581e4f","#591e50","#5b1e51","#5c1e51","#5e1f52","#601f52","#611f53","#631f53","#641f54","#661f54","#681f55","#691f55","#6b1f56","#6d1f56","#6e1f57","#701f57","#711f57","#731f58","#751f58","#761f58","#781f59","#7a1f59","#7b1f59","#7d1f5a","#7f1e5a","#811e5a","#821e5a","#841e5a","#861e5b","#871e5b","#891e5b","#8b1d5b","#8c1d5b","#8e1d5b","#901d5b","#921c5b","#931c5b","#951c5b","#971c5b","#981b5b","#9a1b5b","#9c1b5b","#9e1a5b","#9f1a5b","#a11a5b","#a3195b","#a4195b","#a6195a","#a8185a","#aa185a","#ab185a","#ad1759","#af1759","#b01759","#b21758","#b41658","#b51657","#b71657","#b91657","#ba1656","#bc1656","#bd1655","#bf1654","#c11754","#c21753","#c41753","#c51852","#c71951","#c81951","#ca1a50","#cb1b4f","#cd1c4e","#ce1d4e","#cf1e4d","#d11f4c","#d2204c","#d3214b","#d5224a","#d62449","#d72549","#d82748","#d92847","#db2946","#dc2b46","#dd2c45","#de2e44","#df2f44","#e03143","#e13342","#e23442","#e33641","#e43841","#e53940","#e63b40","#e73d3f","#e83f3f","#e8403e","#e9423e","#ea443e","#eb463e","#eb483e","#ec4a3e","#ec4c3e","#ed4e3e","#ed503e","#ee523f","#ee543f","#ef5640","#ef5840","#ef5a41","#f05c42","#f05e42","#f06043","#f16244","#f16445","#f16646","#f26747","#f26948","#f26b49","#f26d4b","#f26f4c","#f3714d","#f3734e","#f37450","#f37651","#f37852","#f47a54","#f47c55","#f47d57","#f47f58","#f4815a","#f4835b","#f4845d","#f4865e","#f58860","#f58a61","#f58b63","#f58d64","#f58f66","#f59067","#f59269","#f5946b","#f5966c","#f5976e","#f59970","#f69b71","#f69c73","#f69e75","#f6a077","#f6a178","#f6a37a","#f6a47c","#f6a67e","#f6a880","#f6a981","#f6ab83","#f6ad85","#f6ae87","#f6b089","#f6b18b","#f6b38d","#f6b48f","#f6b691","#f6b893","#f6b995","#f6bb97","#f6bc99","#f6be9b","#f6bf9d","#f6c19f","#f7c2a2","#f7c4a4","#f7c6a6","#f7c7a8","#f7c9aa","#f7caac","#f7ccaf","#f7cdb1","#f7cfb3","#f7d0b5","#f8d1b8","#f8d3ba","#f8d4bc","#f8d6be","#f8d7c0","#f8d9c3","#f8dac5","#f8dcc7","#f9ddc9","#f9dfcb","#f9e0cd","#f9e2d0","#f9e3d2","#f9e5d4","#fae6d6","#fae8d8","#fae9da","#faebdd"],Ou=["#0b0405","#0d0406","#0e0508","#0f0609","#10060a","#11070c","#12080d","#13090f","#140910","#150a12","#160b13","#170c15","#180d16","#190e18","#1a0e19","#1b0f1a","#1c101c","#1d111d","#1e111f","#1f1220","#201322","#211423","#221425","#231526","#241628","#251729","#26172b","#27182d","#28192e","#291930","#291a31","#2a1b33","#2b1c35","#2c1c36","#2d1d38","#2e1e39","#2e1e3b","#2f1f3d","#30203e","#312140","#312142","#322243","#332345","#342447","#342548","#35254a","#35264c","#36274d","#37284f","#372851","#382953","#382a54","#392b56","#3a2c58","#3a2c59","#3b2d5b","#3b2e5d","#3b2f5f","#3c3060","#3c3162","#3d3164","#3d3266","#3e3367","#3e3469","#3e356b","#3f366d","#3f366f","#3f3770","#403872","#403974","#403a76","#403b78","#403c79","#413d7b","#413e7d","#413e7f","#413f80","#414082","#414184","#414285","#414387","#414488","#40468a","#40478b","#40488d","#40498e","#3f4a8f","#3f4b90","#3f4c92","#3e4d93","#3e4f94","#3e5095","#3d5195","#3d5296","#3c5397","#3c5598","#3b5698","#3b5799","#3b589a","#3a599a","#3a5b9b","#3a5c9b","#395d9c","#395e9c","#385f9c","#38619d","#38629d","#38639d","#37649e","#37659e","#37669e","#37689f","#36699f","#366a9f","#366b9f","#366ca0","#366da0","#366fa0","#3670a0","#3671a0","#3572a1","#3573a1","#3574a1","#3575a1","#3576a2","#3578a2","#3579a2","#357aa2","#357ba3","#357ca3","#357da3","#357ea4","#347fa4","#3480a4","#3482a4","#3483a5","#3484a5","#3485a5","#3486a5","#3487a6","#3488a6","#3489a6","#348ba6","#348ca7","#348da7","#348ea7","#348fa7","#3490a8","#3491a8","#3492a8","#3493a8","#3495a9","#3496a9","#3497a9","#3498a9","#3499aa","#349aaa","#359baa","#359caa","#359eaa","#359fab","#35a0ab","#35a1ab","#36a2ab","#36a3ab","#36a4ab","#37a5ac","#37a6ac","#37a8ac","#38a9ac","#38aaac","#39abac","#39acac","#3aadac","#3aaead","#3bafad","#3cb1ad","#3cb2ad","#3db3ad","#3eb4ad","#3fb5ad","#3fb6ad","#40b7ad","#41b8ad","#42b9ad","#43baad","#44bcad","#45bdad","#46bead","#47bfad","#48c0ad","#49c1ad","#4bc2ad","#4cc3ad","#4dc4ad","#4fc5ad","#50c6ad","#52c7ad","#53c9ad","#55caad","#57cbad","#59ccad","#5bcdad","#5ecdad","#60ceac","#62cfac","#65d0ad","#68d1ad","#6ad2ad","#6dd3ad","#70d4ad","#73d4ad","#76d5ae","#79d6ae","#7cd6af","#7fd7af","#82d8b0","#85d9b1","#88d9b1","#8bdab2","#8edbb3","#91dbb4","#94dcb5","#96ddb5","#99ddb6","#9cdeb7","#9edfb8","#a1dfb9","#a4e0bb","#a6e1bc","#a9e1bd","#abe2be","#aee3c0","#b0e4c1","#b2e4c2","#b5e5c4","#b7e6c5","#b9e6c7","#bbe7c8","#bee8ca","#c0e9cc","#c2e9cd","#c4eacf","#c6ebd1","#c8ecd2","#caedd4","#ccedd6","#ceeed7","#d0efd9","#d2f0db","#d4f1dc","#d6f1de","#d8f2e0","#daf3e1","#dcf4e3","#def5e5"],Lu=["#000000","#111111","#222222","#333333","#444444","#555555","#666666","#777777","#888888","#999999","#aaaaaa","#bbbbbb","#cccccc","#dddddd","#eeeeee","#ffffff"],Bu=["#a8780d","#b3701b","#be6828","#c75f35","#cf5643","#d54b53","#db4066","#de357b","#df2a93","#dc25ad","#d529c4","#cc34d7","#c041e5","#b24fef","#a25cf3","#9168f4","#7d73f0","#687ce8","#5285dc","#3d8bcd","#2c90bc","#2093ac","#19959c","#12978c","#0c987c","#119a69","#249a52","#409839","#5e9420","#778d12","#8b860d","#9b7f0d"],Le=e=>e.slice().reverse(),ju={turbo:Au,"turbo-reversed":Le(Au),grey:Lu,"grey-reversed":Le(Lu),magma:$u,"magma-reversed":Le($u),inferno:Cu,"inferno-reversed":Le(Cu),plasma:Ru,"plasma-reversed":Le(Ru),viridis:Du,"viridis-reversed":Le(Du),cividis:Pu,"cividis-reversed":Le(Pu),rocket:Fu,"rocket-reversed":Le(Fu),mako:Ou,"mako-reversed":Le(Ou),"cmocean-phase":Bu,"cmocean-phase-reversed":Le(Bu)};var Uu=7,Hu=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23];function _e(e){if(e<0)return NaN;let n=0;for(;e<10;)n+=Math.log(e),e+=1;let t=Math.PI,i=e*e*e;return e*Math.log(e)-e-.5*Math.log(e)+.5*Math.log(2*t)+1/(12*e)-1/(360*i)+1/(1260*i*e*e)-n}function ne(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*ne(1-e));if(e>100)return Math.exp(_e(e));e-=1;let n=Hu[0];for(let i=1;i<Uu+2;i++)n+=Hu[i]/(e+i);let t=e+Uu+.5;return Math.sqrt(2*Math.PI)*Math.pow(t,e+.5)*Math.exp(-t)*n}function xp(e){let t=Math.log(1-e*e),i=2/(Math.PI*.147)+t/2;return Math.sign(e)*Math.sqrt(Math.sqrt(i*i-t/.147)-i)}function Zu(e){if(Number.isNaN(e)||e<-1||e>1)return NaN;if(e===0)return 0;if(e===1)return 1/0;if(e===-1)return-1/0;let n=e<0?-1:1,t=Math.abs(e),i=xp(t),r=Math.sqrt(Math.PI)/2;for(let s=0;s<4;s++)i-=(Sn(i)-t)*r*Math.exp(i*i);return n*i}function zn(e){if(Number.isNaN(e))return NaN;if(!Number.isFinite(e))return e>0?0:2;if(e<0)return 2-zn(-e);if(e<2)return 1-Sn(e);let n=1e-300,t=e===0?n:e,i=t,r=0;for(let s=1;s<=500;s++){let o=s/2;r=e+o*r,r===0&&(r=n),r=1/r,i=e+o/i,i===0&&(i=n);let a=i*r;if(t*=a,Math.abs(a-1)<1e-17)break}return Math.exp(-e*e)/(Math.sqrt(Math.PI)*t)}function Sn(e){if(Number.isNaN(e))return NaN;if(e===0)return 0;if(!Number.isFinite(e))return e>0?1:-1;let n=e<0?-1:1,t=Math.abs(e);if(t>=6)return n;let i=t*t,r=t,s=t;for(let o=1;o<200&&(r*=2*i/(2*o+1),s+=r,!(r<s*1e-18));o++);return n*(2/Math.sqrt(Math.PI))*Math.exp(-i)*s}var mi=.5772156649015329,Jn=[1/6,-1/30,1/42,-1/30,5/66,-691/2730,7/6,-3617/510,43867/798,-174611/330];function hi(e){if(!isFinite(e))return NaN;if(e<0)return Number.isInteger(e)?NaN:hi(1-e)-Math.PI/Math.tan(Math.PI*e);if(e===0)return NaN;let n=0,t=e;for(;t<7;)n-=1/t,t+=1;n+=Math.log(t)-1/(2*t);let i=t*t;for(let r=0;r<Jn.length;r++)n-=Jn[r]/(2*(r+1)*i),i*=t*t;return n}function gi(e){if(!isFinite(e))return NaN;if(e<0){if(Number.isInteger(e))return NaN;let r=Math.sin(Math.PI*e);return Math.PI*Math.PI/(r*r)-gi(1-e)}if(e===0)return NaN;let n=0,t=e;for(;t<7;)n+=1/(t*t),t+=1;n+=1/t+1/(2*t*t);let i=t*t*t;for(let r=0;r<Jn.length;r++)n+=Jn[r]/i,i*=t*t;return n}function Dr(e,n){if(!Number.isInteger(e)||e<0)return NaN;if(e===0)return hi(n);if(e===1)return gi(n);if(!isFinite(n)||n===0)return NaN;if(n<0){if(Number.isInteger(n))return NaN;let a=0,u=n,l=e%2===0?1:-1;for(;u<1;)a+=l*qn(e)/Math.pow(u,e+1),u+=1;return a+Dr(e,u)}let t=0,i=n,r=e%2===0?-1:1;for(;i<7;)t+=r*qn(e)/Math.pow(i,e+1),i+=1;let s=e%2===0?-1:1;t+=s*qn(e-1)/Math.pow(i,e),t+=s*qn(e)/(2*Math.pow(i,e+1));let o=Math.pow(i,e+2);for(let a=0;a<Math.min(Jn.length,6);a++){let u=2*(a+1),l=1;for(let c=0;c<u;c++)l*=e+c;t+=s*Jn[a]*l/(qn(u)*o),o*=i*i}return t}function qn(e){if(e<=1)return 1;let n=1;for(let t=2;t<=e;t++)n*=t;return n}function Yu(e,n){return e>100||n>100||e+n>100?Math.exp(_e(e)+_e(n)-_e(e+n)):ne(e)*ne(n)/ne(e+n)}function Pr(e){if(!isFinite(e))return NaN;if(e===1)return 1/0;if(e===0)return-.5;if(e===2)return Math.PI*Math.PI/6;if(e===4)return Math.PI**4/90;if(e===6)return Math.PI**6/945;if(e===8)return Math.PI**8/9450;if(e<0)return Math.pow(2,e)*Math.pow(Math.PI,e-1)*Math.sin(Math.PI*e/2)*ne(1-e)*Pr(1-e);let n=22,t=vp(n),i=t[n],r=0;for(let s=0;s<=n;s++)r+=(s%2===0?1:-1)*(t[s]-i)/Math.pow(s+1,e);return-1/(i*(1-Math.pow(2,1-e)))*r}function vp(e){let n=new Array(e+1);n[0]=1;for(let t=1;t<=e;t++)n[t]=n[t-1]+Ep(e,t);return n}function Ep(e,n){n>e-n&&(n=e-n);let t=1;for(let i=0;i<n;i++)t=t*(e-i)/(i+1);return t}function Wu(e){if(!isFinite(e))return e;if(e===0)return 0;let n=1/Math.E;if(e<-n)return NaN;if(Math.abs(e+n)<1e-15)return-1;let t;if(e<0){let i=Math.sqrt(2*(Math.E*e+1));t=-1+i-i*i/3+11/72*i*i*i}else if(e<=1)t=e*(1-e*(1-1.5*e));else if(e<100){let i=Math.log(e);t=i-Math.log(i)}else{let i=Math.log(e),r=Math.log(i);t=i-r+r/i}for(let i=0;i<30;i++){let r=Math.exp(t),o=t*r-e,a=r*(t+1),u=r*(t+2),l=o/(a-o*u/(2*a));if(t-=l,Math.abs(l)<1e-15*(1+Math.abs(t)))break}return t}function an(e,n){return!isFinite(n)||!Number.isInteger(e)?NaN:n===0?e===0?1:0:e<0?(e=-e,e%2===0?an(e,n):-an(e,n)):n<0?e%2===0?an(e,-n):-an(e,-n):n>25+e*e/2?Tp(e,n):n<5+e?Np(e,n):Ip(e,n)}function Np(e,n){let t=n/2,i=-(n*n)/4,r=1;for(let o=1;o<=e;o++)r/=o;let s=r;for(let o=1;o<=60&&(r*=i/(o*(e+o)),s+=r,!(Math.abs(r)<Math.abs(s)*1e-16));o++);return s*Math.pow(t,e)}function Xu(e,n){let t=4*e*e,i=1,r=0,s=1,o=8*n;for(let a=1;a<=20;a++){s*=t-(2*a-1)*(2*a-1);let u=qn(a)*Math.pow(o,a),l=s/u;if(a%2===1?r+=(a%4===1?1:-1)*l:i+=(a%4===2?-1:1)*l,Math.abs(l)<1e-15)break}return[i,r]}function Tp(e,n){let t=n-(e/2+.25)*Math.PI,[i,r]=Xu(e,n);return Math.sqrt(2/(Math.PI*n))*(i*Math.cos(t)-r*Math.sin(t))}function Ip(e,n){let t=Math.max(e+20,Math.ceil(n)+30),i=0,r=1,s=new Array(t+1);s[t]=r;for(let u=t;u>=1;u--){let l=2*u/n*r-i;i=r,r=l,s[u-1]=r}let o=s[0];for(let u=2;u<=t;u+=2)o+=2*s[u];let a=1/o;return s[e]*a}function di(e,n){if(!isFinite(n)||!Number.isInteger(e))return NaN;if(n<=0)return NaN;if(e<0)return e=-e,e%2===0?di(e,n):-di(e,n);if(n>12+e*e/4)return kp(e,n);let t=_p(n);if(e===0)return t;let i=Sp(n);if(e===1)return i;let r=t,s=i;for(let o=1;o<e;o++){let a=2*o/n*s-r;r=s,s=a}return s}function _p(e){let n=e/2,t=n*n,i=an(0,e),r=0,s=1,o=0;for(let a=1;a<=60&&(o+=1/a,s*=-t/(a*a),r-=s*o,!(Math.abs(s*o)<Math.abs(r)*1e-16));a++);return 2/Math.PI*(i*(Math.log(n)+mi)+r)}function Sp(e){let n=e/2,t=n*n,i=an(1,e),r=0,s=1,o=1;for(let a=0;a<=60;a++){a>0&&(o*=a,s*=t);let u=o*(a+1),l=0;for(let v=1;v<=a;v++)l+=1/v;let c=l+1/(a+1),f=-mi+l,d=-mi+c,g=(a%2===0?1:-1)*(f+d)*s/(o*u);if(r+=g,a>3&&Math.abs(g)<1e-16*Math.abs(r))break}return-2/(Math.PI*e)+2/Math.PI*Math.log(n)*i-n/Math.PI*r}function kp(e,n){let t=n-(e/2+.25)*Math.PI,[i,r]=Xu(e,n);return Math.sqrt(2/(Math.PI*n))*(i*Math.sin(t)+r*Math.cos(t))}function _n(e,n){return!isFinite(n)||!Number.isInteger(e)?NaN:n===0?e===0?1:0:(e<0&&(e=-e),n<0?e%2===0?_n(e,-n):-_n(e,-n):n>40?wp(e,n):Mp(e,n))}function Mp(e,n){let t=n/2,i=n*n/4,r=1;for(let o=1;o<=e;o++)r/=o;let s=r;for(let o=1;o<=80&&(r*=i/(o*(e+o)),s+=r,!(Math.abs(r)<Math.abs(s)*1e-16));o++);return s*Math.pow(t,e)}function wp(e,n){let t=4*e*e,i=1,r=1;for(let s=1;s<=12;s++){let o=t-(2*s-1)*(2*s-1);if(i*=o/(s*8*n),r+=i,Math.abs(i)<1e-15)break}return Math.exp(n)/Math.sqrt(2*Math.PI*n)*r}function Qu(e,n){if(!isFinite(n)||!Number.isInteger(e))return NaN;if(n<=0)return NaN;if(e<0&&(e=-e),n>40)return $p(e,n);let t=Ku(n);if(e===0)return t;let i=Ap(n);if(e===1)return i;let r=t,s=i;for(let o=1;o<e;o++){let a=2*o/n*s+r;r=s,s=a}return s}function Ku(e){let n=e/2,t=n*n,i=_n(0,e),r=0,s=1,o=0;for(let a=1;a<=60&&(o+=1/a,s*=t/(a*a),r+=s*o,!(Math.abs(s*o)<Math.abs(r)*1e-16&&a>3));a++);return-(Math.log(n)+mi)*i+r}function Ap(e){let n=_n(0,e),t=_n(1,e),i=Ku(e);return(1/e-t*i)/n}function $p(e,n){let t=4*e*e,i=1,r=1;for(let s=1;s<=12;s++){let o=t-(2*s-1)*(2*s-1);if(i*=o/(s*8*n),r+=i,Math.abs(i)<1e-15)break}return Math.sqrt(Math.PI/(2*n))*Math.exp(-n)*r}function el(e){if(!isFinite(e))return NaN;if(e>5){let a=.6666666666666666*Math.pow(e,1.5);return Cp(e,a)}if(e<-5){let a=-e,u=2/3*Math.pow(a,1.5);return Rp(a,u)}let n=1/(Math.pow(3,2/3)*ne(2/3)),t=1/(Math.pow(3,1/3)*ne(1/3)),i=1,r=e,s=1,o=e;for(let a=1;a<=80;a++){let u=3*a;if(s*=e*e*e/((u-1)*u),o*=e*e*e/(u*(u+1)),i+=s,r+=o,Math.abs(s)+Math.abs(o)<1e-16*(Math.abs(i)+Math.abs(r)))break}return n*i-t*r}function Cp(e,n){let t=Math.pow(e,.25),i=1,r=1,s=[1,5/72,385/10368,85085/2239488,37182145/644972544];for(let o=1;o<s.length;o++)r=s[o]/Math.pow(n,o),i+=(o%2===0?1:-1)*r;return Math.exp(-n)/(2*Math.sqrt(Math.PI)*t)*i}function Rp(e,n){let t=Math.pow(e,.25);return Math.sin(n+Math.PI/4)/(Math.sqrt(Math.PI)*t)}function nl(e){if(!isFinite(e))return NaN;if(e>5){let a=.6666666666666666*Math.pow(e,1.5);return Dp(e,a)}if(e<-5){let a=-e,u=2/3*Math.pow(a,1.5);return Pp(a,u)}let n=1/(Math.pow(3,2/3)*ne(2/3)),t=1/(Math.pow(3,1/3)*ne(1/3)),i=1,r=e,s=1,o=e;for(let a=1;a<=80;a++){let u=3*a;if(s*=e*e*e/((u-1)*u),o*=e*e*e/(u*(u+1)),i+=s,r+=o,Math.abs(s)+Math.abs(o)<1e-16*(Math.abs(i)+Math.abs(r)))break}return Math.sqrt(3)*(n*i+t*r)}function Dp(e,n){let t=Math.pow(e,.25),i=1,r=1,s=[1,5/72,385/10368,85085/2239488,37182145/644972544];for(let o=1;o<s.length;o++)r=s[o]/Math.pow(n,o),i+=r;return Math.exp(n)/(Math.sqrt(Math.PI)*t)*i}function Pp(e,n){let t=Math.pow(e,.25);return Math.cos(n+Math.PI/4)/(Math.sqrt(Math.PI)*t)}var Fp=[-2991.8191940101983,708840.0452577386,-6297414862058625e-8,25489088057337637e-7,-4429795180596978e-5,3180162978765678e-4],Op=[1,281.3762688899943,45584.78108065326,5173438887700964e-9,4193202458981112e-7,22441179564534092e-6,607366389490085e-3],Lp=[-49884311457357354e-24,9504280628298596e-21,-.0006451914356839651,.018884331939670384,-.20552590095501388,1],Bp=[399982968972496e-26,9154392157746574e-25,12500186247959882e-23,12226278902417902e-21,.0008680295429417843,.04121420907221998,1],tl=[.4215435550436775,.1434079197807589,.011522095507358577,.000345017939782574,46361374928786735e-22,3055689837902576e-23,10230451416490724e-26,17201074326816183e-29,13428327623306275e-32,3763297112699879e-35],il=[1,.7515863983533789,.11688892585919138,.0064405152650885865,.00015593440916415301,18462756734893055e-22,11269922476399903e-24,36014002958937136e-27,5887545336215784e-29,45200143407412973e-33,12544323709001127e-36],rl=[.5044420736433832,.1971028335255234,.018764858409257526,.0006840793809153931,11513882611188428e-21,9828524436884223e-23,44534441586175015e-26,10826804113902088e-28,1375554606332618e-30,8363544356306774e-34,18695871016278324e-38],sl=[1,1.4749575992512833,.33774898912002,.02536037414203388,.0008146791071843061,12754507566772912e-21,10431458965757199e-23,46068072851523205e-26,11027321506624028e-28,13879653125957886e-31,8391588162831187e-34,18695871016278324e-38];function Ie(e,n){let t=n[0];for(let i=1;i<n.length;i++)t=t*e+n[i];return t}function un(e){if(!isFinite(e))return e!==e?NaN:e>0?.5:-.5;let n=e<0?-1:1;if(e=Math.abs(e),e<1.6){let t=e*e,i=t*t;return n*e*t*Ie(i,Fp)/Ie(i,Op)}if(e<36974){let t=e*e,i=Math.PI*t,r=1/(i*i),s=1-r*Ie(r,tl)/Ie(r,il),o=1/i*Ie(r,rl)/Ie(r,sl),a=Math.PI/2*t,u=Math.cos(a),l=Math.sin(a);return n*(.5-(s*u+o*l)/(Math.PI*e))}return n*.5}function ln(e){if(!isFinite(e))return e!==e?NaN:e>0?.5:-.5;let n=e<0?-1:1;if(e=Math.abs(e),e<1.6){let t=e*e,i=t*t;return n*e*Ie(i,Lp)/Ie(i,Bp)}if(e<36974){let t=e*e,i=Math.PI*t,r=1/(i*i),s=1-r*Ie(r,tl)/Ie(r,il),o=1/i*Ie(r,rl)/Ie(r,sl),a=Math.PI/2*t,u=Math.cos(a),l=Math.sin(a);return n*(.5+(s*l-o*u)/(Math.PI*e))}return n*.5}function ol(e){return e===0?1:Math.sin(e)/e}var bt=[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1],[1,6,15,20,15,6,1],[1,7,21,35,35,21,7,1],[1,8,28,56,70,56,28,8,1]];function yt(e,n){for(;e>=bt.length;){let t=bt.length,i=[1],r=bt[t-1];for(let s=1;s<t;s++)i[s]=r[s-1]+r[s];i[t]=1,bt.push(i)}return bt[e][n]}function ul(e){let n=0,t=0;for(let i of e)n+=i,t++;return t===0?NaN:n/t}function xt(e){let n=[...e].sort((i,r)=>i-r),t=Math.floor(n.length/2);return n.length%2===0?(n[t-1]+n[t])/2:n[t]}function Fr(e){let n=0,t=0,i=0;for(let r of e)n+=r,t+=r*r,i++;return i===0?NaN:(t-n*n/i)/(i-1)}function Or(e){let n=0,t=0,i=0;for(let r of e)n+=r,t+=r*r,i++;return i===0?NaN:(t-n*n/i)/i}function ll(e){return Math.sqrt(Fr(e))}function cl(e){return Math.sqrt(Or(e))}function fl(e){let n=0,t=0,i=0,r=0,s=0;for(let c of e){let f=c;if(!Number.isFinite(f))return NaN;n+=f,t+=f*f,i+=f*f*f,r+=f*f*f*f,s++}if(s===0)return NaN;let o=s,a=n/o,u=(t-n*n/o)/o;return(r-4*a*i+6*a*a*t-4*a*a*a*n+o*a*a*a*a)/o/(u*u)}function pl(e){let n=0,t=0,i=0,r=0;for(let l of e){let c=l;if(!Number.isFinite(c))return NaN;n+=c,t+=c*c,i+=c*c*c,r++}if(r===0)return NaN;let s=r,o=n/s,a=(t-n*n/s)/s;return(i-3*o*t+3*o*o*n-s*o*o*o)/s/Math.pow(a,3/2)}function ml(e){let n={};for(let r of e)n[r]=(n[r]??0)+1;let t=0,i=NaN;for(let r in n){let s=n[r];s>t&&(t=s,i=+r)}return i}function Lr(e){let n=[...e].sort((o,a)=>o-a),t=Math.floor(n.length/2),i=xt(n.slice(0,t)),r=xt(n),s=xt(n.slice(t));return[i,r,s]}function dl(e){let[n,,t]=Lr(e);return t-n}function jp(e,n){if(n===0)return{estimate:e,error:n};let t=Math.abs(n),i=Math.floor(Math.log10(t)),r=2,s=Math.pow(10,i-(r-1)),o=Math.round(n/s)*s,a=Math.max(0,-(i-(r-1)));return{estimate:Number(e.toFixed(a)),error:o}}function hl(e,n,t,i=1e5){let r=0,s=0;if(n===-1/0&&t===1/0)for(let m=0;m<i;m++){let g=Math.random(),v=Math.tan(Math.PI*(g-.5)),N=e(v)*Math.PI*(1+v*v);r+=N,s+=N*N}else if(n===-1/0)for(let m=0;m<i;m++){let g=Math.random(),v=t+Math.log(g),N=e(v)/g;r+=N,s+=N*N}else if(t===1/0)for(let m=0;m<i;m++){let g=Math.random(),v=n-Math.log(g),N=e(v)/g;r+=N,s+=N*N}else for(let m=0;m<i;m++){let g=e(n+Math.random()*(t-n));r+=g,s+=g*g}let o=r/i,a=(s-i*o*o)/(i-1),u=Math.sqrt(a/i),l=isFinite(n)&&isFinite(t)?t-n:1,c=o*l,f=u*l;return jp(c,f)}var Br={Add:["+",11],Negate:["-",14],Subtract:["-",11],Multiply:["*",12],Divide:["/",13],Equal:["===",8],NotEqual:["!==",8],LessEqual:["<=",9],GreaterEqual:[">=",9],Less:["<",9],Greater:[">",9],And:["&&",4],Or:["||",3],Not:["!",14]},Vr={Abs:(e,n)=>b.isComplexValued(e[0])?`_SYS.cabs(${n(e[0])})`:b.isNonNegative(e[0])?n(e[0]):`Math.abs(${n(e[0])})`,Add:(e,n)=>{if(e.length===1)return n(e[0]);if(!e.some(o=>b.isComplexValued(o))){let o=e.map(Q);if(o.every(u=>u!==void 0))return String(o.reduce((u,l)=>u+l,0));let a=e.filter(u=>Q(u)!==0);return a.length===0?"0":a.length===1?n(a[0]):`(${a.map(u=>n(u)).join(" + ")})`}let i=e.map(o=>({code:n(o),isComplex:b.isComplexValued(o)})),r=i.map(o=>o.isComplex?`(${o.code}).re`:o.code),s=i.filter(o=>o.isComplex).map(o=>`(${o.code}).im`);return`({ re: ${r.join(" + ")}, im: ${s.join(" + ")} })`},Arccos:(e,n)=>b.isComplexValued(e[0])?`_SYS.cacos(${n(e[0])})`:`Math.acos(${n(e[0])})`,Arcosh:"Math.acosh",Arccot:([e],n)=>{if(e===null)throw new Error("Arccot: no argument");return b.isComplexValued(e)?`_SYS.cacot(${n(e)})`:`Math.atan(1 / (${n(e)}))`},Arcoth:([e],n)=>{if(e===null)throw new Error("Arcoth: no argument");return b.isComplexValued(e)?`_SYS.cacoth(${n(e)})`:`Math.atanh(1 / (${n(e)}))`},Arccsc:([e],n)=>{if(e===null)throw new Error("Arccsc: no argument");return b.isComplexValued(e)?`_SYS.cacsc(${n(e)})`:`Math.asin(1 / (${n(e)}))`},Arcsch:([e],n)=>{if(e===null)throw new Error("Arcsch: no argument");return b.isComplexValued(e)?`_SYS.cacsch(${n(e)})`:`Math.asinh(1 / (${n(e)}))`},Arcsec:([e],n)=>{if(e===null)throw new Error("Arcsec: no argument");return b.isComplexValued(e)?`_SYS.casec(${n(e)})`:`Math.acos(1 / (${n(e)}))`},Arsech:([e],n)=>{if(e===null)throw new Error("Arsech: no argument");return b.isComplexValued(e)?`_SYS.casech(${n(e)})`:`Math.acosh(1 / (${n(e)}))`},Arcsin:(e,n)=>b.isComplexValued(e[0])?`_SYS.casin(${n(e[0])})`:`Math.asin(${n(e[0])})`,Arsinh:"Math.asinh",Arctan:(e,n)=>b.isComplexValued(e[0])?`_SYS.catan(${n(e[0])})`:`Math.atan(${n(e[0])})`,Artanh:"Math.atanh",Ceil:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`Math.ceil(${n(e[0])})`,Chop:"_SYS.chop",Cos:(e,n)=>b.isComplexValued(e[0])?`_SYS.ccos(${n(e[0])})`:`Math.cos(${n(e[0])})`,Cosh:(e,n)=>b.isComplexValued(e[0])?`_SYS.ccosh(${n(e[0])})`:`Math.cosh(${n(e[0])})`,Cot:([e],n)=>{if(e===null)throw new Error("Cot: no argument");return b.isComplexValued(e)?`_SYS.ccot(${n(e)})`:b.inlineExpression("Math.cos(${x}) / Math.sin(${x})",n(e))},Coth:([e],n)=>{if(e===null)throw new Error("Coth: no argument");return b.isComplexValued(e)?`_SYS.ccoth(${n(e)})`:b.inlineExpression("(Math.cosh(${x}) / Math.sinh(${x}))",n(e))},Csc:([e],n)=>{if(e===null)throw new Error("Csc: no argument");return b.isComplexValued(e)?`_SYS.ccsc(${n(e)})`:`1 / Math.sin(${n(e)})`},Csch:([e],n)=>{if(e===null)throw new Error("Csch: no argument");return b.isComplexValued(e)?`_SYS.ccsch(${n(e)})`:`1 / Math.sinh(${n(e)})`},Exp:(e,n)=>b.isComplexValued(e[0])?`_SYS.cexp(${n(e[0])})`:`Math.exp(${n(e[0])})`,First:(e,n)=>`${n(e[0])}[0]`,Floor:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`Math.floor(${n(e[0])})`,Fract:([e],n)=>{if(e===null)throw new Error("Fract: no argument");return b.inlineExpression("${x} - Math.floor(${x})",n(e))},Gamma:"_SYS.gamma",GCD:"_SYS.gcd",Integrate:(e,n,t)=>Yp(e,n,t),LCM:"_SYS.lcm",Product:(e,n,t)=>bl("Product",e,n,t),Sum:(e,n,t)=>bl("Sum",e,n,t),Limit:(e,n)=>`_SYS.limit(${n(e[0])}, ${n(e[1])})`,Ln:(e,n)=>b.isComplexValued(e[0])?`_SYS.cln(${n(e[0])})`:`Math.log(${n(e[0])})`,List:(e,n)=>`[${e.map(t=>n(t)).join(", ")}]`,Matrix:(e,n)=>n(e[0]),Tuple:(e,n)=>`[${e.map(t=>n(t)).join(", ")}]`,Log:(e,n)=>e.length===1?`Math.log10(${n(e[0])})`:`(Math.log(${n(e[0])}) / Math.log(${n(e[1])}))`,GammaLn:"_SYS.lngamma",Lb:"Math.log2",Max:"Math.max",Mean:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.mean(${n(e[0])})`:`_SYS.mean([${e.map(t=>n(t)).join(", ")}])`,Median:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.median(${n(e[0])})`:`_SYS.median([${e.map(t=>n(t)).join(", ")}])`,Variance:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.variance(${n(e[0])})`:`_SYS.variance([${e.map(t=>n(t)).join(", ")}])`,PopulationVariance:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.populationVariance(${n(e[0])})`:`_SYS.populationVariance([${e.map(t=>n(t)).join(", ")}])`,StandardDeviation:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.standardDeviation(${n(e[0])})`:`_SYS.standardDeviation([${e.map(t=>n(t)).join(", ")}])`,PopulationStandardDeviation:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.populationStandardDeviation(${n(e[0])})`:`_SYS.populationStandardDeviation([${e.map(t=>n(t)).join(", ")}])`,Kurtosis:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.kurtosis(${n(e[0])})`:`_SYS.kurtosis([${e.map(t=>n(t)).join(", ")}])`,Skewness:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.skewness(${n(e[0])})`:`_SYS.skewness([${e.map(t=>n(t)).join(", ")}])`,Mode:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.mode(${n(e[0])})`:`_SYS.mode([${e.map(t=>n(t)).join(", ")}])`,Quartiles:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.quartiles(${n(e[0])})`:`_SYS.quartiles([${e.map(t=>n(t)).join(", ")}])`,InterquartileRange:(e,n)=>e.length===0?"NaN":e.length===1?`_SYS.interquartileRange(${n(e[0])})`:`_SYS.interquartileRange([${e.map(t=>n(t)).join(", ")}])`,Min:"Math.min",Power:(e,n)=>{let t=e[0],i=e[1];if(t===null)throw new Error("Power: no argument");if(b.isComplexValued(t)||b.isComplexValued(i))return`_SYS.cpow(${n(t)}, ${n(i)})`;let r=Q(t),s=Q(i);if(r!==void 0&&s!==void 0)return String(Math.pow(r,s));if(s===0)return"1";if(s===1)return n(t);if(s===2&&(T(t)||R(t))){let o=n(t);return`(${o} * ${o})`}return s===-1?`(1 / (${n(t)}))`:s===.5?`Math.sqrt(${n(t)})`:s===1/3?`Math.cbrt(${n(t)})`:s===-.5?`(1 / Math.sqrt(${n(t)}))`:`Math.pow(${n(t)}, ${n(i)})`},Range:(e,n)=>{if(e.length===0)return"[]";if(e.length===1)return`Array.from({length: ${n(e[0])}}, (_, i) => i)`;let t=n(e[0]),i=n(e[1]),r=e[2]?n(e[2]):"1";if(t===null)throw new Error("Range: no start");if(i===null&&(i=t,t="1"),r==="0")throw new Error("Range: step cannot be zero");if(parseFloat(r)===1){let s=parseFloat(i),o=parseFloat(t);return!isNaN(s)&&!isNaN(o)?s-o<50?`[${Array.from({length:s-o+1},(a,u)=>o+u).join(", ")}]`:`Array.from({length: ${s-o+1}
45
45
  }, (_, i) => ${t} + i)`:`Array.from({length: ${i} - ${t} + 1
46
- }, (_, i) => ${t} + i)`}return`Array.from({length: Math.floor((${i} - ${t}) / ${r}) + 1}, (_, i) => ${t} + i * ${r})`},Root:([e,n],t)=>{if(e===null)throw new Error("Root: no argument");if(n===null)return`Math.sqrt(${t(e)})`;let i=X(e),r=X(n);return i!==void 0&&r!==void 0&&r!==0?String(Math.pow(i,1/r)):r===2?`Math.sqrt(${t(e)})`:r===3?`Math.cbrt(${t(e)})`:r!==void 0?`Math.pow(${t(e)}, ${1/r})`:`Math.pow(${t(e)}, 1 / (${t(n)}))`},Random:(e,n)=>{if(e.length===0)return"Math.random()";if(e.length===2){let r=n(e[0]),s=n(e[1]);return`((${r}) + Math.floor(Math.random() * ((${s}) - (${r}))))`}let t=e[0];return g.isIntegerValued(t)?`Math.floor(Math.random() * (${n(t)}))`:`(() => { const _s = (${n(t)}) * 12.9898; const _v = Math.sin(_s) * 43758.5453; return _v - Math.floor(_v); })()`},Round:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`Math.round(${n(e[0])})`,Square:(e,n)=>{let t=e[0];if(t===null)throw new Error("Square: no argument");let i=X(t);if(i!==void 0)return String(i*i);if(k(t)){let r=n(t);return`(${r} * ${r})`}return`Math.pow(${n(t)}, 2)`},Sec:(e,n)=>{let t=e[0];if(t===null)throw new Error("Sec: no argument");return g.isComplexValued(t)?`_SYS.csec(${n(t)})`:`1 / Math.cos(${n(t)})`},Sech:(e,n)=>{let t=e[0];if(t===null)throw new Error("Sech: no argument");return g.isComplexValued(t)?`_SYS.csech(${n(t)})`:`1 / Math.cosh(${n(t)})`},Second:(e,n)=>`${n(e[0])}[1]`,Heaviside:"_SYS.heaviside",Sign:"Math.sign",Sinc:"_SYS.sinc",FresnelS:"_SYS.fresnelS",FresnelC:"_SYS.fresnelC",Sin:(e,n)=>g.isComplexValued(e[0])?`_SYS.csin(${n(e[0])})`:`Math.sin(${n(e[0])})`,Sinh:(e,n)=>g.isComplexValued(e[0])?`_SYS.csinh(${n(e[0])})`:`Math.sinh(${n(e[0])})`,Sqrt:(e,n)=>{if(g.isComplexValued(e[0]))return`_SYS.csqrt(${n(e[0])})`;let t=X(e[0]);return t!==void 0?String(Math.sqrt(t)):`Math.sqrt(${n(e[0])})`},Tan:(e,n)=>g.isComplexValued(e[0])?`_SYS.ctan(${n(e[0])})`:`Math.tan(${n(e[0])})`,Tanh:(e,n)=>g.isComplexValued(e[0])?`_SYS.ctanh(${n(e[0])})`:`Math.tanh(${n(e[0])})`,Third:(e,n)=>`${n(e[0])}[2]`,Mod:([e,n],t)=>{if(e===null||n===null)throw new Error("Mod: missing argument");let i=t(e),r=t(n);return g.isIntegerValued(e)&&g.isIntegerValued(n)&&g.isNonNegative(e)?`(${i} % ${r})`:`((${i} % ${r}) + ${r}) % ${r}`},Truncate:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`Math.trunc(${n(e[0])})`,Remainder:([e,n],t)=>{if(e===null||n===null)throw new Error("Remainder: missing argument");return`(${t(e)} - ${t(n)} * Math.round(${t(e)} / ${t(n)}))`},Divide:([e,n],t)=>{if(e===null||n===null)throw new Error("Divide: missing argument");let i=g.isComplexValued(e),r=g.isComplexValued(n);if(!i&&!r){let s=X(e),o=X(n);return s!==void 0&&o!==void 0&&o!==0?String(s/o):o===1?t(e):`(${t(e)} / ${t(n)})`}return i&&r?`(() => { const _a = ${t(e)}, _b = ${t(n)}, _d = _b.re * _b.re + _b.im * _b.im; return { re: (_a.re * _b.re + _a.im * _b.im) / _d, im: (_a.im * _b.re - _a.re * _b.im) / _d }; })()`:i&&!r?`(() => { const _a = ${t(e)}, _r = ${t(n)}; return { re: _a.re / _r, im: _a.im / _r }; })()`:`(() => { const _r = ${t(e)}, _b = ${t(n)}, _d = _b.re * _b.re + _b.im * _b.im; return { re: _r * _b.re / _d, im: -_r * _b.im / _d }; })()`},Negate:([e],n)=>{if(e===null)throw new Error("Negate: no argument");if(!g.isComplexValued(e)){let t=X(e);return t!==void 0?String(-t):`(-${n(e)})`}return`_SYS.cneg(${n(e)})`},Multiply:(e,n)=>{if(e.length===1)return n(e[0]);if(!e.some(o=>g.isComplexValued(o))){if(e.some(u=>X(u)===0))return"0";let o=e.map(X);if(o.every(u=>u!==void 0))return String(o.reduce((u,l)=>u*l,1));let a=e.filter(u=>X(u)!==1);return a.length===0?"1":a.length===1?n(a[0]):`(${a.map(u=>n(u)).join(" * ")})`}if(e.length===2){let o=g.isComplexValued(e[0]),a=g.isComplexValued(e[1]),u=n(e[0]),l=n(e[1]);return o&&a?`(() => { const _a = ${u}, _b = ${l}; return { re: _a.re * _b.re - _a.im * _b.im, im: _a.re * _b.im + _a.im * _b.re }; })()`:o&&!a?`(() => { const _a = ${u}, _r = ${l}; return { re: _a.re * _r, im: _a.im * _r }; })()`:`(() => { const _r = ${u}, _b = ${l}; return { re: _r * _b.re, im: _r * _b.im }; })()`}let i=[],r=[];for(let o=0;o<e.length;o++){let a=`_v${o}`;r.push(a),i.push(`const ${a} = ${n(e[o])}`)}let s=g.isComplexValued(e[0]);i.push(`let _re = ${s?`${r[0]}.re`:r[0]}`),i.push(`let _im = ${s?`${r[0]}.im`:"0"}`);for(let o=1;o<e.length;o++){let a=r[o],u=g.isComplexValued(e[o]),l=u?`${a}.re`:a,c=u?`${a}.im`:"0";i.push(`const _nre${o} = _re * ${l} - _im * ${c}`),i.push(`const _nim${o} = _re * ${c} + _im * ${l}`),i.push(`_re = _nre${o}`),i.push(`_im = _nim${o}`)}return`(() => { ${i.join("; ")}; return { re: _re, im: _im }; })()`},Factorial:"_SYS.factorial",Factorial2:"_SYS.factorial2",Exp2:([e],n)=>{if(e===null)throw new Error("Exp2: no argument");return`Math.pow(2, ${n(e)})`},Log2:"Math.log2",Log10:"Math.log10",Lg:"Math.log10",Arctan2:"Math.atan2",Hypot:"Math.hypot",Degrees:([e],n)=>{if(e===null)throw new Error("Degrees: no argument");return`(${n(e)} * Math.PI / 180)`},Haversine:([e],n)=>{if(e===null)throw new Error("Haversine: no argument");return g.inlineExpression("(1 - Math.cos(${x})) / 2",n(e))},InverseHaversine:([e],n)=>{if(e===null)throw new Error("InverseHaversine: no argument");return`(2 * Math.asin(Math.sqrt(${n(e)})))`},Erf:"_SYS.erf",Erfc:"_SYS.erfc",ErfInv:"_SYS.erfInv",Beta:"_SYS.beta",Digamma:"_SYS.digamma",Trigamma:"_SYS.trigamma",PolyGamma:(e,n)=>`_SYS.polygamma(${n(e[0])}, ${n(e[1])})`,Zeta:"_SYS.zeta",LambertW:"_SYS.lambertW",BesselJ:(e,n)=>`_SYS.besselJ(${n(e[0])}, ${n(e[1])})`,BesselY:(e,n)=>`_SYS.besselY(${n(e[0])}, ${n(e[1])})`,BesselI:(e,n)=>`_SYS.besselI(${n(e[0])}, ${n(e[1])})`,BesselK:(e,n)=>`_SYS.besselK(${n(e[0])}, ${n(e[1])})`,AiryAi:"_SYS.airyAi",AiryBi:"_SYS.airyBi",Mandelbrot:([e,n],t)=>{if(e===null||n===null)throw new Error("Mandelbrot: missing arguments");return`_SYS.mandelbrot(${t(e)}, ${t(n)})`},Julia:([e,n,t],i)=>{if(e===null||n===null||t===null)throw new Error("Julia: missing arguments");return`_SYS.julia(${i(e)}, ${i(n)}, ${i(t)})`},Binomial:(e,n)=>`_SYS.binomial(${n(e[0])}, ${n(e[1])})`,Fibonacci:"_SYS.fibonacci",Real:(e,n)=>g.isComplexValued(e[0])?`(${n(e[0])}).re`:n(e[0]),Imaginary:(e,n)=>g.isComplexValued(e[0])?`(${n(e[0])}).im`:"0",Argument:(e,n)=>g.isComplexValued(e[0])?`_SYS.carg(${n(e[0])})`:`(${n(e[0])} >= 0 ? 0 : Math.PI)`,Conjugate:(e,n)=>g.isComplexValued(e[0])?`_SYS.cconj(${n(e[0])})`:n(e[0]),Color:([e],n)=>{if(e===null)throw new Error("Color: no argument");return`_SYS.color(${n(e)})`},ColorToString:(e,n)=>{if(e.length===0)throw new Error("ColorToString: no argument");return e.length>=2?`_SYS.colorToString(${n(e[0])}, ${n(e[1])})`:`_SYS.colorToString(${n(e[0])})`},ColorMix:(e,n)=>{if(e.length<2)throw new Error("ColorMix: need two colors");return e.length>=3?`_SYS.colorMix(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`:`_SYS.colorMix(${n(e[0])}, ${n(e[1])})`},ColorContrast:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorContrast: need two colors");return`_SYS.colorContrast(${t(e)}, ${t(n)})`},ContrastingColor:(e,n)=>{if(e.length===0)throw new Error("ContrastingColor: no argument");return e.length>=3?`_SYS.contrastingColor(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`:`_SYS.contrastingColor(${n(e[0])})`},ColorToColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorToColorspace: need color and space");return`_SYS.colorToColorspace(${t(e)}, ${t(n)})`},ColorFromColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorFromColorspace: need components and space");return`_SYS.colorFromColorspace(${t(e)}, ${t(n)})`},Colormap:(e,n)=>{if(e.length===0)throw new Error("Colormap: no argument");return e.length>=2?`_SYS.colormap(${n(e[0])}, ${n(e[1])})`:`_SYS.colormap(${n(e[0])})`},Rgb:(e,n)=>{if(e.length<3)throw new Error("Rgb: need 3 components");return`_SYS.rgb(${e.map(n).join(", ")})`},Hsv:(e,n)=>{if(e.length<3)throw new Error("Hsv: need 3 components");return`_SYS.hsv(${e.map(n).join(", ")})`},Hsl:(e,n)=>{if(e.length<3)throw new Error("Hsl: need 3 components");return`_SYS.hsl(${e.map(n).join(", ")})`},Oklab:(e,n)=>{if(e.length<3)throw new Error("Oklab: need 3 components");return`_SYS.oklab(${e.map(n).join(", ")})`},Oklch:(e,n)=>{if(e.length<3)throw new Error("Oklch: need 3 components");return`_SYS.oklch(${e.map(n).join(", ")})`},AsRgb:([e],n)=>{if(e===null)throw new Error("AsRgb: no argument");return`_SYS.asRgb(${n(e)})`},AsHsv:([e],n)=>{if(e===null)throw new Error("AsHsv: no argument");return`_SYS.asHsv(${n(e)})`},AsHsl:([e],n)=>{if(e===null)throw new Error("AsHsl: no argument");return`_SYS.asHsl(${n(e)})`},AsOklab:([e],n)=>{if(e===null)throw new Error("AsOklab: no argument");return`_SYS.asOklab(${n(e)})`},AsOklch:([e],n)=>{if(e===null)throw new Error("AsOklch: no argument");return n(e)},ColorDelta:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorDelta: need two colors");return`_SYS.colorDelta(${t(e)}, ${t(n)})`},Distance:([e,n],t)=>{if(e===null||n===null)throw new Error("Distance: need two points");return`_SYS.distance(${t(e)}, ${t(n)})`}};function Y(e){return{re:e.re,im:e.im}}function Se(e){if(e!==void 0&&Number.isFinite(e)&&!(Math.abs(e-1)<1e-9))return e}function Fe(e){if(typeof e=="string"){let t=We(e),i={r:t>>>24&255,g:t>>>16&255,b:t>>>8&255},r=Se((t&255)/255);return r!==void 0&&(i.alpha=r),i}let n=ni({L:e[0],C:e[1],H:e[2]});if(e.length>=4){let t=Se(e[3]);t!==void 0&&(n.alpha=t)}return n}function pt(e){if(typeof e=="string"){let n=We(e),t=n>>>24&255,i=n>>>16&255,r=n>>>8&255,s=ve({r:t,g:i,b:r}),o=Se((n&255)/255);return o!==void 0&&(s.alpha=o),s}return{L:e[0],C:e[1],H:e[2],alpha:e.length>=4?Se(e[3]):void 0}}function oi(e){let n=e>>>24&255,t=e>>>16&255,i=e>>>8&255,r=ve({r:n,g:t,b:i}),s=Se((e&255)/255);return s!==void 0?[r.L,r.C,r.H,s]:[r.L,r.C,r.H]}var Gf={color(e){return oi(We(e))},colorToString(e,n){let t=Fe(e),i=(n??"hex").toLowerCase();switch(i){case"hex":{let r=Math.round(Math.max(0,Math.min(255,t.r))),s=Math.round(Math.max(0,Math.min(255,t.g))),o=Math.round(Math.max(0,Math.min(255,t.b))),a=`#${r.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;if(t.alpha!==void 0){let u=Math.round(Math.max(0,Math.min(255,t.alpha*255)));a+=u.toString(16).padStart(2,"0")}return a}case"rgb":{let r=Math.round(t.r),s=Math.round(t.g),o=Math.round(t.b);return t.alpha!==void 0?`rgb(${r} ${s} ${o} / ${t.alpha})`:`rgb(${r} ${s} ${o})`}case"hsl":{let r=ei(t.r,t.g,t.b),s=Math.round(r.h*10)/10,o=Math.round(r.s*1e3)/10,a=Math.round(r.l*1e3)/10;return t.alpha!==void 0?`hsl(${s} ${o}% ${a}% / ${t.alpha})`:`hsl(${s} ${o}% ${a}%)`}case"oklch":{let r=ve(t),s=Math.round(r.L*1e3)/1e3,o=Math.round(r.C*1e3)/1e3,a=Math.round(r.H*10)/10;return t.alpha!==void 0?`oklch(${s} ${o} ${a} / ${t.alpha})`:`oklch(${s} ${o} ${a})`}default:throw new Error(`Unknown color format: ${i}`)}},colorMix(e,n,t=.5){let i=pt(e),r=pt(n);t=Math.max(0,Math.min(1,t));let s=i.C<1e-6,o=r.C<1e-6,a;if(s&&o)a=i.H;else if(s)a=r.H;else if(o)a=i.H;else{let d=r.H-i.H;d>180&&(d-=360),d<-180&&(d+=360),a=i.H+d*t,a<0&&(a+=360),a>=360&&(a-=360)}let u=i.L+(r.L-i.L)*t,l=i.C+(r.C-i.C)*t,c=i.alpha??1,f=r.alpha??1,m=Se(c+(f-c)*t);return m!==void 0?[u,l,a,m]:[u,l,a]},colorContrast(e,n){return Qt(Fe(e),Fe(n))},contrastingColor(e,n,t){let i=Fe(e);return oi(n!==void 0&&t!==void 0?yr({bg:i,fg1:Fe(n),fg2:Fe(t)}):yr(i))},colorToColorspace(e,n){let t=Fe(e),i=t.alpha,r;switch(n.toLowerCase()){case"rgb":r=[t.r/255,t.g/255,t.b/255];break;case"hsl":{let s=ei(t.r,t.g,t.b);r=[s.h,s.s,s.l];break}case"oklch":{let s=ve(t);r=[s.L,s.C,s.H];break}case"oklab":case"lab":{let s=br(t);r=[s.L,s.a,s.b];break}default:throw new Error(`Unknown color space: ${n}`)}return i!==void 0&&r.push(i),r},colormap(e,n){let i={...tu,...eu,...nu}[e];if(!i)throw new Error(`Unknown palette: ${e}`);let r=i.map(o=>oi(We(o)));if(n===void 0)return r;if(Number.isInteger(n)&&n>=2){let o=n,a=[];for(let u=0;u<o;u++){let l=o===1?0:u/(o-1);a.push(this._interpolatePalette(r,l))}return a}let s=Math.max(0,Math.min(1,n));return this._interpolatePalette(r,s)},_interpolatePalette(e,n){if(e.length===0)return[0,0,0];if(n<=0)return[...e[0]];if(n>=1)return[...e[e.length-1]];let t=n*(e.length-1),i=Math.floor(t),r=t-i;if(r===0||i>=e.length-1)return[...e[Math.min(i,e.length-1)]];let[s,o,a]=e[i],[u,l,c]=e[i+1],f=o<1e-6,m=l<1e-6,d;if(f&&m)d=a;else if(f)d=c;else if(m)d=a;else{let b=c-a;b>180&&(b-=360),b<-180&&(b+=360),d=a+b*r,d<0&&(d+=360),d>=360&&(d-=360)}return[s+(u-s)*r,o+(l-o)*r,d]},colorFromColorspace(e,n){let t=e[0],i=e[1],r=e[2],s=e.length>=4?e[3]:void 0,o;switch(n.toLowerCase()){case"rgb":o=ve({r:t*255,g:i*255,b:r*255});break;case"hsl":{let a=Kt(t,i,r);o=ve(a);break}case"oklch":o={L:t,C:i,H:r};break;case"oklab":case"lab":o=lt({L:t,a:i,b:r});break;default:throw new Error(`Unknown color space: ${n}`)}return s!==void 0?[o.L,o.C,o.H,s]:[o.L,o.C,o.H]},rgb(e,n,t,i){let r=ve({r:e*255,g:n*255,b:t*255}),s=Se(i);return s!==void 0?[r.L,r.C,r.H,s]:[r.L,r.C,r.H]},hsv(e,n,t,i){let r=Xa(e,n,t),s=ve(r),o=Se(i);return o!==void 0?[s.L,s.C,s.H,o]:[s.L,s.C,s.H]},hsl(e,n,t,i){let r=Kt(e,n,t),s=ve({r:r.r,g:r.g,b:r.b}),o=Se(i);return o!==void 0?[s.L,s.C,s.H,o]:[s.L,s.C,s.H]},oklab(e,n,t,i){let r=lt({L:e,a:n,b:t}),s=Se(i);return s!==void 0?[r.L,r.C,r.H,s]:[r.L,r.C,r.H]},oklch(e,n,t,i){let r=Se(i);return r!==void 0?[e,n,t,r]:[e,n,t]},asRgb(e){let n=Fe(e),t=n.r/255,i=n.g/255,r=n.b/255;return n.alpha!==void 0?[t,i,r,n.alpha]:[t,i,r]},asHsv(e){let n=Fe(e),t=Qa(n.r,n.g,n.b);return n.alpha!==void 0?[t.h,t.s,t.v,n.alpha]:[t.h,t.s,t.v]},asHsl(e){let n=Fe(e),t=ei(n.r,n.g,n.b);return n.alpha!==void 0?[t.h,t.s,t.l,n.alpha]:[t.h,t.s,t.l]},asOklab(e){let n=pt(e),t=dn({L:n.L,C:n.C,H:n.H});return n.alpha!==void 0?[t.L,t.a,t.b,n.alpha]:[t.L,t.a,t.b]},colorDelta(e,n){let t=dn(pt(e)),i=dn(pt(n));return Ka(t,i)},distance(e,n){if(!Array.isArray(e)||!Array.isArray(n))throw new Error("Distance: expected two arrays");if(e.length!==n.length)throw new Error("Distance: dimension mismatch");let t=0;for(let i=0;i<e.length;i++){let r=e[i]-n[i];t+=r*r}return Math.sqrt(t)}},Au={chop:Zn,factorial:Un,factorial2:Hn,gamma:ie,gcd:Me,heaviside:e=>e<0?0:e===0?.5:1,integrate:(e,n,t)=>Su(e,n,t,1e7).estimate,lcm:Xe,lngamma:ke,limit:Tt,mean:xu,median:xn,variance:Er,populationVariance:Nr,standardDeviation:vu,populationStandardDeviation:Eu,kurtosis:Nu,skewness:Tu,mode:Iu,quartiles:_u,interquartileRange:ku,erf:Bn,erfc:ct,erfInv:su,beta:ou,digamma:ri,trigamma:si,polygamma:xr,zeta:vr,lambertW:au,besselJ:rn,besselY:ii,besselI:hn,besselK:lu,airyAi:fu,airyBi:pu,sinc:bu,fresnelS:gn,fresnelC:bn,mandelbrot:(e,n)=>{let t=0,i=0,r=typeof e=="number"?e:e.re,s=typeof e=="number"?0:e.im,o=Math.round(n);for(let a=0;a<o;a++){let u=t*t-i*i+r;i=2*t*i+s,t=u;let l=t*t+i*i;if(l>4){let c=(a-Math.log2(Math.log2(l))+4)/o;return Math.max(0,Math.min(1,c))}}return 1},julia:(e,n,t)=>{let i=typeof e=="number"?e:e.re,r=typeof e=="number"?0:e.im,s=typeof n=="number"?n:n.re,o=typeof n=="number"?0:n.im,a=Math.round(t);for(let u=0;u<a;u++){let l=i*i-r*r+s;r=2*i*r+o,i=l;let c=i*i+r*r;if(c>4){let f=(u-Math.log2(Math.log2(c))+4)/a;return Math.max(0,Math.min(1,f))}}return 1},binomial:yn,fibonacci:Sr,csin:e=>Y(new $(e.re,e.im).sin()),ccos:e=>Y(new $(e.re,e.im).cos()),ctan:e=>Y(new $(e.re,e.im).tan()),casin:e=>Y(new $(e.re,e.im).asin()),cacos:e=>Y(new $(e.re,e.im).acos()),catan:e=>Y(new $(e.re,e.im).atan()),csinh:e=>Y(new $(e.re,e.im).sinh()),ccosh:e=>Y(new $(e.re,e.im).cosh()),ctanh:e=>Y(new $(e.re,e.im).tanh()),csqrt:e=>Y(new $(e.re,e.im).sqrt()),cexp:e=>Y(new $(e.re,e.im).exp()),cln:e=>Y(new $(e.re,e.im).log()),cpow:(e,n)=>{let t=typeof e=="number"?new $(e,0):new $(e.re,e.im),i=typeof n=="number"?new $(n,0):new $(n.re,n.im);return Y(t.pow(i))},ccot:e=>Y(new $(e.re,e.im).cot()),csec:e=>Y(new $(e.re,e.im).sec()),ccsc:e=>Y(new $(e.re,e.im).csc()),ccoth:e=>Y(new $(e.re,e.im).coth()),csech:e=>Y(new $(e.re,e.im).sech()),ccsch:e=>Y(new $(e.re,e.im).csch()),cacot:e=>Y(new $(e.re,e.im).acot()),casec:e=>Y(new $(e.re,e.im).asec()),cacsc:e=>Y(new $(e.re,e.im).acsc()),cacoth:e=>Y(new $(e.re,e.im).acoth()),casech:e=>Y(new $(e.re,e.im).asech()),cacsch:e=>Y(new $(e.re,e.im).acsch()),cabs:e=>new $(e.re,e.im).abs(),carg:e=>new $(e.re,e.im).arg(),cconj:e=>Y(new $(e.re,e.im).conjugate()),cneg:e=>({re:-e.re,im:-e.im}),...Gf},kr=class extends Function{SYS=Au;constructor(n,t=""){return super("_SYS","_",t?`${t};return ${n}`:`return ${n}`),new Proxy(this,{apply:(i,r,s)=>super.apply(r,[this.SYS,...s]),get:(i,r)=>r==="toString"?()=>n:r==="isCompiled"?!0:i[r]})}},ai=class extends Function{SYS=Au;constructor(n,t){return super("_SYS",...t,`return ${n}`),new Proxy(this,{apply:(i,r,s)=>super.apply(r,[this.SYS,...s]),get:(i,r)=>r==="toString"?()=>`(${t.join(", ")}) => ${n}`:r==="isCompiled"?!0:i[r]})}},ui=class{getOperators(){return Tr}getFunctions(){return Ir}createTarget(n={}){return{language:"javascript",operators:t=>Tr[t],functions:t=>Ir[t],var:t=>({Pi:"Math.PI",ExponentialE:"Math.E",NaN:"Number.NaN",ImaginaryUnit:"({ re: 0, im: 1 })",Half:"0.5",MachineEpsilon:"Number.EPSILON",GoldenRatio:"((1 + Math.sqrt(5)) / 2)",CatalanConstant:"0.91596559417721901",EulerGamma:"0.57721566490153286"})[t],string:t=>JSON.stringify(t),number:t=>t.toString(),complex:(t,i)=>`({ re: ${t}, im: ${i} })`,indent:0,ws:t=>t??"",preamble:"",...n}}compile(n,t={}){let{operators:i,functions:r,vars:s,imports:o=[],preamble:a,realOnly:u}=t,l=n.unknowns,c=o.map(b=>{if(typeof b=="function")return b.toString();throw new Error(`Unsupported import \`${b}\``)}).join(`
47
- `),f={};if(r)for(let[b,v]of Object.entries(r))typeof v=="function"?Zf(v)?(c+=`${v.toString()};
48
- `,f[b]=v.name):(c+=`const ${b} = ${v.toString()};
49
- `,f[b]=b):typeof v=="string"&&(f[b]=v);let m=b=>{if(i){let v=typeof i=="function"?i(b):i[b];if(v)return v}return Tr[b]},d=this.createTarget({operators:m,functions:b=>f?.[b]?f[b]:Ir[b],var:b=>{if(s&&b in s)return JSON.stringify(s[b]);let v={Pi:"Math.PI",ExponentialE:"Math.E",NaN:"Number.NaN",ImaginaryUnit:"({ re: 0, im: 1 })",Half:"0.5",MachineEpsilon:"Number.EPSILON",GoldenRatio:"((1 + Math.sqrt(5)) / 2)",CatalanConstant:"0.91596559417721901",EulerGamma:"0.57721566490153286"}[b];if(v!==void 0)return v;if(l.includes(b))return`_.${b}`},preamble:(a??"")+c});return jf(n,d,u)}};function _r(e){let n=e.run;return{...e,run:((...i)=>{let r=n(...i);return typeof r=="object"&&r!==null&&"im"in r?r.im===0?r.re:NaN:r})}}function jf(e,n,t){if(h(e,"Function")){let o=e.ops,a=o.slice(1).map(f=>k(f)?f.symbol:"_"),u=g.compile(o[0].canonical,{...n,var:f=>a.includes(f)?f:n.var(f)}),l=new ai(u,a),c={target:"javascript",success:!0,code:`(${a.join(", ")}) => ${u}`,calling:"lambda",run:l};return t?_r(c):c}if(k(e)){let o=n.operators?.(e.symbol);if(o){let a=new ai(`a ${o[0]} b`,["a","b"]),u={target:"javascript",success:!0,code:`(a, b) => a ${o[0]} b`,calling:"lambda",run:a};return t?_r(u):u}}let i=g.compile(e,n),r=new kr(i,n.preamble),s={target:"javascript",success:!0,code:i,calling:"expression",run:r};return t?_r(s):s}var Uf=100;function $u(e){e.operator;let n=e,t=k(n.op1)?n.op1.symbol:"_",i=n.op2,r=n.op3,s=i.re,o=r.re;return{index:t,lowerExpr:i,upperExpr:r,lowerNum:!isNaN(s)&&Number.isFinite(s)?Math.floor(s):void 0,upperNum:!isNaN(o)&&Number.isFinite(o)?Math.floor(o):void 0}}function Mu(e,n,t){return n!==void 0?String(n):`Math.floor(${g.compile(e,t)})`}function wu(e,n,t,i){if(!n[0])throw new Error(`${e}: no body`);if(!n[1])throw new Error(`${e}: no indexing set`);let{index:r,lowerExpr:s,upperExpr:o,lowerNum:a,upperNum:u}=$u(n[1]),l=e==="Sum",c=l?"+":"*",f=l?"0":"1",m=g.isComplexValued(n[0]),d=a!==void 0&&u!==void 0;if(d&&a>u)return f;if(d&&u-a+1<=Uf){let F=[];for(let H=a;H<=u;H++){let se={...i,var:oe=>oe===r?String(H):i.var(oe)};F.push(`(${g.compile(n[0],se)})`)}if(!m)return`(${F.join(` ${c} `)})`;let V=F.map((H,se)=>`_t${se}`),U=F.map((H,se)=>`const ${V[se]} = ${H}`).join("; ");if(l){let H=V.map(oe=>`${oe}.re`).join(" + "),se=V.map(oe=>`${oe}.im`).join(" + ");return`(() => { ${U}; return { re: ${H}, im: ${se} }; })()`}let L=V[0],ue=[U];for(let H=1;H<V.length;H++){let se=L;L=`_p${H}`,ue.push(`const ${L} = { re: ${se}.re * ${V[H]}.re - ${se}.im * ${V[H]}.im, im: ${se}.re * ${V[H]}.im + ${se}.im * ${V[H]}.re }`)}return`(() => { ${ue.join("; ")}; return ${L}; })()`}let b=Mu(s,a,i),v=Mu(o,u,i),T=g.compile(n[0],{...i,var:C=>C===r?r:i.var(C)}),M=g.tempVar();if(m){let C=g.tempVar();return l?`(() => { let ${M} = { re: 0, im: 0 }; let ${r} = ${b}; const _upper = ${v}; while (${r} <= _upper) { const ${C} = ${T}; ${M} = { re: ${M}.re + ${C}.re, im: ${M}.im + ${C}.im }; ${r}++; } return ${M}; })()`:`(() => { let ${M} = { re: 1, im: 0 }; let ${r} = ${b}; const _upper = ${v}; while (${r} <= _upper) { const ${C} = ${T}; ${M} = { re: ${M}.re * ${C}.re - ${M}.im * ${C}.im, im: ${M}.re * ${C}.im + ${M}.im * ${C}.re }; ${r}++; } return ${M}; })()`}return`(() => { let ${M} = ${f}; let ${r} = ${b}; const _upper = ${v}; while (${r} <= _upper) { ${M} ${c}= ${T}; ${r}++; } return ${M}; })()`}function Hf(e,n,t){let{index:i,lowerExpr:r,upperExpr:s,lowerNum:o,upperNum:a}=$u(e[1]),u=g.compile(e[0],{...t,var:f=>f===i?f:t.var(f)}),l=o!==void 0?String(o):g.compile(r,t),c=a!==void 0?String(a):g.compile(s,t);return`_SYS.integrate((${i}) => (${u}), ${l}, ${c})`}function Zf(e){let n=e.toString();return n.includes("=>")?!1:n.startsWith("function ")&&n.includes(e.name)}function Sr(e){if(!Number.isInteger(e))return NaN;if(e<0)return e%2===0?-Sr(-e):Sr(-e);if(e<=1)return e;let n=0,t=1;for(let i=2;i<=e;i++){let r=n+t;n=t,t=r}return t}var Cu={Add:["+",11],Negate:["-",14],Subtract:["-",11],Multiply:["*",12],Divide:["/",13],Equal:["==",8],NotEqual:["!=",8],LessEqual:["<=",9],GreaterEqual:[">=",9],Less:["<",9],Greater:[">",9],And:["&&",4],Or:["||",3],Not:["!",14]};function Ie(e){return e?.language==="wgsl"?"vec2f":"vec2"}function Vn(e){return e?.language==="wgsl"?"vec3f":"vec3"}function Mr(e){return fe(e)?e.string?.toLowerCase()??null:null}function Ru(e,n,t){let i=X(e);return i!==void 0&&Number.isInteger(i)?i.toString():`${t?.language==="wgsl"?"i32":"int"}(${n(e)})`}var Yf=100;function Du(e,n,t,i){if(!n[0])throw new Error(`${e}: no body`);if(!n[1])throw new Error(`${e}: no indexing set`);if(g.isComplexValued(n[0]))throw new Error(`${e}: complex-valued body not supported in GPU targets`);let r=n[1];if(!h(r,"Limits"))throw new Error(`${e}: expected Limits indexing set`);let s=r.ops,o=k(s[0])?s[0].symbol:"_",a=s[1].re,u=s[2].re,l=!isNaN(a)&&Number.isFinite(a)?Math.floor(a):void 0,c=!isNaN(u)&&Number.isFinite(u)?Math.floor(u):void 0,f=e==="Sum",m=f?"+":"*",d=f?"0.0":"1.0",b=i.language==="wgsl",v=l!==void 0&&c!==void 0;if(v&&l>c)return d;if(v&&c-l+1<=Yf){let oe=[];for(let ne=l;ne<=c;ne++){let Oe=vn(ne),Be={...i,var:yt=>yt===o?Oe:i.var(yt)};oe.push(`(${g.compile(n[0],Be)})`)}return`(${oe.join(` ${m} `)})`}let T=g.tempVar(),M=b?"f32":"float",C=b?"i32":"int",F={...i,var:oe=>oe===o?b?`f32(${o})`:`float(${o})`:i.var(oe)},V=g.compile(n[0],F),U=l!==void 0?String(l):g.compile(s[1],i),L=c!==void 0?String(c):g.compile(s[2],i),ue=b?`var ${T}: ${M}`:`${M} ${T}`,H=b?`var ${o}: ${C}`:`${C} ${o}`;return[`${ue} = ${d};`,`for (${H} = ${U}; ${o} <= ${L}; ${o}++) {`,` ${T} ${m}= ${V};`,"}",`return ${T};`].join(`
50
- `)}var Wf={Add:(e,n,t)=>{if(e.length===0)return"0.0";if(e.length===1)return n(e[0]);if(!e.some(l=>g.isComplexValued(l)))return tn(e.map(l=>n(l)),"0.0","+");let r=e.map(l=>Ra(l,n));if(r.some(l=>l===null)){let l=Ie(t);return e.map(c=>{let f=n(c);return g.isComplexValued(c)?f:`${l}(${f}, 0.0)`}).join(" + ")}let s=[],o=[];for(let l of r)l.re!==null&&s.push(l.re),l.im!==null&&o.push(l.im);let a=tn(s,"0.0","+"),u=tn(o,"0.0","+");return`${Ie(t)}(${a}, ${u})`},Multiply:(e,n,t)=>{if(e.length===0)return"1.0";if(e.length===1)return n(e[0]);if(!e.some(l=>g.isComplexValued(l)))return tn(e.map(l=>n(l)),"1.0","*");let r=e.findIndex(l=>k(l,"ImaginaryUnit")||D(l)&&l.re===0&&l.im!==0);if(r>=0){let l=e[r],c=k(l,"ImaginaryUnit")?1:l.im,f=e.filter((v,T)=>T!==r),m=Ie(t);if(f.length===0)return`${m}(0.0, ${ae(c)})`;let d=f.map(v=>n(v));c!==1&&d.unshift(ae(c));let b=tn(d,"1.0","*");return`${m}(0.0, ${b})`}let s=[],o=[];for(let l of e)g.isComplexValued(l)?o.push(n(l)):s.push(n(l));let a=tn(s,"1.0","*"),u=o[0];for(let l=1;l<o.length;l++)u=`_gpu_cmul(${u}, ${o[l]})`;return a!=="1.0"&&(u=`(${a} * ${u})`),u},Divide:(e,n,t)=>{if(e.length===0)return"1.0";if(e.length===1)return n(e[0]);let i=g.isComplexValued(e[0]),r=e.length>=2&&g.isComplexValued(e[1]);if(!i&&!r){if(e.length===2){let a=X(e[0]),u=X(e[1]);return a!==void 0&&u!==void 0&&u!==0?ae(a/u):u===1?n(e[0]):`${n(e[0])} / ${n(e[1])}`}let o=n(e[0]);for(let a=1;a<e.length;a++)o=`${o} / ${n(e[a])}`;return o}return i&&r?`_gpu_cdiv(${n(e[0])}, ${n(e[1])})`:i&&!r?`(${n(e[0])} / ${n(e[1])})`:`_gpu_cdiv(${Ie(t)}(${n(e[0])}, 0.0), ${n(e[1])})`},Negate:([e],n,t)=>{if(e===null)throw new Error("Negate: no argument");let i=X(e);return i!==void 0?ae(-i):D(e)&&e.im!==0?`${Ie(t)}(${ae(-e.re)}, ${ae(-e.im)})`:k(e,"ImaginaryUnit")?`${Ie(t)}(0.0, -1.0)`:`(-${n(e)})`},Abs:(e,n)=>g.isComplexValued(e[0])?`length(${n(e[0])})`:g.isNonNegative(e[0])?n(e[0]):`abs(${n(e[0])})`,Arccos:(e,n)=>g.isComplexValued(e[0])?`_gpu_cacos(${n(e[0])})`:`acos(${n(e[0])})`,Arcsin:(e,n)=>g.isComplexValued(e[0])?`_gpu_casin(${n(e[0])})`:`asin(${n(e[0])})`,Arctan:(e,n)=>g.isComplexValued(e[0])?`_gpu_catan(${n(e[0])})`:`atan(${n(e[0])})`,Ceil:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`ceil(${n(e[0])})`,Clamp:"clamp",Cos:(e,n)=>g.isComplexValued(e[0])?`_gpu_ccos(${n(e[0])})`:`cos(${n(e[0])})`,Degrees:"degrees",Exp:(e,n)=>g.isComplexValued(e[0])?`_gpu_cexp(${n(e[0])})`:`exp(${n(e[0])})`,Exp2:"exp2",First:(e,n)=>`${n(e[0])}.x`,Second:(e,n)=>`${n(e[0])}.y`,Third:(e,n)=>`${n(e[0])}.z`,Floor:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`floor(${n(e[0])})`,Fract:"fract",Ln:(e,n)=>g.isComplexValued(e[0])?`_gpu_cln(${n(e[0])})`:`log(${n(e[0])})`,Log2:"log2",Max:"max",Min:"min",Mix:"mix",Power:(e,n,t)=>{let i=e[0],r=e[1];if(i===null)throw new Error("Power: no argument");if(g.isComplexValued(i)||g.isComplexValued(r)){if(k(i,"ExponentialE"))return`_gpu_cexp(${n(r)})`;let a=Ie(t),u=g.isComplexValued(i)?n(i):`${a}(${n(i)}, 0.0)`,l=g.isComplexValued(r)?n(r):`${a}(${n(r)}, 0.0)`;return`_gpu_cpow(${u}, ${l})`}let s=X(i),o=X(r);if(s!==void 0&&o!==void 0)return ae(Math.pow(s,o));if(o===0)return"1.0";if(o===1)return n(i);if(o===2&&(k(i)||D(i))){let a=n(i);return`(${a} * ${a})`}return o===-1?`(1.0 / ${n(i)})`:o===.5?`sqrt(${n(i)})`:`pow(${n(i)}, ${n(r)})`},Radians:"radians",Round:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`round(${n(e[0])})`,Sign:"sign",Sin:(e,n)=>g.isComplexValued(e[0])?`_gpu_csin(${n(e[0])})`:`sin(${n(e[0])})`,Smoothstep:"smoothstep",Sqrt:(e,n)=>{if(g.isComplexValued(e[0]))return`_gpu_csqrt(${n(e[0])})`;let t=X(e[0]);return t!==void 0?ae(Math.sqrt(t)):`sqrt(${n(e[0])})`},Step:"step",Tan:(e,n)=>g.isComplexValued(e[0])?`_gpu_ctan(${n(e[0])})`:`tan(${n(e[0])})`,Truncate:(e,n)=>g.isIntegerValued(e[0])?n(e[0]):`trunc(${n(e[0])})`,Real:(e,n)=>g.isComplexValued(e[0])?`(${n(e[0])}).x`:n(e[0]),Imaginary:(e,n)=>g.isComplexValued(e[0])?`(${n(e[0])}).y`:"0.0",Argument:(e,n)=>{if(g.isComplexValued(e[0])){let t=n(e[0]);return`atan(${t}.y, ${t}.x)`}return`(${n(e[0])} >= 0.0 ? 0.0 : 3.14159265359)`},Conjugate:(e,n,t)=>{if(g.isComplexValued(e[0])){let i=Ie(t),r=n(e[0]);return`${i}(${r}.x, -${r}.y)`}return n(e[0])},Remainder:([e,n],t)=>{if(e===null||n===null)throw new Error("Remainder: missing argument");return`(${t(e)} - ${t(n)} * round(${t(e)} / ${t(n)}))`},Cot:([e],n)=>{if(e===null)throw new Error("Cot: no argument");if(g.isComplexValued(e))return`_gpu_cdiv(_gpu_ccos(${n(e)}), _gpu_csin(${n(e)}))`;let t=n(e);return`(cos(${t}) / sin(${t}))`},Csc:([e],n,t)=>{if(e===null)throw new Error("Csc: no argument");return g.isComplexValued(e)?`_gpu_cdiv(${Ie(t)}(1.0, 0.0), _gpu_csin(${n(e)}))`:`(1.0 / sin(${n(e)}))`},Sec:([e],n,t)=>{if(e===null)throw new Error("Sec: no argument");return g.isComplexValued(e)?`_gpu_cdiv(${Ie(t)}(1.0, 0.0), _gpu_ccos(${n(e)}))`:`(1.0 / cos(${n(e)}))`},Arccot:([e],n)=>{if(e===null)throw new Error("Arccot: no argument");return`atan(1.0 / (${n(e)}))`},Arccsc:([e],n)=>{if(e===null)throw new Error("Arccsc: no argument");return`asin(1.0 / (${n(e)}))`},Arcsec:([e],n)=>{if(e===null)throw new Error("Arcsec: no argument");return`acos(1.0 / (${n(e)}))`},Sinh:(e,n)=>g.isComplexValued(e[0])?`_gpu_csinh(${n(e[0])})`:`sinh(${n(e[0])})`,Cosh:(e,n)=>g.isComplexValued(e[0])?`_gpu_ccosh(${n(e[0])})`:`cosh(${n(e[0])})`,Tanh:(e,n)=>g.isComplexValued(e[0])?`_gpu_ctanh(${n(e[0])})`:`tanh(${n(e[0])})`,Coth:([e],n)=>{if(e===null)throw new Error("Coth: no argument");if(g.isComplexValued(e))return`_gpu_cdiv(_gpu_ccosh(${n(e)}), _gpu_csinh(${n(e)}))`;let t=n(e);return`(cosh(${t}) / sinh(${t}))`},Csch:([e],n,t)=>{if(e===null)throw new Error("Csch: no argument");return g.isComplexValued(e)?`_gpu_cdiv(${Ie(t)}(1.0, 0.0), _gpu_csinh(${n(e)}))`:`(1.0 / sinh(${n(e)}))`},Sech:([e],n,t)=>{if(e===null)throw new Error("Sech: no argument");return g.isComplexValued(e)?`_gpu_cdiv(${Ie(t)}(1.0, 0.0), _gpu_ccosh(${n(e)}))`:`(1.0 / cosh(${n(e)}))`},Arcosh:(e,n)=>g.isComplexValued(e[0])?`_gpu_cacosh(${n(e[0])})`:`acosh(${n(e[0])})`,Arsinh:(e,n)=>g.isComplexValued(e[0])?`_gpu_casinh(${n(e[0])})`:`asinh(${n(e[0])})`,Artanh:(e,n)=>g.isComplexValued(e[0])?`_gpu_catanh(${n(e[0])})`:`atanh(${n(e[0])})`,Arcoth:([e],n)=>{if(e===null)throw new Error("Arcoth: no argument");return`atanh(1.0 / (${n(e)}))`},Arcsch:([e],n)=>{if(e===null)throw new Error("Arcsch: no argument");return`asinh(1.0 / (${n(e)}))`},Arsech:([e],n)=>{if(e===null)throw new Error("Arsech: no argument");return`acosh(1.0 / (${n(e)}))`},Arctan2:(e,n)=>{if(e.length<2)throw new Error("Arctan2: need two arguments");return`atan(${n(e[0])}, ${n(e[1])})`},Hypot:([e,n],t)=>{if(e===null||n===null)throw new Error("Hypot: need two arguments");return`length(vec2(${t(e)}, ${t(n)}))`},Haversine:([e],n)=>{if(e===null)throw new Error("Haversine: no argument");return`((1.0 - cos(${n(e)})) * 0.5)`},InverseHaversine:([e],n)=>{if(e===null)throw new Error("InverseHaversine: no argument");return`(2.0 * asin(sqrt(${n(e)})))`},Gamma:([e],n)=>{if(e===null)throw new Error("Gamma: no argument");return`_gpu_gamma(${n(e)})`},GammaLn:([e],n)=>{if(e===null)throw new Error("GammaLn: no argument");return`_gpu_gammaln(${n(e)})`},Factorial:([e],n)=>{if(e===null)throw new Error("Factorial: no argument");return`_gpu_gamma(${n(e)} + 1.0)`},Beta:([e,n],t)=>{if(e===null||n===null)throw new Error("Beta: need two arguments");let i=t(e),r=t(n);return`(_gpu_gamma(${i}) * _gpu_gamma(${r}) / _gpu_gamma(${i} + ${r}))`},Erf:([e],n)=>{if(e===null)throw new Error("Erf: no argument");return`_gpu_erf(${n(e)})`},Erfc:([e],n)=>{if(e===null)throw new Error("Erfc: no argument");return`(1.0 - _gpu_erf(${n(e)}))`},ErfInv:([e],n)=>{if(e===null)throw new Error("ErfInv: no argument");return`_gpu_erfinv(${n(e)})`},Heaviside:([e],n)=>{if(e===null)throw new Error("Heaviside: no argument");return`_gpu_heaviside(${n(e)})`},Sinc:([e],n)=>{if(e===null)throw new Error("Sinc: no argument");return`_gpu_sinc(${n(e)})`},FresnelC:([e],n)=>{if(e===null)throw new Error("FresnelC: no argument");return`_gpu_fresnelC(${n(e)})`},FresnelS:([e],n)=>{if(e===null)throw new Error("FresnelS: no argument");return`_gpu_fresnelS(${n(e)})`},BesselJ:([e,n],t,i)=>{if(e===null||n===null)throw new Error("BesselJ: need two arguments");return`_gpu_besselJ(${i?.language==="wgsl"?"i32":"int"}(${t(e)}), ${t(n)})`},Lb:"log2",Log:(e,n)=>{if(e.length===0)throw new Error("Log: no argument");return e.length===1?`(log(${n(e[0])}) / log(10.0))`:`(log(${n(e[0])}) / log(${n(e[1])}))`},Log10:([e],n)=>{if(e===null)throw new Error("Log10: no argument");return`(log(${n(e)}) * 0.4342944819032518)`},Lg:([e],n)=>{if(e===null)throw new Error("Lg: no argument");return`(log(${n(e)}) * 0.4342944819032518)`},Square:([e],n)=>{if(e===null)throw new Error("Square: no argument");if(k(e)||D(e)){let t=n(e);return`(${t} * ${t})`}return`pow(${n(e)}, 2.0)`},Root:([e,n],t)=>{if(e===null)throw new Error("Root: no argument");if(n==null)return`sqrt(${t(e)})`;let i=X(n);if(i===2)return`sqrt(${t(e)})`;let r=X(e);return r!==void 0&&i!==void 0?ae(Math.pow(r,1/i)):`pow(${t(e)}, 1.0 / ${t(n)})`},ColorMix:(e,n)=>{if(e.length<2)throw new Error("ColorMix: need two colors");let t=n(e[0]),i=n(e[1]),r=e.length>=3?n(e[2]):"0.5";return`_gpu_color_mix(${t}, ${i}, ${r})`},ColorContrast:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorContrast: need two colors");return`_gpu_apca(${t(e)}, ${t(n)})`},ContrastingColor:(e,n,t)=>{if(e.length===0)throw new Error("ContrastingColor: no argument");let i=n(e[0]);if(e.length>=3){let u=n(e[1]),l=n(e[2]);return`(abs(_gpu_apca(${i}, ${u})) >= abs(_gpu_apca(${i}, ${l})) ? ${u} : ${l})`}let s=t?.language==="wgsl"?"vec3f":"vec3",o=`${s}(0.0)`,a=`${s}(1.0, 0.0, 0.0)`;return`((_gpu_apca(${i}, ${o}) > 50.0) ? ${o} : ${a})`},ColorToColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorToColorspace: need color and space");let i=Mr(n);if(i===null)throw new Error("ColorToColorspace: space must be a string literal");let r=t(e);switch(i){case"oklch":return r;case"oklab":case"lab":return`_gpu_oklch_to_oklab(${r})`;case"rgb":return`_gpu_oklch_to_srgb(${r})`;case"hsl":return`_gpu_rgb_to_hsl(_gpu_oklch_to_srgb(${r}))`;case"hsv":return`_gpu_rgb_to_hsv(_gpu_oklch_to_srgb(${r}))`;default:throw new Error(`ColorToColorspace: unsupported space "${i}" on GPU target`)}},ColorFromColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorFromColorspace: need components and space");let i=Mr(n);if(i===null)throw new Error("ColorFromColorspace: space must be a string literal");let r=t(e);switch(i){case"oklch":return r;case"oklab":case"lab":return`_gpu_oklab_to_oklch(${r})`;case"rgb":return`_gpu_srgb_to_oklch(${r})`;case"hsl":return`_gpu_srgb_to_oklch(_gpu_hsl_to_rgb(${r}))`;case"hsv":return`_gpu_srgb_to_oklch(_gpu_hsv_to_rgb(${r}))`;default:throw new Error(`ColorFromColorspace: unsupported space "${i}" on GPU target`)}},Color:([e],n,t)=>{if(e===null)throw new Error("Color: no argument");let i=Mr(e);if(i===null)throw new Error("Color: argument must be a string literal on GPU target");let r=We(i);if(r===0&&i.trim().toLowerCase()!=="transparent")throw new Error(`Color: invalid color string "${i}"`);let s=r>>>24&255,o=r>>>16&255,a=r>>>8&255,u=ve({r:s,g:o,b:a});return`${Vn(t)}(${ae(u.L)}, ${ae(u.C)}, ${ae(u.H)})`},Rgb:(e,n,t)=>{if(e.length<3)throw new Error("Rgb: need 3 components");return`_gpu_srgb_to_oklch(${Vn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])}))`},Hsv:(e,n,t)=>{if(e.length<3)throw new Error("Hsv: need 3 components");return`_gpu_srgb_to_oklch(_gpu_hsv_to_rgb(${Vn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])})))`},Hsl:(e,n,t)=>{if(e.length<3)throw new Error("Hsl: need 3 components");return`_gpu_srgb_to_oklch(_gpu_hsl_to_rgb(${Vn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])})))`},Oklab:(e,n,t)=>{if(e.length<3)throw new Error("Oklab: need 3 components");return`_gpu_oklab_to_oklch(${Vn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])}))`},Oklch:(e,n,t)=>{if(e.length<3)throw new Error("Oklch: need 3 components");return`${Vn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`},AsOklch:([e],n)=>{if(e===null)throw new Error("AsOklch: no argument");return n(e)},AsOklab:([e],n)=>{if(e===null)throw new Error("AsOklab: no argument");return`_gpu_oklch_to_oklab(${n(e)})`},AsRgb:([e],n)=>{if(e===null)throw new Error("AsRgb: no argument");return`_gpu_oklch_to_srgb(${n(e)})`},AsHsv:([e],n)=>{if(e===null)throw new Error("AsHsv: no argument");return`_gpu_rgb_to_hsv(_gpu_oklch_to_srgb(${n(e)}))`},AsHsl:([e],n)=>{if(e===null)throw new Error("AsHsl: no argument");return`_gpu_rgb_to_hsl(_gpu_oklch_to_srgb(${n(e)}))`},Mandelbrot:([e,n],t,i)=>{if(e===null||n===null)throw new Error("Mandelbrot: missing arguments");let r=Ru(n,t,i);return`_fractal_mandelbrot(${t(e)}, ${r})`},Julia:([e,n,t],i,r)=>{if(e===null||n===null||t===null)throw new Error("Julia: missing arguments");let s=Ru(t,i,r);return`_fractal_julia(${i(e)}, ${i(n)}, ${s})`},Cross:"cross",Distance:"distance",Dot:"dot",Length:"length",Normalize:"normalize",Reflect:"reflect",Refract:"refract",Sum:(e,n,t)=>Du("Sum",e,n,t),Product:(e,n,t)=>Du("Product",e,n,t),Range:(e,n,t)=>{if(e.length<2||e.length>3)throw new Error("Range: GPU compile expects 2 or 3 arguments (lo, hi, step?)");let i=e[0].re,r=e[1].re,s=e.length===3?e[2].re:1;if(!Number.isFinite(i)||!Number.isFinite(r)||!Number.isFinite(s))throw new Error("Range: GPU compile requires constant numeric bounds (non-constant ranges must be materialized at JS host then uploaded as a uniform)");if(s===0)throw new Error("Range: step cannot be zero");let o=Math.max(0,Math.floor((r-i)/s)+1);if(o===0)throw new Error("Range: empty range (lo > hi for positive step, or lo < hi for negative step)");if(o>256)throw new Error(`Range: GPU compile inlines ranges up to 256 elements (got ${o})`);let a=[];for(let c=0;c<o;c++)a.push(i+c*s);return`${t.language==="wgsl"?`array<f32, ${o}>`:`float[${o}]`}(${a.map(vn).join(", ")})`},Loop:(e,n,t)=>{if(!e[0])throw new Error("Loop: no body");if(!e[1])throw new Error("Loop: no indexing set");let i=e[1];if(!h(i,"Element"))throw new Error("Loop: expected Element(index, Range(lo, hi))");let r=i.ops[0],s=i.ops[1];if(!k(r))throw new Error("Loop: index must be a symbol");if(!h(s,"Range"))throw new Error("Loop: expected Range(lo, hi)");let o=r.symbol,a=Math.floor(s.ops[0].re),u=Math.floor(s.ops[1].re);if(!Number.isFinite(a)||!Number.isFinite(u))throw new Error("Loop: bounds must be finite numbers");let l=t.language==="wgsl",c=l?"i32":"int",f=g.compile(e[0],{...t,var:d=>d===o?o:t.var(d)});return`for (${l?`var ${o}: ${c}`:`${c} ${o}`} = ${a}; ${o} <= ${u}; ${o}++) {
46
+ }, (_e, i) => ${t} + i)`}return`Array.from({length: Math.floor((${i} - ${t}) / ${r}) + 1}, (_e, i) => ${t} + i * ${r})`},Root:([e,n],t)=>{if(e===null)throw new Error("Root: no argument");if(n===null)return`Math.sqrt(${t(e)})`;let i=Q(e),r=Q(n);return i!==void 0&&r!==void 0&&r!==0?String(Math.pow(i,1/r)):r===2?`Math.sqrt(${t(e)})`:r===3?`Math.cbrt(${t(e)})`:r!==void 0?`Math.pow(${t(e)}, ${1/r})`:`Math.pow(${t(e)}, 1 / (${t(n)}))`},Random:(e,n)=>{if(e.length===0)return"Math.random()";if(e.length===2){let r=n(e[0]),s=n(e[1]);return`((${r}) + Math.floor(Math.random() * ((${s}) - (${r}))))`}let t=e[0];return b.isIntegerValued(t)?`Math.floor(Math.random() * (${n(t)}))`:`(() => { const _s = (${n(t)}) * 12.9898; const _v = Math.sin(_s) * 43758.5453; return _v - Math.floor(_v); })()`},Round:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`Math.round(${n(e[0])})`,Square:(e,n)=>{let t=e[0];if(t===null)throw new Error("Square: no argument");let i=Q(t);if(i!==void 0)return String(i*i);if(T(t)){let r=n(t);return`(${r} * ${r})`}return`Math.pow(${n(t)}, 2)`},Sec:(e,n)=>{let t=e[0];if(t===null)throw new Error("Sec: no argument");return b.isComplexValued(t)?`_SYS.csec(${n(t)})`:`1 / Math.cos(${n(t)})`},Sech:(e,n)=>{let t=e[0];if(t===null)throw new Error("Sech: no argument");return b.isComplexValued(t)?`_SYS.csech(${n(t)})`:`1 / Math.cosh(${n(t)})`},Second:(e,n)=>`${n(e[0])}[1]`,Heaviside:"_SYS.heaviside",Sign:"Math.sign",Sinc:"_SYS.sinc",FresnelS:"_SYS.fresnelS",FresnelC:"_SYS.fresnelC",Sin:(e,n)=>b.isComplexValued(e[0])?`_SYS.csin(${n(e[0])})`:`Math.sin(${n(e[0])})`,Sinh:(e,n)=>b.isComplexValued(e[0])?`_SYS.csinh(${n(e[0])})`:`Math.sinh(${n(e[0])})`,Sqrt:(e,n)=>{if(b.isComplexValued(e[0]))return`_SYS.csqrt(${n(e[0])})`;let t=Q(e[0]);return t!==void 0?String(Math.sqrt(t)):`Math.sqrt(${n(e[0])})`},Tan:(e,n)=>b.isComplexValued(e[0])?`_SYS.ctan(${n(e[0])})`:`Math.tan(${n(e[0])})`,Tanh:(e,n)=>b.isComplexValued(e[0])?`_SYS.ctanh(${n(e[0])})`:`Math.tanh(${n(e[0])})`,Third:(e,n)=>`${n(e[0])}[2]`,Mod:([e,n],t)=>{if(e===null||n===null)throw new Error("Mod: missing argument");let i=t(e),r=t(n);return b.isIntegerValued(e)&&b.isIntegerValued(n)&&b.isNonNegative(e)?`(${i} % ${r})`:`((${i} % ${r}) + ${r}) % ${r}`},Truncate:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`Math.trunc(${n(e[0])})`,Remainder:([e,n],t)=>{if(e===null||n===null)throw new Error("Remainder: missing argument");return`(${t(e)} - ${t(n)} * Math.round(${t(e)} / ${t(n)}))`},Divide:([e,n],t)=>{if(e===null||n===null)throw new Error("Divide: missing argument");let i=b.isComplexValued(e),r=b.isComplexValued(n);if(!i&&!r){let s=Q(e),o=Q(n);return s!==void 0&&o!==void 0&&o!==0?String(s/o):o===1?t(e):`(${t(e)} / ${t(n)})`}return i&&r?`(() => { const _a = ${t(e)}, _b = ${t(n)}, _d = _b.re * _b.re + _b.im * _b.im; return { re: (_a.re * _b.re + _a.im * _b.im) / _d, im: (_a.im * _b.re - _a.re * _b.im) / _d }; })()`:i&&!r?`(() => { const _a = ${t(e)}, _r = ${t(n)}; return { re: _a.re / _r, im: _a.im / _r }; })()`:`(() => { const _r = ${t(e)}, _b = ${t(n)}, _d = _b.re * _b.re + _b.im * _b.im; return { re: _r * _b.re / _d, im: -_r * _b.im / _d }; })()`},Negate:([e],n)=>{if(e===null)throw new Error("Negate: no argument");if(!b.isComplexValued(e)){let t=Q(e);return t!==void 0?String(-t):`(-${n(e)})`}return`_SYS.cneg(${n(e)})`},Multiply:(e,n)=>{if(e.length===1)return n(e[0]);if(!e.some(o=>b.isComplexValued(o))){if(e.some(u=>Q(u)===0))return"0";let o=e.map(Q);if(o.every(u=>u!==void 0))return String(o.reduce((u,l)=>u*l,1));let a=e.filter(u=>Q(u)!==1);return a.length===0?"1":a.length===1?n(a[0]):`(${a.map(u=>n(u)).join(" * ")})`}if(e.length===2){let o=b.isComplexValued(e[0]),a=b.isComplexValued(e[1]),u=n(e[0]),l=n(e[1]);return o&&a?`(() => { const _a = ${u}, _b = ${l}; return { re: _a.re * _b.re - _a.im * _b.im, im: _a.re * _b.im + _a.im * _b.re }; })()`:o&&!a?`(() => { const _a = ${u}, _r = ${l}; return { re: _a.re * _r, im: _a.im * _r }; })()`:`(() => { const _r = ${u}, _b = ${l}; return { re: _r * _b.re, im: _r * _b.im }; })()`}let i=[],r=[];for(let o=0;o<e.length;o++){let a=`_v${o}`;r.push(a),i.push(`const ${a} = ${n(e[o])}`)}let s=b.isComplexValued(e[0]);i.push(`let _re = ${s?`${r[0]}.re`:r[0]}`),i.push(`let _im = ${s?`${r[0]}.im`:"0"}`);for(let o=1;o<e.length;o++){let a=r[o],u=b.isComplexValued(e[o]),l=u?`${a}.re`:a,c=u?`${a}.im`:"0";i.push(`const _nre${o} = _re * ${l} - _im * ${c}`),i.push(`const _nim${o} = _re * ${c} + _im * ${l}`),i.push(`_re = _nre${o}`),i.push(`_im = _nim${o}`)}return`(() => { ${i.join("; ")}; return { re: _re, im: _im }; })()`},Factorial:"_SYS.factorial",Factorial2:"_SYS.factorial2",Exp2:([e],n)=>{if(e===null)throw new Error("Exp2: no argument");return`Math.pow(2, ${n(e)})`},Log2:"Math.log2",Log10:"Math.log10",Lg:"Math.log10",Arctan2:"Math.atan2",Hypot:"Math.hypot",Degrees:([e],n)=>{if(e===null)throw new Error("Degrees: no argument");return`(${n(e)} * Math.PI / 180)`},Haversine:([e],n)=>{if(e===null)throw new Error("Haversine: no argument");return b.inlineExpression("(1 - Math.cos(${x})) / 2",n(e))},InverseHaversine:([e],n)=>{if(e===null)throw new Error("InverseHaversine: no argument");return`(2 * Math.asin(Math.sqrt(${n(e)})))`},Erf:"_SYS.erf",Erfc:"_SYS.erfc",ErfInv:"_SYS.erfInv",Beta:"_SYS.beta",Digamma:"_SYS.digamma",Trigamma:"_SYS.trigamma",PolyGamma:(e,n)=>`_SYS.polygamma(${n(e[0])}, ${n(e[1])})`,Zeta:"_SYS.zeta",LambertW:"_SYS.lambertW",BesselJ:(e,n)=>`_SYS.besselJ(${n(e[0])}, ${n(e[1])})`,BesselY:(e,n)=>`_SYS.besselY(${n(e[0])}, ${n(e[1])})`,BesselI:(e,n)=>`_SYS.besselI(${n(e[0])}, ${n(e[1])})`,BesselK:(e,n)=>`_SYS.besselK(${n(e[0])}, ${n(e[1])})`,AiryAi:"_SYS.airyAi",AiryBi:"_SYS.airyBi",Mandelbrot:([e,n],t)=>{if(e===null||n===null)throw new Error("Mandelbrot: missing arguments");return`_SYS.mandelbrot(${t(e)}, ${t(n)})`},Julia:([e,n,t],i)=>{if(e===null||n===null||t===null)throw new Error("Julia: missing arguments");return`_SYS.julia(${i(e)}, ${i(n)}, ${i(t)})`},Binomial:(e,n)=>`_SYS.binomial(${n(e[0])}, ${n(e[1])})`,Fibonacci:"_SYS.fibonacci",Real:(e,n)=>b.isComplexValued(e[0])?`(${n(e[0])}).re`:n(e[0]),Imaginary:(e,n)=>b.isComplexValued(e[0])?`(${n(e[0])}).im`:"0",Argument:(e,n)=>b.isComplexValued(e[0])?`_SYS.carg(${n(e[0])})`:`(${n(e[0])} >= 0 ? 0 : Math.PI)`,Conjugate:(e,n)=>b.isComplexValued(e[0])?`_SYS.cconj(${n(e[0])})`:n(e[0]),Color:([e],n)=>{if(e===null)throw new Error("Color: no argument");return`_SYS.color(${n(e)})`},ColorToString:(e,n)=>{if(e.length===0)throw new Error("ColorToString: no argument");return e.length>=2?`_SYS.colorToString(${n(e[0])}, ${n(e[1])})`:`_SYS.colorToString(${n(e[0])})`},ColorMix:(e,n)=>{if(e.length<2)throw new Error("ColorMix: need two colors");return e.length>=3?`_SYS.colorMix(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`:`_SYS.colorMix(${n(e[0])}, ${n(e[1])})`},ColorContrast:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorContrast: need two colors");return`_SYS.colorContrast(${t(e)}, ${t(n)})`},ContrastingColor:(e,n)=>{if(e.length===0)throw new Error("ContrastingColor: no argument");return e.length>=3?`_SYS.contrastingColor(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`:`_SYS.contrastingColor(${n(e[0])})`},ColorToColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorToColorspace: need color and space");return`_SYS.colorToColorspace(${t(e)}, ${t(n)})`},ColorFromColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorFromColorspace: need components and space");return`_SYS.colorFromColorspace(${t(e)}, ${t(n)})`},Colormap:(e,n)=>{if(e.length===0)throw new Error("Colormap: no argument");return e.length>=2?`_SYS.colormap(${n(e[0])}, ${n(e[1])})`:`_SYS.colormap(${n(e[0])})`},Rgb:(e,n)=>{if(e.length<3)throw new Error("Rgb: need 3 components");return`_SYS.rgb(${e.map(n).join(", ")})`},Hsv:(e,n)=>{if(e.length<3)throw new Error("Hsv: need 3 components");return`_SYS.hsv(${e.map(n).join(", ")})`},Hsl:(e,n)=>{if(e.length<3)throw new Error("Hsl: need 3 components");return`_SYS.hsl(${e.map(n).join(", ")})`},Oklab:(e,n)=>{if(e.length<3)throw new Error("Oklab: need 3 components");return`_SYS.oklab(${e.map(n).join(", ")})`},Oklch:(e,n)=>{if(e.length<3)throw new Error("Oklch: need 3 components");return`_SYS.oklch(${e.map(n).join(", ")})`},AsRgb:([e],n)=>{if(e===null)throw new Error("AsRgb: no argument");return`_SYS.asRgb(${n(e)})`},AsHsv:([e],n)=>{if(e===null)throw new Error("AsHsv: no argument");return`_SYS.asHsv(${n(e)})`},AsHsl:([e],n)=>{if(e===null)throw new Error("AsHsl: no argument");return`_SYS.asHsl(${n(e)})`},AsOklab:([e],n)=>{if(e===null)throw new Error("AsOklab: no argument");return`_SYS.asOklab(${n(e)})`},AsOklch:([e],n)=>{if(e===null)throw new Error("AsOklch: no argument");return n(e)},ColorDelta:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorDelta: need two colors");return`_SYS.colorDelta(${t(e)}, ${t(n)})`},Distance:([e,n],t)=>{if(e===null||n===null)throw new Error("Distance: need two points");return`_SYS.distance(${t(e)}, ${t(n)})`}};function W(e){return{re:e.re,im:e.im}}function Ae(e){if(e!==void 0&&Number.isFinite(e)&&!(Math.abs(e-1)<1e-9))return e}function Ve(e){if(typeof e=="string"){let t=en(e),i={r:t>>>24&255,g:t>>>16&255,b:t>>>8&255},r=Ae((t&255)/255);return r!==void 0&&(i.alpha=r),i}let n=pi({L:e[0],C:e[1],H:e[2]});if(e.length>=4){let t=Ae(e[3]);t!==void 0&&(n.alpha=t)}return n}function vt(e){if(typeof e=="string"){let n=en(e),t=n>>>24&255,i=n>>>16&255,r=n>>>8&255,s=Ee({r:t,g:i,b:r}),o=Ae((n&255)/255);return o!==void 0&&(s.alpha=o),s}return{L:e[0],C:e[1],H:e[2],alpha:e.length>=4?Ae(e[3]):void 0}}function bi(e){let n=e>>>24&255,t=e>>>16&255,i=e>>>8&255,r=Ee({r:n,g:t,b:i}),s=Ae((e&255)/255);return s!==void 0?[r.L,r.C,r.H,s]:[r.L,r.C,r.H]}var Up={color(e){return bi(en(e))},colorToString(e,n){let t=Ve(e),i=(n??"hex").toLowerCase();switch(i){case"hex":{let r=Math.round(Math.max(0,Math.min(255,t.r))),s=Math.round(Math.max(0,Math.min(255,t.g))),o=Math.round(Math.max(0,Math.min(255,t.b))),a=`#${r.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`;if(t.alpha!==void 0){let u=Math.round(Math.max(0,Math.min(255,t.alpha*255)));a+=u.toString(16).padStart(2,"0")}return a}case"rgb":{let r=Math.round(t.r),s=Math.round(t.g),o=Math.round(t.b);return t.alpha!==void 0?`rgb(${r} ${s} ${o} / ${t.alpha})`:`rgb(${r} ${s} ${o})`}case"hsl":{let r=fi(t.r,t.g,t.b),s=Math.round(r.h*10)/10,o=Math.round(r.s*1e3)/10,a=Math.round(r.l*1e3)/10;return t.alpha!==void 0?`hsl(${s} ${o}% ${a}% / ${t.alpha})`:`hsl(${s} ${o}% ${a}%)`}case"oklch":{let r=Ee(t),s=Math.round(r.L*1e3)/1e3,o=Math.round(r.C*1e3)/1e3,a=Math.round(r.H*10)/10;return t.alpha!==void 0?`oklch(${s} ${o} ${a} / ${t.alpha})`:`oklch(${s} ${o} ${a})`}default:throw new Error(`Unknown color format: ${i}`)}},colorMix(e,n,t=.5){let i=vt(e),r=vt(n);t=Math.max(0,Math.min(1,t));let s=i.C<1e-6,o=r.C<1e-6,a;if(s&&o)a=i.H;else if(s)a=r.H;else if(o)a=i.H;else{let m=r.H-i.H;m>180&&(m-=360),m<-180&&(m+=360),a=i.H+m*t,a<0&&(a+=360),a>=360&&(a-=360)}let u=i.L+(r.L-i.L)*t,l=i.C+(r.C-i.C)*t,c=i.alpha??1,f=r.alpha??1,d=Ae(c+(f-c)*t);return d!==void 0?[u,l,a,d]:[u,l,a]},colorContrast(e,n){return li(Ve(e),Ve(n))},contrastingColor(e,n,t){let i=Ve(e);return bi(n!==void 0&&t!==void 0?Rr({bg:i,fg1:Ve(n),fg2:Ve(t)}):Rr(i))},colorToColorspace(e,n){let t=Ve(e),i=t.alpha,r;switch(n.toLowerCase()){case"rgb":r=[t.r/255,t.g/255,t.b/255];break;case"hsl":{let s=fi(t.r,t.g,t.b);r=[s.h,s.s,s.l];break}case"oklch":{let s=Ee(t);r=[s.L,s.C,s.H];break}case"oklab":case"lab":{let s=Cr(t);r=[s.L,s.a,s.b];break}default:throw new Error(`Unknown color space: ${n}`)}return i!==void 0&&r.push(i),r},colormap(e,n){let i={...ju,...zu,...Gu}[e];if(!i)throw new Error(`Unknown palette: ${e}`);let r=i.map(o=>bi(en(o)));if(n===void 0)return r;if(Number.isInteger(n)&&n>=2){let o=n,a=[];for(let u=0;u<o;u++){let l=o===1?0:u/(o-1);a.push(this._interpolatePalette(r,l))}return a}let s=Math.max(0,Math.min(1,n));return this._interpolatePalette(r,s)},_interpolatePalette(e,n){if(e.length===0)return[0,0,0];if(n<=0)return[...e[0]];if(n>=1)return[...e[e.length-1]];let t=n*(e.length-1),i=Math.floor(t),r=t-i;if(r===0||i>=e.length-1)return[...e[Math.min(i,e.length-1)]];let[s,o,a]=e[i],[u,l,c]=e[i+1],f=o<1e-6,d=l<1e-6,m;if(f&&d)m=a;else if(f)m=c;else if(d)m=a;else{let g=c-a;g>180&&(g-=360),g<-180&&(g+=360),m=a+g*r,m<0&&(m+=360),m>=360&&(m-=360)}return[s+(u-s)*r,o+(l-o)*r,m]},colorFromColorspace(e,n){let t=e[0],i=e[1],r=e[2],s=e.length>=4?e[3]:void 0,o;switch(n.toLowerCase()){case"rgb":o=Ee({r:t*255,g:i*255,b:r*255});break;case"hsl":{let a=ci(t,i,r);o=Ee(a);break}case"oklch":o={L:t,C:i,H:r};break;case"oklab":case"lab":o=gt({L:t,a:i,b:r});break;default:throw new Error(`Unknown color space: ${n}`)}return s!==void 0?[o.L,o.C,o.H,s]:[o.L,o.C,o.H]},rgb(e,n,t,i){let r=Ee({r:e*255,g:n*255,b:t*255}),s=Ae(i);return s!==void 0?[r.L,r.C,r.H,s]:[r.L,r.C,r.H]},hsv(e,n,t,i){let r=Vu(e,n,t),s=Ee(r),o=Ae(i);return o!==void 0?[s.L,s.C,s.H,o]:[s.L,s.C,s.H]},hsl(e,n,t,i){let r=ci(e,n,t),s=Ee({r:r.r,g:r.g,b:r.b}),o=Ae(i);return o!==void 0?[s.L,s.C,s.H,o]:[s.L,s.C,s.H]},oklab(e,n,t,i){let r=gt({L:e,a:n,b:t}),s=Ae(i);return s!==void 0?[r.L,r.C,r.H,s]:[r.L,r.C,r.H]},oklch(e,n,t,i){let r=Ae(i);return r!==void 0?[e,n,t,r]:[e,n,t]},asRgb(e){let n=Ve(e),t=n.r/255,i=n.g/255,r=n.b/255;return n.alpha!==void 0?[t,i,r,n.alpha]:[t,i,r]},asHsv(e){let n=Ve(e),t=qu(n.r,n.g,n.b);return n.alpha!==void 0?[t.h,t.s,t.v,n.alpha]:[t.h,t.s,t.v]},asHsl(e){let n=Ve(e),t=fi(n.r,n.g,n.b);return n.alpha!==void 0?[t.h,t.s,t.l,n.alpha]:[t.h,t.s,t.l]},asOklab(e){let n=vt(e),t=In({L:n.L,C:n.C,H:n.H});return n.alpha!==void 0?[t.L,t.a,t.b,n.alpha]:[t.L,t.a,t.b]},colorDelta(e,n){let t=In(vt(e)),i=In(vt(n));return Ju(t,i)},distance(e,n){if(!Array.isArray(e)||!Array.isArray(n))throw new Error("Distance: expected two arrays");if(e.length!==n.length)throw new Error("Distance: dimension mismatch");let t=0;for(let i=0;i<e.length;i++){let r=e[i]-n[i];t+=r*r}return Math.sqrt(t)}},yl={chop:Kn,factorial:Xn,factorial2:Qn,gamma:ne,gcd:mn,heaviside:e=>e<0?0:e===0?.5:1,integrate:(e,n,t)=>hl(e,n,t,1e7).estimate,lcm:Wn,lngamma:_e,limit:At,mean:ul,median:xt,variance:Fr,populationVariance:Or,standardDeviation:ll,populationStandardDeviation:cl,kurtosis:fl,skewness:pl,mode:ml,quartiles:Lr,interquartileRange:dl,erf:Sn,erfc:zn,erfInv:Zu,beta:Yu,digamma:hi,trigamma:gi,polygamma:Dr,zeta:Pr,lambertW:Wu,besselJ:an,besselY:di,besselI:_n,besselK:Qu,airyAi:el,airyBi:nl,sinc:ol,fresnelS:un,fresnelC:ln,mandelbrot:(e,n)=>{let t=0,i=0,r=typeof e=="number"?e:e.re,s=typeof e=="number"?0:e.im,o=Math.round(n);for(let a=0;a<o;a++){let u=t*t-i*i+r;i=2*t*i+s,t=u;let l=t*t+i*i;if(l>4){let c=(a-Math.log2(Math.log2(l))+4)/o;return Math.max(0,Math.min(1,c))}}return 1},julia:(e,n,t)=>{let i=typeof e=="number"?e:e.re,r=typeof e=="number"?0:e.im,s=typeof n=="number"?n:n.re,o=typeof n=="number"?0:n.im,a=Math.round(t);for(let u=0;u<a;u++){let l=i*i-r*r+s;r=2*i*r+o,i=l;let c=i*i+r*r;if(c>4){let f=(u-Math.log2(Math.log2(c))+4)/a;return Math.max(0,Math.min(1,f))}}return 1},binomial:yt,fibonacci:zr,csin:e=>W(new C(e.re,e.im).sin()),ccos:e=>W(new C(e.re,e.im).cos()),ctan:e=>W(new C(e.re,e.im).tan()),casin:e=>W(new C(e.re,e.im).asin()),cacos:e=>W(new C(e.re,e.im).acos()),catan:e=>W(new C(e.re,e.im).atan()),csinh:e=>W(new C(e.re,e.im).sinh()),ccosh:e=>W(new C(e.re,e.im).cosh()),ctanh:e=>W(new C(e.re,e.im).tanh()),csqrt:e=>W(new C(e.re,e.im).sqrt()),cexp:e=>W(new C(e.re,e.im).exp()),cln:e=>W(new C(e.re,e.im).log()),cpow:(e,n)=>{let t=typeof e=="number"?new C(e,0):new C(e.re,e.im),i=typeof n=="number"?new C(n,0):new C(n.re,n.im);return W(t.pow(i))},ccot:e=>W(new C(e.re,e.im).cot()),csec:e=>W(new C(e.re,e.im).sec()),ccsc:e=>W(new C(e.re,e.im).csc()),ccoth:e=>W(new C(e.re,e.im).coth()),csech:e=>W(new C(e.re,e.im).sech()),ccsch:e=>W(new C(e.re,e.im).csch()),cacot:e=>W(new C(e.re,e.im).acot()),casec:e=>W(new C(e.re,e.im).asec()),cacsc:e=>W(new C(e.re,e.im).acsc()),cacoth:e=>W(new C(e.re,e.im).acoth()),casech:e=>W(new C(e.re,e.im).asech()),cacsch:e=>W(new C(e.re,e.im).acsch()),cabs:e=>new C(e.re,e.im).abs(),carg:e=>new C(e.re,e.im).arg(),cconj:e=>W(new C(e.re,e.im).conjugate()),cneg:e=>({re:-e.re,im:-e.im}),...Up},Jr=class extends Function{SYS=yl;constructor(n,t=""){return super("_SYS","_",t?`${t};return ${n}`:`return ${n}`),new Proxy(this,{apply:(i,r,s)=>super.apply(r,[this.SYS,...s]),get:(i,r)=>r==="toString"?()=>n:r==="isCompiled"?!0:i[r]})}},yi=class extends Function{SYS=yl;constructor(n,t){return super("_SYS",...t,`return ${n}`),new Proxy(this,{apply:(i,r,s)=>super.apply(r,[this.SYS,...s]),get:(i,r)=>r==="toString"?()=>`(${t.join(", ")}) => ${n}`:r==="isCompiled"?!0:i[r]})}},xi=class{getOperators(){return Br}getFunctions(){return Vr}createTarget(n={}){return{language:"javascript",operators:t=>Br[t],functions:t=>Vr[t],var:t=>({Pi:"Math.PI",ExponentialE:"Math.E",NaN:"Number.NaN",ImaginaryUnit:"({ re: 0, im: 1 })",Half:"0.5",MachineEpsilon:"Number.EPSILON",GoldenRatio:"((1 + Math.sqrt(5)) / 2)",CatalanConstant:"0.91596559417721901",EulerGamma:"0.57721566490153286"})[t],string:t=>JSON.stringify(t),number:t=>t.toString(),complex:(t,i)=>`({ re: ${t}, im: ${i} })`,indent:0,ws:t=>t??"",preamble:"",...n}}compile(n,t={}){let{operators:i,functions:r,vars:s,imports:o=[],preamble:a,realOnly:u}=t,l=n.unknowns,c=o.map(g=>{if(typeof g=="function")return g.toString();throw new Error(`Unsupported import \`${g}\``)}).join(`
47
+ `),f={};if(r)for(let[g,v]of Object.entries(r))typeof v=="function"?Wp(v)?(c+=`${v.toString()};
48
+ `,f[g]=v.name):(c+=`const ${g} = ${v.toString()};
49
+ `,f[g]=g):typeof v=="string"&&(f[g]=v);let d=g=>{if(i){let v=typeof i=="function"?i(g):i[g];if(v)return v}return Br[g]},m=this.createTarget({operators:d,functions:g=>f?.[g]?f[g]:Vr[g],var:g=>{if(s&&g in s)return JSON.stringify(s[g]);let v={Pi:"Math.PI",ExponentialE:"Math.E",NaN:"Number.NaN",ImaginaryUnit:"({ re: 0, im: 1 })",Half:"0.5",MachineEpsilon:"Number.EPSILON",GoldenRatio:"((1 + Math.sqrt(5)) / 2)",CatalanConstant:"0.91596559417721901",EulerGamma:"0.57721566490153286"}[g];if(v!==void 0)return v;if(l.includes(g))return`_.${g}`},preamble:(a??"")+c});return Hp(n,m,u)}};function qr(e){let n=e.run;return{...e,run:((...i)=>{let r=n(...i);return typeof r=="object"&&r!==null&&"im"in r?r.im===0?r.re:NaN:r})}}function Hp(e,n,t){if(h(e,"Function")){let o=e.ops,a=o.slice(1).map(f=>T(f)?f.symbol:"_"),u=b.compile(o[0].canonical,{...n,var:f=>a.includes(f)?f:n.var(f)}),l=new yi(u,a),c={target:"javascript",success:!0,code:`(${a.join(", ")}) => ${u}`,calling:"lambda",run:l};return t?qr(c):c}if(T(e)){let o=n.operators?.(e.symbol);if(o){let a=new yi(`a ${o[0]} b`,["a","b"]),u={target:"javascript",success:!0,code:`(a, b) => a ${o[0]} b`,calling:"lambda",run:a};return t?qr(u):u}}let i=b.compile(e,n),r=new Jr(i,n.preamble),s={target:"javascript",success:!0,code:i,calling:"expression",run:r};return t?qr(s):s}var Zp=100;function xl(e){e.operator;let n=e,t=T(n.op1)?n.op1.symbol:"_",i=n.op2,r=n.op3,s=i.re,o=r.re;return{index:t,lowerExpr:i,upperExpr:r,lowerNum:!isNaN(s)&&Number.isFinite(s)?Math.floor(s):void 0,upperNum:!isNaN(o)&&Number.isFinite(o)?Math.floor(o):void 0}}function gl(e,n,t){return n!==void 0?String(n):`Math.floor(${b.compile(e,t)})`}function bl(e,n,t,i){if(!n[0])throw new Error(`${e}: no body`);if(!n[1])throw new Error(`${e}: no indexing set`);let{index:r,lowerExpr:s,upperExpr:o,lowerNum:a,upperNum:u}=xl(n[1]),l=e==="Sum",c=l?"+":"*",f=l?"0":"1",d=b.isComplexValued(n[0]),m=a!==void 0&&u!==void 0;if(m&&a>u)return f;if(m&&u-a+1<=Zp){let P=[];for(let Z=a;Z<=u;Z++){let se={...i,var:oe=>oe===r?String(Z):i.var(oe)};P.push(`(${b.compile(n[0],se)})`)}if(!d)return`(${P.join(` ${c} `)})`;let J=P.map((Z,se)=>`_t${se}`),H=P.map((Z,se)=>`const ${J[se]} = ${Z}`).join("; ");if(l){let Z=J.map(oe=>`${oe}.re`).join(" + "),se=J.map(oe=>`${oe}.im`).join(" + ");return`(() => { ${H}; return { re: ${Z}, im: ${se} }; })()`}let O=J[0],ue=[H];for(let Z=1;Z<J.length;Z++){let se=O;O=`_p${Z}`,ue.push(`const ${O} = { re: ${se}.re * ${J[Z]}.re - ${se}.im * ${J[Z]}.im, im: ${se}.re * ${J[Z]}.im + ${se}.im * ${J[Z]}.re }`)}return`(() => { ${ue.join("; ")}; return ${O}; })()`}let g=gl(s,a,i),v=gl(o,u,i),N=b.compile(n[0],{...i,var:$=>$===r?r:i.var($)}),M=b.tempVar();if(d){let $=b.tempVar();return l?`(() => { let ${M} = { re: 0, im: 0 }; let ${r} = ${g}; const _upper = ${v}; while (${r} <= _upper) { const ${$} = ${N}; ${M} = { re: ${M}.re + ${$}.re, im: ${M}.im + ${$}.im }; ${r}++; } return ${M}; })()`:`(() => { let ${M} = { re: 1, im: 0 }; let ${r} = ${g}; const _upper = ${v}; while (${r} <= _upper) { const ${$} = ${N}; ${M} = { re: ${M}.re * ${$}.re - ${M}.im * ${$}.im, im: ${M}.re * ${$}.im + ${M}.im * ${$}.re }; ${r}++; } return ${M}; })()`}return`(() => { let ${M} = ${f}; let ${r} = ${g}; const _upper = ${v}; while (${r} <= _upper) { ${M} ${c}= ${N}; ${r}++; } return ${M}; })()`}function Yp(e,n,t){let{index:i,lowerExpr:r,upperExpr:s,lowerNum:o,upperNum:a}=xl(e[1]),u=b.compile(e[0],{...t,var:f=>f===i?f:t.var(f)}),l=o!==void 0?String(o):b.compile(r,t),c=a!==void 0?String(a):b.compile(s,t);return`_SYS.integrate((${i}) => (${u}), ${l}, ${c})`}function Wp(e){let n=e.toString();return n.includes("=>")?!1:n.startsWith("function ")&&n.includes(e.name)}function zr(e){if(!Number.isInteger(e))return NaN;if(e<0)return e%2===0?-zr(-e):zr(-e);if(e<=1)return e;let n=0,t=1;for(let i=2;i<=e;i++){let r=n+t;n=t,t=r}return t}var vl={Add:["+",11],Negate:["-",14],Subtract:["-",11],Multiply:["*",12],Divide:["/",13],Equal:["==",8],NotEqual:["!=",8],LessEqual:["<=",9],GreaterEqual:[">=",9],Less:["<",9],Greater:[">",9],And:["&&",4],Or:["||",3],Not:["!",14]};function Se(e){return e?.language==="wgsl"?"vec2f":"vec2"}function Gn(e){return e?.language==="wgsl"?"vec3f":"vec3"}function Gr(e){return e?.language==="wgsl"?"bitcast<f32>(0x7fc00000u)":"(0.0 / 0.0)"}function jr(e,n,t,i){return i?.language==="wgsl"?`select(${t}, ${n}, ${e})`:`((${e}) ? (${n}) : (${t}))`}function Ur(e){return le(e)?e.string?.toLowerCase()??null:null}function El(e,n,t){let i=Q(e);return i!==void 0&&Number.isInteger(i)?i.toString():`${t?.language==="wgsl"?"i32":"int"}(${n(e)})`}var Xp=100;function Nl(e,n,t,i){if(!n[0])throw new Error(`${e}: no body`);if(!n[1])throw new Error(`${e}: no indexing set`);if(b.isComplexValued(n[0]))throw new Error(`${e}: complex-valued body not supported in GPU targets`);let r=n[1];if(!h(r,"Limits"))throw new Error(`${e}: expected Limits indexing set`);let s=r.ops,o=T(s[0])?s[0].symbol:"_",a=s[1].re,u=s[2].re,l=!isNaN(a)&&Number.isFinite(a)?Math.floor(a):void 0,c=!isNaN(u)&&Number.isFinite(u)?Math.floor(u):void 0,f=e==="Sum",d=f?"+":"*",m=f?"0.0":"1.0",g=i.language==="wgsl",v=l!==void 0&&c!==void 0;if(v&&l>c)return m;if(v&&c-l+1<=Xp){let oe=[];for(let te=l;te<=c;te++){let Je=kn(te),ze={...i,var:St=>St===o?Je:i.var(St)};oe.push(`(${b.compile(n[0],ze)})`)}return`(${oe.join(` ${d} `)})`}let N=b.tempVar(),M=g?"f32":"float",$=g?"i32":"int",P={...i,var:oe=>oe===o?g?`f32(${o})`:`float(${o})`:i.var(oe)},J=b.compile(n[0],P),H=l!==void 0?String(l):b.compile(s[1],i),O=c!==void 0?String(c):b.compile(s[2],i),ue=g?`var ${N}: ${M}`:`${M} ${N}`,Z=g?`var ${o}: ${$}`:`${$} ${o}`;return[`${ue} = ${m};`,`for (${Z} = ${H}; ${o} <= ${O}; ${o}++) {`,` ${N} ${d}= ${J};`,"}",`return ${N};`].join(`
50
+ `)}var Qp={Add:(e,n,t)=>{if(e.length===0)return"0.0";if(e.length===1)return n(e[0]);if(!e.some(l=>b.isComplexValued(l)))return on(e.map(l=>n(l)),"0.0","+");let r=e.map(l=>Nu(l,n));if(r.some(l=>l===null)){let l=Se(t);return e.map(c=>{let f=n(c);return b.isComplexValued(c)?f:`${l}(${f}, 0.0)`}).join(" + ")}let s=[],o=[];for(let l of r)l.re!==null&&s.push(l.re),l.im!==null&&o.push(l.im);let a=on(s,"0.0","+"),u=on(o,"0.0","+");return`${Se(t)}(${a}, ${u})`},Multiply:(e,n,t)=>{if(e.length===0)return"1.0";if(e.length===1)return n(e[0]);if(!e.some(l=>b.isComplexValued(l)))return on(e.map(l=>n(l)),"1.0","*");let r=e.findIndex(l=>T(l,"ImaginaryUnit")||R(l)&&l.re===0&&l.im!==0);if(r>=0){let l=e[r],c=T(l,"ImaginaryUnit")?1:l.im,f=e.filter((v,N)=>N!==r),d=Se(t);if(f.length===0)return`${d}(0.0, ${ae(c)})`;let m=f.map(v=>ri(v,n(v)));c!==1&&m.unshift(ae(c));let g=on(m,"1.0","*");return`${d}(0.0, ${g})`}let s=[],o=[];for(let l of e)b.isComplexValued(l)?o.push(n(l)):s.push(ri(l,n(l)));let a=on(s,"1.0","*"),u=o[0];for(let l=1;l<o.length;l++)u=`_gpu_cmul(${u}, ${o[l]})`;return a!=="1.0"&&(u=`(${a} * ${u})`),u},Divide:(e,n,t)=>{if(e.length===0)return"1.0";if(e.length===1)return n(e[0]);let i=b.isComplexValued(e[0]),r=e.length>=2&&b.isComplexValued(e[1]);if(!i&&!r){if(e.length===2){let a=Q(e[0]),u=Q(e[1]);return a!==void 0&&u!==void 0&&u!==0?ae(a/u):u===1?n(e[0]):`${n(e[0])} / ${n(e[1])}`}let o=n(e[0]);for(let a=1;a<e.length;a++)o=`${o} / ${n(e[a])}`;return o}return i&&r?`_gpu_cdiv(${n(e[0])}, ${n(e[1])})`:i&&!r?`(${n(e[0])} / ${n(e[1])})`:`_gpu_cdiv(${Se(t)}(${n(e[0])}, 0.0), ${n(e[1])})`},Negate:([e],n,t)=>{if(e===null)throw new Error("Negate: no argument");let i=Q(e);return i!==void 0?ae(-i):R(e)&&e.im!==0?`${Se(t)}(${ae(-e.re)}, ${ae(-e.im)})`:T(e,"ImaginaryUnit")?`${Se(t)}(0.0, -1.0)`:`(-${n(e)})`},Abs:(e,n)=>b.isComplexValued(e[0])?`length(${n(e[0])})`:b.isNonNegative(e[0])?n(e[0]):`abs(${n(e[0])})`,Arccos:(e,n)=>b.isComplexValued(e[0])?`_gpu_cacos(${n(e[0])})`:`acos(${n(e[0])})`,Arcsin:(e,n)=>b.isComplexValued(e[0])?`_gpu_casin(${n(e[0])})`:`asin(${n(e[0])})`,Arctan:(e,n)=>b.isComplexValued(e[0])?`_gpu_catan(${n(e[0])})`:`atan(${n(e[0])})`,Ceil:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`ceil(${n(e[0])})`,Clamp:"clamp",Cos:(e,n)=>b.isComplexValued(e[0])?`_gpu_ccos(${n(e[0])})`:`cos(${n(e[0])})`,Degrees:"radians",Exp:(e,n)=>b.isComplexValued(e[0])?`_gpu_cexp(${n(e[0])})`:`exp(${n(e[0])})`,Exp2:"exp2",First:(e,n)=>`${n(e[0])}.x`,Second:(e,n)=>`${n(e[0])}.y`,Third:(e,n)=>`${n(e[0])}.z`,Floor:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`floor(${n(e[0])})`,Fract:"fract",Ln:(e,n)=>b.isComplexValued(e[0])?`_gpu_cln(${n(e[0])})`:`log(${n(e[0])})`,Log2:"log2",Max:"max",Min:"min",Mix:"mix",If:(e,n,t)=>{if(e.length!==3)throw new Error("If: wrong number of arguments");return jr(n(e[0]),n(e[1]),n(e[2]),t)},When:(e,n,t)=>{if(e.length!==2)throw new Error("When: expected exactly 2 arguments (expr, cond)");return T(e[1],"True")?`(${n(e[0])})`:T(e[1],"False")?Gr(t):jr(n(e[1]),n(e[0]),Gr(t),t)},Which:(e,n,t)=>{if(e.length<2||e.length%2!==0)throw new Error("Which: expected condition/value pairs");let i=r=>{if(r>=e.length)return Gr(t);let s=e[r],o=e[r+1];return T(s,"True")?`(${n(o)})`:jr(n(s),n(o),i(r+2),t)};return i(0)},Power:(e,n,t)=>{let i=e[0],r=e[1];if(i===null)throw new Error("Power: no argument");if(b.isComplexValued(i)||b.isComplexValued(r)){if(T(i,"ExponentialE"))return`_gpu_cexp(${n(r)})`;let a=Se(t),u=b.isComplexValued(i)?n(i):`${a}(${n(i)}, 0.0)`,l=b.isComplexValued(r)?n(r):`${a}(${n(r)}, 0.0)`;return`_gpu_cpow(${u}, ${l})`}let s=Q(i),o=Q(r);if(s!==void 0&&o!==void 0)return ae(Math.pow(s,o));if(o===0)return"1.0";if(o===1)return n(i);if(o===2&&(T(i)||R(i))){let a=n(i);return`(${a} * ${a})`}return o===-1?`(1.0 / ${n(i)})`:o===.5?`sqrt(${n(i)})`:`pow(${n(i)}, ${n(r)})`},Radians:"radians",Round:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`round(${n(e[0])})`,Sign:"sign",Sin:(e,n)=>b.isComplexValued(e[0])?`_gpu_csin(${n(e[0])})`:`sin(${n(e[0])})`,Smoothstep:"smoothstep",Sqrt:(e,n)=>{if(b.isComplexValued(e[0]))return`_gpu_csqrt(${n(e[0])})`;let t=Q(e[0]);return t!==void 0?ae(Math.sqrt(t)):`sqrt(${n(e[0])})`},Step:"step",Tan:(e,n)=>b.isComplexValued(e[0])?`_gpu_ctan(${n(e[0])})`:`tan(${n(e[0])})`,Truncate:(e,n)=>b.isIntegerValued(e[0])?n(e[0]):`trunc(${n(e[0])})`,Real:(e,n)=>b.isComplexValued(e[0])?`(${n(e[0])}).x`:n(e[0]),Imaginary:(e,n)=>b.isComplexValued(e[0])?`(${n(e[0])}).y`:"0.0",Argument:(e,n)=>{if(b.isComplexValued(e[0])){let t=n(e[0]);return`atan(${t}.y, ${t}.x)`}return`(${n(e[0])} >= 0.0 ? 0.0 : 3.14159265359)`},Conjugate:(e,n,t)=>{if(b.isComplexValued(e[0])){let i=Se(t),r=n(e[0]);return`${i}(${r}.x, -${r}.y)`}return n(e[0])},Remainder:([e,n],t)=>{if(e===null||n===null)throw new Error("Remainder: missing argument");return`(${t(e)} - ${t(n)} * round(${t(e)} / ${t(n)}))`},Cot:([e],n)=>{if(e===null)throw new Error("Cot: no argument");if(b.isComplexValued(e))return`_gpu_cdiv(_gpu_ccos(${n(e)}), _gpu_csin(${n(e)}))`;let t=n(e);return`(cos(${t}) / sin(${t}))`},Csc:([e],n,t)=>{if(e===null)throw new Error("Csc: no argument");return b.isComplexValued(e)?`_gpu_cdiv(${Se(t)}(1.0, 0.0), _gpu_csin(${n(e)}))`:`(1.0 / sin(${n(e)}))`},Sec:([e],n,t)=>{if(e===null)throw new Error("Sec: no argument");return b.isComplexValued(e)?`_gpu_cdiv(${Se(t)}(1.0, 0.0), _gpu_ccos(${n(e)}))`:`(1.0 / cos(${n(e)}))`},Arccot:([e],n)=>{if(e===null)throw new Error("Arccot: no argument");return`atan(1.0 / (${n(e)}))`},Arccsc:([e],n)=>{if(e===null)throw new Error("Arccsc: no argument");return`asin(1.0 / (${n(e)}))`},Arcsec:([e],n)=>{if(e===null)throw new Error("Arcsec: no argument");return`acos(1.0 / (${n(e)}))`},Sinh:(e,n)=>b.isComplexValued(e[0])?`_gpu_csinh(${n(e[0])})`:`sinh(${n(e[0])})`,Cosh:(e,n)=>b.isComplexValued(e[0])?`_gpu_ccosh(${n(e[0])})`:`cosh(${n(e[0])})`,Tanh:(e,n)=>b.isComplexValued(e[0])?`_gpu_ctanh(${n(e[0])})`:`tanh(${n(e[0])})`,Coth:([e],n)=>{if(e===null)throw new Error("Coth: no argument");if(b.isComplexValued(e))return`_gpu_cdiv(_gpu_ccosh(${n(e)}), _gpu_csinh(${n(e)}))`;let t=n(e);return`(cosh(${t}) / sinh(${t}))`},Csch:([e],n,t)=>{if(e===null)throw new Error("Csch: no argument");return b.isComplexValued(e)?`_gpu_cdiv(${Se(t)}(1.0, 0.0), _gpu_csinh(${n(e)}))`:`(1.0 / sinh(${n(e)}))`},Sech:([e],n,t)=>{if(e===null)throw new Error("Sech: no argument");return b.isComplexValued(e)?`_gpu_cdiv(${Se(t)}(1.0, 0.0), _gpu_ccosh(${n(e)}))`:`(1.0 / cosh(${n(e)}))`},Arcosh:(e,n)=>b.isComplexValued(e[0])?`_gpu_cacosh(${n(e[0])})`:`acosh(${n(e[0])})`,Arsinh:(e,n)=>b.isComplexValued(e[0])?`_gpu_casinh(${n(e[0])})`:`asinh(${n(e[0])})`,Artanh:(e,n)=>b.isComplexValued(e[0])?`_gpu_catanh(${n(e[0])})`:`atanh(${n(e[0])})`,Arcoth:([e],n)=>{if(e===null)throw new Error("Arcoth: no argument");return`atanh(1.0 / (${n(e)}))`},Arcsch:([e],n)=>{if(e===null)throw new Error("Arcsch: no argument");return`asinh(1.0 / (${n(e)}))`},Arsech:([e],n)=>{if(e===null)throw new Error("Arsech: no argument");return`acosh(1.0 / (${n(e)}))`},Arctan2:(e,n)=>{if(e.length<2)throw new Error("Arctan2: need two arguments");return`atan(${n(e[0])}, ${n(e[1])})`},Hypot:([e,n],t)=>{if(e===null||n===null)throw new Error("Hypot: need two arguments");return`length(vec2(${t(e)}, ${t(n)}))`},Haversine:([e],n)=>{if(e===null)throw new Error("Haversine: no argument");return`((1.0 - cos(${n(e)})) * 0.5)`},InverseHaversine:([e],n)=>{if(e===null)throw new Error("InverseHaversine: no argument");return`(2.0 * asin(sqrt(${n(e)})))`},Gamma:([e],n)=>{if(e===null)throw new Error("Gamma: no argument");return`_gpu_gamma(${n(e)})`},GammaLn:([e],n)=>{if(e===null)throw new Error("GammaLn: no argument");return`_gpu_gammaln(${n(e)})`},Factorial:([e],n)=>{if(e===null)throw new Error("Factorial: no argument");return`_gpu_gamma(${n(e)} + 1.0)`},Beta:([e,n],t)=>{if(e===null||n===null)throw new Error("Beta: need two arguments");let i=t(e),r=t(n);return`(_gpu_gamma(${i}) * _gpu_gamma(${r}) / _gpu_gamma(${i} + ${r}))`},Erf:([e],n)=>{if(e===null)throw new Error("Erf: no argument");return`_gpu_erf(${n(e)})`},Erfc:([e],n)=>{if(e===null)throw new Error("Erfc: no argument");return`(1.0 - _gpu_erf(${n(e)}))`},ErfInv:([e],n)=>{if(e===null)throw new Error("ErfInv: no argument");return`_gpu_erfinv(${n(e)})`},Heaviside:([e],n)=>{if(e===null)throw new Error("Heaviside: no argument");return`_gpu_heaviside(${n(e)})`},Sinc:([e],n)=>{if(e===null)throw new Error("Sinc: no argument");return`_gpu_sinc(${n(e)})`},FresnelC:([e],n)=>{if(e===null)throw new Error("FresnelC: no argument");return`_gpu_fresnelC(${n(e)})`},FresnelS:([e],n)=>{if(e===null)throw new Error("FresnelS: no argument");return`_gpu_fresnelS(${n(e)})`},BesselJ:([e,n],t,i)=>{if(e===null||n===null)throw new Error("BesselJ: need two arguments");return`_gpu_besselJ(${i?.language==="wgsl"?"i32":"int"}(${t(e)}), ${t(n)})`},Lb:"log2",Log:(e,n)=>{if(e.length===0)throw new Error("Log: no argument");return e.length===1?`(log(${n(e[0])}) / log(10.0))`:`(log(${n(e[0])}) / log(${n(e[1])}))`},Log10:([e],n)=>{if(e===null)throw new Error("Log10: no argument");return`(log(${n(e)}) * 0.4342944819032518)`},Lg:([e],n)=>{if(e===null)throw new Error("Lg: no argument");return`(log(${n(e)}) * 0.4342944819032518)`},Square:([e],n)=>{if(e===null)throw new Error("Square: no argument");if(T(e)||R(e)){let t=n(e);return`(${t} * ${t})`}return`pow(${n(e)}, 2.0)`},Root:([e,n],t)=>{if(e===null)throw new Error("Root: no argument");if(n==null)return`sqrt(${t(e)})`;let i=Q(n);if(i===2)return`sqrt(${t(e)})`;let r=Q(e);return r!==void 0&&i!==void 0?ae(Math.pow(r,1/i)):`pow(${t(e)}, 1.0 / ${t(n)})`},ColorMix:(e,n)=>{if(e.length<2)throw new Error("ColorMix: need two colors");let t=n(e[0]),i=n(e[1]),r=e.length>=3?n(e[2]):"0.5";return`_gpu_color_mix(${t}, ${i}, ${r})`},ColorContrast:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorContrast: need two colors");return`_gpu_apca(${t(e)}, ${t(n)})`},ContrastingColor:(e,n,t)=>{if(e.length===0)throw new Error("ContrastingColor: no argument");let i=n(e[0]);if(e.length>=3){let u=n(e[1]),l=n(e[2]);return`(abs(_gpu_apca(${i}, ${u})) >= abs(_gpu_apca(${i}, ${l})) ? ${u} : ${l})`}let s=t?.language==="wgsl"?"vec3f":"vec3",o=`${s}(0.0)`,a=`${s}(1.0, 0.0, 0.0)`;return`((_gpu_apca(${i}, ${o}) > 50.0) ? ${o} : ${a})`},ColorToColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorToColorspace: need color and space");let i=Ur(n);if(i===null)throw new Error("ColorToColorspace: space must be a string literal");let r=t(e);switch(i){case"oklch":return r;case"oklab":case"lab":return`_gpu_oklch_to_oklab(${r})`;case"rgb":return`_gpu_oklch_to_srgb(${r})`;case"hsl":return`_gpu_rgb_to_hsl(_gpu_oklch_to_srgb(${r}))`;case"hsv":return`_gpu_rgb_to_hsv(_gpu_oklch_to_srgb(${r}))`;default:throw new Error(`ColorToColorspace: unsupported space "${i}" on GPU target`)}},ColorFromColorspace:([e,n],t)=>{if(e===null||n===null)throw new Error("ColorFromColorspace: need components and space");let i=Ur(n);if(i===null)throw new Error("ColorFromColorspace: space must be a string literal");let r=t(e);switch(i){case"oklch":return r;case"oklab":case"lab":return`_gpu_oklab_to_oklch(${r})`;case"rgb":return`_gpu_srgb_to_oklch(${r})`;case"hsl":return`_gpu_srgb_to_oklch(_gpu_hsl_to_rgb(${r}))`;case"hsv":return`_gpu_srgb_to_oklch(_gpu_hsv_to_rgb(${r}))`;default:throw new Error(`ColorFromColorspace: unsupported space "${i}" on GPU target`)}},Color:([e],n,t)=>{if(e===null)throw new Error("Color: no argument");let i=Ur(e);if(i===null)throw new Error("Color: argument must be a string literal on GPU target");let r=en(i);if(r===0&&i.trim().toLowerCase()!=="transparent")throw new Error(`Color: invalid color string "${i}"`);let s=r>>>24&255,o=r>>>16&255,a=r>>>8&255,u=Ee({r:s,g:o,b:a});return`${Gn(t)}(${ae(u.L)}, ${ae(u.C)}, ${ae(u.H)})`},Rgb:(e,n,t)=>{if(e.length<3)throw new Error("Rgb: need 3 components");return`_gpu_srgb_to_oklch(${Gn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])}))`},Hsv:(e,n,t)=>{if(e.length<3)throw new Error("Hsv: need 3 components");return`_gpu_srgb_to_oklch(_gpu_hsv_to_rgb(${Gn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])})))`},Hsl:(e,n,t)=>{if(e.length<3)throw new Error("Hsl: need 3 components");return`_gpu_srgb_to_oklch(_gpu_hsl_to_rgb(${Gn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])})))`},Oklab:(e,n,t)=>{if(e.length<3)throw new Error("Oklab: need 3 components");return`_gpu_oklab_to_oklch(${Gn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])}))`},Oklch:(e,n,t)=>{if(e.length<3)throw new Error("Oklch: need 3 components");return`${Gn(t)}(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`},AsOklch:([e],n)=>{if(e===null)throw new Error("AsOklch: no argument");return n(e)},AsOklab:([e],n)=>{if(e===null)throw new Error("AsOklab: no argument");return`_gpu_oklch_to_oklab(${n(e)})`},AsRgb:([e],n)=>{if(e===null)throw new Error("AsRgb: no argument");return`_gpu_oklch_to_srgb(${n(e)})`},AsHsv:([e],n)=>{if(e===null)throw new Error("AsHsv: no argument");return`_gpu_rgb_to_hsv(_gpu_oklch_to_srgb(${n(e)}))`},AsHsl:([e],n)=>{if(e===null)throw new Error("AsHsl: no argument");return`_gpu_rgb_to_hsl(_gpu_oklch_to_srgb(${n(e)}))`},Mandelbrot:([e,n],t,i)=>{if(e===null||n===null)throw new Error("Mandelbrot: missing arguments");let r=El(n,t,i);return`_fractal_mandelbrot(${t(e)}, ${r})`},Julia:([e,n,t],i,r)=>{if(e===null||n===null||t===null)throw new Error("Julia: missing arguments");let s=El(t,i,r);return`_fractal_julia(${i(e)}, ${i(n)}, ${s})`},Cross:"cross",Distance:"distance",Dot:"dot",Length:"length",Normalize:"normalize",Reflect:"reflect",Refract:"refract",Sum:(e,n,t)=>Nl("Sum",e,n,t),Product:(e,n,t)=>Nl("Product",e,n,t),Range:(e,n,t)=>{if(e.length<2||e.length>3)throw new Error("Range: GPU compile expects 2 or 3 arguments (lo, hi, step?)");let i=e[0].re,r=e[1].re,s=e.length===3?e[2].re:1;if(!Number.isFinite(i)||!Number.isFinite(r)||!Number.isFinite(s))throw new Error("Range: GPU compile requires constant numeric bounds (non-constant ranges must be materialized at JS host then uploaded as a uniform)");if(s===0)throw new Error("Range: step cannot be zero");let o=Math.max(0,Math.floor((r-i)/s)+1);if(o===0)throw new Error("Range: empty range (lo > hi for positive step, or lo < hi for negative step)");if(o>256)throw new Error(`Range: GPU compile inlines ranges up to 256 elements (got ${o})`);let a=[];for(let c=0;c<o;c++)a.push(i+c*s);return`${t.language==="wgsl"?`array<f32, ${o}>`:`float[${o}]`}(${a.map(kn).join(", ")})`},Loop:(e,n,t)=>{if(!e[0])throw new Error("Loop: no body");if(!e[1])throw new Error("Loop: no indexing set");let i=e[1];if(!h(i,"Element"))throw new Error("Loop: expected Element(index, Range(lo, hi))");let r=i.ops[0],s=i.ops[1];if(!T(r))throw new Error("Loop: index must be a symbol");if(!h(s,"Range"))throw new Error("Loop: expected Range(lo, hi)");let o=r.symbol,a=Math.floor(s.ops[0].re),u=Math.floor(s.ops[1].re);if(!Number.isFinite(a)||!Number.isFinite(u))throw new Error("Loop: bounds must be finite numbers");let l=t.language==="wgsl",c=l?"i32":"int",f=b.compile(e[0],{...t,var:m=>m===o?o:t.var(m)});return`for (${l?`var ${o}: ${c}`:`${c} ${o}`} = ${a}; ${o} <= ${u}; ${o}++) {
51
51
  ${f};
52
- }`},GCD:(e,n)=>{if(e.length<2)throw new Error("GCD: need at least two arguments");if(e.length>2)throw new Error("GCD: GPU target supports only two-argument GCD");let t=e[0],i=e[1];if(t===null||i===null)throw new Error("GCD: missing argument");return`_gpu_gcd(${n(t)}, ${n(i)})`},Variance:(e,n)=>{let t;if(e.length===1&&h(e[0],"List"))t=e[0].ops;else if(e.length>=2)t=e;else throw new Error("Variance: GPU target requires a List argument or at least 2 scalar arguments");let i=t.length;if(i<2)throw new Error("Variance: need at least 2 elements");let r=t.map(u=>n(u)),o=`((${r.join(" + ")}) / ${vn(i)})`;return`((${r.map(u=>`(${u} - ${o}) * (${u} - ${o})`).join(" + ")}) / ${vn(i-1)})`},Median:(e,n)=>{let t;if(e.length===1&&h(e[0],"List"))t=e[0].ops;else if(e.length>=1)t=e;else throw new Error("Median: GPU target requires a List argument or at least 1 scalar argument");let i=t.length;if(i===0)throw new Error("Median: empty list");if(i>8)throw new Error(`Median: GPU target supports up to 8 elements via inline sorting network (got ${i}). For larger lists, compute on the CPU and pass the result as a uniform.`);let r=t.map(s=>n(s));return i===1?r[0]:`_gpu_median_${i}(${r.join(", ")})`},Random:(e,n,t)=>{if(e.length===0){if(t.language==="wgsl")throw new Error("Random(): WGSL compile requires an explicit seed argument. WGSL has no gl_FragCoord built-in outside fragment entry points, so the no-arg fallback used in GLSL is unavailable. Use Random(seed) where seed is a deterministic per-invocation value.");return"_gpu_random(gl_FragCoord.x + gl_FragCoord.y * 1024.0)"}if(e.length===1){let i=e[0];if(g.isIntegerValued(i)){let r=n(i);return`floor(_gpu_random(float(${r})) * float(${r}))`}return`_gpu_random(${n(i)})`}if(e.length===2){if(t.language==="wgsl")throw new Error("Random(m, n): WGSL compile requires explicit seeding. Use a seeded variant or compute the integer range manually.");let i=n(e[0]),r=n(e[1]);return`(float(${i}) + floor(_gpu_random(gl_FragCoord.x + gl_FragCoord.y * 1024.0) * float((${r}) - (${i}))))`}throw new Error("Random: GPU compile expects 0, 1, or 2 arguments")},Function:()=>{throw new Error("Anonymous functions (Function) are not supported in GPU targets")}};function li(e,n,t,i,r){let s=e[0];if(!h(s))return n(s);let o=s.ops;if(o.length===0)return n(s);let a=o.length,u=o[0],l=h(u)?u.nops:0;if(l===1&&o.every(c=>h(c)&&c.nops===1)){let c=o.map(f=>n(h(f)?f.ops[0]:f));return a>=2&&a<=4?`${t(a)}(${c.join(", ")})`:`${r(a)}(${c.join(", ")})`}if(a===l&&a>=2&&a<=4&&o.every(c=>h(c)&&c.nops===l)){let c=[];for(let f=0;f<l;f++){let m=o.map(d=>n(h(d)?d.ops[f]:d));c.push(`${t(a)}(${m.join(", ")})`)}return`${i(a)}(${c.join(", ")})`}return n(s)}var Xf=`
52
+ }`},GCD:(e,n)=>{if(e.length<2)throw new Error("GCD: need at least two arguments");if(e.length>2)throw new Error("GCD: GPU target supports only two-argument GCD");let t=e[0],i=e[1];if(t===null||i===null)throw new Error("GCD: missing argument");return`_gpu_gcd(${n(t)}, ${n(i)})`},Variance:(e,n)=>{let t;if(e.length===1&&h(e[0],"List"))t=e[0].ops;else if(e.length>=2)t=e;else throw new Error("Variance: GPU target requires a List argument or at least 2 scalar arguments");let i=t.length;if(i<2)throw new Error("Variance: need at least 2 elements");let r=t.map(u=>n(u)),o=`((${r.join(" + ")}) / ${kn(i)})`;return`((${r.map(u=>`(${u} - ${o}) * (${u} - ${o})`).join(" + ")}) / ${kn(i-1)})`},Median:(e,n)=>{let t;if(e.length===1&&h(e[0],"List"))t=e[0].ops;else if(e.length>=1)t=e;else throw new Error("Median: GPU target requires a List argument or at least 1 scalar argument");let i=t.length;if(i===0)throw new Error("Median: empty list");if(i>8)throw new Error(`Median: GPU target supports up to 8 elements via inline sorting network (got ${i}). For larger lists, compute on the CPU and pass the result as a uniform.`);let r=t.map(s=>n(s));return i===1?r[0]:`_gpu_median_${i}(${r.join(", ")})`},Random:(e,n,t)=>{if(e.length===0){if(t.language==="wgsl")throw new Error("Random(): WGSL compile requires an explicit seed argument. WGSL has no gl_FragCoord built-in outside fragment entry points, so the no-arg fallback used in GLSL is unavailable. Use Random(seed) where seed is a deterministic per-invocation value.");return"_gpu_random(gl_FragCoord.x + gl_FragCoord.y * 1024.0)"}if(e.length===1){let i=e[0];if(b.isIntegerValued(i)){let r=n(i);return`floor(_gpu_random(float(${r})) * float(${r}))`}return`_gpu_random(${n(i)})`}if(e.length===2){if(t.language==="wgsl")throw new Error("Random(m, n): WGSL compile requires explicit seeding. Use a seeded variant or compute the integer range manually.");let i=n(e[0]),r=n(e[1]);return`(float(${i}) + floor(_gpu_random(gl_FragCoord.x + gl_FragCoord.y * 1024.0) * float((${r}) - (${i}))))`}throw new Error("Random: GPU compile expects 0, 1, or 2 arguments")},Function:()=>{throw new Error("Anonymous functions (Function) are not supported in GPU targets")}};function vi(e,n,t,i,r){let s=e[0];if(!h(s))return n(s);let o=s.ops;if(o.length===0)return n(s);let a=o.length,u=o[0],l=h(u)?u.nops:0;if(l===1&&o.every(c=>h(c)&&c.nops===1)){let c=o.map(f=>n(h(f)?f.ops[0]:f));return a>=2&&a<=4?`${t(a)}(${c.join(", ")})`:`${r(a)}(${c.join(", ")})`}if(a===l&&a>=2&&a<=4&&o.every(c=>h(c)&&c.nops===l)){let c=[];for(let f=0;f<l;f++){let d=o.map(m=>n(h(m)?m.ops[f]:m));c.push(`${t(a)}(${d.join(", ")})`)}return`${i(a)}(${c.join(", ")})`}return n(s)}var Kp=`
53
53
  float _gpu_gamma(float z) {
54
54
  const float PI = 3.14159265358979;
55
55
  // For z < 0.5, use reflection formula with inlined Lanczos (non-recursive)
@@ -80,7 +80,36 @@ float _gpu_gammaln(float z) {
80
80
  - 1.0 / (360.0 * z3)
81
81
  + 1.0 / (1260.0 * z3 * z * z);
82
82
  }
83
- `,Qf=`
83
+ `,em=`
84
+ fn _gpu_gamma(z: f32) -> f32 {
85
+ let PI = 3.14159265358979;
86
+ var w = z;
87
+ if (z < 0.5) { w = 1.0 - z; }
88
+ w = w - 1.0;
89
+ var x = 0.99999999999980993;
90
+ x = x + 676.5203681218851 / (w + 1.0);
91
+ x = x + -1259.1392167224028 / (w + 2.0);
92
+ x = x + 771.32342877765313 / (w + 3.0);
93
+ x = x + -176.61502916214059 / (w + 4.0);
94
+ x = x + 12.507343278686905 / (w + 5.0);
95
+ x = x + -0.13857109526572012 / (w + 6.0);
96
+ x = x + 9.9843695780195716e-6 / (w + 7.0);
97
+ x = x + 1.5056327351493116e-7 / (w + 8.0);
98
+ let t = w + 7.5;
99
+ let g = sqrt(2.0 * PI) * pow(t, w + 0.5) * exp(-t) * x;
100
+ if (z < 0.5) { return PI / (sin(PI * z) * g); }
101
+ return g;
102
+ }
103
+
104
+ fn _gpu_gammaln(z: f32) -> f32 {
105
+ let z3 = z * z * z;
106
+ return z * log(z) - z - 0.5 * log(z)
107
+ + 0.5 * log(2.0 * 3.14159265358979)
108
+ + 1.0 / (12.0 * z)
109
+ - 1.0 / (360.0 * z3)
110
+ + 1.0 / (1260.0 * z3 * z * z);
111
+ }
112
+ `,nm=`
84
113
  float _gpu_erf(float x) {
85
114
  float ax = abs(x);
86
115
  float t = 1.0 / (1.0 + 0.3275911 * ax);
@@ -98,41 +127,60 @@ float _gpu_erfinv(float x) {
98
127
  float x9 = x7 * x2;
99
128
  return sqrt(pi) * 0.5 * (x + (pi / 12.0) * x3 + (7.0 * pi * pi / 480.0) * x5 + (127.0 * pi * pi * pi / 40320.0) * x7 + (4369.0 * pi * pi * pi * pi / 5806080.0) * x9);
100
129
  }
101
- `,Kf=`
130
+ `,tm=`
131
+ fn _gpu_erf(x: f32) -> f32 {
132
+ let ax = abs(x);
133
+ let t = 1.0 / (1.0 + 0.3275911 * ax);
134
+ let y = ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t;
135
+ let result = 1.0 - y * exp(-ax * ax);
136
+ if (x < 0.0) { return -result; }
137
+ return result;
138
+ }
139
+
140
+ fn _gpu_erfinv(x: f32) -> f32 {
141
+ let pi = 3.14159265358979;
142
+ let x2 = x * x;
143
+ let x3 = x * x2;
144
+ let x5 = x3 * x2;
145
+ let x7 = x5 * x2;
146
+ let x9 = x7 * x2;
147
+ return sqrt(pi) * 0.5 * (x + (pi / 12.0) * x3 + (7.0 * pi * pi / 480.0) * x5 + (127.0 * pi * pi * pi / 40320.0) * x7 + (4369.0 * pi * pi * pi * pi / 5806080.0) * x9);
148
+ }
149
+ `,im=`
102
150
  float _gpu_heaviside(float x) {
103
151
  if (x < 0.0) return 0.0;
104
152
  if (x > 0.0) return 1.0;
105
153
  return 0.5;
106
154
  }
107
- `,ep=`
155
+ `,rm=`
108
156
  fn _gpu_heaviside(x: f32) -> f32 {
109
157
  if (x < 0.0) { return 0.0; }
110
158
  if (x > 0.0) { return 1.0; }
111
159
  return 0.5;
112
160
  }
113
- `,np=`
161
+ `,sm=`
114
162
  float _gpu_sinc(float x) {
115
163
  if (abs(x) < 1e-10) return 1.0;
116
164
  return sin(x) / x;
117
165
  }
118
- `,tp=`
166
+ `,om=`
119
167
  fn _gpu_sinc(x: f32) -> f32 {
120
168
  if (abs(x) < 1e-10) { return 1.0; }
121
169
  return sin(x) / x;
122
170
  }
123
- `,ip=`
171
+ `,am=`
124
172
  float _gpu_polevl(float x, float c[12], int n) {
125
173
  float ans = c[0];
126
174
  for (int i = 1; i < n; i++) ans = ans * x + c[i];
127
175
  return ans;
128
176
  }
129
- `,rp=`
177
+ `,um=`
130
178
  fn _gpu_polevl(x: f32, c: array<f32, 12>, n: i32) -> f32 {
131
179
  var ans = c[0];
132
180
  for (var i: i32 = 1; i < n; i++) { ans = ans * x + c[i]; }
133
181
  return ans;
134
182
  }
135
- `,sp=`
183
+ `,lm=`
136
184
  float _gpu_fresnelC(float x_in) {
137
185
  float sgn = x_in < 0.0 ? -1.0 : 1.0;
138
186
  float x = abs(x_in);
@@ -198,7 +246,7 @@ float _gpu_fresnelC(float x_in) {
198
246
 
199
247
  return sgn * 0.5;
200
248
  }
201
- `,op=`
249
+ `,cm=`
202
250
  fn _gpu_fresnelC(x_in: f32) -> f32 {
203
251
  let sgn: f32 = select(1.0, -1.0, x_in < 0.0);
204
252
  let x = abs(x_in);
@@ -267,7 +315,7 @@ fn _gpu_fresnelC(x_in: f32) -> f32 {
267
315
 
268
316
  return sgn * 0.5;
269
317
  }
270
- `,ap=`
318
+ `,fm=`
271
319
  float _gpu_fresnelS(float x_in) {
272
320
  float sgn = x_in < 0.0 ? -1.0 : 1.0;
273
321
  float x = abs(x_in);
@@ -333,7 +381,7 @@ float _gpu_fresnelS(float x_in) {
333
381
 
334
382
  return sgn * 0.5;
335
383
  }
336
- `,up=`
384
+ `,pm=`
337
385
  fn _gpu_fresnelS(x_in: f32) -> f32 {
338
386
  let sgn: f32 = select(1.0, -1.0, x_in < 0.0);
339
387
  let x = abs(x_in);
@@ -402,7 +450,7 @@ fn _gpu_fresnelS(x_in: f32) -> f32 {
402
450
 
403
451
  return sgn * 0.5;
404
452
  }
405
- `,lp=`
453
+ `,mm=`
406
454
  float _gpu_factorial(int n) {
407
455
  float f = 1.0;
408
456
  for (int i = 2; i <= n; i++) f *= float(i);
@@ -479,7 +527,7 @@ float _gpu_besselJ(int n, float x) {
479
527
  for (int k = 2; k <= M; k += 2) norm += 2.0 * vals[k];
480
528
  return sgn * vals[n] / norm;
481
529
  }
482
- `,cp=`
530
+ `,dm=`
483
531
  fn _gpu_factorial(n: i32) -> f32 {
484
532
  var f: f32 = 1.0;
485
533
  for (var i: i32 = 2; i <= n; i++) { f *= f32(i); }
@@ -556,7 +604,7 @@ fn _gpu_besselJ(n_in: i32, x_in: f32) -> f32 {
556
604
  for (var k2: i32 = 2; k2 <= M; k2 += 2) { norm += 2.0 * vals[k2]; }
557
605
  return sgn * vals[n] / norm;
558
606
  }
559
- `,fp=`
607
+ `,hm=`
560
608
  float _fractal_mandelbrot(vec2 c, int maxIter) {
561
609
  vec2 z = vec2(0.0, 0.0);
562
610
  for (int i = 0; i < maxIter; i++) {
@@ -575,7 +623,7 @@ float _fractal_julia(vec2 z, vec2 c, int maxIter) {
575
623
  }
576
624
  return 1.0;
577
625
  }
578
- `,pp=`
626
+ `,gm=`
579
627
  fn _fractal_mandelbrot(c: vec2f, maxIter: i32) -> f32 {
580
628
  var z = vec2f(0.0, 0.0);
581
629
  for (var i: i32 = 0; i < maxIter; i++) {
@@ -597,7 +645,7 @@ fn _fractal_julia(z_in: vec2f, c: vec2f, maxIter: i32) -> f32 {
597
645
  }
598
646
  return 1.0;
599
647
  }
600
- `,mp=`
648
+ `,bm=`
601
649
  float _gpu_gcd(float a, float b) {
602
650
  a = abs(a); b = abs(b);
603
651
  for (int i = 0; i < 32; i++) {
@@ -608,7 +656,7 @@ float _gpu_gcd(float a, float b) {
608
656
  }
609
657
  return a;
610
658
  }
611
- `,dp=`
659
+ `,ym=`
612
660
  fn _gpu_gcd(a_in: f32, b_in: f32) -> f32 {
613
661
  var a = abs(a_in); var b = abs(b_in);
614
662
  for (var i: i32 = 0; i < 32; i++) {
@@ -619,7 +667,7 @@ fn _gpu_gcd(a_in: f32, b_in: f32) -> f32 {
619
667
  }
620
668
  return a;
621
669
  }
622
- `,hp=`
670
+ `,xm=`
623
671
  // Deterministic pseudorandom in [0, 1) from a float seed.
624
672
  // Standard fract-sin hash; reproducible across runs for the same seed.
625
673
  // Note: this hash exhibits visible banding near seed \u2248 k\u03C0 for integer k.
@@ -628,7 +676,7 @@ fn _gpu_gcd(a_in: f32, b_in: f32) -> f32 {
628
676
  float _gpu_random(float seed) {
629
677
  return fract(sin(seed * 12.9898) * 43758.5453);
630
678
  }
631
- `,gp=`
679
+ `,vm=`
632
680
  // Deterministic pseudorandom in [0, 1) from a float seed.
633
681
  // Standard fract-sin hash; reproducible across runs for the same seed.
634
682
  // Note: this hash exhibits visible banding near seed \u2248 k\u03C0 for integer k.
@@ -637,7 +685,7 @@ float _gpu_random(float seed) {
637
685
  fn _gpu_random(seed: f32) -> f32 {
638
686
  return fract(sin(seed * 12.9898) * 43758.5453);
639
687
  }
640
- `,bp=`
688
+ `,Em=`
641
689
  float _gpu_median_2(float a, float b) {
642
690
  return (a + b) * 0.5;
643
691
  }
@@ -717,7 +765,7 @@ float _gpu_median_8(float a, float b, float c, float d, float e, float f, float
717
765
  t=min(v3,v4); v4=max(v3,v4); v3=t;
718
766
  return (v3 + v4) * 0.5;
719
767
  }
720
- `,yp=`
768
+ `,Nm=`
721
769
  fn _gpu_median_2(a: f32, b: f32) -> f32 {
722
770
  return (a + b) * 0.5;
723
771
  }
@@ -797,7 +845,7 @@ fn _gpu_median_8(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32, g: f32, h: f32)
797
845
  t=min(v3,v4); v4=max(v3,v4); v3=t;
798
846
  return (v3 + v4) * 0.5;
799
847
  }
800
- `,xp=`
848
+ `,Tm=`
801
849
  float _gpu_srgb_to_linear(float c) {
802
850
  if (c <= 0.04045) return c / 12.92;
803
851
  return pow((c + 0.055) / 1.055, 2.4);
@@ -968,7 +1016,7 @@ float _gpu_apca(vec3 lch_bg, vec3 lch_fg) {
968
1016
  float contrast = (bgC - fgC) * 1.14;
969
1017
  return contrast * 100.0;
970
1018
  }
971
- `,vp=`
1019
+ `,Im=`
972
1020
  fn _gpu_srgb_to_linear(c: f32) -> f32 {
973
1021
  if (c <= 0.04045) { return c / 12.92; }
974
1022
  return pow((c + 0.055) / 1.055, 2.4);
@@ -1148,7 +1196,7 @@ fn _gpu_apca(lch_bg: vec3f, lch_fg: vec3f) -> f32 {
1148
1196
  let contrast = (bgC - fgC) * 1.14;
1149
1197
  return contrast * 100.0;
1150
1198
  }
1151
- `,wr={_gpu_cmul:{deps:[],glsl:`vec2 _gpu_cmul(vec2 a, vec2 b) {
1199
+ `,Hr={_gpu_cmul:{deps:[],glsl:`vec2 _gpu_cmul(vec2 a, vec2 b) {
1152
1200
  return vec2(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
1153
1201
  }`,wgsl:`fn _gpu_cmul(a: vec2f, b: vec2f) -> vec2f {
1154
1202
  return vec2f(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
@@ -1256,12 +1304,12 @@ fn _gpu_apca(lch_bg: vec3f, lch_fg: vec3f) -> f32 {
1256
1304
  let a = _gpu_cln(vec2f(1.0 + z.x, z.y));
1257
1305
  let b = _gpu_cln(vec2f(1.0 - z.x, -z.y));
1258
1306
  return vec2f(0.5 * (a.x - b.x), 0.5 * (a.y - b.y));
1259
- }`}};function Ep(e,n){let t=new Set;for(let a of Object.keys(wr))e.includes(a)&&t.add(a);if(t.size===0)return"";let i=new Set;function r(a){if(i.has(a))return;let u=wr[a];if(u){for(let l of u.deps)r(l);i.add(a)}}for(let a of t)r(a);let s=n==="wgsl"?"wgsl":"glsl",o=[];for(let a of i)o.push(wr[a][s]);return`
1307
+ }`}};function _m(e,n){let t=new Set;for(let a of Object.keys(Hr))e.includes(a)&&t.add(a);if(t.size===0)return"";let i=new Set;function r(a){if(i.has(a))return;let u=Hr[a];if(u){for(let l of u.deps)r(l);i.add(a)}}for(let a of t)r(a);let s=n==="wgsl"?"wgsl":"glsl",o=[];for(let a of i)o.push(Hr[a][s]);return`
1260
1308
  `+o.join(`
1261
1309
 
1262
1310
  `)+`
1263
- `}var Np={Pi:"3.14159265359",ExponentialE:"2.71828182846",GoldenRatio:"1.61803398875",CatalanConstant:"0.91596559417",EulerGamma:"0.57721566490"};function vn(e){let n=e.toString();return!n.includes(".")&&!n.includes("e")&&!n.includes("E")?`${n}.0`:n}var sn=class{getOperators(){return Cu}getFunctions(){return{...Wf,...this.getLanguageSpecificFunctions()}}getConstants(){return Np}createTarget(n={}){let t=this.getFunctions(),i=this.getConstants(),r=this.languageId==="wgsl"?"vec2f":"vec2";return{language:this.languageId,operators:s=>Cu[s],functions:s=>t[s],var:s=>s==="ImaginaryUnit"?`${r}(0.0, 1.0)`:s in i?i[s]:s,string:s=>JSON.stringify(s),number:vn,complex:(s,o)=>`${r}(${vn(s)}, ${vn(o)})`,indent:0,ws:s=>s??"",preamble:"",declare:(s,o)=>{let a=o??(this.languageId==="wgsl"?"f32":"float");return this.languageId==="wgsl"?`var ${s}: ${a}`:`${a} ${s}`},block:s=>{if(s.length===0)return"";let o=s.length-1;return s[o]=`return ${s[o]}`,s.join(`;
1264
- `)+";"},...n}}compile(n,t={}){let{functions:i,vars:r}=t,s=this.getFunctions(),o=this.getConstants(),a=this.languageId==="wgsl"?"vec2f":"vec2",u=this.createTarget({functions:m=>{if(i&&m in i){let d=i[m];if(typeof d=="string")return d;if(typeof d=="function")return d.name||m}return s[m]},var:m=>r&&m in r?r[m]:m==="ImaginaryUnit"?`${a}(0.0, 1.0)`:m in o?o[m]:m}),l=g.compile(n,u),c={target:this.languageId,success:!0,code:l},f="";return f+=Ep(l,this.languageId),l.includes("_gpu_gamma")&&(f+=Xf),l.includes("_gpu_erf")&&(f+=Qf),l.includes("_gpu_heaviside")&&(f+=this.languageId==="wgsl"?ep:Kf),l.includes("_gpu_sinc")&&(f+=this.languageId==="wgsl"?tp:np),l.includes("_gpu_fresnel")&&(f+=this.languageId==="wgsl"?rp:ip),l.includes("_gpu_fresnelC")&&(f+=this.languageId==="wgsl"?op:sp),l.includes("_gpu_fresnelS")&&(f+=this.languageId==="wgsl"?up:ap),l.includes("_gpu_besselJ")&&(f+=this.languageId==="wgsl"?cp:lp),l.includes("_fractal_")&&(f+=this.languageId==="wgsl"?pp:fp),l.includes("_gpu_random")&&(f+=this.languageId==="wgsl"?gp:hp),l.includes("_gpu_gcd")&&(f+=this.languageId==="wgsl"?dp:mp),l.includes("_gpu_median_")&&(f+=this.languageId==="wgsl"?yp:bp),(l.includes("_gpu_srgb_to")||l.includes("_gpu_oklab")||l.includes("_gpu_oklch")||l.includes("_gpu_color_mix")||l.includes("_gpu_apca"))&&(f+=this.languageId==="wgsl"?vp:xp),f&&(c.preamble=f),c}compileToSource(n,t={}){let i=this.createTarget();return g.compile(n,i)}};function Pu(e,n){return e.length===2?`vec2(${e.map(t=>n(t)).join(", ")})`:e.length===3?`vec3(${e.map(t=>n(t)).join(", ")})`:e.length===4?`vec4(${e.map(t=>n(t)).join(", ")})`:`float[${e.length}](${e.map(t=>n(t)).join(", ")})`}var Tp={Inversesqrt:"inversesqrt",Mod:"mod",List:Pu,Matrix:(e,n)=>li(e,n,t=>`vec${t}`,t=>`mat${t}`,t=>`float[${t}]`),Tuple:Pu},ci=class extends sn{languageId="glsl";getLanguageSpecificFunctions(){return Tp}compileFunction(n,t,i,r){let s=this.createTarget(),o=g.compile(n,s),a=r.map(([u,l])=>`${l} ${u}`).join(", ");if(o.includes(`
1311
+ `}var Sm={Pi:"3.14159265359",ExponentialE:"2.71828182846",GoldenRatio:"1.61803398875",CatalanConstant:"0.91596559417",EulerGamma:"0.57721566490"};function kn(e){let n=e.toString();return!n.includes(".")&&!n.includes("e")&&!n.includes("E")?`${n}.0`:n}var cn=class{getOperators(){return vl}getFunctions(){return{...Qp,...this.getLanguageSpecificFunctions()}}getConstants(){return Sm}createTarget(n={}){let t=this.getFunctions(),i=this.getConstants(),r=this.languageId==="wgsl"?"vec2f":"vec2";return{language:this.languageId,operators:s=>vl[s],functions:s=>t[s],var:s=>s==="ImaginaryUnit"?`${r}(0.0, 1.0)`:s in i?i[s]:s,string:s=>JSON.stringify(s),number:kn,complex:(s,o)=>`${r}(${kn(s)}, ${kn(o)})`,indent:0,ws:s=>s??"",preamble:"",declare:(s,o)=>{let a=o??(this.languageId==="wgsl"?"f32":"float");return this.languageId==="wgsl"?`var ${s}: ${a}`:`${a} ${s}`},block:s=>{if(s.length===0)return"";let o=s.length-1;return s[o]=`return ${s[o]}`,s.join(`;
1312
+ `)+";"},...n}}compile(n,t={}){let{functions:i,vars:r}=t,s=this.getFunctions(),o=this.getConstants(),a=this.languageId==="wgsl"?"vec2f":"vec2",u=this.createTarget({functions:d=>{if(i&&d in i){let m=i[d];if(typeof m=="string")return m;if(typeof m=="function")return m.name||d}return s[d]},var:d=>r&&d in r?r[d]:d==="ImaginaryUnit"?`${a}(0.0, 1.0)`:d in o?o[d]:d}),l=b.compile(n,u),c={target:this.languageId,success:!0,code:l},f="";return f+=_m(l,this.languageId),l.includes("_gpu_gamma")&&(f+=this.languageId==="wgsl"?em:Kp),l.includes("_gpu_erf")&&(f+=this.languageId==="wgsl"?tm:nm),l.includes("_gpu_heaviside")&&(f+=this.languageId==="wgsl"?rm:im),l.includes("_gpu_sinc")&&(f+=this.languageId==="wgsl"?om:sm),l.includes("_gpu_fresnel")&&(f+=this.languageId==="wgsl"?um:am),l.includes("_gpu_fresnelC")&&(f+=this.languageId==="wgsl"?cm:lm),l.includes("_gpu_fresnelS")&&(f+=this.languageId==="wgsl"?pm:fm),l.includes("_gpu_besselJ")&&(f+=this.languageId==="wgsl"?dm:mm),l.includes("_fractal_")&&(f+=this.languageId==="wgsl"?gm:hm),l.includes("_gpu_random")&&(f+=this.languageId==="wgsl"?vm:xm),l.includes("_gpu_gcd")&&(f+=this.languageId==="wgsl"?ym:bm),l.includes("_gpu_median_")&&(f+=this.languageId==="wgsl"?Nm:Em),(l.includes("_gpu_srgb_to")||l.includes("_gpu_oklab")||l.includes("_gpu_oklch")||l.includes("_gpu_color_mix")||l.includes("_gpu_apca"))&&(f+=this.languageId==="wgsl"?Im:Tm),f&&(c.preamble=f),c}compileToSource(n,t={}){let i=this.createTarget();return b.compile(n,i)}};function Tl(e,n){return e.length===2?`vec2(${e.map(t=>n(t)).join(", ")})`:e.length===3?`vec3(${e.map(t=>n(t)).join(", ")})`:e.length===4?`vec4(${e.map(t=>n(t)).join(", ")})`:`float[${e.length}](${e.map(t=>n(t)).join(", ")})`}var km={Inversesqrt:"inversesqrt",Mod:"mod",List:Tl,Matrix:(e,n)=>vi(e,n,t=>`vec${t}`,t=>`mat${t}`,t=>`float[${t}]`),Tuple:Tl},Ei=class extends cn{languageId="glsl";getLanguageSpecificFunctions(){return km}compileFunction(n,t,i,r){let s=this.createTarget(),o=b.compile(n,s),a=r.map(([u,l])=>`${l} ${u}`).join(", ");if(o.includes(`
1265
1313
  `)){let u=o.split(`
1266
1314
  `).map(l=>` ${l}`).join(`
1267
1315
  `);return`${i} ${t}(${a}) {
@@ -1279,37 +1327,37 @@ ${u}
1279
1327
  `);for(let f of o)u+=`uniform ${f.type} ${f.name};
1280
1328
  `;o.length>0&&(u+=`
1281
1329
  `),u+=`void main() {
1282
- `;for(let f of a){let m=this.compileToSource(f.expression);u+=` ${f.variable} = ${m};
1330
+ `;for(let f of a){let d=this.compileToSource(f.expression);u+=` ${f.variable} = ${d};
1283
1331
  `}return u+=`}
1284
- `,u}};function Fu(e,n){return e.length===2?`vec2f(${e.map(t=>n(t)).join(", ")})`:e.length===3?`vec3f(${e.map(t=>n(t)).join(", ")})`:e.length===4?`vec4f(${e.map(t=>n(t)).join(", ")})`:`array<f32, ${e.length}>(${e.map(t=>n(t)).join(", ")})`}var Ip={Inversesqrt:"inverseSqrt",Mod:([e,n],t)=>{if(e===null||n===null)throw new Error("Mod: missing argument");return`(${t(e)} % ${t(n)})`},Hypot:([e,n],t)=>{if(e===null||n===null)throw new Error("Hypot: need two arguments");return`length(vec2f(${t(e)}, ${t(n)}))`},List:Fu,Matrix:(e,n)=>li(e,n,t=>`vec${t}f`,t=>`mat${t}x${t}f`,t=>`array<f32, ${t}>`),Tuple:Fu},_p={float:"f32",int:"i32",uint:"u32",bool:"bool",vec2:"vec2f",vec3:"vec3f",vec4:"vec4f",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f"};function Jn(e){return _p[e]??e}var fi=class extends sn{languageId="wgsl";getLanguageSpecificFunctions(){return Ip}compileFunction(n,t,i,r){let s=this.createTarget(),o=g.compile(n,s),a=r.map(([u,l])=>`${u}: ${Jn(l)}`).join(", ");if(o.includes(`
1332
+ `,u}};function Il(e,n){return e.length===2?`vec2f(${e.map(t=>n(t)).join(", ")})`:e.length===3?`vec3f(${e.map(t=>n(t)).join(", ")})`:e.length===4?`vec4f(${e.map(t=>n(t)).join(", ")})`:`array<f32, ${e.length}>(${e.map(t=>n(t)).join(", ")})`}var Mm={Inversesqrt:"inverseSqrt",Mod:([e,n],t)=>{if(e===null||n===null)throw new Error("Mod: missing argument");return`(${t(e)} % ${t(n)})`},Hypot:([e,n],t)=>{if(e===null||n===null)throw new Error("Hypot: need two arguments");return`length(vec2f(${t(e)}, ${t(n)}))`},List:Il,Matrix:(e,n)=>vi(e,n,t=>`vec${t}f`,t=>`mat${t}x${t}f`,t=>`array<f32, ${t}>`),Tuple:Il},wm={float:"f32",int:"i32",uint:"u32",bool:"bool",vec2:"vec2f",vec3:"vec3f",vec4:"vec4f",mat2:"mat2x2f",mat3:"mat3x3f",mat4:"mat4x4f"};function jn(e){return wm[e]??e}var Ni=class extends cn{languageId="wgsl";getLanguageSpecificFunctions(){return Mm}compileFunction(n,t,i,r){let s=this.createTarget(),o=b.compile(n,s),a=r.map(([u,l])=>`${u}: ${jn(l)}`).join(", ");if(o.includes(`
1285
1333
  `)){let u=o.split(`
1286
1334
  `).map(l=>` ${l}`).join(`
1287
- `);return`fn ${t}(${a}) -> ${Jn(i)} {
1335
+ `);return`fn ${t}(${a}) -> ${jn(i)} {
1288
1336
  ${u}
1289
- }`}return`fn ${t}(${a}) -> ${Jn(i)} {
1337
+ }`}return`fn ${t}(${a}) -> ${jn(i)} {
1290
1338
  return ${o};
1291
1339
  }`}compileShader(n){let{type:t,inputs:i=[],outputs:r=[],uniforms:s=[],workgroupSize:o,body:a}=n,u="";if(i.length>0){u+=`struct VertexInput {
1292
- `;for(let T of i){let M=T.builtin?`@builtin(${T.builtin})`:`@location(${T.location??0})`;u+=` ${M} ${T.name}: ${Jn(T.type)},
1340
+ `;for(let N of i){let M=N.builtin?`@builtin(${N.builtin})`:`@location(${N.location??0})`;u+=` ${M} ${N.name}: ${jn(N.type)},
1293
1341
  `}u+=`};
1294
1342
 
1295
1343
  `}if(r.length>0){u+=`struct ${t==="vertex"?"VertexOutput":"FragmentOutput"} {
1296
- `;for(let M of r){let C=M.builtin?`@builtin(${M.builtin})`:`@location(${M.location??0})`;u+=` ${C} ${M.name}: ${Jn(M.type)},
1344
+ `;for(let M of r){let $=M.builtin?`@builtin(${M.builtin})`:`@location(${M.location??0})`;u+=` ${$} ${M.name}: ${jn(M.type)},
1297
1345
  `}u+=`};
1298
1346
 
1299
- `}for(let T of s){let M=T.group??0,C=T.binding??0;u+=`@group(${M}) @binding(${C}) var<uniform> ${T.name}: ${Jn(T.type)};
1347
+ `}for(let N of s){let M=N.group??0,$=N.binding??0;u+=`@group(${M}) @binding(${$}) var<uniform> ${N.name}: ${jn(N.type)};
1300
1348
  `}s.length>0&&(u+=`
1301
1349
  `);let l=`@${t}`,c=t==="compute"&&o?`@workgroup_size(${o.join(", ")})
1302
- `:"",f=i.length>0,m=r.length>0,d=t==="vertex"?"VertexOutput":"FragmentOutput",b=f?"input: VertexInput":"",v=m?` -> ${d}`:"";u+=`${l}
1303
- ${c}fn main(${b})${v} {
1304
- `,m&&(u+=` var output: ${d};
1305
- `);for(let T of a){let M=this.compileToSource(T.expression);u+=` ${T.variable} = ${M};
1306
- `}return m&&(u+=` return output;
1350
+ `:"",f=i.length>0,d=r.length>0,m=t==="vertex"?"VertexOutput":"FragmentOutput",g=f?"input: VertexInput":"",v=d?` -> ${m}`:"";u+=`${l}
1351
+ ${c}fn main(${g})${v} {
1352
+ `,d&&(u+=` var output: ${m};
1353
+ `);for(let N of a){let M=this.compileToSource(N.expression);u+=` ${N.variable} = ${M};
1354
+ `}return d&&(u+=` return output;
1307
1355
  `),u+=`}
1308
- `,u}};var Lu={Add:["+",11],Negate:["-",14],Subtract:["-",11],Multiply:["*",12],Divide:["/",13],Power:["**",15],Equal:["==",8],NotEqual:["!=",8],LessEqual:["<=",9],GreaterEqual:[">=",9],Less:["<",9],Greater:[">",9],And:["and",4],Or:["or",3],Not:["not",14]},Ou={Add:(e,n)=>e.length===0?"0":e.length===1?n(e[0]):e.map(t=>n(t)).join(" + "),Multiply:(e,n)=>e.length===0?"1":e.length===1?n(e[0]):e.map(t=>n(t)).join(" * "),Divide:(e,n)=>{if(e.length===0)return"1";if(e.length===1)return n(e[0]);if(e.length===2)return`${n(e[0])} / ${n(e[1])}`;let t=n(e[0]);for(let i=1;i<e.length;i++)t=`${t} / ${n(e[i])}`;return t},Sin:(e,n)=>g.isComplexValued(e[0])?`cmath.sin(${n(e[0])})`:`np.sin(${n(e[0])})`,Cos:(e,n)=>g.isComplexValued(e[0])?`cmath.cos(${n(e[0])})`:`np.cos(${n(e[0])})`,Tan:(e,n)=>g.isComplexValued(e[0])?`cmath.tan(${n(e[0])})`:`np.tan(${n(e[0])})`,Arcsin:(e,n)=>g.isComplexValued(e[0])?`cmath.asin(${n(e[0])})`:`np.arcsin(${n(e[0])})`,Arccos:(e,n)=>g.isComplexValued(e[0])?`cmath.acos(${n(e[0])})`:`np.arccos(${n(e[0])})`,Arctan:(e,n)=>g.isComplexValued(e[0])?`cmath.atan(${n(e[0])})`:`np.arctan(${n(e[0])})`,Arctan2:"np.arctan2",Sinh:(e,n)=>g.isComplexValued(e[0])?`cmath.sinh(${n(e[0])})`:`np.sinh(${n(e[0])})`,Cosh:(e,n)=>g.isComplexValued(e[0])?`cmath.cosh(${n(e[0])})`:`np.cosh(${n(e[0])})`,Tanh:(e,n)=>g.isComplexValued(e[0])?`cmath.tanh(${n(e[0])})`:`np.tanh(${n(e[0])})`,Arsinh:"np.arcsinh",Arcosh:"np.arccosh",Artanh:"np.arctanh",Cot:([e],n)=>{if(e===null)throw new Error("Cot: no argument");return`(np.cos(${n(e)}) / np.sin(${n(e)}))`},Csc:([e],n)=>{if(e===null)throw new Error("Csc: no argument");return`(1 / np.sin(${n(e)}))`},Sec:([e],n)=>{if(e===null)throw new Error("Sec: no argument");return`(1 / np.cos(${n(e)}))`},Arccot:([e],n)=>{if(e===null)throw new Error("Arccot: no argument");return`np.arctan(1 / (${n(e)}))`},Arccsc:([e],n)=>{if(e===null)throw new Error("Arccsc: no argument");return`np.arcsin(1 / (${n(e)}))`},Arcsec:([e],n)=>{if(e===null)throw new Error("Arcsec: no argument");return`np.arccos(1 / (${n(e)}))`},Coth:([e],n)=>{if(e===null)throw new Error("Coth: no argument");return`(np.cosh(${n(e)}) / np.sinh(${n(e)}))`},Csch:([e],n)=>{if(e===null)throw new Error("Csch: no argument");return`(1 / np.sinh(${n(e)}))`},Sech:([e],n)=>{if(e===null)throw new Error("Sech: no argument");return`(1 / np.cosh(${n(e)}))`},Arcoth:([e],n)=>{if(e===null)throw new Error("Arcoth: no argument");return`np.arctanh(1 / (${n(e)}))`},Arcsch:([e],n)=>{if(e===null)throw new Error("Arcsch: no argument");return`np.arcsinh(1 / (${n(e)}))`},Arsech:([e],n)=>{if(e===null)throw new Error("Arsech: no argument");return`np.arccosh(1 / (${n(e)}))`},Lb:"np.log2",Square:([e],n)=>{if(e===null)throw new Error("Square: no argument");return`np.square(${n(e)})`},Fract:([e],n)=>{if(e===null)throw new Error("Fract: no argument");return`np.modf(${n(e)})[0]`},Exp:(e,n)=>g.isComplexValued(e[0])?`cmath.exp(${n(e[0])})`:`np.exp(${n(e[0])})`,Ln:(e,n)=>g.isComplexValued(e[0])?`cmath.log(${n(e[0])})`:`np.log(${n(e[0])})`,Log:(e,n)=>e.length===1?`np.log10(${n(e[0])})`:e.length===2?`(np.log(${n(e[0])}) / np.log(${n(e[1])}))`:"np.log10",Log10:"np.log10",Log2:"np.log2",Exp2:"np.exp2",Power:(e,n)=>e.length!==2?"np.power":g.isComplexValued(e[0])||g.isComplexValued(e[1])?`(${n(e[0])} ** ${n(e[1])})`:`np.power(${n(e[0])}, ${n(e[1])})`,Sqrt:(e,n)=>g.isComplexValued(e[0])?`cmath.sqrt(${n(e[0])})`:`np.sqrt(${n(e[0])})`,Root:(e,n)=>e.length!==2?"np.power":`np.power(${n(e[0])}, 1.0 / ${n(e[1])})`,Abs:(e,n)=>g.isComplexValued(e[0])?`abs(${n(e[0])})`:`np.abs(${n(e[0])})`,Sign:"np.sign",Floor:"np.floor",Ceil:"np.ceil",Round:"np.round",Truncate:"np.trunc",Min:"np.minimum",Max:"np.maximum",Mod:"np.mod",Remainder:"np.remainder",Real:"np.real",Imaginary:"np.imag",Argument:"np.angle",Conjugate:"np.conj",Sum:"np.sum",Product:"np.prod",Mean:"np.mean",Median:"np.median",Variance:"np.var",StandardDeviation:"np.std",Dot:"np.dot",Cross:"np.cross",Norm:"np.linalg.norm",Determinant:"np.linalg.det",Inverse:"np.linalg.inv",Transpose:"np.transpose",MatrixMultiply:"np.matmul",Equal:"np.equal",NotEqual:"np.not_equal",Less:"np.less",LessEqual:"np.less_equal",Greater:"np.greater",GreaterEqual:"np.greater_equal",And:"np.logical_and",Or:"np.logical_or",Not:"np.logical_not",Erf:"scipy.special.erf",Erfc:"scipy.special.erfc",Gamma:"scipy.special.gamma",GammaLn:"scipy.special.loggamma",Factorial:"scipy.special.factorial",List:(e,n)=>`[${e.map(t=>n(t)).join(", ")}]`,Matrix:(e,n)=>`np.array(${n(e[0])})`,Tuple:(e,n)=>`(${e.map(t=>n(t)).join(", ")})`,Sequence:(e,n)=>`np.array([${e.map(t=>n(t)).join(", ")}])`,Range:(e,n)=>e.length===1?`np.arange(${n(e[0])})`:e.length===2?`np.arange(${n(e[0])}, ${n(e[1])})`:e.length===3?`np.arange(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`:"np.arange"},pi=class{includeImports;useScipy;constructor(n={}){this.includeImports=n.includeImports??!1,this.useScipy=n.useScipy??!1}getOperators(){return Lu}getFunctions(){return Ou}createTarget(n={}){return{language:"python",operators:t=>Lu[t],functions:t=>Ou[t],var:t=>{let i={Pi:"np.pi",ExponentialE:"np.e",ImaginaryUnit:"1j",Infinity:"np.inf",NaN:"np.nan",GoldenRatio:"((1 + np.sqrt(5)) / 2)",CatalanConstant:"0.915965594177219015054603514932384110774",EulerGamma:"0.5772156649015328606065120900824024310421"};return t in i?i[t]:t},complex:(t,i)=>`complex(${t}, ${i})`,string:t=>JSON.stringify(t),number:t=>isFinite(t)?t.toString():t===1/0?"np.inf":t===-1/0?"-np.inf":"np.nan",indent:0,ws:t=>t??"",preamble:"",...n}}compile(n,t={}){return{target:"python",success:!0,code:this.compileToSource(n,t)}}compileToSource(n,t={}){let i=this.createTarget(),r=g.compile(n,i);if(this.includeImports){let s=`import numpy as np
1356
+ `,u}};var _l={Add:["+",11],Negate:["-",14],Subtract:["-",11],Multiply:["*",12],Divide:["/",13],Power:["**",15],Equal:["==",8],NotEqual:["!=",8],LessEqual:["<=",9],GreaterEqual:[">=",9],Less:["<",9],Greater:[">",9],And:["and",4],Or:["or",3],Not:["not",14]},Sl={Add:(e,n)=>e.length===0?"0":e.length===1?n(e[0]):e.map(t=>n(t)).join(" + "),Multiply:(e,n)=>e.length===0?"1":e.length===1?n(e[0]):e.map(t=>n(t)).join(" * "),Divide:(e,n)=>{if(e.length===0)return"1";if(e.length===1)return n(e[0]);if(e.length===2)return`${n(e[0])} / ${n(e[1])}`;let t=n(e[0]);for(let i=1;i<e.length;i++)t=`${t} / ${n(e[i])}`;return t},Sin:(e,n)=>b.isComplexValued(e[0])?`cmath.sin(${n(e[0])})`:`np.sin(${n(e[0])})`,Cos:(e,n)=>b.isComplexValued(e[0])?`cmath.cos(${n(e[0])})`:`np.cos(${n(e[0])})`,Tan:(e,n)=>b.isComplexValued(e[0])?`cmath.tan(${n(e[0])})`:`np.tan(${n(e[0])})`,Arcsin:(e,n)=>b.isComplexValued(e[0])?`cmath.asin(${n(e[0])})`:`np.arcsin(${n(e[0])})`,Arccos:(e,n)=>b.isComplexValued(e[0])?`cmath.acos(${n(e[0])})`:`np.arccos(${n(e[0])})`,Arctan:(e,n)=>b.isComplexValued(e[0])?`cmath.atan(${n(e[0])})`:`np.arctan(${n(e[0])})`,Arctan2:"np.arctan2",Sinh:(e,n)=>b.isComplexValued(e[0])?`cmath.sinh(${n(e[0])})`:`np.sinh(${n(e[0])})`,Cosh:(e,n)=>b.isComplexValued(e[0])?`cmath.cosh(${n(e[0])})`:`np.cosh(${n(e[0])})`,Tanh:(e,n)=>b.isComplexValued(e[0])?`cmath.tanh(${n(e[0])})`:`np.tanh(${n(e[0])})`,Arsinh:"np.arcsinh",Arcosh:"np.arccosh",Artanh:"np.arctanh",Cot:([e],n)=>{if(e===null)throw new Error("Cot: no argument");return`(np.cos(${n(e)}) / np.sin(${n(e)}))`},Csc:([e],n)=>{if(e===null)throw new Error("Csc: no argument");return`(1 / np.sin(${n(e)}))`},Sec:([e],n)=>{if(e===null)throw new Error("Sec: no argument");return`(1 / np.cos(${n(e)}))`},Arccot:([e],n)=>{if(e===null)throw new Error("Arccot: no argument");return`np.arctan(1 / (${n(e)}))`},Arccsc:([e],n)=>{if(e===null)throw new Error("Arccsc: no argument");return`np.arcsin(1 / (${n(e)}))`},Arcsec:([e],n)=>{if(e===null)throw new Error("Arcsec: no argument");return`np.arccos(1 / (${n(e)}))`},Coth:([e],n)=>{if(e===null)throw new Error("Coth: no argument");return`(np.cosh(${n(e)}) / np.sinh(${n(e)}))`},Csch:([e],n)=>{if(e===null)throw new Error("Csch: no argument");return`(1 / np.sinh(${n(e)}))`},Sech:([e],n)=>{if(e===null)throw new Error("Sech: no argument");return`(1 / np.cosh(${n(e)}))`},Arcoth:([e],n)=>{if(e===null)throw new Error("Arcoth: no argument");return`np.arctanh(1 / (${n(e)}))`},Arcsch:([e],n)=>{if(e===null)throw new Error("Arcsch: no argument");return`np.arcsinh(1 / (${n(e)}))`},Arsech:([e],n)=>{if(e===null)throw new Error("Arsech: no argument");return`np.arccosh(1 / (${n(e)}))`},Lb:"np.log2",Square:([e],n)=>{if(e===null)throw new Error("Square: no argument");return`np.square(${n(e)})`},Fract:([e],n)=>{if(e===null)throw new Error("Fract: no argument");return`np.modf(${n(e)})[0]`},Exp:(e,n)=>b.isComplexValued(e[0])?`cmath.exp(${n(e[0])})`:`np.exp(${n(e[0])})`,Ln:(e,n)=>b.isComplexValued(e[0])?`cmath.log(${n(e[0])})`:`np.log(${n(e[0])})`,Log:(e,n)=>e.length===1?`np.log10(${n(e[0])})`:e.length===2?`(np.log(${n(e[0])}) / np.log(${n(e[1])}))`:"np.log10",Log10:"np.log10",Log2:"np.log2",Exp2:"np.exp2",Power:(e,n)=>e.length!==2?"np.power":b.isComplexValued(e[0])||b.isComplexValued(e[1])?`(${n(e[0])} ** ${n(e[1])})`:`np.power(${n(e[0])}, ${n(e[1])})`,Sqrt:(e,n)=>b.isComplexValued(e[0])?`cmath.sqrt(${n(e[0])})`:`np.sqrt(${n(e[0])})`,Root:(e,n)=>e.length!==2?"np.power":`np.power(${n(e[0])}, 1.0 / ${n(e[1])})`,Abs:(e,n)=>b.isComplexValued(e[0])?`abs(${n(e[0])})`:`np.abs(${n(e[0])})`,Sign:"np.sign",Floor:"np.floor",Ceil:"np.ceil",Round:"np.round",Truncate:"np.trunc",Min:"np.minimum",Max:"np.maximum",Mod:"np.mod",Remainder:"np.remainder",Real:"np.real",Imaginary:"np.imag",Argument:"np.angle",Conjugate:"np.conj",Sum:"np.sum",Product:"np.prod",Mean:"np.mean",Median:"np.median",Variance:"np.var",StandardDeviation:"np.std",Dot:"np.dot",Cross:"np.cross",Norm:"np.linalg.norm",Determinant:"np.linalg.det",Inverse:"np.linalg.inv",Transpose:"np.transpose",MatrixMultiply:"np.matmul",Equal:"np.equal",NotEqual:"np.not_equal",Less:"np.less",LessEqual:"np.less_equal",Greater:"np.greater",GreaterEqual:"np.greater_equal",And:"np.logical_and",Or:"np.logical_or",Not:"np.logical_not",Erf:"scipy.special.erf",Erfc:"scipy.special.erfc",Gamma:"scipy.special.gamma",GammaLn:"scipy.special.loggamma",Factorial:"scipy.special.factorial",List:(e,n)=>`[${e.map(t=>n(t)).join(", ")}]`,Matrix:(e,n)=>`np.array(${n(e[0])})`,Tuple:(e,n)=>`(${e.map(t=>n(t)).join(", ")})`,Sequence:(e,n)=>`np.array([${e.map(t=>n(t)).join(", ")}])`,Range:(e,n)=>e.length===1?`np.arange(${n(e[0])})`:e.length===2?`np.arange(${n(e[0])}, ${n(e[1])})`:e.length===3?`np.arange(${n(e[0])}, ${n(e[1])}, ${n(e[2])})`:"np.arange"},Ti=class{includeImports;useScipy;constructor(n={}){this.includeImports=n.includeImports??!1,this.useScipy=n.useScipy??!1}getOperators(){return _l}getFunctions(){return Sl}createTarget(n={}){return{language:"python",operators:t=>_l[t],functions:t=>Sl[t],var:t=>{let i={Pi:"np.pi",ExponentialE:"np.e",ImaginaryUnit:"1j",Infinity:"np.inf",NaN:"np.nan",GoldenRatio:"((1 + np.sqrt(5)) / 2)",CatalanConstant:"0.915965594177219015054603514932384110774",EulerGamma:"0.5772156649015328606065120900824024310421"};return t in i?i[t]:t},complex:(t,i)=>`complex(${t}, ${i})`,string:t=>JSON.stringify(t),number:t=>isFinite(t)?t.toString():t===1/0?"np.inf":t===-1/0?"-np.inf":"np.nan",indent:0,ws:t=>t??"",preamble:"",...n}}compile(n,t={}){return{target:"python",success:!0,code:this.compileToSource(n,t)}}compileToSource(n,t={}){let i=this.createTarget(),r=b.compile(n,i);if(this.includeImports){let s=`import numpy as np
1309
1357
  `;return s+=`import cmath
1310
1358
  `,this.useScipy&&(s+=`import scipy.special
1311
1359
  `),`${s}
1312
- ${r}`}return r}compileFunction(n,t,i,r){let s=this.createTarget(),o=g.compile(n,s),a=i.join(", "),u="";return this.includeImports&&(u+=`import numpy as np
1360
+ ${r}`}return r}compileFunction(n,t,i,r){let s=this.createTarget(),o=b.compile(n,s),a=i.join(", "),u="";return this.includeImports&&(u+=`import numpy as np
1313
1361
  `,u+=`import cmath
1314
1362
  `,this.useScipy&&(u+=`import scipy.special
1315
1363
  `),u+=`
@@ -1319,16 +1367,16 @@ ${r}`}return r}compileFunction(n,t,i,r){let s=this.createTarget(),o=g.compile(n,
1319
1367
  `,u}compileVectorized(n,t,i,r){let o=this.compileFunction(n,`_${t}_scalar`,i,r)+`
1320
1368
  `;return o+=`# Vectorized version
1321
1369
  `,o+=`${t} = np.vectorize(_${t}_scalar)
1322
- `,o}compileLambda(n,t){let i=this.createTarget(),r=g.compile(n,i);return`lambda ${t.join(", ")}: ${r}`}};function E(e){return{kind:"interval",value:e}}function Ar(e){return{lo:e,hi:e}}function ce(e,n,t){let i=Math.ceil((e.lo-n)/t),r=n+i*t,s=1e-15;return r>=e.lo-s&&r<=e.hi+s}function qn(e,n){if(e.kind==="empty")return n;if(n.kind==="empty")return e;if(e.kind==="singular"||n.kind==="singular")return{kind:"singular"};if(e.kind==="entire"||n.kind==="entire")return{kind:"entire"};let t=e.value,i=n.value,r=e.kind==="partial"?e.domainClipped:null,s=n.kind==="partial"?n.domainClipped:null,o={lo:Math.min(t.lo,i.lo),hi:Math.max(t.hi,i.hi)};if(r||s){let a=mi(r,s);return{kind:"partial",value:o,domainClipped:a}}return{kind:"interval",value:o}}function mi(e,n){return e==="both"||n==="both"?"both":e===null?n:n===null||e===n?e:"both"}function $r(e){return e.lo===e.hi}function me(e){return e.lo<=0&&e.hi>=0}function Cr(e){return e.lo>0}function mt(e){return e.hi<0}function Rr(e){return e.lo>=0}function Dr(e){return e.hi<=0}function Pr(e){return e.hi-e.lo}function Fr(e){return(e.lo+e.hi)/2}function Lr(e){if(e.kind==="interval"||e.kind==="partial")return e.value}function Or(e){return"kind"in e?e.kind==="interval"||e.kind==="partial"?e.value:void 0:e}function _(...e){let n=[];for(let t of e)if("kind"in t){if(t.kind==="empty")return{kind:"empty"};if(t.kind==="entire")return{kind:"entire"};if(t.kind==="singular")return t;n.push(t.value)}else n.push(t);return n}function Br(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:i.lo+r.lo,hi:i.hi+r.hi})}function dt(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:i.lo-r.hi,hi:i.hi-r.lo})}function Vr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:-t.hi,hi:-t.lo})}function Jr(e,n){let t=[e.lo*n.lo,e.lo*n.hi,e.hi*n.lo,e.hi*n.hi];return{lo:Math.min(...t),hi:Math.max(...t)}}function ht(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E(Jr(i,r))}function de(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return kp(i,r)}function kp(e,n){return n.lo>0||n.hi<0?E(Jr(e,{lo:1/n.hi,hi:1/n.lo})):n.lo<0&&n.hi>0?{kind:"singular"}:n.lo===0&&n.hi>0?e.lo>=0?{kind:"partial",value:{lo:e.lo/n.hi,hi:1/0},domainClipped:"hi"}:e.hi<=0?{kind:"partial",value:{lo:-1/0,hi:e.hi/n.hi},domainClipped:"lo"}:{kind:"entire"}:n.hi===0&&n.lo<0?e.lo>=0?{kind:"partial",value:{lo:-1/0,hi:e.lo/n.lo},domainClipped:"lo"}:e.hi<=0?{kind:"partial",value:{lo:e.hi/n.lo,hi:1/0},domainClipped:"hi"}:{kind:"entire"}:{kind:"empty"}}function qr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return Sp(t)}function Sp(e){return e.hi<0?{kind:"empty"}:e.lo>=0?E({lo:Math.sqrt(e.lo),hi:Math.sqrt(e.hi)}):{kind:"partial",value:{lo:0,hi:Math.sqrt(e.hi)},domainClipped:"lo"}}function zr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?E({lo:t.lo*t.lo,hi:t.hi*t.hi}):t.hi<=0?E({lo:t.hi*t.hi,hi:t.lo*t.lo}):E({lo:0,hi:Math.max(t.lo*t.lo,t.hi*t.hi)})}function Bu(e,n){return n===0?{lo:1,hi:1}:n===1?e:n%2===0?e.lo>=0?{lo:Math.pow(e.lo,n),hi:Math.pow(e.hi,n)}:e.hi<=0?{lo:Math.pow(e.hi,n),hi:Math.pow(e.lo,n)}:{lo:0,hi:Math.max(Math.pow(e.lo,n),Math.pow(e.hi,n))}:{lo:Math.pow(e.lo,n),hi:Math.pow(e.hi,n)}}function di(e,n){let t=_(e);if(!Array.isArray(t))return t;let[i]=t;if(Number.isInteger(n)){if(n>=0)return E(Bu(i,n));{if(me(i))return{kind:"singular"};let r=Bu(i,-n);return E({lo:1/r.hi,hi:1/r.lo})}}else return mt(i)?{kind:"empty"}:i.lo<0?{kind:"partial",value:n>0?{lo:0,hi:Math.pow(i.hi,n)}:{lo:Math.pow(i.hi,n),hi:1/0},domainClipped:"lo"}:n>0?E({lo:Math.pow(i.lo,n),hi:Math.pow(i.hi,n)}):i.lo===0?{kind:"partial",value:{lo:Math.pow(i.hi,n),hi:1/0},domainClipped:"hi"}:E({lo:Math.pow(i.hi,n),hi:Math.pow(i.lo,n)})}function Gr(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(r.lo===r.hi&&Number.isInteger(r.lo))return di(i,r.lo);if(i.hi<=0)return i.lo===-1&&i.hi===-1&&Math.floor(r.hi)>Math.floor(r.lo)?E({lo:-1,hi:1}):{kind:"empty"};if(i.lo<=0){let o={lo:Math.max(i.lo,Number.EPSILON),hi:i.hi},a=[Math.pow(o.lo,r.lo),Math.pow(o.lo,r.hi),Math.pow(o.hi,r.lo),Math.pow(o.hi,r.hi)];return{kind:"partial",value:{lo:Math.min(...a),hi:Math.max(...a)},domainClipped:"lo"}}let s=[Math.pow(i.lo,r.lo),Math.pow(i.lo,r.hi),Math.pow(i.hi,r.lo),Math.pow(i.hi,r.hi)];return E({lo:Math.min(...s),hi:Math.max(...s)})}function jr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.exp(t.lo),hi:Math.exp(t.hi)})}function Ur(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?E({lo:Math.log(t.lo),hi:Math.log(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log(t.hi)},domainClipped:"lo"}}function Hr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?E({lo:Math.log10(t.lo),hi:Math.log10(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log10(t.hi)},domainClipped:"lo"}}function Zr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?E({lo:Math.log2(t.lo),hi:Math.log2(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log2(t.hi)},domainClipped:"lo"}}function Yr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?E(t):t.hi<=0?E({lo:-t.hi,hi:-t.lo}):E({lo:0,hi:Math.max(-t.lo,t.hi)})}function Wr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?E({lo:i,hi:r}):{kind:"singular",at:i+1,continuity:"right"}}function Xr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.ceil(t.lo),r=Math.ceil(t.hi);return i===r?E({lo:i,hi:r}):{kind:"singular",at:i,continuity:"left"}}function hi(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.round(t.lo),r=Math.round(t.hi);return i===r?E({lo:i,hi:r}):{kind:"singular",at:i+.5,continuity:"right"}}function Qr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?E({lo:t.lo-i,hi:t.hi-i}):{kind:"singular",at:i+1,continuity:"right"}}function Kr(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.trunc(t.lo),r=Math.trunc(t.hi);if(i===r)return E({lo:i,hi:r});if(t.lo>=0)return{kind:"singular",at:i+1,continuity:"right"};let s=Math.ceil(t.lo);return s!==0?{kind:"singular",at:s,continuity:"left"}:{kind:"singular",at:1,continuity:"right"}}function es(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:Math.min(i.lo,r.lo),hi:Math.min(i.hi,r.hi)})}function ns(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:Math.max(i.lo,r.lo),hi:Math.max(i.hi,r.hi)})}function ts(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(me(r))return{kind:"singular"};let s=Math.abs(r.lo===r.hi?r.lo:Math.max(Math.abs(r.lo),Math.abs(r.hi))),o=Math.floor(i.lo/s),a=Math.floor(i.hi/s);if(o!==a)return{kind:"singular",at:(o+1)*s,continuity:"right"};let u=i.lo-s*o,l=i.hi-s*o;return E({lo:Math.min(u,l),hi:Math.max(u,l)})}function is(e,n){return dt(e,ht(n,hi(de(e,n))))}function rs(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?E({lo:1,hi:1}):t.hi<0?E({lo:0,hi:0}):t.lo===0&&t.hi===0?E({lo:.5,hi:.5}):{kind:"singular",at:0}}function ss(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?E({lo:1,hi:1}):t.hi<0?E({lo:-1,hi:-1}):t.lo===0&&t.hi===0?E({lo:0,hi:0}):{kind:"singular",at:0}}var Vu=1.4616321449683622,Mp=.8856031944108887;function os(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return wp(t)}function wp(e){if(e.hi>=0&&e.lo<=0)return{kind:"singular",at:0};if(e.lo<0){let n=Math.ceil(e.lo),t=Math.floor(e.hi);if(n<=t)return{kind:"singular",at:n};let i=ie(e.lo),r=ie(e.hi);return E({lo:Math.min(i,r),hi:Math.max(i,r)})}return e.lo>=Vu?E({lo:ie(e.lo),hi:ie(e.hi)}):e.hi<=Vu?E({lo:ie(e.hi),hi:ie(e.lo)}):E({lo:Mp,hi:Math.max(ie(e.lo),ie(e.hi))})}function as(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return Ap(t)}function Ap(e){if(e.hi>=0&&e.lo<=0)return{kind:"singular",at:0};if(e.lo<0){let n=Math.ceil(e.lo),t=Math.floor(e.hi);if(n<=t)return{kind:"singular",at:n};let i=ke(e.lo),r=ke(e.hi);return E({lo:Math.min(i,r),hi:Math.max(i,r)})}return E({lo:ke(e.lo),hi:ke(e.hi)})}function us(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=Un(Math.round(t.lo)),r=Un(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?E({lo:Math.min(i,r),hi:Math.max(i,r)}):E({lo:i,hi:r})}function ls(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=Hn(Math.round(t.lo)),r=Hn(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?E({lo:Math.min(i,r),hi:Math.max(i,r)}):E({lo:i,hi:r})}function Ju(e,n){let t=_(e);if(!Array.isArray(t))return t;let i=_(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=[yn(Math.round(r.lo),Math.round(s.lo)),yn(Math.round(r.lo),Math.round(s.hi)),yn(Math.round(r.hi),Math.round(s.lo)),yn(Math.round(r.hi),Math.round(s.hi))];return E({lo:Math.min(...o),hi:Math.max(...o)})}function qu(e,n){let t=_(e);if(!Array.isArray(t))return t;let i=_(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=[Me(Math.round(r.lo),Math.round(s.lo)),Me(Math.round(r.lo),Math.round(s.hi)),Me(Math.round(r.hi),Math.round(s.lo)),Me(Math.round(r.hi),Math.round(s.hi))];return E({lo:Math.min(...o),hi:Math.max(...o)})}function zu(e,n){let t=_(e);if(!Array.isArray(t))return t;let i=_(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=[Xe(Math.round(r.lo),Math.round(s.lo)),Xe(Math.round(r.lo),Math.round(s.hi)),Xe(Math.round(r.hi),Math.round(s.lo)),Xe(Math.round(r.hi),Math.round(s.hi))];return E({lo:Math.min(...o),hi:Math.max(...o)})}function Gu(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Zn(t.lo),hi:Zn(t.hi)})}function ju(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Bn(t.lo),hi:Bn(t.hi)})}function Uu(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:ct(t.hi),hi:ct(t.lo)})}function Hu(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.pow(2,t.lo),hi:Math.pow(2,t.hi)})}function Zu(e,n){let t=_(e);if(!Array.isArray(t))return t;let i=_(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=[Math.hypot(r.lo,s.lo),Math.hypot(r.lo,s.hi),Math.hypot(r.hi,s.lo),Math.hypot(r.hi,s.hi)],a=Math.min(...o);return r.lo<=0&&r.hi>=0&&(a=Math.min(a,Math.abs(s.lo),Math.abs(s.hi))),s.lo<=0&&s.hi>=0&&(a=Math.min(a,Math.abs(r.lo),Math.abs(r.hi))),r.lo<=0&&r.hi>=0&&s.lo<=0&&s.hi>=0&&(a=0),E({lo:a,hi:Math.max(...o)})}var Le=2*Math.PI,re=Math.PI,on=Math.PI/2,Yu=3*Math.PI/2;function fs(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=Le)return E({lo:-1,hi:1});let i=Math.sin(t.lo),r=Math.sin(t.hi),s=Math.min(i,r),o=Math.max(i,r);return ce(t,on,Le)&&(o=1),ce(t,Yu,Le)&&(s=-1),E({lo:s,hi:o})}function ps(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=Le)return E({lo:-1,hi:1});let i=Math.cos(t.lo),r=Math.cos(t.hi),s=Math.min(i,r),o=Math.max(i,r);return ce(t,0,Le)&&(o=1),ce(t,re,Le)&&(s=-1),E({lo:s,hi:o})}function ms(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(ce(t,on,re)){let s=Math.ceil((t.lo-on)/re);return{kind:"singular",at:on+s*re}}let i=Math.tan(t.lo),r=Math.tan(t.hi);return i>1e10&&r<-1e10||i<-1e10&&r>1e10?{kind:"singular"}:E({lo:i,hi:r})}function ds(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(ce(t,0,re))return{kind:"singular",at:Math.ceil(t.lo/re)*re};let i=1/Math.tan(t.lo),r=1/Math.tan(t.hi);return E({lo:Math.min(i,r),hi:Math.max(i,r)})}function hs(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(ce(t,on,re)){let a=Math.ceil((t.lo-on)/re);return{kind:"singular",at:on+a*re}}let i=1/Math.cos(t.lo),r=1/Math.cos(t.hi),s=Math.min(i,r),o=Math.max(i,r);return ce(t,0,Le)&&(s=Math.min(s,1),o=Math.max(o,1)),ce(t,re,Le)&&(s=Math.min(s,-1),o=Math.max(o,-1)),E({lo:s,hi:o})}function gs(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(ce(t,0,re))return{kind:"singular",at:Math.ceil(t.lo/re)*re};let i=1/Math.sin(t.lo),r=1/Math.sin(t.hi),s=Math.min(i,r),o=Math.max(i,r);return ce(t,on,Le)&&(s=Math.min(s,1),o=Math.max(o,1)),ce(t,Yu,Le)&&(s=Math.min(s,-1),o=Math.max(o,-1)),E({lo:s,hi:o})}function gi(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo>1||t.hi<-1)return{kind:"empty"};if(t.lo<-1||t.hi>1){let i=Math.max(t.lo,-1),r=Math.min(t.hi,1);return{kind:"partial",value:{lo:Math.asin(i),hi:Math.asin(r)},domainClipped:t.lo<-1&&t.hi>1?"both":t.lo<-1?"lo":"hi"}}return E({lo:Math.asin(t.lo),hi:Math.asin(t.hi)})}function bi(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo>1||t.hi<-1)return{kind:"empty"};if(t.lo<-1||t.hi>1){let i=Math.max(t.lo,-1),r=Math.min(t.hi,1);return{kind:"partial",value:{lo:Math.acos(r),hi:Math.acos(i)},domainClipped:t.lo<-1&&t.hi>1?"both":t.lo<-1?"lo":"hi"}}return E({lo:Math.acos(t.hi),hi:Math.acos(t.lo)})}function yi(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.atan(t.lo),hi:Math.atan(t.hi)})}function bs(e,n){let t=_(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(i.lo===i.hi&&r.lo===r.hi){let o=Math.atan2(i.lo,r.lo);return E({lo:o,hi:o})}let s=[];return s.push(Math.atan2(i.lo,r.lo)),s.push(Math.atan2(i.lo,r.hi)),s.push(Math.atan2(i.hi,r.lo)),s.push(Math.atan2(i.hi,r.hi)),r.lo<0&&i.lo<0&&i.hi>0?E({lo:-re,hi:re}):E({lo:Math.min(...s),hi:Math.max(...s)})}function gt(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.sinh(t.lo),hi:Math.sinh(t.hi)})}function bt(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?E({lo:Math.cosh(t.lo),hi:Math.cosh(t.hi)}):t.hi<=0?E({lo:Math.cosh(t.hi),hi:Math.cosh(t.lo)}):E({lo:1,hi:Math.max(Math.cosh(t.lo),Math.cosh(t.hi))})}function ys(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.tanh(t.lo),hi:Math.tanh(t.hi)})}function xi(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.asinh(t.lo),hi:Math.asinh(t.hi)})}function vi(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<1?{kind:"empty"}:t.lo<1?{kind:"partial",value:{lo:0,hi:Math.acosh(t.hi)},domainClipped:"lo"}:E({lo:Math.acosh(t.lo),hi:Math.acosh(t.hi)})}function Ei(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo>=1||t.hi<=-1)return{kind:"empty"};if(t.lo<=-1||t.hi>=1){let i=Math.max(t.lo,-1+Number.EPSILON),r=Math.min(t.hi,1-Number.EPSILON);return{kind:"partial",value:{lo:Math.atanh(i),hi:Math.atanh(r)},domainClipped:t.lo<=-1&&t.hi>=1?"both":t.lo<=-1?"lo":"hi"}}return E({lo:Math.atanh(t.lo),hi:Math.atanh(t.hi)})}function xs(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:yi(de(E({lo:1,hi:1}),E(t)))}function vs(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:gi(de(E({lo:1,hi:1}),E(t)))}function Es(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:bi(de(E({lo:1,hi:1}),E(t)))}function Ns(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:de(bt(t),gt(t))}function Ts(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:de(E({lo:1,hi:1}),gt(t))}function Is(e){return de(E({lo:1,hi:1}),bt(e))}function _s(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:Ei(de(E({lo:1,hi:1}),E(t)))}function ks(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:xi(de(E({lo:1,hi:1}),E(t)))}function Ss(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n;return me(t)?{kind:"singular",at:0}:vi(de(E({lo:1,hi:1}),E(t)))}var cs=[4.49341,7.72525,10.90412,14.06619,17.22076,20.3713,23.51945,26.66605,29.8116,32.95639],$p=-.21724;function Ms(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=u=>u===0?1:Math.sin(u)/u,r=i(t.lo),s=r,o=u=>{u<r&&(r=u),u>s&&(s=u)};o(i(t.hi)),t.lo<=0&&t.hi>=0&&o(1);let a=cs[cs.length-1];for(let u of cs)u>=t.lo&&u<=t.hi&&o(i(u)),-u>=t.lo&&-u<=t.hi&&o(i(-u));return(Math.abs(t.lo)>a||Math.abs(t.hi)>a)&&o($p),E({lo:r,hi:s})}var Wu=[],Xu=[];for(let e=1;e<=20;e++)Wu.push(Math.sqrt(2*e)),Xu.push(Math.sqrt(2*e-1));function ws(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=gn(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(gn(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of Wu)o>=t.lo&&o<=t.hi&&s(gn(o)),-o>=t.lo&&-o<=t.hi&&s(gn(-o));return E({lo:i,hi:r})}function As(e){let n=_(e);if(!Array.isArray(n))return n;let[t]=n,i=bn(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(bn(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of Xu)o>=t.lo&&o<=t.hi&&s(bn(o)),-o>=t.lo&&-o<=t.hi&&s(bn(-o));return E({lo:i,hi:r})}function an(e){return"kind"in e?e:{kind:"interval",value:e}}function $s(e,n){let t=_(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.hi<r.lo?"true":i.lo>=r.hi?"false":"maybe"}function Cs(e,n){let t=_(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.hi<=r.lo?"true":i.lo>r.hi?"false":"maybe"}function Rs(e,n){let t=_(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.lo>r.hi?"true":i.hi<=r.lo?"false":"maybe"}function Ds(e,n){let t=_(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.lo>=r.hi?"true":i.hi<r.lo?"false":"maybe"}function Ni(e,n){let t=_(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.lo===i.hi&&r.lo===r.hi&&i.lo===r.lo?"true":i.hi<r.lo||r.hi<i.lo?"false":"maybe"}function Ps(e,n){let t=Ni(e,n);return t==="true"?"false":t==="false"?"true":"maybe"}function Fs(e,n){return e==="false"||n==="false"?"false":e==="true"&&n==="true"?"true":"maybe"}function Ls(e,n){return e==="true"||n==="true"?"true":e==="false"&&n==="false"?"false":"maybe"}function Os(e){return e==="true"?"false":e==="false"?"true":"maybe"}function Bs(e,n,t,i){if(e==="true"||e==="false"||e==="maybe"){let f=e,m=n,d=t;switch(f){case"true":return an(m());case"false":return an(d());case"maybe":return qn(an(m()),an(d()))}}let r=e,s=n,o=t,a=i,u=_(r);if(!Array.isArray(u))return u;let[l]=u;switch(s(l)){case"true":return an(o(l));case"false":return an(a(l));case"maybe":let f=an(o(l)),m=an(a(l));return qn(f,m)}}function Vs(e,n,t){let i=_(e,n,t);if(!Array.isArray(i))return i;let[r,s,o]=i,a=Math.max(r.lo,s.lo),u=Math.min(r.hi,o.hi);return a>u?{kind:"empty"}:{kind:"interval",value:{lo:a,hi:u}}}var Qu={ok:E,point:Ar,containsExtremum:ce,unionResults:qn,mergeDomainClip:mi,isPoint:$r,containsZero:me,isPositive:Cr,isNegative:mt,isNonNegative:Rr,isNonPositive:Dr,width:Pr,midpoint:Fr,getValue:Lr,unwrap:Or,unwrapOrPropagate:_,add:Br,sub:dt,mul:ht,div:de,negate:Vr,sqrt:qr,square:zr,pow:di,powInterval:Gr,exp:jr,ln:Ur,log10:Hr,log2:Zr,abs:Yr,floor:Wr,ceil:Xr,round:hi,fract:Qr,trunc:Kr,min:es,max:ns,mod:ts,remainder:is,heaviside:rs,sign:ss,gamma:os,gammaln:as,factorial:us,factorial2:ls,binomial:Ju,gcd:qu,lcm:zu,chop:Gu,erf:ju,erfc:Uu,exp2:Hu,hypot:Zu,sin:fs,cos:ps,tan:ms,cot:ds,sec:hs,csc:gs,asin:gi,acos:bi,atan:yi,atan2:bs,sinh:gt,cosh:bt,tanh:ys,asinh:xi,acosh:vi,atanh:Ei,acot:xs,acsc:vs,asec:Es,coth:Ns,csch:Ts,sech:Is,acoth:_s,acsch:ks,asech:Ss,sinc:Ms,fresnelS:ws,fresnelC:As,less:$s,lessEqual:Cs,greater:Rs,greaterEqual:Ds,equal:Ni,notEqual:Ps,and:Fs,or:Ls,not:Os,piecewise:Bs,clamp:Vs};var Cp={Add:["_IA.add",20],Negate:["_IA.negate",20],Subtract:["_IA.sub",20],Multiply:["_IA.mul",20],Divide:["_IA.div",20],Equal:["_IA.equal",20],NotEqual:["_IA.notEqual",20],LessEqual:["_IA.lessEqual",20],GreaterEqual:["_IA.greaterEqual",20],Less:["_IA.less",20],Greater:["_IA.greater",20],And:["_IA.and",20],Or:["_IA.or",20],Not:["_IA.not",20]},Js={Add:(e,n)=>{if(e.length===0)return"_IA.point(0)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.add(${t}, ${n(e[i])})`;return t},Multiply:(e,n)=>{if(e.length===0)return"_IA.point(1)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.mul(${t}, ${n(e[i])})`;return t},Divide:(e,n)=>{if(e.length===0)return"_IA.point(1)";if(e.length===1)return n(e[0]);if(e.length===2)return`_IA.div(${n(e[0])}, ${n(e[1])})`;let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.div(${t}, ${n(e[i])})`;return t},Negate:(e,n)=>`_IA.negate(${n(e[0])})`,Abs:(e,n)=>`_IA.abs(${n(e[0])})`,Ceil:(e,n)=>`_IA.ceil(${n(e[0])})`,Exp:(e,n)=>`_IA.exp(${n(e[0])})`,Floor:(e,n)=>`_IA.floor(${n(e[0])})`,Ln:(e,n)=>`_IA.ln(${n(e[0])})`,Log:(e,n)=>e.length===1?`_IA.log10(${n(e[0])})`:`_IA.div(_IA.ln(${n(e[0])}), _IA.ln(${n(e[1])}))`,Lb:(e,n)=>`_IA.log2(${n(e[0])})`,Max:(e,n)=>{if(e.length===0)return"_IA.point(-Infinity)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.max(${t}, ${n(e[i])})`;return t},Min:(e,n)=>{if(e.length===0)return"_IA.point(Infinity)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.min(${t}, ${n(e[i])})`;return t},Power:(e,n)=>{let t=e[0],i=e[1];if(t===null)throw new Error("Power: no argument");if(k(t,"ExponentialE"))return`_IA.exp(${n(i)})`;if(D(i)&&i.im===0){let r=i.re;return r===.5?`_IA.sqrt(${n(t)})`:r===2?`_IA.square(${n(t)})`:`_IA.pow(${n(t)}, ${r})`}return`_IA.powInterval(${n(t)}, ${n(i)})`},Root:(e,n)=>{let[t,i]=e;if(t===null)throw new Error("Root: no argument");return i===null?`_IA.sqrt(${n(t)})`:i?.re===2?`_IA.sqrt(${n(t)})`:D(i)&&i.im===0?`_IA.pow(${n(t)}, ${1/i.re})`:`_IA.powInterval(${n(t)}, _IA.div(_IA.point(1), ${n(i)}))`},Round:(e,n)=>`_IA.round(${n(e[0])})`,Heaviside:(e,n)=>`_IA.heaviside(${n(e[0])})`,Sign:(e,n)=>`_IA.sign(${n(e[0])})`,Sqrt:(e,n)=>`_IA.sqrt(${n(e[0])})`,Square:(e,n)=>`_IA.square(${n(e[0])})`,Sin:(e,n)=>`_IA.sin(${n(e[0])})`,Cos:(e,n)=>`_IA.cos(${n(e[0])})`,Tan:(e,n)=>`_IA.tan(${n(e[0])})`,Cot:(e,n)=>`_IA.cot(${n(e[0])})`,Sec:(e,n)=>`_IA.sec(${n(e[0])})`,Csc:(e,n)=>`_IA.csc(${n(e[0])})`,Arcsin:(e,n)=>`_IA.asin(${n(e[0])})`,Arccos:(e,n)=>`_IA.acos(${n(e[0])})`,Arctan:(e,n)=>`_IA.atan(${n(e[0])})`,Arccot:(e,n)=>`_IA.acot(${n(e[0])})`,Arccsc:(e,n)=>`_IA.acsc(${n(e[0])})`,Arcsec:(e,n)=>`_IA.asec(${n(e[0])})`,Sinh:(e,n)=>`_IA.sinh(${n(e[0])})`,Cosh:(e,n)=>`_IA.cosh(${n(e[0])})`,Tanh:(e,n)=>`_IA.tanh(${n(e[0])})`,Coth:(e,n)=>`_IA.coth(${n(e[0])})`,Csch:(e,n)=>`_IA.csch(${n(e[0])})`,Sech:(e,n)=>`_IA.sech(${n(e[0])})`,Arsinh:(e,n)=>`_IA.asinh(${n(e[0])})`,Arcosh:(e,n)=>`_IA.acosh(${n(e[0])})`,Artanh:(e,n)=>`_IA.atanh(${n(e[0])})`,Arcoth:(e,n)=>`_IA.acoth(${n(e[0])})`,Arcsch:(e,n)=>`_IA.acsch(${n(e[0])})`,Arsech:(e,n)=>`_IA.asech(${n(e[0])})`,Sinc:(e,n)=>`_IA.sinc(${n(e[0])})`,FresnelS:(e,n)=>`_IA.fresnelS(${n(e[0])})`,FresnelC:(e,n)=>`_IA.fresnelC(${n(e[0])})`,Factorial:(e,n)=>`_IA.factorial(${n(e[0])})`,Factorial2:(e,n)=>`_IA.factorial2(${n(e[0])})`,Gamma:(e,n)=>`_IA.gamma(${n(e[0])})`,GammaLn:(e,n)=>`_IA.gammaln(${n(e[0])})`,Binomial:(e,n)=>`_IA.binomial(${n(e[0])}, ${n(e[1])})`,GCD:(e,n)=>`_IA.gcd(${n(e[0])}, ${n(e[1])})`,LCM:(e,n)=>`_IA.lcm(${n(e[0])}, ${n(e[1])})`,Chop:(e,n)=>`_IA.chop(${n(e[0])})`,Erf:(e,n)=>`_IA.erf(${n(e[0])})`,Erfc:(e,n)=>`_IA.erfc(${n(e[0])})`,Exp2:(e,n)=>`_IA.exp2(${n(e[0])})`,Arctan2:(e,n)=>`_IA.atan2(${n(e[0])}, ${n(e[1])})`,Hypot:(e,n)=>`_IA.hypot(${n(e[0])}, ${n(e[1])})`,Fract:(e,n)=>`_IA.fract(${n(e[0])})`,Truncate:(e,n)=>`_IA.trunc(${n(e[0])})`,Mod:(e,n)=>`_IA.mod(${n(e[0])}, ${n(e[1])})`,Remainder:(e,n)=>`_IA.remainder(${n(e[0])}, ${n(e[1])})`,Sum:(e,n,t)=>el("Sum",e,n,t),Product:(e,n,t)=>el("Product",e,n,t),If:(e,n)=>{if(e.length!==3)throw new Error("If: wrong number of arguments");return`_IA.piecewise(
1370
+ `,o}compileLambda(n,t){let i=this.createTarget(),r=b.compile(n,i);return`lambda ${t.join(", ")}: ${r}`}};function E(e){return{kind:"interval",value:e}}function Zr(e){return{lo:e,hi:e}}function fe(e,n,t){let i=Math.ceil((e.lo-n)/t),r=n+i*t,s=1e-15;return r>=e.lo-s&&r<=e.hi+s}function Un(e,n){if(e.kind==="empty")return n;if(n.kind==="empty")return e;if(e.kind==="singular"||n.kind==="singular")return{kind:"singular"};if(e.kind==="entire"||n.kind==="entire")return{kind:"entire"};let t=e.value,i=n.value,r=e.kind==="partial"?e.domainClipped:null,s=n.kind==="partial"?n.domainClipped:null,o={lo:Math.min(t.lo,i.lo),hi:Math.max(t.hi,i.hi)};if(r||s){let a=Ii(r,s);return{kind:"partial",value:o,domainClipped:a}}return{kind:"interval",value:o}}function Ii(e,n){return e==="both"||n==="both"?"both":e===null?n:n===null||e===n?e:"both"}function Yr(e){return e.lo===e.hi}function de(e){return e.lo<=0&&e.hi>=0}function Wr(e){return e.lo>0}function Et(e){return e.hi<0}function Xr(e){return e.lo>=0}function Qr(e){return e.hi<=0}function Kr(e){return e.hi-e.lo}function es(e){return(e.lo+e.hi)/2}function ns(e){if(e.kind==="interval"||e.kind==="partial")return e.value}function ts(e){return"kind"in e?e.kind==="interval"||e.kind==="partial"?e.value:void 0:e}function S(...e){let n=[];for(let t of e)if("kind"in t){if(t.kind==="empty")return{kind:"empty"};if(t.kind==="entire")return{kind:"entire"};if(t.kind==="singular")return t;n.push(t.value)}else n.push(t);return n}function is(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:i.lo+r.lo,hi:i.hi+r.hi})}function Nt(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:i.lo-r.hi,hi:i.hi-r.lo})}function rs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:-t.hi,hi:-t.lo})}function ss(e,n){let t=[_i(e.lo,n.lo),_i(e.lo,n.hi),_i(e.hi,n.lo),_i(e.hi,n.hi)];return{lo:Math.min(...t),hi:Math.max(...t)}}function _i(e,n){return e===0||n===0?0:e*n}function Tt(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E(ss(i,r))}function he(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return Am(i,r)}function Am(e,n){return n.lo>0||n.hi<0?E(ss(e,{lo:1/n.hi,hi:1/n.lo})):n.lo<0&&n.hi>0?{kind:"singular"}:n.lo===0&&n.hi>0?e.lo>=0?{kind:"partial",value:{lo:e.lo/n.hi,hi:1/0},domainClipped:"hi"}:e.hi<=0?{kind:"partial",value:{lo:-1/0,hi:e.hi/n.hi},domainClipped:"lo"}:{kind:"entire"}:n.hi===0&&n.lo<0?e.lo>=0?{kind:"partial",value:{lo:-1/0,hi:e.lo/n.lo},domainClipped:"lo"}:e.hi<=0?{kind:"partial",value:{lo:e.hi/n.lo,hi:1/0},domainClipped:"hi"}:{kind:"entire"}:{kind:"empty"}}function as(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return $m(t)}function $m(e){return e.hi<0?{kind:"empty"}:e.lo>=0?E({lo:Math.sqrt(e.lo),hi:Math.sqrt(e.hi)}):{kind:"partial",value:{lo:0,hi:Math.sqrt(e.hi)},domainClipped:"lo"}}function us(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?E({lo:t.lo*t.lo,hi:t.hi*t.hi}):t.hi<=0?E({lo:t.hi*t.hi,hi:t.lo*t.lo}):E({lo:0,hi:Math.max(t.lo*t.lo,t.hi*t.hi)})}function kl(e,n){return n===0?{lo:1,hi:1}:n===1?e:n%2===0?e.lo>=0?{lo:Math.pow(e.lo,n),hi:Math.pow(e.hi,n)}:e.hi<=0?{lo:Math.pow(e.hi,n),hi:Math.pow(e.lo,n)}:{lo:0,hi:Math.max(Math.pow(e.lo,n),Math.pow(e.hi,n))}:{lo:Math.pow(e.lo,n),hi:Math.pow(e.hi,n)}}function Si(e,n){let t=S(e);if(!Array.isArray(t))return t;let[i]=t;if(Number.isInteger(n)){if(n>=0)return E(kl(i,n));{if(de(i))return{kind:"singular"};let r=kl(i,-n);return E({lo:1/r.hi,hi:1/r.lo})}}else return Et(i)?{kind:"empty"}:i.lo<0?{kind:"partial",value:n>0?{lo:0,hi:Math.pow(i.hi,n)}:{lo:Math.pow(i.hi,n),hi:1/0},domainClipped:"lo"}:n>0?E({lo:Math.pow(i.lo,n),hi:Math.pow(i.hi,n)}):i.lo===0?{kind:"partial",value:{lo:Math.pow(i.hi,n),hi:1/0},domainClipped:"hi"}:E({lo:Math.pow(i.hi,n),hi:Math.pow(i.lo,n)})}function ls(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(r.lo===r.hi&&Number.isInteger(r.lo))return Si(i,r.lo);if(i.hi<=0)return i.lo===-1&&i.hi===-1&&Math.floor(r.hi)>Math.floor(r.lo)?E({lo:-1,hi:1}):{kind:"empty"};if(i.lo<=0){let o={lo:Math.max(i.lo,Number.EPSILON),hi:i.hi},a=[Math.pow(o.lo,r.lo),Math.pow(o.lo,r.hi),Math.pow(o.hi,r.lo),Math.pow(o.hi,r.hi)];return{kind:"partial",value:{lo:Math.min(...a),hi:Math.max(...a)},domainClipped:"lo"}}let s=[Math.pow(i.lo,r.lo),Math.pow(i.lo,r.hi),Math.pow(i.hi,r.lo),Math.pow(i.hi,r.hi)];return E({lo:Math.min(...s),hi:Math.max(...s)})}function cs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.exp(t.lo),hi:Math.exp(t.hi)})}function fs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?E({lo:Math.log(t.lo),hi:Math.log(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log(t.hi)},domainClipped:"lo"}}function ps(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?E({lo:Math.log10(t.lo),hi:Math.log10(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log10(t.hi)},domainClipped:"lo"}}function ms(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?E({lo:Math.log2(t.lo),hi:Math.log2(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log2(t.hi)},domainClipped:"lo"}}function ds(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?E(t):t.hi<=0?E({lo:-t.hi,hi:-t.lo}):E({lo:0,hi:Math.max(-t.lo,t.hi)})}function hs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?E({lo:i,hi:r}):{kind:"singular",at:i+1,continuity:"right"}}function gs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.ceil(t.lo),r=Math.ceil(t.hi);return i===r?E({lo:i,hi:r}):{kind:"singular",at:i,continuity:"left"}}function ki(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.round(t.lo),r=Math.round(t.hi);return i===r?E({lo:i,hi:r}):{kind:"singular",at:i+.5,continuity:"right"}}function bs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?E({lo:t.lo-i,hi:t.hi-i}):{kind:"singular",at:i+1,continuity:"right"}}function ys(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.trunc(t.lo),r=Math.trunc(t.hi);if(i===r)return E({lo:i,hi:r});if(t.lo>=0)return{kind:"singular",at:i+1,continuity:"right"};let s=Math.ceil(t.lo);return s!==0?{kind:"singular",at:s,continuity:"left"}:{kind:"singular",at:1,continuity:"right"}}function xs(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:Math.min(i.lo,r.lo),hi:Math.min(i.hi,r.hi)})}function vs(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return E({lo:Math.max(i.lo,r.lo),hi:Math.max(i.hi,r.hi)})}function Es(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(de(r))return{kind:"singular"};let s=Math.abs(r.lo===r.hi?r.lo:Math.max(Math.abs(r.lo),Math.abs(r.hi))),o=r.hi<0,a=Math.floor(i.lo/s),u=Math.floor(i.hi/s);if(a!==u)return{kind:"singular",at:(a+1)*s,continuity:"right"};let l=i.lo-s*a,c=i.hi-s*a;return o?l===0?{kind:"singular",at:i.lo,continuity:"right"}:E({lo:l-s,hi:c-s}):E({lo:Math.min(l,c),hi:Math.max(l,c)})}function Ns(e,n){return Nt(e,Tt(n,ki(he(e,n))))}function Ts(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?E({lo:1,hi:1}):t.hi<0?E({lo:0,hi:0}):t.lo===0&&t.hi===0?E({lo:.5,hi:.5}):{kind:"singular",at:0}}function Is(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?E({lo:1,hi:1}):t.hi<0?E({lo:-1,hi:-1}):t.lo===0&&t.hi===0?E({lo:0,hi:0}):{kind:"singular",at:0}}var Ml=1.4616321449683622,Cm=.8856031944108887;function _s(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return Rm(t)}var wl=[-.504083008264455,-1.573498473162391,-2.610720868444145,-3.635293366436901,-4.653163765628266,-5.667162441556885,-6.678418213073426,-7.687788325031709,-8.695764163640956,-9.702672540001863];function $l(e){let t=-Math.floor(e)-1;return t>=0&&t<wl.length?wl[t]:null}function Rm(e){if(e.hi>=0&&e.lo<=0)return{kind:"singular",at:0};if(e.lo<0){let n=Math.ceil(e.lo),t=Math.floor(e.hi);if(n<=t)return{kind:"singular",at:n};let i=ne(e.lo),r=ne(e.hi),s=Math.min(i,r),o=Math.max(i,r),a=$l(e.lo);if(a!==null){if(a>=e.lo&&a<=e.hi){let u=ne(a);s=Math.min(s,u),o=Math.max(o,u)}}else Math.floor(e.lo)%2===0?s=Math.min(s,0):o=Math.max(o,0);return E({lo:s,hi:o})}return e.lo>=Ml?E({lo:ne(e.lo),hi:ne(e.hi)}):e.hi<=Ml?E({lo:ne(e.hi),hi:ne(e.lo)}):E({lo:Cm,hi:Math.max(ne(e.lo),ne(e.hi))})}function Ss(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return Dm(t)}function Dm(e){if(e.hi>=0&&e.lo<=0)return{kind:"singular",at:0};if(e.lo<0){let n=Math.ceil(e.lo),t=Math.floor(e.hi);if(n<=t)return{kind:"singular",at:n};let i=_e(e.lo),r=_e(e.hi),s=Math.min(i,r),o=Math.max(i,r),a=$l(e.lo);return a!==null?a>=e.lo&&a<=e.hi&&(s=Math.min(s,_e(a))):s=-1/0,E({lo:s,hi:o})}return E({lo:_e(e.lo),hi:_e(e.hi)})}function ks(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=Xn(Math.round(t.lo)),r=Xn(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?E({lo:Math.min(i,r),hi:Math.max(i,r)}):E({lo:i,hi:r})}function Ms(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=Qn(Math.round(t.lo)),r=Qn(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?E({lo:Math.min(i,r),hi:Math.max(i,r)}):E({lo:i,hi:r})}var os=4096;function Al(e,n,t){let i=Math.round(e),r=Math.round(n);if(!Number.isFinite(i)||!Number.isFinite(r)||r-i+1>t)return null;let s=[];for(let o=i;o<=r;o++)s.push(o);return s}function ws(e,n,t){let i=Al(e.lo,e.hi,os),r=Al(n.lo,n.hi,os);if(!i||!r||i.length*r.length>os)return null;let s=1/0,o=-1/0;for(let a of i)for(let u of r){let l=t(a,u);Number.isFinite(l)&&(l<s&&(s=l),l>o&&(o=l))}return s===1/0?null:E({lo:s,hi:o})}function As(e,n){let t=S(e);if(!Array.isArray(t))return t;let i=S(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=ws(r,s,yt);if(o)return o;let a=Math.round(r.hi);return E({lo:0,hi:yt(a,Math.floor(a/2))})}function $s(e,n){let t=S(e);if(!Array.isArray(t))return t;let i=S(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=ws(r,s,mn);if(o)return o;let a=Math.max(Math.abs(Math.round(r.lo)),Math.abs(Math.round(r.hi)),Math.abs(Math.round(s.lo)),Math.abs(Math.round(s.hi)));return E({lo:0,hi:a})}function Cs(e,n){let t=S(e);if(!Array.isArray(t))return t;let i=S(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=ws(r,s,Wn);if(o)return o;let a=Math.max(Math.abs(Math.round(r.lo)),Math.abs(Math.round(r.hi))),u=Math.max(Math.abs(Math.round(s.lo)),Math.abs(Math.round(s.hi)));return E({lo:0,hi:a*u})}function Cl(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Kn(t.lo),hi:Kn(t.hi)})}function Rl(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Sn(t.lo),hi:Sn(t.hi)})}function Dl(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:zn(t.hi),hi:zn(t.lo)})}function Pl(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.pow(2,t.lo),hi:Math.pow(2,t.hi)})}function Fl(e,n){let t=S(e);if(!Array.isArray(t))return t;let i=S(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=[Math.hypot(r.lo,s.lo),Math.hypot(r.lo,s.hi),Math.hypot(r.hi,s.lo),Math.hypot(r.hi,s.hi)],a=Math.min(...o);return r.lo<=0&&r.hi>=0&&(a=Math.min(a,Math.abs(s.lo),Math.abs(s.hi))),s.lo<=0&&s.hi>=0&&(a=Math.min(a,Math.abs(r.lo),Math.abs(r.hi))),r.lo<=0&&r.hi>=0&&s.lo<=0&&s.hi>=0&&(a=0),E({lo:a,hi:Math.max(...o)})}var qe=2*Math.PI,re=Math.PI,fn=Math.PI/2,Ol=3*Math.PI/2;function Fs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=qe)return E({lo:-1,hi:1});let i=Math.sin(t.lo),r=Math.sin(t.hi),s=Math.min(i,r),o=Math.max(i,r);return fe(t,fn,qe)&&(o=1),fe(t,Ol,qe)&&(s=-1),E({lo:s,hi:o})}function Os(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=qe)return E({lo:-1,hi:1});let i=Math.cos(t.lo),r=Math.cos(t.hi),s=Math.min(i,r),o=Math.max(i,r);return fe(t,0,qe)&&(o=1),fe(t,re,qe)&&(s=-1),E({lo:s,hi:o})}function Ls(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(fe(t,fn,re)){let s=Math.ceil((t.lo-fn)/re);return{kind:"singular",at:fn+s*re}}let i=Math.tan(t.lo),r=Math.tan(t.hi);return i>1e10&&r<-1e10||i<-1e10&&r>1e10?{kind:"singular"}:E({lo:i,hi:r})}function Bs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(fe(t,0,re))return{kind:"singular",at:Math.ceil(t.lo/re)*re};let i=1/Math.tan(t.lo),r=1/Math.tan(t.hi);return E({lo:Math.min(i,r),hi:Math.max(i,r)})}function Vs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(fe(t,fn,re)){let a=Math.ceil((t.lo-fn)/re);return{kind:"singular",at:fn+a*re}}let i=1/Math.cos(t.lo),r=1/Math.cos(t.hi),s=Math.min(i,r),o=Math.max(i,r);return fe(t,0,qe)&&(s=Math.min(s,1),o=Math.max(o,1)),fe(t,re,qe)&&(s=Math.min(s,-1),o=Math.max(o,-1)),E({lo:s,hi:o})}function qs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=re)return{kind:"singular"};if(fe(t,0,re))return{kind:"singular",at:Math.ceil(t.lo/re)*re};let i=1/Math.sin(t.lo),r=1/Math.sin(t.hi),s=Math.min(i,r),o=Math.max(i,r);return fe(t,fn,qe)&&(s=Math.min(s,1),o=Math.max(o,1)),fe(t,Ol,qe)&&(s=Math.min(s,-1),o=Math.max(o,-1)),E({lo:s,hi:o})}function Mi(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo>1||t.hi<-1)return{kind:"empty"};if(t.lo<-1||t.hi>1){let i=Math.max(t.lo,-1),r=Math.min(t.hi,1);return{kind:"partial",value:{lo:Math.asin(i),hi:Math.asin(r)},domainClipped:t.lo<-1&&t.hi>1?"both":t.lo<-1?"lo":"hi"}}return E({lo:Math.asin(t.lo),hi:Math.asin(t.hi)})}function wi(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo>1||t.hi<-1)return{kind:"empty"};if(t.lo<-1||t.hi>1){let i=Math.max(t.lo,-1),r=Math.min(t.hi,1);return{kind:"partial",value:{lo:Math.acos(r),hi:Math.acos(i)},domainClipped:t.lo<-1&&t.hi>1?"both":t.lo<-1?"lo":"hi"}}return E({lo:Math.acos(t.hi),hi:Math.acos(t.lo)})}function Ai(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.atan(t.lo),hi:Math.atan(t.hi)})}function Js(e,n){let t=S(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(i.lo===i.hi&&r.lo===r.hi){let o=Math.atan2(i.lo,r.lo);return E({lo:o,hi:o})}let s=[];return s.push(Math.atan2(i.lo,r.lo)),s.push(Math.atan2(i.lo,r.hi)),s.push(Math.atan2(i.hi,r.lo)),s.push(Math.atan2(i.hi,r.hi)),r.lo<0&&i.lo<0&&i.hi>0?E({lo:-re,hi:re}):E({lo:Math.min(...s),hi:Math.max(...s)})}function It(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.sinh(t.lo),hi:Math.sinh(t.hi)})}function _t(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?E({lo:Math.cosh(t.lo),hi:Math.cosh(t.hi)}):t.hi<=0?E({lo:Math.cosh(t.hi),hi:Math.cosh(t.lo)}):E({lo:1,hi:Math.max(Math.cosh(t.lo),Math.cosh(t.hi))})}function zs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.tanh(t.lo),hi:Math.tanh(t.hi)})}function $i(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return E({lo:Math.asinh(t.lo),hi:Math.asinh(t.hi)})}function Ci(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<1?{kind:"empty"}:t.lo<1?{kind:"partial",value:{lo:0,hi:Math.acosh(t.hi)},domainClipped:"lo"}:E({lo:Math.acosh(t.lo),hi:Math.acosh(t.hi)})}function Ri(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo>=1||t.hi<=-1)return{kind:"empty"};if(t.lo<=-1||t.hi>=1){let i=Math.max(t.lo,-1+Number.EPSILON),r=Math.min(t.hi,1-Number.EPSILON);return{kind:"partial",value:{lo:Math.atanh(i),hi:Math.atanh(r)},domainClipped:t.lo<=-1&&t.hi>=1?"both":t.lo<=-1?"lo":"hi"}}return E({lo:Math.atanh(t.lo),hi:Math.atanh(t.hi)})}function Gs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:Ai(he(E({lo:1,hi:1}),E(t)))}function js(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:Mi(he(E({lo:1,hi:1}),E(t)))}function Us(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:wi(he(E({lo:1,hi:1}),E(t)))}function Hs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:he(_t(t),It(t))}function Zs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:he(E({lo:1,hi:1}),It(t))}function Ys(e){return he(E({lo:1,hi:1}),_t(e))}function Ws(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:Ri(he(E({lo:1,hi:1}),E(t)))}function Xs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:$i(he(E({lo:1,hi:1}),E(t)))}function Qs(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n;return de(t)?{kind:"singular",at:0}:Ci(he(E({lo:1,hi:1}),E(t)))}var Rs=[4.49341,7.72525,10.90412,14.06619,17.22076,20.3713,23.51945,26.66605,29.8116,32.95639];function Ks(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=l=>l===0?1:Math.sin(l)/l,r=i(t.lo),s=r,o=l=>{l<r&&(r=l),l>s&&(s=l)};o(i(t.hi)),t.lo<=0&&t.hi>=0&&o(1);let a=Rs[Rs.length-1];for(let l of Rs)l>=t.lo&&l<=t.hi&&o(i(l)),-l>=t.lo&&-l<=t.hi&&o(i(-l));let u=1/0;return t.hi>a&&(u=Math.min(u,Math.max(t.lo,a))),t.lo<-a&&(u=Math.min(u,-Math.min(t.hi,-a))),Number.isFinite(u)&&u>0&&(o(1/u),o(-1/u)),E({lo:r,hi:s})}var Ds=[],Ps=[];for(let e=1;e<=20;e++)Ds.push(Math.sqrt(2*e)),Ps.push(Math.sqrt(2*e-1));function eo(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=un(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(un(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of Ds)o>=t.lo&&o<=t.hi&&s(un(o)),-o>=t.lo&&-o<=t.hi&&s(un(-o));return Ll(t,Ds,un,s),E({lo:i,hi:r})}function Ll(e,n,t,i){let r=n[n.length-1],s=Math.abs(t(r)-.5);e.hi>r&&(i(.5+s),i(.5-s)),e.lo<-r&&(i(-.5-s),i(-.5+s))}function no(e){let n=S(e);if(!Array.isArray(n))return n;let[t]=n,i=ln(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(ln(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of Ps)o>=t.lo&&o<=t.hi&&s(ln(o)),-o>=t.lo&&-o<=t.hi&&s(ln(-o));return Ll(t,Ps,ln,s),E({lo:i,hi:r})}function pn(e){return"kind"in e?e:{kind:"interval",value:e}}function to(e,n){let t=S(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.hi<r.lo?"true":i.lo>=r.hi?"false":"maybe"}function io(e,n){let t=S(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.hi<=r.lo?"true":i.lo>r.hi?"false":"maybe"}function ro(e,n){let t=S(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.lo>r.hi?"true":i.hi<=r.lo?"false":"maybe"}function so(e,n){let t=S(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.lo>=r.hi?"true":i.hi<r.lo?"false":"maybe"}function Di(e,n){let t=S(e,n);if(!Array.isArray(t))return"maybe";let[i,r]=t;return i.lo===i.hi&&r.lo===r.hi&&i.lo===r.lo?"true":i.hi<r.lo||r.hi<i.lo?"false":"maybe"}function oo(e,n){let t=Di(e,n);return t==="true"?"false":t==="false"?"true":"maybe"}function ao(e,n){return e==="false"||n==="false"?"false":e==="true"&&n==="true"?"true":"maybe"}function uo(e,n){return e==="true"||n==="true"?"true":e==="false"&&n==="false"?"false":"maybe"}function lo(e){return e==="true"?"false":e==="false"?"true":"maybe"}function co(e,n,t,i){if(e==="true"||e==="false"||e==="maybe"){let f=e,d=n,m=t;switch(f){case"true":return pn(d());case"false":return pn(m());case"maybe":return Un(pn(d()),pn(m()))}}let r=e,s=n,o=t,a=i,u=S(r);if(!Array.isArray(u))return u;let[l]=u;switch(s(l)){case"true":return pn(o(l));case"false":return pn(a(l));case"maybe":let f=pn(o(l)),d=pn(a(l));return Un(f,d)}}function fo(e,n,t){let i=S(e,n,t);if(!Array.isArray(i))return i;let[r,s,o]=i,a={lo:Math.max(r.lo,s.lo),hi:Math.max(r.hi,s.hi)},u=Math.min(a.lo,o.lo),l=Math.min(a.hi,o.hi);return{kind:"interval",value:{lo:u,hi:l}}}var Bl={ok:E,point:Zr,containsExtremum:fe,unionResults:Un,mergeDomainClip:Ii,isPoint:Yr,containsZero:de,isPositive:Wr,isNegative:Et,isNonNegative:Xr,isNonPositive:Qr,width:Kr,midpoint:es,getValue:ns,unwrap:ts,unwrapOrPropagate:S,add:is,sub:Nt,mul:Tt,div:he,negate:rs,sqrt:as,square:us,pow:Si,powInterval:ls,exp:cs,ln:fs,log10:ps,log2:ms,abs:ds,floor:hs,ceil:gs,round:ki,fract:bs,trunc:ys,min:xs,max:vs,mod:Es,remainder:Ns,heaviside:Ts,sign:Is,gamma:_s,gammaln:Ss,factorial:ks,factorial2:Ms,binomial:As,gcd:$s,lcm:Cs,chop:Cl,erf:Rl,erfc:Dl,exp2:Pl,hypot:Fl,sin:Fs,cos:Os,tan:Ls,cot:Bs,sec:Vs,csc:qs,asin:Mi,acos:wi,atan:Ai,atan2:Js,sinh:It,cosh:_t,tanh:zs,asinh:$i,acosh:Ci,atanh:Ri,acot:Gs,acsc:js,asec:Us,coth:Hs,csch:Zs,sech:Ys,acoth:Ws,acsch:Xs,asech:Qs,sinc:Ks,fresnelS:eo,fresnelC:no,less:to,lessEqual:io,greater:ro,greaterEqual:so,equal:Di,notEqual:oo,and:ao,or:uo,not:lo,piecewise:co,clamp:fo};var Pm={Add:["_IA.add",20],Negate:["_IA.negate",20],Subtract:["_IA.sub",20],Multiply:["_IA.mul",20],Divide:["_IA.div",20],Equal:["_IA.equal",20],NotEqual:["_IA.notEqual",20],LessEqual:["_IA.lessEqual",20],GreaterEqual:["_IA.greaterEqual",20],Less:["_IA.less",20],Greater:["_IA.greater",20],And:["_IA.and",20],Or:["_IA.or",20],Not:["_IA.not",20]},po={Add:(e,n)=>{if(e.length===0)return"_IA.point(0)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.add(${t}, ${n(e[i])})`;return t},Multiply:(e,n)=>{if(e.length===0)return"_IA.point(1)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.mul(${t}, ${n(e[i])})`;return t},Divide:(e,n)=>{if(e.length===0)return"_IA.point(1)";if(e.length===1)return n(e[0]);if(e.length===2)return`_IA.div(${n(e[0])}, ${n(e[1])})`;let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.div(${t}, ${n(e[i])})`;return t},Negate:(e,n)=>`_IA.negate(${n(e[0])})`,Abs:(e,n)=>`_IA.abs(${n(e[0])})`,Ceil:(e,n)=>`_IA.ceil(${n(e[0])})`,Exp:(e,n)=>`_IA.exp(${n(e[0])})`,Floor:(e,n)=>`_IA.floor(${n(e[0])})`,Ln:(e,n)=>`_IA.ln(${n(e[0])})`,Log:(e,n)=>e.length===1?`_IA.log10(${n(e[0])})`:`_IA.div(_IA.ln(${n(e[0])}), _IA.ln(${n(e[1])}))`,Lb:(e,n)=>`_IA.log2(${n(e[0])})`,Max:(e,n)=>{if(e.length===0)return"_IA.point(-Infinity)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.max(${t}, ${n(e[i])})`;return t},Min:(e,n)=>{if(e.length===0)return"_IA.point(Infinity)";if(e.length===1)return n(e[0]);let t=n(e[0]);for(let i=1;i<e.length;i++)t=`_IA.min(${t}, ${n(e[i])})`;return t},Power:(e,n)=>{let t=e[0],i=e[1];if(t===null)throw new Error("Power: no argument");if(T(t,"ExponentialE"))return`_IA.exp(${n(i)})`;if(R(i)&&i.im===0){let r=i.re;return r===.5?`_IA.sqrt(${n(t)})`:r===2?`_IA.square(${n(t)})`:`_IA.pow(${n(t)}, ${r})`}return`_IA.powInterval(${n(t)}, ${n(i)})`},Root:(e,n)=>{let[t,i]=e;if(t===null)throw new Error("Root: no argument");return i===null?`_IA.sqrt(${n(t)})`:i?.re===2?`_IA.sqrt(${n(t)})`:R(i)&&i.im===0?`_IA.pow(${n(t)}, ${1/i.re})`:`_IA.powInterval(${n(t)}, _IA.div(_IA.point(1), ${n(i)}))`},Round:(e,n)=>`_IA.round(${n(e[0])})`,Heaviside:(e,n)=>`_IA.heaviside(${n(e[0])})`,Sign:(e,n)=>`_IA.sign(${n(e[0])})`,Sqrt:(e,n)=>`_IA.sqrt(${n(e[0])})`,Square:(e,n)=>`_IA.square(${n(e[0])})`,Sin:(e,n)=>`_IA.sin(${n(e[0])})`,Cos:(e,n)=>`_IA.cos(${n(e[0])})`,Tan:(e,n)=>`_IA.tan(${n(e[0])})`,Cot:(e,n)=>`_IA.cot(${n(e[0])})`,Sec:(e,n)=>`_IA.sec(${n(e[0])})`,Csc:(e,n)=>`_IA.csc(${n(e[0])})`,Arcsin:(e,n)=>`_IA.asin(${n(e[0])})`,Arccos:(e,n)=>`_IA.acos(${n(e[0])})`,Arctan:(e,n)=>`_IA.atan(${n(e[0])})`,Arccot:(e,n)=>`_IA.acot(${n(e[0])})`,Arccsc:(e,n)=>`_IA.acsc(${n(e[0])})`,Arcsec:(e,n)=>`_IA.asec(${n(e[0])})`,Sinh:(e,n)=>`_IA.sinh(${n(e[0])})`,Cosh:(e,n)=>`_IA.cosh(${n(e[0])})`,Tanh:(e,n)=>`_IA.tanh(${n(e[0])})`,Coth:(e,n)=>`_IA.coth(${n(e[0])})`,Csch:(e,n)=>`_IA.csch(${n(e[0])})`,Sech:(e,n)=>`_IA.sech(${n(e[0])})`,Arsinh:(e,n)=>`_IA.asinh(${n(e[0])})`,Arcosh:(e,n)=>`_IA.acosh(${n(e[0])})`,Artanh:(e,n)=>`_IA.atanh(${n(e[0])})`,Arcoth:(e,n)=>`_IA.acoth(${n(e[0])})`,Arcsch:(e,n)=>`_IA.acsch(${n(e[0])})`,Arsech:(e,n)=>`_IA.asech(${n(e[0])})`,Sinc:(e,n)=>`_IA.sinc(${n(e[0])})`,FresnelS:(e,n)=>`_IA.fresnelS(${n(e[0])})`,FresnelC:(e,n)=>`_IA.fresnelC(${n(e[0])})`,Factorial:(e,n)=>`_IA.factorial(${n(e[0])})`,Factorial2:(e,n)=>`_IA.factorial2(${n(e[0])})`,Gamma:(e,n)=>`_IA.gamma(${n(e[0])})`,GammaLn:(e,n)=>`_IA.gammaln(${n(e[0])})`,Binomial:(e,n)=>`_IA.binomial(${n(e[0])}, ${n(e[1])})`,GCD:(e,n)=>`_IA.gcd(${n(e[0])}, ${n(e[1])})`,LCM:(e,n)=>`_IA.lcm(${n(e[0])}, ${n(e[1])})`,Chop:(e,n)=>`_IA.chop(${n(e[0])})`,Erf:(e,n)=>`_IA.erf(${n(e[0])})`,Erfc:(e,n)=>`_IA.erfc(${n(e[0])})`,Exp2:(e,n)=>`_IA.exp2(${n(e[0])})`,Arctan2:(e,n)=>`_IA.atan2(${n(e[0])}, ${n(e[1])})`,Hypot:(e,n)=>`_IA.hypot(${n(e[0])}, ${n(e[1])})`,Fract:(e,n)=>`_IA.fract(${n(e[0])})`,Truncate:(e,n)=>`_IA.trunc(${n(e[0])})`,Mod:(e,n)=>`_IA.mod(${n(e[0])}, ${n(e[1])})`,Remainder:(e,n)=>`_IA.remainder(${n(e[0])}, ${n(e[1])})`,Sum:(e,n,t)=>ql("Sum",e,n,t),Product:(e,n,t)=>ql("Product",e,n,t),If:(e,n)=>{if(e.length!==3)throw new Error("If: wrong number of arguments");return`_IA.piecewise(
1323
1371
  ${n(e[0])},
1324
1372
  () => ${n(e[1])},
1325
1373
  () => ${n(e[2])}
1326
- )`},Which:(e,n)=>{if(e.length<2||e.length%2!==0)throw new Error("Which: expected even number of arguments (condition/value pairs)");let t=i=>{if(i>=e.length)return"{ kind: 'empty' }";let r=e[i],s=e[i+1];return k(r,"True")?n(s):`_IA.piecewise(
1374
+ )`},Which:(e,n)=>{if(e.length<2||e.length%2!==0)throw new Error("Which: expected even number of arguments (condition/value pairs)");let t=i=>{if(i>=e.length)return"{ kind: 'empty' }";let r=e[i],s=e[i+1];return T(r,"True")?n(s):`_IA.piecewise(
1327
1375
  ${n(r)},
1328
1376
  () => ${n(s)},
1329
1377
  () => ${t(i+2)}
1330
- )`};return t(0)},Equal:(e,n)=>`_IA.equal(${n(e[0])}, ${n(e[1])})`,NotEqual:(e,n)=>`_IA.notEqual(${n(e[0])}, ${n(e[1])})`,LessEqual:(e,n)=>`_IA.lessEqual(${n(e[0])}, ${n(e[1])})`,GreaterEqual:(e,n)=>`_IA.greaterEqual(${n(e[0])}, ${n(e[1])})`,Less:(e,n)=>`_IA.less(${n(e[0])}, ${n(e[1])})`,Greater:(e,n)=>`_IA.greater(${n(e[0])}, ${n(e[1])})`,And:(e,n)=>`_IA.and(${n(e[0])}, ${n(e[1])})`,Or:(e,n)=>`_IA.or(${n(e[0])}, ${n(e[1])})`,Not:(e,n)=>`_IA.not(${n(e[0])})`},Rp=100;function Dp(e){e.operator;let n=e,t=k(n.op1)?n.op1.symbol:"_",i=n.op2,r=n.op3,s=i.re,o=r.re;return{index:t,lowerExpr:i,upperExpr:r,lowerNum:!isNaN(s)&&Number.isFinite(s)?Math.floor(s):void 0,upperNum:!isNaN(o)&&Number.isFinite(o)?Math.floor(o):void 0}}function Ku(e,n,t){return n!==void 0?String(n):`Math.floor((${g.compile(e,t)}).hi)`}function el(e,n,t,i){if(!n[0])throw new Error(`${e}: no body`);if(!n[1])throw new Error(`${e}: no indexing set`);let{index:r,lowerExpr:s,upperExpr:o,lowerNum:a,upperNum:u}=Dp(n[1]),l=e==="Sum",c=l?"_IA.add":"_IA.mul",f=l?"_IA.point(0)":"_IA.point(1)",m=a!==void 0&&u!==void 0;if(m&&a>u)return f;if(m&&u-a+1<=Rp){let C=[];for(let V=a;V<=u;V++){let U={...i,var:L=>L===r?`_IA.point(${V})`:i.var(L)};C.push(g.compile(n[0],U))}let F=C[C.length-1];for(let V=C.length-2;V>=0;V--)F=`${c}(${C[V]}, ${F})`;return F}let d=Ku(s,a,i),b=Ku(o,u,i),v=g.tempVar(),T=g.compile(n[0],{...i,var:M=>M===r?`_IA.point(${r})`:i.var(M)});return`(() => { let ${v} = ${f}; const _upper = ${b}; for (let ${r} = ${d}; ${r} <= _upper; ${r}++) { ${v} = ${c}(${v}, ${T}); } return ${v}; })()`}var qs=class extends Function{IA=Qu;constructor(n,t=""){return super("_IA","_",t?`${t};return ${n}`:`return ${n}`),new Proxy(this,{apply:(i,r,s)=>{try{let o=s.map(tl);return super.apply(r,[this.IA,...o])}catch{return{kind:"entire"}}},get:(i,r)=>r==="toString"?()=>n:r==="isCompiled"?!0:i[r]})}};function nl(e){return e!==null&&typeof e=="object"}function Pp(e){return nl(e)&&"lo"in e&&"hi"in e}function tl(e){if(e==null||Pp(e))return e;if(nl(e)){let n={};for(let[t,i]of Object.entries(e))n[t]=tl(i);return n}return typeof e=="number"?{lo:e,hi:e}:e}var Ti=class{getOperators(){return Cp}getFunctions(){return Js}createTarget(n={}){return{language:"interval-javascript",operators:()=>{},functions:t=>Js[t],var:t=>({Pi:"_IA.point(Math.PI)",ExponentialE:"_IA.point(Math.E)",NaN:"{ lo: NaN, hi: NaN }",ImaginaryUnit:"{ lo: NaN, hi: NaN }",Half:"_IA.point(0.5)",MachineEpsilon:"_IA.point(Number.EPSILON)",GoldenRatio:"_IA.point((1 + Math.sqrt(5)) / 2)",CatalanConstant:"_IA.point(0.91596559417721901)",EulerGamma:"_IA.point(0.57721566490153286)"})[t],string:t=>JSON.stringify(t),number:t=>`_IA.point(${t})`,indent:0,ws:t=>t??"",preamble:"",...n}}compile(n,t={}){let{functions:i,vars:r,preamble:s}=t,o=n.unknowns,a={},u="";if(i)for(let[c,f]of Object.entries(i))typeof f=="function"?(u+=`const ${c} = ${f.toString()};
1331
- `,a[c]=c):typeof f=="string"&&(a[c]=f);let l=this.createTarget({functions:c=>a?.[c]?a[c]:Js[c],var:c=>{if(r&&c in r)return r[c];let f={Pi:"_IA.point(Math.PI)",ExponentialE:"_IA.point(Math.E)",NaN:"{ lo: NaN, hi: NaN }",ImaginaryUnit:"{ lo: NaN, hi: NaN }",Half:"_IA.point(0.5)",MachineEpsilon:"_IA.point(Number.EPSILON)",GoldenRatio:"_IA.point((1 + Math.sqrt(5)) / 2)",CatalanConstant:"_IA.point(0.91596559417721901)",EulerGamma:"_IA.point(0.57721566490153286)"};if(c in f)return f[c];if(o.includes(c))return`_.${c}`},preamble:(s??"")+u});return Fp(n,l)}};function Fp(e,n){let t;try{t=g.compile(e,n)}catch{return{target:"interval-js",success:!1,code:""}}let i=new qs(t,n.preamble);return{target:"interval-js",success:!0,code:t,calling:"expression",run:i}}var Lp="0.58.0";return ul(Op);})();
1378
+ )`};return t(0)},Equal:(e,n)=>`_IA.equal(${n(e[0])}, ${n(e[1])})`,NotEqual:(e,n)=>`_IA.notEqual(${n(e[0])}, ${n(e[1])})`,LessEqual:(e,n)=>`_IA.lessEqual(${n(e[0])}, ${n(e[1])})`,GreaterEqual:(e,n)=>`_IA.greaterEqual(${n(e[0])}, ${n(e[1])})`,Less:(e,n)=>`_IA.less(${n(e[0])}, ${n(e[1])})`,Greater:(e,n)=>`_IA.greater(${n(e[0])}, ${n(e[1])})`,And:(e,n)=>`_IA.and(${n(e[0])}, ${n(e[1])})`,Or:(e,n)=>`_IA.or(${n(e[0])}, ${n(e[1])})`,Not:(e,n)=>`_IA.not(${n(e[0])})`},Fm=100;function Om(e){e.operator;let n=e,t=T(n.op1)?n.op1.symbol:"_",i=n.op2,r=n.op3,s=i.re,o=r.re;return{index:t,lowerExpr:i,upperExpr:r,lowerNum:!isNaN(s)&&Number.isFinite(s)?Math.floor(s):void 0,upperNum:!isNaN(o)&&Number.isFinite(o)?Math.floor(o):void 0}}function Vl(e,n,t){return n!==void 0?String(n):`Math.floor(((_b) => (_b && _b.value ? _b.value.hi : _b.hi))(${b.compile(e,t)}))`}function ql(e,n,t,i){if(!n[0])throw new Error(`${e}: no body`);if(!n[1])throw new Error(`${e}: no indexing set`);let{index:r,lowerExpr:s,upperExpr:o,lowerNum:a,upperNum:u}=Om(n[1]),l=e==="Sum",c=l?"_IA.add":"_IA.mul",f=l?"_IA.point(0)":"_IA.point(1)",d=a!==void 0&&u!==void 0;if(d&&a>u)return f;if(d&&u-a+1<=Fm){let $=[];for(let J=a;J<=u;J++){let H={...i,var:O=>O===r?`_IA.point(${J})`:i.var(O)};$.push(b.compile(n[0],H))}let P=$[$.length-1];for(let J=$.length-2;J>=0;J--)P=`${c}(${$[J]}, ${P})`;return P}let m=Vl(s,a,i),g=Vl(o,u,i),v=b.tempVar(),N=b.compile(n[0],{...i,var:M=>M===r?`_IA.point(${r})`:i.var(M)});return`(() => { let ${v} = ${f}; const _upper = ${g}; for (let ${r} = ${m}; ${r} <= _upper; ${r}++) { ${v} = ${c}(${v}, ${N}); } return ${v}; })()`}var mo=class extends Function{IA=Bl;constructor(n,t=""){return super("_IA","_",t?`${t};return ${n}`:`return ${n}`),new Proxy(this,{apply:(i,r,s)=>{try{let o=s.map(zl);return super.apply(r,[this.IA,...o])}catch{return{kind:"entire"}}},get:(i,r)=>r==="toString"?()=>n:r==="isCompiled"?!0:i[r]})}};function Jl(e){return e!==null&&typeof e=="object"}function Lm(e){return Jl(e)&&"lo"in e&&"hi"in e}function zl(e){if(e==null||Lm(e))return e;if(Jl(e)){let n={};for(let[t,i]of Object.entries(e))n[t]=zl(i);return n}return typeof e=="number"?{lo:e,hi:e}:e}var Pi=class{getOperators(){return Pm}getFunctions(){return po}createTarget(n={}){return{language:"interval-javascript",operators:()=>{},functions:t=>po[t],var:t=>({Pi:"_IA.point(Math.PI)",ExponentialE:"_IA.point(Math.E)",NaN:"{ lo: NaN, hi: NaN }",ImaginaryUnit:"{ lo: NaN, hi: NaN }",Half:"_IA.point(0.5)",MachineEpsilon:"_IA.point(Number.EPSILON)",GoldenRatio:"_IA.point((1 + Math.sqrt(5)) / 2)",CatalanConstant:"_IA.point(0.91596559417721901)",EulerGamma:"_IA.point(0.57721566490153286)"})[t],string:t=>JSON.stringify(t),number:t=>`_IA.point(${t})`,indent:0,ws:t=>t??"",preamble:"",...n}}compile(n,t={}){let{functions:i,vars:r,preamble:s}=t,o=n.unknowns,a={},u="";if(i)for(let[c,f]of Object.entries(i))typeof f=="function"?(u+=`const ${c} = ${f.toString()};
1379
+ `,a[c]=c):typeof f=="string"&&(a[c]=f);let l=this.createTarget({functions:c=>a?.[c]?a[c]:po[c],var:c=>{if(r&&c in r)return r[c];let f={Pi:"_IA.point(Math.PI)",ExponentialE:"_IA.point(Math.E)",NaN:"{ lo: NaN, hi: NaN }",ImaginaryUnit:"{ lo: NaN, hi: NaN }",Half:"_IA.point(0.5)",MachineEpsilon:"_IA.point(Number.EPSILON)",GoldenRatio:"_IA.point((1 + Math.sqrt(5)) / 2)",CatalanConstant:"_IA.point(0.91596559417721901)",EulerGamma:"_IA.point(0.57721566490153286)"};if(c in f)return f[c];if(o.includes(c))return`_.${c}`},preamble:(s??"")+u});return Bm(n,l)}};function Bm(e,n){let t;try{t=b.compile(e,n)}catch{return{target:"interval-js",success:!1,code:""}}let i=new mo(t,n.preamble);return{target:"interval-js",success:!0,code:t,calling:"expression",run:i}}var Vm="0.59.0";return Yl(qm);})();
1332
1380
  /*! Bundled license information:
1333
1381
 
1334
1382
  complex-esm/dist/src/complex.js: