From ecef173a249aeea226f757a76f8da2ad445e60eb Mon Sep 17 00:00:00 2001 From: jos Date: Sat, 17 Aug 2019 22:14:59 +0200 Subject: [PATCH] Publish mathjs@6.1.0 --- docs/custom_bundling.md | 2 +- docs/expressions/security.md | 2 +- docs/getting_started.md | 2 +- docs/reference/functions.md | 1 + docs/reference/functions/combinations.md | 1 + .../functions/combinationsWithRep.md | 47 + docs/reference/functions/factorial.md | 1 + docs/reference/functions/permutations.md | 1 + download.md | 12 +- examples/advanced/custom_argument_parsing.js | 2 +- .../advanced/custom_argument_parsing.js.md | 2 +- .../advanced/custom_relational_functions.js | 62 + .../custom_relational_functions.js.md | 76 + examples/advanced/more_secure_eval.js | 12 +- examples/advanced/more_secure_eval.js.md | 12 +- examples/advanced/web_server/index.md | 2 +- examples/advanced/web_server/math_worker.js | 2 +- examples/browser/angle_configuration.html | 2 +- examples/browser/angle_configuration.html.md | 2 +- examples/browser/basic_usage.html | 2 +- examples/browser/basic_usage.html.md | 2 +- examples/browser/currency_conversion.html | 2 +- examples/browser/currency_conversion.html.md | 2 +- examples/browser/custom_separators.html | 2 +- examples/browser/custom_separators.html.md | 2 +- examples/browser/plot.html | 2 +- examples/browser/plot.html.md | 2 +- .../browser/pretty_printing_with_mathjax.html | 2 +- .../pretty_printing_with_mathjax.html.md | 2 +- examples/browser/printing_html.html | 2 +- examples/browser/printing_html.html.md | 2 +- examples/browser/requirejs_loading.html | 2 +- examples/browser/requirejs_loading.html.md | 2 +- .../rocket_trajectory_optimization.html | 2 +- .../rocket_trajectory_optimization.html.md | 2 +- examples/browser/webworkers/index.md | 2 +- examples/browser/webworkers/worker.js | 2 +- examples/expressions.js | 6 +- examples/expressions.js.md | 6 +- examples/index.md | 1 + examples/objects.js | 2 +- examples/objects.js.md | 2 +- history.md | 13 +- js/lib/math.js | 4772 +++++++++-------- js/lib/math.min.js | 8 +- js/lib/math.min.map | 2 +- package-lock.json | 36 +- package.json | 6 +- 48 files changed, 2717 insertions(+), 2416 deletions(-) create mode 100644 docs/reference/functions/combinationsWithRep.md create mode 100644 examples/advanced/custom_relational_functions.js create mode 100644 examples/advanced/custom_relational_functions.js.md diff --git a/docs/custom_bundling.md b/docs/custom_bundling.md index 9a23d2e13..202729dcb 100644 --- a/docs/custom_bundling.md +++ b/docs/custom_bundling.md @@ -8,7 +8,7 @@ Math.js is a large library containing many data types and functions. It is well possible that you only need a small portion of the library. Math.js allows for picking just the functions and data types you need. This gives faster load times and smaller browser bundles. Math.js uses -ES6 modules, and creating small bundles using tree-shaking works out of +ES modules, and creating small bundles using tree-shaking works out of the box when using Webpack for example. This page describes: diff --git a/docs/expressions/security.md b/docs/expressions/security.md index 9234aa11c..a312566a7 100644 --- a/docs/expressions/security.md +++ b/docs/expressions/security.md @@ -15,7 +15,7 @@ the code server side. A user could try to inject malicious JavaScript code via the expression parser. The expression parser of mathjs offers a sandboxed environment to execute expressions which should make this impossible. It's possible -though that there are unknown security vulnerabilties, so it's important +though that there are unknown security vulnerabilities, so it's important to be careful, especially when allowing server side execution of arbitrary expressions. diff --git a/docs/getting_started.md b/docs/getting_started.md index e95ef4f57..e12c51057 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -25,7 +25,7 @@ and instantiated. When creating an instance, one can optionally provide configuration options as described in [Configuration](core/configuration.html). -

ES6 modules #

+

ES modules #

