mathjs 9.5.2 → 10.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. package/HISTORY.md +43 -1
  2. package/NOTICE +1 -1
  3. package/README.md +10 -2
  4. package/bin/cli.js +1 -1
  5. package/docs/expressions/syntax.md +1 -1
  6. package/docs/reference/constants.md +1 -1
  7. package/docs/reference/functions/invmod.md +41 -0
  8. package/docs/reference/functions.md +1 -0
  9. package/examples/expressions.js +1 -1
  10. package/lib/browser/math.js +7 -7
  11. package/lib/browser/math.js.map +1 -1
  12. package/lib/cjs/constants.js +1 -1
  13. package/lib/cjs/core/function/config.js +1 -1
  14. package/lib/cjs/core/function/import.js +2 -1
  15. package/lib/cjs/entry/dependenciesAny/dependenciesIntersect.generated.js +6 -0
  16. package/lib/cjs/entry/dependenciesAny/dependenciesInvmod.generated.js +41 -0
  17. package/lib/cjs/entry/dependenciesAny/dependenciesRationalize.generated.js +15 -0
  18. package/lib/cjs/entry/dependenciesAny/dependenciesSimplify.generated.js +15 -0
  19. package/lib/cjs/entry/dependenciesAny.generated.js +1002 -994
  20. package/lib/cjs/entry/dependenciesNumber/dependenciesRationalize.generated.js +15 -0
  21. package/lib/cjs/entry/dependenciesNumber/dependenciesSimplify.generated.js +15 -0
  22. package/lib/cjs/entry/dependenciesNumber.generated.js +581 -581
  23. package/lib/cjs/entry/impureFunctionsAny.generated.js +325 -313
  24. package/lib/cjs/entry/impureFunctionsNumber.generated.js +233 -222
  25. package/lib/cjs/entry/mainAny.js +8 -8
  26. package/lib/cjs/entry/mainNumber.js +8 -8
  27. package/lib/cjs/entry/pureFunctionsAny.generated.js +1111 -1097
  28. package/lib/cjs/entry/pureFunctionsNumber.generated.js +375 -375
  29. package/lib/cjs/entry/typeChecks.js +12 -12
  30. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -1
  31. package/lib/cjs/expression/embeddedDocs/function/arithmetic/invmod.js +15 -0
  32. package/lib/cjs/expression/embeddedDocs/function/matrix/forEach.js +1 -1
  33. package/lib/cjs/expression/operators.js +1 -1
  34. package/lib/cjs/factoriesAny.js +668 -660
  35. package/lib/cjs/factoriesNumber.js +268 -237
  36. package/lib/cjs/function/algebra/rationalize.js +18 -4
  37. package/lib/cjs/function/algebra/simplify/simplifyConstant.js +223 -29
  38. package/lib/cjs/function/algebra/simplify/simplifyCore.js +34 -6
  39. package/lib/cjs/function/algebra/simplify.js +73 -22
  40. package/lib/cjs/function/arithmetic/invmod.js +73 -0
  41. package/lib/cjs/function/arithmetic/round.js +2 -2
  42. package/lib/cjs/function/geometry/intersect.js +12 -13
  43. package/lib/cjs/function/probability/gamma.js +28 -30
  44. package/lib/cjs/header.js +3 -3
  45. package/lib/cjs/plain/bignumber/arithmetic.js +2 -2
  46. package/lib/cjs/plain/number/arithmetic.js +10 -10
  47. package/lib/cjs/plain/number/constants.js +1 -1
  48. package/lib/cjs/plain/number/logical.js +1 -1
  49. package/lib/cjs/plain/number/probability.js +2 -1
  50. package/lib/cjs/plain/number/trigonometry.js +1 -1
  51. package/lib/cjs/plain/number/utils.js +1 -1
  52. package/lib/cjs/type/matrix/SparseMatrix.js +19 -15
  53. package/lib/cjs/type/unit/Unit.js +2 -2
  54. package/lib/cjs/type/unit/physicalConstants.js +1 -1
  55. package/lib/cjs/utils/array.js +14 -14
  56. package/lib/cjs/utils/bignumber/bitwise.js +1 -1
  57. package/lib/cjs/utils/customs.js +5 -5
  58. package/lib/cjs/utils/factory.js +3 -3
  59. package/lib/cjs/utils/function.js +1 -1
  60. package/lib/cjs/utils/is.js +23 -23
  61. package/lib/cjs/utils/latex.js +2 -1
  62. package/lib/cjs/utils/map.js +3 -3
  63. package/lib/cjs/utils/noop.js +1 -1
  64. package/lib/cjs/utils/number.js +11 -7
  65. package/lib/cjs/utils/object.js +8 -8
  66. package/lib/cjs/utils/snapshot.js +3 -3
  67. package/lib/cjs/utils/string.js +2 -2
  68. package/lib/cjs/version.js +1 -1
  69. package/lib/esm/core/function/import.js +2 -1
  70. package/lib/esm/entry/dependenciesAny/dependenciesIntersect.generated.js +4 -0
  71. package/lib/esm/entry/dependenciesAny/dependenciesInvmod.generated.js +24 -0
  72. package/lib/esm/entry/dependenciesAny/dependenciesRationalize.generated.js +10 -0
  73. package/lib/esm/entry/dependenciesAny/dependenciesSimplify.generated.js +10 -0
  74. package/lib/esm/entry/dependenciesAny.generated.js +271 -270
  75. package/lib/esm/entry/dependenciesNumber/dependenciesRationalize.generated.js +10 -0
  76. package/lib/esm/entry/dependenciesNumber/dependenciesSimplify.generated.js +10 -0
  77. package/lib/esm/entry/dependenciesNumber.generated.js +163 -163
  78. package/lib/esm/entry/impureFunctionsAny.generated.js +312 -301
  79. package/lib/esm/entry/impureFunctionsNumber.generated.js +221 -211
  80. package/lib/esm/entry/pureFunctionsAny.generated.js +827 -814
  81. package/lib/esm/entry/pureFunctionsNumber.generated.js +234 -234
  82. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -1
  83. package/lib/esm/expression/embeddedDocs/function/arithmetic/invmod.js +8 -0
  84. package/lib/esm/expression/embeddedDocs/function/matrix/forEach.js +1 -1
  85. package/lib/esm/factoriesAny.js +1 -0
  86. package/lib/esm/function/algebra/rationalize.js +18 -4
  87. package/lib/esm/function/algebra/simplify/simplifyConstant.js +197 -29
  88. package/lib/esm/function/algebra/simplify/simplifyCore.js +35 -7
  89. package/lib/esm/function/algebra/simplify.js +73 -22
  90. package/lib/esm/function/arithmetic/invmod.js +57 -0
  91. package/lib/esm/function/arithmetic/round.js +2 -2
  92. package/lib/esm/function/geometry/intersect.js +12 -12
  93. package/lib/esm/function/probability/gamma.js +28 -30
  94. package/lib/esm/header.js +1 -1
  95. package/lib/esm/type/matrix/SparseMatrix.js +19 -15
  96. package/lib/esm/type/unit/Unit.js +2 -2
  97. package/lib/esm/utils/number.js +1 -1
  98. package/lib/esm/utils/snapshot.js +2 -2
  99. package/lib/esm/version.js +1 -1
  100. package/package.json +18 -17
  101. package/types/index.d.ts +250 -71
