@cortex-js/compute-engine 0.129.0 → 0.129.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (433) hide show
  1. package/dist/esm-min/chunks/{chunk-RKFNDUDQ.js → chunk-75MH3VS7.js} +3 -3
  2. package/dist/esm-min/chunks/{chunk-3XFZFOXD.js → chunk-S6UB43FH.js} +1 -1
  3. package/dist/esm-min/cli/epsil.js +1 -1
  4. package/dist/esm-min/compile.js +2 -2
  5. package/dist/esm-min/compute-engine.js +2 -2
  6. package/dist/esm-min/core.js +2 -2
  7. package/dist/esm-min/epsil.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/cache-stats.d.ts +1 -1
  20. package/dist/types/common/configuration-change.d.ts +1 -1
  21. package/dist/types/common/debug-hook.d.ts +1 -1
  22. package/dist/types/common/debug.d.ts +1 -1
  23. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  24. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  25. package/dist/types/common/interruptible.d.ts +1 -1
  26. package/dist/types/common/kleene.d.ts +1 -1
  27. package/dist/types/common/one-of.d.ts +1 -1
  28. package/dist/types/common/signals.d.ts +1 -1
  29. package/dist/types/common/styled-text.d.ts +1 -1
  30. package/dist/types/common/terminal.d.ts +1 -1
  31. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  32. package/dist/types/common/type/boxed-type.d.ts +1 -1
  33. package/dist/types/common/type/compatibility.d.ts +1 -1
  34. package/dist/types/common/type/conditional-conformance.d.ts +1 -1
  35. package/dist/types/common/type/effects.d.ts +1 -1
  36. package/dist/types/common/type/facts.d.ts +1 -1
  37. package/dist/types/common/type/immutable.d.ts +1 -1
  38. package/dist/types/common/type/instantiate.d.ts +1 -1
  39. package/dist/types/common/type/intern.d.ts +1 -1
  40. package/dist/types/common/type/lexer.d.ts +1 -1
  41. package/dist/types/common/type/numeric-range.d.ts +1 -1
  42. package/dist/types/common/type/parse.d.ts +1 -1
  43. package/dist/types/common/type/parser.d.ts +1 -1
  44. package/dist/types/common/type/primitive.d.ts +1 -1
  45. package/dist/types/common/type/reduce.d.ts +1 -1
  46. package/dist/types/common/type/reference.d.ts +1 -1
  47. package/dist/types/common/type/serialize.d.ts +1 -1
  48. package/dist/types/common/type/size-cap.d.ts +1 -1
  49. package/dist/types/common/type/subtype.d.ts +1 -1
  50. package/dist/types/common/type/type-builder.d.ts +1 -1
  51. package/dist/types/common/type/types.d.ts +1 -1
  52. package/dist/types/common/type/utils.d.ts +1 -1
  53. package/dist/types/common/type/variance.d.ts +1 -1
  54. package/dist/types/common/type/widen-value.d.ts +1 -1
  55. package/dist/types/common/utils.d.ts +1 -1
  56. package/dist/types/compile.d.ts +1 -1
  57. package/dist/types/compute-engine/assume.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/ambient-chain.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/async-only-descendants.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/binders.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/binding-sites.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/binding-tombstone.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/boxed-character.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/boxed-object.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/broadcast-cell-widening.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/broadcast-lift-type.d.ts +1 -1
  82. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/call-result-type.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/callback-arity.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  87. package/dist/types/compute-engine/boxed-expression/collection-element-memo.d.ts +1 -1
  88. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  89. package/dist/types/compute-engine/boxed-expression/conditional-value.d.ts +1 -1
  90. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  91. package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +1 -1
  92. package/dist/types/compute-engine/boxed-expression/cycle-guard.d.ts +1 -1
  93. package/dist/types/compute-engine/boxed-expression/definition-guards.d.ts +1 -1
  94. package/dist/types/compute-engine/boxed-expression/derive-application-type.d.ts +1 -1
  95. package/dist/types/compute-engine/boxed-expression/diophantine.d.ts +1 -1
  96. package/dist/types/compute-engine/boxed-expression/effects-inference.d.ts +1 -1
  97. package/dist/types/compute-engine/boxed-expression/effects-of.d.ts +1 -1
  98. package/dist/types/compute-engine/boxed-expression/effects-provenance.d.ts +1 -1
  99. package/dist/types/compute-engine/boxed-expression/error-value.d.ts +1 -1
  100. package/dist/types/compute-engine/boxed-expression/exp-to-trig.d.ts +1 -1
  101. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  102. package/dist/types/compute-engine/boxed-expression/explain-labels.d.ts +1 -1
  103. package/dist/types/compute-engine/boxed-expression/explain.d.ts +1 -1
  104. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  105. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  106. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  107. package/dist/types/compute-engine/boxed-expression/function-literal.d.ts +1 -1
  108. package/dist/types/compute-engine/boxed-expression/generic-instantiation.d.ts +1 -1
  109. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  110. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  111. package/dist/types/compute-engine/boxed-expression/inferred-annotations.d.ts +1 -1
  112. package/dist/types/compute-engine/boxed-expression/infinite-point.d.ts +1 -1
  113. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  114. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  115. package/dist/types/compute-engine/boxed-expression/literal-tier.d.ts +1 -1
  116. package/dist/types/compute-engine/boxed-expression/logarithm.d.ts +1 -1
  117. package/dist/types/compute-engine/boxed-expression/machine-number.d.ts +1 -1
  118. package/dist/types/compute-engine/boxed-expression/match-dispatch.d.ts +1 -1
  119. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  120. package/dist/types/compute-engine/boxed-expression/modular-arithmetic.d.ts +1 -1
  121. package/dist/types/compute-engine/boxed-expression/multivariate-gcd.d.ts +1 -1
  122. package/dist/types/compute-engine/boxed-expression/multivariate-poly.d.ts +1 -1
  123. package/dist/types/compute-engine/boxed-expression/named-arguments.d.ts +1 -1
  124. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  125. package/dist/types/compute-engine/boxed-expression/number-set-types.d.ts +1 -1
  126. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  127. package/dist/types/compute-engine/boxed-expression/object-deps.d.ts +1 -1
  128. package/dist/types/compute-engine/boxed-expression/object-walk.d.ts +1 -1
  129. package/dist/types/compute-engine/boxed-expression/operand-descriptor.d.ts +1 -1
  130. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  131. package/dist/types/compute-engine/boxed-expression/overload.d.ts +1 -1
  132. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  133. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  134. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  135. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  136. package/dist/types/compute-engine/boxed-expression/provisional-application.d.ts +1 -1
  137. package/dist/types/compute-engine/boxed-expression/recursive-list-builder.d.ts +1 -1
  138. package/dist/types/compute-engine/boxed-expression/rule-index.d.ts +1 -1
  139. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  140. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  141. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  142. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  143. package/dist/types/compute-engine/boxed-expression/solve-congruence.d.ts +1 -1
  144. package/dist/types/compute-engine/boxed-expression/solve-domain.d.ts +1 -1
  145. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  146. package/dist/types/compute-engine/boxed-expression/solve-system.d.ts +1 -1
  147. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  148. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  149. package/dist/types/compute-engine/boxed-expression/tensor-view.d.ts +1 -1
  150. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  151. package/dist/types/compute-engine/boxed-expression/tuple-pattern.d.ts +1 -1
  152. package/dist/types/compute-engine/boxed-expression/type-compatibility-error.d.ts +1 -1
  153. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  154. package/dist/types/compute-engine/boxed-expression/type-provenance.d.ts +1 -1
  155. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  156. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  157. package/dist/types/compute-engine/boxed-expression/value-membership.d.ts +1 -1
  158. package/dist/types/compute-engine/checkpoint-journal.d.ts +1 -1
  159. package/dist/types/compute-engine/checkpoint.d.ts +1 -1
  160. package/dist/types/compute-engine/clause-identity.d.ts +1 -1
  161. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  162. package/dist/types/compute-engine/compilation/angular-unit.d.ts +1 -1
  163. package/dist/types/compute-engine/compilation/auto-escalation.d.ts +1 -1
  164. package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
  165. package/dist/types/compute-engine/compilation/builtin-callback.d.ts +1 -1
  166. package/dist/types/compute-engine/compilation/color-space-fact.d.ts +1 -1
  167. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  168. package/dist/types/compute-engine/compilation/constant-folding.d.ts +1 -1
  169. package/dist/types/compute-engine/compilation/cse.d.ts +1 -1
  170. package/dist/types/compute-engine/compilation/deprecation-warnings.d.ts +1 -1
  171. package/dist/types/compute-engine/compilation/derivative-closed-form.d.ts +1 -1
  172. package/dist/types/compute-engine/compilation/diagnostics.d.ts +1 -1
  173. package/dist/types/compute-engine/compilation/fixed-width-unroll.d.ts +1 -1
  174. package/dist/types/compute-engine/compilation/function-purity.d.ts +1 -1
  175. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  176. package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -1
  177. package/dist/types/compute-engine/compilation/gpu-value-facts.d.ts +1 -1
  178. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  179. package/dist/types/compute-engine/compilation/javascript-selection-fusion.d.ts +1 -1
  180. package/dist/types/compute-engine/compilation/javascript-statements.d.ts +1 -1
  181. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  182. package/dist/types/compute-engine/compilation/javascript-value-facts.d.ts +1 -1
  183. package/dist/types/compute-engine/compilation/jet-derivative.d.ts +1 -1
  184. package/dist/types/compute-engine/compilation/protocol-dispatch.d.ts +1 -1
  185. package/dist/types/compute-engine/compilation/provable-kind.d.ts +1 -1
  186. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  187. package/dist/types/compute-engine/compilation/storage-hints.d.ts +1 -1
  188. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  189. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  190. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  191. package/dist/types/compute-engine/declaration-origin.d.ts +1 -1
  192. package/dist/types/compute-engine/differential-equation-utils.d.ts +1 -1
  193. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  194. package/dist/types/compute-engine/engine-boxing-state.d.ts +1 -1
  195. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  196. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  197. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  198. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  199. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  200. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  201. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  202. package/dist/types/compute-engine/engine-inspectable-scope.d.ts +1 -1
  203. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  204. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  205. package/dist/types/compute-engine/engine-protocols.d.ts +1 -1
  206. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  207. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  208. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  209. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  210. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  211. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  212. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  213. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  214. package/dist/types/compute-engine/function-properties/index.d.ts +1 -1
  215. package/dist/types/compute-engine/function-properties/types.d.ts +1 -1
  216. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  217. package/dist/types/compute-engine/fungrim/loader.d.ts +1 -1
  218. package/dist/types/compute-engine/fungrim/types.d.ts +1 -1
  219. package/dist/types/compute-engine/global-types.d.ts +1 -1
  220. package/dist/types/compute-engine/implicit-compile.d.ts +1 -1
  221. package/dist/types/compute-engine/index.d.ts +1 -1
  222. package/dist/types/compute-engine/inference-rollback.d.ts +1 -1
  223. package/dist/types/compute-engine/interpret-oeis.d.ts +1 -1
  224. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  225. package/dist/types/compute-engine/interval/collections.d.ts +1 -1
  226. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  227. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  228. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  229. package/dist/types/compute-engine/interval/integrate.d.ts +1 -1
  230. package/dist/types/compute-engine/interval/rounding.d.ts +1 -1
  231. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  232. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  233. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  234. package/dist/types/compute-engine/latex-syntax/delimiter-tables.d.ts +1 -1
  235. package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
  236. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  237. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  238. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  239. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-colors.d.ts +1 -1
  240. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  241. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  242. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  243. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  244. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  245. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  246. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  247. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  248. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  249. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  250. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  251. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  252. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  253. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  254. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  255. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  256. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  257. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
  258. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  259. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  260. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  261. package/dist/types/compute-engine/latex-syntax/style-options.d.ts +1 -1
  262. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  263. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  264. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  265. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  266. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  267. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  268. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  269. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  270. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  271. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  272. package/dist/types/compute-engine/library/core.d.ts +1 -1
  273. package/dist/types/compute-engine/library/distributions.d.ts +1 -1
  274. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  275. package/dist/types/compute-engine/library/library.d.ts +1 -1
  276. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  277. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  278. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  279. package/dist/types/compute-engine/library/map-auto-compile.d.ts +1 -1
  280. package/dist/types/compute-engine/library/map-broadcast-shape.d.ts +1 -1
  281. package/dist/types/compute-engine/library/map-exact-proof.d.ts +1 -1
  282. package/dist/types/compute-engine/library/map-lowering.d.ts +1 -1
  283. package/dist/types/compute-engine/library/measurement-arithmetic.d.ts +1 -1
  284. package/dist/types/compute-engine/library/missing-data.d.ts +1 -1
  285. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  286. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  287. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  288. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  289. package/dist/types/compute-engine/library/random-utils.d.ts +1 -1
  290. package/dist/types/compute-engine/library/regexp.d.ts +1 -1
  291. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  292. package/dist/types/compute-engine/library/ring-constructions.d.ts +1 -1
  293. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  294. package/dist/types/compute-engine/library/special-functions.d.ts +1 -1
  295. package/dist/types/compute-engine/library/statistics-data.d.ts +1 -1
  296. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  297. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  298. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  299. package/dist/types/compute-engine/library/type-value-utils.d.ts +1 -1
  300. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  301. package/dist/types/compute-engine/library/units.d.ts +1 -1
  302. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  303. package/dist/types/compute-engine/map-auto-compile-stats.d.ts +1 -1
  304. package/dist/types/compute-engine/multi-clause.d.ts +1 -1
  305. package/dist/types/compute-engine/nonlinear-fit.d.ts +1 -1
  306. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  307. package/dist/types/compute-engine/numeric-value/exact-integer-value.d.ts +1 -1
  308. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  309. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  310. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  311. package/dist/types/compute-engine/numerics/bernoulli.d.ts +1 -1
  312. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  313. package/dist/types/compute-engine/numerics/complex-esm-augment.d.ts +1 -1
  314. package/dist/types/compute-engine/numerics/differential-equations.d.ts +1 -1
  315. package/dist/types/compute-engine/numerics/diophantine.d.ts +1 -1
  316. package/dist/types/compute-engine/numerics/distributions.d.ts +1 -1
  317. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  318. package/dist/types/compute-engine/numerics/gauss-kronrod.d.ts +1 -1
  319. package/dist/types/compute-engine/numerics/interval-arithmetic.d.ts +1 -1
  320. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  321. package/dist/types/compute-engine/numerics/levenberg-marquardt.d.ts +1 -1
  322. package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
  323. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  324. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  325. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  326. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  327. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  328. package/dist/types/compute-engine/numerics/oscillatory-quadrature.d.ts +1 -1
  329. package/dist/types/compute-engine/numerics/polynomial-roots.d.ts +1 -1
  330. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  331. package/dist/types/compute-engine/numerics/random.d.ts +1 -1
  332. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  333. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  334. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  335. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  336. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  337. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  338. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  339. package/dist/types/compute-engine/numerics/value-scaled-caps.d.ts +1 -1
  340. package/dist/types/compute-engine/oeis.d.ts +1 -1
  341. package/dist/types/compute-engine/rubi/compile.d.ts +1 -1
  342. package/dist/types/compute-engine/rubi/driver.d.ts +1 -1
  343. package/dist/types/compute-engine/rubi/explain-trace.d.ts +1 -1
  344. package/dist/types/compute-engine/rubi/loader.d.ts +1 -1
  345. package/dist/types/compute-engine/rubi/match.d.ts +1 -1
  346. package/dist/types/compute-engine/rubi/normal-form.d.ts +1 -1
  347. package/dist/types/compute-engine/rubi/rubi-utils.d.ts +1 -1
  348. package/dist/types/compute-engine/rubi/types.d.ts +1 -1
  349. package/dist/types/compute-engine/sequence.d.ts +1 -1
  350. package/dist/types/compute-engine/sum-representation.d.ts +1 -1
  351. package/dist/types/compute-engine/symbolic/angular-unit.d.ts +1 -1
  352. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  353. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  354. package/dist/types/compute-engine/symbolic/differential-equations.d.ts +1 -1
  355. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  356. package/dist/types/compute-engine/symbolic/explain-derivative.d.ts +1 -1
  357. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  358. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  359. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  360. package/dist/types/compute-engine/symbolic/interior-pole.d.ts +1 -1
  361. package/dist/types/compute-engine/symbolic/interpret.d.ts +1 -1
  362. package/dist/types/compute-engine/symbolic/limit.d.ts +1 -1
  363. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  364. package/dist/types/compute-engine/symbolic/recurrences.d.ts +1 -1
  365. package/dist/types/compute-engine/symbolic/residue.d.ts +1 -1
  366. package/dist/types/compute-engine/symbolic/series.d.ts +1 -1
  367. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  368. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  369. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  370. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  371. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  372. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  373. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  374. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  375. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  376. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  377. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  378. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  379. package/dist/types/compute-engine/symbolic/solver-utils.d.ts +1 -1
  380. package/dist/types/compute-engine/symbolic/trig-rewrite.d.ts +1 -1
  381. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  382. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  383. package/dist/types/compute-engine/type-constructors.d.ts +1 -1
  384. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  385. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  386. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  387. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  388. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  389. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  390. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  391. package/dist/types/compute-engine/types.d.ts +1 -1
  392. package/dist/types/compute-engine.d.ts +1 -1
  393. package/dist/types/core.d.ts +1 -1
  394. package/dist/types/epsil/characters.d.ts +1 -1
  395. package/dist/types/epsil/definition-sites.d.ts +1 -1
  396. package/dist/types/epsil/diagnostics.d.ts +1 -1
  397. package/dist/types/epsil/error-location.d.ts +1 -1
  398. package/dist/types/epsil/execute-epsil.d.ts +1 -1
  399. package/dist/types/epsil/formatter.d.ts +1 -1
  400. package/dist/types/epsil/lexer.d.ts +1 -1
  401. package/dist/types/epsil/library-names.d.ts +1 -1
  402. package/dist/types/epsil/match-exhaustiveness.d.ts +1 -1
  403. package/dist/types/epsil/occurrences.d.ts +1 -1
  404. package/dist/types/epsil/operators.d.ts +1 -1
  405. package/dist/types/epsil/parse-epsil.d.ts +1 -1
  406. package/dist/types/epsil/parser.d.ts +1 -1
  407. package/dist/types/epsil/reserved-words.d.ts +1 -1
  408. package/dist/types/epsil/resolve-library-names.d.ts +1 -1
  409. package/dist/types/epsil/serialize-epsil.d.ts +1 -1
  410. package/dist/types/epsil/signature-notes.d.ts +1 -1
  411. package/dist/types/epsil/static-diagnostics.d.ts +1 -1
  412. package/dist/types/epsil/tokens.d.ts +1 -1
  413. package/dist/types/epsil.d.ts +2 -2
  414. package/dist/types/identities.d.ts +1 -1
  415. package/dist/types/integration-rules.d.ts +1 -1
  416. package/dist/types/interval.d.ts +1 -1
  417. package/dist/types/latex-syntax.d.ts +2 -2
  418. package/dist/types/math-json/symbols.d.ts +1 -1
  419. package/dist/types/math-json/types.d.ts +1 -1
  420. package/dist/types/math-json/utils.d.ts +1 -1
  421. package/dist/types/math-json.d.ts +2 -2
  422. package/dist/types/numerics.d.ts +1 -1
  423. package/dist/umd-min/compile.cjs +2 -2
  424. package/dist/umd-min/compute-engine.cjs +2 -2
  425. package/dist/umd-min/core.cjs +2 -2
  426. package/dist/umd-min/epsil.cjs +3 -3
  427. package/dist/umd-min/identities.cjs +2 -2
  428. package/dist/umd-min/integration-rules.cjs +2 -2
  429. package/dist/umd-min/interval.cjs +2 -2
  430. package/dist/umd-min/latex-syntax.cjs +2 -2
  431. package/dist/umd-min/math-json.cjs +2 -2
  432. package/dist/umd-min/numerics.cjs +2 -2
  433. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /** Epsil 0.129.0 */
1
+ /** Epsil 0.129.1 */
2
2
  (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Epsil = {}));})(this, (function (exports) { 'use strict';
3
3
  "use strict";var Epsil=(()=>{var SO=Object.defineProperty;var r1e=Object.getOwnPropertyDescriptor;var o1e=Object.getOwnPropertyNames;var s1e=Object.prototype.hasOwnProperty;var a1e=(e,n)=>{for(var t in n)SO(e,t,{get:n[t],enumerable:!0})},u1e=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of o1e(n))!s1e.call(e,r)&&r!==t&&SO(e,r,{get:()=>n[r],enumerable:!(i=r1e(n,r))||i.enumerable});return e};var l1e=e=>u1e(SO({},"__esModule",{value:!0}),e);var _Ye={};a1e(_Ye,{ComputeEngine:()=>zxe,canonicalLibraryName:()=>T_,epsilLibraryNames:()=>eJ,epsilNameOf:()=>S_,executeEpsil:()=>Xve,parseEpsil:()=>lO,resolveLibraryNames:()=>pO,serializeEpsil:()=>dO,version:()=>wYe});var po=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},ka=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},f1e=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)},c1e=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))},Fy=function(){throw SyntaxError("Invalid Param")};function TO(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 d1e=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 te.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 te.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]):Fy();break;case"string":t.im=t.re=0;var i=e.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,o=0;i===null&&Fy();for(var s=0;s<i.length;s++){var a=i[s];a===" "||a===" "||a===`
4
4
  `||(a==="+"?r++:a==="-"?o++:a==="i"||a==="I"?(r+o===0&&Fy(),i[s+1]!==" "&&!isNaN(Number(i[s+1]))?(t.im+=parseFloat((o%2?"-":"")+i[s+1]),s++):t.im+=parseFloat((o%2?"-":"")+"1"),r=o=0):((r+o===0||isNaN(Number(a)))&&Fy(),i[s+1]==="i"||i[s+1]==="I"?(t.im+=parseFloat((o%2?"-":"")+a),s++):t.re+=parseFloat((o%2?"-":"")+a),r=o=0))}r+o>0&&Fy();break;case"number":t.im=0,t.re=e;break;default:Fy()}return isNaN(t.re)||isNaN(t.im),t},te=class e{constructor(n,t){this.re=0,this.im=0;var i=d1e(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,o=i.im,s,a;return o===0?new e(n/r,t/r):Math.abs(r)<Math.abs(o)?(a=r/o,s=r*a+o,new e((n*a+t)/s,(t*a-n)/s)):(a=o/r,s=o*a+r,new e((n+t*a)/s,(t-n*a)/s))}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),o=TO(n,t);return n=Math.exp(i.re*o-i.im*r),t=i.im*o+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,o;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?o=.5*Math.sqrt(2*(i-n)):o=Math.abs(t)/Math.sqrt(2*(i+n)),new e(r,t<0?-o:o)}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)+f1e(t),Math.exp(n)*Math.sin(t))}log(){var n=this.re,t=this.im;return t===0&&n>0,new e(TO(n,t),Math.atan2(t,n))}abs(){return c1e(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)*po(t),Math.cos(n)*ka(t))}cos(){var n=this.re,t=this.im;return new e(Math.cos(n)*po(t),-Math.sin(n)*ka(t))}tan(){var n=2*this.re,t=2*this.im,i=Math.cos(n)+po(t);return new e(Math.sin(n)/i,ka(t)/i)}cot(){var n=2*this.re,t=2*this.im,i=Math.cos(n)-po(t);return new e(-Math.sin(n)/i,ka(t)/i)}sec(){var n=this.re,t=this.im,i=.5*po(2*t)+.5*Math.cos(2*n);return new e(Math.cos(n)*po(t)/i,Math.sin(n)*ka(t)/i)}csc(){var n=this.re,t=this.im,i=.5*po(2*t)-.5*Math.cos(2*n);return new e(Math.sin(n)*po(t)/i,-Math.cos(n)*ka(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(ka(n)*Math.cos(t),po(n)*Math.sin(t))}cosh(){var n=this.re,t=this.im;return new e(po(n)*Math.cos(t),ka(n)*Math.sin(t))}tanh(){var n=2*this.re,t=2*this.im,i=po(n)+Math.cos(t);return new e(ka(n)/i,Math.sin(t)/i)}coth(){var n=2*this.re,t=2*this.im,i=po(n)-Math.cos(t);return new e(ka(n)/i,-Math.sin(t)/i)}csch(){var n=this.re,t=this.im,i=Math.cos(2*t)-po(2*n);return new e(-2*ka(n)*Math.cos(t)/i,2*po(n)*Math.sin(t)/i)}sech(){var n=this.re,t=this.im,i=Math.cos(2*t)+po(2*n);return new e(2*po(n)*Math.cos(t)/i,-2*ka(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,o=1+n,s=r*r+t*t,a=s!==0?new e((o*r-t*t)/s,(t*r+o*t)/s):new e(n!==-1?n/0:0,t!==0?t/0:0),u=a.re;return a.re=TO(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())}};te.ZERO=new te(0,0);te.ONE=new te(1,0);te.I=new te(0,1);te.PI=new te(Math.PI,0);te.E=new te(Math.E,0);te.INFINITY=new te(1/0,1/0);te.NAN=new te(NaN,NaN);te.EPSILON=1e-15;var dJ=new Map,p1e=1e5;function Vn(e){if(e<=p1e){let n=dJ.get(e);return n===void 0&&(n=10n**BigInt(e),dJ.set(e,n)),n}return 10n**BigInt(e)}function wc(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 mJ(e,n,t){return e*n>>BigInt(t)}function hJ(e,n,t){return(e<<BigInt(t))/n}function I_(e,n){if(e===0n)return 0n;if(e<0n)throw new RangeError("fpsqrt: negative input");let t=e<<BigInt(n),i;if(n<m1e){i=_O(t);let a;do a=i,i=(i+t/i)/2n;while(Ia(i-a)>1n)}else i=NO(t,wc(t));let r=(i+t/i)/2n,o=Ia(i*i-t);return Ia(r*r-t)<o?r:i}function _O(e){let n=wc(e);if(n<=1023){let s=Math.sqrt(Number(e));if(Number.isFinite(s)&&s>=1)return BigInt(Math.floor(s))}let t=n-52,i=Number(e>>BigInt(t)),r=Math.sqrt(i);t&1&&(r*=Math.SQRT2);let o=BigInt(Math.round(r))<<BigInt(t>>1);return o>0n?o:1n}var gJ=1024,m1e=640;function NO(e,n){if(n<gJ){let o=_O(e),s;do s=o,o=(o+e/o)/2n;while(Ia(o-s)>1n);for(;o*o>e;)o-=1n;for(;(o+1n)*(o+1n)<=e;)o+=1n;return o}let t=n>>2<<1,i=NO(e>>BigInt(t),n-t)<<BigInt(t>>1),r;do r=i,i=(i+e/i)/2n;while(Ia(i-r)>1n);for(;i*i>e;)i-=1n;for(;(i+1n)*(i+1n)<=e;)i+=1n;return i}function Ia(e){return e<0n?-e:e}function By(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<Vn(t-1);)t--;for(;e>=Vn(t);)t++;return t}var h1e=.7;function CO(e,n){if(e===0n)return 1n<<BigInt(n);let t=Math.round(h1e*Math.sqrt(n)),i=t+8,r=n+i,o=BigInt(r),s=1n<<o,a=BigInt(i),u=e<<a,l=u<0n,f=l?-u:u,c=Math.max(0,wc(f)-r+t);f>>=BigInt(c),u=l?-f:f;let d=s,p=u;d+=p;for(let m=2;p=(p*u>>o)/BigInt(m),p!==0n;m++)d+=p;for(let m=0;m<c;m++)d=d*d>>o;return d+(1n<<a-1n)>>a}var g1e=4e4;function kO(e,n){let t=1n<<BigInt(n);if(e<=0n)throw new RangeError("fpln: input must be positive");return e===t?0n:n>=g1e?E1e(e,n):y1e(e,n)}function y1e(e,n){let t=BigInt(n),i=1n<<t,r=52,o=n-r,s;if(o>0){let m=Number(e>>BigInt(o))/2**r;s=BigInt(Math.round(Math.log(m)*2**r))<<BigInt(o)}else{let m=Number(e)/Number(i);s=BigInt(Math.round(Math.log(m)*Number(i)))}let a=e*CO(-s,n)>>t,l=(a-i<<t)/(a+i),f=l<0n?-l:l,c=f*f>>t,d=f,p=f;for(let m=3n;d=d*c>>t,d!==0n;m+=2n)p+=d/m;return s+(l<0n?-2n:2n)*p}var oh=null;function b1e(e){if(oh!==null){if(oh.bits===e)return oh.value;if(oh.bits>e)return oh.value>>BigInt(oh.bits-e)}let n=Math.ceil(e*R_)+12,t;if(n<=pJ.length){let i=pJ.slice(0,n);t=(BigInt(i)<<BigInt(e))/Vn(i.length)}else t=_1e(e);return oh={bits:e,value:t},t}function E1e(e,n){let t=BigInt(n),i=wc(e)-n,r=Math.max(2,Math.ceil(n/2+4-i)),o=e<<BigInt(r-2),s=1n<<t,a=o;for(;Ia(s-a)>1n;){let l=s+a>>1n;a=kx(s*a),s=l}return k_(n)*o/(2n*s)-BigInt(r)*b1e(n)}var Ly="314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635",R_=Math.log10(2),pJ="693147180559945309417232121458176568075500134360255254120680009493393621969694715605863326996418687542001481020570685733685520235758130557032670751635075961930727570828371435190307038623891673471123350115364497955239120475172681574932065155524734139525882950453007095326366642654104239157814952043740430385500801944170641671518644712839968171784546957026271631064546150257207402481637773389638550695260668341137273873722928956493547025762652098859693201965058554764703306793654432547632744951250406069438147104689946506220167720424524529612687946546193165174681392672504103802546259656869144192871608293803172714367782654877566485085674077648451464439940461422603193096735402574446070308096085047486638523138181676751438667476647890881437141985494231519973548803751658612753529166100071053558249879414729509293113897155998205654392871700072180857610252368892132449713893203784393530887748259701715591070882368362758984258918535302436342143670611892367891923723146723217205340164925687274778234453534764811494186423867767744060695626573796008670762571991847340226514628379048830620330611446300737194890027436439650025809365194430411911506080948793067865158870900605203468429736193841289652556539686022194122924207574321757489097706752687115817051137009158942665478595964890653058460258668382940022833005382074005677053046787001841624044188332327983863490015631218895606505531512721993983320307514084260914790012651682434438935724727882054862715527418772430024897945401961872339808608316648114909306675193393128904316413706813977764981769748689038877899912965036192707108892641052309247839173735012298424204995689359922066022046549415106139187885744245577510206837030866619480896412186807790208181588580001688115973056186676199187395200766719214592236720602539595436541655311295175989940056000366513567569051245926825743946483168332624901803824240824231452306140963805700702551387702681785163069025513703234053802145019015374029509942262995779647427138157363801729873940704242179972266962979939312706935747240493386530879758721699645129446491883771156701678598804981838896784134938314014073166472765327635919233511233389338709513209059272185471328975470797891384445466676192702885533423429899321803769154973340267546758873236778342916191810430116091695265547859732891763545556742863877463987101912431754255888301206779210280341206879759143081283307230300883494705792496591005860012341561757413272465943",x1e=13591409n,v1e=545140134n,S1e=10939058860032000n,T1e=47.11;function C_(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 d=BigInt(e);f=d*d*d*S1e}let c=l*(x1e+v1e*BigInt(e));return e&1&&(c=-c),[l,f,c]}let t=e+n>>1,[i,r,o]=C_(e,t),[s,a,u]=C_(t,n);return[i*s,r*a,a*o+i*u]}function yJ(e){return Math.max(2,Math.floor(e/T1e)+3)}function w1e(e){let[,n,t]=C_(0,yJ(e)),i=1n<<BigInt(e),r=kx(10005n*i*i);return n*426880n*r/t}function bJ(e){let[,n,t]=C_(0,yJ(Math.ceil(e/R_))),i=Vn(e),r=kx(10005n*i*i);return n*426880n*r/t}function wO(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,o]=wO(e,t),[s,a,u]=wO(t,n);return[i*s,r*a,a*o+i*u]}function _1e(e){let n=Math.max(2,Math.ceil(e/3.169925)+5),[,t,i]=wO(0,n);return(i<<BigInt(e+1))/(3n*t)}function kx(e){if(e<0n)throw new RangeError("bigintSqrt: negative input");if(e===0n)return 0n;let n=wc(e);if(n>=gJ)return NO(e,n);let t=_O(e),i;do i=t,t=(t+e/t)/2n;while(Ia(t-i)>1n);for(;t*t>e;)t-=1n;for(;(t+1n)*(t+1n)<=e;)t+=1n;return t}var sh=null;function k_(e){if(sh!==null){if(sh.bits===e)return sh.value;if(sh.bits>e)return sh.value>>BigInt(sh.bits-e)}let n=N1e(e);return sh={bits:e,value:n},n}function N1e(e){let n=Math.ceil(e*R_)+12;if(n+1<=Ly.length){let t=Ly.slice(0,n+1);return(BigInt(t)<<BigInt(e))/Vn(t.length-1)}return w1e(e)}function A_(e,n){let t=BigInt(n),i=1n<<t;if(e===0n)return[0n,i];let r=k_(n),o=2n*r,s=r/2n,a,u=Ia(e);if(u>i<<30n){let v=wc(u)-n+64,w=n+v,_=e<<BigInt(v),k=2n*k_(w),M=_%k;M<0n&&(M+=k),a=M>>BigInt(v)}else a=e%o;a<0n&&(a+=o);let l=1n,f=1n;a>3n*s?(a=o-a,l=-1n):a>r?(a=a-r,l=-1n,f=-1n):a>s&&(a=r-a,f=-1n);let c=Math.round(n*R_),d=Math.min(18,Math.max(2,Math.ceil(.87*Math.sqrt(c)))),p=0,m=i>>BigInt(d);for(;a>m;)a=a/2n,p++;let g=a,y=i,b=a,E=i,x=a*a,S=2n*t;for(let v=2;;v+=2){if(E=(E*x>>S)/(BigInt(v)*BigInt(v-1)),E===0n){b=(b*x>>S)/(BigInt(v+1)*BigInt(v)),b!==0n&&(v%4===2?(y-=E,g-=b):(y+=E,g+=b));break}if(b=(b*x>>S)/(BigInt(v+1)*BigInt(v)),v%4===2?(y-=E,g-=b):(y+=E,g+=b),b===0n)break}for(let v=0;v<p;v++){let w=2n*g*y>>t,_=(2n*y*y>>t)-i;g=w,y=_}return[l*g,f*y]}function Cx(e,n){if(e===0n)return 0n;if(e<0n)return-Cx(-e,n);let t=BigInt(n),i=1n<<t,o=k_(n)/2n;if(e>i){let p=(i<<t)/e;return o-Cx(p,n)}let s=4n*i/10n,a=0,u=e;for(;u>s;){let p=u*u,m=(i<<t)+p>>t,g=I_(m,n);u=(u<<t)/(i+g),a++}let l=u,f=u,c=u*u,d=2n*t;for(let p=3;f=f*c>>d,f!==0n;p+=2)p%4===3?l-=f/BigInt(p):l+=f/BigInt(p);for(let p=0;p<a;p++)l=2n*l;return l}var IO=NaN,I=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<=Ly.length)e._piFullPrecision===null&&(e._piFullPrecision=new e(Ly[0]+"."+Ly.slice(1))),i=e._piFullPrecision.toPrecision(t);else{let r=t+4;i=$n(bJ(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=I1e(n);return e._eulerGammaCache=t,e._eulerGammaCachePrecision=n,t}significand;exponent;_digits;_digitCount(){return this._digits??(this._digits=By(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]=M_(n,0);return}if(typeof n=="number"){[this.significand,this.exponent]=R1e(n);return}[this.significand,this.exponent]=SJ(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 IO;let p=this.exponent;if(Number.isNaN(p))return IO;if(n===0)return this.significand===0n?0:this.significand>0n?1:-1;if(!Number.isFinite(p))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)&&p>=0&&p<=15){let m=this.significand*Vn(p),g=BigInt(n);return m<g?-1:m>g?1:0}n=new e(n)}let t=this.exponent,i=n.exponent,r=this.significand,o=n.significand;if(t!==t||i!==i)return IO;if(!Number.isFinite(t)||!Number.isFinite(i))return!Number.isFinite(t)&&!Number.isFinite(i)?r===o?0:r>o?1:-1:Number.isFinite(t)?o>0n?-1:1:r>0n?1:-1;if(r===0n)return o===0n?0:o>0n?-1:1;if(o===0n)return r>0n?1:-1;if(r>0n&&o<0n)return 1;if(r<0n&&o>0n)return-1;if(t===i)return r<o?-1:r>o?1:0;let s=this._digitCount(),a=n._digitCount(),u=s+t,l=a+i;if(u!==l){let p=r>0n?1:-1;return u>l?p:-p}let f=r,c=o,d=Math.abs(t-i);if(d>1e3){let p=s,m=a,g=Math.max(p,m)+1;p<g&&(f=f*Vn(g-p)),m<g&&(c=c*Vn(g-m))}else t<i?c=c*Vn(d):f=f*Vn(d);return f<c?-1:f>c?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*Vn(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 $n(this.significand+n.significand,t);let s=t-i;return s>0?$n(this.significand*Vn(s)+n.significand,i):$n(this.significand+n.significand*Vn(-s),t)}if(t!==t||i!==i)return e.NAN;let r=!Number.isFinite(t),o=!Number.isFinite(i);return r&&o?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 $n(this.significand-n.significand,t);let s=t-i;return s>0?$n(this.significand*Vn(s)-n.significand,i):$n(this.significand-n.significand*Vn(-s),t)}if(t!==t||i!==i)return e.NAN;let r=!Number.isFinite(t),o=!Number.isFinite(i);return r&&o?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 $n(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,o=n.significand>0n?1n:-1n;return r*o>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}_mulToPrecision(n,t){typeof n=="number"&&(n=new e(n));let i=this.exponent,r=n.exponent,o=this.significand,s=n.significand;if(o!==0n&&s!==0n&&Number.isFinite(i)&&Number.isFinite(r)){let a=o*s,u=i+r,l=this._digitCount()+n._digitCount()-1,c=(a<0n?-a:a)>=Vn(l)?l+1:l;return c<=t?$n(a,u):EJ(a,u).roundToPrecKnownDigits(t,c)}return this.mul(n).toPrecision(t)}neg(){let n=this.significand;return n===0n?this:Number.isFinite(this.exponent)?$n(-n,this.exponent):n>0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY}abs(){return this.significand>=0n?this:Number.isFinite(this.exponent)?$n(-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($n(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($n(1n,0)):t}return this}round(){let n=this.exponent;if(n>=0)return this;if(Number.isFinite(n)){let t=$n(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/Vn(-n);return $n(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,o=n.significand;if(Number.isFinite(t)&&Number.isFinite(i)){if(o===0n)return r===0n?e.NAN:r>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY;if(r===0n)return $n(0n,0);let u=e.precision,l=10,f=this._digitCount(),c=n._digitCount(),d=u+l+Math.max(0,c-f),p=Vn(d),m=r*p/o,g=t-i-d,y=m<0n?-m:m,b=f+d-c,E=y>=Vn(b)?b+1:b;return EJ(m,g).roundToPrecKnownDigits(u,E)}if(t!==t||i!==i)return e.NAN;let s=!Number.isFinite(t),a=!Number.isFinite(i);if(s&&a)return e.NAN;if(s){let u=r>0n?1n:-1n,l=o>0n?1n:o<0n?-1n:1n;return u*l>0n?e.POSITIVE_INFINITY:e.NEGATIVE_INFINITY}return $n(0n,0)}inv(){return $n(1n,0).div(this)}divToward(n,t){typeof n=="number"&&(n=new e(n));let i=this.exponent,r=n.exponent,o=this.significand,s=n.significand;if(!Number.isFinite(i)||!Number.isFinite(r)||s===0n||o===0n)return this.div(n);let a=o<0n!=s<0n,u=o<0n?-o:o,l=s<0n?-s:s,f=e.precision,d=f+10+Math.max(0,n._digitCount()-this._digitCount()),p=u*Vn(d),m=p/l,g=p%l!==0n,y=i-r-d,b=this._digitCount()+d-n._digitCount(),E=m>=Vn(b)?b+1:b,x=a?t==="floor":t==="ceiling",[S,v]=RO(m,g,y,f,x,E);return $n(a?-S:S,v)}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,o=this.exponent,s=o+this._digitCount()-1,a=Math.floor(s/2),u=t+i-a;o+2*u<0&&(u=Math.ceil(-o/2)+1);let l=o+2*u,f=l>=0?r*Vn(l):r/Vn(-l),c=kx(f),d=c*c!==f,[p,m]=RO(c,d,-u,t,n==="ceiling");return $n(p,m)}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 $n(0n,0);let r=t-i,o=r>=0?this.significand*Vn(r):this.significand,s=r>=0?n.significand:n.significand*Vn(-r),a=o/s;return this.sub($n(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 $n(1n,0);if(!this.isFinite())return a>0n?this.significand<0n&&a%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY:$n(0n,0);if(this.isZero())return a>0n?$n(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,c=f>0?Number(u/10n**BigInt(f)):Number(u),d=Math.log10(c)+f+this.exponent,p=Number(a)*d;if(p>9e15)return this.significand<0n&&a%2n!==0n?e.NEGATIVE_INFINITY:e.POSITIVE_INFINITY;if(p<-9e15)return $n(0n,0);let m=e.precision,g=a.toString(2).length,y=Math.min(2*g+5,100),b=m+y,E=$n(1n,0),x=this,S=a;for(;S>0n;)S&1n&&(E=E._mulToPrecision(x,b)),S>>=1n,S>0n&&(x=x._mulToPrecision(x,b));return E.toPrecision(m)}if(!this.isFinite())return this.significand<0n?e.NAN:n.significand>0n?e.POSITIVE_INFINITY:e.ZERO;if(this.isZero())return n.significand>0n?e.ZERO:e.POSITIVE_INFINITY;if(this.significand<0n)return e.NAN;let t=this.exponent+this._digitCount()-1,r=n.exponent+n._digitCount()-1+Math.log10(Math.abs(t)*2.303+3)+1,o=Math.min(20,Math.max(2,Math.ceil(r)+2)),s=e.precision;e.precision=s+o;try{let a=k1e(this,s+o);return n.mul(a).exp().toPrecision(s)}finally{e.precision=s}}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,o=n?"-":"";if(r>20||r<-6){let u=i===1?t:t[0]+"."+t.slice(1),l=r>=0?"+":"";return`${o}${u}e${l}${r}`}if(this.exponent>=0)return o+t+"0".repeat(this.exponent);let s=-this.exponent;if(s<i){let u=t.slice(0,i-s),l=t.slice(i-s);return`${o}${u}.${l}`}let a=s-i;return`${o}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,o=this.exponent+t,s,a;if(o>=0)a=r===0n,s=a?"0":r.toString()+"0".repeat(o);else{let c=Vn(-o),d=r/c,p=r%c,m=c/2n,g;p>m?g=d+1n:p<m||c%2n!==0n||d%2n===0n?g=d:g=d+1n,a=g===0n,s=g.toString()}let u=i&&!a?"-":"";if(t===0)return`${u}${s}`;if(s.length<=t){let c=s.padStart(t,"0");return`${u}0.${c}`}let l=s.slice(0,s.length-t),f=s.slice(s.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,o=Vn(r),s=i/o,a=i-s*o,u=o/2n;(a>u||a===u&&s%2n!==0n)&&(s+=1n);let l=this.significand<0n?-s:s;return $n(l,this.exponent+r)}toPrecisionToward(n,t){if(this.significand===0n||!Number.isFinite(this.exponent))return this;let i=this._digitCount();if(i<=n)return this;let r=this.significand<0n,[o,s]=RO(r?-this.significand:this.significand,!1,this.exponent,n,t==="ceiling"!==r,i);return $n(r?-o:o,s)}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*Vn(this.exponent);let n=Vn(-this.exponent);return this.significand/n}},C1e=8,Ix=[];function k1e(e,n){let t=e.significand,i=e.exponent;for(let o=Ix.length-1;o>=0;o--){let s=Ix[o];if(s.prec===n&&s.exp===i&&s.sig===t)return s.ln}let r=e.ln();return Ix.push({sig:t,exp:i,prec:n,ln:r}),Ix.length>C1e&&Ix.shift(),r}function I1e(e){let n=e+20+Math.ceil(Math.log10(e+10)),t=I.precision;I.precision=n;try{let i=Math.ceil(n*Math.LN10/4)+5,r=new I(i),o=r.mul(r),s=I.ONE,a=I.ONE,u=I.ZERO,l=I.ZERO,f=I.ONE.div(new I(10).pow(n)),c=6*i+100;for(let d=1;d<=c;d++){let p=new I(d).mul(d);if(s=s.mul(o).div(p).toPrecision(n),l=l.add(I.ONE.div(d)).toPrecision(n),a=a.add(s).toPrecision(n),u=u.add(s.mul(l)).toPrecision(n),d>i&&s.lt(a.mul(f)))break}return u.div(a).sub(r.ln()).toPrecision(e)}finally{I.precision=t}}function $n(e,n){let[t,i]=M_(e,n),r=Object.create(I.prototype);return r.significand=t,r.exponent=i,r}function EJ(e,n){let t=Object.create(I.prototype);return t.significand=e,t.exponent=n,t}function RO(e,n,t,i,r,o){if(e===0n)return[r&&n?1n:0n,t];let s=o??By(e);if(s<=i)return[r&&n?e+1n:e,t];let a=s-i,u=Vn(a),l=e/u,f=n||e%u!==0n;return r&&f&&(l+=1n),[l,t+a]}var xJ=1000000000n,vJ=1000n;function M_(e,n){if(e===0n)return[0n,0];if((e&1n)!==0n)return[e,n];if(e%10n!==0n)return[e,n];for(;e%xJ===0n;)e/=xJ,n+=9;for(;e%vJ===0n;)e/=vJ,n+=3;for(;e%10n===0n;)e/=10n,n+=1;return[e,n]}function R1e(e){return Number.isNaN(e)?[0n,NaN]:e===1/0?[1n,1/0]:e===-1/0?[-1n,1/0]:Number.isInteger(e)?M_(BigInt(e),0):SJ(e.toString())}function SJ(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 o=n.indexOf("."),s,a;o===-1?(s=n,a=""):(s=n.slice(0,o),a=n.slice(o+1)),s=s.replace(/^0+/,"")||"0";let u=s+a;if(u.length===0||!/^\d+$/.test(u))return[0n,NaN];let l=BigInt(u);r&&(l=-l);let f=-a.length;return M_(l,f+t)}var A1e=Math.log2(10),_J=Math.log10(2),M1e=16,MO=1e6;function _c(e,n){let t=Math.ceil(n*A1e)+M1e,i=BigInt(t);return e.exponent>=0?[e.significand*Vn(e.exponent)<<i,t]:[(e.significand<<i)/Vn(-e.exponent),t]}function Nc(e,n,t){if(e===0n)return I.ZERO;let i=e<0n,r=i?-e:e,o=BigInt(n),s=wc(r)-n,a=Math.floor(s*_J),u=t+4-a,l,f;if(u>=0)l=r*Vn(u)+(1n<<o-1n)>>o,f=-u;else{let d=Vn(-u)<<o;l=(r+d/2n)/d,f=-u}if(l===0n)return I.ZERO;let c=By(l);if(c>t){let d=c-t,p=Vn(d),m=p/2n,g=l%p;l=l/p,g>=m&&(l+=1n),f+=d}return $n(i?-l:l,f)}function Fo(e){return e.exponent+e._digitCount()-1}function AO(e,n){if(e===0n)return 0;let t=e<0n?-e:e,i=n*_J-(By(t)-1);return i>0?Math.ceil(i):0}var NJ=5,TJ=BigInt(Number.MAX_SAFE_INTEGER),ah=null;function CJ(e){if(ah!==null){if(ah.bits===e)return ah.value;if(ah.bits>e)return ah.value>>BigInt(ah.bits-e)}let n=kO(10n<<BigInt(e),e);return ah={bits:e,value:n},n}I.prototype.sqrt=function(){if(this.isNaN())return I.NAN;if(this.isZero())return I.ZERO;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NAN;if(this.significand<0n)return I.NAN;let e=I.precision,n=e+10,t=Fo(this),i=Math.floor(t/2),r=$n(this.significand,this.exponent-2*i),[o,s]=_c(r,n),a=I_(o,s),u=Nc(a,s,e);return $n(u.significand,u.exponent+i)};I.prototype.cbrt=function(){if(this.isNaN())return I.NAN;if(this.isZero())return I.ZERO;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NEGATIVE_INFINITY;if(this.significand<0n)return this.neg().cbrt().neg();let e=I.precision,n=e+10,t=Fo(this),i=Math.floor(t/3),r=$n(this.significand,this.exponent-3*i),[o,s]=_c(r,n),a=o<<BigInt(2*s),u,l=r.toNumber();if(s<=1e3&&Number.isFinite(l)&&l>0){let d=Number(1n<<BigInt(s)),p=Math.cbrt(l);Number.isFinite(p)&&p>0?(u=BigInt(Math.floor(p*d)),u===0n&&(u=1n)):u=wJ(a)}else u=wJ(a);let f;do{f=u;let d=u*u;if(d===0n){u=1n;break}u=(2n*u+a/d)/3n}while(Ia(u-f)>1n);{let d=(2n*u+a/(u*u))/3n,p=Ia(u*u*u-a);Ia(d*d*d-a)<p&&(u=d)}let c=Nc(u,s,e);return $n(c.significand,c.exponent+i)};I.sqrt=function(e){return e.sqrt()};I.cbrt=function(e){return e.cbrt()};I.prototype.exp=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.ZERO;if(this.isZero())return I.ONE;if(Fo(this)>=17)return this.significand>0n?I.POSITIVE_INFINITY:I.ZERO;let e=I.precision,n=Math.max(0,this.exponent+this._digitCount()),t=e+20+n,[i,r]=_c(this,t),o=CJ(r),s=i/o,a=i-s*o;if(a<0n&&(s-=1n,a+=o),s>TJ||s<-TJ)return s>0n?I.POSITIVE_INFINITY:I.ZERO;let u=Nc(CO(a,r),r,e),l=u.exponent+Number(s);return Number.isSafeInteger(l)?$n(u.significand,l):s>0n?I.POSITIVE_INFINITY:I.ZERO};I.prototype.ln=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NAN;if(this.isZero())return I.NEGATIVE_INFINITY;if(this.significand<0n)return I.NAN;if(this.eq(1))return I.ZERO;let e=I.precision,n=this.significand,t=this._digitCount(),i=this.exponent+t-1,r=$n(n,-(t-1)),o=Math.abs(i).toString().length,s=0;if(i===0||i===-1){let d=this.sub(I.ONE);if(!d.isZero()){let p=Fo(d);p<0&&(s=-p)}}let a=e+20+o+s,[u,l]=_c(r,a),f=CJ(l),c=kO(u,l)+BigInt(i)*f;return Nc(c,l,e)};I.prototype.log=function(e){let n=e instanceof I?e:new I(e),t=I.precision;I.precision=t+10;try{return this.ln().div(n.ln()).toPrecision(t)}finally{I.precision=t}};I.exp=function(e){return e.exp()};I.ln=function(e){return e.ln()};I.log10=function(e){return e.log(10)};I.log2=function(e){return e.log(2)};I.prototype.sin=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return I.NAN;if(this.isZero())return I.ZERO;let e=I.precision,n=Fo(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=e+15+(n<0?-n:0);if(n+t+30>MO)return I.NAN;let[i,r]=_c(this,t),[o]=A_(i,r);return Nc(o,r,e)};I.prototype.cos=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return I.NAN;if(this.isZero())return I.ONE;let e=I.precision,n=Fo(this),t=0;for(let i=0;;i++){let r=e+15+t;if(n+r+30>MO)return I.NAN;let[o,s]=_c(this,r),[,a]=A_(o,s);if(a===0n){if(i>=3)return I.ZERO;t+=e+30;continue}let u=AO(a,s);if(u<=t+NJ||i>=3)return Nc(a,s,e);t=u+5}};I.prototype.tan=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return I.NAN;if(this.isZero())return I.ZERO;let e=I.precision,n=Fo(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 o=e+15+t+i;if(n+o+30>MO)return I.NAN;let[s,a]=_c(this,o),[u,l]=A_(s,a);if(l===0n){if(r>=3)return u>0n?I.POSITIVE_INFINITY:I.NEGATIVE_INFINITY;i+=e+30;continue}let f=Math.max(u===0n?0:AO(u,a),AO(l,a));if(f<=i+NJ||r>=3){let c=(u<<BigInt(a))/l;return Nc(c,a,e)}i=f+5}};I.prototype.atan=function(){if(this.isNaN())return I.NAN;if(this.isZero())return I.ZERO;if(!this.isFinite()){let s=I.PI.div(I.TWO);return this.significand>0n?s:s.neg()}let e=I.precision,n=Fo(this);if(n<0&&-2*n>=e+4)return this.toPrecision(e);let t=e+15+(n<0?-n:0),[i,r]=_c(this,t),o=Cx(i,r);return Nc(o,r,e)};I.prototype.asin=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return I.NAN;if(this.isZero())return I.ZERO;let e=this.abs(),n=I.ONE;if(e.gt(n))return I.NAN;if(e.eq(n)){let p=I.PI.div(I.TWO);return this.significand>0n?p:p.neg()}let t=I.precision,i=Fo(this);if(i<0&&-2*i>=t+4)return this.toPrecision(t);let r=t+20+(i<0?-i:0),[o,s]=_c(this,r),a=1n<<BigInt(s),u=mJ(o,o,s),l=a-u,f=I_(l,s),c=hJ(o,f,s),d=Cx(c,s);return Nc(d,s,t)};I.prototype.acos=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return I.NAN;if(this.abs().gt(I.ONE))return I.NAN;if(this.eq(1))return I.ZERO;if(this.eq(-1))return I.PI;let n=I.precision,t=I.precision;I.precision=n+10;try{let i=I.TWO;if(this.significand>=0n){let o=I.ONE.sub(this)._mulToPrecision(I.HALF,n+10).sqrt();return i._mulToPrecision(o.asin(),n)}let r=I.ONE.add(this)._mulToPrecision(I.HALF,n+10).sqrt();return I.PI.sub(i.mul(r.asin())).toPrecision(n)}finally{I.precision=t}};I.sin=function(e){return e.sin()};I.cos=function(e){return e.cos()};I.tan=function(e){return e.tan()};I.asin=function(e){return e.asin()};I.acos=function(e){return e.acos()};I.atan=function(e){return e.atan()};I.atan2=function(e,n){let t=e instanceof I?e:new I(e);if(t.isNaN()||n.isNaN())return I.NAN;let i=I.PI,r=i.div(I.TWO);if(n.isZero())return t.isZero()?I.ZERO:t.significand>0n?r:r.neg();let o=t.div(n);return n.significand>0n?o.atan():t.significand>=0n?o.atan().add(i):o.atan().sub(i)};I.prototype.sinh=function(){if(this.isNaN())return I.NAN;if(this.isZero())return I.ZERO;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NEGATIVE_INFINITY;let e=I.precision,n=Fo(this);if(n<0){if(-2*n>=e+4)return this.toPrecision(e);let r=I.precision;I.precision=e-n+5;try{let o=this.exp();return o.sub(o.inv())._mulToPrecision(I.HALF,e)}finally{I.precision=r}}if(Math.abs(this.toNumber())>1.16*(e+3)){let r=this.abs().exp().div(I.TWO);return this.significand>0n?r:r.neg()}let t=this.exp(),i=t.inv();return t.sub(i).div(I.TWO)};I.prototype.cosh=function(){if(this.isNaN())return I.NAN;if(this.isZero())return I.ONE;if(!this.isFinite())return I.POSITIVE_INFINITY;let e=I.precision;if(Math.abs(this.toNumber())>1.16*(e+3))return this.abs().exp().div(I.TWO);let n=this.exp(),t=n.inv();return n.add(t).div(I.TWO)};I.prototype.tanh=function(){if(this.isNaN())return I.NAN;if(this.isZero())return I.ZERO;if(!this.isFinite())return this.significand>0n?I.ONE:I.NEGATIVE_ONE;let e=I.precision,n=Fo(this);if(n<0){if(-2*n>=e+4)return this.toPrecision(e);let i=I.precision;I.precision=e-n+5;try{let r=this.mul(I.TWO).exp();return r.sub(I.ONE).div(r.add(I.ONE)).toPrecision(e)}finally{I.precision=i}}if(Math.abs(this.toNumber())>1.16*(e+3))return this.significand>0n?I.ONE:I.NEGATIVE_ONE;let t=this.mul(I.TWO).exp();return t.sub(I.ONE).div(t.add(I.ONE))};I.sinh=function(e){return e.sinh()};I.cosh=function(e){return e.cosh()};I.tanh=function(e){return e.tanh()};I.prototype.expm1=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NEGATIVE_ONE;if(this.isZero())return I.ZERO;let e=I.precision,n=Fo(this);if(n<0&&-n>=e+2)return this.toPrecision(e);if(n<0){let t=I.precision;I.precision=e-n+5;try{return this.exp().sub(I.ONE).toPrecision(e)}finally{I.precision=t}}return this.exp().sub(I.ONE)};I.prototype.log1p=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NAN;if(this.isZero())return I.ZERO;let e=I.ONE.add(this);if(e.isZero())return I.NEGATIVE_INFINITY;if(e.significand<0n)return I.NAN;let n=I.precision,t=Fo(this);if(t<0&&-t>=n+2)return this.toPrecision(n);if(t<0){let i=I.precision;I.precision=n-t+5;try{return I.ONE.add(this).ln().toPrecision(n)}finally{I.precision=i}}return I.ONE.add(this).ln()};I.prototype.asinh=function(){if(this.isNaN())return I.NAN;if(this.isZero())return I.ZERO;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NEGATIVE_INFINITY;let e=this.significand<0n,n=this.abs(),t=I.precision,i=Fo(this);if(i<0&&-2*i>=t+4)return this.toPrecision(t);let r=()=>n.add(n.mul(n).add(I.ONE).sqrt()).ln(),o;if(i<0){let s=I.precision;I.precision=t-i+5;try{o=r().toPrecision(t)}finally{I.precision=s}}else o=r();return e?o.neg():o};I.prototype.acosh=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:I.NAN;if(this.lt(I.ONE))return I.NAN;if(this.eq(1))return I.ZERO;let e=this.sub(I.ONE).div(I.TWO).sqrt();return I.TWO.mul(e.asinh())};I.prototype.atanh=function(){if(this.isNaN())return I.NAN;if(!this.isFinite())return I.NAN;if(this.isZero())return I.ZERO;let e=this.abs();if(e.eq(1))return this.significand>0n?I.POSITIVE_INFINITY:I.NEGATIVE_INFINITY;if(e.gt(I.ONE))return I.NAN;let n=I.precision,t=Fo(this);if(-2*t>=n+4)return this.toPrecision(n);let i=I.precision;I.precision=n-t+5;try{return I.ONE.add(this).div(I.ONE.sub(this)).ln()._mulToPrecision(I.HALF,n)}finally{I.precision=i}};I.prototype.nthRoot=function(e){if(this.isNaN()||!Number.isInteger(e)||e===0)return I.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 I.ZERO;if(!this.isFinite())return this.significand>0n?I.POSITIVE_INFINITY:e%2===0?I.NAN:I.NEGATIVE_INFINITY;if(this.significand<0n)return e%2===0?I.NAN:this.neg().nthRoot(e).neg();let n=I.precision,t=I.precision;I.precision=n+8;try{return I.exp(this.ln().div(new I(e))).toPrecision(n)}finally{I.precision=t}};I.asinh=function(e){return e.asinh()};I.acosh=function(e){return e.acosh()};I.atanh=function(e){return e.atanh()};I.expm1=function(e){return e.expm1()};I.log1p=function(e){return e.log1p()};I.nthRoot=function(e,n){return e.nthRoot(n)};function wJ(e){let n=wc(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),o=Math.floor(t/3),s=t%3;s===1&&(r*=1.2599210498948732),s===2&&(r*=1.5874010519681994);let a=BigInt(Math.round(r))<<BigInt(o);return a>0n?a:1n}var P1e=["sgn","type","effects","lazyValue","storedValue","elementMemo","collectionFacet","typeParse"],O1e=["hit","hitConstant","hitFastPath","missCold","missGeneration","missGenerationWasted","missEpoch","missScope","missKeyShape","missDependency","declineCycle","declineStore","evictClear"],D1e=["generation","mutationGeneration","semanticEpoch","valueWrite","ephemeralValueWrite"],$1e=["clean","dirty"],We=(()=>{if(typeof process>"u")return!1;let e=process.env?.CE_CACHE_STATS;return e!==void 0&&e!=="0"})(),P_=We||typeof process<"u"&&!1;function F1e(){let e={};for(let n of O1e)e[n]=0;return e}var L1e=(()=>{let e={};for(let n of P1e)e[n]=F1e();return e})(),B1e=(()=>{let e={};for(let n of D1e)e[n]=0;return e})(),V1e=(()=>{let e={};for(let n of $1e)e[n]=0;return e})();function dn(e,n){L1e[e][n]+=1}function Vy(e){B1e[e]+=1}function kJ(e){V1e[e]+=1}var jy=["number","complex","imaginary","real","rational","integer","infinity","nan"],PO=["indexed_collection","list","tuple","range","string"],O_=Object.freeze({kind:"indexed_collection",elements:"integer"}),D_=Object.freeze({kind:"indexed_collection",elements:"character"}),OO=Object.freeze({kind:"list",elements:"unknown"}),DO=Object.freeze({kind:"set",elements:"unknown"}),Rx=Object.freeze({kind:"dictionary",values:"unknown"}),$_=Object.freeze({kind:"collection",elements:"unknown"}),Ax=Object.freeze({kind:"indexed_collection",elements:"unknown"}),An=Object.freeze({kind:"collection",elements:"any"}),un=Object.freeze({kind:"indexed_collection",elements:"any"}),F_=Object.freeze({kind:"dictionary",values:"any"}),nt=Object.freeze({kind:"union",types:[{kind:"value",value:1/0},{kind:"value",value:-1/0}]}),jn=Object.freeze({kind:"union",types:["real",{kind:"value",value:1/0},{kind:"value",value:-1/0}]}),L_=[...PO,"collection","set","record","dictionary"],B_=["scalar",...jy,"boolean","character"],$O=["value","color","regexp","type","object",...L_,...B_],FO=["expression","symbol","function",...$O],LO=["any","unknown","nothing","missing","never","error",...FO],Ra=new Set(jy),IJ=new Set(L_),RJ=new Set(B_),uh=new Set(LO),Mx="Variadic arguments cannot be used with optional arguments";function ps(e){if(typeof e=="string")return!1;switch(e.kind){case"signature":return(e.optArgs?.length??0)>0&&e.variadicArg!==void 0?!0:ps(e.result)||(e.args?.some(n=>ps(n.type))??!1)||(e.optArgs?.some(n=>ps(n.type))??!1)||e.variadicArg!==void 0&&ps(e.variadicArg.type)||(e.typeParams?.some(n=>n.bound!==void 0&&ps(n.bound))??!1);case"record":case"object":return Object.values(e.elements).some(ps);case"union":case"intersection":return e.types.some(ps);case"negation":return ps(e.type);case"list":case"set":case"collection":case"indexed_collection":case"broadcastable":return ps(e.elements);case"dictionary":return ps(e.values);case"tuple":return e.elements.some(n=>ps(n.type));case"reference":return e.args?.some(ps)??!1;default:return!1}}function Ll(e){return typeof e!="string"?!1:uh.has(e)}function Aa(e){return typeof e=="string"?uh.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==="object"||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==="variable"||e.kind==="reference"}var V_=Object.freeze({complexInfinity:!0});function Ur(e){return typeof e=="object"&&e!==null&&e.complexInfinity===!0}function j1e(e){return e==="\u211D"||e==="\u2124"||e==="\u211A"||e==="\u2102"||e==="\u2115"}var Px=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===`
@@ -1874,7 +1874,7 @@ return function (_) { ${r} };`)(this.IA);return new Proxy(this,{apply:(s,a,u)=>{
1874
1874
  `,l[p]=p):typeof g=="string"&&(l[p]=g)}let c=this.createTarget({mode:t.mode,constantFold:!1,varsKeys:s?new Set(Object.keys(s)):void 0,foldExcludedOps:Object.keys(l).length>0?new Set(Object.keys(l)):void 0,unrollSkipHeads:i,unrollMinWidth:1,unrollConstantLists:!0,foldEmittedConstant:t.constantFold===!1?void 0:(p,m)=>c_(m,!1,yz(c)),constant:p=>_P[p],functions:p=>l?.[p]?l[p]:LEe(p),var:p=>{if(s&&Object.hasOwn(s,p))return s[p];let m=_P[p];if(m!==void 0)return m;if(u.includes(p))return $Ee(p);if(n.engine._getSymbolValue(p)===void 0)return $Ee(p)},preamble:(a??"")+f,userFunctions:{defs:new Map,compiling:new Set},naming:A.newNamingContext(n,[a,f,...Object.values(l),...s?Object.values(s):[]])});c.userFunctions.root=c,n=us(A.inlineCollectionValuedCallsAtRoot(n,c),r),u=n.unknowns,A.openCseSession(n,c,{enabled:t.cse,isOverriddenOperator:p=>Object.prototype.hasOwnProperty.call(l,p),isStringVar:p=>s!==void 0&&typeof s[p]=="string",isVarsKey:p=>s!==void 0&&Object.prototype.hasOwnProperty.call(s,p)});let d=yGe(n,c);return A.withReferences(d,n,c,s?new Set(Object.keys(s)):void 0)}};function yGe(e,n){rGe(n);let t;try{let c=XUe(e,n),d=c===void 0&&XEe.has((Yd(e,n)??e).operator);t=c!==void 0?A.compileCseRoot(e,n,0,()=>`[${c.map(p=>A.compileValueOperand(p,n)).join(", ")}]`):d?A.compileCseRoot(e,n,0,()=>Ec(e,n)??A.compile(e,n)):A.compileCseRoot(e,n)}catch(c){return{target:"interval-js",success:!1,code:"",error:c.message,diagnostic:ac(c),...A.modeReport()}}let i=A.userFunctionsPreamble(n),r=gGe(i,t,n),o=r.expression,s=MP.get(A.namingContext(n)),a=[s&&s.length>0?`let ${s.join(", ")};`:"",r.declarations].filter(c=>c).join(`
1875
1875
  `),u=[n.preamble,r.definitions].filter(c=>c).join(`
1876
1876
  `),l=[n.preamble,a,r.definitions].filter(c=>c).join(`
1877
- `),f=new mz(o,u,a);return{target:"interval-js",success:!0,code:o,...l?{preamble:l}:{},calling:"expression",run:f}}var $P=class{_targets=new Map;register(n,t){Cge(n),Ige(t),this._targets.set(n,t)}get(n){return this._targets.get(n)}list(){return[...this._targets.keys()]}unregister(n){this._targets.delete(n)}registerDefaults(){this.register("javascript",new jE),this.register("glsl",new YE),this.register("wgsl",new Qw),this.register("python",new XE),this.register("interval-js",new ux)}};var FP=class{_listeners=[];_registered=new WeakSet;_pending=!1;_version=0;listen(n){return this._registered.has(n)||(this._registered.add(n),this._listeners.push(n)),()=>this._unsubscribe(n)}_unsubscribe(n){this._registered.has(n)&&(this._registered.delete(n),this._listeners=this._listeners.filter(t=>t!==n))}notify(){if(this._pending)return;this._pending=!0;let n=this._version+1;queueMicrotask(()=>{if(n!==this._version+1){this._pending=!1;return}this.notifyNow()})}notifyNow(){this._version++;for(let n of this._listeners)try{n?.onConfigurationChange?.()}catch(t){console.error("Listener error:",t)}this._pending=!1}};function bGe(e){switch(e.kind){case"assumption":case"inference":case"config":case"binding-repair":return!0;case"redefine":case"type-write":return e.callableBefore||e.callableAfter;case"scope-pop":return e.assumptionsDirty;case"value-write":return e.callable;case"declare":return!e.scratch&&(e.callable||e.shadowsCallable);case"object-store":return!1}}var EGe=(()=>{if(typeof process>"u")return!1;let e=process.env?.CE_OBJECT_STORE_BUMPS_ANY;return e!==void 0&&e!=="0"})();function xGe(e){switch(e.kind){case"value-write":return{any:!0,semantic:!e.ephemeral,world:!1};case"declare":return e.scratch?{any:!1,semantic:!1,world:!1}:{any:!0,semantic:!1,world:!1};case"binding-repair":return{any:!0,semantic:!1,world:!1};case"redefine":return e.callableAfter?{any:!1,semantic:!0,world:!0}:{any:!1,semantic:!1,world:!1};case"type-write":return{any:!0,semantic:!1,world:!1};case"scope-pop":return{any:!e.transient&&!e.clean||e.assumptionsDirty,semantic:e.assumptionsDirty,world:e.assumptionsDirty};case"assumption":return{any:!0,semantic:!0,world:!0};case"inference":return e.valueType?{any:!1,semantic:!1,world:!1}:e.symbolSignature?{any:!0,semantic:!0,world:!0}:{any:!0,semantic:!0,world:!0};case"config":return{any:!0,semantic:!0,world:!0};case"object-store":return EGe?{any:!0,semantic:!1,world:!1}:{any:!1,semantic:!1,world:!1}}}var LP=class{_anyVersion=0;_semanticVersion=0;_worldVersion=0;_callableVersion=0;_ephemeralWriteDepth=0;_factSuppressionDepth=0;_scratchDeclarationScopes=[];_tracker=new FP;get anyVersion(){return this._anyVersion}get semanticVersion(){return this._semanticVersion}get worldVersion(){return this._worldVersion}get callableVersion(){return this._callableVersion}get ephemeralWriteDepth(){return this._ephemeralWriteDepth}set ephemeralWriteDepth(n){this._ephemeralWriteDepth=n}get factSuppressionDepth(){return this._factSuppressionDepth}set factSuppressionDepth(n){this._factSuppressionDepth=n}get scratchDeclarationScopes(){return this._scratchDeclarationScopes}noteStateEvent(n){let t=xGe(n);t.any&&(this._anyVersion+=1),t.semantic&&(this._semanticVersion+=1),t.world&&(this._worldVersion+=1),bGe(n)&&(this._callableVersion+=1),We&&(t.any&&Vy("generation"),t.semantic&&Vy("mutationGeneration"),t.world&&Vy("semanticEpoch"))}reset(n){this._scratchDeclarationScopes.length=0,this.noteStateEvent({kind:"config"}),n.refreshNumericConstants(),n.resetCommonSymbols(),n.purgeCaches(),this._tracker.notifyNow()}listen(n){return this._tracker.listen(n)}};function vGe(e){return!!(e===void 0||e==="Number"||e===!0||Array.isArray(e)&&e.includes("Number"))}function lxe(e,n,t,i){let r=i?.canonical??!0,o=i?.metadata,s=t.normalize(),a=s.toLowerCase();if(a==="infinity"||a==="+infinity")return e.PositiveInfinity;if(a==="-infinity")return e.NegativeInfinity;if(e.strict&&!Qt(s))return e.error(["invalid-symbol",ca(s)],s);if(!r)return new zs(e,s,{metadata:o});if(e._isShadowedParameter(s)){let d=e._shadowedParameterType(s);if(d!==void 0){let E=e._shadowedParameterDef(s);if(E!==void 0)return new zs(e,s,{metadata:o,def:E});let x=e.context.lexicalScope;for(;x.noAutoDeclare&&x.parent;)x=x.parent;let S=x.bindings.get(s),v=S??e._declareSymbolValue(s,{type:d,inferred:!1},x);e._setShadowedParameterDef(s,v);let w=new zs(e,s,{metadata:o,def:v});return S===void 0&&le(v)&&ja(e,v.value,{type:v.value.type,kind:"auto-declared",axis:"type",cause:w,epoch:qa(e)}),w}let p=e._shadowedParameterDef(s);if(p!==void 0)return new zs(e,s,{metadata:o,def:p});let m=e.context.lexicalScope;for(;m.noAutoDeclare&&m.parent;)m=m.parent;let g=m.bindings.get(s),y=g??e._declareSymbolValue(s,{type:"unknown",inferred:!0},m);e._setShadowedParameterDef(s,y);let b=new zs(e,s,{metadata:o,def:y});return g===void 0&&le(y)&&ja(e,y.value,{type:y.value.type,kind:"auto-declared",axis:"type",cause:b,epoch:qa(e)}),b}let u=Object.hasOwn(n,s)?n[s]:void 0;if(u)return u;let l=e.lookupDefinition(s);if(le(l)&&l.value.holdUntil==="never")return l.value.value??e.Nothing;if(l)return new zs(e,s,{metadata:o,def:l});if(i?.autoDeclare===!1||e._resolveOnlyDepth>0)return new zs(e,s,{metadata:o});let f=e.context.lexicalScope;for(;f.noAutoDeclare&&f.parent;)f=f.parent;l=e._declareSymbolValue(s,{type:"unknown",inferred:!0},f),e._boxingState.isPersistentScope(f)===!1&&e._boxingState.noteTransientAutoDeclare(s);let c=new zs(e,s,{metadata:o,def:l});return le(l)&&ja(e,l.value,{type:l.value.type,kind:"auto-declared",axis:"type",cause:c,epoch:qa(e)}),c}function fxe(e,n,t){let i=t.bindings.get(n);if(le(i))return new zs(e,n,{def:i})}function cxe(e,n,t,i){let r=i?.metadata;if(!vGe(i?.canonical)&&Ul(t))return e._fn("Rational",[e.number(t[0]),e.number(t[1])],{...r,canonical:!1});let s=TR(e,t);if(r===void 0){if(typeof s=="number"){let a=s;if(a===1)return e.One;if(a===0)return e.Zero;if(a===-1)return e.NegativeOne;if(a===2)return e.Two;if(Number.isInteger(a)&&n[a]!==void 0)return n[a]??=new ki(e,s),n[a];if(Number.isNaN(a))return e.NaN;if(!Number.isFinite(a))return a<0?e.NegativeInfinity:e.PositiveInfinity}else if(s instanceof Qn){if(s.isZero)return e.Zero;if(s.isOne)return e.One;if(s.isNegativeOne)return e.NegativeOne;if(s.isNaN)return e.NaN;if(s.isNegativeInfinity)return e.NegativeInfinity;if(s.isPositiveInfinity)return e.PositiveInfinity}}return new ki(e,s,{metadata:r})}var fx=class{_rules;_cachedLength=-1;constructor(n){this._rules=n}get rules(){return this._rules}set rules(n){this._rules=n,this._cachedLength=-1}hasMutatedSinceLastCache(){return this._cachedLength>=0&&this._rules.length!==this._cachedLength}markCached(){this._cachedLength=this._rules.length}};var BP=class{_precision;_angularUnit;_tolerance;_bignumTolerance;_negBignumTolerance;constructor(n){let t=n?.precision??bD;t==="machine"&&(t=Math.floor(Mu)),this._precision=t,I.precision=t,this._angularUnit=n?.angularUnit??"rad",this._tolerance=Zy,this._bignumTolerance=new I(Zy),this._negBignumTolerance=new I(-Zy),this.setTolerance(n?.tolerance??"auto")}get precision(){return this._precision}setPrecision(n){let t=n;if(t==="machine"&&(t=Mu),t==="auto"&&(t=bD),t===this._precision)return!1;if(typeof t!="number"||t<=0)throw Error('Expected "machine" or a positive number');return this._precision=Math.max(t,Mu),I.precision=this._precision,this.setTolerance("auto"),!0}get angularUnit(){return this._angularUnit}setAngularUnit(n){if(n===this._angularUnit)return!1;if(typeof n!="string")throw Error("Expected a string");return this._angularUnit=n,!0}get tolerance(){return this._tolerance}setTolerance(n){let t=n;return t==="auto"&&(t=Zy),(!Number.isFinite(t)||t<0)&&(t=Math.pow(10,-this._precision+2)),t===this._tolerance?!1:(this._tolerance=t,this._bignumTolerance=new I(t),this._negBignumTolerance=new I(-t),!0)}get bignumTolerance(){return this._bignumTolerance}get negBignumTolerance(){return this._negBignumTolerance}get bignumNaN(){return I.NAN}get bignumZero(){return I.ZERO}get bignumOne(){return I.ONE}get bignumTwo(){return I.TWO}get bignumHalf(){return I.HALF}get bignumPi(){return I.PI}get bignumNegativeOne(){return I.NEGATIVE_ONE}bignum(n){if(n instanceof I)return n;try{return new I(n)}catch(t){t instanceof Error?console.error(t.message):console.error(String(t))}return I.NAN}};var VP=class{_iterationLimit=1024;_recursionLimit=256;_recursionDepth=0;_maxCollectionSize=1e4;_deadlineFrame=void 0;_randomFrame=void 0;_isVerifying=!1;get iterationLimit(){return this._iterationLimit}set iterationLimit(n){this._iterationLimit=n<=0?Number.POSITIVE_INFINITY:n}get recursionLimit(){return this._recursionLimit}set recursionLimit(n){this._recursionLimit=n<=0?Number.POSITIVE_INFINITY:n}get recursionDepth(){return this._recursionDepth}enterRecursion(){if(this._recursionDepth>=this._recursionLimit)throw new Ae({cause:"recursion-depth-exceeded",message:"Recursion limit exceeded"});this._recursionDepth+=1}exitRecursion(){this._recursionDepth>0&&(this._recursionDepth-=1)}get maxCollectionSize(){return this._maxCollectionSize}set maxCollectionSize(n){this._maxCollectionSize=n<=0?Number.POSITIVE_INFINITY:n}get deadlineFrame(){return this._deadlineFrame}set deadlineFrame(n){this._deadlineFrame=n}get deadline(){return this._deadlineFrame?.at}set deadline(n){this._deadlineFrame=n===void 0?void 0:{at:n,spans:[]}}get randomFrame(){return this._randomFrame}set randomFrame(n){this._randomFrame=n}get timeRemaining(){return this._deadlineFrame===void 0?Number.POSITIVE_INFINITY:this._deadlineFrame.at-Date.now()}get isVerifying(){return this._isVerifying}set isVerifying(n){this._isVerifying=n}shouldContinueExecution(){return this._deadlineFrame===void 0||this._deadlineFrame.at>=Date.now()}};var jP=class{_frames=[];_rootActive=!1;_isPersistentScope=null;_transientAutoDeclares=null;withRootRepair(n,t){if(this._rootActive)return n();this._rootActive=!0,this._isPersistentScope=t??null;try{return this._withRepairFrame(void 0,()=>(this._transientAutoDeclares=null,n()))}finally{this._rootActive=!1,this._isPersistentScope=null,this._transientAutoDeclares=null}}get isRootActive(){return this._rootActive}withScopedRepair(n,t){return this._rootActive?this._withRepairFrame(n,t):t()}get isRebuilding(){return this._frames.some(n=>n.rebuilding)}isPersistentScope(n){if(!(!this._rootActive||!this._isPersistentScope))return this._isPersistentScope(n)}noteTransientAutoDeclare(n){!this._rootActive||!this._isPersistentScope||(this._transientAutoDeclares??=new Set).add(n)}noteDeclarationIn(n,t){if(!this._rootActive||!this._transientAutoDeclares?.has(t)||this._isPersistentScope?.(n)!==!0)return;let i=this._frames.find(r=>r.scope===void 0);i&&(i.repairRequested=!0)}frameDepth(){return this._frames.length}hasRepairRequestedAtOrAbove(n){for(let t=n;t<this._frames.length;t++)if(this._frames[t].repairRequested)return!0;return!1}noteDevolvedShadow(n){for(let i=this._frames.length-1;i>=0;i--){let r=this._frames[i];if(r.scope===n){r.repairRequested=!0;return}}let t=this._frames.find(i=>i.scope===void 0);t&&(t.repairRequested=!0)}_withRepairFrame(n,t){let i={scope:n,repairRequested:!1,rebuilding:!1};this._frames.push(i);try{let r=t(),o=0;for(;i.repairRequested;){if(o>=3){let s="Devolved-shadow repair did not stabilize after 3 rebuilds";throw new Error(s)}i.repairRequested=!1,i.rebuilding=!0,o+=1;try{r=t()}finally{i.rebuilding=!1}}return r}finally{let r=this._frames.pop()}}};function SGe(e){if(typeof e!="string")return Rge(e),e;let n=cy.find(t=>t.name===e);if(!n)throw new Error(`Unknown standard library: "${e}"`);return n}function dxe(e){return e?rM(e.map(SGe)):[...oM()]}function TGe(e){return cy.includes(e)}function pxe(e,n){for(let t of n){let i=t.definitions;if(!i)continue;let r=!TGe(t),o=Array.isArray(i)?i:[i];for(let s of o){if(r)for(let a of Object.keys(s))e._customLibraryOperators.add(a.normalize());hpe(e,s)}}}function cx(e,n){let t=e[n];if(!t)throw new Error(`Common symbol "${n}" failed to initialize`);return t}var qP=class{constructor(n){this.engine=n}engine;initializeCommonNumbers(){return{Zero:new ki(this.engine,0),One:new ki(this.engine,1),Half:new ki(this.engine,{rational:[1,2]}),NegativeOne:new ki(this.engine,-1),Two:new ki(this.engine,2),NaN:new ki(this.engine,Number.NaN),PositiveInfinity:new ki(this.engine,Number.POSITIVE_INFINITY),NegativeInfinity:new ki(this.engine,Number.NEGATIVE_INFINITY),I:new ki(this.engine,{rational:[0,1],imRational:[1,1]}),ComplexInfinity:new ki(this.engine,{re:1/0,im:1/0})}}bootstrapLibraries(n){let t=dxe(n);pxe(this.engine,t)}initializeCommonSymbolBindings(n){return phe(this.engine,n),{True:cx(n,"True"),False:cx(n,"False"),Pi:cx(n,"Pi"),E:cx(n,"ExponentialE"),Nothing:cx(n,"Nothing"),Missing:cx(n,"Missing")}}};function mxe(e){let n=new Set,t=(i,r)=>{if(i==="never")return!0;let o=e._protocolRegistry?.[r];if(o===void 0)return!1;let s=`${mo(i)} ${r}`;if(n.has(s))return!1;n.add(s);try{return o.conformances.some(a=>a.where===void 0?R(i,a.target):dk(a.target,a.where,i,t)!==null)}finally{n.delete(s)}};return{get names(){return Object.keys(e._typeRegistry)},resolve(i){let r=e._typeRegistry[i];if(r!==void 0)return r;if(e._protocolRegistry?.[i]!==void 0)throw new ot("protocol-in-type-position",`\`${i}\` is a protocol, not a type. Use a constrained variable: \`(x: T) -> boolean where T is ${i}\``)},forward(i){let r=e._typeRegistry[i];if(r!==void 0)return r;let o={kind:"reference",name:i,alias:!1,def:void 0};return e._typeRegistry[i]=o,o},conformsTo:t}}function zP(e,n,t){let i;typeof n=="string"?i=e.string(n):i=e.function("ErrorCode",n.map(s=>e.string(s)));let r;t!==void 0&&typeof t!="string"?r=t:t&&PC(t)?r=e.function("LatexString",[e.string(wp(t))]):typeof t=="string"&&t.length>0&&(r=e.string(t));let o=[e.expr(i)];return r&&o.push(r),e.function("Error",o)}function hxe(e){if(typeof e=="object"){if((e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="set"||e.kind==="list"&&e.dimensions===void 0)&&e.elements==="any")return e.kind;if(e.kind==="dictionary"&&e.values==="any")return"dictionary"}return e}function gxe(e){let n=hxe(e);if(n!==e)return ne(n);if(typeof e=="object"&&e.kind==="union"){let t=e.types.map(hxe);if(t.some((i,r)=>i!==e.types[r]))return ne(ze({...e,types:t}))}return ne(e)}function yxe(e,n,t,i){if(t){if(typeof i=="object"&&i!==null&&"type"in i&&"engine"in i){let o=i;$2(o.engine)&&t.toString()===o.type.toString()&&(t=one(o.engine,()=>o.type))}let r=typeof t=="object"&&"kind"in t?ne(t):t.toString();return zP(e,["incompatible-type",gxe(n),r],i)}return zP(e,["incompatible-type",gxe(n)],i)}function JP(e,n){Age(n);let t=_Ge(n);n=t.options;let i=t.modeFromAlias;if(n?.target!==void 0&&n.cse===!0)throw new Error("CSE is not supported on direct custom targets in Phase 1; omit `cse` or use a registered target.");if(n?.target!==void 0&&n.storage!==void 0&&Object.keys(n.storage).length>0)throw new Error('The `storage` option is not supported on direct custom targets: the sampler-backed read needs the reference gate and the helper preamble a registered target provides. Omit `storage` or use a registered target (`to: "glsl"`).');if(n?.target===void 0&&n?.storage!==void 0){let r=e.engine._getCompilationTarget(n.to??"javascript")?.createTarget();r!==void 0&&uc(n.storage,[e],r,{vars:n.vars,functions:n.functions})}try{if(n?.target){let a=us(ci(e),{skipHeads:Am(n.operators,n.functions),iterationBudget:n.target.iterationBudget,readsLiveSource:d=>typeof n.vars?.[d]=="string"}),u=[n.preamble,n.target.preamble,...n.vars?Object.values(n.vars):[],...n.functions?Object.values(n.functions).map(d=>{let p=$m(d);return typeof p=="string"?p:void 0}):[]];n.target.naming=A.newNamingContext(a,u),n.target.cse={enabled:!1,instances:[]},n.target.constantFold=n.constantFold,n.target.complexPromotion=n.complexPromotion,n.target.storage=void 0,n.target.mode=NGe(n.target,i&&!(n.target.supportedModes??["strict"]).includes("complex")?void 0:n.mode);let l,f;try{l=A.compileRoot(a,n.target)}catch(d){if(!Mw(d)||n.target.mode!=="auto")throw d;n.target.reset?.(),n.target.mode="complex",n.target.naming=A.newNamingContext(a,u),l=A.compileRoot(a,n.target),f=d.diagnostic}let c=A.withReferences({target:n.target.language??"custom",success:!0,code:l},e,n.target,n.vars?new Set(Object.keys(n.vars)):void 0);return f!==void 0&&(c.escalation=f),c}let r=n?.to??"javascript",o=e.engine._getCompilationTarget(r);if(!o)throw new Error(`Compilation target "${r}" is not registered. Available targets: ${e.engine._listCompilationTargets().join(", ")}`);let s={fallback:n?.fallback??!0,operators:n?.operators,functions:n?.functions,vars:n?.vars,imports:n?.imports,preamble:n?.preamble,complexPromotion:n?.complexPromotion,mode:n?.mode,entryChecks:n?.entryChecks,iterationBudget:n?.iterationBudget,quadrature:n?.quadrature,symbolDeps:n?.symbolDeps,varsObjectRefs:n?.varsObjectRefs,cse:n?.cse,constantFold:n?.constantFold,storage:n?.storage};return i&&!wGe(o,"complex")&&(s.mode=void 0),o.compile(e,s)}catch(r){if(n?.fallback??!0){let o=r.message;console.warn(`Compilation fallback for "${e.operator}" (target: ${n?.to??"javascript"}): ${o}`);let s=n?.to??"javascript";if(s==="interval-js"){let u=e.engine._getCompilationTarget("interval-js");if(u)return u.compile(e,{vars:n?.vars,fallback:!0})}let a=n?.target??e.engine._getCompilationTarget(s)?.createTarget();return A.buildInterpreterFallback(e,o,s,a,n?.vars?new Set(Object.keys(n.vars)):void 0,ac(r,o))}throw r}}var bxe=new WeakMap;function wGe(e,n){let t=bxe.get(e);return t===void 0&&(t=e.createTarget().supportedModes??["strict"],bxe.set(e,t)),t.includes(n)}function _Ge(e){return e===void 0?{options:e,modeFromAlias:!1}:lc(e)}function NGe(e,n){let t=e.supportedModes??["strict"],i=typeof e.complexLift=="function"&&typeof e.complexIsReal=="function",r=t.includes("auto")&&i&&typeof e.reset=="function";return n===void 0?r?"auto":"strict":n==="auto"&&t.includes("auto")&&!r?"strict":n}var Ez=null,xz=null;function GP(e){xz=e}function UP(){if(!Ez){if(!xz)throw new Error("ComputeEngine factory not registered. Import from the main module.");Ez=xz()}return Ez}function CGe(e,n){if(typeof e=="string"){let t=UP();return t.parse(e,{strict:n?.strict??!1})??t.expr("Nothing")}return $u(e)?e:UP().expr(e)}function HP(e,n){return JP(CGe(e,n),n)}var kGe=/^(Sin|Cos|Tan|Cot|Sec|Csc)$/;function WP(e){return kGe.test(e.operator)?!0:h(e)?e.ops.some(WP):!1}function Km(e,...n){return n.includes(e.operator)?!0:h(e)?e.ops.some(t=>Km(t,...n)):!1}function gi(e,n){let t=e.engine;if(h(e)&&e.ops.length>0){let i=e,r=i.ops.map(s=>gi(s,n));r.some((s,a)=>s!==i.ops[a])&&(e=t._fn(i.operator,r))}return n(e)??e}function vz(e,n){if(!h(e)||!h(n))return!1;let t=e.op1,i=n.op1;return t!==void 0&&i!==void 0&&t.isSame(i)}function IGe(e){let n=e.engine,t=e.operator;if(!h(e))return;let i=e.op1;if(i){if(t==="Sec")return n.One.div(n._fn("Cos",[i]));if(t==="Csc")return n.One.div(n._fn("Sin",[i]))}}function Txe(e){return gi(e,IGe)}function RGe(e){let n=e.engine,t=e.operator;if(!h(e))return;let i=e.op1;if(i){if(t==="Tan")return n._fn("Sin",[i]).div(n._fn("Cos",[i]));if(t==="Cot")return n._fn("Cos",[i]).div(n._fn("Sin",[i]))}}function wxe(e){return gi(e,RGe)}function AGe(e){let n=e.engine;if(e.operator!=="Divide"||!h(e))return;let t=e.op1,i=e.op2;if(!(!t||!i)){if(t.operator==="Sin"&&i.operator==="Cos"&&vz(t,i))return h(t)?n._fn("Tan",[t.op1]):void 0;if(t.operator==="Cos"&&i.operator==="Sin"&&vz(t,i))return h(t)?n._fn("Cot",[t.op1]):void 0}}function _xe(e){return gi(e,AGe)}function MGe(e){if(h(e,"Negate"))return e.op1;if(h(e,"Multiply")){let n=e.ops.findIndex(t=>t.isSame(-1));if(n>=0){let t=e.ops.filter((i,r)=>r!==n);return t.length===1?t[0]:e.engine._fn("Multiply",t)}}}function PGe(e){let n=e.engine,t=e.operator;if(!h(e))return;let i=e.op1;if(!i)return;let r=MGe(i);if(r){if(t==="Cos")return n._fn("Cos",[r]);if(t==="Sec")return n._fn("Sec",[r]);if(t==="Sin")return n._fn("Sin",[r]).neg();if(t==="Tan")return n._fn("Tan",[r]).neg();if(t==="Csc")return n._fn("Csc",[r]).neg();if(t==="Cot")return n._fn("Cot",[r]).neg()}}function Nxe(e){return gi(e,PGe)}function OGe(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||t.operator!=="Sin"||!i.isSame(2)||!h(t))return;let r=t.op1;if(r)return n.One.sub(n._fn("Cos",[r]).pow(2))}function Sz(e){return gi(e,OGe)}function DGe(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||t.operator!=="Cos"||!i.isSame(2)||!h(t))return;let r=t.op1;if(r)return n.One.sub(n._fn("Sin",[r]).pow(2))}function Cxe(e){return gi(e,DGe)}function $Ge(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||t.operator!=="Cos"||!i.isSame(2)||!h(t))return;let r=t.op1;if(r)return n.One.add(n._fn("Cos",[r.mul(2)])).div(2)}function kxe(e){return gi(e,$Ge)}function FGe(e){let n=e.engine;if(h(e,"Divide")){let i=e.op1,r=e.op2;if(!i||!r||!r.isSame(2))return;if(h(i,"Add")&&i.ops.length===2)return Exe(n,i.ops)}let t=i=>!!(i.re===.5&&i.im===0||i.isSame(n.Half));if(h(e,"Multiply")){let i=e.ops.findIndex(r=>t(r));if(i>=0){let r=e.ops.filter((o,s)=>s!==i);if(r.length===1&&r[0].operator==="Add"){let o=r[0];if(h(o)&&o.ops.length===2)return Exe(n,o.ops)}}}if(h(e,"Add")&&e.ops.length===2){let i,r,o=!1,s=a=>a.re===-.5&&a.im===0;for(let a of e.ops){if(t(a)){i=a;continue}let u=a,l=!1;if(h(a,"Negate")&&(l=!0,u=a.op1),h(u,"Divide")&&u.op2?.isSame(2)){let f=u.op1;if(f?.operator==="Cos"){r=f,o=l;continue}}if(h(u,"Multiply")){let f=u.ops.findIndex(d=>t(d));if(f>=0){let d=u.ops.filter((p,m)=>m!==f);if(d.length===1&&d[0].operator==="Cos"){r=d[0],o=l;continue}}let c=u.ops.findIndex(d=>s(d));if(c>=0){let d=u.ops.filter((p,m)=>m!==c);if(d.length===1&&d[0].operator==="Cos"){r=d[0],o=!l;continue}}}}if(i&&r){if(!h(r))return;let a=r.op1;if(!a)return;let u;if(h(a,"Multiply")){let l=a.ops.findIndex(f=>f.isSame(2));if(l>=0){let f=a.ops.filter((c,d)=>d!==l);u=f.length===1?f[0]:n._fn("Multiply",f)}}return u?o?n._fn("Sin",[u]).pow(2):n._fn("Cos",[u]).pow(2):void 0}}}function Exe(e,n){let t=-1,i=-1,r=!1;for(let u=0;u<n.length;u++)if(n[u].isSame(1))t=u;else if(n[u].operator==="Cos")i=u,r=!1;else if(n[u].operator==="Negate"){let l=n[u];h(l)&&l.op1?.operator==="Cos"&&(i=u,r=!0)}if(t<0||i<0)return;let o;if(r){let u=n[i];if(!h(u))return;o=u.op1}else o=n[i];if(!h(o))return;let s=o.op1;if(!s)return;let a;if(h(s,"Multiply")){let u=s.ops.findIndex(l=>l.isSame(2));if(u>=0){let l=s.ops.filter((f,c)=>c!==u);a=l.length===1?l[0]:e._fn("Multiply",l)}}if(a)return r?e._fn("Sin",[a]).pow(2):e._fn("Cos",[a]).pow(2)}function Tz(e){return gi(e,FGe)}function LGe(e){let n=e.engine;if(e.operator!=="Multiply"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r];if(!h(o)||!h(s))continue;let a=o.op1,u=s.op1;if(!a||!u)continue;let l;if(o.operator==="Sin"&&s.operator==="Cos"?l=n._fn("Sin",[a.add(u)]).add(n._fn("Sin",[a.sub(u)])).div(2):o.operator==="Cos"&&s.operator==="Sin"?l=n._fn("Sin",[a.add(u)]).sub(n._fn("Sin",[a.sub(u)])).div(2):o.operator==="Cos"&&s.operator==="Cos"?l=n._fn("Cos",[a.add(u)]).add(n._fn("Cos",[a.sub(u)])).div(2):o.operator==="Sin"&&s.operator==="Sin"&&(l=n._fn("Cos",[a.sub(u)]).sub(n._fn("Cos",[a.add(u)])).div(2)),l){let f=t.filter((c,d)=>d!==i&&d!==r);return f.length===0?l:l.mul(f.length===1?f[0]:n._fn("Multiply",f))}}}function Ixe(e){return gi(e,LGe)}function BGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r],a;if(o.operator==="Sin"&&s.operator==="Sin"){if(!h(o)||!h(s))continue;let u=o.op1,l=s.op1;if(u&&l){let f=u.add(l).div(2),c=u.sub(l).div(2);a=n._fn("Sin",[f]).mul(n._fn("Cos",[c])).mul(2)}}else if(o.operator==="Cos"&&s.operator==="Cos"){if(!h(o)||!h(s))continue;let u=o.op1,l=s.op1;if(u&&l){let f=u.add(l).div(2),c=u.sub(l).div(2);a=n._fn("Cos",[f]).mul(n._fn("Cos",[c])).mul(2)}}else if(o.operator==="Sin"&&s.operator==="Negate"){if(!h(o)||!h(s)||s.op1?.operator!=="Sin")continue;let u=s.op1;if(!h(u))continue;let l=o.op1,f=u.op1;if(l&&f){let c=l.add(f).div(2),d=l.sub(f).div(2);a=n._fn("Cos",[c]).mul(n._fn("Sin",[d])).mul(2)}}else if(o.operator==="Cos"&&s.operator==="Negate"){if(!h(o)||!h(s)||s.op1?.operator!=="Cos")continue;let u=s.op1;if(!h(u))continue;let l=o.op1,f=u.op1;if(l&&f){let c=l.add(f).div(2),d=l.sub(f).div(2);a=n._fn("Sin",[c]).mul(n._fn("Sin",[d])).mul(-2)}}if(a){let u=t.filter((l,f)=>f!==i&&f!==r);return u.length===0?a:a.add(u.length===1?u[0]:n._fn("Add",u))}}}function YP(e){return gi(e,BGe)}function VGe(e){let n=e.engine,t=e.operator;if(t!=="Sin"&&t!=="Cos"||!h(e))return;let i=e.op1;if(i){if(h(i,"Add")&&i.ops.length===2){let[r,o]=i.ops;return t==="Sin"?n._fn("Sin",[r]).mul(n._fn("Cos",[o])).add(n._fn("Cos",[r]).mul(n._fn("Sin",[o]))):n._fn("Cos",[r]).mul(n._fn("Cos",[o])).sub(n._fn("Sin",[r]).mul(n._fn("Sin",[o])))}if(h(i,"Subtract")){let r=i.op1,o=i.op2;return!r||!o?void 0:t==="Sin"?n._fn("Sin",[r]).mul(n._fn("Cos",[o])).sub(n._fn("Cos",[r]).mul(n._fn("Sin",[o]))):n._fn("Cos",[r]).mul(n._fn("Cos",[o])).add(n._fn("Sin",[r]).mul(n._fn("Sin",[o])))}}}function Rxe(e){return gi(e,VGe)}function jGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r],a=v=>{if(v.operator!=="Multiply"||!h(v))return null;let w=v.ops;if(w.length!==2)return null;let[_,C]=w;return _.operator==="Sin"&&C.operator==="Cos"?{sin:_,cos:C}:_.operator==="Cos"&&C.operator==="Sin"?{sin:C,cos:_}:null},u=v=>{if(v.operator!=="Multiply"||!h(v))return null;let w=v.ops;if(w.length!==2)return null;let[_,C]=w;return _.operator==="Cos"&&C.operator==="Cos"?{cos1:_,cos2:C}:null},l=v=>{if(v.operator!=="Multiply"||!h(v))return null;let w=v.ops;if(w.length!==2)return null;let[_,C]=w;return _.operator==="Sin"&&C.operator==="Sin"?{sin1:_,sin2:C}:null},f=v=>h(v)?v.op1:void 0,c=a(o),d=a(s),p=h(o,"Negate")&&o.op1?a(o.op1):null,m=h(s,"Negate")&&s.op1?a(s.op1):null;if(c&&d){let v=f(c.sin),w=f(c.cos),_=f(d.sin),C=f(d.cos);if(v&&w&&_&&C&&v.isSame(C)&&w.isSame(_)){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Sin",[v.add(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(c&&m){let v=f(c.sin),w=f(c.cos),_=f(m.sin),C=f(m.cos);if(v&&w&&_&&C&&v.isSame(C)&&w.isSame(_)){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Sin",[v.sub(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(p&&d){let v=f(p.sin),w=f(p.cos),_=f(d.sin),C=f(d.cos);if(v&&w&&_&&C&&_.isSame(w)&&C.isSame(v)){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Sin",[_.sub(C)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}let g=u(o),y=u(s),b=l(o),E=l(s),x=h(o,"Negate")&&o.op1?l(o.op1):null,S=h(s,"Negate")&&s.op1?l(s.op1):null;if(g&&S){let v=f(g.cos1),w=f(g.cos2),_=f(S.sin1),C=f(S.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.add(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(x&&y){let v=f(y.cos1),w=f(y.cos2),_=f(x.sin1),C=f(x.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.add(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(g&&E){let v=f(g.cos1),w=f(g.cos2),_=f(E.sin1),C=f(E.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.sub(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(b&&y){let v=f(y.cos1),w=f(y.cos2),_=f(b.sin1),C=f(b.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.sub(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}}}function ZP(e){return gi(e,jGe)}function qGe(e){let n=e.engine,t=e.operator;if(t!=="Sin"&&t!=="Cos"||!h(e))return;let i=e.op1;if(i&&h(i,"Multiply")){let r=i.ops,o=r.findIndex(s=>s.isSame(2));if(o>=0){let s=r.filter((u,l)=>l!==o),a=s.length===1?s[0]:n._fn("Multiply",s);return t==="Sin"?n._fn("Sin",[a]).mul(n._fn("Cos",[a])).mul(2):n._fn("Cos",[a]).pow(2).mul(2).sub(n.One)}}}function wz(e){return gi(e,qGe)}function zGe(e){let n=e.engine;if(h(e,"Multiply")){let t=e.ops,i=t.findIndex(r=>r.isSame(2));if(i>=0){let r=t.filter((a,u)=>u!==i),o,s;for(let a of r)a.operator==="Sin"&&!o?o=a:a.operator==="Cos"&&!s&&(s=a);if(o&&s&&vz(o,s)){if(!h(o))return;let a=r.filter(l=>l!==o&&l!==s),u=n._fn("Sin",[o.op1.mul(2)]);return a.length===0?u:u.mul(a.length===1?a[0]:n._fn("Multiply",a))}}}if(h(e,"Add")&&e.ops.length===2){let[t,i]=e.ops;if(h(t,"Power")&&t.op1?.operator==="Cos"&&t.op2?.isSame(2)&&i.operator==="Negate"&&h(i)&&i.op1?.operator==="Power"&&h(i.op1)&&i.op1.op1?.operator==="Sin"&&i.op1.op2?.isSame(2)){let u=t.op1,l=i.op1;if(h(u)&&h(l)){let f=l.op1;if(h(f)){let c=u.op1,d=f.op1;if(c&&d&&c.isSame(d))return n._fn("Cos",[c.mul(2)])}}}let r=u=>{if(!h(u,"Multiply"))return;let l=u.ops.findIndex(d=>d.isSame(2));if(l<0)return;let f=u.ops.filter((d,p)=>p!==l);if(f.length!==1)return;let c=f[0];if(h(c,"Power")&&c.op1?.operator==="Cos"&&c.op2?.isSame(2)){let d=c.op1;if(h(d))return d.op1}},o=r(t);if(o&&(i.isSame(-1)||h(i,"Negate")&&i.op1?.isSame(1)))return n._fn("Cos",[o.mul(2)]);if(o=r(i),o&&(t.isSame(-1)||h(t,"Negate")&&t.op1?.isSame(1)))return n._fn("Cos",[o.mul(2)]);let s=u=>{if(!h(u,"Multiply"))return;let l=u.ops.findIndex(d=>d.isSame(2));if(l<0)return;let f=u.ops.filter((d,p)=>p!==l);if(f.length!==1)return;let c=f[0];if(h(c,"Power")&&c.op1?.operator==="Sin"&&c.op2?.isSame(2)){let d=c.op1;if(h(d))return d.op1}};if(t.isSame(1)&&h(i,"Negate")&&i.op1){let u=s(i.op1);if(u)return n._fn("Cos",[u.mul(2)])}if(i.isSame(1)&&h(t,"Negate")&&t.op1){let u=s(t.op1);if(u)return n._fn("Cos",[u.mul(2)])}let a=u=>{if(!h(u,"Multiply"))return;let l=u.ops.findIndex(d=>d.isSame(-2));if(l<0)return;let f=u.ops.filter((d,p)=>p!==l);if(f.length!==1)return;let c=f[0];if(h(c,"Power")&&c.op1?.operator==="Sin"&&c.op2?.isSame(2)){let d=c.op1;if(h(d))return d.op1}};if(t.isSame(1)){let u=a(i);if(u)return n._fn("Cos",[u.mul(2)])}if(i.isSame(1)){let u=a(t);if(u)return n._fn("Cos",[u.mul(2)])}}}function Axe(e){return gi(e,zGe)}function xxe(e){let n=!1,t=e;if(h(t,"Negate")&&t.op1)n=!0,t=t.op1;else if(h(t,"Multiply")&&t.ops.length===2){let s=t.ops.findIndex(a=>a.isSame(-1));s>=0&&(n=!0,t=t.ops[1-s])}if(!h(t,"Power"))return;let i=t.op1,r=t.op2;if(!i||!r||!(r.isSame(2)||r.isSame(4))||i.operator!=="Sin"&&i.operator!=="Cos"||!h(i))return;let o=i.op1;if(o)return{func:i.operator,arg:o,power:r.isSame(2)?2:4,negated:n}}function JGe(e){let n=e.engine;if(!h(e,"Add")||e.ops.length!==2)return;let t=xxe(e.ops[0]),i=xxe(e.ops[1]);if(!t||!i||t.negated===i.negated||t.func===i.func||t.power!==i.power||!t.arg.isSame(i.arg))return;let r=t.negated?i:t,o=n._fn("Cos",[r.arg.mul(2)]);return r.func==="Cos"?o:o.neg()}function Mxe(e){return gi(e,JGe)}function UGe(e){let n=e.engine;if(e.operator!=="Tan"||!h(e))return;let t=e.op1;if(t){if(h(t,"Add")&&t.ops.length===2){let[i,r]=t.ops,o=n._fn("Tan",[i]),s=n._fn("Tan",[r]);return o.add(s).div(n.One.sub(o.mul(s)))}if(h(t,"Subtract")){let i=t.op1,r=t.op2;if(!i||!r)return;let o=n._fn("Tan",[i]),s=n._fn("Tan",[r]);return o.sub(s).div(n.One.add(o.mul(s)))}}}function Pxe(e){return gi(e,UGe)}var GGe=[{value:0,angle:[0,1]},{value:1/Math.sqrt(3),angle:[1,6]},{value:1,angle:[1,4]},{value:Math.sqrt(3),angle:[1,3]},{value:2-Math.sqrt(3),angle:[1,12]},{value:2+Math.sqrt(3),angle:[5,12]}];function HGe(e,n=1e-10){for(let t of GGe)if(Math.abs(t.value-e)<n)return t.angle}function WGe(e){if(e.operator!=="Multiply"||!h(e))return;let n=e.ops;if(n.length<2)return;let t=[],i=1;for(let r of n)if(h(r,"Tan")&&r.op1)t.push(r.op1);else if(h(r,"Negate")&&r.op1?.operator==="Sqrt"){let o=r.op1;if(h(o)){let s=o.op1;if(N(s)&&typeof s.re=="number")i*=-Math.sqrt(s.re);else return}else return}else if(h(r,"Sqrt")){let o=r.op1;if(o&&N(o)&&typeof o.re=="number")i*=Math.sqrt(o.re);else return}else if(N(r)&&typeof r.re=="number")i*=r.re;else return;if(t.length===2)return[i,t[0],t[1]]}function vxe(e){if(h(e,"Multiply")){let n=!1,t;for(let i of e.ops)if(T(i,"Pi"))n=!0;else if(N(i)&&typeof i.re=="number"){let r=i.re;for(let o=1;o<=36;o++){let s=Math.round(r*o);if(Math.abs(s/o-r)<1e-10){t=[s,o];break}}}if(n&&t)return t}if(T(e,"Pi"))return[1,1]}function YGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(t.length!==3)return;let i=[],r;for(let E=0;E<t.length;E++){let x=t[E];if(h(x,"Tan")&&x.op1)i.push({arg:x.op1,index:E});else{let S=WGe(x);S&&(r={coef:S[0],arg1:S[1],arg2:S[2],index:E})}}if(i.length!==2||!r)return;let[o,s]=i,a=o.arg.isSame(r.arg1)||o.arg.isSame(r.arg2),u=s.arg.isSame(r.arg1)||s.arg.isSame(r.arg2),l=o.arg.isSame(r.arg2)||o.arg.isSame(r.arg1),f=s.arg.isSame(r.arg2)||s.arg.isSame(r.arg1);if(!(a&&f||u&&l))return;let c=-r.coef;if(c<=0)return;let d=HGe(c);if(!d)return;let p=vxe(o.arg),m=vxe(s.arg);if(!p||!m)return;let g=Sxe(Sxe(p[1],m[1]),d[1]);if(p[0]*(g/p[1])+m[0]*(g/m[1])+d[0]*(g/d[1])!==g)return;let b=n._fn("Multiply",[n.number([d[0],d[1]]),n.symbol("Pi")]);return n._fn("Tan",[b]).neg()}function Sxe(e,n){return Math.abs(e*n)/ZGe(e,n)}function ZGe(e,n){for(e=Math.abs(e),n=Math.abs(n);n;){let t=n;n=e%n,e=t}return e}function Oxe(e){return gi(e,YGe)}function KGe(e){let n=e.engine;if(e.operator!=="Multiply"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r];if(!h(o)||!h(s))continue;let a=o.op1,u=s.op1;if(!(!a||!u)){if(o.operator==="Tan"&&s.operator==="Tan"){let l=o,f=s,c=n._fn("Cot",[a.add(u)]),d=n.One.sub(l.add(f).mul(c)),p=t.filter((m,g)=>g!==i&&g!==r);return p.length===0?d:d.mul(p.length===1?p[0]:n._fn("Multiply",p))}if(o.operator==="Cot"&&s.operator==="Cot"){let l=o,f=s,c=n._fn("Cot",[a.add(u)]),d=n.One.add(l.add(f).mul(c)),p=t.filter((m,g)=>g!==i&&g!==r);return p.length===0?d:d.mul(p.length===1?p[0]:n._fn("Multiply",p))}}}}function Dxe(e){return gi(e,KGe)}function XGe(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||!i.isSame(2)||!h(t))return;let r=t.op1;if(r){if(t.operator==="Tan")return n._fn("Sec",[r]).pow(2).sub(n.One);if(t.operator==="Cot")return n._fn("Csc",[r]).pow(2).sub(n.One);if(t.operator==="Sec")return n.One.add(n._fn("Tan",[r]).pow(2));if(t.operator==="Csc")return n.One.add(n._fn("Cot",[r]).pow(2))}}function $xe(e){return gi(e,XGe)}function QGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(t.length!==2)return;let i=d=>{let p=!1,m=d;if(h(d,"Negate")&&(p=!0,m=d.op1),!h(m)||m.operator!=="Power"||!m.op2?.isSame(2))return null;let g=m.op1;if(!h(g)||!g.op1)return null;let y=g.operator;return["Tan","Cot","Sec","Csc"].includes(y)?{func:y,arg:g.op1,neg:p}:null},r=i(t[0]),o=i(t[1]);if(r&&o&&r.arg.isSame(o.arg)){if(r.func==="Cot"&&!r.neg&&o.func==="Csc"&&o.neg||r.func==="Csc"&&r.neg&&o.func==="Cot"&&!o.neg)return n.number(-1);if(r.func==="Csc"&&!r.neg&&o.func==="Cot"&&o.neg||r.func==="Cot"&&r.neg&&o.func==="Csc"&&!o.neg)return n.One;if(r.func==="Tan"&&!r.neg&&o.func==="Sec"&&o.neg||r.func==="Sec"&&r.neg&&o.func==="Tan"&&!o.neg)return n.number(-1);if(r.func==="Sec"&&!r.neg&&o.func==="Tan"&&o.neg||r.func==="Tan"&&r.neg&&o.func==="Sec"&&!o.neg)return n.One}let s=-1,a=-1,u=!1;for(let d=0;d<t.length;d++){let p=t[d];p.isSame(1)?(s=d,u=!1):p.isSame(-1)||h(p,"Negate")&&p.op1?.isSame(1)?(s=d,u=!0):h(p,"Power")&&p.op2?.isSame(2)&&(a=d)}if(s<0||a<0)return;let l=t[a];if(!h(l))return;let f=l.op1;if(!f||!h(f))return;let c=f.op1;if(c){if(f.operator==="Sec"&&u)return n._fn("Tan",[c]).pow(2);if(f.operator==="Csc"&&u)return n._fn("Cot",[c]).pow(2);if(f.operator==="Tan"&&!u)return n._fn("Sec",[c]).pow(2);if(f.operator==="Cot"&&!u)return n._fn("Csc",[c]).pow(2)}}function _z(e){return gi(e,QGe)}function eHe(e){let n=e.engine;if(!h(e,"Multiply"))return[1,n.One,e];for(let t=0;t<e.ops.length;t++){let i=e.ops[t],r;if(N(i)&&typeof i.re=="number"&&i.im===0&&(r=i.re),r!==void 0){let o=e.ops.filter((a,u)=>u!==t),s=o.length===1?o[0]:n._fn("Multiply",o);return[r,i,s]}}return[1,n.One,e]}function nHe(e){let n=e.engine;if(e.operator!=="Multiply"||!h(e))return;let t=e.ops;if(t.length<2)return;let i=[],r=[];for(let _ of t)if(h(_,"Cos")&&_.op1){let C=eHe(_.op1);C?i.push({arg:C[2],numericMult:C[0],symbolicCoeff:C[1]}):i.push({arg:_.op1,numericMult:1,symbolicCoeff:n.One})}else r.push(_);if(i.length<2)return;let o=i[0].arg,s=i.filter(_=>_.arg.isSame(o)),a=i.filter(_=>!_.arg.isSame(o));if(s.length<2)return;s.sort((_,C)=>_.numericMult-C.numericMult);let u=[],l=[],f=[...s],c=f[0].numericMult;if(c>0){u.push(f[0]);let _=new Set([0]),C=c*2;for(;;){let k=f.findIndex((M,j)=>!_.has(j)&&Math.abs(M.numericMult-C)<1e-10);if(k===-1)break;u.push(f[k]),_.add(k),C*=2}l=f.filter((k,M)=>!_.has(M))}if(u.length<2)return;let d=u[0].numericMult,p=[...r];for(let _ of l){let C=_.symbolicCoeff.isSame(n.One)?_.arg:n._fn("Multiply",[_.symbolicCoeff,_.arg]);p.push(n._fn("Cos",[C]))}for(let _ of a){let C=_.symbolicCoeff.isSame(n.One)?_.arg:n._fn("Multiply",[_.symbolicCoeff,_.arg]);p.push(n._fn("Cos",[C]))}let m=u.length,g=u[0].symbolicCoeff,y=Math.pow(2,m);if(T(o,"Pi")){let _=1/(y+1);if(Math.abs(d-_)<1e-10){let C=n.number([1,y]);return p.length===0?C:C.mul(p.length===1?p[0]:n._fn("Multiply",p))}}let b=g.mul(y),E=g.isSame(n.One)?o:n._fn("Multiply",[g,o]),x=n._fn("Multiply",[b,o]),S=n._fn("Sin",[x]),v=n._fn("Sin",[E]),w=S.div(n.number(y).mul(v));return p.length===0?w:w.mul(p.length===1?p[0]:n._fn("Multiply",p))}function Fxe(e){return gi(e,nHe)}function tHe(e){if(h(e,"Power")&&e.op2?.isSame(2)){let n=e.op1;if(h(n,"Sin")&&n.op1)return{func:"Sin",arg:n.op1,coef:1};if(h(n,"Cos")&&n.op1)return{func:"Cos",arg:n.op1,coef:1}}if(h(e,"Multiply")){let n=1,t;for(let i of e.ops)if(h(i,"Power")&&i.op2?.isSame(2)){let r=i.op1;(r?.operator==="Sin"||r?.operator==="Cos")&&(t=i)}else typeof i.re=="number"&&i.im===0&&(n*=i.re);if(h(t)){let i=t.op1;if(h(i,"Sin")&&i.op1)return{func:"Sin",arg:i.op1,coef:n};if(h(i,"Cos")&&i.op1)return{func:"Cos",arg:i.op1,coef:n}}}return null}function iHe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(t.length<2)return;let i=[],r=[],o=[];for(let s=0;s<t.length;s++){let a=t[s],u=tHe(a);u?i.push({...u,index:s}):typeof a.re=="number"&&a.im===0&&N(a)?o.push({value:a.re,index:s}):r.push({expr:a,index:s})}for(let s=0;s<i.length;s++)for(let a=s+1;a<i.length;a++){let u=i[s],l=i[a];if(u.arg.isSame(l.arg)&&(u.func==="Sin"&&l.func==="Cos"||u.func==="Cos"&&l.func==="Sin")&&Math.abs(u.coef-l.coef)<1e-10){let f=u.coef,c=new Set([u.index,l.index]),d=t.filter((p,m)=>!c.has(m));return d.length===0?n.number(f):f===1?n._fn("Add",[n.One,...d]):n._fn("Add",[n.number(f),...d])}}for(let s of i)if(s.coef<0){let a=Math.abs(s.coef);for(let u of o)if(Math.abs(u.value-a)<1e-10){let l=new Set([s.index,u.index]),f=t.filter((p,m)=>!l.has(m)),c=s.func==="Sin"?"Cos":"Sin",d=n._fn(c,[s.arg]).pow(2).mul(a);return f.length===0?d:n._fn("Add",[d,...f])}}}function Lxe(e){return gi(e,iHe)}var rHe=new Set(["Sin","Cos","Tan","Cot","Sec","Csc"]);function Nz(e){let n=0;if(rHe.has(e.operator)&&(n=1),h(e))for(let t of e.ops)n+=Nz(t);return n}function Cz(e){if(T(e)||N(e))return 1;let n=1;if(h(e))for(let t of e.ops)n+=Cz(t);return n}function Bxe(e){let n=Nz(e),t=Cz(e);return n*1e3+t}var Vxe=Bxe;function kz(e,n){if(e.length===0)throw new Error("bestOf called with empty array");if(e.length===1)return e[0];let t=e[0],i=n(t);for(let r=1;r<e.length;r++){let o=n(e[r]);o<i&&(t=e[r],i=o)}return t}function d_(e,n){let t=n(e);return t.isSame(e)?null:t}function jxe(e,n){let t=d_(e,Sz),i=d_(e,Cxe),r=[e];return t&&r.push(t),i&&r.push(i),kz(r,n)}function oHe(e,n){return jxe(e,n)}function sHe(e,n){let t=d_(e,Ixe),i=[e];if(t){i.push(t);let r=d_(t,ZP);r&&i.push(r)}return kz(i,n)}function aHe(e,n){let t=d_(e,ZP),i=[e];return t&&i.push(t),kz(i,n)}function uHe(e,n){let t=Pxe(e);return t=Dxe(t),t}function lHe(e,n){let t=e;return t=Rxe(t),t=wz(t),t=Sz(t),t=kxe(t),t=wz(t),t=sHe(t,n),t=jxe(t,n),t=YP(t),t=oHe(t,n),t=YP(t),t=aHe(t,n),t}function qxe(e,n){if(!WP(e))return;let t=n?.measure??Vxe,i=n?.maxIterations??100,r=e,o=0,s=e,a=t(e),u=v=>{let w=t(v);w<a&&(s=v,a=w)};r=Nxe(r),u(r);let l=_z(r);u(l);let f=$xe(r);u(f),r=s;let c=Tz(r);if(u(c),r=s,Km(r,"Sec","Csc")&&(r=Txe(r),s=r,a=t(r)),Km(r,"Tan","Cot")){let v=uHe(r,t);u(v),r=v}if(Km(r,"Tan","Cot")&&(r=wxe(r),u(r)),Km(r,"Sin","Cos")){let v=YP(r);u(v),r=s}if(Km(r,"Sin","Cos")){let v=t(r);for(;o<i;){o++;let w=lHe(r,t),_=t(w);if(u(w),_>=v)break;r=w,v=_}}let d=_xe(s);u(d);let p=Axe(s);u(p);let m=Mxe(s);u(m);let g=Fxe(s);u(g);let y=Tz(s);u(y);let b=_z(s);u(b);let E=ZP(s);u(E);let x=Lxe(s);u(x);let S=Oxe(s);if(u(S),s.operator==="Add"||s.operator==="Multiply"){let v=e.engine.expr(s.json);u(v)}if(!s.isSame(e))return{value:s,because:"fu"}}function Iz(e,n){if(Array.isArray(e)){if(e[0]==="InvisibleOperator")for(let t=1;t+1<e.length;t++){let i=e[t],r=e[t+1];typeof i=="string"&&Array.isArray(r)&&r[0]==="Delimiter"&&n.add(i)}for(let t of e)Iz(t,n);return}e!==null&&typeof e=="object"&&"fn"in e&&Array.isArray(e.fn)&&Iz(e.fn,n)}var Xm=class e{static _latexSyntaxFactory=null;True;False;Pi;E;Nothing;Missing;Zero;One;Half;NegativeOne;Two;I;NaN;PositiveInfinity;NegativeInfinity;ComplexInfinity;_numericConfiguration;_cacheStore=new xM;_runtimeState=new VP;_boxingState=new jP;_configurationLifecycle=new LP;_cost;_integrationProvider;_simplificationRules=new fx([...Tme]);_solveRules=new fx([...poe]);_harmonizationRules=new fx([...yoe]);_compilationTargets=new $P;_fuAlgorithm=qxe;_customLibraryOperators=new Set;_commonSymbols={Pi:null,True:null,False:null,All:null,Nothing:null,Missing:null,None:null,Undefined:null,ExponentialE:null};_commonNumbers={"-5":null,"-4":null,"-3":null,"-2":null,2:null,3:null,4:null,5:null,6:null,7:null,8:null,9:null,10:null,11:null,12:null,36:null};_commonTypes=new Map;_evalContextStack=[];get context(){return this._evalContextStack[this._evalContextStack.length-1]}get contextStack(){return[...this._evalContextStack]}set contextStack(n){this._evalContextStack=[...n]}_typeRegistry=Object.create(null);_protocolRegistry=Object.create(null);_conformanceVersionCounter=0;get _conformanceVersion(){return this._conformanceVersionCounter}_noteConformanceRegistryChange(){this._conformanceVersionCounter+=1}_staticTypeCheckDepth=0;_epsilBatchId=void 0;_staticAssignmentEvidence=void 0;_epsilDeclarationRoute=!1;_typeRegistryRollbackPoint(){let n=this._typeRegistry,t=new Set(Object.keys(n)),i=[...t].map(r=>{let o=n[r];return{r:o,def:o.def,alias:o.alias,typeParams:o.typeParams,varianceState:o._varianceState,varianceBlockedOn:o._varianceBlockedOn,declaredByStatement:o._declaredByStatement,forwardArity:o._forwardArity===void 0?void 0:new Set(o._forwardArity),sumOf:o._sumOf,sumVariants:o._sumVariants,declOrigin:o._declOrigin}});return()=>{let r=!1;for(let o of Object.keys(n))t.has(o)||(delete n[o],r=!0);for(let o of i){let s=o.r;s.def!==o.def&&(r=!0),s.def=o.def,s.alias!==o.alias&&(r=!0),s.alias=o.alias,s.typeParams!==o.typeParams&&(r=!0),o.typeParams===void 0?delete s.typeParams:s.typeParams=o.typeParams,s._varianceState!==o.varianceState&&(r=!0),o.varianceState===void 0?delete s._varianceState:s._varianceState=o.varianceState,s._varianceBlockedOn!==o.varianceBlockedOn&&(r=!0),o.varianceBlockedOn===void 0?delete s._varianceBlockedOn:s._varianceBlockedOn=o.varianceBlockedOn;let a=s;a._declaredByStatement!==o.declaredByStatement&&(r=!0),o.declaredByStatement===void 0?delete a._declaredByStatement:a._declaredByStatement=o.declaredByStatement;let u=s,l=u._forwardArity,f=o.forwardArity;(l===void 0!=(f===void 0)||l!==void 0&&f!==void 0&&(l.size!==f.size||[...f].some(c=>!l.has(c))))&&(r=!0),f===void 0?delete u._forwardArity:u._forwardArity=f,s._sumOf!==o.sumOf&&(r=!0),o.sumOf===void 0?delete s._sumOf:s._sumOf=o.sumOf,s._sumVariants!==o.sumVariants&&(r=!0),o.sumVariants===void 0?delete s._sumVariants:s._sumVariants=o.sumVariants,o.declOrigin===void 0?delete s._declOrigin:s._declOrigin=o.declOrigin,s.name in n||(n[s.name]=s,r=!0)}r&&this._noteStateEvent({kind:"config"})}}_protocolRegistryRollbackPoint(){let n=this._protocolRegistry,t=new Set(Object.keys(n)),i=[...t].map(r=>{let o=n[r];return{r:o,members:o.members,conformances:[...o.conformances],edges:o.conformances.map(s=>({c:s,impl:s.impl,authored:s._authored,origin:s._implOrigin,pending:s.pending,pendingReason:s._pendingReason})),declaredByStatement:o.declaredByStatement,declOrigin:o._declOrigin}});return()=>{let r=!1;for(let o of Object.keys(n))t.has(o)||(delete n[o],r=!0);for(let o of i){let s=o.r;s.members!==o.members&&(r=!0),s.members=o.members,s.declaredByStatement!==o.declaredByStatement&&(r=!0),s.declaredByStatement=o.declaredByStatement,o.declOrigin===void 0?delete s._declOrigin:s._declOrigin=o.declOrigin,(s.conformances.length!==o.conformances.length||o.conformances.some((a,u)=>s.conformances[u]!==a))&&(r=!0),s.conformances=o.conformances;for(let a of o.edges)a.c.impl!==a.impl&&(r=!0),a.impl===void 0?delete a.c.impl:a.c.impl=a.impl,a.authored===void 0?delete a.c._authored:a.c._authored=a.authored,a.origin===void 0?delete a.c._implOrigin:a.c._implOrigin=a.origin,a.c.pending!==a.pending&&(r=!0),a.c.pending=a.pending,a.pendingReason===void 0?delete a.c._pendingReason:a.c._pendingReason=a.pendingReason;s.name in n||(n[s.name]=s,r=!0)}r&&(this._noteStateEvent({kind:"config"}),this._noteConformanceRegistryChange())}}_rollbackFrames=[];_withRolledBackInference(n,t){this._inferenceTxDepth>0;let i=new pN({boxingRepairDepthAtOpen:this._boxingState.frameDepth(),forbidsRepairs:t?.forbidsRepairs});this._rollbackFrames.push(i);let r;try{return n()}catch(o){throw r={error:o},o}finally{let o=this._rollbackFrames.pop(),s=i.rollback();if(this._boxingState.hasRepairRequestedAtOrAbove(i.boxingRepairDepthAtOpen),s!==void 0&&this._debugBindings)throw new Error("Inference rollback failed: an undo entry threw while unwinding the frame",{cause:r?.error??s.error})}}_withBoxingPassWindow(n){dM(this);try{return n()}finally{pM(this)}}declareProtocol(n,t){Rk(this,n,t)}declareProtocolImplementation(n,t,i,r){EX(this,n,t,i,r)}__typeResolver;get _typeResolver(){return this.__typeResolver??=mxe(this),this.__typeResolver}declareType(n,t,i){dE(this,n,t,i)}get trace(){return this._evalContextStack.map(n=>n.name).filter(n=>n!==void 0).reverse()}get _anyVersion(){return this._configurationLifecycle.anyVersion}get _semanticVersion(){return this._configurationLifecycle.semanticVersion}get _worldVersion(){return this._configurationLifecycle.worldVersion}get _callableVersion(){return this._configurationLifecycle.callableVersion}get _ephemeralWriteDepth(){return this._configurationLifecycle.ephemeralWriteDepth}set _ephemeralWriteDepth(n){this._configurationLifecycle.ephemeralWriteDepth=n}get _factSuppressionDepth(){return this._configurationLifecycle.factSuppressionDepth}set _factSuppressionDepth(n){this._configurationLifecycle.factSuppressionDepth=n}_withoutFacts(n){if(n.constructor.name==="AsyncFunction")throw new Error("A fact-blind bracket must be synchronous: an async thunk is refused before it runs, because everything after its first await would see the assumptions again");let t=this._configurationLifecycle;t.factSuppressionDepth+=1;let i;try{i=n()}finally{t.factSuppressionDepth-=1}if(typeof i?.then=="function")throw Promise.resolve(i).then(void 0,()=>{}),new Error("A fact-blind bracket must be synchronous: its thunk returned a promise, whose work would run after the bracket closed and would see the assumptions again");return i}_factsHidden(){if(this._factSuppressionDepth===0)return!1;let n=this.context;return n===void 0?!1:(n.assumptions?.size??0)!==0||(n.assumedValues?.size??0)!==0}_cacheGeneration(){return this._anyVersion*2+(this._factsHidden()?1:0)}_nextFactId(){return this._factIdCounter+=1,this._factIdCounter}_factIdCounter=0;get _scratchDeclarationScopes(){return this._configurationLifecycle.scratchDeclarationScopes}_checkpointWindow=void 0;_checkpointStack=[];_checkpointPoisoned=!1;_nextCheckpointId=1;_invalidateCheckpointsOnFrameDiscard(n){HX(this,n)}_inFlightAsyncEvaluations=0;_evaluationDepth=0;_objectStoreEpoch=0;_applicationMemo=void 0;checkpoint(n){return UX(this,n)}restore(n){GX(this,n)}discard(n){WX(this,n)}_noteStateEvent(n){SD&&this._checkpointWindow?.noteEvent(n.kind),this._configurationLifecycle.noteStateEvent(n)}_inferenceTxDepth=0;_hasAsyncOnlyOperator=!1;_boxingEpoch=0;_debugBindings=KU();_freshlyInferred=null;_inferenceCause=null;_noteInferenceWrite(n){let t=this._inferenceCause;if(t&&t.expr===void 0&&(t.expr=this._fn(t.operator,t.ops.map(i=>this.expr(i,{form:"raw"})),{canonical:!1})),ja(this,n.target,{type:n.to,kind:n.kind,axis:"type",cause:t?.expr,epoch:qa(this)}),n.valueDef!==void 0&&n.from.isUnknown&&this._inferenceTxDepth>0){let i=this._freshlyInferred??=new Set,r=gt(this);if(r!==void 0&&!i.has(n.valueDef)){let o=n.valueDef;r.record({undo:()=>i.delete(o)})}i.add(n.valueDef)}this._narrowingSink?._recordNarrowing(n.name,n.binding,n.from,n.to)}strict;get jit(){return this._jit}set jit(n){n!==this._jit&&(this._jit=n,this._noteStateEvent({kind:"config"}))}_jit="auto";static getStandardLibrary(n){return oM(n)}constructor(n){if(n!==void 0&&typeof n!="object")throw Error("Unexpected argument");this.strict=!0,this.jit="auto",this._numericConfiguration=new BP({precision:n?.precision,tolerance:n?.tolerance??"auto",angularUnit:"rad"});let t=new qP(this),i=t.initializeCommonNumbers();this.Zero=i.Zero,this.One=i.One,this.Half=i.Half,this.NegativeOne=i.NegativeOne,this.Two=i.Two,this.NaN=i.NaN,this.PositiveInfinity=i.PositiveInfinity,this.NegativeInfinity=i.NegativeInfinity,this.I=i.I,this.ComplexInfinity=i.ComplexInfinity,this._reset(),this.pushScope(void 0,"system"),this.declareType("limits","expression<Limits>"),this.declareType("distribution","expression<NormalDistribution> | expression<BinomialDistribution> | expression<PoissonDistribution> | expression<UniformDistribution> | expression<ExponentialDistribution>",{alias:!0}),t.bootstrapLibraries(n?.libraries);let r=t.initializeCommonSymbolBindings(this._commonSymbols);this.True=r.True,this.False=r.False,this.Pi=r.Pi,this.E=r.E,this.Nothing=r.Nothing,this.Missing=r.Missing,this.pushScope(void 0,"global"),this._compilationTargets.registerDefaults(),n?.latexSyntax&&(this._latexSyntax=n.latexSyntax),n?.latexOptions&&(dN(n.latexOptions),this._latexOptions={...n.latexOptions}),FU(this)}toJSON(){return"[ComputeEngine]"}[Symbol.toStringTag]="ComputeEngine";_reset(){this._configurationLifecycle.reset({refreshNumericConstants:()=>{},resetCommonSymbols:()=>mhe(this._commonSymbols),purgeCaches:()=>this._cacheStore.purgeValues()})}_listenToConfigurationChange(n){return this._configurationLifecycle.listen(n)}_compile(n,t){return JP(n,t)}_getCompilationTarget(n){return this._compilationTargets.get(n)}_listCompilationTargets(){return this._compilationTargets.list()}_registerCompilationTarget(n,t){this._compilationTargets.register(n,t)}_unregisterCompilationTarget(n){this._compilationTargets.unregister(n)}get precision(){return this._numericConfiguration.precision}set precision(n){this._numericConfiguration.setPrecision(n)&&this._reset()}get angularUnit(){return this._numericConfiguration.angularUnit}set angularUnit(n){this._numericConfiguration.setAngularUnit(n)&&this._reset()}withTimeLimit(n,t){let i=typeof n=="number"?n:n.ms,r=typeof n=="number"?void 0:n.label,o=this._runtimeState.deadlineFrame,s=Date.now()+i,a=[...o?.spans??[],...r!==void 0?[r]:[]],u=o!==void 0&&o.at<=s?{at:o.at,owner:o.owner,spans:a}:{at:s,owner:r,spans:a};this._runtimeState.deadlineFrame=u;try{return t()}finally{this._runtimeState.deadlineFrame=o}}get _deadline(){return this._runtimeState.deadline}set _deadline(n){this._runtimeState.deadline=n}get _deadlineFrame(){return this._runtimeState.deadlineFrame}set _deadlineFrame(n){this._runtimeState.deadlineFrame=n}get _timeRemaining(){return this._runtimeState.timeRemaining}get _mapAutoCompileStats(){return Wo}get iterationLimit(){return this._runtimeState.iterationLimit}set iterationLimit(n){n!==this._runtimeState.iterationLimit&&(this._runtimeState.iterationLimit=n,this._noteStateEvent({kind:"config"}))}get recursionLimit(){return this._runtimeState.recursionLimit}set recursionLimit(n){this._runtimeState.recursionLimit=n}_enterRecursion(){this._runtimeState.enterRecursion()}_exitRecursion(){this._runtimeState.exitRecursion()}get maxCollectionSize(){return this._runtimeState.maxCollectionSize}set maxCollectionSize(n){this._runtimeState.maxCollectionSize=n}get _isVerifying(){return this._runtimeState.isVerifying}set _isVerifying(n){this._runtimeState.isVerifying=n}get isVerifying(){return this._runtimeState.isVerifying}get tolerance(){return this._numericConfiguration.tolerance}set tolerance(n){this._numericConfiguration.setTolerance(n)&&this._noteStateEvent({kind:"config"})}get _randomFrame(){return this._runtimeState.randomFrame}set _randomFrame(n){this._runtimeState.randomFrame=n}_random(){let n=this._runtimeState.randomFrame;if(n!==void 0){let t=n.next>>>0;return n.next=n.next+1>>>0,TD(n.seedLo,n.seedHi,t)}return Math.random()}_substream(n){return rG(this._runtimeState.randomFrame,n)}chop(n){let t=this._numericConfiguration.tolerance;return typeof n=="number"?Math.abs(n)<=t?0:n:n instanceof I?n.isPositive()&&n.lte(this._numericConfiguration.bignumTolerance)||n.isNegative()&&n.gte(this._numericConfiguration.negBignumTolerance)||n.isZero()?0:n:n instanceof te&&Math.abs(n.re)<=t&&Math.abs(n.im)<=t?0:n}bignum(n){return this._numericConfiguration.bignum(n)}complex(n,t){return n instanceof I&&(n=n.toNumber()),t instanceof I&&(t=t.toNumber()),new te(n,t)}_numericValue(n){if(n instanceof Qn)return n.asExact??n;let t=this._numericConfiguration.precision>Mu?i=>new mg(i):i=>new cd(i);if(typeof n=="number")return Number.isInteger(n)?new je(n,t):t(n);if(typeof n=="bigint")return new je(n,t);if(Ul(n))return new je({rational:n},t);if(n instanceof I){if(n.isInteger()){let i=Vt(n.toString());if(i!==null)return new je(i,t)}return t(n)}if(n instanceof te)return n.im===0?this._numericValue(n.re):t({re:n.re,im:n.im});if("im"in n||"re"in n)return n.im!==void 0&&n.im!==0?t(n):n.re instanceof I&&n.re.isInteger()?new je({rational:[Vt(n.re.toString()),BigInt(1)]},t):typeof n.re=="number"&&Number.isInteger(n.re)?new je({rational:[n.re,1]},t):t(n);if("radical"in n||"rational"in n){let i=n;if(i.radical!==void 0&&i.radical!==1){if(!Number.isInteger(i.radical)||i.radical<1)return t({re:tb(i.rational??[1,1])*Math.sqrt(i.radical)});if(i.radical>=Je){let[r,o]=Va(i.radical,2);if(o>=Je)return t({re:tb(i.rational??[1,1])*Math.sqrt(i.radical)});i={...i,radical:o,rational:it(i.rational??[1,1],[r,1])}}}return i.rational&&br(i.rational)&&(!Number.isInteger(i.rational[0])||!Number.isInteger(i.rational[1]))?t(i):new je(i,t)}throw Error(`Unexpected value: ${typeof n=="object"?JSON.stringify(n):String(n)}`)}get costFunction(){return this._cost??gpe}set costFunction(n){this._cost=typeof n=="function"?n:void 0}get simplificationRules(){return this._simplificationRules.rules}set simplificationRules(n){this._simplificationRules.rules=n,this._cacheStore.invalidate("standard-simplification-rules")}get solveRules(){return this._solveRules.rules}set solveRules(n){this._solveRules.rules=n,this._cacheStore.invalidate("univariate-roots-rules")}get harmonizationRules(){return this._harmonizationRules.rules}set harmonizationRules(n){this._harmonizationRules.rules=n,this._cacheStore.invalidate("harmonization-rules")}lookupDefinition(n){return Ffe(this,n)}normalizeIdentifier(n){if(!n)return"";if(Qt(n))return n;this.pushScope();try{let t=this.parse(n);if(T(t))return t.symbol}finally{this.popScope()}return""}operatorInfo(n){let t=this.lookupDefinition(n);if(!t||!pe(t))return;let i=t.operator,r=!!(i.evaluate||i.collection);return{kind:r?"function":"opaque",signature:i.signature,canEvaluate:r}}symbolInfo(n){let t=this.lookupDefinition(n);if(!t||!le(t))return;let i=t.value;return{kind:i.isConstant?"constant":"variable",type:i.type}}searchDefinitions(n,t){return Lfe(this,n,t)}suggestOperatorName(n){return Bfe(this,n)}functionProperties(n){return Jg(this,n)}_declareSymbolValue(n,t,i){return jfe(this,n,t,i)}_declareSymbolOperator(n,t,i){return qfe(this,n,t,i)}pushScope(n,t){Cme(this,n,t)}popScope(){kme(this)}createScope(n,t){return Pme(this,n,t)}_narrowingSink=void 0;_pushEvalContext(n,t,i){mj(this,n,t,i)}_popEvalContext(){hj(this)}_removeEvalContext(n){Ime(this,n)}_inScope(n,t){return Ame(this,n,t)}_resolveOnlyDepth=0;_resolveOnly(n){this._resolveOnlyDepth+=1;try{return n()}finally{this._resolveOnlyDepth-=1}}_printStack(n){Mme(this,n)}_bindingSymbol(n,t){return fxe(this,n,t)}_shadowedParameterStack=[];_pushShadowedParameters(n,t){this._shadowedParameterStack.push({names:new Set(n),types:t,defs:new Map,boundary:this.context.lexicalScope})}_popShadowedParameters(){this._shadowedParameterStack.pop()}_isShadowedParameter(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return!0;return!1}_shadowedParameterType(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return t[i].types?.get(n)}_shadowedParameterBoundary(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return t[i].boundary}_shadowedParameterDef(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return t[i].defs.get(n)}_setShadowedParameterDef(n,t){let i=this._shadowedParameterStack;for(let r=i.length-1;r>=0;r--)if(i[r].names.has(n)){i[r].defs.set(n,t);return}}_currentShadowedParameterDefs(){let n=this._shadowedParameterStack;return n.length>0?n[n.length-1].defs:new Map}_getSymbolValue(n){return zfe(this,n)}_setSymbolValue(n,t){Jfe(this,n,t)}declare(n,t,i){return Hfe(this,n,t,i)}declareSequence(n,t){return nhe(this,n,t)}getSequenceStatus(n){return the(this,n)}getSequence(n){return ihe(this,n)}listSequences(){return rhe(this)}isSequence(n){return ohe(this,n)}clearSequenceCache(n){she(this,n)}getSequenceCache(n){return ahe(this,n)}getSequenceTerms(n,t,i,r){return uhe(this,n,t,i,r)}lookupOEIS(n,t){return lhe(this,n,t)}checkSequenceOEIS(n,t,i){return fhe(this,n,t,i)}interpret(n,t){return che(this,n,t)}assign(n,t){return Wfe(this,n,t)}_shouldContinueExecution(){return this._runtimeState.shouldContinueExecution()}_checkContinueExecution(){if(!this._shouldContinueExecution())throw new Error("timeout")}_cache(n,t,i){return this._cacheStore.getOrBuild(n,()=>{let r=this._runtimeState.deadlineFrame;if(r===void 0)return t();this._runtimeState.deadlineFrame=void 0;try{return t()}finally{this._runtimeState.deadlineFrame=r}},i)}expr(n,t){let{canonical:i,structural:r}=bw(t);return gM(this,t?.scope,()=>Gi(this,n,{canonical:i,structural:r,scope:t?.scope}))}box(n,t){return this.expr(n,t)}rebind(n,t){return gM(this,t?.scope,()=>qpe(this,n,t))}_latexSyntax;get latexSyntax(){return!this._latexSyntax&&e._latexSyntaxFactory&&(this._latexSyntax=e._latexSyntaxFactory()),this._latexSyntax}_requireLatexSyntax(){if(!this._latexSyntax&&e._latexSyntaxFactory&&(this._latexSyntax=e._latexSyntaxFactory()),!this._latexSyntax)throw new Error("LatexSyntax not available. Pass a LatexSyntax instance to the ComputeEngine constructor.");return this._latexSyntax}_latexOptions={};get latexOptions(){return this._latexOptions}set latexOptions(n){dN(n),this._latexOptions={...n}}parse(n,t){if(n==null)return null;if(typeof n!="string")throw Error("ce.parse(): expected a LaTeX string");if(t?.speculative){if(t.scope!==void 0)throw Error("ce.parse(): the `speculative` and `scope` options are mutually exclusive \u2014 `speculative` discards the parse's writes, `scope` harvests them");let{speculative:b,...E}=t,x=this.parse(n,{...E,form:"raw"});this.pushScope(void 0,"speculative-parse");try{let S=this.context.lexicalScope;if(x!==null)for(let v of new Set(x.symbols)){let w=this.lookupDefinition(v);w!==void 0&&"value"in w&&!w.value.isConstant&&(w.value.inferredType||w.value.type.isUnknown)&&this.declare(v,{inferred:!0,type:w.value.type.type,...w.value.subscriptEvaluate?{subscriptEvaluate:w.value.subscriptEvaluate}:{}},S)}return this.parse(n,E)}finally{this.popScope()}}if(t?.scope)return gM(this,t.scope,()=>this.parse(n,{...t,scope:void 0}));let i=this._requireLatexSyntax(),{form:r,canonical:o,structural:s,scope:a,speculative:u,...l}=t??{},f=l.diagnostics??this._latexOptions?.diagnostics??!1,c,d,p,m=new Set;if(f){c=[],p=E=>m.add(E);let b=new Set;d=E=>{let x=`${E.code} ${E.start} ${E.end} ${E.detail?JSON.stringify(E.detail):""}`;b.has(x)||(b.add(x),c.push(E))}}let g=l.resolveSymbol??this._latexOptions?.resolveSymbol,y=g?b=>g(b)??this._resolveSymbolFromScope(b):b=>this._resolveSymbolFromScope(b);dM(this);try{let b=i.parse(n,{tolerance:this.tolerance,...this._latexOptions,...l,resolveSymbol:y,diagnostics:f,onDiagnostic:d,onBoundVariable:p});if(b===null)return null;let E=Gi(this,b,bw({form:r,canonical:o,structural:s}));if(c!==void 0){if(E=E._unshared(),E.isCanonical)try{let x=new Set(E.symbols),S=new Set(E.freeVariables);for(let v of c){if(v.code!=="undeclared-symbol")continue;let w=v.detail?.name;typeof w=="string"&&(m.has(w)||x.has(w)&&!S.has(w)&&`${w}`)}}catch{}for(let x of c)x.detail&&Object.freeze(x.detail),Object.freeze(x);E.parseDiagnostics=Object.freeze(c)}return E}finally{pM(this)}}_resolveSymbolFromScope(n){let t=this.lookupDefinition(n);if(t)return pe(t)?{type:t.operator.signature}:le(t)?{type:t.value.type,subscriptEvaluate:!!t.value.subscriptEvaluate}:{type:O.unknown}}appliedNonFunctions(n){let t=this.latexSyntax;if(!t)return[];let i=this._latexOptions?.resolveSymbol,r=t.parse(n,{...this._latexOptions,resolveSymbol:i?s=>i(s)??this._resolveSymbolFromScope(s):s=>this._resolveSymbolFromScope(s)}),o=new Set;return r!==null&&Iz(r,o),Array.from(o).sort()}function(n,t,i){let{canonical:r,structural:o}=bw(i);return gw(this,n,t,{metadata:i?.metadata,canonical:r,structural:o,scope:i?.scope})}error(n,t){return zP(this,n,t)}typeError(n,t,i){return yxe(this,n,t,i)}hold(n){return this._fn("Hold",[this.expr(n,{form:"raw"})])}tuple(...n){return new Jn(this,"Tuple",n.map(t=>typeof t=="number"?this.number(t):t.canonical).filter(t=>!T(t,"Nothing")),{canonical:!0})}list(n){let t=n.length;if(typeof t!="number"||!Number.isSafeInteger(t)||t<0)throw new TypeError(`list(): the length must be a non-negative safe integer, not ${String(t)}`);if(t===0)return this.function("List",[]);let i=new Array(t);for(let r=0;r<t;r++){let o=n[r];if(typeof o!="number")throw new TypeError(`list(): element ${r} is ${o===void 0?"undefined":typeof o}, not a number`);i[r]=o===0?0:o}return new Jn(this,"List",void 0,{canonical:!0,numericStore:Object.freeze(i)})}type(n){if(n instanceof O)return n;if(typeof n=="string"&&Ll(n)){let t=this._commonTypes.get(n);return t===void 0&&(t=new O(n,this._typeResolver),this._commonTypes.set(n,t)),t}return new O(n,this._typeResolver)}string(n,t){return new Pp(this,n,t)}character(n,t){if(!Op(n))throw new Error(`ce.character(): "${n}" is not exactly one grapheme cluster. A character is exactly one user-perceived character (one UAX #29 extended grapheme cluster); use ce.string() for arbitrary text, or CharacterFrom() to get a diagnostic instead of a throw.`);return new gk(this,n,t)}symbol(n,t){return lxe(this,this._commonSymbols,n,t)}number(n,t){return cxe(this,this._commonNumbers,n,t)}rules(n,t){return uT(this,n,t)}getRuleSet(n){if(n??="standard-simplification",n==="standard-simplification"){this._simplificationRules.hasMutatedSinceLastCache()&&this._cacheStore.invalidate("standard-simplification-rules");let t=this._cache("standard-simplification-rules",()=>{let r=uT(this,this._simplificationRules.rules,{canonical:!0}).rules.filter(o=>o.purpose!=="expand");return{rules:zre(r)}});return this._simplificationRules.markCached(),t}if(n==="solve-univariate"){this._solveRules.hasMutatedSinceLastCache()&&this._cacheStore.invalidate("univariate-roots-rules");let t=this._cache("univariate-roots-rules",()=>uT(this,this._solveRules.rules));return this._solveRules.markCached(),t}if(n==="harmonization"){this._harmonizationRules.hasMutatedSinceLastCache()&&this._cacheStore.invalidate("harmonization-rules");let t=this._cache("harmonization-rules",()=>uT(this,this._harmonizationRules.rules));return this._harmonizationRules.markCached(),t}}_fn(n,t,i){let r=i?.canonical??!0;return lp(t,this)?this.error("object-foreign-engine"):new Jn(this,n,t,{...i,canonical:r})}_object(n,t,i,r){return Ype(this,n,t,i,r)}ask(n){return vj(this,n)}verify(n){return Sj(this,n)}assume(n){return Kme(this,n)}forget(n){Tj(this,n)}};GP(()=>new Xm);var zxe=Xm;Xm._latexSyntaxFactory=()=>new Rp;GP(()=>new Xm({latexSyntax:new Rp}));globalThis[Symbol.for("io.cortexjs.compute-engine")]={ComputeEngine:Xm,version:"0.129.0",LatexSyntax:Rp,LATEX_DICTIONARY:tg,isExpression:$u,isNumber:N,isSymbol:T,isFunction:h,isString:J,isCharacter:sn,isTensor:Fu,isDictionary:Ve,isObject:yn,isCollection:kD,isIndexedCollection:ID,numericValue:at,sym:F,compile:HP};function Rz(e){return e.fg===void 0&&e.bg===void 0&&(e.weight===void 0||e.weight==="normal")&&(e.italic===void 0||e.italic===!1)}var KP=class{width;indent;constructor(n){this.width=n?.width,this.indent=n?.indent??0}renderBlock(n){let t="spans"in n?this.renderSpans(n.spans):n.blocks.map(i=>this.renderBlock(i)).join(`
1877
+ `),f=new mz(o,u,a);return{target:"interval-js",success:!0,code:o,...l?{preamble:l}:{},calling:"expression",run:f}}var $P=class{_targets=new Map;register(n,t){Cge(n),Ige(t),this._targets.set(n,t)}get(n){return this._targets.get(n)}list(){return[...this._targets.keys()]}unregister(n){this._targets.delete(n)}registerDefaults(){this.register("javascript",new jE),this.register("glsl",new YE),this.register("wgsl",new Qw),this.register("python",new XE),this.register("interval-js",new ux)}};var FP=class{_listeners=[];_registered=new WeakSet;_pending=!1;_version=0;listen(n){return this._registered.has(n)||(this._registered.add(n),this._listeners.push(n)),()=>this._unsubscribe(n)}_unsubscribe(n){this._registered.has(n)&&(this._registered.delete(n),this._listeners=this._listeners.filter(t=>t!==n))}notify(){if(this._pending)return;this._pending=!0;let n=this._version+1;queueMicrotask(()=>{if(n!==this._version+1){this._pending=!1;return}this.notifyNow()})}notifyNow(){this._version++;for(let n of this._listeners)try{n?.onConfigurationChange?.()}catch(t){console.error("Listener error:",t)}this._pending=!1}};function bGe(e){switch(e.kind){case"assumption":case"inference":case"config":case"binding-repair":return!0;case"redefine":case"type-write":return e.callableBefore||e.callableAfter;case"scope-pop":return e.assumptionsDirty;case"value-write":return e.callable;case"declare":return!e.scratch&&(e.callable||e.shadowsCallable);case"object-store":return!1}}var EGe=(()=>{if(typeof process>"u")return!1;let e=process.env?.CE_OBJECT_STORE_BUMPS_ANY;return e!==void 0&&e!=="0"})();function xGe(e){switch(e.kind){case"value-write":return{any:!0,semantic:!e.ephemeral,world:!1};case"declare":return e.scratch?{any:!1,semantic:!1,world:!1}:{any:!0,semantic:!1,world:!1};case"binding-repair":return{any:!0,semantic:!1,world:!1};case"redefine":return e.callableAfter?{any:!1,semantic:!0,world:!0}:{any:!1,semantic:!1,world:!1};case"type-write":return{any:!0,semantic:!1,world:!1};case"scope-pop":return{any:!e.transient&&!e.clean||e.assumptionsDirty,semantic:e.assumptionsDirty,world:e.assumptionsDirty};case"assumption":return{any:!0,semantic:!0,world:!0};case"inference":return e.valueType?{any:!1,semantic:!1,world:!1}:e.symbolSignature?{any:!0,semantic:!0,world:!0}:{any:!0,semantic:!0,world:!0};case"config":return{any:!0,semantic:!0,world:!0};case"object-store":return EGe?{any:!0,semantic:!1,world:!1}:{any:!1,semantic:!1,world:!1}}}var LP=class{_anyVersion=0;_semanticVersion=0;_worldVersion=0;_callableVersion=0;_ephemeralWriteDepth=0;_factSuppressionDepth=0;_scratchDeclarationScopes=[];_tracker=new FP;get anyVersion(){return this._anyVersion}get semanticVersion(){return this._semanticVersion}get worldVersion(){return this._worldVersion}get callableVersion(){return this._callableVersion}get ephemeralWriteDepth(){return this._ephemeralWriteDepth}set ephemeralWriteDepth(n){this._ephemeralWriteDepth=n}get factSuppressionDepth(){return this._factSuppressionDepth}set factSuppressionDepth(n){this._factSuppressionDepth=n}get scratchDeclarationScopes(){return this._scratchDeclarationScopes}noteStateEvent(n){let t=xGe(n);t.any&&(this._anyVersion+=1),t.semantic&&(this._semanticVersion+=1),t.world&&(this._worldVersion+=1),bGe(n)&&(this._callableVersion+=1),We&&(t.any&&Vy("generation"),t.semantic&&Vy("mutationGeneration"),t.world&&Vy("semanticEpoch"))}reset(n){this._scratchDeclarationScopes.length=0,this.noteStateEvent({kind:"config"}),n.refreshNumericConstants(),n.resetCommonSymbols(),n.purgeCaches(),this._tracker.notifyNow()}listen(n){return this._tracker.listen(n)}};function vGe(e){return!!(e===void 0||e==="Number"||e===!0||Array.isArray(e)&&e.includes("Number"))}function lxe(e,n,t,i){let r=i?.canonical??!0,o=i?.metadata,s=t.normalize(),a=s.toLowerCase();if(a==="infinity"||a==="+infinity")return e.PositiveInfinity;if(a==="-infinity")return e.NegativeInfinity;if(e.strict&&!Qt(s))return e.error(["invalid-symbol",ca(s)],s);if(!r)return new zs(e,s,{metadata:o});if(e._isShadowedParameter(s)){let d=e._shadowedParameterType(s);if(d!==void 0){let E=e._shadowedParameterDef(s);if(E!==void 0)return new zs(e,s,{metadata:o,def:E});let x=e.context.lexicalScope;for(;x.noAutoDeclare&&x.parent;)x=x.parent;let S=x.bindings.get(s),v=S??e._declareSymbolValue(s,{type:d,inferred:!1},x);e._setShadowedParameterDef(s,v);let w=new zs(e,s,{metadata:o,def:v});return S===void 0&&le(v)&&ja(e,v.value,{type:v.value.type,kind:"auto-declared",axis:"type",cause:w,epoch:qa(e)}),w}let p=e._shadowedParameterDef(s);if(p!==void 0)return new zs(e,s,{metadata:o,def:p});let m=e.context.lexicalScope;for(;m.noAutoDeclare&&m.parent;)m=m.parent;let g=m.bindings.get(s),y=g??e._declareSymbolValue(s,{type:"unknown",inferred:!0},m);e._setShadowedParameterDef(s,y);let b=new zs(e,s,{metadata:o,def:y});return g===void 0&&le(y)&&ja(e,y.value,{type:y.value.type,kind:"auto-declared",axis:"type",cause:b,epoch:qa(e)}),b}let u=Object.hasOwn(n,s)?n[s]:void 0;if(u)return u;let l=e.lookupDefinition(s);if(le(l)&&l.value.holdUntil==="never")return l.value.value??e.Nothing;if(l)return new zs(e,s,{metadata:o,def:l});if(i?.autoDeclare===!1||e._resolveOnlyDepth>0)return new zs(e,s,{metadata:o});let f=e.context.lexicalScope;for(;f.noAutoDeclare&&f.parent;)f=f.parent;l=e._declareSymbolValue(s,{type:"unknown",inferred:!0},f),e._boxingState.isPersistentScope(f)===!1&&e._boxingState.noteTransientAutoDeclare(s);let c=new zs(e,s,{metadata:o,def:l});return le(l)&&ja(e,l.value,{type:l.value.type,kind:"auto-declared",axis:"type",cause:c,epoch:qa(e)}),c}function fxe(e,n,t){let i=t.bindings.get(n);if(le(i))return new zs(e,n,{def:i})}function cxe(e,n,t,i){let r=i?.metadata;if(!vGe(i?.canonical)&&Ul(t))return e._fn("Rational",[e.number(t[0]),e.number(t[1])],{...r,canonical:!1});let s=TR(e,t);if(r===void 0){if(typeof s=="number"){let a=s;if(a===1)return e.One;if(a===0)return e.Zero;if(a===-1)return e.NegativeOne;if(a===2)return e.Two;if(Number.isInteger(a)&&n[a]!==void 0)return n[a]??=new ki(e,s),n[a];if(Number.isNaN(a))return e.NaN;if(!Number.isFinite(a))return a<0?e.NegativeInfinity:e.PositiveInfinity}else if(s instanceof Qn){if(s.isZero)return e.Zero;if(s.isOne)return e.One;if(s.isNegativeOne)return e.NegativeOne;if(s.isNaN)return e.NaN;if(s.isNegativeInfinity)return e.NegativeInfinity;if(s.isPositiveInfinity)return e.PositiveInfinity}}return new ki(e,s,{metadata:r})}var fx=class{_rules;_cachedLength=-1;constructor(n){this._rules=n}get rules(){return this._rules}set rules(n){this._rules=n,this._cachedLength=-1}hasMutatedSinceLastCache(){return this._cachedLength>=0&&this._rules.length!==this._cachedLength}markCached(){this._cachedLength=this._rules.length}};var BP=class{_precision;_angularUnit;_tolerance;_bignumTolerance;_negBignumTolerance;constructor(n){let t=n?.precision??bD;t==="machine"&&(t=Math.floor(Mu)),this._precision=t,I.precision=t,this._angularUnit=n?.angularUnit??"rad",this._tolerance=Zy,this._bignumTolerance=new I(Zy),this._negBignumTolerance=new I(-Zy),this.setTolerance(n?.tolerance??"auto")}get precision(){return this._precision}setPrecision(n){let t=n;if(t==="machine"&&(t=Mu),t==="auto"&&(t=bD),t===this._precision)return!1;if(typeof t!="number"||t<=0)throw Error('Expected "machine" or a positive number');return this._precision=Math.max(t,Mu),I.precision=this._precision,this.setTolerance("auto"),!0}get angularUnit(){return this._angularUnit}setAngularUnit(n){if(n===this._angularUnit)return!1;if(typeof n!="string")throw Error("Expected a string");return this._angularUnit=n,!0}get tolerance(){return this._tolerance}setTolerance(n){let t=n;return t==="auto"&&(t=Zy),(!Number.isFinite(t)||t<0)&&(t=Math.pow(10,-this._precision+2)),t===this._tolerance?!1:(this._tolerance=t,this._bignumTolerance=new I(t),this._negBignumTolerance=new I(-t),!0)}get bignumTolerance(){return this._bignumTolerance}get negBignumTolerance(){return this._negBignumTolerance}get bignumNaN(){return I.NAN}get bignumZero(){return I.ZERO}get bignumOne(){return I.ONE}get bignumTwo(){return I.TWO}get bignumHalf(){return I.HALF}get bignumPi(){return I.PI}get bignumNegativeOne(){return I.NEGATIVE_ONE}bignum(n){if(n instanceof I)return n;try{return new I(n)}catch(t){t instanceof Error?console.error(t.message):console.error(String(t))}return I.NAN}};var VP=class{_iterationLimit=1024;_recursionLimit=256;_recursionDepth=0;_maxCollectionSize=1e4;_deadlineFrame=void 0;_randomFrame=void 0;_isVerifying=!1;get iterationLimit(){return this._iterationLimit}set iterationLimit(n){this._iterationLimit=n<=0?Number.POSITIVE_INFINITY:n}get recursionLimit(){return this._recursionLimit}set recursionLimit(n){this._recursionLimit=n<=0?Number.POSITIVE_INFINITY:n}get recursionDepth(){return this._recursionDepth}enterRecursion(){if(this._recursionDepth>=this._recursionLimit)throw new Ae({cause:"recursion-depth-exceeded",message:"Recursion limit exceeded"});this._recursionDepth+=1}exitRecursion(){this._recursionDepth>0&&(this._recursionDepth-=1)}get maxCollectionSize(){return this._maxCollectionSize}set maxCollectionSize(n){this._maxCollectionSize=n<=0?Number.POSITIVE_INFINITY:n}get deadlineFrame(){return this._deadlineFrame}set deadlineFrame(n){this._deadlineFrame=n}get deadline(){return this._deadlineFrame?.at}set deadline(n){this._deadlineFrame=n===void 0?void 0:{at:n,spans:[]}}get randomFrame(){return this._randomFrame}set randomFrame(n){this._randomFrame=n}get timeRemaining(){return this._deadlineFrame===void 0?Number.POSITIVE_INFINITY:this._deadlineFrame.at-Date.now()}get isVerifying(){return this._isVerifying}set isVerifying(n){this._isVerifying=n}shouldContinueExecution(){return this._deadlineFrame===void 0||this._deadlineFrame.at>=Date.now()}};var jP=class{_frames=[];_rootActive=!1;_isPersistentScope=null;_transientAutoDeclares=null;withRootRepair(n,t){if(this._rootActive)return n();this._rootActive=!0,this._isPersistentScope=t??null;try{return this._withRepairFrame(void 0,()=>(this._transientAutoDeclares=null,n()))}finally{this._rootActive=!1,this._isPersistentScope=null,this._transientAutoDeclares=null}}get isRootActive(){return this._rootActive}withScopedRepair(n,t){return this._rootActive?this._withRepairFrame(n,t):t()}get isRebuilding(){return this._frames.some(n=>n.rebuilding)}isPersistentScope(n){if(!(!this._rootActive||!this._isPersistentScope))return this._isPersistentScope(n)}noteTransientAutoDeclare(n){!this._rootActive||!this._isPersistentScope||(this._transientAutoDeclares??=new Set).add(n)}noteDeclarationIn(n,t){if(!this._rootActive||!this._transientAutoDeclares?.has(t)||this._isPersistentScope?.(n)!==!0)return;let i=this._frames.find(r=>r.scope===void 0);i&&(i.repairRequested=!0)}frameDepth(){return this._frames.length}hasRepairRequestedAtOrAbove(n){for(let t=n;t<this._frames.length;t++)if(this._frames[t].repairRequested)return!0;return!1}noteDevolvedShadow(n){for(let i=this._frames.length-1;i>=0;i--){let r=this._frames[i];if(r.scope===n){r.repairRequested=!0;return}}let t=this._frames.find(i=>i.scope===void 0);t&&(t.repairRequested=!0)}_withRepairFrame(n,t){let i={scope:n,repairRequested:!1,rebuilding:!1};this._frames.push(i);try{let r=t(),o=0;for(;i.repairRequested;){if(o>=3){let s="Devolved-shadow repair did not stabilize after 3 rebuilds";throw new Error(s)}i.repairRequested=!1,i.rebuilding=!0,o+=1;try{r=t()}finally{i.rebuilding=!1}}return r}finally{let r=this._frames.pop()}}};function SGe(e){if(typeof e!="string")return Rge(e),e;let n=cy.find(t=>t.name===e);if(!n)throw new Error(`Unknown standard library: "${e}"`);return n}function dxe(e){return e?rM(e.map(SGe)):[...oM()]}function TGe(e){return cy.includes(e)}function pxe(e,n){for(let t of n){let i=t.definitions;if(!i)continue;let r=!TGe(t),o=Array.isArray(i)?i:[i];for(let s of o){if(r)for(let a of Object.keys(s))e._customLibraryOperators.add(a.normalize());hpe(e,s)}}}function cx(e,n){let t=e[n];if(!t)throw new Error(`Common symbol "${n}" failed to initialize`);return t}var qP=class{constructor(n){this.engine=n}engine;initializeCommonNumbers(){return{Zero:new ki(this.engine,0),One:new ki(this.engine,1),Half:new ki(this.engine,{rational:[1,2]}),NegativeOne:new ki(this.engine,-1),Two:new ki(this.engine,2),NaN:new ki(this.engine,Number.NaN),PositiveInfinity:new ki(this.engine,Number.POSITIVE_INFINITY),NegativeInfinity:new ki(this.engine,Number.NEGATIVE_INFINITY),I:new ki(this.engine,{rational:[0,1],imRational:[1,1]}),ComplexInfinity:new ki(this.engine,{re:1/0,im:1/0})}}bootstrapLibraries(n){let t=dxe(n);pxe(this.engine,t)}initializeCommonSymbolBindings(n){return phe(this.engine,n),{True:cx(n,"True"),False:cx(n,"False"),Pi:cx(n,"Pi"),E:cx(n,"ExponentialE"),Nothing:cx(n,"Nothing"),Missing:cx(n,"Missing")}}};function mxe(e){let n=new Set,t=(i,r)=>{if(i==="never")return!0;let o=e._protocolRegistry?.[r];if(o===void 0)return!1;let s=`${mo(i)} ${r}`;if(n.has(s))return!1;n.add(s);try{return o.conformances.some(a=>a.where===void 0?R(i,a.target):dk(a.target,a.where,i,t)!==null)}finally{n.delete(s)}};return{get names(){return Object.keys(e._typeRegistry)},resolve(i){let r=e._typeRegistry[i];if(r!==void 0)return r;if(e._protocolRegistry?.[i]!==void 0)throw new ot("protocol-in-type-position",`\`${i}\` is a protocol, not a type. Use a constrained variable: \`(x: T) -> boolean where T is ${i}\``)},forward(i){let r=e._typeRegistry[i];if(r!==void 0)return r;let o={kind:"reference",name:i,alias:!1,def:void 0};return e._typeRegistry[i]=o,o},conformsTo:t}}function zP(e,n,t){let i;typeof n=="string"?i=e.string(n):i=e.function("ErrorCode",n.map(s=>e.string(s)));let r;t!==void 0&&typeof t!="string"?r=t:t&&PC(t)?r=e.function("LatexString",[e.string(wp(t))]):typeof t=="string"&&t.length>0&&(r=e.string(t));let o=[e.expr(i)];return r&&o.push(r),e.function("Error",o)}function hxe(e){if(typeof e=="object"){if((e.kind==="collection"||e.kind==="indexed_collection"||e.kind==="set"||e.kind==="list"&&e.dimensions===void 0)&&e.elements==="any")return e.kind;if(e.kind==="dictionary"&&e.values==="any")return"dictionary"}return e}function gxe(e){let n=hxe(e);if(n!==e)return ne(n);if(typeof e=="object"&&e.kind==="union"){let t=e.types.map(hxe);if(t.some((i,r)=>i!==e.types[r]))return ne(ze({...e,types:t}))}return ne(e)}function yxe(e,n,t,i){if(t){if(typeof i=="object"&&i!==null&&"type"in i&&"engine"in i){let o=i;$2(o.engine)&&t.toString()===o.type.toString()&&(t=one(o.engine,()=>o.type))}let r=typeof t=="object"&&"kind"in t?ne(t):t.toString();return zP(e,["incompatible-type",gxe(n),r],i)}return zP(e,["incompatible-type",gxe(n)],i)}function JP(e,n){Age(n);let t=_Ge(n);n=t.options;let i=t.modeFromAlias;if(n?.target!==void 0&&n.cse===!0)throw new Error("CSE is not supported on direct custom targets in Phase 1; omit `cse` or use a registered target.");if(n?.target!==void 0&&n.storage!==void 0&&Object.keys(n.storage).length>0)throw new Error('The `storage` option is not supported on direct custom targets: the sampler-backed read needs the reference gate and the helper preamble a registered target provides. Omit `storage` or use a registered target (`to: "glsl"`).');if(n?.target===void 0&&n?.storage!==void 0){let r=e.engine._getCompilationTarget(n.to??"javascript")?.createTarget();r!==void 0&&uc(n.storage,[e],r,{vars:n.vars,functions:n.functions})}try{if(n?.target){let a=us(ci(e),{skipHeads:Am(n.operators,n.functions),iterationBudget:n.target.iterationBudget,readsLiveSource:d=>typeof n.vars?.[d]=="string"}),u=[n.preamble,n.target.preamble,...n.vars?Object.values(n.vars):[],...n.functions?Object.values(n.functions).map(d=>{let p=$m(d);return typeof p=="string"?p:void 0}):[]];n.target.naming=A.newNamingContext(a,u),n.target.cse={enabled:!1,instances:[]},n.target.constantFold=n.constantFold,n.target.complexPromotion=n.complexPromotion,n.target.storage=void 0,n.target.mode=NGe(n.target,i&&!(n.target.supportedModes??["strict"]).includes("complex")?void 0:n.mode);let l,f;try{l=A.compileRoot(a,n.target)}catch(d){if(!Mw(d)||n.target.mode!=="auto")throw d;n.target.reset?.(),n.target.mode="complex",n.target.naming=A.newNamingContext(a,u),l=A.compileRoot(a,n.target),f=d.diagnostic}let c=A.withReferences({target:n.target.language??"custom",success:!0,code:l},e,n.target,n.vars?new Set(Object.keys(n.vars)):void 0);return f!==void 0&&(c.escalation=f),c}let r=n?.to??"javascript",o=e.engine._getCompilationTarget(r);if(!o)throw new Error(`Compilation target "${r}" is not registered. Available targets: ${e.engine._listCompilationTargets().join(", ")}`);let s={fallback:n?.fallback??!0,operators:n?.operators,functions:n?.functions,vars:n?.vars,imports:n?.imports,preamble:n?.preamble,complexPromotion:n?.complexPromotion,mode:n?.mode,entryChecks:n?.entryChecks,iterationBudget:n?.iterationBudget,quadrature:n?.quadrature,symbolDeps:n?.symbolDeps,varsObjectRefs:n?.varsObjectRefs,cse:n?.cse,constantFold:n?.constantFold,storage:n?.storage};return i&&!wGe(o,"complex")&&(s.mode=void 0),o.compile(e,s)}catch(r){if(n?.fallback??!0){let o=r.message;console.warn(`Compilation fallback for "${e.operator}" (target: ${n?.to??"javascript"}): ${o}`);let s=n?.to??"javascript";if(s==="interval-js"){let u=e.engine._getCompilationTarget("interval-js");if(u)return u.compile(e,{vars:n?.vars,fallback:!0})}let a=n?.target??e.engine._getCompilationTarget(s)?.createTarget();return A.buildInterpreterFallback(e,o,s,a,n?.vars?new Set(Object.keys(n.vars)):void 0,ac(r,o))}throw r}}var bxe=new WeakMap;function wGe(e,n){let t=bxe.get(e);return t===void 0&&(t=e.createTarget().supportedModes??["strict"],bxe.set(e,t)),t.includes(n)}function _Ge(e){return e===void 0?{options:e,modeFromAlias:!1}:lc(e)}function NGe(e,n){let t=e.supportedModes??["strict"],i=typeof e.complexLift=="function"&&typeof e.complexIsReal=="function",r=t.includes("auto")&&i&&typeof e.reset=="function";return n===void 0?r?"auto":"strict":n==="auto"&&t.includes("auto")&&!r?"strict":n}var Ez=null,xz=null;function GP(e){xz=e}function UP(){if(!Ez){if(!xz)throw new Error("ComputeEngine factory not registered. Import from the main module.");Ez=xz()}return Ez}function CGe(e,n){if(typeof e=="string"){let t=UP();return t.parse(e,{strict:n?.strict??!1})??t.expr("Nothing")}return $u(e)?e:UP().expr(e)}function HP(e,n){return JP(CGe(e,n),n)}var kGe=/^(Sin|Cos|Tan|Cot|Sec|Csc)$/;function WP(e){return kGe.test(e.operator)?!0:h(e)?e.ops.some(WP):!1}function Km(e,...n){return n.includes(e.operator)?!0:h(e)?e.ops.some(t=>Km(t,...n)):!1}function gi(e,n){let t=e.engine;if(h(e)&&e.ops.length>0){let i=e,r=i.ops.map(s=>gi(s,n));r.some((s,a)=>s!==i.ops[a])&&(e=t._fn(i.operator,r))}return n(e)??e}function vz(e,n){if(!h(e)||!h(n))return!1;let t=e.op1,i=n.op1;return t!==void 0&&i!==void 0&&t.isSame(i)}function IGe(e){let n=e.engine,t=e.operator;if(!h(e))return;let i=e.op1;if(i){if(t==="Sec")return n.One.div(n._fn("Cos",[i]));if(t==="Csc")return n.One.div(n._fn("Sin",[i]))}}function Txe(e){return gi(e,IGe)}function RGe(e){let n=e.engine,t=e.operator;if(!h(e))return;let i=e.op1;if(i){if(t==="Tan")return n._fn("Sin",[i]).div(n._fn("Cos",[i]));if(t==="Cot")return n._fn("Cos",[i]).div(n._fn("Sin",[i]))}}function wxe(e){return gi(e,RGe)}function AGe(e){let n=e.engine;if(e.operator!=="Divide"||!h(e))return;let t=e.op1,i=e.op2;if(!(!t||!i)){if(t.operator==="Sin"&&i.operator==="Cos"&&vz(t,i))return h(t)?n._fn("Tan",[t.op1]):void 0;if(t.operator==="Cos"&&i.operator==="Sin"&&vz(t,i))return h(t)?n._fn("Cot",[t.op1]):void 0}}function _xe(e){return gi(e,AGe)}function MGe(e){if(h(e,"Negate"))return e.op1;if(h(e,"Multiply")){let n=e.ops.findIndex(t=>t.isSame(-1));if(n>=0){let t=e.ops.filter((i,r)=>r!==n);return t.length===1?t[0]:e.engine._fn("Multiply",t)}}}function PGe(e){let n=e.engine,t=e.operator;if(!h(e))return;let i=e.op1;if(!i)return;let r=MGe(i);if(r){if(t==="Cos")return n._fn("Cos",[r]);if(t==="Sec")return n._fn("Sec",[r]);if(t==="Sin")return n._fn("Sin",[r]).neg();if(t==="Tan")return n._fn("Tan",[r]).neg();if(t==="Csc")return n._fn("Csc",[r]).neg();if(t==="Cot")return n._fn("Cot",[r]).neg()}}function Nxe(e){return gi(e,PGe)}function OGe(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||t.operator!=="Sin"||!i.isSame(2)||!h(t))return;let r=t.op1;if(r)return n.One.sub(n._fn("Cos",[r]).pow(2))}function Sz(e){return gi(e,OGe)}function DGe(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||t.operator!=="Cos"||!i.isSame(2)||!h(t))return;let r=t.op1;if(r)return n.One.sub(n._fn("Sin",[r]).pow(2))}function Cxe(e){return gi(e,DGe)}function $Ge(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||t.operator!=="Cos"||!i.isSame(2)||!h(t))return;let r=t.op1;if(r)return n.One.add(n._fn("Cos",[r.mul(2)])).div(2)}function kxe(e){return gi(e,$Ge)}function FGe(e){let n=e.engine;if(h(e,"Divide")){let i=e.op1,r=e.op2;if(!i||!r||!r.isSame(2))return;if(h(i,"Add")&&i.ops.length===2)return Exe(n,i.ops)}let t=i=>!!(i.re===.5&&i.im===0||i.isSame(n.Half));if(h(e,"Multiply")){let i=e.ops.findIndex(r=>t(r));if(i>=0){let r=e.ops.filter((o,s)=>s!==i);if(r.length===1&&r[0].operator==="Add"){let o=r[0];if(h(o)&&o.ops.length===2)return Exe(n,o.ops)}}}if(h(e,"Add")&&e.ops.length===2){let i,r,o=!1,s=a=>a.re===-.5&&a.im===0;for(let a of e.ops){if(t(a)){i=a;continue}let u=a,l=!1;if(h(a,"Negate")&&(l=!0,u=a.op1),h(u,"Divide")&&u.op2?.isSame(2)){let f=u.op1;if(f?.operator==="Cos"){r=f,o=l;continue}}if(h(u,"Multiply")){let f=u.ops.findIndex(d=>t(d));if(f>=0){let d=u.ops.filter((p,m)=>m!==f);if(d.length===1&&d[0].operator==="Cos"){r=d[0],o=l;continue}}let c=u.ops.findIndex(d=>s(d));if(c>=0){let d=u.ops.filter((p,m)=>m!==c);if(d.length===1&&d[0].operator==="Cos"){r=d[0],o=!l;continue}}}}if(i&&r){if(!h(r))return;let a=r.op1;if(!a)return;let u;if(h(a,"Multiply")){let l=a.ops.findIndex(f=>f.isSame(2));if(l>=0){let f=a.ops.filter((c,d)=>d!==l);u=f.length===1?f[0]:n._fn("Multiply",f)}}return u?o?n._fn("Sin",[u]).pow(2):n._fn("Cos",[u]).pow(2):void 0}}}function Exe(e,n){let t=-1,i=-1,r=!1;for(let u=0;u<n.length;u++)if(n[u].isSame(1))t=u;else if(n[u].operator==="Cos")i=u,r=!1;else if(n[u].operator==="Negate"){let l=n[u];h(l)&&l.op1?.operator==="Cos"&&(i=u,r=!0)}if(t<0||i<0)return;let o;if(r){let u=n[i];if(!h(u))return;o=u.op1}else o=n[i];if(!h(o))return;let s=o.op1;if(!s)return;let a;if(h(s,"Multiply")){let u=s.ops.findIndex(l=>l.isSame(2));if(u>=0){let l=s.ops.filter((f,c)=>c!==u);a=l.length===1?l[0]:e._fn("Multiply",l)}}if(a)return r?e._fn("Sin",[a]).pow(2):e._fn("Cos",[a]).pow(2)}function Tz(e){return gi(e,FGe)}function LGe(e){let n=e.engine;if(e.operator!=="Multiply"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r];if(!h(o)||!h(s))continue;let a=o.op1,u=s.op1;if(!a||!u)continue;let l;if(o.operator==="Sin"&&s.operator==="Cos"?l=n._fn("Sin",[a.add(u)]).add(n._fn("Sin",[a.sub(u)])).div(2):o.operator==="Cos"&&s.operator==="Sin"?l=n._fn("Sin",[a.add(u)]).sub(n._fn("Sin",[a.sub(u)])).div(2):o.operator==="Cos"&&s.operator==="Cos"?l=n._fn("Cos",[a.add(u)]).add(n._fn("Cos",[a.sub(u)])).div(2):o.operator==="Sin"&&s.operator==="Sin"&&(l=n._fn("Cos",[a.sub(u)]).sub(n._fn("Cos",[a.add(u)])).div(2)),l){let f=t.filter((c,d)=>d!==i&&d!==r);return f.length===0?l:l.mul(f.length===1?f[0]:n._fn("Multiply",f))}}}function Ixe(e){return gi(e,LGe)}function BGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r],a;if(o.operator==="Sin"&&s.operator==="Sin"){if(!h(o)||!h(s))continue;let u=o.op1,l=s.op1;if(u&&l){let f=u.add(l).div(2),c=u.sub(l).div(2);a=n._fn("Sin",[f]).mul(n._fn("Cos",[c])).mul(2)}}else if(o.operator==="Cos"&&s.operator==="Cos"){if(!h(o)||!h(s))continue;let u=o.op1,l=s.op1;if(u&&l){let f=u.add(l).div(2),c=u.sub(l).div(2);a=n._fn("Cos",[f]).mul(n._fn("Cos",[c])).mul(2)}}else if(o.operator==="Sin"&&s.operator==="Negate"){if(!h(o)||!h(s)||s.op1?.operator!=="Sin")continue;let u=s.op1;if(!h(u))continue;let l=o.op1,f=u.op1;if(l&&f){let c=l.add(f).div(2),d=l.sub(f).div(2);a=n._fn("Cos",[c]).mul(n._fn("Sin",[d])).mul(2)}}else if(o.operator==="Cos"&&s.operator==="Negate"){if(!h(o)||!h(s)||s.op1?.operator!=="Cos")continue;let u=s.op1;if(!h(u))continue;let l=o.op1,f=u.op1;if(l&&f){let c=l.add(f).div(2),d=l.sub(f).div(2);a=n._fn("Sin",[c]).mul(n._fn("Sin",[d])).mul(-2)}}if(a){let u=t.filter((l,f)=>f!==i&&f!==r);return u.length===0?a:a.add(u.length===1?u[0]:n._fn("Add",u))}}}function YP(e){return gi(e,BGe)}function VGe(e){let n=e.engine,t=e.operator;if(t!=="Sin"&&t!=="Cos"||!h(e))return;let i=e.op1;if(i){if(h(i,"Add")&&i.ops.length===2){let[r,o]=i.ops;return t==="Sin"?n._fn("Sin",[r]).mul(n._fn("Cos",[o])).add(n._fn("Cos",[r]).mul(n._fn("Sin",[o]))):n._fn("Cos",[r]).mul(n._fn("Cos",[o])).sub(n._fn("Sin",[r]).mul(n._fn("Sin",[o])))}if(h(i,"Subtract")){let r=i.op1,o=i.op2;return!r||!o?void 0:t==="Sin"?n._fn("Sin",[r]).mul(n._fn("Cos",[o])).sub(n._fn("Cos",[r]).mul(n._fn("Sin",[o]))):n._fn("Cos",[r]).mul(n._fn("Cos",[o])).add(n._fn("Sin",[r]).mul(n._fn("Sin",[o])))}}}function Rxe(e){return gi(e,VGe)}function jGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r],a=v=>{if(v.operator!=="Multiply"||!h(v))return null;let w=v.ops;if(w.length!==2)return null;let[_,C]=w;return _.operator==="Sin"&&C.operator==="Cos"?{sin:_,cos:C}:_.operator==="Cos"&&C.operator==="Sin"?{sin:C,cos:_}:null},u=v=>{if(v.operator!=="Multiply"||!h(v))return null;let w=v.ops;if(w.length!==2)return null;let[_,C]=w;return _.operator==="Cos"&&C.operator==="Cos"?{cos1:_,cos2:C}:null},l=v=>{if(v.operator!=="Multiply"||!h(v))return null;let w=v.ops;if(w.length!==2)return null;let[_,C]=w;return _.operator==="Sin"&&C.operator==="Sin"?{sin1:_,sin2:C}:null},f=v=>h(v)?v.op1:void 0,c=a(o),d=a(s),p=h(o,"Negate")&&o.op1?a(o.op1):null,m=h(s,"Negate")&&s.op1?a(s.op1):null;if(c&&d){let v=f(c.sin),w=f(c.cos),_=f(d.sin),C=f(d.cos);if(v&&w&&_&&C&&v.isSame(C)&&w.isSame(_)){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Sin",[v.add(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(c&&m){let v=f(c.sin),w=f(c.cos),_=f(m.sin),C=f(m.cos);if(v&&w&&_&&C&&v.isSame(C)&&w.isSame(_)){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Sin",[v.sub(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(p&&d){let v=f(p.sin),w=f(p.cos),_=f(d.sin),C=f(d.cos);if(v&&w&&_&&C&&_.isSame(w)&&C.isSame(v)){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Sin",[_.sub(C)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}let g=u(o),y=u(s),b=l(o),E=l(s),x=h(o,"Negate")&&o.op1?l(o.op1):null,S=h(s,"Negate")&&s.op1?l(s.op1):null;if(g&&S){let v=f(g.cos1),w=f(g.cos2),_=f(S.sin1),C=f(S.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.add(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(x&&y){let v=f(y.cos1),w=f(y.cos2),_=f(x.sin1),C=f(x.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.add(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(g&&E){let v=f(g.cos1),w=f(g.cos2),_=f(E.sin1),C=f(E.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.sub(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}if(b&&y){let v=f(y.cos1),w=f(y.cos2),_=f(b.sin1),C=f(b.sin2);if(v&&w&&_&&C&&(v.isSame(_)&&w.isSame(C)||v.isSame(C)&&w.isSame(_))){let k=t.filter((j,V)=>V!==i&&V!==r),M=n._fn("Cos",[v.sub(w)]);return k.length===0?M:M.add(k.length===1?k[0]:n._fn("Add",k))}}}}function ZP(e){return gi(e,jGe)}function qGe(e){let n=e.engine,t=e.operator;if(t!=="Sin"&&t!=="Cos"||!h(e))return;let i=e.op1;if(i&&h(i,"Multiply")){let r=i.ops,o=r.findIndex(s=>s.isSame(2));if(o>=0){let s=r.filter((u,l)=>l!==o),a=s.length===1?s[0]:n._fn("Multiply",s);return t==="Sin"?n._fn("Sin",[a]).mul(n._fn("Cos",[a])).mul(2):n._fn("Cos",[a]).pow(2).mul(2).sub(n.One)}}}function wz(e){return gi(e,qGe)}function zGe(e){let n=e.engine;if(h(e,"Multiply")){let t=e.ops,i=t.findIndex(r=>r.isSame(2));if(i>=0){let r=t.filter((a,u)=>u!==i),o,s;for(let a of r)a.operator==="Sin"&&!o?o=a:a.operator==="Cos"&&!s&&(s=a);if(o&&s&&vz(o,s)){if(!h(o))return;let a=r.filter(l=>l!==o&&l!==s),u=n._fn("Sin",[o.op1.mul(2)]);return a.length===0?u:u.mul(a.length===1?a[0]:n._fn("Multiply",a))}}}if(h(e,"Add")&&e.ops.length===2){let[t,i]=e.ops;if(h(t,"Power")&&t.op1?.operator==="Cos"&&t.op2?.isSame(2)&&i.operator==="Negate"&&h(i)&&i.op1?.operator==="Power"&&h(i.op1)&&i.op1.op1?.operator==="Sin"&&i.op1.op2?.isSame(2)){let u=t.op1,l=i.op1;if(h(u)&&h(l)){let f=l.op1;if(h(f)){let c=u.op1,d=f.op1;if(c&&d&&c.isSame(d))return n._fn("Cos",[c.mul(2)])}}}let r=u=>{if(!h(u,"Multiply"))return;let l=u.ops.findIndex(d=>d.isSame(2));if(l<0)return;let f=u.ops.filter((d,p)=>p!==l);if(f.length!==1)return;let c=f[0];if(h(c,"Power")&&c.op1?.operator==="Cos"&&c.op2?.isSame(2)){let d=c.op1;if(h(d))return d.op1}},o=r(t);if(o&&(i.isSame(-1)||h(i,"Negate")&&i.op1?.isSame(1)))return n._fn("Cos",[o.mul(2)]);if(o=r(i),o&&(t.isSame(-1)||h(t,"Negate")&&t.op1?.isSame(1)))return n._fn("Cos",[o.mul(2)]);let s=u=>{if(!h(u,"Multiply"))return;let l=u.ops.findIndex(d=>d.isSame(2));if(l<0)return;let f=u.ops.filter((d,p)=>p!==l);if(f.length!==1)return;let c=f[0];if(h(c,"Power")&&c.op1?.operator==="Sin"&&c.op2?.isSame(2)){let d=c.op1;if(h(d))return d.op1}};if(t.isSame(1)&&h(i,"Negate")&&i.op1){let u=s(i.op1);if(u)return n._fn("Cos",[u.mul(2)])}if(i.isSame(1)&&h(t,"Negate")&&t.op1){let u=s(t.op1);if(u)return n._fn("Cos",[u.mul(2)])}let a=u=>{if(!h(u,"Multiply"))return;let l=u.ops.findIndex(d=>d.isSame(-2));if(l<0)return;let f=u.ops.filter((d,p)=>p!==l);if(f.length!==1)return;let c=f[0];if(h(c,"Power")&&c.op1?.operator==="Sin"&&c.op2?.isSame(2)){let d=c.op1;if(h(d))return d.op1}};if(t.isSame(1)){let u=a(i);if(u)return n._fn("Cos",[u.mul(2)])}if(i.isSame(1)){let u=a(t);if(u)return n._fn("Cos",[u.mul(2)])}}}function Axe(e){return gi(e,zGe)}function xxe(e){let n=!1,t=e;if(h(t,"Negate")&&t.op1)n=!0,t=t.op1;else if(h(t,"Multiply")&&t.ops.length===2){let s=t.ops.findIndex(a=>a.isSame(-1));s>=0&&(n=!0,t=t.ops[1-s])}if(!h(t,"Power"))return;let i=t.op1,r=t.op2;if(!i||!r||!(r.isSame(2)||r.isSame(4))||i.operator!=="Sin"&&i.operator!=="Cos"||!h(i))return;let o=i.op1;if(o)return{func:i.operator,arg:o,power:r.isSame(2)?2:4,negated:n}}function JGe(e){let n=e.engine;if(!h(e,"Add")||e.ops.length!==2)return;let t=xxe(e.ops[0]),i=xxe(e.ops[1]);if(!t||!i||t.negated===i.negated||t.func===i.func||t.power!==i.power||!t.arg.isSame(i.arg))return;let r=t.negated?i:t,o=n._fn("Cos",[r.arg.mul(2)]);return r.func==="Cos"?o:o.neg()}function Mxe(e){return gi(e,JGe)}function UGe(e){let n=e.engine;if(e.operator!=="Tan"||!h(e))return;let t=e.op1;if(t){if(h(t,"Add")&&t.ops.length===2){let[i,r]=t.ops,o=n._fn("Tan",[i]),s=n._fn("Tan",[r]);return o.add(s).div(n.One.sub(o.mul(s)))}if(h(t,"Subtract")){let i=t.op1,r=t.op2;if(!i||!r)return;let o=n._fn("Tan",[i]),s=n._fn("Tan",[r]);return o.sub(s).div(n.One.add(o.mul(s)))}}}function Pxe(e){return gi(e,UGe)}var GGe=[{value:0,angle:[0,1]},{value:1/Math.sqrt(3),angle:[1,6]},{value:1,angle:[1,4]},{value:Math.sqrt(3),angle:[1,3]},{value:2-Math.sqrt(3),angle:[1,12]},{value:2+Math.sqrt(3),angle:[5,12]}];function HGe(e,n=1e-10){for(let t of GGe)if(Math.abs(t.value-e)<n)return t.angle}function WGe(e){if(e.operator!=="Multiply"||!h(e))return;let n=e.ops;if(n.length<2)return;let t=[],i=1;for(let r of n)if(h(r,"Tan")&&r.op1)t.push(r.op1);else if(h(r,"Negate")&&r.op1?.operator==="Sqrt"){let o=r.op1;if(h(o)){let s=o.op1;if(N(s)&&typeof s.re=="number")i*=-Math.sqrt(s.re);else return}else return}else if(h(r,"Sqrt")){let o=r.op1;if(o&&N(o)&&typeof o.re=="number")i*=Math.sqrt(o.re);else return}else if(N(r)&&typeof r.re=="number")i*=r.re;else return;if(t.length===2)return[i,t[0],t[1]]}function vxe(e){if(h(e,"Multiply")){let n=!1,t;for(let i of e.ops)if(T(i,"Pi"))n=!0;else if(N(i)&&typeof i.re=="number"){let r=i.re;for(let o=1;o<=36;o++){let s=Math.round(r*o);if(Math.abs(s/o-r)<1e-10){t=[s,o];break}}}if(n&&t)return t}if(T(e,"Pi"))return[1,1]}function YGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(t.length!==3)return;let i=[],r;for(let E=0;E<t.length;E++){let x=t[E];if(h(x,"Tan")&&x.op1)i.push({arg:x.op1,index:E});else{let S=WGe(x);S&&(r={coef:S[0],arg1:S[1],arg2:S[2],index:E})}}if(i.length!==2||!r)return;let[o,s]=i,a=o.arg.isSame(r.arg1)||o.arg.isSame(r.arg2),u=s.arg.isSame(r.arg1)||s.arg.isSame(r.arg2),l=o.arg.isSame(r.arg2)||o.arg.isSame(r.arg1),f=s.arg.isSame(r.arg2)||s.arg.isSame(r.arg1);if(!(a&&f||u&&l))return;let c=-r.coef;if(c<=0)return;let d=HGe(c);if(!d)return;let p=vxe(o.arg),m=vxe(s.arg);if(!p||!m)return;let g=Sxe(Sxe(p[1],m[1]),d[1]);if(p[0]*(g/p[1])+m[0]*(g/m[1])+d[0]*(g/d[1])!==g)return;let b=n._fn("Multiply",[n.number([d[0],d[1]]),n.symbol("Pi")]);return n._fn("Tan",[b]).neg()}function Sxe(e,n){return Math.abs(e*n)/ZGe(e,n)}function ZGe(e,n){for(e=Math.abs(e),n=Math.abs(n);n;){let t=n;n=e%n,e=t}return e}function Oxe(e){return gi(e,YGe)}function KGe(e){let n=e.engine;if(e.operator!=="Multiply"||!h(e))return;let t=e.ops;if(!(t.length<2))for(let i=0;i<t.length;i++)for(let r=i+1;r<t.length;r++){let o=t[i],s=t[r];if(!h(o)||!h(s))continue;let a=o.op1,u=s.op1;if(!(!a||!u)){if(o.operator==="Tan"&&s.operator==="Tan"){let l=o,f=s,c=n._fn("Cot",[a.add(u)]),d=n.One.sub(l.add(f).mul(c)),p=t.filter((m,g)=>g!==i&&g!==r);return p.length===0?d:d.mul(p.length===1?p[0]:n._fn("Multiply",p))}if(o.operator==="Cot"&&s.operator==="Cot"){let l=o,f=s,c=n._fn("Cot",[a.add(u)]),d=n.One.add(l.add(f).mul(c)),p=t.filter((m,g)=>g!==i&&g!==r);return p.length===0?d:d.mul(p.length===1?p[0]:n._fn("Multiply",p))}}}}function Dxe(e){return gi(e,KGe)}function XGe(e){let n=e.engine;if(e.operator!=="Power"||!h(e))return;let t=e.op1,i=e.op2;if(!t||!i||!i.isSame(2)||!h(t))return;let r=t.op1;if(r){if(t.operator==="Tan")return n._fn("Sec",[r]).pow(2).sub(n.One);if(t.operator==="Cot")return n._fn("Csc",[r]).pow(2).sub(n.One);if(t.operator==="Sec")return n.One.add(n._fn("Tan",[r]).pow(2));if(t.operator==="Csc")return n.One.add(n._fn("Cot",[r]).pow(2))}}function $xe(e){return gi(e,XGe)}function QGe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(t.length!==2)return;let i=d=>{let p=!1,m=d;if(h(d,"Negate")&&(p=!0,m=d.op1),!h(m)||m.operator!=="Power"||!m.op2?.isSame(2))return null;let g=m.op1;if(!h(g)||!g.op1)return null;let y=g.operator;return["Tan","Cot","Sec","Csc"].includes(y)?{func:y,arg:g.op1,neg:p}:null},r=i(t[0]),o=i(t[1]);if(r&&o&&r.arg.isSame(o.arg)){if(r.func==="Cot"&&!r.neg&&o.func==="Csc"&&o.neg||r.func==="Csc"&&r.neg&&o.func==="Cot"&&!o.neg)return n.number(-1);if(r.func==="Csc"&&!r.neg&&o.func==="Cot"&&o.neg||r.func==="Cot"&&r.neg&&o.func==="Csc"&&!o.neg)return n.One;if(r.func==="Tan"&&!r.neg&&o.func==="Sec"&&o.neg||r.func==="Sec"&&r.neg&&o.func==="Tan"&&!o.neg)return n.number(-1);if(r.func==="Sec"&&!r.neg&&o.func==="Tan"&&o.neg||r.func==="Tan"&&r.neg&&o.func==="Sec"&&!o.neg)return n.One}let s=-1,a=-1,u=!1;for(let d=0;d<t.length;d++){let p=t[d];p.isSame(1)?(s=d,u=!1):p.isSame(-1)||h(p,"Negate")&&p.op1?.isSame(1)?(s=d,u=!0):h(p,"Power")&&p.op2?.isSame(2)&&(a=d)}if(s<0||a<0)return;let l=t[a];if(!h(l))return;let f=l.op1;if(!f||!h(f))return;let c=f.op1;if(c){if(f.operator==="Sec"&&u)return n._fn("Tan",[c]).pow(2);if(f.operator==="Csc"&&u)return n._fn("Cot",[c]).pow(2);if(f.operator==="Tan"&&!u)return n._fn("Sec",[c]).pow(2);if(f.operator==="Cot"&&!u)return n._fn("Csc",[c]).pow(2)}}function _z(e){return gi(e,QGe)}function eHe(e){let n=e.engine;if(!h(e,"Multiply"))return[1,n.One,e];for(let t=0;t<e.ops.length;t++){let i=e.ops[t],r;if(N(i)&&typeof i.re=="number"&&i.im===0&&(r=i.re),r!==void 0){let o=e.ops.filter((a,u)=>u!==t),s=o.length===1?o[0]:n._fn("Multiply",o);return[r,i,s]}}return[1,n.One,e]}function nHe(e){let n=e.engine;if(e.operator!=="Multiply"||!h(e))return;let t=e.ops;if(t.length<2)return;let i=[],r=[];for(let _ of t)if(h(_,"Cos")&&_.op1){let C=eHe(_.op1);C?i.push({arg:C[2],numericMult:C[0],symbolicCoeff:C[1]}):i.push({arg:_.op1,numericMult:1,symbolicCoeff:n.One})}else r.push(_);if(i.length<2)return;let o=i[0].arg,s=i.filter(_=>_.arg.isSame(o)),a=i.filter(_=>!_.arg.isSame(o));if(s.length<2)return;s.sort((_,C)=>_.numericMult-C.numericMult);let u=[],l=[],f=[...s],c=f[0].numericMult;if(c>0){u.push(f[0]);let _=new Set([0]),C=c*2;for(;;){let k=f.findIndex((M,j)=>!_.has(j)&&Math.abs(M.numericMult-C)<1e-10);if(k===-1)break;u.push(f[k]),_.add(k),C*=2}l=f.filter((k,M)=>!_.has(M))}if(u.length<2)return;let d=u[0].numericMult,p=[...r];for(let _ of l){let C=_.symbolicCoeff.isSame(n.One)?_.arg:n._fn("Multiply",[_.symbolicCoeff,_.arg]);p.push(n._fn("Cos",[C]))}for(let _ of a){let C=_.symbolicCoeff.isSame(n.One)?_.arg:n._fn("Multiply",[_.symbolicCoeff,_.arg]);p.push(n._fn("Cos",[C]))}let m=u.length,g=u[0].symbolicCoeff,y=Math.pow(2,m);if(T(o,"Pi")){let _=1/(y+1);if(Math.abs(d-_)<1e-10){let C=n.number([1,y]);return p.length===0?C:C.mul(p.length===1?p[0]:n._fn("Multiply",p))}}let b=g.mul(y),E=g.isSame(n.One)?o:n._fn("Multiply",[g,o]),x=n._fn("Multiply",[b,o]),S=n._fn("Sin",[x]),v=n._fn("Sin",[E]),w=S.div(n.number(y).mul(v));return p.length===0?w:w.mul(p.length===1?p[0]:n._fn("Multiply",p))}function Fxe(e){return gi(e,nHe)}function tHe(e){if(h(e,"Power")&&e.op2?.isSame(2)){let n=e.op1;if(h(n,"Sin")&&n.op1)return{func:"Sin",arg:n.op1,coef:1};if(h(n,"Cos")&&n.op1)return{func:"Cos",arg:n.op1,coef:1}}if(h(e,"Multiply")){let n=1,t;for(let i of e.ops)if(h(i,"Power")&&i.op2?.isSame(2)){let r=i.op1;(r?.operator==="Sin"||r?.operator==="Cos")&&(t=i)}else typeof i.re=="number"&&i.im===0&&(n*=i.re);if(h(t)){let i=t.op1;if(h(i,"Sin")&&i.op1)return{func:"Sin",arg:i.op1,coef:n};if(h(i,"Cos")&&i.op1)return{func:"Cos",arg:i.op1,coef:n}}}return null}function iHe(e){let n=e.engine;if(e.operator!=="Add"||!h(e))return;let t=e.ops;if(t.length<2)return;let i=[],r=[],o=[];for(let s=0;s<t.length;s++){let a=t[s],u=tHe(a);u?i.push({...u,index:s}):typeof a.re=="number"&&a.im===0&&N(a)?o.push({value:a.re,index:s}):r.push({expr:a,index:s})}for(let s=0;s<i.length;s++)for(let a=s+1;a<i.length;a++){let u=i[s],l=i[a];if(u.arg.isSame(l.arg)&&(u.func==="Sin"&&l.func==="Cos"||u.func==="Cos"&&l.func==="Sin")&&Math.abs(u.coef-l.coef)<1e-10){let f=u.coef,c=new Set([u.index,l.index]),d=t.filter((p,m)=>!c.has(m));return d.length===0?n.number(f):f===1?n._fn("Add",[n.One,...d]):n._fn("Add",[n.number(f),...d])}}for(let s of i)if(s.coef<0){let a=Math.abs(s.coef);for(let u of o)if(Math.abs(u.value-a)<1e-10){let l=new Set([s.index,u.index]),f=t.filter((p,m)=>!l.has(m)),c=s.func==="Sin"?"Cos":"Sin",d=n._fn(c,[s.arg]).pow(2).mul(a);return f.length===0?d:n._fn("Add",[d,...f])}}}function Lxe(e){return gi(e,iHe)}var rHe=new Set(["Sin","Cos","Tan","Cot","Sec","Csc"]);function Nz(e){let n=0;if(rHe.has(e.operator)&&(n=1),h(e))for(let t of e.ops)n+=Nz(t);return n}function Cz(e){if(T(e)||N(e))return 1;let n=1;if(h(e))for(let t of e.ops)n+=Cz(t);return n}function Bxe(e){let n=Nz(e),t=Cz(e);return n*1e3+t}var Vxe=Bxe;function kz(e,n){if(e.length===0)throw new Error("bestOf called with empty array");if(e.length===1)return e[0];let t=e[0],i=n(t);for(let r=1;r<e.length;r++){let o=n(e[r]);o<i&&(t=e[r],i=o)}return t}function d_(e,n){let t=n(e);return t.isSame(e)?null:t}function jxe(e,n){let t=d_(e,Sz),i=d_(e,Cxe),r=[e];return t&&r.push(t),i&&r.push(i),kz(r,n)}function oHe(e,n){return jxe(e,n)}function sHe(e,n){let t=d_(e,Ixe),i=[e];if(t){i.push(t);let r=d_(t,ZP);r&&i.push(r)}return kz(i,n)}function aHe(e,n){let t=d_(e,ZP),i=[e];return t&&i.push(t),kz(i,n)}function uHe(e,n){let t=Pxe(e);return t=Dxe(t),t}function lHe(e,n){let t=e;return t=Rxe(t),t=wz(t),t=Sz(t),t=kxe(t),t=wz(t),t=sHe(t,n),t=jxe(t,n),t=YP(t),t=oHe(t,n),t=YP(t),t=aHe(t,n),t}function qxe(e,n){if(!WP(e))return;let t=n?.measure??Vxe,i=n?.maxIterations??100,r=e,o=0,s=e,a=t(e),u=v=>{let w=t(v);w<a&&(s=v,a=w)};r=Nxe(r),u(r);let l=_z(r);u(l);let f=$xe(r);u(f),r=s;let c=Tz(r);if(u(c),r=s,Km(r,"Sec","Csc")&&(r=Txe(r),s=r,a=t(r)),Km(r,"Tan","Cot")){let v=uHe(r,t);u(v),r=v}if(Km(r,"Tan","Cot")&&(r=wxe(r),u(r)),Km(r,"Sin","Cos")){let v=YP(r);u(v),r=s}if(Km(r,"Sin","Cos")){let v=t(r);for(;o<i;){o++;let w=lHe(r,t),_=t(w);if(u(w),_>=v)break;r=w,v=_}}let d=_xe(s);u(d);let p=Axe(s);u(p);let m=Mxe(s);u(m);let g=Fxe(s);u(g);let y=Tz(s);u(y);let b=_z(s);u(b);let E=ZP(s);u(E);let x=Lxe(s);u(x);let S=Oxe(s);if(u(S),s.operator==="Add"||s.operator==="Multiply"){let v=e.engine.expr(s.json);u(v)}if(!s.isSame(e))return{value:s,because:"fu"}}function Iz(e,n){if(Array.isArray(e)){if(e[0]==="InvisibleOperator")for(let t=1;t+1<e.length;t++){let i=e[t],r=e[t+1];typeof i=="string"&&Array.isArray(r)&&r[0]==="Delimiter"&&n.add(i)}for(let t of e)Iz(t,n);return}e!==null&&typeof e=="object"&&"fn"in e&&Array.isArray(e.fn)&&Iz(e.fn,n)}var Xm=class e{static _latexSyntaxFactory=null;True;False;Pi;E;Nothing;Missing;Zero;One;Half;NegativeOne;Two;I;NaN;PositiveInfinity;NegativeInfinity;ComplexInfinity;_numericConfiguration;_cacheStore=new xM;_runtimeState=new VP;_boxingState=new jP;_configurationLifecycle=new LP;_cost;_integrationProvider;_simplificationRules=new fx([...Tme]);_solveRules=new fx([...poe]);_harmonizationRules=new fx([...yoe]);_compilationTargets=new $P;_fuAlgorithm=qxe;_customLibraryOperators=new Set;_commonSymbols={Pi:null,True:null,False:null,All:null,Nothing:null,Missing:null,None:null,Undefined:null,ExponentialE:null};_commonNumbers={"-5":null,"-4":null,"-3":null,"-2":null,2:null,3:null,4:null,5:null,6:null,7:null,8:null,9:null,10:null,11:null,12:null,36:null};_commonTypes=new Map;_evalContextStack=[];get context(){return this._evalContextStack[this._evalContextStack.length-1]}get contextStack(){return[...this._evalContextStack]}set contextStack(n){this._evalContextStack=[...n]}_typeRegistry=Object.create(null);_protocolRegistry=Object.create(null);_conformanceVersionCounter=0;get _conformanceVersion(){return this._conformanceVersionCounter}_noteConformanceRegistryChange(){this._conformanceVersionCounter+=1}_staticTypeCheckDepth=0;_epsilBatchId=void 0;_staticAssignmentEvidence=void 0;_epsilDeclarationRoute=!1;_typeRegistryRollbackPoint(){let n=this._typeRegistry,t=new Set(Object.keys(n)),i=[...t].map(r=>{let o=n[r];return{r:o,def:o.def,alias:o.alias,typeParams:o.typeParams,varianceState:o._varianceState,varianceBlockedOn:o._varianceBlockedOn,declaredByStatement:o._declaredByStatement,forwardArity:o._forwardArity===void 0?void 0:new Set(o._forwardArity),sumOf:o._sumOf,sumVariants:o._sumVariants,declOrigin:o._declOrigin}});return()=>{let r=!1;for(let o of Object.keys(n))t.has(o)||(delete n[o],r=!0);for(let o of i){let s=o.r;s.def!==o.def&&(r=!0),s.def=o.def,s.alias!==o.alias&&(r=!0),s.alias=o.alias,s.typeParams!==o.typeParams&&(r=!0),o.typeParams===void 0?delete s.typeParams:s.typeParams=o.typeParams,s._varianceState!==o.varianceState&&(r=!0),o.varianceState===void 0?delete s._varianceState:s._varianceState=o.varianceState,s._varianceBlockedOn!==o.varianceBlockedOn&&(r=!0),o.varianceBlockedOn===void 0?delete s._varianceBlockedOn:s._varianceBlockedOn=o.varianceBlockedOn;let a=s;a._declaredByStatement!==o.declaredByStatement&&(r=!0),o.declaredByStatement===void 0?delete a._declaredByStatement:a._declaredByStatement=o.declaredByStatement;let u=s,l=u._forwardArity,f=o.forwardArity;(l===void 0!=(f===void 0)||l!==void 0&&f!==void 0&&(l.size!==f.size||[...f].some(c=>!l.has(c))))&&(r=!0),f===void 0?delete u._forwardArity:u._forwardArity=f,s._sumOf!==o.sumOf&&(r=!0),o.sumOf===void 0?delete s._sumOf:s._sumOf=o.sumOf,s._sumVariants!==o.sumVariants&&(r=!0),o.sumVariants===void 0?delete s._sumVariants:s._sumVariants=o.sumVariants,o.declOrigin===void 0?delete s._declOrigin:s._declOrigin=o.declOrigin,s.name in n||(n[s.name]=s,r=!0)}r&&this._noteStateEvent({kind:"config"})}}_protocolRegistryRollbackPoint(){let n=this._protocolRegistry,t=new Set(Object.keys(n)),i=[...t].map(r=>{let o=n[r];return{r:o,members:o.members,conformances:[...o.conformances],edges:o.conformances.map(s=>({c:s,impl:s.impl,authored:s._authored,origin:s._implOrigin,pending:s.pending,pendingReason:s._pendingReason})),declaredByStatement:o.declaredByStatement,declOrigin:o._declOrigin}});return()=>{let r=!1;for(let o of Object.keys(n))t.has(o)||(delete n[o],r=!0);for(let o of i){let s=o.r;s.members!==o.members&&(r=!0),s.members=o.members,s.declaredByStatement!==o.declaredByStatement&&(r=!0),s.declaredByStatement=o.declaredByStatement,o.declOrigin===void 0?delete s._declOrigin:s._declOrigin=o.declOrigin,(s.conformances.length!==o.conformances.length||o.conformances.some((a,u)=>s.conformances[u]!==a))&&(r=!0),s.conformances=o.conformances;for(let a of o.edges)a.c.impl!==a.impl&&(r=!0),a.impl===void 0?delete a.c.impl:a.c.impl=a.impl,a.authored===void 0?delete a.c._authored:a.c._authored=a.authored,a.origin===void 0?delete a.c._implOrigin:a.c._implOrigin=a.origin,a.c.pending!==a.pending&&(r=!0),a.c.pending=a.pending,a.pendingReason===void 0?delete a.c._pendingReason:a.c._pendingReason=a.pendingReason;s.name in n||(n[s.name]=s,r=!0)}r&&(this._noteStateEvent({kind:"config"}),this._noteConformanceRegistryChange())}}_rollbackFrames=[];_withRolledBackInference(n,t){this._inferenceTxDepth>0;let i=new pN({boxingRepairDepthAtOpen:this._boxingState.frameDepth(),forbidsRepairs:t?.forbidsRepairs});this._rollbackFrames.push(i);let r;try{return n()}catch(o){throw r={error:o},o}finally{let o=this._rollbackFrames.pop(),s=i.rollback();if(this._boxingState.hasRepairRequestedAtOrAbove(i.boxingRepairDepthAtOpen),s!==void 0&&this._debugBindings)throw new Error("Inference rollback failed: an undo entry threw while unwinding the frame",{cause:r?.error??s.error})}}_withBoxingPassWindow(n){dM(this);try{return n()}finally{pM(this)}}declareProtocol(n,t){Rk(this,n,t)}declareProtocolImplementation(n,t,i,r){EX(this,n,t,i,r)}__typeResolver;get _typeResolver(){return this.__typeResolver??=mxe(this),this.__typeResolver}declareType(n,t,i){dE(this,n,t,i)}get trace(){return this._evalContextStack.map(n=>n.name).filter(n=>n!==void 0).reverse()}get _anyVersion(){return this._configurationLifecycle.anyVersion}get _semanticVersion(){return this._configurationLifecycle.semanticVersion}get _worldVersion(){return this._configurationLifecycle.worldVersion}get _callableVersion(){return this._configurationLifecycle.callableVersion}get _ephemeralWriteDepth(){return this._configurationLifecycle.ephemeralWriteDepth}set _ephemeralWriteDepth(n){this._configurationLifecycle.ephemeralWriteDepth=n}get _factSuppressionDepth(){return this._configurationLifecycle.factSuppressionDepth}set _factSuppressionDepth(n){this._configurationLifecycle.factSuppressionDepth=n}_withoutFacts(n){if(n.constructor.name==="AsyncFunction")throw new Error("A fact-blind bracket must be synchronous: an async thunk is refused before it runs, because everything after its first await would see the assumptions again");let t=this._configurationLifecycle;t.factSuppressionDepth+=1;let i;try{i=n()}finally{t.factSuppressionDepth-=1}if(typeof i?.then=="function")throw Promise.resolve(i).then(void 0,()=>{}),new Error("A fact-blind bracket must be synchronous: its thunk returned a promise, whose work would run after the bracket closed and would see the assumptions again");return i}_factsHidden(){if(this._factSuppressionDepth===0)return!1;let n=this.context;return n===void 0?!1:(n.assumptions?.size??0)!==0||(n.assumedValues?.size??0)!==0}_cacheGeneration(){return this._anyVersion*2+(this._factsHidden()?1:0)}_nextFactId(){return this._factIdCounter+=1,this._factIdCounter}_factIdCounter=0;get _scratchDeclarationScopes(){return this._configurationLifecycle.scratchDeclarationScopes}_checkpointWindow=void 0;_checkpointStack=[];_checkpointPoisoned=!1;_nextCheckpointId=1;_invalidateCheckpointsOnFrameDiscard(n){HX(this,n)}_inFlightAsyncEvaluations=0;_evaluationDepth=0;_objectStoreEpoch=0;_applicationMemo=void 0;checkpoint(n){return UX(this,n)}restore(n){GX(this,n)}discard(n){WX(this,n)}_noteStateEvent(n){SD&&this._checkpointWindow?.noteEvent(n.kind),this._configurationLifecycle.noteStateEvent(n)}_inferenceTxDepth=0;_hasAsyncOnlyOperator=!1;_boxingEpoch=0;_debugBindings=KU();_freshlyInferred=null;_inferenceCause=null;_noteInferenceWrite(n){let t=this._inferenceCause;if(t&&t.expr===void 0&&(t.expr=this._fn(t.operator,t.ops.map(i=>this.expr(i,{form:"raw"})),{canonical:!1})),ja(this,n.target,{type:n.to,kind:n.kind,axis:"type",cause:t?.expr,epoch:qa(this)}),n.valueDef!==void 0&&n.from.isUnknown&&this._inferenceTxDepth>0){let i=this._freshlyInferred??=new Set,r=gt(this);if(r!==void 0&&!i.has(n.valueDef)){let o=n.valueDef;r.record({undo:()=>i.delete(o)})}i.add(n.valueDef)}this._narrowingSink?._recordNarrowing(n.name,n.binding,n.from,n.to)}strict;get jit(){return this._jit}set jit(n){n!==this._jit&&(this._jit=n,this._noteStateEvent({kind:"config"}))}_jit="auto";static getStandardLibrary(n){return oM(n)}constructor(n){if(n!==void 0&&typeof n!="object")throw Error("Unexpected argument");this.strict=!0,this.jit="auto",this._numericConfiguration=new BP({precision:n?.precision,tolerance:n?.tolerance??"auto",angularUnit:"rad"});let t=new qP(this),i=t.initializeCommonNumbers();this.Zero=i.Zero,this.One=i.One,this.Half=i.Half,this.NegativeOne=i.NegativeOne,this.Two=i.Two,this.NaN=i.NaN,this.PositiveInfinity=i.PositiveInfinity,this.NegativeInfinity=i.NegativeInfinity,this.I=i.I,this.ComplexInfinity=i.ComplexInfinity,this._reset(),this.pushScope(void 0,"system"),this.declareType("limits","expression<Limits>"),this.declareType("distribution","expression<NormalDistribution> | expression<BinomialDistribution> | expression<PoissonDistribution> | expression<UniformDistribution> | expression<ExponentialDistribution>",{alias:!0}),t.bootstrapLibraries(n?.libraries);let r=t.initializeCommonSymbolBindings(this._commonSymbols);this.True=r.True,this.False=r.False,this.Pi=r.Pi,this.E=r.E,this.Nothing=r.Nothing,this.Missing=r.Missing,this.pushScope(void 0,"global"),this._compilationTargets.registerDefaults(),n?.latexSyntax&&(this._latexSyntax=n.latexSyntax),n?.latexOptions&&(dN(n.latexOptions),this._latexOptions={...n.latexOptions}),FU(this)}toJSON(){return"[ComputeEngine]"}[Symbol.toStringTag]="ComputeEngine";_reset(){this._configurationLifecycle.reset({refreshNumericConstants:()=>{},resetCommonSymbols:()=>mhe(this._commonSymbols),purgeCaches:()=>this._cacheStore.purgeValues()})}_listenToConfigurationChange(n){return this._configurationLifecycle.listen(n)}_compile(n,t){return JP(n,t)}_getCompilationTarget(n){return this._compilationTargets.get(n)}_listCompilationTargets(){return this._compilationTargets.list()}_registerCompilationTarget(n,t){this._compilationTargets.register(n,t)}_unregisterCompilationTarget(n){this._compilationTargets.unregister(n)}get precision(){return this._numericConfiguration.precision}set precision(n){this._numericConfiguration.setPrecision(n)&&this._reset()}get angularUnit(){return this._numericConfiguration.angularUnit}set angularUnit(n){this._numericConfiguration.setAngularUnit(n)&&this._reset()}withTimeLimit(n,t){let i=typeof n=="number"?n:n.ms,r=typeof n=="number"?void 0:n.label,o=this._runtimeState.deadlineFrame,s=Date.now()+i,a=[...o?.spans??[],...r!==void 0?[r]:[]],u=o!==void 0&&o.at<=s?{at:o.at,owner:o.owner,spans:a}:{at:s,owner:r,spans:a};this._runtimeState.deadlineFrame=u;try{return t()}finally{this._runtimeState.deadlineFrame=o}}get _deadline(){return this._runtimeState.deadline}set _deadline(n){this._runtimeState.deadline=n}get _deadlineFrame(){return this._runtimeState.deadlineFrame}set _deadlineFrame(n){this._runtimeState.deadlineFrame=n}get _timeRemaining(){return this._runtimeState.timeRemaining}get _mapAutoCompileStats(){return Wo}get iterationLimit(){return this._runtimeState.iterationLimit}set iterationLimit(n){n!==this._runtimeState.iterationLimit&&(this._runtimeState.iterationLimit=n,this._noteStateEvent({kind:"config"}))}get recursionLimit(){return this._runtimeState.recursionLimit}set recursionLimit(n){this._runtimeState.recursionLimit=n}_enterRecursion(){this._runtimeState.enterRecursion()}_exitRecursion(){this._runtimeState.exitRecursion()}get maxCollectionSize(){return this._runtimeState.maxCollectionSize}set maxCollectionSize(n){this._runtimeState.maxCollectionSize=n}get _isVerifying(){return this._runtimeState.isVerifying}set _isVerifying(n){this._runtimeState.isVerifying=n}get isVerifying(){return this._runtimeState.isVerifying}get tolerance(){return this._numericConfiguration.tolerance}set tolerance(n){this._numericConfiguration.setTolerance(n)&&this._noteStateEvent({kind:"config"})}get _randomFrame(){return this._runtimeState.randomFrame}set _randomFrame(n){this._runtimeState.randomFrame=n}_random(){let n=this._runtimeState.randomFrame;if(n!==void 0){let t=n.next>>>0;return n.next=n.next+1>>>0,TD(n.seedLo,n.seedHi,t)}return Math.random()}_substream(n){return rG(this._runtimeState.randomFrame,n)}chop(n){let t=this._numericConfiguration.tolerance;return typeof n=="number"?Math.abs(n)<=t?0:n:n instanceof I?n.isPositive()&&n.lte(this._numericConfiguration.bignumTolerance)||n.isNegative()&&n.gte(this._numericConfiguration.negBignumTolerance)||n.isZero()?0:n:n instanceof te&&Math.abs(n.re)<=t&&Math.abs(n.im)<=t?0:n}bignum(n){return this._numericConfiguration.bignum(n)}complex(n,t){return n instanceof I&&(n=n.toNumber()),t instanceof I&&(t=t.toNumber()),new te(n,t)}_numericValue(n){if(n instanceof Qn)return n.asExact??n;let t=this._numericConfiguration.precision>Mu?i=>new mg(i):i=>new cd(i);if(typeof n=="number")return Number.isInteger(n)?new je(n,t):t(n);if(typeof n=="bigint")return new je(n,t);if(Ul(n))return new je({rational:n},t);if(n instanceof I){if(n.isInteger()){let i=Vt(n.toString());if(i!==null)return new je(i,t)}return t(n)}if(n instanceof te)return n.im===0?this._numericValue(n.re):t({re:n.re,im:n.im});if("im"in n||"re"in n)return n.im!==void 0&&n.im!==0?t(n):n.re instanceof I&&n.re.isInteger()?new je({rational:[Vt(n.re.toString()),BigInt(1)]},t):typeof n.re=="number"&&Number.isInteger(n.re)?new je({rational:[n.re,1]},t):t(n);if("radical"in n||"rational"in n){let i=n;if(i.radical!==void 0&&i.radical!==1){if(!Number.isInteger(i.radical)||i.radical<1)return t({re:tb(i.rational??[1,1])*Math.sqrt(i.radical)});if(i.radical>=Je){let[r,o]=Va(i.radical,2);if(o>=Je)return t({re:tb(i.rational??[1,1])*Math.sqrt(i.radical)});i={...i,radical:o,rational:it(i.rational??[1,1],[r,1])}}}return i.rational&&br(i.rational)&&(!Number.isInteger(i.rational[0])||!Number.isInteger(i.rational[1]))?t(i):new je(i,t)}throw Error(`Unexpected value: ${typeof n=="object"?JSON.stringify(n):String(n)}`)}get costFunction(){return this._cost??gpe}set costFunction(n){this._cost=typeof n=="function"?n:void 0}get simplificationRules(){return this._simplificationRules.rules}set simplificationRules(n){this._simplificationRules.rules=n,this._cacheStore.invalidate("standard-simplification-rules")}get solveRules(){return this._solveRules.rules}set solveRules(n){this._solveRules.rules=n,this._cacheStore.invalidate("univariate-roots-rules")}get harmonizationRules(){return this._harmonizationRules.rules}set harmonizationRules(n){this._harmonizationRules.rules=n,this._cacheStore.invalidate("harmonization-rules")}lookupDefinition(n){return Ffe(this,n)}normalizeIdentifier(n){if(!n)return"";if(Qt(n))return n;this.pushScope();try{let t=this.parse(n);if(T(t))return t.symbol}finally{this.popScope()}return""}operatorInfo(n){let t=this.lookupDefinition(n);if(!t||!pe(t))return;let i=t.operator,r=!!(i.evaluate||i.collection);return{kind:r?"function":"opaque",signature:i.signature,canEvaluate:r}}symbolInfo(n){let t=this.lookupDefinition(n);if(!t||!le(t))return;let i=t.value;return{kind:i.isConstant?"constant":"variable",type:i.type}}searchDefinitions(n,t){return Lfe(this,n,t)}suggestOperatorName(n){return Bfe(this,n)}functionProperties(n){return Jg(this,n)}_declareSymbolValue(n,t,i){return jfe(this,n,t,i)}_declareSymbolOperator(n,t,i){return qfe(this,n,t,i)}pushScope(n,t){Cme(this,n,t)}popScope(){kme(this)}createScope(n,t){return Pme(this,n,t)}_narrowingSink=void 0;_pushEvalContext(n,t,i){mj(this,n,t,i)}_popEvalContext(){hj(this)}_removeEvalContext(n){Ime(this,n)}_inScope(n,t){return Ame(this,n,t)}_resolveOnlyDepth=0;_resolveOnly(n){this._resolveOnlyDepth+=1;try{return n()}finally{this._resolveOnlyDepth-=1}}_printStack(n){Mme(this,n)}_bindingSymbol(n,t){return fxe(this,n,t)}_shadowedParameterStack=[];_pushShadowedParameters(n,t){this._shadowedParameterStack.push({names:new Set(n),types:t,defs:new Map,boundary:this.context.lexicalScope})}_popShadowedParameters(){this._shadowedParameterStack.pop()}_isShadowedParameter(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return!0;return!1}_shadowedParameterType(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return t[i].types?.get(n)}_shadowedParameterBoundary(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return t[i].boundary}_shadowedParameterDef(n){let t=this._shadowedParameterStack;for(let i=t.length-1;i>=0;i--)if(t[i].names.has(n))return t[i].defs.get(n)}_setShadowedParameterDef(n,t){let i=this._shadowedParameterStack;for(let r=i.length-1;r>=0;r--)if(i[r].names.has(n)){i[r].defs.set(n,t);return}}_currentShadowedParameterDefs(){let n=this._shadowedParameterStack;return n.length>0?n[n.length-1].defs:new Map}_getSymbolValue(n){return zfe(this,n)}_setSymbolValue(n,t){Jfe(this,n,t)}declare(n,t,i){return Hfe(this,n,t,i)}declareSequence(n,t){return nhe(this,n,t)}getSequenceStatus(n){return the(this,n)}getSequence(n){return ihe(this,n)}listSequences(){return rhe(this)}isSequence(n){return ohe(this,n)}clearSequenceCache(n){she(this,n)}getSequenceCache(n){return ahe(this,n)}getSequenceTerms(n,t,i,r){return uhe(this,n,t,i,r)}lookupOEIS(n,t){return lhe(this,n,t)}checkSequenceOEIS(n,t,i){return fhe(this,n,t,i)}interpret(n,t){return che(this,n,t)}assign(n,t){return Wfe(this,n,t)}_shouldContinueExecution(){return this._runtimeState.shouldContinueExecution()}_checkContinueExecution(){if(!this._shouldContinueExecution())throw new Error("timeout")}_cache(n,t,i){return this._cacheStore.getOrBuild(n,()=>{let r=this._runtimeState.deadlineFrame;if(r===void 0)return t();this._runtimeState.deadlineFrame=void 0;try{return t()}finally{this._runtimeState.deadlineFrame=r}},i)}expr(n,t){let{canonical:i,structural:r}=bw(t);return gM(this,t?.scope,()=>Gi(this,n,{canonical:i,structural:r,scope:t?.scope}))}box(n,t){return this.expr(n,t)}rebind(n,t){return gM(this,t?.scope,()=>qpe(this,n,t))}_latexSyntax;get latexSyntax(){return!this._latexSyntax&&e._latexSyntaxFactory&&(this._latexSyntax=e._latexSyntaxFactory()),this._latexSyntax}_requireLatexSyntax(){if(!this._latexSyntax&&e._latexSyntaxFactory&&(this._latexSyntax=e._latexSyntaxFactory()),!this._latexSyntax)throw new Error("LatexSyntax not available. Pass a LatexSyntax instance to the ComputeEngine constructor.");return this._latexSyntax}_latexOptions={};get latexOptions(){return this._latexOptions}set latexOptions(n){dN(n),this._latexOptions={...n}}parse(n,t){if(n==null)return null;if(typeof n!="string")throw Error("ce.parse(): expected a LaTeX string");if(t?.speculative){if(t.scope!==void 0)throw Error("ce.parse(): the `speculative` and `scope` options are mutually exclusive \u2014 `speculative` discards the parse's writes, `scope` harvests them");let{speculative:b,...E}=t,x=this.parse(n,{...E,form:"raw"});this.pushScope(void 0,"speculative-parse");try{let S=this.context.lexicalScope;if(x!==null)for(let v of new Set(x.symbols)){let w=this.lookupDefinition(v);w!==void 0&&"value"in w&&!w.value.isConstant&&(w.value.inferredType||w.value.type.isUnknown)&&this.declare(v,{inferred:!0,type:w.value.type.type,...w.value.subscriptEvaluate?{subscriptEvaluate:w.value.subscriptEvaluate}:{}},S)}return this.parse(n,E)}finally{this.popScope()}}if(t?.scope)return gM(this,t.scope,()=>this.parse(n,{...t,scope:void 0}));let i=this._requireLatexSyntax(),{form:r,canonical:o,structural:s,scope:a,speculative:u,...l}=t??{},f=l.diagnostics??this._latexOptions?.diagnostics??!1,c,d,p,m=new Set;if(f){c=[],p=E=>m.add(E);let b=new Set;d=E=>{let x=`${E.code} ${E.start} ${E.end} ${E.detail?JSON.stringify(E.detail):""}`;b.has(x)||(b.add(x),c.push(E))}}let g=l.resolveSymbol??this._latexOptions?.resolveSymbol,y=g?b=>g(b)??this._resolveSymbolFromScope(b):b=>this._resolveSymbolFromScope(b);dM(this);try{let b=i.parse(n,{tolerance:this.tolerance,...this._latexOptions,...l,resolveSymbol:y,diagnostics:f,onDiagnostic:d,onBoundVariable:p});if(b===null)return null;let E=Gi(this,b,bw({form:r,canonical:o,structural:s}));if(c!==void 0){if(E=E._unshared(),E.isCanonical)try{let x=new Set(E.symbols),S=new Set(E.freeVariables);for(let v of c){if(v.code!=="undeclared-symbol")continue;let w=v.detail?.name;typeof w=="string"&&(m.has(w)||x.has(w)&&!S.has(w)&&`${w}`)}}catch{}for(let x of c)x.detail&&Object.freeze(x.detail),Object.freeze(x);E.parseDiagnostics=Object.freeze(c)}return E}finally{pM(this)}}_resolveSymbolFromScope(n){let t=this.lookupDefinition(n);if(t)return pe(t)?{type:t.operator.signature}:le(t)?{type:t.value.type,subscriptEvaluate:!!t.value.subscriptEvaluate}:{type:O.unknown}}appliedNonFunctions(n){let t=this.latexSyntax;if(!t)return[];let i=this._latexOptions?.resolveSymbol,r=t.parse(n,{...this._latexOptions,resolveSymbol:i?s=>i(s)??this._resolveSymbolFromScope(s):s=>this._resolveSymbolFromScope(s)}),o=new Set;return r!==null&&Iz(r,o),Array.from(o).sort()}function(n,t,i){let{canonical:r,structural:o}=bw(i);return gw(this,n,t,{metadata:i?.metadata,canonical:r,structural:o,scope:i?.scope})}error(n,t){return zP(this,n,t)}typeError(n,t,i){return yxe(this,n,t,i)}hold(n){return this._fn("Hold",[this.expr(n,{form:"raw"})])}tuple(...n){return new Jn(this,"Tuple",n.map(t=>typeof t=="number"?this.number(t):t.canonical).filter(t=>!T(t,"Nothing")),{canonical:!0})}list(n){let t=n.length;if(typeof t!="number"||!Number.isSafeInteger(t)||t<0)throw new TypeError(`list(): the length must be a non-negative safe integer, not ${String(t)}`);if(t===0)return this.function("List",[]);let i=new Array(t);for(let r=0;r<t;r++){let o=n[r];if(typeof o!="number")throw new TypeError(`list(): element ${r} is ${o===void 0?"undefined":typeof o}, not a number`);i[r]=o===0?0:o}return new Jn(this,"List",void 0,{canonical:!0,numericStore:Object.freeze(i)})}type(n){if(n instanceof O)return n;if(typeof n=="string"&&Ll(n)){let t=this._commonTypes.get(n);return t===void 0&&(t=new O(n,this._typeResolver),this._commonTypes.set(n,t)),t}return new O(n,this._typeResolver)}string(n,t){return new Pp(this,n,t)}character(n,t){if(!Op(n))throw new Error(`ce.character(): "${n}" is not exactly one grapheme cluster. A character is exactly one user-perceived character (one UAX #29 extended grapheme cluster); use ce.string() for arbitrary text, or CharacterFrom() to get a diagnostic instead of a throw.`);return new gk(this,n,t)}symbol(n,t){return lxe(this,this._commonSymbols,n,t)}number(n,t){return cxe(this,this._commonNumbers,n,t)}rules(n,t){return uT(this,n,t)}getRuleSet(n){if(n??="standard-simplification",n==="standard-simplification"){this._simplificationRules.hasMutatedSinceLastCache()&&this._cacheStore.invalidate("standard-simplification-rules");let t=this._cache("standard-simplification-rules",()=>{let r=uT(this,this._simplificationRules.rules,{canonical:!0}).rules.filter(o=>o.purpose!=="expand");return{rules:zre(r)}});return this._simplificationRules.markCached(),t}if(n==="solve-univariate"){this._solveRules.hasMutatedSinceLastCache()&&this._cacheStore.invalidate("univariate-roots-rules");let t=this._cache("univariate-roots-rules",()=>uT(this,this._solveRules.rules));return this._solveRules.markCached(),t}if(n==="harmonization"){this._harmonizationRules.hasMutatedSinceLastCache()&&this._cacheStore.invalidate("harmonization-rules");let t=this._cache("harmonization-rules",()=>uT(this,this._harmonizationRules.rules));return this._harmonizationRules.markCached(),t}}_fn(n,t,i){let r=i?.canonical??!0;return lp(t,this)?this.error("object-foreign-engine"):new Jn(this,n,t,{...i,canonical:r})}_object(n,t,i,r){return Ype(this,n,t,i,r)}ask(n){return vj(this,n)}verify(n){return Sj(this,n)}assume(n){return Kme(this,n)}forget(n){Tj(this,n)}};GP(()=>new Xm);var zxe=Xm;Xm._latexSyntaxFactory=()=>new Rp;GP(()=>new Xm({latexSyntax:new Rp}));globalThis[Symbol.for("io.cortexjs.compute-engine")]={ComputeEngine:Xm,version:"0.129.1",LatexSyntax:Rp,LATEX_DICTIONARY:tg,isExpression:$u,isNumber:N,isSymbol:T,isFunction:h,isString:J,isCharacter:sn,isTensor:Fu,isDictionary:Ve,isObject:yn,isCollection:kD,isIndexedCollection:ID,numericValue:at,sym:F,compile:HP};function Rz(e){return e.fg===void 0&&e.bg===void 0&&(e.weight===void 0||e.weight==="normal")&&(e.italic===void 0||e.italic===!1)}var KP=class{width;indent;constructor(n){this.width=n?.width,this.indent=n?.indent??0}renderBlock(n){let t="spans"in n?this.renderSpans(n.spans):n.blocks.map(i=>this.renderBlock(i)).join(`
1878
1878
  `);return n.tag==="paragraph"?`
1879
1879
  ${p_(t,this.width).join(`
1880
1880
  `)}
@@ -1896,7 +1896,7 @@ ${p_(t,this.width).join(`
1896
1896
  `:t?n+`
1897
1897
  `+t:n+`
1898
1898
  `}countLinebreaks(n){return n.split(/\r\n|\r|\n/).length}normalizedBlocks(n){return n.map(t=>typeof t=="string"?new $l(this,t):t).filter(t=>!(t instanceof Dy))}infixOperator(n){return new $l(this,this.options.aroundInfixOperator+n+this.options.aroundInfixOperator)}relationalOperator(n){return new $l(this,this.options.aroundRelationalOperator+n+this.options.aroundRelationalOperator)}separator(n){return new $l(this,n+this.options.afterSeparator)}fence(n){return new $l(this,n)}text(n){return!n||n.length===0?new Dy(this):new $l(this,n)}line(...n){let t=this.normalizedBlocks(n),i=[],r="";for(let o of t)o instanceof $l?r?(i.pop(),r=r+o.s,i.push(new $l(this,r))):(i.push(o),r=o.s):(r="",i.push(o));return i.length===1?i[0]:new xx(this,...i)}stack(...n){let t=this.normalizedBlocks(n);return t.length===1?t[0]:new fO(this,...t)}wrap(...n){let t=this.normalizedBlocks(n);return t.length===1?t[0]:new Zz(this,...t)}indent(n,t=1){return new xx(this,new $l(this,this.indentChars(t)),n)}choice(...n){let t=this.normalizedBlocks(n);return t.length===1?t[0]:new Kz(this,...t)}fencedBlock(n,t,i){return t?this.fencedList(n,"",i,[t]):this.line(this.fence(n),this.fence(i))}fencedList(n,t,i,r){let o=this.fence(n),s=this.fence(i);if(r.length===0)return this.line(o,s);if(r.length===1)return this.line(o,r[0],s);let a=r.map(l=>this.line(l,t)),u=[...a];return u.pop(),u.push(r[r.length-1]),!n&&!i?this.choice(this.line(...u),this.wrap(...u)):this.choice(this.line(o,...u,s),this.stack(o,this.indent(this.stack(...a)),s))}list(n,t){return this.fencedList("",n,"",t)}};var vx={positiveInfinity:"Infinity",negativeInfinity:"-Infinity",notANumber:"NaN",imaginaryUnit:"i",decimalSeparator:".",digitGroupSeparator:"_",digitGroup:3,exponentProduct:"",beginExponentMarker:"e",endExponentMarker:"",truncationMarker:"",repeatingDecimal:"none",fractionalDigits:"max",notation:"auto",avoidExponentsInRange:[-7,20]},Xz={get names(){return[]},forward:()=>{},resolve:e=>({kind:"reference",name:e,alias:!1,def:void 0}),conformsTo:()=>!0},hWe=new Map([...h_].filter(([,e])=>/^[0-9-]$/.test(e)).map(([e,n])=>[n,String.fromCodePoint(e)]));function dO(e,n){let t=new cO({...n?.fancySymbols?{aroundInfixOperator:"\u205F",aroundRelationalOperator:"\u2005",afterSeparator:"\u2009"}:{},...n});function i(B){if(B===null)return new Dy(t);if(typeof B=="string"&&sb(B)){let oe=fe(B);if(oe!==null)return s(oe)}if(typeof B=="object"&&B!==null&&"str"in B)return s(B.str);let W=a(B),Q;if(L(B)&&(Q=X(B)??yi(B)??ee(B)),!Q){let oe=Z(B);oe!==null&&(Q=t.text(Ri(oe)))}if(!Q&&(typeof B=="number"||Ua(B)||typeof B=="string"&&na(B))){let oe=rd(B,vx);oe&&(Q=t.text(oe))}if(!Q){let oe=mv(B);if(oe!==null){let se=oe.dict,he=Object.keys(se).map(Ce=>t.line(s(Ce),t.relationalOperator("->"),i(Tve(se[Ce]))));if(he.length===0)return t.line(t.fence("{"),t.relationalOperator("->"),t.fence("}"));Q=t.fencedList("{",t.separator(","),"}",he)}}return Q?W instanceof Dy?Q:t.choice(t.line(W,Q),t.stack(W,Q)):t.text()}let r=0;function o(B,W){let Q=r;r=B;try{return W()}finally{r=Q}}function s(B){return t.text(`"${v_(B)}"`)}function a(B){return typeof B!="object"?t.text():"comment"in B&&B.comment&&B.comment.length>0?t.text(`/* ${B.comment} */`):t.text()}let u={};for(let B of bx)B.name in u||B.name!=="Range"&&(u[B.name]={symbol:B.symbol,fancySymbol:B.fancySymbol,precedence:B.precedence,assoc:B.assoc??"left",unary:B.kind==="prefix",postfix:B.kind==="postfix",relational:B.relational});u.Divide&&!u.Rational&&(u.Rational={...u.Divide}),u.If={symbol:"if",precedence:wu,assoc:"left"};let l=B=>B!==null&&(typeof B=="number"||Ua(B)||typeof B=="string"&&na(B)),f=B=>{if(!l(B))return!1;let W=Se(B);return W!==null&&W<0},c=bx.find(B=>B.name==="Negate").precedence,d=new Set(["Add","Multiply","And","Or"]);function p(B,W,Q,ie){if(B===null)return!1;let oe=L(B),se=u[oe];return se?se.precedence<W.precedence?!0:se.precedence===W.precedence?oe===Q&&d.has(Q)?!1:ie!==W.assoc:!1:ie==="left"&&W.precedence>c&&f(B)}function m(B,W){if(B===null)return!1;if(Z(B)!==null)return!0;if(l(B)){let ie=Se(B);return ie!==null&&!Number.isNaN(ie)&&ie>=0}let Q=L(B);return Q?W==="radicand"&&(b(B)!==null||Q==="Power"&&y(B)!==null)?!0:!(Q in u)&&!(Q in x):!1}function g(B){if(B===null)return null;if(typeof B=="number")return Number.isSafeInteger(B)?B:null;let W=Ua(B)?B.num:typeof B=="string"?B:null;if(W===null||!/^[+-]?\d+$/.test(W))return null;let Q=Number(W);return Number.isSafeInteger(Q)?Q:null}function y(B){if(!n?.fancySymbols||Te(B)!==2)return null;let W=g(P(B,2));return W===null?null:[...String(W)].map(Q=>hWe.get(Q)??Q).join("")}function b(B){if(!n?.fancySymbols||B===null)return null;let W=L(B);if(W==="Sqrt"&&Te(B)===1)return"\u221A";if(W==="Root"&&Te(B)===2){let Q=g(P(B,2));if(Q===3)return"\u221B";if(Q===4)return"\u221C"}return null}function E(B,W){return m(W,"radicand")?t.line(B,i(W)):t.line(B,"(",i(W),")")}let x={Sqrt:B=>{let W=b(B);return W!==null?E(W,P(B,1)):ee(B)},Root:B=>{let W=b(B);return W!==null?E(W,P(B,1)):ee(B)},Power:B=>{let W=y(B);if(W!==null){let Q=P(B,1);return m(Q,"base")?t.line(i(Q),W):t.line("(",i(Q),")",W)}return yi(B)??ee(B)},BaseForm:B=>{let W=Se(P(B,2))??16,Q=P(B,1),ie=Se(Q);return ie===null||Number.isNaN(ie)||!Number.isFinite(ie)||!(W===2||W===10||W===16)?ee(B):W===2?t.text("0b"+Number(ie).toString(2)):W===10?t.text(rd(Q,vx)):W===16?Number.isFinite(ie)?Number.isInteger(ie)?t.text("0x"+Number(ie).toString(16)):t.text(fK(ie)):t.text(rd(Q,vx)):ee(B)},String:B=>t.wrap('"',...xr(B,W=>{let Q=fe(W);return Q!==null?t.text(v_(Q)):t.fencedBlock("\\(",i(W),")")}),'"'),List:B=>t.fencedList("[",t.separator(","),"]",xr(B,i)),Set:B=>Te(B)===0?t.text("{}"):t.fencedList("{",t.separator(","),"}",xr(B,i)),Tuple:B=>Te(B)<2?ee(B):t.fencedList("(",t.separator(","),")",xr(B,i)),At:B=>{let W=P(B,1),Q=G(B).slice(1);if(W===null||Q.length===0)return ee(B);let ie=u[L(W)]!==void 0?t.line("(",i(W),")"):i(W);return t.line(ie,t.fencedList("[",t.separator(","),"]",Q.map(oe=>i(oe))))},Field:B=>{let W=P(B,1),Q=P(B,2),ie=Q===null?null:fe(Q);if(W===null||ie===null||!/^[A-Za-z_][A-Za-z0-9_]*$/.test(ie))return ee(B);let oe=u[L(W)]!==void 0?t.line("(",i(W),")"):i(W);return t.line(oe,t.text("."+ie))},ProtocolProperty:B=>{if(Te(B)!==3)return ee(B);let W=fe(P(B,1))??Z(P(B,1)),Q=fe(P(B,2))??Z(P(B,2)),ie=P(B,3);if(W===null||Q===null||ie===null)return ee(B);let oe=u[L(ie)]!==void 0?t.line("(",i(ie),")"):i(ie);return t.line(oe,t.text(`.(${Ri(W)}.${Ri(Q)})`))},MemberCall:B=>{let W=P(B,1),Q=fe(P(B,2))??Z(P(B,2));if(W===null||Q===null||l(W))return ee(B);let ie=u[L(W)]!==void 0?t.line("(",i(W),")"):i(W);return t.line(ie,t.text("."+Ri(Q)),t.fencedList("(",t.separator(","),")",G(B).slice(2).map(i)))},ProtocolMember:B=>{if(Te(B)<3)return ee(B);let W=fe(P(B,1))??Z(P(B,1)),Q=fe(P(B,2))??Z(P(B,2)),ie=P(B,3);if(W===null||Q===null||ie===null||l(ie))return ee(B);let oe=u[L(ie)]!==void 0?t.line("(",i(ie),")"):i(ie);return t.line(oe,t.text(`.(${Ri(W)}.${Ri(Q)})`),t.fencedList("(",t.separator(","),")",G(B).slice(3).map(i)))},Dictionary:B=>Te(B)===0?t.line(t.fence("{"),t.relationalOperator("->"),t.fence("}")):t.fencedList("{",t.separator(","),"}",xr(B,i)),Spread:B=>Te(B)!==1?ee(B):t.line("...",i(P(B,1))),NamedArgument:B=>{if(Te(B)!==2)return ee(B);let W=fe(P(B,1));return W===null?ee(B):t.line(`${Ri(W)}: `,i(P(B,2)))},Negate:B=>{if(Te(B)!==1)return ee(B);let W=P(B,1);return l(W)?t.text(yWe(rd(W,vx))):yi(B)??ee(B)},Multiply:B=>{let W=G(B);if(W.length===2&&l(W[0])){let Q=Z(W[1]);if(Q!==null){let ie=rd(W[0],vx);if(bWe(ie,Q))return t.text(ie+Q)}}return yi(B)??ee(B)},If:B=>Bt(B)??ee(B),Block:B=>_e("do ",B),Loop:B=>ht(B)??ee(B),Break:B=>r>0&&Te(B)===0?t.text("break"):ee(B),Continue:B=>r>0&&Te(B)===0?t.text("continue"):ee(B),Function:B=>o(0,()=>$(B)),Typed:B=>{let W=_(P(B,2));if(W!==null&&!Es(W))try{let Q=re(W,Xz);if(typeof Q!="string"&&Q.kind==="signature")return ee(B)}catch{}return i(P(B,1))},Declare:B=>{let W=G(B);if(W.length<1||W.length>3)return ee(B);let Q=W[0],ie=Dn=>L(Dn)==="Tuple"&&Te(Dn)>=2&&G(Dn).every(ds=>Z(ds)!==null||ie(ds)),oe=ie(Q);if(!oe&&Z(Q)===null)return ee(B);let se=null,he=null;for(let Dn of W.slice(1)){let ds=Sx(Dn);if(ds!==null){if(he!==null)return ee(B);he=ds}else{let Tc=fe(Dn)??Z(Dn);if(Tc===null||se!==null||he!==null)return ee(B);se=Tc}}let Ce=null,tn=!1;if(he!==null)for(let Dn of Object.keys(he))if(Dn==="value")Ce=he[Dn];else if(Dn==="constant"){let ds=he[Dn];if((Z(ds)??fe(ds))!=="True")return ee(B);tn=!0}else return ee(B);if(oe&&(se!==null||Ce===null))return ee(B);let Be=[tn?"const ":"let ",i(Q)];return se!==null&&Be.push(": "+se),Ce!==null&&Be.push(" = ",i(Ce)),t.line(...Be)},DeclareType:B=>{let W=G(B);if(W.length!==2&&W.length!==3)return ee(B);let Q=Z(W[0])??fe(W[0]),ie=fe(W[1])??Z(W[1]);if(Q===null||ie===null)return ee(B);if(W.length===2)return t.line("type ",Q," = ",ie);let oe=Sx(W[2]);if(oe===null)return ee(B);let se=Object.keys(oe);if(se.length===0||se.some(Dn=>Dn!=="alias"&&Dn!=="typeParams"))return ee(B);let he=oe.alias??null;if(he!==null&&(Z(he)??fe(he))!=="True")return ee(B);let Ce=he!==null?"type alias ":"type ",tn=oe.typeParams;if(tn===void 0)return t.line(Ce,Q," = ",ie);let Be=fe(tn)??Z(tn);return Be===null||Be.length===0?ee(B):t.line(Ce,Q,"<",Be,"> = ",ie)},DeclareProtocol:B=>{let W=G(B);if(W.length!==1&&W.length!==2)return ee(B);let Q=Z(W[0])??fe(W[0]);if(Q===null)return ee(B);let ie=Ri(Q);if(W.length===1)return t.line("protocol ",ie," {}");let oe=Sx(W[1]);if(oe===null)return ee(B);let se=[];for(let[he,Ce]of Object.entries(oe)){if(L(Ce)!=="Pair"||Te(Ce)!==2)return ee(B);let tn=fe(P(Ce,1))??Z(P(Ce,1)),Be=fe(P(Ce,2))??Z(P(Ce,2));if(Be===null)return ee(B);if(tn==="function")se.push(t.text(`function ${Ri(he)}${Be}`));else if(tn==="readonly"||tn==="readwrite")se.push(t.text(`${tn} ${Ri(he)}: ${Be}`));else return ee(B)}return se.length===0?t.line("protocol ",ie," {}"):t.stack(t.line("protocol ",ie," {"),t.indent(t.stack(...se)),t.text("}"))},DeclareConformance:B=>{let W=G(B);if(W.length<2||W.length>4)return ee(B);let Q=fe(W[0])??Z(W[0]);if(Q===null)return ee(B);let oe=(L(W[1])==="List"?G(W[1]):[W[1]]).map(Be=>Z(Be)??fe(Be));if(oe.length===0||oe.some(Be=>Be===null))return ee(B);let se=`type ${Q} is ${oe.map(Be=>Ri(Be)).join(" & ")}`,he=W.slice(2);if(he.length>0&&fe(he[0])!==null){let Be=fe(he[0]);he=he.slice(1),se+=/^\s*where\b/.test(Be)?` ${Be.trim()}`:` where ${Be.trim()}`}if(he.length>1)return ee(B);if(he.length===0)return t.text(se);let Ce=Sx(he[0]);if(Ce===null)return ee(B);let tn=[];for(let[Be,Dn]of Object.entries(Ce)){if(L(Dn)!=="Function")return ee(B);let ds=Be.startsWith("__get__"),Tc=Be.startsWith("__set__"),Nx=ds||Tc?Be.slice(7):Be,$y=q(ds?"get":Tc?"set":"function",Nx,Dn);if($y===null)return ee(B);tn.push($y)}return tn.length===0?t.line(se," {}"):t.stack(t.text(`${se} {`),t.indent(t.stack(...tn)),t.text("}"))},DeclareSumType:B=>{let W=G(B);if(W.length<2)return ee(B);let Q=Z(W[0])??fe(W[0]);if(Q===null)return ee(B);let ie=W.slice(1),oe=null;if(L(ie[0])!=="Tuple"){let he=Sx(ie[0]);if(ie=ie.slice(1),he===null)return ee(B);let Ce=Object.keys(he);if(Ce.length!==1||Ce[0]!=="typeParams"||(oe=fe(he.typeParams)??Z(he.typeParams),oe===null||oe.length===0))return ee(B)}if(ie.length===0)return ee(B);let se=[];for(let he of ie){if(L(he)!=="Tuple"||Te(he)!==2)return ee(B);let Ce=fe(P(he,1))??Z(P(he,1)),tn=fe(P(he,2))??Z(P(he,2));if(Ce===null||tn===null)return ee(B);if(tn==="nothing")se.push(Ce);else{let Be=gWe(tn);se.push(`${Ce}(${Be??tn})`)}}return t.line("type ",Q,oe===null?"":`<${oe}>`," = ",se.join(" | "))},Assign:B=>{let W=P(B,1),Q=P(B,2);if(W!==null&&Q!==null&&L(Q)==="Function"){let ie=G(Q).slice(1),oe=P(Q,1),se=ie.some(Ce=>L(Ce)==="Typed"),he=L(oe)==="Typed";if((se||he)&&U(ie))return K(W,Q)}return yi(B)??ee(B)},DefineFunction:B=>{let W=P(B,1),Q=P(B,2),ie=Te(B)===3?de(P(B,3)):null;if((Te(B)===2||ie!==null)&&W!==null&&Z(W)!==null&&Q!==null&&L(Q)==="Function"&&U(G(Q).slice(1))){let oe=K(W,Q,ie??{});return ie?.description!==void 0?t.stack(...ie.description.split(`
1899
- `).map(se=>t.text(`/// ${se}`)),oe):oe}return ee(B)},Match:B=>{let W=Kd(B);if(W!==null)return W;let Q=P(B,1),ie=G(B).slice(1),oe=t.line("match ",i(Q)," {");return ie.length===0?t.line("match ",i(Q)," {}"):t.stack(oe,t.indent(t.stack(...ie.map(S))),t.text("}"))},MatchCase:B=>S(B),Pin:B=>v(B),Alternatives:B=>v(B)};function S(B){let W=G(B),Q=v(W[0]??"Nothing"),ie=W.length>=3,oe=ie?W[1]:null,se=ie?W[2]:W[1],he=[Q];return oe!=null&&he.push(" if ",i(oe)),he.push(n?.fancySymbols?" \u21D2 ":" => ",i(se??"Nothing")),t.line(...he)}function v(B,W){let Q=L(B);if(Q==="Pin")return t.line("== ",i(P(B,1)));if(Q==="Alternatives"){let se=G(B),he=[];return se.forEach((Ce,tn)=>{tn>0&&he.push(" | "),he.push(v(Ce,W))}),t.line(...he)}if(Q==="Range"&&G(B).length===2)return t.line(v(P(B,1)??"Nothing",W),t.infixOperator(".."),v(P(B,2)??"Nothing",W));if(Q==="List")return t.fencedList("[",t.separator(","),"]",G(B).map(se=>v(se,W)));if(Q==="Tuple")return t.fencedList("(",t.separator(","),")",G(B).map(se=>v(se,W)));if(Q==="Dictionary"){let se=G(B);return se.length===0?t.line(t.fence("{"),t.relationalOperator("->"),t.fence("}")):t.fencedList("{",t.separator(","),"}",se.map(he=>t.line(i(P(he,1)),t.relationalOperator("->"),v(P(he,2)??"Nothing",W))))}let ie=Z(B);if(ie!==null){if(ie==="_")return t.text("_");if(ie==="True")return t.text("true");if(ie==="False")return t.text("false");if(ie.startsWith("___"))return t.text("..."+ie.slice(3));if(ie.startsWith("_")){let se=ie.slice(1),he=W?.get(se);return t.text(he===void 0?Ri(se):Ri(se)+": "+he)}return t.line("== ",t.text(Ri(ie)))}if(l(B))return t.text(rd(B,vx));if(typeof B=="object"&&B!==null&&"str"in B)return s(B.str);let oe=typeof B=="string"&&/^'[\s\S]*'$/.test(B)?fe(B):null;return oe!==null?s(oe):i(w(B))}function w(B){let W=Z(B);if(W!==null)return W!=="_"&&!W.startsWith("___")&&W.startsWith("_")?{sym:W.slice(1)}:B;let Q=L(B);return Q?{fn:[Q,...G(B).map(w)]}:B}let _=B=>{if(B===null)return null;let W=fe(B);return W!==null?W:Z(B)},C=B=>{let W={typeParams:null,argTypes:[],decomposed:!1},Q=P(B,1);if(L(Q)!=="Typed")return{bodyExpr:Q,retType:null,specifier:null,...W};let ie=P(Q,1),oe=_(P(Q,2));if(oe!==null&&!Es(oe))try{let se=re(oe,Xz);if(typeof se!="string"&&se.kind==="signature"){let he=wn(se),Ce=se.typeParams??[],tn=se.result;return{bodyExpr:ie,retType:tn==="unknown"||tn==="any"?null:xh(tn),specifier:he!==void 0?Ks(he):null,typeParams:Ce.length>0?Ce.map(Dn=>Dn.bound!==void 0?`${Dn.name}: ${ne(Dn.bound)}`:Dn.name).join(", "):null,argTypes:Ce.length>0?(se.args??[]).map(Dn=>Dn.type):[],decomposed:!0}}}catch{}return{bodyExpr:ie,retType:oe,specifier:null,...W}},k={oo:"Infinity","+oo":"Infinity","-oo":"-Infinity",Infinity:"Infinity","+Infinity":"Infinity","-Infinity":"-Infinity",NaN:"NaN",nan:"NaN"},M=B=>/^-?[0-9.]/.test(B)||B.startsWith('"')||B==="true"||B==="false"||B in k,j=B=>{let W=[];for(let Q of G(B)){if(L(Q)==="Tuple"){let oe=j(Q);if(oe===null)return null;W.push(oe);continue}let ie=Z(Q);if(ie===null)return null;W.push(Ri(ie))}return`(${W.join(", ")})`},V=B=>L(B)==="Spread"&&Te(B)===1&&Z(P(B,1))!==null,U=B=>B.every((W,Q)=>L(W)==="Spread"?V(W)&&Q===B.length-1:L(W)!=="Tuple"||j(W)!==null),D=(B,W,Q)=>{if(L(B)==="Tuple")return t.text(j(B)??"");if(V(B))return t.text(`...${Ri(Z(P(B,1)))}`);let ie=L(B)==="Typed",oe=ie?Z(P(B,1)):Z(B),se=(ie?_(P(B,2)):null)??(W!==void 0&&W!=="unknown"?ne(W):null);if(oe!==null&&ws(oe)&&se!==null&&M(se)){if(se.startsWith('"')&&se.endsWith('"')){let tn=se.slice(1,-1).replace(/\\(["\\])/g,"$1");return t.text(`"${v_(tn)}"`)}return t.text(k[se]??se)}let he=oe!==null?Ri(oe):"",Ce=oe!==null&&Q!==void 0&&Q.has(oe)?"bind ":"";return t.text(se!==null?`${Ce}${he}: ${se}`:`${Ce}${he}`)},z=(B,W=[],Q)=>t.fencedList("(",t.separator(","),")",B.map((ie,oe)=>D(ie,W[oe],Q))),$=B=>{let W=G(B).slice(1),Q=P(B,1),ie=W.some(Dn=>L(Dn)==="Typed"),oe=L(Q)==="Typed";if(!U(W))return ee(B);let se=W.some(Dn=>L(Dn)==="Tuple"),he=W.some(Dn=>L(Dn)==="Spread");if(!ie&&!oe&&!se&&!he)return ee(B);let{bodyExpr:Ce,decomposed:tn}=C(B);if(tn)return ee(B);let Be=n?.fancySymbols?"\u21D2":"=>";return t.line(z(W),` ${Be} `,i(Ce))},q=(B,W,Q)=>o(0,()=>H(B,W,Q)),H=(B,W,Q)=>{let ie=G(Q).slice(1);if(!U(ie))return null;let{bodyExpr:oe,retType:se,specifier:he,argTypes:Ce}=C(Q),tn=he!==null?` ${he}`:"",Be=se!==null?` -> ${se}`:"";return t.line(`${B} ${Ri(W)}`,z(ie,Ce),`${tn}${Be} `,t.fencedList("{",t.separator(";"),"}",L(oe)==="Block"?xr(oe,i):[i(oe)]))},K=(B,W,Q={})=>o(0,()=>Y(B,W,Q)),Y=(B,W,Q)=>{let ie=Z(B),oe=ie!==null?Ri(ie):"",se=G(W).slice(1),{bodyExpr:he,retType:Ce,specifier:tn,typeParams:Be,argTypes:Dn}=C(W),ds=[...tn!==null?[tn]:[],...Q.algebraic??[]],Tc=ds.length>0?ds.join(" "):null,Nx=Tc!==null?` ${Tc}`:"",$y=Ce!==null?` -> ${Ce}`:"",xO=Q.bind!==void 0?new Set(Q.bind):void 0,vO=Q.hold?"hold ":"",cJ=Be!==null?`<${Be}>`:"";if(L(he)==="Block")return t.line(`${vO}function ${oe}${cJ}`,z(se,Dn,xO),`${Nx}${$y} `,t.fencedList("{",t.separator(";"),"}",xr(he,i)));if(Be!==null)return t.line(`${vO}function ${oe}${cJ}`,z(se,Dn,xO),`${Nx}${$y} `,t.fencedList("{",t.separator(";"),"}",[i(he)]));let i1e=Ce!==null?$y:Tc!==null?" -> unknown":"";return t.line(`${vO}${oe}`,z(se,void 0,xO),`${Nx}${i1e} = `,i(he))};function de(B){if(B===null)return null;let W=Sx(B);if(W===null)return null;let Q={},ie=oe=>(Z(oe)??fe(oe))==="True";for(let oe of Object.keys(W)){let se=W[oe];if(se!=null)switch(oe){case"hold":if(!ie(se))return null;Q.hold=!0;break;case"commutative":case"associative":case"idempotent":case"involution":if(!ie(se))return null;(Q.algebraic??=[]).push(oe);break;case"bind":{let he=L(se)==="List"?G(se):Array.isArray(se)?se:[se],Ce=[];for(let tn of he){let Be=fe(tn)??Z(tn);if(Be===null)return null;Ce.push(Be)}Q.bind=Ce;break}case"description":{let he=fe(se);if(he===null)return null;Q.description=he;break}default:return null}}return Q}function X(B){return x[L(B)]?.(B)??null}function ee(B){let W=L(B);return W?t.line(Ri(W),t.fencedList("(",t.separator(","),")",xr(B,i))):t.line("Apply(",i(W),t.separator(","),t.fencedList("[",t.separator(","),"]",xr(B,i)),")")}function _e(B,W){let Q=co(W);return Q.length===0?t.text(B+"{}"):t.choice(t.line(B,Qe(W)),t.stack(t.text(B+"{"),t.indent(t.stack(...Q)),t.text("}")))}function Qe(B){let W=co(B);if(W.length===0)return t.text("{}");let Q=[];return W.forEach((ie,oe)=>{oe>0&&Q.push(t.separator(";")),Q.push(ie)}),t.line(t.fence("{"),...Q,t.fence("}"))}function bn(B,W){let Q=u[L(B)];return Q&&Q.precedence<W?t.line("(",i(B),")"):i(B)}let nn=B=>B!==null&&L(B)==="Block";function Hn(B){let W=[],Q=B;for(;;){let ie;if(L(Q)==="If"){let se=Te(Q);if(se!==2&&se!==3)return null;let he=P(Q,1),Ce=P(Q,2);if(ie=se===3?P(Q,3):null,he===null||Ce===null||!nn(Ce))return null;W.push({head:()=>bn(he,wu+1),body:Ce})}else{let se=On(Q);if(se===null)return null;let{pattern:he,typed:Ce,subject:tn,body:Be}=se;W.push({head:()=>t.line("let ",v(he,Ce)," = ",bn(tn,wu+1)),body:Be}),ie=se.fallback}if(ie===null)return{clauses:W,elseBody:null};if(nn(ie))return{clauses:W,elseBody:ie};let oe=L(ie);if(oe!=="If"&&oe!=="Match")return null;Q=ie}}function Oe(B){if(L(B)!=="Match"||Te(B)!==3)return null;let W=P(B,1),Q=P(B,2),ie=P(B,3);if(W===null||Q===null||ie===null||L(Q)!=="MatchCase")return null;let oe=Te(Q);if(oe!==2&&oe!==3)return null;let se=P(Q,1),he=oe===3?P(Q,2):null,Ce=P(Q,oe);if(se===null||Ce===null||!nn(Ce))return null;let tn=Ca(se,he);if(tn===null||L(ie)!=="MatchCase"||Te(ie)!==2||Z(P(ie,1))!=="_")return null;let Be=P(ie,2);return Be===null?null:{subject:W,pattern:se,typed:tn,body:Ce,fallbackBody:Be}}function On(B){let W=Oe(B);if(W===null)return null;let{subject:Q,pattern:ie,typed:oe,body:se,fallbackBody:he}=W,Ce;if(Z(he)==="Missing")Ce=null;else if(nn(he)||L(he)==="If"||L(he)==="Match")Ce=he;else return null;return{subject:Q,pattern:ie,typed:oe,body:se,fallback:Ce}}function ct(B){let W=Oe(B);if(W===null)return null;let{subject:Q,pattern:ie,typed:oe,body:se,fallbackBody:he}=W;return L(he)!=="Break"||Te(he)!==0?null:{subject:Q,pattern:ie,typed:oe,body:se}}function Ca(B,W){let Q=new Map;if(W===null)return Q;let ie=L(W)==="And"?G(W):[W];for(let oe of ie){if(L(oe)!=="MatchesType"||Te(oe)!==2)return null;let se=Z(P(oe,1)),he=P(oe,2);if(se===null||L(he)!=="TypeFrom"||Te(he)!==1)return null;let Ce=fe(P(he,1));if(Ce===null||Q.has(se)||!$o(Ce)||Fl(B,se)!==1)return null;Q.set(se,Ce)}return Q}function $o(B){if(/[\r\n\u2028\u2029]/.test(B))return!1;try{return re(B,Xz),!0}catch{return!1}}function Fl(B,W){if(Z(B)==="_"+W)return 1;let Q=L(B);return Q==="List"||Q==="Tuple"?G(B).reduce((ie,oe)=>ie+Fl(oe,W),0):Q==="Dictionary"?G(B).reduce((ie,oe)=>ie+Fl(P(oe,2)??"Nothing",W),0):0}let co=B=>xr(B,i)??[];function Kd(B){let W=Hn(B);if(W===null)return null;let{clauses:Q,elseBody:ie}=W,oe=[];Q.forEach(({head:tn,body:Be},Dn)=>{oe.push(Dn===0?"if ":" else if "),oe.push(tn()," ",Qe(Be))}),ie!==null&&oe.push(" else ",Qe(ie));let se=t.line(...oe),he=[],Ce=tn=>{let Be=co(tn);Be.length>0&&he.push(t.indent(t.stack(...Be)))};return Q.forEach(({head:tn,body:Be},Dn)=>{he.push(t.line(Dn===0?"if ":"} else if ",tn()," {")),Ce(Be)}),ie!==null&&(he.push(t.text("} else {")),Ce(ie)),he.push(t.text("}")),t.choice(se,t.stack(...he))}function Bt(B){let W=Kd(B);if(W!==null)return W;if(Te(B)!==3)return null;let Q=P(B,1),ie=P(B,2),oe=P(B,3);return Q===null||ie===null||oe===null||nn(ie)||nn(oe)?null:t.line(bn(ie,wu+1)," if ",bn(Q,wu+1)," else ",bn(oe,wu))}function He(B,W){let Q=co(W);return Q.length===0?t.line(B," {}"):t.choice(t.line(B," ",Qe(W)),t.stack(t.line(B," {"),t.indent(t.stack(...Q)),t.text("}")))}function Kn(B){if(!nn(B)||Te(B)!==2)return null;let W=P(B,1),Q=P(B,2);if(W===null||Q===null||!nn(Q)||L(W)!=="If"||Te(W)!==2)return null;let ie=P(W,1),oe=P(W,2);if(L(ie)!=="Not"||Te(ie)!==1||L(oe)!=="Break"||Te(oe)!==0)return null;let se=P(ie,1);return se===null?null:{cond:se,body:Q}}function ht(B){let W=ie=>bn(ie,wu+1),Q=G(B);if(Q.length===2){let[ie,oe]=Q;if(!nn(ie)||L(oe)!=="Element"||Te(oe)!==2)return null;let se=P(oe,1),he=P(oe,2);if(se===null||he===null)return null;let Ce;if(L(se)==="Tuple")Ce=j(se);else{let Be=Z(se);Ce=Be===null?null:Ri(Be)}if(Ce===null)return null;let tn=t.line("for ",Ce," in ",W(he));return o(r+1,()=>He(tn,ie))}if(Q.length===1){let ie=Kn(Q[0]);if(ie!==null){let se=t.line("while ",W(ie.cond));return o(r+1,()=>He(se,ie.body))}let oe=ct(Q[0]);if(oe!==null){let{pattern:se,typed:he,subject:Ce,body:tn}=oe,Be=t.line("while let ",v(se,he)," = ",W(Ce));return o(r+1,()=>He(Be,tn))}}return null}function yi(B){let W=L(B);if(!W)return null;let Q=u[W];if(!Q)return null;if(W==="MapsTo"&&r!==0)return o(0,()=>yi(B));let ie=n?.fancySymbols?Q.fancySymbol??Q.symbol:Q.symbol;if(Q.unary){if(Te(B)!==1)return null;let se=P(B,1),he=L(se),Ce=u[he];return Ce&&Ce.precedence<Q.precedence?t.line(ie,"(",i(se),")"):t.line(ie,i(se))}if(Q.postfix){if(Te(B)!==1)return null;let se=P(B,1),he=L(se),Ce=u[he];return Ce&&Ce.precedence<=Q.precedence||f(se)||b(se)!==null?t.line("(",i(se),")",ie):t.line(i(se),ie)}let oe=G(B).map((se,he)=>p(se,Q,W,he===0?"left":"right")?t.line("(",i(se),")"):i(se));return oe.length===0?null:t.list(Q.relational?t.relationalOperator(ie):t.infixOperator(ie),oe)}return L(e)==="Block"&&Te(e)>=2?t.stack(...xr(e,i)).serialize(0):i(e).serialize(0)}function Tve(e){return typeof e=="boolean"?e?"True":"False":e}function gWe(e){let n="tuple<";if(!e.startsWith(n)||!e.endsWith(">"))return null;let t=0;for(let i=n.length;i<e.length;i++){let r=e[i];if(r==="-"&&e[i+1]===">"){i+=1;continue}if(r==="<"||r==="("||r==="[")t+=1;else if(r===">"||r===")"||r==="]"){if(t===0)return r===">"&&i===e.length-1?e.slice(n.length,i):null;t-=1}}return null}function Sx(e){if(e===null)return null;let n=Object.create(null);if(typeof e=="object"&&!Array.isArray(e)&&"dict"in e&&typeof e.dict=="object"&&e.dict!==null){for(let[t,i]of Object.entries(e.dict))n[t]=Tve(i);return n}if(L(e)!=="Dictionary")return null;for(let t of G(e)){if(L(t)!=="KeyValuePair")return null;let i=fe(P(t,1))??Z(P(t,1));if(i===null)return null;n[i]=P(t,2)??"Nothing"}return n}function yWe(e){return e.startsWith("-")?e.slice(1):e.startsWith("+")?"-"+e.slice(1):"-"+e}function bWe(e,n){return!(!/^\d[\d_]*(\.\d[\d_]*)?$/.test(e)||Ri(n)!==n||!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(n)||/^[eE]/.test(n)||e==="0"&&/^[bBxX]/.test(n))}function Sve(e){return QP.has(e)?QP.get(e):Dz(e)?e<65536?`\\u${("0000"+e.toString(16)).slice(-4)}`:`\\u{${("000000000"+e.toString(16)).slice(-8)}}`:String.fromCodePoint(e)}function v_(e){let n="",t=Xv(e);if(typeof t=="string")for(let i of t)n+=Sve(i.codePointAt(0));else for(let i of t)i.length===1?n+=Sve(i.codePointAt(0)):n+=i;return n}function Ri(e){if(Zd.has(e))return`\`${e}\``;if(e==="let")return`\`${e}\``;if(/^[a-zA-Z][a-zA-Z\d_]*$/.test(e))return e;let n=e.codePointAt(0);if(Na.has(n))return`\`${v_(e)}\``;let t=!1,i=Xv(e),r=0;for(;!t&&r<i.length;){let o=i[r].codePointAt(0);t=QP.has(o)||Dz(o)||px(o),r+=1}return t?`\`${v_(e)}\``:e}var EWe=new Set(["Alternatives","Annotated","At","Block","Colon","Comprehension","Condition","Declare","DeclareConformance","DeclareProtocol","DeclareSumType","DeclareType","DefineFunction","Delimiter","Hold","HoldValues","HorizontalSpacing","IndexedSequence","InvisibleOperator","Latex","LatexString","Loop","MatchCase","MatchesType","MemberCall","NamedArgument","OverParen","Pair","PreDecrement","PreIncrement","ReleaseHold","Rule","Sequence","Single","Spread","Square","Subscript","Text","Triple","Typed","Unevaluated","Which","Wildcard","WildcardOptionalSequence","WildcardSequence"]),xWe=new Set(["Dictionary","List","Set","String","Tuple"]),vWe=new Set(["Approx","ApproxEqual","ApproxNotEqual","NotApprox","NotApproxEqual","NotApproxNotEqual","NotGreater","NotGreaterNotEqual","NotLess","NotLessNotEqual","NotPrecedes","NotSubset","NotSucceeds","NotSuperset","NotSupersetEqual","NotTilde","NotTildeEqual","NotTildeFullEqual","PlusMinus","Precedes","Succeeds","Tilde","TildeEqual","TildeFullEqual"]),SWe=new Set(["BuiltinFunction","ContinuationPlaceholder","ErrorCode","Object","Pin","Predicate","ProtocolMember","ProtocolProperty","RuntimeError","Signature","Subtype"]),TWe=new Set(["True","False","NaN"]),wWe=new Set(bx.map(e=>e.name));function _We(e){let n=/^([A-Z]+)(.*)$/s.exec(e);if(n===null)return;let[,t,i]=n;return t.length===1?t.toLowerCase()+i:/^[a-z]/.test(i)?t.slice(0,-1).toLowerCase()+t.slice(-1)+i:t.toLowerCase()+i}function S_(e){if(e.length<=1)return;let n=_We(e);if(n!==void 0&&!wWe.has(e)&&!Zd.has(n)&&!(EWe.has(e)||xWe.has(e)||vWe.has(e)||SWe.has(e)||TWe.has(e)))return n}var Qz;function eJ(){if(Qz!==void 0)return Qz;let e=new Map;for(let n of cy){let t=n.definitions;if(t===void 0)continue;let i=Array.isArray(t)?t:[t];for(let r of i)for(let o of Object.keys(r)){let s=S_(o);s!==void 0&&(!e.has(s)||e.get(s),`${s}${e.get(s)}${o}`,e.set(s,o))}}return Qz=e,e}function T_(e){return eJ().get(e)}var wve={definition:0,write:1,read:2};function _ve(e,n,t){let i=[],r=new Map,o={span:[0,n.length],bindings:new Map,parent:void 0};function s(v){return typeof v=="object"&&v!==null&&!Array.isArray(v)?v.sourceOffsets:void 0}function a(v,w){if(w[0]<0||w[1]>n.length||w[0]>=w[1])return!1;let _=n.slice(w[0],w[1]);if(_===v||_==="`"+v+"`")return!0;if(_.length>v.length+8)return!1;let C=oO(_).filter(k=>k.type!=="EOF");return C.length===1&&C[0].start===0&&C[0].end===_.length&&(C[0].type==="SYMBOL"||C[0].type==="VERBATIM_SYMBOL")&&(C[0].value??C[0].text)===v}function u(v,w){return{span:v??w.span,bindings:new Map,parent:w}}function l(v,w,_,C,k){let M=v.bindings.get(w);if(M!==void 0)return M;let j={name:w,kind:_,occurrences:[],...C===void 0?{}:{declaration:C},scope:v.span,visibleFrom:k};return i.push(j),v.bindings.set(w,j),j}function f(v,w,_,C){for(let M=_;M!==void 0;M=M.parent){let j=M.bindings.get(v);if(j!==void 0&&w[0]>=j.visibleFrom){j.occurrences.push({start:w[0],end:w[1],role:C});return}}let k=r.get(v);k===void 0&&(k={name:v,kind:"free",occurrences:[],scope:o.span,visibleFrom:0},r.set(v,k),i.push(k)),k.occurrences.push({start:w[0],end:w[1],role:C})}function c(v){let w=v===null?null:Z(v);if(w===null||w==="_")return;let _=s(v);if(!(_===void 0||!a(w,_)))return{name:w,span:_}}function d(v,w,_,C,k){if(v===null)return;let M=L(v);if(M===""){let j=c(v);if(j===void 0)return;l(w,j.name,_,C,k).occurrences.push({start:j.span[0],end:j.span[1],role:"definition"});return}if(M==="Typed"){d(P(v,1),w,_,C,k);return}if(M==="Tuple"){for(let j of G(v))d(j,w,_,C,k);return}b(v,w)}function p(v,w){if(v===null)return;let _=L(v);if(_!==""){if(_==="Typed"){p(P(v,1),w);return}for(let M of G(v))p(M,w);return}let C=Z(v);if(C===null||/^_+$/.test(C))return;let k=s(v);if(k!==void 0){if(C.startsWith("___")){let M=C.slice(3),j=[k[0]+3,k[1]];n.slice(k[0],k[0]+3)==="..."&&a(M,j)&&l(w,M,"pattern",k,w.span[0]).occurrences.push({start:j[0],end:j[1],role:"definition"});return}if(C.startsWith("_")&&a(C.slice(1),k)){l(w,C.slice(1),"pattern",k,w.span[0]).occurrences.push({start:k[0],end:k[1],role:"definition"});return}a(C,k)&&f(C,k,w,"read")}}function m(v,w,_){let C=c(P(v,1));if(C===void 0)return;let k=s(v)??C.span,M=l(w,C.name,"function",k,w.span[0]);M.declaration!==void 0&&(M.declaration=[Math.min(M.declaration[0],k[0]),Math.max(M.declaration[1],k[1])]),_&&M.occurrences.push({start:C.span[0],end:C.span[1],role:"definition"})}function g(v,w){for(let _ of v)_!==null&&L(_)==="DefineFunction"&&m(_,w,!1)}function y(v,w){let _=u(s(v),w),C=[...G(v)];for(let k=1;k<C.length;k++)d(C[k],_,"parameter",void 0,_.span[0]);b(C[0]??null,_)}function b(v,w){if(v===null)return;let _=L(v);if(_===""){let C=c(v);C!==void 0&&f(C.name,C.span,w,"read");return}switch(_){case"Block":{let C=u(s(v),w),k=[...G(v)];g(k,C);for(let M of k)b(M,C);return}case"Declare":{let C=[...G(v)];for(let M=1;M<C.length;M++)b(C[M],w);let k=s(v);d(C[0]??null,w,"variable",k,k?.[1]??w.span[0]);return}case"Assign":{let C=[...G(v)];for(let k=1;k<C.length;k++)b(C[k],w);x(C[0]??null,w,s(v));return}case"DefineFunction":{m(v,w,!0);let C=P(v,2);C!==null&&L(C)==="Function"?y(C,w):b(C,w),b(P(v,3),w);return}case"Function":y(v,w);return;case"Loop":{let C=P(v,2);if(C!==null&&L(C)==="Element"){b(P(C,2),w);let k=u(s(v),w);d(P(C,1),k,"loop",s(C),k.span[0]),b(P(v,1),k);return}for(let k of G(v))b(k,w);return}case"Match":{b(P(v,1),w);let C=[...G(v)];for(let k=1;k<C.length;k++){let M=C[k];if(M!==null&&L(M)==="MatchCase"){let j=u(s(M),w),V=[...G(M)];p(V[0]??null,j);for(let U=1;U<V.length;U++)b(V[U],j)}else b(M,w)}return}case"DeclareType":case"DeclareSumType":case"DeclareProtocol":{let C=c(P(v,1));C!==void 0&&l(w,C.name,"type",s(v)??C.span,w.span[0]).occurrences.push({start:C.span[0],end:C.span[1],role:"definition"});return}case"KeyValuePair":case"NamedArgument":{let C=[...G(v)];for(let k=1;k<C.length;k++)b(C[k],w);return}case"Typed":{b(P(v,1),w);return}default:{typeof _=="string"?E(v,_,w):b(_,w);let C=s(v),k=typeof _=="string"&&t?.binderSites!==void 0&&S(w,_,C?.[0]??w.span[0])===void 0?t.binderSites(v):void 0;if(k!==void 0&&k.length>0){let M=new Map;[...G(v)].forEach((j,V)=>{let U=k.filter(z=>z.operands==="all"||z.operands.includes(V));if(U.length===0){b(j,w);return}let D=u(C,w);for(let z of U){let $=M.get(z.name);$===void 0?M.set(z.name,l(D,z.name,"parameter",void 0,D.span[0])):D.bindings.set(z.name,$)}b(j,D)});return}for(let M of G(v))b(M,w);return}}}function E(v,w,_){if(w===""||w==="_")return;let C=s(v);if(C===void 0)return;let k=[C[0],C[0]+w.length];if(k[1]<=C[1]&&a(w,k)){f(w,k,_,"read");return}let M=[C[0],C[0]+w.length+2];M[1]<=C[1]&&n.slice(M[0],M[1])==="`"+w+"`"&&f(w,M,_,"read")}function x(v,w,_){if(v===null)return;let C=L(v);if(C==="Tuple"){for(let M of G(v))x(M,w,_);return}if(C==="Typed"){x(P(v,1),w,_);return}let k=c(v);if(k!==void 0){S(w,k.name,k.span[0])!==void 0?f(k.name,k.span,w,"write"):d(v,w,"variable",_,_?.[1]??w.span[0]);return}b(v,w)}function S(v,w,_){for(let C=v;C!==void 0;C=C.parent){let k=C.bindings.get(w);if(k!==void 0&&_>=k.visibleFrom)return k}}if(e!==null)if(L(e)==="Block"){let v=[...G(e)];g(v,o);for(let w of v)b(w,o)}else g([e],o),b(e,o);for(let v of i)v.occurrences.sort((w,_)=>w.start-_.start||w.end-_.end||wve[w.role]-wve[_.role]),v.occurrences=v.occurrences.filter((w,_,C)=>_===0||C[_-1].start!==w.start||C[_-1].end!==w.end);return i.sort((v,w)=>(v.occurrences[0]?.start??0)-(w.occurrences[0]?.start??0)),i}function NWe(e,n){let t=e;for(let i of n){if(t===null)return;t=G(t)[i]??null}return t===null?void 0:Z(t)??void 0}function Nve(e,n){return e===null?!1:Z(e)===n?!0:L(e)===""?!1:G(e).some(i=>Nve(i,n))}function Cve(e,n){if(e===null)return!1;let t=L(e);return t===""?!1:t===n?!0:G(e).some(i=>Cve(i,n))}var CWe=new Set(["List","Set","Tuple","Pair","Triple"]);function kWe(e,n,t){let i=L(n);if(i==="")return;let r=n.sourceOffsets,s=r!==void 0&&t[r[0]]==="`"||e.lookupDefinition(i)!==void 0?i:T_(i)??i,a=e.lookupDefinition(s);if(a===void 0||!("operator"in a))return;let u=[...G(n)],l=[],f=new Set,c=a.operator.bindingSites;if(c!==void 0){let d;try{d=u.map(p=>e.box(p,{form:"raw"}))}catch{d=void 0}if(d!==void 0){let p=c(d,"pre"),m=Math.min(...p.filter(g=>g.clauseLocal).map(g=>g.path[0]));for(let g of p){let y=NWe(n,g.path);if(y===void 0||f.has(y))continue;f.add(y);let b=g.path[0];l.push({name:y,operands:g.clauseLocal?u.map((E,x)=>x).filter(E=>E<m||E>=b):"all"})}}}return u.forEach((d,p)=>{let m=[],g=Z(d);if(g!==null)m.push(g);else if(CWe.has(L(d)))for(let y of G(d)){let b=Z(y);b!==null&&m.push(b)}for(let y of m)f.has(y)||y==="_"||!u.some((E,x)=>x!==p&&Nve(E,y))||u.some(E=>Cve(E,y))||(f.add(y),l.push({name:y,operands:"all"}))}),l}function pO(e,n,t){let i=_ve(e,n,{binderSites:u=>kWe(t,u,n)}),r=new Map,o=(u,l)=>`${u}:${l}`;for(let u of i){if(u.kind!=="free")continue;let l=T_(u.name);if(l!==void 0&&t.lookupDefinition(u.name)===void 0)for(let f of u.occurrences)n[f.start]!=="`"&&r.set(o(f.start,u.name),l)}if(r.size===0)return e;let s=u=>u.sourceOffsets,a=u=>{if(u===null||typeof u!="object")return;if(Array.isArray(u)){for(let f of u)a(f);return}let l=s(u);if("sym"in u){let f=l===void 0?void 0:r.get(o(l[0],u.sym));f!==void 0&&(u.sym=f);return}if("fn"in u){let f=u.fn,c=f[0];if(typeof c=="string"){let d=l===void 0?void 0:r.get(o(l[0],c));d!==void 0&&(f[0]=d)}else a(c);for(let d=1;d<f.length;d++)a(f[d]);return}if("dict"in u)for(let f of Object.values(u.dict))a(f)};return a(e),e}function mO(e){let n=new Map;return kve(e,(t,i)=>{n.has(t)||n.set(t,i)}),n}function kve(e,n){if(e===null)return;let t=L(e);if(t!==""){if(t==="DefineFunction"||t==="Declare"||t==="Assign"){let i=P(e,1),r=Z(i),o=nJ(i),s=nJ(e);if(r!==null&&o!==void 0){let a=t==="DefineFunction"?RWe(e):void 0;n(r,{name:o,header:IWe(e,t,s??o),...a!==void 0?{description:a}:{}})}}for(let i of G(e))kve(i,n)}}function IWe(e,n,t){if(n!=="DefineFunction")return t;let i=nJ(P(P(e,2),1));return i===void 0?t:[t[0],i[0]]}function RWe(e){let n=P(e,3);if(n!==null){if(typeof n=="object"&&!Array.isArray(n)&&"dict"in n&&typeof n.dict=="object"&&n.dict!==null){let t=n.dict.description;return typeof t=="string"?t:void 0}if(L(n)==="Dictionary"){for(let t of G(n))if(!(L(t)!=="KeyValuePair"||(Z(P(t,1))??fe(P(t,1)))!=="description"))return fe(P(t,2))??void 0}}}function nJ(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0}function hO(e){let n=[...G(e)],t=n[n.length-1];if(t===void 0||L(t)!=="ErrorTrace")return[];let i=[];for(let r of G(t)){if(L(r)!=="ErrorFrame")continue;let o=fe(P(r,1)),s=Se(P(r,2));o===null||s===null||i.push({name:o,index:s})}return i}function tJ(e,n){let t=L(e);if(t==="")return;let i=0;for(let r of G(e)){if(i+=1,r===n)return{name:t,index:i};let o=tJ(r,n);if(o!==void 0)return o}}function iJ(e,n,t,i,r="declaration"){for(let{name:o,index:s}of e){let a=[];if(Ave(n,o,a),a.length!==1)continue;let u=AWe([...G(a[0])],s-1,o,r,i),l=Ive(u)??Ive(a[0]);if(l!==void 0)return{range:l,call:a[0]}}return{range:t}}function AWe(e,n,t,i,r){if(i==="written"||!e.some(a=>L(a)==="NamedArgument"))return e[n]??null;let o=r?.(t);if(o===void 0)return null;let s=0;for(let a of e){if(L(a)!=="NamedArgument"){if(s===n)return a;s+=1;continue}let u=fe(P(a,1));if(u!==null&&o.indexOf(u)===n)return a}return null}function Rve(e,n,t,i,r="declaration"){return iJ(e,n,t,i,r).range}function Ave(e,n,t){if(!(e===null||t.length>1)&&L(e)!==""){L(e)===n&&t.push(e);for(let i of G(e))Ave(i,n,t)}}function Ive(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0}var MWe=new Set(["missing","unexpected-argument","incompatible-type"]);function w_(e,n,t){if(!MWe.has(rJ(n)))return[];let i=OWe(n)??t?.enclosingFrame;if(i===void 0)return[];let r=[],o=_t(DWe(e,i.name));if(o!==void 0&&o.length>1)r.push({message:`\`${i.name}\` has ${o.length} overloads: ${o.map(u=>`\`${Pve(u)}\``).join(", ")}`});else if(o!==void 0&&o.length===1){let u=$We(n,o[0],i.index);u!==void 0&&r.push({message:`\`${i.name}\` has signature \`${Pve(o[0])}\`${u}`})}let s=t?.definitionSites?.get(i.name);s!==void 0&&!LWe(s.name,t?.primaryRange)&&r.push({message:`\`${i.name}\` is defined here`,range:s.name});let a=PWe(e,n,i,t?.call,t?.boxedError);return a!==void 0&&r.push(a),r}function PWe(e,n,t,i,r){if(rJ(n)!=="incompatible-type")return;let o=P(n,1);if(L(o)!=="ErrorCode")return;let s=fe(P(o,3));if(s===null)return;let a=r?.ops?.[1];if(a!==void 0&&a.operator!=="ErrorTrace"){let d=a.symbol;return typeof d=="string"?Mve(d,a.valueDefinition?._typeProvenance,s):void 0}if(i===void 0)return;let u=[...G(i)][t.index-1]??null,l=u===null?null:Z(u);if(l===null)return;let f=e.lookupDefinition(l),c=f!==void 0&&"value"in f?f.value._typeProvenance:void 0;return Mve(l,c,s)}function Mve(e,n,t){if(n!==void 0)for(let i=n.length-1;i>=0;i--){let r=n[i];if(r.kind==="inferred"&&r.cause!==void 0&&r.type.toString()===t)return{message:`\`${e}\` was inferred to have type \`${t}\` from its use in \`${r.cause.toString()}\``}}}function rJ(e){let n=P(e,1);return n===null?"":L(n)==="ErrorCode"?fe(P(n,1))??"":fe(n)??""}function OWe(e){let n=hO(e)[0];if(n!==void 0)return n.name==="Block"||n.name==="Function"?void 0:n}function DWe(e,n){let t;try{t=e.lookupDefinition(n)}catch{return}if(t!==void 0)return"operator"in t?t.operator.signature.type:t.value.type.type}function $We(e,n,t){let i=n.args?.length??0,r=n.optArgs?.length??0,o=n.args?.[t-1]??n.optArgs?.[t-1-i]??void 0,s=o===void 0?"":` (\`${Ove(o)}\`)`;switch(rJ(e)){case"missing":return o===void 0?void 0:`; argument ${t}${s} was not supplied`;case"unexpected-argument":return n.variadicArg!==void 0?void 0:`; it takes ${FWe(i,r)}, so argument ${t} is extra`;default:return o===void 0?void 0:`; argument ${t} is \`${Ove(o)}\``}}function FWe(e,n){let t=i=>`${i} argument${i===1?"":"s"}`;return n>0?`${e} to ${t(e+n)}`:t(e)}function Pve(e){return ne({...e,args:e.args?.map(gO),optArgs:e.optArgs?.map(gO),variadicArg:e.variadicArg===void 0?void 0:gO(e.variadicArg)})}function gO(e){return e.name!==void 0&&ws(e.name)?{type:e.type}:e}function Ove(e){let n=gO(e);return n.name===void 0?ne(n.type):`${n.name}: ${ne(n.type)}`}function LWe(e,n){return n!==void 0&&e[0]<n[1]&&n[0]<e[1]}function Dve(e,n,t,i,r){Sc(e,n,r,i,t)}function Sc(e,n,t,i,r){let o=L(n);if(o!=="")switch(o){case"Block":{let s=new Map(t);for(let a of G(n))Sc(e,a,t,i,r);yO(t,s);return}case"Declare":{let s=G(n);for(let l of s.slice(1))Sc(e,l,t,i,r);if(s[0]===void 0)return;let a=Z(s[0]);if(a===null){for(let l of bO(s[0]))t.delete(l);return}let u=fe(s[1]);u!==null?t.set(a,u):t.delete(a);return}case"Function":{let[s,...a]=G(n),u=new Map(t);for(let l of a){if(L(l)==="Typed"){let f=Z(P(l,1)),c=fe(P(l,2));if(f!==null&&c!==null){t.set(f,c);continue}}for(let f of bO(l))t.delete(f)}s!==void 0&&Sc(e,s,t,i,r),yO(t,u);return}case"Loop":{let[s,a]=G(n);if(L(a)==="Element"){let[u,l]=G(a);l!==void 0&&Sc(e,l,t,i,r);let f=new Map(t);if(u!==void 0)for(let c of bO(u))t.delete(c);s!==void 0&&Sc(e,s,t,i,r),yO(t,f);return}for(let u of G(n))Sc(e,u,t,i,r);return}case"Match":{let[s,...a]=G(n);s!==void 0&&(BWe(e,n,s,a,t,i,r),Sc(e,s,t,i,r));for(let u of a){if(L(u)!=="MatchCase")continue;let[l,...f]=G(u),c=new Map(t),d=$ve(l);for(let p of d)t.delete(p);if(f.length===2)for(let p of Bve(f[0])){let m=Lve(p);m!==void 0&&d.includes(m.name)&&t.set(m.name,m.type)}for(let p of f)Sc(e,p,t,i,r);yO(t,c)}return}default:for(let s of G(n))Sc(e,s,t,i,r)}}function yO(e,n){e.clear();for(let[t,i]of n)e.set(t,i)}function bO(e){let n=Z(e);return n!==null?[n]:G(e).flatMap(bO)}function $ve(e){let n=Z(e);if(n!==null){if(!n.startsWith("_"))return[];let t=n.replace(/^_+/,"");return t===""?[]:[t]}return L(e)==="Pin"?[]:G(e).flatMap($ve)}function BWe(e,n,t,i,r,o,s){let a=Z(t);if(a===null)return;let u=r.get(a);if(u===void 0)return;let l=Vve(e,u);if(l===void 0)return;let f=new Set;for(let d of i){if(L(d)!=="MatchCase")continue;let p=G(d),m=p[0],g=p.length===3?p[1]:null;if(m===void 0)continue;let y=Fve(e,m,g,l);if(y==="all")return;for(let b of y)f.add(b)}let c=l.alternatives.filter(d=>!f.has(d.name));c.length!==0&&o.push({severity:"warning",message:["match-not-exhaustive",l.label,c.map(JWe).join(", ")],range:UWe(n)??[0,s.length]})}function Fve(e,n,t,i){if(t!==null&&Z(t)==="True"&&(t=null),t!==null){let a=qWe(n,t);if(a===void 0)return[];if(["any","unknown","expression"].includes(a.type.trim()))return"all";let u=Vve(e,a.type);return u===void 0?[]:u.alternatives.map(l=>l.name)}let r=Z(n);if(r!==null)return sJ(r)?"all":(r==="True"||r==="False")&&i.alternatives.some(a=>a.kind==="boolean"&&a.name===r)?[r]:[];let o=L(n);if(o==="Alternatives"){let a=[];for(let u of G(n)){let l=Fve(e,u,null,i);if(l==="all")return"all";a.push(...l)}return a}let s=i.alternatives.find(a=>a.kind==="variant"&&a.name===o);return s===void 0||s.kind!=="variant"?[]:VWe(G(n),s.arity)?[s.name]:[]}function VWe(e,n){let t=0,i=!1;for(let r of e){let o=Z(r);if(o===null)return!1;if(jWe(o)){if(i)return!1;i=!0}else if(sJ(o))t+=1;else return!1}return i?t<=n:t===n}function sJ(e){return e.startsWith("_")&&!e.startsWith("__")}function jWe(e){return e.startsWith("___")}function qWe(e,n){if(n===null)return;let t=Z(e);if(t===null||!sJ(t))return;let i=t.slice(1);if(i==="")return;let r=Lve(n);return r!==void 0&&r.name===i?r:void 0}function Lve(e){if(L(e)!=="MatchesType")return;let n=Z(P(e,1));if(n===null)return;let t=P(e,2);if(L(t)!=="TypeFrom")return;let i=fe(P(t,1));return i===null?void 0:{name:n,type:i}}function Bve(e){return L(e)!=="And"?[e]:G(e).flatMap(Bve)}function Vve(e,n){let t;try{t=e.type(n).type}catch{return}let i=jve(e,t,0);return i===void 0?void 0:{label:n,alternatives:i}}var zWe=8;function jve(e,n,t){if(n==="boolean")return[{kind:"boolean",name:"True"},{kind:"boolean",name:"False"}];if(typeof n=="object"){if(n.kind==="reference"){let i=vn(n);if(i._sumVariants!==void 0){let r=[];for(let o of i._sumVariants){let s=oJ(e,o.name);if(s===void 0)return;r.push(s)}return r}if(i._sumOf!==void 0){let r=oJ(e,i.name);return r===void 0?void 0:[r]}return i.alias&&i.def!==void 0&&t<zWe?jve(e,i.def,t+1):void 0}if(n.kind==="union"){let i=[],r=new Set;for(let o of n.types){if(typeof o!="object"||o.kind!=="reference")return;let s=vn(o);if(s._sumOf===void 0)return;let a=oJ(e,s.name);if(a===void 0)return;r.has(a.name)||(r.add(a.name),i.push(a))}return i.length===0?void 0:i}}}function oJ(e,n){let t=ul(e,n);return t===void 0?void 0:{kind:"variant",name:n,arity:t.arity}}function JWe(e){return e.kind==="boolean"?e.name==="True"?"true":"false":`${e.name}(${Array.from({length:e.arity},()=>"_").join(", ")})`}function UWe(e){if(typeof e!="object"||e===null||Array.isArray(e))return;let n=e.sourceOffsets;return Array.isArray(n)?[n[0],n[1]]:void 0}function Jve(e){return n=>ej(e,n)}function uJ(e){return Cpe(e)?"written":"declaration"}var qve=60,GWe=new Set(["variable-redeclaration","protocol-implementation-duplicate","argument-name-unknown","argument-order-invalid","argument-name-duplicate","argument-names-unavailable","argument-optional-skipped","argument-names-required","dot-call-not-a-protocol-function","callback-arity","pipe-stage-arity","no-product-between-points","no-division-by-point","incompatible-type","incompatible-dimensions","invalid-axis","invalid-symbol","missing","unexpected-argument","unexpected-mathjson","unexpected-operator"]);function HWe(e,n,t,i){let r=L(n),o=null,s=null;r==="DefineFunction"?(o=P(n,1),s=P(n,2)):r==="Declare"&&(o=P(n,1),s=ZWe(n));let a=Z(o);if(a===null||s===null||L(s)!=="Function")return;let u=zve(o)??zve(n);if(u===void 0)return;let l=WWe(e,a)??YWe(t),f=typeof l=="object"&&(l.kind==="signature"||l.kind==="union"||l.kind==="intersection")?wn(l)??[]:void 0,c={name:a,range:u,effects:f,declared:KWe(e,s)||XWe(e,n)},d=i.findIndex(p=>p.name===a);d<0?i.push(c):i[d]={...c,range:i[d].range,declared:i[d].declared||c.declared}}function WWe(e,n){let t=e.lookupDefinition(n);if(t===void 0)return;let i="operator"in t?t.operator.signature.type:t.value.type.type;return typeof i=="object"&&(i.kind==="signature"||i.kind==="union"||i.kind==="intersection")?i:void 0}function YWe(e){if(!h(e,"Declare"))return;let n=e.ops[e.ops.length-1],t=n!==void 0&&Ve(n)?n.get("value"):void 0;if(!(t===void 0||t.operator!=="Function"))return t.canonical.type.type}function Uve(e){for(let n of G(e).slice(1))if(L(n)==="Dictionary")return n;return null}function ZWe(e){let n=Uve(e);if(n===null)return null;for(let t of G(n)){if(L(t)!=="KeyValuePair")continue;let i=P(t,1);if(Z(i)==="value"||fe(i)==="value")return P(t,2)}return null}function Gve(e,n){if(Es(n))return!1;try{let t=re(n,e._typeResolver);return typeof t=="object"&&t.kind==="signature"&&t.effects!==void 0}catch{return!1}}function KWe(e,n){let t=P(n,1);if(t===null||L(t)!=="Typed")return!1;let i=fe(P(t,2));return i!==null&&Gve(e,i)}function XWe(e,n){if(L(n)!=="Declare")return!1;let t=null;for(let r of G(n).slice(1)){let o=fe(r);o!==null&&(t=o)}let i=Uve(n);if(t===null&&i!==null)for(let r of G(i)){if(L(r)!=="KeyValuePair")continue;let o=P(r,1);(Z(o)==="type"||fe(o)==="type")&&(t=fe(P(r,2)))}return t!==null&&Gve(e,t)}function zve(e){if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.sourceOffsets;if(Array.isArray(n)&&n.length===2&&typeof n[0]=="number"&&typeof n[1]=="number")return[n[0],n[1]]}function QWe(e){return GWe.has(e)||e.startsWith("expected-")}function Hve(e,n,t,i=[],r){let o=e._typeRegistryRollbackPoint(),s=e._protocolRegistryRollbackPoint();e._staticTypeCheckDepth+=1,e.pushScope(void 0,"epsil:static-check");let a=e._staticAssignmentEvidence;e._staticAssignmentEvidence=new Map,e._factSuppressionDepth+=1;try{return e._withBoxingPassWindow(()=>e._withRolledBackInference(()=>nYe(e,n,t,i,r?.effects)))}finally{e._staticAssignmentEvidence=a,e.popScope(),e._factSuppressionDepth-=1,e._staticTypeCheckDepth-=1,o(),s()}}function eYe(e,n,t){let i=e._staticAssignmentEvidence;if(i===void 0)return;let r,o;if(h(n,"Assign"))r=n.ops[0],o=n.ops[1];else if(h(n,"Declare")){r=n.ops[0];let l=n.ops.slice(1),f=l[l.length-1],c=Ve(f)?f:void 0,d=c===void 0?l:l.slice(0,-1),p=d.find(m=>J(m))??c?.get("type");if(p!==void 0){let m=J(p)?p.string:T(p)?p.symbol:null;if(r!==void 0&&T(r)&&m!==null){try{e.declare(r.symbol,m),t.add(r.symbol)}catch{}let g=d.find(y=>!J(y))??c?.get("value");if(g!==void 0&&g.operator!=="Function"){let y=g.canonical;if(y.isValid&&!y.type.isUnknown){let b=e.box(r.symbol).valueDefinition;if(b!==void 0&&(i.set(b,y._literalType??y.type.type),b._placeholderSkeleton!==void 0&&t.has(r.symbol))){let E=zb(b._placeholderSkeleton,y.type.type);E!==b.type.type&&b._setElementRefinement(e.type(E))}}}}return}o=d.find(m=>!J(m))??c?.get("value")}else return;if(r===void 0||o===void 0||o.operator==="Function"||(o=o.canonical,!o.isValid))return;let s=o.type;if(s.isUnknown)return;if(h(r,"Tuple")){let l=s.type;typeof l=="object"&&l.kind==="tuple"&&l.elements.length===r.nops&&r.ops.every(f=>T(f))&&r.ops.forEach((f,c)=>{let d=l.elements[c].type;if(d==="unknown"||!T(f))return;let p=e.box(f.symbol),m=p.valueDefinition;m!==void 0&&(p._infer(()=>nk(e,d),"replace"),i.set(m,d))});return}if(!T(r))return;let a=e.box(r.symbol),u=a.valueDefinition;if(u!==void 0){if(u._placeholderSkeleton!==void 0&&t.has(r.symbol)){let l=zb(u._placeholderSkeleton,s.type);l!==u.type.type&&u._setElementRefinement(e.type(l))}else a._infer(()=>LL(e,o).type,"replace");i.set(u,o._literalType??s.type)}}function nYe(e,n,t,i,r){let o=L(n)==="Block"?[...G(n)]:[n],s=mO(n),a=new Map,u=new Map,l=new Map,f=new Map,c=new Set,d=new Map;for(let p of o){let m=rYe(p,t,u);m!==void 0&&i.push(m);let g=oYe(p,t,f);g!==void 0&&i.push(g);let y=cYe(p),b,E,x=e._epsilDeclarationRoute;e._epsilDeclarationRoute=lJ(p);try{ae(e._deadlineFrame),E=e.box(p),b=E.json}catch(V){if(ql(V))throw V;continue}finally{e._epsilDeclarationRoute=x}Dve(e,p,t,i,d),m===void 0&&iYe(p,b,t,u),sYe(p,l);let S=aYe(e,p,E,t,l);S!==void 0&&i.push(S),r!==void 0&&m===void 0&&S===void 0&&HWe(e,p,E,r);let v=fYe(e,E);v===void 0&&uYe(e,E,a),v===void 0&&eYe(e,E,c);let w=[];wx(b,w);let _=new Map;{let V=[E];for(;V.length>0;){let U=V.pop();if(U.operator==="Error"){let $=JSON.stringify(U.json);_.has($)||_.set($,U)}let D=U.values;if(Array.isArray(D))for(let $=D.length-1;$>=0;$--)V.push(D[$]);let z=U.ops;if(z!==void 0)for(let $=z.length-1;$>=0;$--)V.push(z[$])}}if(w.length===0&&v===void 0)continue;let[C,k]=N_(p,t),M=aJ(p);v!==void 0&&i.push({severity:"error",message:["static-type-error",v,M,"incompatible-type"],range:[C,k,C]});let j=new Set;for(let V of w){let U=__(V);if(!QWe(U))continue;let D=EO(V),z=Yve(V),$=y.get(z);if($!==void 0&&$>0){y.set(z,$-1);continue}if(j.has(z))continue;j.add(z);let q=tJ(b,V),H=iJ(q===void 0?[]:[q],p,[C,k],ee=>ej(e,ee),uJ(U)),[K,Y]=H.range,de={severity:"error",message:["static-type-error",D,H.call===void 0?M:aJ(H.call),U],range:[K,Y,K]},X=w_(e,V,{definitionSites:s,primaryRange:[K,Y],enclosingFrame:q,call:H.call,boxedError:_.get(JSON.stringify(V))});if(X.length>0&&(de.notes=X),U==="incompatible-type"){let _e=_.get(JSON.stringify(V))?.ops?.[1],Qe=P(V,1),bn=Qe!==null&&L(Qe)==="ErrorCode"?_x([...G(Qe)][1]):void 0;if(_e!==void 0&&T(_e)&&bn!==void 0&&bn!==""){let nn=_e.valueDefinition,Hn=nn===void 0?void 0:e._staticAssignmentEvidence?.get(nn),Oe=re(bn,e._typeResolver);Hn!==void 0&&Oe!==void 0&&yo(Hn,Oe)&&!R(Hn,Oe)&&(de.notes??=[]).push({message:`the assignment gives \`${_e.symbol}\` the type \`${ne(Hn)}\`, which only POSSIBLY fits \`${bn}\` \u2014 annotate the declaration (\`let ${_e.symbol}: ${bn}\`) to state the contract and have each assignment checked against it`})}}i.push(de)}}return i}function Wve(e){switch(L(e)){case"DeclareType":{let n=Tx(P(e,1));return n===void 0?void 0:{kind:"type",names:[n]}}case"DeclareSumType":{let n=[...G(e)],t=Tx(n[0]??null);if(t===void 0)return;let i=[t];for(let r of n.slice(1)){if(L(r)!=="Tuple")continue;let o=Tx(P(r,1));o!==void 0&&i.push(o)}return{kind:"type",names:i}}case"DeclareProtocol":{let n=Tx(P(e,1));return n===void 0?void 0:{kind:"protocol",names:[n]}}default:return}}function Tx(e){if(e!==null)return fe(e)??Z(e)??void 0}function lJ(e){let n=L(e);return n==="DeclareType"||n==="DeclareSumType"||n==="DeclareProtocol"||n==="DeclareConformance"||n==="DefineFunction"}var tYe=new Set(["invalid-type-declaration","invalid-protocol-declaration","type-redefinition","protocol-redefinition"]);function iYe(e,n,t,i){let r=Wve(e);if(r===void 0)return;let o=[];if(wx(n,o),o.some(a=>tYe.has(__(a))))return;let s=N_(e,t);for(let a of r.names)i.set(`${r.kind} ${a}`,s)}function rYe(e,n,t){let i=Wve(e);if(i===void 0)return;let[r,o]=N_(e,n);for(let s of i.names){let a=t.get(`${i.kind} ${s}`);if(a!==void 0)return{severity:"error",message:[i.kind==="type"?"type-redefinition":"protocol-redefinition",s],range:[r,o,r],notes:[{message:`\`${s}\` is first declared here`,range:a}]}}}function oYe(e,n,t){let i=fJ(e);if(i.length===0)return;let r=N_(e,n),o=i.find(s=>t.has(s));if(o===void 0){for(let s of i)t.set(s,r);return}return{severity:"error",message:["variable-redeclaration",o],range:[r[0],r[1],r[0]],notes:[{message:`\`${o}\` is first declared here`,range:t.get(o)}]}}function fJ(e){if(L(e)!=="Declare")return[];let n=[],t=i=>{if(i===null)return;if(L(i)==="Tuple"){for(let o of G(i))t(o);return}let r=Z(i);r!=null&&r!=="_"&&r!=="Nothing"&&n.push(r)};return t(P(e,1)),n}function sYe(e,n){let t=L(e);if(t!=="Assign"&&t!=="Declare"||t==="Declare"&&P(e,2)===null)return;let i=Tx(P(e,1));i!==void 0&&n.delete(i)}function aYe(e,n,t,i,r){if(L(n)!=="DefineFunction")return;let o=Tx(P(n,1));if(o===void 0||!h(t,"DefineFunction"))return;let s=t.ops[1];if(!h(s,"Function"))return;let a=s.type.type;if(Fn(a))return;let u=fk(a),l=N_(n,i),f=r.get(o)??[],c=f.find(d=>k1(d.signature,u));if(c===void 0){C1(e.lookupDefinition(o))||(f.push({signature:u,range:l}),r.set(o,f));return}return{severity:"error",message:["function-redefinition",o],range:[l[0],l[1],l[0]],notes:[{message:`this clause of \`${o}\` is first defined here`,range:c.range}]}}function uYe(e,n,t){let i=null,r;if(h(n,"Assign")){let a=n.ops[0];i=T(a)?a.symbol:null;let u=i===null?void 0:t.get(i);if(u!==void 0){e.box(i)._infer(()=>u,"narrow");return}let l=n.ops[1];l!==void 0&&l.operator==="Function"&&(r=l.type.type)}else if(h(n,"Declare")){let a=n.ops[1];if(J(a)){let u=n.ops[0];i=T(u)?u.symbol:null;try{r=e.type(a.string).type}catch{return}}}if(i===null||r===void 0||!lYe(r)||t.has(i))return;let o=e.lookupDefinition(i);if(o!==void 0&&(!le(o)||o.value.isConstant||!o.value.inferredType&&!o.value.type.isUnknown||!o.value.type.isUnknown&&!$a(o.value.type.type)))return;let s=r;e.box(i)._infer(()=>s,"narrow")&&t.set(i,s)}function lYe(e){return typeof e=="string"||e.kind!=="signature"?!1:[...e.args??[],...e.optArgs??[]].some(n=>n.name!==void 0)}function fYe(e,n){if(!h(n,"Declare"))return;let t=n.ops[1];if(!J(t))return;let i=n.ops.find(f=>Ve(f));if(i===void 0||!Ve(i))return;let r=i.get("value");if(r===void 0||i.get("holdUntil")!==void 0)return;let o;try{o=e.type(t.string)}catch{return}if(o.isUnknown||r.type.isUnknown)return;let s=N(r)||J(r)||T(r,"True")||T(r,"False");if(J(r)&&D1(o.type)&&Op(r.string)||!(s?!r.type.matches(o):o.isDisjointFrom(r.type)))return;let u=`The value "${r.toString()}" of type "${r.type}" is not compatible with the declared type "${o}"`,l=a$(r,o);return l===void 0?u:`${u}. ${l}`}function cYe(e){let n=[];wx(e,n);let t=new Map;for(let i of n){let r=Yve(i);t.set(r,(t.get(r)??0)+1)}return t}function Yve(e){let n=P(e,1);return EO(n===null?e:["Error",n])}function wx(e,n){if(L(e)==="Error"){let t=[];for(let i of G(e))wx(i,t);n.push(...t.length>0?t:[e]);return}if(TN(e)){for(let t of Object.values(e.dict))wx(t,n);return}for(let t of G(e))wx(t,n)}function __(e){let n=P(e,1);return n===null?"error":L(n)==="ErrorCode"?_x(P(n,1)??"Nothing"):_x(n)}function EO(e){let n=P(e,1),t=P(e,2),i=L(t)==="ErrorTrace"?null:t,r="error",o=[];if(n!==null)if(L(n)==="ErrorCode"){let l=[...G(n)].map(_x);r=l[0]??r,o.push(...l.slice(1))}else r=_x(n);let s=i===null?"":_x(i),a=s===""?"":/^\d+$/.test(s)?`for argument ${s}`:s.length<=40?`at \`${s}\``:`\u2014 ${s}`,u;switch(r){case"expected-function":u=o.length>=2?a===""?`\`${o[0]}\`: expected a function, got \`${o[1]}\``:`expected a function, got \`${o[1]}\``:`expected a function (${o.join(", ")})`;break;case"incompatible-type":u=o.length===2?`expected \`${o[0]}\`, got \`${o[1]}\``:`incompatible type: ${o.join(", ")}`;break;case"missing":u=o.length===0?"a required argument is missing":`a required argument is missing (${o.join(", ")})`;break;case"unexpected-argument":return o.length===0?"unexpected argument":`unexpected argument \`${o.join(", ")}\``;case"callback-arity":return o.length===0?"the callback takes the wrong number of parameters":o.join(" ");case"pipe-stage-arity":return o.length===0?"the pipe stage takes the wrong number of parameters":o.join(" ");case"no-division-by-point":return"a point cannot be a divisor";case"no-product-between-points":{let l=o.slice(1).join(" ");return l===""?"no product is defined between points":`no product is defined between points; ${l}`}case"invalid-symbol":u=o.length===0?"invalid symbol":`invalid symbol \`${o.join(", ")}\``;break;case"protocol-function-not-a-field":{let l=(o[1]??"").split(", ").filter(d=>d!=="").map(d=>`\`${d}\``),f=l.length===1?"protocol":"protocols",c=o[2]==="assign"?" and cannot be assigned":l.length===1?`: call it as \`${o[0]}(x)\` or \`x.${o[0]}()\``:"; more than one applies here, so call it with a qualified name";u=o.length>=2&&l.length>0?`\`${o[0]}\` is a function member of the ${l.join(" and ")} ${f}, not a field${c}`:`a protocol function member is not a field (${o.join(", ")})`;break}case"dot-call-not-a-protocol-function":{let[l,f]=o;u=l===void 0?"only a protocol function can be called with a dot":`\`${l}\` is not a protocol function${f===void 0?"":` on a value of type \`${f}\``}: write \`${l}(x)\` or \`x |> ${l}\``;break}default:{let l=/^[a-z][a-z0-9-]*$/.test(r)?r.replaceAll("-"," "):r;u=o.length===0?l:`${l}: ${o.join(", ")}`}}return a===""?u:`${u} ${a}`}function _x(e){return fe(e)??aJ(e)}function aJ(e){let n;try{n=dO(e).replaceAll(/\s+/g," ").trim()}catch{return""}return n.length>qve?`${n.slice(0,qve-1)}\u2026`:n}function N_(e,n){return(typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0)??[0,n.length]}function dYe(e){let n={};for(let t of e._typeResolver.names){let i=e._typeResolver.resolve(t)?._sumOf;i!==void 0&&(n[t]=i)}return n}var pYe=0;function Xve(e,n,t){let i=e._epsilBatchId;e._epsilBatchId=++pYe;try{return mYe(e,n,t)}finally{e._epsilBatchId=i}}function mYe(e,n,t){let i=[],r;try{let[m,g]=lO(n,t?.url,{parseLatex:t?.parseLatex,allowHostPragmas:t?.allowHostPragmas??!1,typeNames:e._typeResolver.names,protocolNames:Object.keys(e._protocolRegistry),sumVariants:dYe(e),deadline:e._deadlineFrame});r=pO(m,n,e),i.push(...g)}catch(m){if(m instanceof mx)return i.push(Kve(["error-directive",m.message],[0,n.length])),{value:e.Nothing,diagnostics:i};if(ql(m))return{value:e.box(["Error",{str:m instanceof Error?m.message:"Timeout exceeded"},{str:"timeout"}]),diagnostics:i,valueRange:[0,n.length]};throw m}let o=L(r)==="Block"?[...G(r)]:[r],s=mO(r),a=!1;if(!i.some(m=>m.severity==="error"))try{Hve(e,r,n,i)}catch(m){if(!ql(m))throw m;a=!0}if(!a&&!i.some(m=>m.severity==="error")){let m=new Set;for(let g of o)n1e(e,g,m,i,g,n)}let u=e.Nothing,l,f=new Set,c=new Set;for(let m=0;m<o.length;m++){let g=o[m],y;l=rh(g,n);let b;Qve(e,g,f,i,g,n);let E=e._epsilDeclarationRoute;e._epsilDeclarationRoute=lJ(g);try{ae(e._deadlineFrame),b=hYe(g,c),u=b===void 0?e.box(g).evaluate():e.error(["variable-redeclaration",b]);let S=u.errors;S.length>0&&(l=Zve(e,S[0].json,g,l))}catch(S){let v=S instanceof Error?S.message:String(S);y=TYe(S),u=y!==void 0?e.box(["Error",{str:v},{str:y}]):e.box(["Error",{str:v}])}finally{e._epsilDeclarationRoute=E}let x=b!==void 0&&i.some(S=>Array.isArray(S.message)&&S.message[0]==="variable-redeclaration"&&S.message[1]===b);if(m<o.length-1&&!x){let S=u.errors;if(S.length>0){let v=gYe(S[0].json),w=EO(S[0].json),_=Zve(e,S[0].json,g,rh(g,n)),C=Kve(y!==void 0?["evaluation-canceled",y,S[0].toString()]:["runtime-error",w,v,__(S[0].json)],_),k=w_(e,S[0].json,{definitionSites:s,primaryRange:_,boxedError:S[0]});k.length>0&&(C.notes=k),i.push(C)}}if(y==="timeout")break;t1e(e,u.json,f,i,g,n)}let d=EYe(o,n);for(let m of Object.values(e._protocolRegistry))for(let g of m.conformances)g.pending&&i.push({severity:"warning",message:["protocol-implementation-pending",g.targetKey,m.name,g._pendingReason??""],range:xYe(d,g.targetKey,m.name)??[0,n.length]});let p=u.errors.length>0?w_(e,u.errors[0].json,{definitionSites:s,primaryRange:l,boxedError:u.errors[0]}):[];return{value:u,diagnostics:i,...l===void 0?{}:{valueRange:l},...p.length===0?{}:{valueNotes:p}}}function hYe(e,n){let t=fJ(e),i=t.find(r=>n.has(r));if(i!==void 0)return i;for(let r of t)n.add(r)}function gYe(e){let n=[...G(e)],t=n[n.length-1];if(t===void 0||L(t)!=="ErrorTrace")return"";let i=[];for(let r of G(t)){if(L(r)==="ErrorBroadcast"){let a=fe(P(r,1)),u=Se(P(r,2)),l=Se(P(r,3));if(a===null||u===null||l===null)continue;i.push(`while applying ${a} element-wise over ${l} element${l===1?"":"s"} (element ${u})`);continue}if(L(r)!=="ErrorFrame")continue;let o=fe(P(r,1)),s=Se(P(r,2));o===null||s===null||o==="Block"||o==="Function"||i.push(`in ${o} argument ${s}`)}return i.join(", ")}function Zve(e,n,t,i){return Rve(hO(n),t,i,Jve(e),uJ(__(n)))}function Qve(e,n,t,i,r,o,s=new Set){let a=L(n);if(a==="")return;if(!t.has(a)&&!s.has(a)&&e.operatorInfo(a)===void 0&&!yYe(e,a)){let l=vYe(e,a);l!==void 0&&(t.add(a),i.push({severity:"warning",message:["protocol-property-not-callable",a,l],range:e1e(n)??rh(r,o)}))}let u=a==="Function"?bYe(n,s):s;for(let l of G(n))Qve(e,l,t,i,r,o,u)}function yYe(e,n){let t=e.lookupDefinition(n);return t===void 0?!1:"value"in t?t.value.type.matches("function"):!0}function bYe(e,n){let t=new Set(n),i=[...G(e)].slice(1),r=o=>{let s=Z(o);s!=null&&t.add(s);for(let a of G(o))r(a)};for(let o of i)r(o);return t}function EYe(e,n){let t=[];for(let i of e){if(L(i)!=="DeclareConformance")continue;let r=fe(P(i,1))??Z(P(i,1));if(r==null)continue;let o=fe(P(i,3)),s=o===null||o===""?void 0:o,a=rh(i,n);for(let u of G(P(i,2)??"Nothing")){let l=Z(u)??fe(u);l!=null&&t.push({target:r,protocol:l,clause:s,range:a})}}return t}function xYe(e,n,t){let i=e.filter(r=>r.protocol===t&&(r.clause===void 0?n===r.target:n.startsWith(`${r.target} where `)));return i.length===1?i[0].range:void 0}function vYe(e,n){for(let t of Object.values(e._protocolRegistry)){let i=t.members[n]?.kind;if(i==="readonly"||i==="readwrite")return t.name}}function e1e(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0}function rh(e,n){return e1e(e)??[0,n.length]}var SYe=new Set(["println","printf","puts","echo"]);function n1e(e,n,t,i,r,o){if(L(n)==="Function")for(let s of G(n).slice(1)){let a=Z(s)??(L(s)==="Typed"?Z(P(s,1)):null);if(a===null||a.length<=1||t.has(a)||ws(a))continue;let u=e.lookupDefinition(a),l=e.contextStack[0]?.lexicalScope;u!==void 0&&l!==void 0&&l.bindings.get(a)===u&&"value"in u&&u.value?.isConstant===!0&&(t.add(a),i.push({severity:"warning",message:["parameter-shadows-constant",a],range:rh(r,o)}))}for(let s of G(n))n1e(e,s,t,i,r,o)}function t1e(e,n,t,i,r,o){let s=L(n);if(s!==""){if(!t.has(s)&&e.operatorInfo(s)===void 0)if(t.add(s),e._typeResolver.resolve(s)!==void 0)i.push({severity:"warning",message:["type-not-callable",s],range:rh(r,o)});else if(SYe.has(s.toLowerCase()))i.push({severity:"warning",message:["print-not-available",s],range:rh(r,o)});else{let a=e.suggestOperatorName(s),u=a===void 0?void 0:S_(a)??a;u!==void 0&&u!==s&&i.push({severity:"warning",message:["unknown-function",s,u],range:rh(r,o)})}for(let a of G(n))t1e(e,a,t,i,r,o)}}function TYe(e){if(!(e instanceof Error)||e.name!=="CancellationError")return;let n=e.cause;if(n==="timeout"||n==="iteration-limit-exceeded"||n==="recursion-depth-exceeded")return n}function Kve(e,n){return{severity:"error",message:e,range:n}}var wYe="0.129.0";return l1e(_Ye);})();
1899
+ `).map(se=>t.text(`/// ${se}`)),oe):oe}return ee(B)},Match:B=>{let W=Kd(B);if(W!==null)return W;let Q=P(B,1),ie=G(B).slice(1),oe=t.line("match ",i(Q)," {");return ie.length===0?t.line("match ",i(Q)," {}"):t.stack(oe,t.indent(t.stack(...ie.map(S))),t.text("}"))},MatchCase:B=>S(B),Pin:B=>v(B),Alternatives:B=>v(B)};function S(B){let W=G(B),Q=v(W[0]??"Nothing"),ie=W.length>=3,oe=ie?W[1]:null,se=ie?W[2]:W[1],he=[Q];return oe!=null&&he.push(" if ",i(oe)),he.push(n?.fancySymbols?" \u21D2 ":" => ",i(se??"Nothing")),t.line(...he)}function v(B,W){let Q=L(B);if(Q==="Pin")return t.line("== ",i(P(B,1)));if(Q==="Alternatives"){let se=G(B),he=[];return se.forEach((Ce,tn)=>{tn>0&&he.push(" | "),he.push(v(Ce,W))}),t.line(...he)}if(Q==="Range"&&G(B).length===2)return t.line(v(P(B,1)??"Nothing",W),t.infixOperator(".."),v(P(B,2)??"Nothing",W));if(Q==="List")return t.fencedList("[",t.separator(","),"]",G(B).map(se=>v(se,W)));if(Q==="Tuple")return t.fencedList("(",t.separator(","),")",G(B).map(se=>v(se,W)));if(Q==="Dictionary"){let se=G(B);return se.length===0?t.line(t.fence("{"),t.relationalOperator("->"),t.fence("}")):t.fencedList("{",t.separator(","),"}",se.map(he=>t.line(i(P(he,1)),t.relationalOperator("->"),v(P(he,2)??"Nothing",W))))}let ie=Z(B);if(ie!==null){if(ie==="_")return t.text("_");if(ie==="True")return t.text("true");if(ie==="False")return t.text("false");if(ie.startsWith("___"))return t.text("..."+ie.slice(3));if(ie.startsWith("_")){let se=ie.slice(1),he=W?.get(se);return t.text(he===void 0?Ri(se):Ri(se)+": "+he)}return t.line("== ",t.text(Ri(ie)))}if(l(B))return t.text(rd(B,vx));if(typeof B=="object"&&B!==null&&"str"in B)return s(B.str);let oe=typeof B=="string"&&/^'[\s\S]*'$/.test(B)?fe(B):null;return oe!==null?s(oe):i(w(B))}function w(B){let W=Z(B);if(W!==null)return W!=="_"&&!W.startsWith("___")&&W.startsWith("_")?{sym:W.slice(1)}:B;let Q=L(B);return Q?{fn:[Q,...G(B).map(w)]}:B}let _=B=>{if(B===null)return null;let W=fe(B);return W!==null?W:Z(B)},C=B=>{let W={typeParams:null,argTypes:[],decomposed:!1},Q=P(B,1);if(L(Q)!=="Typed")return{bodyExpr:Q,retType:null,specifier:null,...W};let ie=P(Q,1),oe=_(P(Q,2));if(oe!==null&&!Es(oe))try{let se=re(oe,Xz);if(typeof se!="string"&&se.kind==="signature"){let he=wn(se),Ce=se.typeParams??[],tn=se.result;return{bodyExpr:ie,retType:tn==="unknown"||tn==="any"?null:xh(tn),specifier:he!==void 0?Ks(he):null,typeParams:Ce.length>0?Ce.map(Dn=>Dn.bound!==void 0?`${Dn.name}: ${ne(Dn.bound)}`:Dn.name).join(", "):null,argTypes:Ce.length>0?(se.args??[]).map(Dn=>Dn.type):[],decomposed:!0}}}catch{}return{bodyExpr:ie,retType:oe,specifier:null,...W}},k={oo:"Infinity","+oo":"Infinity","-oo":"-Infinity",Infinity:"Infinity","+Infinity":"Infinity","-Infinity":"-Infinity",NaN:"NaN",nan:"NaN"},M=B=>/^-?[0-9.]/.test(B)||B.startsWith('"')||B==="true"||B==="false"||B in k,j=B=>{let W=[];for(let Q of G(B)){if(L(Q)==="Tuple"){let oe=j(Q);if(oe===null)return null;W.push(oe);continue}let ie=Z(Q);if(ie===null)return null;W.push(Ri(ie))}return`(${W.join(", ")})`},V=B=>L(B)==="Spread"&&Te(B)===1&&Z(P(B,1))!==null,U=B=>B.every((W,Q)=>L(W)==="Spread"?V(W)&&Q===B.length-1:L(W)!=="Tuple"||j(W)!==null),D=(B,W,Q)=>{if(L(B)==="Tuple")return t.text(j(B)??"");if(V(B))return t.text(`...${Ri(Z(P(B,1)))}`);let ie=L(B)==="Typed",oe=ie?Z(P(B,1)):Z(B),se=(ie?_(P(B,2)):null)??(W!==void 0&&W!=="unknown"?ne(W):null);if(oe!==null&&ws(oe)&&se!==null&&M(se)){if(se.startsWith('"')&&se.endsWith('"')){let tn=se.slice(1,-1).replace(/\\(["\\])/g,"$1");return t.text(`"${v_(tn)}"`)}return t.text(k[se]??se)}let he=oe!==null?Ri(oe):"",Ce=oe!==null&&Q!==void 0&&Q.has(oe)?"bind ":"";return t.text(se!==null?`${Ce}${he}: ${se}`:`${Ce}${he}`)},z=(B,W=[],Q)=>t.fencedList("(",t.separator(","),")",B.map((ie,oe)=>D(ie,W[oe],Q))),$=B=>{let W=G(B).slice(1),Q=P(B,1),ie=W.some(Dn=>L(Dn)==="Typed"),oe=L(Q)==="Typed";if(!U(W))return ee(B);let se=W.some(Dn=>L(Dn)==="Tuple"),he=W.some(Dn=>L(Dn)==="Spread");if(!ie&&!oe&&!se&&!he)return ee(B);let{bodyExpr:Ce,decomposed:tn}=C(B);if(tn)return ee(B);let Be=n?.fancySymbols?"\u21D2":"=>";return t.line(z(W),` ${Be} `,i(Ce))},q=(B,W,Q)=>o(0,()=>H(B,W,Q)),H=(B,W,Q)=>{let ie=G(Q).slice(1);if(!U(ie))return null;let{bodyExpr:oe,retType:se,specifier:he,argTypes:Ce}=C(Q),tn=he!==null?` ${he}`:"",Be=se!==null?` -> ${se}`:"";return t.line(`${B} ${Ri(W)}`,z(ie,Ce),`${tn}${Be} `,t.fencedList("{",t.separator(";"),"}",L(oe)==="Block"?xr(oe,i):[i(oe)]))},K=(B,W,Q={})=>o(0,()=>Y(B,W,Q)),Y=(B,W,Q)=>{let ie=Z(B),oe=ie!==null?Ri(ie):"",se=G(W).slice(1),{bodyExpr:he,retType:Ce,specifier:tn,typeParams:Be,argTypes:Dn}=C(W),ds=[...tn!==null?[tn]:[],...Q.algebraic??[]],Tc=ds.length>0?ds.join(" "):null,Nx=Tc!==null?` ${Tc}`:"",$y=Ce!==null?` -> ${Ce}`:"",xO=Q.bind!==void 0?new Set(Q.bind):void 0,vO=Q.hold?"hold ":"",cJ=Be!==null?`<${Be}>`:"";if(L(he)==="Block")return t.line(`${vO}function ${oe}${cJ}`,z(se,Dn,xO),`${Nx}${$y} `,t.fencedList("{",t.separator(";"),"}",xr(he,i)));if(Be!==null)return t.line(`${vO}function ${oe}${cJ}`,z(se,Dn,xO),`${Nx}${$y} `,t.fencedList("{",t.separator(";"),"}",[i(he)]));let i1e=Ce!==null?$y:Tc!==null?" -> unknown":"";return t.line(`${vO}${oe}`,z(se,void 0,xO),`${Nx}${i1e} = `,i(he))};function de(B){if(B===null)return null;let W=Sx(B);if(W===null)return null;let Q={},ie=oe=>(Z(oe)??fe(oe))==="True";for(let oe of Object.keys(W)){let se=W[oe];if(se!=null)switch(oe){case"hold":if(!ie(se))return null;Q.hold=!0;break;case"commutative":case"associative":case"idempotent":case"involution":if(!ie(se))return null;(Q.algebraic??=[]).push(oe);break;case"bind":{let he=L(se)==="List"?G(se):Array.isArray(se)?se:[se],Ce=[];for(let tn of he){let Be=fe(tn)??Z(tn);if(Be===null)return null;Ce.push(Be)}Q.bind=Ce;break}case"description":{let he=fe(se);if(he===null)return null;Q.description=he;break}default:return null}}return Q}function X(B){return x[L(B)]?.(B)??null}function ee(B){let W=L(B);return W?t.line(Ri(W),t.fencedList("(",t.separator(","),")",xr(B,i))):t.line("Apply(",i(W),t.separator(","),t.fencedList("[",t.separator(","),"]",xr(B,i)),")")}function _e(B,W){let Q=co(W);return Q.length===0?t.text(B+"{}"):t.choice(t.line(B,Qe(W)),t.stack(t.text(B+"{"),t.indent(t.stack(...Q)),t.text("}")))}function Qe(B){let W=co(B);if(W.length===0)return t.text("{}");let Q=[];return W.forEach((ie,oe)=>{oe>0&&Q.push(t.separator(";")),Q.push(ie)}),t.line(t.fence("{"),...Q,t.fence("}"))}function bn(B,W){let Q=u[L(B)];return Q&&Q.precedence<W?t.line("(",i(B),")"):i(B)}let nn=B=>B!==null&&L(B)==="Block";function Hn(B){let W=[],Q=B;for(;;){let ie;if(L(Q)==="If"){let se=Te(Q);if(se!==2&&se!==3)return null;let he=P(Q,1),Ce=P(Q,2);if(ie=se===3?P(Q,3):null,he===null||Ce===null||!nn(Ce))return null;W.push({head:()=>bn(he,wu+1),body:Ce})}else{let se=On(Q);if(se===null)return null;let{pattern:he,typed:Ce,subject:tn,body:Be}=se;W.push({head:()=>t.line("let ",v(he,Ce)," = ",bn(tn,wu+1)),body:Be}),ie=se.fallback}if(ie===null)return{clauses:W,elseBody:null};if(nn(ie))return{clauses:W,elseBody:ie};let oe=L(ie);if(oe!=="If"&&oe!=="Match")return null;Q=ie}}function Oe(B){if(L(B)!=="Match"||Te(B)!==3)return null;let W=P(B,1),Q=P(B,2),ie=P(B,3);if(W===null||Q===null||ie===null||L(Q)!=="MatchCase")return null;let oe=Te(Q);if(oe!==2&&oe!==3)return null;let se=P(Q,1),he=oe===3?P(Q,2):null,Ce=P(Q,oe);if(se===null||Ce===null||!nn(Ce))return null;let tn=Ca(se,he);if(tn===null||L(ie)!=="MatchCase"||Te(ie)!==2||Z(P(ie,1))!=="_")return null;let Be=P(ie,2);return Be===null?null:{subject:W,pattern:se,typed:tn,body:Ce,fallbackBody:Be}}function On(B){let W=Oe(B);if(W===null)return null;let{subject:Q,pattern:ie,typed:oe,body:se,fallbackBody:he}=W,Ce;if(Z(he)==="Missing")Ce=null;else if(nn(he)||L(he)==="If"||L(he)==="Match")Ce=he;else return null;return{subject:Q,pattern:ie,typed:oe,body:se,fallback:Ce}}function ct(B){let W=Oe(B);if(W===null)return null;let{subject:Q,pattern:ie,typed:oe,body:se,fallbackBody:he}=W;return L(he)!=="Break"||Te(he)!==0?null:{subject:Q,pattern:ie,typed:oe,body:se}}function Ca(B,W){let Q=new Map;if(W===null)return Q;let ie=L(W)==="And"?G(W):[W];for(let oe of ie){if(L(oe)!=="MatchesType"||Te(oe)!==2)return null;let se=Z(P(oe,1)),he=P(oe,2);if(se===null||L(he)!=="TypeFrom"||Te(he)!==1)return null;let Ce=fe(P(he,1));if(Ce===null||Q.has(se)||!$o(Ce)||Fl(B,se)!==1)return null;Q.set(se,Ce)}return Q}function $o(B){if(/[\r\n\u2028\u2029]/.test(B))return!1;try{return re(B,Xz),!0}catch{return!1}}function Fl(B,W){if(Z(B)==="_"+W)return 1;let Q=L(B);return Q==="List"||Q==="Tuple"?G(B).reduce((ie,oe)=>ie+Fl(oe,W),0):Q==="Dictionary"?G(B).reduce((ie,oe)=>ie+Fl(P(oe,2)??"Nothing",W),0):0}let co=B=>xr(B,i)??[];function Kd(B){let W=Hn(B);if(W===null)return null;let{clauses:Q,elseBody:ie}=W,oe=[];Q.forEach(({head:tn,body:Be},Dn)=>{oe.push(Dn===0?"if ":" else if "),oe.push(tn()," ",Qe(Be))}),ie!==null&&oe.push(" else ",Qe(ie));let se=t.line(...oe),he=[],Ce=tn=>{let Be=co(tn);Be.length>0&&he.push(t.indent(t.stack(...Be)))};return Q.forEach(({head:tn,body:Be},Dn)=>{he.push(t.line(Dn===0?"if ":"} else if ",tn()," {")),Ce(Be)}),ie!==null&&(he.push(t.text("} else {")),Ce(ie)),he.push(t.text("}")),t.choice(se,t.stack(...he))}function Bt(B){let W=Kd(B);if(W!==null)return W;if(Te(B)!==3)return null;let Q=P(B,1),ie=P(B,2),oe=P(B,3);return Q===null||ie===null||oe===null||nn(ie)||nn(oe)?null:t.line(bn(ie,wu+1)," if ",bn(Q,wu+1)," else ",bn(oe,wu))}function He(B,W){let Q=co(W);return Q.length===0?t.line(B," {}"):t.choice(t.line(B," ",Qe(W)),t.stack(t.line(B," {"),t.indent(t.stack(...Q)),t.text("}")))}function Kn(B){if(!nn(B)||Te(B)!==2)return null;let W=P(B,1),Q=P(B,2);if(W===null||Q===null||!nn(Q)||L(W)!=="If"||Te(W)!==2)return null;let ie=P(W,1),oe=P(W,2);if(L(ie)!=="Not"||Te(ie)!==1||L(oe)!=="Break"||Te(oe)!==0)return null;let se=P(ie,1);return se===null?null:{cond:se,body:Q}}function ht(B){let W=ie=>bn(ie,wu+1),Q=G(B);if(Q.length===2){let[ie,oe]=Q;if(!nn(ie)||L(oe)!=="Element"||Te(oe)!==2)return null;let se=P(oe,1),he=P(oe,2);if(se===null||he===null)return null;let Ce;if(L(se)==="Tuple")Ce=j(se);else{let Be=Z(se);Ce=Be===null?null:Ri(Be)}if(Ce===null)return null;let tn=t.line("for ",Ce," in ",W(he));return o(r+1,()=>He(tn,ie))}if(Q.length===1){let ie=Kn(Q[0]);if(ie!==null){let se=t.line("while ",W(ie.cond));return o(r+1,()=>He(se,ie.body))}let oe=ct(Q[0]);if(oe!==null){let{pattern:se,typed:he,subject:Ce,body:tn}=oe,Be=t.line("while let ",v(se,he)," = ",W(Ce));return o(r+1,()=>He(Be,tn))}}return null}function yi(B){let W=L(B);if(!W)return null;let Q=u[W];if(!Q)return null;if(W==="MapsTo"&&r!==0)return o(0,()=>yi(B));let ie=n?.fancySymbols?Q.fancySymbol??Q.symbol:Q.symbol;if(Q.unary){if(Te(B)!==1)return null;let se=P(B,1),he=L(se),Ce=u[he];return Ce&&Ce.precedence<Q.precedence?t.line(ie,"(",i(se),")"):t.line(ie,i(se))}if(Q.postfix){if(Te(B)!==1)return null;let se=P(B,1),he=L(se),Ce=u[he];return Ce&&Ce.precedence<=Q.precedence||f(se)||b(se)!==null?t.line("(",i(se),")",ie):t.line(i(se),ie)}let oe=G(B).map((se,he)=>p(se,Q,W,he===0?"left":"right")?t.line("(",i(se),")"):i(se));return oe.length===0?null:t.list(Q.relational?t.relationalOperator(ie):t.infixOperator(ie),oe)}return L(e)==="Block"&&Te(e)>=2?t.stack(...xr(e,i)).serialize(0):i(e).serialize(0)}function Tve(e){return typeof e=="boolean"?e?"True":"False":e}function gWe(e){let n="tuple<";if(!e.startsWith(n)||!e.endsWith(">"))return null;let t=0;for(let i=n.length;i<e.length;i++){let r=e[i];if(r==="-"&&e[i+1]===">"){i+=1;continue}if(r==="<"||r==="("||r==="[")t+=1;else if(r===">"||r===")"||r==="]"){if(t===0)return r===">"&&i===e.length-1?e.slice(n.length,i):null;t-=1}}return null}function Sx(e){if(e===null)return null;let n=Object.create(null);if(typeof e=="object"&&!Array.isArray(e)&&"dict"in e&&typeof e.dict=="object"&&e.dict!==null){for(let[t,i]of Object.entries(e.dict))n[t]=Tve(i);return n}if(L(e)!=="Dictionary")return null;for(let t of G(e)){if(L(t)!=="KeyValuePair")return null;let i=fe(P(t,1))??Z(P(t,1));if(i===null)return null;n[i]=P(t,2)??"Nothing"}return n}function yWe(e){return e.startsWith("-")?e.slice(1):e.startsWith("+")?"-"+e.slice(1):"-"+e}function bWe(e,n){return!(!/^\d[\d_]*(\.\d[\d_]*)?$/.test(e)||Ri(n)!==n||!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(n)||/^[eE]/.test(n)||e==="0"&&/^[bBxX]/.test(n))}function Sve(e){return QP.has(e)?QP.get(e):Dz(e)?e<65536?`\\u${("0000"+e.toString(16)).slice(-4)}`:`\\u{${("000000000"+e.toString(16)).slice(-8)}}`:String.fromCodePoint(e)}function v_(e){let n="",t=Xv(e);if(typeof t=="string")for(let i of t)n+=Sve(i.codePointAt(0));else for(let i of t)i.length===1?n+=Sve(i.codePointAt(0)):n+=i;return n}function Ri(e){if(Zd.has(e))return`\`${e}\``;if(e==="let")return`\`${e}\``;if(/^[a-zA-Z][a-zA-Z\d_]*$/.test(e))return e;let n=e.codePointAt(0);if(Na.has(n))return`\`${v_(e)}\``;let t=!1,i=Xv(e),r=0;for(;!t&&r<i.length;){let o=i[r].codePointAt(0);t=QP.has(o)||Dz(o)||px(o),r+=1}return t?`\`${v_(e)}\``:e}var EWe=new Set(["Alternatives","Annotated","At","Block","Colon","Comprehension","Condition","Declare","DeclareConformance","DeclareProtocol","DeclareSumType","DeclareType","DefineFunction","Delimiter","Hold","HoldValues","HorizontalSpacing","IndexedSequence","InvisibleOperator","Latex","LatexString","Loop","MatchCase","MatchesType","MemberCall","NamedArgument","OverParen","Pair","PreDecrement","PreIncrement","ReleaseHold","Rule","Sequence","Single","Spread","Square","Subscript","Text","Triple","Typed","Unevaluated","Which","Wildcard","WildcardOptionalSequence","WildcardSequence"]),xWe=new Set(["Dictionary","List","Set","String","Tuple"]),vWe=new Set(["Approx","ApproxEqual","ApproxNotEqual","NotApprox","NotApproxEqual","NotApproxNotEqual","NotGreater","NotGreaterNotEqual","NotLess","NotLessNotEqual","NotPrecedes","NotSubset","NotSucceeds","NotSuperset","NotSupersetEqual","NotTilde","NotTildeEqual","NotTildeFullEqual","PlusMinus","Precedes","Succeeds","Tilde","TildeEqual","TildeFullEqual"]),SWe=new Set(["BuiltinFunction","ContinuationPlaceholder","ErrorCode","Object","Pin","Predicate","ProtocolMember","ProtocolProperty","RuntimeError","Signature","Subtype"]),TWe=new Set(["True","False","NaN"]),wWe=new Set(bx.map(e=>e.name));function _We(e){let n=/^([A-Z]+)(.*)$/s.exec(e);if(n===null)return;let[,t,i]=n;return t.length===1?t.toLowerCase()+i:/^[a-z]/.test(i)?t.slice(0,-1).toLowerCase()+t.slice(-1)+i:t.toLowerCase()+i}function S_(e){if(e.length<=1)return;let n=_We(e);if(n!==void 0&&!wWe.has(e)&&!Zd.has(n)&&!(EWe.has(e)||xWe.has(e)||vWe.has(e)||SWe.has(e)||TWe.has(e)))return n}var Qz;function eJ(){if(Qz!==void 0)return Qz;let e=new Map;for(let n of cy){let t=n.definitions;if(t===void 0)continue;let i=Array.isArray(t)?t:[t];for(let r of i)for(let o of Object.keys(r)){let s=S_(o);s!==void 0&&(!e.has(s)||e.get(s),`${s}${e.get(s)}${o}`,e.set(s,o))}}return Qz=e,e}function T_(e){return eJ().get(e)}var wve={definition:0,write:1,read:2};function _ve(e,n,t){let i=[],r=new Map,o={span:[0,n.length],bindings:new Map,parent:void 0};function s(v){return typeof v=="object"&&v!==null&&!Array.isArray(v)?v.sourceOffsets:void 0}function a(v,w){if(w[0]<0||w[1]>n.length||w[0]>=w[1])return!1;let _=n.slice(w[0],w[1]);if(_===v||_==="`"+v+"`")return!0;if(_.length>v.length+8)return!1;let C=oO(_).filter(k=>k.type!=="EOF");return C.length===1&&C[0].start===0&&C[0].end===_.length&&(C[0].type==="SYMBOL"||C[0].type==="VERBATIM_SYMBOL")&&(C[0].value??C[0].text)===v}function u(v,w){return{span:v??w.span,bindings:new Map,parent:w}}function l(v,w,_,C,k){let M=v.bindings.get(w);if(M!==void 0)return M;let j={name:w,kind:_,occurrences:[],...C===void 0?{}:{declaration:C},scope:v.span,visibleFrom:k};return i.push(j),v.bindings.set(w,j),j}function f(v,w,_,C){for(let M=_;M!==void 0;M=M.parent){let j=M.bindings.get(v);if(j!==void 0&&w[0]>=j.visibleFrom){j.occurrences.push({start:w[0],end:w[1],role:C});return}}let k=r.get(v);k===void 0&&(k={name:v,kind:"free",occurrences:[],scope:o.span,visibleFrom:0},r.set(v,k),i.push(k)),k.occurrences.push({start:w[0],end:w[1],role:C})}function c(v){let w=v===null?null:Z(v);if(w===null||w==="_")return;let _=s(v);if(!(_===void 0||!a(w,_)))return{name:w,span:_}}function d(v,w,_,C,k){if(v===null)return;let M=L(v);if(M===""){let j=c(v);if(j===void 0)return;l(w,j.name,_,C,k).occurrences.push({start:j.span[0],end:j.span[1],role:"definition"});return}if(M==="Typed"){d(P(v,1),w,_,C,k);return}if(M==="Tuple"){for(let j of G(v))d(j,w,_,C,k);return}b(v,w)}function p(v,w){if(v===null)return;let _=L(v);if(_!==""){if(_==="Typed"){p(P(v,1),w);return}for(let M of G(v))p(M,w);return}let C=Z(v);if(C===null||/^_+$/.test(C))return;let k=s(v);if(k!==void 0){if(C.startsWith("___")){let M=C.slice(3),j=[k[0]+3,k[1]];n.slice(k[0],k[0]+3)==="..."&&a(M,j)&&l(w,M,"pattern",k,w.span[0]).occurrences.push({start:j[0],end:j[1],role:"definition"});return}if(C.startsWith("_")&&a(C.slice(1),k)){l(w,C.slice(1),"pattern",k,w.span[0]).occurrences.push({start:k[0],end:k[1],role:"definition"});return}a(C,k)&&f(C,k,w,"read")}}function m(v,w,_){let C=c(P(v,1));if(C===void 0)return;let k=s(v)??C.span,M=l(w,C.name,"function",k,w.span[0]);M.declaration!==void 0&&(M.declaration=[Math.min(M.declaration[0],k[0]),Math.max(M.declaration[1],k[1])]),_&&M.occurrences.push({start:C.span[0],end:C.span[1],role:"definition"})}function g(v,w){for(let _ of v)_!==null&&L(_)==="DefineFunction"&&m(_,w,!1)}function y(v,w){let _=u(s(v),w),C=[...G(v)];for(let k=1;k<C.length;k++)d(C[k],_,"parameter",void 0,_.span[0]);b(C[0]??null,_)}function b(v,w){if(v===null)return;let _=L(v);if(_===""){let C=c(v);C!==void 0&&f(C.name,C.span,w,"read");return}switch(_){case"Block":{let C=u(s(v),w),k=[...G(v)];g(k,C);for(let M of k)b(M,C);return}case"Declare":{let C=[...G(v)];for(let M=1;M<C.length;M++)b(C[M],w);let k=s(v);d(C[0]??null,w,"variable",k,k?.[1]??w.span[0]);return}case"Assign":{let C=[...G(v)];for(let k=1;k<C.length;k++)b(C[k],w);x(C[0]??null,w,s(v));return}case"DefineFunction":{m(v,w,!0);let C=P(v,2);C!==null&&L(C)==="Function"?y(C,w):b(C,w),b(P(v,3),w);return}case"Function":y(v,w);return;case"Loop":{let C=P(v,2);if(C!==null&&L(C)==="Element"){b(P(C,2),w);let k=u(s(v),w);d(P(C,1),k,"loop",s(C),k.span[0]),b(P(v,1),k);return}for(let k of G(v))b(k,w);return}case"Match":{b(P(v,1),w);let C=[...G(v)];for(let k=1;k<C.length;k++){let M=C[k];if(M!==null&&L(M)==="MatchCase"){let j=u(s(M),w),V=[...G(M)];p(V[0]??null,j);for(let U=1;U<V.length;U++)b(V[U],j)}else b(M,w)}return}case"DeclareType":case"DeclareSumType":case"DeclareProtocol":{let C=c(P(v,1));C!==void 0&&l(w,C.name,"type",s(v)??C.span,w.span[0]).occurrences.push({start:C.span[0],end:C.span[1],role:"definition"});return}case"KeyValuePair":case"NamedArgument":{let C=[...G(v)];for(let k=1;k<C.length;k++)b(C[k],w);return}case"Typed":{b(P(v,1),w);return}default:{typeof _=="string"?E(v,_,w):b(_,w);let C=s(v),k=typeof _=="string"&&t?.binderSites!==void 0&&S(w,_,C?.[0]??w.span[0])===void 0?t.binderSites(v):void 0;if(k!==void 0&&k.length>0){let M=new Map;[...G(v)].forEach((j,V)=>{let U=k.filter(z=>z.operands==="all"||z.operands.includes(V));if(U.length===0){b(j,w);return}let D=u(C,w);for(let z of U){let $=M.get(z.name);$===void 0?M.set(z.name,l(D,z.name,"parameter",void 0,D.span[0])):D.bindings.set(z.name,$)}b(j,D)});return}for(let M of G(v))b(M,w);return}}}function E(v,w,_){if(w===""||w==="_")return;let C=s(v);if(C===void 0)return;let k=[C[0],C[0]+w.length];if(k[1]<=C[1]&&a(w,k)){f(w,k,_,"read");return}let M=[C[0],C[0]+w.length+2];M[1]<=C[1]&&n.slice(M[0],M[1])==="`"+w+"`"&&f(w,M,_,"read")}function x(v,w,_){if(v===null)return;let C=L(v);if(C==="Tuple"){for(let M of G(v))x(M,w,_);return}if(C==="Typed"){x(P(v,1),w,_);return}let k=c(v);if(k!==void 0){S(w,k.name,k.span[0])!==void 0?f(k.name,k.span,w,"write"):d(v,w,"variable",_,_?.[1]??w.span[0]);return}b(v,w)}function S(v,w,_){for(let C=v;C!==void 0;C=C.parent){let k=C.bindings.get(w);if(k!==void 0&&_>=k.visibleFrom)return k}}if(e!==null)if(L(e)==="Block"){let v=[...G(e)];g(v,o);for(let w of v)b(w,o)}else g([e],o),b(e,o);for(let v of i)v.occurrences.sort((w,_)=>w.start-_.start||w.end-_.end||wve[w.role]-wve[_.role]),v.occurrences=v.occurrences.filter((w,_,C)=>_===0||C[_-1].start!==w.start||C[_-1].end!==w.end);return i.sort((v,w)=>(v.occurrences[0]?.start??0)-(w.occurrences[0]?.start??0)),i}function NWe(e,n){let t=e;for(let i of n){if(t===null)return;t=G(t)[i]??null}return t===null?void 0:Z(t)??void 0}function Nve(e,n){return e===null?!1:Z(e)===n?!0:L(e)===""?!1:G(e).some(i=>Nve(i,n))}function Cve(e,n){if(e===null)return!1;let t=L(e);return t===""?!1:t===n?!0:G(e).some(i=>Cve(i,n))}var CWe=new Set(["List","Set","Tuple","Pair","Triple"]);function kWe(e,n,t){let i=L(n);if(i==="")return;let r=n.sourceOffsets,s=r!==void 0&&t[r[0]]==="`"||e.lookupDefinition(i)!==void 0?i:T_(i)??i,a=e.lookupDefinition(s);if(a===void 0||!("operator"in a))return;let u=[...G(n)],l=[],f=new Set,c=a.operator.bindingSites;if(c!==void 0){let d;try{d=u.map(p=>e.box(p,{form:"raw"}))}catch{d=void 0}if(d!==void 0){let p=c(d,"pre"),m=Math.min(...p.filter(g=>g.clauseLocal).map(g=>g.path[0]));for(let g of p){let y=NWe(n,g.path);if(y===void 0||f.has(y))continue;f.add(y);let b=g.path[0];l.push({name:y,operands:g.clauseLocal?u.map((E,x)=>x).filter(E=>E<m||E>=b):"all"})}}}return u.forEach((d,p)=>{let m=[],g=Z(d);if(g!==null)m.push(g);else if(CWe.has(L(d)))for(let y of G(d)){let b=Z(y);b!==null&&m.push(b)}for(let y of m)f.has(y)||y==="_"||!u.some((E,x)=>x!==p&&Nve(E,y))||u.some(E=>Cve(E,y))||(f.add(y),l.push({name:y,operands:"all"}))}),l}function pO(e,n,t){let i=_ve(e,n,{binderSites:u=>kWe(t,u,n)}),r=new Map,o=(u,l)=>`${u}:${l}`;for(let u of i){if(u.kind!=="free")continue;let l=T_(u.name);if(l!==void 0&&t.lookupDefinition(u.name)===void 0)for(let f of u.occurrences)n[f.start]!=="`"&&r.set(o(f.start,u.name),l)}if(r.size===0)return e;let s=u=>u.sourceOffsets,a=u=>{if(u===null||typeof u!="object")return;if(Array.isArray(u)){for(let f of u)a(f);return}let l=s(u);if("sym"in u){let f=l===void 0?void 0:r.get(o(l[0],u.sym));f!==void 0&&(u.sym=f);return}if("fn"in u){let f=u.fn,c=f[0];if(typeof c=="string"){let d=l===void 0?void 0:r.get(o(l[0],c));d!==void 0&&(f[0]=d)}else a(c);for(let d=1;d<f.length;d++)a(f[d]);return}if("dict"in u)for(let f of Object.values(u.dict))a(f)};return a(e),e}function mO(e){let n=new Map;return kve(e,(t,i)=>{n.has(t)||n.set(t,i)}),n}function kve(e,n){if(e===null)return;let t=L(e);if(t!==""){if(t==="DefineFunction"||t==="Declare"||t==="Assign"){let i=P(e,1),r=Z(i),o=nJ(i),s=nJ(e);if(r!==null&&o!==void 0){let a=t==="DefineFunction"?RWe(e):void 0;n(r,{name:o,header:IWe(e,t,s??o),...a!==void 0?{description:a}:{}})}}for(let i of G(e))kve(i,n)}}function IWe(e,n,t){if(n!=="DefineFunction")return t;let i=nJ(P(P(e,2),1));return i===void 0?t:[t[0],i[0]]}function RWe(e){let n=P(e,3);if(n!==null){if(typeof n=="object"&&!Array.isArray(n)&&"dict"in n&&typeof n.dict=="object"&&n.dict!==null){let t=n.dict.description;return typeof t=="string"?t:void 0}if(L(n)==="Dictionary"){for(let t of G(n))if(!(L(t)!=="KeyValuePair"||(Z(P(t,1))??fe(P(t,1)))!=="description"))return fe(P(t,2))??void 0}}}function nJ(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0}function hO(e){let n=[...G(e)],t=n[n.length-1];if(t===void 0||L(t)!=="ErrorTrace")return[];let i=[];for(let r of G(t)){if(L(r)!=="ErrorFrame")continue;let o=fe(P(r,1)),s=Se(P(r,2));o===null||s===null||i.push({name:o,index:s})}return i}function tJ(e,n){let t=L(e);if(t==="")return;let i=0;for(let r of G(e)){if(i+=1,r===n)return{name:t,index:i};let o=tJ(r,n);if(o!==void 0)return o}}function iJ(e,n,t,i,r="declaration"){for(let{name:o,index:s}of e){let a=[];if(Ave(n,o,a),a.length!==1)continue;let u=AWe([...G(a[0])],s-1,o,r,i),l=Ive(u)??Ive(a[0]);if(l!==void 0)return{range:l,call:a[0]}}return{range:t}}function AWe(e,n,t,i,r){if(i==="written"||!e.some(a=>L(a)==="NamedArgument"))return e[n]??null;let o=r?.(t);if(o===void 0)return null;let s=0;for(let a of e){if(L(a)!=="NamedArgument"){if(s===n)return a;s+=1;continue}let u=fe(P(a,1));if(u!==null&&o.indexOf(u)===n)return a}return null}function Rve(e,n,t,i,r="declaration"){return iJ(e,n,t,i,r).range}function Ave(e,n,t){if(!(e===null||t.length>1)&&L(e)!==""){L(e)===n&&t.push(e);for(let i of G(e))Ave(i,n,t)}}function Ive(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0}var MWe=new Set(["missing","unexpected-argument","incompatible-type"]);function w_(e,n,t){if(!MWe.has(rJ(n)))return[];let i=OWe(n)??t?.enclosingFrame;if(i===void 0)return[];let r=[],o=_t(DWe(e,i.name));if(o!==void 0&&o.length>1)r.push({message:`\`${i.name}\` has ${o.length} overloads: ${o.map(u=>`\`${Pve(u)}\``).join(", ")}`});else if(o!==void 0&&o.length===1){let u=$We(n,o[0],i.index);u!==void 0&&r.push({message:`\`${i.name}\` has signature \`${Pve(o[0])}\`${u}`})}let s=t?.definitionSites?.get(i.name);s!==void 0&&!LWe(s.name,t?.primaryRange)&&r.push({message:`\`${i.name}\` is defined here`,range:s.name});let a=PWe(e,n,i,t?.call,t?.boxedError);return a!==void 0&&r.push(a),r}function PWe(e,n,t,i,r){if(rJ(n)!=="incompatible-type")return;let o=P(n,1);if(L(o)!=="ErrorCode")return;let s=fe(P(o,3));if(s===null)return;let a=r?.ops?.[1];if(a!==void 0&&a.operator!=="ErrorTrace"){let d=a.symbol;return typeof d=="string"?Mve(d,a.valueDefinition?._typeProvenance,s):void 0}if(i===void 0)return;let u=[...G(i)][t.index-1]??null,l=u===null?null:Z(u);if(l===null)return;let f=e.lookupDefinition(l),c=f!==void 0&&"value"in f?f.value._typeProvenance:void 0;return Mve(l,c,s)}function Mve(e,n,t){if(n!==void 0)for(let i=n.length-1;i>=0;i--){let r=n[i];if(r.kind==="inferred"&&r.cause!==void 0&&r.type.toString()===t)return{message:`\`${e}\` was inferred to have type \`${t}\` from its use in \`${r.cause.toString()}\``}}}function rJ(e){let n=P(e,1);return n===null?"":L(n)==="ErrorCode"?fe(P(n,1))??"":fe(n)??""}function OWe(e){let n=hO(e)[0];if(n!==void 0)return n.name==="Block"||n.name==="Function"?void 0:n}function DWe(e,n){let t;try{t=e.lookupDefinition(n)}catch{return}if(t!==void 0)return"operator"in t?t.operator.signature.type:t.value.type.type}function $We(e,n,t){let i=n.args?.length??0,r=n.optArgs?.length??0,o=n.args?.[t-1]??n.optArgs?.[t-1-i]??void 0,s=o===void 0?"":` (\`${Ove(o)}\`)`;switch(rJ(e)){case"missing":return o===void 0?void 0:`; argument ${t}${s} was not supplied`;case"unexpected-argument":return n.variadicArg!==void 0?void 0:`; it takes ${FWe(i,r)}, so argument ${t} is extra`;default:return o===void 0?void 0:`; argument ${t} is \`${Ove(o)}\``}}function FWe(e,n){let t=i=>`${i} argument${i===1?"":"s"}`;return n>0?`${e} to ${t(e+n)}`:t(e)}function Pve(e){return ne({...e,args:e.args?.map(gO),optArgs:e.optArgs?.map(gO),variadicArg:e.variadicArg===void 0?void 0:gO(e.variadicArg)})}function gO(e){return e.name!==void 0&&ws(e.name)?{type:e.type}:e}function Ove(e){let n=gO(e);return n.name===void 0?ne(n.type):`${n.name}: ${ne(n.type)}`}function LWe(e,n){return n!==void 0&&e[0]<n[1]&&n[0]<e[1]}function Dve(e,n,t,i,r){Sc(e,n,r,i,t)}function Sc(e,n,t,i,r){let o=L(n);if(o!=="")switch(o){case"Block":{let s=new Map(t);for(let a of G(n))Sc(e,a,t,i,r);yO(t,s);return}case"Declare":{let s=G(n);for(let l of s.slice(1))Sc(e,l,t,i,r);if(s[0]===void 0)return;let a=Z(s[0]);if(a===null){for(let l of bO(s[0]))t.delete(l);return}let u=fe(s[1]);u!==null?t.set(a,u):t.delete(a);return}case"Function":{let[s,...a]=G(n),u=new Map(t);for(let l of a){if(L(l)==="Typed"){let f=Z(P(l,1)),c=fe(P(l,2));if(f!==null&&c!==null){t.set(f,c);continue}}for(let f of bO(l))t.delete(f)}s!==void 0&&Sc(e,s,t,i,r),yO(t,u);return}case"Loop":{let[s,a]=G(n);if(L(a)==="Element"){let[u,l]=G(a);l!==void 0&&Sc(e,l,t,i,r);let f=new Map(t);if(u!==void 0)for(let c of bO(u))t.delete(c);s!==void 0&&Sc(e,s,t,i,r),yO(t,f);return}for(let u of G(n))Sc(e,u,t,i,r);return}case"Match":{let[s,...a]=G(n);s!==void 0&&(BWe(e,n,s,a,t,i,r),Sc(e,s,t,i,r));for(let u of a){if(L(u)!=="MatchCase")continue;let[l,...f]=G(u),c=new Map(t),d=$ve(l);for(let p of d)t.delete(p);if(f.length===2)for(let p of Bve(f[0])){let m=Lve(p);m!==void 0&&d.includes(m.name)&&t.set(m.name,m.type)}for(let p of f)Sc(e,p,t,i,r);yO(t,c)}return}default:for(let s of G(n))Sc(e,s,t,i,r)}}function yO(e,n){e.clear();for(let[t,i]of n)e.set(t,i)}function bO(e){let n=Z(e);return n!==null?[n]:G(e).flatMap(bO)}function $ve(e){let n=Z(e);if(n!==null){if(!n.startsWith("_"))return[];let t=n.replace(/^_+/,"");return t===""?[]:[t]}return L(e)==="Pin"?[]:G(e).flatMap($ve)}function BWe(e,n,t,i,r,o,s){let a=Z(t);if(a===null)return;let u=r.get(a);if(u===void 0)return;let l=Vve(e,u);if(l===void 0)return;let f=new Set;for(let d of i){if(L(d)!=="MatchCase")continue;let p=G(d),m=p[0],g=p.length===3?p[1]:null;if(m===void 0)continue;let y=Fve(e,m,g,l);if(y==="all")return;for(let b of y)f.add(b)}let c=l.alternatives.filter(d=>!f.has(d.name));c.length!==0&&o.push({severity:"warning",message:["match-not-exhaustive",l.label,c.map(JWe).join(", ")],range:UWe(n)??[0,s.length]})}function Fve(e,n,t,i){if(t!==null&&Z(t)==="True"&&(t=null),t!==null){let a=qWe(n,t);if(a===void 0)return[];if(["any","unknown","expression"].includes(a.type.trim()))return"all";let u=Vve(e,a.type);return u===void 0?[]:u.alternatives.map(l=>l.name)}let r=Z(n);if(r!==null)return sJ(r)?"all":(r==="True"||r==="False")&&i.alternatives.some(a=>a.kind==="boolean"&&a.name===r)?[r]:[];let o=L(n);if(o==="Alternatives"){let a=[];for(let u of G(n)){let l=Fve(e,u,null,i);if(l==="all")return"all";a.push(...l)}return a}let s=i.alternatives.find(a=>a.kind==="variant"&&a.name===o);return s===void 0||s.kind!=="variant"?[]:VWe(G(n),s.arity)?[s.name]:[]}function VWe(e,n){let t=0,i=!1;for(let r of e){let o=Z(r);if(o===null)return!1;if(jWe(o)){if(i)return!1;i=!0}else if(sJ(o))t+=1;else return!1}return i?t<=n:t===n}function sJ(e){return e.startsWith("_")&&!e.startsWith("__")}function jWe(e){return e.startsWith("___")}function qWe(e,n){if(n===null)return;let t=Z(e);if(t===null||!sJ(t))return;let i=t.slice(1);if(i==="")return;let r=Lve(n);return r!==void 0&&r.name===i?r:void 0}function Lve(e){if(L(e)!=="MatchesType")return;let n=Z(P(e,1));if(n===null)return;let t=P(e,2);if(L(t)!=="TypeFrom")return;let i=fe(P(t,1));return i===null?void 0:{name:n,type:i}}function Bve(e){return L(e)!=="And"?[e]:G(e).flatMap(Bve)}function Vve(e,n){let t;try{t=e.type(n).type}catch{return}let i=jve(e,t,0);return i===void 0?void 0:{label:n,alternatives:i}}var zWe=8;function jve(e,n,t){if(n==="boolean")return[{kind:"boolean",name:"True"},{kind:"boolean",name:"False"}];if(typeof n=="object"){if(n.kind==="reference"){let i=vn(n);if(i._sumVariants!==void 0){let r=[];for(let o of i._sumVariants){let s=oJ(e,o.name);if(s===void 0)return;r.push(s)}return r}if(i._sumOf!==void 0){let r=oJ(e,i.name);return r===void 0?void 0:[r]}return i.alias&&i.def!==void 0&&t<zWe?jve(e,i.def,t+1):void 0}if(n.kind==="union"){let i=[],r=new Set;for(let o of n.types){if(typeof o!="object"||o.kind!=="reference")return;let s=vn(o);if(s._sumOf===void 0)return;let a=oJ(e,s.name);if(a===void 0)return;r.has(a.name)||(r.add(a.name),i.push(a))}return i.length===0?void 0:i}}}function oJ(e,n){let t=ul(e,n);return t===void 0?void 0:{kind:"variant",name:n,arity:t.arity}}function JWe(e){return e.kind==="boolean"?e.name==="True"?"true":"false":`${e.name}(${Array.from({length:e.arity},()=>"_").join(", ")})`}function UWe(e){if(typeof e!="object"||e===null||Array.isArray(e))return;let n=e.sourceOffsets;return Array.isArray(n)?[n[0],n[1]]:void 0}function Jve(e){return n=>ej(e,n)}function uJ(e){return Cpe(e)?"written":"declaration"}var qve=60,GWe=new Set(["variable-redeclaration","protocol-implementation-duplicate","argument-name-unknown","argument-order-invalid","argument-name-duplicate","argument-names-unavailable","argument-optional-skipped","argument-names-required","dot-call-not-a-protocol-function","callback-arity","pipe-stage-arity","no-product-between-points","no-division-by-point","incompatible-type","incompatible-dimensions","invalid-axis","invalid-symbol","missing","unexpected-argument","unexpected-mathjson","unexpected-operator"]);function HWe(e,n,t,i){let r=L(n),o=null,s=null;r==="DefineFunction"?(o=P(n,1),s=P(n,2)):r==="Declare"&&(o=P(n,1),s=ZWe(n));let a=Z(o);if(a===null||s===null||L(s)!=="Function")return;let u=zve(o)??zve(n);if(u===void 0)return;let l=WWe(e,a)??YWe(t),f=typeof l=="object"&&(l.kind==="signature"||l.kind==="union"||l.kind==="intersection")?wn(l)??[]:void 0,c={name:a,range:u,effects:f,declared:KWe(e,s)||XWe(e,n)},d=i.findIndex(p=>p.name===a);d<0?i.push(c):i[d]={...c,range:i[d].range,declared:i[d].declared||c.declared}}function WWe(e,n){let t=e.lookupDefinition(n);if(t===void 0)return;let i="operator"in t?t.operator.signature.type:t.value.type.type;return typeof i=="object"&&(i.kind==="signature"||i.kind==="union"||i.kind==="intersection")?i:void 0}function YWe(e){if(!h(e,"Declare"))return;let n=e.ops[e.ops.length-1],t=n!==void 0&&Ve(n)?n.get("value"):void 0;if(!(t===void 0||t.operator!=="Function"))return t.canonical.type.type}function Uve(e){for(let n of G(e).slice(1))if(L(n)==="Dictionary")return n;return null}function ZWe(e){let n=Uve(e);if(n===null)return null;for(let t of G(n)){if(L(t)!=="KeyValuePair")continue;let i=P(t,1);if(Z(i)==="value"||fe(i)==="value")return P(t,2)}return null}function Gve(e,n){if(Es(n))return!1;try{let t=re(n,e._typeResolver);return typeof t=="object"&&t.kind==="signature"&&t.effects!==void 0}catch{return!1}}function KWe(e,n){let t=P(n,1);if(t===null||L(t)!=="Typed")return!1;let i=fe(P(t,2));return i!==null&&Gve(e,i)}function XWe(e,n){if(L(n)!=="Declare")return!1;let t=null;for(let r of G(n).slice(1)){let o=fe(r);o!==null&&(t=o)}let i=Uve(n);if(t===null&&i!==null)for(let r of G(i)){if(L(r)!=="KeyValuePair")continue;let o=P(r,1);(Z(o)==="type"||fe(o)==="type")&&(t=fe(P(r,2)))}return t!==null&&Gve(e,t)}function zve(e){if(e===null||typeof e!="object"||Array.isArray(e))return;let n=e.sourceOffsets;if(Array.isArray(n)&&n.length===2&&typeof n[0]=="number"&&typeof n[1]=="number")return[n[0],n[1]]}function QWe(e){return GWe.has(e)||e.startsWith("expected-")}function Hve(e,n,t,i=[],r){let o=e._typeRegistryRollbackPoint(),s=e._protocolRegistryRollbackPoint();e._staticTypeCheckDepth+=1,e.pushScope(void 0,"epsil:static-check");let a=e._staticAssignmentEvidence;e._staticAssignmentEvidence=new Map,e._factSuppressionDepth+=1;try{return e._withBoxingPassWindow(()=>e._withRolledBackInference(()=>nYe(e,n,t,i,r?.effects)))}finally{e._staticAssignmentEvidence=a,e.popScope(),e._factSuppressionDepth-=1,e._staticTypeCheckDepth-=1,o(),s()}}function eYe(e,n,t){let i=e._staticAssignmentEvidence;if(i===void 0)return;let r,o;if(h(n,"Assign"))r=n.ops[0],o=n.ops[1];else if(h(n,"Declare")){r=n.ops[0];let l=n.ops.slice(1),f=l[l.length-1],c=Ve(f)?f:void 0,d=c===void 0?l:l.slice(0,-1),p=d.find(m=>J(m))??c?.get("type");if(p!==void 0){let m=J(p)?p.string:T(p)?p.symbol:null;if(r!==void 0&&T(r)&&m!==null){try{e.declare(r.symbol,m),t.add(r.symbol)}catch{}let g=d.find(y=>!J(y))??c?.get("value");if(g!==void 0&&g.operator!=="Function"){let y=g.canonical;if(y.isValid&&!y.type.isUnknown){let b=e.box(r.symbol).valueDefinition;if(b!==void 0&&(i.set(b,y._literalType??y.type.type),b._placeholderSkeleton!==void 0&&t.has(r.symbol))){let E=zb(b._placeholderSkeleton,y.type.type);E!==b.type.type&&b._setElementRefinement(e.type(E))}}}}return}o=d.find(m=>!J(m))??c?.get("value")}else return;if(r===void 0||o===void 0||o.operator==="Function"||(o=o.canonical,!o.isValid))return;let s=o.type;if(s.isUnknown)return;if(h(r,"Tuple")){let l=s.type;typeof l=="object"&&l.kind==="tuple"&&l.elements.length===r.nops&&r.ops.every(f=>T(f))&&r.ops.forEach((f,c)=>{let d=l.elements[c].type;if(d==="unknown"||!T(f))return;let p=e.box(f.symbol),m=p.valueDefinition;m!==void 0&&(p._infer(()=>nk(e,d),"replace"),i.set(m,d))});return}if(!T(r))return;let a=e.box(r.symbol),u=a.valueDefinition;if(u!==void 0){if(u._placeholderSkeleton!==void 0&&t.has(r.symbol)){let l=zb(u._placeholderSkeleton,s.type);l!==u.type.type&&u._setElementRefinement(e.type(l))}else a._infer(()=>LL(e,o).type,"replace");i.set(u,o._literalType??s.type)}}function nYe(e,n,t,i,r){let o=L(n)==="Block"?[...G(n)]:[n],s=mO(n),a=new Map,u=new Map,l=new Map,f=new Map,c=new Set,d=new Map;for(let p of o){let m=rYe(p,t,u);m!==void 0&&i.push(m);let g=oYe(p,t,f);g!==void 0&&i.push(g);let y=cYe(p),b,E,x=e._epsilDeclarationRoute;e._epsilDeclarationRoute=lJ(p);try{ae(e._deadlineFrame),E=e.box(p),b=E.json}catch(V){if(ql(V))throw V;continue}finally{e._epsilDeclarationRoute=x}Dve(e,p,t,i,d),m===void 0&&iYe(p,b,t,u),sYe(p,l);let S=aYe(e,p,E,t,l);S!==void 0&&i.push(S),r!==void 0&&m===void 0&&S===void 0&&HWe(e,p,E,r);let v=fYe(e,E);v===void 0&&uYe(e,E,a),v===void 0&&eYe(e,E,c);let w=[];wx(b,w);let _=new Map;{let V=[E];for(;V.length>0;){let U=V.pop();if(U.operator==="Error"){let $=JSON.stringify(U.json);_.has($)||_.set($,U)}let D=U.values;if(Array.isArray(D))for(let $=D.length-1;$>=0;$--)V.push(D[$]);let z=U.ops;if(z!==void 0)for(let $=z.length-1;$>=0;$--)V.push(z[$])}}if(w.length===0&&v===void 0)continue;let[C,k]=N_(p,t),M=aJ(p);v!==void 0&&i.push({severity:"error",message:["static-type-error",v,M,"incompatible-type"],range:[C,k,C]});let j=new Set;for(let V of w){let U=__(V);if(!QWe(U))continue;let D=EO(V),z=Yve(V),$=y.get(z);if($!==void 0&&$>0){y.set(z,$-1);continue}if(j.has(z))continue;j.add(z);let q=tJ(b,V),H=iJ(q===void 0?[]:[q],p,[C,k],ee=>ej(e,ee),uJ(U)),[K,Y]=H.range,de={severity:"error",message:["static-type-error",D,H.call===void 0?M:aJ(H.call),U],range:[K,Y,K]},X=w_(e,V,{definitionSites:s,primaryRange:[K,Y],enclosingFrame:q,call:H.call,boxedError:_.get(JSON.stringify(V))});if(X.length>0&&(de.notes=X),U==="incompatible-type"){let _e=_.get(JSON.stringify(V))?.ops?.[1],Qe=P(V,1),bn=Qe!==null&&L(Qe)==="ErrorCode"?_x([...G(Qe)][1]):void 0;if(_e!==void 0&&T(_e)&&bn!==void 0&&bn!==""){let nn=_e.valueDefinition,Hn=nn===void 0?void 0:e._staticAssignmentEvidence?.get(nn),Oe=re(bn,e._typeResolver);Hn!==void 0&&Oe!==void 0&&yo(Hn,Oe)&&!R(Hn,Oe)&&(de.notes??=[]).push({message:`the assignment gives \`${_e.symbol}\` the type \`${ne(Hn)}\`, which only POSSIBLY fits \`${bn}\` \u2014 annotate the declaration (\`let ${_e.symbol}: ${bn}\`) to state the contract and have each assignment checked against it`})}}i.push(de)}}return i}function Wve(e){switch(L(e)){case"DeclareType":{let n=Tx(P(e,1));return n===void 0?void 0:{kind:"type",names:[n]}}case"DeclareSumType":{let n=[...G(e)],t=Tx(n[0]??null);if(t===void 0)return;let i=[t];for(let r of n.slice(1)){if(L(r)!=="Tuple")continue;let o=Tx(P(r,1));o!==void 0&&i.push(o)}return{kind:"type",names:i}}case"DeclareProtocol":{let n=Tx(P(e,1));return n===void 0?void 0:{kind:"protocol",names:[n]}}default:return}}function Tx(e){if(e!==null)return fe(e)??Z(e)??void 0}function lJ(e){let n=L(e);return n==="DeclareType"||n==="DeclareSumType"||n==="DeclareProtocol"||n==="DeclareConformance"||n==="DefineFunction"}var tYe=new Set(["invalid-type-declaration","invalid-protocol-declaration","type-redefinition","protocol-redefinition"]);function iYe(e,n,t,i){let r=Wve(e);if(r===void 0)return;let o=[];if(wx(n,o),o.some(a=>tYe.has(__(a))))return;let s=N_(e,t);for(let a of r.names)i.set(`${r.kind} ${a}`,s)}function rYe(e,n,t){let i=Wve(e);if(i===void 0)return;let[r,o]=N_(e,n);for(let s of i.names){let a=t.get(`${i.kind} ${s}`);if(a!==void 0)return{severity:"error",message:[i.kind==="type"?"type-redefinition":"protocol-redefinition",s],range:[r,o,r],notes:[{message:`\`${s}\` is first declared here`,range:a}]}}}function oYe(e,n,t){let i=fJ(e);if(i.length===0)return;let r=N_(e,n),o=i.find(s=>t.has(s));if(o===void 0){for(let s of i)t.set(s,r);return}return{severity:"error",message:["variable-redeclaration",o],range:[r[0],r[1],r[0]],notes:[{message:`\`${o}\` is first declared here`,range:t.get(o)}]}}function fJ(e){if(L(e)!=="Declare")return[];let n=[],t=i=>{if(i===null)return;if(L(i)==="Tuple"){for(let o of G(i))t(o);return}let r=Z(i);r!=null&&r!=="_"&&r!=="Nothing"&&n.push(r)};return t(P(e,1)),n}function sYe(e,n){let t=L(e);if(t!=="Assign"&&t!=="Declare"||t==="Declare"&&P(e,2)===null)return;let i=Tx(P(e,1));i!==void 0&&n.delete(i)}function aYe(e,n,t,i,r){if(L(n)!=="DefineFunction")return;let o=Tx(P(n,1));if(o===void 0||!h(t,"DefineFunction"))return;let s=t.ops[1];if(!h(s,"Function"))return;let a=s.type.type;if(Fn(a))return;let u=fk(a),l=N_(n,i),f=r.get(o)??[],c=f.find(d=>k1(d.signature,u));if(c===void 0){C1(e.lookupDefinition(o))||(f.push({signature:u,range:l}),r.set(o,f));return}return{severity:"error",message:["function-redefinition",o],range:[l[0],l[1],l[0]],notes:[{message:`this clause of \`${o}\` is first defined here`,range:c.range}]}}function uYe(e,n,t){let i=null,r;if(h(n,"Assign")){let a=n.ops[0];i=T(a)?a.symbol:null;let u=i===null?void 0:t.get(i);if(u!==void 0){e.box(i)._infer(()=>u,"narrow");return}let l=n.ops[1];l!==void 0&&l.operator==="Function"&&(r=l.type.type)}else if(h(n,"Declare")){let a=n.ops[1];if(J(a)){let u=n.ops[0];i=T(u)?u.symbol:null;try{r=e.type(a.string).type}catch{return}}}if(i===null||r===void 0||!lYe(r)||t.has(i))return;let o=e.lookupDefinition(i);if(o!==void 0&&(!le(o)||o.value.isConstant||!o.value.inferredType&&!o.value.type.isUnknown||!o.value.type.isUnknown&&!$a(o.value.type.type)))return;let s=r;e.box(i)._infer(()=>s,"narrow")&&t.set(i,s)}function lYe(e){return typeof e=="string"||e.kind!=="signature"?!1:[...e.args??[],...e.optArgs??[]].some(n=>n.name!==void 0)}function fYe(e,n){if(!h(n,"Declare"))return;let t=n.ops[1];if(!J(t))return;let i=n.ops.find(f=>Ve(f));if(i===void 0||!Ve(i))return;let r=i.get("value");if(r===void 0||i.get("holdUntil")!==void 0)return;let o;try{o=e.type(t.string)}catch{return}if(o.isUnknown||r.type.isUnknown)return;let s=N(r)||J(r)||T(r,"True")||T(r,"False");if(J(r)&&D1(o.type)&&Op(r.string)||!(s?!r.type.matches(o):o.isDisjointFrom(r.type)))return;let u=`The value "${r.toString()}" of type "${r.type}" is not compatible with the declared type "${o}"`,l=a$(r,o);return l===void 0?u:`${u}. ${l}`}function cYe(e){let n=[];wx(e,n);let t=new Map;for(let i of n){let r=Yve(i);t.set(r,(t.get(r)??0)+1)}return t}function Yve(e){let n=P(e,1);return EO(n===null?e:["Error",n])}function wx(e,n){if(L(e)==="Error"){let t=[];for(let i of G(e))wx(i,t);n.push(...t.length>0?t:[e]);return}if(TN(e)){for(let t of Object.values(e.dict))wx(t,n);return}for(let t of G(e))wx(t,n)}function __(e){let n=P(e,1);return n===null?"error":L(n)==="ErrorCode"?_x(P(n,1)??"Nothing"):_x(n)}function EO(e){let n=P(e,1),t=P(e,2),i=L(t)==="ErrorTrace"?null:t,r="error",o=[];if(n!==null)if(L(n)==="ErrorCode"){let l=[...G(n)].map(_x);r=l[0]??r,o.push(...l.slice(1))}else r=_x(n);let s=i===null?"":_x(i),a=s===""?"":/^\d+$/.test(s)?`for argument ${s}`:s.length<=40?`at \`${s}\``:`\u2014 ${s}`,u;switch(r){case"expected-function":u=o.length>=2?a===""?`\`${o[0]}\`: expected a function, got \`${o[1]}\``:`expected a function, got \`${o[1]}\``:`expected a function (${o.join(", ")})`;break;case"incompatible-type":u=o.length===2?`expected \`${o[0]}\`, got \`${o[1]}\``:`incompatible type: ${o.join(", ")}`;break;case"missing":u=o.length===0?"a required argument is missing":`a required argument is missing (${o.join(", ")})`;break;case"unexpected-argument":return o.length===0?"unexpected argument":`unexpected argument \`${o.join(", ")}\``;case"callback-arity":return o.length===0?"the callback takes the wrong number of parameters":o.join(" ");case"pipe-stage-arity":return o.length===0?"the pipe stage takes the wrong number of parameters":o.join(" ");case"no-division-by-point":return"a point cannot be a divisor";case"no-product-between-points":{let l=o.slice(1).join(" ");return l===""?"no product is defined between points":`no product is defined between points; ${l}`}case"invalid-symbol":u=o.length===0?"invalid symbol":`invalid symbol \`${o.join(", ")}\``;break;case"protocol-function-not-a-field":{let l=(o[1]??"").split(", ").filter(d=>d!=="").map(d=>`\`${d}\``),f=l.length===1?"protocol":"protocols",c=o[2]==="assign"?" and cannot be assigned":l.length===1?`: call it as \`${o[0]}(x)\` or \`x.${o[0]}()\``:"; more than one applies here, so call it with a qualified name";u=o.length>=2&&l.length>0?`\`${o[0]}\` is a function member of the ${l.join(" and ")} ${f}, not a field${c}`:`a protocol function member is not a field (${o.join(", ")})`;break}case"dot-call-not-a-protocol-function":{let[l,f]=o;u=l===void 0?"only a protocol function can be called with a dot":`\`${l}\` is not a protocol function${f===void 0?"":` on a value of type \`${f}\``}: write \`${l}(x)\` or \`x |> ${l}\``;break}default:{let l=/^[a-z][a-z0-9-]*$/.test(r)?r.replaceAll("-"," "):r;u=o.length===0?l:`${l}: ${o.join(", ")}`}}return a===""?u:`${u} ${a}`}function _x(e){return fe(e)??aJ(e)}function aJ(e){let n;try{n=dO(e).replaceAll(/\s+/g," ").trim()}catch{return""}return n.length>qve?`${n.slice(0,qve-1)}\u2026`:n}function N_(e,n){return(typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0)??[0,n.length]}function dYe(e){let n={};for(let t of e._typeResolver.names){let i=e._typeResolver.resolve(t)?._sumOf;i!==void 0&&(n[t]=i)}return n}var pYe=0;function Xve(e,n,t){let i=e._epsilBatchId;e._epsilBatchId=++pYe;try{return mYe(e,n,t)}finally{e._epsilBatchId=i}}function mYe(e,n,t){let i=[],r;try{let[m,g]=lO(n,t?.url,{parseLatex:t?.parseLatex,allowHostPragmas:t?.allowHostPragmas??!1,typeNames:e._typeResolver.names,protocolNames:Object.keys(e._protocolRegistry),sumVariants:dYe(e),deadline:e._deadlineFrame});r=pO(m,n,e),i.push(...g)}catch(m){if(m instanceof mx)return i.push(Kve(["error-directive",m.message],[0,n.length])),{value:e.Nothing,diagnostics:i};if(ql(m))return{value:e.box(["Error",{str:m instanceof Error?m.message:"Timeout exceeded"},{str:"timeout"}]),diagnostics:i,valueRange:[0,n.length]};throw m}let o=L(r)==="Block"?[...G(r)]:[r],s=mO(r),a=!1;if(!i.some(m=>m.severity==="error"))try{Hve(e,r,n,i)}catch(m){if(!ql(m))throw m;a=!0}if(!a&&!i.some(m=>m.severity==="error")){let m=new Set;for(let g of o)n1e(e,g,m,i,g,n)}let u=e.Nothing,l,f=new Set,c=new Set;for(let m=0;m<o.length;m++){let g=o[m],y;l=rh(g,n);let b;Qve(e,g,f,i,g,n);let E=e._epsilDeclarationRoute;e._epsilDeclarationRoute=lJ(g);try{ae(e._deadlineFrame),b=hYe(g,c),u=b===void 0?e.box(g).evaluate():e.error(["variable-redeclaration",b]);let S=u.errors;S.length>0&&(l=Zve(e,S[0].json,g,l))}catch(S){let v=S instanceof Error?S.message:String(S);y=TYe(S),u=y!==void 0?e.box(["Error",{str:v},{str:y}]):e.box(["Error",{str:v}])}finally{e._epsilDeclarationRoute=E}let x=b!==void 0&&i.some(S=>Array.isArray(S.message)&&S.message[0]==="variable-redeclaration"&&S.message[1]===b);if(m<o.length-1&&!x){let S=u.errors;if(S.length>0){let v=gYe(S[0].json),w=EO(S[0].json),_=Zve(e,S[0].json,g,rh(g,n)),C=Kve(y!==void 0?["evaluation-canceled",y,S[0].toString()]:["runtime-error",w,v,__(S[0].json)],_),k=w_(e,S[0].json,{definitionSites:s,primaryRange:_,boxedError:S[0]});k.length>0&&(C.notes=k),i.push(C)}}if(y==="timeout")break;t1e(e,u.json,f,i,g,n)}let d=EYe(o,n);for(let m of Object.values(e._protocolRegistry))for(let g of m.conformances)g.pending&&i.push({severity:"warning",message:["protocol-implementation-pending",g.targetKey,m.name,g._pendingReason??""],range:xYe(d,g.targetKey,m.name)??[0,n.length]});let p=u.errors.length>0?w_(e,u.errors[0].json,{definitionSites:s,primaryRange:l,boxedError:u.errors[0]}):[];return{value:u,diagnostics:i,...l===void 0?{}:{valueRange:l},...p.length===0?{}:{valueNotes:p}}}function hYe(e,n){let t=fJ(e),i=t.find(r=>n.has(r));if(i!==void 0)return i;for(let r of t)n.add(r)}function gYe(e){let n=[...G(e)],t=n[n.length-1];if(t===void 0||L(t)!=="ErrorTrace")return"";let i=[];for(let r of G(t)){if(L(r)==="ErrorBroadcast"){let a=fe(P(r,1)),u=Se(P(r,2)),l=Se(P(r,3));if(a===null||u===null||l===null)continue;i.push(`while applying ${a} element-wise over ${l} element${l===1?"":"s"} (element ${u})`);continue}if(L(r)!=="ErrorFrame")continue;let o=fe(P(r,1)),s=Se(P(r,2));o===null||s===null||o==="Block"||o==="Function"||i.push(`in ${o} argument ${s}`)}return i.join(", ")}function Zve(e,n,t,i){return Rve(hO(n),t,i,Jve(e),uJ(__(n)))}function Qve(e,n,t,i,r,o,s=new Set){let a=L(n);if(a==="")return;if(!t.has(a)&&!s.has(a)&&e.operatorInfo(a)===void 0&&!yYe(e,a)){let l=vYe(e,a);l!==void 0&&(t.add(a),i.push({severity:"warning",message:["protocol-property-not-callable",a,l],range:e1e(n)??rh(r,o)}))}let u=a==="Function"?bYe(n,s):s;for(let l of G(n))Qve(e,l,t,i,r,o,u)}function yYe(e,n){let t=e.lookupDefinition(n);return t===void 0?!1:"value"in t?t.value.type.matches("function"):!0}function bYe(e,n){let t=new Set(n),i=[...G(e)].slice(1),r=o=>{let s=Z(o);s!=null&&t.add(s);for(let a of G(o))r(a)};for(let o of i)r(o);return t}function EYe(e,n){let t=[];for(let i of e){if(L(i)!=="DeclareConformance")continue;let r=fe(P(i,1))??Z(P(i,1));if(r==null)continue;let o=fe(P(i,3)),s=o===null||o===""?void 0:o,a=rh(i,n);for(let u of G(P(i,2)??"Nothing")){let l=Z(u)??fe(u);l!=null&&t.push({target:r,protocol:l,clause:s,range:a})}}return t}function xYe(e,n,t){let i=e.filter(r=>r.protocol===t&&(r.clause===void 0?n===r.target:n.startsWith(`${r.target} where `)));return i.length===1?i[0].range:void 0}function vYe(e,n){for(let t of Object.values(e._protocolRegistry)){let i=t.members[n]?.kind;if(i==="readonly"||i==="readwrite")return t.name}}function e1e(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e.sourceOffsets:void 0}function rh(e,n){return e1e(e)??[0,n.length]}var SYe=new Set(["println","printf","puts","echo"]);function n1e(e,n,t,i,r,o){if(L(n)==="Function")for(let s of G(n).slice(1)){let a=Z(s)??(L(s)==="Typed"?Z(P(s,1)):null);if(a===null||a.length<=1||t.has(a)||ws(a))continue;let u=e.lookupDefinition(a),l=e.contextStack[0]?.lexicalScope;u!==void 0&&l!==void 0&&l.bindings.get(a)===u&&"value"in u&&u.value?.isConstant===!0&&(t.add(a),i.push({severity:"warning",message:["parameter-shadows-constant",a],range:rh(r,o)}))}for(let s of G(n))n1e(e,s,t,i,r,o)}function t1e(e,n,t,i,r,o){let s=L(n);if(s!==""){if(!t.has(s)&&e.operatorInfo(s)===void 0)if(t.add(s),e._typeResolver.resolve(s)!==void 0)i.push({severity:"warning",message:["type-not-callable",s],range:rh(r,o)});else if(SYe.has(s.toLowerCase()))i.push({severity:"warning",message:["print-not-available",s],range:rh(r,o)});else{let a=e.suggestOperatorName(s),u=a===void 0?void 0:S_(a)??a;u!==void 0&&u!==s&&i.push({severity:"warning",message:["unknown-function",s,u],range:rh(r,o)})}for(let a of G(n))t1e(e,a,t,i,r,o)}}function TYe(e){if(!(e instanceof Error)||e.name!=="CancellationError")return;let n=e.cause;if(n==="timeout"||n==="iteration-limit-exceeded"||n==="recursion-depth-exceeded")return n}function Kve(e,n){return{severity:"error",message:e,range:n}}var wYe="0.129.1";return l1e(_Ye);})();
1900
1900
  /*! Bundled license information:
1901
1901
 
1902
1902
  complex-esm/dist/src/complex.js: