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
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module modularGcd
|
|
4
|
+
*
|
|
5
|
+
* Greatest common divisors for sparse polynomials over a modular field.
|
|
6
|
+
*
|
|
7
|
+
* External references consulted for finite-field Euclidean GCD and recursive
|
|
8
|
+
* evaluation/interpolation:
|
|
9
|
+
* - SymPy finite-field polynomial GCD:
|
|
10
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/galoistools.py
|
|
11
|
+
* - SymPy sparse univariate modular GCD bridge:
|
|
12
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/zippel.py
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.modularGcdUnivariate = modularGcdUnivariate;
|
|
16
|
+
exports.modularGcdFiniteField = modularGcdFiniteField;
|
|
17
|
+
exports.modularGcdBivariate = modularGcdBivariate;
|
|
18
|
+
exports.modularGcdTrivariate = modularGcdTrivariate;
|
|
19
|
+
const errors_1 = require("../../core/errors");
|
|
20
|
+
const primeFactor_1 = require("../../core/functions/bigint/primeFactor");
|
|
21
|
+
const ModularSparsePolynomial_1 = require("./ModularSparsePolynomial");
|
|
22
|
+
// SymPy gives failed sparse interpolation data a small number of fresh attempts
|
|
23
|
+
// before abandoning the current modular image.
|
|
24
|
+
const MODULAR_GCD_RECONSTRUCTION_ATTEMPTS = 3n;
|
|
25
|
+
/**
|
|
26
|
+
* Computes polynomial content in one selected coefficient variable.
|
|
27
|
+
*
|
|
28
|
+
* Terms are grouped by their complete exponent vector outside coefficientVariable.
|
|
29
|
+
* The grouping key is used only for identity and is never parsed back into exponents.
|
|
30
|
+
*/
|
|
31
|
+
function modularContentInVariable(polynomial, coefficientVariable) {
|
|
32
|
+
polynomial.degree(coefficientVariable);
|
|
33
|
+
if (polynomial.isZero()) {
|
|
34
|
+
return ModularSparsePolynomial_1.ModularSparsePolynomial.zero(polynomial.variableCount, polynomial.modulus);
|
|
35
|
+
}
|
|
36
|
+
const groups = new Map();
|
|
37
|
+
for (const term of polynomial.terms()) {
|
|
38
|
+
const groupExponents = [...term.exponents];
|
|
39
|
+
groupExponents[coefficientVariable] = 0n;
|
|
40
|
+
const key = groupExponents.join(',');
|
|
41
|
+
const coefficientExponents = new Array(polynomial.variableCount).fill(0n);
|
|
42
|
+
coefficientExponents[coefficientVariable] = term.exponents[coefficientVariable];
|
|
43
|
+
const group = groups.get(key) ?? [];
|
|
44
|
+
group.push({
|
|
45
|
+
coefficient: term.coefficient,
|
|
46
|
+
exponents: coefficientExponents,
|
|
47
|
+
});
|
|
48
|
+
groups.set(key, group);
|
|
49
|
+
}
|
|
50
|
+
let content = ModularSparsePolynomial_1.ModularSparsePolynomial.zero(polynomial.variableCount, polynomial.modulus);
|
|
51
|
+
for (const terms of groups.values()) {
|
|
52
|
+
const coefficient = new ModularSparsePolynomial_1.ModularSparsePolynomial(polynomial.variableCount, polynomial.modulus, terms);
|
|
53
|
+
content = content.isZero()
|
|
54
|
+
? coefficient.monic('lex')
|
|
55
|
+
: modularGcdUnivariate(content, coefficient, coefficientVariable);
|
|
56
|
+
if (content.isConstant()) {
|
|
57
|
+
return ModularSparsePolynomial_1.ModularSparsePolynomial.constant(polynomial.variableCount, polynomial.modulus, 1n);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return content.monic('lex');
|
|
61
|
+
}
|
|
62
|
+
/** Removes polynomial content in one selected coefficient variable. */
|
|
63
|
+
function modularPrimitivePartInVariable(polynomial, coefficientVariable) {
|
|
64
|
+
if (polynomial.isZero()) {
|
|
65
|
+
return {
|
|
66
|
+
content: ModularSparsePolynomial_1.ModularSparsePolynomial.zero(polynomial.variableCount, polynomial.modulus),
|
|
67
|
+
primitive: polynomial,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const content = modularContentInVariable(polynomial, coefficientVariable);
|
|
71
|
+
const primitive = polynomial.divideExact(content);
|
|
72
|
+
if (primitive === null) {
|
|
73
|
+
throw new RangeError((0, errors_1.message)('polyModularContentExactDivision'));
|
|
74
|
+
}
|
|
75
|
+
return { content, primitive };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the coefficient polynomial at the lexicographically greatest monomial
|
|
79
|
+
* in polynomialVariables. The result depends only on coefficientVariable.
|
|
80
|
+
*/
|
|
81
|
+
function modularLeadingCoefficientInVariables(polynomial, polynomialVariables, coefficientVariable) {
|
|
82
|
+
polynomial.degree(coefficientVariable);
|
|
83
|
+
for (const variableIndex of polynomialVariables) {
|
|
84
|
+
polynomial.degree(variableIndex);
|
|
85
|
+
}
|
|
86
|
+
const terms = polynomial.terms();
|
|
87
|
+
if (terms.length === 0) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
let leading = terms[0];
|
|
91
|
+
for (let termIndex = 1; termIndex < terms.length; termIndex++) {
|
|
92
|
+
const term = terms[termIndex];
|
|
93
|
+
for (const variableIndex of polynomialVariables) {
|
|
94
|
+
if (term.exponents[variableIndex] === leading.exponents[variableIndex]) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (term.exponents[variableIndex] > leading.exponents[variableIndex]) {
|
|
98
|
+
leading = term;
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const coefficientTerms = [];
|
|
104
|
+
for (const term of terms) {
|
|
105
|
+
let matches = true;
|
|
106
|
+
for (const variableIndex of polynomialVariables) {
|
|
107
|
+
if (term.exponents[variableIndex] !== leading.exponents[variableIndex]) {
|
|
108
|
+
matches = false;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!matches) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const exponents = new Array(polynomial.variableCount).fill(0n);
|
|
116
|
+
exponents[coefficientVariable] = term.exponents[coefficientVariable];
|
|
117
|
+
coefficientTerms.push({
|
|
118
|
+
coefficient: term.coefficient,
|
|
119
|
+
exponents,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return new ModularSparsePolynomial_1.ModularSparsePolynomial(polynomial.variableCount, polynomial.modulus, coefficientTerms);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the monomial support over selected variables.
|
|
126
|
+
*
|
|
127
|
+
* Keys are used only for set membership and are never decoded back into exponents.
|
|
128
|
+
*/
|
|
129
|
+
function monomialSupport(polynomial, variables) {
|
|
130
|
+
const support = new Set();
|
|
131
|
+
for (const term of polynomial.terms()) {
|
|
132
|
+
support.add(variables.map(variableIndex => term.exponents[variableIndex]).join(','));
|
|
133
|
+
}
|
|
134
|
+
return support;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Computes the monic GCD of two univariate polynomials over the same modular field.
|
|
138
|
+
*
|
|
139
|
+
* The polynomial ring may retain additional variable coordinates, but neither input
|
|
140
|
+
* may depend on variables other than variableIndex.
|
|
141
|
+
*/
|
|
142
|
+
function modularGcdUnivariate(left, right, variableIndex) {
|
|
143
|
+
if (left.variableCount !== right.variableCount || left.modulus !== right.modulus) {
|
|
144
|
+
throw new RangeError((0, errors_1.message)('polyRequires', { operation: 'Modular polynomial GCD', requirement: (0, errors_1.message)('polyReqSamePolynomialRing') }));
|
|
145
|
+
}
|
|
146
|
+
left.degree(variableIndex);
|
|
147
|
+
right.degree(variableIndex);
|
|
148
|
+
for (const activeVariable of left.variables()) {
|
|
149
|
+
if (activeVariable !== variableIndex) {
|
|
150
|
+
throw new RangeError((0, errors_1.message)('polyRequires', { operation: 'Modular polynomial GCD inputs', requirement: (0, errors_1.message)('polyReqUnivariatePolynomial') }));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (const activeVariable of right.variables()) {
|
|
154
|
+
if (activeVariable !== variableIndex) {
|
|
155
|
+
throw new RangeError((0, errors_1.message)('polyRequires', { operation: 'Modular polynomial GCD inputs', requirement: (0, errors_1.message)('polyReqUnivariatePolynomial') }));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
let a = new ModularSparsePolynomial_1.ModularSparsePolynomial(left.variableCount, left.modulus, left.terms());
|
|
159
|
+
let b = new ModularSparsePolynomial_1.ModularSparsePolynomial(right.variableCount, right.modulus, right.terms());
|
|
160
|
+
while (!b.isZero()) {
|
|
161
|
+
const division = a.divideWithRemainder(b, 'lex');
|
|
162
|
+
a = b;
|
|
163
|
+
b = division.remainder;
|
|
164
|
+
}
|
|
165
|
+
return a.isZero() ? a : a.monic('lex');
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Computes a modular GCD recursively by specializing the last selected variable.
|
|
169
|
+
*
|
|
170
|
+
* The caller supplies the variable order used by the recursive polynomial view.
|
|
171
|
+
* Ring coordinates not listed in variables must be dormant.
|
|
172
|
+
*/
|
|
173
|
+
function modularGcdRecursive(left, right, variables) {
|
|
174
|
+
if (variables.length === 1) {
|
|
175
|
+
return modularGcdUnivariate(left, right, variables[0]);
|
|
176
|
+
}
|
|
177
|
+
if (left.isZero()) {
|
|
178
|
+
return right.isZero() ? right : right.monic('lex');
|
|
179
|
+
}
|
|
180
|
+
if (right.isZero()) {
|
|
181
|
+
return left.monic('lex');
|
|
182
|
+
}
|
|
183
|
+
const interpolationVariable = variables[variables.length - 1];
|
|
184
|
+
const polynomialVariables = variables.slice(0, -1);
|
|
185
|
+
const leftParts = modularPrimitivePartInVariable(left, interpolationVariable);
|
|
186
|
+
const rightParts = modularPrimitivePartInVariable(right, interpolationVariable);
|
|
187
|
+
const contentGcd = modularGcdUnivariate(leftParts.content, rightParts.content, interpolationVariable);
|
|
188
|
+
const leftLeading = modularLeadingCoefficientInVariables(leftParts.primitive, polynomialVariables, interpolationVariable);
|
|
189
|
+
const rightLeading = modularLeadingCoefficientInVariables(rightParts.primitive, polynomialVariables, interpolationVariable);
|
|
190
|
+
if (leftLeading === null || rightLeading === null) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const scaling = modularGcdUnivariate(leftLeading, rightLeading, interpolationVariable);
|
|
194
|
+
const leftInterpolationDegree = leftParts.primitive.degree(interpolationVariable) ?? 0n;
|
|
195
|
+
const rightInterpolationDegree = rightParts.primitive.degree(interpolationVariable) ?? 0n;
|
|
196
|
+
const maxGcdDegree = leftInterpolationDegree < rightInterpolationDegree
|
|
197
|
+
? leftInterpolationDegree
|
|
198
|
+
: rightInterpolationDegree;
|
|
199
|
+
const leftLeadingDegree = leftLeading.degree(interpolationVariable) ?? 0n;
|
|
200
|
+
const rightLeadingDegree = rightLeading.degree(interpolationVariable) ?? 0n;
|
|
201
|
+
const scalingDegree = scaling.degree(interpolationVariable) ?? 0n;
|
|
202
|
+
const requiredSamples = maxGcdDegree + 2n;
|
|
203
|
+
const badPointBound = leftLeadingDegree + rightLeadingDegree + scalingDegree;
|
|
204
|
+
const availablePoints = left.modulus - 1n;
|
|
205
|
+
const requestedPoints = requiredSamples * MODULAR_GCD_RECONSTRUCTION_ATTEMPTS + badPointBound;
|
|
206
|
+
const scanLimit = availablePoints < requestedPoints ? availablePoints : requestedPoints;
|
|
207
|
+
let expectedDegrees = null;
|
|
208
|
+
let expectedSupport = null;
|
|
209
|
+
let acceptedSamples = 0n;
|
|
210
|
+
let reconstructionAttempts = 0n;
|
|
211
|
+
let samples = [];
|
|
212
|
+
for (let value = 1n; value <= scanLimit; value++) {
|
|
213
|
+
const leftLeadingValue = leftLeading.evaluateVariable(interpolationVariable, value);
|
|
214
|
+
const rightLeadingValue = rightLeading.evaluateVariable(interpolationVariable, value);
|
|
215
|
+
const scalingValue = scaling.evaluateVariable(interpolationVariable, value).constantTerm();
|
|
216
|
+
if (leftLeadingValue.constantTerm() === 0n ||
|
|
217
|
+
rightLeadingValue.constantTerm() === 0n ||
|
|
218
|
+
scalingValue === 0n) {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const evaluatedLeft = leftParts.primitive.evaluateVariable(interpolationVariable, value);
|
|
222
|
+
const evaluatedRight = rightParts.primitive.evaluateVariable(interpolationVariable, value);
|
|
223
|
+
if (evaluatedLeft.isZero() || evaluatedRight.isZero()) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const image = modularGcdRecursive(evaluatedLeft, evaluatedRight, polynomialVariables);
|
|
227
|
+
if (image === null) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (image.isConstant() && !image.isZero()) {
|
|
231
|
+
return contentGcd;
|
|
232
|
+
}
|
|
233
|
+
const imageDegrees = polynomialVariables.map(variableIndex => image.degree(variableIndex) ?? 0n);
|
|
234
|
+
if (expectedDegrees === null) {
|
|
235
|
+
expectedDegrees = imageDegrees;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
let degreeComparison = 0;
|
|
239
|
+
for (let index = 0; index < imageDegrees.length; index++) {
|
|
240
|
+
if (imageDegrees[index] < expectedDegrees[index]) {
|
|
241
|
+
degreeComparison = -1;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
if (imageDegrees[index] > expectedDegrees[index]) {
|
|
245
|
+
degreeComparison = 1;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (degreeComparison < 0) {
|
|
250
|
+
expectedDegrees = imageDegrees;
|
|
251
|
+
expectedSupport = null;
|
|
252
|
+
samples = [];
|
|
253
|
+
acceptedSamples = 0n;
|
|
254
|
+
reconstructionAttempts = 0n;
|
|
255
|
+
}
|
|
256
|
+
else if (degreeComparison > 0) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const imageSupport = monomialSupport(image, polynomialVariables);
|
|
261
|
+
if (expectedSupport === null) {
|
|
262
|
+
expectedSupport = imageSupport;
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
const imageContainsExpected = [...expectedSupport].every(key => imageSupport.has(key));
|
|
266
|
+
const currentSupport = expectedSupport;
|
|
267
|
+
const expectedContainsImage = [...imageSupport].every(key => currentSupport.has(key));
|
|
268
|
+
if (imageContainsExpected && !expectedContainsImage) {
|
|
269
|
+
expectedSupport = imageSupport;
|
|
270
|
+
samples = [];
|
|
271
|
+
acceptedSamples = 0n;
|
|
272
|
+
reconstructionAttempts = 0n;
|
|
273
|
+
}
|
|
274
|
+
else if (!imageContainsExpected) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
samples.push({
|
|
279
|
+
value,
|
|
280
|
+
polynomial: image.scale(scalingValue),
|
|
281
|
+
});
|
|
282
|
+
acceptedSamples++;
|
|
283
|
+
if (acceptedSamples < requiredSamples) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const interpolated = ModularSparsePolynomial_1.ModularSparsePolynomial.interpolateVariable(interpolationVariable, samples);
|
|
287
|
+
const reconstructed = modularPrimitivePartInVariable(interpolated, interpolationVariable).primitive;
|
|
288
|
+
const candidate = reconstructed.multiply(contentGcd).monic('lex');
|
|
289
|
+
if (left.divideExact(candidate) !== null && right.divideExact(candidate) !== null) {
|
|
290
|
+
return candidate;
|
|
291
|
+
}
|
|
292
|
+
reconstructionAttempts++;
|
|
293
|
+
if (reconstructionAttempts >= MODULAR_GCD_RECONSTRUCTION_ATTEMPTS) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
samples = [];
|
|
297
|
+
acceptedSamples = 0n;
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Computes a multivariate GCD over a prime field using recursive
|
|
303
|
+
* evaluation and interpolation.
|
|
304
|
+
*
|
|
305
|
+
* variables must follow polynomial-ring order and contain every active variable
|
|
306
|
+
* in both inputs exactly once. Dormant ring coordinates may be omitted.
|
|
307
|
+
*/
|
|
308
|
+
function modularGcdFiniteField(left, right, variables) {
|
|
309
|
+
if (left.variableCount !== right.variableCount || left.modulus !== right.modulus) {
|
|
310
|
+
throw new RangeError((0, errors_1.message)('polyRequires', { operation: 'Modular polynomial GCD', requirement: (0, errors_1.message)('polyReqSamePolynomialRing') }));
|
|
311
|
+
}
|
|
312
|
+
if (variables.length === 0) {
|
|
313
|
+
throw new RangeError((0, errors_1.message)('polyRequires', { operation: 'Modular polynomial GCD', requirement: (0, errors_1.message)('polyReqAtLeastOneVariable') }));
|
|
314
|
+
}
|
|
315
|
+
if (!(0, primeFactor_1.isPrimeBig)(left.modulus)) {
|
|
316
|
+
throw new RangeError((0, errors_1.message)('polyRequires', { operation: 'Multivariate modular GCD', requirement: (0, errors_1.message)('polyReqPrimeModulus') }));
|
|
317
|
+
}
|
|
318
|
+
const selected = new Set();
|
|
319
|
+
let previousVariable = -1;
|
|
320
|
+
for (const variableIndex of variables) {
|
|
321
|
+
left.degree(variableIndex);
|
|
322
|
+
right.degree(variableIndex);
|
|
323
|
+
if (selected.has(variableIndex)) {
|
|
324
|
+
throw new RangeError((0, errors_1.message)('polyVariablesUnique', { operation: 'Modular polynomial GCD' }));
|
|
325
|
+
}
|
|
326
|
+
if (variableIndex <= previousVariable) {
|
|
327
|
+
throw new RangeError((0, errors_1.message)('polyVariablesRingOrder', { operation: 'Modular polynomial GCD' }));
|
|
328
|
+
}
|
|
329
|
+
selected.add(variableIndex);
|
|
330
|
+
previousVariable = variableIndex;
|
|
331
|
+
}
|
|
332
|
+
for (const activeVariable of [...left.variables(), ...right.variables()]) {
|
|
333
|
+
if (!selected.has(activeVariable)) {
|
|
334
|
+
throw new RangeError((0, errors_1.message)('polyInputsSelectedOnly', { operation: 'Modular polynomial GCD' }));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return modularGcdRecursive(left, right, variables);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Computes a bivariate GCD over a prime field by evaluation and interpolation.
|
|
341
|
+
*/
|
|
342
|
+
function modularGcdBivariate(left, right, mainVariable, interpolationVariable) {
|
|
343
|
+
if (mainVariable >= interpolationVariable) {
|
|
344
|
+
throw new RangeError((0, errors_1.message)('polyVariablesRingOrder', { operation: 'Bivariate modular GCD' }));
|
|
345
|
+
}
|
|
346
|
+
return modularGcdFiniteField(left, right, [mainVariable, interpolationVariable]);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Computes a trivariate GCD over a prime field by recursively specializing the
|
|
350
|
+
* last selected variable and reconstructing from bivariate GCD images.
|
|
351
|
+
*
|
|
352
|
+
* The selected variables must follow their polynomial-ring order. Other ring
|
|
353
|
+
* coordinates may remain dormant.
|
|
354
|
+
*/
|
|
355
|
+
function modularGcdTrivariate(left, right, mainVariable, secondaryVariable, interpolationVariable) {
|
|
356
|
+
if (mainVariable >= secondaryVariable ||
|
|
357
|
+
secondaryVariable >= interpolationVariable) {
|
|
358
|
+
throw new RangeError((0, errors_1.message)('polyVariablesRingOrder', { operation: 'Trivariate modular GCD' }));
|
|
359
|
+
}
|
|
360
|
+
return modularGcdFiniteField(left, right, [
|
|
361
|
+
mainVariable,
|
|
362
|
+
secondaryVariable,
|
|
363
|
+
interpolationVariable,
|
|
364
|
+
]);
|
|
365
|
+
}
|
|
@@ -5,8 +5,10 @@ const subst_1 = require("../core/functions/subst");
|
|
|
5
5
|
const simplify_1 = require("./simplify/simplify");
|
|
6
6
|
function polynomialize(expression, map, callback) {
|
|
7
7
|
map ??= {};
|
|
8
|
-
//
|
|
9
|
-
|
|
8
|
+
// Ordinary polynomial input is already in the exact domain required below.
|
|
9
|
+
// Avoid routing it through the full simplifier, which ends by factoring and can
|
|
10
|
+
// recursively re-enter polynomial GCD preprocessing.
|
|
11
|
+
let x = expression.isPolynomialLike() ? expression : (0, simplify_1.simplify)(expression);
|
|
10
12
|
// Substitute out all functions
|
|
11
13
|
[x, map] = (0, subst_1.uSubFN)(x, map);
|
|
12
14
|
// Substitute out all exponential functions
|
|
@@ -337,7 +337,7 @@ function simplifyLogs(x) {
|
|
|
337
337
|
// Principal-log identities such as log(a)+log(b)=log(a*b) and
|
|
338
338
|
// c*log(a)=log(a^c) are only branch-safe when the log arguments are
|
|
339
339
|
// provably positive real values. Preserve unknown-sign terms unchanged.
|
|
340
|
-
const transformableLogTerms = logTerms.filter(t => !t.arg.isComplex() && t.arg.gt(0));
|
|
340
|
+
const transformableLogTerms = logTerms.filter(t => !t.arg.isComplex() && t.arg.gt((0, shortcuts_1.zero)()));
|
|
341
341
|
if (transformableLogTerms.length === 0) {
|
|
342
342
|
return x;
|
|
343
343
|
}
|
|
@@ -72,7 +72,7 @@ function simplifyRadicals(x) {
|
|
|
72
72
|
// Principal radicals can be combined when both radicands are known nonnegative.
|
|
73
73
|
// Reciprocals still require a strictly signed base because a zero denominator
|
|
74
74
|
// cannot be admitted by the sign proof for a negative power.
|
|
75
|
-
if (!u.isComplex() && !v.isComplex() && u.gte(0) && v.gte(0)) {
|
|
75
|
+
if (!u.isComplex() && !v.isComplex() && u.gte((0, shortcuts_1.zero)()) && v.gte((0, shortcuts_1.zero)())) {
|
|
76
76
|
const multiplier = a.getMultiplier().times(b.getMultiplier());
|
|
77
77
|
if (u.isNUM() && v.isNUM()) {
|
|
78
78
|
// Preserve exact numeric reduction when the combined radicand is numeric.
|
|
@@ -116,8 +116,17 @@ function factorResult(x) {
|
|
|
116
116
|
if (x.isNUM()) {
|
|
117
117
|
return x;
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
function rebuildFactorResult(original, factors) {
|
|
120
|
+
let retval = (0, utils_1.product)(...factors);
|
|
121
|
+
if (original.hasDecimal() && factors.length === 1 && factors[0].eq(original)) {
|
|
122
|
+
retval = original;
|
|
123
|
+
}
|
|
124
|
+
return retval;
|
|
125
|
+
}
|
|
126
|
+
const numerator = x.getNumerator();
|
|
127
|
+
const denominator = x.getDenominator();
|
|
128
|
+
const num = rebuildFactorResult(numerator, (0, factor_1.polyFactorExpressions)(numerator));
|
|
129
|
+
const den = rebuildFactorResult(denominator, (0, factor_1.polyFactorExpressions)(denominator));
|
|
121
130
|
return num.div(den);
|
|
122
131
|
}
|
|
123
132
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Expression } from '../core/classes/expression/Expression';
|
|
2
2
|
import type { ExpressionInput } from '../core/types';
|
|
3
|
-
/** Components of a quadratic rewritten
|
|
3
|
+
/** Components of a quadratic rewritten in completed-square form. */
|
|
4
4
|
export interface CompleteSquareResult {
|
|
5
5
|
/** Original quadratic coefficient. */
|
|
6
6
|
a: Expression;
|
package/output/algebra/utils.js
CHANGED
|
@@ -38,11 +38,11 @@ function sqcomp(expr, variable) {
|
|
|
38
38
|
const b = c.hasPower(1) ? c.getPower(1) : (0, shortcuts_1.zero)();
|
|
39
39
|
const k0 = c.hasPower(0) ? c.getPower(0) : (0, shortcuts_1.zero)();
|
|
40
40
|
// h = b / (2a)
|
|
41
|
-
const h = b.div(a.times(
|
|
41
|
+
const h = b.div(a.times((0, shortcuts_1.two)()));
|
|
42
42
|
// k = c - b² / (4a)
|
|
43
|
-
const k = k0.minus(b.pow(
|
|
43
|
+
const k = k0.minus(b.pow((0, shortcuts_1.two)()).div(a.times((0, shortcuts_1.four)())));
|
|
44
44
|
// Build a*(variable + h)^2 + k
|
|
45
45
|
const x = Expression_1.Expression.create(variable);
|
|
46
|
-
const expression = a.times(x.plus(h).pow(
|
|
46
|
+
const expression = a.times(x.plus(h).pow((0, shortcuts_1.two)())).plus(k);
|
|
47
47
|
return { a, h, k, variable, expression };
|
|
48
48
|
}
|
package/output/api/advanced.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { Groebner, GroebnerBudgetExceeded, eliminate, groebnerBasisWithOptions, idealMembership, reduceByBasis, solve as solveRationalSystem, } from '../algebra/algorithms/groebnerBase';
|
|
2
2
|
export type { GroebnerBasisOptions, GroebnerStats, MonomialOrder, RationalSolution, } from '../algebra/algorithms/groebnerBase';
|
|
3
|
-
export { MultiPoly } from '../algebra/algorithms/multiPoly/MultiPoly';
|
|
4
3
|
/** Advanced numerical and exact-polynomial APIs. */
|
|
5
4
|
export { Complex } from '../core/classes/complex/Complex';
|
|
5
|
+
export { SparsePolynomial } from '../core/classes/polynomial/SparsePolynomial';
|
|
6
|
+
export type { SparsePolynomialTerm } from '../core/classes/polynomial/SparsePolynomial';
|
|
6
7
|
export { FunctionSolver } from '../solve/classes/FunctionSolver';
|
|
7
8
|
export type { FunctionSolverOptions, Root, RootFindingMethod, } from '../solve/classes/FunctionSolver';
|
package/output/api/advanced.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FunctionSolver = exports.
|
|
3
|
+
exports.FunctionSolver = exports.SparsePolynomial = exports.Complex = exports.solveRationalSystem = exports.reduceByBasis = exports.idealMembership = exports.groebnerBasisWithOptions = exports.eliminate = exports.GroebnerBudgetExceeded = exports.Groebner = void 0;
|
|
4
4
|
var groebnerBase_1 = require("../algebra/algorithms/groebnerBase");
|
|
5
5
|
Object.defineProperty(exports, "Groebner", { enumerable: true, get: function () { return groebnerBase_1.Groebner; } });
|
|
6
6
|
Object.defineProperty(exports, "GroebnerBudgetExceeded", { enumerable: true, get: function () { return groebnerBase_1.GroebnerBudgetExceeded; } });
|
|
@@ -9,10 +9,10 @@ Object.defineProperty(exports, "groebnerBasisWithOptions", { enumerable: true, g
|
|
|
9
9
|
Object.defineProperty(exports, "idealMembership", { enumerable: true, get: function () { return groebnerBase_1.idealMembership; } });
|
|
10
10
|
Object.defineProperty(exports, "reduceByBasis", { enumerable: true, get: function () { return groebnerBase_1.reduceByBasis; } });
|
|
11
11
|
Object.defineProperty(exports, "solveRationalSystem", { enumerable: true, get: function () { return groebnerBase_1.solve; } });
|
|
12
|
-
var MultiPoly_1 = require("../algebra/algorithms/multiPoly/MultiPoly");
|
|
13
|
-
Object.defineProperty(exports, "MultiPoly", { enumerable: true, get: function () { return MultiPoly_1.MultiPoly; } });
|
|
14
12
|
/** Advanced numerical and exact-polynomial APIs. */
|
|
15
13
|
var Complex_1 = require("../core/classes/complex/Complex");
|
|
16
14
|
Object.defineProperty(exports, "Complex", { enumerable: true, get: function () { return Complex_1.Complex; } });
|
|
15
|
+
var SparsePolynomial_1 = require("../core/classes/polynomial/SparsePolynomial");
|
|
16
|
+
Object.defineProperty(exports, "SparsePolynomial", { enumerable: true, get: function () { return SparsePolynomial_1.SparsePolynomial; } });
|
|
17
17
|
var FunctionSolver_1 = require("../solve/classes/FunctionSolver");
|
|
18
18
|
Object.defineProperty(exports, "FunctionSolver", { enumerable: true, get: function () { return FunctionSolver_1.FunctionSolver; } });
|
package/output/api/algebra.d.ts
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { CompleteSquareResult } from '../algebra/utils';
|
|
2
|
+
import type { ExpressionInput } from '../core/types';
|
|
3
|
+
export { factor, pfactor, pfactord, polyFactors } from '../algebra/factor/factor';
|
|
3
4
|
export { gcd, lcm } from '../algebra/gcd/gcd';
|
|
4
5
|
export { groebner } from '../algebra/groebner';
|
|
5
6
|
export { partfrac } from '../algebra/partfrac';
|
|
6
7
|
export { simplify } from '../algebra/simplify/simplify';
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Completes the square for a quadratic expression.
|
|
10
|
+
*
|
|
11
|
+
* For `a*x^2+b*x+c`, the returned expression has the form
|
|
12
|
+
* `a*(x+h)^2+k`, with `h=b/(2*a)` and `k=c-b^2/(4*a)`.
|
|
13
|
+
*
|
|
14
|
+
* @param expr - Quadratic expression to rewrite.
|
|
15
|
+
* @param variable - Variable to use. Defaults to the first variable in the expression.
|
|
16
|
+
* @returns The quadratic coefficient, shift, remainder, selected variable, and rewritten expression.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const result = completeSquare('x^2+6*x+1');
|
|
21
|
+
* result.expression.text({ sort: true }); // "(3+x)^2-8"
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const completeSquare: (expr: ExpressionInput, variable?: string) => CompleteSquareResult;
|
|
8
25
|
export type { CompleteSquareResult } from '../algebra/utils';
|
|
9
26
|
export { CoeffObject } from '../core/classes/expression/CoeffObject';
|
|
10
|
-
export { content, deg } from '../core/classes/polynomial/functions';
|
|
27
|
+
export { coeffs, content, deg } from '../core/classes/polynomial/functions';
|
|
11
28
|
export { Polynomial } from '../core/classes/polynomial/Polynomial';
|
|
12
29
|
export type { EvalInputType, Ordering, PolyType, VariableFrequency, } from '../core/classes/polynomial/Polynomial';
|
|
13
30
|
export { Term } from '../core/classes/polynomial/Term';
|
package/output/api/algebra.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPrime = exports.uUnSub = exports.uSub = exports.Term = exports.Polynomial = exports.deg = exports.content = exports.CoeffObject = exports.completeSquare = exports.simplify = exports.partfrac = exports.groebner = exports.lcm = exports.gcd = exports.polyFactors = exports.factor = void 0;
|
|
3
|
+
exports.isPrime = exports.uUnSub = exports.uSub = exports.Term = exports.Polynomial = exports.deg = exports.content = exports.coeffs = exports.CoeffObject = exports.completeSquare = exports.simplify = exports.partfrac = exports.groebner = exports.lcm = exports.gcd = exports.polyFactors = exports.pfactord = exports.pfactor = exports.factor = void 0;
|
|
4
4
|
/** Public symbolic algebra and polynomial APIs. */
|
|
5
|
+
const utils_1 = require("../algebra/utils");
|
|
5
6
|
var factor_1 = require("../algebra/factor/factor");
|
|
6
7
|
Object.defineProperty(exports, "factor", { enumerable: true, get: function () { return factor_1.factor; } });
|
|
8
|
+
Object.defineProperty(exports, "pfactor", { enumerable: true, get: function () { return factor_1.pfactor; } });
|
|
9
|
+
Object.defineProperty(exports, "pfactord", { enumerable: true, get: function () { return factor_1.pfactord; } });
|
|
7
10
|
Object.defineProperty(exports, "polyFactors", { enumerable: true, get: function () { return factor_1.polyFactors; } });
|
|
8
11
|
var gcd_1 = require("../algebra/gcd/gcd");
|
|
9
12
|
Object.defineProperty(exports, "gcd", { enumerable: true, get: function () { return gcd_1.gcd; } });
|
|
@@ -14,11 +17,27 @@ var partfrac_1 = require("../algebra/partfrac");
|
|
|
14
17
|
Object.defineProperty(exports, "partfrac", { enumerable: true, get: function () { return partfrac_1.partfrac; } });
|
|
15
18
|
var simplify_1 = require("../algebra/simplify/simplify");
|
|
16
19
|
Object.defineProperty(exports, "simplify", { enumerable: true, get: function () { return simplify_1.simplify; } });
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Completes the square for a quadratic expression.
|
|
22
|
+
*
|
|
23
|
+
* For `a*x^2+b*x+c`, the returned expression has the form
|
|
24
|
+
* `a*(x+h)^2+k`, with `h=b/(2*a)` and `k=c-b^2/(4*a)`.
|
|
25
|
+
*
|
|
26
|
+
* @param expr - Quadratic expression to rewrite.
|
|
27
|
+
* @param variable - Variable to use. Defaults to the first variable in the expression.
|
|
28
|
+
* @returns The quadratic coefficient, shift, remainder, selected variable, and rewritten expression.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const result = completeSquare('x^2+6*x+1');
|
|
33
|
+
* result.expression.text({ sort: true }); // "(3+x)^2-8"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
exports.completeSquare = utils_1.sqcomp;
|
|
19
37
|
var CoeffObject_1 = require("../core/classes/expression/CoeffObject");
|
|
20
38
|
Object.defineProperty(exports, "CoeffObject", { enumerable: true, get: function () { return CoeffObject_1.CoeffObject; } });
|
|
21
39
|
var functions_1 = require("../core/classes/polynomial/functions");
|
|
40
|
+
Object.defineProperty(exports, "coeffs", { enumerable: true, get: function () { return functions_1.coeffs; } });
|
|
22
41
|
Object.defineProperty(exports, "content", { enumerable: true, get: function () { return functions_1.content; } });
|
|
23
42
|
Object.defineProperty(exports, "deg", { enumerable: true, get: function () { return functions_1.deg; } });
|
|
24
43
|
var Polynomial_1 = require("../core/classes/polynomial/Polynomial");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { assume, clearAssumptions, forgetAssumptionFor, getAssumptionFor, } from '../core/classes/assumption/assume';
|
|
1
|
+
export { assume, clearAssumptions, forgetAssumptionFor, getAssumptionFor, getAssumptions, } from '../core/classes/assumption/assume';
|
|
2
2
|
/** Public process-wide assumption APIs. */
|
|
3
3
|
export { Assumption } from '../core/classes/assumption/Assumption';
|
|
4
4
|
export type { AssumptionComparison, AssumptionValue, Bound, ParsedAssumption, } from '../core/classes/assumption/Assumption';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Assumption = exports.getAssumptionFor = exports.forgetAssumptionFor = exports.clearAssumptions = exports.assume = void 0;
|
|
3
|
+
exports.Assumption = exports.getAssumptions = exports.getAssumptionFor = exports.forgetAssumptionFor = exports.clearAssumptions = exports.assume = void 0;
|
|
4
4
|
var assume_1 = require("../core/classes/assumption/assume");
|
|
5
5
|
Object.defineProperty(exports, "assume", { enumerable: true, get: function () { return assume_1.assume; } });
|
|
6
6
|
Object.defineProperty(exports, "clearAssumptions", { enumerable: true, get: function () { return assume_1.clearAssumptions; } });
|
|
7
7
|
Object.defineProperty(exports, "forgetAssumptionFor", { enumerable: true, get: function () { return assume_1.forgetAssumptionFor; } });
|
|
8
8
|
Object.defineProperty(exports, "getAssumptionFor", { enumerable: true, get: function () { return assume_1.getAssumptionFor; } });
|
|
9
|
+
Object.defineProperty(exports, "getAssumptions", { enumerable: true, get: function () { return assume_1.getAssumptions; } });
|
|
9
10
|
/** Public process-wide assumption APIs. */
|
|
10
11
|
var Assumption_1 = require("../core/classes/assumption/Assumption");
|
|
11
12
|
Object.defineProperty(exports, "Assumption", { enumerable: true, get: function () { return Assumption_1.Assumption; } });
|
package/output/api/calculus.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export { ilaplace } from '../calculus/laplace/ilaplace';
|
|
|
6
6
|
export { laplace } from '../calculus/laplace/laplace';
|
|
7
7
|
export { limit } from '../calculus/limit/limit';
|
|
8
8
|
export type { LimitDir } from '../calculus/limit/limit';
|
|
9
|
-
export { defint
|
|
9
|
+
export { defint } from '../math/defint/defint';
|
|
10
|
+
export { product, sum } from '../math/math';
|
package/output/api/calculus.js
CHANGED
|
@@ -15,7 +15,8 @@ var laplace_1 = require("../calculus/laplace/laplace");
|
|
|
15
15
|
Object.defineProperty(exports, "laplace", { enumerable: true, get: function () { return laplace_1.laplace; } });
|
|
16
16
|
var limit_1 = require("../calculus/limit/limit");
|
|
17
17
|
Object.defineProperty(exports, "limit", { enumerable: true, get: function () { return limit_1.limit; } });
|
|
18
|
+
var defint_1 = require("../math/defint/defint");
|
|
19
|
+
Object.defineProperty(exports, "defint", { enumerable: true, get: function () { return defint_1.defint; } });
|
|
18
20
|
var math_1 = require("../math/math");
|
|
19
|
-
Object.defineProperty(exports, "defint", { enumerable: true, get: function () { return math_1.defint; } });
|
|
20
21
|
Object.defineProperty(exports, "product", { enumerable: true, get: function () { return math_1.product; } });
|
|
21
22
|
Object.defineProperty(exports, "sum", { enumerable: true, get: function () { return math_1.sum; } });
|
package/output/api/core.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Core Nerdamer object model and shared public types.
|
|
3
|
-
*
|
|
4
|
-
* Import from `nerdamer/core` when working directly with Nerdamer values rather
|
|
5
|
-
* than through the callable compatibility root.
|
|
6
|
-
*/
|
|
1
|
+
import type { ExpressionInput } from '../core/types';
|
|
7
2
|
export { Equation } from '../core/classes/equation/Equation';
|
|
8
3
|
export { CoeffObject } from '../core/classes/expression/CoeffObject';
|
|
9
4
|
export { Expression } from '../core/classes/expression/Expression';
|
|
@@ -13,5 +8,31 @@ export type { JsFunction, OptionValue, OptionsObject, ParserConstants, ParserVal
|
|
|
13
8
|
export { Rational } from '../core/classes/rational/Rational';
|
|
14
9
|
export { Converter } from '../core/converters/Converter';
|
|
15
10
|
export { AssignmentError, DimensionError, DivisionByZeroError, MathError, MissingReferenceError, NaNError, NotImplementedError, OperatorError, ParserError, ParserSyntaxError, PolynomialError, UndefinedError, UnexpectedDataType, UnexpectedInputError, UnexpectedTokenError, UnsupportedOperationError, ZeroToZeroPowerError, } from '../core/errors';
|
|
16
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Compiles an expression into a native JavaScript-number function for repeated evaluation.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Function calls are linked to Nerdamer's numerical implementations, including any dependencies
|
|
16
|
+
* they require. The compiler supports scalar JavaScript-number arithmetic rather than Nerdamer's
|
|
17
|
+
* full symbolic or structured value model. Symbolic-only operations such as indexed sums,
|
|
18
|
+
* products, solvers, and matrix operations are rejected if they remain in the expression.
|
|
19
|
+
*
|
|
20
|
+
* `buildFunction` uses `new Function`, so it may be unavailable under a Content Security Policy
|
|
21
|
+
* that forbids dynamic JavaScript evaluation. When `argsArray` is omitted, free variables are
|
|
22
|
+
* sorted alphabetically.
|
|
23
|
+
*
|
|
24
|
+
* @param x - The expression to compile.
|
|
25
|
+
* @param argsArray - Variable names in the positional order expected by the compiled function.
|
|
26
|
+
* @returns The compiled JavaScript-number function.
|
|
27
|
+
* @throws {@link core!UnsupportedOperationError} If the expression contains the imaginary unit or a
|
|
28
|
+
* function for which no matching JavaScript-number implementation is registered.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* buildFunction('x-y')(9, 7); // 2
|
|
33
|
+
* buildFunction('x-y', ['y', 'x'])(9, 7); // -2
|
|
34
|
+
* buildFunction('erf(x)+2')(9); // 3
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const buildFunction: (x: ExpressionInput, argsArray?: string[]) => (...args: number[]) => number;
|
|
17
38
|
export type { ExpressionInput, NerdamerInput, ParserEntity, StructuredEntityType, } from '../core/types';
|