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
@@ -0,0 +1,461 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assume = void 0;
4
+ exports.equal = equal;
5
+ exports.gt = gt;
6
+ exports.gte = gte;
7
+ exports.lt = lt;
8
+ exports.lte = lte;
9
+ const errors_1 = require("../../../errors");
10
+ const rationalNormalization_1 = require("../../../functions/rationalNormalization");
11
+ const assume_1 = require("../../assumption/assume");
12
+ const Expression_1 = require("../../expression/Expression");
13
+ const multiply_1 = require("./multiply");
14
+ const subtract_1 = require("./subtract");
15
+ var assume_2 = require("../../assumption/assume");
16
+ Object.defineProperty(exports, "assume", { enumerable: true, get: function () { return assume_2.assume; } });
17
+ function getAffineForm(x) {
18
+ let retval = undefined;
19
+ if (!x.isComplex() && x.getPower().isOne()) {
20
+ if (x.isVAR()) {
21
+ if ((0, assume_1.getAssumptionFor)(x.value)) {
22
+ retval = {
23
+ coefficient: Expression_1.Expression.fromRational(x.getMultiplier()),
24
+ constant: Expression_1.Expression.Number(0),
25
+ symbol: x.value,
26
+ };
27
+ }
28
+ }
29
+ else if (x.isSum()) {
30
+ const terms = x.elementsArray();
31
+ let symbol = undefined;
32
+ let valid = true;
33
+ for (const term of terms) {
34
+ if (term.isNUM()) {
35
+ continue;
36
+ }
37
+ if (!term.isVAR() || !term.getPower().isOne()) {
38
+ valid = false;
39
+ break;
40
+ }
41
+ if (symbol === undefined) {
42
+ symbol = term.value;
43
+ if (!(0, assume_1.getAssumptionFor)(symbol)) {
44
+ valid = false;
45
+ break;
46
+ }
47
+ }
48
+ else if (symbol !== term.value) {
49
+ valid = false;
50
+ break;
51
+ }
52
+ }
53
+ if (valid && symbol !== undefined) {
54
+ let coefficient = Expression_1.Expression.Number(0);
55
+ let constant = Expression_1.Expression.Number(0);
56
+ for (const term of terms) {
57
+ if (term.isNUM()) {
58
+ constant = constant.plus(term);
59
+ }
60
+ else {
61
+ coefficient = coefficient.plus(Expression_1.Expression.fromRational(term.getMultiplier()));
62
+ }
63
+ }
64
+ if (!coefficient.isZero()) {
65
+ retval = { coefficient, constant, symbol };
66
+ }
67
+ }
68
+ }
69
+ }
70
+ return retval;
71
+ }
72
+ function compareAffineToValue(x, value, relation) {
73
+ const affine = getAffineForm(x);
74
+ let retval = undefined;
75
+ if (affine) {
76
+ const assumption = (0, assume_1.getAssumptionFor)(affine.symbol);
77
+ if (assumption) {
78
+ const bound = value.minus(affine.constant).div(affine.coefficient);
79
+ let resolvedRelation = relation;
80
+ if (affine.coefficient.getMultiplier().isNegative()) {
81
+ if (relation === 'gt') {
82
+ resolvedRelation = 'lt';
83
+ }
84
+ else if (relation === 'gte') {
85
+ resolvedRelation = 'lte';
86
+ }
87
+ else if (relation === 'lt') {
88
+ resolvedRelation = 'gt';
89
+ }
90
+ else {
91
+ resolvedRelation = 'gte';
92
+ }
93
+ }
94
+ retval = assumption[resolvedRelation](bound);
95
+ }
96
+ }
97
+ return retval;
98
+ }
99
+ function compareAffineExpressions(a, b, relation) {
100
+ let retval = undefined;
101
+ const aCandidate = a.isSum() || (a.isVAR() && !a.isPlainVariable());
102
+ const bCandidate = b.isSum() || (b.isVAR() && !b.isPlainVariable());
103
+ if (aCandidate && b.isNUM()) {
104
+ retval = compareAffineToValue(a, b, relation);
105
+ }
106
+ else if (a.isNUM() && bCandidate) {
107
+ let reversedRelation;
108
+ if (relation === 'gt') {
109
+ reversedRelation = 'lt';
110
+ }
111
+ else if (relation === 'gte') {
112
+ reversedRelation = 'lte';
113
+ }
114
+ else if (relation === 'lt') {
115
+ reversedRelation = 'gt';
116
+ }
117
+ else {
118
+ reversedRelation = 'gte';
119
+ }
120
+ retval = compareAffineToValue(b, a, reversedRelation);
121
+ }
122
+ return retval;
123
+ }
124
+ function getAffineSign(x) {
125
+ const affine = getAffineForm(x);
126
+ let retval = undefined;
127
+ if (affine) {
128
+ const assumption = (0, assume_1.getAssumptionFor)(affine.symbol);
129
+ if (assumption) {
130
+ const bound = affine.constant.neg().div(affine.coefficient);
131
+ const coefficientIsNegative = affine.coefficient.getMultiplier().isNegative();
132
+ const positive = coefficientIsNegative ? assumption.lt(bound) : assumption.gt(bound);
133
+ const negative = coefficientIsNegative ? assumption.gt(bound) : assumption.lt(bound);
134
+ if (positive === true) {
135
+ retval = 1;
136
+ }
137
+ else if (negative === true) {
138
+ retval = -1;
139
+ }
140
+ else if (assumption.eq(bound) === true) {
141
+ retval = 0;
142
+ }
143
+ }
144
+ }
145
+ return retval;
146
+ }
147
+ /**
148
+ * Returns a sign only when it can be proved from numeric values, assumptions, or
149
+ * simple multiplicative structure. Unknown symbolic signs stay unknown.
150
+ */
151
+ function getProvenSign(x) {
152
+ let retval = undefined;
153
+ if (!x.isComplex()) {
154
+ if (x.isNUM()) {
155
+ retval = x.getMultiplier().sign();
156
+ }
157
+ else {
158
+ const multiplierSign = x.getMultiplier().sign();
159
+ const exponent = x.getPower();
160
+ if (multiplierSign === 0) {
161
+ retval = 0;
162
+ }
163
+ else if (!exponent.isOne() && exponent.isNUM()) {
164
+ // Powers are stored directly on many node types, not only EXP nodes.
165
+ // Use the common base-extraction API so x^-1, (x*y)^2, and explicit
166
+ // EXP nodes all follow the same sign reasoning.
167
+ const base = x.toLinearAndUnitMultiplier();
168
+ const baseSign = getProvenSign(base);
169
+ let poweredSign = undefined;
170
+ if (baseSign === 1) {
171
+ poweredSign = 1;
172
+ }
173
+ else if (baseSign === -1 && exponent.isInteger()) {
174
+ poweredSign = exponent.isEven() ? 1 : -1;
175
+ }
176
+ else if (baseSign === 0 && exponent.getMultiplier().gt('0')) {
177
+ poweredSign = 0;
178
+ }
179
+ if (poweredSign !== undefined) {
180
+ retval = (multiplierSign * poweredSign);
181
+ }
182
+ }
183
+ else if (x.isProduct()) {
184
+ let productSign = multiplierSign;
185
+ let allKnown = true;
186
+ for (const element of x.elementsArray()) {
187
+ const elementSign = getProvenSign(element);
188
+ if (elementSign === undefined) {
189
+ allKnown = false;
190
+ break;
191
+ }
192
+ productSign *= elementSign;
193
+ if (productSign === 0) {
194
+ break;
195
+ }
196
+ }
197
+ if (allKnown) {
198
+ retval = productSign;
199
+ }
200
+ }
201
+ if (retval === undefined && exponent.isOne()) {
202
+ const base = x.toLinearAndUnitMultiplier();
203
+ const assumption = (0, assume_1.getAssumptionFor)(base);
204
+ if (assumption) {
205
+ const zero = Expression_1.Expression.Number(0);
206
+ let assumedSign = undefined;
207
+ if (assumption.gt(zero) === true) {
208
+ assumedSign = 1;
209
+ }
210
+ else if (assumption.lt(zero) === true) {
211
+ assumedSign = -1;
212
+ }
213
+ else if (assumption.eq(zero) === true) {
214
+ assumedSign = 0;
215
+ }
216
+ if (assumedSign !== undefined) {
217
+ retval = (multiplierSign * assumedSign);
218
+ }
219
+ }
220
+ else if (x.isSum() && (0, assume_1.hasAssumptions)()) {
221
+ retval = getAffineSign(x);
222
+ }
223
+ }
224
+ }
225
+ }
226
+ return retval;
227
+ }
228
+ /**
229
+ * Checks whether Nerdamer can establish that `a` and `b` are equal.
230
+ *
231
+ * @remarks
232
+ * The public expression comparison remains boolean for compatibility. Assumptions
233
+ * supply a result when they can prove or disprove the relation; an unknown assumption
234
+ * result falls through to the ordinary symbolic comparison. If neither path can prove
235
+ * equality, this function returns `false`. Use the corresponding `Assumption` relation
236
+ * directly when a caller needs to distinguish a disproved relation from an unknown one.
237
+ */
238
+ function equal(a, b) {
239
+ a = Expression_1.Expression.create(a);
240
+ b = Expression_1.Expression.create(b);
241
+ const sameVariable = a.isPlainVariable() && b.isPlainVariable() && a.value === b.value;
242
+ const x = (0, assume_1.getAssumptionFor)(a);
243
+ const y = (0, assume_1.getAssumptionFor)(b);
244
+ let assumptionResult = undefined;
245
+ let retval;
246
+ // An assumption describes the admissible values of a variable; it does not erase
247
+ // the identity of the variable itself. x == x remains true even when x ranges over
248
+ // more than one value.
249
+ if (sameVariable) {
250
+ retval = true;
251
+ }
252
+ else {
253
+ if (x && y) {
254
+ assumptionResult = x.eq(y);
255
+ }
256
+ else if (x) {
257
+ assumptionResult = x.eq(b);
258
+ }
259
+ else if (y) {
260
+ assumptionResult = y.eq(a);
261
+ }
262
+ if (assumptionResult !== undefined) {
263
+ retval = assumptionResult;
264
+ }
265
+ else {
266
+ let result;
267
+ // Try the cheap comparison first. If they're NUM just extract the difference.
268
+ if (a.isNUM() && b.isNUM()) {
269
+ result = (0, subtract_1.subtract)(a, b);
270
+ }
271
+ else {
272
+ // Canonicalize numeric radicals so equivalent exact forms compare consistently.
273
+ a = (0, multiply_1.canonicalizeRadicals)(a);
274
+ b = (0, multiply_1.canonicalizeRadicals)(b);
275
+ result = (0, rationalNormalization_1.toCommonDenominator)((0, subtract_1.subtract)(a, b).expand()).expand();
276
+ }
277
+ retval = result.isNUM() && result.getMultiplier().eq('0');
278
+ }
279
+ }
280
+ return retval;
281
+ }
282
+ /** Checks whether Nerdamer can establish that `a` is strictly greater than `b`. */
283
+ function gt(a, b) {
284
+ a = Expression_1.Expression.create(a);
285
+ b = Expression_1.Expression.create(b);
286
+ if (a.isComplex() || b.isComplex()) {
287
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
288
+ }
289
+ const x = (0, assume_1.getAssumptionFor)(a);
290
+ const y = (0, assume_1.getAssumptionFor)(b);
291
+ let assumptionResult = undefined;
292
+ let retval;
293
+ if (x && y) {
294
+ assumptionResult = x.gt(y);
295
+ }
296
+ else if (x) {
297
+ assumptionResult = x.gt(b);
298
+ }
299
+ else if (y) {
300
+ assumptionResult = y.lt(a);
301
+ }
302
+ if (assumptionResult !== undefined) {
303
+ retval = assumptionResult;
304
+ }
305
+ else {
306
+ let sign = undefined;
307
+ if (b.isZero()) {
308
+ sign = getProvenSign(a);
309
+ }
310
+ else if (a.isZero()) {
311
+ const rightSign = getProvenSign(b);
312
+ if (rightSign !== undefined) {
313
+ sign = -rightSign;
314
+ }
315
+ }
316
+ if (sign !== undefined) {
317
+ retval = sign > 0;
318
+ }
319
+ else {
320
+ const affineResult = (0, assume_1.hasAssumptions)() && !(a.isZero() || b.isZero())
321
+ ? compareAffineExpressions(a, b, 'gt')
322
+ : undefined;
323
+ if (affineResult !== undefined) {
324
+ retval = affineResult;
325
+ }
326
+ else {
327
+ // E.g. 9 > 6 is decided from the sign of 9 - 6.
328
+ const result = (0, subtract_1.subtract)(a.evaluate(), b.evaluate()).expand();
329
+ retval = result.isNUM() && result.getMultiplier().gt('0');
330
+ }
331
+ }
332
+ }
333
+ return retval;
334
+ }
335
+ /** Checks whether Nerdamer can establish that `a` is greater than or equal to `b`. */
336
+ function gte(a, b) {
337
+ a = Expression_1.Expression.create(a);
338
+ b = Expression_1.Expression.create(b);
339
+ if (a.isComplex() || b.isComplex()) {
340
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
341
+ }
342
+ const sameVariable = a.isPlainVariable() && b.isPlainVariable() && a.value === b.value;
343
+ const x = (0, assume_1.getAssumptionFor)(a);
344
+ const y = (0, assume_1.getAssumptionFor)(b);
345
+ let assumptionResult = undefined;
346
+ let retval;
347
+ if (sameVariable) {
348
+ retval = true;
349
+ }
350
+ else {
351
+ if (x && y) {
352
+ assumptionResult = x.gte(y);
353
+ }
354
+ else if (x) {
355
+ assumptionResult = x.gte(b);
356
+ }
357
+ else if (y) {
358
+ assumptionResult = y.lte(a);
359
+ }
360
+ if (assumptionResult !== undefined) {
361
+ retval = assumptionResult;
362
+ }
363
+ else {
364
+ const affineResult = (0, assume_1.hasAssumptions)()
365
+ ? compareAffineExpressions(a, b, 'gte')
366
+ : undefined;
367
+ retval = affineResult === undefined ? gt(a, b) || equal(a, b) : affineResult;
368
+ }
369
+ }
370
+ return retval;
371
+ }
372
+ /** Checks whether Nerdamer can establish that `a` is strictly less than `b`. */
373
+ function lt(a, b) {
374
+ a = Expression_1.Expression.create(a);
375
+ b = Expression_1.Expression.create(b);
376
+ if (a.isComplex() || b.isComplex()) {
377
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
378
+ }
379
+ const x = (0, assume_1.getAssumptionFor)(a);
380
+ const y = (0, assume_1.getAssumptionFor)(b);
381
+ let assumptionResult = undefined;
382
+ let retval;
383
+ if (x && y) {
384
+ assumptionResult = x.lt(y);
385
+ }
386
+ else if (x) {
387
+ assumptionResult = x.lt(b);
388
+ }
389
+ else if (y) {
390
+ assumptionResult = y.gt(a);
391
+ }
392
+ if (assumptionResult !== undefined) {
393
+ retval = assumptionResult;
394
+ }
395
+ else {
396
+ let sign = undefined;
397
+ if (b.isZero()) {
398
+ sign = getProvenSign(a);
399
+ }
400
+ else if (a.isZero()) {
401
+ const rightSign = getProvenSign(b);
402
+ if (rightSign !== undefined) {
403
+ sign = -rightSign;
404
+ }
405
+ }
406
+ if (sign !== undefined) {
407
+ retval = sign < 0;
408
+ }
409
+ else {
410
+ const affineResult = (0, assume_1.hasAssumptions)() && !(a.isZero() || b.isZero())
411
+ ? compareAffineExpressions(a, b, 'lt')
412
+ : undefined;
413
+ if (affineResult !== undefined) {
414
+ retval = affineResult;
415
+ }
416
+ else {
417
+ // E.g. 6 < 9 is decided from the sign of 6 - 9.
418
+ const result = (0, subtract_1.subtract)(a.evaluate(), b.evaluate()).expand();
419
+ retval = result.isNUM() && result.getMultiplier().lt('0');
420
+ }
421
+ }
422
+ }
423
+ return retval;
424
+ }
425
+ /** Checks whether Nerdamer can establish that `a` is less than or equal to `b`. */
426
+ function lte(a, b) {
427
+ a = Expression_1.Expression.create(a);
428
+ b = Expression_1.Expression.create(b);
429
+ if (a.isComplex() || b.isComplex()) {
430
+ throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
431
+ }
432
+ const sameVariable = a.isPlainVariable() && b.isPlainVariable() && a.value === b.value;
433
+ const x = (0, assume_1.getAssumptionFor)(a);
434
+ const y = (0, assume_1.getAssumptionFor)(b);
435
+ let assumptionResult = undefined;
436
+ let retval;
437
+ if (sameVariable) {
438
+ retval = true;
439
+ }
440
+ else {
441
+ if (x && y) {
442
+ assumptionResult = x.lte(y);
443
+ }
444
+ else if (x) {
445
+ assumptionResult = x.lte(b);
446
+ }
447
+ else if (y) {
448
+ assumptionResult = y.gte(a);
449
+ }
450
+ if (assumptionResult !== undefined) {
451
+ retval = assumptionResult;
452
+ }
453
+ else {
454
+ const affineResult = (0, assume_1.hasAssumptions)()
455
+ ? compareAffineExpressions(a, b, 'lte')
456
+ : undefined;
457
+ retval = affineResult === undefined ? lt(a, b) || equal(a, b) : affineResult;
458
+ }
459
+ }
460
+ return retval;
461
+ }
@@ -0,0 +1,2 @@
1
+ import { Expression } from '../../expression/Expression';
2
+ export declare function divide(a: Expression, b: Expression): Expression;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.divide = divide;
4
+ const errors_1 = require("../../../errors");
5
+ const Settings_1 = require("../../../Settings");
6
+ const Expression_1 = require("../../expression/Expression");
7
+ const shortcuts_1 = require("../../expression/shortcuts");
8
+ const multiply_1 = require("./multiply");
9
+ const power_1 = require("./power");
10
+ function divide(a, b) {
11
+ let retval;
12
+ if (Settings_1.Settings.DEFER_SIMPLIFICATION) {
13
+ // Explicitly add a power to a NUM so it can be inverted.
14
+ if (b.isNUM()) {
15
+ b.power = (0, shortcuts_1.one)();
16
+ }
17
+ retval = div(a, b);
18
+ retval.deferred = true;
19
+ }
20
+ else {
21
+ // Disallow division by zero
22
+ if (b.isZero()) {
23
+ throw new errors_1.DivisionByZeroError((0, errors_1.message)('divisionByZero'));
24
+ }
25
+ if (a.isZero() && !b.isInf()) {
26
+ retval = Expression_1.Expression.Number('0');
27
+ }
28
+ else if (a.isNUM() && b.isNUM()) {
29
+ retval = Expression_1.Expression.fromRational(a.getMultiplier().div(b.getMultiplier()));
30
+ }
31
+ else if (b.isNUM()) {
32
+ retval = a.copy(); // create a new copy
33
+ const multiplier = a.getMultiplier().div(b.getMultiplier());
34
+ retval.multiplier = multiplier;
35
+ }
36
+ else if (a.isComplex() || b.isComplex()) {
37
+ const realA = a.realPart();
38
+ const realB = b.realPart();
39
+ const imA = a.imagPart();
40
+ const imB = b.imagPart();
41
+ const den = realB.sq().plus(imB.sq());
42
+ const re = realA.times(realB).plus(imA.times(imB)).div(den);
43
+ const im = imA.times(realB).minus(realA.times(imB)).div(den).times(Expression_1.Expression.Img());
44
+ return re.plus(im);
45
+ }
46
+ else if (b.isInf() && !a.isZero()) {
47
+ if (!b.getMultiplier().isNegative() && !a.isInf()) {
48
+ retval = Expression_1.Expression.Number('0');
49
+ }
50
+ }
51
+ else {
52
+ retval = div(a, b);
53
+ // Only rationalize if the result is a simple numeric radical
54
+ // e.g. 1/sqrt(2) → sqrt(2)/2
55
+ // Don't rationalize complex products or higher roots where it makes things worse
56
+ if (retval.isEXP() && retval.hasRadical()) {
57
+ retval = (0, power_1.rationalizeRadical)(retval);
58
+ }
59
+ }
60
+ if (!retval) {
61
+ throw new errors_1.UndefinedError((0, errors_1.message)('undefinedDivision', { type: `${a}/${b}` }));
62
+ }
63
+ }
64
+ return retval;
65
+ }
66
+ function div(a, b) {
67
+ b = b.copy();
68
+ // Negate and send it to multiplier
69
+ b.power = b.getPower().neg();
70
+ b.multiplier = b.getMultiplier().invert();
71
+ return (0, multiply_1.multiply)(a, b);
72
+ }
@@ -0,0 +1,46 @@
1
+ import { Equation } from '../../equation/Equation';
2
+ import { Matrix } from '../../matrix/Matrix';
3
+ import { Vector } from '../../vector/Vector';
4
+ import { comma } from './comma';
5
+ import type { ParserEntity } from '../../../types';
6
+ import type { Operation, PreFixFunction, PostFixFunction, EquationConstructorCall, CommaOperation, DeferredFunctionArgument, DeferredOperation } from '../types';
7
+ /**
8
+ * The wrapper used to call functions within the parser.
9
+ *
10
+ * @param functionName The name of the function being called
11
+ * @param args
12
+ * @returns
13
+ */
14
+ export declare function callFunction(functionName: string, args: (ParserEntity | DeferredFunctionArgument)[]): ParserEntity;
15
+ /**
16
+ * Combines all base operations into one object for parser.
17
+ */
18
+ export declare const _: {
19
+ [functionName: string]: Operation | DeferredOperation | PreFixFunction | PostFixFunction | EquationConstructorCall | CommaOperation;
20
+ };
21
+ /**
22
+ * Applies a scalar function over a copied Vector or Matrix while preserving its shape.
23
+ * Matrix cells must remain Expressions because Matrix does not permit aggregate elements.
24
+ */
25
+ export declare function distribute(fn: (v: ParserEntity, i: number, j?: number) => ParserEntity, structure: Vector | Matrix): Vector | Matrix;
26
+ /**
27
+ * Set's one expression equal to the other
28
+ * @param a
29
+ * @param b
30
+ * @returns
31
+ */
32
+ export declare function setEqual(a: ParserEntity, b: ParserEntity): Equation;
33
+ /**
34
+ * Registers a symbolic function from a deferred declaration body.
35
+ *
36
+ * The parser preserves the declaration as the parameter expressions followed by
37
+ * the function name. Each part of the signature must remain a plain variable. The
38
+ * right-hand callback owns compiled parser RPN and is executed only when the registered
39
+ * function is called.
40
+ *
41
+ * @param a - Deferred function signature.
42
+ * @param body - Deferred symbolic function body.
43
+ * @returns The registered function signature.
44
+ */
45
+ export declare function functionAssign(a: ParserEntity, body: DeferredFunctionArgument): ParserEntity;
46
+ export declare function route(a: ParserEntity, b: ParserEntity, operation: string): ParserEntity | ReturnType<typeof comma>;