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.
- package/BREAKING_CHANGES.md +244 -0
- package/README.md +168 -229
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.LICENSE.txt +6 -6
- package/output/algebra/adapters.d.ts +3 -33
- package/output/algebra/adapters.js +7 -105
- package/output/algebra/algorithms/arith.js +10 -9
- package/output/algebra/algorithms/groebnerBase.d.ts +24 -20
- package/output/algebra/algorithms/groebnerBase.js +486 -723
- package/output/algebra/dispatch.d.ts +1 -0
- package/output/algebra/dispatch.js +25 -0
- package/output/algebra/factor/factor.d.ts +15 -0
- package/output/algebra/factor/factor.js +99 -12
- package/output/algebra/gcd/gcd.d.ts +8 -7
- package/output/algebra/gcd/gcd.js +32 -78
- package/output/algebra/groebner.d.ts +2 -2
- package/output/algebra/groebner.js +6 -12
- package/output/algebra/partfrac.d.ts +3 -3
- package/output/algebra/partfrac.js +28 -61
- package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
- package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
- package/output/algebra/polynomial/modularGcd.d.ts +40 -0
- package/output/algebra/polynomial/modularGcd.js +365 -0
- package/output/algebra/polynomialize.js +4 -2
- package/output/algebra/simplify/funcsimp.js +1 -1
- package/output/algebra/simplify/ratsimp.js +1 -1
- package/output/algebra/simplify/simplify.js +11 -2
- package/output/algebra/utils.d.ts +1 -1
- package/output/algebra/utils.js +3 -3
- package/output/api/advanced.d.ts +2 -1
- package/output/api/advanced.js +3 -3
- package/output/api/algebra.d.ts +21 -4
- package/output/api/algebra.js +22 -3
- package/output/api/assumptions.d.ts +1 -1
- package/output/api/assumptions.js +2 -1
- package/output/api/calculus.d.ts +2 -1
- package/output/api/calculus.js +2 -1
- package/output/api/core.d.ts +28 -7
- package/output/api/core.js +28 -2
- package/output/api/languages/deu.d.ts +3 -0
- package/output/api/languages/deu.js +266 -0
- package/output/api/languages/fra.d.ts +3 -0
- package/output/api/languages/fra.js +266 -0
- package/output/api/languages/ita.d.ts +3 -0
- package/output/api/languages/ita.js +266 -0
- package/output/api/languages/nld.d.ts +3 -0
- package/output/api/languages/nld.js +266 -0
- package/output/api/languages/por.d.ts +3 -0
- package/output/api/languages/por.js +266 -0
- package/output/api/languages/spa.d.ts +3 -0
- package/output/api/languages/spa.js +266 -0
- package/output/api/parser.d.ts +10 -2
- package/output/api/parser.js +2 -0
- package/output/api/solve.d.ts +1 -1
- package/output/api/solve.js +2 -1
- package/output/api/structures.d.ts +1 -1
- package/output/api/structures.js +2 -1
- package/output/calculus/adapters.d.ts +8 -0
- package/output/calculus/adapters.js +41 -0
- package/output/calculus/derivative/diff.js +6 -3
- package/output/calculus/dispatch.d.ts +1 -0
- package/output/calculus/dispatch.js +25 -0
- package/output/calculus/integrate/integrate.js +4 -4
- package/output/calculus/integrate/integrationTable.js +16 -16
- package/output/calculus/laplace/ilaplace.js +1 -1
- package/output/calculus/laplace/ilaplaceTable.js +18 -17
- package/output/calculus/laplace/laplaceTable.js +3 -2
- package/output/calculus/limit/limit.js +1 -1
- package/output/core/classes/assumption/Assumption.js +14 -10
- package/output/core/classes/assumption/assume.d.ts +6 -0
- package/output/core/classes/assumption/assume.js +9 -0
- package/output/core/classes/assumption/dispatch.d.ts +1 -0
- package/output/core/classes/assumption/dispatch.js +11 -0
- package/output/core/classes/collection/Collection.js +11 -2
- package/output/core/classes/complex/Complex.d.ts +10 -0
- package/output/core/classes/complex/Complex.js +19 -1
- package/output/core/classes/decimalSet/DecimalSet.js +5 -4
- package/output/core/classes/dictionary/Dictionary.js +4 -1
- package/output/core/classes/expression/CoeffObject.d.ts +1 -1
- package/output/core/classes/expression/CoeffObject.js +1 -2
- package/output/core/classes/expression/Expression.d.ts +35 -26
- package/output/core/classes/expression/Expression.js +77 -50
- package/output/core/classes/expression/analysis.d.ts +1 -1
- package/output/core/classes/expression/analysis.js +7 -7
- package/output/core/classes/expression/format.d.ts +9 -0
- package/output/core/classes/expression/format.js +130 -7
- package/output/core/classes/expression/utils.d.ts +9 -0
- package/output/core/classes/expression/utils.js +52 -6
- package/output/core/classes/matrix/Matrix.d.ts +2 -3
- package/output/core/classes/matrix/Matrix.js +26 -23
- package/output/core/classes/matrix/dispatch.d.ts +1 -0
- package/output/core/classes/matrix/dispatch.js +19 -0
- package/output/core/classes/matrix/functions.d.ts +2 -0
- package/output/core/classes/matrix/functions.js +5 -0
- package/output/core/classes/parser/Parser.d.ts +31 -5
- package/output/core/classes/parser/Parser.js +357 -444
- package/output/core/classes/parser/constants.d.ts +2 -0
- package/output/core/classes/parser/constants.js +4 -2
- package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
- package/output/core/classes/parser/controlFlowSignals.js +60 -0
- package/output/core/classes/parser/operations/add.js +14 -16
- package/output/core/classes/parser/operations/compare.js +13 -0
- package/output/core/classes/parser/operations/functions.d.ts +3 -4
- package/output/core/classes/parser/operations/functions.js +48 -102
- package/output/core/classes/parser/operations/multiply.js +22 -15
- package/output/core/classes/parser/operations/power.js +11 -11
- package/output/core/classes/parser/operations/subtract.js +2 -1
- package/output/core/classes/parser/preprocess.d.ts +0 -7
- package/output/core/classes/parser/preprocess.js +33 -39
- package/output/core/classes/parser/scripting/controlFlow.d.ts +4 -102
- package/output/core/classes/parser/scripting/controlFlow.js +134 -186
- package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
- package/output/core/classes/parser/scripting/deferred.js +65 -0
- package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
- package/output/core/classes/parser/scripting/dispatch.js +62 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +13 -0
- package/output/core/classes/parser/scripting/evaluate.js +17 -1
- package/output/core/classes/parser/scripting/scope.d.ts +1 -28
- package/output/core/classes/parser/scripting/scope.js +36 -40
- package/output/core/classes/parser/types.d.ts +5 -5
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +4 -3
- package/output/core/classes/parser/wrappers/IndexedReference.js +8 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +2 -2
- package/output/core/classes/polynomial/Polynomial.d.ts +5 -1
- package/output/core/classes/polynomial/Polynomial.js +53 -7
- package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
- package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -0
- package/output/core/classes/polynomial/Term.js +2 -2
- package/output/core/{adapters.d.ts → classes/polynomial/adapters.d.ts} +2 -2
- package/output/core/classes/polynomial/adapters.js +33 -0
- package/output/core/classes/polynomial/dispatch.d.ts +1 -0
- package/output/core/classes/polynomial/dispatch.js +14 -0
- package/output/core/classes/polynomial/functions.d.ts +8 -0
- package/output/core/classes/polynomial/functions.js +71 -8
- package/output/core/classes/polynomial/utils.js +2 -1
- package/output/core/classes/rational/Rational.d.ts +8 -11
- package/output/core/classes/rational/Rational.js +70 -20
- package/output/core/classes/seq/SEQ.js +4 -4
- package/output/core/classes/valuesSet/ValuesSet.d.ts +9 -1
- package/output/core/classes/valuesSet/ValuesSet.js +22 -4
- package/output/core/classes/vector/Vector.d.ts +2 -3
- package/output/core/classes/vector/Vector.js +11 -15
- package/output/core/classes/vector/dispatch.d.ts +1 -0
- package/output/core/classes/vector/dispatch.js +11 -0
- package/output/core/common/classes/MathematicalAggregate.js +11 -2
- package/output/core/common/classes/StructuredEntity.d.ts +0 -17
- package/output/core/common/classes/StructuredEntity.js +3 -64
- package/output/core/common/common.d.ts +0 -1
- package/output/core/common/common.js +29 -234
- package/output/core/converters/BaseConverter.js +3 -2
- package/output/core/converters/Converter.js +9 -5
- package/output/core/converters/Pattern.js +1 -1
- package/output/core/dispatch.d.ts +18 -0
- package/output/core/dispatch.js +3 -281
- package/output/core/errors.d.ts +259 -474
- package/output/core/errors.js +270 -542
- package/output/core/fullFunctions.d.ts +7 -0
- package/output/core/fullFunctions.js +31 -0
- package/output/core/functions/bigint/bigint.d.ts +13 -1
- package/output/core/functions/bigint/bigint.js +56 -4
- package/output/core/functions/bigint/primeFactor.d.ts +2 -0
- package/output/core/functions/bigint/primeFactor.js +13 -13
- package/output/core/functions/build/definitions.js +6 -0
- package/output/core/functions/complex.d.ts +2 -2
- package/output/core/functions/complex.dispatch.d.ts +1 -0
- package/output/core/functions/complex.dispatch.js +16 -0
- package/output/core/functions/complex.js +7 -7
- package/output/core/functions/decimal.js +2 -1
- package/output/core/functions/expand/expand.js +2 -2
- package/output/core/functions/numeric.d.ts +1 -1
- package/output/core/functions/string.js +2 -1
- package/output/core/functions/subst.js +21 -13
- package/output/core/parserFunctions.d.ts +7 -0
- package/output/core/parserFunctions.js +25 -0
- package/output/index.d.ts +50 -30
- package/output/index.js +147 -19
- package/output/math/defint/defint.d.ts +18 -0
- package/output/math/defint/defint.js +60 -0
- package/output/math/defint/defintDecimal.js +6 -5
- package/output/math/defint/defintNative.js +7 -18
- package/output/math/dispatch.d.ts +1 -0
- package/output/math/dispatch.js +101 -0
- package/output/math/geometry.d.ts +4 -0
- package/output/math/geometry.js +23 -0
- package/output/math/math.d.ts +59 -19
- package/output/math/math.js +244 -100
- package/output/math/trig.js +4 -4
- package/output/math/utils.d.ts +6 -0
- package/output/math/utils.js +39 -0
- package/output/solve/classes/PolynomialSolver.d.ts +33 -14
- package/output/solve/classes/PolynomialSolver.js +267 -67
- package/output/solve/classes/SolutionSet.d.ts +20 -1
- package/output/solve/classes/SolutionSet.js +82 -5
- package/output/solve/dispatch.d.ts +1 -0
- package/output/solve/dispatch.js +13 -0
- package/output/solve/linsolve.d.ts +2 -0
- package/output/solve/linsolve.js +13 -5
- package/output/solve/solve.d.ts +10 -0
- package/output/solve/solve.js +128 -20
- package/output/solve/solveSystem.d.ts +1 -1
- package/output/solve/solveSystem.js +8 -32
- package/output/solve/utils.d.ts +2 -1
- package/output/solve/utils.js +18 -22
- package/output/utils/array.d.ts +1 -1
- package/output/utils/debug.js +2 -1
- package/package.json +22 -38
- package/dist/parser.js +0 -2
- package/dist/parser.js.LICENSE.txt +0 -7
- package/docs-data/parser-functions.json +0 -1960
- package/output/algebra/algorithms/factor.d.ts +0 -3
- package/output/algebra/algorithms/factor.js +0 -5
- package/output/algebra/algorithms/factorMultivariate.d.ts +0 -23
- package/output/algebra/algorithms/factorMultivariate.js +0 -2393
- package/output/algebra/algorithms/factorUnivariate.d.ts +0 -72
- package/output/algebra/algorithms/factorUnivariate.js +0 -1072
- package/output/algebra/algorithms/gcd.d.ts +0 -22
- package/output/algebra/algorithms/gcd.js +0 -690
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +0 -137
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +0 -346
- package/output/algebra/algorithms/poly.d.ts +0 -228
- package/output/algebra/algorithms/poly.js +0 -1299
- package/output/algebra/algorithms/rational.d.ts +0 -17
- package/output/algebra/algorithms/rational.js +0 -115
- package/output/core/adapters.js +0 -40
- package/output/core/classes/parser/operations/comma.d.ts +0 -7
- package/output/core/classes/parser/operations/comma.js +0 -11
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatMultiplierString = formatMultiplierString;
|
|
4
4
|
exports.formatPowerString = formatPowerString;
|
|
5
|
+
exports.toDefaultText = toDefaultText;
|
|
5
6
|
exports.toText = toText;
|
|
6
7
|
exports.formatExpressionString = formatExpressionString;
|
|
7
8
|
exports.convertToTitle = convertToTitle;
|
|
@@ -21,14 +22,18 @@ function formatMultiplierString(x, options) {
|
|
|
21
22
|
let retval = '';
|
|
22
23
|
const m = x.getMultiplier();
|
|
23
24
|
const mString = m.text(options);
|
|
24
|
-
|
|
25
|
+
const isScientific = options?.scientific !== undefined;
|
|
26
|
+
const isUnit = isScientific ? m.isOne() : mString === '1' || mString === '1.0';
|
|
27
|
+
if (!isUnit) {
|
|
25
28
|
retval = mString;
|
|
26
|
-
if (!m.isInteger() && !(m.asDecimal || options?.decimal)) {
|
|
29
|
+
if (!m.isInteger() && !(m.asDecimal || options?.decimal || options?.scientific)) {
|
|
27
30
|
retval = `(${retval})`;
|
|
28
31
|
}
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
// Keep the established display behavior for approximate decimal values that render as -1.0.
|
|
33
|
+
const isMinusUnit = isScientific
|
|
34
|
+
? m.isMinusOne()
|
|
35
|
+
: mString === '-1' || mString === '-1.0';
|
|
36
|
+
if (isMinusUnit && !options?.wrapPow) {
|
|
32
37
|
retval = '-';
|
|
33
38
|
}
|
|
34
39
|
else {
|
|
@@ -49,7 +54,11 @@ function formatMultiplierString(x, options) {
|
|
|
49
54
|
function formatPowerString(x, options, powerOperator) {
|
|
50
55
|
let retval = '';
|
|
51
56
|
const power = x.getPower();
|
|
52
|
-
const
|
|
57
|
+
const powerOptions = {
|
|
58
|
+
...options,
|
|
59
|
+
exactScientific: true,
|
|
60
|
+
};
|
|
61
|
+
const powerString = power.text(powerOptions);
|
|
53
62
|
if (powerString !== '1' && powerString !== '1.0') {
|
|
54
63
|
retval = powerString;
|
|
55
64
|
// Wrap fractions in brackets
|
|
@@ -81,6 +90,120 @@ function formatPowerString(x, options, powerOperator) {
|
|
|
81
90
|
}
|
|
82
91
|
return retval;
|
|
83
92
|
}
|
|
93
|
+
function formatDefaultPowerString(x, powerOperator, sortFunction) {
|
|
94
|
+
let retval = '';
|
|
95
|
+
const power = x.getPower();
|
|
96
|
+
const powerString = toDefaultText(power, powerOperator, sortFunction);
|
|
97
|
+
if (powerString !== '1' && powerString !== '1.0') {
|
|
98
|
+
retval = powerString;
|
|
99
|
+
if (power.dataType === constants_1.RATIONAL && !power.isInteger()) {
|
|
100
|
+
retval = `(${retval})`;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
let needsBrackets = false;
|
|
104
|
+
if (power.type === SUM || power.type === PRD) {
|
|
105
|
+
needsBrackets = true;
|
|
106
|
+
}
|
|
107
|
+
else if (x.type === EXP) {
|
|
108
|
+
if (power.isNUM() && !power.isInteger()) {
|
|
109
|
+
needsBrackets = true;
|
|
110
|
+
}
|
|
111
|
+
else if (!power.isNUM() && !power.getMultiplier().isOne()) {
|
|
112
|
+
needsBrackets = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (needsBrackets || retval.includes('/')) {
|
|
116
|
+
retval = `(${retval})`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
retval = `${powerOperator}${retval}`;
|
|
120
|
+
}
|
|
121
|
+
return retval;
|
|
122
|
+
}
|
|
123
|
+
function formatDefaultExpressionString(x, powerOperator, sortFunction) {
|
|
124
|
+
const glue = x.type === PRD ? '*' : '+';
|
|
125
|
+
const elements = Object.values(x.getElements());
|
|
126
|
+
if (Settings_1.Settings.SORT_TERMS) {
|
|
127
|
+
elements.sort(sortFunction);
|
|
128
|
+
}
|
|
129
|
+
return elements
|
|
130
|
+
.map(element => {
|
|
131
|
+
let value = toDefaultText(element, powerOperator, sortFunction);
|
|
132
|
+
if (x.type === PRD && element.isSum()) {
|
|
133
|
+
value = `(${value})`;
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
})
|
|
137
|
+
.join(glue)
|
|
138
|
+
.replace('+-', '-');
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Formats the ordinary no-options text form without creating formatting option objects
|
|
142
|
+
* while descending the expression tree.
|
|
143
|
+
*
|
|
144
|
+
* This routine follows the same default rendering rules as {@link toText}. Calls that
|
|
145
|
+
* request explicit formatting options continue through {@link toText}.
|
|
146
|
+
*/
|
|
147
|
+
function toDefaultText(x, powerOperator, sortFunction) {
|
|
148
|
+
let retval = '';
|
|
149
|
+
if (x.type === NUM) {
|
|
150
|
+
retval = x.getMultiplier().text();
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const multiplier = formatMultiplierString(x);
|
|
154
|
+
const power = formatDefaultPowerString(x, powerOperator, sortFunction);
|
|
155
|
+
let value;
|
|
156
|
+
switch (x.type) {
|
|
157
|
+
case VAR:
|
|
158
|
+
case INF:
|
|
159
|
+
retval = `${multiplier}${x.value}`;
|
|
160
|
+
break;
|
|
161
|
+
case FUN: {
|
|
162
|
+
if (x.name === constants_1.SYMBOLIC_ACCESSOR) {
|
|
163
|
+
const args = x.getArguments();
|
|
164
|
+
const target = args[0];
|
|
165
|
+
const indices = args.slice(1);
|
|
166
|
+
retval = `${multiplier}${toDefaultText(target, powerOperator, sortFunction)}[${indices
|
|
167
|
+
.map(index => toDefaultText(index, powerOperator, sortFunction))
|
|
168
|
+
.join(', ')}]`;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
retval = `${multiplier}${x.name || ''}(${x
|
|
172
|
+
.getArguments()
|
|
173
|
+
.map(argument => toDefaultText(argument, powerOperator, sortFunction))
|
|
174
|
+
.join(', ')})`;
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case GRP:
|
|
179
|
+
case SUM:
|
|
180
|
+
value = formatDefaultExpressionString(x, powerOperator, sortFunction);
|
|
181
|
+
value = multiplier || power ? `(${value})` : value;
|
|
182
|
+
retval = `${multiplier}${value}`;
|
|
183
|
+
break;
|
|
184
|
+
case PRD:
|
|
185
|
+
value = formatDefaultExpressionString(x, powerOperator, sortFunction);
|
|
186
|
+
value = power ? `(${value})` : value;
|
|
187
|
+
retval = `${multiplier}${value}`;
|
|
188
|
+
break;
|
|
189
|
+
case EXP: {
|
|
190
|
+
const arg = x.getBase();
|
|
191
|
+
const p = arg.getPower();
|
|
192
|
+
value = toDefaultText(arg, powerOperator, sortFunction);
|
|
193
|
+
if (arg.elements ||
|
|
194
|
+
value.startsWith('-') ||
|
|
195
|
+
value.includes('/') ||
|
|
196
|
+
!(p.isOne() || p.isZero())) {
|
|
197
|
+
value = `(${value})`;
|
|
198
|
+
}
|
|
199
|
+
retval = `${multiplier}${value}`;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
retval += power;
|
|
204
|
+
}
|
|
205
|
+
return retval.replace(/\+-/g, '-');
|
|
206
|
+
}
|
|
84
207
|
/**
|
|
85
208
|
* Formats an expression using the current formatting policy supplied by Expression.
|
|
86
209
|
*
|
|
@@ -92,7 +215,7 @@ function formatPowerString(x, options, powerOperator) {
|
|
|
92
215
|
* @returns
|
|
93
216
|
*/
|
|
94
217
|
function toText(x, options, asId, powerOperator, sortFunction) {
|
|
95
|
-
options = { ...{ precision: x.precision }, ...options };
|
|
218
|
+
options = { ...{ precision: x.precision, scientific: x.scientific }, ...options };
|
|
96
219
|
let retval = '';
|
|
97
220
|
if (x.type === NUM) {
|
|
98
221
|
retval = x.getMultiplier().text(options);
|
|
@@ -23,6 +23,15 @@ export declare function product(...args: Expression[]): Expression;
|
|
|
23
23
|
export declare function sum(...args: Expression[]): Expression;
|
|
24
24
|
/** Removes the power from an Expression. The original object is unchanged. */
|
|
25
25
|
export declare function stripPower(x: Expression): Expression;
|
|
26
|
+
/**
|
|
27
|
+
* Deep-copies an Expression tree without routing every nested node back through the
|
|
28
|
+
* Expression constructor and factory.
|
|
29
|
+
*
|
|
30
|
+
* Expression.hook is still applied once for each copied node, matching the existing
|
|
31
|
+
* copy path. Mutable nested values are recreated so the returned tree remains
|
|
32
|
+
* independent from the source.
|
|
33
|
+
*/
|
|
34
|
+
export declare function cloneExpressionTree(source: Expression): Expression;
|
|
26
35
|
/**
|
|
27
36
|
* Copies over all the properties of the provided symbolic essentially cloning it to x.
|
|
28
37
|
*
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.product = product;
|
|
4
4
|
exports.sum = sum;
|
|
5
5
|
exports.stripPower = stripPower;
|
|
6
|
+
exports.cloneExpressionTree = cloneExpressionTree;
|
|
6
7
|
exports.copyOver = copyOver;
|
|
7
8
|
exports.toArrays = toArrays;
|
|
8
9
|
exports.largestPower = largestPower;
|
|
@@ -10,7 +11,6 @@ exports.assertPlainVariableAndGetString = assertPlainVariableAndGetString;
|
|
|
10
11
|
exports.getNumericOrAssumedValue = getNumericOrAssumedValue;
|
|
11
12
|
const errors_1 = require("../../errors");
|
|
12
13
|
const assume_1 = require("../assumption/assume");
|
|
13
|
-
const Rational_1 = require("../rational/Rational");
|
|
14
14
|
const Expression_1 = require("./Expression");
|
|
15
15
|
const shortcuts_1 = require("./shortcuts");
|
|
16
16
|
/** Multiplies a series of Expressions into one product. */
|
|
@@ -35,6 +35,51 @@ function stripPower(x) {
|
|
|
35
35
|
delete retval.power;
|
|
36
36
|
return retval;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Deep-copies an Expression tree without routing every nested node back through the
|
|
40
|
+
* Expression constructor and factory.
|
|
41
|
+
*
|
|
42
|
+
* Expression.hook is still applied once for each copied node, matching the existing
|
|
43
|
+
* copy path. Mutable nested values are recreated so the returned tree remains
|
|
44
|
+
* independent from the source.
|
|
45
|
+
*/
|
|
46
|
+
function cloneExpressionTree(source) {
|
|
47
|
+
const hooked = Expression_1.Expression.hook(source);
|
|
48
|
+
if (!Expression_1.Expression.isExpression(hooked)) {
|
|
49
|
+
return Expression_1.Expression.create(hooked);
|
|
50
|
+
}
|
|
51
|
+
const src = hooked;
|
|
52
|
+
const target = Object.create(Expression_1.Expression.prototype);
|
|
53
|
+
target.dataType = src.dataType;
|
|
54
|
+
target.deferred = src.deferred;
|
|
55
|
+
target.isEnumerable = src.isEnumerable;
|
|
56
|
+
target.type = src.type;
|
|
57
|
+
target.value = src.value;
|
|
58
|
+
target.precision = src.precision;
|
|
59
|
+
target.scientific = src.scientific;
|
|
60
|
+
if (src.multiplier) {
|
|
61
|
+
target.multiplier = src.multiplier.copy();
|
|
62
|
+
}
|
|
63
|
+
if (src.name !== undefined) {
|
|
64
|
+
target.name = src.name;
|
|
65
|
+
}
|
|
66
|
+
if (src.power) {
|
|
67
|
+
target.power = cloneExpressionTree(src.power);
|
|
68
|
+
}
|
|
69
|
+
if (src.args) {
|
|
70
|
+
target.args = src.args.map(cloneExpressionTree);
|
|
71
|
+
}
|
|
72
|
+
if (src.base) {
|
|
73
|
+
target.base = cloneExpressionTree(src.base);
|
|
74
|
+
}
|
|
75
|
+
if (src.elements) {
|
|
76
|
+
target.elements = {};
|
|
77
|
+
for (const key in src.elements) {
|
|
78
|
+
target.elements[key] = cloneExpressionTree(src.elements[key]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return target;
|
|
82
|
+
}
|
|
38
83
|
/**
|
|
39
84
|
* Copies over all the properties of the provided symbolic essentially cloning it to x.
|
|
40
85
|
*
|
|
@@ -48,7 +93,7 @@ function copyOver(src, target, options) {
|
|
|
48
93
|
};
|
|
49
94
|
// Copy over the multiplier
|
|
50
95
|
if (src.multiplier && !options.omitMultiplier) {
|
|
51
|
-
target.multiplier =
|
|
96
|
+
target.multiplier = src.multiplier.copy();
|
|
52
97
|
}
|
|
53
98
|
// toFunctions have name so we need those copied
|
|
54
99
|
if (src.name !== undefined) {
|
|
@@ -56,30 +101,31 @@ function copyOver(src, target, options) {
|
|
|
56
101
|
}
|
|
57
102
|
// Copy over the power
|
|
58
103
|
if (src.power && !options.omitPower) {
|
|
59
|
-
target.power =
|
|
104
|
+
target.power = cloneExpressionTree(src.power);
|
|
60
105
|
}
|
|
61
106
|
// Copy over the args if any
|
|
62
107
|
if (src.args) {
|
|
63
108
|
target.args = [];
|
|
64
109
|
for (const arg of src.args) {
|
|
65
|
-
target.args.push(
|
|
110
|
+
target.args.push(cloneExpressionTree(arg));
|
|
66
111
|
}
|
|
67
112
|
}
|
|
68
113
|
// Copy over the base if an
|
|
69
114
|
if (src.base) {
|
|
70
|
-
target.base = src.base
|
|
115
|
+
target.base = cloneExpressionTree(src.base);
|
|
71
116
|
}
|
|
72
117
|
// Copy over the elements if any
|
|
73
118
|
if (src.elements) {
|
|
74
119
|
target.elements = {};
|
|
75
120
|
for (const x in src.elements) {
|
|
76
|
-
target.elements[x] =
|
|
121
|
+
target.elements[x] = cloneExpressionTree(src.elements[x]);
|
|
77
122
|
}
|
|
78
123
|
}
|
|
79
124
|
// Last but not least
|
|
80
125
|
target.type = src.type;
|
|
81
126
|
target.value = src.value;
|
|
82
127
|
target.precision = src.precision;
|
|
128
|
+
target.scientific = src.scientific;
|
|
83
129
|
target.deferred = src.deferred;
|
|
84
130
|
return target;
|
|
85
131
|
}
|
|
@@ -115,9 +115,8 @@ export declare class Matrix extends StructuredEntity<Matrix, Vector> {
|
|
|
115
115
|
*/
|
|
116
116
|
each(fn: (e: Expression, i?: string | number, j?: string | number) => Expression | void): Matrix;
|
|
117
117
|
eq(M: ParserEntity): boolean;
|
|
118
|
-
/** Evaluates a copied matrix
|
|
119
|
-
evaluate(): Matrix;
|
|
120
|
-
evaluate(values: ParserValuesObject): ParserEntity;
|
|
118
|
+
/** Evaluates and returns a copied matrix. */
|
|
119
|
+
evaluate(values?: ParserValuesObject): Matrix;
|
|
121
120
|
/** Expands a copied matrix, leaving this one unchanged. */
|
|
122
121
|
expand(): Matrix;
|
|
123
122
|
/** Visits every cell without changing the matrix. */
|
|
@@ -116,12 +116,18 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
116
116
|
__get__(indices) {
|
|
117
117
|
const row = indices[0];
|
|
118
118
|
if (row < 0 || row >= this.elements.length) {
|
|
119
|
-
throw new errors_1.MathError(
|
|
119
|
+
throw new errors_1.MathError((0, errors_1.message)('matrixRowIndexOutOfBounds', {
|
|
120
|
+
index: String(row),
|
|
121
|
+
length: String(this.elements.length),
|
|
122
|
+
}));
|
|
120
123
|
}
|
|
121
124
|
if (indices.length > 1) {
|
|
122
125
|
const col = indices[1];
|
|
123
126
|
if (col < 0 || col >= this.elements[row].length) {
|
|
124
|
-
throw new errors_1.MathError(
|
|
127
|
+
throw new errors_1.MathError((0, errors_1.message)('matrixColumnIndexOutOfBounds', {
|
|
128
|
+
index: String(col),
|
|
129
|
+
length: String(this.elements[row].length),
|
|
130
|
+
}));
|
|
125
131
|
}
|
|
126
132
|
return this.elements[row][col];
|
|
127
133
|
}
|
|
@@ -139,16 +145,22 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
139
145
|
*/
|
|
140
146
|
__set__(indices, value) {
|
|
141
147
|
if (typeof indices === 'string') {
|
|
142
|
-
throw new errors_1.MathError(
|
|
148
|
+
throw new errors_1.MathError((0, errors_1.message)('matrixStringKeyUnsupported'));
|
|
143
149
|
}
|
|
144
150
|
const row = indices[0];
|
|
145
151
|
const col = indices.length > 1 ? indices[1] : undefined;
|
|
146
152
|
if (row < 0 || row >= this.elements.length) {
|
|
147
|
-
throw new errors_1.MathError(
|
|
153
|
+
throw new errors_1.MathError((0, errors_1.message)('matrixRowIndexOutOfBounds', {
|
|
154
|
+
index: String(row),
|
|
155
|
+
length: String(this.elements.length),
|
|
156
|
+
}));
|
|
148
157
|
}
|
|
149
158
|
if (col !== undefined) {
|
|
150
159
|
if (col < 0 || col >= this.elements[row].length) {
|
|
151
|
-
throw new errors_1.MathError(
|
|
160
|
+
throw new errors_1.MathError((0, errors_1.message)('matrixColumnIndexOutOfBounds', {
|
|
161
|
+
index: String(col),
|
|
162
|
+
length: String(this.elements[row].length),
|
|
163
|
+
}));
|
|
152
164
|
}
|
|
153
165
|
this.elements[row][col] = Expression_1.Expression.create(value);
|
|
154
166
|
}
|
|
@@ -209,8 +221,7 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
209
221
|
}
|
|
210
222
|
/** Copies the matrix and every Expression element. */
|
|
211
223
|
copy() {
|
|
212
|
-
|
|
213
|
-
return this.copySymbolicAccessTo(copy);
|
|
224
|
+
return this.map(e => e.copy());
|
|
214
225
|
}
|
|
215
226
|
/**
|
|
216
227
|
* Computes the determinant by triangular elimination.
|
|
@@ -295,18 +306,11 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
295
306
|
}
|
|
296
307
|
return true;
|
|
297
308
|
}
|
|
309
|
+
/** Evaluates and returns a copied matrix. */
|
|
298
310
|
evaluate(values) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
retval = symbolicAccess.evaluate(values);
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
const copy = this.copy();
|
|
306
|
-
copy.each(e => e.evaluate(values));
|
|
307
|
-
retval = copy;
|
|
308
|
-
}
|
|
309
|
-
return retval;
|
|
311
|
+
const copy = this.copy();
|
|
312
|
+
copy.each(e => e.evaluate(values));
|
|
313
|
+
return copy;
|
|
310
314
|
}
|
|
311
315
|
/** Expands a copied matrix, leaving this one unchanged. */
|
|
312
316
|
expand() {
|
|
@@ -425,7 +429,7 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
425
429
|
return new Matrix(...inverseElements);
|
|
426
430
|
}
|
|
427
431
|
isSingular() {
|
|
428
|
-
return this.isSquare() && this.determinant().eq(
|
|
432
|
+
return this.isSquare() && this.determinant().eq((0, shortcuts_1.zero)());
|
|
429
433
|
}
|
|
430
434
|
isSquare() {
|
|
431
435
|
return this.rows() === this.cols();
|
|
@@ -727,8 +731,7 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
727
731
|
}
|
|
728
732
|
textArray.push(`[${rowTextArray.join(', ')}]`);
|
|
729
733
|
}
|
|
730
|
-
|
|
731
|
-
return this.formatSymbolicAccess(text);
|
|
734
|
+
return `matrix(${textArray.join(', ')})`;
|
|
732
735
|
}
|
|
733
736
|
times(M) {
|
|
734
737
|
let retval;
|
|
@@ -844,14 +847,14 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
844
847
|
*/
|
|
845
848
|
trace() {
|
|
846
849
|
if (!this.isSquare()) {
|
|
847
|
-
throw new errors_1.MathError(
|
|
850
|
+
throw new errors_1.MathError((0, errors_1.message)('matrixTraceUnavailable'));
|
|
848
851
|
}
|
|
849
852
|
let tr = (0, shortcuts_1.zero)();
|
|
850
853
|
const n = this.elements.length;
|
|
851
854
|
for (let i = 0; i < n; i++) {
|
|
852
855
|
const e = this.elements[i][i];
|
|
853
856
|
if (!Expression_1.Expression.isExpression(e)) {
|
|
854
|
-
throw new errors_1.MathError(
|
|
857
|
+
throw new errors_1.MathError((0, errors_1.message)('matrixTraceUnavailable'));
|
|
855
858
|
}
|
|
856
859
|
tr = tr.plus(e);
|
|
857
860
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadMatrixFunctions(): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadMatrixFunctions = loadMatrixFunctions;
|
|
4
|
+
const math_1 = require("../../../math/math");
|
|
5
|
+
const dispatch_1 = require("../../dispatch");
|
|
6
|
+
const functions_1 = require("./functions");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
function loadMatrixFunctions() {
|
|
9
|
+
Object.assign(dispatch_1.mathFunctionRegistry, {
|
|
10
|
+
matrix: (0, dispatch_1.systemFunction)({ fn: math_1.matrix, minArgs: 1, maxArgs: -1, distElWise: false }),
|
|
11
|
+
imatrix: (0, dispatch_1.systemFunction)({ fn: utils_1.imatrix, minArgs: 1, maxArgs: 1, distElWise: false }),
|
|
12
|
+
determinant: (0, dispatch_1.systemFunction)({ fn: functions_1.determinant, minArgs: 1, maxArgs: 1, distElWise: false }),
|
|
13
|
+
invert: (0, dispatch_1.systemFunction)({ fn: functions_1.invert, minArgs: 1, maxArgs: 1, distElWise: false }),
|
|
14
|
+
transpose: (0, dispatch_1.systemFunction)({ fn: (M) => M.transpose(), minArgs: 1, maxArgs: 1, distElWise: false }),
|
|
15
|
+
augment: (0, dispatch_1.systemFunction)({ fn: (M, N) => M.augment(N), minArgs: 2, maxArgs: 2, distElWise: false }),
|
|
16
|
+
rref: (0, dispatch_1.systemFunction)({ fn: (M, prime) => M.rref(prime), minArgs: 1, maxArgs: 2, distElWise: false }),
|
|
17
|
+
nullspace: (0, dispatch_1.systemFunction)({ fn: functions_1.nullspace, minArgs: 1, maxArgs: 2, distElWise: false }),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -7,6 +7,8 @@ import { Matrix } from './Matrix';
|
|
|
7
7
|
* @throws {@link core!UnsupportedOperationError} If `M` is not square.
|
|
8
8
|
*/
|
|
9
9
|
export declare function determinant(M: Matrix): Expression;
|
|
10
|
+
/** Returns the inverse without modifying the supplied Matrix. */
|
|
11
|
+
export declare function invert(M: Matrix): Matrix;
|
|
10
12
|
/** Returns the nullspace basis as a Vector of basis vectors. */
|
|
11
13
|
export declare function nullspace(M: Matrix, prime?: string | number | Expression): Vector;
|
|
12
14
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.determinant = determinant;
|
|
4
|
+
exports.invert = invert;
|
|
4
5
|
exports.nullspace = nullspace;
|
|
5
6
|
exports.characteristicPolynomial = characteristicPolynomial;
|
|
6
7
|
const errors_1 = require("../../errors");
|
|
@@ -15,6 +16,10 @@ const Matrix_1 = require("./Matrix");
|
|
|
15
16
|
function determinant(M) {
|
|
16
17
|
return M.copy().determinant();
|
|
17
18
|
}
|
|
19
|
+
/** Returns the inverse without modifying the supplied Matrix. */
|
|
20
|
+
function invert(M) {
|
|
21
|
+
return M.inverse();
|
|
22
|
+
}
|
|
18
23
|
/** Returns the nullspace basis as a Vector of basis vectors. */
|
|
19
24
|
function nullspace(M, prime) {
|
|
20
25
|
return new Vector_1.Vector(M.nullspace(prime).map(vector => new Vector_1.Vector(vector)));
|
|
@@ -62,6 +62,19 @@ declare class ExpressionParser {
|
|
|
62
62
|
* result, so ordinary substitution does not hand out the stored object itself.
|
|
63
63
|
*/
|
|
64
64
|
KNOWN_VALUES: Record<string, ParserEntity>;
|
|
65
|
+
/**
|
|
66
|
+
* Resolves a Dictionary index through the active parser scope.
|
|
67
|
+
*
|
|
68
|
+
* A plain variable index is resolved directly instead of reparsing its square
|
|
69
|
+
* scope. This matters for deferred scripting bodies, where LET installs the
|
|
70
|
+
* current binding in KNOWN_VALUES while excluding that name from inherited
|
|
71
|
+
* call-scoped substitutions.
|
|
72
|
+
*
|
|
73
|
+
* An unresolved symbolic index remains its own textual key, so d[x] still
|
|
74
|
+
* addresses the literal key "x". Computed indices continue through the normal
|
|
75
|
+
* parser path.
|
|
76
|
+
*/
|
|
77
|
+
private extractDictionaryKey;
|
|
65
78
|
/**
|
|
66
79
|
* Converts an index scope to the zero-based indices used internally.
|
|
67
80
|
*
|
|
@@ -72,11 +85,11 @@ declare class ExpressionParser {
|
|
|
72
85
|
*/
|
|
73
86
|
private extractIndices;
|
|
74
87
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
88
|
+
* Resolves or preserves symbolic bracket access after the target and indices have
|
|
89
|
+
* been parsed. Vector and Matrix arity is checked here so direct bracket parsing
|
|
90
|
+
* and reevaluation of a preserved accessor follow the same rules.
|
|
78
91
|
*/
|
|
79
|
-
private
|
|
92
|
+
private resolveSymbolicAccess;
|
|
80
93
|
/** Creates another spelling for an existing operator without changing its action. */
|
|
81
94
|
aliasOperator(symbol: string, alias: string): this;
|
|
82
95
|
/**
|
|
@@ -134,7 +147,7 @@ declare class ExpressionParser {
|
|
|
134
147
|
* const indexBase = Parser.get('INDEX_BASE');
|
|
135
148
|
* ```
|
|
136
149
|
*/
|
|
137
|
-
get(setting: keyof typeof Settings): number | bigint | boolean | "
|
|
150
|
+
get(setting: keyof typeof Settings): number | bigint | boolean | import("../../errors").Language;
|
|
138
151
|
/**
|
|
139
152
|
* Returns the symbol currently reserved for the imaginary unit.
|
|
140
153
|
*
|
|
@@ -165,6 +178,19 @@ declare class ExpressionParser {
|
|
|
165
178
|
* @returns The configured number of significant digits.
|
|
166
179
|
*/
|
|
167
180
|
getPrecision(): number;
|
|
181
|
+
/**
|
|
182
|
+
* Reports whether a name is reserved by Nerdamer's parser or solver conventions.
|
|
183
|
+
*
|
|
184
|
+
* @remarks
|
|
185
|
+
* The result reflects the current process-wide parser state. In particular, changing
|
|
186
|
+
* the imaginary-unit symbol through {@link setI} removes the previous symbol from the
|
|
187
|
+
* restricted-name list and reserves the replacement. Solver-specific names such as
|
|
188
|
+
* `_n` and `all` are also reserved.
|
|
189
|
+
*
|
|
190
|
+
* @param name - Variable or symbol name to test.
|
|
191
|
+
* @returns Whether Nerdamer currently reserves the name.
|
|
192
|
+
*/
|
|
193
|
+
isReserved(name: string): boolean;
|
|
168
194
|
/**
|
|
169
195
|
* Parses supported expression input into a Nerdamer parser entity.
|
|
170
196
|
*
|