package/HISTORY.md CHANGED
@@ -1,6 +1,48 @@
1
1
  # History
2
2
 
3
- # 2021-11-03, version 9.5.2
3
+ # 2022-01-15, version 10.1.0
4
+
5
+ - Implemented function `invmod`, see #2368, #1744. Thanks @thetazero.
6
+ - Improvements and fixes in function `simplify`, thanks @gwhitney:
7
+ - Fix #1179, #1290: improve collection of non-constant like terms (#2384).
8
+ - Fix #2152: do not transform strings into numbers (#2372).
9
+ - Fix #1913: implement support for array and object simplification (#2382).
10
+ - Fix #2379: add embedded documentation for function `print`.
11
+ - Remove broken example from the embedded documentation of function `forEach`.
12
+
13
+
14
+ # 2021-12-29, version 10.0.2
15
+
16
+ - Fix #2156: simplify expressions like `-1 / (-x)` to `1/x`. Thanks @ony3000.
17
+ - Fix #2363: remove a redundant part of the regex to split a number.
18
+ - Fix #2291: add support for fractions in function `intersect`.
19
+ Thanks @thetazero.
20
+ - Fix #2358: bug in `SparseMatrix` when replacing a subset of a matrix with
21
+ a non-consecutive index. Thanks @Al-0.
22
+
23
+
24
+ # 2021-12-22, version 10.0.1
25
+
26
+ - Fix #1681: function `gamma` giving inaccurate complex results in some cases.
27
+ Thanks @kmdrGroch.
28
+ - Fixed a typo in an example, see #2366. Thanks @blackwindforce.
29
+
30
+
31
+ # 2021-11-03, version 10.0.0
32
+
33
+ !!! BE CAREFUL: BREAKING CHANGES IN THE TYPESCRIPT DEFINITIONS !!!
34
+
35
+ - Improvements to the Typescript typings (commit fc5c202e).
36
+ Thanks @joshhansen. First introduced in v9.5.1, but reverted because
37
+ it contains breaking changes.
38
+
39
+ Breaking changes: interface `MathNode` is now renamed to `MathNodeCommon`
40
+ and the related interfaces are structured in a different way.
41
+
42
+ - Fixed a typo in the TypeScript definition of toHTML. Thanks @TheToto.
43
+
44
+
45
+ # 2021-11-03, version 9.5.2`
4
46
 
