Publish mathjs@10.3.0

This commit is contained in:
Jos de Jong 2022-03-02 13:47:02 +01:00
parent b2bd8c05e1
commit 66056d692f
31 changed files with 180 additions and 47 deletions

View File

@ -142,8 +142,8 @@ math.evaluate('log(10000, 3 + 7)') // 4
math.evaluate('sin(pi / 4)') // 0.7071067811865475
```
New functions can be defined using the `function` keyword. Functions can be
defined with multiple variables. Function assignments are limited: they can
New functions can be defined by "assigning" an expression to a function call
with one or more variables. Such function assignments are limited: they can
only be defined on a single line.
```js
@ -157,6 +157,35 @@ parser.evaluate('g(x, y) = x ^ y')
parser.evaluate('g(2, 3)') // 8
```
Note that these function assignments do _not_ create closures; put another way,
all free variables in mathjs are dynamic:
```js
const parser = math.parser()
parser.evaluate('x = 7')
parser.evaluate('h(y) = x + y')
parser.evaluate('h(3)') // 10
parser.evaluate('x = 3')
parser.evaluate('h(3)') // 6, *not* 10
```
It is however possible to pass functions as parameters:
```js
const parser = math.parser()
parser.evaluate('twice(func, x) = func(func(x))')
parser.evaluate('twice(square, 2)') // 16
parser.evaluate('f(x) = 3*x')
parser.evaluate('twice(f, 2)') // 18
// a simplistic "numerical derivative":
parser.evaluate('eps = 1e-10')
parser.evaluate('nd(f, x) = (f(x+eps) - func(x-eps))/(2*eps)')
parser.evaluate('nd(square,2)') // 4.000000330961484
```
Math.js itself heavily uses typed functions, which ensure correct inputs and
throws meaningful errors when the input arguments are invalid. One can create
a [typed-function](https://github.com/josdejong/typed-function) in the

View File

@ -29,6 +29,7 @@ Function | Description
[simplify(expr)](functions/simplify.html) | Simplify an expression tree.
[simplifyCore(expr)](functions/simplifyCore.html) | simplifyCore() performs single pass simplification suitable for applications requiring ultimate performance.
[math.slu(A, order, threshold)](functions/slu.html) | Calculate the Sparse Matrix LU decomposition with full pivoting.
[symbolicEqual(expr1, expr2)](functions/symbolicEqual.html) | Attempts to determine if two expressions are symbolically equal, i.
[math.usolve(U, b)](functions/usolve.html) | Finds one solution of a linear equation system by backward substitution.
[math.usolveAll(U, b)](functions/usolveAll.html) | Finds all solutions of a linear equation system by backward substitution.
@ -141,7 +142,7 @@ Function | Description
[math.identity(n)](functions/identity.html) | Create a 2-dimensional identity matrix with size m x n or n x n.
[math.inv(x)](functions/inv.html) | Calculate the inverse of a square matrix.
[math.kron(x, y)](functions/kron.html) | Calculates the kronecker product of 2 matrices or vectors.
[math.map(x, callback)](functions/map.html) | Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.
[math.map(x, callback)](functions/map.html) | Create a new matrix or array with the results of a callback function executed on each entry of a given matrix/array.
[math.matrixFromColumns(...arr)](functions/matrixFromColumns.html) | Create a dense matrix from vectors as individual columns.
[math.matrixFromFunction(size, fn)](functions/matrixFromFunction.html) | Create a matrix by evaluating a generating function at each index.
[math.matrixFromRows(...arr)](functions/matrixFromRows.html) | Create a dense matrix from vectors as individual rows.

View File

@ -6,8 +6,15 @@ layout: default
<h1 id="function-map">Function map <a href="#function-map" title="Permalink">#</a></h1>
Create a new matrix or array with the results of the callback function executed on
each entry of the matrix/array.
Create a new matrix or array with the results of a callback function executed on
each entry of a given matrix/array.
For each entry of the input, the callback is invoked with three arguments:
the value of the entry, the index at which that entry occurs, and the full
matrix/array being traversed. Note that because the matrix/array might be
multidimensional, the "index" argument is always an array of numbers giving
the index in each dimension. This is true even for vectors: the "index"
argument is an array of length 1, rather than simply a number.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
@ -20,14 +27,14 @@ math.map(x, callback)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Matrix &#124; Array | The matrix to iterate on.
`callback` | Function | The callback method is invoked with three parameters: the value of the element, the index of the element, and the matrix being traversed.
`x` | Matrix &#124; Array | The input to iterate on.
`callback` | Function | The function to call (as described above) on each entry of the input
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
Matrix &#124; array | Transformed map of x
Matrix &#124; array | Transformed map of x; always has the same type and shape as x
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
@ -42,6 +49,16 @@ Type | Description
math.map([1, 2, 3], function(value) {
return value * value
}) // returns [1, 4, 9]
// The calling convention for the callback can cause subtleties:
math.map([1, 2, 3], math.format)
// throws TypeError: map attempted to call 'format(1,[0])' but argument 2 of type Array does not match expected type number or function or Object or string or boolean
// [This happens because `format` _can_ take a second argument,
// but its semantics don't match that of the 2nd argument `map` provides]
// To avoid this error, use a function that takes exactly the
// desired arguments:
math.map([1, 2, 3], x => math.format(x)) // returns ['1', '2', '3']
```

