nerdamer 1.1.13 → 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/LICENSE.md +184 -0
  2. package/README.md +293 -312
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +7 -0
  5. package/dist/parser.js +2 -0
  6. package/dist/parser.js.LICENSE.txt +7 -0
  7. package/docs-data/parser-functions.json +1960 -0
  8. package/index.d.ts +10 -426
  9. package/output/algebra/adapters.d.ts +33 -0
  10. package/output/algebra/adapters.js +109 -0
  11. package/output/algebra/algorithms/arith.d.ts +84 -0
  12. package/output/algebra/algorithms/arith.js +323 -0
  13. package/output/algebra/algorithms/factor.d.ts +3 -0
  14. package/output/algebra/algorithms/factor.js +5 -0
  15. package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
  16. package/output/algebra/algorithms/factorMultivariate.js +2393 -0
  17. package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
  18. package/output/algebra/algorithms/factorUnivariate.js +1072 -0
  19. package/output/algebra/algorithms/gcd.d.ts +22 -0
  20. package/output/algebra/algorithms/gcd.js +690 -0
  21. package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
  22. package/output/algebra/algorithms/groebnerBase.js +1166 -0
  23. package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
  24. package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
  25. package/output/algebra/algorithms/poly.d.ts +228 -0
  26. package/output/algebra/algorithms/poly.js +1299 -0
  27. package/output/algebra/algorithms/rational.d.ts +17 -0
  28. package/output/algebra/algorithms/rational.js +115 -0
  29. package/output/algebra/factor/factor.d.ts +62 -0
  30. package/output/algebra/factor/factor.js +158 -0
  31. package/output/algebra/gcd/gcd.d.ts +29 -0
  32. package/output/algebra/gcd/gcd.js +141 -0
  33. package/output/algebra/groebner.d.ts +21 -0
  34. package/output/algebra/groebner.js +42 -0
  35. package/output/algebra/partfrac.d.ts +19 -0
  36. package/output/algebra/partfrac.js +398 -0
  37. package/output/algebra/polynomialize.d.ts +20 -0
  38. package/output/algebra/polynomialize.js +24 -0
  39. package/output/algebra/simplify/complexsimp.d.ts +7 -0
  40. package/output/algebra/simplify/complexsimp.js +24 -0
  41. package/output/algebra/simplify/factorCommon.d.ts +13 -0
  42. package/output/algebra/simplify/factorCommon.js +136 -0
  43. package/output/algebra/simplify/funcsimp.d.ts +26 -0
  44. package/output/algebra/simplify/funcsimp.js +633 -0
  45. package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
  46. package/output/algebra/simplify/invtrigrewrite.js +96 -0
  47. package/output/algebra/simplify/ratsimp.d.ts +21 -0
  48. package/output/algebra/simplify/ratsimp.js +140 -0
  49. package/output/algebra/simplify/simplify.d.ts +25 -0
  50. package/output/algebra/simplify/simplify.js +228 -0
  51. package/output/algebra/simplify/trigreduce.d.ts +38 -0
  52. package/output/algebra/simplify/trigreduce.js +424 -0
  53. package/output/algebra/simplify/trigrewrite.d.ts +17 -0
  54. package/output/algebra/simplify/trigrewrite.js +156 -0
  55. package/output/algebra/simplify/trigsimp.d.ts +11 -0
  56. package/output/algebra/simplify/trigsimp.js +369 -0
  57. package/output/algebra/simplify/utils.d.ts +32 -0
  58. package/output/algebra/simplify/utils.js +56 -0
  59. package/output/algebra/utils.d.ts +32 -0
  60. package/output/algebra/utils.js +48 -0
  61. package/output/api/advanced.d.ts +7 -0
  62. package/output/api/advanced.js +18 -0
  63. package/output/api/algebra.d.ts +17 -0
  64. package/output/api/algebra.js +32 -0
  65. package/output/api/assumptions.d.ts +4 -0
  66. package/output/api/assumptions.js +11 -0
  67. package/output/api/calculus.d.ts +9 -0
  68. package/output/api/calculus.js +21 -0
  69. package/output/api/core.d.ts +17 -0
  70. package/output/api/core.js +41 -0
  71. package/output/api/debug.d.ts +16 -0
  72. package/output/api/debug.js +23 -0
  73. package/output/api/parser.d.ts +85 -0
  74. package/output/api/parser.js +16 -0
  75. package/output/api/solve.d.ts +10 -0
  76. package/output/api/solve.js +16 -0
  77. package/output/api/structures.d.ts +10 -0
  78. package/output/api/structures.js +22 -0
  79. package/output/calculus/derivative/diff.d.ts +30 -0
  80. package/output/calculus/derivative/diff.js +238 -0
  81. package/output/calculus/fresnel.d.ts +16 -0
  82. package/output/calculus/fresnel.js +39 -0
  83. package/output/calculus/integrate/byParts.d.ts +18 -0
  84. package/output/calculus/integrate/byParts.js +339 -0
  85. package/output/calculus/integrate/bySubstitution.d.ts +135 -0
  86. package/output/calculus/integrate/bySubstitution.js +411 -0
  87. package/output/calculus/integrate/integrate.d.ts +38 -0
  88. package/output/calculus/integrate/integrate.js +652 -0
  89. package/output/calculus/integrate/integrationTable.d.ts +2 -0
  90. package/output/calculus/integrate/integrationTable.js +914 -0
  91. package/output/calculus/integrate/utils.d.ts +28 -0
  92. package/output/calculus/integrate/utils.js +96 -0
  93. package/output/calculus/laplace/ilaplace.d.ts +31 -0
  94. package/output/calculus/laplace/ilaplace.js +192 -0
  95. package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
  96. package/output/calculus/laplace/ilaplaceTable.js +200 -0
  97. package/output/calculus/laplace/laplace.d.ts +22 -0
  98. package/output/calculus/laplace/laplace.js +109 -0
  99. package/output/calculus/laplace/laplaceTable.d.ts +2 -0
  100. package/output/calculus/laplace/laplaceTable.js +187 -0
  101. package/output/calculus/limit/limit.d.ts +35 -0
  102. package/output/calculus/limit/limit.js +1183 -0
  103. package/output/calculus/limit/limitsTable.d.ts +2 -0
  104. package/output/calculus/limit/limitsTable.js +7 -0
  105. package/output/core/Settings.d.ts +32 -0
  106. package/output/core/Settings.js +68 -0
  107. package/output/core/adapters.d.ts +18 -0
  108. package/output/core/adapters.js +40 -0
  109. package/output/core/classes/assumption/Assumption.d.ts +218 -0
  110. package/output/core/classes/assumption/Assumption.js +605 -0
  111. package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
  112. package/output/core/classes/assumption/assertiveFunctions.js +64 -0
  113. package/output/core/classes/assumption/assume.d.ts +90 -0
  114. package/output/core/classes/assumption/assume.js +145 -0
  115. package/output/core/classes/collection/Collection.d.ts +107 -0
  116. package/output/core/classes/collection/Collection.js +231 -0
  117. package/output/core/classes/complex/Complex.d.ts +99 -0
  118. package/output/core/classes/complex/Complex.js +135 -0
  119. package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
  120. package/output/core/classes/decimalSet/DecimalSet.js +453 -0
  121. package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
  122. package/output/core/classes/dictionary/Dictionary.js +213 -0
  123. package/output/core/classes/equation/Equation.d.ts +256 -0
  124. package/output/core/classes/equation/Equation.js +350 -0
  125. package/output/core/classes/expression/CoeffObject.d.ts +100 -0
  126. package/output/core/classes/expression/CoeffObject.js +198 -0
  127. package/output/core/classes/expression/Expression.d.ts +1674 -0
  128. package/output/core/classes/expression/Expression.js +2332 -0
  129. package/output/core/classes/expression/analysis.d.ts +25 -0
  130. package/output/core/classes/expression/analysis.js +218 -0
  131. package/output/core/classes/expression/collect.d.ts +9 -0
  132. package/output/core/classes/expression/collect.js +49 -0
  133. package/output/core/classes/expression/format.d.ts +45 -0
  134. package/output/core/classes/expression/format.js +217 -0
  135. package/output/core/classes/expression/products.d.ts +23 -0
  136. package/output/core/classes/expression/products.js +115 -0
  137. package/output/core/classes/expression/shortcuts.d.ts +35 -0
  138. package/output/core/classes/expression/shortcuts.js +129 -0
  139. package/output/core/classes/expression/traversal.d.ts +31 -0
  140. package/output/core/classes/expression/traversal.js +216 -0
  141. package/output/core/classes/expression/trig.d.ts +25 -0
  142. package/output/core/classes/expression/trig.js +40 -0
  143. package/output/core/classes/expression/utils.d.ts +52 -0
  144. package/output/core/classes/expression/utils.js +189 -0
  145. package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
  146. package/output/core/classes/lookupTable/LookupTable.js +55 -0
  147. package/output/core/classes/matrix/Matrix.d.ts +227 -0
  148. package/output/core/classes/matrix/Matrix.js +889 -0
  149. package/output/core/classes/matrix/Sylvester.d.ts +11 -0
  150. package/output/core/classes/matrix/Sylvester.js +54 -0
  151. package/output/core/classes/matrix/functions.d.ts +26 -0
  152. package/output/core/classes/matrix/functions.js +52 -0
  153. package/output/core/classes/matrix/utils.d.ts +9 -0
  154. package/output/core/classes/matrix/utils.js +22 -0
  155. package/output/core/classes/parser/Parser.d.ts +480 -0
  156. package/output/core/classes/parser/Parser.js +1812 -0
  157. package/output/core/classes/parser/Token.d.ts +58 -0
  158. package/output/core/classes/parser/Token.js +137 -0
  159. package/output/core/classes/parser/constants.d.ts +160 -0
  160. package/output/core/classes/parser/constants.js +227 -0
  161. package/output/core/classes/parser/helpers.d.ts +21 -0
  162. package/output/core/classes/parser/helpers.js +42 -0
  163. package/output/core/classes/parser/operations/add.d.ts +15 -0
  164. package/output/core/classes/parser/operations/add.js +238 -0
  165. package/output/core/classes/parser/operations/comma.d.ts +7 -0
  166. package/output/core/classes/parser/operations/comma.js +11 -0
  167. package/output/core/classes/parser/operations/compare.d.ts +21 -0
  168. package/output/core/classes/parser/operations/compare.js +461 -0
  169. package/output/core/classes/parser/operations/divide.d.ts +2 -0
  170. package/output/core/classes/parser/operations/divide.js +72 -0
  171. package/output/core/classes/parser/operations/functions.d.ts +46 -0
  172. package/output/core/classes/parser/operations/functions.js +430 -0
  173. package/output/core/classes/parser/operations/multiply.d.ts +11 -0
  174. package/output/core/classes/parser/operations/multiply.js +321 -0
  175. package/output/core/classes/parser/operations/power.d.ts +48 -0
  176. package/output/core/classes/parser/operations/power.js +673 -0
  177. package/output/core/classes/parser/operations/subtract.d.ts +3 -0
  178. package/output/core/classes/parser/operations/subtract.js +35 -0
  179. package/output/core/classes/parser/preprocess.d.ts +14 -0
  180. package/output/core/classes/parser/preprocess.js +259 -0
  181. package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
  182. package/output/core/classes/parser/scripting/controlFlow.js +355 -0
  183. package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
  184. package/output/core/classes/parser/scripting/evaluate.js +112 -0
  185. package/output/core/classes/parser/scripting/functions.d.ts +14 -0
  186. package/output/core/classes/parser/scripting/functions.js +59 -0
  187. package/output/core/classes/parser/scripting/scope.d.ts +35 -0
  188. package/output/core/classes/parser/scripting/scope.js +155 -0
  189. package/output/core/classes/parser/types.d.ts +125 -0
  190. package/output/core/classes/parser/types.js +2 -0
  191. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
  192. package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
  193. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
  194. package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
  195. package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
  196. package/output/core/classes/polynomial/Polynomial.js +1149 -0
  197. package/output/core/classes/polynomial/Term.d.ts +222 -0
  198. package/output/core/classes/polynomial/Term.js +430 -0
  199. package/output/core/classes/polynomial/functions.d.ts +69 -0
  200. package/output/core/classes/polynomial/functions.js +126 -0
  201. package/output/core/classes/polynomial/utils.d.ts +62 -0
  202. package/output/core/classes/polynomial/utils.js +206 -0
  203. package/output/core/classes/rational/Rational.d.ts +504 -0
  204. package/output/core/classes/rational/Rational.js +779 -0
  205. package/output/core/classes/seq/SEQ.d.ts +13 -0
  206. package/output/core/classes/seq/SEQ.js +137 -0
  207. package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
  208. package/output/core/classes/valuesSet/ValuesSet.js +381 -0
  209. package/output/core/classes/vector/Vector.d.ts +222 -0
  210. package/output/core/classes/vector/Vector.js +497 -0
  211. package/output/core/classes/vector/functions.d.ts +28 -0
  212. package/output/core/classes/vector/functions.js +47 -0
  213. package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
  214. package/output/core/common/classes/MathematicalAggregate.js +140 -0
  215. package/output/core/common/classes/Scope.d.ts +62 -0
  216. package/output/core/common/classes/Scope.js +122 -0
  217. package/output/core/common/classes/StructuredEntity.d.ts +55 -0
  218. package/output/core/common/classes/StructuredEntity.js +151 -0
  219. package/output/core/common/common.d.ts +63 -0
  220. package/output/core/common/common.js +279 -0
  221. package/output/core/common/functions/functions.d.ts +14 -0
  222. package/output/core/common/functions/functions.js +33 -0
  223. package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
  224. package/output/core/common/functions/structuredEntityUtils.js +40 -0
  225. package/output/core/converters/BaseConverter.d.ts +97 -0
  226. package/output/core/converters/BaseConverter.js +405 -0
  227. package/output/core/converters/Converter.d.ts +111 -0
  228. package/output/core/converters/Converter.js +802 -0
  229. package/output/core/converters/Pattern.d.ts +71 -0
  230. package/output/core/converters/Pattern.js +302 -0
  231. package/output/core/dispatch.d.ts +34 -0
  232. package/output/core/dispatch.js +304 -0
  233. package/output/core/errors.d.ts +531 -0
  234. package/output/core/errors.js +621 -0
  235. package/output/core/functions/bigint/bigint.d.ts +121 -0
  236. package/output/core/functions/bigint/bigint.js +392 -0
  237. package/output/core/functions/bigint/primeFactor.d.ts +49 -0
  238. package/output/core/functions/bigint/primeFactor.js +267 -0
  239. package/output/core/functions/bigint/primes.d.ts +1 -0
  240. package/output/core/functions/bigint/primes.js +11 -0
  241. package/output/core/functions/build/definitions.d.ts +12 -0
  242. package/output/core/functions/build/definitions.js +133 -0
  243. package/output/core/functions/build/index.d.ts +32 -0
  244. package/output/core/functions/build/index.js +136 -0
  245. package/output/core/functions/complex.d.ts +90 -0
  246. package/output/core/functions/complex.js +482 -0
  247. package/output/core/functions/decimal.d.ts +24 -0
  248. package/output/core/functions/decimal.js +664 -0
  249. package/output/core/functions/expand/expand.d.ts +42 -0
  250. package/output/core/functions/expand/expand.js +376 -0
  251. package/output/core/functions/fresnelNumeric.d.ts +12 -0
  252. package/output/core/functions/fresnelNumeric.js +123 -0
  253. package/output/core/functions/numeric.d.ts +140 -0
  254. package/output/core/functions/numeric.js +790 -0
  255. package/output/core/functions/rationalNormalization.d.ts +11 -0
  256. package/output/core/functions/rationalNormalization.js +117 -0
  257. package/output/core/functions/setFunction.d.ts +19 -0
  258. package/output/core/functions/setFunction.js +75 -0
  259. package/output/core/functions/string.d.ts +26 -0
  260. package/output/core/functions/string.js +101 -0
  261. package/output/core/functions/subst.d.ts +90 -0
  262. package/output/core/functions/subst.js +498 -0
  263. package/output/core/functions/utils.d.ts +24 -0
  264. package/output/core/functions/utils.js +51 -0
  265. package/output/core/types.d.ts +48 -0
  266. package/output/core/types.js +2 -0
  267. package/output/index.d.ts +339 -0
  268. package/output/index.js +715 -0
  269. package/output/math/defint/defintDecimal.d.ts +37 -0
  270. package/output/math/defint/defintDecimal.js +320 -0
  271. package/output/math/defint/defintNative.d.ts +57 -0
  272. package/output/math/defint/defintNative.js +292 -0
  273. package/output/math/geometry.d.ts +8 -0
  274. package/output/math/geometry.js +32 -0
  275. package/output/math/math.d.ts +655 -0
  276. package/output/math/math.js +1811 -0
  277. package/output/math/trig.d.ts +518 -0
  278. package/output/math/trig.js +1444 -0
  279. package/output/math/trunc.d.ts +19 -0
  280. package/output/math/trunc.js +36 -0
  281. package/output/math/utils.d.ts +60 -0
  282. package/output/math/utils.js +180 -0
  283. package/output/solve/classes/DecimalMatrix.d.ts +17 -0
  284. package/output/solve/classes/DecimalMatrix.js +86 -0
  285. package/output/solve/classes/FunctionSolver.d.ts +135 -0
  286. package/output/solve/classes/FunctionSolver.js +433 -0
  287. package/output/solve/classes/MultivariateSolver.d.ts +84 -0
  288. package/output/solve/classes/MultivariateSolver.js +240 -0
  289. package/output/solve/classes/PolynomialSolver.d.ts +85 -0
  290. package/output/solve/classes/PolynomialSolver.js +292 -0
  291. package/output/solve/classes/SolutionSet.d.ts +153 -0
  292. package/output/solve/classes/SolutionSet.js +357 -0
  293. package/output/solve/classes/Solver.d.ts +17 -0
  294. package/output/solve/classes/Solver.js +132 -0
  295. package/output/solve/classes/SymbolicSolver.d.ts +74 -0
  296. package/output/solve/classes/SymbolicSolver.js +601 -0
  297. package/output/solve/linsolve.d.ts +51 -0
  298. package/output/solve/linsolve.js +225 -0
  299. package/output/solve/solve.d.ts +34 -0
  300. package/output/solve/solve.js +260 -0
  301. package/output/solve/solveSystem.d.ts +31 -0
  302. package/output/solve/solveSystem.js +290 -0
  303. package/output/solve/utils.d.ts +9 -0
  304. package/output/solve/utils.js +62 -0
  305. package/output/utils/array.d.ts +42 -0
  306. package/output/utils/array.js +98 -0
  307. package/output/utils/debug.d.ts +131 -0
  308. package/output/utils/debug.js +295 -0
  309. package/output/utils/decimal.d.ts +3 -0
  310. package/output/utils/decimal.js +16 -0
  311. package/output/utils/numeric.d.ts +14 -0
  312. package/output/utils/numeric.js +51 -0
  313. package/output/utils/object.d.ts +26 -0
  314. package/output/utils/object.js +56 -0
  315. package/package.json +213 -57
  316. package/.travis.yml +0 -3
  317. package/Algebra.js +0 -4568
  318. package/BREAKING_CHANGES.md +0 -5
  319. package/CODE_OF_CONDUCT.md +0 -46
  320. package/CONTRIBUTING.md +0 -14
  321. package/Calculus.js +0 -2675
  322. package/Extra.js +0 -622
  323. package/Solve.js +0 -1783
  324. package/all.js +0 -16
  325. package/all.min.js +0 -1
  326. package/gulpfile.js +0 -16
  327. package/index.html +0 -158
  328. package/license.txt +0 -19
  329. package/nerdamer.core.js +0 -12510
  330. package/spec/LaTeX.spec.js +0 -302
  331. package/spec/TeXConvert.spec.js +0 -8
  332. package/spec/algebra.spec.js +0 -287
  333. package/spec/basic_parser.spec.js +0 -134
  334. package/spec/build.spec.js +0 -131
  335. package/spec/calculus.spec.js +0 -183
  336. package/spec/core.spec.js +0 -2970
  337. package/spec/extra.spec.js +0 -54
  338. package/spec/solve.spec.js +0 -126
  339. package/spec/support/jasmine.json +0 -11
  340. package/spec/support/utils.js +0 -42
  341. package/spec/text.spec.js +0 -132
package/README.md CHANGED
@@ -1,427 +1,408 @@
1
- [![Build Status](https://travis-ci.org/jiggzson/nerdamer.svg?branch=master)](https://travis-ci.org/jiggzson/nerdamer)
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
- As of version 0.5.0, the library is split into the core and optional add-ons which can be loaded after the core has been loaded.
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
- Load the library in your html page
9
+ Nerdamer 2.0 is currently available as a release candidate under the npm `next` tag:
11
10
 
12
- ```html
13
- <!-- assuming you've saved the file in the root of course -->
14
- <!-- This the core and the only file needed if all you'll be doing is evaluating expresssions -->
15
- <script src="nerdamer.core.js"></script>
16
- <!-- LOAD ADD-ONS. These files contain extended functions. See documentation -->
17
- <!-- again assuming you've saved the files in root -->
18
- <script src="Algebra.js"></script>
19
- <script src="Calculus.js"></script>
20
- <script src="Solve.js"></script>
21
- <script src="Extra.js"></script>
22
- ```
23
- Or import everything
24
- ```html
25
- <script src="all.min.js"></script> <!-- assuming you've saved the file in the root -->
11
+ ```bash
12
+ npm install nerdamer@next
26
13
  ```
27
- If you're using node.js install it using `npm i nerdamer` and then
14
+
15
+ When Nerdamer 2.0 becomes the stable `latest` release, the normal `npm install nerdamer` command will install the 2.x line.
16
+
17
+ ### Need to stay on the 1.x line?
18
+
19
+ Nerdamer 2.0 contains substantial API and behavior changes. If an existing application cannot migrate to 2.0 yet, use [Nerdamer-Prime](https://github.com/together-science/nerdamer-prime), a separately maintained continuation of the earlier Nerdamer codebase:
20
+
21
+ ```bash
22
+ npm install nerdamer-prime
23
+ ```
24
+
25
+ Nerdamer-Prime is maintained separately from Nerdamer 2.0 and is the appropriate option for projects that need to remain closer to the 1.x API and package structure.
26
+
27
+ In Node.js, require the package and start working with expressions:
28
28
 
29
29
  ```javascript
30
- // const cannot be used since nerdamer gets modified when other modules are loaded
31
- var nerdamer = require('nerdamer');
32
- // Load additional modules. These are not required.
33
- require('nerdamer/Algebra');
34
- require('nerdamer/Calculus');
35
- require('nerdamer/Solve');
36
- require('nerdamer/Extra');
37
- ```
38
- Or do a single import to import everything
39
- ```javascript
40
- const nerdamer = require("nerdamer/all.min")
30
+ const nerdamer = require('nerdamer');
31
+
32
+ const e = nerdamer('x^2+2*(cos(x)+x*x)');
33
+ console.log(e.text());
34
+ // 2*cos(x)+3*x^2
41
35
  ```
42
36
 
43
- Some functions have dependencies from other add-ons.
37
+ TypeScript and ESM users can use the default import:
44
38
 
45
- You can see nerdamer in action at http://nerdamer.com/demo
39
+ ```typescript
40
+ import nerdamer from 'nerdamer';
46
41
 
47
- For full documentation go to http://nerdamer.com/documentation
42
+ console.log(nerdamer('expand((x+1)^3)').text());
43
+ ```
48
44
 
49
- All operations are done using the 'nerdamer' object.
45
+ TypeScript projects that compile to CommonJS should enable `esModuleInterop`.
50
46
 
51
- To add an expression just add it to the nerdamer object which will return a `Expression` object.
47
+ ### Browser use
52
48
 
53
- ```javascript
54
- var e = nerdamer('x^2+2*(cos(x)+x*x)');
55
- console.log(e.text());
49
+ The complete browser bundle is included in the package at `dist/bundle.js`. A standalone parser bundle is also available at `dist/parser.js`.
50
+
51
+ ```html
52
+ <script src="./node_modules/nerdamer/dist/bundle.js"></script>
53
+ <script>
54
+ const e = nerdamer('x^2+2*x+1');
55
+ console.log(e.text());
56
+ </script>
57
+ ```
58
+
59
+ ## Everything is included
60
+
61
+ Nerdamer 1.x was split into the core plus add-ons such as `Algebra.js`, `Calculus.js`, `Solve.js`, and `Extra.js`. Nerdamer 2.0 includes the commonly used algebra, calculus, solving, matrix, vector, and special-function features in the main package. Additional add-on imports are no longer required.
56
62
 
57
- //result:
58
- //2*cos(x)+3*x^2
59
- ```
60
- It is also possible to use `nerdamer` functions directly within the need for string manipulation of the input. The input will be parsed and the output will of type `Expression`. For example:
61
63
  ```javascript
62
- var ans = nerdamer.expand('(x-1)^5');
63
- console.log(ans.text());
64
- // -1-10*x^2-5*x^4+10*x^3+5*x+x^5
64
+ const nerdamer = require('nerdamer');
65
65
 
66
- var sol = nerdamer.solve('x^2-4', 'x');
67
- console.log(sol.text())
68
- // [2,-2]
66
+ console.log(nerdamer.factor('x^2-1').text());
67
+ console.log(nerdamer.diff('x^3', 'x').text());
68
+ console.log(nerdamer.solve('x^2-4', 'x').text());
69
69
  ```
70
70
 
71
- You can also pass in an object with known values as the second parameter.
71
+ ## Expressions and substitutions
72
72
 
73
- ```javascript
74
- var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:6});
75
- console.log(e.text());
73
+ As in earlier versions, calling `nerdamer(...)` parses an expression and returns a Nerdamer value.
76
74
 
