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/index.d.ts CHANGED
@@ -1,430 +1,14 @@
1
- export as namespace nerdamer
2
- export = nerdamer
3
- declare function nerdamer(
4
- expression: nerdamer.ExpressionParam,
5
- subs?: { [name: string]: string },
6
- option?: keyof nerdamer.Options | (keyof nerdamer.Options)[],
7
- location?: nerdamer.int): nerdamer.Expression
8
- declare namespace nerdamer {
9
- export type ExpressionParam = Expression | string
10
- export interface Options {
11
- numer: never, expand: never
12
- }
13
- type int = number
14
- /**
15
- * Returns the current version of nerdamer.
16
- */
17
- export function version(): string
1
+ import * as generated from './output/index';
18
2
 
19
- /**
20
- * Sets a constant value which nerdamer will automatically substitute when parsing expression/equation
21
- * @param name The variable to be set as the constant.
22
- * @param value The value for the expression to be set to.
23
- */
24
- export function setConstant(name: string, value: number | string): typeof nerdamer
3
+ import type { SettingsType } from './output/core/Settings';
25
4
 
26
- /**
27
- * Sets a function which can then be called using nerdamer.
28
- * @param function_name The function name
29
- * @param param_array The parameter array in the order in which the arguments are to be passed
30
- * @param function_body The body of the function
31
- * @example
32
- * nerdamer.setFunction('f', ['x', 'y'], 'x^2+y')
33
- * var x = nerdamer('f(4, 7)').toString()
34
- * console.log(x.toString())
35
- * nerdamer.setFunction('g', ['z', 'x', 'y'], '2*x+3*y+4*z')
36
- * x = nerdamer('g(3, 1, 2)')
37
- * console.log(x.toString())
38
- */
39
- export function setFunction(function_name: string, param_array: string[], function_body: string): typeof nerdamer
5
+ type GeneratedNerdamer = typeof generated.default;
6
+ type RootSettings = SettingsType & { PRECISION: number };
7
+ type Nerdamer = Omit<GeneratedNerdamer, 'get'> &
8
+ ((...args: Parameters<GeneratedNerdamer>) => ReturnType<GeneratedNerdamer>) & {
9
+ get<K extends keyof RootSettings>(setting: K): RootSettings[K];
10
+ };
40
11
 
41
- /**
42
- * Returns the nerdamer core object. This object contains all the core functions of nerdamer and houses the parser.
43
- * @example
44
- * Object.keys(nerdamer.getCore())
45
- */
46
- export function getCore(): any
12
+ declare const nerdamer: Nerdamer;
47
13
 
48
- /**
49
- * Gets the list of reserved names. This is a list of names already in use by nerdamer excluding variable names. This is not a static list.
50
- * @param asArray Pass in true to get the list back as an array instead of as an object.
51
- */
52
- export function reserved(asArray: true): string[]
53
- export function reserved(asArray?: false): any
54
-
55
- /**
56
- * Clears all stored expressions.
57
- * @example
58
- * var x = nerdamer('x*x')
59
- console.log(nerdamer.expressions())
60
- nerdamer.flush() //clear all expressions
61
- console.log(nerdamer.expressions())
62
- */
63
- export function flush(): typeof nerdamer
64
-
65
- /**
66
- * Converts and expression to LaTeX without evaluating expression.
67
- * @param expression The expression being converted.
68
- */
69
- export function convertToLaTeX(expression: string): string
70
-
71
- /**
72
- * Attempts to import a LaTeX string.
73
- * @param TeX The expression being converted.
74
- */
75
- export function convertFromLaTeX(TeX: string): Expression
76
-
77
- /**
78
- * Each time an expression is parsed nerdamer stores the result. Use this method to get back stored expressions.
79
- * @param asObject Pass in true to get expressions as numbered object with 1 as starting index
80
- * @param asLatex Pass in the string "LaTeX" to get the expression to LaTeX, otherwise expressions come back as strings
81
- */
82
- export function expressions(asObject?: boolean, asLatex?: 'LaTeX'): string[]
83
-
84
- /**
85
- * Registers a module function with nerdamer. The object needs to contain at a minimum, a name property (text), a numargs property (int), this is -1 for variable arguments or an array containing the min and max arguments, the visible property (bool) which allows use of this function through nerdamer, defaults to true, and a build property containing a function which returns the function to be used. This function is also handy for creating aliases to functions. See below how the alias D was created for the diff function).
86
- * @param o
87
- */
88
- export interface ModuleFunction {
89
- /**
90
- * Name of function.
91
- */
92
- name: string,
93
-
94
- /**
95
- * Number of function arguments, -1 for variable arguments or an tuple containing minimum and maximum number of arguments.
96
- */
97
- numargs: int | [int, int],
98
-
99
- /**
100
- * Allows use of this function through nerdamer. Defaults to true.
101
- */
102
- visible?: boolean,
103
-
104
- /**
105
- * Return the function to be used.
106
- */
107
- build(): (...args: number[]) => number
108
- }
109
-
110
- /**
111
- * Registers one or more module functions with nerdamer.
112
- * @param f
113
- * @example
114
- * var core = nerdamer.getCore()
115
- var _ = core.PARSER
116
- function f(a, b) {
117
- //use clone for safety since a or b might be returned
118
- var sum = _.add(a.clone(), b.clone())
119
- var product = _.multiply(a.clone(), b.clone())
120
- return _.multiply(sum, product)
121
- }
122
- //register the function with nerdamer
123
- nerdamer.register({
124
- name: 'myFunction',
125
- numargs: 2,
126
- visible: true,
127
- build: function(){ return f }
128
- })
129
-
130
- //create an alias for the diff function
131
- var core = nerdamer.getCore()
132
- nerdamer.register({
133
- name: 'D',
134
- visible: true,
135
- numargs: [1, 3],
136
- build: function(){ return core.Calculus.diff }
137
- })
138
- */
139
- export function register(f: ModuleFunction | ModuleFunction[]): typeof nerdamer
140
-
141
- /**
142
- * This method can be used to check that the variable meets variable name requirements for nerdamer. Variable names Must start with a letter or underscore and may contains any combination of numbers, letters, and underscores after that.
143
- * @param variable_name The variable name being validated.
144
- * @example
145
- * nerdamer.validVarName('cos') // false
146
- * nerdamer.validVarName('chicken1') // true
147
- * nerdamer.validVarName('1chicken') // false
148
- * nerdamer.validVarName('_') // true
149
- */
150
- export function validVarName(variable_name: string): boolean
151
-
152
- /**
153
- * Sets a known value in nerdamer. This differs from setConstant as the value can be overridden trough the scope. See example.
154
- * @param name The known value to be set.
155
- * @param value The value for the expression to be set to
156
- * @example
157
- * nerdamer.setVar('x', '11')
158
- * nerdamer('x*x') // == 121
159
- * // nerdamer will use 13 instead of 11:
160
- * nerdamer('x*x', {x: 13}) // == 169
161
- * // the value will be 121 again since the known value isn't being overridden:
162
- * nerdamer('x*x') // == 121
163
- * nerdamer.setVar('x', 'delete')
164
- * // since there no longer is a known value it will just be evaluated symbolically:
165
- * nerdamer('x*x') // == x^2
166
- */
167
- export function setVar(name: string, value: number | string | 'delete'): void
168
-
169
- /**
170
- * Clears all previously set variables.
171
- */
172
- export function clearVars(): typeof nerdamer
173
-
174
- /**
175
- * Gets all previously set variables.
176
- * @param option Use "LaTeX" to get as LaTeX. Defaults to text.
177
- */
178
- export function getVars(option: 'LaTeX' | 'text'): { [name: string]: string }
179
-
180
- /**
181
- * Sets the value of a nerdamer setting. Currently PARSE2NUMBER and IMAGINARY. Setting PARSE2NUMBER to true will let nerdamer always try to return a number whenenver possible. IMAGINARY allows you to change the variable used for imaginary to j for instance.
182
- * @param setting The setting to be changed
183
- * @param value The value to set the setting to.
184
- * @example
185
- * nerdamer.set('PARSE2NUMBER', true)
186
- * nerdamer('cos(9)+1') // == 14846499/167059106
187
- * nerdamer.set('IMAGINARY', 'j')
188
- * nerdamer('sqrt(-1)') // == j
189
- */
190
- export function set(setting: 'PARSE2NUMBER', value: boolean): typeof nerdamer
191
- export function set(setting: 'IMAGINARY', value: string | 'i'): typeof nerdamer
192
- export function set(setting: 'POWER_OPERATOR', value: '**' | '^'): typeof nerdamer
193
-
194
- export interface Expression {
195
- /**
196
- * Generates a JavaScript function given the expression. This is perfect for plotting and filtering user input. Plotting for the demo is accomplished using this. The order of the parameters is in alphabetical order by default but an argument array can be provided with the desired order.
197
- * @param args_array The argument array with the order in which they are preferred.
198
- */
199
- buildFunction(args_array?: string[]): (...args: number[]) => number
200
-
201
- /**
202
- * Forces evaluation of the expression.
203
- * @example
204
- * const x = nerdamer('sin(9+5)')
205
- * //the expression is simplified but the functions aren't called:
206
- * x.toString() // == sin(14)
207
- * // force function calls with evaluate:
208
- * x.evaluate().toString() // == 127690464/128901187
209
- */
210
- evaluate(): Expression
211
-
212
- /**
213
- * Substitutes a given value for another given value
214
- * @param value The value being substituted.
215
- * @param for_value The value to substitute for.
216
- */
217
- sub(value: string, for_value: string): Expression
218
-
219
- /**
220
- * Get a list of the variables contained within the expression.
221
- */
222
- variables(): string[]
223
-
224
- /**
225
- * Gets expression as LaTeX
226
- */
227
- toTeX(): string
228
-
229
- /**
230
- * Returns the value of the expression as a string or a number
231
- */
232
- valueOf(): string | number
233
-
234
- /**
235
- * Gets the list of reserved names. This is a list of names already in use by nerdamer excluding variable names. This is not a static list.
236
- * @param outputType Pass in the string 'decimals' to always get back numers as decimals. Pass in the string 'fractions' to always get back number as fractions. Defaults to decimals.
237
- */
238
- text(outputType?: 'decimals' | 'fractions'): string
239
-
240
- /**
241
- * This method requires that the Solve, Calculus, and Algebra add-ons are loaded. It will attempt to solve an equation. If solutions no solutions are found then an empty array is returned. It can solve for multivariate polynomials up to the third degree. After which it can solve numerically for polynomials up to the the 100th degree. If it's a univariate equation it will attempt to solve it using numerical methods.
242
- * @param variable The variable to solve for.
243
- * @example
244
- * nerdamer('a*x^2+b*x=y').evaluate({y: 'x-7'}) // == ??
245
- * eq.solveFor('x') // ?? TODO
246
- */
247
- solveFor(variable: string): Expression
248
-
249
- /**
250
- * Forces the expression to displayed with decimals
251
- */
252
- toDecimal(prec?: number): string
253
-
254
- /**
255
- * Checks to see if the expression's value equals a number. Compares the direct value returned.
256
- * The function will not check for all possible cases. To avoid this call evaluate.
257
- * @example
258
- * nerdamer('sqrt(5)').isNumber()
259
- * // false
260
- * nerdamer('sqrt(5)').evaluate().isNumber()
261
- * // true
262
- */
263
- isNumber(): boolean
264
-
265
- /**
266
- * Checks if a number evaluates to an imaginary number
267
- * @example
268
- * nerdamer('sqrt(-5)+8').isImaginary()
269
- * // true
270
- * nerdamer('sqrt(5)+8').isImaginary()
271
- * // false
272
- */
273
- isImaginary(): boolean
274
-
275
- /**
276
- * Adds a value to an expression
277
- * @example
278
- * nerdamer('x').add(3)
279
- */
280
- add(symbol: number | string | Expression): Expression
281
-
282
- /**
283
- * Subtracts a value from an expression
284
- * @example
285
- * nerdamer('x').subtract(3)
286
- */
287
- subtract(symbol: number | string | Expression): Expression
288
-
289
- /**
290
- * Multiplies an expression by a value
291
- * @example
292
- * nerdamer('x').multiply(3)
293
- */
294
- multiply(symbol: number | string | Expression): Expression
295
-
296
- /**
297
- * Divides an expression by a valule
298
- * @example
299
- * nerdamer('9*x').divide(3)
300
- */
301
- divide(symbol: number | string | Expression): Expression
302
-
303
- /**
304
- * Raises an expression to a power
305
- * @example
306
- * nerdamer('x').pow(3)
307
- */
308
- pow(symbol: number | string | Expression): Expression
309
-
310
- /**
311
- * Checks if two values are equal
312
- * @param value The value being tested
313
- * @example
314
- * nerdamer('sqrt(9)').eq(3)
315
- * // true
316
- * nerdamer('x').eq('y')
317
- * // false
318
- */
319
- eq(value: number | string | Expression): boolean
320
-
321
- /**
322
- * Checks if a value is less than another
323
- * @param value The value being tested
324
- * @example
325
- * nerdamer('sqrt(9)').lt(3)
326
- * // false
327
- * nerdamer('8').lt(100)
328
- * // true
329
- */
330
- lt(value: number | string | Expression): boolean
331
-
332
- /**
333
- * Checks if a value is less than or equal to another
334
- * @param value The value being tested
335
- * @example
336
- * nerdamer('sqrt(9)').lte(3)
337
- * // true
338
- * nerdamer('x').lte(100)
339
- * // false
340
- */
341
- lte(value: number | string | Expression): boolean
342
-
343
- /**
344
- * Checks if a value is greater than another
345
- * @param value The value being tested
346
- * @example
347
- * nerdamer('sqrt(9)').gt(3)
348
- * // false
349
- * nerdamer('800').gt(100)
350
- * // true
351
- */
352
- gt(value: number | string | Expression): boolean
353
-
354
- /**
355
- * Checks if a value is greater than or equal to another
356
- * @param value The value being tested
357
- * @example
358
- * nerdamer('sqrt(9)').gte(3)
359
- * // true
360
- * nerdamer('x').gte(100)
361
- * // false
362
- */
363
- gte(value: number | string | Expression): boolean
364
-
365
- /**
366
- * Expands a function or expression.
367
- * @example
368
- * nerdamer('x*(x+1)').expand();
369
- * // x+x^2
370
- * nerdamer('(x+y)*(x-5)*x').expand();
371
- * // -5*x*y-5*x^2+x^3+x^2*y
372
- */
373
- expand(): Expression
374
- }
375
-
376
- ////////// CALCULUS
377
-
378
- /**
379
- * Gets the GCD of 2 polynomials
380
- * @param expression Returns the appropriate value if possible otherwise it returns the function with the simplified expression.
381
- * @param index The index of summation.
382
- * @param lower Starting index.
383
- * @param upper Ending index.
384
- */
385
- export function sum(expression: ExpressionParam,
386
- index: string,
387
- lower: ExpressionParam,
388
- upper: ExpressionParam): Expression
389
-
390
- /**
391
- *
392
- * @param expression Returns the appropriate value if possible otherwise it returns the function with the simplified expression.
393
- * @param variable The variable with respect to which to integrate.
394
- */
395
- export function integrate(expression: ExpressionParam, variable: string): Expression
396
-
397
- /**
398
- *
399
- * @param expression Returns the appropriate value if possible otherwise it returns the function with the simplified expression.
400
- * @param variable The variable with respect to which to differentiate.
401
- * @param n Calculate the nth derivative.
402
- */
403
- export function diff(expression: ExpressionParam, variable: string, n?: int): Expression
404
-
405
- ////////// ALGEBRA
406
-
407
- /**
408
- * Divides 2 polynominals.
409
- * @param expression Returns the appropriate value if possible otherwise it returns the function with the simplified expression.
410
- */
411
- export function divide(expression: ExpressionParam): Expression
412
-
413
- /**
414
- * Factor an expression.
415
- * @param expression Returns the appropriate value if possible otherwise it returns the function with the simplified expression.
416
- */
417
- export function factor(expression: ExpressionParam): Expression
418
-
419
- /**
420
- * Gets the GCD of 2 polynomials.
421
- * @param expression Returns the appropriate value if possible otherwise it returns the function with the simplified expression.
422
- */
423
- export function gcd(expression: ExpressionParam): Expression
424
-
425
- /**
426
- * Finds the roots of a univariate polynomial.
427
- * @param expression
428
- */
429
- export function factor(expression: ExpressionParam): Expression
430
- }
14
+ export = nerdamer;
@@ -0,0 +1,33 @@
1
+ import { Expression } from '../core/classes/expression/Expression';
2
+ import { Polynomial } from '../core/classes/polynomial/Polynomial';
3
+ import { MultiPoly } from './algorithms/multiPoly/MultiPoly';
4
+ import type { PolyType } from '../core/classes/polynomial/Polynomial';
5
+ import type { FactorsObject } from './algorithms/factor';
6
+ /**
7
+ * Converts a polynomial to a MultiPoly to be used with the polynomial algorithms.
8
+ *
9
+ * @param p The polynomial to be converted.
10
+ * @param variables Optional variable order.
11
+ * @returns The MultiPoly and variable order used for its term keys.
12
+ */
13
+ export declare function polynomialToMultiPoly(p: PolyType, variables?: string[]): {
14
+ poly: MultiPoly;
15
+ variables: string[];
16
+ };
17
+ export declare function multiPolyToExpression(poly: MultiPoly, variables: string[]): Expression;
18
+ /**
19
+ * Converts the factored Expression or Polynomial to an array of Expressions.
20
+ *
21
+ * @param factorObj The integer polynomial factors.
22
+ * @param variables The variable order used by each factor.
23
+ * @returns Expression factors including non-unit content.
24
+ */
25
+ export declare function factorsToExpressions(factorObj: FactorsObject, variables: string[]): Expression[];
26
+ /**
27
+ * Converts the factored Expression or Polynomial to an array of Polynomials.
28
+ *
29
+ * @param factorsObj The integer polynomial factors.
30
+ * @param variables The variable order used by each factor.
31
+ * @returns Polynomial wrappers around the converted factors.
32
+ */
33
+ export declare function factorsToPolynomials(factorsObj: FactorsObject, variables: string[]): Polynomial[];
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polynomialToMultiPoly = polynomialToMultiPoly;
4
+ exports.multiPolyToExpression = multiPolyToExpression;
5
+ exports.factorsToExpressions = factorsToExpressions;
6
+ exports.factorsToPolynomials = factorsToPolynomials;
7
+ const Expression_1 = require("../core/classes/expression/Expression");
8
+ const shortcuts_1 = require("../core/classes/expression/shortcuts");
9
+ const Polynomial_1 = require("../core/classes/polynomial/Polynomial");
10
+ const MultiPoly_1 = require("./algorithms/multiPoly/MultiPoly");
11
+ /**
12
+ * Converts a polynomial to a MultiPoly to be used with the polynomial algorithms.
13
+ *
14
+ * @param p The polynomial to be converted.
15
+ * @param variables Optional variable order.
16
+ * @returns The MultiPoly and variable order used for its term keys.
17
+ */
18
+ function polynomialToMultiPoly(p, variables) {
19
+ p = Polynomial_1.Polynomial.toPolynomial(p);
20
+ const poly = new MultiPoly_1.MultiPoly();
21
+ variables = variables ?? p.variables;
22
+ for (const term of p.terms) {
23
+ const keyElements = [];
24
+ for (let i = 0; i < variables.length; i++) {
25
+ const power = term.powers[variables[i]];
26
+ // Don't add zero powers or undefined powers
27
+ if (!power) {
28
+ continue;
29
+ }
30
+ // Generate the key which is nothing more than index:power
31
+ keyElements.push(`${i}:${power}`);
32
+ }
33
+ const key = keyElements.join(',');
34
+ poly.terms.set(key, term.coeff.getMultiplier().numerator);
35
+ }
36
+ return { poly, variables };
37
+ }
38
+ function multiPolyToExpression(poly, variables) {
39
+ let retval;
40
+ if (poly.terms.size === 0) {
41
+ retval = (0, shortcuts_1.zero)();
42
+ }
43
+ else {
44
+ let result;
45
+ for (const [key, coeff] of poly.terms) {
46
+ // Build the coefficient as an Expression directly
47
+ let term = Expression_1.Expression.Number(coeff);
48
+ // Multiply by each variable raised to its power
49
+ if (key !== '') {
50
+ for (const part of key.split(',')) {
51
+ const [varIndex, power] = part.split(':');
52
+ const v = Expression_1.Expression.Variable(variables[+varIndex]);
53
+ term = term.times(power === '1' ? v : v.pow(Expression_1.Expression.Number(power)));
54
+ }
55
+ }
56
+ // Accumulate into sum
57
+ result = result === undefined ? term : result.plus(term);
58
+ }
59
+ retval = result ?? (0, shortcuts_1.zero)();
60
+ }
61
+ return retval;
62
+ }
63
+ /**
64
+ * Converts a PolyFactor to an Expression object.
65
+ *
66
+ * @param factor The factor to convert.
67
+ * @param variables The variable order used by the factor's MultiPoly.
68
+ * @returns The equivalent Expression.
69
+ */
70
+ function makeExpression(factor, variables) {
71
+ // The terms of each factor
72
+ let exp = multiPolyToExpression(factor.poly, variables);
73
+ // Add back the power
74
+ if (factor.multiplicity > 1n) {
75
+ exp = exp.pow(Expression_1.Expression.Number(factor.multiplicity));
76
+ }
77
+ return exp;
78
+ }
79
+ /**
80
+ * Converts the factored Expression or Polynomial to an array of Expressions.
81
+ *
82
+ * @param factorObj The integer polynomial factors.
83
+ * @param variables The variable order used by each factor.
84
+ * @returns Expression factors including non-unit content.
85
+ */
86
+ function factorsToExpressions(factorObj, variables) {
87
+ const factors = [];
88
+ // set the terms
89
+ // Add the content
90
+ if (factorObj.content !== 1n) {
91
+ factors.push(Expression_1.Expression.Number(factorObj.content));
92
+ }
93
+ // Now the factors
94
+ for (const factor of factorObj.factors) {
95
+ const f = makeExpression(factor, variables);
96
+ factors.push(f);
97
+ }
98
+ return factors;
99
+ }
100
+ /**
101
+ * Converts the factored Expression or Polynomial to an array of Polynomials.
102
+ *
103
+ * @param factorsObj The integer polynomial factors.
104
+ * @param variables The variable order used by each factor.
105
+ * @returns Polynomial wrappers around the converted factors.
106
+ */
107
+ function factorsToPolynomials(factorsObj, variables) {
108
+ return factorsToExpressions(factorsObj, variables).map(e => new Polynomial_1.Polynomial(e));
109
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @module arith
3
+ *
4
+ * Low-level integer and modular arithmetic helpers used throughout the library.
5
+ *
6
+ * - All integer arithmetic is done with `bigint`.
7
+ * - Modular routines assume a prime modulus `p` when inverses are required.
8
+ */
9
+ /**
10
+ * Shared integer + modular arithmetic primitives used across Zippel GCD and
11
+ * multivariate factorization.
12
+ *
13
+ * Design goals:
14
+ * - BigInt-only arithmetic for coefficient paths.
15
+ * - Small, stable surface area: use `abs`, `gcd`, `pow`.
16
+ */
17
+ /** Absolute value for BigInt. */
18
+ export declare function abs(a: bigint): bigint;
19
+ /**
20
+ * Euclidean GCD for BigInt.
21
+ *
22
+ * Returns a nonnegative gcd. gcd(0,0) = 0.
23
+ */
24
+ export declare function gcd(a: bigint, b: bigint): bigint;
25
+ /**
26
+ * Integer exponentiation for BigInt with a nonnegative exponent.
27
+ *
28
+ * This is NOT modular exponentiation (see {@link modPow}).
29
+ */
30
+ export declare function pow(base: bigint, exp: bigint): bigint;
31
+ /**
32
+ * Integer exponentiation for BigInt with a small nonnegative JS number exponent.
33
+ *
34
+ * Convenience wrapper used throughout factorization code where exponents are known
35
+ * to fit in a number.
36
+ */
37
+ export declare function powN(base: bigint, exp: number): bigint;
38
+ /**
39
+ * Integer square root: floor(sqrt(n)) for n >= 0.
40
+ */
41
+ export declare function bigIntSqrt(n: bigint): bigint;
42
+ /**
43
+ * Exact n-th root if it exists.
44
+ * Returns r such that r^n === value, or null if value is not a perfect n-th power.
45
+ */
46
+ export declare function intNthRootExact(value: bigint, n: number): bigint | null;
47
+ /**
48
+ * Return positive divisors of n (n > 0) by trial division.
49
+ *
50
+ * NOTE: This is intended for small integers used in factoring heuristics.
51
+ */
52
+ export declare function getDivisors(n: bigint): bigint[];
53
+ /** Normalize a into the range [0, |p|). Throws if p is zero. */
54
+ export declare function modNorm(a: bigint, p: bigint): bigint;
55
+ /** Map a to the symmetric residue class (-|p|/2, |p|/2]. */
56
+ export declare function modSymmetric(a: bigint, p: bigint): bigint;
57
+ /** Modular multiplicative inverse of a mod p, where gcd(a,p)=1. */
58
+ export declare function modInv(a: bigint, p: bigint): bigint;
59
+ /**
60
+ * Content (GCD of coefficients) for an iterable of bigint coefficients.
61
+ * Returns 0n for the all-zero collection.
62
+ */
63
+ export declare function contentBigint(coeffs: Iterable<bigint>): bigint;
64
+ /** Bit-length of a bigint (0 -> 0). */
65
+ export declare function bigintBitLength(a: bigint): number;
66
+ /** Next prime >= start. */
67
+ export declare function nextPrime32(start: number): number;
68
+ type AlgebraPhase = 'prime-selection' | 'specialization' | 'lift' | 'reconstruction' | 'verification' | 'budget' | 'normalization' | 'unknown';
69
+ declare class AlgebraError extends Error {
70
+ /** Additional structured debugging info. Always present (possibly empty). */
71
+ readonly details: Record<string, unknown>;
72
+ readonly phase: AlgebraPhase;
73
+ constructor(message: string, phase?: AlgebraPhase, details?: Record<string, unknown>);
74
+ }
75
+ export declare class PrimeSelectionError extends AlgebraError {
76
+ constructor(message: string, details?: Record<string, unknown>);
77
+ }
78
+ /**
79
+ * Thrown when Zippel-style multivariate GCD exceeds its specialization / interpolation budget.
80
+ */
81
+ export declare class GcdBudgetExceededError extends AlgebraError {
82
+ constructor(message: string, details?: Record<string, unknown>);
83
+ }
84
+ export {};