5
47
  - Revert the improvements to the Typescript typings because they contain
6
48
  breaking changes. The improvements will be published in v10.0.0. See #2339.
package/NOTICE CHANGED
@@ -1,7 +1,7 @@
1
1
  math.js
2
2
  https://github.com/josdejong/mathjs
3
3
 
4
- Copyright (C) 2013-2021 Jos de Jong <wjosdejong@gmail.com>
4
+ Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
5
5
 
6
6
  Licensed under the Apache License, Version 2.0 (the "License");
7
7
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -7,7 +7,7 @@ Math.js is an extensive math library for JavaScript and Node.js. It features a f
7
7
  [![Version](https://img.shields.io/npm/v/mathjs.svg)](https://www.npmjs.com/package/mathjs)
8
8
  [![Downloads](https://img.shields.io/npm/dm/mathjs.svg)](https://www.npmjs.com/package/mathjs)
9
9
  [![Build Status](https://github.com/josdejong/mathjs/workflows/Node.js%20CI/badge.svg)](https://github.com/josdejong/mathjs/actions)
10
- [![Maintenance](https://img.shields.io/maintenance/yes/2021.svg)](https://github.com/josdejong/mathjs/graphs/commit-activity)
10
+ [![Maintenance](https://img.shields.io/maintenance/yes/2022.svg)](https://github.com/josdejong/mathjs/graphs/commit-activity)
11
11
  [![License](https://img.shields.io/github/license/josdejong/mathjs.svg)](https://github.com/josdejong/mathjs/blob/master/LICENSE)
12
12
  [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjosdejong%2Fmathjs.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjosdejong%2Fmathjs?ref=badge_shield)
13
13
  [![Codecov](https://codecov.io/gh/josdejong/mathjs/branch/develop/graph/badge.svg)](https://codecov.io/gh/josdejong/mathjs)
@@ -155,6 +155,14 @@ To run the tests remotely on BrowserStack, first set the environment variables `
155
155
 
156
156
  npm run test:browserstack
157
157
 
158
+ You can separately run the code linter, though it is also executed with `npm test`:
159
+
160
+ npm run lint
161
+
162
+ To automatically fix linting issue, run:
163
+
164
+ npm run format
165
+
158
166
  To test code coverage of the tests:
159
167
 
160
168
  npm run coverage
@@ -174,7 +182,7 @@ Thanks Github Actions and BrowserStack for the generous free hosting of this ope
174
182
 
175
183
  ## License
176
184
 
177
- Copyright (C) 2013-2021 Jos de Jong <wjosdejong@gmail.com>
185
+ Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
178
186
 
179
187
  Licensed under the Apache License, Version 2.0 (the "License");
180
188
  you may not use this file except in compliance with the License.
package/bin/cli.js CHANGED
@@ -30,7 +30,7 @@
30
30
  * cat script.txt | mathjs > results.txt Run input stream, output to file
31
31
  *
32
32
  * @license
33
- * Copyright (C) 2013-2021 Jos de Jong <wjosdejong@gmail.com>
33
+ * Copyright (C) 2013-2022 Jos de Jong <wjosdejong@gmail.com>
34
34
  *
35
35
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
36
36
  * use this file except in compliance with the License. You may obtain a copy
@@ -547,7 +547,7 @@ parser.evaluate('c[end - 1 : -1 : 2]') // Matrix, [8, 7, 6]
547
547
  ## Objects
548
548
 
549
549
  Objects in math.js work the same as in languages like JavaScript and Python.
550
- An object is enclosed by square brackets `{`, `}`, and contains a set of
550
+ An object is enclosed by curly brackets `{`, `}`, and contains a set of
551
551
  comma separated key/value pairs. Keys and values are separated by a colon `:`.
552
552
  Keys can be a symbol like `prop` or a string like `"prop"`.
553
553
 
@@ -5,7 +5,7 @@ Math.js contains the following constants.
5
5
  Constant | Description | Value
6
6
  --------------- | ----------- | -----
7
7
  `e`, `E` | Euler's number, the base of the natural logarithm. | 2.718281828459045
8
- `i` | Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part. | `sqrt(-1)`
8
+ `i` | Imaginary unit, defined as `i * i = -1`. A complex number is described as `a + b * i`, where a is the real part, and b is the imaginary part. | `sqrt(-1)`
9
9
  `Infinity` | Infinity, a number which is larger than the maximum number that can be handled by a floating point number. | `Infinity`
10
10
  `LN2` | Returns the natural logarithm of 2. | `0.6931471805599453`
11
11
  `LN10` | Returns the natural logarithm of 10. | `2.302585092994046`
@@ -0,0 +1,41 @@
1
+ <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
+
3
+ # Function invmod
4
+
5
+ Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation `ax ≣ 1 (mod b)`
6
+ See https://en.wikipedia.org/wiki/Modular_multiplicative_inverse.
7
+
8
+
9
+ ## Syntax
10
+
11
+ ```js
12
+ math.invmod(a, b)
13
+ ```
14
+
15
+ ### Parameters
16
+
17
+ Parameter | Type | Description
18
+ --------- | ---- | -----------
19
+ `a` | number &#124; BigNumber | An integer number
20
+ `b` | number &#124; BigNumber | An integer number
21
+
22
+ ### Returns
23
+
24
+ Type | Description
25
+ ---- | -----------
26
+ number &#124; BigNumber | Returns an integer number where `invmod(a,b)*a ≣ 1 (mod b)`
27
+
28
+
29
+ ## Examples
30
+
31
+ ```js
32
+ math.invmod(8, 12) // returns NaN
33
+ math.invmod(7, 13) // return 2
34
+ math.invmod(15151, 15122) // returns 10429
35
+ ```
36
+
37
+
38
+ ## See also
39
+
40
+ [gcd](gcd.md),
41
+ [xgcd](xgcd.md)
@@ -44,6 +44,7 @@ Function | Description
44
44
  [math.floor(x)](functions/floor.md) | Round a value towards minus infinity.
45
45
  [math.gcd(a,&nbsp;b)](functions/gcd.md) | Calculate the greatest common divisor for two or more values or arrays.
46
46
  [math.hypot(a,&nbsp;b,&nbsp;...)](functions/hypot.md) | Calculate the hypotenusa of a list with values.
47
+ [math.invmod(a,&nbsp;b)](functions/invmod.md) | Calculate the (modular) multiplicative inverse of a modulo b.
47
48
  [math.lcm(a,&nbsp;b)](functions/lcm.md) | Calculate the least common multiple for two or more values or arrays.
48
49
  [math.log(x&nbsp;[,&nbsp;base])](functions/log.md) | Calculate the logarithm of a value.
49
50
  [math.log10(x)](functions/log10.md) | Calculate the 10-base logarithm of a value.
@@ -91,7 +91,7 @@ const scope2 = {
91
91
  print(code2.evaluate(scope2)) // 9
92
92
 
93
93
  // change a value in the scope and re-evaluate the node
94
- scope.a = 3
94
+ scope2.a = 3
95
95
  print(code2.evaluate(scope2)) // 27
96
96
 
97
97
  // 3. using function math.compile