77
- //result:
78
- //108+2*cos(6)
79
- ```
80
-
75
+ ```javascript
76
+ const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 });
77
+ console.log(e.text());
78
+ ```
81
79
 
82
- As you can see only the substitution is performed. To evaluate the result just call evaluate.
83
- Note that evaluate returns a text string or a number not an object.
80
+ Only substitution is performed by the values object. To numerically evaluate the result, call `evaluate()`:
84
81
 
85
- ```javascript
86
- var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:6}).evaluate();
82
+ ```javascript
83
+ const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 6 }).evaluate();
87
84
  console.log(e.text());
85
+ ```
88
86
 
89
- //result:
90
- //109.9203405733006
91
- ```
92
- To get back the text as a fraction, call the text method and pass in the string 'fractions'.
87
+ Values can themselves be expressions:
93
88
 
94
- ```javascript
95
- var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:6}).evaluate();
96
- console.log(e.text('fractions'));
89
+ ```javascript
90
+ const e = nerdamer('x^2+2*(cos(x)+x*x)', { x: 'x^2+1' });
91
+ console.log(e.text());
92
+ ```
97
93
 
98
- //result:
99
- //429607273/3908351
100
- ```
101
- You can get your expression back as LaTeX by calling the toTeX method
102
- ```javascript
103
- var LaTeX = nerdamer('x^2+2*(cos(x)+x*x)',{x:0.25}).toTeX();
104
- console.log(LaTeX);
94
+ Parser results are always represented by Nerdamer-native values. A scalar expression returns an `Expression`; equations, vectors, matrices, sets, collections, dictionaries, and other supported structured inputs return the corresponding Nerdamer type rather than a JavaScript-native result shape.
105
95
 
106
- //result:
107
- //2 \cdot \mathrm{cos}\left(\frac{1}{4}\right)+\frac{3}{16}
108
- ```
96
+ ## Text output and term ordering
109
97
 
110
- To have numbers returned as decimals pass in the string 'decimals' to the toTeX method
98
+ `text()` returns Nerdamer's normal symbolic representation. For example, a polynomial
99
+ may place the constant term first:
111
100
 
112
- ```javascript
113
- var LaTeX = nerdamer('x^2+2*(cos(x)+x*x)',{x:0.25}).toTeX('decimal');
114
- console.log(LaTeX);
101
+ ```javascript
102
+ const e = nerdamer('x^2+2*x+1');
115
103
 
116
- //result:
117
- //2 \cdot \mathrm{cos}\left(0.25\right)+0.1875
118
- ```
104
+ e.text();
105
+ // 1+2*x+x^2
106
+ ```
119
107
 
120
- Alternatively you can pass an object containing known values into evaluate method instead. The values passed in don't have to be number they can be another expression if needed.
108
+ Use the per-call `sort` option when conventional display order is preferred:
121
109
 
122
- ```javascript
123
- var e = nerdamer('x^2+2*(cos(x)+x*x)',{x:'x^2+1'});
124
- console.log(e.text());
110
+ ```javascript
111
+ e.text({ sort: true });
112
+ // x^2+2*x+1
125
113
 
126
- //result:
127
- //2*cos(1+x^2)+3*(1+x^2)^2
128
- ```
114
+ nerdamer('(x+1)^2').expand().text({ sort: true });
115
+ // x^2+2*x+1
116
+ ```
117
+
118
+ Sorting affects only the returned string. It does not modify the expression or change the
119
+ process-wide `SORT_TERMS` setting. TypeScript users can import `TextOptions` from
120
+ `nerdamer` or `nerdamer/core`.
129
121
 
130
- Every time you parse an expression it's stored in nerdamer. To get a list of all the expressions you just call
131
- nerdamer.expressions().
122
+ The full package also provides the chainable converter-based form:
132
123
 
133
- ```javascript
134
- var knownValues = {x:'x^2+1'};
135
- nerdamer('x^2+2*(cos(x)+x*x)').evaluate(knownValues);
136
- nerdamer('sin(x)^2+cos(x)^2').evaluate(knownValues);
124
+ ```javascript
125
+ e.toText();
126
+ // x^2+2*x+1
127
+ ```
137
128
 
