nerdamer 2.0.0-rc.1 → 2.0.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 (236) hide show
  1. package/BREAKING_CHANGES.md +244 -0
  2. package/README.md +168 -229
  3. package/dist/bundle.js +1 -1
  4. package/dist/bundle.js.LICENSE.txt +6 -6
  5. package/output/algebra/adapters.d.ts +3 -33
  6. package/output/algebra/adapters.js +7 -105
  7. package/output/algebra/algorithms/arith.js +10 -9
  8. package/output/algebra/algorithms/groebnerBase.d.ts +24 -20
  9. package/output/algebra/algorithms/groebnerBase.js +486 -723
  10. package/output/algebra/dispatch.d.ts +1 -0
  11. package/output/algebra/dispatch.js +25 -0
  12. package/output/algebra/factor/factor.d.ts +15 -0
  13. package/output/algebra/factor/factor.js +99 -12
  14. package/output/algebra/gcd/gcd.d.ts +8 -7
  15. package/output/algebra/gcd/gcd.js +32 -78
  16. package/output/algebra/groebner.d.ts +2 -2
  17. package/output/algebra/groebner.js +6 -12
  18. package/output/algebra/partfrac.d.ts +3 -3
  19. package/output/algebra/partfrac.js +28 -61
  20. package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
  21. package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
  22. package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
  23. package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
  24. package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
  25. package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
  26. package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
  27. package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
  28. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
  29. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
  30. package/output/algebra/polynomial/modularGcd.d.ts +40 -0
  31. package/output/algebra/polynomial/modularGcd.js +365 -0
  32. package/output/algebra/polynomialize.js +4 -2
  33. package/output/algebra/simplify/funcsimp.js +1 -1
  34. package/output/algebra/simplify/ratsimp.js +1 -1
  35. package/output/algebra/simplify/simplify.js +11 -2
  36. package/output/algebra/utils.d.ts +1 -1
  37. package/output/algebra/utils.js +3 -3
  38. package/output/api/advanced.d.ts +2 -1
  39. package/output/api/advanced.js +3 -3
  40. package/output/api/algebra.d.ts +21 -4
  41. package/output/api/algebra.js +22 -3
  42. package/output/api/assumptions.d.ts +1 -1
  43. package/output/api/assumptions.js +2 -1
  44. package/output/api/calculus.d.ts +2 -1
  45. package/output/api/calculus.js +2 -1
  46. package/output/api/core.d.ts +28 -7
  47. package/output/api/core.js +28 -2
  48. package/output/api/languages/deu.d.ts +3 -0
  49. package/output/api/languages/deu.js +266 -0
  50. package/output/api/languages/fra.d.ts +3 -0
  51. package/output/api/languages/fra.js +266 -0
  52. package/output/api/languages/ita.d.ts +3 -0
  53. package/output/api/languages/ita.js +266 -0
  54. package/output/api/languages/nld.d.ts +3 -0
  55. package/output/api/languages/nld.js +266 -0
  56. package/output/api/languages/por.d.ts +3 -0
  57. package/output/api/languages/por.js +266 -0
  58. package/output/api/languages/spa.d.ts +3 -0
  59. package/output/api/languages/spa.js +266 -0
  60. package/output/api/parser.d.ts +10 -2
  61. package/output/api/parser.js +2 -0
  62. package/output/api/solve.d.ts +1 -1
  63. package/output/api/solve.js +2 -1
  64. package/output/api/structures.d.ts +1 -1
  65. package/output/api/structures.js +2 -1
  66. package/output/calculus/adapters.d.ts +8 -0
  67. package/output/calculus/adapters.js +41 -0
  68. package/output/calculus/derivative/diff.js +6 -3
  69. package/output/calculus/dispatch.d.ts +1 -0
  70. package/output/calculus/dispatch.js +25 -0
  71. package/output/calculus/integrate/integrate.js +4 -4
  72. package/output/calculus/integrate/integrationTable.js +16 -16
  73. package/output/calculus/laplace/ilaplace.js +1 -1
  74. package/output/calculus/laplace/ilaplaceTable.js +18 -17
  75. package/output/calculus/laplace/laplaceTable.js +3 -2
  76. package/output/calculus/limit/limit.js +1 -1
  77. package/output/core/classes/assumption/Assumption.js +14 -10
  78. package/output/core/classes/assumption/assume.d.ts +6 -0
  79. package/output/core/classes/assumption/assume.js +9 -0
  80. package/output/core/classes/assumption/dispatch.d.ts +1 -0
  81. package/output/core/classes/assumption/dispatch.js +11 -0
  82. package/output/core/classes/collection/Collection.js +11 -2
  83. package/output/core/classes/complex/Complex.d.ts +10 -0
  84. package/output/core/classes/complex/Complex.js +19 -1
  85. package/output/core/classes/decimalSet/DecimalSet.js +5 -4
  86. package/output/core/classes/dictionary/Dictionary.js +4 -1
  87. package/output/core/classes/expression/CoeffObject.d.ts +1 -1
  88. package/output/core/classes/expression/CoeffObject.js +1 -2
  89. package/output/core/classes/expression/Expression.d.ts +35 -26
  90. package/output/core/classes/expression/Expression.js +77 -50
  91. package/output/core/classes/expression/analysis.d.ts +1 -1
  92. package/output/core/classes/expression/analysis.js +7 -7
  93. package/output/core/classes/expression/format.d.ts +9 -0
  94. package/output/core/classes/expression/format.js +130 -7
  95. package/output/core/classes/expression/utils.d.ts +9 -0
  96. package/output/core/classes/expression/utils.js +52 -6
  97. package/output/core/classes/matrix/Matrix.d.ts +2 -3
  98. package/output/core/classes/matrix/Matrix.js +26 -23
  99. package/output/core/classes/matrix/dispatch.d.ts +1 -0
  100. package/output/core/classes/matrix/dispatch.js +19 -0
  101. package/output/core/classes/matrix/functions.d.ts +2 -0
  102. package/output/core/classes/matrix/functions.js +5 -0
  103. package/output/core/classes/parser/Parser.d.ts +31 -5
  104. package/output/core/classes/parser/Parser.js +357 -444
  105. package/output/core/classes/parser/constants.d.ts +2 -0
  106. package/output/core/classes/parser/constants.js +4 -2
  107. package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
  108. package/output/core/classes/parser/controlFlowSignals.js +60 -0
  109. package/output/core/classes/parser/operations/add.js +14 -16
  110. package/output/core/classes/parser/operations/compare.js +13 -0
  111. package/output/core/classes/parser/operations/functions.d.ts +3 -4
  112. package/output/core/classes/parser/operations/functions.js +48 -102
  113. package/output/core/classes/parser/operations/multiply.js +22 -15
  114. package/output/core/classes/parser/operations/power.js +11 -11
  115. package/output/core/classes/parser/operations/subtract.js +2 -1
  116. package/output/core/classes/parser/preprocess.d.ts +0 -7
  117. package/output/core/classes/parser/preprocess.js +33 -39
  118. package/output/core/classes/parser/scripting/controlFlow.d.ts +4 -102
  119. package/output/core/classes/parser/scripting/controlFlow.js +134 -186
  120. package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
  121. package/output/core/classes/parser/scripting/deferred.js +65 -0
  122. package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
  123. package/output/core/classes/parser/scripting/dispatch.js +62 -0
  124. package/output/core/classes/parser/scripting/evaluate.d.ts +13 -0
  125. package/output/core/classes/parser/scripting/evaluate.js +17 -1
  126. package/output/core/classes/parser/scripting/scope.d.ts +1 -28
  127. package/output/core/classes/parser/scripting/scope.js +36 -40
  128. package/output/core/classes/parser/types.d.ts +5 -5
  129. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +4 -3
  130. package/output/core/classes/parser/wrappers/IndexedReference.js +8 -0
  131. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +2 -2
  132. package/output/core/classes/polynomial/Polynomial.d.ts +5 -1
  133. package/output/core/classes/polynomial/Polynomial.js +53 -7
  134. package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
  135. package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
  136. package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
  137. package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -0
  138. package/output/core/classes/polynomial/Term.js +2 -2
  139. package/output/core/{adapters.d.ts → classes/polynomial/adapters.d.ts} +2 -2
  140. package/output/core/classes/polynomial/adapters.js +33 -0
  141. package/output/core/classes/polynomial/dispatch.d.ts +1 -0
  142. package/output/core/classes/polynomial/dispatch.js +14 -0
  143. package/output/core/classes/polynomial/functions.d.ts +8 -0
  144. package/output/core/classes/polynomial/functions.js +71 -8
  145. package/output/core/classes/polynomial/utils.js +2 -1
  146. package/output/core/classes/rational/Rational.d.ts +8 -11
  147. package/output/core/classes/rational/Rational.js +70 -20
  148. package/output/core/classes/seq/SEQ.js +4 -4
  149. package/output/core/classes/valuesSet/ValuesSet.d.ts +9 -1
  150. package/output/core/classes/valuesSet/ValuesSet.js +22 -4
  151. package/output/core/classes/vector/Vector.d.ts +2 -3
  152. package/output/core/classes/vector/Vector.js +11 -15
  153. package/output/core/classes/vector/dispatch.d.ts +1 -0
  154. package/output/core/classes/vector/dispatch.js +11 -0
  155. package/output/core/common/classes/MathematicalAggregate.js +11 -2
  156. package/output/core/common/classes/StructuredEntity.d.ts +0 -17
  157. package/output/core/common/classes/StructuredEntity.js +3 -64
  158. package/output/core/common/common.d.ts +0 -1
  159. package/output/core/common/common.js +29 -234
  160. package/output/core/converters/BaseConverter.js +3 -2
  161. package/output/core/converters/Converter.js +9 -5
  162. package/output/core/converters/Pattern.js +1 -1
  163. package/output/core/dispatch.d.ts +18 -0
  164. package/output/core/dispatch.js +3 -281
  165. package/output/core/errors.d.ts +259 -474
  166. package/output/core/errors.js +270 -542
  167. package/output/core/fullFunctions.d.ts +7 -0
  168. package/output/core/fullFunctions.js +31 -0
  169. package/output/core/functions/bigint/bigint.d.ts +13 -1
  170. package/output/core/functions/bigint/bigint.js +56 -4
  171. package/output/core/functions/bigint/primeFactor.d.ts +2 -0
  172. package/output/core/functions/bigint/primeFactor.js +13 -13
  173. package/output/core/functions/build/definitions.js +6 -0
  174. package/output/core/functions/complex.d.ts +2 -2
  175. package/output/core/functions/complex.dispatch.d.ts +1 -0
  176. package/output/core/functions/complex.dispatch.js +16 -0
  177. package/output/core/functions/complex.js +7 -7
  178. package/output/core/functions/decimal.js +2 -1
  179. package/output/core/functions/expand/expand.js +2 -2
  180. package/output/core/functions/numeric.d.ts +1 -1
  181. package/output/core/functions/string.js +2 -1
  182. package/output/core/functions/subst.js +21 -13
  183. package/output/core/parserFunctions.d.ts +7 -0
  184. package/output/core/parserFunctions.js +25 -0
  185. package/output/index.d.ts +50 -30
  186. package/output/index.js +147 -19
  187. package/output/math/defint/defint.d.ts +18 -0
  188. package/output/math/defint/defint.js +60 -0
  189. package/output/math/defint/defintDecimal.js +6 -5
  190. package/output/math/defint/defintNative.js +7 -18
  191. package/output/math/dispatch.d.ts +1 -0
  192. package/output/math/dispatch.js +101 -0
  193. package/output/math/geometry.d.ts +4 -0
  194. package/output/math/geometry.js +23 -0
  195. package/output/math/math.d.ts +59 -19
  196. package/output/math/math.js +244 -100
  197. package/output/math/trig.js +4 -4
  198. package/output/math/utils.d.ts +6 -0
  199. package/output/math/utils.js +39 -0
  200. package/output/solve/classes/PolynomialSolver.d.ts +33 -14
  201. package/output/solve/classes/PolynomialSolver.js +267 -67
  202. package/output/solve/classes/SolutionSet.d.ts +20 -1
  203. package/output/solve/classes/SolutionSet.js +82 -5
  204. package/output/solve/dispatch.d.ts +1 -0
  205. package/output/solve/dispatch.js +13 -0
  206. package/output/solve/linsolve.d.ts +2 -0
  207. package/output/solve/linsolve.js +13 -5
  208. package/output/solve/solve.d.ts +10 -0
  209. package/output/solve/solve.js +128 -20
  210. package/output/solve/solveSystem.d.ts +1 -1
  211. package/output/solve/solveSystem.js +8 -32
  212. package/output/solve/utils.d.ts +2 -1
  213. package/output/solve/utils.js +18 -22
  214. package/output/utils/array.d.ts +1 -1
  215. package/output/utils/debug.js +2 -1
  216. package/package.json +22 -38
  217. package/dist/parser.js +0 -2
  218. package/dist/parser.js.LICENSE.txt +0 -7
  219. package/docs-data/parser-functions.json +0 -1960
  220. package/output/algebra/algorithms/factor.d.ts +0 -3
  221. package/output/algebra/algorithms/factor.js +0 -5
  222. package/output/algebra/algorithms/factorMultivariate.d.ts +0 -23
  223. package/output/algebra/algorithms/factorMultivariate.js +0 -2393
  224. package/output/algebra/algorithms/factorUnivariate.d.ts +0 -72
  225. package/output/algebra/algorithms/factorUnivariate.js +0 -1072
  226. package/output/algebra/algorithms/gcd.d.ts +0 -22
  227. package/output/algebra/algorithms/gcd.js +0 -690
  228. package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +0 -137
  229. package/output/algebra/algorithms/multiPoly/MultiPoly.js +0 -346
  230. package/output/algebra/algorithms/poly.d.ts +0 -228
  231. package/output/algebra/algorithms/poly.js +0 -1299
  232. package/output/algebra/algorithms/rational.d.ts +0 -17
  233. package/output/algebra/algorithms/rational.js +0 -115
  234. package/output/core/adapters.js +0 -40
  235. package/output/core/classes/parser/operations/comma.d.ts +0 -7
  236. package/output/core/classes/parser/operations/comma.js +0 -11
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Registers the complete Nerdamer parser function surface.
3
+ *
4
+ * Core parser modules do not import higher-level mathematical domains. Entry points
5
+ * and consumers that require the complete Nerdamer notation surface call this registration function.
6
+ */
7
+ export declare function registerNerdamerFunctions(): void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerNerdamerFunctions = registerNerdamerFunctions;
4
+ const dispatch_1 = require("../algebra/dispatch");
5
+ const dispatch_2 = require("../calculus/dispatch");
6
+ const dispatch_3 = require("../math/dispatch");
7
+ const dispatch_4 = require("../solve/dispatch");
8
+ const dispatch_5 = require("./classes/assumption/dispatch");
9
+ const dispatch_6 = require("./classes/matrix/dispatch");
10
+ const dispatch_7 = require("./classes/parser/scripting/dispatch");
11
+ const dispatch_8 = require("./classes/polynomial/dispatch");
12
+ const dispatch_9 = require("./classes/vector/dispatch");
13
+ const complex_dispatch_1 = require("./functions/complex.dispatch");
14
+ /**
15
+ * Registers the complete Nerdamer parser function surface.
16
+ *
17
+ * Core parser modules do not import higher-level mathematical domains. Entry points
18
+ * and consumers that require the complete Nerdamer notation surface call this registration function.
19
+ */
20
+ function registerNerdamerFunctions() {
21
+ (0, dispatch_7.loadScriptingFunctions)();
22
+ (0, dispatch_5.loadAssumptionFunctions)();
23
+ (0, dispatch_6.loadMatrixFunctions)();
24
+ (0, dispatch_9.loadVectorFunctions)();
25
+ (0, complex_dispatch_1.loadComplexFunctions)();
26
+ (0, dispatch_8.loadPolynomialFunctions)();
27
+ (0, dispatch_3.loadMathFunctions)();
28
+ (0, dispatch_1.loadAlgebraFunctions)();
29
+ (0, dispatch_2.loadCalculusFunctions)();
30
+ (0, dispatch_4.loadSolveFunctions)();
31
+ }
@@ -45,7 +45,7 @@ export declare function convert(numStr: string): [bigint, bigint];
45
45
  * @param n
