@cortex-js/compute-engine 0.63.0 → 0.64.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 (292) hide show
  1. package/dist/compile.esm.js +8 -3
  2. package/dist/compile.min.esm.js +7 -7
  3. package/dist/compile.min.umd.cjs +7 -7
  4. package/dist/compile.umd.cjs +8 -3
  5. package/dist/compute-engine.esm.js +1097 -106
  6. package/dist/compute-engine.min.esm.js +80 -80
  7. package/dist/compute-engine.min.umd.cjs +80 -80
  8. package/dist/compute-engine.umd.cjs +1097 -106
  9. package/dist/core.esm.js +1096 -105
  10. package/dist/core.min.esm.js +78 -78
  11. package/dist/core.min.umd.cjs +78 -78
  12. package/dist/core.umd.cjs +1096 -105
  13. package/dist/identities.esm.js +2 -7
  14. package/dist/identities.min.esm.js +2 -2
  15. package/dist/identities.min.umd.cjs +2 -2
  16. package/dist/identities.umd.cjs +2 -7
  17. package/dist/integration-rules.esm.js +3 -2
  18. package/dist/integration-rules.min.esm.js +4 -4
  19. package/dist/integration-rules.min.umd.cjs +4 -4
  20. package/dist/integration-rules.umd.cjs +3 -2
  21. package/dist/interval.esm.js +3 -2
  22. package/dist/interval.min.esm.js +4 -4
  23. package/dist/interval.min.umd.cjs +4 -4
  24. package/dist/interval.umd.cjs +3 -2
  25. package/dist/latex-syntax.esm.js +3 -2
  26. package/dist/latex-syntax.min.esm.js +6 -6
  27. package/dist/latex-syntax.min.umd.cjs +6 -6
  28. package/dist/latex-syntax.umd.cjs +3 -2
  29. package/dist/math-json.esm.js +2 -2
  30. package/dist/math-json.min.esm.js +2 -2
  31. package/dist/math-json.min.umd.cjs +2 -2
  32. package/dist/math-json.umd.cjs +2 -2
  33. package/dist/numerics.esm.js +53 -91
  34. package/dist/numerics.min.esm.js +4 -4
  35. package/dist/numerics.min.umd.cjs +4 -4
  36. package/dist/numerics.umd.cjs +53 -91
  37. package/dist/types/big-decimal/big-decimal.d.ts +1 -1
  38. package/dist/types/big-decimal/index.d.ts +1 -1
  39. package/dist/types/big-decimal/transcendentals.d.ts +1 -1
  40. package/dist/types/big-decimal/utils.d.ts +1 -1
  41. package/dist/types/common/ansi-codes.d.ts +1 -1
  42. package/dist/types/common/configuration-change.d.ts +1 -1
  43. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  44. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  45. package/dist/types/common/interruptible.d.ts +1 -1
  46. package/dist/types/common/one-of.d.ts +1 -1
  47. package/dist/types/common/signals.d.ts +1 -1
  48. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  49. package/dist/types/common/type/boxed-type.d.ts +1 -1
  50. package/dist/types/common/type/lexer.d.ts +1 -1
  51. package/dist/types/common/type/parse.d.ts +1 -1
  52. package/dist/types/common/type/parser.d.ts +1 -1
  53. package/dist/types/common/type/primitive.d.ts +1 -1
  54. package/dist/types/common/type/reduce.d.ts +1 -1
  55. package/dist/types/common/type/serialize.d.ts +1 -1
  56. package/dist/types/common/type/subtype.d.ts +1 -1
  57. package/dist/types/common/type/type-builder.d.ts +1 -1
  58. package/dist/types/common/type/types.d.ts +1 -1
  59. package/dist/types/common/type/utils.d.ts +1 -1
  60. package/dist/types/common/utils.d.ts +1 -1
  61. package/dist/types/compile.d.ts +1 -1
  62. package/dist/types/compute-engine/assume.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  78. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  79. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  80. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  81. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  82. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  83. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  84. package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +1 -1
  85. package/dist/types/compute-engine/boxed-expression/exp-to-trig.d.ts +1 -1
  86. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  87. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  88. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  89. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  90. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  91. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  92. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  93. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  94. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  95. package/dist/types/compute-engine/boxed-expression/multivariate-gcd.d.ts +1 -1
  96. package/dist/types/compute-engine/boxed-expression/multivariate-poly.d.ts +1 -1
  97. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  98. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +11 -5
  99. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  100. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  101. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  102. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  103. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  104. package/dist/types/compute-engine/boxed-expression/rule-index.d.ts +1 -1
  105. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  106. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  107. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  108. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  109. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  110. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  111. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  112. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  113. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  114. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  115. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  116. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  117. package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
  118. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  119. package/dist/types/compute-engine/compilation/constant-folding.d.ts +1 -1
  120. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  121. package/dist/types/compute-engine/compilation/gpu-target.d.ts +1 -1
  122. package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +1 -1
  123. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  124. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  125. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  126. package/dist/types/compute-engine/compilation/types.d.ts +1 -1
  127. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  128. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  129. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  130. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  131. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  132. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  133. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  134. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  135. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  136. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  137. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  138. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  139. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  140. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  141. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  142. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  143. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  144. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  145. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  146. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  147. package/dist/types/compute-engine/function-properties/index.d.ts +1 -1
  148. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  149. package/dist/types/compute-engine/fungrim/loader.d.ts +1 -1
  150. package/dist/types/compute-engine/fungrim/types.d.ts +1 -1
  151. package/dist/types/compute-engine/global-types.d.ts +1 -1
  152. package/dist/types/compute-engine/index.d.ts +1 -1
  153. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  154. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  155. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  156. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  157. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  158. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  159. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  160. package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
  161. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  162. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  163. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  164. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-colors.d.ts +1 -1
  165. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  166. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  167. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  168. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  169. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  170. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  171. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  172. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  173. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  174. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  175. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  176. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  177. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  178. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  179. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  180. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  181. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  182. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
  183. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  184. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  185. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  186. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  187. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  188. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  189. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  190. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  191. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  192. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  193. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  194. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  195. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  196. package/dist/types/compute-engine/library/core.d.ts +1 -1
  197. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  198. package/dist/types/compute-engine/library/library.d.ts +1 -1
  199. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  200. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  201. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  202. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  203. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  204. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  205. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  206. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  207. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  208. package/dist/types/compute-engine/library/special-functions.d.ts +1 -1
  209. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  210. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  211. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  212. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  213. package/dist/types/compute-engine/library/units.d.ts +1 -1
  214. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  215. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  216. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  217. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  218. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  219. package/dist/types/compute-engine/numerics/bernoulli.d.ts +1 -1
  220. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  221. package/dist/types/compute-engine/numerics/complex-esm-augment.d.ts +1 -1
  222. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  223. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  224. package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
  225. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  226. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  227. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
  228. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  229. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  230. package/dist/types/compute-engine/numerics/oscillatory-quadrature.d.ts +1 -1
  231. package/dist/types/compute-engine/numerics/polynomial-roots.d.ts +1 -1
  232. package/dist/types/compute-engine/numerics/primes.d.ts +5 -3
  233. package/dist/types/compute-engine/numerics/random.d.ts +1 -1
  234. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  235. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  236. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  237. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  238. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  239. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  240. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  241. package/dist/types/compute-engine/oeis.d.ts +1 -1
  242. package/dist/types/compute-engine/rubi/compile.d.ts +1 -1
  243. package/dist/types/compute-engine/rubi/driver.d.ts +1 -1
  244. package/dist/types/compute-engine/rubi/loader.d.ts +1 -1
  245. package/dist/types/compute-engine/rubi/match.d.ts +1 -1
  246. package/dist/types/compute-engine/rubi/normal-form.d.ts +1 -1
  247. package/dist/types/compute-engine/rubi/rubi-utils.d.ts +1 -1
  248. package/dist/types/compute-engine/rubi/types.d.ts +1 -1
  249. package/dist/types/compute-engine/sequence.d.ts +1 -1
  250. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  251. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  252. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  253. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  254. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  255. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  256. package/dist/types/compute-engine/symbolic/limit.d.ts +1 -1
  257. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  258. package/dist/types/compute-engine/symbolic/residue.d.ts +1 -1
  259. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  260. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  261. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  262. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  263. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  264. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  265. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  266. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  267. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  268. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  269. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  270. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  271. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  272. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  273. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  274. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  275. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  276. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  277. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  278. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  279. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  280. package/dist/types/compute-engine/types.d.ts +1 -1
  281. package/dist/types/compute-engine.d.ts +1 -1
  282. package/dist/types/core.d.ts +1 -1
  283. package/dist/types/identities.d.ts +1 -1
  284. package/dist/types/integration-rules.d.ts +1 -1
  285. package/dist/types/interval.d.ts +1 -1
  286. package/dist/types/latex-syntax.d.ts +2 -2
  287. package/dist/types/math-json/symbols.d.ts +1 -1
  288. package/dist/types/math-json/types.d.ts +1 -1
  289. package/dist/types/math-json/utils.d.ts +1 -1
  290. package/dist/types/math-json.d.ts +2 -2
  291. package/dist/types/numerics.d.ts +1 -1
  292. package/package.json +1 -1
