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,369 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simplifyTrigSum = simplifyTrigSum;
|
|
4
|
+
const Expression_1 = require("../../core/classes/expression/Expression");
|
|
5
|
+
const shortcuts_1 = require("../../core/classes/expression/shortcuts");
|
|
6
|
+
const constants_1 = require("../../core/classes/parser/constants");
|
|
7
|
+
const trig_1 = require("../../math/trig");
|
|
8
|
+
/**
|
|
9
|
+
* Extracts trig information from a sum term.
|
|
10
|
+
* Returns null if the term doesn't contain a sin^2 or cos^2.
|
|
11
|
+
*/
|
|
12
|
+
function extractTrigSquared(term) {
|
|
13
|
+
// Case 1: Direct trig function, e.g. sin(x)^2 or 3*cos(x)^2
|
|
14
|
+
if ((term.isFunction(constants_1.SIN) || term.isFunction(constants_1.COS)) && term.getPower().eq((0, shortcuts_1.two)())) {
|
|
15
|
+
return {
|
|
16
|
+
coeff: Expression_1.Expression.fromRational(term.getMultiplier()),
|
|
17
|
+
trigFn: term.isFunction(constants_1.SIN) ? constants_1.SIN : constants_1.COS,
|
|
18
|
+
arg: term.getArguments()[0],
|
|
19
|
+
trigPower: term.getPower(),
|
|
20
|
+
original: term,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Case 2: Product containing a trig function, e.g. x*cos(x)^2
|
|
24
|
+
if (term.isProduct()) {
|
|
25
|
+
let trigElement = null;
|
|
26
|
+
let trigFn = null;
|
|
27
|
+
let trigMultiplier = (0, shortcuts_1.one)();
|
|
28
|
+
const coeffParts = [];
|
|
29
|
+
for (const element of term.elementsArray()) {
|
|
30
|
+
if (!trigElement &&
|
|
31
|
+
(element.isFunction(constants_1.SIN) || element.isFunction(constants_1.COS)) &&
|
|
32
|
+
element.getPower().eq((0, shortcuts_1.two)())) {
|
|
33
|
+
trigElement = element;
|
|
34
|
+
trigFn = element.isFunction(constants_1.SIN) ? constants_1.SIN : constants_1.COS;
|
|
35
|
+
trigMultiplier = Expression_1.Expression.fromRational(element.getMultiplier());
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
coeffParts.push(element);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (trigElement && trigFn) {
|
|
42
|
+
let coeff = Expression_1.Expression.fromRational(term.getMultiplier());
|
|
43
|
+
for (const part of coeffParts) {
|
|
44
|
+
coeff = coeff.times(part);
|
|
45
|
+
}
|
|
46
|
+
coeff = coeff.times(trigMultiplier);
|
|
47
|
+
return {
|
|
48
|
+
coeff,
|
|
49
|
+
trigFn,
|
|
50
|
+
arg: (trigElement).getArguments()[0],
|
|
51
|
+
trigPower: (trigElement).getPower(),
|
|
52
|
+
original: term,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Extracts tan^2, sec^2, csc^2, or cot^2 terms from a sum element.
|
|
60
|
+
*/
|
|
61
|
+
function extractDerivedTrigSquared(term) {
|
|
62
|
+
const fns = [constants_1.TAN, constants_1.SEC, constants_1.CSC, constants_1.COT];
|
|
63
|
+
// Case 1: Direct function, e.g. sec(x)^2
|
|
64
|
+
for (const fn of fns) {
|
|
65
|
+
if (term.isFunction(fn) && term.getPower().eq((0, shortcuts_1.two)())) {
|
|
66
|
+
return {
|
|
67
|
+
coeff: Expression_1.Expression.fromRational(term.getMultiplier()),
|
|
68
|
+
trigFn: fn,
|
|
69
|
+
arg: term.getArguments()[0],
|
|
70
|
+
trigPower: term.getPower(),
|
|
71
|
+
original: term,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Case 2: Product containing a derived trig function
|
|
76
|
+
if (term.isProduct()) {
|
|
77
|
+
let trigElement = null;
|
|
78
|
+
let trigFn = null;
|
|
79
|
+
let trigMultiplier = (0, shortcuts_1.one)();
|
|
80
|
+
const coeffParts = [];
|
|
81
|
+
for (const element of term.elementsArray()) {
|
|
82
|
+
if (!trigElement) {
|
|
83
|
+
for (const fn of fns) {
|
|
84
|
+
if (element.isFunction(fn) && element.getPower().eq((0, shortcuts_1.two)())) {
|
|
85
|
+
trigElement = element;
|
|
86
|
+
trigFn = fn;
|
|
87
|
+
trigMultiplier = Expression_1.Expression.fromRational(element.getMultiplier());
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!trigElement) {
|
|
92
|
+
coeffParts.push(element);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
coeffParts.push(element);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (trigElement && trigFn) {
|
|
100
|
+
let coeff = Expression_1.Expression.fromRational(term.getMultiplier());
|
|
101
|
+
for (const part of coeffParts) {
|
|
102
|
+
coeff = coeff.times(part);
|
|
103
|
+
}
|
|
104
|
+
coeff = coeff.times(trigMultiplier);
|
|
105
|
+
return {
|
|
106
|
+
coeff,
|
|
107
|
+
trigFn,
|
|
108
|
+
arg: trigElement.getArguments()[0],
|
|
109
|
+
trigPower: trigElement.getPower(),
|
|
110
|
+
original: term,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Simplifies trig identities in a sum expression.
|
|
118
|
+
*
|
|
119
|
+
* Applies:
|
|
120
|
+
* a·sin(u)² + a·cos(u)² = a (Pythagorean)
|
|
121
|
+
* a·sec(u)² - a·tan(u)² = a (sec²-tan²=1)
|
|
122
|
+
* a·csc(u)² - a·cot(u)² = a (csc²-cot²=1)
|
|
123
|
+
* Partial Pythagorean for mismatched coefficients
|
|
124
|
+
*/
|
|
125
|
+
function simplifyTrigSum(x) {
|
|
126
|
+
if (!x.isSum()) {
|
|
127
|
+
return x;
|
|
128
|
+
}
|
|
129
|
+
// Step 1: Apply the standard sin²+cos²=1 Pythagorean identity
|
|
130
|
+
let result = simplifyPythagorean(x);
|
|
131
|
+
// Step 2: Apply sec²-tan²=1 and csc²-cot²=1 identities
|
|
132
|
+
if (result.isSum()) {
|
|
133
|
+
result = simplifyDerivedPythagorean(result);
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Standard Pythagorean: a·sin²(u) + a·cos²(u) = a
|
|
139
|
+
* With partial support for mismatched coefficients.
|
|
140
|
+
*/
|
|
141
|
+
function simplifyPythagorean(x) {
|
|
142
|
+
if (!x.isSum()) {
|
|
143
|
+
return x;
|
|
144
|
+
}
|
|
145
|
+
const trigTerms = [];
|
|
146
|
+
const otherTerms = [];
|
|
147
|
+
for (const term of x.elementsArray()) {
|
|
148
|
+
const info = extractTrigSquared(term);
|
|
149
|
+
if (info) {
|
|
150
|
+
trigTerms.push(info);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
otherTerms.push(term);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const hasSin = trigTerms.some(t => t.trigFn === constants_1.SIN);
|
|
157
|
+
const hasCos = trigTerms.some(t => t.trigFn === constants_1.COS);
|
|
158
|
+
if (!hasSin || !hasCos) {
|
|
159
|
+
return x;
|
|
160
|
+
}
|
|
161
|
+
const byArg = new Map();
|
|
162
|
+
for (const t of trigTerms) {
|
|
163
|
+
const key = t.arg.text();
|
|
164
|
+
let group = byArg.get(key);
|
|
165
|
+
if (!group) {
|
|
166
|
+
group = { sins: [], coss: [] };
|
|
167
|
+
byArg.set(key, group);
|
|
168
|
+
}
|
|
169
|
+
if (t.trigFn === constants_1.SIN) {
|
|
170
|
+
group.sins.push(t);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
group.coss.push(t);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const resultTerms = [...otherTerms];
|
|
177
|
+
for (const [, group] of byArg) {
|
|
178
|
+
const { sins, coss } = group;
|
|
179
|
+
const usedSins = new Set();
|
|
180
|
+
const usedCoss = new Set();
|
|
181
|
+
// Step 1: Full Pythagorean cancellation for matching coefficients
|
|
182
|
+
for (let i = 0; i < sins.length; i++) {
|
|
183
|
+
for (let j = 0; j < coss.length; j++) {
|
|
184
|
+
if (usedSins.has(i) || usedCoss.has(j)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (sins[i].coeff.eq(coss[j].coeff)) {
|
|
188
|
+
resultTerms.push(sins[i].coeff);
|
|
189
|
+
usedSins.add(i);
|
|
190
|
+
usedCoss.add(j);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Step 2: Partial Pythagorean for mismatched coefficients
|
|
195
|
+
for (let i = 0; i < sins.length; i++) {
|
|
196
|
+
if (usedSins.has(i)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
for (let j = 0; j < coss.length; j++) {
|
|
200
|
+
if (usedCoss.has(j)) {
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (sins[i].arg.eq(coss[j].arg)) {
|
|
204
|
+
const a = sins[i].coeff;
|
|
205
|
+
const b = coss[j].coeff;
|
|
206
|
+
const diff = a.minus(b);
|
|
207
|
+
let smaller;
|
|
208
|
+
let larger;
|
|
209
|
+
let remainderFn;
|
|
210
|
+
if (diff.sign() === 1) {
|
|
211
|
+
smaller = b;
|
|
212
|
+
larger = a;
|
|
213
|
+
remainderFn = (0, trig_1.sin)(sins[i].arg).pow((0, shortcuts_1.two)());
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
smaller = a;
|
|
217
|
+
larger = b;
|
|
218
|
+
remainderFn = (0, trig_1.cos)(coss[j].arg).pow((0, shortcuts_1.two)());
|
|
219
|
+
}
|
|
220
|
+
const scale = smaller.getDenominator();
|
|
221
|
+
const scaledSmaller = smaller.times(scale);
|
|
222
|
+
const scaledRemainder = larger.minus(smaller).times(scale);
|
|
223
|
+
const inner = scaledSmaller.plus(scaledRemainder.times(remainderFn));
|
|
224
|
+
resultTerms.push((0, shortcuts_1.one)().div(scale).times(inner));
|
|
225
|
+
usedSins.add(i);
|
|
226
|
+
usedCoss.add(j);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
// Add back unmatched terms
|
|
231
|
+
for (let i = 0; i < sins.length; i++) {
|
|
232
|
+
if (!usedSins.has(i)) {
|
|
233
|
+
resultTerms.push(sins[i].original);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
for (let j = 0; j < coss.length; j++) {
|
|
237
|
+
if (!usedCoss.has(j)) {
|
|
238
|
+
resultTerms.push(coss[j].original);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (resultTerms.length === 1) {
|
|
243
|
+
return resultTerms[0];
|
|
244
|
+
}
|
|
245
|
+
let result = (0, shortcuts_1.zero)();
|
|
246
|
+
for (const term of resultTerms) {
|
|
247
|
+
result = result.plus(term);
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Derived Pythagorean identities applied to sums:
|
|
253
|
+
*
|
|
254
|
+
* a·sec(u)² - a·tan(u)² = a (from 1 + tan² = sec²)
|
|
255
|
+
* a·csc(u)² - a·cot(u)² = a (from 1 + cot² = csc²)
|
|
256
|
+
*
|
|
257
|
+
* Also handles:
|
|
258
|
+
* a·sec(u)² = a + a·tan(u)² (rewrite sec² as 1+tan²)
|
|
259
|
+
* a·tan(u)² = a·sec(u)² - a (rewrite tan² as sec²-1)
|
|
260
|
+
*/
|
|
261
|
+
function simplifyDerivedPythagorean(x) {
|
|
262
|
+
if (!x.isSum()) {
|
|
263
|
+
return x;
|
|
264
|
+
}
|
|
265
|
+
const derivedTerms = [];
|
|
266
|
+
const otherTerms = [];
|
|
267
|
+
for (const term of x.elementsArray()) {
|
|
268
|
+
const info = extractDerivedTrigSquared(term);
|
|
269
|
+
if (info) {
|
|
270
|
+
derivedTerms.push(info);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
otherTerms.push(term);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (derivedTerms.length < 2) {
|
|
277
|
+
return x;
|
|
278
|
+
}
|
|
279
|
+
// Group by argument
|
|
280
|
+
const byArg = new Map();
|
|
281
|
+
for (const t of derivedTerms) {
|
|
282
|
+
const key = t.arg.text();
|
|
283
|
+
let group = byArg.get(key);
|
|
284
|
+
if (!group) {
|
|
285
|
+
group = { secs: [], tans: [], cscs: [], cots: [] };
|
|
286
|
+
byArg.set(key, group);
|
|
287
|
+
}
|
|
288
|
+
if (t.trigFn === constants_1.SEC) {
|
|
289
|
+
group.secs.push(t);
|
|
290
|
+
}
|
|
291
|
+
else if (t.trigFn === constants_1.TAN) {
|
|
292
|
+
group.tans.push(t);
|
|
293
|
+
}
|
|
294
|
+
else if (t.trigFn === constants_1.CSC) {
|
|
295
|
+
group.cscs.push(t);
|
|
296
|
+
}
|
|
297
|
+
else if (t.trigFn === constants_1.COT) {
|
|
298
|
+
group.cots.push(t);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const resultTerms = [...otherTerms];
|
|
302
|
+
for (const [, group] of byArg) {
|
|
303
|
+
const { secs, tans, cscs, cots } = group;
|
|
304
|
+
const usedSecs = new Set();
|
|
305
|
+
const usedTans = new Set();
|
|
306
|
+
const usedCscs = new Set();
|
|
307
|
+
const usedCots = new Set();
|
|
308
|
+
// sec²(u) - tan²(u) = 1 → a·sec²(u) + (-a)·tan²(u) = a
|
|
309
|
+
for (let i = 0; i < secs.length; i++) {
|
|
310
|
+
for (let j = 0; j < tans.length; j++) {
|
|
311
|
+
if (usedSecs.has(i) || usedTans.has(j)) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
// sec² coeff is a, tan² coeff is -a → result is a
|
|
315
|
+
const secCoeff = secs[i].coeff;
|
|
316
|
+
const tanCoeff = tans[j].coeff;
|
|
317
|
+
if (secCoeff.eq(tanCoeff.neg())) {
|
|
318
|
+
resultTerms.push(secCoeff);
|
|
319
|
+
usedSecs.add(i);
|
|
320
|
+
usedTans.add(j);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// csc²(u) - cot²(u) = 1 → a·csc²(u) + (-a)·cot²(u) = a
|
|
325
|
+
for (let i = 0; i < cscs.length; i++) {
|
|
326
|
+
for (let j = 0; j < cots.length; j++) {
|
|
327
|
+
if (usedCscs.has(i) || usedCots.has(j)) {
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const cscCoeff = cscs[i].coeff;
|
|
331
|
+
const cotCoeff = cots[j].coeff;
|
|
332
|
+
if (cscCoeff.eq(cotCoeff.neg())) {
|
|
333
|
+
resultTerms.push(cscCoeff);
|
|
334
|
+
usedCscs.add(i);
|
|
335
|
+
usedCots.add(j);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// Add back unmatched terms
|
|
340
|
+
for (let i = 0; i < secs.length; i++) {
|
|
341
|
+
if (!usedSecs.has(i)) {
|
|
342
|
+
resultTerms.push(secs[i].original);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
for (let j = 0; j < tans.length; j++) {
|
|
346
|
+
if (!usedTans.has(j)) {
|
|
347
|
+
resultTerms.push(tans[j].original);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
for (let i = 0; i < cscs.length; i++) {
|
|
351
|
+
if (!usedCscs.has(i)) {
|
|
352
|
+
resultTerms.push(cscs[i].original);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
for (let j = 0; j < cots.length; j++) {
|
|
356
|
+
if (!usedCots.has(j)) {
|
|
357
|
+
resultTerms.push(cots[j].original);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (resultTerms.length === 1) {
|
|
362
|
+
return resultTerms[0];
|
|
363
|
+
}
|
|
364
|
+
let result = (0, shortcuts_1.zero)();
|
|
365
|
+
for (const term of resultTerms) {
|
|
366
|
+
result = result.plus(term);
|
|
367
|
+
}
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Expression } from '../../core/classes/expression/Expression';
|
|
2
|
+
/**
|
|
3
|
+
* Strategies
|
|
4
|
+
*
|
|
5
|
+
* Sums
|
|
6
|
+
* ===================
|
|
7
|
+
* Rewrite cos^2+sin^2=1
|
|
8
|
+
* Rewrite sec^2-tan^2=1, csc^2-cot^2=1
|
|
9
|
+
* Combine log terms: log(a)+log(b) → log(a·b)
|
|
10
|
+
*
|
|
11
|
+
* Products
|
|
12
|
+
* ===================
|
|
13
|
+
* Radicalize expression
|
|
14
|
+
* Rewrite all trig functions as sin & cos and then fish back out other identities
|
|
15
|
+
* Recursively call simplify until expression in === out
|
|
16
|
+
* Factor the top polynomial by the bottom
|
|
17
|
+
* Simplify factorial ratios: n!/(n+k)! → 1/((n+1)...(n+k))
|
|
18
|
+
* Rewrite sin(u)*cos(u) → (1/2)*sin(2u)
|
|
19
|
+
*
|
|
20
|
+
* Functions
|
|
21
|
+
* ==================
|
|
22
|
+
* trigreduce: power reduction for sin²/cos² → half-angle form
|
|
23
|
+
*
|
|
24
|
+
* Factor out the GCD
|
|
25
|
+
*/
|
|
26
|
+
export declare function hasIrrationalDenominator(x: Expression): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a product expression contains at least two factorial terms
|
|
29
|
+
* (one with positive power, one with negative), indicating a ratio that
|
|
30
|
+
* can potentially be simplified.
|
|
31
|
+
*/
|
|
32
|
+
export declare function hasFactorialRatio(x: Expression): boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasIrrationalDenominator = hasIrrationalDenominator;
|
|
4
|
+
exports.hasFactorialRatio = hasFactorialRatio;
|
|
5
|
+
const constants_1 = require("../../core/classes/parser/constants");
|
|
6
|
+
/**
|
|
7
|
+
* Strategies
|
|
8
|
+
*
|
|
9
|
+
* Sums
|
|
10
|
+
* ===================
|
|
11
|
+
* Rewrite cos^2+sin^2=1
|
|
12
|
+
* Rewrite sec^2-tan^2=1, csc^2-cot^2=1
|
|
13
|
+
* Combine log terms: log(a)+log(b) → log(a·b)
|
|
14
|
+
*
|
|
15
|
+
* Products
|
|
16
|
+
* ===================
|
|
17
|
+
* Radicalize expression
|
|
18
|
+
* Rewrite all trig functions as sin & cos and then fish back out other identities
|
|
19
|
+
* Recursively call simplify until expression in === out
|
|
20
|
+
* Factor the top polynomial by the bottom
|
|
21
|
+
* Simplify factorial ratios: n!/(n+k)! → 1/((n+1)...(n+k))
|
|
22
|
+
* Rewrite sin(u)*cos(u) → (1/2)*sin(2u)
|
|
23
|
+
*
|
|
24
|
+
* Functions
|
|
25
|
+
* ==================
|
|
26
|
+
* trigreduce: power reduction for sin²/cos² → half-angle form
|
|
27
|
+
*
|
|
28
|
+
* Factor out the GCD
|
|
29
|
+
*/
|
|
30
|
+
function hasIrrationalDenominator(x) {
|
|
31
|
+
const checkIrrationalDenominator = true;
|
|
32
|
+
return x.hasRadical(checkIrrationalDenominator);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if a product expression contains at least two factorial terms
|
|
36
|
+
* (one with positive power, one with negative), indicating a ratio that
|
|
37
|
+
* can potentially be simplified.
|
|
38
|
+
*/
|
|
39
|
+
function hasFactorialRatio(x) {
|
|
40
|
+
if (!x.isProduct()) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
let hasPos = false;
|
|
44
|
+
let hasNeg = false;
|
|
45
|
+
for (const element of x.elementsArray()) {
|
|
46
|
+
if (element.isFunction(constants_1.FACTORIAL)) {
|
|
47
|
+
if (element.getPower().sign() === 1) {
|
|
48
|
+
hasPos = true;
|
|
49
|
+
}
|
|
50
|
+
else if (element.getPower().sign() === -1) {
|
|
51
|
+
hasNeg = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return hasPos && hasNeg;
|
|
56
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Expression } from '../core/classes/expression/Expression';
|
|
2
|
+
import type { ExpressionInput } from '../core/types';
|
|
3
|
+
/** Components of a quadratic rewritten by {@link sqcomp}. */
|
|
4
|
+
export interface CompleteSquareResult {
|
|
5
|
+
/** Original quadratic coefficient. */
|
|
6
|
+
a: Expression;
|
|
7
|
+
/** Shift in `a*(variable+h)^2+k`. */
|
|
8
|
+
h: Expression;
|
|
9
|
+
/** Remaining constant in `a*(variable+h)^2+k`. */
|
|
10
|
+
k: Expression;
|
|
11
|
+
/** Variable used for the rewrite. */
|
|
12
|
+
variable: string;
|
|
13
|
+
/** Completed-square expression. */
|
|
14
|
+
expression: Expression;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Completes the square for a quadratic expression.
|
|
18
|
+
*
|
|
19
|
+
* For `a*x^2+b*x+c`, the returned expression has the form
|
|
20
|
+
* `a*(x+h)^2+k`, with `h=b/(2*a)` and `k=c-b^2/(4*a)`.
|
|
21
|
+
*
|
|
22
|
+
* @param expr - Quadratic expression to rewrite.
|
|
23
|
+
* @param variable - Variable to use. Defaults to the first variable in the expression.
|
|
24
|
+
* @returns The quadratic coefficient, shift, remainder, selected variable, and rewritten expression.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const result = sqcomp('x^2+6*x+1');
|
|
29
|
+
* result.expression.text({ sort: true }); // "(3+x)^2-8"
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function sqcomp(expr: ExpressionInput, variable?: string): CompleteSquareResult;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sqcomp = sqcomp;
|
|
4
|
+
const Expression_1 = require("../core/classes/expression/Expression");
|
|
5
|
+
const shortcuts_1 = require("../core/classes/expression/shortcuts");
|
|
6
|
+
const errors_1 = require("../core/errors");
|
|
7
|
+
/**
|
|
8
|
+
* Completes the square for a quadratic expression.
|
|
9
|
+
*
|
|
10
|
+
* For `a*x^2+b*x+c`, the returned expression has the form
|
|
11
|
+
* `a*(x+h)^2+k`, with `h=b/(2*a)` and `k=c-b^2/(4*a)`.
|
|
12
|
+
*
|
|
13
|
+
* @param expr - Quadratic expression to rewrite.
|
|
14
|
+
* @param variable - Variable to use. Defaults to the first variable in the expression.
|
|
15
|
+
* @returns The quadratic coefficient, shift, remainder, selected variable, and rewritten expression.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const result = sqcomp('x^2+6*x+1');
|
|
20
|
+
* result.expression.text({ sort: true }); // "(3+x)^2-8"
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function sqcomp(expr, variable) {
|
|
24
|
+
const e = Expression_1.Expression.create(expr);
|
|
25
|
+
// Auto-detect variable if not provided
|
|
26
|
+
if (!variable) {
|
|
27
|
+
const vars = e.variables();
|
|
28
|
+
if (vars.length === 0) {
|
|
29
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('noVariableInExpression'));
|
|
30
|
+
}
|
|
31
|
+
variable = vars[0];
|
|
32
|
+
}
|
|
33
|
+
const c = e.coeffs(variable);
|
|
34
|
+
if (c.max() !== 2) {
|
|
35
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('quadraticExpressionExpected'));
|
|
36
|
+
}
|
|
37
|
+
const a = c.hasPower(2) ? c.getPower(2) : (0, shortcuts_1.zero)();
|
|
38
|
+
const b = c.hasPower(1) ? c.getPower(1) : (0, shortcuts_1.zero)();
|
|
39
|
+
const k0 = c.hasPower(0) ? c.getPower(0) : (0, shortcuts_1.zero)();
|
|
40
|
+
// h = b / (2a)
|
|
41
|
+
const h = b.div(a.times(2));
|
|
42
|
+
// k = c - b² / (4a)
|
|
43
|
+
const k = k0.minus(b.pow(2).div(a.times(4)));
|
|
44
|
+
// Build a*(variable + h)^2 + k
|
|
45
|
+
const x = Expression_1.Expression.create(variable);
|
|
46
|
+
const expression = a.times(x.plus(h).pow(2)).plus(k);
|
|
47
|
+
return { a, h, k, variable, expression };
|
|
48
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Groebner, GroebnerBudgetExceeded, eliminate, groebnerBasisWithOptions, idealMembership, reduceByBasis, solve as solveRationalSystem, } from '../algebra/algorithms/groebnerBase';
|
|
2
|
+
export type { GroebnerBasisOptions, GroebnerStats, MonomialOrder, RationalSolution, } from '../algebra/algorithms/groebnerBase';
|
|
3
|
+
export { MultiPoly } from '../algebra/algorithms/multiPoly/MultiPoly';
|
|
4
|
+
/** Advanced numerical and exact-polynomial APIs. */
|
|
5
|
+
export { Complex } from '../core/classes/complex/Complex';
|
|
6
|
+
export { FunctionSolver } from '../solve/classes/FunctionSolver';
|
|
7
|
+
export type { FunctionSolverOptions, Root, RootFindingMethod, } from '../solve/classes/FunctionSolver';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionSolver = exports.Complex = exports.MultiPoly = exports.solveRationalSystem = exports.reduceByBasis = exports.idealMembership = exports.groebnerBasisWithOptions = exports.eliminate = exports.GroebnerBudgetExceeded = exports.Groebner = void 0;
|
|
4
|
+
var groebnerBase_1 = require("../algebra/algorithms/groebnerBase");
|
|
5
|
+
Object.defineProperty(exports, "Groebner", { enumerable: true, get: function () { return groebnerBase_1.Groebner; } });
|
|
6
|
+
Object.defineProperty(exports, "GroebnerBudgetExceeded", { enumerable: true, get: function () { return groebnerBase_1.GroebnerBudgetExceeded; } });
|
|
7
|
+
Object.defineProperty(exports, "eliminate", { enumerable: true, get: function () { return groebnerBase_1.eliminate; } });
|
|
8
|
+
Object.defineProperty(exports, "groebnerBasisWithOptions", { enumerable: true, get: function () { return groebnerBase_1.groebnerBasisWithOptions; } });
|
|
9
|
+
Object.defineProperty(exports, "idealMembership", { enumerable: true, get: function () { return groebnerBase_1.idealMembership; } });
|
|
10
|
+
Object.defineProperty(exports, "reduceByBasis", { enumerable: true, get: function () { return groebnerBase_1.reduceByBasis; } });
|
|
11
|
+
Object.defineProperty(exports, "solveRationalSystem", { enumerable: true, get: function () { return groebnerBase_1.solve; } });
|
|
12
|
+
var MultiPoly_1 = require("../algebra/algorithms/multiPoly/MultiPoly");
|
|
13
|
+
Object.defineProperty(exports, "MultiPoly", { enumerable: true, get: function () { return MultiPoly_1.MultiPoly; } });
|
|
14
|
+
/** Advanced numerical and exact-polynomial APIs. */
|
|
15
|
+
var Complex_1 = require("../core/classes/complex/Complex");
|
|
16
|
+
Object.defineProperty(exports, "Complex", { enumerable: true, get: function () { return Complex_1.Complex; } });
|
|
17
|
+
var FunctionSolver_1 = require("../solve/classes/FunctionSolver");
|
|
18
|
+
Object.defineProperty(exports, "FunctionSolver", { enumerable: true, get: function () { return FunctionSolver_1.FunctionSolver; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Public symbolic algebra and polynomial APIs. */
|
|
2
|
+
export { factor, polyFactors } from '../algebra/factor/factor';
|
|
3
|
+
export { gcd, lcm } from '../algebra/gcd/gcd';
|
|
4
|
+
export { groebner } from '../algebra/groebner';
|
|
5
|
+
export { partfrac } from '../algebra/partfrac';
|
|
6
|
+
export { simplify } from '../algebra/simplify/simplify';
|
|
7
|
+
export { sqcomp as completeSquare } from '../algebra/utils';
|
|
8
|
+
export type { CompleteSquareResult } from '../algebra/utils';
|
|
9
|
+
export { CoeffObject } from '../core/classes/expression/CoeffObject';
|
|
10
|
+
export { content, deg } from '../core/classes/polynomial/functions';
|
|
11
|
+
export { Polynomial } from '../core/classes/polynomial/Polynomial';
|
|
12
|
+
export type { EvalInputType, Ordering, PolyType, VariableFrequency, } from '../core/classes/polynomial/Polynomial';
|
|
13
|
+
export { Term } from '../core/classes/polynomial/Term';
|
|
14
|
+
export type { PowersObject } from '../core/classes/polynomial/Term';
|
|
15
|
+
export { uSub, uUnSub } from '../core/functions/subst';
|
|
16
|
+
export type { SubstitutionMap, USubstitutionResult, } from '../core/functions/subst';
|
|
17
|
+
export { isprime as isPrime } from '../math/utils';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPrime = exports.uUnSub = exports.uSub = exports.Term = exports.Polynomial = exports.deg = exports.content = exports.CoeffObject = exports.completeSquare = exports.simplify = exports.partfrac = exports.groebner = exports.lcm = exports.gcd = exports.polyFactors = exports.factor = void 0;
|
|
4
|
+
/** Public symbolic algebra and polynomial APIs. */
|
|
5
|
+
var factor_1 = require("../algebra/factor/factor");
|
|
6
|
+
Object.defineProperty(exports, "factor", { enumerable: true, get: function () { return factor_1.factor; } });
|
|
7
|
+
Object.defineProperty(exports, "polyFactors", { enumerable: true, get: function () { return factor_1.polyFactors; } });
|
|
8
|
+
var gcd_1 = require("../algebra/gcd/gcd");
|
|
9
|
+
Object.defineProperty(exports, "gcd", { enumerable: true, get: function () { return gcd_1.gcd; } });
|
|
10
|
+
Object.defineProperty(exports, "lcm", { enumerable: true, get: function () { return gcd_1.lcm; } });
|
|
11
|
+
var groebner_1 = require("../algebra/groebner");
|
|
12
|
+
Object.defineProperty(exports, "groebner", { enumerable: true, get: function () { return groebner_1.groebner; } });
|
|
13
|
+
var partfrac_1 = require("../algebra/partfrac");
|
|
14
|
+
Object.defineProperty(exports, "partfrac", { enumerable: true, get: function () { return partfrac_1.partfrac; } });
|
|
15
|
+
var simplify_1 = require("../algebra/simplify/simplify");
|
|
16
|
+
Object.defineProperty(exports, "simplify", { enumerable: true, get: function () { return simplify_1.simplify; } });
|
|
17
|
+
var utils_1 = require("../algebra/utils");
|
|
18
|
+
Object.defineProperty(exports, "completeSquare", { enumerable: true, get: function () { return utils_1.sqcomp; } });
|
|
19
|
+
var CoeffObject_1 = require("../core/classes/expression/CoeffObject");
|
|
20
|
+
Object.defineProperty(exports, "CoeffObject", { enumerable: true, get: function () { return CoeffObject_1.CoeffObject; } });
|
|
21
|
+
var functions_1 = require("../core/classes/polynomial/functions");
|
|
22
|
+
Object.defineProperty(exports, "content", { enumerable: true, get: function () { return functions_1.content; } });
|
|
23
|
+
Object.defineProperty(exports, "deg", { enumerable: true, get: function () { return functions_1.deg; } });
|
|
24
|
+
var Polynomial_1 = require("../core/classes/polynomial/Polynomial");
|
|
25
|
+
Object.defineProperty(exports, "Polynomial", { enumerable: true, get: function () { return Polynomial_1.Polynomial; } });
|
|
26
|
+
var Term_1 = require("../core/classes/polynomial/Term");
|
|
27
|
+
Object.defineProperty(exports, "Term", { enumerable: true, get: function () { return Term_1.Term; } });
|
|
28
|
+
var subst_1 = require("../core/functions/subst");
|
|
29
|
+
Object.defineProperty(exports, "uSub", { enumerable: true, get: function () { return subst_1.uSub; } });
|
|
30
|
+
Object.defineProperty(exports, "uUnSub", { enumerable: true, get: function () { return subst_1.uUnSub; } });
|
|
31
|
+
var utils_2 = require("../math/utils");
|
|
32
|
+
Object.defineProperty(exports, "isPrime", { enumerable: true, get: function () { return utils_2.isprime; } });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { assume, clearAssumptions, forgetAssumptionFor, getAssumptionFor, } from '../core/classes/assumption/assume';
|
|
2
|
+
/** Public process-wide assumption APIs. */
|
|
3
|
+
export { Assumption } from '../core/classes/assumption/Assumption';
|
|
4
|
+
export type { AssumptionComparison, AssumptionValue, Bound, ParsedAssumption, } from '../core/classes/assumption/Assumption';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Assumption = exports.getAssumptionFor = exports.forgetAssumptionFor = exports.clearAssumptions = exports.assume = void 0;
|
|
4
|
+
var assume_1 = require("../core/classes/assumption/assume");
|
|
5
|
+
Object.defineProperty(exports, "assume", { enumerable: true, get: function () { return assume_1.assume; } });
|
|
6
|
+
Object.defineProperty(exports, "clearAssumptions", { enumerable: true, get: function () { return assume_1.clearAssumptions; } });
|
|
7
|
+
Object.defineProperty(exports, "forgetAssumptionFor", { enumerable: true, get: function () { return assume_1.forgetAssumptionFor; } });
|
|
8
|
+
Object.defineProperty(exports, "getAssumptionFor", { enumerable: true, get: function () { return assume_1.getAssumptionFor; } });
|
|
9
|
+
/** Public process-wide assumption APIs. */
|
|
10
|
+
var Assumption_1 = require("../core/classes/assumption/Assumption");
|
|
11
|
+
Object.defineProperty(exports, "Assumption", { enumerable: true, get: function () { return Assumption_1.Assumption; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Public calculus APIs. */
|
|
2
|
+
export { diff } from '../calculus/derivative/diff';
|
|
3
|
+
export { S, C } from '../calculus/fresnel';
|
|
4
|
+
export { integrate } from '../calculus/integrate/integrate';
|
|
5
|
+
export { ilaplace } from '../calculus/laplace/ilaplace';
|
|
6
|
+
export { laplace } from '../calculus/laplace/laplace';
|
|
7
|
+
export { limit } from '../calculus/limit/limit';
|
|
8
|
+
export type { LimitDir } from '../calculus/limit/limit';
|
|
9
|
+
export { defint, product, sum } from '../math/math';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sum = exports.product = exports.defint = exports.limit = exports.laplace = exports.ilaplace = exports.integrate = exports.C = exports.S = exports.diff = void 0;
|
|
4
|
+
/** Public calculus APIs. */
|
|
5
|
+
var diff_1 = require("../calculus/derivative/diff");
|
|
6
|
+
Object.defineProperty(exports, "diff", { enumerable: true, get: function () { return diff_1.diff; } });
|
|
7
|
+
var fresnel_1 = require("../calculus/fresnel");
|
|
8
|
+
Object.defineProperty(exports, "S", { enumerable: true, get: function () { return fresnel_1.S; } });
|
|
9
|
+
Object.defineProperty(exports, "C", { enumerable: true, get: function () { return fresnel_1.C; } });
|
|
10
|
+
var integrate_1 = require("../calculus/integrate/integrate");
|
|
11
|
+
Object.defineProperty(exports, "integrate", { enumerable: true, get: function () { return integrate_1.integrate; } });
|
|
12
|
+
var ilaplace_1 = require("../calculus/laplace/ilaplace");
|
|
13
|
+
Object.defineProperty(exports, "ilaplace", { enumerable: true, get: function () { return ilaplace_1.ilaplace; } });
|
|
14
|
+
var laplace_1 = require("../calculus/laplace/laplace");
|
|
15
|
+
Object.defineProperty(exports, "laplace", { enumerable: true, get: function () { return laplace_1.laplace; } });
|
|
16
|
+
var limit_1 = require("../calculus/limit/limit");
|
|
17
|
+
Object.defineProperty(exports, "limit", { enumerable: true, get: function () { return limit_1.limit; } });
|
|
18
|
+
var math_1 = require("../math/math");
|
|
19
|
+
Object.defineProperty(exports, "defint", { enumerable: true, get: function () { return math_1.defint; } });
|
|
20
|
+
Object.defineProperty(exports, "product", { enumerable: true, get: function () { return math_1.product; } });
|
|
21
|
+
Object.defineProperty(exports, "sum", { enumerable: true, get: function () { return math_1.sum; } });
|