From fbdac7cfed27dcdf15723cccab215b3c78620b2b Mon Sep 17 00:00:00 2001 From: josdejong Date: Fri, 5 Apr 2013 21:18:42 +0200 Subject: [PATCH] Implemented matrix support for methods max and min --- math.js | 231 ++++++++++++++++++++++------ math.min.js | 6 +- src/function/arithmetic/divide.js | 8 +- src/function/arithmetic/larger.js | 2 +- src/function/arithmetic/multiply.js | 8 +- src/function/matrix/det.js | 13 +- src/function/matrix/inv.js | 24 +-- src/function/statistics/max.js | 85 ++++++++-- src/function/statistics/min.js | 91 +++++++++-- test/function/statistics.js | 55 ++++++- 10 files changed, 428 insertions(+), 95 deletions(-) diff --git a/math.js b/math.js index 1c7157b60..f144aaea2 100644 --- a/math.js +++ b/math.js @@ -3076,18 +3076,18 @@ function divide(x, y) { } else if (y instanceof Complex) { // number / complex - return divideComplex(new Complex(x, 0), y); + return _divideComplex(new Complex(x, 0), y); } } if (x instanceof Complex) { if (isNumber(y)) { // complex / number - return divideComplex(x, new Complex(y, 0)); + return _divideComplex(x, new Complex(y, 0)); } else if (y instanceof Complex) { // complex / complex - return divideComplex(x, y); + return _divideComplex(x, y); } } @@ -3133,7 +3133,7 @@ function divide(x, y) { * @return {Complex} res * @private */ -function divideComplex (x, y) { +function _divideComplex (x, y) { var den = y.re * y.re + y.im * y.im; return new Complex( (x.re * y.re + x.im * y.im) / den, @@ -3461,7 +3461,7 @@ function larger(x, y) { if (x instanceof Array || x instanceof Matrix || x instanceof Range || y instanceof Array || y instanceof Matrix || y instanceof Range) { - return util.map2(x, y, equal); + return util.map2(x, y, larger); } if (x.valueOf() !== x || y.valueOf() !== y) { @@ -3817,7 +3817,7 @@ function multiply(x, y) { } else if (y instanceof Complex) { // number * complex - return multiplyComplex(new Complex(x, 0), y); + return _multiplyComplex (new Complex(x, 0), y); } else if (y instanceof Unit) { res = y.clone(); @@ -3828,11 +3828,11 @@ function multiply(x, y) { else if (x instanceof Complex) { if (isNumber(y)) { // complex * number - return multiplyComplex(x, new Complex(y, 0)); + return _multiplyComplex (x, new Complex(y, 0)); } else if (y instanceof Complex) { // complex * complex - return multiplyComplex(x, y); + return _multiplyComplex (x, y); } } else if (x instanceof Unit) { @@ -3918,7 +3918,7 @@ function multiply(x, y) { * @return {Complex} res * @private */ -function multiplyComplex (x, y) { +function _multiplyComplex (x, y) { return new Complex( x.re * y.re - x.im * y.im, x.re * y.im + x.im * y.re @@ -5334,6 +5334,9 @@ math.det = det; * @private */ function _det (matrix, rows, cols) { + var multiply = math.multiply, + subtract = math.subtract; + // this is a square matrix if (rows == 1) { // this is a 1 x 1 matrix @@ -5342,9 +5345,9 @@ function _det (matrix, rows, cols) { else if (rows == 2) { // this is a 2 x 2 matrix // the determinant of [a11,a12;a21,a22] is det = a11*a22-a21*a12 - return math.subtract( - math.multiply(matrix[0][0], matrix[1][1]), - math.multiply(matrix[1][0], matrix[0][1]) + return subtract( + multiply(matrix[0][0], matrix[1][1]), + multiply(matrix[1][0], matrix[0][1]) ); } else { @@ -5353,8 +5356,8 @@ function _det (matrix, rows, cols) { for (var c = 0; c < cols; c++) { var minor = _minor(matrix, rows, cols, 0, c); //d += Math.pow(-1, 1 + c) * a(1, c) * _det(minor); - d += math.multiply( - math.multiply((c + 1) % 2 + (c + 1) % 2 - 1, matrix[0][c]), + d += multiply( + multiply((c + 1) % 2 + (c + 1) % 2 - 1, matrix[0][c]), _det(minor, rows - 1, cols - 1) ); // faster than with pow() } @@ -5656,7 +5659,11 @@ math.inv = inv; * @private */ function _inv (matrix, rows, cols){ - var r, s, f, value, temp; + var r, s, f, value, temp, + add = math.add, + unaryminus = math.unaryminus, + multiply = math.multiply, + divide = math.divide; if (rows == 1) { // this is a 1 x 1 matrix @@ -5676,12 +5683,12 @@ function _inv (matrix, rows, cols){ } return [ [ - math.divide(matrix[1][1], det), - math.divide(math.unaryminus(matrix[0][1]), det) + divide(matrix[1][1], det), + divide(unaryminus(matrix[0][1]), det) ], [ - math.divide(math.unaryminus(matrix[1][0]), det), - math.divide(matrix[0][0], det) + divide(unaryminus(matrix[1][0]), det), + divide(matrix[0][0], det) ] ]; } @@ -5727,15 +5734,15 @@ function _inv (matrix, rows, cols){ if(r != c) { // eliminate value at column c and row r if (Ar[c] != 0) { - f = math.divide(math.unaryminus(Ar[c]), Ac[c]); + f = divide(unaryminus(Ar[c]), Ac[c]); // add (f * row c) to row r to eliminate the value // at column c for (s = c; s < cols; s++) { - Ar[s] = math.add(Ar[s], math.multiply(f, Ac[s])); + Ar[s] = add(Ar[s], multiply(f, Ac[s])); } for (s = 0; s < cols; s++) { - Br[s] = math.add(Br[s], math.multiply(f, Bc[s])); + Br[s] = add(Br[s], multiply(f, Bc[s])); } } } @@ -5744,10 +5751,10 @@ function _inv (matrix, rows, cols){ // divide each value on row r with the value at Acc f = Ac[c]; for (s = c; s < cols; s++) { - Ar[s] = math.divide(Ar[s], f); + Ar[s] = divide(Ar[s], f); } for (s = 0; s < cols; s++) { - Br[s] = math.divide(Br[s], f); + Br[s] = divide(Br[s], f); } } } @@ -6180,27 +6187,94 @@ random.doc = { */ function max(args) { if (arguments.length == 0) { - throw new Error('Function sum requires one or more parameters (0 provided)'); + throw new Error('Function max requires one or more parameters (0 provided)'); } - if (arguments.length == 1 && (args.valueOf() instanceof Array)) { - return max.apply(this, args.valueOf()); + if (args instanceof Array || args instanceof Matrix || args instanceof Range) { + // max([a, b, c, d, ...]]) + if (arguments.length > 1) { + throw Error('Wrong number of parameters (1 matrix or multiple scalars expected)'); + } + + var size = math.size(args); + + if (size.length == 1) { + // vector + if (args.length == 0) { + throw new Error('Cannot calculate max of an empty vector'); + } + + return _max(args.valueOf()); + } + else if (size.length == 2) { + // 2 dimensional matrix + if (size[0] == 0 || size[1] == 0) { + throw new Error('Cannot calculate max of an empty matrix'); + } + if (args instanceof Array) { + return _max2(args, size[0], size[1]); + } + else if (args instanceof Matrix || args instanceof Range) { + return new Matrix(_max2(args.valueOf(), size[0], size[1])); + } + else { + throw newUnsupportedTypeError('max', args); + } + } + else { + // TODO: implement max for n-dimensional matrices + throw new RangeError('Cannot calculate max for multi dimensional matrix'); + } } + else { + // max(a, b, c, d, ...) + return _max(arguments); + } +} - // TODO: implement support for Matrix +math.max = max; - var res = arguments[0]; - for (var i = 1, iMax = arguments.length; i < iMax; i++) { - var value = arguments[i]; +/** + * Calculate the max of a one dimensional array + * @param {Array} array + * @return {Number} max + * @private + */ +function _max(array) { + var larger = math.larger; + var res = array[0]; + for (var i = 1, iMax = array.length; i < iMax; i++) { + var value = array[i]; if (larger(value, res)) { res = value; } } - return res; } -math.max = max; +/** + * Calculate the max of a two dimensional array + * @param {Array} array + * @param {Number} rows + * @param {Number} cols + * @return {Number[]} max + * @private + */ +function _max2(array, rows, cols) { + var larger = math.larger; + var res = []; + for (var c = 0; c < cols; c++) { + var max = array[0][c]; + for (var r = 1; r < rows; r++) { + var value = array[r][c]; + if (larger(value, max)) { + max = value; + } + } + res[c] = max; + } + return res; +} /** * Function documentation @@ -6235,27 +6309,94 @@ max.doc = { */ function min(args) { if (arguments.length == 0) { - throw new Error('Function sum requires one or more parameters (0 provided)'); + throw new Error('Function min requires one or more parameters (0 provided)'); } - if (arguments.length == 1 && (args.valueOf() instanceof Array)) { - return min.apply(this, args.valueOf()); + if (args instanceof Array || args instanceof Matrix || args instanceof Range) { + // min([a, b, c, d, ...]]) + if (arguments.length > 1) { + throw Error('Wrong number of parameters (1 matrix or multiple scalars expected)'); + } + + var size = math.size(args); + + if (size.length == 1) { + // vector + if (args.length == 0) { + throw new Error('Cannot calculate min of an empty vector'); + } + + return _min(args.valueOf()); + } + else if (size.length == 2) { + // 2 dimensional matrix + if (size[0] == 0 || size[1] == 0) { + throw new Error('Cannot calculate min of an empty matrix'); + } + if (args instanceof Array) { + return _min2(args, size[0], size[1]); + } + else if (args instanceof Matrix || args instanceof Range) { + return new Matrix(_min2(args.valueOf(), size[0], size[1])); + } + else { + throw newUnsupportedTypeError('min', args); + } + } + else { + // TODO: implement min for n-dimensional matrices + throw new RangeError('Cannot calculate min for multi dimensional matrix'); + } } + else { + // min(a, b, c, d, ...) + return _min(arguments); + } +} - // TODO: implement support for Matrix +math.min = min; - var res = arguments[0]; - for (var i = 1, iMax = arguments.length; i < iMax; i++) { - var value = arguments[i]; +/** + * Calculate the min of a one dimensional array + * @param {Array} array + * @return {Number} min + * @private + */ +function _min(array) { + var smaller = math.smaller; + var res = array[0]; + for (var i = 1, iMax = array.length; i < iMax; i++) { + var value = array[i]; if (smaller(value, res)) { res = value; } } - return res; } -math.min = min; +/** + * Calculate the min of a two dimensional array + * @param {Array} array + * @param {Number} rows + * @param {Number} cols + * @return {Number[]} min + * @private + */ +function _min2(array, rows, cols) { + var smaller = math.smaller; + var res = []; + for (var c = 0; c < cols; c++) { + var min = array[0][c]; + for (var r = 1; r < rows; r++) { + var value = array[r][c]; + if (smaller(value, min)) { + min = value; + } + } + res[c] = min; + } + return res; +} /** * Function documentation @@ -6268,9 +6409,9 @@ min.doc = { ], 'description': 'Compute the minimum value of a list of values.', 'examples': [ - 'max(2, 3, 4, 1)', - 'max(2.7, 7.1, -4.5, 2.0, 4.1)', - 'min(2.7, 7.1, -4.5, 2.0, 4.1)' + 'min(2, 3, 4, 1)', + 'min(2.7, 7.1, -4.5, 2.0, 4.1)', + 'max(2.7, 7.1, -4.5, 2.0, 4.1)' ], 'seealso': [ 'sum', diff --git a/math.min.js b/math.min.js index 362dbbd90..492e86b9c 100644 --- a/math.min.js +++ b/math.min.js @@ -24,6 +24,6 @@ * License for the specific language governing permissions and limitations under * the License. */ -(function(){function e(e){return e instanceof Boolean||"boolean"==typeof e}function t(e,n){if(this.constructor!=t)throw new SyntaxError("Complex constructor must be called with the new operator");if(null!=e&&!v(e)||null!=n&&!v(n))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=e||0,this.im=n||0}function n(e){if(this.constructor!=n)throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof n||e instanceof g)this._data=e.toArray();else if(e instanceof Array)this._data=e;else{if(null!=e)throw new TypeError("Unsupported type of data ("+Qt.typeof(e)+")");this._data=[]}this._size=Jt.size(this._data)}function r(e,t){if(!v(e)||!d(e))throw new TypeError("Index must be an integer (value: "+e+")");if(1>e)throw new RangeError("Index out of range ("+e+" < 1)");if(t&&e>t)throw new RangeError("Index out of range ("+e+" > "+t+")")}function a(e,t){return r(t,e.length),e[t-1]}function i(e,t){return t.forEach(function(t){e=a(e,t)}),It(e)}function o(e,t){var n=t[0];return n.map?n.map(function(t){return a(e,t)}):[a(e,n)]}function s(e,t){var n=t[0],r=t[1];if(n.map)return r.map?n.map(function(t){var n=a(e,t);return r.map(function(e){return a(n,e)})}):n.map(function(t){return[a(a(e,t),r)]});if(r.map){var i=a(e,n);return[r.map(function(e){return a(i,e)})]}return[[a(a(e,n),r)]]}function f(e,t,n){var r=n==t.length-1,i=t[n],o=function(i){var o=a(e,i);return r?o:f(o,t,n+1)};return i.map?i.map(o):[o(i)]}function u(e,t,n){if(r(t),n instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[t-1]=n}function c(e,t,n,a){var i=!1;n.length>t.length&&(i=!0);for(var o=0;n.length>o;o++){var s=n[o];r(s),(null==t[o]||s>t[o])&&(t[o]=s,i=!0)}i&&Jt.resize(e,t,0);var f=t.length;n.forEach(function(t,n){f-1>n?e=e[t-1]:e[t-1]=a})}function l(e,t,n,a){var i=n[0];r(i),i>t[0]&&Jt.resize(e,[i],0),e[i-1]=a}function h(e,t,n,a){var i=n[0],o=n[1];r(i),r(o);var s=!1;i>(t[0]||0)&&(t[0]=i,s=!0),o>(t[1]||0)&&(t[1]=o,s=!0),s&&Jt.resize(e,t,0),e[i-1][o-1]=a}function m(e,t,n,r,a){var i=r==n.length-1,o=n[r],s=function(o,s){if(i)u(e,o,a[s]),e.length>(t[r]||0)&&(t[r]=e.length);else{var f=e[o-1];f instanceof Array||(e[o-1]=f=[f],e.length>(t[r]||0)&&(t[r]=e.length)),m(f,t,n,r+1,a[s])}};if(o.map){var f=o.size&&o.size()||o.length;if(f!=a.length)throw new RangeError("Dimensions mismatch ("+f+" != "+a.length+")");o.map(s)}else s(o,0)}function p(e){for(var t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array?p(r):void 0==r&&(e[t]=0)}}function v(e){return e instanceof Number||"number"==typeof e}function d(e){return e==Math.round(e)}function g(e,t,n){if(this.constructor!=g)throw new SyntaxError("Range constructor must be called with the new operator");if(null!=e&&!v(e))throw new TypeError("Parameter start must be a number");if(null!=n&&!v(n))throw new TypeError("Parameter end must be a number");if(null!=t&&!v(t))throw new TypeError("Parameter step must be a number");this.start=null!=e?e:0,this.end=null!=n?n:0,this.step=null!=t?t:1}function y(e){return e instanceof String||"string"==typeof e}function x(e,t){if(this.constructor!=x)throw Error("Unit constructor must be called with the new operator");if(null!=e&&!v(e))throw Error("First parameter in Unit constructor must be a number");if(null!=t&&!y(t))throw Error("Second parameter in Unit constructor must be a string");if(this.value=1,this.unit=x.UNIT_NONE,this.prefix=x.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1,null!=t){for(var n=x.UNITS,r=!1,a=0,i=n.length;i>a;a++){var o=n[a];if(x.endsWith(t,o.name)){var s=t.length-o.name.length,f=t.substring(0,s),u=o.prefixes[f];if(void 0!==u){this.unit=o,this.prefix=u,this.hasUnit=!0,r=!0;break}}}if(!r)throw Error('String "'+t+'" is no unit')}null!=e?(this.value=this._normalize(e),this.hasValue=!0):this.value=this._normalize(1)}function w(e,t){var n=void 0;if(2==arguments.length){var r=jt(t);n="Function "+e+" does not support a parameter of type "+r}else if(arguments.length>2){for(var a=[],i=1;arguments.length>i;i++)a.push(jt(arguments[i]));n="Function "+e+" does not support a parameters of type "+a.join(", ")}else n="Unsupported parameter in function "+e;return new TypeError(n)}function E(e,t,n,r){var a="Wrong number of arguments in function "+e+" ("+t+" provided, "+n+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(a)}function N(e){if(1!=arguments.length)throw E("abs",arguments.length,1);if(v(e))return Math.abs(e);if(e instanceof t)return Math.sqrt(e.re*e.re+e.im*e.im);if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,N);if(e.valueOf()!==e)return N(e.valueOf());throw w("abs",e)}function b(e,r){if(2!=arguments.length)throw E("add",arguments.length,2);if(v(e)){if(v(r))return e+r;if(r instanceof t)return new t(e+r.re,r.im)}else if(e instanceof t){if(v(r))return new t(e.re+r,e.im);if(r instanceof t)return new t(e.re+r.re,e.im+r.im)}else if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Units do not match");if(!e.hasValue)throw Error("Unit on left hand side of operator + has no value");if(!r.hasValue)throw Error("Unit on right hand side of operator + has no value");var a=e.clone();return a.value+=r.value,a.fixPrefix=!1,a}if(y(e)||y(r))return e+r;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,b);if(e.valueOf()!==e)return b(e.valueOf(),r.valueOf());throw w("add",e,r)}function O(e){if(1!=arguments.length)throw E("ceil",arguments.length,1);if(v(e))return Math.ceil(e);if(e instanceof t)return new t(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,O);if(e.valueOf()!==e)return O(e.valueOf());throw w("ceil",e)}function M(e){if(1!=arguments.length)throw E("cube",arguments.length,1);if(v(e))return e*e*e;if(e instanceof t)return P(P(e,e),e);if(e instanceof Array||e instanceof n||e instanceof g)return P(P(e,e),e);if(e.valueOf()!==e)return M(e.valueOf());throw w("cube",e)}function A(e,r){if(2!=arguments.length)throw E("divide",arguments.length,2);if(v(e)){if(v(r))return e/r;if(r instanceof t)return S(new t(e,0),r)}if(e instanceof t){if(v(r))return S(e,new t(r,0));if(r instanceof t)return S(e,r)}if(e instanceof x&&v(r)){var a=e.clone();return a.value/=r,a}if(e instanceof Array||e instanceof n)return r instanceof Array||r instanceof n?Qt.multiply(e,Qt.inv(r)):Jt.map2(e,r,A);if(r instanceof Array||r instanceof n)return Qt.multiply(e,Qt.inv(r));if(e.valueOf()!==e||r.valueOf()!==r)return A(e.valueOf(),r.valueOf());throw w("divide",e,r)}function S(e,n){var r=n.re*n.re+n.im*n.im;return new t((e.re*n.re+e.im*n.im)/r,(e.im*n.re-e.re*n.im)/r)}function T(e,r){if(2!=arguments.length)throw E("equal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof t)return e==r.re&&0==r.im}if(e instanceof t){if(v(r))return e.re==r&&0==e.im;if(r instanceof t)return e.re==r.re&&e.im==r.im}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value==r.value}if(y(e)||y(r))return e==r;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,T);if(e.valueOf()!==e||r.valueOf()!==r)return T(e.valueOf(),r.valueOf());throw w("equal",e,r)}function z(e){if(1!=arguments.length)throw E("exp",arguments.length,1);if(v(e))return Math.exp(e);if(e instanceof t){var r=Math.exp(e.re);return new t(r*Math.cos(e.im),r*Math.sin(e.im))}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,z);if(e.valueOf()!==e)return z(e.valueOf());throw w("exp",e)}function q(e){if(1!=arguments.length)throw E("fix",arguments.length,1);if(v(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof t)return new t(e.re>0?Math.floor(e.re):Math.ceil(e.re),e.im>0?Math.floor(e.im):Math.ceil(e.im));if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,q);if(e.valueOf()!==e)return q(e.valueOf());throw w("fix",e)}function U(e){if(1!=arguments.length)throw E("floor",arguments.length,1);if(v(e))return Math.floor(e);if(e instanceof t)return new t(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,U);if(e.valueOf()!==e)return U(e.valueOf());throw w("floor",e)}function L(e,r){if(2!=arguments.length)throw E("larger",arguments.length,2);if(v(e)){if(v(r))return e>r;if(r instanceof t)return e>N(r)}if(e instanceof t){if(v(r))return N(e)>r;if(r instanceof t)return N(e)>N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value>r.value}if(y(e)||y(r))return e>r;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,T);if(e.valueOf()!==e||r.valueOf()!==r)return L(e.valueOf(),r.valueOf());throw w("larger",e,r)}function R(e,r){if(2!=arguments.length)throw E("largereq",arguments.length,2);if(v(e)){if(v(r))return e>=r;if(r instanceof t)return e>=N(r)}if(e instanceof t){if(v(r))return N(e)>=r;if(r instanceof t)return N(e)>=N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value>=r.value}if(y(e)||y(r))return e>=r;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,R);if(e.valueOf()!==e||r.valueOf()!==r)return R(e.valueOf(),r.valueOf());throw w("largereq",e,r)}function _(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("log",arguments.length,1,2);if(void 0!==r)return A(_(e),_(r));if(v(e))return e>=0?Math.log(e):_(new t(e,0));if(e instanceof t)return new t(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,_);if(e.valueOf()!==e||r.valueOf()!==r)return _(e.valueOf(),r.valueOf());throw w("log",e,r)}function I(e){if(1!=arguments.length)throw E("log10",arguments.length,1);if(v(e))return e>=0?Math.log(e)/Math.LN10:I(new t(e,0));if(e instanceof t)return new t(Math.log(Math.sqrt(e.re*e.re+e.im*e.im))/Math.LN10,Math.atan2(e.im,e.re)/Math.LN10);if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,I);if(e.valueOf()!==e)return I(e.valueOf());throw w("log10",e)}function C(e,r){if(2!=arguments.length)throw E("mod",arguments.length,2);if(v(e)){if(v(r))return e%r;if(r instanceof t&&0==r.im)return e%r.re}else if(e instanceof t&&0==e.im){if(v(r))return e.re%r;if(r instanceof t&&0==r.im)return e.re%r.re}if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,C);if(e.valueOf()!==e||r.valueOf()!==r)return C(e.valueOf(),r.valueOf());throw w("mod",e,r)}function P(e,r){if(2!=arguments.length)throw E("multiply",arguments.length,2);if(v(e)){if(v(r))return e*r;if(r instanceof t)return B(new t(e,0),r);if(r instanceof x)return o=r.clone(),o.value*=e,o}else if(e instanceof t){if(v(r))return B(e,new t(r,0));if(r instanceof t)return B(e,r)}else if(e instanceof x){if(v(r))return o=e.clone(),o.value*=r,o}else{if(e instanceof Array){if(r instanceof Array){var a=Jt.size(e),i=Jt.size(r);if(2!=a.length)throw Error("Can only multiply a 2 dimensional matrix (A has "+a.length+" dimensions)");if(2!=i.length)throw Error("Can only multiply a 2 dimensional matrix (B has "+i.length+" dimensions)");if(a[1]!=i[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+a[0]+"x"+a[1]+", B is "+i[0]+"x"+i[1]+", "+i[1]+" != "+i[0]+")");for(var o=[],s=a[0],f=i[1],u=a[1],c=0;s>c;c++){o[c]=[];for(var l=0;f>l;l++){for(var h=null,m=0;u>m;m++){var p=P(e[c][m],r[m][l]);h=null==h?p:b(h,p)}o[c][l]=h}}return o}return r instanceof n?new n(P(e.valueOf(),r.valueOf())):Jt.map2(e,r,P)}if(e instanceof n)return new n(P(e.valueOf(),r.valueOf()))}if(r instanceof Array)return Jt.map2(e,r,P);if(r instanceof n)return new n(P(e.valueOf(),r.valueOf()));if(e.valueOf()!==e||r.valueOf()!==r)return P(e.valueOf(),r.valueOf());throw w("multiply",e,r)}function B(e,n){return new t(e.re*n.re-e.im*n.im,e.re*n.im+e.im*n.re)}function k(e,r){if(2!=arguments.length)throw E("pow",arguments.length,2);if(v(e)){if(v(r))return d(r)||e>=0?Math.pow(e,r):G(new t(e,0),new t(r,0));if(r instanceof t)return G(new t(e,0),r)}else if(e instanceof t){if(v(r))return G(e,new t(r,0));if(r instanceof t)return G(e,r)}else{if(e instanceof Array){if(!v(r)||!d(r)||0>r)throw new TypeError("For A^b, b must be a positive integer (value is "+r+")");var a=Jt.size(e);if(2!=a.length)throw Error("For A^b, A must be 2 dimensional (A has "+a.length+" dimensions)");if(a[0]!=a[1])throw Error("For A^b, A must be square (size is "+a[0]+"x"+a[1]+")");if(0==r)return identity(a[0]);for(var i=e,o=1;r>o;o++)i=P(e,i);return i}if(e instanceof n)return new n(k(e.valueOf(),r))}if(e.valueOf()!==e||r.valueOf()!==r)return k(e.valueOf(),r.valueOf());throw w("pow",e,r)}function G(e,t){var n=_(e),r=P(n,t);return z(r)}function j(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("round",arguments.length,1,2);if(void 0==r){if(v(e))return Math.round(e);if(e instanceof t)return new t(Math.round(e.re),Math.round(e.im));if((e instanceof Array||e instanceof n||e instanceof g)&&Jt.map(e,j),e.valueOf()!==e)return j(e.valueOf());throw w("round",e)}if(!v(r))throw new TypeError("Number of digits in function round must be an integer");if(r!==Math.round(r))throw new TypeError("Number of digits in function round must be integer");if(0>r||r>9)throw Error("Number of digits in function round must be in te range of 0-9");if(v(e))return V(e,r);if(e instanceof t)return new t(V(e.re,r),V(e.im,r));if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,j);if(e.valueOf()!==e||r.valueOf()!==r)return L(e.valueOf(),r.valueOf());throw w("round",e,r)}function V(e,t){var n=Math.pow(10,void 0!=t?t:Qt.options.precision);return Math.round(e*n)/n}function D(e){if(1!=arguments.length)throw E("sign",arguments.length,1);if(v(e)){var r;return r=e>0?1:0>e?-1:0}if(e instanceof t){var a=Math.sqrt(e.re*e.re+e.im*e.im);return new t(e.re/a,e.im/a)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,r);if(e.valueOf()!==e)return r(e.valueOf());throw w("sign",e)}function F(e,r){if(2!=arguments.length)throw E("smaller",arguments.length,2);if(v(e)){if(v(r))return r>e;if(r instanceof t)return N(r)>e}if(e instanceof t){if(v(r))return r>N(e);if(r instanceof t)return N(e)e;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,F);if(e.valueOf()!==e||r.valueOf()!==r)return F(e.valueOf(),r.valueOf());throw w("smaller",e,r)}function H(e,r){if(2!=arguments.length)throw E("smallereq",arguments.length,2);if(v(e)){if(v(r))return r>=e;if(r instanceof t)return N(r)>=e}if(e instanceof t){if(v(r))return r>=N(e);if(r instanceof t)return N(e)<=N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value<=r.value}if(y(e)||y(r))return r>=e;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,H);if(e.valueOf()!==e||r.valueOf()!==r)return H(e.valueOf(),r.valueOf());throw w("smallereq",e,r)}function Y(e){if(1!=arguments.length)throw E("sqrt",arguments.length,1);if(v(e))return e>=0?Math.sqrt(e):Y(new t(e,0));if(e instanceof t){var r=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new t(.5*Math.sqrt(2*(r+e.re)),.5*Math.sqrt(2*(r-e.re))):new t(.5*Math.sqrt(2*(r+e.re)),-.5*Math.sqrt(2*(r-e.re)))}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Y);if(e.valueOf()!==e)return Y(e.valueOf());throw w("sqrt",e)}function W(e){if(1!=arguments.length)throw E("square",arguments.length,1);if(v(e))return e*e;if(e instanceof t)return P(e,e);if(e instanceof Array||e instanceof n||e instanceof g)return P(e,e);if(e.valueOf()!==e)return W(e.valueOf());throw w("square",e)}function X(e,r){if(2!=arguments.length)throw E("subtract",arguments.length,2);if(v(e)){if(v(r))return e-r;if(r instanceof t)return new t(e-r.re,r.im)}else if(e instanceof t){if(v(r))return new t(e.re-r,e.im);if(r instanceof t)return new t(e.re-r.re,e.im-r.im)}else if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Units do not match");if(!e.hasValue)throw Error("Unit on left hand side of operator - has no value");if(!r.hasValue)throw Error("Unit on right hand side of operator - has no value");var a=e.clone();return a.value-=r.value,a.fixPrefix=!1,a}if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,X);if(e.valueOf()!==e||r.valueOf()!==r)return X(e.valueOf(),r.valueOf());throw w("subtract",e,r)}function Z(e){if(1!=arguments.length)throw E("unaryminus",arguments.length,1);if(v(e))return-e;if(e instanceof t)return new t(-e.re,-e.im);if(e instanceof x){var r=e.clone();return r.value=-e.value,r}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Z);if(e.valueOf()!==e)return Z(e.valueOf());throw w("unaryminus",e)}function K(e,r){if(2!=arguments.length)throw E("unequal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof t)return e==r.re&&0==r.im}if(e instanceof t){if(v(r))return e.re==r&&0==e.im;if(r instanceof t)return e.re==r.re&&e.im==r.im}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value==r.value}if(y(e)||y(r))return e==r;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,K);if(e.valueOf()!==e||r.valueOf()!==r)return K(e.valueOf(),r.valueOf());throw w("unequal",e,r)}function Q(e){if(1!=arguments.length)throw E("arg",arguments.length,1);if(v(e))return Math.atan2(0,e);if(e instanceof t)return Math.atan2(e.im,e.re);if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Q);if(e.valueOf()!==e)return Q(e.valueOf());throw w("arg",e)}function J(e){if(1!=arguments.length)throw E("conj",arguments.length,1);if(v(e))return e;if(e instanceof t)return new t(e.re,-e.im);if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,J);if(e.valueOf()!==e)return J(e.valueOf());throw w("conj",e)}function $(e){if(1!=arguments.length)throw E("im",arguments.length,1);if(v(e))return 0;if(e instanceof t)return e.im;if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,$);if(e.valueOf()!==e)return $(e.valueOf());throw w("im",e)}function et(e){if(1!=arguments.length)throw E("re",arguments.length,1);if(v(e))return e;if(e instanceof t)return e.re;if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,et);if(e.valueOf()!==e)return et(e.valueOf());throw w("re",e)}function tt(){switch(arguments.length){case 0:return new t(0,0);case 1:var e=arguments[0];if(!y(e))throw new TypeError("Two numbers or a single string expected in function complex");var n=t.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid complex number');case 2:return new t(arguments[0],arguments[1]);default:throw E("complex",arguments.length,0,2)}}function nt(e){if(arguments.length>1)throw E("matrix",arguments.length,0,1);return new n(e)}function rt(){return new Qt.expr.Parser}function at(e){switch(arguments.length){case 1:if(!y(e))throw new TypeError("Two or three numbers or a single string expected in function range");var t=g.parse(e);if(t)return t;throw new SyntaxError('String "'+t+'" is no valid range');case 2:return new g(arguments[0],null,arguments[1]);case 3:return new g(arguments[0],arguments[1],arguments[2]);default:throw E("range",arguments.length,2,3)}}function it(){switch(arguments.length){case 1:var e=arguments[0];if(!y(e))throw new TypeError("A string or a number and string expected in function unit");if(x.isUnit(e))return new x(null,e);var t=x.parse(e);if(t)return t;throw new SyntaxError('String "'+e+'" is no valid unit');case 2:return new x(arguments[0],arguments[1]);default:throw E("unit",arguments.length,1,2)}}function ot(){return new Qt.expr.Workspace}function st(e){if(1!=arguments.length)throw E("det",arguments.length,1);var t=Qt.size(e);switch(t.length){case 0:return Qt.clone(e);case 1:if(1==t[0])return Qt.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+Qt.format(t)+")");case 2:var n=t[0],r=t[1];if(n==r)return ft(e.valueOf(),n,r);throw new RangeError("Matrix must be square (size: "+Qt.format(t)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+Qt.format(t)+")")}}function ft(e,t,n){if(1==t)return e[0][0];if(2==t)return Qt.subtract(Qt.multiply(e[0][0],e[1][1]),Qt.multiply(e[1][0],e[0][1]));for(var r=0,a=0;n>a;a++){var i=ut(e,t,n,0,a);r+=Qt.multiply(Qt.multiply((a+1)%2+(a+1)%2-1,e[0][a]),ft(i,t-1,n-1))}return r}function ut(e,t,n,r,a){for(var i,o=[],s=0;t>s;s++)if(s!=r){i=o[s-(s>r)]=[];for(var f=0;n>f;f++)f!=a&&(i[f-(f>a)]=e[s][f])}return o}function ct(e,t){var r,a,i,o;if(1!=arguments.length&&2!=arguments.length)throw E("diag",arguments.length,1,2);if(t){if(!v(t)||!d(t))throw new TypeError("Second parameter in function diag must be an integer")}else t=0;var s=t>0?t:0,f=0>t?-t:0;e instanceof n||e instanceof g||(e=new n(e));var u;switch(e.isVector()?(e=e.toVector(),u=[e.length]):u=e.size(),u.length){case 1:a=e.valueOf();var c=new n;for(c.resize([a.length+f,a.length+s]),r=c.valueOf(),o=a.length,i=0;o>i;i++)r[i+f][i+s]=It(a[i]);return c;case 2:for(a=[],r=e.valueOf(),o=Math.min(u[0]-f,u[1]-s),i=0;o>i;i++)a[i]=It(r[i+f][i+s]);return new n(a);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}}function lt(){var e=Jt.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw E("eye",num,0,2);var t=e[0],r=e[1];if(!v(t)||!d(t)||1>t)throw Error("Parameters in function eye must be positive integers");if(r&&(!v(r)||!d(r)||1>r))throw Error("Parameters in function eye must be positive integers");var a=new n;a.resize(e);for(var i=Qt.min(e),o=a.valueOf(),s=0;i>s;s++)o[s][s]=1;return a}function ht(e){if(1!=arguments.length)throw E("inv",arguments.length,1);var t=Qt.size(e);switch(t.length){case 0:return Qt.divide(1,e);case 1:if(1==t[0])return e instanceof n?new n([Qt.divide(1,e.valueOf()[0])]):[Qt.divide(1,e[0])];throw new RangeError("Matrix must be square (size: "+Qt.format(t)+")");case 2:var r=t[0],a=t[1];if(r==a)return e instanceof n?new n(mt(e.valueOf(),r,a)):mt(e,r,a);throw new RangeError("Matrix must be square (size: "+Qt.format(t)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+Qt.format(t)+")")}}function mt(e,t,n){var r,a,i,o,s;if(1==t){if(o=e[0][0],0==o)throw Error("Cannot calculate inverse, determinant is zero");return[[Qt.divide(1,o)]]}if(2==t){var f=Qt.det(e);if(0==f)throw Error("Cannot calculate inverse, determinant is zero");return[[Qt.divide(e[1][1],f),Qt.divide(Qt.unaryminus(e[0][1]),f)],[Qt.divide(Qt.unaryminus(e[1][0]),f),Qt.divide(e[0][0],f)]]}var u=e.concat();for(r=0;t>r;r++)u[r]=u[r].concat();for(var c=Qt.eye(t).valueOf(),l=0;n>l;l++){for(r=l;t>r&&0==u[r][l];)r++;if(r==t||0==u[r][l])throw Error("Cannot calculate inverse, determinant is zero");r!=l&&(s=u[l],u[l]=u[r],u[r]=s,s=c[l],c[l]=c[r],c[r]=s);var h=u[l],m=c[l];for(r=0;t>r;r++){var p=u[r],v=c[r];if(r!=l){if(0!=p[l]){for(i=Qt.divide(Qt.unaryminus(p[l]),h[l]),a=l;n>a;a++)p[a]=Qt.add(p[a],Qt.multiply(i,h[a]));for(a=0;n>a;a++)v[a]=Qt.add(v[a],Qt.multiply(i,m[a]))}}else{for(i=h[l],a=l;n>a;a++)p[a]=Qt.divide(p[a],i);for(a=0;n>a;a++)v[a]=Qt.divide(v[a],i)}}}return c}function pt(){var e=Jt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new n,r=1;return t.resize(e,r),t}function vt(e){if(1!=arguments.length)throw E("size",arguments.length,1);if(v(e)||e instanceof t||e instanceof x||null==e)return[];if(y(e))return[e.length];if(e instanceof Array)return Jt.size(e);if(e instanceof n||e instanceof g)return e.size();if(e.valueOf()!==e)return vt(e.valueOf());throw w("size",e)}function dt(e){if(1!=arguments.length)throw E("squeeze",arguments.length,1);return e instanceof n||e instanceof g?gt(e.toArray()):e instanceof Array?gt(It(e)):It(e)}function gt(e){if(1==e.length)return gt(e[0]);for(var t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array&&(e[t]=gt(r))}return e}function yt(e){if(1!=arguments.length)throw E("transpose",arguments.length,1);var t=Qt.size(e);switch(t.length){case 0:return Qt.clone(e);case 1:return Qt.clone(e);case 2:for(var n,r=t[1],a=t[0],i=e.valueOf(),o=[],s=Qt.clone,f=0;r>f;f++){n=o[f]=[];for(var u=0;a>u;u++)n[u]=s(i[u][f])}return 0==a&&(o[0]=[]),o;default:throw new RangeError("Matrix must be two dimensional (size: "+Qt.format(t)+")")}}function xt(){var e=Jt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new n;return t.resize(e),t}function wt(e){if(1!=arguments.length)throw E("factorial",arguments.length,1);if(v(e)){if(!d(e))throw new TypeError("Function factorial can only handle integer values");var t=e,r=t;for(t--;t>1;)r*=t,t--;return 0==r&&(r=1),r}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,wt);if(e.valueOf()!==e)return wt(e.valueOf());throw w("factorial",e)}function Et(){if(0!=arguments.length)throw E("random",arguments.length,0);return Math.random()}function Nt(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return Nt.apply(this,e.valueOf());for(var t=arguments[0],n=1,r=arguments.length;r>n;n++){var a=arguments[n];L(a,t)&&(t=a)}return t}function bt(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return bt.apply(this,e.valueOf());for(var t=arguments[0],n=1,r=arguments.length;r>n;n++){var a=arguments[n];F(a,t)&&(t=a)}return t}function Ot(e){if(1!=arguments.length)throw E("acos",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.acos(e):Ot(new t(e,0));if(e instanceof t){var r=new t(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),a=Y(r),i=new t(a.re-e.im,a.im+e.re),o=_(i);return new t(1.5707963267948966-o.im,o.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Ot);if(e.valueOf()!==e)return Ot(e.valueOf());throw w("acos",e)}function Mt(e){if(1!=arguments.length)throw E("asin",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.asin(e):Mt(new t(e,0));if(e instanceof t){var r=e.re,a=e.im,i=new t(a*a-r*r+1,-2*r*a),o=Y(i),s=new t(o.re-a,o.im+r),f=_(s);return new t(f.im,-f.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Mt);if(e.valueOf()!==e)return Mt(e.valueOf());throw w("asin",e)}function At(e){if(1!=arguments.length)throw E("atan",arguments.length,1);if(v(e))return Math.atan(e);if(e instanceof t){var r=e.re,a=e.im,i=r*r+(1-a)*(1-a),o=new t((1-a*a-r*r)/i,-2*r/i),s=_(o);return new t(-.5*s.im,.5*s.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,At);if(e.valueOf()!==e)return At(e.valueOf());throw w("atan",e)}function St(e,r){if(2!=arguments.length)throw E("atan2",arguments.length,2);if(v(e)){if(v(r))return Math.atan2(e,r);if(r instanceof t)return Math.atan2(e,r.re)}else if(e instanceof t){if(v(r))return Math.atan2(e.re,r);if(r instanceof t)return Math.atan2(e.re,r.re)}if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Jt.map2(e,r,St);if(r.valueOf()!==r||e.valueOf()!==e)return St(e.valueOf(),r.valueOf());throw w("atan2",e,r)}function Tt(e){if(1!=arguments.length)throw E("cos",arguments.length,1);if(v(e))return Math.cos(e);if(e instanceof t)return new t(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.sin(e.re)*(Math.exp(-e.im)-Math.exp(e.im)));if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(e.value)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Tt);if(e.valueOf()!==e)return Tt(e.valueOf());throw w("cos",e)}function zt(e){if(1!=arguments.length)throw E("cot",arguments.length,1);if(v(e))return 1/Math.tan(e);if(e instanceof t){var r=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new t(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(Math.exp(-4*e.im)-1)/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(e.value)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,zt);if(e.valueOf()!==e)return zt(e.valueOf());throw w("cot",e)}function qt(e){if(1!=arguments.length)throw E("csc",arguments.length,1);if(v(e))return 1/Math.sin(e);if(e instanceof t){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return new t(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.cos(e.re)*(Math.exp(-e.im)-Math.exp(e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(e.value)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,qt);if(e.valueOf()!==e)return qt(e.valueOf());throw w("csc",e)}function Ut(e){if(1!=arguments.length)throw E("sec",arguments.length,1);if(v(e))return 1/Math.cos(e);if(e instanceof t){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return new t(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.sin(e.re)*(Math.exp(e.im)-Math.exp(-e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(e.value)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Ut);if(e.valueOf()!==e)return Ut(e.valueOf());throw w("sec",e)}function Lt(e){if(1!=arguments.length)throw E("sin",arguments.length,1);if(v(e))return Math.sin(e);if(e instanceof t)return new t(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.cos(e.re)*(Math.exp(e.im)-Math.exp(-e.im)));if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(e.value)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Lt);if(e.valueOf()!==e)return Lt(e.valueOf());throw w("sin",e)}function Rt(e){if(1!=arguments.length)throw E("tan",arguments.length,1);if(v(e))return Math.tan(e);if(e instanceof t){var r=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new t(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(1-Math.exp(-4*e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(e.value)}if(e instanceof Array||e instanceof n||e instanceof g)return Jt.map(e,Rt);if(e.valueOf()!==e)return Rt(e.valueOf());throw w("tan",e)}function _t(e,t){if(2!=arguments.length)throw E("in",arguments.length,2);if(e instanceof x&&t instanceof x){if(!e.equalBase(t))throw Error("Units do not match");if(t.hasValue)throw Error("Cannot convert to a unit with a value");if(!t.hasUnit)throw Error("Unit expected on the right hand side of function in");var r=t.clone();return r.value=e.value,r.fixPrefix=!0,r}if(e instanceof Array||e instanceof n||e instanceof g||t instanceof Array||t instanceof n||t instanceof g)return Jt.map2(e,t,_t);if(e.valueOf()!==e)return Qt.in(e.valueOf());throw w("in",e)}function It(t){if(1!=arguments.length)throw E("clone",arguments.length,1);if(null==t)return t;if("function"==typeof t.clone)return t.clone();if(v(t)||y(t)||e(t))return t;if(t instanceof Array)return t.map(function(e){return It(e)});if(t instanceof Object)return Jt.mapObject(t,It);throw w("clone",t)}function Ct(e,t){var n=arguments.length;if(1!=n&&2!=n)throw E("format",n,1,2);if(1==n){var r=arguments[0];return v(r)?Jt.formatNumber(r):r instanceof Array?Jt.formatArray(r):y(r)?'"'+r+'"':r instanceof Object?""+r:r+""}if(!y(e))throw new TypeError("String expected as first parameter in function format"); -if(!(t instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,n){for(var r=n.split("."),a=t[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})}function Pt(e){if(1!=arguments.length)throw E("help",arguments.length,1);if(void 0!=e){if(e.doc)return Bt(e.doc);if(e.constructor.doc)return Bt(e.constructor.doc);if(y(e)){var t=Qt[e];if(t&&t.doc)return Bt(t.doc)}}return e instanceof Object&&e.name?'No documentation found on subject "'+e.name+'"':e instanceof Object&&e.constructor.name?'No documentation found on subject "'+e.constructor.name+'"':'No documentation found on subject "'+e+'"'}function Bt(e){var t="";if(e.name&&(t+="NAME\n"+e.name+"\n\n"),e.category&&(t+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(t+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var n=Qt.parser();t+="EXAMPLES\n";for(var r=0;e.examples.length>r;r++){var a,i=e.examples[r];try{a=n.eval(i)}catch(o){a=o}t+=i+"\n",t+=" "+Qt.format(a)+"\n"}t+="\n"}return e.seealso&&(t+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),t}function kt(e,t){var n;if(y(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var r=require(e);kt(r)}else if(Gt(e)){if(n=e.name,!n)throw Error("Cannot import an unnamed function");(t||void 0===Qt[n])&&(Qt[n]=e)}else if(e instanceof Object)for(n in e)if(e.hasOwnProperty(n)){var a=e[n];Gt(a)?(t||void 0===Qt[n])&&(Qt[n]=a):kt(a)}}function Gt(e){return"function"==typeof e||v(e)||y(e)||e instanceof t||e instanceof x}function jt(e){if(1!=arguments.length)throw E("typeof",arguments.length,1);var t=typeof e;if("object"==t){if(null==e)return"null";if(e.constructor){for(var n in Qt)if(Qt.hasOwnProperty(n)&&e.constructor==Qt[n])return n.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t}function Vt(){}function Dt(e,t,n){this.name=e,this.fn=t,this.params=n}function Ft(e){this.value=e}function Ht(e){this.nodes=e||[]}function Yt(){this.params=[],this.visible=[]}function Wt(e,t,n,r){this.name=e,this.params=t,this.expr=n,this.result=r}function Xt(e,t){this.object=e,this.params=t}function Zt(e,t,n,r,a){this.name=e,this.variables=n,this.values=[];for(var i=0,o=this.variables.length;o>i;i++)this.values[i]=function(){var e=function(){return e.value};return e.value=void 0,e}();this.def=this.createFunction(e,t,n,r),this.result=a}function Kt(e,t){throw Error('Constructor "'+e+'" has been replaced by '+'constructor method "'+t+'" in math.js v0.5.0')}var Qt={type:{},expr:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=Qt),"undefined"!=typeof exports&&(exports=Qt),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return Qt}),"undefined"!=typeof window&&(window.math=Qt);var Jt=function(){function e(e){if(e instanceof Array){var t=e.length;if(t){var n=o(e[0]);return 0==n[0]?[0].concat(n):[t].concat(n)}return[t]}return[]}function t(e,n,r){var a,i=e.length;if(i!=n[r])throw new RangeError("Dimension mismatch ("+i+" != "+n[r]+")");if(n.length-1>r){var o=r+1;for(a=0;i>a;a++){var s=e[a];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(n.length-1)+" < "+n.length+")");t(e[a],n,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(n.length+1)+" > "+n.length+")")}function r(e,t,n){if(t.length-1>n){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");r(a,t,n+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,t,n,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=t[n];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?It(r):0;else e.length=t[n];i=e.length}if(t.length-1>n){var f=n+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,t,f,r)}else for(s=0;i>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var i={};return i.formatNumber=function(e,t){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var n=Math.abs(e);if(n>1e-4&&1e6>n||0==n)return V(e,t)+"";var r=Math.round(Math.log(n)/Math.LN10),a=e/Math.pow(10,r);return V(a,t)+"E"+r},i.formatArray=function(e){if(e instanceof Array){for(var t="[",n=e.length,r=0;n>r;r++)0!=r&&(t+=", "),t+=i.formatArray(e[r]);return t+="]"}return Ct(e)},i.formatArray2d=function(e){var t="[",n=i.size(e);if(2!=n.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(n)+")");for(var r=n[0],a=n[1],o=0;r>o;o++){0!=o&&(t+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(t+=", ");var u=s[f];void 0!=u&&(t+=Ct(u))}}return t+="]"},i.argsToArray=function(e){var t;if(0==e.length)t=[];else if(1==e.length)t=e[0],t instanceof n&&(t=t.toVector()),t instanceof g&&(t=t.valueOf()),t instanceof Array||(t=[t]);else{t=[];for(var r=0;e.length>r;r++)t[r]=e[r]}return t},i.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},i.map=function(e,t){if(e instanceof Array||e instanceof n||e instanceof g)return e.map(function(e){return t(e)});throw new TypeError("Array expected")},i.map2=function(e,t,r){var a,o,s;if(e instanceof n||t instanceof n)return new n(i.map2(e.valueOf(),t.valueOf(),r));if(e instanceof g||t instanceof g)return new n(i.map2(e.valueOf(),t.valueOf(),r));if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],t[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],t);else if(t instanceof Array)for(a=[],o=t.length,s=0;o>s;s++)a[s]=r(e,t[s]);else a=r(e,t);return a},i.forEach=function(e,t){if(e instanceof Array)e.forEach(t);else for(var n in e)e.hasOwnProperty(n)&&t(e[n],n,e)},i.mapObject=function(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n},i.deepEqual=function(e,t){var n,r,a;if(e instanceof Array){if(!(t instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],t[r]))return!1;return!0}if(e instanceof Object){if(t instanceof Array||!(t instanceof Object))return!1;for(n in e)if(e.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;for(n in t)if(t.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;return!0}return e.valueOf()==t.valueOf()},i.size=function o(t){var n=e(t);return i.validate(t,n),n},i.validate=function(e,n){var a=0==n.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=n.indexOf(0);o?(n.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(n)+")")}),r(e,n,0)):t(e,n,0)}},i.resize=function(e,t,n){if(!(t instanceof Array))throw new TypeError("Size must be an array (size is "+Qt.typeof(t)+")");t.forEach(function(e){if(!v(e)||!d(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(t)+")")});var r=-1!=t.indexOf(0);r&&t.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(t)+")")}),a(e,t,0,n)},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;this.length>t;t++)if(this[t]==e)return t;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){for(var n=0,r=this.length;r>n;++n)e.call(t||this,this[n],n,this)}),Array.prototype.map||(Array.prototype.map=function(e,t){var n,r,a;if(null==this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(t&&(n=t),r=Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(n,s,a,i),r[a]=f),a++}return r}),Array.prototype.every||(Array.prototype.every=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&!e.call(r,t[a],a,t))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&e.call(r,t[a],a,t))return!0;return!1}),i}();Qt.type.Complex=t,function(){function e(){for(;" "==c||" "==c;)a()}function n(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function a(){u++,c=f[u]}function i(e){u=e,c=f[u]}function o(){var e="",t=u;if("+"==c?a():"-"==c&&(e+=c,a()),!n(c))return i(t),null;for(;n(c);)e+=c,a();if("E"==c||"e"==c){if(e+=c,a(),("+"==c||"-"==c)&&(e+=c,a()),!r(c))return i(t),null;for(;r(c);)e+=c,a()}return e}function s(){var e=f[u+1];if("I"==c||"i"==c)return a(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var t="+"==c?"1":"-1";return a(),a(),t}return null}var f,u,c;t.parse=function(n){if(f=n,u=-1,c="",!y(f))return null;a(),e();var r=o();if(r){if("I"==c||"i"==c)return a(),e(),c?null:new t(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new t(Number(r),0);a(),e();var l=o();if(l){if("I"!=c&&"i"!=c)return null;a()}else if(l=s(),!l)return null;return"-"==i&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),a(),e(),c?null:new t(Number(r),Number(l))}return(r=s())?(e(),c?null:new t(0,Number(r))):null}}(),t.prototype.clone=function(){return new t(this.re,this.im)},t.prototype.toString=function(){var e="",t=Jt.formatNumber(this.re),n=Jt.formatNumber(this.im);return e=0==this.im?t:0==this.re?1==this.im?"i":-1==this.im?"-i":n+"i":this.im>0?1==this.im?t+" + i":t+" + "+n+"i":-1==this.im?t+" - i":t+" - "+Jt.formatNumber(Math.abs(this.im))+"i"},t.doc={name:"Complex",category:"type",syntax:["a + bi","a + b * i"],description:"A complex value a + bi, where a is the real part and b is the complex part, and i is the imaginary number defined as sqrt(-1).",examples:["2 + 3i","sqrt(-4)","(1.2 -5i) * 2"],seealso:["abs","arg","conj","im","re"]},Qt.type.Matrix=n,n.prototype.get=function(e){var t;if(e instanceof n)t=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+Qt.typeof(e));t=!e.some(function(e){return e.forEach})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(t)switch(e.length){case 1:return a(this._data,e[0]);case 2:return a(a(this._data,e[0]),e[1]);default:return i(this._data,e)}else switch(e.length){case 1:return new n(o(this._data,e));case 2:return new n(s(this._data,e));default:return new n(f(this._data,e,0))}},n.prototype.set=function(e,t){var r;if(e instanceof n)r=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+Qt.typeof(e));r=!e.some(function(e){return e.forEach})}if((t instanceof n||t instanceof g)&&(t=t.valueOf()),e.length=e})},n.prototype.toVector=function(){var e=0,t=void 0,n=[];if(this._size.forEach(function(r,a){r>1&&(e++,t=a),n[a]=0}),0==e){var r=this.toScalar();return r?[r]:[]}if(1==e){var a=[],i=function(e){e instanceof Array?e.forEach(i):a.push(e)};return i(this._data),a}return null},n.prototype.isVector=function(){var e=0;return this._size.forEach(function(t){t>1&&e++}),1>=e},n.prototype.toArray=function(){return It(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.toString=function(){return Jt.formatArray(this._data)},Qt.type.Range=g,g.parse=function(e){if(!y(e))return null;var t=e.split(":"),n=t.map(function(e){return Number(e)}),r=n.some(function(e){return isNaN(e)});if(r)return null;switch(n.length){case 2:return new g(n[0],1,n[1]);case 3:return new g(n[0],n[1],n[2]);default:return null}},g.prototype.clone=function(){return new g(this.start,this.step,this.end)},g.prototype.size=function(){var e=0,t=Number(this.start),n=Number(this.step),r=Number(this.end),a=r-t;return D(n)==D(a)?e=Math.floor(a/n)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},g.prototype.forEach=function(e){var t=Number(this.start),n=Number(this.step),r=Number(this.end),a=0;if(n>0)for(;r>=t;)e(t,a,this),t+=n,a++;else if(0>n)for(;t>=r;)e(t,a,this),t+=n,a++},g.prototype.map=function(e){var t=[];return this.forEach(function(n,r,a){t[r]=e(n,r,a)}),t},g.prototype.toMatrix=function(){return new n(this.toArray())},g.prototype.toArray=function(){var e=[];return this.forEach(function(t,n){e[n]=t}),e},g.prototype.toVector=g.prototype.toArray,g.prototype.isVector=function(){return!0},g.prototype.toScalar=function(){var e=this.toArray();return 1==e.length?e[0]:null},g.prototype.isScalar=function(){return 1==this.size()[0]},g.prototype.valueOf=function(){return this.toArray()},g.prototype.toString=function(){var e=Ct(Number(this.start));return 1!=this.step&&(e+=":"+Ct(Number(this.step))),e+=":"+Ct(Number(this.end))},Qt.type.Unit=x,function(){function e(){for(;" "==u||" "==u;)r()}function t(e){return e>="0"&&"9">=e||"."==e}function n(e){return e>="0"&&"9">=e}function r(){f++,u=s[f]}function a(e){f=e,u=s[f]}function i(){var e="",i=f;if("+"==u?r():"-"==u&&(e+=u,r()),!t(u))return a(i),null;for(;t(u);)e+=u,r();if("E"==u||"e"==u){if(e+=u,r(),("+"==u||"-"==u)&&(e+=u,r()),!n(u))return a(i),null;for(;n(u);)e+=u,r()}return e}function o(){var t="";for(e();u&&" "!=u&&" "!=u;)t+=u,r();return t||null}var s,f,u;x.parse=function(t){if(s=t,f=-1,u="",!y(s))return null;r(),e();var n,a=i();return a?(n=o(),r(),e(),u?null:a&&n?new x(Number(a),n):null):(n=o(),r(),e(),u?null:new x(null,n))}}(),x.prototype.clone=function(){var e=new x;for(var t in this)this.hasOwnProperty(t)&&(e[t]=this[t]);return e},x.endsWith=function(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t},x.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},x.prototype._unnormalize=function(e,t){return void 0===t?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/t-this.unit.offset},x.isUnit=function(e){for(var t=x.UNITS,n=t.length,r=0;n>r;r++){var a=t[r];if(x.endsWith(e,a.name)){var i=e.length-a.name.length;if(0==i)return!0;var o=e.substring(0,i),s=a.prefixes[o];if(void 0!==s)return!0}}return!1},x.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},x.prototype.equalBase=function(e){return this.unit.base===e.unit.base},x.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},x.prototype.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),Jt.formatNumber(e)+" "+this.prefix.name+this.unit.name;var t=Math.abs(this.value/this.unit.value),n=x.PREFIX_NONE,r=Math.abs(Math.log(t/n.value)/Math.LN10-1.2),a=this.unit.prefixes;for(var i in a)if(a.hasOwnProperty(i)){var o=a[i];if(o.scientific){var s=Math.abs(Math.log(t/o.value)/Math.LN10-1.2);r>s&&(n=o,r=s)}}return e=this._unnormalize(this.value,n.value),Jt.formatNumber(e)+" "+n.name+this.unit.name},x.PREFIXES={NONE:{"":{name:"",value:1,scientific:!0}},SHORT:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:10,scientific:!1},h:{name:"h",value:100,scientific:!1},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},d:{name:"d",value:.1,scientific:!1},c:{name:"c",value:.01,scientific:!1},m:{name:"m",value:.001,scientific:!0},u:{name:"u",value:1e-6,scientific:!0},n:{name:"n",value:1e-9,scientific:!0},p:{name:"p",value:1e-12,scientific:!0},f:{name:"f",value:1e-15,scientific:!0},a:{name:"a",value:1e-18,scientific:!0},z:{name:"z",value:1e-21,scientific:!0},y:{name:"y",value:1e-24,scientific:!0}},LONG:{"":{name:"",value:1,scientific:!0},deca:{name:"deca",value:10,scientific:!1},hecto:{name:"hecto",value:100,scientific:!1},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},deci:{name:"deci",value:.1,scientific:!1},centi:{name:"centi",value:.01,scientific:!1},milli:{name:"milli",value:.001,scientific:!0},micro:{name:"micro",value:1e-6,scientific:!0},nano:{name:"nano",value:1e-9,scientific:!0},pico:{name:"pico",value:1e-12,scientific:!0},femto:{name:"femto",value:1e-15,scientific:!0},atto:{name:"atto",value:1e-18,scientific:!0},zepto:{name:"zepto",value:1e-21,scientific:!0},yocto:{name:"yocto",value:1e-24,scientific:!0}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1024,scientific:!0},M:{name:"M",value:Math.pow(1024,2),scientific:!0},G:{name:"G",value:Math.pow(1024,3),scientific:!0},T:{name:"T",value:Math.pow(1024,4),scientific:!0},P:{name:"P",value:Math.pow(1024,5),scientific:!0},E:{name:"E",value:Math.pow(1024,6),scientific:!0},Z:{name:"Z",value:Math.pow(1024,7),scientific:!0},Y:{name:"Y",value:Math.pow(1024,8),scientific:!0},Ki:{name:"Ki",value:1024,scientific:!0},Mi:{name:"Mi",value:Math.pow(1024,2),scientific:!0},Gi:{name:"Gi",value:Math.pow(1024,3),scientific:!0},Ti:{name:"Ti",value:Math.pow(1024,4),scientific:!0},Pi:{name:"Pi",value:Math.pow(1024,5),scientific:!0},Ei:{name:"Ei",value:Math.pow(1024,6),scientific:!0},Zi:{name:"Zi",value:Math.pow(1024,7),scientific:!0},Yi:{name:"Yi",value:Math.pow(1024,8),scientific:!0}},BINARY_LONG:{"":{name:"",value:1,scientific:!0},kilo:{name:"kilo",value:1024,scientific:!0},mega:{name:"mega",value:Math.pow(1024,2),scientific:!0},giga:{name:"giga",value:Math.pow(1024,3),scientific:!0},tera:{name:"tera",value:Math.pow(1024,4),scientific:!0},peta:{name:"peta",value:Math.pow(1024,5),scientific:!0},exa:{name:"exa",value:Math.pow(1024,6),scientific:!0},zetta:{name:"zetta",value:Math.pow(1024,7),scientific:!0},yotta:{name:"yotta",value:Math.pow(1024,8),scientific:!0},kibi:{name:"kibi",value:1024,scientific:!0},mebi:{name:"mebi",value:Math.pow(1024,2),scientific:!0},gibi:{name:"gibi",value:Math.pow(1024,3),scientific:!0},tebi:{name:"tebi",value:Math.pow(1024,4),scientific:!0},pebi:{name:"pebi",value:Math.pow(1024,5),scientific:!0},exi:{name:"exi",value:Math.pow(1024,6),scientific:!0},zebi:{name:"zebi",value:Math.pow(1024,7),scientific:!0},yobi:{name:"yobi",value:Math.pow(1024,8),scientific:!0}}},x.PREFIX_NONE={name:"",value:1,scientific:!0},x.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var $t=x.BASE_UNITS,en=x.PREFIXES;x.BASE_UNIT_NONE={},x.UNIT_NONE={name:"",base:x.BASE_UNIT_NONE,value:1,offset:0},x.UNITS=[{name:"meter",base:$t.LENGTH,prefixes:en.LONG,value:1,offset:0},{name:"inch",base:$t.LENGTH,prefixes:en.NONE,value:.0254,offset:0},{name:"foot",base:$t.LENGTH,prefixes:en.NONE,value:.3048,offset:0},{name:"yard",base:$t.LENGTH,prefixes:en.NONE,value:.9144,offset:0},{name:"mile",base:$t.LENGTH,prefixes:en.NONE,value:1609.344,offset:0},{name:"link",base:$t.LENGTH,prefixes:en.NONE,value:.201168,offset:0},{name:"rod",base:$t.LENGTH,prefixes:en.NONE,value:5.02921,offset:0},{name:"chain",base:$t.LENGTH,prefixes:en.NONE,value:20.1168,offset:0},{name:"angstrom",base:$t.LENGTH,prefixes:en.NONE,value:1e-10,offset:0},{name:"m",base:$t.LENGTH,prefixes:en.SHORT,value:1,offset:0},{name:"ft",base:$t.LENGTH,prefixes:en.NONE,value:.3048,offset:0},{name:"yd",base:$t.LENGTH,prefixes:en.NONE,value:.9144,offset:0},{name:"mi",base:$t.LENGTH,prefixes:en.NONE,value:1609.344,offset:0},{name:"li",base:$t.LENGTH,prefixes:en.NONE,value:.201168,offset:0},{name:"rd",base:$t.LENGTH,prefixes:en.NONE,value:5.02921,offset:0},{name:"ch",base:$t.LENGTH,prefixes:en.NONE,value:20.1168,offset:0},{name:"mil",base:$t.LENGTH,prefixes:en.NONE,value:254e-7,offset:0},{name:"m2",base:$t.SURFACE,prefixes:en.SHORT,value:1,offset:0},{name:"sqin",base:$t.SURFACE,prefixes:en.NONE,value:64516e-8,offset:0},{name:"sqft",base:$t.SURFACE,prefixes:en.NONE,value:.09290304,offset:0},{name:"sqyd",base:$t.SURFACE,prefixes:en.NONE,value:.83612736,offset:0},{name:"sqmi",base:$t.SURFACE,prefixes:en.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:$t.SURFACE,prefixes:en.NONE,value:25.29295,offset:0},{name:"sqch",base:$t.SURFACE,prefixes:en.NONE,value:404.6873,offset:0},{name:"sqmil",base:$t.SURFACE,prefixes:en.NONE,value:6.4516e-10,offset:0},{name:"m3",base:$t.VOLUME,prefixes:en.SHORT,value:1,offset:0},{name:"L",base:$t.VOLUME,prefixes:en.SHORT,value:.001,offset:0},{name:"litre",base:$t.VOLUME,prefixes:en.LONG,value:.001,offset:0},{name:"cuin",base:$t.VOLUME,prefixes:en.NONE,value:16387064e-12,offset:0},{name:"cuft",base:$t.VOLUME,prefixes:en.NONE,value:.028316846592,offset:0},{name:"cuyd",base:$t.VOLUME,prefixes:en.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:$t.VOLUME,prefixes:en.NONE,value:5e-6,offset:0},{name:"tablespoon",base:$t.VOLUME,prefixes:en.NONE,value:15e-6,offset:0},{name:"minim",base:$t.VOLUME,prefixes:en.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:$t.VOLUME,prefixes:en.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:$t.VOLUME,prefixes:en.NONE,value:2957353e-11,offset:0},{name:"gill",base:$t.VOLUME,prefixes:en.NONE,value:.0001182941,offset:0},{name:"cup",base:$t.VOLUME,prefixes:en.NONE,value:.0002365882,offset:0},{name:"pint",base:$t.VOLUME,prefixes:en.NONE,value:.0004731765,offset:0},{name:"quart",base:$t.VOLUME,prefixes:en.NONE,value:.0009463529,offset:0},{name:"gallon",base:$t.VOLUME,prefixes:en.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:$t.VOLUME,prefixes:en.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:$t.VOLUME,prefixes:en.NONE,value:.1589873,offset:0},{name:"hogshead",base:$t.VOLUME,prefixes:en.NONE,value:.238481,offset:0},{name:"fldr",base:$t.VOLUME,prefixes:en.NONE,value:36966911e-13,offset:0},{name:"floz",base:$t.VOLUME,prefixes:en.NONE,value:2957353e-11,offset:0},{name:"gi",base:$t.VOLUME,prefixes:en.NONE,value:.0001182941,offset:0},{name:"cp",base:$t.VOLUME,prefixes:en.NONE,value:.0002365882,offset:0},{name:"pt",base:$t.VOLUME,prefixes:en.NONE,value:.0004731765,offset:0},{name:"qt",base:$t.VOLUME,prefixes:en.NONE,value:.0009463529,offset:0},{name:"gal",base:$t.VOLUME,prefixes:en.NONE,value:.003785412,offset:0},{name:"bbl",base:$t.VOLUME,prefixes:en.NONE,value:.1173478,offset:0},{name:"obl",base:$t.VOLUME,prefixes:en.NONE,value:.1589873,offset:0},{name:"g",base:$t.MASS,prefixes:en.SHORT,value:.001,offset:0},{name:"gram",base:$t.MASS,prefixes:en.LONG,value:.001,offset:0},{name:"ton",base:$t.MASS,prefixes:en.SHORT,value:907.18474,offset:0},{name:"tonne",base:$t.MASS,prefixes:en.SHORT,value:1e3,offset:0},{name:"grain",base:$t.MASS,prefixes:en.NONE,value:6479891e-11,offset:0},{name:"dram",base:$t.MASS,prefixes:en.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:$t.MASS,prefixes:en.NONE,value:.028349523125,offset:0},{name:"poundmass",base:$t.MASS,prefixes:en.NONE,value:.45359237,offset:0},{name:"hundredweight",base:$t.MASS,prefixes:en.NONE,value:45.359237,offset:0},{name:"stick",base:$t.MASS,prefixes:en.NONE,value:.115,offset:0},{name:"gr",base:$t.MASS,prefixes:en.NONE,value:6479891e-11,offset:0},{name:"dr",base:$t.MASS,prefixes:en.NONE,value:.0017718451953125,offset:0},{name:"oz",base:$t.MASS,prefixes:en.NONE,value:.028349523125,offset:0},{name:"lbm",base:$t.MASS,prefixes:en.NONE,value:.45359237,offset:0},{name:"cwt",base:$t.MASS,prefixes:en.NONE,value:45.359237,offset:0},{name:"s",base:$t.TIME,prefixes:en.SHORT,value:1,offset:0},{name:"min",base:$t.TIME,prefixes:en.NONE,value:60,offset:0},{name:"h",base:$t.TIME,prefixes:en.NONE,value:3600,offset:0},{name:"seconds",base:$t.TIME,prefixes:en.LONG,value:1,offset:0},{name:"second",base:$t.TIME,prefixes:en.LONG,value:1,offset:0},{name:"sec",base:$t.TIME,prefixes:en.LONG,value:1,offset:0},{name:"minutes",base:$t.TIME,prefixes:en.NONE,value:60,offset:0},{name:"minute",base:$t.TIME,prefixes:en.NONE,value:60,offset:0},{name:"hours",base:$t.TIME,prefixes:en.NONE,value:3600,offset:0},{name:"hour",base:$t.TIME,prefixes:en.NONE,value:3600,offset:0},{name:"day",base:$t.TIME,prefixes:en.NONE,value:86400,offset:0},{name:"days",base:$t.TIME,prefixes:en.NONE,value:86400,offset:0},{name:"rad",base:$t.ANGLE,prefixes:en.NONE,value:1,offset:0},{name:"deg",base:$t.ANGLE,prefixes:en.NONE,value:.017453292519943295,offset:0},{name:"grad",base:$t.ANGLE,prefixes:en.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:$t.ANGLE,prefixes:en.NONE,value:6.283185307179586,offset:0},{name:"A",base:$t.CURRENT,prefixes:en.SHORT,value:1,offset:0},{name:"ampere",base:$t.CURRENT,prefixes:en.LONG,value:1,offset:0},{name:"K",base:$t.TEMPERATURE,prefixes:en.NONE,value:1,offset:0},{name:"degC",base:$t.TEMPERATURE,prefixes:en.NONE,value:1,offset:273.15},{name:"degF",base:$t.TEMPERATURE,prefixes:en.NONE,value:1/1.8,offset:459.67},{name:"degR",base:$t.TEMPERATURE,prefixes:en.NONE,value:1/1.8,offset:0},{name:"kelvin",base:$t.TEMPERATURE,prefixes:en.NONE,value:1,offset:0},{name:"celsius",base:$t.TEMPERATURE,prefixes:en.NONE,value:1,offset:273.15},{name:"fahrenheit",base:$t.TEMPERATURE,prefixes:en.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:$t.TEMPERATURE,prefixes:en.NONE,value:1/1.8,offset:0},{name:"mol",base:$t.AMOUNT_OF_SUBSTANCE,prefixes:en.NONE,value:1,offset:0},{name:"mole",base:$t.AMOUNT_OF_SUBSTANCE,prefixes:en.NONE,value:1,offset:0},{name:"cd",base:$t.LUMINOUS_INTENSITY,prefixes:en.NONE,value:1,offset:0},{name:"candela",base:$t.LUMINOUS_INTENSITY,prefixes:en.NONE,value:1,offset:0},{name:"N",base:$t.FORCE,prefixes:en.SHORT,value:1,offset:0},{name:"newton",base:$t.FORCE,prefixes:en.LONG,value:1,offset:0},{name:"lbf",base:$t.FORCE,prefixes:en.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:$t.FORCE,prefixes:en.NONE,value:4.4482216152605,offset:0},{name:"b",base:$t.BIT,prefixes:en.BINARY_SHORT,value:1,offset:0},{name:"bits",base:$t.BIT,prefixes:en.BINARY_LONG,value:1,offset:0},{name:"B",base:$t.BIT,prefixes:en.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:$t.BIT,prefixes:en.BINARY_LONG,value:8,offset:0}],Qt.E=Math.E,Qt.LN2=Math.LN2,Qt.LN10=Math.LN10,Qt.LOG2E=Math.LOG2E,Qt.LOG10E=Math.LOG10E,Qt.PI=Math.PI,Qt.SQRT1_2=Math.SQRT1_2,Qt.SQRT2=Math.SQRT2,Qt.I=new t(0,-1),Qt.pi=Qt.PI,Qt.e=Qt.E,Qt.i=Qt.I,Qt.abs=N,N.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},Qt.add=b,b.doc={name:"add",category:"Operators",syntax:["x + y","add(x, y)"],description:"Add two values.",examples:["2.1 + 3.6","ans - 3.6","3 + 2i",'"hello" + " world"',"3 cm + 2 inch"],seealso:["subtract"]},Qt.ceil=O,O.doc={name:"ceil",category:"Arithmetic",syntax:["ceil(x)"],description:"Round a value towards plus infinity.If x is complex, both real and imaginary part are rounded towards plus infinity.",examples:["ceil(3.2)","ceil(3.8)","ceil(-4.2)"],seealso:["floor","fix","round"]},Qt.cube=M,M.doc={name:"cube",category:"Arithmetic",syntax:["cube(x)"],description:"Compute the cube of a value. The cube of x is x * x * x.",examples:["cube(2)","2^3","2 * 2 * 2"],seealso:["multiply","square","pow"]},Qt.divide=A,A.doc={name:"divide",category:"Operators",syntax:["x / y","divide(x, y)"],description:"Divide two values.",examples:["2 / 3","ans * 3","4.5 / 2","3 + 4 / 2","(3 + 4) / 2","18 km / 4.5"],seealso:["multiply"]},Qt.equal=T,T.doc={name:"equal",category:"Operators",syntax:["x == y","equal(x, y)"],description:"Check equality of two values. Returns 1 if the values are equal, and 0 if not.",examples:["2+2 == 3","2+2 == 4","a = 3.2","b = 6-2.8","a == b","50cm == 0.5m"],seealso:["unequal","smaller","larger","smallereq","largereq"]},Qt.exp=z,z.doc={name:"exp",category:"Arithmetic",syntax:["exp(x)"],description:"Calculate the exponent of a value.",examples:["exp(1.3)","e ^ 1.3","log(exp(1.3))","x = 2.4","(exp(i*x) == cos(x) + i*sin(x)) # Euler's formula"],seealso:["square","multiply","log"]},Qt.fix=q,q.doc={name:"fix",category:"Arithmetic",syntax:["fix(x)"],description:"Round a value towards zero.If x is complex, both real and imaginary part are rounded towards zero.",examples:["fix(3.2)","fix(3.8)","fix(-4.2)","fix(-4.8)"],seealso:["ceil","floor","round"]},Qt.floor=U,U.doc={name:"floor",category:"Arithmetic",syntax:["floor(x)"],description:"Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.",examples:["floor(3.2)","floor(3.8)","floor(-4.2)"],seealso:["ceil","fix","round"]},Qt.larger=L,L.doc={name:"larger",category:"Operators",syntax:["x > y","larger(x, y)"],description:"Check if value x is larger than y. Returns 1 if x is larger than y, and 0 if not.",examples:["2 > 3","5 > 2*2","a = 3.3","b = 6-2.8","(a > b)","(b < a)","5 cm > 2 inch"],seealso:["equal","unequal","smaller","smallereq","largereq"]},Qt.largereq=R,R.doc={name:"largereq",category:"Operators",syntax:["x >= y","largereq(x, y)"],description:"Check if value x is larger or equal to y. Returns 1 if x is larger or equal to y, and 0 if not.",examples:["2 > 1+1","2 >= 1+1","a = 3.2","b = 6-2.8","(a > b)"],seealso:["equal","unequal","smallereq","smaller","largereq"]},Qt.log=_,_.doc={name:"log",category:"Arithmetic",syntax:["log(x)","log(x, base)"],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).",examples:["log(3.5)","a = log(2.4)","exp(a)","10 ^ 3","log(1000, 10)","log(1000) / log(10)","b = logb(1024, 2)","2 ^ b"],seealso:["exp","log10"]},Qt.log10=I,I.doc={name:"log10",category:"Arithmetic",syntax:["log10(x)"],description:"Compute the 10-base logarithm of a value.",examples:["log10(1000)","10 ^ 3","log10(0.01)","log(1000) / log(10)","log(1000, 10)"],seealso:["exp","log"]},Qt.mod=C,C.doc={name:"mod",category:"Operators",syntax:["x % y","x mod y","mod(x, y)"],description:"Calculates the modulus, the remainder of an integer division.",examples:["7 % 3","11 % 2","10 mod 4","function isOdd(x) = x % 2","isOdd(2)","isOdd(3)"],seealso:[]},Qt.multiply=P,P.doc={name:"multiply",category:"Operators",syntax:["x * y","multiply(x, y)"],description:"multiply two values.",examples:["2.1 * 3.6","ans / 3.6","2 * 3 + 4","2 * (3 + 4)","3 * 2.1 km"],seealso:["divide"]},Qt.pow=k,k.doc={name:"pow",category:"Operators",syntax:["x ^ y","pow(x, y)"],description:"Calculates the power of x to y, x^y.",examples:["2^3 = 8","2*2*2","1 + e ^ (pi * i)"],seealso:["unequal","smaller","larger","smallereq","largereq"]},Qt.round=j,j.doc={name:"round",category:"Arithmetic",syntax:["round(x)","round(x, n)"],description:"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.",examples:["round(3.2)","round(3.8)","round(-4.2)","round(-4.8)","round(pi, 3)","round(123.45678, 2)"],seealso:["ceil","floor","fix"]},Qt.sign=D,D.doc={name:"sign",category:"Arithmetic",syntax:["sign(x)"],description:"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.",examples:["sign(3.5)","sign(-4.2)","sign(0)"],seealso:["abs"]},Qt.smaller=F,F.doc={name:"smaller",category:"Operators",syntax:["x < y","smaller(x, y)"],description:"Check if value x is smaller than value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 3","5 < 2*2","a = 3.3","b = 6-2.8","(a < b)","5 cm < 2 inch"],seealso:["equal","unequal","larger","smallereq","largereq"]},Qt.smallereq=H,H.doc={name:"smallereq",category:"Operators",syntax:["x <= y","smallereq(x, y)"],description:"Check if value x is smaller or equal to value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 1+1","2 <= 1+1","a = 3.2","b = 6-2.8","(a < b)"],seealso:["equal","unequal","larger","smaller","largereq"]},Qt.sqrt=Y,Y.doc={name:"sqrt",category:"Arithmetic",syntax:["sqrt(x)"],description:"Compute the square root value. If x = y * y, then y is the square root of x.",examples:["sqrt(25)","5 * 5","sqrt(-1)"],seealso:["square","multiply"]},Qt.square=W,W.doc={name:"square",category:"Arithmetic",syntax:["square(x)"],description:"Compute the square of a value. The square of x is x * x.",examples:["square(3)","sqrt(9)","3^2","3 * 3"],seealso:["multiply","pow","sqrt","cube"]},Qt.subtract=X,X.doc={name:"subtract",category:"Operators",syntax:["x - y","subtract(x, y)"],description:"subtract two values.",examples:["5.3 - 2","ans + 2","2/3 - 1/6","2 * 3 - 3","2.1 km - 500m"],seealso:["add"]},Qt.unaryminus=Z,Z.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},Qt.unequal=K,K.doc={name:"unequal",category:"Operators",syntax:["x != y","unequal(x, y)"],description:"Check unequality of two values. Returns 1 if the values are unequal, and 0 if they are equal.",examples:["2+2 != 3","2+2 != 4","a = 3.2","b = 6-2.8","a != b","50cm != 0.5m","5 cm != 2 inch"],seealso:["equal","smaller","larger","smallereq","largereq"]},Qt.arg=Q,Q.doc={name:"arg",category:"Complex",syntax:["arg(x)"],description:"Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).",examples:["arg(2 + 2i)","atan2(3, 2)","arg(2 - 3i)"],seealso:["re","im","conj","abs"]},Qt.conj=J,J.doc={name:"conj",category:"Complex",syntax:["conj(x)"],description:"Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.",examples:["conj(2 + 3i)","conj(2 - 3i)","conj(-5.2i)"],seealso:["re","im","abs","arg"]},Qt.im=$,$.doc={name:"im",category:"Complex",syntax:["im(x)"],description:"Get the imaginary part of a complex number.",examples:["im(2 + 3i)","re(2 + 3i)","im(-5.2i)","im(2.4)"],seealso:["re","conj","abs","arg"]},Qt.re=et,et.doc={name:"re",category:"Complex",syntax:["re(x)"],description:"Get the real part of a complex number.",examples:["re(2 + 3i)","im(2 + 3i)","re(-5.2i)","re(2.4)"],seealso:["im","conj","abs","arg"]},Qt.complex=tt,Qt.matrix=nt,Qt.parser=rt,Qt.range=at,Qt.unit=it,Qt.workspace=ot,Qt.det=st,st.doc={name:"det",category:"Numerics",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["diag","eye","inv","range","size","squeeze","transpose","zeros"]},Qt.diag=ct,ct.doc={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],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.",examples:["diag(1:4)","diag(1:4, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["det","eye","inv","ones","range","size","squeeze","transpose","zeros"]},Qt.eye=lt,lt.doc={name:"eye",category:"Numerics",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["det","diag","inv","ones","range","size","squeeze","transpose","zeros"]},Qt.inv=ht,ht.doc={name:"inv",category:"Numerics",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["det","diag","eye","ones","range","size","squeeze","transpose","zeros"]},Qt.ones=pt,pt.doc={name:"ones",category:"Numerics",syntax:["ones(n)","ones(m, n)","ones(m, n, p, ...)","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["det","diag","eye","inv","range","size","squeeze","transpose","zeros"]},Qt.size=vt,vt.doc={name:"size",category:"Numerics",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["det","diag","eye","inv","ones","range","squeeze","transpose","zeros"]},Qt.squeeze=dt,dt.doc={name:"squeeze",category:"Numerics",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["det","diag","eye","inv","ones","range","size","transpose","zeros"]},Qt.transpose=yt,yt.doc={name:"transpose",category:"Numerics",syntax:["transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","transpose(a)"],seealso:["det","diag","eye","inv","ones","range","size","squeeze","zeros"]},Qt.zeros=xt,xt.doc={name:"zeros",category:"Numerics",syntax:["zeros(n)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["det","diag","eye","inv","ones","range","size","squeeze","transpose"]},Qt.factorial=wt,wt.doc={name:"factorial",category:"Probability",syntax:["x!","factorial(x)"],description:"Compute the factorial of a value",examples:["5!","5*4*3*2*1","3!"],seealso:[]},Qt.random=Et,Et.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},Qt.max=Nt,Nt.doc={name:"max",category:"Statistics",syntax:["max(a, b, c, ...)"],description:"Compute the maximum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},Qt.min=bt,bt.doc={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},Qt.acos=Ot,Ot.doc={name:"acos",category:"Trigonometry",syntax:["acos(x)"],description:"Compute the inverse cosine of a value in radians.",examples:["acos(0.5)","acos(cos(2.3))"],seealso:["cos","acos","asin"]},Qt.asin=Mt,Mt.doc={name:"asin",category:"Trigonometry",syntax:["asin(x)"],description:"Compute the inverse sine of a value in radians.",examples:["asin(0.5)","asin(sin(2.3))"],seealso:["sin","acos","asin"]},Qt.atan=At,At.doc={name:"atan",category:"Trigonometry",syntax:["atan(x)"],description:"Compute the inverse tangent of a value in radians.",examples:["atan(0.5)","atan(tan(2.3))"],seealso:["tan","acos","asin"]},Qt.atan2=St,St.doc={name:"atan2",category:"Trigonometry",syntax:["atan2(y, x)"],description:"Computes the principal value of the arc tangent of y/x in radians.",examples:["atan2(2, 2) / pi","angle = 60 deg in rad","x = cos(angle)","y = sin(angle)","atan2(y, x)"],seealso:["sin","cos","tan"]},Qt.cos=Tt,Tt.doc={name:"cos",category:"Trigonometry",syntax:["cos(x)"],description:"Compute the cosine of x in radians.",examples:["cos(2)","cos(pi / 4) ^ 2","cos(180 deg)","cos(60 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["acos","sin","tan"]},Qt.cot=zt,zt.doc={name:"cot",category:"Trigonometry",syntax:["cot(x)"],description:"Compute the cotangent of x in radians. Defined as 1/tan(x)",examples:["cot(2)","1 / tan(2)"],seealso:["sec","csc","tan"]},Qt.csc=qt,qt.doc={name:"csc",category:"Trigonometry",syntax:["csc(x)"],description:"Compute the cosecant of x in radians. Defined as 1/sin(x)",examples:["csc(2)","1 / sin(2)"],seealso:["sec","cot","sin"]},Qt.sec=Ut,Ut.doc={name:"sec",category:"Trigonometry",syntax:["sec(x)"],description:"Compute the secant of x in radians. Defined as 1/cos(x)",examples:["sec(2)","1 / cos(2)"],seealso:["cot","csc","cos"]},Qt.sin=Lt,Lt.doc={name:"sin",category:"Trigonometry",syntax:["sin(x)"],description:"Compute the sine of x in radians.",examples:["sin(2)","sin(pi / 4) ^ 2","sin(90 deg)","sin(30 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["asin","cos","tan"]},Qt.tan=Rt,Rt.doc={name:"tan",category:"Trigonometry",syntax:["tan(x)"],description:"Compute the tangent of x in radians.",examples:["tan(0.5)","sin(0.5) / cos(0.5)","tan(pi / 4)","tan(45 deg)"],seealso:["atan","sin","cos"]},Qt.in=_t,_t.doc={name:"in",category:"Units",syntax:["x in unit","in(x, unit)"],description:"Change the unit of a value.",examples:["5 inch in cm","3.2kg in g","16 bytes in bits"],seealso:[]},Qt.clone=It,It.doc={name:"clone",category:"Utils",syntax:["clone(x)"],description:"Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices",examples:["clone(3.5)","clone(2 - 4i)","clone(45 deg)","clone([1, 2; 3, 4])",'clone("hello world")'],seealso:[]},Qt.format=Ct,Ct.doc={name:"format",category:"Utils",syntax:["format(value)"],description:"Format a value of any type as string.",examples:["format(2.3)","format(3 - 4i)","format([])"],seealso:[]},Qt.help=Pt,Pt.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},Qt["import"]=kt,kt.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},Qt["typeof"]=jt,jt.doc={name:"typeof",category:"Utils",syntax:["typeof(x)"],description:"Get the type of a variable.",examples:["typeof(3.5)","typeof(2 - 4i)","typeof(45 deg)",'typeof("hello world")'],seealso:[]},Qt.expr.node.Node=Vt,Vt.prototype.eval=function(){throw Error("Cannot evaluate a Node interface") -},Vt.prototype.toString=function(){return""},Dt.prototype=new Vt,Qt.expr.node.Symbol=Dt,Dt.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},Dt.prototype.eval=function(){var e=this.fn;if(void 0===e)throw Error("Undefined symbol "+this.name);var t=this.params.map(function(e){return e.eval()});return e.apply(this,t)},Dt.prototype.toString=function(){if(this.name&&!this.params)return this.name;var e=this.name;return this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e},Ft.prototype=new Vt,Qt.expr.node.Constant=Ft,Ft.prototype.eval=function(){return this.value},Ft.prototype.toString=function(){return this.value?Qt.format(this.value):""},Ht.prototype=new Vt,Qt.expr.node.MatrixNode=Ht,function(){function e(t){return t.map(function(t){return t instanceof Array?e(t):t.eval()})}function t(e){if(e instanceof Array){for(var n="[",r=e.length,a=0;r>a;a++)0!=a&&(n+=", "),n+=t(e[a]);return n+="]"}return""+e}Ht.prototype.eval=function(){return new n(e(this.nodes))},Ht.prototype.toString=function(){return t(this.nodes)}}(),Yt.prototype=new Vt,Qt.expr.node.Block=Yt,Yt.prototype.add=function(e,t){var n=this.params.length;this.params[n]=e,this.visible[n]=void 0!=t?t:!0},Yt.prototype.eval=function(){for(var e=[],t=0,n=this.params.length;n>t;t++){var r=this.params[t].eval();this.visible[t]&&e.push(r)}return e},Yt.prototype.toString=function(){for(var e=[],t=0,n=this.params.length;n>t;t++)this.visible[t]&&e.push("\n "+(""+this.params[t]));return"["+e.join(",")+"\n]"},Wt.prototype=new Vt,Qt.expr.node.Assignment=Wt,Wt.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,t=this.params;if(t&&t.length){var n=[];this.params.forEach(function(e){n.push(e.eval())});var r=this.expr.eval();if(void 0==this.result.value)throw Error("Undefined symbol "+this.name);var a=this.result();if(!a.set)throw new TypeError("Cannot apply a subset to object of type "+Qt.typeof(a));e=a.set(n,r),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},Wt.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},Xt.prototype=new Vt,Qt.expr.node.Arguments=Xt,Xt.prototype.eval=function(){var e=this.object;if(void 0==e)throw Error("Node undefined");for(var t=e.eval(),n=this.params,r=[],a=0,i=n.length;i>a;a++)r[a]=n[a].eval();if(!t.get)throw new TypeError("Cannot apply arguments to object of type "+Qt.typeof(t));return t.get(r)},Xt.prototype.toString=function(){var e=this.object?""+this.object:"";return this.params&&(e+="("+this.params.join(", ")+")"),e},Zt.prototype=new Vt,Qt.expr.node.FunctionAssignment=Zt,Zt.prototype.createFunction=function(e,t,n,r){var a=function(){var t=n?n.length:0,a=arguments?arguments.length:0;if(t!=a)throw E(e,a,t);if(t>0)for(var i=0;t>i;i++)n[i].value=arguments[i];return r.eval()};return a.toString=function(){return e+"("+t.join(", ")+")"},a},Zt.prototype.eval=function(){for(var e=this.variables,t=this.values,n=0,r=e.length;r>n;n++)e[n].value=t[n];return this.result.value=this.def,this.def},Zt.prototype.toString=function(){return""+this.def},function(){function e(e){this.parentScope=e,this.nestedScopes=void 0,this.symbols={},this.defs={},this.updates={},this.links={}}Qt.expr.Scope=e,e.prototype.createNestedScope=function(){var t=new e(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(t),t},e.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,t=0,n=e.length;n>t;t++)e[t].clear()},e.prototype.createSymbol=function(e){var t=this.symbols[e];if(!t){var n=this.findDef(e);t=this.newSymbol(e,n),this.symbols[e]=t}return t},e.prototype.newSymbol=function(e,t){var r=this,a=function(){var t,i;if(!a.value&&(a.value=r.findDef(e),!a.value))throw Error("Undefined symbol "+e);if("function"==typeof a.value)return a.value.apply(null,arguments);if(a.value instanceof n||a.value instanceof g||a.value instanceof Array){if(arguments.length){var o=a.value instanceof Array?new n(a.value):a.value;for(t=[],i=0;arguments.length>i;i++)t[i]=arguments[i];return o.get(t)}return a.value}return a.value};return a.value=t,a.toString=function(){return a.value?""+a.value:""},a},e.prototype.createLink=function(e){var t=this.links[e];return t||(t=this.createSymbol(e),this.links[e]=t),t},e.prototype.createDef=function(e,t){var n=this.defs[e];return n||(n=this.createSymbol(e),this.defs[e]=n),n&&void 0!=t&&(n.value=t),n},e.prototype.createUpdate=function(e){var t=this.updates[e];return t||(t=this.createLink(e),this.updates[e]=t),t},e.prototype.findDef=function(e){function n(e,t){var n=a(e,t);return i[e]=n,o[e]=n,n}var r;if(r=this.defs[e])return r;if(r=this.updates[e])return r;if(this.parentScope)return this.parentScope.findDef(e);var a=this.newSymbol,i=this.symbols,o=this.defs;if("pi"==e)return n(e,Qt.PI);if("e"==e)return n(e,Qt.E);if("i"==e)return n(e,new t(0,1));var s=Qt[e];if(s)return n(e,s);if(x.isUnit(e)){var f=new x(null,e);return n(e,f)}return void 0},e.prototype.removeLink=function(e){delete this.links[e]},e.prototype.removeDef=function(e){delete this.defs[e]},e.prototype.removeUpdate=function(e){delete this.updates[e]},e.prototype.init=function(){var e=this.symbols,t=this.parentScope;for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];r.value=t?t.findDef(n):void 0}this.nestedScopes&&this.nestedScopes.forEach(function(e){e.init()})},e.prototype.hasLink=function(e){if(this.links[e])return!0;if(this.nestedScopes)for(var t=this.nestedScopes,n=0,r=t.length;r>n;n++)if(t[n].hasLink(e))return!0;return!1},e.prototype.hasDef=function(e){return void 0!=this.defs[e]},e.prototype.hasUpdate=function(e){return void 0!=this.updates[e]},e.prototype.getUndefinedSymbols=function(){var e=this.symbols,t=[];for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];void 0==r.value&&t.push(r)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){t=t.concat(e.getUndefinedSymbols())}),t}}(),function(){function e(){B++,G=P.charAt(B)}function n(){B=0,G=P.charAt(0)}function r(){for(V=C.NULL,j="";" "==G||" "==G;)e();if("#"==G)for(;"\n"!=G&&""!=G;)e();if(""==G)return V=C.DELIMITER,void 0;if("-"==G||","==G||"("==G||")"==G||"["==G||"]"==G||'"'==G||"\n"==G||";"==G||":"==G)return V=C.DELIMITER,j+=G,e(),void 0;if(a(G))for(V=C.DELIMITER;a(G);)j+=G,e();else if(o(G)){for(V=C.NUMBER;o(G);)j+=G,e();if("E"==G||"e"==G)for(j+=G,e(),("+"==G||"-"==G)&&(j+=G,e()),s(G)||(V=C.UNKNOWN);s(G);)j+=G,e()}else{if(!i(G)){for(V=C.UNKNOWN;""!=G;)j+=G,e();throw L('Syntax error in part "'+j+'"')}for(V=C.SYMBOL;i(G)||s(G);)j+=G,e()}}function a(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==e||"!"==e}function i(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e}function o(e){return e>="0"&&"9">=e||"."==e}function s(e){return e>="0"&&"9">=e}function f(e){n(),r();var t;if(t=""==j?new Ft(void 0):c(e),""!=j)throw V==C.DELIMITER?_("Unknown operator "+j):L('Unexpected part "'+j+'"');return t}function u(e){var t=l(e);if(!(t instanceof Wt)){var n="ans",r=void 0,a=e.createDef(n);return new Wt(n,r,t,a)}return t}function c(e){var t,n,a;for("\n"!=j&&";"!=j&&""!=j&&(t=u(e));"\n"==j||";"==j;)n||(n=new Yt,t&&(a=";"!=j,n.add(t,a))),r(),"\n"!=j&&";"!=j&&""!=j&&(t=u(e),a=";"!=j,n.add(t,a));return n?n:(t||(t=u(e)),t)}function l(e){if(V==C.SYMBOL&&"function"==j){if(r(),V!=C.SYMBOL)throw L("Function name expected");var t=j;if(r(),"("!=j)throw L("Opening parenthesis ( expected");for(var n=e.createNestedScope(),a=[],i=[];;){if(r(),V!=C.SYMBOL)throw L("Variable name expected");var o=j,s=n.createDef(o);if(a.push(o),i.push(s),r(),","!=j){if(")"==j)break;throw L('Comma , or closing parenthesis ) expected"')}}if(r(),"="!=j)throw L("Equal sign = expected");r();var f=m(n),u=e.createDef(t);return new Zt(t,a,i,f,u)}return h(e)}function h(e){var t=!1;V==C.SYMBOL&&(t=e.hasLink(j));var n=m(e);if("="==j){if(!(n instanceof Dt))throw L("Symbol expected at the left hand side of assignment operator =");var a=n.name,i=n.params;t||e.removeLink(a),r();var o=m(e),s=n.hasParams()?e.createUpdate(a):e.createDef(a);return new Wt(a,i,o,s)}return n}function m(e){var t=p(e);if(":"==j){for(var n=[t];":"==j;)r(),n.push(p(e));if(n.length>3)throw new TypeError("Invalid range");var a="range",i=at;t=new Dt(a,i,n)}return t}function p(e){for(var t=v(e),n={"in":"in"};void 0!==n[j];){var a=j,i=Qt[n[a]];r();var o=[t,v(e)];t=new Dt(a,i,o)}return t}function v(e){var t=d(e);return t}function d(e){for(var t=g(e),n={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==n[j];){var a=j,i=Qt[n[a]];r();var o=[t,g(e)];t=new Dt(a,i,o)}return t}function g(e){for(var t=y(e),n={"+":"add","-":"subtract"};void 0!==n[j];){var a=j,i=Qt[n[a]];r();var o=[t,y(e)];t=new Dt(a,i,o)}return t}function y(e){for(var t=w(e),n={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==n[j];){var a=j,i=Qt[n[a]];r();var o=[t,w(e)];t=new Dt(a,i,o)}return t}function w(e){if("-"==j){var t=j,n=Z;r();var a=[E(e)];return new Dt(t,n,a)}return E(e)}function E(e){for(var t=[N(e)];"^"==j;)r(),t.push(N(e));for(var n=t.pop();t.length;){var a=t.pop(),i="^",o=k,s=[a,n];n=new Dt(i,o,s)}return n}function N(e){for(var t=b(e);"!"==j;){var n=j,a=wt;r();var i=[t];t=new Dt(n,a,i)}return t}function b(e){return O(e)}function O(e){if(V==C.SYMBOL){var t=j;r();var n=e.createLink(t),a=M(e),i=new Dt(t,n,a);return i}return A(e)}function M(e){var t=[];if("("==j){if(r(),")"!=j)for(t.push(m(e));","==j;)r(),t.push(m(e));if(")"!=j)throw L("Parenthesis ) missing");r()}return t}function A(t){if('"'==j){for(var n="",a="";""!=G&&('"'!=G||"\\"==a);)n+=G,a=G,e();if(r(),'"'!=j)throw L('End of string " missing');r();var i=new Ft(n);return i}return S(t)}function S(e){if("["==j){var t;for(r();"\n"==j;)r();if("]"!=j){var n=[],a=0,i=0;for(n[0]=[m(e)];","==j||";"==j;){for(","==j?i++:(a++,i=0,n[a]=[]),r();"\n"==j;)r();for(n[a][i]=m(e);"\n"==j;)r()}var o=n.length,s=n.length>0?n[0].length:0;for(a=1;o>a;a++)if(n[a].length!=s)throw _("Number of columns must match ("+n[a].length+" != "+s+")");if("]"!=j)throw L("End of matrix ] missing");r(),t=new Ht(n)}else r(),t=new Ht([]);return t}return T(e)}function T(e){if(V==C.NUMBER){var n;n="."==j?0:Number(j),r();var a;if(V==C.SYMBOL){if("i"==j||"I"==j)return a=new t(0,n),r(),new Ft(a);if(x.isUnit(j))return a=new x(n,j),r(),new Ft(a);throw R('Unknown unit "'+j+'"')}var i=new Ft(n);return i}return z(e)}function z(e){if("("==j){r();var t=m(e);if(")"!=j)throw L("Parenthesis ) expected");return r(),t}return q(e)}function q(){throw""==j?L("Unexpected end of expression"):L("Value expected")}function U(e){var t=t(),n=n();return void 0===t?void 0===n?e:e+" (col "+n+")":e+" (ln "+t+", col "+n+")"}function L(e){return new SyntaxError(U(e))}function R(e){return new TypeError(U(e))}function _(e){return Error(U(e))}Qt.expr.Parser=function I(){if(this.constructor!=I)throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new Qt.expr.Scope},Qt.expr.Parser.prototype.parse=function(e,t){return P=e||"",t||(this._newScope(),t=this.scope),f(t)},Qt.expr.Parser.prototype.eval=function(e){var t=this.parse(e);return t.eval()},Qt.expr.Parser.prototype.get=function(e){this._newScope();var t=this.scope.findDef(e);return t?t.value:void 0},Qt.expr.Parser.prototype.set=function(e,t){this.scope.createDef(e,t)},Qt.expr.Parser.prototype._newScope=function(){this.scope=new Qt.expr.Scope(this.scope)},Qt.expr.Parser.prototype.clear=function(){this.scope.clear()};var C={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},P="",B=0,G="",j="",V=C.NULL}(),function(){function e(){this.idMax=-1,this.updateSeq=0,this.parser=new Qt.expr.Parser,this.scope=new Qt.expr.Scope,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}Qt.expr.Workspace=e,e.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},e.prototype.append=function(t){var n=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,a=new Qt.expr.Scope(r),i=new e.Node({id:n,expression:t,parser:this.parser,scope:a,nextNode:void 0,previousNode:this.lastNode});return this.nodes[n]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([n]),n},e.prototype.insertBefore=function(t,n){var r=this.nodes[n];if(!r)throw'Node with id "'+n+'" not found';var a=r.previousNode,i=this._getNewId(),o=a?a.scope:this.scope,s=new Qt.expr.Scope(o),f=new e.Node({id:i,expression:t,parser:this.parser,scope:s,nextNode:r,previousNode:a});this.nodes[i]=f,a?a.nextNode=f:this.firstNode=f,r.previousNode=f,r.scope.parentScope=f.scope;var u=this.getDependencies(i);return-1==u.indexOf(i)&&u.unshift(i),this._update(u),i},e.prototype.insertAfter=function(e,t){var n=this.nodes[t];if(!n)throw'Node with id "'+t+'" not found';return n==this.lastNode?this.append(e):this.insertBefore(t+1,e)},e.prototype.remove=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';var n=this.getDependencies(e),r=t.previousNode,a=t.nextNode;r?r.nextNode=a:this.firstNode=a,a?a.previousNode=r:this.lastNode=r;var i=r?r.scope:this.scope;a&&(a.scope.parentScope=i),delete this.nodes[e],this._update(n)},e.prototype.replace=function(t,n){var r=this.nodes[n];if(!r)throw'Node with id "'+n+'" not found';var a=[n];e._merge(a,this.getDependencies(n));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(t),e._merge(a,this.getDependencies(n)),this._update(a)},e.Node=function(e){this.id=e.id,this.parser=e.parser,this.scope=e.scope,this.nextNode=e.nextNode,this.previousNode=e.previousNode,this.updateSeq=0,this.result=void 0,this.setExpr(e.expression)},e.Node.prototype.setExpr=function(e){this.expression=e||"",this.scope.clear(),this._parse()},e.Node.prototype.getExpr=function(){return this.expression},e.Node.prototype.getResult=function(){return this.result},e.Node.prototype._parse=function(){try{this.fn=this.parser.parse(this.expression,this.scope)}catch(e){var t="Error: "+((e.message||e)+"");this.fn=new Ft(t)}},e.Node.prototype.eval=function(){try{this.scope.init(),this.result=this.fn.eval()}catch(e){this.scope.init(),this.result="Error: "+((e.message||e)+"")}return this.result},e._merge=function(e,t){for(var n=0,r=t.length;r>n;n++){var a=t[n];-1==e.indexOf(a)&&e.push(a)}},e.prototype.getDependencies=function(t){var n,r=[],a=this.nodes[t];if(a){var i=a.scope.defs,o=a.scope.updates,s=[];for(n in i)i.hasOwnProperty(n)&&s.push(n);for(n in o)o.hasOwnProperty(n)&&-1==s.indexOf(n)&&s.push(n);for(var f=a.nextNode;f&&s.length;){for(var u=f.scope,c=0;s.length>c;){if(n=s[c],(u.hasLink(n)||u.hasUpdate(n))&&-1==r.indexOf(f.id)){r.push(f.id);var l=this.getDependencies(f.id);e._merge(r,l)}u.hasDef(n)&&(s.splice(c,1),c--),c++}f=f.nextNode}}return r},e.prototype.getExpr=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getExpr()},e.prototype.getResult=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getResult()},e.prototype._update=function(e){this.updateSeq++;for(var t=this.updateSeq,n=this.nodes,r=0,a=e.length;a>r;r++){var i=e[r],o=n[i];o&&(o.eval(),o.updateSeq=t)}},e.prototype.getChanges=function(e){var t=[],n=this.firstNode;for(e=e||0;n;)n.updateSeq>e&&t.push(n.id),n=n.nextNode;return{ids:t,updateSeq:this.updateSeq}},e.prototype._getNewId=function(){return this.idMax++,this.idMax},e.prototype.toString=function(){return JSON.stringify(this.toJSON())},e.prototype.toJSON=function(){for(var e=[],t=this.firstNode;t;){var n={id:t.id,expression:t.expression,dependencies:this.getDependencies(t.id)};try{n.result=t.getResult()}catch(r){n.result="Error: "+((r.message||r)+"")}e.push(n),t=t.nextNode}return e}}(),Qt.Complex=function(){Kt("new math.Complex()","math.complex()")},Qt.Unit=function(){Kt("new math.Unit()","math.unit()")},Qt.parser.Parser=function(){Kt("new math.parser.Parser()","math.parser()")},Qt.parser.Workspace=function(){Kt("new math.parser.Workspace()","math.workspace()")}})(); \ No newline at end of file +(function(){function e(e){return e instanceof Boolean||"boolean"==typeof e}function n(e,t){if(this.constructor!=n)throw new SyntaxError("Complex constructor must be called with the new operator");if(null!=e&&!v(e)||null!=t&&!v(t))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=e||0,this.im=t||0}function t(e){if(this.constructor!=t)throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof t||e instanceof g)this._data=e.toArray();else if(e instanceof Array)this._data=e;else{if(null!=e)throw new TypeError("Unsupported type of data ("+tt.typeof(e)+")");this._data=[]}this._size=rt.size(this._data)}function r(e,n){if(!v(e)||!d(e))throw new TypeError("Index must be an integer (value: "+e+")");if(1>e)throw new RangeError("Index out of range ("+e+" < 1)");if(n&&e>n)throw new RangeError("Index out of range ("+e+" > "+n+")")}function a(e,n){return r(n,e.length),e[n-1]}function i(e,n){return n.forEach(function(n){e=a(e,n)}),Gn(e)}function o(e,n){var t=n[0];return t.map?t.map(function(n){return a(e,n)}):[a(e,t)]}function s(e,n){var t=n[0],r=n[1];if(t.map)return r.map?t.map(function(n){var t=a(e,n);return r.map(function(e){return a(t,e)})}):t.map(function(n){return[a(a(e,n),r)]});if(r.map){var i=a(e,t);return[r.map(function(e){return a(i,e)})]}return[[a(a(e,t),r)]]}function f(e,n,t){var r=t==n.length-1,i=n[t],o=function(i){var o=a(e,i);return r?o:f(o,n,t+1)};return i.map?i.map(o):[o(i)]}function u(e,n,t){if(r(n),t instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[n-1]=t}function c(e,n,t,a){var i=!1;t.length>n.length&&(i=!0);for(var o=0;t.length>o;o++){var s=t[o];r(s),(null==n[o]||s>n[o])&&(n[o]=s,i=!0)}i&&rt.resize(e,n,0);var f=n.length;t.forEach(function(n,t){f-1>t?e=e[n-1]:e[n-1]=a})}function l(e,n,t,a){var i=t[0];r(i),i>n[0]&&rt.resize(e,[i],0),e[i-1]=a}function h(e,n,t,a){var i=t[0],o=t[1];r(i),r(o);var s=!1;i>(n[0]||0)&&(n[0]=i,s=!0),o>(n[1]||0)&&(n[1]=o,s=!0),s&&rt.resize(e,n,0),e[i-1][o-1]=a}function m(e,n,t,r,a){var i=r==t.length-1,o=t[r],s=function(o,s){if(i)u(e,o,a[s]),e.length>(n[r]||0)&&(n[r]=e.length);else{var f=e[o-1];f instanceof Array||(e[o-1]=f=[f],e.length>(n[r]||0)&&(n[r]=e.length)),m(f,n,t,r+1,a[s])}};if(o.map){var f=o.size&&o.size()||o.length;if(f!=a.length)throw new RangeError("Dimensions mismatch ("+f+" != "+a.length+")");o.map(s)}else s(o,0)}function p(e){for(var n=0,t=e.length;t>n;n++){var r=e[n];r instanceof Array?p(r):void 0==r&&(e[n]=0)}}function v(e){return e instanceof Number||"number"==typeof e}function d(e){return e==Math.round(e)}function g(e,n,t){if(this.constructor!=g)throw new SyntaxError("Range constructor must be called with the new operator");if(null!=e&&!v(e))throw new TypeError("Parameter start must be a number");if(null!=t&&!v(t))throw new TypeError("Parameter end must be a number");if(null!=n&&!v(n))throw new TypeError("Parameter step must be a number");this.start=null!=e?e:0,this.end=null!=t?t:0,this.step=null!=n?n:1}function y(e){return e instanceof String||"string"==typeof e}function x(e,n){if(this.constructor!=x)throw Error("Unit constructor must be called with the new operator");if(null!=e&&!v(e))throw Error("First parameter in Unit constructor must be a number");if(null!=n&&!y(n))throw Error("Second parameter in Unit constructor must be a string");if(this.value=1,this.unit=x.UNIT_NONE,this.prefix=x.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1,null!=n){for(var t=x.UNITS,r=!1,a=0,i=t.length;i>a;a++){var o=t[a];if(x.endsWith(n,o.name)){var s=n.length-o.name.length,f=n.substring(0,s),u=o.prefixes[f];if(void 0!==u){this.unit=o,this.prefix=u,this.hasUnit=!0,r=!0;break}}}if(!r)throw Error('String "'+n+'" is no unit')}null!=e?(this.value=this._normalize(e),this.hasValue=!0):this.value=this._normalize(1)}function w(e,n){var t=void 0;if(2==arguments.length){var r=Yn(n);t="Function "+e+" does not support a parameter of type "+r}else if(arguments.length>2){for(var a=[],i=1;arguments.length>i;i++)a.push(Yn(arguments[i]));t="Function "+e+" does not support a parameters of type "+a.join(", ")}else t="Unsupported parameter in function "+e;return new TypeError(t)}function E(e,n,t,r){var a="Wrong number of arguments in function "+e+" ("+n+" provided, "+t+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(a)}function N(e){if(1!=arguments.length)throw E("abs",arguments.length,1);if(v(e))return Math.abs(e);if(e instanceof n)return Math.sqrt(e.re*e.re+e.im*e.im);if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,N);if(e.valueOf()!==e)return N(e.valueOf());throw w("abs",e)}function b(e,r){if(2!=arguments.length)throw E("add",arguments.length,2);if(v(e)){if(v(r))return e+r;if(r instanceof n)return new n(e+r.re,r.im)}else if(e instanceof n){if(v(r))return new n(e.re+r,e.im);if(r instanceof n)return new n(e.re+r.re,e.im+r.im)}else if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Units do not match");if(!e.hasValue)throw Error("Unit on left hand side of operator + has no value");if(!r.hasValue)throw Error("Unit on right hand side of operator + has no value");var a=e.clone();return a.value+=r.value,a.fixPrefix=!1,a}if(y(e)||y(r))return e+r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,b);if(e.valueOf()!==e)return b(e.valueOf(),r.valueOf());throw w("add",e,r)}function O(e){if(1!=arguments.length)throw E("ceil",arguments.length,1);if(v(e))return Math.ceil(e);if(e instanceof n)return new n(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,O);if(e.valueOf()!==e)return O(e.valueOf());throw w("ceil",e)}function M(e){if(1!=arguments.length)throw E("cube",arguments.length,1);if(v(e))return e*e*e;if(e instanceof n)return P(P(e,e),e);if(e instanceof Array||e instanceof t||e instanceof g)return P(P(e,e),e);if(e.valueOf()!==e)return M(e.valueOf());throw w("cube",e)}function A(e,r){if(2!=arguments.length)throw E("divide",arguments.length,2);if(v(e)){if(v(r))return e/r;if(r instanceof n)return S(new n(e,0),r)}if(e instanceof n){if(v(r))return S(e,new n(r,0));if(r instanceof n)return S(e,r)}if(e instanceof x&&v(r)){var a=e.clone();return a.value/=r,a}if(e instanceof Array||e instanceof t)return r instanceof Array||r instanceof t?tt.multiply(e,tt.inv(r)):rt.map2(e,r,A);if(r instanceof Array||r instanceof t)return tt.multiply(e,tt.inv(r));if(e.valueOf()!==e||r.valueOf()!==r)return A(e.valueOf(),r.valueOf());throw w("divide",e,r)}function S(e,t){var r=t.re*t.re+t.im*t.im;return new n((e.re*t.re+e.im*t.im)/r,(e.im*t.re-e.re*t.im)/r)}function T(e,r){if(2!=arguments.length)throw E("equal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof n)return e==r.re&&0==r.im}if(e instanceof n){if(v(r))return e.re==r&&0==e.im;if(r instanceof n)return e.re==r.re&&e.im==r.im}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value==r.value}if(y(e)||y(r))return e==r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,T);if(e.valueOf()!==e||r.valueOf()!==r)return T(e.valueOf(),r.valueOf());throw w("equal",e,r)}function z(e){if(1!=arguments.length)throw E("exp",arguments.length,1);if(v(e))return Math.exp(e);if(e instanceof n){var r=Math.exp(e.re);return new n(r*Math.cos(e.im),r*Math.sin(e.im))}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,z);if(e.valueOf()!==e)return z(e.valueOf());throw w("exp",e)}function q(e){if(1!=arguments.length)throw E("fix",arguments.length,1);if(v(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof n)return new n(e.re>0?Math.floor(e.re):Math.ceil(e.re),e.im>0?Math.floor(e.im):Math.ceil(e.im));if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,q);if(e.valueOf()!==e)return q(e.valueOf());throw w("fix",e)}function U(e){if(1!=arguments.length)throw E("floor",arguments.length,1);if(v(e))return Math.floor(e);if(e instanceof n)return new n(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,U);if(e.valueOf()!==e)return U(e.valueOf());throw w("floor",e)}function R(e,r){if(2!=arguments.length)throw E("larger",arguments.length,2);if(v(e)){if(v(r))return e>r;if(r instanceof n)return e>N(r)}if(e instanceof n){if(v(r))return N(e)>r;if(r instanceof n)return N(e)>N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value>r.value}if(y(e)||y(r))return e>r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,R);if(e.valueOf()!==e||r.valueOf()!==r)return R(e.valueOf(),r.valueOf());throw w("larger",e,r)}function L(e,r){if(2!=arguments.length)throw E("largereq",arguments.length,2);if(v(e)){if(v(r))return e>=r;if(r instanceof n)return e>=N(r)}if(e instanceof n){if(v(r))return N(e)>=r;if(r instanceof n)return N(e)>=N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value>=r.value}if(y(e)||y(r))return e>=r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,L);if(e.valueOf()!==e||r.valueOf()!==r)return L(e.valueOf(),r.valueOf());throw w("largereq",e,r)}function C(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("log",arguments.length,1,2);if(void 0!==r)return A(C(e),C(r));if(v(e))return e>=0?Math.log(e):C(new n(e,0));if(e instanceof n)return new n(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,C);if(e.valueOf()!==e||r.valueOf()!==r)return C(e.valueOf(),r.valueOf());throw w("log",e,r)}function _(e){if(1!=arguments.length)throw E("log10",arguments.length,1);if(v(e))return e>=0?Math.log(e)/Math.LN10:_(new n(e,0));if(e instanceof n)return new n(Math.log(Math.sqrt(e.re*e.re+e.im*e.im))/Math.LN10,Math.atan2(e.im,e.re)/Math.LN10);if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,_);if(e.valueOf()!==e)return _(e.valueOf());throw w("log10",e)}function I(e,r){if(2!=arguments.length)throw E("mod",arguments.length,2);if(v(e)){if(v(r))return e%r;if(r instanceof n&&0==r.im)return e%r.re}else if(e instanceof n&&0==e.im){if(v(r))return e.re%r;if(r instanceof n&&0==r.im)return e.re%r.re}if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,I);if(e.valueOf()!==e||r.valueOf()!==r)return I(e.valueOf(),r.valueOf());throw w("mod",e,r)}function P(e,r){if(2!=arguments.length)throw E("multiply",arguments.length,2);if(v(e)){if(v(r))return e*r;if(r instanceof n)return B(new n(e,0),r);if(r instanceof x)return o=r.clone(),o.value*=e,o}else if(e instanceof n){if(v(r))return B(e,new n(r,0));if(r instanceof n)return B(e,r)}else if(e instanceof x){if(v(r))return o=e.clone(),o.value*=r,o}else{if(e instanceof Array){if(r instanceof Array){var a=rt.size(e),i=rt.size(r);if(2!=a.length)throw Error("Can only multiply a 2 dimensional matrix (A has "+a.length+" dimensions)");if(2!=i.length)throw Error("Can only multiply a 2 dimensional matrix (B has "+i.length+" dimensions)");if(a[1]!=i[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+a[0]+"x"+a[1]+", B is "+i[0]+"x"+i[1]+", "+i[1]+" != "+i[0]+")");for(var o=[],s=a[0],f=i[1],u=a[1],c=0;s>c;c++){o[c]=[];for(var l=0;f>l;l++){for(var h=null,m=0;u>m;m++){var p=P(e[c][m],r[m][l]);h=null==h?p:b(h,p)}o[c][l]=h}}return o}return r instanceof t?new t(P(e.valueOf(),r.valueOf())):rt.map2(e,r,P)}if(e instanceof t)return new t(P(e.valueOf(),r.valueOf()))}if(r instanceof Array)return rt.map2(e,r,P);if(r instanceof t)return new t(P(e.valueOf(),r.valueOf()));if(e.valueOf()!==e||r.valueOf()!==r)return P(e.valueOf(),r.valueOf());throw w("multiply",e,r)}function B(e,t){return new n(e.re*t.re-e.im*t.im,e.re*t.im+e.im*t.re)}function k(e,r){if(2!=arguments.length)throw E("pow",arguments.length,2);if(v(e)){if(v(r))return d(r)||e>=0?Math.pow(e,r):G(new n(e,0),new n(r,0));if(r instanceof n)return G(new n(e,0),r)}else if(e instanceof n){if(v(r))return G(e,new n(r,0));if(r instanceof n)return G(e,r)}else{if(e instanceof Array){if(!v(r)||!d(r)||0>r)throw new TypeError("For A^b, b must be a positive integer (value is "+r+")");var a=rt.size(e);if(2!=a.length)throw Error("For A^b, A must be 2 dimensional (A has "+a.length+" dimensions)");if(a[0]!=a[1])throw Error("For A^b, A must be square (size is "+a[0]+"x"+a[1]+")");if(0==r)return identity(a[0]);for(var i=e,o=1;r>o;o++)i=P(e,i);return i}if(e instanceof t)return new t(k(e.valueOf(),r))}if(e.valueOf()!==e||r.valueOf()!==r)return k(e.valueOf(),r.valueOf());throw w("pow",e,r)}function G(e,n){var t=C(e),r=P(t,n);return z(r)}function j(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("round",arguments.length,1,2);if(void 0==r){if(v(e))return Math.round(e);if(e instanceof n)return new n(Math.round(e.re),Math.round(e.im));if((e instanceof Array||e instanceof t||e instanceof g)&&rt.map(e,j),e.valueOf()!==e)return j(e.valueOf());throw w("round",e)}if(!v(r))throw new TypeError("Number of digits in function round must be an integer");if(r!==Math.round(r))throw new TypeError("Number of digits in function round must be integer");if(0>r||r>9)throw Error("Number of digits in function round must be in te range of 0-9");if(v(e))return V(e,r);if(e instanceof n)return new n(V(e.re,r),V(e.im,r));if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,j);if(e.valueOf()!==e||r.valueOf()!==r)return R(e.valueOf(),r.valueOf());throw w("round",e,r)}function V(e,n){var t=Math.pow(10,void 0!=n?n:tt.options.precision);return Math.round(e*t)/t}function D(e){if(1!=arguments.length)throw E("sign",arguments.length,1);if(v(e)){var r;return r=e>0?1:0>e?-1:0}if(e instanceof n){var a=Math.sqrt(e.re*e.re+e.im*e.im);return new n(e.re/a,e.im/a)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,r);if(e.valueOf()!==e)return r(e.valueOf());throw w("sign",e)}function F(e,r){if(2!=arguments.length)throw E("smaller",arguments.length,2);if(v(e)){if(v(r))return r>e;if(r instanceof n)return N(r)>e}if(e instanceof n){if(v(r))return r>N(e);if(r instanceof n)return N(e)e;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,F);if(e.valueOf()!==e||r.valueOf()!==r)return F(e.valueOf(),r.valueOf());throw w("smaller",e,r)}function H(e,r){if(2!=arguments.length)throw E("smallereq",arguments.length,2);if(v(e)){if(v(r))return r>=e;if(r instanceof n)return N(r)>=e}if(e instanceof n){if(v(r))return r>=N(e);if(r instanceof n)return N(e)<=N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value<=r.value}if(y(e)||y(r))return r>=e;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,H);if(e.valueOf()!==e||r.valueOf()!==r)return H(e.valueOf(),r.valueOf());throw w("smallereq",e,r)}function Y(e){if(1!=arguments.length)throw E("sqrt",arguments.length,1);if(v(e))return e>=0?Math.sqrt(e):Y(new n(e,0));if(e instanceof n){var r=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new n(.5*Math.sqrt(2*(r+e.re)),.5*Math.sqrt(2*(r-e.re))):new n(.5*Math.sqrt(2*(r+e.re)),-.5*Math.sqrt(2*(r-e.re)))}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Y);if(e.valueOf()!==e)return Y(e.valueOf());throw w("sqrt",e)}function W(e){if(1!=arguments.length)throw E("square",arguments.length,1);if(v(e))return e*e;if(e instanceof n)return P(e,e);if(e instanceof Array||e instanceof t||e instanceof g)return P(e,e);if(e.valueOf()!==e)return W(e.valueOf());throw w("square",e)}function X(e,r){if(2!=arguments.length)throw E("subtract",arguments.length,2);if(v(e)){if(v(r))return e-r;if(r instanceof n)return new n(e-r.re,r.im)}else if(e instanceof n){if(v(r))return new n(e.re-r,e.im);if(r instanceof n)return new n(e.re-r.re,e.im-r.im)}else if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Units do not match");if(!e.hasValue)throw Error("Unit on left hand side of operator - has no value");if(!r.hasValue)throw Error("Unit on right hand side of operator - has no value");var a=e.clone();return a.value-=r.value,a.fixPrefix=!1,a}if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,X);if(e.valueOf()!==e||r.valueOf()!==r)return X(e.valueOf(),r.valueOf());throw w("subtract",e,r)}function Z(e){if(1!=arguments.length)throw E("unaryminus",arguments.length,1);if(v(e))return-e;if(e instanceof n)return new n(-e.re,-e.im);if(e instanceof x){var r=e.clone();return r.value=-e.value,r}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Z);if(e.valueOf()!==e)return Z(e.valueOf());throw w("unaryminus",e)}function K(e,r){if(2!=arguments.length)throw E("unequal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof n)return e==r.re&&0==r.im}if(e instanceof n){if(v(r))return e.re==r&&0==e.im;if(r instanceof n)return e.re==r.re&&e.im==r.im}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value==r.value}if(y(e)||y(r))return e==r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,K);if(e.valueOf()!==e||r.valueOf()!==r)return K(e.valueOf(),r.valueOf());throw w("unequal",e,r)}function Q(e){if(1!=arguments.length)throw E("arg",arguments.length,1);if(v(e))return Math.atan2(0,e);if(e instanceof n)return Math.atan2(e.im,e.re);if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Q);if(e.valueOf()!==e)return Q(e.valueOf());throw w("arg",e)}function J(e){if(1!=arguments.length)throw E("conj",arguments.length,1);if(v(e))return e;if(e instanceof n)return new n(e.re,-e.im);if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,J);if(e.valueOf()!==e)return J(e.valueOf());throw w("conj",e)}function $(e){if(1!=arguments.length)throw E("im",arguments.length,1);if(v(e))return 0;if(e instanceof n)return e.im;if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,$);if(e.valueOf()!==e)return $(e.valueOf());throw w("im",e)}function en(e){if(1!=arguments.length)throw E("re",arguments.length,1);if(v(e))return e;if(e instanceof n)return e.re;if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,en);if(e.valueOf()!==e)return en(e.valueOf());throw w("re",e)}function nn(){switch(arguments.length){case 0:return new n(0,0);case 1:var e=arguments[0];if(!y(e))throw new TypeError("Two numbers or a single string expected in function complex");var t=n.parse(e);if(t)return t;throw new SyntaxError('String "'+e+'" is no valid complex number');case 2:return new n(arguments[0],arguments[1]);default:throw E("complex",arguments.length,0,2)}}function tn(e){if(arguments.length>1)throw E("matrix",arguments.length,0,1);return new t(e)}function rn(){return new tt.expr.Parser}function an(e){switch(arguments.length){case 1:if(!y(e))throw new TypeError("Two or three numbers or a single string expected in function range");var n=g.parse(e);if(n)return n;throw new SyntaxError('String "'+n+'" is no valid range');case 2:return new g(arguments[0],null,arguments[1]);case 3:return new g(arguments[0],arguments[1],arguments[2]);default:throw E("range",arguments.length,2,3)}}function on(){switch(arguments.length){case 1:var e=arguments[0];if(!y(e))throw new TypeError("A string or a number and string expected in function unit");if(x.isUnit(e))return new x(null,e);var n=x.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid unit');case 2:return new x(arguments[0],arguments[1]);default:throw E("unit",arguments.length,1,2)}}function sn(){return new tt.expr.Workspace}function fn(e){if(1!=arguments.length)throw E("det",arguments.length,1);var n=tt.size(e);switch(n.length){case 0:return tt.clone(e);case 1:if(1==n[0])return tt.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+tt.format(n)+")");case 2:var t=n[0],r=n[1];if(t==r)return un(e.valueOf(),t,r);throw new RangeError("Matrix must be square (size: "+tt.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+tt.format(n)+")")}}function un(e,n,t){var r=tt.multiply,a=tt.subtract;if(1==n)return e[0][0];if(2==n)return a(r(e[0][0],e[1][1]),r(e[1][0],e[0][1]));for(var i=0,o=0;t>o;o++){var s=cn(e,n,t,0,o);i+=r(r((o+1)%2+(o+1)%2-1,e[0][o]),un(s,n-1,t-1))}return i}function cn(e,n,t,r,a){for(var i,o=[],s=0;n>s;s++)if(s!=r){i=o[s-(s>r)]=[];for(var f=0;t>f;f++)f!=a&&(i[f-(f>a)]=e[s][f])}return o}function ln(e,n){var r,a,i,o;if(1!=arguments.length&&2!=arguments.length)throw E("diag",arguments.length,1,2);if(n){if(!v(n)||!d(n))throw new TypeError("Second parameter in function diag must be an integer")}else n=0;var s=n>0?n:0,f=0>n?-n:0;e instanceof t||e instanceof g||(e=new t(e));var u;switch(e.isVector()?(e=e.toVector(),u=[e.length]):u=e.size(),u.length){case 1:a=e.valueOf();var c=new t;for(c.resize([a.length+f,a.length+s]),r=c.valueOf(),o=a.length,i=0;o>i;i++)r[i+f][i+s]=Gn(a[i]);return c;case 2:for(a=[],r=e.valueOf(),o=Math.min(u[0]-f,u[1]-s),i=0;o>i;i++)a[i]=Gn(r[i+f][i+s]);return new t(a);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}}function hn(){var e=rt.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw E("eye",num,0,2);var n=e[0],r=e[1];if(!v(n)||!d(n)||1>n)throw Error("Parameters in function eye must be positive integers");if(r&&(!v(r)||!d(r)||1>r))throw Error("Parameters in function eye must be positive integers");var a=new t;a.resize(e);for(var i=tt.min(e),o=a.valueOf(),s=0;i>s;s++)o[s][s]=1;return a}function mn(e){if(1!=arguments.length)throw E("inv",arguments.length,1);var n=tt.size(e);switch(n.length){case 0:return tt.divide(1,e);case 1:if(1==n[0])return e instanceof t?new t([tt.divide(1,e.valueOf()[0])]):[tt.divide(1,e[0])];throw new RangeError("Matrix must be square (size: "+tt.format(n)+")");case 2:var r=n[0],a=n[1];if(r==a)return e instanceof t?new t(pn(e.valueOf(),r,a)):pn(e,r,a);throw new RangeError("Matrix must be square (size: "+tt.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+tt.format(n)+")")}}function pn(e,n,t){var r,a,i,o,s,f=tt.add,u=tt.unaryminus,c=tt.multiply,l=tt.divide;if(1==n){if(o=e[0][0],0==o)throw Error("Cannot calculate inverse, determinant is zero");return[[tt.divide(1,o)]]}if(2==n){var h=tt.det(e);if(0==h)throw Error("Cannot calculate inverse, determinant is zero");return[[l(e[1][1],h),l(u(e[0][1]),h)],[l(u(e[1][0]),h),l(e[0][0],h)]]}var m=e.concat();for(r=0;n>r;r++)m[r]=m[r].concat();for(var p=tt.eye(n).valueOf(),v=0;t>v;v++){for(r=v;n>r&&0==m[r][v];)r++;if(r==n||0==m[r][v])throw Error("Cannot calculate inverse, determinant is zero");r!=v&&(s=m[v],m[v]=m[r],m[r]=s,s=p[v],p[v]=p[r],p[r]=s);var d=m[v],g=p[v];for(r=0;n>r;r++){var y=m[r],x=p[r];if(r!=v){if(0!=y[v]){for(i=l(u(y[v]),d[v]),a=v;t>a;a++)y[a]=f(y[a],c(i,d[a]));for(a=0;t>a;a++)x[a]=f(x[a],c(i,g[a]))}}else{for(i=d[v],a=v;t>a;a++)y[a]=l(y[a],i);for(a=0;t>a;a++)x[a]=l(x[a],i)}}}return p}function vn(){var e=rt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new t,r=1;return n.resize(e,r),n}function dn(e){if(1!=arguments.length)throw E("size",arguments.length,1);if(v(e)||e instanceof n||e instanceof x||null==e)return[];if(y(e))return[e.length];if(e instanceof Array)return rt.size(e);if(e instanceof t||e instanceof g)return e.size();if(e.valueOf()!==e)return dn(e.valueOf());throw w("size",e)}function gn(e){if(1!=arguments.length)throw E("squeeze",arguments.length,1);return e instanceof t||e instanceof g?yn(e.toArray()):e instanceof Array?yn(Gn(e)):Gn(e)}function yn(e){if(1==e.length)return yn(e[0]);for(var n=0,t=e.length;t>n;n++){var r=e[n];r instanceof Array&&(e[n]=yn(r))}return e}function xn(e){if(1!=arguments.length)throw E("transpose",arguments.length,1);var n=tt.size(e);switch(n.length){case 0:return tt.clone(e);case 1:return tt.clone(e);case 2:for(var t,r=n[1],a=n[0],i=e.valueOf(),o=[],s=tt.clone,f=0;r>f;f++){t=o[f]=[];for(var u=0;a>u;u++)t[u]=s(i[u][f])}return 0==a&&(o[0]=[]),o;default:throw new RangeError("Matrix must be two dimensional (size: "+tt.format(n)+")")}}function wn(){var e=rt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new t;return n.resize(e),n}function En(e){if(1!=arguments.length)throw E("factorial",arguments.length,1);if(v(e)){if(!d(e))throw new TypeError("Function factorial can only handle integer values");var n=e,r=n;for(n--;n>1;)r*=n,n--;return 0==r&&(r=1),r}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,En);if(e.valueOf()!==e)return En(e.valueOf());throw w("factorial",e)}function Nn(){if(0!=arguments.length)throw E("random",arguments.length,0);return Math.random()}function bn(e){if(0==arguments.length)throw Error("Function max requires one or more parameters (0 provided)");if(e instanceof Array||e instanceof t||e instanceof g){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=tt.size(e);if(1==n.length){if(0==e.length)throw Error("Cannot calculate max of an empty vector");return On(e.valueOf())}if(2==n.length){if(0==n[0]||0==n[1])throw Error("Cannot calculate max of an empty matrix");if(e instanceof Array)return Mn(e,n[0],n[1]);if(e instanceof t||e instanceof g)return new t(Mn(e.valueOf(),n[0],n[1]));throw w("max",e)}throw new RangeError("Cannot calculate max for multi dimensional matrix")}return On(arguments)}function On(e){for(var n=tt.larger,t=e[0],r=1,a=e.length;a>r;r++){var i=e[r];n(i,t)&&(t=i)}return t}function Mn(e,n,t){for(var r=tt.larger,a=[],i=0;t>i;i++){for(var o=e[0][i],s=1;n>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function An(e){if(0==arguments.length)throw Error("Function min requires one or more parameters (0 provided)");if(e instanceof Array||e instanceof t||e instanceof g){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=tt.size(e);if(1==n.length){if(0==e.length)throw Error("Cannot calculate min of an empty vector");return Sn(e.valueOf())}if(2==n.length){if(0==n[0]||0==n[1])throw Error("Cannot calculate min of an empty matrix");if(e instanceof Array)return Tn(e,n[0],n[1]);if(e instanceof t||e instanceof g)return new t(Tn(e.valueOf(),n[0],n[1]));throw w("min",e)}throw new RangeError("Cannot calculate min for multi dimensional matrix")}return Sn(arguments)}function Sn(e){for(var n=tt.smaller,t=e[0],r=1,a=e.length;a>r;r++){var i=e[r];n(i,t)&&(t=i)}return t}function Tn(e,n,t){for(var r=tt.smaller,a=[],i=0;t>i;i++){for(var o=e[0][i],s=1;n>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function zn(e){if(1!=arguments.length)throw E("acos",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.acos(e):zn(new n(e,0));if(e instanceof n){var r=new n(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),a=Y(r),i=new n(a.re-e.im,a.im+e.re),o=C(i);return new n(1.5707963267948966-o.im,o.re)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,zn);if(e.valueOf()!==e)return zn(e.valueOf());throw w("acos",e)}function qn(e){if(1!=arguments.length)throw E("asin",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.asin(e):qn(new n(e,0));if(e instanceof n){var r=e.re,a=e.im,i=new n(a*a-r*r+1,-2*r*a),o=Y(i),s=new n(o.re-a,o.im+r),f=C(s);return new n(f.im,-f.re)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,qn);if(e.valueOf()!==e)return qn(e.valueOf());throw w("asin",e)}function Un(e){if(1!=arguments.length)throw E("atan",arguments.length,1);if(v(e))return Math.atan(e);if(e instanceof n){var r=e.re,a=e.im,i=r*r+(1-a)*(1-a),o=new n((1-a*a-r*r)/i,-2*r/i),s=C(o);return new n(-.5*s.im,.5*s.re)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Un);if(e.valueOf()!==e)return Un(e.valueOf());throw w("atan",e)}function Rn(e,r){if(2!=arguments.length)throw E("atan2",arguments.length,2);if(v(e)){if(v(r))return Math.atan2(e,r);if(r instanceof n)return Math.atan2(e,r.re)}else if(e instanceof n){if(v(r))return Math.atan2(e.re,r);if(r instanceof n)return Math.atan2(e.re,r.re)}if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return rt.map2(e,r,Rn);if(r.valueOf()!==r||e.valueOf()!==e)return Rn(e.valueOf(),r.valueOf());throw w("atan2",e,r)}function Ln(e){if(1!=arguments.length)throw E("cos",arguments.length,1);if(v(e))return Math.cos(e);if(e instanceof n)return new n(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.sin(e.re)*(Math.exp(-e.im)-Math.exp(e.im)));if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Ln);if(e.valueOf()!==e)return Ln(e.valueOf());throw w("cos",e)}function Cn(e){if(1!=arguments.length)throw E("cot",arguments.length,1);if(v(e))return 1/Math.tan(e);if(e instanceof n){var r=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new n(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(Math.exp(-4*e.im)-1)/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Cn);if(e.valueOf()!==e)return Cn(e.valueOf());throw w("cot",e)}function _n(e){if(1!=arguments.length)throw E("csc",arguments.length,1);if(v(e))return 1/Math.sin(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return new n(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.cos(e.re)*(Math.exp(-e.im)-Math.exp(e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,_n);if(e.valueOf()!==e)return _n(e.valueOf());throw w("csc",e)}function In(e){if(1!=arguments.length)throw E("sec",arguments.length,1);if(v(e))return 1/Math.cos(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return new n(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.sin(e.re)*(Math.exp(e.im)-Math.exp(-e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,In);if(e.valueOf()!==e)return In(e.valueOf());throw w("sec",e)}function Pn(e){if(1!=arguments.length)throw E("sin",arguments.length,1);if(v(e))return Math.sin(e);if(e instanceof n)return new n(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.cos(e.re)*(Math.exp(e.im)-Math.exp(-e.im)));if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Pn);if(e.valueOf()!==e)return Pn(e.valueOf());throw w("sin",e)}function Bn(e){if(1!=arguments.length)throw E("tan",arguments.length,1);if(v(e))return Math.tan(e);if(e instanceof n){var r=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new n(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(1-Math.exp(-4*e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return rt.map(e,Bn); +if(e.valueOf()!==e)return Bn(e.valueOf());throw w("tan",e)}function kn(e,n){if(2!=arguments.length)throw E("in",arguments.length,2);if(e instanceof x&&n instanceof x){if(!e.equalBase(n))throw Error("Units do not match");if(n.hasValue)throw Error("Cannot convert to a unit with a value");if(!n.hasUnit)throw Error("Unit expected on the right hand side of function in");var r=n.clone();return r.value=e.value,r.fixPrefix=!0,r}if(e instanceof Array||e instanceof t||e instanceof g||n instanceof Array||n instanceof t||n instanceof g)return rt.map2(e,n,kn);if(e.valueOf()!==e)return tt.in(e.valueOf());throw w("in",e)}function Gn(n){if(1!=arguments.length)throw E("clone",arguments.length,1);if(null==n)return n;if("function"==typeof n.clone)return n.clone();if(v(n)||y(n)||e(n))return n;if(n instanceof Array)return n.map(function(e){return Gn(e)});if(n instanceof Object)return rt.mapObject(n,Gn);throw w("clone",n)}function jn(e,n){var t=arguments.length;if(1!=t&&2!=t)throw E("format",t,1,2);if(1==t){var r=arguments[0];return v(r)?rt.formatNumber(r):r instanceof Array?rt.formatArray(r):y(r)?'"'+r+'"':r instanceof Object?""+r:r+""}if(!y(e))throw new TypeError("String expected as first parameter in function format");if(!(n instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,t){for(var r=t.split("."),a=n[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})}function Vn(e){if(1!=arguments.length)throw E("help",arguments.length,1);if(void 0!=e){if(e.doc)return Dn(e.doc);if(e.constructor.doc)return Dn(e.constructor.doc);if(y(e)){var n=tt[e];if(n&&n.doc)return Dn(n.doc)}}return e instanceof Object&&e.name?'No documentation found on subject "'+e.name+'"':e instanceof Object&&e.constructor.name?'No documentation found on subject "'+e.constructor.name+'"':'No documentation found on subject "'+e+'"'}function Dn(e){var n="";if(e.name&&(n+="NAME\n"+e.name+"\n\n"),e.category&&(n+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(n+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var t=tt.parser();n+="EXAMPLES\n";for(var r=0;e.examples.length>r;r++){var a,i=e.examples[r];try{a=t.eval(i)}catch(o){a=o}n+=i+"\n",n+=" "+tt.format(a)+"\n"}n+="\n"}return e.seealso&&(n+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),n}function Fn(e,n){var t;if(y(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var r=require(e);Fn(r)}else if(Hn(e)){if(t=e.name,!t)throw Error("Cannot import an unnamed function");(n||void 0===tt[t])&&(tt[t]=e)}else if(e instanceof Object)for(t in e)if(e.hasOwnProperty(t)){var a=e[t];Hn(a)?(n||void 0===tt[t])&&(tt[t]=a):Fn(a)}}function Hn(e){return"function"==typeof e||v(e)||y(e)||e instanceof n||e instanceof x}function Yn(e){if(1!=arguments.length)throw E("typeof",arguments.length,1);var n=typeof e;if("object"==n){if(null==e)return"null";if(e.constructor){for(var t in tt)if(tt.hasOwnProperty(t)&&e.constructor==tt[t])return t.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return n}function Wn(){}function Xn(e,n,t){this.name=e,this.fn=n,this.params=t}function Zn(e){this.value=e}function Kn(e){this.nodes=e||[]}function Qn(){this.params=[],this.visible=[]}function Jn(e,n,t,r){this.name=e,this.params=n,this.expr=t,this.result=r}function $n(e,n){this.object=e,this.params=n}function et(e,n,t,r,a){this.name=e,this.variables=t,this.values=[];for(var i=0,o=this.variables.length;o>i;i++)this.values[i]=function(){var e=function(){return e.value};return e.value=void 0,e}();this.def=this.createFunction(e,n,t,r),this.result=a}function nt(e,n){throw Error('Constructor "'+e+'" has been replaced by '+'constructor method "'+n+'" in math.js v0.5.0')}var tt={type:{},expr:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=tt),"undefined"!=typeof exports&&(exports=tt),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return tt}),"undefined"!=typeof window&&(window.math=tt);var rt=function(){function e(e){if(e instanceof Array){var n=e.length;if(n){var t=o(e[0]);return 0==t[0]?[0].concat(t):[n].concat(t)}return[n]}return[]}function n(e,t,r){var a,i=e.length;if(i!=t[r])throw new RangeError("Dimension mismatch ("+i+" != "+t[r]+")");if(t.length-1>r){var o=r+1;for(a=0;i>a;a++){var s=e[a];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(t.length-1)+" < "+t.length+")");n(e[a],t,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(t.length+1)+" > "+t.length+")")}function r(e,n,t){if(n.length-1>t){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");r(a,n,t+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,n,t,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=n[t];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?Gn(r):0;else e.length=n[t];i=e.length}if(n.length-1>t){var f=t+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,n,f,r)}else for(s=0;i>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var i={};return i.formatNumber=function(e,n){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var t=Math.abs(e);if(t>1e-4&&1e6>t||0==t)return V(e,n)+"";var r=Math.round(Math.log(t)/Math.LN10),a=e/Math.pow(10,r);return V(a,n)+"E"+r},i.formatArray=function(e){if(e instanceof Array){for(var n="[",t=e.length,r=0;t>r;r++)0!=r&&(n+=", "),n+=i.formatArray(e[r]);return n+="]"}return jn(e)},i.formatArray2d=function(e){var n="[",t=i.size(e);if(2!=t.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(t)+")");for(var r=t[0],a=t[1],o=0;r>o;o++){0!=o&&(n+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(n+=", ");var u=s[f];void 0!=u&&(n+=jn(u))}}return n+="]"},i.argsToArray=function(e){var n;if(0==e.length)n=[];else if(1==e.length)n=e[0],n instanceof t&&(n=n.toVector()),n instanceof g&&(n=n.valueOf()),n instanceof Array||(n=[n]);else{n=[];for(var r=0;e.length>r;r++)n[r]=e[r]}return n},i.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},i.map=function(e,n){if(e instanceof Array||e instanceof t||e instanceof g)return e.map(function(e){return n(e)});throw new TypeError("Array expected")},i.map2=function(e,n,r){var a,o,s;if(e instanceof t||n instanceof t)return new t(i.map2(e.valueOf(),n.valueOf(),r));if(e instanceof g||n instanceof g)return new t(i.map2(e.valueOf(),n.valueOf(),r));if(e instanceof Array)if(n instanceof Array){if(e.length!=n.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+n.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],n[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],n);else if(n instanceof Array)for(a=[],o=n.length,s=0;o>s;s++)a[s]=r(e,n[s]);else a=r(e,n);return a},i.forEach=function(e,n){if(e instanceof Array)e.forEach(n);else for(var t in e)e.hasOwnProperty(t)&&n(e[t],t,e)},i.mapObject=function(e,n){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},i.deepEqual=function(e,n){var t,r,a;if(e instanceof Array){if(!(n instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],n[r]))return!1;return!0}if(e instanceof Object){if(n instanceof Array||!(n instanceof Object))return!1;for(t in e)if(e.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;for(t in n)if(n.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;return!0}return e.valueOf()==n.valueOf()},i.size=function o(n){var t=e(n);return i.validate(n,t),t},i.validate=function(e,t){var a=0==t.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=t.indexOf(0);o?(t.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(t)+")")}),r(e,t,0)):n(e,t,0)}},i.resize=function(e,n,t){if(!(n instanceof Array))throw new TypeError("Size must be an array (size is "+tt.typeof(n)+")");n.forEach(function(e){if(!v(e)||!d(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(n)+")")});var r=-1!=n.indexOf(0);r&&n.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(n)+")")}),a(e,n,0,t)},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var n=0;this.length>n;n++)if(this[n]==e)return n;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,n){for(var t=0,r=this.length;r>t;++t)e.call(n||this,this[t],t,this)}),Array.prototype.map||(Array.prototype.map=function(e,n){var t,r,a;if(null==this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(n&&(t=n),r=Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(t,s,a,i),r[a]=f),a++}return r}),Array.prototype.every||(Array.prototype.every=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&!e.call(r,n[a],a,n))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&e.call(r,n[a],a,n))return!0;return!1}),i}();tt.type.Complex=n,function(){function e(){for(;" "==c||" "==c;)a()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function a(){u++,c=f[u]}function i(e){u=e,c=f[u]}function o(){var e="",n=u;if("+"==c?a():"-"==c&&(e+=c,a()),!t(c))return i(n),null;for(;t(c);)e+=c,a();if("E"==c||"e"==c){if(e+=c,a(),("+"==c||"-"==c)&&(e+=c,a()),!r(c))return i(n),null;for(;r(c);)e+=c,a()}return e}function s(){var e=f[u+1];if("I"==c||"i"==c)return a(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var n="+"==c?"1":"-1";return a(),a(),n}return null}var f,u,c;n.parse=function(t){if(f=t,u=-1,c="",!y(f))return null;a(),e();var r=o();if(r){if("I"==c||"i"==c)return a(),e(),c?null:new n(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new n(Number(r),0);a(),e();var l=o();if(l){if("I"!=c&&"i"!=c)return null;a()}else if(l=s(),!l)return null;return"-"==i&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),a(),e(),c?null:new n(Number(r),Number(l))}return(r=s())?(e(),c?null:new n(0,Number(r))):null}}(),n.prototype.clone=function(){return new n(this.re,this.im)},n.prototype.toString=function(){var e="",n=rt.formatNumber(this.re),t=rt.formatNumber(this.im);return e=0==this.im?n:0==this.re?1==this.im?"i":-1==this.im?"-i":t+"i":this.im>0?1==this.im?n+" + i":n+" + "+t+"i":-1==this.im?n+" - i":n+" - "+rt.formatNumber(Math.abs(this.im))+"i"},n.doc={name:"Complex",category:"type",syntax:["a + bi","a + b * i"],description:"A complex value a + bi, where a is the real part and b is the complex part, and i is the imaginary number defined as sqrt(-1).",examples:["2 + 3i","sqrt(-4)","(1.2 -5i) * 2"],seealso:["abs","arg","conj","im","re"]},tt.type.Matrix=t,t.prototype.get=function(e){var n;if(e instanceof t)n=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+tt.typeof(e));n=!e.some(function(e){return e.forEach})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(n)switch(e.length){case 1:return a(this._data,e[0]);case 2:return a(a(this._data,e[0]),e[1]);default:return i(this._data,e)}else switch(e.length){case 1:return new t(o(this._data,e));case 2:return new t(s(this._data,e));default:return new t(f(this._data,e,0))}},t.prototype.set=function(e,n){var r;if(e instanceof t)r=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+tt.typeof(e));r=!e.some(function(e){return e.forEach})}if((n instanceof t||n instanceof g)&&(n=n.valueOf()),e.length=e})},t.prototype.toVector=function(){var e=0,n=void 0,t=[];if(this._size.forEach(function(r,a){r>1&&(e++,n=a),t[a]=0}),0==e){var r=this.toScalar();return r?[r]:[]}if(1==e){var a=[],i=function(e){e instanceof Array?e.forEach(i):a.push(e)};return i(this._data),a}return null},t.prototype.isVector=function(){var e=0;return this._size.forEach(function(n){n>1&&e++}),1>=e},t.prototype.toArray=function(){return Gn(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.toString=function(){return rt.formatArray(this._data)},tt.type.Range=g,g.parse=function(e){if(!y(e))return null;var n=e.split(":"),t=n.map(function(e){return Number(e)}),r=t.some(function(e){return isNaN(e)});if(r)return null;switch(t.length){case 2:return new g(t[0],1,t[1]);case 3:return new g(t[0],t[1],t[2]);default:return null}},g.prototype.clone=function(){return new g(this.start,this.step,this.end)},g.prototype.size=function(){var e=0,n=Number(this.start),t=Number(this.step),r=Number(this.end),a=r-n;return D(t)==D(a)?e=Math.floor(a/t)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},g.prototype.forEach=function(e){var n=Number(this.start),t=Number(this.step),r=Number(this.end),a=0;if(t>0)for(;r>=n;)e(n,a,this),n+=t,a++;else if(0>t)for(;n>=r;)e(n,a,this),n+=t,a++},g.prototype.map=function(e){var n=[];return this.forEach(function(t,r,a){n[r]=e(t,r,a)}),n},g.prototype.toMatrix=function(){return new t(this.toArray())},g.prototype.toArray=function(){var e=[];return this.forEach(function(n,t){e[t]=n}),e},g.prototype.toVector=g.prototype.toArray,g.prototype.isVector=function(){return!0},g.prototype.toScalar=function(){var e=this.toArray();return 1==e.length?e[0]:null},g.prototype.isScalar=function(){return 1==this.size()[0]},g.prototype.valueOf=function(){return this.toArray()},g.prototype.toString=function(){var e=jn(Number(this.start));return 1!=this.step&&(e+=":"+jn(Number(this.step))),e+=":"+jn(Number(this.end))},tt.type.Unit=x,function(){function e(){for(;" "==u||" "==u;)r()}function n(e){return e>="0"&&"9">=e||"."==e}function t(e){return e>="0"&&"9">=e}function r(){f++,u=s[f]}function a(e){f=e,u=s[f]}function i(){var e="",i=f;if("+"==u?r():"-"==u&&(e+=u,r()),!n(u))return a(i),null;for(;n(u);)e+=u,r();if("E"==u||"e"==u){if(e+=u,r(),("+"==u||"-"==u)&&(e+=u,r()),!t(u))return a(i),null;for(;t(u);)e+=u,r()}return e}function o(){var n="";for(e();u&&" "!=u&&" "!=u;)n+=u,r();return n||null}var s,f,u;x.parse=function(n){if(s=n,f=-1,u="",!y(s))return null;r(),e();var t,a=i();return a?(t=o(),r(),e(),u?null:a&&t?new x(Number(a),t):null):(t=o(),r(),e(),u?null:new x(null,t))}}(),x.prototype.clone=function(){var e=new x;for(var n in this)this.hasOwnProperty(n)&&(e[n]=this[n]);return e},x.endsWith=function(e,n){var t=e.length-n.length,r=e.length;return e.substring(t,r)===n},x.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},x.prototype._unnormalize=function(e,n){return void 0===n?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/n-this.unit.offset},x.isUnit=function(e){for(var n=x.UNITS,t=n.length,r=0;t>r;r++){var a=n[r];if(x.endsWith(e,a.name)){var i=e.length-a.name.length;if(0==i)return!0;var o=e.substring(0,i),s=a.prefixes[o];if(void 0!==s)return!0}}return!1},x.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},x.prototype.equalBase=function(e){return this.unit.base===e.unit.base},x.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},x.prototype.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),rt.formatNumber(e)+" "+this.prefix.name+this.unit.name;var n=Math.abs(this.value/this.unit.value),t=x.PREFIX_NONE,r=Math.abs(Math.log(n/t.value)/Math.LN10-1.2),a=this.unit.prefixes;for(var i in a)if(a.hasOwnProperty(i)){var o=a[i];if(o.scientific){var s=Math.abs(Math.log(n/o.value)/Math.LN10-1.2);r>s&&(t=o,r=s)}}return e=this._unnormalize(this.value,t.value),rt.formatNumber(e)+" "+t.name+this.unit.name},x.PREFIXES={NONE:{"":{name:"",value:1,scientific:!0}},SHORT:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:10,scientific:!1},h:{name:"h",value:100,scientific:!1},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},d:{name:"d",value:.1,scientific:!1},c:{name:"c",value:.01,scientific:!1},m:{name:"m",value:.001,scientific:!0},u:{name:"u",value:1e-6,scientific:!0},n:{name:"n",value:1e-9,scientific:!0},p:{name:"p",value:1e-12,scientific:!0},f:{name:"f",value:1e-15,scientific:!0},a:{name:"a",value:1e-18,scientific:!0},z:{name:"z",value:1e-21,scientific:!0},y:{name:"y",value:1e-24,scientific:!0}},LONG:{"":{name:"",value:1,scientific:!0},deca:{name:"deca",value:10,scientific:!1},hecto:{name:"hecto",value:100,scientific:!1},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},deci:{name:"deci",value:.1,scientific:!1},centi:{name:"centi",value:.01,scientific:!1},milli:{name:"milli",value:.001,scientific:!0},micro:{name:"micro",value:1e-6,scientific:!0},nano:{name:"nano",value:1e-9,scientific:!0},pico:{name:"pico",value:1e-12,scientific:!0},femto:{name:"femto",value:1e-15,scientific:!0},atto:{name:"atto",value:1e-18,scientific:!0},zepto:{name:"zepto",value:1e-21,scientific:!0},yocto:{name:"yocto",value:1e-24,scientific:!0}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1024,scientific:!0},M:{name:"M",value:Math.pow(1024,2),scientific:!0},G:{name:"G",value:Math.pow(1024,3),scientific:!0},T:{name:"T",value:Math.pow(1024,4),scientific:!0},P:{name:"P",value:Math.pow(1024,5),scientific:!0},E:{name:"E",value:Math.pow(1024,6),scientific:!0},Z:{name:"Z",value:Math.pow(1024,7),scientific:!0},Y:{name:"Y",value:Math.pow(1024,8),scientific:!0},Ki:{name:"Ki",value:1024,scientific:!0},Mi:{name:"Mi",value:Math.pow(1024,2),scientific:!0},Gi:{name:"Gi",value:Math.pow(1024,3),scientific:!0},Ti:{name:"Ti",value:Math.pow(1024,4),scientific:!0},Pi:{name:"Pi",value:Math.pow(1024,5),scientific:!0},Ei:{name:"Ei",value:Math.pow(1024,6),scientific:!0},Zi:{name:"Zi",value:Math.pow(1024,7),scientific:!0},Yi:{name:"Yi",value:Math.pow(1024,8),scientific:!0}},BINARY_LONG:{"":{name:"",value:1,scientific:!0},kilo:{name:"kilo",value:1024,scientific:!0},mega:{name:"mega",value:Math.pow(1024,2),scientific:!0},giga:{name:"giga",value:Math.pow(1024,3),scientific:!0},tera:{name:"tera",value:Math.pow(1024,4),scientific:!0},peta:{name:"peta",value:Math.pow(1024,5),scientific:!0},exa:{name:"exa",value:Math.pow(1024,6),scientific:!0},zetta:{name:"zetta",value:Math.pow(1024,7),scientific:!0},yotta:{name:"yotta",value:Math.pow(1024,8),scientific:!0},kibi:{name:"kibi",value:1024,scientific:!0},mebi:{name:"mebi",value:Math.pow(1024,2),scientific:!0},gibi:{name:"gibi",value:Math.pow(1024,3),scientific:!0},tebi:{name:"tebi",value:Math.pow(1024,4),scientific:!0},pebi:{name:"pebi",value:Math.pow(1024,5),scientific:!0},exi:{name:"exi",value:Math.pow(1024,6),scientific:!0},zebi:{name:"zebi",value:Math.pow(1024,7),scientific:!0},yobi:{name:"yobi",value:Math.pow(1024,8),scientific:!0}}},x.PREFIX_NONE={name:"",value:1,scientific:!0},x.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var at=x.BASE_UNITS,it=x.PREFIXES;x.BASE_UNIT_NONE={},x.UNIT_NONE={name:"",base:x.BASE_UNIT_NONE,value:1,offset:0},x.UNITS=[{name:"meter",base:at.LENGTH,prefixes:it.LONG,value:1,offset:0},{name:"inch",base:at.LENGTH,prefixes:it.NONE,value:.0254,offset:0},{name:"foot",base:at.LENGTH,prefixes:it.NONE,value:.3048,offset:0},{name:"yard",base:at.LENGTH,prefixes:it.NONE,value:.9144,offset:0},{name:"mile",base:at.LENGTH,prefixes:it.NONE,value:1609.344,offset:0},{name:"link",base:at.LENGTH,prefixes:it.NONE,value:.201168,offset:0},{name:"rod",base:at.LENGTH,prefixes:it.NONE,value:5.02921,offset:0},{name:"chain",base:at.LENGTH,prefixes:it.NONE,value:20.1168,offset:0},{name:"angstrom",base:at.LENGTH,prefixes:it.NONE,value:1e-10,offset:0},{name:"m",base:at.LENGTH,prefixes:it.SHORT,value:1,offset:0},{name:"ft",base:at.LENGTH,prefixes:it.NONE,value:.3048,offset:0},{name:"yd",base:at.LENGTH,prefixes:it.NONE,value:.9144,offset:0},{name:"mi",base:at.LENGTH,prefixes:it.NONE,value:1609.344,offset:0},{name:"li",base:at.LENGTH,prefixes:it.NONE,value:.201168,offset:0},{name:"rd",base:at.LENGTH,prefixes:it.NONE,value:5.02921,offset:0},{name:"ch",base:at.LENGTH,prefixes:it.NONE,value:20.1168,offset:0},{name:"mil",base:at.LENGTH,prefixes:it.NONE,value:254e-7,offset:0},{name:"m2",base:at.SURFACE,prefixes:it.SHORT,value:1,offset:0},{name:"sqin",base:at.SURFACE,prefixes:it.NONE,value:64516e-8,offset:0},{name:"sqft",base:at.SURFACE,prefixes:it.NONE,value:.09290304,offset:0},{name:"sqyd",base:at.SURFACE,prefixes:it.NONE,value:.83612736,offset:0},{name:"sqmi",base:at.SURFACE,prefixes:it.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:at.SURFACE,prefixes:it.NONE,value:25.29295,offset:0},{name:"sqch",base:at.SURFACE,prefixes:it.NONE,value:404.6873,offset:0},{name:"sqmil",base:at.SURFACE,prefixes:it.NONE,value:6.4516e-10,offset:0},{name:"m3",base:at.VOLUME,prefixes:it.SHORT,value:1,offset:0},{name:"L",base:at.VOLUME,prefixes:it.SHORT,value:.001,offset:0},{name:"litre",base:at.VOLUME,prefixes:it.LONG,value:.001,offset:0},{name:"cuin",base:at.VOLUME,prefixes:it.NONE,value:16387064e-12,offset:0},{name:"cuft",base:at.VOLUME,prefixes:it.NONE,value:.028316846592,offset:0},{name:"cuyd",base:at.VOLUME,prefixes:it.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:at.VOLUME,prefixes:it.NONE,value:5e-6,offset:0},{name:"tablespoon",base:at.VOLUME,prefixes:it.NONE,value:15e-6,offset:0},{name:"minim",base:at.VOLUME,prefixes:it.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:at.VOLUME,prefixes:it.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:at.VOLUME,prefixes:it.NONE,value:2957353e-11,offset:0},{name:"gill",base:at.VOLUME,prefixes:it.NONE,value:.0001182941,offset:0},{name:"cup",base:at.VOLUME,prefixes:it.NONE,value:.0002365882,offset:0},{name:"pint",base:at.VOLUME,prefixes:it.NONE,value:.0004731765,offset:0},{name:"quart",base:at.VOLUME,prefixes:it.NONE,value:.0009463529,offset:0},{name:"gallon",base:at.VOLUME,prefixes:it.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:at.VOLUME,prefixes:it.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:at.VOLUME,prefixes:it.NONE,value:.1589873,offset:0},{name:"hogshead",base:at.VOLUME,prefixes:it.NONE,value:.238481,offset:0},{name:"fldr",base:at.VOLUME,prefixes:it.NONE,value:36966911e-13,offset:0},{name:"floz",base:at.VOLUME,prefixes:it.NONE,value:2957353e-11,offset:0},{name:"gi",base:at.VOLUME,prefixes:it.NONE,value:.0001182941,offset:0},{name:"cp",base:at.VOLUME,prefixes:it.NONE,value:.0002365882,offset:0},{name:"pt",base:at.VOLUME,prefixes:it.NONE,value:.0004731765,offset:0},{name:"qt",base:at.VOLUME,prefixes:it.NONE,value:.0009463529,offset:0},{name:"gal",base:at.VOLUME,prefixes:it.NONE,value:.003785412,offset:0},{name:"bbl",base:at.VOLUME,prefixes:it.NONE,value:.1173478,offset:0},{name:"obl",base:at.VOLUME,prefixes:it.NONE,value:.1589873,offset:0},{name:"g",base:at.MASS,prefixes:it.SHORT,value:.001,offset:0},{name:"gram",base:at.MASS,prefixes:it.LONG,value:.001,offset:0},{name:"ton",base:at.MASS,prefixes:it.SHORT,value:907.18474,offset:0},{name:"tonne",base:at.MASS,prefixes:it.SHORT,value:1e3,offset:0},{name:"grain",base:at.MASS,prefixes:it.NONE,value:6479891e-11,offset:0},{name:"dram",base:at.MASS,prefixes:it.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:at.MASS,prefixes:it.NONE,value:.028349523125,offset:0},{name:"poundmass",base:at.MASS,prefixes:it.NONE,value:.45359237,offset:0},{name:"hundredweight",base:at.MASS,prefixes:it.NONE,value:45.359237,offset:0},{name:"stick",base:at.MASS,prefixes:it.NONE,value:.115,offset:0},{name:"gr",base:at.MASS,prefixes:it.NONE,value:6479891e-11,offset:0},{name:"dr",base:at.MASS,prefixes:it.NONE,value:.0017718451953125,offset:0},{name:"oz",base:at.MASS,prefixes:it.NONE,value:.028349523125,offset:0},{name:"lbm",base:at.MASS,prefixes:it.NONE,value:.45359237,offset:0},{name:"cwt",base:at.MASS,prefixes:it.NONE,value:45.359237,offset:0},{name:"s",base:at.TIME,prefixes:it.SHORT,value:1,offset:0},{name:"min",base:at.TIME,prefixes:it.NONE,value:60,offset:0},{name:"h",base:at.TIME,prefixes:it.NONE,value:3600,offset:0},{name:"seconds",base:at.TIME,prefixes:it.LONG,value:1,offset:0},{name:"second",base:at.TIME,prefixes:it.LONG,value:1,offset:0},{name:"sec",base:at.TIME,prefixes:it.LONG,value:1,offset:0},{name:"minutes",base:at.TIME,prefixes:it.NONE,value:60,offset:0},{name:"minute",base:at.TIME,prefixes:it.NONE,value:60,offset:0},{name:"hours",base:at.TIME,prefixes:it.NONE,value:3600,offset:0},{name:"hour",base:at.TIME,prefixes:it.NONE,value:3600,offset:0},{name:"day",base:at.TIME,prefixes:it.NONE,value:86400,offset:0},{name:"days",base:at.TIME,prefixes:it.NONE,value:86400,offset:0},{name:"rad",base:at.ANGLE,prefixes:it.NONE,value:1,offset:0},{name:"deg",base:at.ANGLE,prefixes:it.NONE,value:.017453292519943295,offset:0},{name:"grad",base:at.ANGLE,prefixes:it.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:at.ANGLE,prefixes:it.NONE,value:6.283185307179586,offset:0},{name:"A",base:at.CURRENT,prefixes:it.SHORT,value:1,offset:0},{name:"ampere",base:at.CURRENT,prefixes:it.LONG,value:1,offset:0},{name:"K",base:at.TEMPERATURE,prefixes:it.NONE,value:1,offset:0},{name:"degC",base:at.TEMPERATURE,prefixes:it.NONE,value:1,offset:273.15},{name:"degF",base:at.TEMPERATURE,prefixes:it.NONE,value:1/1.8,offset:459.67},{name:"degR",base:at.TEMPERATURE,prefixes:it.NONE,value:1/1.8,offset:0},{name:"kelvin",base:at.TEMPERATURE,prefixes:it.NONE,value:1,offset:0},{name:"celsius",base:at.TEMPERATURE,prefixes:it.NONE,value:1,offset:273.15},{name:"fahrenheit",base:at.TEMPERATURE,prefixes:it.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:at.TEMPERATURE,prefixes:it.NONE,value:1/1.8,offset:0},{name:"mol",base:at.AMOUNT_OF_SUBSTANCE,prefixes:it.NONE,value:1,offset:0},{name:"mole",base:at.AMOUNT_OF_SUBSTANCE,prefixes:it.NONE,value:1,offset:0},{name:"cd",base:at.LUMINOUS_INTENSITY,prefixes:it.NONE,value:1,offset:0},{name:"candela",base:at.LUMINOUS_INTENSITY,prefixes:it.NONE,value:1,offset:0},{name:"N",base:at.FORCE,prefixes:it.SHORT,value:1,offset:0},{name:"newton",base:at.FORCE,prefixes:it.LONG,value:1,offset:0},{name:"lbf",base:at.FORCE,prefixes:it.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:at.FORCE,prefixes:it.NONE,value:4.4482216152605,offset:0},{name:"b",base:at.BIT,prefixes:it.BINARY_SHORT,value:1,offset:0},{name:"bits",base:at.BIT,prefixes:it.BINARY_LONG,value:1,offset:0},{name:"B",base:at.BIT,prefixes:it.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:at.BIT,prefixes:it.BINARY_LONG,value:8,offset:0}],tt.E=Math.E,tt.LN2=Math.LN2,tt.LN10=Math.LN10,tt.LOG2E=Math.LOG2E,tt.LOG10E=Math.LOG10E,tt.PI=Math.PI,tt.SQRT1_2=Math.SQRT1_2,tt.SQRT2=Math.SQRT2,tt.I=new n(0,-1),tt.pi=tt.PI,tt.e=tt.E,tt.i=tt.I,tt.abs=N,N.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},tt.add=b,b.doc={name:"add",category:"Operators",syntax:["x + y","add(x, y)"],description:"Add two values.",examples:["2.1 + 3.6","ans - 3.6","3 + 2i",'"hello" + " world"',"3 cm + 2 inch"],seealso:["subtract"]},tt.ceil=O,O.doc={name:"ceil",category:"Arithmetic",syntax:["ceil(x)"],description:"Round a value towards plus infinity.If x is complex, both real and imaginary part are rounded towards plus infinity.",examples:["ceil(3.2)","ceil(3.8)","ceil(-4.2)"],seealso:["floor","fix","round"]},tt.cube=M,M.doc={name:"cube",category:"Arithmetic",syntax:["cube(x)"],description:"Compute the cube of a value. The cube of x is x * x * x.",examples:["cube(2)","2^3","2 * 2 * 2"],seealso:["multiply","square","pow"]},tt.divide=A,A.doc={name:"divide",category:"Operators",syntax:["x / y","divide(x, y)"],description:"Divide two values.",examples:["2 / 3","ans * 3","4.5 / 2","3 + 4 / 2","(3 + 4) / 2","18 km / 4.5"],seealso:["multiply"]},tt.equal=T,T.doc={name:"equal",category:"Operators",syntax:["x == y","equal(x, y)"],description:"Check equality of two values. Returns 1 if the values are equal, and 0 if not.",examples:["2+2 == 3","2+2 == 4","a = 3.2","b = 6-2.8","a == b","50cm == 0.5m"],seealso:["unequal","smaller","larger","smallereq","largereq"]},tt.exp=z,z.doc={name:"exp",category:"Arithmetic",syntax:["exp(x)"],description:"Calculate the exponent of a value.",examples:["exp(1.3)","e ^ 1.3","log(exp(1.3))","x = 2.4","(exp(i*x) == cos(x) + i*sin(x)) # Euler's formula"],seealso:["square","multiply","log"]},tt.fix=q,q.doc={name:"fix",category:"Arithmetic",syntax:["fix(x)"],description:"Round a value towards zero.If x is complex, both real and imaginary part are rounded towards zero.",examples:["fix(3.2)","fix(3.8)","fix(-4.2)","fix(-4.8)"],seealso:["ceil","floor","round"]},tt.floor=U,U.doc={name:"floor",category:"Arithmetic",syntax:["floor(x)"],description:"Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.",examples:["floor(3.2)","floor(3.8)","floor(-4.2)"],seealso:["ceil","fix","round"]},tt.larger=R,R.doc={name:"larger",category:"Operators",syntax:["x > y","larger(x, y)"],description:"Check if value x is larger than y. Returns 1 if x is larger than y, and 0 if not.",examples:["2 > 3","5 > 2*2","a = 3.3","b = 6-2.8","(a > b)","(b < a)","5 cm > 2 inch"],seealso:["equal","unequal","smaller","smallereq","largereq"]},tt.largereq=L,L.doc={name:"largereq",category:"Operators",syntax:["x >= y","largereq(x, y)"],description:"Check if value x is larger or equal to y. Returns 1 if x is larger or equal to y, and 0 if not.",examples:["2 > 1+1","2 >= 1+1","a = 3.2","b = 6-2.8","(a > b)"],seealso:["equal","unequal","smallereq","smaller","largereq"]},tt.log=C,C.doc={name:"log",category:"Arithmetic",syntax:["log(x)","log(x, base)"],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).",examples:["log(3.5)","a = log(2.4)","exp(a)","10 ^ 3","log(1000, 10)","log(1000) / log(10)","b = logb(1024, 2)","2 ^ b"],seealso:["exp","log10"]},tt.log10=_,_.doc={name:"log10",category:"Arithmetic",syntax:["log10(x)"],description:"Compute the 10-base logarithm of a value.",examples:["log10(1000)","10 ^ 3","log10(0.01)","log(1000) / log(10)","log(1000, 10)"],seealso:["exp","log"]},tt.mod=I,I.doc={name:"mod",category:"Operators",syntax:["x % y","x mod y","mod(x, y)"],description:"Calculates the modulus, the remainder of an integer division.",examples:["7 % 3","11 % 2","10 mod 4","function isOdd(x) = x % 2","isOdd(2)","isOdd(3)"],seealso:[]},tt.multiply=P,P.doc={name:"multiply",category:"Operators",syntax:["x * y","multiply(x, y)"],description:"multiply two values.",examples:["2.1 * 3.6","ans / 3.6","2 * 3 + 4","2 * (3 + 4)","3 * 2.1 km"],seealso:["divide"]},tt.pow=k,k.doc={name:"pow",category:"Operators",syntax:["x ^ y","pow(x, y)"],description:"Calculates the power of x to y, x^y.",examples:["2^3 = 8","2*2*2","1 + e ^ (pi * i)"],seealso:["unequal","smaller","larger","smallereq","largereq"]},tt.round=j,j.doc={name:"round",category:"Arithmetic",syntax:["round(x)","round(x, n)"],description:"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.",examples:["round(3.2)","round(3.8)","round(-4.2)","round(-4.8)","round(pi, 3)","round(123.45678, 2)"],seealso:["ceil","floor","fix"]},tt.sign=D,D.doc={name:"sign",category:"Arithmetic",syntax:["sign(x)"],description:"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.",examples:["sign(3.5)","sign(-4.2)","sign(0)"],seealso:["abs"]},tt.smaller=F,F.doc={name:"smaller",category:"Operators",syntax:["x < y","smaller(x, y)"],description:"Check if value x is smaller than value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 3","5 < 2*2","a = 3.3","b = 6-2.8","(a < b)","5 cm < 2 inch"],seealso:["equal","unequal","larger","smallereq","largereq"]},tt.smallereq=H,H.doc={name:"smallereq",category:"Operators",syntax:["x <= y","smallereq(x, y)"],description:"Check if value x is smaller or equal to value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 1+1","2 <= 1+1","a = 3.2","b = 6-2.8","(a < b)"],seealso:["equal","unequal","larger","smaller","largereq"]},tt.sqrt=Y,Y.doc={name:"sqrt",category:"Arithmetic",syntax:["sqrt(x)"],description:"Compute the square root value. If x = y * y, then y is the square root of x.",examples:["sqrt(25)","5 * 5","sqrt(-1)"],seealso:["square","multiply"]},tt.square=W,W.doc={name:"square",category:"Arithmetic",syntax:["square(x)"],description:"Compute the square of a value. The square of x is x * x.",examples:["square(3)","sqrt(9)","3^2","3 * 3"],seealso:["multiply","pow","sqrt","cube"]},tt.subtract=X,X.doc={name:"subtract",category:"Operators",syntax:["x - y","subtract(x, y)"],description:"subtract two values.",examples:["5.3 - 2","ans + 2","2/3 - 1/6","2 * 3 - 3","2.1 km - 500m"],seealso:["add"]},tt.unaryminus=Z,Z.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},tt.unequal=K,K.doc={name:"unequal",category:"Operators",syntax:["x != y","unequal(x, y)"],description:"Check unequality of two values. Returns 1 if the values are unequal, and 0 if they are equal.",examples:["2+2 != 3","2+2 != 4","a = 3.2","b = 6-2.8","a != b","50cm != 0.5m","5 cm != 2 inch"],seealso:["equal","smaller","larger","smallereq","largereq"]},tt.arg=Q,Q.doc={name:"arg",category:"Complex",syntax:["arg(x)"],description:"Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).",examples:["arg(2 + 2i)","atan2(3, 2)","arg(2 - 3i)"],seealso:["re","im","conj","abs"]},tt.conj=J,J.doc={name:"conj",category:"Complex",syntax:["conj(x)"],description:"Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.",examples:["conj(2 + 3i)","conj(2 - 3i)","conj(-5.2i)"],seealso:["re","im","abs","arg"]},tt.im=$,$.doc={name:"im",category:"Complex",syntax:["im(x)"],description:"Get the imaginary part of a complex number.",examples:["im(2 + 3i)","re(2 + 3i)","im(-5.2i)","im(2.4)"],seealso:["re","conj","abs","arg"]},tt.re=en,en.doc={name:"re",category:"Complex",syntax:["re(x)"],description:"Get the real part of a complex number.",examples:["re(2 + 3i)","im(2 + 3i)","re(-5.2i)","re(2.4)"],seealso:["im","conj","abs","arg"]},tt.complex=nn,tt.matrix=tn,tt.parser=rn,tt.range=an,tt.unit=on,tt.workspace=sn,tt.det=fn,fn.doc={name:"det",category:"Numerics",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["diag","eye","inv","range","size","squeeze","transpose","zeros"]},tt.diag=ln,ln.doc={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],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.",examples:["diag(1:4)","diag(1:4, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["det","eye","inv","ones","range","size","squeeze","transpose","zeros"]},tt.eye=hn,hn.doc={name:"eye",category:"Numerics",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["det","diag","inv","ones","range","size","squeeze","transpose","zeros"]},tt.inv=mn,mn.doc={name:"inv",category:"Numerics",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["det","diag","eye","ones","range","size","squeeze","transpose","zeros"]},tt.ones=vn,vn.doc={name:"ones",category:"Numerics",syntax:["ones(n)","ones(m, n)","ones(m, n, p, ...)","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["det","diag","eye","inv","range","size","squeeze","transpose","zeros"]},tt.size=dn,dn.doc={name:"size",category:"Numerics",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["det","diag","eye","inv","ones","range","squeeze","transpose","zeros"]},tt.squeeze=gn,gn.doc={name:"squeeze",category:"Numerics",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["det","diag","eye","inv","ones","range","size","transpose","zeros"]},tt.transpose=xn,xn.doc={name:"transpose",category:"Numerics",syntax:["transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","transpose(a)"],seealso:["det","diag","eye","inv","ones","range","size","squeeze","zeros"]},tt.zeros=wn,wn.doc={name:"zeros",category:"Numerics",syntax:["zeros(n)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["det","diag","eye","inv","ones","range","size","squeeze","transpose"]},tt.factorial=En,En.doc={name:"factorial",category:"Probability",syntax:["x!","factorial(x)"],description:"Compute the factorial of a value",examples:["5!","5*4*3*2*1","3!"],seealso:[]},tt.random=Nn,Nn.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},tt.max=bn,bn.doc={name:"max",category:"Statistics",syntax:["max(a, b, c, ...)"],description:"Compute the maximum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},tt.min=An,An.doc={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["min(2, 3, 4, 1)","min(2.7, 7.1, -4.5, 2.0, 4.1)","max(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},tt.acos=zn,zn.doc={name:"acos",category:"Trigonometry",syntax:["acos(x)"],description:"Compute the inverse cosine of a value in radians.",examples:["acos(0.5)","acos(cos(2.3))"],seealso:["cos","acos","asin"]},tt.asin=qn,qn.doc={name:"asin",category:"Trigonometry",syntax:["asin(x)"],description:"Compute the inverse sine of a value in radians.",examples:["asin(0.5)","asin(sin(2.3))"],seealso:["sin","acos","asin"]},tt.atan=Un,Un.doc={name:"atan",category:"Trigonometry",syntax:["atan(x)"],description:"Compute the inverse tangent of a value in radians.",examples:["atan(0.5)","atan(tan(2.3))"],seealso:["tan","acos","asin"]},tt.atan2=Rn,Rn.doc={name:"atan2",category:"Trigonometry",syntax:["atan2(y, x)"],description:"Computes the principal value of the arc tangent of y/x in radians.",examples:["atan2(2, 2) / pi","angle = 60 deg in rad","x = cos(angle)","y = sin(angle)","atan2(y, x)"],seealso:["sin","cos","tan"]},tt.cos=Ln,Ln.doc={name:"cos",category:"Trigonometry",syntax:["cos(x)"],description:"Compute the cosine of x in radians.",examples:["cos(2)","cos(pi / 4) ^ 2","cos(180 deg)","cos(60 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["acos","sin","tan"]},tt.cot=Cn,Cn.doc={name:"cot",category:"Trigonometry",syntax:["cot(x)"],description:"Compute the cotangent of x in radians. Defined as 1/tan(x)",examples:["cot(2)","1 / tan(2)"],seealso:["sec","csc","tan"]},tt.csc=_n,_n.doc={name:"csc",category:"Trigonometry",syntax:["csc(x)"],description:"Compute the cosecant of x in radians. Defined as 1/sin(x)",examples:["csc(2)","1 / sin(2)"],seealso:["sec","cot","sin"]},tt.sec=In,In.doc={name:"sec",category:"Trigonometry",syntax:["sec(x)"],description:"Compute the secant of x in radians. Defined as 1/cos(x)",examples:["sec(2)","1 / cos(2)"],seealso:["cot","csc","cos"]},tt.sin=Pn,Pn.doc={name:"sin",category:"Trigonometry",syntax:["sin(x)"],description:"Compute the sine of x in radians.",examples:["sin(2)","sin(pi / 4) ^ 2","sin(90 deg)","sin(30 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["asin","cos","tan"]},tt.tan=Bn,Bn.doc={name:"tan",category:"Trigonometry",syntax:["tan(x)"],description:"Compute the tangent of x in radians.",examples:["tan(0.5)","sin(0.5) / cos(0.5)","tan(pi / 4)","tan(45 deg)"],seealso:["atan","sin","cos"]},tt.in=kn,kn.doc={name:"in",category:"Units",syntax:["x in unit","in(x, unit)"],description:"Change the unit of a value.",examples:["5 inch in cm","3.2kg in g","16 bytes in bits"],seealso:[]},tt.clone=Gn,Gn.doc={name:"clone",category:"Utils",syntax:["clone(x)"],description:"Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices",examples:["clone(3.5)","clone(2 - 4i)","clone(45 deg)","clone([1, 2; 3, 4])",'clone("hello world")'],seealso:[]},tt.format=jn,jn.doc={name:"format",category:"Utils",syntax:["format(value)"],description:"Format a value of any type as string.",examples:["format(2.3)","format(3 - 4i)","format([])"],seealso:[]},tt.help=Vn,Vn.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},tt["import"]=Fn,Fn.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},tt["typeof"]=Yn,Yn.doc={name:"typeof",category:"Utils",syntax:["typeof(x)"],description:"Get the type of a variable.",examples:["typeof(3.5)","typeof(2 - 4i)","typeof(45 deg)",'typeof("hello world")'],seealso:[]},tt.expr.node.Node=Wn,Wn.prototype.eval=function(){throw Error("Cannot evaluate a Node interface") +},Wn.prototype.toString=function(){return""},Xn.prototype=new Wn,tt.expr.node.Symbol=Xn,Xn.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},Xn.prototype.eval=function(){var e=this.fn;if(void 0===e)throw Error("Undefined symbol "+this.name);var n=this.params.map(function(e){return e.eval()});return e.apply(this,n)},Xn.prototype.toString=function(){if(this.name&&!this.params)return this.name;var e=this.name;return this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e},Zn.prototype=new Wn,tt.expr.node.Constant=Zn,Zn.prototype.eval=function(){return this.value},Zn.prototype.toString=function(){return this.value?tt.format(this.value):""},Kn.prototype=new Wn,tt.expr.node.MatrixNode=Kn,function(){function e(n){return n.map(function(n){return n instanceof Array?e(n):n.eval()})}function n(e){if(e instanceof Array){for(var t="[",r=e.length,a=0;r>a;a++)0!=a&&(t+=", "),t+=n(e[a]);return t+="]"}return""+e}Kn.prototype.eval=function(){return new t(e(this.nodes))},Kn.prototype.toString=function(){return n(this.nodes)}}(),Qn.prototype=new Wn,tt.expr.node.Block=Qn,Qn.prototype.add=function(e,n){var t=this.params.length;this.params[t]=e,this.visible[t]=void 0!=n?n:!0},Qn.prototype.eval=function(){for(var e=[],n=0,t=this.params.length;t>n;n++){var r=this.params[n].eval();this.visible[n]&&e.push(r)}return e},Qn.prototype.toString=function(){for(var e=[],n=0,t=this.params.length;t>n;n++)this.visible[n]&&e.push("\n "+(""+this.params[n]));return"["+e.join(",")+"\n]"},Jn.prototype=new Wn,tt.expr.node.Assignment=Jn,Jn.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,n=this.params;if(n&&n.length){var t=[];this.params.forEach(function(e){t.push(e.eval())});var r=this.expr.eval();if(void 0==this.result.value)throw Error("Undefined symbol "+this.name);var a=this.result();if(!a.set)throw new TypeError("Cannot apply a subset to object of type "+tt.typeof(a));e=a.set(t,r),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},Jn.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},$n.prototype=new Wn,tt.expr.node.Arguments=$n,$n.prototype.eval=function(){var e=this.object;if(void 0==e)throw Error("Node undefined");for(var n=e.eval(),t=this.params,r=[],a=0,i=t.length;i>a;a++)r[a]=t[a].eval();if(!n.get)throw new TypeError("Cannot apply arguments to object of type "+tt.typeof(n));return n.get(r)},$n.prototype.toString=function(){var e=this.object?""+this.object:"";return this.params&&(e+="("+this.params.join(", ")+")"),e},et.prototype=new Wn,tt.expr.node.FunctionAssignment=et,et.prototype.createFunction=function(e,n,t,r){var a=function(){var n=t?t.length:0,a=arguments?arguments.length:0;if(n!=a)throw E(e,a,n);if(n>0)for(var i=0;n>i;i++)t[i].value=arguments[i];return r.eval()};return a.toString=function(){return e+"("+n.join(", ")+")"},a},et.prototype.eval=function(){for(var e=this.variables,n=this.values,t=0,r=e.length;r>t;t++)e[t].value=n[t];return this.result.value=this.def,this.def},et.prototype.toString=function(){return""+this.def},function(){function e(e){this.parentScope=e,this.nestedScopes=void 0,this.symbols={},this.defs={},this.updates={},this.links={}}tt.expr.Scope=e,e.prototype.createNestedScope=function(){var n=new e(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(n),n},e.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,n=0,t=e.length;t>n;n++)e[n].clear()},e.prototype.createSymbol=function(e){var n=this.symbols[e];if(!n){var t=this.findDef(e);n=this.newSymbol(e,t),this.symbols[e]=n}return n},e.prototype.newSymbol=function(e,n){var r=this,a=function(){var n,i;if(!a.value&&(a.value=r.findDef(e),!a.value))throw Error("Undefined symbol "+e);if("function"==typeof a.value)return a.value.apply(null,arguments);if(a.value instanceof t||a.value instanceof g||a.value instanceof Array){if(arguments.length){var o=a.value instanceof Array?new t(a.value):a.value;for(n=[],i=0;arguments.length>i;i++)n[i]=arguments[i];return o.get(n)}return a.value}return a.value};return a.value=n,a.toString=function(){return a.value?""+a.value:""},a},e.prototype.createLink=function(e){var n=this.links[e];return n||(n=this.createSymbol(e),this.links[e]=n),n},e.prototype.createDef=function(e,n){var t=this.defs[e];return t||(t=this.createSymbol(e),this.defs[e]=t),t&&void 0!=n&&(t.value=n),t},e.prototype.createUpdate=function(e){var n=this.updates[e];return n||(n=this.createLink(e),this.updates[e]=n),n},e.prototype.findDef=function(e){function t(e,n){var t=a(e,n);return i[e]=t,o[e]=t,t}var r;if(r=this.defs[e])return r;if(r=this.updates[e])return r;if(this.parentScope)return this.parentScope.findDef(e);var a=this.newSymbol,i=this.symbols,o=this.defs;if("pi"==e)return t(e,tt.PI);if("e"==e)return t(e,tt.E);if("i"==e)return t(e,new n(0,1));var s=tt[e];if(s)return t(e,s);if(x.isUnit(e)){var f=new x(null,e);return t(e,f)}return void 0},e.prototype.removeLink=function(e){delete this.links[e]},e.prototype.removeDef=function(e){delete this.defs[e]},e.prototype.removeUpdate=function(e){delete this.updates[e]},e.prototype.init=function(){var e=this.symbols,n=this.parentScope;for(var t in e)if(e.hasOwnProperty(t)){var r=e[t];r.value=n?n.findDef(t):void 0}this.nestedScopes&&this.nestedScopes.forEach(function(e){e.init()})},e.prototype.hasLink=function(e){if(this.links[e])return!0;if(this.nestedScopes)for(var n=this.nestedScopes,t=0,r=n.length;r>t;t++)if(n[t].hasLink(e))return!0;return!1},e.prototype.hasDef=function(e){return void 0!=this.defs[e]},e.prototype.hasUpdate=function(e){return void 0!=this.updates[e]},e.prototype.getUndefinedSymbols=function(){var e=this.symbols,n=[];for(var t in e)if(e.hasOwnProperty(t)){var r=e[t];void 0==r.value&&n.push(r)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){n=n.concat(e.getUndefinedSymbols())}),n}}(),function(){function e(){B++,G=P.charAt(B)}function t(){B=0,G=P.charAt(0)}function r(){for(V=I.NULL,j="";" "==G||" "==G;)e();if("#"==G)for(;"\n"!=G&&""!=G;)e();if(""==G)return V=I.DELIMITER,void 0;if("-"==G||","==G||"("==G||")"==G||"["==G||"]"==G||'"'==G||"\n"==G||";"==G||":"==G)return V=I.DELIMITER,j+=G,e(),void 0;if(a(G))for(V=I.DELIMITER;a(G);)j+=G,e();else if(o(G)){for(V=I.NUMBER;o(G);)j+=G,e();if("E"==G||"e"==G)for(j+=G,e(),("+"==G||"-"==G)&&(j+=G,e()),s(G)||(V=I.UNKNOWN);s(G);)j+=G,e()}else{if(!i(G)){for(V=I.UNKNOWN;""!=G;)j+=G,e();throw R('Syntax error in part "'+j+'"')}for(V=I.SYMBOL;i(G)||s(G);)j+=G,e()}}function a(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==e||"!"==e}function i(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e}function o(e){return e>="0"&&"9">=e||"."==e}function s(e){return e>="0"&&"9">=e}function f(e){t(),r();var n;if(n=""==j?new Zn(void 0):c(e),""!=j)throw V==I.DELIMITER?C("Unknown operator "+j):R('Unexpected part "'+j+'"');return n}function u(e){var n=l(e);if(!(n instanceof Jn)){var t="ans",r=void 0,a=e.createDef(t);return new Jn(t,r,n,a)}return n}function c(e){var n,t,a;for("\n"!=j&&";"!=j&&""!=j&&(n=u(e));"\n"==j||";"==j;)t||(t=new Qn,n&&(a=";"!=j,t.add(n,a))),r(),"\n"!=j&&";"!=j&&""!=j&&(n=u(e),a=";"!=j,t.add(n,a));return t?t:(n||(n=u(e)),n)}function l(e){if(V==I.SYMBOL&&"function"==j){if(r(),V!=I.SYMBOL)throw R("Function name expected");var n=j;if(r(),"("!=j)throw R("Opening parenthesis ( expected");for(var t=e.createNestedScope(),a=[],i=[];;){if(r(),V!=I.SYMBOL)throw R("Variable name expected");var o=j,s=t.createDef(o);if(a.push(o),i.push(s),r(),","!=j){if(")"==j)break;throw R('Comma , or closing parenthesis ) expected"')}}if(r(),"="!=j)throw R("Equal sign = expected");r();var f=m(t),u=e.createDef(n);return new et(n,a,i,f,u)}return h(e)}function h(e){var n=!1;V==I.SYMBOL&&(n=e.hasLink(j));var t=m(e);if("="==j){if(!(t instanceof Xn))throw R("Symbol expected at the left hand side of assignment operator =");var a=t.name,i=t.params;n||e.removeLink(a),r();var o=m(e),s=t.hasParams()?e.createUpdate(a):e.createDef(a);return new Jn(a,i,o,s)}return t}function m(e){var n=p(e);if(":"==j){for(var t=[n];":"==j;)r(),t.push(p(e));if(t.length>3)throw new TypeError("Invalid range");var a="range",i=an;n=new Xn(a,i,t)}return n}function p(e){for(var n=v(e),t={"in":"in"};void 0!==t[j];){var a=j,i=tt[t[a]];r();var o=[n,v(e)];n=new Xn(a,i,o)}return n}function v(e){var n=d(e);return n}function d(e){for(var n=g(e),t={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==t[j];){var a=j,i=tt[t[a]];r();var o=[n,g(e)];n=new Xn(a,i,o)}return n}function g(e){for(var n=y(e),t={"+":"add","-":"subtract"};void 0!==t[j];){var a=j,i=tt[t[a]];r();var o=[n,y(e)];n=new Xn(a,i,o)}return n}function y(e){for(var n=w(e),t={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==t[j];){var a=j,i=tt[t[a]];r();var o=[n,w(e)];n=new Xn(a,i,o)}return n}function w(e){if("-"==j){var n=j,t=Z;r();var a=[E(e)];return new Xn(n,t,a)}return E(e)}function E(e){for(var n=[N(e)];"^"==j;)r(),n.push(N(e));for(var t=n.pop();n.length;){var a=n.pop(),i="^",o=k,s=[a,t];t=new Xn(i,o,s)}return t}function N(e){for(var n=b(e);"!"==j;){var t=j,a=En;r();var i=[n];n=new Xn(t,a,i)}return n}function b(e){return O(e)}function O(e){if(V==I.SYMBOL){var n=j;r();var t=e.createLink(n),a=M(e),i=new Xn(n,t,a);return i}return A(e)}function M(e){var n=[];if("("==j){if(r(),")"!=j)for(n.push(m(e));","==j;)r(),n.push(m(e));if(")"!=j)throw R("Parenthesis ) missing");r()}return n}function A(n){if('"'==j){for(var t="",a="";""!=G&&('"'!=G||"\\"==a);)t+=G,a=G,e();if(r(),'"'!=j)throw R('End of string " missing');r();var i=new Zn(t);return i}return S(n)}function S(e){if("["==j){var n;for(r();"\n"==j;)r();if("]"!=j){var t=[],a=0,i=0;for(t[0]=[m(e)];","==j||";"==j;){for(","==j?i++:(a++,i=0,t[a]=[]),r();"\n"==j;)r();for(t[a][i]=m(e);"\n"==j;)r()}var o=t.length,s=t.length>0?t[0].length:0;for(a=1;o>a;a++)if(t[a].length!=s)throw C("Number of columns must match ("+t[a].length+" != "+s+")");if("]"!=j)throw R("End of matrix ] missing");r(),n=new Kn(t)}else r(),n=new Kn([]);return n}return T(e)}function T(e){if(V==I.NUMBER){var t;t="."==j?0:Number(j),r();var a;if(V==I.SYMBOL){if("i"==j||"I"==j)return a=new n(0,t),r(),new Zn(a);if(x.isUnit(j))return a=new x(t,j),r(),new Zn(a);throw L('Unknown unit "'+j+'"')}var i=new Zn(t);return i}return z(e)}function z(e){if("("==j){r();var n=m(e);if(")"!=j)throw R("Parenthesis ) expected");return r(),n}return q(e)}function q(){throw""==j?R("Unexpected end of expression"):R("Value expected")}function U(e){var n=n(),t=t();return void 0===n?void 0===t?e:e+" (col "+t+")":e+" (ln "+n+", col "+t+")"}function R(e){return new SyntaxError(U(e))}function L(e){return new TypeError(U(e))}function C(e){return Error(U(e))}tt.expr.Parser=function _(){if(this.constructor!=_)throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new tt.expr.Scope},tt.expr.Parser.prototype.parse=function(e,n){return P=e||"",n||(this._newScope(),n=this.scope),f(n)},tt.expr.Parser.prototype.eval=function(e){var n=this.parse(e);return n.eval()},tt.expr.Parser.prototype.get=function(e){this._newScope();var n=this.scope.findDef(e);return n?n.value:void 0},tt.expr.Parser.prototype.set=function(e,n){this.scope.createDef(e,n)},tt.expr.Parser.prototype._newScope=function(){this.scope=new tt.expr.Scope(this.scope)},tt.expr.Parser.prototype.clear=function(){this.scope.clear()};var I={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},P="",B=0,G="",j="",V=I.NULL}(),function(){function e(){this.idMax=-1,this.updateSeq=0,this.parser=new tt.expr.Parser,this.scope=new tt.expr.Scope,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}tt.expr.Workspace=e,e.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},e.prototype.append=function(n){var t=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,a=new tt.expr.Scope(r),i=new e.Node({id:t,expression:n,parser:this.parser,scope:a,nextNode:void 0,previousNode:this.lastNode});return this.nodes[t]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([t]),t},e.prototype.insertBefore=function(n,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var a=r.previousNode,i=this._getNewId(),o=a?a.scope:this.scope,s=new tt.expr.Scope(o),f=new e.Node({id:i,expression:n,parser:this.parser,scope:s,nextNode:r,previousNode:a});this.nodes[i]=f,a?a.nextNode=f:this.firstNode=f,r.previousNode=f,r.scope.parentScope=f.scope;var u=this.getDependencies(i);return-1==u.indexOf(i)&&u.unshift(i),this._update(u),i},e.prototype.insertAfter=function(e,n){var t=this.nodes[n];if(!t)throw'Node with id "'+n+'" not found';return t==this.lastNode?this.append(e):this.insertBefore(n+1,e)},e.prototype.remove=function(e){var n=this.nodes[e];if(!n)throw'Node with id "'+e+'" not found';var t=this.getDependencies(e),r=n.previousNode,a=n.nextNode;r?r.nextNode=a:this.firstNode=a,a?a.previousNode=r:this.lastNode=r;var i=r?r.scope:this.scope;a&&(a.scope.parentScope=i),delete this.nodes[e],this._update(t)},e.prototype.replace=function(n,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var a=[t];e._merge(a,this.getDependencies(t));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(n),e._merge(a,this.getDependencies(t)),this._update(a)},e.Node=function(e){this.id=e.id,this.parser=e.parser,this.scope=e.scope,this.nextNode=e.nextNode,this.previousNode=e.previousNode,this.updateSeq=0,this.result=void 0,this.setExpr(e.expression)},e.Node.prototype.setExpr=function(e){this.expression=e||"",this.scope.clear(),this._parse()},e.Node.prototype.getExpr=function(){return this.expression},e.Node.prototype.getResult=function(){return this.result},e.Node.prototype._parse=function(){try{this.fn=this.parser.parse(this.expression,this.scope)}catch(e){var n="Error: "+((e.message||e)+"");this.fn=new Zn(n)}},e.Node.prototype.eval=function(){try{this.scope.init(),this.result=this.fn.eval()}catch(e){this.scope.init(),this.result="Error: "+((e.message||e)+"")}return this.result},e._merge=function(e,n){for(var t=0,r=n.length;r>t;t++){var a=n[t];-1==e.indexOf(a)&&e.push(a)}},e.prototype.getDependencies=function(n){var t,r=[],a=this.nodes[n];if(a){var i=a.scope.defs,o=a.scope.updates,s=[];for(t in i)i.hasOwnProperty(t)&&s.push(t);for(t in o)o.hasOwnProperty(t)&&-1==s.indexOf(t)&&s.push(t);for(var f=a.nextNode;f&&s.length;){for(var u=f.scope,c=0;s.length>c;){if(t=s[c],(u.hasLink(t)||u.hasUpdate(t))&&-1==r.indexOf(f.id)){r.push(f.id);var l=this.getDependencies(f.id);e._merge(r,l)}u.hasDef(t)&&(s.splice(c,1),c--),c++}f=f.nextNode}}return r},e.prototype.getExpr=function(e){var n=this.nodes[e];if(!n)throw'Node with id "'+e+'" not found';return n.getExpr()},e.prototype.getResult=function(e){var n=this.nodes[e];if(!n)throw'Node with id "'+e+'" not found';return n.getResult()},e.prototype._update=function(e){this.updateSeq++;for(var n=this.updateSeq,t=this.nodes,r=0,a=e.length;a>r;r++){var i=e[r],o=t[i];o&&(o.eval(),o.updateSeq=n)}},e.prototype.getChanges=function(e){var n=[],t=this.firstNode;for(e=e||0;t;)t.updateSeq>e&&n.push(t.id),t=t.nextNode;return{ids:n,updateSeq:this.updateSeq}},e.prototype._getNewId=function(){return this.idMax++,this.idMax},e.prototype.toString=function(){return JSON.stringify(this.toJSON())},e.prototype.toJSON=function(){for(var e=[],n=this.firstNode;n;){var t={id:n.id,expression:n.expression,dependencies:this.getDependencies(n.id)};try{t.result=n.getResult()}catch(r){t.result="Error: "+((r.message||r)+"")}e.push(t),n=n.nextNode}return e}}(),tt.Complex=function(){nt("new math.Complex()","math.complex()")},tt.Unit=function(){nt("new math.Unit()","math.unit()")},tt.parser.Parser=function(){nt("new math.parser.Parser()","math.parser()")},tt.parser.Workspace=function(){nt("new math.parser.Workspace()","math.workspace()")}})(); \ No newline at end of file diff --git a/src/function/arithmetic/divide.js b/src/function/arithmetic/divide.js index 61ff5f37f..2ff65778e 100644 --- a/src/function/arithmetic/divide.js +++ b/src/function/arithmetic/divide.js @@ -16,18 +16,18 @@ function divide(x, y) { } else if (y instanceof Complex) { // number / complex - return divideComplex(new Complex(x, 0), y); + return _divideComplex(new Complex(x, 0), y); } } if (x instanceof Complex) { if (isNumber(y)) { // complex / number - return divideComplex(x, new Complex(y, 0)); + return _divideComplex(x, new Complex(y, 0)); } else if (y instanceof Complex) { // complex / complex - return divideComplex(x, y); + return _divideComplex(x, y); } } @@ -73,7 +73,7 @@ function divide(x, y) { * @return {Complex} res * @private */ -function divideComplex (x, y) { +function _divideComplex (x, y) { var den = y.re * y.re + y.im * y.im; return new Complex( (x.re * y.re + x.im * y.im) / den, diff --git a/src/function/arithmetic/larger.js b/src/function/arithmetic/larger.js index 5c85b6605..da3e59c72 100644 --- a/src/function/arithmetic/larger.js +++ b/src/function/arithmetic/larger.js @@ -40,7 +40,7 @@ function larger(x, y) { if (x instanceof Array || x instanceof Matrix || x instanceof Range || y instanceof Array || y instanceof Matrix || y instanceof Range) { - return util.map2(x, y, equal); + return util.map2(x, y, larger); } if (x.valueOf() !== x || y.valueOf() !== y) { diff --git a/src/function/arithmetic/multiply.js b/src/function/arithmetic/multiply.js index 43ae54800..eacef053f 100644 --- a/src/function/arithmetic/multiply.js +++ b/src/function/arithmetic/multiply.js @@ -16,7 +16,7 @@ function multiply(x, y) { } else if (y instanceof Complex) { // number * complex - return multiplyComplex(new Complex(x, 0), y); + return _multiplyComplex (new Complex(x, 0), y); } else if (y instanceof Unit) { res = y.clone(); @@ -27,11 +27,11 @@ function multiply(x, y) { else if (x instanceof Complex) { if (isNumber(y)) { // complex * number - return multiplyComplex(x, new Complex(y, 0)); + return _multiplyComplex (x, new Complex(y, 0)); } else if (y instanceof Complex) { // complex * complex - return multiplyComplex(x, y); + return _multiplyComplex (x, y); } } else if (x instanceof Unit) { @@ -117,7 +117,7 @@ function multiply(x, y) { * @return {Complex} res * @private */ -function multiplyComplex (x, y) { +function _multiplyComplex (x, y) { return new Complex( x.re * y.re - x.im * y.im, x.re * y.im + x.im * y.re diff --git a/src/function/matrix/det.js b/src/function/matrix/det.js index 330995cc9..932d50ca3 100644 --- a/src/function/matrix/det.js +++ b/src/function/matrix/det.js @@ -58,6 +58,9 @@ math.det = det; * @private */ function _det (matrix, rows, cols) { + var multiply = math.multiply, + subtract = math.subtract; + // this is a square matrix if (rows == 1) { // this is a 1 x 1 matrix @@ -66,9 +69,9 @@ function _det (matrix, rows, cols) { else if (rows == 2) { // this is a 2 x 2 matrix // the determinant of [a11,a12;a21,a22] is det = a11*a22-a21*a12 - return math.subtract( - math.multiply(matrix[0][0], matrix[1][1]), - math.multiply(matrix[1][0], matrix[0][1]) + return subtract( + multiply(matrix[0][0], matrix[1][1]), + multiply(matrix[1][0], matrix[0][1]) ); } else { @@ -77,8 +80,8 @@ function _det (matrix, rows, cols) { for (var c = 0; c < cols; c++) { var minor = _minor(matrix, rows, cols, 0, c); //d += Math.pow(-1, 1 + c) * a(1, c) * _det(minor); - d += math.multiply( - math.multiply((c + 1) % 2 + (c + 1) % 2 - 1, matrix[0][c]), + d += multiply( + multiply((c + 1) % 2 + (c + 1) % 2 - 1, matrix[0][c]), _det(minor, rows - 1, cols - 1) ); // faster than with pow() } diff --git a/src/function/matrix/inv.js b/src/function/matrix/inv.js index 64bbebb74..98171ae5e 100644 --- a/src/function/matrix/inv.js +++ b/src/function/matrix/inv.js @@ -75,7 +75,11 @@ math.inv = inv; * @private */ function _inv (matrix, rows, cols){ - var r, s, f, value, temp; + var r, s, f, value, temp, + add = math.add, + unaryminus = math.unaryminus, + multiply = math.multiply, + divide = math.divide; if (rows == 1) { // this is a 1 x 1 matrix @@ -95,12 +99,12 @@ function _inv (matrix, rows, cols){ } return [ [ - math.divide(matrix[1][1], det), - math.divide(math.unaryminus(matrix[0][1]), det) + divide(matrix[1][1], det), + divide(unaryminus(matrix[0][1]), det) ], [ - math.divide(math.unaryminus(matrix[1][0]), det), - math.divide(matrix[0][0], det) + divide(unaryminus(matrix[1][0]), det), + divide(matrix[0][0], det) ] ]; } @@ -146,15 +150,15 @@ function _inv (matrix, rows, cols){ if(r != c) { // eliminate value at column c and row r if (Ar[c] != 0) { - f = math.divide(math.unaryminus(Ar[c]), Ac[c]); + f = divide(unaryminus(Ar[c]), Ac[c]); // add (f * row c) to row r to eliminate the value // at column c for (s = c; s < cols; s++) { - Ar[s] = math.add(Ar[s], math.multiply(f, Ac[s])); + Ar[s] = add(Ar[s], multiply(f, Ac[s])); } for (s = 0; s < cols; s++) { - Br[s] = math.add(Br[s], math.multiply(f, Bc[s])); + Br[s] = add(Br[s], multiply(f, Bc[s])); } } } @@ -163,10 +167,10 @@ function _inv (matrix, rows, cols){ // divide each value on row r with the value at Acc f = Ac[c]; for (s = c; s < cols; s++) { - Ar[s] = math.divide(Ar[s], f); + Ar[s] = divide(Ar[s], f); } for (s = 0; s < cols; s++) { - Br[s] = math.divide(Br[s], f); + Br[s] = divide(Br[s], f); } } } diff --git a/src/function/statistics/max.js b/src/function/statistics/max.js index c41184131..def738fc3 100644 --- a/src/function/statistics/max.js +++ b/src/function/statistics/max.js @@ -5,27 +5,94 @@ */ function max(args) { if (arguments.length == 0) { - throw new Error('Function sum requires one or more parameters (0 provided)'); + throw new Error('Function max requires one or more parameters (0 provided)'); } - if (arguments.length == 1 && (args.valueOf() instanceof Array)) { - return max.apply(this, args.valueOf()); + if (args instanceof Array || args instanceof Matrix || args instanceof Range) { + // max([a, b, c, d, ...]]) + if (arguments.length > 1) { + throw Error('Wrong number of parameters (1 matrix or multiple scalars expected)'); + } + + var size = math.size(args); + + if (size.length == 1) { + // vector + if (args.length == 0) { + throw new Error('Cannot calculate max of an empty vector'); + } + + return _max(args.valueOf()); + } + else if (size.length == 2) { + // 2 dimensional matrix + if (size[0] == 0 || size[1] == 0) { + throw new Error('Cannot calculate max of an empty matrix'); + } + if (args instanceof Array) { + return _max2(args, size[0], size[1]); + } + else if (args instanceof Matrix || args instanceof Range) { + return new Matrix(_max2(args.valueOf(), size[0], size[1])); + } + else { + throw newUnsupportedTypeError('max', args); + } + } + else { + // TODO: implement max for n-dimensional matrices + throw new RangeError('Cannot calculate max for multi dimensional matrix'); + } } + else { + // max(a, b, c, d, ...) + return _max(arguments); + } +} - // TODO: implement support for Matrix +math.max = max; - var res = arguments[0]; - for (var i = 1, iMax = arguments.length; i < iMax; i++) { - var value = arguments[i]; +/** + * Calculate the max of a one dimensional array + * @param {Array} array + * @return {Number} max + * @private + */ +function _max(array) { + var larger = math.larger; + var res = array[0]; + for (var i = 1, iMax = array.length; i < iMax; i++) { + var value = array[i]; if (larger(value, res)) { res = value; } } - return res; } -math.max = max; +/** + * Calculate the max of a two dimensional array + * @param {Array} array + * @param {Number} rows + * @param {Number} cols + * @return {Number[]} max + * @private + */ +function _max2(array, rows, cols) { + var larger = math.larger; + var res = []; + for (var c = 0; c < cols; c++) { + var max = array[0][c]; + for (var r = 1; r < rows; r++) { + var value = array[r][c]; + if (larger(value, max)) { + max = value; + } + } + res[c] = max; + } + return res; +} /** * Function documentation diff --git a/src/function/statistics/min.js b/src/function/statistics/min.js index fef9dd1c6..97bead7cc 100644 --- a/src/function/statistics/min.js +++ b/src/function/statistics/min.js @@ -5,27 +5,94 @@ */ function min(args) { if (arguments.length == 0) { - throw new Error('Function sum requires one or more parameters (0 provided)'); + throw new Error('Function min requires one or more parameters (0 provided)'); } - if (arguments.length == 1 && (args.valueOf() instanceof Array)) { - return min.apply(this, args.valueOf()); + if (args instanceof Array || args instanceof Matrix || args instanceof Range) { + // min([a, b, c, d, ...]]) + if (arguments.length > 1) { + throw Error('Wrong number of parameters (1 matrix or multiple scalars expected)'); + } + + var size = math.size(args); + + if (size.length == 1) { + // vector + if (args.length == 0) { + throw new Error('Cannot calculate min of an empty vector'); + } + + return _min(args.valueOf()); + } + else if (size.length == 2) { + // 2 dimensional matrix + if (size[0] == 0 || size[1] == 0) { + throw new Error('Cannot calculate min of an empty matrix'); + } + if (args instanceof Array) { + return _min2(args, size[0], size[1]); + } + else if (args instanceof Matrix || args instanceof Range) { + return new Matrix(_min2(args.valueOf(), size[0], size[1])); + } + else { + throw newUnsupportedTypeError('min', args); + } + } + else { + // TODO: implement min for n-dimensional matrices + throw new RangeError('Cannot calculate min for multi dimensional matrix'); + } } + else { + // min(a, b, c, d, ...) + return _min(arguments); + } +} - // TODO: implement support for Matrix +math.min = min; - var res = arguments[0]; - for (var i = 1, iMax = arguments.length; i < iMax; i++) { - var value = arguments[i]; +/** + * Calculate the min of a one dimensional array + * @param {Array} array + * @return {Number} min + * @private + */ +function _min(array) { + var smaller = math.smaller; + var res = array[0]; + for (var i = 1, iMax = array.length; i < iMax; i++) { + var value = array[i]; if (smaller(value, res)) { res = value; } } - return res; } -math.min = min; +/** + * Calculate the min of a two dimensional array + * @param {Array} array + * @param {Number} rows + * @param {Number} cols + * @return {Number[]} min + * @private + */ +function _min2(array, rows, cols) { + var smaller = math.smaller; + var res = []; + for (var c = 0; c < cols; c++) { + var min = array[0][c]; + for (var r = 1; r < rows; r++) { + var value = array[r][c]; + if (smaller(value, min)) { + min = value; + } + } + res[c] = min; + } + return res; +} /** * Function documentation @@ -38,9 +105,9 @@ min.doc = { ], 'description': 'Compute the minimum value of a list of values.', 'examples': [ - 'max(2, 3, 4, 1)', - 'max(2.7, 7.1, -4.5, 2.0, 4.1)', - 'min(2.7, 7.1, -4.5, 2.0, 4.1)' + 'min(2, 3, 4, 1)', + 'min(2.7, 7.1, -4.5, 2.0, 4.1)', + 'max(2.7, 7.1, -4.5, 2.0, 4.1)' ], 'seealso': [ 'sum', diff --git a/test/function/statistics.js b/test/function/statistics.js index 2883534ed..a280cc7bd 100644 --- a/test/function/statistics.js +++ b/test/function/statistics.js @@ -3,5 +3,56 @@ var assert = require('assert'); var math = require('../../math.js'); -// TODO: test max -// TODO: test min +// test max +assert.equal(math.max(5), 5); +assert.equal(math.max(3,1), 3); +assert.equal(math.max(1,3), 3); +assert.equal(math.max(1,3,5,2,-5), 5); +assert.equal(math.max(0,0,0,0), 0); +assert.equal(math.max('A', 'C', 'D', 'B'), 'D'); +assert.equal(math.max([1,3,5,2,-5]), 5); +assert.equal(math.max(math.matrix([1,3,5,2,-5])), 5); +assert.equal(math.max(math.range(1,5)), 5); +assert.equal(math.max(math.range(5,-1,2)), 5); +assert.throws(function() {math.max()}); +assert.throws(function() {math.max([5,2], 3)}); +assert.throws(function() {math.max([])}); +assert.deepEqual(math.max([ + [ 1, 4, 7], + [ 3, 0, 5], + [-1, 9, 11] +]), [ 3, 9, 11]); +assert.deepEqual(math.max(math.matrix([ + [ 1, 4, 7], + [ 3, 0, 5], + [-1, 9, 11] +])), math.matrix([ 3, 9, 11])); + + + +// test min +assert.equal(math.min(5), 5); +assert.equal(math.min(1,3), 1); +assert.equal(math.min(3,1), 1); +assert.equal(math.min(1,3,5,-5,2), -5); +assert.equal(math.min(0,0,0,0), 0); +assert.equal(math.min('A', 'C', 'D', 'B'), 'A'); +assert.equal(math.min([1,3,5,-5,2]), -5); +assert.equal(math.min(math.matrix([1,3,5,-5,2])), -5); +assert.equal(math.min(math.range(1,5)), 1); +assert.equal(math.min(math.range(5,-1,2)), 2); +assert.throws(function() {math.min()}); +assert.throws(function() {math.min([5,2], 3)}); +assert.throws(function() {math.min([])}); +assert.deepEqual(math.min([ + [ 1, 4, 7], + [ 3, 0, 5], + [-1, 9, 11] +]), [-1, 0, 5]); +assert.deepEqual(math.min(math.matrix([ + [ 1, 4, 7], + [ 3, 0, 5], + [-1, 9, 11] +])), math.matrix([-1, 0, 5])); + +