@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
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.63.0 */
1
+ /** Compute Engine 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.ComputeEngine = {}));})(this, (function (exports) { 'use strict';
3
3
  "use strict";
4
4
  var ComputeEngine = (() => {
@@ -5355,7 +5355,6 @@ var ComputeEngine = (() => {
5355
5355
  }
5356
5356
 
5357
5357
  // src/compute-engine/numerics/primes.ts
5358
- var LARGE_PRIME = 1125899906842597;
5359
5358
  var SMALL_PRIMES = /* @__PURE__ */ new Set([
5360
5359
  2,
5361
5360
  3,
@@ -6402,102 +6401,60 @@ var ComputeEngine = (() => {
6402
6401
  else result[n] = 1;
6403
6402
  return result;
6404
6403
  }
6405
- function isPrime(n) {
6406
- if (!Number.isInteger(n) || !Number.isFinite(n) || Number.isNaN(n) || n <= 1) {
6407
- return false;
6408
- }
6409
- if (n <= LARGEST_SMALL_PRIME) return SMALL_PRIMES.has(n);
6410
- for (const smallPrime of SMALL_PRIMES) {
6411
- if (n % smallPrime === 0) return false;
6412
- }
6413
- if (n < LARGE_PRIME) return n === leastFactor(n) || void 0;
6414
- return probablyPrime(n, 30) ? void 0 : false;
6415
- }
6416
- function leastFactor(n) {
6417
- if (n === 1) return 1;
6418
- if (n % 2 === 0) return 2;
6419
- if (n % 3 === 0) return 3;
6420
- if (n % 5 === 0) return 5;
6421
- const m = Math.floor(Math.sqrt(n));
6422
- let i = 7;
6423
- while (i <= m) {
6424
- if (n % i === 0) return i;
6425
- if (n % (i + 4) === 0) return i + 4;
6426
- if (n % (i + 6) === 0) return i + 6;
6427
- if (n % (i + 10) === 0) return i + 10;
6428
- if (n % (i + 12) === 0) return i + 12;
6429
- if (n % (i + 16) === 0) return i + 16;
6430
- if (n % (i + 22) === 0) return i + 22;
6431
- if (n % (i + 24) === 0) return i + 24;
6432
- i += 30;
6433
- }
6434
- return n;
6435
- }
6404
+ var MILLER_RABIN_THRESHOLD = 1n << 32n;
6405
+ var MILLER_RABIN_BASES = [
6406
+ 2n,
6407
+ 3n,
6408
+ 5n,
6409
+ 7n,
6410
+ 11n,
6411
+ 13n,
6412
+ 17n,
6413
+ 19n,
6414
+ 23n,
6415
+ 29n,
6416
+ 31n,
6417
+ 37n
6418
+ ];
6436
6419
  function isPrimeBigint(n) {
6437
- if (n <= 1) return false;
6438
- if (n <= LARGEST_SMALL_PRIME) return isPrime(Number(n));
6439
- for (const smallPrime of SMALL_PRIMES) {
6440
- if (n % BigInt(smallPrime) === BigInt(0)) return false;
6441
- }
6442
- if (n < LARGE_PRIME) n = leastBigFactor(n);
6443
- return probablyPrimeBigint(n, 30) ? void 0 : false;
6444
- }
6445
- function leastBigFactor(n) {
6446
- if (n === BigInt(1)) return BigInt(1);
6447
- if (n % BigInt(2) === BigInt(0)) return BigInt(2);
6448
- if (n % BigInt(3) === BigInt(0)) return BigInt(3);
6449
- if (n % BigInt(5) === BigInt(0)) return BigInt(5);
6450
- const m = BigInt(Math.floor(Math.sqrt(Number(n))));
6451
- let i = BigInt(7);
6452
- while (i <= m) {
6453
- if (n % i === BigInt(0)) return i;
6454
- if (n % (i + BigInt(4)) === BigInt(0)) return i + BigInt(4);
6455
- if (n % (i + BigInt(6)) === BigInt(0)) return i + BigInt(6);
6456
- if (n % (i + BigInt(10)) === BigInt(0)) return i + BigInt(10);
6457
- if (n % (i + BigInt(12)) === BigInt(0)) return i + BigInt(12);
6458
- if (n % (i + BigInt(16)) === BigInt(0)) return i + BigInt(16);
6459
- if (n % (i + BigInt(22)) === BigInt(0)) return i + BigInt(22);
6460
- if (n % (i + BigInt(24)) === BigInt(0)) return i + BigInt(24);
6461
- i += BigInt(30);
6420
+ if (n < 2n) return false;
6421
+ if (n <= LARGEST_SMALL_PRIME) return SMALL_PRIMES.has(Number(n));
6422
+ if (n < MILLER_RABIN_THRESHOLD) {
6423
+ if (n % 2n === 0n || n % 3n === 0n) return false;
6424
+ for (let i = 5n; i * i <= n; i += 6n)
6425
+ if (n % i === 0n || n % (i + 2n) === 0n) return false;
6426
+ return true;
6462
6427
  }
6463
- return n;
6428
+ return millerRabin(n);
6464
6429
  }
6465
- function probablyPrime(n, k) {
6466
- let s = 0;
6467
- let d = n - 1;
6468
- while (d % 2 === 0) {
6469
- d /= 2;
6470
- ++s;
6471
- }
6472
- WitnessLoop: do {
6473
- let x = Math.pow(2 + Math.floor(Math.random() * (n - 3)), d) % n;
6474
- if (x === 1 || x === n - 1) continue;
6475
- for (let i = s - 1; i--; ) {
6476
- x = x * x % n;
6477
- if (x === 1) return false;
6478
- if (x === n - 1) continue WitnessLoop;
6479
- }
6480
- return false;
6481
- } while (--k);
6482
- return true;
6430
+ function modPow(base, exp3, mod3) {
6431
+ if (mod3 === 1n) return 0n;
6432
+ let result = 1n;
6433
+ base = (base % mod3 + mod3) % mod3;
6434
+ while (exp3 > 0n) {
6435
+ if (exp3 & 1n) result = result * base % mod3;
6436
+ base = base * base % mod3;
6437
+ exp3 >>= 1n;
6438
+ }
6439
+ return result;
6483
6440
  }
6484
- function probablyPrimeBigint(n, k) {
6485
- let s = 0;
6486
- let d = n - BigInt(1);
6487
- while (d % BigInt(2) === BigInt(0)) {
6488
- d = d / BigInt(2);
6489
- ++s;
6490
- }
6491
- WitnessLoop: do {
6492
- let x = BigInt(2 + Math.floor(Math.random() * (Number(n) - 3))) ** d % n;
6493
- if (x === BigInt(1) || x === n - BigInt(1)) continue;
6494
- for (let i = s - 1; i--; ) {
6441
+ function millerRabin(n) {
6442
+ for (const p of MILLER_RABIN_BASES) if (n % p === 0n) return n === p;
6443
+ let d = n - 1n;
6444
+ let s = 0n;
6445
+ while (d % 2n === 0n) {
6446
+ d /= 2n;
6447
+ s += 1n;
6448
+ }
6449
+ WitnessLoop: for (const a of MILLER_RABIN_BASES) {
6450
+ let x = modPow(a, d, n);
6451
+ if (x === 1n || x === n - 1n) continue;
6452
+ for (let r = 1n; r < s; r++) {
6495
6453
  x = x * x % n;
6496
- if (x === BigInt(1)) return false;
6497
- if (x === n - BigInt(1)) continue WitnessLoop;
6454
+ if (x === n - 1n) continue WitnessLoop;
6498
6455
  }
6499
6456
  return false;
6500
- } while (--k);
6457
+ }
6501
6458
  return true;
6502
6459
  }
6503
6460
  var PRIME_WHEEL_INC = [
@@ -6510,6 +6467,63 @@ var ComputeEngine = (() => {
6510
6467
  BigInt(2),
6511
6468
  BigInt(6)
6512
6469
  ];
6470
+ function bigPrimeFactors(d) {
6471
+ if (d < Number.MAX_SAFE_INTEGER) {
6472
+ const factors = primeFactors(Number(d));
6473
+ const result2 = /* @__PURE__ */ new Map();
6474
+ for (const f of Object.keys(factors))
6475
+ result2.set(bigint(f), factors[Number(f)]);
6476
+ return result2;
6477
+ }
6478
+ let n = d;
6479
+ const result = /* @__PURE__ */ new Map();
6480
+ let count2 = 0;
6481
+ let count3 = 0;
6482
+ let count5 = 0;
6483
+ let k = BigInt(10);
6484
+ while (n % k === BigInt(0)) {
6485
+ count2 += 1;
6486
+ count5 += 1;
6487
+ n = n / k;
6488
+ }
6489
+ k = BigInt(5);
6490
+ while (n % k === BigInt(0)) {
6491
+ count5 += 1;
6492
+ n = n / k;
6493
+ }
6494
+ k = BigInt(3);
6495
+ while (n % k === BigInt(0)) {
6496
+ count3 += 1;
6497
+ n = n / k;
6498
+ }
6499
+ k = BigInt(2);
6500
+ while (n % k === BigInt(0)) {
6501
+ count2 += 1;
6502
+ n = n / k;
6503
+ }
6504
+ if (count2 > 0) result.set("2", count2);
6505
+ if (count3 > 0) result.set("3", count3);
6506
+ if (count5 > 0) result.set("5", count5);
6507
+ k = BigInt(7);
6508
+ let kIndex = "";
6509
+ let i = 0;
6510
+ while (k * k < n) {
6511
+ if (n % k === BigInt(0)) {
6512
+ if (!kIndex) kIndex = k.toString();
6513
+ result.set(kIndex, (result.get(kIndex) ?? 0) + 1);
6514
+ n = n / k;
6515
+ } else {
6516
+ k = k + PRIME_WHEEL_INC[i];
6517
+ kIndex = "";
6518
+ i = i < 7 ? i + 1 : 0;
6519
+ }
6520
+ }
6521
+ if (n !== BigInt(1))
6522
+ result.set(n.toString(), (result.get(n.toString()) ?? 0) + 1);
6523
+ const r = /* @__PURE__ */ new Map();
6524
+ for (const [k2, v] of result) r.set(bigint(k2), v);
6525
+ return r;
6526
+ }
6513
6527
 
6514
6528
  // src/compute-engine/numerics/numeric.ts
6515
6529
  var DEFAULT_PRECISION = 21;
@@ -25351,7 +25365,11 @@ ${lines.join("\n")}`;
25351
25365
  function toInteger(expr2) {
25352
25366
  if (!isNumber(expr2)) return null;
25353
25367
  const num = expr2.numericValue;
25354
- return Math.round(typeof num === "number" ? num : num.re);
25368
+ const re = typeof num === "number" ? num : num.re;
25369
+ if (!Number.isFinite(re)) return null;
25370
+ const n = Math.round(re);
25371
+ if (!Number.isSafeInteger(n)) return null;
25372
+ return n;
25355
25373
  }
25356
25374
  function toBigint(expr2) {
25357
25375
  if (expr2 === void 0 || expr2 === null) return null;
@@ -31970,12 +31988,10 @@ ${lines.join("\n")}`;
31970
31988
  }
31971
31989
 
31972
31990
  // src/compute-engine/boxed-expression/predicates.ts
31973
- function isPrime2(expr2) {
31991
+ function isPrime(expr2) {
31974
31992
  if (!expr2.isInteger) return void 0;
31975
31993
  if (expr2.isNegative) return void 0;
31976
31994
  if (!isNumber(expr2)) return void 0;
31977
- const n = toInteger(expr2);
31978
- if (n !== null) return isPrime(n);
31979
31995
  const b = asBigint(expr2);
31980
31996
  if (b !== null) return isPrimeBigint(b);
31981
31997
  return void 0;
@@ -37947,6 +37963,7 @@ ${lines.join("\n")}`;
37947
37963
  sgn: ([x]) => x.isNonNegative ? "positive" : x.isNegative || x.isReal === false ? "unsigned" : void 0,
37948
37964
  evaluate: (ops) => {
37949
37965
  const x = ops[0];
37966
+ if (x.isInteger !== true) return void 0;
37950
37967
  const n = toInteger(x);
37951
37968
  if (n === null) return void 0;
37952
37969
  const ce = x.engine;
@@ -38900,7 +38917,7 @@ ${lines.join("\n")}`;
38900
38917
  broadcastable: true,
38901
38918
  signature: "(number) -> boolean",
38902
38919
  evaluate: ([n], { engine }) => {
38903
- const result = isPrime2(n);
38920
+ const result = isPrime(n);
38904
38921
  if (result === void 0) return void 0;
38905
38922
  return engine.symbol(result ? "True" : "False");
38906
38923
  }
@@ -39582,8 +39599,8 @@ ${lines.join("\n")}`;
39582
39599
  nonpositive: (x) => x.isNonPositive,
39583
39600
  even: (x) => x.isEven,
39584
39601
  odd: (x) => x.isOdd,
39585
- prime: (x) => isPrime2(x) === true,
39586
- composite: (x) => isPrime2(x) === false,
39602
+ prime: (x) => isPrime(x) === true,
39603
+ composite: (x) => isPrime(x) === false,
39587
39604
  notzero: (x) => x.isSame(0) === false,
39588
39605
  notone: (x) => x.isSame(1) === false,
39589
39606
  finite: (x) => x.isFinite,
@@ -56602,6 +56619,7 @@ ${e instanceof Error ? e.message : e}
56602
56619
  signature: "(integer) -> integer",
56603
56620
  type: () => "finite_integer",
56604
56621
  evaluate: ([n], { engine: ce }) => {
56622
+ if (n.isInteger !== true) return void 0;
56605
56623
  const k = toInteger(n);
56606
56624
  if (k === null || k < 0) return void 0;
56607
56625
  let result = 1n;
@@ -56619,6 +56637,7 @@ ${e instanceof Error ? e.message : e}
56619
56637
  signature: "(integer) -> integer",
56620
56638
  type: () => "finite_integer",
56621
56639
  evaluate: ([n], { engine: ce }) => {
56640
+ if (n.isInteger !== true) return void 0;
56622
56641
  const k = toInteger(n);
56623
56642
  if (k === null || k < 0) return void 0;
56624
56643
  let row = [1n];
@@ -58198,17 +58217,35 @@ ${e instanceof Error ? e.message : e}
58198
58217
  }
58199
58218
  },
58200
58219
  N: {
58201
- description: "Numerically evaluate an expression",
58220
+ description: [
58221
+ "N(expr): numerically evaluate an expression",
58222
+ "N(expr, precision): evaluate to `precision` significant digits"
58223
+ ],
58202
58224
  lazy: true,
58203
- signature: "(any) -> unknown",
58225
+ signature: "(any, integer?) -> unknown",
58204
58226
  type: ([x]) => x.type,
58205
58227
  canonical: (ops, { engine: ce }) => {
58206
- if (ops.length !== 1) return ce._fn("N", checkArity(ce, ops, 1));
58207
- const h = ops[0].operator;
58208
- if (h === "N" || h === "Evaluate") return ops[0].canonical;
58228
+ if (ops.length === 0) return ce._fn("N", checkArity(ce, ops, 1));
58229
+ if (ops.length > 2) return ce._fn("N", checkArity(ce, ops, 2));
58230
+ if (ops.length === 1) {
58231
+ const h = ops[0].operator;
58232
+ if (h === "N" || h === "Evaluate") return ops[0].canonical;
58233
+ }
58209
58234
  return ce._fn("N", ops);
58210
58235
  },
58211
- evaluate: ([x]) => x.N()
58236
+ evaluate: (ops, { engine: ce }) => {
58237
+ const x = ops[0];
58238
+ if (ops.length < 2) return x.canonical.N();
58239
+ let p = ops[1].canonical.N().re;
58240
+ if (!Number.isFinite(p) || p < 1) return x.canonical.N();
58241
+ p = Math.min(Math.trunc(p), 1e3);
58242
+ const global = ce.precision;
58243
+ if (p > global) {
58244
+ ce.precision = p;
58245
+ return x.canonical.N();
58246
+ }
58247
+ return roundToSignificantDigits(x.canonical.N(), p);
58248
+ }
58212
58249
  },
58213
58250
  Random: {
58214
58251
  description: [
@@ -58713,6 +58750,20 @@ ${e instanceof Error ? e.message : e}
58713
58750
  }
58714
58751
  }
58715
58752
  ];
58753
+ function roundToSignificantDigits(value, p) {
58754
+ const ce = value.engine;
58755
+ const re = value.re;
58756
+ const im = value.im;
58757
+ if (!Number.isFinite(re) || !Number.isFinite(im)) return value;
58758
+ if (im !== 0) {
58759
+ const clamp2 = Math.min(p, 100);
58760
+ return ce.number(
58761
+ ce.complex(Number(re.toPrecision(clamp2)), Number(im.toPrecision(clamp2)))
58762
+ );
58763
+ }
58764
+ const bd = value.bignumRe ?? ce.bignum(re);
58765
+ return ce.number(bd.toPrecision(p));
58766
+ }
58716
58767
 
58717
58768
  // src/compute-engine/library/linear-algebra.ts
58718
58769
  var LINEAR_ALGEBRA_LIBRARY = [
@@ -59171,6 +59222,165 @@ ${e instanceof Error ? e.message : e}
59171
59222
  return void 0;
59172
59223
  }
59173
59224
  },
59225
+ Dot: {
59226
+ description: "Dot product (vector inner product) or matrix product.",
59227
+ complexity: 8300,
59228
+ signature: "(matrix|vector, matrix|vector) -> value",
59229
+ // `Dot` is Mathematica's `.`: it reduces to the inner product for two
59230
+ // vectors and to the matrix product otherwise — exactly what
59231
+ // `MatrixMultiply` already computes.
59232
+ evaluate: (ops, { engine: ce }) => ce.function("MatrixMultiply", ops).evaluate()
59233
+ },
59234
+ MatrixRank: {
59235
+ description: "Rank of a matrix (number of linearly independent rows/columns).",
59236
+ complexity: 8200,
59237
+ signature: "(value) -> integer",
59238
+ sgn: () => "non-negative",
59239
+ evaluate: ([map], { engine: ce }) => {
59240
+ const op = map.evaluate();
59241
+ if (op.isNumber) return ce.number(op.isSame(0) ? 0 : 1);
59242
+ if (!isTensor2(op)) return void 0;
59243
+ const shape = op.shape;
59244
+ if (shape.length > 2) return ce.error("expected-matrix", op.toString());
59245
+ const rowCount = shape.length === 1 ? 1 : shape[0];
59246
+ const columnCount = shape.length === 1 ? shape[0] : shape[1];
59247
+ const matrix = tensorToNumericMatrix(op, rowCount, columnCount);
59248
+ if (!matrix) return void 0;
59249
+ const nullity = computeNullSpaceBasis(matrix).length;
59250
+ return ce.number(columnCount - nullity);
59251
+ }
59252
+ },
59253
+ IsSquareMatrix: {
59254
+ description: "Whether the value is a square matrix.",
59255
+ complexity: 8200,
59256
+ signature: "(value) -> boolean",
59257
+ evaluate: ([m], { engine: ce }) => {
59258
+ const op = m.evaluate();
59259
+ if (!isTensor2(op)) return ce.False;
59260
+ return op.tensor.isSquare ? ce.True : ce.False;
59261
+ }
59262
+ },
59263
+ IsSymmetric: {
59264
+ description: "Whether the matrix is symmetric (A equals its transpose).",
59265
+ complexity: 8200,
59266
+ signature: "(value) -> boolean",
59267
+ evaluate: ([m], { engine: ce }) => {
59268
+ const op = m.evaluate();
59269
+ if (!isTensor2(op)) return ce.False;
59270
+ return op.tensor.isSymmetric ? ce.True : ce.False;
59271
+ }
59272
+ },
59273
+ IsDiagonal: {
59274
+ description: "Whether the matrix is diagonal (all off-diagonal entries are zero).",
59275
+ complexity: 8200,
59276
+ signature: "(value) -> boolean",
59277
+ evaluate: ([m], { engine: ce }) => {
59278
+ const op = m.evaluate();
59279
+ if (!isTensor2(op)) return ce.False;
59280
+ return op.tensor.isDiagonal ? ce.True : ce.False;
59281
+ }
59282
+ },
59283
+ Cross: {
59284
+ description: "Cross product of two 3-vectors.",
59285
+ complexity: 8300,
59286
+ signature: "(vector, vector) -> vector",
59287
+ evaluate: ([a, b], { engine: ce }) => {
59288
+ const A = a.evaluate();
59289
+ const B = b.evaluate();
59290
+ if (!isTensor2(A) || !isTensor2(B)) return void 0;
59291
+ if (A.shape.length !== 1 || A.shape[0] !== 3 || B.shape.length !== 1 || B.shape[0] !== 3)
59292
+ return ce.error(
59293
+ "incompatible-dimensions",
59294
+ "cross product requires two 3-vectors"
59295
+ );
59296
+ const a1 = ce.expr(A.tensor.at(1) ?? ce.Zero);
59297
+ const a2 = ce.expr(A.tensor.at(2) ?? ce.Zero);
59298
+ const a3 = ce.expr(A.tensor.at(3) ?? ce.Zero);
59299
+ const b1 = ce.expr(B.tensor.at(1) ?? ce.Zero);
59300
+ const b2 = ce.expr(B.tensor.at(2) ?? ce.Zero);
59301
+ const b3 = ce.expr(B.tensor.at(3) ?? ce.Zero);
59302
+ return ce.function("List", [
59303
+ a2.mul(b3).sub(a3.mul(b2)),
59304
+ a3.mul(b1).sub(a1.mul(b3)),
59305
+ a1.mul(b2).sub(a2.mul(b1))
59306
+ ]).evaluate();
59307
+ }
59308
+ },
59309
+ MatrixPower: {
59310
+ description: "Square matrix raised to an integer power (repeated matrix product).",
59311
+ complexity: 8300,
59312
+ signature: "(matrix, integer) -> matrix",
59313
+ evaluate: ([mat, exponent], { engine: ce }) => {
59314
+ const A = mat.evaluate();
59315
+ if (!isTensor2(A)) return void 0;
59316
+ if (!A.tensor.isSquare)
59317
+ return ce.error("expected-square-matrix", A.toString());
59318
+ const n = exponent.re;
59319
+ if (n === void 0 || !Number.isInteger(n)) return void 0;
59320
+ const size = A.shape[0];
59321
+ if (n === 0)
59322
+ return ce.function("IdentityMatrix", [ce.number(size)]).evaluate();
59323
+ let base = A;
59324
+ let k = n;
59325
+ if (n < 0) {
59326
+ const inv = ce.function("Inverse", [A]).evaluate();
59327
+ if (!isTensor2(inv)) return inv;
59328
+ base = inv;
59329
+ k = -n;
59330
+ }
59331
+ let result = base;
59332
+ for (let i = 1; i < k; i++)
59333
+ result = ce.function("MatrixMultiply", [result, base]).evaluate();
59334
+ return result;
59335
+ }
59336
+ },
59337
+ CharacteristicPolynomial: {
59338
+ description: "Characteristic polynomial det(x\xB7I \u2212 A) of a square matrix (monic).",
59339
+ complexity: 8700,
59340
+ // The variable is accepted as `any` (not `symbol`): an undeclared symbol
59341
+ // is inferred to have a numeric type, which would fail a `symbol`
59342
+ // signature check. The evaluate handler validates it with `isSymbol`.
59343
+ signature: "(matrix, any?) -> expression",
59344
+ evaluate: ([mat, variable], { engine: ce }) => {
59345
+ const A = mat.evaluate();
59346
+ if (!isTensor2(A)) return void 0;
59347
+ if (!A.tensor.isSquare)
59348
+ return ce.error("expected-square-matrix", A.toString());
59349
+ const x = variable && isSymbol2(variable) ? variable : ce.symbol("x");
59350
+ const n = A.shape[0];
59351
+ const rows = [];
59352
+ for (let i = 0; i < n; i++) {
59353
+ const row = [];
59354
+ for (let j = 0; j < n; j++) {
59355
+ const entry = ce.expr(A.tensor.at(i + 1, j + 1) ?? ce.Zero);
59356
+ row.push(i === j ? x.sub(entry) : entry.neg());
59357
+ }
59358
+ rows.push(ce.function("List", row));
59359
+ }
59360
+ return ce.function("Determinant", [ce.function("List", rows)]).evaluate();
59361
+ }
59362
+ },
59363
+ RowReduce: {
59364
+ description: "Reduced row echelon form (RREF) of a matrix.",
59365
+ complexity: 8200,
59366
+ signature: "(matrix) -> matrix",
59367
+ evaluate: ([m], { engine: ce }) => {
59368
+ const op = m.evaluate();
59369
+ if (!isTensor2(op)) return void 0;
59370
+ const shape = op.shape;
59371
+ if (shape.length !== 2)
59372
+ return ce.error("expected-matrix", op.toString());
59373
+ const matrix = tensorToNumericMatrix(op, shape[0], shape[1]);
59374
+ if (!matrix) return void 0;
59375
+ const { matrix: reduced } = rref(matrix);
59376
+ return ce.expr([
59377
+ "List",
59378
+ ...reduced.map(
59379
+ (row) => ce.expr(["List", ...row.map((value) => ce.number(ce.chop(value)))])
59380
+ )
59381
+ ]);
59382
+ }
59383
+ },
59174
59384
  // Diagonal can be used to:
59175
59385
  // 1. Create a diagonal matrix from a vector
59176
59386
  // 2. Extract the diagonal from a matrix as a vector
@@ -60781,6 +60991,628 @@ ${e instanceof Error ? e.message : e}
60781
60991
  // src/compute-engine/library/number-theory.ts
60782
60992
  var NUMBER_THEORY_LIBRARY = [
60783
60993
  {
60994
+ FactorInteger: {
60995
+ 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.",
60996
+ signature: "(integer) -> list<tuple<integer, integer>>",
60997
+ examples: ["FactorInteger(360) // [(2, 3), (3, 2), (5, 1)]"],
60998
+ evaluate: ([n], { engine: ce }) => {
60999
+ const k = toBigint(n);
61000
+ if (k === null) return void 0;
61001
+ const tuple = (prime, exponent) => ce._fn("Tuple", [ce.number(prime), ce.number(exponent)]);
61002
+ if (k === 0n) return ce.function("List", [tuple(0n, 1)]);
61003
+ if (k === 1n) return ce.function("List", [tuple(1n, 1)]);
61004
+ const result = [];
61005
+ let m = k;
61006
+ if (m < 0n) {
61007
+ result.push(tuple(-1n, 1));
61008
+ m = -m;
61009
+ }
61010
+ if (m > 1n) {
61011
+ const factors = bigPrimeFactors(m);
61012
+ const primes = [...factors.keys()].sort(
61013
+ (a, b) => a < b ? -1 : a > b ? 1 : 0
61014
+ );
61015
+ for (const p of primes) result.push(tuple(p, factors.get(p)));
61016
+ }
61017
+ return ce.function("List", result);
61018
+ }
61019
+ },
61020
+ Divisors: {
61021
+ description: "Return the sorted list of positive divisors of an integer `n`. The sign of `n` is ignored.",
61022
+ signature: "(integer) -> list<integer>",
61023
+ examples: ["Divisors(12) // [1, 2, 3, 4, 6, 12]"],
61024
+ evaluate: ([n], { engine: ce }) => {
61025
+ const k = toBigint(n);
61026
+ if (k === null) return void 0;
61027
+ const m = k < 0n ? -k : k;
61028
+ if (m === 0n) return void 0;
61029
+ return ce.function(
61030
+ "List",
61031
+ divisorsAscending(m, ce._deadline).map((d) => ce.number(d))
61032
+ );
61033
+ }
61034
+ },
61035
+ NthPrime: {
61036
+ description: "Return the nth prime number (1-based): `NthPrime(1)` is 2, `NthPrime(2)` is 3, \u2026",
61037
+ signature: "(integer) -> integer",
61038
+ type: () => "finite_integer",
61039
+ examples: ["NthPrime(10) // 29"],
61040
+ evaluate: ([n], { engine: ce }) => {
61041
+ const k = toBigint(n);
61042
+ if (k === null || k < 1n) return void 0;
61043
+ if (k === 1n) return ce.number(2);
61044
+ let count = 1n;
61045
+ let candidate = 1n;
61046
+ let steps = 0;
61047
+ while (count < k) {
61048
+ candidate += 2n;
61049
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61050
+ if (isPrimeBigint(candidate)) count += 1n;
61051
+ }
61052
+ return ce.number(candidate);
61053
+ }
61054
+ },
61055
+ NextPrime: {
61056
+ 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`).",
61057
+ signature: "(integer, integer?) -> integer",
61058
+ type: () => "finite_integer",
61059
+ examples: ["NextPrime(10) // 11", "NextPrime(10, -1) // 7"],
61060
+ evaluate: ([n, kArg], { engine: ce }) => {
61061
+ const start = toBigint(n);
61062
+ if (start === null) return void 0;
61063
+ const k = kArg === void 0 ? 1n : toBigint(kArg);
61064
+ if (k === null || k === 0n) return void 0;
61065
+ let p = start;
61066
+ let steps = 0;
61067
+ if (k > 0n) {
61068
+ for (let i = 0n; i < k; i++) {
61069
+ do {
61070
+ p += 1n;
61071
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61072
+ } while (!isPrimeBigint(p));
61073
+ }
61074
+ } else {
61075
+ for (let i = 0n; i > k; i--) {
61076
+ do {
61077
+ p -= 1n;
61078
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61079
+ if (p < 2n) return void 0;
61080
+ } while (!isPrimeBigint(p));
61081
+ }
61082
+ }
61083
+ return ce.number(p);
61084
+ }
61085
+ },
61086
+ PrimeFactors: {
61087
+ 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.",
61088
+ signature: "(integer) -> list<integer>",
61089
+ examples: ["PrimeFactors(360) // [2, 3, 5]"],
61090
+ evaluate: ([n], { engine: ce }) => {
61091
+ const k = toBigint(n);
61092
+ if (k === null) return void 0;
61093
+ const m = k < 0n ? -k : k;
61094
+ if (m === 0n) return void 0;
61095
+ const primes = [...bigPrimeFactors(m).keys()].filter((p) => p !== 1n).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
61096
+ return ce.function(
61097
+ "List",
61098
+ primes.map((p) => ce.number(p))
61099
+ );
61100
+ }
61101
+ },
61102
+ PrimeNu: {
61103
+ description: "Return \u03C9(n), the number of distinct prime factors of `n`. The sign of `n` is ignored; `PrimeNu(1)` is 0.",
61104
+ signature: "(integer) -> integer",
61105
+ type: () => "finite_integer",
61106
+ examples: ["PrimeNu(360) // 3"],
61107
+ evaluate: ([n], { engine: ce }) => {
61108
+ const k = toBigint(n);
61109
+ if (k === null) return void 0;
61110
+ const m = k < 0n ? -k : k;
61111
+ if (m === 0n) return void 0;
61112
+ if (m === 1n) return ce.number(0);
61113
+ return ce.number(bigPrimeFactors(m).size);
61114
+ }
61115
+ },
61116
+ PrimeOmega: {
61117
+ description: "Return \u03A9(n), the number of prime factors of `n` counted with multiplicity. The sign of `n` is ignored; `PrimeOmega(1)` is 0.",
61118
+ signature: "(integer) -> integer",
61119
+ type: () => "finite_integer",
61120
+ examples: ["PrimeOmega(360) // 6"],
61121
+ evaluate: ([n], { engine: ce }) => {
61122
+ const k = toBigint(n);
61123
+ if (k === null) return void 0;
61124
+ const m = k < 0n ? -k : k;
61125
+ if (m === 0n) return void 0;
61126
+ if (m === 1n) return ce.number(0);
61127
+ let total = 0;
61128
+ for (const e of bigPrimeFactors(m).values()) total += e;
61129
+ return ce.number(total);
61130
+ }
61131
+ },
61132
+ MoebiusMu: {
61133
+ 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.",
61134
+ signature: "(integer) -> integer",
61135
+ type: () => "finite_integer",
61136
+ examples: ["MoebiusMu(30) // -1"],
61137
+ evaluate: ([n], { engine: ce }) => {
61138
+ const k = toBigint(n);
61139
+ if (k === null) return void 0;
61140
+ const m = k < 0n ? -k : k;
61141
+ if (m === 0n) return void 0;
61142
+ if (m === 1n) return ce.number(1);
61143
+ const factors = bigPrimeFactors(m);
61144
+ for (const e of factors.values()) if (e > 1) return ce.number(0);
61145
+ return ce.number(factors.size % 2 === 0 ? 1 : -1);
61146
+ }
61147
+ },
61148
+ IsSquareFree: {
61149
+ description: 'Return `"True"` if `n` is square-free (not divisible by any perfect square > 1). The sign of `n` is ignored.',
61150
+ signature: "(integer) -> boolean",
61151
+ examples: ['IsSquareFree(30) // "True"'],
61152
+ evaluate: ([n], { engine: ce }) => {
61153
+ const k = toBigint(n);
61154
+ if (k === null) return void 0;
61155
+ const m = k < 0n ? -k : k;
61156
+ if (m === 0n) return ce.False;
61157
+ if (m === 1n) return ce.True;
61158
+ const factors = bigPrimeFactors(m);
61159
+ for (const e of factors.values()) if (e > 1) return ce.False;
61160
+ return ce.True;
61161
+ }
61162
+ },
61163
+ Radical: {
61164
+ 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.",
61165
+ signature: "(integer) -> integer",
61166
+ type: () => "finite_integer",
61167
+ examples: ["Radical(360) // 30"],
61168
+ evaluate: ([n], { engine: ce }) => {
61169
+ const k = toBigint(n);
61170
+ if (k === null) return void 0;
61171
+ const m = k < 0n ? -k : k;
61172
+ if (m === 0n) return void 0;
61173
+ if (m === 1n) return ce.number(1);
61174
+ let product = 1n;
61175
+ for (const p of bigPrimeFactors(m).keys()) product *= p;
61176
+ return ce.number(product);
61177
+ }
61178
+ },
61179
+ PowerMod: {
61180
+ 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).",
61181
+ signature: "(integer, integer, integer) -> integer",
61182
+ type: () => "finite_integer",
61183
+ examples: ["PowerMod(2, 10, 1000) // 24"],
61184
+ evaluate: ([aOp, bOp, mOp], { engine: ce }) => {
61185
+ const a = toBigint(aOp);
61186
+ const b = toBigint(bOp);
61187
+ const m = toBigint(mOp);
61188
+ if (a === null || b === null || m === null) return void 0;
61189
+ if (m <= 0n) return void 0;
61190
+ if (m === 1n) return ce.number(0);
61191
+ if (b >= 0n) return ce.number(modPow(a, b, m));
61192
+ const base = (a % m + m) % m;
61193
+ const [g, s] = extGcd(base, m);
61194
+ if (g !== 1n) return void 0;
61195
+ const inv = (s % m + m) % m;
61196
+ return ce.number(modPow(inv, -b, m));
61197
+ }
61198
+ },
61199
+ ExtendedGCD: {
61200
+ 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).",
61201
+ signature: "(integer, integer) -> tuple<integer, integer, integer>",
61202
+ examples: ["ExtendedGCD(12, 18) // (6, -1, 1)"],
61203
+ evaluate: ([aOp, bOp], { engine: ce }) => {
61204
+ const a = toBigint(aOp);
61205
+ const b = toBigint(bOp);
61206
+ if (a === null || b === null) return void 0;
61207
+ let [g, x, y] = extGcd(a, b);
61208
+ if (g < 0n) {
61209
+ g = -g;
61210
+ x = -x;
61211
+ y = -y;
61212
+ }
61213
+ return ce._fn("Tuple", [ce.number(g), ce.number(x), ce.number(y)]);
61214
+ }
61215
+ },
61216
+ IntegerSqrt: {
61217
+ description: "Return the integer square root of `n`, i.e. the largest integer `m` such that `m\xB2 \u2264 n`. Undefined for negative `n`.",
61218
+ signature: "(integer) -> integer",
61219
+ type: () => "finite_integer",
61220
+ examples: ["IntegerSqrt(17) // 4"],
61221
+ evaluate: ([n], { engine: ce }) => {
61222
+ const k = toBigint(n);
61223
+ if (k === null || k < 0n) return void 0;
61224
+ return ce.number(bigintSqrt2(k));
61225
+ }
61226
+ },
61227
+ ChineseRemainder: {
61228
+ 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.",
61229
+ signature: "(collection, collection) -> integer",
61230
+ examples: ["ChineseRemainder([2, 3, 2], [3, 5, 7]) // 23"],
61231
+ evaluate: ([residuesOp, moduliOp], { engine: ce }) => {
61232
+ const residues = Array.from(residuesOp?.each() ?? []).map(toBigint);
61233
+ const moduli = Array.from(moduliOp?.each() ?? []).map(toBigint);
61234
+ if (residues.length === 0 || residues.length !== moduli.length)
61235
+ return void 0;
61236
+ if (residues.includes(null) || moduli.includes(null)) return void 0;
61237
+ const x = chineseRemainder(residues, moduli);
61238
+ if (x === null) return void 0;
61239
+ return ce.number(x);
61240
+ }
61241
+ },
61242
+ CarmichaelLambda: {
61243
+ 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`.",
61244
+ signature: "(integer) -> integer",
61245
+ type: () => "finite_integer",
61246
+ examples: ["CarmichaelLambda(15) // 4"],
61247
+ evaluate: ([n], { engine: ce }) => {
61248
+ const k = toBigint(n);
61249
+ if (k === null || k < 1n) return void 0;
61250
+ return ce.number(carmichaelLambda(k));
61251
+ }
61252
+ },
61253
+ LucasL: {
61254
+ 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)`.",
61255
+ signature: "(integer) -> integer",
61256
+ type: () => "finite_integer",
61257
+ examples: ["LucasL(10) // 123"],
61258
+ evaluate: ([n], { engine: ce }) => {
61259
+ const k = toBigint(n);
61260
+ if (k === null) return void 0;
61261
+ const neg2 = k < 0n;
61262
+ const kk = neg2 ? -k : k;
61263
+ let a = 2n;
61264
+ let b = 1n;
61265
+ let steps = 0;
61266
+ for (let i = 0n; i < kk; i++) {
61267
+ if ((++steps & 4095) === 0) checkDeadline(ce._deadline);
61268
+ [a, b] = [b, a + b];
61269
+ }
61270
+ return ce.number(neg2 && kk % 2n === 1n ? -a : a);
61271
+ }
61272
+ },
61273
+ CatalanNumber: {
61274
+ 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`.",
61275
+ signature: "(integer) -> integer",
61276
+ type: () => "finite_integer",
61277
+ examples: ["CatalanNumber(5) // 42"],
61278
+ evaluate: ([n], { engine: ce }) => {
61279
+ const k = toBigint(n);
61280
+ if (k === null || k < 0n) return void 0;
61281
+ let c = 1n;
61282
+ let steps = 0;
61283
+ for (let i = 0n; i < k; i++) {
61284
+ if ((++steps & 4095) === 0) checkDeadline(ce._deadline);
61285
+ c = c * 2n * (2n * i + 1n) / (i + 2n);
61286
+ }
61287
+ return ce.number(c);
61288
+ }
61289
+ },
61290
+ IsPerfectPower: {
61291
+ 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.',
61292
+ signature: "(integer) -> boolean",
61293
+ examples: ['IsPerfectPower(64) // "True"'],
61294
+ evaluate: ([n], { engine: ce }) => {
61295
+ const k = toBigint(n);
61296
+ if (k === null) return void 0;
61297
+ const m = k < 0n ? -k : k;
61298
+ if (m < 4n) return ce.False;
61299
+ return ce.symbol(
61300
+ isPerfectPowerBigint(m, k < 0n, ce._deadline) ? "True" : "False"
61301
+ );
61302
+ }
61303
+ },
61304
+ ContinuedFraction: {
61305
+ 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).",
61306
+ signature: "(number, integer?) -> list<integer>",
61307
+ examples: ["ContinuedFraction(43/19) // [2, 3, 1, 4]"],
61308
+ evaluate: ([xOp, nOp], { engine: ce }) => {
61309
+ if (xOp === void 0) return void 0;
61310
+ const maxTerms = nOp === void 0 ? void 0 : Number(toBigint(nOp) ?? 0n);
61311
+ if (maxTerms !== void 0 && maxTerms < 1) return void 0;
61312
+ const terms = [];
61313
+ if (xOp.isRational) {
61314
+ let a = toBigint(xOp.numerator);
61315
+ let b = toBigint(xOp.denominator);
61316
+ if (a === null || b === null || b === 0n) return void 0;
61317
+ if (b < 0n) {
61318
+ a = -a;
61319
+ b = -b;
61320
+ }
61321
+ while (b !== 0n) {
61322
+ let q = a / b;
61323
+ if (a % b !== 0n && a < 0n !== b < 0n) q -= 1n;
61324
+ terms.push(q);
61325
+ [a, b] = [b, a - q * b];
61326
+ if (maxTerms !== void 0 && terms.length >= maxTerms) break;
61327
+ }
61328
+ } else {
61329
+ let val = xOp.re;
61330
+ if (!Number.isFinite(val)) return void 0;
61331
+ const cap = maxTerms ?? 20;
61332
+ for (let i = 0; i < cap; i++) {
61333
+ const fl = Math.floor(val);
61334
+ terms.push(BigInt(fl));
61335
+ const frac = val - fl;
61336
+ if (frac < 1e-12) break;
61337
+ val = 1 / frac;
61338
+ if (!Number.isFinite(val)) break;
61339
+ }
61340
+ }
61341
+ return ce.function(
61342
+ "List",
61343
+ terms.map((t) => ce.number(t))
61344
+ );
61345
+ }
61346
+ },
61347
+ FromContinuedFraction: {
61348
+ description: "Reconstruct the (rational) value of a continued fraction given its list of integer terms `[a0, a1, \u2026]`.",
61349
+ signature: "(collection) -> number",
61350
+ examples: ["FromContinuedFraction([2, 3, 1, 4]) // 43/19"],
61351
+ evaluate: ([listOp], { engine: ce }) => {
61352
+ const terms = Array.from(listOp?.each() ?? []).map(toBigint);
61353
+ if (terms.length === 0 || terms.includes(null)) return void 0;
61354
+ let p = 1n;
61355
+ let q = 0n;
61356
+ for (let i = terms.length - 1; i >= 0; i--)
61357
+ [p, q] = [terms[i] * p + q, p];
61358
+ if (q === 0n) return void 0;
61359
+ return ce.number(p).div(ce.number(q));
61360
+ }
61361
+ },
61362
+ IntegerDigits: {
61363
+ 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.",
61364
+ signature: "(integer, integer?, integer?) -> list<integer>",
61365
+ examples: ["IntegerDigits(255, 16) // [15, 15]"],
61366
+ evaluate: ([nOp, baseOp, lenOp], { engine: ce }) => {
61367
+ const k = toBigint(nOp);
61368
+ if (k === null) return void 0;
61369
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61370
+ if (base === null || base < 2n) return void 0;
61371
+ let m = k < 0n ? -k : k;
61372
+ const digits = [];
61373
+ if (m === 0n) digits.push(0n);
61374
+ while (m > 0n) {
61375
+ digits.push(m % base);
61376
+ m = m / base;
61377
+ }
61378
+ digits.reverse();
61379
+ if (lenOp !== void 0) {
61380
+ const len = toBigint(lenOp);
61381
+ if (len === null || len < 0n) return void 0;
61382
+ const L = Number(len);
61383
+ while (digits.length < L) digits.unshift(0n);
61384
+ if (digits.length > L) digits.splice(0, digits.length - L);
61385
+ }
61386
+ return ce.function(
61387
+ "List",
61388
+ digits.map((d) => ce.number(d))
61389
+ );
61390
+ }
61391
+ },
61392
+ DigitCount: {
61393
+ 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]`.",
61394
+ signature: "(integer, integer?, integer?) -> integer | list<integer>",
61395
+ type: ([, , digit]) => digit !== void 0 ? "finite_integer" : "list",
61396
+ examples: ["DigitCount(122, 10, 2) // 2"],
61397
+ evaluate: ([nOp, baseOp, digitOp], { engine: ce }) => {
61398
+ const k = toBigint(nOp);
61399
+ if (k === null) return void 0;
61400
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61401
+ if (base === null || base < 2n) return void 0;
61402
+ const counts = /* @__PURE__ */ new Map();
61403
+ let m = k < 0n ? -k : k;
61404
+ if (m === 0n) counts.set(0n, 1);
61405
+ while (m > 0n) {
61406
+ const d = m % base;
61407
+ counts.set(d, (counts.get(d) ?? 0) + 1);
61408
+ m = m / base;
61409
+ }
61410
+ if (digitOp !== void 0) {
61411
+ const d = toBigint(digitOp);
61412
+ if (d === null || d < 0n || d >= base) return void 0;
61413
+ return ce.number(counts.get(d) ?? 0);
61414
+ }
61415
+ const list = [];
61416
+ for (let d = 1n; d < base; d++)
61417
+ list.push(ce.number(counts.get(d) ?? 0));
61418
+ list.push(ce.number(counts.get(0n) ?? 0));
61419
+ return ce.function("List", list);
61420
+ }
61421
+ },
61422
+ RandomPrime: {
61423
+ 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.",
61424
+ pure: false,
61425
+ signature: "(integer, integer?) -> integer",
61426
+ type: () => "finite_integer",
61427
+ examples: ["RandomPrime(100) // e.g. 47"],
61428
+ evaluate: ([aOp, bOp], { engine: ce }) => {
61429
+ let lo;
61430
+ let hi;
61431
+ if (bOp === void 0) {
61432
+ lo = 2n;
61433
+ hi = toBigint(aOp);
61434
+ } else {
61435
+ lo = toBigint(aOp);
61436
+ hi = toBigint(bOp);
61437
+ }
61438
+ if (lo === null || hi === null) return void 0;
61439
+ if (lo < 2n) lo = 2n;
61440
+ if (hi < lo) return void 0;
61441
+ const range2 = hi - lo + 1n;
61442
+ const attempts = 100 + 20 * hi.toString().length;
61443
+ for (let i = 0; i < attempts; i++) {
61444
+ const r = lo + randomBigintBelow(range2);
61445
+ if (isPrimeBigint(r)) return ce.number(r);
61446
+ }
61447
+ for (let p = lo; p <= hi; p++) {
61448
+ checkDeadline(ce._deadline);
61449
+ if (isPrimeBigint(p)) return ce.number(p);
61450
+ }
61451
+ return void 0;
61452
+ }
61453
+ },
61454
+ PrimePi: {
61455
+ description: "Return \u03C0(n), the prime-counting function: the number of primes less than or equal to `n`.",
61456
+ signature: "(real) -> integer",
61457
+ type: () => "finite_integer",
61458
+ examples: ["PrimePi(10) // 4"],
61459
+ evaluate: ([n], { engine: ce }) => {
61460
+ const x = n?.re;
61461
+ if (x === void 0 || !Number.isFinite(x)) return void 0;
61462
+ const bound = BigInt(Math.floor(x));
61463
+ if (bound < 2n) return ce.number(0);
61464
+ let count = 1;
61465
+ let steps = 0;
61466
+ for (let k = 3n; k <= bound; k += 2n) {
61467
+ if ((++steps & 1023) === 0) checkDeadline(ce._deadline);
61468
+ if (isPrimeBigint(k)) count++;
61469
+ }
61470
+ return ce.number(count);
61471
+ }
61472
+ },
61473
+ BernoulliB: {
61474
+ description: "Return the nth Bernoulli number B\u2099 as an exact rational, using the convention B\u2081 = -1/2. Odd `n > 1` give 0.",
61475
+ signature: "(integer) -> finite_rational",
61476
+ type: () => "finite_rational",
61477
+ examples: ["BernoulliB(2) // 1/6"],
61478
+ evaluate: ([n], { engine: ce }) => {
61479
+ const k = toBigint(n);
61480
+ if (k === null || k < 0n) return void 0;
61481
+ if (k === 0n) return ce.number(1);
61482
+ if (k === 1n) return ce.number(-1).div(ce.number(2));
61483
+ if (k % 2n === 1n) return ce.number(0);
61484
+ const [num, den] = bernoulliNumber(Number(k), ce._deadline);
61485
+ return den === 1n ? ce.number(num) : ce.number(num).div(ce.number(den));
61486
+ }
61487
+ },
61488
+ FromDigits: {
61489
+ 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).",
61490
+ signature: "(collection, integer?) -> integer",
61491
+ type: () => "finite_integer",
61492
+ examples: ["FromDigits([1, 2, 3, 4]) // 1234"],
61493
+ evaluate: ([digitsOp, baseOp], { engine: ce }) => {
61494
+ const digits = Array.from(digitsOp?.each() ?? []).map(toBigint);
61495
+ if (digits.length === 0 || digits.includes(null)) return void 0;
61496
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61497
+ if (base === null || base < 2n) return void 0;
61498
+ let result = 0n;
61499
+ for (const d of digits) result = result * base + d;
61500
+ return ce.number(result);
61501
+ }
61502
+ },
61503
+ DigitSum: {
61504
+ description: "Return the sum of the digits of `n` in the given `base` (default 10). The sign of `n` is ignored.",
61505
+ signature: "(integer, integer?) -> integer",
61506
+ type: () => "finite_integer",
61507
+ examples: ["DigitSum(1234) // 10"],
61508
+ evaluate: ([nOp, baseOp], { engine: ce }) => {
61509
+ const k = toBigint(nOp);
61510
+ if (k === null) return void 0;
61511
+ const base = baseOp === void 0 ? 10n : toBigint(baseOp);
61512
+ if (base === null || base < 2n) return void 0;
61513
+ let m = k < 0n ? -k : k;
61514
+ let sum = 0n;
61515
+ while (m > 0n) {
61516
+ sum += m % base;
61517
+ m /= base;
61518
+ }
61519
+ return ce.number(sum);
61520
+ }
61521
+ },
61522
+ DivisorSigma: {
61523
+ 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`.",
61524
+ signature: "(integer, integer) -> integer",
61525
+ type: () => "finite_integer",
61526
+ examples: ["DivisorSigma(2, 6) // 50"],
61527
+ evaluate: ([kOp, nOp], { engine: ce }) => {
61528
+ const k = toBigint(kOp);
61529
+ const n = toBigint(nOp);
61530
+ if (k === null || n === null || k < 0n || n < 1n) return void 0;
61531
+ if (n === 1n) return ce.number(1);
61532
+ let result = 1n;
61533
+ for (const [p, e] of bigPrimeFactors(n)) {
61534
+ if (k === 0n) result *= BigInt(e + 1);
61535
+ else {
61536
+ const pk = p ** k;
61537
+ result *= (pk ** BigInt(e + 1) - 1n) / (pk - 1n);
61538
+ }
61539
+ }
61540
+ return ce.number(result);
61541
+ }
61542
+ },
61543
+ JacobiSymbol: {
61544
+ description: "The Jacobi symbol (a/n) for an odd `n > 0`. Returns -1, 0, or 1. Undefined when `n` is even or non-positive.",
61545
+ signature: "(integer, integer) -> integer",
61546
+ type: () => "finite_integer",
61547
+ examples: ["JacobiSymbol(5, 21) // 1"],
61548
+ evaluate: ([aOp, nOp], { engine: ce }) => {
61549
+ const a = toBigint(aOp);
61550
+ const n = toBigint(nOp);
61551
+ if (a === null || n === null) return void 0;
61552
+ if (n <= 0n || n % 2n === 0n) return void 0;
61553
+ return ce.number(jacobiSymbol(a, n));
61554
+ }
61555
+ },
61556
+ LegendreSymbol: {
61557
+ description: "The Legendre symbol (a/p) for an odd prime `p`. Returns -1, 0, or 1. Undefined when `p` is not an odd prime.",
61558
+ signature: "(integer, integer) -> integer",
61559
+ type: () => "finite_integer",
61560
+ examples: ["LegendreSymbol(3, 7) // -1"],
61561
+ evaluate: ([aOp, pOp], { engine: ce }) => {
61562
+ const a = toBigint(aOp);
61563
+ const p = toBigint(pOp);
61564
+ if (a === null || p === null) return void 0;
61565
+ if (p <= 2n || p % 2n === 0n || !isPrimeBigint(p)) return void 0;
61566
+ return ce.number(jacobiSymbol(a, p));
61567
+ }
61568
+ },
61569
+ MultiplicativeOrder: {
61570
+ 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.",
61571
+ signature: "(integer, integer) -> integer",
61572
+ type: () => "finite_integer",
61573
+ examples: ["MultiplicativeOrder(2, 7) // 3"],
61574
+ evaluate: ([aOp, nOp], { engine: ce }) => {
61575
+ const a0 = toBigint(aOp);
61576
+ const n = toBigint(nOp);
61577
+ if (a0 === null || n === null || n < 1n) return void 0;
61578
+ if (n === 1n) return ce.number(1);
61579
+ const a = (a0 % n + n) % n;
61580
+ if (gcd2(a, n) !== 1n) return void 0;
61581
+ for (const d of divisorsAscending(carmichaelLambda(n), ce._deadline)) {
61582
+ checkDeadline(ce._deadline);
61583
+ if (modPow(a, d, n) === 1n) return ce.number(d);
61584
+ }
61585
+ return void 0;
61586
+ }
61587
+ },
61588
+ PrimitiveRoot: {
61589
+ 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).",
61590
+ signature: "(integer) -> integer",
61591
+ type: () => "finite_integer",
61592
+ examples: ["PrimitiveRoot(7) // 3"],
61593
+ evaluate: ([nOp], { engine: ce }) => {
61594
+ const n = toBigint(nOp);
61595
+ if (n === null || n < 1n) return void 0;
61596
+ if (n === 1n) return ce.number(0);
61597
+ if (n === 2n) return ce.number(1);
61598
+ if (n === 4n) return ce.number(3);
61599
+ if (!hasPrimitiveRoot(n)) return void 0;
61600
+ const phi = eulerPhi(n);
61601
+ const phiFactors = [...bigPrimeFactors(phi).keys()];
61602
+ for (let a = 2n; a < n; a++) {
61603
+ checkDeadline(ce._deadline);
61604
+ if (gcd2(a, n) !== 1n) continue;
61605
+ if (phiFactors.every((q) => modPow(a, phi / q, n) !== 1n))
61606
+ return ce.number(a);
61607
+ }
61608
+ return void 0;
61609
+ }
61610
+ },
61611
+ PrimeNumber: {
61612
+ description: "The nth prime number. `PrimeNumber` is an alias for `NthPrime`, which is the preferred name.",
61613
+ signature: "(integer) -> integer",
61614
+ canonical: ([n], { engine }) => engine._fn("NthPrime", [n])
61615
+ },
60784
61616
  Totient: {
60785
61617
  wikidata: "Q190026",
60786
61618
  description: "Euler's totient function \u03C6(n): count of positive integers \u2264 n that are coprime to n.",
@@ -61017,6 +61849,165 @@ ${e instanceof Error ? e.message : e}
61017
61849
  }
61018
61850
  }
61019
61851
  ];
61852
+ function extGcd(a, b) {
61853
+ let [oldR, r] = [a, b];
61854
+ let [oldS, s] = [1n, 0n];
61855
+ let [oldT, t] = [0n, 1n];
61856
+ while (r !== 0n) {
61857
+ const q = oldR / r;
61858
+ [oldR, r] = [r, oldR - q * r];
61859
+ [oldS, s] = [s, oldS - q * s];
61860
+ [oldT, t] = [t, oldT - q * t];
61861
+ }
61862
+ return [oldR, oldS, oldT];
61863
+ }
61864
+ function bigintSqrt2(n) {
61865
+ if (n < 2n) return n;
61866
+ let x = 1n << (BigInt(n.toString(2).length) + 1n) / 2n;
61867
+ for (; ; ) {
61868
+ const y = x + n / x >> 1n;
61869
+ if (y >= x) break;
61870
+ x = y;
61871
+ }
61872
+ while (x * x > n) x -= 1n;
61873
+ return x;
61874
+ }
61875
+ function chineseRemainder(residues, moduli) {
61876
+ let x = 0n;
61877
+ let m = 1n;
61878
+ for (let i = 0; i < residues.length; i++) {
61879
+ const ni = moduli[i];
61880
+ if (ni <= 0n) return null;
61881
+ const ri = (residues[i] % ni + ni) % ni;
61882
+ const [g, p] = extGcd(m, ni);
61883
+ if ((ri - x) % g !== 0n) return null;
61884
+ const lcmMN = m / g * ni;
61885
+ const mod22 = ni / g;
61886
+ const lambda = ((ri - x) / g * p % mod22 + mod22) % mod22;
61887
+ x = ((x + m * lambda) % lcmMN + lcmMN) % lcmMN;
61888
+ m = lcmMN;
61889
+ }
61890
+ return x;
61891
+ }
61892
+ function iroot(n, b) {
61893
+ if (n < 2n) return n;
61894
+ const bb = BigInt(b);
61895
+ const approx = Math.pow(Number(n), 1 / b);
61896
+ let x = Number.isFinite(approx) ? BigInt(Math.round(approx)) : 1n << BigInt(n.toString(2).length) / bb + 1n;
61897
+ if (x < 1n) x = 1n;
61898
+ while (x ** bb > n) x -= 1n;
61899
+ while ((x + 1n) ** bb <= n) x += 1n;
61900
+ return x;
61901
+ }
61902
+ function isPerfectPowerBigint(m, oddOnly, deadline) {
61903
+ const bits = m.toString(2).length;
61904
+ for (let b = oddOnly ? 3 : 2; b <= bits; b++) {
61905
+ if (oddOnly && b % 2 === 0) continue;
61906
+ checkDeadline(deadline);
61907
+ const r = iroot(m, b);
61908
+ if (r >= 2n && r ** BigInt(b) === m) return true;
61909
+ }
61910
+ return false;
61911
+ }
61912
+ function randomBigintBelow(n) {
61913
+ if (n <= 1n) return 0n;
61914
+ if (n <= BigInt(Number.MAX_SAFE_INTEGER))
61915
+ return BigInt(Math.floor(Math.random() * Number(n)));
61916
+ const bits = n.toString(2).length;
61917
+ let r;
61918
+ do {
61919
+ r = 0n;
61920
+ for (let i = 0; i < bits; i += 30)
61921
+ r = r << 30n | BigInt(Math.floor(Math.random() * (1 << 30)));
61922
+ r &= (1n << BigInt(bits)) - 1n;
61923
+ } while (r >= n);
61924
+ return r;
61925
+ }
61926
+ function divisorsAscending(m, deadline) {
61927
+ const small = [];
61928
+ const large = [];
61929
+ let steps = 0;
61930
+ for (let i = 1n; i * i <= m; i++) {
61931
+ if ((++steps & 4095) === 0) checkDeadline(deadline);
61932
+ if (m % i === 0n) {
61933
+ small.push(i);
61934
+ const j = m / i;
61935
+ if (j !== i) large.push(j);
61936
+ }
61937
+ }
61938
+ large.reverse();
61939
+ return [...small, ...large];
61940
+ }
61941
+ function eulerPhi(n) {
61942
+ if (n <= 1n) return 1n;
61943
+ let result = n;
61944
+ for (const p of bigPrimeFactors(n).keys()) result = result / p * (p - 1n);
61945
+ return result;
61946
+ }
61947
+ function carmichaelLambda(n) {
61948
+ if (n <= 1n) return 1n;
61949
+ let result = 1n;
61950
+ for (const [p, e] of bigPrimeFactors(n)) {
61951
+ const lambda = p === 2n ? e === 1 ? 1n : e === 2 ? 2n : 1n << BigInt(e - 2) : p ** BigInt(e - 1) * (p - 1n);
61952
+ result = lcm2(result, lambda);
61953
+ }
61954
+ return result;
61955
+ }
61956
+ function jacobiSymbol(a, n) {
61957
+ a = (a % n + n) % n;
61958
+ let result = 1;
61959
+ while (a !== 0n) {
61960
+ while (a % 2n === 0n) {
61961
+ a /= 2n;
61962
+ const r = n % 8n;
61963
+ if (r === 3n || r === 5n) result = -result;
61964
+ }
61965
+ [a, n] = [n, a];
61966
+ if (a % 4n === 3n && n % 4n === 3n) result = -result;
61967
+ a %= n;
61968
+ }
61969
+ return n === 1n ? result : 0;
61970
+ }
61971
+ function hasPrimitiveRoot(n) {
61972
+ if (n === 1n || n === 2n || n === 4n) return true;
61973
+ let m = n;
61974
+ let twos = 0;
61975
+ while (m % 2n === 0n) {
61976
+ m /= 2n;
61977
+ twos++;
61978
+ }
61979
+ if (twos > 1) return false;
61980
+ if (m === 1n) return false;
61981
+ return bigPrimeFactors(m).size === 1;
61982
+ }
61983
+ function reduceRat(num, den) {
61984
+ if (den < 0n) {
61985
+ num = -num;
61986
+ den = -den;
61987
+ }
61988
+ const g = gcd2(num < 0n ? -num : num, den);
61989
+ return g > 1n ? [num / g, den / g] : [num, den];
61990
+ }
61991
+ function bernoulliNumber(n, deadline) {
61992
+ const B = [[1n, 1n]];
61993
+ for (let m = 1; m <= n; m++) {
61994
+ checkDeadline(deadline);
61995
+ let sNum = 0n;
61996
+ let sDen = 1n;
61997
+ let c = 1n;
61998
+ for (let k = 0; k < m; k++) {
61999
+ const tNum = c * B[k][0];
62000
+ const tDen = B[k][1];
62001
+ const g = gcd2(sDen, tDen);
62002
+ sNum = sNum * (tDen / g) + tNum * (sDen / g);
62003
+ sDen = sDen / g * tDen;
62004
+ [sNum, sDen] = reduceRat(sNum, sDen);
62005
+ c = c * BigInt(m + 1 - k) / BigInt(k + 1);
62006
+ }
62007
+ B.push(reduceRat(-sNum, sDen * BigInt(m + 1)));
62008
+ }
62009
+ return B[n];
62010
+ }
61020
62011
  function sumSquareDigits(k) {
61021
62012
  return k.toString().split("").map((d) => BigInt(d)).reduce((sum, d) => sum + d * d, 0n);
61022
62013
  }
@@ -84392,14 +85383,14 @@ ${code}`;
84392
85383
  _setDefaultEngineFactory(() => new ComputeEngine());
84393
85384
 
84394
85385
  // src/compute-engine.ts
84395
- var version = "0.63.0";
85386
+ var version = "0.64.0";
84396
85387
  ComputeEngine._latexSyntaxFactory = () => new LatexSyntax();
84397
85388
  _setDefaultEngineFactory(
84398
85389
  () => new ComputeEngine({ latexSyntax: new LatexSyntax() })
84399
85390
  );
84400
85391
  globalThis[/* @__PURE__ */ Symbol.for("io.cortexjs.compute-engine")] = {
84401
85392
  ComputeEngine: ComputeEngine.prototype.constructor,
84402
- version: "0.63.0"
85393
+ version: "0.64.0"
84403
85394
  };
84404
85395
  return __toCommonJS(compute_engine_exports);
84405
85396
  })();