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.
Files changed (236) hide show
  1. package/BREAKING_CHANGES.md +244 -0
  2. package/README.md +168 -229
  3. package/dist/bundle.js +1 -1
  4. package/dist/bundle.js.LICENSE.txt +6 -6
  5. package/output/algebra/adapters.d.ts +3 -33
  6. package/output/algebra/adapters.js +7 -105
  7. package/output/algebra/algorithms/arith.js +10 -9
  8. package/output/algebra/algorithms/groebnerBase.d.ts +24 -20
  9. package/output/algebra/algorithms/groebnerBase.js +486 -723
  10. package/output/algebra/dispatch.d.ts +1 -0
  11. package/output/algebra/dispatch.js +25 -0
  12. package/output/algebra/factor/factor.d.ts +15 -0
  13. package/output/algebra/factor/factor.js +99 -12
  14. package/output/algebra/gcd/gcd.d.ts +8 -7
  15. package/output/algebra/gcd/gcd.js +32 -78
  16. package/output/algebra/groebner.d.ts +2 -2
  17. package/output/algebra/groebner.js +6 -12
  18. package/output/algebra/partfrac.d.ts +3 -3
  19. package/output/algebra/partfrac.js +28 -61
  20. package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
  21. package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
  22. package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
  23. package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
  24. package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
  25. package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
  26. package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
  27. package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
  28. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
  29. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
  30. package/output/algebra/polynomial/modularGcd.d.ts +40 -0
  31. package/output/algebra/polynomial/modularGcd.js +365 -0
  32. package/output/algebra/polynomialize.js +4 -2
  33. package/output/algebra/simplify/funcsimp.js +1 -1
  34. package/output/algebra/simplify/ratsimp.js +1 -1
  35. package/output/algebra/simplify/simplify.js +11 -2
  36. package/output/algebra/utils.d.ts +1 -1
  37. package/output/algebra/utils.js +3 -3
  38. package/output/api/advanced.d.ts +2 -1
  39. package/output/api/advanced.js +3 -3
  40. package/output/api/algebra.d.ts +21 -4
  41. package/output/api/algebra.js +22 -3
  42. package/output/api/assumptions.d.ts +1 -1
  43. package/output/api/assumptions.js +2 -1
  44. package/output/api/calculus.d.ts +2 -1
  45. package/output/api/calculus.js +2 -1
  46. package/output/api/core.d.ts +28 -7
  47. package/output/api/core.js +28 -2
  48. package/output/api/languages/deu.d.ts +3 -0
  49. package/output/api/languages/deu.js +266 -0
  50. package/output/api/languages/fra.d.ts +3 -0
  51. package/output/api/languages/fra.js +266 -0
  52. package/output/api/languages/ita.d.ts +3 -0
  53. package/output/api/languages/ita.js +266 -0
  54. package/output/api/languages/nld.d.ts +3 -0
  55. package/output/api/languages/nld.js +266 -0
  56. package/output/api/languages/por.d.ts +3 -0
  57. package/output/api/languages/por.js +266 -0
  58. package/output/api/languages/spa.d.ts +3 -0
  59. package/output/api/languages/spa.js +266 -0
  60. package/output/api/parser.d.ts +10 -2
  61. package/output/api/parser.js +2 -0
  62. package/output/api/solve.d.ts +1 -1
  63. package/output/api/solve.js +2 -1
  64. package/output/api/structures.d.ts +1 -1
  65. package/output/api/structures.js +2 -1
  66. package/output/calculus/adapters.d.ts +8 -0
  67. package/output/calculus/adapters.js +41 -0
  68. package/output/calculus/derivative/diff.js +6 -3
  69. package/output/calculus/dispatch.d.ts +1 -0
  70. package/output/calculus/dispatch.js +25 -0
  71. package/output/calculus/integrate/integrate.js +4 -4
  72. package/output/calculus/integrate/integrationTable.js +16 -16
  73. package/output/calculus/laplace/ilaplace.js +1 -1
  74. package/output/calculus/laplace/ilaplaceTable.js +18 -17
  75. package/output/calculus/laplace/laplaceTable.js +3 -2
  76. package/output/calculus/limit/limit.js +1 -1
  77. package/output/core/classes/assumption/Assumption.js +14 -10
  78. package/output/core/classes/assumption/assume.d.ts +6 -0
  79. package/output/core/classes/assumption/assume.js +9 -0
  80. package/output/core/classes/assumption/dispatch.d.ts +1 -0
  81. package/output/core/classes/assumption/dispatch.js +11 -0
  82. package/output/core/classes/collection/Collection.js +11 -2
  83. package/output/core/classes/complex/Complex.d.ts +10 -0
  84. package/output/core/classes/complex/Complex.js +19 -1
  85. package/output/core/classes/decimalSet/DecimalSet.js +5 -4
  86. package/output/core/classes/dictionary/Dictionary.js +4 -1
  87. package/output/core/classes/expression/CoeffObject.d.ts +1 -1
  88. package/output/core/classes/expression/CoeffObject.js +1 -2
  89. package/output/core/classes/expression/Expression.d.ts +35 -26
  90. package/output/core/classes/expression/Expression.js +77 -50
  91. package/output/core/classes/expression/analysis.d.ts +1 -1
  92. package/output/core/classes/expression/analysis.js +7 -7
  93. package/output/core/classes/expression/format.d.ts +9 -0
  94. package/output/core/classes/expression/format.js +130 -7
  95. package/output/core/classes/expression/utils.d.ts +9 -0
  96. package/output/core/classes/expression/utils.js +52 -6
  97. package/output/core/classes/matrix/Matrix.d.ts +2 -3
  98. package/output/core/classes/matrix/Matrix.js +26 -23
  99. package/output/core/classes/matrix/dispatch.d.ts +1 -0
  100. package/output/core/classes/matrix/dispatch.js +19 -0
  101. package/output/core/classes/matrix/functions.d.ts +2 -0
  102. package/output/core/classes/matrix/functions.js +5 -0
  103. package/output/core/classes/parser/Parser.d.ts +31 -5
  104. package/output/core/classes/parser/Parser.js +357 -444
  105. package/output/core/classes/parser/constants.d.ts +2 -0
  106. package/output/core/classes/parser/constants.js +4 -2
  107. package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
  108. package/output/core/classes/parser/controlFlowSignals.js +60 -0
  109. package/output/core/classes/parser/operations/add.js +14 -16
  110. package/output/core/classes/parser/operations/compare.js +13 -0
  111. package/output/core/classes/parser/operations/functions.d.ts +3 -4
  112. package/output/core/classes/parser/operations/functions.js +48 -102
  113. package/output/core/classes/parser/operations/multiply.js +22 -15
  114. package/output/core/classes/parser/operations/power.js +11 -11
  115. package/output/core/classes/parser/operations/subtract.js +2 -1
  116. package/output/core/classes/parser/preprocess.d.ts +0 -7
  117. package/output/core/classes/parser/preprocess.js +33 -39
  118. package/output/core/classes/parser/scripting/controlFlow.d.ts +4 -102
  119. package/output/core/classes/parser/scripting/controlFlow.js +134 -186
  120. package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
  121. package/output/core/classes/parser/scripting/deferred.js +65 -0
  122. package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
  123. package/output/core/classes/parser/scripting/dispatch.js +62 -0
  124. package/output/core/classes/parser/scripting/evaluate.d.ts +13 -0
  125. package/output/core/classes/parser/scripting/evaluate.js +17 -1
  126. package/output/core/classes/parser/scripting/scope.d.ts +1 -28
  127. package/output/core/classes/parser/scripting/scope.js +36 -40
  128. package/output/core/classes/parser/types.d.ts +5 -5
  129. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +4 -3
  130. package/output/core/classes/parser/wrappers/IndexedReference.js +8 -0
  131. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +2 -2
  132. package/output/core/classes/polynomial/Polynomial.d.ts +5 -1
  133. package/output/core/classes/polynomial/Polynomial.js +53 -7
  134. package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
  135. package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
  136. package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
  137. package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -0
  138. package/output/core/classes/polynomial/Term.js +2 -2
  139. package/output/core/{adapters.d.ts → classes/polynomial/adapters.d.ts} +2 -2
  140. package/output/core/classes/polynomial/adapters.js +33 -0
  141. package/output/core/classes/polynomial/dispatch.d.ts +1 -0
  142. package/output/core/classes/polynomial/dispatch.js +14 -0
  143. package/output/core/classes/polynomial/functions.d.ts +8 -0
  144. package/output/core/classes/polynomial/functions.js +71 -8
  145. package/output/core/classes/polynomial/utils.js +2 -1
  146. package/output/core/classes/rational/Rational.d.ts +8 -11
  147. package/output/core/classes/rational/Rational.js +70 -20
  148. package/output/core/classes/seq/SEQ.js +4 -4
  149. package/output/core/classes/valuesSet/ValuesSet.d.ts +9 -1
  150. package/output/core/classes/valuesSet/ValuesSet.js +22 -4
  151. package/output/core/classes/vector/Vector.d.ts +2 -3
  152. package/output/core/classes/vector/Vector.js +11 -15
  153. package/output/core/classes/vector/dispatch.d.ts +1 -0
  154. package/output/core/classes/vector/dispatch.js +11 -0
  155. package/output/core/common/classes/MathematicalAggregate.js +11 -2
  156. package/output/core/common/classes/StructuredEntity.d.ts +0 -17
  157. package/output/core/common/classes/StructuredEntity.js +3 -64
  158. package/output/core/common/common.d.ts +0 -1
  159. package/output/core/common/common.js +29 -234
  160. package/output/core/converters/BaseConverter.js +3 -2
  161. package/output/core/converters/Converter.js +9 -5
  162. package/output/core/converters/Pattern.js +1 -1
  163. package/output/core/dispatch.d.ts +18 -0
  164. package/output/core/dispatch.js +3 -281
  165. package/output/core/errors.d.ts +259 -474
  166. package/output/core/errors.js +270 -542
  167. package/output/core/fullFunctions.d.ts +7 -0
  168. package/output/core/fullFunctions.js +31 -0
  169. package/output/core/functions/bigint/bigint.d.ts +13 -1
  170. package/output/core/functions/bigint/bigint.js +56 -4
  171. package/output/core/functions/bigint/primeFactor.d.ts +2 -0
  172. package/output/core/functions/bigint/primeFactor.js +13 -13
  173. package/output/core/functions/build/definitions.js +6 -0
  174. package/output/core/functions/complex.d.ts +2 -2
  175. package/output/core/functions/complex.dispatch.d.ts +1 -0
  176. package/output/core/functions/complex.dispatch.js +16 -0
  177. package/output/core/functions/complex.js +7 -7
  178. package/output/core/functions/decimal.js +2 -1
  179. package/output/core/functions/expand/expand.js +2 -2
  180. package/output/core/functions/numeric.d.ts +1 -1
  181. package/output/core/functions/string.js +2 -1
  182. package/output/core/functions/subst.js +21 -13
  183. package/output/core/parserFunctions.d.ts +7 -0
  184. package/output/core/parserFunctions.js +25 -0
  185. package/output/index.d.ts +50 -30
  186. package/output/index.js +147 -19
  187. package/output/math/defint/defint.d.ts +18 -0
  188. package/output/math/defint/defint.js +60 -0
  189. package/output/math/defint/defintDecimal.js +6 -5
  190. package/output/math/defint/defintNative.js +7 -18
  191. package/output/math/dispatch.d.ts +1 -0
  192. package/output/math/dispatch.js +101 -0
  193. package/output/math/geometry.d.ts +4 -0
  194. package/output/math/geometry.js +23 -0
  195. package/output/math/math.d.ts +59 -19
  196. package/output/math/math.js +244 -100
  197. package/output/math/trig.js +4 -4
  198. package/output/math/utils.d.ts +6 -0
  199. package/output/math/utils.js +39 -0
  200. package/output/solve/classes/PolynomialSolver.d.ts +33 -14
  201. package/output/solve/classes/PolynomialSolver.js +267 -67
  202. package/output/solve/classes/SolutionSet.d.ts +20 -1
  203. package/output/solve/classes/SolutionSet.js +82 -5
  204. package/output/solve/dispatch.d.ts +1 -0
  205. package/output/solve/dispatch.js +13 -0
  206. package/output/solve/linsolve.d.ts +2 -0
  207. package/output/solve/linsolve.js +13 -5
  208. package/output/solve/solve.d.ts +10 -0
  209. package/output/solve/solve.js +128 -20
  210. package/output/solve/solveSystem.d.ts +1 -1
  211. package/output/solve/solveSystem.js +8 -32
  212. package/output/solve/utils.d.ts +2 -1
  213. package/output/solve/utils.js +18 -22
  214. package/output/utils/array.d.ts +1 -1
  215. package/output/utils/debug.js +2 -1
  216. package/package.json +22 -38
  217. package/dist/parser.js +0 -2
  218. package/dist/parser.js.LICENSE.txt +0 -7
  219. package/docs-data/parser-functions.json +0 -1960
  220. package/output/algebra/algorithms/factor.d.ts +0 -3
  221. package/output/algebra/algorithms/factor.js +0 -5
  222. package/output/algebra/algorithms/factorMultivariate.d.ts +0 -23
  223. package/output/algebra/algorithms/factorMultivariate.js +0 -2393
  224. package/output/algebra/algorithms/factorUnivariate.d.ts +0 -72
  225. package/output/algebra/algorithms/factorUnivariate.js +0 -1072
  226. package/output/algebra/algorithms/gcd.d.ts +0 -22
  227. package/output/algebra/algorithms/gcd.js +0 -690
  228. package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +0 -137
  229. package/output/algebra/algorithms/multiPoly/MultiPoly.js +0 -346
  230. package/output/algebra/algorithms/poly.d.ts +0 -228
  231. package/output/algebra/algorithms/poly.js +0 -1299
  232. package/output/algebra/algorithms/rational.d.ts +0 -17
  233. package/output/algebra/algorithms/rational.js +0 -115
  234. package/output/core/adapters.js +0 -40
  235. package/output/core/classes/parser/operations/comma.d.ts +0 -7
  236. 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 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.
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 the library. Everyday usage remains familiar, while the parser, solvers, numeric handling, public types, and internal architecture have been substantially reworked.
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
- ## Getting started with Nerdamer
7
+ This branch prepares `2.0.0`.
8
8
 
