@cortex-js/compute-engine 0.57.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/README.md +4 -0
  2. package/dist/compile.esm.js +2376 -501
  3. package/dist/compile.min.esm.js +316 -68
  4. package/dist/compile.min.umd.cjs +316 -68
  5. package/dist/compile.umd.cjs +2376 -501
  6. package/dist/compute-engine.esm.js +15717 -12444
  7. package/dist/compute-engine.min.esm.js +331 -83
  8. package/dist/compute-engine.min.umd.cjs +330 -82
  9. package/dist/compute-engine.umd.cjs +15717 -12444
  10. package/dist/core.esm.js +15716 -12443
  11. package/dist/core.min.esm.js +329 -81
  12. package/dist/core.min.umd.cjs +329 -81
  13. package/dist/core.umd.cjs +15716 -12443
  14. package/dist/identities.esm.js +1921 -0
  15. package/dist/identities.min.esm.js +2 -0
  16. package/dist/identities.min.umd.cjs +4 -0
  17. package/dist/identities.umd.cjs +1946 -0
  18. package/dist/interval.esm.js +779 -339
  19. package/dist/interval.min.esm.js +8 -8
  20. package/dist/interval.min.umd.cjs +8 -8
  21. package/dist/interval.umd.cjs +779 -339
  22. package/dist/latex-syntax.esm.js +971 -608
  23. package/dist/latex-syntax.min.esm.js +7 -7
  24. package/dist/latex-syntax.min.umd.cjs +7 -7
  25. package/dist/latex-syntax.umd.cjs +971 -608
  26. package/dist/math-json.esm.js +8 -12
  27. package/dist/math-json.min.esm.js +2 -2
  28. package/dist/math-json.min.umd.cjs +2 -2
  29. package/dist/math-json.umd.cjs +8 -12
  30. package/dist/numerics.esm.js +1382 -226
  31. package/dist/numerics.min.esm.js +16 -5
  32. package/dist/numerics.min.umd.cjs +16 -5
  33. package/dist/numerics.umd.cjs +1382 -226
  34. package/dist/types/big-decimal/big-decimal.d.ts +1 -1
  35. package/dist/types/big-decimal/index.d.ts +1 -1
  36. package/dist/types/big-decimal/transcendentals.d.ts +1 -1
  37. package/dist/types/big-decimal/utils.d.ts +1 -1
  38. package/dist/types/common/ansi-codes.d.ts +1 -1
  39. package/dist/types/common/configuration-change.d.ts +1 -1
  40. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  41. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  42. package/dist/types/common/interruptible.d.ts +1 -1
  43. package/dist/types/common/one-of.d.ts +1 -1
  44. package/dist/types/common/signals.d.ts +1 -1
  45. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  46. package/dist/types/common/type/boxed-type.d.ts +1 -1
  47. package/dist/types/common/type/lexer.d.ts +1 -1
  48. package/dist/types/common/type/parse.d.ts +1 -208
  49. package/dist/types/common/type/parser.d.ts +124 -2
  50. package/dist/types/common/type/primitive.d.ts +5 -1
  51. package/dist/types/common/type/reduce.d.ts +1 -1
  52. package/dist/types/common/type/serialize.d.ts +1 -1
  53. package/dist/types/common/type/subtype.d.ts +18 -1
  54. package/dist/types/common/type/type-builder.d.ts +1 -1
  55. package/dist/types/common/type/types.d.ts +1 -1
  56. package/dist/types/common/type/utils.d.ts +1 -1
  57. package/dist/types/common/utils.d.ts +1 -1
  58. package/dist/types/compile.d.ts +1 -1
  59. package/dist/types/compute-engine/assume.d.ts +13 -6
  60. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -1
  61. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +7 -1
  71. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -3
  74. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +140 -0
  82. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  87. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +34 -12
  88. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  89. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  90. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  91. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  92. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  93. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  94. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  95. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  96. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  97. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  98. package/dist/types/compute-engine/boxed-expression/rule-index.d.ts +112 -0
  99. package/dist/types/compute-engine/boxed-expression/rules.d.ts +2 -1
  100. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  101. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  102. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  103. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  104. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  105. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  106. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  107. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  108. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  109. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  110. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  111. package/dist/types/compute-engine/compilation/base-compiler.d.ts +8 -1
  112. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  113. package/dist/types/compute-engine/compilation/constant-folding.d.ts +16 -1
  114. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  115. package/dist/types/compute-engine/compilation/gpu-target.d.ts +58 -5
  116. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +4 -4
  117. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  118. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  119. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  120. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  121. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  122. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  123. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  124. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  125. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  126. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  127. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  128. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  129. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  130. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  131. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  132. package/dist/types/compute-engine/engine-runtime-state.d.ts +4 -1
  133. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  134. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  135. package/dist/types/compute-engine/engine-simplification-rules.d.ts +10 -2
  136. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  137. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  138. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  139. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  140. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  141. package/dist/types/compute-engine/fungrim/loader.d.ts +13 -0
  142. package/dist/types/compute-engine/fungrim/types.d.ts +160 -0
  143. package/dist/types/compute-engine/global-types.d.ts +1 -1
  144. package/dist/types/compute-engine/index.d.ts +63 -2
  145. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  146. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  147. package/dist/types/compute-engine/interval/elementary.d.ts +10 -2
  148. package/dist/types/compute-engine/interval/index.d.ts +2 -2
  149. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  150. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  151. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  152. package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
  153. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  154. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  155. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  156. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-colors.d.ts +1 -1
  157. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  158. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  159. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  160. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  161. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  162. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  163. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  164. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  165. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  166. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  167. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  168. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  169. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +4 -1
  170. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  171. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  172. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  173. package/dist/types/compute-engine/latex-syntax/parse.d.ts +3 -2
  174. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
  175. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -11
  176. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  177. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  178. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  179. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  180. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  181. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  182. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  183. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  184. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  185. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  186. package/dist/types/compute-engine/library/complex.d.ts +13 -1
  187. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  188. package/dist/types/compute-engine/library/core.d.ts +1 -1
  189. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  190. package/dist/types/compute-engine/library/library.d.ts +1 -1
  191. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  192. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  193. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  194. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  195. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  196. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  197. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  198. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  199. package/dist/types/compute-engine/library/sets.d.ts +27 -1
  200. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  201. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  202. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  203. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  204. package/dist/types/compute-engine/library/units.d.ts +1 -1
  205. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  206. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  207. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +7 -1
  208. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  209. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  210. package/dist/types/compute-engine/numerics/bernoulli.d.ts +39 -0
  211. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  212. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  213. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  214. package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
  215. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  216. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  217. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  218. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +12 -1
  219. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  220. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  221. package/dist/types/compute-engine/numerics/random.d.ts +23 -0
  222. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  223. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  224. package/dist/types/compute-engine/numerics/special-functions.d.ts +78 -10
  225. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  226. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  227. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  228. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  229. package/dist/types/compute-engine/oeis.d.ts +1 -1
  230. package/dist/types/compute-engine/sequence.d.ts +1 -1
  231. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  232. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  233. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  234. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  235. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  236. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  237. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  238. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  239. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  240. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  241. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  242. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  243. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  244. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  245. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  246. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  247. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  248. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  249. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  250. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  251. package/dist/types/compute-engine/tensor/tensors.d.ts +3 -3
  252. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  253. package/dist/types/compute-engine/types-engine.d.ts +52 -3
  254. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  255. package/dist/types/compute-engine/types-expression.d.ts +85 -14
  256. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +32 -1
  257. package/dist/types/compute-engine/types-kernel-serialization.d.ts +45 -3
  258. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  259. package/dist/types/compute-engine/types.d.ts +1 -1
  260. package/dist/types/compute-engine.d.ts +1 -1
  261. package/dist/types/core.d.ts +1 -1
  262. package/dist/types/identities.d.ts +3 -0
  263. package/dist/types/interval.d.ts +1 -1
  264. package/dist/types/latex-syntax.d.ts +2 -2
  265. package/dist/types/math-json/symbols.d.ts +1 -1
  266. package/dist/types/math-json/types.d.ts +1 -1
  267. package/dist/types/math-json/utils.d.ts +1 -1
  268. package/dist/types/math-json.d.ts +2 -2
  269. package/dist/types/numerics.d.ts +1 -1
  270. package/package.json +9 -3
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.57.0 */
1
+ /** Compute Engine 0.59.0 */
2
2
 
3
3
  // src/compute-engine/numeric-value/types.ts