46
46
  * @returns -1 if negative and 1 for positive and 0 for zero
47
47
  */
48
- export declare function sign(n: bigint): 0 | 1 | -1;
48
+ export declare function sign(n: bigint): 1 | 0 | -1;
49
49
  /**
50
50
  * Checks if a bigint is an even number
51
51
  *
@@ -53,6 +53,12 @@ export declare function sign(n: bigint): 0 | 1 | -1;
53
53
  * @returns
54
54
  */
55
55
  export declare function isEven(n: bigint): boolean;
56
+ /**
57
+ * Returns the floor of the exact square root of a non-negative bigint.
58
+ */
59
+ export declare function integerSquareRoot(value: bigint): bigint;
60
+ /** Returns the least bigint whose square is at least value. */
61
+ export declare function ceilIntegerSquareRoot(value: bigint): bigint;
56
62
  /**
57
63
  * Computes the nth Fibonacci number exactly using fast doubling.
58
64
  *
@@ -74,6 +80,12 @@ export declare const factorial: (n: number | bigint) => bigint;
74
80
  * @returns
75
81
  */
76
82
  export declare function mod(a: bigint, b: bigint): bigint;
83
+ /**
84
+ * Raises a bigint base to a non-negative bigint exponent modulo a positive modulus.
85
+ *
86
+ * Binary exponentiation keeps every intermediate value in bigint modular arithmetic.
87
+ */
88
+ export declare function powMod(base: bigint, exponent: bigint, modulus: bigint): bigint;
77
89
  /**
78
90
  * Finds the multiplicative inverse of a modulo m.
79
91
  *
@@ -9,8 +9,11 @@ exports.simplifyRatio = simplifyRatio;
9
9
  exports.convert = convert;
10
10
  exports.sign = sign;
11
11
  exports.isEven = isEven;
12
+ exports.integerSquareRoot = integerSquareRoot;
13
+ exports.ceilIntegerSquareRoot = ceilIntegerSquareRoot;
12
14
  exports.fibonacci = fibonacci;
13
15
  exports.mod = mod;
16
+ exports.powMod = powMod;
14
17
  exports.invMod = invMod;
15
18
  exports.productInRange = productInRange;
16
19
  exports.max = max;
@@ -18,6 +21,7 @@ exports.min = min;
18
21
  exports.recoverCoeffsZ = recoverCoeffsZ;
19
22
  exports.binom = binom;
20
23
  exports.bigintLCM = bigintLCM;
24
+ const errors_1 = require("../../errors");
21
25
  const string_1 = require("../string");
22
26
  const utils_1 = require("../utils");
23
27
  /**
@@ -128,6 +132,30 @@ function sign(n) {
128
132
  function isEven(n) {
129
133
  return n % 2n === 0n;
130
134
  }
135
+ /**
136
+ * Returns the floor of the exact square root of a non-negative bigint.
137
+ */
138
+ function integerSquareRoot(value) {
139
+ if (value < 0n) {
140
+ throw new RangeError((0, errors_1.message)('integerSqrtNonnegative'));
141
+ }
142
+ if (value < 2n) {
143
+ return value;
144
+ }
145
+ let root = 1n << ((BigInt(value.toString(2).length) + 1n) >> 1n);
146
+ while (true) {
147
+ const next = (root + value / root) >> 1n;
148
+ if (next >= root) {
149
+ return root;
150
+ }
151
+ root = next;
152
+ }
153
+ }
154
+ /** Returns the least bigint whose square is at least value. */
155
+ function ceilIntegerSquareRoot(value) {
156
+ const root = integerSquareRoot(value);
157
+ return root * root === value ? root : root + 1n;
158
+ }
131
159
  /**
132
160
  * Computes the nth Fibonacci number exactly using fast doubling.
133
161
  *
@@ -183,7 +211,7 @@ exports.factorial = (function () {
183
211
  n = Number(n);
184
212
  }
185
213
  if (n < 0) {
186
- throw new RangeError('Factorial is undefined for negative integers.');
214
+ throw new RangeError((0, errors_1.message)('factorialNegativeUndefined'));
187
215
  }
188
216
  // If there's a cached version return that instead
189
217
  if (typeof factorialCache[n] != 'undefined') {
@@ -219,6 +247,30 @@ function mod(a, b) {
219
247
  }
220
248
  return retval;
221
249
  }
250
+ /**
251
+ * Raises a bigint base to a non-negative bigint exponent modulo a positive modulus.
252
+ *
253
+ * Binary exponentiation keeps every intermediate value in bigint modular arithmetic.
254
+ */
255
+ function powMod(base, exponent, modulus) {
256
+ if (modulus <= 0n) {
257
+ throw new RangeError((0, errors_1.message)('modularExponentiationPositiveModulus'));
258
+ }
259
+ if (exponent < 0n) {
260
+ throw new RangeError((0, errors_1.message)('modularExponentiationNonnegativeExponent'));
261
+ }
262
+ let result = 1n % modulus;
263
+ let factor = mod(base, modulus);
264
+ let power = exponent;
265
+ while (power > 0n) {
266
+ if (power % 2n === 1n) {
267
+ result = (result * factor) % modulus;
268
+ }
269
+ factor = (factor * factor) % modulus;
270
+ power /= 2n;
271
+ }
272
+ return result;
273
+ }
222
274
  /**
223
275
  * Finds the multiplicative inverse of a modulo m.
224
276
  *
@@ -275,7 +327,7 @@ function max(...args) {
275
327
  // Math.max() for Number returns -Infinity for empty lists,
276
328
  // but BigInt can't represent Infinity, so throwing an error or
277
329
  // handling as per application logic is necessary.
278
- throw new Error('maxBigInt() requires at least one argument');
330
+ throw new Error((0, errors_1.message)('maxBigIntRequiresArgument'));
279
331
  }
280
332
  let max = args[0];
281
333
  for (let i = 1; i < args.length; i++) {
@@ -294,7 +346,7 @@ function min(...args) {
294
346
  if (args.length === 0) {
295
347
  // Math.min() returns Infinity for no arguments, but BigInt cannot represent Infinity.
296
348
  // It's often better to throw an error or handle the empty case explicitly.
297
- throw new Error('Min of empty list is not defined for BigInt.');
349
+ throw new Error((0, errors_1.message)('minBigIntEmpty'));
298
350
  }
299
351
  let min = args[0];
300
352
  for (let i = 1; i < args.length; i++) {
@@ -347,7 +399,7 @@ function recoverCoeffsZ(num, primes) {
347
399
  */
