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/Extra.js DELETED
@@ -1,622 +0,0 @@
1
- /*
2
- * Author : Martin Donk
3
- * Website : http://www.nerdamer.com
4
- * Email : martin.r.donk@gmail.com
5
- * License : MIT
6
- * Source : https://github.com/jiggzson/nerdamer
7
- */
8
-
9
- /* global module */
10
-
11
- if((typeof module) !== 'undefined') {
12
- var nerdamer = require('./nerdamer.core.js');
13
- require('./Calculus');
14
- require('./Algebra');
15
- }
16
-
17
- (function () {
18
- "use strict";
19
-
20
- var core = nerdamer.getCore(),
21
- _ = core.PARSER,
22
- Symbol = core.Symbol,
23
- format = core.Utils.format,
24
- isVector = core.Utils.isVector,
25
- isArray = core.Utils.isArray,
26
- Vector = core.Vector,
27
- S = core.groups.S,
28
- EX = core.groups.EX,
29
- CP = core.groups.CP,
30
- CB = core.groups.CB,
31
- FN = core.groups.FN;
32
- core.Settings.Laplace_integration_depth = 40;
33
-
34
-
35
- Symbol.prototype.findFunction = function (fname) {
36
- //this is what we're looking for
37
- if(this.group === FN && this.fname === fname)
38
- return this.clone();
39
- var found;
40
- if(this.symbols)
41
- for(var x in this.symbols) {
42
- found = this.symbols[x].findFunction(fname);
43
- if(found)
44
- break;
45
- }
46
-
47
- return found;
48
- };
49
-
50
- var __ = core.Extra = {
51
- version: '1.4.2',
52
- //http://integral-table.com/downloads/LaplaceTable.pdf
53
- //Laplace assumes all coefficients to be positive
54
- LaPlace: {
55
- //Using: integral_0^oo f(t)*e^(-s*t) dt
56
- transform: function (symbol, t, s) {
57
- symbol = symbol.clone();
58
-
59
- t = t.toString();
60
- //First try a lookup for a speed boost
61
- symbol = Symbol.unwrapSQRT(symbol, true);
62
- var retval,
63
- coeff = symbol.stripVar(t),
64
- g = symbol.group;
65
-
66
- symbol = _.divide(symbol, coeff.clone());
67
-
68
- if(symbol.isConstant() || !symbol.contains(t, true)) {
69
- retval = _.parse(format('({0})/({1})', symbol, s));
70
- }
71
- else if(g === S && core.Utils.isInt(symbol.power)) {
72
- var n = String(symbol.power);
73
- retval = _.parse(format('factorial({0})/({1})^({0}+1)', n, s));
74
- }
75
- else if(symbol.group === S && symbol.power.equals(1 / 2)) {
76
- retval = _.parse(format('sqrt(pi)/(2*({0})^(3/2))', s));
77
- }
78
- else if(symbol.isComposite()) {
79
- retval = new Symbol(0);
80
- symbol.each(function (x) {
81
- retval = _.add(retval, __.LaPlace.transform(x, t, s));
82
- }, true);
83
- }
84
- else if(symbol.isE() && (symbol.power.group === S || symbol.power.group === CB)) {
85
- var a = symbol.power.stripVar(t);
86
- retval = _.parse(format('1/(({1})-({0}))', a, s));
87
- }
88
- else {
89
- var fns = ['sin', 'cos', 'sinh', 'cosh'];
90
- //support for symbols in fns with arguments in the form a*t or n*t where a = symbolic and n = Number
91
- if(symbol.group === FN && fns.indexOf(symbol.fname) !== -1 && (symbol.args[0].group === S || symbol.args[0].group === CB)) {
92
- var a = symbol.args[0].stripVar(t);
93
-
94
- switch(symbol.fname) {
95
- case 'sin':
96
- retval = _.parse(format('({0})/(({1})^2+({0})^2)', a, s));
97
- break;
98
- case 'cos':
99
- retval = _.parse(format('({1})/(({1})^2+({0})^2)', a, s));
100
- break;
101
- case 'sinh':
102
- retval = _.parse(format('({0})/(({1})^2-({0})^2)', a, s));
103
- break;
104
- case 'cosh':
105
- retval = _.parse(format('({1})/(({1})^2-({0})^2)', a, s));
106
- break;
107
- }
108
-
109
- }
110
- else {
111
- //Try to integrate for a solution
112
- //we need at least the Laplace integration depth
113
- var depth_is_lower = core.Settings.integration_depth < core.Settings.Laplace_integration_depth;
114
-
115
- if(depth_is_lower) {
116
- var integration_depth = core.Settings.integration_depth; //save the depth
117
- core.Settings.integration_depth = core.Settings.Laplace_integration_depth; //transforms need a little more room
118
- }
119
-
120
- core.Utils.block('PARSE2NUMBER', function () {
121
- var u = t;
122
- var sym = symbol.sub(t, u);
123
- var integration_expr = _.parse('e^(-' + s + '*' + u + ')*' + sym);
124
- retval = core.Calculus.integrate(integration_expr, u);
125
- if(retval.hasIntegral())
126
- return _.symfunction('laplace', arguments);
127
- // _.error('Unable to compute transform');
128
- retval = retval.sub(t, 0);
129
- retval = _.expand(_.multiply(retval, new Symbol(-1)));
130
- retval = retval.sub(u, t);
131
- }, false);
132
-
133
- retval = core.Utils.block('PARSE2NUMBER', function () {
134
- return _.parse(retval);
135
- }, true);
136
-
137
- if(depth_is_lower)//put the integration depth as it was
138
- core.Settings.integration_depth = integration_depth;
139
- }
140
-
141
- }
142
-
143
- return _.multiply(retval, coeff);
144
- },
145
- inverse: function (symbol, s_, t) {
146
- var input_symbol = symbol.clone();
147
- return core.Utils.block('POSITIVE_MULTIPLIERS', function () {
148
- //expand and get partial fractions
149
- if(symbol.group === CB) {
150
- symbol = core.Algebra.PartFrac.partfrac(_.expand(symbol), s_);
151
- }
152
-
153
- if(symbol.group === S || symbol.group === CB || symbol.isComposite()) {
154
- var finalize = function () {
155
- //put back the numerator
156
- retval = _.multiply(retval, num);
157
- retval.multiplier = retval.multiplier.multiply(symbol.multiplier);
158
- //put back a
159
- retval = _.divide(retval, f.a);
160
- };
161
- var num, den, s, retval, f, p, m, den_p, fe;
162
- //remove the multiplier
163
- m = symbol.multiplier.clone();
164
- symbol.toUnitMultiplier();
165
- //get the numerator and denominator
166
- num = symbol.getNum();
167
- den = symbol.getDenom().toUnitMultiplier();
168
-
169
- //TODO: Make it so factor doesn't destroy pi
170
- //num = core.Algebra.Factor.factor(symbol.getNum());
171
- //den = core.Algebra.Factor.factor(symbol.getDenom().invert(null, true));
172
-
173
- if(den.group === CP) {
174
- den_p = den.power.clone();
175
- den.toLinear();
176
- }
177
- else {
178
- den_p = new core.Frac(1);
179
- }
180
-
181
- //convert s to a string
182
- s = s_.toString();
183
- //split up the denominator if in the form ax+b
184
- f = core.Utils.decompose_fn(den, s, true);
185
- //move the multiplier to the numerator
186
- fe = core.Utils.decompose_fn(_.expand(num.clone()), s, true);
187
- num.multiplier = num.multiplier.multiply(m);
188
- //store the parts in variables for easy recognition
189
- //check if in the form t^n where n = integer
190
- if((den.group === S || den.group === CB) && f.x.value === s && f.b.equals(0) && core.Utils.isInt(f.x.power)) {
191
- var fact, p;
192
- p = f.x.power - 1;
193
- fact = core.Math2.factorial(p);
194
- // n!/s^(n-1)
195
- retval = _.divide(_.pow(t, new Symbol(p)), new Symbol(fact));
196
- //wrap it up
197
- finalize();
198
- }
199
- else if(den.group === CP && den_p.equals(1)) {
200
- if(f.x.group === core.groups.PL && core.Algebra.degree(den).equals(2)) {
201
- // Possibly in the form 1/(s^2+2*s+1)
202
- // Try factoring to get it in a more familiar form{
203
- // Apply inverse of F(s-a)
204
- var completed = core.Algebra.sqComplete(den, s);
205
- var u = core.Utils.getU(den);
206
- // Get a for the function above
207
- var a = core.Utils.decompose_fn(completed.a, s, true).b;
208
- var tf = __.LaPlace.inverse(_.parse(`1/((${u})^2+(${completed.c}))`), u, t);
209
- retval = _.multiply(tf, _.parse(`(${m})*e^(-(${a})*(${t}))`));
210
- }
211
- else {
212
- // a/(b*s-c) -> ae^(-bt)
213
- if(f.x.isLinear() && !num.contains(s)) {
214
- t = _.divide(t, f.a.clone());
215
-
216
- // Don't add factorial of one or zero
217
- var p = den_p - 1;
218
- var fact = p === 0 || p === 1 ? '1' : `(${den_p}-1)!`
219
- retval = _.parse(format('(({0})^({3}-1)*e^(-(({2})*({0}))/({1})))/(({4})*({1})^({3}))', t, f.a, f.b, den_p, fact));
220
- //wrap it up
221
- finalize();
222
- }
223
- else {
224
- if(f.x.group === S && f.x.power.equals(2)) {
225
- if(!num.contains(s)) {
226
- retval = _.parse(format('(({1})*sin((sqrt(({2})*({3}))*({0}))/({2})))/sqrt(({2})*({3}))', t, num, f.a, f.b));
227
- }
228
- // a*s/(b*s^2+c^2)
229
- else {
230
- var a = new Symbol(1);
231
- if(num.group === CB) {
232
- var new_num = new Symbol(1);
233
- num.each(function (x) {
234
- if(x.contains(s))
235
- new_num = _.multiply(new_num, x);
236
- else
237
- a = _.multiply(a, x);
238
- });
239
- num = new_num;
240
- }
241
-
242
- //we need more information about the denominator to decide
243
- var f2 = core.Utils.decompose_fn(num, s, true);
244
- var fn1, fn2, a_has_sin, b_has_cos, a_has_cos, b_has_sin;
245
- fn1 = f2.a;
246
- fn2 = f2.b;
247
- a_has_sin = fn1.containsFunction('sin');
248
- a_has_cos = fn1.containsFunction('cos');
249
- b_has_cos = fn2.containsFunction('cos');
250
- b_has_sin = fn2.containsFunction('sin');
251
- if(f2.x.value === s && f2.x.isLinear() && !((a_has_sin && b_has_cos) || (a_has_cos || b_has_sin))) {
252
- retval = _.parse(format('(({1})*cos((sqrt(({2})*({3}))*({0}))/({2})))/({2})', t, f2.a, f.a, f.b));
253
- }
254
- else {
255
- if(a_has_sin && b_has_cos) {
256
- var sin, cos;
257
- sin = fn1.findFunction('sin');
258
- cos = fn2.findFunction('cos');
259
- //who has the s?
260
- if(sin.args[0].equals(cos.args[0]) && !sin.args[0].contains(s)) {
261
- var b, c, d, e;
262
- b = _.divide(fn2, cos.toUnitMultiplier()).toString();
263
- c = sin.args[0].toString();
264
- d = f.b;
265
- e = _.divide(fn1, sin.toUnitMultiplier());
266
- exp = '(({1})*({2})*cos({3})*sin(sqrt({4})*({0})))/sqrt({4})+({1})*sin({3})*({5})*cos(sqrt({4})*({0}))';
267
- retval = _.parse(format(exp, t, a, b, c, d, e));
268
- }
269
- }
270
- }
271
- }
272
- }
273
- }
274
- }
275
- }
276
- else if(f.x.power.num && f.x.power.num.equals(3) && f.x.power.den.equals(2) && num.contains('sqrt(pi)') && !num.contains(s) && num.isLinear()) {
277
- var b = _.divide(num.clone(), _.parse('sqrt(pi)'));
278
- retval = _.parse(format('(2*({2})*sqrt({0}))/({1})', t, f.a, b, num));
279
- }
280
- else if(den_p.equals(2) && f.x.power.equals(2)) {
281
- var a, d, exp;
282
- if(!num.contains(s)) {
283
- a = _.divide(num, new Symbol(2));
284
- exp = '(({1})*sin((sqrt(({2})*({3}))*({0}))/({2})))/(({3})*sqrt(({2})*({3})))-(({1})*({0})*cos((sqrt(({2})*({3}))*({0}))/({2})))/(({2})*({3}))';
285
- retval = _.parse(format(exp, t, a, f.a, f.b));
286
- }
287
- else {
288
- // Decompose the numerator to check value of s
289
- f2 = core.Utils.decompose_fn(_.expand(num.clone()), s, true);
290
- if(f2.x.isComposite()) {
291
- var s_terms = [];
292
- //first collect the factors e.g. (a)(bx)(cx^2+d)
293
- var symbols = num.collectSymbols(function (x) {
294
- x = Symbol.unwrapPARENS(x);
295
- var t = core.Utils.decompose_fn(x, s, true);
296
- t.symbol = x;
297
- return t;
298
- }).
299
- //then sort them by power hightest to lowest
300
- sort(function (a, b) {
301
- var p1, p2;
302
- p1 = a.x.value !== s ? 0 : a.x.power;
303
- p2 = b.x.value !== s ? 0 : b.x.power;
304
- return p2 - p1;
305
- });
306
- a = new Symbol(-1);
307
- // Grab only the ones which have s
308
- for(var i = 0; i < symbols.length; i++) {
309
- var fc = symbols[i];
310
- if(fc.x.value === s)
311
- s_terms.push(fc);
312
- else
313
- a = _.multiply(a, fc.symbol);
314
- }
315
- // The following 2 assumptions are made
316
- // 1. since the numerator was factored above then each s_term has a unique power
317
- // 2. because the terms are sorted by descending powers then the first item
318
- // has the highest power
319
- // We can now check for the next type s(s^2-a^2)/(s^2+a^2)^2
320
- if(s_terms[0].x.power.equals(2) && s_terms[1].x.power.equals(1) && s_terms[1].b.equals(0) && !s_terms[0].b.equals(0)) {
321
- b = s_terms[0].a.negate();
322
- exp = '-(({1})*({2})*({5})*({0})*sin((sqrt(({4})*({5}))*({0}))/({4})))/' +
323
- '(2*({4})^2*sqrt(({4})*({5})))-(({1})*({3})*({0})*sin((sqrt(({4})*({5}))*({0}))/({4})))' +
324
- '/(2*({4})*sqrt(({4})*({5})))+(({1})*({2})*cos((sqrt(({4})*({5}))*({0}))/({4})))/({4})^2';
325
- retval = _.parse(format(exp, t, a, b, s_terms[0].b, f.a, f.b));
326
- }
327
- }
328
- else {
329
- if(f2.x.isLinear()) {
330
- a = _.divide(f2.a, new Symbol(2));
331
- exp = '(({1})*({0})*sin((sqrt(({2})*({3}))*({0}))/({2})))/(({2})*sqrt(({2})*({3})))';
332
- retval = _.parse(format(exp, t, a, f.a, f.b));
333
- }
334
- else if(f2.x.power.equals(2)) {
335
- if(f2.b.equals(0)) {
336
- a = _.divide(f2.a, new Symbol(2));
337
- exp = '(({1})*sin((sqrt(({2})*({3}))*({0}))/({2})))/(({2})*sqrt(({2})*({3})))+(({1})*({0})*cos((sqrt(({2})*({3}))*({0}))/({2})))/({2})^2';
338
- retval = _.parse(format(exp, t, a, f.a, f.b));
339
- }
340
- else {
341
- a = _.divide(f2.a, new Symbol(2));
342
- d = f2.b.negate();
343
- exp = '-((({2})*({4})-2*({1})*({3}))*sin((sqrt(({2})*({3}))*({0}))/({2})))/(2*({2})*({3})*sqrt(({2})*({3})))+' +
344
- '(({4})*({0})*cos((sqrt(({2})*({3}))*({0}))/({2})))/(2*({2})*({3}))+(({1})*({0})*cos((sqrt(({2})*({3}))*({0}))/({2})))/({2})^2';
345
- retval = _.parse(format(exp, t, a, f.a, f.b, d));
346
-
347
- }
348
- }
349
- }
350
- }
351
- }
352
- else if(symbol.isComposite()) {
353
- // 1/(s+1)^2
354
- if(den_p.equals(2) && f.x.group === S) {
355
- retval = _.parse(`(${m})*(${t})*e^(-(${f.b})*(${t}))`);
356
- }
357
- else {
358
- retval = new Symbol(0);
359
-
360
- symbol.each(function (x) {
361
- retval = _.add(retval, __.LaPlace.inverse(x, s_, t));
362
- }, true);
363
- }
364
- }
365
- }
366
-
367
- if(!retval) {
368
- retval = _.symfunction('ilt', [input_symbol, s_, t]);
369
- }
370
-
371
- return retval;
372
- }, true);
373
- }
374
- },
375
- Statistics: {
376
- frequencyMap: function (arr) {
377
- var map = {};
378
- //get the frequency map
379
- for(var i = 0, l = arr.length; i < l; i++) {
380
- var e = arr[i],
381
- key = e.toString();
382
- if(!map[key]) //default it to zero
383
- map[key] = 0;
384
- map[key]++; //increment
385
- }
386
- return map;
387
- },
388
- sort: function (arr) {
389
- return arr.sort(function (a, b) {
390
- if(!a.isConstant() || !b.isConstant())
391
- _.error('Unable to sort! All values must be numeric');
392
- return a.multiplier.subtract(b.multiplier);
393
- });
394
- },
395
- count: function (arr) {
396
- return new Symbol(arr.length);
397
- },
398
- sum: function (arr, x_) {
399
- var sum = new Symbol(0);
400
- for(var i = 0, l = arr.length; i < l; i++) {
401
- var xi = arr[i].clone();
402
- if(x_) {
403
- sum = _.add(_.pow(_.subtract(xi, x_.clone()), new Symbol(2)), sum);
404
- }
405
- else
406
- sum = _.add(xi, sum);
407
- }
408
-
409
- return sum;
410
- },
411
- mean: function () {
412
- var args = [].slice.call(arguments);
413
- //handle arrays
414
- if(isVector(args[0]))
415
- return __.Statistics.mean.apply(this, args[0].elements);
416
- return _.divide(__.Statistics.sum(args), __.Statistics.count(args));
417
- },
418
- median: function () {
419
- var args = [].slice.call(arguments), retval;
420
- //handle arrays
421
- if(isVector(args[0]))
422
- return __.Statistics.median.apply(this, args[0].elements);
423
- try {
424
- var sorted = __.Statistics.sort(args);
425
- var l = args.length;
426
- if(core.Utils.even(l)) {
427
- var mid = l / 2;
428
- retval = __.Statistics.mean(sorted[mid - 1], sorted[mid]);
429
- }
430
- else
431
- retval = sorted[Math.floor(l / 2)];
432
- }
433
- catch(e) {
434
- retval = _.symfunction('median', args);
435
- }
436
- return retval;
437
- },
438
- mode: function () {
439
- var args = [].slice.call(arguments),
440
- retval;
441
- //handle arrays
442
- if(isVector(args[0]))
443
- return __.Statistics.mode.apply(this, args[0].elements);
444
-
445
- var map = __.Statistics.frequencyMap(args);
446
-
447
- //the mode of 1 item is that item as per issue #310 (verified by Happypig375).
448
- if(core.Utils.keys(map).length === 1)
449
- retval = args[0];
450
- else {
451
- //invert by arraning them according to their frequency
452
- var inverse = {};
453
- for(var x in map) {
454
- var freq = map[x];
455
- //check if it's in the inverse already
456
- if(!(freq in inverse))
457
- inverse[freq] = x;
458
- else {
459
- var e = inverse[freq];
460
- //if it's already an array then just add it
461
- if(isArray(e))
462
- e.push(x);
463
- //convert it to and array
464
- else
465
- inverse[freq] = [x, inverse[freq]];
466
- }
467
- }
468
- //the keys now represent the maxes. We want the max of those keys
469
- var max = inverse[Math.max.apply(null, core.Utils.keys(inverse))];
470
- //check it's an array. If it is then map over the results and convert
471
- //them to Symbol
472
- if(isArray(max)) {
473
- retval = _.symfunction('mode', max.sort());
474
- }
475
- else
476
- retval = _.parse(max);
477
- }
478
-
479
- return retval;
480
- },
481
- gVariance: function (k, args) {
482
- var x_ = __.Statistics.mean.apply(__.Statistics, args),
483
- sum = __.Statistics.sum(args, x_);
484
- return _.multiply(k, sum);
485
- },
486
- variance: function () {
487
- var args = [].slice.call(arguments);
488
- //handle arrays
489
- if(isVector(args[0]))
490
- return __.Statistics.variance.apply(this, args[0].elements);
491
- var k = _.divide(new Symbol(1), __.Statistics.count(args));
492
- return __.Statistics.gVariance(k, args);
493
- },
494
- sampleVariance: function () {
495
- var args = [].slice.call(arguments);
496
- //handle arrays
497
- if(isVector(args[0]))
498
- return __.Statistics.sampleVariance.apply(this, args[0].elements);
499
-
500
- var k = _.divide(new Symbol(1), _.subtract(__.Statistics.count(args), new Symbol(1)));
501
- return __.Statistics.gVariance(k, args);
502
- },
503
- standardDeviation: function () {
504
- var args = [].slice.call(arguments);
505
- //handle arrays
506
- if(isVector(args[0]))
507
- return __.Statistics.standardDeviation.apply(this, args[0].elements);
508
- return _.pow(__.Statistics.variance.apply(__.Statistics, args), new Symbol(1 / 2));
509
- },
510
- sampleStandardDeviation: function () {
511
- var args = [].slice.call(arguments);
512
- //handle arrays
513
- if(isVector(args[0]))
514
- return __.Statistics.sampleStandardDeviation.apply(this, args[0].elements);
515
- return _.pow(__.Statistics.sampleVariance.apply(__.Statistics, args), new Symbol(1 / 2));
516
- },
517
- zScore: function (x, mean, stdev) {
518
- return _.divide(_.subtract(x, mean), stdev);
519
- }
520
- },
521
- Units: {
522
- table: {
523
- foot: '12 inch',
524
- meter: '100 cm',
525
- decimeter: '10 cm',
526
-
527
- }
528
- }
529
- };
530
-
531
- nerdamer.register([
532
- {
533
- name: 'laplace',
534
- visible: true,
535
- numargs: 3,
536
- build: function () {
537
- return __.LaPlace.transform;
538
- }
539
- },
540
- {
541
- name: 'ilt',
542
- visible: true,
543
- numargs: 3,
544
- build: function () {
545
- return __.LaPlace.inverse;
546
- }
547
- },
548
- //statistical
549
- {
550
- name: 'mean',
551
- visible: true,
552
- numargs: -1,
553
- build: function () {
554
- return __.Statistics.mean;
555
- }
556
- },
557
- {
558
- name: 'median',
559
- visible: true,
560
- numargs: -1,
561
- build: function () {
562
- return __.Statistics.median;
563
- }
564
- },
565
- {
566
- name: 'mode',
567
- visible: true,
568
- numargs: -1,
569
- build: function () {
570
- return __.Statistics.mode;
571
- }
572
- },
573
- {
574
- name: 'smpvar',
575
- visible: true,
576
- numargs: -1,
577
- build: function () {
578
- return __.Statistics.sampleVariance;
579
- }
580
- },
581
- {
582
- name: 'variance',
583
- visible: true,
584
- numargs: -1,
585
- build: function () {
586
- return __.Statistics.variance;
587
- }
588
- },
589
- {
590
- name: 'smpstdev',
591
- visible: true,
592
- numargs: -1,
593
- build: function () {
594
- return __.Statistics.sampleStandardDeviation;
595
- }
596
- },
597
- {
598
- name: 'stdev',
599
- visible: true,
600
- numargs: -1,
601
- build: function () {
602
- return __.Statistics.standardDeviation;
603
- }
604
- },
605
- {
606
- name: 'zscore',
607
- visible: true,
608
- numargs: 3,
609
- build: function () {
610
- return __.Statistics.zScore;
611
- }
612
- }
613
- ]);
614
-
615
- //link registered functions externally
616
- nerdamer.updateAPI();
617
- }());
618
-
619
- // Added for all.min.js
620
- if((typeof module) !== 'undefined') {
621
- module.exports = nerdamer;
622
- };