9
- Nerdamer 2.0 is currently available as a release candidate under the npm `next` tag:
9
+ ## Install
10
10
 
11
11
  ```bash
12
- npm install nerdamer@next
12
+ npm install nerdamer
13
13
  ```
14
14
 
15
- When Nerdamer 2.0 becomes the stable `latest` release, the normal `npm install nerdamer` command will install the 2.x line.
15
+ Nerdamer 2.0 is published under npm's `latest` tag.
16
16
 
17
- ### Need to stay on the 1.x line?
17
+ ## Quick start
18
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:
19
+ ```javascript
20
+ const nerdamer = require('nerdamer');
20
21
 
21
- ```bash
22
- npm install nerdamer-prime
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
- 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
+ TypeScript projects compiling to CommonJS should enable `esModuleInterop`.
26
38
 
27
- In Node.js, require the package and start working with expressions:
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
- const e = nerdamer('x^2+2*(cos(x)+x*x)');
33
- console.log(e.text());
34
- // 2*cos(x)+3*x^2
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
- TypeScript and ESM users can use the default import:
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 nerdamer from 'nerdamer';
54
+ import { Parser } from 'nerdamer/parser';
41
55
 
42
- console.log(nerdamer('expand((x+1)^3)').text());
56
+ const expression = Parser.parse('sqrt(x^2+1)');
57
+ console.log(expression.text());
43
58
  ```
44
59
 
45
- TypeScript projects that compile to CommonJS should enable `esModuleInterop`.
46
-
47
- ### Browser use
60
+ This separation is also reflected in the browser builds:
48
61
 
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`.
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
- const e = nerdamer('x^2+2*x+1');
55
- console.log(e.text());
68
+ console.log(nerdamer('factor(x^2-1)').text());
56
69
  </script>
