nerdamer 1.1.12 → 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 +297 -287
- 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 -420
- 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 -4553
- package/BREAKING_CHANGES.md +0 -5
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -14
- package/Calculus.js +0 -2671
- package/Extra.js +0 -622
- package/Solve.js +0 -1734
- 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 -12613
- package/spec/LaTeX.spec.js +0 -302
- package/spec/TeXConvert.spec.js +0 -8
- package/spec/algebra.spec.js +0 -839
- package/spec/basic_parser.spec.js +0 -134
- package/spec/build.spec.js +0 -131
- package/spec/calculus.spec.js +0 -182
- package/spec/core.spec.js +0 -2970
- package/spec/extra.spec.js +0 -54
- package/spec/solve.spec.js +0 -120
- 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,398 +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>
|
|
11
|
+
```bash
|
|
12
|
+
npm install nerdamer@next
|
|
22
13
|
```
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
You can see nerdamer in action at http://nerdamer.com/demo
|
|
15
|
+
When Nerdamer 2.0 becomes the stable `latest` release, the normal `npm install nerdamer` command will install the 2.x line.
|
|
27
16
|
|
|
28
|
-
|
|
17
|
+
### Need to stay on the 1.x line?
|
|
29
18
|
|
|
30
|
-
|
|
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:
|
|
31
20
|
|
|
32
|
-
|
|
21
|
+
```bash
|
|
22
|
+
npm install nerdamer-prime
|
|
23
|
+
```
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
var e = nerdamer('x^2+2*(cos(x)+x*x)');
|
|
36
|
-
console.log(e.text());
|
|
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.
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
//2*cos(x)+3*x^2
|
|
40
|
-
```
|
|
27
|
+
In Node.js, require the package and start working with expressions:
|
|
41
28
|
|
|
42
|
-
|
|
29
|
+
```javascript
|
|
30
|
+
const nerdamer = require('nerdamer');
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:6});
|
|
32
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)');
|
|
46
33
|
console.log(e.text());
|
|
34
|
+
// 2*cos(x)+3*x^2
|
|
35
|
+
```
|
|
47
36
|
|
|
48
|
-
|
|
49
|
-
//108+2*cos(6)
|
|
50
|
-
```
|
|
51
|
-
|
|
37
|
+
TypeScript and ESM users can use the default import:
|
|
52
38
|
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
```typescript
|
|
40
|
+
import nerdamer from 'nerdamer';
|
|
55
41
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
console.log(e.text());
|
|
42
|
+
console.log(nerdamer('expand((x+1)^3)').text());
|
|
43
|
+
```
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
//109.9203405733006
|
|
62
|
-
```
|
|
63
|
-
To get back the text as a fraction, call the text method and pass in the string 'fractions'.
|
|
45
|
+
TypeScript projects that compile to CommonJS should enable `esModuleInterop`.
|
|
64
46
|
|
|
65
|
-
|
|
66
|
-
var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:6}).evaluate();
|
|
67
|
-
console.log(e.text('fractions'));
|
|
47
|
+
### Browser use
|
|
68
48
|
|
|
69
|
-
|
|
70
|
-
//429607273/3908351
|
|
71
|
-
```
|
|
72
|
-
You can get your expression back as LaTeX by calling the toTeX method
|
|
73
|
-
```javascript
|
|
74
|
-
var LaTeX = nerdamer('x^2+2*(cos(x)+x*x)',{x:0.25}).toTeX();
|
|
75
|
-
console.log(LaTeX);
|
|
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`.
|
|
76
50
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
+
```
|
|
80
58
|
|
|
81
|
-
|
|
59
|
+
## Everything is included
|
|
82
60
|
|
|
83
|
-
|
|
84
|
-
var LaTeX = nerdamer('x^2+2*(cos(x)+x*x)',{x:0.25}).toTeX('decimal');
|
|
85
|
-
console.log(LaTeX);
|
|
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.
|
|
86
62
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```
|
|
63
|
+
```javascript
|
|
64
|
+
const nerdamer = require('nerdamer');
|
|
90
65
|
|
|
91
|
-
|
|
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
|
+
```
|
|
92
70
|
|
|
93
|
-
|
|
94
|
-
var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:'x^2+1'});
|
|
95
|
-
console.log(e.text());
|
|
71
|
+
## Expressions and substitutions
|
|
96
72
|
|
|
97
|
-
|
|
98
|
-
//2*cos(1+x^2)+3*(1+x^2)^2
|
|
99
|
-
```
|
|
73
|
+
As in earlier versions, calling `nerdamer(...)` parses an expression and returns a Nerdamer value.
|
|
100
74
|
|
|
101
|
-
|
|
102
|
-
nerdamer
|
|
75
|
+
```javascript
|
|
76
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 });
|
|
77
|
+
console.log(e.text());
|
|
78
|
+
```
|
|
103
79
|
|
|
104
|
-
|
|
105
|
-
var knownValues = {x:'x^2+1'};
|
|
106
|
-
nerdamer('x^2+2*(cos(x)+x*x)').evaluate(knownValues);
|
|
107
|
-
nerdamer('sin(x)^2+cos(x)^2').evaluate(knownValues);
|
|
80
|
+
Only substitution is performed by the values object. To numerically evaluate the result, call `evaluate()`:
|
|
108
81
|
|
|
109
|
-
|
|
82
|
+
```javascript
|
|
83
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 }).evaluate();
|
|
84
|
+
console.log(e.text());
|
|
85
|
+
```
|
|
110
86
|
|
|
111
|
-
|
|
112
|
-
//[ 46.692712758272776, 1 ]
|
|
113
|
-
```
|
|
87
|
+
Values can themselves be expressions:
|
|
114
88
|
|
|
115
|
-
|
|
116
|
-
|
|
89
|
+
```javascript
|
|
90
|
+
const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 'x^2+1' });
|
|
91
|
+
console.log(e.text());
|
|
92
|
+
```
|
|
117
93
|
|
|
118
|
-
|
|
119
|
-
var knownValues = {x:'x^2+1'};
|
|
120
|
-
nerdamer('x^2+2*(cos(x)+x*x)', knownValues );
|
|
121
|
-
nerdamer('sin(x)^2+cos(x)^2', knownValues );
|
|
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.
|
|
122
95
|
|
|
123
|
-
|
|
96
|
+
## Text output and term ordering
|
|
124
97
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Functions aren't always immediately parsed to numbers. For example
|
|
98
|
+
`text()` returns Nerdamer's normal symbolic representation. For example, a polynomial
|
|
99
|
+
may place the constant term first:
|
|
130
100
|
|
|
131
101
|
```javascript
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
102
|
+
const e = nerdamer('x^2+2*x+1');
|
|
103
|
+
|
|
104
|
+
e.text();
|
|
105
|
+
// 1+2*x+x^2
|
|
135
106
|
```
|
|
136
|
-
|
|
107
|
+
|
|
108
|
+
Use the per-call `sort` option when conventional display order is preferred:
|
|
137
109
|
|
|
138
110
|
```javascript
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
e.text({ sort: true });
|
|
112
|
+
// x^2+2*x+1
|
|
113
|
+
|
|
114
|
+
nerdamer('(x+1)^2').expand().text({ sort: true });
|
|
115
|
+
// x^2+2*x+1
|
|
142
116
|
```
|
|
143
|
-
|
|
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`.
|
|
121
|
+
|
|
122
|
+
The full package also provides the chainable converter-based form:
|
|
144
123
|
|
|
145
124
|
```javascript
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
//0.960170286650366
|
|
125
|
+
e.toText();
|
|
126
|
+
// x^2+2*x+1
|
|
149
127
|
```
|
|
150
|
-
|
|
151
|
-
|
|
128
|
+
|
|
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.
|
|
132
|
+
|
|
133
|
+
## Algebra
|
|
134
|
+
|
|
135
|
+
Nerdamer can expand, factor, simplify, compute polynomial GCDs, and perform related symbolic algebra operations.
|
|
152
136
|
|
|
153
137
|
```javascript
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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);
|
|
157
151
|
```
|
|
158
|
-
The above expample now returns zero whereas in previous version the result would be 4.440892098500626e-16. Same goes for 0.1+0.2.
|
|
159
152
|
|
|
160
|
-
|
|
153
|
+
## Solving equations
|
|
154
|
+
|
|
155
|
+
Use `solve` for a single equation:
|
|
161
156
|
|
|
162
157
|
```javascript
|
|
163
|
-
nerdamer('
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
});
|
|
167
164
|
```
|
|
168
165
|
|
|
169
|
-
|
|
166
|
+
Single-variable solving returns a `SolutionSet`. System solving returns Nerdamer structures rather than the compatibility-only arrays used by older releases.
|
|
170
167
|
|
|
171
168
|
```javascript
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
const solutions = nerdamer.solveSystem(
|
|
170
|
+
['x+y=3', 'x-y=1'],
|
|
171
|
+
['x', 'y']
|
|
172
|
+
);
|
|
176
173
|
|
|
177
|
-
|
|
174
|
+
console.log(solutions.text());
|
|
175
|
+
```
|
|
178
176
|
|
|
179
|
-
|
|
180
|
-
nerdamer('x^2+2*(cos(x)+x*x)');
|
|
181
|
-
nerdamer('sin(x)^0.25+cos(x)^0.5' );
|
|
182
|
-
var asObject = true;
|
|
183
|
-
var asLaTeX = true;
|
|
184
|
-
console.log(nerdamer.expressions(asObject, asLaTeX));
|
|
177
|
+
## Calculus
|
|
185
178
|
|
|
186
|
-
|
|
187
|
-
'2': '\\sqrt{\\mathrm{cos}\\left(x\\right)}+\\mathrm{sin}\\left(x\\right)^{\\frac{1}{4}}' }*/
|
|
188
|
-
```
|
|
189
|
-
|
|
179
|
+
Differentiation, integration, limits, sums, products, and transforms are available without loading a separate add-on.
|
|
190
180
|
|
|
191
|
-
|
|
181
|
+
```javascript
|
|
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();
|
|
185
|
+
```
|
|
192
186
|
|
|
193
|
-
|
|
194
|
-
nerdamer('x^2+2*(cos(x)+x*x)');
|
|
195
|
-
nerdamer('sin(x)^0.25+cos(x)^0.5' );
|
|
196
|
-
nerdamer('expr-override', undefined, 2 );
|
|
197
|
-
var asObject = false;
|
|
198
|
-
var asLaTeX = true;
|
|
199
|
-
console.log(nerdamer.expressions(asObject, asLaTeX));
|
|
187
|
+
You can also use calculus functions inside expression strings:
|
|
200
188
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
'expr-override' ]
|
|
204
|
-
*/
|
|
189
|
+
```javascript
|
|
190
|
+
nerdamer('diff(x^2+2*(cos(x)+x*x),x)').text();
|
|
205
191
|
```
|
|
206
192
|
|
|
207
|
-
|
|
193
|
+
## Matrices and vectors
|
|
194
|
+
|
|
195
|
+
Matrices and vectors are supported directly by the parser and are also available as public TypeScript classes.
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
const m = nerdamer('matrix([1,2],[3,4])');
|
|
199
|
+
console.log(m.text());
|
|
208
200
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
console.log(reserved);
|
|
212
|
-
//result:
|
|
213
|
-
/* 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, parens, sqrt, log, expand, abs, invert, transpose, dot */
|
|
201
|
+
const v = nerdamer('vector(1,2,3)');
|
|
202
|
+
console.log(v.text());
|
|
214
203
|
|
|
215
|
-
|
|
204
|
+
const basis = nerdamer.nullspace(nerdamer('matrix([1,2,3],[2,4,6])'));
|
|
205
|
+
console.log(basis.text());
|
|
206
|
+
```
|
|
216
207
|
|
|
217
|
-
|
|
218
|
-
console.log(reserved);
|
|
219
|
-
//result:
|
|
220
|
-
/* [ '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',
|
|
221
|
-
'parens', 'sqrt', 'log', 'expand', 'abs', 'invert', 'transpose', 'dot' ] */
|
|
222
|
-
```
|
|
208
|
+
## Runtime functions and constants
|
|
223
209
|
|
|
224
|
-
|
|
210
|
+
Custom symbolic functions can be defined with Nerdamer syntax:
|
|
225
211
|
|
|
226
|
-
```javascript
|
|
227
|
-
|
|
212
|
+
```javascript
|
|
213
|
+
nerdamer('hyp(a,b):=sqrt(a^2+b^2)');
|
|
214
|
+
console.log(nerdamer('hyp(3,4)').evaluate().text());
|
|
215
|
+
```
|
|
228
216
|
|
|
229
|
-
|
|
217
|
+
Or use the public function API:
|
|
230
218
|
|
|
231
|
-
|
|
232
|
-
|
|
219
|
+
```javascript
|
|
220
|
+
nerdamer.setFunction('line', ['x', 'm', 'b'], 'm*x+b');
|
|
221
|
+
console.log(nerdamer('line(2,3,4)').text());
|
|
233
222
|
```
|
|
234
|
-
|
|
235
223
|
|
|
236
|
-
|
|
237
|
-
The runtime functions do have symbolic capabilities and support for imaginary numbers.
|
|
238
|
-
The setfunction method is used as follows:
|
|
224
|
+
Constants can be registered as well:
|
|
239
225
|
|
|
240
|
-
|
|
226
|
+
```javascript
|
|
227
|
+
nerdamer.setConstant('g', 9.81);
|
|
228
|
+
console.log(nerdamer('100*g').text());
|
|
229
|
+
```
|
|
241
230
|
|
|
242
|
-
|
|
231
|
+
## Nerdamer scripting
|
|
243
232
|
|
|
244
|
-
|
|
245
|
-
//generate some points
|
|
246
|
-
var f = function(x) { return 5*x-1; }
|
|
247
|
-
console.log(f(1)); //4
|
|
248
|
-
console.log(f(2)); //9 - value to be found
|
|
249
|
-
console.log(f(7)); //34
|
|
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.
|
|
250
234
|
|
|
251
|
-
|
|
252
|
-
|
|
235
|
+
```javascript
|
|
236
|
+
const result = nerdamer('let(x,4,if(x>3,x^2,0))');
|
|
237
|
+
console.log(result.text());
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Multiple statements use semicolons as statement separators:
|
|
253
241
|
|
|
254
|
-
|
|
242
|
+
```javascript
|
|
243
|
+
const result = nerdamer(`
|
|
244
|
+
f(x):=x^2+1;
|
|
245
|
+
f(12)
|
|
246
|
+
`);
|
|
255
247
|
|
|
256
|
-
|
|
248
|
+
console.log(result.text());
|
|
257
249
|
```
|
|
258
250
|
|
|
259
|
-
|
|
251
|
+
## Build a JavaScript function
|
|
252
|
+
|
|
253
|
+
An expression can be compiled to a JavaScript function:
|
|
260
254
|
|
|
261
255
|
```javascript
|
|
262
|
-
|
|
263
|
-
var result = nerdamer('hyp(3, 4)').evaluate().text();
|
|
264
|
-
console.log(result);
|
|
265
|
-
//result: 5
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
If you need to add a constant use the setConstant method
|
|
270
|
-
|
|
271
|
-
```javascript
|
|
272
|
-
nerdamer.setConstant( 'g', 9.81);
|
|
273
|
-
var weight = nerdamer('100*g').text();
|
|
274
|
-
console.log(weight);
|
|
275
|
-
//result:
|
|
276
|
-
//981
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
To delete just set it to delete
|
|
280
|
-
|
|
281
|
-
```javascript
|
|
282
|
-
nerdamer.setConstant( 'g', 9.81);
|
|
283
|
-
var weight = nerdamer('100*g').text();
|
|
284
|
-
console.log(weight);
|
|
285
|
-
//981
|
|
286
|
-
nerdamer.setConstant( 'g', 'delete');
|
|
287
|
-
var weight = nerdamer('100*g').text();
|
|
288
|
-
console.log(weight);
|
|
289
|
-
//100*g
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
You also have the option of exporting your function to a javascript function which can be useful if you need some
|
|
293
|
-
filtering from user input. Do keep in mind that the parameters are sorted alphabetically for more than one
|
|
294
|
-
parameter. To use it add the expression to nerdamer and use the buildFunction method.
|
|
295
|
-
|
|
296
|
-
```javascript
|
|
297
|
-
var f = nerdamer('x^2+5').buildFunction();
|
|
256
|
+
const f = nerdamer('x^2+5').buildFunction();
|
|
298
257
|
console.log(f(9));
|
|
258
|
+
// 86
|
|
259
|
+
```
|
|
299
260
|
|
|
300
|
-
|
|
301
|
-
//86
|
|
302
|
-
```
|
|
303
|
-
If you have a particular order in which you need the parameters to be set, then you pass in an array with the variables in the order in which you want them for instance:
|
|
261
|
+
You can specify the parameter order explicitly:
|
|
304
262
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
```
|
|
263
|
+
```javascript
|
|
264
|
+
const f = nerdamer('z+x^2+y').buildFunction(['y', 'x', 'z']);
|
|
265
|
+
console.log(f(9, 2, 1));
|
|
266
|
+
// 14
|
|
267
|
+
```
|
|
311
268
|
|
|
312
|
-
|
|
313
|
-
the 'expressions' method. To delete an expression use the 'clear' method and pass in the expression you want to delete.
|
|
314
|
-
To clear everything pass in the string 'all'.
|
|
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.
|
|
315
270
|
|
|
316
|
-
|
|
317
|
-
nerdamer('n*R*T/v');
|
|
318
|
-
nerdamer('mc^2');
|
|
319
|
-
nerdamer('G*m1*m2/d^2');
|
|
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.
|
|
320
272
|
|
|
321
|
-
|
|
273
|
+
## TeX
|
|
322
274
|
|
|
323
|
-
|
|
275
|
+
Convert Nerdamer expressions to TeX math markup with `toTeX()` or `convertToTeX()`:
|
|
324
276
|
|
|
325
|
-
|
|
326
|
-
|
|
277
|
+
```javascript
|
|
278
|
+
const e = nerdamer('x^2+2*x+1');
|
|
279
|
+
console.log(e.toTeX());
|
|
327
280
|
|
|
328
|
-
nerdamer.
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
If you need go get the variables of an expression use the variables method. This method can be called after
|
|
335
|
-
nerdamer was provided an expression. For example
|
|
281
|
+
console.log(nerdamer.convertToTeX('sqrt(x^2+1)'));
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The legacy `convertToLaTeX()` name remains available as a deprecated compatibility alias.
|
|
285
|
+
|
|
286
|
+
Nerdamer can also parse supported LaTeX expressions:
|
|
336
287
|
|
|
337
288
|
```javascript
|
|
338
|
-
|
|
339
|
-
console.log(
|
|
340
|
-
//result:
|
|
341
|
-
//[ 'no_boring_x', 'x', 'y' ]
|
|
289
|
+
const e = nerdamer.convertFromLaTeX('\\frac{x^2+1}{2}');
|
|
290
|
+
console.log(e.text());
|
|
342
291
|
```
|
|
343
292
|
|
|
344
|
-
|
|
345
|
-
|
|
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
|
+
```
|
|
346
313
|
|
|
347
|
-
|
|
314
|
+
Additional entry points are available for assumptions, selected parser APIs, advanced algorithms, and debugging tools.
|
|
348
315
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
316
|
+
## Assumptions
|
|
317
|
+
|
|
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.
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
import nerdamer from 'nerdamer';
|
|
322
|
+
import { assume, clearAssumptions } from 'nerdamer/assumptions';
|
|
323
|
+
|
|
324
|
+
assume('x > 0');
|
|
325
|
+
|
|
326
|
+
console.log(nerdamer('sqrt(x^2)').text());
|
|
327
|
+
// x
|
|
328
|
+
|
|
329
|
+
clearAssumptions();
|
|
356
330
|
```
|
|
357
331
|
|
|
358
|
-
|
|
332
|
+
Repeated assumptions for the same symbol are intersected. Contradictory assumptions are rejected instead of silently replacing the existing range.
|
|
333
|
+
|
|
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:
|
|
359
337
|
|
|
360
|
-
You can also solve an expression
|
|
361
338
|
```javascript
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
//
|
|
339
|
+
nerdamer.set('LANGUAGE', 'spa');
|
|
340
|
+
|
|
341
|
+
// Restore English when needed.
|
|
342
|
+
nerdamer.set('LANGUAGE', 'eng');
|
|
365
343
|
```
|
|
366
344
|
|
|
367
|
-
|
|
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`.
|
|
350
|
+
|
|
368
351
|
```javascript
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
//0.5*((-4*y-7)^0.5+1),0.5*(-(-4*y-7)^0.5+1)
|
|
352
|
+
nerdamer('0.1+0.2').text();
|
|
353
|
+
nerdamer('sqrt(2)').evaluate().text();
|
|
372
354
|
```
|
|
373
|
-
You can do up to 3rd order polynomials for multivariate polynomials
|
|
374
355
|
|
|
375
|
-
|
|
356
|
+
## What changed in 2.0
|
|
376
357
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
|
381
384
|
```
|
|
382
|
-
To solve a system of linear equations pass them in as an array. For example
|
|
383
385
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
386
|
+
Run the tests:
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
npm test
|
|
388
390
|
```
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
x = x.evaluate({a: 'x^2-3'});
|
|
395
|
-
console.log(x.toString()); //2+x^2=-7*x^2+21+y
|
|
396
|
-
var solutions = x.solveFor('x');
|
|
397
|
-
console.log(solutions.toString()); //(1/16)*sqrt(32*y+608),(-1/16)*sqrt(32*y+608)
|
|
391
|
+
|
|
392
|
+
Build the complete package:
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
npm run build
|
|
398
396
|
```
|
|
397
|
+
|
|
398
|
+
Validate the npm package as an installed consumer:
|
|
399
|
+
|
|
400
|
+
```bash
|
|
401
|
+
npm run validate:package
|
|
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.
|