package/dist/core.umd.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /** ComputeEngineCore 0.63.0 */
1
+ /** ComputeEngineCore 0.64.0 */
2
2
  (function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngineCore = {}));})(this, (function (exports) { 'use strict';
3
3
  "use strict";
4
4
  var ComputeEngineCore = (() => {
@@ -5326,7 +5326,6 @@ var ComputeEngineCore = (() => {
5326
5326
  }
5327
5327
 
5328
5328
  // src/compute-engine/numerics/primes.ts
5329
- var LARGE_PRIME = 1125899906842597;
5330
5329
  var SMALL_PRIMES = /* @__PURE__ */ new Set([
5331
5330
  2,
5332
5331
  3,
@@ -6373,102 +6372,60 @@ var ComputeEngineCore = (() => {
6373
6372
  else result[n] = 1;
6374
6373
  return result;
6375
6374
  }
6376
- function isPrime(n) {
6377
- if (!Number.isInteger(n) || !Number.isFinite(n) || Number.isNaN(n) || n <= 1) {
6378
- return false;
6379
- }
6380
- if (n <= LARGEST_SMALL_PRIME) return SMALL_PRIMES.has(n);
6381
- for (const smallPrime of SMALL_PRIMES) {
6382
- if (n % smallPrime === 0) return false;
6383
- }
6384
- if (n < LARGE_PRIME) return n === leastFactor(n) || void 0;
6385
- return probablyPrime(n, 30) ? void 0 : false;
6386
- }
6387
- function leastFactor(n) {
6388
- if (n === 1) return 1;
6389
- if (n % 2 === 0) return 2;
6390
- if (n % 3 === 0) return 3;
6391
- if (n % 5 === 0) return 5;
6392
- const m = Math.floor(Math.sqrt(n));
6393
- let i = 7;
6394
- while (i <= m) {
6395
- if (n % i === 0) return i;
6396
- if (n % (i + 4) === 0) return i + 4;
6397
- if (n % (i + 6) === 0) return i + 6;
6398
- if (n % (i + 10) === 0) return i + 10;
6399
- if (n % (i + 12) === 0) return i + 12;
6400
- if (n % (i + 16) === 0) return i + 16;
6401
- if (n % (i + 22) === 0) return i + 22;
6402
- if (n % (i + 24) === 0) return i + 24;
6403
- i += 30;
6404
- }
6405
- return n;
6406
- }
6375
+ var MILLER_RABIN_THRESHOLD = 1n << 32n;
6376
+ var MILLER_RABIN_BASES = [
6377
+ 2n,
6378
+ 3n,
6379
+ 5n,
6380
+ 7n,
6381
+ 11n,
6382
+ 13n,
6383
+ 17n,
6384
+ 19n,
6385
+ 23n,
6386
+ 29n,
6387
+ 31n,
6388
+ 37n
6389
+ ];
6407
6390
  function isPrimeBigint(n) {
6408
- if (n <= 1) return false;
6409
- if (n <= LARGEST_SMALL_PRIME) return isPrime(Number(n));
6410
- for (const smallPrime of SMALL_PRIMES) {
6411
- if (n % BigInt(smallPrime) === BigInt(0)) return false;
6412
- }
6413
- if (n < LARGE_PRIME) n = leastBigFactor(n);
6414
- return probablyPrimeBigint(n, 30) ? void 0 : false;
6415
- }
6416
- function leastBigFactor(n) {
6417
- if (n === BigInt(1)) return BigInt(1);
6418
- if (n % BigInt(2) === BigInt(0)) return BigInt(2);
6419
- if (n % BigInt(3) === BigInt(0)) return BigInt(3);
6420
- if (n % BigInt(5) === BigInt(0)) return BigInt(5);
6421
- const m = BigInt(Math.floor(Math.sqrt(Number(n))));
6422
- let i = BigInt(7);
6423
- while (i <= m) {
6424
- if (n % i === BigInt(0)) return i;
6425
- if (n % (i + BigInt(4)) === BigInt(0)) return i + BigInt(4);
6426
- if (n % (i + BigInt(6)) === BigInt(0)) return i + BigInt(6);
6427
- if (n % (i + BigInt(10)) === BigInt(0)) return i + BigInt(10);
6428
- if (n % (i + BigInt(12)) === BigInt(0)) return i + BigInt(12);
6429
- if (n % (i + BigInt(16)) === BigInt(0)) return i + BigInt(16);
6430
- if (n % (i + BigInt(22)) === BigInt(0)) return i + BigInt(22);
6431
- if (n % (i + BigInt(24)) === BigInt(0)) return i + BigInt(24);
6432
- i += BigInt(30);
6391
+ if (n < 2n) return false;
6392
+ if (n <= LARGEST_SMALL_PRIME) return SMALL_PRIMES.has(Number(n));
6393
+ if (n < MILLER_RABIN_THRESHOLD) {
6394
+ if (n % 2n === 0n || n % 3n === 0n) return false;
6395
+ for (let i = 5n; i * i <= n; i += 6n)
6396
+ if (n % i === 0n || n % (i + 2n) === 0n) return false;
6397
+ return true;
6433
6398
  }
6434
- return n;
6399
+ return millerRabin(n);
6435
6400
  }
6436
- function probablyPrime(n, k) {
6437
- let s = 0;
6438
- let d = n - 1;
6439
- while (d % 2 === 0) {
6440
- d /= 2;
6441
- ++s;
6442
- }
6443
- WitnessLoop: do {
6444
- let x = Math.pow(2 + Math.floor(Math.random() * (n - 3)), d) % n;
6445
- if (x === 1 || x === n - 1) continue;
6446
- for (let i = s - 1; i--; ) {
6447
- x = x * x % n;
6448
- if (x === 1) return false;
6449
- if (x === n - 1) continue WitnessLoop;
6450
- }
6451
- return false;
6452
- } while (--k);
6453
- return true;
6401
+ function modPow(base, exp3, mod3) {
6402
+ if (mod3 === 1n) return 0n;
6403
+ let result = 1n;
6404
+ base = (base % mod3 + mod3) % mod3;
6405
+ while (exp3 > 0n) {
6406
+ if (exp3 & 1n) result = result * base % mod3;
6407
+ base = base * base % mod3;
6408
+ exp3 >>= 1n;
6409
+ }
6410
+ return result;
6454
6411
  }
6455
- function probablyPrimeBigint(n, k) {
6456
- let s = 0;
6457
- let d = n - BigInt(1);
6458
- while (d % BigInt(2) === BigInt(0)) {
6459
- d = d / BigInt(2);
6460
- ++s;
6461
- }
6462
- WitnessLoop: do {
6463
- let x = BigInt(2 + Math.floor(Math.random() * (Number(n) - 3))) ** d % n;
6464
- if (x === BigInt(1) || x === n - BigInt(1)) continue;
6465
- for (let i = s - 1; i--; ) {
6412
+ function millerRabin(n) {
6413
+ for (const p of MILLER_RABIN_BASES) if (n % p === 0n) return n === p;
6414
+ let d = n - 1n;
6415
+ let s = 0n;
6416
+ while (d % 2n === 0n) {
6417
+ d /= 2n;
6418
+ s += 1n;
6419
+ }
6420
+ WitnessLoop: for (const a of MILLER_RABIN_BASES) {
6421
+ let x = modPow(a, d, n);
6422
+ if (x === 1n || x === n - 1n) continue;
6423
+ for (let r = 1n; r < s; r++) {
6466
6424
  x = x * x % n;
6467
- if (x === BigInt(1)) return false;
6468
- if (x === n - BigInt(1)) continue WitnessLoop;
6425
+ if (x === n - 1n) continue WitnessLoop;
6469
6426
  }
6470
6427
  return false;
6471
- } while (--k);
6428
+ }
6472
6429
  return true;
6473
6430
  }
6474
6431
  var PRIME_WHEEL_INC = [
@@ -6481,6 +6438,63 @@ var ComputeEngineCore = (() => {
6481
6438
  BigInt(2),
6482
6439
  BigInt(6)
6483
6440
  ];
6441
+ function bigPrimeFactors(d) {
6442
+ if (d < Number.MAX_SAFE_INTEGER) {
6443
+ const factors = primeFactors(Number(d));
6444
+ const result2 = /* @__PURE__ */ new Map();
6445
+ for (const f of Object.keys(factors))
6446
+ result2.set(bigint(f), factors[Number(f)]);
6447
+ return result2;
6448
+ }
6449
+ let n = d;
6450
+ const result = /* @__PURE__ */ new Map();
6451
+ let count2 = 0;
6452
+ let count3 = 0;
6453
+ let count5 = 0;
6454
+ let k = BigInt(10);
6455
+ while (n % k === BigInt(0)) {
6456
+ count2 += 1;
6457
+ count5 += 1;
6458
+ n = n / k;
6459
+ }
6460
+ k = BigInt(5);
6461
+ while (n % k === BigInt(0)) {
6462
+ count5 += 1;
6463
+ n = n / k;
6464
+ }
6465
+ k = BigInt(3);
6466
+ while (n % k === BigInt(0)) {
6467
+ count3 += 1;
6468
+ n = n / k;
6469
+ }
6470
+ k = BigInt(2);
6471
+ while (n % k === BigInt(0)) {
6472
+ count2 += 1;
6473
+ n = n / k;
6474
+ }
6475
+ if (count2 > 0) result.set("2", count2);
6476
+ if (count3 > 0) result.set("3", count3);
6477
+ if (count5 > 0) result.set("5", count5);
6478
+ k = BigInt(7);
6479
+ let kIndex = "";
6480
+ let i = 0;
6481
+ while (k * k < n) {
6482
+ if (n % k === BigInt(0)) {
6483
+ if (!kIndex) kIndex = k.toString();
6484
+ result.set(kIndex, (result.get(kIndex) ?? 0) + 1);
6485
+ n = n / k;
6486
+ } else {
6487
+ k = k + PRIME_WHEEL_INC[i];
6488
+ kIndex = "";
6489
+ i = i < 7 ? i + 1 : 0;
6490
+ }
6491
+ }
6492
+ if (n !== BigInt(1))
6493
+ result.set(n.toString(), (result.get(n.toString()) ?? 0) + 1);
6494
+ const r = /* @__PURE__ */ new Map();
6495
+ for (const [k2, v] of result) r.set(bigint(k2), v);
6496
+ return r;
6497
+ }
6484
6498
 
6485
6499
  // src/compute-engine/numerics/numeric.ts
6486
6500
  var DEFAULT_PRECISION = 21;
@@ -25322,7 +25336,11 @@ ${lines.join("\n")}`;
25322
25336
  function toInteger(expr2) {
25323
25337
  if (!isNumber(expr2)) return null;
25324
25338
  const num = expr2.numericValue;
25325
- return Math.round(typeof num === "number" ? num : num.re);
25339
+ const re = typeof num === "number" ? num : num.re;
25340
+ if (!Number.isFinite(re)) return null;
25341
+ const n = Math.round(re);
25342
+ if (!Number.isSafeInteger(n)) return null;
25343
+ return n;
25326
25344
  }
25327
25345
  function toBigint(expr2) {
25328
25346
  if (expr2 === void 0 || expr2 === null) return null;
@@ -31941,12 +31959,10 @@ ${lines.join("\n")}`;
31941
31959
  }
31942
31960
 
31943
31961
  // src/compute-engine/boxed-expression/predicates.ts
31944
- function isPrime2(expr2) {
31962
+ function isPrime(expr2) {
31945
31963
  if (!expr2.isInteger) return void 0;
31946
31964
  if (expr2.isNegative) return void 0;
31947
31965
  if (!isNumber(expr2)) return void 0;
31948
- const n = toInteger(expr2);
31949
- if (n !== null) return isPrime(n);
31950
31966
  const b = asBigint(expr2);
31951
31967
  if (b !== null) return isPrimeBigint(b);
31952
31968
  return void 0;
@@ -37918,6 +37934,7 @@ ${lines.join("\n")}`;
37918
37934
  sgn: ([x]) => x.isNonNegative ? "positive" : x.isNegative || x.isReal === false ? "unsigned" : void 0,
37919
37935
  evaluate: (ops) => {
37920
37936
  const x = ops[0];
37937
+ if (x.isInteger !== true) return void 0;
37921
37938
  const n = toInteger(x);
37922
37939
  if (n === null) return void 0;
37923
37940
  const ce = x.engine;
@@ -38871,7 +38888,7 @@ ${lines.join("\n")}`;
38871
38888
  broadcastable: true,
38872
38889
  signature: "(number) -> boolean",
38873
38890
  evaluate: ([n], { engine }) => {
38874
- const result = isPrime2(n);
38891
+ const result = isPrime(n);
38875
38892
  if (result === void 0) return void 0;
38876
38893
  return engine.symbol(result ? "True" : "False");
38877
38894
  }
@@ -39553,8 +39570,8 @@ ${lines.join("\n")}`;
39553
39570
  nonpositive: (x) => x.isNonPositive,
39554
39571
  even: (x) => x.isEven,
39555
39572
  odd: (x) => x.isOdd,
39556
- prime: (x) => isPrime2(x) === true,
39557
- composite: (x) => isPrime2(x) === false,
39573
+ prime: (x) => isPrime(x) === true,
39574
+ composite: (x) => isPrime(x) === false,
39558
39575
  notzero: (x) => x.isSame(0) === false,
39559
39576
  notone: (x) => x.isSame(1) === false,
39560
39577
  finite: (x) => x.isFinite,
@@ -56573,6 +56590,7 @@ ${e instanceof Error ? e.message : e}
56573
56590
  signature: "(integer) -> integer",
56574
56591
  type: () => "finite_integer",
56575
56592
  evaluate: ([n], { engine: ce }) => {
56593
+ if (n.isInteger !== true) return void 0;
56576
56594
  const k = toInteger(n);
56577
56595
  if (k === null || k < 0) return void 0;
56578
56596
  let result = 1n;
@@ -56590,6 +56608,7 @@ ${e instanceof Error ? e.message : e}
56590
56608
  signature: "(integer) -> integer",
56591
56609
  type: () => "finite_integer",
56592
56610
  evaluate: ([n], { engine: ce }) => {
56611
+ if (n.isInteger !== true) return void 0;
56593
56612
  const k = toInteger(n);
56594
56613
  if (k === null || k < 0) return void 0;
56595
56614
  let row = [1n];
@@ -58169,17 +58188,35 @@ ${e instanceof Error ? e.message : e}
58169
58188
  }
58170
58189
  },
58171
58190
  N: {
58172
- description: "Numerically evaluate an expression",
58191
+ description: [
58192
+ "N(expr): numerically evaluate an expression",
58193
+ "N(expr, precision): evaluate to `precision` significant digits"
58194
+ ],
58173
58195
  lazy: true,
58174
- signature: "(any) -> unknown",
58196
+ signature: "(any, integer?) -> unknown",
58175
58197
  type: ([x]) => x.type,
58176
58198
  canonical: (ops, { engine: ce }) => {
58177
- if (ops.length !== 1) return ce._fn("N", checkArity(ce, ops, 1));
58178
- const h = ops[0].operator;
58179
- if (h === "N" || h === "Evaluate") return ops[0].canonical;
58199
+ if (ops.length === 0) return ce._fn("N", checkArity(ce, ops, 1));
58200
+ if (ops.length > 2) return ce._fn("N", checkArity(ce, ops, 2));
58201
+ if (ops.length === 1) {
58202
+ const h = ops[0].operator;
58203
+ if (h === "N" || h === "Evaluate") return ops[0].canonical;
58204
+ }
58180
58205
  return ce._fn("N", ops);
58181
58206
  },
58182
- evaluate: ([x]) => x.N()
58207
+ evaluate: (ops, { engine: ce }) => {
58208
+ const x = ops[0];
58209
+ if (ops.length < 2) return x.canonical.N();
58210
+ let p = ops[1].canonical.N().re;
58211
+ if (!Number.isFinite(p) || p < 1) return x.canonical.N();
58212
+ p = Math.min(Math.trunc(p), 1e3);
58213
+ const global = ce.precision;
58214
+ if (p > global) {
58215
+ ce.precision = p;
58216
+ return x.canonical.N();
58217
+ }
58218
+ return roundToSignificantDigits(x.canonical.N(), p);
58219
+ }
58183
58220
  },
58184
58221
  Random: {
58185
58222
  description: [
@@ -58684,6 +58721,20 @@ ${e instanceof Error ? e.message : e}
58684
58721
  }
58685
58722
  }
58686
58723
  ];
58724
+ function roundToSignificantDigits(value, p) {
58725
+ const ce = value.engine;
58726
+ const re = value.re;
58727
+ const im = value.im;
58728
+ if (!Number.isFinite(re) || !Number.isFinite(im)) return value;
58729
+ if (im !== 0) {
58730
+ const clamp2 = Math.min(p, 100);
58731
+ return ce.number(
58732
+ ce.complex(Number(re.toPrecision(clamp2)), Number(im.toPrecision(clamp2)))
58733
+ );
58734
+ }
58735
+ const bd = value.bignumRe ?? ce.bignum(re);
58736
+ return ce.number(bd.toPrecision(p));
58737
+ }
58687
58738
 
58688
58739
  // src/compute-engine/library/linear-algebra.ts
58689
58740
  var LINEAR_ALGEBRA_LIBRARY = [
@@ -59142,6 +59193,165 @@ ${e instanceof Error ? e.message : e}
59142
59193
  return void 0;
59143
59194
  }
59144
59195
  },
59196
+ Dot: {
59197
+ description: "Dot product (vector inner product) or matrix product.",
59198
+ complexity: 8300,
59199
+ signature: "(matrix|vector, matrix|vector) -> value",
59200
+ // `Dot` is Mathematica's `.`: it reduces to the inner product for two
59201
+ // vectors and to the matrix product otherwise — exactly what
59202
+ // `MatrixMultiply` already computes.
59203
+ evaluate: (ops, { engine: ce }) => ce.function("MatrixMultiply", ops).evaluate()
59204
+ },
59205
+ MatrixRank: {
59206
+ description: "Rank of a matrix (number of linearly independent rows/columns).",
59207
+ complexity: 8200,
59208
+ signature: "(value) -> integer",
59209
+ sgn: () => "non-negative",
59210
+ evaluate: ([map], { engine: ce }) => {
59211
+ const op = map.evaluate();
59212
+ if (op.isNumber) return ce.number(op.isSame(0) ? 0 : 1);
59213
+ if (!isTensor2(op)) return void 0;
59214
+ const shape = op.shape;
59215
+ if (shape.length > 2) return ce.error("expected-matrix", op.toString());
59216
+ const rowCount = shape.length === 1 ? 1 : shape[0];
59217
+ const columnCount = shape.length === 1 ? shape[0] : shape[1];
59218
+ const matrix = tensorToNumericMatrix(op, rowCount, columnCount);
59219
+ if (!matrix) return void 0;
59220
+ const nullity = computeNullSpaceBasis(matrix).length;
59221
+ return ce.number(columnCount - nullity);
59222
+ }
59223
+ },
59224
+ IsSquareMatrix: {
59225
+ description: "Whether the value is a square matrix.",
59226
+ complexity: 8200,
59227
+ signature: "(value) -> boolean",
59228
+ evaluate: ([m], { engine: ce }) => {
59229
+ const op = m.evaluate();
59230
+ if (!isTensor2(op)) return ce.False;
59231
+ return op.tensor.isSquare ? ce.True : ce.False;
59232
+ }
59233
+ },
59234
+ IsSymmetric: {
59235
+ description: "Whether the matrix is symmetric (A equals its transpose).",
59236
+ complexity: 8200,
59237
+ signature: "(value) -> boolean",
59238
+ evaluate: ([m], { engine: ce }) => {
59239
+ const op = m.evaluate();
59240
+ if (!isTensor2(op)) return ce.False;
59241
+ return op.tensor.isSymmetric ? ce.True : ce.False;
59242
+ }
59243
+ },
59244
+ IsDiagonal: {
59245
+ description: "Whether the matrix is diagonal (all off-diagonal entries are zero).",
59246
+ complexity: 8200,
59247
+ signature: "(value) -> boolean",
59248
+ evaluate: ([m], { engine: ce }) => {
59249
+ const op = m.evaluate();
59250
+ if (!isTensor2(op)) return ce.False;
59251
+ return op.tensor.isDiagonal ? ce.True : ce.False;
59252
+ }
59253
+ },
59254
+ Cross: {
59255
+ description: "Cross product of two 3-vectors.",
59256
+ complexity: 8300,
59257
+ signature: "(vector, vector) -> vector",
59258
+ evaluate: ([a, b], { engine: ce }) => {
59259
+ const A = a.evaluate();
59260
+ const B = b.evaluate();
59261
+ if (!isTensor2(A) || !isTensor2(B)) return void 0;
59262
+ if (A.shape.length !== 1 || A.shape[0] !== 3 || B.shape.length !== 1 || B.shape[0] !== 3)
59263
+ return ce.error(
59264
+ "incompatible-dimensions",
59265
+ "cross product requires two 3-vectors"
59266
+ );
59267
+ const a1 = ce.expr(A.tensor.at(1) ?? ce.Zero);
59268
+ const a2 = ce.expr(A.tensor.at(2) ?? ce.Zero);
59269
+ const a3 = ce.expr(A.tensor.at(3) ?? ce.Zero);
59270
+ const b1 = ce.expr(B.tensor.at(1) ?? ce.Zero);
59271
+ const b2 = ce.expr(B.tensor.at(2) ?? ce.Zero);
59272
+ const b3 = ce.expr(B.tensor.at(3) ?? ce.Zero);
59273
+ return ce.function("List", [
59274
+ a2.mul(b3).sub(a3.mul(b2)),
59275
+ a3.mul(b1).sub(a1.mul(b3)),
59276
+ a1.mul(b2).sub(a2.mul(b1))
59277
+ ]).evaluate();
59278
+ }
59279
+ },
59280
+ MatrixPower: {
59281
+ description: "Square matrix raised to an integer power (repeated matrix product).",
59282
+ complexity: 8300,
59283
+ signature: "(matrix, integer) -> matrix",
59284
+ evaluate: ([mat, exponent], { engine: ce }) => {
59285
+ const A = mat.evaluate();
59286
+ if (!isTensor2(A)) return void 0;
59287
+ if (!A.tensor.isSquare)
59288
+ return ce.error("expected-square-matrix", A.toString());
59289
+ const n = exponent.re;
59290
+ if (n === void 0 || !Number.isInteger(n)) return void 0;
59291
+ const size = A.shape[0];
59292
+ if (n === 0)
59293
+ return ce.function("IdentityMatrix", [ce.number(size)]).evaluate();
59294
+ let base = A;
59295
+ let k = n;
59296
+ if (n < 0) {
59297
+ const inv = ce.function("Inverse", [A]).evaluate();
59298
+ if (!isTensor2(inv)) return inv;
59299
+ base = inv;
59300
+ k = -n;
59301
+ }
59302
+ let result = base;
59303
+ for (let i = 1; i < k; i++)
59304
+ result = ce.function("MatrixMultiply", [result, base]).evaluate();
59305
+ return result;
59306
+ }
59307
+ },
59308
+ CharacteristicPolynomial: {
59309
+ description: "Characteristic polynomial det(x\xB7I \u2212 A) of a square matrix (monic).",
59310
+ complexity: 8700,
59311
+ // The variable is accepted as `any` (not `symbol`): an undeclared symbol
59312
+ // is inferred to have a numeric type, which would fail a `symbol`
59313
+ // signature check. The evaluate handler validates it with `isSymbol`.
59314
+ signature: "(matrix, any?) -> expression",
59315
+ evaluate: ([mat, variable], { engine: ce }) => {
59316
+ const A = mat.evaluate();
59317
+ if (!isTensor2(A)) return void 0;
59318
+ if (!A.tensor.isSquare)
59319
+ return ce.error("expected-square-matrix", A.toString());
59320
+ const x = variable && isSymbol2(variable) ? variable : ce.symbol("x");
59321
+ const n = A.shape[0];
59322
+ const rows = [];
59323
+ for (let i = 0; i < n; i++) {
59324
+ const row = [];
59325
+ for (let j = 0; j < n; j++) {
59326
+ const entry = ce.expr(A.tensor.at(i + 1, j + 1) ?? ce.Zero);
59327
+ row.push(i === j ? x.sub(entry) : entry.neg());
59328
+ }
59329
+ rows.push(ce.function("List", row));
59330
+ }
59331
+ return ce.function("Determinant", [ce.function("List", rows)]).evaluate();
59332
+ }
59333
+ },
59334
+ RowReduce: {
59335
+ description: "Reduced row echelon form (RREF) of a matrix.",
59336
+ complexity: 8200,
59337
+ signature: "(matrix) -> matrix",
59338
+ evaluate: ([m], { engine: ce }) => {
59339
+ const op = m.evaluate();
59340
+ if (!isTensor2(op)) return void 0;
59341
+ const shape = op.shape;
59342
+ if (shape.length !== 2)
59343
+ return ce.error("expected-matrix", op.toString());
59344
+ const matrix = tensorToNumericMatrix(op, shape[0], shape[1]);
59345
+ if (!matrix) return void 0;
59346
+ const { matrix: reduced } = rref(matrix);
59347
+ return ce.expr([
59348
+ "List",
59349
+ ...reduced.map(
59350
+ (row) => ce.expr(["List", ...row.map((value) => ce.number(ce.chop(value)))])
59351
+ )
59352
+ ]);
59353
+ }
59354
+ },
59145
59355
  // Diagonal can be used to:
59146
59356
  // 1. Create a diagonal matrix from a vector
59147
59357
  // 2. Extract the diagonal from a matrix as a vector
@@ -60752,6 +60962,628 @@ ${e instanceof Error ? e.message : e}
60752
60962
  // src/compute-engine/library/number-theory.ts
60753
60963
  var NUMBER_THEORY_LIBRARY = [
60754
60964
  {
60965
+ FactorInteger: {
60966
+ description: "Return the prime factorization of an integer `n` as a list of `[prime, exponent]` tuples, ordered by ascending prime. For a negative `n`, a leading `[-1, 1]` tuple carries the sign.",
60967
+ signature: "(integer) -> list<tuple<integer, integer>>",
60968
+ examples: ["FactorInteger(360) // [(2, 3), (3, 2), (5, 1)]"],
60969
+ evaluate: ([n], { engine: ce }) => {
60970
+ const k = toBigint(n);
60971
+ if (k === null) return void 0;
60972
+ const tuple = (prime, exponent) => ce._fn("Tuple", [ce.number(prime), ce.number(exponent)]);
60973
+ if (k === 0n) return ce.function("List", [tuple(0n, 1)]);
60974
+ if (k === 1n) return ce.function("List", [tuple(1n, 1)]);
60975
+ const result = [];
60976
+ let m = k;
60977
+ if (m < 0n) {
60978
+ result.push(tuple(-1n, 1));
60979
+ m = -m;
60980
+ }
60981
+ if (m > 1n) {
60982
+ const factors = bigPrimeFactors(m);
60983
+ const primes = [...factors.keys()].sort(
60984
+ (a, b) => a < b ? -1 : a > b ? 1 : 0
60985
+ );
60986
+ for (const p of primes) result.push(tuple(p, factors.get(p)));
60987
+ }
60988
+ return ce.function("List", result);
60989
+ }
60990
+ },
60991
+ Divisors: {
60992
+ description: "Return the sorted list of positive divisors of an integer `n`. The sign of `n` is ignored.",
60993
+ signature: "(integer) -> list<integer>",
60994
+ examples: ["Divisors(12) // [1, 2, 3, 4, 6, 12]"],
60995
+ evaluate: ([n], { engine: ce }) => {
60996
+ const k = toBigint(n);
60997
+ if (k === null) return void 0;
60998
+ const m = k < 0n ? -k : k;
60999
+ if (m === 0n) return void 0;
61000
+ return ce.function(
61001
+ "List",
61002
+ divisorsAscending(m, ce._deadline).map((d) => ce.number(d))
61003
+ );
61004
+ }
61005
+ },
61006
+ NthPrime: {
61007
+ description: "Return the nth prime number (1-based): `NthPrime(1)` is 2, `NthPrime(2)` is 3, \u2026",
61008
+ signature: "(integer) -> integer",
61009
+ type: () => "finite_integer",
61010
+ examples: ["NthPrime(10) // 29"],
61011
+ evaluate: ([n], { engine: ce }) => {
61012
+ const k = toBigint(n);
61013
+ if (k === null || k < 1n) return void 0;
61014
+ if (k === 1n) return ce.number(2);
61015
+ let count = 1n;
61016
+ let candidate = 1n;
61017
+ let steps = 0;
61018
+ while (count < k) {
61019
+ candidate += 2n;
61020
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61021
+ if (isPrimeBigint(candidate)) count += 1n;
61022
+ }
61023
+ return ce.number(candidate);
61024
+ }
61025
+ },
61026
+ NextPrime: {
61027
+ description: "Return the smallest prime greater than `n`. With a second argument `k`, return the kth prime after `n` (`k < 0` returns the |k|th prime before `n`).",
61028
+ signature: "(integer, integer?) -> integer",
61029
+ type: () => "finite_integer",
61030
+ examples: ["NextPrime(10) // 11", "NextPrime(10, -1) // 7"],
61031
+ evaluate: ([n, kArg], { engine: ce }) => {
61032
+ const start = toBigint(n);
61033
+ if (start === null) return void 0;
61034
+ const k = kArg === void 0 ? 1n : toBigint(kArg);
61035
+ if (k === null || k === 0n) return void 0;
61036
+ let p = start;
61037
+ let steps = 0;
61038
+ if (k > 0n) {
61039
+ for (let i = 0n; i < k; i++) {
61040
+ do {
61041
+ p += 1n;
61042
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61043
+ } while (!isPrimeBigint(p));
61044
+ }
61045
+ } else {
61046
+ for (let i = 0n; i > k; i--) {
61047
+ do {
61048
+ p -= 1n;
61049
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61050
+ if (p < 2n) return void 0;
61051
+ } while (!isPrimeBigint(p));
61052
+ }
61053
+ }
61054
+ return ce.number(p);
61055
+ }
61056
+ },
61057
+ PrimeFactors: {
61058
+ description: "Return the sorted list of distinct prime factors of an integer `n`. The sign of `n` is ignored; `PrimeFactors(1)` is the empty list.",
61059
+ signature: "(integer) -> list<integer>",
61060
+ examples: ["PrimeFactors(360) // [2, 3, 5]"],
61061
+ evaluate: ([n], { engine: ce }) => {
61062
+ const k = toBigint(n);
61063
+ if (k === null) return void 0;
61064
+ const m = k < 0n ? -k : k;
61065
+ if (m === 0n) return void 0;
61066
+ const primes = [...bigPrimeFactors(m).keys()].filter((p) => p !== 1n).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
61067
+ return ce.function(
61068
+ "List",
61069
+ primes.map((p) => ce.number(p))
61070
+ );
61071
+ }
61072
+ },
61073
+ PrimeNu: {
61074
+ description: "Return \u03C9(n), the number of distinct prime factors of `n`. The sign of `n` is ignored; `PrimeNu(1)` is 0.",
61075
+ signature: "(integer) -> integer",
61076
+ type: () => "finite_integer",
61077
+ examples: ["PrimeNu(360) // 3"],
61078
+ evaluate: ([n], { engine: ce }) => {
61079
+ const k = toBigint(n);
61080
+ if (k === null) return void 0;
61081
+ const m = k < 0n ? -k : k;
61082
+ if (m === 0n) return void 0;
61083
+ if (m === 1n) return ce.number(0);
61084
+ return ce.number(bigPrimeFactors(m).size);
61085
+ }
61086
+ },
61087
+ PrimeOmega: {
61088
+ description: "Return \u03A9(n), the number of prime factors of `n` counted with multiplicity. The sign of `n` is ignored; `PrimeOmega(1)` is 0.",
61089
+ signature: "(integer) -> integer",
61090
+ type: () => "finite_integer",
61091
+ examples: ["PrimeOmega(360) // 6"],
61092
+ evaluate: ([n], { engine: ce }) => {
61093
+ const k = toBigint(n);
61094
+ if (k === null) return void 0;
61095
+ const m = k < 0n ? -k : k;
61096
+ if (m === 0n) return void 0;
61097
+ if (m === 1n) return ce.number(0);
61098
+ let total = 0;
61099
+ for (const e of bigPrimeFactors(m).values()) total += e;
61100
+ return ce.number(total);
61101
+ }
61102
+ },
61103
+ MoebiusMu: {
61104
+ description: "Return the M\xF6bius function \u03BC(n): 0 if `n` is divisible by a perfect square > 1, otherwise (-1) raised to the number of distinct prime factors. The sign of `n` is ignored.",
61105
+ signature: "(integer) -> integer",
61106
+ type: () => "finite_integer",
61107
+ examples: ["MoebiusMu(30) // -1"],
61108
+ evaluate: ([n], { engine: ce }) => {
61109
+ const k = toBigint(n);
61110
+ if (k === null) return void 0;
61111
+ const m = k < 0n ? -k : k;
61112
+ if (m === 0n) return void 0;
61113
+ if (m === 1n) return ce.number(1);
61114
+ const factors = bigPrimeFactors(m);
61115
+ for (const e of factors.values()) if (e > 1) return ce.number(0);
61116
+ return ce.number(factors.size % 2 === 0 ? 1 : -1);
61117
+ }
61118
+ },
61119
+ IsSquareFree: {
61120
+ description: 'Return `"True"` if `n` is square-free (not divisible by any perfect square > 1). The sign of `n` is ignored.',
61121
+ signature: "(integer) -> boolean",
61122
+ examples: ['IsSquareFree(30) // "True"'],
61123
+ evaluate: ([n], { engine: ce }) => {
61124
+ const k = toBigint(n);
61125
+ if (k === null) return void 0;
61126
+ const m = k < 0n ? -k : k;
61127
+ if (m === 0n) return ce.False;
61128
+ if (m === 1n) return ce.True;
61129
+ const factors = bigPrimeFactors(m);
61130
+ for (const e of factors.values()) if (e > 1) return ce.False;
61131
+ return ce.True;
61132
+ }
61133
+ },
61134
+ Radical: {
61135
+ description: "Return the radical of `n` (its square-free kernel): the product of its distinct prime factors. The sign of `n` is ignored; `Radical(1)` is 1.",
61136
+ signature: "(integer) -> integer",
61137
+ type: () => "finite_integer",
61138
+ examples: ["Radical(360) // 30"],
61139
+ evaluate: ([n], { engine: ce }) => {
61140
+ const k = toBigint(n);
61141
+ if (k === null) return void 0;
61142
+ const m = k < 0n ? -k : k;
61143
+ if (m === 0n) return void 0;
61144
+ if (m === 1n) return ce.number(1);
61145
+ let product = 1n;
61146
+ for (const p of bigPrimeFactors(m).keys()) product *= p;
61147
+ return ce.number(product);
61148
+ }
61149
+ },
61150
+ PowerMod: {
61151
+ description: "Return `a^b mod m` (modular exponentiation). A negative `b` uses the modular inverse of `a`; the result is undefined when that inverse does not exist (i.e. when `a` and `m` are not coprime). The result is in the range [0, m).",
61152
+ signature: "(integer, integer, integer) -> integer",
61153
+ type: () => "finite_integer",
61154
+ examples: ["PowerMod(2, 10, 1000) // 24"],
61155
+ evaluate: ([aOp, bOp, mOp], { engine: ce }) => {
61156
+ const a = toBigint(aOp);
61157
+ const b = toBigint(bOp);
61158
+ const m = toBigint(mOp);
61159
+ if (a === null || b === null || m === null) return void 0;
61160
+ if (m <= 0n) return void 0;
61161
+ if (m === 1n) return ce.number(0);
61162
+ if (b >= 0n) return ce.number(modPow(a, b, m));
61163
+ const base = (a % m + m) % m;
61164
+ const [g, s] = extGcd(base, m);
61165
+ if (g !== 1n) return void 0;
61166
+ const inv = (s % m + m) % m;
61167
+ return ce.number(modPow(inv, -b, m));
61168
+ }
61169
+ },
61170
+ ExtendedGCD: {
61171
+ description: "Return the extended GCD of `a` and `b` as a tuple `(g, x, y)` where `g = gcd(a, b)` is non-negative and `a\xB7x + b\xB7y = g` (B\xE9zout coefficients).",
61172
+ signature: "(integer, integer) -> tuple<integer, integer, integer>",
61173
+ examples: ["ExtendedGCD(12, 18) // (6, -1, 1)"],
61174
+ evaluate: ([aOp, bOp], { engine: ce }) => {
61175
+ const a = toBigint(aOp);
61176
+ const b = toBigint(bOp);
61177
+ if (a === null || b === null) return void 0;
61178
+ let [g, x, y] = extGcd(a, b);
61179
+ if (g < 0n) {
61180
+ g = -g;
61181
+ x = -x;
61182
+ y = -y;
61183
+ }
61184
+ return ce._fn("Tuple", [ce.number(g), ce.number(x), ce.number(y)]);
61185
+ }
61186
+ },
61187
+ IntegerSqrt: {
61188
+ description: "Return the integer square root of `n`, i.e. the largest integer `m` such that `m\xB2 \u2264 n`. Undefined for negative `n`.",
61189
+ signature: "(integer) -> integer",
61190
+ type: () => "finite_integer",
61191
+ examples: ["IntegerSqrt(17) // 4"],
61192
+ evaluate: ([n], { engine: ce }) => {
61193
+ const k = toBigint(n);
61194
+ if (k === null || k < 0n) return void 0;
61195
+ return ce.number(bigintSqrt2(k));
61196
+ }
61197
+ },
61198
+ ChineseRemainder: {
61199
+ description: "Solve a system of simultaneous congruences: return the smallest non-negative integer `x` such that `x \u2261 residues[i] (mod moduli[i])` for every `i`. Undefined if the system is inconsistent or the two lists differ in length.",
61200
+ signature: "(collection, collection) -> integer",
61201
+ examples: ["ChineseRemainder([2, 3, 2], [3, 5, 7]) // 23"],
61202
+ evaluate: ([residuesOp, moduliOp], { engine: ce }) => {
61203
+ const residues = Array.from(residuesOp?.each() ?? []).map(toBigint);
61204
+ const moduli = Array.from(moduliOp?.each() ?? []).map(toBigint);
61205
+ if (residues.length === 0 || residues.length !== moduli.length)
61206
+ return void 0;
61207
+ if (residues.includes(null) || moduli.includes(null)) return void 0;
61208
+ const x = chineseRemainder(residues, moduli);
61209
+ if (x === null) return void 0;
61210
+ return ce.number(x);
61211
+ }
61212
+ },
61213
+ CarmichaelLambda: {
61214
+ description: "Return the Carmichael function \u03BB(n) (the reduced totient): the smallest positive integer `m` such that `a^m \u2261 1 (mod n)` for every `a` coprime to `n`. Defined for `n \u2265 1`.",
61215
+ signature: "(integer) -> integer",
61216
+ type: () => "finite_integer",
61217
+ examples: ["CarmichaelLambda(15) // 4"],
61218
+ evaluate: ([n], { engine: ce }) => {
61219
+ const k = toBigint(n);
61220
+ if (k === null || k < 1n) return void 0;
61221
+ return ce.number(carmichaelLambda(k));
61222
+ }
61223
+ },
61224
+ LucasL: {
61225
+ description: "Return the nth Lucas number: `LucasL(0)` is 2, `LucasL(1)` is 1, and `LucasL(n) = LucasL(n-1) + LucasL(n-2)`. Negative indices follow `LucasL(-n) = (-1)^n \xB7 LucasL(n)`.",
61226
+ signature: "(integer) -> integer",
61227
+ type: () => "finite_integer",
61228
+ examples: ["LucasL(10) // 123"],
61229
+ evaluate: ([n], { engine: ce }) => {
61230
+ const k = toBigint(n);
61231
+ if (k === null) return void 0;
61232
+ const neg2 = k < 0n;
61233
+ const kk = neg2 ? -k : k;
61234
+ let a = 2n;
61235
+ let b = 1n;
61236
+ let steps = 0;
61237
+ for (let i = 0n; i < kk; i++) {
61238
+ if ((++steps & 4095) === 0) checkDeadline(ce._deadline);
61239
+ [a, b] = [b, a + b];
61240
+ }
61241
+ return ce.number(neg2 && kk % 2n === 1n ? -a : a);
61242
+ }
61243
+ },
61244
+ CatalanNumber: {
61245
+ description: "Return the nth Catalan number `C(n) = (2n)! / ((n+1)! \xB7 n!)`: 1, 1, 2, 5, 14, 42, \u2026 Defined for `n \u2265 0`.",
61246
+ signature: "(integer) -> integer",
61247
+ type: () => "finite_integer",
61248
+ examples: ["CatalanNumber(5) // 42"],
61249
+ evaluate: ([n], { engine: ce }) => {
61250
+ const k = toBigint(n);
61251
+ if (k === null || k < 0n) return void 0;
61252
+ let c = 1n;
61253
+ let steps = 0;
61254
+ for (let i = 0n; i < k; i++) {
61255
+ if ((++steps & 4095) === 0) checkDeadline(ce._deadline);
61256
+ c = c * 2n * (2n * i + 1n) / (i + 2n);
61257
+ }
61258
+ return ce.number(c);
61259
+ }
61260
+ },
61261
+ IsPerfectPower: {
61262
+ description: 'Return `"True"` if `n` is a perfect power `a^b` for integers `a` and `b \u2265 2` (a negative `n` requires an odd exponent). The smallest perfect power is 4.',
61263
+ signature: "(integer) -> boolean",
61264
+ examples: ['IsPerfectPower(64) // "True"'],
61265
+ evaluate: ([n], { engine: ce }) => {
61266
+ const k = toBigint(n);
61267
+ if (k === null) return void 0;
61268
+ const m = k < 0n ? -k : k;
61269
+ if (m < 4n) return ce.False;
61270
+ return ce.symbol(
61271
+ isPerfectPowerBigint(m, k < 0n, ce._deadline) ? "True" : "False"
61272
+ );
61273
+ }
61274
+ },
61275
+ ContinuedFraction: {
61276
+ description: "Return the continued-fraction expansion of `x` as a list of integer terms `[a0, a1, \u2026]`. An exact rational is expanded fully; for an inexact value the expansion is truncated to the optional `n` terms (default 20).",
61277
+ signature: "(number, integer?) -> list<integer>",
61278
+ examples: ["ContinuedFraction(43/19) // [2, 3, 1, 4]"],
61279
+ evaluate: ([xOp, nOp], { engine: ce }) => {
61280
+ if (xOp === void 0) return void 0;
61281
+ const maxTerms = nOp === void 0 ? void 0 : Number(toBigint(nOp) ?? 0n);
61282
+ if (maxTerms !== void 0 && maxTerms < 1) return void 0;
61283
+ const terms = [];
61284
+ if (xOp.isRational) {
61285
+ let a = toBigint(xOp.numerator);
61286
+ let b = toBigint(xOp.denominator);
61287
+ if (a === null || b === null || b === 0n) return void 0;
61288
+ if (b < 0n) {
61289
+ a = -a;
61290
+ b = -b;
61291
+ }
61292
+ while (b !== 0n) {
61293
+ let q = a / b;
61294
+ if (a % b !== 0n && a < 0n !== b < 0n) q -= 1n;
61295
+ terms.push(q);
61296
+ [a, b] = [b, a - q * b];
61297
+ if (maxTerms !== void 0 && terms.length >= maxTerms) break;
61298
+ }
61299
+ } else {
61300
+ let val = xOp.re;
61301
+ if (!Number.isFinite(val)) return void 0;
61302
+ const cap = maxTerms ?? 20;
61303
+ for (let i = 0; i < cap; i++) {
61304
+ const fl = Math.floor(val);
61305
+ terms.push(BigInt(fl));
61306
+ const frac = val - fl;
61307
+ if (frac < 1e-12) break;
61308
+ val = 1 / frac;
61309
+ if (!Number.isFinite(val)) break;
61310
+ }
61311
+ }
61312
+ return ce.function(
61313
+ "List",
61314
+ terms.map((t) => ce.number(t))
61315
+ );
61316
+ }
61317
+ },
61318
+ FromContinuedFraction: {
61319
+ description: "Reconstruct the (rational) value of a continued fraction given its list of integer terms `[a0, a1, \u2026]`.",
61320
+ signature: "(collection) -> number",
61321
+ examples: ["FromContinuedFraction([2, 3, 1, 4]) // 43/19"],
61322
+ evaluate: ([listOp], { engine: ce }) => {
61323
+ const terms = Array.from(listOp?.each() ?? []).map(toBigint);
61324
+ if (terms.length === 0 || terms.includes(null)) return void 0;
61325
+ let p = 1n;
61326
+ let q = 0n;
61327
+ for (let i = terms.length - 1; i >= 0; i--)
61328
+ [p, q] = [terms[i] * p + q, p];
61329
+ if (q === 0n) return void 0;
61330
+ return ce.number(p).div(ce.number(q));
61331
+ }
61332
+ },
61333
+ IntegerDigits: {
61334
+ description: "Return the digits of `n` in the given `base` (default 10), most-significant first. The sign of `n` is ignored. With a third argument `length`, the result is zero-padded on the left (or truncated to its least-significant digits) to that length.",
61335
+ signature: "(integer, integer?, integer?) -> list<integer>",
61336
+ examples: ["IntegerDigits(255, 16) // [15, 15]"],
61337
+ evaluate: ([nOp, baseOp, lenOp], { engine: ce }) => {
61338
+ const k = toBigint(nOp);
61339
+ if (k === null) return void 0;
61340
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61341
+ if (base === null || base < 2n) return void 0;
61342
+ let m = k < 0n ? -k : k;
61343
+ const digits = [];
61344
+ if (m === 0n) digits.push(0n);
61345
+ while (m > 0n) {
61346
+ digits.push(m % base);
61347
+ m = m / base;
61348
+ }
61349
+ digits.reverse();
61350
+ if (lenOp !== void 0) {
61351
+ const len = toBigint(lenOp);
61352
+ if (len === null || len < 0n) return void 0;
61353
+ const L = Number(len);
61354
+ while (digits.length < L) digits.unshift(0n);
61355
+ if (digits.length > L) digits.splice(0, digits.length - L);
61356
+ }
61357
+ return ce.function(
61358
+ "List",
61359
+ digits.map((d) => ce.number(d))
61360
+ );
61361
+ }
61362
+ },
61363
+ DigitCount: {
61364
+ description: "Count digits of `n` in the given `base` (default 10); the sign of `n` is ignored. With a third argument `digit`, return how many times that digit occurs. Otherwise return a list `[count of 1, count of 2, \u2026, count of base-1, count of 0]`.",
61365
+ signature: "(integer, integer?, integer?) -> integer | list<integer>",
61366
+ type: ([, , digit]) => digit !== void 0 ? "finite_integer" : "list",
61367
+ examples: ["DigitCount(122, 10, 2) // 2"],
61368
+ evaluate: ([nOp, baseOp, digitOp], { engine: ce }) => {
61369
+ const k = toBigint(nOp);
61370
+ if (k === null) return void 0;
61371
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61372
+ if (base === null || base < 2n) return void 0;
61373
+ const counts = /* @__PURE__ */ new Map();
61374
+ let m = k < 0n ? -k : k;
61375
+ if (m === 0n) counts.set(0n, 1);
61376
+ while (m > 0n) {
61377
+ const d = m % base;
61378
+ counts.set(d, (counts.get(d) ?? 0) + 1);
61379
+ m = m / base;
61380
+ }
61381
+ if (digitOp !== void 0) {
61382
+ const d = toBigint(digitOp);
61383
+ if (d === null || d < 0n || d >= base) return void 0;
61384
+ return ce.number(counts.get(d) ?? 0);
61385
+ }
61386
+ const list = [];
61387
+ for (let d = 1n; d < base; d++)
61388
+ list.push(ce.number(counts.get(d) ?? 0));
61389
+ list.push(ce.number(counts.get(0n) ?? 0));
61390
+ return ce.function("List", list);
61391
+ }
61392
+ },
61393
+ RandomPrime: {
61394
+ description: "Return a random prime. `RandomPrime(n)` draws a prime in [2, n]; `RandomPrime(m, n)` draws a prime in [m, n]. Undefined if the range contains no prime.",
61395
+ pure: false,
61396
+ signature: "(integer, integer?) -> integer",
61397
+ type: () => "finite_integer",
61398
+ examples: ["RandomPrime(100) // e.g. 47"],
61399
+ evaluate: ([aOp, bOp], { engine: ce }) => {
61400
+ let lo;
61401
+ let hi;
61402
+ if (bOp === void 0) {
61403
+ lo = 2n;
61404
+ hi = toBigint(aOp);
61405
+ } else {
61406
+ lo = toBigint(aOp);
61407
+ hi = toBigint(bOp);
61408
+ }
61409
+ if (lo === null || hi === null) return void 0;
61410
+ if (lo < 2n) lo = 2n;
61411
+ if (hi < lo) return void 0;
61412
+ const range2 = hi - lo + 1n;
61413
+ const attempts = 100 + 20 * hi.toString().length;
61414
+ for (let i = 0; i < attempts; i++) {
61415
+ const r = lo + randomBigintBelow(range2);
61416
+ if (isPrimeBigint(r)) return ce.number(r);
61417
+ }
61418
+ for (let p = lo; p <= hi; p++) {
61419
+ checkDeadline(ce._deadline);
61420
+ if (isPrimeBigint(p)) return ce.number(p);
61421
+ }
61422
+ return void 0;
61423
+ }
61424
+ },
61425
+ PrimePi: {
61426
+ description: "Return \u03C0(n), the prime-counting function: the number of primes less than or equal to `n`.",
61427
+ signature: "(real) -> integer",
61428
+ type: () => "finite_integer",
61429
+ examples: ["PrimePi(10) // 4"],
61430
+ evaluate: ([n], { engine: ce }) => {
61431
+ const x = n?.re;
61432
+ if (x === void 0 || !Number.isFinite(x)) return void 0;
61433
+ const bound = BigInt(Math.floor(x));
61434
+ if (bound < 2n) return ce.number(0);
61435
+ let count = 1;
61436
+ let steps = 0;
61437
+ for (let k = 3n; k <= bound; k += 2n) {
61438
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61439
+ if (isPrimeBigint(k)) count++;
61440
+ }
61441
+ return ce.number(count);
61442
+ }
61443
+ },
61444
+ BernoulliB: {
61445
+ description: "Return the nth Bernoulli number B\u2099 as an exact rational, using the convention B\u2081 = -1/2. Odd `n > 1` give 0.",
61446
+ signature: "(integer) -> finite_rational",
61447
+ type: () => "finite_rational",
61448
+ examples: ["BernoulliB(2) // 1/6"],
61449
+ evaluate: ([n], { engine: ce }) => {
61450
+ const k = toBigint(n);
61451
+ if (k === null || k < 0n) return void 0;
61452
+ if (k === 0n) return ce.number(1);
61453
+ if (k === 1n) return ce.number(-1).div(ce.number(2));
61454
+ if (k % 2n === 1n) return ce.number(0);
61455
+ const [num, den] = bernoulliNumber(Number(k), ce._deadline);
61456
+ return den === 1n ? ce.number(num) : ce.number(num).div(ce.number(den));
61457
+ }
61458
+ },
61459
+ FromDigits: {
61460
+ description: "Reconstruct an integer from its list of digits (most-significant first) in the given `base` (default 10). The inverse of `IntegerDigits`. Digits outside `[0, base)` are combined positionally (Horner evaluation).",
61461
+ signature: "(collection, integer?) -> integer",
61462
+ type: () => "finite_integer",
61463
+ examples: ["FromDigits([1, 2, 3, 4]) // 1234"],
61464
+ evaluate: ([digitsOp, baseOp], { engine: ce }) => {
61465
+ const digits = Array.from(digitsOp?.each() ?? []).map(toBigint);
61466
+ if (digits.length === 0 || digits.includes(null)) return void 0;
61467
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61468
+ if (base === null || base < 2n) return void 0;
61469
+ let result = 0n;
61470
+ for (const d of digits) result = result * base + d;
61471
+ return ce.number(result);
61472
+ }
61473
+ },
61474
+ DigitSum: {
61475
+ description: "Return the sum of the digits of `n` in the given `base` (default 10). The sign of `n` is ignored.",
61476
+ signature: "(integer, integer?) -> integer",
61477
+ type: () => "finite_integer",
61478
+ examples: ["DigitSum(1234) // 10"],
61479
+ evaluate: ([nOp, baseOp], { engine: ce }) => {
61480
+ const k = toBigint(nOp);
61481
+ if (k === null) return void 0;
61482
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61483
+ if (base === null || base < 2n) return void 0;
61484
+ let m = k < 0n ? -k : k;
61485
+ let sum = 0n;
61486
+ while (m > 0n) {
61487
+ sum += m % base;
61488
+ m /= base;
61489
+ }
61490
+ return ce.number(sum);
61491
+ }
61492
+ },
61493
+ DivisorSigma: {
61494
+ description: "The divisor function \u03C3_k(n) = \u03A3_{d | n} d\u1D4F over the positive divisors of `n`. \u03C3\u2080 counts divisors, \u03C3\u2081 sums them. Defined for `n \u2265 1`.",
61495
+ signature: "(integer, integer) -> integer",
61496
+ type: () => "finite_integer",
61497
+ examples: ["DivisorSigma(2, 6) // 50"],
61498
+ evaluate: ([kOp, nOp], { engine: ce }) => {
61499
+ const k = toBigint(kOp);
61500
+ const n = toBigint(nOp);
61501
+ if (k === null || n === null || k < 0n || n < 1n) return void 0;
61502
+ if (n === 1n) return ce.number(1);
61503
+ let result = 1n;
61504
+ for (const [p, e] of bigPrimeFactors(n)) {
61505
+ if (k === 0n) result *= BigInt(e + 1);
61506
+ else {
61507
+ const pk = p ** k;
61508
+ result *= (pk ** BigInt(e + 1) - 1n) / (pk - 1n);
61509
+ }
61510
+ }
61511
+ return ce.number(result);
61512
+ }
61513
+ },
61514
+ JacobiSymbol: {
61515
+ description: "The Jacobi symbol (a/n) for an odd `n > 0`. Returns -1, 0, or 1. Undefined when `n` is even or non-positive.",
61516
+ signature: "(integer, integer) -> integer",
61517
+ type: () => "finite_integer",
61518
+ examples: ["JacobiSymbol(5, 21) // 1"],
61519
+ evaluate: ([aOp, nOp], { engine: ce }) => {
61520
+ const a = toBigint(aOp);
61521
+ const n = toBigint(nOp);
61522
+ if (a === null || n === null) return void 0;
61523
+ if (n <= 0n || n % 2n === 0n) return void 0;
61524
+ return ce.number(jacobiSymbol(a, n));
61525
+ }
61526
+ },
61527
+ LegendreSymbol: {
61528
+ description: "The Legendre symbol (a/p) for an odd prime `p`. Returns -1, 0, or 1. Undefined when `p` is not an odd prime.",
61529
+ signature: "(integer, integer) -> integer",
61530
+ type: () => "finite_integer",
61531
+ examples: ["LegendreSymbol(3, 7) // -1"],
61532
+ evaluate: ([aOp, pOp], { engine: ce }) => {
61533
+ const a = toBigint(aOp);
61534
+ const p = toBigint(pOp);
61535
+ if (a === null || p === null) return void 0;
61536
+ if (p <= 2n || p % 2n === 0n || !isPrimeBigint(p)) return void 0;
61537
+ return ce.number(jacobiSymbol(a, p));
61538
+ }
61539
+ },
61540
+ MultiplicativeOrder: {
61541
+ description: "The multiplicative order of `a` modulo `n`: the smallest `k > 0` such that `a^k \u2261 1 (mod n)`. Undefined unless `a` and `n` are coprime.",
61542
+ signature: "(integer, integer) -> integer",
61543
+ type: () => "finite_integer",
61544
+ examples: ["MultiplicativeOrder(2, 7) // 3"],
61545
+ evaluate: ([aOp, nOp], { engine: ce }) => {
61546
+ const a0 = toBigint(aOp);
61547
+ const n = toBigint(nOp);
61548
+ if (a0 === null || n === null || n < 1n) return void 0;
61549
+ if (n === 1n) return ce.number(1);
61550
+ const a = (a0 % n + n) % n;
61551
+ if (gcd2(a, n) !== 1n) return void 0;
61552
+ for (const d of divisorsAscending(carmichaelLambda(n), ce._deadline)) {
61553
+ checkDeadline(ce._deadline);
61554
+ if (modPow(a, d, n) === 1n) return ce.number(d);
61555
+ }
61556
+ return void 0;
61557
+ }
61558
+ },
61559
+ PrimitiveRoot: {
61560
+ description: "The smallest primitive root modulo `n` (a generator of the multiplicative group of integers mod `n`), or undefined if none exists (which happens unless `n` is 1, 2, 4, p\u1D4F, or 2p\u1D4F for an odd prime p).",
61561
+ signature: "(integer) -> integer",
61562
+ type: () => "finite_integer",
61563
+ examples: ["PrimitiveRoot(7) // 3"],
61564
+ evaluate: ([nOp], { engine: ce }) => {
61565
+ const n = toBigint(nOp);
61566
+ if (n === null || n < 1n) return void 0;
61567
+ if (n === 1n) return ce.number(0);
61568
+ if (n === 2n) return ce.number(1);
61569
+ if (n === 4n) return ce.number(3);
61570
+ if (!hasPrimitiveRoot(n)) return void 0;
61571
+ const phi = eulerPhi(n);
61572
+ const phiFactors = [...bigPrimeFactors(phi).keys()];
61573
+ for (let a = 2n; a < n; a++) {
61574
+ checkDeadline(ce._deadline);
61575
+ if (gcd2(a, n) !== 1n) continue;
61576
+ if (phiFactors.every((q) => modPow(a, phi / q, n) !== 1n))
61577
+ return ce.number(a);
61578
+ }
61579
+ return void 0;
61580
+ }
61581
+ },
61582
+ PrimeNumber: {
61583
+ description: "The nth prime number. `PrimeNumber` is an alias for `NthPrime`, which is the preferred name.",
61584
+ signature: "(integer) -> integer",
61585
+ canonical: ([n], { engine }) => engine._fn("NthPrime", [n])
61586
+ },
60755
61587
  Totient: {
60756
61588
  wikidata: "Q190026",
60757
61589
  description: "Euler's totient function \u03C6(n): count of positive integers \u2264 n that are coprime to n.",
@@ -60988,6 +61820,165 @@ ${e instanceof Error ? e.message : e}
60988
61820
  }
60989
61821
  }
60990
61822
  ];
61823
+ function extGcd(a, b) {
61824
+ let [oldR, r] = [a, b];
61825
+ let [oldS, s] = [1n, 0n];
61826
+ let [oldT, t] = [0n, 1n];
61827
+ while (r !== 0n) {
61828
+ const q = oldR / r;
61829
+ [oldR, r] = [r, oldR - q * r];
61830
+ [oldS, s] = [s, oldS - q * s];
61831
+ [oldT, t] = [t, oldT - q * t];
61832
+ }
61833
+ return [oldR, oldS, oldT];
61834
+ }
61835
+ function bigintSqrt2(n) {
61836
+ if (n < 2n) return n;
61837
+ let x = 1n << (BigInt(n.toString(2).length) + 1n) / 2n;
61838
+ for (; ; ) {
61839
+ const y = x + n / x >> 1n;
61840
+ if (y >= x) break;
61841
+ x = y;
61842
+ }
61843
+ while (x * x > n) x -= 1n;
61844
+ return x;
61845
+ }
61846
+ function chineseRemainder(residues, moduli) {
61847
+ let x = 0n;
61848
+ let m = 1n;
61849
+ for (let i = 0; i < residues.length; i++) {
61850
+ const ni = moduli[i];
61851
+ if (ni <= 0n) return null;
61852
+ const ri = (residues[i] % ni + ni) % ni;
61853
+ const [g, p] = extGcd(m, ni);
61854
+ if ((ri - x) % g !== 0n) return null;
61855
+ const lcmMN = m / g * ni;
61856
+ const mod22 = ni / g;
61857
+ const lambda = ((ri - x) / g * p % mod22 + mod22) % mod22;
61858
+ x = ((x + m * lambda) % lcmMN + lcmMN) % lcmMN;
61859
+ m = lcmMN;
61860
+ }
61861
+ return x;
61862
+ }
61863
+ function iroot(n, b) {
61864
+ if (n < 2n) return n;
61865
+ const bb = BigInt(b);
61866
+ const approx = Math.pow(Number(n), 1 / b);
61867
+ let x = Number.isFinite(approx) ? BigInt(Math.round(approx)) : 1n << BigInt(n.toString(2).length) / bb + 1n;
61868
+ if (x < 1n) x = 1n;
61869
+ while (x ** bb > n) x -= 1n;
61870
+ while ((x + 1n) ** bb <= n) x += 1n;
61871
+ return x;
61872
+ }
61873
+ function isPerfectPowerBigint(m, oddOnly, deadline) {
61874
+ const bits = m.toString(2).length;
61875
+ for (let b = oddOnly ? 3 : 2; b <= bits; b++) {
61876
+ if (oddOnly && b % 2 === 0) continue;
61877
+ checkDeadline(deadline);
61878
+ const r = iroot(m, b);
61879
+ if (r >= 2n && r ** BigInt(b) === m) return true;
61880
+ }
61881
+ return false;
61882
+ }
61883
+ function randomBigintBelow(n) {
61884
+ if (n <= 1n) return 0n;
61885
+ if (n <= BigInt(Number.MAX_SAFE_INTEGER))
61886
+ return BigInt(Math.floor(Math.random() * Number(n)));
61887
+ const bits = n.toString(2).length;
61888
+ let r;
61889
+ do {
61890
+ r = 0n;
61891
+ for (let i = 0; i < bits; i += 30)
61892
+ r = r << 30n | BigInt(Math.floor(Math.random() * (1 << 30)));
61893
+ r &= (1n << BigInt(bits)) - 1n;
61894
+ } while (r >= n);
61895
+ return r;
61896
+ }
61897
+ function divisorsAscending(m, deadline) {
61898
+ const small = [];
61899
+ const large = [];
61900
+ let steps = 0;
61901
+ for (let i = 1n; i * i <= m; i++) {
61902
+ if ((++steps & 4095) === 0) checkDeadline(deadline);
61903
+ if (m % i === 0n) {
61904
+ small.push(i);
61905
+ const j = m / i;
61906
+ if (j !== i) large.push(j);
61907
+ }
61908
+ }
61909
+ large.reverse();
61910
+ return [...small, ...large];
61911
+ }
61912
+ function eulerPhi(n) {
61913
+ if (n <= 1n) return 1n;
61914
+ let result = n;
61915
+ for (const p of bigPrimeFactors(n).keys()) result = result / p * (p - 1n);
61916
+ return result;
61917
+ }
61918
+ function carmichaelLambda(n) {
61919
+ if (n <= 1n) return 1n;
61920
+ let result = 1n;
61921
+ for (const [p, e] of bigPrimeFactors(n)) {
61922
+ const lambda = p === 2n ? e === 1 ? 1n : e === 2 ? 2n : 1n << BigInt(e - 2) : p ** BigInt(e - 1) * (p - 1n);
61923
+ result = lcm2(result, lambda);
61924
+ }
61925
+ return result;
61926
+ }
61927
+ function jacobiSymbol(a, n) {
61928
+ a = (a % n + n) % n;
61929
+ let result = 1;
61930
+ while (a !== 0n) {
61931
+ while (a % 2n === 0n) {
61932
+ a /= 2n;
61933
+ const r = n % 8n;
61934
+ if (r === 3n || r === 5n) result = -result;
61935
+ }
61936
+ [a, n] = [n, a];
61937
+ if (a % 4n === 3n && n % 4n === 3n) result = -result;
61938
+ a %= n;
61939
+ }
61940
+ return n === 1n ? result : 0;
61941
+ }
61942
+ function hasPrimitiveRoot(n) {
61943
+ if (n === 1n || n === 2n || n === 4n) return true;
61944
+ let m = n;
61945
+ let twos = 0;
61946
+ while (m % 2n === 0n) {
61947
+ m /= 2n;
61948
+ twos++;
61949
+ }
61950
+ if (twos > 1) return false;
61951
+ if (m === 1n) return false;
61952
+ return bigPrimeFactors(m).size === 1;
61953
+ }
61954
+ function reduceRat(num, den) {
61955
+ if (den < 0n) {
61956
+ num = -num;
61957
+ den = -den;
61958
+ }
61959
+ const g = gcd2(num < 0n ? -num : num, den);
61960
+ return g > 1n ? [num / g, den / g] : [num, den];
61961
+ }
61962
+ function bernoulliNumber(n, deadline) {
61963
+ const B = [[1n, 1n]];
61964
+ for (let m = 1; m <= n; m++) {
61965
+ checkDeadline(deadline);
61966
+ let sNum = 0n;
61967
+ let sDen = 1n;
61968
+ let c = 1n;
61969
+ for (let k = 0; k < m; k++) {
61970
+ const tNum = c * B[k][0];
61971
+ const tDen = B[k][1];
61972
+ const g = gcd2(sDen, tDen);
61973
+ sNum = sNum * (tDen / g) + tNum * (sDen / g);
61974
+ sDen = sDen / g * tDen;
61975
+ [sNum, sDen] = reduceRat(sNum, sDen);
61976
+ c = c * BigInt(m + 1 - k) / BigInt(k + 1);
61977
+ }
61978
+ B.push(reduceRat(-sNum, sDen * BigInt(m + 1)));
61979
+ }
61980
+ return B[n];
61981
+ }
60991
61982
  function sumSquareDigits(k) {
60992
61983
  return k.toString().split("").map((d) => BigInt(d)).reduce((sum, d) => sum + d * d, 0n);
60993
61984
  }
@@ -83931,7 +84922,7 @@ vec2 _iv_mod(vec2 a, vec2 b) {
83931
84922
  _setDefaultEngineFactory(() => new ComputeEngine());
83932
84923
 
83933
84924
  // src/core.ts
83934
- var version = "0.63.0";
84925
+ var version = "0.64.0";
83935
84926
  return __toCommonJS(core_exports);
83936
84927
  })();
83937
84928
  /*! Bundled license information: