nerdamer 1.1.13 → 2.0.0-rc.2
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 -5
- package/LICENSE.md +184 -0
- package/README.md +232 -318
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +7 -0
- package/dist/parser.js +2 -0
- package/dist/parser.js.LICENSE.txt +7 -0
- package/docs-data/parser-functions.json +2248 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +3 -0
- package/output/algebra/adapters.js +11 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +324 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +161 -0
- package/output/algebra/algorithms/groebnerBase.js +929 -0
- package/output/algebra/dispatch.d.ts +1 -0
- package/output/algebra/dispatch.js +25 -0
- package/output/algebra/factor/factor.d.ts +77 -0
- package/output/algebra/factor/factor.js +245 -0
- package/output/algebra/gcd/gcd.d.ts +30 -0
- package/output/algebra/gcd/gcd.js +95 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +36 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +365 -0
- 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.d.ts +20 -0
- package/output/algebra/polynomialize.js +26 -0
- package/output/algebra/simplify/complexsimp.d.ts +7 -0
- package/output/algebra/simplify/complexsimp.js +24 -0
- package/output/algebra/simplify/factorCommon.d.ts +13 -0
- package/output/algebra/simplify/factorCommon.js +136 -0
- package/output/algebra/simplify/funcsimp.d.ts +26 -0
- package/output/algebra/simplify/funcsimp.js +633 -0
- package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
- package/output/algebra/simplify/invtrigrewrite.js +96 -0
- package/output/algebra/simplify/ratsimp.d.ts +21 -0
- package/output/algebra/simplify/ratsimp.js +140 -0
- package/output/algebra/simplify/simplify.d.ts +25 -0
- package/output/algebra/simplify/simplify.js +237 -0
- package/output/algebra/simplify/trigreduce.d.ts +38 -0
- package/output/algebra/simplify/trigreduce.js +424 -0
- package/output/algebra/simplify/trigrewrite.d.ts +17 -0
- package/output/algebra/simplify/trigrewrite.js +156 -0
- package/output/algebra/simplify/trigsimp.d.ts +11 -0
- package/output/algebra/simplify/trigsimp.js +369 -0
- package/output/algebra/simplify/utils.d.ts +32 -0
- package/output/algebra/simplify/utils.js +56 -0
- package/output/algebra/utils.d.ts +32 -0
- package/output/algebra/utils.js +48 -0
- package/output/api/advanced.d.ts +8 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +35 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +10 -0
- package/output/api/calculus.js +22 -0
- package/output/api/core.d.ts +17 -0
- package/output/api/core.js +41 -0
- package/output/api/debug.d.ts +16 -0
- package/output/api/debug.js +23 -0
- 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 +93 -0
- package/output/api/parser.js +18 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +17 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +23 -0
- package/output/calculus/adapters.d.ts +8 -0
- package/output/calculus/adapters.js +41 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +241 -0
- package/output/calculus/dispatch.d.ts +1 -0
- package/output/calculus/dispatch.js +25 -0
- package/output/calculus/fresnel.d.ts +16 -0
- package/output/calculus/fresnel.js +39 -0
- package/output/calculus/integrate/byParts.d.ts +18 -0
- package/output/calculus/integrate/byParts.js +339 -0
- package/output/calculus/integrate/bySubstitution.d.ts +135 -0
- package/output/calculus/integrate/bySubstitution.js +411 -0
- package/output/calculus/integrate/integrate.d.ts +38 -0
- package/output/calculus/integrate/integrate.js +652 -0
- package/output/calculus/integrate/integrationTable.d.ts +2 -0
- package/output/calculus/integrate/integrationTable.js +914 -0
- package/output/calculus/integrate/utils.d.ts +28 -0
- package/output/calculus/integrate/utils.js +96 -0
- package/output/calculus/laplace/ilaplace.d.ts +31 -0
- package/output/calculus/laplace/ilaplace.js +192 -0
- package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
- package/output/calculus/laplace/ilaplaceTable.js +200 -0
- package/output/calculus/laplace/laplace.d.ts +22 -0
- package/output/calculus/laplace/laplace.js +109 -0
- package/output/calculus/laplace/laplaceTable.d.ts +2 -0
- package/output/calculus/laplace/laplaceTable.js +187 -0
- package/output/calculus/limit/limit.d.ts +35 -0
- package/output/calculus/limit/limit.js +1183 -0
- package/output/calculus/limit/limitsTable.d.ts +2 -0
- package/output/calculus/limit/limitsTable.js +7 -0
- package/output/core/Settings.d.ts +32 -0
- package/output/core/Settings.js +68 -0
- package/output/core/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +609 -0
- package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
- package/output/core/classes/assumption/assertiveFunctions.js +64 -0
- package/output/core/classes/assumption/assume.d.ts +90 -0
- package/output/core/classes/assumption/assume.js +145 -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.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +240 -0
- package/output/core/classes/complex/Complex.d.ts +109 -0
- package/output/core/classes/complex/Complex.js +153 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +454 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +216 -0
- package/output/core/classes/equation/Equation.d.ts +256 -0
- package/output/core/classes/equation/Equation.js +350 -0
- package/output/core/classes/expression/CoeffObject.d.ts +100 -0
- package/output/core/classes/expression/CoeffObject.js +197 -0
- package/output/core/classes/expression/Expression.d.ts +1691 -0
- package/output/core/classes/expression/Expression.js +2381 -0
- package/output/core/classes/expression/analysis.d.ts +25 -0
- package/output/core/classes/expression/analysis.js +218 -0
- package/output/core/classes/expression/collect.d.ts +9 -0
- package/output/core/classes/expression/collect.js +49 -0
- package/output/core/classes/expression/format.d.ts +54 -0
- package/output/core/classes/expression/format.js +340 -0
- package/output/core/classes/expression/products.d.ts +23 -0
- package/output/core/classes/expression/products.js +115 -0
- package/output/core/classes/expression/shortcuts.d.ts +35 -0
- package/output/core/classes/expression/shortcuts.js +129 -0
- package/output/core/classes/expression/traversal.d.ts +31 -0
- package/output/core/classes/expression/traversal.js +216 -0
- package/output/core/classes/expression/trig.d.ts +25 -0
- package/output/core/classes/expression/trig.js +40 -0
- package/output/core/classes/expression/utils.d.ts +61 -0
- package/output/core/classes/expression/utils.js +235 -0
- package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
- package/output/core/classes/lookupTable/LookupTable.js +55 -0
- package/output/core/classes/matrix/Matrix.d.ts +227 -0
- package/output/core/classes/matrix/Matrix.js +901 -0
- package/output/core/classes/matrix/Sylvester.d.ts +11 -0
- package/output/core/classes/matrix/Sylvester.js +54 -0
- 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 +28 -0
- package/output/core/classes/matrix/functions.js +57 -0
- package/output/core/classes/matrix/utils.d.ts +9 -0
- package/output/core/classes/matrix/utils.js +22 -0
- package/output/core/classes/parser/Parser.d.ts +493 -0
- package/output/core/classes/parser/Parser.js +1863 -0
- package/output/core/classes/parser/Token.d.ts +58 -0
- package/output/core/classes/parser/Token.js +137 -0
- package/output/core/classes/parser/constants.d.ts +162 -0
- package/output/core/classes/parser/constants.js +229 -0
- package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
- package/output/core/classes/parser/controlFlowSignals.js +60 -0
- package/output/core/classes/parser/helpers.d.ts +21 -0
- package/output/core/classes/parser/helpers.js +42 -0
- package/output/core/classes/parser/operations/add.d.ts +15 -0
- package/output/core/classes/parser/operations/add.js +236 -0
- package/output/core/classes/parser/operations/comma.d.ts +7 -0
- package/output/core/classes/parser/operations/comma.js +11 -0
- package/output/core/classes/parser/operations/compare.d.ts +21 -0
- package/output/core/classes/parser/operations/compare.js +474 -0
- package/output/core/classes/parser/operations/divide.d.ts +2 -0
- package/output/core/classes/parser/operations/divide.js +72 -0
- package/output/core/classes/parser/operations/functions.d.ts +46 -0
- package/output/core/classes/parser/operations/functions.js +438 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +328 -0
- package/output/core/classes/parser/operations/power.d.ts +48 -0
- package/output/core/classes/parser/operations/power.js +673 -0
- package/output/core/classes/parser/operations/subtract.d.ts +3 -0
- package/output/core/classes/parser/operations/subtract.js +36 -0
- package/output/core/classes/parser/preprocess.d.ts +7 -0
- package/output/core/classes/parser/preprocess.js +246 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +23 -0
- package/output/core/classes/parser/scripting/controlFlow.js +279 -0
- 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 +23 -0
- package/output/core/classes/parser/scripting/evaluate.js +128 -0
- package/output/core/classes/parser/scripting/functions.d.ts +14 -0
- package/output/core/classes/parser/scripting/functions.js +59 -0
- package/output/core/classes/parser/scripting/scope.d.ts +8 -0
- package/output/core/classes/parser/scripting/scope.js +132 -0
- package/output/core/classes/parser/types.d.ts +130 -0
- package/output/core/classes/parser/types.js +2 -0
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
- package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
- package/output/core/classes/polynomial/Polynomial.d.ts +504 -0
- package/output/core/classes/polynomial/Polynomial.js +1195 -0
- 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.d.ts +222 -0
- package/output/core/classes/polynomial/Term.js +430 -0
- package/output/core/classes/polynomial/adapters.d.ts +18 -0
- 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 +77 -0
- package/output/core/classes/polynomial/functions.js +189 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +207 -0
- package/output/core/classes/rational/Rational.d.ts +501 -0
- package/output/core/classes/rational/Rational.js +829 -0
- package/output/core/classes/seq/SEQ.d.ts +13 -0
- package/output/core/classes/seq/SEQ.js +137 -0
- package/output/core/classes/valuesSet/ValuesSet.d.ts +187 -0
- package/output/core/classes/valuesSet/ValuesSet.js +399 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +501 -0
- package/output/core/classes/vector/dispatch.d.ts +1 -0
- package/output/core/classes/vector/dispatch.js +11 -0
- package/output/core/classes/vector/functions.d.ts +28 -0
- package/output/core/classes/vector/functions.js +47 -0
- package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
- package/output/core/common/classes/MathematicalAggregate.js +149 -0
- package/output/core/common/classes/Scope.d.ts +62 -0
- package/output/core/common/classes/Scope.js +122 -0
- package/output/core/common/classes/StructuredEntity.d.ts +55 -0
- package/output/core/common/classes/StructuredEntity.js +151 -0
- package/output/core/common/common.d.ts +62 -0
- package/output/core/common/common.js +74 -0
- package/output/core/common/functions/functions.d.ts +14 -0
- package/output/core/common/functions/functions.js +33 -0
- package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
- package/output/core/common/functions/structuredEntityUtils.js +40 -0
- package/output/core/converters/BaseConverter.d.ts +97 -0
- package/output/core/converters/BaseConverter.js +405 -0
- package/output/core/converters/Converter.d.ts +111 -0
- package/output/core/converters/Converter.js +806 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +52 -0
- package/output/core/dispatch.js +26 -0
- package/output/core/errors.d.ts +316 -0
- package/output/core/errors.js +349 -0
- package/output/core/fullFunctions.d.ts +7 -0
- package/output/core/fullFunctions.js +31 -0
- package/output/core/functions/bigint/bigint.d.ts +133 -0
- package/output/core/functions/bigint/bigint.js +444 -0
- package/output/core/functions/bigint/primeFactor.d.ts +51 -0
- package/output/core/functions/bigint/primeFactor.js +267 -0
- package/output/core/functions/bigint/primes.d.ts +1 -0
- package/output/core/functions/bigint/primes.js +11 -0
- package/output/core/functions/build/definitions.d.ts +12 -0
- package/output/core/functions/build/definitions.js +139 -0
- package/output/core/functions/build/index.d.ts +32 -0
- package/output/core/functions/build/index.js +136 -0
- package/output/core/functions/complex.d.ts +90 -0
- 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 +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +665 -0
- package/output/core/functions/expand/expand.d.ts +42 -0
- package/output/core/functions/expand/expand.js +376 -0
- package/output/core/functions/fresnelNumeric.d.ts +12 -0
- package/output/core/functions/fresnelNumeric.js +123 -0
- package/output/core/functions/numeric.d.ts +140 -0
- package/output/core/functions/numeric.js +790 -0
- package/output/core/functions/rationalNormalization.d.ts +11 -0
- package/output/core/functions/rationalNormalization.js +117 -0
- package/output/core/functions/setFunction.d.ts +19 -0
- package/output/core/functions/setFunction.js +75 -0
- package/output/core/functions/string.d.ts +26 -0
- package/output/core/functions/string.js +102 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +506 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/parserFunctions.d.ts +7 -0
- package/output/core/parserFunctions.js +25 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +359 -0
- package/output/index.js +739 -0
- package/output/math/defint/defint.d.ts +18 -0
- package/output/math/defint/defint.js +60 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +321 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +281 -0
- package/output/math/dispatch.d.ts +1 -0
- package/output/math/dispatch.js +101 -0
- package/output/math/geometry.d.ts +12 -0
- package/output/math/geometry.js +55 -0
- package/output/math/math.d.ts +695 -0
- package/output/math/math.js +1955 -0
- package/output/math/trig.d.ts +518 -0
- package/output/math/trig.js +1444 -0
- package/output/math/trunc.d.ts +19 -0
- package/output/math/trunc.js +36 -0
- package/output/math/utils.d.ts +66 -0
- package/output/math/utils.js +219 -0
- package/output/solve/classes/DecimalMatrix.d.ts +17 -0
- package/output/solve/classes/DecimalMatrix.js +86 -0
- package/output/solve/classes/FunctionSolver.d.ts +135 -0
- package/output/solve/classes/FunctionSolver.js +433 -0
- package/output/solve/classes/MultivariateSolver.d.ts +84 -0
- package/output/solve/classes/MultivariateSolver.js +240 -0
- package/output/solve/classes/PolynomialSolver.d.ts +104 -0
- package/output/solve/classes/PolynomialSolver.js +492 -0
- package/output/solve/classes/SolutionSet.d.ts +172 -0
- package/output/solve/classes/SolutionSet.js +434 -0
- package/output/solve/classes/Solver.d.ts +17 -0
- package/output/solve/classes/Solver.js +132 -0
- package/output/solve/classes/SymbolicSolver.d.ts +74 -0
- package/output/solve/classes/SymbolicSolver.js +601 -0
- package/output/solve/dispatch.d.ts +1 -0
- package/output/solve/dispatch.js +13 -0
- package/output/solve/linsolve.d.ts +53 -0
- package/output/solve/linsolve.js +233 -0
- package/output/solve/solve.d.ts +44 -0
- package/output/solve/solve.js +368 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +266 -0
- package/output/solve/utils.d.ts +10 -0
- package/output/solve/utils.js +58 -0
- package/output/utils/array.d.ts +42 -0
- package/output/utils/array.js +98 -0
- package/output/utils/debug.d.ts +131 -0
- package/output/utils/debug.js +296 -0
- package/output/utils/decimal.d.ts +3 -0
- package/output/utils/decimal.js +16 -0
- package/output/utils/numeric.d.ts +14 -0
- package/output/utils/numeric.js +51 -0
- package/output/utils/object.d.ts +26 -0
- package/output/utils/object.js +56 -0
- package/package.json +178 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -14
- package/Calculus.js +0 -2675
- package/Extra.js +0 -622
- package/Solve.js +0 -1783
- package/all.js +0 -16
- package/all.min.js +0 -1
- package/gulpfile.js +0 -16
- package/index.html +0 -158
- package/license.txt +0 -19
- package/nerdamer.core.js +0 -12510
- package/spec/LaTeX.spec.js +0 -302
- package/spec/TeXConvert.spec.js +0 -8
- package/spec/algebra.spec.js +0 -287
- package/spec/basic_parser.spec.js +0 -134
- package/spec/build.spec.js +0 -131
- package/spec/calculus.spec.js +0 -183
- package/spec/core.spec.js +0 -2970
- package/spec/extra.spec.js +0 -54
- package/spec/solve.spec.js +0 -126
- package/spec/support/jasmine.json +0 -11
- package/spec/support/utils.js +0 -42
- package/spec/text.spec.js +0 -132
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.partfrac = partfrac;
|
|
4
|
+
const Expression_1 = require("../core/classes/expression/Expression");
|
|
5
|
+
const shortcuts_1 = require("../core/classes/expression/shortcuts");
|
|
6
|
+
const Matrix_1 = require("../core/classes/matrix/Matrix");
|
|
7
|
+
const Polynomial_1 = require("../core/classes/polynomial/Polynomial");
|
|
8
|
+
const utils_1 = require("../core/classes/polynomial/utils");
|
|
9
|
+
const factor_1 = require("./factor/factor");
|
|
10
|
+
/**
|
|
11
|
+
* Decomposes a rational expression P(x)/Q(x) into partial fractions.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* The routine extracts `P(x)/Q(x)`, performs polynomial long division for an improper
|
|
15
|
+
* fraction, factors `Q` over the supported exact polynomial domain, and solves the
|
|
16
|
+
* undetermined coefficients by exact evaluation and row reduction. Each denominator
|
|
17
|
+
* factor of degree d receives a numerator polynomial of degree less than d, including
|
|
18
|
+
* repeated factors. A singular coefficient system, a denominator independent of the
|
|
19
|
+
* selected variable, or a factorization that does not expose a useful decomposition
|
|
20
|
+
* leaves the original expression unchanged.
|
|
21
|
+
*
|
|
22
|
+
* @param x - Rational expression to decompose.
|
|
23
|
+
* @param variable - Main variable; defaults to the first variable reported by the expression.
|
|
24
|
+
* @returns A new decomposition when one is found, otherwise the original parsed expression.
|
|
25
|
+
*/
|
|
26
|
+
function partfrac(x, variable) {
|
|
27
|
+
const expr = Expression_1.Expression.create(x);
|
|
28
|
+
let result = expr;
|
|
29
|
+
// Determine the variable
|
|
30
|
+
const vars = expr.variables();
|
|
31
|
+
const v = variable ? String(variable) : vars[0];
|
|
32
|
+
if (v && vars.length > 0) {
|
|
33
|
+
// Extract numerator and denominator.
|
|
34
|
+
const { num, den } = extractNumDen(expr, v);
|
|
35
|
+
// Proceed only if the denominator depends on the variable
|
|
36
|
+
if (den.hasVariable(v)) {
|
|
37
|
+
const pNum = new Polynomial_1.Polynomial(num, [v]);
|
|
38
|
+
const pDen = new Polynomial_1.Polynomial(den, [v]);
|
|
39
|
+
const degNum = pNum.deg();
|
|
40
|
+
const degDen = pDen.deg();
|
|
41
|
+
// Step 1: If improper fraction, do polynomial long division
|
|
42
|
+
let polyPart = (0, shortcuts_1.zero)();
|
|
43
|
+
let remainder = num;
|
|
44
|
+
if (degNum >= degDen) {
|
|
45
|
+
const [quotient, rem] = (0, utils_1.divide)(num, den);
|
|
46
|
+
polyPart = quotient;
|
|
47
|
+
remainder = rem;
|
|
48
|
+
}
|
|
49
|
+
if (Expression_1.Expression.create(remainder).isZero()) {
|
|
50
|
+
// Remainder is zero — the expression is a polynomial
|
|
51
|
+
result = polyPart;
|
|
52
|
+
}
|
|
53
|
+
else if (degDen <= 1) {
|
|
54
|
+
// Denominator is linear or constant — no further decomposition possible.
|
|
55
|
+
// If we performed long division, return polyPart + remainder/den.
|
|
56
|
+
if (!polyPart.isZero()) {
|
|
57
|
+
result = polyPart.plus(remainder.div(den));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Step 2: Factor the denominator
|
|
62
|
+
const factors = (0, factor_1.polyFactorExpressions)(den);
|
|
63
|
+
const factorList = collectFactors(factors, v);
|
|
64
|
+
// Only decompose if factoring produced multiple factors or a repeated factor
|
|
65
|
+
const canDecompose = factorList.length > 1 || (factorList.length === 1 && factorList[0].power > 1);
|
|
66
|
+
if (canDecompose) {
|
|
67
|
+
// Step 3: Set up and solve partial fractions for remainder/den
|
|
68
|
+
const decomposition = decompose(remainder, den, factorList, v);
|
|
69
|
+
if (decomposition !== undefined) {
|
|
70
|
+
result = polyPart.isZero() ? decomposition : polyPart.plus(decomposition);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// A successful decomposition is mathematically equal to its input by definition.
|
|
77
|
+
// Use canonical text here to detect an unchanged shape rather than semantic equality.
|
|
78
|
+
return result.text() === expr.text() ? expr : result;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Extracts the numerator and denominator from an expression.
|
|
82
|
+
* For P/Q, returns { num: P, den: Q }.
|
|
83
|
+
*
|
|
84
|
+
* Rational expressions are typically stored as products where denominator
|
|
85
|
+
* factors have negative powers: P * Q^(-1).
|
|
86
|
+
*/
|
|
87
|
+
function extractNumDen(expr, _v) {
|
|
88
|
+
// Use getNumerator/getDenominator if available
|
|
89
|
+
try {
|
|
90
|
+
const num = expr.getNumerator();
|
|
91
|
+
const den = expr.getDenominator();
|
|
92
|
+
if (den && !den.isOne()) {
|
|
93
|
+
return { num, den };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Fall through to manual extraction
|
|
98
|
+
}
|
|
99
|
+
// Manual extraction: examine the product structure
|
|
100
|
+
// If the expression is a product, separate positive-power and negative-power factors
|
|
101
|
+
if (expr.isProduct()) {
|
|
102
|
+
let num = (0, shortcuts_1.one)();
|
|
103
|
+
let den = (0, shortcuts_1.one)();
|
|
104
|
+
for (const element of expr.elementsArray()) {
|
|
105
|
+
if (element.getPower().isNegative()) {
|
|
106
|
+
// Negative power → denominator factor
|
|
107
|
+
den = den.times(element.invert());
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
num = num.times(element);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Apply the overall multiplier
|
|
114
|
+
num = num.times(Expression_1.Expression.fromRational(expr.getMultiplier()));
|
|
115
|
+
return { num, den };
|
|
116
|
+
}
|
|
117
|
+
// Not a product — check if it has a negative power overall
|
|
118
|
+
if (expr.getPower().sign() === -1) {
|
|
119
|
+
return { num: Expression_1.Expression.fromRational(expr.getMultiplier()), den: expr.invert() };
|
|
120
|
+
}
|
|
121
|
+
// No denominator
|
|
122
|
+
return { num: expr, den: (0, shortcuts_1.one)() };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Collects factors from the factor() result, grouping repeated factors.
|
|
126
|
+
* Extracts embedded powers from expressions like (x-1)^3 so that the
|
|
127
|
+
* base (x-1) is stored with degree 1 and power 3.
|
|
128
|
+
*/
|
|
129
|
+
function collectFactors(factors, v) {
|
|
130
|
+
const result = [];
|
|
131
|
+
const seen = new Map(); // text → index in result
|
|
132
|
+
for (const factor of factors) {
|
|
133
|
+
let f = factor;
|
|
134
|
+
// Skip constant factors (no variable)
|
|
135
|
+
if (!f.hasVariable(v)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
// Extract embedded power from the expression (e.g., (x-1)^3 → base=(x-1), power=3)
|
|
139
|
+
let expPower = 1;
|
|
140
|
+
const p = f.getPower();
|
|
141
|
+
if (p.isInteger()) {
|
|
142
|
+
const n = Number(p.getNumerator());
|
|
143
|
+
if (n > 1) {
|
|
144
|
+
expPower = n;
|
|
145
|
+
f = f.getBase();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const key = f.text();
|
|
149
|
+
const deg = new Polynomial_1.Polynomial(f, [v]).deg();
|
|
150
|
+
if (seen.has(key)) {
|
|
151
|
+
// Repeated factor — accumulate power
|
|
152
|
+
result[seen.get(key)].power += expPower;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
seen.set(key, result.length);
|
|
156
|
+
result.push({ expr: f, power: expPower, degree: deg });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Decomposes remainder/den into partial fractions given the factored denominator.
|
|
163
|
+
*
|
|
164
|
+
* For each factor f(x)^k of degree d, the numerator at every power level is
|
|
165
|
+
* a polynomial of degree less than d. For example, a cubic factor receives
|
|
166
|
+
* A*x^2+B*x+C over each repeated power of that factor.
|
|
167
|
+
*
|
|
168
|
+
* Uses evaluation at strategic points to solve for coefficients.
|
|
169
|
+
*/
|
|
170
|
+
function decompose(numerator, denominator, factors, v) {
|
|
171
|
+
// Build the list of partial fraction terms and count unknowns.
|
|
172
|
+
// A factor of degree d contributes d numerator coefficients at each power level.
|
|
173
|
+
const terms = [];
|
|
174
|
+
let totalUnknowns = 0;
|
|
175
|
+
for (const f of factors) {
|
|
176
|
+
for (let k = 1; k <= f.power; k++) {
|
|
177
|
+
terms.push({
|
|
178
|
+
factor: f.expr,
|
|
179
|
+
power: k,
|
|
180
|
+
unknownIndex: totalUnknowns,
|
|
181
|
+
numUnknowns: f.degree,
|
|
182
|
+
});
|
|
183
|
+
totalUnknowns += f.degree;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// We need to solve: P(x)/Q(x) = Σ terms
|
|
187
|
+
// Multiply both sides by Q(x):
|
|
188
|
+
// P(x) = Σ (coefficients_i × Q(x) / factor_i^power_i)
|
|
189
|
+
//
|
|
190
|
+
// Strategy: evaluate at `totalUnknowns` distinct values of x to get a linear system,
|
|
191
|
+
// then solve it.
|
|
192
|
+
// Collect evaluation points: roots of linear factors + additional integer points
|
|
193
|
+
const evalPoints = [];
|
|
194
|
+
for (const f of factors) {
|
|
195
|
+
if (f.degree === 1) {
|
|
196
|
+
// Linear factor ax + b: root is x = -b/a
|
|
197
|
+
const root = findLinearRoot(f.expr, v);
|
|
198
|
+
if (root !== undefined) {
|
|
199
|
+
evalPoints.push(root);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Add additional integer points to get enough equations
|
|
204
|
+
let pointVal = 0;
|
|
205
|
+
while (evalPoints.length < totalUnknowns) {
|
|
206
|
+
const candidate = Expression_1.Expression.Number(pointVal);
|
|
207
|
+
// Make sure this isn't a root of the denominator (would give division by zero)
|
|
208
|
+
const denAtPoint = evaluateAt(denominator, v, candidate);
|
|
209
|
+
if (!denAtPoint.isZero()) {
|
|
210
|
+
// Also make sure it's not already in our list
|
|
211
|
+
const isDuplicate = evalPoints.some(p => p.eq(candidate));
|
|
212
|
+
if (!isDuplicate) {
|
|
213
|
+
evalPoints.push(candidate);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
pointVal = pointVal <= 0 ? -pointVal + 1 : -pointVal;
|
|
217
|
+
}
|
|
218
|
+
// Build and solve the linear system by evaluation.
|
|
219
|
+
// For each eval point xᵢ:
|
|
220
|
+
// P(xᵢ) = Σⱼ unknowns_j × basisⱼ(xᵢ)
|
|
221
|
+
// where basisⱼ(x) is what multiplies the j-th unknown after clearing denominators.
|
|
222
|
+
const rows = [];
|
|
223
|
+
const rhs = [];
|
|
224
|
+
const cofactors = terms.map(term => computeCofactor(denominator, term.factor, term.power));
|
|
225
|
+
for (let i = 0; i < totalUnknowns; i++) {
|
|
226
|
+
const x = evalPoints[i];
|
|
227
|
+
const numVal = evaluateAt(numerator, v, x);
|
|
228
|
+
rhs.push(numVal);
|
|
229
|
+
const row = [];
|
|
230
|
+
for (let j = 0; j < terms.length; j++) {
|
|
231
|
+
const term = terms[j];
|
|
232
|
+
// The basis for this term: Q(x) / factor^power, evaluated at x.
|
|
233
|
+
const cofactor = evaluateAt(cofactors[j], v, x);
|
|
234
|
+
for (let degree = term.numUnknowns - 1; degree >= 0; degree--) {
|
|
235
|
+
const monomial = degree === 0 ? (0, shortcuts_1.one)() : x.pow(Expression_1.Expression.Number(degree));
|
|
236
|
+
row.push(monomial.times(cofactor));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
rows.push(row);
|
|
240
|
+
}
|
|
241
|
+
// Solve the system
|
|
242
|
+
const solution = solveLinearSystem(rows, rhs);
|
|
243
|
+
if (solution === undefined) {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
// Build the result expression from the solved coefficients
|
|
247
|
+
let result = (0, shortcuts_1.zero)();
|
|
248
|
+
const variable = Expression_1.Expression.create(v);
|
|
249
|
+
for (const term of terms) {
|
|
250
|
+
const denomPart = term.power === 1 ? term.factor : term.factor.pow(Expression_1.Expression.Number(term.power));
|
|
251
|
+
let numPart = (0, shortcuts_1.zero)();
|
|
252
|
+
for (let i = 0; i < term.numUnknowns; i++) {
|
|
253
|
+
const coefficient = solution[term.unknownIndex + i];
|
|
254
|
+
const degree = term.numUnknowns - 1 - i;
|
|
255
|
+
const monomial = degree === 0 ? (0, shortcuts_1.one)() : variable.pow(Expression_1.Expression.Number(degree));
|
|
256
|
+
numPart = numPart.plus(coefficient.times(monomial));
|
|
257
|
+
}
|
|
258
|
+
if (!numPart.isZero()) {
|
|
259
|
+
result = result.plus(numPart.div(denomPart));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Finds the root of a linear expression ax + b, returning -b/a.
|
|
266
|
+
*/
|
|
267
|
+
function findLinearRoot(expr, v) {
|
|
268
|
+
// A linear expression ax + b: evaluate at x=0 to get b, at x=1 to get a+b
|
|
269
|
+
const atZero = evaluateAt(expr, v, (0, shortcuts_1.zero)());
|
|
270
|
+
const atOne = evaluateAt(expr, v, (0, shortcuts_1.one)());
|
|
271
|
+
const a = atOne.plus(atZero.times((0, shortcuts_1.minusOne)())); // a = f(1) - f(0)
|
|
272
|
+
if (a.isZero()) {
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
// root = -b/a = -f(0)/a
|
|
276
|
+
return atZero.times((0, shortcuts_1.minusOne)()).div(a);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Evaluates a polynomial expression at a specific rational value of the variable.
|
|
280
|
+
* Returns the result as an Expression.
|
|
281
|
+
*/
|
|
282
|
+
function evaluateAt(expr, v, value) {
|
|
283
|
+
return expr.subst(v, value);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Computes Q(x) / factor(x)^power.
|
|
287
|
+
* This is the "cofactor" — the part of the denominator that remains after removing this term's factor.
|
|
288
|
+
*/
|
|
289
|
+
function computeCofactor(denominator, fac, power) {
|
|
290
|
+
// Q / factor^power
|
|
291
|
+
const facPow = power === 1 ? fac : fac.pow(Expression_1.Expression.Number(power));
|
|
292
|
+
const [quotient] = (0, utils_1.divide)(denominator, facPow);
|
|
293
|
+
return quotient;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Solves a linear system Ax = b using Gaussian elimination with partial pivoting.
|
|
297
|
+
* Works with Expression arithmetic (exact rational arithmetic).
|
|
298
|
+
*
|
|
299
|
+
* @param A The coefficient matrix (array of rows)
|
|
300
|
+
* @param b The right-hand side vector
|
|
301
|
+
* @returns The solution vector, or undefined if the system is singular
|
|
302
|
+
*/
|
|
303
|
+
function solveLinearSystem(A, b) {
|
|
304
|
+
const n = b.length;
|
|
305
|
+
if (n === 0) {
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
// This solver is used to recover exact coefficients for partial fractions.
|
|
309
|
+
// Use Matrix.rref() so we don't duplicate row-reduction logic.
|
|
310
|
+
// Require a unique solution (square, full-rank). Otherwise return undefined.
|
|
311
|
+
const A_mat = new Matrix_1.Matrix(...A);
|
|
312
|
+
const b_col = new Matrix_1.Matrix(...b.map(v => [v]));
|
|
313
|
+
const aug = A_mat.augment(b_col).rref();
|
|
314
|
+
const rows = aug.rows();
|
|
315
|
+
const cols = aug.cols();
|
|
316
|
+
const unknowns = cols - 1;
|
|
317
|
+
if (rows !== n || unknowns !== n) {
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
// Inconsistency: [0 ... 0 | nonzero]
|
|
321
|
+
for (let i = 0; i < rows; i++) {
|
|
322
|
+
let allZero = true;
|
|
323
|
+
for (let j = 0; j < unknowns; j++) {
|
|
324
|
+
if (!aug.elements[i][j].isZero()) {
|
|
325
|
+
allZero = false;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (allZero && !aug.elements[i][unknowns].isZero()) {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
// Extract solution from pivots. Expect [I | x] up to row ordering.
|
|
334
|
+
const solution = new Array(n);
|
|
335
|
+
const pivotCols = new Set();
|
|
336
|
+
for (let i = 0; i < rows; i++) {
|
|
337
|
+
let pivot = -1;
|
|
338
|
+
for (let j = 0; j < unknowns; j++) {
|
|
339
|
+
if (!aug.elements[i][j].isZero()) {
|
|
340
|
+
pivot = j;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (pivot === -1) {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (!aug.elements[i][pivot].eq('1')) {
|
|
348
|
+
return undefined;
|
|
349
|
+
}
|
|
350
|
+
if (pivotCols.has(pivot)) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
pivotCols.add(pivot);
|
|
354
|
+
solution[pivot] = aug.elements[i][unknowns];
|
|
355
|
+
}
|
|
356
|
+
if (pivotCols.size !== n) {
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
for (let i = 0; i < n; i++) {
|
|
360
|
+
if (!solution[i]) {
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return solution;
|
|
365
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module modularSparsePolynomial
|
|
3
|
+
*
|
|
4
|
+
* Sparse polynomial arithmetic over integer residue classes.
|
|
5
|
+
*
|
|
6
|
+
* External references consulted for modular coefficient arithmetic and sparse
|
|
7
|
+
* polynomial division:
|
|
8
|
+
* - SymPy finite-field polynomial arithmetic:
|
|
9
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/galoistools.py
|
|
10
|
+
* - SymPy sparse polynomial substitution, evaluation, and term division:
|
|
11
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/sparsetools.py
|
|
12
|
+
* - SymPy variable-relative leading coefficient operations used by modular GCD:
|
|
13
|
+
* https://github.com/sympy/sympy/blob/120ee85f346f6292b763cc195afda4f907260d4a/sympy/polys/zippel.py
|
|
14
|
+
*/
|
|
15
|
+
import { SparsePolynomial, type MonomialOrder, type SparsePolynomialTerm } from '../../core/classes/polynomial/SparsePolynomial';
|
|
16
|
+
/**
|
|
17
|
+
* Sparse polynomial whose coefficients are stored as canonical residues modulo
|
|
18
|
+
* a positive integer greater than one.
|
|
19
|
+
*
|
|
20
|
+
* The modulus is part of the polynomial ring. Prime moduli provide finite-field
|
|
21
|
+
* arithmetic; composite moduli remain valid for addition and multiplication but
|
|
22
|
+
* may not provide multiplicative inverses required by monic normalization or
|
|
23
|
+
* polynomial division.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ModularSparsePolynomial {
|
|
26
|
+
private readonly polynomial;
|
|
27
|
+
readonly modulus: bigint;
|
|
28
|
+
readonly variableCount: number;
|
|
29
|
+
constructor(variableCount: number, modulus: bigint, terms?: Iterable<SparsePolynomialTerm> | SparsePolynomial);
|
|
30
|
+
/** Creates a constant polynomial in the selected residue ring. */
|
|
31
|
+
static constant(variableCount: number, modulus: bigint, coefficient: bigint): ModularSparsePolynomial;
|
|
32
|
+
/**
|
|
33
|
+
* Reconstructs a polynomial in one variable from specialized images.
|
|
34
|
+
*
|
|
35
|
+
* Each sample polynomial must be independent of the interpolated variable.
|
|
36
|
+
* Evaluation values are compared as residues in the shared coefficient ring.
|
|
37
|
+
*/
|
|
38
|
+
static interpolateVariable(variableIndex: number, samples: ReadonlyArray<Readonly<{
|
|
39
|
+
value: bigint;
|
|
40
|
+
polynomial: ModularSparsePolynomial;
|
|
41
|
+
}>>): ModularSparsePolynomial;
|
|
42
|
+
/** Creates a one-term polynomial in the selected residue ring. */
|
|
43
|
+
static monomial(variableCount: number, modulus: bigint, coefficient: bigint, exponents: readonly bigint[]): ModularSparsePolynomial;
|
|
44
|
+
/** Creates one polynomial variable with coefficient one. */
|
|
45
|
+
static variable(variableCount: number, modulus: bigint, variableIndex: number): ModularSparsePolynomial;
|
|
46
|
+
/** Creates the zero polynomial in the selected residue ring. */
|
|
47
|
+
static zero(variableCount: number, modulus: bigint): ModularSparsePolynomial;
|
|
48
|
+
/** Verifies that another polynomial belongs to the same residue ring. */
|
|
49
|
+
private assertCompatible;
|
|
50
|
+
/** Adds another polynomial in the same residue ring. */
|
|
51
|
+
add(other: ModularSparsePolynomial): ModularSparsePolynomial;
|
|
52
|
+
/** Returns the canonical residue coefficient of one monomial. */
|
|
53
|
+
coefficient(exponents: readonly bigint[]): bigint;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the coefficient polynomial at one exact power of a selected variable.
|
|
56
|
+
*
|
|
57
|
+
* The selected variable remains in the ring with exponent zero.
|
|
58
|
+
*/
|
|
59
|
+
coefficientIn(variableIndex: number, exponent: bigint): ModularSparsePolynomial;
|
|
60
|
+
/** Returns the canonical residue of the constant coefficient. */
|
|
61
|
+
constantTerm(): bigint;
|
|
62
|
+
/** Returns the degree in one variable, or null for the zero polynomial. */
|
|
63
|
+
degree(variableIndex: number): bigint | null;
|
|
64
|
+
/**
|
|
65
|
+
* Differentiates with respect to one ring variable in the residue ring.
|
|
66
|
+
*/
|
|
67
|
+
derivative(variableIndex: number): ModularSparsePolynomial;
|
|
68
|
+
/**
|
|
69
|
+
* Divides by one polynomial when the remainder is zero.
|
|
70
|
+
*/
|
|
71
|
+
divideExact(divisor: ModularSparsePolynomial, order?: MonomialOrder): ModularSparsePolynomial | null;
|
|
72
|
+
/**
|
|
73
|
+
* Divides by one polynomial and returns quotient and remainder.
|
|
74
|
+
*
|
|
75
|
+
* The leading coefficient of the divisor must be invertible modulo the ring
|
|
76
|
+
* modulus.
|
|
77
|
+
*/
|
|
78
|
+
divideWithRemainder(divisor: ModularSparsePolynomial, order?: MonomialOrder): Readonly<{
|
|
79
|
+
quotient: ModularSparsePolynomial;
|
|
80
|
+
remainder: ModularSparsePolynomial;
|
|
81
|
+
}>;
|
|
82
|
+
/** Returns whether two polynomials have the same residue ring and exact terms. */
|
|
83
|
+
equals(other: ModularSparsePolynomial): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Substitutes one variable with a residue while keeping the same ring dimension.
|
|
86
|
+
*
|
|
87
|
+
* Terms that become like terms after substitution are combined by the sparse
|
|
88
|
+
* polynomial constructor.
|
|
89
|
+
*/
|
|
90
|
+
evaluateVariable(variableIndex: number, value: bigint): ModularSparsePolynomial;
|
|
91
|
+
/** Returns whether the polynomial is zero or contains only a constant term. */
|
|
92
|
+
isConstant(): boolean;
|
|
93
|
+
/** Returns whether the polynomial has no nonzero terms. */
|
|
94
|
+
isZero(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the coefficient polynomial of the highest power of one variable.
|
|
97
|
+
*
|
|
98
|
+
* The selected variable remains in the ring with exponent zero so recursive
|
|
99
|
+
* algorithms can preserve a stable variable layout.
|
|
100
|
+
*/
|
|
101
|
+
leadingCoefficientIn(variableIndex: number): ModularSparsePolynomial | null;
|
|
102
|
+
/** Returns the leading term under the requested monomial order. */
|
|
103
|
+
leadingTerm(order?: MonomialOrder): SparsePolynomialTerm | null;
|
|
104
|
+
/**
|
|
105
|
+
* Scales the polynomial so its leading coefficient is one.
|
|
106
|
+
*
|
|
107
|
+
* Zero remains zero. A nonzero leading coefficient that has no inverse modulo
|
|
108
|
+
* the modulus is rejected.
|
|
109
|
+
*/
|
|
110
|
+
monic(order?: MonomialOrder): ModularSparsePolynomial;
|
|
111
|
+
/** Multiplies by another polynomial in the same residue ring. */
|
|
112
|
+
multiply(other: ModularSparsePolynomial): ModularSparsePolynomial;
|
|
113
|
+
/** Returns the additive inverse in the residue ring. */
|
|
114
|
+
negate(): ModularSparsePolynomial;
|
|
115
|
+
/** Raises the polynomial to a non-negative exact integer power. */
|
|
116
|
+
pow(exponent: bigint): ModularSparsePolynomial;
|
|
117
|
+
/** Multiplies every coefficient by one residue-ring scalar. */
|
|
118
|
+
scale(scalar: bigint): ModularSparsePolynomial;
|
|
119
|
+
/** Subtracts another polynomial in the same residue ring. */
|
|
120
|
+
subtract(other: ModularSparsePolynomial): ModularSparsePolynomial;
|
|
121
|
+
/** Number of stored nonzero terms. */
|
|
122
|
+
get termCount(): number;
|
|
123
|
+
/** Returns the stored canonical residue terms. */
|
|
124
|
+
terms(): readonly SparsePolynomialTerm[];
|
|
125
|
+
/** Converts canonical residues to centered integer representatives. */
|
|
126
|
+
toSymmetricIntegerPolynomial(): SparsePolynomial;
|
|
127
|
+
/** Returns the largest total degree, or null for the zero polynomial. */
|
|
128
|
+
totalDegree(): bigint | null;
|
|
129
|
+
/** Returns the variable indices that occur with a positive exponent. */
|
|
130
|
+
variables(): readonly number[];
|
|
131
|
+
}
|