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
|
+
/**
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Expression } from '../core/classes/expression/Expression';
|
|
2
|
+
import type { Vector } from '../core/classes/vector/Vector';
|
|
3
|
+
import type { MapObjectType } from '../core/functions/subst';
|
|
4
|
+
/**
|
|
5
|
+
* Attempts to put the expression in polynomial form.
|
|
6
|
+
*
|
|
7
|
+
* @param expression The expression to normalize and polynomialize.
|
|
8
|
+
* @param map Existing u-substitutions to preserve across related expressions.
|
|
9
|
+
* @returns Polynomial numerator and denominator plus the substitution map.
|
|
10
|
+
*/
|
|
11
|
+
export declare function polynomialize(expression: Expression, map?: MapObjectType): {
|
|
12
|
+
numerator: Expression;
|
|
13
|
+
denominator: Expression;
|
|
14
|
+
map: MapObjectType;
|
|
15
|
+
};
|
|
16
|
+
export declare function polynomialize<T extends Expression | Vector>(expression: Expression, map: MapObjectType | undefined, callback: (e: Expression, map: MapObjectType) => T): {
|
|
17
|
+
numerator: T;
|
|
18
|
+
denominator: T;
|
|
19
|
+
map: MapObjectType;
|
|
20
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.polynomialize = polynomialize;
|
|
4
|
+
const subst_1 = require("../core/functions/subst");
|
|
5
|
+
const simplify_1 = require("./simplify/simplify");
|
|
6
|
+
function polynomialize(expression, map, callback) {
|
|
7
|
+
map ??= {};
|
|
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);
|
|
12
|
+
// Substitute out all functions
|
|
13
|
+
[x, map] = (0, subst_1.uSubFN)(x, map);
|
|
14
|
+
// Substitute out all exponential functions
|
|
15
|
+
[x, map] = (0, subst_1.uSubEXP)(x, map);
|
|
16
|
+
// Constants although numeric are irrationals and need to be removed.
|
|
17
|
+
[x, map] = (0, subst_1.uSubConstants)(x, map);
|
|
18
|
+
// Extract the numerator and denominator
|
|
19
|
+
const num = x.getNumerator();
|
|
20
|
+
const den = x.getDenominator();
|
|
21
|
+
return {
|
|
22
|
+
numerator: callback ? callback(num, map) : num,
|
|
23
|
+
denominator: callback ? callback(den, map) : den,
|
|
24
|
+
map,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.complexSimplify = complexSimplify;
|
|
4
|
+
const Expression_1 = require("../../core/classes/expression/Expression");
|
|
5
|
+
const shortcuts_1 = require("../../core/classes/expression/shortcuts");
|
|
6
|
+
const expand_1 = require("../../core/functions/expand/expand");
|
|
7
|
+
/**
|
|
8
|
+
* Simplifies a complex number. Assumes expression is in the form a*i+b
|
|
9
|
+
*
|
|
10
|
+
* @param x
|
|
11
|
+
*/
|
|
12
|
+
function complexSimplify(x) {
|
|
13
|
+
const p = x.getPower();
|
|
14
|
+
// Only handle (a*i+b)^(-1) -> a/(a^2+b^2) - b/(a^2+b^2)*i
|
|
15
|
+
if (!p.isInteger() || !p.isMinusOne() /* or p.text() !== '-1' */) {
|
|
16
|
+
return x;
|
|
17
|
+
}
|
|
18
|
+
// base = (a*i+b)
|
|
19
|
+
const base = (0, expand_1.expand)(x.invert());
|
|
20
|
+
const re = base.realPart();
|
|
21
|
+
const im = base.imagPart();
|
|
22
|
+
const d = re.pow((0, shortcuts_1.two)()).plus(im.pow((0, shortcuts_1.two)()));
|
|
23
|
+
return re.div(d).minus(im.div(d).times(Expression_1.Expression.Img()));
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Expression } from '../../core/classes/expression/Expression';
|
|
2
|
+
/**
|
|
3
|
+
* Factors out the greatest common power from each base in a sum expression.
|
|
4
|
+
*
|
|
5
|
+
* For example:
|
|
6
|
+
* x^(3/2) + x^(1/2) → x^(1/2) * (x + 1)
|
|
7
|
+
* x^3 + x^2 → x^2 * (x + 1)
|
|
8
|
+
* 2*x^(5/2) + 3*x^(3/2) → x^(3/2) * (2*x + 3)
|
|
9
|
+
* x^2*y + x*y^2 → x*y * (x + y)
|
|
10
|
+
*
|
|
11
|
+
* Only applies to sums. Non-sum expressions are returned unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function factorCommonPower(x: Expression): Expression;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.factorCommonPower = factorCommonPower;
|
|
4
|
+
const Expression_1 = require("../../core/classes/expression/Expression");
|
|
5
|
+
const shortcuts_1 = require("../../core/classes/expression/shortcuts");
|
|
6
|
+
/**
|
|
7
|
+
* Extracts a map of {base_value → power} from a single term of a sum.
|
|
8
|
+
*
|
|
9
|
+
* For a simple variable like x^(3/2), returns { 'x': 3/2 as Expression }
|
|
10
|
+
* For a product like 2*x^(3/2)*y^2, returns { 'x': 3/2, 'y': 2 }
|
|
11
|
+
* For a constant like 5, returns {}
|
|
12
|
+
*
|
|
13
|
+
* The coefficient (numeric multiplier) is not included in the map.
|
|
14
|
+
*/
|
|
15
|
+
function extractBasePowers(term) {
|
|
16
|
+
const map = new Map();
|
|
17
|
+
if (term.isNUM()) {
|
|
18
|
+
// Pure number — no bases to extract
|
|
19
|
+
return map;
|
|
20
|
+
}
|
|
21
|
+
if (term.isProduct()) {
|
|
22
|
+
for (const element of term.elementsArray()) {
|
|
23
|
+
if (!element.isNUM()) {
|
|
24
|
+
const base = element.getBase();
|
|
25
|
+
const key = base.text();
|
|
26
|
+
const power = element.getPower();
|
|
27
|
+
// Accumulate: a product might have the same base appear once,
|
|
28
|
+
// but just in case, add powers
|
|
29
|
+
const existing = map.get(key);
|
|
30
|
+
map.set(key, existing !== undefined ? existing.plus(power) : power);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const base = term.getBase();
|
|
36
|
+
const key = base.text();
|
|
37
|
+
map.set(key, term.getPower());
|
|
38
|
+
}
|
|
39
|
+
return map;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Factors out the greatest common power from each base in a sum expression.
|
|
43
|
+
*
|
|
44
|
+
* For example:
|
|
45
|
+
* x^(3/2) + x^(1/2) → x^(1/2) * (x + 1)
|
|
46
|
+
* x^3 + x^2 → x^2 * (x + 1)
|
|
47
|
+
* 2*x^(5/2) + 3*x^(3/2) → x^(3/2) * (2*x + 3)
|
|
48
|
+
* x^2*y + x*y^2 → x*y * (x + y)
|
|
49
|
+
*
|
|
50
|
+
* Only applies to sums. Non-sum expressions are returned unchanged.
|
|
51
|
+
*/
|
|
52
|
+
function factorCommonPower(x) {
|
|
53
|
+
if (!x.isSum()) {
|
|
54
|
+
return x;
|
|
55
|
+
}
|
|
56
|
+
const m = x.getMultiplier();
|
|
57
|
+
const p = x.getPower();
|
|
58
|
+
const terms = x.elementsArray();
|
|
59
|
+
// Edge case: single term or empty
|
|
60
|
+
if (terms.length < 2) {
|
|
61
|
+
return x;
|
|
62
|
+
}
|
|
63
|
+
// Step 1: Extract base → power maps for each term
|
|
64
|
+
const termMaps = [];
|
|
65
|
+
let hasConstantTerm = false;
|
|
66
|
+
for (const term of terms) {
|
|
67
|
+
const map = extractBasePowers(term);
|
|
68
|
+
termMaps.push(map);
|
|
69
|
+
if (map.size === 0) {
|
|
70
|
+
hasConstantTerm = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// If there's a constant term (no bases), no common base can be factored
|
|
74
|
+
if (hasConstantTerm) {
|
|
75
|
+
return x;
|
|
76
|
+
}
|
|
77
|
+
// Step 2: Find bases common to ALL terms
|
|
78
|
+
const commonBases = new Set(termMaps[0].keys());
|
|
79
|
+
for (let i = 1; i < termMaps.length; i++) {
|
|
80
|
+
for (const key of commonBases) {
|
|
81
|
+
if (!termMaps[i].has(key)) {
|
|
82
|
+
commonBases.delete(key);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Nothing common to factor out
|
|
87
|
+
if (commonBases.size === 0) {
|
|
88
|
+
return x;
|
|
89
|
+
}
|
|
90
|
+
// Step 3: For each common base, find the minimum power across all terms
|
|
91
|
+
const minPowers = new Map();
|
|
92
|
+
for (const base of commonBases) {
|
|
93
|
+
let minPow = termMaps[0].get(base);
|
|
94
|
+
if (minPow === undefined) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
for (let i = 1; i < termMaps.length; i++) {
|
|
98
|
+
const pow = termMaps[i].get(base);
|
|
99
|
+
if (pow === undefined) {
|
|
100
|
+
minPow = undefined;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
// Use lt to compare — take the smaller power
|
|
104
|
+
if (pow.lt(minPow)) {
|
|
105
|
+
minPow = pow;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Only factor out positive powers
|
|
109
|
+
if (minPow !== undefined && minPow.sign() === 1) {
|
|
110
|
+
minPowers.set(base, minPow);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Nothing positive to factor out
|
|
114
|
+
if (minPowers.size === 0) {
|
|
115
|
+
return x;
|
|
116
|
+
}
|
|
117
|
+
// Step 4: Build the common factor and the reduced sum
|
|
118
|
+
let commonFactor = (0, shortcuts_1.one)();
|
|
119
|
+
for (const [base, power] of minPowers) {
|
|
120
|
+
commonFactor = commonFactor.times(Expression_1.Expression.create(base).pow(power));
|
|
121
|
+
}
|
|
122
|
+
// Step 5: Divide each term by the common factor to get the inner sum
|
|
123
|
+
let innerSum = (0, shortcuts_1.zero)();
|
|
124
|
+
for (const term of terms) {
|
|
125
|
+
innerSum = innerSum.plus(term.div(commonFactor));
|
|
126
|
+
}
|
|
127
|
+
// Step 6: Reconstruct with outer multiplier and power
|
|
128
|
+
let result = commonFactor.times(innerSum);
|
|
129
|
+
if (!p.isOne()) {
|
|
130
|
+
result = result.pow(p);
|
|
131
|
+
}
|
|
132
|
+
if (!m.isOne()) {
|
|
133
|
+
result = result.times(m);
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Expression } from '../../core/classes/expression/Expression';
|
|
2
|
+
/**
|
|
3
|
+
* Simplifies factorial ratios in a product expression.
|
|
4
|
+
*
|
|
5
|
+
* n! · (n+k)!^(-1) → 1 / ((n+1)(n+2)...(n+k)) when k > 0
|
|
6
|
+
* (n+k)! · n!^(-1) → (n+1)(n+2)...(n+k) when k > 0
|
|
7
|
+
*
|
|
8
|
+
* Works by finding pairs of factorials where one has power 1 and the other
|
|
9
|
+
* has power -1, computing their argument difference, and replacing with
|
|
10
|
+
* the product of consecutive integers.
|
|
11
|
+
*/
|
|
12
|
+
export declare function simplifyFactorials(x: Expression): Expression;
|
|
13
|
+
/**
|
|
14
|
+
* Combines logarithmic terms in a sum expression when their arguments are
|
|
15
|
+
* provably positive real values. Unknown-sign logarithms are left unchanged
|
|
16
|
+
* so these real-domain identities do not cross principal complex branches.
|
|
17
|
+
*
|
|
18
|
+
* Power lifting + combination:
|
|
19
|
+
* log(x) + log(y) → log(x·y) [combine, coeff=1]
|
|
20
|
+
* 2·log(x) + 3·log(y) → log(x²·y³) [lift then combine]
|
|
21
|
+
* (1/2)·log(x) → (1/2)·log(x) [rational, standalone: keep]
|
|
22
|
+
* (1/2)·log(x) + (1/3)·log(y) → log(x^(1/2)·y^(1/3)) [rational, combining: lift]
|
|
23
|
+
* a·log(u) + a·log(v) → a·log(u·v) [symbolic, group by coeff]
|
|
24
|
+
* log(a) - log(b) → log(a/b) [sign handling]
|
|
25
|
+
*/
|
|
26
|
+
export declare function simplifyLogs(x: Expression): Expression;
|