nerdamer 1.1.13 → 2.0.0-rc.1
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/LICENSE.md +184 -0
- package/README.md +293 -312
- 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 +1960 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +33 -0
- package/output/algebra/adapters.js +109 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +323 -0
- package/output/algebra/algorithms/factor.d.ts +3 -0
- package/output/algebra/algorithms/factor.js +5 -0
- package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
- package/output/algebra/algorithms/factorMultivariate.js +2393 -0
- package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
- package/output/algebra/algorithms/factorUnivariate.js +1072 -0
- package/output/algebra/algorithms/gcd.d.ts +22 -0
- package/output/algebra/algorithms/gcd.js +690 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
- package/output/algebra/algorithms/groebnerBase.js +1166 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
- package/output/algebra/algorithms/poly.d.ts +228 -0
- package/output/algebra/algorithms/poly.js +1299 -0
- package/output/algebra/algorithms/rational.d.ts +17 -0
- package/output/algebra/algorithms/rational.js +115 -0
- package/output/algebra/factor/factor.d.ts +62 -0
- package/output/algebra/factor/factor.js +158 -0
- package/output/algebra/gcd/gcd.d.ts +29 -0
- package/output/algebra/gcd/gcd.js +141 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +42 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +398 -0
- package/output/algebra/polynomialize.d.ts +20 -0
- package/output/algebra/polynomialize.js +24 -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 +228 -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 +7 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +32 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +9 -0
- package/output/api/calculus.js +21 -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/parser.d.ts +85 -0
- package/output/api/parser.js +16 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +16 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +22 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +238 -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/adapters.d.ts +18 -0
- package/output/core/adapters.js +40 -0
- package/output/core/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +605 -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/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +231 -0
- package/output/core/classes/complex/Complex.d.ts +99 -0
- package/output/core/classes/complex/Complex.js +135 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +453 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +213 -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 +198 -0
- package/output/core/classes/expression/Expression.d.ts +1674 -0
- package/output/core/classes/expression/Expression.js +2332 -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 +45 -0
- package/output/core/classes/expression/format.js +217 -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 +52 -0
- package/output/core/classes/expression/utils.js +189 -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 +889 -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/functions.d.ts +26 -0
- package/output/core/classes/matrix/functions.js +52 -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 +480 -0
- package/output/core/classes/parser/Parser.js +1812 -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 +160 -0
- package/output/core/classes/parser/constants.js +227 -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 +238 -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 +461 -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 +430 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +321 -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 +35 -0
- package/output/core/classes/parser/preprocess.d.ts +14 -0
- package/output/core/classes/parser/preprocess.js +259 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
- package/output/core/classes/parser/scripting/controlFlow.js +355 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
- package/output/core/classes/parser/scripting/evaluate.js +112 -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 +35 -0
- package/output/core/classes/parser/scripting/scope.js +155 -0
- package/output/core/classes/parser/types.d.ts +125 -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 +500 -0
- package/output/core/classes/polynomial/Polynomial.js +1149 -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/functions.d.ts +69 -0
- package/output/core/classes/polynomial/functions.js +126 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +206 -0
- package/output/core/classes/rational/Rational.d.ts +504 -0
- package/output/core/classes/rational/Rational.js +779 -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 +179 -0
- package/output/core/classes/valuesSet/ValuesSet.js +381 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +497 -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 +140 -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 +63 -0
- package/output/core/common/common.js +279 -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 +802 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +34 -0
- package/output/core/dispatch.js +304 -0
- package/output/core/errors.d.ts +531 -0
- package/output/core/errors.js +621 -0
- package/output/core/functions/bigint/bigint.d.ts +121 -0
- package/output/core/functions/bigint/bigint.js +392 -0
- package/output/core/functions/bigint/primeFactor.d.ts +49 -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 +133 -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.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +664 -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 +101 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +498 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +339 -0
- package/output/index.js +715 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +320 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +292 -0
- package/output/math/geometry.d.ts +8 -0
- package/output/math/geometry.js +32 -0
- package/output/math/math.d.ts +655 -0
- package/output/math/math.js +1811 -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 +60 -0
- package/output/math/utils.js +180 -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 +85 -0
- package/output/solve/classes/PolynomialSolver.js +292 -0
- package/output/solve/classes/SolutionSet.d.ts +153 -0
- package/output/solve/classes/SolutionSet.js +357 -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/linsolve.d.ts +51 -0
- package/output/solve/linsolve.js +225 -0
- package/output/solve/solve.d.ts +34 -0
- package/output/solve/solve.js +260 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +290 -0
- package/output/solve/utils.d.ts +9 -0
- package/output/solve/utils.js +62 -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 +295 -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 +213 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- package/BREAKING_CHANGES.md +0 -5
- 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,69 @@
|
|
|
1
|
+
import { Expression } from '../expression/Expression';
|
|
2
|
+
import { Vector } from '../vector/Vector';
|
|
3
|
+
import { Polynomial } from './Polynomial';
|
|
4
|
+
import type { ExpressionInput } from '../../types';
|
|
5
|
+
/**
|
|
6
|
+
* Returns the degree of a polynomial expression.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* With no variable, `deg(p)` returns the total degree: the largest sum of powers in any
|
|
10
|
+
* term. With a variable, `deg(p, x)` returns the largest power of `x`, treating the other
|
|
11
|
+
* variables as coefficients. If the input cannot be converted to a polynomial, the call
|
|
12
|
+
* remains symbolic instead of throwing.
|
|
13
|
+
*
|
|
14
|
+
* @param x - Expression-like input or polynomial to inspect.
|
|
15
|
+
* @param variable - Optional variable whose degree should be returned.
|
|
16
|
+
* @returns A numeric expression for polynomial input, otherwise an unevaluated `deg(...)` call.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* deg('x^2*y^3+x').text(); // "5"
|
|
21
|
+
* deg('x^2*y^3+x', 'x').text(); // "2"
|
|
22
|
+
* deg('x^2*y^3+x', 'y').text(); // "3"
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function deg(x: ExpressionInput | Polynomial, variable?: ExpressionInput): Expression;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the exact numeric content of polynomial expression input.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Content means the greatest common divisor of the polynomial's numeric coefficients.
|
|
31
|
+
* For example, the content of `6*x^2+15*x*y-3*y` is `3`. This function does not choose
|
|
32
|
+
* a main variable or compute a polynomial-valued GCD of symbolic coefficient expressions.
|
|
33
|
+
* If expression conversion fails, the operation remains symbolic as `content(input)`.
|
|
34
|
+
*
|
|
35
|
+
* @param x - Expression-like input or polynomial to inspect.
|
|
36
|
+
* @returns A numeric expression for converted input, otherwise an unevaluated symbolic
|
|
37
|
+
* `content` call.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* content('6*x^2+15*x-3').text(); // "3"
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function content(x: ExpressionInput | Polynomial): Expression;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the quotient and remainder of polynomial division.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* This is the parser-facing compatibility behavior historically exposed as `div(a,b)`.
|
|
50
|
+
* It delegates to the existing polynomial division implementation. When more than one
|
|
51
|
+
* variable is present, Nerdamer treats the input as a multivariable polynomial rather than
|
|
52
|
+
* silently choosing one variable and treating the others as coefficients. If either input
|
|
53
|
+
* is not polynomial-like, the legacy fallback is preserved as `[0, dividend]`. Once both
|
|
54
|
+
* inputs are polynomial, failures from the division engine are allowed to propagate.
|
|
55
|
+
*/
|
|
56
|
+
export declare function div(dividend: ExpressionInput, divisor: ExpressionInput): Vector;
|
|
57
|
+
/**
|
|
58
|
+
* Divides two expressions using polynomial quotient/remainder reconstruction when possible.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* This restores the parser-facing compatibility behavior historically exposed as
|
|
62
|
+
* `divide(a,b)`: a successful polynomial division is returned as
|
|
63
|
+
* `quotient + remainder/divisor`, so the result is a reusable symbolic expression. When
|
|
64
|
+
* more than one variable is present, Nerdamer treats the input as a multivariable polynomial
|
|
65
|
+
* rather than silently choosing a main variable. Inputs outside the polynomial domain fall
|
|
66
|
+
* back to ordinary symbolic division. Once both inputs are polynomial, failures from the
|
|
67
|
+
* division engine are allowed to propagate.
|
|
68
|
+
*/
|
|
69
|
+
export declare function divide(dividend: ExpressionInput, divisor: ExpressionInput): Expression;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deg = deg;
|
|
4
|
+
exports.content = content;
|
|
5
|
+
exports.div = div;
|
|
6
|
+
exports.divide = divide;
|
|
7
|
+
const Expression_1 = require("../expression/Expression");
|
|
8
|
+
const shortcuts_1 = require("../expression/shortcuts");
|
|
9
|
+
const utils_1 = require("../expression/utils");
|
|
10
|
+
const constants_1 = require("../parser/constants");
|
|
11
|
+
const Vector_1 = require("../vector/Vector");
|
|
12
|
+
const Polynomial_1 = require("./Polynomial");
|
|
13
|
+
const utils_2 = require("./utils");
|
|
14
|
+
/**
|
|
15
|
+
* Returns the degree of a polynomial expression.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* With no variable, `deg(p)` returns the total degree: the largest sum of powers in any
|
|
19
|
+
* term. With a variable, `deg(p, x)` returns the largest power of `x`, treating the other
|
|
20
|
+
* variables as coefficients. If the input cannot be converted to a polynomial, the call
|
|
21
|
+
* remains symbolic instead of throwing.
|
|
22
|
+
*
|
|
23
|
+
* @param x - Expression-like input or polynomial to inspect.
|
|
24
|
+
* @param variable - Optional variable whose degree should be returned.
|
|
25
|
+
* @returns A numeric expression for polynomial input, otherwise an unevaluated `deg(...)` call.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* deg('x^2*y^3+x').text(); // "5"
|
|
30
|
+
* deg('x^2*y^3+x', 'x').text(); // "2"
|
|
31
|
+
* deg('x^2*y^3+x', 'y').text(); // "3"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function deg(x, variable) {
|
|
35
|
+
let variableExpression;
|
|
36
|
+
let variableName;
|
|
37
|
+
if (variable !== undefined) {
|
|
38
|
+
variableExpression = Expression_1.Expression.create(variable);
|
|
39
|
+
variableName = (0, utils_1.assertPlainVariableAndGetString)(variableExpression);
|
|
40
|
+
}
|
|
41
|
+
let retval = undefined;
|
|
42
|
+
try {
|
|
43
|
+
const polynomial = Polynomial_1.Polynomial.isPolynomial(x) ? x : new Polynomial_1.Polynomial(x);
|
|
44
|
+
retval = Expression_1.Expression.create(polynomial.deg(variableName));
|
|
45
|
+
}
|
|
46
|
+
catch { }
|
|
47
|
+
const input = Polynomial_1.Polynomial.isPolynomial(x) ? x.getExpression() : x;
|
|
48
|
+
const args = variableExpression === undefined ? [input] : [input, variableExpression];
|
|
49
|
+
return retval ?? Expression_1.Expression.toFunction(constants_1.DEG, args);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns the exact numeric content of polynomial expression input.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* Content means the greatest common divisor of the polynomial's numeric coefficients.
|
|
56
|
+
* For example, the content of `6*x^2+15*x*y-3*y` is `3`. This function does not choose
|
|
57
|
+
* a main variable or compute a polynomial-valued GCD of symbolic coefficient expressions.
|
|
58
|
+
* If expression conversion fails, the operation remains symbolic as `content(input)`.
|
|
59
|
+
*
|
|
60
|
+
* @param x - Expression-like input or polynomial to inspect.
|
|
61
|
+
* @returns A numeric expression for converted input, otherwise an unevaluated symbolic
|
|
62
|
+
* `content` call.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* content('6*x^2+15*x-3').text(); // "3"
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
function content(x) {
|
|
70
|
+
let retval = undefined;
|
|
71
|
+
try {
|
|
72
|
+
const polynomial = Polynomial_1.Polynomial.isPolynomial(x) ? x : new Polynomial_1.Polynomial(x);
|
|
73
|
+
retval = Expression_1.Expression.create(polynomial.content());
|
|
74
|
+
}
|
|
75
|
+
catch { }
|
|
76
|
+
return retval ?? Expression_1.Expression.toFunction(constants_1.CONTENT, [Polynomial_1.Polynomial.isPolynomial(x) ? x.getExpression() : x]);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns the quotient and remainder of polynomial division.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* This is the parser-facing compatibility behavior historically exposed as `div(a,b)`.
|
|
83
|
+
* It delegates to the existing polynomial division implementation. When more than one
|
|
84
|
+
* variable is present, Nerdamer treats the input as a multivariable polynomial rather than
|
|
85
|
+
* silently choosing one variable and treating the others as coefficients. If either input
|
|
86
|
+
* is not polynomial-like, the legacy fallback is preserved as `[0, dividend]`. Once both
|
|
87
|
+
* inputs are polynomial, failures from the division engine are allowed to propagate.
|
|
88
|
+
*/
|
|
89
|
+
function div(dividend, divisor) {
|
|
90
|
+
const numerator = Expression_1.Expression.create(dividend);
|
|
91
|
+
const denominator = Expression_1.Expression.create(divisor);
|
|
92
|
+
let retval;
|
|
93
|
+
if (numerator.isPolynomialLike() && denominator.isPolynomialLike()) {
|
|
94
|
+
const [quotient, remainder] = (0, utils_2.divide)(numerator, denominator);
|
|
95
|
+
retval = new Vector_1.Vector([quotient, remainder]);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
retval = new Vector_1.Vector([(0, shortcuts_1.zero)(), numerator]);
|
|
99
|
+
}
|
|
100
|
+
return retval;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Divides two expressions using polynomial quotient/remainder reconstruction when possible.
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* This restores the parser-facing compatibility behavior historically exposed as
|
|
107
|
+
* `divide(a,b)`: a successful polynomial division is returned as
|
|
108
|
+
* `quotient + remainder/divisor`, so the result is a reusable symbolic expression. When
|
|
109
|
+
* more than one variable is present, Nerdamer treats the input as a multivariable polynomial
|
|
110
|
+
* rather than silently choosing a main variable. Inputs outside the polynomial domain fall
|
|
111
|
+
* back to ordinary symbolic division. Once both inputs are polynomial, failures from the
|
|
112
|
+
* division engine are allowed to propagate.
|
|
113
|
+
*/
|
|
114
|
+
function divide(dividend, divisor) {
|
|
115
|
+
const numerator = Expression_1.Expression.create(dividend);
|
|
116
|
+
const denominator = Expression_1.Expression.create(divisor);
|
|
117
|
+
let retval;
|
|
118
|
+
if (numerator.isPolynomialLike() && denominator.isPolynomialLike()) {
|
|
119
|
+
const [quotient, remainder] = (0, utils_2.divide)(numerator, denominator);
|
|
120
|
+
retval = quotient.plus(remainder.div(denominator));
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
retval = numerator.div(denominator);
|
|
124
|
+
}
|
|
125
|
+
return retval;
|
|
126
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Polynomial } from './Polynomial';
|
|
2
|
+
import type { Expression } from '../expression/Expression';
|
|
3
|
+
import type { Ordering, PolyType } from './Polynomial';
|
|
4
|
+
/**
|
|
5
|
+
* Divides a polynomial by given list of divisors
|
|
6
|
+
* See - Ideals Varieties and Algorithms 4th ed. p.81
|
|
7
|
+
*
|
|
8
|
+
* @param Fs The array of divisors
|
|
9
|
+
* @param g The dividend
|
|
10
|
+
* @param ordering The ordering to be used (optional).
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function polyDiv(Fs: PolyType[], g: PolyType, ordering?: Ordering, variables?: string[]): [Expression[], Expression];
|
|
14
|
+
/**
|
|
15
|
+
* Divides one polynomial by another
|
|
16
|
+
*
|
|
17
|
+
* @param f The dividend
|
|
18
|
+
* @param g The divisor
|
|
19
|
+
* @param ordering The ordering to be used (optional).
|
|
20
|
+
* @returns [The quotient, The remainder]
|
|
21
|
+
*/
|
|
22
|
+
export declare function divide(f: PolyType, g: PolyType, ordering?: Ordering, variables?: string[]): Expression[];
|
|
23
|
+
/**
|
|
24
|
+
* Computes the S-Polynomial given two polynomials
|
|
25
|
+
*
|
|
26
|
+
* @param f
|
|
27
|
+
* @param g
|
|
28
|
+
* @param ordering
|
|
29
|
+
* @param variables
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare function S(f: PolyType, g: PolyType, ordering?: Ordering, variables?: string[]): Polynomial;
|
|
33
|
+
/**
|
|
34
|
+
* Combines all the variables of a set of polynomials
|
|
35
|
+
*
|
|
36
|
+
* @param F
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export declare function combinePolynomialVariables(F: Polynomial[]): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Calculates the polynomial modulus of two polynomials as f mod g
|
|
42
|
+
*
|
|
43
|
+
* @param f
|
|
44
|
+
* @param g
|
|
45
|
+
* @param ordering
|
|
46
|
+
* @param variables
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
export declare function polyMod(f: PolyType, g: PolyType, ordering?: Ordering, variables?: string[]): Polynomial;
|
|
50
|
+
export declare function maxCommonVariableOccurrence(f: PolyType, g: PolyType): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Convert number to polynomial form.
|
|
53
|
+
* e.g. polynomialFromNumber (89, 1) = [8, 9] = 8*x+9
|
|
54
|
+
* e.g. polynomialFromNumber (89, 2) = [1, -1, -1] = x^2-x-1
|
|
55
|
+
* Try (x+4)(x+5)
|
|
56
|
+
*
|
|
57
|
+
* @param n The number
|
|
58
|
+
* @param p The power of the lead monomial
|
|
59
|
+
* @param base The base to use for the polynomial. Default = 10
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export declare function polynomialFromNumber(n: number, p: number, base?: number, startingCoeff?: number, endingCoeff?: number): number[];
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.polyDiv = polyDiv;
|
|
4
|
+
exports.divide = divide;
|
|
5
|
+
exports.S = S;
|
|
6
|
+
exports.combinePolynomialVariables = combinePolynomialVariables;
|
|
7
|
+
exports.polyMod = polyMod;
|
|
8
|
+
exports.maxCommonVariableOccurrence = maxCommonVariableOccurrence;
|
|
9
|
+
exports.polynomialFromNumber = polynomialFromNumber;
|
|
10
|
+
const utils_1 = require("../../functions/utils");
|
|
11
|
+
const shortcuts_1 = require("../expression/shortcuts");
|
|
12
|
+
const Polynomial_1 = require("./Polynomial");
|
|
13
|
+
function normalizePolynomialInputs(inputs, ordering, variables) {
|
|
14
|
+
const provisional = inputs.map(input => Polynomial_1.Polynomial.toPolynomial(input, ordering, variables));
|
|
15
|
+
if (variables !== undefined) {
|
|
16
|
+
return {
|
|
17
|
+
polynomials: provisional,
|
|
18
|
+
variables,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const resolvedVariables = combinePolynomialVariables(provisional);
|
|
22
|
+
if (resolvedVariables.length === 0) {
|
|
23
|
+
return {
|
|
24
|
+
polynomials: provisional,
|
|
25
|
+
variables: undefined,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
polynomials: inputs.map(input => Polynomial_1.Polynomial.toPolynomial(input, ordering, resolvedVariables)),
|
|
30
|
+
variables: resolvedVariables,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Divides a polynomial by given list of divisors
|
|
35
|
+
* See - Ideals Varieties and Algorithms 4th ed. p.81
|
|
36
|
+
*
|
|
37
|
+
* @param Fs The array of divisors
|
|
38
|
+
* @param g The dividend
|
|
39
|
+
* @param ordering The ordering to be used (optional).
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
function polyDiv(Fs, g, ordering, variables) {
|
|
43
|
+
const { polynomials } = normalizePolynomialInputs([...Fs, g], ordering, variables);
|
|
44
|
+
const F = polynomials.slice(0, Fs.length);
|
|
45
|
+
let p = polynomials[Fs.length].order(ordering);
|
|
46
|
+
// The collection of q's to be returned
|
|
47
|
+
const qArray = Fs.map(() => {
|
|
48
|
+
return (0, shortcuts_1.zero)();
|
|
49
|
+
});
|
|
50
|
+
let r = (0, shortcuts_1.zero)();
|
|
51
|
+
let iter = 0;
|
|
52
|
+
const maxIter = Fs.length * 1000;
|
|
53
|
+
// Begin
|
|
54
|
+
while (!p.isZero()) {
|
|
55
|
+
if (iter++ > maxIter) {
|
|
56
|
+
throw new Error('Maximum iterations reached');
|
|
57
|
+
}
|
|
58
|
+
let divisionOccurred = false;
|
|
59
|
+
const s = F.length;
|
|
60
|
+
let i = 0; // Use zero since TS arrays are zero based
|
|
61
|
+
while (i < s && !divisionOccurred) {
|
|
62
|
+
const fi = F[i];
|
|
63
|
+
const fiLT = fi.LT();
|
|
64
|
+
const pLT = p.LT();
|
|
65
|
+
if (fiLT.divides(pLT)) {
|
|
66
|
+
const q = pLT.div(fiLT);
|
|
67
|
+
qArray[i] = qArray[i].plus(q.getExpression());
|
|
68
|
+
// Guarantees a reduction at each step
|
|
69
|
+
p = p.minus(fi.times(q)).order(ordering);
|
|
70
|
+
divisionOccurred = true;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const pLT = p.LT();
|
|
77
|
+
if (!divisionOccurred) {
|
|
78
|
+
r = r.plus(pLT.getExpression());
|
|
79
|
+
p = p.minus(pLT).order(ordering);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [qArray, r];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Divides one polynomial by another
|
|
86
|
+
*
|
|
87
|
+
* @param f The dividend
|
|
88
|
+
* @param g The divisor
|
|
89
|
+
* @param ordering The ordering to be used (optional).
|
|
90
|
+
* @returns [The quotient, The remainder]
|
|
91
|
+
*/
|
|
92
|
+
function divide(f, g, ordering, variables) {
|
|
93
|
+
const [quo, rem] = polyDiv([g], f, ordering, variables);
|
|
94
|
+
return [quo[0], rem];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Computes the S-Polynomial given two polynomials
|
|
98
|
+
*
|
|
99
|
+
* @param f
|
|
100
|
+
* @param g
|
|
101
|
+
* @param ordering
|
|
102
|
+
* @param variables
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
function S(f, g, ordering, variables) {
|
|
106
|
+
const { polynomials: [p, q], } = normalizePolynomialInputs([f, g], ordering, variables);
|
|
107
|
+
const pLT = p.LT();
|
|
108
|
+
const qLT = q.LT();
|
|
109
|
+
const xg = pLT.LCM(qLT);
|
|
110
|
+
return p.times(xg.div(pLT)).minus(q.times(xg.div(qLT)));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Combines all the variables of a set of polynomials
|
|
114
|
+
*
|
|
115
|
+
* @param F
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
function combinePolynomialVariables(F) {
|
|
119
|
+
let variables = [];
|
|
120
|
+
F.forEach(f => {
|
|
121
|
+
variables = (0, utils_1.arrayAddUnique)(variables, f.variables);
|
|
122
|
+
});
|
|
123
|
+
variables.sort();
|
|
124
|
+
return variables;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Calculates the polynomial modulus of two polynomials as f mod g
|
|
128
|
+
*
|
|
129
|
+
* @param f
|
|
130
|
+
* @param g
|
|
131
|
+
* @param ordering
|
|
132
|
+
* @param variables
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
function polyMod(f, g, ordering, variables) {
|
|
136
|
+
const { variables: resolvedVariables } = normalizePolynomialInputs([f, g], ordering, variables);
|
|
137
|
+
const [, rem] = divide(f, g, ordering, resolvedVariables);
|
|
138
|
+
return Polynomial_1.Polynomial.toPolynomial(rem, ordering, resolvedVariables).order(ordering);
|
|
139
|
+
}
|
|
140
|
+
function maxCommonVariableOccurrence(f, g) {
|
|
141
|
+
const a = Polynomial_1.Polynomial.toPolynomial(f).maxVariableFrequency();
|
|
142
|
+
const b = Polynomial_1.Polynomial.toPolynomial(g).maxVariableFrequency();
|
|
143
|
+
// At this point any variable will do as long as it occurs in both a and b
|
|
144
|
+
for (const x in a) {
|
|
145
|
+
if (x in b) {
|
|
146
|
+
return x;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Convert number to polynomial form.
|
|
152
|
+
* e.g. polynomialFromNumber (89, 1) = [8, 9] = 8*x+9
|
|
153
|
+
* e.g. polynomialFromNumber (89, 2) = [1, -1, -1] = x^2-x-1
|
|
154
|
+
* Try (x+4)(x+5)
|
|
155
|
+
*
|
|
156
|
+
* @param n The number
|
|
157
|
+
* @param p The power of the lead monomial
|
|
158
|
+
* @param base The base to use for the polynomial. Default = 10
|
|
159
|
+
* @returns
|
|
160
|
+
*/
|
|
161
|
+
function polynomialFromNumber(n, p, base = 10, startingCoeff, endingCoeff) {
|
|
162
|
+
const remainder = function (a, b) {
|
|
163
|
+
if (a === 0) {
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
return Math.abs(a) < Math.abs(b) ? -(b % a) : a % b;
|
|
167
|
+
};
|
|
168
|
+
const coeffs = [];
|
|
169
|
+
for (let i = p; i >= 0; i--) {
|
|
170
|
+
// Calculate the base
|
|
171
|
+
const m = base ** i;
|
|
172
|
+
// console.log(`m: ${m}, n: ${n}`)
|
|
173
|
+
// Get the mod. This will be negative if the
|
|
174
|
+
const rem = remainder(n, m);
|
|
175
|
+
const d = n - rem;
|
|
176
|
+
const coeff = d / m;
|
|
177
|
+
if (i === p && (coeff < 1 || startingCoeff !== undefined)) {
|
|
178
|
+
const c = startingCoeff || 1;
|
|
179
|
+
coeffs.push(c);
|
|
180
|
+
n -= c * m;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
// Avoid fractions as coefficients
|
|
184
|
+
if (Math.abs(d) < Math.abs(m)) {
|
|
185
|
+
coeffs.push(0);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// console.log(`d: ${d}, rem: ${rem}, n: ${n}, coeff: ${coeff}`)
|
|
189
|
+
// Push the coefficient
|
|
190
|
+
coeffs.push(coeff);
|
|
191
|
+
// Point to the remainder as the new number
|
|
192
|
+
n = rem;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Adjust if the ending coeff is provided. If it cannot be adjusted then the current
|
|
196
|
+
// constant will be used
|
|
197
|
+
if (endingCoeff !== undefined) {
|
|
198
|
+
const lastIndex = coeffs.length - 1;
|
|
199
|
+
const newCoeff = coeffs[lastIndex] - endingCoeff;
|
|
200
|
+
if (newCoeff % base === 0) {
|
|
201
|
+
coeffs[lastIndex] = endingCoeff;
|
|
202
|
+
coeffs[lastIndex - 1] += newCoeff / base;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return coeffs.reverse();
|
|
206
|
+
}
|