nerdamer 2.0.0-rc.1 → 2.0.0
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 -0
- package/README.md +168 -229
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.LICENSE.txt +6 -6
- package/output/algebra/adapters.d.ts +3 -33
- package/output/algebra/adapters.js +7 -105
- package/output/algebra/algorithms/arith.js +10 -9
- package/output/algebra/algorithms/groebnerBase.d.ts +24 -20
- package/output/algebra/algorithms/groebnerBase.js +486 -723
- package/output/algebra/dispatch.d.ts +1 -0
- package/output/algebra/dispatch.js +25 -0
- package/output/algebra/factor/factor.d.ts +15 -0
- package/output/algebra/factor/factor.js +99 -12
- package/output/algebra/gcd/gcd.d.ts +8 -7
- package/output/algebra/gcd/gcd.js +32 -78
- package/output/algebra/groebner.d.ts +2 -2
- package/output/algebra/groebner.js +6 -12
- package/output/algebra/partfrac.d.ts +3 -3
- package/output/algebra/partfrac.js +28 -61
- 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.js +4 -2
- package/output/algebra/simplify/funcsimp.js +1 -1
- package/output/algebra/simplify/ratsimp.js +1 -1
- package/output/algebra/simplify/simplify.js +11 -2
- package/output/algebra/utils.d.ts +1 -1
- package/output/algebra/utils.js +3 -3
- package/output/api/advanced.d.ts +2 -1
- package/output/api/advanced.js +3 -3
- package/output/api/algebra.d.ts +21 -4
- package/output/api/algebra.js +22 -3
- package/output/api/assumptions.d.ts +1 -1
- package/output/api/assumptions.js +2 -1
- package/output/api/calculus.d.ts +2 -1
- package/output/api/calculus.js +2 -1
- package/output/api/core.d.ts +28 -7
- package/output/api/core.js +28 -2
- 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 +10 -2
- package/output/api/parser.js +2 -0
- package/output/api/solve.d.ts +1 -1
- package/output/api/solve.js +2 -1
- package/output/api/structures.d.ts +1 -1
- package/output/api/structures.js +2 -1
- package/output/calculus/adapters.d.ts +8 -0
- package/output/calculus/adapters.js +41 -0
- package/output/calculus/derivative/diff.js +6 -3
- package/output/calculus/dispatch.d.ts +1 -0
- package/output/calculus/dispatch.js +25 -0
- package/output/calculus/integrate/integrate.js +4 -4
- package/output/calculus/integrate/integrationTable.js +16 -16
- package/output/calculus/laplace/ilaplace.js +1 -1
- package/output/calculus/laplace/ilaplaceTable.js +18 -17
- package/output/calculus/laplace/laplaceTable.js +3 -2
- package/output/calculus/limit/limit.js +1 -1
- package/output/core/classes/assumption/Assumption.js +14 -10
- package/output/core/classes/assumption/assume.d.ts +6 -0
- package/output/core/classes/assumption/assume.js +9 -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.js +11 -2
- package/output/core/classes/complex/Complex.d.ts +10 -0
- package/output/core/classes/complex/Complex.js +19 -1
- package/output/core/classes/decimalSet/DecimalSet.js +5 -4
- package/output/core/classes/dictionary/Dictionary.js +4 -1
- package/output/core/classes/expression/CoeffObject.d.ts +1 -1
- package/output/core/classes/expression/CoeffObject.js +1 -2
- package/output/core/classes/expression/Expression.d.ts +35 -26
- package/output/core/classes/expression/Expression.js +77 -50
- package/output/core/classes/expression/analysis.d.ts +1 -1
- package/output/core/classes/expression/analysis.js +7 -7
- package/output/core/classes/expression/format.d.ts +9 -0
- package/output/core/classes/expression/format.js +130 -7
- package/output/core/classes/expression/utils.d.ts +9 -0
- package/output/core/classes/expression/utils.js +52 -6
- package/output/core/classes/matrix/Matrix.d.ts +2 -3
- package/output/core/classes/matrix/Matrix.js +26 -23
- 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 +2 -0
- package/output/core/classes/matrix/functions.js +5 -0
- package/output/core/classes/parser/Parser.d.ts +31 -5
- package/output/core/classes/parser/Parser.js +357 -444
- package/output/core/classes/parser/constants.d.ts +2 -0
- package/output/core/classes/parser/constants.js +4 -2
- package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
- package/output/core/classes/parser/controlFlowSignals.js +60 -0
- package/output/core/classes/parser/operations/add.js +14 -16
- package/output/core/classes/parser/operations/compare.js +13 -0
- package/output/core/classes/parser/operations/functions.d.ts +3 -4
- package/output/core/classes/parser/operations/functions.js +48 -102
- package/output/core/classes/parser/operations/multiply.js +22 -15
- package/output/core/classes/parser/operations/power.js +11 -11
- package/output/core/classes/parser/operations/subtract.js +2 -1
- package/output/core/classes/parser/preprocess.d.ts +0 -7
- package/output/core/classes/parser/preprocess.js +33 -39
- package/output/core/classes/parser/scripting/controlFlow.d.ts +4 -102
- package/output/core/classes/parser/scripting/controlFlow.js +134 -186
- 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 +13 -0
- package/output/core/classes/parser/scripting/evaluate.js +17 -1
- package/output/core/classes/parser/scripting/scope.d.ts +1 -28
- package/output/core/classes/parser/scripting/scope.js +36 -40
- package/output/core/classes/parser/types.d.ts +5 -5
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +4 -3
- package/output/core/classes/parser/wrappers/IndexedReference.js +8 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +2 -2
- package/output/core/classes/polynomial/Polynomial.d.ts +5 -1
- package/output/core/classes/polynomial/Polynomial.js +53 -7
- 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.js +2 -2
- package/output/core/{adapters.d.ts → classes/polynomial/adapters.d.ts} +2 -2
- 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 +8 -0
- package/output/core/classes/polynomial/functions.js +71 -8
- package/output/core/classes/polynomial/utils.js +2 -1
- package/output/core/classes/rational/Rational.d.ts +8 -11
- package/output/core/classes/rational/Rational.js +70 -20
- package/output/core/classes/seq/SEQ.js +4 -4
- package/output/core/classes/valuesSet/ValuesSet.d.ts +9 -1
- package/output/core/classes/valuesSet/ValuesSet.js +22 -4
- package/output/core/classes/vector/Vector.d.ts +2 -3
- package/output/core/classes/vector/Vector.js +11 -15
- package/output/core/classes/vector/dispatch.d.ts +1 -0
- package/output/core/classes/vector/dispatch.js +11 -0
- package/output/core/common/classes/MathematicalAggregate.js +11 -2
- package/output/core/common/classes/StructuredEntity.d.ts +0 -17
- package/output/core/common/classes/StructuredEntity.js +3 -64
- package/output/core/common/common.d.ts +0 -1
- package/output/core/common/common.js +29 -234
- package/output/core/converters/BaseConverter.js +3 -2
- package/output/core/converters/Converter.js +9 -5
- package/output/core/converters/Pattern.js +1 -1
- package/output/core/dispatch.d.ts +18 -0
- package/output/core/dispatch.js +3 -281
- package/output/core/errors.d.ts +259 -474
- package/output/core/errors.js +270 -542
- package/output/core/fullFunctions.d.ts +7 -0
- package/output/core/fullFunctions.js +31 -0
- package/output/core/functions/bigint/bigint.d.ts +13 -1
- package/output/core/functions/bigint/bigint.js +56 -4
- package/output/core/functions/bigint/primeFactor.d.ts +2 -0
- package/output/core/functions/bigint/primeFactor.js +13 -13
- package/output/core/functions/build/definitions.js +6 -0
- package/output/core/functions/complex.d.ts +2 -2
- 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 +7 -7
- package/output/core/functions/decimal.js +2 -1
- package/output/core/functions/expand/expand.js +2 -2
- package/output/core/functions/numeric.d.ts +1 -1
- package/output/core/functions/string.js +2 -1
- package/output/core/functions/subst.js +21 -13
- package/output/core/parserFunctions.d.ts +7 -0
- package/output/core/parserFunctions.js +25 -0
- package/output/index.d.ts +50 -30
- package/output/index.js +147 -19
- package/output/math/defint/defint.d.ts +18 -0
- package/output/math/defint/defint.js +60 -0
- package/output/math/defint/defintDecimal.js +6 -5
- package/output/math/defint/defintNative.js +7 -18
- package/output/math/dispatch.d.ts +1 -0
- package/output/math/dispatch.js +101 -0
- package/output/math/geometry.d.ts +4 -0
- package/output/math/geometry.js +23 -0
- package/output/math/math.d.ts +59 -19
- package/output/math/math.js +244 -100
- package/output/math/trig.js +4 -4
- package/output/math/utils.d.ts +6 -0
- package/output/math/utils.js +39 -0
- package/output/solve/classes/PolynomialSolver.d.ts +33 -14
- package/output/solve/classes/PolynomialSolver.js +267 -67
- package/output/solve/classes/SolutionSet.d.ts +20 -1
- package/output/solve/classes/SolutionSet.js +82 -5
- package/output/solve/dispatch.d.ts +1 -0
- package/output/solve/dispatch.js +13 -0
- package/output/solve/linsolve.d.ts +2 -0
- package/output/solve/linsolve.js +13 -5
- package/output/solve/solve.d.ts +10 -0
- package/output/solve/solve.js +128 -20
- package/output/solve/solveSystem.d.ts +1 -1
- package/output/solve/solveSystem.js +8 -32
- package/output/solve/utils.d.ts +2 -1
- package/output/solve/utils.js +18 -22
- package/output/utils/array.d.ts +1 -1
- package/output/utils/debug.js +2 -1
- package/package.json +22 -38
- package/dist/parser.js +0 -2
- package/dist/parser.js.LICENSE.txt +0 -7
- package/docs-data/parser-functions.json +0 -1960
- package/output/algebra/algorithms/factor.d.ts +0 -3
- package/output/algebra/algorithms/factor.js +0 -5
- package/output/algebra/algorithms/factorMultivariate.d.ts +0 -23
- package/output/algebra/algorithms/factorMultivariate.js +0 -2393
- package/output/algebra/algorithms/factorUnivariate.d.ts +0 -72
- package/output/algebra/algorithms/factorUnivariate.js +0 -1072
- package/output/algebra/algorithms/gcd.d.ts +0 -22
- package/output/algebra/algorithms/gcd.js +0 -690
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +0 -137
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +0 -346
- package/output/algebra/algorithms/poly.d.ts +0 -228
- package/output/algebra/algorithms/poly.js +0 -1299
- package/output/algebra/algorithms/rational.d.ts +0 -17
- package/output/algebra/algorithms/rational.js +0 -115
- package/output/core/adapters.js +0 -40
- package/output/core/classes/parser/operations/comma.d.ts +0 -7
- package/output/core/classes/parser/operations/comma.js +0 -11
package/README.md
CHANGED
|
@@ -1,243 +1,226 @@
|
|
|
1
1
|
# Nerdamer
|
|
2
2
|
|
|
3
|
-
Nerdamer is a symbolic
|
|
3
|
+
Nerdamer is a symbolic mathematics library and computer algebra system for JavaScript and TypeScript.
|
|
4
4
|
|
|
5
|
-
Nerdamer 2.0 is a TypeScript rewrite of
|
|
5
|
+
Nerdamer 2.0 is a TypeScript rewrite of Nerdamer. The familiar string-based API remains available, while the package also exposes typed modules for direct use of the symbolic engine, algebra, calculus, solving, structures, assumptions, parser APIs, and advanced algorithms.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This branch prepares `2.0.0`.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Install
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npm install nerdamer
|
|
12
|
+
npm install nerdamer
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Nerdamer 2.0 is published under npm's `latest` tag.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## Quick start
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
```javascript
|
|
20
|
+
const nerdamer = require('nerdamer');
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const expression = nerdamer('x^2+2*(cos(x)+x*x)');
|
|
23
|
+
console.log(expression.text());
|
|
24
|
+
// 2*cos(x)+3*x^2
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
TypeScript:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import nerdamer from 'nerdamer';
|
|
31
|
+
|
|
32
|
+
const expression = nerdamer('(x+1)^3').expand();
|
|
33
|
+
console.log(expression.text({ sort: true }));
|
|
34
|
+
// x^3+3*x^2+3*x+1
|
|
23
35
|
```
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
TypeScript projects compiling to CommonJS should enable `esModuleInterop`.
|
|
26
38
|
|
|
27
|
-
|
|
39
|
+
## Full package and parser package
|
|
40
|
+
|
|
41
|
+
The normal `nerdamer` entry point assembles the complete CAS. It registers the parser/core and math functions together with algebra, calculus, and solving.
|
|
28
42
|
|
|
29
43
|
```javascript
|
|
30
44
|
const nerdamer = require('nerdamer');
|
|
31
45
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
nerdamer.factor('x^2-1').text();
|
|
47
|
+
nerdamer.diff('x^3', 'x').text();
|
|
48
|
+
nerdamer.solve('x^2-4', 'x').text();
|
|
35
49
|
```
|
|
36
50
|
|
|
37
|
-
|
|
51
|
+
Nerdamer 2.0 also has a separate parser entry point. It contains the symbolic parser, scripting, assumptions, structures, complex and polynomial operations, and general math functions without loading the higher-level algebra, calculus, and solver domains.
|
|
38
52
|
|
|
39
53
|
```typescript
|
|
40
|
-
import
|
|
54
|
+
import { Parser } from 'nerdamer/parser';
|
|
41
55
|
|
|
42
|
-
|
|
56
|
+
const expression = Parser.parse('sqrt(x^2+1)');
|
|
57
|
+
console.log(expression.text());
|
|
43
58
|
```
|
|
44
59
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### Browser use
|
|
60
|
+
This separation is also reflected in the browser builds:
|
|
48
61
|
|
|
49
|
-
|
|
62
|
+
- `dist/bundle.js` — complete Nerdamer package;
|
|
63
|
+
- `dist/parser.js` — parser-focused browser bundle.
|
|
50
64
|
|
|
51
65
|
```html
|
|
52
66
|
<script src="./node_modules/nerdamer/dist/bundle.js"></script>
|
|
53
67
|
<script>
|
|
54
|
-
|
|
55
|
-
console.log(e.text());
|
|
68
|
+
console.log(nerdamer('factor(x^2-1)').text());
|
|
56
69
|
</script>
|
|
57
70
|
```
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
The parser bundle exposes `nerdamerParser` rather than the complete `nerdamer` API.
|
|
60
73
|
|
|
61
|
-
|
|
74
|
+
## Package entry points
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
const nerdamer = require('nerdamer');
|
|
76
|
+
The npm package exports the complete callable API plus typed module entry points:
|
|
65
77
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
```typescript
|
|
79
|
+
import nerdamer from 'nerdamer';
|
|
80
|
+
import { Expression, Rational, type TextOptions } from 'nerdamer/core';
|
|
81
|
+
import { Polynomial, gcd, lcm, partfrac } from 'nerdamer/algebra';
|
|
82
|
+
import { diff, integrate, limit } from 'nerdamer/calculus';
|
|
83
|
+
import { solve, PolynomialSolver } from 'nerdamer/solve';
|
|
84
|
+
import { Matrix, Vector, ValuesSet } from 'nerdamer/structures';
|
|
85
|
+
import { assume, clearAssumptions } from 'nerdamer/assumptions';
|
|
86
|
+
import { Parser } from 'nerdamer/parser';
|
|
69
87
|
```
|
|
70
88
|
|
|
71
|
-
|
|
89
|
+
Additional supported entry points are `nerdamer/advanced` and `nerdamer/debug`.
|
|
72
90
|
|
|
73
|
-
|
|
91
|
+
## Parser results
|
|
92
|
+
|
|
93
|
+
`nerdamer(...)` returns the Nerdamer entity represented by the input. Scalar symbolic input normally returns an `Expression`; equations and structured notation can return `Equation`, `Vector`, `Matrix`, `Collection`, `ValuesSet`, or `Dictionary`.
|
|
74
94
|
|
|
75
95
|
```javascript
|
|
76
|
-
const
|
|
77
|
-
|
|
96
|
+
const scalar = nerdamer('x^2+1');
|
|
97
|
+
const equation = nerdamer('x^2=1');
|
|
98
|
+
const vector = nerdamer('[x, y, 3]');
|
|
78
99
|
```
|
|
79
100
|
|
|
80
|
-
|
|
101
|
+
This is intentional. Nerdamer 2.0 does not wrap every parser result in a compatibility `Expression` object.
|
|
102
|
+
|
|
103
|
+
## Substitution and evaluation
|
|
104
|
+
|
|
105
|
+
Values supplied to `nerdamer(...)` are substitutions. They do not imply numerical evaluation.
|
|
81
106
|
|
|
82
107
|
```javascript
|
|
83
|
-
const
|
|
84
|
-
|
|
108
|
+
const substituted = nerdamer('x^2+cos(x)', { x: 6 });
|
|
109
|
+
const evaluated = substituted.evaluate();
|
|
85
110
|
```
|
|
86
111
|
|
|
87
|
-
Values can themselves be expressions:
|
|
112
|
+
Values can themselves be symbolic expressions:
|
|
88
113
|
|
|
89
114
|
```javascript
|
|
90
|
-
|
|
91
|
-
console.log(e.text());
|
|
115
|
+
nerdamer('x^2+1', { x: 'y+1' }).text();
|
|
92
116
|
```
|
|
93
117
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
## Text output and term ordering
|
|
118
|
+
## Text and TeX output
|
|
97
119
|
|
|
98
|
-
`text()` returns Nerdamer
|
|
99
|
-
may place the constant term first:
|
|
120
|
+
`text()` returns Nerdamer notation. Term ordering can be requested per call:
|
|
100
121
|
|
|
101
122
|
```javascript
|
|
102
|
-
const
|
|
123
|
+
const expression = nerdamer('x^2+2*x+1');
|
|
103
124
|
|
|
104
|
-
|
|
125
|
+
expression.text();
|
|
105
126
|
// 1+2*x+x^2
|
|
127
|
+
|
|
128
|
+
expression.text({ sort: true });
|
|
129
|
+
// x^2+2*x+1
|
|
106
130
|
```
|
|
107
131
|
|
|
108
|
-
|
|
132
|
+
The full package also supplies `toText()` and TeX conversion:
|
|
109
133
|
|
|
110
134
|
```javascript
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
nerdamer('
|
|
115
|
-
// x^2+2*x+1
|
|
135
|
+
expression.toText();
|
|
136
|
+
expression.toTeX();
|
|
137
|
+
nerdamer.convertToTeX('sqrt(x^2+1)');
|
|
138
|
+
nerdamer.convertFromLaTeX('\\frac{x^2+1}{2}');
|
|
116
139
|
```
|
|
117
140
|
|
|
118
|
-
|
|
119
|
-
process-wide `SORT_TERMS` setting. TypeScript users can import `TextOptions` from
|
|
120
|
-
`nerdamer` or `nerdamer/core`.
|
|
141
|
+
`convertToLaTeX()` remains as a deprecated compatibility alias.
|
|
121
142
|
|
|
122
|
-
|
|
143
|
+
Scientific formatting can be requested through `text()` without changing the underlying expression:
|
|
123
144
|
|
|
124
145
|
```javascript
|
|
125
|
-
|
|
126
|
-
//
|
|
146
|
+
nerdamer('1200').text({ scientific: 4 });
|
|
147
|
+
// 1.200e3
|
|
127
148
|
```
|
|
128
149
|
|
|
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
150
|
## Algebra
|
|
134
151
|
|
|
135
|
-
Nerdamer can expand, factor, simplify, compute polynomial GCDs, and perform related symbolic algebra operations.
|
|
136
|
-
|
|
137
152
|
```javascript
|
|
138
|
-
nerdamer('
|
|
153
|
+
nerdamer.expand('(x+1)^4').text();
|
|
139
154
|
nerdamer.factor('x^4-1').text();
|
|
140
155
|
nerdamer.simplify('sin(x)^2+cos(x)^2').text();
|
|
141
156
|
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
|
+
nerdamer.partfrac('1/(x^2-1)', 'x').text();
|
|
151
158
|
```
|
|
152
159
|
|
|
153
|
-
|
|
160
|
+
The 2.0 algebra implementation includes the rewritten polynomial GCD/factorization path, partial fractions, polynomial solving support, and direct polynomial APIs.
|
|
154
161
|
|
|
155
|
-
|
|
162
|
+
Prime factorization has two explicit forms:
|
|
156
163
|
|
|
157
164
|
```javascript
|
|
158
|
-
|
|
159
|
-
|
|
165
|
+
nerdamer.pfactor(100).text();
|
|
166
|
+
// [2,2,5,5]
|
|
160
167
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
Single-variable solving returns a `SolutionSet`. System solving returns Nerdamer structures rather than the compatibility-only arrays used by older releases.
|
|
167
|
-
|
|
168
|
-
```javascript
|
|
169
|
-
const solutions = nerdamer.solveSystem(
|
|
170
|
-
['x+y=3', 'x-y=1'],
|
|
171
|
-
['x', 'y']
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
console.log(solutions.text());
|
|
168
|
+
nerdamer.pfactord(100).text();
|
|
169
|
+
// {2=>2,5=>2}
|
|
175
170
|
```
|
|
176
171
|
|
|
177
172
|
## Calculus
|
|
178
173
|
|
|
179
|
-
Differentiation, integration, limits, sums, products, and transforms are available without loading a separate add-on.
|
|
180
|
-
|
|
181
174
|
```javascript
|
|
182
175
|
nerdamer.diff('x^3+sin(x)', 'x').text();
|
|
183
176
|
nerdamer.integrate('x^2', 'x').text();
|
|
184
177
|
nerdamer.limit('sin(x)/x', 'x', '0').text();
|
|
178
|
+
nerdamer.laplace('t', 't', 's').text();
|
|
185
179
|
```
|
|
186
180
|
|
|
187
|
-
|
|
181
|
+
The same functions can be used in Nerdamer notation:
|
|
188
182
|
|
|
189
183
|
```javascript
|
|
190
|
-
nerdamer('diff(x^
|
|
184
|
+
nerdamer('diff(x^3,x)').text();
|
|
191
185
|
```
|
|
192
186
|
|
|
193
|
-
##
|
|
187
|
+
## Solving
|
|
194
188
|
|
|
195
|
-
|
|
189
|
+
Single-variable solving returns a `SolutionSet`:
|
|
196
190
|
|
|
197
191
|
```javascript
|
|
198
|
-
const
|
|
199
|
-
console.log(
|
|
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());
|
|
192
|
+
const roots = nerdamer.solve('x^2-1', 'x');
|
|
193
|
+
console.log(roots.text());
|
|
206
194
|
```
|
|
207
195
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
Custom symbolic functions can be defined with Nerdamer syntax:
|
|
196
|
+
System solving returns Nerdamer structures rather than legacy JavaScript arrays:
|
|
211
197
|
|
|
212
198
|
```javascript
|
|
213
|
-
nerdamer(
|
|
214
|
-
|
|
199
|
+
const solutions = nerdamer.solveSystem(
|
|
200
|
+
['x+y=3', 'x-y=1'],
|
|
201
|
+
['x', 'y']
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
console.log(solutions.text());
|
|
215
205
|
```
|
|
216
206
|
|
|
217
|
-
|
|
207
|
+
The legacy `solveeqs` name is retained as the compatibility alias for system solving. `solveEquations` is not part of the 2.0 public API.
|
|
218
208
|
|
|
219
|
-
|
|
220
|
-
nerdamer.setFunction('line', ['x', 'm', 'b'], 'm*x+b');
|
|
221
|
-
console.log(nerdamer('line(2,3,4)').text());
|
|
222
|
-
```
|
|
209
|
+
## Matrices, vectors, sets, and dictionaries
|
|
223
210
|
|
|
224
|
-
|
|
211
|
+
Structured values are first-class parser entities:
|
|
225
212
|
|
|
226
213
|
```javascript
|
|
227
|
-
nerdamer
|
|
228
|
-
|
|
214
|
+
nerdamer('matrix([1,2],[3,4])').text();
|
|
215
|
+
nerdamer('[1,x,3]').text();
|
|
216
|
+
nerdamer('{1,2,x}').text();
|
|
229
217
|
```
|
|
230
218
|
|
|
231
|
-
|
|
219
|
+
The corresponding TypeScript classes are exported from `nerdamer/structures`.
|
|
232
220
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
```javascript
|
|
236
|
-
const result = nerdamer('let(x,4,if(x>3,x^2,0))');
|
|
237
|
-
console.log(result.text());
|
|
238
|
-
```
|
|
221
|
+
## Scripting
|
|
239
222
|
|
|
240
|
-
|
|
223
|
+
Nerdamer notation includes a symbolic scripting layer with assignments, user functions, local bindings, conditionals, loops, blocks, logical operations, `return`, `break`, `continue`, and error-handling helpers.
|
|
241
224
|
|
|
242
225
|
```javascript
|
|
243
226
|
const result = nerdamer(`
|
|
@@ -248,160 +231,116 @@ const result = nerdamer(`
|
|
|
248
231
|
console.log(result.text());
|
|
249
232
|
```
|
|
250
233
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
An expression can be compiled to a JavaScript function:
|
|
254
|
-
|
|
255
|
-
```javascript
|
|
256
|
-
const f = nerdamer('x^2+5').buildFunction();
|
|
257
|
-
console.log(f(9));
|
|
258
|
-
// 86
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
You can specify the parameter order explicitly:
|
|
262
|
-
|
|
263
|
-
```javascript
|
|
264
|
-
const f = nerdamer('z+x^2+y').buildFunction(['y', 'x', 'z']);
|
|
265
|
-
console.log(f(9, 2, 1));
|
|
266
|
-
// 14
|
|
267
|
-
```
|
|
268
|
-
|
|
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
|
-
|
|
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
|
-
|
|
273
|
-
## TeX
|
|
234
|
+
Control-flow operations that intentionally produce no mathematical value use an internal null signal. That signal is distinct from legitimate values such as an empty vector and is not exposed as a normal parser entity.
|
|
274
235
|
|
|
275
|
-
|
|
236
|
+
## Runtime functions, constants, and settings
|
|
276
237
|
|
|
277
238
|
```javascript
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
console.log(nerdamer.convertToTeX('sqrt(x^2+1)'));
|
|
239
|
+
nerdamer.setFunction('line', ['x', 'm', 'b'], 'm*x+b');
|
|
240
|
+
nerdamer.setConstant('g', 9.81);
|
|
241
|
+
nerdamer.setVar('a', 5);
|
|
282
242
|
```
|
|
283
243
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
Nerdamer can also parse supported LaTeX expressions:
|
|
244
|
+
Settings remain shared by the package instance:
|
|
287
245
|
|
|
288
246
|
```javascript
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
```
|
|
292
|
-
|
|
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';
|
|
247
|
+
nerdamer.set('LANGUAGE', 'spa');
|
|
248
|
+
nerdamer.set('LANGUAGE', 'eng');
|
|
312
249
|
```
|
|
313
250
|
|
|
314
|
-
|
|
251
|
+
Built-in error messages are available in English, Spanish, French, German, Portuguese, Italian, and Dutch.
|
|
315
252
|
|
|
316
253
|
## Assumptions
|
|
317
254
|
|
|
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
255
|
```typescript
|
|
321
256
|
import nerdamer from 'nerdamer';
|
|
322
257
|
import { assume, clearAssumptions } from 'nerdamer/assumptions';
|
|
323
258
|
|
|
324
259
|
assume('x > 0');
|
|
325
|
-
|
|
326
260
|
console.log(nerdamer('sqrt(x^2)').text());
|
|
327
261
|
// x
|
|
328
|
-
|
|
329
262
|
clearAssumptions();
|
|
330
263
|
```
|
|
331
264
|
|
|
332
|
-
Repeated assumptions for
|
|
265
|
+
Repeated assumptions for a symbol are intersected. Contradictory assumptions are rejected.
|
|
333
266
|
|
|
334
|
-
##
|
|
267
|
+
## Building JavaScript functions
|
|
335
268
|
|
|
336
|
-
|
|
269
|
+
Scalar expressions can be compiled to native JavaScript-number functions:
|
|
337
270
|
|
|
338
271
|
```javascript
|
|
339
|
-
nerdamer
|
|
340
|
-
|
|
341
|
-
//
|
|
342
|
-
nerdamer.set('LANGUAGE', 'eng');
|
|
272
|
+
const f = nerdamer('x^2+5').buildFunction();
|
|
273
|
+
console.log(f(9));
|
|
274
|
+
// 86
|
|
343
275
|
```
|
|
344
276
|
|
|
345
|
-
|
|
277
|
+
`buildFunction()` uses dynamic JavaScript function construction. Applications whose Content Security Policy blocks dynamic code generation should use Nerdamer's symbolic or numeric evaluation APIs instead. Structured parser results cannot be compiled as scalar functions.
|
|
346
278
|
|
|
347
|
-
## Numeric
|
|
279
|
+
## Numeric behavior
|
|
348
280
|
|
|
349
|
-
Nerdamer
|
|
281
|
+
Nerdamer preserves exact integer and rational arithmetic where possible. Large integers use native `BigInt`; decimal arithmetic uses Decimal.js. Complex arithmetic is represented by Nerdamer's numeric types rather than JavaScript's native `Number` alone.
|
|
350
282
|
|
|
351
283
|
```javascript
|
|
352
284
|
nerdamer('0.1+0.2').text();
|
|
353
285
|
nerdamer('sqrt(2)').evaluate().text();
|
|
354
286
|
```
|
|
355
287
|
|
|
356
|
-
##
|
|
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
|
|
288
|
+
## Building from source
|
|
373
289
|
|
|
374
|
-
|
|
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:
|
|
290
|
+
Install dependencies and run the normal checks:
|
|
381
291
|
|
|
382
292
|
```bash
|
|
293
|
+
npm install
|
|
383
294
|
npm run typecheck
|
|
295
|
+
npm test
|
|
384
296
|
```
|
|
385
297
|
|
|
386
|
-
|
|
298
|
+
Build the complete package:
|
|
387
299
|
|
|
388
300
|
```bash
|
|
389
|
-
npm
|
|
301
|
+
npm run build
|
|
390
302
|
```
|
|
391
303
|
|
|
392
|
-
Build the
|
|
304
|
+
Build the parser-only browser bundle:
|
|
393
305
|
|
|
394
306
|
```bash
|
|
395
|
-
npm run build
|
|
307
|
+
npm run build:parser
|
|
396
308
|
```
|
|
397
309
|
|
|
398
|
-
|
|
310
|
+
Browser bundles include English by default. Additional error-message catalogs can be selected with a comma-separated language list:
|
|
399
311
|
|
|
400
312
|
```bash
|
|
401
|
-
|
|
313
|
+
npx webpack --mode=production --env target=full --env language=spa,fra
|
|
402
314
|
```
|
|
403
315
|
|
|
404
|
-
The
|
|
316
|
+
The supported codes are `eng`, `spa`, `fra`, `deu`, `por`, `ita`, and `nld`. English is always available. The first selected non-English language becomes active when the bundle loads; the remaining selected catalogs are available for runtime switching. Duplicate codes are ignored. Use `--env language=all` to include every translated catalog. `all` cannot be combined with individual language codes.
|
|
317
|
+
|
|
318
|
+
Before publishing, the package runs type checking, tests, coverage, both browser builds, parser documentation generation, TypeDoc validation, and packed-package validation through `prepublishOnly`.
|
|
319
|
+
|
|
320
|
+
## Migrating from Nerdamer 1.x
|
|
321
|
+
|
|
322
|
+
Nerdamer 2.0 keeps much of the familiar expression-oriented API, but it is a new implementation. Important migration areas include:
|
|
323
|
+
|
|
324
|
+
- the old `Algebra`, `Calculus`, `Solve`, and `Extra` side-effect imports are replaced by the complete package and supported module entry points;
|
|
325
|
+
- the third and fourth arguments to `nerdamer(...)` are gone;
|
|
326
|
+
- global parsed-expression history is gone;
|
|
327
|
+
- parser results can be structured Nerdamer entities instead of always being wrapped in a compatibility `Expression`;
|
|
328
|
+
- system-solving results use `Vector`/`Dictionary` structures;
|
|
329
|
+
- lower-level 1.x extension hooks such as `getCore()` and `register()` are not restored;
|
|
330
|
+
- several compatibility functions were restored explicitly rather than by exposing every parser function on the root object;
|
|
331
|
+
- internal numeric, parser, solver, polynomial, assumptions, set, and scripting implementations have changed substantially.
|
|
332
|
+
|
|
333
|
+
See [BREAKING_CHANGES.md](BREAKING_CHANGES.md) and [Moving from Nerdamer 1.x to 2.0](docs/MIGRATING_FROM_1X.md) before upgrading an existing application.
|
|
334
|
+
|
|
335
|
+
## Documentation
|
|
336
|
+
|
|
337
|
+
- Website: https://nerdamer.com/
|
|
338
|
+
- Documentation: https://nerdamer.com/documentation
|
|
339
|
+
- Migration guide: `docs/MIGRATING_FROM_1X.md`
|
|
340
|
+
- 2.0 release notes: `docs/RELEASE_NOTES_2.md`
|
|
341
|
+
- Parser conventions: `docs/PARSER_CONVENTIONS.md`
|
|
342
|
+
- Source repository: https://github.com/jiggzson/nerdamer
|
|
343
|
+
- Issues: https://github.com/jiggzson/nerdamer/issues
|
|
405
344
|
|
|
406
345
|
## License
|
|
407
346
|
|