57
70
  ```
58
71
 
59
- ## Everything is included
72
+ The parser bundle exposes `nerdamerParser` rather than the complete `nerdamer` API.
60
73
 
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.
74
+ ## Package entry points
62
75
 
63
- ```javascript
64
- const nerdamer = require('nerdamer');
76
+ The npm package exports the complete callable API plus typed module entry points:
65
77
 
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());
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
- ## Expressions and substitutions
89
+ Additional supported entry points are `nerdamer/advanced` and `nerdamer/debug`.
72
90
 
73
- As in earlier versions, calling `nerdamer(...)` parses an expression and returns a Nerdamer value.
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 e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 });
77
- console.log(e.text());
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
- Only substitution is performed by the values object. To numerically evaluate the result, call `evaluate()`:
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 e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 }).evaluate();
84
- console.log(e.text());
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
- const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 'x^2+1' });
91
- console.log(e.text());
115
+ nerdamer('x^2+1', { x: 'y+1' }).text();
92
116
  ```
93
117
 
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.
95
-
96
- ## Text output and term ordering
118
+ ## Text and TeX output
97
119
 
98
- `text()` returns Nerdamer's normal symbolic representation. For example, a polynomial
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 e = nerdamer('x^2+2*x+1');
123
+ const expression = nerdamer('x^2+2*x+1');
103
124
 
104
- e.text();
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
- Use the per-call `sort` option when conventional display order is preferred:
132
+ The full package also supplies `toText()` and TeX conversion:
109
133
 
110
134
  ```javascript
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
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
- 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`.
141
+ `convertToLaTeX()` remains as a deprecated compatibility alias.
121
142
 
122
- The full package also provides the chainable converter-based form:
143
+ Scientific formatting can be requested through `text()` without changing the underlying expression:
123
144
 
124
145
  ```javascript
