mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
1,318 lines (930 loc) • 72.7 kB
Markdown
# History
# 2019-03-10, version 5.7.0
- Implemented support for `pow()` in `derivative`. Thanks @sam-19.
- Gracefully handle round-off errors in fix, ceil, floor, and range
(Fixes #1429, see also #1434, #1432). Thanks @ericman314.
# 2019-03-02, version 5.6.0
- Upgrade decimal.js to v10.1.1 (#1421).
- Fixed #1418: missing whitespace when stringifying an expression
containing "not".
# 2019-02-20, version 5.5.0
- Fixed #1401: methods `map` and `forEach` of `SparseMatrix` not working
correctly when indexes are unordered.
- Fixed #1404: inconsistent rounding of negative numbers.
- Upgrade tiny-emitter to v2.1.0 (#1397).
# 2019-01-25, version 5.4.2
- Fixed `math.format` not working for BigNumbers with a precision above
1025 digits (see #1385). Thanks @ericman314.
- Fixed incorrect LaTeX output of `RelationalNode`. Thanks @rianmcguire.
- Fixed a bug the methods `map`, `forEach`, `traverse`, and `transform`
of `FunctionNode`.
# 2019-01-10, version 5.4.1
- Fix #1378: negative bignumbers not formatted correctly.
- Upgrade fraction.js to version 4.0.12 (#1369).
# 2018-12-09, version 5.4.0
- Extended sum.js to accept a dimension input to calculate the sum over a
specific axis. Thanks @bnlcas.
- Fix #1328: objects can't be written multi-line. Thanks @GHolk.
- Remove side effects caused by `Unit.format` and `Unit.toString`,
making changes to the unit on execution. Thanks @ericman314.
# 2018-12-03, version 5.3.1
- Fixed #1336: Unit.toSI() returning units with prefix like `mm` instead
of `m`. Thanks @ericman314.
# 2018-11-29, version 5.3.0
- Implemented function `hasNumericValue`. Thanks @Sathish-kumar-Subramani.
- Fix #1326: non-ascii character in print.js.
- Fix #1337: `math.format` not working correctly with `{ precision: 0 }`.
Thanks @dkenul.
# 2018-10-30, version 5.2.3
- Fixed #1293: non-unicode characters in `escape-latex` giving issues in some
specific cases. Thanks @dangmai.
- Fixed incorrect LaTeX output of function `bitNot`, see #1299. Thanks @FSMaxB.
- Fixed #1304: function `pow` not supporting inputs `pow(Unit, BigNumber)`.
- Upgraded dependencies (`escape-latex@1.2.0`)
# 2018-10-23, version 5.2.2
- Fixed #1286: Fixed unit base recognition and formatting for
user-defined units. Thanks @ericman314.
# 2018-10-18, version 5.2.1
- Fixed unit `rod` being defined as `5.02921` instead of `5.0292`.
Thanks @ericman314.
- Upgraded dependencies (`fraction.js@4.0.10`)
- Upgraded devDependencies (`@babel/core@7.1.2`, `nyc@13.1.0`,
`webpack@4.21.0`).
# 2018-10-05, version 5.2.0
- Implemented support for chained conditionals like `10 < x <= 50`.
Thanks @ericman314.
- Add an example showing a proof of concept of using `BigInt` in mathjs.
- Fixed #1269: Bugfix for BigNumber divided by unit. Thanks @ericman314.
- Fixed #1240: allow units having just a value and no unit.
Thanks @ericman314.
## 2018-09-09, version 5.1.2
- Fixed a typo in the docs of `parse`. Thanks @mathiasvr.
- Fixed #1222: a typo in the docs of `subset`.
- Fixed #1236: `quantileSeq` has inconsistent return.
- Fixed #1237: norm sometimes returning a complex number instead of
number.
- Upgraded dependencies (`fraction.js@4.0.9`)
- Upgraded devDependencies (`babel@7`, `karma-webpack@3.0.4`,
`nyc@13.0.1`, `standard@12.0.0`, `uglify-js@3.4.9`, `webpack@4.17.2`)
## 2018-08-21, version 5.1.1
- Function `isNumeric` now recognizes more types.
- Fixed #1214: functions `sqrt`, `max`, `min`, `var`, `std`, `mode`, `mad`,
`median`, and `partitionSelect` not neatly handling `NaN` inputs. In some
cases (`median`, `mad`, and `partitionSelect`) this resulted in an infinite
loop.
- Upgraded dependencies (`escape-latex@1.1.1`)
- Upgraded devDependencies (`webpack@4.17.0`)
## 2018-08-12, version 5.1.0
- Implemented support for strings enclosed in single quotes.
Thanks @jean-emmanuel.
- Implemented function `getMatrixDataType`. Thanks @JasonShin.
- Implemented new `options` argument in `simplify`. Thanks @paulobuchsbaum.
- Bug fixes in `rationalize`, see #1173. Thanks @paulobuchsbaum.
## 2018-07-22, version 5.0.4
- Strongly improved the performance of functions `factorial` for numbers.
This improves performance of functions `gamma`, `permutation`, and
`combination` too. See #1170. Thanks @honeybar.
- Strongly improved the performance of function `reshape`, thanks to a
friend of @honeybar.
## 2018-07-14, version 5.0.3
- Fixed many functions (for example `add` and `subtract`) not working
with matrices having a `datatype` defined.
- Fixed #1147: bug in `format` with `engineering` notation in outputting
the correct number of significant figures. Thanks @ericman314.
- Fixed #1162: transform functions not being cleaned up when overriding
it by importing a factory function with the same name.
- Fixed broken links in the documentation. Thanks @stropitek.
- Refactored the code of `parse` into a functional approach.
Thanks @harrysarson.
- Changed `decimal.js` import to ES6. Thanks @weinshel.
## 2018-07-07, version 5.0.2
- Fixed #1136: rocket trajectory example broken (since v4.0.0).
- Fixed #1137: `simplify` unnecessarily replacing implicit multiplication with
explicit multiplication.
- Fixed #1146: `rationalize` throwing exceptions for some input with decimals.
Thanks @maruta.
- Fixed #1088: function arguments not being passed to `rawArgs` functions.
- Fixed advanced example `add_new_datatypes`.
- Fixed mathjs core constants not working without complex numbers.
Thanks @ChristopherChudzicki.
- Fixed a broken link in the documentation on units. Thanks @stropitek.
- Upgraded dependencies (`typed-function@1.0.4`, `complex.js@2.0.11`).
- Upgraded devDependencies (`babel-loader@7.1.5 `, `uglify-js@3.4.3`,
`expr-eval@1.2.2`, `webpack@4.15.1`).
## 2018-07-01, version 5.0.1
- Improved error messaging when converting units. Thanks @gap777.
- Upgraded devDependencies (`kerma`, `uglify-js`, `webpack`).
## 2018-06-16, version 5.0.0
!!! BE CAREFUL: BREAKING CHANGES !!!
- Implemented complex conjugate transpose `math.ctranspose`. See #1097.
Thanks @jackschmidt.
- Changed the behavior of `A'` (transpose) in the expression parser to
calculate the complex conjugate transpose. See #1097. Thanks @jackschmidt.
- Added support for `complex({abs: 1, arg: 1})`, and improved the docs on
complex numbers. Thanks @ssaket.
- Renamed `eye` to `identity`, see #1054.
- Math.js code can now contain ES6. The ES6 source code is moved from `lib`
to `src`, and `lib` now contains the compiled ES5 code.
- Upgraded dependencies:
- `decimal.js` from `9.0.1` to `10.0.1`
- Upgraded dev dependencies
- Changed code style to https://standardjs.com/, run linter on `npm test`.
See #1110.
- Dropped support for bower. Use npm or an other package manages instead.
- Dropped support for (non-primitive) instances of `Number`, `Boolean`, and
`String` from functions `clone` and `typeof`.
- Dropped official support for IE9 (probably still works, but it's not tested).
- Fixed #851: More consistent behavior of sqrt, nthRoot, and pow.
Thanks @dakotablair.
- Fixed #1103: Calling `toTex` on node that contains `derivative` causing
an exception. Thanks @joelhoover.
## 2018-06-02, version 4.4.2
- Drastically improved the performance of `det`. Thanks @ericman314.
- Fixed #1065, #1121: Fixed wrong documentation of function
`compareNatural` and clarified the behavior for strings.
- Fixed #1122 a regression in function `inv` (since `v4.4.1`).
Thanks @ericman314.
## 2018-05-29, version 4.4.1
- Fixed #1109: a bug in `inv` when dealing with values close to zero.
Thanks @ericman314.
## 2018-05-28, version 4.4.0
- Implemented functions `equalText` and `compareText`. See #1085.
## 2018-05-21, version 4.3.0
- Implemented matrix exponential `math.expm`. Thanks @ericman314.
- Fixed #1101: math.js bundle not working when loading in a WebWorker.
- Upgraded dependencies
- `complex.js` from `v2.0.2` to `v2.0.10`.
- `fraction.js` from `v4.0.4` to `v4.0.8`.
- Upgraded devDependencies (`mocha`, `uglify-js`, `webpack`).
## 2018-05-05, version 4.2.2
- Fixed calculating the Frobenius norm of complex matrices correctly,
see #1098. Thanks @jackschmidt.
- Fixed #1076: cannot use mathjs in React VR by updating to
`escape-latex@1.0.3`.
## 2018-05-02, version 4.2.1
- Fixed `dist/math.js` being minified.
## 2018-05-02, version 4.2.0
- Implemented function `math.sqrtm`. Thanks @ferrolho.
- Implemented functions `math.log2`, `math.log1p`, and `math.expm1`.
Thanks @BigFav and @harrysarson.
- Fixed some unit tests broken on nodejs v10.
- Upgraded development dependencies.
- Dropped integration testing on nodejs v4.
## 2018-04-18, version 4.1.2
- Fixed #1082: implemented support for unit plurals `decades`, `centuries`,
and `millennia`.
- Fixed #1083: units `decade` and `watt` having a wrong name when stringifying.
Thanks @ericman314.
## 2018-04-11, version 4.1.1
- Fixed #1063: derivative not working when resolving a variable with unary
minus like `math.derivative('-x', 'x')`.
## 2018-04-08, version 4.1.0
- Extended function `math.print` with support for arrays and matrices.
Thanks @jean-emmanuel.
- Fixed #1077: Serialization/deserialization to JSON with reviver not being
supported by nodes.
- Fixed #1016: Extended `math.typeof` with support for `ResultSet` and nodes
like `SymbolNode`.
- Fixed #1072: Added support for long and short prefixes for the unit `bar`
(i.e. `millibar` and `mbar`).
## 2018-03-17, version 4.0.1
- Fixed #1062: mathjs not working on ES5 browsers like IE11 and Safari 9.3.
- Fixed #1061: `math.unit` not accepting input like `1/s`.
## 2018-02-25, version 4.0.0
!!! BE CAREFUL: BREAKING CHANGES !!!
Breaking changes (see also #682):
- **New expression compiler**
The compiler of the expression parser is replaced with one that doesn't use
`eval` internally. See #1019. This means:
- a slightly improved performance on most browsers.
- less risk of security exploits.
- the code of the new compiler is easier to understand, maintain, and debug.
Breaking change here: When using custom nodes in the expression parser,
the syntax of `_compile` has changed. This is an undocumented feature though.
- **Parsed expressions**
- The class `ConstantNode` is changed such that it just holds a value
instead of holding a stringified value and it's type.
`ConstantNode(valueStr, valueType`) is now `ConstantNode(value)`
Stringification uses `math.format`, which may result in differently
formatted numeric output.
- The constants `true`, `false`, `null`, `undefined`, `NaN`, `Infinity`,
and `uninitialized` are now parsed as ConstantNodes instead of
SymbolNodes in the expression parser. See #833.
- **Implicit multiplication**
- Changed the behavior of implicit multiplication to have higher
precedence than explicit multiplication and division, except in
a number of specific cases. This gives a more natural behavior
for implicit multiplications. For example `24h / 6h` now returns `4`,
whilst `1/2 kg` evaluates to `0.5 kg`. Thanks @ericman314. See: #792.
Detailed documentation: https://github.com/josdejong/mathjs/blob/v4/docs/expressions/syntax.md#implicit-multiplication.
- Immediately invoking a function returned by a function like `partialAdd(2)(3)`
is no longer supported, instead these expressions are evaluated as
an implicit multiplication `partialAdd(2) * (3)`. See #1035.
- **String formatting**
- In function `math.format`, the options `{exponential: {lower: number, upper: number}}`
(where `lower` and `upper` are values) are replaced with `{lowerExp: number, upperExp: number}`
(where `lowerExp` and `upperExp` are exponents). See #676. For example:
```js
math.format(2000, {exponential: {lower: 1e-2, upper: 1e2}})
```
is now:
```js
math.format(2000, {lowerExp: -2, upperExp: 2})
```
- In function `math.format`, the option `notation: 'fixed'` no longer rounds to
zero digits when no precision is specified: it leaves the digits as is.
See #676.
- **String comparison**
Changed the behavior of relational functions (`compare`, `equal`,
`equalScalar`, `larger`, `largerEq`, `smaller`, `smallerEq`, `unequal`)
to compare strings by their numeric value they contain instead of
alphabetically. This also impacts functions `deepEqual`, `sort`, `min`,
`max`, `median`, and `partitionSelect`. Use `compareNatural` if you
need to sort an array with text. See #680.
- **Angle units**
Changed `rad`, `deg`, and `grad` to have short prefixes,
and introduced `radian`, `degree`, and `gradian` and their plurals
having long prefixes. See #749.
- **Null**
- `null` is no longer implicitly casted to a number `0`, so input like
`math.add(2, null)` is no longer supported. See #830, #353.
- Dropped constant `uninitialized`, which was used to initialize
leave new entries undefined when resizing a matrix is removed.
Use `undefined` instead to indicate entries that are not explicitly
set. See #833.
- **New typed-function library**
- The `typed-function` library used to check the input types
of functions is completely rewritten and doesn't use `eval` under
the hood anymore. This means a reduced security risk, and easier
to debug code. The API is the same, but error messages may differ
a bit. Performance is comparable but may differ in specific
use cases and browsers.
Non breaking changes:
- Thanks to the new expression compiler and `typed-function` implementation,
mathjs doesn't use JavaScript's `eval` anymore under the hood.
This allows using mathjs in environments with security restrictions.
See #401.
- Implemented additional methods `isUnary()` and `isBinary()` on
`OperatorNode`. See #1025.
- Improved error messages for statistical functions.
- Upgraded devDependencies.
- Fixed #1014: `derivative` silently dropping additional arguments
from operator nodes with more than two arguments.
## 2018-02-07, version 3.20.2
- Upgraded to `typed-function@0.10.7` (bug-fix release).
- Fixed option `implicit` not being copied from an `OperatorNode`
when applying function `map`. Thanks @HarrySarson.
- Fixed #995: spaces and underscores not property being escaped
in `toTex()`. Thanks @FSMaxB.
## 2018-01-17, version 3.20.1
- Fixed #1018: `simplifyCore` failing in some cases with parentheses.
Thanks @firepick1.
## 2018-01-14, version 3.20.0
- Implement support for 3 or more arguments for operators `+` and `*` in
`derivative`. Thanks @HarrySarson. See #1002.
- Fixed `simplify` evalution of `simplify` of functions with more than two
arguments wrongly: `simplify('f(x, y, z)') evaluated to `f(f(x, y), z)`
instead of `f(x, y, z)`. Thanks @joelhoover.
- Fixed `simplify` throwing an error in some cases when simplifying unknown
functions, for example `simplify('f(4)')`. Thanks @joelhoover.
- Fixed #1013: `simplify` wrongly simplifing some expressions containing unary
minus, like `0 - -x`. Thanks @joelhoover.
- Fixed an error in an example in the documentation of `xor`. Thanks @denisx.
## 2018-01-06, version 3.19.0
- Extended functions `distance` and `intersect` with support for BigNumbers.
Thanks @ovk.
- Improvements in function `simplify`: added a rule that allows combining
of like terms in embedded quantities. Thanks @joelhoover.
## 2017-12-28, version 3.18.1
- Fixed #998: An issue with simplifying an expression containing a subtraction.
Thanks @firepick1.
## 2017-12-16, version 3.18.0
- Implemented function `rationalize`. Thanks @paulobuchsbaum.
- Upgraded dependencies:
```
decimal.js 7.2.3 → 9.0.1 (no breaking changes affecting mathjs)
fraction.js 4.0.2 → 4.0.4
tiny-emitter 2.0.0 → 2.0.2
```
- Upgraded dev dependencies.
- Fixed #975: a wrong example in the docs of lusolve.
- Fixed #983: `pickRandom` returning an array instead of single value
when input was an array with just one value. Clarified docs.
- Fixed #969: preven issues with yarn autoclean by renaming an
interally used folder "docs" to "embeddedDocs".
## 2017-11-18, version 3.17.0
- Improved `simplify` for nested exponentiations. Thanks @IvanVergiliev.
- Fixed a security issue in `typed-function` allowing arbitrary code execution
in the JavaScript engine by creating a typed function with JavaScript code
in the name. Thanks Masato Kinugawa.
- Fixed a security issue where forbidden properties like constructor could be
replaced by using unicode characters when creating an object. No known exploit,
but could possibly allow arbitrary code execution. Thanks Masato Kinugawa.
## 2017-10-18, version 3.16.5
- Fixed #954: Functions `add` and `multiply` not working when
passing three or more arrays or matrices.
## 2017-10-01, version 3.16.4
- Fixed #948, #949: function `simplify` returning wrong results or
running into an infinite recursive loop. Thanks @ericman314.
- Fixed many small issues in the embedded docs. Thanks @Schnark.
## 2017-08-28, version 3.16.3
- Fixed #934: Wrong simplification of unary minus. Thanks @firepick1.
- Fixed #933: function `simplify` reordering operations. Thanks @firepick1.
- Fixed #930: function `isNaN` returning wrong result for complex
numbers having just one of their parts (re/im) being `NaN`.
- Fixed #929: `FibonacciHeap.isEmpty` returning wrong result.
## 2017-08-20, version 3.16.2
- Fixed #924: a regression in `simplify` not accepting the signature
`simplify(expr, rules, scope)` anymore. Thanks @firepick1.
- Fixed missing parenthesis when stringifying expressions containing
implicit multiplications (see #922). Thanks @FSMaxB.
## 2017-08-12, version 3.16.1
- For security reasons, type checking is now done in a more strict
way using functions like `isComplex(x)` instead of duck type checking
like `x && x.isComplex === true`.
- Fixed #915: No access to property "name".
- Fixed #901: Simplify units when calling `unit.toNumeric()`.
Thanks @AlexanderBeyn.
- Fixed `toString` of a parsed expression tree containing an
immediately invoked function assignment not being wrapped in
parenthesis (for example `(f(x) = x^2)(4)`).
## 2017-08-06, version 3.16.0
- Significant performance improvements in `math.simplify`.
Thanks @firepick1.
- Improved API for `math.simplify`, optionally pass a scope with
variables which are resolved, see #907. Thanks @firepick1.
- Fixed #912: math.js didn't work on IE10 anymore (regression
since 3.15.0).
## 2017-07-29, version 3.15.0
- Added support for the dollar character `$` in symbol names (see #895).
- Allow objects with prototypes as scope again in the expression parser,
this was disabled for security reasons some time ago. See #888, #899.
Thanks @ThomasBrierley.
- Fixed #846: Issues in the functions `map`, `forEach`, and `filter`
when used in the expression parser:
- Not being able to use a function assignment as inline expression
for the callback function.
- Not being able to pass an inline expression as callback for `map`
and `forEach`.
- Index and original array/matrix not passed in `map` and `filter`.
## 2017-07-05, version 3.14.2
- Upgraded to `fraction.js@4.0.2`
- Fixed #891 using BigNumbers not working in browser environments.
## 2017-06-30, version 3.14.1
- Reverted to `fraction.js@4.0.0`, there is an issue with `4.0.1`
in the browser.
## 2017-06-30, version 3.14.0
- Implemented set methods `setCartesian`, `setDifference`,
`setDistinct`, `setIntersect`, `setIsSubset`, `setPowerset`,
`setSize`. Thanks @Nekomajin42.
- Implemented method `toHTML` on nodes. Thanks @Nekomajin42.
- Implemented `compareNatural` and `sort([...], 'natural')`.
- Upgraded dependencies to the latest versions:
- `complex.js@2.0.4`
- `decimal.js@7.2.3`
- `fraction.js@4.0.1`
- `tiny-emitter@2.0.0`
- And all devDependencies.
- Fixed #865: `splitUnit` can now deal with round-off errors.
Thanks @ericman314.
- Fixed #876: incorrect definition for unit `erg`. Thanks @pjhampton.
- More informative error message when using single quotes instead of
double quotes around a string. Thanks @HarrySarson.
## 2017-05-27, version 3.13.3
- Fixed a bug in function `intersection` of line and plane.
Thanks @viclai.
- Fixed security vulnerabilities.
## 2017-05-26, version 3.13.2
- Disabled function `chain` inside the expression parser for security
reasons (it's not needed there anyway).
- Fixed #856: function `subset` not returning non-primitive scalars
from Arrays correctly. (like `math.eval('arr[1]', {arr: [math.bignumber(2)]})`.
- Fixed #861: physical constants not available in the expression parser.
## 2017-05-12, version 3.13.1
- Fixed creating units with an alias not working within the expression
parser.
- Fixed security vulnerabilities. Thanks Sam.
## 2017-05-12, version 3.13.0
- Command line application can now evaluate inline expressions
like `mathjs 1+2`. Thanks @slavaGanzin.
- Function `derivative` now supports `abs`. Thanks @tetslee.
- Function `simplify` now supports BigNumbers. Thanks @tetslee.
- Prevent against endless loops in `simplify`. Thanks @tetslee.
- Fixed #813: function `simplify` converting small numbers to inexact
Fractions. Thanks @tetslee.
- Fixed #838: Function `simplify` now supports constants like `e`.
Thanks @tetslee.
## 2017-05-05, version 3.12.3
- Fixed security vulnerabilities. Thanks Dan and Sam.
## 2017-04-30, version 3.12.2
- Added a rocket trajectory optimization example.
## 2017-04-24, version 3.12.1
- Fixed #804
- Improved handling of powers of `Infinity`. Thanks @HarrySarson.
- Fixed wrong formatting of complex NaN.
- Fixed security vulnerabilities in the expression parser.
Thanks Sam and Dan.
## 2017-04-17, version 3.12.0
- Implemented QR decomposition, function `math.qr`. Thanks @HarrySarson.
- Fixed #824: Calling `math.random()` freezes IE and node.js.
## 2017-04-08, version 3.11.5
- More security measures in the expression parser.
WARNING: the behavior of the expression parser is now more strict,
some undocumented features may not work any longer.
- Accessing and assigning properties is now only allowed on plain
objects, not on classes, arrays, and functions anymore.
- Accessing methods is restricted to a set of known, safe methods.
## 2017-04-03, version 3.11.4
- Fixed a security vulnerability in the expression parser. Thanks @xfix.
## 2017-04-03, version 3.11.3
- Fixed a security vulnerability in the expression parser. Thanks @xfix.
## 2017-04-03, version 3.11.2
- Fixed a security vulnerability in the expression parser. Thanks @xfix.
## 2017-04-02, version 3.11.1
- Fixed security vulnerabilities in the expression parser.
Thanks Joe Vennix and @xfix.
## 2017-04-02, version 3.11.0
- Implemented method Unit.toSI() to convert a unit to base SI units.
Thanks @ericman314.
- Fixed #821, #822: security vulnerabilities in the expression parser.
Thanks @comex and @xfix.
## 2017-03-31, version 3.10.3
- More security fixes related to the ones fixed in `v3.10.2`.
## 2017-03-31, version 3.10.2
- Fixed a security vulnerability in the expression parser allowing
execution of arbitrary JavaScript. Thanks @CapacitorSet and @denvit.
## 2017-03-26, version 3.10.1
- Fixed `xgcd` for negative values. Thanks @litmit.
- Fixed #807: function transform of existing functions not being removed when
overriding such a function.
## 2017-03-05, version 3.10.0
- Implemented function `reshape`. Thanks @patgrasso and @ericman314.
- Implemented configuration option `seedRandom` for deterministic random
numbers. Thanks @morsecodist.
- Small fixes in the docs. Thanks @HarrySarson.
- Dropped support for component package manager (which became deprecated about
one and a half year ago).
## 2017-02-22, version 3.9.3
- Fixed #797: issue with production builds of React Native projects.
- Fixed `math.round` not accepting inputs `NaN`, `Infinity`, `-Infinity`.
- Upgraded all dependencies.
## 2017-02-16, version 3.9.2
- Fixed #795: Parse error in case of a multi-line expression with just comments.
## 2017-02-06, version 3.9.1
- Fixed #789: Math.js not supporting conversion of `string` to `BigNumber`,
`Fraction`, or `Complex` number.
- Fixed #790: Expression parser did not pass function arguments of enclosing
functions via `scope` to functions having `rawArgs = true`.
- Small fixes in the docs. Thanks @HarrySarson.
## 2017-01-23, version 3.9.0
- Implemented support for algebra: powerful new functions `simplify` and
`derivative`. Thanks @ericman314, @tetslee, and @BigFav.
- Implemented Kronecker Product `kron`. Thanks @adamisntdead.
- Reverted `FunctionNode` not accepting a string as function name anymore.
- Fixed #765: `FunctionAssignmentNode.toString()` returning a string
incompatible with the function assignment syntax.
## 2016-12-15, version 3.8.1
- Implemented function `mad` (median absolute deviation). Thanks @ruhleder.
- Fixed #762: expression parser failing to invoke a function returned
by a function.
## 2016-11-18, version 3.8.0
- Functions `add` and `multiply` now accept more than two arguments. See #739.
- `OperatorNode` now supports more than two arguments. See #739. Thanks @FSMaxB.
- Implemented a method `Node.cloneDeep` for the expression nodes. See #745.
- Fixed a bug in `Node.clone()` not cloning implicit multiplication correctly.
Thanks @FSMaxB.
- Fixed #737: Improved algorithm determining the best prefix for units.
It will now retain the original unit like `1 cm` when close enough,
instead of returning `10 mm`. Thanks @ericman314.
- Fixed #732: Allow letter-like unicode characters like Ohm `\u2126`.
- Fixed #749: Units `rad`, `deg`, and `grad` can now have prefixes like `millirad`.
- Some fixes in the docs and comments of examples. Thanks @HarrySarson.
## 2016-11-05, version 3.7.0
- Implemented method `Node.equals(other)` for all nodes of the expression parser.
- Implemented BigNumber support in function `arg()`.
- Command Line Interface loads faster.
- Implicit conversions between Fractions and BigNumbers throw a neat error now
(See #710).
## 2016-10-21, version 3.6.0
- Implemented function `erf()`. THanks @patgrasso.
- Extended function `cross()` to support n-d vectors. Thanks @patgrasso.
- Extended function `pickRandom` with the option to pick multiple values from
an array and give the values weights: `pickRandom(possibles, number, weights)`.
Thanks @woylie.
- Parser now exposes test functions like `isAlpha` which can be replaced in
order to adjust the allowed characters in variables names (See #715).
- Fixed #727: Parser not throwing an error for invalid implicit multiplications
like `-2 2` and `2^3 4` (right after the second value of an operator).
- Fixed #688: Describe allowed variable names in the docs.
## 2016-09-21, version 3.5.3
- Some more fixes regarding numbers ending with a decimal mark (like `2.`).
## 2016-09-20, version 3.5.2
- Fixed numbers ending with a decimal mark (like `2.`) not being supported by
the parser, solved the underlying ambiguity in the parser. See #707, #711.
## 2016-09-12, version 3.5.1
- Removed a left over console.log statement. Thanks @eknkc.
## 2016-09-07, version 3.5.0
- Comments of expressions are are now stored in the parsed nodes. See #690.
- Fixed function `print` not accepting an Object with formatting options as
third parameter Thanks @ThomasBrierley.
- Fixed #707: The expression parser no longer accepts numbers ending with a dot
like `2.`.
## 2016-08-08, version 3.4.1
- Fixed broken bundle files (`dist/math.js`, `dist/math.min.js`).
- Fixed some layout issues in the function reference docs.
## 2016-08-07, version 3.4.0
- Implemented support for custom units using `createUnit`. Thanks @ericman314.
- Implemented function `splitUnits`. Thanks @ericman314.
- Implemented function `isPrime`. Thanks @MathBunny.
## 2016-07-05, version 3.3.0
- Implemented function `isNaN`.
- Function `math.filter` now passes three arguments to the callback function:
value, index, and array.
- Removed the check on the number of arguments from functions defined in the
expression parser (see #665).
- Fixed #665: functions `map`, `forEach`, and `filter` now invoke callbacks
which are a typed-function with the correct number of arguments.
## 2016-04-26, version 3.2.1
- Fixed #651: unable to perform calculations on "Unit-less" units.
- Fixed matrix.subset mutating the replacement matrix when unsqueezing it.
## 2016-04-16, version 3.2.0
- Implemented #644: method `Parser.getAll()` to retrieve all defined variables.
- Upgraded dependencies (decimal.js@5.0.8, fraction.js@3.3.1,
typed-function@0.10.4).
- Fixed #601: Issue with unnamed typed-functions by upgrading to
typed-function v0.10.4.
- Fixed #636: More strict `toTex` templates, reckon with number of arguments.
- Fixed #641: Bug in expression parser parsing implicit multiplication with
wrong precedence in specific cases.
- Fixed #645: Added documentation about `engineering` notation of function
`math.format`.
## 2016-04-03, version 3.1.4
- Using ES6 Math functions like `Math.sinh`, `Math.cbrt`, `Math.sign`, etc when
available.
- Fixed #631: unit aliases `weeks`, `months`, and `years` where missing.
- Fixed #632: problem with escaped backslashes at the end of strings.
- Fixed #635: `Node.toString` options where not passed to function arguments.
- Fixed #629: expression parser throws an error when passing a number with
decimal exponent instead of parsing them as implicit multiplication.
- Fixed #484, #555: inaccuracy of `math.sinh` for values between -1 and 1.
- Fixed #625: Unit `in` (`inch`) not always working due to ambiguity with
the operator `a in b` (alias of `a to b`).
## 2016-03-24, version 3.1.3
- Fix broken bundle.
## 2016-03-24, version 3.1.2
- Fix broken npm release.
## 2016-03-24, version 3.1.1
- Fixed #621: a bug in parsing implicit multiplications like `(2)(3)+4`.
- Fixed #623: `nthRoot` of zero with a negative root returned `0` instead of
`Infinity`.
- Throw an error when functions `min`, `max`, `mean`, or `median` are invoked
with multiple matrices as arguments (see #598).
## 2016-03-19, version 3.1.0
- Hide multiplication operator by default when outputting `toTex` and `toString`
for implicit multiplications. Implemented and option to output the operator.
- Implemented unit `kip` and alias `kips`. Thanks @hgupta9.
- Added support for prefixes for units `mol` and `mole`. Thanks @stu-blair.
- Restored support for implicit multiplications like `2(3+4)` and `(2+3)(4+5)`.
- Some improvements in the docs.
- Added automatic conversions from `boolean` and `null` to `Fraction`,
and conversions from `Fraction` to `Complex`.
## 2016-03-04, version 3.0.0
### breaking changes
- More restricted support for implicit multiplication in the expression
parser: `(...)(...)` is now evaluated as a function invocation,
and `[...][...]` as a matrix subset.
- Matrix multiplication no longer squeezes scalar outputs to a scalar value,
but leaves them as they are: a vector or matrix containing a single value.
See #529.
- Assignments in the expression parser now return the assigned value rather
than the created or updated object (see #533). Example:
```
A = eye(3)
A[1,1] = 2 # this assignment now returns 2 instead of A
```
- Expression parser now supports objects. This involves a refactoring and
extension in expression nodes:
- Implemented new node `ObjectNode`.
- Refactored `AssignmentNode`, `UpdateNode`, and `IndexNode` are refactored
into `AccessorNode`, `AssignmentNode`, and `IndexNode` having a different API.
- Upgraded the used BigNumber library `decimal.js` to v5. Replaced the
trigonometric functions of math.js with those provided in decimal.js v5.
This can give slightly different behavior qua round-off errors.
- Replaced the internal `Complex.js` class with the `complex.js` library
created by @infusion.
- Entries in a matrix (typically numbers, BigNumbers, Units, etc) are now
considered immutable, they are no longer copied when performing operations on
the entries, improving performance.
- Implemented nearly equal comparison for relational functions (`equal`,
`larger`, `smaller`, etc.) when using BigNumbers.
- Changed the casing of the configuration options `matrix` (`Array` or `Matrix`)
and `number` (`number`, `BigNumber`, `Fraction`) such that they now match
the type returned by `math.typeof`. Wrong casing gives a console warning but
will still work.
- Changed the default config value for `epsilon` from `1e-14` to `1e-12`,
see #561.
### non-breaking changes
- Extended function `pow` to return the real root for cubic roots of negative
numbers. See #525, #482, #567.
- Implemented support for JSON objects in the expression parser and the
function `math.format`.
- Function `math.fraction` now supports `BigNumber`, and function
`math.bignumber` now supports `Fraction`.
- Expression parser now allows function and/or variable assignments inside
accessors and conditionals, like `A[x=2]` or `a > 2 ? b="ok" : b="fail"`.
- Command line interface:
- Outputs the variable name of assignments.
- Fixed not rounding BigNumbers to 14 digits like numbers.
- Fixed non-working autocompletion of user defined variables.
- Reorganized and extended docs, added docs on classes and more. Thanks @hgupta9.
- Added new units `acre`, `hectare`, `torr`, `bar`, `mmHg`, `mmH2O`, `cmH2O`,
and added new aliases `acres`, `hectares`, `sqfeet`, `sqyard`, `sqmile`,
`sqmiles`, `mmhg`, `mmh2o`, `cmh2o`. Thanks @hgupta9.
- Fixed a bug in the toString method of an IndexNode.
- Fixed angle units `deg`, `rad`, `grad`, `cycle`, `arcsec`, and `arcmin` not
being defined as BigNumbers when configuring to use BigNumbers.
## 2016-02-03, version 2.7.0
- Added more unit aliases for time: `secs`, `mins`, `hr`, `hrs`. See #551.
- Added support for doing operations with mixed `Fractions` and `BigNumbers`.
- Fixed #540: `math.intersect()` returning null in some cases. Thanks @void42.
- Fixed #546: Cannot import BigNumber, Fraction, Matrix, Array.
Thanks @brettjurgens.
## 2016-01-08, version 2.6.0
- Implemented (complex) units `VA` and `VAR`.
- Implemented time units for weeks, months, years, decades, centuries, and
millennia. Thanks @owenversteeg.
- Implemented new notation `engineering` in function `math.format`.
Thanks @johnmarinelli.
- Fixed #523: In some circumstances, matrix subset returned a scalar instead
of the correct subset.
- Fixed #536: A bug in an internal method used for sparse matrices.
## 2015-12-05, version 2.5.0
- Implemented support for numeric types `Fraction` and `BigNumber` in units.
- Implemented new method `toNumeric` for units.
- Implemented new units `arcsec`, `arcsecond`, `arcmin`, `arcminute`.
Thanks @devdevdata222.
- Implemented new unit `Herts` (`Hz`). Thanks @SwamWithTurtles.
- Fixed #485: Scoping issue with variables both used globally as well as in a
function definition.
- Fixed: Function `number` didn't support `Fraction` as input.
## 2015-11-14, version 2.4.2
- Fixed #502: Issue with `format` in some JavaScript engines.
- Fixed #503: Removed trailing commas and the use of keyword `import` as
property, as this gives issues with old JavaScript engines.
## 2015-10-29, version 2.4.1
- Fixed #480: `nthRoot` not working on Internet Explorer (up to IE 11).
- Fixed #490: `nthRoot` returning an error for negative values like
`nthRoot(-2, 3)`.
- Fixed #489: an issue with initializing a sparse matrix without data.
Thanks @Retsam.
- Fixed: #493: function `combinations` did not throw an exception for
non-integer values of `k`.
- Fixed: function `import` did not override typed functions when the option
override was set true.
- Fixed: added functions `math.sparse` and `math.index` to the reference docs,
they where missing.
- Fixed: removed memoization from `gamma` and `factorial` functions, this
could blow up memory.
## 2015-10-09, version 2.4.0
- Added support in the expression parser for mathematical alphanumeric symbols
in the expression parser: unicode range \u{1D400} to \u{1D7FF} excluding
invalid code points.
- Extended function `distance` with more signatures. Thanks @kv-kunalvyas.
- Fixed a bug in functions `sin` and `cos`, which gave wrong results for
BigNumber integer values around multiples of tau (i.e. `sin(bignumber(7))`).
- Fixed value of unit `stone`. Thanks @Esvandiary for finding the error.
## 2015-09-19, version 2.3.0
- Implemented function `distance`. Thanks @devanp92.
- Implemented support for Fractions in function `lcm`. Thanks @infusion.
- Implemented function `cbrt` for numbers, complex numbers, BigNumbers, Units.
- Implemented function `hypot`.
- Upgraded to fraction.js v3.0.0.
- Fixed #450: issue with non sorted index in sparse matrices.
- Fixed #463, #322: inconsistent handling of implicit multiplication.
- Fixed #444: factorial of infinity not returning infinity.
## 2015-08-30, version 2.2.0
- Units with powers (like `m^2` and `s^-1`) now output with the best prefix.
- Implemented support for units to `abs`, `cube`, `sign`, `sqrt`, `square`.
Thanks @ericman314.
- Implemented function `catalan` (Combinatorics). Thanks @devanp92.
- Improved the `canDefineProperty` check to return false in case of IE8, which
has a broken implementation of `defineProperty`. Thanks @golmansax.
- Fixed function `to` not working in case of a simplified unit.
- Fixed #437: an issue with row swapping in `lup`, also affecting `lusolve`.
## 2015-08-12, version 2.1.1
- Fixed wrong values of the physical constants `speedOfLight`, `molarMassC12`,
and `magneticFluxQuantum`. Thanks @ericman314 for finding two of them.
## 2015-08-11, version 2.1.0
- Implemented derived units (like `110 km/h in m/s`). Thanks @ericman314.
- Implemented support for electric units. Thanks @ericman314.
- Implemented about 50 physical constants like `speedOfLight`, `gravity`, etc.
- Implemented function `kldivergence` (Kullback-Leibler divergence).
Thanks @saromanov.
- Implemented function `mode`. Thanks @kv-kunalvyas.
- Added support for unicode characters in the expression parser: greek letters
and latin letters with accents. See #265.
- Internal functions `Unit.parse` and `Complex.parse` now throw an Error
instead of returning null when passing invalid input.
## 2015-07-29, version 2.0.1
- Fixed operations with mixed fractions and numbers be converted to numbers
instead of fractions.
## 2015-07-28, version 2.0.0
- Large internal refactoring:
- performance improvements.
- allows to create custom bundles
- functions are composed using `typed-function` and are extensible
- Implemented support for fractions, powered by the library `fraction.js`.
- Implemented matrix LU decomposition with partial pivoting and a LU based
linear equations solver (functions `lup` and `lusolve`). Thanks @rjbaucells.
- Implemented a new configuration option `predictable`, which can be set to
true in order to ensure predictable function output types.
- Implemented function `intersect`. Thanks @kv-kunalvyas.
- Implemented support for adding `toTex` properties to custom functions.
Thanks @FSMaxB.
- Implemented support for complex values to `nthRoot`. Thanks @gangachris.
- Implemented util functions `isInteger`, `isNegative`, `isNumeric`,
`isPositive`, and `isZero`.
### breaking changes
- String input is now converted to numbers by default for all functions.
- Adding two strings will no longer concatenate them, but will convert the
strings to numbers and add them.
- Function `index` does no longer accept an array `[start, end, step]`, but
instead accepts an array with arbitrary index values. It also accepts
a `Range` object as input.
- Function `typeof` no longer returns lower case names, but now returns lower
case names for primitives (like `number`, `boolean`, `string`), and
upper-camel-case for non-primitives (like `Array`, `Complex`, `Function`).
- Function `import` no longer supports a module name as argument. Instead,
modules can be loaded using require: `math.import(require('module-name'))`.
- Function `import` has a new option `silent` to ignore errors, and throws
errors on duplicates by default.
- Method `Node.compile()` no longer needs `math` to be passed as argument.
- Reintroduced method `Node.eval([scope])`.
- Function `sum` now returns zero when input is an empty array. Thanks @FSMAxB.
- The size of Arrays is no longer validated. Matrices will validate this on
creation.
## 2015-07-12, version 1.7.1
- Fixed #397: Inaccuracies in nthRoot for very large values, and wrong results
for very small values. (backported from v2)
- Fixed #405: Parser throws error when defining a function in a multiline
expression.
## 2015-05-31, version 1.7.0
- Implemented function `quantileSeq` and `partitionSelect`. Thanks @BigFav.
- Implemented functions `stirlingS2`, `bellNumbers`, `composition`, and
`multinomial`. Thanks @devanp92.
- Improved the performance of `median` (see #373). Thanks @BigFav.
- Extended the command line interface with a `mode` option to output either
the expressions result, string representation, or tex representation.
Thanks @FSMaxB.
- Fixed #309: Function median mutating the input matrix. Thanks @FSMaxB.
- Fixed `Node.transform` not recursing over replaced parts of the
node tree (see #349).
- Fixed #381: issue in docs of `randomInt`.
## 2015-04-22, version 1.6.0
- Improvements in `toTex`. Thanks @FSMaxB.
- Fixed #328: `abs(0 + 0i)` evaluated to `NaN`.
- Fixed not being able to override lazy loaded constants.
## 2015-04-09, version 1.5.2
- Fixed #313: parsed functions did not handle recursive calls correctly.
- Fixed #251: binary prefix and SI prefix incorrectly used for byte. Now
following SI standards (`1 KiB == 1024 B`, `1 kB == 1000 B`).
- Performance improvements in parsed functions.
## 2015-04-08, version 1.5.1
- Fixed #316: a bug in rounding values when formatting.
- Fixed #317, #319: a bug in formatting negative values.
## 2015-03-28, version 1.5.0
- Added unit `stone` (6.35 kg).
- Implemented support for sparse matrices. Thanks @rjbaucells.
- Implemented BigNumber support for function `atan2`. Thanks @BigFav.
- Implemented support for custom LaTeX representations. Thanks @FSMaxB.
- Improvements and bug fixes in outputting parentheses in `Node.toString` and
`Node.toTex` functions. Thanks @FSMaxB.
- Fixed #291: function `format` sometimes returning exponential notation when
it should return a fixed notation.
## 2015-02-28, version 1.4.0
- Implemented trigonometric functions:
`acosh`, `acoth`, `acsch`, `asech`, `asinh`, `atanh`, `acot`, `acsc`, `asec`.
Thanks @BigFav.
- Added BigNumber support for functions: `cot`, `csc`, `sec`, `coth`,
`csch`, `sech`. Thanks @BigFav.
- Implemented support for serialization and deserialization of math.js data
types.
- Fixed the calculation of `norm()` and `abs()` for large complex numbers.
Thanks @rjbaucells.
- Fixed #281: improved formatting complex numbers. Round the real or imaginary
part to zero when the difference is larger than the configured precision.
## 2015-02-09, version 1.3.0
- Implemented BigNumber implementations of most trigonometric functions: `sin`,
`cos`, `tan`, `asin`, `acos`, `atan`, `cosh`, `sinh`, `tanh`. Thanks @BigFav.
- Implemented function `trace`. Thanks @pcorey.
- Faster loading of BigNumber configuration with a high precision by lazy
loading constants like `pi` and `e`.
- Fixed constants `NaN` and `Infinity` not being BigNumber objects when
BigNumbers are configured.
- Fixed missing parentheses in the `toTex` representation of function
`permutations`.
- Some minor fixes in the docs. Thanks @KenanY.
## 2014-12-25, version 1.2.0
- Support for bitwise operations `bitAnd`, `bitNot`, `bitOr`, `bitXor`,
`leftShift`, `rightArithShift`, and `rightLogShift`. Thanks @BigFav.
- Support for boolean operations `and`, `not`, `or`, `xor`. Thanks @BigFav.
- Support for `gamma` function. Thanks @BigFav.
- Converting a unit without value will now result in a unit *with* value,
i.e. `inch in cm` will return `2.54 cm` instead of `cm`.
- Improved accuracy of `sinh` and complex `cos` and `sin`. Thanks @pavpanchekha.
- Renamed function `select` to `chain`. The old function `select` will remain
functional until math.js v2.0.
- Upgraded to decimal.js v4.0.1 (BigNumber library).
## 2014-11-22, version 1.1.1
- Fixed Unit divided by Number returning zero.
- Fixed BigNumber downgrading to Number for a negative base in `pow`.
- Fixed some typos in error messaging (thanks @andy0130tw) and docs.
## 2014-11-15, version 1.1.0
- Implemented functions `dot` (dot product), `cross` (cross product), and
`nthRoot`.
- Officially opened up the API of expression trees:
- Documented the API.
- Implemented recursive functions `clone`, `map`, `forEach`, `traverse`,
`transform`, and `filter` for expression trees.
- Parameter `index` in the callbacks of `map` and `forEach` are now cloned
for every callback.
- Some internal refactoring inside nodes to make the API consistent:
- Renamed `params` to `args` and vice versa to make things consistent.
- Renamed `Block.nodes` to `Block.blocks`.
- `FunctionNode` now has a `name: string` instead of a `symbol: SymbolNode`.
- Changed constructor of `RangeNode` to
`new RangeNode(start: Node, end: Node [, step: Node])`.
- Nodes for a `BlockNode` must now be passed via the constructor instead
of via a function `add`.
- Fixed `2e` giving a syntax error instead of being parsed as `2 * e`.
## 2014-09-12, version 1.0.1
- Disabled array notation for ranges in a matrix index in the expression parser
(it is confusing and redundant there).
- Fixed a regression in the build of function subset not being able to return
a scalar.
- Fixed some missing docs and broken links in the docs.
## 2014-09-04, version 1.0.0
- Implemented a function `filter(x, test)`.
- Removed `math.distribution` for now, needs some rethinking.
- `math.number` can convert units to numbers (requires a second argument)
- Fixed some precedence issues with the range and conversion operators.
- Fixed an zero-based issue when getting a matrix subset using an index
containing a matrix.
## 2014-08-21, version 0.27.0
- Implemented functions `sort(x [, compare])` and `flatten(x)`.
- Implemented support for `null` in all functions.
- Implemented support for "rawArgs" functions in the expression parser. Raw
functions are invoked with unevaluated parameters (nodes).
- Expressions in the expression parser can now be spread over multiple lines,
like '2 +\n3'.
- Changed default value of the option `wrap` of function `math.import` to false.
- Changed the default value for new entries in a resized matrix when to zero.
To leave new entries uninitialized, use the new constant `math.uninitialized`
as default value.
- Renamed transform property from `__transform__` to `transform`, and documented
the transform feature.
- Fixed a bug in `math.import` not applying options when passing a module name.
- A returned matrix subset is now only squeezed when the `index` consists of
scalar values, and no longer for ranges resolving into a single value.
## 2014-08-03, version 0.26.0
- A new instance of math.js can no longer be created like `math([options])`,
to prevent side effects from math being a function instead of an object.
Instead, use the function `math.create([options])` to create a new instance.
- Implemented `BigNumber` support for all constants: `pi`, `tau`, `e`, `phi`,
`E`, `LN2`, `LN10`, `LOG2E`, `LOG10E`, `PI`, `SQRT1_2`, and `SQRT2`.
- Implemented `BigNumber` support for functions `gcd`, `xgcd`, and `lcm`.
- Fixed function `gxcd` returning an Array when math.js was configured
as `{matrix: 'matrix'}`.
- Multi-line expressions now return a `ResultSet` instead of an `Array`.
- Implemented transforms (used right now to transform one-based indices to
zero-based for expressions).
- When used inside the expression parser, functions `concat`, `min`, `max`,
and `mean` expect an one-based dimension number.
- Functions `map` and `forEach` invoke the callback with one-based indices
when used from within the expression parser.
- When adding or removing dimensions when resizing a matrix, the dimensions
are added/removed from the inner side (right) instead of outer side (left).
- Improved index out of range errors.
- Fixed function `concat` not accepting a `BigNumber` for parameter `dim`.
- Function `squeeze` now squeezes both inner and outer singleton dimensions.
- Output of getting a matrix subset is not automatically squeezed anymore
except for scalar output.
- Renamed `FunctionNode` to `FunctionAssignmentNode`, and renamed `ParamsNode`
to `FunctionNode` for more clarity.
- Fixed broken auto completion in CLI.
- Some minor fixes.
## 2014-07-01, version 0.25.0
- The library now immediately returns a default instance of mathjs, there is
no need to instantiate math.js in a separate step unless one ones to set
configuration options:
// instead of:
var mathjs = require('mathjs'), // load math.js
math = mathjs(); // create an instance
// just do:
var math = require('mathjs');
- Implemented support for implicit multiplication, like `math.eval('2a', {a:3})`
and `math.eval('(2+3)(1-3)')`. This changes behavior of matrix indexes as
well: an expression like `[...][...]` is not evaluated as taking a subset of
the first matrix, but as an implicit multiplication of two matrices.
- Removed utility function `ifElse`. This function is redundant now the
expression parser has a conditional operator