View File

@ -21,7 +21,7 @@ math.subset(value, index, replacement [, defaultValue]) // replace a subset
Parameter | Type | Description
--------- | ---- | -----------
`matrix` | Array &#124; Matrix &#124; string | An array, matrix, or string
`index` | Index | An index containing ranges for each dimension
`index` | Index | For each dimension of the target, specifies an index or a list of indices to fetch or set. `subset` uses the cartesian product of the indices specified in each dimension.
`replacement` | * | An array, matrix, or scalar. If provided, the subset is replaced with replacement. If not provided, the subset is returned
`defaultValue` | * | Default value, filled in on new entries when the matrix is resized. If not provided, math.matrix elements will be left undefined. Default value: undefined.
@ -48,8 +48,16 @@ math.subset(d, math.index([0, 1], 1)) // returns [[2], [4]]
// replace a subset
const e = []
const f = math.subset(e, math.index(0, [0, 2]), [5, 6]) // f = [[5, 6]]
const f = math.subset(e, math.index(0, [0, 2]), [5, 6]) // f = [[5, 6]] and e = [[5, 0, 6]]
const g = math.subset(f, math.index(1, 1), 7, 0) // g = [[5, 6], [0, 7]]
// get submatrix using ranges
const M = [
[1,2,3],
[4,5,6],
[7,8,9]
]
math.subset(M, math.index(math.range(0,2), math.range(0,3))) // [[1,2,3],[4,5,6]]
```

View File

@ -0,0 +1,66 @@
---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-symbolicequal">Function symbolicEqual <a href="#function-symbolicequal" title="Permalink">#</a></h1>
Attempts to determine if two expressions are symbolically equal, i.e.
one is the result of valid algebraic manipulations on the other.
Currently, this simply checks if the difference of the two expressions
simplifies down to 0. So there are two important caveats:
1. whether two expressions are symbolically equal depends on the
manipulations allowed. Therefore, this function takes an optional
third argument, which are the options that control the behavior
as documented for the `simplify()` function.
2. it is in general intractable to find the minimal simplification of
an arbitrarily complicated expression. So while a `true` value
of `symbolicEqual` ensures that the two expressions can be manipulated
to match each other, a `false` value does not absolutely rule this out.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
symbolicEqual(expr1, expr2)
symbolicEqual(expr1, expr2, options)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`expr1` | Node &#124; string | The first expression to compare
`expr2` | Node &#124; string | The second expression to compare
`options` | Object | Optional option object, passed to simplify
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
boolean | Returns true if a valid manipulation making the expressions equal is found.
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
Type | Description
---- | -----------
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
symbolicEqual('x*y', 'y*x') // true
symbolicEqual('x*y', 'y*x', {context: {multiply: {commutative: false}}})
//false
symbolicEqual('x/y', '(y*x^(-1))^(-1)') // true
symbolicEqual('abs(x)','x') // false
symbolicEqual('abs(x)','x', simplify.positiveContext) // true
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[simplify](simplify.html),
[evaluate](evaluate.html)

View File

@ -27,7 +27,7 @@ Math.js can be downloaded or linked from various content delivery networks:
<tbody>
<tr>
<td>unpkg</td>
<td><a href="https://unpkg.com/mathjs@10.2.0/">https://unpkg.com/mathjs@10.2.0/</a></td>
<td><a href="https://unpkg.com/mathjs@10.3.0/">https://unpkg.com/mathjs@10.3.0/</a></td>
</tr>
<tr>
<td>cdnjs</td>
@ -47,8 +47,8 @@ Math.js can be downloaded or linked from various content delivery networks:
Or download the full bundle directly from [unpkg](https://unpkg.com):
<p>
<a href="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js">
math.js (version 10.2.0, <span id="size">176 kB</span>, minified and gzipped)
<a href="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js">
math.js (version 10.3.0, <span id="size">177 kB</span>, minified and gzipped)
</a>
</p>

View File

@ -15,7 +15,7 @@
}
</style>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
</head>
<body>

View File

@ -24,7 +24,7 @@ File: [angle_configuration.html](angle_configuration.html) (click for a live dem
}
</style>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
</head>
<body>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>math.js | basic usage</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
</head>
<body>

View File

@ -12,7 +12,7 @@ File: [basic_usage.html](basic_usage.html) (click for a live demo)
<head>
<meta charset="utf-8">
<title>math.js | basic usage</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
</head>
<body>

View File

@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | currency conversion</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<style>
body,

View File

@ -13,7 +13,7 @@ File: [currency_conversion.html](currency_conversion.html) (click for a live dem
<meta charset="utf-8">
<title>math.js | currency conversion</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<style>
body,

View File

@ -15,7 +15,7 @@
}
</style>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
</head>
<body>

View File

@ -24,7 +24,7 @@ File: [custom_separators.html](custom_separators.html) (click for a live demo)
}
</style>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
</head>
<body>

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>math.js | plot</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<script src="https://cdn.plot.ly/plotly-1.35.2.min.js"></script>

View File

@ -12,7 +12,7 @@ File: [plot.html](plot.html) (click for a live demo)
<head>
<meta charset="utf-8">
<title>math.js | plot</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<script src="https://cdn.plot.ly/plotly-1.35.2.min.js"></script>

View File

@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | pretty printing with MathJax</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>

View File

@ -13,7 +13,7 @@ File: [pretty_printing_with_mathjax.html](pretty_printing_with_mathjax.html) (cl
<meta charset="utf-8">
<title>math.js | pretty printing with MathJax</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>

View File

@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | printing HTML</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<style>
body {

View File

@ -13,7 +13,7 @@ File: [printing_html.html](printing_html.html) (click for a live demo)
<meta charset="utf-8">
<title>math.js | printing HTML</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<style>
body {

View File

@ -9,7 +9,7 @@
<script>
// load math.js using require.js
require(['https://unpkg.com/mathjs@10.2.0/lib/browser/math.js'], function (math) {
require(['https://unpkg.com/mathjs@10.3.0/lib/browser/math.js'], function (math) {
// evaluate some expression
const result = math.evaluate('1.2 * (2 + 4.5)')
document.write(result)

View File

@ -18,7 +18,7 @@ File: [requirejs_loading.html](requirejs_loading.html) (click for a live demo)
<script>
// load math.js using require.js
require(['https://unpkg.com/mathjs@10.2.0/lib/browser/math.js'], function (math) {
require(['https://unpkg.com/mathjs@10.3.0/lib/browser/math.js'], function (math) {
// evaluate some expression
const result = math.evaluate('1.2 * (2 + 4.5)')
document.write(result)

View File

@ -5,7 +5,7 @@
<meta charset="utf-8">
<title>math.js | rocket trajectory optimization</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<style>

View File

@ -14,7 +14,7 @@ File: [rocket_trajectory_optimization.html](rocket_trajectory_optimization.html)
<meta charset="utf-8">
<title>math.js | rocket trajectory optimization</title>
<script src="https://unpkg.com/mathjs@10.2.0/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@10.3.0/lib/browser/math.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<style>

View File

@ -92,7 +92,7 @@ File: [webworkers.html](webworkers.html) (click for a live demo)
File: [worker.js](worker.js)
```js
importScripts('https://unpkg.com/mathjs@10.2.0/lib/browser/math.js')
importScripts('https://unpkg.com/mathjs@10.3.0/lib/browser/math.js')
// create a parser
const parser = self.math.parser()