125
- e.toText();
126
- // x^2+2*x+1
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('expand((x+1)^4)').text();
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
- ## Solving equations
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
- Use `solve` for a single equation:
162
+ Prime factorization has two explicit forms:
156
163
 
157
164
  ```javascript
158
- const roots = nerdamer.solve('x^2-1', 'x');
159
- console.log(roots.text());
165
+ nerdamer.pfactor(100).text();
166
+ // [2,2,5,5]
160
167
 
161
- roots.each(root => {
162
- console.log(root.text());
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
- You can also use calculus functions inside expression strings:
181
+ The same functions can be used in Nerdamer notation:
188
182
 
189
183
  ```javascript
190
- nerdamer('diff(x^2+2*(cos(x)+x*x),x)').text();
184
+ nerdamer('diff(x^3,x)').text();
191
185
  ```
192
186
 
193
- ## Matrices and vectors
187
+ ## Solving
194
188
 
195
- Matrices and vectors are supported directly by the parser and are also available as public TypeScript classes.
189
+ Single-variable solving returns a `SolutionSet`:
196
190
 
197
191
  ```javascript
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());
192
+ const roots = nerdamer.solve('x^2-1', 'x');
193
+ console.log(roots.text());
206
194
  ```
207
195
 
208
- ## Runtime functions and constants
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('hyp(a,b):=sqrt(a^2+b^2)');
214
- console.log(nerdamer('hyp(3,4)').evaluate().text());
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
- Or use the public function API:
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
- ```javascript
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
- Constants can be registered as well:
211
+ Structured values are first-class parser entities:
225
212
 
