nerdamer 1.1.13 → 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/LICENSE.md +184 -0
  2. package/README.md +293 -312
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +7 -0
  5. package/dist/parser.js +2 -0
  6. package/dist/parser.js.LICENSE.txt +7 -0
  7. package/docs-data/parser-functions.json +1960 -0
  8. package/index.d.ts +10 -426
  9. package/output/algebra/adapters.d.ts +33 -0
  10. package/output/algebra/adapters.js +109 -0
  11. package/output/algebra/algorithms/arith.d.ts +84 -0
  12. package/output/algebra/algorithms/arith.js +323 -0
  13. package/output/algebra/algorithms/factor.d.ts +3 -0
  14. package/output/algebra/algorithms/factor.js +5 -0
  15. package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
  16. package/output/algebra/algorithms/factorMultivariate.js +2393 -0
  17. package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
  18. package/output/algebra/algorithms/factorUnivariate.js +1072 -0
  19. package/output/algebra/algorithms/gcd.d.ts +22 -0
  20. package/output/algebra/algorithms/gcd.js +690 -0
  21. package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
  22. package/output/algebra/algorithms/groebnerBase.js +1166 -0
  23. package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
  24. package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
  25. package/output/algebra/algorithms/poly.d.ts +228 -0
  26. package/output/algebra/algorithms/poly.js +1299 -0
  27. package/output/algebra/algorithms/rational.d.ts +17 -0
  28. package/output/algebra/algorithms/rational.js +115 -0
  29. package/output/algebra/factor/factor.d.ts +62 -0
  30. package/output/algebra/factor/factor.js +158 -0
  31. package/output/algebra/gcd/gcd.d.ts +29 -0
  32. package/output/algebra/gcd/gcd.js +141 -0
  33. package/output/algebra/groebner.d.ts +21 -0
  34. package/output/algebra/groebner.js +42 -0
  35. package/output/algebra/partfrac.d.ts +19 -0
  36. package/output/algebra/partfrac.js +398 -0
  37. package/output/algebra/polynomialize.d.ts +20 -0
  38. package/output/algebra/polynomialize.js +24 -0
  39. package/output/algebra/simplify/complexsimp.d.ts +7 -0
  40. package/output/algebra/simplify/complexsimp.js +24 -0
  41. package/output/algebra/simplify/factorCommon.d.ts +13 -0
  42. package/output/algebra/simplify/factorCommon.js +136 -0
  43. package/output/algebra/simplify/funcsimp.d.ts +26 -0
  44. package/output/algebra/simplify/funcsimp.js +633 -0
  45. package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
  46. package/output/algebra/simplify/invtrigrewrite.js +96 -0
  47. package/output/algebra/simplify/ratsimp.d.ts +21 -0
  48. package/output/algebra/simplify/ratsimp.js +140 -0
  49. package/output/algebra/simplify/simplify.d.ts +25 -0
  50. package/output/algebra/simplify/simplify.js +228 -0
  51. package/output/algebra/simplify/trigreduce.d.ts +38 -0
  52. package/output/algebra/simplify/trigreduce.js +424 -0
  53. package/output/algebra/simplify/trigrewrite.d.ts +17 -0
  54. package/output/algebra/simplify/trigrewrite.js +156 -0
  55. package/output/algebra/simplify/trigsimp.d.ts +11 -0
  56. package/output/algebra/simplify/trigsimp.js +369 -0
  57. package/output/algebra/simplify/utils.d.ts +32 -0
  58. package/output/algebra/simplify/utils.js +56 -0
  59. package/output/algebra/utils.d.ts +32 -0
  60. package/output/algebra/utils.js +48 -0
  61. package/output/api/advanced.d.ts +7 -0
  62. package/output/api/advanced.js +18 -0
  63. package/output/api/algebra.d.ts +17 -0
  64. package/output/api/algebra.js +32 -0
  65. package/output/api/assumptions.d.ts +4 -0
  66. package/output/api/assumptions.js +11 -0
  67. package/output/api/calculus.d.ts +9 -0
  68. package/output/api/calculus.js +21 -0
  69. package/output/api/core.d.ts +17 -0
  70. package/output/api/core.js +41 -0
  71. package/output/api/debug.d.ts +16 -0
  72. package/output/api/debug.js +23 -0
  73. package/output/api/parser.d.ts +85 -0
  74. package/output/api/parser.js +16 -0
  75. package/output/api/solve.d.ts +10 -0
  76. package/output/api/solve.js +16 -0
  77. package/output/api/structures.d.ts +10 -0
  78. package/output/api/structures.js +22 -0
  79. package/output/calculus/derivative/diff.d.ts +30 -0
  80. package/output/calculus/derivative/diff.js +238 -0
  81. package/output/calculus/fresnel.d.ts +16 -0
  82. package/output/calculus/fresnel.js +39 -0
  83. package/output/calculus/integrate/byParts.d.ts +18 -0
  84. package/output/calculus/integrate/byParts.js +339 -0
  85. package/output/calculus/integrate/bySubstitution.d.ts +135 -0
  86. package/output/calculus/integrate/bySubstitution.js +411 -0
  87. package/output/calculus/integrate/integrate.d.ts +38 -0
  88. package/output/calculus/integrate/integrate.js +652 -0
  89. package/output/calculus/integrate/integrationTable.d.ts +2 -0
  90. package/output/calculus/integrate/integrationTable.js +914 -0
  91. package/output/calculus/integrate/utils.d.ts +28 -0
  92. package/output/calculus/integrate/utils.js +96 -0
  93. package/output/calculus/laplace/ilaplace.d.ts +31 -0
  94. package/output/calculus/laplace/ilaplace.js +192 -0
  95. package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
  96. package/output/calculus/laplace/ilaplaceTable.js +200 -0
  97. package/output/calculus/laplace/laplace.d.ts +22 -0
  98. package/output/calculus/laplace/laplace.js +109 -0
  99. package/output/calculus/laplace/laplaceTable.d.ts +2 -0
  100. package/output/calculus/laplace/laplaceTable.js +187 -0
  101. package/output/calculus/limit/limit.d.ts +35 -0
  102. package/output/calculus/limit/limit.js +1183 -0
  103. package/output/calculus/limit/limitsTable.d.ts +2 -0
  104. package/output/calculus/limit/limitsTable.js +7 -0
  105. package/output/core/Settings.d.ts +32 -0
  106. package/output/core/Settings.js +68 -0
  107. package/output/core/adapters.d.ts +18 -0
  108. package/output/core/adapters.js +40 -0
  109. package/output/core/classes/assumption/Assumption.d.ts +218 -0
  110. package/output/core/classes/assumption/Assumption.js +605 -0
  111. package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
  112. package/output/core/classes/assumption/assertiveFunctions.js +64 -0
  113. package/output/core/classes/assumption/assume.d.ts +90 -0
  114. package/output/core/classes/assumption/assume.js +145 -0
  115. package/output/core/classes/collection/Collection.d.ts +107 -0
  116. package/output/core/classes/collection/Collection.js +231 -0
  117. package/output/core/classes/complex/Complex.d.ts +99 -0
  118. package/output/core/classes/complex/Complex.js +135 -0
  119. package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
  120. package/output/core/classes/decimalSet/DecimalSet.js +453 -0
  121. package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
  122. package/output/core/classes/dictionary/Dictionary.js +213 -0
  123. package/output/core/classes/equation/Equation.d.ts +256 -0
  124. package/output/core/classes/equation/Equation.js +350 -0
  125. package/output/core/classes/expression/CoeffObject.d.ts +100 -0
  126. package/output/core/classes/expression/CoeffObject.js +198 -0
  127. package/output/core/classes/expression/Expression.d.ts +1674 -0
  128. package/output/core/classes/expression/Expression.js +2332 -0
  129. package/output/core/classes/expression/analysis.d.ts +25 -0
  130. package/output/core/classes/expression/analysis.js +218 -0
  131. package/output/core/classes/expression/collect.d.ts +9 -0
  132. package/output/core/classes/expression/collect.js +49 -0
  133. package/output/core/classes/expression/format.d.ts +45 -0
  134. package/output/core/classes/expression/format.js +217 -0
  135. package/output/core/classes/expression/products.d.ts +23 -0
  136. package/output/core/classes/expression/products.js +115 -0
  137. package/output/core/classes/expression/shortcuts.d.ts +35 -0
  138. package/output/core/classes/expression/shortcuts.js +129 -0
  139. package/output/core/classes/expression/traversal.d.ts +31 -0
  140. package/output/core/classes/expression/traversal.js +216 -0
  141. package/output/core/classes/expression/trig.d.ts +25 -0
  142. package/output/core/classes/expression/trig.js +40 -0
  143. package/output/core/classes/expression/utils.d.ts +52 -0
  144. package/output/core/classes/expression/utils.js +189 -0
  145. package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
  146. package/output/core/classes/lookupTable/LookupTable.js +55 -0
  147. package/output/core/classes/matrix/Matrix.d.ts +227 -0
  148. package/output/core/classes/matrix/Matrix.js +889 -0
  149. package/output/core/classes/matrix/Sylvester.d.ts +11 -0
  150. package/output/core/classes/matrix/Sylvester.js +54 -0
  151. package/output/core/classes/matrix/functions.d.ts +26 -0
  152. package/output/core/classes/matrix/functions.js +52 -0
  153. package/output/core/classes/matrix/utils.d.ts +9 -0
  154. package/output/core/classes/matrix/utils.js +22 -0
  155. package/output/core/classes/parser/Parser.d.ts +480 -0
  156. package/output/core/classes/parser/Parser.js +1812 -0
  157. package/output/core/classes/parser/Token.d.ts +58 -0
  158. package/output/core/classes/parser/Token.js +137 -0
  159. package/output/core/classes/parser/constants.d.ts +160 -0
  160. package/output/core/classes/parser/constants.js +227 -0
  161. package/output/core/classes/parser/helpers.d.ts +21 -0
  162. package/output/core/classes/parser/helpers.js +42 -0
  163. package/output/core/classes/parser/operations/add.d.ts +15 -0
  164. package/output/core/classes/parser/operations/add.js +238 -0
  165. package/output/core/classes/parser/operations/comma.d.ts +7 -0
  166. package/output/core/classes/parser/operations/comma.js +11 -0
  167. package/output/core/classes/parser/operations/compare.d.ts +21 -0
  168. package/output/core/classes/parser/operations/compare.js +461 -0
  169. package/output/core/classes/parser/operations/divide.d.ts +2 -0
  170. package/output/core/classes/parser/operations/divide.js +72 -0
  171. package/output/core/classes/parser/operations/functions.d.ts +46 -0
  172. package/output/core/classes/parser/operations/functions.js +430 -0
  173. package/output/core/classes/parser/operations/multiply.d.ts +11 -0
  174. package/output/core/classes/parser/operations/multiply.js +321 -0
  175. package/output/core/classes/parser/operations/power.d.ts +48 -0
  176. package/output/core/classes/parser/operations/power.js +673 -0
  177. package/output/core/classes/parser/operations/subtract.d.ts +3 -0
  178. package/output/core/classes/parser/operations/subtract.js +35 -0
  179. package/output/core/classes/parser/preprocess.d.ts +14 -0
  180. package/output/core/classes/parser/preprocess.js +259 -0
  181. package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
  182. package/output/core/classes/parser/scripting/controlFlow.js +355 -0
  183. package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
  184. package/output/core/classes/parser/scripting/evaluate.js +112 -0
  185. package/output/core/classes/parser/scripting/functions.d.ts +14 -0
  186. package/output/core/classes/parser/scripting/functions.js +59 -0
  187. package/output/core/classes/parser/scripting/scope.d.ts +35 -0
  188. package/output/core/classes/parser/scripting/scope.js +155 -0
  189. package/output/core/classes/parser/types.d.ts +125 -0
  190. package/output/core/classes/parser/types.js +2 -0
  191. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
  192. package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
  193. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
  194. package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
  195. package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
  196. package/output/core/classes/polynomial/Polynomial.js +1149 -0
  197. package/output/core/classes/polynomial/Term.d.ts +222 -0
  198. package/output/core/classes/polynomial/Term.js +430 -0
  199. package/output/core/classes/polynomial/functions.d.ts +69 -0
  200. package/output/core/classes/polynomial/functions.js +126 -0
  201. package/output/core/classes/polynomial/utils.d.ts +62 -0
  202. package/output/core/classes/polynomial/utils.js +206 -0
  203. package/output/core/classes/rational/Rational.d.ts +504 -0
  204. package/output/core/classes/rational/Rational.js +779 -0
  205. package/output/core/classes/seq/SEQ.d.ts +13 -0
  206. package/output/core/classes/seq/SEQ.js +137 -0
  207. package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
  208. package/output/core/classes/valuesSet/ValuesSet.js +381 -0
  209. package/output/core/classes/vector/Vector.d.ts +222 -0
  210. package/output/core/classes/vector/Vector.js +497 -0
  211. package/output/core/classes/vector/functions.d.ts +28 -0
  212. package/output/core/classes/vector/functions.js +47 -0
  213. package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
  214. package/output/core/common/classes/MathematicalAggregate.js +140 -0
  215. package/output/core/common/classes/Scope.d.ts +62 -0
  216. package/output/core/common/classes/Scope.js +122 -0
  217. package/output/core/common/classes/StructuredEntity.d.ts +55 -0
  218. package/output/core/common/classes/StructuredEntity.js +151 -0
  219. package/output/core/common/common.d.ts +63 -0
  220. package/output/core/common/common.js +279 -0
  221. package/output/core/common/functions/functions.d.ts +14 -0
  222. package/output/core/common/functions/functions.js +33 -0
  223. package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
  224. package/output/core/common/functions/structuredEntityUtils.js +40 -0
  225. package/output/core/converters/BaseConverter.d.ts +97 -0
  226. package/output/core/converters/BaseConverter.js +405 -0
  227. package/output/core/converters/Converter.d.ts +111 -0
  228. package/output/core/converters/Converter.js +802 -0
  229. package/output/core/converters/Pattern.d.ts +71 -0
  230. package/output/core/converters/Pattern.js +302 -0
  231. package/output/core/dispatch.d.ts +34 -0
  232. package/output/core/dispatch.js +304 -0
  233. package/output/core/errors.d.ts +531 -0
  234. package/output/core/errors.js +621 -0
  235. package/output/core/functions/bigint/bigint.d.ts +121 -0
  236. package/output/core/functions/bigint/bigint.js +392 -0
  237. package/output/core/functions/bigint/primeFactor.d.ts +49 -0
  238. package/output/core/functions/bigint/primeFactor.js +267 -0
  239. package/output/core/functions/bigint/primes.d.ts +1 -0
  240. package/output/core/functions/bigint/primes.js +11 -0
  241. package/output/core/functions/build/definitions.d.ts +12 -0
  242. package/output/core/functions/build/definitions.js +133 -0
  243. package/output/core/functions/build/index.d.ts +32 -0
  244. package/output/core/functions/build/index.js +136 -0
  245. package/output/core/functions/complex.d.ts +90 -0
  246. package/output/core/functions/complex.js +482 -0
  247. package/output/core/functions/decimal.d.ts +24 -0
  248. package/output/core/functions/decimal.js +664 -0
  249. package/output/core/functions/expand/expand.d.ts +42 -0
  250. package/output/core/functions/expand/expand.js +376 -0
  251. package/output/core/functions/fresnelNumeric.d.ts +12 -0
  252. package/output/core/functions/fresnelNumeric.js +123 -0
  253. package/output/core/functions/numeric.d.ts +140 -0
  254. package/output/core/functions/numeric.js +790 -0
  255. package/output/core/functions/rationalNormalization.d.ts +11 -0
  256. package/output/core/functions/rationalNormalization.js +117 -0
  257. package/output/core/functions/setFunction.d.ts +19 -0
  258. package/output/core/functions/setFunction.js +75 -0
  259. package/output/core/functions/string.d.ts +26 -0
  260. package/output/core/functions/string.js +101 -0
  261. package/output/core/functions/subst.d.ts +90 -0
  262. package/output/core/functions/subst.js +498 -0
  263. package/output/core/functions/utils.d.ts +24 -0
  264. package/output/core/functions/utils.js +51 -0
  265. package/output/core/types.d.ts +48 -0
  266. package/output/core/types.js +2 -0
  267. package/output/index.d.ts +339 -0
  268. package/output/index.js +715 -0
  269. package/output/math/defint/defintDecimal.d.ts +37 -0
  270. package/output/math/defint/defintDecimal.js +320 -0
  271. package/output/math/defint/defintNative.d.ts +57 -0
  272. package/output/math/defint/defintNative.js +292 -0
  273. package/output/math/geometry.d.ts +8 -0
  274. package/output/math/geometry.js +32 -0
  275. package/output/math/math.d.ts +655 -0
  276. package/output/math/math.js +1811 -0
  277. package/output/math/trig.d.ts +518 -0
  278. package/output/math/trig.js +1444 -0
  279. package/output/math/trunc.d.ts +19 -0
  280. package/output/math/trunc.js +36 -0
  281. package/output/math/utils.d.ts +60 -0
  282. package/output/math/utils.js +180 -0
  283. package/output/solve/classes/DecimalMatrix.d.ts +17 -0
  284. package/output/solve/classes/DecimalMatrix.js +86 -0
  285. package/output/solve/classes/FunctionSolver.d.ts +135 -0
  286. package/output/solve/classes/FunctionSolver.js +433 -0
  287. package/output/solve/classes/MultivariateSolver.d.ts +84 -0
  288. package/output/solve/classes/MultivariateSolver.js +240 -0
  289. package/output/solve/classes/PolynomialSolver.d.ts +85 -0
  290. package/output/solve/classes/PolynomialSolver.js +292 -0
  291. package/output/solve/classes/SolutionSet.d.ts +153 -0
  292. package/output/solve/classes/SolutionSet.js +357 -0
  293. package/output/solve/classes/Solver.d.ts +17 -0
  294. package/output/solve/classes/Solver.js +132 -0
  295. package/output/solve/classes/SymbolicSolver.d.ts +74 -0
  296. package/output/solve/classes/SymbolicSolver.js +601 -0
  297. package/output/solve/linsolve.d.ts +51 -0
  298. package/output/solve/linsolve.js +225 -0
  299. package/output/solve/solve.d.ts +34 -0
  300. package/output/solve/solve.js +260 -0
  301. package/output/solve/solveSystem.d.ts +31 -0
  302. package/output/solve/solveSystem.js +290 -0
  303. package/output/solve/utils.d.ts +9 -0
  304. package/output/solve/utils.js +62 -0
  305. package/output/utils/array.d.ts +42 -0
  306. package/output/utils/array.js +98 -0
  307. package/output/utils/debug.d.ts +131 -0
  308. package/output/utils/debug.js +295 -0
  309. package/output/utils/decimal.d.ts +3 -0
  310. package/output/utils/decimal.js +16 -0
  311. package/output/utils/numeric.d.ts +14 -0
  312. package/output/utils/numeric.js +51 -0
  313. package/output/utils/object.d.ts +26 -0
  314. package/output/utils/object.js +56 -0
  315. package/package.json +213 -57
  316. package/.travis.yml +0 -3
  317. package/Algebra.js +0 -4568
  318. package/BREAKING_CHANGES.md +0 -5
  319. package/CODE_OF_CONDUCT.md +0 -46
  320. package/CONTRIBUTING.md +0 -14
  321. package/Calculus.js +0 -2675
  322. package/Extra.js +0 -622
  323. package/Solve.js +0 -1783
  324. package/all.js +0 -16
  325. package/all.min.js +0 -1
  326. package/gulpfile.js +0 -16
  327. package/index.html +0 -158
  328. package/license.txt +0 -19
  329. package/nerdamer.core.js +0 -12510
  330. package/spec/LaTeX.spec.js +0 -302
  331. package/spec/TeXConvert.spec.js +0 -8
  332. package/spec/algebra.spec.js +0 -287
  333. package/spec/basic_parser.spec.js +0 -134
  334. package/spec/build.spec.js +0 -131
  335. package/spec/calculus.spec.js +0 -183
  336. package/spec/core.spec.js +0 -2970
  337. package/spec/extra.spec.js +0 -54
  338. package/spec/solve.spec.js +0 -126
  339. package/spec/support/jasmine.json +0 -11
  340. package/spec/support/utils.js +0 -42
  341. package/spec/text.spec.js +0 -132