138
- console.log(nerdamer.expressions());
129
+ Use `text({ sort: true })` when you want Nerdamer text syntax with explicit per-call
130
+ ordering control. Use `toText()` when you simply want the conventional formatted-text
131
+ representation.
139
132
 
140
- //result:
141
- //[ 46.692712758272776, 1 ]
142
- ```
133
+ ## Algebra
143
134
 
144
- You can request it as an object as well by passing in true. This can be convenient in some
145
- situations as the numbering starts at 1;
135
+ Nerdamer can expand, factor, simplify, compute polynomial GCDs, and perform related symbolic algebra operations.
146
136
 
147
- ```javascript
148
- var knownValues = {x:'x^2+1'};
149
- nerdamer('x^2+2*(cos(x)+x*x)', knownValues );
150
- nerdamer('sin(x)^2+cos(x)^2', knownValues );
137
+ ```javascript
138
+ nerdamer('expand((x+1)^4)').text();
139
+ nerdamer.factor('x^4-1').text();
140
+ nerdamer.simplify('sin(x)^2+cos(x)^2').text();
141
+ nerdamer.gcd('x^2-1', 'x^2-2*x+1').text();
142
+
143
+ const completed = nerdamer.completeSquare('x^2+6*x+1');
144
+ completed.expression.text({ sort: true });
145
+
146
+ const [substituted, substitutions] = nerdamer.uSub(
147
+ 'cos(x)^2+cos(x)+1',
148
+ 'cos(x)'
149
+ );
150
+ nerdamer.uUnSub(substituted, substitutions);
151
+ ```
151
152
 
152
- console.log(nerdamer.expressions(true));
153
+ ## Solving equations
153
154
 
154
- //{ '1': '2*cos(1+x^(2))+3*(1+x^(2))^(2)',
155
- //'2': 'cos(1+x^(2))^(2)+sin(1+x^(2))^(2)' }
156
- ```
157
-
158
- Functions aren't always immediately parsed to numbers. For example
155
+ Use `solve` for a single equation:
159
156
 
160
157
  ```javascript
161
- var result = nerdamer('cos(x)',{x:6});
162
- console.log(result.text());
163
- //cos(6)
158
+ const roots = nerdamer.solve('x^2-1', 'x');
159
+ console.log(roots.text());
160
+
161
+ roots.each(root => {
162
+ console.log(root.text());
163
+ });
164
164
  ```
165
- will only subsitute out the variable name. To change this behaviour numer should be passed in as the 3rd argument.
165
+
166
+ Single-variable solving returns a `SolutionSet`. System solving returns Nerdamer structures rather than the compatibility-only arrays used by older releases.
166
167
 
167
168
  ```javascript
