Skip to content

Commit

Permalink
Merge branch 'josdejong:develop' into CodeEditorExample
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x authored Jan 2, 2024
2 parents cdc2e6d + a1192de commit 61e27be
Show file tree
Hide file tree
Showing 118 changed files with 12,297 additions and 9,319 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/browserstack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- run: npm ci
- run: npm run test:browserstack
env:
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand All @@ -30,10 +30,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- run: npm ci
- run: npm run lint
env:
Expand All @@ -43,10 +43,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- run: npm ci
- run: npm run coverage && npx codecov
env:
Expand All @@ -56,10 +56,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- run: npm ci
- run: npm run build-and-test
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/local-browser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- run: npm ci
- run: npm run test:browser
env:
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'none'
}
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,10 @@ MaybePixem <[email protected]>
Aly Khaled <[email protected]>
BuildTools <[email protected]>
Anik Patel <[email protected]>
Vrushaket Chaudhari <[email protected]>
Praise Nnamonu <[email protected]>
Vincent Tam <[email protected]>
Juan Pablo Alvarado <[email protected]>
Brooks Smith <[email protected]>

# Generated by tools/update-authors.js
116 changes: 116 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,121 @@
# History


# 2023-12-20, 12.2.1

- Fix #3109: method `Node.toHTML` not accepting a custom `handler`.


# 2023-12-08, 12.2.0

- Feat: lazy evaluation of operators `and`, `or`, `&`, `|` (#3090, #3101,
#2766). Thanks @smith120bh.
- Fix: passing a 4th argument with a scope to raw functions.
- Fix: #3096 embedded docs of eigs throwing an error.


# 2023-11-17, 12.1.0

- Feat: Extend function `round` with support for units (#2761, #3095).
- Feat: Extend function `mod` with support for negative divisors in when
using `BigNumber` or `Fraction` (#3087).
- Fix: #3092 a typo in an error message when converting a string into a number.
- Fix: #3094 function `derivative` mutates the input expression when it fails.


# 2023-10-26, 12.0.0

Breaking changes:

- Fix #2879, #2927, #3014: change the confusing interface of `eigs` (#3037),
thanks @gwhitney.
Before, functions `eigs` returned an object:
```
{ values: MathCollection; vectors: MathCollection }
```
where `vectors` was a 2d matrix of which the columns contained the vectors.
This is changed to `eigs` returning an object:
```
{
values: MathCollection
eigenvectors: Array<{
value: number | BigNumber
vector: MathCollection
}>
}
```
Where `eigenvectors` is an array containing an object with the corresponding
eigenvalue and vector.
- Refactored the TypeScript type definitions to make them work with a `NodeNext`
module resolution (#3079, #2919).
- Type `MathJsStatic` is renamed to `MathJsInstance`.
- Type `FactoryDependencies` is deprecated, use `MathJsFactory` instead, and
import dependency maps directly from the library.
- Change the assignment operator of `.toTex()` output from `:=` to `=` (see
#2980, #2987).
- Drop official support for Node.js 14 and 16.

Features:

- Function `eigs` now has an option to turn off calculation of eigenvectors
(#3057, #2180). Thanks @gwhitney.

Fixes:

- Find eigenvectors of defective matrices (#3037). Thanks @gwhitney.


# 2023-10-26, 11.12.0

- Implemented function `subtractScalar` (#3081, #2643), thanks @vrushaket.
- Fix #3073: function format not escaping control characters and double
quotes (#3082).
- Fix: function `clone` not throwing an error when passing an unsupported
type like a function.
- Fix: #2960 add type definition of function `symbolicEqual` (#3035),
thanks @juancodeaudio.


# 2023-10-11, 11.11.2

- Fix #3025: improve handling of matrices and error handling
in function `corr` (#3030). Thanks @vrushaket.
- Fix #3074: improve error message when using function `max` in `derivative`.
- Fix #3073: fix parsing quotes inside a string.
- Fix #2027: cannot use named operators like `to` or `mod` as property name.


# 2023-09-20, 11.11.1

- Fix #2989: use one-based indices in `print` in the parser (#3009).
Thanks @dvd101x.
- Fix #2936: `mod` sometimes giving wrong results due to internal round-off
errors (#3011). Thanks @praisennamonu1.
- Internal refactor of `quantileSeq`, and fixed the embedded help (#3003).
Thanks @dvd101x.
- Updated dependencies and devDependencies.


# 2023-09-05, 11.11.0

- Implement function `corr` to calculate the correlation between two matrices
(#3015, #2624). Thanks @vrushaket.
- Lock `fraction.js` at version `4.3.4` for now, see #3024, 3022,
https://github.com/rawify/Fraction.js/issues/68.


# 2023-08-31, 11.10.1

- Upgrade to `[email protected]`, see #3022.
- Fix #3020: `lruQueue` using the global `hasOwnProperty` which may be
polluted.
- Add support for prefixes for the unit `erg`, and restrict prefixes of the
unit `joule` to only long prefixes like `kilo` and no short prefixes
like `k` (#3019). Thanks @costerwi.
- Add a new browser example `examples/browser/lorenz.html` that uses `solveODE`
and plots the result in a chart (#3018). Thanks @dvd101x.


# 2023-08-23, 11.10.0

- Extend function `quantileSeq` with support for a `dimension` (#3002).
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Math.js is an extensive math library for JavaScript and Node.js. It features a f
[![Version](https://img.shields.io/npm/v/mathjs.svg)](https://www.npmjs.com/package/mathjs)
[![Downloads](https://img.shields.io/npm/dm/mathjs.svg)](https://www.npmjs.com/package/mathjs)
[![Build Status](https://github.com/josdejong/mathjs/workflows/Node.js%20CI/badge.svg)](https://github.com/josdejong/mathjs/actions)
[![Maintenance](https://img.shields.io/maintenance/yes/2023.svg)](https://github.com/josdejong/mathjs/graphs/commit-activity)
[![Maintenance](https://img.shields.io/maintenance/yes/2024.svg)](https://github.com/josdejong/mathjs/graphs/commit-activity)
[![License](https://img.shields.io/github/license/josdejong/mathjs.svg)](https://github.com/josdejong/mathjs/blob/master/LICENSE)
[![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)
[![Codecov](https://codecov.io/gh/josdejong/mathjs/branch/develop/graph/badge.svg)](https://codecov.io/gh/josdejong/mathjs)
[![Github Sponsor](https://camo.githubusercontent.com/7d9333b097b2f54a8957d126ab82937811489c9b75c3850f609985cf94cd29fe/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532302d53706f6e736f722532306d652532306f6e2532304769744875622d6f72616e6765)](https://github.com/sponsors/josdejong)
[![Github Sponsor](https://img.shields.io/github/sponsors/josdejong
)](https://github.com/sponsors/josdejong)

## Features

Expand Down Expand Up @@ -135,7 +136,7 @@ A common case is to implement a new function. This involves the following steps:
- Write documentation on the function in the source code comment of `myNewFunction.js`. This documentation is used to auto generate documentation on the website.
- Write embedded documentation for the new function in `./src/expression/embeddedDocs/function/arithmetic/myNewFunction.js`. Add the new documentation to the index file `./src/expression/embeddedDocs/embeddedDocs.js`.
- Write unit tests for the function in `./test/unit-tests/function/arithmetic/myNewFunction.test.js`.
- Write a TypeScript definition for the new function in `./types/index.d.ts`, and write tests for it in `./types/index.ts`. Normally, two definitions need to be added: one for the static function `math.myNewFunction(...)` and one for the chained API `math.chain(...).myNewFunction(...)`.
- Write the necessary TypeScript definitions for the new function in `./types/index.d.ts`, and write tests for it in `./test/typescript-tests/testTypes.ts`. This is described in [./types/EXPLANATION.md](./types/EXPLANATION.md).
- Ensure the code style is ok by running `npm run lint` (run `npm run format` to fix the code style automatically).


Expand Down
2 changes: 1 addition & 1 deletion docs/datatypes/fractions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Fractions

For calculations with fractions, math.js supports a `Fraction` data type.
Fraction support is powered by [fraction.js](https://github.com/infusion/Fraction.js).
Fraction support is powered by [fraction.js](https://github.com/rawify/Fraction.js).
Unlike [numbers](numbers.md) and [BigNumbers](./bignumbers.md), fractions can
store numbers with infinitely repeating decimals, for example `1/3 = 0.3333333...`,
which can be represented as `0.(3)`, or `2/7` which can be represented as `0.(285714)`.
Expand Down
17 changes: 12 additions & 5 deletions docs/expressions/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,25 @@ See section below | Implicit multiplication
`to`, `in` | Unit conversion
`<<`, `>>`, `>>>` | Bitwise left shift, bitwise right arithmetic shift, bitwise right logical shift
`==`, `!=`, `<`, `>`, `<=`, `>=` | Relational
`&` | Bitwise and
`&` | Bitwise and (lazily evaluated)
<code>^&#124;</code> | Bitwise xor
<code>&#124;</code> | Bitwise or
`and` | Logical and
<code>&#124;</code> | Bitwise or (lazily evaluated)
`and` | Logical and (lazily evaluated)
`xor` | Logical xor
`or` | Logical or
`or` | Logical or (lazily evaluated)
`?`, `:` | Conditional expression
`=` | Assignment
`,` | Parameter and column separator
`;` | Row separator
`\n`, `;` | Statement separators

Lazy evaluation is used where logically possible for bitwise and logical
operators. In the following example, the value of `x` will not even be
evaluated because it cannot effect the final result:
```js
math.evaluate('false and x') // false, no matter what x equals
```


## Functions

Expand Down Expand Up @@ -475,7 +482,7 @@ const parser = math.parser()
parser.evaluate('a = 2 + 3i') // Complex, 2 + 3i
parser.evaluate('b = a - 3i') // Complex, 2 + 0i
parser.evaluate('number(b)') // Number, 2
parser.evaluate('number(a)') // Error: 2 + i is no valid number
parser.evaluate('number(a)') // Error: unexpected type of argument
```


Expand Down
2 changes: 1 addition & 1 deletion docs/reference/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Stores values for a scalar unit and its postfix. (eg `100 mm` or `100 kg`). Alth
Stores values for a fractional number.

- [Overview](../datatypes/fractions.md)
- [Class API](https://github.com/infusion/Fraction.js/)
- [Class API](https://github.com/rawify/Fraction.js)

## BigNumber

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/custom_evaluate_using_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const divide = (a, b) => a / b

// create a mathjs instance with hardly any functions
// there are some functions created which are used internally by evaluate though,
// for example by the Unit class which has dependencies on addScalar, subtract,
// for example by the Unit class which has dependencies on addScalar, subtractScalar,
// multiplyScalar, etc.
const math = create(evaluateDependencies)

Expand Down
53 changes: 53 additions & 0 deletions examples/browser/lorenz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>math.js | Lorenz Attractor</title>
<script src="../../lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-2.25.2.min.js" charset="utf-8"></script>
</head>

<body>
<div id="LorenzGraph"></div>
</body>
<script defer>

// define the constants for the Lorenz attractor
const sigma = 10
const beta = 2.7
const rho = 28

// solve the Lorenz attractor
const sol = math.solveODE(lorenz, [0, 100], [1, 1, 1])

// make colors that represents time differences in the solution
const diff = math.diff(sol.t)
const color = [diff[0], ...diff]

// render the plot using plotly
Plotly.newPlot('LorenzGraph',
[{
x: sol.y.map(u => u[0]),
y: sol.y.map(u => u[1]),
z: sol.y.map(u => u[2]),
line: { color, colorscale: 'Jet' },
type: "scatter3d",
mode: "lines"
}],
{ width: 800, height: 600 }
)

// define the lorenz attractor
function lorenz(t, u) {
const [x, y, z] = u
return [
sigma * (y - x),
x * (rho - z) - y,
x * y - beta * z
]
}
</script>

</html>
2 changes: 1 addition & 1 deletion examples/matrices.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ console.log()
// this will mutate the matrix
console.log('set and get a value')
const p = math.matrix([[1, 2], [3, 4]])
p.set([0, 10], 5)
p.set([0, 1], 5)
print(p) // [[1, 5], [3, 4]]
const p21 = p.get([1, 0])
print(p21) // 3
Expand Down
Loading

0 comments on commit 61e27be

Please sign in to comment.