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,21 @@
|
|
|
1
|
+
import { scopedBlock } from '../../Settings';
|
|
2
|
+
import { Expression } from '../expression/Expression';
|
|
3
|
+
import type { ExpressionInput, StructuredEntityType } from '../../types';
|
|
4
|
+
import type { ParserValuesObject } from './types';
|
|
5
|
+
export { scopedBlock };
|
|
6
|
+
/**
|
|
7
|
+
* Forces the expression to be evaluated
|
|
8
|
+
*
|
|
9
|
+
* @param expression The expression to be evaluated
|
|
10
|
+
* @param values The values to be substituted
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function evaluate(expression: string, values?: ParserValuesObject): import("../../types").ParserEntity;
|
|
14
|
+
export declare function inert(expression: string): import("../../types").ParserEntity;
|
|
15
|
+
export declare function _(expr: ExpressionInput): Expression;
|
|
16
|
+
/**
|
|
17
|
+
* Returns true if the object is a structured entity
|
|
18
|
+
* @param obj
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function isStructuredEntity(obj: unknown): obj is StructuredEntityType;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scopedBlock = void 0;
|
|
4
|
+
exports.evaluate = evaluate;
|
|
5
|
+
exports.inert = inert;
|
|
6
|
+
exports._ = _;
|
|
7
|
+
exports.isStructuredEntity = isStructuredEntity;
|
|
8
|
+
const Settings_1 = require("../../Settings");
|
|
9
|
+
Object.defineProperty(exports, "scopedBlock", { enumerable: true, get: function () { return Settings_1.scopedBlock; } });
|
|
10
|
+
const Expression_1 = require("../expression/Expression");
|
|
11
|
+
const Parser_1 = require("./Parser");
|
|
12
|
+
/**
|
|
13
|
+
* Forces the expression to be evaluated
|
|
14
|
+
*
|
|
15
|
+
* @param expression The expression to be evaluated
|
|
16
|
+
* @param values The values to be substituted
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
function evaluate(expression, values) {
|
|
20
|
+
return Parser_1.Parser.evaluate(expression, values);
|
|
21
|
+
}
|
|
22
|
+
function inert(expression) {
|
|
23
|
+
return (0, Settings_1.scopedBlock)('EVALUATE', false, () => {
|
|
24
|
+
return (0, Settings_1.scopedBlock)('SUBSTITUTE', false, () => {
|
|
25
|
+
return Parser_1.Parser.parse(expression);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function _(expr) {
|
|
30
|
+
return Expression_1.Expression.create(expr);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns true if the object is a structured entity
|
|
34
|
+
* @param obj
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
function isStructuredEntity(obj) {
|
|
38
|
+
if (typeof obj === 'undefined') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return obj.isEnumerable;
|
|
42
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Expression } from '../../expression/Expression';
|
|
2
|
+
export declare function add(a: Expression, b: Expression): Expression;
|
|
3
|
+
export declare function addPrefix(a: Expression): Expression;
|
|
4
|
+
/**
|
|
5
|
+
* This method is not designed for cases where a = b; This should be handled before getting here.
|
|
6
|
+
* This method only does element wise addition for powers of 1. For all else it just creates a new expression
|
|
7
|
+
* and puts them in a new container.
|
|
8
|
+
*
|
|
9
|
+
* @param a
|
|
10
|
+
* @param b
|
|
11
|
+
* @param action
|
|
12
|
+
* @param skipAction
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function join(a: Expression, b: Expression, isGroup?: boolean): Expression;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.add = add;
|
|
4
|
+
exports.addPrefix = addPrefix;
|
|
5
|
+
exports.join = join;
|
|
6
|
+
const errors_1 = require("../../../errors");
|
|
7
|
+
const Settings_1 = require("../../../Settings");
|
|
8
|
+
const Expression_1 = require("../../expression/Expression");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
const { NUM, VAR, EXP, FUN, GRP, PRD, SUM, INF } = constants_1.EXPRESSION_TYPES;
|
|
12
|
+
function add(a, b) {
|
|
13
|
+
let retval;
|
|
14
|
+
if (Settings_1.Settings.DEFER_SIMPLIFICATION) {
|
|
15
|
+
retval = join(a, b, false);
|
|
16
|
+
retval.deferred = true;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const keyA = a.keyValue();
|
|
20
|
+
const keyB = b.keyValue();
|
|
21
|
+
// Distribute only when an operand can actually change. distributeMultiplier()
|
|
22
|
+
// returns an independent deep copy, so calling it for ordinary operands adds
|
|
23
|
+
// substantial copy work without affecting the result.
|
|
24
|
+
if (Expression_1.Expression.DISTRIBUTE_MULTIPLIER) {
|
|
25
|
+
if (a.isSum() && !a.getMultiplier().isOne() && a.isLinear()) {
|
|
26
|
+
a = a.distributeMultiplier();
|
|
27
|
+
}
|
|
28
|
+
if (b.isSum() && !b.getMultiplier().isOne() && b.isLinear()) {
|
|
29
|
+
b = b.distributeMultiplier();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// It suffices to check if their keyValues are the same since x+x will be handled.
|
|
33
|
+
// We're only dealing with x^n+x^(!n) at this point.
|
|
34
|
+
const isGroup = !a.isNUM() && keyA === keyB;
|
|
35
|
+
if (a.isNUM() && b.isNUM()) {
|
|
36
|
+
retval = Expression_1.Expression.fromRational(a.getMultiplier().plus(b.getMultiplier()));
|
|
37
|
+
}
|
|
38
|
+
else if (a.isComplex() && b.isComplex()) {
|
|
39
|
+
const re = a.realPart().plus(b.realPart());
|
|
40
|
+
const im = a.imagPart().plus(b.imagPart()).times(Expression_1.Expression.Img());
|
|
41
|
+
// Do a zero check here rather than placing that additional burden on join.
|
|
42
|
+
retval = re.isZero() ? im : im.isZero() ? re : join(re, im); // Don't use add
|
|
43
|
+
}
|
|
44
|
+
else if (a.isZero()) {
|
|
45
|
+
retval = b.copy();
|
|
46
|
+
}
|
|
47
|
+
else if (a.value === b.value && a.type === b.type && a.getPower().eq(b.getPower())) {
|
|
48
|
+
// Infinity has no finite coefficient magnitude. Same-sign infinities remain
|
|
49
|
+
// canonical infinity, while opposite signs are undefined.
|
|
50
|
+
if (a.isInf()) {
|
|
51
|
+
const x = a.getMultiplier();
|
|
52
|
+
const y = b.getMultiplier();
|
|
53
|
+
if ((x.isNegative() && !y.isNegative()) || (y.isNegative() && !x.isNegative())) {
|
|
54
|
+
throw new errors_1.UndefinedError((0, errors_1.message)('infinityMinusInfinityUndefined'));
|
|
55
|
+
}
|
|
56
|
+
retval = a.isNegInf() ? Expression_1.Expression.NegInf() : Expression_1.Expression.Inf();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const multiplier = a.getMultiplier().plus(b.getMultiplier());
|
|
60
|
+
if (multiplier.isZero()) {
|
|
61
|
+
retval = Expression_1.Expression.Number('0');
|
|
62
|
+
}
|
|
63
|
+
else if (a.isSum() && b.isSum() && a.isLinear() && b.isLinear()) {
|
|
64
|
+
retval = join(a, b);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
retval = a.copy();
|
|
68
|
+
retval.multiplier = multiplier;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Since we've already check for equal power and value we're not dealing with groups
|
|
73
|
+
// These are stored by power rather than their value so x^n+x^(n+1) will be stored as
|
|
74
|
+
// {n: x^n, n+1: x^(n+1)} for any power !== 0
|
|
75
|
+
else if (isGroup) {
|
|
76
|
+
retval = join(a, b, isGroup);
|
|
77
|
+
}
|
|
78
|
+
else if (a.isInf() && b.isInf()) {
|
|
79
|
+
const x = a.getMultiplier();
|
|
80
|
+
const y = b.getMultiplier();
|
|
81
|
+
if ((x.isNegative() && !y.isNegative()) || (y.isNegative() && !x.isNegative())) {
|
|
82
|
+
throw new errors_1.UndefinedError((0, errors_1.message)('infinityMinusInfinityUndefined'));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// We can just flip because of commutativity. Add can figure out the rest.
|
|
86
|
+
// ******************** RECIPROCALS ******************** //
|
|
87
|
+
else if (constants_1.RANK[a.type] > constants_1.RANK[b.type]) {
|
|
88
|
+
retval = add(b, a);
|
|
89
|
+
}
|
|
90
|
+
// This is a catch all for all unhandled cases so do not use else above.
|
|
91
|
+
retval = retval || join(a, b, isGroup);
|
|
92
|
+
}
|
|
93
|
+
return retval;
|
|
94
|
+
}
|
|
95
|
+
function addPrefix(a) {
|
|
96
|
+
// This does nothing but return the Expression
|
|
97
|
+
return a;
|
|
98
|
+
}
|
|
99
|
+
function canJoin(a, b) {
|
|
100
|
+
// In order for SUM or GRP to be able to join, it needs to have a multiplier and a power of one
|
|
101
|
+
return (
|
|
102
|
+
// Any value can be added to SUM
|
|
103
|
+
(a.type === SUM ||
|
|
104
|
+
// b can only be added to a if the keyValue matches
|
|
105
|
+
(a.type === GRP && a.keyValue() === b.keyValue())) &&
|
|
106
|
+
// Both the power and multiplier must be one, basically it's wrapped in parentheses
|
|
107
|
+
a.isLinear() &&
|
|
108
|
+
(!a.multiplier || (a.multiplier && a.getMultiplier().isOne())));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* This method is not designed for cases where a = b; This should be handled before getting here.
|
|
112
|
+
* This method only does element wise addition for powers of 1. For all else it just creates a new expression
|
|
113
|
+
* and puts them in a new container.
|
|
114
|
+
*
|
|
115
|
+
* @param a
|
|
116
|
+
* @param b
|
|
117
|
+
* @param action
|
|
118
|
+
* @param skipAction
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
function join(a, b, isGroup = false) {
|
|
122
|
+
let retval;
|
|
123
|
+
let elements = [];
|
|
124
|
+
const expressionType = isGroup ? GRP : SUM;
|
|
125
|
+
let aCanJoin = canJoin(a, b);
|
|
126
|
+
let bCanJoin = canJoin(b, a);
|
|
127
|
+
// Always keep the joinable expression on the right
|
|
128
|
+
if (aCanJoin && !bCanJoin) {
|
|
129
|
+
[b, a] = [a, b]; // Swap them
|
|
130
|
+
[bCanJoin, aCanJoin] = [aCanJoin, bCanJoin]; // Swap the join condition
|
|
131
|
+
}
|
|
132
|
+
// Case 1: Neither has an expression object so make an empty container and append a copy of the second.
|
|
133
|
+
// If skipAction is true then it will just append and skip everything else. Remember, a != b
|
|
134
|
+
if (!bCanJoin) {
|
|
135
|
+
let asSubExpression = false;
|
|
136
|
+
// Case 1.a: We first get the keys and assume they're not sub-symbolics. For x^-1 and (x+x^2)^-1 for
|
|
137
|
+
// instance we get a tie. Not only are they key values the same, but so are their powers. They should
|
|
138
|
+
// be joined as sub-symbolics at this point. We perform this check to break the tie. We'll know this
|
|
139
|
+
// because we'll have two matching keys which shouldn't happen.
|
|
140
|
+
let keyA = a.keyValue(asSubExpression, isGroup);
|
|
141
|
+
let keyB = b.keyValue(asSubExpression, isGroup);
|
|
142
|
+
// Check for matching keys and recalculate the keys if that's the case
|
|
143
|
+
if (keyA === keyB) {
|
|
144
|
+
asSubExpression = true;
|
|
145
|
+
isGroup = false;
|
|
146
|
+
keyA = a.keyValue(asSubExpression, isGroup);
|
|
147
|
+
keyB = b.keyValue(asSubExpression, isGroup);
|
|
148
|
+
}
|
|
149
|
+
retval = Expression_1.Expression.Number('1');
|
|
150
|
+
retval.elements = {};
|
|
151
|
+
// Copy the elements
|
|
152
|
+
retval.elements[keyA] = a.copy();
|
|
153
|
+
retval.elements[keyB] = b.copy();
|
|
154
|
+
elements = [a, b];
|
|
155
|
+
}
|
|
156
|
+
// Case 2
|
|
157
|
+
// e.g. x + (x+1) or 2*(x+1) + (x+1)+y
|
|
158
|
+
else if (!aCanJoin && bCanJoin) {
|
|
159
|
+
retval = b.copy();
|
|
160
|
+
const subExpressions = retval.getElements();
|
|
161
|
+
// We start with the more restrictive assumption. Taking the example from case 1,
|
|
162
|
+
// we now have an expression in the form x^-1 + (x+x^2)^-1. The simpler from of the key
|
|
163
|
+
// would just be x but we first want to make sure we're not dealing with case 1.a
|
|
164
|
+
let asSubExpression = true;
|
|
165
|
+
let key = a.keyValue(asSubExpression, false);
|
|
166
|
+
// If no value was found then it's safe to use the less restrictive key so recalculate it
|
|
167
|
+
if (!(key in subExpressions)) {
|
|
168
|
+
asSubExpression = false;
|
|
169
|
+
key = a.keyValue(asSubExpression, isGroup);
|
|
170
|
+
}
|
|
171
|
+
// Append the expression or add it to any existing expression if there's one
|
|
172
|
+
if (key in subExpressions) {
|
|
173
|
+
const result = add(a, subExpressions[key]);
|
|
174
|
+
// It may have resulted in zero, so only add if that's not the case
|
|
175
|
+
if (!result.isZero()) {
|
|
176
|
+
subExpressions[key] = result;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// Otherwise remove it
|
|
180
|
+
delete subExpressions[key];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
subExpressions[key] = a.copy();
|
|
185
|
+
}
|
|
186
|
+
elements = Object.values(subExpressions);
|
|
187
|
+
}
|
|
188
|
+
// Case 3
|
|
189
|
+
else {
|
|
190
|
+
retval = a.copy();
|
|
191
|
+
retval.multiplier = a.getMultiplier().times(b.getMultiplier());
|
|
192
|
+
const retvalExpressions = retval.getElements();
|
|
193
|
+
const bExpressions = b.getElements();
|
|
194
|
+
for (const x in bExpressions) {
|
|
195
|
+
const e = bExpressions[x];
|
|
196
|
+
if (x in retvalExpressions) {
|
|
197
|
+
const result = add(e, retvalExpressions[x]);
|
|
198
|
+
// Don't add it if it's zero
|
|
199
|
+
if (result.isZero()) {
|
|
200
|
+
// Remove the entry if it's zero
|
|
201
|
+
delete retvalExpressions[x];
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
retvalExpressions[x] = result;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
retvalExpressions[x] = e.copy();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
elements = Object.values(retvalExpressions);
|
|
212
|
+
}
|
|
213
|
+
// Some cleanup. The expression may have now become a single element. We'll know this because
|
|
214
|
+
// the sub-elements will only be one element long. If that's the case then that become the reval
|
|
215
|
+
if ((retval.isSum() || retval.isProduct()) && elements.length === 1) {
|
|
216
|
+
const onlyElement = elements[0];
|
|
217
|
+
// Move the multiplier
|
|
218
|
+
if (retval.multiplier || onlyElement.multiplier) {
|
|
219
|
+
onlyElement.multiplier = onlyElement.getMultiplier().times(retval.getMultiplier());
|
|
220
|
+
}
|
|
221
|
+
retval = onlyElement;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// If it's empty then the value is zero
|
|
225
|
+
if (elements.length === 0) {
|
|
226
|
+
retval = Expression_1.Expression.Number('0');
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
// Set the type
|
|
230
|
+
retval.type = expressionType;
|
|
231
|
+
// Update derived aggregate state after the element collection changes.
|
|
232
|
+
retval.updateValue(elements);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return retval;
|
|
236
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ExpressionInput } from '../../../types';
|
|
2
|
+
export { assume } from '../../assumption/assume';
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether Nerdamer can establish that `a` and `b` are equal.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The public expression comparison remains boolean for compatibility. Assumptions
|
|
8
|
+
* supply a result when they can prove or disprove the relation; an unknown assumption
|
|
9
|
+
* result falls through to the ordinary symbolic comparison. If neither path can prove
|
|
10
|
+
* equality, this function returns `false`. Use the corresponding `Assumption` relation
|
|
11
|
+
* directly when a caller needs to distinguish a disproved relation from an unknown one.
|
|
12
|
+
*/
|
|
13
|
+
export declare function equal(a: ExpressionInput, b: ExpressionInput): boolean;
|
|
14
|
+
/** Checks whether Nerdamer can establish that `a` is strictly greater than `b`. */
|
|
15
|
+
export declare function gt(a: ExpressionInput, b: ExpressionInput): boolean;
|
|
16
|
+
/** Checks whether Nerdamer can establish that `a` is greater than or equal to `b`. */
|
|
17
|
+
export declare function gte(a: ExpressionInput, b: ExpressionInput): boolean;
|
|
18
|
+
/** Checks whether Nerdamer can establish that `a` is strictly less than `b`. */
|
|
19
|
+
export declare function lt(a: ExpressionInput, b: ExpressionInput): boolean;
|
|
20
|
+
/** Checks whether Nerdamer can establish that `a` is less than or equal to `b`. */
|
|
21
|
+
export declare function lte(a: ExpressionInput, b: ExpressionInput): boolean;
|