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,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasDerivedInverseTrig = hasDerivedInverseTrig;
|
|
4
|
+
exports.rewriteInverseTrig = rewriteInverseTrig;
|
|
5
|
+
const Expression_1 = require("../../core/classes/expression/Expression");
|
|
6
|
+
const shortcuts_1 = require("../../core/classes/expression/shortcuts");
|
|
7
|
+
const constants_1 = require("../../core/classes/parser/constants");
|
|
8
|
+
/**
|
|
9
|
+
* Determines whether an expression contains any asec, acsc, or acot functions.
|
|
10
|
+
*/
|
|
11
|
+
function hasDerivedInverseTrig(x) {
|
|
12
|
+
let found = false;
|
|
13
|
+
x.forEveryElement(e => {
|
|
14
|
+
if (e.isFunction(constants_1.ASEC) || e.isFunction(constants_1.ACSC) || e.isFunction(constants_1.ACOT)) {
|
|
15
|
+
found = true;
|
|
16
|
+
}
|
|
17
|
+
return e;
|
|
18
|
+
});
|
|
19
|
+
return found;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Rewrites a single inverse trig element to its primary form.
|
|
23
|
+
*
|
|
24
|
+
* asec(u)^n → acos(1/u)^n
|
|
25
|
+
* acsc(u)^n → asin(1/u)^n
|
|
26
|
+
* acot(u)^n → atan(1/u)^n
|
|
27
|
+
*
|
|
28
|
+
* Multiplier and power are preserved.
|
|
29
|
+
*/
|
|
30
|
+
function rewriteInverseTrigElement(e) {
|
|
31
|
+
const m = e.getMultiplier();
|
|
32
|
+
const p = e.getPower();
|
|
33
|
+
const args = e.getArguments();
|
|
34
|
+
if (e.isFunction(constants_1.ASEC) && args.length > 0) {
|
|
35
|
+
const u = args[0];
|
|
36
|
+
// asec(u) = acos(1/u)
|
|
37
|
+
const rewritten = Expression_1.Expression.create(`acos(x)`, { x: (0, shortcuts_1.one)().div(u) });
|
|
38
|
+
return Expression_1.Expression.fromRational(m).times(rewritten.pow(p));
|
|
39
|
+
}
|
|
40
|
+
if (e.isFunction(constants_1.ACSC) && args.length > 0) {
|
|
41
|
+
const u = args[0];
|
|
42
|
+
// acsc(u) = asin(1/u)
|
|
43
|
+
const rewritten = Expression_1.Expression.create(`asin(x)`, { x: (0, shortcuts_1.one)().div(u) });
|
|
44
|
+
return Expression_1.Expression.fromRational(m).times(rewritten.pow(p));
|
|
45
|
+
}
|
|
46
|
+
if (e.isFunction(constants_1.ACOT) && args.length > 0) {
|
|
47
|
+
const u = args[0];
|
|
48
|
+
// acot(u) = atan(1/u)
|
|
49
|
+
const rewritten = Expression_1.Expression.create(`atan(x)`, { x: (0, shortcuts_1.one)().div(u) });
|
|
50
|
+
return Expression_1.Expression.fromRational(m).times(rewritten.pow(p));
|
|
51
|
+
}
|
|
52
|
+
return e;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Recursively rewrites all asec, acsc, acot in an expression tree to acos, asin, atan.
|
|
56
|
+
* Descends into sums, products, and function arguments.
|
|
57
|
+
*/
|
|
58
|
+
function rewriteInverseTrig(x) {
|
|
59
|
+
// Direct derived inverse trig function
|
|
60
|
+
if (x.isFunction(constants_1.ASEC) || x.isFunction(constants_1.ACSC) || x.isFunction(constants_1.ACOT)) {
|
|
61
|
+
return rewriteInverseTrigElement(x);
|
|
62
|
+
}
|
|
63
|
+
// For sums: rewrite each term
|
|
64
|
+
if (x.isSum()) {
|
|
65
|
+
const m = x.getMultiplier();
|
|
66
|
+
const p = x.getPower();
|
|
67
|
+
let result = (0, shortcuts_1.zero)();
|
|
68
|
+
for (const term of x.elementsArray()) {
|
|
69
|
+
result = result.plus(rewriteInverseTrig(term));
|
|
70
|
+
}
|
|
71
|
+
if (!p.isOne()) {
|
|
72
|
+
result = result.pow(p);
|
|
73
|
+
}
|
|
74
|
+
if (!m.isOne()) {
|
|
75
|
+
result = result.times(Expression_1.Expression.fromRational(m));
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
// For products: rewrite each factor
|
|
80
|
+
if (x.isProduct()) {
|
|
81
|
+
const m = x.getMultiplier();
|
|
82
|
+
const p = x.getPower();
|
|
83
|
+
let result = (0, shortcuts_1.one)();
|
|
84
|
+
for (const element of x.elementsArray()) {
|
|
85
|
+
result = result.times(rewriteInverseTrig(element));
|
|
86
|
+
}
|
|
87
|
+
if (!p.isOne()) {
|
|
88
|
+
result = result.pow(p);
|
|
89
|
+
}
|
|
90
|
+
if (!m.isOne()) {
|
|
91
|
+
result = result.times(Expression_1.Expression.fromRational(m));
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
return x;
|
|
96
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Expression } from '../../core/classes/expression/Expression';
|
|
2
|
+
import { toCommonDenominator } from '../../core/functions/rationalNormalization';
|
|
3
|
+
export { toCommonDenominator };
|
|
4
|
+
/**
|
|
5
|
+
* Simplifies the expression through rationalizing
|
|
6
|
+
* @param x
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function rationalize(x: Expression): Expression;
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to simplify radicals in the expression. Convert 2/√2 to √2.
|
|
12
|
+
* @param x
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function simplifyRadicals(x: Expression): Expression;
|
|
16
|
+
/**
|
|
17
|
+
* Eliminates common factors from the numerator and denominators give that they're two polynomials
|
|
18
|
+
* @param x
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function cancelCommonFactors(x: Expression): Expression;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCommonDenominator = void 0;
|
|
4
|
+
exports.rationalize = rationalize;
|
|
5
|
+
exports.simplifyRadicals = simplifyRadicals;
|
|
6
|
+
exports.cancelCommonFactors = cancelCommonFactors;
|
|
7
|
+
const Expression_1 = require("../../core/classes/expression/Expression");
|
|
8
|
+
const shortcuts_1 = require("../../core/classes/expression/shortcuts");
|
|
9
|
+
const Polynomial_1 = require("../../core/classes/polynomial/Polynomial");
|
|
10
|
+
const utils_1 = require("../../core/classes/polynomial/utils");
|
|
11
|
+
const rationalNormalization_1 = require("../../core/functions/rationalNormalization");
|
|
12
|
+
Object.defineProperty(exports, "toCommonDenominator", { enumerable: true, get: function () { return rationalNormalization_1.toCommonDenominator; } });
|
|
13
|
+
const subst_1 = require("../../core/functions/subst");
|
|
14
|
+
const factor_1 = require("../factor/factor");
|
|
15
|
+
/**
|
|
16
|
+
* Simplifies the expression through rationalizing
|
|
17
|
+
* @param x
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
function rationalize(x) {
|
|
21
|
+
const num = x.getNumerator();
|
|
22
|
+
const den = x.getDenominator();
|
|
23
|
+
// Nothing to do if the denominator is one
|
|
24
|
+
// Nothing to do if the power in the denominator is 1
|
|
25
|
+
if (den.isOne() || (!den.isProduct() && den.isLinear())) {
|
|
26
|
+
return x;
|
|
27
|
+
}
|
|
28
|
+
const q = den.getPower();
|
|
29
|
+
const f = den.toLinearAndUnitMultiplier();
|
|
30
|
+
const retval = num.div(f.times(den.getMultiplier())).times(f.pow((0, shortcuts_1.one)().minus(q)));
|
|
31
|
+
return retval;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Attempts to simplify radicals in the expression. Convert 2/√2 to √2.
|
|
35
|
+
* @param x
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
function simplifyRadicals(x) {
|
|
39
|
+
// This function only works if it's a product
|
|
40
|
+
if (!x.isProduct()) {
|
|
41
|
+
return x;
|
|
42
|
+
}
|
|
43
|
+
const m = x.getMultiplier();
|
|
44
|
+
const p = x.getPower();
|
|
45
|
+
let retval = (0, shortcuts_1.one)();
|
|
46
|
+
const linearized = x.toLinearAndUnitMultiplier();
|
|
47
|
+
const linearMultiplier = linearized.getMultiplier();
|
|
48
|
+
const elements = linearized.elementsArray().map(e => {
|
|
49
|
+
// Only rationalize if it actually has a radical (fractional power)
|
|
50
|
+
if (e.hasRadical()) {
|
|
51
|
+
return rationalize(e);
|
|
52
|
+
}
|
|
53
|
+
return e;
|
|
54
|
+
});
|
|
55
|
+
// The array of indices that have already been used
|
|
56
|
+
const seen = [];
|
|
57
|
+
for (let i = 0; i < elements.length; i++) {
|
|
58
|
+
// Nothing to do if it's already been multiplied out
|
|
59
|
+
if (seen.includes(i)) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
let a = elements[i];
|
|
63
|
+
const p = a.getPower();
|
|
64
|
+
for (let j = i + 1; j < elements.length; j++) {
|
|
65
|
+
const b = elements[j];
|
|
66
|
+
if (p.eq(b.getPower())) {
|
|
67
|
+
// Powers are stored directly on several expression node types. Extracting
|
|
68
|
+
// the base through the common Expression API avoids assuming an EXP node
|
|
69
|
+
// or a function wrapper for symbolic radicals.
|
|
70
|
+
const u = a.toLinearAndUnitMultiplier();
|
|
71
|
+
const v = b.toLinearAndUnitMultiplier();
|
|
72
|
+
// Principal radicals can be combined when both radicands are known nonnegative.
|
|
73
|
+
// Reciprocals still require a strictly signed base because a zero denominator
|
|
74
|
+
// cannot be admitted by the sign proof for a negative power.
|
|
75
|
+
if (!u.isComplex() && !v.isComplex() && u.gte(0) && v.gte(0)) {
|
|
76
|
+
const multiplier = a.getMultiplier().times(b.getMultiplier());
|
|
77
|
+
if (u.isNUM() && v.isNUM()) {
|
|
78
|
+
// Preserve exact numeric reduction when the combined radicand is numeric.
|
|
79
|
+
a = u.times(v).pow(p).times(multiplier);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Set the outer power directly so the normal power operation does not
|
|
83
|
+
// distribute it back across the known-positive product.
|
|
84
|
+
a = Expression_1.Expression.setPower(u.times(v), p).times(multiplier);
|
|
85
|
+
}
|
|
86
|
+
seen.push(j);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
retval = retval.times(a);
|
|
91
|
+
}
|
|
92
|
+
return retval.pow(p).times(m).times(linearMultiplier);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Eliminates common factors from the numerator and denominators give that they're two polynomials
|
|
96
|
+
* @param x
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
function cancelCommonFactors(x) {
|
|
100
|
+
if (!x.isProduct() || !x.isLinear()) {
|
|
101
|
+
return x;
|
|
102
|
+
}
|
|
103
|
+
let retval = x;
|
|
104
|
+
const [radFree, radicalSubs] = (0, subst_1.subRadicals)(x);
|
|
105
|
+
// Mathematical constants need the same temporary variable treatment as radicals
|
|
106
|
+
// before entering the exact polynomial layer. Restore both substitution sets below.
|
|
107
|
+
const [polynomialReady, subs] = (0, subst_1.uSubConstants)(radFree, radicalSubs);
|
|
108
|
+
let num = polynomialReady.getNumerator();
|
|
109
|
+
let den = polynomialReady.getDenominator();
|
|
110
|
+
function reduce(a, b) {
|
|
111
|
+
const f = new Polynomial_1.Polynomial(a);
|
|
112
|
+
// Factor both
|
|
113
|
+
for (const e of (0, factor_1.polyFactorExpressions)(b)) {
|
|
114
|
+
// Don't risk entering Q by dividing by a constant
|
|
115
|
+
if (e.isNUM()) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const g = new Polynomial_1.Polynomial(e);
|
|
119
|
+
const [q, r] = (0, utils_1.divide)(f, g);
|
|
120
|
+
if (r.isZero()) {
|
|
121
|
+
// Update the numerator with the new values
|
|
122
|
+
a = q;
|
|
123
|
+
// Update the denominator
|
|
124
|
+
const [q2, _r2] = (0, utils_1.divide)(b, g);
|
|
125
|
+
b = q2;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return [a, b];
|
|
129
|
+
}
|
|
130
|
+
if (num.isPolynomialLike() && den.isPolynomialLike()) {
|
|
131
|
+
// Reduce the numerator by the denominator
|
|
132
|
+
[num, den] = reduce(num, den);
|
|
133
|
+
// Reduce the denominator by the numerator
|
|
134
|
+
[den, num] = reduce(den, num);
|
|
135
|
+
// Return the quotient
|
|
136
|
+
retval = num.div(den);
|
|
137
|
+
}
|
|
138
|
+
// First try to reduce the denominator
|
|
139
|
+
return (0, subst_1.uUnSub)(retval, subs);
|
|
140
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Expression } from '../../core/classes/expression/Expression';
|
|
2
|
+
/**
|
|
3
|
+
* Applies Nerdamer's finite symbolic simplification strategy to an expression.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Simplification first normalizes rational structure, recursively simplifies function
|
|
7
|
+
* arguments, and then selects targeted transformations for factorial ratios, complex
|
|
8
|
+
* forms, irrational denominators, sums, or linear products. The final numerator and
|
|
9
|
+
* denominator are factored. This is a heuristic transformation pipeline rather than a
|
|
10
|
+
* proof of globally minimal form, and branch-sensitive identities are limited to the
|
|
11
|
+
* safeguards implemented by the selected rewrite routines.
|
|
12
|
+
*
|
|
13
|
+
* Intermediate expressions may be reused while the pipeline runs, but callers should
|
|
14
|
+
* treat the return value as the simplified result rather than expecting `x` to be updated
|
|
15
|
+
* in place. Decimal-origin formatting is propagated to the result's outer multiplier.
|
|
16
|
+
* The `modifiers` object is internal recursion state; its `image` value prevents another
|
|
17
|
+
* simplification round when the canonical text has stopped changing.
|
|
18
|
+
*
|
|
19
|
+
* @param x - Expression or parser text to simplify.
|
|
20
|
+
* @param modifiers - Internal recursion markers used to detect an unchanged image.
|
|
21
|
+
* @returns The simplified expression, which may retain forms unsupported by the finite strategy set.
|
|
22
|
+
*/
|
|
23
|
+
export declare function simplify(x: Expression | string, modifiers?: {
|
|
24
|
+
[name: string]: string;
|
|
25
|
+
}): Expression;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simplify = simplify;
|
|
4
|
+
const Expression_1 = require("../../core/classes/expression/Expression");
|
|
5
|
+
const shortcuts_1 = require("../../core/classes/expression/shortcuts");
|
|
6
|
+
const utils_1 = require("../../math/utils");
|
|
7
|
+
const factor_1 = require("../factor/factor");
|
|
8
|
+
const complexsimp_1 = require("./complexsimp");
|
|
9
|
+
const factorCommon_1 = require("./factorCommon");
|
|
10
|
+
const funcsimp_1 = require("./funcsimp");
|
|
11
|
+
const invtrigrewrite_1 = require("./invtrigrewrite");
|
|
12
|
+
const ratsimp_1 = require("./ratsimp");
|
|
13
|
+
const trigrewrite_1 = require("./trigrewrite");
|
|
14
|
+
const trigsimp_1 = require("./trigsimp");
|
|
15
|
+
const utils_2 = require("./utils");
|
|
16
|
+
/**
|
|
17
|
+
* Applies Nerdamer's finite symbolic simplification strategy to an expression.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Simplification first normalizes rational structure, recursively simplifies function
|
|
21
|
+
* arguments, and then selects targeted transformations for factorial ratios, complex
|
|
22
|
+
* forms, irrational denominators, sums, or linear products. The final numerator and
|
|
23
|
+
* denominator are factored. This is a heuristic transformation pipeline rather than a
|
|
24
|
+
* proof of globally minimal form, and branch-sensitive identities are limited to the
|
|
25
|
+
* safeguards implemented by the selected rewrite routines.
|
|
26
|
+
*
|
|
27
|
+
* Intermediate expressions may be reused while the pipeline runs, but callers should
|
|
28
|
+
* treat the return value as the simplified result rather than expecting `x` to be updated
|
|
29
|
+
* in place. Decimal-origin formatting is propagated to the result's outer multiplier.
|
|
30
|
+
* The `modifiers` object is internal recursion state; its `image` value prevents another
|
|
31
|
+
* simplification round when the canonical text has stopped changing.
|
|
32
|
+
*
|
|
33
|
+
* @param x - Expression or parser text to simplify.
|
|
34
|
+
* @param modifiers - Internal recursion markers used to detect an unchanged image.
|
|
35
|
+
* @returns The simplified expression, which may retain forms unsupported by the finite strategy set.
|
|
36
|
+
*/
|
|
37
|
+
function simplify(x, modifiers = {}) {
|
|
38
|
+
if (typeof x === 'string') {
|
|
39
|
+
x = Expression_1.Expression.create(x);
|
|
40
|
+
}
|
|
41
|
+
const asDecimal = x.hasDecimal();
|
|
42
|
+
if ((0, invtrigrewrite_1.hasDerivedInverseTrig)(x)) {
|
|
43
|
+
x = (0, invtrigrewrite_1.rewriteInverseTrig)(x);
|
|
44
|
+
}
|
|
45
|
+
x = (0, ratsimp_1.toCommonDenominator)(x);
|
|
46
|
+
x = x.getNumerator().expand().div(x.getDenominator().expand());
|
|
47
|
+
// No changes from last round — nothing left to do
|
|
48
|
+
let retval = x;
|
|
49
|
+
const unchanged = modifiers.image === x.text();
|
|
50
|
+
if (!unchanged) {
|
|
51
|
+
retval = simplifyArguments(retval);
|
|
52
|
+
// Early factorial simplification for bare factorial ratios
|
|
53
|
+
if (retval.isProduct() && (0, utils_2.hasFactorialRatio)(retval)) {
|
|
54
|
+
retval = (0, funcsimp_1.simplifyFactorials)(retval);
|
|
55
|
+
}
|
|
56
|
+
// Only enter the main simplification if factorials didn't fully resolve,
|
|
57
|
+
// or the expression wasn't a factorial ratio to begin with
|
|
58
|
+
if ((0, utils_2.hasFactorialRatio)(retval) || !x.isProduct() || !(0, utils_2.hasFactorialRatio)(x)) {
|
|
59
|
+
if (x.isComplex()) {
|
|
60
|
+
retval = (0, complexsimp_1.complexSimplify)(retval);
|
|
61
|
+
}
|
|
62
|
+
else if ((0, utils_2.hasIrrationalDenominator)(retval)) {
|
|
63
|
+
retval = (0, ratsimp_1.rationalize)(retval);
|
|
64
|
+
}
|
|
65
|
+
else if (retval.isSum()) {
|
|
66
|
+
retval = (0, trigrewrite_1.tryRewriteTrig)(retval);
|
|
67
|
+
retval = (0, trigsimp_1.simplifyTrigSum)(retval);
|
|
68
|
+
retval = (0, factorCommon_1.factorCommonPower)(retval);
|
|
69
|
+
retval = (0, funcsimp_1.simplifyLogs)(retval);
|
|
70
|
+
}
|
|
71
|
+
else if (retval.isProduct() && retval.isLinear()) {
|
|
72
|
+
retval = (0, funcsimp_1.simplifyFactorials)(retval);
|
|
73
|
+
retval = (0, ratsimp_1.simplifyRadicals)(retval);
|
|
74
|
+
retval = cancelNestedFactors(retval);
|
|
75
|
+
retval = (0, ratsimp_1.cancelCommonFactors)(retval);
|
|
76
|
+
retval = (0, trigrewrite_1.tryRewriteTrig)(retval);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
retval = factorResult(retval);
|
|
81
|
+
if (asDecimal) {
|
|
82
|
+
retval.getMultiplier().asDecimal = true;
|
|
83
|
+
}
|
|
84
|
+
return retval;
|
|
85
|
+
}
|
|
86
|
+
function simplifyArguments(x) {
|
|
87
|
+
let retval = undefined;
|
|
88
|
+
const m = x.getMultiplier();
|
|
89
|
+
const p = x.getPower();
|
|
90
|
+
if (x.isFunction()) {
|
|
91
|
+
retval = Expression_1.Expression.toFunction(x.name, x.getArguments().map(e => simplify(e)));
|
|
92
|
+
}
|
|
93
|
+
else if (x.isProduct()) {
|
|
94
|
+
retval = (0, shortcuts_1.one)();
|
|
95
|
+
for (const element of x.elementsArray()) {
|
|
96
|
+
const simplified = simplifyArguments(element);
|
|
97
|
+
retval = retval.times(simplified);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (x.isSum()) {
|
|
101
|
+
retval = (0, shortcuts_1.zero)();
|
|
102
|
+
for (const element of x.elementsArray()) {
|
|
103
|
+
retval = retval.plus(simplifyArguments(element));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (retval) {
|
|
107
|
+
retval = retval.pow(p).times(m);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
retval = x;
|
|
111
|
+
}
|
|
112
|
+
return retval;
|
|
113
|
+
}
|
|
114
|
+
/** Shared exit: factor numerator and denominator, or return as-is for pure numbers. */
|
|
115
|
+
function factorResult(x) {
|
|
116
|
+
if (x.isNUM()) {
|
|
117
|
+
return x;
|
|
118
|
+
}
|
|
119
|
+
const num = (0, utils_1.product)(...(0, factor_1.polyFactorExpressions)(x.getNumerator()));
|
|
120
|
+
const den = (0, utils_1.product)(...(0, factor_1.polyFactorExpressions)(x.getDenominator()));
|
|
121
|
+
return num.div(den);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Cancels common factors between top-level elements and elements nested inside
|
|
125
|
+
* inverted products. Handles cases like fact(n) * (fact(n)*(1+n))^-1 → (1+n)^-1
|
|
126
|
+
* where the denominator is a product raised to -1 and contains a factor that
|
|
127
|
+
* matches a numerator element.
|
|
128
|
+
*/
|
|
129
|
+
function cancelNestedFactors(x) {
|
|
130
|
+
if (!x.isProduct()) {
|
|
131
|
+
return x;
|
|
132
|
+
}
|
|
133
|
+
const numFactors = [];
|
|
134
|
+
const denCompounds = [];
|
|
135
|
+
const otherDen = [];
|
|
136
|
+
let idx = 0;
|
|
137
|
+
for (const element of x.elementsArray()) {
|
|
138
|
+
const p = element.getPower();
|
|
139
|
+
if (p.sign() === -1 && p.isMinusOne?.()) {
|
|
140
|
+
// This is something^-1. Check if the base is a product.
|
|
141
|
+
const base = element.invert();
|
|
142
|
+
if (base.isProduct()) {
|
|
143
|
+
denCompounds.push({ base, index: idx });
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
otherDen.push(element);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else if (p.sign() === 1) {
|
|
150
|
+
numFactors.push(element);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
otherDen.push(element);
|
|
154
|
+
}
|
|
155
|
+
idx++;
|
|
156
|
+
}
|
|
157
|
+
// Nothing to do if there are no compound denominators
|
|
158
|
+
if (denCompounds.length === 0 || numFactors.length === 0) {
|
|
159
|
+
return x;
|
|
160
|
+
}
|
|
161
|
+
let changed = false;
|
|
162
|
+
const usedNum = new Set();
|
|
163
|
+
for (const compound of denCompounds) {
|
|
164
|
+
const denElements = compound.base.elementsArray();
|
|
165
|
+
const denMultiplier = compound.base.getMultiplier();
|
|
166
|
+
const survivingDen = [];
|
|
167
|
+
let compoundChanged = false;
|
|
168
|
+
for (const de of denElements) {
|
|
169
|
+
let cancelled = false;
|
|
170
|
+
for (let i = 0; i < numFactors.length; i++) {
|
|
171
|
+
if (usedNum.has(i)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
// Compare ignoring multipliers
|
|
175
|
+
const numUnit = numFactors[i].toUnitMultiplier();
|
|
176
|
+
const denUnit = de.toUnitMultiplier();
|
|
177
|
+
if (numUnit.eq(denUnit)) {
|
|
178
|
+
// Cancel, keeping ratio of multipliers
|
|
179
|
+
const mRatio = numFactors[i].getMultiplier().div(de.getMultiplier());
|
|
180
|
+
if (!mRatio.isOne()) {
|
|
181
|
+
// Replace the numerator factor with the multiplier ratio
|
|
182
|
+
numFactors[i] = Expression_1.Expression.fromRational(mRatio);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
usedNum.add(i);
|
|
186
|
+
}
|
|
187
|
+
cancelled = true;
|
|
188
|
+
compoundChanged = true;
|
|
189
|
+
changed = true;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (!cancelled) {
|
|
194
|
+
survivingDen.push(de);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (compoundChanged) {
|
|
198
|
+
// Rebuild the denominator from surviving elements
|
|
199
|
+
if (survivingDen.length === 0) {
|
|
200
|
+
// Entire denominator cancelled — just the multiplier remains
|
|
201
|
+
otherDen.push(Expression_1.Expression.fromRational(denMultiplier).invert());
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
let newDen = Expression_1.Expression.fromRational(denMultiplier);
|
|
205
|
+
for (const s of survivingDen) {
|
|
206
|
+
newDen = newDen.times(s);
|
|
207
|
+
}
|
|
208
|
+
otherDen.push(newDen.invert());
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
otherDen.push(compound.base.invert());
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (!changed) {
|
|
216
|
+
return x;
|
|
217
|
+
}
|
|
218
|
+
let result = Expression_1.Expression.fromRational(x.getMultiplier());
|
|
219
|
+
for (let i = 0; i < numFactors.length; i++) {
|
|
220
|
+
if (!usedNum.has(i)) {
|
|
221
|
+
result = result.times(numFactors[i]);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (const d of otherDen) {
|
|
225
|
+
result = result.times(d);
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Expression } from '../../core/classes/expression/Expression';
|
|
2
|
+
/**
|
|
3
|
+
* Applies power reduction to a single trig function with an integer power ≥ 2.
|
|
4
|
+
*
|
|
5
|
+
* sin(u)^(2k) → expanded using repeated application of half-angle
|
|
6
|
+
* cos(u)^(2k) → expanded using repeated application of half-angle
|
|
7
|
+
* sin(u)^(2k+1) → sin(u) · [sin(u)^(2k) reduced]
|
|
8
|
+
* cos(u)^(2k+1) → cos(u) · [cos(u)^(2k) reduced]
|
|
9
|
+
*
|
|
10
|
+
* Only applies when the power is an integer ≥ 2 (or ≤ -2).
|
|
11
|
+
* Fractional powers like sin(x)^(1/2) are left unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function reduceTrigPower(e: Expression): Expression;
|
|
14
|
+
/**
|
|
15
|
+
* Applies power reduction to all trig powers in an expression.
|
|
16
|
+
* Descends into sums and products.
|
|
17
|
+
*/
|
|
18
|
+
export declare function trigReduce(x: Expression): Expression;
|
|
19
|
+
/**
|
|
20
|
+
* Expands all double-angle trig functions in an expression.
|
|
21
|
+
*/
|
|
22
|
+
export declare function expandDoubleAngle(x: Expression): Expression;
|
|
23
|
+
/**
|
|
24
|
+
* Converts a product of two trig functions to a sum using product-to-sum identities.
|
|
25
|
+
*
|
|
26
|
+
* sin(a)·cos(b) → (1/2)[sin(a+b) + sin(a-b)]
|
|
27
|
+
* cos(a)·cos(b) → (1/2)[cos(a-b) + cos(a+b)]
|
|
28
|
+
* sin(a)·sin(b) → (1/2)[cos(a-b) - cos(a+b)]
|
|
29
|
+
*/
|
|
30
|
+
export declare function productToSum(x: Expression): Expression;
|
|
31
|
+
/**
|
|
32
|
+
* Converts sin(u)·cos(u) products into double-angle form.
|
|
33
|
+
*
|
|
34
|
+
* k·sin(u)·cos(u) → (k/2)·sin(2u)
|
|
35
|
+
*
|
|
36
|
+
* This is the reverse of expandDoubleAngle for sin.
|
|
37
|
+
*/
|
|
38
|
+
export declare function convertToDoubleAngle(x: Expression): Expression;
|