nerdamer 1.1.13 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BREAKING_CHANGES.md +244 -5
- package/LICENSE.md +184 -0
- package/README.md +232 -318
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +7 -0
- package/dist/parser.js +2 -0
- package/dist/parser.js.LICENSE.txt +7 -0
- package/docs-data/parser-functions.json +2248 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +3 -0
- package/output/algebra/adapters.js +11 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +324 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +161 -0
- package/output/algebra/algorithms/groebnerBase.js +929 -0
- package/output/algebra/dispatch.d.ts +1 -0
- package/output/algebra/dispatch.js +25 -0
- package/output/algebra/factor/factor.d.ts +77 -0
- package/output/algebra/factor/factor.js +245 -0
- package/output/algebra/gcd/gcd.d.ts +30 -0
- package/output/algebra/gcd/gcd.js +95 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +36 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +365 -0
- package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
- package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
- package/output/algebra/polynomial/modularGcd.d.ts +40 -0
- package/output/algebra/polynomial/modularGcd.js +365 -0
- package/output/algebra/polynomialize.d.ts +20 -0
- package/output/algebra/polynomialize.js +26 -0
- package/output/algebra/simplify/complexsimp.d.ts +7 -0
- package/output/algebra/simplify/complexsimp.js +24 -0
- package/output/algebra/simplify/factorCommon.d.ts +13 -0
- package/output/algebra/simplify/factorCommon.js +136 -0
- package/output/algebra/simplify/funcsimp.d.ts +26 -0
- package/output/algebra/simplify/funcsimp.js +633 -0
- package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
- package/output/algebra/simplify/invtrigrewrite.js +96 -0
- package/output/algebra/simplify/ratsimp.d.ts +21 -0
- package/output/algebra/simplify/ratsimp.js +140 -0
- package/output/algebra/simplify/simplify.d.ts +25 -0
- package/output/algebra/simplify/simplify.js +237 -0
- package/output/algebra/simplify/trigreduce.d.ts +38 -0
- package/output/algebra/simplify/trigreduce.js +424 -0
- package/output/algebra/simplify/trigrewrite.d.ts +17 -0
- package/output/algebra/simplify/trigrewrite.js +156 -0
- package/output/algebra/simplify/trigsimp.d.ts +11 -0
- package/output/algebra/simplify/trigsimp.js +369 -0
- package/output/algebra/simplify/utils.d.ts +32 -0
- package/output/algebra/simplify/utils.js +56 -0
- package/output/algebra/utils.d.ts +32 -0
- package/output/algebra/utils.js +48 -0
- package/output/api/advanced.d.ts +8 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +35 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +10 -0
- package/output/api/calculus.js +22 -0
- package/output/api/core.d.ts +17 -0
- package/output/api/core.js +41 -0
- package/output/api/debug.d.ts +16 -0
- package/output/api/debug.js +23 -0
- package/output/api/languages/deu.d.ts +3 -0
- package/output/api/languages/deu.js +266 -0
- package/output/api/languages/fra.d.ts +3 -0
- package/output/api/languages/fra.js +266 -0
- package/output/api/languages/ita.d.ts +3 -0
- package/output/api/languages/ita.js +266 -0
- package/output/api/languages/nld.d.ts +3 -0
- package/output/api/languages/nld.js +266 -0
- package/output/api/languages/por.d.ts +3 -0
- package/output/api/languages/por.js +266 -0
- package/output/api/languages/spa.d.ts +3 -0
- package/output/api/languages/spa.js +266 -0
- package/output/api/parser.d.ts +93 -0
- package/output/api/parser.js +18 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +17 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +23 -0
- package/output/calculus/adapters.d.ts +8 -0
- package/output/calculus/adapters.js +41 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +241 -0
- package/output/calculus/dispatch.d.ts +1 -0
- package/output/calculus/dispatch.js +25 -0
- package/output/calculus/fresnel.d.ts +16 -0
- package/output/calculus/fresnel.js +39 -0
- package/output/calculus/integrate/byParts.d.ts +18 -0
- package/output/calculus/integrate/byParts.js +339 -0
- package/output/calculus/integrate/bySubstitution.d.ts +135 -0
- package/output/calculus/integrate/bySubstitution.js +411 -0
- package/output/calculus/integrate/integrate.d.ts +38 -0
- package/output/calculus/integrate/integrate.js +652 -0
- package/output/calculus/integrate/integrationTable.d.ts +2 -0
- package/output/calculus/integrate/integrationTable.js +914 -0
- package/output/calculus/integrate/utils.d.ts +28 -0
- package/output/calculus/integrate/utils.js +96 -0
- package/output/calculus/laplace/ilaplace.d.ts +31 -0
- package/output/calculus/laplace/ilaplace.js +192 -0
- package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
- package/output/calculus/laplace/ilaplaceTable.js +200 -0
- package/output/calculus/laplace/laplace.d.ts +22 -0
- package/output/calculus/laplace/laplace.js +109 -0
- package/output/calculus/laplace/laplaceTable.d.ts +2 -0
- package/output/calculus/laplace/laplaceTable.js +187 -0
- package/output/calculus/limit/limit.d.ts +35 -0
- package/output/calculus/limit/limit.js +1183 -0
- package/output/calculus/limit/limitsTable.d.ts +2 -0
- package/output/calculus/limit/limitsTable.js +7 -0
- package/output/core/Settings.d.ts +32 -0
- package/output/core/Settings.js +68 -0
- package/output/core/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +609 -0
- package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
- package/output/core/classes/assumption/assertiveFunctions.js +64 -0
- package/output/core/classes/assumption/assume.d.ts +90 -0
- package/output/core/classes/assumption/assume.js +145 -0
- package/output/core/classes/assumption/dispatch.d.ts +1 -0
- package/output/core/classes/assumption/dispatch.js +11 -0
- package/output/core/classes/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +240 -0
- package/output/core/classes/complex/Complex.d.ts +109 -0
- package/output/core/classes/complex/Complex.js +153 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +454 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +216 -0
- package/output/core/classes/equation/Equation.d.ts +256 -0
- package/output/core/classes/equation/Equation.js +350 -0
- package/output/core/classes/expression/CoeffObject.d.ts +100 -0
- package/output/core/classes/expression/CoeffObject.js +197 -0
- package/output/core/classes/expression/Expression.d.ts +1691 -0
- package/output/core/classes/expression/Expression.js +2381 -0
- package/output/core/classes/expression/analysis.d.ts +25 -0
- package/output/core/classes/expression/analysis.js +218 -0
- package/output/core/classes/expression/collect.d.ts +9 -0
- package/output/core/classes/expression/collect.js +49 -0
- package/output/core/classes/expression/format.d.ts +54 -0
- package/output/core/classes/expression/format.js +340 -0
- package/output/core/classes/expression/products.d.ts +23 -0
- package/output/core/classes/expression/products.js +115 -0
- package/output/core/classes/expression/shortcuts.d.ts +35 -0
- package/output/core/classes/expression/shortcuts.js +129 -0
- package/output/core/classes/expression/traversal.d.ts +31 -0
- package/output/core/classes/expression/traversal.js +216 -0
- package/output/core/classes/expression/trig.d.ts +25 -0
- package/output/core/classes/expression/trig.js +40 -0
- package/output/core/classes/expression/utils.d.ts +61 -0
- package/output/core/classes/expression/utils.js +235 -0
- package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
- package/output/core/classes/lookupTable/LookupTable.js +55 -0
- package/output/core/classes/matrix/Matrix.d.ts +227 -0
- package/output/core/classes/matrix/Matrix.js +901 -0
- package/output/core/classes/matrix/Sylvester.d.ts +11 -0
- package/output/core/classes/matrix/Sylvester.js +54 -0
- package/output/core/classes/matrix/dispatch.d.ts +1 -0
- package/output/core/classes/matrix/dispatch.js +19 -0
- package/output/core/classes/matrix/functions.d.ts +28 -0
- package/output/core/classes/matrix/functions.js +57 -0
- package/output/core/classes/matrix/utils.d.ts +9 -0
- package/output/core/classes/matrix/utils.js +22 -0
- package/output/core/classes/parser/Parser.d.ts +493 -0
- package/output/core/classes/parser/Parser.js +1863 -0
- package/output/core/classes/parser/Token.d.ts +58 -0
- package/output/core/classes/parser/Token.js +137 -0
- package/output/core/classes/parser/constants.d.ts +162 -0
- package/output/core/classes/parser/constants.js +229 -0
- package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
- package/output/core/classes/parser/controlFlowSignals.js +60 -0
- package/output/core/classes/parser/helpers.d.ts +21 -0
- package/output/core/classes/parser/helpers.js +42 -0
- package/output/core/classes/parser/operations/add.d.ts +15 -0
- package/output/core/classes/parser/operations/add.js +236 -0
- package/output/core/classes/parser/operations/comma.d.ts +7 -0
- package/output/core/classes/parser/operations/comma.js +11 -0
- package/output/core/classes/parser/operations/compare.d.ts +21 -0
- package/output/core/classes/parser/operations/compare.js +474 -0
- package/output/core/classes/parser/operations/divide.d.ts +2 -0
- package/output/core/classes/parser/operations/divide.js +72 -0
- package/output/core/classes/parser/operations/functions.d.ts +46 -0
- package/output/core/classes/parser/operations/functions.js +438 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +328 -0
- package/output/core/classes/parser/operations/power.d.ts +48 -0
- package/output/core/classes/parser/operations/power.js +673 -0
- package/output/core/classes/parser/operations/subtract.d.ts +3 -0
- package/output/core/classes/parser/operations/subtract.js +36 -0
- package/output/core/classes/parser/preprocess.d.ts +7 -0
- package/output/core/classes/parser/preprocess.js +246 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +23 -0
- package/output/core/classes/parser/scripting/controlFlow.js +279 -0
- package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
- package/output/core/classes/parser/scripting/deferred.js +65 -0
- package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
- package/output/core/classes/parser/scripting/dispatch.js +62 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +23 -0
- package/output/core/classes/parser/scripting/evaluate.js +128 -0
- package/output/core/classes/parser/scripting/functions.d.ts +14 -0
- package/output/core/classes/parser/scripting/functions.js +59 -0
- package/output/core/classes/parser/scripting/scope.d.ts +8 -0
- package/output/core/classes/parser/scripting/scope.js +132 -0
- package/output/core/classes/parser/types.d.ts +130 -0
- package/output/core/classes/parser/types.js +2 -0
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
- package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
- package/output/core/classes/polynomial/Polynomial.d.ts +504 -0
- package/output/core/classes/polynomial/Polynomial.js +1195 -0
- package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
- package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -0
- package/output/core/classes/polynomial/Term.d.ts +222 -0
- package/output/core/classes/polynomial/Term.js +430 -0
- package/output/core/classes/polynomial/adapters.d.ts +18 -0
- package/output/core/classes/polynomial/adapters.js +33 -0
- package/output/core/classes/polynomial/dispatch.d.ts +1 -0
- package/output/core/classes/polynomial/dispatch.js +14 -0
- package/output/core/classes/polynomial/functions.d.ts +77 -0
- package/output/core/classes/polynomial/functions.js +189 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +207 -0
- package/output/core/classes/rational/Rational.d.ts +501 -0
- package/output/core/classes/rational/Rational.js +829 -0
- package/output/core/classes/seq/SEQ.d.ts +13 -0
- package/output/core/classes/seq/SEQ.js +137 -0
- package/output/core/classes/valuesSet/ValuesSet.d.ts +187 -0
- package/output/core/classes/valuesSet/ValuesSet.js +399 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +501 -0
- package/output/core/classes/vector/dispatch.d.ts +1 -0
- package/output/core/classes/vector/dispatch.js +11 -0
- package/output/core/classes/vector/functions.d.ts +28 -0
- package/output/core/classes/vector/functions.js +47 -0
- package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
- package/output/core/common/classes/MathematicalAggregate.js +149 -0
- package/output/core/common/classes/Scope.d.ts +62 -0
- package/output/core/common/classes/Scope.js +122 -0
- package/output/core/common/classes/StructuredEntity.d.ts +55 -0
- package/output/core/common/classes/StructuredEntity.js +151 -0
- package/output/core/common/common.d.ts +62 -0
- package/output/core/common/common.js +74 -0
- package/output/core/common/functions/functions.d.ts +14 -0
- package/output/core/common/functions/functions.js +33 -0
- package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
- package/output/core/common/functions/structuredEntityUtils.js +40 -0
- package/output/core/converters/BaseConverter.d.ts +97 -0
- package/output/core/converters/BaseConverter.js +405 -0
- package/output/core/converters/Converter.d.ts +111 -0
- package/output/core/converters/Converter.js +806 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +52 -0
- package/output/core/dispatch.js +26 -0
- package/output/core/errors.d.ts +316 -0
- package/output/core/errors.js +349 -0
- package/output/core/fullFunctions.d.ts +7 -0
- package/output/core/fullFunctions.js +31 -0
- package/output/core/functions/bigint/bigint.d.ts +133 -0
- package/output/core/functions/bigint/bigint.js +444 -0
- package/output/core/functions/bigint/primeFactor.d.ts +51 -0
- package/output/core/functions/bigint/primeFactor.js +267 -0
- package/output/core/functions/bigint/primes.d.ts +1 -0
- package/output/core/functions/bigint/primes.js +11 -0
- package/output/core/functions/build/definitions.d.ts +12 -0
- package/output/core/functions/build/definitions.js +139 -0
- package/output/core/functions/build/index.d.ts +32 -0
- package/output/core/functions/build/index.js +136 -0
- package/output/core/functions/complex.d.ts +90 -0
- package/output/core/functions/complex.dispatch.d.ts +1 -0
- package/output/core/functions/complex.dispatch.js +16 -0
- package/output/core/functions/complex.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +665 -0
- package/output/core/functions/expand/expand.d.ts +42 -0
- package/output/core/functions/expand/expand.js +376 -0
- package/output/core/functions/fresnelNumeric.d.ts +12 -0
- package/output/core/functions/fresnelNumeric.js +123 -0
- package/output/core/functions/numeric.d.ts +140 -0
- package/output/core/functions/numeric.js +790 -0
- package/output/core/functions/rationalNormalization.d.ts +11 -0
- package/output/core/functions/rationalNormalization.js +117 -0
- package/output/core/functions/setFunction.d.ts +19 -0
- package/output/core/functions/setFunction.js +75 -0
- package/output/core/functions/string.d.ts +26 -0
- package/output/core/functions/string.js +102 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +506 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/parserFunctions.d.ts +7 -0
- package/output/core/parserFunctions.js +25 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +359 -0
- package/output/index.js +739 -0
- package/output/math/defint/defint.d.ts +18 -0
- package/output/math/defint/defint.js +60 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +321 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +281 -0
- package/output/math/dispatch.d.ts +1 -0
- package/output/math/dispatch.js +101 -0
- package/output/math/geometry.d.ts +12 -0
- package/output/math/geometry.js +55 -0
- package/output/math/math.d.ts +695 -0
- package/output/math/math.js +1955 -0
- package/output/math/trig.d.ts +518 -0
- package/output/math/trig.js +1444 -0
- package/output/math/trunc.d.ts +19 -0
- package/output/math/trunc.js +36 -0
- package/output/math/utils.d.ts +66 -0
- package/output/math/utils.js +219 -0
- package/output/solve/classes/DecimalMatrix.d.ts +17 -0
- package/output/solve/classes/DecimalMatrix.js +86 -0
- package/output/solve/classes/FunctionSolver.d.ts +135 -0
- package/output/solve/classes/FunctionSolver.js +433 -0
- package/output/solve/classes/MultivariateSolver.d.ts +84 -0
- package/output/solve/classes/MultivariateSolver.js +240 -0
- package/output/solve/classes/PolynomialSolver.d.ts +104 -0
- package/output/solve/classes/PolynomialSolver.js +492 -0
- package/output/solve/classes/SolutionSet.d.ts +172 -0
- package/output/solve/classes/SolutionSet.js +434 -0
- package/output/solve/classes/Solver.d.ts +17 -0
- package/output/solve/classes/Solver.js +132 -0
- package/output/solve/classes/SymbolicSolver.d.ts +74 -0
- package/output/solve/classes/SymbolicSolver.js +601 -0
- package/output/solve/dispatch.d.ts +1 -0
- package/output/solve/dispatch.js +13 -0
- package/output/solve/linsolve.d.ts +53 -0
- package/output/solve/linsolve.js +233 -0
- package/output/solve/solve.d.ts +44 -0
- package/output/solve/solve.js +368 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +266 -0
- package/output/solve/utils.d.ts +10 -0
- package/output/solve/utils.js +58 -0
- package/output/utils/array.d.ts +42 -0
- package/output/utils/array.js +98 -0
- package/output/utils/debug.d.ts +131 -0
- package/output/utils/debug.js +296 -0
- package/output/utils/decimal.d.ts +3 -0
- package/output/utils/decimal.js +16 -0
- package/output/utils/numeric.d.ts +14 -0
- package/output/utils/numeric.js +51 -0
- package/output/utils/object.d.ts +26 -0
- package/output/utils/object.js +56 -0
- package/package.json +178 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -14
- package/Calculus.js +0 -2675
- package/Extra.js +0 -622
- package/Solve.js +0 -1783
- package/all.js +0 -16
- package/all.min.js +0 -1
- package/gulpfile.js +0 -16
- package/index.html +0 -158
- package/license.txt +0 -19
- package/nerdamer.core.js +0 -12510
- package/spec/LaTeX.spec.js +0 -302
- package/spec/TeXConvert.spec.js +0 -8
- package/spec/algebra.spec.js +0 -287
- package/spec/basic_parser.spec.js +0 -134
- package/spec/build.spec.js +0 -131
- package/spec/calculus.spec.js +0 -183
- package/spec/core.spec.js +0 -2970
- package/spec/extra.spec.js +0 -54
- package/spec/solve.spec.js +0 -126
- package/spec/support/jasmine.json +0 -11
- package/spec/support/utils.js +0 -42
- package/spec/text.spec.js +0 -132
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.definiteIntegrateNative = definiteIntegrateNative;
|
|
4
|
+
const errors_1 = require("../../core/errors");
|
|
5
|
+
const DEFAULT_TOL = 1e-12;
|
|
6
|
+
const DEFAULT_MAX_DEPTH = 50;
|
|
7
|
+
const DEFAULT_MAX_EVALUATIONS = 100_000;
|
|
8
|
+
const MAX_SINGULAR_TRIES = 8;
|
|
9
|
+
const INFINITE_BOUND_ENDPOINT_EPSILON = 1e-15;
|
|
10
|
+
// ── Helpers ──────────────────────────────────────────────────────────
|
|
11
|
+
function simpson(a, b, fa, fm, fb) {
|
|
12
|
+
return ((b - a) / 6) * (fa + 4 * fm + fb);
|
|
13
|
+
}
|
|
14
|
+
// ── Core: finite-bounds adaptive Simpson ─────────────────────────────
|
|
15
|
+
function withFiniteBounds(f, aIn, bIn, tolAbs, tolRel, maxDepth, maxEvals, singular) {
|
|
16
|
+
let a = aIn;
|
|
17
|
+
let b = bIn;
|
|
18
|
+
if (a === b) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
let sign = 1;
|
|
22
|
+
if (b < a) {
|
|
23
|
+
sign = -1;
|
|
24
|
+
const t = a;
|
|
25
|
+
a = b;
|
|
26
|
+
b = t;
|
|
27
|
+
}
|
|
28
|
+
let evals = 0;
|
|
29
|
+
const evalF = (x) => {
|
|
30
|
+
if (++evals > maxEvals) {
|
|
31
|
+
throw new Error((0, errors_1.message)('defintMaxEvals', { max: String(maxEvals) }));
|
|
32
|
+
}
|
|
33
|
+
const y = f(x);
|
|
34
|
+
if (singular === 'strict' && !isFinite(y)) {
|
|
35
|
+
throw new Error((0, errors_1.message)('defintNonFiniteValue', { x: String(x) }));
|
|
36
|
+
}
|
|
37
|
+
return y;
|
|
38
|
+
};
|
|
39
|
+
const m0 = (a + b) / 2;
|
|
40
|
+
const fa = evalF(a);
|
|
41
|
+
const fm = evalF(m0);
|
|
42
|
+
const fb = evalF(b);
|
|
43
|
+
if (singular === 'ignore' && (isNaN(fa) || isNaN(fm) || isNaN(fb))) {
|
|
44
|
+
return NaN;
|
|
45
|
+
}
|
|
46
|
+
// Auto-split if initial evaluations hit non-finite values
|
|
47
|
+
if (singular === 'auto' && (!isFinite(fa) || !isFinite(fm) || !isFinite(fb))) {
|
|
48
|
+
const leftEndpointSingular = !isFinite(fa) && isFinite(fm) && isFinite(fb);
|
|
49
|
+
const rightEndpointSingular = isFinite(fa) && isFinite(fm) && !isFinite(fb);
|
|
50
|
+
if (leftEndpointSingular || rightEndpointSingular) {
|
|
51
|
+
const span = b - a;
|
|
52
|
+
const endpointProbe = Math.sqrt(Number.EPSILON);
|
|
53
|
+
const singularAtLeft = leftEndpointSingular;
|
|
54
|
+
// A quadratic substitution removes the common integrable endpoint singularities
|
|
55
|
+
// without evaluating the original function at the singular endpoint. Clamping the
|
|
56
|
+
// transformed endpoint inward also avoids roundoff mapping tiny t values back to it.
|
|
57
|
+
const transformed = t => {
|
|
58
|
+
const u = Math.max(t, endpointProbe);
|
|
59
|
+
const x = singularAtLeft ? a + span * u * u : b - span * u * u;
|
|
60
|
+
const y = f(x) * 2 * span * u;
|
|
61
|
+
if (!isFinite(y)) {
|
|
62
|
+
throw new Error((0, errors_1.message)('defintEndpointSingularity', { x: String(x) }));
|
|
63
|
+
}
|
|
64
|
+
return y;
|
|
65
|
+
};
|
|
66
|
+
return (sign *
|
|
67
|
+
withFiniteBounds(transformed, 0, 1, tolAbs, tolRel, maxDepth, maxEvals, singular));
|
|
68
|
+
}
|
|
69
|
+
return sign * autoSplitFinite(f, a, b, tolAbs, tolRel, maxDepth, maxEvals, singular);
|
|
70
|
+
}
|
|
71
|
+
const S0 = simpson(a, b, fa, fm, fb);
|
|
72
|
+
const stack = [
|
|
73
|
+
{
|
|
74
|
+
a,
|
|
75
|
+
b,
|
|
76
|
+
m: m0,
|
|
77
|
+
fa,
|
|
78
|
+
fm,
|
|
79
|
+
fb,
|
|
80
|
+
S: S0,
|
|
81
|
+
depth: 0,
|
|
82
|
+
tolAbs,
|
|
83
|
+
tolRel,
|
|
84
|
+
singularTries: 0,
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
let acc = 0;
|
|
88
|
+
while (stack.length > 0) {
|
|
89
|
+
const fr = stack[stack.length - 1];
|
|
90
|
+
stack.pop();
|
|
91
|
+
const { a: a0, b: b0, m } = fr;
|
|
92
|
+
// Absolute tolerance is budgeted across child intervals. Relative tolerance stays
|
|
93
|
+
// relative to each child estimate rather than tightening again at every depth.
|
|
94
|
+
const childTolRel = fr.tolRel;
|
|
95
|
+
const lm = (a0 + m) / 2;
|
|
96
|
+
const rm = (m + b0) / 2;
|
|
97
|
+
const fLM = evalF(lm);
|
|
98
|
+
const fRM = evalF(rm);
|
|
99
|
+
if (singular === 'ignore' && (isNaN(fLM) || isNaN(fRM))) {
|
|
100
|
+
return NaN;
|
|
101
|
+
}
|
|
102
|
+
// Auto: bisect around non-finite values
|
|
103
|
+
if (singular === 'auto' &&
|
|
104
|
+
(!isFinite(fLM) ||
|
|
105
|
+
!isFinite(fRM) ||
|
|
106
|
+
!isFinite(fr.fa) ||
|
|
107
|
+
!isFinite(fr.fm) ||
|
|
108
|
+
!isFinite(fr.fb))) {
|
|
109
|
+
if (fr.depth >= maxDepth || fr.singularTries >= MAX_SINGULAR_TRIES) {
|
|
110
|
+
throw new Error((0, errors_1.message)('defintSingularity', { a: String(a0), b: String(b0) }));
|
|
111
|
+
}
|
|
112
|
+
const nextDepth = fr.depth + 1;
|
|
113
|
+
const childTolAbs = fr.tolAbs / 2;
|
|
114
|
+
stack.push({
|
|
115
|
+
a: m,
|
|
116
|
+
b: b0,
|
|
117
|
+
m: rm,
|
|
118
|
+
fa: fr.fm,
|
|
119
|
+
fm: fRM,
|
|
120
|
+
fb: fr.fb,
|
|
121
|
+
S: simpson(m, b0, fr.fm, fRM, fr.fb),
|
|
122
|
+
depth: nextDepth,
|
|
123
|
+
tolAbs: childTolAbs,
|
|
124
|
+
tolRel: childTolRel,
|
|
125
|
+
singularTries: fr.singularTries + 1,
|
|
126
|
+
});
|
|
127
|
+
stack.push({
|
|
128
|
+
a: a0,
|
|
129
|
+
b: m,
|
|
130
|
+
m: lm,
|
|
131
|
+
fa: fr.fa,
|
|
132
|
+
fm: fLM,
|
|
133
|
+
fb: fr.fm,
|
|
134
|
+
S: simpson(a0, m, fr.fa, fLM, fr.fm),
|
|
135
|
+
depth: nextDepth,
|
|
136
|
+
tolAbs: childTolAbs,
|
|
137
|
+
tolRel: childTolRel,
|
|
138
|
+
singularTries: fr.singularTries + 1,
|
|
139
|
+
});
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const Sleft = simpson(a0, m, fr.fa, fLM, fr.fm);
|
|
143
|
+
const Sright = simpson(m, b0, fr.fm, fRM, fr.fb);
|
|
144
|
+
const S2 = Sleft + Sright;
|
|
145
|
+
const err = Math.abs(S2 - fr.S) / 15;
|
|
146
|
+
const scale = fr.tolAbs + fr.tolRel * Math.abs(S2);
|
|
147
|
+
if (err <= scale || fr.depth >= maxDepth) {
|
|
148
|
+
// Richardson extrapolation
|
|
149
|
+
acc += S2 + (S2 - fr.S) / 15;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const nextDepth = fr.depth + 1;
|
|
153
|
+
const childTolAbs = fr.tolAbs / 2;
|
|
154
|
+
// Push right then left so left is processed first (LIFO)
|
|
155
|
+
stack.push({
|
|
156
|
+
a: m,
|
|
157
|
+
b: b0,
|
|
158
|
+
m: rm,
|
|
159
|
+
fa: fr.fm,
|
|
160
|
+
fm: fRM,
|
|
161
|
+
fb: fr.fb,
|
|
162
|
+
S: Sright,
|
|
163
|
+
depth: nextDepth,
|
|
164
|
+
tolAbs: childTolAbs,
|
|
165
|
+
tolRel: childTolRel,
|
|
166
|
+
singularTries: fr.singularTries,
|
|
167
|
+
});
|
|
168
|
+
stack.push({
|
|
169
|
+
a: a0,
|
|
170
|
+
b: m,
|
|
171
|
+
m: lm,
|
|
172
|
+
fa: fr.fa,
|
|
173
|
+
fm: fLM,
|
|
174
|
+
fb: fr.fm,
|
|
175
|
+
S: Sleft,
|
|
176
|
+
depth: nextDepth,
|
|
177
|
+
tolAbs: childTolAbs,
|
|
178
|
+
tolRel: childTolRel,
|
|
179
|
+
singularTries: fr.singularTries,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return acc * sign;
|
|
183
|
+
}
|
|
184
|
+
// ── Auto-split helper for singular endpoints ─────────────────────────
|
|
185
|
+
function autoSplitFinite(f, a, b, tolAbs, tolRel, maxDepth, maxEvals, singular) {
|
|
186
|
+
const m = (a + b) / 2;
|
|
187
|
+
const q1 = (a + m) / 2;
|
|
188
|
+
const q3 = (m + b) / 2;
|
|
189
|
+
const segTol = tolAbs / 4;
|
|
190
|
+
return (withFiniteBounds(f, a, q1, segTol, tolRel, maxDepth, maxEvals, singular) +
|
|
191
|
+
withFiniteBounds(f, q1, m, segTol, tolRel, maxDepth, maxEvals, singular) +
|
|
192
|
+
withFiniteBounds(f, m, q3, segTol, tolRel, maxDepth, maxEvals, singular) +
|
|
193
|
+
withFiniteBounds(f, q3, b, segTol, tolRel, maxDepth, maxEvals, singular));
|
|
194
|
+
}
|
|
195
|
+
// ── Public API ───────────────────────────────────────────────────────
|
|
196
|
+
/**
|
|
197
|
+
* Definite integral of `f` from `a` to `b` using adaptive Simpson's rule
|
|
198
|
+
* with Richardson extrapolation, native `number` arithmetic.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* // ∫₀^π sin(x) dx = 2
|
|
203
|
+
* definiteIntegrate(Math.sin, 0, Math.PI);
|
|
204
|
+
*
|
|
205
|
+
* // With breakpoints for |x|
|
|
206
|
+
* definiteIntegrate(x => Math.abs(x), -1, 1, { breakpoints: [0] });
|
|
207
|
+
*
|
|
208
|
+
* // Improper integral ∫₁^∞ 1/x² dx = 1
|
|
209
|
+
* definiteIntegrate(x => 1/(x*x), 1, Infinity, { allowInfinite: true });
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
function definiteIntegrateNative(f, a, b, options = {}) {
|
|
213
|
+
if (a === b) {
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
const tolAbs = options.tolAbs ?? DEFAULT_TOL;
|
|
217
|
+
const tolRel = options.tolRel ?? DEFAULT_TOL;
|
|
218
|
+
const maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
219
|
+
const maxEvals = options.maxEvals ?? DEFAULT_MAX_EVALUATIONS;
|
|
220
|
+
const singular = options.singular ?? 'auto';
|
|
221
|
+
const allowInfinite = options.allowInfinite ?? false;
|
|
222
|
+
const isInfA = !isFinite(a) && !isNaN(a);
|
|
223
|
+
const isInfB = !isFinite(b) && !isNaN(b);
|
|
224
|
+
if ((isInfA || isInfB) && !allowInfinite) {
|
|
225
|
+
throw new Error((0, errors_1.message)('defintInfiniteBounds'));
|
|
226
|
+
}
|
|
227
|
+
// ── Infinite-bound substitutions ─────────────────────────────
|
|
228
|
+
if (allowInfinite && (isInfA || isInfB)) {
|
|
229
|
+
// Guard against very small eps clamping to 0 in float64
|
|
230
|
+
const eps = INFINITE_BOUND_ENDPOINT_EPSILON;
|
|
231
|
+
if (!isInfA && isInfB && b > 0) {
|
|
232
|
+
// ∫_a^∞ → t ∈ [0, 1-eps], x = a + t/(1-t), dx = 1/(1-t)²
|
|
233
|
+
const a0 = a;
|
|
234
|
+
const g = t => {
|
|
235
|
+
const u = 1 - t;
|
|
236
|
+
const x = a0 + t / u;
|
|
237
|
+
return f(x) / (u * u);
|
|
238
|
+
};
|
|
239
|
+
return withFiniteBounds(g, 0, 1 - eps, tolAbs, tolRel, maxDepth, maxEvals, singular);
|
|
240
|
+
}
|
|
241
|
+
if (isInfA && a < 0 && !isInfB) {
|
|
242
|
+
// ∫_{-∞}^b → t ∈ [0, 1-eps], x = b - t/(1-t)
|
|
243
|
+
const b0 = b;
|
|
244
|
+
const g = t => {
|
|
245
|
+
const u = 1 - t;
|
|
246
|
+
const x = b0 - t / u;
|
|
247
|
+
return f(x) / (u * u);
|
|
248
|
+
};
|
|
249
|
+
return withFiniteBounds(g, 0, 1 - eps, tolAbs, tolRel, maxDepth, maxEvals, singular);
|
|
250
|
+
}
|
|
251
|
+
if (isInfA && a < 0 && isInfB && b > 0) {
|
|
252
|
+
// ∫_{-∞}^{∞} → t ∈ [eps, 1-eps], x = tan(π(t - ½))
|
|
253
|
+
const g = t => {
|
|
254
|
+
const u = Math.PI * (t - 0.5);
|
|
255
|
+
const cosU = Math.cos(u);
|
|
256
|
+
// dx/dt = π / cos²(u)
|
|
257
|
+
return (f(Math.tan(u)) * Math.PI) / (cosU * cosU);
|
|
258
|
+
};
|
|
259
|
+
return withFiniteBounds(g, eps, 1 - eps, tolAbs, tolRel, maxDepth, maxEvals, singular);
|
|
260
|
+
}
|
|
261
|
+
throw new Error((0, errors_1.message)('defintUnsupportedInfiniteBounds'));
|
|
262
|
+
}
|
|
263
|
+
// ── Finite bounds with optional breakpoints ──────────────────
|
|
264
|
+
const lo = Math.min(a, b);
|
|
265
|
+
const hi = Math.max(a, b);
|
|
266
|
+
const bps = (options.breakpoints ?? []).filter(x => x > lo && x < hi).sort((x, y) => x - y);
|
|
267
|
+
if (bps.length === 0) {
|
|
268
|
+
return withFiniteBounds(f, a, b, tolAbs, tolRel, maxDepth, maxEvals, singular);
|
|
269
|
+
}
|
|
270
|
+
// Segment integration with tolerance budget split across segments
|
|
271
|
+
const nSeg = bps.length + 1;
|
|
272
|
+
const segTolAbs = tolAbs / nSeg;
|
|
273
|
+
// Determine integration direction
|
|
274
|
+
const forward = a <= b;
|
|
275
|
+
const points = forward ? [a, ...bps, b] : [a, ...bps.reverse(), b];
|
|
276
|
+
let total = 0;
|
|
277
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
278
|
+
total += withFiniteBounds(f, points[i], points[i + 1], segTolAbs, tolRel, maxDepth, maxEvals, singular);
|
|
279
|
+
}
|
|
280
|
+
return total;
|
|
281
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function loadMathFunctions(): void;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadMathFunctions = loadMathFunctions;
|
|
4
|
+
const dispatch_1 = require("../core/dispatch");
|
|
5
|
+
const constants_1 = require("../core/classes/parser/constants");
|
|
6
|
+
const evaluate_1 = require("../core/classes/parser/scripting/evaluate");
|
|
7
|
+
const expand_1 = require("../core/functions/expand/expand");
|
|
8
|
+
const subst_1 = require("../core/functions/subst");
|
|
9
|
+
const geometry_1 = require("./geometry");
|
|
10
|
+
const math_1 = require("./math");
|
|
11
|
+
const trig_1 = require("./trig");
|
|
12
|
+
const trunc_1 = require("./trunc");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
function loadMathFunctions() {
|
|
15
|
+
Object.assign(dispatch_1.mathFunctionRegistry, {
|
|
16
|
+
cos: (0, dispatch_1.systemFunction)({ fn: trig_1.cos, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
17
|
+
sin: (0, dispatch_1.systemFunction)({ fn: trig_1.sin, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
18
|
+
tan: (0, dispatch_1.systemFunction)({ fn: trig_1.tan, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
19
|
+
sec: (0, dispatch_1.systemFunction)({ fn: trig_1.sec, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
20
|
+
csc: (0, dispatch_1.systemFunction)({ fn: trig_1.csc, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
21
|
+
cot: (0, dispatch_1.systemFunction)({ fn: trig_1.cot, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
22
|
+
acos: (0, dispatch_1.systemFunction)({ fn: trig_1.acos, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
23
|
+
asin: (0, dispatch_1.systemFunction)({ fn: trig_1.asin, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
24
|
+
atan: (0, dispatch_1.systemFunction)({ fn: trig_1.atan, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
25
|
+
asec: (0, dispatch_1.systemFunction)({ fn: trig_1.asec, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
26
|
+
acsc: (0, dispatch_1.systemFunction)({ fn: trig_1.acsc, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
27
|
+
acot: (0, dispatch_1.systemFunction)({ fn: trig_1.acot, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
28
|
+
atan2: (0, dispatch_1.systemFunction)({ fn: trig_1.atan2, minArgs: 2, maxArgs: 2, distElWise: true }),
|
|
29
|
+
cosh: (0, dispatch_1.systemFunction)({ fn: trig_1.cosh, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
30
|
+
sinh: (0, dispatch_1.systemFunction)({ fn: trig_1.sinh, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
31
|
+
tanh: (0, dispatch_1.systemFunction)({ fn: trig_1.tanh, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
32
|
+
sech: (0, dispatch_1.systemFunction)({ fn: trig_1.sech, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
33
|
+
csch: (0, dispatch_1.systemFunction)({ fn: trig_1.csch, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
34
|
+
coth: (0, dispatch_1.systemFunction)({ fn: trig_1.coth, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
35
|
+
acosh: (0, dispatch_1.systemFunction)({ fn: trig_1.acosh, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
36
|
+
asinh: (0, dispatch_1.systemFunction)({ fn: trig_1.asinh, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
37
|
+
atanh: (0, dispatch_1.systemFunction)({ fn: trig_1.atanh, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
38
|
+
asech: (0, dispatch_1.systemFunction)({ fn: trig_1.asech, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
39
|
+
acsch: (0, dispatch_1.systemFunction)({ fn: trig_1.acsch, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
40
|
+
acoth: (0, dispatch_1.systemFunction)({ fn: trig_1.acoth, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
41
|
+
line: (0, dispatch_1.systemFunction)({ fn: geometry_1.line, minArgs: 2, maxArgs: 3, distElWise: false }),
|
|
42
|
+
abs: (0, dispatch_1.systemFunction)({ fn: math_1.abs, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
43
|
+
sqrt: (0, dispatch_1.systemFunction)({ fn: math_1.sqrt, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
44
|
+
nthroot: (0, dispatch_1.systemFunction)({ fn: math_1.nthroot, minArgs: 2, maxArgs: 2, distElWise: true }),
|
|
45
|
+
cbrt: (0, dispatch_1.systemFunction)({ fn: math_1.cbrt, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
46
|
+
subst: (0, dispatch_1.systemFunction)({ fn: subst_1.subst, minArgs: 3, maxArgs: 3, distElWise: true }),
|
|
47
|
+
log: (0, dispatch_1.systemFunction)({ fn: math_1.log, minArgs: 1, maxArgs: 2, distElWise: true }),
|
|
48
|
+
log10: (0, dispatch_1.systemFunction)({ fn: math_1.log10, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
49
|
+
radians: (0, dispatch_1.systemFunction)({ fn: math_1.radians, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
50
|
+
degrees: (0, dispatch_1.systemFunction)({ fn: math_1.degrees, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
51
|
+
exp: (0, dispatch_1.systemFunction)({ fn: math_1.exp, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
52
|
+
erf: (0, dispatch_1.systemFunction)({ fn: math_1.erf, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
53
|
+
erfc: (0, dispatch_1.systemFunction)({ fn: math_1.erfc, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
54
|
+
gamma: (0, dispatch_1.systemFunction)({ fn: math_1.gamma, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
55
|
+
gamma_incomplete: (0, dispatch_1.systemFunction)({ fn: math_1.gammaIncomplete, minArgs: 2, maxArgs: 2, distElWise: true }),
|
|
56
|
+
gamma_incomplete_lower: (0, dispatch_1.systemFunction)({ fn: math_1.gammaIncompleteLower, minArgs: 2, maxArgs: 2, distElWise: true }),
|
|
57
|
+
[constants_1.DIRAC]: (0, dispatch_1.systemFunction)({ fn: math_1.dirac, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
58
|
+
[constants_1.HEAVISIDE]: (0, dispatch_1.systemFunction)({ fn: math_1.heaviside, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
59
|
+
step: (0, dispatch_1.systemFunction)({ fn: math_1.step, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
60
|
+
rect: (0, dispatch_1.systemFunction)({ fn: math_1.rect, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
61
|
+
tri: (0, dispatch_1.systemFunction)({ fn: math_1.tri, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
62
|
+
continued_fraction: (0, dispatch_1.systemFunction)({ fn: utils_1.continuedFraction, minArgs: 1, maxArgs: 2, distElWise: false }),
|
|
63
|
+
scientific: (0, dispatch_1.systemFunction)({ fn: math_1.scientific, minArgs: 1, maxArgs: 2, distElWise: true }),
|
|
64
|
+
hypot: (0, dispatch_1.systemFunction)({ fn: geometry_1.hypot, minArgs: 2, maxArgs: 2, distElWise: true }),
|
|
65
|
+
[constants_1.FACTORIAL]: (0, dispatch_1.systemFunction)({ fn: math_1.factorial, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
66
|
+
factorial: (0, dispatch_1.systemFunction)({ fn: math_1.factorial, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
67
|
+
[constants_1.DOUBLE_FACTORIAL]: (0, dispatch_1.systemFunction)({ fn: math_1.doubleFactorial, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
68
|
+
expand: (0, dispatch_1.systemFunction)({ fn: expand_1.expand, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
69
|
+
numeric: (0, dispatch_1.systemFunction)({
|
|
70
|
+
fn: evaluate_1.numeric,
|
|
71
|
+
minArgs: 1,
|
|
72
|
+
maxArgs: 2,
|
|
73
|
+
equationArgs: [0],
|
|
74
|
+
distElWise: false,
|
|
75
|
+
deferArguments: true,
|
|
76
|
+
}),
|
|
77
|
+
round: (0, dispatch_1.systemFunction)({ fn: math_1.round, minArgs: 1, maxArgs: 2, distElWise: true }),
|
|
78
|
+
sign: (0, dispatch_1.systemFunction)({ fn: math_1.sign, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
79
|
+
floor: (0, dispatch_1.systemFunction)({ fn: math_1.floor, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
80
|
+
ceil: (0, dispatch_1.systemFunction)({ fn: math_1.ceiling, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
81
|
+
ceiling: (0, dispatch_1.systemFunction)({ fn: math_1.ceiling, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
82
|
+
trunc: (0, dispatch_1.systemFunction)({ fn: trunc_1.trunc, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
83
|
+
mod: (0, dispatch_1.systemFunction)({ fn: math_1.mod, minArgs: 2, maxArgs: 2, distElWise: true }),
|
|
84
|
+
modinv: (0, dispatch_1.systemFunction)({ fn: math_1.modInv, minArgs: 2, maxArgs: 2, distElWise: true }),
|
|
85
|
+
parens: (0, dispatch_1.systemFunction)({ fn: math_1.parens, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
86
|
+
count: (0, dispatch_1.systemFunction)({ fn: utils_1.count, minArgs: 1, maxArgs: 1, distElWise: false }),
|
|
87
|
+
size: (0, dispatch_1.systemFunction)({ fn: utils_1.size, minArgs: 1, maxArgs: 1, distElWise: false }),
|
|
88
|
+
contains: (0, dispatch_1.systemFunction)({ fn: math_1.contains, minArgs: 2, maxArgs: 2, distElWise: false }),
|
|
89
|
+
max: (0, dispatch_1.systemFunction)({ fn: math_1.max, minArgs: 2, maxArgs: -1, distElWise: true }),
|
|
90
|
+
min: (0, dispatch_1.systemFunction)({ fn: math_1.min, minArgs: 2, maxArgs: -1, distElWise: true }),
|
|
91
|
+
isprime: (0, dispatch_1.systemFunction)({ fn: utils_1.isprime, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
92
|
+
fib: (0, dispatch_1.systemFunction)({ fn: math_1.fibonacci, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
93
|
+
sinc: (0, dispatch_1.systemFunction)({ fn: math_1.sinc, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
94
|
+
Shi: (0, dispatch_1.systemFunction)({ fn: math_1.Shi, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
95
|
+
Si: (0, dispatch_1.systemFunction)({ fn: math_1.Si, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
96
|
+
Chi: (0, dispatch_1.systemFunction)({ fn: math_1.Chi, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
97
|
+
Ci: (0, dispatch_1.systemFunction)({ fn: math_1.Ci, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
98
|
+
Ei: (0, dispatch_1.systemFunction)({ fn: math_1.Ei, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
99
|
+
[constants_1.LI]: (0, dispatch_1.systemFunction)({ fn: math_1.Li, minArgs: 1, maxArgs: 1, distElWise: true }),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Expression } from '../core/classes/expression/Expression';
|
|
2
|
+
import type { Vector } from '../core/classes/vector/Vector';
|
|
3
|
+
import type { ExpressionInput } from '../core/types';
|
|
4
|
+
/**
|
|
5
|
+
* Returns the symbolic hypotenuse of two expressions.
|
|
6
|
+
*
|
|
7
|
+
* Matching linear sine and cosine terms collapse through the Pythagorean identity;
|
|
8
|
+
* otherwise the result is the principal square root of the sum of squares.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hypot(a: Expression, b: Expression): Expression;
|
|
11
|
+
/** Returns the line through two two-dimensional points, evaluated at `dimension`. */
|
|
12
|
+
export declare function line(p1: Vector, p2: Vector, dimension?: ExpressionInput): Expression;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hypot = hypot;
|
|
4
|
+
exports.line = line;
|
|
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
|
+
const add_1 = require("../core/classes/parser/operations/add");
|
|
9
|
+
const power_1 = require("../core/classes/parser/operations/power");
|
|
10
|
+
const errors_1 = require("../core/errors");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the symbolic hypotenuse of two expressions.
|
|
13
|
+
*
|
|
14
|
+
* Matching linear sine and cosine terms collapse through the Pythagorean identity;
|
|
15
|
+
* otherwise the result is the principal square root of the sum of squares.
|
|
16
|
+
*/
|
|
17
|
+
function hypot(a, b) {
|
|
18
|
+
const fns = [constants_1.SIN, constants_1.COS];
|
|
19
|
+
let retval;
|
|
20
|
+
if (a.isFunction(fns) &&
|
|
21
|
+
b.isFunction(fns) &&
|
|
22
|
+
a.name !== b.name &&
|
|
23
|
+
a.isLinear() &&
|
|
24
|
+
b.isLinear() &&
|
|
25
|
+
a.getMultiplier().eq(b.getMultiplier())) {
|
|
26
|
+
retval = Expression_1.Expression.fromRational(a.getMultiplier());
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const aSquared = (0, power_1.power)(a, (0, shortcuts_1.two)());
|
|
30
|
+
const bSquared = (0, power_1.power)(b, (0, shortcuts_1.two)());
|
|
31
|
+
retval = (0, power_1.power)((0, add_1.add)(aSquared, bSquared), (0, shortcuts_1.half)());
|
|
32
|
+
}
|
|
33
|
+
return retval;
|
|
34
|
+
}
|
|
35
|
+
/** Returns the line through two two-dimensional points, evaluated at `dimension`. */
|
|
36
|
+
function line(p1, p2, dimension = 'x') {
|
|
37
|
+
if (!p1 || !p2 || p1.dataType !== constants_1.VECTOR || p2.dataType !== constants_1.VECTOR || p1.count() !== 2 || p2.count() !== 2) {
|
|
38
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: 'line' }));
|
|
39
|
+
}
|
|
40
|
+
const x1 = p1.elements[0];
|
|
41
|
+
const y1 = p1.elements[1];
|
|
42
|
+
const x2 = p2.elements[0];
|
|
43
|
+
const y2 = p2.elements[1];
|
|
44
|
+
if (!Expression_1.Expression.isExpression(x1) ||
|
|
45
|
+
!Expression_1.Expression.isExpression(y1) ||
|
|
46
|
+
!Expression_1.Expression.isExpression(x2) ||
|
|
47
|
+
!Expression_1.Expression.isExpression(y2)) {
|
|
48
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('wrongInput', {
|
|
49
|
+
expected: 'two-dimensional vectors of scalar expressions',
|
|
50
|
+
received: `${p1.text()}, ${p2.text()}`,
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
const variable = Expression_1.Expression.create(dimension);
|
|
54
|
+
return y1.plus(y2.minus(y1).div(x2.minus(x1)).times(variable.minus(x1)));
|
|
55
|
+
}
|