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
@@ -4,13 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.sqrt = sqrt;
7
+ exports.scientific = scientific;
7
8
  exports.nthroot = nthroot;
9
+ exports.radians = radians;
10
+ exports.degrees = degrees;
11
+ exports.log10 = log10;
8
12
  exports.cbrt = cbrt;
9
13
  exports.parens = parens;
10
14
  exports.fibonacci = fibonacci;
11
15
  exports.factorial = factorial;
12
16
  exports.doubleFactorial = doubleFactorial;
13
17
  exports.heaviside = heaviside;
18
+ exports.step = step;
19
+ exports.rect = rect;
20
+ exports.tri = tri;
14
21
  exports.dirac = dirac;
15
22
  exports.numeric = numeric;
16
23
  exports.round = round;
@@ -20,6 +27,8 @@ exports.ceiling = ceiling;
20
27
  exports.abs = abs;
21
28
  exports.modInv = modInv;
22
29
  exports.mod = mod;
30
+ exports.gammaIncomplete = gammaIncomplete;
31
+ exports.gammaIncompleteLower = gammaIncompleteLower;
23
32
  exports.gamma = gamma;
24
33
  exports.erfc = erfc;
25
34
  exports.erf = erf;
@@ -37,7 +46,6 @@ exports.exp = exp;
37
46
  exports.matrix = matrix;
38
47
  exports.sum = sum;
39
48
  exports.product = product;
40
- exports.defint = defint;
41
49
  exports.contains = contains;
42
50
  const decimal_js_1 = __importDefault(require("decimal.js"));
43
51
  const assume_1 = require("../core/classes/assumption/assume");
@@ -58,12 +66,11 @@ const primeFactor_1 = require("../core/functions/bigint/primeFactor");
58
66
  const complex_1 = require("../core/functions/complex");
59
67
  const decimal_1 = require("../core/functions/decimal");
60
68
  const Settings_1 = require("../core/Settings");
61
- const defintNative_1 = require("./defint/defintNative");
62
69
  const geometry_1 = require("./geometry");
63
70
  const trig_1 = require("./trig");
64
71
  const utils_3 = require("./utils");
65
- const NATIVE_DEFINITE_INTEGRATION_PRECISION = 17;
66
72
  const POSITIVE_INTEGER_PRECISION = 'a positive integer precision';
73
+ const DEFAULT_SCIENTIFIC_SIGNIFICANT_DIGITS = 10;
67
74
  /**
68
75
  * Computes the square root of an expression. Equivalent to raising to the power of 1/2.
69
76
  * Nested square roots are automatically simplified (e.g. `sqrt(sqrt(x))` becomes `x^(1/4)`).
@@ -109,6 +116,24 @@ function sqrt(x) {
109
116
  }
110
117
  return retval;
111
118
  }
119
+ /**
120
+ * Returns a copy that renders numeric values in scientific notation.
121
+ *
122
+ * The legacy implementation stored a formatting flag that its formatter did not
123
+ * consume. Nerdamer 2.0 keeps the expression exact and records the requested number
124
+ * of significant digits for formatting. Precision validation follows decimal.js and accepts
125
+ * integer values from 1 through 1e9.
126
+ */
127
+ function scientific(x, significantDigits = DEFAULT_SCIENTIFIC_SIGNIFICANT_DIGITS) {
128
+ const digits = Expression_1.Expression.create(significantDigits);
129
+ const requestedDigits = digits.isNUM() && digits.isInteger()
130
+ ? Number(digits.getMultiplier().numerator)
131
+ : Number.NaN;
132
+ const precision = (0, Rational_1.validateScientificSignificantDigits)(requestedDigits, digits.text());
133
+ const retval = Expression_1.Expression.create(x, undefined, true);
134
+ retval.scientific = precision;
135
+ return retval;
136
+ }
112
137
  /**
113
138
  * Computes the nth root of an expression as its principal power.
114
139
  *
@@ -119,6 +144,18 @@ function sqrt(x) {
119
144
  function nthroot(x, n) {
120
145
  return (0, power_1.power)(Expression_1.Expression.create(x), (0, shortcuts_1.one)().div(Expression_1.Expression.create(n)));
121
146
  }
147
+ /** Converts degrees to radians exactly. */
148
+ function radians(x) {
149
+ return Expression_1.Expression.create(x).times(Expression_1.Expression.Pi()).div(Expression_1.Expression.create(180));
150
+ }
151
+ /** Converts radians to degrees exactly. */
152
+ function degrees(x) {
153
+ return Expression_1.Expression.create(x).times(Expression_1.Expression.create(180)).div(Expression_1.Expression.Pi());
154
+ }
155
+ /** Returns the base-10 logarithm using the ordinary logarithm implementation. */
156
+ function log10(x) {
157
+ return log(x, 10);
158
+ }
122
159
  /**
123
160
  * Computes the cube root of an expression.
124
161
  *
@@ -162,7 +199,7 @@ function cbrt(x) {
162
199
  const d = xe.getMultiplier().toDecimal();
163
200
  const oneThird = new decimal_js_1.default(1).div(3);
164
201
  const r = d.isNeg() ? d.abs().pow(oneThird).neg() : d.pow(oneThird);
165
- return new Expression_1.Expression(r);
202
+ return Expression_1.Expression.create(r);
166
203
  }
167
204
  if (xe.isComplex()) {
168
205
  const re = xe.realPart();
@@ -199,7 +236,7 @@ function cbrt(x) {
199
236
  * ```
200
237
  */
