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
@@ -101,6 +101,8 @@ export declare const DOT_PRODUCT = "dot";
101
101
  export declare const EI = "Ei";
102
102
  export declare const ERF = "erf";
103
103
  export declare const FACTOR = "factor";
104
+ export declare const PFACTOR = "pfactor";
105
+ export declare const PFACTORD = "pfactord";
104
106
  export declare const FLOOR = "floor";
105
107
  export declare const FRESNEL_C = "C";
106
108
  export declare const FRESNEL_S = "S";
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FIB = exports.DOUBLE_FACTORIAL = exports.FACTORIAL = exports.SYMBOLIC_ACCESSOR = exports.PARSER_CONSTANTS = exports.INFINITY = exports.PI = exports.ALIASES = exports.ALL_SYMBOL = exports.INDEX_VARIABLE = exports.DEFAULT_IMAGINARY = exports.PI_SYMBOL = exports.PI_NAME = exports.E = exports.RANK = exports.EXPRESSION_TYPES = exports.dataTypes = exports.ASSUMPTION = exports.DICTIONARY = exports.SOLUTIONS_SET = exports.SET = exports.GFPOLY = exports.TERM = exports.POLYNOMIAL = exports.EQUATION = exports.MATRIX = exports.VECTOR = exports.COLLECTION = exports.EXPRESSION = exports.SCOPE = exports.RATIONAL = exports.KEY_VALUE_PAIR = exports.INDEXED_REFERENCE = exports.TOKEN = exports.WRAP = exports.CLOSE_PAREN = exports.OPEN_PAREN = exports.RETURN = exports.LINEFEED = exports.TAB = exports.NEWLINE = exports.BLANK = exports.SPACE = exports.ASSIGN = exports.COMMA = exports.DOT = exports.DIVIDE = exports.MULTIPLY = exports.PLUS = exports.MINUS = void 0;
7
- exports.SUM_FUNCTION = exports.SINC = exports.SI = exports.SHI = exports.TRUNC = exports.SIZE = exports.ROUND = exports.REALPART = exports.PRODUCT_FUNCTION = exports.NTHROOT = exports.MIN = exports.MAX = exports.LN = exports.LIMIT = exports.LI = exports.LAPLACE = exports.ISPRIME = exports.INTEGRATE = exports.IMATRIX = exports.IMAGPART = exports.ILAPLACE = exports.GCD = exports.FRESNEL_S = exports.FRESNEL_C = exports.FLOOR = exports.FACTOR = exports.ERF = exports.EI = exports.DOT_PRODUCT = exports.DIFF = exports.DEG = exports.DEFINT = exports.CROSS = exports.COUNT = exports.CONTENT = exports.CONTAINS = exports.CONJUGATE = exports.CI = exports.CHI = exports.CEIL = exports.CBRT = exports.CSGN = exports.SGN = exports.LOG = exports.HEAVISIDE = exports.DIRAC = exports.GAMMA = exports.MOD = exports.ABS = exports.SQRT = void 0;
8
- exports.INVERSE_HYPERBOLIC_TRIG = exports.HYPERBOLIC_TRIG = exports.INVERSE_TRIG = exports.TRIG = exports.ACOTH = exports.ACSCH = exports.ASECH = exports.ATANH = exports.ASINH = exports.ACOSH = exports.COTH = exports.CSCH = exports.SECH = exports.TANH = exports.COSH = exports.SINH = exports.ATAN2 = exports.ACOT = exports.ACSC = exports.ASEC = exports.ATAN = exports.COT = exports.CSC = exports.SEC = exports.ACOS = exports.ASIN = exports.TAN = exports.SIN = exports.COS = exports.TRIG_FUNCTION_NAMES = void 0;
7
+ exports.SI = exports.SHI = exports.TRUNC = exports.SIZE = exports.ROUND = exports.REALPART = exports.PRODUCT_FUNCTION = exports.NTHROOT = exports.MIN = exports.MAX = exports.LN = exports.LIMIT = exports.LI = exports.LAPLACE = exports.ISPRIME = exports.INTEGRATE = exports.IMATRIX = exports.IMAGPART = exports.ILAPLACE = exports.GCD = exports.FRESNEL_S = exports.FRESNEL_C = exports.FLOOR = exports.PFACTORD = exports.PFACTOR = exports.FACTOR = exports.ERF = exports.EI = exports.DOT_PRODUCT = exports.DIFF = exports.DEG = exports.DEFINT = exports.CROSS = exports.COUNT = exports.CONTENT = exports.CONTAINS = exports.CONJUGATE = exports.CI = exports.CHI = exports.CEIL = exports.CBRT = exports.CSGN = exports.SGN = exports.LOG = exports.HEAVISIDE = exports.DIRAC = exports.GAMMA = exports.MOD = exports.ABS = exports.SQRT = void 0;
8
+ exports.INVERSE_HYPERBOLIC_TRIG = exports.HYPERBOLIC_TRIG = exports.INVERSE_TRIG = exports.TRIG = exports.ACOTH = exports.ACSCH = exports.ASECH = exports.ATANH = exports.ASINH = exports.ACOSH = exports.COTH = exports.CSCH = exports.SECH = exports.TANH = exports.COSH = exports.SINH = exports.ATAN2 = exports.ACOT = exports.ACSC = exports.ASEC = exports.ATAN = exports.COT = exports.CSC = exports.SEC = exports.ACOS = exports.ASIN = exports.TAN = exports.SIN = exports.COS = exports.TRIG_FUNCTION_NAMES = exports.SUM_FUNCTION = exports.SINC = void 0;
9
9
  const decimal_js_1 = __importDefault(require("decimal.js"));