168
- var result = nerdamer('cos(x)',{x:6}, 'numer');
169
- console.log(result.text());
170
- //0.960170286650366
169
+ const solutions = nerdamer.solveSystem(
170
+ ['x+y=3', 'x-y=1'],
171
+ ['x', 'y']
172
+ );
173
+
174
+ console.log(solutions.text());
171
175
  ```
172
- or alternatively
176
+
177
+ ## Calculus
178
+
179
+ Differentiation, integration, limits, sums, products, and transforms are available without loading a separate add-on.
173
180
 
174
181
  ```javascript
175
- var result = nerdamer('cos(x)').evaluate({x:6});
176
- console.log(result.text());
177
- //0.960170286650366
182
+ nerdamer.diff('x^3+sin(x)', 'x').text();
183
+ nerdamer.integrate('x^2', 'x').text();
184
+ nerdamer.limit('sin(x)/x', 'x', '0').text();
178
185
  ```
179
- The difference however is that the first option directly substitutes the variables while the second first evaluates
180
- the expression and then makes the substitutions. This library utilizes native javascript functions as much as possible. As a result it inherits whatever rounding errors they possess. One major change with version 0.6.0 however, is dealing with floating point issues.
186
+
187
+ You can also use calculus functions inside expression strings:
181
188
 
182
189
  ```javascript
183
- var result = nerdamer('sqrt(x)*sqrt(x)-2', {x: 2});
184
- console.log(result.text());
185
- //0
190
+ nerdamer('diff(x^2+2*(cos(x)+x*x),x)').text();
186
191
  ```
187
- The above expample now returns zero whereas in previous version the result would be 4.440892098500626e-16. Same goes for 0.1+0.2.
188
192
 
189
- An expression can be replaced directly by passing in the index of which expression to override. For example
193
+ ## Matrices and vectors
194
+
195
+ Matrices and vectors are supported directly by the parser and are also available as public TypeScript classes.
190
196
 
191
197
  ```javascript
192
- nerdamer('cos(x)',{x:6}, 'numer');
193
- nerdamer('sin(x)+y',{x:6}, null, 1);
194
- console.log(nerdamer.expressions());
195
- //[ 'sin(6)+y' ]
198
+ const m = nerdamer('matrix([1,2],[3,4])');
199
+ console.log(m.text());
200
+
201
+ const v = nerdamer('vector(1,2,3)');
202
+ console.log(v.text());
203
+
204
+ const basis = nerdamer.nullspace(nerdamer('matrix([1,2,3],[2,4,6])'));
205
+ console.log(basis.text());
196
206
  ```
197
207
 
198
- If multiple modifier options need to be passed into nerdamer you can do so using an array. For example ...
208
+ ## Runtime functions and constants
209
+
210
+ Custom symbolic functions can be defined with Nerdamer syntax:
199
211
 
200
212
  ```javascript
201
- var e = nerdamer('cos(x)+(y-x)^2', {x:7}, ['expand', 'numer']);
202
- console.log(e.text());
203
- //-14*y+y^2+49.7539022543433
213
+ nerdamer('hyp(a,b):=sqrt(a^2+b^2)');
214
+ console.log(nerdamer('hyp(3,4)').evaluate().text());
204
215
  ```
205
216
 
206
- If you need the code as LaTeX you can pass in true as the second parameter when requesting the expressions.
217
+ Or use the public function API:
207
218
 
208
- ```javascript
209
- nerdamer('x^2+2*(cos(x)+x*x)');
210
- nerdamer('sin(x)^0.25+cos(x)^0.5' );
211
- var asObject = true;
212
- var asLaTeX = true;
213
- console.log(nerdamer.expressions(asObject, asLaTeX));
219
+ ```javascript
220
+ nerdamer.setFunction('line', ['x', 'm', 'b'], 'm*x+b');
221
+ console.log(nerdamer('line(2,3,4)').text());
222
+ ```
214
223
 
215
- /*{ '1': '2 \\cdot \\mathrm{cos}\\left(x\\right)+3 \\cdot x^{2}',
216
- '2': '\\sqrt{\\mathrm{cos}\\left(x\\right)}+\\mathrm{sin}\\left(x\\right)^{\\frac{1}{4}}' }*/
217
- ```
218
-
224
+ Constants can be registered as well:
219
225
 
220
- You can specify a particular location when adding an expression, which is specified with the third parameter.
226
+ ```javascript
227
+ nerdamer.setConstant('g', 9.81);
228
+ console.log(nerdamer('100*g').text());
229
+ ```
221
230
 
222
- ```javascript
223
- nerdamer('x^2+2*(cos(x)+x*x)');
224
- nerdamer('sin(x)^0.25+cos(x)^0.5' );
225
- nerdamer('expr-override', undefined, 2 );
226
- var asObject = false;
227
- var asLaTeX = true;
228
- console.log(nerdamer.expressions(asObject, asLaTeX));
231
+ ## Nerdamer scripting
229
232
 
230
- /* [ '2 \\cdot \\mathrm{cos}\\left(x\\right)+3 \\cdot x^{2}',
231
- '\\sqrt{\\mathrm{cos}\\left(x\\right)}+\\mathrm{sin}\\left(x\\right)^{\\frac{1}{4}}',
232
- 'expr-override' ]
233
- */
233
+ Nerdamer includes a small symbolic scripting language in addition to ordinary expression notation. It supports user-defined functions, assignments, local bindings, conditionals, loops, blocks, logical operations, `return`, `break`, `continue`, and error-handling helpers.
234
+
235
+ ```javascript
236
+ const result = nerdamer('let(x,4,if(x>3,x^2,0))');
237
+ console.log(result.text());
234
238
  ```
235
239
 
236
- Here's an example of reserved variable and function names.
240
+ Multiple statements use semicolons as statement separators:
237
241
 
238
- ```javascript
239
- var reserved = nerdamer.reserved();
240
- console.log(reserved);
241
- //result:
242
- /* 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 */
242
+ ```javascript
243
+ const result = nerdamer(`
244
+ f(x):=x^2+1;
245
+ f(12)
246
+ `);
243
247
 
244
- //or as an array
248
+ console.log(result.text());
249
+ ```
245
250
 
246
- var reserved = nerdamer.reserved(true);
247
- console.log(reserved);
248
- //result:
249
- /* [ 'csc', 'sec', 'cot', 'erf', 'fact', 'mod', 'GCD', 'QGCD', 'LCM', 'pow', 'PI', 'E', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'sinh', 'cosh', 'tanh', 'asinh', 'acosh', 'atanh', 'exp', 'min', 'max', 'floor', 'ceil', 'round', 'vector', 'matrix',
250
- 'parens', 'sqrt', 'log', 'expand', 'abs', 'invert', 'transpose', 'dot' ] */
251
- ```
251
+ ## Build a JavaScript function
252
252
 
