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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
* decimal.js v10.6.0
|
|
3
|
+
* An arbitrary-precision Decimal type for JavaScript.
|
|
4
|
+
* https://github.com/MikeMcl/decimal.js
|
|
5
|
+
* Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
6
|
+
* MIT Licence
|
|
7
|
+
*/
|
|
@@ -1,33 +1,3 @@
|
|
|
1
|
-
import { Expression } from '../core/classes/expression/Expression';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { PolyType } from '../core/classes/polynomial/Polynomial';
|
|
5
|
-
import type { FactorsObject } from './algorithms/factor';
|
|
6
|
-
/**
|
|
7
|
-
* Converts a polynomial to a MultiPoly to be used with the polynomial algorithms.
|
|
8
|
-
*
|
|
9
|
-
* @param p The polynomial to be converted.
|
|
10
|
-
* @param variables Optional variable order.
|
|
11
|
-
* @returns The MultiPoly and variable order used for its term keys.
|
|
12
|
-
*/
|
|
13
|
-
export declare function polynomialToMultiPoly(p: PolyType, variables?: string[]): {
|
|
14
|
-
poly: MultiPoly;
|
|
15
|
-
variables: string[];
|
|
16
|
-
};
|
|
17
|
-
export declare function multiPolyToExpression(poly: MultiPoly, variables: string[]): Expression;
|
|
18
|
-
/**
|
|
19
|
-
* Converts the factored Expression or Polynomial to an array of Expressions.
|
|
20
|
-
*
|
|
21
|
-
* @param factorObj The integer polynomial factors.
|
|
22
|
-
* @param variables The variable order used by each factor.
|
|
23
|
-
* @returns Expression factors including non-unit content.
|
|
24
|
-
*/
|
|
25
|
-
export declare function factorsToExpressions(factorObj: FactorsObject, variables: string[]): Expression[];
|
|
26
|
-
/**
|
|
27
|
-
* Converts the factored Expression or Polynomial to an array of Polynomials.
|
|
28
|
-
*
|
|
29
|
-
* @param factorsObj The integer polynomial factors.
|
|
30
|
-
* @param variables The variable order used by each factor.
|
|
31
|
-
* @returns Polynomial wrappers around the converted factors.
|
|
32
|
-
*/
|
|
33
|
-
export declare function factorsToPolynomials(factorsObj: FactorsObject, variables: string[]): Polynomial[];
|
|
1
|
+
import type { Expression } from '../core/classes/expression/Expression';
|
|
2
|
+
/** Completes the square and returns the expression expected by parser notation. */
|
|
3
|
+
export declare function completeSquare(expr: Expression, variable?: Expression): Expression;
|
|
@@ -1,109 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const MultiPoly_1 = require("./algorithms/multiPoly/MultiPoly");
|
|
11
|
-
/**
|
|
12
|
-
* Converts a polynomial to a MultiPoly to be used with the polynomial algorithms.
|
|
13
|
-
*
|
|
14
|
-
* @param p The polynomial to be converted.
|
|
15
|
-
* @param variables Optional variable order.
|
|
16
|
-
* @returns The MultiPoly and variable order used for its term keys.
|
|
17
|
-
*/
|
|
18
|
-
function polynomialToMultiPoly(p, variables) {
|
|
19
|
-
p = Polynomial_1.Polynomial.toPolynomial(p);
|
|
20
|
-
const poly = new MultiPoly_1.MultiPoly();
|
|
21
|
-
variables = variables ?? p.variables;
|
|
22
|
-
for (const term of p.terms) {
|
|
23
|
-
const keyElements = [];
|
|
24
|
-
for (let i = 0; i < variables.length; i++) {
|
|
25
|
-
const power = term.powers[variables[i]];
|
|
26
|
-
// Don't add zero powers or undefined powers
|
|
27
|
-
if (!power) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
// Generate the key which is nothing more than index:power
|
|
31
|
-
keyElements.push(`${i}:${power}`);
|
|
32
|
-
}
|
|
33
|
-
const key = keyElements.join(',');
|
|
34
|
-
poly.terms.set(key, term.coeff.getMultiplier().numerator);
|
|
35
|
-
}
|
|
36
|
-
return { poly, variables };
|
|
37
|
-
}
|
|
38
|
-
function multiPolyToExpression(poly, variables) {
|
|
39
|
-
let retval;
|
|
40
|
-
if (poly.terms.size === 0) {
|
|
41
|
-
retval = (0, shortcuts_1.zero)();
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
let result;
|
|
45
|
-
for (const [key, coeff] of poly.terms) {
|
|
46
|
-
// Build the coefficient as an Expression directly
|
|
47
|
-
let term = Expression_1.Expression.Number(coeff);
|
|
48
|
-
// Multiply by each variable raised to its power
|
|
49
|
-
if (key !== '') {
|
|
50
|
-
for (const part of key.split(',')) {
|
|
51
|
-
const [varIndex, power] = part.split(':');
|
|
52
|
-
const v = Expression_1.Expression.Variable(variables[+varIndex]);
|
|
53
|
-
term = term.times(power === '1' ? v : v.pow(Expression_1.Expression.Number(power)));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// Accumulate into sum
|
|
57
|
-
result = result === undefined ? term : result.plus(term);
|
|
58
|
-
}
|
|
59
|
-
retval = result ?? (0, shortcuts_1.zero)();
|
|
60
|
-
}
|
|
3
|
+
exports.completeSquare = completeSquare;
|
|
4
|
+
const utils_1 = require("../core/classes/expression/utils");
|
|
5
|
+
const utils_2 = require("./utils");
|
|
6
|
+
/** Completes the square and returns the expression expected by parser notation. */
|
|
7
|
+
function completeSquare(expr, variable) {
|
|
8
|
+
const variableName = variable === undefined ? undefined : (0, utils_1.assertPlainVariableAndGetString)(variable);
|
|
9
|
+
const retval = (0, utils_2.sqcomp)(expr, variableName).expression;
|
|
61
10
|
return retval;
|
|
62
11
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Converts a PolyFactor to an Expression object.
|
|
65
|
-
*
|
|
66
|
-
* @param factor The factor to convert.
|
|
67
|
-
* @param variables The variable order used by the factor's MultiPoly.
|
|
68
|
-
* @returns The equivalent Expression.
|
|
69
|
-
*/
|
|
70
|
-
function makeExpression(factor, variables) {
|
|
71
|
-
// The terms of each factor
|
|
72
|
-
let exp = multiPolyToExpression(factor.poly, variables);
|
|
73
|
-
// Add back the power
|
|
74
|
-
if (factor.multiplicity > 1n) {
|
|
75
|
-
exp = exp.pow(Expression_1.Expression.Number(factor.multiplicity));
|
|
76
|
-
}
|
|
77
|
-
return exp;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Converts the factored Expression or Polynomial to an array of Expressions.
|
|
81
|
-
*
|
|
82
|
-
* @param factorObj The integer polynomial factors.
|
|
83
|
-
* @param variables The variable order used by each factor.
|
|
84
|
-
* @returns Expression factors including non-unit content.
|
|
85
|
-
*/
|
|
86
|
-
function factorsToExpressions(factorObj, variables) {
|
|
87
|
-
const factors = [];
|
|
88
|
-
// set the terms
|
|
89
|
-
// Add the content
|
|
90
|
-
if (factorObj.content !== 1n) {
|
|
91
|
-
factors.push(Expression_1.Expression.Number(factorObj.content));
|
|
92
|
-
}
|
|
93
|
-
// Now the factors
|
|
94
|
-
for (const factor of factorObj.factors) {
|
|
95
|
-
const f = makeExpression(factor, variables);
|
|
96
|
-
factors.push(f);
|
|
97
|
-
}
|
|
98
|
-
return factors;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Converts the factored Expression or Polynomial to an array of Polynomials.
|
|
102
|
-
*
|
|
103
|
-
* @param factorsObj The integer polynomial factors.
|
|
104
|
-
* @param variables The variable order used by each factor.
|
|
105
|
-
* @returns Polynomial wrappers around the converted factors.
|
|
106
|
-
*/
|
|
107
|
-
function factorsToPolynomials(factorsObj, variables) {
|
|
108
|
-
return factorsToExpressions(factorsObj, variables).map(e => new Polynomial_1.Polynomial(e));
|
|
109
|
-
}
|
|
@@ -22,6 +22,7 @@ exports.modInv = modInv;
|
|
|
22
22
|
exports.contentBigint = contentBigint;
|
|
23
23
|
exports.bigintBitLength = bigintBitLength;
|
|
24
24
|
exports.nextPrime32 = nextPrime32;
|
|
25
|
+
const errors_1 = require("../../core/errors");
|
|
25
26
|
/**
|
|
26
27
|
* Shared integer + modular arithmetic primitives used across Zippel GCD and
|
|
27
28
|
* multivariate factorization.
|
|
@@ -57,7 +58,7 @@ function gcd(a, b) {
|
|
|
57
58
|
*/
|
|
58
59
|
function pow(base, exp) {
|
|
59
60
|
if (exp < 0n) {
|
|
60
|
-
throw new Error(
|
|
61
|
+
throw new Error((0, errors_1.message)('arithPowNegativeExponent'));
|
|
61
62
|
}
|
|
62
63
|
let b = base;
|
|
63
64
|
let e = exp;
|
|
@@ -79,7 +80,7 @@ function pow(base, exp) {
|
|
|
79
80
|
*/
|
|
80
81
|
function powN(base, exp) {
|
|
81
82
|
if (!Number.isInteger(exp) || exp < 0) {
|
|
82
|
-
throw new Error(
|
|
83
|
+
throw new Error((0, errors_1.message)('arithPowNNonnegativeInteger'));
|
|
83
84
|
}
|
|
84
85
|
return pow(base, BigInt(exp));
|
|
85
86
|
}
|
|
@@ -91,7 +92,7 @@ function powN(base, exp) {
|
|
|
91
92
|
*/
|
|
92
93
|
function bigIntSqrt(n) {
|
|
93
94
|
if (n < 0n) {
|
|
94
|
-
throw new Error(
|
|
95
|
+
throw new Error((0, errors_1.message)('arithBigIntSqrtNegative'));
|
|
95
96
|
}
|
|
96
97
|
if (n < 2n) {
|
|
97
98
|
return n;
|
|
@@ -111,7 +112,7 @@ function bigIntSqrt(n) {
|
|
|
111
112
|
*/
|
|
112
113
|
function intNthRootExact(value, n) {
|
|
113
114
|
if (!Number.isInteger(n) || n <= 0) {
|
|
114
|
-
throw new Error(
|
|
115
|
+
throw new Error((0, errors_1.message)('arithNthRootPositiveInteger'));
|
|
115
116
|
}
|
|
116
117
|
if (value < 0n) {
|
|
117
118
|
// Only odd roots exist for negative values.
|
|
@@ -156,7 +157,7 @@ function intNthRootExact(value, n) {
|
|
|
156
157
|
*/
|
|
157
158
|
function getDivisors(n) {
|
|
158
159
|
if (n <= 0n) {
|
|
159
|
-
throw new Error(
|
|
160
|
+
throw new Error((0, errors_1.message)('arithDivisorsPositive'));
|
|
160
161
|
}
|
|
161
162
|
const out = [];
|
|
162
163
|
const r = bigIntSqrt(n);
|
|
@@ -195,7 +196,7 @@ function egcd(a, b) {
|
|
|
195
196
|
/** Normalize a into the range [0, |p|). Throws if p is zero. */
|
|
196
197
|
function modNorm(a, p) {
|
|
197
198
|
if (p === 0n) {
|
|
198
|
-
throw new Error(
|
|
199
|
+
throw new Error((0, errors_1.message)('arithModNormNonzeroModulus'));
|
|
199
200
|
}
|
|
200
201
|
const m = abs(p);
|
|
201
202
|
const r = a % m;
|
|
@@ -204,7 +205,7 @@ function modNorm(a, p) {
|
|
|
204
205
|
/** Map a to the symmetric residue class (-|p|/2, |p|/2]. */
|
|
205
206
|
function modSymmetric(a, p) {
|
|
206
207
|
if (p === 0n) {
|
|
207
|
-
throw new Error(
|
|
208
|
+
throw new Error((0, errors_1.message)('arithModSymmetricNonzeroModulus'));
|
|
208
209
|
}
|
|
209
210
|
const m = abs(p);
|
|
210
211
|
const r = modNorm(a, m);
|
|
@@ -215,11 +216,11 @@ function modSymmetric(a, p) {
|
|
|
215
216
|
function modInv(a, p) {
|
|
216
217
|
const aa = modNorm(a, p);
|
|
217
218
|
if (aa === 0n) {
|
|
218
|
-
throw new Error(
|
|
219
|
+
throw new Error((0, errors_1.message)('arithModInvZeroNoninvertible'));
|
|
219
220
|
}
|
|
220
221
|
const { g, x } = egcd(aa, p);
|
|
221
222
|
if (g !== 1n && g !== -1n) {
|
|
222
|
-
throw new Error(
|
|
223
|
+
throw new Error((0, errors_1.message)('arithModInvNoninvertible'));
|
|
223
224
|
}
|
|
224
225
|
return modNorm(x, p);
|
|
225
226
|
}
|
|
@@ -11,8 +11,16 @@
|
|
|
11
11
|
* - elimination ideals
|
|
12
12
|
* - ideal membership testing
|
|
13
13
|
* - triangular back-substitution solver
|
|
14
|
+
*
|
|
15
|
+
* External references consulted:
|
|
16
|
+
* - SymPy Gröbner basis implementation:
|
|
17
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/groebnertools.py
|
|
18
|
+
* - Giovini, Mora, Niesi, Robbiano, Traverso, "One Sugar Cube, Please":
|
|
19
|
+
* https://doi.org/10.1145/120694.120701
|
|
20
|
+
* - Bigatti, Caboara, Robbiano, "Computing inhomogeneous Gröbner bases":
|
|
21
|
+
* https://doi.org/10.1016/j.jsc.2010.10.002
|
|
14
22
|
*/
|
|
15
|
-
import {
|
|
23
|
+
import { SparsePolynomial } from '../../core/classes/polynomial/SparsePolynomial';
|
|
16
24
|
/** Monomial order used for leading terms, pair processing, and reduction. */
|
|
17
25
|
export type MonomialOrder = 'LEX' | 'GRLEX' | 'GREVLEX';
|
|
18
26
|
/** Deterministic work counters captured when a Groebner resource budget is exceeded. */
|
|
@@ -64,33 +72,30 @@ export declare class GroebnerBudgetExceeded extends Error {
|
|
|
64
72
|
constructor(message: string, stats: GroebnerStats);
|
|
65
73
|
}
|
|
66
74
|
/**
|
|
67
|
-
* Computes a Groebner basis for
|
|
75
|
+
* Computes a Groebner basis for exact sparse integer polynomials.
|
|
68
76
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* when exact integer division permits it. The returned basis is sorted deterministically,
|
|
74
|
-
* and the routine works from normalized copies rather than editing the supplied generators.
|
|
77
|
+
* The input polynomials must belong to the same ring. With `reduced: true`, the
|
|
78
|
+
* basis is interreduced, coefficient content is removed, leading signs are normalized,
|
|
79
|
+
* and exact monic normalization is applied when possible. Results are sorted
|
|
80
|
+
* deterministically and the supplied polynomials are not modified.
|
|
75
81
|
*
|
|
76
|
-
* @param polys - Ideal generators
|
|
77
|
-
* @param vars - Variable names aligned with exponent indices.
|
|
82
|
+
* @param polys - Ideal generators in one sparse polynomial ring.
|
|
78
83
|
* @param order - Monomial order; defaults to `LEX`.
|
|
79
84
|
* @param reduced - Return the normalized/interreduced basis; defaults to `true`.
|
|
80
|
-
* @returns New basis polynomials in deterministic presentation order.
|
|
85
|
+
* @returns New sparse basis polynomials in deterministic presentation order.
|
|
81
86
|
*/
|
|
82
|
-
export declare function Groebner(polys:
|
|
87
|
+
export declare function Groebner(polys: readonly SparsePolynomial[], order?: MonomialOrder, reduced?: boolean): SparsePolynomial[];
|
|
83
88
|
/**
|
|
84
89
|
* Computes a Groebner basis with ordering, strategy, and budget control.
|
|
85
90
|
*
|
|
86
|
-
* @param polys - Exact integer-coefficient generators
|
|
91
|
+
* @param polys - Exact sparse integer-coefficient generators in one ring.
|
|
87
92
|
* @param opts - Ordering, normalization, pair-selection, and deterministic budget options.
|
|
88
93
|
* @returns New basis polynomials. Work statistics are exposed only when a budget is
|
|
89
94
|
* exceeded; successful calls return the basis itself.
|
|
90
95
|
* @throws {@link GroebnerBudgetExceeded} Thrown after a configured pair-count or
|
|
91
96
|
* basis-size limit is exceeded.
|
|
92
97
|
*/
|
|
93
|
-
export declare function groebnerBasisWithOptions(polys: readonly
|
|
98
|
+
export declare function groebnerBasisWithOptions(polys: readonly SparsePolynomial[], opts?: GroebnerBasisOptions): SparsePolynomial[];
|
|
94
99
|
/**
|
|
95
100
|
* Computes the part of the ideal that lies in the polynomial ring generated by `keepVars`.
|
|
96
101
|
*
|
|
@@ -102,7 +107,7 @@ export declare function groebnerBasisWithOptions(polys: readonly MultiPoly[], op
|
|
|
102
107
|
* @returns New basis polynomials involving only retained variables.
|
|
103
108
|
* @throws {@link GroebnerBudgetExceeded} Thrown when a configured budget is exceeded.
|
|
104
109
|
*/
|
|
105
|
-
export declare function eliminate(polys:
|
|
110
|
+
export declare function eliminate(polys: readonly SparsePolynomial[], vars: readonly string[], keepVars: readonly string[], opts?: Omit<GroebnerBasisOptions, 'order'>): SparsePolynomial[];
|
|
106
111
|
/**
|
|
107
112
|
* Tests exact ideal membership by reducing against a computed Groebner basis.
|
|
108
113
|
*
|
|
@@ -113,21 +118,20 @@ export declare function eliminate(polys: MultiPoly[], vars: string[], keepVars:
|
|
|
113
118
|
* @returns Whether the normal form of `f` is zero.
|
|
114
119
|
* @throws {@link GroebnerBudgetExceeded} Thrown when basis computation exceeds a budget.
|
|
115
120
|
*/
|
|
116
|
-
export declare function idealMembership(f:
|
|
121
|
+
export declare function idealMembership(f: SparsePolynomial, polys: readonly SparsePolynomial[], order?: MonomialOrder, opts?: Omit<GroebnerBasisOptions, 'order' | 'reduced'>): boolean;
|
|
117
122
|
/**
|
|
118
123
|
* Reduces a polynomial by a basis or arbitrary reducer set using fraction-free arithmetic.
|
|
119
124
|
*
|
|
120
125
|
* @remarks
|
|
121
126
|
* This does not compute or verify a Groebner basis. The result is a canonical ideal
|
|
122
|
-
* normal form only when `basis` is already a basis for the selected order.
|
|
123
|
-
* works from normalized polynomial copies, leaving the supplied objects alone.
|
|
127
|
+
* normal form only when `basis` is already a basis for the selected order.
|
|
124
128
|
*
|
|
125
129
|
* @param f - Polynomial to reduce.
|
|
126
130
|
* @param basis - Reducers, normally a Groebner basis.
|
|
127
131
|
* @param order - Monomial order used to select leading terms.
|
|
128
132
|
* @returns The primitive-normalized remainder.
|
|
129
133
|
*/
|
|
130
|
-
export declare function reduceByBasis(f:
|
|
134
|
+
export declare function reduceByBasis(f: SparsePolynomial, basis: readonly SparsePolynomial[], order?: MonomialOrder): SparsePolynomial;
|
|
131
135
|
/**
|
|
132
136
|
* Maps each solved variable to a reduced rational numerator/denominator pair.
|
|
133
137
|
*
|
|
@@ -154,4 +158,4 @@ export type RationalSolution = Map<string, {
|
|
|
154
158
|
* or a non-finite/unsupported triangular result; these cases are not distinguished.
|
|
155
159
|
* @throws {@link GroebnerBudgetExceeded} Thrown when basis computation exceeds a budget.
|
|
156
160
|
*/
|
|
157
|
-
export declare function solve(polys:
|
|
161
|
+
export declare function solve(polys: readonly SparsePolynomial[], vars: readonly string[], opts?: Omit<GroebnerBasisOptions, 'order' | 'reduced'>): RationalSolution[];
|