201
238
  function parens(x) {
202
- return Expression_1.Expression.toFunction(constants_1.WRAP, [x]);
239
+ return Expression_1.Expression.toFunction(constants_1.WRAP, [Expression_1.Expression.create(x)]);
203
240
  }
204
241
  /**
205
242
  * Computes the Fibonacci number for an integer index.
@@ -224,7 +261,7 @@ function fibonacci(x) {
224
261
  retval = Expression_1.Expression.Number((0, bigint_1.fibonacci)(x.getMultiplier().numerator));
225
262
  }
226
263
  else {
227
- retval = Expression_1.Expression.toFunction(constants_2.FIB, [new Expression_1.Expression(x)]);
264
+ retval = Expression_1.Expression.toFunction(constants_2.FIB, [Expression_1.Expression.create(x)]);
228
265
  }
229
266
  return retval;
230
267
  }
@@ -268,7 +305,7 @@ function factorial(x) {
268
305
  if (x.isNUM() && m.denominator === 2n) {
269
306
  const sign = m.sign();
270
307
  m = m.abs();
271
- const n = new Expression_1.Expression(m.numerator - 1n).div((0, shortcuts_1.two)());
308
+ const n = Expression_1.Expression.create(m.numerator - 1n).div((0, shortcuts_1.two)());
272
309
  const sqrtPi = sqrt(Expression_1.Expression.Pi());
273
310
  if (sign === -1) {
274
311
  retval = (0, shortcuts_1.four)()
@@ -285,7 +322,7 @@ function factorial(x) {
285
322
  }
286
323
  }
287
324
  else {
288
- retval = Expression_1.Expression.toFunction(constants_2.FACTORIAL, [new Expression_1.Expression(x)]);
325
+ retval = Expression_1.Expression.toFunction(constants_2.FACTORIAL, [Expression_1.Expression.create(x)]);
289
326
  }
290
327
  }
291
328
  return retval;
@@ -329,7 +366,7 @@ function doubleFactorial(x) {
329
366
  for (let i = 1; i <= n; i++) {
330
367
  let q = (0, shortcuts_1.two)().times(i);
331
368
  if (!even) {
332
- q = q.minus(1);
369
+ q = q.minus((0, shortcuts_1.one)());
333
370
  }
334
371
  r = r.times(q);
335
372
  }
@@ -343,12 +380,12 @@ function doubleFactorial(x) {
343
380
  .minus((0, trig_1.cos)(pi.times(x)))
344
381
  .div((0, shortcuts_1.four)()));
345
382
  const b = pi.pow((0, trig_1.cos)(pi.times(x)).minus((0, shortcuts_1.one)()).div((0, shortcuts_1.four)()));
346
- const c = gamma(x.div((0, shortcuts_1.two)()).plus(1));
383
+ const c = gamma(x.div((0, shortcuts_1.two)()).plus((0, shortcuts_1.one)()));
347
384
  retval = a.times(b).times(c);
348
385
  }
349
386
  }
350
387
  else {
351
- retval = Expression_1.Expression.toFunction(constants_1.DOUBLE_FACTORIAL, [new Expression_1.Expression(x)]);
388
+ retval = Expression_1.Expression.toFunction(constants_1.DOUBLE_FACTORIAL, [Expression_1.Expression.create(x)]);
352
389
  }
353
390
  return retval;
354
391
  }
@@ -392,20 +429,71 @@ function heaviside(x) {
392
429
  retval = (0, shortcuts_1.half)();
393
430
  }
394
431
  }
395
- else if (useAssumptions && x.gt(0)) {
432
+ else if (useAssumptions && x.gt((0, shortcuts_1.zero)())) {
396
433
  retval = (0, shortcuts_1.one)();
397
434
  }
398
- else if (useAssumptions && x.lt(0)) {
435
+ else if (useAssumptions && x.lt((0, shortcuts_1.zero)())) {
399
436
  retval = (0, shortcuts_1.zero)();
400
437
  }
401
- else if (useAssumptions && x.gte(0) && x.lte(0)) {
438
+ else if (useAssumptions && x.gte((0, shortcuts_1.zero)()) && x.lte((0, shortcuts_1.zero)())) {
402
439
  retval = (0, shortcuts_1.half)();
403
440
  }
404
441
  else {
405
- retval = Expression_1.Expression.toFunction(constants_1.HEAVISIDE, [new Expression_1.Expression(x)]);
442
+ retval = Expression_1.Expression.toFunction(constants_1.HEAVISIDE, [Expression_1.Expression.create(x)]);
406
443
  }
407
444
  return retval;
408
445
  }
446
+ /**
447
+ * Legacy unit-step function. Unlike {@link heaviside}, the value at zero is 1.
448
+ */
449
+ function step(x) {
450
+ x = Expression_1.Expression.create(x);
451
+ const useAssumptions = !x.isConstant() && !x.isComplex() && (0, assume_1.hasAssumptions)();
452
+ if (x.isPosInf() || x.isNegInf()) {
453
+ return x.isNegInf() ? (0, shortcuts_1.zero)() : (0, shortcuts_1.one)();
454
+ }
455
+ if (x.isNUM()) {
456
+ return x.sign() < 0 ? (0, shortcuts_1.zero)() : (0, shortcuts_1.one)();
457
+ }
458
+ if (useAssumptions && x.lt((0, shortcuts_1.zero)())) {
459
+ return (0, shortcuts_1.zero)();
460
+ }
461
+ if (useAssumptions && x.gte((0, shortcuts_1.zero)())) {
462
+ return (0, shortcuts_1.one)();
463
+ }
464
+ return Expression_1.Expression.toFunction('step', [x]);
465
+ }
466
+ /**
467
+ * Rectangular pulse with unit width centered at zero.
468
+ *
469
+ * Returns 1 for |x| < 1/2, 1/2 at |x| = 1/2, and 0 for |x| > 1/2.
470
+ */
471
+ function rect(x) {
472
+ const input = Expression_1.Expression.create(x);
473
+ const magnitude = abs(input);
474
+ if (magnitude.lt((0, shortcuts_1.half)())) {
475
+ return (0, shortcuts_1.one)();
476
+ }
477
+ if (magnitude.eq((0, shortcuts_1.half)())) {
478
+ return (0, shortcuts_1.half)();
479
+ }
480
+ if (magnitude.gt((0, shortcuts_1.half)())) {
481
+ return (0, shortcuts_1.zero)();
482
+ }
483
+ return Expression_1.Expression.toFunction('rect', [input]);
484
+ }
485
+ /** Triangular pulse: max(1 - |x|, 0) when the comparison can be resolved. */
486
+ function tri(x) {
487
+ const input = Expression_1.Expression.create(x);
488
+ const magnitude = abs(input);
489
+ if (magnitude.lt((0, shortcuts_1.one)())) {
490
+ return (0, shortcuts_1.one)().minus(magnitude);
491
+ }
492
+ if (magnitude.gte((0, shortcuts_1.one)())) {
493
+ return (0, shortcuts_1.zero)();
494
+ }
495
+ return Expression_1.Expression.toFunction('tri', [input]);
496
+ }
409
497
  /**
410
498
  * Computes the Dirac delta function (distribution).
411
499
  *
@@ -434,17 +522,17 @@ function dirac(x) {
434
522
  if (x.isZero()) {
435
523
  // Dirac delta at zero is technically infinite, but we return
436
524
  // the symbolic form to avoid misleading numeric results.
437
- retval = Expression_1.Expression.toFunction(constants_1.DIRAC, [new Expression_1.Expression(x)]);
525
+ retval = Expression_1.Expression.toFunction(constants_1.DIRAC, [Expression_1.Expression.create(x)]);
438
526
  }
439
527
  else {
440
528
  retval = (0, shortcuts_1.zero)();
441
529
  }
442
530
  }
443
- else if (useAssumptions && (x.gt(0) || x.lt(0))) {
531
+ else if (useAssumptions && (x.gt((0, shortcuts_1.zero)()) || x.lt((0, shortcuts_1.zero)()))) {
444
532
  retval = (0, shortcuts_1.zero)();
445
533
  }
446
534
  else {
447
- retval = Expression_1.Expression.toFunction(constants_1.DIRAC, [new Expression_1.Expression(x)]);
535
+ retval = Expression_1.Expression.toFunction(constants_1.DIRAC, [Expression_1.Expression.create(x)]);
448
536
  }
449
537
  return retval;
450
538
  }
@@ -545,7 +633,7 @@ function round(x, n) {
545
633
  const d = x.getMultiplier().toDecimal();
546
634
  const s = n.getMultiplier().toDecimal();
547
635
  const t = new decimal_js_1.default(10).pow(s);
548
- retval = new Expression_1.Expression(decimal_js_1.default.round(d.times(t)).div(t));
636
+ retval = Expression_1.Expression.create(decimal_js_1.default.round(d.times(t)).div(t));
549
637
  }
550
638
  else {
551
639
  retval = Expression_1.Expression.toFunction(constants_1.ROUND, [x, n]);
@@ -584,13 +672,13 @@ function sign(x) {
584
672
  else if (!(0, assume_1.hasAssumptions)()) {
585
673
  retval = Expression_1.Expression.toFunction(constants_1.SGN, [x]);
586
674
  }
587
- else if (x.gt(0)) {
675
+ else if (x.gt((0, shortcuts_1.zero)())) {
588
676
  retval = (0, shortcuts_1.one)();
589
677
  }
590
- else if (x.lt(0)) {
678
+ else if (x.lt((0, shortcuts_1.zero)())) {
591
679
  retval = (0, shortcuts_1.one)().neg();
592
680
  }
593
- else if (x.eq(0)) {
681
+ else if (x.eq((0, shortcuts_1.zero)())) {
594
682
  retval = (0, shortcuts_1.zero)();
595
683
  }
596
684
  else {
@@ -621,7 +709,7 @@ function floor(x) {
621
709
  else if (x.isNUM()) {
622
710
  // Convert n & x to a decimals
623
711
  const d = x.getMultiplier().toDecimal();
624
- retval = new Expression_1.Expression(d.floor());
712
+ retval = Expression_1.Expression.create(d.floor());
625
713
  }
626
714
  else {
627
715
  retval = Expression_1.Expression.toFunction(constants_1.FLOOR, [x]);
@@ -651,7 +739,7 @@ function ceiling(x) {
651
739
  else if (x.isNUM()) {
652
740
  // Convert n & x to a decimals
653
741
  const d = x.getMultiplier().toDecimal();
654
- retval = new Expression_1.Expression(d.ceil());
742
+ retval = Expression_1.Expression.create(d.ceil());
655
743
  }
656
744
  else {
657
745
  retval = Expression_1.Expression.toFunction(constants_1.CEIL, [x]);
@@ -696,11 +784,11 @@ function abs(x) {
696
784
  else if (x.isComplex()) {
697
785
  retval = (0, geometry_1.hypot)(x.realPart(), x.imagPart());
698
786
  }
699
- else if (useAssumptions && x.gte(0)) {
787
+ else if (useAssumptions && x.gte((0, shortcuts_1.zero)())) {
700
788
  retval = x;
701
789
  wrap = false;
702
790
  }
703
- else if (useAssumptions && x.lte(0)) {
791
+ else if (useAssumptions && x.lte((0, shortcuts_1.zero)())) {
704
792
  retval = x.neg();
705
793
  wrap = false;
706
794
  }
@@ -786,14 +874,42 @@ function modInv(a, p) {
786
874
  [t, tp] = [tp, t.minus(q.times(tp))];
787
875
  [r, rp] = [rp, r.minus(q.times(rp))];
788
876
  }
789
- if (r.gt(1)) {
877
+ if (r.gt((0, shortcuts_1.one)())) {
790
878
  throw new errors_1.MathError((0, errors_1.message)('noInverse'));
791
879
  }
792
880
  return mod(t, p);
793
881
  }
882
+ /**
883
+ * Rounds an exact rational quotient to the nearest integer, choosing the even
884
+ * integer when the value lies exactly halfway between two integers.
885
+ */
886
+ function roundRatioToNearestEven(numerator, denominator) {
887
+ const quotient = numerator / denominator;
888
+ const remainder = numerator % denominator;
889
+ const twiceRemainder = (0, bigint_1.abs)(remainder) * 2n;
890
+ const direction = BigInt((0, bigint_1.sign)(numerator));
891
+ if (twiceRemainder < denominator) {
892
+ return quotient;
893
+ }
894
+ if (twiceRemainder > denominator) {
895
+ return quotient + direction;
896
+ }
897
+ return (0, bigint_1.isEven)(quotient) ? quotient : quotient + direction;
898
+ }
794
899
  /**
795
900
  * Computes the modulo (remainder) of `x` divided by `y`.
796
901
  *
902
+ * Exact Gaussian integers use the same quotient rule as Wolfram Language:
903
+ * divide, round the real and imaginary quotient components independently to
904
+ * the nearest integers with midpoint ties going to even, then subtract
905
+ * `y * quotient` from `x`.
906
+ *
907
+ * Complex values outside the Gaussian integers remain symbolic.
908
+ *
909
+ * @see https://reference.wolfram.com/language/ref/Mod.html
910
+ * @see https://reference.wolfram.com/language/ref/Quotient.html
911
+ * @see https://reference.wolfram.com/language/ref/Round.html
912
+ *
797
913
  * @param x - The dividend.
798
914
  * @param y - The divisor.
799
915
  * @returns The remainder of `x / y`.
@@ -801,8 +917,8 @@ function modInv(a, p) {
801
917
  *
802
918
  * @example
803
919
  * ```ts
804
- * mod(Expression.create(10), Expression.create(3)).text() // "1"
805
- * mod(Expression.create(7), Expression.create(2)).text() // "1"
920
+ * mod(Expression.create(10), Expression.create(3)).text() // "1"
921
+ * mod(Expression.create('5+3*i'), Expression.create('2+i')).text() // "-1"
806
922
  * ```
807
923
  */