@@ -0,0 +1,664 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EULER_GAMMA = void 0;
7
+ exports.erf = erf;
8
+ exports.gamma = gamma;
9
+ exports.sinc = sinc;
10
+ exports.Si = Si;
11
+ exports.Shi = Shi;
12
+ exports.Ci = Ci;
13
+ exports.Chi = Chi;
14
+ exports.Ei = Ei;
15
+ exports.Li = Li;
16
+ const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const bigint_1 = require("./bigint/bigint");
18
+ /*
19
+ * TODO: Currently only up to a 100 digits. This will need to be calculated in the future.
20
+ */
21
+ exports.EULER_GAMMA = new decimal_js_1.default('0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495');
22
+ const DEFAULT_SERIES_GUARD_DIGITS = 8;
23
+ const MIN_PRECISION_SERIES_ITERATIONS = 1000;
24
+ const SERIES_ITERATIONS_PER_PRECISION_DIGIT = 8;
25
+ const DECIMAL_SINC_SERIES_CUTOFF = '1e-8';
26
+ const OSCILLATORY_ASYMPTOTIC_CUTOFF = 1e9;
27
+ const RATIONAL_APPROXIMATION_CUTOFF = 4;
28
+ const ASYMPTOTIC_APPROXIMATION_CUTOFF = 8;
29
+ const EXPONENTIAL_ASYMPTOTIC_CUTOFF = 40;
30
+ const SERIES_MAX_ITERATIONS = 200;
31
+ const ASYMPTOTIC_MAX_TERMS = 100;
32
+ const POWER_SERIES_MAX_TERMS = 500;
33
+ function getSeriesError(guardDigits = DEFAULT_SERIES_GUARD_DIGITS) {
34
+ return new decimal_js_1.default(10).pow(-(decimal_js_1.default.precision + guardDigits));
35
+ }
36
+ function gammaSpouge(x) {
37
+ const precision = decimal_js_1.default.precision;
38
+ decimal_js_1.default.set({ precision: Math.floor(precision * 1.45) });
39
+ try {
40
+ const n = precision;
41
+ const coeffs = calcCoeffs(n);
42
+ let accm = coeffs[0];
43
+ for (let k = 1; k < n; k++) {
44
+ accm = accm.plus(coeffs[k].div(x.plus(k)));
45
+ }
46
+ accm = accm.times(decimal_js_1.default.exp(x.plus(n).neg())).times(decimal_js_1.default.pow(x.plus(n), x.plus(0.5)));
47
+ return accm.div(x);
48
+ }
49
+ finally {
50
+ decimal_js_1.default.set({ precision });
51
+ }
52
+ }
53
+ function erf(x) {
54
+ x = new decimal_js_1.default(x);
55
+ const pi = decimal_js_1.default.acos(-1);
56
+ const twoOverSqrtPi = new decimal_js_1.default(2).div(pi.sqrt());
57
+ const error = getSeriesError();
58
+ const sgn = decimal_js_1.default.sign(x);
59
+ x = x.abs();
60
+ if (x.isZero()) {
61
+ return new decimal_js_1.default(0);
62
+ }
63
+ if (x.lt(2)) {
64
+ let sum = new decimal_js_1.default(0);
65
+ let k = 0;
66
+ let dx = x;
67
+ const max = Math.max(MIN_PRECISION_SERIES_ITERATIONS, decimal_js_1.default.precision * SERIES_ITERATIONS_PER_PRECISION_DIGIT);
68
+ while (dx.gte(error)) {
69
+ const num = new decimal_js_1.default(-1).pow(k).times(x.pow(2 * k + 1));
70
+ const den = new decimal_js_1.default(2 * k + 1).times(String((0, bigint_1.factorial)(k)));
71
+ const result = sum.plus(num.div(den));
72
+ dx = result.minus(sum).abs();
73
+ sum = result;
74
+ k++;
75
+ if (k > max) {
76
+ throw new Error('erf not converging. Exiting!');
77
+ }
78
+ }
79
+ let retval = decimal_js_1.default.min(twoOverSqrtPi.times(sum), 1);
80
+ if (sgn === -1) {
81
+ retval = retval.neg();
82
+ }
83
+ return retval;
84
+ }
85
+ // Asymptotic expansion of erfc(x) for larger |x|:
86
+ // erfc(x) ~ exp(-x^2)/(sqrt(pi)*x) * (1 - 1/(2x^2) + 3/(4x^4) - 15/(8x^6) + ...)
87
+ const xx = x.mul(x);
88
+ const twoX2 = xx.mul(2);
89
+ let term = new decimal_js_1.default(1);
90
+ let series = term;
91
+ let best = term.abs();
92
+ const max = Math.max(MIN_PRECISION_SERIES_ITERATIONS, decimal_js_1.default.precision * SERIES_ITERATIONS_PER_PRECISION_DIGIT);
93
+ for (let n = 1; n < max; n++) {
94
+ term = term.mul(-(2 * n - 1)).div(twoX2);
95
+ const at = term.abs();
96
+ if (at.gt(best)) {
97
+ break;
98
+ }
99
+ best = at;
100
+ series = series.plus(term);
101
+ if (at.lt(error)) {
102
+ break;
103
+ }
104
+ }
105
+ const erfc = x.neg().mul(x).exp().div(pi.sqrt().mul(x)).times(series);
106
+ let retval = new decimal_js_1.default(1).minus(erfc);
107
+ if (sgn === -1) {
108
+ retval = retval.neg();
109
+ }
110
+ return retval;
111
+ }
112
+ function calcCoeffs(n) {
113
+ const c = [];
114
+ let kFact = new decimal_js_1.default(1);
115
+ // Get pi
116
+ const pi = decimal_js_1.default.acos(-1);
117
+ // sqrt(2*pi);
118
+ c[0] = pi.times(2).sqrt();
119
+ for (let k = 1; k < n; k++) {
120
+ c[k] = decimal_js_1.default.exp(n - k)
121
+ .times(decimal_js_1.default.pow(n - k, k - 0.5))
122
+ .div(kFact);
123
+ kFact = kFact.times(-k);
124
+ }
125
+ return c;
126
+ }
127
+ // https://math.stackexchange.com/questions/2204020/definition-of-the-gamma-function-for-non-integer-negative-values
128
+ /**
129
+ * The gamma function using Spouge approximation.
130
+ * This function is slow converging but appropriate for arbitrary precision. It relies on Decimal.js.
131
+ *
132
+ * Ported from: https://rosettacode.org/wiki/Gamma_function#C++ (the implementation)
133
+ * https://math.stackexchange.com/questions/2204020/definition-of-the-gamma-function-for-non-integer-negative-values (negative gamma)
134
+ * https://en.wikipedia.org/wiki/Spouge%27s_approximation (Spouge's Approximation)
135
+ *
136
+ * @param n The number of elements to be calculated in the coefficient array
137
+ * @param x The number being evaluated
138
+ * @returns
139
+ */
140
+ function gamma(x) {
141
+ x = new decimal_js_1.default(x);
142
+ if (x.isInteger()) {
143
+ if (x.lte(0)) {
144
+ return new decimal_js_1.default(Infinity);
145
+ }
146
+ return new decimal_js_1.default(String((0, bigint_1.factorial)(Number(x.minus(1)))));
147
+ }
148
+ if (x.lt(0)) {
149
+ const pi = decimal_js_1.default.acos(-1);
150
+ return pi.div(pi
151
+ .times(x)
152
+ .sin()
153
+ .times(gammaSpouge(new decimal_js_1.default(1).minus(x))));
154
+ }
155
+ return gammaSpouge(x);
156
+ }
157
+ function sinc(x) {
158
+ const d = new decimal_js_1.default(x);
159
+ if (d.isZero()) {
160
+ return new decimal_js_1.default(1);
161
+ }
162
+ const ax = d.abs();
163
+ if (ax.lt(DECIMAL_SINC_SERIES_CUTOFF)) {
164
+ const x2 = d.mul(d);
165
+ return new decimal_js_1.default(1)
166
+ .minus(x2.div(6))
167
+ .plus(x2.mul(x2).div(120))
168
+ .minus(x2.mul(x2).mul(x2).div(5040));
169
+ }
170
+ return d.sin().div(d);
171
+ }
172
+ function Si(x) {
173
+ let d = new decimal_js_1.default(x);
174
+ if (d.isZero()) {
175
+ return new decimal_js_1.default(0);
176
+ }
177
+ let sign = new decimal_js_1.default(1);
178
+ if (d.isNeg()) {
179
+ sign = new decimal_js_1.default(-1);
180
+ d = d.neg();
181
+ }
182
+ function polevl(y, coef) {
183
+ let ans = coef[0];
184
+ for (let i = 1; i < coef.length; i++) {
185
+ ans = ans.mul(y).plus(coef[i]);
186
+ }
187
+ return ans;
188
+ }
189
+ function p1evl(y, coef) {
190
+ let ans = y.plus(coef[0]);
191
+ for (let i = 1; i < coef.length; i++) {
192
+ ans = ans.mul(y).plus(coef[i]);
193
+ }
194
+ return ans;
195
+ }
196
+ if (d.gt(OSCILLATORY_ASYMPTOTIC_CUTOFF)) {
197
+ const halfPi = decimal_js_1.default.acos(-1).div(2);
198
+ return sign.mul(halfPi.minus(d.cos().div(d)));
199
+ }
200
+ if (d.lte(RATIONAL_APPROXIMATION_CUTOFF)) {
201
+ const SN = [
202
+ new decimal_js_1.default('-8.39167827910303881427e-11'),
203
+ new decimal_js_1.default('4.62591714427012837309e-8'),
204
+ new decimal_js_1.default('-9.75759303843632795789e-6'),
205
+ new decimal_js_1.default('9.76945438170435310816e-4'),
206
+ new decimal_js_1.default('-4.13470316229406538752e-2'),
207
+ new decimal_js_1.default('1.00000000000000000302'),
208
+ ];
209
+ const SD = [
210
+ new decimal_js_1.default('2.03269266195951942049e-12'),
211
+ new decimal_js_1.default('1.27997891179943299903e-9'),
212
+ new decimal_js_1.default('4.41827842801218905784e-7'),
213
+ new decimal_js_1.default('9.96412122043875552487e-5'),
214
+ new decimal_js_1.default('1.42085239326149893930e-2'),
215
+ new decimal_js_1.default('9.99999999999999996984e-1'),
216
+ ];
217
+ const z = d.mul(d);
218
+ const s = d.mul(polevl(z, SN)).div(polevl(z, SD));
219
+ return sign.mul(s);
220
+ }
221
+ const s = d.sin();
222
+ const c = d.cos();
223
+ const z = new decimal_js_1.default(1).div(d.mul(d));
224
+ let f;
225
+ let g;
226
+ if (d.lt(ASYMPTOTIC_APPROXIMATION_CUTOFF)) {
227
+ const FN4 = [
228
+ new decimal_js_1.default('4.23612862892216586994'),
229
+ new decimal_js_1.default('5.45937717161812843388'),
230
+ new decimal_js_1.default('1.62083287701538329132'),
231
+ new decimal_js_1.default('1.67006611831323023771e-1'),
232
+ new decimal_js_1.default('6.81020132472518137426e-3'),
233
+ new decimal_js_1.default('1.08936580650328664411e-4'),
234
+ new decimal_js_1.default('5.48900223421373614008e-7'),
235
+ ];
236
+ const FD4 = [
237
+ new decimal_js_1.default('8.16496634205391016773'),
238
+ new decimal_js_1.default('7.30828822505564552187'),
239
+ new decimal_js_1.default('1.86792257950184183883'),
240
+ new decimal_js_1.default('1.78792052963149907262e-1'),
241
+ new decimal_js_1.default('7.01710668322789753610e-3'),
242
+ new decimal_js_1.default('1.10034357153915731354e-4'),
243
+ new decimal_js_1.default('5.48900252756255700982e-7'),
244
+ ];
245
+ const GN4 = [
246
+ new decimal_js_1.default('8.71001698973114191777e-2'),
247
+ new decimal_js_1.default('6.11379109952219284151e-1'),
248
+ new decimal_js_1.default('3.97180296392337498885e-1'),
249
+ new decimal_js_1.default('7.48527737628469092119e-2'),
250
+ new decimal_js_1.default('5.38868681462177273157e-3'),
251
+ new decimal_js_1.default('1.61999794598934024525e-4'),
252
+ new decimal_js_1.default('1.97963874140963632189e-6'),
253
+ new decimal_js_1.default('7.82579040744090311069e-9'),
254
+ ];
255
+ const GD4 = [
256
+ new decimal_js_1.default('1.64402202413355338886'),
257
+ new decimal_js_1.default('6.66296701268987968381e-1'),
258
+ new decimal_js_1.default('9.88771761277688796203e-2'),
259
+ new decimal_js_1.default('6.22396345441768420760e-3'),
260
+ new decimal_js_1.default('1.73221081474177119497e-4'),
261
+ new decimal_js_1.default('2.02659182086343991969e-6'),
262
+ new decimal_js_1.default('7.82579218933534490868e-9'),
263
+ ];
264
+ f = polevl(z, FN4).div(d.mul(p1evl(z, FD4)));
265
+ g = z.mul(polevl(z, GN4)).div(p1evl(z, GD4));
266
+ }
267
+ else {
268
+ const FN8 = [
269
+ new decimal_js_1.default('4.55880873470465315206e-1'),
270
+ new decimal_js_1.default('7.13715274100146711374e-1'),
271
+ new decimal_js_1.default('1.60300158222319456320e-1'),
272
+ new decimal_js_1.default('1.16064229408124407915e-2'),
273
+ new decimal_js_1.default('3.49556442447859055605e-4'),
274
+ new decimal_js_1.default('4.86215430826454749482e-6'),
275
+ new decimal_js_1.default('3.20092790091004902806e-8'),
276
+ new decimal_js_1.default('9.41779576128512936592e-11'),
277
+ new decimal_js_1.default('9.70507110881952024631e-14'),
278
+ ];
279
+ const FD8 = [
280
+ new decimal_js_1.default('9.17463611873684053703e-1'),
281
+ new decimal_js_1.default('1.78685545332074536321e-1'),
282
+ new decimal_js_1.default('1.22253594771971293032e-2'),
283
+ new decimal_js_1.default('3.58696481881851580297e-4'),
284
+ new decimal_js_1.default('4.92435064317881464393e-6'),
285
+ new decimal_js_1.default('3.21956939101046018377e-8'),
286
+ new decimal_js_1.default('9.43720590350276732376e-11'),
287
+ new decimal_js_1.default('9.70507110881952025725e-14'),
288
+ ];
289
+ const GN8 = [
290
+ new decimal_js_1.default('6.97359953443276214934e-1'),
291
+ new decimal_js_1.default('3.30410979305632063225e-1'),
292
+ new decimal_js_1.default('3.84878767649974295920e-2'),
293
+ new decimal_js_1.default('1.71718239052347903558e-3'),
294
+ new decimal_js_1.default('3.48941165502279436777e-5'),
295
+ new decimal_js_1.default('3.47131167084116673800e-7'),
296
+ new decimal_js_1.default('1.70404452782044526189e-9'),
297
+ new decimal_js_1.default('3.85945925430276600453e-12'),
298
+ new decimal_js_1.default('3.14040098946363334640e-15'),
299
+ ];
300
+ const GD8 = [
301
+ new decimal_js_1.default('1.68548898811011640017'),
302
+ new decimal_js_1.default('4.87852258695304967486e-1'),
303
+ new decimal_js_1.default('4.67913194259625806320e-2'),
304
+ new decimal_js_1.default('1.90284426674399523638e-3'),
305
+ new decimal_js_1.default('3.68475504442561108162e-5'),
306
+ new decimal_js_1.default('3.57043223443740838771e-7'),
307
+ new decimal_js_1.default('1.72693748966316146736e-9'),
308
+ new decimal_js_1.default('3.87830166023954706752e-12'),
309
+ new decimal_js_1.default('3.14040098946363335242e-15'),
310
+ ];
311
+ f = polevl(z, FN8).div(d.mul(p1evl(z, FD8)));
312
+ g = z.mul(polevl(z, GN8)).div(p1evl(z, GD8));
313
+ }
314
+ const halfPi = decimal_js_1.default.acos(-1).div(2);
315
+ return sign.mul(halfPi.minus(f.mul(c)).minus(g.mul(s)));
316
+ }
317
+ function Shi(x) {
318
+ const d = new decimal_js_1.default(x);
319
+ if (d.isZero()) {
320
+ return new decimal_js_1.default(0);
321
+ }
322
+ const sign = d.isNeg() ? new decimal_js_1.default(-1) : new decimal_js_1.default(1);
323
+ const ax = d.abs();
324
+ if (ax.lt(ASYMPTOTIC_APPROXIMATION_CUTOFF)) {
325
+ let term = ax;
326
+ let sum = term;
327
+ let n = 0;
328
+ for (let iter = 0; iter < SERIES_MAX_ITERATIONS; iter++) {
329
+ const a = 2 * n + 1;
330
+ term = term
331
+ .mul(ax)
332
+ .mul(ax)
333
+ .mul(a)
334
+ .div(new decimal_js_1.default(a + 2).mul(a + 2).mul(a + 1));
335
+ sum = sum.plus(term);
336
+ n++;
337
+ if (term.abs().lt(getSeriesError())) {
338
+ break;
339
+ }
340
+ }
341
+ return sign.mul(sum);
342
+ }
343
+ function EiLocal(y) {
344
+ if (y.isZero()) {
345
+ return new decimal_js_1.default(-Infinity);
346
+ }
347
+ if (y.gt(EXPONENTIAL_ASYMPTOTIC_CUTOFF) || y.lt(-EXPONENTIAL_ASYMPTOTIC_CUTOFF)) {
348
+ let term = new decimal_js_1.default(1);
349
+ let sum = new decimal_js_1.default(1);
350
+ let best = term.abs();
351
+ for (let n = 1; n < ASYMPTOTIC_MAX_TERMS; n++) {
352
+ term = term.mul(n).div(y);
353
+ const at = term.abs();
354
+ if (at.gt(best)) {
355
+ break;
356
+ }
357
+ best = at;
358
+ sum = sum.plus(term);
359
+ if (at.lt(getSeriesError())) {
360
+ break;
361
+ }
362
+ }
363
+ return y.exp().mul(sum).div(y);
364
+ }
365
+ let term = y;
366
+ let sum = term;
367
+ for (let k = 1; k < POWER_SERIES_MAX_TERMS; k++) {
368
+ term = term
369
+ .mul(y)
370
+ .mul(k)
371
+ .div(new decimal_js_1.default(k + 1).mul(k + 1));
372
+ sum = sum.plus(term);
373
+ if (term.abs().lt(getSeriesError())) {
374
+ break;
375
+ }
376
+ }
377
+ return exports.EULER_GAMMA.plus(y.abs().ln()).plus(sum);
378
+ }
379
+ return EiLocal(d).minus(EiLocal(d.neg())).div(2);
380
+ }
381
+ function Ci(x) {
382
+ let d = new decimal_js_1.default(x);
383
+ if (d.isZero()) {
384
+ return new decimal_js_1.default(-Infinity);
385
+ }
386
+ if (d.isNeg()) {
387
+ d = d.neg();
388
+ }
389
+ function polevl(y, coef) {
390
+ let ans = coef[0];
391
+ for (let i = 1; i < coef.length; i++) {
392
+ ans = ans.mul(y).plus(coef[i]);
393
+ }
394
+ return ans;
395
+ }
396
+ function p1evl(y, coef) {
397
+ let ans = y.plus(coef[0]);
398
+ for (let i = 1; i < coef.length; i++) {
399
+ ans = ans.mul(y).plus(coef[i]);
400
+ }
401
+ return ans;
402
+ }
403
+ if (d.gt(OSCILLATORY_ASYMPTOTIC_CUTOFF)) {
404
+ return d.sin().div(d);
405
+ }
406
+ if (d.lte(RATIONAL_APPROXIMATION_CUTOFF)) {
407
+ const CN = [
408
+ new decimal_js_1.default('2.02524002389102268789e-11'),
409
+ new decimal_js_1.default('-1.35249504915790756375e-8'),
410
+ new decimal_js_1.default('3.59325051419993077021e-6'),
411
+ new decimal_js_1.default('-4.74007206873407909465e-4'),
412
+ new decimal_js_1.default('2.89159652607555242092e-2'),
413
+ new decimal_js_1.default('-1.00000000000000000080'),
414
+ ];
415
+ const CD = [
416
+ new decimal_js_1.default('4.07746040061880559506e-12'),
417
+ new decimal_js_1.default('3.06780997581887812692e-9'),
418
+ new decimal_js_1.default('1.23210355685883423679e-6'),
419
+ new decimal_js_1.default('3.17442024775032769882e-4'),
420
+ new decimal_js_1.default('5.10028056236446052392e-2'),
421
+ new decimal_js_1.default('4.00000000000000000080'),
422
+ ];
423
+ const z = d.mul(d);
424
+ const c0 = z.mul(polevl(z, CN)).div(polevl(z, CD));
425
+ return exports.EULER_GAMMA.plus(d.ln()).plus(c0);
426
+ }
427
+ const s = d.sin();
428
+ const c = d.cos();
429
+ const z = new decimal_js_1.default(1).div(d.mul(d));
430
+ let f;
431
+ let g;
432
+ if (d.lt(ASYMPTOTIC_APPROXIMATION_CUTOFF)) {
433
+ const FN4 = [
434
+ new decimal_js_1.default('4.23612862892216586994'),
435
+ new decimal_js_1.default('5.45937717161812843388'),
436
+ new decimal_js_1.default('1.62083287701538329132'),
437
+ new decimal_js_1.default('1.67006611831323023771e-1'),
438
+ new decimal_js_1.default('6.81020132472518137426e-3'),
439
+ new decimal_js_1.default('1.08936580650328664411e-4'),
440
+ new decimal_js_1.default('5.48900223421373614008e-7'),
441
+ ];
442
+ const FD4 = [
443
+ new decimal_js_1.default('8.16496634205391016773'),
444
+ new decimal_js_1.default('7.30828822505564552187'),
445
+ new decimal_js_1.default('1.86792257950184183883'),
446
+ new decimal_js_1.default('1.78792052963149907262e-1'),
447
+ new decimal_js_1.default('7.01710668322789753610e-3'),
448
+ new decimal_js_1.default('1.10034357153915731354e-4'),
449
+ new decimal_js_1.default('5.48900252756255700982e-7'),
450
+ ];
451
+ const GN4 = [
452
+ new decimal_js_1.default('8.71001698973114191777e-2'),
453
+ new decimal_js_1.default('6.11379109952219284151e-1'),
454
+ new decimal_js_1.default('3.97180296392337498885e-1'),
455
+ new decimal_js_1.default('7.48527737628469092119e-2'),
456
+ new decimal_js_1.default('5.38868681462177273157e-3'),
457
+ new decimal_js_1.default('1.61999794598934024525e-4'),
458
+ new decimal_js_1.default('1.97963874140963632189e-6'),
459
+ new decimal_js_1.default('7.82579040744090311069e-9'),
460
+ ];
461
+ const GD4 = [
462
+ new decimal_js_1.default('1.64402202413355338886'),
463
+ new decimal_js_1.default('6.66296701268987968381e-1'),
464
+ new decimal_js_1.default('9.88771761277688796203e-2'),
465
+ new decimal_js_1.default('6.22396345441768420760e-3'),
466
+ new decimal_js_1.default('1.73221081474177119497e-4'),
467
+ new decimal_js_1.default('2.02659182086343991969e-6'),
468
+ new decimal_js_1.default('7.82579218933534490868e-9'),
469
+ ];
470
+ f = polevl(z, FN4).div(d.mul(p1evl(z, FD4)));
471
+ g = z.mul(polevl(z, GN4)).div(p1evl(z, GD4));
472
+ }
473
+ else {
474
+ const FN8 = [
475
+ new decimal_js_1.default('4.55880873470465315206e-1'),
476
+ new decimal_js_1.default('7.13715274100146711374e-1'),
477
+ new decimal_js_1.default('1.60300158222319456320e-1'),
478
+ new decimal_js_1.default('1.16064229408124407915e-2'),
479
+ new decimal_js_1.default('3.49556442447859055605e-4'),
480
+ new decimal_js_1.default('4.86215430826454749482e-6'),
481
+ new decimal_js_1.default('3.20092790091004902806e-8'),
482
+ new decimal_js_1.default('9.41779576128512936592e-11'),
483
+ new decimal_js_1.default('9.70507110881952024631e-14'),
484
+ ];
485
+ const FD8 = [
486
+ new decimal_js_1.default('9.17463611873684053703e-1'),
487
+ new decimal_js_1.default('1.78685545332074536321e-1'),
488
+ new decimal_js_1.default('1.22253594771971293032e-2'),
489
+ new decimal_js_1.default('3.58696481881851580297e-4'),
490
+ new decimal_js_1.default('4.92435064317881464393e-6'),
491
+ new decimal_js_1.default('3.21956939101046018377e-8'),
492
+ new decimal_js_1.default('9.43720590350276732376e-11'),
493
+ new decimal_js_1.default('9.70507110881952025725e-14'),
494
+ ];
495
+ const GN8 = [
496
+ new decimal_js_1.default('6.97359953443276214934e-1'),
497
+ new decimal_js_1.default('3.30410979305632063225e-1'),
498
+ new decimal_js_1.default('3.84878767649974295920e-2'),
499
+ new decimal_js_1.default('1.71718239052347903558e-3'),
500
+ new decimal_js_1.default('3.48941165502279436777e-5'),
501
+ new decimal_js_1.default('3.47131167084116673800e-7'),
502
+ new decimal_js_1.default('1.70404452782044526189e-9'),
503
+ new decimal_js_1.default('3.85945925430276600453e-12'),
504
+ new decimal_js_1.default('3.14040098946363334640e-15'),
505
+ ];
506
+ const GD8 = [
507
+ new decimal_js_1.default('1.68548898811011640017'),
508
+ new decimal_js_1.default('4.87852258695304967486e-1'),
509
+ new decimal_js_1.default('4.67913194259625806320e-2'),
510
+ new decimal_js_1.default('1.90284426674399523638e-3'),
511
+ new decimal_js_1.default('3.68475504442561108162e-5'),
512
+ new decimal_js_1.default('3.57043223443740838771e-7'),
513
+ new decimal_js_1.default('1.72693748966316146736e-9'),
514
+ new decimal_js_1.default('3.87830166023954706752e-12'),
515
+ new decimal_js_1.default('3.14040098946363335242e-15'),
516
+ ];
517
+ f = polevl(z, FN8).div(d.mul(p1evl(z, FD8)));
518
+ g = z.mul(polevl(z, GN8)).div(p1evl(z, GD8));
519
+ }
520
+ return f.mul(s).minus(g.mul(c));
521
+ }
522
+ function Chi(x) {
523
+ const d = new decimal_js_1.default(x);
524
+ const ax = d.abs();
525
+ if (ax.isZero()) {
526
+ return new decimal_js_1.default(-Infinity);
527
+ }
528
+ if (ax.lt(ASYMPTOTIC_APPROXIMATION_CUTOFF)) {
529
+ let n = 1;
530
+ let term = ax.mul(ax).div(4);
531
+ let sum = term;
532
+ for (let iter = 0; iter < SERIES_MAX_ITERATIONS; iter++) {
533
+ term = term
534
+ .mul(ax)
535
+ .mul(ax)
536
+ .mul(n)
537
+ .div(new decimal_js_1.default(n + 1).mul(2 * n + 1).mul(2 * n + 2));
538
+ sum = sum.plus(term);
539
+ n++;
540
+ if (term.abs().lt(getSeriesError())) {
541
+ break;
542
+ }
543
+ }
544
+ return exports.EULER_GAMMA.plus(ax.ln()).plus(sum);
545
+ }
546
+ function EiLocal(y) {
547
+ if (y.isZero()) {
548
+ return new decimal_js_1.default(-Infinity);
549
+ }
550
+ if (y.gt(EXPONENTIAL_ASYMPTOTIC_CUTOFF) || y.lt(-EXPONENTIAL_ASYMPTOTIC_CUTOFF)) {
551
+ let term = new decimal_js_1.default(1);
552
+ let sum = new decimal_js_1.default(1);
553
+ let best = term.abs();
554
+ for (let n = 1; n < ASYMPTOTIC_MAX_TERMS; n++) {
555
+ term = term.mul(n).div(y);
556
+ const at = term.abs();
557
+ if (at.gt(best)) {
558
+ break;
559
+ }
560
+ best = at;
561
+ sum = sum.plus(term);
562
+ if (at.lt(getSeriesError())) {
563
+ break;
564
+ }
565
+ }
566
+ return y.exp().mul(sum).div(y);
567
+ }
568
+ let term = y;
569
+ let sum = term;
570
+ for (let k = 1; k < POWER_SERIES_MAX_TERMS; k++) {
571
+ term = term
572
+ .mul(y)
573
+ .mul(k)
574
+ .div(new decimal_js_1.default(k + 1).mul(k + 1));
575
+ sum = sum.plus(term);
576
+ if (term.abs().lt(getSeriesError())) {
577
+ break;
578
+ }
579
+ }
580
+ return exports.EULER_GAMMA.plus(y.abs().ln()).plus(sum);
581
+ }
582
+ return EiLocal(d).plus(EiLocal(d.neg())).div(2);
583
+ }
584
+ function Ei(x) {
585
+ const d = new decimal_js_1.default(x);
586
+ if (d.isZero()) {
587
+ return new decimal_js_1.default(-Infinity);
588
+ }
589
+ if (d.gt(EXPONENTIAL_ASYMPTOTIC_CUTOFF) || d.lt(-EXPONENTIAL_ASYMPTOTIC_CUTOFF)) {
590
+ let term = new decimal_js_1.default(1);
591
+ let sum = new decimal_js_1.default(1);
592
+ let best = term.abs();
593
+ for (let n = 1; n < ASYMPTOTIC_MAX_TERMS; n++) {
594
+ term = term.mul(n).div(d);
595
+ const at = term.abs();
596
+ if (at.gt(best)) {
597
+ break;
598
+ }
599
+ best = at;
600
+ sum = sum.plus(term);
601
+ if (at.lt(getSeriesError())) {
602
+ break;
603
+ }
604
+ }
605
+ return d.exp().mul(sum).div(d);
606
+ }
607
+ let term = d;
608
+ let sum = term;
609
+ for (let k = 1; k < POWER_SERIES_MAX_TERMS; k++) {
610
+ term = term
611
+ .mul(d)
612
+ .mul(k)
613
+ .div(new decimal_js_1.default(k + 1).mul(k + 1));
614
+ sum = sum.plus(term);
615
+ if (term.abs().lt(getSeriesError())) {
616
+ break;
617
+ }
618
+ }
619
+ return exports.EULER_GAMMA.plus(d.abs().ln()).plus(sum);
620
+ }
621
+ function Li(x) {
622
+ const d = new decimal_js_1.default(x);
623
+ if (d.lte(0)) {
624
+ return new decimal_js_1.default(NaN);
625
+ }
626
+ if (d.eq(1)) {
627
+ return new decimal_js_1.default(-Infinity);
628
+ }
629
+ const y = d.ln();
630
+ if (y.isZero()) {
631
+ return new decimal_js_1.default(-Infinity);
632
+ }
633
+ if (y.gt(EXPONENTIAL_ASYMPTOTIC_CUTOFF) || y.lt(-EXPONENTIAL_ASYMPTOTIC_CUTOFF)) {
634
+ let term = new decimal_js_1.default(1);
635
+ let sum = new decimal_js_1.default(1);
636
+ let best = term.abs();
637
+ for (let n = 1; n < ASYMPTOTIC_MAX_TERMS; n++) {
638
+ term = term.mul(n).div(y);
639
+ const at = term.abs();
640
+ if (at.gt(best)) {
641
+ break;
642
+ }
643
+ best = at;
644
+ sum = sum.plus(term);
645
+ if (at.lt(getSeriesError())) {
646
+ break;
647
+ }
648
+ }
649
+ return y.exp().mul(sum).div(y);
650
+ }
651
+ let term = y;
652
+ let sum = term;
653
+ for (let k = 1; k < POWER_SERIES_MAX_TERMS; k++) {
654
+ term = term
655
+ .mul(y)
656
+ .mul(k)
657
+ .div(new decimal_js_1.default(k + 1).mul(k + 1));
658
+ sum = sum.plus(term);
659
+ if (term.abs().lt(getSeriesError())) {
660
+ break;
661
+ }
662
+ }
663
+ return exports.EULER_GAMMA.plus(y.abs().ln()).plus(sum);
664
+ }