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
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Rational = void 0;
|
|
6
|
+
exports.Rational = exports.MAX_SCIENTIFIC_SIGNIFICANT_DIGITS = void 0;
|
|
7
|
+
exports.validateScientificSignificantDigits = validateScientificSignificantDigits;
|
|
7
8
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
9
|
const common_1 = require("../../common/common");
|
|
9
10
|
const errors_1 = require("../../errors");
|
|
@@ -12,6 +13,20 @@ const bigint_2 = require("../../functions/bigint/bigint");
|
|
|
12
13
|
const string_1 = require("../../functions/string");
|
|
13
14
|
const Expression_1 = require("../expression/Expression");
|
|
14
15
|
const constants_1 = require("../parser/constants");
|
|
16
|
+
/** Maximum scientific significant-digit count accepted by decimal.js. */
|
|
17
|
+
exports.MAX_SCIENTIFIC_SIGNIFICANT_DIGITS = 1_000_000_000;
|
|
18
|
+
function validateScientificSignificantDigits(value, received = String(value)) {
|
|
19
|
+
if (typeof value !== 'number' ||
|
|
20
|
+
!Number.isInteger(value) ||
|
|
21
|
+
value < 1 ||
|
|
22
|
+
value > exports.MAX_SCIENTIFIC_SIGNIFICANT_DIGITS) {
|
|
23
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('wrongInput', {
|
|
24
|
+
expected: `an integer from 1 to ${exports.MAX_SCIENTIFIC_SIGNIFICANT_DIGITS}`,
|
|
25
|
+
received,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
15
30
|
/**
|
|
16
31
|
* Represents an exact rational value as a `bigint` numerator and denominator.
|
|
17
32
|
*
|
|
@@ -231,19 +246,6 @@ class Rational {
|
|
|
231
246
|
}
|
|
232
247
|
return retval;
|
|
233
248
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Copies a rational's representation and presentation metadata.
|
|
236
|
-
*
|
|
237
|
-
* @param x - Rational to copy.
|
|
238
|
-
* @returns A distinct `Rational` with the same numerator, denominator, `value`, and
|
|
239
|
-
* decimal-presentation flag.
|
|
240
|
-
*/
|
|
241
|
-
static makeCopy(x) {
|
|
242
|
-
const copy = new Rational(x.numerator, x.denominator);
|
|
243
|
-
copy.value = x.value;
|
|
244
|
-
copy.asDecimal = x.asDecimal;
|
|
245
|
-
return copy;
|
|
246
|
-
}
|
|
247
249
|
/**
|
|
248
250
|
* Updates shared numeric settings used by rational decimal conversion.
|
|
249
251
|
*
|
|
@@ -286,7 +288,7 @@ class Rational {
|
|
|
286
288
|
}
|
|
287
289
|
// If they want a guaranteed copy then just return a copy
|
|
288
290
|
if (ensureCopy) {
|
|
289
|
-
return
|
|
291
|
+
return x.copy();
|
|
290
292
|
}
|
|
291
293
|
// Otherwise just return the original rational
|
|
292
294
|
return x;
|
|
@@ -308,7 +310,10 @@ class Rational {
|
|
|
308
310
|
* @returns A new object with the same numeric representation and presentation metadata.
|
|
309
311
|
*/
|
|
310
312
|
copy() {
|
|
311
|
-
|
|
313
|
+
const copy = new Rational(this.numerator, this.denominator);
|
|
314
|
+
copy.value = this.value;
|
|
315
|
+
copy.asDecimal = this.asDecimal;
|
|
316
|
+
return copy;
|
|
312
317
|
}
|
|
313
318
|
div(num) {
|
|
314
319
|
let retval;
|
|
@@ -616,21 +621,66 @@ class Rational {
|
|
|
616
621
|
* Formats this rational as fraction, integer, or decimal text.
|
|
617
622
|
*
|
|
618
623
|
* @remarks
|
|
619
|
-
*
|
|
624
|
+
* Scientific formatting is selected when `options.scientific` supplies an integer significant-digit
|
|
625
|
+
* count from 1 through 1e9. The requested count is preserved in the coefficient, including
|
|
626
|
+
* trailing zeroes. Otherwise decimal formatting is selected when {@link Rational.asDecimal} is set or when
|
|
620
627
|
* `options.decimal` is truthy. Non-integer decimal output uses `decimal.js`; an optional
|
|
621
628
|
* `options.precision` temporarily controls its significant-digit precision for this conversion.
|
|
622
629
|
* Integer decimal output includes a `.0` suffix. Without decimal formatting, non-integer
|
|
623
630
|
* fractions are emitted from the stored numerator and denominator, and integers as plain text.
|
|
624
631
|
*
|
|
625
|
-
* @param options - Formatting options. `
|
|
626
|
-
* decimal conversion precision when applicable.
|
|
632
|
+
* @param options - Formatting options. `scientific` selects significant-digit scientific output;
|
|
633
|
+
* `decimal` forces decimal output and `precision` controls decimal conversion precision when applicable.
|
|
627
634
|
* @returns The formatted numeric text.
|
|
628
635
|
*/
|
|
629
636
|
text(options) {
|
|
630
637
|
let value;
|
|
638
|
+
let scientificValue;
|
|
631
639
|
const thisIsInteger = this.isInteger();
|
|
640
|
+
const integerDigits = thisIsInteger
|
|
641
|
+
? (this.numerator < 0n ? -this.numerator : this.numerator).toString().length
|
|
642
|
+
: 0;
|
|
643
|
+
const exactScientific = options?.exactScientific === true;
|
|
644
|
+
const scientificDigits = options && 'scientific' in options && options.scientific !== undefined
|
|
645
|
+
? validateScientificSignificantDigits(options.scientific)
|
|
646
|
+
: undefined;
|
|
647
|
+
if (scientificDigits !== undefined) {
|
|
648
|
+
if (this.isZero()) {
|
|
649
|
+
scientificValue = '0';
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
const previousPrecision = decimal_js_1.default.precision;
|
|
653
|
+
const precision = Math.max(previousPrecision, scientificDigits);
|
|
654
|
+
try {
|
|
655
|
+
if (precision !== previousPrecision) {
|
|
656
|
+
decimal_js_1.default.set({ precision });
|
|
657
|
+
}
|
|
658
|
+
const scientific = this.toDecimal().toExponential(scientificDigits - 1);
|
|
659
|
+
const [coefficient, exponent] = scientific.split('e');
|
|
660
|
+
const normalizedExponent = BigInt(exponent);
|
|
661
|
+
const candidate = normalizedExponent === 0n
|
|
662
|
+
? coefficient
|
|
663
|
+
: `${coefficient}e${normalizedExponent}`;
|
|
664
|
+
if (!exactScientific ||
|
|
665
|
+
(thisIsInteger &&
|
|
666
|
+
integerDigits > scientificDigits &&
|
|
667
|
+
normalizedExponent !== 0n &&
|
|
668
|
+
Rational.create(candidate).eq(this))) {
|
|
669
|
+
scientificValue = candidate;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
finally {
|
|
673
|
+
if (decimal_js_1.default.precision !== previousPrecision) {
|
|
674
|
+
decimal_js_1.default.set({ precision: previousPrecision });
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if (scientificValue !== undefined) {
|
|
680
|
+
value = scientificValue;
|
|
681
|
+
}
|
|
632
682
|
// Mark it as a decimal if it is such
|
|
633
|
-
if (this.asDecimal || options?.decimal) {
|
|
683
|
+
else if (this.asDecimal || options?.decimal) {
|
|
634
684
|
if (thisIsInteger) {
|
|
635
685
|
value = `${this.numerator}.0`;
|
|
636
686
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* SEQ.ts – corrected & optimized */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.Sequence = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
5
5
|
const DEFAULT_MAX_POWER = 50;
|
|
6
6
|
/* ---------- helpers ---------- */
|
|
7
7
|
function factorial(n) {
|
|
@@ -44,7 +44,7 @@ class Sequence {
|
|
|
44
44
|
this.startsAt = opts?.startsAt ?? 0;
|
|
45
45
|
this.maxPower = opts?.maxPower ?? DEFAULT_MAX_POWER;
|
|
46
46
|
if (!Number.isInteger(this.startsAt)) {
|
|
47
|
-
throw new Error(
|
|
47
|
+
throw new Error((0, errors_1.message)('seqStartsAtInteger'));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
differenceTable() {
|
|
@@ -74,10 +74,10 @@ class Sequence {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
if (degree < 0 || degree > this.maxPower) {
|
|
77
|
-
throw new Error(
|
|
77
|
+
throw new Error((0, errors_1.message)('seqPolynomialOrMaxPower'));
|
|
78
78
|
}
|
|
79
79
|
if (this.seq.length <= degree) {
|
|
80
|
-
throw new Error(
|
|
80
|
+
throw new Error((0, errors_1.message)('seqInsufficientData'));
|
|
81
81
|
}
|
|
82
82
|
const s = BigInt(this.startsAt);
|
|
83
83
|
const stirling = stirlingTable(degree);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MathematicalAggregate } from '../../common/classes/MathematicalAggregate';
|
|
2
2
|
import { SET, SOLUTIONS_SET } from '../parser/constants';
|
|
3
3
|
import type { NerdamerInput, ParserEntity } from '../../types';
|
|
4
|
+
import type { ParserValuesObject } from '../parser/types';
|
|
4
5
|
/**
|
|
5
6
|
* A finite mathematical set of Nerdamer parser values.
|
|
6
7
|
*
|
|
@@ -38,6 +39,13 @@ export declare class ValuesSet extends MathematicalAggregate<ValuesSet> {
|
|
|
38
39
|
* `SolutionSet`.
|
|
39
40
|
*/
|
|
40
41
|
static isValuesSet(obj: unknown): obj is ValuesSet;
|
|
42
|
+
/**
|
|
43
|
+
* Stores a value whose uniqueness has already been established by a specialized subclass.
|
|
44
|
+
*
|
|
45
|
+
* The value is still copied so the set retains ownership of its members. Callers must check
|
|
46
|
+
* uniqueness before using this method.
|
|
47
|
+
*/
|
|
48
|
+
protected addKnownUnique(x: ParserEntity): void;
|
|
41
49
|
protected getValuesArray(): ParserEntity[];
|
|
42
50
|
protected setValuesArray(values: ParserEntity[]): void;
|
|
43
51
|
private indexOf;
|
|
@@ -105,7 +113,7 @@ export declare class ValuesSet extends MathematicalAggregate<ValuesSet> {
|
|
|
105
113
|
/** Tests set equality by membership, independent of insertion order. */
|
|
106
114
|
eq(other: ParserEntity): boolean;
|
|
107
115
|
/** Evaluates every member and returns a new set, collapsing equal results. */
|
|
108
|
-
evaluate(): ValuesSet;
|
|
116
|
+
evaluate(values?: ParserValuesObject): ValuesSet;
|
|
109
117
|
/** Expands every member and returns a new set, collapsing equal results. */
|
|
110
118
|
expand(): ValuesSet;
|
|
111
119
|
/**
|
|
@@ -4,6 +4,7 @@ exports.ValuesSet = void 0;
|
|
|
4
4
|
const MathematicalAggregate_1 = require("../../common/classes/MathematicalAggregate");
|
|
5
5
|
const common_1 = require("../../common/common");
|
|
6
6
|
const errors_1 = require("../../errors");
|
|
7
|
+
const Expression_1 = require("../expression/Expression");
|
|
7
8
|
const constants_1 = require("../parser/constants");
|
|
8
9
|
/**
|
|
9
10
|
* A finite mathematical set of Nerdamer parser values.
|
|
@@ -51,6 +52,15 @@ class ValuesSet extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
51
52
|
static isValuesSet(obj) {
|
|
52
53
|
return ((0, common_1.isNerdamerNativeType)(obj, constants_1.SET) || (0, common_1.isNerdamerNativeType)(obj, constants_1.SOLUTIONS_SET));
|
|
53
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Stores a value whose uniqueness has already been established by a specialized subclass.
|
|
57
|
+
*
|
|
58
|
+
* The value is still copied so the set retains ownership of its members. Callers must check
|
|
59
|
+
* uniqueness before using this method.
|
|
60
|
+
*/
|
|
61
|
+
addKnownUnique(x) {
|
|
62
|
+
this._elements.push(x.copy());
|
|
63
|
+
}
|
|
54
64
|
getValuesArray() {
|
|
55
65
|
return this.elements;
|
|
56
66
|
}
|
|
@@ -91,7 +101,11 @@ class ValuesSet extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
91
101
|
__get__(indices) {
|
|
92
102
|
const index = indices[0];
|
|
93
103
|
if (index < 0 || index >= this._elements.length) {
|
|
94
|
-
throw new RangeError(
|
|
104
|
+
throw new RangeError((0, errors_1.message)('indexOutOfBounds', {
|
|
105
|
+
index: String(index),
|
|
106
|
+
type: String(this.dataType),
|
|
107
|
+
length: String(this._elements.length),
|
|
108
|
+
}));
|
|
95
109
|
}
|
|
96
110
|
return this._elements[index].copy();
|
|
97
111
|
}
|
|
@@ -108,7 +122,11 @@ class ValuesSet extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
108
122
|
__set__(indices, value) {
|
|
109
123
|
const index = indices[0];
|
|
110
124
|
if (index < 0 || index >= this._elements.length) {
|
|
111
|
-
throw new RangeError(
|
|
125
|
+
throw new RangeError((0, errors_1.message)('indexOutOfBounds', {
|
|
126
|
+
index: String(index),
|
|
127
|
+
type: String(this.dataType),
|
|
128
|
+
length: String(this._elements.length),
|
|
129
|
+
}));
|
|
112
130
|
}
|
|
113
131
|
const replacement = value.copy();
|
|
114
132
|
const duplicateIndex = this.indexOf(replacement);
|
|
@@ -234,8 +252,8 @@ class ValuesSet extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
234
252
|
return this.isSubsetOf(other);
|
|
235
253
|
}
|
|
236
254
|
/** Evaluates every member and returns a new set, collapsing equal results. */
|
|
237
|
-
evaluate() {
|
|
238
|
-
return this.copy().each(e => e.evaluate());
|
|
255
|
+
evaluate(values) {
|
|
256
|
+
return this.copy().each(e => Expression_1.Expression.isExpression(e) ? e.evaluate(values) : e.evaluate());
|
|
239
257
|
}
|
|
240
258
|
/** Expands every member and returns a new set, collapsing equal results. */
|
|
241
259
|
expand() {
|
|
@@ -107,9 +107,8 @@ export declare class Vector extends MathematicalAggregate<Vector> {
|
|
|
107
107
|
*/
|
|
108
108
|
each(callback: (e: ParserEntity, i: number) => ParserEntity | void): this;
|
|
109
109
|
eq(V: ParserEntity): boolean;
|
|
110
|
-
/** Evaluates a copied Vector
|
|
111
|
-
evaluate(): Vector;
|
|
112
|
-
evaluate(values: ParserValuesObject): ParserEntity;
|
|
110
|
+
/** Evaluates and returns a copied Vector. */
|
|
111
|
+
evaluate(values?: ParserValuesObject): Vector;
|
|
113
112
|
/** Expands a copied Vector, leaving this one unchanged. */
|
|
114
113
|
expand(): Vector;
|
|
115
114
|
/**
|
|
@@ -76,7 +76,11 @@ class Vector extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
76
76
|
__get__(indices) {
|
|
77
77
|
const index = indices[0];
|
|
78
78
|
if (index < 0 || index >= this.elements.length) {
|
|
79
|
-
throw new errors_1.UnexpectedDataType(
|
|
79
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('indexOutOfBounds', {
|
|
80
|
+
index: String(index),
|
|
81
|
+
type: 'Vector',
|
|
82
|
+
length: String(this.elements.length),
|
|
83
|
+
}));
|
|
80
84
|
}
|
|
81
85
|
return this.elements[index];
|
|
82
86
|
}
|
|
@@ -121,7 +125,7 @@ class Vector extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
121
125
|
copy.elements[i] = e.copy();
|
|
122
126
|
return e;
|
|
123
127
|
});
|
|
124
|
-
return
|
|
128
|
+
return copy;
|
|
125
129
|
}
|
|
126
130
|
/**
|
|
127
131
|
* Gets the number of current elements in the Vector.
|
|
@@ -218,18 +222,11 @@ class Vector extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
218
222
|
}
|
|
219
223
|
return true;
|
|
220
224
|
}
|
|
225
|
+
/** Evaluates and returns a copied Vector. */
|
|
221
226
|
evaluate(values) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
retval = symbolicAccess.evaluate(values);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
const copy = this.copy();
|
|
229
|
-
copy.each(e => (Expression_1.Expression.isExpression(e) ? e.evaluate(values) : e.evaluate()));
|
|
230
|
-
retval = copy;
|
|
231
|
-
}
|
|
232
|
-
return retval;
|
|
227
|
+
const copy = this.copy();
|
|
228
|
+
copy.each(e => (Expression_1.Expression.isExpression(e) ? e.evaluate(values) : e.evaluate()));
|
|
229
|
+
return copy;
|
|
233
230
|
}
|
|
234
231
|
/** Expands a copied Vector, leaving this one unchanged. */
|
|
235
232
|
expand() {
|
|
@@ -436,8 +433,7 @@ class Vector extends MathematicalAggregate_1.MathematicalAggregate {
|
|
|
436
433
|
return retval;
|
|
437
434
|
}
|
|
438
435
|
text() {
|
|
439
|
-
|
|
440
|
-
return this.formatSymbolicAccess(text);
|
|
436
|
+
return `[${this.elements.map(e => e.text()).join(', ')}]`;
|
|
441
437
|
}
|
|
442
438
|
/**
|
|
443
439
|
* Multiplies corresponding Vector elements, broadcasts a scalar factor, or
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadVectorFunctions(): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadVectorFunctions = loadVectorFunctions;
|
|
4
|
+
const dispatch_1 = require("../../dispatch");
|
|
5
|
+
const functions_1 = require("./functions");
|
|
6
|
+
function loadVectorFunctions() {
|
|
7
|
+
Object.assign(dispatch_1.mathFunctionRegistry, {
|
|
8
|
+
dot: (0, dispatch_1.systemFunction)({ fn: functions_1.dot, minArgs: 2, maxArgs: 2, distElWise: false }),
|
|
9
|
+
cross: (0, dispatch_1.systemFunction)({ fn: functions_1.cross, minArgs: 2, maxArgs: 2, distElWise: false }),
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MathematicalAggregate = void 0;
|
|
4
|
+
const errors_1 = require("../../errors");
|
|
4
5
|
const StructuredEntity_1 = require("./StructuredEntity");
|
|
5
6
|
/**
|
|
6
7
|
* MathematicalAggregate
|
|
@@ -18,7 +19,11 @@ class MathematicalAggregate extends StructuredEntity_1.StructuredEntity {
|
|
|
18
19
|
__get__(indices) {
|
|
19
20
|
const index = indices[0];
|
|
20
21
|
if (index < 0 || index >= this.elements.length) {
|
|
21
|
-
throw new RangeError(
|
|
22
|
+
throw new RangeError((0, errors_1.message)('indexOutOfBounds', {
|
|
23
|
+
index: String(index),
|
|
24
|
+
type: String(this.dataType),
|
|
25
|
+
length: String(this.elements.length),
|
|
26
|
+
}));
|
|
22
27
|
}
|
|
23
28
|
return this.elements[index];
|
|
24
29
|
}
|
|
@@ -30,7 +35,11 @@ class MathematicalAggregate extends StructuredEntity_1.StructuredEntity {
|
|
|
30
35
|
__set__(indices, value) {
|
|
31
36
|
const index = indices[0];
|
|
32
37
|
if (index < 0 || index >= this.elements.length) {
|
|
33
|
-
throw new RangeError(
|
|
38
|
+
throw new RangeError((0, errors_1.message)('indexOutOfBounds', {
|
|
39
|
+
index: String(index),
|
|
40
|
+
type: String(this.dataType),
|
|
41
|
+
length: String(this.elements.length),
|
|
42
|
+
}));
|
|
34
43
|
}
|
|
35
44
|
this.elements[index] = value;
|
|
36
45
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Expression } from '../../classes/expression/Expression';
|
|
2
1
|
import type { ParserEntity } from '../../types';
|
|
3
2
|
import type { NerdamerInput } from '../../types';
|
|
4
3
|
/**
|
|
@@ -14,17 +13,6 @@ export declare abstract class StructuredEntity<T extends StructuredEntity<T, TPr
|
|
|
14
13
|
abstract elements: ParserEntity[] | ParserEntity[][];
|
|
15
14
|
abstract isEnumerable: boolean;
|
|
16
15
|
abstract precision?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Public index expressions retained when bracket access cannot yet be resolved.
|
|
19
|
-
* This state belongs to a copied structured entity, never the stored source value.
|
|
20
|
-
*/
|
|
21
|
-
symbolicAccessor?: Expression[];
|
|
22
|
-
/** Original symbolic target used to render and later re-evaluate bracket access. */
|
|
23
|
-
symbolicTarget?: Expression;
|
|
24
|
-
/** Copies symbolic access metadata alongside a concrete structured copy. */
|
|
25
|
-
protected copySymbolicAccessTo(copy: T): T;
|
|
26
|
-
/** Renders symbolic access without exposing the carrier's concrete contents. */
|
|
27
|
-
protected formatSymbolicAccess(baseText: string): string;
|
|
28
16
|
private binaryOp;
|
|
29
17
|
abstract __get__(indices: number[] | string): ParserEntity;
|
|
30
18
|
abstract __set__(indices: number[] | string, value: ParserEntity): void;
|
|
@@ -47,9 +35,4 @@ export declare abstract class StructuredEntity<T extends StructuredEntity<T, TPr
|
|
|
47
35
|
abstract text(): string;
|
|
48
36
|
times(x: NerdamerInput): T | TProduct;
|
|
49
37
|
toString(): string;
|
|
50
|
-
/**
|
|
51
|
-
* Returns a copied structured entity carrying an unresolved bracket access.
|
|
52
|
-
* Existing accessor state is retained so chained symbolic access can be extended.
|
|
53
|
-
*/
|
|
54
|
-
withSymbolicAccessor(target: Expression, indices: Expression[]): T;
|
|
55
38
|
}
|
|
@@ -37,29 +37,9 @@ function getAggregateElement(agg, i, j) {
|
|
|
37
37
|
return row;
|
|
38
38
|
}
|
|
39
39
|
function applyBinaryOp(op, lhs, rhs) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return target.plus(rhs);
|
|
44
|
-
}
|
|
45
|
-
case 'minus': {
|
|
46
|
-
const target = lhs;
|
|
47
|
-
return target.minus(rhs);
|
|
48
|
-
}
|
|
49
|
-
case 'times': {
|
|
50
|
-
const target = lhs;
|
|
51
|
-
return target.times(rhs);
|
|
52
|
-
}
|
|
53
|
-
case 'div': {
|
|
54
|
-
const target = lhs;
|
|
55
|
-
return target.div(rhs);
|
|
56
|
-
}
|
|
57
|
-
case 'pow': {
|
|
58
|
-
const target = lhs;
|
|
59
|
-
// Preserve the historical dynamic failure if an Equation reaches element-wise power.
|
|
60
|
-
return target.pow(rhs);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
40
|
+
const target = lhs;
|
|
41
|
+
const operation = target[op];
|
|
42
|
+
return operation.call(target, rhs);
|
|
63
43
|
}
|
|
64
44
|
/**
|
|
65
45
|
* Abstract base class for Vector, Matrix, and Collection classes.
|
|
@@ -70,32 +50,6 @@ function applyBinaryOp(op, lhs, rhs) {
|
|
|
70
50
|
* so their inherited multiplication continues to return `T` exactly.
|
|
71
51
|
*/
|
|
72
52
|
class StructuredEntity {
|
|
73
|
-
/**
|
|
74
|
-
* Public index expressions retained when bracket access cannot yet be resolved.
|
|
75
|
-
* This state belongs to a copied structured entity, never the stored source value.
|
|
76
|
-
*/
|
|
77
|
-
symbolicAccessor;
|
|
78
|
-
/** Original symbolic target used to render and later re-evaluate bracket access. */
|
|
79
|
-
symbolicTarget;
|
|
80
|
-
/** Copies symbolic access metadata alongside a concrete structured copy. */
|
|
81
|
-
copySymbolicAccessTo(copy) {
|
|
82
|
-
if (this.symbolicTarget) {
|
|
83
|
-
copy.symbolicTarget = this.symbolicTarget.copy();
|
|
84
|
-
}
|
|
85
|
-
if (this.symbolicAccessor) {
|
|
86
|
-
copy.symbolicAccessor = this.symbolicAccessor.map(index => index.copy());
|
|
87
|
-
}
|
|
88
|
-
return copy;
|
|
89
|
-
}
|
|
90
|
-
/** Renders symbolic access without exposing the carrier's concrete contents. */
|
|
91
|
-
formatSymbolicAccess(baseText) {
|
|
92
|
-
let retval = baseText;
|
|
93
|
-
if (this.symbolicAccessor && this.symbolicAccessor.length > 0) {
|
|
94
|
-
const target = this.symbolicTarget ? this.symbolicTarget.text() : baseText;
|
|
95
|
-
retval = `${target}[${this.symbolicAccessor.map(index => index.text()).join(', ')}]`;
|
|
96
|
-
}
|
|
97
|
-
return retval;
|
|
98
|
-
}
|
|
99
53
|
binaryOp(op, x) {
|
|
100
54
|
const rhsAgg = isEnumerableLike(x) && x.dataType === this.dataType ? x : undefined;
|
|
101
55
|
return this.copy().each((e, i, j) => {
|
|
@@ -132,20 +86,5 @@ class StructuredEntity {
|
|
|
132
86
|
toString() {
|
|
133
87
|
return this.text();
|
|
134
88
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Returns a copied structured entity carrying an unresolved bracket access.
|
|
137
|
-
* Existing accessor state is retained so chained symbolic access can be extended.
|
|
138
|
-
*/
|
|
139
|
-
withSymbolicAccessor(target, indices) {
|
|
140
|
-
const retval = this.copy();
|
|
141
|
-
if (!retval.symbolicTarget) {
|
|
142
|
-
retval.symbolicTarget = target.copy();
|
|
143
|
-
}
|
|
144
|
-
retval.symbolicAccessor = [
|
|
145
|
-
...(retval.symbolicAccessor ?? []),
|
|
146
|
-
...indices.map(index => index.copy()),
|
|
147
|
-
];
|
|
148
|
-
return retval;
|
|
149
|
-
}
|
|
150
89
|
}
|
|
151
90
|
exports.StructuredEntity = StructuredEntity;
|
|
@@ -39,7 +39,6 @@ export interface OperatorDefinition {
|
|
|
39
39
|
deferRHSResolution?: boolean;
|
|
40
40
|
postfixVariant?: Operator;
|
|
41
41
|
}
|
|
42
|
-
/** Fully normalized operator metadata stored by the parser. */
|
|
43
42
|
export interface Operator extends OperatorDefinition {
|
|
44
43
|
isPrefix: boolean;
|
|
45
44
|
isPostfix: boolean;
|