4
4
  var NumericValue = class {
@@ -153,6 +153,7 @@ function fpexp(x, scale) {
153
153
  return sum;
154
154
  }
155
155
  function fpln(x, scale) {
156
+ if (x <= 0n) throw new RangeError("fpln: input must be positive");
156
157
  if (x === scale) return 0n;
157
158
  const xNum = Number(x);
158
159
  const scaleNum = Number(scale);
@@ -802,9 +803,11 @@ var BigDecimal = class _BigDecimal {
802
803
  if (Number.isFinite(thisExp) && Number.isFinite(otherExp)) {
803
804
  if (other.significand === 0n) return _BigDecimal.NAN;
804
805
  if (this.significand === 0n) return fromRaw(0n, 0);
805
- return this.sub(this.div(other).trunc().mul(other)).toPrecision(
806
- _BigDecimal.precision
807
- );
806
+ const ediff = thisExp - otherExp;
807
+ const num = ediff >= 0 ? this.significand * pow10(ediff) : this.significand;
808
+ const den = ediff >= 0 ? other.significand : other.significand * pow10(-ediff);
809
+ const q = num / den;
810
+ return this.sub(fromRaw(q, 0).mul(other));
808
811
  }
809
812
  if (thisExp !== thisExp || otherExp !== otherExp) return _BigDecimal.NAN;
810
813
  if (!Number.isFinite(thisExp)) return _BigDecimal.NAN;
@@ -849,7 +852,10 @@ var BigDecimal = class _BigDecimal {
849
852
  return this.pow(n.neg()).inv();
850
853
  }
851
854
  const absSig = this.significand < 0n ? -this.significand : this.significand;
852
- const thisLog10 = bigintDigits(absSig) + this.exponent;
855
+ const sigDigits = bigintDigits(absSig);
856
+ const dropped = sigDigits > 15 ? sigDigits - 15 : 0;
857
+ const lead = dropped > 0 ? Number(absSig / 10n ** BigInt(dropped)) : Number(absSig);
858
+ const thisLog10 = Math.log10(lead) + dropped + this.exponent;
853
859
  const resultLog10 = Number(expValue) * thisLog10;
854
860
  if (resultLog10 > 9e15) {
855
861
  return this.significand < 0n && expValue % 2n !== 0n ? _BigDecimal.NEGATIVE_INFINITY : _BigDecimal.POSITIVE_INFINITY;
@@ -882,7 +888,19 @@ var BigDecimal = class _BigDecimal {
882
888
  return _BigDecimal.POSITIVE_INFINITY;
883
889
  }
884
890
  if (this.significand < 0n) return _BigDecimal.NAN;
885
- return n.mul(this.ln()).exp();
891
+ const baseSig = this.significand;
892
+ const decExpBase = this.exponent + bigintDigits(baseSig) - 1;
893
+ const nSig = n.significand < 0n ? -n.significand : n.significand;
894
+ const decExpN = n.exponent + bigintDigits(nSig) - 1;
895
+ const argMag = decExpN + Math.log10(Math.abs(decExpBase) * 2.303 + 3) + 1;
896
+ const extra = Math.min(20, Math.max(2, Math.ceil(argMag) + 2));
897
+ const savedPrec = _BigDecimal.precision;
898
+ _BigDecimal.precision = savedPrec + extra;
899
+ try {
900
+ return n.mul(this.ln()).exp().toPrecision(savedPrec);
901
+ } finally {
902
+ _BigDecimal.precision = savedPrec;
903
+ }
886
904
  }
887
905
  // ---------- Conversion methods ----------
888
906
  /** Convert to a JavaScript number. May lose precision for large values. */
@@ -1123,6 +1141,20 @@ function fromFixedPoint(fp, scale, targetPrecision) {
1123
1141
  const sig = negative ? -absFp : absFp;
1124
1142
  return fromRaw(sig, resultExp);
1125
1143
  }
1144
+ function decimalExponent(x) {
1145
+ const sig = x.significand < 0n ? -x.significand : x.significand;
1146
+ return x.exponent + bigintDigits(sig) - 1;
1147
+ }
1148
+ var MAX_SAFE_EXPONENT = BigInt(Number.MAX_SAFE_INTEGER);
1149
+ var _ln10Fp = null;
1150
+ var _ln10Scale = null;
1151
+ function ln10Fixed(scale) {
1152
+ if (_ln10Scale !== scale) {
1153
+ _ln10Fp = fpln(10n * scale, scale);
1154
+ _ln10Scale = scale;
1155
+ }
1156
+ return _ln10Fp;
1157
+ }
1126
1158
  BigDecimal.prototype.sqrt = function() {
1127
1159
  if (this.isNaN()) return BigDecimal.NAN;
1128
1160
  if (this.isZero()) return BigDecimal.ZERO;
@@ -1133,9 +1165,13 @@ BigDecimal.prototype.sqrt = function() {
1133
1165
  if (this.significand < 0n) return BigDecimal.NAN;
1134
1166
  const targetPrec = BigDecimal.precision;
1135
1167
  const workingPrec = targetPrec + 10;
1136
- const [fp, scale] = toFixedPoint(this, workingPrec);
1168
+ const e = decimalExponent(this);
1169
+ const k = Math.floor(e / 2);
1170
+ const m = fromRaw(this.significand, this.exponent - 2 * k);
1171
+ const [fp, scale] = toFixedPoint(m, workingPrec);
1137
1172
  const sqrtFp = fpsqrt(fp, scale);
1138
- return fromFixedPoint(sqrtFp, scale, targetPrec);
1173
+ const root = fromFixedPoint(sqrtFp, scale, targetPrec);
1174
+ return fromRaw(root.significand, root.exponent + k);
1139
1175
  };
1140
1176
  BigDecimal.prototype.cbrt = function() {
1141
1177
  if (this.isNaN()) return BigDecimal.NAN;
@@ -1149,10 +1185,13 @@ BigDecimal.prototype.cbrt = function() {
1149
1185
  }
1150
1186
  const targetPrec = BigDecimal.precision;
1151
1187
  const workingPrec = targetPrec + 10;
1152
- const [fp, scale] = toFixedPoint(this, workingPrec);
1188
+ const e = decimalExponent(this);
1189
+ const k = Math.floor(e / 3);
1190
+ const m = fromRaw(this.significand, this.exponent - 3 * k);
1191
+ const [fp, scale] = toFixedPoint(m, workingPrec);
1153
1192
  const C = fp * scale * scale;
1154
1193
  let x;
1155
- const numVal = this.toNumber();
1194
+ const numVal = m.toNumber();
1156
1195
  const scaleNum = Number(scale);
1157
1196
  if (Number.isFinite(numVal) && numVal > 0 && Number.isFinite(scaleNum)) {
1158
1197
  const approx = Math.cbrt(numVal);
@@ -1181,7 +1220,8 @@ BigDecimal.prototype.cbrt = function() {
1181
1220
  const diffNext = bigintAbs(next * next * next - C);
1182
1221
  if (diffNext < diffX) x = next;
1183
1222
  }
1184
- return fromFixedPoint(x, scale, targetPrec);
1223
+ const root = fromFixedPoint(x, scale, targetPrec);
1224
+ return fromRaw(root.significand, root.exponent + k);
1185
1225
  };
1186
1226
  BigDecimal.sqrt = function(x) {
1187
1227
  return x.sqrt();
@@ -1196,11 +1236,27 @@ BigDecimal.prototype.exp = function() {
1196
1236
  return BigDecimal.ZERO;
1197
1237
  }
1198
1238
  if (this.isZero()) return BigDecimal.ONE;
1239
+ if (decimalExponent(this) >= 17)
1240
+ return this.significand > 0n ? BigDecimal.POSITIVE_INFINITY : BigDecimal.ZERO;
1199
1241
  const targetPrec = BigDecimal.precision;
1200
- const workingPrec = targetPrec + 15;
1201
- const [fp, scale] = toFixedPoint(this, workingPrec);
1202
- const expFp = fpexp(fp, scale);
1203
- return fromFixedPoint(expFp, scale, targetPrec);
1242
+ const absSig = this.significand < 0n ? -this.significand : this.significand;
1243
+ const magnitude = Math.max(0, this.exponent + bigintDigits(absSig));
1244
+ const workingPrec = targetPrec + 20 + magnitude;
1245
+ const [xFp, scale] = toFixedPoint(this, workingPrec);
1246
+ const l10 = ln10Fixed(scale);
1247
+ let k = xFp / l10;
1248
+ let rFp = xFp - k * l10;
1249
+ if (rFp < 0n) {
1250
+ k -= 1n;
1251
+ rFp += l10;
1252
+ }
1253
+ if (k > MAX_SAFE_EXPONENT || k < -MAX_SAFE_EXPONENT)
1254
+ return k > 0n ? BigDecimal.POSITIVE_INFINITY : BigDecimal.ZERO;
1255
+ const expR = fromFixedPoint(fpexp(rFp, scale), scale, targetPrec);
1256
+ const newExp = expR.exponent + Number(k);
1257
+ if (!Number.isSafeInteger(newExp))
1258
+ return k > 0n ? BigDecimal.POSITIVE_INFINITY : BigDecimal.ZERO;
1259
+ return fromRaw(expR.significand, newExp);
1204
1260
  };
1205
1261
  BigDecimal.prototype.ln = function() {
1206
1262
  if (this.isNaN()) return BigDecimal.NAN;
@@ -1212,10 +1268,16 @@ BigDecimal.prototype.ln = function() {
1212
1268
  if (this.significand < 0n) return BigDecimal.NAN;
1213
1269
  if (this.eq(1)) return BigDecimal.ZERO;
1214
1270
  const targetPrec = BigDecimal.precision;
1215
- const workingPrec = targetPrec + 15;
1216
- const [fp, scale] = toFixedPoint(this, workingPrec);
1217
- const lnFp = fpln(fp, scale);
1218
- return fromFixedPoint(lnFp, scale, targetPrec);
1271
+ const sig = this.significand;
1272
+ const digits = bigintDigits(sig);
1273
+ const e = this.exponent + digits - 1;
1274
+ const m = fromRaw(sig, -(digits - 1));
1275
+ const eDigits = Math.abs(e).toString().length;
1276
+ const workingPrec = targetPrec + 20 + eDigits;
1277
+ const [mFp, scale] = toFixedPoint(m, workingPrec);
1278
+ const l10 = ln10Fixed(scale);
1279
+ const resultFp = fpln(mFp, scale) + BigInt(e) * l10;
1280
+ return fromFixedPoint(resultFp, scale, targetPrec);
1219
1281
  };
1220
1282
  BigDecimal.prototype.log = function(base) {
1221
1283
  const b = base instanceof BigDecimal ? base : new BigDecimal(base);
@@ -1235,7 +1297,10 @@ BigDecimal.prototype.sin = function() {
1235
1297
  if (!this.isFinite()) return BigDecimal.NAN;
1236
1298
  if (this.isZero()) return BigDecimal.ZERO;
1237
1299
  const targetPrec = BigDecimal.precision;
1238
- const workingPrec = targetPrec + 15;
1300
+ const e = decimalExponent(this);
1301
+ if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
1302
+ const workingPrec = targetPrec + 15 + (e < 0 ? -e : 0);
1303
+ if (e > PI_DIGITS.length - workingPrec - 30) return BigDecimal.NAN;
1239
1304
  const [fp, scale] = toFixedPoint(this, workingPrec);
1240
1305
  const [sinFp] = fpsincos(fp, scale);
1241
1306
  return fromFixedPoint(sinFp, scale, targetPrec);
@@ -1246,6 +1311,8 @@ BigDecimal.prototype.cos = function() {
1246
1311
  if (this.isZero()) return BigDecimal.ONE;
1247
1312
  const targetPrec = BigDecimal.precision;
1248
1313
  const workingPrec = targetPrec + 15;
1314
+ const e = decimalExponent(this);
1315
+ if (e > PI_DIGITS.length - workingPrec - 30) return BigDecimal.NAN;
1249
1316
  const [fp, scale] = toFixedPoint(this, workingPrec);
1250
1317
  const [, cosFp] = fpsincos(fp, scale);
1251
1318
  return fromFixedPoint(cosFp, scale, targetPrec);
@@ -1255,7 +1322,10 @@ BigDecimal.prototype.tan = function() {
1255
1322
  if (!this.isFinite()) return BigDecimal.NAN;
1256
1323
  if (this.isZero()) return BigDecimal.ZERO;
1257
1324
  const targetPrec = BigDecimal.precision;
1258
- const workingPrec = targetPrec + 15;
1325
+ const e = decimalExponent(this);
1326
+ if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
1327
+ const workingPrec = targetPrec + 15 + (e < 0 ? -e : 0);
1328
+ if (e > PI_DIGITS.length - workingPrec - 30) return BigDecimal.NAN;
1259
1329
  const [fp, scale] = toFixedPoint(this, workingPrec);
1260
1330
  const [sinFp, cosFp] = fpsincos(fp, scale);
1261
1331
  if (cosFp === 0n) {
@@ -1273,7 +1343,9 @@ BigDecimal.prototype.atan = function() {
1273
1343
  return piHalf.neg();
1274
1344
  }
1275
1345
  const targetPrec = BigDecimal.precision;
1276
- const workingPrec = targetPrec + 15;
1346
+ const e = decimalExponent(this);
1347
+ if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
1348
+ const workingPrec = targetPrec + 15 + (e < 0 ? -e : 0);
1277
1349
  const [fp, scale] = toFixedPoint(this, workingPrec);
1278
1350
  const atanFp = fpatan(fp, scale);
1279
1351
  return fromFixedPoint(atanFp, scale, targetPrec);
@@ -1290,7 +1362,9 @@ BigDecimal.prototype.asin = function() {
1290
1362
  return this.significand > 0n ? piHalf : piHalf.neg();
1291
1363
  }
1292
1364
  const targetPrec = BigDecimal.precision;
1293
- const workingPrec = targetPrec + 20;
1365
+ const e = decimalExponent(this);
1366
+ if (e < 0 && -2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
1367
+ const workingPrec = targetPrec + 20 + (e < 0 ? -e : 0);
1294
1368
  const [xFp, scale] = toFixedPoint(this, workingPrec);
1295
1369
  const x2 = fpmul(xFp, xFp, scale);
1296
1370
  const oneMinusX2 = scale - x2;
@@ -1353,6 +1427,23 @@ BigDecimal.prototype.sinh = function() {
1353
1427
  if (this.significand > 0n) return BigDecimal.POSITIVE_INFINITY;
1354
1428
  return BigDecimal.NEGATIVE_INFINITY;
1355
1429
  }
1430
+ const targetPrec = BigDecimal.precision;
1431
+ const e = decimalExponent(this);
1432
+ if (e < 0) {
1433
+ if (-2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
1434
+ const saved = BigDecimal.precision;
1435
+ BigDecimal.precision = targetPrec - e + 5;
1436
+ try {
1437
+ const expX2 = this.exp();
1438
+ return expX2.sub(expX2.inv()).div(BigDecimal.TWO).toPrecision(targetPrec);
1439
+ } finally {
1440
+ BigDecimal.precision = saved;
1441
+ }
1442
+ }
1443
+ if (Math.abs(this.toNumber()) > 1.16 * (targetPrec + 3)) {
1444
+ const h = this.abs().exp().div(BigDecimal.TWO);
1445
+ return this.significand > 0n ? h : h.neg();
1446
+ }
1356
1447
  const expX = this.exp();
1357
1448
  const expNegX = expX.inv();
1358
1449
  return expX.sub(expNegX).div(BigDecimal.TWO);
@@ -1363,6 +1454,9 @@ BigDecimal.prototype.cosh = function() {
1363
1454
  if (!this.isFinite()) {
1364
1455
  return BigDecimal.POSITIVE_INFINITY;
1365
1456
  }
1457
+ const targetPrec = BigDecimal.precision;
1458
+ if (Math.abs(this.toNumber()) > 1.16 * (targetPrec + 3))
1459
+ return this.abs().exp().div(BigDecimal.TWO);
1366
1460
  const expX = this.exp();
1367
1461
  const expNegX = expX.inv();
1368
1462
  return expX.add(expNegX).div(BigDecimal.TWO);
@@ -1374,6 +1468,21 @@ BigDecimal.prototype.tanh = function() {
1374
1468
  if (this.significand > 0n) return BigDecimal.ONE;
1375
1469
  return BigDecimal.NEGATIVE_ONE;
1376
1470
  }
1471
+ const targetPrec = BigDecimal.precision;
1472
+ const e = decimalExponent(this);
1473
+ if (e < 0) {
1474
+ if (-2 * e >= targetPrec + 4) return this.toPrecision(targetPrec);
1475
+ const saved = BigDecimal.precision;
1476
+ BigDecimal.precision = targetPrec - e + 5;
1477
+ try {
1478
+ const exp2x2 = this.mul(BigDecimal.TWO).exp();
1479
+ return exp2x2.sub(BigDecimal.ONE).div(exp2x2.add(BigDecimal.ONE)).toPrecision(targetPrec);
1480
+ } finally {
1481
+ BigDecimal.precision = saved;
1482
+ }
1483
+ }
1484
+ if (Math.abs(this.toNumber()) > 1.16 * (targetPrec + 3))
1485
+ return this.significand > 0n ? BigDecimal.ONE : BigDecimal.NEGATIVE_ONE;
1377
1486
  const exp2x = this.mul(BigDecimal.TWO).exp();
1378
1487
  return exp2x.sub(BigDecimal.ONE).div(exp2x.add(BigDecimal.ONE));
1379
1488
  };
@@ -1460,9 +1569,7 @@ function bigint(a) {
1460
1569
  if (typeof a === "bigint") return a;
1461
1570
  if (typeof a === "number") {
1462
1571
  if (!Number.isInteger(a)) return null;
1463
- if (a >= Number.MAX_SAFE_INTEGER && a <= Number.MAX_SAFE_INTEGER)
1464
- return BigInt(a);
1465
- return bigint(a.toString());
1572
+ return BigInt(a);
1466
1573
  }
1467
1574
  if (a instanceof BigDecimal) {
1468
1575
  if (!a.isInteger()) return null;
@@ -2743,7 +2850,8 @@ function canonicalInteger(n, exponent) {
2743
2850
  [1, 5],
2744
2851
  [1, 6],
2745
2852
  [1, 7],
2746
- [1, 8],
2853
+ [2, 2],
2854
+ // √8 = 2√2
2747
2855
  [3, 1],
2748
2856
  [1, 10],
2749
2857
  [1, 11],
@@ -2755,7 +2863,8 @@ function canonicalInteger(n, exponent) {
2755
2863
  [1, 17],
2756
2864
  [3, 2],
2757
2865
  [1, 19],
2758
- [1, 20]
2866
+ [2, 5]
2867
+ // √20 = 2√5
2759
2868
  ][n];
2760
2869
  if (result) return result;
2761
2870
  }
@@ -2780,7 +2889,8 @@ function gcd(a, b) {
2780
2889
  }
2781
2890
  function lcm(a, b) {
2782
2891
  if (a === 0 || b === 0) return 0;
2783
- const res = BigInt(a) * BigInt(b) / BigInt(gcd(a, b));
2892
+ let res = BigInt(a) * BigInt(b) / BigInt(gcd(a, b));
2893
+ if (res < 0n) res = -res;
2784
2894
  return Number(res);
2785
2895
  }
2786
2896
  function factorial(n) {
@@ -3335,12 +3445,23 @@ var PRIMITIVE_TYPES = [
3335
3445
  "error",
3336
3446
  ...EXPRESSION_TYPES
3337
3447
  ];
3448
+ var NUMERIC_TYPES_SET = new Set(
3449
+ NUMERIC_TYPES
3450
+ );
3451
+ var COLLECTION_TYPES_SET = new Set(
3452
+ COLLECTION_TYPES
3453
+ );
3454
+ var SCALAR_TYPES_SET = new Set(
3455
+ SCALAR_TYPES
3456
+ );
3457
+ var PRIMITIVE_TYPES_SET = new Set(
3458
+ PRIMITIVE_TYPES
3459
+ );
3338
3460
  function isValidType(t) {
3339
- if (typeof t === "string")
3340
- return PRIMITIVE_TYPES.includes(t);
3461
+ if (typeof t === "string") return PRIMITIVE_TYPES_SET.has(t);
3341
3462
  if (typeof t !== "object") return false;
3342
3463
  if (!("kind" in t)) return false;
3343
- return t.kind === "signature" || t.kind === "union" || t.kind === "intersection" || t.kind === "negation" || t.kind === "tuple" || t.kind === "list" || t.kind === "record" || t.kind === "dictionary" || t.kind === "set" || t.kind === "function" || t.kind === "collection" || t.kind === "indexed_collection" || t.kind === "reference";
3464
+ return t.kind === "signature" || t.kind === "union" || t.kind === "intersection" || t.kind === "negation" || t.kind === "value" || t.kind === "tuple" || t.kind === "list" || t.kind === "record" || t.kind === "dictionary" || t.kind === "set" || t.kind === "symbol" || t.kind === "expression" || t.kind === "numeric" || t.kind === "collection" || t.kind === "indexed_collection" || t.kind === "reference";
3344
3465
  }
3345
3466
 
3346
3467
  // src/common/type/lexer.ts
@@ -4050,19 +4171,13 @@ var Parser = class {
4050
4171
  );
4051
4172
  let dimensions;
4052
4173
  if (this.match("<")) {
4053
- dimensions = this.parseDimensionWithX();
4054
- if (!dimensions) {
4055
- dimensions = this.parseDimensions();
4056
- }
4174
+ dimensions = this.parseDimensions();
4057
4175
  if (!dimensions) {
4058
4176
  const type = this.parseUnionType();
4059
4177
  if (type) {
4060
4178
  elementType = type;
4061
4179
  if (this.match("^")) {
4062
- dimensions = this.parseDimensionWithX();
4063
- if (!dimensions) {
4064
- dimensions = this.parseDimensions();
4065
- }
4180
+ dimensions = this.parseCaretDimensions();
4066
4181
  }
4067
4182
  }
4068
4183
  }
@@ -4103,19 +4218,13 @@ var Parser = class {
4103
4218
  );
4104
4219
  let dimensions;
4105
4220
  if (this.match("<")) {
4106
- dimensions = this.parseDimensionWithX();
4107
- if (!dimensions) {
4108
- dimensions = this.parseDimensions();
4109
- }
4221
+ dimensions = this.parseDimensions();
4110
4222
  if (!dimensions) {
4111
4223
  const type = this.parseUnionType();
4112
4224
  if (type) {
4113
4225
  elementType = type;
4114
4226
  if (this.match("^")) {
4115
- dimensions = this.parseDimensionWithX();
4116
- if (!dimensions) {
4117
- dimensions = this.parseDimensions();
4118
- }
4227
+ dimensions = this.parseCaretDimensions();
4119
4228
  }
4120
4229
  }
4121
4230
  }
@@ -4146,16 +4255,30 @@ var Parser = class {
4146
4255
  return this.createNode("tensor", { elementType });
4147
4256
  }
4148
4257
  parseDimensions() {
4149
- const dimensions = [];
4150
4258
  const firstDim = this.parseDimension();
4151
4259
  if (!firstDim) return void 0;
4152
- dimensions.push(firstDim);
4153
- while (this.match("x")) {
4154
- const dim = this.parseDimension();
4155
- if (!dim) {
4156
- this.error("Expected dimension after x");
4260
+ const dimensions = [firstDim];
4261
+ for (; ; ) {
4262
+ const tok = this.current;
4263
+ if (tok.type === "IDENTIFIER" && /^(x\d+)+$/.test(tok.value)) {
4264
+ this.advance();
4265
+ for (const m of tok.value.match(/x(\d+)/g))
4266
+ dimensions.push(
4267
+ this.createNode("dimension", {
4268
+ size: parseInt(m.slice(1))
4269
+ })
4270
+ );
4271
+ } else if (tok.type === "IDENTIFIER" && tok.value === "x") {
4272
+ const next = this.lexer.peekToken();
4273
+ if (next.type !== "NUMBER_LITERAL" && next.type !== "?")
4274
+ this.error(
4275
+ "Expected a positive integer literal or `?` after x. For example: `2x3` or `2x?`"
4276
+ );
4277
+ this.advance();
4278
+ dimensions.push(this.parseDimension());
4279
+ } else {
4280
+ break;
4157
4281
  }
4158
- dimensions.push(dim);
4159
4282
  }
4160
4283
  return dimensions;
4161
4284
  }
@@ -4169,35 +4292,11 @@ var Parser = class {
4169
4292
  }
4170
4293
  return void 0;
4171
4294
  }
4172
- parseDimensionWithX() {
4173
- if (this.current.type === "NUMBER_LITERAL") {
4174
- const dimensions = [];
4175
- const firstDim = parseInt(this.advance().value);
4176
- dimensions.push(
4177
- this.createNode("dimension", { size: firstDim })
4178
- );
4179
- if (this.current.type === "IDENTIFIER" && this.current.value.startsWith("x")) {
4180
- const dimString = this.current.value;
4181
- const matches = dimString.match(/x(\d+)/g);
4182
- if (matches && matches.join("") === dimString) {
4183
- this.advance();
4184
- for (const match of matches) {
4185
- const dimValue = parseInt(match.substring(1));
4186
- dimensions.push(
4187
- this.createNode("dimension", { size: dimValue })
4188
- );
4189
- }
4190
- } else if (dimString === "x" || dimString.startsWith("x")) {
4191
- this.error(
4192
- "Expected a positive integer literal or `?` after x. For example: `2x3` or `2x?`"
4193
- );
4194
- }
4195
- }
4196
- if (dimensions.length > 1) {
4197
- return dimensions;
4198
- }
4199
- }
4200
- return void 0;
4295
+ parseCaretDimensions() {
4296
+ const paren = this.match("(");
4297
+ const dimensions = this.parseDimensions();
4298
+ if (paren) this.expect(")");
4299
+ return dimensions;
4201
4300
  }
4202
4301
  parseTupleType() {
4203
4302
  if (this.current.type === "IDENTIFIER" && this.current.value === "tuple") {
@@ -4382,6 +4481,18 @@ var Parser = class {
4382
4481
  this.expect("..");
4383
4482
  const upperBound = this.parseValue();
4384
4483
  this.expect(">");
4484
+ const lower = lowerBound?.value ?? -Infinity;
4485
+ const upper = upperBound?.value ?? Infinity;
4486
+ if (Number.isNaN(lower) || Number.isNaN(upper))
4487
+ this.error(
4488
+ "Invalid numeric type",
4489
+ "Lower and upper bounds must be valid numbers"
4490
+ );
4491
+ if (lower > upper)
4492
+ this.error(
4493
+ `Invalid range: ${lower}..${upper}`,
4494
+ "The lower bound must be less than the upper bound"
4495
+ );
4385
4496
  return this.createNode("numeric", {
4386
4497
  baseType,
4387
4498
  lowerBound,
@@ -4396,7 +4507,7 @@ var Parser = class {
4396
4507
  parsePrimitiveType() {
4397
4508
  if (this.current.type === "IDENTIFIER") {
4398
4509
  const name = this.current.value;
4399
- if (PRIMITIVE_TYPES.includes(name)) {
4510
+ if (PRIMITIVE_TYPES_SET.has(name)) {
4400
4511
  this.advance();
4401
4512
  return this.createNode("primitive", { name });
4402
4513
  }
@@ -4730,14 +4841,32 @@ function buildTypeFromAST(node, typeResolver) {
4730
4841
  }
4731
4842
 
4732
4843
  // src/common/type/parse.ts
4844
+ var TYPE_CACHE = /* @__PURE__ */ new Map();
4845
+ var TYPE_CACHE_MAX_SIZE = 2048;
4846
+ function deepFreeze(obj) {
4847
+ if (obj === null || typeof obj !== "object") return obj;
4848
+ if (Object.isFrozen(obj)) return obj;
4849
+ Object.freeze(obj);
4850
+ for (const value of Object.values(obj)) deepFreeze(value);
4851
+ return obj;
4852
+ }
4733
4853
  function parseType(s, typeResolver) {
4734
4854
  if (s === void 0) return void 0;
4735
4855
  if (isValidType(s)) return s;
4736
4856
  if (typeof s !== "string") return void 0;
4857
+ const cacheable = typeResolver === void 0;
4858
+ if (cacheable) {
4859
+ const cached = TYPE_CACHE.get(s);
4860
+ if (cached !== void 0) return cached;
4861
+ }
4737
4862
  try {
4738
4863
  const parser = new Parser(s, { typeResolver });
4739
4864
  const ast = parser.parseType();
4740
4865
  const type = buildTypeFromAST(ast, typeResolver);
4866
+ if (cacheable) {
4867
+ if (TYPE_CACHE.size >= TYPE_CACHE_MAX_SIZE) TYPE_CACHE.clear();
4868
+ TYPE_CACHE.set(s, deepFreeze(type));
4869
+ }
4741
4870
  return type;
4742
4871
  } catch (error) {
4743
4872
  throw new Error(
@@ -4812,19 +4941,36 @@ var PRIMITIVE_SUBTYPES = {
4812
4941
  color: [],
4813
4942
  expression: EXPRESSION_TYPES
4814
4943
  };
4944
+ var PRIMITIVE_SUBTYPES_CLOSURE = (() => {
4945
+ const closure = {};
4946
+ const closeOver = (t) => {
4947
+ if (closure[t]) return closure[t];
4948
+ const result = /* @__PURE__ */ new Set([t]);
4949
+ closure[t] = result;
4950
+ for (const sub of PRIMITIVE_SUBTYPES[t]) {
4951
+ if (sub === t) continue;
4952
+ for (const s of closeOver(sub)) result.add(s);
4953
+ }
4954
+ return result;
4955
+ };
4956
+ for (const t of Object.keys(PRIMITIVE_SUBTYPES))
4957
+ closeOver(t);
4958
+ return closure;
4959
+ })();
4815
4960
  function isPrimitiveSubtype(lhs, rhs) {
4816
4961
  if (rhs === "any") return true;
4817
4962
  if (lhs === "never") return true;
4818
4963
  if (lhs === "unknown" || rhs === "unknown") return false;
4819
4964
  if (lhs === rhs) return true;
4820
- return PRIMITIVE_SUBTYPES[rhs].includes(lhs);
4965
+ return PRIMITIVE_SUBTYPES_CLOSURE[rhs].has(lhs);
4821
4966
  }
4822
4967
  function isSubtype(lhs, rhs) {
4823
- if (typeof lhs === "string" && !PRIMITIVE_TYPES.includes(lhs))
4968
+ if (typeof lhs === "string" && !PRIMITIVE_TYPES_SET.has(lhs))
4824
4969
  lhs = parseType(lhs);
4825
- if (typeof rhs === "string" && !PRIMITIVE_TYPES.includes(rhs))
4970
+ if (typeof rhs === "string" && !PRIMITIVE_TYPES_SET.has(rhs))
4826
4971
  rhs = parseType(rhs);
4827
4972
  if (rhs === "any") return true;
4973
+ if (lhs === "never") return true;
4828
4974
  if (rhs === "never") return false;
4829
4975
  if (rhs === "error") return lhs === "error";
4830
4976
  if (rhs === "nothing") return lhs === "nothing";
@@ -4839,7 +4985,7 @@ function isSubtype(lhs, rhs) {
4839
4985
  if (typeof lhs.value === "number") {
4840
4986
  if (Number.isInteger(lhs.value))
4841
4987
  return isPrimitiveSubtype("integer", rhs);
4842
- return isPrimitiveSubtype("number", rhs);
4988
+ return isPrimitiveSubtype("real", rhs);
4843
4989
  }
4844
4990
  if (typeof lhs.value === "boolean")
4845
4991
  return isPrimitiveSubtype("boolean", rhs);
@@ -5069,7 +5215,7 @@ function isSubtype(lhs, rhs) {
5069
5215
  }
5070
5216
  function isNumeric(type) {
5071
5217
  if (typeof type === "string")
5072
- return NUMERIC_TYPES.includes(type);
5218
+ return NUMERIC_TYPES_SET.has(type);
5073
5219
  if (type.kind === "value") return typeof type.value === "number";
5074
5220
  if (type.kind === "numeric") return true;
5075
5221
  return false;
@@ -5077,7 +5223,7 @@ function isNumeric(type) {
5077
5223
  function isScalar(type) {
5078
5224
  if (isNumeric(type)) return true;
5079
5225
  if (typeof type === "string")
5080
- return SCALAR_TYPES.includes(type);
5226
+ return SCALAR_TYPES_SET.has(type);
5081
5227
  if (type.kind === "value")
5082
5228
  return ["string", "boolean", "number"].includes(typeof type.value);
5083
5229
  return false;
@@ -5085,7 +5231,7 @@ function isScalar(type) {
5085
5231
  function isCollection(type) {
5086
5232
  if (isIndexedCollection(type)) return true;
5087
5233
  if (typeof type === "string")
5088
- return COLLECTION_TYPES.includes(type);
5234
+ return COLLECTION_TYPES_SET.has(type);
5089
5235
  return ["collection", "set", "record", "dictionary"].includes(type.kind);
5090
5236
  }
5091
5237
  function isIndexedCollection(type) {
@@ -5124,13 +5270,75 @@ function widen2(a, b) {
5124
5270
  if (b === "nothing") return a;
5125
5271
  if (isSubtype(a, b)) return b;
5126
5272
  if (isSubtype(b, a)) return a;
5127
- return superType(a, b);
5273
+ const sup = superType(a, b);
5274
+ if (LOSSY_SUPERTYPE.has(sup)) return unionTypes(a, b);
5275
+ return sup;
5276
+ }
5277
+ var LOSSY_SUPERTYPE = /* @__PURE__ */ new Set([
5278
+ "scalar",
5279
+ "value",
5280
+ "function",
5281
+ "expression",
5282
+ "collection",
5283
+ "indexed_collection",
5284
+ "list",
5285
+ "set",
5286
+ "tuple",
5287
+ "record",
5288
+ "dictionary",
5289
+ "map",
5290
+ "any"
5291
+ ]);
5292
+ function unionTypes(a, b) {
5293
+ const members = [];
5294
+ const keys = /* @__PURE__ */ new Set();
5295
+ const push = (t) => {
5296
+ if (typeof t === "object" && t.kind === "union") {
5297
+ for (const m of t.types) push(m);
5298
+ return;
5299
+ }
5300
+ const key = typeof t === "string" ? t : JSON.stringify(t);
5301
+ if (!keys.has(key)) {
5302
+ keys.add(key);
5303
+ members.push(t);
5304
+ }
5305
+ };
5306
+ push(a);
5307
+ push(b);
5308
+ if (members.length === 1) return members[0];
5309
+ return { kind: "union", types: members };
5128
5310
  }
5129
5311
  function widen(...types) {
5130
5312
  if (types.length === 0) return "nothing";
5131
5313
  if (types.length === 1) return types[0];
5132
5314
  return types.reduce((a, b) => widen2(a, b));
5133
5315
  }
5316
+ var SUPERTYPE_PROBE_ORDER = [
5317
+ "non_finite_number",
5318
+ "finite_integer",
5319
+ "integer",
5320
+ "finite_rational",
5321
+ "rational",
5322
+ "finite_real",
5323
+ "real",
5324
+ "imaginary",
5325
+ "finite_complex",
5326
+ "complex",
5327
+ "finite_number",
5328
+ "number",
5329
+ "list",
5330
+ "record",
5331
+ "dictionary",
5332
+ "set",
5333
+ "tuple",
5334
+ "indexed_collection",
5335
+ "collection",
5336
+ "scalar",
5337
+ "value",
5338
+ "function",
5339
+ "expression"
5340
+ ];
5341
+ var PRIMITIVE_SUPERTYPE_CACHE = /* @__PURE__ */ new Map();
5134
5342
  function superType(a, b) {
5135
5343
  if (a === b) return a;
5136
5344
  if (a === "any" || b === "any") return "any";
@@ -5140,35 +5348,26 @@ function superType(a, b) {
5140
5348
  if (b === "unknown") return a;
5141
5349
  if (a === "nothing") return b;
5142
5350
  if (b === "nothing") return a;
5143
- if (commonSupertype(a, b, "non_finite_number")) return "non_finite_number";
5144
- if (commonSupertype(a, b, "finite_integer")) return "finite_integer";
5145
- if (commonSupertype(a, b, "integer")) return "integer";
5146
- if (commonSupertype(a, b, "finite_rational")) return "finite_rational";
5147
- if (commonSupertype(a, b, "rational")) return "rational";
5148
- if (commonSupertype(a, b, "finite_real")) return "finite_real";
5149
- if (commonSupertype(a, b, "real")) return "real";
5150
- if (commonSupertype(a, b, "imaginary")) return "imaginary";
5151
- if (commonSupertype(a, b, "finite_complex")) return "finite_complex";
5152
- if (commonSupertype(a, b, "complex")) return "complex";
5153
- if (commonSupertype(a, b, "finite_number")) return "finite_number";
5154
- if (commonSupertype(a, b, "number")) return "number";
5155
- if (commonSupertype(a, b, "list")) return "list";
5156
- if (commonSupertype(a, b, "record")) return "record";
5157
- if (commonSupertype(a, b, "dictionary")) return "dictionary";
5158
- if (commonSupertype(a, b, "set")) return "set";
5159
- if (commonSupertype(a, b, "tuple")) return "tuple";
5160
- if (commonSupertype(a, b, "indexed_collection")) return "indexed_collection";
5161
- if (commonSupertype(a, b, "collection")) return "collection";
5162
- if (commonSupertype(a, b, "scalar")) return "scalar";
5163
- if (commonSupertype(a, b, "value")) return "value";
5164
- if (commonSupertype(a, b, "function")) return "function";
5165
- if (commonSupertype(a, b, "expression")) return "expression";
5351
+ if (typeof a === "string" && typeof b === "string") {
5352
+ const key = a < b ? `${a}|${b}` : `${b}|${a}`;
5353
+ let result = PRIMITIVE_SUPERTYPE_CACHE.get(key);
5354
+ if (result === void 0) {
5355
+ result = "any";
5356
+ for (const ancestor of SUPERTYPE_PROBE_ORDER) {
5357
+ const subtypes = PRIMITIVE_SUBTYPES_CLOSURE[ancestor];
5358
+ if (subtypes.has(a) && subtypes.has(b)) {
5359
+ result = ancestor;
5360
+ break;
5361
+ }
5362
+ }
5363
+ PRIMITIVE_SUPERTYPE_CACHE.set(key, result);
5364
+ }
5365
+ return result;
5366
+ }
5367
+ for (const ancestor of SUPERTYPE_PROBE_ORDER)
5368
+ if (isSubtype(a, ancestor) && isSubtype(b, ancestor)) return ancestor;
5166
5369
  return "any";
5167
5370
  }
5168
- function commonSupertype(a, b, ancestor) {
5169
- if (isSubtype(a, ancestor) && isSubtype(b, ancestor)) return true;
5170
- return false;
5171
- }
5172
5371
 
5173
5372
  // src/compute-engine/numeric-value/exact-numeric-value.ts
5174
5373
  var ExactNumericValue = class _ExactNumericValue extends NumericValue {
@@ -5386,6 +5585,10 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
5386
5585
  });
5387
5586
  }
5388
5587
  inv() {
5588
+ if (this.isNaN) return this;
5589
+ if (this.isPositiveInfinity || this.isNegativeInfinity)
5590
+ return this.clone(0);
5591
+ if (this.isZero) return this.clone(Infinity);
5389
5592
  if (this.isOne) return this;
5390
5593
  if (this.isNegativeOne) return this;
5391
5594
  return this.clone({
@@ -5504,7 +5707,7 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
5504
5707
  } else {
5505
5708
  if (exponent instanceof _ExactNumericValue) {
5506
5709
  if (exponent.radical === 1 && exponent.rational[0] == 1)
5507
- return this.root(exponent.rational[0]);
5710
+ return this.root(Number(exponent.rational[1]));
5508
5711
  }
5509
5712
  exponent = exponent.re;
5510
5713
  }
@@ -5639,19 +5842,52 @@ var ExactNumericValue = class _ExactNumericValue extends NumericValue {
5639
5842
  if (this.isPositiveInfinity) return this.clone(Infinity);
5640
5843
  return this.factory(this.bignumRe).exp();
5641
5844
  }
5845
+ /**
5846
+ * Floor/ceil/round of a pure rational (`radical === 1`) computed exactly with
5847
+ * bigints. Routing through `this.re` (a float) would lose digits for
5848
+ * integers/rationals larger than 2^53.
5849
+ */
5850
+ _integerPart(mode2) {
5851
+ let n = BigInt(this.rational[0]);
5852
+ let d = BigInt(this.rational[1]);
5853
+ if (d < 0n) {
5854
+ n = -n;
5855
+ d = -d;
5856
+ }
5857
+ let q;
5858
+ if (mode2 === "round") {
5859
+ const m = 2n * n + d;
5860
+ const dd = 2n * d;
5861
+ q = m / dd;
5862
+ if (m % dd !== 0n && m < 0n) q -= 1n;
5863
+ } else {
5864
+ q = n / d;
5865
+ const r = n % d;
5866
+ if (r !== 0n) {
5867
+ if (mode2 === "floor" && n < 0n) q -= 1n;
5868
+ if (mode2 === "ceil" && n > 0n) q += 1n;
5869
+ }
5870
+ }
5871
+ return this.clone({ rational: [q, BigInt(1)], radical: 1 });
5872
+ }
5873
+ // An exact value is an integer iff it has no radical part and a unit
5874
+ // denominator. (`this.type` returns `'finite_integer'`, never `'integer'`.)
5642
5875
  floor() {
5643
5876
  if (this.isNaN) return this.clone(NaN);
5644
- if (this.type === "integer") return this;
5877
+ if (this.radical === 1 && isInteger(this.rational)) return this;
5878
+ if (this.radical === 1) return this._integerPart("floor");
5645
5879
  return this.clone(Math.floor(this.re));
5646
5880
  }
5647
5881
  ceil() {
5648
5882
  if (this.isNaN) return this.clone(NaN);
5649
- if (this.type === "integer") return this;
5883
+ if (this.radical === 1 && isInteger(this.rational)) return this;
5884
+ if (this.radical === 1) return this._integerPart("ceil");
5650
5885
  return this.clone(Math.ceil(this.re));
5651
5886
  }
5652
5887
  round() {
5653
5888
  if (this.isNaN) return this.clone(NaN);
5654
- if (this.type === "integer") return this;
5889
+ if (this.radical === 1 && isInteger(this.rational)) return this;
5890
+ if (this.radical === 1) return this._integerPart("round");
5655
5891
  return this.clone(Math.round(this.re));
5656
5892
  }
5657
5893
  eq(other) {
@@ -5750,7 +5986,7 @@ function gcd3(a, b) {
5750
5986
  return a.abs();
5751
5987
  }
5752
5988
  function lcm3(a, b) {
5753
- return a.mul(b).div(gcd3(a, b));
5989
+ return a.mul(b).div(gcd3(a, b)).abs();
5754
5990
  }
5755
5991
  function* factorial22(n) {
5756
5992
  if (!n.isInteger() || n.isNegative()) return BigDecimal.NAN;
@@ -5930,8 +6166,8 @@ var BigNumericValue = class _BigNumericValue extends NumericValue {
5930
6166
  if (this.isOne) return this;
5931
6167
  if (this.isNegativeOne) return this;
5932
6168
  if (this.im === 0) return this.clone(this.decimal.inv());
5933
- const d = Math.hypot(this.re, this.im);
5934
- const bigD = this.decimal.mul(this.decimal).add(this.im * this.im).sqrt();
6169
+ const d = this.re * this.re + this.im * this.im;
6170
+ const bigD = this.decimal.mul(this.decimal).add(this.im * this.im);
5935
6171
  return this.clone({ re: this.decimal.div(bigD), im: -this.im / d });
5936
6172
  }
5937
6173
  add(other) {
@@ -5958,7 +6194,7 @@ var BigNumericValue = class _BigNumericValue extends NumericValue {
5958
6194
  if (other === 1) return this;
5959
6195
  if (other === -1) return this.neg();
5960
6196
  if (other === 0) {
5961
- if (this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
6197
+ if (this.isNaN || this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
5962
6198
  return this._makeExact(NaN);
5963
6199
  return this.clone(0);
5964
6200
  }
@@ -5988,7 +6224,7 @@ var BigNumericValue = class _BigNumericValue extends NumericValue {
5988
6224
  if (other.isOne) return this;
5989
6225
  if (other.isNegativeOne) return this.neg();
5990
6226
  if (other.isZero) {
5991
- if (this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
6227
+ if (this.isNaN || this.isPositiveInfinity || this.isNegativeInfinity || this.isComplexInfinity)
5992
6228
  return this._makeExact(NaN);
5993
6229
  return this.clone(0);
5994
6230
  }
@@ -6011,7 +6247,11 @@ var BigNumericValue = class _BigNumericValue extends NumericValue {
6011
6247
  }
6012
6248
  if (other.isOne) return this;
6013
6249
  if (other.isNegativeOne) return this.neg();
6014
- if (other.isZero) return this.clone(this.isZero ? NaN : Infinity);
6250
+ if (other.isZero) {
6251
+ if (this.isZero || this.isNaN) return this.clone(NaN);
6252
+ if (this.im !== 0) return this.clone({ im: Infinity });
6253
+ return this.clone(this.decimal.isNegative() ? -Infinity : Infinity);
6254
+ }
6015
6255
  if (this.im === 0 && other.im === 0)
6016
6256
  return this.clone(this.decimal.div(other.bignumRe ?? other.re));
6017
6257
  const [a, b] = [this.re, this.im];
@@ -6045,13 +6285,18 @@ var BigNumericValue = class _BigNumericValue extends NumericValue {
6045
6285
  if (this.im === Infinity) return this.clone(NaN);
6046
6286
  if (this.isNegativeInfinity) return this.clone(0);
6047
6287
  if (this.isPositiveInfinity) return this.clone({ im: Infinity });
6048
- const zRe = this.pow(re);
6049
- const zArg = this.decimal.ln().mul(im);
6050
- const zIm = this.clone({
6051
- re: zArg.cos(),
6052
- im: chop2(zArg.sin().toNumber())
6288
+ if (this.isZero) return re > 0 ? this.clone(0) : this.clone(NaN);
6289
+ const a2 = this.decimal;
6290
+ const b2 = this.im;
6291
+ const lnMod = a2.mul(a2).add(b2 * b2).sqrt().ln();
6292
+ const arg = BigDecimal.atan2(b2, a2);
6293
+ const realExp = lnMod.mul(re).sub(arg.mul(im));
6294
+ const imagExp = arg.mul(re).add(lnMod.mul(im));
6295
+ const mag = realExp.exp();
6296
+ return this.clone({
6297
+ re: mag.mul(imagExp.cos()),
6298
+ im: chop2(mag.mul(imagExp.sin()).toNumber())
6053
6299
  });
6054
- return zRe.mul(zIm);
6055
6300
  }
6056
6301
  }
6057
6302
  if (this.isPositiveInfinity) {
@@ -6095,13 +6340,13 @@ var BigNumericValue = class _BigNumericValue extends NumericValue {
6095
6340
  if (this.decimal.isNegative()) return this._makeExact(NaN);
6096
6341
  if (exp === 2) return this.clone(this.decimal.sqrt());
6097
6342
  if (exp === 3) return this.clone(this.decimal.cbrt());
6098
- return this.clone(this.decimal.pow(1 / exp));
6343
+ return this.clone(this.decimal.ln().div(exp).exp());
6099
6344
  }
6100
6345
  const a = this.decimal;
6101
6346
  const b = this.im;
6102
6347
  const modulus = a.mul(a).add(b * b).sqrt();
6103
6348
  const argument = BigDecimal.atan2(b, a);
6104
- const newModulus = modulus.pow(1 / exp);
6349
+ const newModulus = modulus.ln().div(exp).exp();
6105
6350
  const newArgument = argument.div(exp);
6106
6351
  return this.clone({
6107
6352
  re: newModulus.mul(newArgument.cos()),
@@ -6367,7 +6612,7 @@ var MachineNumericValue = class _MachineNumericValue extends NumericValue {
6367
6612
  if (this.isOne) return this;
6368
6613
  if (this.isNegativeOne) return this;
6369
6614
  if (this.im === 0) return this.clone(1 / this.decimal);
6370
- const d = Math.hypot(this.re, this.im);
6615
+ const d = this.re * this.re + this.im * this.im;
6371
6616
  return this.clone({ re: this.decimal / d, im: -this.im / d });
6372
6617
  }
6373
6618
  add(other) {
@@ -6477,11 +6722,17 @@ var MachineNumericValue = class _MachineNumericValue extends NumericValue {
6477
6722
  if (this.im === Infinity) return this.clone(NaN);
6478
6723
  if (this.isNegativeInfinity) return this.clone(0);
6479
6724
  if (this.isPositiveInfinity) return this.clone({ im: Infinity });
6480
- const zRe = this.pow(re).re;
6481
- const zArg = Math.log(this.decimal) * im;
6725
+ if (this.isZero) return re > 0 ? this.clone(0) : this.clone(NaN);
6726
+ const a2 = this.decimal;
6727
+ const b2 = this.im;
6728
+ const lnMod = 0.5 * Math.log(a2 * a2 + b2 * b2);
6729
+ const arg = Math.atan2(b2, a2);
6730
+ const realExp = re * lnMod - im * arg;
6731
+ const imagExp = re * arg + im * lnMod;
6732
+ const mag = Math.exp(realExp);
6482
6733
  return this.clone({
6483
- re: chop3(zRe * Math.cos(zArg)),
6484
- im: chop3(zRe * Math.sin(zArg))
6734
+ re: chop3(mag * Math.cos(imagExp)),
6735
+ im: chop3(mag * Math.sin(imagExp))
6485
6736
  });
6486
6737
  }
6487
6738
  }
@@ -6500,14 +6751,15 @@ var MachineNumericValue = class _MachineNumericValue extends NumericValue {
6500
6751
  if (exponent > 0) return this;
6501
6752
  if (exponent < 0) return this.clone({ im: Infinity });
6502
6753
  }
6503
- if (exponent < 0) return this.clone(1 / this.decimal ** -exponent);
6754
+ if (exponent < 0 && this.im === 0)
6755
+ return this.clone(1 / this.decimal ** -exponent);
6504
6756
  if (this.im === 0) return this.clone(this.decimal ** exponent);
6505
6757
  const a = this.decimal;
6506
6758
  const b = this.im;
6507
6759
  const modulus = Math.sqrt(a * a + b * b);
6508
6760
  const argument = Math.atan2(b, a);
6509
6761
  const newModulus = modulus ** exponent;
6510
- const newArgument = argument ** exponent;
6762
+ const newArgument = argument * exponent;
6511
6763
  return this.clone({
6512
6764
  re: newModulus * Math.cos(newArgument),
6513
6765
  im: newModulus * Math.sin(newArgument)
@@ -6628,10 +6880,10 @@ var MachineNumericValue = class _MachineNumericValue extends NumericValue {
6628
6880
  eq(other) {
6629
6881
  if (this.isNaN) return false;
6630
6882
  if (typeof other === "number")
6631
- return this.im === 0 && this.decimal - other === 0;
6883
+ return this.im === 0 && this.decimal === other;
6632
6884
  if (other.isNaN) return false;
6633
6885
  if (!Number.isFinite(this.im)) return !Number.isFinite(other.im);
6634
- return this.decimal - other.re === 0 && this.im - other.im === 0;
6886
+ return this.decimal === other.re && this.im === other.im;
6635
6887
  }
6636
6888
  lt(other) {
6637
6889
  if (this.im !== 0) return void 0;
@@ -6713,42 +6965,20 @@ function interval(expr) {
6713
6965
  return void 0;
6714
6966
  }
6715
6967
  function intervalContains(int, val) {
6716
- if (int.openStart) {
6717
- if (int.start <= val) return false;
6718
- }
6719
- if (int.start < val) return false;
6720
- if (int.openEnd) {
6721
- if (int.end >= val) return false;
6722
- }
6723
- if (int.end > val) return false;
6968
+ if (int.openStart ? val <= int.start : val < int.start) return false;
6969
+ if (int.openEnd ? val >= int.end : val > int.end) return false;
6724
6970
  return true;
6725
6971
  }
6726
6972
  function intervalSubset(int1, int2) {
6727
- if (int1.openStart) {
6728
- if (int2.openStart) {
6729
- if (int1.start <= int2.start) return false;
6730
- } else {
6731
- if (int1.start < int2.start) return false;
6732
- }
6973
+ if (!int1.openStart && int2.openStart) {
6974
+ if (int1.start <= int2.start) return false;
6733
6975
  } else {
6734
- if (int2.openStart) {
6735
- if (int1.start <= int2.start) return false;
6736
- } else {
6737
- if (int1.start < int2.start) return false;
6738
- }
6976
+ if (int1.start < int2.start) return false;
6739
6977
  }
6740
- if (int1.openEnd) {
6741
- if (int2.openEnd) {
6742
- if (int1.end >= int2.end) return false;
6743
- } else {
6744
- if (int1.end > int2.end) return false;
6745
- }
6978
+ if (!int1.openEnd && int2.openEnd) {
6979
+ if (int1.end >= int2.end) return false;
6746
6980
  } else {
6747
- if (int2.openEnd) {
6748
- if (int1.end >= int2.end) return false;
6749
- } else {
6750
- if (int1.end > int2.end) return false;
6751
- }
6981
+ if (int1.end > int2.end) return false;
6752
6982
  }
6753
6983
  return true;
6754
6984
  }
@@ -6931,6 +7161,7 @@ function bigPopulationStandardDeviation(values) {
6931
7161
  function kurtosis(values) {
6932
7162
  let sum = 0;
6933
7163
  let sum2 = 0;
7164
+ let sum3 = 0;
6934
7165
  let sum4 = 0;
6935
7166
  let count = 0;
6936
7167
  for (const op of values) {
@@ -6938,16 +7169,21 @@ function kurtosis(values) {
6938
7169
  if (!Number.isFinite(v)) return NaN;
6939
7170
  sum += v;
6940
7171
  sum2 += v * v;
7172
+ sum3 += v * v * v;
6941
7173
  sum4 += v * v * v * v;
6942
7174
  count++;
6943
7175
  }
6944
7176
  if (count === 0) return NaN;
6945
- const s2 = (sum2 - sum * sum / count) / (count - 1);
6946
- return (sum4 - 4 * sum * sum2 / count + 6 * sum * sum * sum / count / count - 3 * sum * sum * sum * sum / count / count / count) / (s2 * s2);
7177
+ const n = count;
7178
+ const m = sum / n;
7179
+ const m2 = (sum2 - sum * sum / n) / n;
7180
+ const m4 = (sum4 - 4 * m * sum3 + 6 * m * m * sum2 - 4 * m * m * m * sum + n * m * m * m * m) / n;
7181
+ return m4 / (m2 * m2);
6947
7182
  }
6948
7183
  function bigKurtosis(values) {
6949
7184
  let sum = BigDecimal.ZERO;
6950
7185
  let sum2 = BigDecimal.ZERO;
7186
+ let sum3 = BigDecimal.ZERO;
6951
7187
  let sum4 = BigDecimal.ZERO;
6952
7188
  let count = 0;
6953
7189
  for (const op of values) {
@@ -6955,15 +7191,15 @@ function bigKurtosis(values) {
6955
7191
  if (!v.isFinite()) return BigDecimal.NAN;
6956
7192
  sum = sum.add(v);
6957
7193
  sum2 = sum2.add(v.mul(v));
7194
+ sum3 = sum3.add(v.mul(v).mul(v));
6958
7195
  sum4 = sum4.add(v.mul(v).mul(v).mul(v));
6959
7196
  count++;
6960
7197
  }
6961
7198
  if (count === 0) return BigDecimal.NAN;
6962
- const bdCount = new BigDecimal(count);
6963
- const s2 = sum2.sub(sum.mul(sum).div(bdCount)).div(new BigDecimal(count - 1));
6964
- return sum4.sub(sum.mul(sum2).mul(new BigDecimal(4)).div(bdCount)).add(sum.mul(sum).mul(sum).mul(new BigDecimal(6)).div(bdCount).div(bdCount)).sub(
6965
- sum.mul(sum).mul(sum).mul(sum).mul(new BigDecimal(3)).div(bdCount).div(bdCount).div(bdCount)
6966
- ).div(s2.mul(s2));
7199
+ const m = sum.div(count);
7200
+ const m2 = sum2.sub(sum.mul(sum).div(count)).div(count);
7201
+ const m4 = sum4.sub(m.mul(sum3).mul(4)).add(m.mul(m).mul(sum2).mul(6)).sub(m.mul(m).mul(m).mul(sum).mul(4)).add(m.mul(m).mul(m).mul(m).mul(count)).div(count);
7202
+ return m4.div(m2.mul(m2));
6967
7203
  }
6968
7204
  function skewness(values) {
6969
7205
  let sum = 0;
@@ -6979,9 +7215,11 @@ function skewness(values) {
6979
7215
  count++;
6980
7216
  }
6981
7217
  if (count === 0) return NaN;
6982
- const s2 = (sum2 - sum * sum / count) / (count - 1);
6983
- const s3 = (sum3 - sum2 * sum / count) / (count - 1);
6984
- return s3 / Math.pow(s2, 3 / 2) * Math.sqrt(count * 1);
7218
+ const n = count;
7219
+ const m = sum / n;
7220
+ const m2 = (sum2 - sum * sum / n) / n;
7221
+ const m3 = (sum3 - 3 * m * sum2 + 3 * m * m * sum - n * m * m * m) / n;
7222
+ return m3 / Math.pow(m2, 3 / 2);
6985
7223
  }
6986
7224
  function bigSkewness(values) {
6987
7225
  let sum = BigDecimal.ZERO;
@@ -6997,10 +7235,10 @@ function bigSkewness(values) {
6997
7235
  count++;
6998
7236
  }
6999
7237
  if (count === 0) return BigDecimal.NAN;
7000
- const bdCount = new BigDecimal(count);
7001
- const s2 = sum2.sub(sum.mul(sum).div(bdCount)).div(new BigDecimal(count - 1));
7002
- const s3 = sum3.sub(sum2.mul(sum).div(bdCount)).div(new BigDecimal(count - 1));
7003
- return s3.div(s2.pow(new BigDecimal(1.5))).mul(bdCount.sqrt());
7238
+ const m = sum.div(count);
7239
+ const m2 = sum2.sub(sum.mul(sum).div(count)).div(count);
7240
+ const m3 = sum3.sub(m.mul(sum2).mul(3)).add(m.mul(m).mul(sum).mul(3)).sub(m.mul(m).mul(m).mul(count)).div(count);
7241
+ return m3.div(m2.mul(m2.sqrt()));
7004
7242
  }
7005
7243
  function mode(values) {
7006
7244
  const counts = {};
@@ -7051,18 +7289,12 @@ function bigQuartiles(values) {
7051
7289
  return [q1, q2, q3];
7052
7290
  }
7053
7291
  function interquartileRange(values) {
7054
- const sorted = [...values].sort((a, b) => a - b);
7055
- const mid = Math.floor(sorted.length / 2);
7056
- const lower = sorted.slice(0, mid);
7057
- const upper = sorted.slice(mid + 1);
7058
- return median(upper) - median(lower);
7292
+ const [q1, , q3] = quartiles(values);
7293
+ return q3 - q1;
7059
7294
  }
7060
7295
  function bigInterquartileRange(values) {
7061
- const sorted = [...values].sort((a, b) => a.cmp(b));
7062
- const mid = Math.floor(sorted.length / 2);
7063
- const lower = sorted.slice(0, mid);
7064
- const upper = sorted.slice(mid + 1);
7065
- return bigMedian(upper).sub(bigMedian(lower));
7296
+ const [q1, , q3] = bigQuartiles(values);
7297
+ return q3.sub(q1);
7066
7298
  }
7067
7299
 
7068
7300
  // src/compute-engine/numerics/unit-data.ts
@@ -7437,9 +7669,14 @@ var lanczos_7_c = [
7437
7669
  ];
7438
7670
  function gammaln(z) {
7439
7671
  if (z < 0) return NaN;
7672
+ let shift = 0;
7673
+ while (z < 10) {
7674
+ shift += Math.log(z);
7675
+ z += 1;
7676
+ }
7440
7677
  const pi = Math.PI;
7441
7678
  const z3 = z * z * z;
7442
- return z * Math.log(z) - z - 0.5 * Math.log(z) + 0.5 * Math.log(2 * pi) + 1 / (12 * z) - 1 / (360 * z3) + 1 / (1260 * z3 * z * z);
7679
+ return z * Math.log(z) - z - 0.5 * Math.log(z) + 0.5 * Math.log(2 * pi) + 1 / (12 * z) - 1 / (360 * z3) + 1 / (1260 * z3 * z * z) - shift;
7443
7680
  }
7444
7681
  function gamma(z) {
7445
7682
  if (z < 0.5) return Math.PI / (Math.sin(Math.PI * z) * gamma(1 - z));
@@ -7450,31 +7687,62 @@ function gamma(z) {
7450
7687
  const t = z + gammaG + 0.5;
7451
7688
  return Math.sqrt(2 * Math.PI) * Math.pow(t, z + 0.5) * Math.exp(-t) * x;
7452
7689
  }
7690
+ function erfInvApprox(x) {
7691
+ const a = 0.147;
7692
+ const ln1mx2 = Math.log(1 - x * x);
7693
+ const b = 2 / (Math.PI * a) + ln1mx2 / 2;
7694
+ return Math.sign(x) * Math.sqrt(Math.sqrt(b * b - ln1mx2 / a) - b);
7695
+ }
7453
7696
  function erfInv(x) {
7454
- const pi = Math.PI;
7455
- const pi2 = pi * pi;
7456
- const pi3 = pi2 * pi;
7457
- const x2 = x * x;
7458
- const x3 = x * x2;
7459
- const x5 = x3 * x2;
7460
- const x7 = x5 * x2;
7461
- return Math.sqrt(pi) / 2 * (x + pi / 12 * x3 + 7 * pi2 / 480 * x5 + 127 * pi3 / 40320 * x7 + 4369 * pi2 * pi2 / 5806080 * x7 * x2 + 34807 * pi3 * pi2 / 182476800 * x7 * x2 * x2);
7697
+ if (Number.isNaN(x) || x < -1 || x > 1) return NaN;
7698
+ if (x === 0) return 0;
7699
+ if (x === 1) return Infinity;
7700
+ if (x === -1) return -Infinity;
7701
+ const sign = x < 0 ? -1 : 1;
7702
+ const ax = Math.abs(x);
7703
+ let y = erfInvApprox(ax);
7704
+ const c = Math.sqrt(Math.PI) / 2;
7705
+ for (let i = 0; i < 4; i++) y -= (erf(y) - ax) * c * Math.exp(y * y);
7706
+ return sign * y;
7462
7707
  }
7463
7708
  function erfc(x) {
7464
- return 1 - erf(x);
7709
+ if (Number.isNaN(x)) return NaN;
7710
+ if (!Number.isFinite(x)) return x > 0 ? 0 : 2;
7711
+ if (x < 0) return 2 - erfc(-x);
7712
+ if (x < 2) return 1 - erf(x);
7713
+ const tiny = 1e-300;
7714
+ let f = x === 0 ? tiny : x;
7715
+ let c = f;
7716
+ let d = 0;
7717
+ for (let k = 1; k <= 500; k++) {
7718
+ const a = k / 2;
7719
+ d = x + a * d;
7720
+ if (d === 0) d = tiny;
7721
+ d = 1 / d;
7722
+ c = x + a / c;
7723
+ if (c === 0) c = tiny;
7724
+ const delta = c * d;
7725
+ f *= delta;
7726
+ if (Math.abs(delta - 1) < 1e-17) break;
7727
+ }
7728
+ return Math.exp(-x * x) / (Math.sqrt(Math.PI) * f);
7465
7729
  }
7466
7730
  function erf(x) {
7467
- const a1 = 0.254829592;
7468
- const a2 = -0.284496736;
7469
- const a3 = 1.421413741;
7470
- const a4 = -1.453152027;
7471
- const a5 = 1.061405429;
7472
- const p = 0.3275911;
7731
+ if (Number.isNaN(x)) return NaN;
7732
+ if (x === 0) return 0;
7733
+ if (!Number.isFinite(x)) return x > 0 ? 1 : -1;
7473
7734
  const sign = x < 0 ? -1 : 1;
7474
- x = Math.abs(x);
7475
- const t = 1 / (1 + p * x);
7476
- const y = ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t;
7477
- return sign * (1 - y * Math.exp(-x * x));
7735
+ const ax = Math.abs(x);
7736
+ if (ax >= 6) return sign;
7737
+ const x2 = ax * ax;
7738
+ let term = ax;
7739
+ let sum = ax;
7740
+ for (let n = 1; n < 200; n++) {
7741
+ term *= 2 * x2 / (2 * n + 1);
7742
+ sum += term;
7743
+ if (term < sum * 1e-18) break;
7744
+ }
7745
+ return sign * (2 / Math.sqrt(Math.PI)) * Math.exp(-x2) * sum;
7478
7746
  }
7479
7747
  function bigGammaln(ce, z) {
7480
7748
  if (!z.isFinite()) return BigDecimal.NAN;
@@ -8424,7 +8692,7 @@ function fresnelS(x) {
8424
8692
  const t = x2 * x2;
8425
8693
  return sign * x * x2 * polevl(t, SN) / polevl(t, SD);
8426
8694
  }
8427
- if (x < 36) {
8695
+ if (x < 36974) {
8428
8696
  const x2 = x * x;
8429
8697
  const t = Math.PI * x2;
8430
8698
  const u = 1 / (t * t);
@@ -8449,7 +8717,7 @@ function fresnelC(x) {
8449
8717
  const t = x2 * x2;
8450
8718
  return sign * x * polevl(t, CN) / polevl(t, CD);
8451
8719
  }
8452
- if (x < 36) {
8720
+ if (x < 36974) {
8453
8721
  const x2 = x * x;
8454
8722
  const t = Math.PI * x2;
8455
8723
  const u = 1 / (t * t);
@@ -8466,16 +8734,894 @@ function sinc(x) {
8466
8734
  return x === 0 ? 1 : Math.sin(x) / x;
8467
8735
  }
8468
8736
 
8737
+ // node_modules/complex-esm/dist/src/complex.js
8738
+ var cosh = Math.cosh || function(x) {
8739
+ return Math.abs(x) < 1e-9 ? 1 - x : (Math.exp(x) + Math.exp(-x)) * 0.5;
8740
+ };
8741
+ var sinh = Math.sinh || function(x) {
8742
+ return Math.abs(x) < 1e-9 ? x : (Math.exp(x) - Math.exp(-x)) * 0.5;
8743
+ };
8744
+ var cosm1 = function(x) {
8745
+ var b = Math.PI / 4;
8746
+ if (-b > x || x > b) {
8747
+ return Math.cos(x) - 1;
8748
+ }
8749
+ var xx = x * x;
8750
+ return xx * (xx * (xx * (xx * (xx * (xx * (xx * (xx / 20922789888e3 - 1 / 87178291200) + 1 / 479001600) - 1 / 3628800) + 1 / 40320) - 1 / 720) + 1 / 24) - 1 / 2);
8751
+ };
8752
+ var hypot = function(x, y) {
8753
+ var a = Math.abs(x);
8754
+ var b = Math.abs(y);
8755
+ if (a < 3e3 && b < 3e3) {
8756
+ return Math.sqrt(a * a + b * b);
8757
+ }
8758
+ if (a < b) {
8759
+ a = b;
8760
+ b = x / y;
8761
+ } else {
8762
+ b = y / x;
8763
+ }
8764
+ return a * Math.sqrt(1 + b * b);
8765
+ };
8766
+ var parser_exit = function() {
8767
+ throw SyntaxError("Invalid Param");
8768
+ };
8769
+ function logHypot(a, b) {
8770
+ var _a = Math.abs(a);
8771
+ var _b = Math.abs(b);
8772
+ if (a === 0) {
8773
+ return Math.log(_b);
8774
+ }
8775
+ if (b === 0) {
8776
+ return Math.log(_a);
8777
+ }
8778
+ if (_a < 3e3 && _b < 3e3) {
8779
+ return Math.log(a * a + b * b) * 0.5;
8780
+ }
8781
+ a = a / 2;
8782
+ b = b / 2;
8783
+ return 0.5 * Math.log(a * a + b * b) + Math.LN2;
8784
+ }
8785
+ var parse = function(a, b) {
8786
+ var z = { "re": 0, "im": 0 };
8787
+ if (a === void 0 || a === null) {
8788
+ z["re"] = z["im"] = 0;
8789
+ } else if (b !== void 0) {
8790
+ z["re"] = a;
8791
+ z["im"] = b;
8792
+ } else
8793
+ switch (typeof a) {
8794
+ case "object":
8795
+ if ("im" in a && "re" in a) {
8796
+ z["re"] = a["re"];
8797
+ z["im"] = a["im"];
8798
+ } else if ("abs" in a && "arg" in a) {
8799
+ if (!Number.isFinite(a["abs"]) && Number.isFinite(a["arg"])) {
8800
+ return Complex["INFINITY"];
8801
+ }
8802
+ z["re"] = a["abs"] * Math.cos(a["arg"]);
8803
+ z["im"] = a["abs"] * Math.sin(a["arg"]);
8804
+ } else if ("r" in a && "phi" in a) {
8805
+ if (!Number.isFinite(a["r"]) && Number.isFinite(a["phi"])) {
8806
+ return Complex["INFINITY"];
8807
+ }
8808
+ z["re"] = a["r"] * Math.cos(a["phi"]);
8809
+ z["im"] = a["r"] * Math.sin(a["phi"]);
8810
+ } else if (a.length === 2) {
8811
+ z["re"] = a[0];
8812
+ z["im"] = a[1];
8813
+ } else {
8814
+ parser_exit();
8815
+ }
8816
+ break;
8817
+ case "string":
8818
+ z["im"] = /* void */
8819
+ z["re"] = 0;
8820
+ var tokens = a.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g);
8821
+ var plus = 1;
8822
+ var minus = 0;
8823
+ if (tokens === null) {
8824
+ parser_exit();
8825
+ }
8826
+ for (var i = 0; i < tokens.length; i++) {
8827
+ var c = tokens[i];
8828
+ if (c === " " || c === " " || c === "\n") {
8829
+ } else if (c === "+") {
8830
+ plus++;
8831
+ } else if (c === "-") {
8832
+ minus++;
8833
+ } else if (c === "i" || c === "I") {
8834
+ if (plus + minus === 0) {
8835
+ parser_exit();
8836
+ }
8837
+ if (tokens[i + 1] !== " " && !isNaN(Number(tokens[i + 1]))) {
8838
+ z["im"] += parseFloat((minus % 2 ? "-" : "") + tokens[i + 1]);
8839
+ i++;
8840
+ } else {
8841
+ z["im"] += parseFloat((minus % 2 ? "-" : "") + "1");
8842
+ }
8843
+ plus = minus = 0;
8844
+ } else {
8845
+ if (plus + minus === 0 || isNaN(Number(c))) {
8846
+ parser_exit();
8847
+ }
8848
+ if (tokens[i + 1] === "i" || tokens[i + 1] === "I") {
8849
+ z["im"] += parseFloat((minus % 2 ? "-" : "") + c);
8850
+ i++;
8851
+ } else {
8852
+ z["re"] += parseFloat((minus % 2 ? "-" : "") + c);
8853
+ }
8854
+ plus = minus = 0;
8855
+ }
8856
+ }
8857
+ if (plus + minus > 0) {
8858
+ parser_exit();
8859
+ }
8860
+ break;
8861
+ case "number":
8862
+ z["im"] = 0;
8863
+ z["re"] = a;
8864
+ break;
8865
+ default:
8866
+ parser_exit();
8867
+ }
8868
+ if (isNaN(z["re"]) || isNaN(z["im"])) {
8869
+ }
8870
+ return z;
8871
+ };
8872
+ var Complex = class _Complex {
8873
+ constructor(a, b) {
8874
+ this.re = 0;
8875
+ this.im = 0;
8876
+ var z = parse(a, b);
8877
+ this["re"] = z["re"];
8878
+ this["im"] = z["im"];
8879
+ }
8880
+ /**
8881
+ * Calculates the sign of a complex number, which is a normalized complex
8882
+ *
8883
+ * @returns {Complex}
8884
+ */
8885
+ sign() {
8886
+ var abs = this["abs"]();
8887
+ return new _Complex(this["re"] / abs, this["im"] / abs);
8888
+ }
8889
+ /**
8890
+ * Adds two complex numbers
8891
+ *
8892
+ * @returns {Complex}
8893
+ */
8894
+ add(a, b) {
8895
+ var z = new _Complex(a, b);
8896
+ if (this["isInfinite"]() && z["isInfinite"]()) {
8897
+ return _Complex["NAN"];
8898
+ }
8899
+ if (this["isInfinite"]() || z["isInfinite"]()) {
8900
+ return _Complex["INFINITY"];
8901
+ }
8902
+ return new _Complex(this["re"] + z["re"], this["im"] + z["im"]);
8903
+ }
8904
+ /**
8905
+ * Subtracts two complex numbers
8906
+ *
8907
+ * @returns {Complex}
8908
+ */
8909
+ sub(a, b) {
8910
+ var z = new _Complex(a, b);
8911
+ if (this["isInfinite"]() && z["isInfinite"]()) {
8912
+ return _Complex["NAN"];
8913
+ }
8914
+ if (this["isInfinite"]() || z["isInfinite"]()) {
8915
+ return _Complex["INFINITY"];
8916
+ }
8917
+ return new _Complex(this["re"] - z["re"], this["im"] - z["im"]);
8918
+ }
8919
+ /**
8920
+ * Multiplies two complex numbers
8921
+ *
8922
+ * @returns {Complex}
8923
+ */
8924
+ mul(a, b) {
8925
+ var z = new _Complex(a, b);
8926
+ if (this["isInfinite"]() && z["isZero"]() || this["isZero"]() && z["isInfinite"]()) {
8927
+ return _Complex["NAN"];
8928
+ }
8929
+ if (this["isInfinite"]() || z["isInfinite"]()) {
8930
+ return _Complex["INFINITY"];
8931
+ }
8932
+ if (z["im"] === 0 && this["im"] === 0) {
8933
+ return new _Complex(this["re"] * z["re"], 0);
8934
+ }
8935
+ return new _Complex(this["re"] * z["re"] - this["im"] * z["im"], this["re"] * z["im"] + this["im"] * z["re"]);
8936
+ }
8937
+ /**
8938
+ * Divides two complex numbers
8939
+ *
8940
+ * @returns {Complex}
8941
+ */
8942
+ div(a, b) {
8943
+ var z = new _Complex(a, b);
8944
+ if (this["isZero"]() && z["isZero"]() || this["isInfinite"]() && z["isInfinite"]()) {
8945
+ return _Complex["NAN"];
8946
+ }
8947
+ if (this["isInfinite"]() || z["isZero"]()) {
8948
+ return _Complex["INFINITY"];
8949
+ }
8950
+ if (this["isZero"]() || z["isInfinite"]()) {
8951
+ return _Complex["ZERO"];
8952
+ }
8953
+ a = this["re"];
8954
+ b = this["im"];
8955
+ var c = z["re"];
8956
+ var d = z["im"];
8957
+ var t, x;
8958
+ if (0 === d) {
8959
+ return new _Complex(a / c, b / c);
8960
+ }
8961
+ if (Math.abs(c) < Math.abs(d)) {
8962
+ x = c / d;
8963
+ t = c * x + d;
8964
+ return new _Complex((a * x + b) / t, (b * x - a) / t);
8965
+ } else {
8966
+ x = d / c;
8967
+ t = d * x + c;
8968
+ return new _Complex((a + b * x) / t, (b - a * x) / t);
8969
+ }
8970
+ }
8971
+ /**
8972
+ * Calculate the power of two complex numbers
8973
+ *
8974
+ * @returns {Complex}
8975
+ */
8976
+ pow(a, b) {
8977
+ var z = new _Complex(a, b);
8978
+ a = this["re"];
8979
+ b = this["im"];
8980
+ if (z["isZero"]()) {
8981
+ return _Complex["ONE"];
8982
+ }
8983
+ if (z["im"] === 0) {
8984
+ if (b === 0 && a > 0) {
8985
+ return new _Complex(Math.pow(a, z["re"]), 0);
8986
+ } else if (a === 0) {
8987
+ switch ((z["re"] % 4 + 4) % 4) {
8988
+ case 0:
8989
+ return new _Complex(Math.pow(b, z["re"]), 0);
8990
+ case 1:
8991
+ return new _Complex(0, Math.pow(b, z["re"]));
8992
+ case 2:
8993
+ return new _Complex(-Math.pow(b, z["re"]), 0);
8994
+ case 3:
8995
+ return new _Complex(0, -Math.pow(b, z["re"]));
8996
+ }
8997
+ }
8998
+ }
8999
+ if (a === 0 && b === 0 && z["re"] > 0 && z["im"] >= 0) {
9000
+ return _Complex["ZERO"];
9001
+ }
9002
+ var arg = Math.atan2(b, a);
9003
+ var loh = logHypot(a, b);
9004
+ a = Math.exp(z["re"] * loh - z["im"] * arg);
9005
+ b = z["im"] * loh + z["re"] * arg;
9006
+ return new _Complex(a * Math.cos(b), a * Math.sin(b));
9007
+ }
9008
+ /**
9009
+ * Calculate the complex square root
9010
+ *
9011
+ * @returns {Complex}
9012
+ */
9013
+ sqrt() {
9014
+ var a = this["re"];
9015
+ var b = this["im"];
9016
+ var r = this["abs"]();
9017
+ var re, im;
9018
+ if (a >= 0) {
9019
+ if (b === 0) {
9020
+ return new _Complex(Math.sqrt(a), 0);
9021
+ }
9022
+ re = 0.5 * Math.sqrt(2 * (r + a));
9023
+ } else {
9024
+ re = Math.abs(b) / Math.sqrt(2 * (r - a));
9025
+ }
9026
+ if (a <= 0) {
9027
+ im = 0.5 * Math.sqrt(2 * (r - a));
9028
+ } else {
9029
+ im = Math.abs(b) / Math.sqrt(2 * (r + a));
9030
+ }
9031
+ return new _Complex(re, b < 0 ? -im : im);
9032
+ }
9033
+ /**
9034
+ * Calculate the complex exponent
9035
+ *
9036
+ * @returns {Complex}
9037
+ */
9038
+ exp() {
9039
+ var tmp = Math.exp(this["re"]);
9040
+ if (this["im"] === 0) {
9041
+ }
9042
+ return new _Complex(tmp * Math.cos(this["im"]), tmp * Math.sin(this["im"]));
9043
+ }
9044
+ /**
9045
+ * Calculate the complex exponent and subtracts one.
9046
+ *
9047
+ * This may be more accurate than `Complex(x).exp().sub(1)` if
9048
+ * `x` is small.
9049
+ *
9050
+ * @returns {Complex}
9051
+ */
9052
+ expm1() {
9053
+ var a = this["re"];
9054
+ var b = this["im"];
9055
+ return new _Complex(Math.expm1(a) * Math.cos(b) + cosm1(b), Math.exp(a) * Math.sin(b));
9056
+ }
9057
+ /**
9058
+ * Calculate the natural log
9059
+ *
9060
+ * @returns {Complex}
9061
+ */
9062
+ log() {
9063
+ var a = this["re"];
9064
+ var b = this["im"];
9065
+ if (b === 0 && a > 0) {
9066
+ }
9067
+ return new _Complex(logHypot(a, b), Math.atan2(b, a));
9068
+ }
9069
+ /**
9070
+ * Calculate the magnitude of the complex number
9071
+ *
9072
+ * @returns {number}
9073
+ */
9074
+ abs() {
9075
+ return hypot(this["re"], this["im"]);
9076
+ }
9077
+ /**
9078
+ * Calculate the angle of the complex number
9079
+ *
9080
+ * @returns {number}
9081
+ */
9082
+ arg() {
9083
+ return Math.atan2(this["im"], this["re"]);
9084
+ }
9085
+ /**
9086
+ * Calculate the sine of the complex number
9087
+ *
9088
+ * @returns {Complex}
9089
+ */
9090
+ sin() {
9091
+ var a = this["re"];
9092
+ var b = this["im"];
9093
+ return new _Complex(Math.sin(a) * cosh(b), Math.cos(a) * sinh(b));
9094
+ }
9095
+ /**
9096
+ * Calculate the cosine
9097
+ *
9098
+ * @returns {Complex}
9099
+ */
9100
+ cos() {
9101
+ var a = this["re"];
9102
+ var b = this["im"];
9103
+ return new _Complex(Math.cos(a) * cosh(b), -Math.sin(a) * sinh(b));
9104
+ }
9105
+ /**
9106
+ * Calculate the tangent
9107
+ *
9108
+ * @returns {Complex}
9109
+ */
9110
+ tan() {
9111
+ var a = 2 * this["re"];
9112
+ var b = 2 * this["im"];
9113
+ var d = Math.cos(a) + cosh(b);
9114
+ return new _Complex(Math.sin(a) / d, sinh(b) / d);
9115
+ }
9116
+ /**
9117
+ * Calculate the cotangent
9118
+ *
9119
+ * @returns {Complex}
9120
+ */
9121
+ cot() {
9122
+ var a = 2 * this["re"];
9123
+ var b = 2 * this["im"];
9124
+ var d = Math.cos(a) - cosh(b);
9125
+ return new _Complex(-Math.sin(a) / d, sinh(b) / d);
9126
+ }
9127
+ /**
9128
+ * Calculate the secant
9129
+ *
9130
+ * @returns {Complex}
9131
+ */
9132
+ sec() {
9133
+ var a = this["re"];
9134
+ var b = this["im"];
9135
+ var d = 0.5 * cosh(2 * b) + 0.5 * Math.cos(2 * a);
9136
+ return new _Complex(Math.cos(a) * cosh(b) / d, Math.sin(a) * sinh(b) / d);
9137
+ }
9138
+ /**
9139
+ * Calculate the cosecans
9140
+ *
9141
+ * @returns {Complex}
9142
+ */
9143
+ csc() {
9144
+ var a = this["re"];
9145
+ var b = this["im"];
9146
+ var d = 0.5 * cosh(2 * b) - 0.5 * Math.cos(2 * a);
9147
+ return new _Complex(Math.sin(a) * cosh(b) / d, -Math.cos(a) * sinh(b) / d);
9148
+ }
9149
+ /**
9150
+ * Calculate the complex arcus sinus
9151
+ *
9152
+ * @returns {Complex}
9153
+ */
9154
+ asin() {
9155
+ var a = this["re"];
9156
+ var b = this["im"];
9157
+ var t1 = new _Complex(b * b - a * a + 1, -2 * a * b)["sqrt"]();
9158
+ var t2 = new _Complex(t1["re"] - b, t1["im"] + a)["log"]();
9159
+ return new _Complex(t2["im"], -t2["re"]);
9160
+ }
9161
+ /**
9162
+ * Calculate the complex arcus cosinus
9163
+ *
9164
+ * @returns {Complex}
9165
+ */
9166
+ acos() {
9167
+ var a = this["re"];
9168
+ var b = this["im"];
9169
+ var t1 = new _Complex(b * b - a * a + 1, -2 * a * b)["sqrt"]();
9170
+ var t2 = new _Complex(t1["re"] - b, t1["im"] + a)["log"]();
9171
+ return new _Complex(Math.PI / 2 - t2["im"], t2["re"]);
9172
+ }
9173
+ /**
9174
+ * Calculate the complex arcus tangent
9175
+ *
9176
+ * @returns {Complex}
9177
+ */
9178
+ atan() {
9179
+ var a = this["re"];
9180
+ var b = this["im"];
9181
+ if (a === 0) {
9182
+ if (b === 1) {
9183
+ return new _Complex(0, Infinity);
9184
+ }
9185
+ if (b === -1) {
9186
+ return new _Complex(0, -Infinity);
9187
+ }
9188
+ }
9189
+ var d = a * a + (1 - b) * (1 - b);
9190
+ var t1 = new _Complex((1 - b * b - a * a) / d, -2 * a / d).log();
9191
+ return new _Complex(-0.5 * t1["im"], 0.5 * t1["re"]);
9192
+ }
9193
+ /**
9194
+ * Calculate the complex arcus cotangent
9195
+ *
9196
+ * @returns {Complex}
9197
+ */
9198
+ acot() {
9199
+ var a = this["re"];
9200
+ var b = this["im"];
9201
+ if (b === 0) {
9202
+ return new _Complex(Math.atan2(1, a), 0);
9203
+ }
9204
+ var d = a * a + b * b;
9205
+ return d !== 0 ? new _Complex(a / d, -b / d).atan() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).atan();
9206
+ }
9207
+ /**
9208
+ * Calculate the complex arcus secant
9209
+ *
9210
+ * @returns {Complex}
9211
+ */
9212
+ asec() {
9213
+ var a = this["re"];
9214
+ var b = this["im"];
9215
+ if (a === 0 && b === 0) {
9216
+ return new _Complex(0, Infinity);
9217
+ }
9218
+ var d = a * a + b * b;
9219
+ return d !== 0 ? new _Complex(a / d, -b / d).acos() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).acos();
9220
+ }
9221
+ /**
9222
+ * Calculate the complex arcus cosecans
9223
+ *
9224
+ * @returns {Complex}
9225
+ */
9226
+ acsc() {
9227
+ var a = this["re"];
9228
+ var b = this["im"];
9229
+ if (a === 0 && b === 0) {
9230
+ return new _Complex(Math.PI / 2, Infinity);
9231
+ }
9232
+ var d = a * a + b * b;
9233
+ return d !== 0 ? new _Complex(a / d, -b / d).asin() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).asin();
9234
+ }
9235
+ /**
9236
+ * Calculate the complex sinh
9237
+ *
9238
+ * @returns {Complex}
9239
+ */
9240
+ sinh() {
9241
+ var a = this["re"];
9242
+ var b = this["im"];
9243
+ return new _Complex(sinh(a) * Math.cos(b), cosh(a) * Math.sin(b));
9244
+ }
9245
+ /**
9246
+ * Calculate the complex cosh
9247
+ *
9248
+ * @returns {Complex}
9249
+ */
9250
+ cosh() {
9251
+ var a = this["re"];
9252
+ var b = this["im"];
9253
+ return new _Complex(cosh(a) * Math.cos(b), sinh(a) * Math.sin(b));
9254
+ }
9255
+ /**
9256
+ * Calculate the complex tanh
9257
+ *
9258
+ * @returns {Complex}
9259
+ */
9260
+ tanh() {
9261
+ var a = 2 * this["re"];
9262
+ var b = 2 * this["im"];
9263
+ var d = cosh(a) + Math.cos(b);
9264
+ return new _Complex(sinh(a) / d, Math.sin(b) / d);
9265
+ }
9266
+ /**
9267
+ * Calculate the complex coth
9268
+ *
9269
+ * @returns {Complex}
9270
+ */
9271
+ coth() {
9272
+ var a = 2 * this["re"];
9273
+ var b = 2 * this["im"];
9274
+ var d = cosh(a) - Math.cos(b);
9275
+ return new _Complex(sinh(a) / d, -Math.sin(b) / d);
9276
+ }
9277
+ /**
9278
+ * Calculate the complex coth
9279
+ *
9280
+ * @returns {Complex}
9281
+ */
9282
+ csch() {
9283
+ var a = this["re"];
9284
+ var b = this["im"];
9285
+ var d = Math.cos(2 * b) - cosh(2 * a);
9286
+ return new _Complex(-2 * sinh(a) * Math.cos(b) / d, 2 * cosh(a) * Math.sin(b) / d);
9287
+ }
9288
+ /**
9289
+ * Calculate the complex sech
9290
+ *
9291
+ * @returns {Complex}
9292
+ */
9293
+ sech() {
9294
+ var a = this["re"];
9295
+ var b = this["im"];
9296
+ var d = Math.cos(2 * b) + cosh(2 * a);
9297
+ return new _Complex(2 * cosh(a) * Math.cos(b) / d, -2 * sinh(a) * Math.sin(b) / d);
9298
+ }
9299
+ /**
9300
+ * Calculate the complex asinh
9301
+ *
9302
+ * @returns {Complex}
9303
+ */
9304
+ asinh() {
9305
+ var tmp = this["im"];
9306
+ this["im"] = -this["re"];
9307
+ this["re"] = tmp;
9308
+ var res = this["asin"]();
9309
+ this["re"] = -this["im"];
9310
+ this["im"] = tmp;
9311
+ tmp = res["re"];
9312
+ res["re"] = -res["im"];
9313
+ res["im"] = tmp;
9314
+ return res;
9315
+ }
9316
+ /**
9317
+ * Calculate the complex acosh
9318
+ *
9319
+ * @returns {Complex}
9320
+ */
9321
+ acosh() {
9322
+ var res = this["acos"]();
9323
+ if (res["im"] <= 0) {
9324
+ var tmp = res["re"];
9325
+ res["re"] = -res["im"];
9326
+ res["im"] = tmp;
9327
+ } else {
9328
+ var tmp = res["im"];
9329
+ res["im"] = -res["re"];
9330
+ res["re"] = tmp;
9331
+ }
9332
+ return res;
9333
+ }
9334
+ /**
9335
+ * Calculate the complex atanh
9336
+ *
9337
+ * @returns {Complex}
9338
+ */
9339
+ atanh() {
9340
+ var a = this["re"];
9341
+ var b = this["im"];
9342
+ var noIM = a > 1 && b === 0;
9343
+ var oneMinus = 1 - a;
9344
+ var onePlus = 1 + a;
9345
+ var d = oneMinus * oneMinus + b * b;
9346
+ var x = d !== 0 ? new _Complex((onePlus * oneMinus - b * b) / d, (b * oneMinus + onePlus * b) / d) : new _Complex(a !== -1 ? a / 0 : 0, b !== 0 ? b / 0 : 0);
9347
+ var temp = x["re"];
9348
+ x["re"] = logHypot(x["re"], x["im"]) / 2;
9349
+ x["im"] = Math.atan2(x["im"], temp) / 2;
9350
+ if (noIM) {
9351
+ x["im"] = -x["im"];
9352
+ }
9353
+ return x;
9354
+ }
9355
+ /**
9356
+ * Calculate the complex acoth
9357
+ *
9358
+ * @returns {Complex}
9359
+ */
9360
+ acoth() {
9361
+ var a = this["re"];
9362
+ var b = this["im"];
9363
+ if (a === 0 && b === 0) {
9364
+ return new _Complex(0, Math.PI / 2);
9365
+ }
9366
+ var d = a * a + b * b;
9367
+ return d !== 0 ? new _Complex(a / d, -b / d).atanh() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).atanh();
9368
+ }
9369
+ /**
9370
+ * Calculate the complex acsch
9371
+ *
9372
+ * @returns {Complex}
9373
+ */
9374
+ acsch() {
9375
+ var a = this["re"];
9376
+ var b = this["im"];
9377
+ if (b === 0) {
9378
+ return new _Complex(a !== 0 ? Math.log(a + Math.sqrt(a * a + 1)) : Infinity, 0);
9379
+ }
9380
+ var d = a * a + b * b;
9381
+ return d !== 0 ? new _Complex(a / d, -b / d).asinh() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).asinh();
9382
+ }
9383
+ /**
9384
+ * Calculate the complex asech
9385
+ *
9386
+ * @returns {Complex}
9387
+ */
9388
+ asech() {
9389
+ var a = this["re"];
9390
+ var b = this["im"];
9391
+ if (this["isZero"]()) {
9392
+ return _Complex["INFINITY"];
9393
+ }
9394
+ var d = a * a + b * b;
9395
+ return d !== 0 ? new _Complex(a / d, -b / d).acosh() : new _Complex(a !== 0 ? a / 0 : 0, b !== 0 ? -b / 0 : 0).acosh();
9396
+ }
9397
+ /**
9398
+ * Calculate the complex inverse 1/z
9399
+ *
9400
+ * @returns {Complex}
9401
+ */
9402
+ inverse() {
9403
+ if (this["isZero"]()) {
9404
+ return _Complex["INFINITY"];
9405
+ }
9406
+ if (this["isInfinite"]()) {
9407
+ return _Complex["ZERO"];
9408
+ }
9409
+ var a = this["re"];
9410
+ var b = this["im"];
9411
+ var d = a * a + b * b;
9412
+ return new _Complex(a / d, -b / d);
9413
+ }
9414
+ /**
9415
+ * Returns the complex conjugate
9416
+ *
9417
+ * @returns {Complex}
9418
+ */
9419
+ conjugate() {
9420
+ return new _Complex(this["re"], -this["im"]);
9421
+ }
9422
+ /**
9423
+ * Gets the negated complex number
9424
+ *
9425
+ * @returns {Complex}
9426
+ */
9427
+ neg() {
9428
+ return new _Complex(-this["re"], -this["im"]);
9429
+ }
9430
+ /**
9431
+ * Ceils the actual complex number
9432
+ *
9433
+ * @returns {Complex}
9434
+ */
9435
+ ceil(places) {
9436
+ places = Math.pow(10, places || 0);
9437
+ return new _Complex(Math.ceil(this["re"] * places) / places, Math.ceil(this["im"] * places) / places);
9438
+ }
9439
+ /**
9440
+ * Floors the actual complex number
9441
+ *
9442
+ * @returns {Complex}
9443
+ */
9444
+ floor(places) {
9445
+ places = Math.pow(10, places || 0);
9446
+ return new _Complex(Math.floor(this["re"] * places) / places, Math.floor(this["im"] * places) / places);
9447
+ }
9448
+ /**
9449
+ * Ceils the actual complex number
9450
+ *
9451
+ * @returns {Complex}
9452
+ */
9453
+ round(places) {
9454
+ places = Math.pow(10, places || 0);
9455
+ return new _Complex(Math.round(this["re"] * places) / places, Math.round(this["im"] * places) / places);
9456
+ }
9457
+ /**
9458
+ * Compares two complex numbers
9459
+ *
9460
+ * **Note:** new Complex(Infinity).equals(Infinity) === false
9461
+ *
9462
+ * @returns {boolean}
9463
+ */
9464
+ equals(a, b) {
9465
+ var z = new _Complex(a, b);
9466
+ return Math.abs(z["re"] - this["re"]) <= _Complex["EPSILON"] && Math.abs(z["im"] - this["im"]) <= _Complex["EPSILON"];
9467
+ }
9468
+ /**
9469
+ * Clones the actual object
9470
+ *
9471
+ * @returns {Complex}
9472
+ */
9473
+ clone() {
9474
+ return new _Complex(this["re"], this["im"]);
9475
+ }
9476
+ /**
9477
+ * Gets a string of the actual complex number
9478
+ *
9479
+ * @returns {string}
9480
+ */
9481
+ toString() {
9482
+ var a = this["re"];
9483
+ var b = this["im"];
9484
+ var ret = "";
9485
+ if (this["isNaN"]()) {
9486
+ return "NaN";
9487
+ }
9488
+ if (this["isInfinite"]()) {
9489
+ return "Infinity";
9490
+ }
9491
+ if (Math.abs(a) < _Complex["EPSILON"]) {
9492
+ a = 0;
9493
+ }
9494
+ if (Math.abs(b) < _Complex["EPSILON"]) {
9495
+ b = 0;
9496
+ }
9497
+ if (b === 0) {
9498
+ return ret + a;
9499
+ }
9500
+ if (a !== 0) {
9501
+ ret += a;
9502
+ ret += " ";
9503
+ if (b < 0) {
9504
+ b = -b;
9505
+ ret += "-";
9506
+ } else {
9507
+ ret += "+";
9508
+ }
9509
+ ret += " ";
9510
+ } else if (b < 0) {
9511
+ b = -b;
9512
+ ret += "-";
9513
+ }
9514
+ if (1 !== b) {
9515
+ ret += b;
9516
+ }
9517
+ return ret + "i";
9518
+ }
9519
+ /**
9520
+ * Returns the actual number as a vector
9521
+ *
9522
+ * @returns {Array}
9523
+ */
9524
+ toVector() {
9525
+ return [this["re"], this["im"]];
9526
+ }
9527
+ /**
9528
+ * Returns the actual real value of the current object
9529
+ *
9530
+ * @returns {number|null}
9531
+ */
9532
+ valueOf() {
9533
+ if (this["im"] === 0) {
9534
+ return this["re"];
9535
+ }
9536
+ return null;
9537
+ }
9538
+ /**
9539
+ * Determines whether a complex number is not on the Riemann sphere.
9540
+ *
9541
+ * @returns {boolean}
9542
+ */
9543
+ isNaN() {
9544
+ return isNaN(this["re"]) || isNaN(this["im"]);
9545
+ }
9546
+ /**
9547
+ * Determines whether or not a complex number is at the zero pole of the
9548
+ * Riemann sphere.
9549
+ *
9550
+ * @returns {boolean}
9551
+ */
9552
+ isZero() {
9553
+ return this["im"] === 0 && this["re"] === 0;
9554
+ }
9555
+ /**
9556
+ * Determines whether a complex number is not at the infinity pole of the
9557
+ * Riemann sphere.
9558
+ *
9559
+ * @returns {boolean}
9560
+ */
9561
+ isFinite() {
9562
+ return isFinite(this["re"]) && isFinite(this["im"]);
9563
+ }
9564
+ /**
9565
+ * Determines whether or not a complex number is at the infinity pole of the
9566
+ * Riemann sphere.
9567
+ *
9568
+ * @returns {boolean}
9569
+ */
9570
+ isInfinite() {
9571
+ return !(this["isNaN"]() || this["isFinite"]());
9572
+ }
9573
+ };
9574
+ Complex["ZERO"] = new Complex(0, 0);
9575
+ Complex["ONE"] = new Complex(1, 0);
9576
+ Complex["I"] = new Complex(0, 1);
9577
+ Complex["PI"] = new Complex(Math.PI, 0);
9578
+ Complex["E"] = new Complex(Math.E, 0);
9579
+ Complex["INFINITY"] = new Complex(Infinity, Infinity);
9580
+ Complex["NAN"] = new Complex(NaN, NaN);
9581
+ Complex["EPSILON"] = 1e-15;
9582
+
8469
9583
  // src/compute-engine/numerics/numeric-complex.ts
9584
+ var LANCZOS_G = 7;
9585
+ var LANCZOS_P = [
9586
+ 0.9999999999998099,
9587
+ 676.5203681218851,
9588
+ -1259.1392167224028,
9589
+ 771.3234287776531,
9590
+ -176.6150291621406,
9591
+ 12.507343278686905,
9592
+ -0.13857109526572012,
9593
+ 9984369578019572e-21,
9594
+ 15056327351493116e-23
9595
+ ];
9596
+ var SQRT_2PI = Math.sqrt(2 * Math.PI);
9597
+ var HALF_LOG_2PI = 0.5 * Math.log(2 * Math.PI);
8470
9598
  function gamma2(c) {
8471
- return c;
9599
+ if (c.re < 0.5) {
9600
+ const sinPiZ = c.mul(Math.PI).sin();
9601
+ return new Complex(Math.PI, 0).div(sinPiZ.mul(gamma2(new Complex(1, 0).sub(c))));
9602
+ }
9603
+ const z = c.sub(1);
9604
+ let x = new Complex(LANCZOS_P[0], 0);
9605
+ for (let i = 1; i < LANCZOS_G + 2; i++)
9606
+ x = x.add(new Complex(LANCZOS_P[i], 0).div(z.add(i)));
9607
+ const t = z.add(LANCZOS_G + 0.5);
9608
+ return new Complex(SQRT_2PI, 0).mul(t.pow(z.add(0.5))).mul(t.neg().exp()).mul(x);
8472
9609
  }
8473
9610
  function gammaln2(c) {
8474
- return c;
9611
+ if (c.re < 0.5) {
9612
+ const sinPiZ = c.mul(Math.PI).sin();
9613
+ return new Complex(Math.PI, 0).div(sinPiZ).log().sub(gammaln2(new Complex(1, 0).sub(c)));
9614
+ }
9615
+ const z = c.sub(1);
9616
+ let x = new Complex(LANCZOS_P[0], 0);
9617
+ for (let i = 1; i < LANCZOS_G + 2; i++)
9618
+ x = x.add(new Complex(LANCZOS_P[i], 0).div(z.add(i)));
9619
+ const t = z.add(LANCZOS_G + 0.5);
9620
+ return new Complex(HALF_LOG_2PI, 0).add(z.add(0.5).mul(t.log())).sub(t).add(x.log());
8475
9621
  }
8476
9622
 
8477
9623
  // src/numerics.ts
8478
- var version = "0.57.0";
9624
+ var version = "0.59.0";
8479
9625
  export {
8480
9626
  BigNumericValue,
8481
9627
  DEFAULT_PRECISION,
@@ -8618,3 +9764,13 @@ export {
8618
9764
  version,
8619
9765
  zeta
8620
9766
  };
9767
+ /*! Bundled license information:
9768
+
9769
+ complex-esm/dist/src/complex.js:
9770
+ (**
9771
+ * @license Complex.js v2.1.1 12/05/2020
9772
+ *
9773
+ * Copyright (c) 2020, Robert Eisele (robert@xarg.org)
9774
+ * Dual licensed under the MIT or GPL Version 2 licenses.
9775
+ **)
9776
+ */