253
- Most math functions are passed in as part of the expression. If you want to differentiate for instance you just use the function diff which is located in the Calculus add-on as of version 0.5.0
253
+ An expression can be compiled to a JavaScript function:
254
254
 
255
- ```javascript
256
- var e = nerdamer('diff(x^2+2*(cos(x)+x*x),x)');
255
+ ```javascript
256
+ const f = nerdamer('x^2+5').buildFunction();
257
+ console.log(f(9));
258
+ // 86
259
+ ```
257
260
 
258
- console.log(e.text());
261
+ You can specify the parameter order explicitly:
259
262
 
260
- //result:
261
- //-2*sin(x)+6*x
263
+ ```javascript
264
+ const f = nerdamer('z+x^2+y').buildFunction(['y', 'x', 'z']);
265
+ console.log(f(9, 2, 1));
266
+ // 14
262
267
  ```
263
-
264
-
265
- Nerdamer can also handle runtime functions. To do this use the method setFunction.
266
- The runtime functions do have symbolic capabilities and support for imaginary numbers.
267
- The setfunction method is used as follows:
268
268
 
269
- nerdamer.setFunction( function_name, parameter_array, function_body )
269
+ The chained `buildFunction()` method is available on values returned by `nerdamer(...)` so this form remains convenient in TypeScript. Only scalar `Expression` results can be compiled. If the input parses to an `Equation`, `Vector`, `Matrix`, set, or another structured result, calling `buildFunction()` throws `UnexpectedDataType` rather than compiling the contained values independently.
270
270
 
271
- For Example:
271
+ `buildFunction()` uses dynamic JavaScript function construction. Applications with a Content Security Policy that forbids dynamic code generation should use Nerdamer's ordinary symbolic and numeric evaluation APIs instead.
272
272
 
273
- ```javascript
274
- //generate some points
275
- var f = function(x) { return 5*x-1; }
276
- console.log(f(1)); //4
277
- console.log(f(2)); //9 - value to be found
278
- console.log(f(7)); //34
273
+ ## TeX
279
274
 
280
- nerdamer.setFunction('interpolate',['y0','x0','y1','x1','x'],'y0+(y1-y0)*((x-x0)/(x1-x0))')
281
- var answer = nerdamer('interpolate(4,1,34,7,2)').evaluate();
275
+ Convert Nerdamer expressions to TeX math markup with `toTeX()` or `convertToTeX()`:
282
276
 
283
- console.log(answer);
277
+ ```javascript
278
+ const e = nerdamer('x^2+2*x+1');
279
+ console.log(e.toTeX());
284
280
 
285
- //result: 9
281
+ console.log(nerdamer.convertToTeX('sqrt(x^2+1)'));
286
282
  ```
287
283
 
288
- Custom functions alternatively be set in following manner.
284
+ The legacy `convertToLaTeX()` name remains available as a deprecated compatibility alias.
289
285
 
290
- ```javascript
291
- nerdamer('hyp(a, b) := sqrt(a^2 + b^2) ');
292
- var result = nerdamer('hyp(3, 4)').evaluate().text();
293
- console.log(result);
294
- //result: 5
295
- ```
296
-
297
-
298
- If you need to add a constant use the setConstant method
299
-
300
- ```javascript
301
- nerdamer.setConstant( 'g', 9.81);
302
- var weight = nerdamer('100*g').text();
303
- console.log(weight);
304
- //result:
305
- //981
306
- ```
307
-
308
- To delete just set it to delete
309
-
310
- ```javascript
311
- nerdamer.setConstant( 'g', 9.81);
312
- var weight = nerdamer('100*g').text();
313
- console.log(weight);
314
- //981
315
- nerdamer.setConstant( 'g', 'delete');
316
- var weight = nerdamer('100*g').text();
317
- console.log(weight);
318
- //100*g
319
- ```
320
-
321
- You also have the option of exporting your function to a javascript function which can be useful if you need some
322
- filtering from user input. Do keep in mind that the parameters are sorted alphabetically for more than one
323
- parameter. To use it add the expression to nerdamer and use the buildFunction method.
324
-
325
- ```javascript
326
- var f = nerdamer('x^2+5').buildFunction();
327
- console.log(f(9));
286
+ Nerdamer can also parse supported LaTeX expressions:
328
287
 
329
- //result:
330
- //86
331
- ```
332
- 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:
288
+ ```javascript
289
+ const e = nerdamer.convertFromLaTeX('\\frac{x^2+1}{2}');
290
+ console.log(e.text());
291
+ ```
333
292
 
334
- ```javascript
335
- var f = nerdamer('z+x^2+y').buildFunction(['y', 'x', 'z']);
336
- console.log(f(9,2,1));
337
- //result
338
- //14
339
- ```
293
+ ## Direct TypeScript imports
294
+
295
+ The callable `nerdamer` API remains available, but Nerdamer 2.0 also exposes public classes and functions through package subpaths:
296
+
297
+ ```typescript
298
+ import { Expression, Rational, type TextOptions } from 'nerdamer/core';
299
+ import {
300
+ Polynomial,
301
+ completeSquare,
302
+ gcd,
303
+ isPrime,
304
+ lcm,
305
+ polyFactors,
306
+ uSub,
307
+ uUnSub,
308
+ } from 'nerdamer/algebra';
309
+ import { diff, integrate, limit } from 'nerdamer/calculus';
310
+ import { solve, PolynomialSolver } from 'nerdamer/solve';
311
+ import { Matrix, Vector, ValuesSet, nullspace } from 'nerdamer/structures';
312
+ ```
340
313
 
341
- Every time you add an expression to nerdamer it's stored. To list the expressions currently in nerdamer call
342
- the 'expressions' method. To delete an expression use the 'clear' method and pass in the expression you want to delete.
343
- To clear everything pass in the string 'all'.
314
+ Additional entry points are available for assumptions, selected parser APIs, advanced algorithms, and debugging tools.
344
315
 
345
- ```javascript
346
- nerdamer('n*R*T/v');
347
- nerdamer('mc^2');
348
- nerdamer('G*m1*m2/d^2');
316
+ ## Assumptions
349
317
 
350
- nerdamer.clear(2);
318
+ Nerdamer can register numeric interval assumptions for symbols. Assumptions are process-wide and are used by symbolic comparisons and simplifications that depend on sign or range information.
351
319
 
352
- console.log(nerdamer.expressions(true));
320
+ ```typescript
321
+ import nerdamer from 'nerdamer';
322
+ import { assume, clearAssumptions } from 'nerdamer/assumptions';
353
323
 