View File

@ -1,4 +1,4 @@
importScripts('https://unpkg.com/mathjs@10.2.0/lib/browser/math.js')
importScripts('https://unpkg.com/mathjs@10.3.0/lib/browser/math.js')
// create a parser
const parser = self.math.parser()

View File

@ -4,6 +4,18 @@ layout: default
<h1 id="history">History <a href="#history" title="Permalink">#</a></h1>
<h1 id="20210302-version-1030">2021-03-02, version 10.3.0 <a href="#20210302-version-1030" title="Permalink">#</a></h1>
- Fix <a href="https://github.com/josdejong/mathjs/issues/1260">#1260</a>: implement function `symbolicEqual` <a href="https://github.com/josdejong/mathjs/issues/2424">#2424</a>). Thanks <a href="https://github.com/gwhitney">@gwhitney</a>.
- Fix <a href="https://github.com/josdejong/mathjs/issues/2441">#2441</a>, <a href="https://github.com/josdejong/mathjs/issues/2442">#2442</a>: support passing a function as argument to functions created
in the expression parser <a href="https://github.com/josdejong/mathjs/issues/2443">#2443</a>). Thanks <a href="https://github.com/gwhitney">@gwhitney</a>.
- Fix <a href="https://github.com/josdejong/mathjs/issues/2325">#2325</a>: improve documentation of subset indices <a href="https://github.com/josdejong/mathjs/issues/2446">#2446</a>). Thanks <a href="https://github.com/gwhitney">@gwhitney</a>.
- Fix <a href="https://github.com/josdejong/mathjs/issues/2439">#2439</a>: fix a bug in `complexEigs` in which real-valued norms were
inadvertently being typed as complex numbers <a href="https://github.com/josdejong/mathjs/issues/2445">#2445</a>). Thanks <a href="https://github.com/gwhitney">@gwhitney</a>.
- Fix <a href="https://github.com/josdejong/mathjs/issues/2436">#2436</a>: improve documentation and error message of function `map` <a href="https://github.com/josdejong/mathjs/issues/2457">#2457</a>).
Thanks <a href="https://github.com/gwhitney">@gwhitney</a>.
<h1 id="20220301-version-1020">2022-03-01, version 10.2.0 <a href="#20220301-version-1020" title="Permalink">#</a></h1>
- Implemented context options to control simplifications allowed in `simplify`,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

