nerdamer 2.0.0-rc.2 → 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/README.md +11 -5
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.LICENSE.txt +6 -6
- package/output/algebra/dispatch.js +1 -1
- package/output/algebra/partfrac.js +1 -1
- package/output/algebra/simplify/funcsimp.js +1 -1
- package/output/algebra/simplify/ratsimp.js +1 -1
- package/output/algebra/utils.d.ts +1 -1
- package/output/algebra/utils.js +3 -3
- package/output/api/algebra.d.ts +19 -2
- package/output/api/algebra.js +18 -2
- package/output/api/assumptions.d.ts +1 -1
- package/output/api/assumptions.js +2 -1
- package/output/api/core.d.ts +28 -7
- package/output/api/core.js +28 -2
- package/output/calculus/derivative/diff.js +1 -1
- package/output/calculus/dispatch.js +2 -2
- 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/assume.d.ts +6 -0
- package/output/core/classes/assumption/assume.js +9 -0
- package/output/core/classes/expression/CoeffObject.d.ts +1 -1
- package/output/core/classes/expression/Expression.d.ts +8 -16
- package/output/core/classes/expression/Expression.js +11 -33
- package/output/core/classes/matrix/Matrix.d.ts +2 -3
- package/output/core/classes/matrix/Matrix.js +7 -16
- package/output/core/classes/matrix/dispatch.js +1 -1
- package/output/core/classes/parser/Parser.d.ts +17 -4
- package/output/core/classes/parser/Parser.js +312 -450
- package/output/core/classes/parser/operations/functions.d.ts +3 -4
- package/output/core/classes/parser/operations/functions.js +35 -97
- package/output/core/classes/parser/operations/power.js +2 -2
- package/output/core/classes/parser/preprocess.js +14 -7
- package/output/core/classes/parser/scripting/controlFlow.js +49 -25
- package/output/core/classes/parser/scripting/deferred.d.ts +1 -1
- package/output/core/classes/parser/scripting/deferred.js +1 -1
- package/output/core/classes/parser/scripting/scope.js +38 -19
- package/output/core/classes/parser/types.d.ts +0 -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.js +1 -1
- package/output/core/classes/polynomial/SparsePolynomial.d.ts +11 -11
- package/output/core/classes/polynomial/SparsePolynomial.js +65 -65
- package/output/core/classes/vector/Vector.d.ts +2 -3
- package/output/core/classes/vector/Vector.js +6 -14
- package/output/core/common/classes/StructuredEntity.d.ts +0 -17
- package/output/core/common/classes/StructuredEntity.js +3 -64
- package/output/core/converters/BaseConverter.js +2 -1
- package/output/core/fullFunctions.js +14 -14
- package/output/core/functions/bigint/bigint.d.ts +1 -1
- package/output/core/functions/numeric.d.ts +1 -1
- package/output/core/parserFunctions.js +10 -10
- package/output/index.d.ts +29 -29
- package/output/index.js +124 -20
- package/output/math/dispatch.js +1 -1
- package/output/math/math.js +21 -21
- package/output/math/trig.js +4 -4
- package/output/solve/solve.js +1 -1
- package/package.json +34 -15
- package/dist/parser.js +0 -2
- package/dist/parser.js.LICENSE.txt +0 -7
- package/docs-data/parser-functions.json +0 -2248
- package/output/core/classes/parser/operations/comma.d.ts +0 -7
- package/output/core/classes/parser/operations/comma.js +0 -11
|
@@ -74,6 +74,12 @@ export declare function forgetAssumptionFor(x: Expression | string): void;
|
|
|
74
74
|
* @param x - Plain variable expression or variable name.
|
|
75
75
|
* @returns The registered interval, or `undefined` when no assumption is available.
|
|
76
76
|
*/
|
|
77
|
+
/**
|
|
78
|
+
* Returns a snapshot of all currently registered assumptions.
|
|
79
|
+
*
|
|
80
|
+
* Changing the returned Map does not change Nerdamer's active assumptions.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getAssumptions(): Map<string, Assumption>;
|
|
77
83
|
export declare function getAssumptionFor(x: Expression | string): Assumption | undefined;
|
|
78
84
|
/**
|
|
79
85
|
* Parser marker used by `assume(...)` so comparison operators register constraints
|
|
@@ -4,6 +4,7 @@ exports.hasAssumptions = hasAssumptions;
|
|
|
4
4
|
exports.assume = assume;
|
|
5
5
|
exports.clearAssumptions = clearAssumptions;
|
|
6
6
|
exports.forgetAssumptionFor = forgetAssumptionFor;
|
|
7
|
+
exports.getAssumptions = getAssumptions;
|
|
7
8
|
exports.getAssumptionFor = getAssumptionFor;
|
|
8
9
|
exports.assuming = assuming;
|
|
9
10
|
exports.forget = forget;
|
|
@@ -110,6 +111,14 @@ function forgetAssumptionFor(x) {
|
|
|
110
111
|
* @param x - Plain variable expression or variable name.
|
|
111
112
|
* @returns The registered interval, or `undefined` when no assumption is available.
|
|
112
113
|
*/
|
|
114
|
+
/**
|
|
115
|
+
* Returns a snapshot of all currently registered assumptions.
|
|
116
|
+
*
|
|
117
|
+
* Changing the returned Map does not change Nerdamer's active assumptions.
|
|
118
|
+
*/
|
|
119
|
+
function getAssumptions() {
|
|
120
|
+
return new Map(ASSUMPTIONS);
|
|
121
|
+
}
|
|
113
122
|
function getAssumptionFor(x) {
|
|
114
123
|
let symbol;
|
|
115
124
|
if (Expression_1.Expression.isExpression(x) && x.isPlainVariable()) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Polynomial } from '../polynomial/Polynomial';
|
|
2
2
|
import { Vector } from '../vector/Vector';
|
|
3
|
-
import { Expression } from './Expression';
|
|
3
|
+
import type { Expression } from './Expression';
|
|
4
4
|
/**
|
|
5
5
|
* Stores coefficients indexed by the power or multidegree collected from an expression.
|
|
6
6
|
*
|
|
@@ -122,6 +122,13 @@ export declare class Expression implements Base<Expression> {
|
|
|
122
122
|
VEC: number;
|
|
123
123
|
MAT: number;
|
|
124
124
|
};
|
|
125
|
+
/**
|
|
126
|
+
* Cached ordinary lookup key for SUM and PRD nodes.
|
|
127
|
+
*
|
|
128
|
+
* Copies intentionally start without this cache. Aggregate reconstruction clears it
|
|
129
|
+
* through updateValue() before the node is used again.
|
|
130
|
+
*/
|
|
131
|
+
private _keyValueCache?;
|
|
125
132
|
/**
|
|
126
133
|
* Arguments stored by a function node.
|
|
127
134
|
*
|
|
@@ -149,13 +156,6 @@ export declare class Expression implements Base<Expression> {
|
|
|
149
156
|
* responsible for preserving a valid expression representation and regenerating derived values.
|
|
150
157
|
*/
|
|
151
158
|
elements?: Record<string, Expression>;
|
|
152
|
-
/**
|
|
153
|
-
* Cached ordinary lookup key for SUM and PRD nodes.
|
|
154
|
-
*
|
|
155
|
-
* Copies intentionally start without this cache. Aggregate reconstruction clears it
|
|
156
|
-
* through updateValue() before the node is used again.
|
|
157
|
-
*/
|
|
158
|
-
private _keyValueCache?;
|
|
159
159
|
/**
|
|
160
160
|
* Let's the parser know not to treat it as a set of values
|
|
161
161
|
*/
|
|
@@ -274,14 +274,6 @@ export declare class Expression implements Base<Expression> {
|
|
|
274
274
|
* ```
|
|
275
275
|
*/
|
|
276
276
|
static fromRational(x: Rational): Expression;
|
|
277
|
-
/**
|
|
278
|
-
* Converts a structured entity carrying symbolic bracket access into the scalar
|
|
279
|
-
* Expression form used by ordinary algebra and function nodes.
|
|
280
|
-
*
|
|
281
|
-
* Structured entities without symbolic access are left unchanged by returning
|
|
282
|
-
* `undefined`; callers can then apply their normal conversion rules.
|
|
283
|
-
*/
|
|
284
|
-
static fromSymbolicAccess(x: NerdamerInput): Expression | undefined;
|
|
285
277
|
/**
|
|
286
278
|
* Creates a symbolic function node with the given name.
|
|
287
279
|
*
|
|
@@ -1498,7 +1490,7 @@ export declare class Expression implements Base<Expression> {
|
|
|
1498
1490
|
*/
|
|
1499
1491
|
sptext(options?: TextOptions, asId?: boolean): string;
|
|
1500
1492
|
/**
|
|
1501
|
-
* Squares this Expression.
|
|
1493
|
+
* Squares this Expression.
|
|
1502
1494
|
*
|
|
1503
1495
|
* @returns A new Expression representing `this²`.
|
|
1504
1496
|
*
|
|
@@ -163,6 +163,13 @@ class Expression {
|
|
|
163
163
|
};
|
|
164
164
|
/** Internal expression-type constants used by parser and algebra code. */
|
|
165
165
|
static TYPES = constants_1.EXPRESSION_TYPES;
|
|
166
|
+
/**
|
|
167
|
+
* Cached ordinary lookup key for SUM and PRD nodes.
|
|
168
|
+
*
|
|
169
|
+
* Copies intentionally start without this cache. Aggregate reconstruction clears it
|
|
170
|
+
* through updateValue() before the node is used again.
|
|
171
|
+
*/
|
|
172
|
+
_keyValueCache;
|
|
166
173
|
/**
|
|
167
174
|
* Arguments stored by a function node.
|
|
168
175
|
*
|
|
@@ -190,13 +197,6 @@ class Expression {
|
|
|
190
197
|
* responsible for preserving a valid expression representation and regenerating derived values.
|
|
191
198
|
*/
|
|
192
199
|
elements = undefined;
|
|
193
|
-
/**
|
|
194
|
-
* Cached ordinary lookup key for SUM and PRD nodes.
|
|
195
|
-
*
|
|
196
|
-
* Copies intentionally start without this cache. Aggregate reconstruction clears it
|
|
197
|
-
* through updateValue() before the node is used again.
|
|
198
|
-
*/
|
|
199
|
-
_keyValueCache;
|
|
200
200
|
/**
|
|
201
201
|
* Let's the parser know not to treat it as a set of values
|
|
202
202
|
*/
|
|
@@ -354,28 +354,6 @@ class Expression {
|
|
|
354
354
|
retval.getMultiplier().asDecimal = x.asDecimal;
|
|
355
355
|
return retval;
|
|
356
356
|
}
|
|
357
|
-
/**
|
|
358
|
-
* Converts a structured entity carrying symbolic bracket access into the scalar
|
|
359
|
-
* Expression form used by ordinary algebra and function nodes.
|
|
360
|
-
*
|
|
361
|
-
* Structured entities without symbolic access are left unchanged by returning
|
|
362
|
-
* `undefined`; callers can then apply their normal conversion rules.
|
|
363
|
-
*/
|
|
364
|
-
static fromSymbolicAccess(x) {
|
|
365
|
-
let retval;
|
|
366
|
-
if (typeof x === 'object' && x !== null) {
|
|
367
|
-
const structured = x;
|
|
368
|
-
const target = structured.symbolicTarget;
|
|
369
|
-
const indices = structured.symbolicAccessor;
|
|
370
|
-
if (Expression.isExpression(target) &&
|
|
371
|
-
indices &&
|
|
372
|
-
indices.length > 0 &&
|
|
373
|
-
indices.every(index => Expression.isExpression(index))) {
|
|
374
|
-
retval = Expression.toAccessor(target, indices);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return retval;
|
|
378
|
-
}
|
|
379
357
|
/**
|
|
380
358
|
* Creates a symbolic function node with the given name.
|
|
381
359
|
*
|
|
@@ -649,7 +627,7 @@ class Expression {
|
|
|
649
627
|
.filter((x) => {
|
|
650
628
|
return x !== undefined;
|
|
651
629
|
})
|
|
652
|
-
.map(x => Expression.
|
|
630
|
+
.map(x => Expression.create(x));
|
|
653
631
|
// Set the name
|
|
654
632
|
f.name = name;
|
|
655
633
|
// TODO: This needs to be generated the same way as in text.
|
|
@@ -975,7 +953,7 @@ class Expression {
|
|
|
975
953
|
: this.text();
|
|
976
954
|
}
|
|
977
955
|
const evaluated = Parser_1.Parser.evaluate(source, values);
|
|
978
|
-
const retval = Expression.
|
|
956
|
+
const retval = Expression.create(evaluated);
|
|
979
957
|
if (this.scientific !== undefined) {
|
|
980
958
|
retval.scientific = this.scientific;
|
|
981
959
|
}
|
|
@@ -2085,7 +2063,7 @@ class Expression {
|
|
|
2085
2063
|
return txt;
|
|
2086
2064
|
}
|
|
2087
2065
|
/**
|
|
2088
|
-
* Squares this Expression.
|
|
2066
|
+
* Squares this Expression.
|
|
2089
2067
|
*
|
|
2090
2068
|
* @returns A new Expression representing `this²`.
|
|
2091
2069
|
*
|
|
@@ -2096,7 +2074,7 @@ class Expression {
|
|
|
2096
2074
|
* ```
|
|
2097
2075
|
*/
|
|
2098
2076
|
sq() {
|
|
2099
|
-
return this.pow(
|
|
2077
|
+
return this.pow((0, shortcuts_1.two)());
|
|
2100
2078
|
}
|
|
2101
2079
|
/**
|
|
2102
2080
|
* Tests Nerdamer equality while also requiring the same top-level internal type.
|
|
@@ -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. */
|
|
@@ -221,8 +221,7 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
221
221
|
}
|
|
222
222
|
/** Copies the matrix and every Expression element. */
|
|
223
223
|
copy() {
|
|
224
|
-
|
|
225
|
-
return this.copySymbolicAccessTo(copy);
|
|
224
|
+
return this.map(e => e.copy());
|
|
226
225
|
}
|
|
227
226
|
/**
|
|
228
227
|
* Computes the determinant by triangular elimination.
|
|
@@ -307,18 +306,11 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
307
306
|
}
|
|
308
307
|
return true;
|
|
309
308
|
}
|
|
309
|
+
/** Evaluates and returns a copied matrix. */
|
|
310
310
|
evaluate(values) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
retval = symbolicAccess.evaluate(values);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
const copy = this.copy();
|
|
318
|
-
copy.each(e => e.evaluate(values));
|
|
319
|
-
retval = copy;
|
|
320
|
-
}
|
|
321
|
-
return retval;
|
|
311
|
+
const copy = this.copy();
|
|
312
|
+
copy.each(e => e.evaluate(values));
|
|
313
|
+
return copy;
|
|
322
314
|
}
|
|
323
315
|
/** Expands a copied matrix, leaving this one unchanged. */
|
|
324
316
|
expand() {
|
|
@@ -437,7 +429,7 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
437
429
|
return new Matrix(...inverseElements);
|
|
438
430
|
}
|
|
439
431
|
isSingular() {
|
|
440
|
-
return this.isSquare() && this.determinant().eq(
|
|
432
|
+
return this.isSquare() && this.determinant().eq((0, shortcuts_1.zero)());
|
|
441
433
|
}
|
|
442
434
|
isSquare() {
|
|
443
435
|
return this.rows() === this.cols();
|
|
@@ -739,8 +731,7 @@ class Matrix extends StructuredEntity_1.StructuredEntity {
|
|
|
739
731
|
}
|
|
740
732
|
textArray.push(`[${rowTextArray.join(', ')}]`);
|
|
741
733
|
}
|
|
742
|
-
|
|
743
|
-
return this.formatSymbolicAccess(text);
|
|
734
|
+
return `matrix(${textArray.join(', ')})`;
|
|
744
735
|
}
|
|
745
736
|
times(M) {
|
|
746
737
|
let retval;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadMatrixFunctions = loadMatrixFunctions;
|
|
4
|
+
const math_1 = require("../../../math/math");
|
|
4
5
|
const dispatch_1 = require("../../dispatch");
|
|
5
6
|
const functions_1 = require("./functions");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
|
-
const math_1 = require("../../../math/math");
|
|
8
8
|
function loadMatrixFunctions() {
|
|
9
9
|
Object.assign(dispatch_1.mathFunctionRegistry, {
|
|
10
10
|
matrix: (0, dispatch_1.systemFunction)({ fn: math_1.matrix, minArgs: 1, maxArgs: -1, distElWise: false }),
|
|
@@ -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
|
/**
|