354
- //result:
355
- //{ '1': 'R*T*n*v^(-1)', '2': 'G*d^(-2)*m1*m2' }
324
+ assume('x > 0');
356
325
 
357
- nerdamer.clear('all');
358
- console.log(nerdamer.expressions(true));
359
- //result:
360
- //{}
361
- ```
362
-
363
- If you need go get the variables of an expression use the variables method. This method can be called after
364
- nerdamer was provided an expression. For example
326
+ console.log(nerdamer('sqrt(x^2)').text());
327
+ // x
365
328
 
366
- ```javascript
367
- var variables = nerdamer('csc(x*cos(y))-no_boring_x').variables();
368
- console.log(variables);
369
- //result:
370
- //[ 'no_boring_x', 'x', 'y' ]
329
+ clearAssumptions();
371
330
  ```
372
331
 
373
- The order in which the variables appear require a little bit of knowledge of how nerdamer organizes symbols. For the
374
- sake of simplicity we'll just assume that there is no particular order
332
+ Repeated assumptions for the same symbol are intersected. Contradictory assumptions are rejected instead of silently replacing the existing range.
375
333
 
376
- ----------------------------------------------------------------------------------------------------------------------
334
+ ## Localized error messages
335
+
336
+ Nerdamer includes localized built-in error messages for English, Spanish, French, German, Portuguese, Italian, and Dutch. Select the language through the shared parser settings:
377
337
 
378
- Using the solver
379
- ===============
380
- To solve equations first load Solve.js. Just remember that Solve also required Algebra.js and Calculus.js to be loaded. You can then solve equations using nerdamer. Important: State the variable for which you are trying to solve.
381
338
  ```javascript
382
- var sol = nerdamer.solveEquations('x^3+8=x^2+6','x');
383
- console.log(sol.toString());
384
- //1+i,-i+1,-1
339
+ nerdamer.set('LANGUAGE', 'spa');
340
+
341
+ // Restore English when needed.
342
+ nerdamer.set('LANGUAGE', 'eng');
385
343
  ```
386
344
 
387
- Notice that we use toString rather than text as this returns a javascript array.
345
+ The language codes are `eng`, `spa`, `fra`, `deu`, `por`, `ita`, and `nld`.
346
+
347
+ ## Numeric precision
348
+
349
+ Nerdamer keeps exact rational and integer arithmetic where possible. Decimal arithmetic uses Decimal.js and large integers use native `BigInt`.
388
350
 
389
- You can also solve an expression
390
351
  ```javascript
391
- var e = nerdamer.solveEquations('x^2+4-y', 'y');
392
- console.log(e[0].text());
393
- //4+x^2
352
+ nerdamer('0.1+0.2').text();
353
+ nerdamer('sqrt(2)').evaluate().text();
394
354
  ```
395
355
 
396
- You can also solve multivariate equations
397
- ```javascript
398
- var sol = nerdamer.solveEquations('x^2+8+y=x+6','x');
399
- console.log(sol.toString());
400
- //0.5*((-4*y-7)^0.5+1),0.5*(-(-4*y-7)^0.5+1)
356
+ ## What changed in 2.0
357
+
358
+ Nerdamer 2.0 keeps the familiar expression-oriented API, but it is a new implementation rather than a continuation of the 1.x source tree. Important changes include:
359
+
360
+ - the old add-on loading system is gone;
361
+ - TypeScript declarations ship with the package;
362
+ - Nerdamer no longer keeps a global history of every parsed expression;
363
+ - parser-facing APIs consistently return Nerdamer-native values instead of mixing Nerdamer types with JavaScript-native result shapes;
364
+ - solver result types are explicit public structures;
365
+ - lower-level 1.x extension hooks such as `getCore()` and `register()` are not exposed in the same way;
366
+ - decimal, complex-number, parser, solver, assumptions, and set handling have been substantially revised.
367
+
368
+ If an existing project cannot move to Nerdamer 2.0 yet, use [Nerdamer-Prime](https://github.com/together-science/nerdamer-prime), which continues the earlier Nerdamer line under the `nerdamer-prime` npm package.
369
+
370
+ For the current documentation, examples, and migration information, visit [nerdamer.com](https://nerdamer.com/).
371
+
372
+ ## Documentation and playground
373
+
374
+ - Website: [nerdamer.com](https://nerdamer.com/)
375
+ - Documentation: [nerdamer.com/docs](https://nerdamer.com/docs/)
376
+ - Playground: [nerdamer.com/playground](https://nerdamer.com/playground/)
377
+
378
+ ## Development
379
+
380
+ Run the type checker:
381
+
382
+ ```bash
383
+ npm run typecheck
401
384
  ```
402
- You can do up to 3rd order polynomials for multivariate polynomials
403
385
 
404
- Additionally you can try for equations containing functions. This is more of a hit or miss approach unlike single variable polynomials (which uses Mr. David Binner's Jenkins-Traub port - http://www.akiti.ca/PolyRootRe.html) but it's there if you want to give it a try.
386
+ Run the tests:
405
387
 
406
- ```javascript
407
- var sol = nerdamer.solveEquations('cos(x)+cos(3*x)=1','x');
408
- console.log(sol.toString());
409
- //5.7981235959208695,0.4850617112587174
388
+ ```bash
389
+ npm test
410
390
  ```
411
- To solve a system of linear equations pass them in as an array. For example
412
391
 
413
- ```javascript
414
- var sol = nerdamer.solveEquations(['x+y=1', '2*x=6', '4*z+y=6']);
415
- console.log(sol);
416
- //[ [ 'x', 3 ], [ 'y', -2 ], [ 'z', 2 ] ]
392
+ Build the complete package:
393
+
394
+ ```bash
395
+ npm run build
417
396
  ```
418
- In version 0.7.2 and up the solver can additionally be used in the following way
419
- ```javascript
420
- //first parse the equation
421
- var x = nerdamer('x^2+2=y-7*a');
422
- //You can make substitutions to the equation
423
- x = x.evaluate({a: 'x^2-3'});
424
- console.log(x.toString()); //2+x^2=-7*x^2+21+y
425
- var solutions = x.solveFor('x');
426
- console.log(solutions.toString()); //(1/16)*sqrt(32*y+608),(-1/16)*sqrt(32*y+608)
397
+
398
+ Validate the npm package as an installed consumer:
399
+
400
+ ```bash
401
+ npm run validate:package
427
402
  ```
403
+
404
+ The publish hook runs tests, builds the package and parser bundle, generates parser documentation data, and validates the packed npm artifact before publication.
405
+
406
+ ## License
407
+
408
+ Nerdamer 2.0 is licensed under the Apache License 2.0.