808
924
  function mod(x, y) {
@@ -813,16 +929,96 @@ function mod(x, y) {
813
929
  if (x.isNUM() && y.isNUM()) {
814
930
  retval = Expression_1.Expression.create(x.getMultiplier().mod(y.getMultiplier()));
815
931
  }
932
+ else if (x.isComplex() || y.isComplex()) {
933
+ const xReal = x.realPart();
934
+ const xImag = x.imagPart();
935
+ const yReal = y.realPart();
936
+ const yImag = y.imagPart();
937
+ if (xReal.isNUM() &&
938
+ xReal.isInteger() &&
939
+ xImag.isNUM() &&
940
+ xImag.isInteger() &&
941
+ yReal.isNUM() &&
942
+ yReal.isInteger() &&
943
+ yImag.isNUM() &&
944
+ yImag.isInteger()) {
945
+ const a = xReal.getMultiplier().numerator;
946
+ const b = xImag.getMultiplier().numerator;
947
+ const c = yReal.getMultiplier().numerator;
948
+ const d = yImag.getMultiplier().numerator;
949
+ const denominator = c * c + d * d;
950
+ if (denominator === 0n) {
951
+ retval = Expression_1.Expression.toFunction(constants_1.MOD, [Expression_1.Expression.create(x), Expression_1.Expression.create(y)]);
952
+ }
953
+ else {
954
+ const quotientReal = roundRatioToNearestEven(a * c + b * d, denominator);
955
+ const quotientImag = roundRatioToNearestEven(b * c - a * d, denominator);
956
+ const remainderReal = a - c * quotientReal + d * quotientImag;
957
+ const remainderImag = b - c * quotientImag - d * quotientReal;
958
+ retval = Expression_1.Expression.Number(remainderReal).plus(Expression_1.Expression.Number(remainderImag).i());
959
+ }
960
+ }
961
+ else {
962
+ retval = Expression_1.Expression.toFunction(constants_1.MOD, [Expression_1.Expression.create(x), Expression_1.Expression.create(y)]);
963
+ }
964
+ }
816
965
  else if (x.isPolynomialLike() &&
817
966
  y.isPolynomialLike() &&
818
967
  (0, utils_2.maxCommonVariableOccurrence)(x, y)) {
819
968
  retval = (0, utils_2.polyMod)(x, y).getExpression();
820
969
  }
821
970
  else {
822
- retval = Expression_1.Expression.toFunction(constants_1.MOD, [new Expression_1.Expression(x), new Expression_1.Expression(y)]);
971
+ retval = Expression_1.Expression.toFunction(constants_1.MOD, [Expression_1.Expression.create(x), Expression_1.Expression.create(y)]);
823
972
  }
824
973
  return retval;
825
974
  }
975
+ /**
976
+ * Upper incomplete gamma Γ(a, z).
977
+ *
978
+ * Positive integer first arguments are expanded exactly using the finite-sum formula.
979
+ * Other inputs remain symbolic.
980
+ *
981
+ * @see https://dlmf.nist.gov/8.4.E8
982
+ */
983
+ function gammaIncomplete(a, z) {
984
+ const order = Expression_1.Expression.create(a);
985
+ const argument = Expression_1.Expression.create(z);
986
+ if (!order.isNUM() || !order.isInteger() || order.lte((0, shortcuts_1.zero)())) {
987
+ return Expression_1.Expression.toFunction('gamma_incomplete', [order, argument]);
988
+ }
989
+ const n = order.getMultiplier().numerator;
990
+ if (n > BigInt(Settings_1.Settings.MAX_PRODUCT_AND_SUMMATION_ITERATION)) {
991
+ return Expression_1.Expression.toFunction('gamma_incomplete', [order, argument]);
992
+ }
993
+ let term = (0, shortcuts_1.one)();
994
+ let series = (0, shortcuts_1.one)();
995
+ let k = 1n;
996
+ while (k < n) {
997
+ term = term.times(argument).div(Expression_1.Expression.Number(k));
998
+ series = series.plus(term);
999
+ k++;
1000
+ }
1001
+ return factorial(Expression_1.Expression.Number(n - 1n)).times(exp(argument.neg())).times(series);
1002
+ }
1003
+ /**
1004
+ * Lower incomplete gamma γ(a, z).
1005
+ *
1006
+ * Positive integer first arguments use γ(a,z) = Γ(a) - Γ(a,z).
1007
+ * Other inputs remain symbolic.
1008
+ *
1009
+ * @see https://dlmf.nist.gov/8.2.E3
1010
+ */
1011
+ function gammaIncompleteLower(a, z) {
1012
+ const order = Expression_1.Expression.create(a);
1013
+ const argument = Expression_1.Expression.create(z);
1014
+ if (!order.isNUM() || !order.isInteger() || order.lte((0, shortcuts_1.zero)())) {
1015
+ return Expression_1.Expression.toFunction('gamma_incomplete_lower', [order, argument]);
1016
+ }
1017
+ if (order.getMultiplier().numerator > BigInt(Settings_1.Settings.MAX_PRODUCT_AND_SUMMATION_ITERATION)) {
1018
+ return Expression_1.Expression.toFunction('gamma_incomplete_lower', [order, argument]);
1019
+ }
1020
+ return gamma(order).minus(gammaIncomplete(order, argument));
1021
+ }
826
1022
  /**
827
1023
  * Computes the gamma function Γ(x).
828
1024
  *
@@ -956,7 +1152,7 @@ function erf(x) {
956
1152
  }
957
1153
  }
958
1154
  else {
959
- retval = Expression_1.Expression.toFunction(constants_1.ERF, [new Expression_1.Expression(x)]);
1155
+ retval = Expression_1.Expression.toFunction(constants_1.ERF, [Expression_1.Expression.create(x)]);
960
1156
  }
961
1157
  return retval;
962
1158
  }
@@ -996,7 +1192,7 @@ function sinc(x) {
996
1192
  retval = (0, trig_1.sin)(x).div(x);
997
1193
  }
998
1194
  else {
999
- retval = Expression_1.Expression.toFunction(constants_1.SINC, [new Expression_1.Expression(x)]);
1195
+ retval = Expression_1.Expression.toFunction(constants_1.SINC, [Expression_1.Expression.create(x)]);
1000
1196
  }
1001
1197
  return retval;
1002
1198
  }
@@ -1034,7 +1230,7 @@ function Si(x) {
1034
1230
  retval = Expression_1.Expression.Number((0, decimal_1.Si)(x.getMultiplier().toDecimal()));
1035
1231
  }
1036
1232
  else {
1037
- retval = Expression_1.Expression.toFunction(constants_1.SI, [new Expression_1.Expression(x)]);
1233
+ retval = Expression_1.Expression.toFunction(constants_1.SI, [Expression_1.Expression.create(x)]);
1038
1234
  }
1039
1235
  return retval;
1040
1236
  }
@@ -1069,7 +1265,7 @@ function Shi(x) {
1069
1265
  retval = Expression_1.Expression.Number((0, decimal_1.Shi)(x.getMultiplier().toDecimal()));
1070
1266
  }
1071
1267
  else {
1072
- retval = Expression_1.Expression.toFunction(constants_1.SHI, [new Expression_1.Expression(x)]);
1268
+ retval = Expression_1.Expression.toFunction(constants_1.SHI, [Expression_1.Expression.create(x)]);
1073
1269
  }
1074
1270
  return retval;
1075
1271
  }
@@ -1104,7 +1300,7 @@ function Ci(x) {
1104
1300
  retval = Expression_1.Expression.Number((0, decimal_1.Ci)(x.getMultiplier().toDecimal()));
1105
1301
  }
1106
1302
  else {
1107
- retval = Expression_1.Expression.toFunction(constants_1.CI, [new Expression_1.Expression(x)]);
1303
+ retval = Expression_1.Expression.toFunction(constants_1.CI, [Expression_1.Expression.create(x)]);
1108
1304
  }
1109
1305
  return retval;
1110
1306
  }
@@ -1139,7 +1335,7 @@ function Chi(x) {
1139
1335
  retval = Expression_1.Expression.Number((0, decimal_1.Chi)(x.getMultiplier().toDecimal()));
1140
1336
  }
1141
1337
  else {
1142
- retval = Expression_1.Expression.toFunction(constants_1.CHI, [new Expression_1.Expression(x)]);
1338
+ retval = Expression_1.Expression.toFunction(constants_1.CHI, [Expression_1.Expression.create(x)]);
1143
1339
  }
1144
1340
  return retval;
1145
1341
  }
@@ -1170,7 +1366,7 @@ function Ei(x) {
1170
1366
  retval = Expression_1.Expression.Number((0, decimal_1.Ei)(x.getMultiplier().toDecimal()));
1171
1367
  }
1172
1368
  else {
1173
- retval = Expression_1.Expression.toFunction(constants_1.EI, [new Expression_1.Expression(x)]);
1369
+ retval = Expression_1.Expression.toFunction(constants_1.EI, [Expression_1.Expression.create(x)]);
1174
1370
  }
1175
1371
  return retval;
1176
1372
  }
@@ -1200,14 +1396,14 @@ function Li(x) {
1200
1396
  else if (x.isNUM() && Settings_1.Settings.EVALUATE) {
1201
1397
  const m = x.getMultiplier();
1202
1398
  if (m.isNegative()) {
1203
- retval = Expression_1.Expression.toFunction(constants_1.LI, [new Expression_1.Expression(x)]);
1399
+ retval = Expression_1.Expression.toFunction(constants_1.LI, [Expression_1.Expression.create(x)]);
1204
1400
  }
1205
1401
  else {
1206
1402
  retval = Expression_1.Expression.Number((0, decimal_1.Li)(m.toDecimal()));
1207
1403
  }
1208
1404
  }
1209
1405
  else {
1210
- retval = Expression_1.Expression.toFunction(constants_1.LI, [new Expression_1.Expression(x)]);
1406
+ retval = Expression_1.Expression.toFunction(constants_1.LI, [Expression_1.Expression.create(x)]);
1211
1407
  }
1212
1408
  return retval;
1213
1409
  }
@@ -1247,8 +1443,8 @@ function log(x, base, expandPrimes = false) {
1247
1443
  if (baseExpr &&
1248
1444
  x.isInteger() &&
1249
1445
  baseExpr.isInteger() &&
1250
- x.gt(0) &&
1251
- baseExpr.gt(1)) {
1446
+ x.gt((0, shortcuts_1.zero)()) &&
1447
+ baseExpr.gt((0, shortcuts_1.one)())) {
1252
1448
  const target = x.getMultiplier().numerator;
1253
1449
  const radix = baseExpr.getMultiplier().numerator;
1254
1450
  let value = 1n;
@@ -1282,10 +1478,10 @@ function log(x, base, expandPrimes = false) {
1282
1478
  retval = (0, shortcuts_1.one)().times(exponent);
1283
1479
  }
1284
1480
  else {
1285
- retval = Expression_1.Expression.toFunction(Expression_1.Expression.LOG, [new Expression_1.Expression(x)]);
1481
+ retval = Expression_1.Expression.toFunction(Expression_1.Expression.LOG, [Expression_1.Expression.create(x)]);
1286
1482
  }
1287
1483
  }
1288
- else if (!x.isComplex() && x.lt(0)) {
1484
+ else if (!x.isComplex() && x.lt((0, shortcuts_1.zero)())) {
1289
1485
  retval = Expression_1.Expression.Pi().times(Expression_1.Expression.Img()).plus(log(x.abs()));
1290
1486
  }
1291
1487
  // Handle complex numbers regardless of EVALUATE setting
@@ -1355,7 +1551,7 @@ function log(x, base, expandPrimes = false) {
1355
1551
  for (const element of elements) {
1356
1552
  let elementIsPositive = false;
1357
1553
  if (element.isNUM()) {
1358
- elementIsPositive = element.gt(0);
1554
+ elementIsPositive = element.gt((0, shortcuts_1.zero)());
1359
1555
  }
1360
1556
  else {
1361
1557
  const elementPower = element.getPower();
@@ -1365,7 +1561,7 @@ function log(x, base, expandPrimes = false) {
1365
1561
  elementIsPositive =
1366
1562
  !elementPower.isComplex() &&
1367
1563
  !elementBase.isComplex() &&
1368
- elementBase.gt(0);
1564
+ elementBase.gt((0, shortcuts_1.zero)());
1369
1565
  }
1370
1566
  if (!elementIsPositive) {
1371
1567
  canSplitProduct = false;
@@ -1386,11 +1582,11 @@ function log(x, base, expandPrimes = false) {
1386
1582
  const baseExpr = mFree.isEXP() ? mFree.getBase() : (0, utils_3.stripPower)(mFree);
1387
1583
  if (pow.isOne()) {
1388
1584
  logExpr = Expression_1.Expression.toFunction(Expression_1.Expression.LOG, [mFree]);
1389
- mFreeIsPositive = !mFree.isComplex() && mFree.gt(0);
1585
+ mFreeIsPositive = !mFree.isComplex() && mFree.gt((0, shortcuts_1.zero)());
1390
1586
  }
1391
1587
  // log(a^p) → p*log(a) is branch-safe for a positive real base
1392
1588
  // and a real exponent. Unknown-sign bases remain attached.
1393
- else if (!pow.isComplex() && !baseExpr.isComplex() && baseExpr.gt(0)) {
1589
+ else if (!pow.isComplex() && !baseExpr.isComplex() && baseExpr.gt((0, shortcuts_1.zero)())) {
1394
1590
  logExpr = log(baseExpr).times(pow);
1395
1591
  mFreeIsPositive = true;
1396
1592
  }
@@ -1407,7 +1603,7 @@ function log(x, base, expandPrimes = false) {
1407
1603
  }
1408
1604
  }
1409
1605
  }
1410
- retval = retval || Expression_1.Expression.toFunction(Expression_1.Expression.LOG, [new Expression_1.Expression(x)]);
1606
+ retval = retval || Expression_1.Expression.toFunction(Expression_1.Expression.LOG, [Expression_1.Expression.create(x)]);
1411
1607
  // Handle base conversion: log_b(x) = log(x) / log(b)
1412
1608
  if (baseExpr && retval && !exactBaseLog) {
1413
1609
  retval = retval.div(log(baseExpr));
@@ -1719,58 +1915,6 @@ function product(expr, index, lower, upper) {
1719
1915
  }
1720
1916
  return acc;
1721
1917
  }
1722
- /**
1723
- * Calculates the definite integral using Adaptive Simpson. Note that this function uses
1724
- * native JS number due to severe computational overhead when implemented with Decimal.js.
1725
- *
1726
- * @param f The function being integrated
1727
- * @param dx The variable of integration
1728
- * @param from The lower limit of the integral
1729
- * @param to The upper limit of the integral
1730
- * @returns The numeric value if possible else a symbolic function
1731
- *
1732
- * @example
1733
- * ```ts
1734
- * defint('cos(x)-x^2+6', 'x', 1, 6); // -42.787553149673464
1735
- * ```
1736
- */
1737
- function defint(f, dx, from, to) {
1738
- let retval;
1739
- f = Expression_1.Expression.create(f);
1740
- dx = Expression_1.Expression.create(dx);
1741
- from = Expression_1.Expression.create(from);
1742
- to = Expression_1.Expression.create(to);
1743
- const inputVars = f.variables();
1744
- // Get the variable
1745
- const v = (0, utils_1.assertPlainVariableAndGetString)(dx);
1746
- // Pull factors that are constant with respect to the integration variable across the bounds.
1747
- if (!inputVars.includes(v)) {
1748
- retval = f.times(to.minus(from));
1749
- }
1750
- else {
1751
- let numericFrom = from;
1752
- let numericTo = to;
1753
- if (!numericFrom.isNUM() && numericFrom.isConstant()) {
1754
- numericFrom = numericFrom.evaluate();
1755
- }
1756
- if (!numericTo.isNUM() && numericTo.isConstant()) {
1757
- numericTo = numericTo.evaluate();
1758
- }
1759
- if (inputVars.length === 1 &&
1760
- inputVars[0] === v &&
1761
- numericFrom.isNUM() &&
1762
- numericTo.isNUM()) {
1763
- const a = Number(numericFrom.getMultiplier().toDecimal());
1764
- const b = Number(numericTo.getMultiplier().toDecimal());
1765
- retval = Expression_1.Expression.create((0, defintNative_1.definiteIntegrateNative)(f.buildFunction(), a, b));
1766
- retval.precision = NATIVE_DEFINITE_INTEGRATION_PRECISION; // Mark it as limited precision
1767
- }
1768
- else {
1769
- retval = Expression_1.Expression.toFunction(constants_1.DEFINT, [f, dx, from, to]);
1770
- }
1771
- }
1772
- return retval;
1773
- }
1774
1918
  /**
1775
1919
  * Tests whether a value is present in a supported finite container.
1776
1920
  *