226
213
  ```javascript
227
- nerdamer.setConstant('g', 9.81);
228
- console.log(nerdamer('100*g').text());
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
- ## Nerdamer scripting
219
+ The corresponding TypeScript classes are exported from `nerdamer/structures`.
232
220
 
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());
238
- ```
221
+ ## Scripting
239
222
 
240
- Multiple statements use semicolons as statement separators:
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
- ## Build a JavaScript function
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
- Convert Nerdamer expressions to TeX math markup with `toTeX()` or `convertToTeX()`:
236
+ ## Runtime functions, constants, and settings
276
237
 
277
238
  ```javascript
278
- const e = nerdamer('x^2+2*x+1');
279
- console.log(e.toTeX());
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
- The legacy `convertToLaTeX()` name remains available as a deprecated compatibility alias.
285
-
286
- Nerdamer can also parse supported LaTeX expressions:
244
+ Settings remain shared by the package instance:
287
245
 
288
246
  ```javascript
289
- const e = nerdamer.convertFromLaTeX('\\frac{x^2+1}{2}');
290
- console.log(e.text());
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
- Additional entry points are available for assumptions, selected parser APIs, advanced algorithms, and debugging tools.
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 the same symbol are intersected. Contradictory assumptions are rejected instead of silently replacing the existing range.
265
+ Repeated assumptions for a symbol are intersected. Contradictory assumptions are rejected.
333
266
 
334
- ## Localized error messages
267
+ ## Building JavaScript functions
335
268
 
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:
269
+ Scalar expressions can be compiled to native JavaScript-number functions:
337
270
 
338
271
  ```javascript
339
- nerdamer.set('LANGUAGE', 'spa');
340
-
341
- // Restore English when needed.
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
- The language codes are `eng`, `spa`, `fra`, `deu`, `por`, `ita`, and `nld`.
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 precision
279
+ ## Numeric behavior
348
280
 
349
- Nerdamer keeps exact rational and integer arithmetic where possible. Decimal arithmetic uses Decimal.js and large integers use native `BigInt`.
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
- ## 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
288
+ ## Building from source
373
289
 
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:
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
- Run the tests:
298
+ Build the complete package:
387
299
 
388
300
  ```bash
389
- npm test
301
+ npm run build
390
302
  ```
391
303
 
392
- Build the complete package:
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
- Validate the npm package as an installed consumer:
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
- npm run validate:package
313
+ npx webpack --mode=production --env target=full --env language=spa,fra
402
314
  ```
403
315
 
404
- The publish hook runs tests, builds the package and parser bundle, generates parser documentation data, and validates the packed npm artifact before publication.
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