Skip to content

Commit

Permalink
chore: upgrade to [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Oct 2, 2024
1 parent b0e6c61 commit f22364e
Show file tree
Hide file tree
Showing 34 changed files with 130 additions and 51 deletions.
4 changes: 2 additions & 2 deletions docs/core/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ The following configuration options are available:
the input value.

Available values are: `'number'` (default), `'BigNumber'`, `'bigint'`, or `'Fraction'`.
[BigNumbers](../datatypes/bignumbers.js) have higher precision than the default numbers of JavaScript,
[BigNumbers](../datatypes/bignumbers.html) have higher precision than the default numbers of JavaScript,
[bigint](../datatypes/bigints.html) can represent large integer numbers,
and [`Fractions`](../datatypes/fractions.js) store values in terms of a numerator and
and [`Fractions`](../datatypes/fractions.html) store values in terms of a numerator and
denominator.

- `numberFallback`. When `number` is configured for example with value `'bigint'`,
Expand Down
62 changes: 62 additions & 0 deletions docs/expressions/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,68 @@ Note that math.js embodies a preference for the operator forms, in that calling
`simplify` (see [Algebra](./algebra.html)) converts any instances of the function
form into the corresponding operator.

<h2 id="map-and-foreach">Map and forEach <a href="#map-and-foreach" title="Permalink">#</a></h2>

The `map` and `forEach` functions can be used to apply a callback function to each element of an array or matrix.

The callback functions can be functions, typed functions, inline functions (only in the parser) or compiled inline functions (only in the parser).

The callback can have the follwoing inputs:
- **value**: the current value in the array or matrix.
- **index**: the index of the current value expressed as an array of numbers.
- **array**: the array or matrix being iterated.

Below is the syntax for both functions:

<h3 id="map">map <a href="#map" title="Permalink">#</a></h3>

The `map` function applies a function to each element of an array and returns a new array with the results.

```js
const parser = math.parser()

// Define a square function
parser.evaluate('square(x) = x ^ 2')

// Apply the square function to each element of the array
parser.evaluate('result = map([1, 2, 3, 4], square)')
// result: [1, 4, 9, 16]

// Apply an inline function to each element of the array
parser.evaluate('result = map([1, 2, 3, 4], f(x) = x ^ 2)')
// result: [1, 4, 9, 16]

// Apply a compiled inline function to each element of the array
parser.evaluate('result = map([1, 2, 3, 4], x ^ 2)')
// result: [1, 4, 9, 16]
```

<h3 id="foreach">forEach <a href="#foreach" title="Permalink">#</a></h3>
The `forEach` function applies a function to each element of an array or matrix but does not return a new array. It is useful for executing side effects.

```js
// Define a function that prints each element
math.import({consoleLog: x => console.log(x)})
const parser = math.parser()

// Define a squareConsleLog function
parser.evaluate('squareConsoleLog(x) = consoleLog(x ^ 2)')

// Apply the squareConsleLog function to each element of the array
parser.evaluate('forEach([1, 2, 3, 4], squareConsleLog)')
// Prints: 1, 4, 9, 16

// Apply an inline function to each element of the array
parser.evaluate('forEach([1, 2, 3, 4], f(x) = consoleLog(x ^ 2))')
// Prints: 1, 4, 9, 16

// Apply a compiled inline function to each element of the array
parser.evaluate('forEach([1, 2, 3, 4], consoleLog(x ^ 2))')
// Prints: 1, 4, 9, 16
```

These functions are useful for performing element-wise operations on arrays or matrices.

<h2 id="constants-and-variables">Constants and variables <a href="#constants-and-variables" title="Permalink">#</a></h2>

Math.js has a number of built-in constants such as `pi` and `e`.
Expand Down
8 changes: 4 additions & 4 deletions download.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/">https://unpkg.com/mathjs@13.1.1/</a></td>
<td><a href="https://unpkg.com/mathjs@13.2.0/">https://unpkg.com/mathjs@13.2.0/</a></td>
</tr>
<tr>
<td>cdnjs</td>
Expand All @@ -48,9 +48,9 @@ Or download the full bundle directly from [unpkg](https://unpkg.com):

<p>
<a
href="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"
>math.js (version 13.1.1, <span id="size">181 kB</span>, minified and gzipped)</a>
and if needed the <a href="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js.map">source map</a>
href="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"
>math.js (version 13.2.0, <span id="size">181 kB</span>, minified and gzipped)</a>
and if needed the <a href="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js.map">source map</a>
</p>

Too large for you? Create your own [custom bundle](docs/custom_bundling.html).
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/angle_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
</style>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/angle_configuration.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ File: [angle_configuration.html](angle_configuration.html) (click for a live dem
}
</style>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/basic_usage.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>math.js | basic usage</title>
<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/basic_usage.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/currency_conversion.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | currency conversion</title>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<style>
body,
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/currency_conversion.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<style>
body,
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/custom_separators.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
</style>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/custom_separators.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ File: [custom_separators.html](custom_separators.html) (click for a live demo)
}
</style>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/lorenz.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.25.2.min.js" charset="utf-8"></script>
<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/lorenz.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ File: [lorenz.html](lorenz.html) (click for a live demo)
<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.25.2.min.js" charset="utf-8"></script>
<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/lorenz_interactive.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.28.0.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/lorenz_interactive.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ File: [lorenz_interactive.html](lorenz_interactive.html) (click for a live demo)
<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.28.0.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.9/katex.min.js"
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/plot.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>math.js | plot</title>
<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-1.35.2.min.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/plot.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-1.35.2.min.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/pretty_printing_with_mathjax.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | pretty printing with MathJax</title>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/pretty_printing_with_mathjax.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/printing_html.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | printing HTML</title>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<style>
body {
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/printing_html.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>

<style>
body {
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/requirejs_loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script>
// load math.js using require.js
require(['https://unpkg.com/mathjs@13.1.1/lib/browser/math.js'], function (math) {
require(['https://unpkg.com/mathjs@13.2.0/lib/browser/math.js'], function (math) {
// evaluate some expression
const result = math.evaluate('1.2 * (2 + 4.5)')
document.write(result)
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/requirejs_loading.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js'], function (math) {
require(['https://unpkg.com/mathjs@13.2.0/lib/browser/math.js'], function (math) {
// evaluate some expression
const result = math.evaluate('1.2 * (2 + 4.5)')
document.write(result)
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/rocket_trajectory_optimization.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<title>math.js | rocket trajectory optimization</title>

<script src="https://unpkg.com/mathjs@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/rocket_trajectory_optimization.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js"></script>
<script src="https://unpkg.com/mathjs@13.2.0/lib/browser/math.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/webworkers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@13.1.1/lib/browser/math.js')
importScripts('https://unpkg.com/mathjs@13.2.0/lib/browser/math.js')

// create a parser
const parser = self.math.parser()
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/webworkers/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
importScripts('https://unpkg.com/mathjs@13.1.1/lib/browser/math.js')
importScripts('https://unpkg.com/mathjs@13.2.0/lib/browser/math.js')

// create a parser
const parser = self.math.parser()
Expand Down
17 changes: 17 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ layout: default

<h1 id="history">History <a href="#history" title="Permalink">#</a></h1>

<h1 id="22041002-1320">2204-10-02 13.2.0 <a href="#22041002-1320" title="Permalink">#</a></h1>

- Feat: improve performance of functions `map`, `filter` and `forEach` (<a href="https://github.com/josdejong/mathjs/issues/3256">#3256</a>).
Thanks <a href="https://github.com/dvd101x">@dvd101x</a>.
- Feat: improve performance of the methods `map()` and `forEach()`
of `DenseMatrix` (<a href="https://github.com/josdejong/mathjs/issues/3251">#3251</a>). Thanks <a href="https://github.com/Galm007">@Galm007</a>.
- Fix: <a href="https://github.com/josdejong/mathjs/issues/3253">#3253</a> cannot use identifiers containing special characters in function
`derivative`.
- Fix: improve the type definitions of `ConstantNode` to support all data
types (<a href="https://github.com/josdejong/mathjs/issues/3257">#3257</a>). Thanks <a href="https://github.com/smith120bh">@smith120bh</a>.
- Fix: <a href="https://github.com/josdejong/mathjs/issues/3259">#3259</a> function `symbolicEqual` missing in the TypeScript definitions.
- Fix: <a href="https://github.com/josdejong/mathjs/issues/3246">#3246</a> function `leafCount` missing in the TypeScript definitions.
- Fix: <a href="https://github.com/josdejong/mathjs/issues/3267">#3267</a> implicit multiplication with a negative number and unit `in`.
- Docs: fix broken links on the Configuration page. Thanks <a href="https://github.com/vassudanagunta">@vassudanagunta</a>.
- Docs: document the syntax of `map` and `forEach` in the expression parser
(<a href="https://github.com/josdejong/mathjs/issues/3272">#3272</a>). Thanks <a href="https://github.com/dvd101x">@dvd101x</a>.

<h1 id="20240827-1311">2024-08-27, 13.1.1 <a href="#20240827-1311" title="Permalink">#</a></h1>

- Fix security vulnerability in the CLI and web API allowing to call functions
Expand Down
2 changes: 1 addition & 1 deletion js/lib/math.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/lib/math.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* It features real and complex numbers, units, matrices, a large set of
* mathematical functions, and a flexible expression parser.
*
* @version 13.1.1
* @date 2024-08-27
* @version 13.2.0
* @date 2024-10-02
*
* @license
* Copyright (C) 2013-2024 Jos de Jong <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion js/lib/math.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit f22364e

Please sign in to comment.