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
@@ -1,302 +0,0 @@
1
- /* global expect */
2
-
3
- 'use strict';
4
-
5
- var nerdamer = require('../nerdamer.core.js');
6
-
7
- describe('TeX features', function () {
8
- it('should render TeX output correctly', function () {
9
- var testCases = [
10
- {
11
- given: '2',
12
- TeX: '2',
13
- decimalTeX: '2'
14
- }, {
15
- given: '1/2',
16
- TeX: '\\frac{1}{2}',
17
- decimalTeX: '0.5'
18
- }, {
19
- given: '2*x',
20
- TeX: '2 \\cdot x',
21
- decimalTeX: '2 \\cdot x'
22
- }, {
23
- given: '2/5*x',
24
- TeX: '\\frac{2 \\cdot x}{5}',
25
- decimalTeX: '0.4 \\cdot x'
26
- }, {
27
- given: '2/5*x^2',
28
- TeX: '\\frac{2 \\cdot x^{2}}{5}',
29
- decimalTeX: '0.4 \\cdot x^{2}'
30
- }, {
31
- given: '1/2*x',
32
- TeX: '\\frac{x}{2}',
33
- decimalTeX: '0.5 \\cdot x'
34
- }, {
35
- given: '1/2*x^2',
36
- TeX: '\\frac{x^{2}}{2}',
37
- decimalTeX: '0.5 \\cdot x^{2}'
38
- }, {
39
- given: '1/2*2^(2/3)',
40
- TeX: '\\frac{1}{2^{\\frac{1}{3}}}',
41
- decimalTeX: '0.7937005259840998'
42
- }, {
43
- given: '2^(2/3)',
44
- TeX: '2^{\\frac{2}{3}}',
45
- decimalTeX: '1.5874010519681994'
46
- }, {
47
- given: '5/8*2^(2/3)*4',
48
- TeX: '\\frac{5}{2^{\\frac{1}{3}}}',
49
- decimalTeX: '3.968502629920499'
50
- },
51
- {
52
- given: '3*x^(2/3)/4',
53
- TeX: '\\frac{3 \\cdot x^{\\frac{2}{3}}}{4}',
54
- decimalTeX: '0.75 \\cdot x^{0.66666666666666666667}'
55
- },
56
- {
57
- given: '4*cos(x)',
58
- TeX: '4 \\cdot \\mathrm{cos}\\left(x\\right)',
59
- decimalTeX: '4 \\cdot \\mathrm{cos}\\left(x\\right)'
60
- }, {
61
- given: '(1/4)*cos(x)',
62
- TeX: '\\frac{\\mathrm{cos}\\left(x\\right)}{4}',
63
- decimalTeX: '0.25 \\cdot \\mathrm{cos}\\left(x\\right)'
64
- }, {
65
- given: '(5/4)*cos(x)',
66
- TeX: '\\frac{5 \\cdot \\mathrm{cos}\\left(x\\right)}{4}',
67
- decimalTeX: '1.25 \\cdot \\mathrm{cos}\\left(x\\right)'
68
- }, {
69
- given: '7/8*sqrt(x)',
70
- TeX: '\\frac{7 \\cdot \\sqrt{x}}{8}',
71
- decimalTeX: '0.875 \\cdot \\sqrt{x}'
72
- }, {
73
- given: '1/8*sqrt(x+8)',
74
- TeX: '\\frac{\\sqrt{x+8}}{8}',
75
- decimalTeX: '0.125 \\cdot \\sqrt{x+8}'
76
- }, {
77
- given: 'x/(x+y)',
78
- TeX: '\\frac{x}{x+y}',
79
- decimalTeX: '\\frac{x}{x+y}'
80
- }, {
81
- given: 'x/(x+y)^3',
82
- TeX: '\\frac{x}{\\left(x+y\\right)^{3}}',
83
- decimalTeX: '\\frac{x}{\\left(x+y\\right)^{3}}'
84
- }, {
85
- given: '(x+y)^3/x',
86
- TeX: '\\frac{\\left(x+y\\right)^{3}}{x}',
87
- decimalTeX: '\\frac{\\left(x+y\\right)^{3}}{x}'
88
- }, {
89
- given: '((x+1)*(x+2))/(x+5)',
90
- TeX: '\\frac{\\left(x+1\\right) \\cdot \\left(x+2\\right)}{x+5}',
91
- decimalTeX: '\\frac{\\left(x+1\\right) \\cdot \\left(x+2\\right)}{x+5}'
92
- }, {
93
- given: '((x+1)*(x+2)*u)/((x+5)*z)',
94
- TeX: '\\frac{\\left(x+1\\right) \\cdot \\left(x+2\\right) \\cdot u}{\\left(x+5\\right) \\cdot z}',
95
- decimalTeX: '\\frac{\\left(x+1\\right) \\cdot \\left(x+2\\right) \\cdot u}{\\left(x+5\\right) \\cdot z}'
96
- }, {
97
- given: '2/(x+y)^3',
98
- TeX: '\\frac{2}{\\left(x+y\\right)^{3}}',
99
- decimalTeX: '\\frac{2}{\\left(x+y\\right)^{3}}'
100
- }, {
101
- given: '2*(x+1)/(x+y)^3',
102
- TeX: '\\frac{2\\left(x+1\\right)}{\\left(x+y\\right)^{3}}',
103
- decimalTeX: '\\frac{2\\left(x+1\\right)}{\\left(x+y\\right)^{3}}'
104
- }, {
105
- given: '2*(x+1)^2/(x+y)^3',
106
- TeX: '\\frac{2 \\cdot \\left(x+1\\right)^{2}}{\\left(x+y\\right)^{3}}',
107
- decimalTeX: '\\frac{2 \\cdot \\left(x+1\\right)^{2}}{\\left(x+y\\right)^{3}}'
108
- }, {
109
- given: '(x)^x/(x+1)',
110
- TeX: '\\frac{x^{x}}{x+1}',
111
- decimalTeX: '\\frac{x^{x}}{x+1}'
112
- }, {
113
- given: '(3/4)*(x+y)^x/(x+5)^2',
114
- TeX: '\\frac{3 \\cdot \\left(x+y\\right)^{x}}{4 \\cdot \\left(x+5\\right)^{2}}',
115
- decimalTeX: '\\frac{0.75 \\cdot \\left(x+y\\right)^{x}}{\\left(x+5\\right)^{2}}'
116
- }, {
117
- given: '(3/4)*abs(x+y)^x/(x+5)^2',
118
- TeX: '\\frac{3 \\cdot \\left|x+y\\right|^{x}}{4 \\cdot \\left(x+5\\right)^{2}}',
119
- decimalTeX: '\\frac{0.75 \\cdot \\left|x+y\\right|^{x}}{\\left(x+5\\right)^{2}}'
120
- }, {
121
- given: 'x^(1/4)+3/4*x^2+cos(1/4)',
122
- TeX: '\\frac{3 \\cdot x^{2}}{4}+x^{\\frac{1}{4}}+\\mathrm{cos}\\left(\\frac{1}{4}\\right)',
123
- decimalTeX: '0.75 \\cdot x^{2}+x^{0.25}+\\mathrm{cos}\\left(0.25\\right)'
124
- }, {
125
- given: '-(x^wtf+1)^6-(t+1)/(x+3)^2',
126
- TeX: '-\\left(x^{wtf}+1\\right)^{6}-\\frac{t+1}{\\left(x+3\\right)^{2}}',
127
- decimalTeX: '-\\left(x^{wtf}+1\\right)^{6}-\\frac{t+1}{\\left(x+3\\right)^{2}}'
128
- }, {
129
- given: '2*(-log(x)*sin(x)+cos(x)*x^(-1))',
130
- TeX: '2\\left(-\\mathrm{log}\\left(x\\right) \\cdot \\mathrm{sin}\\left(x\\right)+\\frac{\\mathrm{cos}\\left(x\\right)}{x}\\right)',
131
- decimalTeX: '2\\left(-\\mathrm{log}\\left(x\\right) \\cdot \\mathrm{sin}\\left(x\\right)+\\frac{\\mathrm{cos}\\left(x\\right)}{x}\\right)'
132
- }, {
133
- given: '(x*(x+1))/(x^2+2*x+1)',
134
- TeX: '\\frac{x \\cdot \\left(x+1\\right)}{x^{2}+2 \\cdot x+1}',
135
- decimalTeX: '\\frac{x \\cdot \\left(x+1\\right)}{x^{2}+2 \\cdot x+1}'
136
- }, {
137
- given: 'x^2+2*x+y^2+y+6',
138
- TeX: 'x^{2}+2 \\cdot x+y^{2}+y+6',
139
- decimalTeX: 'x^{2}+2 \\cdot x+y^{2}+y+6'
140
- }, {
141
- given: '(-1*(x-1))',
142
- TeX: '-x+1',
143
- decimalTeX: '-x+1'
144
- }, {
145
- given: 'x!',
146
- TeX: 'x!',
147
- decimalTeX: 'x!'
148
- }, {
149
- given: '(x+1)!',
150
- TeX: '\\left(x+1\\right)!',
151
- decimalTeX: '\\left(x+1\\right)!'
152
- },
153
- {
154
- given: 'x!+(x+1)!',
155
- TeX: '\\left(x+1\\right)!+x!',
156
- decimalTeX: '\\left(x+1\\right)!+x!'
157
- },
158
- {
159
- given: '(x/(x+y))^n',
160
- TeX: '\\frac{x^{n}}{x+y}',
161
- decimalTeX: '\\frac{x^{n}}{x+y}'
162
- },
163
- {
164
- given: '1/(a*b)',
165
- TeX: '\\frac{1}{a \\cdot b}',
166
- decimalTeX: '\\frac{1}{a \\cdot b}'
167
- },
168
- {
169
- given: 'sum(a,b,c,Infinity)',
170
- TeX: '\\sum\\limits_{{b}={c}}^{\\infty} {a}',
171
- decimalTeX: '\\sum\\limits_{{b}={c}}^{\\infty} {a}'
172
- },
173
- {
174
- given: 'product(a,b,c,Infinity)',
175
- TeX: '\\prod\\limits_{{b}={c}}^{\\infty} {a}',
176
- decimalTeX: '\\prod\\limits_{{b}={c}}^{\\infty} {a}'
177
- },
178
- {
179
- given: 'mod(a,b)',
180
- TeX: 'a \\bmod b',
181
- decimalTeX: 'a \\bmod b'
182
- },
183
- {
184
- given: 'nthroot(a,b)',
185
- TeX: '\\sqrt[b]{a}',
186
- decimalTeX: '\\sqrt[b]{a}'
187
- },
188
- {
189
- given: 'x_aa_bb+y_cc_dd',
190
- TeX: 'x_{aa_{bb}}+y_{cc_{dd}}',
191
- decimalTeX: 'x_{aa_{bb}}+y_{cc_{dd}}'
192
- }
193
- ];
194
-
195
- for(var i = 0; i < testCases.length; ++i) {
196
- // when
197
- var teX = nerdamer(testCases[i].given).toTeX();
198
- var decimalTex = nerdamer(testCases[i].given).toTeX('decimal');
199
-
200
- // then
201
- expect(teX).toEqual(testCases[i].TeX, 'for formula ' + testCases[i].given);
202
- expect(decimalTex).toEqual(testCases[i].decimalTeX, 'for formula ' + testCases[i].given);
203
- }
204
- });
205
-
206
- /** #36: Weird results with sqrt */
207
- it('should render square roots properly', function () {
208
- // given
209
- var formula = '2*sqrt(x)';
210
-
211
- // when
212
- var teX = nerdamer(formula).toTeX();
213
-
214
- // then
215
- expect(teX).toEqual('2 \\cdot \\sqrt{x}');
216
- });
217
-
218
- /** #39: Terms multiplied in brackets not rendered correctly */
219
- it('should render parentheses', function () {
220
- // given
221
- var formula = '(x+1)*(x+2)';
222
-
223
- // when
224
- var teX = nerdamer(formula).toTeX();
225
-
226
- // then
227
- expect(teX).toEqual('\\left(x+1\\right) \\cdot \\left(x+2\\right)');
228
- });
229
-
230
- /** #41: Latex output should use descending order */
231
- it('should use descending order of polynomials', function () {
232
- // given
233
- var formula = 'x^2+x+1';
234
-
235
- // when
236
- var teX = nerdamer(formula).toTeX();
237
-
238
- // then
239
- expect(teX).toEqual('x^{2}+x+1');
240
- });
241
-
242
- it('should support Greek letters', function () {
243
- // given
244
- var testCases = [
245
- {
246
- given: 'alpha + beta',
247
- expected: '\\alpha+\\beta'
248
- },
249
- {
250
- given: '5 * 3 / psi',
251
- expected: '\\frac{15}{\\psi}'
252
- },
253
- {
254
- given: 'Xi ^ tau - 8*nu',
255
- expected: '\\Xi^{\\tau}-8 \\cdot \\nu'
256
- }
257
- ];
258
-
259
- for(var i = 0; i < testCases.length; ++i) {
260
- // when
261
- var teX = nerdamer(testCases[i].given).toTeX();
262
-
263
- // then
264
- expect(teX).toEqual(testCases[i].expected);
265
- }
266
- });
267
-
268
- it('should explicitly convert to LaTeX', function () {
269
- expect(nerdamer.convertToLaTeX('realpart(a)')).toEqual('\\operatorname{Re}\\left(a\\right)');
270
- expect(nerdamer.convertToLaTeX('imagpart(a)')).toEqual('\\operatorname{Im}\\left(a\\right)');
271
- expect(nerdamer.convertToLaTeX('diff(cos(x),x)')).toEqual('\\frac{d}{d x}\\left({\\mathrm{cos}\\left(x\\right)}\\right)');
272
- expect(nerdamer.convertToLaTeX('integrate(cos(x),x)')).toEqual('\\int {\\mathrm{cos}\\left(x\\right)}\\, dx');
273
- expect(nerdamer.convertToLaTeX('2*(sqrt(3)+sqrt(2))')).toEqual('2 \\cdot \\left(\\sqrt{3} + \\sqrt{2}\\right)');
274
- expect(nerdamer.convertToLaTeX('(a+1)(x+a)^(-5)+1')).toEqual('\\frac{a + 1}{{\\left(x + a\\right)}^{5}} + 1');
275
- expect(nerdamer.convertToLaTeX('a*x^-3+1/a')).toEqual('\\frac{a}{{x}^{3}} + \\frac{1}{a}');
276
- expect(nerdamer.convertToLaTeX('a*x^+3+1/a')).toEqual('a \\cdot {x}^{3} + \\frac{1}{a}');
277
- expect(nerdamer.convertToLaTeX('x^2/y-x')).toEqual('\\frac{{x}^{2}}{y} - x');
278
- });
279
-
280
- it('should display integrals', function () {
281
- // given
282
- var testCases = [
283
- {
284
- given: 'defint(log(2cos(x/2)),-π,π,x)',
285
- expected: '\\int\\limits_{-\\pi}^{\\pi} \\mathrm{log}\\left(2 \\cdot \\mathrm{cos}\\left(\\frac{x}{2}\\right)\\right) dx'
286
- },
287
- {
288
- given: 'integrate(sin(x^x),x)',
289
- expected: '\\int{\\mathrm{sin}\\left(x^{x}\\right)}{dx}'
290
- },
291
- ];
292
-
293
- for(var i = 0; i < testCases.length; ++i) {
294
- // when
295
- var teX = nerdamer(testCases[i].given).toTeX();
296
-
297
- // then
298
- expect(teX).toEqual(testCases[i].expected);
299
- }
300
- });
301
-
302
- });
@@ -1,8 +0,0 @@
1
- var nerdamer = require('../nerdamer.core.js');
2
- it('Should convert from TeX', function () {
3
- expect(nerdamer.convertFromLaTeX('x^6 \\cdot cos(\\frac{1}{2})').toString()).toEqual('cos(1/2)*x^6');
4
- expect(nerdamer.convertFromLaTeX('\\sqrt[3]{1+a}+1').toString()).toEqual('(1+a)^(1/3)+1');
5
- expect(nerdamer.convertFromLaTeX('\\begin{matrix} \\begin{matrix}1 & 2 \\\\ 7 & 8\\end{matrix} & 2+9 \\\\ 7 & 8\\end{matrix}').toString())
6
- .toEqual('matrix([matrix([1,2],[7,8]),11],[7,8])');
7
- expect(nerdamer.convertFromLaTeX('\\int_{0}^{\\pi}(\\sin(y)),y').toString()).toEqual('defint(sin(y),0,pi,y)');
8
- });
@@ -1,287 +0,0 @@
1
- /* global expect */
2
-
3
- 'use strict';
4
-
5
- var nerdamer = require('../nerdamer.core.js');
6
- require('../Algebra.js');
7
-
8
- describe('Algebra', function () {
9
- it('should perform gcd operations correctly', function () {
10
- expect(nerdamer('gcd(5*x^6+5*x^5+27*x^4+27*x^3+28*x^2+28*x, 5*x^3+7*x)').toString()).toEqual('5*x^3+7*x');
11
- expect(nerdamer('gcd(-20+16*i,-10+8*i)').toString()).toEqual('-10+8*i');
12
- expect(nerdamer('gcd(2*x^2+2*x+1,x+1)').toString()).toEqual('1');
13
- expect(nerdamer('gcd(x^2+2*x+1,x+1)').toString()).toEqual('1+x');
14
- expect(nerdamer('gcd(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, (2*x^2+8*x+5))').toString()).toEqual('2*x^2+8*x+5');
15
- expect(nerdamer('gcd(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3))').toString()).toEqual('3+x^3');
16
- expect(nerdamer('gcd(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, x^7+1)').toString()).toEqual('1+x^7');
17
- expect(nerdamer('gcd(1+x^2,2*x)').toString()).toEqual('1');
18
- expect(nerdamer('gcd(84*x^4+147*x^3+16*x^2+28*x, 44*x^5+77*x^4+16*x^3+28*x^2+12*x+21)').toString()).toEqual('4*x+7');
19
- expect(nerdamer('gcd(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x)').toString()).toEqual('5*x^5+x');
20
- expect(nerdamer('gcd(7*x^4+7*x^3+4*x^2+5*x+1, 21*x^6+47*x^4+80*x^3+20*x^2+49*x+11)').toString()).toEqual('1+4*x+7*x^3');
21
- expect(nerdamer('gcd(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x,x)').toString()).toEqual('x');
22
- expect(nerdamer('gcd(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3), 3+x^3)').toString()).toEqual('3+x^3');
23
- expect(nerdamer('gcd(a, b, c)').toString()).toEqual('gcd(a,b,c)');
24
- expect(nerdamer('gcd(18,12, 6)').toString()).toEqual('6');
25
- expect(nerdamer('gcd(3, 5, 7)').toString()).toEqual('1');
26
- expect(nerdamer('gcd(1/2, 1/3, 1/4)').toString()).toEqual('1/12');
27
- expect(nerdamer('gcd(5%, 15%, 25%)').toString()).toEqual('1/20');
28
- expect(nerdamer('gcd(1/a, 1/b, 1/c)').toString()).toEqual('gcd(a^(-1),b^(-1),c^(-1))');
29
- expect(nerdamer('gcd(2^x, 6^x)').toString()).toEqual('2^x');
30
- expect(nerdamer('gcd(a, b, c, gcd(x, y, z, gcd(f,gcd(g,h))))').toString()).toEqual('gcd(a,b,c,x,y,z,f,g,h)');
31
- expect(nerdamer('gcd(2^x, 6^x)').toString()).toEqual('2^x');
32
- expect(nerdamer('gcd(a,a,b,b,gcd(c,c))').toString()).toEqual('1');
33
- expect(nerdamer('gcd(a,a)').toString()).toEqual('a');
34
- expect(nerdamer('gcd(a^b,a^c)').toString()).toEqual('a');
35
- expect(nerdamer('gcd(a^c,b^c)').toString()).toEqual('1');
36
- expect(nerdamer('gcd(a^a,a^a)').toString()).toEqual('a^a');
37
- });
38
-
39
- it('should perform lcm operations correctly', function () {
40
- expect(nerdamer('lcm(5*x^6+5*x^5+27*x^4+27*x^3+28*x^2+28*x, 5*x^3+7*x)').toString()).toEqual('27*x^3+27*x^4+28*x+28*x^2+5*x^5+5*x^6');
41
- expect(nerdamer('lcm(-20+16*i,-10+8*i)').toString()).toEqual('-10+8*i');
42
- expect(nerdamer('lcm(2*x^2+2*x+1,x+1)').toString()).toEqual('(1+2*x+2*x^2)*(1+x)');
43
- expect(nerdamer('lcm(x^2+2*x+1,x+1)').toString()).toEqual('1+2*x+x^2');
44
- expect(nerdamer('lcm(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, (2*x^2+8*x+5))').toString()).toEqual('15+15*x^7+24*x+24*x^8+6*x^2+6*x^9');
45
- expect(nerdamer('lcm(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3))').toString()).toEqual('12*x^3+12*x^4+3*x^5+4*x^6+4*x^7+x^8');
46
- expect(nerdamer('lcm(6*x^9+24*x^8+15*x^7+6*x^2+24*x+15, x^7+1)').toString()).toEqual('15+15*x^7+24*x+24*x^8+6*x^2+6*x^9');
47
- expect(nerdamer('lcm(1+x^2,2*x)').toString()).toEqual('2*(1+x^2)*x');
48
- expect(nerdamer('lcm(84*x^4+147*x^3+16*x^2+28*x, 44*x^5+77*x^4+16*x^3+28*x^2+12*x+21)').toString()).toEqual('(12*x+16*x^3+28*x^2+44*x^5+77*x^4+21)*(147*x^3+16*x^2+28*x+84*x^4)*(4*x+7)^(-1)');
49
- expect(nerdamer('lcm(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x)').toString()).toEqual('(1375*x^9+1430*x^8+1872*x^6+37550*x^7+47075*x^5+7150*x^12+7510*x^3+9360*x+9360*x^10)*(361*x^7+473*x^5+5*x^11+72*x^3+90*x^9+91*x)*(5*x^5+x)^(-1)');
50
- expect(nerdamer('lcm(7*x^4+7*x^3+4*x^2+5*x+1, 21*x^6+47*x^4+80*x^3+20*x^2+49*x+11)').toString()).toEqual('(1+4*x+7*x^3)^(-1)*(1+4*x^2+5*x+7*x^3+7*x^4)*(11+20*x^2+21*x^6+47*x^4+49*x+80*x^3)');
51
- expect(nerdamer('lcm(5*x^11+90*x^9+361*x^7+473*x^5+72*x^3+91*x, 7150*x^12+9360*x^10+1375*x^9+1430*x^8+37550*x^7+1872*x^6+47075*x^5+7510*x^3+9360*x,x)').toString()).toEqual('(1375*x^9+1430*x^8+1872*x^6+37550*x^7+47075*x^5+7150*x^12+7510*x^3+9360*x+9360*x^10)*(361*x^7+473*x^5+5*x^11+72*x^3+90*x^9+91*x)*(5*x^6+x^2)^(-1)*x');
52
- expect(nerdamer('lcm(x^8+4*x^7+4*x^6+3*x^5+12*x^4+12*x^3, (x^3+3), 3+x^3)').toString()).toEqual('(12*x^3+12*x^4+3*x^5+4*x^6+4*x^7+x^8)*(3+x^3)^2*(6*x^3+x^6+9)^(-1)');
53
- expect(nerdamer('lcm(a, b, c)').toString()).toEqual('a*b*c*gcd(a*b,a*c,b*c)^(-1)');
54
- expect(nerdamer('lcm(18,12, 6)').toString()).toEqual('36');
55
- expect(nerdamer('lcm(3, 5, 7)').toString()).toEqual('105');
56
- expect(nerdamer('lcm(1/2, 1/3, 1/4)').toString()).toEqual('1');
57
- expect(nerdamer('lcm(5%, 15%, 25%)').toString()).toEqual('3/4');
58
- expect(nerdamer('lcm(1/a, 1/b, 1/c)').toString()).toEqual('1');
59
- expect(nerdamer('lcm(2^x, 6^x)').toString()).toEqual('6^x');
60
- expect(nerdamer('lcm(a, b, c, gcd(x, y, z, gcd(f,gcd(g,h))))').toString()).toEqual('a*b*c*gcd(x,y,z,f,g,h)');
61
- expect(nerdamer('lcm(2^x, 6^x)').toString()).toEqual('6^x');
62
- expect(nerdamer('lcm(a,a,b,b,gcd(c,c))').toString()).toEqual('a^2*b^2*c*gcd(a^2*b^2,a^2*b*c,a^2*b*c,a*b^2*c,a*b^2*c)^(-1)');
63
- expect(nerdamer('lcm(a,a)').toString()).toEqual('a^2*gcd(a,a)^(-1)');
64
- expect(nerdamer('lcm(a^b,a^c)').toString()).toEqual('a^(-1+b+c)');
65
- expect(nerdamer('lcm(a^c,b^c)').toString()).toEqual('a^c*b^c');
66
- expect(nerdamer('lcm(a^a,a^a)').toString()).toEqual('a^a');
67
- });
68
-
69
- describe('isPoly', function () {
70
- it('should detect polynomials', function () {
71
- expect(nerdamer('51').symbol.isPoly(true)).toEqual(true);
72
- expect(nerdamer('x^2+1').symbol.isPoly(true)).toEqual(true);
73
- expect(nerdamer('51/x').symbol.isPoly(true)).toEqual(false);
74
- expect(nerdamer('x^2+1/x').symbol.isPoly(true)).toEqual(false);
75
- expect(nerdamer('y*x^2+1/x').symbol.isPoly(true)).toEqual(false);
76
- expect(nerdamer('y*x^2+x').symbol.isPoly(true)).toEqual(true);
77
- expect(nerdamer('7*y*x^2+z*x+4').symbol.isPoly(true)).toEqual(true);
78
- expect(nerdamer('7*y*x^2+z*x^-1+4').symbol.isPoly(true)).toEqual(false);
79
- expect(nerdamer('sqrt(5*x)+7').symbol.isPoly(true)).toEqual(false);
80
- expect(nerdamer('abs(5*x^3)-x+7').symbol.isPoly(true)).toEqual(false);
81
- expect(nerdamer('cos(x)^2+cos(x)+1').symbol.isPoly(true)).toEqual(false);
82
- expect(nerdamer('sqrt(97)x^2-sqrt(13)x+sqrt(14)x+sqrt(43)x^2+sqrt(3)*sqrt(101)').symbol.isPoly(true)).toEqual(true);
83
- expect(nerdamer('-5 sqrt(14)x-14x^2 sqrt(83)').symbol.isPoly(true)).toEqual(true);
84
- });
85
-
86
- it('should evaluate abs() directly', function () {
87
- // given
88
- var formula = 'abs(5*x^2)-x+11';
89
-
90
- // when
91
- var isPoly = nerdamer(formula).symbol.isPoly();
92
-
93
- // then
94
- expect(isPoly).toBeTruthy();
95
- });
96
- });
97
-
98
- it('should perform divisions', function () {
99
- expect(nerdamer('div(x^2*y^3+b*y^2+3*a*x^2*y+3*a*b, y^2+3*a)').toString()).toEqual('[b+x^2*y,0]');
100
- expect(nerdamer('div(x^2, x^3)').toString()).toEqual('[0,x^2]');
101
- expect(nerdamer('div(cos(x^2)^2+2*cos(x^2)+1, cos(x^2)+1)').toString()).toEqual('[1+cos(x^2),0]');
102
- expect(nerdamer('div(2*x^2+2*x+1, x+1)').toString()).toEqual('[2*x,1]');
103
- expect(nerdamer('div(7*x,2*x)').toString()).toEqual('[7/2,0]');
104
- expect(nerdamer('div(7*b*z^2+14*y*z+14*a*x^2*z-b*t*z-2*t*y-2*a*t*x^2, 7*z-t)').toString()).toEqual('[2*a*x^2+2*y+b*z,0]');
105
- expect(nerdamer('div(x^2+5, y-1)').toString()).toEqual('[0,5+x^2]');
106
- expect(nerdamer('div(4*a*x^2*y^2+4*a*y^2+b*x^2+a*x^2+b+a, x^2+1)').toString()).toEqual('[4*a*y^2+a+b,0]');
107
- expect(nerdamer('div(4*a*x^2*y^2+4*a*y^2+b*x^2+a*x^2+b+a+u^6+1, x^2+1)').toString()).toEqual('[4*a*y^2+a+b,1+u^6]');
108
- expect(nerdamer('div(15*x^9-25*x^7-35*x^6+6*x^5+3*x^4-10*x^3-19*x^2-7*x, 3*x^3-5*x-7)').toString()).toEqual('[2*x^2+5*x^6+x,0]');
109
- expect(nerdamer('div(sin(x)^2*tan(x)-4*cos(x)*tan(x)+cos(x)*sin(x)^2-4*cos(x)^2, sin(x)^2-4*cos(x)^2)').toString()).toEqual('[cos(x)+tan(x),-4*cos(x)*tan(x)-4*cos(x)^2+4*cos(x)^3+4*cos(x)^2*tan(x)]');
110
- expect(nerdamer('div(y^2*z-4*x*z+x*y^2-4*x^2, y^2-4*x^2)').toString()).toEqual('[x+z,-4*x*z-4*x^2+4*x^3+4*x^2*z]');
111
- expect(nerdamer('div(-5*y^2+16*a*y+5*x^4+14*a*x^2-3*a^2, 3*a-y+x^2)').toString()).toEqual('[-a+5*x^2+5*y,0]');
112
- expect(nerdamer('div(y^2+2*x*y+x^2,x+y)').toString()).toEqual('[x+y,0]');
113
- expect(nerdamer('div(x*y^2+x^2*y-y-x, x*y-1)').toString()).toEqual('[x+y,0]');
114
- expect(nerdamer('div(y^2*z-4*x*z+x*y^2-4*x^2+x^2, y^2-4*x^2)').toString()).toEqual('[x+z,-3*x^2+4*x^3-4*x*z+4*x^2*z]');
115
- expect(nerdamer('div(7*x^6*z-a*x*z+28*a*x^6*y^3-4*a^2*x*y^3+7*b*x^6-a*b*x, 4*y^3*a+z+b)').toString()).toEqual('[-a*x+7*x^6,0]');
116
- expect(nerdamer('div(x^2+5, cos(x)-1)').toString()).toEqual('[0,5+x^2]');
117
- expect(nerdamer('div((1+z), t*x+7)').toString()).toEqual('[0,1+z]');
118
- expect(nerdamer('div(-x^2*y-y+4*a*x^2+t+4*a+6*b, x^2+1)').toString()).toEqual('[-y+4*a,6*b+t]');
119
- expect(nerdamer('div(15*x^9-25*x^7-35*x^6+6*x^5+3*x^4-10*x^3-19*x^2-7*x+y, 3*x^3-5*x-7)').toString()).toEqual('[2*x^2+5*x^6+x,y]');
120
- expect(nerdamer('div(x^2+2*x+1+u, x+1)').toString()).toEqual('[1+x,u]');
121
- expect(nerdamer('div(y^3+x*y^2+x^2*y+x^3+x, x+y)').toString()).toEqual('[x^2+y^2,x]');
122
- expect(nerdamer('div(b*y*z+7*x^6*z-a*x*z-7*z+4*a*b*y^4+28*a*x^6*y^3-4*a^2*x*y^3-28*a*y^3+b^2*y+7*b*x^6-a*b*x-7*b, 4*y^3*a+z+b)').toString()).toEqual('[-7-a*x+7*x^6+b*y,0]');
123
- expect(nerdamer('div(b*y*z-a*x*z+4*a*b*y^4-4*a^2*x*y^3+b^2*y-a*b*x, 4*y^3*a+z+b)').toString()).toEqual('[-a*x+b*y,0]');
124
- expect(nerdamer('div(17*x^3*y+3*x^2*y+34*x+6, x^2*y+2)').toString()).toEqual('[17*x+3,0]');
125
- expect(nerdamer('div(b^2*y^2+2*a*b*y^2+a^2*y^2+2*b^2*x*y+4*a*b*x*y+2*a^2*x*y+b^2*x^2+2*a*b*x^2+a^2*x^2, 2*b*y^2+2*a*y^2+4*b*x*y+4*a*x*y+2*b*x^2+2*a*x^2)').toString()).toEqual('[(1/2)*a+(1/2)*b,0]');
126
- expect(nerdamer('div(2*a*b*x+2*a*b*y+a^2*x+a^2*y+b^2*x+b^2*y, x+y)').toString()).toEqual('[2*a*b+a^2+b^2,0]');
127
- expect(nerdamer('div((2x-1)(3x^2+5x-2)-7x-14,x^2+1)').toString()).toEqual('[6*x+7,-19-22*x]');
128
- expect(nerdamer('div(2(x+1)^5+1,x+2)').toString()).toEqual('[2+2*x^4+4*x+6*x^3+8*x^2,-1]');
129
- expect(nerdamer('divide(a*b^(-1)+b^(-1)*c,a+c)').toString()).toEqual('b^(-1)');
130
- expect(nerdamer('divide(-20+16*i,-10+8*i)').toString()).toEqual('2');
131
- });
132
- /** #3: "(a-b)^2 - (b-a)^2" not simplifying. */
133
- it('should simplify to 0', function () {
134
- // given
135
- var formula = '(a-b)^2-(b-a)^2';
136
-
137
- // when
138
- var result = nerdamer(formula, null, ['numer', 'expand']).toString();
139
-
140
- // then
141
- expect(result).toBe('0');
142
- });
143
- /** #40: Expected more simple solution for factoring. */
144
- it('should use simple factor result', function () {
145
- // given
146
- var formula = 'factor(x^2+x+1/4)';
147
-
148
- // when
149
- var result = nerdamer(formula).toString();
150
-
151
- // then
152
- expect(result).toBe('(1/4)*(1+2*x)^2');
153
- });
154
-
155
- /** #43: Formula not expanded. */
156
- it('should expand formula', function () {
157
- // given
158
- var formula = 'expand((x+5)(x-3)-x^2)';
159
-
160
- // when
161
- var result = nerdamer(formula).toString();
162
-
163
- // then
164
- expect(result).toBe('-15+2*x');
165
- });
166
- it('should factor correctly', function () {
167
- expect(nerdamer('factor(x^2+2*x+1)').toString()).toEqual('(1+x)^2');
168
- expect(nerdamer('factor(x^2-y^2)').toString()).toEqual('(-y+x)*(x+y)');
169
- expect(nerdamer('factor(a^2*x^2-b^2*y^2)').toString()).toEqual('(-b*y+a*x)*(a*x+b*y)');
170
- expect(nerdamer('factor(x^2-6*x+9-4*y^2)').toString()).toEqual('(-2*y-3+x)*(-3+2*y+x)');
171
- expect(nerdamer('factor(b^6+3*a^2*b^4+3*a^4*b^2+a^6)').toString()).toEqual('(a^2+b^2)^3');
172
- expect(nerdamer('factor(b^6+12*a^2*b^4+48*a^4*b^2+64*a^6)').toString()).toEqual('((9007199254740996/2251799813685249)*a^2+b^2)^3');
173
- expect(nerdamer('factor(c^6+3*b^2*c^4+3*a^2*c^4+3*b^4*c^2+6*a^2*b^2*c^2+3*a^4*c^2+b^6+3*a^2*b^4+3*a^4*b^2+a^6)').toString()).toEqual('(a^2+b^2+c^2)^3');
174
- expect(nerdamer('factor(x^4+25*x^3+234*x^2+972*x+1512)').toString()).toEqual('(6+x)^3*(7+x)');
175
- expect(nerdamer('factor(x^5+32*x^4+288*x^3-418*x^2-16577*x-55902)').toString()).toEqual('(-7+x)*(11+x)^3*(6+x)');
176
- expect(nerdamer('factor(x^2*y*z+x*z+t*x^2*y+t*x)').toString()).toEqual('(1+x*y)*(t+z)*x');
177
- expect(nerdamer('factor(x^2*y+x^2)').toString()).toEqual('(1+y)*x^2');
178
- expect(nerdamer('factor(sqrt(4*x^2*y+4*x^2))').toString()).toEqual('2*abs(x)*sqrt(1+y)');
179
- expect(nerdamer('factor(x^3-1/2x^2-13/2x-3)').toString()).toEqual('(1/2)*(-3+x)*(1+2*x)*(2+x)');
180
- expect(nerdamer('factor(x^16-1)').toString()).toEqual('(-1+x)*(1+x)*(1+x^2)*(1+x^4)*(1+x^8)');
181
- expect(nerdamer('factor(-1866240-311040*x^2-3265920*x+1120*x^8+150080*x^6+17610*x^7+2026080*x^4+2509920*x^3+30*x^9+738360*x^5)').toString()).toEqual('10*(-1+x)*(1+x)*(3*x+4)*(6+x)^6');
182
- expect(nerdamer('factor((7x^3+4x^2+x)/(12x^3+6x^2-2x))').toString()).toEqual('(1/2)*(-1+3*x+6*x^2)^(-1)*(1+4*x+7*x^2)');
183
- expect(nerdamer('factor((-2x-2x^2-2))').toString()).toEqual('-2*(1+x+x^2)');
184
- expect(nerdamer('factor(1331*x^3*y^3+216*z^6)').toString()).toEqual('(-66*x*y*z^2+121*x^2*y^2+36*z^4)*(11*x*y+6*z^2)');
185
- expect(nerdamer('factor(1331*x^3*y^3-216*z^6)').toString()).toEqual('(-6*z^2+11*x*y)*(121*x^2*y^2+36*z^4+66*x*y*z^2)');
186
- expect(nerdamer('factor(64a^3-27b^3)').toString()).toEqual('(-3*b+4*a)*(12*a*b+16*a^2+9*b^2)');
187
- expect(nerdamer('factor(64*x^3+125)').toString()).toEqual('(-20*x+16*x^2+25)*(4*x+5)');
188
- expect(nerdamer('factor((-5*K+32)^2)').toString()).toEqual('(-32+5*K)^2');
189
- expect(nerdamer('factor(100)').toString()).toEqual('2^2*5^2');
190
- expect(nerdamer('factor(100*x)').toString()).toEqual('100*x');
191
- expect(nerdamer('(2*y+p)^2').toString()).toEqual('(2*y+p)^2');
192
- });
193
- it('should not have any regression to factor', function() {
194
- //this test will absolutely break as factor improves enough to factor this expression. For now it just serves as a safeguard
195
- expect(nerdamer('factor(x^a+2x^(a-1)+1x^(a-2))').toString()).toEqual('2*x^(-1+a)+x^(-2+a)+x^a');
196
- });
197
- it('should correctly determine the polynomial degree', function () {
198
- expect(nerdamer('deg(x^2+2*x+x^5)').toString()).toEqual('5');
199
- expect(nerdamer('deg(x^2+2*x+x^x)').toString()).toEqual('max(2,x)');
200
- expect(nerdamer('deg(x^2+2*x+cos(x))').toString()).toEqual('2');
201
- expect(nerdamer('deg(x^a+x^b+x^c,x)').toString()).toEqual('max(a,b,c)');
202
- expect(nerdamer('deg(a*x^2+b*x+c,x)').toString()).toEqual('2');
203
- });
204
- it('should correctly peform partial fraction decomposition', function () {
205
- expect(nerdamer('partfrac((3*x+2)/(x^2+x), x)').toString()).toEqual('(1+x)^(-1)+2*x^(-1)');
206
- expect(nerdamer('partfrac((17*x-53)/(x^2-2*x-15), x)').toString()).toEqual('13*(3+x)^(-1)+4*(-5+x)^(-1)');
207
- expect(nerdamer('partfrac((x^3+2)/(x+1)^2,x)').toString()).toEqual('(1+x)^(-2)+3*(1+x)^(-1)-2+x');
208
- expect(nerdamer('partfrac(x/(x-1)^2, x)').toString()).toEqual('(-1+x)^(-1)+(-1+x)^(-2)');
209
- expect(nerdamer('partfrac((x^2+1)/(x*(x-1)^3), x)').toString()).toEqual('(-1+x)^(-1)+2*(-1+x)^(-3)-x^(-1)');
210
- expect(nerdamer('partfrac((17-53)/(x^2-2*x-15), x)').toString()).toEqual('(-9/2)*(-5+x)^(-1)+(9/2)*(3+x)^(-1)');
211
- expect(nerdamer('partfrac(1/(x^6-1),x)').toString()).toEqual('(-1/3)*(-x+x^2+1)^(-1)+(-1/3)*(1+x+x^2)^(-1)+(-1/6)*(1+x)^(-1)+(-1/6)*(1+x+x^2)^(-1)*x+(1/6)*(-1+x)^(-1)+(1/6)*(-x+x^2+1)^(-1)*x');
212
- expect(nerdamer('partfrac((3*x^2-3*x-8)/((x-5)*(x^2+x-4)),x)').toString()).toEqual('(-4+x+x^2)^(-1)*x+2*(-5+x)^(-1)');
213
- expect(nerdamer('partfrac(15*(9+s^2)^(-1)*cos(1)+5*(9+s^2)^(-1)*s*sin(1),s)').toString()).toEqual('(15*cos(1)+5*s*sin(1))*(9+s^2)^(-1)');
214
- });
215
- it('should prime factor correctly', function () {
216
- expect(nerdamer('pfactor(100!)').toString()).toEqual('(11^9)*(13^7)*(17^5)*(19^5)*(23^4)*(29^3)*(2^97)*(31^3)*(37^2)*(3^48)*(41^2)*(43^2)*(47^2)*(53)*(59)*(5^24)*(61)*(67)*(71)*(73)*(79)*(7^16)*(83)*(89)*(97)');
217
- expect(nerdamer('pfactor(100)').toString()).toEqual('(2^2)*(5^2)');
218
- expect(nerdamer('pfactor(8)').toString()).toEqual('(2^3)');
219
- expect(nerdamer('pfactor(999999999999)').toString()).toEqual('(101)*(11)*(13)*(37)*(3^3)*(7)*(9901)');
220
- expect(nerdamer('pfactor(1000000005721)').toString()).toEqual('(1000000005721)');
221
- expect(nerdamer('pfactor(1000000005721092)').toString()).toEqual('(131)*(212044106387)*(2^2)*(3^2)');
222
- expect(nerdamer('pfactor(-10000000114421840327308)').toString()).toEqual('(-2^2)*(480827)*(7)*(8345706745687)*(89)');
223
- expect(nerdamer('pfactor(-7877474663)').toString()).toEqual('(-97)*(180871)*(449)');
224
- expect(nerdamer('pfactor(15!+1)').toString()).toEqual('(46271341)*(479)*(59)');
225
- expect(nerdamer('pfactor(15!+11!)').toString()).toEqual('(11)*(181^2)*(2^8)*(3^4)*(5^2)*(7)');
226
- expect(nerdamer('pfactor(product(n!,n,1,10))').toString()).toEqual('(2^38)*(3^17)*(5^7)*(7^4)');
227
- expect(nerdamer('pfactor(4677271)').toString()).toEqual('(2089)*(2239)');
228
- });
229
- it('should get coeffs', function () {
230
- expect(nerdamer('coeffs(x^2+2*x+1, x)').toString()).toEqual('[1,2,1]');
231
- expect(nerdamer('coeffs(a*b*x^2+c*x+d, x)').toString()).toEqual('[d,c,a*b]');
232
- expect(nerdamer('coeffs(t*x, x)').toString()).toEqual('[0,t]');
233
- expect(nerdamer('coeffs(b*(t*x-5), x)').toString()).toEqual('[-5*b,b*t]');
234
- expect(nerdamer('coeffs(a*x^2+b*x+c+x, x)').toString()).toEqual('[c,1+b,a]');
235
- });
236
- it('should get all coeffs', function () {
237
- expect(nerdamer('coeffs(x+A+1,x)').toString()).toEqual('[1+A,1]');
238
- expect(nerdamer.coeffs('2x+i*x+5', 'x').toString()).toEqual('[5,2+i]');
239
- });
240
- it('should calculate the line function', function () {
241
- expect(nerdamer('line([1,2], [3,4])').toString()).toEqual('1+x');
242
- expect(nerdamer('line([a1,b1], [a2,b2], t)').toString()).toEqual('(-a1+a2)^(-1)*(-b1+b2)*t-(-a1+a2)^(-1)*(-b1+b2)*a1+b1');
243
- });
244
- it('should simplify correctly', function () {
245
- expect(nerdamer('simplify(sin(x)^2+cos(x)^2)').toString()).toEqual('1');
246
- expect(nerdamer('simplify(1/2*sin(x^2)^2+cos(x^2)^2)').toString()).toEqual('(1/4)*(3+cos(2*x^2))');
247
- expect(nerdamer('simplify(0.75*sin(x^2)^2+cos(x^2)^2)').toString()).toEqual('(1/8)*(7+cos(2*x^2))');
248
- expect(nerdamer('simplify(cos(x)^2+sin(x)^2+cos(x)-tan(x)-1+sin(x^2)^2+cos(x^2)^2)').toString()).toEqual('-tan(x)+1+cos(x)');
249
- expect(nerdamer('simplify((x^2+4*x-45)/(x^2+x-30))').toString()).toEqual('(6+x)^(-1)*(9+x)');
250
- expect(nerdamer('simplify(1/(x-1)+1/(1-x))').toString()).toEqual('0');
251
- expect(nerdamer('simplify((x-1)/(1-x))').toString()).toEqual('-1');
252
- expect(nerdamer('simplify((x^2+2*x+1)/(x+1))').toString()).toEqual('1+x');
253
- expect(nerdamer('simplify((- x + x^2 + 1)/(x - x^2 - 1))').toString()).toEqual('-1');
254
- expect(nerdamer('simplify(n!/(n+1)!)').toString()).toEqual('(1+n)^(-1)');
255
- expect(nerdamer('simplify((17/2)*(-10+8*i)^(-1)-5*(-10+8*i)^(-1)*i)').toString()).toEqual('(-9/82)*i-125/164');
256
- expect(nerdamer('simplify((-2*i+7)^(-1)*(3*i+4))').toString()).toEqual('(29/53)*i+22/53');
257
- expect(nerdamer('simplify(((17/2)*(-5*K+32)^(-1)*K^2+(5/2)*K-125*(-5*K+32)^(-1)*K-16+400*(-5*K+32)^(-1))*(-17*(-5*K+32)^(-1)*K+80*(-5*K+32)^(-1))^(-1))').toString()).toEqual('(-35*K+4*K^2+112)*(-80+17*K)^(-1)');
258
- expect(nerdamer('simplify(((a+b)^2)/c)').toString()).toEqual('(a+b)^2*c^(-1)');
259
- expect(nerdamer('simplify(-(-5*x - 9 + 2*y))').toString()).toEqual('-2*y+5*x+9');
260
- expect(nerdamer('simplify(a/b+b/a)').toString()).toEqual('(a*b)^(-1)*(a^2+b^2)');
261
- expect(nerdamer('simplify(((2*e^t)/(e^t))+(1/(e^t)))').toString()).toEqual('(1+2*e^t)*e^(-t)');
262
- expect(nerdamer('simplify((-3/2)x+(1/3)y+2+z)').toString()).toEqual('(1/6)*(-9*x+12+2*y+6*z)');
263
- });
264
- it('should also simplify', function() {
265
- //expect(nerdamer('6/sqrt(3)')).toEqual();
266
- });
267
- it('should calculate nth roots correctly', function() {
268
- expect(nerdamer('roots((-1)^(1/5))').evaluate().text()).toEqual('[0.5877852522924731*i+0.809016994374947,-0.309016994374947+0.9510565162951536*i,-1,-0.309016994374948-0.9510565162951536*i,-0.5877852522924734*i+0.809016994374947]');
269
- expect(nerdamer('roots((2)^(1/3))').evaluate().text()).toEqual('[1.122462048309381,-1.122462048309381]');
270
- });
271
- // As mentioned by @Happypig375 in issue #219
272
- it('should also factor correctly', function() {
273
- expect(nerdamer('factor((x^2+4x+4)-y^2)').toString()).toEqual('(-y+2+x)*(2+x+y)');
274
- expect(nerdamer('factor(81-(16a^2-56a+49))').toString()).toEqual('-8*(-4+a)*(1+2*a)');
275
- expect(nerdamer('factor((9x^2-12x+4)-25)').toString()).toEqual('3*(-7+3*x)*(1+x)');
276
- expect(nerdamer('factor((x^2+4x+4)+x*y+2y)').toString()).toEqual('(2+x)*(2+x+y)');
277
- expect(nerdamer('factor((4x^2+24x+36)-14x*y-42y)').toString()).toEqual('2*(-7*y+2*x+6)*(3+x)');
278
- expect(nerdamer('factor(35a*b-15b+(49a^2-42a+9))').toString()).toEqual('(-3+5*b+7*a)*(-3+7*a)');
279
- expect(nerdamer('factor(1-6a^2+9a^4)').toString()).toEqual('(-1+3*a^2)^2');
280
- expect(nerdamer('factor(1-6a^2+9a^4-49b^2)').toString()).toEqual('(-1+3*a^2+7*b)*(-1-7*b+3*a^2)');
281
- });
282
- it('should complete the square', function() {
283
- expect(nerdamer('sqcomp(a*x^2+b*x-11*c, x)').toString()).toEqual('((1/2)*abs(b)*sqrt(a)^(-1)+sqrt(a)*x)^2+(-1/4)*(abs(b)*sqrt(a)^(-1))^2-11*c');
284
- expect(nerdamer('sqcomp(9*x^2-18*x+17)').toString()).toEqual('(-3+3*x)^2+8');
285
- expect(nerdamer('sqcomp(s^2+s+1)').toString()).toEqual('(1/2+s)^2+3/4');
286
- });
287
- });