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
package/README.md
CHANGED
|
@@ -1,427 +1,408 @@
|
|
|
1
|
-
|
|
1
|
+
# Nerdamer
|
|
2
2
|
|
|
3
|
-
Nerdamer
|
|
4
|
-
========
|
|
3
|
+
Nerdamer is a symbolic math library for JavaScript and TypeScript. It can parse and manipulate algebraic expressions, solve equations, work with matrices and vectors, perform calculus, and evaluate expressions numerically.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Nerdamer 2.0 is a TypeScript rewrite of the library. Everyday usage remains familiar, while the parser, solvers, numeric handling, public types, and internal architecture have been substantially reworked.
|
|
7
6
|
|
|
8
|
-
Getting started with Nerdamer
|
|
7
|
+
## Getting started with Nerdamer
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
Nerdamer 2.0 is currently available as a release candidate under the npm `next` tag:
|
|
11
10
|
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
<!-- This the core and the only file needed if all you'll be doing is evaluating expresssions -->
|
|
15
|
-
<script src="nerdamer.core.js"></script>
|
|
16
|
-
<!-- LOAD ADD-ONS. These files contain extended functions. See documentation -->
|
|
17
|
-
<!-- again assuming you've saved the files in root -->
|
|
18
|
-
<script src="Algebra.js"></script>
|
|
19
|
-
<script src="Calculus.js"></script>
|
|
20
|
-
<script src="Solve.js"></script>
|
|
21
|
-
<script src="Extra.js"></script>
|
|
22
|
-
```
|
|
23
|
-
Or import everything
|
|
24
|
-
```html
|
|
25
|
-
<script src="all.min.js"></script> <!-- assuming you've saved the file in the root -->
|
|
11
|
+
```bash
|
|
12
|
+
npm install nerdamer@next
|
|
26
13
|
```
|
|
27
|
-
|
|
14
|
+
|
|
15
|
+
When Nerdamer 2.0 becomes the stable `latest` release, the normal `npm install nerdamer` command will install the 2.x line.
|
|
16
|
+
|
|
17
|
+
### Need to stay on the 1.x line?
|
|
18
|
+
|
|
19
|
+
Nerdamer 2.0 contains substantial API and behavior changes. If an existing application cannot migrate to 2.0 yet, use [Nerdamer-Prime](https://github.com/together-science/nerdamer-prime), a separately maintained continuation of the earlier Nerdamer codebase:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install nerdamer-prime
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Nerdamer-Prime is maintained separately from Nerdamer 2.0 and is the appropriate option for projects that need to remain closer to the 1.x API and package structure.
|
|
26
|
+
|
|
27
|
+
In Node.js, require the package and start working with expressions:
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
require('nerdamer/Solve');
|
|
36
|
-
require('nerdamer/Extra');
|
|
37
|
-
```
|
|
38
|
-
Or do a single import to import everything
|
|
39
|
-
```javascript
|
|
40
|
-
const nerdamer = require("nerdamer/all.min")
|
|
30
|
+
const nerdamer = require('nerdamer');
|
|
31
|
+
|
|
32
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)');
|
|
33
|
+
console.log(e.text());
|
|
34
|
+
// 2*cos(x)+3*x^2
|
|
41
35
|
```
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
TypeScript and ESM users can use the default import:
|
|
44
38
|
|
|
45
|
-
|
|
39
|
+
```typescript
|
|
40
|
+
import nerdamer from 'nerdamer';
|
|
46
41
|
|
|
47
|
-
|
|
42
|
+
console.log(nerdamer('expand((x+1)^3)').text());
|
|
43
|
+
```
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
TypeScript projects that compile to CommonJS should enable `esModuleInterop`.
|
|
50
46
|
|
|
51
|
-
|
|
47
|
+
### Browser use
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
The complete browser bundle is included in the package at `dist/bundle.js`. A standalone parser bundle is also available at `dist/parser.js`.
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<script src="./node_modules/nerdamer/dist/bundle.js"></script>
|
|
53
|
+
<script>
|
|
54
|
+
const e = nerdamer('x^2+2*x+1');
|
|
55
|
+
console.log(e.text());
|
|
56
|
+
</script>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Everything is included
|
|
60
|
+
|
|
61
|
+
Nerdamer 1.x was split into the core plus add-ons such as `Algebra.js`, `Calculus.js`, `Solve.js`, and `Extra.js`. Nerdamer 2.0 includes the commonly used algebra, calculus, solving, matrix, vector, and special-function features in the main package. Additional add-on imports are no longer required.
|
|
56
62
|
|
|
57
|
-
//result:
|
|
58
|
-
//2*cos(x)+3*x^2
|
|
59
|
-
```
|
|
60
|
-
It is also possible to use `nerdamer` functions directly within the need for string manipulation of the input. The input will be parsed and the output will of type `Expression`. For example:
|
|
61
63
|
```javascript
|
|
62
|
-
|
|
63
|
-
console.log(ans.text());
|
|
64
|
-
// -1-10*x^2-5*x^4+10*x^3+5*x+x^5
|
|
64
|
+
const nerdamer = require('nerdamer');
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
console.log(
|
|
68
|
-
|
|
66
|
+
console.log(nerdamer.factor('x^2-1').text());
|
|
67
|
+
console.log(nerdamer.diff('x^3', 'x').text());
|
|
68
|
+
console.log(nerdamer.solve('x^2-4', 'x').text());
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
## Expressions and substitutions
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:6});
|
|
75
|
-
console.log(e.text());
|
|
73
|
+
As in earlier versions, calling `nerdamer(...)` parses an expression and returns a Nerdamer value.
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
```javascript
|
|
76
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 });
|
|
77
|
+
console.log(e.text());
|
|
78
|
+
```
|
|
81
79
|
|
|
82
|
-
|
|
83
|
-
Note that evaluate returns a text string or a number not an object.
|
|
80
|
+
Only substitution is performed by the values object. To numerically evaluate the result, call `evaluate()`:
|
|
84
81
|
|
|
85
|
-
```javascript
|
|
86
|
-
|
|
82
|
+
```javascript
|
|
83
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 }).evaluate();
|
|
87
84
|
console.log(e.text());
|
|
85
|
+
```
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
//109.9203405733006
|
|
91
|
-
```
|
|
92
|
-
To get back the text as a fraction, call the text method and pass in the string 'fractions'.
|
|
87
|
+
Values can themselves be expressions:
|
|
93
88
|
|
|
94
|
-
```javascript
|
|
95
|
-
|
|
96
|
-
console.log(e.text(
|
|
89
|
+
```javascript
|
|
90
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 'x^2+1' });
|
|
91
|
+
console.log(e.text());
|
|
92
|
+
```
|
|
97
93
|
|
|
98
|
-
|
|
99
|
-
//429607273/3908351
|
|
100
|
-
```
|
|
101
|
-
You can get your expression back as LaTeX by calling the toTeX method
|
|
102
|
-
```javascript
|
|
103
|
-
var LaTeX = nerdamer('x^2+2*(cos(x)+x*x)',{x:0.25}).toTeX();
|
|
104
|
-
console.log(LaTeX);
|
|
94
|
+
Parser results are always represented by Nerdamer-native values. A scalar expression returns an `Expression`; equations, vectors, matrices, sets, collections, dictionaries, and other supported structured inputs return the corresponding Nerdamer type rather than a JavaScript-native result shape.
|
|
105
95
|
|
|
106
|
-
|
|
107
|
-
//2 \cdot \mathrm{cos}\left(\frac{1}{4}\right)+\frac{3}{16}
|
|
108
|
-
```
|
|
96
|
+
## Text output and term ordering
|
|
109
97
|
|
|
110
|
-
|
|
98
|
+
`text()` returns Nerdamer's normal symbolic representation. For example, a polynomial
|
|
99
|
+
may place the constant term first:
|
|
111
100
|
|
|
112
|
-
```javascript
|
|
113
|
-
|
|
114
|
-
console.log(LaTeX);
|
|
101
|
+
```javascript
|
|
102
|
+
const e = nerdamer('x^2+2*x+1');
|
|
115
103
|
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
```
|
|
104
|
+
e.text();
|
|
105
|
+
// 1+2*x+x^2
|
|
106
|
+
```
|
|
119
107
|
|
|
120
|
-
|
|
108
|
+
Use the per-call `sort` option when conventional display order is preferred:
|
|
121
109
|
|
|
122
|
-
```javascript
|
|
123
|
-
|
|
124
|
-
|
|
110
|
+
```javascript
|
|
111
|
+
e.text({ sort: true });
|
|
112
|
+
// x^2+2*x+1
|
|
125
113
|
|
|
126
|
-
|
|
127
|
-
//
|
|
128
|
-
```
|
|
114
|
+
nerdamer('(x+1)^2').expand().text({ sort: true });
|
|
115
|
+
// x^2+2*x+1
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Sorting affects only the returned string. It does not modify the expression or change the
|
|
119
|
+
process-wide `SORT_TERMS` setting. TypeScript users can import `TextOptions` from
|
|
120
|
+
`nerdamer` or `nerdamer/core`.
|
|
129
121
|
|
|
130
|
-
|
|
131
|
-
nerdamer.expressions().
|
|
122
|
+
The full package also provides the chainable converter-based form:
|
|
132
123
|
|
|
133
|
-
```javascript
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
```javascript
|
|
125
|
+
e.toText();
|
|
126
|
+
// x^2+2*x+1
|
|
127
|
+
```
|
|
137
128
|
|
|
138
|
-
|
|
129
|
+
Use `text({ sort: true })` when you want Nerdamer text syntax with explicit per-call
|
|
130
|
+
ordering control. Use `toText()` when you simply want the conventional formatted-text
|
|
131
|
+
representation.
|
|
139
132
|
|
|
140
|
-
|
|
141
|
-
//[ 46.692712758272776, 1 ]
|
|
142
|
-
```
|
|
133
|
+
## Algebra
|
|
143
134
|
|
|
144
|
-
|
|
145
|
-
situations as the numbering starts at 1;
|
|
135
|
+
Nerdamer can expand, factor, simplify, compute polynomial GCDs, and perform related symbolic algebra operations.
|
|
146
136
|
|
|
147
|
-
```javascript
|
|
148
|
-
|
|
149
|
-
nerdamer('x^
|
|
150
|
-
nerdamer('sin(x)^2+cos(x)^2'
|
|
137
|
+
```javascript
|
|
138
|
+
nerdamer('expand((x+1)^4)').text();
|
|
139
|
+
nerdamer.factor('x^4-1').text();
|
|
140
|
+
nerdamer.simplify('sin(x)^2+cos(x)^2').text();
|
|
141
|
+
nerdamer.gcd('x^2-1', 'x^2-2*x+1').text();
|
|
142
|
+
|
|
143
|
+
const completed = nerdamer.completeSquare('x^2+6*x+1');
|
|
144
|
+
completed.expression.text({ sort: true });
|
|
145
|
+
|
|
146
|
+
const [substituted, substitutions] = nerdamer.uSub(
|
|
147
|
+
'cos(x)^2+cos(x)+1',
|
|
148
|
+
'cos(x)'
|
|
149
|
+
);
|
|
150
|
+
nerdamer.uUnSub(substituted, substitutions);
|
|
151
|
+
```
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
## Solving equations
|
|
153
154
|
|
|
154
|
-
|
|
155
|
-
//'2': 'cos(1+x^(2))^(2)+sin(1+x^(2))^(2)' }
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
Functions aren't always immediately parsed to numbers. For example
|
|
155
|
+
Use `solve` for a single equation:
|
|
159
156
|
|
|
160
157
|
```javascript
|
|
161
|
-
|
|
162
|
-
console.log(
|
|
163
|
-
|
|
158
|
+
const roots = nerdamer.solve('x^2-1', 'x');
|
|
159
|
+
console.log(roots.text());
|
|
160
|
+
|
|
161
|
+
roots.each(root => {
|
|
162
|
+
console.log(root.text());
|
|
163
|
+
});
|
|
164
164
|
```
|
|
165
|
-
|
|
165
|
+
|
|
166
|
+
Single-variable solving returns a `SolutionSet`. System solving returns Nerdamer structures rather than the compatibility-only arrays used by older releases.
|
|
166
167
|
|
|
167
168
|
```javascript
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
const solutions = nerdamer.solveSystem(
|
|
170
|
+
['x+y=3', 'x-y=1'],
|
|
171
|
+
['x', 'y']
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
console.log(solutions.text());
|
|
171
175
|
```
|
|
172
|
-
|
|
176
|
+
|
|
177
|
+
## Calculus
|
|
178
|
+
|
|
179
|
+
Differentiation, integration, limits, sums, products, and transforms are available without loading a separate add-on.
|
|
173
180
|
|
|
174
181
|
```javascript
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
182
|
+
nerdamer.diff('x^3+sin(x)', 'x').text();
|
|
183
|
+
nerdamer.integrate('x^2', 'x').text();
|
|
184
|
+
nerdamer.limit('sin(x)/x', 'x', '0').text();
|
|
178
185
|
```
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
|
|
187
|
+
You can also use calculus functions inside expression strings:
|
|
181
188
|
|
|
182
189
|
```javascript
|
|
183
|
-
|
|
184
|
-
console.log(result.text());
|
|
185
|
-
//0
|
|
190
|
+
nerdamer('diff(x^2+2*(cos(x)+x*x),x)').text();
|
|
186
191
|
```
|
|
187
|
-
The above expample now returns zero whereas in previous version the result would be 4.440892098500626e-16. Same goes for 0.1+0.2.
|
|
188
192
|
|
|
189
|
-
|
|
193
|
+
## Matrices and vectors
|
|
194
|
+
|
|
195
|
+
Matrices and vectors are supported directly by the parser and are also available as public TypeScript classes.
|
|
190
196
|
|
|
191
197
|
```javascript
|
|
192
|
-
nerdamer('
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
const m = nerdamer('matrix([1,2],[3,4])');
|
|
199
|
+
console.log(m.text());
|
|
200
|
+
|
|
201
|
+
const v = nerdamer('vector(1,2,3)');
|
|
202
|
+
console.log(v.text());
|
|
203
|
+
|
|
204
|
+
const basis = nerdamer.nullspace(nerdamer('matrix([1,2,3],[2,4,6])'));
|
|
205
|
+
console.log(basis.text());
|
|
196
206
|
```
|
|
197
207
|
|
|
198
|
-
|
|
208
|
+
## Runtime functions and constants
|
|
209
|
+
|
|
210
|
+
Custom symbolic functions can be defined with Nerdamer syntax:
|
|
199
211
|
|
|
200
212
|
```javascript
|
|
201
|
-
|
|
202
|
-
console.log(
|
|
203
|
-
//-14*y+y^2+49.7539022543433
|
|
213
|
+
nerdamer('hyp(a,b):=sqrt(a^2+b^2)');
|
|
214
|
+
console.log(nerdamer('hyp(3,4)').evaluate().text());
|
|
204
215
|
```
|
|
205
216
|
|
|
206
|
-
|
|
217
|
+
Or use the public function API:
|
|
207
218
|
|
|
208
|
-
```javascript
|
|
209
|
-
nerdamer('x
|
|
210
|
-
nerdamer('
|
|
211
|
-
|
|
212
|
-
var asLaTeX = true;
|
|
213
|
-
console.log(nerdamer.expressions(asObject, asLaTeX));
|
|
219
|
+
```javascript
|
|
220
|
+
nerdamer.setFunction('line', ['x', 'm', 'b'], 'm*x+b');
|
|
221
|
+
console.log(nerdamer('line(2,3,4)').text());
|
|
222
|
+
```
|
|
214
223
|
|
|
215
|
-
|
|
216
|
-
'2': '\\sqrt{\\mathrm{cos}\\left(x\\right)}+\\mathrm{sin}\\left(x\\right)^{\\frac{1}{4}}' }*/
|
|
217
|
-
```
|
|
218
|
-
|
|
224
|
+
Constants can be registered as well:
|
|
219
225
|
|
|
220
|
-
|
|
226
|
+
```javascript
|
|
227
|
+
nerdamer.setConstant('g', 9.81);
|
|
228
|
+
console.log(nerdamer('100*g').text());
|
|
229
|
+
```
|
|
221
230
|
|
|
222
|
-
|
|
223
|
-
nerdamer('x^2+2*(cos(x)+x*x)');
|
|
224
|
-
nerdamer('sin(x)^0.25+cos(x)^0.5' );
|
|
225
|
-
nerdamer('expr-override', undefined, 2 );
|
|
226
|
-
var asObject = false;
|
|
227
|
-
var asLaTeX = true;
|
|
228
|
-
console.log(nerdamer.expressions(asObject, asLaTeX));
|
|
231
|
+
## Nerdamer scripting
|
|
229
232
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
233
|
+
Nerdamer includes a small symbolic scripting language in addition to ordinary expression notation. It supports user-defined functions, assignments, local bindings, conditionals, loops, blocks, logical operations, `return`, `break`, `continue`, and error-handling helpers.
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
const result = nerdamer('let(x,4,if(x>3,x^2,0))');
|
|
237
|
+
console.log(result.text());
|
|
234
238
|
```
|
|
235
239
|
|
|
236
|
-
|
|
240
|
+
Multiple statements use semicolons as statement separators:
|
|
237
241
|
|
|
238
|
-
```javascript
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
242
|
+
```javascript
|
|
243
|
+
const result = nerdamer(`
|
|
244
|
+
f(x):=x^2+1;
|
|
245
|
+
f(12)
|
|
246
|
+
`);
|
|
243
247
|
|
|
244
|
-
|
|
248
|
+
console.log(result.text());
|
|
249
|
+
```
|
|
245
250
|
|
|
246
|
-
|
|
247
|
-
console.log(reserved);
|
|
248
|
-
//result:
|
|
249
|
-
/* [ 'csc', 'sec', 'cot', 'erf', 'fact', 'mod', 'GCD', 'QGCD', 'LCM', 'pow', 'PI', 'E', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'sinh', 'cosh', 'tanh', 'asinh', 'acosh', 'atanh', 'exp', 'min', 'max', 'floor', 'ceil', 'round', 'vector', 'matrix',
|
|
250
|
-
'parens', 'sqrt', 'log', 'expand', 'abs', 'invert', 'transpose', 'dot' ] */
|
|
251
|
-
```
|
|
251
|
+
## Build a JavaScript function
|
|
252
252
|
|
|
253
|
-
|
|
253
|
+
An expression can be compiled to a JavaScript function:
|
|
254
254
|
|
|
255
|
-
```javascript
|
|
256
|
-
|
|
255
|
+
```javascript
|
|
256
|
+
const f = nerdamer('x^2+5').buildFunction();
|
|
257
|
+
console.log(f(9));
|
|
258
|
+
// 86
|
|
259
|
+
```
|
|
257
260
|
|
|
258
|
-
|
|
261
|
+
You can specify the parameter order explicitly:
|
|
259
262
|
|
|
260
|
-
|
|
261
|
-
|
|
263
|
+
```javascript
|
|
264
|
+
const f = nerdamer('z+x^2+y').buildFunction(['y', 'x', 'z']);
|
|
265
|
+
console.log(f(9, 2, 1));
|
|
266
|
+
// 14
|
|
262
267
|
```
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
Nerdamer can also handle runtime functions. To do this use the method setFunction.
|
|
266
|
-
The runtime functions do have symbolic capabilities and support for imaginary numbers.
|
|
267
|
-
The setfunction method is used as follows:
|
|
268
268
|
|
|
269
|
-
nerdamer
|
|
269
|
+
The chained `buildFunction()` method is available on values returned by `nerdamer(...)` so this form remains convenient in TypeScript. Only scalar `Expression` results can be compiled. If the input parses to an `Equation`, `Vector`, `Matrix`, set, or another structured result, calling `buildFunction()` throws `UnexpectedDataType` rather than compiling the contained values independently.
|
|
270
270
|
|
|
271
|
-
|
|
271
|
+
`buildFunction()` uses dynamic JavaScript function construction. Applications with a Content Security Policy that forbids dynamic code generation should use Nerdamer's ordinary symbolic and numeric evaluation APIs instead.
|
|
272
272
|
|
|
273
|
-
|
|
274
|
-
//generate some points
|
|
275
|
-
var f = function(x) { return 5*x-1; }
|
|
276
|
-
console.log(f(1)); //4
|
|
277
|
-
console.log(f(2)); //9 - value to be found
|
|
278
|
-
console.log(f(7)); //34
|
|
273
|
+
## TeX
|
|
279
274
|
|
|
280
|
-
|
|
281
|
-
var answer = nerdamer('interpolate(4,1,34,7,2)').evaluate();
|
|
275
|
+
Convert Nerdamer expressions to TeX math markup with `toTeX()` or `convertToTeX()`:
|
|
282
276
|
|
|
283
|
-
|
|
277
|
+
```javascript
|
|
278
|
+
const e = nerdamer('x^2+2*x+1');
|
|
279
|
+
console.log(e.toTeX());
|
|
284
280
|
|
|
285
|
-
|
|
281
|
+
console.log(nerdamer.convertToTeX('sqrt(x^2+1)'));
|
|
286
282
|
```
|
|
287
283
|
|
|
288
|
-
|
|
284
|
+
The legacy `convertToLaTeX()` name remains available as a deprecated compatibility alias.
|
|
289
285
|
|
|
290
|
-
|
|
291
|
-
nerdamer('hyp(a, b) := sqrt(a^2 + b^2) ');
|
|
292
|
-
var result = nerdamer('hyp(3, 4)').evaluate().text();
|
|
293
|
-
console.log(result);
|
|
294
|
-
//result: 5
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
If you need to add a constant use the setConstant method
|
|
299
|
-
|
|
300
|
-
```javascript
|
|
301
|
-
nerdamer.setConstant( 'g', 9.81);
|
|
302
|
-
var weight = nerdamer('100*g').text();
|
|
303
|
-
console.log(weight);
|
|
304
|
-
//result:
|
|
305
|
-
//981
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
To delete just set it to delete
|
|
309
|
-
|
|
310
|
-
```javascript
|
|
311
|
-
nerdamer.setConstant( 'g', 9.81);
|
|
312
|
-
var weight = nerdamer('100*g').text();
|
|
313
|
-
console.log(weight);
|
|
314
|
-
//981
|
|
315
|
-
nerdamer.setConstant( 'g', 'delete');
|
|
316
|
-
var weight = nerdamer('100*g').text();
|
|
317
|
-
console.log(weight);
|
|
318
|
-
//100*g
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
You also have the option of exporting your function to a javascript function which can be useful if you need some
|
|
322
|
-
filtering from user input. Do keep in mind that the parameters are sorted alphabetically for more than one
|
|
323
|
-
parameter. To use it add the expression to nerdamer and use the buildFunction method.
|
|
324
|
-
|
|
325
|
-
```javascript
|
|
326
|
-
var f = nerdamer('x^2+5').buildFunction();
|
|
327
|
-
console.log(f(9));
|
|
286
|
+
Nerdamer can also parse supported LaTeX expressions:
|
|
328
287
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
288
|
+
```javascript
|
|
289
|
+
const e = nerdamer.convertFromLaTeX('\\frac{x^2+1}{2}');
|
|
290
|
+
console.log(e.text());
|
|
291
|
+
```
|
|
333
292
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
293
|
+
## Direct TypeScript imports
|
|
294
|
+
|
|
295
|
+
The callable `nerdamer` API remains available, but Nerdamer 2.0 also exposes public classes and functions through package subpaths:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
import { Expression, Rational, type TextOptions } from 'nerdamer/core';
|
|
299
|
+
import {
|
|
300
|
+
Polynomial,
|
|
301
|
+
completeSquare,
|
|
302
|
+
gcd,
|
|
303
|
+
isPrime,
|
|
304
|
+
lcm,
|
|
305
|
+
polyFactors,
|
|
306
|
+
uSub,
|
|
307
|
+
uUnSub,
|
|
308
|
+
} from 'nerdamer/algebra';
|
|
309
|
+
import { diff, integrate, limit } from 'nerdamer/calculus';
|
|
310
|
+
import { solve, PolynomialSolver } from 'nerdamer/solve';
|
|
311
|
+
import { Matrix, Vector, ValuesSet, nullspace } from 'nerdamer/structures';
|
|
312
|
+
```
|
|
340
313
|
|
|
341
|
-
|
|
342
|
-
the 'expressions' method. To delete an expression use the 'clear' method and pass in the expression you want to delete.
|
|
343
|
-
To clear everything pass in the string 'all'.
|
|
314
|
+
Additional entry points are available for assumptions, selected parser APIs, advanced algorithms, and debugging tools.
|
|
344
315
|
|
|
345
|
-
|
|
346
|
-
nerdamer('n*R*T/v');
|
|
347
|
-
nerdamer('mc^2');
|
|
348
|
-
nerdamer('G*m1*m2/d^2');
|
|
316
|
+
## Assumptions
|
|
349
317
|
|
|
350
|
-
|
|
318
|
+
Nerdamer can register numeric interval assumptions for symbols. Assumptions are process-wide and are used by symbolic comparisons and simplifications that depend on sign or range information.
|
|
351
319
|
|
|
352
|
-
|
|
320
|
+
```typescript
|
|
321
|
+
import nerdamer from 'nerdamer';
|
|
322
|
+
import { assume, clearAssumptions } from 'nerdamer/assumptions';
|
|
353
323
|
|
|
354
|
-
|
|
355
|
-
//{ '1': 'R*T*n*v^(-1)', '2': 'G*d^(-2)*m1*m2' }
|
|
324
|
+
assume('x > 0');
|
|
356
325
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
//result:
|
|
360
|
-
//{}
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
If you need go get the variables of an expression use the variables method. This method can be called after
|
|
364
|
-
nerdamer was provided an expression. For example
|
|
326
|
+
console.log(nerdamer('sqrt(x^2)').text());
|
|
327
|
+
// x
|
|
365
328
|
|
|
366
|
-
|
|
367
|
-
var variables = nerdamer('csc(x*cos(y))-no_boring_x').variables();
|
|
368
|
-
console.log(variables);
|
|
369
|
-
//result:
|
|
370
|
-
//[ 'no_boring_x', 'x', 'y' ]
|
|
329
|
+
clearAssumptions();
|
|
371
330
|
```
|
|
372
331
|
|
|
373
|
-
|
|
374
|
-
sake of simplicity we'll just assume that there is no particular order
|
|
332
|
+
Repeated assumptions for the same symbol are intersected. Contradictory assumptions are rejected instead of silently replacing the existing range.
|
|
375
333
|
|
|
376
|
-
|
|
334
|
+
## Localized error messages
|
|
335
|
+
|
|
336
|
+
Nerdamer includes localized built-in error messages for English, Spanish, French, German, Portuguese, Italian, and Dutch. Select the language through the shared parser settings:
|
|
377
337
|
|
|
378
|
-
Using the solver
|
|
379
|
-
===============
|
|
380
|
-
To solve equations first load Solve.js. Just remember that Solve also required Algebra.js and Calculus.js to be loaded. You can then solve equations using nerdamer. Important: State the variable for which you are trying to solve.
|
|
381
338
|
```javascript
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
//
|
|
339
|
+
nerdamer.set('LANGUAGE', 'spa');
|
|
340
|
+
|
|
341
|
+
// Restore English when needed.
|
|
342
|
+
nerdamer.set('LANGUAGE', 'eng');
|
|
385
343
|
```
|
|
386
344
|
|
|
387
|
-
|
|
345
|
+
The language codes are `eng`, `spa`, `fra`, `deu`, `por`, `ita`, and `nld`.
|
|
346
|
+
|
|
347
|
+
## Numeric precision
|
|
348
|
+
|
|
349
|
+
Nerdamer keeps exact rational and integer arithmetic where possible. Decimal arithmetic uses Decimal.js and large integers use native `BigInt`.
|
|
388
350
|
|
|
389
|
-
You can also solve an expression
|
|
390
351
|
```javascript
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
//4+x^2
|
|
352
|
+
nerdamer('0.1+0.2').text();
|
|
353
|
+
nerdamer('sqrt(2)').evaluate().text();
|
|
394
354
|
```
|
|
395
355
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
356
|
+
## What changed in 2.0
|
|
357
|
+
|
|
358
|
+
Nerdamer 2.0 keeps the familiar expression-oriented API, but it is a new implementation rather than a continuation of the 1.x source tree. Important changes include:
|
|
359
|
+
|
|
360
|
+
- the old add-on loading system is gone;
|
|
361
|
+
- TypeScript declarations ship with the package;
|
|
362
|
+
- Nerdamer no longer keeps a global history of every parsed expression;
|
|
363
|
+
- parser-facing APIs consistently return Nerdamer-native values instead of mixing Nerdamer types with JavaScript-native result shapes;
|
|
364
|
+
- solver result types are explicit public structures;
|
|
365
|
+
- lower-level 1.x extension hooks such as `getCore()` and `register()` are not exposed in the same way;
|
|
366
|
+
- decimal, complex-number, parser, solver, assumptions, and set handling have been substantially revised.
|
|
367
|
+
|
|
368
|
+
If an existing project cannot move to Nerdamer 2.0 yet, use [Nerdamer-Prime](https://github.com/together-science/nerdamer-prime), which continues the earlier Nerdamer line under the `nerdamer-prime` npm package.
|
|
369
|
+
|
|
370
|
+
For the current documentation, examples, and migration information, visit [nerdamer.com](https://nerdamer.com/).
|
|
371
|
+
|
|
372
|
+
## Documentation and playground
|
|
373
|
+
|
|
374
|
+
- Website: [nerdamer.com](https://nerdamer.com/)
|
|
375
|
+
- Documentation: [nerdamer.com/docs](https://nerdamer.com/docs/)
|
|
376
|
+
- Playground: [nerdamer.com/playground](https://nerdamer.com/playground/)
|
|
377
|
+
|
|
378
|
+
## Development
|
|
379
|
+
|
|
380
|
+
Run the type checker:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
npm run typecheck
|
|
401
384
|
```
|
|
402
|
-
You can do up to 3rd order polynomials for multivariate polynomials
|
|
403
385
|
|
|
404
|
-
|
|
386
|
+
Run the tests:
|
|
405
387
|
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
console.log(sol.toString());
|
|
409
|
-
//5.7981235959208695,0.4850617112587174
|
|
388
|
+
```bash
|
|
389
|
+
npm test
|
|
410
390
|
```
|
|
411
|
-
To solve a system of linear equations pass them in as an array. For example
|
|
412
391
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
392
|
+
Build the complete package:
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
npm run build
|
|
417
396
|
```
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
x = x.evaluate({a: 'x^2-3'});
|
|
424
|
-
console.log(x.toString()); //2+x^2=-7*x^2+21+y
|
|
425
|
-
var solutions = x.solveFor('x');
|
|
426
|
-
console.log(solutions.toString()); //(1/16)*sqrt(32*y+608),(-1/16)*sqrt(32*y+608)
|
|
397
|
+
|
|
398
|
+
Validate the npm package as an installed consumer:
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
npm run validate:package
|
|
427
402
|
```
|
|
403
|
+
|
|
404
|
+
The publish hook runs tests, builds the package and parser bundle, generates parser documentation data, and validates the packed npm artifact before publication.
|
|
405
|
+
|
|
406
|
+
## License
|
|
407
|
+
|
|
408
|
+
Nerdamer 2.0 is licensed under the Apache License 2.0.
|