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,42 @@
|
|
|
1
|
+
import { Expression } from '../../classes/expression/Expression';
|
|
2
|
+
export declare function powerExpandToArray(variables: string[], power: number): any[][];
|
|
3
|
+
/**
|
|
4
|
+
* Converts an array of number[] back to its expression form. Given a set of arrays in
|
|
5
|
+
* the form [[1,1,2], [2,0,1]] and the variables [a, b] it gets converted back to
|
|
6
|
+
* a*b*2 + (a)^2. At the time of this documentation the brackets are always added for power > 1
|
|
7
|
+
*
|
|
8
|
+
* @param row
|
|
9
|
+
* @param variables
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function expandArrayToExpression(row: number[][], variables: string[], multiplier?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Checks to see if a sum or product is expandable.
|
|
15
|
+
*
|
|
16
|
+
* @param x
|
|
17
|
+
*/
|
|
18
|
+
export declare function isExpandable(x: Expression): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Expands the Expression with integer powers > 1. It does this by first flattening out the expression.
|
|
21
|
+
* The multiplier and power then become one. This enables us to focus on expanding the power by using
|
|
22
|
+
* integers. So give (x*y+z*y^6)^2 we substitute x*y for 1*($1)^1 and z*y^6 for 1*($2)^1. We then end up with
|
|
23
|
+
* 1*($1)^2 + 2*($1*$2)^1 + 1*($2)^2 after which we back substitute to get 1*(x*y)^2 + 2*(x*y*z*y^6)^1 + 1*(z*y^6)^2
|
|
24
|
+
* and run it through the parser for evaluation.
|
|
25
|
+
*
|
|
26
|
+
* @param x
|
|
27
|
+
*/
|
|
28
|
+
export declare function powerExpand(x: Expression): Expression;
|
|
29
|
+
/**
|
|
30
|
+
* Performs multiplication but expands out the sum.
|
|
31
|
+
*
|
|
32
|
+
* @param x
|
|
33
|
+
* @param y
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare function sumExpandMultiply(x: Expression, y: Expression): Expression;
|
|
37
|
+
/**
|
|
38
|
+
* Expands the function by distributing the power and the multiplier whenever possible
|
|
39
|
+
*
|
|
40
|
+
* @param x
|
|
41
|
+
*/
|
|
42
|
+
export declare function expand(x: Expression): Expression;
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.powerExpandToArray = powerExpandToArray;
|
|
4
|
+
exports.expandArrayToExpression = expandArrayToExpression;
|
|
5
|
+
exports.isExpandable = isExpandable;
|
|
6
|
+
exports.powerExpand = powerExpand;
|
|
7
|
+
exports.sumExpandMultiply = sumExpandMultiply;
|
|
8
|
+
exports.expand = expand;
|
|
9
|
+
const Expression_1 = require("../../classes/expression/Expression");
|
|
10
|
+
const shortcuts_1 = require("../../classes/expression/shortcuts");
|
|
11
|
+
const constants_1 = require("../../classes/parser/constants");
|
|
12
|
+
function powerExpandToArray(variables, power) {
|
|
13
|
+
/**
|
|
14
|
+
* The row will take on the form of [a_power, b_power, ..., coeff]. The polynomial gets
|
|
15
|
+
* flattened so we'll disregard their powers. We'll let the parser handle that at a later point.
|
|
16
|
+
* So x^2 + x*y become two flat variables with the value x^2 and x*y but for this example let's
|
|
17
|
+
* think of a & b. Since the variable is flattened each "term" becomes [0, 0, 1]. We'll construct
|
|
18
|
+
* a table multiplying out the row and column. For the first iteration the column = row. Our table
|
|
19
|
+
* becomes something like this
|
|
20
|
+
* +---+----+----+
|
|
21
|
+
* | | a | b |
|
|
22
|
+
* +---+----+----+
|
|
23
|
+
* | a | aa | ba |
|
|
24
|
+
* | b | ab | bb |
|
|
25
|
+
* +---+----+----+
|
|
26
|
+
*/
|
|
27
|
+
// Constructs the row. You get back the array with zeros and a coefficient of one at the end
|
|
28
|
+
// Given the expression (a+b) becomes [[0,0,1], [0,0,1]] where representing[[power a, power b, coeff a], [power a, power b, coeff b]]
|
|
29
|
+
// The powers for each term are zero since they're just the value 1
|
|
30
|
+
function constructRow() {
|
|
31
|
+
return variables.map((x, i) => {
|
|
32
|
+
const row = new Array(variables.length).fill(0);
|
|
33
|
+
row.push(1);
|
|
34
|
+
row[i] = 1;
|
|
35
|
+
return row;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// We now perform piecewise multiplication incrementing the power each time like values are multiplied.
|
|
39
|
+
let row = constructRow();
|
|
40
|
+
for (let n = 0; n < power - 1; n++) {
|
|
41
|
+
const result = [];
|
|
42
|
+
for (let i = 0; i < row.length; i++) {
|
|
43
|
+
for (let j = 0; j < variables.length; j++) {
|
|
44
|
+
const term = [...row[i]];
|
|
45
|
+
term[j]++;
|
|
46
|
+
result.push(term);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const sumMap = new Map();
|
|
50
|
+
for (const term of result) {
|
|
51
|
+
const key = term.slice(0, -1).join(',');
|
|
52
|
+
const existing = sumMap.get(key);
|
|
53
|
+
if (existing) {
|
|
54
|
+
existing[existing.length - 1] += term[term.length - 1];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
sumMap.set(key, [...term]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
row = Array.from(sumMap.values());
|
|
61
|
+
}
|
|
62
|
+
return row;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Converts an array of number[] back to its expression form. Given a set of arrays in
|
|
66
|
+
* the form [[1,1,2], [2,0,1]] and the variables [a, b] it gets converted back to
|
|
67
|
+
* a*b*2 + (a)^2. At the time of this documentation the brackets are always added for power > 1
|
|
68
|
+
*
|
|
69
|
+
* @param row
|
|
70
|
+
* @param variables
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
function expandArrayToExpression(row, variables, multiplier) {
|
|
74
|
+
const termsArray = [];
|
|
75
|
+
// Put the multiplication in front of the multiplier if provided
|
|
76
|
+
const m = multiplier ? `${multiplier}*` : '';
|
|
77
|
+
for (let i = 0; i < row.length; i++) {
|
|
78
|
+
const term = row[i];
|
|
79
|
+
const varStringArray = [];
|
|
80
|
+
// We skip the last element since that's the coefficient
|
|
81
|
+
for (let j = 0; j < term.length - 1; j++) {
|
|
82
|
+
const variable = variables[j];
|
|
83
|
+
const p = term[j];
|
|
84
|
+
if (p === 1) {
|
|
85
|
+
varStringArray.push(`(${variable})`);
|
|
86
|
+
}
|
|
87
|
+
else if (p !== 0) {
|
|
88
|
+
varStringArray.push(`(${variable})^${p}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
let termsString = varStringArray.join('*');
|
|
92
|
+
const coeff = term[term.length - 1];
|
|
93
|
+
if (coeff !== 1) {
|
|
94
|
+
termsString = `(${coeff})*${termsString}`;
|
|
95
|
+
}
|
|
96
|
+
termsArray.push(m + termsString);
|
|
97
|
+
}
|
|
98
|
+
return termsArray.join('+');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Checks to see if a sum or product is expandable.
|
|
102
|
+
*
|
|
103
|
+
* @param x
|
|
104
|
+
*/
|
|
105
|
+
function isExpandable(x) {
|
|
106
|
+
return x.isComplex() || !x.getMultiplier().isOne() || x.value.includes('(') || !x.isLinear();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Expands the Expression with integer powers > 1. It does this by first flattening out the expression.
|
|
110
|
+
* The multiplier and power then become one. This enables us to focus on expanding the power by using
|
|
111
|
+
* integers. So give (x*y+z*y^6)^2 we substitute x*y for 1*($1)^1 and z*y^6 for 1*($2)^1. We then end up with
|
|
112
|
+
* 1*($1)^2 + 2*($1*$2)^1 + 1*($2)^2 after which we back substitute to get 1*(x*y)^2 + 2*(x*y*z*y^6)^1 + 1*(z*y^6)^2
|
|
113
|
+
* and run it through the parser for evaluation.
|
|
114
|
+
*
|
|
115
|
+
* @param x
|
|
116
|
+
*/
|
|
117
|
+
function powerExpand(x) {
|
|
118
|
+
let retval = x;
|
|
119
|
+
if (x.isSum() && x.getPower().isInteger()) {
|
|
120
|
+
const sgn = x.getPower().sign();
|
|
121
|
+
const power = x.getPower().abs();
|
|
122
|
+
const variables = x.elementsArray().map(e => {
|
|
123
|
+
return e.text();
|
|
124
|
+
});
|
|
125
|
+
const multiplier = x.getMultiplier().isOne()
|
|
126
|
+
? undefined
|
|
127
|
+
: (sgn < 0 ? x.getMultiplier().invert() : x.getMultiplier()).text();
|
|
128
|
+
const termsArray = powerExpandToArray(variables, Number(power));
|
|
129
|
+
const expression = expandArrayToExpression(termsArray, variables, multiplier);
|
|
130
|
+
retval = Expression_1.Expression.create(expression);
|
|
131
|
+
if (sgn === -1) {
|
|
132
|
+
retval = retval.invert();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return retval;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Performs multiplication but expands out the sum.
|
|
139
|
+
*
|
|
140
|
+
* @param x
|
|
141
|
+
* @param y
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
function sumExpandMultiply(x, y) {
|
|
145
|
+
// Expand both
|
|
146
|
+
let retval;
|
|
147
|
+
if (y.isSum() && !x.isSum()) {
|
|
148
|
+
retval = sumExpandMultiply(y, x);
|
|
149
|
+
}
|
|
150
|
+
// Expand but only if the power is one
|
|
151
|
+
else if (x.isSum()) {
|
|
152
|
+
if (!x.isLinear()) {
|
|
153
|
+
// Expand if the power is not one.
|
|
154
|
+
x = powerExpand(x);
|
|
155
|
+
}
|
|
156
|
+
// Expand if expandable
|
|
157
|
+
if (x.isLinear()) {
|
|
158
|
+
retval = (0, shortcuts_1.zero)();
|
|
159
|
+
x.each(element => {
|
|
160
|
+
if (isExpandable(element)) {
|
|
161
|
+
element = expand(element);
|
|
162
|
+
}
|
|
163
|
+
// If either is a sum then call this function recursively
|
|
164
|
+
if (y.isSum() || element.isSum()) {
|
|
165
|
+
retval = retval.plus(sumExpandMultiply(y, element));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const result = y.times(element);
|
|
169
|
+
retval = retval.plus(result);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// Since it turns out that x is not expandable likely due to it being under the denominator,
|
|
174
|
+
// we can try to see if y is expandable. We send it back to sumExpandMultiply.
|
|
175
|
+
// Only swap if y is linear to avoid infinite ping-pong between two non-linear sums.
|
|
176
|
+
else if (y.isSum() && y.isLinear()) {
|
|
177
|
+
retval = sumExpandMultiply(y, x);
|
|
178
|
+
}
|
|
179
|
+
// Since x cannot be expanded and y is not a linear sum, then multiply and return
|
|
180
|
+
else {
|
|
181
|
+
retval = x.times(y);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
retval = expand(x).times(expand(y));
|
|
186
|
+
}
|
|
187
|
+
return retval;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Expands the product of expressions. The power gets distributed when expanding.
|
|
191
|
+
*
|
|
192
|
+
* @param x
|
|
193
|
+
* @returns
|
|
194
|
+
*/
|
|
195
|
+
function productExpand(x) {
|
|
196
|
+
/*
|
|
197
|
+
* Only expand if needed. This eliminates unnecessary multiplication. Note this this is not an all inclusive tests and contains false positives.
|
|
198
|
+
* In that case it will just be a wasted effort. The test is performed against x value instead of x.text().
|
|
199
|
+
* Test to see if:
|
|
200
|
+
* - It has a element with an integer power.
|
|
201
|
+
* - It has a scoped multiplier
|
|
202
|
+
* - Contains a sum
|
|
203
|
+
*/
|
|
204
|
+
// We start with the multiplier
|
|
205
|
+
let retval;
|
|
206
|
+
retval = Expression_1.Expression.fromRational(x.getMultiplier());
|
|
207
|
+
// Store the power
|
|
208
|
+
const pow = x.getPower();
|
|
209
|
+
// Store the check to see if the power is one. If it is then don't raise it
|
|
210
|
+
const powIsOne = pow.isOne();
|
|
211
|
+
// Loop through the remaining elements
|
|
212
|
+
x.each(element => {
|
|
213
|
+
// The power does not equal one then raise it to that power
|
|
214
|
+
if (!powIsOne) {
|
|
215
|
+
element = element.pow(pow);
|
|
216
|
+
}
|
|
217
|
+
// Unwrap the elements
|
|
218
|
+
element = unwrap(element);
|
|
219
|
+
// Expand it if expandable
|
|
220
|
+
// if(isExpandable(element)) {
|
|
221
|
+
element = expand(element);
|
|
222
|
+
// }
|
|
223
|
+
// Store the power
|
|
224
|
+
const power = element.getPower();
|
|
225
|
+
// If it's a product with a power != 1 then expand otherwise just put it back
|
|
226
|
+
if (element.isProduct() && power.isInteger() && !power.isOne()) {
|
|
227
|
+
element.each(subElement => {
|
|
228
|
+
retval = retval.times(subElement.pow(power));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
// retval may have been multiplied out and become a sum at this point so we need to check
|
|
232
|
+
// if retval or the element is a sum
|
|
233
|
+
else if (retval.isSum() || element.isSum()) {
|
|
234
|
+
retval = sumExpandMultiply(retval, element);
|
|
235
|
+
}
|
|
236
|
+
// Otherwise just multiply it out but to check if it's expandable first
|
|
237
|
+
else {
|
|
238
|
+
retval = retval.times(element);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
return retval;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Expands each term of the sum. Expects a fully expanded sum
|
|
245
|
+
*
|
|
246
|
+
* @param x
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
249
|
+
function expandTerms(x) {
|
|
250
|
+
// Only expand into individual terms if the sum has power 1.
|
|
251
|
+
// For non-linear sums like (b^2-4*a)^(1/2), we must preserve the outer power.
|
|
252
|
+
if (!x.isLinear()) {
|
|
253
|
+
return x;
|
|
254
|
+
}
|
|
255
|
+
let retval = (0, shortcuts_1.zero)();
|
|
256
|
+
x.each(e => {
|
|
257
|
+
retval = retval.plus(expand(e));
|
|
258
|
+
});
|
|
259
|
+
return retval;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Removes the expression from the `parens` function
|
|
263
|
+
* @param x
|
|
264
|
+
* @returns
|
|
265
|
+
*/
|
|
266
|
+
function unwrap(x) {
|
|
267
|
+
if (x.isFunction(constants_1.WRAP)) {
|
|
268
|
+
const arg = x.getArguments()[0].pow(x.getPower()).times(x.getMultiplier());
|
|
269
|
+
return arg;
|
|
270
|
+
}
|
|
271
|
+
return x;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Expands factorials in the form of (an+m)!
|
|
275
|
+
* @param x
|
|
276
|
+
* @returns
|
|
277
|
+
*/
|
|
278
|
+
function factorialExpand(x) {
|
|
279
|
+
const args = x.getArguments();
|
|
280
|
+
let retval = x;
|
|
281
|
+
const argElements = args[0].elementsArray().sort((a, _b) => {
|
|
282
|
+
if (a.isNUM()) {
|
|
283
|
+
return 1;
|
|
284
|
+
}
|
|
285
|
+
return -1;
|
|
286
|
+
});
|
|
287
|
+
if (argElements.length === 2) {
|
|
288
|
+
const a = argElements[0];
|
|
289
|
+
const b = argElements[1];
|
|
290
|
+
if (a.isVAR() && a.isLinear() && b.isInteger()) {
|
|
291
|
+
const p = x.getPower();
|
|
292
|
+
const iterations = Number(b.getMultiplier().numerator);
|
|
293
|
+
// Start with the base factorial: fact(a) e.g., fact(2*n)
|
|
294
|
+
const baseFact = Expression_1.Expression.toFunction(constants_1.FACTORIAL, [a]);
|
|
295
|
+
retval = baseFact;
|
|
296
|
+
// Multiply by (a+1) * (a+2) * ... * (a+b)
|
|
297
|
+
// NOT by fact(a+1) * fact(a+2) * ...
|
|
298
|
+
for (let i = 1; i <= iterations; i++) {
|
|
299
|
+
const term = a.plus(i); // (2n+1), (2n+2), etc.
|
|
300
|
+
retval = retval.times(term); // multiply by the term, not its factorial
|
|
301
|
+
}
|
|
302
|
+
retval = retval.pow(p);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
let t = Expression_1.Expression.toFunction(retval.name, args);
|
|
306
|
+
t.multiplier = retval.multiplier;
|
|
307
|
+
t = Expression_1.Expression.setPower(t, retval.getPower());
|
|
308
|
+
retval = t;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
let t = Expression_1.Expression.toFunction(retval.name, args);
|
|
313
|
+
t.multiplier = retval.multiplier;
|
|
314
|
+
t = Expression_1.Expression.setPower(t, retval.getPower());
|
|
315
|
+
retval = t;
|
|
316
|
+
}
|
|
317
|
+
return retval;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Expands the function by distributing the power and the multiplier whenever possible
|
|
321
|
+
*
|
|
322
|
+
* @param x
|
|
323
|
+
*/
|
|
324
|
+
function expand(x) {
|
|
325
|
+
let retval;
|
|
326
|
+
x = unwrap(x);
|
|
327
|
+
if (isExpandable(x)) {
|
|
328
|
+
if (x.isNUM() || x.isVAR()) {
|
|
329
|
+
retval = new Expression_1.Expression(x);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
// At the very least the multiplier must be distributed along the expression
|
|
333
|
+
retval = x.distributeMultiplier();
|
|
334
|
+
// First expand the power if it's a GRP or SUM
|
|
335
|
+
if (retval.isSum()) {
|
|
336
|
+
// First expand each term
|
|
337
|
+
retval = powerExpand(retval);
|
|
338
|
+
if (retval.isSum()) {
|
|
339
|
+
retval = expandTerms(retval);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Expand products
|
|
343
|
+
if (retval.isProduct()) {
|
|
344
|
+
retval = productExpand(retval);
|
|
345
|
+
}
|
|
346
|
+
// Expand arguments
|
|
347
|
+
if (retval.isFunction()) {
|
|
348
|
+
// Just parse it. This can probably be more efficient
|
|
349
|
+
const args = retval.getArguments().map(x => {
|
|
350
|
+
return expand(x);
|
|
351
|
+
});
|
|
352
|
+
if (retval.name === constants_1.FACTORIAL) {
|
|
353
|
+
retval = factorialExpand(retval);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
let t = Expression_1.Expression.toFunction(retval.name, args);
|
|
357
|
+
// Copy over the power and multiplier
|
|
358
|
+
t.multiplier = retval.multiplier;
|
|
359
|
+
t = Expression_1.Expression.setPower(t, retval.getPower());
|
|
360
|
+
retval = t;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (retval.isEXP()) {
|
|
364
|
+
const pow = expand(retval.getPower());
|
|
365
|
+
const expression = expand(retval.getBase());
|
|
366
|
+
const t = expression.pow(pow);
|
|
367
|
+
t.multiplier = t.getMultiplier().times(retval.getMultiplier());
|
|
368
|
+
retval = t;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
retval = new Expression_1.Expression(x);
|
|
374
|
+
}
|
|
375
|
+
return retval;
|
|
376
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluates the normalized Fresnel integrals with JavaScript-number arithmetic.
|
|
3
|
+
*
|
|
4
|
+
* Moderate arguments use adaptive Simpson integration over short segments. Large
|
|
5
|
+
* arguments use the standard asymptotic expansions, avoiding excessive work as
|
|
6
|
+
* the integrand becomes increasingly oscillatory.
|
|
7
|
+
*/
|
|
8
|
+
export declare function fresnelIntegral(x: number, sine: number): number;
|
|
9
|
+
/** Numerical Fresnel sine integral for compiled expressions. */
|
|
10
|
+
export declare function fresnelS(x: number): number;
|
|
11
|
+
/** Numerical Fresnel cosine integral for compiled expressions. */
|
|
12
|
+
export declare function fresnelC(x: number): number;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fresnelIntegral = fresnelIntegral;
|
|
4
|
+
exports.fresnelS = fresnelS;
|
|
5
|
+
exports.fresnelC = fresnelC;
|
|
6
|
+
/**
|
|
7
|
+
* Evaluates the normalized Fresnel integrals with JavaScript-number arithmetic.
|
|
8
|
+
*
|
|
9
|
+
* Moderate arguments use adaptive Simpson integration over short segments. Large
|
|
10
|
+
* arguments use the standard asymptotic expansions, avoiding excessive work as
|
|
11
|
+
* the integrand becomes increasingly oscillatory.
|
|
12
|
+
*/
|
|
13
|
+
function fresnelIntegral(x, sine) {
|
|
14
|
+
const ASYMPTOTIC_CUTOFF = 8;
|
|
15
|
+
const ASYMPTOTIC_F_COEFFICIENTS = [1, -3, 105, -10395];
|
|
16
|
+
const ASYMPTOTIC_G_COEFFICIENTS = [1, -15, 945, -135135];
|
|
17
|
+
const HALF = 0.5;
|
|
18
|
+
const INTEGRATION_TOLERANCE = 1e-13;
|
|
19
|
+
const MAX_DEPTH = 20;
|
|
20
|
+
const SEGMENTS_PER_UNIT = 2;
|
|
21
|
+
const SIMPSON_DIVISOR = 6;
|
|
22
|
+
const SIMPSON_ERROR_FACTOR = 15;
|
|
23
|
+
const SIMPSON_MIDDLE_WEIGHT = 4;
|
|
24
|
+
let retval;
|
|
25
|
+
if (Number.isNaN(x)) {
|
|
26
|
+
retval = NaN;
|
|
27
|
+
}
|
|
28
|
+
else if (!Number.isFinite(x)) {
|
|
29
|
+
retval = Math.sign(x) * HALF;
|
|
30
|
+
}
|
|
31
|
+
else if (x === 0) {
|
|
32
|
+
retval = 0;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const sign = x < 0 ? -1 : 1;
|
|
36
|
+
x = Math.abs(x);
|
|
37
|
+
const phase = Math.PI * x * x * HALF;
|
|
38
|
+
const useSine = sine !== 0;
|
|
39
|
+
if (x >= ASYMPTOTIC_CUTOFF) {
|
|
40
|
+
const t = 1 / (Math.PI * Math.PI * x ** 4);
|
|
41
|
+
const [f0, f1, f2, f3] = ASYMPTOTIC_F_COEFFICIENTS;
|
|
42
|
+
const [g0, g1, g2, g3] = ASYMPTOTIC_G_COEFFICIENTS;
|
|
43
|
+
const f = (f0 + f1 * t + f2 * t ** 2 + f3 * t ** 3) / (Math.PI * x);
|
|
44
|
+
const g = (g0 + g1 * t + g2 * t ** 2 + g3 * t ** 3) / (Math.PI ** 2 * x ** 3);
|
|
45
|
+
const value = useSine
|
|
46
|
+
? HALF - f * Math.cos(phase) - g * Math.sin(phase)
|
|
47
|
+
: HALF + f * Math.sin(phase) - g * Math.cos(phase);
|
|
48
|
+
retval = sign * value;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const fn = useSine
|
|
52
|
+
? (value) => Math.sin(Math.PI * value * value * HALF)
|
|
53
|
+
: (value) => Math.cos(Math.PI * value * value * HALF);
|
|
54
|
+
const segments = Math.max(1, Math.ceil(x * SEGMENTS_PER_UNIT));
|
|
55
|
+
let total = 0;
|
|
56
|
+
let a = 0;
|
|
57
|
+
for (let segment = 0; segment < segments; segment++) {
|
|
58
|
+
const b = (x * (segment + 1)) / segments;
|
|
59
|
+
const midpoint = (a + b) * HALF;
|
|
60
|
+
const fa = fn(a);
|
|
61
|
+
const fm = fn(midpoint);
|
|
62
|
+
const fb = fn(b);
|
|
63
|
+
const whole = ((b - a) / SIMPSON_DIVISOR) *
|
|
64
|
+
(fa + SIMPSON_MIDDLE_WEIGHT * fm + fb);
|
|
65
|
+
const stack = [
|
|
66
|
+
[a, b, fa, fm, fb, whole, 0],
|
|
67
|
+
];
|
|
68
|
+
while (stack.length > 0) {
|
|
69
|
+
const frame = stack.pop();
|
|
70
|
+
const [left, right, fLeft, fMiddle, fRight, previous, depth] = frame;
|
|
71
|
+
const middle = (left + right) * HALF;
|
|
72
|
+
const leftMiddle = (left + middle) * HALF;
|
|
73
|
+
const rightMiddle = (middle + right) * HALF;
|
|
74
|
+
const fLeftMiddle = fn(leftMiddle);
|
|
75
|
+
const fRightMiddle = fn(rightMiddle);
|
|
76
|
+
const leftIntegral = ((middle - left) / SIMPSON_DIVISOR) *
|
|
77
|
+
(fLeft + SIMPSON_MIDDLE_WEIGHT * fLeftMiddle + fMiddle);
|
|
78
|
+
const rightIntegral = ((right - middle) / SIMPSON_DIVISOR) *
|
|
79
|
+
(fMiddle + SIMPSON_MIDDLE_WEIGHT * fRightMiddle + fRight);
|
|
80
|
+
const refined = leftIntegral + rightIntegral;
|
|
81
|
+
if (depth >= MAX_DEPTH ||
|
|
82
|
+
Math.abs(refined - previous) <=
|
|
83
|
+
(SIMPSON_ERROR_FACTOR * INTEGRATION_TOLERANCE) / segments) {
|
|
84
|
+
total += refined + (refined - previous) / SIMPSON_ERROR_FACTOR;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
stack.push([
|
|
88
|
+
middle,
|
|
89
|
+
right,
|
|
90
|
+
fMiddle,
|
|
91
|
+
fRightMiddle,
|
|
92
|
+
fRight,
|
|
93
|
+
rightIntegral,
|
|
94
|
+
depth + 1,
|
|
95
|
+
]);
|
|
96
|
+
stack.push([
|
|
97
|
+
left,
|
|
98
|
+
middle,
|
|
99
|
+
fLeft,
|
|
100
|
+
fLeftMiddle,
|
|
101
|
+
fMiddle,
|
|
102
|
+
leftIntegral,
|
|
103
|
+
depth + 1,
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
a = b;
|
|
108
|
+
}
|
|
109
|
+
retval = sign * total;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return retval;
|
|
113
|
+
}
|
|
114
|
+
/** Numerical Fresnel sine integral for compiled expressions. */
|
|
115
|
+
function fresnelS(x) {
|
|
116
|
+
const retval = fresnelIntegral(x, 1);
|
|
117
|
+
return retval;
|
|
118
|
+
}
|
|
119
|
+
/** Numerical Fresnel cosine integral for compiled expressions. */
|
|
120
|
+
function fresnelC(x) {
|
|
121
|
+
const retval = fresnelIntegral(x, 0);
|
|
122
|
+
return retval;
|
|
123
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
declare const EULER_GAMMA = 0.5772156649015329;
|
|
2
|
+
export { EULER_GAMMA };
|
|
3
|
+
/**
|
|
4
|
+
* Computes factorial values with JavaScript-number arithmetic for compiled expressions.
|
|
5
|
+
*
|
|
6
|
+
* Non-integers use the gamma extension. Negative or unsafe integers return `NaN`, and
|
|
7
|
+
* sufficiently large positive integers naturally overflow to `Infinity`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function factorial(x: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* The gammaLN function which is used to compute the gamma function
|
|
12
|
+
* Ported from: https://www.mrob.com/pub/ries/lanczos-gamma.html
|
|
13
|
+
*
|
|
14
|
+
* @param x
|
|
15
|
+
*/
|
|
16
|
+
export declare function gammaLN(z: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* The gamma function
|
|
19
|
+
*
|
|
20
|
+
* @param z
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function gamma(z: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* The complementary error function
|
|
26
|
+
* https://en.wikipedia.org/wiki/Error_function
|
|
27
|
+
*
|
|
28
|
+
* @param x
|
|
29
|
+
*/
|
|
30
|
+
export declare function erfc(x: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* The numeric error function
|
|
33
|
+
*
|
|
34
|
+
* @param x
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare function erf(x: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Computes the Euclidean GCD of JavaScript safe integers for numerical compilation.
|
|
40
|
+
*
|
|
41
|
+
* This is the small native-number helper used by `buildFunction`; it is separate from
|
|
42
|
+
* Nerdamer's symbolic polynomial GCD implementation. Non-safe-integer inputs return `NaN`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function GCD(...args: number[]): number;
|
|
45
|
+
/**
|
|
46
|
+
* A utility function to check if a number is an integer
|
|
47
|
+
*
|
|
48
|
+
* @param x
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
export declare function isInt(x: number): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Computes the double factorial using JavaScript-number arithmetic.
|
|
54
|
+
*
|
|
55
|
+
* Non-negative integer inputs use the finite product directly. Non-integers follow
|
|
56
|
+
* the same gamma-based extension used by the symbolic implementation. Negative or
|
|
57
|
+
* unsafe integer inputs return `NaN`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function doubleFactorial(x: number): number;
|
|
60
|
+
/**
|
|
61
|
+
* Computes an LCM while the exact integer result remains representable as a safe number.
|
|
62
|
+
* Inputs or results outside that range return `NaN`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function LCM(...args: number[]): number;
|
|
65
|
+
/** Computes the modular multiplicative inverse for integer JavaScript numbers. */
|
|
66
|
+
export declare function modInv(a: number, p: number): number;
|
|
67
|
+
/** Returns `1` for a prime safe integer and `0` otherwise. */
|
|
68
|
+
export declare function isPrime(x: number): 0 | 1;
|
|
69
|
+
/** Numeric half-maximum convention for the Heaviside step function. */
|
|
70
|
+
export declare function heaviside(x: number): number;
|
|
71
|
+
/**
|
|
72
|
+
* Rounds a number to n digits
|
|
73
|
+
* @param x The number to be rounded
|
|
74
|
+
* @param s The number of digits to round to
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
export declare function round(x: number, n?: number): number;
|
|
78
|
+
/**
|
|
79
|
+
* Multiplies an array of numbers
|
|
80
|
+
*
|
|
81
|
+
* @param args
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
export declare function product(...args: number[]): number;
|
|
85
|
+
/**
|
|
86
|
+
* Gets the product given a number range start and finish
|
|
87
|
+
*
|
|
88
|
+
* @param start The start of the range
|
|
89
|
+
* @param end The end of the range
|
|
90
|
+
* @param step The increment step
|
|
91
|
+
*/
|
|
92
|
+
export declare function productInRange(start: number, end: number, step?: number): number;
|
|
93
|
+
/**
|
|
94
|
+
* Gets the average of a set of numbers
|
|
95
|
+
*
|
|
96
|
+
* @param args
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
export declare function avg(...args: number[]): number;
|
|
100
|
+
/**
|
|
101
|
+
* Sums an array of numbers
|
|
102
|
+
*
|
|
103
|
+
* @param args
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
export declare function sum(...args: number[]): number;
|
|
107
|
+
/**
|
|
108
|
+
* Generates a random integer between a min and max
|
|
109
|
+
*
|
|
110
|
+
* @param min
|
|
111
|
+
* @param max
|
|
112
|
+
* @returns
|
|
113
|
+
*/
|
|
114
|
+
export declare function getRandomInt(min: number, max: number): number;
|
|
115
|
+
/**
|
|
116
|
+
* Returns the modulus of a number. Allows for negative numbers
|
|
117
|
+
*
|
|
118
|
+
* @param n
|
|
119
|
+
* @param m
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
export declare function mod(n: number, m: number): number;
|
|
123
|
+
/**
|
|
124
|
+
* Return a function which returns a numeric approximation of the derivative of the provided function
|
|
125
|
+
* @example
|
|
126
|
+
* const d = diff(Math.cos);
|
|
127
|
+
* d(Math.PI) // 0
|
|
128
|
+
*
|
|
129
|
+
* @param f The function to be differentiated
|
|
130
|
+
* @param h The delta to be used
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
export declare function diff(f: (x: number) => number, h?: number): (x: number) => number;
|
|
134
|
+
export declare function sinc(x: number): number;
|
|
135
|
+
export declare function Si(x: number): number;
|
|
136
|
+
export declare function Shi(x: number): number;
|
|
137
|
+
export declare function Ci(x: number): number;
|
|
138
|
+
export declare function Chi(x: number): number;
|
|
139
|
+
export declare function Ei(x: number): number;
|
|
140
|
+
export declare function Li(x: number): number;
|