10
10
  /**
11
11
  * Some helper constants
@@ -167,6 +167,8 @@ exports.DOT_PRODUCT = 'dot';
167
167
  exports.EI = 'Ei';
168
168
  exports.ERF = 'erf';
169
169
  exports.FACTOR = 'factor';
170
+ exports.PFACTOR = 'pfactor';
171
+ exports.PFACTORD = 'pfactord';
170
172
  exports.FLOOR = 'floor';
171
173
  exports.FRESNEL_C = 'C';
172
174
  exports.FRESNEL_S = 'S';
@@ -0,0 +1,38 @@
1
+ import type { ParserEntity } from '../../types';
2
+ export declare const RETURN_SIGNAL = "RETURN_SIGNAL";
3
+ export declare const BREAK_SIGNAL = "BREAK_SIGNAL";
4
+ export declare const CONTINUE_SIGNAL = "CONTINUE_SIGNAL";
5
+ export declare const NULL_SIGNAL = "NULL_SIGNAL";
6
+ /**
7
+ * Internal signals used to unwind late-bound parser evaluation.
8
+ *
9
+ * Deferred scripting expressions can execute after their surrounding syntax has
10
+ * already been parsed, so return, loop control, and no-result state must travel
11
+ * to the evaluation boundary that knows how to consume them.
12
+ *
13
+ * The signals live at the parser level rather than under scripting because both
14
+ * Parser and the scripting implementation need to recognize them. Keeping this
15
+ * module dependency-light avoids a Parser -> scripting -> Parser import cycle.
16
+ * These are evaluation mechanics, not parser result values.
17
+ */
18
+ export declare abstract class ControlFlowSignal extends Error {
19
+ constructor();
20
+ }
21
+ export declare class ReturnSignal extends ControlFlowSignal {
22
+ readonly value: ParserEntity;
23
+ readonly dataType: typeof RETURN_SIGNAL;
24
+ constructor(value: ParserEntity);
25
+ static isReturnSignal(obj: unknown): obj is ReturnSignal;
26
+ }
27
+ export declare class BreakSignal extends ControlFlowSignal {
28
+ readonly dataType: typeof BREAK_SIGNAL;
29
+ static isBreakSignal(obj: unknown): obj is BreakSignal;
30
+ }
31
+ export declare class ContinueSignal extends ControlFlowSignal {
32
+ readonly dataType: typeof CONTINUE_SIGNAL;
33
+ static isContinueSignal(obj: unknown): obj is ContinueSignal;
34
+ }
35
+ export declare class NullSignal extends ControlFlowSignal {
36
+ readonly dataType: typeof NULL_SIGNAL;
37
+ static isNullSignal(obj: unknown): obj is NullSignal;
38
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NullSignal = exports.ContinueSignal = exports.BreakSignal = exports.ReturnSignal = exports.ControlFlowSignal = exports.NULL_SIGNAL = exports.CONTINUE_SIGNAL = exports.BREAK_SIGNAL = exports.RETURN_SIGNAL = void 0;
4
+ const common_1 = require("../../common/common");
5
+ exports.RETURN_SIGNAL = 'RETURN_SIGNAL';
6
+ exports.BREAK_SIGNAL = 'BREAK_SIGNAL';
7
+ exports.CONTINUE_SIGNAL = 'CONTINUE_SIGNAL';
8
+ exports.NULL_SIGNAL = 'NULL_SIGNAL';
9
+ /**
10
+ * Internal signals used to unwind late-bound parser evaluation.
11
+ *
12
+ * Deferred scripting expressions can execute after their surrounding syntax has
13
+ * already been parsed, so return, loop control, and no-result state must travel
14
+ * to the evaluation boundary that knows how to consume them.
15
+ *
16
+ * The signals live at the parser level rather than under scripting because both
17
+ * Parser and the scripting implementation need to recognize them. Keeping this
18
+ * module dependency-light avoids a Parser -> scripting -> Parser import cycle.
19
+ * These are evaluation mechanics, not parser result values.
20
+ */
21
+ class ControlFlowSignal extends Error {
22
+ constructor() {
23
+ super();
24
+ this.name = new.target.name;
25
+ }
26
+ }
27
+ exports.ControlFlowSignal = ControlFlowSignal;
28
+ class ReturnSignal extends ControlFlowSignal {
29
+ value;
30
+ dataType = exports.RETURN_SIGNAL;
31
+ constructor(value) {
32
+ super();
33
+ this.value = value;
34
+ }
35
+ static isReturnSignal(obj) {
36
+ return (0, common_1.isNerdamerNativeType)(obj, exports.RETURN_SIGNAL);
37
+ }
38
+ }
39
+ exports.ReturnSignal = ReturnSignal;
40
+ class BreakSignal extends ControlFlowSignal {
41
+ dataType = exports.BREAK_SIGNAL;
42
+ static isBreakSignal(obj) {
43
+ return (0, common_1.isNerdamerNativeType)(obj, exports.BREAK_SIGNAL);
44
+ }
45
+ }
46
+ exports.BreakSignal = BreakSignal;
47
+ class ContinueSignal extends ControlFlowSignal {
48
+ dataType = exports.CONTINUE_SIGNAL;
49
+ static isContinueSignal(obj) {
50
+ return (0, common_1.isNerdamerNativeType)(obj, exports.CONTINUE_SIGNAL);
51
+ }
52
+ }
53
+ exports.ContinueSignal = ContinueSignal;
54
+ class NullSignal extends ControlFlowSignal {
55
+ dataType = exports.NULL_SIGNAL;
56
+ static isNullSignal(obj) {
57
+ return (0, common_1.isNerdamerNativeType)(obj, exports.NULL_SIGNAL);
58
+ }
59
+ }
60
+ exports.NullSignal = NullSignal;
@@ -18,10 +18,16 @@ function add(a, b) {
18
18
  else {
19
19
  const keyA = a.keyValue();
20
20
  const keyB = b.keyValue();
21
- // Distribute the multiplier if true
21
+ // Distribute only when an operand can actually change. distributeMultiplier()
22
+ // returns an independent deep copy, so calling it for ordinary operands adds
23
+ // substantial copy work without affecting the result.
22
24
  if (Expression_1.Expression.DISTRIBUTE_MULTIPLIER) {
23
- a = a.distributeMultiplier();
24
- b = b.distributeMultiplier();
25
+ if (a.isSum() && !a.getMultiplier().isOne() && a.isLinear()) {
26
+ a = a.distributeMultiplier();
27
+ }
28
+ if (b.isSum() && !b.getMultiplier().isOne() && b.isLinear()) {
29
+ b = b.distributeMultiplier();
30
+ }
25
31
  }
26
32
  // It suffices to check if their keyValues are the same since x+x will be handled.
27
33
  // We're only dealing with x^n+x^(!n) at this point.
@@ -36,7 +42,7 @@ function add(a, b) {
36
42
  retval = re.isZero() ? im : im.isZero() ? re : join(re, im); // Don't use add
37
43
  }
38
44
  else if (a.isZero()) {
39
- retval = Expression_1.Expression.create(b);
45
+ retval = b.copy();
40
46
  }
41
47
  else if (a.value === b.value && a.type === b.type && a.getPower().eq(b.getPower())) {
42
48
  // Infinity has no finite coefficient magnitude. Same-sign infinities remain
@@ -50,24 +56,16 @@ function add(a, b) {
50
56
  retval = a.isNegInf() ? Expression_1.Expression.NegInf() : Expression_1.Expression.Inf();
51
57
  }
52
58
  else {
53
- retval = Expression_1.Expression.create(a);
54
59
  const multiplier = a.getMultiplier().plus(b.getMultiplier());
55
60
  if (multiplier.isZero()) {
56
61
  retval = Expression_1.Expression.Number('0');
57
62
  }
58
- if (a.isSum() && b.isSum() && a.isLinear() && b.isLinear()) {
63
+ else if (a.isSum() && b.isSum() && a.isLinear() && b.isLinear()) {
59
64
  retval = join(a, b);
60
65
  }
61
66
  else {
67
+ retval = a.copy();
62
68
  retval.multiplier = multiplier;
63
- if (retval.power) {
64
- // We can do this since a.power === b.power
65
- retval = Expression_1.Expression.setPower(retval, a.getPower().copy());
66
- }
67
- }
68
- // Put back the power
69
- if (a.power) {
70
- retval = Expression_1.Expression.setPower(retval, a.getPower().copy());
71
69
  }
72
70
  }
73
71
  }
@@ -230,8 +228,8 @@ function join(a, b, isGroup = false) {
230
228
  else {
231
229
  // Set the type
232
230
  retval.type = expressionType;
233
- // Update the value
234
- retval.value = Expression_1.Expression.getValue(elements, 'text', expressionType);
231
+ // Update derived aggregate state after the element collection changes.
232
+ retval.updateValue(elements);
235
233
  }
236
234
  }
237
235
  return retval;
@@ -243,6 +243,19 @@ function equal(a, b) {
243
243
  const y = (0, assume_1.getAssumptionFor)(b);
244
244
  let assumptionResult = undefined;
245
245
  let retval;
246
+ if (a.isComplex() && b.isComplex()) {
247
+ const realA = a.realPart();
248
+ const imaginaryA = a.imagPart();
249
+ const realB = b.realPart();
250
+ const imaginaryB = b.imagPart();
251
+ if (realA.isNUM() &&
252
+ imaginaryA.isNUM() &&
253
+ realB.isNUM() &&
254
+ imaginaryB.isNUM()) {
255
+ return (realA.getMultiplier().eq(realB.getMultiplier()) &&
256
+ imaginaryA.getMultiplier().eq(imaginaryB.getMultiplier()));
257
+ }
258
+ }
246
259
  // An assumption describes the admissible values of a variable; it does not erase
247
260
  // the identity of the variable itself. x == x remains true even when x ranges over
248
261
  // more than one value.
@@ -1,9 +1,8 @@
1
1
  import { Equation } from '../../equation/Equation';
2
2
  import { Matrix } from '../../matrix/Matrix';
3
3
  import { Vector } from '../../vector/Vector';
4
- import { comma } from './comma';
5
4
  import type { ParserEntity } from '../../../types';
6
- import type { Operation, PreFixFunction, PostFixFunction, EquationConstructorCall, CommaOperation, DeferredFunctionArgument, DeferredOperation } from '../types';
5
+ import type { Operation, PreFixFunction, PostFixFunction, EquationConstructorCall, DeferredFunctionArgument, DeferredOperation } from '../types';
7
6
  /**
8
7
  * The wrapper used to call functions within the parser.
9
8
  *
@@ -16,7 +15,7 @@ export declare function callFunction(functionName: string, args: (ParserEntity |
16
15
  * Combines all base operations into one object for parser.
17
16
  */
18
17
  export declare const _: {
19
- [functionName: string]: Operation | DeferredOperation | PreFixFunction | PostFixFunction | EquationConstructorCall | CommaOperation;
18
+ [functionName: string]: Operation | DeferredOperation | PreFixFunction | PostFixFunction | EquationConstructorCall;
20
19
  };
21
20
  /**
22
21
  * Applies a scalar function over a copied Vector or Matrix while preserving its shape.
@@ -43,4 +42,4 @@ export declare function setEqual(a: ParserEntity, b: ParserEntity): Equation;
43
42
  * @returns The registered function signature.
44
43
  */
45
44
  export declare function functionAssign(a: ParserEntity, body: DeferredFunctionArgument): ParserEntity;
46
- export declare function route(a: ParserEntity, b: ParserEntity, operation: string): ParserEntity | ReturnType<typeof comma>;
45
+ export declare function route(a: ParserEntity, b: ParserEntity, operation: string): ParserEntity;
@@ -7,7 +7,6 @@ exports.setEqual = setEqual;
7
7
  exports.functionAssign = functionAssign;
8
8
  exports.route = route;
9
9
  const math_1 = require("../../../../math/math");
10
- const structuredEntityUtils_1 = require("../../../common/functions/structuredEntityUtils");
11
10
  const dispatch_1 = require("../../../dispatch");
12
11
  const errors_1 = require("../../../errors");
13
12
  const setFunction_1 = require("../../../functions/setFunction");
@@ -24,7 +23,6 @@ const controlFlow_1 = require("../scripting/controlFlow");
24
23
  const functions_1 = require("../scripting/functions");
25
24
  const scope_1 = require("../scripting/scope");
26
25
  const add_1 = require("./add");
27
- const comma_1 = require("./comma");
28
26
  const divide_1 = require("./divide");
29
27
  const multiply_1 = require("./multiply");
30
28
  const power_1 = require("./power");
@@ -54,16 +52,24 @@ function callFunction(functionName, args) {
54
52
  // The details regarding the function
55
53
  const attributes = dispatch_1.mathFunctionRegistry[functionName];
56
54
  if (attributes === undefined) {
57
- throw new errors_1.ParserError(`Unsupported function ${functionName}`);
55
+ throw new errors_1.ParserError((0, errors_1.message)('unsupportedFunction', { function: functionName }));
58
56
  }
59
57
  const { fn, minArgs, maxArgs, maxPrecision, equationArgs, distElWise, deferArguments, returnBoundary, } = attributes;
60
58
  // Complain if the number of arguments provided is less that what is allowed
61
59
  if (minArgs > -1 && args.length < minArgs) {
62
- throw new errors_1.ParserError(`${functionName} requires a minimum of ${minArgs} arguments but ${args.length} provided!`);
60
+ throw new errors_1.ParserError((0, errors_1.message)('functionMinArgs', {
61
+ function: functionName,
62
+ min: String(minArgs),
63
+ actual: String(args.length),
64
+ }));
63
65
  }
64
66
  // Complain if the number of arguments provided is greater than what is allowed
65
67
  if (maxArgs > -1 && args.length > maxArgs) {
66
- throw new errors_1.ParserError(`${functionName} allows a maximum of ${maxArgs} arguments but ${args.length} provided!`);
68
+ throw new errors_1.ParserError((0, errors_1.message)('functionMaxArgs', {
69
+ function: functionName,
70
+ max: String(maxArgs),
71
+ actual: String(args.length),
72
+ }));
67
73
  }
68
74
  let result;
69
75
  if (deferArguments) {
@@ -79,18 +85,15 @@ function callFunction(functionName, args) {
79
85
  }
80
86
  entityArgs.push(arg);
81
87
  }
82
- // A structured entity carrying symbolic bracket access represents one unresolved
83
- // scalar value. Normalize it before equation checks, distribution, or invocation.
84
- const normalizedArgs = entityArgs.map(arg => Expression_1.Expression.fromSymbolicAccess(arg) ?? arg);
85
88
  if (attributes.level === 'system') {
86
- for (let i = 0; i < normalizedArgs.length; i++) {
87
- if (Equation_1.Equation.isEquation(normalizedArgs[i]) && !equationArgs?.includes(i)) {
89
+ for (let i = 0; i < entityArgs.length; i++) {
90
+ if (Equation_1.Equation.isEquation(entityArgs[i]) && !equationArgs?.includes(i)) {
88
91
  throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: 'Equation' }));
89
92
  }
90
93
  }
91
94
  }
92
95
  const elementWiseArgs = distElWise
93
- ? normalizedArgs.filter((arg) => Vector_1.Vector.isVector(arg) || Matrix_1.Matrix.isMatrix(arg))
96
+ ? entityArgs.filter((arg) => Vector_1.Vector.isVector(arg) || Matrix_1.Matrix.isMatrix(arg))
94
97
  : [];
95
98
  if (elementWiseArgs.length > 0) {
96
99
  const structure = elementWiseArgs[0];
@@ -107,7 +110,7 @@ function callFunction(functionName, args) {
107
110
  }
108
111
  }
109
112
  result = distribute((_element, i, j) => {
110
- const scalarArgs = normalizedArgs.map(arg => {
113
+ const scalarArgs = entityArgs.map(arg => {
111
114
  let scalarArg = arg;
112
115
  if (Vector_1.Vector.isVector(arg)) {
113
116
  scalarArg = arg.__get__([i]);
@@ -122,15 +125,15 @@ function callFunction(functionName, args) {
122
125
  }
123
126
  // Call and return
124
127
  else if (!fn || Settings_1.Settings.DEFER_SIMPLIFICATION) {
125
- result = Expression_1.Expression.toFunction(functionName, normalizedArgs);
128
+ result = Expression_1.Expression.toFunction(functionName, entityArgs);
126
129
  }
127
130
  else {
128
- result = invokeMathFunction(fn, normalizedArgs);
131
+ result = invokeMathFunction(fn, entityArgs);
129
132
  }
130
133
  // Ensure that this function always returns even if it's a symbolic function. This will
131
134
  // occur if the function didn't return a value.
132
135
  if (!result) {
133
- result = Expression_1.Expression.toFunction(functionName, normalizedArgs);
136
+ result = Expression_1.Expression.toFunction(functionName, entityArgs);
134
137
  }
135
138
  }
136
139
  // Let all future calls know that an inferior precision was used.
@@ -156,7 +159,6 @@ exports._ = {
156
159
  assertGTE: assertiveFunctions_1.assertGTE,
157
160
  assertLT: assertiveFunctions_1.assertLT,
158
161
  assertLTE: assertiveFunctions_1.assertLTE,
159
- comma: comma_1.comma,
160
162
  assign: scope_1.assign,
161
163
  functionAssign: functionAssign,
162
164
  setEqual: setEqual,
@@ -220,12 +222,12 @@ function setEqual(a, b) {
220
222
  */
221
223
  function functionAssign(a, body) {
222
224
  if (!Collection_1.Collection.isCollection(a)) {
223
- throw new errors_1.UnexpectedInputError(`Invalid function declaration ${a.text()}.`);
225
+ throw new errors_1.UnexpectedInputError((0, errors_1.message)('invalidFunctionDeclaration', { declaration: a.text() }));
224
226
  }
225
227
  const signature = [...a.getElements()];
226
228
  const functionExpression = signature.pop();
227
229
  if (!Expression_1.Expression.isExpression(functionExpression)) {
228
- throw new errors_1.UnexpectedInputError(`Invalid function declaration ${a.text()}.`);
230
+ throw new errors_1.UnexpectedInputError((0, errors_1.message)('invalidFunctionDeclaration', { declaration: a.text() }));
229
231
  }
230
232
  const name = (0, utils_1.assertPlainVariableAndGetString)(functionExpression);
231
233
  const args = signature.map(argument => {
@@ -289,7 +291,7 @@ function percentage(a) {
289
291
  if (!Expression_1.Expression.isExpression(a)) {
290
292
  throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
291
293
  }
292
- const retval = a.div(100);
294
+ const retval = a.div(Expression_1.Expression.create(100));
293
295
  return retval;
294
296
  }
295
297
  /**
@@ -310,25 +312,8 @@ function gte(a, b) {
310
312
  function lte(a, b) {
311
313
  return Expression_1.Expression.create(Number(a.lte(b)));
312
314
  }
313
- function isRoutedOperation(operation) {
314
- return (operation === 'pow' ||
315
- operation === 'times' ||
316
- operation === 'div' ||
317
- operation === 'minus' ||
318
- operation === 'plus' ||
319
- operation === 'eq' ||
320
- operation === 'lt' ||
321
- operation === 'lte' ||
322
- operation === 'gt' ||
323
- operation === 'gte');
324
- }
325
- function routeOperation(target, operand, operation) {
326
- const retval = target[operation](operand);
327
- return typeof retval === 'boolean' ? Expression_1.Expression.create(Number(retval)) : retval;
328
- }
329
315
  function dispatchDynamicOperation(a, b, operation) {
330
- // Preserve the parser's historically loose dispatch for operator actions outside
331
- // RoutedOperation. Tightening these actions may change existing runtime behavior.
316
+ // Preserve the parser's historically loose method dispatch for operator actions.
332
317
  const useA = a.isEnumerable || Equation_1.Equation.isEquation(a);
333
318
  const target = useA ? a : b;
334
319
  const operand = useA ? b : a;
@@ -346,82 +331,43 @@ function route(a, b, operation) {
346
331
  if (operation === 'assign') {
347
332
  retval = (0, scope_1.assign)(a, b);
348
333
  }
349
- else if (operation === 'comma') {
350
- retval = (0, comma_1.comma)(a, b);
351
- }
352
334
  else if (operation === 'in') {
353
335
  // Membership is the infix form of contains(container, value), so reverse the operands.
354
336
  retval = callFunction('contains', [b, a]);
355
337
  }
356
- else if (isRoutedOperation(operation)) {
357
- if (Equation_1.Equation.isEquation(a) || Equation_1.Equation.isEquation(b)) {
358
- if (Equation_1.Equation.isEquation(a) && Equation_1.Equation.isEquation(b)) {
359
- if (['eq', 'lt', 'lte', 'gt', 'gte'].includes(operation)) {
360
- retval = dispatchDynamicOperation(a, b, operation);
361
- }
362
- else {
363
- throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
338
+ else if (a.isEnumerable) {
339
+ retval = dispatchDynamicOperation(a, b, operation);
340
+ }
341
+ else if ((Vector_1.Vector.isVector(b) || Matrix_1.Matrix.isMatrix(b)) &&
342
+ (operation === 'minus' || operation === 'div' || operation === 'pow')) {
343
+ // Scalar-left operations are not commutative. Preserve operand order while
344
+ // distributing the operation over the structured right-hand operand.
345
+ if (!Expression_1.Expression.isExpression(a)) {
346
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
347
+ }
348
+ // A scalar base with a Matrix exponent is a matrix-function question. It must
349
+ // not be reversed into Matrix.pow() or silently treated as element-wise power.
350
+ if (Matrix_1.Matrix.isMatrix(b) && operation === 'pow') {
351
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
352
+ }
353
+ retval = distribute(element => {
354
+ let elementResult;
355
+ if (Expression_1.Expression.isExpression(element)) {
356
+ if (operation === 'minus') {
357
+ elementResult = (0, subtract_1.subtract)(a, element);
364
358
  }
365
- }
366
- else if (Equation_1.Equation.isEquation(a)) {
367
- if (['plus', 'minus', 'times', 'div'].includes(operation)) {
368
- retval = dispatchDynamicOperation(a, b, operation);
359
+ else if (operation === 'div') {
360
+ elementResult = (0, divide_1.divide)(a, element);
369
361
  }
370
362
  else {
371
- throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
363
+ elementResult = (0, power_1.power)(a, element);
372
364
  }
373
365
  }
374
- else if (operation === 'plus' || operation === 'times') {
375
- retval = dispatchDynamicOperation(a, b, operation);
376
- }
377
366
  else {
378
- throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
367
+ elementResult = route(a, element, operation);
379
368
  }
380
- }
381
- else if ((0, structuredEntityUtils_1.isEnumerable)(a)) {
382
- retval = routeOperation(a, b, operation);
383
- }
384
- else if ((Vector_1.Vector.isVector(b) || Matrix_1.Matrix.isMatrix(b)) &&
385
- (operation === 'minus' || operation === 'div' || operation === 'pow')) {
386
- // Scalar-left operations are not commutative. Preserve operand order while
387
- // distributing the operation over the structured right-hand operand.
388
- if (!Expression_1.Expression.isExpression(a)) {
389
- throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
390
- }
391
- // A scalar base with a Matrix exponent is a matrix-function question. It must
392
- // not be reversed into Matrix.pow() or silently treated as element-wise power.
393
- if (Matrix_1.Matrix.isMatrix(b) && operation === 'pow') {
394
- throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
395
- }
396
- retval = distribute(element => {
397
- let elementResult;
398
- if (Expression_1.Expression.isExpression(element)) {
399
- if (operation === 'minus') {
400
- elementResult = (0, subtract_1.subtract)(a, element);
401
- }
402
- else if (operation === 'div') {
403
- elementResult = (0, divide_1.divide)(a, element);
404
- }
405
- else {
406
- elementResult = (0, power_1.power)(a, element);
407
- }
408
- }
409
- else {
410
- const nestedResult = route(a, element, operation);
411
- if (Array.isArray(nestedResult)) {
412
- throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
413
- }
414
- elementResult = nestedResult;
415
- }
416
- return elementResult;
417
- }, b);
418
- }
419
- else if ((0, structuredEntityUtils_1.isEnumerable)(b)) {
420
- retval = routeOperation(b, a, operation);
421
- }
422
- else {
423
- retval = dispatchDynamicOperation(a, b, operation);
424
- }
369
+ return elementResult;
370
+ }, b);
425
371
  }
426
372
  else {
427
373
  retval = dispatchDynamicOperation(a, b, operation);
@@ -4,7 +4,6 @@ exports.multiply = multiply;
4
4
  exports.merge = merge;
5
5
  exports.canonicalizeRadicals = canonicalizeRadicals;
6
6
  const errors_1 = require("../../../errors");
7
- const errors_2 = require("../../../errors");
8
7
  const complex_1 = require("../../../functions/complex");
9
8
  const Settings_1 = require("../../../Settings");
10
9
  const Expression_1 = require("../../expression/Expression");
@@ -32,7 +31,7 @@ function multiply(a, b) {
32
31
  else {
33
32
  if (a.isZero()) {
34
33
  if (b.isInf()) {
35
- throw new errors_1.UndefinedError(errors_2.ErrorMessages[Settings_1.Settings.LANGUAGE].infinityTimesZero);
34
+ throw new errors_1.UndefinedError((0, errors_1.message)('infinityTimesZero'));
36
35
  }
37
36
  retval = Expression_1.Expression.Number('0');
38
37
  }
@@ -63,7 +62,7 @@ function multiply(a, b) {
63
62
  retval = retval.neg();
64
63
  }
65
64
  else if (a.isZero() || b.isZero()) {
66
- throw new errors_1.UndefinedError('Infinity times zero is undefined!');
65
+ throw new errors_1.UndefinedError((0, errors_1.message)('infinityTimesZero'));
67
66
  }
68
67
  }
69
68
  else if (a.value === b.value) {
@@ -143,12 +142,20 @@ function merge(a, b) {
143
142
  let bCanMerge = canMerge(b);
144
143
  let setProperties = true;
145
144
  // The multiplier is carried at the top of the expression they get moved and stripped from a and b;
146
- let multiplier = a.multiplier || b.multiplier ? a.getMultiplier().times(b.getMultiplier()) : undefined;
145
+ const aHasMultiplier = a.multiplier !== undefined;
146
+ const bHasMultiplier = b.multiplier !== undefined;
147
+ let multiplier = aHasMultiplier || bHasMultiplier
148
+ ? a.getMultiplier().times(b.getMultiplier())
149
+ : undefined;
147
150
  if (multiplier) {
148
- a = new Expression_1.Expression(a);
149
- b = new Expression_1.Expression(b);
150
- a.multiplier = undefined;
151
- b.multiplier = undefined;
151
+ if (aHasMultiplier) {
152
+ a = a.copy();
153
+ a.multiplier = undefined;
154
+ }
155
+ if (bHasMultiplier) {
156
+ b = b.copy();
157
+ b.multiplier = undefined;
158
+ }
152
159
  }
153
160
  if (a.elements && !b.elements) {
154
161
  [b, a] = [a, b]; // Swap them
@@ -192,7 +199,7 @@ function merge(a, b) {
192
199
  elements = Object.values(retval.getElements());
193
200
  }
194
201
  else {
195
- [retval, elements] = combine(new Expression_1.Expression(a), new Expression_1.Expression(b), keyA, keyB);
202
+ [retval, elements] = combine(a, b, keyA, keyB);
196
203
  }
197
204
  }
198
205
  }
@@ -200,7 +207,7 @@ function merge(a, b) {
200
207
  // the right type. The first object gets added to the second object's expression container.
201
208
  else if (!aCanMerge && bCanMerge) {
202
209
  const key = a.keyValue();
203
- retval = new Expression_1.Expression(b);
210
+ retval = b.copy();
204
211
  const subExpressions = retval.getElements();
205
212
  let result;
206
213
  // No need to move the multiplier since sub elements don't carry one
@@ -223,7 +230,7 @@ function merge(a, b) {
223
230
  result = multiply(a, existing);
224
231
  }
225
232
  else {
226
- result = new Expression_1.Expression(a);
233
+ result = a.copy();
227
234
  }
228
235
  }
229
236
  // remove it if it resulted in one
@@ -241,7 +248,7 @@ function merge(a, b) {
241
248
  }
242
249
  // Case 3: They both have expression objects
243
250
  else {
244
- retval = new Expression_1.Expression(a);
251
+ retval = a.copy();
245
252
  retval.multiplier = a.getMultiplier().times(b.getMultiplier());
246
253
  const retvalElements = retval.getElements();
247
254
  const bExpressions = b.getElements();
@@ -258,7 +265,7 @@ function merge(a, b) {
258
265
  }
259
266
  }
260
267
  else {
261
- retvalElements[x] = new Expression_1.Expression(e);
268
+ retvalElements[x] = e.copy();
262
269
  }
263
270
  }
264
271
  elements = Object.values(retvalElements);
@@ -267,8 +274,8 @@ function merge(a, b) {
267
274
  if (setProperties) {
268
275
  // Set the type
269
276
  retval.type = expressionType;
270
- // Update the value
271
- retval.value = Expression_1.Expression.getValue(elements, 'text', expressionType);
277
+ // Update derived aggregate state after the element collection changes.
278
+ retval.updateValue(elements);
272
279
  }
273
280
  // Put the multiplier back
274
281
  if (multiplier && !multiplier.isOne()) {