@cortex-js/compute-engine 0.86.1 → 0.86.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (320) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/esm-min/chunks/{chunk-RF2RDYMF.js → chunk-7WM7O5R7.js} +30 -30
  3. package/dist/esm-min/chunks/{chunk-JBEE4TIQ.js → chunk-S6GEG7AN.js} +1 -1
  4. package/dist/esm-min/compile.js +14 -14
  5. package/dist/esm-min/compute-engine.js +2 -2
  6. package/dist/esm-min/core.js +14 -14
  7. package/dist/esm-min/cortex.js +3 -3
  8. package/dist/esm-min/identities.js +2 -2
  9. package/dist/esm-min/integration-rules.js +3 -3
  10. package/dist/esm-min/interval.js +2 -2
  11. package/dist/esm-min/latex-syntax.js +2 -2
  12. package/dist/esm-min/math-json.js +2 -2
  13. package/dist/esm-min/numerics.js +2 -2
  14. package/dist/types/big-decimal/big-decimal.d.ts +1 -1
  15. package/dist/types/big-decimal/index.d.ts +1 -1
  16. package/dist/types/big-decimal/transcendentals.d.ts +1 -1
  17. package/dist/types/big-decimal/utils.d.ts +1 -1
  18. package/dist/types/common/ansi-codes.d.ts +1 -1
  19. package/dist/types/common/configuration-change.d.ts +1 -1
  20. package/dist/types/common/debug.d.ts +1 -1
  21. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  22. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  23. package/dist/types/common/interruptible.d.ts +1 -1
  24. package/dist/types/common/one-of.d.ts +1 -1
  25. package/dist/types/common/signals.d.ts +1 -1
  26. package/dist/types/common/styled-text.d.ts +1 -1
  27. package/dist/types/common/terminal.d.ts +1 -1
  28. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  29. package/dist/types/common/type/boxed-type.d.ts +1 -1
  30. package/dist/types/common/type/lexer.d.ts +1 -1
  31. package/dist/types/common/type/parse.d.ts +1 -1
  32. package/dist/types/common/type/parser.d.ts +1 -1
  33. package/dist/types/common/type/primitive.d.ts +1 -1
  34. package/dist/types/common/type/reduce.d.ts +1 -1
  35. package/dist/types/common/type/serialize.d.ts +1 -1
  36. package/dist/types/common/type/subtype.d.ts +1 -1
  37. package/dist/types/common/type/type-builder.d.ts +1 -1
  38. package/dist/types/common/type/types.d.ts +1 -1
  39. package/dist/types/common/type/utils.d.ts +1 -1
  40. package/dist/types/common/utils.d.ts +1 -1
  41. package/dist/types/compile.d.ts +1 -1
  42. package/dist/types/compute-engine/assume.d.ts +1 -1
  43. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/conditional-value.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/diophantine.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/exp-to-trig.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/explain-labels.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/explain.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/function-literal.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/match-dispatch.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/modular-arithmetic.d.ts +1 -1
  82. package/dist/types/compute-engine/boxed-expression/multivariate-gcd.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/multivariate-poly.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  87. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  88. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  89. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  90. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  91. package/dist/types/compute-engine/boxed-expression/rule-index.d.ts +1 -1
  92. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  93. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  94. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  95. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  96. package/dist/types/compute-engine/boxed-expression/solve-congruence.d.ts +1 -1
  97. package/dist/types/compute-engine/boxed-expression/solve-domain.d.ts +1 -1
  98. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  99. package/dist/types/compute-engine/boxed-expression/solve-system.d.ts +1 -1
  100. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  101. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  102. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  103. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  104. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  105. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  106. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  107. package/dist/types/compute-engine/compilation/angular-unit.d.ts +1 -1
  108. package/dist/types/compute-engine/compilation/base-compiler.d.ts +18 -1
  109. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  110. package/dist/types/compute-engine/compilation/constant-folding.d.ts +1 -1
  111. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  112. package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -1
  113. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  114. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  115. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  116. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  117. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  118. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  119. package/dist/types/compute-engine/differential-equation-utils.d.ts +1 -1
  120. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  121. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  122. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  123. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  124. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  125. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  126. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  127. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  128. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  129. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  130. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  131. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  132. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  133. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  134. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  135. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  136. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  137. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  138. package/dist/types/compute-engine/function-properties/index.d.ts +1 -1
  139. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  140. package/dist/types/compute-engine/fungrim/loader.d.ts +1 -1
  141. package/dist/types/compute-engine/fungrim/types.d.ts +1 -1
  142. package/dist/types/compute-engine/global-types.d.ts +1 -1
  143. package/dist/types/compute-engine/index.d.ts +1 -1
  144. package/dist/types/compute-engine/interpret-oeis.d.ts +1 -1
  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 +1 -1
  148. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  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 +1 -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 +1 -1
  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 -1
  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 +1 -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/distributions.d.ts +1 -1
  190. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  191. package/dist/types/compute-engine/library/library.d.ts +1 -1
  192. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  193. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  194. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  195. package/dist/types/compute-engine/library/measurement-arithmetic.d.ts +1 -1
  196. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  197. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  198. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  199. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  200. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  201. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  202. package/dist/types/compute-engine/library/special-functions.d.ts +1 -1
  203. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  204. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  205. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  206. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  207. package/dist/types/compute-engine/library/units.d.ts +1 -1
  208. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  209. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  210. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  211. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  212. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  213. package/dist/types/compute-engine/numerics/bernoulli.d.ts +1 -1
  214. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  215. package/dist/types/compute-engine/numerics/complex-esm-augment.d.ts +1 -1
  216. package/dist/types/compute-engine/numerics/differential-equations.d.ts +1 -1
  217. package/dist/types/compute-engine/numerics/diophantine.d.ts +1 -1
  218. package/dist/types/compute-engine/numerics/distributions.d.ts +1 -1
  219. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  220. package/dist/types/compute-engine/numerics/gauss-kronrod.d.ts +1 -1
  221. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  222. package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
  223. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  224. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  225. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  226. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  227. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  228. package/dist/types/compute-engine/numerics/oscillatory-quadrature.d.ts +1 -1
  229. package/dist/types/compute-engine/numerics/polynomial-roots.d.ts +1 -1
  230. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  231. package/dist/types/compute-engine/numerics/random.d.ts +1 -1
  232. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  233. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  234. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  235. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  236. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  237. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  238. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  239. package/dist/types/compute-engine/oeis.d.ts +1 -1
  240. package/dist/types/compute-engine/rubi/compile.d.ts +1 -1
  241. package/dist/types/compute-engine/rubi/driver.d.ts +1 -1
  242. package/dist/types/compute-engine/rubi/explain-trace.d.ts +1 -1
  243. package/dist/types/compute-engine/rubi/loader.d.ts +1 -1
  244. package/dist/types/compute-engine/rubi/match.d.ts +1 -1
  245. package/dist/types/compute-engine/rubi/normal-form.d.ts +1 -1
  246. package/dist/types/compute-engine/rubi/rubi-utils.d.ts +1 -1
  247. package/dist/types/compute-engine/rubi/types.d.ts +1 -1
  248. package/dist/types/compute-engine/sequence.d.ts +1 -1
  249. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  250. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  251. package/dist/types/compute-engine/symbolic/differential-equations.d.ts +1 -1
  252. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  253. package/dist/types/compute-engine/symbolic/explain-derivative.d.ts +1 -1
  254. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  255. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  256. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  257. package/dist/types/compute-engine/symbolic/interpret.d.ts +1 -1
  258. package/dist/types/compute-engine/symbolic/limit.d.ts +1 -1
  259. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  260. package/dist/types/compute-engine/symbolic/recurrences.d.ts +1 -1
  261. package/dist/types/compute-engine/symbolic/residue.d.ts +1 -1
  262. package/dist/types/compute-engine/symbolic/series.d.ts +1 -1
  263. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  264. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  265. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  266. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  267. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  268. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  269. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  270. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  271. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  272. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  273. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  274. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  275. package/dist/types/compute-engine/symbolic/solver-utils.d.ts +1 -1
  276. package/dist/types/compute-engine/symbolic/trig-rewrite.d.ts +1 -1
  277. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  278. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  279. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  280. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  281. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  282. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  283. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  284. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  285. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  286. package/dist/types/compute-engine/types.d.ts +1 -1
  287. package/dist/types/compute-engine.d.ts +1 -1
  288. package/dist/types/core.d.ts +1 -1
  289. package/dist/types/cortex/characters.d.ts +1 -1
  290. package/dist/types/cortex/diagnostics.d.ts +1 -1
  291. package/dist/types/cortex/execute-cortex.d.ts +1 -1
  292. package/dist/types/cortex/formatter.d.ts +1 -1
  293. package/dist/types/cortex/lexer.d.ts +1 -1
  294. package/dist/types/cortex/operators.d.ts +1 -1
  295. package/dist/types/cortex/parse-cortex.d.ts +1 -1
  296. package/dist/types/cortex/parser.d.ts +1 -1
  297. package/dist/types/cortex/reserved-words.d.ts +1 -1
  298. package/dist/types/cortex/serialize-cortex.d.ts +1 -1
  299. package/dist/types/cortex/tokens.d.ts +1 -1
  300. package/dist/types/cortex.d.ts +2 -2
  301. package/dist/types/identities.d.ts +1 -1
  302. package/dist/types/integration-rules.d.ts +1 -1
  303. package/dist/types/interval.d.ts +1 -1
  304. package/dist/types/latex-syntax.d.ts +2 -2
  305. package/dist/types/math-json/symbols.d.ts +1 -1
  306. package/dist/types/math-json/types.d.ts +1 -1
  307. package/dist/types/math-json/utils.d.ts +1 -1
  308. package/dist/types/math-json.d.ts +2 -2
  309. package/dist/types/numerics.d.ts +1 -1
  310. package/dist/umd-min/compile.cjs +14 -14
  311. package/dist/umd-min/compute-engine.cjs +14 -14
  312. package/dist/umd-min/core.cjs +14 -14
  313. package/dist/umd-min/cortex.cjs +15 -15
  314. package/dist/umd-min/identities.cjs +2 -2
  315. package/dist/umd-min/integration-rules.cjs +2 -2
  316. package/dist/umd-min/interval.cjs +2 -2
  317. package/dist/umd-min/latex-syntax.cjs +2 -2
  318. package/dist/umd-min/math-json.cjs +2 -2
  319. package/dist/umd-min/numerics.cjs +2 -2
  320. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
- /** Compute Engine 0.86.1 */
1
+ /** Compute Engine 0.86.2 */
2
2
  function x(e){return{kind:"interval",value:e}}function ot(e){return{lo:e,hi:e}}function W(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 Be(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=In(r,s);return{kind:"partial",value:o,domainClipped:a}}return{kind:"interval",value:o}}function In(e,n){return e==="both"||n==="both"?"both":e===null?n:n===null||e===n?e:"both"}function at(e){return e.lo===e.hi}function K(e){return e.lo<=0&&e.hi>=0}function ut(e){return e.lo>0}function Qe(e){return e.hi<0}function lt(e){return e.lo>=0}function ct(e){return e.hi<=0}function ft(e){return e.hi-e.lo}function pt(e){return(e.lo+e.hi)/2}function mt(e){if(e.kind==="interval"||e.kind==="partial")return e.value}function dt(e){return"kind"in e?e.kind==="interval"||e.kind==="partial"?e.value:void 0:e}function T(...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 ht(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return x({lo:i.lo+r.lo,hi:i.hi+r.hi})}function en(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return x({lo:i.lo-r.hi,hi:i.hi-r.lo})}function bt(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:-t.hi,hi:-t.lo})}function yt(e,n){let t=[gt(e.lo,n.lo),gt(e.lo,n.hi),gt(e.hi,n.lo),gt(e.hi,n.hi)];return{lo:Math.min(...t),hi:Math.max(...t)}}function gt(e,n){return e===0||n===0?0:e*n}function nn(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return x(yt(i,r))}function Q(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return yu(i,r)}function yu(e,n){return n.lo>0||n.hi<0?x(yt(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"}}var Ps=new Map,xu=1e5;function D(e){if(e<=xu){let n=Ps.get(e);return n===void 0&&(n=10n**BigInt(e),Ps.set(e,n)),n}return 10n**BigInt(e)}function be(e){if(e<0n&&(e=-e),e===0n)return 0;let n=0,t=1;for(;e>>BigInt(t)>0n;)t*=2;for(let i=t>>1;i>=1;i>>=1)e>>BigInt(i)>0n&&(n+=i,e>>=BigInt(i));return n+1}function _s(e,n,t){return e*n>>BigInt(t)}function Rs(e,n,t){return(e<<BigInt(t))/n}function Et(e,n){if(e===0n)return 0n;if(e<0n)throw new RangeError("fpsqrt: negative input");let t=e<<BigInt(n),i;if(n<Nu){i=dr(t);let a;do a=i,i=(i+t/i)/2n;while(se(i-a)>1n)}else i=gr(t,be(t));let r=(i+t/i)/2n,s=se(i*i-t);return se(r*r-t)<s?r:i}function dr(e){let n=be(e);if(n<=1023){let o=Math.sqrt(Number(e));if(Number.isFinite(o)&&o>=1)return BigInt(Math.floor(o))}let t=n-52,i=Number(e>>BigInt(t)),r=Math.sqrt(i);t&1&&(r*=Math.SQRT2);let s=BigInt(Math.round(r))<<BigInt(t>>1);return s>0n?s:1n}var Cs=1024,Nu=640;function gr(e,n){if(n<Cs){let s=dr(e),o;do o=s,s=(s+e/s)/2n;while(se(s-o)>1n);for(;s*s>e;)s-=1n;for(;(s+1n)*(s+1n)<=e;)s+=1n;return s}let t=n>>2<<1,i=gr(e>>BigInt(t),n-t)<<BigInt(t>>1),r;do r=i,i=(i+e/i)/2n;while(se(i-r)>1n);for(;i*i>e;)i-=1n;for(;(i+1n)*(i+1n)<=e;)i+=1n;return i}function se(e){return e<0n?-e:e}function rn(e){if(e===0n)return 1;if(e<0n&&(e=-e),e<0x20000000000000n){let i=Number(e);return i<1e8?i<1e4?i<100?i<10?1:2:i<1e3?3:4:i<1e6?i<1e5?5:6:i<1e7?7:8:i<1e12?i<1e10?i<1e9?9:10:i<1e11?11:12:i<1e14?i<1e13?13:14:i<1e15?15:16}let n=e.toString(16).length*4,t=Math.ceil(n*.30102999566398);for(;e<D(t-1);)t--;for(;e>=D(t);)t++;return t}var Eu=.7;function hr(e,n){if(e===0n)return 1n<<BigInt(n);let t=Math.round(Eu*Math.sqrt(n)),i=t+8,r=n+i,s=BigInt(r),o=1n<<s,a=BigInt(i),u=e<<a,l=u<0n,f=l?-u:u,p=Math.max(0,be(f)-r+t);f>>=BigInt(p),u=l?-f:f;let g=o,h=u;g+=h;for(let N=2;h=(h*u>>s)/BigInt(N),h!==0n;N++)g+=h;for(let N=0;N<p;N++)g=g*g>>s;return g+(1n<<a-1n)>>a}var Tu=4e4;function br(e,n){let t=1n<<BigInt(n);if(e<=0n)throw new RangeError("fpln: input must be positive");return e===t?0n:n>=Tu?Mu(e,n):vu(e,n)}function vu(e,n){let t=BigInt(n),i=1n<<t,r=52,s=n-r,o;if(s>0){let N=Number(e>>BigInt(s))/2**r;o=BigInt(Math.round(Math.log(N)*2**r))<<BigInt(s)}else{let N=Number(e)/Number(i);o=BigInt(Math.round(Math.log(N)*Number(i)))}let a=e*hr(-o,n)>>t,l=(a-i<<t)/(a+i),f=l<0n?-l:l,p=f*f>>t,g=f,h=f;for(let N=3n;g=g*p>>t,g!==0n;N+=2n)h+=g/N;return o+(l<0n?-2n:2n)*h}var Oe=null;function Iu(e){if(Oe!==null){if(Oe.bits===e)return Oe.value;if(Oe.bits>e)return Oe.value>>BigInt(Oe.bits-e)}let n=Math.ceil(e*Tt)+12,t;if(n<=Ds.length){let i=Ds.slice(0,n);t=(BigInt(i)<<BigInt(e))/D(i.length)}else t=Du(e);return Oe={bits:e,value:t},t}function Mu(e,n){let t=BigInt(n),i=be(e)-n,r=Math.max(2,Math.ceil(n/2+4-i)),s=e<<BigInt(r-2),o=1n<<t,a=s;for(;se(o-a)>1n;){let l=o+a>>1n;a=kn(o*a),o=l}return Nt(n)*s/(2n*o)-BigInt(r)*Iu(n)}var tn="314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635",Tt=Math.log10(2),Ds="693147180559945309417232121458176568075500134360255254120680009493393621969694715605863326996418687542001481020570685733685520235758130557032670751635075961930727570828371435190307038623891673471123350115364497955239120475172681574932065155524734139525882950453007095326366642654104239157814952043740430385500801944170641671518644712839968171784546957026271631064546150257207402481637773389638550695260668341137273873722928956493547025762652098859693201965058554764703306793654432547632744951250406069438147104689946506220167720424524529612687946546193165174681392672504103802546259656869144192871608293803172714367782654877566485085674077648451464439940461422603193096735402574446070308096085047486638523138181676751438667476647890881437141985494231519973548803751658612753529166100071053558249879414729509293113897155998205654392871700072180857610252368892132449713893203784393530887748259701715591070882368362758984258918535302436342143670611892367891923723146723217205340164925687274778234453534764811494186423867767744060695626573796008670762571991847340226514628379048830620330611446300737194890027436439650025809365194430411911506080948793067865158870900605203468429736193841289652556539686022194122924207574321757489097706752687115817051137009158942665478595964890653058460258668382940022833005382074005677053046787001841624044188332327983863490015631218895606505531512721993983320307514084260914790012651682434438935724727882054862715527418772430024897945401961872339808608316648114909306675193393128904316413706813977764981769748689038877899912965036192707108892641052309247839173735012298424204995689359922066022046549415106139187885744245577510206837030866619480896412186807790208181588580001688115973056186676199187395200766719214592236720602539595436541655311295175989940056000366513567569051245926825743946483168332624901803824240824231452306140963805700702551387702681785163069025513703234053802145019015374029509942262995779647427138157363801729873940704242179972266962979939312706935747240493386530879758721699645129446491883771156701678598804981838896784134938314014073166472765327635919233511233389338709513209059272185471328975470797891384445466676192702885533423429899321803769154973340267546758873236778342916191810430116091695265547859732891763545556742863877463987101912431754255888301206779210280341206879759143081283307230300883494705792496591005860012341561757413272465943",ku=13591409n,Su=545140134n,wu=10939058860032000n,Au=47.11;function xt(e,n){if(n-e===1){let l,f;if(e===0)l=1n,f=1n;else{l=BigInt(6*e-5)*BigInt(2*e-1)*BigInt(6*e-1);let g=BigInt(e);f=g*g*g*wu}let p=l*(ku+Su*BigInt(e));return e&1&&(p=-p),[l,f,p]}let t=e+n>>1,[i,r,s]=xt(e,t),[o,a,u]=xt(t,n);return[i*o,r*a,a*s+i*u]}function Bs(e){return Math.max(2,Math.floor(e/Au)+3)}function Pu(e){let[,n,t]=xt(0,Bs(e)),i=1n<<BigInt(e),r=kn(10005n*i*i);return n*426880n*r/t}function Os(e){let[,n,t]=xt(0,Bs(Math.ceil(e/Tt))),i=D(e),r=kn(10005n*i*i);return n*426880n*r/t}function mr(e,n){if(n-e===1){let l=e===0?1n:BigInt(2*e-1),f=e===0?1n:9n*BigInt(2*e+1);return[l,f,l]}let t=e+n>>1,[i,r,s]=mr(e,t),[o,a,u]=mr(t,n);return[i*o,r*a,a*s+i*u]}function Du(e){let n=Math.max(2,Math.ceil(e/3.169925)+5),[,t,i]=mr(0,n);return(i<<BigInt(e+1))/(3n*t)}function kn(e){if(e<0n)throw new RangeError("bigintSqrt: negative input");if(e===0n)return 0n;let n=be(e);if(n>=Cs)return gr(e,n);let t=dr(e),i;do i=t,t=(t+e/t)/2n;while(se(t-i)>1n);for(;t*t>e;)t-=1n;for(;(t+1n)*(t+1n)<=e;)t+=1n;return t}var Fe=null;function Nt(e){if(Fe!==null){if(Fe.bits===e)return Fe.value;if(Fe.bits>e)return Fe.value>>BigInt(Fe.bits-e)}let n=_u(e);return Fe={bits:e,value:n},n}function _u(e){let n=Math.ceil(e*Tt)+12;if(n+1<=tn.length){let t=tn.slice(0,n+1);return(BigInt(t)<<BigInt(e))/D(t.length-1)}return Pu(e)}function vt(e,n){let t=BigInt(n),i=1n<<t;if(e===0n)return[0n,i];let r=Nt(n),s=2n*r,o=r/2n,a,u=se(e);if(u>i<<30n){let J=be(u)-n+64,Xe=n+J,Ke=e<<BigInt(J),As=2n*Nt(Xe),pr=Ke%As;pr<0n&&(pr+=As),a=pr>>BigInt(J)}else a=e%s;a<0n&&(a+=s);let l=1n,f=1n;a>3n*o?(a=s-a,l=-1n):a>r?(a=a-r,l=-1n,f=-1n):a>o&&(a=r-a,f=-1n);let p=Math.round(n*Tt),g=Math.min(18,Math.max(2,Math.ceil(.87*Math.sqrt(p)))),h=0,N=i>>BigInt(g);for(;a>N;)a=a/2n,h++;let I=a,F=i,B=a,q=i,H=a*a,U=2n*t;for(let J=2;;J+=2){if(q=(q*H>>U)/(BigInt(J)*BigInt(J-1)),q===0n){B=(B*H>>U)/(BigInt(J+1)*BigInt(J)),B!==0n&&(J%4===2?(F-=q,I-=B):(F+=q,I+=B));break}if(B=(B*H>>U)/(BigInt(J+1)*BigInt(J)),J%4===2?(F-=q,I-=B):(F+=q,I+=B),B===0n)break}for(let J=0;J<h;J++){let Xe=2n*I*F>>t,Ke=(2n*F*F>>t)-i;I=Xe,F=Ke}return[l*I,f*F]}function Mn(e,n){if(e===0n)return 0n;if(e<0n)return-Mn(-e,n);let t=BigInt(n),i=1n<<t,s=Nt(n)/2n;if(e>i){let h=(i<<t)/e;return s-Mn(h,n)}let o=4n*i/10n,a=0,u=e;for(;u>o;){let h=u*u,N=(i<<t)+h>>t,I=Et(N,n);u=(u<<t)/(i+I),a++}let l=u,f=u,p=u*u,g=2n*t;for(let h=3;f=f*p>>g,f!==0n;h+=2)h%4===3?l-=f/BigInt(h):l+=f/BigInt(h);for(let h=0;h<a;h++)l=2n*l;return l}var yr=NaN,m=class e{static precision=50;static ZERO=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:0n,exponent:0}));static ONE=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:1n,exponent:0}));static TWO=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:2n,exponent:0}));static NEGATIVE_ONE=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:-1n,exponent:0}));static HALF=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:5n,exponent:-1}));static NAN=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:0n,exponent:NaN}));static POSITIVE_INFINITY=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:1n,exponent:1/0}));static NEGATIVE_INFINITY=Object.freeze(Object.assign(Object.create(e.prototype),{_digits:1,significand:-1n,exponent:1/0}));static _piFullPrecision=null;static _piCache=null;static _piCachePrecision=0;static _eulerGammaCache=null;static _eulerGammaCachePrecision=0;static get PI(){let n=e.precision;if(e._piCache!==null&&e._piCachePrecision===n)return e._piCache;let t=n+4,i;if(t+1<=tn.length)e._piFullPrecision===null&&(e._piFullPrecision=new e(tn[0]+"."+tn.slice(1))),i=e._piFullPrecision.toPrecision(t);else{let r=t+4;i=_(Os(r),-r).toPrecision(t)}return e._piCache=i,e._piCachePrecision=n,i}static get EULER_GAMMA(){let n=e.precision;if(e._eulerGammaCache!==null&&e._eulerGammaCachePrecision>=n)return e._eulerGammaCache.toPrecision(n);let t=Bu(n);return e._eulerGammaCache=t,e._eulerGammaCachePrecision=n,t}significand;exponent;_digits;digitCount(){return this._digits??(this._digits=rn(this.significand))}constructor(n){if(n instanceof e){this.significand=n.significand,this.exponent=n.exponent;return}if(typeof n=="bigint"){[this.significand,this.exponent]=It(n,0);return}if(typeof n=="number"){[this.significand,this.exponent]=Ou(n);return}[this.significand,this.exponent]=qs(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 yr;let h=this.exponent;if(Number.isNaN(h))return yr;if(n===0)return this.significand===0n?0:this.significand>0n?1:-1;if(!Number.isFinite(h))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)&&h>=0&&h<=15){let N=this.significand*D(h),I=BigInt(n);return N<I?-1:N>I?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 yr;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=this.digitCount(),a=n.digitCount(),u=o+t,l=a+i;if(u!==l){let h=r>0n?1:-1;return u>l?h:-h}let f=r,p=s,g=Math.abs(t-i);if(g>1e3){let h=o,N=a,I=Math.max(h,N)+1;h<I&&(f=f*D(I-h)),N<I&&(p=p*D(I-N))}else t<i?p=p*D(g):f=f*D(g);return f<p?-1:f>p?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*D(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 _(this.significand+n.significand,t);let o=t-i;return o>0?_(this.significand*D(o)+n.significand,i):_(this.significand+n.significand*D(-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 _(this.significand-n.significand,t);let o=t-i;return o>0?_(this.significand*D(o)-n.significand,i):_(this.significand-n.significand*D(-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 _(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}mulToPrecision(n,t){typeof n=="number"&&(n=new e(n));let i=this.exponent,r=n.exponent,s=this.significand,o=n.significand;if(s!==0n&&o!==0n&&Number.isFinite(i)&&Number.isFinite(r)){let a=s*o,u=i+r,l=this.digitCount()+n.digitCount()-1,p=(a<0n?-a:a)>=D(l)?l+1:l;return p<=t?_(a,u):Fs(a,u).roundToPrecKnownDigits(t,p)}return this.mul(n).toPrecision(t)}neg(){let n=this.significand;return n===0n?this:Number.isFinite(this.exponent)?_(-n,this.exponent):n>0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY}abs(){return this.significand>=0n?this:Number.isFinite(this.exponent)?_(-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(_(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(_(1n,0)):t}return this}round(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=_(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/D(-n);return _(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 _(0n,0);let u=e.precision,l=10,f=this.digitCount(),p=n.digitCount(),g=u+l+Math.max(0,p-f),h=D(g),N=r*h/s,I=t-i-g,F=N<0n?-N:N,B=f+g-p,q=F>=D(B)?B+1:B;return Fs(N,I).roundToPrecKnownDigits(u,q)}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 _(0n,0)}inv(){return _(1n,0).div(this)}divToward(n,t){typeof n=="number"&&(n=new e(n));let i=this.exponent,r=n.exponent,s=this.significand,o=n.significand;if(!Number.isFinite(i)||!Number.isFinite(r)||o===0n||s===0n)return this.div(n);let a=s<0n!=o<0n,u=s<0n?-s:s,l=o<0n?-o:o,f=e.precision,g=f+10+Math.max(0,n.digitCount()-this.digitCount()),h=u*D(g),N=h/l,I=h%l!==0n,F=i-r-g,B=this.digitCount()+g-n.digitCount(),q=N>=D(B)?B+1:B,H=a?t==="floor":t==="ceiling",[U,J]=Js(N,I,F,f,H,q);return _(a?-U:U,J)}sqrtToward(n){if(this.significand===0n)return this.exponent!==this.exponent?this:e.ZERO;if(!Number.isFinite(this.exponent))return this.significand>0n?e.POSITIVE_INFINITY:e.NAN;if(this.significand<0n)return e.NAN;let t=e.precision,i=4,r=this.significand,s=this.exponent,o=s+this.digitCount()-1,a=Math.floor(o/2),u=t+i-a;s+2*u<0&&(u=Math.ceil(-s/2)+1);let l=s+2*u,f=l>=0?r*D(l):r/D(-l),p=kn(f),g=p*p!==f,[h,N]=Js(p,g,-u,t,n==="ceiling");return _(h,N)}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 _(0n,0);let r=t-i,s=r>=0?this.significand*D(r):this.significand,o=r>=0?n.significand:n.significand*D(-r),a=s/o;return this.sub(_(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 a=n.toBigInt();if(a===0n)return _(1n,0);if(!this.isFinite())return a>0n?this.significand<0n&&a%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY:_(0n,0);if(this.isZero())return a>0n?_(0n,0):e.POSITIVE_INFINITY;if(a<0n)return this.pow(n.neg()).inv();let u=this.significand<0n?-this.significand:this.significand,l=this.digitCount(),f=l>15?l-15:0,p=f>0?Number(u/10n**BigInt(f)):Number(u),g=Math.log10(p)+f+this.exponent,h=Number(a)*g;if(h>9e15)return this.significand<0n&&a%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY;if(h<-9e15)return _(0n,0);let N=e.precision,I=a.toString(2).length,F=Math.min(2*I+5,100),B=N+F,q=_(1n,0),H=this,U=a;for(;U>0n;)U&1n&&(q=q.mulToPrecision(H,B)),U>>=1n,U>0n&&(H=H.mulToPrecision(H,B));return q.toPrecision(N)}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.exponent+this.digitCount()-1,r=n.exponent+n.digitCount()-1+Math.log10(Math.abs(t)*2.303+3)+1,s=Math.min(20,Math.max(2,Math.ceil(r)+2)),o=e.precision;e.precision=o+s;try{let a=Cu(this,o+s);return n.mul(a).exp().toPrecision(o)}finally{e.precision=o}}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,a;if(s>=0)a=r===0n,o=a?"0":r.toString()+"0".repeat(s);else{let p=D(-s),g=r/p,h=r%p,N=p/2n,I;h>N?I=g+1n:h<N||p%2n!==0n||g%2n===0n?I=g:I=g+1n,a=I===0n,o=I.toString()}let u=i&&!a?"-":"";if(t===0)return`${u}${o}`;if(o.length<=t){let p=o.padStart(t,"0");return`${u}0.${p}`}let l=o.slice(0,o.length-t),f=o.slice(o.length-t);return`${u}${l}.${f}`}toPrecision(n){if(this.significand===0n||!Number.isFinite(this.exponent))return this;let t=this.digitCount();return t<=n?this:this.roundToPrecKnownDigits(n,t)}roundToPrecKnownDigits(n,t){let i=this.significand<0n?-this.significand:this.significand,r=t-n,s=D(r),o=i/s,a=i-o*s,u=s/2n;(a>u||a===u&&o%2n!==0n)&&(o+=1n);let l=this.significand<0n?-o:o;return _(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*D(this.exponent);let n=D(-this.exponent);return this.significand/n}},Ru=8,Sn=[];function Cu(e,n){let t=e.significand,i=e.exponent;for(let s=Sn.length-1;s>=0;s--){let o=Sn[s];if(o.prec===n&&o.exp===i&&o.sig===t)return o.ln}let r=e.ln();return Sn.push({sig:t,exp:i,prec:n,ln:r}),Sn.length>Ru&&Sn.shift(),r}function Bu(e){let n=e+20+Math.ceil(Math.log10(e+10)),t=m.precision;m.precision=n;try{let i=Math.ceil(n*Math.LN10/4)+5,r=new m(i),s=r.mul(r),o=m.ONE,a=m.ONE,u=m.ZERO,l=m.ZERO,f=m.ONE.div(new m(10).pow(n)),p=6*i+100;for(let g=1;g<=p;g++){let h=new m(g).mul(g);if(o=o.mul(s).div(h).toPrecision(n),l=l.add(m.ONE.div(g)).toPrecision(n),a=a.add(o).toPrecision(n),u=u.add(o.mul(l)).toPrecision(n),g>i&&o.lt(a.mul(f)))break}return u.div(a).sub(r.ln()).toPrecision(e)}finally{m.precision=t}}function _(e,n){let[t,i]=It(e,n),r=Object.create(m.prototype);return r.significand=t,r.exponent=i,r}function Fs(e,n){let t=Object.create(m.prototype);return t.significand=e,t.exponent=n,t}function Js(e,n,t,i,r,s){if(e===0n)return[r&&n?1n:0n,t];let o=s??rn(e);if(o<=i)return[r&&n?e+1n:e,t];let a=o-i,u=D(a),l=e/u,f=n||e%u!==0n;return r&&f&&(l+=1n),[l,t+a]}var Ls=1000000000n,Vs=1000n;function It(e,n){if(e===0n)return[0n,0];if((e&1n)!==0n)return[e,n];if(e%10n!==0n)return[e,n];for(;e%Ls===0n;)e/=Ls,n+=9;for(;e%Vs===0n;)e/=Vs,n+=3;for(;e%10n===0n;)e/=10n,n+=1;return[e,n]}function Ou(e){return Number.isNaN(e)?[0n,NaN]:e===1/0?[1n,1/0]:e===-1/0?[-1n,1/0]:Number.isInteger(e)?It(BigInt(e),0):qs(e.toString())}function qs(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 f=-a.length;return It(l,f+t)}var Fu=Math.log2(10),Gs=Math.log10(2),Ju=16,Nr=1e6;function ye(e,n){let t=Math.ceil(n*Fu)+Ju,i=BigInt(t);return e.exponent>=0?[e.significand*D(e.exponent)<<i,t]:[(e.significand<<i)/D(-e.exponent),t]}function xe(e,n,t){if(e===0n)return m.ZERO;let i=e<0n,r=i?-e:e,s=BigInt(n),o=be(r)-n,a=Math.floor(o*Gs),u=t+4-a,l,f;if(u>=0)l=r*D(u)+(1n<<s-1n)>>s,f=-u;else{let g=D(-u)<<s;l=(r+g/2n)/g,f=-u}if(l===0n)return m.ZERO;let p=rn(l);if(p>t){let g=p-t,h=D(g),N=h/2n,I=l%h;l=l/h,I>=N&&(l+=1n),f+=g}return _(i?-l:l,f)}function ee(e){return e.exponent+e.digitCount()-1}function xr(e,n){if(e===0n)return 0;let t=e<0n?-e:e,i=n*Gs-(rn(t)-1);return i>0?Math.ceil(i):0}var zs=5,$s=BigInt(Number.MAX_SAFE_INTEGER),Je=null;function Zs(e){if(Je!==null){if(Je.bits===e)return Je.value;if(Je.bits>e)return Je.value>>BigInt(Je.bits-e)}let n=br(10n<<BigInt(e),e);return Je={bits:e,value:n},n}m.prototype.sqrt=function(){if(this.isNaN())return m.NAN;if(this.isZero())return m.ZERO;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NAN;if(this.significand<0n)return m.NAN;let e=m.precision,n=e+10,t=ee(this),i=Math.floor(t/2),r=_(this.significand,this.exponent-2*i),[s,o]=ye(r,n),a=Et(s,o),u=xe(a,o,e);return _(u.significand,u.exponent+i)};m.prototype.cbrt=function(){if(this.isNaN())return m.NAN;if(this.isZero())return m.ZERO;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NEGATIVE_INFINITY;if(this.significand<0n)return this.neg().cbrt().neg();let e=m.precision,n=e+10,t=ee(this),i=Math.floor(t/3),r=_(this.significand,this.exponent-3*i),[s,o]=ye(r,n),a=s<<BigInt(2*o),u,l=r.toNumber();if(o<=1e3&&Number.isFinite(l)&&l>0){let g=Number(1n<<BigInt(o)),h=Math.cbrt(l);Number.isFinite(h)&&h>0?(u=BigInt(Math.floor(h*g)),u===0n&&(u=1n)):u=js(a)}else u=js(a);let f;do{f=u;let g=u*u;if(g===0n){u=1n;break}u=(2n*u+a/g)/3n}while(se(u-f)>1n);{let g=(2n*u+a/(u*u))/3n,h=se(u*u*u-a);se(g*g*g-a)<h&&(u=g)}let p=xe(u,o,e);return _(p.significand,p.exponent+i)};m.sqrt=function(e){return e.sqrt()};m.cbrt=function(e){return e.cbrt()};m.prototype.exp=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.ZERO;if(this.isZero())return m.ONE;if(ee(this)>=17)return this.significand>0n?m.POSITIVE_INFINITY:m.ZERO;let e=m.precision,n=Math.max(0,this.exponent+this.digitCount()),t=e+20+n,[i,r]=ye(this,t),s=Zs(r),o=i/s,a=i-o*s;if(a<0n&&(o-=1n,a+=s),o>$s||o<-$s)return o>0n?m.POSITIVE_INFINITY:m.ZERO;let u=xe(hr(a,r),r,e),l=u.exponent+Number(o);return Number.isSafeInteger(l)?_(u.significand,l):o>0n?m.POSITIVE_INFINITY:m.ZERO};m.prototype.ln=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NAN;if(this.isZero())return m.NEGATIVE_INFINITY;if(this.significand<0n)return m.NAN;if(this.eq(1))return m.ZERO;let e=m.precision,n=this.significand,t=this.digitCount(),i=this.exponent+t-1,r=_(n,-(t-1)),s=Math.abs(i).toString().length,o=0;if(i===0||i===-1){let g=this.sub(m.ONE);if(!g.isZero()){let h=ee(g);h<0&&(o=-h)}}let a=e+20+s+o,[u,l]=ye(r,a),f=Zs(l),p=br(u,l)+BigInt(i)*f;return xe(p,l,e)};m.prototype.log=function(e){let n=e instanceof m?e:new m(e),t=m.precision;m.precision=t+10;try{return this.ln().div(n.ln()).toPrecision(t)}finally{m.precision=t}};m.exp=function(e){return e.exp()};m.ln=function(e){return e.ln()};m.log10=function(e){return e.log(10)};m.log2=function(e){return e.log(2)};m.prototype.sin=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return m.NAN;if(this.isZero())return m.ZERO;let e=m.precision,n=ee(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=e+15+(n<0?-n:0);if(n+t+30>Nr)return m.NAN;let[i,r]=ye(this,t),[s]=vt(i,r);return xe(s,r,e)};m.prototype.cos=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return m.NAN;if(this.isZero())return m.ONE;let e=m.precision,n=ee(this),t=0;for(let i=0;;i++){let r=e+15+t;if(n+r+30>Nr)return m.NAN;let[s,o]=ye(this,r),[,a]=vt(s,o);if(a===0n){if(i>=3)return m.ZERO;t+=e+30;continue}let u=xr(a,o);if(u<=t+zs||i>=3)return xe(a,o,e);t=u+5}};m.prototype.tan=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return m.NAN;if(this.isZero())return m.ZERO;let e=m.precision,n=ee(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=n<0?-n:0,i=0;for(let r=0;;r++){let s=e+15+t+i;if(n+s+30>Nr)return m.NAN;let[o,a]=ye(this,s),[u,l]=vt(o,a);if(l===0n){if(r>=3)return u>0n?m.POSITIVE_INFINITY:m.NEGATIVE_INFINITY;i+=e+30;continue}let f=Math.max(u===0n?0:xr(u,a),xr(l,a));if(f<=i+zs||r>=3){let p=(u<<BigInt(a))/l;return xe(p,a,e)}i=f+5}};m.prototype.atan=function(){if(this.isNaN())return m.NAN;if(this.isZero())return m.ZERO;if(!this.isFinite()){let o=m.PI.div(m.TWO);return this.significand>0n?o:o.neg()}let e=m.precision,n=ee(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=e+15+(n<0?-n:0),[i,r]=ye(this,t),s=Mn(i,r);return xe(s,r,e)};m.prototype.asin=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return m.NAN;if(this.isZero())return m.ZERO;let e=this.abs(),n=m.ONE;if(e.gt(n))return m.NAN;if(e.eq(n)){let h=m.PI.div(m.TWO);return this.significand>0n?h:h.neg()}let t=m.precision,i=ee(this);if(i<0&&-2*i>=t+4)return this.toPrecision(t);let r=t+20+(i<0?-i:0),[s,o]=ye(this,r),a=1n<<BigInt(o),u=_s(s,s,o),l=a-u,f=Et(l,o),p=Rs(s,f,o),g=Mn(p,o);return xe(g,o,t)};m.prototype.acos=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return m.NAN;if(this.abs().gt(m.ONE))return m.NAN;if(this.eq(1))return m.ZERO;if(this.eq(-1))return m.PI;let n=m.precision,t=m.precision;m.precision=n+10;try{let i=m.TWO;if(this.significand>=0n){let s=m.ONE.sub(this).mulToPrecision(m.HALF,n+10).sqrt();return i.mulToPrecision(s.asin(),n)}let r=m.ONE.add(this).mulToPrecision(m.HALF,n+10).sqrt();return m.PI.sub(i.mul(r.asin())).toPrecision(n)}finally{m.precision=t}};m.sin=function(e){return e.sin()};m.cos=function(e){return e.cos()};m.tan=function(e){return e.tan()};m.asin=function(e){return e.asin()};m.acos=function(e){return e.acos()};m.atan=function(e){return e.atan()};m.atan2=function(e,n){let t=e instanceof m?e:new m(e);if(t.isNaN()||n.isNaN())return m.NAN;let i=m.PI,r=i.div(m.TWO);if(n.isZero())return t.isZero()?m.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)};m.prototype.sinh=function(){if(this.isNaN())return m.NAN;if(this.isZero())return m.ZERO;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NEGATIVE_INFINITY;let e=m.precision,n=ee(this);if(n<0){if(-2*n>=e+4)return this.toPrecision(e);let r=m.precision;m.precision=e-n+5;try{let s=this.exp();return s.sub(s.inv()).mulToPrecision(m.HALF,e)}finally{m.precision=r}}if(Math.abs(this.toNumber())>1.16*(e+3)){let r=this.abs().exp().div(m.TWO);return this.significand>0n?r:r.neg()}let t=this.exp(),i=t.inv();return t.sub(i).div(m.TWO)};m.prototype.cosh=function(){if(this.isNaN())return m.NAN;if(this.isZero())return m.ONE;if(!this.isFinite())return m.POSITIVE_INFINITY;let e=m.precision;if(Math.abs(this.toNumber())>1.16*(e+3))return this.abs().exp().div(m.TWO);let n=this.exp(),t=n.inv();return n.add(t).div(m.TWO)};m.prototype.tanh=function(){if(this.isNaN())return m.NAN;if(this.isZero())return m.ZERO;if(!this.isFinite())return this.significand>0n?m.ONE:m.NEGATIVE_ONE;let e=m.precision,n=ee(this);if(n<0){if(-2*n>=e+4)return this.toPrecision(e);let i=m.precision;m.precision=e-n+5;try{let r=this.mul(m.TWO).exp();return r.sub(m.ONE).div(r.add(m.ONE)).toPrecision(e)}finally{m.precision=i}}if(Math.abs(this.toNumber())>1.16*(e+3))return this.significand>0n?m.ONE:m.NEGATIVE_ONE;let t=this.mul(m.TWO).exp();return t.sub(m.ONE).div(t.add(m.ONE))};m.sinh=function(e){return e.sinh()};m.cosh=function(e){return e.cosh()};m.tanh=function(e){return e.tanh()};m.prototype.expm1=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NEGATIVE_ONE;if(this.isZero())return m.ZERO;let e=m.precision,n=ee(this);if(n<0&&-n>=e+2)return this.toPrecision(e);if(n<0){let t=m.precision;m.precision=e-n+5;try{return this.exp().sub(m.ONE).toPrecision(e)}finally{m.precision=t}}return this.exp().sub(m.ONE)};m.prototype.log1p=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NAN;if(this.isZero())return m.ZERO;let e=m.ONE.add(this);if(e.isZero())return m.NEGATIVE_INFINITY;if(e.significand<0n)return m.NAN;let n=m.precision,t=ee(this);if(t<0&&-t>=n+2)return this.toPrecision(n);if(t<0){let i=m.precision;m.precision=n-t+5;try{return m.ONE.add(this).ln().toPrecision(n)}finally{m.precision=i}}return m.ONE.add(this).ln()};m.prototype.asinh=function(){if(this.isNaN())return m.NAN;if(this.isZero())return m.ZERO;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NEGATIVE_INFINITY;let e=this.significand<0n,n=this.abs(),t=m.precision,i=ee(this);if(i<0&&-2*i>=t+4)return this.toPrecision(t);let r=()=>n.add(n.mul(n).add(m.ONE).sqrt()).ln(),s;if(i<0){let o=m.precision;m.precision=t-i+5;try{s=r().toPrecision(t)}finally{m.precision=o}}else s=r();return e?s.neg():s};m.prototype.acosh=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:m.NAN;if(this.lt(m.ONE))return m.NAN;if(this.eq(1))return m.ZERO;let e=this.sub(m.ONE).div(m.TWO).sqrt();return m.TWO.mul(e.asinh())};m.prototype.atanh=function(){if(this.isNaN())return m.NAN;if(!this.isFinite())return m.NAN;if(this.isZero())return m.ZERO;let e=this.abs();if(e.eq(1))return this.significand>0n?m.POSITIVE_INFINITY:m.NEGATIVE_INFINITY;if(e.gt(m.ONE))return m.NAN;let n=m.precision,t=ee(this);if(-2*t>=n+4)return this.toPrecision(n);let i=m.precision;m.precision=n-t+5;try{return m.ONE.add(this).div(m.ONE.sub(this)).ln().mulToPrecision(m.HALF,n)}finally{m.precision=i}};m.prototype.nthRoot=function(e){if(this.isNaN()||!Number.isInteger(e)||e===0)return m.NAN;if(e===1)return this;if(e===2)return this.sqrt();if(e===3)return this.cbrt();if(e<0)return this.nthRoot(-e).inv();if(this.isZero())return m.ZERO;if(!this.isFinite())return this.significand>0n?m.POSITIVE_INFINITY:e%2===0?m.NAN:m.NEGATIVE_INFINITY;if(this.significand<0n)return e%2===0?m.NAN:this.neg().nthRoot(e).neg();let n=m.precision,t=m.precision;m.precision=n+8;try{return m.exp(this.ln().div(new m(e))).toPrecision(n)}finally{m.precision=t}};m.asinh=function(e){return e.asinh()};m.acosh=function(e){return e.acosh()};m.atanh=function(e){return e.atanh()};m.expm1=function(e){return e.expm1()};m.log1p=function(e){return e.log1p()};m.nthRoot=function(e,n){return e.nthRoot(n)};function js(e){let n=be(e);if(n<=1023){let u=Math.cbrt(Number(e));if(Number.isFinite(u)&&u>=1)return BigInt(Math.floor(u))}let t=n-51,i=Number(e>>BigInt(t)),r=Math.cbrt(i),s=Math.floor(t/3),o=t%3;o===1&&(r*=1.2599210498948732),o===2&&(r*=1.5874010519681994);let a=BigInt(Math.round(r))<<BigInt(s);return a>0n?a:1n}var Mt=7,kt=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23];function sn(e){if(e<0)return NaN;if(e===1||e===2)return 0;let n=e-1,t=kt[0];for(let r=1;r<Mt+2;r++)t+=kt[r]/(n+r);let i=n+Mt+.5;return .5*Math.log(2*Math.PI)+(n+.5)*Math.log(i)-i+Math.log(t)}var Lu=171.6243769563027;function Us(e){e-=1;let n=kt[0];for(let i=1;i<Mt+2;i++)n+=kt[i]/(e+i);let t=e+Mt+.5;return Math.sqrt(2*Math.PI)*Math.pow(t,e+.5)*Math.exp(-t)*n}function St(e,n){if(n<=0)return 1;if(n===1)return e;let t=n>>>1;return St(e,t)*St(e+t,n-t)}function ue(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*ue(1-e));if(e>Lu)return 1/0;if(Number.isInteger(e))return St(1,e-1);if(e>=2){let n=Math.floor(e)-1,t=e-n;return Us(t)*St(t,n)}return Us(e)}function At(e){if(Number.isNaN(e))return NaN;if(!Number.isFinite(e))return e>0?0:2;if(e<0)return 2-At(-e);if(e<2)return 1-Pt(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 Pt(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 yp=[1/6,-1/30,1/42,-1/30,5/66,-691/2730,7/6,-3617/510,43867/798,-174611/330];var Vu=[-2991.8191940101983,708840.0452577386,-6297414862058625e-8,25489088057337637e-7,-4429795180596978e-5,3180162978765678e-4],qu=[1,281.3762688899943,45584.78108065326,5173438887700964e-9,4193202458981112e-7,22441179564534092e-6,607366389490085e-3],$u=[-49884311457357354e-24,9504280628298596e-21,-.0006451914356839651,.018884331939670384,-.20552590095501388,1],ju=[399982968972496e-26,9154392157746574e-25,12500186247959882e-23,12226278902417902e-21,.0008680295429417843,.04121420907221998,1],Hs=[.4215435550436775,.1434079197807589,.011522095507358577,.000345017939782574,46361374928786735e-22,3055689837902576e-23,10230451416490724e-26,17201074326816183e-29,13428327623306275e-32,3763297112699879e-35],Ws=[1,.7515863983533789,.11688892585919138,.0064405152650885865,.00015593440916415301,18462756734893055e-22,11269922476399903e-24,36014002958937136e-27,5887545336215784e-29,45200143407412973e-33,12544323709001127e-36],Ys=[.5044420736433832,.1971028335255234,.018764858409257526,.0006840793809153931,11513882611188428e-21,9828524436884223e-23,44534441586175015e-26,10826804113902088e-28,1375554606332618e-30,8363544356306774e-34,18695871016278324e-38],Xs=[1,1.4749575992512833,.33774898912002,.02536037414203388,.0008146791071843061,12754507566772912e-21,10431458965757199e-23,46068072851523205e-26,11027321506624028e-28,13879653125957886e-31,8391588162831187e-34,18695871016278324e-38];function oe(e,n){let t=n[0];for(let i=1;i<n.length;i++)t=t*e+n[i];return t}var Ks=6e15;function Qs(e){let t=134217729*e,i=t-(t-e),r=e-i,s=i*i%4+2*(i*r%2)+r*r%4;return s%=4,s<0&&(s+=4),Math.PI/2*s}function on(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*oe(i,Vu)/oe(i,qu)}if(e<Ks){let t=e*e,i=Math.PI*t,r=1/(i*i),s=1-r*oe(r,Hs)/oe(r,Ws),o=1/i*oe(r,Ys)/oe(r,Xs),a=Qs(e),u=Math.cos(a),l=Math.sin(a);return n*(.5-(s*u+o*l)/(Math.PI*e))}return n*.5}function an(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*oe(i,$u)/oe(i,ju)}if(e<Ks){let t=e*e,i=Math.PI*t,r=1/(i*i),s=1-r*oe(r,Hs)/oe(r,Ws),o=1/i*oe(r,Ys)/oe(r,Xs),a=Qs(e),u=Math.cos(a),l=Math.sin(a);return n*(.5+(s*l-o*u)/(Math.PI*e))}return n*.5}var kp=1n<<32n;var Sp=[BigInt(4),BigInt(2),BigInt(4),BigInt(2),BigInt(4),BigInt(6),BigInt(2),BigInt(6)];var zu=53,eo=Math.floor(Math.log10(Math.pow(2,zu))),Zu=1e-10,Le=1e6;function un(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 Er(e,n){if(e===0||n===0)return 0;let t=BigInt(e)*BigInt(n)/BigInt(un(e,n));return t<0n&&(t=-t),Number(t)}function Tr(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 vr(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 Ir(e,n=Zu){return typeof e=="number"&&Math.abs(e)<=n?0:e}function Uu(e){let n=[];for(let t=0;t<e.length;t++){let i=e.charCodeAt(t);if(i>=55296&&i<=56319){let r=e.charCodeAt(t+1);if(r>=56320&&r<=57343){let s=i-55296,o=r-56320;i=2**16+s*2**10+o,t++}}n.push(i)}return n}var Dt=8205,no=[127462,127487];function to(e){return e===Dt||e===65038||e===65039||e>=127995&&e<=128e3||e>=129456&&e<=129460||e>=917536&&e<=917632}function Hu(e){return e>=no[0]&&e<=no[1]}function io(e){if(/^[\u0020-\u00FF]*$/.test(e))return e;let n=[],t=Uu(e),i=0;for(;i<t.length;){let r=t[i++],s=t[i];if(s===Dt){let o=i-1;for(i+=2;t[i]===Dt;)i+=2;n.push(String.fromCodePoint(...t.slice(o,i)))}else if(to(s)){let o=i-1;for(;to(t[i]);)i+=t[i]===Dt?2:1;n.push(String.fromCodePoint(...t.slice(o,i)))}else Hu(r)?(i+=1,n.push(String.fromCodePoint(...t.slice(i-2,i)))):n.push(String.fromCodePoint(r))}return n}var Wu={"\u2070":"0","\xB9":"1","\xB2":"2","\xB3":"3","\u2074":"4","\u2075":"5","\u2076":"6","\u2077":"7","\u2078":"8","\u2079":"9","\u207B":"-","\u2071":"i",\u207F:"n"},Yu={"\u2080":"0","\u2081":"1","\u2082":"2","\u2083":"3","\u2084":"4","\u2085":"5","\u2086":"6","\u2087":"7","\u2088":"8","\u2089":"9","\u208B":"-"},ro=new Map;function Xu(e){let n=ro.get(e.source);if(!n){let t=e.source.startsWith("^")?e.source.slice(1):e.source;n=new RegExp(t,"y"),ro.set(e.source,n)}return n}var Mr=class{s;pos;joined;offsets=null;obeyspaces=!1;constructor(n){if(n=n.normalize("NFC"),n=n.replace(/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/g,""),n=n.replace(/\u2212/g,"-"),n=n.replace(/[⁰¹²³⁴⁵⁶⁷⁸⁹⁻ⁱⁿ]+/g,t=>`^{${Array.from(t).map(r=>Wu[r]).join("")}}`),n=n.replace(/[₀₁₂₃₄₅₆₇₈₉₋]+/g,t=>`_{${Array.from(t).map(r=>Yu[r]).join("")}}`),this.s=io(n),this.pos=0,typeof this.s=="string")this.joined=this.s;else{this.joined=this.s.join("");let t=new Array(this.s.length+1),i=0;for(let r=0;r<this.s.length;r++)t[r]=i,i+=this.s[r].length;t[this.s.length]=i,this.offsets=t}}end(){return this.pos>=this.s.length}get(){return this.pos<this.s.length?this.s[this.pos++]:""}peek(){return this.s[this.pos]}match(n){let t=Xu(n);typeof this.s=="string"?t.lastIndex=this.pos:t.lastIndex=this.offsets[this.pos<this.s.length?this.pos:this.s.length];let i=t.exec(this.joined);return i?.[0]?(this.pos+=i[0].length,i[0]):null}next(){if(this.end())return null;if(!this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]+/))return"<space>";if(this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]/))return"<space>";let n=this.get();if(n==="\\"){if(!this.end()){let t=this.match(/^[a-zA-Z]+/);if(t)this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]*/);else if(t=this.get(),t===" ")return"<space>";return"\\"+t}}else{if(n==="{")return"<{>";if(n==="}")return"<}>";if(n==="^"){if(this.peek()==="^"){this.get();let t=this.match(/^(\^(\^(\^(\^[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f][0-9a-f]/);if(t)return String.fromCodePoint(parseInt(t.slice(t.lastIndexOf("^")+1),16))}return n}else if(n==="#"){if(!this.end()){let t=!1;if(/[0-9?]/.test(this.peek())&&(t=!0,this.pos+1<this.s.length)){let i=this.s[this.pos+1];t=/[^0-9A-Za-z]/.test(i)}return t?"#"+this.get():"#"}}else if(n==="$")return this.peek()==="$"?(this.get(),"<$$>"):"<$>"}return n}};function Ku(e,n){let t=e.next();if(!t)return[];let i=[];if(t!=="\\relax"){if(t==="\\noexpand")t=e.next(),t&&i.push(t);else if(t==="\\obeyspaces")e.obeyspaces=!0;else if(t==="\\space"||t==="~")i.push("<space>");else if(t==="\\bgroup")i.push("<{>");else if(t==="\\egroup")i.push("<}>");else if(t==="\\string")t=e.next(),t&&(t[0]==="\\"?Array.from(t).forEach(r=>i.push(r==="\\"?"\\backslash":r)):t==="<{>"?i.push("\\{"):t==="<space>"?i.push("~"):t==="<}>"&&i.push("\\}"));else if(t==="\\csname"){let r="",s=!1,o=[];do o.length===0&&(t=e.next(),o=t?[t]:[]),s=o.length===0,!s&&t==="\\endcsname"&&(s=!0,o.shift()),s||(s=t==="<$>"||t==="<$$>"||t==="<{>"||t==="<}>"||!!t&&t.length>1&&t[0]==="\\"),s||(r+=o.shift());while(!s);r&&i.push("\\"+r),i=i.concat(o)}else if(t!=="\\endcsname")if(t.length>1&&t[0]==="#"){let r=t.slice(1),s=n;i=i.concat(ne(s?.[r]??s?.["?"]??"\\placeholder{}",n))}else i.push(t)}return i}function ne(e,n=[],t){let r=e.toString().split(/(\r?\n)/),s="",o="",a=0;for(let f=0;f<r.length;f+=2){let p=r[f],g=r[f+1]??"";s+=o,o=" ";let h=p.match(/((?:\\%)|[^%])*/);if(h!==null&&(s+=h[0],t!==void 0&&h[0].length<p.length)){let N=a+h[0].length,I=a+p.length;t.push({start:N,end:I,discardedLength:p.length-h[0].length})}a+=p.length+g.length}let u=new Mr(s),l=[];do l.push(...Ku(u,n));while(!u.end());return l}function E(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 Ve(e,n,t){return n.includes(e)&&(n=`{${n}}`),/^[0-9]$/.test(t)?`${n}${e}${t}`:`${n}${e}{${t}}`}function ln(e){let n=[];if(Array.isArray(e))for(let i of e)if(Array.isArray(i))for(let r of i)n.push(r);else n.push(i);else n=[e];return E(n.map(i=>({"<space>":" ","<$$>":"$$","<$>":"$","<{>":"{","<}>":"}"})[i]??i))}var S=245,An=260,le=270,O=275,C=390,Y=600,qe=650,Pn=700,$e=810;function _t(e,n){return(t,i,r)=>{let s=t.parseExpression({...r,minPrec:n});return s===null?null:["Not",[e,i,s]]}}var cn=[{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:S+5,parse:"LessEqual"},{latexTrigger:["\u2264"],kind:"infix",associativity:"any",precedence:241,parse:"LessEqual"},{latexTrigger:["\u2265"],kind:"infix",associativity:"any",precedence:242,parse:"GreaterEqual"},{latexTrigger:["\u2260"],kind:"infix",associativity:"right",precedence:255,parse:"NotEqual"},{name:"LessNotEqual",latexTrigger:["\\lneqq"],kind:"infix",associativity:"any",precedence:S},{name:"NotLessNotEqual",latexTrigger:["\\nleqq"],kind:"infix",associativity:"any",precedence:S},{name:"LessOverEqual",latexTrigger:["\\leqq"],kind:"infix",associativity:"any",precedence:S+5},{name:"GreaterOverEqual",latexTrigger:["\\geqq"],kind:"infix",associativity:"any",precedence:S+5,parse:"GreaterEqual"},{name:"Equal",latexTrigger:["="],kind:"infix",associativity:"right",precedence:S},{latexTrigger:["*","="],kind:"infix",associativity:"right",precedence:S,parse:"StarEqual"},{name:"StarEqual",latexTrigger:["\\star","="],kind:"infix",associativity:"right",precedence:S},{name:"PlusEqual",latexTrigger:["+","="],kind:"infix",associativity:"right",precedence:S},{name:"MinusEqual",latexTrigger:["-","="],kind:"infix",associativity:"right",precedence:S},{name:"SlashEqual",latexTrigger:["/","="],kind:"infix",associativity:"right",precedence:S},{latexTrigger:["=","="],kind:"infix",associativity:"right",precedence:S,parse:"Equal"},{name:"EqualEqualEqual",latexTrigger:["=","=","="],kind:"infix",associativity:"right",precedence:S+5},{name:"Tilde",latexTrigger:["\\sim"],kind:"infix",associativity:"right",precedence:S},{name:"NotTilde",latexTrigger:["\\nsim"],kind:"infix",associativity:"right",precedence:S},{name:"TildeEqual",latexTrigger:["\\simeq"],kind:"infix",associativity:"right",precedence:S},{name:"TildeFullEqual",latexTrigger:["\\cong"],kind:"infix",associativity:"right",precedence:S},{name:"NotTildeFullEqual",latexTrigger:["\\ncong"],kind:"infix",associativity:"right",precedence:S},{name:"Approx",latexTrigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{latexTrigger:["\u2248"],kind:"infix",associativity:"right",precedence:247,parse:"Approx"},{name:"NotApprox",latexTrigger:["\\not","\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"ApproxEqual",latexTrigger:["\\approxeq"],kind:"infix",associativity:"right",precedence:S},{name:"NotApproxEqual",latexTrigger:["\\not","\\approxeq"],kind:"infix",associativity:"right",precedence:250},{name:"NotEqual",latexTrigger:["\\ne"],kind:"infix",associativity:"right",precedence:255},{latexTrigger:["\\neq"],kind:"infix",associativity:"right",precedence:255,parse:"NotEqual"},{latexTrigger:["\\not","="],kind:"infix",associativity:"right",precedence:255,parse:"NotEqual"},{latexTrigger:["\\not","\\le"],kind:"infix",associativity:"right",precedence:241,parse:_t("LessEqual",241)},{latexTrigger:["\\not","\\leq"],kind:"infix",associativity:"right",precedence:241,parse:_t("LessEqual",241)},{latexTrigger:["\\not","\\ge"],kind:"infix",associativity:"right",precedence:242,parse:_t("GreaterEqual",242)},{latexTrigger:["\\not","\\geq"],kind:"infix",associativity:"right",precedence:242,parse:_t("GreaterEqual",242)},{name:"Unequal",latexTrigger:["!","="],kind:"infix",associativity:"right",precedence:S,parse:"NotEqual"},{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:S+5,parse:"GreaterEqual"},{name:"GreaterNotEqual",latexTrigger:["\\gneqq"],kind:"infix",associativity:"right",precedence:S},{name:"NotGreaterNotEqual",latexTrigger:["\\ngeqq"],kind:"infix",associativity:"right",precedence:S},{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:S},{name:"TriangleEqual",latexTrigger:["\\triangleq"],kind:"infix",associativity:"right",precedence:S},{name:"DotEqual",latexTrigger:["\\doteq"],kind:"infix",associativity:"right",precedence:S+5},{name:"DotEqualDot",latexTrigger:["\\doteqdot"],kind:"infix",associativity:"right",precedence:S+5},{name:"FallingDotEqual",latexTrigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:S+5},{name:"RisingDotEqual",latexTrigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:S+5},{name:"QuestionEqual",latexTrigger:["\\questeq"],kind:"infix",associativity:"right",precedence:S},{name:"MuchLess",latexTrigger:["\\ll"],kind:"infix",associativity:"right",precedence:S},{name:"MuchGreater",latexTrigger:["\\gg"],kind:"infix",associativity:"right",precedence:S},{name:"Precedes",latexTrigger:["\\prec"],kind:"infix",associativity:"right",precedence:S},{name:"Succeeds",latexTrigger:["\\succ"],kind:"infix",associativity:"right",precedence:S},{name:"PrecedesEqual",latexTrigger:["\\preccurlyeq"],kind:"infix",associativity:"right",precedence:S},{name:"SucceedsEqual",latexTrigger:["\\curlyeqprec"],kind:"infix",associativity:"right",precedence:S},{name:"NotPrecedes",latexTrigger:["\\nprec"],kind:"infix",associativity:"right",precedence:S},{name:"NotSucceeds",latexTrigger:["\\nsucc"],kind:"infix",associativity:"right",precedence:S},{name:"Between",latexTrigger:["\\between"],kind:"infix",associativity:"right",precedence:S+5}];function Rt(e){return typeof e!="string"?!1:["Less","LessEqual","Greater","GreaterEqual"].includes(e)}function Ct(e){return typeof e!="string"?!1:["Equal","NotEqual"].includes(e)}var X=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},ae=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},Qu=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)},el=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))},fn=function(){throw SyntaxError("Invalid Param")};function kr(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 nl=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 V.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 V.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]):fn();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&&fn();for(var o=0;o<i.length;o++){var a=i[o];a===" "||a===" "||a===`
3
3
  `||(a==="+"?r++:a==="-"?s++:a==="i"||a==="I"?(r+s===0&&fn(),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)))&&fn(),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&&fn();break;case"number":t.im=0,t.re=e;break;default:fn()}return isNaN(t.re)||isNaN(t.im),t},V=class e{constructor(n,t){this.re=0,this.im=0;var i=nl(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=kr(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)+Qu(t),Math.exp(n)*Math.sin(t))}log(){var n=this.re,t=this.im;return t===0&&n>0,new e(kr(n,t),Math.atan2(t,n))}abs(){return el(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)*X(t),Math.cos(n)*ae(t))}cos(){var n=this.re,t=this.im;return new e(Math.cos(n)*X(t),-Math.sin(n)*ae(t))}tan(){var n=2*this.re,t=2*this.im,i=Math.cos(n)+X(t);return new e(Math.sin(n)/i,ae(t)/i)}cot(){var n=2*this.re,t=2*this.im,i=Math.cos(n)-X(t);return new e(-Math.sin(n)/i,ae(t)/i)}sec(){var n=this.re,t=this.im,i=.5*X(2*t)+.5*Math.cos(2*n);return new e(Math.cos(n)*X(t)/i,Math.sin(n)*ae(t)/i)}csc(){var n=this.re,t=this.im,i=.5*X(2*t)-.5*Math.cos(2*n);return new e(Math.sin(n)*X(t)/i,-Math.cos(n)*ae(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(ae(n)*Math.cos(t),X(n)*Math.sin(t))}cosh(){var n=this.re,t=this.im;return new e(X(n)*Math.cos(t),ae(n)*Math.sin(t))}tanh(){var n=2*this.re,t=2*this.im,i=X(n)+Math.cos(t);return new e(ae(n)/i,Math.sin(t)/i)}coth(){var n=2*this.re,t=2*this.im,i=X(n)-Math.cos(t);return new e(ae(n)/i,-Math.sin(t)/i)}csch(){var n=this.re,t=this.im,i=Math.cos(2*t)-X(2*n);return new e(-2*ae(n)*Math.cos(t)/i,2*X(n)*Math.sin(t)/i)}sech(){var n=this.re,t=this.im,i=Math.cos(2*t)+X(2*n);return new e(2*X(n)*Math.cos(t)/i,-2*ae(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=kr(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())}};V.ZERO=new V(0,0);V.ONE=new V(1,0);V.I=new V(0,1);V.PI=new V(Math.PI,0);V.E=new V(Math.E,0);V.INFINITY=new V(1/0,1/0);V.NAN=new V(NaN,NaN);V.EPSILON=1e-15;var Bt=["number","finite_number","complex","finite_complex","imaginary","real","finite_real","rational","finite_rational","integer","finite_integer","non_finite_number"],Sr=["indexed_collection","list","tuple"],Ot=[...Sr,"collection","set","record","dictionary"],Ft=["scalar",...Bt,"boolean","string"],wr=["value","color",...Ot,...Ft],Ar=["expression","symbol","function",...wr],Pr=["any","unknown","nothing","never","error",...Ar],Jt=new Set(Bt),so=new Set(Ot),oo=new Set(Ft),pn=new Set(Pr);function Lt(e){return typeof e=="string"?pn.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==="broadcastable"||e.kind==="symbol"||e.kind==="expression"||e.kind==="numeric"||e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="reference"}var Vt=class{input;pos=0;line=1;column=1;tokens=[];tolerant;constructor(n,t){this.input=n,this.tolerant=t?.tolerant??!1}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
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");if(this.tolerant)return this.createToken("EOF","");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 qt=class{lexer;typeResolver;current;allowTrailing;_end=0;constructor(n,t){this.allowTrailing=t?.allowTrailing??!1,this.lexer=new Vt(n,{tolerant:this.allowTrailing}),this.typeResolver=t?.typeResolver??{forward:()=>{},resolve:()=>{},get names(){return[]}},this.current=this.lexer.consumeToken()}get endOffset(){return this._end}error(n,t){this.errorAtToken(this.current,n,t)}errorAtToken(n,t,i){let r=this.lexer.input;this.allowTrailing&&(r=r.slice(0,n.position+n.value.length));let 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}`];i&&l.push(`| ${i}`),l.push("");let f=new Error(l.join(`
6
6
  `));throw f.position=n.position,f.rawMessage=t,f}advance(){let n=this.current;return this._end=n.position+n.value.length,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}parseTypePrefix(){this.checkForNakedFunctionSignature();let n=this.parseUnionType();return n||this.error("Expected a type"),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.parseBroadcastableType()||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})}}parseBroadcastableType(){if(this.current.type==="IDENTIFIER"&&this.current.value==="broadcastable"){this.advance();let n=this.createNode("primitive",{name:"any"});if(this.match("<")){let t=this.parseUnionType();t&&(n=t),this.expect(">")}return this.createNode("broadcastable",{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(pn.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 ao(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"broadcastable":return n.visitBroadcastableType(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 Dr=class{typeResolver;constructor(n){this.typeResolver=n??{forward:()=>{},resolve:()=>{},get names(){return[]}}}buildType(n){return ao(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}}visitBroadcastableType(n){return{kind:"broadcastable",elements:this.buildType(n.elementType)}}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 uo(e,n){return new Dr(n).buildType(e)}var $t=new Map,tl=2048;function lo(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;Object.freeze(e);for(let n of Object.values(e))lo(n);return e}function De(e,n){if(e===void 0)return;if(Lt(e))return e;if(typeof e!="string")return;let t=n===void 0;if(t){let i=$t.get(e);if(i!==void 0)return i}try{let r=new qt(e,{typeResolver:n}).parseType(),s=uo(r,n);return t&&($t.size>=tl&&$t.clear(),$t.set(e,lo(s))),s}catch(i){throw new Error(`Failed to parse type "${e}": ${i instanceof Error?i.message:String(i)}`)}}var co={number:Bt,non_finite_number:[],finite_number:["finite_complex","finite_real","finite_integer","finite_rational"],complex:["finite_complex","imaginary","real","rational","integer","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:Pr,unknown:[],nothing:[],never:[],error:[],value:wr,scalar:Ft,collection:Ot,indexed_collection:Sr,list:[],set:[],tuple:[],record:[],dictionary:[],function:[],symbol:[],boolean:[],string:[],color:[],expression:Ar},Dn=(()=>{let e={},n=t=>{if(e[t])return e[t];let i=new Set([t]);e[t]=i;for(let r of co[t])if(r!==t)for(let s of n(r))i.add(s);return i};for(let t of Object.keys(co))n(t);return e})();function mn(e,n){return n==="any"||e==="never"?!0:n==="never"?!1:n==="error"?e==="error":n==="nothing"?e==="nothing":e==="nothing"?!1:n==="unknown"?!0:e==="unknown"?!1:e===n?!0:Dn[n].has(e)}function fo(e,n){if(e===n)return[e];let t=Dn[e],i=Dn[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&&Dn[l].has(u)));return po.set(r,a),a}var po=new Map;function il(e){return e.lower!==void 0&&e.upper!==void 0&&Number.isFinite(e.lower)&&Number.isFinite(e.upper)}function rl(e){switch(e){case"number":return"finite_number";case"complex":return"finite_complex";case"real":return"finite_real";case"rational":return"finite_rational";case"integer":return"finite_integer";default:return e}}var sl={finite_number:"number",finite_complex:"complex",finite_real:"real",finite_rational:"rational",finite_integer:"integer"};function ol(e){if(!e.some(t=>t==="non_finite_number"))return e;let n;for(let t of e){if(typeof t!="string")continue;let i=sl[t];i&&(n??=[]).push(i)}return n?[...e,...n]:e}function al(e,n){if(e==="never"||n==="never")return!0;if(e==="any"||n==="any"||e==="unknown"||n==="unknown")return!1;if(e==="nothing"||n==="nothing")return e!==n;if(k(e,n)||k(n,e))return!1;if(typeof e=="object"&&e.kind==="value"||typeof n=="object"&&n.kind==="value")return!0;if(typeof e=="string"&&typeof n=="string")return fo(e,n).length===0;if(typeof e=="object"&&e.kind==="numeric"&&typeof n=="object"&&n.kind==="numeric"){if(fo(e.type,n.type).length===0)return!0;let r=e.lower??-1/0,s=e.upper??1/0,o=n.lower??-1/0,a=n.upper??1/0;return s<o||a<r}let t=_n(e),i=_n(n);if(t!==i){let r=t?n:e;if(!Rr(r)&&!Cr(r)&&!_n(r))return!0}return!1}function k(e,n){if(typeof e=="string"&&!pn.has(e)&&(e=De(e)),typeof n=="string"&&!pn.has(n)&&(n=De(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"){if(typeof e=="string")return mn(e,n);if(e.kind==="broadcastable")return k(e.elements,n)&&k({kind:"indexed_collection",elements:e.elements},n);if(e.kind==="value")return typeof e.value=="boolean"?n==="boolean":typeof e.value=="number"?Number.isInteger(e.value)?mn("integer",n):mn("real",n):typeof e.value=="boolean"?mn("boolean",n):typeof e.value=="string"?mn("string",n):!1;if(e.kind==="union")return e.types.every(t=>k(t,n));if(e.kind==="intersection")return e.types.some(t=>k(t,n));if(e.kind==="negation")return!1;if(e.kind==="numeric"){let t=il(e)?rl(e.type):e.type;return!!k(t,n)}return n==="number"?_n(e):n==="symbol"?_r(e):n==="expression"?ll(e):n==="function"?yo(e):n==="scalar"?Rr(e):n==="value"?Cr(e):n==="indexed_collection"?bo(e):n==="collection"?ho(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"){let t=ol(n.types),i=r=>k(r.elements,n)&&k({kind:"indexed_collection",elements:r.elements},n);return typeof e!="string"&&e.kind==="broadcastable"?i(e):typeof e!="string"&&e.kind==="union"?e.types.every(r=>typeof r!="string"&&r.kind==="broadcastable"?i(r):t.some(s=>k(r,s))):t.some(r=>k(e,r))}if(n.kind==="negation")return typeof e!="string"&&e.kind==="negation"?k(n.type,e.type):al(e,n.type);if(n.kind==="expression"){if(e==="symbol")return n.operator==="Symbol";if(typeof e=="string")return!1;if(e.kind==="expression")return n.operator==="Symbol"?_r(e):e.operator===n.operator;if(e.kind==="symbol")return n.operator==="Symbol"}if(n.kind==="broadcastable"){if(typeof e!="string"&&e.kind==="broadcastable")return k(e.elements,n.elements);if(typeof e!="string"&&e.kind==="union")return e.types.every(i=>k(i,n));if(k(e,n.elements))return!0;let t=ul(e);return t!==void 0?k(t,n.elements):!1}if(typeof e!="string"&&e.kind==="broadcastable")return k(e.elements,n)&&k({kind:"indexed_collection",elements:e.elements},n);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 k(e,n.def)}if(e.kind==="union")return e.types.some(t=>k(t,n));if(e.kind==="intersection"&&n.kind==="intersection")return n.types.every(t=>e.types.some(i=>k(i,t)));if(e.kind==="intersection")return e.types.every(t=>k(t,n));if(n.kind==="intersection")return n.types.every(t=>k(e,t));if(e.kind==="signature"&&n.kind==="signature"){if(!k(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(!k(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(!k(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||!k(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(!k(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(!k(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(!k(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)||!k(e.elements[t],n.elements[t]))return!1;return!0}if(e.kind==="dictionary"&&n.kind==="dictionary")return k(e.values,n.values);if(n.kind==="indexed_collection")return e.kind==="indexed_collection"||e.kind==="list"?k(e.elements,n.elements):e.kind==="tuple"?e.elements.every(t=>k(t.type,n.elements)):!1;if(n.kind==="collection"){if(e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="list")return k(e.elements,n.elements);if(e.kind==="tuple")return e.elements.every(t=>k(t.type,n.elements));if(e.kind==="set")return k(e.elements,n.elements);if(e.kind==="dictionary")return k({kind:"tuple",elements:[{type:"string"},{type:e.values}]},n.elements);if(e.kind==="record")return k({kind:"tuple",elements:[{type:"string"},{type:je(...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(!k(i.type,r.type)||r.name!==void 0&&i.name!==r.name)return!1}return!0}if(n.kind==="list"&&e.kind==="list"){if(!k(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(n.kind==="numeric"&&e.kind==="value"){if(typeof e.value!="number")return!1;let t=Number.isInteger(e.value)?"finite_integer":"finite_real";return!(!mn(t,n.type)||e.value<(n.lower??-1/0)||e.value>(n.upper??1/0))}if(e.kind==="numeric"&&n.kind==="numeric")return!(!k(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!!k(e.elements,n.elements);if(n.kind==="value"&&e.kind==="value")return n.value===e.value;if(e.kind==="value"){if(typeof e.value=="boolean")return k("boolean",n);if(typeof e.value=="number")return Number.isInteger(e.value)?k("integer",n):k("real",n);if(typeof e.value=="string")return k("string",n)}return!1}function _n(e){return typeof e=="string"?Jt.has(e):e.kind==="value"?typeof e.value=="number":e.kind==="numeric"}function Rr(e){return _n(e)?!0:typeof e=="string"?oo.has(e):e.kind==="value"?["string","boolean","number"].includes(typeof e.value):!1}function ho(e){return bo(e)?!0:typeof e=="string"?so.has(e):["collection","set","record","dictionary"].includes(e.kind)}function bo(e){return typeof e=="string"?!1:["indexed_collection","list","tuple"].includes(e.kind)}function ul(e){if(typeof e=="string")return e==="indexed_collection"||e==="list"?"any":void 0;if(e.kind==="indexed_collection")return e.elements;if(e.kind==="list"){let n=e.dimensions;return n&&n.length>1?{kind:"list",elements:e.elements,dimensions:n.slice(1)}:e.elements}}function Cr(e){return Rr(e)||ho(e)}function yo(e){return e==="function"||typeof e!="string"&&e.kind==="signature"}function ll(e){return typeof e=="string"&&["expression","symbol","function"].includes(e)||Cr(e)||yo(e)||_r(e)?!0:typeof e=="string"?!1:e.kind==="expression"}function _r(e){return e==="symbol"?!0:typeof e=="string"?!1:e.kind==="symbol"?!0:e.kind==="expression"?e.operator==="Symbol":!1}function cl(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"||k(e,n)?e:k(n,e)?n:"never"}function fl(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(k(e,n))return n;if(k(n,e))return e;let t=dl(e,n);return pl.has(t)?ml(e,n):t}var pl=new Set(["scalar","value","function","expression","collection","indexed_collection","list","set","tuple","record","dictionary","map","any"]);function ml(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 Br(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce((n,t)=>cl(n,t))}function je(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce((n,t)=>fl(n,t))}var mo=["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"],go=new Map;function dl(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=go.get(t);if(i===void 0){i="any";for(let r of mo){let s=Dn[r];if(s.has(e)&&s.has(n)){i=r;break}}go.set(t,i)}return i}for(let t of mo)if(k(e,t)&&k(n,t))return t;return"any"}var No=3,Eo=1,To=2,gl=4,hl=5,bl=6,yl=7,xl=8,Nl=9,El=10,Tl=11;function L(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=`!${L(e.type,No)}`;break;case"union":{let u=[],l=f=>{typeof f=="object"&&f.kind==="union"?f.types.forEach(l):u.push(L(f,Eo))};e.types.forEach(l),t=u.sort().join(" | ");break}case"intersection":t=e.types.map(u=>L(u,To)).join(" & ");break;case"expression":t=`expression<${xo(e.operator)}>`;break;case"symbol":t=`symbol<${xo(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"&&Jt.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<${L(e.elements)}>`:t=`vector<${L(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<${L(e.elements)}>`:t=`matrix<${L(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<${L(e.elements)}${u}>`}break;case"record":t=`record<${Object.entries(e.elements).map(([u,l])=>`${u}: ${L(l)}`).join(", ")}>`;break;case"dictionary":t=`dictionary<${L(e.values)}>`;break;case"set":t=`set<${L(e.elements)}>`;break;case"broadcastable":t=`broadcastable<${L(e.elements)}>`;break;case"collection":t=`collection<${L(e.elements)}>`;break;case"indexed_collection":t=`indexed_collection<${L(e.elements)}>`;break;case"tuple":if(e.elements.length===0)t="tuple";else if(e.elements.length===1){let[u]=e.elements;t=`tuple<${dn(u)}>`}else t="tuple<"+e.elements.map(u=>dn(u)).join(", ")+">";break;case"signature":let r=e.args?e.args.map(u=>dn(u)).join(", "):"",s=e.optArgs?e.optArgs.map(u=>dn(u)+"?").join(", "):"",o=e.variadicArg?e.variadicMin===0?`${dn(e.variadicArg)}*`:`${dn(e.variadicArg)}+`:"";t=`(${[r,s,o].filter(u=>u).join(", ")}) -> ${L(e.result)}`;break;default:t="error"}return n>0&&n>vl(e.kind)?`(${t})`:t}function dn(e){return e.name?`${e.name}: ${L(e.type)}`:L(e.type)}function xo(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)?e:`\`${e}\``}function vl(e){switch(e){case"negation":return No;case"union":return Eo;case"intersection":return To;case"list":return gl;case"record":return hl;case"dictionary":return bl;case"set":return yl;case"collection":case"indexed_collection":case"broadcastable":return xl;case"tuple":return Nl;case"signature":return El;case"value":return Tl;default:return 0}}var G=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(je(...n.map(t=>t instanceof e?t.type:t)))}static narrow(...n){return new e(Br(...n.map(t=>t instanceof e?t.type:t)))}constructor(n,t){typeof n=="string"?this.type=De(n,t):this.type=n}matches(n){return n instanceof e?k(this.type,n.type):k(this.type,n)}is(n){return k(this.type,n)&&k(n,this.type)}get isUnknown(){return this.type==="unknown"}toString(){return L(this.type)}toJSON(){return L(this.type)}[Symbol.toPrimitive](n){return n==="string"?this.toString():null}valueOf(){return L(this.type)}};var Wm=Object.freeze({bySubject:new Map,membership:new Map,geEdges:new Map,inequalitySubjects:new Set});var id=[0,-1,1,Math.PI,Math.E,-Math.PI,-Math.E,.5,-.5];var Cn=["Error","'missing'"];function ce(e){return!!(typeof e=="number"||gn(e)||typeof e=="string"&&Zt(e))}function gn(e){return e!==null&&typeof e=="object"&&"num"in e}function jt(e){return e!==null&&typeof e=="object"&&"sym"in e}function Mo(e){return e!==null&&typeof e=="object"&&"str"in e}function ko(e){return e!==null&&typeof e=="object"&&"dict"in e&&typeof e.dict=="object"&&!Array.isArray(e.dict)&&e.dict!==null}function hn(e){return e!==null&&typeof e=="object"&&"fn"in e&&Array.isArray(e.fn)&&e.fn.length>0&&typeof e.fn[0]=="string"}function w(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):Zt(e)||Lr(e)?null:e}function Fr(e){if(e==null||w(e)!==null)return null;let n=d(e);return n?[n,...b(e).map(t=>Fr(t)).filter(t=>t!==null)]:e}function d(e){return Array.isArray(e)?e[0]:e==null?"":hn(e)?e.fn[0]:""}function b(e){return Array.isArray(e)?e.slice(1):e!==void 0&&hn(e)?e.fn.slice(1):[]}function c(e,n){return Array.isArray(e)?e[n]??null:e===null||!hn(e)?null:e.fn[n]??null}function A(e){return e==null?0:Array.isArray(e)?Math.max(0,e.length-1):hn(e)?Math.max(0,e.fn.length-1):0}function Jr(e){return e==null?null:d(e)==="Hold"?c(e,1):e}function y(e){return typeof e=="string"&&Lr(e)?e.length>=2&&e.at(0)==="`"&&e.at(-1)==="`"?e.slice(1,-1):e:e==null?null:jt(e)?e.sym:null}function vo(e){let n=d(e);if(n==="KeyValuePair"||n==="Tuple"||n==="Pair"){let[t,i]=b(e),r=w(t);return r?[r,i??"Nothing"]:null}return null}function So(e){if(e===null)return null;if(ko(e))return e;let n=vo(e);if(n)return{dict:{[n[0]]:Io(n[1])??"Nothing"}};if(d(e)==="Dictionary"){let t={};for(let i of b(e)){let r=vo(i);r&&(t[r[0]]=Io(r[1])??"Nothing")}return{dict:t}}return null}function Gt(e){return{dict:Object.fromEntries(Object.entries(e).map(([t,i])=>[t,Or(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 M(e){return typeof e=="number"?e:typeof e=="string"&&Zt(e)?Pl(e):e!==void 0&&gn(e)?M(e.num):null}function Ge(e){if(e==null)return null;if(y(e)==="Half")return[1,2];let n=d(e);if(!n)return null;let t=null,i=null;if(n==="Negate"){let r=Ge(b(e)[0]);if(r)return[-r[0],r[1]]}if(n==="Rational"||n==="Divide"){let[r,s]=b(e);t=M(r)??NaN,i=M(s)??NaN}if(n==="Power"){let[r,s]=b(e),o=M(s);o===1?(t=M(r),i=1):o===-1&&(t=1,i=M(r))}if(n==="Multiply"){let[r,s]=b(e);if(d(s)==="Power"){let[o,a]=b(s);M(a)===-1&&(t=M(r),i=M(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),hn(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 bn(e,n,t){let i=d(n),r=d(t);return i===e&&r===e?[e,...b(n),...b(t)]:i===e?[e,...b(n),t]:r===e?[e,n,...b(t)]:[e,n,t]}function Ne(e){if(e==null)return null;let n=d(e);if(n==="Delimiter"){if(e=c(e,1),e===null)return[];if(n=d(e),n!=="Sequence")return[e]}return n!=="Sequence"?null:b(e)}function R(e){return e==null||e==="Nothing"?!0:d(e)==="Sequence"&&A(e)===0}function P(e){return R(e)?Cn:e}function Zt(e){return/^(nan|oo|\+oo|-oo|infinity|\+infinity|-infinity)$/i.test(e)||/^[+-]?(0|[1-9][0-9]*)(\.([0-9]+(\([0-9]+\))?|\([0-9]+\)))?([eE][+-]?[0-9]+)?$/.test(e)}function Lr(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)||e.length>=2&&e[0]==="`"&&e[e.length-1]==="`"}function Or(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=>Or(n)??"Nothing")];if(e===null)return null;if(typeof e=="object"){let n={};for(let t in e)n[t]=Or(e[t])??"Nothing";return{dict:n}}return hn(e)||jt(e)||gn(e)||Mo(e)||ko(e)?e:null}function Io(e){return e==null?null:Mo(e)?e.str:gn(e)?parseFloat(e.num):jt(e)?e.sym:typeof e=="string"||typeof e=="number"?e:Array.isArray(e)?{fn:e}:e}function wo(e,n){for(;n!==BigInt(0);)[e,n]=[n,e%n];return e<0?-e:e}function Ao(e){return e!==null&&Array.isArray(e)&&typeof e[0]=="number"}function Vr(e){if(Ao(e)){if(e[1]<0&&(e=[-e[0],-e[1]]),e[0]===1||e[1]===1)return e;if(!Number.isFinite(e[1]))return[0,1];let r=un(e[0],e[1]);return r<=1?e:[e[0]/r,e[1]/r]}e[1]<0&&(e=[-e[0],-e[1]]);let n=wo(e[0],e[1]),[t,i]=n<=1?e:[e[0]/n,e[1]/n];return t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER&&i<=Number.MAX_SAFE_INTEGER?[Number(t),Number(i)]:[t,i]}function Po(e,n){if(!Number.isFinite(e))return null;for(let t=1;t<=1e6;t*=10){let i=e*t;if(Number.isInteger(i))return!Number.isSafeInteger(i)||!Number.isSafeInteger(n*t)?null:Vr([i,n*t])}return null}function Do(e,n){return typeof e=="number"?Number.isFinite(e)?parseFloat(e.toPrecision(n)):e:e.toPrecision(n)}function Bn(e,n){return e.toFixed(n)}function qr(e,n,t="auto"){if(t==="max")return{value:String(e),error:String(n)};if(typeof t=="object"&&"fractional"in t){let u=t.fractional;return{value:Bn(e,u),error:Bn(n,u)}}let i=t==="auto"?2:t.significant,r=Do(n,i),s=parseInt(r.toExponential().split("e")[1],10),o=i-1-s;if(o>0)return{value:Bn(e,o),error:Bn(r,o)};let a=Math.pow(10,-o);return{value:String(Math.round(e/a)*a),error:String(Math.round(r/a)*a)}}var _l=new Map;function Ee(e){for(let[n,t]of Object.entries(e))_l.set(n,t)}Ee({"simplify-terms":"Simplify the terms",fu:"Apply trigonometric simplification (Fu algorithm)","exp-to-trig":"Rewrite exponentials as trigonometric functions (Euler\u2019s formula)","simplify-relational-operator":"Simplify both sides of the relation",addition:"Add the terms",multiplication:"Multiply the factors",division:"Divide the terms",negation:"Negate",power:"Evaluate the power",root:"Evaluate the root",sqrt:"Evaluate the square root",rational:"Simplify the fraction",expand:"Expand the expression","cancel common polynomial factors":"Cancel the common factors","partial fraction decomposition":"Decompose into partial fractions","a/a -> 1":"Cancel the common factor: a\u2044a = 1","combined powers":"Combine the powers","combined powers with same base":"Combine powers with the same base","x^n * x^m -> x^{n+m}":"Combine powers with the same base: x\u207F\xB7x\u1D50 = x\u207F\u207A\u1D50","x * x^n -> x^{n+1}":"Combine powers with the same base: x\xB7x\u207F = x\u207F\u207A\xB9","a^m / a^n -> a^{m-n}":"Subtract the exponents: a\u1D50\u2044a\u207F = a\u1D50\u207B\u207F","a^m / a -> a^{m-1}":"Subtract the exponents: a\u1D50\u2044a = a\u1D50\u207B\xB9","a / a^n -> a^{1-n}":"Subtract the exponents: a\u2044a\u207F = a\xB9\u207B\u207F","(-x)^n -> -x^n when n is odd":"Factor out the sign: (\u2212x)\u207F = \u2212x\u207F for odd n","(-x)^n -> x^n when n is even":"Drop the sign: (\u2212x)\u207F = x\u207F for even n","(-x)^{n/m} -> x^{n/m} when n is even and m is odd":"Drop the sign: (\u2212x)\u207F\u141F\u1D50 = x\u207F\u141F\u1D50 for even n and odd m","(-x)^{n/m} -> -x^{n/m} when n and m are odd":"Factor out the sign: (\u2212x)\u207F\u141F\u1D50 = \u2212x\u207F\u141F\u1D50 for odd n and m","root(-a, n) -> -root(a, n) when n odd":"Factor the sign out of the odd root: \u207F\u221A(\u2212a) = \u2212\u207F\u221Aa","a / (b/c)^d -> a * (c/b)^d":"Dividing by (b\u2044c)\u1D48 is multiplying by (c\u2044b)\u1D48","denest \u221A(a+b\u221Ac) -> \u221Ax+\u221Ay":"Denest the radical","sqrt(x^2) -> |x|":"Apply \u221A(x\xB2) = |x|","sqrt(x^{2n}) -> |x|^n":"Apply \u221A(x\xB2\u207F) = |x|\u207F","root(x^n, n) -> x when n odd":"Apply \u207F\u221A(x\u207F) = x for odd n","root(x^n, n) -> |x| when n even":"Apply \u207F\u221A(x\u207F) = |x| for even n","root(x^m, n) -> |x|^{m/n}":"Rewrite the root as a power: \u207F\u221A(x\u1D50) = |x|\u1D50\u141F\u207F","root(1, n) -> 1":"A root of 1 is 1","root(0, n) -> 0 when n > 0":"A root of 0 is 0","root(root(x, m), n) -> x^{1/(m*n)}":"Combine the nested roots: \u207F\u221A(\u1D50\u221Ax) = x^(1\u2044(m\xB7n))","sqrt(sqrt(x)) -> x^{1/4}":"Combine the nested roots: \u221A(\u221Ax) = x^(1\u20444)","root(sqrt(x), n) -> x^{1/(2n)}":"Combine the nested roots: \u207F\u221A(\u221Ax) = x^(1\u2044(2n))","sqrt(root(x, n)) -> x^{1/(2n)}":"Combine the nested roots: \u221A(\u207F\u221Ax) = x^(1\u2044(2n))","root(product, n) -> factored":"Distribute the root over the product",ln:"Simplify the natural logarithm",log:"Simplify the logarithm","combine ln terms":"Combine the logarithms","combine log terms":"Combine the logarithms","e^ln(x) -> x":"Apply e^(ln x) = x: exp and ln are inverses","c^log_c(x) -> x":"Apply c^(log\uA700 x) = x: the exponential and the logarithm are inverses","e^(ln(x) + y) -> x * e^y":"Split the exponent: e^(ln x + y) = x\xB7e\u02B8","e^(ln(x) * y) -> x^y":"Apply e^(y\xB7ln x) = x\u02B8","c^(log_c(x) + y) -> x * c^y":"Split the exponent: c^(log\uA700 x + y) = x\xB7c\u02B8","c^(log_c(x) * y) -> x^y":"Apply c^(y\xB7log\uA700 x) = x\u02B8","ln(e^x * y) -> x + ln(y)":"Expand the logarithm: ln(e\u02E3\xB7y) = x + ln y","log_c(c) -> 1":"The logarithm of the base is 1","log_c(c^x) -> x":"Apply log\uA700(c\u02E3) = x: the logarithm and the exponential are inverses","log_c(c^x * y) -> x + log_c(y)":"Expand the logarithm: log\uA700(c\u02E3\xB7y) = x + log\uA700 y","log_c(c^x / y) -> x - log_c(y)":"Expand the logarithm: log\uA700(c\u02E3\u2044y) = x \u2212 log\uA700 y","log_c(y / c^x) -> log_c(y) - x":"Expand the logarithm: log\uA700(y\u2044c\u02E3) = log\uA700 y \u2212 x","log_c(x^n) -> n*log_c(x)":"Bring the exponent out: log(x\u207F) = n\xB7log x","log_c(x^n) -> n*log_c(|x|) when n even":"Bring the exponent out: log(x\u207F) = n\xB7log|x| for even n","log_c(x^{p/q}) -> (p/q)*log_c(x)":"Bring the exponent out: log(x\u1D56\u141F\u{107A5}) = (p\u2044q)\xB7log x","log_c(x^{p/q}) -> (p/q)*log_c(|x|) when p even":"Bring the exponent out: log(x\u1D56\u141F\u{107A5}) = (p\u2044q)\xB7log|x| for even p","ln(a)/ln(b) -> k when a = b^k":"Recognize the logarithm ratio: ln(b\u1D4F)\u2044ln(b) = k","log_{1/c}(a) -> -log_c(a)":"Invert the base: log\u2081\u2044\uA700(a) = \u2212log\uA700(a)","log_c(a) / log_c(b) -> ln(a) / ln(b)":"Change of base: log\uA700(a)\u2044log\uA700(b) = ln(a)\u2044ln(b)","log_c(a) / ln(a) -> 1/ln(c)":"Change of base: log\uA700(a)\u2044ln(a) = 1\u2044ln(c)","ln(a) / log_c(a) -> ln(c)":"Change of base: ln(a)\u2044log\uA700(a) = ln(c)","log base 0 or 1 -> NaN":"A logarithm base of 0 or 1 is undefined","log_c(0) -> NaN":"The logarithm of 0 is undefined","abs-negate":"Apply |\u2212x| = |x|","|-x| -> |x|":"Apply |\u2212x| = |x|","|x| -> x":"Drop the absolute value: the argument is non-negative","|x| -> -x":"Resolve the absolute value: the argument is non-positive","|xy| -> x|y| when x >= 0":"Move the non-negative factor out of the absolute value","|x/y| -> |x|/y when y >= 0":"Move the non-negative denominator out of the absolute value","|x/y| -> x/|y| when x >= 0":"Move the non-negative numerator out of the absolute value","|x|^n -> x^n when n is even":"Drop the absolute value: |x|\u207F = x\u207F for even n","|x^n| -> x^n when n is even":"Drop the absolute value: x\u207F \u2265 0 for even n","|x^n| -> |x|^n when n is odd":"Move the absolute value onto the base: |x\u207F| = |x|\u207F for odd n","|x|^(p/q) -> x^(p/q) when p is even":"Drop the absolute value: |x|\u1D56\u141F\u{107A5} = x\u1D56\u141F\u{107A5} for even p","|x^(p/q)| -> x^(p/q) when p is even":"Drop the absolute value: x\u1D56\u141F\u{107A5} \u2265 0 for even p","|x^(p/q)| -> |x|^(p/q) when p is odd":"Move the absolute value onto the base: |x\u1D56\u141F\u{107A5}| = |x|\u1D56\u141F\u{107A5} for odd p","sign positive":"The sign of a positive quantity is 1","sign negative":"The sign of a negative quantity is \u22121","sign zero":"The sign of zero is 0","sin\xB2(x) + cos\xB2(x) -> 1":"Apply the Pythagorean identity: sin\xB2x + cos\xB2x = 1","a*sin\xB2(x) + a*cos\xB2(x) -> a":"Apply the Pythagorean identity: sin\xB2x + cos\xB2x = 1","tan\xB2(x) + 1 -> sec\xB2(x)":"Apply the Pythagorean identity: tan\xB2x + 1 = sec\xB2x","1 + cot\xB2(x) -> csc\xB2(x)":"Apply the Pythagorean identity: 1 + cot\xB2x = csc\xB2x","sin(x)cos(y)+cos(x)sin(y) -> sin(x+y)":"Apply the angle-addition identity: sin x cos y + cos x sin y = sin(x + y)","sin(x)cos(y)-cos(x)sin(y) -> sin(x-y)":"Apply the angle-subtraction identity: sin x cos y \u2212 cos x sin y = sin(x \u2212 y)"});Ee({"solve.move-terms":"Move all terms to one side","solve.simplify":"Simplify the equation","solve.apply-inverse":"Apply the inverse function to both sides","solve.equate-exponents":"The bases are equal, so equate the exponents","solve.apply-tangent":"Take the tangent of both sides to clear the inverse trigonometric functions","solve.clear-denominators":"Multiply through to clear the denominators","solve.square-both-sides":"Square both sides to eliminate the radical","solve.substitute":"Substitute a new variable","solve.substituted-equation":"Rewrite the equation in the substituted variable","solve.back-substitute":"Substitute back to the original variable","solve.factor-zero-product":"A product is zero exactly when one of its factors is zero","solve.harmonize":"Rewrite the equation in an equivalent form","solve.expand":"Expand the equation","solve.quadratic-formula":"Apply the quadratic formula","solve.rational-roots":"Find the rational roots (rational-root theorem)","solve.polynomial-roots":"Find the remaining roots of the polynomial","solve.candidates":"Candidate solutions","solve.validate-roots":"Check each candidate in the original equation; reject the extraneous ones","solve.filter-domain":"Discard solutions outside the domain of the variable","solve.roots":"The solutions","solve.template":"Solve the matched equation pattern","solve.system.eliminate":"Eliminate a variable from the remaining equations","solve.system.back-substitute":"Substitute the known value back to solve for the next variable","solve.system.parametric":"Express the solutions in terms of a free parameter","solve.system.solve-for":"Solve one equation for one variable","solve.system.substitute":"Substitute into the remaining equations","solve.system.product-sum":"Rewrite the sum and product conditions as a quadratic","solve.case":"Consider the next case","solve.system.normalize-inequality":"Rewrite the inequality with zero on the right-hand side","solve.system.intersect-boundaries":"Find the intersection points of the boundary lines","solve.system.vertices":"Keep the corner points that satisfy every inequality","solve.system.check-constraints":"Substitute the candidate solution into each constraint","solve.system.reject":"Reject the candidate: it violates a constraint"});Ee({"solve.linear-monomial":"A multiple of the unknown is zero when the unknown is zero","solve.reciprocal":"Solve the reciprocal equation","solve.linear":"Isolate the unknown: subtract the constant, then divide by the coefficient","solve.linear-negated":"Isolate the unknown: subtract the constant, then divide by the coefficient","solve.power":"Take the n-th root of both sides","solve.power-negative-root":"Take the n-th root of both sides (negative root)","solve.quadratic-no-constant-zero":"Factor out the unknown: one solution is 0","solve.quadratic-no-constant":"Factor out the unknown and solve the remaining linear factor","solve.quadratic-formula-positive":"Apply the quadratic formula (positive branch)","solve.quadratic-formula-negative":"Apply the quadratic formula (negative branch)","solve.exponential":"Take the logarithm of both sides","solve.exponential-natural":"Take the natural logarithm of both sides","solve.exponential-natural-unit-exponent":"Take the natural logarithm of both sides","solve.exponential-natural-simple":"Take the natural logarithm of both sides","solve.exponential-natural-unit-coefficient":"Take the natural logarithm of both sides","solve.logarithm-base":"Exponentiate both sides to clear the logarithm","solve.logarithm-base-no-constant":"Exponentiate both sides to clear the logarithm","solve.absolute-value-positive":"Resolve the absolute value (positive case)","solve.absolute-value-negative":"Resolve the absolute value (negative case)","solve.quadratic-in-sqrt-positive":"Solve as a quadratic in the square root of the unknown","solve.quadratic-in-sqrt-negative":"Solve as a quadratic in the square root of the unknown","solve.quadratic-in-sqrt-negated-positive":"Solve as a quadratic in the square root of the unknown","solve.quadratic-in-sqrt-negated-negative":"Solve as a quadratic in the square root of the unknown","solve.radical":"Isolate the radical, then square both sides","solve.logarithm-natural-scaled":"Exponentiate both sides to clear the logarithm","solve.logarithm-natural":"Exponentiate both sides to clear the logarithm","solve.sine":"Apply the inverse sine","solve.sine-second-branch":"Apply the inverse sine (second branch: \u03C0 \u2212 arcsin)","solve.sine-unit":"Apply the inverse sine","solve.sine-unit-second-branch":"Apply the inverse sine (second branch: \u03C0 \u2212 arcsin)","solve.cosine":"Apply the inverse cosine","solve.cosine-negative-branch":"Apply the inverse cosine (negative branch)","solve.cosine-unit":"Apply the inverse cosine","solve.cosine-unit-negative-branch":"Apply the inverse cosine (negative branch)","solve.tangent":"Apply the inverse tangent","solve.tangent-unit":"Apply the inverse tangent","solve.cotangent":"Apply the inverse cotangent","solve.cotangent-unit":"Apply the inverse cotangent","solve.sine-cosine-linear-combination":"Rewrite a\xB7sin x + b\xB7cos x as a single sinusoid"});Ee({"integrate.constant":"The integral of a constant: \u222Bc dx = c\xB7x","integrate.variable":"The integral of the variable: \u222Bx dx = x\xB2/2","integrate.sum":"Integrate term by term: \u222B(u+v) dx = \u222Bu dx + \u222Bv dx","integrate.constant-factor":"Move the constant factor out of the integral","integrate.collected-power":"Integrate the power of the linear expression","integrate.hyperbolic-to-exp":"Rewrite the hyperbolic functions as exponentials","integrate.trig-to-exp":"Rewrite the trigonometric functions as exponentials","integrate.by-parts":"Integrate by parts","integrate.si-ci":"Express the integral with the sine and cosine integral functions Si and Ci","integrate.trig-to-single-exp":"Substitute a single exponential for the trigonometric functions","integrate.exponential-substitution":"Substitute for the exponential and integrate the rational function","integrate.partial-fractions":"Integrate using partial-fraction decomposition","integrate.previous-result":"Use the integral computed earlier","integrate.simplify":"Simplify the result","integrate.antiderivative":"Find the antiderivative of the integrand","integrate.fundamental-theorem":"Apply the Fundamental Theorem of Calculus: \u222B\u1D43\u1D47 f dx = F(b) \u2212 F(a)","integrate.evaluate-bounds":"Evaluate the antiderivative at the bounds"});Ee({"derivative.sum-rule":"Apply the sum rule: (u + v)\u2032 = u\u2032 + v\u2032","derivative.product-rule":"Apply the product rule: (u\xB7v)\u2032 = u\u2032\xB7v + u\xB7v\u2032","derivative.quotient-rule":"Apply the quotient rule: (u\u2044v)\u2032 = (u\u2032\xB7v \u2212 u\xB7v\u2032)\u2044v\xB2","derivative.power-rule":"Apply the power rule: (u\u207F)\u2032 = n\xB7u\u207F\u207B\xB9\xB7u\u2032","derivative.exponential-rule":"Differentiate the exponential: (a\u1D58)\u2032 = a\u1D58\xB7ln(a)\xB7u\u2032","derivative.general-power-rule":"Differentiate by logarithmic differentiation: (f^g)\u2032 = f^g\xB7(g\u2032\xB7ln f + g\xB7f\u2032\u2044f)","derivative.chain-rule":"Apply the chain rule: f(u)\u2032 = f\u2032(u)\xB7u\u2032","derivative.known-derivative":"Differentiate using a known derivative","derivative.constant-multiple":"Apply the constant-multiple rule: (c\xB7u)\u2032 = c\xB7u\u2032","derivative.rewrite":"Rewrite in an equivalent differentiable form","derivative.expand-definition":"Expand the definition of the function","derivative.zero":"The expression is locally constant: its derivative is 0","derivative.simplify":"Simplify the result"});{let e=["Sin","Tan","Cot","Csc","Sinh","Tanh","Coth","Csch","Arcsin","Arctan","Arccsc","Arsinh","Artanh","Arcsch"],n=["Cos","Sec","Cosh","Sech"],t={};for(let i of e){let r=i.toLowerCase();t[`${i}(-x) -> -${i}(x)`]=`Use the odd symmetry: ${r}(\u2212x) = \u2212${r}(x)`}for(let i of n){let r=i.toLowerCase();t[`${i}(-x) -> ${i}(x)`]=`Use the even symmetry: ${r}(\u2212x) = ${r}(x)`}Ee(t)}{let e=["Sin","Tan","Cot","Csc","Sinh","Tanh","Coth","Csch","Arcsin","Arctan","Arccot","Arccsc","Arsinh","Artanh","Arcoth","Arcsch"],n=["Cos","Sec","Cosh","Sech"],t={};for(let i of e){let r=i.toLowerCase();t[`|${i}(x)| -> ${i}(|x|) (odd function)`]=`Move the absolute value onto the argument: |${r}(x)| = ${r}(|x|) because ${r} is odd`}for(let i of n){let r=i.toLowerCase();t[`${i}(|x|) -> ${i}(x) (even function)`]=`Drop the absolute value: ${r}(|x|) = ${r}(x) because ${r} is even`}Ee(t)}Ee({"Sin(\u03C0 + x) -> -Sin(x)":"Shift the angle by \u03C0: sin(\u03C0 + x) = \u2212sin(x)","Cos(\u03C0 + x) -> -Cos(x)":"Shift the angle by \u03C0: cos(\u03C0 + x) = \u2212cos(x)","Tan(\u03C0 + x) -> Tan(x)":"Use the period \u03C0 of tangent: tan(\u03C0 + x) = tan(x)","Cot(\u03C0 + x) -> Cot(x)":"Use the period \u03C0 of cotangent: cot(\u03C0 + x) = cot(x)","Sec(\u03C0 + x) -> -Sec(x)":"Shift the angle by \u03C0: sec(\u03C0 + x) = \u2212sec(x)","Csc(\u03C0 + x) -> -Csc(x)":"Shift the angle by \u03C0: csc(\u03C0 + x) = \u2212csc(x)","Sin(\u03C0/2 - x) -> Cos(x)":"Apply the cofunction identity: sin(\u03C0\u20442 \u2212 x) = cos(x)","Cos(\u03C0/2 - x) -> Sin(x)":"Apply the cofunction identity: cos(\u03C0\u20442 \u2212 x) = sin(x)","Tan(\u03C0/2 - x) -> Cot(x)":"Apply the cofunction identity: tan(\u03C0\u20442 \u2212 x) = cot(x)","Cot(\u03C0/2 - x) -> Tan(x)":"Apply the cofunction identity: cot(\u03C0\u20442 \u2212 x) = tan(x)","Sec(\u03C0/2 - x) -> Csc(x)":"Apply the cofunction identity: sec(\u03C0\u20442 \u2212 x) = csc(x)","Csc(\u03C0/2 - x) -> Sec(x)":"Apply the cofunction identity: csc(\u03C0\u20442 \u2212 x) = sec(x)"});{let e=["Sin","Cos","Tan","Cot","Sec","Csc","Arcsin","Arccos"],n={};for(let t of e)n[`${t}(infinity) -> NaN`]=`${t.toLowerCase()} has no limit at infinity`;for(let t of["arctan(+inf) -> \u03C0/2","arctan(-inf) -> -\u03C0/2","arccot(+inf) -> 0","arccot(-inf) -> \u03C0","arcsec(\xB1inf) -> \u03C0/2","arccsc(\xB1inf) -> 0","sinh(+inf) -> +inf","sinh(-inf) -> -inf","cosh(+inf) -> +inf","cosh(-inf) -> +inf","tanh(+inf) -> 1","tanh(-inf) -> -1","coth(+inf) -> 1","coth(-inf) -> -1","sech(+inf) -> 0","sech(-inf) -> 0","csch(+inf) -> 0","csch(-inf) -> 0","arsinh(+inf) -> +inf","arsinh(-inf) -> -inf","arcosh(+inf) -> +inf","arcoth(\xB1inf) -> 0","arcsch(\xB1inf) -> 0","ln(+inf) -> +inf","log_c(+inf) -> +inf when c > 1","log_c(+inf) -> -inf when 0 < c < 1","log_c(0) -> -inf when c > 1","log_c(0) -> +inf when 0 < c < 1","log_inf(x) -> 0","root(+inf, n) -> +inf when n > 0"])n[t]="Evaluate the limit at infinity";for(let t of["artanh(\xB1inf) -> NaN","arsech(\xB1inf) -> NaN","arcosh(-inf) -> NaN","log_inf(inf) -> NaN"])n[t]="The value is undefined at infinity";for(let t of["root(x, 0) -> NaN","root(0, n) -> NaN when n <= 0"])n[t]="The root is undefined";Ee(n)}function Rl(e){let n=e.index;e.skipVisualSpace();let t=!1;return e.match("(")&&(e.skipVisualSpace(),t=e.peek==="\\bmod"||e.peek==="\\pmod"||e.peek==="\\mod"||e.matchAll(["m","o","d"])),e.index=n,t}function Cl(e,n){let t=e.index;if(e.skipVisualSpace(),e.match("(")){if(e.skipVisualSpace(),e.match("\\bmod")||e.match("\\pmod")||e.match("\\mod")||e.matchAll(["m","o","d"])){e.skipVisualSpace();let s=e.parseExpression({...n,minPrec:0})??e.parseGroup();if(e.skipVisualSpace(),s!==null&&e.match(")"))return s}return e.index=t,null}let i=e.parseExpression({...n,minPrec:$e});if(i!==null&&d(i)==="Mod"){let r=A(i)>=2?c(i,2):c(i,1);if(r!==null)return r}return e.index=t,null}function On(e,n,t){let i=e.parseExpression({...t,minPrec:S,condition:s=>Rl(s)||(t.condition?.(s)??!1)}),r=Cl(e,t);return r!==null?d(n)==="Congruent"?["And",n,["Congruent",P(c(n,2)),P(i),r]]:["Congruent",n,P(i),r]:["Equivalent",n,P(i)]}var Ro=[{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:"\\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:["\\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:S,parse:On},{latexTrigger:["\u2261"],kind:"infix",associativity:"right",precedence:S,parse:On},{latexTrigger:["\\equiv"],kind:"prefix",precedence:S,parse:(e,n)=>On(e,e.error("missing",e.index),n??{minPrec:0})},{latexTrigger:["\\not","\\equiv"],kind:"infix",associativity:"right",precedence:S,parse:(e,n,t)=>["Not",On(e,n,t)]},{latexTrigger:["\u2262"],kind:"infix",associativity:"right",precedence:S,parse:(e,n,t)=>["Not",On(e,n,t)]},{latexTrigger:["\\pmod"],kind:"infix",precedence:S-1,parse:(e,n)=>{let t=e.parseGroup()??e.parseToken();return["Mod",n,P(t)]}},{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:Fn("\\forall"),parse:_e("ForAll")},{name:"Exists",kind:"prefix",latexTrigger:["\\exists"],precedence:200,serialize:Fn("\\exists"),parse:_e("Exists")},{name:"ExistsUnique",kind:"prefix",latexTrigger:["\\exists","!"],precedence:200,serialize:Fn("\\exists!"),parse:_e("ExistsUnique")},{name:"NotForAll",kind:"prefix",latexTrigger:["\\lnot","\\forall"],precedence:200,serialize:Fn("\\lnot\\forall"),parse:_e("NotForAll")},{name:"NotExists",kind:"prefix",latexTrigger:["\\lnot","\\exists"],precedence:200,serialize:Fn("\\lnot\\exists"),parse:_e("NotExists")},{name:"KroneckerDelta",kind:"prefix",latexTrigger:["\\delta","_"],precedence:200,serialize:(e,n)=>{let t=b(n);return t.length===0?"\\delta":t.every(i=>y(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=Ne(n);return t&&t.length<=2?["KroneckerDelta",...t]:d(n)==="InvisibleOperator"?["KroneckerDelta",...b(n)]:n!==null?["KroneckerDelta",n]:null}},{name:"Boole",kind:"matchfix",openTrigger:"[",closeTrigger:"]",parse:(e,n)=>{let t=d(n);return!t||!cn.some(i=>i.name===t)?null:["Boole",n]}},{kind:"matchfix",openTrigger:"\\llbracket",closeTrigger:"\\rrbracket",parse:(e,n)=>{let t=d(n);return!t||!cn.some(i=>i.name===t)?null:["Boole",n]}},{name:"Predicate",serialize:(e,n)=>{let t=b(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 Fn(e){return(n,t)=>{let i=b(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 _o(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 _e(e){return(n,t)=>{let i=n.index,r=n.diagnosticsCheckpoint(),s=n.options.quantifierScope!=="loose",o=n.parseSymbol(t),a=typeof o=="string"?o:null;if(o){if(n.skipSpace(),n.match(",")||n.match("\\mid")||n.match(".")||n.match(":")||n.match("\\colon")){let p=s?{...t,condition:h=>_o(h,t)}:t;n.enterQuantifierScope();let g=n.parseExpression(p);return n.exitQuantifierScope(),a&&n.pruneUndeclared([a],r),[e,o,P(g)]}n.enterQuantifierScope();let f=n.parseEnclosure();if(n.exitQuantifierScope(),f)return a&&n.pruneUndeclared([a],r),[e,o,P(f)]}n.index=i;let u={...t,condition:f=>f.peek===":"||f.peek==="\\colon"||(t?.condition?.(f)??!1)},l=n.parseExpression(u);if(l===null)return null;if(n.skipSpace(),n.matchAny([",","\\mid",":","\\colon"])){let f=s?{...t,condition:g=>_o(g,t)}:t;n.enterQuantifierScope();let p=n.parseExpression(f);return n.exitQuantifierScope(),[e,l,P(p)]}if(n.match("(")){n.enterQuantifierScope();let f=n.parseExpression(t);return n.exitQuantifierScope(),n.match(")")?[e,l,P(f)]:null}return d(l)!==""?[e,l,"True"]:null}}var Bl={x:"PointX",y:"PointY",z:"PointZ",real:"Real",re:"Real",imag:"Imaginary",im:"Imaginary",count:"Length",length:"Length",total:"Sum",max:"Max",min:"Min"};function $r(e){return Bl[e]??null}function Co(e){let n=null;if(typeof e=="number")Number.isSafeInteger(e)&&e>=0&&(n=e.toString());else if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.num=="string"){let t=e.num;/^[0-9]+$/.test(t)&&(n=t)}return n===null||!/^[0-9]+$/.test(n)?null:n}function Ol(e,n){if(!(typeof n=="number"&&Number.isInteger(n)&&n>=2)){let a=y(n);if(a===null||a==="Nothing")return null;let u=Co(e);if(u===null)return null;let l=[],f=u.length;for(let g=0;g<f;g++){let h=u.charCodeAt(g)-48;if(h===0)continue;let N=f-1-g;if(N===0)l.push(h);else if(N===1)l.push(h===1?a:["Multiply",h,a]);else{let I=["Power",a,N];l.push(h===1?I:["Multiply",h,I])}}return["BaseForm",l.length===0?0:l.length===1?l[0]:["Add",...l],a]}let t=n,i=Co(e);if(i===null)return null;let r=BigInt(t),s=0n;for(let a=0;a<i.length;a++){let u=i.charCodeAt(a)-48;if(u>=t)return null;s=s*r+BigInt(u)}return["BaseForm",s<=BigInt(Number.MAX_SAFE_INTEGER)?Number(s):{num:s.toString()},t]}function Fl(e){if(typeof e=="number")return Number.isSafeInteger(e)?BigInt(e):null;if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.num=="string"){let n=e.num;if(/^[+-]?[0-9]+$/.test(n))return BigInt(n)}return null}function Jl(e,n){if(e==null)return null;let t=d(e)==="Add"?[...b(e)]:[e],i=new Map;for(let o of t){let a,u,l=p=>{if(y(p)===n)return 1;if(d(p)==="Square"&&y(c(p,1))===n)return 2;if(d(p)==="Power"&&y(c(p,1))===n){let g=M(c(p,2));return g===null?null:g}return null},f=y(o);if(f!==null){if(f!==n)return null;a=1,u=1}else if(d(o)==="Power"||d(o)==="Square"){let p=l(o);if(p===null)return null;a=1,u=p}else if(d(o)==="Multiply"){let p=[...b(o)];if(p.length!==2)return null;let g=M(p[0]);if(g===null)return null;a=g;let h=l(p[1]);if(h===null)return null;u=h}else{let p=M(o);if(p===null)return null;a=p,u=0}if(!Number.isInteger(a)||a<0||a>9||!Number.isInteger(u)||u<0||u>40||i.has(u))return null;i.set(u,a)}let r=Math.max(0,...i.keys()),s="";for(let o=r;o>=0;o--)s+=String(i.get(o)??0);return s}function Ll(e,n){if(e===0n)return"0";let t=BigInt(n),i=[],r=e;for(;r>0n;){let s=Number(r%t);if(s<10)i.push(String.fromCharCode(48+s));else if(s<36)i.push(String.fromCharCode(97+s-10));else return null;r=r/t}return i.reverse().join("")}function Vl(e,n){if(e.skipVisualSpace(),!ce(n)&&typeof e.peek=="string"&&/^\d$/.test(e.peek)){let i="";for(;typeof e.peek=="string"&&/^\d$/.test(e.peek);)i+=e.nextToken();return["InvisibleOperator",n,{num:"0."+i}]}if(e.match("\\operatorname")){let i=e.parseStringGroup();if(i===null)return null;let r=$r(i.trim());return r===null?null:[r,n]}let t=e.peek;if(typeof t=="string"&&t.startsWith("\\")){let i=t.slice(1),r=$r(i);return r!==null?(e.nextToken(),[r,n]):null}if(typeof t=="string"&&/^[a-zA-Z]$/.test(t)){let i=y(n);if(i!==null&&e.getSymbolType(i).matches("dictionary")){let s="";for(;typeof e.peek=="string"&&/^[a-zA-Z]$/.test(e.peek);)s+=e.nextToken();return["At",n,{str:s}]}let r=$r(t);return r===null?null:(e.nextToken(),[r,n])}return null}function ql(e){let n=e;return d(n)==="Delimiter"&&(n=c(n,1)??n),d(n)==="Sequence"?b(n):[e]}function Go(e){let n=d(e);return Rt(n)||Ct(n)||["And","Or","Not","Element","NotElement"].includes(n)}function $l(e){let n=[];for(let t=0;t<e.length;t++){let i=e[t];if(d(i)==="Colon"&&A(i)===2)n.push(c(i,1),c(i,2));else if(Go(i))n.push(i,1);else if(t===e.length-1)n.push("True",i);else return null}return n}function Bo(e,n,t){e.addBoundary(t),e.skipVisualSpace();let i=e.parseExpression({minPrec:0});if(i===null||(e.skipVisualSpace(),!e.matchBoundary()))return e.removeBoundary(),null;let r=ql(i);if(r.length>1||d(r[0])==="Colon"){if(r.some(s=>d(s)==="Colon")){let s=$l(r);if(s!==null)return["Multiply",n,["Which",...s]]}else if(r.every(Go))return["When",n,["Or",...r]]}return["When",n,i]}var jl={"+":"Add","-":"Subtract","*":"Multiply","\\cdot":"Multiply","\\times":"Multiply","\\circ":"Ring","\\cup":"Union","\\cap":"Intersection","\\oplus":"CirclePlus","\\otimes":"CircleTimes","\\star":"Star"};function Gl(e,n,t){let i=jl[e.peek];if(i===void 0)return null;let r=e.index;return e.nextToken(),e.skipSpace(),e.peek===t||e.atTerminator(n)?i:(e.index=r,null)}function jr(e,n,t,i,r){if(n&&n.minPrec>=i)return null;let s=u=>{d(u)==="Sequence"?o.push(...b(u)):o.push(u)},o=[];t?s(t):o.push("Nothing");let a=!1;for(;!a;){for(a=!0,e.skipSpace();e.match(r);)o.push("Nothing"),e.skipSpace();if(e.skipVisualSpace(),e.atTerminator(n))o.push("Nothing");else{let u=Gl(e,n,r);if(u!==null)o.push(u),a=!1;else{let l=e.parseExpression({...n,minPrec:i});l!==null?s(l):o.push("Nothing"),a=l===null}}a||(e.skipSpace(),a=!e.match(r),a||e.skipVisualSpace())}return o}function zl(e,n){if(!n)return"";let t=b(n);if(t.length===0)return"";if(t.length===1)return e.serialize(t[0]);let i=t.map(s=>e.serialize(s)),r=[i[0]];for(let s=1;s<i.length;s++){let o=i[s-1],a=i[s],u=/[0-9]$/.test(o)&&/^[-+0-9]/.test(a);r.push(u?", ":" ",a)}return E(r)}function Zl(e,n){let t=d(n);if(t!=="Divide"&&t!=="Rational"||A(n)!==2||!e.options.prettify)return!1;let i=e.options.fractionStyle(n,e.level+1);return i==="inline-solidus"||i==="nice-solidus"}function Ul(e,n){if(!n)return"";let t=b(n);return t.length===0?"":t.length===1?e.serialize(t[0]):E(t.map((i,r)=>{let s=e.serialize(i);return r<t.length-1&&Zl(e,i)?e.wrapString(s,e.groupStyle(n,e.level+1)):s}))}function ze(e=""){return(n,t)=>{if(!t)return"";let i=b(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(),E(r)}}var Hl=[{surface:"if",kind:"prefix",precedence:245,operatorname:!0,build:ac},{surface:"for",kind:"prefix",precedence:245,operatorname:!0,build:uc},{surface:"for",kind:"infix",precedence:19,associativity:"none",operatorname:!0,build:(e,n,t)=>{let i=e.index,r=Xo(e,n,t);if(r!==null)return r;e.index=i;let s=$o(e,t);return s===null?(e.index=i,null):["ForAll",s,jo(n)]}},{surface:"break",kind:"prefix",precedence:245,operatorname:!0,build:()=>["Break"]},{surface:"continue",kind:"prefix",precedence:245,operatorname:!0,build:()=>["Continue"]},{surface:"return",kind:"prefix",precedence:245,operatorname:!0,build:(e,n)=>["Return",e.parseExpression(n)??"Nothing"]},{surface:"for all",kind:"prefix",precedence:200,build:(e,n)=>_e("ForAll")(e,n)},{surface:"for all",kind:"infix",precedence:19,associativity:"none",build:(e,n,t)=>{let i=e.index,r=$o(e,t);return r===null?(e.index=i,null):["ForAll",r,jo(n)]}},{surface:"there exists",kind:"prefix",precedence:200,build:(e,n)=>_e("Exists")(e,n)},{surface:"where",kind:"infix",precedence:21,associativity:"none",operatorname:!0,build:(e,n,t)=>cc(e,n,t)},{surface:"such that",kind:"infix",precedence:21,associativity:"right",build:(e,n,t)=>["Colon",n,e.parseExpression({...t,minPrec:21})??"Nothing"]},{surface:"and",kind:"prefix",precedence:235,build:(e,n)=>(e.skipVisualSpace(),e.parseExpression(n)??"Nothing")},{surface:"and",kind:"infix",precedence:235,associativity:"right",build:(e,n,t)=>["And",n,e.parseExpression({...t,minPrec:235})??"Nothing"]},{surface:"or",kind:"infix",precedence:230,associativity:"right",build:(e,n,t)=>["Or",n,e.parseExpression({...t,minPrec:230})??"Nothing"]},{surface:"iff",kind:"infix",precedence:219,associativity:"right",build:(e,n,t)=>["Equivalent",n,e.parseExpression({...t,minPrec:219})??"Nothing"]},{surface:"if and only if",kind:"infix",precedence:219,associativity:"right",build:(e,n,t)=>["Equivalent",n,e.parseExpression({...t,minPrec:219})??"Nothing"]}];function Wl(){let e=[];for(let n of Hl){let t=n.surface;for(let i of["\\text","\\keyword"])if(n.kind==="prefix"){let r=n.build;e.push({latexTrigger:[i],kind:"prefix",precedence:n.precedence,parse:(s,o)=>{let a=s.index;return Zr(s,t)?r(s,o):(s.index=a,null)}})}else{let r=n.build;e.push({latexTrigger:[i],kind:"infix",associativity:n.associativity??"right",precedence:n.precedence,parse:(s,o,a)=>{let u=s.index;return Zr(s,t)?r(s,o,a):(s.index=u,null)}})}if(n.operatorname)if(n.kind==="prefix"){let i=n.build;e.push({symbolTrigger:t,kind:"prefix",precedence:n.precedence,parse:(r,s)=>i(r,s)})}else{let i=n.build;e.push({symbolTrigger:t,kind:"infix",associativity:n.associativity??"right",precedence:n.precedence,parse:(r,s,o)=>i(r,s,o)})}}return e.push({latexTrigger:["\\keyword"],parse:n=>$(n)}),e}function fe(e,n,t){let i=e.options.keywordStyle??"text";if(i==="keyword")return`\\keyword{${n}}`;if(i==="operatorname")return`\\operatorname{${n}}`;let r=t?.lead?" ":"",s=t?.trail?" ":"";return`\\text{${r}${n}${s}}`}var ve="topic_marker";function zo(e,n){if(y(e)===ve)return[n,!0];let t=d(e);if(!t)return[e,!1];let i=!1,r=b(e).map(s=>{let[o,a]=zo(s,n);return a&&(i=!0),o});return i?[[t,...r],!0]:[e,!1]}function Zo(e,n){let[t,i]=zo(e,n);return i?t:["Apply",e,n]}function Jn(e,n,t){let i=e.parseExpression({minPrec:21})??"Nothing";return Zo(i,n)}function Ln(e,n){let t=e.parseExpression({minPrec:21})??"Nothing",i="_";return["Function",Zo(t,i),i]}var Uo=[{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:["\\cdots"],parse:"ContinuationPlaceholder"},{latexTrigger:["\\dotsb"],parse:"ContinuationPlaceholder"},{latexTrigger:["\\dotsc"],parse:"ContinuationPlaceholder"},{latexTrigger:["\\dotsm"],parse:"ContinuationPlaceholder"},{latexTrigger:["\u2026"],parse:"ContinuationPlaceholder"},{latexTrigger:[".",".","."],parse:"ContinuationPlaceholder"},{latexTrigger:["\\vdots"],parse:"ContinuationPlaceholder"},{latexTrigger:["\\ddots"],parse:"ContinuationPlaceholder"},{name:"Typed",serialize:(e,n)=>e.serialize(c(n,1))},{name:"Function",latexTrigger:["\\mapsto"],kind:"infix",precedence:le,parse:(e,n,t)=>{let i=e.operandDiagnosticCheckpoint,r=[];if(d(n)==="Delimiter"&&(n=c(n,1)??"Nothing"),d(n)==="Sequence")for(let o of b(n)){if(!y(o))return null;r.push(y(o))}else{if(!y(n))return null;r=[y(n)]}let s=e.parseExpression({...t??{},minPrec:21})??"Nothing";return d(s)==="Delimiter"&&(s=c(s,1)??"Nothing"),d(s)==="Sequence"&&(s=["Block",...b(s)]),e.pruneUndeclared(r,i),["Function",s,...r]},serialize:(e,n)=>{let t=b(n),i=r=>d(r)==="Typed"?c(r,1)??r:r;return t.length<1?"()\\mapsto()":t.length===1?E(["()","\\mapsto",e.serialize(c(n,1))]):t.length===2?E([e.serialize(i(c(n,2))),"\\mapsto",e.serialize(c(n,1))]):E([e.wrapString(b(n)?.slice(1).map(r=>e.serialize(i(r))).join(", "),"normal"),"\\mapsto",e.serialize(c(n,1))])}},{name:"Apply",kind:"function",symbolTrigger:"apply",serialize:(e,n)=>{let t=c(n,1),i=d(t);if(i==="Derivative"){let o=Kl(e,n);if(o!==null)return o}if(i==="InverseFunction"||i==="Derivative"){let o=e.options.applyFunctionStyle(n,e.level),a=b(n).slice(1);return e.serializeFunction(t,e.dictionary.ids.get(i))+e.wrapString(a.map(u=>e.serialize(u)).join(", "),o)}let r=c(n,2);if(typeof t=="string"||!r){let o=b(n);return e.serialize(o)}if(A(n)===2)return E([e.wrap(t,20),"\\lhd",e.wrap(r,20)]);let s=e.options.applyFunctionStyle(n,e.level);return E(["\\operatorname{apply}",e.wrapString(e.serialize(i)+", "+e.serialize(["List",...b(n)]),s)])}},{latexTrigger:"\\lhd",kind:"infix",precedence:20,parse:"Apply"},{name:ve,serialize:"\\square"},{latexTrigger:"\\rhd",kind:"infix",precedence:20,parse:Jn},{latexTrigger:"\\triangleright",kind:"infix",precedence:20,parse:Jn},{latexTrigger:"\\vartriangleright",kind:"infix",precedence:20,parse:Jn},{latexTrigger:"|>",kind:"infix",precedence:20,parse:Jn},{latexTrigger:["\u22B3"],kind:"infix",precedence:20,parse:Jn},{latexTrigger:"|>",kind:"prefix",precedence:20,parse:Ln},{latexTrigger:"\\rhd",kind:"prefix",precedence:20,parse:Ln},{latexTrigger:"\\triangleright",kind:"prefix",precedence:20,parse:Ln},{latexTrigger:"\\vartriangleright",kind:"prefix",precedence:20,parse:Ln},{latexTrigger:["\u22B3"],kind:"prefix",precedence:20,parse:Ln},{name:"EvaluateAt",openTrigger:".",closeTrigger:"|",kind:"matchfix",serialize:(e,n)=>{let t=c(n,1);if(!t)return"";let i=b(n).slice(1);if(d(t)==="Function"){let r=b(t).slice(1),s=c(t,1);if(d(s)==="Block"&&A(s)===1&&(s=c(s,1)),r.length===1&&i.length===2)return`\\left.\\left(${e.serialize(s)}\\right)\\right|_{${e.serialize(i[0])}}^{${e.serialize(i[1])}}`;if(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:An,serialize:(e,n)=>{let t=Jr(c(n,1));if(d(c(n,2))==="Function"){let i=c(n,2),r=Jr(c(i,1)),s=b(i).slice(1);return E([e.serialize(t),e.wrapString(s.map(o=>e.serialize(o)).join(", "),e.options.applyFunctionStyle(n,e.level)),"\\coloneq",e.serialize(r)])}return E([e.serialize(t),"\\coloneq",e.serialize(c(n,2))])},parse:Ht},{latexTrigger:"\\coloneqq",kind:"infix",associativity:"right",precedence:An,parse:Ht},{latexTrigger:"\\colonequals",kind:"infix",associativity:"right",precedence:An,parse:Ht},{latexTrigger:[":","="],kind:"infix",associativity:"right",precedence:An,parse:Ht},{name:"Colon",latexTrigger:":",kind:"infix",associativity:"right",precedence:240,serialize:(e,n)=>E([e.serialize(c(n,1)),"\\colon",e.serialize(c(n,2))])},{latexTrigger:"\\colon",kind:"infix",associativity:"right",precedence:240,parse:"Colon"},{name:"BaseForm",serialize:(e,n)=>{let t=M(c(n,2))??NaN;if(isFinite(t)&&t>=2&&Number.isInteger(t)){let r=Fl(c(n,1));if(r!==null&&r>=0n){let s=Ll(r,t);if(s!==null)return/^[0-9]+$/.test(s)?`${s}_{${t}}`:`\\mathrm{${s}}_{${t}}`}}let i=y(c(n,2));if(i!==null){let r=Jl(c(n,1),i);if(r!==null)return`${r}_{${i}}`}return"\\operatorname{BaseForm}("+e.serialize(c(n,1))+", "+e.serialize(c(n,2))+")"}},{name:"Sequence",serialize:zl},{name:"InvisibleOperator",serialize:Ul},{name:"Delimiter",serialize:(e,n)=>{let t=e.options.groupStyle(n,e.level+1),i=c(n,1),r={Set:"{,}",List:"[,]",Tuple:"(,)",Single:"(,)",Pair:"(,)",Triple:"(,)",Sequence:"(,)",String:'""'}[d(i)],s=r?i:["Sequence",i];if(r??="(,)",A(n)>1){let f=w(c(n,2));typeof f=="string"&&f.length<=3&&(r=f)}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?ze(a)(e,s):e.serialize(i):"";return e.wrapString(l,t,o+u)}},{name:"Tuple",serialize:(e,n)=>E(["(",ze(",")(e,n),")"])},{name:"Pair",serialize:(e,n)=>E(["(",ze(",")(e,n),")"])},{name:"Triple",serialize:(e,n)=>E(["(",ze(",")(e,n),")"])},{name:"Single",serialize:(e,n)=>E(["(",ze(",")(e,n),")"])},{name:"Domain",serialize:(e,n)=>d(n)==="Error"?e.serialize(n):`\\mathbf{${e.serialize(c(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=c(n,1);if(w(t)==="missing")return`\\error{${e.options.missingSymbol??"\\placeholder{}"}}`;let i=Xl(e,n)||"\\blacksquare",r=d(t)==="ErrorCode"?w(c(t,1)):w(t);return r==="incompatible-type"?y(c(t,3))==="Undefined"?`\\mathtip{\\error{${i}}}{\\notin ${e.serialize(c(t,2))}}`:`\\mathtip{\\error{${i}}}{\\in ${e.serialize(c(t,3))}\\notin ${e.serialize(c(t,2))}}`:typeof r=="string"?`\\error{${i}}`:`\\error{${i}}`}},{name:"ErrorCode",serialize:(e,n)=>{let t=w(c(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{${Oo(w(c(n,1)))}}`},{name:"Latex",serialize:(e,n)=>n===null?"":E(zt(n,t=>w(t)??e.serialize(t)))},{name:"LatexString",serialize:(e,n)=>n===null?"":E(zt(n,t=>e.serialize(t)))},{name:"LatexTokens",serialize:Yl},{kind:"postfix",precedence:850,latexTrigger:["."],parse:Vl},{name:"At",kind:"postfix",precedence:810,latexTrigger:["["],parse:Wt("]"),serialize:(e,n)=>{let t=b(n),i=e.wrap(t[0]??"Nothing",$e),r=t.slice(1).map(s=>e.serialize(s));return e.indexStyle(n,e.level)==="bracket"?E([i,"[",r.join(", "),"]"]):Ve("_",i,r.join(","))}},{kind:"postfix",precedence:810,latexTrigger:["\\lbrack"],parse:Wt("\\rbrack")},{kind:"postfix",precedence:810,latexTrigger:["\\left","\\lbrack"],parse:Wt("\\right","\\rbrack")},{kind:"postfix",precedence:810,latexTrigger:["\\left","["],parse:Wt("\\right","]")},{name:"When",kind:"postfix",precedence:800,latexTrigger:["\\left","\\{"],parse:(e,n)=>Bo(e,n,["\\right","\\}"]),serialize:(e,n)=>{let t=c(n,1),i=c(n,2);if(!t||!i)return"";let s=(d(i)==="And"?b(i)??[]:[i]).map(o=>`\\left\\{${e.serialize(o)}\\right\\}`).join("");return`${e.serialize(t)}${s}`}},{kind:"postfix",precedence:800,latexTrigger:["\\{"],parse:(e,n)=>Bo(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=y(n);if(i!==null&&(r&&e.getSymbolType(r).matches("indexed_collection")||d(n)==="List"))return d(i)==="Delimiter"&&(i=c(i,1)??"Nothing"),d(i)==="Sequence"?["At",n,...b(i)]:["At",n,i];if(i!==null){let s=Ol(n,i);if(s!==null)return s}return i!==null&&y(i)==="Nothing"?n:["Subscript",n,i]}},{name:"List",kind:"matchfix",openTrigger:"[",closeTrigger:"]",parse:Ho,serialize:rc},{kind:"matchfix",openTrigger:"(",closeTrigger:")",parse:Ql},{name:"AngleBracket",kind:"matchfix",openTrigger:["\\langle"],closeTrigger:["\\rangle"],parse:(e,n)=>{if(n===null||R(n))return["AngleBracket"];let t=n;return d(t)==="Delimiter"&&(t=c(t,1)??t),d(t)==="Sequence"||d(t)==="List"?["AngleBracket",...b(t)]:["AngleBracket",t]},serialize:(e,n)=>E(["\\langle ",b(n).map(t=>e.serialize(t)).join(", ")," \\rangle"])},{latexTrigger:[","],kind:"infix",precedence:20,parse:(e,n,t)=>{let i=jr(e,t,n,20,",");return i===null?null:["Delimiter",["Sequence",...i],{str:","}]}},{latexTrigger:[","],kind:"prefix",precedence:20,parse:(e,n)=>{let t=jr(e,n,null,20,",");return t===null?null:["Delimiter",["Sequence",...t],{str:","}]}},{name:"Range",latexTrigger:[".","."],kind:"infix",precedence:800,parse:(e,n)=>e.peek==="."?null:Ut(e,n),serialize:(e,n)=>{let t=b(n);if(t.length===0)return"";if(t.length===1)return"1.."+e.serialize(c(n,1));if(t.length===2)return e.wrap(c(n,1),800)+".."+e.wrap(c(n,2),800);if(t.length===3){let i=M(c(n,3)),r=M(c(n,1));return i!==null&&r!==null?e.wrap(c(n,1),800)+".."+e.wrap(r+i,800)+".."+e.wrap(c(n,2),800):e.wrap(c(n,1),800)+"..("+(e.wrap(c(n,1),O)+"+"+e.wrap(c(n,3),O))+").."+e.wrap(c(n,2),800)}return""}},{latexTrigger:[".",".","."],kind:"infix",precedence:qe-10,parse:(e,n)=>Ut(e,n,!0)},{latexTrigger:["\\ldots"],kind:"infix",precedence:qe-10,parse:(e,n)=>Ut(e,n,!0)},{latexTrigger:["\\dots"],kind:"infix",precedence:qe-10,parse:(e,n)=>Ut(e,n,!0)},{latexTrigger:[";"],kind:"infix",precedence:19,parse:(e,n,t)=>{let i=jr(e,t,n,19,";");return i===null?null:i.some(r=>d(r)==="Assign")?fc(i):["Delimiter",["Sequence",...i],"';'"]}},...Wl(),{name:"Block",serialize:(e,n)=>{let t=b(n);return!t||t.length===0?"":t.filter(r=>d(r)!=="Declare").map(r=>e.serialize(r)).join("; ")}},{name:"If",serialize:(e,n)=>{let t=b(n);return!t||t.length<3?"":E([fe(e,"if",{trail:!0}),e.serialize(t[0]),fe(e,"then",{lead:!0,trail:!0}),e.serialize(t[1]),fe(e,"else",{lead:!0,trail:!0}),e.serialize(t[2])])}},{name:"Loop",serialize:(e,n)=>{let t=b(n);if(!t||t.length===0)return"";let i=t[0],r=t.slice(1);if(r.length===1&&d(r[0])==="Element"){let s=r[0],o=c(s,1),a=c(s,2);if(d(a)==="Range"){let u=c(a,1),l=c(a,2);return E([fe(e,"for",{trail:!0}),e.serialize(o),fe(e,"from",{lead:!0,trail:!0}),e.serialize(u),fe(e,"to",{lead:!0,trail:!0}),e.serialize(l),fe(e,"do",{lead:!0,trail:!0}),e.serialize(i)])}}return E(["\\operatorname{Loop}(",t.map(s=>e.serialize(s)).join(", "),")"])}},{name:"Comprehension",serialize:(e,n)=>{let t=b(n);if(!t||t.length<2)return"";let i=t[0],s=t.slice(1).map(o=>{let a=c(o,1),u=c(o,2);return E([e.serialize(a)," = ",e.serialize(u)])}).join(", ");return E([e.serialize(i)," \\operatorname{for} ",s])}},{name:"Break",serialize:e=>fe(e,"break")},{name:"Continue",serialize:e=>fe(e,"continue")},{name:"Return",serialize:(e,n)=>{let t=c(n,1);return!t||y(t)==="Nothing"?fe(e,"return"):E([fe(e,"return",{trail:!0}),e.serialize(t)])}},{name:"Text",serialize:(e,n)=>{let t=b(n);if(t.length===0)return"";let i=-1,r=-1;for(let a=0;a<t.length;a++)w(t[a])!==null&&(i<0&&(i=a),r=a);if(i<0)return E(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=w(t[a]);u!==null?o+=Oo(u):d(t[a])==="Annotated"||d(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 E(s)}},{name:"String",latexTrigger:["\\text"],parse:e=>$(e),serialize:(e,n)=>{let t=b(n);return t.length===0?"\\text{}":E(["\\text{",t.map(i=>e.serialize(i)).join(""),"}"])}},{name:"Subscript",latexTrigger:["_"],kind:"infix",serialize:(e,n)=>A(n)===2?e.serialize(c(n,1))+"_{"+e.serialize(c(n,2))+"}":"_{"+e.serialize(c(n,1))+"}"},{name:"IndexedSequence",serialize:(e,n)=>{let t=zr(c(n,1)),i=c(n,2),r=c(n,3),s=A(n)>=4?b(n)?.[3]??null:null,o=`\\left\\{${e.serialize(t)}\\right\\}_{${e.serialize(i)}=${e.serialize(r)}}`;return s===null?o:`${o}^{${e.serialize(s)}}`}},{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)=>Te(e,n,1),serialize:(e,n)=>{let t=M(c(n,2))??1,i=e.serialize(c(n,1));return t===1?i+"^\\prime":t===2?i+"^\\doubleprime":t===3?i+"^\\tripleprime":i+"^{("+e.serialize(c(n,2))+")}"}},{latexTrigger:"^{\\prime\\prime}",kind:"postfix",parse:(e,n)=>Te(e,n,2)},{latexTrigger:"^{\\prime\\prime\\prime}",kind:"postfix",parse:(e,n)=>Te(e,n,3)},{latexTrigger:["^","\\doubleprime"],kind:"postfix",parse:(e,n)=>Te(e,n,2)},{latexTrigger:["^","\\tripleprime"],kind:"postfix",parse:(e,n)=>Te(e,n,3)},{latexTrigger:"'",kind:"postfix",precedence:810,parse:(e,n)=>Te(e,n,1)},{latexTrigger:"\\prime",kind:"postfix",precedence:810,parse:(e,n)=>Te(e,n,1)},{latexTrigger:"\\doubleprime",kind:"postfix",precedence:810,parse:(e,n)=>Te(e,n,2)},{latexTrigger:"\\tripleprime",kind:"postfix",precedence:810,parse:(e,n)=>Te(e,n,3)},{latexTrigger:["^","<{>","("],kind:"postfix",parse:(e,n,t)=>{let i=y(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(d(n)==="Matrix")return e.match("<}>"),["Inverse",n];let t=y(n);if(!t)return null;let i=e.getSymbolType(t);if(i.matches(new G("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(c(n,1))+"^{-1}"},{name:"Derivative",serialize:(e,n)=>{let t=e.serialize(c(n,1)),i=b(n).slice(1);if(i.length>1)return t+"^{("+i.map(s=>e.serialize(s)).join(", ")+")}";let r=M(i[0])??1;return r===1?t+"^{\\prime}":r===2?t+"^{\\doubleprime}":r===3?t+"^{\\tripleprime}":t+"^{("+e.serialize(i[0])+")}"}},{name:"D",serialize:(e,n)=>{if(d(n)!=="D")return"D";let t=c(n,1),i=c(n,2);if(!t||!i)return"D";let r=1,s=t;for(;d(s)==="D";){let l=c(s,2);if(y(l)===y(i))r++,s=c(s,1);else break}let o=s;d(s)==="Function"&&(o=c(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=M(o)??1}else i=!0;if(!t||y(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:Gr,serialize:(e,n)=>{let t=[],i=b(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 E(["\\begin{cases}",t.join("\\\\"),"\\end{cases}"])}},{kind:"environment",symbolTrigger:"dcases",parse:Gr},{kind:"environment",symbolTrigger:"rcases",parse:Gr},{kind:"environment",symbolTrigger:"aligned",parse:pe},{kind:"environment",symbolTrigger:"aligned*",parse:pe},{kind:"environment",symbolTrigger:"align",parse:pe},{kind:"environment",symbolTrigger:"align*",parse:pe},{kind:"environment",symbolTrigger:"gather",parse:pe},{kind:"environment",symbolTrigger:"gather*",parse:pe},{kind:"environment",symbolTrigger:"gathered",parse:pe},{kind:"environment",symbolTrigger:"split",parse:pe},{kind:"environment",symbolTrigger:"multline",parse:pe},{kind:"environment",symbolTrigger:"multline*",parse:pe},{kind:"environment",symbolTrigger:"eqnarray",parse:pe}];function $(e,n){if(!e.match("<{>"))return"''";let t=[],i="",r=null,s=()=>{r!==null&&i?t.push(["Annotated",`'${i}'`,Gt(r)]):i&&t.push(`'${i}'`),i="",r=null};for(;!e.atEnd&&!e.match("<}>");)if(e.peek==="<{>")s(),t.push($(e));else if(e.match("\\textbf"))s(),t.push($(e,{fontWeight:"bold"}));else if(e.match("\\textmd"))s(),t.push($(e,{fontStyle:"normal"}));else if(e.match("\\textup"))s(),t.push($(e,{fontStyle:"normal"}));else if(e.match("\\textsl"))s(),t.push($(e,{fontStyle:"italic"}));else if(e.match("\\textit"))s(),t.push($(e,{fontStyle:"italic"}));else if(e.match("\\texttt"))s(),t.push($(e,{fontFamily:"monospace"}));else if(e.match("\\textsf"))s(),t.push($(e,{fontFamily:"sans-serif"}));else if(e.match("\\textcolor")){let a=e.index,u=e.parseStringGroup();if(u!==null){s();let l=$(e);t.push(["Annotated",l,Gt({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=>w(a)!==null)?o="'"+t.map(a=>w(a)).join("")+"'":o=["Text",...t],n?["Annotated",o,Gt(n)]:o}function Yl(e,n){return n===null?"":E(zt(n,t=>{let i=w(t);return i===null?e.serialize(t):i==="<{>"?"{":i==="<}>"?"}":i==="<$>"?"$":i==="<$$>"?"$$":i==="<space>"?" ":i}))}function Oo(e){return e===null?"":e.replace(/[{}\[\]\\:\-\$%]/g,n=>({"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "})[n]??"\\"+n)}function Xl(e,n){let t=c(n,2);return t?d(t)==="LatexString"?w(c(t,1))??"":d(t)==="Hold"?e.serialize(c(t,1)):e.serialize(t):""}function Kl(e,n){let t=c(n,1);if(d(t)!=="Derivative")return null;let i=[];for(let f of b(t).slice(1)){let p=M(f);if(p===null||!Number.isInteger(p)||p<0)return null;i.push(p)}if(i.length<2)return null;let r=b(n).slice(1);if(r.length!==i.length)return null;let s=i.reduce((f,p)=>f+p,0);if(s===0)return null;let o=[];for(let f=0;f<i.length;f++){if(i[f]===0)continue;if(!y(r[f]))return null;let p=e.serialize(r[f]);o.push(i[f]===1?`\\partial ${p}`:`\\partial ${p}^{${i[f]}}`)}let a=s===1?"\\partial":`\\partial^{${s}}`,u=e.serialize(c(t,1)),l=r.map(f=>e.serialize(f)).join(", ");return`\\frac{${a}}{${o.join(" ")}} ${u}(${l})`}function Te(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=d(n);if(i==="Derivative"||i==="Prime"){let a=M(c(n,2))??1;return[i,P(c(n,1)),a+t]}let r=y(n),s=r&&e.getSymbolType(r).matches("function")||d(n);e.skipSpace();let o=e.parseArguments("enclosure");return o&&o.length>0?["Apply",["Derivative",n,t],...o]:s?t===1?["Derivative",n]:["Derivative",n,t]:t===1?["Prime",P(n)]:["Prime",P(n),t]}function Ql(e,n){if(R(n))return["Delimiter"];let t=d(n);if(t==="Delimiter"&&c(n,2)!==null){let i=w(c(n,2));if(i?.length===1)return["Delimiter",c(n,1)??"Nothing",{str:`(${i})`}]}return t==="Matrix"&&(w(c(n,2))??"..")===".."?["Matrix",c(n,1)]:["Delimiter",n]}function Ho(e,n){if(R(n))return["List"];let t=d(n);if(t==="Range"||t==="Linspace"||t==="Comprehension")return n;if(t==="Sequence"){let i=b(n),r=Xt(i,e);return r||["List",...i]}if(t==="Delimiter"){let i=w(c(n,2))??"...";if(i===";"||i===".;.")return["List",...(b(c(n,1))??[]).map(r=>Ho(e,r))];if(i===","||i===".,."){if(n=c(n,1),d(n)==="Sequence"){let r=b(n),s=Xt(r,e);return s||["List",...r]}return["List",n??"Nothing"]}}return["List",n]}function Vn(e){let n=M(e);if(n!==null)return n;if(d(e)==="Negate"){let t=M(c(e,1));if(t!==null)return-t}return null}var Hr=new WeakSet;function Wo(e){let n=M(e);if(n!==null)return{num:n,den:1};let t=d(e);if(t==="Negate"){let i=c(e,1);if(i==null)return null;let r=Wo(i);return r===null?null:{num:-r.num,den:r.den}}if(t==="Divide"||t==="Rational"){if(A(e)!==2)return null;let i=Vn(c(e,1)),r=Vn(c(e,2));return i===null||r===null||!Number.isInteger(i)||!Number.isInteger(r)||r===0?null:{num:i,den:r}}return null}function Fo(e,n){n<0&&([e,n]=[-e,-n]);let t=ec(Math.abs(e),n);return[e,n]=[e/t,n/t],n===1?e:["Divide",e,n]}function ec(e,n){for(;n!==0;)[e,n]=[n,e%n];return e===0?1:e}function nc(e){let n=d(e);if(n!=="Add"&&n!=="Subtract")return null;let t=b(e);if(t.length<2)return null;let i=t[t.length-1];if(d(i)!=="Range"||b(i).length!==2||!Hr.has(i))return null;let r=t.slice(0,-1);return{sample:[n,...r,c(i,1)],end:c(i,2)}}function Yt(e){let n=d(e);if(n==="InvisibleOperator"||n==="Multiply"){let t=b(e);if(t.length>=2&&y(t[0])==="ContinuationPlaceholder"){let i=t.slice(1);return i.length===1?i[0]:[n,...i]}return null}if(n==="Negate"){let t=Yt(c(e,1));return t===null?null:["Negate",t]}if(n==="Subtract"){let t=Yt(c(e,1));return t===null?null:["Subtract",t,c(e,2)]}if(n==="Add"){let t=b(e),i=Yt(t[0]);return i===null?null:["Add",i,...t.slice(1)]}return null}function Xt(e,n){if(e.length>=2){let p=e[e.length-1],g=e[e.length-2];if(y(g)!=="ContinuationPlaceholder")if(d(p)==="Range"&&b(p).length===2&&Hr.has(p))e=[...e.slice(0,-1),c(p,1),"ContinuationPlaceholder",c(p,2)];else{let h=nc(p);if(h!==null)e=[...e.slice(0,-1),h.sample,"ContinuationPlaceholder",h.end];else{let N=Yt(p);N!==null&&(e=[...e.slice(0,-1),"ContinuationPlaceholder",N])}}}if(e.length<3)return null;let t=e[e.length-2];if(y(t)!=="ContinuationPlaceholder")return null;let i=e.slice(0,-2),r=e[e.length-1];if(i.length===1){let p=i[0];return y(p)==="ContinuationPlaceholder"?null:["Range",M(p)??p,r]}if(i.length<2)return null;let s=n.options.tolerance,o=i.map(Wo);if(o.every(p=>p!==null)){let p=o,g=p.map(N=>N.num/N.den),h=g[g.length-1]-g[g.length-2];if(Math.abs(h)<s)return n.error("degenerate-range-step",n.index);for(let N=1;N<g.length;N++)if(Math.abs(g[N]-g[N-1]-h)>s)return n.error("inconsistent-range-samples",n.index);if(p.some(N=>N.den!==1)){let N=p[p.length-1],I=p[p.length-2];return["Range",Fo(p[0].num,p[0].den),r,Fo(N.num*I.den-I.num*N.den,N.den*I.den)]}return["Range",g[0],r,h]}let a=i.map(Yo);if(a.some(p=>p===null))return ic(i,r,s);let u=a.map(p=>p.coeff),l=a[0].sym;if(a.some(p=>p.sym!==l))return null;let f=u[u.length-1]-u[u.length-2];if(Math.abs(f)<s)return n.error("degenerate-range-step",n.index);for(let p=1;p<u.length;p++)if(Math.abs(u[p]-u[p-1]-f)>s)return n.error("inconsistent-range-samples",n.index);return["Range",Jo(u[0],l),r,Jo(f,l)]}function Yo(e){let n=y(e);if(n!==null)return n.includes("_")?null:{coeff:1,sym:n};let t=d(e);if(t==="Negate"){let i=c(e,1);if(!i)return null;let r=Yo(i);return r===null?null:{coeff:-r.coeff,sym:r.sym}}if(t==="Multiply"||t==="InvisibleOperator"){let i=b(e);if(i.length!==2)return null;let r=Vn(i[0]),s=y(i[1]);return r===null||s===null||s.includes("_")?null:{coeff:r,sym:s}}return null}function Jo(e,n){return e===1?n:e===-1?["Negate",n]:["Multiply",e,n]}function Lo(e){if(d(e)==="Add"){let n=[],t=0;for(let r of b(e)){let s=Vn(r);s!==null?t+=s:n.push(r)}return n.length===0?null:{base:n.length===1?n[0]:["Add",...n],offset:t}}return Vn(e)!==null?null:{base:e,offset:0}}function tc(e,n){return n===0?e:d(e)==="Add"?["Add",...b(e),n]:["Add",e,n]}function ic(e,n,t){let i=e.map(Lo);if(i.some(l=>l===null))return null;let r=i,s=JSON.stringify(r[0].base);if(r.some(l=>JSON.stringify(l.base)!==s))return null;let o=Lo(n);if(o===null||JSON.stringify(o.base)!==s)return null;let a=r.map(l=>l.offset),u=a[a.length-1]-a[a.length-2];if(Math.abs(u)<t)return null;for(let l=1;l<a.length;l++)if(Math.abs(a[l]-a[l-1]-u)>t)return null;return["Range",tc(r[0].base,a[0]),n,u]}function rc(e,n){return A(n)>1&&b(n).every(t=>{let i=d(t);return Ct(i)||Rt(i)})?E(["\\begin{cases}",ze("\\\\")(e,n),"\\end{cases}"]):E(["\\bigl\\lbrack",ze(", ")(e,n),"\\bigr\\rbrack"])}function Ut(e,n,t=!1){if(n===null)return null;let i=e.parseExpression({minPrec:270});if(i===null)return t?["Sequence",n,"ContinuationPlaceholder"]:null;if(t&&d(n)==="InvisibleOperator"&&b(n).some(s=>w(s)!==null))return["InvisibleOperator",...b(n),"ContinuationPlaceholder",i];if(d(i)==="Range"){let s=c(i,1),o=c(i,2);return s&&o?["Range",n,o,["Subtract",s,n]]:null}let r=["Range",n,i];return Hr.add(r),r}var Kt={"(":"(",")":")","[":"\\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 zr(e){if(e===null)return"Nothing";let n=d(e);if(!n)return e;let t=b(e)??[];return n.length>1&&n.endsWith("_")&&t.length===1?["Subscript",n.slice(0,-1),zr(t[0])]:[n,...t.map(i=>zr(i))]}function Vo(e,n,t){if(!n||n.length===0)return;let i=[];for(let r of n){let s=y(r);s&&i.push(s)}e.pruneUndeclared(i,t)}function Ht(e,n,t){let i=e.operandDiagnosticCheckpoint,r=(t?.minPrec??0)>=19,s=y(n);if(s&&s.includes("_")){let u=s.indexOf("_"),l=s.substring(0,u),f=s.substring(u+1),p=parseInt(f,10),g=!isNaN(p)&&String(p)===f?p:f,h=g!==""&&(typeof g=="number"||typeof g=="string"&&g.length===1);(e.getSymbolType(l).matches("indexed_collection")||!r&&h)&&(n=["Subscript",l,g])}if(d(n)==="InvisibleOperator"&&A(n)===2&&d(c(n,2))==="Delimiter"){let u=y(c(n,1));if(!u)return null;let l=e.parseExpression({...t??{},minPrec:20});if(l===null)return null;let f=c(c(n,2),1),p=[];return d(f)==="Sequence"?p=[...b(f)]:f&&(p=[f]),Vo(e,p,i),e.pruneJuxtaposition(u,i),e.pruneUndeclared([u],i),["Assign",u,["Function",l,...p??[]]]}if(d(n)==="Subscript"&&y(c(n,1))){let u=y(c(n,1));if(!e.getSymbolType(u).matches("indexed_collection")){let p=c(n,2),g=(p!==null&&typeof p=="string"?p:void 0)??(p!==null&&typeof p=="number"?String(p):void 0);if(g&&r){let h=e.parseExpression({...t??{},minPrec:20});return h===null?null:["Assign",u+"_"+g,h]}}let l=e.parseExpression({...t??{},minPrec:20});if(l===null)return null;let f=c(n,2);return w(f)!==null?["Assign",n,l]:y(f)?["Assign",n,l]:["Assign",n,l]}let o=d(n);if(o){let u=b(n),l=e.parseExpression({...t??{},minPrec:20});return l===null?null:(Vo(e,u,i),e.pruneJuxtaposition(o,i),e.pruneUndeclared([o],i),["Assign",o,["Function",l,...u]])}if(!y(n))return null;let a=e.parseExpression({...t??{},minPrec:20});return a===null?null:["Assign",n,a]}function Gr(e){let n=e.parseTabular();if(!n)return["List"];if(n.every(i=>{if(i.length!==1)return!1;let r=d(i[0]);return Rt(r)||Ct(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=w(i[1]);t.push(r?"True":Fr(i[1])??"True"),t.push(i[0])}return["Which",...t]}var sc={"=":"Equal","\\ne":"NotEqual","\\neq":"NotEqual","<":"Less","\\lt":"Less",">":"Greater","\\gt":"Greater","\\le":"LessEqual","\\leq":"LessEqual","\\ge":"GreaterEqual","\\geq":"GreaterEqual"};function qo(e){return e.atBoundary||e.peek==="\\\\"||e.peek==="\\cr"}function oc(e){let n=i=>i.peek==="&"||i.peek==="\\\\"||i.peek==="\\cr"||i.peek===","||i.peek===";",t=null;for(;!qo(e)&&(e.skipSpace(),!qo(e));){if(e.match("&"))continue;if(e.peek===","||e.peek==="."||e.peek===";"){e.nextToken();continue}let i=sc[e.peek];if(i!==void 0&&t!==null){e.nextToken();let s=e.parseExpression({minPrec:0,condition:n});t=[i,t,P(s)];continue}let r=e.parseExpression({minPrec:0,condition:n});if(r===null){e.nextToken();continue}t=t===null?r:["InvisibleOperator",t,r]}return t}function pe(e){let n=[];for(;!e.atBoundary;){let t=e.index,i=oc(e);if(i!==null&&n.push(i),e.skipSpace(),(e.match("\\\\")||e.match("\\cr"))&&e.parseOptionalGroup(),e.index===t){if(e.atBoundary)break;e.nextToken()}}return["List",...n]}function Zr(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 Ze(e,n){let t=e.index;e.skipVisualSpace();let i=e.diagnosticsCheckpoint();if(e.match("\\text")||e.match("\\keyword")){if(Zr(e,n))return e.rollbackDiagnostics(i),!0;e.index=t}let r=e.index,s=e.parseSymbol();return e.rollbackDiagnostics(i),s!==null&&y(s)===n?!0:(e.index=r,!1)}function Ue(e,n){let t=e.index,i=Ze(e,n);return e.index=t,i}function ac(e,n){e.skipVisualSpace();let t=e.parseExpression({minPrec:0,condition:s=>Ue(s,"then")});if(t===null||!Ze(e,"then"))return null;e.skipVisualSpace();let i=e.parseExpression({minPrec:0,condition:s=>Ue(s,"else")});if(i===null||!Ze(e,"else"))return null;e.skipVisualSpace();let r=e.parseExpression(n)??"Nothing";return["If",t,i,r]}function uc(e,n){let t=e.parseExpression({minPrec:0,condition:a=>Ue(a,"from")}),i=t?y(t):null;if(!i||!Ze(e,"from"))return null;let r=e.parseExpression({minPrec:0,condition:a=>Ue(a,"to")});if(r===null||!Ze(e,"to"))return null;let s=e.parseExpression({minPrec:0,condition:a=>Ue(a,"do")});return s===null||!Ze(e,"do")?null:["Loop",e.parseExpression(n)??"Nothing",["Element",i,["Range",r,s]]]}function Xo(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||Ue(s,"where")||Ue(s,"with"))}},r=[];do{e.skipVisualSpace();let s=e.parseExpression(i);if(s===null)break;let o=d(s);if(o!=="Equal"&&o!=="Assign")return null;let a=c(s,1),u=c(s,2);if(!a||!u)return null;r.push(["Element",a,u]),e.skipVisualSpace()}while(e.match(","));return r.length===0?null:["Comprehension",n,...r]}var lc=new Set(["Less","Greater","LessEqual","GreaterEqual","Equal","NotEqual","Element"]);function Ko(e){if(e===null)return!1;let n=d(e);if(!n)return!1;if(lc.has(n))return!0;if(n==="And"||n==="Or"){let t=b(e);return t.length===0?!1:t.every(i=>Ko(i))}return!1}function $o(e,n){e.skipVisualSpace();let t=e.parseExpression(n);return Ko(t)?t:null}function jo(e){if(d(e)!=="Delimiter")return e;let n=c(e,1);return d(n)!=="Sequence"||A(e)!==2||w(c(e,2))!==","?e:["Tuple",...b(n)]}function cc(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(Ze(e,"for")){let a=Xo(e,n,t);if(a){let u=[];for(let l of r){let f=Ur(l);d(f)==="Assign"&&u.push(["Declare",c(f,1)]),u.push(f)}return u.push(a),["Block",...u]}e.index=s}let o=[];for(let a of r){let u=Ur(a);d(u)==="Assign"&&o.push(["Declare",c(u,1)]),o.push(u)}return o.push(n),["Block",...o]}function fc(e){let n=[];for(let t of e){let i=Ur(t);d(i)==="Assign"&&n.push(["Declare",c(i,1)]),n.push(i)}return["Block",...n]}function Ur(e){if(d(e)!=="Assign")return e;let n=c(e,1);if(d(n)!=="Subscript")return e;let t=y(c(n,1));if(!t)return e;let i=c(n,2),r=(typeof i=="string"?i:void 0)??(typeof i=="number"?String(i):void 0);return r?["Assign",`${t}_${r}`,c(e,2)??"Nothing"]:e}function pc(e){if(d(e)!=="Delimiter")return!1;if(A(e)<2)return!0;let n=w(c(e,2));return typeof n=="string"&&n.length>=2&&n[0]==="("}var mc=new Set(["Delimiter","List","Sequence","InvisibleOperator","Error","At"]);function dc(e){let n=d(e);return typeof n!="string"||n===""?!1:!mc.has(n)}function Wt(...e){return(n,t)=>{if(!y(t)&&d(t)!=="List"&&!pc(t)&&!dc(t))return null;let i=null;if(e.length===0){if(i=n.parseGroup()??n.parseExpression({minPrec:0}),i===null)return null}else if(e.length>1){if(n.addBoundary(e),i=n.parseExpression({minPrec:0}),i===null||!n.matchBoundary())return n.removeBoundary(),null}else if(i=n.parseExpression({minPrec:0}),i===null||!n.matchAll(e))return null;return e.length===0&&w(i)!==null?null:(d(i)==="Delimiter"&&(i=c(i,1)??"Nothing"),d(i)==="Sequence"?["At",t,...b(i)]:["At",t,i])}}var He=[["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],["CapitalPi","\\Pi",928],["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",8467],["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]],Qo=[...He.map(([e,n,t])=>({kind:"symbol",name:e,latexTrigger:[n],parse:e})),...He.map(([e,n,t])=>({kind:"symbol",latexTrigger:[String.fromCodePoint(t)],parse:e}))];var ea=[{name:"To",latexTrigger:["\\to"],kind:"infix",precedence:270},{latexTrigger:["\\rightarrow"],kind:"infix",precedence:270,parse:"To"},{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 me(e,n,t){if(R(e))return null;let i,r=d(e);if(r==="Delimiter"){let l=w(c(e,2));if(l!==","&&l!=="(,)"&&l!=="[,]")return null;let f=c(e,1);d(f)==="Sequence"?i=[...b(f)]:i=f?[f]:[]}else if(r==="Sequence")i=[...b(e)];else return null;if(i.length!==2)return null;let[s,o]=i;return["Interval",n?["Open",s]:s,t?["Open",o]:o]}function qn(e){if(e===null)return null;if(d(e)==="List"&&A(e)===2)return["Interval",c(e,1),c(e,2)];if(d(e)==="Delimiter"){let n=w(c(e,2))??"(,)";if(n!==","&&n!=="(,)"&&n!=="()")return e;let t=c(e,1);if(d(t)==="Sequence"&&A(t)===2)return["Interval",["Open",c(t,1)],["Open",c(t,2)]]}return e}function Z(e,n,t){return(i,r,s)=>{if(r===null)return null;let o=P(i.parseExpression({...s,minPrec:n}));return[e,t==="both"?qn(r):r,qn(o)]}}var na=new Set(["Less","LessEqual","Greater","GreaterEqual","Equal","NotEqual","And","Or","Not"]),ia=[{name:"AlgebraicNumbers",latexTrigger:"\\overline\\Q"},{latexTrigger:"\\bar\\Q",parse:"AlgebraicNumbers"},{name:"ComplexNumbers",latexTrigger:["\\C"]},{latexTrigger:"\\mathbb{C}",parse:"ComplexNumbers"},{name:"UpperHalfPlane",latexTrigger:"\\mathbb{C}^+"},{latexTrigger:"\\mathbb{C}^{+}",parse:"UpperHalfPlane"},{latexTrigger:"\\C^+",parse:"UpperHalfPlane"},{latexTrigger:"\\C^{+}",parse:"UpperHalfPlane"},{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^{\\leqslant0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{-0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{\\leq}",parse:"NonPositiveNumbers"},{latexTrigger:"\\R^{\\leqslant}",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_{\\geqslant0}",parse:"NonNegativeNumbers"},{latexTrigger:"\\R^{0+}",parse:"NonNegativeNumbers"},{latexTrigger:"\\R^{\\geq}",parse:"NonNegativeNumbers"},{latexTrigger:"\\R^{\\geqslant}",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_{\\leqslant0}",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^{\\geqslant}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{\\geq0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\Z^{\\geqslant0}",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:"\\mathbb{R}_{>0}",parse:"PositiveNumbers"},{latexTrigger:"\\mathbb{R}_{\\gt0}",parse:"PositiveNumbers"},{latexTrigger:"\\mathbb{R}_+",parse:"PositiveNumbers"},{latexTrigger:"\\mathbb{R}_{+}",parse:"PositiveNumbers"},{latexTrigger:"\\mathbb{R}_{\\geq0}",parse:"NonNegativeNumbers"},{latexTrigger:"\\mathbb{R}_{\\ge0}",parse:"NonNegativeNumbers"},{latexTrigger:"\\mathbb{R}_{\\geqslant0}",parse:"NonNegativeNumbers"},{latexTrigger:"\\mathbb{R}_{<0}",parse:"NegativeNumbers"},{latexTrigger:"\\mathbb{R}_{\\lt0}",parse:"NegativeNumbers"},{latexTrigger:"\\mathbb{R}_-",parse:"NegativeNumbers"},{latexTrigger:"\\mathbb{R}_{-}",parse:"NegativeNumbers"},{latexTrigger:"\\mathbb{R}_{\\leq0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\mathbb{R}_{\\le0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\mathbb{R}_{\\leqslant0}",parse:"NonPositiveNumbers"},{latexTrigger:"\\mathbb{Z}_{>0}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{Z}_{\\gt0}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{Z}_+",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{Z}_{+}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{Z}^+",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{Z}^{+}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{Z}_{\\geq0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{Z}_{\\ge0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{Z}_{\\geqslant0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{Z}_{<0}",parse:"NegativeIntegers"},{latexTrigger:"\\mathbb{Z}_{\\lt0}",parse:"NegativeIntegers"},{latexTrigger:"\\mathbb{Z}_-",parse:"NegativeIntegers"},{latexTrigger:"\\mathbb{Z}_{-}",parse:"NegativeIntegers"},{latexTrigger:"\\mathbb{Z}_{\\leq0}",parse:"NonPositiveIntegers"},{latexTrigger:"\\mathbb{Z}_{\\le0}",parse:"NonPositiveIntegers"},{latexTrigger:"\\mathbb{Z}_{\\leqslant0}",parse:"NonPositiveIntegers"},{latexTrigger:"\\mathbb{N}_{>0}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}_{\\gt0}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}^+",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}^{+}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}^*",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}^{*}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}_0",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{N}_{0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{N}_{\\geq0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{N}_{\\ge0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{N}_{\\geqslant0}",parse:"NonNegativeIntegers"},{latexTrigger:"\\mathbb{N}_1",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}_{1}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}_{\\geq1}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}_{\\ge1}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}_{\\geqslant1}",parse:"PositiveIntegers"},{latexTrigger:"\\mathbb{N}_{>1}",parse:()=>["Set",["Element","n","NonNegativeIntegers"],["Condition",["Greater","n",1]]]},{latexTrigger:"\\N_{>1}",parse:()=>["Set",["Element","n","NonNegativeIntegers"],["Condition",["Greater","n",1]]]},{latexTrigger:["^","\\complement"],kind:"postfix",parse:(e,n)=>["Complement",n]},{name:"Complement",latexTrigger:["^","<{>","\\complement","<}>"],kind:"postfix",serialize:(e,n)=>E([e.serialize(c(n,1)),"^\\complement"])},{name:"Intersection",latexTrigger:["\\cap"],kind:"infix",precedence:350,parse:Z("Intersection",350,"both")},{latexTrigger:["\u2229"],kind:"infix",precedence:350,parse:Z("Intersection",350,"both")},{name:"Interval",serialize:ta},{kind:"matchfix",openTrigger:["["],closeTrigger:[")"],parse:(e,n)=>me(n,!1,!0)},{kind:"matchfix",openTrigger:["\\lbrack"],closeTrigger:["\\rparen"],parse:(e,n)=>me(n,!1,!0)},{kind:"matchfix",openTrigger:["\\lbrack"],closeTrigger:[")"],parse:(e,n)=>me(n,!1,!0)},{kind:"matchfix",openTrigger:["["],closeTrigger:["\\rparen"],parse:(e,n)=>me(n,!1,!0)},{kind:"matchfix",openTrigger:["("],closeTrigger:["]"],parse:(e,n)=>me(n,!0,!1)},{kind:"matchfix",openTrigger:["\\lparen"],closeTrigger:["\\rbrack"],parse:(e,n)=>me(n,!0,!1)},{kind:"matchfix",openTrigger:["\\lparen"],closeTrigger:["]"],parse:(e,n)=>me(n,!0,!1)},{kind:"matchfix",openTrigger:["("],closeTrigger:["\\rbrack"],parse:(e,n)=>me(n,!0,!1)},{kind:"matchfix",openTrigger:["]"],closeTrigger:["["],parse:(e,n)=>me(n,!0,!0)},{kind:"matchfix",openTrigger:["\\rbrack"],closeTrigger:["\\lbrack"],parse:(e,n)=>me(n,!0,!0)},{name:"Multiple",serialize:ta},{name:"Union",latexTrigger:["\\cup"],kind:"infix",precedence:350,parse:Z("Union",350,"both")},{latexTrigger:["\u222A"],kind:"infix",precedence:350,parse:Z("Union",350,"both")},{name:"Divides",latexTrigger:["\\mid"],kind:"infix",precedence:160},{name:"NotDivides",latexTrigger:["\\nmid"],kind:"infix",precedence:160},{name:"Set",kind:"matchfix",openTrigger:"{",closeTrigger:"}",parse:(e,n)=>{if(R(n))return"EmptySet";d(n)=="Delimiter"&&w(c(n,2))===","&&(n=c(n,1));let t=d(n);if(t==="Divides"){let i=c(n,1),r=c(n,2);if(i!==null&&r!==null)return["Set",i,["Condition",r]]}if(t==="Colon"){let i=c(n,1),r=c(n,2);if(i!==null&&r!==null){let s=d(i);return s!==null&&na.has(s)?["Which",i,r]:["Set",i,["Condition",r]]}}if(t==="Sequence"){let i=b(n),r=i.filter(a=>d(a)==="Colon");if(r.length>0&&r.every(a=>{let u=c(a,1),l=u!==null?d(u):null;return l!==null&&na.has(l)})){let a=[];for(let u=0;u<i.length;u++){let l=i[u];if(d(l)==="Colon"){let f=c(l,1),p=c(l,2);if(f===null||p===null)return["Set",...i];a.push(f,p)}else{if(u!==i.length-1)return["Set",...i];a.push("True",l)}}return["Which",...a]}let o=Xt(i,e);return o||["Set",...i]}return["Set",n]},serialize:(e,n)=>{if(A(n)===2&&d(c(n,2))==="Condition"){let t=c(n,2);return E(["\\lbrace",e.serialize(c(n,1)),"\\mid",e.serialize(c(t,1)),"\\rbrace"])}return E(["\\lbrace",b(n).map(t=>e.serialize(t)).join(", "),"\\rbrace"])}},{name:"SetMinus",latexTrigger:["\\setminus"],kind:"infix",precedence:650,parse:Z("SetMinus",650,"both")},{latexTrigger:["\\backslash"],kind:"infix",precedence:650,parse:Z("SetMinus",650,"both")},{name:"SymmetricDifference",latexTrigger:["\\triangle"],kind:"infix",precedence:S},{latexTrigger:["\\ni"],kind:"infix",associativity:"none",precedence:160,parse:(e,n,t)=>{let i=e.parseExpression(t);return i===null?null:["Element",i,qn(n)]}},{name:"Element",latexTrigger:["\\in"],kind:"infix",precedence:241,parse:Z("Element",241,"rhs")},{latexTrigger:["\u2208"],kind:"infix",precedence:241,parse:Z("Element",241,"rhs")},{name:"NotElement",latexTrigger:["\\notin"],kind:"infix",precedence:240,parse:Z("NotElement",240,"rhs")},{latexTrigger:["\u2209"],kind:"infix",precedence:240,parse:Z("NotElement",240,"rhs")},{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},{latexTrigger:["\\not","\\in"],kind:"infix",precedence:240,parse:Z("NotElement",240,"rhs")},{latexTrigger:["\\not","\\subset"],kind:"infix",associativity:"none",precedence:240,parse:"NotSubset"},{latexTrigger:["\\not","\\supset"],kind:"infix",associativity:"none",precedence:240,parse:"NotSuperset"},{latexTrigger:["\\not","\\subseteq"],kind:"infix",associativity:"none",precedence:240,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:240});return i===null?null:["Not",["SubsetEqual",qn(n),qn(i)]]}},{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,parse:Z("Subset",240,"both")},{latexTrigger:["\\subsetneq"],kind:"infix",associativity:"none",precedence:240,parse:Z("Subset",240,"both")},{latexTrigger:["\\varsubsetneqq"],kind:"infix",associativity:"none",precedence:240,parse:Z("Subset",240,"both")},{name:"SubsetEqual",latexTrigger:["\\subseteq"],kind:"infix",associativity:"none",precedence:240,parse:Z("SubsetEqual",240,"both")},{name:"Superset",latexTrigger:["\\supset"],kind:"infix",associativity:"none",precedence:240,parse:Z("Superset",240,"both")},{latexTrigger:["\\supsetneq"],kind:"infix",associativity:"none",precedence:240,parse:Z("Superset",240,"both")},{latexTrigger:["\\varsupsetneq"],kind:"infix",associativity:"none",precedence:240,parse:Z("Superset",240,"both")},{name:"SupersetEqual",latexTrigger:["\\supseteq"],kind:"infix",associativity:"none",precedence:240,parse:Z("SupersetEqual",240,"both")}];function ta(e,n){if(n===null)return"";let t=d(n);if(!t)return"";if(t==="Range")return E(["\\mathopen\\lbrack",e.serialize(c(n,1)),", ",e.serialize(c(n,2)),"\\mathclose\\rbrack"]);if(t==="Interval"){let r=c(n,1),s=c(n,2),o=!1,a=!1;return d(r)==="Open"&&(r=c(r,1),o=!0),d(s)==="Open"&&(s=c(s,1),a=!0),E([o?"\\lparen":"\\lbrack",e.serialize(r),", ",e.serialize(s),a?"\\rparen":"\\rbrack"])}let i=e.numericSetStyle(n,e.level);return""}function Ie(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 E(i.map(r=>{switch(r){case"#1":return n;case"#2":return t;default:return r}}))}function Qt(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 gc(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 ei(e){let{deg:n,min:t,sec:i}=gc(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 hc(e){if(d(e)!=="Multiply")return[[],[]];let n=[],t=[];for(let i of b(e))if(d(i)==="Power"){let r=c(i,1),s=c(i,2);if(d(s)==="Negate"){let o=c(s,1);r&&o&&t.push(["Power",r,o])}else{let o=M(s)??NaN;o===-1?r&&t.push(r):o<0?r&&t.push(["Power",r,-o]):n.push(i)}}else if(d(i)==="Rational"&&A(i)===2||d(i)==="Divide"){let r=c(i,1),s=c(i,2);M(r)!==1&&n.push(r),M(s)!==1&&t.push(s)}else{let r=Ge(i);r!==null?(r[0]!==1&&n.push(r[0]),t.push(r[1])):n.push(i)}return[n,t]}function ra(e){let n=e.parseOptionalGroup(),t=e.parseGroup(),i=t??e.parseToken();if(R(i)){if(n===null&&t===null)return"Sqrt";let r=e.error("missing",e.index);return n!==null?["Root",r,P(n)]:["Sqrt",r]}return n!==null?["Root",i,n]:["Sqrt",i]}function bc(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 ga(e){if(e==null)return!1;if(y(e)==="ContinuationPlaceholder")return!0;let n=d(e);return n==="Add"||n==="Subtract"||n==="Negate"?b(e).some(t=>ga(t)):!1}function ha(e){if(d(e)==="Subtract"){let n=c(e,1),t=c(e,2);return[...ha(n),["Negate",t]]}return[e]}function sa(e){if(d(e)!=="Add")return e;let n=b(e);if(!n.some(i=>ga(i)))return e;let t=[];for(let i of n)t.push(...ha(i));return["Add",...t]}function yc(e,n){if(!n)return"\\pm";let t=c(n,1),i=c(n,2);if(t===null)return"\\pm";if(i===null)return e.serialize(t);let r=M(t),s=M(i);if(r!==null&&s!==null&&Number.isFinite(r)&&Number.isFinite(s)&&s>0){let{value:o,error:a}=qr(r,s,e.options.digits);return E([o,"\\pm",a])}return E([e.serialize(t),"\\pm",e.serialize(i)])}function Gn(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)+"}}":M(i)===2?"\\sqrt{"+e.serialize(t)+"}":"\\sqrt["+e.serialize(i)+"]{"+e.serialize(t)+"}")}var xc=new Set(["Pi","ExponentialE","ImaginaryUnit","GoldenRatio","EulerGamma","CatalanConstant","MachineEpsilon"]);function Xr(e,n){let t=y(e);if(t!==null)return t===n;for(let i of b(e))if(Xr(i,n))return!0;return!1}function ba(e){let n=y(e);if(n!==null)return xc.has(n)?null:n;for(let t of b(e)){let i=ba(t);if(i!==null)return i}return null}function Me(e,n){if(ce(e))return 0;let t=y(e);if(t!==null)return t===n?1:0;let i=d(e);if(!i)return 0;if(i==="Negate")return Me(c(e,1),n);if(i==="Multiply"){let r=0;for(let s of b(e)){let o=Me(s,n);if(o===void 0)return;r+=o}return r}if(i==="Divide"){let r=Me(c(e,1),n),s=Me(c(e,2),n);return r===void 0||s===void 0?void 0:r-s}if(i==="Power"){let r=c(e,1),s=c(e,2),o=Me(r,n);if(o===void 0)return;if(o===0)return Xr(s,n)?void 0:0;let a=M(s);return a===null||!Number.isInteger(a)?void 0:o*a}if(i==="Square"){let r=Me(c(e,1),n);return r===void 0?void 0:r*2}if(i==="Add"||i==="Subtract"){let r;for(let s of b(e)){let o=Me(s,n);o!==void 0&&(r===void 0||o>r)&&(r=o)}return r}return Xr(e,n)?void 0:0}function Nc(e){let n=e;return d(n)==="Negate"&&(n=c(n,1)),d(n)==="BigO"?c(n,1):null}function Ec(e){let n=e.map(Nc);if(!n.some(u=>u!==null))return e;let t=null;for(let u of n)if(u!==null&&(t=ba(u),t!==null))break;if(t===null)return e;let i=n.find(u=>u!==null),r=(Me(i,t)??0)>=0,s=[],o=[];for(let u=0;u<e.length;u++)n[u]!==null?o.push(e[u]):s.push(e[u]);let a=u=>Me(u,t)??0;return s.sort((u,l)=>r?a(u)-a(l):a(l)-a(u)),[...s,...o]}function Tc(e,n){e.level-=1;let t=d(n),i="",r=c(n,1);if(t==="Negate")i="-"+e.wrap(r,O+1);else if(t==="Subtract"){i=e.wrap(r,O);let s=c(n,2);if(s!==null){let o=e.wrap(s,O);o[0]==="-"?i+="+"+o.slice(1):o[0]==="+"?i+="-"+o.slice(1):i=i+"-"+o}}else if(t==="Add"){let s=Ec(b(n));if(e.options.prettify&&s.length===2&&e.options.invisiblePlus!=="+"){let[o,a]=s,[u,l]=[o,a],f=M(u),p=Ge(l);if((f===null||p===null)&&([u,l]=[a,o],f=M(u),p=Ge(l)),f!==null&&p!==null&&isFinite(f)&&Number.isInteger(f)&&f>=0&&f<=1e3&&isFinite(p[0])&&isFinite(p[1])&&p[0]>0&&p[0]<=100&&p[1]<=100)return i=Ie(e.options.invisiblePlus,e.serialize(u),e.serialize(l)),e.level+=1,i}if(e.options.prettify&&s.length===2){let[o,a]=Zn(s[0]),[u,l]=Zn(s[1]);if(a<0&&l>0)return i=e.wrap(u,O)+"-"+e.wrap(o,O),e.level+=1,i}i=d(s[0])==="Range"?e.wrap(s[0],O):e.serialize(s[0]);for(let o=1;o<s.length;o++)if(r=s[o],e.options.prettify){let[a,u]=Zn(r),l=e.wrap(a,O);u>0?l.startsWith("+")||l.startsWith("-")?i+=l:i+="+"+l:l.startsWith("+")?i+="-"+l.slice(1):l.startsWith("-")?i+="+"+l.slice(1):i+="-"+l}else{let a=e.wrap(r,O);a[0]==="-"||a[0]==="+"?i+=a:i+="+"+a}}return e.level+=1,i}function ya(e,n){if(n===null)return"";e.level-=1;let t="";if(e.options.prettify===!0){let[f,p]=hc(n);p.length>0&&(p.length===1&&p[0]===1?f.length===0?t="1":f.length===1?t=e.serialize(f[0]):t=ya(e,["Multiply",...f]):t=e.serialize(["Divide",f.length===1?f[0]:["Multiply",...f],p.length===1?p[0]:["Multiply",...p]]))}if(t)return e.level+=1,t;let i=!1,r=null,s=A(n)+1,o=b(n);e.options.prettify===!0&&o.length===2&&ce(o[1])&&!ce(o[0])&&(o=[o[1],o[0]]);let a=!1,u=!1,l=!1;for(let f=1;f<s;f++){if(r=o[f-1],r===null)continue;let p;if(ce(r)){p=e.serialize(r),p==="-1"&&!t?(t="",i=!i):(p[0]==="-"&&(p=p.slice(1),i=!i),t?t=Ie(e.options.multiply,t,p):t=p),a=!0,u=!1,l=!1;continue}if(d(r)==="Power"){let h=Ge(c(r,2));if(h!=null){let[N,I]=h;if(N===1&&I!==null){t+=Gn(e,e.rootStyle(r,e.level),c(r,1),I),a=!1,u=!1,l=!1;continue}}}if(d(r)==="Power"&&!isNaN(M(c(r,1))??NaN)){p=e.serialize(r),t?t=Ie(e.options.multiply,t,p):t=p,a=!0,u=!1,l=!1;continue}d(r)==="Negate"&&(r=c(r,1),i=!i),p=d(r)==="Mod"&&A(r)===2?e.wrap(r,Y+1):e.wrap(r,C);let g=y(r)==="ContinuationPlaceholder";if(!t)t=p;else{let h=d(r);a&&(h==="Divide"||h==="Rational")?t=Ie(e.options.multiply,t,p):/^\d/.test(p)?t=Ie(e.options.multiply,t,p):g||u?t=Ie(e.options.multiply,t,p):l&&vc(r)?t=Ie(e.options.multiply,t,p):e.options.invisibleMultiply?t=Ie(e.options.invisibleMultiply,t,p):t=E([t,p])}a=!1,u=g,l=y(r)!==null&&!g}return e.level+=1,i?"-"+t:t}function vc(e){if(e===null)return!1;let n=d(e);if(n==="Tuple"||n==="Pair"||n==="Triple")return A(e)>=2;if(n==="Delimiter"){let t=c(e,1);if(d(t)!=="Sequence"||A(t)<2)return!1;let i=w(c(e,2));return i==null||i.startsWith("(")}return!1}function ii(e){let n=e.parseGroup();return n===null?P(e.parseToken()):R(n)?e.error("missing",e.index):n}function ni(e){let n=ii(e),t=ii(e),i=d(t)==="PartialDerivative"?[t]:d(t)==="Multiply"||d(t)==="Sequence"||d(t)==="InvisibleOperator"?b(t).filter(a=>d(a)==="PartialDerivative"):[];if(i.length>0){let a=d(n)==="PartialDerivative"?c(n,1):null;(a==null||a==="Nothing")&&(a=oa(P(e.parseExpression())));let u=[];for(let f of i){let p=c(f,1),g=d(p)==="List"?b(p):[p];for(let h of g)h&&h!=="Nothing"&&u.push(h)}let l=M(c(n,2))??1;if(u.length===1&&l>1)for(let f=1;f<l;f++)u.push(u[0]);if(u.length>0)return["D",a,...u]}let r=a=>a==="d"||a==="d_upright"||a==="differentialD",s=null,o=null;{let a=d(n),u=a==="Multiply"||a==="InvisibleOperator"||a==="Sequence"?[...b(n)]:[n],l=u[0];if(r(y(l)))s=1;else if(d(l)==="Power"&&r(y(c(l,1)))){let f=M(c(l,2));f!==null&&f>0&&(s=f)}if(s!==null&&u.length>1){let f=u.slice(1);o=f.length===1?f[0]:["Multiply",...f]}}if(s!==null){let a=[],u=!1,l=f=>{if(!f)return;let p=y(f);if(p&&r(p)){u=!0;return}if(p){a.push(f);return}let g=d(f);if(g==="Sequence"||g==="Multiply"||g==="InvisibleOperator")for(let h of b(f))l(h);else if(g==="Power"){let h=c(f,1);h&&!r(y(h))&&a.push(h)}};if(l(t),u||(a.length=0),a.length===0){let f=y(t);f&&f.length>1&&f[0]==="d"&&a.push(f.slice(1))}if(a.length===1&&s>1)for(let f=1;f<s;f++)a.push(a[0]);if(a.length>0){let p=o??oa(P(e.parseExpression()));for(let g of a)p=["D",p,g];return p}}return["Divide",n,t]}function $n(e,n,t){if(e.match("_")){let r=e.parseGroup()??e.parseToken();if(r===null)return null;let s=e.parseArguments("implicit");return s===null||s.length===0?null:t==="first"?[n,r,...s]:[n,...s,r]}let i=e.parseArguments("enclosure");return i===null?n:[n,...i]}function oa(e){return d(e)==="List"&&A(e)===1?c(e,1):e}function Ic(e,n,t){let i=e.parseExpression({...t,minPrec:Y+1});if(i===null)return["Divide",n,Cn];let r=Mc(n,i);return r||["Divide",n,i]}function Mc(e,n){let t=y(e);if(t!=="d"&&t!=="d_upright"&&t!=="differentialD")return null;let i=d(n);if(i!=="InvisibleOperator"&&i!=="Multiply")return null;let r=b(n);if(r.length<3)return null;let s=y(r[0]);if(s!=="d"&&s!=="d_upright"&&s!=="differentialD")return null;let o=r[1];if(!y(o))return null;let a=r.length===3?r[2]:["InvisibleOperator",...r.slice(2)];return["D",zn(a),o]}function zn(e){if(d(e)==="Delimiter")return zn(c(e,1));if(d(e)==="InvisibleOperator"){let n=b(e);return n.length===2&&y(n[0])&&d(n[1])==="Delimiter"?[y(n[0]),zn(n[1])]:["InvisibleOperator",...n.map(t=>zn(t))]}if(Array.isArray(e)){let n=e[0];if(typeof n!="string")return e;let t=[n];for(let i=1;i<e.length;i++)t.push(zn(e[i]));return t}return e}function aa(e,n){if(n===null)return"";let t=P(c(n,1)),i=P(c(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 M(t)===1?e.wrap(i)+"^{-1}":e.wrap(t)+e.wrap(i)+"^{-1}";if(r==="factor")return M(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 Wr(e){let n=ii(e),t=ii(e);return["Binomial",n,P(t)]}function kc(e,n){if(n===null)return"";let t=e.serialize(P(c(n,1))),i=e.serialize(P(c(n,2)));return`\\binom{${t}}{${i}}`}function Yr(e,n){if(!n)return"";let t=d(n),i=P(c(n,1));if(t==="Sqrt")return Gn(e,e.rootStyle(n,e.level-1),i,2);let r=P(c(n,2));if(t==="Root")return Gn(e,e.rootStyle(n,e.level-1),i,r);if(e.options.prettify){let o=M(r)??1;if(o===-1)return e.serialize(["Divide","1",i]);if(o<0)return e.serialize(["Divide","1",["Power",i,-o]]);if(d(r)==="Divide"||d(r)==="Rational"){let a=M(c(r,1)),u=M(c(r,2));if(a===1){let l=e.rootStyle(n,e.level);return Gn(e,l,i,c(r,2))}if(a===-1)return u===2?e.serialize(["Divide","1",["Sqrt",i]]):e.serialize(["Divide","1",["Root",i,c(r,2)??Cn]]);if(u===2)return`${e.serialize(["Sqrt",i])}^{${e.serialize(c(r,1))}}`}else if(d(r)==="Power"&&M(c(r,2))===-1){let a=e.rootStyle(n,e.level);return Gn(e,a,i,c(r,1))}}return Ve("^",(o=>o.startsWith("-")?e.wrapString(o,"normal"):o)(e.wrapShort(i)),e.serialize(r))}function jn(e,n){e.skipSpace();let t=e.index,i=e.parseNumber(),r=null,s=null;if(i!==null&&(e.match("'")||e.match("\\prime"))){r=M(i),e.skipSpace();let u=e.index,l=e.parseNumber();l!==null&&(e.match('"')||e.match("\\doubleprime"))?s=M(l):e.index=u}else return e.index=t,["Degrees",n];let o=M(n);if(o!==null&&r!==null){let u=3600*o+60*r+(s??0),l=Po(u,3600);if(l===null)return["Degrees",u/3600];let[f,p]=l;return p===1?["Degrees",f]:["Degrees",["Rational",f,p]]}let a=[["Quantity",n,"deg"]];return a.push(["Quantity",i,"arcmin"]),s!==null&&a.push(["Quantity",s,"arcsec"]),["Add",...a]}var xa=[{name:"CatalanConstant",symbolTrigger:"G"},{name:"GoldenRatio",latexTrigger:"\\varphi"},{name:"EulerGamma",latexTrigger:"\\gamma"},{name:"Degrees",latexTrigger:["\\degree"],kind:"postfix",precedence:880,parse:(e,n)=>jn(e,n),serialize:(e,n)=>{let t=e.options,i=c(n,1);if(t.dmsFormat||t.angleNormalization&&t.angleNormalization!=="none"){let r=M(i);if(r===null){let s=Ge(i);s!==null&&s[1]!==0&&(r=s[0]/s[1])}if(r!==null){let s=r;return t.angleNormalization&&t.angleNormalization!=="none"&&(s=Qt(s,t.angleNormalization)),t.dmsFormat?ei(s):`${s}\xB0`}}return E([e.serialize(i),"\\degree"])}},{latexTrigger:["\\degree"],kind:"postfix",precedence:880,parse:(e,n)=>jn(e,n)},{latexTrigger:["^","<{>","\\circ","<}>"],kind:"postfix",parse:(e,n)=>jn(e,n)},{latexTrigger:["^","\\circ"],kind:"postfix",parse:(e,n)=>jn(e,n)},{latexTrigger:["\xB0"],kind:"postfix",precedence:880,parse:(e,n)=>jn(e,n)},{latexTrigger:["\\ang"],parse:e=>{let n=e.parseGroup();return n===null?["Degrees"]:["Degrees",n]}},{name:"DMS",serialize:(e,n)=>{let t=M(c(n,1)),i=M(c(n,2)),r=M(c(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=c(n,o);a!==null&&s.push(e.serialize(a))}return`\\operatorname{DMS}(${s.join(", ")})`}},{latexTrigger:["\\infty"],parse:"PositiveInfinity"},{latexTrigger:["\\infin"],parse:"PositiveInfinity"},{latexTrigger:["\u221E"],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=>pa(e)},{latexTrigger:"\\exp",parse:e=>pa(e)},{name:"ImaginaryUnit",latexTrigger:["\\imaginaryI"]},{latexTrigger:"\\operatorname{i}",parse:"ImaginaryUnit"},{latexTrigger:"\\mathrm{i}",parse:"ImaginaryUnit"},{name:"Abs",kind:"matchfix",openTrigger:"|",closeTrigger:"|",parse:(e,n)=>R(n)?null:["Abs",n]},{kind:"matchfix",openTrigger:["\\vert"],closeTrigger:["\\vert"],parse:(e,n)=>R(n)?null:["Abs",n]},{symbolTrigger:"abs",kind:"function",parse:"Abs"},{latexTrigger:["\\abs"],kind:"function",parse:"Abs"},{name:"Add",latexTrigger:["+"],kind:"infix",associativity:"any",precedence:O,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:O+1});if(i===null)return null;if(d(i)==="Negate"){let r=c(i,1);if(ce(r))return sa(bn("Add",n,bc(r)))}return sa(bn("Add",n,i))},serialize:Tc},{kind:"prefix",latexTrigger:["+"],precedence:O,parse:(e,n)=>e.parseExpression({...n,minPrec:400})},{name:"Ceil",kind:"matchfix",openTrigger:"\\lceil",closeTrigger:"\\rceil",parse:(e,n)=>R(n)?null:["Ceil",n]},{kind:"matchfix",openTrigger:["\u2308"],closeTrigger:["\u2309"],parse:(e,n)=>R(n)?null:["Ceil",n]},{symbolTrigger:"ceil",kind:"function",parse:"Ceil"},{name:"Chop",symbolTrigger:"chop",kind:"function",parse:"Chop"},{name:"Complex",precedence:O-1,serialize:(e,n)=>{let t=e.serialize(c(n,1)),i=M(c(n,2));if(i===0)return t;let r=i===1?"\\imaginaryI":i===-1?"-\\imaginaryI":E([e.serialize(c(n,2)),"\\imaginaryI"]);return M(c(n,1))===0?r:i!==null&&i<0?E([t,r]):E([t,"+",r])}},{name:"Divide",latexTrigger:"\\frac",precedence:Y,parse:ni,serialize:aa},{latexTrigger:"\\dfrac",precedence:Y,parse:ni},{latexTrigger:"\\tfrac",precedence:Y,parse:ni},{latexTrigger:"\\cfrac",precedence:Y,parse:ni},{name:"Binomial",latexTrigger:"\\binom",parse:Wr,serialize:kc},{latexTrigger:"\\dbinom",parse:Wr},{latexTrigger:"\\tbinom",parse:Wr},{kind:"infix",latexTrigger:"\\over",associativity:"none",precedence:Y,parse:"Divide"},{kind:"infix",latexTrigger:"\\choose",associativity:"none",precedence:Y,parse:"Binomial"},{latexTrigger:["\\/"],kind:"infix",associativity:"left",precedence:Y,parse:"Divide"},{latexTrigger:["/"],kind:"infix",associativity:"left",precedence:Y,parse:Ic},{latexTrigger:["\\div"],kind:"infix",associativity:"left",precedence:Y,parse:"Divide"},{name:"Exp",serialize:(e,n)=>{let t=c(n,1);return y(t)||M(t)!==null?E(["\\exponentialE^{",e.serialize(t),"}"]):E(["\\exp",e.wrap(P(t))])}},{name:"Factorial",latexTrigger:["!"],kind:"postfix",precedence:$e,parse:(e,n)=>e.peek==="="?null:["Factorial",n]},{name:"Factorial2",latexTrigger:["!","!"],kind:"postfix",precedence:$e},{name:"Floor",kind:"matchfix",openTrigger:"\\lfloor",closeTrigger:"\\rfloor",parse:(e,n)=>R(n)?null:["Floor",n]},{kind:"matchfix",openTrigger:["\u230A"],closeTrigger:["\u230B"],parse:(e,n)=>R(n)?null:["Floor",n]},{symbolTrigger:"floor",kind:"function",parse:"Floor"},{latexTrigger:["\\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",parse:e=>$n(e,"LambertW","last"),serialize:(e,n)=>{let t=c(n,1),i=c(n,2);return t!==null&&i!==null?"\\operatorname{W}_{"+e.serialize(i)+"}"+e.wrapArguments(["LambertW",t]):"\\operatorname{W}"+e.wrapArguments(n)}},{name:"BesselJ",latexTrigger:["\\operatorname{J}"],kind:"function",parse:e=>$n(e,"BesselJ","first"),serialize:(e,n)=>{let t=c(n,1),i=c(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",parse:e=>$n(e,"BesselY","first"),serialize:(e,n)=>{let t=c(n,1),i=c(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",parse:e=>$n(e,"BesselI","first"),serialize:(e,n)=>{let t=c(n,1),i=c(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",parse:e=>$n(e,"BesselK","first"),serialize:(e,n)=>{let t=c(n,1),i=c(n,2);return t!==null&&i!==null?"\\operatorname{K}_{"+e.serialize(t)+"}"+e.wrapArguments(["BesselK",i]):"\\operatorname{K}"+e.wrapArguments(n)}},{name:"PolyLog",latexTrigger:["\\operatorname{Li}"],kind:"function",parse:e=>{if(!e.match("_"))return null;let n=e.parseGroup()??e.parseToken();if(n===null)return null;let t=e.parseArguments("implicit");return t===null?["PolyLog",n]:["PolyLog",n,...t]},serialize:(e,n)=>{let t=c(n,1),i=c(n,2);return t!==null&&i!==null?"\\operatorname{Li}_{"+e.serialize(t)+"}"+e.wrapArguments(["PolyLog",i]):"\\operatorname{Li}"+e.wrapArguments(n)}},{name:"LogIntegral",latexTrigger:["\\operatorname{li}"],kind:"function",serialize:(e,n)=>"\\operatorname{li}"+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:"AiryAiPrime",kind:"function",serialize:(e,n)=>"\\operatorname{Ai}'"+e.wrapArguments(n)},{name:"AiryBiPrime",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)=>y(n)!==null?"\\lg":"\\log_{10}"+e.wrapArguments(n),parse:e=>ma(e)},{kind:"function",symbolTrigger:"lg",parse:e=>ma(e)},{name:"Lb",latexTrigger:"\\lb",parse:e=>da(e)},{kind:"function",symbolTrigger:"lb",parse:e=>da(e)},{name:"Ln",latexTrigger:["\\ln"],parse:e=>ti("Ln",e),serialize:(e,n)=>y(n)!==null?"\\ln":"\\ln"+e.wrapArguments(n)},{kind:"function",symbolTrigger:"ln",parse:e=>ti("Ln",e)},{name:"Log",latexTrigger:["\\log"],parse:e=>ti("Log",e),serialize:(e,n)=>{if(y(n)!==null)return"\\log";let[t,i]=b(n);return i?E(["\\log_{",e.serialize(i),"}",e.wrap(t)]):"\\log"+e.wrapArguments(n)}},{kind:"function",symbolTrigger:"log",parse:e=>ti("Log",e)},{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=>{let n=e.diagnosticsCheckpoint();if(!e.match("_"))return null;let t=e.index,i=e.parseGroup(),r=e.index;if(d(i)!=="To")return null;let s=e.parseExpression({minPrec:C});if(!s)return null;let o=y(c(i,1));o&&e.pruneUndeclared([o],n,r,[[t,r]]);let a=c(i,2),u;d(a)==="PseudoInverse"&&A(a)===1?(u=1,a=c(a,1)):d(a)==="Superminus"&&A(a)===1&&(u=-1,a=c(a,1));let l=["Function",s,c(i,1)];return u===void 0?["Limit",l,a]:["Limit",l,a,u]},serialize:(e,n)=>{let t=c(n,1),i=c(t,2),r=c(n,2),s=M(c(n,3)),o=s===1?"^{+}":s===-1?"^{-}":"";return E(["\\lim_{",e.serialize(i),"\\to",e.serialize(r)+o,"}",e.serialize(c(t,1))])}},{name:"MinusPlus",latexTrigger:["\\mp"],kind:"infix",associativity:"any",precedence:le},{latexTrigger:["\u2213"],kind:"infix",associativity:"any",precedence:le,parse:"MinusPlus"},{name:"Multiply",latexTrigger:["\\times"],kind:"infix",associativity:"any",precedence:C,serialize:ya},{latexTrigger:["\\cdot"],kind:"infix",associativity:"any",precedence:C,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:C+2});return i===null?null:bn("Multiply",n,i)}},{latexTrigger:["\xD7"],kind:"infix",associativity:"any",precedence:C,parse:"Multiply"},{latexTrigger:["\xB7"],kind:"infix",associativity:"any",precedence:C,parse:"Multiply"},{name:"CirclePlus",latexTrigger:["\\oplus"],kind:"infix",associativity:"any",precedence:O},{latexTrigger:["\u2295"],kind:"infix",associativity:"any",precedence:O,parse:"CirclePlus"},{name:"CircleMinus",latexTrigger:["\\ominus"],kind:"infix",precedence:O},{latexTrigger:["\u2296"],kind:"infix",precedence:O,parse:"CircleMinus"},{name:"CircleTimes",latexTrigger:["\\otimes"],kind:"infix",associativity:"any",precedence:C},{latexTrigger:["\u2297"],kind:"infix",associativity:"any",precedence:C,parse:"CircleTimes"},{name:"CircleDot",latexTrigger:["\\odot"],kind:"infix",associativity:"any",precedence:C},{latexTrigger:["\u2299"],kind:"infix",associativity:"any",precedence:C,parse:"CircleDot"},{name:"CircledAst",latexTrigger:["\\circledast"],kind:"infix",associativity:"any",precedence:C},{latexTrigger:["\u229B"],kind:"infix",associativity:"any",precedence:C,parse:"CircledAst"},{name:"Star",latexTrigger:["\\star"],kind:"infix",associativity:"any",precedence:C},{latexTrigger:["\u22C6"],kind:"infix",associativity:"any",precedence:C,parse:"Star"},{latexTrigger:["\u22C5"],kind:"infix",associativity:"any",precedence:C,parse:"Multiply"},{latexTrigger:["*"],kind:"infix",associativity:"any",precedence:C,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:C+2});return i===null?["Multiply",n,Cn]:bn("Multiply",n,i)}},{name:"Mod",latexTrigger:"\\bmod",kind:"infix",precedence:Y,serialize:(e,n)=>{if(A(n)!==2)return"";let t=c(n,1),i=d(t)==="Mod"?e.wrap(t,Y+1):e.wrap(t,C),r=e.wrap(c(n,2),C);return E([i,"\\bmod",r])}},{latexTrigger:"\\mod",kind:"infix",precedence:Y,parse:"Mod"},{latexTrigger:"\\operatorname{mod}",kind:"function",parse:"Mod"},{latexTrigger:["\\mod"],kind:"function",parse:"Mod"},{latexTrigger:"\\pmod",kind:"prefix",precedence:S,parse:e=>{let n=e.parseGroup()??e.parseToken();return["Mod",e.error("missing",e.index),P(n)]}},{name:"Congruent",serialize:(e,n)=>{let t=e.serialize(c(n,1)),i=e.serialize(c(n,2));if(c(n,3)===null)return E([t,"\\equiv",i]);let r=e.serialize(c(n,3));return E([t,"\\equiv",i,"\\pmod{",r,"}"])}},{name:"Negate",latexTrigger:["-"],kind:"prefix",precedence:Pn+1,parse:(e,n)=>{e.skipSpace();let t=e.parseExpression({...n,minPrec:Pn+3});return t===null?null:["Negate",t]}},{kind:"matchfix",openTrigger:"||",closeTrigger:"||",parse:(e,n)=>R(n)?null:["Norm",n]},{name:"Norm",kind:"matchfix",openTrigger:["\\left","\\Vert"],closeTrigger:["\\right","\\Vert"],parse:(e,n)=>R(n)?null:["Norm",n],serialize:(e,n)=>{let t=c(n,1);if(d(t)==="Matrix"){let i=c(t,1),r=c(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:"Measurement",latexTrigger:["\\pm"],kind:"infix",associativity:"any",precedence:le,serialize:yc},{latexTrigger:["\\pm"],kind:"prefix",precedence:le,parse:(e,n)=>{let t=e.parseExpression({...n,minPrec:400});return["Measurement",0,P(t)]}},{latexTrigger:["\\plusmn"],kind:"infix",associativity:"any",precedence:le,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:400});return["Measurement",n,P(i)]}},{latexTrigger:["\\plusmn"],kind:"prefix",precedence:le,parse:(e,n)=>{let t=e.parseExpression({...n,minPrec:400});return["Measurement",0,P(t)]}},{latexTrigger:["\xB1"],kind:"infix",associativity:"any",precedence:le,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:400});return["Measurement",n,P(i)]}},{latexTrigger:["\xB1"],kind:"prefix",precedence:le,parse:(e,n)=>{let t=e.parseExpression({...n,minPrec:400});return["Measurement",0,P(t)]}},{name:"Power",latexTrigger:["^"],kind:"infix",serialize:Yr},{latexTrigger:"\\prod",precedence:C,name:"Product",parse:la("Product",C),serialize:fa("\\prod")},{latexTrigger:["*","*"],kind:"infix",associativity:"right",precedence:Pn,parse:(e,n,t)=>{if(e.options.strict!==!1)return null;let i=e.parseExpression({...t,minPrec:Pn});return i===null?null:["Power",n,i]}},{name:"Rational",precedence:Y,serialize:(e,n)=>n&&A(n)===1?"\\operatorname{Rational}"+e.wrapArguments(n):aa(e,n)},{name:"Reduce",serialize:(e,n)=>{let t=c(n,1);if(!t)return"";let i=c(n,2);return y(i)==="Add"?`\\sum ${e.serialize(t)}`:y(i)==="Multiply"?`\\prod ${e.serialize(t)}`:`\\operatorname{Reduce}\\left(${e.serialize(t)}, ${e.serialize(c(n,2))}\\right)`}},{name:"Root",serialize:Yr},{name:"Round",symbolTrigger:"round",kind:"function"},{name:"Square",precedence:720,serialize:(e,n)=>{let t=e.wrapShort(c(n,1));return(t.startsWith("-")?e.wrapString(t,"normal"):t)+"^2"}},{latexTrigger:["\\sum"],precedence:O,name:"Sum",parse:la("Sum",C),serialize:fa("\\sum")},{name:"Heaviside",symbolTrigger:"Heaviside",kind:"function"},{name:"Sign",symbolTrigger:"sgn",kind:"function"},{symbolTrigger:"sign",kind:"function",parse:"Sign"},{latexTrigger:["\\sign"],kind:"function",parse:"Sign"},{name:"Sqrt",latexTrigger:["\\sqrt"],parse:ra,serialize:Yr},{latexTrigger:["\u221A"],parse:ra},{latexTrigger:["\xBD"],parse:()=>["Rational",1,2]},{latexTrigger:["\u2153"],parse:()=>["Rational",1,3]},{latexTrigger:["\xBC"],parse:()=>["Rational",1,4]},{latexTrigger:["\xBE"],parse:()=>["Rational",3,4]},{latexTrigger:["\u2154"],parse:()=>["Rational",2,3]},{name:"Subtract",latexTrigger:["-"],kind:"infix",associativity:"left",precedence:O+2,parse:(e,n,t)=>{let i=e.parseExpression({...t,minPrec:O+3});return i===null?null:["Subtract",n,i]},serialize:(e,n)=>{let t=e.wrap(c(n,1),O+2),i=e.wrap(c(n,2),O+3);return i.startsWith("-")&&(i=e.wrapString(i,"normal")),E([t,"-",i])}},{name:"Distance",latexTrigger:["\\operatorname{distance}"],kind:"function",serialize:(e,n)=>"\\operatorname{distance}"+e.wrapArguments(n)}];function Sc(e,n){if(e!==null){if(y(e))return{index:y(e)??"Nothing",upper:n};if(ce(e))return{index:"Nothing",lower:e,upper:n};if(d(e)==="GreaterEqual"){let t=y(c(e,1))??"Nothing",i=c(e,2)??1;return{index:t,lower:i,upper:n}}if(d(e)==="LessEqual"){let t=b(e)??[];if(t.length===3)return{index:y(t[1])??"Nothing",lower:t[0],upper:t[2]};if(t.length===2){if(y(t[0]))return{index:y(t[0]),upper:t[1]};if(y(t[1]))return{index:y(t[1]),lower:t[0],upper:n}}}if(d(e)==="Equal"){let t=y(c(e,1))??"Nothing",i=c(e,2);if(d(i)==="Range"){let s=c(i,1)??1,o=c(i,2)??void 0;return{index:t,lower:s,upper:o}}return{index:t,lower:i??1,upper:n}}if(d(e)==="Element")return{index:y(c(e,1))??"Nothing",element:e}}}function wc(e){let n=d(e);return n?new Set(["Less","LessEqual","Greater","GreaterEqual","NotEqual","And","Or","Not"]).has(n):!1}function ua(e){if(e===null)return[];let n=Ne(e);if(n)return[...n];if(d(e)==="Tuple"){let t=b(e);return t?[...t]:[e]}return[e]}function Ac(e,n){R(e)&&(e=null),R(n)&&(n=null);let t=ua(e),i=ua(n),r=[],s=0;for(;s<t.length;){let o=t[s],a=Sc(o,i[s]);if(a){if(a.element&&s+1<t.length){let u=t[s+1];if(wc(u)&&d(u)!=="Element"&&d(u)!=="Equal"){let l=a.element;if(Array.isArray(l)&&l.length>=3){let f=[l[0],...l.slice(1),u];a.element=f}s++}}r.push(a)}s++}return r}function Pc(e){let n=new Set;for(let t of e)if(t.index&&t.index!=="Nothing"&&n.add(t.index),t.element){let i=y(c(t.element,1));i&&n.add(i)}return n}function la(e,n){return t=>{t.skipSpace();let i=t.diagnosticsCheckpoint();t.pushSymbolTable();let r=null,s=null,o=-1,a=-1;for(;!(s&&r)&&(t.peek==="_"||t.peek==="^");)t.match("_")?(o=t.index,s=t.parseGroup()??t.parseToken(),a=t.index):t.match("^")&&(r=t.parseGroup()??t.parseToken()),t.skipSpace();if(!r&&!s){let g=t.parseExpression({minPrec:n});return t.popSymbolTable(),g?[e,g]:null}let u=Ac(s,r),l=t.index,f=t.parseExpression({minPrec:n});if(t.popSymbolTable(),t.pruneUndeclared(Pc(u),i,l,o>=0?[[o,a]]:void 0),f===null)return[e];let p=[];for(let g of u){if(g.element){p.push(g.element);continue}let h=g.lower,N=g.upper,I=g.index??"Nothing";N!=null?p.push(["Tuple",I,h??1,N]):h!=null?p.push(["Tuple",I,h]):p.push(["Tuple",I])}return[e,f,...p]}}var Dc=new Set(["Tuple","Triple","Pair","Single","Limits","Element"]);function ca(e){return e==null||y(e)==="Nothing"?null:e}function _c(e){let n=[],t=b(e);if(t.length<=1)return n;for(let i of t.slice(1)){let r=d(i);if(r&&Dc.has(r)){n.push(i);continue}break}return n}function Rc(e,n){if(d(n)==="Element"){let l=e.serialize(c(n,1)),f=e.serialize(c(n,2));return{sub:`${l}\\in ${f}`}}let t=c(n,1);t!==null&&d(t)==="Hold"&&(t=c(t,1));let i=ca(c(n,2)),r=ca(c(n,3)),s={},o=t?y(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 fa(e){return(n,t)=>{let i=c(t,1);if(!i)return e;let r=_c(t),s=e;if(r.length>0){let o=[],a=[];for(let u of r){let l=Rc(n,u);l.sub&&o.push(l.sub),l.sup&&a.push(l.sup)}o.length>0&&(s=Ve("_",s,o.join(", "))),a.length>0&&(s=Ve("^",s,a.join(", ")))}return E([s,n.wrap(i,C)])}}function Kr(e){return e.skipSpace(),e.match("^")?e.parseGroup()??e.parseToken():null}function Cc(e){return M(e)===-1?!0:d(e)==="Negate"&&M(c(e,1))===1}function Qr(e,n,t){return n===null?e:Cc(n)?t():["Power",e,n]}function pa(e){let n=Kr(e),t=e.parseArguments("implicit");return t===null?n===null?"Exp":["Power","Exp",n]:Qr(["Exp",...t],n,()=>["Ln",t[0]])}function ti(e,n){let t=null;n.match("_")&&(t=n.parseGroup()??n.parseToken());let i=Kr(n),r=n.parseArguments("implicit");if(r===null&&t===null&&i===null)return e;r===null&&(r=[ve]);let s=()=>e==="Ln"?["Exp",r[0]]:["Power",t??10,r[0]],o;return t===null?o=[e,...r]:t===10?o=["Log",r[0]]:t===2?o=["Lb",...r]:o=["Log",r[0],t],Qr(o,i,s)}function ma(e){let n=Kr(e),t=e.parseArguments("implicit");return t===null&&n===null?"Lg":(t===null&&(t=[ve]),Qr(["Log",...t,10],n,()=>["Power",10,t[0]]))}function da(e){let n=e.parseArguments("implicit");return n===null?"Lb":["Log",n[0],2]}function Zn(e){let n=1,t=e;do{e=t;let i=d(e);if(i==="Negate")n*=-1,t=c(e,1);else if(i==="Multiply"){let[r,s]=Zn(c(e,1));s<0&&(n*=-1,r===1?t=["Multiply",...b(e).slice(1)]:t=["Multiply",r,...b(e).slice(1)])}else if(i==="Divide"||i==="Rational"){let[r,s]=Zn(c(e,1));s<0&&(n*=-1,t=[i,r,c(e,2)])}else{let r=M(e);r!==null&&r<0&&(n*=-1,t=-r)}}while(t!==e);return[e,n]}var Na=[{name:"Real",kind:"function",latexTrigger:["\\Re"],arguments:"implicit"},{name:"Imaginary",kind:"function",latexTrigger:["\\Im"],arguments:"implicit"},{name:"Argument",kind:"function",latexTrigger:["\\arg"],arguments:"implicit"},{symbolTrigger:"arg",kind:"function",parse:"Argument",arguments:"implicit"},{name:"Conjugate",latexTrigger:["^","\\star"],kind:"postfix"}];function v(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 p=n.parsePostfixOperator(s,t);if(p===null)break;s=p}while(!0);n.skipSpace();let o=null;n.match("^")&&(o=n.parseGroup()??n.parseToken()),n.skipSpace();let a=n.parseArguments("implicit",{minPrec:C,condition:p=>i[p.peek]!==void 0||(t?.condition?.(p)??!1)});a===null&&o!==null&&(a=[ve]);let l=a?.length===2&&(s==="Arctan"||Array.isArray(s)&&s[0]==="InverseFunction"&&s[1]==="Tan")?"Arctan2":s,f=a===null?s:typeof l=="string"?[l,...a]:["Apply",l,...a];return o===null?f:["Power",f,o]}}var Ea=[{name:"Arcsin",latexTrigger:["\\arcsin"],parse:v("Arcsin")},{name:"Arccos",latexTrigger:["\\arccos"],parse:v("Arccos")},{name:"Arctan",latexTrigger:["\\arctan"],parse:v("Arctan")},{name:"Arctan2",serialize:(e,n)=>`\\arctan(${e.serialize(c(n,1))}, ${e.serialize(c(n,2))})`},{latexTrigger:["\\arctg"],parse:v("Arctan")},{symbolTrigger:"arctg",parse:v("Arctan")},{name:"Arccot",symbolTrigger:"arcctg",parse:v("Arccot")},{latexTrigger:["\\arcctg"],parse:v("Arccot")},{name:"Arcoth",symbolTrigger:"arcoth",parse:v("Arcoth")},{symbolTrigger:"arccoth",parse:v("Arcoth")},{latexTrigger:["\\arcoth"],parse:v("Arcoth")},{latexTrigger:["\\arccoth"],parse:v("Arcoth")},{name:"Arcsec",symbolTrigger:"arcsec",parse:v("Arcsec")},{latexTrigger:["\\arcsec"],parse:v("Arcsec")},{name:"Arccsc",symbolTrigger:"arccsc",parse:v("Arccsc")},{latexTrigger:["\\arccsc"],parse:v("Arccsc")},{name:"Arsinh",symbolTrigger:"arsinh",parse:v("Arsinh")},{symbolTrigger:"arcsinh",parse:v("Arsinh")},{latexTrigger:["\\arsinh"],parse:v("Arsinh")},{latexTrigger:["\\arcsinh"],parse:v("Arsinh")},{name:"Arcosh",symbolTrigger:"arcosh",parse:v("Arcosh")},{symbolTrigger:"arccosh",parse:v("Arcosh")},{latexTrigger:"\\arcosh",parse:v("Arcosh")},{latexTrigger:"\\arccosh",parse:v("Arcosh")},{name:"Artanh",symbolTrigger:"artanh",parse:v("Artanh")},{symbolTrigger:"arctanh",parse:v("Artanh")},{latexTrigger:"\\artanh",parse:v("Artanh")},{latexTrigger:["\\arctanh"],parse:v("Artanh")},{name:"Arsech",symbolTrigger:"arsech",parse:v("Arsech")},{symbolTrigger:"arcsech",parse:v("Arsech")},{latexTrigger:["\\arsech"],parse:v("Arsech")},{latexTrigger:["\\arcsech"],parse:v("Arsech")},{name:"Arcsch",symbolTrigger:"arcsch",parse:v("Arcsch")},{symbolTrigger:"arccsch",parse:v("Arcsch")},{latexTrigger:["\\arcsch"],parse:v("Arcsch")},{latexTrigger:["\\arccsch"],parse:v("Arcsch")},{name:"Cosec",symbolTrigger:"cosec",parse:v("Cosec")},{latexTrigger:["\\cosec"],parse:v("Cosec")},{name:"Cosh",latexTrigger:["\\cosh"],parse:v("Cosh")},{latexTrigger:["\\ch"],parse:v("Cosh")},{name:"Cot",latexTrigger:["\\cot"],parse:v("Cot")},{latexTrigger:["\\cotg"],parse:v("Cot")},{latexTrigger:["\\ctg"],parse:v("Cot")},{name:"Csc",latexTrigger:["\\csc"],parse:v("Csc")},{name:"Csch",latexTrigger:["\\csch"],parse:v("Csch")},{symbolTrigger:"csch",parse:v("Csch")},{name:"Coth",latexTrigger:["\\coth"],parse:v("Coth")},{latexTrigger:["\\cth"],parse:v("Coth")},{symbolTrigger:"cth",parse:v("Coth")},{latexTrigger:["\\coth"],parse:v("Coth")},{name:"Sec",latexTrigger:["\\sec"],parse:v("Sec")},{name:"Sech",symbolTrigger:"sech",parse:v("Sech")},{latexTrigger:["\\sech"],parse:v("Sech")},{name:"Sinh",latexTrigger:["\\sinh"],parse:v("Sinh")},{latexTrigger:["\\sh"],parse:v("Sinh")},{name:"Tan",latexTrigger:["\\tan"],parse:v("Tan")},{latexTrigger:["\\tg"],parse:v("Tan")},{name:"Tanh",latexTrigger:["\\tanh"],parse:v("Tanh")},{latexTrigger:["\\th"],parse:v("Tanh")},{name:"Cos",latexTrigger:["\\cos"],parse:v("Cos")},{name:"Sin",latexTrigger:["\\sin"],parse:v("Sin")},{name:"Sinc",symbolTrigger:"sinc",kind:"function"},{name:"FresnelS",symbolTrigger:"FresnelS",kind:"function"},{name:"FresnelC",symbolTrigger:"FresnelC",kind:"function"},{symbolTrigger:"sin",parse:v("Sin")},{symbolTrigger:"cos",parse:v("Cos")},{symbolTrigger:"tan",parse:v("Tan")},{symbolTrigger:"sec",parse:v("Sec")},{symbolTrigger:"csc",parse:v("Csc")},{symbolTrigger:"cot",parse:v("Cot")},{symbolTrigger:"sinh",parse:v("Sinh")},{symbolTrigger:"cosh",parse:v("Cosh")},{symbolTrigger:"tanh",parse:v("Tanh")},{symbolTrigger:"coth",parse:v("Coth")},{symbolTrigger:"arcsin",parse:v("Arcsin")},{symbolTrigger:"asin",parse:v("Arcsin")},{symbolTrigger:"arccos",parse:v("Arccos")},{symbolTrigger:"acos",parse:v("Arccos")},{symbolTrigger:"arctan",parse:v("Arctan")},{symbolTrigger:"atan",parse:v("Arctan")},{symbolTrigger:"asinh",parse:v("Arsinh")},{symbolTrigger:"acosh",parse:v("Arcosh")},{symbolTrigger:"atanh",parse:v("Artanh")}];function yn(e,n=1){return t=>{let i=t.diagnosticsCheckpoint();t.skipVisualSpace(),t.match("\\limits"),t.skipSpace();let r=null,s=null;for(;!(s!==null&&r!==null)&&(t.peek==="_"||t.peek==="^");)t.match("_")?s=t.parseGroup()??t.parseToken():t.match("^")&&(r=t.parseGroup()??t.parseToken()),t.skipSpace();R(s)&&(s=null),R(r)&&(r=null);let o=[s??"Nothing"],a=[r??"Nothing"];t.skipVisualSpace();let u=t.index,[l,f]=Bc(t,n);if(l&&f.length===0){if(d(l)==="Add"||d(l)==="Subtract"){let p=[],g=[];for(let h of b(l))if(f)g.push(h);else{let N;[N,f]=ke(h),p.push(N??h)}if(f!==null&&g.length>0)return["Add",Ta(e,["Add",...p],{indexes:f,subs:o,sups:a})??"Nothing",...g]}else if(d(l)==="Divide"){let p;[p,f]=ke(c(l,1)),p!==null&&f!==null&&(l=["Divide",p,c(l,2)])}}return f.length>0&&t.pruneUndeclared(f,i,u),Ta(e,l,{indexes:f,subs:o,sups:a})}}function Ta(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?d(n)==="Function"?b(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 Bc(e,n=1){let t=!1,i=e.parseExpression({minPrec:266,condition:()=>{let r=e.index;return t=Sa(e),e.index=r,t}});return i!==null&&!t?ke(i):[i,Oc(e,n)]}function Oc(e,n){let t=[];for(;t.length<n&&Sa(e);){e.skipVisualSpace();let i=y(e.parseSymbol());if(i===null)return t;t.push(i)}return t}function ke(e){let n=d(e),t=c(e,1);if(!t)return[e,[]];if(n==="Sequence"&&A(e)===1)return ke(t);if(n==="Multiply"||n==="InvisibleOperator"){let i=b(e);if(i){let[r,s]=Jc(i);return r.length>0?[[n,...r],s]:[null,s]}}else if(n==="Delimiter"){let[i,r]=ke(t);if(r)return i?[["Delimiter",["Sequence",i],...b(e).slice(1)],r]:[null,r]}else if(n==="Add"){let i=b(e);if(i.length>0){let[r,s]=ke(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]=ke(t);if(r.length>0)return[i?["Negate",i]:null,r]}else if(n==="Divide"){let[i,r]=ke(t);if(r.length>0)return[["Divide",i??1,c(e,2)],r]}else{let i=b(e);if(i.length===1){let[r,s]=ke(i[0]);if(s.length>0)return[[d(e),r],s]}}return[e,[]]}function va(e){return(n,t)=>{if(!c(t,1))return e;let i=c(t,1),r=[];d(i)==="BuiltInFunction"?(r=["x"],i=[c(i,1),"x"]):d(i)==="Function"?(r=b(i).slice(1),i=c(i,1)):y(i)?r=[]:r=[];let s=b(t).slice(1),o=[],a=s.map((f,p)=>{if(y(f)==="Nothing")return o.push(y(r[p])??"Nothing"),"";if(y(f))return o.push(y(f)??"Nothing"),"";let g=d(f);if(g==="Tuple"||g==="Triple"||g==="Pair"||g==="Limits"||g==="Range"){if(A(f)===3){let h=c(f,1);o.push(y(h)??"Nothing");let N=c(f,2),I=c(f,3);return y(N)==="Nothing"&&(N=null),y(I)==="Nothing"&&(I=null),N!==null&&I!==null?`_{${n.serialize(N)}}^{${n.serialize(I)}}`:N!==null?`_{${n.serialize(N)}}`:I!==null?`^{${n.serialize(I)}}`:""}return`_{${n.serialize(f)}}`}if(A(f)===2){if(y(c(f,1))){o.push(y(c(f,1))??"Nothing");let I=c(f,2);return y(I)==="Nothing"?"":`_{${n.serialize(I)}}`}o.push(y(r[p])??"Nothing");let h=c(f,1),N=c(f,2);if(y(h)==="Nothing"&&(h=null),y(N)==="Nothing"&&(N=null),h!==null&&N!==null)return`_{${n.serialize(h)}}^{${n.serialize(N)}}`;if(h!==null)return`_{${n.serialize(h)}}`;if(N!==null)return`^{${n.serialize(N)}}`}else o.push(y(r[p])??"Nothing")}),u=o.filter(f=>y(f)!=="Nothing").map(f=>`\\mathrm{d}${n.serialize(y(f)??"x")}`);if(u.length>0&&(u=["\\,",...u]),a.length===0)return`${e}\\,${n.serialize(i)}\\!${u.join(" ")}`;let l=Fc(e,a);return l!==null?l+"\\!"+n.serialize(i)+u.join(" "):a.reverse().map(f=>`${e}${f}`).join("")+"\\!"+n.serialize(i)+u.join(" ")}}function Fc(e,n){let t=n.length;if(t!==2&&t!==3)return null;let r={"\\int":["\\iint","\\iiint"],"\\oint":["\\oiint","\\oiiint"]}[e];return!r||n.slice(1).some(s=>s)?null:r[t-2]+(n[0]??"")}var ka=[{kind:"expression",name:"Integrate",latexTrigger:["\\int"],parse:yn("Integrate"),serialize:va("\\int")},{kind:"expression",latexTrigger:["\\iint"],parse:yn("Integrate",2)},{kind:"expression",latexTrigger:["\\iiint"],parse:yn("Integrate",3)},{kind:"expression",name:"CircularIntegrate",latexTrigger:["\\oint"],parse:yn("CircularIntegrate"),serialize:va("\\oint")},{kind:"expression",latexTrigger:["\\oiint"],parse:yn("CircularIntegrate",2)},{kind:"expression",latexTrigger:["\\oiiint"],parse:yn("CircularIntegrate",3)},{kind:"expression",name:"Series",serialize:(e,n)=>"\\operatorname{Series}"+e.wrapArguments(n)},{kind:"expression",name:"Normal",serialize:(e,n)=>"\\operatorname{Normal}"+e.wrapArguments(n)},{kind:"expression",name:"InterpolatingFunction",serialize:(e,n)=>{let t=c(n,1),i="";if(d(t)==="List"&&A(t)>0){let o=b(t),a=o[0],u=o[o.length-1],l=h=>typeof h=="number"?h:h!==null&&typeof h=="object"&&"num"in h?parseFloat(h.num):null,f=l(c(a,1)),p=l(c(u,1)),g=l(c(u,2));if(f!==null&&p!==null&&g!==null){let h=N=>e.serialize(Math.round(N*1e6)/1e6);i=`\\left[${h(f)}, ${h(p+g)}\\right]`}}let r=A(n)>1?c(n,2):null,s=r===null?"":`\\left(${e.serialize(r)}\\right)`;return`\\operatorname{InterpolatingFunction}_{${i}}${s}`}},{kind:"expression",name:"BigO",latexTrigger:["\\mathcal","<{>","O","<}>"],parse:Ia,serialize:(e,n)=>"O\\left("+e.serialize(c(n,1))+"\\right)"},{kind:"expression",latexTrigger:["\\operatorname","<{>","O","<}>"],parse:Ia},{kind:"expression",latexTrigger:["\\mathrm","<{>","D","<}>"],parse:e=>Ma(e,"D_upright")},{kind:"expression",latexTrigger:["\\operatorname","<{>","D","<}>"],parse:e=>Ma(e,"D")}];function Ia(e){let n=e.parseArguments();return n===null?"BigO":["BigO",...n]}function Ma(e,n){let t=e.parseArguments();return t===null||t.length===0?n:["D",...t]}function Sa(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]=Lc(n),!i)break;t.push(i)}return[n,t]}function Lc(e){if(e.length<2)return[e,""];let n=e[e.length-2];if(n==="d"||n==="d_upright"){let t=y(e[e.length-1]);if(t)return[e.slice(0,-2),t]}return[e,""]}var Vc=new Set(["Integers","RationalNumbers","RealNumbers","ComplexNumbers","NonNegativeIntegers","AlgebraicNumbers","TranscendentalNumbers","ImaginaryNumbers","ExtendedRealNumbers","ExtendedIntegers","ExtendedRationalNumbers","ExtendedComplexNumbers"]),wa={Integers:"PositiveIntegers",NonNegativeIntegers:"PositiveIntegers",RealNumbers:"PositiveNumbers",ComplexNumbers:"UpperHalfPlane"},Aa=[{name:"Matrix",serialize:(e,n)=>{let t=b(c(n,1));return es(e,t,w(c(n,2)),w(c(n,3)))}},{name:"Vector",serialize:(e,n)=>{let t=b(n);return es(e,t.map(i=>["List",i]),w(c(n,2)),w(c(n,3)))}},{kind:"environment",symbolTrigger:"pmatrix",parse:e=>{let n=we(e),[t,i]=Se(e);return n?[t,i,{str:"()"},{str:n}]:[t,i]}},{kind:"environment",symbolTrigger:"bmatrix",parse:e=>{let n=we(e),[t,i]=Se(e);return n?[t,i,{str:"[]"},{str:n}]:[t,i,{str:"[]"}]}},{kind:"environment",symbolTrigger:"Bmatrix",parse:e=>{let n=we(e),[t,i]=Se(e);return n?[t,i,{str:"{}"},{str:n}]:[t,i,{str:"{}"}]}},{kind:"environment",symbolTrigger:"vmatrix",parse:e=>{let n=we(e),[t,i]=Se(e);return n?["Determinant",[t,i,{str:n}]]:["Determinant",[t,i]]}},{kind:"environment",symbolTrigger:"Vmatrix",parse:e=>{let n=we(e),[t,i]=Se(e);return n?["Norm",[t,i,{str:n}]]:["Norm",[t,i]]}},{kind:"environment",symbolTrigger:"smallmatrix",parse:e=>{let n=we(e),[t,i]=Se(e);return n?[t,i,{str:"()"},{str:n}]:[t,i]}},{kind:"environment",symbolTrigger:"array",parse:e=>{let n=we(e,!1),[t,i]=Se(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{kind:"environment",symbolTrigger:"matrix",parse:e=>{let n=we(e),[t,i]=Se(e);return n?[t,i,{str:".."},{str:n}]:[t,i,{str:".."}]}},{kind:"environment",symbolTrigger:"matrix*",parse:e=>{let n=we(e),[t,i]=Se(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:["^","+"],parse:(e,n)=>{if(typeof n=="string"){if(n in wa)return wa[n];if(Vc.has(n))return null}return["PseudoInverse",n]}},{name:"Inverse",serialize:(e,n)=>e.serialize(c(n,1))+"^{-1}"},{name:"Trace",kind:"function",latexTrigger:"\\tr",arguments:"implicit",serialize:(e,n)=>xn(e,n,"\\tr")},{symbolTrigger:"tr",kind:"function",parse:"Trace",arguments:"implicit"},{name:"Kernel",kind:"function",latexTrigger:"\\ker",arguments:"implicit",serialize:(e,n)=>xn(e,n,"\\ker")},{symbolTrigger:"ker",kind:"function",parse:"Kernel",arguments:"implicit"},{name:"Dimension",kind:"function",latexTrigger:"\\dim",arguments:"implicit",serialize:(e,n)=>xn(e,n,"\\dim")},{symbolTrigger:"dim",kind:"function",parse:"Dimension",arguments:"implicit"},{name:"Degree",kind:"function",latexTrigger:"\\deg",arguments:"implicit",serialize:(e,n)=>xn(e,n,"\\deg")},{symbolTrigger:"deg",kind:"function",parse:"Degree",arguments:"implicit"},{name:"Hom",kind:"function",latexTrigger:"\\hom",arguments:"implicit",serialize:(e,n)=>xn(e,n,"\\hom")},{symbolTrigger:"hom",kind:"function",parse:"Hom",arguments:"implicit"},{name:"Determinant",kind:"function",latexTrigger:"\\det",arguments:"implicit",serialize:(e,n)=>{let t=c(n,1);if(d(t)==="Matrix"){let i=b(c(t,1));return es(e,i,"||",w(c(t,2)))}return xn(e,n,"\\det")}},{symbolTrigger:"det",kind:"function",parse:"Determinant",arguments:"implicit"},{name:"MatrixMultiply",serialize:(e,n)=>{let t=e.serialize(c(n,1)),i=e.serialize(c(n,2));return`${t} \\cdot ${i}`}},{name:"HadamardProduct",latexTrigger:["\\odot"],kind:"infix",associativity:"any",precedence:C}];function Se(e){let n=e.parseTabular();return n?["Matrix",["List",...n.map(t=>["List",...t])]]:["",null]}function we(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 xn(e,n,t){if(b(n).length!==1)return`${t}${e.wrapArguments(n)}`;let r=c(n,1),s=e.serialize(r);return typeof r=="string"||typeof r=="number"?`${t} ${s}`:`${t}\\left(${s}\\right)`}function es(e,n,t,i){t??="()";let[r,s]=["",""];typeof t=="string"&&t.length===2&&([r,s]=t);let o="";if(i)for(let f of i)f==="<"?o+="l":f===">"?o+="r":f==="="?o+="c":f==="|"?o+="|":f===":"&&(o+=":");let a=[];for(let f of n??[]){let p=[];for(let g of b(f))p.push(e.serialize(g));a.push(p.join(" & "))}let u=a.join(`\\\\
7
- `),l=o.length>0?`[${o}]`:"";return r==="("&&s===")"?E(["\\begin{pmatrix}",l,u,"\\end{pmatrix}"]):r==="["&&s==="]"?E(["\\begin{bmatrix}",l,u,"\\end{bmatrix}"]):r==="{"&&s==="}"?E(["\\begin{Bmatrix}",l,u,"\\end{Bmatrix}"]):r==="|"&&s==="|"?E(["\\begin{vmatrix}",l,u,"\\end{vmatrix}"]):r==="\u2016"&&s==="\u2016"?E(["\\begin{Vmatrix}",l,u,"\\end{Vmatrix}"]):r==="{"&&s==="."?E(["\\begin{dcases}",l,u,"\\end{dcases}"]):r==="."&&s==="}"?E(["\\begin{rcases}",l,u,"\\end{rcases}"]):o||r!=="."||s!=="."?E(["\\left",Kt[r]??r,"\\begin{array}",`{${o}}`,u,"\\end{array}","\\right",Kt[s]??s]):E(["\\begin{matrix}",u,"\\end{matrix}"])}var qc=["NormalDistribution","BinomialDistribution","PoissonDistribution","UniformDistribution","ExponentialDistribution","PDF","CDF","Quantile","GammaRegularized","BetaRegularized","Covariance","PopulationCovariance","Correlation","LinearRegression","PolynomialFit"],Pa=[...qc.map(e=>({kind:"expression",name:e,serialize:(n,t)=>`\\operatorname{${e}}`+n.wrapArguments(t)})),{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||!y(t)?null:["Mean",t]}},{latexTrigger:"\\operatorname{var}",kind:"function",parse:"Variance"},{latexTrigger:"\\operatorname{cov}",kind:"function",parse:"Covariance"},{latexTrigger:"\\operatorname{corr}",kind:"function",parse:"Correlation"}];var ri={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},Da=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"]),si={m:{dimension:[1,0,0,0,0,0,0,0],scale:1},kg:{dimension:[0,1,0,0,0,0,0,0],scale:1},g:{dimension:[0,1,0,0,0,0,0,0],scale:.001},s:{dimension:[0,0,1,0,0,0,0,0],scale:1},A:{dimension:[0,0,0,1,0,0,0,0],scale:1},K:{dimension:[0,0,0,0,1,0,0,0],scale:1},mol:{dimension:[0,0,0,0,0,1,0,0],scale:1},cd:{dimension:[0,0,0,0,0,0,1,0],scale:1},Hz:{dimension:[0,0,-1,0,0,0,0,0],scale:1},N:{dimension:[1,1,-2,0,0,0,0,0],scale:1},Pa:{dimension:[-1,1,-2,0,0,0,0,0],scale:1},J:{dimension:[2,1,-2,0,0,0,0,0],scale:1},W:{dimension:[2,1,-3,0,0,0,0,0],scale:1},C:{dimension:[0,0,1,1,0,0,0,0],scale:1},V:{dimension:[2,1,-3,-1,0,0,0,0],scale:1},F:{dimension:[-2,-1,4,2,0,0,0,0],scale:1},ohm:{dimension:[2,1,-3,-2,0,0,0,0],scale:1},S:{dimension:[-2,-1,3,2,0,0,0,0],scale:1},Wb:{dimension:[2,1,-2,-1,0,0,0,0],scale:1},T:{dimension:[0,1,-2,-1,0,0,0,0],scale:1},H:{dimension:[2,1,-2,-2,0,0,0,0],scale:1},lm:{dimension:[0,0,0,0,0,0,1,0],scale:1},lx:{dimension:[-2,0,0,0,0,0,1,0],scale:1},Bq:{dimension:[0,0,-1,0,0,0,0,0],scale:1},Gy:{dimension:[2,0,-2,0,0,0,0,0],scale:1},Sv:{dimension:[2,0,-2,0,0,0,0,0],scale:1},kat:{dimension:[0,0,-1,0,0,1,0,0],scale:1},degC:{dimension:[0,0,0,0,1,0,0,0],scale:1,offset:273.15},degF:{dimension:[0,0,0,0,1,0,0,0],scale:5/9,offset:459.67},min:{dimension:[0,0,1,0,0,0,0,0],scale:60},h:{dimension:[0,0,1,0,0,0,0,0],scale:3600},d:{dimension:[0,0,1,0,0,0,0,0],scale:86400},wk:{dimension:[0,0,1,0,0,0,0,0],scale:604800},ha:{dimension:[2,0,0,0,0,0,0,0],scale:1e4},L:{dimension:[3,0,0,0,0,0,0,0],scale:.001},t:{dimension:[0,1,0,0,0,0,0,0],scale:1e3},eV:{dimension:[2,1,-2,0,0,0,0,0],scale:1602176634e-28},Da:{dimension:[0,1,0,0,0,0,0,0],scale:16605390666e-37},au:{dimension:[1,0,0,0,0,0,0,0],scale:149597870700},deg:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/180},rad:{dimension:[0,0,0,0,0,0,0,0],scale:1},grad:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/200},turn:{dimension:[0,0,0,0,0,0,0,0],scale:2*Math.PI},arcmin:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/10800},arcsec:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/648e3},percent:{dimension:[0,0,0,0,0,0,0,0],scale:.01},ppm:{dimension:[0,0,0,0,0,0,0,0],scale:1e-6},dB:{dimension:[0,0,0,0,0,0,0,0],scale:1},Np:{dimension:[0,0,0,0,0,0,0,0],scale:1},in:{dimension:[1,0,0,0,0,0,0,0],scale:.0254},ft:{dimension:[1,0,0,0,0,0,0,0],scale:.3048},yd:{dimension:[1,0,0,0,0,0,0,0],scale:.9144},mi:{dimension:[1,0,0,0,0,0,0,0],scale:1609.344},lb:{dimension:[0,1,0,0,0,0,0,0],scale:.45359237},oz:{dimension:[0,1,0,0,0,0,0,0],scale:.028349523125},gal:{dimension:[3,0,0,0,0,0,0,0],scale:.003785411784},qt:{dimension:[3,0,0,0,0,0,0,0],scale:.000946352946},pt:{dimension:[3,0,0,0,0,0,0,0],scale:.000473176473},cup:{dimension:[3,0,0,0,0,0,0,0],scale:.0002365882365},atm:{dimension:[-1,1,-2,0,0,0,0,0],scale:101325},bar:{dimension:[-1,1,-2,0,0,0,0,0],scale:1e5},cal:{dimension:[2,1,-2,0,0,0,0,0],scale:4.184},kWh:{dimension:[2,1,-2,0,0,0,0,0],scale:36e5},\u00C5:{dimension:[1,0,0,0,0,0,0,0],scale:1e-10},USD:{dimension:[0,0,0,0,0,0,0,1],scale:1},cent:{dimension:[0,0,0,0,0,0,0,1],scale:.01}};function $c(e){if(e.length>2){let n=e.slice(0,2),t=e.slice(2);if(ri[n]!==void 0&&Da.has(t)){let i=si[t];if(i)return{prefixScale:ri[n],baseEntry:i}}}if(e.length>1){let n=e.slice(0,1),t=e.slice(1);if(ri[n]!==void 0&&Da.has(t)){let i=si[t];if(i)return{prefixScale:ri[n],baseEntry:i}}}return null}function jc(e){let n=si[e];if(n)return n;let t=$c(e);return t?{dimension:t.baseEntry.dimension,scale:t.prefixScale*t.baseEntry.scale}:null}function ns(e){let n=jc(e);return n?n.dimension:null}var Oh=new Map(["N","J","W","Pa","Hz","C","V","F","ohm","S","Wb","T","H","lm","lx","Gy","kat"].map(e=>[si[e].dimension.join(","),e]));function Gc(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 Un(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 Un(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=Un(r),a=Un(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=>Un(a));return o.some(a=>a===null)?null:o.length===1?o[0]:["Multiply",...o]}return e[0]==="("?null:Gc(e)}function _a(e){return e=e.trim(),e.length===0?null:/[/*^()]/.test(e)?Un(e):e}function Oa(e){for(;e.peek==="<space>";)e.nextToken();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>"){n.length>0&&!n.endsWith(" ")&&(n+=" "),e.nextToken();continue}if(i==="<$>"){n+="$",e.nextToken();continue}if(i==="\\cdot"){n+="*",e.nextToken();continue}if(i==="^"){n+="^",e.nextToken();continue}n+=i,e.nextToken()}return null}var Fa=new Set(["d"]),zc={inch:"in",inches:"in","in.":"in",foot:"ft",feet:"ft","ft.":"ft",mile:"mi",miles:"mi",yard:"yd",yards:"yd",meter:"m",meters:"m",metre:"m",metres:"m",centimeter:"cm",centimeters:"cm",centimetre:"cm",centimetres:"cm",kilometer:"km",kilometers:"km",kilometre:"km",kilometres:"km",gallon:"gal",gallons:"gal",quart:"qt",quarts:"qt",pint:"pt",pints:"pt",cup:"cup",cups:"cup",liter:"L",liters:"L",litre:"L",litres:"L",ounce:"oz",ounces:"oz",pound:"lb",pounds:"lb",gram:"g",grams:"g",kilogram:"kg",kilograms:"kg",second:"s",seconds:"s",minute:"min",minutes:"min",hour:"h",hours:"h",day:"d",days:"d",week:"wk",weeks:"wk",dollar:"USD",dollars:"USD",$:"USD",cent:"cent",cents:"cent",degree:"deg",degrees:"deg",mph:"mi/h",per:"/"};function Zc(e){return e.replace(/\$|[A-Za-z.]+/g,n=>zc[n]??n)}function ts(e){if(!e)return null;let n=e.trim();if(n.length===0||Fa.has(n))return null;let t=Zc(n).replace(/\s+/g,"");if(ns(t)!==null)return t;if(/[/*^]/.test(t))try{let i=_a(t);if(i!==null&&is(i))return i}catch{return null}return null}function is(e){if(typeof e=="string")return ns(e)!==null;if(!Array.isArray(e))return!1;let n=e[0];return n==="Multiply"||n==="Divide"?e.slice(1).every(t=>is(t)):n==="Power"?is(e[1]):!1}function Uc(e){let n=e.index;if(!e.match("^"))return null;if(e.match("<{>")){let i="";for(;!e.atEnd&&e.peek!=="<}>";)i+=e.peek,e.nextToken();return e.match("<}>")?i:(e.index=n,null)}if(e.atEnd)return e.index=n,null;let t=e.peek;return e.nextToken(),t}var Ra=e=>{let n=e.index,t=Oa(e);if(t===null)return e.index=n,null;let i=e.index;if(!Fa.has(t.trim())){let s=Uc(e);if(s!==null){let o=ts(`${t}^${s}`);if(o!==null)return["__unit__",o];e.index=i}}let r=ts(t);return r===null?(e.index=n,null):["__unit__",r]};function We(e){let n=y(e);if(n!==null)return n;if(typeof e=="number")return String(e);let t=d(e);if(!t)return"";if(t==="Divide"){let i=c(e,1),r=c(e,2);return`${We(i)}/${We(r)}`}if(t==="Multiply"){let i=[];if(Array.isArray(e))for(let r=1;r<e.length;r++)i.push(We(e[r]));return i.join("\\cdot ")}if(t==="Power"){let i=c(e,1),r=c(e,2),s=typeof r=="number"?String(r):y(r)??String(r);return`${We(i)}^{${s}}`}if(t==="Square"){let i=c(e,1);return`${We(i)}^{2}`}return""}function Ca(e){let n=e.parseGroup();if(n===null)return null;let t=Ja(e);return t===null?null:["Quantity",n,t]}function Ba(e){return Ja(e)}function Ja(e){let n=e.index,t=Oa(e);if(t===null)return e.index=n,null;let i=ts(t);return i===null?(e.index=n,null):i}var La=[{latexTrigger:"\\mathrm",kind:"expression",parse:Ra},{latexTrigger:"\\text",kind:"expression",parse:Ra},{latexTrigger:"\\qty",parse:Ca},{latexTrigger:"\\SI",parse:Ca},{latexTrigger:"\\unit",parse:Ba},{latexTrigger:"\\si",parse:Ba},{name:"Quantity",serialize:(e,n)=>{let t=c(n,1),i=c(n,2);if(t===null||i===null)return"";let r=y(i),s=r==="deg"||r==="rad"||r==="arcmin"||r==="arcsec",o=e.options;if(s&&(o.dmsFormat||o.angleNormalization&&o.angleNormalization!=="none")){let l=M(t);if(l===null){let p=e.serialize(t),g=We(i);return E([p,"\\,",`\\mathrm{${g}}`])}let f=l;return r==="rad"?f=f*180/Math.PI:r==="arcmin"?f=f/60:r==="arcsec"&&(f=f/3600),o.angleNormalization&&o.angleNormalization!=="none"&&(f=Qt(f,o.angleNormalization)),o.dmsFormat?ei(f):`${f}\xB0`}let a=e.serialize(t);d(t)==="Measurement"&&(a=`\\left(${a}\\right)`);let u=We(i);return E([a,"\\,",`\\mathrm{${u}}`])}}];var Hc=["pt","em","mu","ex","mm","cm","in","bp","sp","dd","cc","pc","nc","nd"];function Va(e){for(e.skipSpace(),(e.peek==="-"||e.peek==="+")&&e.nextToken();/^[\d.]$/.test(e.peek);)e.nextToken();for(let n of Hc)if(e.matchAll([...n]))return}function Wc(e){return n=>{let t=n.parseGroup();return t===null?[e]:[e,t]}}function re(e,n){return{name:e,latexTrigger:[n],parse:Wc(e),serialize:(t,i)=>{let r=c(i,1);return r===null?n:`${n}{${t.serialize(r)}}`}}}function Re(e,n){return(t,i)=>{let r=t.parseExpression({...i??{},minPrec:C});if(r===null||R(r))return n??[e];let s=d(r);return s==="InvisibleOperator"||s==="Multiply"?[e,...b(r)]:[e,r]}}function qa(e){return(n,t)=>{let i=b(t);return i.length===0?e:e+" "+i.map(r=>n.serialize(r)).join("")}}function $a(e){return n=>{let t=n.parseGroup()??n.parseToken();if(t===null||R(t))return[e];let i=d(t);return i==="InvisibleOperator"||i==="Multiply"?[e,...b(t)]:[e,t]}}function ja(e){return(n,t)=>{let i=b(t);return e+"{"+i.map(r=>n.serialize(r)).join("")+"}"}}function oi(e){return n=>{let t=n.parseExpression();return t!==null&&!R(t)?["Annotated",t,{dict:{mathStyle:e}}]:"Nothing"}}function de(e){return n=>{let t=n.parseExpression();return t!==null&&!R(t)?["Annotated",t,{dict:{size:e}}]:"Nothing"}}var Ga=[{name:"Overscript",latexTrigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",latexTrigger:["\\underset"],kind:"infix",precedence:700},{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;if(i===null||t===null)return null;if(i!=="Nothing"){let a=Ne(i)??[i];e.skipSpace();let u=e.parseGroup()??e.parseSymbol()??"Nothing";if(!R(u)){let p=e.parseArguments();p&&(u=[u,...p])}let l=M(t)??1,f=a.length===1&&l>1?Array.from({length:l},()=>a[0]):[...a];return["D",u,...f]}let r=[],s=()=>{e.skipSpace();let o=e.parseGroup()??e.parseSymbol()??"Nothing",a=1;if(d(o)==="Power")a=M(c(o,2))??1,o=c(o,1)??o;else if(e.match("^")){let u=e.parseGroup()??e.parseToken();a=M(u)??1}for(let u=0;u<a;u++)r.push(o)};for(s();e.skipSpace(),!!e.match("\\partial");)s();return r.length===1?["PartialDerivative",r[0],t]:["PartialDerivative",["List",...r],t]},precedence:740},re("OverBar","\\overline"),re("UnderBar","\\underline"),re("OverVector","\\vec"),re("OverTilde","\\tilde"),re("OverHat","\\hat"),re("OverRightArrow","\\overrightarrow"),re("OverLeftArrow","\\overleftarrow"),re("OverRightDoubleArrow","\\Overrightarrow"),re("OverLeftHarpoon","\\overleftharpoon"),re("OverRightHarpoon","\\overrightharpoon"),re("OverLeftRightArrow","\\overleftrightarrow"),re("OverBrace","\\overbrace"),re("UnderBrace","\\underbrace"),re("OverLineSegment","\\overlinesegment"),re("OverGroup","\\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"}},...["\\cancel","\\bcancel","\\xcancel"].map(e=>({latexTrigger:[e],parse:n=>n.parseGroup()??"Nothing"})),{latexTrigger:["\\cancelto"],parse:e=>{let n=e.parseGroup();return e.parseGroup(),n??"Nothing"}},{latexTrigger:["\\textbf"],parse:e=>$(e,{fontWeight:"bold"})},{latexTrigger:["\\textit"],parse:e=>$(e,{fontStyle:"italic"})},{latexTrigger:["\\emph"],parse:e=>$(e,{fontStyle:"italic"})},{latexTrigger:["\\textup"],parse:e=>$(e,{fontStyle:"normal"})},{latexTrigger:["\\texttt"],parse:e=>$(e,{fontFamily:"monospace"})},{latexTrigger:["\\textsf"],parse:e=>$(e,{fontFamily:"sans-serif"})},{latexTrigger:["\\textrm"],parse:e=>$(e)},{latexTrigger:["\\mbox"],parse:e=>$(e)},{latexTrigger:["\\displaystyle"],parse:oi("normal")},{latexTrigger:["\\textstyle"],parse:oi("compact")},{latexTrigger:["\\scriptstyle"],parse:oi("script")},{latexTrigger:["\\scriptscriptstyle"],parse:oi("scriptscript")},{latexTrigger:["\\color"],parse:e=>{let n=e.parseStringGroup();if(n!==null){let t=e.parseExpression();if(t!==null&&!R(t))return["Annotated",t,{dict:{color:n}}]}return"Nothing"}},{latexTrigger:["\\tiny"],parse:de(1)},{latexTrigger:["\\scriptsize"],parse:de(2)},{latexTrigger:["\\footnotesize"],parse:de(3)},{latexTrigger:["\\small"],parse:de(4)},{latexTrigger:["\\normalsize"],parse:de(5)},{latexTrigger:["\\large"],parse:de(6)},{latexTrigger:["\\Large"],parse:de(7)},{latexTrigger:["\\LARGE"],parse:de(8)},{latexTrigger:["\\huge"],parse:de(9)},{latexTrigger:["\\Huge"],parse:de(10)},{name:"Annotated",serialize:(e,n)=>{let t=e.serialize(c(n,1)),i=So(c(n,2));if(i==null)return t;let r=w(c(n,1));r!==null&&(i.dict.fontFamily==="monospace"||i.dict.fontFamily==="sans-serif"||i.dict.fontWeight==="bold"||i.dict.fontStyle==="italic"||i.dict.fontStyle==="normal")&&(t=r),i.dict.mathStyle==="normal"?t=E(["{\\displaystyle",t,"}"]):i.dict.mathStyle==="compact"?t=E(["{\\textstyle",t,"}"]):i.dict.mathStyle==="script"?t=E(["{\\scriptstyle",t,"}"]):i.dict.mathStyle==="scriptscript"&&(t=E(["{\\scriptscriptstyle",t,"}"]));let s=i.dict.size;return s!==null&&s>=1&&s<=10&&(t=E(["{",{1:"\\tiny",2:"\\scriptsize",3:"\\footnotesize",4:"\\small",5:"\\normalsize",6:"\\large",7:"\\Large",8:"\\LARGE",9:"\\huge",10:"\\Huge"}[s],t,"}"])),i.dict.fontFamily==="monospace"?t=E(["\\texttt{",t,"}"]):i.dict.fontFamily==="sans-serif"&&(t=E(["\\textsf{",t,"}"])),i.dict.fontWeight==="bold"&&(t=E(["\\textbf{",t,"}"])),i.dict.fontStyle==="italic"?t=E(["\\textit{",t,"}"]):i.dict.fontStyle==="normal"&&(t=E(["\\textup{",t,"}"])),i.dict.color&&(t=E(["\\textcolor{",i.dict.color,"}{",t,"}"])),i.dict.backgroundColor&&(t=E(["\\colorbox{",i.dict.backgroundColor,"}{",t,"}"])),i.dict.border===!0&&(t=E(["\\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=>(Va(e),["HorizontalSpacing",0])},{latexTrigger:["\\kern"],parse:e=>(Va(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(c(n,2)!==null){let i=w(c(n,2)),r=e.serialize(c(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=M(c(n,1));return t===null?"":{"-3":"\\!",6:"\\ ",3:"\\,",4:"\\:",5:"\\;",9:"\\enspace",18:"\\quad",36:"\\qquad"}[t]??""}},{latexTrigger:"\\operatorname{count}",kind:"function",parse:"Length"},{latexTrigger:"\\operatorname{length}",kind:"function",parse:"Length"},{latexTrigger:"\\operatorname{nCr}",kind:"function",parse:"Choose"},{latexTrigger:"\\operatorname{nPr}",parse:e=>{let n=e.parseArguments("enclosure");return!n||n.length!==2?null:["Multiply",["Choose",n[0],n[1]],["Factorial",n[1]]]}},{latexTrigger:"\\operatorname{random}",kind:"function",parse:"Random"},{latexTrigger:"\\operatorname{shuffle}",kind:"function",parse:"Shuffle"},{latexTrigger:"\\operatorname{repeat}",kind:"function",parse:"Repeat"},{latexTrigger:"\\operatorname{join}",kind:"function",parse:"Join"},{latexTrigger:"\\operatorname{range}",kind:"function",parse:"Range"},{latexTrigger:"\\operatorname{histogram}",kind:"function",parse:"Histogram"},{latexTrigger:"\\operatorname{pdf}",kind:"function",parse:"PDF"},{latexTrigger:"\\operatorname{cdf}",kind:"function",parse:"CDF"},{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)},{name:"Polygon",latexTrigger:["\\operatorname{polygon}"],kind:"function",serialize:(e,n)=>"\\operatorname{polygon}"+e.wrapArguments(n)},{name:"PointList",latexTrigger:["\\operatorname{PointList}"],kind:"function",serialize:(e,n)=>"\\operatorname{PointList}"+e.wrapArguments(n)},{name:"Angle",latexTrigger:["\\angle"],kind:"prefix",precedence:S,parse:Re("Angle"),serialize:qa("\\angle")},{latexTrigger:["\\varangle"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\\measuredangle"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\\Varangle"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\u2220"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\u2221"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\\triangle"],kind:"prefix",precedence:S,parse:Re("Triangle")},{name:"Quadrilateral",latexTrigger:["\\square"],kind:"prefix",precedence:S,parse:Re("Quadrilateral",ve),serialize:qa("\\square")},{name:"Perpendicular",latexTrigger:["\\perp"],kind:"infix",precedence:S},{name:"Parallel",latexTrigger:["\\parallel"],kind:"infix",precedence:S},{name:"Arc",latexTrigger:["\\widehat"],parse:$a("Arc"),serialize:ja("\\widehat")},{name:"OverParen",latexTrigger:["\\overparen"],parse:$a("OverParen"),serialize:ja("\\overparen")}];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 Yc=[{name:"Mu0",kind:"symbol",latexTrigger:"\\mu_0"},{name:"VacuumPermittivity",kind:"symbol",latexTrigger:"\\varepsilon_0"}];var Xc=[...Uo,...Qo,...ea,...Ro,...ia,...cn,...xa,...Na,...Ea,...ka,...Aa,...Pa,...La,...Ga,...Yc,...za];var rs;function Ha(e){if(!rs){let t=`^[${["Zyyy","Zinh","Arab","Armn","Beng","Bopo","Cyrl","Deva","Ethi","Geor","Grek","Gujr","Guru","Hang","Hani","Hebr","Hira","Kana","Knda","Khmr","Laoo","Latn","Mlym","Mymr","Orya","Sinh","Taml","Telu","Thaa","Thai","Tibt"].map(i=>`\\p{Script=${i}}`).join("")}]*$`;rs=new RegExp(t,"u")}return rs.test(e)}function Ye(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)||Nn.test(e)?!0:Ha(e)?/^[\p{XIDS}_]\p{XIDC}*$/u.test(e):!1}var Kc="\\u{FE0F}",Qc="\\u{20E3}",ef="\\u{200D}",nf="\\p{RI}\\p{RI}",tf="(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})",Za=`(?:\\p{EMod}|${Kc}${Qc}?|${tf})`,rf="(?:(?=\\P{XIDC})(?=[^\\x23\\x2a\\x30-\\x39])\\p{Emoji})",Ua=`(?:${rf}${Za}*|\\p{Emoji}${Za}+|${nf})`,Wa=`(?:${Ua})(${ef}${Ua})*`,sf=new RegExp(`(?:${Wa})+`,"u"),Nn=new RegExp(`^(?:${Wa})+$`,"u");function ss(e){return typeof e!="string"?"not-a-string":e===""?"empty-string":e.normalize()!==e?"expected-nfc":/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(e)?"unexpected-bidi-marker":Nn.test(e)?"valid":/\p{XIDC}/u.test(e)&&sf.test(e)?"unexpected-mixed-emoji":Ha(e)?Ye(e)?"valid":Ye(e[0])?"invalid-char":"invalid-first-char":"unexpected-script"}var Hn=null;function af(){if(!Hn){Hn=new Map;for(let[e,n]of He)Hn.has(n)||Hn.set(n,e)}return Hn}var Ya={"\\mathord":"","\\mathop":"","\\mathbin":"","\\mathrel":"","\\mathopen":"","\\mathclose":"","\\mathpunct":"","\\mathinner":"","\\operatorname":"","\\text":"","\\mathrm":"_upright","\\mathit":"_italic","\\mathbf":"_bold","\\bold":"_bold","\\boldsymbol":"_bold","\\bm":"_bold","\\mathscr":"_script","\\mathcal":"_calligraphic","\\mathfrak":"_fraktur","\\mathsf":"_sansserif","\\mathtt":"_monospace","\\mathbb":"_doublestruck"},uf={"\\mathring":"_ring","\\hat":"_hat","\\tilde":"_tilde","\\vec":"_vec","\\overline":"_bar","\\underline":"_underbar","\\dot":"_dot","\\ddot":"_ddot","\\dddot":"_dddot","\\ddddot":"_ddddot","\\acute":"_acute","\\grave":"_grave","\\breve":"_breve","\\check":"_check"};function Xa(e,n){if(e.atEnd)return null;let t=e.peek,i={"\\_":"_","\\#":"hash"}[t];if(!i&&!n.toplevel&&(i={"+":"plus","-":"minus","\\plusmn":"pm","\\pm":"pm","\\ast":"ast","\\dag":"dag","\\ddag":"ddag","\\bot":"bottom","\\top":"top","\\bullet":"bullet","\\cir":"circle","\\diamond":"diamond","\\times":"times","\\square":"square","\\star":"star"}[t]),i)return e.nextToken(),i;let r=af().get(t);if(r!==void 0)return e.nextToken(),r;let s=e.parseChar();if(s!==null)return/^\p{XIDC}+$/u.test(s)?s:[...s].length===1?"____"+s.codePointAt(0).toString(16).toUpperCase().padStart(6,"0"):s;let o=e.peek;return o&&/^[\p{XIDC}\p{M}]/u.test(o)?e.nextToken():null}function Wn(e){let n=os(e),t=uf[e.peek]??null;if(t){if(e.nextToken(),!e.match("<{>"))return null;let s=Wn(e);if(s===null||!e.match("<}>"))return null;n=`${s}${t}`}if(n===null){for(n="";!e.atEnd;){let s=e.peek;if(s==="<}>"||s==="_"||s==="^")break;if(s==="<space>"){e.nextToken();continue}if(Nn.test(n+s)){n+=e.nextToken();continue}let o=Xa(e,{toplevel:!1});if(o===null)return null;n+=o}for(;!e.atEnd&&/\d/.test(e.peek);)n+=e.nextToken()}for(;!e.atEnd;)if(e.match("\\degree"))n+="_deg";else if(e.matchAll(["^","\\circ"]))n+="_deg";else if(e.matchAll(["^","\\prime"]))n+="_prime";else if(e.matchAll(["^","<{>","\\prime","<}>"]))n+="_prime";else if(e.matchAll(["^","<{>","\\doubleprime","<}>"]))n+="_dprime";else if(e.matchAll(["^","<{>","\\prime","\\prime","<}>"]))n+="_dprime";else break;let i=[],r=[];for(;!e.atEnd;)if(e.match("_")){let s=e.match("<{>"),o=Wn(e);if(s&&!e.match("<}>")||o===null)return null;r.push(o)}else if(e.match("^")){let s=e.match("<{>"),o=Wn(e);if(s&&!e.match("<}>")||o===null)return null;i.push(o)}else break;return i.length>0&&(n+="__"+i.join("")),r.length>0&&(n+="_"+r.join("")),n}function os(e){let n=Ya[e.peek]??null;if(n===null)return null;let t=e.index;if(e.nextToken(),e.match("<{>")){let i="",r={0:"zero",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine"}[e.peek]??"";r&&(i=r,e.nextToken());let s=Wn(e);return s===null||!e.match("<}>")?(e.index=t,null):(i+=s,n==="_upright"&&i.length>1?i:i+n)}return e.index=t,null}function as(e){let n=e.index,t=os(e);if(t!==null)return Ye(t)?null:e.error(["invalid-symbol",{str:ss(t)}],n);if(e.index=n,(Ya[e.peek]??null)===null)return null;if(e.nextToken(),!e.match("<{>"))return e.index=n,null;let r=e.index,s=0;for(;!e.atEnd&&!(s===0&&e.peek==="<}>");)e.peek==="<{>"&&(s+=1),e.peek==="<}>"&&(s-=1),e.nextToken();let o=e.latex(r,e.index);return Ye(o)?(e.index=n,null):(e.match("<}>"),e.error(["invalid-symbol",{str:ss(o)}],n))}function Yn(e){if(/^[a-zA-Z]$/.test(e.peek)||/^\p{XIDS}$/u.test(e.peek)){let i=e.nextToken(),s=e.getSymbolType(i).matches("indexed_collection"),o=e.hasSubscriptEvaluate(i);for(;!e.atEnd&&!s&&!o&&e.peek==="_";){let u=e.index;if(e.nextToken(),e.match("<{>")){let f=e.peek;if(f==="("||f==="\\lparen"||f==="\\left"){e.index=u;break}let p=Wn(e);if(p===""&&e.peek==="<}>"){e.match("<}>");continue}let g=p!==null&&/plus|minus|times|ast/.test(p);if(p===null||p.includes(",")||g||e.peek!=="<}>"){e.index=u;break}e.match("<}>"),i+="_"+p}else{let f=e.peek;if(e.options.strict===!1&&/^[0-9]$/.test(f)){let p="";for(;!e.atEnd&&/^[0-9]$/.test(e.peek);)p+=e.peek,e.nextToken();i+="_"+p}else if(/^[a-zA-Z0-9]$/.test(f)||/^\p{XIDS}$/u.test(f))e.nextToken(),i+="_"+f;else{e.index=u;break}}}return i}let n=os(e);if(!n){for(n="";!e.atEnd&&Nn.test(n+e.peek);)n+=e.nextToken();n||(n=null)}let t=e.index;return n??=Xa(e,{toplevel:!0}),n&&(n=n.normalize(),Ye(n))?n:(e.index=t,null)}function lf(e){let n=!!e.matchAny(["-","\u2212"]);for(;e.matchAny(["+","\uFE62"])||e.skipSpace();)e.matchAny(["-","\u2212"])&&(n=!n);return n?"-":"+"}function Ce(e,n,t="whole"){let i=[],r=!1;for(;!r;){for(;/^[0-9]$/.test(e.peek);)i.push(e.nextToken()),e.skipVisualSpace();r=!0;let s=t==="whole"?n.wholeDigitGroupSeparatorTokens:n.fractionalDigitGroupSeparatorTokens;if(t!=="none"){let o=e.index;e.skipVisualSpace();let a=n.decimalSeparatorTokens.length===3&&n.decimalSeparatorTokens[0]==="<{>"&&n.decimalSeparatorTokens[1]===","&&n.decimalSeparatorTokens[2]==="<}>";s.length>0&&e.matchAll(s)||!a&&e.matchAll(["<{>",",","<}>"])?(e.skipVisualSpace(),/^[0-9]$/.test(e.peek)?r=!1:e.index=o):e.index=o}}return i.join("")}function us(e,n,t){let i=e.index,r=lf(e),s=Ce(e,n,t);return s?r==="-"?"-"+s:s:(e.index=i,"")}function cf(e,n){let t=e.index;if(e.skipVisualSpace(),e.matchAny(["e","E"])){let i=us(e,n,"none");if(i)return i}if(e.index=t,e.match("\\times")&&(e.skipVisualSpace(),e.matchAll(["1","0"])&&(e.skipVisualSpace(),e.match("^")))){if(e.skipVisualSpace(),/^[0-9]$/.test(e.peek))return e.nextToken();if(e.match("<{>")){e.skipVisualSpace();let i=us(e,n,"whole");if(e.skipVisualSpace(),i&&e.match("<}>"))return i}}if(e.index=t,e.skipVisualSpace(),e.match("\\%"))return"-2";if(e.index=t,e.matchAll(n.exponentProductTokens)&&(e.skipVisualSpace(),e.matchAll(n.beginExponentMarkerTokens))){e.skipVisualSpace();let i=us(e,n,"none");if(e.skipVisualSpace(),i&&e.matchAll(n.endExponentMarkerTokens))return i}return e.index=t,""}function Ka(e){let n=e.index;if(e.matchAll(["\\overset","<{>"])&&(e.match(".")||e.match("\\cdots"))&&e.matchAll(["<}>","<{>"])){let t=e.nextToken();if(t&&/^\d$/.test(t)&&e.match("<}>"))return t}return e.index=n,null}function ff(e){let n=e.length;for(let t=1;t<=n>>1;t++){let i=e.slice(n-t),r=1;for(;(r+1)*t<=n&&e.startsWith(i,n-(r+1)*t);)r+=1;if(r>=(t===1?3:2))return[e.slice(0,n-r*t),i]}return null}function pf(e){let n=e.peek;return n==="\\overline"||n==="\\overset"||n==="\\wideparen"||n==="\\overarc"||n==="("||n==="\\left"}function cs(e,n){let t=e.index,i=e.options.repeatingDecimal,r="";if((i==="auto"||i==="parentheses")&&e.match("("))return r=Ce(e,n,"fraction"),r&&e.match(")")?`(${r})`:(e.index=t,"");if(e.index=t,(i==="auto"||i==="parentheses")&&e.matchAll(["\\left","("]))return r=Ce(e,n,"fraction"),r&&e.matchAll(["\\right",")"])?`(${r})`:(e.index=t,"");if(e.index=t,(i==="auto"||i==="vinculum")&&e.matchAll(["\\overline","<{>"]))return r=Ce(e,n,"fraction"),r&&e.match("<}>")?`(${r})`:(e.index=t,"");if(e.index=t,(i==="auto"||i==="arc")&&(e.matchAll(["\\wideparen","<{>"])||e.matchAll(["\\overarc","<{>"])))return r=Ce(e,n,"fraction"),r&&e.match("<}>")?`(${r})`:(e.index=t,"");if(e.index=t,i==="auto"||i==="dots"){let s=Ka(e);if(s!==null){if(r=Ce(e,n,"fraction"),!r)return`(${s})`;let o=Ka(e);if(o!==null)return`(${s}${r}${o})`}}return e.index=t,""}function ls(e){return e===0?{num:"0"}:Number.isInteger(e)&&Math.abs(e)<Le?e:{num:e.toString()}}function Qa(e,n){let t=e.options.parseNumbers;if(t===!1||t==="never")return null;let i=e.index;e.skipVisualSpace();let r=1;for(;e.peek==="-"||e.peek==="+";)e.match("-")?r=-r:e.match("+"),e.skipVisualSpace();let s="",o="",a=!1;if(e.match(".")||e.matchAll(n.decimalSeparatorTokens)){let g=e.peek;(/^[\d]$/.test(g)||pf(e))&&(a=!0,s="0")}else s=Ce(e,n,"whole");if(!s)return e.index=i,null;let u=e.index,l=!1;(a||e.match(".")||e.matchAll(n.decimalSeparatorTokens))&&(o=Ce(e,n,"fraction"),l=!0);let f=!1;if(l){let g=cs(e,n);if(g&&(o+=g,f=!0),(e.match("\\ldots")||e.matchAll(n.truncationMarkerTokens))&&!f){let h=ff(o);h&&(o=`${h[0]}(${h[1]})`,f=!0)}}if(l&&!o){let g=e.peek,h=typeof g=="string"&&(/^[a-zA-Z]$/.test(g)||g==="\\operatorname"||g==="\\max"||g==="\\min"||g===".");return(a||h)&&(e.index=u),s.length<10?ls(r*parseInt(s,10)):{num:r<0?"-"+s:s}}let p=cf(e,n);if(!l&&!p&&s.length<10)return ls(r*parseInt(s,10));if(!f&&e.options.parseNumbers==="rational"){let g=s.length>16||s.length===16&&s>"9007199254740991";if(!o){if(g){let U=r<0?"-"+s:s;return p?["Multiply",{num:U},["Power",10,p]]:{num:U}}let H=parseInt(s,10);return p?["Multiply",r*H,["Power",10,p]]:ls(r*H)}let h=o.length;if(s.length+h>15){let H=BigInt(s),U=BigInt(o),J=BigInt(10)**BigInt(h),Xe=H*J+U,Ke=r<0?-Xe:Xe;return p?["Multiply",["Rational",{num:Ke.toString()},Number(J)],["Power",10,p]]:["Rational",{num:Ke.toString()},Number(J)]}let I=parseInt(s,10),F=parseInt(o,10),B=I*10**h+F,q=10**h;return p?["Multiply",["Rational",r*B,q],["Power",10,p]]:["Rational",r*B,q]}return{num:(r<0?"-":"")+s+(l?"."+o:"")+(p?"e"+p:"")}}function ru(e,n){return e===null?!1:typeof e=="string"?e===n||e.split("_").includes(n):Array.isArray(e)?e.some(t=>ru(t,n)):!1}function fs(e,n){if(typeof e=="string"){let t=e.indexOf("_");return t>0&&e.substring(t+1)===n?[e.substring(0,t)+"_",n]:e}return Array.isArray(e)?d(e)==="Subscript"&&typeof c(e,1)=="string"&&ru(c(e,2),n)?[c(e,1)+"_",fs(c(e,2),n)]:[e[0],...e.slice(1).map(t=>fs(t,n))]:e}function mf(e){if(e==="NonNegativeIntegers")return 0;if(e==="PositiveIntegers")return 1}function df(e){let n,t=e;if(d(e)==="Power"&&(n=c(e,2)??void 0,t=c(e,1)),t===null||d(t)!=="Subscript")return e;let i=c(t,1);if(i===null||d(i)!=="Set"||(b(i)?.length??0)!==1)return e;let r=c(t,2);if(r===null)return e;let s,o;if(d(r)==="Equal"){let u=c(r,1);if(typeof u!="string")return e;s=u,o=c(r,2)??void 0}else if(d(r)==="Element"){let u=c(r,1);if(typeof u!="string")return e;let l=mf(c(r,2));if(l===void 0)return e;s=u,o=l}else return e;if(s===void 0||o===void 0)return e;let a=fs(c(i,1),s);return n===void 0?["IndexedSequence",a,s,o]:["IndexedSequence",a,s,o,n]}var gf=new Set([...'!"#$%&(),/;:?@[]\\`|~'.split(""),"\\left","\\bigl","\\mleft"]),hf=new Set(["\\!","\\,","\\:","\\;","\\enskip","\\enspace","\\space","\\quad","\\qquad"]),bf=["pt","em","mu","ex","mm","cm","in","bp","sp","dd","cc","pc","nc","nd"].map(e=>[...e]),ai={sin:"Sin",cos:"Cos",tan:"Tan",cot:"Cot",sec:"Sec",csc:"Csc",sinh:"Sinh",cosh:"Cosh",tanh:"Tanh",coth:"Coth",sech:"Sech",csch:"Csch",arcsin:"Arcsin",arccos:"Arccos",arctan:"Arctan",arccot:"Arccot",arcsec:"Arcsec",arccsc:"Arccsc",asin:"Arcsin",acos:"Arccos",atan:"Arctan",acot:"Arccot",asec:"Arcsec",acsc:"Arccsc",atan2:"Arctan2",arcsinh:"Arsinh",arccosh:"Arcosh",arctanh:"Artanh",arccoth:"Arcoth",arcsech:"Arsech",arccsch:"Arcsch",asinh:"Arsinh",acosh:"Arcosh",atanh:"Artanh",log:"Log",ln:"Ln",exp:"Exp",lg:"Lg",lb:"Lb",sqrt:"Sqrt",abs:"Abs",sgn:"Sgn",sign:"Sgn",floor:"Floor",ceil:"Ceil",round:"Round",max:"Max",min:"Min",gcd:"Gcd",lcm:"Lcm",cbrt:"Root",binom:"Binomial",nCr:"Binomial",nPr:"Permutations"},eu={"<space>":" ","<$$>":"$$","<$>":"$","<{>":"{","<}>":"}"},ui=null;function yf(){if(!ui){ui=new Map;for(let[,e,n]of He)ui.set(e,String.fromCodePoint(n))}return ui}var nu={"(":["\\lparen","("],")":["\\rparen",")"],"[":["\\lbrack","\\[","["],"]":["\\rbrack","\\]","]"],"<":["<","\\langle"],">":[">","\\rangle"],"{":["\\{","\\lbrace"],"}":["\\}","\\rbrace"],":":[":","\\colon"],"|":["|","\\|","\\lvert","\\rvert"],"||":["||","\\Vert","\\lVert","\\rVert","\\|"]},En={"\\left":"\\right","\\bigl":"\\bigr","\\Bigl":"\\Bigr","\\biggl":"\\biggr","\\Biggl":"\\Biggr","\\big":"\\big","\\Big":"\\Big","\\bigg":"\\bigg","\\Bigg":"\\Bigg","\\mathopen":"\\mathclose","\\mleft":"\\mright"},tu=new Set(Object.values(En)),ps={"(":")","[":"]","|":"|","\\{":"\\}","\\[":"\\]","\\lbrace":"\\rbrace","\\lparen":"\\rparen","\\langle":"\\rangle","\\lfloor":"\\rfloor","\\lceil":"\\rceil","\\vert":"\\vert","\\lvert":"\\rvert","\\Vert":"\\Vert","\\lVert":"\\rVert","\\|":"\\|","\\lbrack":"\\rbrack","\\ulcorner":"\\urcorner","\\llcorner":"\\lrcorner","\\lgroup":"\\rgroup","\\lmoustache":"\\rmoustache","\\llbracket":"\\rrbracket"};function xf(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e instanceof G)return"BoxedType";if(typeof e=="string")return`"${e}"`;if(typeof e=="object"){let n=e.constructor?.name;return n&&n!=="Object"?n:"object"}return`${typeof e} (${String(e)})`}var iu=class e{options;_index=0;symbolTable={parent:null,ids:{}};pushSymbolTable(){this._symbolTableGen+=1,this.symbolTable={parent:this.symbolTable,ids:{}}}popSymbolTable(){this._symbolTableGen+=1,this.symbolTable=this.symbolTable.parent??this.symbolTable}addSymbol(n,t){if(this._symbolTableGen+=1,typeof t=="string"&&(t=new G(t)),n in this.symbolTable.ids&&!this.symbolTable.ids[n].is(t.type))throw new Error(`Symbol ${n} already declared as a different type`);this.symbolTable.ids[n]=t}_reversedIntervalDepth=0;_quantifierScopeDepth=0;get inQuantifierScope(){return this._quantifierScopeDepth>0}enterQuantifierScope(){this._quantifierScopeDepth++}exitQuantifierScope(){this._quantifierScopeDepth>0&&this._quantifierScopeDepth--}get index(){return this._index}set index(n){if(this.diagnostics!==null&&this.diagnostics.length>0&&n<this._index){let i=this.tokenPrefixOffsets()[Math.max(0,Math.min(n,this._tokens.length))],r=this.diagnostics,s=0;for(let o=0;o<r.length;o++)r[o].start>=i||(r[s++]=r[o]);r.length=s}this._index=n,this._lastPeek="",this._peekCounter=0}_tokens;_positiveInfinityTokens;_negativeInfinityTokens;_notANumberTokens;_decimalSeparatorTokens;_wholeDigitGroupSeparatorTokens;_fractionalDigitGroupSeparatorTokens;_exponentProductTokens;_beginExponentMarkerTokens;_endExponentMarkerTokens;_truncationMarkerTokens;_imaginaryUnitTokens;_dictionary;_boundaries=[];_lastPeek="";_peekCounter=0;_lookAheadCache=null;_lookAheadIndex=-1;_tokenPrefixOffsets=null;_symbolTableGen=0;_symCandidateIndex=-1;_symCandidateGen=-1;_symCandidate=null;_symCandidateCount=0;diagnostics;_diagnosticSeq=0;emitDiagnostic(n,t,i,r){if(this.diagnostics===null)return;let[s,o]=this.sourceOffsets(t,i),a=this._diagnosticSeq++;this.diagnostics.push(r!==void 0?{code:n,start:s,end:o,detail:r,_seq:a}:{code:n,start:s,end:o,_seq:a})}diagnosticsCheckpoint(){return this._diagnosticSeq}rollbackDiagnostics(n){if(this.diagnostics===null)return;let t=this.diagnostics,i=0;for(let r=0;r<t.length;r++)t[r]._seq<n&&(t[i++]=t[r]);t.length=i}pruneUndeclared(n,t,i,r){if(this.diagnostics===null)return;let s=n instanceof Set?n:new Set(n);if(s.size===0)return;if(this.options.onBoundVariable)for(let h of s)this.options.onBoundVariable(h);let o=this.tokenPrefixOffsets(),a=this._tokens.length,u=h=>o[Math.max(0,Math.min(h,a))],l=i===void 0?-1/0:u(i),f=(r??[]).map(([h,N])=>[u(h),u(N)]),p=this.diagnostics,g=0;for(let h=0;h<p.length;h++){let N=p[h],I=N.detail?.name;if(N.code==="undeclared-symbol"&&N._seq>=t&&typeof I=="string"&&s.has(I)){let B=N.start>=l,q=f.some(([H,U])=>N.start>=H&&N.start<U);if(B||q)continue}p[g++]=N}p.length=g}pruneJuxtaposition(n,t){if(this.diagnostics===null)return;let i=this.diagnostics,r=0;for(let s=0;s<i.length;s++){let o=i[s];o.code==="juxtaposition-as-multiply"&&o._seq>=t&&o.detail?.name===n||(i[r++]=o)}i.length=r}get operandDiagnosticCheckpoint(){return this._operandDiagnosticCheckpoint}_operandDiagnosticCheckpoint=0;isSymbolDeclared(n){let t=this.symbolTable;for(;t;){if(n in t.ids)return!0;t=t.parent}return this.options.isSymbolDeclared?.(n)?!0:!this.getSymbolType(n).isUnknown}emitSymbolReference(n,t,i){this.diagnostics!==null&&(this.isSymbolDeclared(n)||this.emitDiagnostic("undeclared-symbol",t,i,{name:n,type:this.getSymbolType(n).toString()}))}constructor(n,t,i){this._tokens=n,this.options=i,this._dictionary=t,this.diagnostics=i.diagnostics?[]:null,this._positiveInfinityTokens=ne(this.options.positiveInfinity),this._negativeInfinityTokens=ne(this.options.negativeInfinity),this._notANumberTokens=ne(this.options.notANumber),this._decimalSeparatorTokens=ne(this.options.decimalSeparator),this._wholeDigitGroupSeparatorTokens=[],this._fractionalDigitGroupSeparatorTokens=[],this.options.digitGroupSeparator&&(typeof this.options.digitGroupSeparator=="string"?(this._wholeDigitGroupSeparatorTokens=ne(this.options.digitGroupSeparator),this._fractionalDigitGroupSeparatorTokens=this._wholeDigitGroupSeparatorTokens):Array.isArray(this.options.digitGroupSeparator)&&(this._wholeDigitGroupSeparatorTokens=ne(this.options.digitGroupSeparator[0]),this._fractionalDigitGroupSeparatorTokens=ne(this.options.digitGroupSeparator[1]))),this._exponentProductTokens=ne(this.options.exponentProduct),this._beginExponentMarkerTokens=ne(this.options.beginExponentMarker),this._endExponentMarkerTokens=ne(this.options.endExponentMarker),this._truncationMarkerTokens=ne(this.options.truncationMarker),this._imaginaryUnitTokens=ne(this.options.imaginaryUnit),this._numberFormatTokens={decimalSeparatorTokens:this._decimalSeparatorTokens,wholeDigitGroupSeparatorTokens:this._wholeDigitGroupSeparatorTokens,fractionalDigitGroupSeparatorTokens:this._fractionalDigitGroupSeparatorTokens,exponentProductTokens:this._exponentProductTokens,beginExponentMarkerTokens:this._beginExponentMarkerTokens,endExponentMarkerTokens:this._endExponentMarkerTokens,truncationMarkerTokens:this._truncationMarkerTokens}}_numberFormatTokens;getSymbolType(n){let t=this.symbolTable;for(;t;){if(n in t.ids)return t.ids[n];t=t.parent}if(this.options.getSymbolType){let i=this.options.getSymbolType(n);if(i instanceof G)return i;if(typeof i=="string")try{return new G(i)}catch(r){let s=r instanceof Error?r.message:String(r);throw new Error(`ce.parse(): getSymbolType("${n}") returned invalid type string "${i}". ${s}`)}throw new Error(`ce.parse(): getSymbolType("${n}") must return a BoxedType or a type string, received ${xf(i)}`)}return G.unknown}hasSubscriptEvaluate(n){return this.options.hasSubscriptEvaluate?this.options.hasSubscriptEvaluate(n):!1}get peek(){let n=this._tokens[this.index];if(n===this._lastPeek?this._peekCounter+=1:this._peekCounter=0,this._peekCounter>=1024){let t=`Infinite loop detected while parsing "${this.latex(0)}" at "${this._lastPeek}" (index ${this.index})`;throw console.error(t),new Error(t)}return this._lastPeek=n,n}nextToken(){return this._tokens[this.index++]}get atEnd(){return this.index>=this._tokens.length}atTerminator(n){return this.atBoundary||((n?.condition&&n.condition(this))??!1)}get atBoundary(){if(this.atEnd)return!0;let n=this.index;for(let t of this._boundaries)if(this.matchBoundaryTokens(t.tokens))return this.index=n,!0;return!1}matchBoundaryTokens(n){return this.matchAll(n)?!0:n.length===2&&tu.has(n[0])&&this._tokens[this.index]===n[0]&&this._tokens[this.index+1]==="."?(this.index+=2,!0):!1}addBoundary(n){this._boundaries.push({index:this.index,tokens:n})}removeBoundary(){this._boundaries.pop()}matchBoundary(){let n=this._boundaries[this._boundaries.length-1],t=n&&this.matchBoundaryTokens(n.tokens);return t&&this._boundaries.pop(),t}boundaryError(n){let t=this._boundaries[this._boundaries.length-1];return this._boundaries.pop(),this.error(n,t.index)}canSkipMatchfixReparsing(n,t,i){return i||t.length!==1?!1:(n==="("||n==="\\lparen")&&(t[0]==="]"||t[0]==="\\rbrack")||(n==="]"||n==="\\rbrack")&&(t[0]==="["||t[0]==="\\lbrack")}latex(n,t){return ln(this._tokens.slice(n,t))}sourceOffsets(n,t=this.index){let i=this.tokenPrefixOffsets(),r=this._tokens.length,s=i[Math.max(0,Math.min(n,r))],o=i[Math.max(0,Math.min(t,r))];return s<=o?[s,o]:[o,s]}tokenPrefixOffsets(){if(this._tokenPrefixOffsets!==null)return this._tokenPrefixOffsets;let n=this._tokens,t=new Array(n.length+1);t[0]=0;let i=0,r="";for(let s=0;s<n.length;s++){let o=eu[n[s]]??n[s];/[a-zA-Z]/.test(o[0])&&(i+=r.length),r=/\\[a-zA-Z]+\*?$/.test(o)?" ":"",i+=o.length,t[s+1]=i}return this._tokenPrefixOffsets=t,t}lookAhead(){if(this._lookAheadIndex===this.index&&this._lookAheadCache!==null)return this._lookAheadCache;let n=this._dictionary.triggerStartMax.get(this._tokens[this.index])??0,t=Math.min(n,this._tokens.length-this.index),i=[],r="",s="";for(let o=0;o<t;o++){let a=this._tokens[this.index+o],u=eu[a]??a;/[a-zA-Z]/.test(u[0])&&(r+=s),s=/\\[a-zA-Z]+\*?$/.test(u)?" ":"",r+=u,i[t-1-o]=[o+1,r]}return this._lookAheadCache=i,this._lookAheadIndex=this.index,i}peekDefinitions(n){if(this.atEnd)return[];let t=[],i=this._dictionary,r;switch(n){case"infix":r=i.infixByTrigger;break;case"prefix":r=i.prefixByTrigger;break;case"postfix":r=i.postfixByTrigger;break;case"function":r=i.functionByTrigger;break;case"symbol":r=i.symbolByTrigger;break;case"expression":r=i.expressionByTrigger;break;case"operator":r=i.operatorByTrigger;break}let s=i.universalDefs.get(n);if(s)for(let a of s)t.push([a,0]);for(let[a,u]of this.lookAhead()){let l=r.get(u);if(l)for(let f of l)t.push([f,a])}let o=i.symbolTriggerDefs.get(n);if(o){let a,u;if(this._symCandidateIndex===this.index&&this._symCandidateGen===this._symbolTableGen)a=this._symCandidate,u=this._symCandidateCount;else{let l=this.index;a=Yn(this)?.trim()??null,u=this.index-l,this.index=l,this._symCandidateIndex=l,this._symCandidateGen=this._symbolTableGen,this._symCandidate=a,this._symCandidateCount=u}if(a&&u>0){let l=o.get(a);if(l)for(let f of l)t.push([f,u])}}return t}skipSpaceTokens(){for(;this.match("<space>"););}skipSpace(){if(!this.atEnd&&this.peek==="<{>"){let t=this.index;for(this.nextToken();this.match("<space>"););if(this.nextToken()==="<}>")return this.skipSpace(),!0;this.index=t}if(!this.options.skipSpace)return!1;let n=!1;for(;this.match("<space>");)n=!0;return n&&this.skipSpace(),n}skipVisualSpace(){if(this.options.skipSpace){if(this.skipSpace(),hf.has(this.peek)&&(this.nextToken(),this.skipVisualSpace()),this.match("\\hspace")&&(this.match("*"),this.parseStringGroup(),this.skipVisualSpace()),this.match("\\hskip")||this.match("\\kern")){for(this.skipSpace(),this.match("-")||this.match("+");/^[\d.]$/.test(this.peek);)this.nextToken();for(let n of bf)if(this.matchAll(n))break;this.skipVisualSpace()}this.skipSpace()}}match(n){return this._tokens[this.index]!==n?!1:(this.index++,!0)}matchAll(n){if(n.length===0)return!1;let t,i=0;do t=this._tokens[this.index+i]===n[i++];while(t&&i<n.length);return t&&(this.index+=i),t}matchAny(n){return n.includes(this._tokens[this.index])?this._tokens[this.index++]:""}parseLatexNumber(n=!0){let t=!1,i=this.peek;for(;i==="<space>"||i==="+"||i==="-";)i==="-"&&(t=!t),this.nextToken(),i=this.peek;let r=10,s=["0","1","2","3","4","5","6","7","8","9"];if(this.match("'"))r=8,s=["0","1","2","3","4","5","6","7"],n=!0;else if(this.match('"')||this.match("x"))r=16,s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],n=!0;else if(this.match("`"))return i=this.nextToken(),i?i.startsWith("\\")&&i.length===2?(t?-1:1)*(i.codePointAt(1)??0):(t?-1:1)*(i.codePointAt(0)??0):null;let o="";for(;s.includes(this.peek);)o+=this.nextToken();if(!n&&this.match("."))for(o+=".";s.includes(this.peek);)o+=this.nextToken();let a=n?Number.parseInt(o,r):Number.parseFloat(o);return Number.isNaN(a)?null:t?-a:a}parseChar(){let n=this.index,t=0;for(;this.match("^");)t+=1;if(t<2&&(this.index=n),t>=2){let i="",r=0;for(;r!=t;){let s=this.matchAny(["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]);if(!s)break;i+=s,r+=1}if(i.length===t)return String.fromCodePoint(Number.parseInt(i,16))}else if(this.match("\\char")){let i=Math.floor(this.parseLatexNumber()??Number.NaN);return(!Number.isFinite(i)||i<0||i>1114111)&&(i=10067),String.fromCodePoint(i)}else if(this.match("\\unicode"))if(this.skipSpaceTokens(),this.match("<{>")){let i=this.parseLatexNumber();if(this.match("<}>")&&i!==null&&i>=0&&i<=1114111)return String.fromCodePoint(i)}else{let i=this.parseLatexNumber();if(i!==null&&i>=0&&i<=1114111)return String.fromCodePoint(i)}return this.index=n,null}matchDelimiter(n,t){let i=this.index,r=En[this.peek];r&&this.nextToken();let s=r&&this.peek==="<{>";if(s&&this.nextToken(),Array.isArray(n)){if(Array.isArray(t),n.length===1){if(!(nu[n[0]]??[n[0]]).includes(this.peek))return this.index=i,!1;if(this.nextToken(),s&&!this.match("<}>"))return this.index=i,!1;let f=t[0],p=r?s?[r,"<{>",f,"<}>"]:[r,f]:[f];return this.addBoundary(p),!0}if(!this.matchAll(n))return this.index=i,!1;let u=r?[r,...t]:t;return this.addBoundary(u),!0}if(Array.isArray(t),n==="||"&&this.matchAll(["|","|"]))return this.addBoundary(["|","|"]),!0;if(!(nu[n]??[n]).includes(this.peek))return this.index=i,!1;if(n=this.nextToken(),s&&!this.match("<}>"))return this.index=i,!1;let o=ps[n]??t,a=r?s?[r,"<{>",o,"<}>"]:[r,o]:[o];return this.addBoundary(a),!0}parseGroup(){let n=this.index;if(this.skipSpaceTokens(),this.match("<{>")){this.addBoundary(["<}>"]);let t=this.parseExpression();if(this.skipSpace(),this.matchBoundary())return t??"Nothing";for(;!this.matchBoundary()&&!this.atEnd;)this.nextToken();if(d(t)==="Error")return t;let i=this.error("expected-closing-delimiter",n);return t!==null?["InvisibleOperator",t,i]:i}return this.index=n,null}parseOptionalGroup(){let n=this.index;if(this.skipSpaceTokens(),this.match("[")){this.addBoundary(["]"]);let t=this.parseExpression();return this.skipSpace(),this.matchBoundary()?t:this.boundaryError("expected-closing-delimiter")}return this.index=n,null}parseToken(){return this.skipSpace(),gf.has(this.peek)?null:/^[0-9]$/.test(this.peek)?parseInt(this.nextToken(),10):this.parseGenericExpression()??this.parseSymbol()}parseTabular(){let n=[],t=[],i=null;for(;!this.atBoundary;)if(this.skipSpace(),this.match("&"))t.push(i??"Nothing"),i=null;else if(this.match("\\\\")||this.match("\\cr"))this.skipSpace(),this.parseOptionalGroup(),i!==null&&t.push(i),n.push(t),t=[],i=null;else{let r=[],s=this.peek;for(;s!=="&"&&s!=="\\\\"&&s!=="\\cr"&&!this.atBoundary;)i=this.parseExpression({minPrec:0,condition:o=>{let a=o.peek;return a==="&"||a==="\\\\"||a==="\\cr"}}),i!==null?r.push(i):(r.push(["Error","'unexpected-token'",{str:ln(s)}]),this.nextToken()),this.skipSpace(),s=this.peek;r.length>1?i=["Sequence",...r]:i=r[0]??"Nothing"}return i!==null&&t.push(i),t.length>0&&n.push(t),n}parseStringGroupContent(){let n=this.index,t="",i=0;for(;!this.atEnd&&(!this.atBoundary||i>0);){let r=this.nextToken();if(r==="<$>"||r==="<$$>")return this.index=n,"";if(r==="<{>")i+=1,t+="\\{";else if(r==="<}>")i-=1,t+="\\}";else if(r==="<space>")t+=" ";else if(r[0]==="\\"){let s=yf().get(r);t+=s??r}else t+=r}return t}parseStringGroup(n,t){n===void 0&&(n=!1);let i=this.index;for(;this.match("<space>"););if(this.match(n?"[":"<{>")){let r=this.index;this.addBoundary([n?"]":"<}>"]);let s=this.parseStringGroupContent();if(this.matchBoundary())return t&&t.push(...this._tokens.slice(r,this.index-1)),s;this.removeBoundary()}return this.index=i,null}parseDoubleQuoteString(){if(this.peek!=='"')return null;let n=this.index;this.nextToken(),this.addBoundary(['"']);let t=this.parseStringGroupContent();return this.matchBoundary()?{str:t}:(this.removeBoundary(),this.error("expected-closing-delimiter",n))}parseEnvironment(n){let t=this.index;if(!this.match("\\begin"))return null;let i=[],r=this.parseStringGroup(!1,i)?.trim();if(!r)return this.error("expected-environment-name",t);for(;i[0]==="<space>";)i.shift();for(;i[i.length-1]==="<space>";)i.pop();this.addBoundary(["\\end","<{>",...i,"<}>"]);for(let s of this.getDefs("environment"))if(s.symbolTrigger===r){let o=s.parse(this,n);return this.skipSpace(),this.matchBoundary()?o!==null?this.decorate(o,t):(this.index=t,null):this.boundaryError("unbalanced-environment")}return this.parseTabular(),this.skipSpace(),this.matchBoundary()?this.error(["unknown-environment",{str:r}],t):this.boundaryError("unbalanced-environment")}parseRepeatingDecimal(){return cs(this,this._numberFormatTokens)}parseNumber(){return Qa(this,this._numberFormatTokens)}parsePrefixOperator(n){n||(n={minPrec:0}),n.minPrec||(n={...n,minPrec:0});let t=this.index;for(let[i,r]of this.peekDefinitions("prefix")){this.index=t+r;let s=i.parse(this,{...n,minPrec:i.precedence+1});if(s!==null)return s}return this.index=t,null}parseInfixOperator(n,t){t??={minPrec:0},t.minPrec,t.minPrec===void 0&&(t={...t,minPrec:0});let i=this.index;for(let[r,s]of this.peekDefinitions("infix"))if(r.precedence>=t.minPrec){this.index=i+s;let o=r.parse(this,n,t);if(o!==null)return o}if(this.index=i,this.peek==="\\textcolor"){let r=this.parseStyledInfixOperator(n,t);if(r!==null)return r;this.index=i}return null}parseStyledInfixOperator(n,t){let i=this.index;if(!this.match("\\textcolor"))return null;if(this.parseStringGroup()===null)return this.index=i,null;if(this.skipSpace(),!this.match("<{>"))return this.index=i,null;this.skipSpace();let r=this.index;for(let[s,o]of this.peekDefinitions("infix")){if(s.precedence<t.minPrec)continue;if(this.index=r+o,this.skipSpace(),!this.match("<}>")){this.index=r;continue}let a=s.parse(this,n,t);if(a!==null)return a;this.index=r}return this.index=i,null}wouldMatchTextInfix(n){let t=this.index;for(let[i,r]of n){if(i.kind!=="infix")continue;if(this.index=t+r,i.parse(this,"Nothing",{minPrec:0})!==null)return this.index=t,!0}return this.index=t,!1}parseArguments(n="enclosure",t){if(this.atTerminator(t))return null;let i=this.index,r=this.parseEnclosure();if(n==="enclosure")return r===null?null:Ne(r)??[r];if(n==="implicit"){if(d(r)==="Delimiter"){let o=c(r,1);return d(o)==="Sequence"?b(o):o===null?[]:[o]}if(r!==null)return[r];let s=this.parseExpression({...t,minPrec:C});return s===null?null:[s]}return this.index=i,null}parseBraceArguments(){let n=this.index,t=[];for(;this.peek==="<{>";){let i=this.index,r=this.parseGroup();if(r===null||r==="Nothing"){this.index=i;break}t.push(...Ne(r)??[r])}return t.length===0?(this.index=n,null):t}parseEnclosure(){let n=this.index,t=this.peek,i=En[t],r=i?this._tokens[this.index+1]:t;i&&r==="<{>"&&(r=this._tokens[this.index+2]);let s=this._dictionary.matchfixByOpen.get(r)??[];s.length===0&&!r&&(s=[...this.getDefs("matchfix")]);for(let o of s){this.index=n;let a=Array.isArray(o.openTrigger)&&o.openTrigger.length===1&&(o.openTrigger[0]==="]"||o.openTrigger[0]==="\\rbrack")&&Array.isArray(o.closeTrigger)&&o.closeTrigger.length===1&&(o.closeTrigger[0]==="["||o.closeTrigger[0]==="\\lbrack");if(a&&this._reversedIntervalDepth>0)continue;if(o.closeTokens.size>0){let I=!1,F=this._tokens;for(let B=n;B<F.length;B++){if(o.closeTokens.has(F[B])){I=!0;break}if(i&&tu.has(F[B])&&F[B+1]==="."){I=!0;break}}if(!I)continue}if(typeof o.openTrigger=="string"&&o.openTrigger==="."&&!En[t]||!this.matchDelimiter(o.openTrigger,o.closeTrigger))continue;let l=this.index;this.skipSpace(),a&&(this._reversedIntervalDepth+=1);let f=this.parseExpression();a&&(this._reversedIntervalDepth-=1),this.skipSpace();let p=this._boundaries[this._boundaries.length-1]?.tokens,g=this.matchBoundary(),h=typeof o.openTrigger=="string"&&typeof o.closeTrigger=="string"&&o.openTrigger===o.closeTrigger||Array.isArray(o.openTrigger)&&Array.isArray(o.closeTrigger)&&o.openTrigger.length===o.closeTrigger.length&&o.openTrigger.every((I,F)=>I===o.closeTrigger[F]);if(g&&R(f)&&h&&p){if(this.index=l,this.skipSpace(),a&&(this._reversedIntervalDepth+=1),f=this.parseExpression(),a&&(this._reversedIntervalDepth-=1),this.skipSpace(),!this.matchAll(p)){if(this.index=n,!this.atEnd)continue;return null}}else if(!g){let I=this._boundaries[this._boundaries.length-1]?.tokens;if(!I){this.index=n;continue}if(this.canSkipMatchfixReparsing(r,I,h)){this.removeBoundary(),this.index=n;continue}else if(this.removeBoundary(),this.index=l,this.skipSpace(),a&&(this._reversedIntervalDepth+=1),f=this.parseExpression(),a&&(this._reversedIntervalDepth-=1),this.skipSpace(),!this.matchAll(I)){if(this.index=n,!this.atEnd)continue;return null}}let N=o.parse(this,f??"Nothing");if(N!==null)return N}return this.index=n,null}parseGenericExpression(n){if(this.atTerminator(n))return null;let t=this.index,i=null,r=this.peekDefinitions("expression")??[];for(let[s,o]of r)if(this.index=t+o,typeof s.parse=="function"){if(i=s.parse(this,n),i!==null)return i}else return s.name;return this.index=t,null}parseFunction(n){if(this.atTerminator(n))return null;let t=this.index,i=null,r="enclosure";for(let[a,u]of this.peekDefinitions("function"))if(this.index=t+u,typeof a.parse=="function"){if(i=a.parse(this,n),i!==null)return i}else{i=a.name,r=a.arguments??"enclosure";break}let s=!1;if(i===null&&(this.index=t,i=Yn(this),typeof i=="string"&&this.emitSymbolReference(i,t,this.index),!this.isFunctionOperator(i))){if(!this.looksLikePredicate(i))return this.index=t,null;s=!0}do{let a=this.parsePostfixOperator(i,n);if(a===null)break;i=a}while(!0);let o=this.parseArguments(r,n);return o===null?i:s&&typeof i=="string"&&this.inQuantifierScope?["Predicate",i,...o]:typeof i=="string"?[i,...o]:["Apply",i,...o]}parseSymbol(n){if(this.atTerminator(n))return null;let t=this.index;for(let[r,s]of this.peekDefinitions("symbol"))if(this.index=t+s,typeof r.parse=="function"){let o=r.parse(this,n);if(o!==null)return o}else return r.name;this.index=t;let i=Yn(this);return i!==null&&!this.getSymbolType(i).matches("error")?(this.emitSymbolReference(i,t,this.index),i):(this.index=t,null)}peekBareWord(){let n=this.index;for(;this._tokens[n]==="<space>";)n++;let t="";for(;n<this._tokens.length&&/^[a-zA-Z]$/.test(this._tokens[n]);)t+=this._tokens[n],n++;return t}tryParseBareFunction(n){if(this.options.strict!==!1)return null;let t=this.index;if(t>0&&/^[a-zA-Z]$/.test(this._tokens[t-1]))return null;let i="";for(;!this.atEnd&&/^[a-zA-Z]$/.test(this.peek);)i+=this.peek,this.index++;if(!i)return this.index=t,null;if(!this.atEnd&&/^[0-9]$/.test(this.peek)){let l="",f=this.index;for(;f<this._tokens.length&&/^[0-9]$/.test(this._tokens[f]);)l+=this._tokens[f],f++;for(let p=l.length;p>=1;p--)if(ai[i+l.slice(0,p)]!==void 0){i+=l.slice(0,p),this.index+=p;break}}this.skipSpace();let r=null;if(this.peek==="_"){if(this.index++,r=this.parseGroup(),r===null){if(!this.atEnd&&/^[a-zA-Z]$/.test(this.peek))r=this.peek,this.index++;else{let l="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)l+=this.peek,this.index++;l&&(r=parseInt(l))}if(r===null)return this.index=t,null}this.skipSpace()}if(r===null&&i==="log"&&!this.atEnd&&/^[0-9]$/.test(this.peek)){let l="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)l+=this.peek,this.index++;r=parseInt(l),this.skipSpace()}let s=null;if(this.peek==="^"){if(this.index++,s=this.parseGroup(),s===null){let l=!1;this.peek==="-"&&(l=!0,this.index++);let f="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)f+=this.peek,this.index++;if(f){let p=parseInt(f);s=l?-p:p}else return this.index=t,null}this.skipSpace()}let o=ai[i];if(!o)return this.index=t,null;let a;if(this.peek==="("?a=this.parseArguments("enclosure",n):a=this.parseArguments("implicit",{...n,minPrec:C,condition:l=>{let f=this.peekBareWord();return f.length>0&&ai[f]!==void 0||(n?.condition?.(l)??!1)}}),a===null)return this.index=t,null;if(i==="cbrt"){let l=["Root",a[0]??"Nothing",3];return s!==null?["Power",l,s]:l}if(i==="nPr"){let l=["Multiply",["Binomial",a[0]??"Nothing",a[1]??"Nothing"],["Factorial",a[1]??"Nothing"]];return s!==null?["Power",l,s]:l}let u;if(i==="log"&&r!==null?r===2?u=["Lb",...a]:r===10?u=["Log",...a]:u=["Log",a[0],r]:u=[o,...a],s===-1&&Array.isArray(u)){let[l,...f]=u;return["Apply",["InverseFunction",l],...f]}return s!==null?["Power",u,s]:u}static BARE_SYMBOL_MAP={alpha:"alpha",beta:"beta",gamma:"gamma",delta:"delta",epsilon:"epsilon",varepsilon:"varepsilon",zeta:"zeta",eta:"eta",theta:"theta",vartheta:"vartheta",iota:"iota",kappa:"kappa",lambda:"lambda",mu:"mu",nu:"nu",xi:"xi",omicron:"omicron",pi:"Pi",rho:"rho",sigma:"sigma",tau:"tau",upsilon:"upsilon",phi:"phi",varphi:"varphi",chi:"chi",psi:"psi",omega:"omega",Gamma:"Gamma",Delta:"Delta",Theta:"Theta",Lambda:"Lambda",Xi:"Xi",Sigma:"Sigma",Upsilon:"Upsilon",Phi:"Phi",Psi:"Psi",Omega:"Omega",oo:"PositiveInfinity",inf:"PositiveInfinity",ii:"ImaginaryUnit"};tryParseBareSymbol(){if(this.options.strict!==!1)return null;let n=this.index;if(n>0&&/^[a-zA-Z]$/.test(this._tokens[n-1]))return null;let t="";for(;!this.atEnd&&/^[a-zA-Z]$/.test(this.peek);)t+=this.peek,this.index++;if(!t)return this.index=n,null;let i=e.BARE_SYMBOL_MAP[t];return i?(this.emitSymbolReference(i,n,this.index),i):(this.index=n,null)}static SEGMENTABLE_SYMBOLS=Object.fromEntries(Object.entries(e.BARE_SYMBOL_MAP).filter(([n])=>!["oo","inf","ii"].includes(n)));static MAX_SEGMENTABLE_LENGTH=Math.max(...Object.keys(e.SEGMENTABLE_SYMBOLS).map(n=>n.length));static SEGMENTABLE_SYMBOL_VALUES=new Set(Object.values(e.SEGMENTABLE_SYMBOLS));tryParseBareRun(){if(this.options.strict!==!1)return null;let n=this.index;if(n>0&&/^[a-zA-Z]$/.test(this._tokens[n-1]))return null;let t="";for(;!this.atEnd&&/^[a-zA-Z]$/.test(this.peek);)t+=this.peek,this.index++;if(t.length<2)return this.index=n,null;if(ai[t]!==void 0)return this.emitSymbolReference(t,n,this.index),t;let i=e.SEGMENTABLE_SYMBOLS,r=[],s=!1,o=0;for(;o<t.length;){let a=!1,u=Math.min(t.length-o,e.MAX_SEGMENTABLE_LENGTH);for(let l=u;l>=2;l--){let f=t.slice(o,o+l);if(i[f]!==void 0){r.push(i[f]),o+=l,a=!0,s=!0;break}}a||(this.emitSymbolReference(t[o],n+o,n+o+1),r.push(t[o]),o+=1)}return s?r.length===1?r[0]:["Multiply",...r]:(this.index=n,null)}parseSupsub(n){if(this.atEnd)return n;let t=this.index;if(this.options.strict===!1&&typeof n=="string"&&(n.length===1&&/^[a-zA-Z]$/.test(n)||e.SEGMENTABLE_SYMBOL_VALUES.has(n))&&/^[0-9]$/.test(this.peek)){let u="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)u+=this.peek,this.index++;return this.parseSupsub(["Subscript",n,parseInt(u)])}this.skipSpace();let i=[],r=[],s=t;for(;this.peek==="_"||this.peek==="^";){if(this.match("_"))if(s=this.index,this.match("_")||this.match("^"))r.push(this.error("syntax-error",s));else{let u=this.parseGroup();if(u===null&&this.options.strict===!1){let l="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)l+=this.peek,this.index++;l&&(u=parseInt(l))}if(u??=this.parseToken(),u===null&&this.options.strict===!1&&this.peek==="("&&(u=this.parseEnclosure()),u??=this.parseStringGroup(),u===null)return this.error("missing",t);r.push(u)}else if(this.match("^"))if(s=this.index,this.match("_")||this.match("^"))i.push(this.error("syntax-error",s));else{let u=this.parseGroup();if(u===null&&this.options.strict===!1){let l=this.index,f=!1;this.peek==="-"&&(f=!0,this.index++);let p="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)p+=this.peek,this.index++;if(p){let g=parseInt(p);u=f?-g:g}else this.index=l}if(u??=this.parseToken(),u===null&&this.options.strict===!1&&this.peek==="("&&(u=this.parseEnclosure()),u===null)return this.error("missing",t);i.push(u)}s=this.index,this.skipSpace()}if(i.length===0&&r.length===0)return this.index=t,n;let o=n,a=r.filter(u=>!R(u));if(a.length>0){let u=this._dictionary.infixByTrigger.get("_")??[];if(u){let l=["Subscript",o,a.length===1?a[0]:["List",...a]];for(let f of u)if(typeof f.parse=="function"?o=f.parse(this,l,{minPrec:0}):o=l,o!==null)break}}if(i.length>0){let u=this._dictionary.infixByTrigger.get("^")??[];if(u){let l=i.filter(f=>{if(R(f))return!1;let p=w(f);return!(p!==null&&/^(?:st|nd|rd|th)$/i.test(p))});if(l.length>1)return this.error("unexpected-superscript",t);if(l.length!==0){let f=l[0],p=["Superscript",o,f];for(let g of u)if(typeof g.parse=="function"?o=g.parse(this,p,{minPrec:0}):o=p,o!==null)break}}}return o===null&&(this.index=t),o}parsePostfixOperator(n,t){if(n===null||this.atEnd)return null;let i=this.index;if(this.skipVisualSpace(),this.index!==i){let s=this._tokens[this.index];s==="\\{"||s==="\\left"&&this._tokens[this.index+1]==="\\{"||(this.index=i)}let r=this.index;for(let[s,o]of this.peekDefinitions("postfix")){this.index=r+o;let a=s.parse(this,n,t);if(a!==null)return a}return this.index=i,null}parseSyntaxError(){let n=this.index;if(this.peek==="^")return this.index+=1,["Superscript",this.error("missing",n),P(this.parseGroup())];let t=this.peekDefinitions("operator");if(t.length>0){if(t=this.peekDefinitions("postfix"),t.length>0){let[a,u]=t[0];if(this.index+=u,typeof a.parse=="function"){let l=a.parse(this,this.error("missing",n));if(l!==null)return l}return this.error("unexpected-operator",n)}if(t=this.peekDefinitions("prefix"),t.length>0){let[a,u]=t[0];if(this.index+=u,typeof a.parse=="function"){let l=a.parse(this,{minPrec:0});if(l!==null)return l}return a.name?[a.name,this.parseExpression()??this.error("missing",n)]:this.error("unexpected-operator",n)}if(t=this.peekDefinitions("infix"),t.length>0){let[a,u]=t[0];this.index+=u;let l=a.parse(this,this.error("missing",n),{minPrec:0});return l!==null?l:this.error("unexpected-operator",n)}}let i=this.index,r=as(this);if(r!==null)return r;if(r=Yn(this),r!==null)return this.error(["unexpected-symbol",{str:r}],i);let s=this.peek;if(!s)return this.error("syntax-error",n);if(Nf(this))return this.error("unexpected-delimiter",n);if(s[0]!=="\\")return this.nextToken(),this.error(["unexpected-token",{str:ln(s)}],n);let o=this.nextToken();if(this.skipSpaceTokens(),o==="\\end"){let a=this.parseStringGroup();return a===null?this.error("expected-environment-name",n):this.error(["unbalanced-environment",{str:a}],n)}for(;this.match("[");){let a=0;for(;!this.atEnd&&a===0&&this.peek!=="]";)this.peek==="["&&(a+=1),this.peek==="]"&&(a-=1),this.nextToken();this.match("]")}for(;this.match("<{>");){let a=0;for(;!this.atEnd&&a===0&&this.peek!=="<}>";)this.peek==="<{>"&&(a+=1),this.peek==="<}>"&&(a-=1),this.nextToken();this.match("<}>")}return this.error(["unexpected-command",{str:ln(o)}],n)}parsePrimary(n){if(this.atBoundary||this.atTerminator(n))return null;let t=null,i=this.index;if(this.match("<}>"))return this.error("unexpected-closing-delimiter",i);if(t??=this.parseGroup(),t??=this.parseNumber(),t??=this.parseDoubleQuoteString(),t??=this.parseEnclosure(),t??=this.parseEnvironment(n),t===null&&this.matchAll(this._positiveInfinityTokens)&&(t="PositiveInfinity"),t===null&&this.matchAll(this._negativeInfinityTokens)&&(t="NegativeInfinity"),t===null&&this.matchAll(this._notANumberTokens)&&(t="NaN"),t===null&&this.matchAll(this._imaginaryUnitTokens)&&(t="ImaginaryUnit"),t??=this.tryParseBareFunction(n),t??=this.tryParseBareSymbol(),t??=this.tryParseBareRun(),t??=this.parseGenericExpression(n)??this.parseFunction(n)??this.parseSymbol(n)??as(this),t!==null&&R(t))return this.parsePrimary(n);if(t!==null){t=this.decorate(t,i);let r=null,s=this.index;do{if(r=this.parsePostfixOperator(t,n),t=r??t,this.index===s&&r!==null){this.index;break}s=this.index}while(r!==null)}if(t!==null&&(t=this.parseSupsub(t)),t!==null&&(t=df(t)),t!==null){let r=null,s=this.index;do{if(r=this.parsePostfixOperator(t,n),t=r??t,this.index===s&&r!==null){this.index;break}s=this.index}while(r!==null)}if(t===null&&(t=this.options.parseUnexpectedToken?.(null,this)??null,t===null&&this.peek.startsWith("\\"))){if(this.peek==="\\"){let r=this.index;if(this.nextToken(),this.skipVisualSpace(),this.atEnd)return this.emitDiagnostic("recovered",r,this.index,{skipped:this.latex(r,this.index)}),this.decorate(null,i);this.index=r}this.nextToken(),t=this.error("unexpected-command",i)}return this.decorate(t,i)}parseExpression(n){this.skipSpace();let t=this.index;if(this.atBoundary)return this.index=t,null;let i=this.diagnosticsCheckpoint();n??={minPrec:0},n.minPrec,n.minPrec===void 0&&(n={...n,minPrec:0});let r=this.parsePrefixOperator({...n,minPrec:0});if(r??=this.parsePrimary(n),r!==null){let s=!1;for(;!s&&!this.atTerminator(n);){this.skipSpace(),this._operandDiagnosticCheckpoint=i;let o=this.parseInfixOperator(r,n);if(o===null&&n.minPrec<=qe){let a=this.peekDefinitions("operator");if((a.length===0||a.every(([u])=>u.latexTrigger==="\\text"||u.latexTrigger==="\\keyword"))&&!(a.length>0&&this.wouldMatchTextInfix(a))){let u=this.index,l=this.parseExpression({...n,minPrec:qe+1});l!==null?(this.emitJuxtapositionDiagnostic(r,l,t,u),d(r)==="InvisibleOperator"?d(l)==="InvisibleOperator"?o=["InvisibleOperator",...b(r),...b(l)]:o=["InvisibleOperator",...b(r),l]:d(l)==="InvisibleOperator"?o=["InvisibleOperator",r,...b(l)]:o=["InvisibleOperator",r,l]):o===null&&(o=this.options.parseUnexpectedToken?.(r,this)??null)}}o!==null?r=o:s=!0}}return this.decorate(r,t)}decorate(n,t){if(n===null)return null;if(!this.options.preserveLatex)return n;let i=this.latex(t,this.index);return Array.isArray(n)?n={latex:i,fn:n}:typeof n=="number"?n={latex:i,num:Number(n).toString()}:typeof n=="string"?n.startsWith("'")?n={latex:i,str:n.slice(1,-1)}:n={latex:i,sym:n}:typeof n=="object"&&n!==null&&(n.latex=i),n}error(n,t){let i;typeof n=="string"?(n.startsWith("'"),i={str:n}):(n[0].startsWith("'"),i=["ErrorCode",{str:n[0]},...n.slice(1)]);let r=this.latex(t,this.index),s=r?["Error",i,["LatexString",{str:r}]]:["Error",i],a=typeof n=="string"&&n==="missing"?this.sourceOffsets(t,t):this.sourceOffsets(t,this.index);return{fn:s,sourceOffsets:a}}emitJuxtapositionDiagnostic(n,t,i,r){if(this.diagnostics===null)return;let s=d(t);if(s!=="Delimiter"&&s!=="Matrix")return;let o=null,a=i,u,l=y(n);if(l!==null)o=l;else if(d(n)==="__unit__")o=y(c(n,1)),o!==null&&(u="unit");else if(d(n)==="InvisibleOperator"){let p=this.trailingLetterRun(r);if(p===null)return;o=p.name,a=p.startToken}if(o===null)return;let f=this.isSymbolDeclared(o)?this.getSymbolType(o).matches("function")?"function":"value":"unknown";this.emitDiagnostic("juxtaposition-as-multiply",a,this.index,u!==void 0?{name:o,declaredAs:f,lexedAs:u}:{name:o,declaredAs:f})}trailingLetterRun(n){let t=n;for(;t>0&&this._tokens[t-1]==="<space>";)t--;let i="";for(;t>0&&/^[a-zA-Z]$/.test(this._tokens[t-1]);)i=this._tokens[t-1]+i,t--;return i.length===0?null:{name:i,startToken:t}}isFunctionOperator(n){return n===null||n==="D"||n==="N"?!1:!!this.getSymbolType(n).matches("function")}looksLikePredicate(n){return n===null||typeof n!="string"||!/^[A-Z]$/.test(n)?!1:(this.skipSpace(),this.peek==="("||this.peek==="\\left")}*getDefs(n){if(n==="operator")for(let t=this._dictionary.defs.length-1;t>=0;t--){let i=this._dictionary.defs[t];/^prefix|infix|postfix/.test(i.kind)&&(yield i)}else for(let t=this._dictionary.defs.length-1;t>=0;t--){let i=this._dictionary.defs[t];i.kind===n&&(yield i)}}};function Nf(e){let n=e.peek;return Object.values(ps).includes(n)||ps[n]?(e.nextToken(),!0):En[n]||Object.values(En).includes(n)?(e.nextToken(),e.nextToken(),!0):!1}var f0=Object.freeze([0,1]);var Cx=new G("matrix"),Bx=new G("vector");var Kn=[[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 gs(e,n){for(;e>=Kn.length;){let t=Kn.length,i=[1],r=Kn[t-1];for(let s=1;s<t;s++)i[s]=r[s-1]+r[s];i[t]=1,Kn.push(i)}return Kn[e][n]}function ci(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return Yf(t)}function Yf(e){return e.hi<0?{kind:"empty"}:e.lo>=0?x({lo:Math.sqrt(e.lo),hi:Math.sqrt(e.hi)}):{kind:"partial",value:{lo:0,hi:Math.sqrt(e.hi)},domainClipped:"lo"}}function fi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?x({lo:t.lo*t.lo,hi:t.hi*t.hi}):t.hi<=0?x({lo:t.hi*t.hi,hi:t.lo*t.lo}):x({lo:0,hi:Math.max(t.lo*t.lo,t.hi*t.hi)})}function cu(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 Ae(e,n){let t=T(e);if(!Array.isArray(t))return t;let[i]=t;if(Number.isInteger(n)){if(n>=0)return x(cu(i,n));{if(K(i))return{kind:"singular"};let r=cu(i,-n);return x({lo:1/r.hi,hi:1/r.lo})}}else return Qe(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?x({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"}:x({lo:Math.pow(i.hi,n),hi:Math.pow(i.lo,n)})}function pi(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(r.lo===r.hi&&Number.isInteger(r.lo))return Ae(i,r.lo);if(i.hi<=0)return i.lo===-1&&i.hi===-1&&Math.floor(r.hi)>Math.floor(r.lo)?x({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 x({lo:Math.min(...s),hi:Math.max(...s)})}function fu(e,n,t){if(e===0)return t>0?0:t<0?1/0:1;let i=Math.pow(Math.abs(e),t);return e<0&&n%2!==0?-i:i}function bs(e,n,t){let i=T(e);if(!Array.isArray(i))return i;let[r]=i,s=n/t;if(t%2===0)return Ae(x(r),s);if(r.lo>=0)return Ae(x(r),s);let o=r.lo<=0&&r.hi>=0;if(n<0&&o)return{kind:"singular",at:0};let a=[fu(r.lo,n,s),fu(r.hi,n,s)];return o&&n>0&&a.push(0),x({lo:Math.min(...a),hi:Math.max(...a)})}function ys(e,n){let t=T(e);if(!Array.isArray(t))return t;let[i]=t;if(!Number.isInteger(n)||n===0)return Ae(x(i),1/n);if(n%2===0)return Ae(x(i),1/n);let r=s=>Math.sign(s)*Math.pow(Math.abs(s),1/n);return x({lo:r(i.lo),hi:r(i.hi)})}function mi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.exp(t.lo),hi:Math.exp(t.hi)})}function di(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?x({lo:Math.log(t.lo),hi:Math.log(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log(t.hi)},domainClipped:"lo"}}function gi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?x({lo:Math.log10(t.lo),hi:Math.log10(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log10(t.hi)},domainClipped:"lo"}}function hi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?x({lo:Math.log2(t.lo),hi:Math.log2(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log2(t.hi)},domainClipped:"lo"}}function bi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?x(t):t.hi<=0?x({lo:-t.hi,hi:-t.lo}):x({lo:0,hi:Math.max(-t.lo,t.hi)})}function yi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?x({lo:i,hi:r}):{kind:"singular",at:i+1,continuity:"right"}}function xi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.ceil(t.lo),r=Math.ceil(t.hi);return i===r?x({lo:i,hi:r}):{kind:"singular",at:i,continuity:"left"}}function Xf(e){return Math.sign(e)*Math.round(Math.abs(e))}function Kf(e,n){let t=n(e.lo),i=n(e.hi);if(t===i)return x({lo:t,hi:i});let r=t+.5;return{kind:"singular",at:r,continuity:n(r)===t+1?"right":"left"}}function Qn(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return Kf(t,Xf)}function Ni(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?x({lo:t.lo-i,hi:t.hi-i}):{kind:"singular",at:i+1,continuity:"right"}}function Ei(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.trunc(t.lo),r=Math.trunc(t.hi);if(i===r)return x({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 Ti(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return x({lo:Math.min(i.lo,r.lo),hi:Math.min(i.hi,r.hi)})}function vi(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return x({lo:Math.max(i.lo,r.lo),hi:Math.max(i.hi,r.hi)})}function Ii(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(K(r))return{kind:"singular"};if(i.lo===i.hi&&r.lo===r.hi){let p=r.lo,g=(i.lo%p+p)%p+0;return x({lo:g,hi:g})}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,f=i.hi-s*a;return o?l===0?{kind:"singular",at:i.lo,continuity:"right"}:x({lo:l-s,hi:f-s}):x({lo:Math.min(l,f),hi:Math.max(l,f)})}function Mi(e,n){return en(e,nn(n,Qn(Q(e,n))))}function ki(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?x({lo:1,hi:1}):t.hi<0?x({lo:0,hi:0}):t.lo===0&&t.hi===0?x({lo:.5,hi:.5}):{kind:"singular",at:0}}function Si(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?x({lo:1,hi:1}):t.hi<0?x({lo:-1,hi:-1}):t.lo===0&&t.hi===0?x({lo:0,hi:0}):{kind:"singular",at:0}}var pu=1.4616321449683622,Qf=.8856031944108887;function wi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return ep(t)}var mu=[-.504083008264455,-1.573498473162391,-2.610720868444145,-3.635293366436901,-4.653163765628266,-5.667162441556885,-6.678418213073426,-7.687788325031709,-8.695764163640956,-9.702672540001863];function gu(e){let t=-Math.floor(e)-1;return t>=0&&t<mu.length?mu[t]:null}function ep(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=ue(e.lo),r=ue(e.hi),s=Math.min(i,r),o=Math.max(i,r),a=gu(e.lo);if(a!==null){if(a>=e.lo&&a<=e.hi){let u=ue(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 x({lo:s,hi:o})}return e.lo>=pu?x({lo:ue(e.lo),hi:ue(e.hi)}):e.hi<=pu?x({lo:ue(e.hi),hi:ue(e.lo)}):x({lo:Qf,hi:Math.max(ue(e.lo),ue(e.hi))})}function Ai(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return np(t)}function np(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=sn(e.lo),r=sn(e.hi),s=Math.min(i,r),o=Math.max(i,r),a=gu(e.lo);return a!==null?a>=e.lo&&a<=e.hi&&(s=Math.min(s,sn(a))):s=-1/0,x({lo:s,hi:o})}return x({lo:sn(e.lo),hi:sn(e.hi)})}function Pi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=Tr(Math.round(t.lo)),r=Tr(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?x({lo:Math.min(i,r),hi:Math.max(i,r)}):x({lo:i,hi:r})}function Di(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=vr(Math.round(t.lo)),r=vr(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?x({lo:Math.min(i,r),hi:Math.max(i,r)}):x({lo:i,hi:r})}var hs=4096;function du(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 xs(e,n,t){let i=du(e.lo,e.hi,hs),r=du(n.lo,n.hi,hs);if(!i||!r||i.length*r.length>hs)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:x({lo:s,hi:o})}function _i(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=xs(r,s,gs);if(o)return o;let a=Math.round(r.hi);return x({lo:0,hi:gs(a,Math.floor(a/2))})}function Ri(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=xs(r,s,un);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 x({lo:0,hi:a})}function Ci(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=xs(r,s,Er);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 x({lo:0,hi:a*u})}function Ns(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Ir(t.lo),hi:Ir(t.hi)})}function Es(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Pt(t.lo),hi:Pt(t.hi)})}function Ts(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:At(t.hi),hi:At(t.lo)})}function vs(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.pow(2,t.lo),hi:Math.pow(2,t.hi)})}function Is(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(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),x({lo:a,hi:Math.max(...o)})}var ge=2*Math.PI,j=Math.PI,he=Math.PI/2,hu=3*Math.PI/2;function Bi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=ge)return x({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 W(t,he,ge)&&(o=1),W(t,hu,ge)&&(s=-1),x({lo:s,hi:o})}function Oi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=ge)return x({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 W(t,0,ge)&&(o=1),W(t,j,ge)&&(s=-1),x({lo:s,hi:o})}function Fi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,he,j)){let s=Math.ceil((t.lo-he)/j);return{kind:"singular",at:he+s*j}}let i=Math.tan(t.lo),r=Math.tan(t.hi);return i>1e10&&r<-1e10||i<-1e10&&r>1e10?{kind:"singular"}:x({lo:i,hi:r})}function Ji(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,0,j))return{kind:"singular",at:Math.ceil(t.lo/j)*j};let i=1/Math.tan(t.lo),r=1/Math.tan(t.hi);return x({lo:Math.min(i,r),hi:Math.max(i,r)})}function Li(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,he,j)){let a=Math.ceil((t.lo-he)/j);return{kind:"singular",at:he+a*j}}let i=1/Math.cos(t.lo),r=1/Math.cos(t.hi),s=Math.min(i,r),o=Math.max(i,r);return W(t,0,ge)&&(s=Math.min(s,1),o=Math.max(o,1)),W(t,j,ge)&&(s=Math.min(s,-1),o=Math.max(o,-1)),x({lo:s,hi:o})}function Vi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,0,j))return{kind:"singular",at:Math.ceil(t.lo/j)*j};let i=1/Math.sin(t.lo),r=1/Math.sin(t.hi),s=Math.min(i,r),o=Math.max(i,r);return W(t,he,ge)&&(s=Math.min(s,1),o=Math.max(o,1)),W(t,hu,ge)&&(s=Math.min(s,-1),o=Math.max(o,-1)),x({lo:s,hi:o})}function et(e){let n=T(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 x({lo:Math.asin(t.lo),hi:Math.asin(t.hi)})}function nt(e){let n=T(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 x({lo:Math.acos(t.hi),hi:Math.acos(t.lo)})}function qi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.atan(t.lo),hi:Math.atan(t.hi)})}function $i(e,n){let t=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 x({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?x({lo:-j,hi:j}):x({lo:Math.min(...s),hi:Math.max(...s)})}function Tn(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.sinh(t.lo),hi:Math.sinh(t.hi)})}function vn(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?x({lo:Math.cosh(t.lo),hi:Math.cosh(t.hi)}):t.hi<=0?x({lo:Math.cosh(t.hi),hi:Math.cosh(t.lo)}):x({lo:1,hi:Math.max(Math.cosh(t.lo),Math.cosh(t.hi))})}function ji(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.tanh(t.lo),hi:Math.tanh(t.hi)})}function tt(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.asinh(t.lo),hi:Math.asinh(t.hi)})}function it(e){let n=T(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"}:x({lo:Math.acosh(t.lo),hi:Math.acosh(t.hi)})}function rt(e){let n=T(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 x({lo:Math.atanh(t.lo),hi:Math.atanh(t.hi)})}function Gi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:he-Math.atan(t.hi),hi:he-Math.atan(t.lo)})}function zi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:et(Q(x({lo:1,hi:1}),x(t)))}function Zi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:nt(Q(x({lo:1,hi:1}),x(t)))}function Ui(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:Q(vn(t),Tn(t))}function Hi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:Q(x({lo:1,hi:1}),Tn(t))}function Wi(e){return Q(x({lo:1,hi:1}),vn(e))}function Yi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:rt(Q(x({lo:1,hi:1}),x(t)))}function Xi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:tt(Q(x({lo:1,hi:1}),x(t)))}function Ki(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:it(Q(x({lo:1,hi:1}),x(t)))}var Ms=[4.49341,7.72525,10.90412,14.06619,17.22076,20.3713,23.51945,26.66605,29.8116,32.95639];function Qi(e){let n=T(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=Ms[Ms.length-1];for(let l of Ms)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)),x({lo:r,hi:s})}var ks=[],Ss=[];for(let e=1;e<=20;e++)ks.push(Math.sqrt(2*e)),Ss.push(Math.sqrt(2*e-1));function er(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=on(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(on(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of ks)o>=t.lo&&o<=t.hi&&s(on(o)),-o>=t.lo&&-o<=t.hi&&s(on(-o));return bu(t,ks,on,s),x({lo:i,hi:r})}function bu(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 nr(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=an(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(an(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of Ss)o>=t.lo&&o<=t.hi&&s(an(o)),-o>=t.lo&&-o<=t.hi&&s(an(-o));return bu(t,Ss,an,s),x({lo:i,hi:r})}function Pe(e){return"kind"in e?e:{kind:"interval",value:e}}function tr(e,n){let t=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 ir(e,n){let t=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 rr(e,n){let t=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 sr(e,n){let t=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 st(e,n){let t=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 or(e,n){let t=st(e,n);return t==="true"?"false":t==="false"?"true":"maybe"}function ar(e,n){return e==="false"||n==="false"?"false":e==="true"&&n==="true"?"true":"maybe"}function ur(e,n){return e==="true"||n==="true"?"true":e==="false"&&n==="false"?"false":"maybe"}function lr(e){return e==="true"?"false":e==="false"?"true":"maybe"}function cr(e,n,t,i){if(e==="true"||e==="false"||e==="maybe"){let p=e,g=n,h=t;switch(p){case"true":return Pe(g());case"false":return Pe(h());case"maybe":return Be(Pe(g()),Pe(h()))}}let r=e,s=n,o=t,a=i,u=T(r);if(!Array.isArray(u))return u;let[l]=u;switch(s(l)){case"true":return Pe(o(l));case"false":return Pe(a(l));case"maybe":let p=Pe(o(l)),g=Pe(a(l));return Be(p,g)}}function ws(e,n){if(e==="false")return{kind:"empty"};let t=Pe(n());return e==="true"?t:t.kind==="interval"?{kind:"partial",value:t.value,domainClipped:"both"}:t.kind==="partial"?{...t,domainClipped:"both"}:t}function fr(e,n,t){let i=T(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 tp={ok:x,point:ot,containsExtremum:W,unionResults:Be,mergeDomainClip:In,isPoint:at,containsZero:K,isPositive:ut,isNegative:Qe,isNonNegative:lt,isNonPositive:ct,width:ft,midpoint:pt,getValue:mt,unwrap:dt,unwrapOrPropagate:T,add:ht,sub:en,mul:nn,div:Q,negate:bt,sqrt:ci,square:fi,pow:Ae,powInterval:pi,powRational:bs,nthRoot:ys,exp:mi,ln:di,log10:gi,log2:hi,abs:bi,floor:yi,ceil:xi,round:Qn,fract:Ni,trunc:Ei,min:Ti,max:vi,mod:Ii,remainder:Mi,heaviside:ki,sign:Si,gamma:wi,gammaln:Ai,factorial:Pi,factorial2:Di,binomial:_i,gcd:Ri,lcm:Ci,chop:Ns,erf:Es,erfc:Ts,exp2:vs,hypot:Is,sin:Bi,cos:Oi,tan:Fi,cot:Ji,sec:Li,csc:Vi,asin:et,acos:nt,atan:qi,atan2:$i,sinh:Tn,cosh:vn,tanh:ji,asinh:tt,acosh:it,atanh:rt,acot:Gi,acsc:zi,asec:Zi,coth:Ui,csch:Hi,sech:Wi,acoth:Yi,acsch:Xi,asech:Ki,sinc:Qi,fresnelS:er,fresnelC:nr,less:tr,lessEqual:ir,greater:rr,greaterEqual:sr,equal:st,notEqual:or,and:ar,or:ur,not:lr,piecewise:cr,restrict:ws,clamp:fr};var xN="0.86.1";export{tp as IntervalArithmetic,yt as _mul,bi as abs,nt as acos,it as acosh,Gi as acot,Yi as acoth,zi as acsc,Xi as acsch,ht as add,ar as and,Zi as asec,Ki as asech,et as asin,tt as asinh,qi as atan,$i as atan2,rt as atanh,_i as binomial,xi as ceil,Ns as chop,fr as clamp,W as containsExtremum,K as containsZero,Oi as cos,vn as cosh,Ji as cot,Ui as coth,Vi as csc,Hi as csch,Q as div,st as equal,Es as erf,Ts as erfc,mi as exp,vs as exp2,Pi as factorial,Di as factorial2,yi as floor,Ni as fract,nr as fresnelC,er as fresnelS,wi as gamma,Ai as gammaln,Ri as gcd,mt as getValue,rr as greater,sr as greaterEqual,ki as heaviside,Is as hypot,Qe as isNegative,lt as isNonNegative,ct as isNonPositive,at as isPoint,ut as isPositive,Ci as lcm,tr as less,ir as lessEqual,di as ln,gi as log10,hi as log2,vi as max,In as mergeDomainClip,pt as midpoint,Ti as min,Ii as mod,nn as mul,bt as negate,lr as not,or as notEqual,x as ok,ur as or,cr as piecewise,ot as point,Ae as pow,pi as powInterval,Mi as remainder,Qn as round,Li as sec,Wi as sech,Si as sign,Bi as sin,Qi as sinc,Tn as sinh,ci as sqrt,fi as square,en as sub,Fi as tan,ji as tanh,Ei as trunc,Be as unionResults,dt as unwrap,T as unwrapOrPropagate,xN as version,ft as width};
7
+ `),l=o.length>0?`[${o}]`:"";return r==="("&&s===")"?E(["\\begin{pmatrix}",l,u,"\\end{pmatrix}"]):r==="["&&s==="]"?E(["\\begin{bmatrix}",l,u,"\\end{bmatrix}"]):r==="{"&&s==="}"?E(["\\begin{Bmatrix}",l,u,"\\end{Bmatrix}"]):r==="|"&&s==="|"?E(["\\begin{vmatrix}",l,u,"\\end{vmatrix}"]):r==="\u2016"&&s==="\u2016"?E(["\\begin{Vmatrix}",l,u,"\\end{Vmatrix}"]):r==="{"&&s==="."?E(["\\begin{dcases}",l,u,"\\end{dcases}"]):r==="."&&s==="}"?E(["\\begin{rcases}",l,u,"\\end{rcases}"]):o||r!=="."||s!=="."?E(["\\left",Kt[r]??r,"\\begin{array}",`{${o}}`,u,"\\end{array}","\\right",Kt[s]??s]):E(["\\begin{matrix}",u,"\\end{matrix}"])}var qc=["NormalDistribution","BinomialDistribution","PoissonDistribution","UniformDistribution","ExponentialDistribution","PDF","CDF","Quantile","GammaRegularized","BetaRegularized","Covariance","PopulationCovariance","Correlation","LinearRegression","PolynomialFit"],Pa=[...qc.map(e=>({kind:"expression",name:e,serialize:(n,t)=>`\\operatorname{${e}}`+n.wrapArguments(t)})),{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||!y(t)?null:["Mean",t]}},{latexTrigger:"\\operatorname{var}",kind:"function",parse:"Variance"},{latexTrigger:"\\operatorname{cov}",kind:"function",parse:"Covariance"},{latexTrigger:"\\operatorname{corr}",kind:"function",parse:"Correlation"}];var ri={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},Da=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"]),si={m:{dimension:[1,0,0,0,0,0,0,0],scale:1},kg:{dimension:[0,1,0,0,0,0,0,0],scale:1},g:{dimension:[0,1,0,0,0,0,0,0],scale:.001},s:{dimension:[0,0,1,0,0,0,0,0],scale:1},A:{dimension:[0,0,0,1,0,0,0,0],scale:1},K:{dimension:[0,0,0,0,1,0,0,0],scale:1},mol:{dimension:[0,0,0,0,0,1,0,0],scale:1},cd:{dimension:[0,0,0,0,0,0,1,0],scale:1},Hz:{dimension:[0,0,-1,0,0,0,0,0],scale:1},N:{dimension:[1,1,-2,0,0,0,0,0],scale:1},Pa:{dimension:[-1,1,-2,0,0,0,0,0],scale:1},J:{dimension:[2,1,-2,0,0,0,0,0],scale:1},W:{dimension:[2,1,-3,0,0,0,0,0],scale:1},C:{dimension:[0,0,1,1,0,0,0,0],scale:1},V:{dimension:[2,1,-3,-1,0,0,0,0],scale:1},F:{dimension:[-2,-1,4,2,0,0,0,0],scale:1},ohm:{dimension:[2,1,-3,-2,0,0,0,0],scale:1},S:{dimension:[-2,-1,3,2,0,0,0,0],scale:1},Wb:{dimension:[2,1,-2,-1,0,0,0,0],scale:1},T:{dimension:[0,1,-2,-1,0,0,0,0],scale:1},H:{dimension:[2,1,-2,-2,0,0,0,0],scale:1},lm:{dimension:[0,0,0,0,0,0,1,0],scale:1},lx:{dimension:[-2,0,0,0,0,0,1,0],scale:1},Bq:{dimension:[0,0,-1,0,0,0,0,0],scale:1},Gy:{dimension:[2,0,-2,0,0,0,0,0],scale:1},Sv:{dimension:[2,0,-2,0,0,0,0,0],scale:1},kat:{dimension:[0,0,-1,0,0,1,0,0],scale:1},degC:{dimension:[0,0,0,0,1,0,0,0],scale:1,offset:273.15},degF:{dimension:[0,0,0,0,1,0,0,0],scale:5/9,offset:459.67},min:{dimension:[0,0,1,0,0,0,0,0],scale:60},h:{dimension:[0,0,1,0,0,0,0,0],scale:3600},d:{dimension:[0,0,1,0,0,0,0,0],scale:86400},wk:{dimension:[0,0,1,0,0,0,0,0],scale:604800},ha:{dimension:[2,0,0,0,0,0,0,0],scale:1e4},L:{dimension:[3,0,0,0,0,0,0,0],scale:.001},t:{dimension:[0,1,0,0,0,0,0,0],scale:1e3},eV:{dimension:[2,1,-2,0,0,0,0,0],scale:1602176634e-28},Da:{dimension:[0,1,0,0,0,0,0,0],scale:16605390666e-37},au:{dimension:[1,0,0,0,0,0,0,0],scale:149597870700},deg:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/180},rad:{dimension:[0,0,0,0,0,0,0,0],scale:1},grad:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/200},turn:{dimension:[0,0,0,0,0,0,0,0],scale:2*Math.PI},arcmin:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/10800},arcsec:{dimension:[0,0,0,0,0,0,0,0],scale:Math.PI/648e3},percent:{dimension:[0,0,0,0,0,0,0,0],scale:.01},ppm:{dimension:[0,0,0,0,0,0,0,0],scale:1e-6},dB:{dimension:[0,0,0,0,0,0,0,0],scale:1},Np:{dimension:[0,0,0,0,0,0,0,0],scale:1},in:{dimension:[1,0,0,0,0,0,0,0],scale:.0254},ft:{dimension:[1,0,0,0,0,0,0,0],scale:.3048},yd:{dimension:[1,0,0,0,0,0,0,0],scale:.9144},mi:{dimension:[1,0,0,0,0,0,0,0],scale:1609.344},lb:{dimension:[0,1,0,0,0,0,0,0],scale:.45359237},oz:{dimension:[0,1,0,0,0,0,0,0],scale:.028349523125},gal:{dimension:[3,0,0,0,0,0,0,0],scale:.003785411784},qt:{dimension:[3,0,0,0,0,0,0,0],scale:.000946352946},pt:{dimension:[3,0,0,0,0,0,0,0],scale:.000473176473},cup:{dimension:[3,0,0,0,0,0,0,0],scale:.0002365882365},atm:{dimension:[-1,1,-2,0,0,0,0,0],scale:101325},bar:{dimension:[-1,1,-2,0,0,0,0,0],scale:1e5},cal:{dimension:[2,1,-2,0,0,0,0,0],scale:4.184},kWh:{dimension:[2,1,-2,0,0,0,0,0],scale:36e5},\u00C5:{dimension:[1,0,0,0,0,0,0,0],scale:1e-10},USD:{dimension:[0,0,0,0,0,0,0,1],scale:1},cent:{dimension:[0,0,0,0,0,0,0,1],scale:.01}};function $c(e){if(e.length>2){let n=e.slice(0,2),t=e.slice(2);if(ri[n]!==void 0&&Da.has(t)){let i=si[t];if(i)return{prefixScale:ri[n],baseEntry:i}}}if(e.length>1){let n=e.slice(0,1),t=e.slice(1);if(ri[n]!==void 0&&Da.has(t)){let i=si[t];if(i)return{prefixScale:ri[n],baseEntry:i}}}return null}function jc(e){let n=si[e];if(n)return n;let t=$c(e);return t?{dimension:t.baseEntry.dimension,scale:t.prefixScale*t.baseEntry.scale}:null}function ns(e){let n=jc(e);return n?n.dimension:null}var Oh=new Map(["N","J","W","Pa","Hz","C","V","F","ohm","S","Wb","T","H","lm","lx","Gy","kat"].map(e=>[si[e].dimension.join(","),e]));function Gc(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 Un(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 Un(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=Un(r),a=Un(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=>Un(a));return o.some(a=>a===null)?null:o.length===1?o[0]:["Multiply",...o]}return e[0]==="("?null:Gc(e)}function _a(e){return e=e.trim(),e.length===0?null:/[/*^()]/.test(e)?Un(e):e}function Oa(e){for(;e.peek==="<space>";)e.nextToken();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>"){n.length>0&&!n.endsWith(" ")&&(n+=" "),e.nextToken();continue}if(i==="<$>"){n+="$",e.nextToken();continue}if(i==="\\cdot"){n+="*",e.nextToken();continue}if(i==="^"){n+="^",e.nextToken();continue}n+=i,e.nextToken()}return null}var Fa=new Set(["d"]),zc={inch:"in",inches:"in","in.":"in",foot:"ft",feet:"ft","ft.":"ft",mile:"mi",miles:"mi",yard:"yd",yards:"yd",meter:"m",meters:"m",metre:"m",metres:"m",centimeter:"cm",centimeters:"cm",centimetre:"cm",centimetres:"cm",kilometer:"km",kilometers:"km",kilometre:"km",kilometres:"km",gallon:"gal",gallons:"gal",quart:"qt",quarts:"qt",pint:"pt",pints:"pt",cup:"cup",cups:"cup",liter:"L",liters:"L",litre:"L",litres:"L",ounce:"oz",ounces:"oz",pound:"lb",pounds:"lb",gram:"g",grams:"g",kilogram:"kg",kilograms:"kg",second:"s",seconds:"s",minute:"min",minutes:"min",hour:"h",hours:"h",day:"d",days:"d",week:"wk",weeks:"wk",dollar:"USD",dollars:"USD",$:"USD",cent:"cent",cents:"cent",degree:"deg",degrees:"deg",mph:"mi/h",per:"/"};function Zc(e){return e.replace(/\$|[A-Za-z.]+/g,n=>zc[n]??n)}function ts(e){if(!e)return null;let n=e.trim();if(n.length===0||Fa.has(n))return null;let t=Zc(n).replace(/\s+/g,"");if(ns(t)!==null)return t;if(/[/*^]/.test(t))try{let i=_a(t);if(i!==null&&is(i))return i}catch{return null}return null}function is(e){if(typeof e=="string")return ns(e)!==null;if(!Array.isArray(e))return!1;let n=e[0];return n==="Multiply"||n==="Divide"?e.slice(1).every(t=>is(t)):n==="Power"?is(e[1]):!1}function Uc(e){let n=e.index;if(!e.match("^"))return null;if(e.match("<{>")){let i="";for(;!e.atEnd&&e.peek!=="<}>";)i+=e.peek,e.nextToken();return e.match("<}>")?i:(e.index=n,null)}if(e.atEnd)return e.index=n,null;let t=e.peek;return e.nextToken(),t}var Ra=e=>{let n=e.index,t=Oa(e);if(t===null)return e.index=n,null;let i=e.index;if(!Fa.has(t.trim())){let s=Uc(e);if(s!==null){let o=ts(`${t}^${s}`);if(o!==null)return["__unit__",o];e.index=i}}let r=ts(t);return r===null?(e.index=n,null):["__unit__",r]};function We(e){let n=y(e);if(n!==null)return n;if(typeof e=="number")return String(e);let t=d(e);if(!t)return"";if(t==="Divide"){let i=c(e,1),r=c(e,2);return`${We(i)}/${We(r)}`}if(t==="Multiply"){let i=[];if(Array.isArray(e))for(let r=1;r<e.length;r++)i.push(We(e[r]));return i.join("\\cdot ")}if(t==="Power"){let i=c(e,1),r=c(e,2),s=typeof r=="number"?String(r):y(r)??String(r);return`${We(i)}^{${s}}`}if(t==="Square"){let i=c(e,1);return`${We(i)}^{2}`}return""}function Ca(e){let n=e.parseGroup();if(n===null)return null;let t=Ja(e);return t===null?null:["Quantity",n,t]}function Ba(e){return Ja(e)}function Ja(e){let n=e.index,t=Oa(e);if(t===null)return e.index=n,null;let i=ts(t);return i===null?(e.index=n,null):i}var La=[{latexTrigger:"\\mathrm",kind:"expression",parse:Ra},{latexTrigger:"\\text",kind:"expression",parse:Ra},{latexTrigger:"\\qty",parse:Ca},{latexTrigger:"\\SI",parse:Ca},{latexTrigger:"\\unit",parse:Ba},{latexTrigger:"\\si",parse:Ba},{name:"Quantity",serialize:(e,n)=>{let t=c(n,1),i=c(n,2);if(t===null||i===null)return"";let r=y(i),s=r==="deg"||r==="rad"||r==="arcmin"||r==="arcsec",o=e.options;if(s&&(o.dmsFormat||o.angleNormalization&&o.angleNormalization!=="none")){let l=M(t);if(l===null){let p=e.serialize(t),g=We(i);return E([p,"\\,",`\\mathrm{${g}}`])}let f=l;return r==="rad"?f=f*180/Math.PI:r==="arcmin"?f=f/60:r==="arcsec"&&(f=f/3600),o.angleNormalization&&o.angleNormalization!=="none"&&(f=Qt(f,o.angleNormalization)),o.dmsFormat?ei(f):`${f}\xB0`}let a=e.serialize(t);d(t)==="Measurement"&&(a=`\\left(${a}\\right)`);let u=We(i);return E([a,"\\,",`\\mathrm{${u}}`])}}];var Hc=["pt","em","mu","ex","mm","cm","in","bp","sp","dd","cc","pc","nc","nd"];function Va(e){for(e.skipSpace(),(e.peek==="-"||e.peek==="+")&&e.nextToken();/^[\d.]$/.test(e.peek);)e.nextToken();for(let n of Hc)if(e.matchAll([...n]))return}function Wc(e){return n=>{let t=n.parseGroup();return t===null?[e]:[e,t]}}function re(e,n){return{name:e,latexTrigger:[n],parse:Wc(e),serialize:(t,i)=>{let r=c(i,1);return r===null?n:`${n}{${t.serialize(r)}}`}}}function Re(e,n){return(t,i)=>{let r=t.parseExpression({...i??{},minPrec:C});if(r===null||R(r))return n??[e];let s=d(r);return s==="InvisibleOperator"||s==="Multiply"?[e,...b(r)]:[e,r]}}function qa(e){return(n,t)=>{let i=b(t);return i.length===0?e:e+" "+i.map(r=>n.serialize(r)).join("")}}function $a(e){return n=>{let t=n.parseGroup()??n.parseToken();if(t===null||R(t))return[e];let i=d(t);return i==="InvisibleOperator"||i==="Multiply"?[e,...b(t)]:[e,t]}}function ja(e){return(n,t)=>{let i=b(t);return e+"{"+i.map(r=>n.serialize(r)).join("")+"}"}}function oi(e){return n=>{let t=n.parseExpression();return t!==null&&!R(t)?["Annotated",t,{dict:{mathStyle:e}}]:"Nothing"}}function de(e){return n=>{let t=n.parseExpression();return t!==null&&!R(t)?["Annotated",t,{dict:{size:e}}]:"Nothing"}}var Ga=[{name:"Overscript",latexTrigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",latexTrigger:["\\underset"],kind:"infix",precedence:700},{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;if(i===null||t===null)return null;if(i!=="Nothing"){let a=Ne(i)??[i];e.skipSpace();let u=e.parseGroup()??e.parseSymbol()??"Nothing";if(!R(u)){let p=e.parseArguments();p&&(u=[u,...p])}let l=M(t)??1,f=a.length===1&&l>1?Array.from({length:l},()=>a[0]):[...a];return["D",u,...f]}let r=[],s=()=>{e.skipSpace();let o=e.parseGroup()??e.parseSymbol()??"Nothing",a=1;if(d(o)==="Power")a=M(c(o,2))??1,o=c(o,1)??o;else if(e.match("^")){let u=e.parseGroup()??e.parseToken();a=M(u)??1}for(let u=0;u<a;u++)r.push(o)};for(s();e.skipSpace(),!!e.match("\\partial");)s();return r.length===1?["PartialDerivative",r[0],t]:["PartialDerivative",["List",...r],t]},precedence:740},re("OverBar","\\overline"),re("UnderBar","\\underline"),re("OverVector","\\vec"),re("OverTilde","\\tilde"),re("OverHat","\\hat"),re("OverRightArrow","\\overrightarrow"),re("OverLeftArrow","\\overleftarrow"),re("OverRightDoubleArrow","\\Overrightarrow"),re("OverLeftHarpoon","\\overleftharpoon"),re("OverRightHarpoon","\\overrightharpoon"),re("OverLeftRightArrow","\\overleftrightarrow"),re("OverBrace","\\overbrace"),re("UnderBrace","\\underbrace"),re("OverLineSegment","\\overlinesegment"),re("OverGroup","\\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"}},...["\\cancel","\\bcancel","\\xcancel"].map(e=>({latexTrigger:[e],parse:n=>n.parseGroup()??"Nothing"})),{latexTrigger:["\\cancelto"],parse:e=>{let n=e.parseGroup();return e.parseGroup(),n??"Nothing"}},{latexTrigger:["\\textbf"],parse:e=>$(e,{fontWeight:"bold"})},{latexTrigger:["\\textit"],parse:e=>$(e,{fontStyle:"italic"})},{latexTrigger:["\\emph"],parse:e=>$(e,{fontStyle:"italic"})},{latexTrigger:["\\textup"],parse:e=>$(e,{fontStyle:"normal"})},{latexTrigger:["\\texttt"],parse:e=>$(e,{fontFamily:"monospace"})},{latexTrigger:["\\textsf"],parse:e=>$(e,{fontFamily:"sans-serif"})},{latexTrigger:["\\textrm"],parse:e=>$(e)},{latexTrigger:["\\mbox"],parse:e=>$(e)},{latexTrigger:["\\displaystyle"],parse:oi("normal")},{latexTrigger:["\\textstyle"],parse:oi("compact")},{latexTrigger:["\\scriptstyle"],parse:oi("script")},{latexTrigger:["\\scriptscriptstyle"],parse:oi("scriptscript")},{latexTrigger:["\\color"],parse:e=>{let n=e.parseStringGroup();if(n!==null){let t=e.parseExpression();if(t!==null&&!R(t))return["Annotated",t,{dict:{color:n}}]}return"Nothing"}},{latexTrigger:["\\tiny"],parse:de(1)},{latexTrigger:["\\scriptsize"],parse:de(2)},{latexTrigger:["\\footnotesize"],parse:de(3)},{latexTrigger:["\\small"],parse:de(4)},{latexTrigger:["\\normalsize"],parse:de(5)},{latexTrigger:["\\large"],parse:de(6)},{latexTrigger:["\\Large"],parse:de(7)},{latexTrigger:["\\LARGE"],parse:de(8)},{latexTrigger:["\\huge"],parse:de(9)},{latexTrigger:["\\Huge"],parse:de(10)},{name:"Annotated",serialize:(e,n)=>{let t=e.serialize(c(n,1)),i=So(c(n,2));if(i==null)return t;let r=w(c(n,1));r!==null&&(i.dict.fontFamily==="monospace"||i.dict.fontFamily==="sans-serif"||i.dict.fontWeight==="bold"||i.dict.fontStyle==="italic"||i.dict.fontStyle==="normal")&&(t=r),i.dict.mathStyle==="normal"?t=E(["{\\displaystyle",t,"}"]):i.dict.mathStyle==="compact"?t=E(["{\\textstyle",t,"}"]):i.dict.mathStyle==="script"?t=E(["{\\scriptstyle",t,"}"]):i.dict.mathStyle==="scriptscript"&&(t=E(["{\\scriptscriptstyle",t,"}"]));let s=i.dict.size;return s!==null&&s>=1&&s<=10&&(t=E(["{",{1:"\\tiny",2:"\\scriptsize",3:"\\footnotesize",4:"\\small",5:"\\normalsize",6:"\\large",7:"\\Large",8:"\\LARGE",9:"\\huge",10:"\\Huge"}[s],t,"}"])),i.dict.fontFamily==="monospace"?t=E(["\\texttt{",t,"}"]):i.dict.fontFamily==="sans-serif"&&(t=E(["\\textsf{",t,"}"])),i.dict.fontWeight==="bold"&&(t=E(["\\textbf{",t,"}"])),i.dict.fontStyle==="italic"?t=E(["\\textit{",t,"}"]):i.dict.fontStyle==="normal"&&(t=E(["\\textup{",t,"}"])),i.dict.color&&(t=E(["\\textcolor{",i.dict.color,"}{",t,"}"])),i.dict.backgroundColor&&(t=E(["\\colorbox{",i.dict.backgroundColor,"}{",t,"}"])),i.dict.border===!0&&(t=E(["\\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=>(Va(e),["HorizontalSpacing",0])},{latexTrigger:["\\kern"],parse:e=>(Va(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(c(n,2)!==null){let i=w(c(n,2)),r=e.serialize(c(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=M(c(n,1));return t===null?"":{"-3":"\\!",6:"\\ ",3:"\\,",4:"\\:",5:"\\;",9:"\\enspace",18:"\\quad",36:"\\qquad"}[t]??""}},{latexTrigger:"\\operatorname{count}",kind:"function",parse:"Length"},{latexTrigger:"\\operatorname{length}",kind:"function",parse:"Length"},{latexTrigger:"\\operatorname{nCr}",kind:"function",parse:"Choose"},{latexTrigger:"\\operatorname{nPr}",parse:e=>{let n=e.parseArguments("enclosure");return!n||n.length!==2?null:["Multiply",["Choose",n[0],n[1]],["Factorial",n[1]]]}},{latexTrigger:"\\operatorname{random}",kind:"function",parse:"Random"},{latexTrigger:"\\operatorname{shuffle}",kind:"function",parse:"Shuffle"},{latexTrigger:"\\operatorname{repeat}",kind:"function",parse:"Repeat"},{latexTrigger:"\\operatorname{join}",kind:"function",parse:"Join"},{latexTrigger:"\\operatorname{range}",kind:"function",parse:"Range"},{latexTrigger:"\\operatorname{histogram}",kind:"function",parse:"Histogram"},{latexTrigger:"\\operatorname{pdf}",kind:"function",parse:"PDF"},{latexTrigger:"\\operatorname{cdf}",kind:"function",parse:"CDF"},{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)},{name:"Polygon",latexTrigger:["\\operatorname{polygon}"],kind:"function",serialize:(e,n)=>"\\operatorname{polygon}"+e.wrapArguments(n)},{name:"PointList",latexTrigger:["\\operatorname{PointList}"],kind:"function",serialize:(e,n)=>"\\operatorname{PointList}"+e.wrapArguments(n)},{name:"Angle",latexTrigger:["\\angle"],kind:"prefix",precedence:S,parse:Re("Angle"),serialize:qa("\\angle")},{latexTrigger:["\\varangle"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\\measuredangle"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\\Varangle"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\u2220"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\u2221"],kind:"prefix",precedence:S,parse:Re("Angle")},{latexTrigger:["\\triangle"],kind:"prefix",precedence:S,parse:Re("Triangle")},{name:"Quadrilateral",latexTrigger:["\\square"],kind:"prefix",precedence:S,parse:Re("Quadrilateral",ve),serialize:qa("\\square")},{name:"Perpendicular",latexTrigger:["\\perp"],kind:"infix",precedence:S},{name:"Parallel",latexTrigger:["\\parallel"],kind:"infix",precedence:S},{name:"Arc",latexTrigger:["\\widehat"],parse:$a("Arc"),serialize:ja("\\widehat")},{name:"OverParen",latexTrigger:["\\overparen"],parse:$a("OverParen"),serialize:ja("\\overparen")}];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 Yc=[{name:"Mu0",kind:"symbol",latexTrigger:"\\mu_0"},{name:"VacuumPermittivity",kind:"symbol",latexTrigger:"\\varepsilon_0"}];var Xc=[...Uo,...Qo,...ea,...Ro,...ia,...cn,...xa,...Na,...Ea,...ka,...Aa,...Pa,...La,...Ga,...Yc,...za];var rs;function Ha(e){if(!rs){let t=`^[${["Zyyy","Zinh","Arab","Armn","Beng","Bopo","Cyrl","Deva","Ethi","Geor","Grek","Gujr","Guru","Hang","Hani","Hebr","Hira","Kana","Knda","Khmr","Laoo","Latn","Mlym","Mymr","Orya","Sinh","Taml","Telu","Thaa","Thai","Tibt"].map(i=>`\\p{Script=${i}}`).join("")}]*$`;rs=new RegExp(t,"u")}return rs.test(e)}function Ye(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)||Nn.test(e)?!0:Ha(e)?/^[\p{XIDS}_]\p{XIDC}*$/u.test(e):!1}var Kc="\\u{FE0F}",Qc="\\u{20E3}",ef="\\u{200D}",nf="\\p{RI}\\p{RI}",tf="(?:[\\u{E0020}-\\u{E007E}]+\\u{E007F})",Za=`(?:\\p{EMod}|${Kc}${Qc}?|${tf})`,rf="(?:(?=\\P{XIDC})(?=[^\\x23\\x2a\\x30-\\x39])\\p{Emoji})",Ua=`(?:${rf}${Za}*|\\p{Emoji}${Za}+|${nf})`,Wa=`(?:${Ua})(${ef}${Ua})*`,sf=new RegExp(`(?:${Wa})+`,"u"),Nn=new RegExp(`^(?:${Wa})+$`,"u");function ss(e){return typeof e!="string"?"not-a-string":e===""?"empty-string":e.normalize()!==e?"expected-nfc":/[\u200E\u200F\u2066-\u2069\u202A-\u202E]/.test(e)?"unexpected-bidi-marker":Nn.test(e)?"valid":/\p{XIDC}/u.test(e)&&sf.test(e)?"unexpected-mixed-emoji":Ha(e)?Ye(e)?"valid":Ye(e[0])?"invalid-char":"invalid-first-char":"unexpected-script"}var Hn=null;function af(){if(!Hn){Hn=new Map;for(let[e,n]of He)Hn.has(n)||Hn.set(n,e)}return Hn}var Ya={"\\mathord":"","\\mathop":"","\\mathbin":"","\\mathrel":"","\\mathopen":"","\\mathclose":"","\\mathpunct":"","\\mathinner":"","\\operatorname":"","\\text":"","\\mathrm":"_upright","\\mathit":"_italic","\\mathbf":"_bold","\\bold":"_bold","\\boldsymbol":"_bold","\\bm":"_bold","\\mathscr":"_script","\\mathcal":"_calligraphic","\\mathfrak":"_fraktur","\\mathsf":"_sansserif","\\mathtt":"_monospace","\\mathbb":"_doublestruck"},uf={"\\mathring":"_ring","\\hat":"_hat","\\tilde":"_tilde","\\vec":"_vec","\\overline":"_bar","\\underline":"_underbar","\\dot":"_dot","\\ddot":"_ddot","\\dddot":"_dddot","\\ddddot":"_ddddot","\\acute":"_acute","\\grave":"_grave","\\breve":"_breve","\\check":"_check"};function Xa(e,n){if(e.atEnd)return null;let t=e.peek,i={"\\_":"_","\\#":"hash"}[t];if(!i&&!n.toplevel&&(i={"+":"plus","-":"minus","\\plusmn":"pm","\\pm":"pm","\\ast":"ast","\\dag":"dag","\\ddag":"ddag","\\bot":"bottom","\\top":"top","\\bullet":"bullet","\\cir":"circle","\\diamond":"diamond","\\times":"times","\\square":"square","\\star":"star"}[t]),i)return e.nextToken(),i;let r=af().get(t);if(r!==void 0)return e.nextToken(),r;let s=e.parseChar();if(s!==null)return/^\p{XIDC}+$/u.test(s)?s:[...s].length===1?"____"+s.codePointAt(0).toString(16).toUpperCase().padStart(6,"0"):s;let o=e.peek;return o&&/^[\p{XIDC}\p{M}]/u.test(o)?e.nextToken():null}function Wn(e){let n=os(e),t=uf[e.peek]??null;if(t){if(e.nextToken(),!e.match("<{>"))return null;let s=Wn(e);if(s===null||!e.match("<}>"))return null;n=`${s}${t}`}if(n===null){for(n="";!e.atEnd;){let s=e.peek;if(s==="<}>"||s==="_"||s==="^")break;if(s==="<space>"){e.nextToken();continue}if(Nn.test(n+s)){n+=e.nextToken();continue}let o=Xa(e,{toplevel:!1});if(o===null)return null;n+=o}for(;!e.atEnd&&/\d/.test(e.peek);)n+=e.nextToken()}for(;!e.atEnd;)if(e.match("\\degree"))n+="_deg";else if(e.matchAll(["^","\\circ"]))n+="_deg";else if(e.matchAll(["^","\\prime"]))n+="_prime";else if(e.matchAll(["^","<{>","\\prime","<}>"]))n+="_prime";else if(e.matchAll(["^","<{>","\\doubleprime","<}>"]))n+="_dprime";else if(e.matchAll(["^","<{>","\\prime","\\prime","<}>"]))n+="_dprime";else break;let i=[],r=[];for(;!e.atEnd;)if(e.match("_")){let s=e.match("<{>"),o=Wn(e);if(s&&!e.match("<}>")||o===null)return null;r.push(o)}else if(e.match("^")){let s=e.match("<{>"),o=Wn(e);if(s&&!e.match("<}>")||o===null)return null;i.push(o)}else break;return i.length>0&&(n+="__"+i.join("")),r.length>0&&(n+="_"+r.join("")),n}function os(e){let n=Ya[e.peek]??null;if(n===null)return null;let t=e.index;if(e.nextToken(),e.match("<{>")){let i="",r={0:"zero",1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine"}[e.peek]??"";r&&(i=r,e.nextToken());let s=Wn(e);return s===null||!e.match("<}>")?(e.index=t,null):(i+=s,n==="_upright"&&i.length>1?i:i+n)}return e.index=t,null}function as(e){let n=e.index,t=os(e);if(t!==null)return Ye(t)?null:e.error(["invalid-symbol",{str:ss(t)}],n);if(e.index=n,(Ya[e.peek]??null)===null)return null;if(e.nextToken(),!e.match("<{>"))return e.index=n,null;let r=e.index,s=0;for(;!e.atEnd&&!(s===0&&e.peek==="<}>");)e.peek==="<{>"&&(s+=1),e.peek==="<}>"&&(s-=1),e.nextToken();let o=e.latex(r,e.index);return Ye(o)?(e.index=n,null):(e.match("<}>"),e.error(["invalid-symbol",{str:ss(o)}],n))}function Yn(e){if(/^[a-zA-Z]$/.test(e.peek)||/^\p{XIDS}$/u.test(e.peek)){let i=e.nextToken(),s=e.getSymbolType(i).matches("indexed_collection"),o=e.hasSubscriptEvaluate(i);for(;!e.atEnd&&!s&&!o&&e.peek==="_";){let u=e.index;if(e.nextToken(),e.match("<{>")){let f=e.peek;if(f==="("||f==="\\lparen"||f==="\\left"){e.index=u;break}let p=Wn(e);if(p===""&&e.peek==="<}>"){e.match("<}>");continue}let g=p!==null&&/plus|minus|times|ast/.test(p);if(p===null||p.includes(",")||g||e.peek!=="<}>"){e.index=u;break}e.match("<}>"),i+="_"+p}else{let f=e.peek;if(e.options.strict===!1&&/^[0-9]$/.test(f)){let p="";for(;!e.atEnd&&/^[0-9]$/.test(e.peek);)p+=e.peek,e.nextToken();i+="_"+p}else if(/^[a-zA-Z0-9]$/.test(f)||/^\p{XIDS}$/u.test(f))e.nextToken(),i+="_"+f;else{e.index=u;break}}}return i}let n=os(e);if(!n){for(n="";!e.atEnd&&Nn.test(n+e.peek);)n+=e.nextToken();n||(n=null)}let t=e.index;return n??=Xa(e,{toplevel:!0}),n&&(n=n.normalize(),Ye(n))?n:(e.index=t,null)}function lf(e){let n=!!e.matchAny(["-","\u2212"]);for(;e.matchAny(["+","\uFE62"])||e.skipSpace();)e.matchAny(["-","\u2212"])&&(n=!n);return n?"-":"+"}function Ce(e,n,t="whole"){let i=[],r=!1;for(;!r;){for(;/^[0-9]$/.test(e.peek);)i.push(e.nextToken()),e.skipVisualSpace();r=!0;let s=t==="whole"?n.wholeDigitGroupSeparatorTokens:n.fractionalDigitGroupSeparatorTokens;if(t!=="none"){let o=e.index;e.skipVisualSpace();let a=n.decimalSeparatorTokens.length===3&&n.decimalSeparatorTokens[0]==="<{>"&&n.decimalSeparatorTokens[1]===","&&n.decimalSeparatorTokens[2]==="<}>";s.length>0&&e.matchAll(s)||!a&&e.matchAll(["<{>",",","<}>"])?(e.skipVisualSpace(),/^[0-9]$/.test(e.peek)?r=!1:e.index=o):e.index=o}}return i.join("")}function us(e,n,t){let i=e.index,r=lf(e),s=Ce(e,n,t);return s?r==="-"?"-"+s:s:(e.index=i,"")}function cf(e,n){let t=e.index;if(e.skipVisualSpace(),e.matchAny(["e","E"])){let i=us(e,n,"none");if(i)return i}if(e.index=t,e.match("\\times")&&(e.skipVisualSpace(),e.matchAll(["1","0"])&&(e.skipVisualSpace(),e.match("^")))){if(e.skipVisualSpace(),/^[0-9]$/.test(e.peek))return e.nextToken();if(e.match("<{>")){e.skipVisualSpace();let i=us(e,n,"whole");if(e.skipVisualSpace(),i&&e.match("<}>"))return i}}if(e.index=t,e.skipVisualSpace(),e.match("\\%"))return"-2";if(e.index=t,e.matchAll(n.exponentProductTokens)&&(e.skipVisualSpace(),e.matchAll(n.beginExponentMarkerTokens))){e.skipVisualSpace();let i=us(e,n,"none");if(e.skipVisualSpace(),i&&e.matchAll(n.endExponentMarkerTokens))return i}return e.index=t,""}function Ka(e){let n=e.index;if(e.matchAll(["\\overset","<{>"])&&(e.match(".")||e.match("\\cdots"))&&e.matchAll(["<}>","<{>"])){let t=e.nextToken();if(t&&/^\d$/.test(t)&&e.match("<}>"))return t}return e.index=n,null}function ff(e){let n=e.length;for(let t=1;t<=n>>1;t++){let i=e.slice(n-t),r=1;for(;(r+1)*t<=n&&e.startsWith(i,n-(r+1)*t);)r+=1;if(r>=(t===1?3:2))return[e.slice(0,n-r*t),i]}return null}function pf(e){let n=e.peek;return n==="\\overline"||n==="\\overset"||n==="\\wideparen"||n==="\\overarc"||n==="("||n==="\\left"}function cs(e,n){let t=e.index,i=e.options.repeatingDecimal,r="";if((i==="auto"||i==="parentheses")&&e.match("("))return r=Ce(e,n,"fraction"),r&&e.match(")")?`(${r})`:(e.index=t,"");if(e.index=t,(i==="auto"||i==="parentheses")&&e.matchAll(["\\left","("]))return r=Ce(e,n,"fraction"),r&&e.matchAll(["\\right",")"])?`(${r})`:(e.index=t,"");if(e.index=t,(i==="auto"||i==="vinculum")&&e.matchAll(["\\overline","<{>"]))return r=Ce(e,n,"fraction"),r&&e.match("<}>")?`(${r})`:(e.index=t,"");if(e.index=t,(i==="auto"||i==="arc")&&(e.matchAll(["\\wideparen","<{>"])||e.matchAll(["\\overarc","<{>"])))return r=Ce(e,n,"fraction"),r&&e.match("<}>")?`(${r})`:(e.index=t,"");if(e.index=t,i==="auto"||i==="dots"){let s=Ka(e);if(s!==null){if(r=Ce(e,n,"fraction"),!r)return`(${s})`;let o=Ka(e);if(o!==null)return`(${s}${r}${o})`}}return e.index=t,""}function ls(e){return e===0?{num:"0"}:Number.isInteger(e)&&Math.abs(e)<Le?e:{num:e.toString()}}function Qa(e,n){let t=e.options.parseNumbers;if(t===!1||t==="never")return null;let i=e.index;e.skipVisualSpace();let r=1;for(;e.peek==="-"||e.peek==="+";)e.match("-")?r=-r:e.match("+"),e.skipVisualSpace();let s="",o="",a=!1;if(e.match(".")||e.matchAll(n.decimalSeparatorTokens)){let g=e.peek;(/^[\d]$/.test(g)||pf(e))&&(a=!0,s="0")}else s=Ce(e,n,"whole");if(!s)return e.index=i,null;let u=e.index,l=!1;(a||e.match(".")||e.matchAll(n.decimalSeparatorTokens))&&(o=Ce(e,n,"fraction"),l=!0);let f=!1;if(l){let g=cs(e,n);if(g&&(o+=g,f=!0),(e.match("\\ldots")||e.matchAll(n.truncationMarkerTokens))&&!f){let h=ff(o);h&&(o=`${h[0]}(${h[1]})`,f=!0)}}if(l&&!o){let g=e.peek,h=typeof g=="string"&&(/^[a-zA-Z]$/.test(g)||g==="\\operatorname"||g==="\\max"||g==="\\min"||g===".");return(a||h)&&(e.index=u),s.length<10?ls(r*parseInt(s,10)):{num:r<0?"-"+s:s}}let p=cf(e,n);if(!l&&!p&&s.length<10)return ls(r*parseInt(s,10));if(!f&&e.options.parseNumbers==="rational"){let g=s.length>16||s.length===16&&s>"9007199254740991";if(!o){if(g){let U=r<0?"-"+s:s;return p?["Multiply",{num:U},["Power",10,p]]:{num:U}}let H=parseInt(s,10);return p?["Multiply",r*H,["Power",10,p]]:ls(r*H)}let h=o.length;if(s.length+h>15){let H=BigInt(s),U=BigInt(o),J=BigInt(10)**BigInt(h),Xe=H*J+U,Ke=r<0?-Xe:Xe;return p?["Multiply",["Rational",{num:Ke.toString()},Number(J)],["Power",10,p]]:["Rational",{num:Ke.toString()},Number(J)]}let I=parseInt(s,10),F=parseInt(o,10),B=I*10**h+F,q=10**h;return p?["Multiply",["Rational",r*B,q],["Power",10,p]]:["Rational",r*B,q]}return{num:(r<0?"-":"")+s+(l?"."+o:"")+(p?"e"+p:"")}}function ru(e,n){return e===null?!1:typeof e=="string"?e===n||e.split("_").includes(n):Array.isArray(e)?e.some(t=>ru(t,n)):!1}function fs(e,n){if(typeof e=="string"){let t=e.indexOf("_");return t>0&&e.substring(t+1)===n?[e.substring(0,t)+"_",n]:e}return Array.isArray(e)?d(e)==="Subscript"&&typeof c(e,1)=="string"&&ru(c(e,2),n)?[c(e,1)+"_",fs(c(e,2),n)]:[e[0],...e.slice(1).map(t=>fs(t,n))]:e}function mf(e){if(e==="NonNegativeIntegers")return 0;if(e==="PositiveIntegers")return 1}function df(e){let n,t=e;if(d(e)==="Power"&&(n=c(e,2)??void 0,t=c(e,1)),t===null||d(t)!=="Subscript")return e;let i=c(t,1);if(i===null||d(i)!=="Set"||(b(i)?.length??0)!==1)return e;let r=c(t,2);if(r===null)return e;let s,o;if(d(r)==="Equal"){let u=c(r,1);if(typeof u!="string")return e;s=u,o=c(r,2)??void 0}else if(d(r)==="Element"){let u=c(r,1);if(typeof u!="string")return e;let l=mf(c(r,2));if(l===void 0)return e;s=u,o=l}else return e;if(s===void 0||o===void 0)return e;let a=fs(c(i,1),s);return n===void 0?["IndexedSequence",a,s,o]:["IndexedSequence",a,s,o,n]}var gf=new Set([...'!"#$%&(),/;:?@[]\\`|~'.split(""),"\\left","\\bigl","\\mleft"]),hf=new Set(["\\!","\\,","\\:","\\;","\\enskip","\\enspace","\\space","\\quad","\\qquad"]),bf=["pt","em","mu","ex","mm","cm","in","bp","sp","dd","cc","pc","nc","nd"].map(e=>[...e]),ai={sin:"Sin",cos:"Cos",tan:"Tan",cot:"Cot",sec:"Sec",csc:"Csc",sinh:"Sinh",cosh:"Cosh",tanh:"Tanh",coth:"Coth",sech:"Sech",csch:"Csch",arcsin:"Arcsin",arccos:"Arccos",arctan:"Arctan",arccot:"Arccot",arcsec:"Arcsec",arccsc:"Arccsc",asin:"Arcsin",acos:"Arccos",atan:"Arctan",acot:"Arccot",asec:"Arcsec",acsc:"Arccsc",atan2:"Arctan2",arcsinh:"Arsinh",arccosh:"Arcosh",arctanh:"Artanh",arccoth:"Arcoth",arcsech:"Arsech",arccsch:"Arcsch",asinh:"Arsinh",acosh:"Arcosh",atanh:"Artanh",log:"Log",ln:"Ln",exp:"Exp",lg:"Lg",lb:"Lb",sqrt:"Sqrt",abs:"Abs",sgn:"Sgn",sign:"Sgn",floor:"Floor",ceil:"Ceil",round:"Round",max:"Max",min:"Min",gcd:"Gcd",lcm:"Lcm",cbrt:"Root",binom:"Binomial",nCr:"Binomial",nPr:"Permutations"},eu={"<space>":" ","<$$>":"$$","<$>":"$","<{>":"{","<}>":"}"},ui=null;function yf(){if(!ui){ui=new Map;for(let[,e,n]of He)ui.set(e,String.fromCodePoint(n))}return ui}var nu={"(":["\\lparen","("],")":["\\rparen",")"],"[":["\\lbrack","\\[","["],"]":["\\rbrack","\\]","]"],"<":["<","\\langle"],">":[">","\\rangle"],"{":["\\{","\\lbrace"],"}":["\\}","\\rbrace"],":":[":","\\colon"],"|":["|","\\|","\\lvert","\\rvert"],"||":["||","\\Vert","\\lVert","\\rVert","\\|"]},En={"\\left":"\\right","\\bigl":"\\bigr","\\Bigl":"\\Bigr","\\biggl":"\\biggr","\\Biggl":"\\Biggr","\\big":"\\big","\\Big":"\\Big","\\bigg":"\\bigg","\\Bigg":"\\Bigg","\\mathopen":"\\mathclose","\\mleft":"\\mright"},tu=new Set(Object.values(En)),ps={"(":")","[":"]","|":"|","\\{":"\\}","\\[":"\\]","\\lbrace":"\\rbrace","\\lparen":"\\rparen","\\langle":"\\rangle","\\lfloor":"\\rfloor","\\lceil":"\\rceil","\\vert":"\\vert","\\lvert":"\\rvert","\\Vert":"\\Vert","\\lVert":"\\rVert","\\|":"\\|","\\lbrack":"\\rbrack","\\ulcorner":"\\urcorner","\\llcorner":"\\lrcorner","\\lgroup":"\\rgroup","\\lmoustache":"\\rmoustache","\\llbracket":"\\rrbracket"};function xf(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e instanceof G)return"BoxedType";if(typeof e=="string")return`"${e}"`;if(typeof e=="object"){let n=e.constructor?.name;return n&&n!=="Object"?n:"object"}return`${typeof e} (${String(e)})`}var iu=class e{options;_index=0;symbolTable={parent:null,ids:{}};pushSymbolTable(){this._symbolTableGen+=1,this.symbolTable={parent:this.symbolTable,ids:{}}}popSymbolTable(){this._symbolTableGen+=1,this.symbolTable=this.symbolTable.parent??this.symbolTable}addSymbol(n,t){if(this._symbolTableGen+=1,typeof t=="string"&&(t=new G(t)),n in this.symbolTable.ids&&!this.symbolTable.ids[n].is(t.type))throw new Error(`Symbol ${n} already declared as a different type`);this.symbolTable.ids[n]=t}_reversedIntervalDepth=0;_quantifierScopeDepth=0;get inQuantifierScope(){return this._quantifierScopeDepth>0}enterQuantifierScope(){this._quantifierScopeDepth++}exitQuantifierScope(){this._quantifierScopeDepth>0&&this._quantifierScopeDepth--}get index(){return this._index}set index(n){if(this.diagnostics!==null&&this.diagnostics.length>0&&n<this._index){let i=this.tokenPrefixOffsets()[Math.max(0,Math.min(n,this._tokens.length))],r=this.diagnostics,s=0;for(let o=0;o<r.length;o++)r[o].start>=i||(r[s++]=r[o]);r.length=s}this._index=n,this._lastPeek="",this._peekCounter=0}_tokens;_positiveInfinityTokens;_negativeInfinityTokens;_notANumberTokens;_decimalSeparatorTokens;_wholeDigitGroupSeparatorTokens;_fractionalDigitGroupSeparatorTokens;_exponentProductTokens;_beginExponentMarkerTokens;_endExponentMarkerTokens;_truncationMarkerTokens;_imaginaryUnitTokens;_dictionary;_boundaries=[];_lastPeek="";_peekCounter=0;_lookAheadCache=null;_lookAheadIndex=-1;_tokenPrefixOffsets=null;_symbolTableGen=0;_symCandidateIndex=-1;_symCandidateGen=-1;_symCandidate=null;_symCandidateCount=0;diagnostics;_diagnosticSeq=0;emitDiagnostic(n,t,i,r){if(this.diagnostics===null)return;let[s,o]=this.sourceOffsets(t,i),a=this._diagnosticSeq++;this.diagnostics.push(r!==void 0?{code:n,start:s,end:o,detail:r,_seq:a}:{code:n,start:s,end:o,_seq:a})}diagnosticsCheckpoint(){return this._diagnosticSeq}rollbackDiagnostics(n){if(this.diagnostics===null)return;let t=this.diagnostics,i=0;for(let r=0;r<t.length;r++)t[r]._seq<n&&(t[i++]=t[r]);t.length=i}pruneUndeclared(n,t,i,r){if(this.diagnostics===null)return;let s=n instanceof Set?n:new Set(n);if(s.size===0)return;if(this.options.onBoundVariable)for(let h of s)this.options.onBoundVariable(h);let o=this.tokenPrefixOffsets(),a=this._tokens.length,u=h=>o[Math.max(0,Math.min(h,a))],l=i===void 0?-1/0:u(i),f=(r??[]).map(([h,N])=>[u(h),u(N)]),p=this.diagnostics,g=0;for(let h=0;h<p.length;h++){let N=p[h],I=N.detail?.name;if(N.code==="undeclared-symbol"&&N._seq>=t&&typeof I=="string"&&s.has(I)){let B=N.start>=l,q=f.some(([H,U])=>N.start>=H&&N.start<U);if(B||q)continue}p[g++]=N}p.length=g}pruneJuxtaposition(n,t){if(this.diagnostics===null)return;let i=this.diagnostics,r=0;for(let s=0;s<i.length;s++){let o=i[s];o.code==="juxtaposition-as-multiply"&&o._seq>=t&&o.detail?.name===n||(i[r++]=o)}i.length=r}get operandDiagnosticCheckpoint(){return this._operandDiagnosticCheckpoint}_operandDiagnosticCheckpoint=0;isSymbolDeclared(n){let t=this.symbolTable;for(;t;){if(n in t.ids)return!0;t=t.parent}return this.options.isSymbolDeclared?.(n)?!0:!this.getSymbolType(n).isUnknown}emitSymbolReference(n,t,i){this.diagnostics!==null&&(this.isSymbolDeclared(n)||this.emitDiagnostic("undeclared-symbol",t,i,{name:n,type:this.getSymbolType(n).toString()}))}constructor(n,t,i){this._tokens=n,this.options=i,this._dictionary=t,this.diagnostics=i.diagnostics?[]:null,this._positiveInfinityTokens=ne(this.options.positiveInfinity),this._negativeInfinityTokens=ne(this.options.negativeInfinity),this._notANumberTokens=ne(this.options.notANumber),this._decimalSeparatorTokens=ne(this.options.decimalSeparator),this._wholeDigitGroupSeparatorTokens=[],this._fractionalDigitGroupSeparatorTokens=[],this.options.digitGroupSeparator&&(typeof this.options.digitGroupSeparator=="string"?(this._wholeDigitGroupSeparatorTokens=ne(this.options.digitGroupSeparator),this._fractionalDigitGroupSeparatorTokens=this._wholeDigitGroupSeparatorTokens):Array.isArray(this.options.digitGroupSeparator)&&(this._wholeDigitGroupSeparatorTokens=ne(this.options.digitGroupSeparator[0]),this._fractionalDigitGroupSeparatorTokens=ne(this.options.digitGroupSeparator[1]))),this._exponentProductTokens=ne(this.options.exponentProduct),this._beginExponentMarkerTokens=ne(this.options.beginExponentMarker),this._endExponentMarkerTokens=ne(this.options.endExponentMarker),this._truncationMarkerTokens=ne(this.options.truncationMarker),this._imaginaryUnitTokens=ne(this.options.imaginaryUnit),this._numberFormatTokens={decimalSeparatorTokens:this._decimalSeparatorTokens,wholeDigitGroupSeparatorTokens:this._wholeDigitGroupSeparatorTokens,fractionalDigitGroupSeparatorTokens:this._fractionalDigitGroupSeparatorTokens,exponentProductTokens:this._exponentProductTokens,beginExponentMarkerTokens:this._beginExponentMarkerTokens,endExponentMarkerTokens:this._endExponentMarkerTokens,truncationMarkerTokens:this._truncationMarkerTokens}}_numberFormatTokens;getSymbolType(n){let t=this.symbolTable;for(;t;){if(n in t.ids)return t.ids[n];t=t.parent}if(this.options.getSymbolType){let i=this.options.getSymbolType(n);if(i instanceof G)return i;if(typeof i=="string")try{return new G(i)}catch(r){let s=r instanceof Error?r.message:String(r);throw new Error(`ce.parse(): getSymbolType("${n}") returned invalid type string "${i}". ${s}`)}throw new Error(`ce.parse(): getSymbolType("${n}") must return a BoxedType or a type string, received ${xf(i)}`)}return G.unknown}hasSubscriptEvaluate(n){return this.options.hasSubscriptEvaluate?this.options.hasSubscriptEvaluate(n):!1}get peek(){let n=this._tokens[this.index];if(n===this._lastPeek?this._peekCounter+=1:this._peekCounter=0,this._peekCounter>=1024){let t=`Infinite loop detected while parsing "${this.latex(0)}" at "${this._lastPeek}" (index ${this.index})`;throw console.error(t),new Error(t)}return this._lastPeek=n,n}nextToken(){return this._tokens[this.index++]}get atEnd(){return this.index>=this._tokens.length}atTerminator(n){return this.atBoundary||((n?.condition&&n.condition(this))??!1)}get atBoundary(){if(this.atEnd)return!0;let n=this.index;for(let t of this._boundaries)if(this.matchBoundaryTokens(t.tokens))return this.index=n,!0;return!1}matchBoundaryTokens(n){return this.matchAll(n)?!0:n.length===2&&tu.has(n[0])&&this._tokens[this.index]===n[0]&&this._tokens[this.index+1]==="."?(this.index+=2,!0):!1}addBoundary(n){this._boundaries.push({index:this.index,tokens:n})}removeBoundary(){this._boundaries.pop()}matchBoundary(){let n=this._boundaries[this._boundaries.length-1],t=n&&this.matchBoundaryTokens(n.tokens);return t&&this._boundaries.pop(),t}boundaryError(n){let t=this._boundaries[this._boundaries.length-1];return this._boundaries.pop(),this.error(n,t.index)}canSkipMatchfixReparsing(n,t,i){return i||t.length!==1?!1:(n==="("||n==="\\lparen")&&(t[0]==="]"||t[0]==="\\rbrack")||(n==="]"||n==="\\rbrack")&&(t[0]==="["||t[0]==="\\lbrack")}latex(n,t){return ln(this._tokens.slice(n,t))}sourceOffsets(n,t=this.index){let i=this.tokenPrefixOffsets(),r=this._tokens.length,s=i[Math.max(0,Math.min(n,r))],o=i[Math.max(0,Math.min(t,r))];return s<=o?[s,o]:[o,s]}tokenPrefixOffsets(){if(this._tokenPrefixOffsets!==null)return this._tokenPrefixOffsets;let n=this._tokens,t=new Array(n.length+1);t[0]=0;let i=0,r="";for(let s=0;s<n.length;s++){let o=eu[n[s]]??n[s];/[a-zA-Z]/.test(o[0])&&(i+=r.length),r=/\\[a-zA-Z]+\*?$/.test(o)?" ":"",i+=o.length,t[s+1]=i}return this._tokenPrefixOffsets=t,t}lookAhead(){if(this._lookAheadIndex===this.index&&this._lookAheadCache!==null)return this._lookAheadCache;let n=this._dictionary.triggerStartMax.get(this._tokens[this.index])??0,t=Math.min(n,this._tokens.length-this.index),i=[],r="",s="";for(let o=0;o<t;o++){let a=this._tokens[this.index+o],u=eu[a]??a;/[a-zA-Z]/.test(u[0])&&(r+=s),s=/\\[a-zA-Z]+\*?$/.test(u)?" ":"",r+=u,i[t-1-o]=[o+1,r]}return this._lookAheadCache=i,this._lookAheadIndex=this.index,i}peekDefinitions(n){if(this.atEnd)return[];let t=[],i=this._dictionary,r;switch(n){case"infix":r=i.infixByTrigger;break;case"prefix":r=i.prefixByTrigger;break;case"postfix":r=i.postfixByTrigger;break;case"function":r=i.functionByTrigger;break;case"symbol":r=i.symbolByTrigger;break;case"expression":r=i.expressionByTrigger;break;case"operator":r=i.operatorByTrigger;break}let s=i.universalDefs.get(n);if(s)for(let a of s)t.push([a,0]);for(let[a,u]of this.lookAhead()){let l=r.get(u);if(l)for(let f of l)t.push([f,a])}let o=i.symbolTriggerDefs.get(n);if(o){let a,u;if(this._symCandidateIndex===this.index&&this._symCandidateGen===this._symbolTableGen)a=this._symCandidate,u=this._symCandidateCount;else{let l=this.index;a=Yn(this)?.trim()??null,u=this.index-l,this.index=l,this._symCandidateIndex=l,this._symCandidateGen=this._symbolTableGen,this._symCandidate=a,this._symCandidateCount=u}if(a&&u>0){let l=o.get(a);if(l)for(let f of l)t.push([f,u])}}return t}skipSpaceTokens(){for(;this.match("<space>"););}skipSpace(){if(!this.atEnd&&this.peek==="<{>"){let t=this.index;for(this.nextToken();this.match("<space>"););if(this.nextToken()==="<}>")return this.skipSpace(),!0;this.index=t}if(!this.options.skipSpace)return!1;let n=!1;for(;this.match("<space>");)n=!0;return n&&this.skipSpace(),n}skipVisualSpace(){if(this.options.skipSpace){if(this.skipSpace(),hf.has(this.peek)&&(this.nextToken(),this.skipVisualSpace()),this.match("\\hspace")&&(this.match("*"),this.parseStringGroup(),this.skipVisualSpace()),this.match("\\hskip")||this.match("\\kern")){for(this.skipSpace(),this.match("-")||this.match("+");/^[\d.]$/.test(this.peek);)this.nextToken();for(let n of bf)if(this.matchAll(n))break;this.skipVisualSpace()}this.skipSpace()}}match(n){return this._tokens[this.index]!==n?!1:(this.index++,!0)}matchAll(n){if(n.length===0)return!1;let t,i=0;do t=this._tokens[this.index+i]===n[i++];while(t&&i<n.length);return t&&(this.index+=i),t}matchAny(n){return n.includes(this._tokens[this.index])?this._tokens[this.index++]:""}parseLatexNumber(n=!0){let t=!1,i=this.peek;for(;i==="<space>"||i==="+"||i==="-";)i==="-"&&(t=!t),this.nextToken(),i=this.peek;let r=10,s=["0","1","2","3","4","5","6","7","8","9"];if(this.match("'"))r=8,s=["0","1","2","3","4","5","6","7"],n=!0;else if(this.match('"')||this.match("x"))r=16,s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],n=!0;else if(this.match("`"))return i=this.nextToken(),i?i.startsWith("\\")&&i.length===2?(t?-1:1)*(i.codePointAt(1)??0):(t?-1:1)*(i.codePointAt(0)??0):null;let o="";for(;s.includes(this.peek);)o+=this.nextToken();if(!n&&this.match("."))for(o+=".";s.includes(this.peek);)o+=this.nextToken();let a=n?Number.parseInt(o,r):Number.parseFloat(o);return Number.isNaN(a)?null:t?-a:a}parseChar(){let n=this.index,t=0;for(;this.match("^");)t+=1;if(t<2&&(this.index=n),t>=2){let i="",r=0;for(;r!=t;){let s=this.matchAny(["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]);if(!s)break;i+=s,r+=1}if(i.length===t)return String.fromCodePoint(Number.parseInt(i,16))}else if(this.match("\\char")){let i=Math.floor(this.parseLatexNumber()??Number.NaN);return(!Number.isFinite(i)||i<0||i>1114111)&&(i=10067),String.fromCodePoint(i)}else if(this.match("\\unicode"))if(this.skipSpaceTokens(),this.match("<{>")){let i=this.parseLatexNumber();if(this.match("<}>")&&i!==null&&i>=0&&i<=1114111)return String.fromCodePoint(i)}else{let i=this.parseLatexNumber();if(i!==null&&i>=0&&i<=1114111)return String.fromCodePoint(i)}return this.index=n,null}matchDelimiter(n,t){let i=this.index,r=En[this.peek];r&&this.nextToken();let s=r&&this.peek==="<{>";if(s&&this.nextToken(),Array.isArray(n)){if(Array.isArray(t),n.length===1){if(!(nu[n[0]]??[n[0]]).includes(this.peek))return this.index=i,!1;if(this.nextToken(),s&&!this.match("<}>"))return this.index=i,!1;let f=t[0],p=r?s?[r,"<{>",f,"<}>"]:[r,f]:[f];return this.addBoundary(p),!0}if(!this.matchAll(n))return this.index=i,!1;let u=r?[r,...t]:t;return this.addBoundary(u),!0}if(Array.isArray(t),n==="||"&&this.matchAll(["|","|"]))return this.addBoundary(["|","|"]),!0;if(!(nu[n]??[n]).includes(this.peek))return this.index=i,!1;if(n=this.nextToken(),s&&!this.match("<}>"))return this.index=i,!1;let o=ps[n]??t,a=r?s?[r,"<{>",o,"<}>"]:[r,o]:[o];return this.addBoundary(a),!0}parseGroup(){let n=this.index;if(this.skipSpaceTokens(),this.match("<{>")){this.addBoundary(["<}>"]);let t=this.parseExpression();if(this.skipSpace(),this.matchBoundary())return t??"Nothing";for(;!this.matchBoundary()&&!this.atEnd;)this.nextToken();if(d(t)==="Error")return t;let i=this.error("expected-closing-delimiter",n);return t!==null?["InvisibleOperator",t,i]:i}return this.index=n,null}parseOptionalGroup(){let n=this.index;if(this.skipSpaceTokens(),this.match("[")){this.addBoundary(["]"]);let t=this.parseExpression();return this.skipSpace(),this.matchBoundary()?t:this.boundaryError("expected-closing-delimiter")}return this.index=n,null}parseToken(){return this.skipSpace(),gf.has(this.peek)?null:/^[0-9]$/.test(this.peek)?parseInt(this.nextToken(),10):this.parseGenericExpression()??this.parseSymbol()}parseTabular(){let n=[],t=[],i=null;for(;!this.atBoundary;)if(this.skipSpace(),this.match("&"))t.push(i??"Nothing"),i=null;else if(this.match("\\\\")||this.match("\\cr"))this.skipSpace(),this.parseOptionalGroup(),i!==null&&t.push(i),n.push(t),t=[],i=null;else{let r=[],s=this.peek;for(;s!=="&"&&s!=="\\\\"&&s!=="\\cr"&&!this.atBoundary;)i=this.parseExpression({minPrec:0,condition:o=>{let a=o.peek;return a==="&"||a==="\\\\"||a==="\\cr"}}),i!==null?r.push(i):(r.push(["Error","'unexpected-token'",{str:ln(s)}]),this.nextToken()),this.skipSpace(),s=this.peek;r.length>1?i=["Sequence",...r]:i=r[0]??"Nothing"}return i!==null&&t.push(i),t.length>0&&n.push(t),n}parseStringGroupContent(){let n=this.index,t="",i=0;for(;!this.atEnd&&(!this.atBoundary||i>0);){let r=this.nextToken();if(r==="<$>"||r==="<$$>")return this.index=n,"";if(r==="<{>")i+=1,t+="\\{";else if(r==="<}>")i-=1,t+="\\}";else if(r==="<space>")t+=" ";else if(r[0]==="\\"){let s=yf().get(r);t+=s??r}else t+=r}return t}parseStringGroup(n,t){n===void 0&&(n=!1);let i=this.index;for(;this.match("<space>"););if(this.match(n?"[":"<{>")){let r=this.index;this.addBoundary([n?"]":"<}>"]);let s=this.parseStringGroupContent();if(this.matchBoundary())return t&&t.push(...this._tokens.slice(r,this.index-1)),s;this.removeBoundary()}return this.index=i,null}parseDoubleQuoteString(){if(this.peek!=='"')return null;let n=this.index;this.nextToken(),this.addBoundary(['"']);let t=this.parseStringGroupContent();return this.matchBoundary()?{str:t}:(this.removeBoundary(),this.error("expected-closing-delimiter",n))}parseEnvironment(n){let t=this.index;if(!this.match("\\begin"))return null;let i=[],r=this.parseStringGroup(!1,i)?.trim();if(!r)return this.error("expected-environment-name",t);for(;i[0]==="<space>";)i.shift();for(;i[i.length-1]==="<space>";)i.pop();this.addBoundary(["\\end","<{>",...i,"<}>"]);for(let s of this.getDefs("environment"))if(s.symbolTrigger===r){let o=s.parse(this,n);return this.skipSpace(),this.matchBoundary()?o!==null?this.decorate(o,t):(this.index=t,null):this.boundaryError("unbalanced-environment")}return this.parseTabular(),this.skipSpace(),this.matchBoundary()?this.error(["unknown-environment",{str:r}],t):this.boundaryError("unbalanced-environment")}parseRepeatingDecimal(){return cs(this,this._numberFormatTokens)}parseNumber(){return Qa(this,this._numberFormatTokens)}parsePrefixOperator(n){n||(n={minPrec:0}),n.minPrec||(n={...n,minPrec:0});let t=this.index;for(let[i,r]of this.peekDefinitions("prefix")){this.index=t+r;let s=i.parse(this,{...n,minPrec:i.precedence+1});if(s!==null)return s}return this.index=t,null}parseInfixOperator(n,t){t??={minPrec:0},t.minPrec,t.minPrec===void 0&&(t={...t,minPrec:0});let i=this.index;for(let[r,s]of this.peekDefinitions("infix"))if(r.precedence>=t.minPrec){this.index=i+s;let o=r.parse(this,n,t);if(o!==null)return o}if(this.index=i,this.peek==="\\textcolor"){let r=this.parseStyledInfixOperator(n,t);if(r!==null)return r;this.index=i}return null}parseStyledInfixOperator(n,t){let i=this.index;if(!this.match("\\textcolor"))return null;if(this.parseStringGroup()===null)return this.index=i,null;if(this.skipSpace(),!this.match("<{>"))return this.index=i,null;this.skipSpace();let r=this.index;for(let[s,o]of this.peekDefinitions("infix")){if(s.precedence<t.minPrec)continue;if(this.index=r+o,this.skipSpace(),!this.match("<}>")){this.index=r;continue}let a=s.parse(this,n,t);if(a!==null)return a;this.index=r}return this.index=i,null}wouldMatchTextInfix(n){let t=this.index;for(let[i,r]of n){if(i.kind!=="infix")continue;if(this.index=t+r,i.parse(this,"Nothing",{minPrec:0})!==null)return this.index=t,!0}return this.index=t,!1}parseArguments(n="enclosure",t){if(this.atTerminator(t))return null;let i=this.index,r=this.parseEnclosure();if(n==="enclosure")return r===null?null:Ne(r)??[r];if(n==="implicit"){if(d(r)==="Delimiter"){let o=c(r,1);return d(o)==="Sequence"?b(o):o===null?[]:[o]}if(r!==null)return[r];let s=this.parseExpression({...t,minPrec:C});return s===null?null:[s]}return this.index=i,null}parseBraceArguments(){let n=this.index,t=[];for(;this.peek==="<{>";){let i=this.index,r=this.parseGroup();if(r===null||r==="Nothing"){this.index=i;break}t.push(...Ne(r)??[r])}return t.length===0?(this.index=n,null):t}parseEnclosure(){let n=this.index,t=this.peek,i=En[t],r=i?this._tokens[this.index+1]:t;i&&r==="<{>"&&(r=this._tokens[this.index+2]);let s=this._dictionary.matchfixByOpen.get(r)??[];s.length===0&&!r&&(s=[...this.getDefs("matchfix")]);for(let o of s){this.index=n;let a=Array.isArray(o.openTrigger)&&o.openTrigger.length===1&&(o.openTrigger[0]==="]"||o.openTrigger[0]==="\\rbrack")&&Array.isArray(o.closeTrigger)&&o.closeTrigger.length===1&&(o.closeTrigger[0]==="["||o.closeTrigger[0]==="\\lbrack");if(a&&this._reversedIntervalDepth>0)continue;if(o.closeTokens.size>0){let I=!1,F=this._tokens;for(let B=n;B<F.length;B++){if(o.closeTokens.has(F[B])){I=!0;break}if(i&&tu.has(F[B])&&F[B+1]==="."){I=!0;break}}if(!I)continue}if(typeof o.openTrigger=="string"&&o.openTrigger==="."&&!En[t]||!this.matchDelimiter(o.openTrigger,o.closeTrigger))continue;let l=this.index;this.skipSpace(),a&&(this._reversedIntervalDepth+=1);let f=this.parseExpression();a&&(this._reversedIntervalDepth-=1),this.skipSpace();let p=this._boundaries[this._boundaries.length-1]?.tokens,g=this.matchBoundary(),h=typeof o.openTrigger=="string"&&typeof o.closeTrigger=="string"&&o.openTrigger===o.closeTrigger||Array.isArray(o.openTrigger)&&Array.isArray(o.closeTrigger)&&o.openTrigger.length===o.closeTrigger.length&&o.openTrigger.every((I,F)=>I===o.closeTrigger[F]);if(g&&R(f)&&h&&p){if(this.index=l,this.skipSpace(),a&&(this._reversedIntervalDepth+=1),f=this.parseExpression(),a&&(this._reversedIntervalDepth-=1),this.skipSpace(),!this.matchAll(p)){if(this.index=n,!this.atEnd)continue;return null}}else if(!g){let I=this._boundaries[this._boundaries.length-1]?.tokens;if(!I){this.index=n;continue}if(this.canSkipMatchfixReparsing(r,I,h)){this.removeBoundary(),this.index=n;continue}else if(this.removeBoundary(),this.index=l,this.skipSpace(),a&&(this._reversedIntervalDepth+=1),f=this.parseExpression(),a&&(this._reversedIntervalDepth-=1),this.skipSpace(),!this.matchAll(I)){if(this.index=n,!this.atEnd)continue;return null}}let N=o.parse(this,f??"Nothing");if(N!==null)return N}return this.index=n,null}parseGenericExpression(n){if(this.atTerminator(n))return null;let t=this.index,i=null,r=this.peekDefinitions("expression")??[];for(let[s,o]of r)if(this.index=t+o,typeof s.parse=="function"){if(i=s.parse(this,n),i!==null)return i}else return s.name;return this.index=t,null}parseFunction(n){if(this.atTerminator(n))return null;let t=this.index,i=null,r="enclosure";for(let[a,u]of this.peekDefinitions("function"))if(this.index=t+u,typeof a.parse=="function"){if(i=a.parse(this,n),i!==null)return i}else{i=a.name,r=a.arguments??"enclosure";break}let s=!1;if(i===null&&(this.index=t,i=Yn(this),typeof i=="string"&&this.emitSymbolReference(i,t,this.index),!this.isFunctionOperator(i))){if(!this.looksLikePredicate(i))return this.index=t,null;s=!0}do{let a=this.parsePostfixOperator(i,n);if(a===null)break;i=a}while(!0);let o=this.parseArguments(r,n);return o===null?i:s&&typeof i=="string"&&this.inQuantifierScope?["Predicate",i,...o]:typeof i=="string"?[i,...o]:["Apply",i,...o]}parseSymbol(n){if(this.atTerminator(n))return null;let t=this.index;for(let[r,s]of this.peekDefinitions("symbol"))if(this.index=t+s,typeof r.parse=="function"){let o=r.parse(this,n);if(o!==null)return o}else return r.name;this.index=t;let i=Yn(this);return i!==null&&!this.getSymbolType(i).matches("error")?(this.emitSymbolReference(i,t,this.index),i):(this.index=t,null)}peekBareWord(){let n=this.index;for(;this._tokens[n]==="<space>";)n++;let t="";for(;n<this._tokens.length&&/^[a-zA-Z]$/.test(this._tokens[n]);)t+=this._tokens[n],n++;return t}tryParseBareFunction(n){if(this.options.strict!==!1)return null;let t=this.index;if(t>0&&/^[a-zA-Z]$/.test(this._tokens[t-1]))return null;let i="";for(;!this.atEnd&&/^[a-zA-Z]$/.test(this.peek);)i+=this.peek,this.index++;if(!i)return this.index=t,null;if(!this.atEnd&&/^[0-9]$/.test(this.peek)){let l="",f=this.index;for(;f<this._tokens.length&&/^[0-9]$/.test(this._tokens[f]);)l+=this._tokens[f],f++;for(let p=l.length;p>=1;p--)if(ai[i+l.slice(0,p)]!==void 0){i+=l.slice(0,p),this.index+=p;break}}this.skipSpace();let r=null;if(this.peek==="_"){if(this.index++,r=this.parseGroup(),r===null){if(!this.atEnd&&/^[a-zA-Z]$/.test(this.peek))r=this.peek,this.index++;else{let l="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)l+=this.peek,this.index++;l&&(r=parseInt(l))}if(r===null)return this.index=t,null}this.skipSpace()}if(r===null&&i==="log"&&!this.atEnd&&/^[0-9]$/.test(this.peek)){let l="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)l+=this.peek,this.index++;r=parseInt(l),this.skipSpace()}let s=null;if(this.peek==="^"){if(this.index++,s=this.parseGroup(),s===null){let l=!1;this.peek==="-"&&(l=!0,this.index++);let f="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)f+=this.peek,this.index++;if(f){let p=parseInt(f);s=l?-p:p}else return this.index=t,null}this.skipSpace()}let o=ai[i];if(!o)return this.index=t,null;let a;if(this.peek==="("?a=this.parseArguments("enclosure",n):a=this.parseArguments("implicit",{...n,minPrec:C,condition:l=>{let f=this.peekBareWord();return f.length>0&&ai[f]!==void 0||(n?.condition?.(l)??!1)}}),a===null)return this.index=t,null;if(i==="cbrt"){let l=["Root",a[0]??"Nothing",3];return s!==null?["Power",l,s]:l}if(i==="nPr"){let l=["Multiply",["Binomial",a[0]??"Nothing",a[1]??"Nothing"],["Factorial",a[1]??"Nothing"]];return s!==null?["Power",l,s]:l}let u;if(i==="log"&&r!==null?r===2?u=["Lb",...a]:r===10?u=["Log",...a]:u=["Log",a[0],r]:u=[o,...a],s===-1&&Array.isArray(u)){let[l,...f]=u;return["Apply",["InverseFunction",l],...f]}return s!==null?["Power",u,s]:u}static BARE_SYMBOL_MAP={alpha:"alpha",beta:"beta",gamma:"gamma",delta:"delta",epsilon:"epsilon",varepsilon:"varepsilon",zeta:"zeta",eta:"eta",theta:"theta",vartheta:"vartheta",iota:"iota",kappa:"kappa",lambda:"lambda",mu:"mu",nu:"nu",xi:"xi",omicron:"omicron",pi:"Pi",rho:"rho",sigma:"sigma",tau:"tau",upsilon:"upsilon",phi:"phi",varphi:"varphi",chi:"chi",psi:"psi",omega:"omega",Gamma:"Gamma",Delta:"Delta",Theta:"Theta",Lambda:"Lambda",Xi:"Xi",Sigma:"Sigma",Upsilon:"Upsilon",Phi:"Phi",Psi:"Psi",Omega:"Omega",oo:"PositiveInfinity",inf:"PositiveInfinity",ii:"ImaginaryUnit"};tryParseBareSymbol(){if(this.options.strict!==!1)return null;let n=this.index;if(n>0&&/^[a-zA-Z]$/.test(this._tokens[n-1]))return null;let t="";for(;!this.atEnd&&/^[a-zA-Z]$/.test(this.peek);)t+=this.peek,this.index++;if(!t)return this.index=n,null;let i=e.BARE_SYMBOL_MAP[t];return i?(this.emitSymbolReference(i,n,this.index),i):(this.index=n,null)}static SEGMENTABLE_SYMBOLS=Object.fromEntries(Object.entries(e.BARE_SYMBOL_MAP).filter(([n])=>!["oo","inf","ii"].includes(n)));static MAX_SEGMENTABLE_LENGTH=Math.max(...Object.keys(e.SEGMENTABLE_SYMBOLS).map(n=>n.length));static SEGMENTABLE_SYMBOL_VALUES=new Set(Object.values(e.SEGMENTABLE_SYMBOLS));tryParseBareRun(){if(this.options.strict!==!1)return null;let n=this.index;if(n>0&&/^[a-zA-Z]$/.test(this._tokens[n-1]))return null;let t="";for(;!this.atEnd&&/^[a-zA-Z]$/.test(this.peek);)t+=this.peek,this.index++;if(t.length<2)return this.index=n,null;if(ai[t]!==void 0)return this.emitSymbolReference(t,n,this.index),t;let i=e.SEGMENTABLE_SYMBOLS,r=[],s=!1,o=0;for(;o<t.length;){let a=!1,u=Math.min(t.length-o,e.MAX_SEGMENTABLE_LENGTH);for(let l=u;l>=2;l--){let f=t.slice(o,o+l);if(i[f]!==void 0){r.push(i[f]),o+=l,a=!0,s=!0;break}}a||(this.emitSymbolReference(t[o],n+o,n+o+1),r.push(t[o]),o+=1)}return s?r.length===1?r[0]:["Multiply",...r]:(this.index=n,null)}parseSupsub(n){if(this.atEnd)return n;let t=this.index;if(this.options.strict===!1&&typeof n=="string"&&(n.length===1&&/^[a-zA-Z]$/.test(n)||e.SEGMENTABLE_SYMBOL_VALUES.has(n))&&/^[0-9]$/.test(this.peek)){let u="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)u+=this.peek,this.index++;return this.parseSupsub(["Subscript",n,parseInt(u)])}this.skipSpace();let i=[],r=[],s=t;for(;this.peek==="_"||this.peek==="^";){if(this.match("_"))if(s=this.index,this.match("_")||this.match("^"))r.push(this.error("syntax-error",s));else{let u=this.parseGroup();if(u===null&&this.options.strict===!1){let l="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)l+=this.peek,this.index++;l&&(u=parseInt(l))}if(u??=this.parseToken(),u===null&&this.options.strict===!1&&this.peek==="("&&(u=this.parseEnclosure()),u??=this.parseStringGroup(),u===null)return this.error("missing",t);r.push(u)}else if(this.match("^"))if(s=this.index,this.match("_")||this.match("^"))i.push(this.error("syntax-error",s));else{let u=this.parseGroup();if(u===null&&this.options.strict===!1){let l=this.index,f=!1;this.peek==="-"&&(f=!0,this.index++);let p="";for(;!this.atEnd&&/^[0-9]$/.test(this.peek);)p+=this.peek,this.index++;if(p){let g=parseInt(p);u=f?-g:g}else this.index=l}if(u??=this.parseToken(),u===null&&this.options.strict===!1&&this.peek==="("&&(u=this.parseEnclosure()),u===null)return this.error("missing",t);i.push(u)}s=this.index,this.skipSpace()}if(i.length===0&&r.length===0)return this.index=t,n;let o=n,a=r.filter(u=>!R(u));if(a.length>0){let u=this._dictionary.infixByTrigger.get("_")??[];if(u){let l=["Subscript",o,a.length===1?a[0]:["List",...a]];for(let f of u)if(typeof f.parse=="function"?o=f.parse(this,l,{minPrec:0}):o=l,o!==null)break}}if(i.length>0){let u=this._dictionary.infixByTrigger.get("^")??[];if(u){let l=i.filter(f=>{if(R(f))return!1;let p=w(f);return!(p!==null&&/^(?:st|nd|rd|th)$/i.test(p))});if(l.length>1)return this.error("unexpected-superscript",t);if(l.length!==0){let f=l[0],p=["Superscript",o,f];for(let g of u)if(typeof g.parse=="function"?o=g.parse(this,p,{minPrec:0}):o=p,o!==null)break}}}return o===null&&(this.index=t),o}parsePostfixOperator(n,t){if(n===null||this.atEnd)return null;let i=this.index;if(this.skipVisualSpace(),this.index!==i){let s=this._tokens[this.index];s==="\\{"||s==="\\left"&&this._tokens[this.index+1]==="\\{"||(this.index=i)}let r=this.index;for(let[s,o]of this.peekDefinitions("postfix")){this.index=r+o;let a=s.parse(this,n,t);if(a!==null)return a}return this.index=i,null}parseSyntaxError(){let n=this.index;if(this.peek==="^")return this.index+=1,["Superscript",this.error("missing",n),P(this.parseGroup())];let t=this.peekDefinitions("operator");if(t.length>0){if(t=this.peekDefinitions("postfix"),t.length>0){let[a,u]=t[0];if(this.index+=u,typeof a.parse=="function"){let l=a.parse(this,this.error("missing",n));if(l!==null)return l}return this.error("unexpected-operator",n)}if(t=this.peekDefinitions("prefix"),t.length>0){let[a,u]=t[0];if(this.index+=u,typeof a.parse=="function"){let l=a.parse(this,{minPrec:0});if(l!==null)return l}return a.name?[a.name,this.parseExpression()??this.error("missing",n)]:this.error("unexpected-operator",n)}if(t=this.peekDefinitions("infix"),t.length>0){let[a,u]=t[0];this.index+=u;let l=a.parse(this,this.error("missing",n),{minPrec:0});return l!==null?l:this.error("unexpected-operator",n)}}let i=this.index,r=as(this);if(r!==null)return r;if(r=Yn(this),r!==null)return this.error(["unexpected-symbol",{str:r}],i);let s=this.peek;if(!s)return this.error("syntax-error",n);if(Nf(this))return this.error("unexpected-delimiter",n);if(s[0]!=="\\")return this.nextToken(),this.error(["unexpected-token",{str:ln(s)}],n);let o=this.nextToken();if(this.skipSpaceTokens(),o==="\\end"){let a=this.parseStringGroup();return a===null?this.error("expected-environment-name",n):this.error(["unbalanced-environment",{str:a}],n)}for(;this.match("[");){let a=0;for(;!this.atEnd&&a===0&&this.peek!=="]";)this.peek==="["&&(a+=1),this.peek==="]"&&(a-=1),this.nextToken();this.match("]")}for(;this.match("<{>");){let a=0;for(;!this.atEnd&&a===0&&this.peek!=="<}>";)this.peek==="<{>"&&(a+=1),this.peek==="<}>"&&(a-=1),this.nextToken();this.match("<}>")}return this.error(["unexpected-command",{str:ln(o)}],n)}parsePrimary(n){if(this.atBoundary||this.atTerminator(n))return null;let t=null,i=this.index;if(this.match("<}>"))return this.error("unexpected-closing-delimiter",i);if(t??=this.parseGroup(),t??=this.parseNumber(),t??=this.parseDoubleQuoteString(),t??=this.parseEnclosure(),t??=this.parseEnvironment(n),t===null&&this.matchAll(this._positiveInfinityTokens)&&(t="PositiveInfinity"),t===null&&this.matchAll(this._negativeInfinityTokens)&&(t="NegativeInfinity"),t===null&&this.matchAll(this._notANumberTokens)&&(t="NaN"),t===null&&this.matchAll(this._imaginaryUnitTokens)&&(t="ImaginaryUnit"),t??=this.tryParseBareFunction(n),t??=this.tryParseBareSymbol(),t??=this.tryParseBareRun(),t??=this.parseGenericExpression(n)??this.parseFunction(n)??this.parseSymbol(n)??as(this),t!==null&&R(t))return this.parsePrimary(n);if(t!==null){t=this.decorate(t,i);let r=null,s=this.index;do{if(r=this.parsePostfixOperator(t,n),t=r??t,this.index===s&&r!==null){this.index;break}s=this.index}while(r!==null)}if(t!==null&&(t=this.parseSupsub(t)),t!==null&&(t=df(t)),t!==null){let r=null,s=this.index;do{if(r=this.parsePostfixOperator(t,n),t=r??t,this.index===s&&r!==null){this.index;break}s=this.index}while(r!==null)}if(t===null&&(t=this.options.parseUnexpectedToken?.(null,this)??null,t===null&&this.peek.startsWith("\\"))){if(this.peek==="\\"){let r=this.index;if(this.nextToken(),this.skipVisualSpace(),this.atEnd)return this.emitDiagnostic("recovered",r,this.index,{skipped:this.latex(r,this.index)}),this.decorate(null,i);this.index=r}this.nextToken(),t=this.error("unexpected-command",i)}return this.decorate(t,i)}parseExpression(n){this.skipSpace();let t=this.index;if(this.atBoundary)return this.index=t,null;let i=this.diagnosticsCheckpoint();n??={minPrec:0},n.minPrec,n.minPrec===void 0&&(n={...n,minPrec:0});let r=this.parsePrefixOperator({...n,minPrec:0});if(r??=this.parsePrimary(n),r!==null){let s=!1;for(;!s&&!this.atTerminator(n);){this.skipSpace(),this._operandDiagnosticCheckpoint=i;let o=this.parseInfixOperator(r,n);if(o===null&&n.minPrec<=qe){let a=this.peekDefinitions("operator");if((a.length===0||a.every(([u])=>u.latexTrigger==="\\text"||u.latexTrigger==="\\keyword"))&&!(a.length>0&&this.wouldMatchTextInfix(a))){let u=this.index,l=this.parseExpression({...n,minPrec:qe+1});l!==null?(this.emitJuxtapositionDiagnostic(r,l,t,u),d(r)==="InvisibleOperator"?d(l)==="InvisibleOperator"?o=["InvisibleOperator",...b(r),...b(l)]:o=["InvisibleOperator",...b(r),l]:d(l)==="InvisibleOperator"?o=["InvisibleOperator",r,...b(l)]:o=["InvisibleOperator",r,l]):o===null&&(o=this.options.parseUnexpectedToken?.(r,this)??null)}}o!==null?r=o:s=!0}}return this.decorate(r,t)}decorate(n,t){if(n===null)return null;if(!this.options.preserveLatex)return n;let i=this.latex(t,this.index);return Array.isArray(n)?n={latex:i,fn:n}:typeof n=="number"?n={latex:i,num:Number(n).toString()}:typeof n=="string"?n.startsWith("'")?n={latex:i,str:n.slice(1,-1)}:n={latex:i,sym:n}:typeof n=="object"&&n!==null&&(n.latex=i),n}error(n,t){let i;typeof n=="string"?(n.startsWith("'"),i={str:n}):(n[0].startsWith("'"),i=["ErrorCode",{str:n[0]},...n.slice(1)]);let r=this.latex(t,this.index),s=r?["Error",i,["LatexString",{str:r}]]:["Error",i],a=typeof n=="string"&&n==="missing"?this.sourceOffsets(t,t):this.sourceOffsets(t,this.index);return{fn:s,sourceOffsets:a}}emitJuxtapositionDiagnostic(n,t,i,r){if(this.diagnostics===null)return;let s=d(t);if(s!=="Delimiter"&&s!=="Matrix")return;let o=null,a=i,u,l=y(n);if(l!==null)o=l;else if(d(n)==="__unit__")o=y(c(n,1)),o!==null&&(u="unit");else if(d(n)==="InvisibleOperator"){let p=this.trailingLetterRun(r);if(p===null)return;o=p.name,a=p.startToken}if(o===null)return;let f=this.isSymbolDeclared(o)?this.getSymbolType(o).matches("function")?"function":"value":"unknown";this.emitDiagnostic("juxtaposition-as-multiply",a,this.index,u!==void 0?{name:o,declaredAs:f,lexedAs:u}:{name:o,declaredAs:f})}trailingLetterRun(n){let t=n;for(;t>0&&this._tokens[t-1]==="<space>";)t--;let i="";for(;t>0&&/^[a-zA-Z]$/.test(this._tokens[t-1]);)i=this._tokens[t-1]+i,t--;return i.length===0?null:{name:i,startToken:t}}isFunctionOperator(n){return n===null||n==="D"||n==="N"?!1:!!this.getSymbolType(n).matches("function")}looksLikePredicate(n){return n===null||typeof n!="string"||!/^[A-Z]$/.test(n)?!1:(this.skipSpace(),this.peek==="("||this.peek==="\\left")}*getDefs(n){if(n==="operator")for(let t=this._dictionary.defs.length-1;t>=0;t--){let i=this._dictionary.defs[t];/^prefix|infix|postfix/.test(i.kind)&&(yield i)}else for(let t=this._dictionary.defs.length-1;t>=0;t--){let i=this._dictionary.defs[t];i.kind===n&&(yield i)}}};function Nf(e){let n=e.peek;return Object.values(ps).includes(n)||ps[n]?(e.nextToken(),!0):En[n]||Object.values(En).includes(n)?(e.nextToken(),e.nextToken(),!0):!1}var f0=Object.freeze([0,1]);var Cx=new G("matrix"),Bx=new G("vector");var Kn=[[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 gs(e,n){for(;e>=Kn.length;){let t=Kn.length,i=[1],r=Kn[t-1];for(let s=1;s<t;s++)i[s]=r[s-1]+r[s];i[t]=1,Kn.push(i)}return Kn[e][n]}function ci(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return Yf(t)}function Yf(e){return e.hi<0?{kind:"empty"}:e.lo>=0?x({lo:Math.sqrt(e.lo),hi:Math.sqrt(e.hi)}):{kind:"partial",value:{lo:0,hi:Math.sqrt(e.hi)},domainClipped:"lo"}}function fi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?x({lo:t.lo*t.lo,hi:t.hi*t.hi}):t.hi<=0?x({lo:t.hi*t.hi,hi:t.lo*t.lo}):x({lo:0,hi:Math.max(t.lo*t.lo,t.hi*t.hi)})}function cu(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 Ae(e,n){let t=T(e);if(!Array.isArray(t))return t;let[i]=t;if(Number.isInteger(n)){if(n>=0)return x(cu(i,n));{if(K(i))return{kind:"singular"};let r=cu(i,-n);return x({lo:1/r.hi,hi:1/r.lo})}}else return Qe(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?x({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"}:x({lo:Math.pow(i.hi,n),hi:Math.pow(i.lo,n)})}function pi(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(r.lo===r.hi&&Number.isInteger(r.lo))return Ae(i,r.lo);if(i.hi<=0)return i.lo===-1&&i.hi===-1&&Math.floor(r.hi)>Math.floor(r.lo)?x({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 x({lo:Math.min(...s),hi:Math.max(...s)})}function fu(e,n,t){if(e===0)return t>0?0:t<0?1/0:1;let i=Math.pow(Math.abs(e),t);return e<0&&n%2!==0?-i:i}function bs(e,n,t){let i=T(e);if(!Array.isArray(i))return i;let[r]=i,s=n/t;if(t%2===0)return Ae(x(r),s);if(r.lo>=0)return Ae(x(r),s);let o=r.lo<=0&&r.hi>=0;if(n<0&&o)return{kind:"singular",at:0};let a=[fu(r.lo,n,s),fu(r.hi,n,s)];return o&&n>0&&a.push(0),x({lo:Math.min(...a),hi:Math.max(...a)})}function ys(e,n){let t=T(e);if(!Array.isArray(t))return t;let[i]=t;if(!Number.isInteger(n)||n===0)return Ae(x(i),1/n);if(n%2===0)return Ae(x(i),1/n);let r=s=>Math.sign(s)*Math.pow(Math.abs(s),1/n);return x({lo:r(i.lo),hi:r(i.hi)})}function mi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.exp(t.lo),hi:Math.exp(t.hi)})}function di(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?x({lo:Math.log(t.lo),hi:Math.log(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log(t.hi)},domainClipped:"lo"}}function gi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?x({lo:Math.log10(t.lo),hi:Math.log10(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log10(t.hi)},domainClipped:"lo"}}function hi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.hi<=0?{kind:"empty"}:t.lo>0?x({lo:Math.log2(t.lo),hi:Math.log2(t.hi)}):{kind:"partial",value:{lo:-1/0,hi:Math.log2(t.hi)},domainClipped:"lo"}}function bi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?x(t):t.hi<=0?x({lo:-t.hi,hi:-t.lo}):x({lo:0,hi:Math.max(-t.lo,t.hi)})}function yi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?x({lo:i,hi:r}):{kind:"singular",at:i+1,continuity:"right"}}function xi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.ceil(t.lo),r=Math.ceil(t.hi);return i===r?x({lo:i,hi:r}):{kind:"singular",at:i,continuity:"left"}}function Xf(e){return Math.sign(e)*Math.round(Math.abs(e))}function Kf(e,n){let t=n(e.lo),i=n(e.hi);if(t===i)return x({lo:t,hi:i});let r=t+.5;return{kind:"singular",at:r,continuity:n(r)===t+1?"right":"left"}}function Qn(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return Kf(t,Xf)}function Ni(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.floor(t.lo),r=Math.floor(t.hi);return i===r?x({lo:t.lo-i,hi:t.hi-i}):{kind:"singular",at:i+1,continuity:"right"}}function Ei(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=Math.trunc(t.lo),r=Math.trunc(t.hi);if(i===r)return x({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 Ti(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return x({lo:Math.min(i.lo,r.lo),hi:Math.min(i.hi,r.hi)})}function vi(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;return x({lo:Math.max(i.lo,r.lo),hi:Math.max(i.hi,r.hi)})}function Ii(e,n){let t=T(e,n);if(!Array.isArray(t))return t;let[i,r]=t;if(K(r))return{kind:"singular"};if(i.lo===i.hi&&r.lo===r.hi){let p=r.lo,g=(i.lo%p+p)%p+0;return x({lo:g,hi:g})}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,f=i.hi-s*a;return o?l===0?{kind:"singular",at:i.lo,continuity:"right"}:x({lo:l-s,hi:f-s}):x({lo:Math.min(l,f),hi:Math.max(l,f)})}function Mi(e,n){return en(e,nn(n,Qn(Q(e,n))))}function ki(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?x({lo:1,hi:1}):t.hi<0?x({lo:0,hi:0}):t.lo===0&&t.hi===0?x({lo:.5,hi:.5}):{kind:"singular",at:0}}function Si(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>0?x({lo:1,hi:1}):t.hi<0?x({lo:-1,hi:-1}):t.lo===0&&t.hi===0?x({lo:0,hi:0}):{kind:"singular",at:0}}var pu=1.4616321449683622,Qf=.8856031944108887;function wi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return ep(t)}var mu=[-.504083008264455,-1.573498473162391,-2.610720868444145,-3.635293366436901,-4.653163765628266,-5.667162441556885,-6.678418213073426,-7.687788325031709,-8.695764163640956,-9.702672540001863];function gu(e){let t=-Math.floor(e)-1;return t>=0&&t<mu.length?mu[t]:null}function ep(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=ue(e.lo),r=ue(e.hi),s=Math.min(i,r),o=Math.max(i,r),a=gu(e.lo);if(a!==null){if(a>=e.lo&&a<=e.hi){let u=ue(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 x({lo:s,hi:o})}return e.lo>=pu?x({lo:ue(e.lo),hi:ue(e.hi)}):e.hi<=pu?x({lo:ue(e.hi),hi:ue(e.lo)}):x({lo:Qf,hi:Math.max(ue(e.lo),ue(e.hi))})}function Ai(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return np(t)}function np(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=sn(e.lo),r=sn(e.hi),s=Math.min(i,r),o=Math.max(i,r),a=gu(e.lo);return a!==null?a>=e.lo&&a<=e.hi&&(s=Math.min(s,sn(a))):s=-1/0,x({lo:s,hi:o})}return x({lo:sn(e.lo),hi:sn(e.hi)})}function Pi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=Tr(Math.round(t.lo)),r=Tr(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?x({lo:Math.min(i,r),hi:Math.max(i,r)}):x({lo:i,hi:r})}function Di(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.lo<0)return{kind:"empty"};let i=vr(Math.round(t.lo)),r=vr(Math.round(t.hi));return!Number.isFinite(i)||!Number.isFinite(r)?x({lo:Math.min(i,r),hi:Math.max(i,r)}):x({lo:i,hi:r})}var hs=4096;function du(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 xs(e,n,t){let i=du(e.lo,e.hi,hs),r=du(n.lo,n.hi,hs);if(!i||!r||i.length*r.length>hs)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:x({lo:s,hi:o})}function _i(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=xs(r,s,gs);if(o)return o;let a=Math.round(r.hi);return x({lo:0,hi:gs(a,Math.floor(a/2))})}function Ri(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=xs(r,s,un);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 x({lo:0,hi:a})}function Ci(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(n);if(!Array.isArray(i))return i;let[r]=t,[s]=i,o=xs(r,s,Er);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 x({lo:0,hi:a*u})}function Ns(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Ir(t.lo),hi:Ir(t.hi)})}function Es(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Pt(t.lo),hi:Pt(t.hi)})}function Ts(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:At(t.hi),hi:At(t.lo)})}function vs(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.pow(2,t.lo),hi:Math.pow(2,t.hi)})}function Is(e,n){let t=T(e);if(!Array.isArray(t))return t;let i=T(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),x({lo:a,hi:Math.max(...o)})}var ge=2*Math.PI,j=Math.PI,he=Math.PI/2,hu=3*Math.PI/2;function Bi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=ge)return x({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 W(t,he,ge)&&(o=1),W(t,hu,ge)&&(s=-1),x({lo:s,hi:o})}function Oi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=ge)return x({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 W(t,0,ge)&&(o=1),W(t,j,ge)&&(s=-1),x({lo:s,hi:o})}function Fi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,he,j)){let s=Math.ceil((t.lo-he)/j);return{kind:"singular",at:he+s*j}}let i=Math.tan(t.lo),r=Math.tan(t.hi);return i>1e10&&r<-1e10||i<-1e10&&r>1e10?{kind:"singular"}:x({lo:i,hi:r})}function Ji(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,0,j))return{kind:"singular",at:Math.ceil(t.lo/j)*j};let i=1/Math.tan(t.lo),r=1/Math.tan(t.hi);return x({lo:Math.min(i,r),hi:Math.max(i,r)})}function Li(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,he,j)){let a=Math.ceil((t.lo-he)/j);return{kind:"singular",at:he+a*j}}let i=1/Math.cos(t.lo),r=1/Math.cos(t.hi),s=Math.min(i,r),o=Math.max(i,r);return W(t,0,ge)&&(s=Math.min(s,1),o=Math.max(o,1)),W(t,j,ge)&&(s=Math.min(s,-1),o=Math.max(o,-1)),x({lo:s,hi:o})}function Vi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;if(t.hi-t.lo>=j)return{kind:"singular"};if(W(t,0,j))return{kind:"singular",at:Math.ceil(t.lo/j)*j};let i=1/Math.sin(t.lo),r=1/Math.sin(t.hi),s=Math.min(i,r),o=Math.max(i,r);return W(t,he,ge)&&(s=Math.min(s,1),o=Math.max(o,1)),W(t,hu,ge)&&(s=Math.min(s,-1),o=Math.max(o,-1)),x({lo:s,hi:o})}function et(e){let n=T(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 x({lo:Math.asin(t.lo),hi:Math.asin(t.hi)})}function nt(e){let n=T(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 x({lo:Math.acos(t.hi),hi:Math.acos(t.lo)})}function qi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.atan(t.lo),hi:Math.atan(t.hi)})}function $i(e,n){let t=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 x({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?x({lo:-j,hi:j}):x({lo:Math.min(...s),hi:Math.max(...s)})}function Tn(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.sinh(t.lo),hi:Math.sinh(t.hi)})}function vn(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return t.lo>=0?x({lo:Math.cosh(t.lo),hi:Math.cosh(t.hi)}):t.hi<=0?x({lo:Math.cosh(t.hi),hi:Math.cosh(t.lo)}):x({lo:1,hi:Math.max(Math.cosh(t.lo),Math.cosh(t.hi))})}function ji(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.tanh(t.lo),hi:Math.tanh(t.hi)})}function tt(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:Math.asinh(t.lo),hi:Math.asinh(t.hi)})}function it(e){let n=T(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"}:x({lo:Math.acosh(t.lo),hi:Math.acosh(t.hi)})}function rt(e){let n=T(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 x({lo:Math.atanh(t.lo),hi:Math.atanh(t.hi)})}function Gi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return x({lo:he-Math.atan(t.hi),hi:he-Math.atan(t.lo)})}function zi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:et(Q(x({lo:1,hi:1}),x(t)))}function Zi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:nt(Q(x({lo:1,hi:1}),x(t)))}function Ui(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:Q(vn(t),Tn(t))}function Hi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:Q(x({lo:1,hi:1}),Tn(t))}function Wi(e){return Q(x({lo:1,hi:1}),vn(e))}function Yi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:rt(Q(x({lo:1,hi:1}),x(t)))}function Xi(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:tt(Q(x({lo:1,hi:1}),x(t)))}function Ki(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n;return K(t)?{kind:"singular",at:0}:it(Q(x({lo:1,hi:1}),x(t)))}var Ms=[4.49341,7.72525,10.90412,14.06619,17.22076,20.3713,23.51945,26.66605,29.8116,32.95639];function Qi(e){let n=T(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=Ms[Ms.length-1];for(let l of Ms)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)),x({lo:r,hi:s})}var ks=[],Ss=[];for(let e=1;e<=20;e++)ks.push(Math.sqrt(2*e)),Ss.push(Math.sqrt(2*e-1));function er(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=on(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(on(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of ks)o>=t.lo&&o<=t.hi&&s(on(o)),-o>=t.lo&&-o<=t.hi&&s(on(-o));return bu(t,ks,on,s),x({lo:i,hi:r})}function bu(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 nr(e){let n=T(e);if(!Array.isArray(n))return n;let[t]=n,i=an(t.lo),r=i,s=o=>{o<i&&(i=o),o>r&&(r=o)};s(an(t.hi)),t.lo<=0&&t.hi>=0&&s(0);for(let o of Ss)o>=t.lo&&o<=t.hi&&s(an(o)),-o>=t.lo&&-o<=t.hi&&s(an(-o));return bu(t,Ss,an,s),x({lo:i,hi:r})}function Pe(e){return"kind"in e?e:{kind:"interval",value:e}}function tr(e,n){let t=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 ir(e,n){let t=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 rr(e,n){let t=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 sr(e,n){let t=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 st(e,n){let t=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 or(e,n){let t=st(e,n);return t==="true"?"false":t==="false"?"true":"maybe"}function ar(e,n){return e==="false"||n==="false"?"false":e==="true"&&n==="true"?"true":"maybe"}function ur(e,n){return e==="true"||n==="true"?"true":e==="false"&&n==="false"?"false":"maybe"}function lr(e){return e==="true"?"false":e==="false"?"true":"maybe"}function cr(e,n,t,i){if(e==="true"||e==="false"||e==="maybe"){let p=e,g=n,h=t;switch(p){case"true":return Pe(g());case"false":return Pe(h());case"maybe":return Be(Pe(g()),Pe(h()))}}let r=e,s=n,o=t,a=i,u=T(r);if(!Array.isArray(u))return u;let[l]=u;switch(s(l)){case"true":return Pe(o(l));case"false":return Pe(a(l));case"maybe":let p=Pe(o(l)),g=Pe(a(l));return Be(p,g)}}function ws(e,n){if(e==="false")return{kind:"empty"};let t=Pe(n());return e==="true"?t:t.kind==="interval"?{kind:"partial",value:t.value,domainClipped:"both"}:t.kind==="partial"?{...t,domainClipped:"both"}:t}function fr(e,n,t){let i=T(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 tp={ok:x,point:ot,containsExtremum:W,unionResults:Be,mergeDomainClip:In,isPoint:at,containsZero:K,isPositive:ut,isNegative:Qe,isNonNegative:lt,isNonPositive:ct,width:ft,midpoint:pt,getValue:mt,unwrap:dt,unwrapOrPropagate:T,add:ht,sub:en,mul:nn,div:Q,negate:bt,sqrt:ci,square:fi,pow:Ae,powInterval:pi,powRational:bs,nthRoot:ys,exp:mi,ln:di,log10:gi,log2:hi,abs:bi,floor:yi,ceil:xi,round:Qn,fract:Ni,trunc:Ei,min:Ti,max:vi,mod:Ii,remainder:Mi,heaviside:ki,sign:Si,gamma:wi,gammaln:Ai,factorial:Pi,factorial2:Di,binomial:_i,gcd:Ri,lcm:Ci,chop:Ns,erf:Es,erfc:Ts,exp2:vs,hypot:Is,sin:Bi,cos:Oi,tan:Fi,cot:Ji,sec:Li,csc:Vi,asin:et,acos:nt,atan:qi,atan2:$i,sinh:Tn,cosh:vn,tanh:ji,asinh:tt,acosh:it,atanh:rt,acot:Gi,acsc:zi,asec:Zi,coth:Ui,csch:Hi,sech:Wi,acoth:Yi,acsch:Xi,asech:Ki,sinc:Qi,fresnelS:er,fresnelC:nr,less:tr,lessEqual:ir,greater:rr,greaterEqual:sr,equal:st,notEqual:or,and:ar,or:ur,not:lr,piecewise:cr,restrict:ws,clamp:fr};var xN="0.86.2";export{tp as IntervalArithmetic,yt as _mul,bi as abs,nt as acos,it as acosh,Gi as acot,Yi as acoth,zi as acsc,Xi as acsch,ht as add,ar as and,Zi as asec,Ki as asech,et as asin,tt as asinh,qi as atan,$i as atan2,rt as atanh,_i as binomial,xi as ceil,Ns as chop,fr as clamp,W as containsExtremum,K as containsZero,Oi as cos,vn as cosh,Ji as cot,Ui as coth,Vi as csc,Hi as csch,Q as div,st as equal,Es as erf,Ts as erfc,mi as exp,vs as exp2,Pi as factorial,Di as factorial2,yi as floor,Ni as fract,nr as fresnelC,er as fresnelS,wi as gamma,Ai as gammaln,Ri as gcd,mt as getValue,rr as greater,sr as greaterEqual,ki as heaviside,Is as hypot,Qe as isNegative,lt as isNonNegative,ct as isNonPositive,at as isPoint,ut as isPositive,Ci as lcm,tr as less,ir as lessEqual,di as ln,gi as log10,hi as log2,vi as max,In as mergeDomainClip,pt as midpoint,Ti as min,Ii as mod,nn as mul,bt as negate,lr as not,or as notEqual,x as ok,ur as or,cr as piecewise,ot as point,Ae as pow,pi as powInterval,Mi as remainder,Qn as round,Li as sec,Wi as sech,Si as sign,Bi as sin,Qi as sinc,Tn as sinh,ci as sqrt,fi as square,en as sub,Fi as tan,ji as tanh,Ei as trunc,Be as unionResults,dt as unwrap,T as unwrapOrPropagate,xN as version,ft as width};
8
8
  /*! Bundled license information:
9
9
 
10
10
  complex-esm/dist/src/complex.js: