mathjs 10.5.2 → 10.6.1
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +28 -0
- package/lib/browser/math.js +6 -5
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesFft.generated.js +41 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesIfft.generated.js +29 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +16 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +66 -64
- package/lib/cjs/entry/pureFunctionsAny.generated.js +189 -171
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +6 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/fft.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/ifft.js +15 -0
- package/lib/cjs/factoriesAny.js +16 -0
- package/lib/cjs/function/algebra/derivative.js +1 -1
- package/lib/cjs/function/matrix/fft.js +128 -0
- package/lib/cjs/function/matrix/ifft.js +49 -0
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesFft.generated.js +24 -0
- package/lib/esm/entry/dependenciesAny/dependenciesIfft.generated.js +16 -0
- package/lib/esm/entry/dependenciesAny.generated.js +2 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +63 -61
- package/lib/esm/entry/pureFunctionsAny.generated.js +161 -145
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +4 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/fft.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/ifft.js +8 -0
- package/lib/esm/factoriesAny.js +2 -0
- package/lib/esm/function/algebra/derivative.js +1 -1
- package/lib/esm/function/matrix/fft.js +104 -0
- package/lib/esm/function/matrix/ifft.js +38 -0
- package/lib/esm/version.js +1 -1
- package/package.json +22 -24
- package/types/index.d.ts +1052 -283
- package/types/index.ts +711 -7
- package/docs/command_line_interface.md +0 -87
- package/docs/core/chaining.md +0 -41
- package/docs/core/configuration.md +0 -144
- package/docs/core/extension.md +0 -263
- package/docs/core/index.md +0 -21
- package/docs/core/serialization.md +0 -50
- package/docs/custom_bundling.md +0 -116
- package/docs/datatypes/bignumbers.md +0 -102
- package/docs/datatypes/complex_numbers.md +0 -168
- package/docs/datatypes/fractions.md +0 -75
- package/docs/datatypes/index.md +0 -67
- package/docs/datatypes/matrices.md +0 -375
- package/docs/datatypes/numbers.md +0 -106
- package/docs/datatypes/units.md +0 -444
- package/docs/expressions/algebra.md +0 -110
- package/docs/expressions/customization.md +0 -379
- package/docs/expressions/expression_trees.md +0 -710
- package/docs/expressions/html_classes.md +0 -38
- package/docs/expressions/index.md +0 -21
- package/docs/expressions/parsing.md +0 -224
- package/docs/expressions/security.md +0 -89
- package/docs/expressions/syntax.md +0 -706
- package/docs/getting_started.md +0 -124
- package/docs/index.md +0 -39
- package/docs/reference/classes/densematrix.md +0 -247
- package/docs/reference/classes/fibonacciheap.md +0 -70
- package/docs/reference/classes/matrixindex.md +0 -133
- package/docs/reference/classes/matrixrange.md +0 -158
- package/docs/reference/classes/resultset.md +0 -47
- package/docs/reference/classes/sparsematrix.md +0 -245
- package/docs/reference/classes/unit.md +0 -242
- package/docs/reference/classes.md +0 -86
- package/docs/reference/constants.md +0 -29
- package/docs/reference/functions/abs.md +0 -46
- package/docs/reference/functions/acos.md +0 -49
- package/docs/reference/functions/acosh.md +0 -47
- package/docs/reference/functions/acot.md +0 -48
- package/docs/reference/functions/acoth.md +0 -46
- package/docs/reference/functions/acsc.md +0 -49
- package/docs/reference/functions/acsch.md +0 -46
- package/docs/reference/functions/add.md +0 -59
- package/docs/reference/functions/and.md +0 -53
- package/docs/reference/functions/apply.md +0 -56
- package/docs/reference/functions/arg.md +0 -53
- package/docs/reference/functions/asec.md +0 -49
- package/docs/reference/functions/asech.md +0 -46
- package/docs/reference/functions/asin.md +0 -49
- package/docs/reference/functions/asinh.md +0 -46
- package/docs/reference/functions/atan.md +0 -49
- package/docs/reference/functions/atan2.md +0 -56
- package/docs/reference/functions/atanh.md +0 -46
- package/docs/reference/functions/bellNumbers.md +0 -45
- package/docs/reference/functions/bignumber.md +0 -47
- package/docs/reference/functions/bin.md +0 -45
- package/docs/reference/functions/bitAnd.md +0 -51
- package/docs/reference/functions/bitNot.md +0 -51
- package/docs/reference/functions/bitOr.md +0 -52
- package/docs/reference/functions/bitXor.md +0 -51
- package/docs/reference/functions/boolean.md +0 -50
- package/docs/reference/functions/catalan.md +0 -45
- package/docs/reference/functions/cbrt.md +0 -60
- package/docs/reference/functions/ceil.md +0 -63
- package/docs/reference/functions/chain.md +0 -54
- package/docs/reference/functions/clone.md +0 -43
- package/docs/reference/functions/column.md +0 -45
- package/docs/reference/functions/combinations.md +0 -49
- package/docs/reference/functions/combinationsWithRep.md +0 -49
- package/docs/reference/functions/compare.md +0 -67
- package/docs/reference/functions/compareNatural.md +0 -92
- package/docs/reference/functions/compareText.md +0 -54
- package/docs/reference/functions/compile.md +0 -56
- package/docs/reference/functions/complex.md +0 -17
- package/docs/reference/functions/composition.md +0 -46
- package/docs/reference/functions/concat.md +0 -56
- package/docs/reference/functions/config.md +0 -44
- package/docs/reference/functions/conj.md +0 -50
- package/docs/reference/functions/cos.md +0 -51
- package/docs/reference/functions/cosh.md +0 -46
- package/docs/reference/functions/cot.md +0 -47
- package/docs/reference/functions/coth.md +0 -49
- package/docs/reference/functions/count.md +0 -45
- package/docs/reference/functions/createUnit.md +0 -52
- package/docs/reference/functions/cross.md +0 -58
- package/docs/reference/functions/csc.md +0 -47
- package/docs/reference/functions/csch.md +0 -49
- package/docs/reference/functions/ctranspose.md +0 -50
- package/docs/reference/functions/cube.md +0 -51
- package/docs/reference/functions/cumsum.md +0 -57
- package/docs/reference/functions/deepEqual.md +0 -53
- package/docs/reference/functions/derivative.md +0 -61
- package/docs/reference/functions/det.md +0 -49
- package/docs/reference/functions/diag.md +0 -61
- package/docs/reference/functions/diff.md +0 -70
- package/docs/reference/functions/distance.md +0 -80
- package/docs/reference/functions/divide.md +0 -55
- package/docs/reference/functions/dot.md +0 -48
- package/docs/reference/functions/dotDivide.md +0 -52
- package/docs/reference/functions/dotMultiply.md +0 -52
- package/docs/reference/functions/dotPow.md +0 -49
- package/docs/reference/functions/eigs.md +0 -54
- package/docs/reference/functions/equal.md +0 -75
- package/docs/reference/functions/equalText.md +0 -53
- package/docs/reference/functions/erf.md +0 -49
- package/docs/reference/functions/evaluate.md +0 -56
- package/docs/reference/functions/exp.md +0 -54
- package/docs/reference/functions/expm.md +0 -49
- package/docs/reference/functions/expm1.md +0 -54
- package/docs/reference/functions/factorial.md +0 -49
- package/docs/reference/functions/fft.md +0 -35
- package/docs/reference/functions/filter.md +0 -50
- package/docs/reference/functions/fix.md +0 -62
- package/docs/reference/functions/flatten.md +0 -46
- package/docs/reference/functions/floor.md +0 -66
- package/docs/reference/functions/forEach.md +0 -41
- package/docs/reference/functions/format.md +0 -127
- package/docs/reference/functions/fraction.md +0 -45
- package/docs/reference/functions/gamma.md +0 -49
- package/docs/reference/functions/gcd.md +0 -50
- package/docs/reference/functions/getMatrixDataType.md +0 -59
- package/docs/reference/functions/hasNumericValue.md +0 -55
- package/docs/reference/functions/help.md +0 -42
- package/docs/reference/functions/hex.md +0 -45
- package/docs/reference/functions/hypot.md +0 -51
- package/docs/reference/functions/identity.md +0 -57
- package/docs/reference/functions/ifft.md +0 -35
- package/docs/reference/functions/im.md +0 -53
- package/docs/reference/functions/import.md +0 -68
- package/docs/reference/functions/index.md +0 -55
- package/docs/reference/functions/intersect.md +0 -50
- package/docs/reference/functions/inv.md +0 -45
- package/docs/reference/functions/invmod.md +0 -47
- package/docs/reference/functions/isInteger.md +0 -55
- package/docs/reference/functions/isNaN.md +0 -56
- package/docs/reference/functions/isNegative.md +0 -55
- package/docs/reference/functions/isNumeric.md +0 -55
- package/docs/reference/functions/isPositive.md +0 -57
- package/docs/reference/functions/isPrime.md +0 -54
- package/docs/reference/functions/isZero.md +0 -59
- package/docs/reference/functions/kldivergence.md +0 -41
- package/docs/reference/functions/kron.md +0 -53
- package/docs/reference/functions/larger.md +0 -60
- package/docs/reference/functions/largerEq.md +0 -56
- package/docs/reference/functions/lcm.md +0 -54
- package/docs/reference/functions/leafCount.md +0 -52
- package/docs/reference/functions/leftShift.md +0 -52
- package/docs/reference/functions/lgamma.md +0 -46
- package/docs/reference/functions/log.md +0 -57
- package/docs/reference/functions/log10.md +0 -50
- package/docs/reference/functions/log1p.md +0 -54
- package/docs/reference/functions/log2.md +0 -50
- package/docs/reference/functions/lsolve.md +0 -51
- package/docs/reference/functions/lsolveAll.md +0 -51
- package/docs/reference/functions/lup.md +0 -52
- package/docs/reference/functions/lusolve.md +0 -59
- package/docs/reference/functions/mad.md +0 -50
- package/docs/reference/functions/map.md +0 -65
- package/docs/reference/functions/matrix.md +0 -56
- package/docs/reference/functions/matrixFromColumns.md +0 -49
- package/docs/reference/functions/matrixFromFunction.md +0 -54
- package/docs/reference/functions/matrixFromRows.md +0 -49
- package/docs/reference/functions/max.md +0 -61
- package/docs/reference/functions/mean.md +0 -57
- package/docs/reference/functions/median.md +0 -57
- package/docs/reference/functions/min.md +0 -61
- package/docs/reference/functions/mod.md +0 -59
- package/docs/reference/functions/mode.md +0 -50
- package/docs/reference/functions/multinomial.md +0 -46
- package/docs/reference/functions/multiply.md +0 -60
- package/docs/reference/functions/norm.md +0 -59
- package/docs/reference/functions/not.md +0 -50
- package/docs/reference/functions/nthRoot.md +0 -53
- package/docs/reference/functions/nthRoots.md +0 -58
- package/docs/reference/functions/number.md +0 -49
- package/docs/reference/functions/numeric.md +0 -52
- package/docs/reference/functions/oct.md +0 -45
- package/docs/reference/functions/ones.md +0 -59
- package/docs/reference/functions/or.md +0 -53
- package/docs/reference/functions/parse.md +0 -56
- package/docs/reference/functions/parser.md +0 -70
- package/docs/reference/functions/partitionSelect.md +0 -53
- package/docs/reference/functions/permutations.md +0 -51
- package/docs/reference/functions/pickRandom.md +0 -59
- package/docs/reference/functions/pinv.md +0 -44
- package/docs/reference/functions/pow.md +0 -65
- package/docs/reference/functions/print.md +0 -64
- package/docs/reference/functions/prod.md +0 -55
- package/docs/reference/functions/qr.md +0 -65
- package/docs/reference/functions/quantileSeq.md +0 -62
- package/docs/reference/functions/random.md +0 -54
- package/docs/reference/functions/randomInt.md +0 -53
- package/docs/reference/functions/range.md +0 -70
- package/docs/reference/functions/rationalize.md +0 -68
- package/docs/reference/functions/re.md +0 -53
- package/docs/reference/functions/reshape.md +0 -60
- package/docs/reference/functions/resize.md +0 -51
- package/docs/reference/functions/resolve.md +0 -46
- package/docs/reference/functions/rightArithShift.md +0 -52
- package/docs/reference/functions/rightLogShift.md +0 -52
- package/docs/reference/functions/rotate.md +0 -53
- package/docs/reference/functions/rotationMatrix.md +0 -57
- package/docs/reference/functions/round.md +0 -61
- package/docs/reference/functions/row.md +0 -45
- package/docs/reference/functions/sec.md +0 -47
- package/docs/reference/functions/sech.md +0 -49
- package/docs/reference/functions/setCartesian.md +0 -49
- package/docs/reference/functions/setDifference.md +0 -47
- package/docs/reference/functions/setDistinct.md +0 -43
- package/docs/reference/functions/setIntersect.md +0 -46
- package/docs/reference/functions/setIsSubset.md +0 -47
- package/docs/reference/functions/setMultiplicity.md +0 -46
- package/docs/reference/functions/setPowerset.md +0 -43
- package/docs/reference/functions/setSize.md +0 -47
- package/docs/reference/functions/setSymDifference.md +0 -47
- package/docs/reference/functions/setUnion.md +0 -46
- package/docs/reference/functions/sign.md +0 -52
- package/docs/reference/functions/simplify.md +0 -130
- package/docs/reference/functions/simplifyConstant.md +0 -52
- package/docs/reference/functions/simplifyCore.md +0 -50
- package/docs/reference/functions/sin.md +0 -51
- package/docs/reference/functions/sinh.md +0 -46
- package/docs/reference/functions/size.md +0 -50
- package/docs/reference/functions/slu.md +0 -57
- package/docs/reference/functions/smaller.md +0 -60
- package/docs/reference/functions/smallerEq.md +0 -56
- package/docs/reference/functions/sort.md +0 -56
- package/docs/reference/functions/sparse.md +0 -51
- package/docs/reference/functions/splitUnit.md +0 -37
- package/docs/reference/functions/sqrt.md +0 -50
- package/docs/reference/functions/sqrtm.md +0 -46
- package/docs/reference/functions/square.md +0 -51
- package/docs/reference/functions/squeeze.md +0 -53
- package/docs/reference/functions/std.md +0 -76
- package/docs/reference/functions/stirlingS2.md +0 -52
- package/docs/reference/functions/string.md +0 -49
- package/docs/reference/functions/subset.md +0 -65
- package/docs/reference/functions/subtract.md +0 -54
- package/docs/reference/functions/sum.md +0 -54
- package/docs/reference/functions/symbolicEqual.md +0 -62
- package/docs/reference/functions/tan.md +0 -49
- package/docs/reference/functions/tanh.md +0 -50
- package/docs/reference/functions/to.md +0 -47
- package/docs/reference/functions/trace.md +0 -50
- package/docs/reference/functions/transpose.md +0 -49
- package/docs/reference/functions/typeOf.md +0 -81
- package/docs/reference/functions/typed.md +0 -56
- package/docs/reference/functions/unaryMinus.md +0 -49
- package/docs/reference/functions/unaryPlus.md +0 -48
- package/docs/reference/functions/unequal.md +0 -74
- package/docs/reference/functions/unit.md +0 -48
- package/docs/reference/functions/usolve.md +0 -51
- package/docs/reference/functions/usolveAll.md +0 -51
- package/docs/reference/functions/variance.md +0 -78
- package/docs/reference/functions/xgcd.md +0 -47
- package/docs/reference/functions/xor.md +0 -53
- package/docs/reference/functions/zeros.md +0 -57
- package/docs/reference/functions.md +0 -297
- package/docs/reference/index.md +0 -5
- package/examples/advanced/convert_fraction_to_bignumber.js +0 -59
- package/examples/advanced/custom_argument_parsing.js +0 -98
- package/examples/advanced/custom_datatype.js +0 -56
- package/examples/advanced/custom_evaluate_using_factories.js +0 -19
- package/examples/advanced/custom_evaluate_using_import.js +0 -18
- package/examples/advanced/custom_loading.js +0 -33
- package/examples/advanced/custom_relational_functions.js +0 -62
- package/examples/advanced/custom_scope_objects.js +0 -115
- package/examples/advanced/expression_trees.js +0 -55
- package/examples/advanced/function_transform.js +0 -50
- package/examples/advanced/more_secure_eval.js +0 -36
- package/examples/advanced/use_bigint.js +0 -43
- package/examples/advanced/web_server/math_worker.js +0 -24
- package/examples/advanced/web_server/server.js +0 -80
- package/examples/algebra.js +0 -34
- package/examples/basic_usage.js +0 -49
- package/examples/bignumbers.js +0 -52
- package/examples/browser/angle_configuration.html +0 -134
- package/examples/browser/basic_usage.html +0 -39
- package/examples/browser/currency_conversion.html +0 -125
- package/examples/browser/custom_separators.html +0 -81
- package/examples/browser/plot.html +0 -78
- package/examples/browser/pretty_printing_with_mathjax.html +0 -122
- package/examples/browser/printing_html.html +0 -170
- package/examples/browser/requirejs_loading.html +0 -20
- package/examples/browser/rocket_trajectory_optimization.html +0 -301
- package/examples/browser/webworkers/webworkers.html +0 -80
- package/examples/browser/webworkers/worker.js +0 -28
- package/examples/chaining.js +0 -56
- package/examples/complex_numbers.js +0 -67
- package/examples/expressions.js +0 -188
- package/examples/fractions.js +0 -74
- package/examples/import.js +0 -95
- package/examples/matrices.js +0 -101
- package/examples/objects.js +0 -35
- package/examples/package.json +0 -3
- package/examples/serialization.js +0 -16
- package/examples/sparse_matrices.js +0 -19
- package/examples/units.js +0 -108
@@ -1,87 +0,0 @@
|
|
1
|
-
# Command Line Interface (CLI)
|
2
|
-
|
3
|
-
When math.js is installed globally using npm, its expression parser can be used
|
4
|
-
from the command line. To install math.js globally:
|
5
|
-
|
6
|
-
```bash
|
7
|
-
$ npm install -g mathjs
|
8
|
-
```
|
9
|
-
|
10
|
-
Normally, a global installation must be run with admin rights (precede the
|
11
|
-
command with `sudo`). After installation, the application `mathjs` is available
|
12
|
-
via the command line:
|
13
|
-
|
14
|
-
```bash
|
15
|
-
$ mathjs
|
16
|
-
> 12 / (2.3 + 0.7)
|
17
|
-
4
|
18
|
-
> 12.7 cm to inch
|
19
|
-
5 inch
|
20
|
-
> sin(45 deg) ^ 2
|
21
|
-
0.5
|
22
|
-
> 9 / 3 + 2i
|
23
|
-
3 + 2i
|
24
|
-
> det([-1, 2; 3, 1])
|
25
|
-
-7
|
26
|
-
```
|
27
|
-
|
28
|
-
The command line interface can be used to open a prompt, to execute a script,
|
29
|
-
or to pipe input and output streams:
|
30
|
-
|
31
|
-
```bash
|
32
|
-
$ mathjs # Open a command prompt
|
33
|
-
$ mathjs script.txt # Run a script file, output to console
|
34
|
-
$ mathjs script1.txt script2.txt # Run two script files
|
35
|
-
$ mathjs script.txt > results.txt # Run a script file, output to file
|
36
|
-
$ cat script.txt | mathjs # Run input stream, output to console
|
37
|
-
$ cat script.txt | mathjs > results.txt # Run input stream, output to file
|
38
|
-
```
|
39
|
-
|
40
|
-
You can also use it to create LaTeX from or sanitize your expressions using the
|
41
|
-
`--tex` and `--string` options:
|
42
|
-
|
43
|
-
```bash
|
44
|
-
$ mathjs --tex
|
45
|
-
> 1/2
|
46
|
-
\frac{1}{2}
|
47
|
-
```
|
48
|
-
|
49
|
-
```bash
|
50
|
-
$ mathjs --string
|
51
|
-
> (1+1+1)
|
52
|
-
(1 + 1 + 1)
|
53
|
-
```
|
54
|
-
|
55
|
-
To change the parenthesis option use the `--parenthesis=` flag:
|
56
|
-
|
57
|
-
```bash
|
58
|
-
$ mathjs --string --parenthesis=auto
|
59
|
-
> (1+1+1)
|
60
|
-
1 + 1 + 1
|
61
|
-
```
|
62
|
-
|
63
|
-
```bash
|
64
|
-
$ mathjs --string --parenthesis=all
|
65
|
-
> (1+1+1)
|
66
|
-
(1 + 1) + 1
|
67
|
-
```
|
68
|
-
|
69
|
-
# Command line debugging (REPL)
|
70
|
-
|
71
|
-
For debugging purposes, `bin/repl.js` provides a REPL (Read Evaluate Print Loop)
|
72
|
-
for interactive testing of mathjs without having to build new build files after every
|
73
|
-
little change to the source files. You can either start it directly (`./bin/repl.js`) or
|
74
|
-
via node (`node bin/repl.js`).
|
75
|
-
|
76
|
-
You can exit using either [ctrl]-[C] or [ctrl]-[D].
|
77
|
-
|
78
|
-
```bash
|
79
|
-
$ ./bin/repl.js
|
80
|
-
> math.parse('1+1')
|
81
|
-
{ op: '+',
|
82
|
-
fn: 'add',
|
83
|
-
args:
|
84
|
-
[ { value: '1', valueType: 'number' },
|
85
|
-
{ value: '1', valueType: 'number' } ] }
|
86
|
-
>
|
87
|
-
```
|
package/docs/core/chaining.md
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# Chaining
|
2
|
-
|
3
|
-
Math.js supports chaining operations by wrapping a value into a `Chain`.
|
4
|
-
A chain can be created with the function `math.chain(value)`
|
5
|
-
(formerly `math.select(value)`).
|
6
|
-
All functions available in the math namespace can be executed via the chain.
|
7
|
-
The functions will be executed with the chain's value as the first argument,
|
8
|
-
followed by extra arguments provided by the function call itself.
|
9
|
-
|
10
|
-
```js
|
11
|
-
math.chain(3)
|
12
|
-
.add(4)
|
13
|
-
.subtract(2)
|
14
|
-
.done() // 5
|
15
|
-
|
16
|
-
math.chain( [[1, 2], [3, 4]] )
|
17
|
-
.subset(math.index(0, 0), 8)
|
18
|
-
.multiply(3)
|
19
|
-
.done() // [[24, 6], [9, 12]]
|
20
|
-
```
|
21
|
-
|
22
|
-
### API
|
23
|
-
|
24
|
-
A `Chain` is constructed as:
|
25
|
-
|
26
|
-
```js
|
27
|
-
math.chain()
|
28
|
-
math.chain(value)
|
29
|
-
```
|
30
|
-
|
31
|
-
The `Chain` has all functions available in the `math` namespace, and has
|
32
|
-
a number of special functions:
|
33
|
-
|
34
|
-
- `done()`
|
35
|
-
Finalize the chain and return the chain's value.
|
36
|
-
- `valueOf()`
|
37
|
-
The same as `done()`, returns the chain's value.
|
38
|
-
- `toString()`
|
39
|
-
Executes `math.format(value)` onto the chain's value, returning
|
40
|
-
a string representation of the value.
|
41
|
-
|
@@ -1,144 +0,0 @@
|
|
1
|
-
# Configuration
|
2
|
-
|
3
|
-
Math.js contains a number of configuration options.
|
4
|
-
These options can be applied on a created mathjs instance and changed afterwards.
|
5
|
-
|
6
|
-
```js
|
7
|
-
import { create, all } from 'mathjs'
|
8
|
-
|
9
|
-
// create a mathjs instance with configuration
|
10
|
-
const config = {
|
11
|
-
epsilon: 1e-12,
|
12
|
-
matrix: 'Matrix',
|
13
|
-
number: 'number',
|
14
|
-
precision: 64,
|
15
|
-
predictable: false,
|
16
|
-
randomSeed: null
|
17
|
-
}
|
18
|
-
const math = create(all, config)
|
19
|
-
|
20
|
-
// read the applied configuration
|
21
|
-
console.log(math.config())
|
22
|
-
|
23
|
-
// change the configuration
|
24
|
-
math.config({
|
25
|
-
number: 'BigNumber'
|
26
|
-
})
|
27
|
-
```
|
28
|
-
|
29
|
-
The following configuration options are available:
|
30
|
-
|
31
|
-
- `epsilon`. The minimum relative difference used to test equality between two
|
32
|
-
compared values. This value is used by all relational functions.
|
33
|
-
Default value is `1e-12`.
|
34
|
-
|
35
|
-
- `matrix`. The default type of matrix output for functions.
|
36
|
-
Available values are: `'Matrix'` (default) or `'Array'`.
|
37
|
-
Where possible, the type of matrix output from functions is determined from
|
38
|
-
the function input: An array as input will return an Array, a Matrix as input
|
39
|
-
will return a Matrix. In case of no matrix as input, the type of output is
|
40
|
-
determined by the option `matrix`. In case of mixed matrix
|
41
|
-
inputs, a matrix will be returned always.
|
42
|
-
|
43
|
-
- `number`. The type of numeric output for functions which cannot
|
44
|
-
determine the numeric type from the inputs. For most functions though,
|
45
|
-
the type of output is determined from the the input:
|
46
|
-
a number as input will return a number as output,
|
47
|
-
a BigNumber as input returns a BigNumber as output.
|
48
|
-
|
49
|
-
For example the functions `math.evaluate('2+3')`, `math.parse('2+3')`,
|
50
|
-
`math.range('1:10')`, and `math.unit('5cm')` use the `number` configuration
|
51
|
-
setting. But `math.sqrt(4)` will always return the number `2`
|
52
|
-
regardless of the `number` configuration, because the input is a number.
|
53
|
-
|
54
|
-
Available values are: `'number'` (default), `'BigNumber'`, or `'Fraction'`.
|
55
|
-
[BigNumbers](../datatypes/bignumbers.js) have higher precision than the default
|
56
|
-
numbers of JavaScript, and [`Fractions`](../datatypes/fractions.js) store
|
57
|
-
values in terms of a numerator and denominator.
|
58
|
-
|
59
|
-
- `precision`. The maximum number of significant digits for BigNumbers.
|
60
|
-
This setting only applies to BigNumbers, not to numbers.
|
61
|
-
Default value is `64`.
|
62
|
-
|
63
|
-
- `predictable`. Predictable output type of functions. When true, output type
|
64
|
-
depends only on the input types. When false (default), output type can vary
|
65
|
-
depending on input values. For example `math.sqrt(-4)` returns `complex('2i')` when
|
66
|
-
predictable is false, and returns `NaN` when true.
|
67
|
-
Predictable output can be needed when programmatically handling the result of
|
68
|
-
a calculation, but can be inconvenient for users when evaluating dynamic
|
69
|
-
equations.
|
70
|
-
|
71
|
-
- `randomSeed`. Set this option to seed pseudo random number generation, making it deterministic. The pseudo random number generator is reset with the seed provided each time this option is set. For example, setting it to `'a'` will cause `math.random()` to return `0.43449421599986604` upon the first call after setting the option every time. Set to `null` to seed the pseudo random number generator with a random seed. Default value is `null`.
|
72
|
-
|
73
|
-
|
74
|
-
## Examples
|
75
|
-
|
76
|
-
This section shows a number of configuration examples.
|
77
|
-
|
78
|
-
### node.js
|
79
|
-
|
80
|
-
```js
|
81
|
-
import { create, all } from 'mathjs'
|
82
|
-
|
83
|
-
const config = {
|
84
|
-
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
|
85
|
-
}
|
86
|
-
const math = create(all, config)
|
87
|
-
|
88
|
-
// range will output an Array
|
89
|
-
math.range(0, 4) // Array [0, 1, 2, 3]
|
90
|
-
|
91
|
-
// change the configuration from Arrays to Matrices
|
92
|
-
math.config({
|
93
|
-
matrix: 'Matrix' // Choose 'Matrix' (default) or 'Array'
|
94
|
-
})
|
95
|
-
|
96
|
-
// range will output a Matrix
|
97
|
-
math.range(0, 4) // Matrix [0, 1, 2, 3]
|
98
|
-
|
99
|
-
// create an instance of math.js with BigNumber configuration
|
100
|
-
const bigmath = create(all, {
|
101
|
-
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
|
102
|
-
precision: 32 // 64 by default, only applicable for BigNumbers
|
103
|
-
})
|
104
|
-
|
105
|
-
// parser will parse numbers as BigNumber now:
|
106
|
-
bigmath.evaluate('1 / 3') // BigNumber, 0.33333333333333333333333333333333
|
107
|
-
```
|
108
|
-
|
109
|
-
### browser
|
110
|
-
|
111
|
-
|
112
|
-
```html
|
113
|
-
<!DOCTYPE HTML>
|
114
|
-
<html>
|
115
|
-
<head>
|
116
|
-
<script src="math.js" type="text/javascript"></script>
|
117
|
-
</head>
|
118
|
-
<body>
|
119
|
-
<script type="text/javascript">
|
120
|
-
// the default instance of math.js is available as 'math'
|
121
|
-
|
122
|
-
// range will output a Matrix
|
123
|
-
math.range(0, 4) // Matrix [0, 1, 2, 3]
|
124
|
-
|
125
|
-
// change the configuration of math from Matrices to Arrays
|
126
|
-
math.config({
|
127
|
-
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
|
128
|
-
})
|
129
|
-
|
130
|
-
// range will output an Array
|
131
|
-
math.range(0, 4) // Array [0, 1, 2, 3]
|
132
|
-
|
133
|
-
// create a new instance of math.js with bignumber configuration
|
134
|
-
const bigmath = math.create({
|
135
|
-
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
|
136
|
-
precision: 32 // 64 by default, only applicable for BigNumbers
|
137
|
-
})
|
138
|
-
|
139
|
-
// parser will parse numbers as BigNumber now:
|
140
|
-
bigmath.evaluate('1 / 3') // BigNumber, 0.33333333333333333333333333333333
|
141
|
-
</script>
|
142
|
-
</body>
|
143
|
-
</html>
|
144
|
-
```
|
package/docs/core/extension.md
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
# Extension
|
2
|
-
|
3
|
-
The library can easily be extended with functions and variables using the
|
4
|
-
[`import`](../reference/functions/import.md) function. The `import` function is available on a mathjs instance, which can be created using the `create` function.
|
5
|
-
|
6
|
-
```js
|
7
|
-
import { create, all } from 'mathjs'
|
8
|
-
|
9
|
-
const math = create(all)
|
10
|
-
|
11
|
-
math.import(/* ... */)
|
12
|
-
```
|
13
|
-
|
14
|
-
The function `import` accepts an object with functions and variables, or an array with factory functions. It has the following syntax:
|
15
|
-
|
16
|
-
```js
|
17
|
-
math.import(functions: Object [, options: Object])
|
18
|
-
```
|
19
|
-
|
20
|
-
Where:
|
21
|
-
|
22
|
-
- `functions` is an object or array containing the functions and/or values to be
|
23
|
-
imported. `import` support regular values and functions, typed functions
|
24
|
-
(see section [Typed functions](#typed-functions)), and factory functions
|
25
|
-
(see section [Factory functions](#factory-functions)).
|
26
|
-
An array is only applicable when it contains factory functions.
|
27
|
-
|
28
|
-
- `options` is an optional second argument with options.
|
29
|
-
The following options are available:
|
30
|
-
|
31
|
-
- `{boolean} override`
|
32
|
-
If `true`, existing functions will be overwritten. The default value is `false`.
|
33
|
-
- `{boolean} silent`
|
34
|
-
If `true`, the function will not throw errors on duplicates or invalid
|
35
|
-
types. Default value is `false`.
|
36
|
-
- `{boolean} wrap`
|
37
|
-
If `true`, the functions will be wrapped in a wrapper function which
|
38
|
-
converts data types like Matrix to primitive data types like Array.
|
39
|
-
The wrapper is needed when extending math.js with libraries which do not
|
40
|
-
support the math.js data types. The default value is `false`.
|
41
|
-
|
42
|
-
The following code example shows how to import a function and a value into math.js:
|
43
|
-
|
44
|
-
```js
|
45
|
-
// define new functions and variables
|
46
|
-
math.import({
|
47
|
-
myvalue: 42,
|
48
|
-
hello: function (name) {
|
49
|
-
return 'hello, ' + name + '!'
|
50
|
-
}
|
51
|
-
})
|
52
|
-
|
53
|
-
// defined functions can be used in both JavaScript as well as the parser
|
54
|
-
math.myvalue * 2 // 84
|
55
|
-
math.hello('user') // 'hello, user!'
|
56
|
-
|
57
|
-
const parser = math.parser()
|
58
|
-
parser.evaluate('myvalue + 10') // 52
|
59
|
-
parser.evaluate('hello("user")') // 'hello, user!'
|
60
|
-
```
|
61
|
-
|
62
|
-
## Import external libraries
|
63
|
-
|
64
|
-
External libraries like
|
65
|
-
[numbers.js](https://github.com/sjkaliski/numbers.js) and
|
66
|
-
[numeric.js](https://github.com/sloisel/numeric) can be imported as follows.
|
67
|
-
The libraries must be installed using npm:
|
68
|
-
|
69
|
-
$ npm install numbers
|
70
|
-
$ npm install numeric
|
71
|
-
|
72
|
-
The libraries can be easily imported into math.js using `import`.
|
73
|
-
In order to convert math.js specific data types like `Matrix` to primitive types
|
74
|
-
like `Array`, the imported functions can be wrapped by enabling `{wrap: true}`.
|
75
|
-
|
76
|
-
```js
|
77
|
-
import { create, all } from 'mathjs'
|
78
|
-
import * as numbers from 'numbers'
|
79
|
-
import * as numeric from 'numeric'
|
80
|
-
|
81
|
-
// create a mathjs instance and import the numbers.js and numeric.js libraries
|
82
|
-
const math = create(all)
|
83
|
-
math.import(numbers, {wrap: true, silent: true})
|
84
|
-
math.import(numeric, {wrap: true, silent: true})
|
85
|
-
|
86
|
-
// use functions from numbers.js
|
87
|
-
math.fibonacci(7) // 13
|
88
|
-
math.evaluate('fibonacci(7)') // 13
|
89
|
-
|
90
|
-
// use functions from numeric.js
|
91
|
-
math.evaluate('eig([1, 2; 4, 3])').lambda.x // [5, -1]
|
92
|
-
```
|
93
|
-
|
94
|
-
|
95
|
-
## Typed functions
|
96
|
-
|
97
|
-
Typed functions can be created using `math.typed`. A typed function is a function
|
98
|
-
which does type checking on the input arguments. It can have multiple signatures.
|
99
|
-
And can automatically convert input types where needed.
|
100
|
-
|
101
|
-
A typed function can be created like:
|
102
|
-
|
103
|
-
```js
|
104
|
-
const max = typed('max', {
|
105
|
-
'number, number': function (a, b) {
|
106
|
-
return Math.max(a, b)
|
107
|
-
},
|
108
|
-
|
109
|
-
'BigNumber, BigNumber': function (a, b) {
|
110
|
-
return a.greaterThan(b) ? a : b
|
111
|
-
}
|
112
|
-
})
|
113
|
-
```
|
114
|
-
|
115
|
-
Typed functions can be merged as long as there are no conflicts in the signatures.
|
116
|
-
This allows for extending existing functions in math.js with support for new
|
117
|
-
data types.
|
118
|
-
|
119
|
-
```js
|
120
|
-
// create a new data type
|
121
|
-
function MyType (value) {
|
122
|
-
this.value = value
|
123
|
-
}
|
124
|
-
MyType.prototype.isMyType = true
|
125
|
-
MyType.prototype.toString = function () {
|
126
|
-
return 'MyType:' + this.value
|
127
|
-
}
|
128
|
-
|
129
|
-
// define a new datatype
|
130
|
-
math.typed.addType({
|
131
|
-
name: 'MyType',
|
132
|
-
test: function (x) {
|
133
|
-
// test whether x is of type MyType
|
134
|
-
return x && x.isMyType
|
135
|
-
}
|
136
|
-
})
|
137
|
-
|
138
|
-
// use the type in a new typed function
|
139
|
-
const add = typed('add', {
|
140
|
-
'MyType, MyType': function (a, b) {
|
141
|
-
return new MyType(a.value + b.value)
|
142
|
-
}
|
143
|
-
})
|
144
|
-
|
145
|
-
// import in math.js, extend the existing function `add` with support for MyType
|
146
|
-
math.import({add: add})
|
147
|
-
|
148
|
-
// use the new type
|
149
|
-
const ans = math.add(new MyType(2), new MyType(3)) // returns MyType(5)
|
150
|
-
console.log(ans) // outputs 'MyType:5'
|
151
|
-
```
|
152
|
-
|
153
|
-
Detailed information on typed functions is available here:
|
154
|
-
[https://github.com/josdejong/typed-function](https://github.com/josdejong/typed-function)
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
## Factory functions
|
160
|
-
|
161
|
-
Regular JavaScript functions can be imported in math.js using `math.import`:
|
162
|
-
|
163
|
-
```js
|
164
|
-
math.import({
|
165
|
-
myFunction: function (a, b) {
|
166
|
-
// ...
|
167
|
-
}
|
168
|
-
})
|
169
|
-
```
|
170
|
-
|
171
|
-
The function can be stored in a separate file:
|
172
|
-
|
173
|
-
```js
|
174
|
-
export function myFunction (a, b) {
|
175
|
-
// ...
|
176
|
-
}
|
177
|
-
```
|
178
|
-
|
179
|
-
Which can be imported like:
|
180
|
-
|
181
|
-
```js
|
182
|
-
import { myFunction } from './myFunction.js'
|
183
|
-
|
184
|
-
math.import({
|
185
|
-
myFunction
|
186
|
-
})
|
187
|
-
```
|
188
|
-
|
189
|
-
An issue arises when `myFunction` needs functionality from math.js:
|
190
|
-
it doesn't have access to the current instance of math.js when in a separate file.
|
191
|
-
Factory functions can be used to solve this issue. A factory function allows to inject dependencies into a function when creating it.
|
192
|
-
|
193
|
-
A syntax of factory function is:
|
194
|
-
|
195
|
-
```js
|
196
|
-
factory(name: string, dependencies: string[], create: function, meta?: Object): function
|
197
|
-
```
|
198
|
-
|
199
|
-
where:
|
200
|
-
|
201
|
-
- `name` is the name of the created function.
|
202
|
-
- `dependencies` is an array with names of the dependent functions.
|
203
|
-
- `create` is a function which creates the function.
|
204
|
-
An object with the dependencies is passed as first argument.
|
205
|
-
- `meta` An optional object which can contain any meta data you want.
|
206
|
-
This will be attached as a property `meta` on the created function.
|
207
|
-
Known meta data properties used by the mathjs instance are:
|
208
|
-
- `isClass: boolean` If true, the created function is supposed to be a
|
209
|
-
class, and for example will not be exposed in the expression parser
|
210
|
-
for security reasons.
|
211
|
-
- `lazy: boolean`. By default, everything is imported lazily by `import`.
|
212
|
-
only as soon as the imported function or constant is actually used, it
|
213
|
-
will be constructed. A function can be forced to be created immediately
|
214
|
-
by setting `lazy: false` in the meta data.
|
215
|
-
- `isTransformFunction: boolean`. If true, the created function is imported
|
216
|
-
as a transform function. It will not be imported in `math` itself, only
|
217
|
-
in the internal `mathWithTransform` namespace that is used by the
|
218
|
-
expression parser.
|
219
|
-
- `recreateOnConfigChange: boolean`. If true, the imported factory will be
|
220
|
-
created again when there is a change in the configuration. This is for
|
221
|
-
example used for the constants like `pi`, which is different depending
|
222
|
-
on the configsetting `number` which can be numbers or BigNumbers.
|
223
|
-
|
224
|
-
Here an example of a factory function which depends on `multiply`:
|
225
|
-
|
226
|
-
```js
|
227
|
-
import { factory, create, all } from 'mathjs'
|
228
|
-
|
229
|
-
// create a factory function
|
230
|
-
const name = 'negativeSquare'
|
231
|
-
const dependencies = ['multiply', 'unaryMinus']
|
232
|
-
const createNegativeSquare = factory(name, dependencies, function ({ multiply, unaryMinus }) {
|
233
|
-
return function negativeSquare (x) {
|
234
|
-
return unaryMinus(multiply(x, x))
|
235
|
-
}
|
236
|
-
})
|
237
|
-
|
238
|
-
// create an instance of the function yourself:
|
239
|
-
const multiply = (a, b) => a * b
|
240
|
-
const unaryMinus = (a) => -a
|
241
|
-
const negativeSquare = createNegativeSquare({ multiply, unaryMinus })
|
242
|
-
console.log(negativeSquare(3)) // -9
|
243
|
-
|
244
|
-
// or import the factory in a mathjs instance and use it there
|
245
|
-
const math = create(all)
|
246
|
-
math.import(createNegativeSquare)
|
247
|
-
console.log(math.negativeSquare(4)) // -16
|
248
|
-
console.log(math.evaluate('negativeSquare(5)')) // -25
|
249
|
-
```
|
250
|
-
|
251
|
-
You may wonder why you would inject functions `multiply` and `unaryMinus`
|
252
|
-
instead of just doing these calculations inside the function itself. The
|
253
|
-
reason is that this makes the factory function `negativeSquare` work for
|
254
|
-
different implementations: numbers, BigNumbers, units, etc.
|
255
|
-
|
256
|
-
```js
|
257
|
-
import { Decimal } from 'decimal.js'
|
258
|
-
|
259
|
-
// create an instance of our negativeSquare supporting BigNumbers instead of numbers
|
260
|
-
const multiply = (a, b) => a.mul(b)
|
261
|
-
const unaryMinus = (a) => new Decimal(0).minus(a)
|
262
|
-
const negativeSquare = createNegativeSquare({ multiply, unaryMinus })
|
263
|
-
```
|
package/docs/core/index.md
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# Core
|
2
|
-
|
3
|
-
## Usage
|
4
|
-
|
5
|
-
The core of math.js is the `math` namespace containing all functions and constants. There are three ways to do calculations in math.js:
|
6
|
-
|
7
|
-
- Doing regular function calls like `math.add(math.sqrt(4), 2)`.
|
8
|
-
- Evaluating expressions like `math.evaluate('sqrt(4) + 2')`
|
9
|
-
- Chaining operations like `math.chain(4).sqrt().add(2)`.
|
10
|
-
|
11
|
-
## Configuration
|
12
|
-
|
13
|
-
math.js can be configured using the `math.config()`, see page [Configuration](configuration.md).
|
14
|
-
|
15
|
-
## Extension
|
16
|
-
|
17
|
-
math.js can be extended with new functions and constants using the function `math.import()`, see page [Extension](extension.md).
|
18
|
-
|
19
|
-
## Serialization
|
20
|
-
|
21
|
-
To persist or exchange data structures like matrices and units, the data types of math.js can be stringified as JSON. This is explained on the page [Serialization](serialization.md).
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# Serialization
|
2
|
-
|
3
|
-
Math.js has a number of data types like `Matrix`, `Complex`, and `Unit`. These
|
4
|
-
types are instantiated JavaScript objects. To be able to store these data types
|
5
|
-
or send them between processes, they must be serialized. The data types of
|
6
|
-
math.js can be serialized to JSON. Use cases:
|
7
|
-
|
8
|
-
- Store data in a database or on disk.
|
9
|
-
- Interchange of data between a server and a client.
|
10
|
-
- Interchange of data between a web worker and the browser.
|
11
|
-
|
12
|
-
Math.js types can be serialized using JavaScript's built-in `JSON.stringify`
|
13
|
-
function:
|
14
|
-
|
15
|
-
```js
|
16
|
-
const x = math.complex('2 + 3i')
|
17
|
-
const str = JSON.stringify(x, math.replacer)
|
18
|
-
console.log(str)
|
19
|
-
// outputs a string '{"mathjs":"Complex","re":2,"im":3}'
|
20
|
-
```
|
21
|
-
|
22
|
-
> IMPORTANT: in most cases works, serialization correctly without
|
23
|
-
> passing the `math.replacer` function as second argument. This is because
|
24
|
-
> in most cases we can rely on the default behavior of JSON.stringify, which
|
25
|
-
> uses the `.toJSON` method on classes like `Unit` and `Complex` to correctly
|
26
|
-
> serialize them. However, there are a few special cases like the
|
27
|
-
> number `Infinity` which does require the replacer function in order to be
|
28
|
-
> serialized without losing information: without it, `Infinity` will be
|
29
|
-
> serialized as `"null"` and cannot be deserialized correctly.
|
30
|
-
>
|
31
|
-
> So, it's best to always pass the `math.replacer` function to prevent
|
32
|
-
> weird edge cases.
|
33
|
-
|
34
|
-
In order to deserialize a string, containing math.js data types, `JSON.parse`
|
35
|
-
can be used. In order to recognize the data types of math.js, `JSON.parse` must
|
36
|
-
be called with the reviver function of math.js:
|
37
|
-
|
38
|
-
```js
|
39
|
-
const json = '{"mathjs":"Unit","value":5,"unit":"cm","fixPrefix":false}'
|
40
|
-
const x = JSON.parse(json, math.reviver) // Unit 5 cm
|
41
|
-
```
|
42
|
-
|
43
|
-
Note that if math.js is used in conjunction with other data types, it is
|
44
|
-
possible to use multiple reviver functions at the same time by cascading them:
|
45
|
-
|
46
|
-
```js
|
47
|
-
const reviver = function (key, value) {
|
48
|
-
return reviver1(key, reviver2(key, value))
|
49
|
-
}
|
50
|
-
```
|