20533
/*************************************
20534
* Trigonometric functions *
20535
*************************************/
20538
* Calculate the arccosine or arcsecant of x
20540
* acos(x) = 2*atan(sqrt(1-x^2)/(1+x))
20542
* asec(x) = acos(1/x)
20544
* @param {BigNumber} x
20545
* @param {DecimalFactory} Big current BigNumber constructor
20546
* @param {Boolean} reciprocal is sec
20547
* @returns {BigNumber} arccosine or arcsecant of x
20549
exports.arccos_arcsec = function (x, Big, reciprocal) {
20550
var precision = Big.precision;
20552
if (x.abs().lt(Big.ONE)) {
20553
throw new Error('asec() only has non-complex values for |x| >= 1.');
20555
} else if (x.abs().gt(Big.ONE)) {
20556
throw new Error('acos() only has non-complex values for |x| <= 1.');
20559
return exports.pi(precision);
20562
Big.config({precision: precision + 4});
20565
x = Big.ONE.div(x);
20568
var acos = exports.arctan_arccot(Big.ONE.minus(x.times(x)).sqrt()
20569
.div(x.plus(Big.ONE)), Big).times(2);
20571
Big.config({precision: precision});
20572
return acos.toDP(precision - 1);
20576
* Calculate the arcsine or arccosecant of x
20578
* @param {BigNumber} x
20579
* @param {DecimalFactory} Big current BigNumber constructor
20580
* @param {Boolean} reciprocal is csc
20581
* @returns {BigNumber} arcsine or arccosecant of x
20583
exports.arcsin_arccsc = function (x, Big, reciprocal) {
20585
return new Big(NaN);
20588
var precision = Big.precision;
20589
var absX = x.abs();
20591
if (absX.lt(Big.ONE)) {
20592
throw new Error('acsc() only has non-complex values for |x| >= 1.');
20595
Big.config({precision: precision + 2});
20596
x = Big.ONE.div(x);
20597
Big.config({precision: precision});
20600
} else if (absX.gt(Big.ONE)) {
20601
throw new Error('asin() only has non-complex values for |x| <= 1.');
20604
// Get x below 0.58
20605
if (absX.gt(0.8)) {
20606
Big.config({precision: precision + 4});
20608
// arcsin(x) = sign(x)*(Pi/2 - arcsin(sqrt(1 - x^2)))
20610
var halfPi = exports.pi(precision + 4).div(2);
20611
x = halfPi.minus(exports.arcsin_arccsc(Big.ONE.minus(x.times(x)).sqrt(), Big));
20614
x.constructor = Big;
20615
Big.config({precision: precision});
20616
return x.toDP(precision - 1);
20618
var wasReduced = absX.gt(0.58);
20620
Big.config({precision: precision + 8});
20622
// arcsin(x) = 2*arcsin(x / (sqrt(2)*sqrt(sqrt(1 - x^2) + 1)))
20623
x = x.div(new Big(2).sqrt().times(Big.ONE.minus(x.times(x)).sqrt()
20624
.plus(Big.ONE).sqrt()));
20626
Big.config({precision: precision});
20629
// Avoid overhead of Newton's Method if feasible
20630
var ret = (precision <= 60 || ((x.dp() <= Math.log(precision)) && x.lt(0.05)))
20631
? arcsin_taylor(x, precision)
20632
: arcsin_newton(x, Big);
20635
return ret.times(2);
20641
* Calculate the arctangent or arccotangent of x
20643
* @param {BigNumber} x
20644
* @param {DecimalFactory} Big current BigNumber constructor
20645
* @param {Boolean} reciprocal is cot
20646
* @returns {BigNumber} arctangent or arccotangent of x
20648
exports.arctan_arccot = function (x, Big, reciprocal) {
20650
return new Big(NaN);
20652
if ((!reciprocal && x.isZero()) || (reciprocal && !x.isFinite())) {
20656
var precision = Big.precision;
20657
if ((!reciprocal && !x.isFinite()) || (reciprocal && x.isZero())) {
20658
var halfPi = exports.pi(precision + 2).div(2).toDP(precision - 1);
20664
Big.config({precision: precision + 4});
20667
x = Big.ONE.div(x);
20670
var absX = x.abs();
20671
if (absX.lte(0.875)) {
20672
var ret = arctan_taylor(x);
20674
ret.constructor = Big;
20675
Big.config({precision: precision});
20676
return ret.toDP(Big.precision - 1);
20678
if (absX.gte(1.143)) {
20679
// arctan(x) = sign(x)*((PI / 2) - arctan(1 / |x|))
20680
var halfPi = exports.pi(precision + 4).div(2);
20681
var ret = halfPi.minus(arctan_taylor(Big.ONE.div(absX)));
20684
ret.constructor = Big;
20685
Big.config({precision: precision});
20686
return ret.toDP(Big.precision - 1);
20689
// arctan(x) = arcsin(x / [sqrt(1 + x^2)])
20690
x = x.div(x.times(x).plus(1).sqrt());
20692
Big.config({precision: precision});
20693
return exports.arcsin_arccsc(x, Big);
20697
* Calculate the hyperbolic arccosine, arcsine, arcsecant, or arccosecant of x
20699
* acosh(x) = ln(x + sqrt(x^2 - 1))
20701
* asinh(x) = ln(x + sqrt(x^2 + 1))
20703
* asech(x) = acosh(1 / x)
20705
* acsch(x) = asinh(1 / x)
20707
* @param {BigNumber} x
20708
* @param {DecimalFactory} Big current BigNumber constructor
20709
* @param {Boolean} mode sine function if true, cosine function if false
20710
* @param {Boolean} reciprocal is sec or csc
20711
* @returns {BigNumber} hyperbolic arccosine, arcsine, arcsecant, or arccosecant of x
20713
exports.acosh_asinh_asech_acsch = function (x, Big, mode, reciprocal) {
20715
return new Big(NaN);
20717
if (reciprocal && x.isZero()) {
20718
return new Big(Infinity);
20722
if (x.isNegative() || x.gt(Big.ONE)) {
20723
throw new Error('asech() only has non-complex values for 0 <= x <= 1.');
20725
} else if (x.lt(Big.ONE)) {
20726
throw new Error('acosh() only has non-complex values for x >= 1.');
20730
var precision = Big.precision;
20731
Big.config({precision: precision + 4});
20733
var y = new Big(x);
20734
y.constructor = Big;
20737
y = Big.ONE.div(y);
20740
var x2PlusOrMinus = (mode) ? y.times(y).plus(Big.ONE) : y.times(y).minus(Big.ONE);
20741
var ret = y.plus(x2PlusOrMinus.sqrt()).ln();
20743
Big.config({precision: precision});
20744
return new Big(ret.toPrecision(precision));
20748
* Calculate the hyperbolic arctangent or arccotangent of x
20750
* atanh(x) = ln((1 + x)/(1 - x)) / 2
20752
* acoth(x) = atanh(1 / x)
20754
* @param {BigNumber} x
20755
* @param {DecimalFactory} Big current BigNumber constructor
20756
* @param {Boolean} reciprocal is sec or csc
20757
* @returns {BigNumber} hyperbolic arctangent or arccotangent of x
20759
exports.atanh_acoth = function (x, Big, reciprocal) {
20761
return new Big(NaN);
20764
var absX = x.abs();
20765
if (absX.eq(Big.ONE)) {
20766
return new Big(x.isNegative() ? -Infinity : Infinity);
20768
if (absX.gt(Big.ONE)) {
20770
throw new Error('atanh() only has non-complex values for |x| <= 1.');
20772
} else if (reciprocal) {
20773
throw new Error('acoth() has complex values for |x| < 1.');
20780
var precision = Big.precision;
20781
Big.config({precision: precision + 4});
20783
var y = new Big(x);
20784
y.constructor = Big;
20787
y = Big.ONE.div(y);
20789
var ret = Big.ONE.plus(y).div(Big.ONE.minus(y)).ln().div(2);
20791
Big.config({precision: precision});
20792
return new Big(ret.toPrecision(precision));
20796
* Calculate the cosine/sine of x using the multiple angle identity:
20798
* cos(4x) = 8[cos(x)^4 - cos(x)^2] + 1
20800
* sin(5x) = 16sin(x)^5 - 20sin(x)^3 + 5sin(x)
20801
* http://www.tc.umn.edu/~ringx004/sidebar.html
20803
* @param {BigNumber} x
20804
* @param {DecimalFactory} Big current BigNumber constructor
20805
* @param {Number} mode cosine function if 0, sine function if 1
20806
* @param {Boolean} reciprocal is sec or csc
20807
* @returns {BigNumber} cosine, sine, secant, or cosecant of x
20809
exports.cos_sin_sec_csc = function (x, Big, mode, reciprocal) {
20810
if (x.isNaN() || !x.isFinite()) {
20811
return new Big(NaN);
20813
var precision = Big.precision;
20815
// Avoid changing the original value
20816
var y = new Big(x);
20818
// sin(-x) == -sin(x), cos(-x) == cos(x)
20819
var isNeg = y.isNegative();
20824
// Apply ~log(precision) guard bits
20825
var precPlusGuardDigits = precision + (Math.log(precision) | 0) + 3;
20826
Big.config({precision: precPlusGuardDigits});
20828
y = reduceToPeriod(y, precPlusGuardDigits, mode); // Make this destructive
20829
y[0].constructor = Big;
20832
if (reciprocal && y.isZero()) {
20833
y = new Big(Infinity);
20836
Big.config({precision: precision});
20843
ret = cos_sin_taylor(y.div(3125), mode);
20844
Big.config({precision: Math.min(precPlusGuardDigits, precision + 15)});
20846
var five = new Big(5);
20847
var sixteen = new Big(16);
20848
var twenty = new Big(20);
20849
for (var i = 0; i < 5; ++i) {
20850
var ret2 = ret.times(ret);
20851
var ret3 = ret2.times(ret);
20852
var ret5 = ret3.times(ret2);
20853
ret = sixteen.times(ret5).minus(
20854
twenty.times(ret3)).plus(
20862
var div_factor, loops;
20863
if (y.abs().lt(Big.ONE)) {
20871
ret = cos_sin_taylor(y.div(div_factor), mode);
20872
Big.config({precision: Math.min(precPlusGuardDigits, precision + 8)});
20874
var eight = new Big(8);
20875
for (; loops > 0; --loops) {
20876
var ret2 = ret.times(ret);
20877
var ret4 = ret2.times(ret2);
20878
ret = eight.times(ret4.minus(ret2)).plus(Big.ONE);
20883
ret = (ret.e <= -precision)
20884
? new Big(Infinity)
20885
: Big.ONE.div(ret);
20888
Big.config({precision: precision});
20889
return ret.toDP(precision - 1);
20893
* Calculate the tangent of x
20895
* tan(x) = sin(x) / cos(x)
20897
* cot(x) = cos(x) / sin(x)
20899
* @param {BigNumber} x
20900
* @param {DecimalFactory} Big current BigNumber constructor
20901
* @param {Boolean} reciprocal is cot
20902
* @returns {BigNumber} tangent or cotangent of x
20904
exports.tan_cot = function (x, Big, reciprocal) {
20906
return new Big(NaN);
20909
var precision = Big.precision;
20910
var pi = exports.pi(precision + 2);
20911
var halfPi = pi.div(2).toDP(precision - 1);
20912
pi = pi.toDP(precision - 1);
20914
var y = reduceToPeriod(x, precision, 1)[0];
20915
if (y.abs().eq(pi)) {
20916
return new Big(Infinity);
20919
Big.config({precision: precision + 2});
20920
var sin = exports.cos_sin_sec_csc(y, Big, 1, false);
20921
var cos = sinToCos(sin);
20923
sin = sin.toDP(precision);
20924
cos = cos.toDP(precision);
20926
// Make sure sign for cosine is correct
20928
if (y.gt(halfPi)) {
20931
} else if (pi.minus(y.abs()).gt(halfPi)) {
20935
var tan = (reciprocal) ? cos.div(sin) : sin.div(cos);
20937
Big.config({precision: precision});
20938
return new Big(tan.toPrecision(precision));
20942
* Calculate the hyperbolic sine, cosine, secant, or cosecant of x
20944
* cosh(x) = (exp(x) + exp(-x)) / 2
20945
* = (e^x + 1/e^x) / 2
20947
* sinh(x) = (exp(x) - exp(-x)) / 2
20948
* = (e^x - 1/e^x) / 2
20950
* sech(x) = 2 / (exp(x) + exp(-x))
20951
* = 2 / (e^x + 1/e^x)
20953
* csch(x) = 2 / (exp(x) - exp(-x))
20954
* = 2 / (e^x - 1/e^x)
20956
* @param {BigNumber} x
20957
* @param {DecimalFactory} Big current BigNumber constructor
20958
* @param {Boolean} mode sinh function if true, cosh function if false
20959
* @param {Boolean} reciprocal is sech or csch
20960
* @returns {BigNumber} hyperbolic cosine, sine, secant. or cosecant of x
20962
exports.cosh_sinh_csch_sech = function (x, Big, mode, reciprocal) {
20964
return new Big(NaN);
20966
if (!x.isFinite()) {
20970
return new Big((mode) ? x : Infinity);
20973
var precision = Big.precision;
20974
Big.config({precision: precision + 4});
20976
var y = new Big(x);
20977
y.constructor = Big;
20980
y = (mode) ? y.minus(Big.ONE.div(y)) : y.plus(Big.ONE.div(y));
20981
y = (reciprocal) ? new Big(2).div(y) : y.div(2);
20983
Big.config({precision: precision});
20984
return new Big(y.toPrecision(precision));
20988
* Calculate the hyperbolic tangent of x
20990
* tanh(x) = (exp(x) + exp(-x)) / (exp(x) - exp(-x))
20991
* = (exp(2x) - 1) / (exp(2x) + 1)
20992
* = (e^x - 1/e^x) / (e^x + 1/e^x)
20994
* coth(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
20995
* = (exp(2x) + 1) / (exp(2x) - 1)
20996
* = (e^x + 1/e^x) / (e^x - 1/e^x)
20998
* @param {BigNumber} x
20999
* @param {DecimalFactory} Big current BigNumber constructor
21000
* @param {Boolean} reciprocal is coth
21001
* @returns {BigNumber} hyperbolic tangent or cotangent of x
21003
exports.tanh_coth = function (x, Big, reciprocal) {
21005
return new Big(NaN);
21007
if (!x.isFinite()) {
21008
return new Big(x.s);
21011
var precision = Big.precision;
21012
Big.config({precision: precision + 4});
21014
var y = new Big(x);
21015
y.constructor = Big;
21017
var posExp = y.exp();
21018
var negExp = Big.ONE.div(posExp);
21019
var ret = posExp.minus(negExp);
21020
ret = (reciprocal) ? posExp.plus(negExp).div(ret) : ret.div(posExp.plus(negExp));
21022
Big.config({precision: precision});
21023
return ret.toDP(precision - 1);
21027
* Calculate the arc sine of x using Newton's method
21029
* f(x) = sin(x) = N => f(x) = sin(x) - N
21032
* Thus we solve each step as follows:
21033
* x_(i+1) = x_i - (sin(x_i) - N)/cos(x_i)
21035
* @param {BigNumber} x
21036
* @param {DecimalFactory} Big current BigNumber constructor
21037
* @returns {BigNumber} arc sine of x
21039
function arcsin_newton(x, Big) {
21040
var oldPrecision = Big.precision;
21042
// Calibration variables, adjusted from MAPM
21043
var tolerance = -(oldPrecision + 4);
21044
var maxp = oldPrecision + 8 - x.e;
21045
var localPrecision = 25 - x.e;
21046
var maxIter = Math.max(Math.log(oldPrecision + 2) * 1.442695 | 0 + 5, 5);
21047
Big.config({precision: localPrecision});
21050
var curr = new Big(Math.asin(x.toNumber()) + '');
21052
var tmp0 = exports.cos_sin_sec_csc(curr, Big, 1, false);
21053
var tmp1 = sinToCos(tmp0);
21054
if (!tmp0.isZero()) {
21058
var tmp2 = tmp0.minus(x).div(tmp1);
21059
curr = curr.minus(tmp2);
21061
localPrecision = Math.min(2*localPrecision, maxp);
21062
Big.config({precision: localPrecision});
21063
} while ((2*tmp2.e >= tolerance) && !tmp2.isZero() && (++i <= maxIter))
21065
if (i == maxIter) {
21066
throw new Error('asin() failed to converge to the requested accuracy.' +
21067
'Try with a higher precision.');
21070
Big.config({precision: oldPrecision});
21071
return curr.toDP(oldPrecision - 1);
21075
* Calculate the arc sine of x
21077
* arcsin(x) = x + (1/2)*x^3/3 + (3/8)*x^5/5 + (15/48)*x^7/7 ...
21078
* = x + (1/2)*x^2*x^1/3 + [(1*3)/(2*4)]*x^2*x^3/5 + [(1*3*5)/(2*4*6)]*x^2*x^5/7 ...
21080
* @param {BigNumber} x
21081
* @param {Number} precision
21082
* @returns {BigNumber} arc sine of x
21084
function arcsin_taylor(x, precision) {
21085
var Big = x.constructor;
21086
Big.config({precision: precision + Math.log(precision) | 0 + 4});
21088
var one = new Big(1);
21091
var x2 = x.times(x);
21093
var constNum = new Big(one);
21094
var constDen = new Big(one);
21096
var bigK = new Big(one);
21097
for (var k = 3; !y.equals(yPrev); k += 2) {
21098
polyNum = polyNum.times(x2);
21100
constNum = constNum.times(bigK);
21101
constDen = constDen.times(bigK.plus(one));
21105
y = y.plus(polyNum.times(constNum).div(bigK.times(constDen)));
21108
Big.config({precision: precision});
21109
return y.toDP(precision - 1);
21113
* Calculate the arc tangent of x using a Taylor expansion
21115
* arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - ...
21116
* = x - x^2*x^1/3 + x^2*x^3/5 - x^2*x^5/7 + x^2*x^7/9 - ...
21118
* @param {BigNumber} x
21119
* @returns {BigNumber} arc tangent of x
21121
function arctan_taylor(x) {
21124
var x2 = x.times(x);
21128
for (var k = 3; !y.equals(yPrev); k += 2) {
21129
num = num.times(x2);
21133
y = (add) ? y.plus(num.div(k)) : y.minus(num.div(k));
21140
* Calculate the cosine or sine of x using Taylor Series.
21142
* cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! - ...
21143
* = 1 - 1*x^2/2! + x^2*x^2/4! - x^2*x^4/6! + x^2*x^6/8! - ...
21145
* sin(x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! - ...
21146
* = x - x^2*x^1/3! + x^2*x^3/5! - x^2*x^5/7! + x^2*x^7/9! - ...
21148
* @param {BigNumber} x reduced argument
21149
* @param {Number} mode sine function if 1, cosine function if 0
21150
* @returns {BigNumber} sine or cosine of x
21152
function cos_sin_taylor(x, mode) {
21153
var one = x.constructor.ONE;
21157
var x2 = x.times(x);
21158
var num = (mode) ? y : y = one;
21162
for (var k = mode; !y.equals(yPrev); k += 2) {
21163
num = num.times(x2);
21164
den = den.times(k+1).times(k+2);
21168
y = (add) ? y.plus(num.div(den)) : y.minus(num.div(den));
21175
* Reduce x within a period of pi (0, pi] with guard digits.
21177
* @param {BigNumber} x
21178
* @param {Number} precision
21179
* @param {Number} mode
21180
* @returns {Array} [Reduced x, is tau multiple?]
21182
function reduceToPeriod(x, precision, mode) {
21183
var pi = exports.pi(precision + 2);
21184
var tau = exports.tau(precision);
21185
if (x.abs().lte(pi.toDP(x.dp()))) {
21189
var Big = x.constructor;
21190
// Catch if input is tau multiple using pi's precision
21191
if (x.div(pi.toDP(x.dp())).toNumber() % 2 == 0) {
21192
return [new Big(mode ^ 1), true];
21195
var y = x.mod(tau);
21197
// Catch if tau multiple with tau's precision
21198
if (y.toDP(x.dp(), 1).isZero()) {
21199
return [new Big(mode ^ 1), true];
21204
// sin(x + pi) = -sin(x)
21208
// cos(x) = cos(tau - x)
21213
y.constructor = Big;
21218
* Convert from sine to cosine
21220
* |cos(x)| = sqrt(1 - sin(x)^2)
21222
* @param {BigNumber} sine of x
21223
* @returns {BigNumber} sine as cosine
21225
function sinToCos(sinVal) {
21226
var Big = sinVal.constructor;
21227
var precision = Big.precision;
21228
Big.config({precision: precision + 2});
21230
var ret = Big.ONE.minus(sinVal.times(sinVal)).sqrt();
21232
Big.config({precision: precision});
21233
return ret.toDP(precision - 1);
21237
/************************************
21238
* Format functions *
21239
************************************/
21242
* Convert a number to a formatted string representation.
21247
* format(value, options)
21248
* format(value, precision)
21249
* format(value, fn)
21253
* {Number} value The value to be formatted
21254
* {Object} options An object with formatting options. Available options:
21255
* {String} notation
21256
* Number notation. Choose from:
21257
* 'fixed' Always use regular number notation.
21258
* For example '123.40' and '14000000'
21259
* 'exponential' Always use exponential notation.
21260
* For example '1.234e+2' and '1.4e+7'
21261
* 'auto' (default) Regular number notation for numbers
21262
* having an absolute value between
21263
* `lower` and `upper` bounds, and uses
21264
* exponential notation elsewhere.
21265
* Lower bound is included, upper bound
21267
* For example '123.4' and '1.4e7'.
21268
* {Number} precision A number between 0 and 16 to round
21269
* the digits of the number.
21270
* In case of notations 'exponential' and
21271
* 'auto', `precision` defines the total
21272
* number of significant digits returned
21273
* and is undefined by default.
21274
* In case of notation 'fixed',
21275
* `precision` defines the number of
21276
* significant digits after the decimal
21277
* point, and is 0 by default.
21278
* {Object} exponential An object containing two parameters,
21279
* {Number} lower and {Number} upper,
21280
* used by notation 'auto' to determine
21281
* when to return exponential notation.
21282
* Default values are `lower=1e-3` and
21284
* Only applicable for notation `auto`.
21285
* {Function} fn A custom formatting function. Can be used to override the
21286
* built-in notations. Function `fn` is called with `value` as
21287
* parameter and must return a string. Is useful for example to
21288
* format all values inside a matrix in a particular way.
21292
* format(6.4); // '6.4'
21293
* format(1240000); // '1.24e6'
21294
* format(1/3); // '0.3333333333333333'
21295
* format(1/3, 3); // '0.333'
21296
* format(21385, 2); // '21000'
21297
* format(12.071, {notation: 'fixed'}); // '12'
21298
* format(2.3, {notation: 'fixed', precision: 2}); // '2.30'
21299
* format(52.8, {notation: 'exponential'}); // '5.28e+1'
21301
* @param {BigNumber} value
21302
* @param {Object | Function | Number} [options]
21303
* @return {String} str The formatted value
21305
exports.format = function(value, options) {
21306
if (typeof options === 'function') {
21307
// handle format(value, fn)
21308
return options(value);
21311
// handle special cases
21312
if (!value.isFinite()) {
21313
return value.isNaN() ? 'NaN' : (value.gt(0) ? 'Infinity' : '-Infinity');
21316
// default values for options
21317
var notation = 'auto';
21318
var precision = undefined;
21320
if (options !== undefined) {
21321
// determine notation from options
21322
if (options.notation) {
21323
notation = options.notation;
21326
// determine precision from options
21327
if (isNumber(options)) {
21328
precision = options;
21330
else if (options.precision) {
21331
precision = options.precision;
21335
// handle the various notations
21336
switch (notation) {
21338
return exports.toFixed(value, precision);
21340
case 'exponential':
21341
return exports.toExponential(value, precision);
21344
// determine lower and upper bound for exponential notation.
21345
// TODO: implement support for upper and lower to be BigNumbers themselves
21348
if (options && options.exponential) {
21349
if (options.exponential.lower !== undefined) {
21350
lower = options.exponential.lower;
21352
if (options.exponential.upper !== undefined) {
21353
upper = options.exponential.upper;
21357
// adjust the configuration of the BigNumber constructor (yeah, this is quite tricky...)
21359
toExpNeg: value.constructor.toExpNeg,
21360
toExpPos: value.constructor.toExpPos
21363
value.constructor.config({
21364
toExpNeg: Math.round(Math.log(lower) / Math.LN10),
21365
toExpPos: Math.round(Math.log(upper) / Math.LN10)
21368
// handle special case zero
21369
if (value.isZero()) return '0';
21371
// determine whether or not to output exponential notation
21373
var abs = value.abs();
21374
if (abs.gte(lower) && abs.lt(upper)) {
21375
// normal number notation
21376
str = value.toSignificantDigits(precision).toFixed();
21379
// exponential notation
21380
str = exports.toExponential(value, precision);
21383
// remove trailing zeros after the decimal point
21384
return str.replace(/((\.\d*?)(0+))($|e)/, function () {
21385
var digits = arguments[2];
21386
var e = arguments[4];
21387
return (digits !== '.') ? digits + e : e;
21391
throw new Error('Unknown notation "' + notation + '". ' +
21392
'Choose "auto", "exponential", or "fixed".');
21397
* Format a number in exponential notation. Like '1.23e+5', '2.3e+0', '3.500e-3'
21398
* @param {BigNumber} value
21399
* @param {Number} [precision] Number of digits in formatted output.
21400
* If not provided, the maximum available digits
21402
* @returns {string} str
21404
exports.toExponential = function(value, precision) {
21405
if (precision !== undefined) {
21406
return value.toExponential(precision - 1); // Note the offset of one
21409
return value.toExponential();
21414
* Format a number with fixed notation.
21415
* @param {BigNumber} value
21416
* @param {Number} [precision=0] Optional number of decimals after the
21417
* decimal point. Zero by default.
21419
exports.toFixed = function(value, precision) {
21420
return value.toFixed(precision || 0);
21421
// Note: the (precision || 0) is needed as the toFixed of BigNumber has an
21422
// undefined default precision instead of 0.
21425
/* Helper functions */
21426
function BigNumberCopy(x) {
21427
var Big = BigNumber.constructor({precision: x.constructor.precision});
21428
var y = new Big(x);
21429
y.constructor = Big; // Not sure why I have to do this...
19370
21437
/***/ function(module, exports, __webpack_require__) {
19372
21439
'use strict';
19374
var number = __webpack_require__(4),
19375
string = __webpack_require__(176),
19376
object = __webpack_require__(3),
19377
types = __webpack_require__(196),
21441
var number = __webpack_require__(3),
21442
string = __webpack_require__(205),
21443
object = __webpack_require__(2),
21444
types = __webpack_require__(334),
19379
DimensionError = __webpack_require__(156),
19380
IndexError = __webpack_require__(157),
21446
DimensionError = __webpack_require__(168),
21447
IndexError = __webpack_require__(169),
19382
21449
isArray = Array.isArray;
19934
/***/ function(module, exports, __webpack_require__) {
19936
var __WEBPACK_AMD_DEFINE_RESULT__;/*! decimal.js v4.0.1 https://github.com/MikeMcl/decimal.js/LICENCE */
22001
/***/ function(module, exports, __webpack_require__) {
22005
exports.array = __webpack_require__(165);
22006
exports['boolean'] = __webpack_require__(204);
22007
exports.number = __webpack_require__(3);
22008
exports.bignumber = __webpack_require__(164);
22009
exports.object = __webpack_require__(2);
22010
exports.string = __webpack_require__(205);
22011
exports.types = __webpack_require__(334);
22016
/***/ function(module, exports, __webpack_require__) {
22020
var Node = __webpack_require__(180),
22021
object = __webpack_require__(2),
22022
string = __webpack_require__(205),
22023
collection = __webpack_require__(14),
22024
util = __webpack_require__(171),
22026
isArray = Array.isArray,
22027
isNode = Node.isNode;
22030
* @constructor ArrayNode
22032
* Holds an 1-dimensional array with nodes
22033
* @param {Node[]} [nodes] 1 dimensional array with nodes
22035
function ArrayNode(nodes) {
22036
if (!(this instanceof ArrayNode)) {
22037
throw new SyntaxError('Constructor must be called with the new operator');
22040
this.nodes = nodes || [];
22043
if (!isArray(this.nodes) || !this.nodes.every(isNode)) {
22044
throw new TypeError('Array containing Nodes expected')
22048
ArrayNode.prototype = new Node();
22050
ArrayNode.prototype.type = 'ArrayNode';
22053
* Compile the node to javascript code
22054
* @param {Object} defs Object which can be used to define functions
22055
* or constants globally available for the compiled
22059
ArrayNode.prototype._compile = function (defs) {
22060
var asMatrix = (defs.math.config().matrix !== 'array');
22062
var nodes = this.nodes.map(function (node) {
22063
return node._compile(defs);
22066
return (asMatrix ? 'math.matrix([' : '[') +
22068
(asMatrix ? '])' : ']');
22072
* Execute a callback for each of the child nodes of this node
22073
* @param {function(child: Node, path: string, parent: Node)} callback
22075
ArrayNode.prototype.forEach = function (callback) {
22076
for (var i = 0; i < this.nodes.length; i++) {
22077
var node = this.nodes[i];
22078
callback(node, 'nodes[' + i + ']', this);
22083
* Create a new ArrayNode having it's childs be the results of calling
22084
* the provided callback function for each of the childs of the original node.
22085
* @param {function(child: Node, path: string, parent: Node): Node} callback
22086
* @returns {ArrayNode} Returns a transformed copy of the node
22088
ArrayNode.prototype.map = function (callback) {
22090
for (var i = 0; i < this.nodes.length; i++) {
22091
nodes[i] = this._ifNode(callback(this.nodes[i], 'nodes[' + i + ']', this));
22093
return new ArrayNode(nodes);
22097
* Create a clone of this node, a shallow copy
22098
* @return {ArrayNode}
22100
ArrayNode.prototype.clone = function() {
22101
return new ArrayNode(this.nodes.slice(0))
22105
* Get string representation
22106
* @return {String} str
22109
ArrayNode.prototype.toString = function() {
22110
return string.format(this.nodes);
22114
* Get LaTeX representation
22115
* @return {String} str
22117
ArrayNode.prototype.toTex = function(type) {
22118
type = type || 'bmatrix';
22119
var s = '\\begin{' + type + '}';
22121
this.nodes.forEach(function(node) {
22123
s += node.nodes.map(function(childNode) {
22124
return childNode.toTex();
22134
s += '\\end{' + type + '}';
22138
module.exports = ArrayNode;
22143
/***/ function(module, exports, __webpack_require__) {
22147
var Node = __webpack_require__(180),
22148
ArrayNode = __webpack_require__(172),
22150
keywords = __webpack_require__(337),
22152
latex = __webpack_require__(338),
22153
isString = __webpack_require__(205).isString;
22156
* @constructor AssignmentNode
22158
* Define a symbol, like "a = 3.2"
22160
* @param {String} name Symbol name
22161
* @param {Node} expr The expression defining the symbol
22163
function AssignmentNode(name, expr) {
22164
if (!(this instanceof AssignmentNode)) {
22165
throw new SyntaxError('Constructor must be called with the new operator');
22169
if (!isString(name)) throw new TypeError('String expected for parameter "name"');
22170
if (!(expr instanceof Node)) throw new TypeError('Node expected for parameter "expr"');
22171
if (name in keywords) throw new Error('Illegal symbol name, "' + name + '" is a reserved keyword');
22177
AssignmentNode.prototype = new Node();
22179
AssignmentNode.prototype.type = 'AssignmentNode';
22182
* Compile the node to javascript code
22183
* @param {Object} defs Object which can be used to define functions
22184
* or constants globally available for the compiled
22188
AssignmentNode.prototype._compile = function (defs) {
22189
return 'scope["' + this.name + '"] = ' + this.expr._compile(defs) + '';
22194
* Execute a callback for each of the child nodes of this node
22195
* @param {function(child: Node, path: string, parent: Node)} callback
22197
AssignmentNode.prototype.forEach = function (callback) {
22198
callback(this.expr, 'expr', this);
22202
* Create a new AssignmentNode having it's childs be the results of calling
22203
* the provided callback function for each of the childs of the original node.
22204
* @param {function(child: Node, path: string, parent: Node): Node} callback
22205
* @returns {AssignmentNode} Returns a transformed copy of the node
22207
AssignmentNode.prototype.map = function (callback) {
22208
return new AssignmentNode(this.name, this._ifNode(callback(this.expr, 'expr', this)));
22212
* Create a clone of this node, a shallow copy
22213
* @return {AssignmentNode}
22215
AssignmentNode.prototype.clone = function() {
22216
return new AssignmentNode(this.name, this.expr);
22220
* Get string representation
22223
AssignmentNode.prototype.toString = function() {
22224
return this.name + ' = ' + this.expr.toString();
22228
* Get LaTeX representation
22231
AssignmentNode.prototype.toTex = function() {
22233
if (this.expr instanceof ArrayNode) {
22234
brace = ['\\mathbf{', '}'];
22236
return latex.addBraces(latex.toSymbol(this.name), brace) + '=' +
22237
latex.addBraces(this.expr.toTex());
22240
module.exports = AssignmentNode;
22244
/***/ function(module, exports, __webpack_require__) {
22248
var Node = __webpack_require__(180);
22249
var ResultSet = __webpack_require__(13);
22250
var isBoolean = __webpack_require__(204).isBoolean;
22253
* @constructor BlockNode
22255
* Holds a set with blocks
22256
* @param {Array.<{node: Node} | {node: Node, visible: boolean}>} blocks
22257
* An array with blocks, where a block is constructed as an Object
22258
* with properties block, which is a Node, and visible, which is
22259
* a boolean. The property visible is optional and is true by default
22261
function BlockNode(blocks) {
22262
if (!(this instanceof BlockNode)) {
22263
throw new SyntaxError('Constructor must be called with the new operator');
22266
// validate input, copy blocks
22267
if (!Array.isArray(blocks)) throw new Error('Array expected');
22268
this.blocks = blocks.map(function (block) {
22269
var node = block && block.node;
22270
var visible = block && block.visible !== undefined ? block.visible : true;
22272
if (!(node instanceof Node)) throw new TypeError('Property "node" must be a Node');
22273
if (!isBoolean(visible)) throw new TypeError('Property "visible" must be a boolean');
22282
BlockNode.prototype = new Node();
22284
BlockNode.prototype.type = 'BlockNode';
22287
* Compile the node to javascript code
22288
* @param {Object} defs Object which can be used to define functions
22289
* or constants globally available for the compiled
22291
* @return {String} js
22294
BlockNode.prototype._compile = function (defs) {
22295
defs.ResultSet = ResultSet;
22296
var blocks = this.blocks.map(function (param) {
22297
var js = param.node._compile(defs);
22298
if (param.visible) {
22299
return 'results.push(' + js + ');';
22306
return '(function () {' +
22307
'var results = [];' +
22309
'return new ResultSet(results);' +
22314
* Execute a callback for each of the child blocks of this node
22315
* @param {function(child: Node, path: string, parent: Node)} callback
22317
BlockNode.prototype.forEach = function (callback) {
22318
for (var i = 0; i < this.blocks.length; i++) {
22319
callback(this.blocks[i].node, 'blocks[' + i + '].node', this);
22324
* Create a new BlockNode having it's childs be the results of calling
22325
* the provided callback function for each of the childs of the original node.
22326
* @param {function(child: Node, path: string, parent: Node): Node} callback
22327
* @returns {BlockNode} Returns a transformed copy of the node
22329
BlockNode.prototype.map = function (callback) {
22331
for (var i = 0; i < this.blocks.length; i++) {
22332
var block = this.blocks[i];
22333
var node = this._ifNode(callback(block.node, 'blocks[' + i + '].node', this));
22336
visible: block.visible
22339
return new BlockNode(blocks);
22343
* Create a clone of this node, a shallow copy
22344
* @return {BlockNode}
22346
BlockNode.prototype.clone = function() {
22347
var blocks = this.blocks.map(function(block) {
22350
visible: block.visible
22354
return new BlockNode(blocks);
22358
* Get string representation
22359
* @return {String} str
22362
BlockNode.prototype.toString = function() {
22363
return this.blocks.map(function (param) {
22364
return param.node.toString() + (param.visible ? '' : ';');
22369
* Get LaTeX representation
22370
* @return {String} str
22372
BlockNode.prototype.toTex = function() {
22373
return this.blocks.map(function (param) {
22374
return param.node.toTex() + (param.visible ? '' : ';');
22378
module.exports = BlockNode;
22383
/***/ function(module, exports, __webpack_require__) {
22387
var Node = __webpack_require__(180);
22388
var latex = __webpack_require__(338);
22389
var BigNumber = __webpack_require__(5);
22390
var Complex = __webpack_require__(7);
22391
var Unit = __webpack_require__(11);
22392
var util = __webpack_require__(171);
22393
var isString = util.string.isString;
22394
var isNumber = util.number.isNumber;
22395
var isBoolean = util['boolean'].isBoolean;
22398
* A lazy evaluating conditional operator: 'condition ? trueExpr : falseExpr'
22400
* @param {Node} condition Condition, must result in a boolean
22401
* @param {Node} trueExpr Expression evaluated when condition is true
22402
* @param {Node} falseExpr Expression evaluated when condition is true
22404
* @constructor ConditionalNode
22407
function ConditionalNode (condition, trueExpr, falseExpr) {
22408
if (!(this instanceof ConditionalNode)) {
22409
throw new SyntaxError('Constructor must be called with the new operator');
22411
if (!(condition instanceof Node)) throw new TypeError('Parameter condition must be a Node');
22412
if (!(trueExpr instanceof Node)) throw new TypeError('Parameter trueExpr must be a Node');
22413
if (!(falseExpr instanceof Node)) throw new TypeError('Parameter falseExpr must be a Node');
22415
this.condition = condition;
22416
this.trueExpr = trueExpr;
22417
this.falseExpr = falseExpr;
22420
ConditionalNode.prototype = new Node();
22422
ConditionalNode.prototype.type = 'ConditionalNode';
22425
* Compile the node to javascript code
22426
* @param {Object} defs Object which can be used to define functions
22427
* or constants globally available for the compiled
22429
* @return {String} js
22432
ConditionalNode.prototype._compile = function(defs) {
22434
* Test whether a condition is met
22435
* @param {*} condition
22436
* @returns {boolean} true if condition is true or non-zero, else false
22438
defs.testCondition = function (condition) {
22439
if (isNumber(condition) || isBoolean(condition) || isString(condition)) {
22440
return condition ? true : false;
22443
if (condition instanceof BigNumber) {
22444
return condition.isZero() ? false : true;
22447
if (condition instanceof Complex) {
22448
return (condition.re || condition.im) ? true : false;
22451
if (condition instanceof Unit) {
22452
return condition.value ? true : false;
22455
if (condition === null || condition === undefined) {
22459
throw new TypeError('Unsupported type of condition "' + defs.math['typeof'](condition) + '"');
22463
'testCondition(' + this.condition._compile(defs) + ') ? ' +
22464
'( ' + this.trueExpr._compile(defs) + ') : ' +
22465
'( ' + this.falseExpr._compile(defs) + ')'
22470
* Execute a callback for each of the child nodes of this node
22471
* @param {function(child: Node, path: string, parent: Node)} callback
22473
ConditionalNode.prototype.forEach = function (callback) {
22474
callback(this.condition, 'condition', this);
22475
callback(this.trueExpr, 'trueExpr', this);
22476
callback(this.falseExpr, 'falseExpr', this);
22480
* Create a new ConditionalNode having it's childs be the results of calling
22481
* the provided callback function for each of the childs of the original node.
22482
* @param {function(child: Node, path: string, parent: Node): Node} callback
22483
* @returns {ConditionalNode} Returns a transformed copy of the node
22485
ConditionalNode.prototype.map = function (callback) {
22486
return new ConditionalNode(
22487
this._ifNode(callback(this.condition, 'condition', this)),
22488
this._ifNode(callback(this.trueExpr, 'trueExpr', this)),
22489
this._ifNode(callback(this.falseExpr, 'falseExpr', this))
22494
* Create a clone of this node, a shallow copy
22495
* @return {ConditionalNode}
22497
ConditionalNode.prototype.clone = function() {
22498
return new ConditionalNode(this.condition, this.trueExpr, this.falseExpr);
22502
* Get string representation
22503
* @return {String} str
22505
ConditionalNode.prototype.toString = function() {
22506
// TODO: not nice adding parenthesis al the time
22507
return '(' + this.condition.toString() + ') ? (' +
22508
this.trueExpr.toString() + ') : (' +
22509
this.falseExpr.toString() + ')';
22513
* Get LaTeX representation
22514
* @return {String} str
22516
ConditionalNode.prototype.toTex = function() {
22518
latex.addBraces(this.trueExpr.toTex()) +
22520
latex.addBraces('\\text{if}\\;' + this.condition.toTex())
22522
latex.addBraces(this.falseExpr.toTex()) +
22524
latex.addBraces('\\text{otherwise}')
22527
return latex.addBraces(s, [
22528
'\\left\\{\\begin{array}{l l}',
22529
'\\end{array}\\right.'
22533
module.exports = ConditionalNode;
22538
/***/ function(module, exports, __webpack_require__) {
22542
var Node = __webpack_require__(180);
22543
var BigNumber = __webpack_require__(5);
22544
var type = __webpack_require__(334).type;
22545
var isString = __webpack_require__(205).isString;
22548
* A ConstantNode holds a constant value like a number or string. A ConstantNode
22549
* stores a stringified version of the value and uses this to compile to
22552
* In case of a stringified number as input, this may be compiled to a BigNumber
22553
* when the math instance is configured for BigNumbers.
22557
* // stringified values with type
22558
* new ConstantNode('2.3', 'number');
22559
* new ConstantNode('true', 'boolean');
22560
* new ConstantNode('hello', 'string');
22562
* // non-stringified values, type will be automatically detected
22563
* new ConstantNode(2.3);
22564
* new ConstantNode('hello');
22566
* @param {String | Number | Boolean | null | undefined} value
22567
* When valueType is provided, value must contain
22568
* an uninterpreted string representing the value.
22569
* When valueType is undefined, value can be a
22570
* number, string, boolean, null, or undefined, and
22571
* the type will be determined automatically.
22572
* @param {String} [valueType] The type of value. Choose from 'number', 'string',
22573
* 'boolean', 'undefined', 'null'
22574
* @constructor ConstantNode
22577
function ConstantNode(value, valueType) {
22578
if (!(this instanceof ConstantNode)) {
22579
throw new SyntaxError('Constructor must be called with the new operator');
22583
if (!isString(valueType)) {
22584
throw new TypeError('String expected for parameter "valueType"');
22586
if (!isString(value)){
22587
throw new TypeError('String expected for parameter "value"');
22590
this.value = value;
22591
this.valueType = valueType;
22594
// stringify the value and determine the type
22595
this.value = value + '';
22596
this.valueType = type(value);
22599
if (!SUPPORTED_TYPES[this.valueType]) {
22600
throw new TypeError('Unsupported type of value "' + this.valueType + '"');
22604
var SUPPORTED_TYPES = {
22612
ConstantNode.prototype = new Node();
22614
ConstantNode.prototype.type = 'ConstantNode';
22617
* Compile the node to javascript code
22618
* @param {Object} defs Object which can be used to define functions
22619
* or constants globally available for the compiled
22621
* @return {String} js
22624
ConstantNode.prototype._compile = function (defs) {
22625
switch (this.valueType) {
22627
if (defs.math.config().number === 'bignumber') {
22628
return 'math.bignumber("' + this.value + '")';
22631
// remove leading zeros like '003.2' which are not allowed by JavaScript
22632
return this.value.replace(/^(0*)[0-9]/, function (match, zeros) {
22633
return match.substring(zeros.length);
22638
return '"' + this.value + '"';
22650
// TODO: move this error to the constructor?
22651
throw new TypeError('Unsupported type of constant "' + this.valueType + '"');
22656
* Execute a callback for each of the child nodes of this node
22657
* @param {function(child: Node, path: string, parent: Node)} callback
22659
ConstantNode.prototype.forEach = function (callback) {
22660
// nothing to do, we don't have childs
22665
* Create a new ConstantNode having it's childs be the results of calling
22666
* the provided callback function for each of the childs of the original node.
22667
* @param {function(child: Node, path: string, parent: Node) : Node} callback
22668
* @returns {ConstantNode} Returns a clone of the node
22670
ConstantNode.prototype.map = function (callback) {
22671
return this.clone();
22675
* Create a clone of this node, a shallow copy
22676
* @return {ConstantNode}
22678
ConstantNode.prototype.clone = function() {
22679
return new ConstantNode(this.value, this.valueType);
22683
* Get string representation
22684
* @return {String} str
22686
ConstantNode.prototype.toString = function() {
22687
switch (this.valueType) {
22689
return '"' + this.value + '"';
22697
* Get LaTeX representation
22698
* @return {String} str
22700
ConstantNode.prototype.toTex = function() {
22701
var value = this.value,
22703
switch (this.valueType) {
22705
return '\\text{' + value + '}';
22708
index = value.toLowerCase().indexOf('e');
22709
if (index !== -1) {
22710
return value.substring(0, index) + ' \\cdot 10^{' +
22711
value.substring(index + 1) + '}';
22720
module.exports = ConstantNode;
22725
/***/ function(module, exports, __webpack_require__) {
22729
var Node = __webpack_require__(180);
22730
var RangeNode = __webpack_require__(182);
22731
var SymbolNode = __webpack_require__(183);
22733
var BigNumber = __webpack_require__(5);
22734
var Range = __webpack_require__(8);
22736
var isNode = Node.isNode;
22737
var isArray = Array.isArray;
22740
* @constructor IndexNode
22743
* get a subset of a matrix
22745
* @param {Node} object
22746
* @param {Node[]} ranges
22748
function IndexNode (object, ranges) {
22749
if (!(this instanceof IndexNode)) {
22750
throw new SyntaxError('Constructor must be called with the new operator');
22754
if (!(object instanceof Node)) throw new TypeError('Node expected for parameter "object"');
22755
if (!isArray(ranges) || !ranges.every(isNode)) {
22756
throw new TypeError('Array containing Nodes expected for parameter "ranges"');
22759
this.object = object;
22760
this.ranges = ranges;
22763
IndexNode.prototype = new Node();
22765
IndexNode.prototype.type = 'IndexNode';
22768
* Compile the node to javascript code
22769
* @param {Object} defs Object which can be used to define functions
22770
* or constants globally available for the compiled
22772
* @return {String} js
22775
IndexNode.prototype._compile = function (defs) {
22776
return this.compileSubset(defs);
22780
* Compile the node to javascript code
22781
* @param {Object} defs Object which can be used to define functions
22782
* or constants globally available for the
22783
* compiled expression
22784
* @param {String} [replacement] If provided, the function returns
22785
* "math.subset(obj, math.index(...), replacement)"
22786
* Else, the function returns
22787
* "math.subset(obj, math.index(...))"
22788
* @return {String} js
22789
* @returns {string}
22791
IndexNode.prototype.compileSubset = function(defs, replacement) {
22792
// check whether any of the ranges expressions uses the context symbol 'end'
22793
function test(node) {
22794
return (node instanceof SymbolNode) && (node.name == 'end');
22797
var someUseEnd = false;
22798
var rangesUseEnd = this.ranges.map(function (range) {
22799
var useEnd = range.filter(test).length > 0;
22800
someUseEnd = useEnd ? useEnd : someUseEnd;
22804
// create a Range from start, step and end
22805
defs.range = function (start, end, step) {
22807
start instanceof BigNumber ? start.toNumber() : start,
22808
end instanceof BigNumber ? end.toNumber() : end,
22809
step instanceof BigNumber ? step.toNumber() : step
22813
// TODO: implement support for bignumber (currently bignumbers are silently
22814
// reduced to numbers when changing the value to zero-based)
22816
// TODO: Optimization: when the range values are ConstantNodes,
22817
// we can beforehand resolve the zero-based value
22819
var ranges = this.ranges.map(function(range, i) {
22820
var useEnd = rangesUseEnd[i];
22821
if (range instanceof RangeNode) {
22823
// resolve end and create range
22824
return '(function (scope) {' +
22825
' scope = Object.create(scope); ' +
22826
' scope["end"] = size[' + i + '];' +
22828
' ' + range.start._compile(defs) + ', ' +
22829
' ' + range.end._compile(defs) + ', ' +
22830
' ' + (range.step ? range.step._compile(defs) : '1') +
22837
range.start._compile(defs) + ', ' +
22838
range.end._compile(defs) + ', ' +
22839
(range.step ? range.step._compile(defs) : '1') +
22845
// resolve the parameter 'end'
22846
return '(function (scope) {' +
22847
' scope = Object.create(scope); ' +
22848
' scope["end"] = size[' + i + '];' +
22849
' return ' + range._compile(defs) + ';' +
22853
// just evaluate the expression
22854
return range._compile(defs);
22859
// if some parameters use the 'end' parameter, we need to calculate the size
22861
return '(function () {' +
22862
' var obj = ' + this.object._compile(defs) + ';' +
22863
' var size = math.size(obj).valueOf();' +
22864
' return math.subset(' +
22866
' math.index(' + ranges.join(', ') + ')' +
22867
' ' + (replacement ? (', ' + replacement) : '') +
22872
return 'math.subset(' +
22873
this.object._compile(defs) + ',' +
22874
'math.index(' + ranges.join(', ') + ')' +
22875
(replacement ? (', ' + replacement) : '') +
22881
* Execute a callback for each of the child nodes of this node
22882
* @param {function(child: Node, path: string, parent: Node)} callback
22884
IndexNode.prototype.forEach = function (callback) {
22886
callback(this.object, 'object', this);
22889
for (var i = 0; i < this.ranges.length; i++) {
22890
callback(this.ranges[i], 'ranges[' + i + ']', this);
22895
* Create a new IndexNode having it's childs be the results of calling
22896
* the provided callback function for each of the childs of the original node.
22897
* @param {function(child: Node, path: string, parent: Node): Node} callback
22898
* @returns {IndexNode} Returns a transformed copy of the node
22900
IndexNode.prototype.map = function (callback) {
22901
var object = this._ifNode(callback(this.object, 'object', this));
22904
for (var i = 0; i < this.ranges.length; i++) {
22905
ranges[i] = this._ifNode(callback(this.ranges[i], 'ranges[' + i + ']', this));
22908
return new IndexNode(object, ranges);
22912
* Get the name of the object linked to this IndexNode
22913
* @return {string} name
22915
IndexNode.prototype.objectName = function() {
22916
return this.object.name;
22920
* Create a clone of this node, a shallow copy
22921
* @return {IndexNode}
22923
IndexNode.prototype.clone = function() {
22924
return new IndexNode(this.object, this.ranges.slice(0));
22928
* Get string representation
22929
* @return {String} str
22931
IndexNode.prototype.toString = function() {
22932
// format the parameters like "[1, 0:5]"
22933
return this.object.toString() + '[' + this.ranges.join(', ') + ']';
22937
* Get LaTeX representation
22938
* @return {String} str
22940
IndexNode.prototype.toTex = function() {
22941
return this.object.toTex() + '[' + this.ranges.join(', ') + ']';
22944
module.exports = IndexNode;
22948
/***/ function(module, exports, __webpack_require__) {
22952
var Node = __webpack_require__(180);
22953
var keywords = __webpack_require__(337);
22954
var latex = __webpack_require__(338);
22955
var isString = __webpack_require__(205).isString;
22956
var isArray = Array.isArray;
22959
* @constructor FunctionAssignmentNode
22961
* Function assignment
22963
* @param {String} name Function name
22964
* @param {String[]} params Function parameter names
22965
* @param {Node} expr The function expression
22967
function FunctionAssignmentNode(name, params, expr) {
22968
if (!(this instanceof FunctionAssignmentNode)) {
22969
throw new SyntaxError('Constructor must be called with the new operator');
22973
if (!isString(name)) throw new TypeError('String expected for parameter "name"');
22974
if (!isArray(params) || !params.every(isString)) throw new TypeError('Array containing strings expected for parameter "params"');
22975
if (!(expr instanceof Node)) throw new TypeError('Node expected for parameter "expr"');
22976
if (name in keywords) throw new Error('Illegal function name, "' + name + '" is a reserved keyword');
22979
this.params = params;
22983
FunctionAssignmentNode.prototype = new Node();
22985
FunctionAssignmentNode.prototype.type = 'FunctionAssignmentNode';
22988
* Compile the node to javascript code
22989
* @param {Object} defs Object which can be used to define functions
22990
* or constants globally available for the compiled
22992
* @return {String} js
22995
FunctionAssignmentNode.prototype._compile = function (defs) {
22996
return 'scope["' + this.name + '"] = ' +
22997
' (function (scope) {' +
22998
' scope = Object.create(scope); ' +
22999
' var fn = function ' + this.name + '(' + this.params.join(',') + ') {' +
23000
' if (arguments.length != ' + this.params.length + ') {' +
23001
// TODO: use util.error.ArgumentsError here
23002
// TODO: test arguments error
23003
' throw new SyntaxError("Wrong number of arguments in function ' + this.name + ' (" + arguments.length + " provided, ' + this.params.length + ' expected)");' +
23005
this.params.map(function (variable, index) {
23006
return 'scope["' + variable + '"] = arguments[' + index + '];';
23008
' return ' + this.expr._compile(defs) + '' +
23010
' fn.syntax = "' + this.name + '(' + this.params.join(', ') + ')";' +
23016
* Execute a callback for each of the child nodes of this node
23017
* @param {function(child: Node, path: string, parent: Node)} callback
23019
FunctionAssignmentNode.prototype.forEach = function (callback) {
23020
callback(this.expr, 'expr', this);
23024
* Create a new FunctionAssignmentNode having it's childs be the results of calling
23025
* the provided callback function for each of the childs of the original node.
23026
* @param {function(child: Node, path: string, parent: Node): Node} callback
23027
* @returns {FunctionAssignmentNode} Returns a transformed copy of the node
23029
FunctionAssignmentNode.prototype.map = function (callback) {
23030
var expr = this._ifNode(callback(this.expr, 'expr', this));
23032
return new FunctionAssignmentNode(this.name, this.params.slice(0), expr);
23036
* Create a clone of this node, a shallow copy
23037
* @return {FunctionAssignmentNode}
23039
FunctionAssignmentNode.prototype.clone = function() {
23040
return new FunctionAssignmentNode(this.name, this.params.slice(0), this.expr);
23044
* get string representation
23045
* @return {String} str
23047
FunctionAssignmentNode.prototype.toString = function() {
23048
return 'function ' + this.name +
23049
'(' + this.params.join(', ') + ') = ' +
23050
this.expr.toString();
23054
* get LaTeX representation
23055
* @return {String} str
23057
FunctionAssignmentNode.prototype.toTex = function() {
23059
latex.addBraces(this.params.map(latex.toSymbol).join(', '), true) + '=' +
23060
latex.addBraces(this.expr.toTex());
23063
module.exports = FunctionAssignmentNode;
23068
/***/ function(module, exports, __webpack_require__) {
23072
var Node = __webpack_require__(180);
23073
var SymbolNode = __webpack_require__(183);
23075
var latex = __webpack_require__(338);
23076
var isNode = Node.isNode;
23077
var isArray = Array.isArray;
23080
* @constructor FunctionNode
23082
* invoke a list with arguments on a node
23083
* @param {string} name
23084
* @param {Node[]} args
23086
function FunctionNode (name, args) {
23087
if (!(this instanceof FunctionNode)) {
23088
throw new SyntaxError('Constructor must be called with the new operator');
23092
if (typeof name !== 'string') throw new TypeError('string expected for parameter "name"');
23093
if (!isArray(args) || !args.every(isNode)) {
23094
throw new TypeError('Array containing Nodes expected for parameter "args"');
23098
this.args = args || [];
23101
FunctionNode.prototype = new Node();
23103
FunctionNode.prototype.type = 'FunctionNode';
23106
* Compile the node to javascript code
23107
* @param {Object} defs Object which can be used to define functions
23108
* or constants globally available for the compiled
23110
* @return {String} js
23113
FunctionNode.prototype._compile = function (defs) {
23114
var fn = defs.math[this.name];
23115
var isRaw = (typeof fn === 'function') && (fn.rawArgs == true);
23117
// compile the parameters
23118
var args = this.args.map(function (arg) {
23119
return arg._compile(defs);
23123
// pass unevaluated parameters (nodes) to the function
23126
paramsName = 'p' + Math.round(Math.random() * 10000);
23128
while (paramsName in defs);
23129
defs[paramsName] = this.args;
23131
return '("' + this.name + '" in scope ? ' +
23132
'scope["' + this.name + '"](' + args.join(', ') + ') : ' +
23133
'math["' + this.name + '"]' + '(' + paramsName + ', math, scope))';
23136
// "regular" evaluation
23137
var symbol = new SymbolNode(this.name);
23138
return symbol._compile(defs) + '(' + args.join(', ') + ')';
23143
* Execute a callback for each of the child nodes of this node
23144
* @param {function(child: Node, path: string, parent: Node)} callback
23146
FunctionNode.prototype.forEach = function (callback) {
23147
for (var i = 0; i < this.args.length; i++) {
23148
callback(this.args[i], 'args[' + i + ']', this);
23153
* Create a new FunctionNode having it's childs be the results of calling
23154
* the provided callback function for each of the childs of the original node.
23155
* @param {function(child: Node, path: string, parent: Node): Node} callback
23156
* @returns {FunctionNode} Returns a transformed copy of the node
23158
FunctionNode.prototype.map = function (callback) {
23160
for (var i = 0; i < this.args.length; i++) {
23161
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
23163
return new FunctionNode(this.name, args);
23167
* Create a clone of this node, a shallow copy
23168
* @return {FunctionNode}
23170
FunctionNode.prototype.clone = function() {
23171
return new FunctionNode(this.name, this.args.slice(0));
23175
* Get string representation
23176
* @return {String} str
23178
FunctionNode.prototype.toString = function() {
23179
// format the parameters like "add(2, 4.2)"
23180
return this.name + '(' + this.args.join(', ') + ')';
23184
* Get LaTeX representation
23185
* @return {String} str
23187
FunctionNode.prototype.toTex = function() {
23188
return latex.toArgs(this);
23191
module.exports = FunctionNode;
23196
/***/ function(module, exports, __webpack_require__) {
23200
var keywords = __webpack_require__(337);
23206
if (!(this instanceof Node)) {
23207
throw new SyntaxError('Constructor must be called with the new operator');
23212
* Evaluate the node
23213
* @return {*} result
23215
// TODO: cleanup deprecated code one day. Deprecated since version 0.19.0
23216
Node.prototype.eval = function () {
23217
throw new Error('Node.eval is deprecated. ' +
23218
'Use Node.compile(math).eval([scope]) instead.');
23221
Node.prototype.type = 'Node';
23224
* Compile the node to javascript code
23225
* @param {Object} math math.js instance
23226
* @return {{eval: function}} expr Returns an object with a function 'eval',
23227
* which can be invoked as expr.eval([scope]),
23228
* where scope is an optional object with
23231
Node.prototype.compile = function (math) {
23232
if (!(math instanceof Object)) {
23233
throw new TypeError('Object expected for parameter math');
23236
// definitions globally available inside the closure of the compiled expressions
23238
math: _transform(math),
23239
_validateScope: _validateScope
23242
var code = this._compile(defs);
23244
var defsCode = Object.keys(defs).map(function (name) {
23245
return ' var ' + name + ' = defs["' + name + '"];';
23249
defsCode.join(' ') +
23251
' "eval": function (scope) {' +
23252
' if (scope) _validateScope(scope);' +
23253
' scope = scope || {};' +
23254
' return ' + code + ';' +
23258
var factory = new Function ('defs', factoryCode);
23259
return factory(defs);
23263
* Compile the node to javascript code
23264
* @param {Object} defs Object which can be used to define functions
23265
* and constants globally available inside the closure
23266
* of the compiled expression
23267
* @return {String} js
23270
Node.prototype._compile = function (defs) {
23271
// must be implemented by each of the Node implementations
23272
throw new Error('Cannot compile a Node interface');
23276
* Execute a callback for each of the child nodes of this node
23277
* @param {function(child: Node, path: string, parent: Node)} callback
23279
Node.prototype.forEach = function (callback) {
23280
// must be implemented by each of the Node implementations
23281
throw new Error('Cannot run forEach on a Node interface');
23285
* Create a new Node having it's childs be the results of calling
23286
* the provided callback function for each of the childs of the original node.
23287
* @param {function(child: Node, path: string, parent: Node): Node} callback
23288
* @returns {OperatorNode} Returns a transformed copy of the node
23290
Node.prototype.map = function (callback) {
23291
// must be implemented by each of the Node implementations
23292
throw new Error('Cannot run map on a Node interface');
23296
* Validate whether an object is a Node, for use with map
23297
* @param {Node} node
23298
* @returns {Node} Returns the input if it's a node, else throws an Error
23301
Node.prototype._ifNode = function (node) {
23302
if (!(node instanceof Node)) {
23303
throw new TypeError('Callback function must return a Node');
23310
* Recursively traverse all nodes in a node tree. Executes given callback for
23311
* this node and each of its child nodes.
23312
* @param {function(node: Node, path: string, parent: Node)} callback
23313
* A callback called for every node in the node tree.
23315
Node.prototype.traverse = function (callback) {
23316
// execute callback for itself
23317
callback(this, null, null);
23319
// recursively traverse over all childs of a node
23320
function _traverse (node, callback) {
23321
node.forEach(function(child, path, parent) {
23322
callback(child, path, parent);
23323
_traverse(child, callback);
23326
_traverse(this, callback);
23330
* Recursively transform a node tree via a transform function.
23332
* For example, to replace all nodes of type SymbolNode having name 'x' with a
23333
* ConstantNode with value 2:
23335
* var res = Node.transform(function (node, path, parent) {
23336
* if (node instanceof SymbolNode) && (node.name == 'x')) {
23337
* return new ConstantNode(2);
23344
* @param {function(node: Node, path: string, parent: Node) : Node} callback
23345
* A mapping function accepting a node, and returning
23346
* a replacement for the node or the original node.
23347
* Signature: callback(node: Node, index: string, parent: Node) : Node
23348
* @return {Node} Returns the original node or its replacement
23350
Node.prototype.transform = function (callback) {
23352
var replacement = callback(this, null, null);
23353
if (replacement !== this) {
23354
return replacement;
23357
// traverse over all childs
23358
function _transform (node, callback) {
23359
return node.map(function(child, path, parent) {
23360
var replacement = callback(child, path, parent);
23361
return (replacement !== child) ? replacement : _transform(child, callback);
23364
return _transform(this, callback);
23368
* Find any node in the node tree matching given filter function. For example, to
23369
* find all nodes of type SymbolNode having name 'x':
23371
* var results = Node.filter(function (node) {
23372
* return (node instanceof SymbolNode) && (node.name == 'x');
23375
* @param {function(node: Node, path: string, parent: Node) : Node} callback
23376
* A test function returning true when a node matches, and false
23377
* otherwise. Function signature:
23378
* callback(node: Node, index: string, parent: Node) : boolean
23379
* @return {Node[]} nodes An array with nodes matching given filter criteria
23381
Node.prototype.filter = function (callback) {
23384
this.traverse(function (node, path, parent) {
23385
if (callback(node, path, parent)) {
23393
// TODO: deprecated since version 1.1.0, remove this some day
23394
Node.prototype.find = function () {
23395
throw new Error('Function Node.find is deprecated. Use Node.filter instead.');
23398
// TODO: deprecated since version 1.1.0, remove this some day
23399
Node.prototype.match = function () {
23400
throw new Error('Function Node.match is deprecated. See functions Node.filter, Node.transform, Node.traverse.');
23404
* Create a clone of this node, a shallow copy
23407
Node.prototype.clone = function() {
23408
// must be implemented by each of the Node implementations
23409
throw new Error('Cannot clone a Node interface');
23413
* Get string representation
23416
Node.prototype.toString = function() {
23421
* Get LaTeX representation
23424
Node.prototype.toTex = function() {
23429
* Test whether an object is a Node
23430
* @param {*} object
23431
* @returns {boolean} isNode
23433
Node.isNode = function(object) {
23434
return object instanceof Node;
23438
* Validate the symbol names of a scope.
23439
* Throws an error when the scope contains an illegal symbol.
23440
* @param {Object} scope
23442
function _validateScope (scope) {
23443
for (var symbol in scope) {
23444
if (scope.hasOwnProperty(symbol)) {
23445
if (symbol in keywords) {
23446
throw new Error('Scope contains an illegal symbol, "' + symbol + '" is a reserved keyword');
23453
* Replace all functions having a transform function attached at property transform
23454
* with their transform.
23455
* @param {Object} math
23456
* @return {Object} transformed
23459
function _transform(math) {
23460
var transformed = Object.create(math);
23462
if (math.expression && math.expression.transform) {
23463
for (var name in math.expression.transform) {
23464
if (math.expression.transform.hasOwnProperty(name)) {
23465
transformed[name] = math.expression.transform[name];
23470
return transformed;
23473
module.exports = Node;
23478
/***/ function(module, exports, __webpack_require__) {
23482
var Node = __webpack_require__(180),
23483
ConstantNode = __webpack_require__(176),
23484
SymbolNode = __webpack_require__(183),
23485
FunctionNode = __webpack_require__(179),
23486
latex = __webpack_require__(338);
23489
* @constructor OperatorNode
23491
* An operator with two arguments, like 2+3
23493
* @param {String} op Operator name, for example '+'
23494
* @param {String} fn Function name, for example 'add'
23495
* @param {Node[]} args Operator arguments
23497
function OperatorNode (op, fn, args) {
23498
if (!(this instanceof OperatorNode)) {
23499
throw new SyntaxError('Constructor must be called with the new operator');
23502
// TODO: validate input
23505
this.args = args || [];
23508
OperatorNode.prototype = new Node();
23510
OperatorNode.prototype.type = 'OperatorNode';
23513
* Compile the node to javascript code
23514
* @param {Object} defs Object which can be used to define functions
23515
* or constants globally available for the compiled
23517
* @return {String} js
23520
OperatorNode.prototype._compile = function (defs) {
23521
if (!(this.fn in defs.math)) {
23522
throw new Error('Function ' + this.fn + ' missing in provided namespace "math"');
23525
var args = this.args.map(function (arg) {
23526
return arg._compile(defs);
23528
return 'math.' + this.fn + '(' + args.join(', ') + ')';
23532
* Execute a callback for each of the child nodes of this node
23533
* @param {function(child: Node, path: string, parent: Node)} callback
23535
OperatorNode.prototype.forEach = function (callback) {
23536
for (var i = 0; i < this.args.length; i++) {
23537
callback(this.args[i], 'args[' + i + ']', this);
23542
* Create a new OperatorNode having it's childs be the results of calling
23543
* the provided callback function for each of the childs of the original node.
23544
* @param {function(child: Node, path: string, parent: Node): Node} callback
23545
* @returns {OperatorNode} Returns a transformed copy of the node
23547
OperatorNode.prototype.map = function (callback) {
23549
for (var i = 0; i < this.args.length; i++) {
23550
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
23552
return new OperatorNode(this.op, this.fn, args);
23556
* Create a clone of this node, a shallow copy
23557
* @return {OperatorNode}
23559
OperatorNode.prototype.clone = function() {
23560
return new OperatorNode(this.op, this.fn, this.args.slice(0));
23564
* Get string representation
23565
* @return {String} str
23567
OperatorNode.prototype.toString = function() {
23568
var args = this.args;
23570
switch (args.length) {
23572
if (this.op == '-') {
23573
// special case: unary minus
23574
return '-' + args[0].toString();
23577
// for example '5!'
23578
return args[0].toString() + this.op;
23581
case 2: // for example '2+3'
23582
var lhs = args[0].toString();
23583
if (args[0] instanceof OperatorNode) {
23584
lhs = '(' + lhs + ')';
23586
var rhs = args[1].toString();
23587
if (args[1] instanceof OperatorNode) {
23588
rhs = '(' + rhs + ')';
23590
return lhs + ' ' + this.op + ' ' + rhs;
23592
default: // this should not occur. format as a function call
23593
return this.op + '(' + this.args.join(', ') + ')';
23598
* Get LaTeX representation
23599
* @return {String} str
23601
OperatorNode.prototype.toTex = function() {
23602
var args = this.args,
23603
mop = latex.toOperator(this.op),
23607
switch (args.length) {
23609
var operand = lp.toTex();
23611
case '-': //unary minus needs brackets around '-' and '+'
23612
if (lp instanceof OperatorNode && (lp.op === '-' || lp.op === '+')) {
23613
return this.op + latex.addBraces(operand, true);
23616
return this.op + operand;
23618
default: // fox example '5!'
23619
if (lp instanceof OperatorNode) {
23620
return latex.addBraces(operand, true) + this.op;
23622
return operand + this.op;
23625
case 2: // for example '2+3'
23626
var lhs = lp.toTex(),
23641
if (lp instanceof OperatorNode) {
23642
if (lp.op === '+' || lp.op === '-') {
23647
if (rp instanceof OperatorNode) {
23648
if (rp.op === '+' || rp.op === '-' || rp.op === '*') {
23653
if ((lp instanceof ConstantNode || lp instanceof OperatorNode) &&
23654
(rp instanceof ConstantNode || rp instanceof OperatorNode)) {
23664
if (rp instanceof OperatorNode) {
23665
if (rp.op === '+' | rp.op === '-' ) {
23672
if (lp instanceof OperatorNode || lp instanceof FunctionNode) {
23675
else if (lp instanceof SymbolNode) {
23682
rhs = latex.toUnit(rhs, true);
23686
lhs = latex.addBraces(lhs, lhb);
23687
rhs = latex.addBraces(rhs, rhb);
23689
return lop + lhs + mop + rhs + rop;
23691
default: // this should not occur. format as a function call
23692
return mop + '(' + this.args.map(latex.toSymbol).join(', ') + ')';
23696
module.exports = OperatorNode;
23701
/***/ function(module, exports, __webpack_require__) {
23705
var Node = __webpack_require__(180);
23707
var isNode = Node.isNode;
23710
* @constructor RangeNode
23713
* @param {Node} start included lower-bound
23714
* @param {Node} end included lower-bound
23715
* @param {Node} [step] optional step
23717
function RangeNode (start, end, step) {
23718
if (!(this instanceof RangeNode)) {
23719
throw new SyntaxError('Constructor must be called with the new operator');
23723
if (!isNode(start)) throw new TypeError('Node expected');
23724
if (!isNode(end)) throw new TypeError('Node expected');
23725
if (step && !isNode(step)) throw new TypeError('Node expected');
23726
if (arguments.length > 3) throw new Error('Too many arguments');
23728
this.start = start; // included lower-bound
23729
this.end = end; // included upper-bound
23730
this.step = step || null; // optional step
23733
RangeNode.prototype = new Node();
23735
RangeNode.prototype.type = 'RangeNode';
23738
* Compile the node to javascript code
23739
* @param {Object} defs Object which can be used to define functions
23740
* or constants globally available for the compiled
23742
* @return {String} js
23745
RangeNode.prototype._compile = function (defs) {
23746
return 'math.range(' +
23747
this.start._compile(defs) + ', ' +
23748
this.end._compile(defs) +
23749
(this.step ? (', ' + this.step._compile(defs)) : '') +
23754
* Execute a callback for each of the child nodes of this node
23755
* @param {function(child: Node, path: string, parent: Node)} callback
23757
RangeNode.prototype.forEach = function (callback) {
23758
callback(this.start, 'start', this);
23759
callback(this.end, 'end', this);
23761
callback(this.step, 'step', this);
23766
* Create a new RangeNode having it's childs be the results of calling
23767
* the provided callback function for each of the childs of the original node.
23768
* @param {function(child: Node, path: string, parent: Node): Node} callback
23769
* @returns {RangeNode} Returns a transformed copy of the node
23771
RangeNode.prototype.map = function (callback) {
23772
return new RangeNode(
23773
this._ifNode(callback(this.start, 'start', this)),
23774
this._ifNode(callback(this.end, 'end', this)),
23775
this.step && this._ifNode(callback(this.step, 'step', this))
23780
* Create a clone of this node, a shallow copy
23781
* @return {RangeNode}
23783
RangeNode.prototype.clone = function() {
23784
return new RangeNode(this.start, this.end, this.step && this.step);
23788
* Get string representation
23789
* @return {String} str
23791
RangeNode.prototype.toString = function() {
23792
// format the range like "start:step:end"
23793
var str = this.start.toString();
23795
str += ':' + this.step.toString();
23797
str += ':' + this.end.toString();
23803
* Get LaTeX representation
23804
* @return {String} str
23806
RangeNode.prototype.toTex = function() {
23807
var str = this.start.toTex();
23809
str += ':' + this.step.toTex();
23811
str += ':' + this.end.toTex();
23816
module.exports = RangeNode;
23821
/***/ function(module, exports, __webpack_require__) {
23825
var Node = __webpack_require__(180),
23826
Unit = __webpack_require__(11),
23828
latex = __webpack_require__(338),
23829
isString = __webpack_require__(205).isString;
23832
* @constructor SymbolNode
23834
* A symbol node can hold and resolve a symbol
23835
* @param {String} name
23838
function SymbolNode(name) {
23839
if (!(this instanceof SymbolNode)) {
23840
throw new SyntaxError('Constructor must be called with the new operator');
23844
if (!isString(name)) throw new TypeError('String expected for parameter "name"');
23849
SymbolNode.prototype = new Node();
23851
SymbolNode.prototype.type = 'SymbolNode';
23854
* Compile the node to javascript code
23855
* @param {Object} defs Object which can be used to define functions
23856
* or constants globally available for the compiled
23858
* @return {String} js
23861
SymbolNode.prototype._compile = function (defs) {
23862
// add a function to the definitions
23863
defs['undef'] = undef;
23864
defs['Unit'] = Unit;
23866
if (this.name in defs.math) {
23867
return '("' + this.name + '" in scope ? scope["' + this.name + '"] : math["' + this.name + '"])';
23871
'"' + this.name + '" in scope ? scope["' + this.name + '"] : ' +
23872
(Unit.isValuelessUnit(this.name) ?
23873
'new Unit(null, "' + this.name + '")' :
23874
'undef("' + this.name + '")') +
23880
* Execute a callback for each of the child nodes of this node
23881
* @param {function(child: Node, path: string, parent: Node)} callback
23883
SymbolNode.prototype.forEach = function (callback) {
23884
// nothing to do, we don't have childs
23888
* Create a new SymbolNode having it's childs be the results of calling
23889
* the provided callback function for each of the childs of the original node.
23890
* @param {function(child: Node, path: string, parent: Node) : Node} callback
23891
* @returns {SymbolNode} Returns a clone of the node
23893
SymbolNode.prototype.map = function (callback) {
23894
return this.clone();
23898
* Throws an error 'Undefined symbol {name}'
23899
* @param {String} name
23901
function undef (name) {
23902
throw new Error('Undefined symbol ' + name);
23906
* Create a clone of this node, a shallow copy
23907
* @return {SymbolNode}
23909
SymbolNode.prototype.clone = function() {
23910
return new SymbolNode(this.name);
23914
* Get string representation
23915
* @return {String} str
23918
SymbolNode.prototype.toString = function() {
23923
* Get LaTeX representation
23924
* @return {String} str
23927
SymbolNode.prototype.toTex = function() {
23928
return latex.toSymbol(this.name);
23931
module.exports = SymbolNode;
23936
/***/ function(module, exports, __webpack_require__) {
23940
var Node = __webpack_require__(180),
23941
IndexNode = __webpack_require__(177);
23944
* @constructor UpdateNode
23946
* Update a matrix subset, like A[2,3] = 4.5
23948
* @param {IndexNode} index IndexNode containing symbol and ranges
23949
* @param {Node} expr The expression defining the symbol
23951
function UpdateNode(index, expr) {
23952
if (!(this instanceof UpdateNode)) {
23953
throw new SyntaxError('Constructor must be called with the new operator');
23956
if (!(index instanceof IndexNode)) {
23957
throw new TypeError('Expected IndexNode for parameter "index"');
23959
if (!(expr instanceof Node)) {
23960
throw new TypeError('Expected Node for parameter "expr"');
23963
this.index = index;
23967
UpdateNode.prototype = new Node();
23969
UpdateNode.prototype.type = 'UpdateNode';
23972
* Compile the node to javascript code
23973
* @param {Object} defs Object which can be used to define functions
23974
* or constants globally available for the compiled
23976
* @return {String} js
23979
UpdateNode.prototype._compile = function (defs) {
23980
return 'scope["' + this.index.objectName() + '\"] = ' +
23981
this.index.compileSubset(defs, this.expr._compile(defs));
23985
* Execute a callback for each of the child nodes of this node
23986
* @param {function(child: Node, path: string, parent: Node)} callback
23988
UpdateNode.prototype.forEach = function (callback) {
23989
callback(this.index, 'index', this);
23990
callback(this.expr, 'expr', this);
23994
* Create a new UpdateNode having it's childs be the results of calling
23995
* the provided callback function for each of the childs of the original node.
23996
* @param {function(child: Node, path: string, parent: Node): Node} callback
23997
* @returns {UpdateNode} Returns a transformed copy of the node
23999
UpdateNode.prototype.map = function (callback) {
24000
return new UpdateNode(
24001
this._ifNode(callback(this.index, 'index', this)),
24002
this._ifNode(callback(this.expr, 'expr', this))
24007
* Create a clone of this node, a shallow copy
24008
* @return {UpdateNode}
24010
UpdateNode.prototype.clone = function() {
24011
return new UpdateNode(this.index, this.expr);
24015
* Get string representation
24018
UpdateNode.prototype.toString = function() {
24019
return this.index.toString() + ' = ' + this.expr.toString();
24023
* Get LaTeX representation
24026
UpdateNode.prototype.toTex = function() {
24027
return this.index.toTex() + ' = ' + this.expr.toTex();
24030
module.exports = UpdateNode;
24035
/***/ function(module, exports, __webpack_require__) {
24039
'category': 'Constants',
24043
'description': 'Euler\'s number, the base of the natural logarithm. Approximately equal to 2.71828',
24056
/***/ function(module, exports, __webpack_require__) {
24060
'category': 'Constants',
24064
'description': 'Boolean value false',
24068
'seealso': ['true']
24074
/***/ function(module, exports, __webpack_require__) {
24078
'category': 'Constants',
24082
'description': 'Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.',
24094
/***/ function(module, exports, __webpack_require__) {
24097
'name': 'Infinity',
24098
'category': 'Constants',
24102
'description': 'Infinity, a number which is larger than the maximum number that can be handled by a floating point number.',
24113
/***/ function(module, exports, __webpack_require__) {
24117
'category': 'Constants',
24121
'description': 'Returns the natural logarithm of 2, approximately equal to 0.693',
24132
/***/ function(module, exports, __webpack_require__) {
24136
'category': 'Constants',
24140
'description': 'Returns the natural logarithm of 10, approximately equal to 2.302',
24151
/***/ function(module, exports, __webpack_require__) {
24155
'category': 'Constants',
24159
'description': 'Returns the base-2 logarithm of E, approximately equal to 1.442',
24170
/***/ function(module, exports, __webpack_require__) {
24174
'category': 'Constants',
24178
'description': 'Returns the base-10 logarithm of E, approximately equal to 0.434',
24189
/***/ function(module, exports, __webpack_require__) {
24193
'category': 'Constants',
24197
'description': 'Not a number',
24208
/***/ function(module, exports, __webpack_require__) {
24212
'category': 'Constants',
24216
'description': 'Value null',
24220
'seealso': ['true', 'false']
24226
/***/ function(module, exports, __webpack_require__) {
24230
'category': 'Constants',
24234
'description': 'The number pi is a mathematical constant that is the ratio of a circle\'s circumference to its diameter, and is approximately equal to 3.14159',
24245
/***/ function(module, exports, __webpack_require__) {
24249
'category': 'Constants',
24253
'description': 'Phi is the golden ratio. Two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities. Phi is defined as `(1 + sqrt(5)) / 2` and is approximately 1.618034...',
24263
/***/ function(module, exports, __webpack_require__) {
24267
'category': 'Constants',
24271
'description': 'Returns the square root of 1/2, approximately equal to 0.707',
24282
/***/ function(module, exports, __webpack_require__) {
24286
'category': 'Constants',
24290
'description': 'Returns the square root of 2, approximately equal to 1.414',
24301
/***/ function(module, exports, __webpack_require__) {
24305
'category': 'Constants',
24309
'description': 'Tau is the ratio constant of a circle\'s circumference to radius, equal to 2 * pi, approximately 6.2832.',
24320
/***/ function(module, exports, __webpack_require__) {
24324
'category': 'Constants',
24328
'description': 'Boolean value true',
24332
'seealso': ['false']
24338
/***/ function(module, exports, __webpack_require__) {
24342
'category': 'Constants',
24346
'description': 'A string with the version number of math.js',
24356
/***/ function(module, exports, __webpack_require__) {
24362
"./filter.js": 156,
24364
"./forEach.js": 163,
24366
"./format.js": 157,
24368
"./import.js": 158,
24378
function webpackContext(req) {
24379
return __webpack_require__(webpackContextResolve(req));
24381
function webpackContextResolve(req) {
24382
return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
24384
webpackContext.keys = function webpackContextKeys() {
24385
return Object.keys(map);
24387
webpackContext.resolve = webpackContextResolve;
24388
module.exports = webpackContext;
24389
webpackContext.id = 202;
24394
/***/ function(module, exports, __webpack_require__) {
24396
var DimensionError = __webpack_require__(168);
24397
var IndexError = __webpack_require__(169);
24400
* Transform zero-based indices to one-based indices in errors
24401
* @param {Error} err
24402
* @returns {Error} Returns the transformed error
24404
exports.transform = function (err) {
24405
if (err instanceof IndexError) {
24406
return new IndexError(err.index + 1, err.min + 1, err.max + 1);
24415
/***/ function(module, exports, __webpack_require__) {
24420
* Test whether value is a Boolean
24422
* @return {Boolean} isBoolean
24424
exports.isBoolean = function(value) {
24425
return (value instanceof Boolean) || (typeof value == 'boolean');
24431
/***/ function(module, exports, __webpack_require__) {
24435
var number = __webpack_require__(3);
24436
var bignumber = __webpack_require__(164);
24437
var BigNumber = __webpack_require__(5);
24440
* Test whether value is a String
24442
* @return {Boolean} isString
24444
exports.isString = function(value) {
24445
return (value instanceof String) || (typeof value == 'string');
24449
* Check if a text ends with a certain string.
24450
* @param {String} text
24451
* @param {String} search
24453
exports.endsWith = function(text, search) {
24454
var start = text.length - search.length;
24455
var end = text.length;
24456
return (text.substring(start, end) === search);
24460
* Format a value of any type into a string.
24463
* math.format(value)
24464
* math.format(value, precision)
24466
* If value is a function, the returned string is 'function' unless the function
24467
* has a property `description`, in that case this properties value is returned.
24470
* math.format(2/7); // '0.2857142857142857'
24471
* math.format(math.pi, 3); // '3.14'
24472
* math.format(new Complex(2, 3)); // '2 + 3i'
24473
* math.format('hello'); // '"hello"'
24475
* @param {*} value Value to be stringified
24476
* @param {Object | Number | Function} [options] Formatting options. See
24477
* lib/util/number:format for a
24478
* description of the available
24480
* @return {String} str
24482
exports.format = function(value, options) {
24483
if (number.isNumber(value)) {
24484
return number.format(value, options);
24487
if (value instanceof BigNumber) {
24488
return bignumber.format(value, options);
24491
if (Array.isArray(value)) {
24492
return formatArray(value, options);
24495
if (exports.isString(value)) {
24496
return '"' + value + '"';
24499
if (typeof value === 'function') {
24500
return value.syntax ? value.syntax + '' : 'function';
24503
if (value instanceof Object) {
24504
if (typeof value.format === 'function') {
24505
return value.format(options);
24508
return value.toString();
24512
return String(value);
24516
* Recursively format an n-dimensional matrix
24517
* Example output: "[[1, 2], [3, 4]]"
24518
* @param {Array} array
24519
* @param {Object | Number | Function} [options] Formatting options. See
24520
* lib/util/number:format for a
24521
* description of the available
24523
* @returns {String} str
24525
function formatArray (array, options) {
24526
if (Array.isArray(array)) {
24528
var len = array.length;
24529
for (var i = 0; i < len; i++) {
24533
str += formatArray(array[i], options);
24539
return exports.format(array, options);
24546
/***/ function(module, exports, __webpack_require__) {
24550
'category': 'Arithmetic',
24554
'description': 'Compute the absolute value.',
24559
'seealso': ['sign']
24565
/***/ function(module, exports, __webpack_require__) {
24569
'category': 'Operators',
24574
'description': 'Add two values.',
24579
'"hello" + " world"',
24590
/***/ function(module, exports, __webpack_require__) {
24594
'category': 'Arithmetic',
24599
'Round a value towards plus infinity. If x is complex, both real and imaginary part are rounded towards plus infinity.',
24605
'seealso': ['floor', 'fix', 'round']
24611
/***/ function(module, exports, __webpack_require__) {
24615
'category': 'Arithmetic',
24619
'description': 'Compute the cube of a value. The cube of x is x * x * x.',
24635
/***/ function(module, exports, __webpack_require__) {
24639
'category': 'Operators',
24644
'description': 'Divide two values.',
24661
/***/ function(module, exports, __webpack_require__) {
24664
'name': 'dotDivide',
24665
'category': 'Operators',
24670
'description': 'Divide two values element wise.',
24672
'a = [1, 2, 3; 4, 5, 6]',
24673
'b = [2, 1, 1; 3, 2, 5]',
24686
/***/ function(module, exports, __webpack_require__) {
24689
'name': 'dotMultiply',
24690
'category': 'Operators',
24693
'dotMultiply(x, y)'
24695
'description': 'Multiply two values element wise.',
24697
'a = [1, 2, 3; 4, 5, 6]',
24698
'b = [2, 1, 1; 3, 2, 5]',
24711
/***/ function(module, exports, __webpack_require__) {
24715
'category': 'Operators',
24721
'Calculates the power of x to y element wise.',
24723
'a = [1, 2, 3; 4, 5, 6]',
24734
/***/ function(module, exports, __webpack_require__) {
24738
'category': 'Arithmetic',
24742
'description': 'Calculate the exponent of a value.',
24748
'(exp(i*x) == cos(x) + i*sin(x)) # Euler\'s formula'
24759
/***/ function(module, exports, __webpack_require__) {
24763
'category': 'Arithmetic',
24768
'Round a value towards zero. If x is complex, both real and imaginary part are rounded towards zero.',
24775
'seealso': ['ceil', 'floor', 'round']
24781
/***/ function(module, exports, __webpack_require__) {
24785
'category': 'Arithmetic',
24790
'Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.',
24796
'seealso': ['ceil', 'fix', 'round']
24802
/***/ function(module, exports, __webpack_require__) {
24806
'category': 'Arithmetic',
24809
'gcd(a, b, c, ...)'
24811
'description': 'Compute the greatest common divisor.',
24817
'seealso': [ 'lcm', 'xgcd' ]
24823
/***/ function(module, exports, __webpack_require__) {
24827
'category': 'Arithmetic',
24831
'description': 'Compute the least common multiple.',
24837
'seealso': [ 'gcd' ]
24843
/***/ function(module, exports, __webpack_require__) {
24847
'category': 'Arithmetic',
24852
'description': 'Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).',
24859
'log(10000) / log(10)',
24860
'b = log(1024, 2)',
24871
/***/ function(module, exports, __webpack_require__) {
24875
'category': 'Arithmetic',
24879
'description': 'Compute the 10-base logarithm of a value.',
24884
'log(10000) / log(10)',
24896
/***/ function(module, exports, __webpack_require__) {
24900
'category': 'Operators',
24907
'Calculates the modulus, the remainder of an integer division.',
24912
'function isOdd(x) = x % 2',
24916
'seealso': ['divide']
24922
/***/ function(module, exports, __webpack_require__) {
24925
'name': 'multiply',
24926
'category': 'Operators',
24931
'description': 'multiply two values.',
24947
/***/ function(module, exports, __webpack_require__) {
24951
'category': 'Arithmetic',
24956
'description': 'Calculate the norm of a number, vector or matrix.',
24961
'norm([1, 2, -3], Infinity)',
24962
'norm([1, 2, -3], -Infinity)',
24964
'norm([[1, 2], [3, 4]], 1)',
24965
'norm([[1, 2], [3, 4]], \'inf\')',
24966
'norm([[1, 2], [3, 4]], \'fro\')'
24973
/***/ function(module, exports, __webpack_require__) {
24977
'category': 'Arithmetic',
24982
'description': 'Calculate the nth root of a value. ' +
24983
'The principal nth root of a positive real number A, ' +
24984
'is the positive real solution of the equation "x^root = A".',
24999
/***/ function(module, exports, __webpack_require__) {
25003
'category': 'Operators',
25009
'Calculates the power of x to y, x^y.',
25015
'seealso': [ 'multiply' ]
25021
/***/ function(module, exports, __webpack_require__) {
25025
'category': 'Arithmetic',
25031
'round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.',
25038
'round(123.45678, 2)'
25040
'seealso': ['ceil', 'floor', 'fix']
25046
/***/ function(module, exports, __webpack_require__) {
25050
'category': 'Arithmetic',
25055
'Compute the sign of a value. The sign of a value x is 1 when x>1, -1 when x<0, and 0 when x=0.',
25069
/***/ function(module, exports, __webpack_require__) {
25073
'category': 'Arithmetic',
25078
'Compute the square root value. If x = y * y, then y is the square root of x.',
25093
/***/ function(module, exports, __webpack_require__) {
25097
'category': 'Arithmetic',
25102
'Compute the square of a value. The square of x is x * x.',
25120
/***/ function(module, exports, __webpack_require__) {
25123
'name': 'subtract',
25124
'category': 'Operators',
25129
'description': 'subtract two values.',
25145
/***/ function(module, exports, __webpack_require__) {
25148
'name': 'unaryMinus',
25149
'category': 'Operators',
25155
'Inverse the sign of a value. Converts booleans and strings to numbers.',
25162
'add', 'subtract', 'unaryPlus'
25169
/***/ function(module, exports, __webpack_require__) {
25172
'name': 'unaryPlus',
25173
'category': 'Operators',
25179
'Converts booleans and strings to numbers.',
25185
'add', 'subtract', 'unaryMinus'
25192
/***/ function(module, exports, __webpack_require__) {
25196
'category': 'Arithmetic',
25200
'description': 'Calculate the extended greatest common divisor for two values',
25204
'xgcd(36163, 21199)'
25206
'seealso': [ 'gcd', 'lcm' ]
25212
/***/ function(module, exports, __webpack_require__) {
25216
'category': 'Bitwise',
25221
'description': 'Bitwise AND operation. Performs the logical AND operation on each pair of the corresponding bits of the two given values by multiplying them. If both bits in the compared position are 1, the bit in the resulting binary representation is 1, otherwise, the result is 0',
25228
'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift'
25235
/***/ function(module, exports, __webpack_require__) {
25239
'category': 'Bitwise',
25244
'description': 'Bitwise NOT operation. Performs a logical negation on each bit of the given value. Bits that are 0 become 1, and those that are 1 become 0.',
25248
'bitNot([2, -3, 4])'
25251
'bitAnd', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift'
25258
/***/ function(module, exports, __webpack_require__) {
25262
'category': 'Bitwise',
25267
'description': 'Bitwise OR operation. Performs the logical inclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if the first bit is 1 or the second bit is 1 or both bits are 1, otherwise, the result is 0.',
25270
'bitOr([1, 2, 3], 4)'
25273
'bitAnd', 'bitNot', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift'
25280
/***/ function(module, exports, __webpack_require__) {
25284
'category': 'Bitwise',
25288
'description': 'Bitwise XOR operation, exclusive OR. Performs the logical exclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1.',
25291
'bitXor([2, 3, 4], 4)'
25294
'bitAnd', 'bitNot', 'bitOr', 'leftShift', 'rightArithShift', 'rightLogShift'
25301
/***/ function(module, exports, __webpack_require__) {
25304
'name': 'leftShift',
25305
'category': 'Bitwise',
25310
'description': 'Bitwise left logical shift of a value x by y number of bits.',
25316
'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'rightArithShift', 'rightLogShift'
25323
/***/ function(module, exports, __webpack_require__) {
25326
'name': 'rightArithShift',
25327
'category': 'Bitwise',
25332
'description': 'Bitwise right arithmetic shift of a value x by y number of bits.',
25339
'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightLogShift'
25346
/***/ function(module, exports, __webpack_require__) {
25349
'name': 'rightLogShift',
25350
'category': 'Bitwise',
25355
'description': 'Bitwise right logical shift of a value x by y number of bits.',
25362
'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift'
25369
/***/ function(module, exports, __webpack_require__) {
25373
'category': 'Complex',
25378
'Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).',
25395
/***/ function(module, exports, __webpack_require__) {
25399
'category': 'Complex',
25404
'Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.',
25421
/***/ function(module, exports, __webpack_require__) {
25425
'category': 'Complex',
25429
'description': 'Get the real part of a complex number.',
25447
/***/ function(module, exports, __webpack_require__) {
25451
'category': 'Complex',
25455
'description': 'Get the imaginary part of a complex number.',
25473
/***/ function(module, exports, __webpack_require__) {
25476
'name': 'bignumber',
25477
'category': 'Type',
25482
'Create a big number from a number or string.',
25485
'bignumber(0.1) + bignumber(0.2)',
25486
'bignumber("7.2")',
25487
'bignumber("7.2e500")',
25488
'bignumber([0.1, 0.2, 0.3])'
25491
'boolean', 'complex', 'index', 'matrix', 'string', 'unit'
25498
/***/ function(module, exports, __webpack_require__) {
25502
'category': 'Type',
25508
'Convert a string or number into a boolean.',
25514
'boolean("false")',
25515
'boolean([1, 0, 1, 1])'
25518
'bignumber', 'complex', 'index', 'matrix', 'number', 'string', 'unit'
25525
/***/ function(module, exports, __webpack_require__) {
25529
'category': 'Type',
25536
'Create a complex number.',
25540
'complex("7 - 2i")'
25543
'bignumber', 'boolean', 'index', 'matrix', 'number', 'string', 'unit'
25550
/***/ function(module, exports, __webpack_require__) {
25554
'category': 'Type',
25558
'[start:step:end]',
25559
'[start1, start 2, ...]',
25560
'[start1:end1, start2:end2, ...]',
25561
'[start1:step1:end1, start2:step2:end2, ...]'
25564
'Create an index to get or replace a subset of a matrix',
25568
'A = [1, 2, 3; 4, 5, 6]',
25571
'A[0:2, 0:2] = ones(2, 2)'
25574
'bignumber', 'boolean', 'complex', 'matrix,', 'number', 'range', 'string', 'unit'
25581
/***/ function(module, exports, __webpack_require__) {
25585
'category': 'Type',
25588
'[a1, b1, ...; a2, b2, ...]',
25593
'Create a matrix.',
25597
'[1, 2, 3; 4, 5, 6]',
25602
'bignumber', 'boolean', 'complex', 'index', 'number', 'string', 'unit'
25609
/***/ function(module, exports, __webpack_require__) {
25613
'category': 'Type',
25619
'Create a number or convert a string or boolean into a number.',
25627
'number([true, false, true, true])',
25628
'number("52cm", "m")'
25631
'bignumber', 'boolean', 'complex', 'index', 'matrix', 'string', 'unit'
25638
/***/ function(module, exports, __webpack_require__) {
25642
'category': 'Type',
25648
'Create a string or convert a value to a string',
25655
'bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'unit'
25662
/***/ function(module, exports, __webpack_require__) {
25666
'category': 'Type',
25669
'unit(value, unit)',
25677
'unit(7.1, "kilogram")',
25681
'bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'string'
25688
/***/ function(module, exports, __webpack_require__) {
25692
'category': 'Expression',
25694
'eval(expression)',
25695
'eval([expr1, expr2, expr3, ...])'
25697
'description': 'Evaluate an expression or an array with expressions.',
25700
'eval("sqrt(" + 4 + ")")'
25708
/***/ function(module, exports, __webpack_require__) {
25712
'category': 'Expression',
25717
'description': 'Display documentation on a function or data type.',
25728
/***/ function(module, exports, __webpack_require__) {
25732
'category': 'Logical',
25737
'description': 'Logical and. Test whether two values are both defined with a nonzero/nonempty value.',
25751
/***/ function(module, exports, __webpack_require__) {
25755
'category': 'Logical',
25761
'description': 'Logical not. Flips the boolean value of given argument.',
25776
/***/ function(module, exports, __webpack_require__) {
25780
'category': 'Logical',
25785
'description': 'Logical or. Test if at least one value is defined with a nonzero/nonempty value.',
25792
'not', 'and', 'xor'
25799
/***/ function(module, exports, __webpack_require__) {
25803
'category': 'Logical',
25808
'description': 'Logical exclusive or, xor. Test whether one and only one value is defined with a nonzero/nonempty value.',
25823
/***/ function(module, exports, __webpack_require__) {
25827
'category': 'Matrix',
25829
'concat(A, B, C, ...)',
25830
'concat(A, B, C, ..., dim)'
25832
'description': 'Concatenate matrices. By default, the matrices are concatenated by the last dimension. The dimension on which to concatenate can be provided as last argument.',
25834
'A = [1, 2; 5, 6]',
25835
'B = [3, 4; 7, 8]',
25841
'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
25848
/***/ function(module, exports, __webpack_require__) {
25852
'category': 'Matrix',
25856
'description': 'Calculate the cross product for two vectors in three dimensional space.',
25858
'cross([1, 1, 0], [0, 1, 1])',
25859
'cross([3, -3, 1], [4, 9, 2])',
25860
'cross([2, 3, 4], [5, 6, 7])'
25871
/***/ function(module, exports, __webpack_require__) {
25875
'category': 'Matrix',
25879
'description': 'Calculate the determinant of a matrix',
25881
'det([1, 2; 3, 4])',
25882
'det([-2, 2, 3; -1, 1, 3; 2, 0, -1])'
25885
'concat', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
25892
/***/ function(module, exports, __webpack_require__) {
25896
'category': 'Matrix',
25901
'description': 'Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned. When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.',
25905
'a = [1, 2, 3; 4, 5, 6; 7, 8, 9]',
25909
'concat', 'det', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
25916
/***/ function(module, exports, __webpack_require__) {
25920
'category': 'Matrix',
25924
'description': 'Calculate the dot product of two vectors. ' +
25925
'The dot product of A = [a1, a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] ' +
25926
'is defined as dot(A, B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn',
25928
'dot([2, 4, 1], [2, 2, 3])',
25929
'[2, 4, 1] * [2, 2, 3]'
25940
/***/ function(module, exports, __webpack_require__) {
25944
'category': 'Matrix',
25951
'description': 'Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.',
25955
'a = [1, 2, 3; 4, 5, 6]',
25959
'concat', 'det', 'diag', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
25966
/***/ function(module, exports, __webpack_require__) {
25970
'category': 'Matrix',
25974
'description': 'Flatten a multi dimensional matrix into a single dimensional matrix.',
25976
'a = [1, 2, 3; 4, 5, 6]',
25982
'concat', 'resize', 'size', 'squeeze'
25989
/***/ function(module, exports, __webpack_require__) {
25993
'category': 'Matrix',
25997
'description': 'Calculate the inverse of a matrix',
25999
'inv([1, 2; 3, 4])',
26004
'concat', 'det', 'diag', 'eye', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
26011
/***/ function(module, exports, __webpack_require__) {
26015
'category': 'Matrix',
26019
'ones(m, n, p, ...)',
26022
'ones([m, n, p, ...])',
26025
'description': 'Create a matrix containing ones.',
26029
'ones([2,3]) * 4.5',
26030
'a = [1, 2, 3; 4, 5, 6]',
26034
'concat', 'det', 'diag', 'eye', 'inv', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
26041
/***/ function(module, exports, __webpack_require__) {
26045
'category': 'Type',
26049
'range(start, end)',
26050
'range(start, end, step)',
26054
'Create a range. Lower bound of the range is included, upper bound is excluded.',
26061
'a = [1, 2, 3, 4; 5, 6, 7, 8]',
26065
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
26072
/***/ function(module, exports, __webpack_require__) {
26076
'category': 'Matrix',
26079
'resize(x, size, defaultValue)'
26081
'description': 'Resize a matrix.',
26083
'resize([1,2,3,4,5], [3])',
26084
'resize([1,2,3], [5])',
26085
'resize([1,2,3], [5], -1)',
26086
'resize(2, [2, 3])',
26087
'resize("hello", [8], "!")'
26090
'size', 'subset', 'squeeze'
26097
/***/ function(module, exports, __webpack_require__) {
26101
'category': 'Matrix',
26105
'description': 'Calculate the size of a matrix.',
26108
'size("hello world")',
26109
'a = [1, 2; 3, 4; 5, 6]',
26114
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
26121
/***/ function(module, exports, __webpack_require__) {
26125
'category': 'Matrix',
26129
'description': 'Remove inner and outer singleton dimensions from a matrix.',
26131
'a = zeros(3,2,1)',
26132
'size(squeeze(a))',
26133
'b = zeros(1,1,3)',
26137
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'subset', 'trace', 'transpose', 'zeros'
26144
/***/ function(module, exports, __webpack_require__) {
26148
'category': 'Matrix',
26151
'value(index) = replacement',
26152
'subset(value, [index])',
26153
'subset(value, [index], replacement)'
26155
'description': 'Get or set a subset of a matrix or string. ' +
26156
'Indexes are one-based. ' +
26157
'Both the ranges lower-bound and upper-bound are included.',
26159
'd = [1, 2; 3, 4]',
26161
'e[1, 1:2] = [5, 6]',
26162
'e[2, :] = [7, 8]',
26168
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'trace', 'transpose', 'zeros'
26175
/***/ function(module, exports, __webpack_require__) {
26179
'category': 'Matrix',
26183
'description': 'Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.',
26185
'A = [1, 2, 3; -1, 2, 3; 2, 0, 3]',
26189
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
26196
/***/ function(module, exports, __webpack_require__) {
26199
'name': 'transpose',
26200
'category': 'Matrix',
26205
'description': 'Transpose a matrix',
26207
'a = [1, 2, 3; 4, 5, 6]',
26212
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'zeros'
26219
/***/ function(module, exports, __webpack_require__) {
26223
'category': 'Matrix',
26227
'zeros(m, n, p, ...)',
26230
'zeros([m, n, p, ...])',
26233
'description': 'Create a matrix containing zeros.',
26237
'a = [1, 2, 3; 4, 5, 6]',
26241
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose'
26248
/***/ function(module, exports, __webpack_require__) {
26251
'name': 'combinations',
26252
'category': 'Probability',
26254
'combinations(n, k)'
26256
'description': 'Compute the number of combinations of n items taken k at a time',
26258
'combinations(7, 5)'
26260
'seealso': ['permutations', 'factorial']
26266
/***/ function(module, exports, __webpack_require__) {
26269
'name': 'factorial',
26270
'category': 'Probability',
26275
'description': 'Compute the factorial of a value',
26278
'5 * 4 * 3 * 2 * 1',
26281
'seealso': ['combinations', 'permutations', 'gamma']
26287
/***/ function(module, exports, __webpack_require__) {
26291
'category': 'Probability',
26295
'description': 'Compute the gamma function. For small values, the Lanczos approximation is used, and for large values the extended Stirling approximation.',
26302
'seealso': ['factorial']
26308
/***/ function(module, exports, __webpack_require__) {
26311
'name': 'permutations',
26312
'category': 'Probability',
26315
'permutations(n, k)'
26317
'description': 'Compute the number of permutations of n items taken k at a time',
26320
'permutations(5, 3)'
26322
'seealso': ['combinations', 'factorial']
26328
/***/ function(module, exports, __webpack_require__) {
26331
'name': 'pickRandom',
26332
'category': 'Probability',
26334
'pickRandom(array)'
26337
'Pick a random entry from a given array.',
26339
'pickRandom(0:10)',
26340
'pickRandom([1, 3, 1, 6])'
26342
'seealso': ['random', 'randomInt']
26348
/***/ function(module, exports, __webpack_require__) {
26352
'category': 'Probability',
26356
'random(min, max)',
26358
'random(size, max)',
26359
'random(size, min, max)'
26362
'Return a random number.',
26368
'seealso': ['pickRandom', 'randomInt']
26374
/***/ function(module, exports, __webpack_require__) {
26378
'category': 'Probability',
26382
'randInt(min, max)',
26384
'randInt(size, max)',
26385
'randInt(size, min, max)'
26388
'Return a random integer number',
26392
'randInt([2, 3], 10)'
26394
'seealso': ['pickRandom', 'random']
26399
/***/ function(module, exports, __webpack_require__) {
26403
'category': 'Relational',
26408
'Compare two values. Returns 1 if x is larger than y, -1 if x is smaller than y, and 0 if x and y are equal.',
26413
'compare(5cm, 40mm)',
26414
'compare(2, [1, 2, 3])'
26417
'equal', 'unequal', 'smaller', 'smallerEq', 'largerEq'
26424
/***/ function(module, exports, __webpack_require__) {
26427
'name': 'deepEqual',
26428
'category': 'Relational',
26433
'Check equality of two matrices element wise. Returns true if the size of both matrices is equal and when and each of the elements are equal.',
26435
'[1,3,4] == [1,3,4]',
26439
'equal', 'unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare'
26446
/***/ function(module, exports, __webpack_require__) {
26450
'category': 'Relational',
26456
'Check equality of two values. Returns true if the values are equal, and false if not.',
26466
'unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual'
26473
/***/ function(module, exports, __webpack_require__) {
26477
'category': 'Relational',
26483
'Check if value x is larger than y. Returns true if x is larger than y, and false if not.',
26494
'equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compare'
26501
/***/ function(module, exports, __webpack_require__) {
26504
'name': 'largerEq',
26505
'category': 'Relational',
26511
'Check if value x is larger or equal to y. Returns true if x is larger or equal to y, and false if not.',
26520
'equal', 'unequal', 'smallerEq', 'smaller', 'largerEq', 'compare'
26527
/***/ function(module, exports, __webpack_require__) {
26531
'category': 'Relational',
26537
'Check if value x is smaller than value y. Returns true if x is smaller than y, and false if not.',
26547
'equal', 'unequal', 'larger', 'smallerEq', 'largerEq', 'compare'
26554
/***/ function(module, exports, __webpack_require__) {
26557
'name': 'smallerEq',
26558
'category': 'Relational',
26564
'Check if value x is smaller or equal to value y. Returns true if x is smaller than y, and false if not.',
26573
'equal', 'unequal', 'larger', 'smaller', 'largerEq', 'compare'
26580
/***/ function(module, exports, __webpack_require__) {
26584
'category': 'Relational',
26590
'Check unequality of two values. Returns true if the values are unequal, and false if they are equal.',
26601
'equal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual'
26608
/***/ function(module, exports, __webpack_require__) {
26612
'category': 'Statistics',
26614
'max(a, b, c, ...)',
26618
'description': 'Compute the maximum value of a list of values.',
26621
'max([2, 3, 4, 1])',
26622
'max([2, 5; 4, 3])',
26623
'max([2, 5; 4, 3], 1)',
26624
'max([2, 5; 4, 3], 2)',
26625
'max(2.7, 7.1, -4.5, 2.0, 4.1)',
26626
'min(2.7, 7.1, -4.5, 2.0, 4.1)'
26642
/***/ function(module, exports, __webpack_require__) {
26646
'category': 'Statistics',
26648
'mean(a, b, c, ...)',
26652
'description': 'Compute the arithmetic mean of a list of values.',
26654
'mean(2, 3, 4, 1)',
26655
'mean([2, 3, 4, 1])',
26656
'mean([2, 5; 4, 3])',
26657
'mean([2, 5; 4, 3], 1)',
26658
'mean([2, 5; 4, 3], 2)',
26659
'mean([1.0, 2.7, 3.2, 4.0])'
26675
/***/ function(module, exports, __webpack_require__) {
26679
'category': 'Statistics',
26681
'median(a, b, c, ...)',
26684
'description': 'Compute the median of all values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned.',
26687
'median([3, -1, 5, 7])'
26703
/***/ function(module, exports, __webpack_require__) {
26707
'category': 'Statistics',
26709
'min(a, b, c, ...)',
26713
'description': 'Compute the minimum value of a list of values.',
26716
'min([2, 3, 4, 1])',
26717
'min([2, 5; 4, 3])',
26718
'min([2, 5; 4, 3], 1)',
26719
'min([2, 5; 4, 3], 2)',
26720
'min(2.7, 7.1, -4.5, 2.0, 4.1)',
26721
'max(2.7, 7.1, -4.5, 2.0, 4.1)'
26737
/***/ function(module, exports, __webpack_require__) {
26741
'category': 'Statistics',
26743
'prod(a, b, c, ...)',
26746
'description': 'Compute the product of all values.',
26750
'prod([2, 5; 4, 3])'
26767
/***/ function(module, exports, __webpack_require__) {
26771
'category': 'Statistics',
26773
'std(a, b, c, ...)',
26775
'std(A, normalization)'
26777
'description': 'Compute the standard deviation of all values, defined as std(A) = sqrt(var(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
26780
'std([2, 4, 6, 8])',
26781
'std([2, 4, 6, 8], "uncorrected")',
26782
'std([2, 4, 6, 8], "biased")',
26783
'std([1, 2, 3; 4, 5, 6])'
26800
/***/ function(module, exports, __webpack_require__) {
26804
'category': 'Statistics',
26806
'sum(a, b, c, ...)',
26809
'description': 'Compute the sum of all values.',
26812
'sum([2, 3, 4, 1])',
26813
'sum([2, 5; 4, 3])'
26830
/***/ function(module, exports, __webpack_require__) {
26834
'category': 'Statistics',
26836
'var(a, b, c, ...)',
26838
'var(A, normalization)'
26840
'description': 'Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
26843
'var([2, 4, 6, 8])',
26844
'var([2, 4, 6, 8], "uncorrected")',
26845
'var([2, 4, 6, 8], "biased")',
26846
'var([1, 2, 3; 4, 5, 6])'
26863
/***/ function(module, exports, __webpack_require__) {
26867
'category': 'Trigonometry',
26871
'description': 'Compute the inverse cosine of a value in radians.',
26886
/***/ function(module, exports, __webpack_require__) {
26890
'category': 'Trigonometry',
26894
'description': 'Calculate the hyperbolic arccos of a value, defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`.',
26907
/***/ function(module, exports, __webpack_require__) {
26911
'category': 'Trigonometry',
26915
'description': 'Calculate the inverse cotangent of a value.',
26930
/***/ function(module, exports, __webpack_require__) {
26934
'category': 'Trigonometry',
26938
'description': 'Calculate the hyperbolic arccotangent of a value, defined as `acoth(x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.',
26950
/***/ function(module, exports, __webpack_require__) {
26954
'category': 'Trigonometry',
26958
'description': 'Calculate the inverse cotangent of a value.',
26974
/***/ function(module, exports, __webpack_require__) {
26978
'category': 'Trigonometry',
26982
'description': 'Calculate the hyperbolic arccosecant of a value, defined as `acsch(x) = ln(1/x + sqrt(1/x^2 + 1))`.',
26995
/***/ function(module, exports, __webpack_require__) {
26999
'category': 'Trigonometry',
27003
'description': 'Calculate the inverse secant of a value.',
27019
/***/ function(module, exports, __webpack_require__) {
27023
'category': 'Trigonometry',
27027
'description': 'Calculate the inverse secant of a value.',
27040
/***/ function(module, exports, __webpack_require__) {
27044
'category': 'Trigonometry',
27048
'description': 'Compute the inverse sine of a value in radians.',
27063
/***/ function(module, exports, __webpack_require__) {
27067
'category': 'Trigonometry',
27071
'description': 'Calculate the hyperbolic arcsine of a value, defined as `asinh(x) = ln(x + sqrt(x^2 + 1))`.',
27084
/***/ function(module, exports, __webpack_require__) {
27088
'category': 'Trigonometry',
27092
'description': 'Compute the inverse tangent of a value in radians.',
27107
/***/ function(module, exports, __webpack_require__) {
27111
'category': 'Trigonometry',
27115
'description': 'Calculate the hyperbolic arctangent of a value, defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`.',
27128
/***/ function(module, exports, __webpack_require__) {
27132
'category': 'Trigonometry',
27137
'Computes the principal value of the arc tangent of y/x in radians.',
27139
'atan2(2, 2) / pi',
27140
'angle = 60 deg in rad',
27155
/***/ function(module, exports, __webpack_require__) {
27159
'category': 'Trigonometry',
27163
'description': 'Compute the cosine of x in radians.',
27169
'sin(0.2)^2 + cos(0.2)^2'
27181
/***/ function(module, exports, __webpack_require__) {
27185
'category': 'Trigonometry',
27189
'description': 'Compute the hyperbolic cosine of x in radians.',
27203
/***/ function(module, exports, __webpack_require__) {
27207
'category': 'Trigonometry',
27211
'description': 'Compute the cotangent of x in radians. Defined as 1/tan(x)',
27226
/***/ function(module, exports, __webpack_require__) {
27230
'category': 'Trigonometry',
27234
'description': 'Compute the hyperbolic cotangent of x in radians.',
27249
/***/ function(module, exports, __webpack_require__) {
27253
'category': 'Trigonometry',
27257
'description': 'Compute the cosecant of x in radians. Defined as 1/sin(x)',
27272
/***/ function(module, exports, __webpack_require__) {
27276
'category': 'Trigonometry',
27280
'description': 'Compute the hyperbolic cosecant of x in radians. Defined as 1/sinh(x)',
27295
/***/ function(module, exports, __webpack_require__) {
27299
'category': 'Trigonometry',
27303
'description': 'Compute the secant of x in radians. Defined as 1/cos(x)',
27318
/***/ function(module, exports, __webpack_require__) {
27322
'category': 'Trigonometry',
27326
'description': 'Compute the hyperbolic secant of x in radians. Defined as 1/cosh(x)',
27341
/***/ function(module, exports, __webpack_require__) {
27345
'category': 'Trigonometry',
27349
'description': 'Compute the sine of x in radians.',
27355
'sin(0.2)^2 + cos(0.2)^2'
27367
/***/ function(module, exports, __webpack_require__) {
27371
'category': 'Trigonometry',
27375
'description': 'Compute the hyperbolic sine of x in radians.',
27388
/***/ function(module, exports, __webpack_require__) {
27392
'category': 'Trigonometry',
27396
'description': 'Compute the tangent of x in radians.',
27399
'sin(0.5) / cos(0.5)',
27413
/***/ function(module, exports, __webpack_require__) {
27417
'category': 'Trigonometry',
27421
'description': 'Compute the hyperbolic tangent of x in radians.',
27424
'sinh(0.5) / cosh(0.5)'
27435
/***/ function(module, exports, __webpack_require__) {
27439
'category': 'Units',
27444
'description': 'Change the unit of a value.',
27456
/***/ function(module, exports, __webpack_require__) {
27460
'category': 'Utils',
27464
'description': 'Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices',
27469
'clone([1, 2; 3, 4])',
27470
'clone("hello world")'
27478
/***/ function(module, exports, __webpack_require__) {
27482
'category': 'Utils',
27486
'description': 'Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.',
27488
'map([1, 2, 3], function(val) { return value * value })'
27490
'seealso': ['filter', 'forEach']
27496
/***/ function(module, exports, __webpack_require__) {
27500
'category': 'Utils',
27504
'description': 'Filter items in a matrix.',
27506
'isPositive(x) = x > 0',
27507
'filter([6, -2, -1, 4, 3], isPositive)',
27508
'filter([6, -2, 0, 1, 0], x != 0)'
27510
'seealso': ['sort', 'map', 'forEach']
27516
/***/ function(module, exports, __webpack_require__) {
27520
'category': 'Utils',
27522
'forEach(x, callback)'
27524
'description': 'Iterates over all elements of a matrix/array, and executes the given callback function.',
27526
'forEach([1, 2, 3], function(val) { console.log(val) })'
27528
'seealso': ['map', 'sort', 'filter']
27534
/***/ function(module, exports, __webpack_require__) {
27538
'category': 'Utils',
27541
'format(value, precision)'
27543
'description': 'Format a value of any type as string.',
27550
'seealso': ['print']
27556
/***/ function(module, exports, __webpack_require__) {
27560
'category': 'Utils',
27564
'description': 'Import functions from a file.',
27566
'import("numbers")',
27567
'import("./mylib.js")'
27575
/***/ function(module, exports, __webpack_require__) {
27579
'category': 'Utils',
27584
'description': 'Sort the items in a matrix. Compare can be a string "asc" or "desc", or a custom sort function.',
27586
'sort([5, 10, 1])',
27587
'sort(["C", "B", "A", "D"])',
27588
'sortByLength(a, b) = size(a)[1] - size(b)[1]',
27589
'sort(["Langdon", "Tom", "Sara"], sortByLength)'
27591
'seealso': ['map', 'filter', 'forEach']
27597
/***/ function(module, exports, __webpack_require__) {
27601
'category': 'Utils',
27605
'description': 'Get the type of a variable.',
27610
'typeof("hello world")'
27618
/***/ function(module, exports, __webpack_require__) {
27622
// NOTE: distribution is NOT added to math.distribution but returned by the factory function
27623
// TODO: rethink math.distribution
27625
module.exports = function (math) {
27626
var Matrix = __webpack_require__(10);
27627
var array = __webpack_require__(165);
27628
var collection = __webpack_require__(14);
27629
var isCollection = collection.isCollection;
27632
* Create a distribution object with a set of random functions for given
27633
* random distribution.
27637
* math.distribution(name)
27641
* var normalDist = math.distribution('normal'); // create a normal distribution
27642
* normalDist.random(0, 10); // get a random value between 0 and 10
27646
* random, randomInt, pickRandom
27648
* @param {String} name Name of a distribution. Choose from 'uniform', 'normal'.
27649
* @return {Object} Returns a distribution object containing functions:
27650
* `random([size] [, min] [, max])`,
27651
* `randomInt([min] [, max])`,
27652
* `pickRandom(array)`
27654
function distribution(name) {
27655
if (!distributions.hasOwnProperty(name))
27656
throw new Error('Unknown distribution ' + name);
27658
var args = Array.prototype.slice.call(arguments, 1),
27659
distribution = distributions[name].apply(this, args);
27661
return (function(distribution) {
27663
// This is the public API for all distributions
27664
var randFunctions = {
27666
random: function(arg1, arg2, arg3) {
27667
var size, min, max;
27668
if (arguments.length > 3) {
27669
throw new math.error.ArgumentsError('random', arguments.length, 0, 3);
27671
// `random(max)` or `random(size)`
27672
} else if (arguments.length === 1) {
27673
if (isCollection(arg1)) {
27679
// `random(min, max)` or `random(size, max)`
27680
} else if (arguments.length === 2) {
27681
if (isCollection(arg1)) {
27689
// `random(size, min, max)`
27696
// TODO: validate type of min, max, and size
27698
if (max === undefined) max = 1;
27699
if (min === undefined) min = 0;
27700
if (size !== undefined) {
27701
var res = _randomDataForMatrix(size.valueOf(), min, max, _random);
27702
return (size instanceof Matrix) ? new Matrix(res) : res;
27704
else return _random(min, max);
27707
randomInt: function(arg1, arg2, arg3) {
27708
var size, min, max;
27709
if (arguments.length > 3 || arguments.length < 1)
27710
throw new math.error.ArgumentsError('randomInt', arguments.length, 1, 3);
27712
// `random(max)` or `random(size)`
27713
else if (arguments.length === 1)
27714
if (isCollection(arg1)) {
27720
// `randomInt(min, max)` or `randomInt(size, max)`
27721
else if (arguments.length === 2) {
27722
if (isCollection(arg1)) {
27730
// `randomInt(size, min, max)`
27737
// TODO: validate type of min, max, and size
27739
if (min === undefined) min = 0;
27740
if (size !== undefined) {
27741
var res = _randomDataForMatrix(size.valueOf(), min, max, _randomInt);
27742
return (size instanceof Matrix) ? new Matrix(res) : res;
27744
else return _randomInt(min, max);
27747
pickRandom: function(possibles) {
27748
if (arguments.length !== 1) {
27749
throw new math.error.ArgumentsError('pickRandom', arguments.length, 1);
27751
if (possibles instanceof Matrix) {
27752
possibles = possibles.valueOf(); // get Array
27754
else if (!Array.isArray(possibles)) {
27755
throw new math.error.UnsupportedTypeError('pickRandom', math['typeof'](possibles));
27758
if (array.size(possibles).length > 1) {
27759
throw new Error('Only one dimensional vectors supported');
27762
// TODO: add support for multi dimensional matrices
27763
return possibles[Math.floor(Math.random() * possibles.length)];
27768
var _random = function(min, max) {
27769
return min + distribution() * (max - min);
27772
var _randomInt = function(min, max) {
27773
return Math.floor(min + distribution() * (max - min));
27776
// This is a function for generating a random matrix recursively.
27777
var _randomDataForMatrix = function(size, min, max, randFunc) {
27778
var data = [], length, i;
27779
size = size.slice(0);
27781
if (size.length > 1) {
27782
for (i = 0, length = size.shift(); i < length; i++)
27783
data.push(_randomDataForMatrix(size, min, max, randFunc));
27785
for (i = 0, length = size.shift(); i < length; i++)
27786
data.push(randFunc(min, max));
27792
return randFunctions;
27797
// Each distribution is a function that takes no argument and when called returns
27798
// a number between 0 and 1.
27799
var distributions = {
27801
uniform: function() {
27802
return Math.random;
27805
// Implementation of normal distribution using Box-Muller transform
27806
// ref : http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
27807
// We take : mean = 0.5, standard deviation = 1/6
27808
// so that 99.7% values are in [0, 1].
27809
normal: function() {
27810
return function() {
27813
// We reject values outside of the interval [0, 1]
27814
// TODO: check if it is ok to do that?
27815
while (picked < 0 || picked > 1) {
27816
u1 = Math.random();
27817
u2 = Math.random();
27818
picked = 1/6 * Math.pow(-2 * Math.log(u1), 0.5) * Math.cos(2 * Math.PI * u2) + 0.5;
27825
return distribution;
27831
/***/ function(module, exports, __webpack_require__) {
27836
* Determine the type of a variable
27841
* @return {String} type Lower case type, for example 'number', 'string',
27844
exports.type = function(x) {
27845
var type = typeof x;
27847
if (type === 'object') {
27848
if (x === null) return 'null';
27849
if (x instanceof Boolean) return 'boolean';
27850
if (x instanceof Number) return 'number';
27851
if (x instanceof String) return 'string';
27852
if (Array.isArray(x)) return 'array';
27853
if (x instanceof Date) return 'date';
27854
if (x instanceof Function)return 'function';
27855
if (x instanceof RegExp) return 'regexp';
27864
/***/ function(module, exports, __webpack_require__) {
27869
* Memoize a given function by caching the computed result.
27870
* The cache of a memoized function can be cleared by deleting the `cache`
27871
* property of the function.
27873
* @param {function} fn The function to be memoized. Must be a pure function.
27874
* @return {function} Returns the memoized function
27876
exports.memoize = function(fn) {
27877
return function memoize() {
27878
if (typeof memoize.cache !== 'object') {
27879
memoize.cache = {};
27882
var hash = JSON.stringify(arguments);
27883
if (!(hash in memoize.cache)) {
27884
return memoize.cache[hash] = fn.apply(fn, arguments);
27886
return memoize.cache[hash];
27893
/***/ function(module, exports, __webpack_require__) {
27895
var __WEBPACK_AMD_DEFINE_RESULT__;/*! decimal.js v4.0.2 https://github.com/MikeMcl/decimal.js/LICENCE */
19937
27896
;(function (global) {
19938
27897
'use strict';
19942
* decimal.js v4.0.1
27901
* decimal.js v4.0.2
19943
27902
* An arbitrary-precision Decimal type for JavaScript.
19944
27903
* https://github.com/MikeMcl/decimal.js
19945
27904
* Copyright (c) 2014 Michael Mclaughlin <M8ch88l@gmail.com>
24003
/***/ function(module, exports, __webpack_require__) {
24007
exports.array = __webpack_require__(153);
24008
exports['boolean'] = __webpack_require__(175);
24009
exports.number = __webpack_require__(4);
24010
exports.bignumber = __webpack_require__(152);
24011
exports.object = __webpack_require__(3);
24012
exports.string = __webpack_require__(176);
24013
exports.types = __webpack_require__(196);
24018
/***/ function(module, exports, __webpack_require__) {
24022
var Node = __webpack_require__(173),
24023
object = __webpack_require__(3),
24024
string = __webpack_require__(176),
24025
collection = __webpack_require__(13),
24026
util = __webpack_require__(160),
24028
isArray = Array.isArray,
24029
isNode = Node.isNode;
24032
* @constructor ArrayNode
24034
* Holds an 1-dimensional array with nodes
24035
* @param {Node[]} [nodes] 1 dimensional array with nodes
24037
function ArrayNode(nodes) {
24038
if (!(this instanceof ArrayNode)) {
24039
throw new SyntaxError('Constructor must be called with the new operator');
24042
this.nodes = nodes || [];
24045
if (!isArray(this.nodes) || !this.nodes.every(isNode)) {
24046
throw new TypeError('Array containing Nodes expected')
24050
ArrayNode.prototype = new Node();
24052
ArrayNode.prototype.type = 'ArrayNode';
24055
* Compile the node to javascript code
24056
* @param {Object} defs Object which can be used to define functions
24057
* or constants globally available for the compiled
24061
ArrayNode.prototype._compile = function (defs) {
24062
var asMatrix = (defs.math.config().matrix !== 'array');
24064
var nodes = this.nodes.map(function (node) {
24065
return node._compile(defs);
24068
return (asMatrix ? 'math.matrix([' : '[') +
24070
(asMatrix ? '])' : ']');
24074
* Execute a callback for each of the child nodes of this node
24075
* @param {function(child: Node, path: string, parent: Node)} callback
24077
ArrayNode.prototype.forEach = function (callback) {
24078
for (var i = 0; i < this.nodes.length; i++) {
24079
var node = this.nodes[i];
24080
callback(node, 'nodes[' + i + ']', this);
24085
* Create a new ArrayNode having it's childs be the results of calling
24086
* the provided callback function for each of the childs of the original node.
24087
* @param {function(child: Node, path: string, parent: Node): Node} callback
24088
* @returns {ArrayNode} Returns a transformed copy of the node
24090
ArrayNode.prototype.map = function (callback) {
24092
for (var i = 0; i < this.nodes.length; i++) {
24093
nodes[i] = this._ifNode(callback(this.nodes[i], 'nodes[' + i + ']', this));
24095
return new ArrayNode(nodes);
24099
* Create a clone of this node, a shallow copy
24100
* @return {ArrayNode}
24102
ArrayNode.prototype.clone = function() {
24103
return new ArrayNode(this.nodes.slice(0))
24107
* Get string representation
24108
* @return {String} str
24111
ArrayNode.prototype.toString = function() {
24112
return string.format(this.nodes);
24116
* Get LaTeX representation
24117
* @return {String} str
24119
ArrayNode.prototype.toTex = function(type) {
24120
type = type || 'bmatrix';
24121
var s = '\\begin{' + type + '}';
24123
this.nodes.forEach(function(node) {
24125
s += node.nodes.map(function(childNode) {
24126
return childNode.toTex();
24136
s += '\\end{' + type + '}';
24140
module.exports = ArrayNode;
24145
/***/ function(module, exports, __webpack_require__) {
24149
var Node = __webpack_require__(173),
24150
ArrayNode = __webpack_require__(161),
24152
keywords = __webpack_require__(314),
24154
latex = __webpack_require__(315),
24155
isString = __webpack_require__(176).isString;
24158
* @constructor AssignmentNode
24160
* Define a symbol, like "a = 3.2"
24162
* @param {String} name Symbol name
24163
* @param {Node} expr The expression defining the symbol
24165
function AssignmentNode(name, expr) {
24166
if (!(this instanceof AssignmentNode)) {
24167
throw new SyntaxError('Constructor must be called with the new operator');
24171
if (!isString(name)) throw new TypeError('String expected for parameter "name"');
24172
if (!(expr instanceof Node)) throw new TypeError('Node expected for parameter "expr"');
24173
if (name in keywords) throw new Error('Illegal symbol name, "' + name + '" is a reserved keyword');
24179
AssignmentNode.prototype = new Node();
24181
AssignmentNode.prototype.type = 'AssignmentNode';
24184
* Compile the node to javascript code
24185
* @param {Object} defs Object which can be used to define functions
24186
* or constants globally available for the compiled
24190
AssignmentNode.prototype._compile = function (defs) {
24191
return 'scope["' + this.name + '"] = ' + this.expr._compile(defs) + '';
24196
* Execute a callback for each of the child nodes of this node
24197
* @param {function(child: Node, path: string, parent: Node)} callback
24199
AssignmentNode.prototype.forEach = function (callback) {
24200
callback(this.expr, 'expr', this);
24204
* Create a new AssignmentNode having it's childs be the results of calling
24205
* the provided callback function for each of the childs of the original node.
24206
* @param {function(child: Node, path: string, parent: Node): Node} callback
24207
* @returns {AssignmentNode} Returns a transformed copy of the node
24209
AssignmentNode.prototype.map = function (callback) {
24210
return new AssignmentNode(this.name, this._ifNode(callback(this.expr, 'expr', this)));
24214
* Create a clone of this node, a shallow copy
24215
* @return {AssignmentNode}
24217
AssignmentNode.prototype.clone = function() {
24218
return new AssignmentNode(this.name, this.expr);
24222
* Get string representation
24225
AssignmentNode.prototype.toString = function() {
24226
return this.name + ' = ' + this.expr.toString();
24230
* Get LaTeX representation
24233
AssignmentNode.prototype.toTex = function() {
24235
if (this.expr instanceof ArrayNode) {
24236
brace = ['\\mathbf{', '}'];
24238
return latex.addBraces(latex.toSymbol(this.name), brace) + '=' +
24239
latex.addBraces(this.expr.toTex());
24242
module.exports = AssignmentNode;
24246
/***/ function(module, exports, __webpack_require__) {
24250
var Node = __webpack_require__(173);
24251
var ResultSet = __webpack_require__(12);
24252
var isBoolean = __webpack_require__(175).isBoolean;
24255
* @constructor BlockNode
24257
* Holds a set with blocks
24258
* @param {Array.<{node: Node} | {node: Node, visible: boolean}>} blocks
24259
* An array with blocks, where a block is constructed as an Object
24260
* with properties block, which is a Node, and visible, which is
24261
* a boolean. The property visible is optional and is true by default
24263
function BlockNode(blocks) {
24264
if (!(this instanceof BlockNode)) {
24265
throw new SyntaxError('Constructor must be called with the new operator');
24268
// validate input, copy blocks
24269
if (!Array.isArray(blocks)) throw new Error('Array expected');
24270
this.blocks = blocks.map(function (block) {
24271
var node = block && block.node;
24272
var visible = block && block.visible !== undefined ? block.visible : true;
24274
if (!(node instanceof Node)) throw new TypeError('Property "node" must be a Node');
24275
if (!isBoolean(visible)) throw new TypeError('Property "visible" must be a boolean');
24284
BlockNode.prototype = new Node();
24286
BlockNode.prototype.type = 'BlockNode';
24289
* Compile the node to javascript code
24290
* @param {Object} defs Object which can be used to define functions
24291
* or constants globally available for the compiled
24293
* @return {String} js
24296
BlockNode.prototype._compile = function (defs) {
24297
defs.ResultSet = ResultSet;
24298
var blocks = this.blocks.map(function (param) {
24299
var js = param.node._compile(defs);
24300
if (param.visible) {
24301
return 'results.push(' + js + ');';
24308
return '(function () {' +
24309
'var results = [];' +
24311
'return new ResultSet(results);' +
24316
* Execute a callback for each of the child blocks of this node
24317
* @param {function(child: Node, path: string, parent: Node)} callback
24319
BlockNode.prototype.forEach = function (callback) {
24320
for (var i = 0; i < this.blocks.length; i++) {
24321
callback(this.blocks[i].node, 'blocks[' + i + '].node', this);
24326
* Create a new BlockNode having it's childs be the results of calling
24327
* the provided callback function for each of the childs of the original node.
24328
* @param {function(child: Node, path: string, parent: Node): Node} callback
24329
* @returns {BlockNode} Returns a transformed copy of the node
24331
BlockNode.prototype.map = function (callback) {
24333
for (var i = 0; i < this.blocks.length; i++) {
24334
var block = this.blocks[i];
24335
var node = this._ifNode(callback(block.node, 'blocks[' + i + '].node', this));
24338
visible: block.visible
24341
return new BlockNode(blocks);
24345
* Create a clone of this node, a shallow copy
24346
* @return {BlockNode}
24348
BlockNode.prototype.clone = function() {
24349
var blocks = this.blocks.map(function(block) {
24352
visible: block.visible
24356
return new BlockNode(blocks);
24360
* Get string representation
24361
* @return {String} str
24364
BlockNode.prototype.toString = function() {
24365
return this.blocks.map(function (param) {
24366
return param.node.toString() + (param.visible ? '' : ';');
24371
* Get LaTeX representation
24372
* @return {String} str
24374
BlockNode.prototype.toTex = function() {
24375
return this.blocks.map(function (param) {
24376
return param.node.toTex() + (param.visible ? '' : ';');
24380
module.exports = BlockNode;
24385
/***/ function(module, exports, __webpack_require__) {
24389
var Node = __webpack_require__(173);
24390
var latex = __webpack_require__(315);
24391
var BigNumber = __webpack_require__(159);
24392
var Complex = __webpack_require__(6);
24393
var Unit = __webpack_require__(10);
24394
var util = __webpack_require__(160);
24395
var isString = util.string.isString;
24396
var isNumber = util.number.isNumber;
24397
var isBoolean = util['boolean'].isBoolean;
24400
* A lazy evaluating conditional operator: 'condition ? trueExpr : falseExpr'
24402
* @param {Node} condition Condition, must result in a boolean
24403
* @param {Node} trueExpr Expression evaluated when condition is true
24404
* @param {Node} falseExpr Expression evaluated when condition is true
24406
* @constructor ConditionalNode
24409
function ConditionalNode (condition, trueExpr, falseExpr) {
24410
if (!(this instanceof ConditionalNode)) {
24411
throw new SyntaxError('Constructor must be called with the new operator');
24413
if (!(condition instanceof Node)) throw new TypeError('Parameter condition must be a Node');
24414
if (!(trueExpr instanceof Node)) throw new TypeError('Parameter trueExpr must be a Node');
24415
if (!(falseExpr instanceof Node)) throw new TypeError('Parameter falseExpr must be a Node');
24417
this.condition = condition;
24418
this.trueExpr = trueExpr;
24419
this.falseExpr = falseExpr;
24422
ConditionalNode.prototype = new Node();
24424
ConditionalNode.prototype.type = 'ConditionalNode';
24427
* Compile the node to javascript code
24428
* @param {Object} defs Object which can be used to define functions
24429
* or constants globally available for the compiled
24431
* @return {String} js
24434
ConditionalNode.prototype._compile = function(defs) {
24436
* Test whether a condition is met
24437
* @param {*} condition
24438
* @returns {boolean} true if condition is true or non-zero, else false
24440
defs.testCondition = function (condition) {
24441
if (isNumber(condition) || isBoolean(condition) || isString(condition)) {
24442
return condition ? true : false;
24445
if (condition instanceof BigNumber) {
24446
return condition.isZero() ? false : true;
24449
if (condition instanceof Complex) {
24450
return (condition.re || condition.im) ? true : false;
24453
if (condition instanceof Unit) {
24454
return condition.value ? true : false;
24457
if (condition === null || condition === undefined) {
24461
throw new TypeError('Unsupported type of condition "' + defs.math['typeof'](condition) + '"');
24465
'testCondition(' + this.condition._compile(defs) + ') ? ' +
24466
'( ' + this.trueExpr._compile(defs) + ') : ' +
24467
'( ' + this.falseExpr._compile(defs) + ')'
24472
* Execute a callback for each of the child nodes of this node
24473
* @param {function(child: Node, path: string, parent: Node)} callback
24475
ConditionalNode.prototype.forEach = function (callback) {
24476
callback(this.condition, 'condition', this);
24477
callback(this.trueExpr, 'trueExpr', this);
24478
callback(this.falseExpr, 'falseExpr', this);
24482
* Create a new ConditionalNode having it's childs be the results of calling
24483
* the provided callback function for each of the childs of the original node.
24484
* @param {function(child: Node, path: string, parent: Node): Node} callback
24485
* @returns {ConditionalNode} Returns a transformed copy of the node
24487
ConditionalNode.prototype.map = function (callback) {
24488
return new ConditionalNode(
24489
this._ifNode(callback(this.condition, 'condition', this)),
24490
this._ifNode(callback(this.trueExpr, 'trueExpr', this)),
24491
this._ifNode(callback(this.falseExpr, 'falseExpr', this))
24496
* Create a clone of this node, a shallow copy
24497
* @return {ConditionalNode}
24499
ConditionalNode.prototype.clone = function() {
24500
return new ConditionalNode(this.condition, this.trueExpr, this.falseExpr);
24504
* Get string representation
24505
* @return {String} str
24507
ConditionalNode.prototype.toString = function() {
24508
// TODO: not nice adding parenthesis al the time
24509
return '(' + this.condition.toString() + ') ? (' +
24510
this.trueExpr.toString() + ') : (' +
24511
this.falseExpr.toString() + ')';
24515
* Get LaTeX representation
24516
* @return {String} str
24518
ConditionalNode.prototype.toTex = function() {
24520
latex.addBraces(this.trueExpr.toTex()) +
24522
latex.addBraces('\\text{if}\\;' + this.condition.toTex())
24524
latex.addBraces(this.falseExpr.toTex()) +
24526
latex.addBraces('\\text{otherwise}')
24529
return latex.addBraces(s, [
24530
'\\left\\{\\begin{array}{l l}',
24531
'\\end{array}\\right.'
24535
module.exports = ConditionalNode;
24540
/***/ function(module, exports, __webpack_require__) {
24544
var Node = __webpack_require__(173),
24545
BigNumber = __webpack_require__(159),
24546
type = __webpack_require__(196).type,
24547
isString = __webpack_require__(176).isString;
24550
* A ConstantNode holds a constant value like a number or string. A ConstantNode
24551
* stores a stringified version of the value and uses this to compile to
24554
* In case of a stringified number as input, this may be compiled to a BigNumber
24555
* when the math instance is configured for BigNumbers.
24559
* // stringified values with type
24560
* new ConstantNode('2.3', 'number');
24561
* new ConstantNode('true', 'boolean');
24562
* new ConstantNode('hello', 'string');
24564
* // non-stringified values, type will be automatically detected
24565
* new ConstantNode(2.3);
24566
* new ConstantNode('hello');
24568
* @param {String | Number | Boolean | null | undefined} value
24569
* When valueType is provided, value must contain
24570
* an uninterpreted string representing the value.
24571
* When valueType is undefined, value can be a
24572
* number, string, boolean, null, or undefined, and
24573
* the type will be determined automatically.
24574
* @param {String} [valueType] The type of value. Choose from 'number', 'string',
24575
* 'boolean', 'undefined', 'null'
24576
* @constructor ConstantNode
24579
function ConstantNode(value, valueType) {
24580
if (!(this instanceof ConstantNode)) {
24581
throw new SyntaxError('Constructor must be called with the new operator');
24585
if (!isString(valueType)) {
24586
throw new TypeError('String expected for parameter "valueType"');
24588
if (!isString(value)){
24589
throw new TypeError('String expected for parameter "value"');
24592
this.value = value;
24593
this.valueType = valueType;
24596
// stringify the value and determine the type
24597
this.value = value + '';
24598
this.valueType = type(value);
24601
if (!SUPPORTED_TYPES[this.valueType]) {
24602
throw new TypeError('Unsupported type of value "' + this.valueType + '"');
24606
var SUPPORTED_TYPES = {
24614
ConstantNode.prototype = new Node();
24616
ConstantNode.prototype.type = 'ConstantNode';
24619
* Compile the node to javascript code
24620
* @param {Object} defs Object which can be used to define functions
24621
* or constants globally available for the compiled
24623
* @return {String} js
24626
ConstantNode.prototype._compile = function (defs) {
24627
switch (this.valueType) {
24629
if (defs.math.config().number === 'bignumber') {
24630
return 'math.bignumber("' + this.value + '")';
24633
// remove leading zeros like '003.2' which are not allowed by JavaScript
24634
return this.value.replace(/^(0*)[0-9]/, function (match, zeros) {
24635
return match.substring(zeros.length);
24640
return '"' + this.value + '"';
24652
// TODO: move this error to the constructor?
24653
throw new TypeError('Unsupported type of constant "' + this.valueType + '"');
24658
* Execute a callback for each of the child nodes of this node
24659
* @param {function(child: Node, path: string, parent: Node)} callback
24661
ConstantNode.prototype.forEach = function (callback) {
24662
// nothing to do, we don't have childs
24667
* Create a new ConstantNode having it's childs be the results of calling
24668
* the provided callback function for each of the childs of the original node.
24669
* @param {function(child: Node, path: string, parent: Node) : Node} callback
24670
* @returns {ConstantNode} Returns a clone of the node
24672
ConstantNode.prototype.map = function (callback) {
24673
return this.clone();
24677
* Create a clone of this node, a shallow copy
24678
* @return {ConstantNode}
24680
ConstantNode.prototype.clone = function() {
24681
return new ConstantNode(this.value, this.valueType);
24685
* Get string representation
24686
* @return {String} str
24688
ConstantNode.prototype.toString = function() {
24689
switch (this.valueType) {
24691
return '"' + this.value + '"';
24699
* Get LaTeX representation
24700
* @return {String} str
24702
ConstantNode.prototype.toTex = function() {
24703
var value = this.value,
24705
switch (this.valueType) {
24707
return '\\text{' + value + '}';
24710
index = value.toLowerCase().indexOf('e');
24711
if (index !== -1) {
24712
return value.substring(0, index) + ' \\cdot 10^{' +
24713
value.substring(index + 1) + '}';
24722
module.exports = ConstantNode;
24727
/***/ function(module, exports, __webpack_require__) {
24731
var Node = __webpack_require__(173);
24732
var keywords = __webpack_require__(314);
24733
var latex = __webpack_require__(315);
24734
var isString = __webpack_require__(176).isString;
24735
var isArray = Array.isArray;
24738
* @constructor FunctionAssignmentNode
24740
* Function assignment
24742
* @param {String} name Function name
24743
* @param {String[]} params Function parameter names
24744
* @param {Node} expr The function expression
24746
function FunctionAssignmentNode(name, params, expr) {
24747
if (!(this instanceof FunctionAssignmentNode)) {
24748
throw new SyntaxError('Constructor must be called with the new operator');
24752
if (!isString(name)) throw new TypeError('String expected for parameter "name"');
24753
if (!isArray(params) || !params.every(isString)) throw new TypeError('Array containing strings expected for parameter "params"');
24754
if (!(expr instanceof Node)) throw new TypeError('Node expected for parameter "expr"');
24755
if (name in keywords) throw new Error('Illegal function name, "' + name + '" is a reserved keyword');
24758
this.params = params;
24762
FunctionAssignmentNode.prototype = new Node();
24764
FunctionAssignmentNode.prototype.type = 'FunctionAssignmentNode';
24767
* Compile the node to javascript code
24768
* @param {Object} defs Object which can be used to define functions
24769
* or constants globally available for the compiled
24771
* @return {String} js
24774
FunctionAssignmentNode.prototype._compile = function (defs) {
24775
return 'scope["' + this.name + '"] = ' +
24776
' (function (scope) {' +
24777
' scope = Object.create(scope); ' +
24778
' var fn = function ' + this.name + '(' + this.params.join(',') + ') {' +
24779
' if (arguments.length != ' + this.params.length + ') {' +
24780
// TODO: use util.error.ArgumentsError here
24781
// TODO: test arguments error
24782
' throw new SyntaxError("Wrong number of arguments in function ' + this.name + ' (" + arguments.length + " provided, ' + this.params.length + ' expected)");' +
24784
this.params.map(function (variable, index) {
24785
return 'scope["' + variable + '"] = arguments[' + index + '];';
24787
' return ' + this.expr._compile(defs) + '' +
24789
' fn.syntax = "' + this.name + '(' + this.params.join(', ') + ')";' +
24795
* Execute a callback for each of the child nodes of this node
24796
* @param {function(child: Node, path: string, parent: Node)} callback
24798
FunctionAssignmentNode.prototype.forEach = function (callback) {
24799
callback(this.expr, 'expr', this);
24803
* Create a new FunctionAssignmentNode having it's childs be the results of calling
24804
* the provided callback function for each of the childs of the original node.
24805
* @param {function(child: Node, path: string, parent: Node): Node} callback
24806
* @returns {FunctionAssignmentNode} Returns a transformed copy of the node
24808
FunctionAssignmentNode.prototype.map = function (callback) {
24809
var expr = this._ifNode(callback(this.expr, 'expr', this));
24811
return new FunctionAssignmentNode(this.name, this.params.slice(0), expr);
24815
* Create a clone of this node, a shallow copy
24816
* @return {FunctionAssignmentNode}
24818
FunctionAssignmentNode.prototype.clone = function() {
24819
return new FunctionAssignmentNode(this.name, this.params.slice(0), this.expr);
24823
* get string representation
24824
* @return {String} str
24826
FunctionAssignmentNode.prototype.toString = function() {
24827
return 'function ' + this.name +
24828
'(' + this.params.join(', ') + ') = ' +
24829
this.expr.toString();
24833
* get LaTeX representation
24834
* @return {String} str
24836
FunctionAssignmentNode.prototype.toTex = function() {
24838
latex.addBraces(this.params.map(latex.toSymbol).join(', '), true) + '=' +
24839
latex.addBraces(this.expr.toTex());
24842
module.exports = FunctionAssignmentNode;
24847
/***/ function(module, exports, __webpack_require__) {
24851
var Node = __webpack_require__(173);
24852
var RangeNode = __webpack_require__(170);
24853
var SymbolNode = __webpack_require__(171);
24855
var BigNumber = __webpack_require__(159);
24856
var Range = __webpack_require__(7);
24858
var isNode = Node.isNode;
24859
var isArray = Array.isArray;
24862
* @constructor IndexNode
24865
* get a subset of a matrix
24867
* @param {Node} object
24868
* @param {Node[]} ranges
24870
function IndexNode (object, ranges) {
24871
if (!(this instanceof IndexNode)) {
24872
throw new SyntaxError('Constructor must be called with the new operator');
24876
if (!(object instanceof Node)) throw new TypeError('Node expected for parameter "object"');
24877
if (!isArray(ranges) || !ranges.every(isNode)) {
24878
throw new TypeError('Array containing Nodes expected for parameter "ranges"');
24881
this.object = object;
24882
this.ranges = ranges;
24885
IndexNode.prototype = new Node();
24887
IndexNode.prototype.type = 'IndexNode';
24890
* Compile the node to javascript code
24891
* @param {Object} defs Object which can be used to define functions
24892
* or constants globally available for the compiled
24894
* @return {String} js
24897
IndexNode.prototype._compile = function (defs) {
24898
return this.compileSubset(defs);
24902
* Compile the node to javascript code
24903
* @param {Object} defs Object which can be used to define functions
24904
* or constants globally available for the
24905
* compiled expression
24906
* @param {String} [replacement] If provided, the function returns
24907
* "math.subset(obj, math.index(...), replacement)"
24908
* Else, the function returns
24909
* "math.subset(obj, math.index(...))"
24910
* @return {String} js
24911
* @returns {string}
24913
IndexNode.prototype.compileSubset = function(defs, replacement) {
24914
// check whether any of the ranges expressions uses the context symbol 'end'
24915
function test(node) {
24916
return (node instanceof SymbolNode) && (node.name == 'end');
24919
var someUseEnd = false;
24920
var rangesUseEnd = this.ranges.map(function (range) {
24921
var useEnd = range.filter(test).length > 0;
24922
someUseEnd = useEnd ? useEnd : someUseEnd;
24926
// create a Range from start, step and end
24927
defs.range = function (start, end, step) {
24929
start instanceof BigNumber ? start.toNumber() : start,
24930
end instanceof BigNumber ? end.toNumber() : end,
24931
step instanceof BigNumber ? step.toNumber() : step
24935
// TODO: implement support for bignumber (currently bignumbers are silently
24936
// reduced to numbers when changing the value to zero-based)
24938
// TODO: Optimization: when the range values are ConstantNodes,
24939
// we can beforehand resolve the zero-based value
24941
var ranges = this.ranges.map(function(range, i) {
24942
var useEnd = rangesUseEnd[i];
24943
if (range instanceof RangeNode) {
24945
// resolve end and create range
24946
return '(function (scope) {' +
24947
' scope = Object.create(scope); ' +
24948
' scope["end"] = size[' + i + '];' +
24950
' ' + range.start._compile(defs) + ', ' +
24951
' ' + range.end._compile(defs) + ', ' +
24952
' ' + (range.step ? range.step._compile(defs) : '1') +
24959
range.start._compile(defs) + ', ' +
24960
range.end._compile(defs) + ', ' +
24961
(range.step ? range.step._compile(defs) : '1') +
24967
// resolve the parameter 'end'
24968
return '(function (scope) {' +
24969
' scope = Object.create(scope); ' +
24970
' scope["end"] = size[' + i + '];' +
24971
' return ' + range._compile(defs) + ';' +
24975
// just evaluate the expression
24976
return range._compile(defs);
24981
// if some parameters use the 'end' parameter, we need to calculate the size
24983
return '(function () {' +
24984
' var obj = ' + this.object._compile(defs) + ';' +
24985
' var size = math.size(obj).valueOf();' +
24986
' return math.subset(' +
24988
' math.index(' + ranges.join(', ') + ')' +
24989
' ' + (replacement ? (', ' + replacement) : '') +
24994
return 'math.subset(' +
24995
this.object._compile(defs) + ',' +
24996
'math.index(' + ranges.join(', ') + ')' +
24997
(replacement ? (', ' + replacement) : '') +
25003
* Execute a callback for each of the child nodes of this node
25004
* @param {function(child: Node, path: string, parent: Node)} callback
25006
IndexNode.prototype.forEach = function (callback) {
25008
callback(this.object, 'object', this);
25011
for (var i = 0; i < this.ranges.length; i++) {
25012
callback(this.ranges[i], 'ranges[' + i + ']', this);
25017
* Create a new IndexNode having it's childs be the results of calling
25018
* the provided callback function for each of the childs of the original node.
25019
* @param {function(child: Node, path: string, parent: Node): Node} callback
25020
* @returns {IndexNode} Returns a transformed copy of the node
25022
IndexNode.prototype.map = function (callback) {
25023
var object = this._ifNode(callback(this.object, 'object', this));
25026
for (var i = 0; i < this.ranges.length; i++) {
25027
ranges[i] = this._ifNode(callback(this.ranges[i], 'ranges[' + i + ']', this));
25030
return new IndexNode(object, ranges);
25034
* Get the name of the object linked to this IndexNode
25035
* @return {string} name
25037
IndexNode.prototype.objectName = function() {
25038
return this.object.name;
25042
* Create a clone of this node, a shallow copy
25043
* @return {IndexNode}
25045
IndexNode.prototype.clone = function() {
25046
return new IndexNode(this.object, this.ranges.slice(0));
25050
* Get string representation
25051
* @return {String} str
25053
IndexNode.prototype.toString = function() {
25054
// format the parameters like "[1, 0:5]"
25055
return this.object.toString() + '[' + this.ranges.join(', ') + ']';
25059
* Get LaTeX representation
25060
* @return {String} str
25062
IndexNode.prototype.toTex = function() {
25063
return this.object.toTex() + '[' + this.ranges.join(', ') + ']';
25066
module.exports = IndexNode;
25070
/***/ function(module, exports, __webpack_require__) {
25074
var Node = __webpack_require__(173),
25075
ConstantNode = __webpack_require__(165),
25076
SymbolNode = __webpack_require__(171),
25077
FunctionNode = __webpack_require__(169),
25078
latex = __webpack_require__(315);
25081
* @constructor OperatorNode
25083
* An operator with two arguments, like 2+3
25085
* @param {String} op Operator name, for example '+'
25086
* @param {String} fn Function name, for example 'add'
25087
* @param {Node[]} args Operator arguments
25089
function OperatorNode (op, fn, args) {
25090
if (!(this instanceof OperatorNode)) {
25091
throw new SyntaxError('Constructor must be called with the new operator');
25094
// TODO: validate input
25097
this.args = args || [];
25100
OperatorNode.prototype = new Node();
25102
OperatorNode.prototype.type = 'OperatorNode';
25105
* Compile the node to javascript code
25106
* @param {Object} defs Object which can be used to define functions
25107
* or constants globally available for the compiled
25109
* @return {String} js
25112
OperatorNode.prototype._compile = function (defs) {
25113
if (!(this.fn in defs.math)) {
25114
throw new Error('Function ' + this.fn + ' missing in provided namespace "math"');
25117
var args = this.args.map(function (arg) {
25118
return arg._compile(defs);
25120
return 'math.' + this.fn + '(' + args.join(', ') + ')';
25124
* Execute a callback for each of the child nodes of this node
25125
* @param {function(child: Node, path: string, parent: Node)} callback
25127
OperatorNode.prototype.forEach = function (callback) {
25128
for (var i = 0; i < this.args.length; i++) {
25129
callback(this.args[i], 'args[' + i + ']', this);
25134
* Create a new OperatorNode having it's childs be the results of calling
25135
* the provided callback function for each of the childs of the original node.
25136
* @param {function(child: Node, path: string, parent: Node): Node} callback
25137
* @returns {OperatorNode} Returns a transformed copy of the node
25139
OperatorNode.prototype.map = function (callback) {
25141
for (var i = 0; i < this.args.length; i++) {
25142
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
25144
return new OperatorNode(this.op, this.fn, args);
25148
* Create a clone of this node, a shallow copy
25149
* @return {OperatorNode}
25151
OperatorNode.prototype.clone = function() {
25152
return new OperatorNode(this.op, this.fn, this.args.slice(0));
25156
* Get string representation
25157
* @return {String} str
25159
OperatorNode.prototype.toString = function() {
25160
var args = this.args;
25162
switch (args.length) {
25164
if (this.op == '-') {
25165
// special case: unary minus
25166
return '-' + args[0].toString();
25169
// for example '5!'
25170
return args[0].toString() + this.op;
25173
case 2: // for example '2+3'
25174
var lhs = args[0].toString();
25175
if (args[0] instanceof OperatorNode) {
25176
lhs = '(' + lhs + ')';
25178
var rhs = args[1].toString();
25179
if (args[1] instanceof OperatorNode) {
25180
rhs = '(' + rhs + ')';
25182
return lhs + ' ' + this.op + ' ' + rhs;
25184
default: // this should not occur. format as a function call
25185
return this.op + '(' + this.args.join(', ') + ')';
25190
* Get LaTeX representation
25191
* @return {String} str
25193
OperatorNode.prototype.toTex = function() {
25194
var args = this.args,
25195
mop = latex.toOperator(this.op),
25199
switch (args.length) {
25201
if (this.op === '-' || this.op === '+') {
25202
// special case: unary minus
25203
return this.op + lp.toTex();
25205
// for example '5!'
25206
return lp.toTex() + this.op;
25208
case 2: // for example '2+3'
25209
var lhs = lp.toTex(),
25224
if (lp instanceof OperatorNode) {
25225
if (lp.op === '+' || lp.op === '-') {
25230
if (rp instanceof OperatorNode) {
25231
if (rp.op === '+' || rp.op === '-') {
25234
else if (rp.op === '*') {
25239
if ((lp instanceof ConstantNode || lp instanceof OperatorNode) &&
25240
(rp instanceof ConstantNode || rp instanceof OperatorNode)) {
25250
if (lp instanceof OperatorNode || lp instanceof FunctionNode) {
25253
else if (lp instanceof SymbolNode) {
25260
rhs = latex.toUnit(rhs, true);
25264
lhs = latex.addBraces(lhs, lhb);
25265
rhs = latex.addBraces(rhs, rhb);
25267
return lop + lhs + mop + rhs + rop;
25269
default: // this should not occur. format as a function call
25270
return mop + '(' + this.args.map(latex.toSymbol).join(', ') + ')';
25274
module.exports = OperatorNode;
25279
/***/ function(module, exports, __webpack_require__) {
25283
var Node = __webpack_require__(173);
25284
var SymbolNode = __webpack_require__(171);
25286
var latex = __webpack_require__(315);
25287
var isNode = Node.isNode;
25288
var isArray = Array.isArray;
25291
* @constructor FunctionNode
25293
* invoke a list with arguments on a node
25294
* @param {string} name
25295
* @param {Node[]} args
25297
function FunctionNode (name, args) {
25298
if (!(this instanceof FunctionNode)) {
25299
throw new SyntaxError('Constructor must be called with the new operator');
25303
if (typeof name !== 'string') throw new TypeError('string expected for parameter "name"');
25304
if (!isArray(args) || !args.every(isNode)) {
25305
throw new TypeError('Array containing Nodes expected for parameter "args"');
25309
this.args = args || [];
25312
FunctionNode.prototype = new Node();
25314
FunctionNode.prototype.type = 'FunctionNode';
25317
* Compile the node to javascript code
25318
* @param {Object} defs Object which can be used to define functions
25319
* or constants globally available for the compiled
25321
* @return {String} js
25324
FunctionNode.prototype._compile = function (defs) {
25325
var fn = defs.math[this.name];
25326
var isRaw = (typeof fn === 'function') && (fn.rawArgs == true);
25328
// compile the parameters
25329
var args = this.args.map(function (arg) {
25330
return arg._compile(defs);
25334
// pass unevaluated parameters (nodes) to the function
25337
paramsName = 'p' + Math.round(Math.random() * 10000);
25339
while (paramsName in defs);
25340
defs[paramsName] = this.args;
25342
return '("' + this.name + '" in scope ? ' +
25343
'scope["' + this.name + '"](' + args.join(', ') + ') : ' +
25344
'math["' + this.name + '"]' + '(' + paramsName + ', math, scope))';
25347
// "regular" evaluation
25348
var symbol = new SymbolNode(this.name);
25349
return symbol._compile(defs) + '(' + args.join(', ') + ')';
25354
* Execute a callback for each of the child nodes of this node
25355
* @param {function(child: Node, path: string, parent: Node)} callback
25357
FunctionNode.prototype.forEach = function (callback) {
25358
for (var i = 0; i < this.args.length; i++) {
25359
callback(this.args[i], 'args[' + i + ']', this);
25364
* Create a new FunctionNode having it's childs be the results of calling
25365
* the provided callback function for each of the childs of the original node.
25366
* @param {function(child: Node, path: string, parent: Node): Node} callback
25367
* @returns {FunctionNode} Returns a transformed copy of the node
25369
FunctionNode.prototype.map = function (callback) {
25371
for (var i = 0; i < this.args.length; i++) {
25372
args[i] = this._ifNode(callback(this.args[i], 'args[' + i + ']', this));
25374
return new FunctionNode(this.name, args);
25378
* Create a clone of this node, a shallow copy
25379
* @return {FunctionNode}
25381
FunctionNode.prototype.clone = function() {
25382
return new FunctionNode(this.name, this.args.slice(0));
25386
* Get string representation
25387
* @return {String} str
25389
FunctionNode.prototype.toString = function() {
25390
// format the parameters like "add(2, 4.2)"
25391
return this.name + '(' + this.args.join(', ') + ')';
25395
* Get LaTeX representation
25396
* @return {String} str
25398
FunctionNode.prototype.toTex = function() {
25399
return latex.toArgs(this);
25402
module.exports = FunctionNode;
25407
/***/ function(module, exports, __webpack_require__) {
25411
var Node = __webpack_require__(173);
25413
var isNode = Node.isNode;
25416
* @constructor RangeNode
25419
* @param {Node} start included lower-bound
25420
* @param {Node} end included lower-bound
25421
* @param {Node} [step] optional step
25423
function RangeNode (start, end, step) {
25424
if (!(this instanceof RangeNode)) {
25425
throw new SyntaxError('Constructor must be called with the new operator');
25429
if (!isNode(start)) throw new TypeError('Node expected');
25430
if (!isNode(end)) throw new TypeError('Node expected');
25431
if (step && !isNode(step)) throw new TypeError('Node expected');
25432
if (arguments.length > 3) throw new Error('Too many arguments');
25434
this.start = start; // included lower-bound
25435
this.end = end; // included upper-bound
25436
this.step = step || null; // optional step
25439
RangeNode.prototype = new Node();
25441
RangeNode.prototype.type = 'RangeNode';
25444
* Compile the node to javascript code
25445
* @param {Object} defs Object which can be used to define functions
25446
* or constants globally available for the compiled
25448
* @return {String} js
25451
RangeNode.prototype._compile = function (defs) {
25452
return 'math.range(' +
25453
this.start._compile(defs) + ', ' +
25454
this.end._compile(defs) +
25455
(this.step ? (', ' + this.step._compile(defs)) : '') +
25460
* Execute a callback for each of the child nodes of this node
25461
* @param {function(child: Node, path: string, parent: Node)} callback
25463
RangeNode.prototype.forEach = function (callback) {
25464
callback(this.start, 'start', this);
25465
callback(this.end, 'end', this);
25467
callback(this.step, 'step', this);
25472
* Create a new RangeNode having it's childs be the results of calling
25473
* the provided callback function for each of the childs of the original node.
25474
* @param {function(child: Node, path: string, parent: Node): Node} callback
25475
* @returns {RangeNode} Returns a transformed copy of the node
25477
RangeNode.prototype.map = function (callback) {
25478
return new RangeNode(
25479
this._ifNode(callback(this.start, 'start', this)),
25480
this._ifNode(callback(this.end, 'end', this)),
25481
this.step && this._ifNode(callback(this.step, 'step', this))
25486
* Create a clone of this node, a shallow copy
25487
* @return {RangeNode}
25489
RangeNode.prototype.clone = function() {
25490
return new RangeNode(this.start, this.end, this.step && this.step);
25494
* Get string representation
25495
* @return {String} str
25497
RangeNode.prototype.toString = function() {
25498
// format the range like "start:step:end"
25499
var str = this.start.toString();
25501
str += ':' + this.step.toString();
25503
str += ':' + this.end.toString();
25509
* Get LaTeX representation
25510
* @return {String} str
25512
RangeNode.prototype.toTex = function() {
25513
var str = this.start.toTex();
25515
str += ':' + this.step.toTex();
25517
str += ':' + this.end.toTex();
25522
module.exports = RangeNode;
25527
/***/ function(module, exports, __webpack_require__) {
25531
var Node = __webpack_require__(173),
25532
Unit = __webpack_require__(10),
25534
latex = __webpack_require__(315),
25535
isString = __webpack_require__(176).isString;
25538
* @constructor SymbolNode
25540
* A symbol node can hold and resolve a symbol
25541
* @param {String} name
25544
function SymbolNode(name) {
25545
if (!(this instanceof SymbolNode)) {
25546
throw new SyntaxError('Constructor must be called with the new operator');
25550
if (!isString(name)) throw new TypeError('String expected for parameter "name"');
25555
SymbolNode.prototype = new Node();
25557
SymbolNode.prototype.type = 'SymbolNode';
25560
* Compile the node to javascript code
25561
* @param {Object} defs Object which can be used to define functions
25562
* or constants globally available for the compiled
25564
* @return {String} js
25567
SymbolNode.prototype._compile = function (defs) {
25568
// add a function to the definitions
25569
defs['undef'] = undef;
25570
defs['Unit'] = Unit;
25572
if (this.name in defs.math) {
25573
return '("' + this.name + '" in scope ? scope["' + this.name + '"] : math["' + this.name + '"])';
25577
'"' + this.name + '" in scope ? scope["' + this.name + '"] : ' +
25578
(Unit.isValuelessUnit(this.name) ?
25579
'new Unit(null, "' + this.name + '")' :
25580
'undef("' + this.name + '")') +
25586
* Execute a callback for each of the child nodes of this node
25587
* @param {function(child: Node, path: string, parent: Node)} callback
25589
SymbolNode.prototype.forEach = function (callback) {
25590
// nothing to do, we don't have childs
25594
* Create a new SymbolNode having it's childs be the results of calling
25595
* the provided callback function for each of the childs of the original node.
25596
* @param {function(child: Node, path: string, parent: Node) : Node} callback
25597
* @returns {SymbolNode} Returns a clone of the node
25599
SymbolNode.prototype.map = function (callback) {
25600
return this.clone();
25604
* Throws an error 'Undefined symbol {name}'
25605
* @param {String} name
25607
function undef (name) {
25608
throw new Error('Undefined symbol ' + name);
25612
* Create a clone of this node, a shallow copy
25613
* @return {SymbolNode}
25615
SymbolNode.prototype.clone = function() {
25616
return new SymbolNode(this.name);
25620
* Get string representation
25621
* @return {String} str
25624
SymbolNode.prototype.toString = function() {
25629
* Get LaTeX representation
25630
* @return {String} str
25633
SymbolNode.prototype.toTex = function() {
25634
return latex.toSymbol(this.name);
25637
module.exports = SymbolNode;
25642
/***/ function(module, exports, __webpack_require__) {
25646
var Node = __webpack_require__(173),
25647
IndexNode = __webpack_require__(167);
25650
* @constructor UpdateNode
25652
* Update a matrix subset, like A[2,3] = 4.5
25654
* @param {IndexNode} index IndexNode containing symbol and ranges
25655
* @param {Node} expr The expression defining the symbol
25657
function UpdateNode(index, expr) {
25658
if (!(this instanceof UpdateNode)) {
25659
throw new SyntaxError('Constructor must be called with the new operator');
25662
if (!(index instanceof IndexNode)) {
25663
throw new TypeError('Expected IndexNode for parameter "index"');
25665
if (!(expr instanceof Node)) {
25666
throw new TypeError('Expected Node for parameter "expr"');
25669
this.index = index;
25673
UpdateNode.prototype = new Node();
25675
UpdateNode.prototype.type = 'UpdateNode';
25678
* Compile the node to javascript code
25679
* @param {Object} defs Object which can be used to define functions
25680
* or constants globally available for the compiled
25682
* @return {String} js
25685
UpdateNode.prototype._compile = function (defs) {
25686
return 'scope["' + this.index.objectName() + '\"] = ' +
25687
this.index.compileSubset(defs, this.expr._compile(defs));
25691
* Execute a callback for each of the child nodes of this node
25692
* @param {function(child: Node, path: string, parent: Node)} callback
25694
UpdateNode.prototype.forEach = function (callback) {
25695
callback(this.index, 'index', this);
25696
callback(this.expr, 'expr', this);
25700
* Create a new UpdateNode having it's childs be the results of calling
25701
* the provided callback function for each of the childs of the original node.
25702
* @param {function(child: Node, path: string, parent: Node): Node} callback
25703
* @returns {UpdateNode} Returns a transformed copy of the node
25705
UpdateNode.prototype.map = function (callback) {
25706
return new UpdateNode(
25707
this._ifNode(callback(this.index, 'index', this)),
25708
this._ifNode(callback(this.expr, 'expr', this))
25713
* Create a clone of this node, a shallow copy
25714
* @return {UpdateNode}
25716
UpdateNode.prototype.clone = function() {
25717
return new UpdateNode(this.index, this.expr);
25721
* Get string representation
25724
UpdateNode.prototype.toString = function() {
25725
return this.index.toString() + ' = ' + this.expr.toString();
25729
* Get LaTeX representation
25732
UpdateNode.prototype.toTex = function() {
25733
return this.index.toTex() + ' = ' + this.expr.toTex();
25736
module.exports = UpdateNode;
25741
/***/ function(module, exports, __webpack_require__) {
25745
var keywords = __webpack_require__(314);
25751
if (!(this instanceof Node)) {
25752
throw new SyntaxError('Constructor must be called with the new operator');
25757
* Evaluate the node
25758
* @return {*} result
25760
// TODO: cleanup deprecated code one day. Deprecated since version 0.19.0
25761
Node.prototype.eval = function () {
25762
throw new Error('Node.eval is deprecated. ' +
25763
'Use Node.compile(math).eval([scope]) instead.');
25766
Node.prototype.type = 'Node';
25769
* Compile the node to javascript code
25770
* @param {Object} math math.js instance
25771
* @return {{eval: function}} expr Returns an object with a function 'eval',
25772
* which can be invoked as expr.eval([scope]),
25773
* where scope is an optional object with
25776
Node.prototype.compile = function (math) {
25777
if (!(math instanceof Object)) {
25778
throw new TypeError('Object expected for parameter math');
25781
// definitions globally available inside the closure of the compiled expressions
25783
math: _transform(math),
25784
_validateScope: _validateScope
25787
var code = this._compile(defs);
25789
var defsCode = Object.keys(defs).map(function (name) {
25790
return ' var ' + name + ' = defs["' + name + '"];';
25794
defsCode.join(' ') +
25796
' "eval": function (scope) {' +
25797
' if (scope) _validateScope(scope);' +
25798
' scope = scope || {};' +
25799
' return ' + code + ';' +
25803
var factory = new Function ('defs', factoryCode);
25804
return factory(defs);
25808
* Compile the node to javascript code
25809
* @param {Object} defs Object which can be used to define functions
25810
* and constants globally available inside the closure
25811
* of the compiled expression
25812
* @return {String} js
25815
Node.prototype._compile = function (defs) {
25816
// must be implemented by each of the Node implementations
25817
throw new Error('Cannot compile a Node interface');
25821
* Execute a callback for each of the child nodes of this node
25822
* @param {function(child: Node, path: string, parent: Node)} callback
25824
Node.prototype.forEach = function (callback) {
25825
// must be implemented by each of the Node implementations
25826
throw new Error('Cannot run forEach on a Node interface');
25830
* Create a new Node having it's childs be the results of calling
25831
* the provided callback function for each of the childs of the original node.
25832
* @param {function(child: Node, path: string, parent: Node): Node} callback
25833
* @returns {OperatorNode} Returns a transformed copy of the node
25835
Node.prototype.map = function (callback) {
25836
// must be implemented by each of the Node implementations
25837
throw new Error('Cannot run map on a Node interface');
25841
* Validate whether an object is a Node, for use with map
25842
* @param {Node} node
25843
* @returns {Node} Returns the input if it's a node, else throws an Error
25846
Node.prototype._ifNode = function (node) {
25847
if (!(node instanceof Node)) {
25848
throw new TypeError('Callback function must return a Node');
25855
* Recursively traverse all nodes in a node tree. Executes given callback for
25856
* this node and each of its child nodes.
25857
* @param {function(node: Node, path: string, parent: Node)} callback
25858
* A callback called for every node in the node tree.
25860
Node.prototype.traverse = function (callback) {
25861
// execute callback for itself
25862
callback(this, null, null);
25864
// recursively traverse over all childs of a node
25865
function _traverse (node, callback) {
25866
node.forEach(function(child, path, parent) {
25867
callback(child, path, parent);
25868
_traverse(child, callback);
25871
_traverse(this, callback);
25875
* Recursively transform a node tree via a transform function.
25877
* For example, to replace all nodes of type SymbolNode having name 'x' with a
25878
* ConstantNode with value 2:
25880
* var res = Node.transform(function (node, path, parent) {
25881
* if (node instanceof SymbolNode) && (node.name == 'x')) {
25882
* return new ConstantNode(2);
25889
* @param {function(node: Node, path: string, parent: Node) : Node} callback
25890
* A mapping function accepting a node, and returning
25891
* a replacement for the node or the original node.
25892
* Signature: callback(node: Node, index: string, parent: Node) : Node
25893
* @return {Node} Returns the original node or its replacement
25895
Node.prototype.transform = function (callback) {
25897
var replacement = callback(this, null, null);
25898
if (replacement !== this) {
25899
return replacement;
25902
// traverse over all childs
25903
function _transform (node, callback) {
25904
return node.map(function(child, path, parent) {
25905
var replacement = callback(child, path, parent);
25906
return (replacement !== child) ? replacement : _transform(child, callback);
25909
return _transform(this, callback);
25913
* Find any node in the node tree matching given filter function. For example, to
25914
* find all nodes of type SymbolNode having name 'x':
25916
* var results = Node.filter(function (node) {
25917
* return (node instanceof SymbolNode) && (node.name == 'x');
25920
* @param {function(node: Node, path: string, parent: Node) : Node} callback
25921
* A test function returning true when a node matches, and false
25922
* otherwise. Function signature:
25923
* callback(node: Node, index: string, parent: Node) : boolean
25924
* @return {Node[]} nodes An array with nodes matching given filter criteria
25926
Node.prototype.filter = function (callback) {
25929
this.traverse(function (node, path, parent) {
25930
if (callback(node, path, parent)) {
25938
// TODO: deprecated since version 1.1.0, remove this some day
25939
Node.prototype.find = function () {
25940
throw new Error('Function Node.find is deprecated. Use Node.filter instead.');
25943
// TODO: deprecated since version 1.1.0, remove this some day
25944
Node.prototype.match = function () {
25945
throw new Error('Function Node.match is deprecated. See functions Node.filter, Node.transform, Node.traverse.');
25949
* Create a clone of this node, a shallow copy
25952
Node.prototype.clone = function() {
25953
// must be implemented by each of the Node implementations
25954
throw new Error('Cannot clone a Node interface');
25958
* Get string representation
25961
Node.prototype.toString = function() {
25966
* Get LaTeX representation
25969
Node.prototype.toTex = function() {
25974
* Test whether an object is a Node
25975
* @param {*} object
25976
* @returns {boolean} isNode
25978
Node.isNode = function(object) {
25979
return object instanceof Node;
25983
* Validate the symbol names of a scope.
25984
* Throws an error when the scope contains an illegal symbol.
25985
* @param {Object} scope
25987
function _validateScope (scope) {
25988
for (var symbol in scope) {
25989
if (scope.hasOwnProperty(symbol)) {
25990
if (symbol in keywords) {
25991
throw new Error('Scope contains an illegal symbol, "' + symbol + '" is a reserved keyword');
25998
* Replace all functions having a transform function attached at property transform
25999
* with their transform.
26000
* @param {Object} math
26001
* @return {Object} transformed
26004
function _transform(math) {
26005
var transformed = Object.create(math);
26007
for (var name in math) {
26008
if (math.hasOwnProperty(name)) {
26009
var fn = math[name];
26010
var transform = fn && fn.transform;
26012
transformed[name] = transform;
26017
return transformed;
26020
module.exports = Node;
26025
/***/ function(module, exports, __webpack_require__) {
26027
var DimensionError = __webpack_require__(156);
26028
var IndexError = __webpack_require__(157);
26031
* Transform zero-based indices to one-based indices in errors
26032
* @param {Error} err
26033
* @returns {Error} Returns the transformed error
26035
exports.transform = function (err) {
26036
if (err instanceof IndexError) {
26037
return new IndexError(err.index + 1, err.min + 1, err.max + 1);
26046
/***/ function(module, exports, __webpack_require__) {
26051
* Test whether value is a Boolean
26053
* @return {Boolean} isBoolean
26055
exports.isBoolean = function(value) {
26056
return (value instanceof Boolean) || (typeof value == 'boolean');
26062
/***/ function(module, exports, __webpack_require__) {
26066
var number = __webpack_require__(4),
26067
bignumber = __webpack_require__(152),
26068
BigNumber = __webpack_require__(159);
26071
* Test whether value is a String
26073
* @return {Boolean} isString
26075
exports.isString = function(value) {
26076
return (value instanceof String) || (typeof value == 'string');
26080
* Check if a text ends with a certain string.
26081
* @param {String} text
26082
* @param {String} search
26084
exports.endsWith = function(text, search) {
26085
var start = text.length - search.length;
26086
var end = text.length;
26087
return (text.substring(start, end) === search);
26091
* Format a value of any type into a string.
26094
* math.format(value)
26095
* math.format(value, precision)
26097
* If value is a function, the returned string is 'function' unless the function
26098
* has a property `description`, in that case this properties value is returned.
26101
* math.format(2/7); // '0.2857142857142857'
26102
* math.format(math.pi, 3); // '3.14'
26103
* math.format(new Complex(2, 3)); // '2 + 3i'
26104
* math.format('hello'); // '"hello"'
26106
* @param {*} value Value to be stringified
26107
* @param {Object | Number | Function} [options] Formatting options. See
26108
* lib/util/number:format for a
26109
* description of the available
26111
* @return {String} str
26113
exports.format = function(value, options) {
26114
if (number.isNumber(value)) {
26115
return number.format(value, options);
26118
if (value instanceof BigNumber) {
26119
return bignumber.format(value, options);
26122
if (Array.isArray(value)) {
26123
return formatArray(value, options);
26126
if (exports.isString(value)) {
26127
return '"' + value + '"';
26130
if (typeof value === 'function') {
26131
return value.syntax ? value.syntax + '' : 'function';
26134
if (value instanceof Object) {
26135
if (typeof value.format === 'function') {
26136
return value.format(options);
26139
return value.toString();
26143
return String(value);
26147
* Recursively format an n-dimensional matrix
26148
* Example output: "[[1, 2], [3, 4]]"
26149
* @param {Array} array
26150
* @param {Object | Number | Function} [options] Formatting options. See
26151
* lib/util/number:format for a
26152
* description of the available
26154
* @returns {String} str
26156
function formatArray (array, options) {
26157
if (Array.isArray(array)) {
26159
var len = array.length;
26160
for (var i = 0; i < len; i++) {
26164
str += formatArray(array[i], options);
26170
return exports.format(array, options);
26177
/***/ function(module, exports, __webpack_require__) {
26181
'category': 'Constants',
26185
'description': 'Euler\'s number, the base of the natural logarithm. Approximately equal to 2.71828',
26198
/***/ function(module, exports, __webpack_require__) {
26202
'category': 'Constants',
26206
'description': 'Boolean value false',
26210
'seealso': ['true']
26216
/***/ function(module, exports, __webpack_require__) {
26220
'category': 'Constants',
26224
'description': 'Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.',
26236
/***/ function(module, exports, __webpack_require__) {
26239
'name': 'Infinity',
26240
'category': 'Constants',
26244
'description': 'Infinity, a number which is larger than the maximum number that can be handled by a floating point number.',
26255
/***/ function(module, exports, __webpack_require__) {
26259
'category': 'Constants',
26263
'description': 'Returns the natural logarithm of 2, approximately equal to 0.693',
26274
/***/ function(module, exports, __webpack_require__) {
26278
'category': 'Constants',
26282
'description': 'Returns the natural logarithm of 10, approximately equal to 2.302',
26293
/***/ function(module, exports, __webpack_require__) {
26297
'category': 'Constants',
26301
'description': 'Returns the base-2 logarithm of E, approximately equal to 1.442',
26312
/***/ function(module, exports, __webpack_require__) {
26316
'category': 'Constants',
26320
'description': 'Returns the base-10 logarithm of E, approximately equal to 0.434',
26331
/***/ function(module, exports, __webpack_require__) {
26335
'category': 'Constants',
26339
'description': 'Not a number',
26350
/***/ function(module, exports, __webpack_require__) {
26354
'category': 'Constants',
26358
'description': 'Value null',
26362
'seealso': ['true', 'false']
26368
/***/ function(module, exports, __webpack_require__) {
26372
'category': 'Constants',
26376
'description': 'The number pi is a mathematical constant that is the ratio of a circle\'s circumference to its diameter, and is approximately equal to 3.14159',
26387
/***/ function(module, exports, __webpack_require__) {
26391
'category': 'Constants',
26395
'description': 'Phi is the golden ratio. Two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities. Phi is defined as `(1 + sqrt(5)) / 2` and is approximately 1.618034...',
26405
/***/ function(module, exports, __webpack_require__) {
26409
'category': 'Constants',
26413
'description': 'Returns the square root of 1/2, approximately equal to 0.707',
26424
/***/ function(module, exports, __webpack_require__) {
26428
'category': 'Constants',
26432
'description': 'Returns the square root of 2, approximately equal to 1.414',
26443
/***/ function(module, exports, __webpack_require__) {
26447
'category': 'Constants',
26451
'description': 'Tau is the ratio constant of a circle\'s circumference to radius, equal to 2 * pi, approximately 6.2832.',
26462
/***/ function(module, exports, __webpack_require__) {
26466
'category': 'Constants',
26470
'description': 'Boolean value true',
26474
'seealso': ['false']
26480
/***/ function(module, exports, __webpack_require__) {
26484
'category': 'Constants',
26488
'description': 'A string with the version number of math.js',
26498
/***/ function(module, exports, __webpack_require__) {
26502
// NOTE: distribution is NOT added to math.distribution but returned by the factory function
26503
// TODO: rethink math.distribution
26505
module.exports = function (math) {
26506
var Matrix = __webpack_require__(9);
26507
var array = __webpack_require__(153);
26508
var collection = __webpack_require__(13);
26509
var isCollection = collection.isCollection;
26512
* Create a distribution object with a set of random functions for given
26513
* random distribution.
26517
* math.distribution(name)
26521
* var normalDist = math.distribution('normal'); // create a normal distribution
26522
* normalDist.random(0, 10); // get a random value between 0 and 10
26526
* random, randomInt, pickRandom
26528
* @param {String} name Name of a distribution. Choose from 'uniform', 'normal'.
26529
* @return {Object} Returns a distribution object containing functions:
26530
* `random([size] [, min] [, max])`,
26531
* `randomInt([min] [, max])`,
26532
* `pickRandom(array)`
26534
function distribution(name) {
26535
if (!distributions.hasOwnProperty(name))
26536
throw new Error('Unknown distribution ' + name);
26538
var args = Array.prototype.slice.call(arguments, 1),
26539
distribution = distributions[name].apply(this, args);
26541
return (function(distribution) {
26543
// This is the public API for all distributions
26544
var randFunctions = {
26546
random: function(arg1, arg2, arg3) {
26547
var size, min, max;
26548
if (arguments.length > 3) {
26549
throw new math.error.ArgumentsError('random', arguments.length, 0, 3);
26551
// `random(max)` or `random(size)`
26552
} else if (arguments.length === 1) {
26553
if (isCollection(arg1)) {
26559
// `random(min, max)` or `random(size, max)`
26560
} else if (arguments.length === 2) {
26561
if (isCollection(arg1)) {
26569
// `random(size, min, max)`
26576
// TODO: validate type of min, max, and size
26578
if (max === undefined) max = 1;
26579
if (min === undefined) min = 0;
26580
if (size !== undefined) {
26581
var res = _randomDataForMatrix(size.valueOf(), min, max, _random);
26582
return (size instanceof Matrix) ? new Matrix(res) : res;
26584
else return _random(min, max);
26587
randomInt: function(arg1, arg2, arg3) {
26588
var size, min, max;
26589
if (arguments.length > 3 || arguments.length < 1)
26590
throw new math.error.ArgumentsError('randomInt', arguments.length, 1, 3);
26592
// `random(max)` or `random(size)`
26593
else if (arguments.length === 1)
26594
if (isCollection(arg1)) {
26600
// `randomInt(min, max)` or `randomInt(size, max)`
26601
else if (arguments.length === 2) {
26602
if (isCollection(arg1)) {
26610
// `randomInt(size, min, max)`
26617
// TODO: validate type of min, max, and size
26619
if (min === undefined) min = 0;
26620
if (size !== undefined) {
26621
var res = _randomDataForMatrix(size.valueOf(), min, max, _randomInt);
26622
return (size instanceof Matrix) ? new Matrix(res) : res;
26624
else return _randomInt(min, max);
26627
pickRandom: function(possibles) {
26628
if (arguments.length !== 1) {
26629
throw new math.error.ArgumentsError('pickRandom', arguments.length, 1);
26631
if (possibles instanceof Matrix) {
26632
possibles = possibles.valueOf(); // get Array
26634
else if (!Array.isArray(possibles)) {
26635
throw new math.error.UnsupportedTypeError('pickRandom', math['typeof'](possibles));
26638
if (array.size(possibles).length > 1) {
26639
throw new Error('Only one dimensional vectors supported');
26642
// TODO: add support for multi dimensional matrices
26643
return possibles[Math.floor(Math.random() * possibles.length)];
26648
var _random = function(min, max) {
26649
return min + distribution() * (max - min);
26652
var _randomInt = function(min, max) {
26653
return Math.floor(min + distribution() * (max - min));
26656
// This is a function for generating a random matrix recursively.
26657
var _randomDataForMatrix = function(size, min, max, randFunc) {
26658
var data = [], length, i;
26659
size = size.slice(0);
26661
if (size.length > 1) {
26662
for (i = 0, length = size.shift(); i < length; i++)
26663
data.push(_randomDataForMatrix(size, min, max, randFunc));
26665
for (i = 0, length = size.shift(); i < length; i++)
26666
data.push(randFunc(min, max));
26672
return randFunctions;
26677
// Each distribution is a function that takes no argument and when called returns
26678
// a number between 0 and 1.
26679
var distributions = {
26681
uniform: function() {
26682
return Math.random;
26685
// Implementation of normal distribution using Box-Muller transform
26686
// ref : http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
26687
// We take : mean = 0.5, standard deviation = 1/6
26688
// so that 99.7% values are in [0, 1].
26689
normal: function() {
26690
return function() {
26693
// We reject values outside of the interval [0, 1]
26694
// TODO: check if it is ok to do that?
26695
while (picked < 0 || picked > 1) {
26696
u1 = Math.random();
26697
u2 = Math.random();
26698
picked = 1/6 * Math.pow(-2 * Math.log(u1), 0.5) * Math.cos(2 * Math.PI * u2) + 0.5;
26705
return distribution;
26711
/***/ function(module, exports, __webpack_require__) {
26717
"./filter.js": 144,
26719
"./forEach.js": 151,
26721
"./format.js": 145,
26723
"./import.js": 146,
26733
function webpackContext(req) {
26734
return __webpack_require__(webpackContextResolve(req));
26736
function webpackContextResolve(req) {
26737
return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
26739
webpackContext.keys = function webpackContextKeys() {
26740
return Object.keys(map);
26742
webpackContext.resolve = webpackContextResolve;
26743
module.exports = webpackContext;
26744
webpackContext.id = 195;
26749
/***/ function(module, exports, __webpack_require__) {
26754
* Determine the type of a variable
26759
* @return {String} type Lower case type, for example 'number', 'string',
26762
exports.type = function(x) {
26763
var type = typeof x;
26765
if (type === 'object') {
26766
if (x === null) return 'null';
26767
if (x instanceof Boolean) return 'boolean';
26768
if (x instanceof Number) return 'number';
26769
if (x instanceof String) return 'string';
26770
if (Array.isArray(x)) return 'array';
26771
if (x instanceof Date) return 'date';
26772
if (x instanceof Function)return 'function';
26773
if (x instanceof RegExp) return 'regexp';
26782
/***/ function(module, exports, __webpack_require__) {
26786
'category': 'Arithmetic',
26790
'description': 'Compute the absolute value.',
26795
'seealso': ['sign']
26801
/***/ function(module, exports, __webpack_require__) {
26805
'category': 'Operators',
26810
'description': 'Add two values.',
26815
'"hello" + " world"',
26826
/***/ function(module, exports, __webpack_require__) {
26830
'category': 'Arithmetic',
26835
'Round a value towards plus infinity. If x is complex, both real and imaginary part are rounded towards plus infinity.',
26841
'seealso': ['floor', 'fix', 'round']
26847
/***/ function(module, exports, __webpack_require__) {
26851
'category': 'Arithmetic',
26855
'description': 'Compute the cube of a value. The cube of x is x * x * x.',
26871
/***/ function(module, exports, __webpack_require__) {
26875
'category': 'Operators',
26880
'description': 'Divide two values.',
26897
/***/ function(module, exports, __webpack_require__) {
26900
'name': 'dotDivide',
26901
'category': 'Operators',
26906
'description': 'Divide two values element wise.',
26908
'a = [1, 2, 3; 4, 5, 6]',
26909
'b = [2, 1, 1; 3, 2, 5]',
26922
/***/ function(module, exports, __webpack_require__) {
26925
'name': 'dotMultiply',
26926
'category': 'Operators',
26929
'dotMultiply(x, y)'
26931
'description': 'Multiply two values element wise.',
26933
'a = [1, 2, 3; 4, 5, 6]',
26934
'b = [2, 1, 1; 3, 2, 5]',
26947
/***/ function(module, exports, __webpack_require__) {
26951
'category': 'Operators',
26957
'Calculates the power of x to y element wise.',
26959
'a = [1, 2, 3; 4, 5, 6]',
26970
/***/ function(module, exports, __webpack_require__) {
26974
'category': 'Arithmetic',
26978
'description': 'Calculate the exponent of a value.',
26984
'(exp(i*x) == cos(x) + i*sin(x)) # Euler\'s formula'
26995
/***/ function(module, exports, __webpack_require__) {
26999
'category': 'Arithmetic',
27004
'Round a value towards zero. If x is complex, both real and imaginary part are rounded towards zero.',
27011
'seealso': ['ceil', 'floor', 'round']
27017
/***/ function(module, exports, __webpack_require__) {
27021
'category': 'Arithmetic',
27026
'Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.',
27032
'seealso': ['ceil', 'fix', 'round']
27038
/***/ function(module, exports, __webpack_require__) {
27042
'category': 'Arithmetic',
27045
'gcd(a, b, c, ...)'
27047
'description': 'Compute the greatest common divisor.',
27053
'seealso': [ 'lcm', 'xgcd' ]
27059
/***/ function(module, exports, __webpack_require__) {
27063
'category': 'Arithmetic',
27067
'description': 'Compute the least common multiple.',
27073
'seealso': [ 'gcd' ]
27079
/***/ function(module, exports, __webpack_require__) {
27083
'category': 'Arithmetic',
27088
'description': 'Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).',
27095
'log(10000) / log(10)',
27096
'b = log(1024, 2)',
27107
/***/ function(module, exports, __webpack_require__) {
27111
'category': 'Arithmetic',
27115
'description': 'Compute the 10-base logarithm of a value.',
27120
'log(10000) / log(10)',
27132
/***/ function(module, exports, __webpack_require__) {
27136
'category': 'Operators',
27143
'Calculates the modulus, the remainder of an integer division.',
27148
'function isOdd(x) = x % 2',
27152
'seealso': ['divide']
27158
/***/ function(module, exports, __webpack_require__) {
27161
'name': 'multiply',
27162
'category': 'Operators',
27167
'description': 'multiply two values.',
27183
/***/ function(module, exports, __webpack_require__) {
27187
'category': 'Arithmetic',
27192
'description': 'Calculate the norm of a number, vector or matrix.',
27197
'norm([1, 2, -3], Infinity)',
27198
'norm([1, 2, -3], -Infinity)',
27200
'norm([[1, 2], [3, 4]], 1)',
27201
'norm([[1, 2], [3, 4]], \'inf\')',
27202
'norm([[1, 2], [3, 4]], \'fro\')'
27209
/***/ function(module, exports, __webpack_require__) {
27213
'category': 'Arithmetic',
27218
'description': 'Calculate the nth root of a value. ' +
27219
'The principal nth root of a positive real number A, ' +
27220
'is the positive real solution of the equation "x^root = A".',
27235
/***/ function(module, exports, __webpack_require__) {
27239
'category': 'Operators',
27245
'Calculates the power of x to y, x^y.',
27251
'seealso': [ 'multiply' ]
27257
/***/ function(module, exports, __webpack_require__) {
27261
'category': 'Arithmetic',
27267
'round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.',
27274
'round(123.45678, 2)'
27276
'seealso': ['ceil', 'floor', 'fix']
27282
/***/ function(module, exports, __webpack_require__) {
27286
'category': 'Arithmetic',
27291
'Compute the sign of a value. The sign of a value x is 1 when x>1, -1 when x<0, and 0 when x=0.',
27305
/***/ function(module, exports, __webpack_require__) {
27309
'category': 'Arithmetic',
27314
'Compute the square root value. If x = y * y, then y is the square root of x.',
27329
/***/ function(module, exports, __webpack_require__) {
27333
'category': 'Arithmetic',
27338
'Compute the square of a value. The square of x is x * x.',
27356
/***/ function(module, exports, __webpack_require__) {
27359
'name': 'subtract',
27360
'category': 'Operators',
27365
'description': 'subtract two values.',
27381
/***/ function(module, exports, __webpack_require__) {
27384
'name': 'unaryMinus',
27385
'category': 'Operators',
27391
'Inverse the sign of a value. Converts booleans and strings to numbers.',
27398
'add', 'subtract', 'unaryPlus'
27405
/***/ function(module, exports, __webpack_require__) {
27408
'name': 'unaryPlus',
27409
'category': 'Operators',
27415
'Converts booleans and strings to numbers.',
27421
'add', 'subtract', 'unaryMinus'
27428
/***/ function(module, exports, __webpack_require__) {
27432
'category': 'Arithmetic',
27436
'description': 'Calculate the extended greatest common divisor for two values',
27440
'xgcd(36163, 21199)'
27442
'seealso': [ 'gcd', 'lcm' ]
27448
/***/ function(module, exports, __webpack_require__) {
27452
'category': 'Bitwise',
27457
'description': 'Bitwise AND operation. Performs the logical AND operation on each pair of the corresponding bits of the two given values by multiplying them. If both bits in the compared position are 1, the bit in the resulting binary representation is 1, otherwise, the result is 0',
27464
'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift'
27471
/***/ function(module, exports, __webpack_require__) {
27475
'category': 'Bitwise',
27480
'description': 'Bitwise NOT operation. Performs a logical negation on each bit of the given value. Bits that are 0 become 1, and those that are 1 become 0.',
27484
'bitNot([2, -3, 4])'
27487
'bitAnd', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift'
27494
/***/ function(module, exports, __webpack_require__) {
27498
'category': 'Bitwise',
27503
'description': 'Bitwise OR operation. Performs the logical inclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if the first bit is 1 or the second bit is 1 or both bits are 1, otherwise, the result is 0.',
27506
'bitOr([1, 2, 3], 4)'
27509
'bitAnd', 'bitNot', 'bitXor', 'leftShift', 'rightArithShift', 'rightLogShift'
27516
/***/ function(module, exports, __webpack_require__) {
27520
'category': 'Bitwise',
27524
'description': 'Bitwise XOR operation, exclusive OR. Performs the logical exclusive OR operation on each pair of corresponding bits of the two given values. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1.',
27527
'bitXor([2, 3, 4], 4)'
27530
'bitAnd', 'bitNot', 'bitOr', 'leftShift', 'rightArithShift', 'rightLogShift'
27537
/***/ function(module, exports, __webpack_require__) {
27540
'name': 'leftShift',
27541
'category': 'Bitwise',
27546
'description': 'Bitwise left logical shift of a value x by y number of bits.',
27552
'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'rightArithShift', 'rightLogShift'
27559
/***/ function(module, exports, __webpack_require__) {
27562
'name': 'rightArithShift',
27563
'category': 'Bitwise',
27568
'description': 'Bitwise right arithmetic shift of a value x by y number of bits.',
27575
'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightLogShift'
27582
/***/ function(module, exports, __webpack_require__) {
27585
'name': 'rightLogShift',
27586
'category': 'Bitwise',
27591
'description': 'Bitwise right logical shift of a value x by y number of bits.',
27598
'bitAnd', 'bitNot', 'bitOr', 'bitXor', 'leftShift', 'rightArithShift'
27605
/***/ function(module, exports, __webpack_require__) {
27609
'category': 'Complex',
27614
'Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).',
27631
/***/ function(module, exports, __webpack_require__) {
27635
'category': 'Complex',
27640
'Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.',
27657
/***/ function(module, exports, __webpack_require__) {
27661
'category': 'Complex',
27665
'description': 'Get the real part of a complex number.',
27683
/***/ function(module, exports, __webpack_require__) {
27687
'category': 'Complex',
27691
'description': 'Get the imaginary part of a complex number.',
27709
/***/ function(module, exports, __webpack_require__) {
27712
'name': 'bignumber',
27713
'category': 'Type',
27718
'Create a big number from a number or string.',
27721
'bignumber(0.1) + bignumber(0.2)',
27722
'bignumber("7.2")',
27723
'bignumber("7.2e500")',
27724
'bignumber([0.1, 0.2, 0.3])'
27727
'boolean', 'complex', 'index', 'matrix', 'string', 'unit'
27734
/***/ function(module, exports, __webpack_require__) {
27738
'category': 'Type',
27744
'Convert a string or number into a boolean.',
27750
'boolean("false")',
27751
'boolean([1, 0, 1, 1])'
27754
'bignumber', 'complex', 'index', 'matrix', 'number', 'string', 'unit'
27761
/***/ function(module, exports, __webpack_require__) {
27765
'category': 'Type',
27772
'Create a complex number.',
27776
'complex("7 - 2i")'
27779
'bignumber', 'boolean', 'index', 'matrix', 'number', 'string', 'unit'
27786
/***/ function(module, exports, __webpack_require__) {
27790
'category': 'Type',
27794
'[start:step:end]',
27795
'[start1, start 2, ...]',
27796
'[start1:end1, start2:end2, ...]',
27797
'[start1:step1:end1, start2:step2:end2, ...]'
27800
'Create an index to get or replace a subset of a matrix',
27804
'A = [1, 2, 3; 4, 5, 6]',
27807
'A[0:2, 0:2] = ones(2, 2)'
27810
'bignumber', 'boolean', 'complex', 'matrix,', 'number', 'range', 'string', 'unit'
27817
/***/ function(module, exports, __webpack_require__) {
27821
'category': 'Type',
27824
'[a1, b1, ...; a2, b2, ...]',
27829
'Create a matrix.',
27833
'[1, 2, 3; 4, 5, 6]',
27838
'bignumber', 'boolean', 'complex', 'index', 'number', 'string', 'unit'
27845
/***/ function(module, exports, __webpack_require__) {
27849
'category': 'Type',
27855
'Create a number or convert a string or boolean into a number.',
27863
'number([true, false, true, true])',
27864
'number("52cm", "m")'
27867
'bignumber', 'boolean', 'complex', 'index', 'matrix', 'string', 'unit'
27874
/***/ function(module, exports, __webpack_require__) {
27878
'category': 'Type',
27884
'Create a string or convert a value to a string',
27891
'bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'unit'
27898
/***/ function(module, exports, __webpack_require__) {
27902
'category': 'Type',
27905
'unit(value, unit)',
27913
'unit(7.1, "kilogram")',
27917
'bignumber', 'boolean', 'complex', 'index', 'matrix', 'number', 'string'
27924
/***/ function(module, exports, __webpack_require__) {
27928
'category': 'Expression',
27930
'eval(expression)',
27931
'eval([expr1, expr2, expr3, ...])'
27933
'description': 'Evaluate an expression or an array with expressions.',
27936
'eval("sqrt(" + 4 + ")")'
27944
/***/ function(module, exports, __webpack_require__) {
27948
'category': 'Expression',
27953
'description': 'Display documentation on a function or data type.',
27964
/***/ function(module, exports, __webpack_require__) {
27968
'category': 'Logical',
27973
'description': 'Logical and. Test whether two values are both defined with a nonzero/nonempty value.',
27987
/***/ function(module, exports, __webpack_require__) {
27991
'category': 'Logical',
27997
'description': 'Logical not. Flips the boolean value of given argument.',
28012
/***/ function(module, exports, __webpack_require__) {
28016
'category': 'Logical',
28021
'description': 'Logical or. Test if at least one value is defined with a nonzero/nonempty value.',
28028
'not', 'and', 'xor'
28035
/***/ function(module, exports, __webpack_require__) {
28039
'category': 'Logical',
28044
'description': 'Logical exclusive or, xor. Test whether one and only one value is defined with a nonzero/nonempty value.',
28059
/***/ function(module, exports, __webpack_require__) {
28063
'category': 'Matrix',
28065
'concat(A, B, C, ...)',
28066
'concat(A, B, C, ..., dim)'
28068
'description': 'Concatenate matrices. By default, the matrices are concatenated by the last dimension. The dimension on which to concatenate can be provided as last argument.',
28070
'A = [1, 2; 5, 6]',
28071
'B = [3, 4; 7, 8]',
28077
'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
28084
/***/ function(module, exports, __webpack_require__) {
28088
'category': 'Matrix',
28092
'description': 'Calculate the cross product for two vectors in three dimensional space.',
28094
'cross([1, 1, 0], [0, 1, 1])',
28095
'cross([3, -3, 1], [4, 9, 2])',
28096
'cross([2, 3, 4], [5, 6, 7])'
28107
/***/ function(module, exports, __webpack_require__) {
28111
'category': 'Matrix',
28115
'description': 'Calculate the determinant of a matrix',
28117
'det([1, 2; 3, 4])',
28118
'det([-2, 2, 3; -1, 1, 3; 2, 0, -1])'
28121
'concat', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
28128
/***/ function(module, exports, __webpack_require__) {
28132
'category': 'Matrix',
28137
'description': 'Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned. When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.',
28141
'a = [1, 2, 3; 4, 5, 6; 7, 8, 9]',
28145
'concat', 'det', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
28152
/***/ function(module, exports, __webpack_require__) {
28156
'category': 'Matrix',
28160
'description': 'Calculate the dot product of two vectors. ' +
28161
'The dot product of A = [a1, a2, a3, ..., an] and B = [b1, b2, b3, ..., bn] ' +
28162
'is defined as dot(A, B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn',
28164
'dot([2, 4, 1], [2, 2, 3])',
28165
'[2, 4, 1] * [2, 2, 3]'
28176
/***/ function(module, exports, __webpack_require__) {
28180
'category': 'Matrix',
28187
'description': 'Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.',
28191
'a = [1, 2, 3; 4, 5, 6]',
28195
'concat', 'det', 'diag', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
28202
/***/ function(module, exports, __webpack_require__) {
28206
'category': 'Matrix',
28210
'description': 'Flatten a multi dimensional matrix into a single dimensional matrix.',
28212
'a = [1, 2, 3; 4, 5, 6]',
28218
'concat', 'resize', 'size', 'squeeze'
28225
/***/ function(module, exports, __webpack_require__) {
28229
'category': 'Matrix',
28233
'description': 'Calculate the inverse of a matrix',
28235
'inv([1, 2; 3, 4])',
28240
'concat', 'det', 'diag', 'eye', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
28247
/***/ function(module, exports, __webpack_require__) {
28251
'category': 'Matrix',
28255
'ones(m, n, p, ...)',
28258
'ones([m, n, p, ...])',
28261
'description': 'Create a matrix containing ones.',
28265
'ones([2,3]) * 4.5',
28266
'a = [1, 2, 3; 4, 5, 6]',
28270
'concat', 'det', 'diag', 'eye', 'inv', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
28277
/***/ function(module, exports, __webpack_require__) {
28281
'category': 'Type',
28285
'range(start, end)',
28286
'range(start, end, step)',
28290
'Create a range. Lower bound of the range is included, upper bound is excluded.',
28297
'a = [1, 2, 3, 4; 5, 6, 7, 8]',
28301
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
28308
/***/ function(module, exports, __webpack_require__) {
28312
'category': 'Matrix',
28315
'resize(x, size, defaultValue)'
28317
'description': 'Resize a matrix.',
28319
'resize([1,2,3,4,5], [3])',
28320
'resize([1,2,3], [5])',
28321
'resize([1,2,3], [5], -1)',
28322
'resize(2, [2, 3])',
28323
'resize("hello", [8], "!")'
28326
'size', 'subset', 'squeeze'
28333
/***/ function(module, exports, __webpack_require__) {
28337
'category': 'Matrix',
28341
'description': 'Calculate the size of a matrix.',
28344
'size("hello world")',
28345
'a = [1, 2; 3, 4; 5, 6]',
28350
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'squeeze', 'subset', 'transpose', 'zeros'
28357
/***/ function(module, exports, __webpack_require__) {
28361
'category': 'Matrix',
28365
'description': 'Remove inner and outer singleton dimensions from a matrix.',
28367
'a = zeros(3,2,1)',
28368
'size(squeeze(a))',
28369
'b = zeros(1,1,3)',
28373
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'subset', 'transpose', 'zeros'
28380
/***/ function(module, exports, __webpack_require__) {
28384
'category': 'Matrix',
28387
'value(index) = replacement',
28388
'subset(value, [index])',
28389
'subset(value, [index], replacement)'
28391
'description': 'Get or set a subset of a matrix or string. ' +
28392
'Indexes are one-based. ' +
28393
'Both the ranges lower-bound and upper-bound are included.',
28395
'd = [1, 2; 3, 4]',
28397
'e[1, 1:2] = [5, 6]',
28398
'e[2, :] = [7, 8]',
28404
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'transpose', 'zeros'
28411
/***/ function(module, exports, __webpack_require__) {
28414
'name': 'transpose',
28415
'category': 'Matrix',
28420
'description': 'Transpose a matrix',
28422
'a = [1, 2, 3; 4, 5, 6]',
28427
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'zeros'
28434
/***/ function(module, exports, __webpack_require__) {
28438
'category': 'Matrix',
28442
'zeros(m, n, p, ...)',
28445
'zeros([m, n, p, ...])',
28448
'description': 'Create a matrix containing zeros.',
28452
'a = [1, 2, 3; 4, 5, 6]',
28456
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose'
28463
/***/ function(module, exports, __webpack_require__) {
28466
'name': 'combinations',
28467
'category': 'Probability',
28469
'combinations(n, k)'
28471
'description': 'Compute the number of combinations of n items taken k at a time',
28473
'combinations(7, 5)'
28475
'seealso': ['permutations', 'factorial']
28481
/***/ function(module, exports, __webpack_require__) {
28484
'name': 'factorial',
28485
'category': 'Probability',
28490
'description': 'Compute the factorial of a value',
28493
'5 * 4 * 3 * 2 * 1',
28496
'seealso': ['combinations', 'permutations', 'gamma']
28502
/***/ function(module, exports, __webpack_require__) {
28506
'category': 'Probability',
28510
'description': 'Compute the gamma function. For small values, the Lanczos approximation is used, and for large values the extended Stirling approximation.',
28517
'seealso': ['factorial']
28523
/***/ function(module, exports, __webpack_require__) {
28526
'name': 'permutations',
28527
'category': 'Probability',
28530
'permutations(n, k)'
28532
'description': 'Compute the number of permutations of n items taken k at a time',
28535
'permutations(5, 3)'
28537
'seealso': ['combinations', 'factorial']
28543
/***/ function(module, exports, __webpack_require__) {
28546
'name': 'pickRandom',
28547
'category': 'Probability',
28549
'pickRandom(array)'
28552
'Pick a random entry from a given array.',
28554
'pickRandom(0:10)',
28555
'pickRandom([1, 3, 1, 6])'
28557
'seealso': ['random', 'randomInt']
28563
/***/ function(module, exports, __webpack_require__) {
28567
'category': 'Probability',
28571
'random(min, max)',
28573
'random(size, max)',
28574
'random(size, min, max)'
28577
'Return a random number.',
28583
'seealso': ['pickRandom', 'randomInt']
28589
/***/ function(module, exports, __webpack_require__) {
28593
'category': 'Probability',
28597
'randInt(min, max)',
28599
'randInt(size, max)',
28600
'randInt(size, min, max)'
28603
'Return a random integer number',
28607
'randInt([2, 3], 10)'
28609
'seealso': ['pickRandom', 'random']
28614
/***/ function(module, exports, __webpack_require__) {
28618
'category': 'Relational',
28623
'Compare two values. Returns 1 if x is larger than y, -1 if x is smaller than y, and 0 if x and y are equal.',
28628
'compare(5cm, 40mm)',
28629
'compare(2, [1, 2, 3])'
28632
'equal', 'unequal', 'smaller', 'smallerEq', 'largerEq'
28639
/***/ function(module, exports, __webpack_require__) {
28642
'name': 'deepEqual',
28643
'category': 'Relational',
28648
'Check equality of two matrices element wise. Returns true if the size of both matrices is equal and when and each of the elements are equal.',
28650
'[1,3,4] == [1,3,4]',
28654
'equal', 'unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare'
28661
/***/ function(module, exports, __webpack_require__) {
28665
'category': 'Relational',
28671
'Check equality of two values. Returns true if the values are equal, and false if not.',
28681
'unequal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual'
28688
/***/ function(module, exports, __webpack_require__) {
28692
'category': 'Relational',
28698
'Check if value x is larger than y. Returns true if x is larger than y, and false if not.',
28709
'equal', 'unequal', 'smaller', 'smallerEq', 'largerEq', 'compare'
28716
/***/ function(module, exports, __webpack_require__) {
28719
'name': 'largerEq',
28720
'category': 'Relational',
28726
'Check if value x is larger or equal to y. Returns true if x is larger or equal to y, and false if not.',
28735
'equal', 'unequal', 'smallerEq', 'smaller', 'largerEq', 'compare'
28742
/***/ function(module, exports, __webpack_require__) {
28746
'category': 'Relational',
28752
'Check if value x is smaller than value y. Returns true if x is smaller than y, and false if not.',
28762
'equal', 'unequal', 'larger', 'smallerEq', 'largerEq', 'compare'
28769
/***/ function(module, exports, __webpack_require__) {
28772
'name': 'smallerEq',
28773
'category': 'Relational',
28779
'Check if value x is smaller or equal to value y. Returns true if x is smaller than y, and false if not.',
28788
'equal', 'unequal', 'larger', 'smaller', 'largerEq', 'compare'
28795
/***/ function(module, exports, __webpack_require__) {
28799
'category': 'Relational',
28805
'Check unequality of two values. Returns true if the values are unequal, and false if they are equal.',
28816
'equal', 'smaller', 'larger', 'smallerEq', 'largerEq', 'compare', 'deepEqual'
28823
/***/ function(module, exports, __webpack_require__) {
28827
'category': 'Statistics',
28829
'max(a, b, c, ...)',
28833
'description': 'Compute the maximum value of a list of values.',
28836
'max([2, 3, 4, 1])',
28837
'max([2, 5; 4, 3], 0)',
28838
'max([2, 5; 4, 3], 1)',
28839
'max(2.7, 7.1, -4.5, 2.0, 4.1)',
28840
'min(2.7, 7.1, -4.5, 2.0, 4.1)'
28856
/***/ function(module, exports, __webpack_require__) {
28860
'category': 'Statistics',
28862
'mean(a, b, c, ...)',
28866
'description': 'Compute the arithmetic mean of a list of values.',
28868
'mean(2, 3, 4, 1)',
28869
'mean([2, 3, 4, 1])',
28870
'mean([2, 5; 4, 3], 0)',
28871
'mean([2, 5; 4, 3], 1)',
28872
'mean([1.0, 2.7, 3.2, 4.0])'
28888
/***/ function(module, exports, __webpack_require__) {
28892
'category': 'Statistics',
28894
'median(a, b, c, ...)',
28897
'description': 'Compute the median of all values. The values are sorted and the middle value is returned. In case of an even number of values, the average of the two middle values is returned.',
28900
'median([3, -1, 5, 7])'
28916
/***/ function(module, exports, __webpack_require__) {
28920
'category': 'Statistics',
28922
'min(a, b, c, ...)',
28926
'description': 'Compute the minimum value of a list of values.',
28929
'min([2, 3, 4, 1])',
28930
'min([2, 5; 4, 3], 0)',
28931
'min([2, 5; 4, 3], 1)',
28932
'min(2.7, 7.1, -4.5, 2.0, 4.1)',
28933
'max(2.7, 7.1, -4.5, 2.0, 4.1)'
28949
/***/ function(module, exports, __webpack_require__) {
28953
'category': 'Statistics',
28955
'prod(a, b, c, ...)',
28958
'description': 'Compute the product of all values.',
28962
'prod([2, 5; 4, 3])'
28979
/***/ function(module, exports, __webpack_require__) {
28983
'category': 'Statistics',
28985
'std(a, b, c, ...)',
28987
'std(A, normalization)'
28989
'description': 'Compute the standard deviation of all values, defined as std(A) = sqrt(var(A)). Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
28992
'std([2, 4, 6, 8])',
28993
'std([2, 4, 6, 8], "uncorrected")',
28994
'std([2, 4, 6, 8], "biased")',
28995
'std([1, 2, 3; 4, 5, 6])'
29012
/***/ function(module, exports, __webpack_require__) {
29016
'category': 'Statistics',
29018
'sum(a, b, c, ...)',
29021
'description': 'Compute the sum of all values.',
29024
'sum([2, 3, 4, 1])',
29025
'sum([2, 5; 4, 3])'
29042
/***/ function(module, exports, __webpack_require__) {
29046
'category': 'Statistics',
29048
'var(a, b, c, ...)',
29050
'var(A, normalization)'
29052
'description': 'Compute the variance of all values. Optional parameter normalization can be "unbiased" (default), "uncorrected", or "biased".',
29055
'var([2, 4, 6, 8])',
29056
'var([2, 4, 6, 8], "uncorrected")',
29057
'var([2, 4, 6, 8], "biased")',
29058
'var([1, 2, 3; 4, 5, 6])'
29075
/***/ function(module, exports, __webpack_require__) {
29079
'category': 'Trigonometry',
29083
'description': 'Compute the inverse cosine of a value in radians.',
29098
/***/ function(module, exports, __webpack_require__) {
29102
'category': 'Trigonometry',
29106
'description': 'Compute the inverse sine of a value in radians.',
29121
/***/ function(module, exports, __webpack_require__) {
29125
'category': 'Trigonometry',
29129
'description': 'Compute the inverse tangent of a value in radians.',
29144
/***/ function(module, exports, __webpack_require__) {
29148
'category': 'Trigonometry',
29153
'Computes the principal value of the arc tangent of y/x in radians.',
29155
'atan2(2, 2) / pi',
29156
'angle = 60 deg in rad',
29171
/***/ function(module, exports, __webpack_require__) {
29175
'category': 'Trigonometry',
29179
'description': 'Compute the cosine of x in radians.',
29185
'sin(0.2)^2 + cos(0.2)^2'
29197
/***/ function(module, exports, __webpack_require__) {
29201
'category': 'Trigonometry',
29205
'description': 'Compute the hyperbolic cosine of x in radians.',
29219
/***/ function(module, exports, __webpack_require__) {
29223
'category': 'Trigonometry',
29227
'description': 'Compute the cotangent of x in radians. Defined as 1/tan(x)',
29242
/***/ function(module, exports, __webpack_require__) {
29246
'category': 'Trigonometry',
29250
'description': 'Compute the hyperbolic cotangent of x in radians.',
29265
/***/ function(module, exports, __webpack_require__) {
29269
'category': 'Trigonometry',
29273
'description': 'Compute the cosecant of x in radians. Defined as 1/sin(x)',
29288
/***/ function(module, exports, __webpack_require__) {
29292
'category': 'Trigonometry',
29296
'description': 'Compute the hyperbolic cosecant of x in radians. Defined as 1/sinh(x)',
29311
/***/ function(module, exports, __webpack_require__) {
29315
'category': 'Trigonometry',
29319
'description': 'Compute the secant of x in radians. Defined as 1/cos(x)',
29334
/***/ function(module, exports, __webpack_require__) {
29338
'category': 'Trigonometry',
29342
'description': 'Compute the hyperbolic secant of x in radians. Defined as 1/cosh(x)',
29357
/***/ function(module, exports, __webpack_require__) {
29361
'category': 'Trigonometry',
29365
'description': 'Compute the sine of x in radians.',
29371
'sin(0.2)^2 + cos(0.2)^2'
29383
/***/ function(module, exports, __webpack_require__) {
29387
'category': 'Trigonometry',
29391
'description': 'Compute the hyperbolic sine of x in radians.',
29404
/***/ function(module, exports, __webpack_require__) {
29408
'category': 'Trigonometry',
29412
'description': 'Compute the tangent of x in radians.',
29415
'sin(0.5) / cos(0.5)',
29429
/***/ function(module, exports, __webpack_require__) {
29433
'category': 'Trigonometry',
29437
'description': 'Compute the hyperbolic tangent of x in radians.',
29440
'sinh(0.5) / cosh(0.5)'
29451
/***/ function(module, exports, __webpack_require__) {
29455
'category': 'Units',
29460
'description': 'Change the unit of a value.',
29472
/***/ function(module, exports, __webpack_require__) {
29476
'category': 'Utils',
29480
'description': 'Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices',
29485
'clone([1, 2; 3, 4])',
29486
'clone("hello world")'
29494
/***/ function(module, exports, __webpack_require__) {
29498
'category': 'Utils',
29502
'description': 'Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.',
29504
'map([1, 2, 3], function(val) { return value * value })'
29506
'seealso': ['filter', 'forEach']
29512
/***/ function(module, exports, __webpack_require__) {
29516
'category': 'Utils',
29520
'description': 'Filter items in a matrix.',
29522
'isPositive(x) = x > 0',
29523
'filter([6, -2, -1, 4, 3], isPositive)',
29524
'filter([6, -2, 0, 1, 0], x != 0)'
29526
'seealso': ['sort', 'map', 'forEach']
29532
/***/ function(module, exports, __webpack_require__) {
29536
'category': 'Utils',
29538
'forEach(x, callback)'
29540
'description': 'Iterates over all elements of a matrix/array, and executes the given callback function.',
29542
'forEach([1, 2, 3], function(val) { console.log(val) })'
29544
'seealso': ['map', 'sort', 'filter']
29550
/***/ function(module, exports, __webpack_require__) {
29554
'category': 'Utils',
29557
'format(value, precision)'
29559
'description': 'Format a value of any type as string.',
29566
'seealso': ['print']
29572
/***/ function(module, exports, __webpack_require__) {
29576
'category': 'Utils',
29580
'description': 'Import functions from a file.',
29582
'import("numbers")',
29583
'import("./mylib.js")'
29591
/***/ function(module, exports, __webpack_require__) {
29595
'category': 'Utils',
29600
'description': 'Sort the items in a matrix. Compare can be a string "asc" or "desc", or a custom sort function.',
29602
'sort([5, 10, 1])',
29603
'sort(["C", "B", "A", "D"])',
29604
'sortByLength(a, b) = size(a)[1] - size(b)[1]',
29605
'sort(["Langdon", "Tom", "Sara"], sortByLength)'
29607
'seealso': ['map', 'filter', 'forEach']
29613
/***/ function(module, exports, __webpack_require__) {
29617
'category': 'Utils',
29621
'description': 'Get the type of a variable.',
29626
'typeof("hello world")'
29634
31959
/***/ function(module, exports, __webpack_require__) {
29636
31961
'use strict';