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,34 +2,7 @@ import { Scope } from '../../../common/classes/Scope';
|
|
|
2
2
|
import { Expression } from '../../expression/Expression';
|
|
3
3
|
import type { ExpressionInput, ParserEntity } from '../../../types';
|
|
4
4
|
import type { DeferredFunctionArgument } from '../types';
|
|
5
|
-
|
|
6
|
-
* Adds a known value to a variable in the parser
|
|
7
|
-
* @param a
|
|
8
|
-
* @param b
|
|
9
|
-
*/
|
|
10
|
-
export declare function assign(a: ExpressionInput, b: ParserEntity | string): ParserEntity;
|
|
11
|
-
/**
|
|
12
|
-
* Converts colon-style LET bindings into the alternating name/value scopes consumed by LET.
|
|
13
|
-
*/
|
|
5
|
+
export declare function assign(a: ExpressionInput, b: ParserEntity | string | DeferredFunctionArgument): ParserEntity;
|
|
14
6
|
export declare function normalizeLetArguments(argumentScopes: Scope[]): Scope[];
|
|
15
|
-
/**
|
|
16
|
-
* Evaluates sequential local bindings and restores only those bindings after the body.
|
|
17
|
-
*
|
|
18
|
-
* Arguments are alternating variable/value pairs followed by a body expression. Each value
|
|
19
|
-
* is evaluated after earlier bindings have been installed, so later initializers can reference
|
|
20
|
-
* earlier locals. Ordinary assignment is reused for validation and storage. Any assignment to
|
|
21
|
-
* a name not declared by LET keeps its normal parser behavior.
|
|
22
|
-
*
|
|
23
|
-
* @param args Deferred variable/value pairs followed by the deferred body.
|
|
24
|
-
* @returns The body's result.
|
|
25
|
-
*/
|
|
26
7
|
export declare function LET(...args: DeferredFunctionArgument[]): ParserEntity;
|
|
27
|
-
/**
|
|
28
|
-
* Removes a known parser value by variable name.
|
|
29
|
-
*
|
|
30
|
-
* Parser calls defer the argument so an assigned variable can be read as its name rather than
|
|
31
|
-
* substituted value. Direct callers may still pass an Expression or string.
|
|
32
|
-
*
|
|
33
|
-
* @param x Variable name or deferred variable-name expression.
|
|
34
|
-
*/
|
|
35
8
|
export declare function unassign(x: Expression | string | DeferredFunctionArgument): Expression;
|
|
@@ -10,32 +10,41 @@ const Settings_1 = require("../../../Settings");
|
|
|
10
10
|
const Expression_1 = require("../../expression/Expression");
|
|
11
11
|
const utils_1 = require("../../expression/utils");
|
|
12
12
|
const constants_1 = require("../constants");
|
|
13
|
+
const controlFlowSignals_1 = require("../controlFlowSignals");
|
|
13
14
|
const Parser_1 = require("../Parser");
|
|
14
15
|
const Token_1 = require("../Token");
|
|
15
|
-
|
|
16
|
-
* Adds a known value to a variable in the parser
|
|
17
|
-
* @param a
|
|
18
|
-
* @param b
|
|
19
|
-
*/
|
|
16
|
+
const controlFlow_1 = require("./controlFlow");
|
|
20
17
|
function assign(a, b) {
|
|
21
18
|
a = Expression_1.Expression.create(a);
|
|
22
|
-
if (typeof b === 'string') {
|
|
23
|
-
b = Parser_1.Parser.parse(b);
|
|
24
|
-
}
|
|
25
|
-
// We can only assign to plain variables
|
|
26
19
|
if (Expression_1.Expression.isExpression(a) && !a.isPlainVariable()) {
|
|
27
20
|
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: String(a) }));
|
|
28
21
|
}
|
|
29
|
-
// We cannot assign to restricted values
|
|
30
22
|
if (Settings_1.RESTRICTED.includes(a.value)) {
|
|
31
23
|
throw new errors_1.AssignmentError((0, errors_1.message)('restrictedVariableName', { name: a.value }));
|
|
32
24
|
}
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
let value;
|
|
26
|
+
try {
|
|
27
|
+
if (typeof b === 'function') {
|
|
28
|
+
value = b();
|
|
29
|
+
}
|
|
30
|
+
else if (typeof b === 'string') {
|
|
31
|
+
value = Parser_1.Parser.parse(b);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
value = b;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (controlFlowSignals_1.NullSignal.isNullSignal(error)) {
|
|
39
|
+
// A no-result RHS is assignment's one special case. It is equivalent to x:x:
|
|
40
|
+
// preserve an existing binding, or leave an unbound name unresolved.
|
|
41
|
+
return Parser_1.Parser.KNOWN_VALUES[a.value]?.copy() ?? a;
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
Parser_1.Parser.KNOWN_VALUES[a.value] = value;
|
|
46
|
+
return value;
|
|
35
47
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Converts colon-style LET bindings into the alternating name/value scopes consumed by LET.
|
|
38
|
-
*/
|
|
39
48
|
function normalizeLetArguments(argumentScopes) {
|
|
40
49
|
const normalizedScopes = [];
|
|
41
50
|
for (let i = 0; i < argumentScopes.length; i++) {
|
|
@@ -44,9 +53,7 @@ function normalizeLetArguments(argumentScopes) {
|
|
|
44
53
|
if (i < argumentScopes.length - 1) {
|
|
45
54
|
for (let j = 0; j < argumentScope.length; j++) {
|
|
46
55
|
const argumentToken = argumentScope[j];
|
|
47
|
-
if (Token_1.Token.isToken(argumentToken) &&
|
|
48
|
-
argumentToken.type === Token_1.Token.OPERATOR &&
|
|
49
|
-
argumentToken.value === constants_1.ASSIGN) {
|
|
56
|
+
if (Token_1.Token.isToken(argumentToken) && argumentToken.type === Token_1.Token.OPERATOR && argumentToken.value === constants_1.ASSIGN) {
|
|
50
57
|
assignmentIndex = j;
|
|
51
58
|
break;
|
|
52
59
|
}
|
|
@@ -69,17 +76,6 @@ function normalizeLetArguments(argumentScopes) {
|
|
|
69
76
|
}
|
|
70
77
|
return normalizedScopes;
|
|
71
78
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Evaluates sequential local bindings and restores only those bindings after the body.
|
|
74
|
-
*
|
|
75
|
-
* Arguments are alternating variable/value pairs followed by a body expression. Each value
|
|
76
|
-
* is evaluated after earlier bindings have been installed, so later initializers can reference
|
|
77
|
-
* earlier locals. Ordinary assignment is reused for validation and storage. Any assignment to
|
|
78
|
-
* a name not declared by LET keeps its normal parser behavior.
|
|
79
|
-
*
|
|
80
|
-
* @param args Deferred variable/value pairs followed by the deferred body.
|
|
81
|
-
* @returns The body's result.
|
|
82
|
-
*/
|
|
83
79
|
function LET(...args) {
|
|
84
80
|
if (args.length < 3 || args.length % 2 === 0) {
|
|
85
81
|
throw new errors_1.ParserError((0, errors_1.message)('letRequiresBindingsAndBody'));
|
|
@@ -90,8 +86,6 @@ function LET(...args) {
|
|
|
90
86
|
let retval;
|
|
91
87
|
try {
|
|
92
88
|
for (let i = 0; i < args.length - 1; i += 2) {
|
|
93
|
-
// Binding names are syntax, not values. Suppress both call-scoped and known-value
|
|
94
|
-
// substitution while resolving the plain variable name.
|
|
95
89
|
const nameExpression = args[i]({ inheritValues: false, substitute: false });
|
|
96
90
|
if (!Expression_1.Expression.isExpression(nameExpression)) {
|
|
97
91
|
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: nameExpression.text() }));
|
|
@@ -111,7 +105,17 @@ function LET(...args) {
|
|
|
111
105
|
localNames.push(name);
|
|
112
106
|
}
|
|
113
107
|
}
|
|
114
|
-
|
|
108
|
+
try {
|
|
109
|
+
retval = args[args.length - 1]({ excludeValues: localNames });
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if ((0, controlFlow_1.shouldConsumeLocalReturn)() && controlFlow_1.ReturnSignal.isReturnSignal(error)) {
|
|
113
|
+
retval = error.value;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
115
119
|
}
|
|
116
120
|
finally {
|
|
117
121
|
for (const [name, value] of previousValues) {
|
|
@@ -123,14 +127,6 @@ function LET(...args) {
|
|
|
123
127
|
}
|
|
124
128
|
return retval;
|
|
125
129
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Removes a known parser value by variable name.
|
|
128
|
-
*
|
|
129
|
-
* Parser calls defer the argument so an assigned variable can be read as its name rather than
|
|
130
|
-
* substituted value. Direct callers may still pass an Expression or string.
|
|
131
|
-
*
|
|
132
|
-
* @param x Variable name or deferred variable-name expression.
|
|
133
|
-
*/
|
|
134
130
|
function unassign(x) {
|
|
135
131
|
let variable;
|
|
136
132
|
let name;
|
|
@@ -8,11 +8,6 @@ import type Decimal from 'decimal.js';
|
|
|
8
8
|
* The type used to defined a operation function for the parser
|
|
9
9
|
*/
|
|
10
10
|
export type Operation = (a: ParserEntity, b?: ParserEntity) => ParserEntity;
|
|
11
|
-
/**
|
|
12
|
-
* The comma operation returns both operands so the parser can place them back
|
|
13
|
-
* on the output stack as separate values.
|
|
14
|
-
*/
|
|
15
|
-
export type CommaOperation = (a: ParserStackValue, b: ParserStackValue) => ParserStackValue[];
|
|
16
11
|
/**
|
|
17
12
|
* The type used to defined a prefix for the parser
|
|
18
13
|
*/
|
|
@@ -88,6 +83,11 @@ export type TextOptions = {
|
|
|
88
83
|
decimal?: boolean;
|
|
89
84
|
/** Significant-digit precision used when decimal output is requested. */
|
|
90
85
|
precision?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Render numeric values in scientific notation with exactly this many significant digits (1–1e9).
|
|
88
|
+
* Numeric powers use scientific notation only when the formatted exponent remains exact.
|
|
89
|
+
*/
|
|
90
|
+
scientific?: number;
|
|
91
91
|
/** Sort sum and product elements with {@link Expression.sortFunction} before rendering. */
|
|
92
92
|
sort?: boolean;
|
|
93
93
|
/** Parenthesize powers for output that will be embedded in JavaScript-style expressions. */
|
|
@@ -18,14 +18,15 @@ export declare class IndexedReference {
|
|
|
18
18
|
isEnumerable: boolean;
|
|
19
19
|
constructor(target: ParserEntity, indices: number[] | string, targetName?: string | undefined);
|
|
20
20
|
static isIndexedReference(obj: unknown): obj is IndexedReference;
|
|
21
|
-
copy(): import("../../
|
|
21
|
+
copy(): import("../../collection/Collection").Collection | import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../matrix/Matrix").Matrix | import("../../equation/Equation").Equation | Dictionary;
|
|
22
22
|
eq(other: ParserEntity): boolean;
|
|
23
|
-
evaluate(): import("../../
|
|
24
|
-
expand(): import("../../
|
|
23
|
+
evaluate(): import("../../collection/Collection").Collection | import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../matrix/Matrix").Matrix | import("../../equation/Equation").Equation | Dictionary;
|
|
24
|
+
expand(): import("../../collection/Collection").Collection | import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../matrix/Matrix").Matrix | import("../../equation/Equation").Equation | Dictionary;
|
|
25
25
|
gt(other: ParserEntity): boolean;
|
|
26
26
|
gte(other: ParserEntity): boolean;
|
|
27
27
|
lt(other: ParserEntity): boolean;
|
|
28
28
|
lte(other: ParserEntity): boolean;
|
|
29
29
|
resolve(): ParserEntity;
|
|
30
|
+
set(value: ParserEntity): void;
|
|
30
31
|
text(): string;
|
|
31
32
|
}
|
|
@@ -61,6 +61,14 @@ class IndexedReference {
|
|
|
61
61
|
}
|
|
62
62
|
return this._resolved;
|
|
63
63
|
}
|
|
64
|
+
set(value) {
|
|
65
|
+
if (typeof this.indices === 'string') {
|
|
66
|
+
this.target.__set__(this.indices, value);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.target.__set__(this.indices, value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
text() {
|
|
65
73
|
return this.resolve().text();
|
|
66
74
|
}
|
|
@@ -14,8 +14,8 @@ export declare class KeyValuePair {
|
|
|
14
14
|
static isKeyValuePair(obj: unknown): obj is KeyValuePair;
|
|
15
15
|
copy(): KeyValuePair;
|
|
16
16
|
eq(): boolean;
|
|
17
|
-
evaluate(): import("../../
|
|
18
|
-
expand(): import("../../
|
|
17
|
+
evaluate(): import("../../collection/Collection").Collection | import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../matrix/Matrix").Matrix | import("../../equation/Equation").Equation | import("../../dictionary/Dictionary").Dictionary;
|
|
18
|
+
expand(): import("../../collection/Collection").Collection | import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../matrix/Matrix").Matrix | import("../../equation/Equation").Equation | import("../../dictionary/Dictionary").Dictionary;
|
|
19
19
|
gt(): boolean;
|
|
20
20
|
gte(): boolean;
|
|
21
21
|
lt(): boolean;
|
|
@@ -425,6 +425,9 @@ export declare class Polynomial {
|
|
|
425
425
|
/**
|
|
426
426
|
* Raises the polynomial to a power.
|
|
427
427
|
*
|
|
428
|
+
* Exact non-negative integer powers use sparse polynomial arithmetic when the
|
|
429
|
+
* coefficient domain permits it. Other exponents retain symbolic expression behavior.
|
|
430
|
+
*
|
|
428
431
|
* @param p - Exponent accepted by symbolic expression powers.
|
|
429
432
|
* @returns A new polynomial parsed from the powered expression.
|
|
430
433
|
* @throws {@link core!PolynomialError} Thrown when the powered result is not polynomial-like.
|
|
@@ -456,7 +459,8 @@ export declare class Polynomial {
|
|
|
456
459
|
*
|
|
457
460
|
* @param x - Multiplier.
|
|
458
461
|
* @returns A new polynomial. Term multiplication copies this polynomial before
|
|
459
|
-
* updating its terms
|
|
462
|
+
* updating its terms. Polynomial multiplication uses exact sparse arithmetic when
|
|
463
|
+
* both operands have numeric coefficients and otherwise preserves symbolic multiplication.
|
|
460
464
|
*/
|
|
461
465
|
times(x: Term | Polynomial): Polynomial;
|
|
462
466
|
/**
|
|
@@ -16,6 +16,7 @@ const Expression_1 = require("../expression/Expression");
|
|
|
16
16
|
const shortcuts_1 = require("../expression/shortcuts");
|
|
17
17
|
const constants_1 = require("../parser/constants");
|
|
18
18
|
const Rational_1 = require("../rational/Rational");
|
|
19
|
+
const SparsePolynomialAdapter_1 = require("./SparsePolynomialAdapter");
|
|
19
20
|
const Term_1 = require("./Term");
|
|
20
21
|
const utils_2 = require("./utils");
|
|
21
22
|
/**
|
|
@@ -80,7 +81,7 @@ class Polynomial {
|
|
|
80
81
|
*/
|
|
81
82
|
constructor(p, vars, ordering) {
|
|
82
83
|
if (Polynomial.isPolynomial(p)) {
|
|
83
|
-
this.expression =
|
|
84
|
+
this.expression = p.expression.copy();
|
|
84
85
|
this.variables = [...p.variables];
|
|
85
86
|
this.ordering = p.ordering;
|
|
86
87
|
this.isMultivariate = p.isMultivariate;
|
|
@@ -101,8 +102,10 @@ class Polynomial {
|
|
|
101
102
|
}
|
|
102
103
|
// Expand the expression but only if needed. This will be needed if the value has a bracket
|
|
103
104
|
// or if the expression has a power greater than one.
|
|
104
|
-
|
|
105
|
+
let expandedForCoefficients = false;
|
|
106
|
+
if (x.value.includes('(') || (x.isSum() && x.getPower().gt((0, shortcuts_1.one)()))) {
|
|
105
107
|
x = (0, expand_1.expand)(x);
|
|
108
|
+
expandedForCoefficients = true;
|
|
106
109
|
}
|
|
107
110
|
this.expression = x;
|
|
108
111
|
let variables;
|
|
@@ -123,7 +126,7 @@ class Polynomial {
|
|
|
123
126
|
// Calculate the coefficients. Coeffs will come back as a collection of objects so for instance
|
|
124
127
|
// a*x*y + b*x^2*y will come back as [a, '1,1'] & [b, '2,1']. It's preferred to have it in object form
|
|
125
128
|
// TODO: this should probably be done with `coeffs`.
|
|
126
|
-
|
|
129
|
+
(0, analysis_1.coeffs)(x, this.variables, undefined, !expandedForCoefficients).each((coeff, powers) => {
|
|
127
130
|
this.terms.push(new Term_1.Term(coeff, powers, this.variables));
|
|
128
131
|
});
|
|
129
132
|
// Set a blank array if none was provided or calculated
|
|
@@ -169,7 +172,7 @@ class Polynomial {
|
|
|
169
172
|
for (const variable of vars) {
|
|
170
173
|
powers[variable] = i;
|
|
171
174
|
}
|
|
172
|
-
retval.terms.push(new Term_1.Term(
|
|
175
|
+
retval.terms.push(new Term_1.Term(coefficient.copy(), powers, vars));
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
178
|
retval.order();
|
|
@@ -985,12 +988,35 @@ class Polynomial {
|
|
|
985
988
|
/**
|
|
986
989
|
* Raises the polynomial to a power.
|
|
987
990
|
*
|
|
991
|
+
* Exact non-negative integer powers use sparse polynomial arithmetic when the
|
|
992
|
+
* coefficient domain permits it. Other exponents retain symbolic expression behavior.
|
|
993
|
+
*
|
|
988
994
|
* @param p - Exponent accepted by symbolic expression powers.
|
|
989
995
|
* @returns A new polynomial parsed from the powered expression.
|
|
990
996
|
* @throws {@link core!PolynomialError} Thrown when the powered result is not polynomial-like.
|
|
991
997
|
*/
|
|
992
998
|
pow(p) {
|
|
993
|
-
|
|
999
|
+
const exponent = Expression_1.Expression.create(p);
|
|
1000
|
+
const source = this.getExpression();
|
|
1001
|
+
let sparseResult;
|
|
1002
|
+
if (exponent.isNUM() &&
|
|
1003
|
+
exponent.isInteger() &&
|
|
1004
|
+
exponent.sign() >= 0 &&
|
|
1005
|
+
!source.hasDecimal()) {
|
|
1006
|
+
try {
|
|
1007
|
+
const power = exponent.getMultiplier().numerator;
|
|
1008
|
+
const variables = [...this.variables];
|
|
1009
|
+
const converted = (0, SparsePolynomialAdapter_1.expressionToIntegerSparsePolynomial)(source, variables);
|
|
1010
|
+
const denominator = converted.denominator ** power;
|
|
1011
|
+
let expression = (0, SparsePolynomialAdapter_1.sparsePolynomialToExpression)(converted.polynomial.pow(power), variables);
|
|
1012
|
+
if (denominator !== 1n) {
|
|
1013
|
+
expression = expression.div(Expression_1.Expression.Number(denominator));
|
|
1014
|
+
}
|
|
1015
|
+
sparseResult = new Polynomial(expression, undefined, this.ordering);
|
|
1016
|
+
}
|
|
1017
|
+
catch { }
|
|
1018
|
+
}
|
|
1019
|
+
return sparseResult ?? new Polynomial(source.pow(exponent), undefined, this.ordering);
|
|
994
1020
|
}
|
|
995
1021
|
/**
|
|
996
1022
|
* Sorts the terms by {@link revlex} reverse lexicographic order
|
|
@@ -1053,7 +1079,8 @@ class Polynomial {
|
|
|
1053
1079
|
*
|
|
1054
1080
|
* @param x - Multiplier.
|
|
1055
1081
|
* @returns A new polynomial. Term multiplication copies this polynomial before
|
|
1056
|
-
* updating its terms
|
|
1082
|
+
* updating its terms. Polynomial multiplication uses exact sparse arithmetic when
|
|
1083
|
+
* both operands have numeric coefficients and otherwise preserves symbolic multiplication.
|
|
1057
1084
|
*/
|
|
1058
1085
|
times(x) {
|
|
1059
1086
|
let retval;
|
|
@@ -1071,7 +1098,26 @@ class Polynomial {
|
|
|
1071
1098
|
retval.updateExpression();
|
|
1072
1099
|
}
|
|
1073
1100
|
else {
|
|
1074
|
-
|
|
1101
|
+
const leftExpression = this.getExpression();
|
|
1102
|
+
const rightExpression = x.getExpression();
|
|
1103
|
+
let sparseResult;
|
|
1104
|
+
if (!leftExpression.hasDecimal() && !rightExpression.hasDecimal()) {
|
|
1105
|
+
try {
|
|
1106
|
+
const variables = [...new Set([...this.variables, ...x.variables])].sort();
|
|
1107
|
+
const left = (0, SparsePolynomialAdapter_1.expressionToIntegerSparsePolynomial)(leftExpression, variables);
|
|
1108
|
+
const right = (0, SparsePolynomialAdapter_1.expressionToIntegerSparsePolynomial)(rightExpression, variables);
|
|
1109
|
+
const denominator = left.denominator * right.denominator;
|
|
1110
|
+
let expression = (0, SparsePolynomialAdapter_1.sparsePolynomialToExpression)(left.polynomial.multiply(right.polynomial), variables);
|
|
1111
|
+
if (denominator !== 1n) {
|
|
1112
|
+
expression = expression.div(Expression_1.Expression.Number(denominator));
|
|
1113
|
+
}
|
|
1114
|
+
sparseResult = new Polynomial(expression, undefined, this.ordering);
|
|
1115
|
+
}
|
|
1116
|
+
catch { }
|
|
1117
|
+
}
|
|
1118
|
+
retval =
|
|
1119
|
+
sparseResult ??
|
|
1120
|
+
new Polynomial(leftExpression.times(rightExpression), undefined, this.ordering);
|
|
1075
1121
|
}
|
|
1076
1122
|
return retval;
|
|
1077
1123
|
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sparsePolynomial
|
|
3
|
+
*
|
|
4
|
+
* Sparse polynomial storage with exact bigint coefficients and exponents.
|
|
5
|
+
*
|
|
6
|
+
* External references consulted for monomial representation and ordering:
|
|
7
|
+
* - SymPy monomial operations:
|
|
8
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/monomials.py
|
|
9
|
+
* - SymPy lexicographic, graded lexicographic, and graded reverse lexicographic orders:
|
|
10
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/orderings.py
|
|
11
|
+
* - SymPy coefficient content and primitive-part operations:
|
|
12
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/densetools.py
|
|
13
|
+
* - SymPy sparse polynomial division:
|
|
14
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/sparsetools.py
|
|
15
|
+
*/
|
|
16
|
+
export type MonomialOrder = 'lex' | 'grlex' | 'grevlex';
|
|
17
|
+
export type SparsePolynomialTerm = Readonly<{
|
|
18
|
+
coefficient: bigint;
|
|
19
|
+
exponents: readonly bigint[];
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Sparse polynomial with bigint coefficients and bigint exponents.
|
|
23
|
+
*
|
|
24
|
+
* The variable count is part of the polynomial rather than inferred from its support.
|
|
25
|
+
* Exponent vectors therefore have one exact entry for every variable, including zero
|
|
26
|
+
* polynomials and constants. The internal map key is an encoding detail and is never
|
|
27
|
+
* exposed or parsed by polynomial algorithms.
|
|
28
|
+
*/
|
|
29
|
+
export declare class SparsePolynomial {
|
|
30
|
+
private readonly termsByKey;
|
|
31
|
+
readonly variableCount: number;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a sparse polynomial in a ring with a fixed number of variables.
|
|
34
|
+
*
|
|
35
|
+
* Duplicate monomials are combined and zero coefficients are removed.
|
|
36
|
+
*
|
|
37
|
+
* @param variableCount - Number of variables in the polynomial ring.
|
|
38
|
+
* @param terms - Terms with exponent vectors of exactly variableCount entries.
|
|
39
|
+
*/
|
|
40
|
+
constructor(variableCount: number, terms?: Iterable<SparsePolynomialTerm>);
|
|
41
|
+
/**
|
|
42
|
+
* Verifies that an exponent vector belongs to a ring and contains only
|
|
43
|
+
* non-negative exact integer exponents.
|
|
44
|
+
*/
|
|
45
|
+
private static assertExponents;
|
|
46
|
+
/**
|
|
47
|
+
* Compares exponent vectors using the three global monomial orders required by
|
|
48
|
+
* the polynomial algorithms.
|
|
49
|
+
*/
|
|
50
|
+
static compareMonomials(a: readonly bigint[], b: readonly bigint[], order: MonomialOrder): number;
|
|
51
|
+
/** Creates a constant polynomial in a ring with variableCount variables. */
|
|
52
|
+
static constant(variableCount: number, coefficient: bigint): SparsePolynomial;
|
|
53
|
+
/**
|
|
54
|
+
* Encodes an exponent vector only for map identity.
|
|
55
|
+
*
|
|
56
|
+
* The polynomial retains the exponent vector beside the key, so no decoder exists.
|
|
57
|
+
*/
|
|
58
|
+
private static keyOf;
|
|
59
|
+
/** Creates a one-term polynomial. */
|
|
60
|
+
static monomial(variableCount: number, coefficient: bigint, exponents: readonly bigint[]): SparsePolynomial;
|
|
61
|
+
/** Creates the variable at variableIndex with coefficient one. */
|
|
62
|
+
static variable(variableCount: number, variableIndex: number): SparsePolynomial;
|
|
63
|
+
/** Creates the zero polynomial in a ring with variableCount variables. */
|
|
64
|
+
static zero(variableCount: number): SparsePolynomial;
|
|
65
|
+
/**
|
|
66
|
+
* Adds another polynomial in the same ring.
|
|
67
|
+
*
|
|
68
|
+
* Like monomials are combined exactly and zero coefficients are removed from
|
|
69
|
+
* the returned polynomial.
|
|
70
|
+
*/
|
|
71
|
+
add(other: SparsePolynomial): SparsePolynomial;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the coefficient of one monomial.
|
|
74
|
+
*
|
|
75
|
+
* @param exponents - Exact exponent vector for the requested monomial.
|
|
76
|
+
*/
|
|
77
|
+
coefficient(exponents: readonly bigint[]): bigint;
|
|
78
|
+
/**
|
|
79
|
+
* Returns the coefficient polynomial at one exact power of a selected variable.
|
|
80
|
+
*
|
|
81
|
+
* The selected variable remains in the ring with exponent zero so recursive
|
|
82
|
+
* algorithms can preserve the original coordinate layout.
|
|
83
|
+
*/
|
|
84
|
+
coefficientIn(variableIndex: number, exponent: bigint): SparsePolynomial;
|
|
85
|
+
/** Returns the constant coefficient, or zero when the constant monomial is absent. */
|
|
86
|
+
constantTerm(): bigint;
|
|
87
|
+
/**
|
|
88
|
+
* Returns the positive greatest common divisor of all coefficients.
|
|
89
|
+
*
|
|
90
|
+
* The zero polynomial has coefficient content zero.
|
|
91
|
+
*/
|
|
92
|
+
content(): bigint;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the degree in one variable.
|
|
95
|
+
*
|
|
96
|
+
* The zero polynomial has no degree and returns null.
|
|
97
|
+
*/
|
|
98
|
+
degree(variableIndex: number): bigint | null;
|
|
99
|
+
/**
|
|
100
|
+
* Differentiates with respect to one ring variable.
|
|
101
|
+
*
|
|
102
|
+
* Coefficients and exponents stay in bigint arithmetic, including exponents
|
|
103
|
+
* above JavaScript's safe-integer range.
|
|
104
|
+
*/
|
|
105
|
+
derivative(variableIndex: number): SparsePolynomial;
|
|
106
|
+
/**
|
|
107
|
+
* Divides every term by one monomial when the quotient stays in the integer
|
|
108
|
+
* polynomial ring.
|
|
109
|
+
*
|
|
110
|
+
* Returns null when any coefficient or exponent is not exactly divisible.
|
|
111
|
+
*/
|
|
112
|
+
divideByMonomial(divisor: SparsePolynomialTerm): SparsePolynomial | null;
|
|
113
|
+
/**
|
|
114
|
+
* Divides all coefficients by an integer scalar.
|
|
115
|
+
*
|
|
116
|
+
* @throws RangeError When the scalar is zero or does not divide every coefficient.
|
|
117
|
+
*/
|
|
118
|
+
divideByScalarExact(divisor: bigint): SparsePolynomial;
|
|
119
|
+
/**
|
|
120
|
+
* Divides by one polynomial using exact integer coefficient arithmetic.
|
|
121
|
+
*
|
|
122
|
+
* Returns null as soon as the current leading term is not exactly divisible
|
|
123
|
+
* by the divisor leading term. A successful result therefore has zero
|
|
124
|
+
* remainder in the selected monomial order.
|
|
125
|
+
*/
|
|
126
|
+
divideExact(divisor: SparsePolynomial, order?: MonomialOrder): SparsePolynomial | null;
|
|
127
|
+
/** Returns whether both polynomials have the same ring and exact nonzero terms. */
|
|
128
|
+
equals(other: SparsePolynomial): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Substitutes one variable with an exact integer while retaining the same ring.
|
|
131
|
+
*
|
|
132
|
+
* Terms that become like terms after substitution are combined in the result.
|
|
133
|
+
*/
|
|
134
|
+
evaluateVariable(variableIndex: number, value: bigint): SparsePolynomial;
|
|
135
|
+
/**
|
|
136
|
+
* Substitutes several variables with exact integers in one sparse traversal.
|
|
137
|
+
*
|
|
138
|
+
* The selected coordinates remain in the polynomial ring with exponent zero.
|
|
139
|
+
*/
|
|
140
|
+
evaluateVariables(variableIndices: readonly number[], values: readonly bigint[]): SparsePolynomial;
|
|
141
|
+
/** Returns whether the polynomial is zero or contains only a constant term. */
|
|
142
|
+
isConstant(): boolean;
|
|
143
|
+
/** Returns whether the polynomial has no nonzero terms. */
|
|
144
|
+
isZero(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Returns the coefficient polynomial of the highest power of one variable.
|
|
147
|
+
*
|
|
148
|
+
* The selected coordinate remains present with exponent zero.
|
|
149
|
+
*/
|
|
150
|
+
leadingCoefficientIn(variableIndex: number): SparsePolynomial | null;
|
|
151
|
+
/**
|
|
152
|
+
* Returns the leading term under the requested monomial order.
|
|
153
|
+
*
|
|
154
|
+
* Variable priority follows exponent-vector index order.
|
|
155
|
+
*/
|
|
156
|
+
leadingTerm(order?: MonomialOrder): SparsePolynomialTerm | null;
|
|
157
|
+
/**
|
|
158
|
+
* Applies an exact bigint transformation to every stored coefficient while
|
|
159
|
+
* preserving the existing monomial keys and exponent vectors.
|
|
160
|
+
*/
|
|
161
|
+
mapCoefficients(mapper: (coefficient: bigint) => bigint): SparsePolynomial;
|
|
162
|
+
/** Returns the largest absolute coefficient, or zero for the zero polynomial. */
|
|
163
|
+
maxAbsoluteCoefficient(): bigint;
|
|
164
|
+
/**
|
|
165
|
+
* Computes the difference of two monomial-scaled polynomials in one sparse
|
|
166
|
+
* traversal. This avoids constructing the monomial factors and multiplication
|
|
167
|
+
* results used by fraction-free S-polynomials.
|
|
168
|
+
*/
|
|
169
|
+
monomialScaleSubtract(leftScalar: bigint, leftMonomialExponents: readonly bigint[], other: SparsePolynomial, rightScalar: bigint, rightMonomialExponents: readonly bigint[]): SparsePolynomial;
|
|
170
|
+
/**
|
|
171
|
+
* Multiplies by another polynomial in the same ring.
|
|
172
|
+
*
|
|
173
|
+
* Monomial exponents are added as bigints. The constructor combines products
|
|
174
|
+
* that land on the same monomial and removes coefficients that cancel to zero.
|
|
175
|
+
*/
|
|
176
|
+
multiply(other: SparsePolynomial): SparsePolynomial;
|
|
177
|
+
/**
|
|
178
|
+
* Returns the additive inverse of this polynomial.
|
|
179
|
+
*/
|
|
180
|
+
negate(): SparsePolynomial;
|
|
181
|
+
/**
|
|
182
|
+
* Makes the leading coefficient positive without changing coefficient content.
|
|
183
|
+
*/
|
|
184
|
+
normalizeLeadingSign(order?: MonomialOrder): SparsePolynomial;
|
|
185
|
+
/** Raises the polynomial to a non-negative exact integer power. */
|
|
186
|
+
pow(exponent: bigint): SparsePolynomial;
|
|
187
|
+
/**
|
|
188
|
+
* Divides by positive coefficient content while preserving the polynomial sign.
|
|
189
|
+
*/
|
|
190
|
+
primitivePart(): SparsePolynomial;
|
|
191
|
+
/**
|
|
192
|
+
* Multiplies every coefficient by an exact integer scalar.
|
|
193
|
+
*/
|
|
194
|
+
scale(scalar: bigint): SparsePolynomial;
|
|
195
|
+
/**
|
|
196
|
+
* Computes a scaled subtraction where the right polynomial is also multiplied
|
|
197
|
+
* by one monomial. This avoids constructing the two scaled intermediate
|
|
198
|
+
* polynomials used by fraction-free reduction.
|
|
199
|
+
*/
|
|
200
|
+
scaleSubtractMonomial(leftScalar: bigint, other: SparsePolynomial, rightScalar: bigint, monomialExponents: readonly bigint[]): SparsePolynomial;
|
|
201
|
+
/**
|
|
202
|
+
* Subtracts another polynomial in the same ring.
|
|
203
|
+
*/
|
|
204
|
+
subtract(other: SparsePolynomial): SparsePolynomial;
|
|
205
|
+
/** Number of stored nonzero terms. */
|
|
206
|
+
get termCount(): number;
|
|
207
|
+
/**
|
|
208
|
+
* Returns a copy of the stored terms.
|
|
209
|
+
*
|
|
210
|
+
* The exponent arrays themselves are frozen so callers cannot alter polynomial storage.
|
|
211
|
+
*/
|
|
212
|
+
terms(): readonly SparsePolynomialTerm[];
|
|
213
|
+
/**
|
|
214
|
+
* Returns the largest total degree among the stored monomials.
|
|
215
|
+
*
|
|
216
|
+
* The zero polynomial has no total degree and returns null.
|
|
217
|
+
*/
|
|
218
|
+
totalDegree(): bigint | null;
|
|
219
|
+
/** Returns the variable indices that occur with a positive exponent. */
|
|
220
|
+
variables(): readonly number[];
|
|
221
|
+
}
|