348
400
  function binom(n, k) {
349
401
  if (n < 0n) {
350
- throw new RangeError('binomBigInt: n must be non-negative');
402
+ throw new RangeError((0, errors_1.message)('binomBigIntNonnegativeN'));
351
403
  }
352
404
  if (k < 0n || k > n) {
353
405
  return 0n;
@@ -7,6 +7,8 @@ export type factorCountType = Record<string, bigint>;
7
7
  * @returns
8
8
  */
9
9
  export declare function isPrimeBig(num: bigint): boolean;
10
+ /** Returns the least prime greater than or equal to start. */
11
+ export declare function nextPrimeBig(start: bigint): bigint;
10
12
  /**
11
13
  * Fast prime factorization using trial division with optimizations
12
14
  */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPrimeBig = isPrimeBig;
4
+ exports.nextPrimeBig = nextPrimeBig;
4
5
  exports.trialDivisionBig = trialDivisionBig;
5
6
  exports.pollardRhoBig = pollardRhoBig;
6
7
  exports.primeFactorsBig = primeFactorsBig;
@@ -73,18 +74,6 @@ function isPrimeBig(num) {
73
74
  r++;
74
75
  d /= 2n;
75
76
  }
76
- const modPow = (base, exp, mod) => {
77
- let result = 1n;
78
- base %= mod;
79
- while (exp > 0n) {
80
- if (exp % 2n === 1n) {
81
- result = (result * base) % mod;
82
- }
83
- base = (base * base) % mod;
84
- exp /= 2n;
85
- }
86
- return result;
87
- };
88
77
  // These witnesses are deterministic for every unsigned 64-bit integer. For larger
89
78
  // BigInts they remain a stable probable-prime test rather than a randomized result.
90
79
  const witnesses = num < 18446744073709551616n
@@ -95,7 +84,7 @@ function isPrimeBig(num) {
95
84
  if (a < 2n) {
96
85
  continue;
97
86
  }
98
- let x = modPow(a, d, num);
87
+ let x = (0, bigint_1.powMod)(a, d, num);
99
88
  if (x === 1n || x === num - 1n) {
100
89
  continue;
101
90
  }
@@ -113,6 +102,17 @@ function isPrimeBig(num) {
113
102
  }
114
103
  return true;
115
104
  }
105
+ /** Returns the least prime greater than or equal to start. */
106
+ function nextPrimeBig(start) {
107
+ let candidate = start <= 2n ? 2n : start;
108
+ if (candidate > 2n && candidate % 2n === 0n) {
109
+ candidate++;
110
+ }
111
+ while (!isPrimeBig(candidate)) {
112
+ candidate += candidate === 2n ? 1n : 2n;
113
+ }
114
+ return candidate;
115
+ }
116
116
  /**
117
117
  * Fast prime factorization using trial division with optimizations
118
118
  */
@@ -69,6 +69,12 @@ exports.definitions = {
69
69
  min: [(...args) => Math.min(...args)],
70
70
  avg: [(...args) => args.reduce((total, value) => total + value, 0) / args.length],
71
71
  heaviside: [numeric_1.heaviside],
72
+ step: [x => (Number.isNaN(x) ? NaN : x < 0 ? 0 : 1)],
73
+ rect: [x => {
74
+ const a = Math.abs(x);
75
+ return a < 0.5 ? 1 : a === 0.5 ? 0.5 : 0;
76
+ }],
77
+ tri: [x => Math.max(1 - Math.abs(x), 0)],
72
78
  // Complex-component helpers are limited to real JavaScript-number inputs. This is
73
79
  // faithful to buildFunction's scalar runtime function without pretending to provide
74
80
  // a JavaScript-number representation for genuinely complex values.
@@ -56,7 +56,7 @@ export declare function arg(x: ExpressionInput): Expression;
56
56
  * Distributes over sums, products, integer powers, and powers whose
57
57
  * constant base is known not to lie on the principal logarithm's branch cut.
58
58
  *
59
- * @param expr - The expression to conjugate
59
+ * @param x - The expression to conjugate
60
60
  * @returns The complex conjugate of the expression
61
61
  *
62
62
  * @example
@@ -76,7 +76,7 @@ export declare function conjugate(x: ExpressionInput): Expression;
76
76
  *
77
77
  * Useful for branch cut decisions in sqrt, log, and power simplification.
78
78
  *
79
- * @param expr - The expression to evaluate the complex sign of
79
+ * @param x - The expression to evaluate the complex sign of
80
80
  * @returns 1, -1, 0, or an unevaluated csgn expression
81
81
  *
82
82
  * @example
@@ -0,0 +1 @@
1
+ export declare function loadComplexFunctions(): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadComplexFunctions = loadComplexFunctions;
4
+ const dispatch_1 = require("../dispatch");
5
+ const complex_1 = require("./complex");
6
+ function loadComplexFunctions() {
7
+ Object.assign(dispatch_1.mathFunctionRegistry, {
8
+ imagpart: (0, dispatch_1.systemFunction)({ fn: complex_1.imagPart, minArgs: 1, maxArgs: 1, distElWise: true }),
9
+ realpart: (0, dispatch_1.systemFunction)({ fn: complex_1.realPart, minArgs: 1, maxArgs: 1, distElWise: true }),
10
+ polarform: (0, dispatch_1.systemFunction)({ fn: complex_1.polarForm, minArgs: 1, maxArgs: 1, distElWise: true }),
11
+ rectform: (0, dispatch_1.systemFunction)({ fn: complex_1.rectForm, minArgs: 1, maxArgs: 1, distElWise: true }),
12
+ arg: (0, dispatch_1.systemFunction)({ fn: complex_1.arg, minArgs: 1, maxArgs: 1, distElWise: true }),
13
+ csgn: (0, dispatch_1.systemFunction)({ fn: complex_1.csgn, minArgs: 1, maxArgs: 1, distElWise: true }),
14
+ conjugate: (0, dispatch_1.systemFunction)({ fn: complex_1.conjugate, minArgs: 1, maxArgs: 1, distElWise: true }),
15
+ });
16
+ }
@@ -60,12 +60,12 @@ function realPart(a) {
60
60
  // other functions without complex inputs, and keep explicitly complex
61
61
  // function components symbolic rather than treating them as zero.
62
62
  else if (x.isComplexComponentFunction()) {
63
- retval = new Expression_1.Expression(x);
63
+ retval = x.copy();
64
64
  }
65
65
  else if (x.isFunction()) {
66
66
  retval = x.isComplex()
67
67
  ? Expression_1.Expression.toFunction(constants_1.REALPART, [x])
68
- : new Expression_1.Expression(x);
68
+ : x.copy();
69
69
  }
70
70
  // Decompose products through their complex factors while preserving real
71
71
  // factors as an outer scale.
@@ -111,13 +111,13 @@ function realPart(a) {
111
111
  else if (x.isConstant() ||
112
112
  (x.isVAR() && !x.isI()) ||
113
113
  (x.isProduct() && !x.isComplex())) {
114
- retval = new Expression_1.Expression(a);
114
+ retval = a.copy();
115
115
  }
116
116
  // Deal with x+1, y+y^2, ...
117
117
  else if (x.isSum()) {
118
118
  // Check if the sum has a power attached - if so, treat as single term
119
119
  if (!x.getPower().isOne()) {
120
- retval = new Expression_1.Expression(a);
120
+ retval = a.copy();
121
121
  }
122
122
  else {
123
123
  retval = (0, shortcuts_1.zero)();
@@ -296,7 +296,7 @@ function polarForm(x) {
296
296
  let retval;
297
297
  if (x.isNUM() || (x.isI() && x.isLinear())) {
298
298
  // The polarform of a number is just the number
299
- retval = new Expression_1.Expression(x);
299
+ retval = x.copy();
300
300
  }
301
301
  else {
302
302
  // Get r and theta. Theta will come back as (atan(x) or a*pi/n)
@@ -390,7 +390,7 @@ function arg(x) {
390
390
  * Distributes over sums, products, integer powers, and powers whose
391
391
  * constant base is known not to lie on the principal logarithm's branch cut.
392
392
  *
393
- * @param expr - The expression to conjugate
393
+ * @param x - The expression to conjugate
394
394
  * @returns The complex conjugate of the expression
395
395
  *
396
396
  * @example
@@ -452,7 +452,7 @@ function conjugate(x) {
452
452
  *
453
453
  * Useful for branch cut decisions in sqrt, log, and power simplification.
454
454
  *
455
- * @param expr - The expression to evaluate the complex sign of
455
+ * @param x - The expression to evaluate the complex sign of
456
456
  * @returns 1, -1, 0, or an unevaluated csgn expression
457
457
  *
458
458
  * @example
@@ -14,6 +14,7 @@ exports.Chi = Chi;
14
14
  exports.Ei = Ei;
15
15
  exports.Li = Li;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const errors_1 = require("../errors");
17
18
  const bigint_1 = require("./bigint/bigint");
18
19
  /*
19
20
  * TODO: Currently only up to a 100 digits. This will need to be calculated in the future.
@@ -73,7 +74,7 @@ function erf(x) {
73
74
  sum = result;
74
75
  k++;
75
76
  if (k > max) {
76
- throw new Error('erf not converging. Exiting!');
77
+ throw new Error((0, errors_1.message)('erfConvergenceFailed'));
77
78
  }
78
79
  }
79
80
  let retval = decimal_js_1.default.min(twoOverSqrtPi.times(sum), 1);
@@ -326,7 +326,7 @@ function expand(x) {
326
326
  x = unwrap(x);
327
327
  if (isExpandable(x)) {
328
328
  if (x.isNUM() || x.isVAR()) {
329
- retval = new Expression_1.Expression(x);
329
+ retval = x.copy();
330
330
  }
331
331
  else {
332
332
  // At the very least the multiplier must be distributed along the expression
@@ -370,7 +370,7 @@ function expand(x) {
370
370
  }
371
371
  }
372
372
  else {
373
- retval = new Expression_1.Expression(x);
373
+ retval = x.copy();
374
374
  }
375
375
  return retval;
376
376
  }
@@ -65,7 +65,7 @@ export declare function LCM(...args: number[]): number;
65
65
  /** Computes the modular multiplicative inverse for integer JavaScript numbers. */
66
66
  export declare function modInv(a: number, p: number): number;
67
67
  /** Returns `1` for a prime safe integer and `0` otherwise. */
68
- export declare function isPrime(x: number): 0 | 1;
68
+ export declare function isPrime(x: number): 1 | 0;
69
69
  /** Numeric half-maximum convention for the Heaviside step function. */
70
70
  export declare function heaviside(x: number): number;
71
71
  /**
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.scientificToDecimal = scientificToDecimal;
4
4
  exports.decimalSplit = decimalSplit;
5
5
  exports.format = format;
6
+ const errors_1 = require("../errors");
6
7
  /**
7
8
  * Removes the minus sign from the beginning of the string
8
9
  *
@@ -67,7 +68,7 @@ function scientificToDecimal(str) {
67
68
  function decimalSplit(str) {
68
69
  const parts = str.split('.');
69
70
  if (parts.length > 2) {
70
- throw new SyntaxError(`Invalid decimal value: ${str}`);
71
+ throw new SyntaxError((0, errors_1.message)('invalidDecimalValue', { value: str }));
71
72
  }
72
73
  if (parts.length === 1) {
73
74
  parts.push('');
@@ -29,7 +29,7 @@ function prodSubst(expression, value, withValue, includeNumeric) {
29
29
  // First check the multipliers. This has to be an integer
30
30
  const m = expression.getMultiplier().div(value.getMultiplier());
31
31
  if (!m.isInteger() && !Settings_1.Settings.ALLOW_RAT_SUBS) {
32
- retval = new Expression_1.Expression(expression);
32
+ retval = expression.copy();
33
33
  }
34
34
  else {
35
35
  let power;
@@ -227,7 +227,7 @@ function subst(expression, value, withValue, includeNumeric = false) {
227
227
  }
228
228
  else if (expression.isFunction()) {
229
229
  if (expression.value === value.value) {
230
- retval = new Expression_1.Expression(withValue);
230
+ retval = withValue.copy();
231
231
  }
232
232
  else {
233
233
  retval = Expression_1.Expression.Function(expression.name);
@@ -439,21 +439,29 @@ function uUnSub(expression, map) {
439
439
  function uSubConstants(expression, map) {
440
440
  map ??= {};
441
441
  const constants = new Set();
442
- // forEveryElement returns immediately for a VAR root. Check the root first so standalone
443
- // mathematical constants and their powers are promoted just like the same constants nested
444
- // inside sums and products.
445
- if (expression.isVAR() && (expression.isConstant() || expression.isI())) {
446
- constants.add(expression.value);
447
- }
448
- expression.forEveryElement(e => {
442
+ function collectConstants(current) {
449
443
  // The imaginary unit is a mathematical constant, but isConstant() only recognizes parser
450
444
  // constants such as pi and e. Promote i here as well so polynomial factorization does not
451
445
  // treat it as an ordinary polynomial variable.
452
- if (e.isVAR() && (e.isConstant() || e.isI())) {
453
- constants.add(e.value);
446
+ if (current.isVAR() && (current.isConstant() || current.isI())) {
447
+ constants.add(current.value);
454
448
  }
455
- return e;
456
- });
449
+ if (current.args) {
450
+ for (const argument of current.args) {
451
+ collectConstants(argument);
452
+ }
453
+ }
454
+ if (current.elements) {
455
+ for (const element of Object.values(current.elements)) {
456
+ collectConstants(element);
457
+ }
458
+ }
459
+ if (current.isEXP()) {
460
+ collectConstants(current.getBase());
461
+ collectConstants(current.getPower());
462
+ }
463
+ }
464
+ collectConstants(expression);
457
465
  for (const c of constants) {
458
466
  [expression, map] = uSub(expression, (0, helpers_1._)(c), map);
459
467
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Registers the function surface supplied by the parser package.
3
+ *
4
+ * Algebra, calculus, and solving are higher-level CAS domains and are composed by
5
+ * the full package rather than the parser package.
6
+ */
7
+ export declare function loadParserFunctions(): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadParserFunctions = loadParserFunctions;
4
+ const dispatch_1 = require("../math/dispatch");
5
+ const dispatch_2 = require("./classes/assumption/dispatch");
6
+ const dispatch_3 = require("./classes/matrix/dispatch");
7
+ const dispatch_4 = require("./classes/parser/scripting/dispatch");
8
+ const dispatch_5 = require("./classes/polynomial/dispatch");
9
+ const dispatch_6 = require("./classes/vector/dispatch");
10
+ const complex_dispatch_1 = require("./functions/complex.dispatch");
11
+ /**
12
+ * Registers the function surface supplied by the parser package.
13
+ *
14
+ * Algebra, calculus, and solving are higher-level CAS domains and are composed by
15
+ * the full package rather than the parser package.
16
+ */
17
+ function loadParserFunctions() {
18
+ (0, dispatch_4.loadScriptingFunctions)();
19
+ (0, dispatch_2.loadAssumptionFunctions)();
20
+ (0, dispatch_3.loadMatrixFunctions)();
21
+ (0, dispatch_6.loadVectorFunctions)();
22
+ (0, dispatch_5.loadPolynomialFunctions)();
23
+ (0, complex_dispatch_1.loadComplexFunctions)();
24
+ (0, dispatch_1.loadMathFunctions)();
25
+ }