Load the functions you need and use them: diff --git a/docs/reference/functions.md b/docs/reference/functions.md index e65b98cd5..7ef76f50d 100644 --- a/docs/reference/functions.md +++ b/docs/reference/functions.md @@ -180,6 +180,7 @@ Function | Description Function | Description ---- | ----------- [math.combinations(n, k)](functions/combinations.html) | Compute the number of ways of picking `k` unordered outcomes from `n` possibilities. +[math.combinationsWithRep(n, k)](functions/combinationsWithRep.html) | Compute the number of ways of picking `k` unordered outcomes from `n` possibilities, allowing individual outcomes to be repeated more than once. [math.factorial(n)](functions/factorial.html) | Compute the factorial of a value Factorial only supports an integer value as argument. [math.gamma(n)](functions/gamma.html) | Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values. [math.kldivergence(x, y)](functions/kldivergence.html) | Calculate the Kullback-Leibler (KL) divergence between two distributions. diff --git a/docs/reference/functions/combinations.md b/docs/reference/functions/combinations.md index 72c965fcb..0198945a2 100644 --- a/docs/reference/functions/combinations.md +++ b/docs/reference/functions/combinations.md @@ -42,5 +42,6 @@ math.combinations(7, 5) // returns 21

See also #

+[combinationsWithRep](combinationsWithRep.html), [permutations](permutations.html), [factorial](factorial.html) diff --git a/docs/reference/functions/combinationsWithRep.md b/docs/reference/functions/combinationsWithRep.md new file mode 100644 index 000000000..049dd9249 --- /dev/null +++ b/docs/reference/functions/combinationsWithRep.md @@ -0,0 +1,47 @@ +--- +layout: default +--- + + + +

Function combinationsWithRep #

+ +Compute the number of ways of picking `k` unordered outcomes from `n` +possibilities, allowing individual outcomes to be repeated more than once. + +CombinationsWithRep only takes integer arguments. +The following condition must be enforced: k <= n + k -1. + + +

Syntax #

+ +```js +math.combinationsWithRep(n, k) +``` + +

Parameters #

+ +Parameter | Type | Description +--------- | ---- | ----------- +`n` | number | BigNumber | Total number of objects in the set +`k` | number | BigNumber | Number of objects in the subset + +

Returns #

+ +Type | Description +---- | ----------- +number | BigNumber | Number of possible combinations with replacement. + + +

Examples #

+ +```js +math.combinationsWithRep(7, 5) // returns 462 +``` + + +

See also #

+ +[combinations](combinations.html), +[permutations](permutations.html), +[factorial](factorial.html) diff --git a/docs/reference/functions/factorial.md b/docs/reference/functions/factorial.md index 354d58765..cbeaa6b27 100644 --- a/docs/reference/functions/factorial.md +++ b/docs/reference/functions/factorial.md @@ -42,5 +42,6 @@ math.factorial(3) // returns 6

See also #

[combinations](combinations.html), +[combinationsWithRep](combinationsWithRep.html), [gamma](gamma.html), [permutations](permutations.html) diff --git a/docs/reference/functions/permutations.md b/docs/reference/functions/permutations.md index 705c6a034..f9d582194 100644 --- a/docs/reference/functions/permutations.md +++ b/docs/reference/functions/permutations.md @@ -45,4 +45,5 @@ math.permutations(5, 3) // 60

See also #

[combinations](combinations.html), +[combinationsWithRep](combinationsWithRep.html), [factorial](factorial.html) diff --git a/download.md b/download.md index 1a654c49b..28cdcc9f5 100644 --- a/download.md +++ b/download.md @@ -29,7 +29,7 @@ Math.js can be downloaded or linked from various content delivery networks: unpkg - https://unpkg.com/mathjs@6.0.3/ + https://unpkg.com/mathjs@6.1.0/ cdnjs @@ -47,18 +47,18 @@ Here some direct download links from [unpkg](https://unpkg.com):
- - Development (version 6.0.3) + + Development (version 6.1.0) - 1827 kB, uncompressed with comments + 1829 kB, uncompressed with comments
- - Production (version 6.0.3) + + Production (version 6.1.0) diff --git a/examples/advanced/custom_argument_parsing.js b/examples/advanced/custom_argument_parsing.js index 752eb7f98..7b66e85f9 100644 --- a/examples/advanced/custom_argument_parsing.js +++ b/examples/advanced/custom_argument_parsing.js @@ -93,6 +93,6 @@ console.log(math.integrate(f, 0, 1)) // outputs 0.6667254718034714 console.log(math.evaluate('integrate(x^0.5, x, 0, 1)')) // outputs 0.6667254718034714 // use the function via the expression parser (2) -let scope = {} +const scope = {} math.evaluate('f(x) = 2 * x', scope) console.log(math.evaluate('integrate(f(x), x, 0, 2)', scope)) // outputs 4.000000000000003 diff --git a/examples/advanced/custom_argument_parsing.js.md b/examples/advanced/custom_argument_parsing.js.md index 5f9281663..0f05a5c09 100644 --- a/examples/advanced/custom_argument_parsing.js.md +++ b/examples/advanced/custom_argument_parsing.js.md @@ -102,7 +102,7 @@ console.log(math.integrate(f, 0, 1)) // outputs 0.6667254718034714 console.log(math.evaluate('integrate(x^0.5, x, 0, 1)')) // outputs 0.6667254718034714 // use the function via the expression parser (2) -let scope = {} +const scope = {} math.evaluate('f(x) = 2 * x', scope) console.log(math.evaluate('integrate(f(x), x, 0, 2)', scope)) // outputs 4.000000000000003 diff --git a/examples/advanced/custom_relational_functions.js b/examples/advanced/custom_relational_functions.js new file mode 100644 index 000000000..fbcb2ab96 --- /dev/null +++ b/examples/advanced/custom_relational_functions.js @@ -0,0 +1,62 @@ +const { create, all, factory } = require('../..') + +// First let's see what the default behavior is: +// strings are compared by their numerical value +console.log('default (compare string by their numerical value)') +const { evaluate } = create(all) +evaluateAndLog(evaluate, '2 < 10') // true +evaluateAndLog(evaluate, '"2" < "10"') // true +evaluateAndLog(evaluate, '"a" == "b"') // Error: Cannot convert "a" to a number +evaluateAndLog(evaluate, '"a" == "a"') // Error: Cannot convert "a" to a number +console.log('') + +// Suppose we want different behavior for string comparisons. To achieve +// this we can replace the factory functions for all relational functions +// with our own. In this simple example we use the JavaScript implementation. +console.log('custom (compare strings lexically)') + +const allWithCustomFunctions = { + ...all, + + createEqual: factory('equal', [], () => function equal (a, b) { + return a === b + }), + + createUnequal: factory('unequal', [], () => function unequal (a, b) { + return a !== b + }), + + createSmaller: factory('smaller', [], () => function smaller (a, b) { + return a < b + }), + + createSmallerEq: factory('smallerEq', [], () => function smallerEq (a, b) { + return a <= b + }), + + createLarger: factory('larger', [], () => function larger (a, b) { + return a > b + }), + + createLargerEq: factory('largerEq', [], () => function largerEq (a, b) { + return a >= b + }), + + createCompare: factory('compare', [], () => function compare (a, b) { + return a > b ? 1 : a < b ? -1 : 0 + }) +} +const evaluateCustom = create(allWithCustomFunctions).evaluate +evaluateAndLog(evaluateCustom, '2 < 10') // true +evaluateAndLog(evaluateCustom, '"2" < "10"') // false +evaluateAndLog(evaluateCustom, '"a" == "b"') // false +evaluateAndLog(evaluateCustom, '"a" == "a"') // true + +// helper function to evaluate an expression and print the results +function evaluateAndLog (evaluate, expression) { + try { + console.log(expression, evaluate(expression)) + } catch (err) { + console.error(expression, err.toString()) + } +} diff --git a/examples/advanced/custom_relational_functions.js.md b/examples/advanced/custom_relational_functions.js.md new file mode 100644 index 000000000..d82d46882 --- /dev/null +++ b/examples/advanced/custom_relational_functions.js.md @@ -0,0 +1,76 @@ +--- +layout: default +--- + +# Custom relational functions + +File: [custom_relational_functions.js](custom_relational_functions.js) (click for a live demo) + +```js +const { create, all, factory } = require('../..') + +// First let's see what the default behavior is: +// strings are compared by their numerical value +console.log('default (compare string by their numerical value)') +const { evaluate } = create(all) +evaluateAndLog(evaluate, '2 < 10') // true +evaluateAndLog(evaluate, '"2" < "10"') // true +evaluateAndLog(evaluate, '"a" == "b"') // Error: Cannot convert "a" to a number +evaluateAndLog(evaluate, '"a" == "a"') // Error: Cannot convert "a" to a number +console.log('') + +// Suppose we want different behavior for string comparisons. To achieve +// this we can replace the factory functions for all relational functions +// with our own. In this simple example we use the JavaScript implementation. +console.log('custom (compare strings lexically)') + +const allWithCustomFunctions = { + ...all, + + createEqual: factory('equal', [], () => function equal (a, b) { + return a === b + }), + + createUnequal: factory('unequal', [], () => function unequal (a, b) { + return a !== b + }), + + createSmaller: factory('smaller', [], () => function smaller (a, b) { + return a < b + }), + + createSmallerEq: factory('smallerEq', [], () => function smallerEq (a, b) { + return a <= b + }), + + createLarger: factory('larger', [], () => function larger (a, b) { + return a > b + }), + + createLargerEq: factory('largerEq', [], () => function largerEq (a, b) { + return a >= b + }), + + createCompare: factory('compare', [], () => function compare (a, b) { + return a > b ? 1 : a < b ? -1 : 0 + }) +} +const evaluateCustom = create(allWithCustomFunctions).evaluate +evaluateAndLog(evaluateCustom, '2 < 10') // true +evaluateAndLog(evaluateCustom, '"2" < "10"') // false +evaluateAndLog(evaluateCustom, '"a" == "b"') // false +evaluateAndLog(evaluateCustom, '"a" == "a"') // true + +// helper function to evaluate an expression and print the results +function evaluateAndLog (evaluate, expression) { + try { + console.log(expression, evaluate(expression)) + } catch (err) { + console.error(expression, err.toString()) + } +} + +``` + + + diff --git a/examples/advanced/more_secure_eval.js b/examples/advanced/more_secure_eval.js index 1d89a85ec..46329ba7c 100644 --- a/examples/advanced/more_secure_eval.js +++ b/examples/advanced/more_secure_eval.js @@ -24,12 +24,12 @@ const math = create(all) const limitedEvaluate = math.evaluate math.import({ - 'import': function () { throw new Error('Function import is disabled') }, - 'createUnit': function () { throw new Error('Function createUnit is disabled') }, - 'evaluate': function () { throw new Error('Function evaluate is disabled') }, - 'parse': function () { throw new Error('Function parse is disabled') }, - 'simplify': function () { throw new Error('Function simplify is disabled') }, - 'derivative': function () { throw new Error('Function derivative is disabled') } + import: function () { throw new Error('Function import is disabled') }, + createUnit: function () { throw new Error('Function createUnit is disabled') }, + evaluate: function () { throw new Error('Function evaluate is disabled') }, + parse: function () { throw new Error('Function parse is disabled') }, + simplify: function () { throw new Error('Function simplify is disabled') }, + derivative: function () { throw new Error('Function derivative is disabled') } }, { override: true }) console.log(limitedEvaluate('sqrt(16)')) // Ok, 4 diff --git a/examples/advanced/more_secure_eval.js.md b/examples/advanced/more_secure_eval.js.md index f96557ce0..faa1b9338 100644 --- a/examples/advanced/more_secure_eval.js.md +++ b/examples/advanced/more_secure_eval.js.md @@ -33,12 +33,12 @@ const math = create(all) const limitedEvaluate = math.evaluate math.import({ - 'import': function () { throw new Error('Function import is disabled') }, - 'createUnit': function () { throw new Error('Function createUnit is disabled') }, - 'evaluate': function () { throw new Error('Function evaluate is disabled') }, - 'parse': function () { throw new Error('Function parse is disabled') }, - 'simplify': function () { throw new Error('Function simplify is disabled') }, - 'derivative': function () { throw new Error('Function derivative is disabled') } + import: function () { throw new Error('Function import is disabled') }, + createUnit: function () { throw new Error('Function createUnit is disabled') }, + evaluate: function () { throw new Error('Function evaluate is disabled') }, + parse: function () { throw new Error('Function parse is disabled') }, + simplify: function () { throw new Error('Function simplify is disabled') }, + derivative: function () { throw new Error('Function derivative is disabled') } }, { override: true }) console.log(limitedEvaluate('sqrt(16)')) // Ok, 4 diff --git a/examples/advanced/web_server/index.md b/examples/advanced/web_server/index.md index 2e9600456..5488bec5f 100644 --- a/examples/advanced/web_server/index.md +++ b/examples/advanced/web_server/index.md @@ -15,7 +15,7 @@ const math = create(all) function noImport () { throw new Error('function import is disabled.') } -math.import({ 'import': noImport }, { override: true }) +math.import({ import: noImport }, { override: true }) /** * Evaluate an expression diff --git a/examples/advanced/web_server/math_worker.js b/examples/advanced/web_server/math_worker.js index 878d2ac3f..2c7c0baa4 100644 --- a/examples/advanced/web_server/math_worker.js +++ b/examples/advanced/web_server/math_worker.js @@ -6,7 +6,7 @@ const math = create(all) function noImport () { throw new Error('function import is disabled.') } -math.import({ 'import': noImport }, { override: true }) +math.import({ import: noImport }, { override: true }) /** * Evaluate an expression diff --git a/examples/browser/angle_configuration.html b/examples/browser/angle_configuration.html index 044163290..2e49734a6 100644 --- a/examples/browser/angle_configuration.html +++ b/examples/browser/angle_configuration.html @@ -15,7 +15,7 @@ } - + diff --git a/examples/browser/angle_configuration.html.md b/examples/browser/angle_configuration.html.md index 85637ce75..ffb5c9248 100644 --- a/examples/browser/angle_configuration.html.md +++ b/examples/browser/angle_configuration.html.md @@ -24,7 +24,7 @@ File: [angle_configuration.html](angle_configuration.html) (click for a live dem } - + diff --git a/examples/browser/basic_usage.html b/examples/browser/basic_usage.html index 1e57eb9a1..1b161980c 100644 --- a/examples/browser/basic_usage.html +++ b/examples/browser/basic_usage.html @@ -3,7 +3,7 @@ math.js | basic usage - + diff --git a/examples/browser/basic_usage.html.md b/examples/browser/basic_usage.html.md index 918e83d6b..17577dac7 100644 --- a/examples/browser/basic_usage.html.md +++ b/examples/browser/basic_usage.html.md @@ -12,7 +12,7 @@ File: [basic_usage.html](basic_usage.html) (click for a live demo) math.js | basic usage - + diff --git a/examples/browser/currency_conversion.html b/examples/browser/currency_conversion.html index 56d10d0a8..1365e8b88 100644 --- a/examples/browser/currency_conversion.html +++ b/examples/browser/currency_conversion.html @@ -4,7 +4,7 @@ math.js | currency conversion - + - + diff --git a/examples/browser/custom_separators.html.md b/examples/browser/custom_separators.html.md index 7a49a0ffe..60f37e1b2 100644 --- a/examples/browser/custom_separators.html.md +++ b/examples/browser/custom_separators.html.md @@ -24,7 +24,7 @@ File: [custom_separators.html](custom_separators.html) (click for a live demo) } - + diff --git a/examples/browser/plot.html b/examples/browser/plot.html index f52a1385d..170218224 100644 --- a/examples/browser/plot.html +++ b/examples/browser/plot.html @@ -3,7 +3,7 @@ math.js | plot - + diff --git a/examples/browser/plot.html.md b/examples/browser/plot.html.md index 23581080c..8d6e50b5f 100644 --- a/examples/browser/plot.html.md +++ b/examples/browser/plot.html.md @@ -12,7 +12,7 @@ File: [plot.html](plot.html) (click for a live demo) math.js | plot - + diff --git a/examples/browser/pretty_printing_with_mathjax.html b/examples/browser/pretty_printing_with_mathjax.html index 7a3266a92..a0eea44fc 100644 --- a/examples/browser/pretty_printing_with_mathjax.html +++ b/examples/browser/pretty_printing_with_mathjax.html @@ -4,7 +4,7 @@ math.js | pretty printing with MathJax - +