14
package-lock.json generated
View File

@ -8,7 +8,7 @@
"name": "mathjs-website",
"version": "1.0.0",
"dependencies": {
"mathjs": "10.2.0"
"mathjs": "10.3.0"
},
"devDependencies": {
"fancy-log": "1.3.3",
@ -2936,9 +2936,9 @@
}
},
"node_modules/mathjs": {
"version": "10.2.0",
"resolved": "https://registry.npmjs.org/mathjs/-/mathjs-10.2.0.tgz",
"integrity": "sha512-SSr0E069ZePcqxlxG9QnPYFk+JZbY9L1d7bm/C/ySsOEvHvDGixTtlXwYXvkCWX+mtk1KmlluB6ShpXu53TEvw==",
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/mathjs/-/mathjs-10.3.0.tgz",
"integrity": "sha512-SHWkCPOMYNUyBc4FW27dg/s3P7iWBF9fmhAsIKxEyDRilymtPKhm4QVvdDP9TvXPn3w8J1pHhfNoC/b606H2ng==",
"dependencies": {
"@babel/runtime": "^7.17.2",
"complex.js": "^2.0.15",
@ -7008,9 +7008,9 @@
}
},
"mathjs": {
"version": "10.2.0",
"resolved": "https://registry.npmjs.org/mathjs/-/mathjs-10.2.0.tgz",
"integrity": "sha512-SSr0E069ZePcqxlxG9QnPYFk+JZbY9L1d7bm/C/ySsOEvHvDGixTtlXwYXvkCWX+mtk1KmlluB6ShpXu53TEvw==",
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/mathjs/-/mathjs-10.3.0.tgz",
"integrity": "sha512-SHWkCPOMYNUyBc4FW27dg/s3P7iWBF9fmhAsIKxEyDRilymtPKhm4QVvdDP9TvXPn3w8J1pHhfNoC/b606H2ng==",
"requires": {
"@babel/runtime": "^7.17.2",
"complex.js": "^2.0.15",

View File

@ -6,7 +6,7 @@
"url": "https://github.com/josdejong/mathjs.git"
},
"dependencies": {
"mathjs": "10.2.0"
"mathjs": "10.3.0"
},
"devDependencies": {
"fancy-log": "1.3.3",